@confect/cli 9.0.0-next.0 → 9.0.0-next.10
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 +351 -1
- package/dist/BuildError.mjs +9 -2
- package/dist/BuildError.mjs.map +1 -1
- package/dist/Bundler.mjs +67 -57
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodeBlockWriter.mjs +1 -1
- package/dist/CodeBlockWriter.mjs.map +1 -1
- package/dist/CodegenError.mjs +36 -21
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/ConfectDirectory.mjs +5 -2
- package/dist/ConfectDirectory.mjs.map +1 -1
- package/dist/ConvexDirectory.mjs +6 -2
- package/dist/ConvexDirectory.mjs.map +1 -1
- package/dist/FunctionPath.mjs +1 -1
- package/dist/FunctionPath.mjs.map +1 -1
- package/dist/FunctionPaths.mjs +5 -1
- package/dist/FunctionPaths.mjs.map +1 -1
- package/dist/GroupPath.mjs +9 -2
- package/dist/GroupPath.mjs.map +1 -1
- package/dist/GroupPaths.mjs +1 -1
- package/dist/GroupPaths.mjs.map +1 -1
- package/dist/LeafModule.mjs +20 -24
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ProjectRoot.mjs +8 -3
- package/dist/ProjectRoot.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +9 -11
- package/dist/SpecAssemblyNode.mjs.map +1 -1
- package/dist/TableModule.mjs +94 -0
- package/dist/TableModule.mjs.map +1 -0
- package/dist/cliApp.mjs +1 -1
- package/dist/cliApp.mjs.map +1 -1
- package/dist/confect/codegen.mjs +272 -141
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/dev.mjs +36 -17
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/confect.mjs +2 -2
- package/dist/confect.mjs.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/log.mjs +9 -4
- package/dist/log.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/dist/templates.mjs +139 -48
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +42 -22
- package/dist/utils.mjs.map +1 -1
- package/package.json +33 -50
- package/dist/index.d.mts +0 -1
- package/src/BuildError.ts +0 -210
- package/src/Bundler.ts +0 -144
- package/src/CodeBlockWriter.ts +0 -65
- package/src/CodegenError.ts +0 -344
- package/src/ConfectDirectory.ts +0 -42
- package/src/ConvexDirectory.ts +0 -68
- package/src/FunctionPath.ts +0 -27
- package/src/FunctionPaths.ts +0 -103
- package/src/GroupPath.ts +0 -118
- package/src/GroupPaths.ts +0 -7
- package/src/LeafModule.ts +0 -313
- package/src/ProjectRoot.ts +0 -50
- package/src/SpecAssemblyNode.ts +0 -82
- package/src/cliApp.ts +0 -8
- package/src/confect/codegen.ts +0 -589
- package/src/confect/dev.ts +0 -749
- package/src/confect.ts +0 -19
- package/src/index.ts +0 -22
- package/src/log.ts +0 -104
- package/src/templates.ts +0 -477
- package/src/utils.ts +0 -429
package/src/confect.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Command } from "@effect/cli";
|
|
2
|
-
import { Layer } from "effect";
|
|
3
|
-
import { codegen } from "./confect/codegen";
|
|
4
|
-
import { dev } from "./confect/dev";
|
|
5
|
-
import { ConfectDirectory } from "./ConfectDirectory";
|
|
6
|
-
import { ConvexDirectory } from "./ConvexDirectory";
|
|
7
|
-
import { ProjectRoot } from "./ProjectRoot";
|
|
8
|
-
|
|
9
|
-
export const confect = Command.make("confect").pipe(
|
|
10
|
-
Command.withDescription("Generate and sync Confect files with Convex"),
|
|
11
|
-
Command.withSubcommands([codegen, dev]),
|
|
12
|
-
Command.provide(
|
|
13
|
-
Layer.mergeAll(
|
|
14
|
-
ConfectDirectory.Default,
|
|
15
|
-
ProjectRoot.Default,
|
|
16
|
-
ConvexDirectory.Default,
|
|
17
|
-
),
|
|
18
|
-
),
|
|
19
|
-
);
|
package/src/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
|
4
|
-
import { Effect } from "effect";
|
|
5
|
-
import { cliApp } from "./cliApp";
|
|
6
|
-
|
|
7
|
-
// Track if we received SIGINT so we can re-raise it after cleanup.
|
|
8
|
-
// This ensures proper terminal state restoration when run via e.g. `pnpm`.
|
|
9
|
-
let interrupted = false;
|
|
10
|
-
process.prependListener("SIGINT", () => {
|
|
11
|
-
interrupted = true;
|
|
12
|
-
});
|
|
13
|
-
process.on("exit", () => {
|
|
14
|
-
if (interrupted) {
|
|
15
|
-
process.kill(process.pid, "SIGINT");
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
cliApp(process.argv).pipe(
|
|
20
|
-
Effect.provide(NodeContext.layer),
|
|
21
|
-
NodeRuntime.runMain,
|
|
22
|
-
);
|
package/src/log.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Path } from "@effect/platform";
|
|
2
|
-
import { Ansi, AnsiDoc } from "@effect/printer-ansi";
|
|
3
|
-
import { Console, Effect, pipe, String } from "effect";
|
|
4
|
-
import type * as FunctionPath from "./FunctionPath";
|
|
5
|
-
import * as GroupPath from "./GroupPath";
|
|
6
|
-
import { ProjectRoot } from "./ProjectRoot";
|
|
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
|
-
|
|
29
|
-
// --- File operation logs ---
|
|
30
|
-
|
|
31
|
-
const logFile = (char: string, color: Ansi.Ansi) => (fullPath: string) =>
|
|
32
|
-
Effect.gen(function* () {
|
|
33
|
-
const projectRoot = yield* ProjectRoot.get;
|
|
34
|
-
const path = yield* Path.Path;
|
|
35
|
-
|
|
36
|
-
const prefix = projectRoot + path.sep;
|
|
37
|
-
const suffix = pipe(fullPath, String.startsWith(prefix))
|
|
38
|
-
? pipe(fullPath, String.slice(prefix.length))
|
|
39
|
-
: fullPath;
|
|
40
|
-
|
|
41
|
-
yield* Console.log(
|
|
42
|
-
pipe(
|
|
43
|
-
AnsiDoc.char(char),
|
|
44
|
-
AnsiDoc.annotate(color),
|
|
45
|
-
AnsiDoc.catWithSpace(
|
|
46
|
-
AnsiDoc.hcat([
|
|
47
|
-
pipe(AnsiDoc.text(prefix), AnsiDoc.annotate(Ansi.blackBright)),
|
|
48
|
-
pipe(AnsiDoc.text(suffix), AnsiDoc.annotate(color)),
|
|
49
|
-
]),
|
|
50
|
-
),
|
|
51
|
-
AnsiDoc.render({ style: "pretty" }),
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export const logFileAdded = logFile("+", Ansi.green);
|
|
57
|
-
|
|
58
|
-
export const logFileRemoved = logFile("-", Ansi.red);
|
|
59
|
-
|
|
60
|
-
export const logFileModified = logFile("~", Ansi.yellow);
|
|
61
|
-
|
|
62
|
-
// --- Function subline logs ---
|
|
63
|
-
|
|
64
|
-
const logFunction =
|
|
65
|
-
(char: string, color: Ansi.Ansi) =>
|
|
66
|
-
(functionPath: FunctionPath.FunctionPath) =>
|
|
67
|
-
Console.log(
|
|
68
|
-
pipe(
|
|
69
|
-
AnsiDoc.text(" "),
|
|
70
|
-
AnsiDoc.cat(pipe(AnsiDoc.char(char), AnsiDoc.annotate(color))),
|
|
71
|
-
AnsiDoc.catWithSpace(
|
|
72
|
-
AnsiDoc.hcat([
|
|
73
|
-
pipe(
|
|
74
|
-
AnsiDoc.text(GroupPath.toString(functionPath.groupPath) + "."),
|
|
75
|
-
AnsiDoc.annotate(Ansi.blackBright),
|
|
76
|
-
),
|
|
77
|
-
pipe(AnsiDoc.text(functionPath.name), AnsiDoc.annotate(color)),
|
|
78
|
-
]),
|
|
79
|
-
),
|
|
80
|
-
AnsiDoc.render({ style: "pretty" }),
|
|
81
|
-
),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
export const logFunctionAdded = logFunction("+", Ansi.green);
|
|
85
|
-
|
|
86
|
-
export const logFunctionRemoved = logFunction("-", Ansi.red);
|
|
87
|
-
|
|
88
|
-
// --- Process status logs ---
|
|
89
|
-
|
|
90
|
-
const logStatus = (char: string, charColor: Ansi.Ansi) => (message: string) =>
|
|
91
|
-
Console.log(
|
|
92
|
-
pipe(
|
|
93
|
-
AnsiDoc.char(char),
|
|
94
|
-
AnsiDoc.annotate(charColor),
|
|
95
|
-
AnsiDoc.catWithSpace(AnsiDoc.text(message)),
|
|
96
|
-
AnsiDoc.render({ style: "pretty" }),
|
|
97
|
-
),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
export const logSuccess = logStatus("✔︎", Ansi.green);
|
|
101
|
-
|
|
102
|
-
export const logFailure = logStatus("✘", Ansi.red);
|
|
103
|
-
|
|
104
|
-
export const logPending = logStatus("⭘", Ansi.yellow);
|
package/src/templates.ts
DELETED
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
import { Array, Effect, Option } from "effect";
|
|
2
|
-
import { CodeBlockWriter } from "./CodeBlockWriter";
|
|
3
|
-
import {
|
|
4
|
-
collectImportBindings,
|
|
5
|
-
type SpecAssemblyNode,
|
|
6
|
-
} from "./SpecAssemblyNode";
|
|
7
|
-
|
|
8
|
-
export const functions = ({
|
|
9
|
-
functionNames,
|
|
10
|
-
registeredFunctionsImportPath,
|
|
11
|
-
useNode = false,
|
|
12
|
-
}: {
|
|
13
|
-
functionNames: string[];
|
|
14
|
-
registeredFunctionsImportPath: string;
|
|
15
|
-
useNode?: boolean;
|
|
16
|
-
}) =>
|
|
17
|
-
Effect.gen(function* () {
|
|
18
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
19
|
-
|
|
20
|
-
if (useNode) {
|
|
21
|
-
yield* cbw.writeLine(`"use node";`);
|
|
22
|
-
yield* cbw.blankLine();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
yield* cbw.writeLine(
|
|
26
|
-
`import registeredFunctions from "${registeredFunctionsImportPath}";`,
|
|
27
|
-
);
|
|
28
|
-
yield* cbw.newLine();
|
|
29
|
-
yield* Effect.forEach(functionNames, (functionName) =>
|
|
30
|
-
cbw.writeLine(
|
|
31
|
-
`export const ${functionName} = registeredFunctions.${functionName};`,
|
|
32
|
-
),
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return yield* cbw.toString();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export const schema = ({ schemaImportPath }: { schemaImportPath: string }) =>
|
|
39
|
-
Effect.gen(function* () {
|
|
40
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
41
|
-
|
|
42
|
-
yield* cbw.writeLine(`import schemaDefinition from "${schemaImportPath}";`);
|
|
43
|
-
yield* cbw.newLine();
|
|
44
|
-
yield* cbw.writeLine(
|
|
45
|
-
`export default schemaDefinition.convexSchemaDefinition;`,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
return yield* cbw.toString();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export const http = ({ httpImportPath }: { httpImportPath: string }) =>
|
|
52
|
-
Effect.gen(function* () {
|
|
53
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
54
|
-
|
|
55
|
-
yield* cbw.writeLine(`import http from "${httpImportPath}";`);
|
|
56
|
-
yield* cbw.newLine();
|
|
57
|
-
yield* cbw.writeLine(`export default http;`);
|
|
58
|
-
|
|
59
|
-
return yield* cbw.toString();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export const crons = ({ cronsImportPath }: { cronsImportPath: string }) =>
|
|
63
|
-
Effect.gen(function* () {
|
|
64
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
65
|
-
|
|
66
|
-
yield* cbw.writeLine(`import crons from "${cronsImportPath}";`);
|
|
67
|
-
yield* cbw.newLine();
|
|
68
|
-
yield* cbw.writeLine(`export default crons.convexCronJobs;`);
|
|
69
|
-
|
|
70
|
-
return yield* cbw.toString();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
export const authConfig = ({ authImportPath }: { authImportPath: string }) =>
|
|
74
|
-
Effect.gen(function* () {
|
|
75
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
76
|
-
|
|
77
|
-
yield* cbw.writeLine(`import auth from "${authImportPath}";`);
|
|
78
|
-
yield* cbw.newLine();
|
|
79
|
-
yield* cbw.writeLine(`export default auth;`);
|
|
80
|
-
|
|
81
|
-
return yield* cbw.toString();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export const refs = ({
|
|
85
|
-
specImportPath,
|
|
86
|
-
nodeSpecImportPath,
|
|
87
|
-
}: {
|
|
88
|
-
specImportPath: string;
|
|
89
|
-
nodeSpecImportPath: Option.Option<string>;
|
|
90
|
-
}) =>
|
|
91
|
-
Effect.gen(function* () {
|
|
92
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
93
|
-
|
|
94
|
-
yield* cbw.writeLine(`import { Refs } from "@confect/core";`);
|
|
95
|
-
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
96
|
-
yield* Option.match(nodeSpecImportPath, {
|
|
97
|
-
onNone: () => Effect.void,
|
|
98
|
-
onSome: (nodeSpecImportPath_) =>
|
|
99
|
-
cbw.writeLine(`import nodeSpec from "${nodeSpecImportPath_}";`),
|
|
100
|
-
});
|
|
101
|
-
yield* cbw.blankLine();
|
|
102
|
-
yield* cbw.writeLine(
|
|
103
|
-
Option.match(nodeSpecImportPath, {
|
|
104
|
-
onSome: () => `export default Refs.make(spec, nodeSpec);`,
|
|
105
|
-
onNone: () => `export default Refs.make(spec);`,
|
|
106
|
-
}),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return yield* cbw.toString();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
export const api = ({
|
|
113
|
-
schemaImportPath,
|
|
114
|
-
specImportPath,
|
|
115
|
-
}: {
|
|
116
|
-
schemaImportPath: string;
|
|
117
|
-
specImportPath: string;
|
|
118
|
-
}) =>
|
|
119
|
-
Effect.gen(function* () {
|
|
120
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
121
|
-
|
|
122
|
-
yield* cbw.writeLine(`import { Api } from "@confect/server";`);
|
|
123
|
-
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
124
|
-
yield* cbw.writeLine(`import spec from "${specImportPath}";`);
|
|
125
|
-
yield* cbw.blankLine();
|
|
126
|
-
yield* cbw.writeLine(`export default Api.make(schema, spec);`);
|
|
127
|
-
|
|
128
|
-
return yield* cbw.toString();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
export const nodeApi = ({
|
|
132
|
-
schemaImportPath,
|
|
133
|
-
nodeSpecImportPath,
|
|
134
|
-
}: {
|
|
135
|
-
schemaImportPath: string;
|
|
136
|
-
nodeSpecImportPath: string;
|
|
137
|
-
}) =>
|
|
138
|
-
Effect.gen(function* () {
|
|
139
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
140
|
-
|
|
141
|
-
yield* cbw.writeLine(`import { Api } from "@confect/server";`);
|
|
142
|
-
yield* cbw.blankLine();
|
|
143
|
-
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
144
|
-
yield* cbw.writeLine(`import nodeSpec from "${nodeSpecImportPath}";`);
|
|
145
|
-
yield* cbw.blankLine();
|
|
146
|
-
yield* cbw.writeLine(`export default Api.make(schema, nodeSpec);`);
|
|
147
|
-
|
|
148
|
-
return yield* cbw.toString();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
export const registeredFunctionsForGroup = ({
|
|
152
|
-
apiImportPath,
|
|
153
|
-
groupPathDot,
|
|
154
|
-
implImportPath,
|
|
155
|
-
layerExportName,
|
|
156
|
-
useNode = false,
|
|
157
|
-
}: {
|
|
158
|
-
apiImportPath: string;
|
|
159
|
-
groupPathDot: string;
|
|
160
|
-
implImportPath: string;
|
|
161
|
-
layerExportName: string;
|
|
162
|
-
useNode?: boolean;
|
|
163
|
-
}) =>
|
|
164
|
-
Effect.gen(function* () {
|
|
165
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
166
|
-
|
|
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
|
-
}
|
|
179
|
-
|
|
180
|
-
yield* cbw.writeLine(`import api from "${apiImportPath}";`);
|
|
181
|
-
yield* cbw.writeLine(`import ${layerExportName} from "${implImportPath}";`);
|
|
182
|
-
yield* cbw.blankLine();
|
|
183
|
-
const quotedGroupPath = `"${groupPathDot.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
184
|
-
yield* cbw.writeLine(
|
|
185
|
-
useNode
|
|
186
|
-
? `export default RegisteredFunctions.buildForGroup(api, ${quotedGroupPath}, ${layerExportName}, RegisteredNodeFunction.make);`
|
|
187
|
-
: `export default RegisteredFunctions.buildForGroup(api, ${quotedGroupPath}, ${layerExportName}, RegisteredConvexFunction.make);`,
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
return yield* cbw.toString();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
export const services = ({ schemaImportPath }: { schemaImportPath: string }) =>
|
|
194
|
-
Effect.gen(function* () {
|
|
195
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
196
|
-
|
|
197
|
-
// Imports
|
|
198
|
-
yield* cbw.writeLine("import {");
|
|
199
|
-
yield* cbw.indent(
|
|
200
|
-
Effect.gen(function* () {
|
|
201
|
-
yield* cbw.writeLine("ActionCtx as ActionCtx_,");
|
|
202
|
-
yield* cbw.writeLine("ActionRunner as ActionRunner_,");
|
|
203
|
-
yield* cbw.writeLine("Auth as Auth_,");
|
|
204
|
-
yield* cbw.writeLine("type DataModel,");
|
|
205
|
-
yield* cbw.writeLine("DatabaseReader as DatabaseReader_,");
|
|
206
|
-
yield* cbw.writeLine("DatabaseWriter as DatabaseWriter_,");
|
|
207
|
-
yield* cbw.writeLine("MutationCtx as MutationCtx_,");
|
|
208
|
-
yield* cbw.writeLine("MutationRunner as MutationRunner_,");
|
|
209
|
-
yield* cbw.writeLine("QueryCtx as QueryCtx_,");
|
|
210
|
-
yield* cbw.writeLine("QueryRunner as QueryRunner_,");
|
|
211
|
-
yield* cbw.writeLine("Scheduler as Scheduler_,");
|
|
212
|
-
yield* cbw.writeLine("StorageActionWriter as StorageActionWriter_,");
|
|
213
|
-
yield* cbw.writeLine("StorageReader as StorageReader_,");
|
|
214
|
-
yield* cbw.writeLine("StorageWriter as StorageWriter_,");
|
|
215
|
-
yield* cbw.writeLine("VectorSearch as VectorSearch_,");
|
|
216
|
-
}),
|
|
217
|
-
);
|
|
218
|
-
yield* cbw.writeLine(`} from "@confect/server";`);
|
|
219
|
-
yield* cbw.writeLine(
|
|
220
|
-
`import type schemaDefinition from "${schemaImportPath}";`,
|
|
221
|
-
);
|
|
222
|
-
yield* cbw.blankLine();
|
|
223
|
-
|
|
224
|
-
// Auth
|
|
225
|
-
yield* cbw.writeLine("export const Auth = Auth_.Auth;");
|
|
226
|
-
yield* cbw.writeLine("export type Auth = typeof Auth.Identifier;");
|
|
227
|
-
yield* cbw.blankLine();
|
|
228
|
-
|
|
229
|
-
// Scheduler
|
|
230
|
-
yield* cbw.writeLine("export const Scheduler = Scheduler_.Scheduler;");
|
|
231
|
-
yield* cbw.writeLine(
|
|
232
|
-
"export type Scheduler = typeof Scheduler.Identifier;",
|
|
233
|
-
);
|
|
234
|
-
yield* cbw.blankLine();
|
|
235
|
-
|
|
236
|
-
// StorageReader
|
|
237
|
-
yield* cbw.writeLine(
|
|
238
|
-
"export const StorageReader = StorageReader_.StorageReader;",
|
|
239
|
-
);
|
|
240
|
-
yield* cbw.writeLine(
|
|
241
|
-
"export type StorageReader = typeof StorageReader.Identifier;",
|
|
242
|
-
);
|
|
243
|
-
yield* cbw.blankLine();
|
|
244
|
-
|
|
245
|
-
// StorageWriter
|
|
246
|
-
yield* cbw.writeLine(
|
|
247
|
-
"export const StorageWriter = StorageWriter_.StorageWriter;",
|
|
248
|
-
);
|
|
249
|
-
yield* cbw.writeLine(
|
|
250
|
-
"export type StorageWriter = typeof StorageWriter.Identifier;",
|
|
251
|
-
);
|
|
252
|
-
yield* cbw.blankLine();
|
|
253
|
-
|
|
254
|
-
// StorageActionWriter
|
|
255
|
-
yield* cbw.writeLine(
|
|
256
|
-
"export const StorageActionWriter = StorageActionWriter_.StorageActionWriter;",
|
|
257
|
-
);
|
|
258
|
-
yield* cbw.writeLine(
|
|
259
|
-
"export type StorageActionWriter = typeof StorageActionWriter.Identifier;",
|
|
260
|
-
);
|
|
261
|
-
yield* cbw.blankLine();
|
|
262
|
-
|
|
263
|
-
// VectorSearch
|
|
264
|
-
yield* cbw.writeLine("export const VectorSearch =");
|
|
265
|
-
yield* cbw.indent(
|
|
266
|
-
cbw.writeLine(
|
|
267
|
-
"VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();",
|
|
268
|
-
),
|
|
269
|
-
);
|
|
270
|
-
yield* cbw.writeLine(
|
|
271
|
-
"export type VectorSearch = typeof VectorSearch.Identifier;",
|
|
272
|
-
);
|
|
273
|
-
yield* cbw.blankLine();
|
|
274
|
-
|
|
275
|
-
// DatabaseReader
|
|
276
|
-
yield* cbw.writeLine("export const DatabaseReader =");
|
|
277
|
-
yield* cbw.indent(
|
|
278
|
-
cbw.writeLine(
|
|
279
|
-
"DatabaseReader_.DatabaseReader<typeof schemaDefinition>();",
|
|
280
|
-
),
|
|
281
|
-
);
|
|
282
|
-
yield* cbw.writeLine(
|
|
283
|
-
"export type DatabaseReader = typeof DatabaseReader.Identifier;",
|
|
284
|
-
);
|
|
285
|
-
yield* cbw.blankLine();
|
|
286
|
-
|
|
287
|
-
// DatabaseWriter
|
|
288
|
-
yield* cbw.writeLine("export const DatabaseWriter =");
|
|
289
|
-
yield* cbw.indent(
|
|
290
|
-
cbw.writeLine(
|
|
291
|
-
"DatabaseWriter_.DatabaseWriter<typeof schemaDefinition>();",
|
|
292
|
-
),
|
|
293
|
-
);
|
|
294
|
-
yield* cbw.writeLine(
|
|
295
|
-
"export type DatabaseWriter = typeof DatabaseWriter.Identifier;",
|
|
296
|
-
);
|
|
297
|
-
yield* cbw.blankLine();
|
|
298
|
-
|
|
299
|
-
// QueryRunner
|
|
300
|
-
yield* cbw.writeLine(
|
|
301
|
-
"export const QueryRunner = QueryRunner_.QueryRunner;",
|
|
302
|
-
);
|
|
303
|
-
yield* cbw.writeLine(
|
|
304
|
-
"export type QueryRunner = typeof QueryRunner.Identifier;",
|
|
305
|
-
);
|
|
306
|
-
yield* cbw.blankLine();
|
|
307
|
-
|
|
308
|
-
// MutationRunner
|
|
309
|
-
yield* cbw.writeLine(
|
|
310
|
-
"export const MutationRunner = MutationRunner_.MutationRunner;",
|
|
311
|
-
);
|
|
312
|
-
yield* cbw.writeLine(
|
|
313
|
-
"export type MutationRunner = typeof MutationRunner.Identifier;",
|
|
314
|
-
);
|
|
315
|
-
yield* cbw.blankLine();
|
|
316
|
-
|
|
317
|
-
// ActionRunner
|
|
318
|
-
yield* cbw.writeLine(
|
|
319
|
-
"export const ActionRunner = ActionRunner_.ActionRunner;",
|
|
320
|
-
);
|
|
321
|
-
yield* cbw.writeLine(
|
|
322
|
-
"export type ActionRunner = typeof ActionRunner.Identifier;",
|
|
323
|
-
);
|
|
324
|
-
yield* cbw.blankLine();
|
|
325
|
-
|
|
326
|
-
// QueryCtx
|
|
327
|
-
yield* cbw.writeLine("export const QueryCtx =");
|
|
328
|
-
yield* cbw.indent(
|
|
329
|
-
Effect.gen(function* () {
|
|
330
|
-
yield* cbw.writeLine("QueryCtx_.QueryCtx<");
|
|
331
|
-
yield* cbw.indent(
|
|
332
|
-
cbw.writeLine(
|
|
333
|
-
"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>",
|
|
334
|
-
),
|
|
335
|
-
);
|
|
336
|
-
yield* cbw.writeLine(">();");
|
|
337
|
-
}),
|
|
338
|
-
);
|
|
339
|
-
yield* cbw.writeLine("export type QueryCtx = typeof QueryCtx.Identifier;");
|
|
340
|
-
yield* cbw.blankLine();
|
|
341
|
-
|
|
342
|
-
// MutationCtx
|
|
343
|
-
yield* cbw.writeLine("export const MutationCtx =");
|
|
344
|
-
yield* cbw.indent(
|
|
345
|
-
Effect.gen(function* () {
|
|
346
|
-
yield* cbw.writeLine("MutationCtx_.MutationCtx<");
|
|
347
|
-
yield* cbw.indent(
|
|
348
|
-
cbw.writeLine(
|
|
349
|
-
"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>",
|
|
350
|
-
),
|
|
351
|
-
);
|
|
352
|
-
yield* cbw.writeLine(">();");
|
|
353
|
-
}),
|
|
354
|
-
);
|
|
355
|
-
yield* cbw.writeLine(
|
|
356
|
-
"export type MutationCtx = typeof MutationCtx.Identifier;",
|
|
357
|
-
);
|
|
358
|
-
yield* cbw.blankLine();
|
|
359
|
-
|
|
360
|
-
// ActionCtx
|
|
361
|
-
yield* cbw.writeLine("export const ActionCtx =");
|
|
362
|
-
yield* cbw.indent(
|
|
363
|
-
Effect.gen(function* () {
|
|
364
|
-
yield* cbw.writeLine("ActionCtx_.ActionCtx<");
|
|
365
|
-
yield* cbw.indent(
|
|
366
|
-
cbw.writeLine(
|
|
367
|
-
"DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>",
|
|
368
|
-
),
|
|
369
|
-
);
|
|
370
|
-
yield* cbw.writeLine(">();");
|
|
371
|
-
}),
|
|
372
|
-
);
|
|
373
|
-
yield* cbw.writeLine(
|
|
374
|
-
"export type ActionCtx = typeof ActionCtx.Identifier;",
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
return yield* cbw.toString();
|
|
378
|
-
});
|
|
379
|
-
|
|
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
|
-
});
|
|
392
|
-
|
|
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(")");
|
|
403
|
-
|
|
404
|
-
yield* Effect.forEach(node.children, (child) =>
|
|
405
|
-
writeChildAddGroupAt(cbw, child, groupFactory),
|
|
406
|
-
);
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const writeGroupAssembly: (
|
|
410
|
-
cbw: CodeBlockWriter,
|
|
411
|
-
node: SpecAssemblyNode,
|
|
412
|
-
groupFactory: string,
|
|
413
|
-
) => Effect.Effect<void> = (cbw, node, groupFactory) =>
|
|
414
|
-
node.children.length === 0
|
|
415
|
-
? Option.match(node.importBinding, {
|
|
416
|
-
onNone: () => writeGroupFactoryCall(cbw, node, groupFactory),
|
|
417
|
-
onSome: (binding) => cbw.write(binding.exportName),
|
|
418
|
-
})
|
|
419
|
-
: writeGroupFactoryCall(cbw, node, groupFactory);
|
|
420
|
-
|
|
421
|
-
const writeRootAddAt = (
|
|
422
|
-
cbw: CodeBlockWriter,
|
|
423
|
-
node: SpecAssemblyNode,
|
|
424
|
-
groupFactory: string,
|
|
425
|
-
): Effect.Effect<void> =>
|
|
426
|
-
Effect.gen(function* () {
|
|
427
|
-
yield* cbw.write(".addAt(");
|
|
428
|
-
yield* cbw.quote(node.segment);
|
|
429
|
-
yield* cbw.write(", ");
|
|
430
|
-
|
|
431
|
-
yield* writeGroupAssembly(cbw, node, groupFactory);
|
|
432
|
-
|
|
433
|
-
yield* cbw.write(")");
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
export const assembledSpec = ({
|
|
437
|
-
nodes,
|
|
438
|
-
runtime,
|
|
439
|
-
}: {
|
|
440
|
-
nodes: ReadonlyArray<SpecAssemblyNode>;
|
|
441
|
-
runtime: "Convex" | "Node";
|
|
442
|
-
}) =>
|
|
443
|
-
Effect.gen(function* () {
|
|
444
|
-
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
445
|
-
|
|
446
|
-
const needsGroupSpec = Array.some(
|
|
447
|
-
nodes,
|
|
448
|
-
(node) => node.children.length > 0,
|
|
449
|
-
);
|
|
450
|
-
yield* cbw.writeLine(
|
|
451
|
-
needsGroupSpec
|
|
452
|
-
? `import { GroupSpec, Spec } from "@confect/core";`
|
|
453
|
-
: `import { Spec } from "@confect/core";`,
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
yield* Effect.forEach(collectImportBindings(nodes), (binding) =>
|
|
457
|
-
cbw.writeLine(
|
|
458
|
-
`import ${binding.exportName} from "${binding.importPath}";`,
|
|
459
|
-
),
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
yield* cbw.blankLine();
|
|
463
|
-
|
|
464
|
-
const specFactory =
|
|
465
|
-
runtime === "Convex" ? "Spec.make()" : "Spec.makeNode()";
|
|
466
|
-
const groupFactory =
|
|
467
|
-
runtime === "Convex" ? "GroupSpec.makeAt" : "GroupSpec.makeNodeAt";
|
|
468
|
-
|
|
469
|
-
yield* cbw.write(`export default ${specFactory}`);
|
|
470
|
-
yield* Effect.forEach(nodes, (node) =>
|
|
471
|
-
writeRootAddAt(cbw, node, groupFactory),
|
|
472
|
-
);
|
|
473
|
-
yield* cbw.write(";");
|
|
474
|
-
yield* cbw.newLine();
|
|
475
|
-
|
|
476
|
-
return yield* cbw.toString();
|
|
477
|
-
});
|