@gaganref/confect-cli 10.3.1-fork.96 → 10.6.0-fork.2
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 +78 -0
- package/dist/Ansi.mjs +1 -2
- package/dist/BuildError.mjs +5 -5
- package/dist/BuildError.mjs.map +1 -1
- package/dist/Bundler.mjs +103 -76
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodeBlockWriter.mjs +1 -2
- package/dist/CodegenError.mjs +27 -17
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/ConfectDirectory.mjs +8 -3
- package/dist/ConfectDirectory.mjs.map +1 -1
- package/dist/ConvexConfig.mjs +23 -15
- package/dist/ConvexConfig.mjs.map +1 -1
- package/dist/ConvexDirectory.mjs +6 -4
- package/dist/ConvexDirectory.mjs.map +1 -1
- package/dist/Declaration.mjs +92 -56
- package/dist/Declaration.mjs.map +1 -1
- package/dist/DirectoryOptions.mjs +13 -8
- package/dist/DirectoryOptions.mjs.map +1 -1
- package/dist/DocName.mjs +1 -2
- package/dist/EntryPoint.mjs +17 -15
- package/dist/EntryPoint.mjs.map +1 -1
- package/dist/Evaluation.mjs +24 -13
- package/dist/Evaluation.mjs.map +1 -1
- package/dist/EvaluationWorker.mjs +5 -6
- package/dist/EvaluationWorker.mjs.map +1 -1
- package/dist/FunctionModule.mjs +85 -47
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/FunctionPath.mjs +1 -2
- package/dist/FunctionPath.mjs.map +1 -1
- package/dist/FunctionPaths.mjs +2 -3
- package/dist/GenerationSnapshot.mjs +30 -22
- package/dist/GenerationSnapshot.mjs.map +1 -1
- package/dist/GroupPath.mjs +6 -3
- package/dist/GroupPath.mjs.map +1 -1
- package/dist/GroupPaths.mjs +1 -2
- package/dist/ImplModulePath.mjs +1 -2
- package/dist/Json.mjs +13 -0
- package/dist/Json.mjs.map +1 -0
- package/dist/LeafModule.mjs +121 -41
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ManifestSections.mjs +23 -19
- package/dist/ManifestSections.mjs.map +1 -1
- package/dist/PackageSelfReference.mjs +32 -0
- package/dist/PackageSelfReference.mjs.map +1 -0
- package/dist/ProjectRoot.mjs +11 -3
- package/dist/ProjectRoot.mjs.map +1 -1
- package/dist/RelativeModulePath.mjs +1 -2
- package/dist/Remove.mjs +2 -3
- package/dist/Remove.mjs.map +1 -1
- package/dist/RestoreWatcher.mjs +1 -2
- package/dist/Rollback.mjs +7 -6
- package/dist/Rollback.mjs.map +1 -1
- package/dist/SectionFiles.mjs +77 -48
- package/dist/SectionFiles.mjs.map +1 -1
- package/dist/SnapshotError.mjs +3 -3
- package/dist/SnapshotError.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +1 -2
- package/dist/SpecModulePath.mjs +4 -4
- package/dist/SpecModulePath.mjs.map +1 -1
- package/dist/SyncState.mjs +3 -4
- package/dist/SyncState.mjs.map +1 -1
- package/dist/TableModule.mjs +18 -10
- package/dist/TableModule.mjs.map +1 -1
- package/dist/TableModulePath.mjs +3 -3
- package/dist/TableModulePath.mjs.map +1 -1
- package/dist/TypeScriptConfig.mjs +135 -0
- package/dist/TypeScriptConfig.mjs.map +1 -0
- package/dist/WatchBuild.mjs +107 -32
- package/dist/WatchBuild.mjs.map +1 -1
- package/dist/WatchGraph.mjs +4 -4
- package/dist/WatchGraph.mjs.map +1 -1
- package/dist/WatchTopology.mjs +5 -4
- package/dist/WatchTopology.mjs.map +1 -1
- package/dist/Watcher.mjs +179 -108
- package/dist/Watcher.mjs.map +1 -1
- package/dist/cliApp.mjs +5 -3
- package/dist/cliApp.mjs.map +1 -1
- package/dist/confect/codegen.mjs +95 -53
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/declaration.mjs +76 -42
- package/dist/confect/declaration.mjs.map +1 -1
- package/dist/confect/dev.mjs +18 -12
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/confect.mjs +4 -2
- package/dist/confect.mjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/log.mjs +13 -5
- package/dist/log.mjs.map +1 -1
- package/dist/package.json.mjs +5 -0
- package/dist/package.json.mjs.map +1 -0
- package/dist/templates.mjs +34 -22
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +36 -5
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -10
- package/dist/package.mjs +0 -6
- package/dist/package.mjs.map +0 -1
package/dist/FunctionModule.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { fromGroupModulePath, modulePath } from "./GroupPath.mjs";
|
|
2
|
-
import { ProjectRoot } from "./ProjectRoot.mjs";
|
|
3
|
-
import { logFileAdded, logFileModified, logFileRemoved } from "./log.mjs";
|
|
4
1
|
import { UnownedConvexEntrypointError } from "./CodegenError.mjs";
|
|
5
|
-
import { ConvexDirectory } from "./ConvexDirectory.mjs";
|
|
6
|
-
import { ConfectDirectory } from "./ConfectDirectory.mjs";
|
|
7
|
-
import { CodeBlockWriter } from "./CodeBlockWriter.mjs";
|
|
8
|
-
import { crons, declaredHttp, http } from "./templates.mjs";
|
|
9
|
-
import { removePathIfExists, toModuleImportPath, toPosixPath } from "./utils.mjs";
|
|
10
|
-
import { GroupPaths } from "./GroupPaths.mjs";
|
|
11
2
|
import { isGenerated } from "./Declaration.mjs";
|
|
12
3
|
import { written } from "./SectionFiles.mjs";
|
|
4
|
+
import { crons, declaredHttp, http } from "./templates.mjs";
|
|
13
5
|
import { functionPaths, plan } from "./GenerationSnapshot.mjs";
|
|
6
|
+
import { fromGroupModulePath, modulePath } from "./GroupPath.mjs";
|
|
7
|
+
import { GroupPaths } from "./GroupPaths.mjs";
|
|
8
|
+
import { CodeBlockWriter } from "./CodeBlockWriter.mjs";
|
|
9
|
+
import { logFileAdded, logFileModified, logFileRemoved } from "./log.mjs";
|
|
10
|
+
import { ConfectDirectory } from "./ConfectDirectory.mjs";
|
|
11
|
+
import { ConvexDirectory } from "./ConvexDirectory.mjs";
|
|
12
|
+
import { removePathIfExists, toModuleImportPath, toPosixPath } from "./utils.mjs";
|
|
13
|
+
import { ProjectRoot } from "./ProjectRoot.mjs";
|
|
14
|
+
import { quote } from "./Json.mjs";
|
|
14
15
|
import * as Effect from "effect/Effect";
|
|
15
16
|
import * as FileSystem from "effect/FileSystem";
|
|
16
17
|
import * as Path from "effect/Path";
|
|
@@ -18,8 +19,9 @@ import * as Array from "effect/Array";
|
|
|
18
19
|
import { pipe } from "effect/Function";
|
|
19
20
|
import * as HashSet from "effect/HashSet";
|
|
20
21
|
import * as Match from "effect/Match";
|
|
21
|
-
import * as
|
|
22
|
-
|
|
22
|
+
import * as Option from "effect/Option";
|
|
23
|
+
import * as String from "effect/String";
|
|
24
|
+
// src/FunctionModule.ts
|
|
23
25
|
const RESERVED_CONVEX_TS_FILE_NAMES = /* @__PURE__ */ new Set([
|
|
24
26
|
"schema.ts",
|
|
25
27
|
"http.ts",
|
|
@@ -33,10 +35,13 @@ const getEntrypoints = Effect.gen(function* () {
|
|
|
33
35
|
const path = yield* Path.Path;
|
|
34
36
|
const convex = yield* ConvexDirectory.get;
|
|
35
37
|
const files = yield* fs.readDirectory(convex, { recursive: true });
|
|
36
|
-
const components = files.filter((file) => path.basename(file) === "convex.config.ts" && path.dirname(file) !== ".").map((file) => path.dirname(file) + path.sep);
|
|
37
|
-
return
|
|
38
|
+
const components = pipe(files, Array.filter((file) => path.basename(file) === "convex.config.ts" && path.dirname(file) !== "."), Array.map((file) => path.dirname(file) + path.sep));
|
|
39
|
+
return Array.filter(files, (file) => {
|
|
38
40
|
const base = path.basename(file);
|
|
39
|
-
return !file.startsWith("_generated" + path.sep) && !
|
|
41
|
+
return !pipe(file, String.startsWith("_generated" + path.sep)) && !Array.some(components, (component) => pipe(file, String.startsWith(component))) && /\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) && !pipe(base, String.startsWith(".")) && !pipe(base, String.startsWith("#")) && pipe(base, String.match(/\./g), Option.match({
|
|
42
|
+
onNone: () => 0,
|
|
43
|
+
onSome: (dots) => dots.length
|
|
44
|
+
})) === 1 && base !== "schema.ts" && base !== "schema.js" && !pipe(file, String.includes(" "));
|
|
40
45
|
});
|
|
41
46
|
});
|
|
42
47
|
const tokenize = (source, modulePath, path) => {
|
|
@@ -47,14 +52,13 @@ const tokenize = (source, modulePath, path) => {
|
|
|
47
52
|
if (match === null) return void 0;
|
|
48
53
|
const value = match[0];
|
|
49
54
|
if (/^\s|^\//.test(value)) continue;
|
|
50
|
-
if (value.startsWith("\"") || value.startsWith("'")) {
|
|
51
|
-
const literal = value.slice(1, -1);
|
|
52
|
-
tokens.push(
|
|
55
|
+
if (pipe(value, String.startsWith("\"")) || pipe(value, String.startsWith("'"))) {
|
|
56
|
+
const literal = pipe(value, String.slice(1, -1));
|
|
57
|
+
tokens.push(quote(pipe(literal, String.startsWith(".")) ? path.resolve(path.dirname(modulePath), pipe(literal, String.replace(/\.js$/, ""))) : literal));
|
|
53
58
|
} else tokens.push(value);
|
|
54
59
|
}
|
|
55
60
|
return tokens;
|
|
56
61
|
};
|
|
57
|
-
const encodeString = Schema.encodeSync(Schema.fromJsonString(Schema.String));
|
|
58
62
|
const matchesShape = (actual, expected) => {
|
|
59
63
|
let index = 0;
|
|
60
64
|
for (const token of expected) {
|
|
@@ -64,6 +68,10 @@ const matchesShape = (actual, expected) => {
|
|
|
64
68
|
}
|
|
65
69
|
return index === actual.length;
|
|
66
70
|
};
|
|
71
|
+
const legacyRouter = String.replace("HttpRouter.make(schema, http.routes, ", "HttpRouter.forSchema(schema)(http.routes, ");
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
67
75
|
const assertOwnedEntrypoints = Effect.gen(function* () {
|
|
68
76
|
const fs = yield* FileSystem.FileSystem;
|
|
69
77
|
const path = yield* Path.Path;
|
|
@@ -71,7 +79,7 @@ const assertOwnedEntrypoints = Effect.gen(function* () {
|
|
|
71
79
|
const confect = yield* ConfectDirectory.get;
|
|
72
80
|
const projectRoot = yield* ProjectRoot.get;
|
|
73
81
|
const importFromConvex = (file) => toModuleImportPath(path.relative(convex, path.join(confect, file)));
|
|
74
|
-
const
|
|
82
|
+
const httpTemplates = [
|
|
75
83
|
yield* http({ httpImportPath: yield* importFromConvex("http.ts") }),
|
|
76
84
|
yield* declaredHttp({
|
|
77
85
|
schemaImportPath: yield* importFromConvex("_generated/schema.ts"),
|
|
@@ -82,8 +90,10 @@ const assertOwnedEntrypoints = Effect.gen(function* () {
|
|
|
82
90
|
httpImportPath: yield* importFromConvex("http.ts"),
|
|
83
91
|
runtimeImportPath: yield* importFromConvex("runtime.ts")
|
|
84
92
|
})
|
|
85
|
-
]
|
|
86
|
-
const
|
|
93
|
+
];
|
|
94
|
+
const optional = /* @__PURE__ */ new Map([["http.ts", Array.flatMap(httpTemplates, (template) => [template, legacyRouter(template)])], ["crons.ts", [yield* crons({ cronsImportPath: yield* importFromConvex("crons.ts") })]]]);
|
|
95
|
+
const written2 = yield* written;
|
|
96
|
+
const sectionImports = new Set(Array.map(written2, (file) => quote(path.join(confect, "_generated", path.basename(file, ".ts")))));
|
|
87
97
|
const withoutSectionImports = (tokens) => tokens[0] === "import" && sectionImports.has(tokens[1] ?? "") ? withoutSectionImports(tokens.slice(tokens[2] === ";" ? 3 : 2)) : tokens;
|
|
88
98
|
const refused = [];
|
|
89
99
|
for (const relative of yield* getEntrypoints) {
|
|
@@ -92,28 +102,33 @@ const assertOwnedEntrypoints = Effect.gen(function* () {
|
|
|
92
102
|
if (relative === DEPLOY_MODULE && isGenerated(contents, [])) continue;
|
|
93
103
|
const tokens = tokenize(contents, absolute, path);
|
|
94
104
|
if (tokens !== void 0) {
|
|
95
|
-
|
|
105
|
+
const shapes = optional.get(relative);
|
|
106
|
+
if (shapes !== void 0 && Array.some(shapes, (template) => matchesShape(relative === "http.ts" ? withoutSectionImports(tokens) : tokens, tokenize(template, absolute, path)))) continue;
|
|
96
107
|
if (path.extname(relative) === ".ts") {
|
|
97
|
-
const names =
|
|
108
|
+
const names = Array.flatMap(tokens, (token, index) => token === "export" && tokens[index + 1] === "const" ? [tokens[index + 2]] : []);
|
|
98
109
|
const group = yield* fromGroupModulePath(relative);
|
|
110
|
+
const reusesContext = names.includes("experimental_reuseContext");
|
|
111
|
+
const functionNames = Array.filter(names, (name) => name !== "experimental_reuseContext");
|
|
99
112
|
const template = yield* render({
|
|
100
|
-
functionNames
|
|
113
|
+
functionNames,
|
|
101
114
|
registeredFunctionsImportPath: yield* registeredFunctionsImportPathForGroup(group, absolute),
|
|
102
|
-
useNode: tokens[0] === "\"use node\""
|
|
115
|
+
useNode: tokens[0] === "\"use node\"",
|
|
116
|
+
experimental_reuseContext: reusesContext
|
|
103
117
|
});
|
|
104
|
-
if (
|
|
118
|
+
if (functionNames.length > 0 && new Set(functionNames).size === functionNames.length && matchesShape(tokens, tokenize(template, absolute, path))) continue;
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));
|
|
108
122
|
}
|
|
109
|
-
if (refused.length > 0) return yield*
|
|
123
|
+
if (refused.length > 0) return yield* UnownedConvexEntrypointError.make({ filePaths: refused.sort() });
|
|
110
124
|
});
|
|
111
|
-
const render = ({ functionNames, registeredFunctionsImportPath, useNode = false }) => renderEffect({
|
|
125
|
+
const render = ({ functionNames, registeredFunctionsImportPath, useNode = false, experimental_reuseContext = false }) => renderEffect({
|
|
112
126
|
functionNames,
|
|
113
127
|
registeredFunctionsImportPath,
|
|
114
|
-
useNode
|
|
128
|
+
useNode,
|
|
129
|
+
experimental_reuseContext
|
|
115
130
|
});
|
|
116
|
-
const renderEffect = Effect.fnUntraced(function* ({ functionNames, registeredFunctionsImportPath, useNode = false }) {
|
|
131
|
+
const renderEffect = Effect.fnUntraced(function* ({ functionNames, registeredFunctionsImportPath, useNode = false, experimental_reuseContext = false }) {
|
|
117
132
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
118
133
|
if (useNode) {
|
|
119
134
|
yield* cbw.writeLine(`"use node";`);
|
|
@@ -121,34 +136,43 @@ const renderEffect = Effect.fnUntraced(function* ({ functionNames, registeredFun
|
|
|
121
136
|
}
|
|
122
137
|
yield* cbw.writeLine(`import registeredFunctions from "${registeredFunctionsImportPath}";`);
|
|
123
138
|
yield* cbw.newLine();
|
|
139
|
+
if (experimental_reuseContext) {
|
|
140
|
+
yield* cbw.writeLine("export const experimental_reuseContext = true;");
|
|
141
|
+
yield* cbw.newLine();
|
|
142
|
+
}
|
|
124
143
|
yield* Effect.forEach(functionNames, (name) => cbw.writeLine(`export const ${name} = registeredFunctions.${name};`));
|
|
125
144
|
return yield* cbw.toString();
|
|
126
145
|
});
|
|
127
|
-
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
const generateGroupModule = ({ groupPath, functionNames, registeredFunctionsImportPath, useNode = false, experimental_reuseContext = false }) => generateGroupModuleEffect({
|
|
128
150
|
groupPath,
|
|
129
151
|
functionNames,
|
|
130
152
|
registeredFunctionsImportPath,
|
|
131
|
-
useNode
|
|
153
|
+
useNode,
|
|
154
|
+
experimental_reuseContext
|
|
132
155
|
});
|
|
133
|
-
const generateGroupModuleEffect = Effect.fnUntraced(function* ({ groupPath, functionNames, registeredFunctionsImportPath, useNode = false }) {
|
|
156
|
+
const generateGroupModuleEffect = Effect.fnUntraced(function* ({ groupPath, functionNames, registeredFunctionsImportPath, useNode = false, experimental_reuseContext = false }) {
|
|
134
157
|
const fs = yield* FileSystem.FileSystem;
|
|
135
158
|
const path = yield* Path.Path;
|
|
136
159
|
const convexDirectory = yield* ConvexDirectory.get;
|
|
137
160
|
const relativeModulePath = yield* modulePath(groupPath);
|
|
138
|
-
const modulePath$
|
|
139
|
-
const directoryPath = path.dirname(modulePath$
|
|
161
|
+
const modulePath$2 = path.join(convexDirectory, relativeModulePath);
|
|
162
|
+
const directoryPath = path.dirname(modulePath$2);
|
|
140
163
|
if (!(yield* fs.exists(directoryPath))) yield* fs.makeDirectory(directoryPath, { recursive: true });
|
|
141
164
|
const functionsContentsString = yield* render({
|
|
142
165
|
functionNames,
|
|
143
166
|
registeredFunctionsImportPath,
|
|
144
|
-
useNode
|
|
167
|
+
useNode,
|
|
168
|
+
experimental_reuseContext
|
|
145
169
|
});
|
|
146
|
-
if (!(yield* fs.exists(modulePath$
|
|
147
|
-
yield* fs.writeFileString(modulePath$
|
|
170
|
+
if (!(yield* fs.exists(modulePath$2))) {
|
|
171
|
+
yield* fs.writeFileString(modulePath$2, functionsContentsString);
|
|
148
172
|
return "Added";
|
|
149
173
|
}
|
|
150
|
-
if ((yield* fs.readFileString(modulePath$
|
|
151
|
-
yield* fs.writeFileString(modulePath$
|
|
174
|
+
if ((yield* fs.readFileString(modulePath$2)) !== functionsContentsString) {
|
|
175
|
+
yield* fs.writeFileString(modulePath$2, functionsContentsString);
|
|
152
176
|
return "Modified";
|
|
153
177
|
}
|
|
154
178
|
return "Unchanged";
|
|
@@ -159,6 +183,8 @@ const generateGroupModuleEffect = Effect.fnUntraced(function* ({ groupPath, func
|
|
|
159
183
|
* path mirrors the group's path one-to-one (see
|
|
160
184
|
* `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and
|
|
161
185
|
* Node groups.
|
|
186
|
+
*
|
|
187
|
+
* @internal
|
|
162
188
|
*/
|
|
163
189
|
const registeredFunctionsImportPathForGroup = Effect.fnUntraced(function* (groupPath, modulePath) {
|
|
164
190
|
const path = yield* Path.Path;
|
|
@@ -174,11 +200,17 @@ const logGroupPaths = Effect.fnUntraced(function* (groupPaths, logFn) {
|
|
|
174
200
|
yield* logFn(path.join(convexDirectory, relativeModulePath));
|
|
175
201
|
}));
|
|
176
202
|
});
|
|
203
|
+
/**
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
177
206
|
const generateFunctions = Effect.fnUntraced(function* (snapshot) {
|
|
178
207
|
const groupPathsFromFs = yield* getGroupPathsFromFs;
|
|
179
208
|
yield* applyFunctionPlan(plan(snapshot, groupPathsFromFs));
|
|
180
209
|
return functionPaths(snapshot);
|
|
181
210
|
});
|
|
211
|
+
/**
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
182
214
|
const applyFunctionPlan = Effect.fnUntraced(function* (plan) {
|
|
183
215
|
const removed = GroupPaths.make(HashSet.fromIterable(plan.removed));
|
|
184
216
|
yield* removeGroups(removed);
|
|
@@ -191,32 +223,38 @@ const getGroupPathsFromFs = Effect.gen(function* () {
|
|
|
191
223
|
const groupPathArray = yield* pipe(allConvexPaths, Array.filter((convexPath) => path.extname(convexPath) === ".ts" && !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) && convexPath !== DEPLOY_MODULE), Effect.forEach((groupModulePath) => fromGroupModulePath(groupModulePath)));
|
|
192
224
|
return GroupPaths.make(HashSet.fromIterable(groupPathArray));
|
|
193
225
|
});
|
|
226
|
+
/**
|
|
227
|
+
* @internal
|
|
228
|
+
*/
|
|
194
229
|
const removeGroups = Effect.fnUntraced(function* (groupPaths) {
|
|
195
230
|
const path = yield* Path.Path;
|
|
196
231
|
const convexDirectory = yield* ConvexDirectory.get;
|
|
197
232
|
yield* Effect.all(HashSet.map(groupPaths, (groupPath) => Effect.gen(function* () {
|
|
198
233
|
const relativeModulePath = yield* modulePath(groupPath);
|
|
199
|
-
const modulePath$
|
|
234
|
+
const modulePath$1 = path.join(convexDirectory, relativeModulePath);
|
|
200
235
|
yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);
|
|
201
|
-
yield* removePathIfExists(modulePath$
|
|
236
|
+
yield* removePathIfExists(modulePath$1);
|
|
202
237
|
yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);
|
|
203
238
|
})), { concurrency: "unbounded" });
|
|
204
239
|
});
|
|
240
|
+
/**
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
205
243
|
const writeGroups = (groups) => Effect.forEach(groups, Effect.fnUntraced(function* (group) {
|
|
206
244
|
const path = yield* Path.Path;
|
|
207
245
|
const convexDirectory = yield* ConvexDirectory.get;
|
|
208
246
|
const relativeModulePath = yield* modulePath(group.path);
|
|
209
|
-
const modulePath$
|
|
210
|
-
const registeredFunctionsImportPath = yield* registeredFunctionsImportPathForGroup(group.path, modulePath$
|
|
247
|
+
const modulePath$3 = path.join(convexDirectory, relativeModulePath);
|
|
248
|
+
const registeredFunctionsImportPath = yield* registeredFunctionsImportPathForGroup(group.path, modulePath$3);
|
|
211
249
|
const change = yield* generateGroupModule({
|
|
212
250
|
groupPath: group.path,
|
|
213
251
|
functionNames: group.functionNames,
|
|
214
252
|
registeredFunctionsImportPath,
|
|
215
|
-
useNode: group.runtime === "Node"
|
|
253
|
+
useNode: group.runtime === "Node",
|
|
254
|
+
experimental_reuseContext: group.experimental_reuseContext === true
|
|
216
255
|
});
|
|
217
|
-
yield* Match.value(change).pipe(Match.when("Added", () => logFileAdded(modulePath$
|
|
256
|
+
yield* Match.value(change).pipe(Match.when("Added", () => logFileAdded(modulePath$3)), Match.when("Modified", () => logFileModified(modulePath$3)), Match.when("Unchanged", () => Effect.void), Match.exhaustive);
|
|
218
257
|
}));
|
|
219
|
-
//#endregion
|
|
220
258
|
export { applyFunctionPlan, assertOwnedEntrypoints, generateFunctions, generateGroupModule, registeredFunctionsImportPathForGroup, removeGroups, render, writeGroups };
|
|
221
259
|
|
|
222
260
|
//# sourceMappingURL=FunctionModule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionModule.mjs","names":["templates.http","templates.declaredHttp","templates.crons","SectionFiles.written","Declaration.isGenerated","GroupPath.fromGroupModulePath","GroupPath.modulePath","modulePath","GenerationSnapshot.plan","GenerationSnapshot.functionPaths"],"sources":["../src/FunctionModule.ts"],"sourcesContent":["import * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Schema from \"effect/Schema\";\nimport { UnownedConvexEntrypointError } from \"./CodegenError.js\";\nimport * as Declaration from \"./Declaration.js\";\nimport * as SectionFiles from \"./SectionFiles.js\";\nimport * as templates from \"./templates.js\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport * as GroupPaths from \"./GroupPaths.js\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter.js\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n} from \"./utils.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\n\nconst RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n]);\n\n// Only the root module is codegen's; a nested group may take the name.\nconst DEPLOY_MODULE = \"confectDeploy.ts\";\n\n// Keep ownership and removal aligned with Convex's bundler entryPoints filter.\nconst getEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const files = yield* fs.readDirectory(convex, { recursive: true });\n const components = files\n .filter(\n (file) =>\n path.basename(file) === \"convex.config.ts\" &&\n path.dirname(file) !== \".\",\n )\n .map((file) => path.dirname(file) + path.sep);\n return files.filter((file) => {\n const base = path.basename(file);\n return (\n !file.startsWith(\"_generated\" + path.sep) &&\n !components.some((component) => file.startsWith(component)) &&\n /\\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) &&\n !base.startsWith(\".\") &&\n !base.startsWith(\"#\") &&\n (base.match(/\\./g)?.length ?? 0) === 1 &&\n base !== \"schema.ts\" &&\n base !== \"schema.js\" &&\n !file.includes(\" \")\n );\n });\n});\n\nconst tokenize = (\n source: string,\n modulePath: string,\n path: Path.Path,\n): string[] | undefined => {\n const token =\n /\\s+|\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/|\"(?:\\\\.|[^\"\\\\\\r\\n])*\"|'(?:\\\\.|[^'\\\\\\r\\n])*'|[$A-Z_a-z][$\\w]*|[{}()[\\].,:;=]/y;\n const tokens: string[] = [];\n while (token.lastIndex < source.length) {\n const match = token.exec(source);\n if (match === null) return undefined;\n const value = match[0];\n if (/^\\s|^\\//.test(value)) continue;\n if (value.startsWith('\"') || value.startsWith(\"'\")) {\n const literal = value.slice(1, -1);\n tokens.push(\n JSON.stringify(\n literal.startsWith(\".\")\n ? path.resolve(\n path.dirname(modulePath),\n literal.replace(/\\.js$/, \"\"),\n )\n : literal,\n ),\n );\n } else tokens.push(value);\n }\n return tokens;\n};\n\nconst encodeString = Schema.encodeSync(Schema.fromJsonString(Schema.String));\n\nconst matchesShape = (\n actual: readonly string[],\n expected: readonly string[],\n) => {\n let index = 0;\n for (const token of expected) {\n if (token === \";\" && actual[index] !== \";\") continue;\n if (actual[index] === \",\" && (token === \"}\" || token === \")\")) index++;\n if (actual[index++] !== token) return false;\n }\n return index === actual.length;\n};\n\nexport const assertOwnedEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const confect = yield* ConfectDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const importFromConvex = (file: string) =>\n toModuleImportPath(path.relative(convex, path.join(confect, file)));\n const optional = new Map([\n [\n \"http.ts\",\n [\n yield* templates.http({\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n runtimeImportPath: yield* importFromConvex(\"runtime.ts\"),\n }),\n ],\n ],\n [\n \"crons.ts\",\n [\n yield* templates.crons({\n cronsImportPath: yield* importFromConvex(\"crons.ts\"),\n }),\n ],\n ],\n ]);\n // The declared HTTP router first imports each file a manifest section wrote.\n const sectionImports = new Set(\n (yield* SectionFiles.written).map((file) =>\n encodeString(\n path.join(confect, \"_generated\", path.basename(file, \".ts\")),\n ),\n ),\n );\n const withoutSectionImports = (\n tokens: ReadonlyArray<string>,\n ): ReadonlyArray<string> =>\n tokens[0] === \"import\" && sectionImports.has(tokens[1] ?? \"\")\n ? withoutSectionImports(tokens.slice(tokens[2] === \";\" ? 3 : 2))\n : tokens;\n const refused: string[] = [];\n for (const relative of yield* getEntrypoints) {\n const absolute = path.join(convex, relative);\n const contents = yield* fs.readFileString(absolute);\n if (relative === DEPLOY_MODULE && Declaration.isGenerated(contents, []))\n continue;\n const tokens = tokenize(contents, absolute, path);\n if (tokens !== undefined) {\n if (\n optional\n .get(relative)\n ?.some((template) =>\n matchesShape(\n relative === \"http.ts\" ? withoutSectionImports(tokens) : tokens,\n tokenize(template, absolute, path)!,\n ),\n )\n )\n continue;\n if (path.extname(relative) === \".ts\") {\n const names = tokens.flatMap((token, index) =>\n token === \"export\" && tokens[index + 1] === \"const\"\n ? [tokens[index + 2]!]\n : [],\n );\n const group = yield* GroupPath.fromGroupModulePath(relative);\n const template = yield* render({\n functionNames: names,\n registeredFunctionsImportPath:\n yield* registeredFunctionsImportPathForGroup(group, absolute),\n useNode: tokens[0] === '\"use node\"',\n });\n if (\n names.length > 0 &&\n new Set(names).size === names.length &&\n matchesShape(tokens, tokenize(template, absolute, path)!)\n )\n continue;\n }\n }\n refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));\n }\n if (refused.length > 0)\n return yield* new UnownedConvexEntrypointError({\n filePaths: refused.sort(),\n });\n});\n\nexport const render = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: Parameters<typeof renderEffect>[0]) =>\n renderEffect({ functionNames, registeredFunctionsImportPath, useNode });\n\nconst renderEffect = Effect.fnUntraced(function* ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) {\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, (name) =>\n cbw.writeLine(`export const ${name} = registeredFunctions.${name};`),\n );\n\n return yield* cbw.toString();\n});\n\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: Parameters<typeof generateGroupModuleEffect>[0]) =>\n generateGroupModuleEffect({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n });\n\nconst generateGroupModuleEffect = Effect.fnUntraced(function* ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const functionsContentsString = yield* render({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n});\n\n/**\n * Compute the module import specifier (relative to `modulePath`) for a group's\n * registry file under `confect/_generated/registeredFunctions/`. The registry\n * path mirrors the group's path one-to-one (see\n * `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and\n * Node groups.\n */\nexport const registeredFunctionsImportPathForGroup = Effect.fnUntraced(\n function* (groupPath: GroupPath.GroupPath, modulePath: string) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const registeredFunctionsPath =\n path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n ...groupPath.pathSegments,\n ) + \".ts\";\n\n return yield* toModuleImportPath(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n },\n);\n\nconst logGroupPaths = Effect.fnUntraced(function* <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n): Effect.fn.Return<void, never, R | Path.Path | ConvexDirectory> {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(\n groupPaths,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n});\n\nexport const generateFunctions = Effect.fnUntraced(function* (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n) {\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n yield* applyFunctionPlan(GenerationSnapshot.plan(snapshot, groupPathsFromFs));\n return GenerationSnapshot.functionPaths(snapshot);\n});\n\nexport const applyFunctionPlan = Effect.fnUntraced(function* (\n plan: GenerationSnapshot.ModulePlan,\n) {\n const removed = GroupPaths.GroupPaths.make(\n HashSet.fromIterable(plan.removed),\n );\n yield* removeGroups(removed);\n yield* logGroupPaths(removed, logFileRemoved);\n yield* writeGroups(plan.changed);\n});\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const path = yield* Path.Path;\n const allConvexPaths = yield* getEntrypoints;\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&\n convexPath !== DEPLOY_MODULE,\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return GroupPaths.GroupPaths.make(HashSet.fromIterable(groupPathArray));\n});\n\nexport const removeGroups = Effect.fnUntraced(function* (\n groupPaths: GroupPaths.GroupPaths,\n) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* removePathIfExists(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n});\n\nexport const writeGroups = (\n groups: ReadonlyArray<GenerationSnapshot.GroupSummary>,\n) =>\n Effect.forEach(\n groups,\n Effect.fnUntraced(function* (group: GenerationSnapshot.GroupSummary) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const relativeModulePath = yield* GroupPath.modulePath(group.path);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n const registeredFunctionsImportPath =\n yield* registeredFunctionsImportPathForGroup(group.path, modulePath);\n const change = yield* generateGroupModule({\n groupPath: group.path,\n functionNames: group.functionNames,\n registeredFunctionsImportPath,\n useNode: group.runtime === \"Node\",\n });\n yield* Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(modulePath)),\n Match.when(\"Modified\", () => logFileModified(modulePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n );\n }),\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mB,OAAO,IAAI,GACzC,MAAM,UACR;AACF,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"FunctionModule.mjs","names":["templates.http","templates.declaredHttp","templates.crons","SectionFiles.written","Declaration.isGenerated","GroupPath.fromGroupModulePath","GroupPath.modulePath","modulePath","GenerationSnapshot.plan","GenerationSnapshot.functionPaths"],"sources":["../src/FunctionModule.ts"],"sourcesContent":["import * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as String from \"effect/String\";\nimport { UnownedConvexEntrypointError } from \"./CodegenError.js\";\nimport * as Declaration from \"./Declaration.js\";\nimport * as SectionFiles from \"./SectionFiles.js\";\nimport * as templates from \"./templates.js\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport * as GroupPaths from \"./GroupPaths.js\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter.js\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n} from \"./utils.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\nimport * as Option from \"effect/Option\";\nimport { quote } from \"./Json.js\";\n\nconst RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n]);\n\n// Only the root module is codegen's; a nested group may take the name.\nconst DEPLOY_MODULE = \"confectDeploy.ts\";\n\n// Keep ownership and removal aligned with Convex's bundler entryPoints filter.\nconst getEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const files = yield* fs.readDirectory(convex, { recursive: true });\n const components = pipe(\n files,\n Array.filter(\n (file) =>\n path.basename(file) === \"convex.config.ts\" &&\n path.dirname(file) !== \".\",\n ),\n Array.map((file) => path.dirname(file) + path.sep),\n );\n return Array.filter(files, (file) => {\n const base = path.basename(file);\n return (\n !pipe(file, String.startsWith(\"_generated\" + path.sep)) &&\n !Array.some(components, (component) =>\n pipe(file, String.startsWith(component)),\n ) &&\n /\\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) &&\n !pipe(base, String.startsWith(\".\")) &&\n !pipe(base, String.startsWith(\"#\")) &&\n pipe(\n base,\n String.match(/\\./g),\n Option.match({ onNone: () => 0, onSome: (dots) => dots.length }),\n ) === 1 &&\n base !== \"schema.ts\" &&\n base !== \"schema.js\" &&\n !pipe(file, String.includes(\" \"))\n );\n });\n});\n\nconst tokenize = (\n source: string,\n modulePath: string,\n path: Path.Path,\n): string[] | undefined => {\n const token =\n /\\s+|\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/|\"(?:\\\\.|[^\"\\\\\\r\\n])*\"|'(?:\\\\.|[^'\\\\\\r\\n])*'|[$A-Z_a-z][$\\w]*|[{}()[\\].,:;=]/y;\n const tokens: string[] = [];\n while (token.lastIndex < source.length) {\n const match = token.exec(source);\n if (match === null) return undefined;\n const value = match[0];\n if (/^\\s|^\\//.test(value)) continue;\n if (\n pipe(value, String.startsWith('\"')) ||\n pipe(value, String.startsWith(\"'\"))\n ) {\n const literal = pipe(value, String.slice(1, -1));\n tokens.push(\n quote(\n pipe(literal, String.startsWith(\".\"))\n ? path.resolve(\n path.dirname(modulePath),\n pipe(literal, String.replace(/\\.js$/, \"\")),\n )\n : literal,\n ),\n );\n } else tokens.push(value);\n }\n return tokens;\n};\n\nconst matchesShape = (\n actual: readonly string[],\n expected: readonly string[],\n) => {\n let index = 0;\n for (const token of expected) {\n if (token === \";\" && actual[index] !== \";\") continue;\n if (actual[index] === \",\" && (token === \"}\" || token === \")\")) index++;\n if (actual[index++] !== token) return false;\n }\n return index === actual.length;\n};\n\n// Before the schema-first HttpRouter.make, codegen emitted forSchema; codegen\n// owns that output so it can rewrite it.\nconst legacyRouter = String.replace(\n \"HttpRouter.make(schema, http.routes, \",\n \"HttpRouter.forSchema(schema)(http.routes, \",\n);\n\n/**\n * @internal\n */\nexport const assertOwnedEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const confect = yield* ConfectDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const importFromConvex = (file: string) =>\n toModuleImportPath(path.relative(convex, path.join(confect, file)));\n const httpTemplates = [\n yield* templates.http({\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n runtimeImportPath: yield* importFromConvex(\"runtime.ts\"),\n }),\n ];\n const optional = new Map([\n [\n \"http.ts\",\n Array.flatMap(httpTemplates, (template) => [\n template,\n legacyRouter(template),\n ]),\n ],\n [\n \"crons.ts\",\n [\n yield* templates.crons({\n cronsImportPath: yield* importFromConvex(\"crons.ts\"),\n }),\n ],\n ],\n ]);\n const written2 = yield* SectionFiles.written;\n // The declared HTTP router first imports each file a manifest section wrote.\n const sectionImports = new Set(\n Array.map(written2, (file) =>\n quote(path.join(confect, \"_generated\", path.basename(file, \".ts\"))),\n ),\n );\n const withoutSectionImports = (\n tokens: ReadonlyArray<string>,\n ): ReadonlyArray<string> =>\n tokens[0] === \"import\" && sectionImports.has(tokens[1] ?? \"\")\n ? withoutSectionImports(tokens.slice(tokens[2] === \";\" ? 3 : 2))\n : tokens;\n const refused: string[] = [];\n for (const relative of yield* getEntrypoints) {\n const absolute = path.join(convex, relative);\n const contents = yield* fs.readFileString(absolute);\n if (relative === DEPLOY_MODULE && Declaration.isGenerated(contents, []))\n continue;\n const tokens = tokenize(contents, absolute, path);\n if (tokens !== undefined) {\n const shapes = optional.get(relative);\n if (\n shapes !== undefined &&\n Array.some(shapes, (template) =>\n matchesShape(\n relative === \"http.ts\" ? withoutSectionImports(tokens) : tokens,\n tokenize(template, absolute, path)!,\n ),\n )\n )\n continue;\n if (path.extname(relative) === \".ts\") {\n const names = Array.flatMap(tokens, (token, index) =>\n token === \"export\" && tokens[index + 1] === \"const\"\n ? [tokens[index + 2]!]\n : [],\n );\n const group = yield* GroupPath.fromGroupModulePath(relative);\n const reusesContext = names.includes(\"experimental_reuseContext\");\n const functionNames = Array.filter(\n names,\n (name) => name !== \"experimental_reuseContext\",\n );\n const template = yield* render({\n functionNames,\n registeredFunctionsImportPath:\n yield* registeredFunctionsImportPathForGroup(group, absolute),\n useNode: tokens[0] === '\"use node\"',\n experimental_reuseContext: reusesContext,\n });\n if (\n functionNames.length > 0 &&\n new Set(functionNames).size === functionNames.length &&\n matchesShape(tokens, tokenize(template, absolute, path)!)\n )\n continue;\n }\n }\n refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));\n }\n if (refused.length > 0)\n return yield* UnownedConvexEntrypointError.make({\n filePaths: refused.sort(),\n });\n});\n\nexport const render = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: Parameters<typeof renderEffect>[0]) =>\n renderEffect({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\nconst renderEffect = Effect.fnUntraced(function* ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: {\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n experimental_reuseContext?: boolean;\n}) {\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 if (experimental_reuseContext) {\n yield* cbw.writeLine(\"export const experimental_reuseContext = true;\");\n yield* cbw.newLine();\n }\n yield* Effect.forEach(functionNames, (name) =>\n cbw.writeLine(`export const ${name} = registeredFunctions.${name};`),\n );\n\n return yield* cbw.toString();\n});\n\n/**\n * @internal\n */\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: Parameters<typeof generateGroupModuleEffect>[0]) =>\n generateGroupModuleEffect({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\nconst generateGroupModuleEffect = Effect.fnUntraced(function* ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n experimental_reuseContext?: boolean;\n}) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const functionsContentsString = yield* render({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n});\n\n/**\n * Compute the module import specifier (relative to `modulePath`) for a group's\n * registry file under `confect/_generated/registeredFunctions/`. The registry\n * path mirrors the group's path one-to-one (see\n * `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and\n * Node groups.\n *\n * @internal\n */\nexport const registeredFunctionsImportPathForGroup = Effect.fnUntraced(\n function* (groupPath: GroupPath.GroupPath, modulePath: string) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const registeredFunctionsPath =\n path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n ...groupPath.pathSegments,\n ) + \".ts\";\n\n return yield* toModuleImportPath(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n },\n);\n\nconst logGroupPaths = Effect.fnUntraced(function* <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n): Effect.fn.Return<void, never, R | Path.Path | ConvexDirectory> {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(\n groupPaths,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n});\n\n/**\n * @internal\n */\nexport const generateFunctions = Effect.fnUntraced(function* (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n) {\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n yield* applyFunctionPlan(GenerationSnapshot.plan(snapshot, groupPathsFromFs));\n return GenerationSnapshot.functionPaths(snapshot);\n});\n\n/**\n * @internal\n */\nexport const applyFunctionPlan = Effect.fnUntraced(function* (\n plan: GenerationSnapshot.ModulePlan,\n) {\n const removed = GroupPaths.GroupPaths.make(\n HashSet.fromIterable(plan.removed),\n );\n yield* removeGroups(removed);\n yield* logGroupPaths(removed, logFileRemoved);\n yield* writeGroups(plan.changed);\n});\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const path = yield* Path.Path;\n const allConvexPaths = yield* getEntrypoints;\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&\n convexPath !== DEPLOY_MODULE,\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return GroupPaths.GroupPaths.make(HashSet.fromIterable(groupPathArray));\n});\n\n/**\n * @internal\n */\nexport const removeGroups = Effect.fnUntraced(function* (\n groupPaths: GroupPaths.GroupPaths,\n) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* removePathIfExists(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n});\n\n/**\n * @internal\n */\nexport const writeGroups = (\n groups: ReadonlyArray<GenerationSnapshot.GroupSummary>,\n) =>\n Effect.forEach(\n groups,\n Effect.fnUntraced(function* (group: GenerationSnapshot.GroupSummary) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const relativeModulePath = yield* GroupPath.modulePath(group.path);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n const registeredFunctionsImportPath =\n yield* registeredFunctionsImportPathForGroup(group.path, modulePath);\n const change = yield* generateGroupModule({\n groupPath: group.path,\n functionNames: group.functionNames,\n registeredFunctionsImportPath,\n useNode: group.runtime === \"Node\",\n experimental_reuseContext: group.experimental_reuseContext === true,\n });\n yield* Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(modulePath)),\n Match.when(\"Modified\", () => logFileModified(modulePath)),\n Match.when(\"Un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O,OAAO,SAAS,mBAAmB,mBAAmB,KAAK;EAElE,OAAO,mBAAmBA,YAAU;EACpC,OAAO,OAAO,SAAS,UAAU,mBAAmB,UAAU;CAChE,CAAC,CACH,GACA,EAAE,aAAa,YAAY,CAC7B;AACF,CAAC;;;;AAKD,MAAa,eACX,WAEA,OAAO,QACL,QACA,OAAO,WAAW,WAAW,OAAwC;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,kBAAkB,OAAO,gBAAgB;CAC/C,MAAM,qBAAqB,OAAOD,WAAqB,MAAM,IAAI;CACjE,MAAMC,eAAa,KAAK,KAAK,iBAAiB,kBAAkB;CAChE,MAAM,gCACJ,OAAO,sCAAsC,MAAM,MAAMA,YAAU;CACrE,MAAM,SAAS,OAAO,oBAAoB;EACxC,WAAW,MAAM;EACjB,eAAe,MAAM;EACrB;EACA,SAAS,MAAM,YAAY;EAC3B,2BAA2B,MAAM,8BAA8B;CACjE,CAAC;CACD,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KACzB,MAAM,KAAK,eAAe,aAAaA,YAAU,CAAC,GAClD,MAAM,KAAK,kBAAkB,gBAAgBA,YAAU,CAAC,GACxD,MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,UACR;AACF,CAAC,CACH"}
|
package/dist/FunctionPath.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GroupPath } from "./GroupPath.mjs";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
-
|
|
3
|
+
// src/FunctionPath.ts
|
|
4
4
|
/**
|
|
5
5
|
* The path to a function in the Confect API.
|
|
6
6
|
*/
|
|
@@ -12,7 +12,6 @@ var FunctionPath = class extends Schema.Class("FunctionPath")({
|
|
|
12
12
|
* Get the group path from a function path.
|
|
13
13
|
*/
|
|
14
14
|
const groupPath = (functionPath) => functionPath.groupPath;
|
|
15
|
-
//#endregion
|
|
16
15
|
export { FunctionPath, groupPath };
|
|
17
16
|
|
|
18
17
|
//# sourceMappingURL=FunctionPath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionPath.mjs","names":["GroupPath.GroupPath"],"sources":["../src/FunctionPath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as GroupPath from \"./GroupPath.js\";\n\n/**\n * The path to a function in the Confect API.\n */\nexport class FunctionPath extends Schema.Class<FunctionPath>(\"FunctionPath\")({\n groupPath: GroupPath.GroupPath,\n name: Schema.NonEmptyString,\n}) {}\n\n/**\n * Get the group path from a function path.\n */\nexport const groupPath = (functionPath: FunctionPath): GroupPath.GroupPath =>\n functionPath.groupPath;\n\n/**\n * Get the function name from a function path.\n */\nexport const name = (functionPath: FunctionPath): string => functionPath.name;\n\n/**\n * Get the function path as a string.\n */\nexport const toString = (functionPath: FunctionPath): string =>\n `${GroupPath.toString(functionPath.groupPath)}.${functionPath.name}`;\n"],"mappings":";;;;;;AAMA,IAAa,eAAb,cAAkC,OAAO,
|
|
1
|
+
{"version":3,"file":"FunctionPath.mjs","names":["GroupPath.GroupPath"],"sources":["../src/FunctionPath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as GroupPath from \"./GroupPath.js\";\n\n/**\n * The path to a function in the Confect API.\n */\nexport class FunctionPath extends Schema.Class<FunctionPath, {}>(\n \"FunctionPath\",\n)({\n groupPath: GroupPath.GroupPath,\n name: Schema.NonEmptyString,\n}) {}\n\n/**\n * Get the group path from a function path.\n */\nexport const groupPath = (functionPath: FunctionPath): GroupPath.GroupPath =>\n functionPath.groupPath;\n\n/**\n * Get the function name from a function path.\n */\nexport const name = (functionPath: FunctionPath): string => functionPath.name;\n\n/**\n * Get the function path as a string.\n */\nexport const toString = (functionPath: FunctionPath): string =>\n `${GroupPath.toString(functionPath.groupPath)}.${functionPath.name}`;\n"],"mappings":";;;;;;AAMA,IAAa,eAAb,cAAkC,OAAO,MACvC,cACF,CAAC,CAAC;CACA,WAAWA;CACX,MAAM,OAAO;AACf,CAAC,CAAC,CAAC,CAAC;;;;AAKJ,MAAa,aAAa,iBACxB,aAAa"}
|
package/dist/FunctionPaths.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { append, make as make$1 } from "./GroupPath.mjs";
|
|
2
1
|
import { FunctionPath, groupPath } from "./FunctionPath.mjs";
|
|
2
|
+
import { append, make as make$1 } from "./GroupPath.mjs";
|
|
3
3
|
import { GroupPaths } from "./GroupPaths.mjs";
|
|
4
4
|
import { Spec } from "@confect/core";
|
|
5
5
|
import { pipe } from "effect/Function";
|
|
@@ -7,7 +7,7 @@ import * as HashSet from "effect/HashSet";
|
|
|
7
7
|
import * as Option from "effect/Option";
|
|
8
8
|
import * as Record from "effect/Record";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
|
-
|
|
10
|
+
// src/FunctionPaths.ts
|
|
11
11
|
const FunctionPaths = Schema.HashSet(FunctionPath).pipe(Schema.brand("@confect/cli/FunctionPaths"));
|
|
12
12
|
const make = (spec) => makeHelper(Spec.groups(spec), Option.none(), FunctionPaths.make(HashSet.empty()));
|
|
13
13
|
const makeHelper = (groups, currentGroupPath, apiPaths) => Record.reduce(groups, apiPaths, (acc, group, groupName) => {
|
|
@@ -39,7 +39,6 @@ const diff = (previousFunctions, currentFunctions) => {
|
|
|
39
39
|
groupsChanged: pipe(existingGroupsToWhichFunctionsWereAdded, HashSet.union(existingGroupsToWhichFunctionsWereRemoved), HashSet.difference(HashSet.union(groupsAdded, groupsRemoved)), (paths) => GroupPaths.make(paths))
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
//#endregion
|
|
43
42
|
export { FunctionPaths, diff, groupPaths, make };
|
|
44
43
|
|
|
45
44
|
//# sourceMappingURL=FunctionPaths.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GroupPath, append, make } from "./GroupPath.mjs";
|
|
2
|
-
import { SnapshotError } from "./SnapshotError.mjs";
|
|
3
1
|
import { ParentChildNameCollisionError } from "./CodegenError.mjs";
|
|
4
2
|
import { FunctionPath } from "./FunctionPath.mjs";
|
|
5
3
|
import { FunctionPaths } from "./FunctionPaths.mjs";
|
|
4
|
+
import { GroupPath, append, make } from "./GroupPath.mjs";
|
|
6
5
|
import { SpecModulePath } from "./SpecModulePath.mjs";
|
|
6
|
+
import { SnapshotError } from "./SnapshotError.mjs";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
8
|
import { Identifier } from "@confect/core";
|
|
9
9
|
import * as Array from "effect/Array";
|
|
@@ -17,14 +17,16 @@ import * as Schema from "effect/Schema";
|
|
|
17
17
|
import * as String from "effect/String";
|
|
18
18
|
import * as SchemaGetter from "effect/SchemaGetter";
|
|
19
19
|
import * as SchemaIssue from "effect/SchemaIssue";
|
|
20
|
-
|
|
20
|
+
// src/GenerationSnapshot.ts
|
|
21
21
|
const GroupSummary = Schema.Struct({
|
|
22
22
|
path: GroupPath,
|
|
23
23
|
runtime: Schema.Literals(["Convex", "Node"]),
|
|
24
|
+
experimental_reuseContext: Schema.optionalKey(Schema.Boolean),
|
|
24
25
|
functionNames: Schema.Array(Schema.NonEmptyString)
|
|
25
26
|
});
|
|
26
27
|
const GroupTree = Schema.Struct({
|
|
27
28
|
runtime: GroupSummary.fields.runtime,
|
|
29
|
+
experimental_reuseContext: GroupSummary.fields.experimental_reuseContext,
|
|
28
30
|
functionNames: GroupSummary.fields.functionNames,
|
|
29
31
|
groups: Schema.Record(Schema.String, Schema.suspend(() => GroupTree))
|
|
30
32
|
});
|
|
@@ -41,28 +43,33 @@ var Snapshot = class Snapshot {
|
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
45
|
const Entries = Schema.Array(Schema.Tuple([Schema.String, GroupTree]));
|
|
44
|
-
const CanonicalSpecPath = SpecModulePath.check(Schema.makeFilter((path) => !
|
|
45
|
-
const rootPath = (path) => make(String.split(
|
|
46
|
+
const CanonicalSpecPath = SpecModulePath.check(Schema.makeFilter((path) => !String.includes("\\")(path)));
|
|
47
|
+
const rootPath = (path) => make(String.split(String.slice(0, -8)(path), "/"));
|
|
46
48
|
const parseTree = (relativePath, path, tree) => Result.gen(function* () {
|
|
49
|
+
if (tree.experimental_reuseContext === true && (tree.runtime === "Node" || tree.functionNames.includes("experimental_reuseContext"))) return yield* Result.fail(SnapshotError.make({
|
|
50
|
+
reason: "InvalidContextReuse",
|
|
51
|
+
relativePath,
|
|
52
|
+
pathSegments: path.pathSegments
|
|
53
|
+
}));
|
|
47
54
|
yield* Result.try({
|
|
48
55
|
try: () => {
|
|
49
56
|
for (const name of tree.functionNames) Identifier.validateConfectFunctionIdentifier(name);
|
|
50
57
|
},
|
|
51
|
-
catch: () =>
|
|
58
|
+
catch: () => SnapshotError.make({
|
|
52
59
|
reason: "NoncanonicalFunctionNames",
|
|
53
60
|
relativePath,
|
|
54
61
|
pathSegments: path.pathSegments
|
|
55
62
|
})
|
|
56
63
|
});
|
|
57
|
-
if (HashSet.size(HashSet.fromIterable(tree.functionNames)) !== tree.functionNames.length) return yield* Result.fail(
|
|
64
|
+
if (HashSet.size(HashSet.fromIterable(tree.functionNames)) !== tree.functionNames.length) return yield* Result.fail(SnapshotError.make({
|
|
58
65
|
reason: "NoncanonicalFunctionNames",
|
|
59
66
|
relativePath,
|
|
60
67
|
pathSegments: path.pathSegments
|
|
61
68
|
}));
|
|
62
|
-
for (const [name, child] of
|
|
69
|
+
for (const [name, child] of Record.toEntries(tree.groups)) {
|
|
63
70
|
yield* Result.try({
|
|
64
71
|
try: () => Identifier.validateConfectFunctionIdentifier(name),
|
|
65
|
-
catch: () =>
|
|
72
|
+
catch: () => SnapshotError.make({
|
|
66
73
|
reason: "NoncanonicalPath",
|
|
67
74
|
relativePath,
|
|
68
75
|
pathSegments: [...path.pathSegments, name]
|
|
@@ -75,7 +82,7 @@ const parseTree = (relativePath, path, tree) => Result.gen(function* () {
|
|
|
75
82
|
const fromEntries = (entries) => Result.gen(function* () {
|
|
76
83
|
let leaves = HashMap.empty();
|
|
77
84
|
for (const [key, tree] of entries) {
|
|
78
|
-
const relativePath = yield* Schema.decodeResult(CanonicalSpecPath)(key).pipe(Result.mapError((cause) =>
|
|
85
|
+
const relativePath = yield* Schema.decodeResult(CanonicalSpecPath)(key).pipe(Result.mapError((cause) => SnapshotError.make({
|
|
79
86
|
reason: "NoncanonicalPath",
|
|
80
87
|
relativePath: key,
|
|
81
88
|
pathSegments: [],
|
|
@@ -86,13 +93,13 @@ const fromEntries = (entries) => Result.gen(function* () {
|
|
|
86
93
|
try: () => {
|
|
87
94
|
for (const segment of path.pathSegments) Identifier.validateConfectFunctionIdentifier(segment);
|
|
88
95
|
},
|
|
89
|
-
catch: () =>
|
|
96
|
+
catch: () => SnapshotError.make({
|
|
90
97
|
reason: "NoncanonicalPath",
|
|
91
98
|
relativePath,
|
|
92
99
|
pathSegments: path.pathSegments
|
|
93
100
|
})
|
|
94
101
|
});
|
|
95
|
-
if (HashMap.has(leaves, relativePath)) return yield* Result.fail(
|
|
102
|
+
if (HashMap.has(leaves, relativePath)) return yield* Result.fail(SnapshotError.make({
|
|
96
103
|
reason: "DuplicateLeaf",
|
|
97
104
|
relativePath,
|
|
98
105
|
pathSegments: path.pathSegments
|
|
@@ -102,7 +109,7 @@ const fromEntries = (entries) => Result.gen(function* () {
|
|
|
102
109
|
}
|
|
103
110
|
return yield* Snapshot.parseLeaves(leaves);
|
|
104
111
|
});
|
|
105
|
-
const parse = (input) => Schema.decodeUnknownResult(Entries)(input).pipe(Result.mapError((cause) =>
|
|
112
|
+
const parse = (input) => Schema.decodeUnknownResult(Entries)(input).pipe(Result.mapError((cause) => SnapshotError.make({
|
|
106
113
|
reason: "InvalidShape",
|
|
107
114
|
relativePath: "",
|
|
108
115
|
pathSegments: [],
|
|
@@ -117,6 +124,7 @@ const GenerationSnapshot = Entries.pipe(Schema.decodeTo(Schema.declare((input) =
|
|
|
117
124
|
}));
|
|
118
125
|
const summarize = (group) => ({
|
|
119
126
|
runtime: group.runtime,
|
|
127
|
+
...group.experimental_reuseContext ? { experimental_reuseContext: true } : {},
|
|
120
128
|
functionNames: Record.keys(group.functions),
|
|
121
129
|
groups: Record.map(group.groups, summarize)
|
|
122
130
|
});
|
|
@@ -125,16 +133,17 @@ const update = (snapshot, leaves) => Result.gen(function* () {
|
|
|
125
133
|
const replacement = yield* fromLoadedLeaves(leaves);
|
|
126
134
|
return yield* Snapshot.parseLeaves(HashMap.union(snapshot.leaves, replacement.leaves));
|
|
127
135
|
});
|
|
128
|
-
const fromLoadedLeaves = (leaves) => parse(
|
|
136
|
+
const fromLoadedLeaves = (leaves) => parse(Array.map(leaves, (leaf) => [String.replaceAll("\\", "/")(leaf.relativePath), summarize(leaf.spec)]));
|
|
129
137
|
const groups = (snapshot) => {
|
|
130
138
|
const visit = (path, tree) => [{
|
|
131
139
|
path,
|
|
132
140
|
runtime: tree.runtime,
|
|
141
|
+
...tree.experimental_reuseContext === true ? { experimental_reuseContext: true } : {},
|
|
133
142
|
functionNames: Array.sort(tree.functionNames, String.Order)
|
|
134
|
-
}, ...Array.flatMap(Array.sort(
|
|
143
|
+
}, ...Array.flatMap(Array.sort(Record.keys(tree.groups), String.Order), (name) => visit(append(path, name), tree.groups[name]))];
|
|
135
144
|
return Array.flatMap(Array.fromIterable(snapshot.leaves), ([path, tree]) => visit(rootPath(path), tree));
|
|
136
145
|
};
|
|
137
|
-
const functionPaths = (snapshot) => FunctionPaths.make(HashSet.fromIterable(Array.flatMap(groups(snapshot), (group) => group.functionNames
|
|
146
|
+
const functionPaths = (snapshot) => FunctionPaths.make(HashSet.fromIterable(Array.flatMap(groups(snapshot), (group) => Array.map(group.functionNames, (name) => FunctionPath.make({
|
|
138
147
|
groupPath: group.path,
|
|
139
148
|
name
|
|
140
149
|
})))));
|
|
@@ -142,8 +151,8 @@ const generatedGroups = (snapshot) => HashMap.fromIterable(Array.filterMap(group
|
|
|
142
151
|
const plan = (snapshot, existing) => {
|
|
143
152
|
const current = generatedGroups(snapshot);
|
|
144
153
|
return {
|
|
145
|
-
removed: Array.fromIterable(existing)
|
|
146
|
-
changed:
|
|
154
|
+
removed: Array.filter(Array.fromIterable(existing), (path) => !HashMap.has(current, path)),
|
|
155
|
+
changed: current.pipe(HashMap.values, Array.fromIterable)
|
|
147
156
|
};
|
|
148
157
|
};
|
|
149
158
|
const equivalentGroup = Schema.toEquivalence(GroupSummary);
|
|
@@ -162,12 +171,12 @@ const parseNoParentChildNameCollisions = (leaves) => {
|
|
|
162
171
|
for (const childPath of HashMap.keys(leaves)) {
|
|
163
172
|
const segments = rootPath(childPath).pathSegments;
|
|
164
173
|
for (let depth = 1; depth < segments.length; depth++) {
|
|
165
|
-
const parentPath = SpecModulePath.make(`${segments.slice(0, depth)
|
|
174
|
+
const parentPath = SpecModulePath.make(`${Array.join(segments.slice(0, depth), "/")}.spec.ts`);
|
|
166
175
|
const parent = HashMap.get(leaves, parentPath);
|
|
167
176
|
if (Option.isNone(parent)) continue;
|
|
168
177
|
const collisionName = segments[depth];
|
|
169
|
-
const collisionKind = parent.value.functionNames.includes(collisionName) ? "function" :
|
|
170
|
-
if (collisionKind !== void 0) return Result.fail(
|
|
178
|
+
const collisionKind = parent.value.functionNames.includes(collisionName) ? "function" : Record.has(parent.value.groups, collisionName) ? "group" : void 0;
|
|
179
|
+
if (collisionKind !== void 0) return Result.fail(ParentChildNameCollisionError.make({
|
|
171
180
|
parentSpecPath: parentPath,
|
|
172
181
|
childSpecPath: childPath,
|
|
173
182
|
collisionName,
|
|
@@ -177,7 +186,6 @@ const parseNoParentChildNameCollisions = (leaves) => {
|
|
|
177
186
|
}
|
|
178
187
|
return Result.succeed(leaves);
|
|
179
188
|
};
|
|
180
|
-
//#endregion
|
|
181
189
|
export { GenerationSnapshot, GroupSummary, GroupTree, diff, fromLoadedLeaves, functionPaths, parse, plan, update };
|
|
182
190
|
|
|
183
191
|
//# sourceMappingURL=GenerationSnapshot.mjs.map
|