@confect/cli 8.0.0 → 9.0.0-next.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 +57 -1
- package/dist/BuildError.mjs +101 -0
- package/dist/BuildError.mjs.map +1 -0
- package/dist/Bundler.mjs +91 -0
- package/dist/Bundler.mjs.map +1 -0
- package/dist/CodeBlockWriter.mjs +55 -0
- package/dist/CodeBlockWriter.mjs.map +1 -0
- package/dist/CodegenError.mjs +101 -0
- package/dist/CodegenError.mjs.map +1 -0
- package/dist/FunctionPaths.mjs +1 -1
- package/dist/LeafModule.mjs +170 -0
- package/dist/LeafModule.mjs.map +1 -0
- package/dist/SpecAssemblyNode.mjs +33 -0
- package/dist/SpecAssemblyNode.mjs.map +1 -0
- package/dist/confect/codegen.mjs +292 -72
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/dev.mjs +234 -180
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/log.mjs +13 -1
- package/dist/log.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/dist/templates.mjs +69 -72
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +77 -73
- package/dist/utils.mjs.map +1 -1
- package/package.json +4 -3
- package/src/BuildError.ts +210 -0
- package/src/Bundler.ts +144 -0
- package/src/CodeBlockWriter.ts +65 -0
- package/src/CodegenError.ts +376 -0
- package/src/LeafModule.ts +317 -0
- package/src/SpecAssemblyNode.ts +82 -0
- package/src/confect/codegen.ts +511 -141
- package/src/confect/dev.ts +556 -435
- package/src/log.ts +21 -0
- package/src/templates.ts +146 -109
- package/src/utils.ts +118 -93
package/src/log.ts
CHANGED
|
@@ -5,6 +5,27 @@ import type * as FunctionPath from "./FunctionPath";
|
|
|
5
5
|
import * as GroupPath from "./GroupPath";
|
|
6
6
|
import { ProjectRoot } from "./ProjectRoot";
|
|
7
7
|
|
|
8
|
+
// --- Path styling ---
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Render a relative path as an AnsiDoc with the directory portion
|
|
12
|
+
* dimmed (`Ansi.blackBright`) and the file leaf rendered in the
|
|
13
|
+
* default terminal color. Used inline anywhere a file path appears
|
|
14
|
+
* in a CLI message.
|
|
15
|
+
*/
|
|
16
|
+
export const formatPathDoc = (relativePath: string): AnsiDoc.AnsiDoc => {
|
|
17
|
+
const lastSep = Math.max(
|
|
18
|
+
relativePath.lastIndexOf("/"),
|
|
19
|
+
relativePath.lastIndexOf("\\"),
|
|
20
|
+
);
|
|
21
|
+
const dir = lastSep < 0 ? "" : relativePath.slice(0, lastSep + 1);
|
|
22
|
+
const leaf = lastSep < 0 ? relativePath : relativePath.slice(lastSep + 1);
|
|
23
|
+
return AnsiDoc.hcat([
|
|
24
|
+
pipe(AnsiDoc.text(dir), AnsiDoc.annotate(Ansi.blackBright)),
|
|
25
|
+
AnsiDoc.text(leaf),
|
|
26
|
+
]);
|
|
27
|
+
};
|
|
28
|
+
|
|
8
29
|
// --- File operation logs ---
|
|
9
30
|
|
|
10
31
|
const logFile = (char: string, color: Ansi.Ansi) => (fullPath: string) =>
|
package/src/templates.ts
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { Array, Effect, Option } from "effect";
|
|
2
|
+
import { CodeBlockWriter } from "./CodeBlockWriter";
|
|
3
|
+
import {
|
|
4
|
+
collectImportBindings,
|
|
5
|
+
type SpecAssemblyNode,
|
|
6
|
+
} from "./SpecAssemblyNode";
|
|
5
7
|
|
|
6
8
|
export const functions = ({
|
|
7
|
-
groupPath,
|
|
8
9
|
functionNames,
|
|
9
10
|
registeredFunctionsImportPath,
|
|
10
|
-
registeredFunctionsVariableName = "registeredFunctions",
|
|
11
|
-
registeredFunctionsLookupPath,
|
|
12
11
|
useNode = false,
|
|
13
12
|
}: {
|
|
14
|
-
groupPath: GroupPath.GroupPath;
|
|
15
13
|
functionNames: string[];
|
|
16
14
|
registeredFunctionsImportPath: string;
|
|
17
|
-
registeredFunctionsVariableName?: string;
|
|
18
|
-
registeredFunctionsLookupPath?: readonly string[];
|
|
19
15
|
useNode?: boolean;
|
|
20
16
|
}) =>
|
|
21
17
|
Effect.gen(function* () {
|
|
22
18
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
23
19
|
|
|
24
|
-
const lookupPath = registeredFunctionsLookupPath ?? groupPath.pathSegments;
|
|
25
|
-
|
|
26
20
|
if (useNode) {
|
|
27
21
|
yield* cbw.writeLine(`"use node";`);
|
|
28
22
|
yield* cbw.blankLine();
|
|
29
23
|
}
|
|
30
24
|
|
|
31
25
|
yield* cbw.writeLine(
|
|
32
|
-
`import
|
|
26
|
+
`import registeredFunctions from "${registeredFunctionsImportPath}";`,
|
|
33
27
|
);
|
|
34
28
|
yield* cbw.newLine();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
`export const ${functionName} =
|
|
38
|
-
)
|
|
39
|
-
|
|
29
|
+
yield* Effect.forEach(functionNames, (functionName) =>
|
|
30
|
+
cbw.writeLine(
|
|
31
|
+
`export const ${functionName} = registeredFunctions.${functionName};`,
|
|
32
|
+
),
|
|
33
|
+
);
|
|
40
34
|
|
|
41
35
|
return yield* cbw.toString();
|
|
42
36
|
});
|
|
@@ -92,21 +86,24 @@ export const refs = ({
|
|
|
92
86
|
nodeSpecImportPath,
|
|
93
87
|
}: {
|
|
94
88
|
specImportPath: string;
|
|
95
|
-
nodeSpecImportPath
|
|
89
|
+
nodeSpecImportPath: Option.Option<string>;
|
|
96
90
|
}) =>
|
|
97
91
|
Effect.gen(function* () {
|
|
98
92
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
99
93
|
|
|
100
94
|
yield* cbw.writeLine(`import { Refs } from "@confect/core";`);
|
|
101
95
|
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
yield* Option.match(nodeSpecImportPath, {
|
|
97
|
+
onNone: () => Effect.void,
|
|
98
|
+
onSome: (nodeSpecImportPath_) =>
|
|
99
|
+
cbw.writeLine(`import nodeSpec from "${nodeSpecImportPath_}";`),
|
|
100
|
+
});
|
|
105
101
|
yield* cbw.blankLine();
|
|
106
102
|
yield* cbw.writeLine(
|
|
107
|
-
nodeSpecImportPath
|
|
108
|
-
|
|
109
|
-
: `export default Refs.make(spec);`,
|
|
103
|
+
Option.match(nodeSpecImportPath, {
|
|
104
|
+
onSome: () => `export default Refs.make(spec, nodeSpec);`,
|
|
105
|
+
onNone: () => `export default Refs.make(spec);`,
|
|
106
|
+
}),
|
|
110
107
|
);
|
|
111
108
|
|
|
112
109
|
return yield* cbw.toString();
|
|
@@ -151,45 +148,43 @@ export const nodeApi = ({
|
|
|
151
148
|
return yield* cbw.toString();
|
|
152
149
|
});
|
|
153
150
|
|
|
154
|
-
export const
|
|
151
|
+
export const registeredFunctionsForGroup = ({
|
|
152
|
+
apiImportPath,
|
|
153
|
+
groupPathDot,
|
|
155
154
|
implImportPath,
|
|
155
|
+
layerExportName,
|
|
156
|
+
useNode = false,
|
|
156
157
|
}: {
|
|
158
|
+
apiImportPath: string;
|
|
159
|
+
groupPathDot: string;
|
|
157
160
|
implImportPath: string;
|
|
161
|
+
layerExportName: string;
|
|
162
|
+
useNode?: boolean;
|
|
158
163
|
}) =>
|
|
159
164
|
Effect.gen(function* () {
|
|
160
165
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
161
166
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
export const nodeRegisteredFunctions = ({
|
|
175
|
-
nodeImplImportPath,
|
|
176
|
-
}: {
|
|
177
|
-
nodeImplImportPath: string;
|
|
178
|
-
}) =>
|
|
179
|
-
Effect.gen(function* () {
|
|
180
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
167
|
+
if (useNode) {
|
|
168
|
+
yield* cbw.writeLine(
|
|
169
|
+
`import { RegisteredFunctions } from "@confect/server";`,
|
|
170
|
+
);
|
|
171
|
+
yield* cbw.writeLine(
|
|
172
|
+
`import { RegisteredNodeFunction } from "@confect/server/node";`,
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
yield* cbw.writeLine(
|
|
176
|
+
`import { RegisteredConvexFunction, RegisteredFunctions } from "@confect/server";`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
181
179
|
|
|
182
|
-
yield* cbw.writeLine(
|
|
183
|
-
|
|
184
|
-
);
|
|
185
|
-
yield* cbw.writeLine(
|
|
186
|
-
`import { RegisteredNodeFunction } from "@confect/server/node";`,
|
|
187
|
-
);
|
|
188
|
-
yield* cbw.blankLine();
|
|
189
|
-
yield* cbw.writeLine(`import nodeImpl from "${nodeImplImportPath}";`);
|
|
180
|
+
yield* cbw.writeLine(`import api from "${apiImportPath}";`);
|
|
181
|
+
yield* cbw.writeLine(`import ${layerExportName} from "${implImportPath}";`);
|
|
190
182
|
yield* cbw.blankLine();
|
|
183
|
+
const quotedGroupPath = `"${groupPathDot.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
191
184
|
yield* cbw.writeLine(
|
|
192
|
-
|
|
185
|
+
useNode
|
|
186
|
+
? `export default RegisteredFunctions.buildForGroup(api, ${quotedGroupPath}, ${layerExportName}, RegisteredNodeFunction.make);`
|
|
187
|
+
: `export default RegisteredFunctions.buildForGroup(api, ${quotedGroupPath}, ${layerExportName}, RegisteredConvexFunction.make);`,
|
|
193
188
|
);
|
|
194
189
|
|
|
195
190
|
return yield* cbw.toString();
|
|
@@ -382,64 +377,106 @@ export const services = ({ schemaImportPath }: { schemaImportPath: string }) =>
|
|
|
382
377
|
return yield* cbw.toString();
|
|
383
378
|
});
|
|
384
379
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
this.writer.setIndentationLevel(indentationLevel + 1);
|
|
398
|
-
yield* eff;
|
|
399
|
-
this.writer.setIndentationLevel(indentationLevel);
|
|
400
|
-
});
|
|
401
|
-
}
|
|
380
|
+
const writeChildAddGroupAt = (
|
|
381
|
+
cbw: CodeBlockWriter,
|
|
382
|
+
child: SpecAssemblyNode,
|
|
383
|
+
groupFactory: string,
|
|
384
|
+
): Effect.Effect<void> =>
|
|
385
|
+
Effect.gen(function* () {
|
|
386
|
+
yield* cbw.write(".addGroupAt(");
|
|
387
|
+
yield* cbw.quote(child.segment);
|
|
388
|
+
yield* cbw.write(", ");
|
|
389
|
+
yield* writeGroupAssembly(cbw, child, groupFactory);
|
|
390
|
+
yield* cbw.write(")");
|
|
391
|
+
});
|
|
402
392
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
393
|
+
const writeGroupFactoryCall = (
|
|
394
|
+
cbw: CodeBlockWriter,
|
|
395
|
+
node: SpecAssemblyNode,
|
|
396
|
+
groupFactory: string,
|
|
397
|
+
): Effect.Effect<void> =>
|
|
398
|
+
Effect.gen(function* () {
|
|
399
|
+
yield* cbw.write(groupFactory);
|
|
400
|
+
yield* cbw.write("(");
|
|
401
|
+
yield* cbw.quote(node.segment);
|
|
402
|
+
yield* cbw.write(")");
|
|
408
403
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
404
|
+
yield* Effect.forEach(node.children, (child) =>
|
|
405
|
+
writeChildAddGroupAt(cbw, child, groupFactory),
|
|
406
|
+
);
|
|
407
|
+
});
|
|
414
408
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
409
|
+
const writeGroupAssembly: (
|
|
410
|
+
cbw: CodeBlockWriter,
|
|
411
|
+
node: SpecAssemblyNode,
|
|
412
|
+
groupFactory: string,
|
|
413
|
+
) => Effect.Effect<void> = (cbw, node, groupFactory) =>
|
|
414
|
+
Option.match(node.importBinding, {
|
|
415
|
+
onNone: () => writeGroupFactoryCall(cbw, node, groupFactory),
|
|
416
|
+
onSome: (binding) =>
|
|
417
|
+
Effect.gen(function* () {
|
|
418
|
+
yield* cbw.write(binding.exportName);
|
|
419
|
+
yield* Effect.forEach(node.children, (child) =>
|
|
420
|
+
writeChildAddGroupAt(cbw, child, groupFactory),
|
|
421
|
+
);
|
|
422
|
+
}),
|
|
423
|
+
});
|
|
429
424
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
425
|
+
const writeRootAddAt = (
|
|
426
|
+
cbw: CodeBlockWriter,
|
|
427
|
+
node: SpecAssemblyNode,
|
|
428
|
+
groupFactory: string,
|
|
429
|
+
): Effect.Effect<void> =>
|
|
430
|
+
Effect.gen(function* () {
|
|
431
|
+
yield* cbw.write(".addAt(");
|
|
432
|
+
yield* cbw.quote(node.segment);
|
|
433
|
+
yield* cbw.write(", ");
|
|
435
434
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
435
|
+
yield* writeGroupAssembly(cbw, node, groupFactory);
|
|
436
|
+
|
|
437
|
+
yield* cbw.write(")");
|
|
438
|
+
});
|
|
441
439
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
440
|
+
export const assembledSpec = ({
|
|
441
|
+
nodes,
|
|
442
|
+
runtime,
|
|
443
|
+
}: {
|
|
444
|
+
nodes: ReadonlyArray<SpecAssemblyNode>;
|
|
445
|
+
runtime: "Convex" | "Node";
|
|
446
|
+
}) =>
|
|
447
|
+
Effect.gen(function* () {
|
|
448
|
+
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
449
|
+
|
|
450
|
+
const nodeRequiresGroupFactory = (node: SpecAssemblyNode): boolean =>
|
|
451
|
+
Option.isNone(node.importBinding) ||
|
|
452
|
+
Array.some(node.children, nodeRequiresGroupFactory);
|
|
453
|
+
|
|
454
|
+
const needsGroupSpec = Array.some(nodes, nodeRequiresGroupFactory);
|
|
455
|
+
yield* cbw.writeLine(
|
|
456
|
+
needsGroupSpec
|
|
457
|
+
? `import { GroupSpec, Spec } from "@confect/core";`
|
|
458
|
+
: `import { Spec } from "@confect/core";`,
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
yield* Effect.forEach(collectImportBindings(nodes), (binding) =>
|
|
462
|
+
cbw.writeLine(
|
|
463
|
+
`import ${binding.exportName} from "${binding.importPath}";`,
|
|
464
|
+
),
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
yield* cbw.blankLine();
|
|
468
|
+
|
|
469
|
+
const specFactory =
|
|
470
|
+
runtime === "Convex" ? "Spec.make()" : "Spec.makeNode()";
|
|
471
|
+
const groupFactory =
|
|
472
|
+
runtime === "Convex" ? "GroupSpec.makeAt" : "GroupSpec.makeNodeAt";
|
|
473
|
+
|
|
474
|
+
yield* cbw.write(`export default ${specFactory}`);
|
|
475
|
+
yield* Effect.forEach(nodes, (node) =>
|
|
476
|
+
writeRootAddAt(cbw, node, groupFactory),
|
|
477
|
+
);
|
|
478
|
+
yield* cbw.write(";");
|
|
479
|
+
yield* cbw.newLine();
|
|
480
|
+
|
|
481
|
+
return yield* cbw.toString();
|
|
482
|
+
});
|