-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.config.js
More file actions
67 lines (62 loc) · 1.58 KB
/
Copy pathdb.config.js
File metadata and controls
67 lines (62 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// @ts-check
import { defineConfig } from '@async/db/config';
export default defineConfig({
outputs: {
stateDir: './.db',
types: './.db/types/index.d.ts',
committedTypes: './src/generated/db.types.d.ts',
operationRegistry: './src/generated/db.operations.json',
operationRefs: './src/generated/db.operation-refs.json',
},
types: {
enabled: true,
emitComments: true,
},
schema: {
unknownFields: 'warn',
},
operations: {
enabled: false,
sourceDir: './db/operations',
},
rest: {
formats: {
yaml: {
mediaTypes: ['application/yaml', 'text/yaml'],
contentType: 'application/yaml; charset=utf-8',
render({ data }) {
return `${toYaml(data)}\n`;
},
},
},
},
});
function toYaml(value, indent = 0) {
const pad = ' '.repeat(indent);
if (Array.isArray(value)) {
return value.map((item) => {
if (item && typeof item === 'object') {
return `${pad}-\n${toYaml(item, indent + 2)}`;
}
return `${pad}- ${formatYamlScalar(item)}`;
}).join('\n');
}
if (value && typeof value === 'object') {
return Object.entries(value).map(([key, item]) => {
if (item && typeof item === 'object') {
return `${pad}${key}:\n${toYaml(item, indent + 2)}`;
}
return `${pad}${key}: ${formatYamlScalar(item)}`;
}).join('\n');
}
return `${pad}${formatYamlScalar(value)}`;
}
function formatYamlScalar(value) {
if (typeof value === 'string') {
return JSON.stringify(value);
}
if (value === null) {
return 'null';
}
return String(value);
}