@confect/cli 9.0.0-next.9 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +173 -1
- package/dist/Bundler.mjs +1 -4
- package/dist/Bundler.mjs.map +1 -1
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/log.mjs +2 -2
- package/dist/log.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +6 -24
- package/dist/index.d.mts +0 -1
- package/src/BuildError.ts +0 -217
- package/src/Bundler.ts +0 -145
- package/src/CodeBlockWriter.ts +0 -65
- package/src/CodegenError.ts +0 -407
- package/src/ConfectDirectory.ts +0 -45
- package/src/ConvexDirectory.ts +0 -72
- package/src/FunctionPath.ts +0 -27
- package/src/FunctionPaths.ts +0 -107
- package/src/GroupPath.ts +0 -116
- package/src/GroupPaths.ts +0 -7
- package/src/LeafModule.ts +0 -305
- package/src/ProjectRoot.ts +0 -55
- package/src/SpecAssemblyNode.ts +0 -75
- package/src/TableModule.ts +0 -157
- package/src/cliApp.ts +0 -8
- package/src/confect/codegen.ts +0 -847
- package/src/confect/dev.ts +0 -785
- package/src/confect.ts +0 -19
- package/src/index.ts +0 -23
- package/src/log.ts +0 -110
- package/src/templates.ts +0 -614
- package/src/utils.ts +0 -435
package/src/templates.ts
DELETED
|
@@ -1,614 +0,0 @@
|
|
|
1
|
-
import * as Array from "effect/Array";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Option from "effect/Option";
|
|
4
|
-
import { CodeBlockWriter } from "./CodeBlockWriter";
|
|
5
|
-
import {
|
|
6
|
-
collectImportBindings,
|
|
7
|
-
type SpecAssemblyNode,
|
|
8
|
-
} from "./SpecAssemblyNode";
|
|
9
|
-
|
|
10
|
-
export const functions = ({
|
|
11
|
-
functionNames,
|
|
12
|
-
registeredFunctionsImportPath,
|
|
13
|
-
useNode = false,
|
|
14
|
-
}: {
|
|
15
|
-
functionNames: string[];
|
|
16
|
-
registeredFunctionsImportPath: string;
|
|
17
|
-
useNode?: boolean;
|
|
18
|
-
}) =>
|
|
19
|
-
Effect.gen(function* () {
|
|
20
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
21
|
-
|
|
22
|
-
if (useNode) {
|
|
23
|
-
yield* cbw.writeLine(`"use node";`);
|
|
24
|
-
yield* cbw.blankLine();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
yield* cbw.writeLine(
|
|
28
|
-
`import registeredFunctions from "${registeredFunctionsImportPath}";`,
|
|
29
|
-
);
|
|
30
|
-
yield* cbw.newLine();
|
|
31
|
-
yield* Effect.forEach(functionNames, (functionName) =>
|
|
32
|
-
cbw.writeLine(
|
|
33
|
-
`export const ${functionName} = registeredFunctions.${functionName};`,
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
return yield* cbw.toString();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Emit `convex/schema.ts` as a one-line re-export of the codegen-emitted
|
|
42
|
-
* deploy schema in `confect/_generated/convexSchema.ts`. Deploy-time
|
|
43
|
-
* consumers (the Convex CLI, `convex-test`) keep reading
|
|
44
|
-
* `convex/schema.ts`; the runtime `DatabaseSchema` in
|
|
45
|
-
* `confect/_generated/schema.ts` is untouched by this file.
|
|
46
|
-
*/
|
|
47
|
-
export const schema = ({
|
|
48
|
-
convexSchemaImportPath,
|
|
49
|
-
}: {
|
|
50
|
-
convexSchemaImportPath: string;
|
|
51
|
-
}) =>
|
|
52
|
-
Effect.gen(function* () {
|
|
53
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
54
|
-
|
|
55
|
-
yield* cbw.writeLine(
|
|
56
|
-
`export { default } from "${convexSchemaImportPath}";`,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
return yield* cbw.toString();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
interface TableModuleBinding {
|
|
63
|
-
readonly importPath: string;
|
|
64
|
-
readonly tableName: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Emit `confect/_generated/schema.ts` — the runtime `DatabaseSchema` used
|
|
69
|
-
* by impls and the per-group registries (and downstream by per-function
|
|
70
|
-
* bundles for codec lookup). Every table wrapper at
|
|
71
|
-
* `confect/_generated/tables/<name>.ts` is imported statically and
|
|
72
|
-
* registered as a value entry on the `DatabaseSchema.make({...})` call.
|
|
73
|
-
* Per-table laziness lives inside each `Table`: its `Fields`, `Doc`, and
|
|
74
|
-
* `tableDefinition` are lazy memoised getters that only evaluate the
|
|
75
|
-
* user-supplied field-schema callback on first access, so unused tables in
|
|
76
|
-
* a function bundle never pay schema-construction cost despite the
|
|
77
|
-
* static import.
|
|
78
|
-
*
|
|
79
|
-
* The `DatabaseSchema` import is aliased to `$DatabaseSchema` because each
|
|
80
|
-
* table is imported under its own (filename-derived) name; a table named
|
|
81
|
-
* `DatabaseSchema` would otherwise collide with the library import and emit
|
|
82
|
-
* a duplicate-binding file. The leading `$` makes the alias collision-proof:
|
|
83
|
-
* `validateConfectTableIdentifier` requires names to match
|
|
84
|
-
* `/^[a-zA-Z][a-zA-Z0-9_]*$/`, which forbids `$`, so no valid table import
|
|
85
|
-
* can ever shadow it.
|
|
86
|
-
*/
|
|
87
|
-
export const runtimeSchema = ({
|
|
88
|
-
tableModules,
|
|
89
|
-
}: {
|
|
90
|
-
tableModules: ReadonlyArray<TableModuleBinding>;
|
|
91
|
-
}) =>
|
|
92
|
-
Effect.gen(function* () {
|
|
93
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
94
|
-
|
|
95
|
-
yield* cbw.writeLine(
|
|
96
|
-
`import { DatabaseSchema as $DatabaseSchema } from "@confect/server";`,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
if (tableModules.length > 0) {
|
|
100
|
-
yield* cbw.blankLine();
|
|
101
|
-
yield* Effect.forEach(tableModules, ({ tableName, importPath }) =>
|
|
102
|
-
cbw.writeLine(`import ${tableName} from "${importPath}";`),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
yield* cbw.blankLine();
|
|
107
|
-
|
|
108
|
-
if (tableModules.length === 0) {
|
|
109
|
-
yield* cbw.writeLine(`export default $DatabaseSchema.make({});`);
|
|
110
|
-
} else {
|
|
111
|
-
yield* cbw.writeLine(`export default $DatabaseSchema.make({`);
|
|
112
|
-
yield* cbw.indent(
|
|
113
|
-
Effect.gen(function* () {
|
|
114
|
-
for (const { tableName } of tableModules) {
|
|
115
|
-
yield* cbw.writeLine(`${tableName},`);
|
|
116
|
-
}
|
|
117
|
-
}),
|
|
118
|
-
);
|
|
119
|
-
yield* cbw.writeLine(`});`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return yield* cbw.toString();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Emit `confect/_generated/convexSchema.ts` — the Convex deploy-time
|
|
127
|
-
* `SchemaDefinition`. Imports every table from its generated wrapper at
|
|
128
|
-
* `_generated/tables/<name>` and calls `defineSchema({...})` exactly once.
|
|
129
|
-
* The file deliberately avoids any `@confect/server` import so that the
|
|
130
|
-
* deploy artifact's import graph stays decoupled from the runtime
|
|
131
|
-
* `DatabaseSchema` machinery.
|
|
132
|
-
*
|
|
133
|
-
* The `defineSchema` import is aliased to `$defineSchema` because each table
|
|
134
|
-
* is imported under its own (filename-derived) name; a table named
|
|
135
|
-
* `defineSchema` would otherwise collide with the library import and emit a
|
|
136
|
-
* duplicate-binding file. The leading `$` makes the alias collision-proof:
|
|
137
|
-
* `validateConfectTableIdentifier` requires names to match
|
|
138
|
-
* `/^[a-zA-Z][a-zA-Z0-9_]*$/`, which forbids `$`, so no valid table import
|
|
139
|
-
* can ever shadow it.
|
|
140
|
-
*/
|
|
141
|
-
export const convexSchema = ({
|
|
142
|
-
tableModules,
|
|
143
|
-
}: {
|
|
144
|
-
tableModules: ReadonlyArray<TableModuleBinding>;
|
|
145
|
-
}) =>
|
|
146
|
-
Effect.gen(function* () {
|
|
147
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
148
|
-
|
|
149
|
-
yield* cbw.writeLine(
|
|
150
|
-
`import { defineSchema as $defineSchema } from "convex/server";`,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
if (tableModules.length > 0) {
|
|
154
|
-
yield* cbw.blankLine();
|
|
155
|
-
yield* Effect.forEach(tableModules, ({ tableName, importPath }) =>
|
|
156
|
-
cbw.writeLine(`import ${tableName} from "${importPath}";`),
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
yield* cbw.blankLine();
|
|
161
|
-
|
|
162
|
-
if (tableModules.length === 0) {
|
|
163
|
-
yield* cbw.writeLine(`export default $defineSchema({});`);
|
|
164
|
-
} else {
|
|
165
|
-
yield* cbw.writeLine(`export default $defineSchema({`);
|
|
166
|
-
yield* cbw.indent(
|
|
167
|
-
Effect.gen(function* () {
|
|
168
|
-
for (const { tableName } of tableModules) {
|
|
169
|
-
yield* cbw.writeLine(`${tableName}: ${tableName}.tableDefinition,`);
|
|
170
|
-
}
|
|
171
|
-
}),
|
|
172
|
-
);
|
|
173
|
-
yield* cbw.writeLine(`});`);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return yield* cbw.toString();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Emit `confect/_generated/id.ts` — a type-constrained `Id` constructor and
|
|
181
|
-
* a `TableNames` union derived from the user's `confect/tables/*.ts`
|
|
182
|
-
* filenames. User-authored table modules import `Id` from this file to
|
|
183
|
-
* declare cross-table id references without typing the destination name as
|
|
184
|
-
* a free string (and without ever importing each other transitively).
|
|
185
|
-
*
|
|
186
|
-
* When the table directory is empty the `TableNames` union resolves to
|
|
187
|
-
* `never`, which still lets the file typecheck against an empty workspace.
|
|
188
|
-
*/
|
|
189
|
-
export const id = ({ tableNames }: { tableNames: ReadonlyArray<string> }) =>
|
|
190
|
-
Effect.gen(function* () {
|
|
191
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
192
|
-
|
|
193
|
-
yield* cbw.writeLine(`import { GenericId } from "@confect/core";`);
|
|
194
|
-
yield* cbw.blankLine();
|
|
195
|
-
|
|
196
|
-
const union =
|
|
197
|
-
tableNames.length === 0
|
|
198
|
-
? "never"
|
|
199
|
-
: tableNames.map((n) => `"${n}"`).join(" | ");
|
|
200
|
-
yield* cbw.writeLine(`export type TableNames = ${union};`);
|
|
201
|
-
yield* cbw.blankLine();
|
|
202
|
-
|
|
203
|
-
yield* cbw.writeLine(
|
|
204
|
-
`export const Id = <const TableName extends TableNames>(`,
|
|
205
|
-
);
|
|
206
|
-
yield* cbw.indent(cbw.writeLine(`tableName: TableName,`));
|
|
207
|
-
yield* cbw.writeLine(`) => GenericId.GenericId(tableName);`);
|
|
208
|
-
|
|
209
|
-
return yield* cbw.toString();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Emit `confect/_generated/tables/<tableName>.ts` — a two-line wrapper that
|
|
214
|
-
* imports the user-authored `UnnamedTable` and binds the file basename to
|
|
215
|
-
* it, producing the fully-named `Table` value that downstream consumers
|
|
216
|
-
* (schema, specs, impls) read.
|
|
217
|
-
*/
|
|
218
|
-
export const tableWrapper = ({
|
|
219
|
-
tableName,
|
|
220
|
-
unnamedImportPath,
|
|
221
|
-
}: {
|
|
222
|
-
tableName: string;
|
|
223
|
-
unnamedImportPath: string;
|
|
224
|
-
}) =>
|
|
225
|
-
Effect.gen(function* () {
|
|
226
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
227
|
-
|
|
228
|
-
yield* cbw.writeLine(`import unnamed from "${unnamedImportPath}";`);
|
|
229
|
-
yield* cbw.blankLine();
|
|
230
|
-
yield* cbw.writeLine(`export default unnamed("${tableName}");`);
|
|
231
|
-
|
|
232
|
-
return yield* cbw.toString();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
export const http = ({ httpImportPath }: { httpImportPath: string }) =>
|
|
236
|
-
Effect.gen(function* () {
|
|
237
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
238
|
-
|
|
239
|
-
yield* cbw.writeLine(`import http from "${httpImportPath}";`);
|
|
240
|
-
yield* cbw.newLine();
|
|
241
|
-
yield* cbw.writeLine(`export default http;`);
|
|
242
|
-
|
|
243
|
-
return yield* cbw.toString();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
export const crons = ({ cronsImportPath }: { cronsImportPath: string }) =>
|
|
247
|
-
Effect.gen(function* () {
|
|
248
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
249
|
-
|
|
250
|
-
yield* cbw.writeLine(`import crons from "${cronsImportPath}";`);
|
|
251
|
-
yield* cbw.newLine();
|
|
252
|
-
yield* cbw.writeLine(`export default crons.convexCronJobs;`);
|
|
253
|
-
|
|
254
|
-
return yield* cbw.toString();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
export const authConfig = ({ authImportPath }: { authImportPath: string }) =>
|
|
258
|
-
Effect.gen(function* () {
|
|
259
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
260
|
-
|
|
261
|
-
yield* cbw.writeLine(`import auth from "${authImportPath}";`);
|
|
262
|
-
yield* cbw.newLine();
|
|
263
|
-
yield* cbw.writeLine(`export default auth;`);
|
|
264
|
-
|
|
265
|
-
return yield* cbw.toString();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
export const refs = ({ specImportPath }: { specImportPath: string }) =>
|
|
269
|
-
Effect.gen(function* () {
|
|
270
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
271
|
-
|
|
272
|
-
yield* cbw.writeLine(`import { Refs } from "@confect/core";`);
|
|
273
|
-
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
274
|
-
yield* cbw.blankLine();
|
|
275
|
-
yield* cbw.writeLine(`export default Refs.make(spec);`);
|
|
276
|
-
|
|
277
|
-
return yield* cbw.toString();
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
export const registeredFunctionsForGroup = ({
|
|
281
|
-
schemaImportPath,
|
|
282
|
-
specImportPath,
|
|
283
|
-
implImportPath,
|
|
284
|
-
layerExportName,
|
|
285
|
-
useNode = false,
|
|
286
|
-
}: {
|
|
287
|
-
schemaImportPath: string;
|
|
288
|
-
specImportPath: string;
|
|
289
|
-
implImportPath: string;
|
|
290
|
-
layerExportName: string;
|
|
291
|
-
useNode?: boolean;
|
|
292
|
-
}) =>
|
|
293
|
-
Effect.gen(function* () {
|
|
294
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
295
|
-
|
|
296
|
-
if (useNode) {
|
|
297
|
-
yield* cbw.writeLine(
|
|
298
|
-
`import { RegisteredFunctions } from "@confect/server";`,
|
|
299
|
-
);
|
|
300
|
-
yield* cbw.writeLine(
|
|
301
|
-
`import { RegisteredNodeFunction } from "@confect/server/node";`,
|
|
302
|
-
);
|
|
303
|
-
} else {
|
|
304
|
-
yield* cbw.writeLine(
|
|
305
|
-
`import { RegisteredConvexFunction, RegisteredFunctions } from "@confect/server";`,
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
yield* cbw.writeLine(`import databaseSchema from "${schemaImportPath}";`);
|
|
310
|
-
yield* cbw.writeLine(`import ${layerExportName} from "${implImportPath}";`);
|
|
311
|
-
yield* cbw.blankLine();
|
|
312
|
-
// The group's own leaf spec is referenced type-only (`typeof import(...)`),
|
|
313
|
-
// so the spec module is erased at transpile time and never enters the
|
|
314
|
-
// per-function bundle; only `databaseSchema` and the impl are runtime
|
|
315
|
-
// imports. Typing from the leaf spec (not the project-wide assembled spec)
|
|
316
|
-
// keeps the registry's type dependent solely on its own group.
|
|
317
|
-
const specType = `typeof import("${specImportPath}")["default"]`;
|
|
318
|
-
const makeFn = useNode
|
|
319
|
-
? "RegisteredNodeFunction.make"
|
|
320
|
-
: "RegisteredConvexFunction.make";
|
|
321
|
-
yield* cbw.writeLine(
|
|
322
|
-
`export default RegisteredFunctions.buildForGroup<${specType}>(databaseSchema, ${layerExportName}, ${makeFn});`,
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
return yield* cbw.toString();
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
export const services = ({ schemaImportPath }: { schemaImportPath: string }) =>
|
|
329
|
-
Effect.gen(function* () {
|
|
330
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
331
|
-
|
|
332
|
-
// Imports
|
|
333
|
-
yield* cbw.writeLine("import {");
|
|
334
|
-
yield* cbw.indent(
|
|
335
|
-
Effect.gen(function* () {
|
|
336
|
-
yield* cbw.writeLine("ActionCtx as ActionCtx_,");
|
|
337
|
-
yield* cbw.writeLine("ActionRunner as ActionRunner_,");
|
|
338
|
-
yield* cbw.writeLine("Auth as Auth_,");
|
|
339
|
-
yield* cbw.writeLine("type DataModel,");
|
|
340
|
-
yield* cbw.writeLine("DatabaseReader as DatabaseReader_,");
|
|
341
|
-
yield* cbw.writeLine("DatabaseWriter as DatabaseWriter_,");
|
|
342
|
-
yield* cbw.writeLine("MutationCtx as MutationCtx_,");
|
|
343
|
-
yield* cbw.writeLine("MutationRunner as MutationRunner_,");
|
|
344
|
-
yield* cbw.writeLine("QueryCtx as QueryCtx_,");
|
|
345
|
-
yield* cbw.writeLine("QueryRunner as QueryRunner_,");
|
|
346
|
-
yield* cbw.writeLine("Scheduler as Scheduler_,");
|
|
347
|
-
yield* cbw.writeLine("StorageActionWriter as StorageActionWriter_,");
|
|
348
|
-
yield* cbw.writeLine("StorageReader as StorageReader_,");
|
|
349
|
-
yield* cbw.writeLine("StorageWriter as StorageWriter_,");
|
|
350
|
-
yield* cbw.writeLine("VectorSearch as VectorSearch_,");
|
|
351
|
-
}),
|
|
352
|
-
);
|
|
353
|
-
yield* cbw.writeLine(`} from "@confect/server";`);
|
|
354
|
-
yield* cbw.writeLine(
|
|
355
|
-
`import type schemaDefinition from "${schemaImportPath}";`,
|
|
356
|
-
);
|
|
357
|
-
yield* cbw.blankLine();
|
|
358
|
-
|
|
359
|
-
// Auth
|
|
360
|
-
yield* cbw.writeLine("export const Auth = Auth_.Auth;");
|
|
361
|
-
yield* cbw.writeLine("export type Auth = typeof Auth.Identifier;");
|
|
362
|
-
yield* cbw.blankLine();
|
|
363
|
-
|
|
364
|
-
// Scheduler
|
|
365
|
-
yield* cbw.writeLine("export const Scheduler = Scheduler_.Scheduler;");
|
|
366
|
-
yield* cbw.writeLine(
|
|
367
|
-
"export type Scheduler = typeof Scheduler.Identifier;",
|
|
368
|
-
);
|
|
369
|
-
yield* cbw.blankLine();
|
|
370
|
-
|
|
371
|
-
// StorageReader
|
|
372
|
-
yield* cbw.writeLine(
|
|
373
|
-
"export const StorageReader = StorageReader_.StorageReader;",
|
|
374
|
-
);
|
|
375
|
-
yield* cbw.writeLine(
|
|
376
|
-
"export type StorageReader = typeof StorageReader.Identifier;",
|
|
377
|
-
);
|
|
378
|
-
yield* cbw.blankLine();
|
|
379
|
-
|
|
380
|
-
// StorageWriter
|
|
381
|
-
yield* cbw.writeLine(
|
|
382
|
-
"export const StorageWriter = StorageWriter_.StorageWriter;",
|
|
383
|
-
);
|
|
384
|
-
yield* cbw.writeLine(
|
|
385
|
-
"export type StorageWriter = typeof StorageWriter.Identifier;",
|
|
386
|
-
);
|
|
387
|
-
yield* cbw.blankLine();
|
|
388
|
-
|
|
389
|
-
// StorageActionWriter
|
|
390
|
-
yield* cbw.writeLine(
|
|
391
|
-
"export const StorageActionWriter = StorageActionWriter_.StorageActionWriter;",
|
|
392
|
-
);
|
|
393
|
-
yield* cbw.writeLine(
|
|
394
|
-
"export type StorageActionWriter = typeof StorageActionWriter.Identifier;",
|
|
395
|
-
);
|
|
396
|
-
yield* cbw.blankLine();
|
|
397
|
-
|
|
398
|
-
// VectorSearch
|
|
399
|
-
yield* cbw.writeLine("export const VectorSearch =");
|
|
400
|
-
yield* cbw.indent(
|
|
401
|
-
cbw.writeLine(
|
|
402
|
-
"VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();",
|
|
403
|
-
),
|
|
404
|
-
);
|
|
405
|
-
yield* cbw.writeLine(
|
|
406
|
-
"export type VectorSearch = typeof VectorSearch.Identifier;",
|
|
407
|
-
);
|
|
408
|
-
yield* cbw.blankLine();
|
|
409
|
-
|
|
410
|
-
// DatabaseReader
|
|
411
|
-
yield* cbw.writeLine("export const DatabaseReader =");
|
|
412
|
-
yield* cbw.indent(
|
|
413
|
-
cbw.writeLine(
|
|
414
|
-
"DatabaseReader_.DatabaseReader<typeof schemaDefinition>();",
|
|
415
|
-
),
|
|
416
|
-
);
|
|
417
|
-
yield* cbw.writeLine(
|
|
418
|
-
"export type DatabaseReader = typeof DatabaseReader.Identifier;",
|
|
419
|
-
);
|
|
420
|
-
yield* cbw.blankLine();
|
|
421
|
-
|
|
422
|
-
// DatabaseWriter
|
|
423
|
-
yield* cbw.writeLine("export const DatabaseWriter =");
|
|
424
|
-
yield* cbw.indent(
|
|
425
|
-
cbw.writeLine(
|
|
426
|
-
"DatabaseWriter_.DatabaseWriter<typeof schemaDefinition>();",
|
|
427
|
-
),
|
|
428
|
-
);
|
|
429
|
-
yield* cbw.writeLine(
|
|
430
|
-
"export type DatabaseWriter = typeof DatabaseWriter.Identifier;",
|
|
431
|
-
);
|
|
432
|
-
yield* cbw.blankLine();
|
|
433
|
-
|
|
434
|
-
// QueryRunner
|
|
435
|
-
yield* cbw.writeLine(
|
|
436
|
-
"export const QueryRunner = QueryRunner_.QueryRunner;",
|
|
437
|
-
);
|
|
438
|
-
yield* cbw.writeLine(
|
|
439
|
-
"export type QueryRunner = typeof QueryRunner.Identifier;",
|
|
440
|
-
);
|
|
441
|
-
yield* cbw.blankLine();
|
|
442
|
-
|
|
443
|
-
// MutationRunner
|
|
444
|
-
yield* cbw.writeLine(
|
|
445
|
-
"export const MutationRunner = MutationRunner_.MutationRunner;",
|
|
446
|
-
);
|
|
447
|
-
yield* cbw.writeLine(
|
|
448
|
-
"export type MutationRunner = typeof MutationRunner.Identifier;",
|
|
449
|
-
);
|
|
450
|
-
yield* cbw.blankLine();
|
|
451
|
-
|
|
452
|
-
// ActionRunner
|
|
453
|
-
yield* cbw.writeLine(
|
|
454
|
-
"export const ActionRunner = ActionRunner_.ActionRunner;",
|
|
455
|
-
);
|
|
456
|
-
yield* cbw.writeLine(
|
|
457
|
-
"export type ActionRunner = typeof ActionRunner.Identifier;",
|
|
458
|
-
);
|
|
459
|
-
yield* cbw.blankLine();
|
|
460
|
-
|
|
461
|
-
// QueryCtx
|
|
462
|
-
yield* cbw.writeLine("export const QueryCtx =");
|
|
463
|
-
yield* cbw.indent(
|
|
464
|
-
Effect.gen(function* () {
|
|
465
|
-
yield* cbw.writeLine("QueryCtx_.QueryCtx<");
|
|
466
|
-
yield* cbw.indent(
|
|
467
|
-
cbw.writeLine(
|
|
468
|
-
"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>",
|
|
469
|
-
),
|
|
470
|
-
);
|
|
471
|
-
yield* cbw.writeLine(">();");
|
|
472
|
-
}),
|
|
473
|
-
);
|
|
474
|
-
yield* cbw.writeLine("export type QueryCtx = typeof QueryCtx.Identifier;");
|
|
475
|
-
yield* cbw.blankLine();
|
|
476
|
-
|
|
477
|
-
// MutationCtx
|
|
478
|
-
yield* cbw.writeLine("export const MutationCtx =");
|
|
479
|
-
yield* cbw.indent(
|
|
480
|
-
Effect.gen(function* () {
|
|
481
|
-
yield* cbw.writeLine("MutationCtx_.MutationCtx<");
|
|
482
|
-
yield* cbw.indent(
|
|
483
|
-
cbw.writeLine(
|
|
484
|
-
"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>",
|
|
485
|
-
),
|
|
486
|
-
);
|
|
487
|
-
yield* cbw.writeLine(">();");
|
|
488
|
-
}),
|
|
489
|
-
);
|
|
490
|
-
yield* cbw.writeLine(
|
|
491
|
-
"export type MutationCtx = typeof MutationCtx.Identifier;",
|
|
492
|
-
);
|
|
493
|
-
yield* cbw.blankLine();
|
|
494
|
-
|
|
495
|
-
// ActionCtx
|
|
496
|
-
yield* cbw.writeLine("export const ActionCtx =");
|
|
497
|
-
yield* cbw.indent(
|
|
498
|
-
Effect.gen(function* () {
|
|
499
|
-
yield* cbw.writeLine("ActionCtx_.ActionCtx<");
|
|
500
|
-
yield* cbw.indent(
|
|
501
|
-
cbw.writeLine(
|
|
502
|
-
"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>",
|
|
503
|
-
),
|
|
504
|
-
);
|
|
505
|
-
yield* cbw.writeLine(">();");
|
|
506
|
-
}),
|
|
507
|
-
);
|
|
508
|
-
yield* cbw.writeLine(
|
|
509
|
-
"export type ActionCtx = typeof ActionCtx.Identifier;",
|
|
510
|
-
);
|
|
511
|
-
|
|
512
|
-
return yield* cbw.toString();
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
const writeChildAddGroupAt = (
|
|
516
|
-
cbw: CodeBlockWriter,
|
|
517
|
-
child: SpecAssemblyNode,
|
|
518
|
-
groupFactory: string,
|
|
519
|
-
): Effect.Effect<void> =>
|
|
520
|
-
Effect.gen(function* () {
|
|
521
|
-
yield* cbw.write(".addGroupAt(");
|
|
522
|
-
yield* cbw.quote(child.segment);
|
|
523
|
-
yield* cbw.write(", ");
|
|
524
|
-
yield* writeGroupAssembly(cbw, child, groupFactory);
|
|
525
|
-
yield* cbw.write(")");
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
const writeGroupFactoryCall = (
|
|
529
|
-
cbw: CodeBlockWriter,
|
|
530
|
-
node: SpecAssemblyNode,
|
|
531
|
-
groupFactory: string,
|
|
532
|
-
): Effect.Effect<void> =>
|
|
533
|
-
Effect.gen(function* () {
|
|
534
|
-
yield* cbw.write(groupFactory);
|
|
535
|
-
yield* cbw.write("(");
|
|
536
|
-
yield* cbw.quote(node.segment);
|
|
537
|
-
yield* cbw.write(")");
|
|
538
|
-
|
|
539
|
-
yield* Effect.forEach(node.children, (child) =>
|
|
540
|
-
writeChildAddGroupAt(cbw, child, groupFactory),
|
|
541
|
-
);
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
const writeGroupAssembly: (
|
|
545
|
-
cbw: CodeBlockWriter,
|
|
546
|
-
node: SpecAssemblyNode,
|
|
547
|
-
groupFactory: string,
|
|
548
|
-
) => Effect.Effect<void> = (cbw, node, groupFactory) =>
|
|
549
|
-
Option.match(node.importBinding, {
|
|
550
|
-
onNone: () => writeGroupFactoryCall(cbw, node, groupFactory),
|
|
551
|
-
onSome: (binding) =>
|
|
552
|
-
Effect.gen(function* () {
|
|
553
|
-
yield* cbw.write(binding.localName);
|
|
554
|
-
yield* Effect.forEach(node.children, (child) =>
|
|
555
|
-
writeChildAddGroupAt(cbw, child, groupFactory),
|
|
556
|
-
);
|
|
557
|
-
}),
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
const writeRootAddAt = (
|
|
561
|
-
cbw: CodeBlockWriter,
|
|
562
|
-
node: SpecAssemblyNode,
|
|
563
|
-
groupFactory: string,
|
|
564
|
-
): Effect.Effect<void> =>
|
|
565
|
-
Effect.gen(function* () {
|
|
566
|
-
yield* cbw.write(".addAt(");
|
|
567
|
-
yield* cbw.quote(node.segment);
|
|
568
|
-
yield* cbw.write(", ");
|
|
569
|
-
|
|
570
|
-
yield* writeGroupAssembly(cbw, node, groupFactory);
|
|
571
|
-
|
|
572
|
-
yield* cbw.write(")");
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
export const assembledSpec = ({
|
|
576
|
-
nodes,
|
|
577
|
-
}: {
|
|
578
|
-
nodes: ReadonlyArray<SpecAssemblyNode>;
|
|
579
|
-
}) =>
|
|
580
|
-
Effect.gen(function* () {
|
|
581
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
582
|
-
|
|
583
|
-
const nodeRequiresGroupFactory = (node: SpecAssemblyNode): boolean =>
|
|
584
|
-
Option.isNone(node.importBinding) ||
|
|
585
|
-
Array.some(node.children, nodeRequiresGroupFactory);
|
|
586
|
-
|
|
587
|
-
const needsGroupSpec = Array.some(nodes, nodeRequiresGroupFactory);
|
|
588
|
-
yield* cbw.writeLine(
|
|
589
|
-
needsGroupSpec
|
|
590
|
-
? `import { GroupSpec, Spec } from "@confect/core";`
|
|
591
|
-
: `import { Spec } from "@confect/core";`,
|
|
592
|
-
);
|
|
593
|
-
|
|
594
|
-
yield* Effect.forEach(collectImportBindings(nodes), (binding) =>
|
|
595
|
-
cbw.writeLine(
|
|
596
|
-
`import ${binding.localName} from "${binding.importPath}";`,
|
|
597
|
-
),
|
|
598
|
-
);
|
|
599
|
-
|
|
600
|
-
yield* cbw.blankLine();
|
|
601
|
-
|
|
602
|
-
// The assembled spec is runtime-agnostic: a Node group's `makeNode()` is
|
|
603
|
-
// already baked into its imported leaf spec, so the root is always
|
|
604
|
-
// `Spec.make()` and binding-less container groups always use
|
|
605
|
-
// `GroupSpec.makeAt` (containers register no functions and carry no runtime).
|
|
606
|
-
yield* cbw.write(`export default Spec.make()`);
|
|
607
|
-
yield* Effect.forEach(nodes, (node) =>
|
|
608
|
-
writeRootAddAt(cbw, node, "GroupSpec.makeAt"),
|
|
609
|
-
);
|
|
610
|
-
yield* cbw.write(";");
|
|
611
|
-
yield* cbw.newLine();
|
|
612
|
-
|
|
613
|
-
return yield* cbw.toString();
|
|
614
|
-
});
|