@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/dist/confect/codegen.mjs
CHANGED
|
@@ -1,40 +1,60 @@
|
|
|
1
1
|
import { logFileAdded, logFileModified, logFileRemoved, logPending, logSuccess } from "../log.mjs";
|
|
2
|
+
import { fromBundlerError } from "../BuildError.mjs";
|
|
3
|
+
import { MissingImplFileError, MissingSchemaFileError, MissingSpecFileError, ParentChildNameCollisionError, SchemaInvalidDefaultExportError, tapAndLog } from "../CodegenError.mjs";
|
|
2
4
|
import { ConvexDirectory } from "../ConvexDirectory.mjs";
|
|
3
5
|
import { ConfectDirectory } from "../ConfectDirectory.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { FunctionPaths, make } from "../FunctionPaths.mjs";
|
|
7
|
+
import { bundle } from "../Bundler.mjs";
|
|
8
|
+
import { assemblyNodesFromLeaves, partitionByRuntime } from "../SpecAssemblyNode.mjs";
|
|
9
|
+
import { api, assembledSpec, nodeApi, refs, registeredFunctionsForGroup, schema, services } from "../templates.mjs";
|
|
10
|
+
import { WriteTracker, generateAuthConfig, generateCrons, generateFunctions, generateHttp, removePathExtension, removePathIfExists, toModuleImportPath, touchConvexSchema, writeFileStringAndLog } from "../utils.mjs";
|
|
11
|
+
import { discoverLeafImplFiles, discoverLeafSpecFiles, implPathForSpec, registeredFunctionsRelativePath, specPathForImpl, toLeafModule, toNodeRegistryLeaf, validateImpl, validateSpec } from "../LeafModule.mjs";
|
|
12
|
+
import { Array, Effect, Either, HashSet, Match, Option, Ref } from "effect";
|
|
7
13
|
import { Command } from "@effect/cli";
|
|
8
|
-
import {
|
|
14
|
+
import { Spec } from "@confect/core";
|
|
15
|
+
import * as DatabaseSchema from "@confect/server/DatabaseSchema";
|
|
9
16
|
import { FileSystem, Path } from "@effect/platform";
|
|
10
17
|
|
|
11
18
|
//#region src/confect/codegen.ts
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const GENERATED_SPEC_PATH = "_generated/spec.ts";
|
|
20
|
+
const GENERATED_NODE_SPEC_PATH = "_generated/nodeSpec.ts";
|
|
21
|
+
const LEGACY_PATHS = [
|
|
22
|
+
"spec.ts",
|
|
23
|
+
"nodeSpec.ts",
|
|
24
|
+
"impl.ts",
|
|
25
|
+
"nodeImpl.ts",
|
|
26
|
+
"notesAndRandom.impl.ts",
|
|
27
|
+
"groups.impl.ts",
|
|
28
|
+
"_generated/registeredFunctions.ts",
|
|
29
|
+
"_generated/nodeRegisteredFunctions.ts",
|
|
30
|
+
"_generated/impl.ts",
|
|
31
|
+
"_generated/nodeImpl.ts"
|
|
32
|
+
];
|
|
25
33
|
const codegen = Command.make("codegen", {}, () => Effect.gen(function* () {
|
|
26
34
|
yield* logPending("Performing initial sync…");
|
|
27
|
-
yield* codegenHandler;
|
|
28
|
-
|
|
29
|
-
})).pipe(Command.withDescription("Generate `confect/_generated` files and the contents of the `convex` directory (except `tsconfig.json`)"));
|
|
35
|
+
yield* codegenHandler.pipe(Effect.asVoid, Effect.tap(() => logSuccess("Generated files are up-to-date")), tapAndLog);
|
|
36
|
+
})).pipe(Command.withDescription("Generate `confect/_generated` files and the contents of the `convex` directory (except `convex.config.ts` and `tsconfig.json`)"));
|
|
30
37
|
const codegenHandler = Effect.gen(function* () {
|
|
38
|
+
const tracker = yield* Ref.make(false);
|
|
39
|
+
return {
|
|
40
|
+
functionPaths: yield* runCodegen.pipe(Effect.provideService(WriteTracker, tracker)),
|
|
41
|
+
anyWritesHappened: yield* Ref.get(tracker)
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
const runCodegen = Effect.gen(function* () {
|
|
31
45
|
yield* generateConfectGeneratedDirectory;
|
|
46
|
+
yield* validateSchema;
|
|
47
|
+
const { leaves, groupSpecsByRelativePath } = yield* loadAndValidateLeafModules;
|
|
48
|
+
yield* removeLegacyFiles;
|
|
49
|
+
yield* validateNoParentChildNameCollisions(leaves, groupSpecsByRelativePath);
|
|
50
|
+
yield* generateAssembledSpecs(leaves);
|
|
51
|
+
yield* validateImplModules(leaves);
|
|
52
|
+
yield* generateGroupRegisteredFunctions(leaves);
|
|
53
|
+
yield* removeObsoleteRegisteredFunctions(leaves);
|
|
32
54
|
yield* Effect.all([
|
|
33
55
|
generateApi,
|
|
34
56
|
generateRefs,
|
|
35
|
-
generateRegisteredFunctions,
|
|
36
57
|
generateNodeApi,
|
|
37
|
-
generateNodeRegisteredFunctions,
|
|
38
58
|
generateServices
|
|
39
59
|
], { concurrency: "unbounded" });
|
|
40
60
|
const [functionPaths] = yield* Effect.all([
|
|
@@ -44,6 +64,7 @@ const codegenHandler = Effect.gen(function* () {
|
|
|
44
64
|
logGenerated(generateCrons),
|
|
45
65
|
logGenerated(generateAuthConfig)
|
|
46
66
|
], { concurrency: "unbounded" });
|
|
67
|
+
yield* touchConvexSchema;
|
|
47
68
|
return functionPaths;
|
|
48
69
|
});
|
|
49
70
|
const generateConfectGeneratedDirectory = Effect.gen(function* () {
|
|
@@ -55,13 +76,238 @@ const generateConfectGeneratedDirectory = Effect.gen(function* () {
|
|
|
55
76
|
yield* logFileAdded(path.join(confectDirectory, "_generated") + "/");
|
|
56
77
|
}
|
|
57
78
|
});
|
|
79
|
+
const loadAndValidateLeafModules = Effect.gen(function* () {
|
|
80
|
+
const fs = yield* FileSystem.FileSystem;
|
|
81
|
+
const path = yield* Path.Path;
|
|
82
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
83
|
+
const specFiles = yield* discoverLeafSpecFiles;
|
|
84
|
+
const results = yield* Effect.forEach(specFiles, (specRelativePath) => Effect.gen(function* () {
|
|
85
|
+
const leaf = yield* toLeafModule(specRelativePath);
|
|
86
|
+
const groupSpec = yield* validateSpec(leaf);
|
|
87
|
+
const implRelativePath = yield* implPathForSpec(specRelativePath);
|
|
88
|
+
const implAbsolutePath = path.join(confectDirectory, implRelativePath);
|
|
89
|
+
if (!(yield* fs.exists(implAbsolutePath))) return yield* new MissingImplFileError({
|
|
90
|
+
specPath: specRelativePath,
|
|
91
|
+
expectedImplPath: implRelativePath
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
leaf,
|
|
95
|
+
groupSpec
|
|
96
|
+
};
|
|
97
|
+
}));
|
|
98
|
+
yield* validateOrphanImpls(specFiles);
|
|
99
|
+
return {
|
|
100
|
+
leaves: Array.map(results, ({ leaf }) => leaf),
|
|
101
|
+
groupSpecsByRelativePath: new Map(Array.map(results, ({ leaf, groupSpec }) => [leaf.relativePath, groupSpec]))
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* Walk the assembly tree and fail with a {@link ParentChildNameCollisionError}
|
|
106
|
+
* when a parent leaf declares a function or subgroup whose name matches a
|
|
107
|
+
* sibling subdirectory spec's segment. Without this check the colliding
|
|
108
|
+
* descendant would overwrite the parent's entry in the assembled
|
|
109
|
+
* `GroupSpec.groups` map at runtime, surfacing as a confusing
|
|
110
|
+
* `Refs.make` error rather than a codegen-time diagnostic.
|
|
111
|
+
*/
|
|
112
|
+
const validateNoParentChildNameCollisions = (leaves, groupSpecsByRelativePath) => Effect.gen(function* () {
|
|
113
|
+
const { convex, node } = partitionByRuntime(leaves);
|
|
114
|
+
const convexNodes = assemblyNodesFromLeaves(convex);
|
|
115
|
+
const nodeNodes = assemblyNodesFromLeaves(Array.map(node, toNodeRegistryLeaf));
|
|
116
|
+
yield* Effect.forEach(convexNodes, (n) => checkAssemblyNodeForCollisions(n, groupSpecsByRelativePath));
|
|
117
|
+
yield* Effect.forEach(nodeNodes, (n) => checkAssemblyNodeForCollisions(n, groupSpecsByRelativePath));
|
|
118
|
+
});
|
|
119
|
+
const checkAssemblyNodeForCollisions = (node, groupSpecsByRelativePath) => Effect.gen(function* () {
|
|
120
|
+
yield* Option.match(node.importBinding, {
|
|
121
|
+
onNone: () => Effect.void,
|
|
122
|
+
onSome: (binding) => Effect.gen(function* () {
|
|
123
|
+
if (node.children.length === 0) return;
|
|
124
|
+
const parentRelativePath = bindingToRelativeSpecPath(binding.importPath);
|
|
125
|
+
const parentGroupSpec = groupSpecsByRelativePath.get(parentRelativePath);
|
|
126
|
+
if (parentGroupSpec === void 0) return;
|
|
127
|
+
yield* Effect.forEach(node.children, (child) => {
|
|
128
|
+
if (Object.prototype.hasOwnProperty.call(parentGroupSpec.functions, child.segment)) return Effect.fail(new ParentChildNameCollisionError({
|
|
129
|
+
parentSpecPath: parentRelativePath,
|
|
130
|
+
childSpecPath: childRepresentativeSpecPath(child),
|
|
131
|
+
collisionName: child.segment,
|
|
132
|
+
collisionKind: "function"
|
|
133
|
+
}));
|
|
134
|
+
if (Object.prototype.hasOwnProperty.call(parentGroupSpec.groups, child.segment)) return Effect.fail(new ParentChildNameCollisionError({
|
|
135
|
+
parentSpecPath: parentRelativePath,
|
|
136
|
+
childSpecPath: childRepresentativeSpecPath(child),
|
|
137
|
+
collisionName: child.segment,
|
|
138
|
+
collisionKind: "group"
|
|
139
|
+
}));
|
|
140
|
+
return Effect.void;
|
|
141
|
+
});
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
yield* Effect.forEach(node.children, (child) => checkAssemblyNodeForCollisions(child, groupSpecsByRelativePath));
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* `LeafModule.specImportPath` is the import path used from inside the
|
|
148
|
+
* generated `_generated/spec.ts` (e.g. `"../notes.spec"`). Strip the
|
|
149
|
+
* `../` prefix and re-add the `.ts` extension to recover the leaf's
|
|
150
|
+
* confect-relative spec path used as the key in
|
|
151
|
+
* `groupSpecsByRelativePath`.
|
|
152
|
+
*/
|
|
153
|
+
const bindingToRelativeSpecPath = (importPath) => {
|
|
154
|
+
return `${importPath.startsWith("../") ? importPath.slice(3) : importPath}.ts`;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* A child assembly node may itself be a parent without a leaf (when the
|
|
158
|
+
* actual leaves live only in deeper subdirectories). In that case we
|
|
159
|
+
* surface the first descendant leaf as a representative path so the
|
|
160
|
+
* error message points at something the user actually wrote.
|
|
161
|
+
*/
|
|
162
|
+
const childRepresentativeSpecPath = (node) => {
|
|
163
|
+
if (Option.isSome(node.importBinding)) return bindingToRelativeSpecPath(node.importBinding.value.importPath);
|
|
164
|
+
for (const child of node.children) return childRepresentativeSpecPath(child);
|
|
165
|
+
return node.segment;
|
|
166
|
+
};
|
|
167
|
+
const validateOrphanImpls = (specFiles) => Effect.gen(function* () {
|
|
168
|
+
const fs = yield* FileSystem.FileSystem;
|
|
169
|
+
const path = yield* Path.Path;
|
|
170
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
171
|
+
const implFiles = yield* discoverLeafImplFiles;
|
|
172
|
+
const specPaths = new Set(specFiles);
|
|
173
|
+
yield* Effect.forEach(implFiles, (implRelativePath) => Effect.gen(function* () {
|
|
174
|
+
const specRelativePath = yield* specPathForImpl(implRelativePath);
|
|
175
|
+
if (specPaths.has(specRelativePath)) return;
|
|
176
|
+
const specAbsolutePath = path.join(confectDirectory, specRelativePath);
|
|
177
|
+
if (!(yield* fs.exists(specAbsolutePath))) return yield* new MissingSpecFileError({
|
|
178
|
+
implPath: implRelativePath,
|
|
179
|
+
expectedSpecPath: specRelativePath
|
|
180
|
+
});
|
|
181
|
+
}));
|
|
182
|
+
});
|
|
183
|
+
const removeLegacyFiles = Effect.gen(function* () {
|
|
184
|
+
const fs = yield* FileSystem.FileSystem;
|
|
185
|
+
const path = yield* Path.Path;
|
|
186
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
187
|
+
yield* Effect.forEach(LEGACY_PATHS, (relativePath) => Effect.gen(function* () {
|
|
188
|
+
const absolutePath = path.join(confectDirectory, relativePath);
|
|
189
|
+
if (yield* fs.exists(absolutePath)) {
|
|
190
|
+
yield* removePathIfExists(absolutePath);
|
|
191
|
+
yield* logFileRemoved(absolutePath);
|
|
192
|
+
}
|
|
193
|
+
}));
|
|
194
|
+
});
|
|
195
|
+
const generateAssembledSpecs = (leaves) => Effect.gen(function* () {
|
|
196
|
+
const path = yield* Path.Path;
|
|
197
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
198
|
+
const { convex, node } = partitionByRuntime(leaves);
|
|
199
|
+
if (convex.length > 0) {
|
|
200
|
+
const nodes = assemblyNodesFromLeaves(convex);
|
|
201
|
+
const specContents = yield* assembledSpec({
|
|
202
|
+
nodes,
|
|
203
|
+
runtime: "Convex"
|
|
204
|
+
});
|
|
205
|
+
yield* writeFileStringAndLog(path.join(confectDirectory, GENERATED_SPEC_PATH), specContents);
|
|
206
|
+
}
|
|
207
|
+
if (node.length > 0) {
|
|
208
|
+
const nodes = assemblyNodesFromLeaves(Array.map(node, toNodeRegistryLeaf));
|
|
209
|
+
const nodeSpecContents = yield* assembledSpec({
|
|
210
|
+
nodes,
|
|
211
|
+
runtime: "Node"
|
|
212
|
+
});
|
|
213
|
+
yield* writeFileStringAndLog(path.join(confectDirectory, GENERATED_NODE_SPEC_PATH), nodeSpecContents);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
const validateImplModules = (leaves) => Effect.forEach(leaves, validateImpl);
|
|
217
|
+
const generateGroupRegisteredFunctions = (leaves) => Effect.gen(function* () {
|
|
218
|
+
const path = yield* Path.Path;
|
|
219
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
220
|
+
yield* Effect.forEach(leaves, (leaf) => Effect.gen(function* () {
|
|
221
|
+
const registryRelativePath = yield* registeredFunctionsRelativePath(leaf);
|
|
222
|
+
const registryPath = path.join(confectDirectory, "_generated", registryRelativePath);
|
|
223
|
+
const registryDir = path.dirname(registryPath);
|
|
224
|
+
const fs = yield* FileSystem.FileSystem;
|
|
225
|
+
if (!(yield* fs.exists(registryDir))) yield* fs.makeDirectory(registryDir, { recursive: true });
|
|
226
|
+
const implRelativePath = yield* implPathForSpec(leaf.relativePath);
|
|
227
|
+
const apiFileName = leaf.runtime === "Node" ? "nodeApi.ts" : "api.ts";
|
|
228
|
+
const apiImportPath = yield* toModuleImportPath(path.relative(path.dirname(registryPath), path.join(confectDirectory, "_generated", apiFileName)));
|
|
229
|
+
const implImportPath = yield* toModuleImportPath(path.relative(path.dirname(registryPath), path.join(confectDirectory, implRelativePath)));
|
|
230
|
+
yield* writeFileStringAndLog(registryPath, yield* registeredFunctionsForGroup({
|
|
231
|
+
apiImportPath,
|
|
232
|
+
groupPathDot: leaf.registryGroupPathDot,
|
|
233
|
+
implImportPath,
|
|
234
|
+
layerExportName: leaf.exportName,
|
|
235
|
+
useNode: leaf.runtime === "Node"
|
|
236
|
+
}));
|
|
237
|
+
}));
|
|
238
|
+
});
|
|
239
|
+
const removeObsoleteRegisteredFunctions = (leaves) => Effect.gen(function* () {
|
|
240
|
+
const fs = yield* FileSystem.FileSystem;
|
|
241
|
+
const path = yield* Path.Path;
|
|
242
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
243
|
+
const registryRoot = path.join(confectDirectory, "_generated", "registeredFunctions");
|
|
244
|
+
if (!(yield* fs.exists(registryRoot))) return;
|
|
245
|
+
const expected = new Set(yield* Effect.forEach(leaves, (leaf) => registeredFunctionsRelativePath(leaf)));
|
|
246
|
+
const existing = yield* fs.readDirectory(registryRoot, { recursive: true });
|
|
247
|
+
yield* Effect.forEach(existing, (relativePath) => {
|
|
248
|
+
if (path.extname(relativePath) !== ".ts") return Effect.void;
|
|
249
|
+
const normalized = path.join("registeredFunctions", relativePath);
|
|
250
|
+
if (!expected.has(normalized)) return Effect.gen(function* () {
|
|
251
|
+
const absolutePath = path.join(registryRoot, relativePath);
|
|
252
|
+
if (yield* fs.exists(absolutePath)) {
|
|
253
|
+
yield* removePathIfExists(absolutePath);
|
|
254
|
+
yield* logFileRemoved(absolutePath);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return Effect.void;
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
const getGeneratedSpecPath = Effect.gen(function* () {
|
|
261
|
+
const path = yield* Path.Path;
|
|
262
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
263
|
+
return path.join(confectDirectory, GENERATED_SPEC_PATH);
|
|
264
|
+
});
|
|
265
|
+
const getGeneratedNodeSpecPath = Effect.gen(function* () {
|
|
266
|
+
const path = yield* Path.Path;
|
|
267
|
+
const confectDirectory = yield* ConfectDirectory.get;
|
|
268
|
+
return path.join(confectDirectory, GENERATED_NODE_SPEC_PATH);
|
|
269
|
+
});
|
|
270
|
+
const loadGeneratedSpec = Effect.gen(function* () {
|
|
271
|
+
const specPath = yield* getGeneratedSpecPath;
|
|
272
|
+
const { module: specModule } = yield* bundle(specPath);
|
|
273
|
+
const spec = specModule.default;
|
|
274
|
+
if (!Spec.isConvexSpec(spec)) return yield* Effect.dieMessage("_generated/spec.ts does not export a valid Convex Spec");
|
|
275
|
+
return spec;
|
|
276
|
+
});
|
|
277
|
+
const loadGeneratedNodeSpec = Effect.gen(function* () {
|
|
278
|
+
const fs = yield* FileSystem.FileSystem;
|
|
279
|
+
const nodeSpecPath = yield* getGeneratedNodeSpecPath;
|
|
280
|
+
if (!(yield* fs.exists(nodeSpecPath))) return Option.none();
|
|
281
|
+
const { module: nodeSpecModule } = yield* bundle(nodeSpecPath);
|
|
282
|
+
const nodeSpec = nodeSpecModule.default;
|
|
283
|
+
if (!Spec.isNodeSpec(nodeSpec)) return yield* Effect.dieMessage("_generated/nodeSpec.ts does not export a valid Node Spec");
|
|
284
|
+
return Option.some(nodeSpec);
|
|
285
|
+
});
|
|
286
|
+
const emptyFunctionPaths = FunctionPaths.make(HashSet.empty());
|
|
287
|
+
const loadPreviousFunctionPaths = Effect.gen(function* () {
|
|
288
|
+
const fs = yield* FileSystem.FileSystem;
|
|
289
|
+
const specPath = yield* getGeneratedSpecPath;
|
|
290
|
+
if (!(yield* fs.exists(specPath))) return emptyFunctionPaths;
|
|
291
|
+
const specEither = yield* loadGeneratedSpec.pipe(Effect.either);
|
|
292
|
+
return yield* Either.match(specEither, {
|
|
293
|
+
onLeft: () => Effect.succeed(emptyFunctionPaths),
|
|
294
|
+
onRight: (spec) => Effect.gen(function* () {
|
|
295
|
+
const nodeSpecOption = yield* loadGeneratedNodeSpec;
|
|
296
|
+
const mergedSpec = Option.match(nodeSpecOption, {
|
|
297
|
+
onNone: () => spec,
|
|
298
|
+
onSome: (nodeSpec) => Spec.merge(spec, nodeSpec)
|
|
299
|
+
});
|
|
300
|
+
return make(mergedSpec);
|
|
301
|
+
})
|
|
302
|
+
});
|
|
303
|
+
});
|
|
58
304
|
const generateApi = Effect.gen(function* () {
|
|
59
305
|
const path = yield* Path.Path;
|
|
60
306
|
const confectDirectory = yield* ConfectDirectory.get;
|
|
61
307
|
const apiPath = path.join(confectDirectory, "_generated", "api.ts");
|
|
62
308
|
const apiDir = path.dirname(apiPath);
|
|
63
|
-
const schemaImportPath = yield*
|
|
64
|
-
const specImportPath = yield*
|
|
309
|
+
const schemaImportPath = yield* toModuleImportPath(path.relative(apiDir, path.join(confectDirectory, "schema.ts")));
|
|
310
|
+
const specImportPath = yield* toModuleImportPath(path.relative(apiDir, path.join(confectDirectory, GENERATED_SPEC_PATH)));
|
|
65
311
|
yield* writeFileStringAndLog(apiPath, yield* api({
|
|
66
312
|
schemaImportPath,
|
|
67
313
|
specImportPath
|
|
@@ -71,35 +317,40 @@ const generateNodeApi = Effect.gen(function* () {
|
|
|
71
317
|
const fs = yield* FileSystem.FileSystem;
|
|
72
318
|
const path = yield* Path.Path;
|
|
73
319
|
const confectDirectory = yield* ConfectDirectory.get;
|
|
74
|
-
const nodeSpecPath = yield*
|
|
320
|
+
const nodeSpecPath = yield* getGeneratedNodeSpecPath;
|
|
75
321
|
const nodeApiPath = path.join(confectDirectory, "_generated", "nodeApi.ts");
|
|
76
322
|
if (!(yield* fs.exists(nodeSpecPath))) {
|
|
77
323
|
if (yield* fs.exists(nodeApiPath)) {
|
|
78
|
-
yield*
|
|
324
|
+
yield* removePathIfExists(nodeApiPath);
|
|
79
325
|
yield* logFileRemoved(nodeApiPath);
|
|
80
326
|
}
|
|
81
327
|
return;
|
|
82
328
|
}
|
|
83
329
|
const nodeApiDir = path.dirname(nodeApiPath);
|
|
84
|
-
const schemaImportPath = yield*
|
|
85
|
-
const nodeSpecImportPath = yield*
|
|
330
|
+
const schemaImportPath = yield* toModuleImportPath(path.relative(nodeApiDir, path.join(confectDirectory, "schema.ts")));
|
|
331
|
+
const nodeSpecImportPath = yield* toModuleImportPath(path.relative(nodeApiDir, nodeSpecPath));
|
|
86
332
|
yield* writeFileStringAndLog(nodeApiPath, yield* nodeApi({
|
|
87
333
|
schemaImportPath,
|
|
88
334
|
nodeSpecImportPath
|
|
89
335
|
}));
|
|
90
336
|
});
|
|
91
337
|
const generateFunctionModules = Effect.gen(function* () {
|
|
338
|
+
const spec = yield* loadGeneratedSpec;
|
|
339
|
+
const nodeSpecOption = yield* loadGeneratedNodeSpec;
|
|
340
|
+
return yield* generateFunctions(Option.match(nodeSpecOption, {
|
|
341
|
+
onNone: () => spec,
|
|
342
|
+
onSome: (nodeSpec) => Spec.merge(spec, nodeSpec)
|
|
343
|
+
}));
|
|
344
|
+
});
|
|
345
|
+
const validateSchema = Effect.gen(function* () {
|
|
92
346
|
const fs = yield* FileSystem.FileSystem;
|
|
93
347
|
const path = yield* Path.Path;
|
|
94
348
|
const confectDirectory = yield* ConfectDirectory.get;
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return yield* generateFunctions(Option.match(nodeSpecOption, {
|
|
101
|
-
onNone: () => spec,
|
|
102
|
-
onSome: (nodeSpec) => nodeImplExists ? Spec.merge(spec, nodeSpec) : spec
|
|
349
|
+
const confectSchemaPath = path.join(confectDirectory, "schema.ts");
|
|
350
|
+
if (!(yield* fs.exists(confectSchemaPath))) return yield* new MissingSchemaFileError({ schemaPath: "schema.ts" });
|
|
351
|
+
yield* bundle(confectSchemaPath).pipe(Effect.mapError((error) => fromBundlerError("schema.ts", error)), Effect.andThen(({ module: schemaModule }) => {
|
|
352
|
+
const defaultExport = schemaModule.default;
|
|
353
|
+
return DatabaseSchema.isDatabaseSchema(defaultExport) ? Effect.succeed(defaultExport) : Effect.fail(new SchemaInvalidDefaultExportError({ schemaPath: "schema.ts" }));
|
|
103
354
|
}));
|
|
104
355
|
});
|
|
105
356
|
const generateSchema = Effect.gen(function* () {
|
|
@@ -107,10 +358,6 @@ const generateSchema = Effect.gen(function* () {
|
|
|
107
358
|
const confectDirectory = yield* ConfectDirectory.get;
|
|
108
359
|
const convexDirectory = yield* ConvexDirectory.get;
|
|
109
360
|
const confectSchemaPath = path.join(confectDirectory, "schema.ts");
|
|
110
|
-
yield* bundleAndImport(confectSchemaPath).pipe(Effect.andThen((schemaModule) => {
|
|
111
|
-
const defaultExport = schemaModule.default;
|
|
112
|
-
return DatabaseSchema.isDatabaseSchema(defaultExport) ? Effect.succeed(defaultExport) : Effect.die("Invalid schema module");
|
|
113
|
-
}));
|
|
114
361
|
const convexSchemaPath = path.join(convexDirectory, "schema.ts");
|
|
115
362
|
const importPathWithoutExt = yield* removePathExtension(path.relative(path.dirname(convexSchemaPath), confectSchemaPath));
|
|
116
363
|
yield* writeFileStringAndLog(convexSchemaPath, yield* schema({ schemaImportPath: importPathWithoutExt }));
|
|
@@ -123,33 +370,6 @@ const generateServices = Effect.gen(function* () {
|
|
|
123
370
|
const schemaImportPath = path.relative(path.dirname(servicesPath), path.join(confectDirectory, "schema"));
|
|
124
371
|
yield* writeFileStringAndLog(servicesPath, yield* services({ schemaImportPath }));
|
|
125
372
|
});
|
|
126
|
-
const generateRegisteredFunctions = Effect.gen(function* () {
|
|
127
|
-
const path = yield* Path.Path;
|
|
128
|
-
const confectDirectory = yield* ConfectDirectory.get;
|
|
129
|
-
const confectGeneratedDirectory = path.join(confectDirectory, "_generated");
|
|
130
|
-
const registeredFunctionsPath = path.join(confectGeneratedDirectory, "registeredFunctions.ts");
|
|
131
|
-
const implImportPath = yield* removePathExtension(path.relative(path.dirname(registeredFunctionsPath), path.join(confectDirectory, "impl.ts")));
|
|
132
|
-
yield* writeFileStringAndLog(registeredFunctionsPath, yield* registeredFunctions({ implImportPath }));
|
|
133
|
-
});
|
|
134
|
-
const generateNodeRegisteredFunctions = Effect.gen(function* () {
|
|
135
|
-
const fs = yield* FileSystem.FileSystem;
|
|
136
|
-
const path = yield* Path.Path;
|
|
137
|
-
const confectDirectory = yield* ConfectDirectory.get;
|
|
138
|
-
const nodeImplPath = path.join(confectDirectory, "nodeImpl.ts");
|
|
139
|
-
const nodeSpecPath = yield* getNodeSpecPath;
|
|
140
|
-
const nodeRegisteredFunctionsPath = path.join(confectDirectory, "_generated", "nodeRegisteredFunctions.ts");
|
|
141
|
-
const nodeImplExists = yield* fs.exists(nodeImplPath);
|
|
142
|
-
const nodeSpecExists = yield* fs.exists(nodeSpecPath);
|
|
143
|
-
if (!nodeImplExists || !nodeSpecExists) {
|
|
144
|
-
if (yield* fs.exists(nodeRegisteredFunctionsPath)) {
|
|
145
|
-
yield* fs.remove(nodeRegisteredFunctionsPath);
|
|
146
|
-
yield* logFileRemoved(nodeRegisteredFunctionsPath);
|
|
147
|
-
}
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const nodeImplImportPath = yield* removePathExtension(path.relative(path.dirname(nodeRegisteredFunctionsPath), nodeImplPath));
|
|
151
|
-
yield* writeFileStringAndLog(nodeRegisteredFunctionsPath, yield* nodeRegisteredFunctions({ nodeImplImportPath }));
|
|
152
|
-
});
|
|
153
373
|
const generateRefs = Effect.gen(function* () {
|
|
154
374
|
const fs = yield* FileSystem.FileSystem;
|
|
155
375
|
const path = yield* Path.Path;
|
|
@@ -157,12 +377,12 @@ const generateRefs = Effect.gen(function* () {
|
|
|
157
377
|
const confectGeneratedDirectory = path.join(confectDirectory, "_generated");
|
|
158
378
|
const refsPath = path.join(confectGeneratedDirectory, "refs.ts");
|
|
159
379
|
const refsDir = path.dirname(refsPath);
|
|
160
|
-
const specImportPath = yield*
|
|
161
|
-
const nodeSpecPath = yield*
|
|
162
|
-
const nodeSpecImportPath = (yield* fs.exists(nodeSpecPath)) ? yield*
|
|
380
|
+
const specImportPath = yield* toModuleImportPath(path.relative(refsDir, path.join(confectDirectory, GENERATED_SPEC_PATH)));
|
|
381
|
+
const nodeSpecPath = yield* getGeneratedNodeSpecPath;
|
|
382
|
+
const nodeSpecImportPath = (yield* fs.exists(nodeSpecPath)) ? Option.some(yield* toModuleImportPath(path.relative(refsDir, nodeSpecPath))) : Option.none();
|
|
163
383
|
yield* writeFileStringAndLog(refsPath, yield* refs({
|
|
164
384
|
specImportPath,
|
|
165
|
-
|
|
385
|
+
nodeSpecImportPath
|
|
166
386
|
}));
|
|
167
387
|
});
|
|
168
388
|
const logGenerated = (effect) => effect.pipe(Effect.tap(Option.match({
|
|
@@ -171,5 +391,5 @@ const logGenerated = (effect) => effect.pipe(Effect.tap(Option.match({
|
|
|
171
391
|
})));
|
|
172
392
|
|
|
173
393
|
//#endregion
|
|
174
|
-
export { codegen, codegenHandler,
|
|
394
|
+
export { codegen, codegenHandler, loadPreviousFunctionPaths };
|
|
175
395
|
//# sourceMappingURL=codegen.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.mjs","names":["templates.api","templates.nodeApi","templates.schema","templates.services","templates.registeredFunctions","templates.nodeRegisteredFunctions","templates.refs"],"sources":["../../src/confect/codegen.ts"],"sourcesContent":["import { DatabaseSchema, Spec } from \"@confect/core\";\nimport { Command } from \"@effect/cli\";\nimport { FileSystem, Path } from \"@effect/platform\";\nimport { Effect, Match, Option } from \"effect\";\nimport {\n logFileAdded,\n logFileModified,\n logFileRemoved,\n logPending,\n logSuccess,\n} from \"../log\";\nimport { ConfectDirectory } from \"../ConfectDirectory\";\nimport { ConvexDirectory } from \"../ConvexDirectory\";\nimport * as templates from \"../templates\";\nimport {\n bundleAndImport,\n generateAuthConfig,\n generateCrons,\n generateFunctions,\n generateHttp,\n removePathExtension,\n writeFileStringAndLog,\n} from \"../utils\";\n\nconst getNodeSpecPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n return path.join(confectDirectory, \"nodeSpec.ts\");\n});\n\nconst loadNodeSpec = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const nodeSpecPath = yield* getNodeSpecPath;\n\n if (!(yield* fs.exists(nodeSpecPath))) {\n return Option.none<Spec.AnyWithPropsWithRuntime<\"Node\">>();\n }\n\n const nodeSpecModule = yield* bundleAndImport(nodeSpecPath);\n const nodeSpec = nodeSpecModule.default;\n\n if (!Spec.isNodeSpec(nodeSpec)) {\n return yield* Effect.die(\"nodeSpec.ts does not export a valid Node Spec\");\n }\n\n return Option.some(nodeSpec);\n});\n\nexport const codegen = Command.make(\"codegen\", {}, () =>\n Effect.gen(function* () {\n yield* logPending(\"Performing initial sync…\");\n yield* codegenHandler;\n yield* logSuccess(\"Generated files are up-to-date\");\n }),\n).pipe(\n Command.withDescription(\n \"Generate `confect/_generated` files and the contents of the `convex` directory (except `tsconfig.json`)\",\n ),\n);\n\nexport const codegenHandler = Effect.gen(function* () {\n yield* generateConfectGeneratedDirectory;\n yield* Effect.all(\n [\n generateApi,\n generateRefs,\n generateRegisteredFunctions,\n generateNodeApi,\n generateNodeRegisteredFunctions,\n generateServices,\n ],\n { concurrency: \"unbounded\" },\n );\n const [functionPaths] = yield* Effect.all(\n [\n generateFunctionModules,\n generateSchema,\n logGenerated(generateHttp),\n logGenerated(generateCrons),\n logGenerated(generateAuthConfig),\n ],\n { concurrency: \"unbounded\" },\n );\n return functionPaths;\n});\n\nconst generateConfectGeneratedDirectory = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n if (!(yield* fs.exists(path.join(confectDirectory, \"_generated\")))) {\n yield* fs.makeDirectory(path.join(confectDirectory, \"_generated\"), {\n recursive: true,\n });\n yield* logFileAdded(path.join(confectDirectory, \"_generated\") + \"/\");\n }\n});\n\nconst generateApi = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const apiPath = path.join(confectDirectory, \"_generated\", \"api.ts\");\n const apiDir = path.dirname(apiPath);\n\n const schemaImportPath = yield* removePathExtension(\n path.relative(apiDir, path.join(confectDirectory, \"schema.ts\")),\n );\n\n const specImportPath = yield* removePathExtension(\n path.relative(apiDir, path.join(confectDirectory, \"spec.ts\")),\n );\n\n const apiContents = yield* templates.api({\n schemaImportPath,\n specImportPath,\n });\n\n yield* writeFileStringAndLog(apiPath, apiContents);\n});\n\nexport const generateNodeApi = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const nodeSpecPath = yield* getNodeSpecPath;\n const nodeApiPath = path.join(confectDirectory, \"_generated\", \"nodeApi.ts\");\n\n if (!(yield* fs.exists(nodeSpecPath))) {\n if (yield* fs.exists(nodeApiPath)) {\n yield* fs.remove(nodeApiPath);\n yield* logFileRemoved(nodeApiPath);\n }\n return;\n }\n\n const nodeApiDir = path.dirname(nodeApiPath);\n\n const schemaImportPath = yield* removePathExtension(\n path.relative(nodeApiDir, path.join(confectDirectory, \"schema.ts\")),\n );\n\n const nodeSpecImportPath = yield* removePathExtension(\n path.relative(nodeApiDir, nodeSpecPath),\n );\n\n const nodeApiContents = yield* templates.nodeApi({\n schemaImportPath,\n nodeSpecImportPath,\n });\n\n yield* writeFileStringAndLog(nodeApiPath, nodeApiContents);\n});\n\nconst generateFunctionModules = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const specPath = path.join(confectDirectory, \"spec.ts\");\n\n const specModule = yield* bundleAndImport(specPath);\n const spec = specModule.default;\n\n if (!Spec.isConvexSpec(spec)) {\n return yield* Effect.die(\"spec.ts does not export a valid Convex Spec\");\n }\n\n const nodeImplPath = path.join(confectDirectory, \"nodeImpl.ts\");\n const nodeImplExists = yield* fs.exists(nodeImplPath);\n const nodeSpecOption = yield* loadNodeSpec;\n\n const mergedSpec = Option.match(nodeSpecOption, {\n onNone: () => spec,\n onSome: (nodeSpec) => (nodeImplExists ? Spec.merge(spec, nodeSpec) : spec),\n });\n\n return yield* generateFunctions(mergedSpec);\n});\n\nconst generateSchema = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const confectSchemaPath = path.join(confectDirectory, \"schema.ts\");\n\n yield* bundleAndImport(confectSchemaPath).pipe(\n Effect.andThen((schemaModule) => {\n const defaultExport = schemaModule.default;\n\n return DatabaseSchema.isDatabaseSchema(defaultExport)\n ? Effect.succeed(defaultExport)\n : Effect.die(\"Invalid schema module\");\n }),\n );\n\n const convexSchemaPath = path.join(convexDirectory, \"schema.ts\");\n\n const relativeImportPath = path.relative(\n path.dirname(convexSchemaPath),\n confectSchemaPath,\n );\n const importPathWithoutExt = yield* removePathExtension(relativeImportPath);\n const schemaContents = yield* templates.schema({\n schemaImportPath: importPathWithoutExt,\n });\n\n yield* writeFileStringAndLog(convexSchemaPath, schemaContents);\n});\n\nconst generateServices = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const confectGeneratedDirectory = path.join(confectDirectory, \"_generated\");\n\n const servicesPath = path.join(confectGeneratedDirectory, \"services.ts\");\n const schemaImportPath = path.relative(\n path.dirname(servicesPath),\n path.join(confectDirectory, \"schema\"),\n );\n\n const servicesContentsString = yield* templates.services({\n schemaImportPath,\n });\n\n yield* writeFileStringAndLog(servicesPath, servicesContentsString);\n});\n\nconst generateRegisteredFunctions = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const confectGeneratedDirectory = path.join(confectDirectory, \"_generated\");\n\n const registeredFunctionsPath = path.join(\n confectGeneratedDirectory,\n \"registeredFunctions.ts\",\n );\n const implImportPath = yield* removePathExtension(\n path.relative(\n path.dirname(registeredFunctionsPath),\n path.join(confectDirectory, \"impl.ts\"),\n ),\n );\n\n const registeredFunctionsContents = yield* templates.registeredFunctions({\n implImportPath,\n });\n\n yield* writeFileStringAndLog(\n registeredFunctionsPath,\n registeredFunctionsContents,\n );\n});\n\nexport const generateNodeRegisteredFunctions = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const nodeImplPath = path.join(confectDirectory, \"nodeImpl.ts\");\n const nodeSpecPath = yield* getNodeSpecPath;\n const nodeRegisteredFunctionsPath = path.join(\n confectDirectory,\n \"_generated\",\n \"nodeRegisteredFunctions.ts\",\n );\n\n const nodeImplExists = yield* fs.exists(nodeImplPath);\n const nodeSpecExists = yield* fs.exists(nodeSpecPath);\n\n if (!nodeImplExists || !nodeSpecExists) {\n if (yield* fs.exists(nodeRegisteredFunctionsPath)) {\n yield* fs.remove(nodeRegisteredFunctionsPath);\n yield* logFileRemoved(nodeRegisteredFunctionsPath);\n }\n return;\n }\n\n const nodeImplImportPath = yield* removePathExtension(\n path.relative(path.dirname(nodeRegisteredFunctionsPath), nodeImplPath),\n );\n\n const nodeRegisteredFunctionsContents =\n yield* templates.nodeRegisteredFunctions({\n nodeImplImportPath,\n });\n\n yield* writeFileStringAndLog(\n nodeRegisteredFunctionsPath,\n nodeRegisteredFunctionsContents,\n );\n});\n\nconst generateRefs = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const confectGeneratedDirectory = path.join(confectDirectory, \"_generated\");\n const refsPath = path.join(confectGeneratedDirectory, \"refs.ts\");\n const refsDir = path.dirname(refsPath);\n\n const specImportPath = yield* removePathExtension(\n path.relative(refsDir, path.join(confectDirectory, \"spec.ts\")),\n );\n\n const nodeSpecPath = yield* getNodeSpecPath;\n const nodeSpecExists = yield* fs.exists(nodeSpecPath);\n const nodeSpecImportPath = nodeSpecExists\n ? yield* removePathExtension(path.relative(refsDir, nodeSpecPath))\n : null;\n\n const refsContents = yield* templates.refs({\n specImportPath,\n ...(nodeSpecImportPath === null ? {} : { nodeSpecImportPath }),\n });\n\n yield* writeFileStringAndLog(refsPath, refsContents);\n});\n\nconst logGenerated = (effect: typeof generateHttp) =>\n effect.pipe(\n Effect.tap(\n Option.match({\n onNone: () => Effect.void,\n onSome: ({ change, convexFilePath }) =>\n Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(convexFilePath)),\n Match.when(\"Modified\", () => logFileModified(convexFilePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n ),\n }),\n ),\n );\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,kBAAkB,OAAO,IAAI,aAAa;CAC9C,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,mBAAmB,OAAO,iBAAiB;AACjD,QAAO,KAAK,KAAK,kBAAkB,cAAc;EACjD;AAEF,MAAM,eAAe,OAAO,IAAI,aAAa;CAC3C,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,eAAe,OAAO;AAE5B,KAAI,EAAE,OAAO,GAAG,OAAO,aAAa,EAClC,QAAO,OAAO,MAA4C;CAI5D,MAAM,YADiB,OAAO,gBAAgB,aAAa,EAC3B;AAEhC,KAAI,CAAC,KAAK,WAAW,SAAS,CAC5B,QAAO,OAAO,OAAO,IAAI,gDAAgD;AAG3E,QAAO,OAAO,KAAK,SAAS;EAC5B;AAEF,MAAa,UAAU,QAAQ,KAAK,WAAW,EAAE,QAC/C,OAAO,IAAI,aAAa;AACtB,QAAO,WAAW,2BAA2B;AAC7C,QAAO;AACP,QAAO,WAAW,iCAAiC;EACnD,CACH,CAAC,KACA,QAAQ,gBACN,0GACD,CACF;AAED,MAAa,iBAAiB,OAAO,IAAI,aAAa;AACpD,QAAO;AACP,QAAO,OAAO,IACZ;EACE;EACA;EACA;EACA;EACA;EACA;EACD,EACD,EAAE,aAAa,aAAa,CAC7B;CACD,MAAM,CAAC,iBAAiB,OAAO,OAAO,IACpC;EACE;EACA;EACA,aAAa,aAAa;EAC1B,aAAa,cAAc;EAC3B,aAAa,mBAAmB;E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CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"codegen.mjs","names":["CodegenError.tapAndLog","templates.assembledSpec","templates.registeredFunctionsForGroup","Bundler.bundle","FunctionPaths.make","templates.api","templates.nodeApi","templates.schema","templates.services","templates.refs"],"sources":["../../src/confect/codegen.ts"],"sourcesContent":["import { type GroupSpec, Spec } from \"@confect/core\";\nimport * as DatabaseSchema from \"@confect/server/DatabaseSchema\";\nimport { Command } from \"@effect/cli\";\nimport { FileSystem, Path } from \"@effect/platform\";\nimport { Array, Effect, Either, HashSet, Match, Option, Ref } from \"effect\";\nimport { fromBundlerError } from \"../BuildError\";\nimport * as CodegenError from \"../CodegenError\";\nimport {\n MissingImplFileError,\n MissingSchemaFileError,\n MissingSpecFileError,\n ParentChildNameCollisionError,\n SchemaInvalidDefaultExportError,\n} from \"../CodegenError\";\nimport { ConfectDirectory } from \"../ConfectDirectory\";\nimport { ConvexDirectory } from \"../ConvexDirectory\";\nimport * as FunctionPaths from \"../FunctionPaths\";\nimport {\n logFileAdded,\n logFileModified,\n logFileRemoved,\n logPending,\n logSuccess,\n} from \"../log\";\nimport {\n discoverLeafImplFiles,\n discoverLeafSpecFiles,\n implPathForSpec,\n registeredFunctionsRelativePath,\n specPathForImpl,\n toLeafModule,\n toNodeRegistryLeaf,\n validateImpl,\n validateSpec,\n type LeafModule,\n} from \"../LeafModule\";\nimport {\n assemblyNodesFromLeaves,\n partitionByRuntime,\n type SpecAssemblyNode,\n} from \"../SpecAssemblyNode\";\nimport * as templates from \"../templates\";\nimport * as Bundler from \"../Bundler\";\nimport {\n generateAuthConfig,\n generateCrons,\n generateFunctions,\n generateHttp,\n removePathExtension,\n removePathIfExists,\n toModuleImportPath,\n touchConvexSchema,\n writeFileStringAndLog,\n WriteTracker,\n} from \"../utils\";\n\nconst GENERATED_SPEC_PATH = \"_generated/spec.ts\";\nconst GENERATED_NODE_SPEC_PATH = \"_generated/nodeSpec.ts\";\n\nconst LEGACY_PATHS = [\n \"spec.ts\",\n \"nodeSpec.ts\",\n \"impl.ts\",\n \"nodeImpl.ts\",\n \"notesAndRandom.impl.ts\",\n \"groups.impl.ts\",\n \"_generated/registeredFunctions.ts\",\n \"_generated/nodeRegisteredFunctions.ts\",\n \"_generated/impl.ts\",\n \"_generated/nodeImpl.ts\",\n];\n\nexport const codegen = Command.make(\"codegen\", {}, () =>\n Effect.gen(function* () {\n yield* logPending(\"Performing initial sync…\");\n yield* codegenHandler.pipe(\n Effect.asVoid,\n Effect.tap(() => logSuccess(\"Generated files are up-to-date\")),\n CodegenError.tapAndLog,\n );\n }),\n).pipe(\n Command.withDescription(\n \"Generate `confect/_generated` files and the contents of the `convex` directory (except `convex.config.ts` and `tsconfig.json`)\",\n ),\n);\n\nexport const codegenHandler = Effect.gen(function* () {\n const tracker = yield* Ref.make(false);\n\n const functionPaths = yield* runCodegen.pipe(\n Effect.provideService(WriteTracker, tracker),\n );\n\n const anyWritesHappened = yield* Ref.get(tracker);\n return { functionPaths, anyWritesHappened };\n});\n\nconst runCodegen = Effect.gen(function* () {\n yield* generateConfectGeneratedDirectory;\n // Validate schema first so its missing-file / invalid-default-export\n // diagnostics surface ahead of impl bundling, which transitively depends\n // on schema via `_generated/api.ts` and would otherwise blow up with a\n // less actionable bundler error.\n yield* validateSchema;\n const { leaves, groupSpecsByRelativePath } =\n yield* loadAndValidateLeafModules;\n yield* removeLegacyFiles;\n yield* validateNoParentChildNameCollisions(leaves, groupSpecsByRelativePath);\n yield* generateAssembledSpecs(leaves);\n yield* validateImplModules(leaves);\n yield* generateGroupRegisteredFunctions(leaves);\n yield* removeObsoleteRegisteredFunctions(leaves);\n yield* Effect.all(\n [generateApi, generateRefs, generateNodeApi, generateServices],\n { concurrency: \"unbounded\" },\n );\n const [functionPaths] = yield* Effect.all(\n [\n generateFunctionModules,\n generateSchema,\n logGenerated(generateHttp),\n logGenerated(generateCrons),\n logGenerated(generateAuthConfig),\n ],\n { concurrency: \"unbounded\" },\n );\n yield* touchConvexSchema;\n return functionPaths;\n});\n\nconst generateConfectGeneratedDirectory = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n if (!(yield* fs.exists(path.join(confectDirectory, \"_generated\")))) {\n yield* fs.makeDirectory(path.join(confectDirectory, \"_generated\"), {\n recursive: true,\n });\n yield* logFileAdded(path.join(confectDirectory, \"_generated\") + \"/\");\n }\n});\n\nconst loadAndValidateLeafModules = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const specFiles = yield* discoverLeafSpecFiles;\n\n const results = yield* Effect.forEach(specFiles, (specRelativePath) =>\n Effect.gen(function* () {\n const leaf = yield* toLeafModule(specRelativePath);\n const groupSpec = yield* validateSpec(leaf);\n\n const implRelativePath = yield* implPathForSpec(specRelativePath);\n const implAbsolutePath = path.join(confectDirectory, implRelativePath);\n if (!(yield* fs.exists(implAbsolutePath))) {\n return yield* new MissingImplFileError({\n specPath: specRelativePath,\n expectedImplPath: implRelativePath,\n });\n }\n\n return { leaf, groupSpec };\n }),\n );\n\n yield* validateOrphanImpls(specFiles);\n\n const leaves = Array.map(results, ({ leaf }) => leaf);\n const groupSpecsByRelativePath = new Map(\n Array.map(results, ({ leaf, groupSpec }) => [leaf.relativePath, groupSpec]),\n );\n\n return { leaves, groupSpecsByRelativePath };\n});\n\n/**\n * Walk the assembly tree and fail with a {@link ParentChildNameCollisionError}\n * when a parent leaf declares a function or subgroup whose name matches a\n * sibling subdirectory spec's segment. Without this check the colliding\n * descendant would overwrite the parent's entry in the assembled\n * `GroupSpec.groups` map at runtime, surfacing as a confusing\n * `Refs.make` error rather than a codegen-time diagnostic.\n */\nexport const validateNoParentChildNameCollisions = (\n leaves: ReadonlyArray<LeafModule>,\n groupSpecsByRelativePath: ReadonlyMap<string, GroupSpec.AnyWithProps>,\n) =>\n Effect.gen(function* () {\n const { convex, node } = partitionByRuntime(leaves);\n const convexNodes = assemblyNodesFromLeaves(convex);\n const nodeNodes = assemblyNodesFromLeaves(\n Array.map(node, toNodeRegistryLeaf),\n );\n yield* Effect.forEach(convexNodes, (n) =>\n checkAssemblyNodeForCollisions(n, groupSpecsByRelativePath),\n );\n yield* Effect.forEach(nodeNodes, (n) =>\n checkAssemblyNodeForCollisions(n, groupSpecsByRelativePath),\n );\n });\n\nconst checkAssemblyNodeForCollisions = (\n node: SpecAssemblyNode,\n groupSpecsByRelativePath: ReadonlyMap<string, GroupSpec.AnyWithProps>,\n): Effect.Effect<void, ParentChildNameCollisionError> =>\n Effect.gen(function* () {\n yield* Option.match(node.importBinding, {\n onNone: () => Effect.void,\n onSome: (binding) =>\n Effect.gen(function* () {\n if (node.children.length === 0) return;\n const parentRelativePath = bindingToRelativeSpecPath(\n binding.importPath,\n );\n const parentGroupSpec =\n groupSpecsByRelativePath.get(parentRelativePath);\n if (parentGroupSpec === undefined) return;\n yield* Effect.forEach(node.children, (child) => {\n if (\n Object.prototype.hasOwnProperty.call(\n parentGroupSpec.functions,\n child.segment,\n )\n ) {\n return Effect.fail(\n new ParentChildNameCollisionError({\n parentSpecPath: parentRelativePath,\n childSpecPath: childRepresentativeSpecPath(child),\n collisionName: child.segment,\n collisionKind: \"function\",\n }),\n );\n }\n if (\n Object.prototype.hasOwnProperty.call(\n parentGroupSpec.groups,\n child.segment,\n )\n ) {\n return Effect.fail(\n new ParentChildNameCollisionError({\n parentSpecPath: parentRelativePath,\n childSpecPath: childRepresentativeSpecPath(child),\n collisionName: child.segment,\n collisionKind: \"group\",\n }),\n );\n }\n return Effect.void;\n });\n }),\n });\n yield* Effect.forEach(node.children, (child) =>\n checkAssemblyNodeForCollisions(child, groupSpecsByRelativePath),\n );\n });\n\n/**\n * `LeafModule.specImportPath` is the import path used from inside the\n * generated `_generated/spec.ts` (e.g. `\"../notes.spec\"`). Strip the\n * `../` prefix and re-add the `.ts` extension to recover the leaf's\n * confect-relative spec path used as the key in\n * `groupSpecsByRelativePath`.\n */\nconst bindingToRelativeSpecPath = (importPath: string): string => {\n const withoutDotDot = importPath.startsWith(\"../\")\n ? importPath.slice(3)\n : importPath;\n return `${withoutDotDot}.ts`;\n};\n\n/**\n * A child assembly node may itself be a parent without a leaf (when the\n * actual leaves live only in deeper subdirectories). In that case we\n * surface the first descendant leaf as a representative path so the\n * error message points at something the user actually wrote.\n */\nconst childRepresentativeSpecPath = (node: SpecAssemblyNode): string => {\n if (Option.isSome(node.importBinding)) {\n return bindingToRelativeSpecPath(node.importBinding.value.importPath);\n }\n for (const child of node.children) {\n return childRepresentativeSpecPath(child);\n }\n return node.segment;\n};\n\nconst validateOrphanImpls = (specFiles: ReadonlyArray<string>) =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const implFiles = yield* discoverLeafImplFiles;\n const specPaths = new Set(specFiles);\n\n yield* Effect.forEach(implFiles, (implRelativePath) =>\n Effect.gen(function* () {\n const specRelativePath = yield* specPathForImpl(implRelativePath);\n if (specPaths.has(specRelativePath)) {\n return;\n }\n\n const specAbsolutePath = path.join(confectDirectory, specRelativePath);\n if (!(yield* fs.exists(specAbsolutePath))) {\n return yield* new MissingSpecFileError({\n implPath: implRelativePath,\n expectedSpecPath: specRelativePath,\n });\n }\n }),\n );\n });\n\nconst removeLegacyFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n yield* Effect.forEach(LEGACY_PATHS, (relativePath) =>\n Effect.gen(function* () {\n const absolutePath = path.join(confectDirectory, relativePath);\n if (yield* fs.exists(absolutePath)) {\n yield* removePathIfExists(absolutePath);\n yield* logFileRemoved(absolutePath);\n }\n }),\n );\n});\n\nconst generateAssembledSpecs = (leaves: ReadonlyArray<LeafModule>) =>\n Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const { convex, node } = partitionByRuntime(leaves);\n\n if (convex.length > 0) {\n const nodes = assemblyNodesFromLeaves(convex);\n const specContents = yield* templates.assembledSpec({\n nodes,\n runtime: \"Convex\",\n });\n yield* writeFileStringAndLog(\n path.join(confectDirectory, GENERATED_SPEC_PATH),\n specContents,\n );\n }\n\n if (node.length > 0) {\n const nodes = assemblyNodesFromLeaves(\n Array.map(node, toNodeRegistryLeaf),\n );\n const nodeSpecContents = yield* templates.assembledSpec({\n nodes,\n runtime: \"Node\",\n });\n yield* writeFileStringAndLog(\n path.join(confectDirectory, GENERATED_NODE_SPEC_PATH),\n nodeSpecContents,\n );\n }\n });\n\nconst validateImplModules = (leaves: ReadonlyArray<LeafModule>) =>\n Effect.forEach(leaves, validateImpl);\n\nconst generateGroupRegisteredFunctions = (leaves: ReadonlyArray<LeafModule>) =>\n Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n yield* Effect.forEach(leaves, (leaf) =>\n Effect.gen(function* () {\n const registryRelativePath =\n yield* registeredFunctionsRelativePath(leaf);\n const registryPath = path.join(\n confectDirectory,\n \"_generated\",\n registryRelativePath,\n );\n const registryDir = path.dirname(registryPath);\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(registryDir))) {\n yield* fs.makeDirectory(registryDir, { recursive: true });\n }\n\n const implRelativePath = yield* implPathForSpec(leaf.relativePath);\n const apiFileName = leaf.runtime === \"Node\" ? \"nodeApi.ts\" : \"api.ts\";\n const apiImportPath = yield* toModuleImportPath(\n path.relative(\n path.dirname(registryPath),\n path.join(confectDirectory, \"_generated\", apiFileName),\n ),\n );\n const implImportPath = yield* toModuleImportPath(\n path.relative(\n path.dirname(registryPath),\n path.join(confectDirectory, implRelativePath),\n ),\n );\n\n const contents = yield* templates.registeredFunctionsForGroup({\n apiImportPath,\n groupPathDot: leaf.registryGroupPathDot,\n implImportPath,\n layerExportName: leaf.exportName,\n useNode: leaf.runtime === \"Node\",\n });\n\n yield* writeFileStringAndLog(registryPath, contents);\n }),\n );\n });\n\nconst removeObsoleteRegisteredFunctions = (leaves: ReadonlyArray<LeafModule>) =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const registryRoot = path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n );\n\n if (!(yield* fs.exists(registryRoot))) {\n return;\n }\n\n const expected = new Set(\n yield* Effect.forEach(leaves, (leaf) =>\n registeredFunctionsRelativePath(leaf),\n ),\n );\n\n const existing = yield* fs.readDirectory(registryRoot, { recursive: true });\n yield* Effect.forEach(existing, (relativePath) => {\n if (path.extname(relativePath) !== \".ts\") {\n return Effect.void;\n }\n const normalized = path.join(\"registeredFunctions\", relativePath);\n if (!expected.has(normalized)) {\n return Effect.gen(function* () {\n const absolutePath = path.join(registryRoot, relativePath);\n if (yield* fs.exists(absolutePath)) {\n yield* removePathIfExists(absolutePath);\n yield* logFileRemoved(absolutePath);\n }\n });\n }\n return Effect.void;\n });\n });\n\nconst getGeneratedSpecPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n return path.join(confectDirectory, GENERATED_SPEC_PATH);\n});\n\nconst getGeneratedNodeSpecPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n return path.join(confectDirectory, GENERATED_NODE_SPEC_PATH);\n});\n\nconst loadGeneratedSpec = Effect.gen(function* () {\n const specPath = yield* getGeneratedSpecPath;\n const { module: specModule } = yield* Bundler.bundle(specPath);\n const spec = specModule.default;\n\n if (!Spec.isConvexSpec(spec)) {\n return yield* Effect.dieMessage(\n \"_generated/spec.ts does not export a valid Convex Spec\",\n );\n }\n\n return spec;\n});\n\nconst loadGeneratedNodeSpec = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const nodeSpecPath = yield* getGeneratedNodeSpecPath;\n\n if (!(yield* fs.exists(nodeSpecPath))) {\n return Option.none<Spec.AnyWithPropsWithRuntime<\"Node\">>();\n }\n\n const { module: nodeSpecModule } = yield* Bundler.bundle(nodeSpecPath);\n const nodeSpec = nodeSpecModule.default;\n\n if (!Spec.isNodeSpec(nodeSpec)) {\n return yield* Effect.dieMessage(\n \"_generated/nodeSpec.ts does not export a valid Node Spec\",\n );\n }\n\n return Option.some(nodeSpec);\n});\n\nconst emptyFunctionPaths = FunctionPaths.FunctionPaths.make(HashSet.empty());\n\nexport const loadPreviousFunctionPaths = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const specPath = yield* getGeneratedSpecPath;\n\n if (!(yield* fs.exists(specPath))) {\n return emptyFunctionPaths;\n }\n\n const specEither = yield* loadGeneratedSpec.pipe(Effect.either);\n\n return yield* Either.match(specEither, {\n onLeft: () => Effect.succeed(emptyFunctionPaths),\n onRight: (spec) =>\n Effect.gen(function* () {\n const nodeSpecOption = yield* loadGeneratedNodeSpec;\n const mergedSpec = Option.match(nodeSpecOption, {\n onNone: () => spec,\n onSome: (nodeSpec) => Spec.merge(spec, nodeSpec),\n });\n return FunctionPaths.make(mergedSpec);\n }),\n });\n});\n\nconst generateApi = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const apiPath = path.join(confectDirectory, \"_generated\", \"api.ts\");\n const apiDir = path.dirname(apiPath);\n\n const schemaImportPath = yield* toModuleImportPath(\n path.relative(apiDir, path.join(confectDirectory, \"schema.ts\")),\n );\n\n const specImportPath = yield* toModuleImportPath(\n path.relative(apiDir, path.join(confectDirectory, GENERATED_SPEC_PATH)),\n );\n\n const apiContents = yield* templates.api({\n schemaImportPath,\n specImportPath,\n });\n\n yield* writeFileStringAndLog(apiPath, apiContents);\n});\n\nexport const generateNodeApi = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const nodeSpecPath = yield* getGeneratedNodeSpecPath;\n const nodeApiPath = path.join(confectDirectory, \"_generated\", \"nodeApi.ts\");\n\n if (!(yield* fs.exists(nodeSpecPath))) {\n if (yield* fs.exists(nodeApiPath)) {\n yield* removePathIfExists(nodeApiPath);\n yield* logFileRemoved(nodeApiPath);\n }\n return;\n }\n\n const nodeApiDir = path.dirname(nodeApiPath);\n\n const schemaImportPath = yield* toModuleImportPath(\n path.relative(nodeApiDir, path.join(confectDirectory, \"schema.ts\")),\n );\n\n const nodeSpecImportPath = yield* toModuleImportPath(\n path.relative(nodeApiDir, nodeSpecPath),\n );\n\n const nodeApiContents = yield* templates.nodeApi({\n schemaImportPath,\n nodeSpecImportPath,\n });\n\n yield* writeFileStringAndLog(nodeApiPath, nodeApiContents);\n});\n\nconst generateFunctionModules = Effect.gen(function* () {\n const spec = yield* loadGeneratedSpec;\n const nodeSpecOption = yield* loadGeneratedNodeSpec;\n\n const mergedSpec = Option.match(nodeSpecOption, {\n onNone: () => spec,\n onSome: (nodeSpec) => Spec.merge(spec, nodeSpec),\n });\n\n return yield* generateFunctions(mergedSpec);\n});\n\nexport const validateSchema = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const confectSchemaPath = path.join(confectDirectory, \"schema.ts\");\n\n if (!(yield* fs.exists(confectSchemaPath))) {\n return yield* new MissingSchemaFileError({ schemaPath: \"schema.ts\" });\n }\n\n yield* Bundler.bundle(confectSchemaPath).pipe(\n Effect.mapError((error) => fromBundlerError(\"schema.ts\", error)),\n Effect.andThen(({ module: schemaModule }) => {\n const defaultExport = schemaModule.default;\n\n return DatabaseSchema.isDatabaseSchema(defaultExport)\n ? Effect.succeed(defaultExport)\n : Effect.fail(\n new SchemaInvalidDefaultExportError({\n schemaPath: \"schema.ts\",\n }),\n );\n }),\n );\n});\n\nconst generateSchema = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const confectSchemaPath = path.join(confectDirectory, \"schema.ts\");\n\n // `validateSchema` runs once at the top of `runCodegen`; no need to\n // bundle the schema again here.\n\n const convexSchemaPath = path.join(convexDirectory, \"schema.ts\");\n\n const relativeImportPath = path.relative(\n path.dirname(convexSchemaPath),\n confectSchemaPath,\n );\n const importPathWithoutExt = yield* removePathExtension(relativeImportPath);\n const schemaContents = yield* templates.schema({\n schemaImportPath: importPathWithoutExt,\n });\n\n yield* writeFileStringAndLog(convexSchemaPath, schemaContents);\n});\n\nconst generateServices = Effect.gen(function* () {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const confectGeneratedDirectory = path.join(confectDirectory, \"_generated\");\n\n const servicesPath = path.join(confectGeneratedDirectory, \"services.ts\");\n const schemaImportPath = path.relative(\n path.dirname(servicesPath),\n path.join(confectDirectory, \"schema\"),\n );\n\n const servicesContentsString = yield* templates.services({\n schemaImportPath,\n });\n\n yield* writeFileStringAndLog(servicesPath, servicesContentsString);\n});\n\nconst generateRefs = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const confectGeneratedDirectory = path.join(confectDirectory, \"_generated\");\n const refsPath = path.join(confectGeneratedDirectory, \"refs.ts\");\n const refsDir = path.dirname(refsPath);\n\n const specImportPath = yield* toModuleImportPath(\n path.relative(refsDir, path.join(confectDirectory, GENERATED_SPEC_PATH)),\n );\n\n const nodeSpecPath = yield* getGeneratedNodeSpecPath;\n const nodeSpecExists = yield* fs.exists(nodeSpecPath);\n const nodeSpecImportPath = nodeSpecExists\n ? Option.some(\n yield* toModuleImportPath(path.relative(refsDir, nodeSpecPath)),\n )\n : Option.none<string>();\n\n const refsContents = yield* templates.refs({\n specImportPath,\n nodeSpecImportPath,\n });\n\n yield* writeFileStringAndLog(refsPath, refsContents);\n});\n\nconst logGenerated = (effect: typeof generateHttp) =>\n effect.pipe(\n Effect.tap(\n Option.match({\n onNone: () => Effect.void,\n onSome: ({ change, convexFilePath }) =>\n Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(convexFilePath)),\n Match.when(\"Modified\", () => logFileModified(convexFilePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n ),\n }),\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwDA,MAAM,sBAAsB;AAC5B,MAAM,2BAA2B;AAEjC,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,UAAU,QAAQ,KAAK,WAAW,EAAE,QAC/C,OAAO,IAAI,aAAa;AACtB,QAAO,WAAW,2BAA2B;AAC7C,QAAO,eAAe,KACpB,OAAO,QACP,OAAO,UAAU,WAAW,iCAAiC,CAAC,EAC9DA,UACD;EACD,CACH,CAAC,KACA,QAAQ,gBACN,iIACD,CACF;AAED,MAAa,iBAAiB,OAAO,IAAI,aAAa;CACpD,MAAM,UAAU,OAAO,IAAI,KAAK,MAAM;AAOtC,QAAO;EAAE,eALa,OAAO,WAAW,KACtC,OAAO,eAAe,cAAc,QAAQ,CAC7C;EAGuB,mBADE,OAAO,IAAI,IAAI,QAAQ;EACN;EAC3C;AAEF,MAAM,aAAa,OAAO,IAAI,aAAa;AACzC,QAAO;AAKP,QAAO;CACP,MAAM,EAAE,QAAQ,6BACd,OAAO;AACT,QAAO;AACP,QAAO,oCAAoC,QAAQ,yBAAyB;AAC5E,QAAO,uBAAuB,OAAO;AACrC,QAAO,oBAAoB,OAAO;AAClC,QAAO,iCAAiC,OAAO;AAC/C,QAAO,kCAAkC,OAAO;AAChD,QAAO,OAAO,IACZ;EAAC;EAAa;EAAc;EAAiB;EAAiB,EAC9D,EAAE,aAAa,aAAa,CAC7B;CACD,MAAM,CAAC,iBAAiB,OAAO,OAAO,IACpC;EACE;EACA;EACA,aAAa,aAAa;EAC1B,aAAa,cAAc;EAC3B,aAAa,mBAAmB;EACjC,EACD,EAAE,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