@confect/cli 9.0.0-next.4 → 9.0.0-next.6
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 +178 -0
- package/dist/Bundler.mjs +63 -72
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodegenError.mjs +22 -9
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/LeafModule.mjs +2 -2
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +1 -19
- package/dist/SpecAssemblyNode.mjs.map +1 -1
- package/dist/TableModule.mjs +90 -0
- package/dist/TableModule.mjs.map +1 -0
- package/dist/confect/codegen.mjs +175 -78
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/dev.mjs +15 -12
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/log.mjs +4 -3
- package/dist/log.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/dist/templates.mjs +123 -34
- package/dist/templates.mjs.map +1 -1
- package/package.json +42 -42
- package/src/Bundler.ts +67 -90
- package/src/CodegenError.ts +90 -28
- package/src/LeafModule.ts +1 -1
- package/src/SpecAssemblyNode.ts +0 -36
- package/src/TableModule.ts +153 -0
- package/src/confect/codegen.ts +323 -132
- package/src/confect/dev.ts +52 -10
- package/src/log.ts +4 -2
- package/src/templates.ts +200 -59
package/dist/templates.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CodeBlockWriter } from "./CodeBlockWriter.mjs";
|
|
2
|
-
import { collectImportBindings
|
|
2
|
+
import { collectImportBindings } from "./SpecAssemblyNode.mjs";
|
|
3
3
|
import { Array, Effect, Option } from "effect";
|
|
4
4
|
|
|
5
5
|
//#region src/templates.ts
|
|
@@ -14,11 +14,123 @@ const functions = ({ functionNames, registeredFunctionsImportPath, useNode = fal
|
|
|
14
14
|
yield* Effect.forEach(functionNames, (functionName) => cbw.writeLine(`export const ${functionName} = registeredFunctions.${functionName};`));
|
|
15
15
|
return yield* cbw.toString();
|
|
16
16
|
});
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Emit `convex/schema.ts` as a one-line re-export of the codegen-emitted
|
|
19
|
+
* deploy schema in `confect/_generated/convexSchema.ts`. Deploy-time
|
|
20
|
+
* consumers (the Convex CLI, `convex-test`) keep reading
|
|
21
|
+
* `convex/schema.ts`; the runtime `DatabaseSchema` in
|
|
22
|
+
* `confect/_generated/schema.ts` is untouched by this file.
|
|
23
|
+
*/
|
|
24
|
+
const schema = ({ convexSchemaImportPath }) => Effect.gen(function* () {
|
|
18
25
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
19
|
-
yield* cbw.writeLine(`
|
|
20
|
-
yield* cbw.
|
|
21
|
-
|
|
26
|
+
yield* cbw.writeLine(`export { default } from "${convexSchemaImportPath}";`);
|
|
27
|
+
return yield* cbw.toString();
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Emit `confect/_generated/schema.ts` — the runtime `DatabaseSchema` used
|
|
31
|
+
* by impls and the per-group registries (and downstream by per-function
|
|
32
|
+
* bundles for codec lookup). Every table wrapper at
|
|
33
|
+
* `confect/_generated/tables/<name>.ts` is imported statically and
|
|
34
|
+
* registered as a value entry on the `DatabaseSchema.make({...})` call.
|
|
35
|
+
* Per-table laziness lives inside each `Table`: its `Fields`, `Doc`, and
|
|
36
|
+
* `tableDefinition` are lazy memoised getters that only evaluate the
|
|
37
|
+
* user-supplied field-schema callback on first access, so unused tables in
|
|
38
|
+
* a function bundle never pay schema-construction cost despite the
|
|
39
|
+
* static import.
|
|
40
|
+
*
|
|
41
|
+
* The `DatabaseSchema` import is aliased to `$DatabaseSchema` because each
|
|
42
|
+
* table is imported under its own (filename-derived) name; a table named
|
|
43
|
+
* `DatabaseSchema` would otherwise collide with the library import and emit
|
|
44
|
+
* a duplicate-binding file. The leading `$` makes the alias collision-proof:
|
|
45
|
+
* `validateConfectTableIdentifier` requires names to match
|
|
46
|
+
* `/^[a-zA-Z][a-zA-Z0-9_]*$/`, which forbids `$`, so no valid table import
|
|
47
|
+
* can ever shadow it.
|
|
48
|
+
*/
|
|
49
|
+
const runtimeSchema = ({ tableModules }) => Effect.gen(function* () {
|
|
50
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
51
|
+
yield* cbw.writeLine(`import { DatabaseSchema as $DatabaseSchema } from "@confect/server";`);
|
|
52
|
+
if (tableModules.length > 0) {
|
|
53
|
+
yield* cbw.blankLine();
|
|
54
|
+
yield* Effect.forEach(tableModules, ({ tableName, importPath }) => cbw.writeLine(`import ${tableName} from "${importPath}";`));
|
|
55
|
+
}
|
|
56
|
+
yield* cbw.blankLine();
|
|
57
|
+
if (tableModules.length === 0) yield* cbw.writeLine(`export default $DatabaseSchema.make({});`);
|
|
58
|
+
else {
|
|
59
|
+
yield* cbw.writeLine(`export default $DatabaseSchema.make({`);
|
|
60
|
+
yield* cbw.indent(Effect.gen(function* () {
|
|
61
|
+
for (const { tableName } of tableModules) yield* cbw.writeLine(`${tableName},`);
|
|
62
|
+
}));
|
|
63
|
+
yield* cbw.writeLine(`});`);
|
|
64
|
+
}
|
|
65
|
+
return yield* cbw.toString();
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Emit `confect/_generated/convexSchema.ts` — the Convex deploy-time
|
|
69
|
+
* `SchemaDefinition`. Imports every table from its generated wrapper at
|
|
70
|
+
* `_generated/tables/<name>` and calls `defineSchema({...})` exactly once.
|
|
71
|
+
* The file deliberately avoids any `@confect/server` import so that the
|
|
72
|
+
* deploy artifact's import graph stays decoupled from the runtime
|
|
73
|
+
* `DatabaseSchema` machinery.
|
|
74
|
+
*
|
|
75
|
+
* The `defineSchema` import is aliased to `$defineSchema` because each table
|
|
76
|
+
* is imported under its own (filename-derived) name; a table named
|
|
77
|
+
* `defineSchema` would otherwise collide with the library import and emit a
|
|
78
|
+
* duplicate-binding file. The leading `$` makes the alias collision-proof:
|
|
79
|
+
* `validateConfectTableIdentifier` requires names to match
|
|
80
|
+
* `/^[a-zA-Z][a-zA-Z0-9_]*$/`, which forbids `$`, so no valid table import
|
|
81
|
+
* can ever shadow it.
|
|
82
|
+
*/
|
|
83
|
+
const convexSchema = ({ tableModules }) => Effect.gen(function* () {
|
|
84
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
85
|
+
yield* cbw.writeLine(`import { defineSchema as $defineSchema } from "convex/server";`);
|
|
86
|
+
if (tableModules.length > 0) {
|
|
87
|
+
yield* cbw.blankLine();
|
|
88
|
+
yield* Effect.forEach(tableModules, ({ tableName, importPath }) => cbw.writeLine(`import ${tableName} from "${importPath}";`));
|
|
89
|
+
}
|
|
90
|
+
yield* cbw.blankLine();
|
|
91
|
+
if (tableModules.length === 0) yield* cbw.writeLine(`export default $defineSchema({});`);
|
|
92
|
+
else {
|
|
93
|
+
yield* cbw.writeLine(`export default $defineSchema({`);
|
|
94
|
+
yield* cbw.indent(Effect.gen(function* () {
|
|
95
|
+
for (const { tableName } of tableModules) yield* cbw.writeLine(`${tableName}: ${tableName}.tableDefinition,`);
|
|
96
|
+
}));
|
|
97
|
+
yield* cbw.writeLine(`});`);
|
|
98
|
+
}
|
|
99
|
+
return yield* cbw.toString();
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Emit `confect/_generated/id.ts` — a type-constrained `Id` constructor and
|
|
103
|
+
* a `TableNames` union derived from the user's `confect/tables/*.ts`
|
|
104
|
+
* filenames. User-authored table modules import `Id` from this file to
|
|
105
|
+
* declare cross-table id references without typing the destination name as
|
|
106
|
+
* a free string (and without ever importing each other transitively).
|
|
107
|
+
*
|
|
108
|
+
* When the table directory is empty the `TableNames` union resolves to
|
|
109
|
+
* `never`, which still lets the file typecheck against an empty workspace.
|
|
110
|
+
*/
|
|
111
|
+
const id = ({ tableNames }) => Effect.gen(function* () {
|
|
112
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
113
|
+
yield* cbw.writeLine(`import { GenericId } from "@confect/core";`);
|
|
114
|
+
yield* cbw.blankLine();
|
|
115
|
+
const union = tableNames.length === 0 ? "never" : tableNames.map((n) => `"${n}"`).join(" | ");
|
|
116
|
+
yield* cbw.writeLine(`export type TableNames = ${union};`);
|
|
117
|
+
yield* cbw.blankLine();
|
|
118
|
+
yield* cbw.writeLine(`export const Id = <const TableName extends TableNames>(`);
|
|
119
|
+
yield* cbw.indent(cbw.writeLine(`tableName: TableName,`));
|
|
120
|
+
yield* cbw.writeLine(`) => GenericId.GenericId(tableName);`);
|
|
121
|
+
return yield* cbw.toString();
|
|
122
|
+
});
|
|
123
|
+
/**
|
|
124
|
+
* Emit `confect/_generated/tables/<tableName>.ts` — a two-line wrapper that
|
|
125
|
+
* imports the user-authored `UnnamedTable` and binds the file basename to
|
|
126
|
+
* it, producing the fully-named `Table` value that downstream consumers
|
|
127
|
+
* (schema, specs, impls) read.
|
|
128
|
+
*/
|
|
129
|
+
const tableWrapper = ({ tableName, unnamedImportPath }) => Effect.gen(function* () {
|
|
130
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
131
|
+
yield* cbw.writeLine(`import unnamed from "${unnamedImportPath}";`);
|
|
132
|
+
yield* cbw.blankLine();
|
|
133
|
+
yield* cbw.writeLine(`export default unnamed("${tableName}");`);
|
|
22
134
|
return yield* cbw.toString();
|
|
23
135
|
});
|
|
24
136
|
const http = ({ httpImportPath }) => Effect.gen(function* () {
|
|
@@ -57,36 +169,18 @@ const refs = ({ specImportPath, nodeSpecImportPath }) => Effect.gen(function* ()
|
|
|
57
169
|
}));
|
|
58
170
|
return yield* cbw.toString();
|
|
59
171
|
});
|
|
60
|
-
const
|
|
61
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
62
|
-
yield* cbw.writeLine(`import { Api } from "@confect/server";`);
|
|
63
|
-
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
64
|
-
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
65
|
-
yield* cbw.blankLine();
|
|
66
|
-
yield* cbw.writeLine(`export default Api.make(schema, spec);`);
|
|
67
|
-
return yield* cbw.toString();
|
|
68
|
-
});
|
|
69
|
-
const nodeApi = ({ schemaImportPath, nodeSpecImportPath }) => Effect.gen(function* () {
|
|
70
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
71
|
-
yield* cbw.writeLine(`import { Api } from "@confect/server";`);
|
|
72
|
-
yield* cbw.blankLine();
|
|
73
|
-
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
74
|
-
yield* cbw.writeLine(`import nodeSpec from "${nodeSpecImportPath}";`);
|
|
75
|
-
yield* cbw.blankLine();
|
|
76
|
-
yield* cbw.writeLine(`export default Api.make(schema, nodeSpec);`);
|
|
77
|
-
return yield* cbw.toString();
|
|
78
|
-
});
|
|
79
|
-
const registeredFunctionsForGroup = ({ apiImportPath, groupPathDot, implImportPath, layerExportName, useNode = false }) => Effect.gen(function* () {
|
|
172
|
+
const registeredFunctionsForGroup = ({ schemaImportPath, specImportPath, implImportPath, layerExportName, useNode = false }) => Effect.gen(function* () {
|
|
80
173
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
81
174
|
if (useNode) {
|
|
82
175
|
yield* cbw.writeLine(`import { RegisteredFunctions } from "@confect/server";`);
|
|
83
176
|
yield* cbw.writeLine(`import { RegisteredNodeFunction } from "@confect/server/node";`);
|
|
84
177
|
} else yield* cbw.writeLine(`import { RegisteredConvexFunction, RegisteredFunctions } from "@confect/server";`);
|
|
85
|
-
yield* cbw.writeLine(`import
|
|
178
|
+
yield* cbw.writeLine(`import databaseSchema from "${schemaImportPath}";`);
|
|
86
179
|
yield* cbw.writeLine(`import ${layerExportName} from "${implImportPath}";`);
|
|
87
180
|
yield* cbw.blankLine();
|
|
88
|
-
const
|
|
89
|
-
|
|
181
|
+
const specType = `typeof import("${specImportPath}")["default"]`;
|
|
182
|
+
const makeFn = useNode ? "RegisteredNodeFunction.make" : "RegisteredConvexFunction.make";
|
|
183
|
+
yield* cbw.writeLine(`export default RegisteredFunctions.buildForGroup<${specType}>(databaseSchema, ${layerExportName}, ${makeFn});`);
|
|
90
184
|
return yield* cbw.toString();
|
|
91
185
|
});
|
|
92
186
|
const services = ({ schemaImportPath }) => Effect.gen(function* () {
|
|
@@ -211,11 +305,6 @@ const assembledSpec = ({ nodes, runtime }) => Effect.gen(function* () {
|
|
|
211
305
|
const specFactory = runtime === "Convex" ? "Spec.make()" : "Spec.makeNode()";
|
|
212
306
|
const groupFactory = runtime === "Convex" ? "GroupSpec.makeAt" : "GroupSpec.makeNodeAt";
|
|
213
307
|
yield* cbw.write(`export default ${specFactory}`);
|
|
214
|
-
yield* Effect.forEach(collectLeafPaths(nodes), (leaf) => Effect.gen(function* () {
|
|
215
|
-
yield* cbw.write(`.addPath(${leaf.binding.localName}, `);
|
|
216
|
-
yield* cbw.quote(leaf.dotPath);
|
|
217
|
-
yield* cbw.write(")");
|
|
218
|
-
}));
|
|
219
308
|
yield* Effect.forEach(nodes, (node) => writeRootAddAt(cbw, node, groupFactory));
|
|
220
309
|
yield* cbw.write(";");
|
|
221
310
|
yield* cbw.newLine();
|
|
@@ -223,5 +312,5 @@ const assembledSpec = ({ nodes, runtime }) => Effect.gen(function* () {
|
|
|
223
312
|
});
|
|
224
313
|
|
|
225
314
|
//#endregion
|
|
226
|
-
export {
|
|
315
|
+
export { assembledSpec, authConfig, convexSchema, crons, functions, http, id, refs, registeredFunctionsForGroup, runtimeSchema, schema, services, tableWrapper };
|
|
227
316
|
//# sourceMappingURL=templates.mjs.map
|
package/dist/templates.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.mjs","names":[],"sources":["../src/templates.ts"],"sourcesContent":["import { Array, Effect, Option } from \"effect\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter\";\nimport {\n collectImportBindings,\n collectLeafPaths,\n type SpecAssemblyNode,\n} from \"./SpecAssemblyNode\";\n\nexport const functions = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n functionNames: string[];\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(`\"use node\";`);\n yield* cbw.blankLine();\n }\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n yield* Effect.forEach(functionNames, (functionName) =>\n cbw.writeLine(\n `export const ${functionName} = registeredFunctions.${functionName};`,\n ),\n );\n\n return yield* cbw.toString();\n });\n\nexport const schema = ({ schemaImportPath }: { schemaImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import schemaDefinition from \"${schemaImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(\n `export default schemaDefinition.convexSchemaDefinition;`,\n );\n\n return yield* cbw.toString();\n });\n\nexport const http = ({ httpImportPath }: { httpImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import http from \"${httpImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default http;`);\n\n return yield* cbw.toString();\n });\n\nexport const crons = ({ cronsImportPath }: { cronsImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import crons from \"${cronsImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default crons.convexCronJobs;`);\n\n return yield* cbw.toString();\n });\n\nexport const authConfig = ({ authImportPath }: { authImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import auth from \"${authImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default auth;`);\n\n return yield* cbw.toString();\n });\n\nexport const refs = ({\n specImportPath,\n nodeSpecImportPath,\n}: {\n specImportPath: string;\n nodeSpecImportPath: Option.Option<string>;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { Refs } from \"@confect/core\";`);\n yield* cbw.writeLine(`import spec from \"${specImportPath}\";`);\n yield* Option.match(nodeSpecImportPath, {\n onNone: () => Effect.void,\n onSome: (nodeSpecImportPath_) =>\n cbw.writeLine(`import nodeSpec from \"${nodeSpecImportPath_}\";`),\n });\n yield* cbw.blankLine();\n yield* cbw.writeLine(\n Option.match(nodeSpecImportPath, {\n onSome: () => `export default Refs.make(spec, nodeSpec);`,\n onNone: () => `export default Refs.make(spec);`,\n }),\n );\n\n return yield* cbw.toString();\n });\n\nexport const api = ({\n schemaImportPath,\n specImportPath,\n}: {\n schemaImportPath: string;\n specImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { Api } from \"@confect/server\";`);\n yield* cbw.writeLine(`import schema from \"${schemaImportPath}\";`);\n yield* cbw.writeLine(`import spec from \"${specImportPath}\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(`export default Api.make(schema, spec);`);\n\n return yield* cbw.toString();\n });\n\nexport const nodeApi = ({\n schemaImportPath,\n nodeSpecImportPath,\n}: {\n schemaImportPath: string;\n nodeSpecImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { Api } from \"@confect/server\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(`import schema from \"${schemaImportPath}\";`);\n yield* cbw.writeLine(`import nodeSpec from \"${nodeSpecImportPath}\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(`export default Api.make(schema, nodeSpec);`);\n\n return yield* cbw.toString();\n });\n\nexport const registeredFunctionsForGroup = ({\n apiImportPath,\n groupPathDot,\n implImportPath,\n layerExportName,\n useNode = false,\n}: {\n apiImportPath: string;\n groupPathDot: string;\n implImportPath: string;\n layerExportName: string;\n useNode?: boolean;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(\n `import { RegisteredFunctions } from \"@confect/server\";`,\n );\n yield* cbw.writeLine(\n `import { RegisteredNodeFunction } from \"@confect/server/node\";`,\n );\n } else {\n yield* cbw.writeLine(\n `import { RegisteredConvexFunction, RegisteredFunctions } from \"@confect/server\";`,\n );\n }\n\n yield* cbw.writeLine(`import api from \"${apiImportPath}\";`);\n yield* cbw.writeLine(`import ${layerExportName} from \"${implImportPath}\";`);\n yield* cbw.blankLine();\n const quotedGroupPath = `\"${groupPathDot.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"')}\"`;\n yield* cbw.writeLine(\n useNode\n ? `export default RegisteredFunctions.buildForGroup(api, ${quotedGroupPath}, ${layerExportName}, RegisteredNodeFunction.make);`\n : `export default RegisteredFunctions.buildForGroup(api, ${quotedGroupPath}, ${layerExportName}, RegisteredConvexFunction.make);`,\n );\n\n return yield* cbw.toString();\n });\n\nexport const services = ({ schemaImportPath }: { schemaImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n // Imports\n yield* cbw.writeLine(\"import {\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"ActionCtx as ActionCtx_,\");\n yield* cbw.writeLine(\"ActionRunner as ActionRunner_,\");\n yield* cbw.writeLine(\"Auth as Auth_,\");\n yield* cbw.writeLine(\"type DataModel,\");\n yield* cbw.writeLine(\"DatabaseReader as DatabaseReader_,\");\n yield* cbw.writeLine(\"DatabaseWriter as DatabaseWriter_,\");\n yield* cbw.writeLine(\"MutationCtx as MutationCtx_,\");\n yield* cbw.writeLine(\"MutationRunner as MutationRunner_,\");\n yield* cbw.writeLine(\"QueryCtx as QueryCtx_,\");\n yield* cbw.writeLine(\"QueryRunner as QueryRunner_,\");\n yield* cbw.writeLine(\"Scheduler as Scheduler_,\");\n yield* cbw.writeLine(\"StorageActionWriter as StorageActionWriter_,\");\n yield* cbw.writeLine(\"StorageReader as StorageReader_,\");\n yield* cbw.writeLine(\"StorageWriter as StorageWriter_,\");\n yield* cbw.writeLine(\"VectorSearch as VectorSearch_,\");\n }),\n );\n yield* cbw.writeLine(`} from \"@confect/server\";`);\n yield* cbw.writeLine(\n `import type schemaDefinition from \"${schemaImportPath}\";`,\n );\n yield* cbw.blankLine();\n\n // Auth\n yield* cbw.writeLine(\"export const Auth = Auth_.Auth;\");\n yield* cbw.writeLine(\"export type Auth = typeof Auth.Identifier;\");\n yield* cbw.blankLine();\n\n // Scheduler\n yield* cbw.writeLine(\"export const Scheduler = Scheduler_.Scheduler;\");\n yield* cbw.writeLine(\n \"export type Scheduler = typeof Scheduler.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageReader\n yield* cbw.writeLine(\n \"export const StorageReader = StorageReader_.StorageReader;\",\n );\n yield* cbw.writeLine(\n \"export type StorageReader = typeof StorageReader.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageWriter\n yield* cbw.writeLine(\n \"export const StorageWriter = StorageWriter_.StorageWriter;\",\n );\n yield* cbw.writeLine(\n \"export type StorageWriter = typeof StorageWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageActionWriter\n yield* cbw.writeLine(\n \"export const StorageActionWriter = StorageActionWriter_.StorageActionWriter;\",\n );\n yield* cbw.writeLine(\n \"export type StorageActionWriter = typeof StorageActionWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // VectorSearch\n yield* cbw.writeLine(\"export const VectorSearch =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type VectorSearch = typeof VectorSearch.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // DatabaseReader\n yield* cbw.writeLine(\"export const DatabaseReader =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DatabaseReader_.DatabaseReader<typeof schemaDefinition>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type DatabaseReader = typeof DatabaseReader.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // DatabaseWriter\n yield* cbw.writeLine(\"export const DatabaseWriter =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DatabaseWriter_.DatabaseWriter<typeof schemaDefinition>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type DatabaseWriter = typeof DatabaseWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // QueryRunner\n yield* cbw.writeLine(\n \"export const QueryRunner = QueryRunner_.QueryRunner;\",\n );\n yield* cbw.writeLine(\n \"export type QueryRunner = typeof QueryRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // MutationRunner\n yield* cbw.writeLine(\n \"export const MutationRunner = MutationRunner_.MutationRunner;\",\n );\n yield* cbw.writeLine(\n \"export type MutationRunner = typeof MutationRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // ActionRunner\n yield* cbw.writeLine(\n \"export const ActionRunner = ActionRunner_.ActionRunner;\",\n );\n yield* cbw.writeLine(\n \"export type ActionRunner = typeof ActionRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // QueryCtx\n yield* cbw.writeLine(\"export const QueryCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"QueryCtx_.QueryCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\"export type QueryCtx = typeof QueryCtx.Identifier;\");\n yield* cbw.blankLine();\n\n // MutationCtx\n yield* cbw.writeLine(\"export const MutationCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"MutationCtx_.MutationCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\n \"export type MutationCtx = typeof MutationCtx.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // ActionCtx\n yield* cbw.writeLine(\"export const ActionCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"ActionCtx_.ActionCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\n \"export type ActionCtx = typeof ActionCtx.Identifier;\",\n );\n\n return yield* cbw.toString();\n });\n\nconst writeChildAddGroupAt = (\n cbw: CodeBlockWriter,\n child: SpecAssemblyNode,\n groupFactory: string,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n yield* cbw.write(\".addGroupAt(\");\n yield* cbw.quote(child.segment);\n yield* cbw.write(\", \");\n yield* writeGroupAssembly(cbw, child, groupFactory);\n yield* cbw.write(\")\");\n });\n\nconst writeGroupFactoryCall = (\n cbw: CodeBlockWriter,\n node: SpecAssemblyNode,\n groupFactory: string,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n yield* cbw.write(groupFactory);\n yield* cbw.write(\"(\");\n yield* cbw.quote(node.segment);\n yield* cbw.write(\")\");\n\n yield* Effect.forEach(node.children, (child) =>\n writeChildAddGroupAt(cbw, child, groupFactory),\n );\n });\n\nconst writeGroupAssembly: (\n cbw: CodeBlockWriter,\n node: SpecAssemblyNode,\n groupFactory: string,\n) => Effect.Effect<void> = (cbw, node, groupFactory) =>\n Option.match(node.importBinding, {\n onNone: () => writeGroupFactoryCall(cbw, node, groupFactory),\n onSome: (binding) =>\n Effect.gen(function* () {\n yield* cbw.write(binding.localName);\n yield* Effect.forEach(node.children, (child) =>\n writeChildAddGroupAt(cbw, child, groupFactory),\n );\n }),\n });\n\nconst writeRootAddAt = (\n cbw: CodeBlockWriter,\n node: SpecAssemblyNode,\n groupFactory: string,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n yield* cbw.write(\".addAt(\");\n yield* cbw.quote(node.segment);\n yield* cbw.write(\", \");\n\n yield* writeGroupAssembly(cbw, node, groupFactory);\n\n yield* cbw.write(\")\");\n });\n\nexport const assembledSpec = ({\n nodes,\n runtime,\n}: {\n nodes: ReadonlyArray<SpecAssemblyNode>;\n runtime: \"Convex\" | \"Node\";\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n const nodeRequiresGroupFactory = (node: SpecAssemblyNode): boolean =>\n Option.isNone(node.importBinding) ||\n Array.some(node.children, nodeRequiresGroupFactory);\n\n const needsGroupSpec = Array.some(nodes, nodeRequiresGroupFactory);\n yield* cbw.writeLine(\n needsGroupSpec\n ? `import { GroupSpec, Spec } from \"@confect/core\";`\n : `import { Spec } from \"@confect/core\";`,\n );\n\n yield* Effect.forEach(collectImportBindings(nodes), (binding) =>\n cbw.writeLine(\n `import ${binding.localName} from \"${binding.importPath}\";`,\n ),\n );\n\n yield* cbw.blankLine();\n\n const specFactory =\n runtime === \"Convex\" ? \"Spec.make()\" : \"Spec.makeNode()\";\n const groupFactory =\n runtime === \"Convex\" ? \"GroupSpec.makeAt\" : \"GroupSpec.makeNodeAt\";\n\n yield* cbw.write(`export default ${specFactory}`);\n yield* Effect.forEach(collectLeafPaths(nodes), (leaf) =>\n Effect.gen(function* () {\n yield* cbw.write(`.addPath(${leaf.binding.localName}, `);\n yield* cbw.quote(leaf.dotPath);\n yield* cbw.write(\")\");\n }),\n );\n yield* Effect.forEach(nodes, (node) =>\n writeRootAddAt(cbw, node, groupFactory),\n );\n yield* cbw.write(\";\");\n yield* cbw.newLine();\n\n return yield* cbw.toString();\n });\n"],"mappings":";;;;;AAQA,MAAa,aAAa,EACxB,eACA,+BACA,UAAU,YAMV,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,KAAI,SAAS;AACX,SAAO,IAAI,UAAU,cAAc;AACnC,SAAO,IAAI,WAAW;;AAGxB,QAAO,IAAI,UACT,oCAAoC,8BAA8B,IACnE;AACD,QAAO,IAAI,SAAS;AACpB,QAAO,OAAO,QAAQ,gBAAgB,iBACpC,IAAI,UACF,gBAAgB,aAAa,yBAAyB,aAAa,GACpE,CACF;AAED,QAAO,OAAO,IAAI,UAAU;EAC5B;AAEJ,MAAa,UAAU,EAAE,uBACvB,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,QAAO,IAAI,UAAU,iCAAiC,iBAAiB,IAAI;AAC3E,QAAO,IAAI,SAAS;AACpB,QAAO,IAAI,UACT,0DACD;AAED,QAAO,OAAO,IAAI,UAAU;EAC5B;AAEJ,MAAa,QAAQ,EAAE,qBACrB,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,QAAO,IAAI,UAAU,qBAAqB,eAAe,IAAI;AAC7D,QAAO,IAAI,SAAS;AACpB,QAAO,IAAI,UAAU,uBAAuB;AAE5C,QAAO,OAAO,IAAI,UAAU;EAC5B;AAEJ,MAAa,SAAS,EAAE,sBACtB,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,QAAO,IAAI,UAAU,sBAAsB,gBAAgB,IAAI;AAC/D,QAAO,IAAI,SAAS;AACpB,QAAO,IAAI,UAAU,uCAAuC;AAE5D,QA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D,QAAO,OAAO,QAAQ,iBAAiB,MAAM,GAAG,SAC9C,OAAO,IAAI,aAAa;AACtB,SAAO,IAAI,MAAM,YAAY,KAAK,QAAQ,UAAU,IAAI;AACxD,SAAO,IAAI,MAAM,KAAK,QAAQ;AAC9B,SAAO,IAAI,MAAM,IAAI;GACrB,CACH;AACD,QAAO,OAAO,QAAQ,QAAQ,SAC5B,eAAe,KAAK,MAAM,aAAa,CACxC;AACD,QAAO,IAAI,MAAM,IAAI;AACrB,QAAO,IAAI,SAAS;AAEpB,QAAO,OAAO,IAAI,UAAU;EAC5B"}
|
|
1
|
+
{"version":3,"file":"templates.mjs","names":[],"sources":["../src/templates.ts"],"sourcesContent":["import { Array, Effect, Option } from \"effect\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter\";\nimport {\n collectImportBindings,\n type SpecAssemblyNode,\n} from \"./SpecAssemblyNode\";\n\nexport const functions = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n functionNames: string[];\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(`\"use node\";`);\n yield* cbw.blankLine();\n }\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n yield* Effect.forEach(functionNames, (functionName) =>\n cbw.writeLine(\n `export const ${functionName} = registeredFunctions.${functionName};`,\n ),\n );\n\n return yield* cbw.toString();\n });\n\n/**\n * Emit `convex/schema.ts` as a one-line re-export of the codegen-emitted\n * deploy schema in `confect/_generated/convexSchema.ts`. Deploy-time\n * consumers (the Convex CLI, `convex-test`) keep reading\n * `convex/schema.ts`; the runtime `DatabaseSchema` in\n * `confect/_generated/schema.ts` is untouched by this file.\n */\nexport const schema = ({\n convexSchemaImportPath,\n}: {\n convexSchemaImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(\n `export { default } from \"${convexSchemaImportPath}\";`,\n );\n\n return yield* cbw.toString();\n });\n\ninterface TableModuleBinding {\n readonly importPath: string;\n readonly tableName: string;\n}\n\n/**\n * Emit `confect/_generated/schema.ts` — the runtime `DatabaseSchema` used\n * by impls and the per-group registries (and downstream by per-function\n * bundles for codec lookup). Every table wrapper at\n * `confect/_generated/tables/<name>.ts` is imported statically and\n * registered as a value entry on the `DatabaseSchema.make({...})` call.\n * Per-table laziness lives inside each `Table`: its `Fields`, `Doc`, and\n * `tableDefinition` are lazy memoised getters that only evaluate the\n * user-supplied field-schema callback on first access, so unused tables in\n * a function bundle never pay schema-construction cost despite the\n * static import.\n *\n * The `DatabaseSchema` import is aliased to `$DatabaseSchema` because each\n * table is imported under its own (filename-derived) name; a table named\n * `DatabaseSchema` would otherwise collide with the library import and emit\n * a duplicate-binding file. The leading `$` makes the alias collision-proof:\n * `validateConfectTableIdentifier` requires names to match\n * `/^[a-zA-Z][a-zA-Z0-9_]*$/`, which forbids `$`, so no valid table import\n * can ever shadow it.\n */\nexport const runtimeSchema = ({\n tableModules,\n}: {\n tableModules: ReadonlyArray<TableModuleBinding>;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(\n `import { DatabaseSchema as $DatabaseSchema } from \"@confect/server\";`,\n );\n\n if (tableModules.length > 0) {\n yield* cbw.blankLine();\n yield* Effect.forEach(tableModules, ({ tableName, importPath }) =>\n cbw.writeLine(`import ${tableName} from \"${importPath}\";`),\n );\n }\n\n yield* cbw.blankLine();\n\n if (tableModules.length === 0) {\n yield* cbw.writeLine(`export default $DatabaseSchema.make({});`);\n } else {\n yield* cbw.writeLine(`export default $DatabaseSchema.make({`);\n yield* cbw.indent(\n Effect.gen(function* () {\n for (const { tableName } of tableModules) {\n yield* cbw.writeLine(`${tableName},`);\n }\n }),\n );\n yield* cbw.writeLine(`});`);\n }\n\n return yield* cbw.toString();\n });\n\n/**\n * Emit `confect/_generated/convexSchema.ts` — the Convex deploy-time\n * `SchemaDefinition`. Imports every table from its generated wrapper at\n * `_generated/tables/<name>` and calls `defineSchema({...})` exactly once.\n * The file deliberately avoids any `@confect/server` import so that the\n * deploy artifact's import graph stays decoupled from the runtime\n * `DatabaseSchema` machinery.\n *\n * The `defineSchema` import is aliased to `$defineSchema` because each table\n * is imported under its own (filename-derived) name; a table named\n * `defineSchema` would otherwise collide with the library import and emit a\n * duplicate-binding file. The leading `$` makes the alias collision-proof:\n * `validateConfectTableIdentifier` requires names to match\n * `/^[a-zA-Z][a-zA-Z0-9_]*$/`, which forbids `$`, so no valid table import\n * can ever shadow it.\n */\nexport const convexSchema = ({\n tableModules,\n}: {\n tableModules: ReadonlyArray<TableModuleBinding>;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(\n `import { defineSchema as $defineSchema } from \"convex/server\";`,\n );\n\n if (tableModules.length > 0) {\n yield* cbw.blankLine();\n yield* Effect.forEach(tableModules, ({ tableName, importPath }) =>\n cbw.writeLine(`import ${tableName} from \"${importPath}\";`),\n );\n }\n\n yield* cbw.blankLine();\n\n if (tableModules.length === 0) {\n yield* cbw.writeLine(`export default $defineSchema({});`);\n } else {\n yield* cbw.writeLine(`export default $defineSchema({`);\n yield* cbw.indent(\n Effect.gen(function* () {\n for (const { tableName } of tableModules) {\n yield* cbw.writeLine(`${tableName}: ${tableName}.tableDefinition,`);\n }\n }),\n );\n yield* cbw.writeLine(`});`);\n }\n\n return yield* cbw.toString();\n });\n\n/**\n * Emit `confect/_generated/id.ts` — a type-constrained `Id` constructor and\n * a `TableNames` union derived from the user's `confect/tables/*.ts`\n * filenames. User-authored table modules import `Id` from this file to\n * declare cross-table id references without typing the destination name as\n * a free string (and without ever importing each other transitively).\n *\n * When the table directory is empty the `TableNames` union resolves to\n * `never`, which still lets the file typecheck against an empty workspace.\n */\nexport const id = ({ tableNames }: { tableNames: ReadonlyArray<string> }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { GenericId } from \"@confect/core\";`);\n yield* cbw.blankLine();\n\n const union =\n tableNames.length === 0\n ? \"never\"\n : tableNames.map((n) => `\"${n}\"`).join(\" | \");\n yield* cbw.writeLine(`export type TableNames = ${union};`);\n yield* cbw.blankLine();\n\n yield* cbw.writeLine(\n `export const Id = <const TableName extends TableNames>(`,\n );\n yield* cbw.indent(cbw.writeLine(`tableName: TableName,`));\n yield* cbw.writeLine(`) => GenericId.GenericId(tableName);`);\n\n return yield* cbw.toString();\n });\n\n/**\n * Emit `confect/_generated/tables/<tableName>.ts` — a two-line wrapper that\n * imports the user-authored `UnnamedTable` and binds the file basename to\n * it, producing the fully-named `Table` value that downstream consumers\n * (schema, specs, impls) read.\n */\nexport const tableWrapper = ({\n tableName,\n unnamedImportPath,\n}: {\n tableName: string;\n unnamedImportPath: string;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import unnamed from \"${unnamedImportPath}\";`);\n yield* cbw.blankLine();\n yield* cbw.writeLine(`export default unnamed(\"${tableName}\");`);\n\n return yield* cbw.toString();\n });\n\nexport const http = ({ httpImportPath }: { httpImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import http from \"${httpImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default http;`);\n\n return yield* cbw.toString();\n });\n\nexport const crons = ({ cronsImportPath }: { cronsImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import crons from \"${cronsImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default crons.convexCronJobs;`);\n\n return yield* cbw.toString();\n });\n\nexport const authConfig = ({ authImportPath }: { authImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import auth from \"${authImportPath}\";`);\n yield* cbw.newLine();\n yield* cbw.writeLine(`export default auth;`);\n\n return yield* cbw.toString();\n });\n\nexport const refs = ({\n specImportPath,\n nodeSpecImportPath,\n}: {\n specImportPath: string;\n nodeSpecImportPath: Option.Option<string>;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n yield* cbw.writeLine(`import { Refs } from \"@confect/core\";`);\n yield* cbw.writeLine(`import spec from \"${specImportPath}\";`);\n yield* Option.match(nodeSpecImportPath, {\n onNone: () => Effect.void,\n onSome: (nodeSpecImportPath_) =>\n cbw.writeLine(`import nodeSpec from \"${nodeSpecImportPath_}\";`),\n });\n yield* cbw.blankLine();\n yield* cbw.writeLine(\n Option.match(nodeSpecImportPath, {\n onSome: () => `export default Refs.make(spec, nodeSpec);`,\n onNone: () => `export default Refs.make(spec);`,\n }),\n );\n\n return yield* cbw.toString();\n });\n\nexport const registeredFunctionsForGroup = ({\n schemaImportPath,\n specImportPath,\n implImportPath,\n layerExportName,\n useNode = false,\n}: {\n schemaImportPath: string;\n specImportPath: string;\n implImportPath: string;\n layerExportName: string;\n useNode?: boolean;\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(\n `import { RegisteredFunctions } from \"@confect/server\";`,\n );\n yield* cbw.writeLine(\n `import { RegisteredNodeFunction } from \"@confect/server/node\";`,\n );\n } else {\n yield* cbw.writeLine(\n `import { RegisteredConvexFunction, RegisteredFunctions } from \"@confect/server\";`,\n );\n }\n\n yield* cbw.writeLine(`import databaseSchema from \"${schemaImportPath}\";`);\n yield* cbw.writeLine(`import ${layerExportName} from \"${implImportPath}\";`);\n yield* cbw.blankLine();\n // The group's own leaf spec is referenced type-only (`typeof import(...)`),\n // so the spec module is erased at transpile time and never enters the\n // per-function bundle; only `databaseSchema` and the impl are runtime\n // imports. Typing from the leaf spec (not the project-wide assembled spec)\n // keeps the registry's type dependent solely on its own group.\n const specType = `typeof import(\"${specImportPath}\")[\"default\"]`;\n const makeFn = useNode\n ? \"RegisteredNodeFunction.make\"\n : \"RegisteredConvexFunction.make\";\n yield* cbw.writeLine(\n `export default RegisteredFunctions.buildForGroup<${specType}>(databaseSchema, ${layerExportName}, ${makeFn});`,\n );\n\n return yield* cbw.toString();\n });\n\nexport const services = ({ schemaImportPath }: { schemaImportPath: string }) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n // Imports\n yield* cbw.writeLine(\"import {\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"ActionCtx as ActionCtx_,\");\n yield* cbw.writeLine(\"ActionRunner as ActionRunner_,\");\n yield* cbw.writeLine(\"Auth as Auth_,\");\n yield* cbw.writeLine(\"type DataModel,\");\n yield* cbw.writeLine(\"DatabaseReader as DatabaseReader_,\");\n yield* cbw.writeLine(\"DatabaseWriter as DatabaseWriter_,\");\n yield* cbw.writeLine(\"MutationCtx as MutationCtx_,\");\n yield* cbw.writeLine(\"MutationRunner as MutationRunner_,\");\n yield* cbw.writeLine(\"QueryCtx as QueryCtx_,\");\n yield* cbw.writeLine(\"QueryRunner as QueryRunner_,\");\n yield* cbw.writeLine(\"Scheduler as Scheduler_,\");\n yield* cbw.writeLine(\"StorageActionWriter as StorageActionWriter_,\");\n yield* cbw.writeLine(\"StorageReader as StorageReader_,\");\n yield* cbw.writeLine(\"StorageWriter as StorageWriter_,\");\n yield* cbw.writeLine(\"VectorSearch as VectorSearch_,\");\n }),\n );\n yield* cbw.writeLine(`} from \"@confect/server\";`);\n yield* cbw.writeLine(\n `import type schemaDefinition from \"${schemaImportPath}\";`,\n );\n yield* cbw.blankLine();\n\n // Auth\n yield* cbw.writeLine(\"export const Auth = Auth_.Auth;\");\n yield* cbw.writeLine(\"export type Auth = typeof Auth.Identifier;\");\n yield* cbw.blankLine();\n\n // Scheduler\n yield* cbw.writeLine(\"export const Scheduler = Scheduler_.Scheduler;\");\n yield* cbw.writeLine(\n \"export type Scheduler = typeof Scheduler.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageReader\n yield* cbw.writeLine(\n \"export const StorageReader = StorageReader_.StorageReader;\",\n );\n yield* cbw.writeLine(\n \"export type StorageReader = typeof StorageReader.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageWriter\n yield* cbw.writeLine(\n \"export const StorageWriter = StorageWriter_.StorageWriter;\",\n );\n yield* cbw.writeLine(\n \"export type StorageWriter = typeof StorageWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // StorageActionWriter\n yield* cbw.writeLine(\n \"export const StorageActionWriter = StorageActionWriter_.StorageActionWriter;\",\n );\n yield* cbw.writeLine(\n \"export type StorageActionWriter = typeof StorageActionWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // VectorSearch\n yield* cbw.writeLine(\"export const VectorSearch =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type VectorSearch = typeof VectorSearch.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // DatabaseReader\n yield* cbw.writeLine(\"export const DatabaseReader =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DatabaseReader_.DatabaseReader<typeof schemaDefinition>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type DatabaseReader = typeof DatabaseReader.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // DatabaseWriter\n yield* cbw.writeLine(\"export const DatabaseWriter =\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DatabaseWriter_.DatabaseWriter<typeof schemaDefinition>();\",\n ),\n );\n yield* cbw.writeLine(\n \"export type DatabaseWriter = typeof DatabaseWriter.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // QueryRunner\n yield* cbw.writeLine(\n \"export const QueryRunner = QueryRunner_.QueryRunner;\",\n );\n yield* cbw.writeLine(\n \"export type QueryRunner = typeof QueryRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // MutationRunner\n yield* cbw.writeLine(\n \"export const MutationRunner = MutationRunner_.MutationRunner;\",\n );\n yield* cbw.writeLine(\n \"export type MutationRunner = typeof MutationRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // ActionRunner\n yield* cbw.writeLine(\n \"export const ActionRunner = ActionRunner_.ActionRunner;\",\n );\n yield* cbw.writeLine(\n \"export type ActionRunner = typeof ActionRunner.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // QueryCtx\n yield* cbw.writeLine(\"export const QueryCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"QueryCtx_.QueryCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\"export type QueryCtx = typeof QueryCtx.Identifier;\");\n yield* cbw.blankLine();\n\n // MutationCtx\n yield* cbw.writeLine(\"export const MutationCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"MutationCtx_.MutationCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\n \"export type MutationCtx = typeof MutationCtx.Identifier;\",\n );\n yield* cbw.blankLine();\n\n // ActionCtx\n yield* cbw.writeLine(\"export const ActionCtx =\");\n yield* cbw.indent(\n Effect.gen(function* () {\n yield* cbw.writeLine(\"ActionCtx_.ActionCtx<\");\n yield* cbw.indent(\n cbw.writeLine(\n \"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>\",\n ),\n );\n yield* cbw.writeLine(\">();\");\n }),\n );\n yield* cbw.writeLine(\n \"export type ActionCtx = typeof ActionCtx.Identifier;\",\n );\n\n return yield* cbw.toString();\n });\n\nconst writeChildAddGroupAt = (\n cbw: CodeBlockWriter,\n child: SpecAssemblyNode,\n groupFactory: string,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n yield* cbw.write(\".addGroupAt(\");\n yield* cbw.quote(child.segment);\n yield* cbw.write(\", \");\n yield* writeGroupAssembly(cbw, child, groupFactory);\n yield* cbw.write(\")\");\n });\n\nconst writeGroupFactoryCall = (\n cbw: CodeBlockWriter,\n node: SpecAssemblyNode,\n groupFactory: string,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n yield* cbw.write(groupFactory);\n yield* cbw.write(\"(\");\n yield* cbw.quote(node.segment);\n yield* cbw.write(\")\");\n\n yield* Effect.forEach(node.children, (child) =>\n writeChildAddGroupAt(cbw, child, groupFactory),\n );\n });\n\nconst writeGroupAssembly: (\n cbw: CodeBlockWriter,\n node: SpecAssemblyNode,\n groupFactory: string,\n) => Effect.Effect<void> = (cbw, node, groupFactory) =>\n Option.match(node.importBinding, {\n onNone: () => writeGroupFactoryCall(cbw, node, groupFactory),\n onSome: (binding) =>\n Effect.gen(function* () {\n yield* cbw.write(binding.localName);\n yield* Effect.forEach(node.children, (child) =>\n writeChildAddGroupAt(cbw, child, groupFactory),\n );\n }),\n });\n\nconst writeRootAddAt = (\n cbw: CodeBlockWriter,\n node: SpecAssemblyNode,\n groupFactory: string,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n yield* cbw.write(\".addAt(\");\n yield* cbw.quote(node.segment);\n yield* cbw.write(\", \");\n\n yield* writeGroupAssembly(cbw, node, groupFactory);\n\n yield* cbw.write(\")\");\n });\n\nexport const assembledSpec = ({\n nodes,\n runtime,\n}: {\n nodes: ReadonlyArray<SpecAssemblyNode>;\n runtime: \"Convex\" | \"Node\";\n}) =>\n Effect.gen(function* () {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n const nodeRequiresGroupFactory = (node: SpecAssemblyNode): boolean =>\n Option.isNone(node.importBinding) ||\n Array.some(node.children, nodeRequiresGroupFactory);\n\n const needsGroupSpec = Array.some(nodes, nodeRequiresGroupFactory);\n yield* cbw.writeLine(\n needsGroupSpec\n ? `import { GroupSpec, Spec } from \"@confect/core\";`\n : `import { Spec } from \"@confect/core\";`,\n );\n\n yield* Effect.forEach(collectImportBindings(nodes), (binding) =>\n cbw.writeLine(\n `import ${binding.localName} from \"${binding.importPath}\";`,\n ),\n );\n\n yield* cbw.blankLine();\n\n const specFactory =\n runtime === \"Convex\" ? \"Spec.make()\" : \"Spec.makeNode()\";\n const groupFactory =\n runtime === \"Convex\" ? \"GroupSpec.makeAt\" : \"GroupSpec.makeNodeAt\";\n\n yield* cbw.write(`export default ${specFactory}`);\n yield* Effect.forEach(nodes, (node) =>\n writeRootAddAt(cbw, node, groupFactory),\n );\n yield* cbw.write(\";\");\n yield* cbw.newLine();\n\n return yield* cbw.toString();\n });\n"],"mappings":";;;;;AAOA,MAAa,aAAa,EACxB,eACA,+BACA,UAAU,YAMV,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;AAE5D,KAAI,SAAS;AACX,SAAO,IAAI,UAAU,cAAc;AACnC,SAAO,IAAI,WAAW;;AAGxB,QAAO,IAAI,UACT,oCAAoC,8BAA8B,IACnE;AACD,QAAO,IAAI,SAAS;AACpB,QAAO,OAAO,QAAQ,gBAAgB,iBACpC,IAAI,UACF,gBAAgB,aAAa,yBAAyB,aAAa,GACpE,CACF;AAED,QAAO,OAAO,IAAI,UAAU;EAC5B;;;;;;;;AASJ,MAAa,UAAU,EACrB,6BAIA,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAs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;AAC9B,QAAO,IAAI,MAAM,KAAK;AAEtB,QAAO,mBAAmB,KAAK,MAAM,aAAa;AAElD,QAAO,IAAI,MAAM,IAAI;EACrB;AAEJ,MAAa,iBAAiB,EAC5B,OACA,cAKA,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,GAAG,CAAC;CAE5D,MAAM,4BAA4B,SAChC,OAAO,OAAO,KAAK,cAAc,IACjC,MAAM,KAAK,KAAK,UAAU,yBAAyB;CAErD,MAAM,iBAAiB,MAAM,KAAK,OAAO,yBAAyB;AAClE,QAAO,IAAI,UACT,iBACI,qDACA,wCACL;AAED,QAAO,OAAO,QAAQ,sBAAsB,MAAM,GAAG,YACnD,IAAI,UACF,UAAU,QAAQ,UAAU,SAAS,QAAQ,WAAW,IACzD,CACF;AAED,QAAO,IAAI,WAAW;CAEtB,MAAM,cACJ,YAAY,WAAW,gBAAgB;CACzC,MAAM,eACJ,YAAY,WAAW,qBAAqB;AAE9C,QAAO,IAAI,MAAM,kBAAkB,cAAc;AACjD,QAAO,OAAO,QAAQ,QAAQ,SAC5B,eAAe,KAAK,MAAM,aAAa,CACxC;AACD,QAAO,IAAI,MAAM,IAAI;AACrB,QAAO,IAAI,SAAS;AAEpB,QAAO,OAAO,IAAI,UAAU;EAC5B"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/cli",
|
|
3
|
-
"version": "9.0.0-next.4",
|
|
4
3
|
"description": "Developer tooling for codegen and sync",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"url": "https://github.com/rjdellecese/confect.git"
|
|
8
|
-
},
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://github.com/rjdellecese/confect/issues"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://confect.dev",
|
|
13
|
-
"sideEffects": false,
|
|
14
|
-
"type": "module",
|
|
4
|
+
"version": "9.0.0-next.6",
|
|
5
|
+
"author": "RJ Dellecese",
|
|
15
6
|
"bin": {
|
|
16
7
|
"confect": "./dist/index.mjs"
|
|
17
8
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"LICENSE",
|
|
21
|
-
"README.md",
|
|
22
|
-
"dist",
|
|
23
|
-
"package.json",
|
|
24
|
-
"src"
|
|
25
|
-
],
|
|
26
|
-
"exports": {
|
|
27
|
-
".": {
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
|
-
"default": "./dist/index.js"
|
|
30
|
-
},
|
|
31
|
-
"./package.json": "./package.json"
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/rjdellecese/confect/issues"
|
|
32
11
|
},
|
|
33
|
-
"keywords": [
|
|
34
|
-
"effect",
|
|
35
|
-
"convex",
|
|
36
|
-
"cli"
|
|
37
|
-
],
|
|
38
|
-
"author": "RJ Dellecese",
|
|
39
|
-
"license": "ISC",
|
|
40
12
|
"dependencies": {
|
|
41
13
|
"@effect/cli": "^0.75.1",
|
|
42
14
|
"@effect/platform": "0.96.1",
|
|
@@ -44,6 +16,7 @@
|
|
|
44
16
|
"@effect/platform-node-shared": "0.59.0",
|
|
45
17
|
"@effect/printer": "^0.49.0",
|
|
46
18
|
"@effect/printer-ansi": "^0.49.0",
|
|
19
|
+
"bundle-require": "^5.1.0",
|
|
47
20
|
"code-block-writer": "^13.0.3",
|
|
48
21
|
"esbuild": "^0.27.3"
|
|
49
22
|
},
|
|
@@ -63,26 +36,53 @@
|
|
|
63
36
|
"vite-tsconfig-paths": "6.1.1",
|
|
64
37
|
"vitest": "3.2.4"
|
|
65
38
|
},
|
|
66
|
-
"peerDependencies": {
|
|
67
|
-
"effect": "^3.21.2",
|
|
68
|
-
"@confect/core": "^9.0.0-next.4",
|
|
69
|
-
"@confect/server": "^9.0.0-next.4"
|
|
70
|
-
},
|
|
71
39
|
"engines": {
|
|
72
|
-
"node": ">=22"
|
|
73
|
-
|
|
40
|
+
"node": ">=22"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"default": "./dist/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
74
48
|
},
|
|
49
|
+
"files": [
|
|
50
|
+
"CHANGELOG.md",
|
|
51
|
+
"LICENSE",
|
|
52
|
+
"README.md",
|
|
53
|
+
"dist",
|
|
54
|
+
"package.json",
|
|
55
|
+
"src"
|
|
56
|
+
],
|
|
57
|
+
"homepage": "https://confect.dev",
|
|
58
|
+
"keywords": [
|
|
59
|
+
"cli",
|
|
60
|
+
"convex",
|
|
61
|
+
"effect"
|
|
62
|
+
],
|
|
63
|
+
"license": "ISC",
|
|
75
64
|
"main": "./dist/index.js",
|
|
76
65
|
"module": "./dist/index.js",
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"effect": "^3.21.2",
|
|
68
|
+
"@confect/core": "^9.0.0-next.6",
|
|
69
|
+
"@confect/server": "^9.0.0-next.6"
|
|
70
|
+
},
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
74
|
+
},
|
|
75
|
+
"sideEffects": false,
|
|
76
|
+
"type": "module",
|
|
77
77
|
"types": "./dist/index.d.ts",
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "tsdown --config-loader unrun",
|
|
80
|
+
"clean": "rm -rf dist coverage node_modules",
|
|
80
81
|
"dev": "tsdown --watch --config-loader unrun",
|
|
81
|
-
"test": "vitest run",
|
|
82
|
-
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
83
82
|
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
84
83
|
"format": "prettier --check .",
|
|
85
84
|
"lint": "eslint . --max-warnings=0",
|
|
86
|
-
"
|
|
85
|
+
"test": "vitest run",
|
|
86
|
+
"typecheck": "tsc --noEmit --project tsconfig.json"
|
|
87
87
|
}
|
|
88
88
|
}
|
package/src/Bundler.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
2
2
|
import { Path } from "@effect/platform";
|
|
3
|
+
import { bundleRequire } from "bundle-require";
|
|
3
4
|
import { Array, Effect, Option, pipe } from "effect";
|
|
4
|
-
import * as esbuild from "esbuild";
|
|
5
|
+
import type * as esbuild from "esbuild";
|
|
5
6
|
import { BundlerError } from "./BuildError";
|
|
6
7
|
|
|
7
8
|
export interface Bundled {
|
|
@@ -9,108 +10,84 @@ export interface Bundled {
|
|
|
9
10
|
readonly metafile: esbuild.Metafile;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
const isRelativeOrAbsolutePath = (importPath: string) =>
|
|
13
|
-
importPath.startsWith("./") ||
|
|
14
|
-
importPath.startsWith("../") ||
|
|
15
|
-
importPath.startsWith("/");
|
|
16
|
-
|
|
17
|
-
// Recursion guard for `absoluteExternalsPlugin`. When the plugin asks esbuild
|
|
18
|
-
// to resolve a bare specifier via `build.resolve(...)`, esbuild invokes every
|
|
19
|
-
// registered `onResolve` hook again for that same specifier — including this
|
|
20
|
-
// one. The flag (carried through the recursive call via `pluginData`) tells
|
|
21
|
-
// the recursive invocation to skip rewriting and fall through to esbuild's
|
|
22
|
-
// built-in resolver, which is what we wanted from `build.resolve` in the
|
|
23
|
-
// first place.
|
|
24
|
-
const PLUGIN_DATA_SKIP = Symbol("absolute-externals.skip");
|
|
25
|
-
|
|
26
13
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* Bundles produced with this plugin are loaded via a data URL `import(...)`
|
|
34
|
-
* (see {@link bundle}); rewriting bare externals to absolute file URLs is what
|
|
35
|
-
* makes them resolvable at runtime, since a data URL has no parent file from
|
|
36
|
-
* which a bare specifier could be resolved.
|
|
37
|
-
*
|
|
38
|
-
* Relative/absolute-path imports are left to esbuild to bundle as usual, and
|
|
39
|
-
* `node:*` built-ins are passed through unchanged.
|
|
14
|
+
* `bundle-require` sets `absWorkingDir: cwd` on the underlying esbuild build,
|
|
15
|
+
* so the metafile's input keys (and each input's `imports[].path`) are stored
|
|
16
|
+
* relative to that cwd. Callers reach for the metafile with absolute paths
|
|
17
|
+
* (e.g. {@link directlyImports}), so we normalize every key/import path to
|
|
18
|
+
* absolute up front. That way the lookup logic stays oblivious to whatever
|
|
19
|
+
* cwd was used during bundling.
|
|
40
20
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (resolved.errors.length > 0) {
|
|
60
|
-
return { errors: resolved.errors, warnings: resolved.warnings };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
path: pathToFileURL(resolved.path).href,
|
|
65
|
-
external: true,
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const buildEntry = (entryPoint: string) =>
|
|
72
|
-
Effect.tryPromise({
|
|
73
|
-
try: () =>
|
|
74
|
-
esbuild.build({
|
|
75
|
-
entryPoints: [entryPoint],
|
|
76
|
-
bundle: true,
|
|
77
|
-
write: false,
|
|
78
|
-
platform: "node",
|
|
79
|
-
format: "esm",
|
|
80
|
-
logLevel: "silent",
|
|
81
|
-
metafile: true,
|
|
82
|
-
plugins: [absoluteExternalsPlugin],
|
|
83
|
-
}),
|
|
84
|
-
catch: (cause) => new BundlerError({ cause }),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const importBundledModule = (result: esbuild.BuildResult) => {
|
|
88
|
-
const code = result.outputFiles![0]!.text;
|
|
89
|
-
const dataUrl =
|
|
90
|
-
"data:text/javascript;base64," + Buffer.from(code).toString("base64");
|
|
91
|
-
return import(dataUrl);
|
|
21
|
+
const absolutizeMetafile = (
|
|
22
|
+
metafile: esbuild.Metafile,
|
|
23
|
+
cwd: string,
|
|
24
|
+
): esbuild.Metafile => {
|
|
25
|
+
const absolutize = (p: string) => (isAbsolute(p) ? p : resolve(cwd, p));
|
|
26
|
+
const inputs: esbuild.Metafile["inputs"] = {};
|
|
27
|
+
for (const [key, value] of Object.entries(metafile.inputs)) {
|
|
28
|
+
inputs[absolutize(key)] = {
|
|
29
|
+
...value,
|
|
30
|
+
imports: value.imports.map((i) => ({ ...i, path: absolutize(i.path) })),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const outputs: esbuild.Metafile["outputs"] = {};
|
|
34
|
+
for (const [key, value] of Object.entries(metafile.outputs)) {
|
|
35
|
+
outputs[absolutize(key)] = value;
|
|
36
|
+
}
|
|
37
|
+
return { inputs, outputs };
|
|
92
38
|
};
|
|
93
39
|
|
|
94
40
|
/**
|
|
95
|
-
* Bundle a TypeScript entry point with esbuild
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
41
|
+
* Bundle a TypeScript entry point with esbuild via {@link bundleRequire} and
|
|
42
|
+
* import the result. `bundle-require` writes a temp `.mjs` next to the source,
|
|
43
|
+
* `import()`s it, and deletes it — so bare-specifier externals (third-party
|
|
44
|
+
* packages, workspace deps) resolve through the user's normal `node_modules`
|
|
45
|
+
* walk, and tsconfig `paths` aliases stay inside the bundle.
|
|
46
|
+
*
|
|
47
|
+
* `cwd` is set to the entry's directory so `bundle-require`'s `tsconfig.json`
|
|
48
|
+
* discovery (which walks upward from `cwd`) lands on the project's tsconfig
|
|
49
|
+
* regardless of where `confect codegen` was invoked from, and so esbuild
|
|
50
|
+
* resolves relative imports against the entry's location.
|
|
51
|
+
*
|
|
52
|
+
* The returned pair carries both the imported module and the esbuild metafile
|
|
53
|
+
* so callers can inspect the import graph (see {@link directlyImports}); the
|
|
54
|
+
* metafile is captured via a small `onEnd` plugin because `bundle-require`
|
|
55
|
+
* itself only exposes a flat `dependencies: string[]`.
|
|
100
56
|
*/
|
|
101
57
|
export const bundle = (
|
|
102
58
|
entryPoint: string,
|
|
103
59
|
): Effect.Effect<Bundled, BundlerError> =>
|
|
104
60
|
Effect.gen(function* () {
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
61
|
+
let metafile: esbuild.Metafile | undefined;
|
|
62
|
+
const captureMetafile: esbuild.Plugin = {
|
|
63
|
+
name: "confect:capture-metafile",
|
|
64
|
+
setup(build) {
|
|
65
|
+
build.onEnd((result) => {
|
|
66
|
+
metafile = result.metafile;
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const cwd = dirname(entryPoint);
|
|
72
|
+
const result = yield* Effect.tryPromise({
|
|
73
|
+
try: () =>
|
|
74
|
+
bundleRequire({
|
|
75
|
+
filepath: entryPoint,
|
|
76
|
+
cwd,
|
|
77
|
+
format: "esm",
|
|
78
|
+
esbuildOptions: {
|
|
79
|
+
plugins: [captureMetafile],
|
|
80
|
+
logLevel: "silent",
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
108
83
|
catch: (cause) => new BundlerError({ cause }),
|
|
109
84
|
});
|
|
110
|
-
|
|
85
|
+
|
|
86
|
+
if (!metafile) {
|
|
111
87
|
return yield* Effect.dieMessage("esbuild metafile missing");
|
|
112
88
|
}
|
|
113
|
-
|
|
89
|
+
|
|
90
|
+
return { module: result.mod, metafile: absolutizeMetafile(metafile, cwd) };
|
|
114
91
|
});
|
|
115
92
|
|
|
116
93
|
const findMetafileInputKey = (
|