-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.config.example.js
More file actions
154 lines (141 loc) · 5.3 KB
/
Copy pathdb.config.example.js
File metadata and controls
154 lines (141 loc) · 5.3 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// @ts-check
import { defineConfig } from '@async/db/config';
export default defineConfig({
// Generated output locations. Most committed outputs are opt-in.
outputs: {
stateDir: './.db',
types: './.db/types/index.ts',
committedTypes: null,
schemaManifest: null,
viewerManifest: null,
operationRegistry: null,
operationRefs: null,
honoStarterDir: './db-api',
},
// Optional visitor hook for changing or omitting generated manifest fields.
schemaManifest: {
customizeField({ defaultManifest }) {
return defaultManifest;
},
},
// Optional custom source readers. Built-in readers handle JSON, JSONC, CSV,
// .schema.json, .schema.jsonc, and .schema.js. Custom readers run first.
sources: {
writePolicy: 'preserve',
readers: [],
},
// Runtime stores. The default json store writes app edits to
// .db/state/<resource>.json while keeping source fixtures unchanged.
// Set stores.default to sourceFile when every plain .json resource should
// save directly back into db/<resource>.json. Optional database stores such as
// @async/db/postgres, @async/db/kv, and @async/db/redis accept injected
// clients so the core package stays dependency-light.
stores: {
default: 'json',
// Keep undoable per-write history under .db/state/.versions/<resource>/
// and roll back with `async-db restore <resource>`.
// json: { driver: 'json', durability: 'versioned', maxVersions: 10 },
// postgres: postgresStore({ client: pgPool }),
// redis: redisStore({ client: redisClient, prefix: 'my-app:' }),
// Seal state files at rest with AES-256-GCM (32-byte key or passphrase):
// sealed: jsonStore({ encryption: { key: () => process.env.DB_STATE_KEY } }),
},
resources: {
// users: { store: 'sourceFile' },
// featureFlags: { audit: true }, // who-changed-what JSONL trail
// billingSettings: { audit: { values: true } }, // plus before/after snapshots
// activityEvents: {
// store: 'json',
// indexes: [
// { fields: ['observedAt'] },
// { fields: ['domain', 'observedAt'] },
// ],
// },
},
// Generated TypeScript type behavior. Paths live under `outputs`.
types: {
enabled: true,
useReadonly: false,
emitComments: true,
},
// Default local development behavior is permissive: unknown schema-backed
// fields warn. Use 'error' when you want schema drift to fail sync/writes.
schema: {
unknownFields: 'warn',
},
// Optional schema-only mock records. Leave off when real fixture data exists.
seed: {
generateFromSchema: false,
generatedCount: 5,
},
// Local server settings.
server: {
// Dev-tool route base for the viewer, schema, batch, import, events, and log.
// Defaults to '/__db'.
apiBase: '/__db',
// App-facing REST data route alias. Defaults to '/db'; set false to only
// use scoped REST under /__db/rest and standalone root REST routes.
dataPath: '/db',
host: '127.0.0.1',
port: 7331,
maxBodyBytes: 1048576,
// Maximum concurrent /__db/events live-event subscribers. Extra
// subscriptions answer 503 VIEWER_EVENTS_LIMIT. Defaults to 100.
maxEventClients: 100,
// Opt-in request tracing. When enabled, traces are written to /__db/log,
// concise console lines are printed, and responses get a request id header.
// Trace metadata includes query keys only, never request bodies, response
// bodies, cookie headers, authorization headers, or query values.
trace: {
enabled: false,
slowMs: 100,
console: true,
events: true,
header: 'x-async-db-request-id',
},
// Optional custom data viewer links shown in discovery and manifest output.
viewerLinks: [
// { label: 'My Viewer', href: 'http://127.0.0.1:5173/db' },
],
// App-owned gate for every db-handled request. GET /__db/health has its
// own exposure setting (expose.health, default 'open') for load balancers.
// authorize({ request, route, method }) {
// if (method === 'GET') return true;
// return request.headers.authorization === `Bearer ${process.env.DB_WRITE_TOKEN}`;
// },
},
// REST and manifest response formats. Built-ins are json, html, and md.
// Object entries can register media types for Accept negotiation and can
// render both resource routes and /__db/manifest.<extension>.
rest: {
formats: {
default: 'json',
// yaml: {
// mediaTypes: ['application/yaml', 'text/yaml'],
// contentType: 'application/yaml; charset=utf-8',
// render({ data }) {
// return stringifyYaml(data);
// },
// },
},
},
// GraphQL and Falcor endpoints are opt-in. REST stays the default workflow.
// graphql: {
// enabled: true,
// path: '/graphql',
// },
// falcor: {
// enabled: true,
// path: '/model.json',
// },
// Local latency is on by default so loading states are visible. Use 0 to
// disable delay, 50 for a fixed 50ms delay, or [50, 300] for a range.
// Random errors are off by default. All mock behavior is skipped
// automatically when NODE_ENV=production; set production: true only when a
// production-like environment should keep mock delays/errors (chaos testing).
mock: {
delay: [30, 100],
errors: null,
// production: false,
},
});