@gaganref/confect-cli 10.3.1-fork.8 → 10.3.1-fork.80
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/dist/CodegenError.mjs +16 -1
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/Declaration.mjs +139 -26
- package/dist/Declaration.mjs.map +1 -1
- package/dist/EntryPoint.mjs +2 -0
- package/dist/EntryPoint.mjs.map +1 -1
- package/dist/Evaluation.mjs +39 -13
- package/dist/Evaluation.mjs.map +1 -1
- package/dist/EvaluationWorker.mjs +13 -1
- package/dist/EvaluationWorker.mjs.map +1 -1
- package/dist/FunctionModule.mjs +109 -24
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/LeafModule.mjs +28 -16
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ManifestSections.mjs +125 -0
- package/dist/ManifestSections.mjs.map +1 -0
- package/dist/SectionFiles.mjs +192 -0
- package/dist/SectionFiles.mjs.map +1 -0
- package/dist/SyncState.mjs +1 -1
- package/dist/SyncState.mjs.map +1 -1
- package/dist/Watcher.mjs +60 -56
- package/dist/Watcher.mjs.map +1 -1
- package/dist/confect/codegen.mjs +92 -41
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/declaration.mjs +149 -20
- package/dist/confect/declaration.mjs.map +1 -1
- package/dist/confect/dev.mjs +9 -4
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/templates.mjs +74 -43
- package/dist/templates.mjs.map +1 -1
- package/package.json +6 -5
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { fromBundlerError } from "../BuildError.mjs";
|
|
2
2
|
import { ProjectRoot } from "../ProjectRoot.mjs";
|
|
3
|
-
import { logFileRemoved } from "../log.mjs";
|
|
3
|
+
import { logFileRemoved, logWarn } from "../log.mjs";
|
|
4
4
|
import { bundle, resolveModule } from "../Bundler.mjs";
|
|
5
|
-
import { DeclarationKindMismatchError, HandWrittenConvexFileError, InvalidDeclarationError } from "../CodegenError.mjs";
|
|
5
|
+
import { DeclarationKindMismatchError, HandWrittenConvexFileError, InvalidDeclarationError, logCodegenError } from "../CodegenError.mjs";
|
|
6
6
|
import { ConvexDirectory } from "../ConvexDirectory.mjs";
|
|
7
7
|
import { ConfectDirectory } from "../ConfectDirectory.mjs";
|
|
8
8
|
import { authConfig, declaredHttp, http } from "../templates.mjs";
|
|
9
9
|
import { removePathIfExists, toModuleImportPath, toPosixPath, writeFileString, writeFileStringAndLog } from "../utils.mjs";
|
|
10
|
-
import { CONVEX_CONFIG_FILENAME, componentConfigPlugin, componentImportOf } from "../ConvexConfig.mjs";
|
|
11
|
-
import { authConfig as authConfig$1, convexConfig, digest, fileOf, isGenerated, manifest, parse } from "../Declaration.mjs";
|
|
10
|
+
import { CONVEX_CONFIG_FILENAME, componentConfigPlugin, componentImportOf, discoverInstalledComponents, resolveDefinition } from "../ConvexConfig.mjs";
|
|
11
|
+
import { authConfig as authConfig$1, authProviders, convexConfig, digest, fileOf, isGenerated, manifest, parse, renderManifest } from "../Declaration.mjs";
|
|
12
|
+
import { check, collect, sections, summarize } from "../ManifestSections.mjs";
|
|
12
13
|
import * as Effect from "effect/Effect";
|
|
13
|
-
import { App, Http } from "@confect/core";
|
|
14
|
+
import { App, Http, Mount } from "@confect/core";
|
|
14
15
|
import * as FileSystem from "effect/FileSystem";
|
|
15
16
|
import * as Path from "effect/Path";
|
|
16
17
|
import * as Result from "effect/Result";
|
|
@@ -22,7 +23,7 @@ import * as Predicate from "effect/Predicate";
|
|
|
22
23
|
* Bumped when the generated files change shape, so a manifest written by an
|
|
23
24
|
* older generator never matches a current one.
|
|
24
25
|
*/
|
|
25
|
-
const GENERATOR_FORMAT = "
|
|
26
|
+
const GENERATOR_FORMAT = "2";
|
|
26
27
|
const confectPath = Effect.fnUntraced(function* (file) {
|
|
27
28
|
return (yield* Path.Path).join(yield* ConfectDirectory.get, file);
|
|
28
29
|
});
|
|
@@ -75,16 +76,19 @@ const packageVersion = Effect.fnUntraced(function* (name, from) {
|
|
|
75
76
|
* Every first-party file the declaration modules import, by project-relative
|
|
76
77
|
* path and contents. Files under `node_modules` and outside the project count
|
|
77
78
|
* through package versions instead, so rebuilding a dependency does not change
|
|
78
|
-
* the digest.
|
|
79
|
+
* the digest. The components registry is left out: codegen derives it from the
|
|
80
|
+
* `convex.config.ts` this declaration writes, so its inputs are already here,
|
|
81
|
+
* and a first run bundles a provisional registry that the real one replaces.
|
|
79
82
|
*/
|
|
80
83
|
const declarationInputs = Effect.fnUntraced(function* (bundles) {
|
|
81
84
|
const fs = yield* FileSystem.FileSystem;
|
|
82
85
|
const path = yield* Path.Path;
|
|
83
86
|
const projectRoot = yield* ProjectRoot.get;
|
|
87
|
+
const registry = path.join(yield* ConfectDirectory.get, "_generated", "components.ts");
|
|
84
88
|
const files = /* @__PURE__ */ new Set();
|
|
85
89
|
for (const { metafile } of bundles) for (const input of Object.keys(metafile.inputs)) {
|
|
86
90
|
const relative = path.relative(projectRoot, input);
|
|
87
|
-
if (path.isAbsolute(input) && !relative.startsWith("..") && !relative.split(path.sep).includes("node_modules")) files.add(input);
|
|
91
|
+
if (path.isAbsolute(input) && !relative.startsWith("..") && !relative.split(path.sep).includes("node_modules") && path.resolve(input) !== registry) files.add(input);
|
|
88
92
|
}
|
|
89
93
|
const real = yield* Effect.filter([...files], (file) => fs.exists(file));
|
|
90
94
|
return yield* Effect.forEach(real, (file) => fs.readFileString(file).pipe(Effect.map((contents) => [toPosixPath(path, path.relative(projectRoot, file)), contents])));
|
|
@@ -117,7 +121,46 @@ const removeGenerated = Effect.fnUntraced(function* (filePath, legacy) {
|
|
|
117
121
|
const removeManifest = Effect.gen(function* () {
|
|
118
122
|
yield* removeGenerated(yield* manifestPath, []);
|
|
119
123
|
});
|
|
120
|
-
const
|
|
124
|
+
const readManifest = Effect.gen(function* () {
|
|
125
|
+
const fs = yield* FileSystem.FileSystem;
|
|
126
|
+
const file = yield* manifestPath;
|
|
127
|
+
if (!(yield* fs.exists(file))) return {};
|
|
128
|
+
const data = (yield* bundle(file).pipe(Effect.mapError((error) => fromBundlerError("confect/_generated/manifest.ts", error)))).module.default;
|
|
129
|
+
return Predicate.isObject(data) ? data : {};
|
|
130
|
+
});
|
|
131
|
+
const readPrevious = readManifest.pipe(Effect.orElseSucceed(() => ({})));
|
|
132
|
+
const sectionDigest = (base, sections) => Object.keys(sections).length === 0 ? base : digest({
|
|
133
|
+
files: [["declaration", base]],
|
|
134
|
+
versions: [],
|
|
135
|
+
sections
|
|
136
|
+
});
|
|
137
|
+
const syncManifestSections = Effect.fnUntraced(function* (leaves, previous, baseDigest, modules) {
|
|
138
|
+
if (baseDigest === void 0) return;
|
|
139
|
+
const current = yield* readManifest;
|
|
140
|
+
const registry = yield* Effect.fromResult(collect(leaves).pipe(Result.flatMap((described) => summarize(described, modules))));
|
|
141
|
+
const checked = check(registry, previous);
|
|
142
|
+
for (const note of checked.notes) yield* logWarn(note);
|
|
143
|
+
const [error, ...more] = checked.errors;
|
|
144
|
+
for (const other of more) yield* logCodegenError(other);
|
|
145
|
+
if (error !== void 0) return yield* error;
|
|
146
|
+
const sections = Object.fromEntries([...registry].map(([key, { data }]) => [key, data]));
|
|
147
|
+
const { name, env, http } = current;
|
|
148
|
+
const digest = sectionDigest(baseDigest, sections);
|
|
149
|
+
yield* writeFileStringAndLog(yield* manifestPath, renderManifest({
|
|
150
|
+
name,
|
|
151
|
+
env,
|
|
152
|
+
http,
|
|
153
|
+
digest,
|
|
154
|
+
...sections
|
|
155
|
+
}));
|
|
156
|
+
}, Effect.tapError(() => removeManifest));
|
|
157
|
+
const authProvidersPath = Effect.gen(function* () {
|
|
158
|
+
return (yield* Path.Path).join(yield* ConfectDirectory.get, "_generated", "auth.providers.ts");
|
|
159
|
+
});
|
|
160
|
+
const removeAuthProviders = Effect.gen(function* () {
|
|
161
|
+
yield* removeGenerated(yield* authProvidersPath, []);
|
|
162
|
+
});
|
|
163
|
+
const writeDeclaration = Effect.fnUntraced(function* (previous) {
|
|
121
164
|
const fs = yield* FileSystem.FileSystem;
|
|
122
165
|
const path = yield* Path.Path;
|
|
123
166
|
const convexDirectory = yield* ConvexDirectory.get;
|
|
@@ -147,24 +190,33 @@ const writeDeclaration = Effect.gen(function* () {
|
|
|
147
190
|
const legacyAuthConfigs = yield* Effect.forEach([authImportPath, authImportPath.replace(/\.js$/, "")], (importPath) => authConfig({ authImportPath: importPath }));
|
|
148
191
|
yield* assertOwned(convexConfigPath, "app.ts", []);
|
|
149
192
|
yield* assertOwned(authConfigPath, "auth.ts", legacyAuthConfigs);
|
|
193
|
+
let digest$1;
|
|
150
194
|
if (target === "app") {
|
|
151
|
-
|
|
195
|
+
digest$1 = digest({
|
|
152
196
|
files: yield* declarationInputs([app, ...Option.toArray(auth)]),
|
|
153
197
|
versions: [["convex", yield* packageVersion("convex", projectRoot)], ["@confect/cli generator format", GENERATOR_FORMAT]]
|
|
154
198
|
});
|
|
155
|
-
|
|
199
|
+
const sections$1 = sections(previous);
|
|
200
|
+
yield* writeFileStringAndLog(yield* manifestPath, manifest(declaration, sectionDigest(digest$1, sections$1), sections$1));
|
|
156
201
|
}
|
|
157
202
|
yield* writeFileStringAndLog(convexConfigPath, convexConfig(declaration));
|
|
158
203
|
yield* Option.match(declaration.providers, {
|
|
159
204
|
onNone: () => Effect.gen(function* () {
|
|
205
|
+
yield* removeAuthProviders;
|
|
160
206
|
if (yield* fs.exists(authConfigPath)) {
|
|
161
207
|
yield* removePathIfExists(authConfigPath);
|
|
162
208
|
yield* logFileRemoved(authConfigPath);
|
|
163
209
|
}
|
|
164
210
|
}),
|
|
165
|
-
onSome: (providers) =>
|
|
211
|
+
onSome: (providers) => Effect.gen(function* () {
|
|
212
|
+
yield* writeFileStringAndLog(authConfigPath, authConfig$1(providers));
|
|
213
|
+
yield* writeFileStringAndLog(yield* authProvidersPath, authProviders(providers));
|
|
214
|
+
})
|
|
166
215
|
});
|
|
167
|
-
return
|
|
216
|
+
return {
|
|
217
|
+
app: App.isApp(appValue) ? Option.some(appValue) : Option.none(),
|
|
218
|
+
digest: digest$1
|
|
219
|
+
};
|
|
168
220
|
});
|
|
169
221
|
/**
|
|
170
222
|
* Write the declaration's Convex files and manifest from `confect/app.ts`,
|
|
@@ -172,20 +224,24 @@ const writeDeclaration = Effect.gen(function* () {
|
|
|
172
224
|
* any failure the previous manifest is removed, so a stale manifest never
|
|
173
225
|
* outlives a declaration that no longer produces it.
|
|
174
226
|
*/
|
|
175
|
-
const syncDeclaration = Effect.
|
|
227
|
+
const syncDeclaration = Effect.fnUntraced(function* (previous) {
|
|
176
228
|
if (!(yield* isDeclared)) {
|
|
177
229
|
yield* removeManifest;
|
|
178
|
-
|
|
230
|
+
yield* removeAuthProviders;
|
|
231
|
+
return {
|
|
232
|
+
app: Option.none(),
|
|
233
|
+
digest: void 0
|
|
234
|
+
};
|
|
179
235
|
}
|
|
180
|
-
return yield* writeDeclaration.pipe(Effect.tapError(() => removeManifest));
|
|
236
|
+
return yield* writeDeclaration(previous).pipe(Effect.tapError(() => removeManifest.pipe(Effect.andThen(removeAuthProviders))));
|
|
181
237
|
});
|
|
182
238
|
/**
|
|
183
239
|
* Check every HTTP route the backend serves and write `convex/http.ts` from
|
|
184
240
|
* `confect/http.ts`. Runs after generation, because `http.ts` imports its
|
|
185
241
|
* handlers, which import generated services.
|
|
186
242
|
*/
|
|
187
|
-
const syncDeclaredHttp = (app) => checkAndWriteHttp(app).pipe(Effect.tapError(() => removeManifest));
|
|
188
|
-
const checkAndWriteHttp = Effect.fnUntraced(function* (app) {
|
|
243
|
+
const syncDeclaredHttp = (app, sectionFiles) => checkAndWriteHttp(app, sectionFiles).pipe(Effect.tapError(() => removeManifest));
|
|
244
|
+
const checkAndWriteHttp = Effect.fnUntraced(function* (app, sectionFiles) {
|
|
189
245
|
const fs = yield* FileSystem.FileSystem;
|
|
190
246
|
const path = yield* Path.Path;
|
|
191
247
|
const convexDirectory = yield* ConvexDirectory.get;
|
|
@@ -204,8 +260,10 @@ const checkAndWriteHttp = Effect.fnUntraced(function* (app) {
|
|
|
204
260
|
});
|
|
205
261
|
yield* Http.routes(app, http$1).pipe(Result.mapError(invalid("http.ts")), Effect.fromResult);
|
|
206
262
|
const contents = yield* declaredHttp({
|
|
263
|
+
runtimeImportPath: (yield* fs.exists(path.join(confectDirectory, "runtime.ts"))) ? yield* toModuleImportPath(path.relative(convexDirectory, path.join(confectDirectory, "runtime.ts"))) : void 0,
|
|
207
264
|
schemaImportPath: yield* toModuleImportPath(path.relative(convexDirectory, path.join(confectDirectory, "_generated", "schema.ts"))),
|
|
208
|
-
httpImportPath: yield* toModuleImportPath(path.relative(convexDirectory, httpPath))
|
|
265
|
+
httpImportPath: yield* toModuleImportPath(path.relative(convexDirectory, httpPath)),
|
|
266
|
+
sectionImportPaths: yield* Effect.forEach(sectionFiles, (file) => toModuleImportPath(path.relative(convexDirectory, path.join(confectDirectory, "_generated", file))))
|
|
209
267
|
});
|
|
210
268
|
const change = yield* writeFileString(convexHttpPath, contents);
|
|
211
269
|
return Option.some({
|
|
@@ -213,7 +271,78 @@ const checkAndWriteHttp = Effect.fnUntraced(function* (app) {
|
|
|
213
271
|
convexFilePath: convexHttpPath
|
|
214
272
|
});
|
|
215
273
|
});
|
|
274
|
+
const DEPLOY_MODULE = "confectDeploy.ts";
|
|
275
|
+
/**
|
|
276
|
+
* Whether a mounted component's own codegen wrote a deploy module, so a push
|
|
277
|
+
* visits its mounts after its `init`.
|
|
278
|
+
*/
|
|
279
|
+
const hasDeployModule = Effect.fnUntraced(function* (component, config) {
|
|
280
|
+
const fs = yield* FileSystem.FileSystem;
|
|
281
|
+
const path = yield* Path.Path;
|
|
282
|
+
const directory = path.isAbsolute(component.componentDefinitionPath) ? Option.some(component.componentDefinitionPath) : Option.map(resolveDefinition(`${component.componentDefinitionPath}/convex.config`, config, path), path.dirname);
|
|
283
|
+
if (Option.isNone(directory)) return false;
|
|
284
|
+
for (const file of [DEPLOY_MODULE, "confectDeploy.js"]) if (yield* fs.exists(path.join(directory.value, file))) return true;
|
|
285
|
+
return false;
|
|
286
|
+
});
|
|
287
|
+
/**
|
|
288
|
+
* The export of `confect/<name>.ts` that is the mount named `name`.
|
|
289
|
+
*/
|
|
290
|
+
const mountExport = Effect.fnUntraced(function* (name) {
|
|
291
|
+
const fs = yield* FileSystem.FileSystem;
|
|
292
|
+
const file = yield* confectPath(`${name}.ts`);
|
|
293
|
+
const missing = new InvalidDeclarationError({
|
|
294
|
+
declarationPath: "confect/app.ts",
|
|
295
|
+
reason: `the mount ${name} runs at every push, so export it from confect/${name}.ts.`
|
|
296
|
+
});
|
|
297
|
+
if (!(yield* fs.exists(file))) return yield* missing;
|
|
298
|
+
const exports = (yield* bundleDeclaration(`${name}.ts`)).module;
|
|
299
|
+
const found = Object.entries(exports).find(([, value]) => Predicate.hasProperty(value, "~@confect/core/Mount") && Mount.data(value).name === name);
|
|
300
|
+
if (found === void 0) return yield* missing;
|
|
301
|
+
return {
|
|
302
|
+
file,
|
|
303
|
+
exportName: found[0]
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
/**
|
|
307
|
+
* Write `convex/confectDeploy.ts`, the internal mutation a push calls for the
|
|
308
|
+
* steps it runs at each mount: every mount whose component declares `init` or
|
|
309
|
+
* has a deploy module of its own, in declaration order. Remove it when there
|
|
310
|
+
* are none.
|
|
311
|
+
*/
|
|
312
|
+
const syncDeployModule = Effect.fnUntraced(function* (app) {
|
|
313
|
+
const fs = yield* FileSystem.FileSystem;
|
|
314
|
+
const path = yield* Path.Path;
|
|
315
|
+
const convexDirectory = yield* ConvexDirectory.get;
|
|
316
|
+
const deployPath = path.join(convexDirectory, DEPLOY_MODULE);
|
|
317
|
+
const config = path.join(convexDirectory, CONVEX_CONFIG_FILENAME);
|
|
318
|
+
const installed = Option.isSome(app) && (yield* fs.exists(config)) ? yield* discoverInstalledComponents(config, yield* displayPath(config), (yield* ConvexDirectory.target).kind) : [];
|
|
319
|
+
const entries = [];
|
|
320
|
+
const imports = [];
|
|
321
|
+
for (const mount of Option.match(app, {
|
|
322
|
+
onNone: () => [],
|
|
323
|
+
onSome: App.mounts
|
|
324
|
+
})) {
|
|
325
|
+
const component = installed.find(({ name }) => name === mount.name);
|
|
326
|
+
const nested = component !== void 0 && (yield* hasDeployModule(component, config));
|
|
327
|
+
if (mount.component.init === void 0 && !nested) continue;
|
|
328
|
+
const { file, exportName } = yield* mountExport(mount.name);
|
|
329
|
+
const local = `mount${entries.length}`;
|
|
330
|
+
imports.push(`import { ${exportName} as ${local} } from "${yield* toModuleImportPath(path.relative(convexDirectory, file))}";`);
|
|
331
|
+
entries.push(` { mount: ${local}, nested: ${nested} },`);
|
|
332
|
+
}
|
|
333
|
+
if (entries.length === 0) return yield* removeGenerated(deployPath, []);
|
|
334
|
+
yield* writeFileStringAndLog(deployPath, [
|
|
335
|
+
"// Generated by `confect codegen` from confect/app.ts. Do not edit.",
|
|
336
|
+
"import { MountInit } from \"@confect/server\";",
|
|
337
|
+
...imports,
|
|
338
|
+
"",
|
|
339
|
+
"export const steps = MountInit.mutation([",
|
|
340
|
+
...entries,
|
|
341
|
+
"]);",
|
|
342
|
+
""
|
|
343
|
+
].join("\n"));
|
|
344
|
+
});
|
|
216
345
|
//#endregion
|
|
217
|
-
export { isDeclared, syncDeclaration, syncDeclaredHttp };
|
|
346
|
+
export { isDeclared, readPrevious, syncDeclaration, syncDeclaredHttp, syncDeployModule, syncManifestSections };
|
|
218
347
|
|
|
219
348
|
//# sourceMappingURL=declaration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin","Declaration.isGenerated","Bundler.resolveModule","ConvexConfig.componentImportOf","Declaration.parse","Declaration.fileOf","ConvexConfig.CONVEX_CONFIG_FILENAME","templates.authConfig","digest","Declaration.digest","Declaration.manifest","Declaration.convexConfig","Declaration.authConfig","templates.http","http","templates.declaredHttp"],"sources":["../../src/confect/declaration.ts"],"sourcesContent":["import { App, Http } from \"@confect/core\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"../BuildError.js\";\nimport * as Bundler from \"../Bundler.js\";\nimport {\n HandWrittenConvexFileError,\n DeclarationKindMismatchError,\n InvalidDeclarationError,\n} from \"../CodegenError.js\";\nimport { ConfectDirectory } from \"../ConfectDirectory.js\";\nimport * as ConvexConfig from \"../ConvexConfig.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as Declaration from \"../Declaration.js\";\nimport { logFileRemoved } from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport * as templates from \"../templates.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n writeFileString,\n writeFileStringAndLog,\n} from \"../utils.js\";\n\n/**\n * Bumped when the generated files change shape, so a manifest written by an\n * older generator never matches a current one.\n */\nconst GENERATOR_FORMAT = \"1\";\n\nconst confectPath = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, file);\n});\n\n/**\n * A backend opts in to the declaration by writing `confect/app.ts`.\n */\nexport const isDeclared = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n return yield* fs.exists(yield* confectPath(\"app.ts\"));\n});\n\nconst displayPath = Effect.fnUntraced(function* (absolutePath: string) {\n const path = yield* Path.Path;\n return toPosixPath(path, path.relative(yield* ProjectRoot.get, absolutePath));\n});\n\nconst bundleDeclaration = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n const absolutePath = yield* confectPath(file);\n return yield* Bundler.bundle(absolutePath, {\n plugins: [ConvexConfig.componentConfigPlugin(path)],\n }).pipe(\n Effect.mapError((error) => fromBundlerError(`confect/${file}`, error)),\n );\n});\n\nconst invalid = (file: string) => (error: { readonly message: string }) =>\n new InvalidDeclarationError({\n declarationPath: `confect/${file}`,\n reason: error.message,\n });\n\n/**\n * Fail instead of overwriting a Convex file someone wrote by hand. A file with\n * the generated header, or one of the exact files an earlier codegen wrote\n * there, is ours to replace.\n */\nconst assertOwned = Effect.fnUntraced(function* (\n convexPath: string,\n declarationFile: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(convexPath))) return;\n if (Declaration.isGenerated(yield* fs.readFileString(convexPath), legacy)) {\n return;\n }\n return yield* new HandWrittenConvexFileError({\n convexPath: yield* displayPath(convexPath),\n declarationPath: `confect/${declarationFile}`,\n });\n});\n\nconst decodeVersion = Schema.decodeUnknownOption(\n Schema.fromJsonString(Schema.Struct({ version: Schema.String })),\n);\n\nconst packageVersion = Effect.fnUntraced(function* (\n name: string,\n from: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n return yield* Option.match(\n Bundler.resolveModule(`${name}/package.json`, path.join(from, \"_\")),\n {\n onNone: () => Effect.succeed(\"unresolved\"),\n onSome: (packageJson) =>\n fs.readFileString(packageJson).pipe(\n Effect.map((contents) =>\n Option.match(decodeVersion(contents), {\n onNone: () => \"unknown\",\n onSome: ({ version }) => version,\n }),\n ),\n ),\n },\n );\n});\n\n/**\n * Every first-party file the declaration modules import, by project-relative\n * path and contents. Files under `node_modules` and outside the project count\n * through package versions instead, so rebuilding a dependency does not change\n * the digest.\n */\nconst declarationInputs = Effect.fnUntraced(function* (\n bundles: ReadonlyArray<Bundler.Bundled>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const projectRoot = yield* ProjectRoot.get;\n const files = new Set<string>();\n for (const { metafile } of bundles) {\n for (const input of Object.keys(metafile.inputs)) {\n const relative = path.relative(projectRoot, input);\n if (\n path.isAbsolute(input) &&\n !relative.startsWith(\"..\") &&\n !relative.split(path.sep).includes(\"node_modules\")\n ) {\n files.add(input);\n }\n }\n }\n // Plugin namespaces (component config wrappers) appear as inputs too;\n // only real files count.\n const real = yield* Effect.filter([...files], (file) => fs.exists(file));\n return yield* Effect.forEach(real, (file) =>\n fs\n .readFileString(file)\n .pipe(\n Effect.map(\n (contents) =>\n [\n toPosixPath(path, path.relative(projectRoot, file)),\n contents,\n ] as const,\n ),\n ),\n );\n});\n\nconst componentImport = Effect.fnUntraced(function* () {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n return (definition: unknown): Option.Option<Declaration.ComponentImport> =>\n Option.map(ConvexConfig.componentImportOf(definition), (recorded) => {\n const bare =\n !recorded.specifier.startsWith(\".\") &&\n !path.isAbsolute(recorded.specifier);\n const relative = toPosixPath(\n path,\n path.relative(convexDirectory, recorded.path),\n ).replace(/\\.([cm]?)[jt]s$/, \".$1js\");\n return {\n importPath: bare\n ? recorded.specifier\n : relative.startsWith(\".\")\n ? relative\n : `./${relative}`,\n componentName:\n Predicate.hasProperty(definition, \"defaultName\") &&\n Predicate.isString(definition.defaultName)\n ? definition.defaultName\n : \"component\",\n };\n });\n});\n\nconst manifestPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, \"_generated\", \"manifest.ts\");\n});\n\n/**\n * Remove a file codegen wrote whose source is gone; leave anything else.\n */\nconst removeGenerated = Effect.fnUntraced(function* (\n filePath: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(filePath))) return;\n if (!Declaration.isGenerated(yield* fs.readFileString(filePath), legacy)) {\n return;\n }\n yield* removePathIfExists(filePath);\n yield* logFileRemoved(filePath);\n});\n\nconst removeManifest = Effect.gen(function* () {\n yield* removeGenerated(yield* manifestPath, []);\n});\n\nconst writeDeclaration = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const target = (yield* ConvexDirectory.target).kind;\n\n const app = yield* bundleDeclaration(\"app.ts\");\n const appValue: unknown = app.module.default;\n if (App.isApp(appValue) && appValue.kind !== target) {\n return yield* new DeclarationKindMismatchError({\n declarationPath: \"confect/app.ts\",\n declaredKind: appValue.kind,\n targetKind: target,\n });\n }\n const authPath = yield* confectPath(\"auth.ts\");\n const auth = (yield* fs.exists(authPath))\n ? Option.some(yield* bundleDeclaration(\"auth.ts\"))\n : Option.none();\n\n const declaration = yield* Declaration.parse({\n target,\n app: app.module.default,\n auth: Option.map(auth, ({ module }) => module.default),\n componentImport: yield* componentImport(),\n }).pipe(\n Result.mapError(\n (error) =>\n new InvalidDeclarationError({\n declarationPath: Declaration.fileOf(error),\n reason: error.message,\n }),\n ),\n Effect.fromResult,\n );\n\n const convexConfigPath = path.join(\n convexDirectory,\n ConvexConfig.CONVEX_CONFIG_FILENAME,\n );\n const authConfigPath = path.join(convexDirectory, \"auth.config.ts\");\n const authImportPath = yield* toModuleImportPath(\n path.relative(convexDirectory, authPath),\n );\n const legacyAuthConfigs = yield* Effect.forEach(\n [authImportPath, authImportPath.replace(/\\.js$/, \"\")],\n (importPath) => templates.authConfig({ authImportPath: importPath }),\n );\n yield* assertOwned(convexConfigPath, \"app.ts\", []);\n yield* assertOwned(authConfigPath, \"auth.ts\", legacyAuthConfigs);\n\n if (target === \"app\") {\n const digest = Declaration.digest({\n files: yield* declarationInputs([app, ...Option.toArray(auth)]),\n versions: [\n [\"convex\", yield* packageVersion(\"convex\", projectRoot)],\n [\"@confect/cli generator format\", GENERATOR_FORMAT],\n ],\n });\n yield* writeFileStringAndLog(\n yield* manifestPath,\n Declaration.manifest(declaration, digest),\n );\n }\n yield* writeFileStringAndLog(\n convexConfigPath,\n Declaration.convexConfig(declaration),\n );\n yield* Option.match(declaration.providers, {\n onNone: () =>\n Effect.gen(function* () {\n if (yield* fs.exists(authConfigPath)) {\n yield* removePathIfExists(authConfigPath);\n yield* logFileRemoved(authConfigPath);\n }\n }),\n onSome: (providers) =>\n writeFileStringAndLog(authConfigPath, Declaration.authConfig(providers)),\n });\n return App.isApp(appValue) ? Option.some(appValue) : Option.none<App.Any>();\n});\n\n/**\n * Write the declaration's Convex files and manifest from `confect/app.ts`,\n * `confect/env.ts` and `confect/auth.ts`, before anything else is validated. On\n * any failure the previous manifest is removed, so a stale manifest never\n * outlives a declaration that no longer produces it.\n */\nexport const syncDeclaration = Effect.gen(function* () {\n if (!(yield* isDeclared)) {\n yield* removeManifest;\n return Option.none<App.Any>();\n }\n return yield* writeDeclaration.pipe(Effect.tapError(() => removeManifest));\n});\n\n/**\n * Check every HTTP route the backend serves and write `convex/http.ts` from\n * `confect/http.ts`. Runs after generation, because `http.ts` imports its\n * handlers, which import generated services.\n */\nexport const syncDeclaredHttp = (app: App.Any) =>\n checkAndWriteHttp(app).pipe(Effect.tapError(() => removeManifest));\n\nconst checkAndWriteHttp = Effect.fnUntraced(function* (app: App.Any) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const confectDirectory = yield* ConfectDirectory.get;\n const httpPath = yield* confectPath(\"http.ts\");\n\n const convexHttpPath = path.join(convexDirectory, \"http.ts\");\n if (!(yield* fs.exists(httpPath))) {\n yield* Http.routes(app).pipe(\n Result.mapError(invalid(\"app.ts\")),\n Effect.fromResult,\n );\n yield* removeGenerated(convexHttpPath, [\n yield* templates.http({\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n }),\n ]);\n return Option.none();\n }\n\n const http = (yield* bundleDeclaration(\"http.ts\")).module.default;\n if (!Http.isHttp(http)) {\n return yield* new InvalidDeclarationError({\n declarationPath: \"confect/http.ts\",\n reason: \"it must default-export Http.make(...).\",\n });\n }\n yield* Http.routes(app, http).pipe(\n Result.mapError(invalid(\"http.ts\")),\n Effect.fromResult,\n );\n\n const contents = yield* templates.declaredHttp({\n schemaImportPath: yield* toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"_generated\", \"schema.ts\"),\n ),\n ),\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n });\n const change = yield* writeFileString(convexHttpPath, contents);\n return Option.some({ change, convexFilePath: convexHttpPath });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,mBAAmB;AAEzB,MAAM,cAAc,OAAO,WAAW,WAAW,MAAc;CAE7D,QAAO,OADa,KAAK,KAAA,CACb,KAAK,OAAO,iBAAiB,KAAK,IAAI;AACpD,CAAC;;;;AAKD,MAAa,aAAa,OAAO,IAAI,aAAa;CAEhD,OAAO,QAAO,OADI,WAAW,WAAA,CACZ,OAAO,OAAO,YAAY,QAAQ,CAAC;AACtD,CAAC;AAED,MAAM,cAAc,OAAO,WAAW,WAAW,cAAsB;CACrE,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,YAAY,MAAM,KAAK,SAAS,OAAO,YAAY,KAAK,YAAY,CAAC;AAC9E,CAAC;AAED,MAAM,oBAAoB,OAAO,WAAW,WAAW,MAAc;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,eAAe,OAAO,YAAY,IAAI;CAC5C,OAAO,OAAOA,OAAe,cAAc,EACzC,SAAS,CAACC,sBAAmC,IAAI,CAAC,EACpD,CAAC,CAAC,CAAC,KACD,OAAO,UAAU,UAAU,iBAAiB,WAAW,QAAQ,KAAK,CAAC,CACvE;AACF,CAAC;AAED,MAAM,WAAW,UAAkB,UACjC,IAAI,wBAAwB;CAC1B,iBAAiB,WAAW;CAC5B,QAAQ,MAAM;AAChB,CAAC;;;;;;AAOH,MAAM,cAAc,OAAO,WAAW,WACpC,YACA,iBACA,QACA;CACA,MAAM,KAAK,OAAO,WAAW;CAC7B,IAAI,EAAE,OAAO,GAAG,OAAO,UAAU,IAAI;CACrC,IAAIC,YAAwB,OAAO,GAAG,eAAe,UAAU,GAAG,MAAM,GACtE;CAEF,OAAO,OAAO,IAAI,2BAA2B;E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,gBAAgB,gBAAgB,CACrC,OAAOC,KAAe,EACpB,gBAAgB,OAAO,mBACrB,KAAK,SAAS,iBAAiB,QAAQ,CACzC,EACF,CAAC,CACH,CAAC;EACD,OAAO,OAAO,KAAK;CACrB;CAEA,MAAMC,UAAQ,OAAO,kBAAkB,SAAS,EAAA,CAAG,OAAO;CAC1D,IAAI,CAAC,KAAK,OAAOA,MAAI,GACnB,OAAO,OAAO,IAAI,wBAAwB;EACxC,iBAAiB;EACjB,QAAQ;CACV,CAAC;CAEH,OAAO,KAAK,OAAO,KAAKA,MAAI,CAAC,CAAC,KAC5B,OAAO,SAAS,QAAQ,SAAS,CAAC,GAClC,OAAO,UACT;CAEA,MAAM,WAAW,OAAOC,aAAuB;EAC7C,kBAAkB,OAAO,mBACvB,KAAK,SACH,iBACA,KAAK,KAAK,kBAAkB,cAAc,WAAW,CACvD,CACF;EACA,gBAAgB,OAAO,mBACrB,KAAK,SAAS,iBAAiB,QAAQ,CACzC;CACF,CAAC;CACD,MAAM,SAAS,OAAO,gBAAgB,gBAAgB,QAAQ;CAC9D,OAAO,OAAO,KAAK;EAAE;EAAQ,gBAAgB;CAAe,CAAC;AAC/D,CAAC"}
|
|
1
|
+
{"version":3,"file":"declaration.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin","Declaration.isGenerated","Bundler.resolveModule","ConvexConfig.componentImportOf","Declaration.digest","ManifestSections.collect","ManifestSections.summarize","ManifestSections.check","Declaration.renderManifest","Declaration.parse","Declaration.fileOf","ConvexConfig.CONVEX_CONFIG_FILENAME","templates.authConfig","digest","sections","ManifestSections.sections","Declaration.manifest","Declaration.convexConfig","Declaration.authConfig","Declaration.authProviders","templates.http","http","templates.declaredHttp","ConvexConfig.resolveDefinition","ConvexConfig.discoverInstalledComponents"],"sources":["../../src/confect/declaration.ts"],"sourcesContent":["import { App, Http, Mount, type ManifestSection } from \"@confect/core\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"../BuildError.js\";\nimport * as Bundler from \"../Bundler.js\";\nimport {\n HandWrittenConvexFileError,\n DeclarationKindMismatchError,\n InvalidDeclarationError,\n logCodegenError,\n} from \"../CodegenError.js\";\nimport { ConfectDirectory } from \"../ConfectDirectory.js\";\nimport * as ConvexConfig from \"../ConvexConfig.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as Declaration from \"../Declaration.js\";\nimport * as ManifestSections from \"../ManifestSections.js\";\nimport type { LoadedLeafModule } from \"../LeafModule.js\";\nimport { logWarn, logFileRemoved } from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport * as templates from \"../templates.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n writeFileString,\n writeFileStringAndLog,\n} from \"../utils.js\";\n\n/**\n * Bumped when the generated files change shape, so a manifest written by an\n * older generator never matches a current one.\n */\nconst GENERATOR_FORMAT = \"2\";\n\nconst confectPath = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, file);\n});\n\n/**\n * A backend opts in to the declaration by writing `confect/app.ts`.\n */\nexport const isDeclared = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n return yield* fs.exists(yield* confectPath(\"app.ts\"));\n});\n\nconst displayPath = Effect.fnUntraced(function* (absolutePath: string) {\n const path = yield* Path.Path;\n return toPosixPath(path, path.relative(yield* ProjectRoot.get, absolutePath));\n});\n\nconst bundleDeclaration = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n const absolutePath = yield* confectPath(file);\n return yield* Bundler.bundle(absolutePath, {\n plugins: [ConvexConfig.componentConfigPlugin(path)],\n }).pipe(\n Effect.mapError((error) => fromBundlerError(`confect/${file}`, error)),\n );\n});\n\nconst invalid = (file: string) => (error: { readonly message: string }) =>\n new InvalidDeclarationError({\n declarationPath: `confect/${file}`,\n reason: error.message,\n });\n\n/**\n * Fail instead of overwriting a Convex file someone wrote by hand. A file with\n * the generated header, or one of the exact files an earlier codegen wrote\n * there, is ours to replace.\n */\nconst assertOwned = Effect.fnUntraced(function* (\n convexPath: string,\n declarationFile: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(convexPath))) return;\n if (Declaration.isGenerated(yield* fs.readFileString(convexPath), legacy)) {\n return;\n }\n return yield* new HandWrittenConvexFileError({\n convexPath: yield* displayPath(convexPath),\n declarationPath: `confect/${declarationFile}`,\n });\n});\n\nconst decodeVersion = Schema.decodeUnknownOption(\n Schema.fromJsonString(Schema.Struct({ version: Schema.String })),\n);\n\nconst packageVersion = Effect.fnUntraced(function* (\n name: string,\n from: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n return yield* Option.match(\n Bundler.resolveModule(`${name}/package.json`, path.join(from, \"_\")),\n {\n onNone: () => Effect.succeed(\"unresolved\"),\n onSome: (packageJson) =>\n fs.readFileString(packageJson).pipe(\n Effect.map((contents) =>\n Option.match(decodeVersion(contents), {\n onNone: () => \"unknown\",\n onSome: ({ version }) => version,\n }),\n ),\n ),\n },\n );\n});\n\n/**\n * Every first-party file the declaration modules import, by project-relative\n * path and contents. Files under `node_modules` and outside the project count\n * through package versions instead, so rebuilding a dependency does not change\n * the digest. The components registry is left out: codegen derives it from the\n * `convex.config.ts` this declaration writes, so its inputs are already here,\n * and a first run bundles a provisional registry that the real one replaces.\n */\nconst declarationInputs = Effect.fnUntraced(function* (\n bundles: ReadonlyArray<Bundler.Bundled>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const projectRoot = yield* ProjectRoot.get;\n const registry = path.join(\n yield* ConfectDirectory.get,\n \"_generated\",\n \"components.ts\",\n );\n const files = new Set<string>();\n for (const { metafile } of bundles) {\n for (const input of Object.keys(metafile.inputs)) {\n const relative = path.relative(projectRoot, input);\n if (\n path.isAbsolute(input) &&\n !relative.startsWith(\"..\") &&\n !relative.split(path.sep).includes(\"node_modules\") &&\n path.resolve(input) !== registry\n ) {\n files.add(input);\n }\n }\n }\n // Plugin namespaces (component config wrappers) appear as inputs too;\n // only real files count.\n const real = yield* Effect.filter([...files], (file) => fs.exists(file));\n return yield* Effect.forEach(real, (file) =>\n fs\n .readFileString(file)\n .pipe(\n Effect.map(\n (contents) =>\n [\n toPosixPath(path, path.relative(projectRoot, file)),\n contents,\n ] as const,\n ),\n ),\n );\n});\n\nconst componentImport = Effect.fnUntraced(function* () {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n return (definition: unknown): Option.Option<Declaration.ComponentImport> =>\n Option.map(ConvexConfig.componentImportOf(definition), (recorded) => {\n const bare =\n !recorded.specifier.startsWith(\".\") &&\n !path.isAbsolute(recorded.specifier);\n const relative = toPosixPath(\n path,\n path.relative(convexDirectory, recorded.path),\n ).replace(/\\.([cm]?)[jt]s$/, \".$1js\");\n return {\n importPath: bare\n ? recorded.specifier\n : relative.startsWith(\".\")\n ? relative\n : `./${relative}`,\n componentName:\n Predicate.hasProperty(definition, \"defaultName\") &&\n Predicate.isString(definition.defaultName)\n ? definition.defaultName\n : \"component\",\n };\n });\n});\n\nconst manifestPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, \"_generated\", \"manifest.ts\");\n});\n\n/**\n * Remove a file codegen wrote whose source is gone; leave anything else.\n */\nconst removeGenerated = Effect.fnUntraced(function* (\n filePath: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(filePath))) return;\n if (!Declaration.isGenerated(yield* fs.readFileString(filePath), legacy)) {\n return;\n }\n yield* removePathIfExists(filePath);\n yield* logFileRemoved(filePath);\n});\n\nconst removeManifest = Effect.gen(function* () {\n yield* removeGenerated(yield* manifestPath, []);\n});\n\nconst readManifest = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const file = yield* manifestPath;\n if (!(yield* fs.exists(file))) return {} as Record<string, unknown>;\n const data: unknown = (yield* Bundler.bundle(file).pipe(\n Effect.mapError((error) =>\n fromBundlerError(\"confect/_generated/manifest.ts\", error),\n ),\n )).module.default;\n return Predicate.isObject(data) ? data : {};\n});\n\nexport const readPrevious = readManifest.pipe(\n Effect.orElseSucceed(() => ({}) as Record<string, unknown>),\n);\n\nconst sectionDigest = (\n base: string,\n sections: Readonly<Record<string, unknown>>,\n) =>\n Object.keys(sections).length === 0\n ? base\n : Declaration.digest({\n files: [[\"declaration\", base]],\n versions: [],\n sections,\n });\n\nexport const syncManifestSections = Effect.fnUntraced(\n function* (\n leaves: ReadonlyArray<LoadedLeafModule>,\n previous: Readonly<Record<string, unknown>>,\n baseDigest: string | undefined,\n modules: ReadonlyMap<string, ManifestSection.GenerateInput[\"modules\"]>,\n ) {\n if (baseDigest === undefined) return;\n const current = yield* readManifest;\n const registry = yield* Effect.fromResult(\n ManifestSections.collect(leaves).pipe(\n Result.flatMap((described) =>\n ManifestSections.summarize(described, modules),\n ),\n ),\n );\n const checked = ManifestSections.check(registry, previous);\n for (const note of checked.notes) yield* logWarn(note);\n const [error, ...more] = checked.errors;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n const sections = Object.fromEntries(\n [...registry].map(([key, { data }]) => [key, data]),\n );\n const { name, env, http } = current;\n const digest = sectionDigest(baseDigest, sections);\n yield* writeFileStringAndLog(\n yield* manifestPath,\n Declaration.renderManifest({ name, env, http, digest, ...sections }),\n );\n },\n Effect.tapError(() => removeManifest),\n);\n\nconst authProvidersPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n return path.join(\n yield* ConfectDirectory.get,\n \"_generated\",\n \"auth.providers.ts\",\n );\n});\n\nconst removeAuthProviders = Effect.gen(function* () {\n yield* removeGenerated(yield* authProvidersPath, []);\n});\n\nconst writeDeclaration = Effect.fnUntraced(function* (\n previous: Readonly<Record<string, unknown>>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const target = (yield* ConvexDirectory.target).kind;\n\n const app = yield* bundleDeclaration(\"app.ts\");\n const appValue: unknown = app.module.default;\n if (App.isApp(appValue) && appValue.kind !== target) {\n return yield* new DeclarationKindMismatchError({\n declarationPath: \"confect/app.ts\",\n declaredKind: appValue.kind,\n targetKind: target,\n });\n }\n const authPath = yield* confectPath(\"auth.ts\");\n const auth = (yield* fs.exists(authPath))\n ? Option.some(yield* bundleDeclaration(\"auth.ts\"))\n : Option.none();\n\n const declaration = yield* Declaration.parse({\n target,\n app: app.module.default,\n auth: Option.map(auth, ({ module }) => module.default),\n componentImport: yield* componentImport(),\n }).pipe(\n Result.mapError(\n (error) =>\n new InvalidDeclarationError({\n declarationPath: Declaration.fileOf(error),\n reason: error.message,\n }),\n ),\n Effect.fromResult,\n );\n\n const convexConfigPath = path.join(\n convexDirectory,\n ConvexConfig.CONVEX_CONFIG_FILENAME,\n );\n const authConfigPath = path.join(convexDirectory, \"auth.config.ts\");\n const authImportPath = yield* toModuleImportPath(\n path.relative(convexDirectory, authPath),\n );\n const legacyAuthConfigs = yield* Effect.forEach(\n [authImportPath, authImportPath.replace(/\\.js$/, \"\")],\n (importPath) => templates.authConfig({ authImportPath: importPath }),\n );\n yield* assertOwned(convexConfigPath, \"app.ts\", []);\n yield* assertOwned(authConfigPath, \"auth.ts\", legacyAuthConfigs);\n\n let digest: string | undefined;\n if (target === \"app\") {\n digest = Declaration.digest({\n files: yield* declarationInputs([app, ...Option.toArray(auth)]),\n versions: [\n [\"convex\", yield* packageVersion(\"convex\", projectRoot)],\n [\"@confect/cli generator format\", GENERATOR_FORMAT],\n ],\n });\n const sections = ManifestSections.sections(previous);\n yield* writeFileStringAndLog(\n yield* manifestPath,\n Declaration.manifest(\n declaration,\n sectionDigest(digest, sections),\n sections,\n ),\n );\n }\n yield* writeFileStringAndLog(\n convexConfigPath,\n Declaration.convexConfig(declaration),\n );\n yield* Option.match(declaration.providers, {\n onNone: () =>\n Effect.gen(function* () {\n yield* removeAuthProviders;\n if (yield* fs.exists(authConfigPath)) {\n yield* removePathIfExists(authConfigPath);\n yield* logFileRemoved(authConfigPath);\n }\n }),\n onSome: (providers) =>\n Effect.gen(function* () {\n yield* writeFileStringAndLog(\n authConfigPath,\n Declaration.authConfig(providers),\n );\n yield* writeFileStringAndLog(\n yield* authProvidersPath,\n Declaration.authProviders(providers),\n );\n }),\n });\n return {\n app: App.isApp(appValue) ? Option.some(appValue) : Option.none<App.Any>(),\n digest,\n };\n});\n\n/**\n * Write the declaration's Convex files and manifest from `confect/app.ts`,\n * `confect/env.ts` and `confect/auth.ts`, before anything else is validated. On\n * any failure the previous manifest is removed, so a stale manifest never\n * outlives a declaration that no longer produces it.\n */\nexport const syncDeclaration = Effect.fnUntraced(function* (\n previous: Readonly<Record<string, unknown>>,\n) {\n if (!(yield* isDeclared)) {\n yield* removeManifest;\n yield* removeAuthProviders;\n return { app: Option.none<App.Any>(), digest: undefined };\n }\n return yield* writeDeclaration(previous).pipe(\n Effect.tapError(() =>\n removeManifest.pipe(Effect.andThen(removeAuthProviders)),\n ),\n );\n});\n\n/**\n * Check every HTTP route the backend serves and write `convex/http.ts` from\n * `confect/http.ts`. Runs after generation, because `http.ts` imports its\n * handlers, which import generated services.\n */\nexport const syncDeclaredHttp = (\n app: App.Any,\n sectionFiles: ReadonlyArray<string>,\n) =>\n checkAndWriteHttp(app, sectionFiles).pipe(\n Effect.tapError(() => removeManifest),\n );\n\nconst checkAndWriteHttp = Effect.fnUntraced(function* (\n app: App.Any,\n sectionFiles: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const confectDirectory = yield* ConfectDirectory.get;\n const httpPath = yield* confectPath(\"http.ts\");\n\n const convexHttpPath = path.join(convexDirectory, \"http.ts\");\n if (!(yield* fs.exists(httpPath))) {\n yield* Http.routes(app).pipe(\n Result.mapError(invalid(\"app.ts\")),\n Effect.fromResult,\n );\n yield* removeGenerated(convexHttpPath, [\n yield* templates.http({\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n }),\n ]);\n return Option.none();\n }\n\n const http = (yield* bundleDeclaration(\"http.ts\")).module.default;\n if (!Http.isHttp(http)) {\n return yield* new InvalidDeclarationError({\n declarationPath: \"confect/http.ts\",\n reason: \"it must default-export Http.make(...).\",\n });\n }\n yield* Http.routes(app, http).pipe(\n Result.mapError(invalid(\"http.ts\")),\n Effect.fromResult,\n );\n\n const contents = yield* templates.declaredHttp({\n runtimeImportPath: (yield* fs.exists(\n path.join(confectDirectory, \"runtime.ts\"),\n ))\n ? yield* toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"runtime.ts\"),\n ),\n )\n : undefined,\n schemaImportPath: yield* toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"_generated\", \"schema.ts\"),\n ),\n ),\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n sectionImportPaths: yield* Effect.forEach(sectionFiles, (file) =>\n toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"_generated\", file),\n ),\n ),\n ),\n });\n const change = yield* writeFileString(convexHttpPath, contents);\n return Option.some({ change, convexFilePath: convexHttpPath });\n});\n\nconst DEPLOY_MODULE = \"confectDeploy.ts\";\n\n/**\n * Whether a mounted component's own codegen wrote a deploy module, so a push\n * visits its mounts after its `init`.\n */\nconst hasDeployModule = Effect.fnUntraced(function* (\n component: ConvexConfig.InstalledComponent,\n config: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const directory = path.isAbsolute(component.componentDefinitionPath)\n ? Option.some(component.componentDefinitionPath)\n : Option.map(\n ConvexConfig.resolveDefinition(\n `${component.componentDefinitionPath}/convex.config`,\n config,\n path,\n ),\n path.dirname,\n );\n if (Option.isNone(directory)) return false;\n for (const file of [DEPLOY_MODULE, \"confectDeploy.js\"]) {\n if (yield* fs.exists(path.join(directory.value, file))) return true;\n }\n return false;\n});\n\n/**\n * The export of `confect/<name>.ts` that is the mount named `name`.\n */\nconst mountExport = Effect.fnUntraced(function* (name: string) {\n const fs = yield* FileSystem.FileSystem;\n const file = yield* confectPath(`${name}.ts`);\n const missing = new InvalidDeclarationError({\n declarationPath: \"confect/app.ts\",\n reason: `the mount ${name} runs at every push, so export it from confect/${name}.ts.`,\n });\n if (!(yield* fs.exists(file))) return yield* missing;\n const exports: Record<string, unknown> = (yield* bundleDeclaration(\n `${name}.ts`,\n )).module;\n const found = Object.entries(exports).find(\n ([, value]) =>\n Predicate.hasProperty(value, \"~@confect/core/Mount\") &&\n Mount.data(value as Mount.Any).name === name,\n );\n if (found === undefined) return yield* missing;\n return { file, exportName: found[0] };\n});\n\n/**\n * Write `convex/confectDeploy.ts`, the internal mutation a push calls for the\n * steps it runs at each mount: every mount whose component declares `init` or\n * has a deploy module of its own, in declaration order. Remove it when there\n * are none.\n */\nexport const syncDeployModule = Effect.fnUntraced(function* (\n app: Option.Option<App.Any>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const deployPath = path.join(convexDirectory, DEPLOY_MODULE);\n const config = path.join(\n convexDirectory,\n ConvexConfig.CONVEX_CONFIG_FILENAME,\n );\n const installed =\n Option.isSome(app) && (yield* fs.exists(config))\n ? yield* ConvexConfig.discoverInstalledComponents(\n config,\n yield* displayPath(config),\n (yield* ConvexDirectory.target).kind,\n )\n : [];\n const entries: Array<string> = [];\n const imports: Array<string> = [];\n for (const mount of Option.match(app, {\n onNone: () => [],\n onSome: App.mounts,\n })) {\n const component = installed.find(({ name }) => name === mount.name);\n const nested =\n component !== undefined && (yield* hasDeployModule(component, config));\n if (mount.component.init === undefined && !nested) continue;\n const { file, exportName } = yield* mountExport(mount.name);\n const local = `mount${entries.length}`;\n imports.push(\n `import { ${exportName} as ${local} } from \"${yield* toModuleImportPath(path.relative(convexDirectory, file))}\";`,\n );\n entries.push(` { mount: ${local}, nested: ${nested} },`);\n }\n if (entries.length === 0) return yield* removeGenerated(deployPath, []);\n yield* writeFileStringAndLog(\n deployPath,\n [\n \"// Generated by `confect codegen` from confect/app.ts. Do not edit.\",\n 'import { MountInit } from \"@confect/server\";',\n ...imports,\n \"\",\n \"export const steps = MountInit.mutation([\",\n ...entries,\n \"]);\",\n \"\",\n ].join(\"\\n\"),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAM,mBAAmB;AAEzB,MAAM,cAAc,OAAO,WAAW,WAAW,MAAc;CAE7D,QAAO,OADa,KAAK,KAAA,CACb,KAAK,OAAO,iBAAiB,KAAK,IAAI;AACpD,CAAC;;;;AAKD,MAAa,aAAa,OAAO,IAAI,aAAa;CAEhD,OAAO,QAAO,OADI,WAAW,WAAA,CACZ,OAAO,OAAO,YAAY,QAAQ,CAAC;AACtD,CAAC;AAED,MAAM,cAAc,OAAO,WAAW,WAAW,cAAsB;CACrE,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,YAAY,MAAM,KAAK,SAAS,OAAO,YAAY,KAAK,YAAY,CAAC;AAC9E,CAAC;AAED,MAAM,oBAAoB,OAAO,WAAW,WAAW,MAAc;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,eAAe,OAAO,YAAY,IAAI;CAC5C,OAAO,OAAOA,OAAe,cAAc,EACzC,SAAS,CAACC,sBAAmC,IAAI,CAAC,EACpD,CAAC,CAAC,CAAC,KACD,OAAO,UAAU,UAAU,iBAAiB,WAAW,QAAQ,KAAK,CAAC,CACvE;AACF,CAAC;AAED,MAAM,WAAW,UAAkB,UACjC,IAAI,wBAAwB;CAC1B,iBAAiB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Ac,KAAA,MAAc,OAAO,gBAAgB,WAAW,MAAM;EACtE,IAAI,MAAM,UAAU,SAAS,KAAA,KAAa,CAAC,QAAQ;EACnD,MAAM,EAAE,MAAM,eAAe,OAAO,YAAY,MAAM,IAAI;EAC1D,MAAM,QAAQ,QAAQ,QAAQ;EAC9B,QAAQ,KACN,YAAY,WAAW,MAAM,MAAM,WAAW,OAAO,mBAAmB,KAAK,SAAS,iBAAiB,IAAI,CAAC,EAAE,GAChH;EACA,QAAQ,KAAK,cAAc,MAAM,YAAY,OAAO,IAAI;CAC1D;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO,OAAO,gBAAgB,YAAY,CAAC,CAAC;CACtE,OAAO,sBACL,YACA;EACE;EACA;EACA,GAAG;EACH;EACA;EACA,GAAG;EACH;EACA;CACF,CAAC,CAAC,KAAK,IAAI,CACb;AACF,CAAC"}
|
package/dist/confect/dev.mjs
CHANGED
|
@@ -10,8 +10,8 @@ import { functionPaths } from "../GenerationSnapshot.mjs";
|
|
|
10
10
|
import { preserveComponentOutput } from "../Rollback.mjs";
|
|
11
11
|
import { isDeclared } from "./declaration.mjs";
|
|
12
12
|
import { Operation, Outcome, Phase, forBackend, isDirty, needsDeploymentNotification, plan, shouldRetry, transition } from "../SyncState.mjs";
|
|
13
|
-
import { isRefreshSuccessful, make } from "../Watcher.mjs";
|
|
14
|
-
import { EvaluationError, catchAndLog, generateSnapshot, loadPreviousFunctionPaths, updateDeclarations, validate } from "../Evaluation.mjs";
|
|
13
|
+
import { CoalesceQuiescence, isRefreshSuccessful, make } from "../Watcher.mjs";
|
|
14
|
+
import { EvaluationError, catchAndLog, generateSnapshot, loadPreviousFunctionPaths, prewarmedLayer, updateDeclarations, validate } from "../Evaluation.mjs";
|
|
15
15
|
import * as Effect from "effect/Effect";
|
|
16
16
|
import * as Command from "effect/cli/Command";
|
|
17
17
|
import * as FileSystem from "effect/FileSystem";
|
|
@@ -26,6 +26,8 @@ import * as Ref from "effect/Ref";
|
|
|
26
26
|
import * as String from "effect/String";
|
|
27
27
|
import * as Console from "effect/Console";
|
|
28
28
|
import * as Order from "effect/Order";
|
|
29
|
+
import * as Flag from "effect/cli/Flag";
|
|
30
|
+
import * as Duration from "effect/Duration";
|
|
29
31
|
import * as Equal from "effect/Equal";
|
|
30
32
|
//#region src/confect/dev.ts
|
|
31
33
|
const changeChar = (change) => Match.value(change).pipe(Match.when("Added", () => ({
|
|
@@ -59,8 +61,11 @@ const devHandler = Effect.gen(function* () {
|
|
|
59
61
|
const previousFunctionPaths = yield* loadPreviousFunctionPaths;
|
|
60
62
|
const watcher = yield* make();
|
|
61
63
|
yield* Effect.all([watcher.run, syncLoop(previousFunctionPaths, watcher)], { concurrency: "unbounded" });
|
|
62
|
-
});
|
|
63
|
-
const dev = Command.make("dev",
|
|
64
|
+
}).pipe(Effect.provide(prewarmedLayer));
|
|
65
|
+
const dev = Command.make("dev", {
|
|
66
|
+
...flags,
|
|
67
|
+
coalesceMs: Flag.Int("coalesce-ms").pipe(Flag.filter((ms) => ms >= 0 && ms <= 5e3, () => "Set --coalesce-ms to an integer between 0 and 5000 milliseconds."), Flag.withDefault(Duration.toMillis(CoalesceQuiescence.defaultValue())), Flag.withDescription("Quiet period before processing saved files, in milliseconds."))
|
|
68
|
+
}, ({ coalesceMs }) => devHandler.pipe(Effect.provideService(CoalesceQuiescence, Duration.millis(coalesceMs)))).pipe(Command.withDescription("Start the Confect development server"), Command.provide((options) => layer(options)));
|
|
64
69
|
const esbuildMessageKey = (m) => `${m.location?.file ?? ""}:${m.location?.line ?? ""}:${m.location?.column ?? ""}:${m.text}`;
|
|
65
70
|
const dedupeWatcherMessages = (messages) => pipe(messages, Array.dedupeWith((messageA, messageB) => esbuildMessageKey(messageA) === esbuildMessageKey(messageB)));
|
|
66
71
|
const watcherMessagesSignature = (messages) => pipe(messages, Array.map(esbuildMessageKey), Array.dedupe, Array.sort(Order.String), Array.join("\n"));
|
package/dist/confect/dev.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.mjs","names":["Ansi.green","Ansi.red","Ansi.magenta","Ansi.blackBright","FunctionPaths.diff","Evaluation.loadPreviousFunctionPaths","Watcher.make","DirectoryOptions.flags","DirectoryOptions.layer","SyncState.isDirty","SyncState.forBackend","SyncState.plan","GenerationSnapshot.functionPaths","Evaluation.catchAndLog","Watcher.isRefreshSuccessful","Evaluation.EvaluationError","validate","Evaluation.validate","Evaluation.generateSnapshot","Evaluation.updateDeclarations","SyncState.transition","SyncState.shouldRetry","SyncState.needsDeploymentNotification"],"sources":["../../src/confect/dev.ts"],"sourcesContent":["import * as Command from \"effect/cli/Command\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as Equal from \"effect/Equal\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Ref from \"effect/Ref\";\nimport * as Result from \"effect/Result\";\nimport * as String from \"effect/String\";\nimport type * as esbuild from \"esbuild\";\nimport * as Ansi from \"../Ansi.js\";\nimport { renderCodegenError } from \"../CodegenError.js\";\nimport * as SyncState from \"../SyncState.js\";\nimport type { OptionalFile } from \"../EntryPoint.js\";\nimport * as Watcher from \"../Watcher.js\";\nimport * as Evaluation from \"../Evaluation.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as DirectoryOptions from \"../DirectoryOptions.js\";\nimport * as FunctionPaths from \"../FunctionPaths.js\";\nimport * as GenerationSnapshot from \"../GenerationSnapshot.js\";\nimport type { ImplModulePath } from \"../ImplModulePath.js\";\nimport type * as GroupPath from \"../GroupPath.js\";\nimport type * as GroupPaths from \"../GroupPaths.js\";\nimport {\n logCoalescedBuildErrors,\n logCoalescedBuildWarnings,\n logFunctionAdded,\n logFunctionRemoved,\n logPending,\n logSuccess,\n} from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport { preserveComponentOutput } from \"../Rollback.js\";\nimport {\n generateAuthConfig,\n generateCrons,\n generateHttp,\n touchConvexSchema,\n} from \"../utils.js\";\nimport { isDeclared } from \"./declaration.js\";\n\nconst changeChar = (change: \"Added\" | \"Removed\" | \"Modified\") =>\n Match.value(change).pipe(\n Match.when(\"Added\", () => ({ char: \"+\", color: Ansi.green })),\n Match.when(\"Removed\", () => ({ char: \"-\", color: Ansi.red })),\n Match.when(\"Modified\", () => ({ char: \"~\", color: Ansi.magenta })),\n Match.exhaustive,\n );\n\nconst logFileChangeIndented = Effect.fnUntraced(function* (\n change: \"Added\" | \"Removed\" | \"Modified\",\n fullPath: string,\n) {\n const projectRoot = yield* ProjectRoot.get;\n const path = yield* Path.Path;\n\n const prefix = projectRoot + path.sep;\n const suffix = pipe(fullPath, String.startsWith(prefix))\n ? pipe(fullPath, String.slice(prefix.length))\n : fullPath;\n\n const { char, color } = changeChar(change);\n\n yield* Console.log(\n `${color(char)} ${Ansi.blackBright(prefix)}${color(suffix)}`,\n );\n});\n\nconst logFunctionPathDiff = Effect.fnUntraced(function* (\n previous: FunctionPaths.FunctionPaths,\n current: FunctionPaths.FunctionPaths,\n) {\n const {\n functionsAdded,\n functionsRemoved,\n groupsRemoved,\n groupsAdded,\n groupsChanged,\n } = FunctionPaths.diff(previous, current);\n\n const logForGroups = (\n groupPaths: GroupPaths.GroupPaths,\n fnPaths: FunctionPaths.FunctionPaths,\n logFn: typeof logFunctionAdded,\n ) =>\n Effect.forEach(groupPaths, (gp) =>\n Effect.forEach(\n Array.fromIterable(\n HashSet.filter(fnPaths, (fp) => Equal.equals(fp.groupPath, gp)),\n ),\n logFn,\n ),\n );\n\n yield* logForGroups(groupsRemoved, functionsRemoved, logFunctionRemoved);\n yield* logForGroups(groupsAdded, functionsAdded, logFunctionAdded);\n yield* Effect.forEach(\n groupsChanged,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsAdded, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionAdded,\n );\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsRemoved, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionRemoved,\n );\n }),\n );\n});\n\nexport const devHandler = Effect.gen(function* () {\n yield* logPending(\"Performing initial sync…\");\n const previousFunctionPaths = yield* Evaluation.loadPreviousFunctionPaths;\n\n const watcher = yield* Watcher.make();\n\n yield* Effect.all([watcher.run, syncLoop(previousFunctionPaths, watcher)], {\n concurrency: \"unbounded\",\n });\n});\n\nexport const dev = Command.make(\n \"dev\",\n DirectoryOptions.flags,\n () => devHandler,\n).pipe(\n Command.withDescription(\"Start the Confect development server\"),\n Command.provide(DirectoryOptions.layer),\n);\n\nconst esbuildMessageKey = (m: esbuild.Message): string =>\n `${m.location?.file ?? \"\"}:${m.location?.line ?? \"\"}:${m.location?.column ?? \"\"}:${m.text}`;\n\nconst dedupeWatcherMessages = (\n messages: ReadonlyArray<esbuild.Message>,\n): ReadonlyArray<esbuild.Message> =>\n pipe(\n messages,\n Array.dedupeWith(\n (messageA, messageB) =>\n esbuildMessageKey(messageA) === esbuildMessageKey(messageB),\n ),\n );\n\nconst watcherMessagesSignature = (\n messages: ReadonlyArray<esbuild.Message>,\n): string =>\n pipe(\n messages,\n Array.map(esbuildMessageKey),\n Array.dedupe,\n Array.sort(Order.String),\n Array.join(\"\\n\"),\n );\n\n/**\n * Log any watcher messages (errors or warnings) that haven't already been\n * logged at their current signature. Suppresses the per-watcher fanout that\n * happens when one root cause (e.g. a missing import) breaks every entry\n * point's build at the same source location.\n */\nconst logChangedWatcherMessages = Effect.fnUntraced(function* (\n messages: ReadonlyArray<esbuild.Message>,\n lastLoggedSignatureRef: Ref.Ref<string>,\n log: (messages: ReadonlyArray<esbuild.Message>) => Effect.Effect<void>,\n) {\n const signature = watcherMessagesSignature(messages);\n const previous = yield* Ref.get(lastLoggedSignatureRef);\n if (signature === previous) return;\n yield* Ref.set(lastLoggedSignatureRef, signature);\n if (messages.length === 0) return;\n yield* log(dedupeWatcherMessages(messages));\n});\n\nconst syncLoop = Effect.fnUntraced(function* (\n initialFunctionPaths: FunctionPaths.FunctionPaths,\n watcher: Watcher.Watcher,\n) {\n const functionPathsRef = yield* Ref.make(initialFunctionPaths);\n const lastLoggedErrorsRef = yield* Ref.make<string>(\"\");\n const lastLoggedWarningsRef = yield* Ref.make<string>(\"\");\n const phaseRef = yield* Ref.make<SyncState.Phase>(\n SyncState.Phase.Bootstrapping(),\n );\n const optionalPendingRef = yield* Ref.make(HashSet.empty<OptionalFile>());\n const logMessages = Effect.gen(function* () {\n const { errors, warnings } = yield* watcher.diagnostics;\n yield* logChangedWatcherMessages(\n errors,\n lastLoggedErrorsRef,\n logCoalescedBuildErrors,\n );\n yield* logChangedWatcherMessages(\n warnings,\n lastLoggedWarningsRef,\n logCoalescedBuildWarnings,\n );\n });\n\n return yield* Effect.forever(\n Effect.gen(function* () {\n yield* Effect.logDebug(\"Running sync loop…\");\n const taken = yield* watcher.next;\n\n const phase = yield* Ref.get(phaseRef);\n const firstSync = SyncState.Phase.$is(\"Bootstrapping\")(phase);\n if (!firstSync) yield* logMessages;\n\n if (!SyncState.isDirty(taken)) return;\n\n const declared = yield* isDeclared;\n const pending = SyncState.forBackend(\n {\n ...taken,\n optional: yield* Ref.updateAndGet(\n optionalPendingRef,\n HashSet.union(taken.optional),\n ),\n },\n {\n declared,\n component: (yield* ConvexDirectory.target).kind === \"component\",\n },\n );\n const optional = pending.optional;\n const operation = SyncState.plan(phase, pending);\n yield* Effect.logDebug(\"Planned development sync\").pipe(\n Effect.annotateLogs({\n phase: phase._tag,\n work: pending.work._tag,\n operation: operation._tag,\n }),\n );\n if (\n !firstSync &&\n !(\n SyncState.Operation.$is(\"Validate\")(operation) &&\n operation.paths.length === 0\n )\n )\n yield* logPending(\"Dependencies may have changed, reloading…\");\n\n const regenerate = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n Effect.gen(function* () {\n const current = yield* generation.pipe(\n Effect.tap((snapshot) =>\n Effect.gen(function* () {\n const nextFunctionPaths =\n GenerationSnapshot.functionPaths(snapshot);\n const previous = yield* Ref.get(functionPathsRef);\n yield* logFunctionPathDiff(previous, nextFunctionPaths);\n yield* Ref.set(functionPathsRef, nextFunctionPaths);\n }),\n ),\n Evaluation.catchAndLog,\n );\n if (Option.isNone(current)) {\n return SyncState.Outcome.GenerationFailed();\n }\n const refreshed = yield* watcher.refresh.pipe(Effect.result);\n if (Result.isFailure(refreshed)) {\n yield* Console.error(\n `Dependency watcher could not ${refreshed.failure.operation}: ${globalThis.String(refreshed.failure.cause)}`,\n );\n return SyncState.Outcome.ReconciliationFailed();\n }\n if (!Watcher.isRefreshSuccessful(refreshed.success)) {\n yield* logMessages;\n return SyncState.Outcome.ReconciliationFailed();\n }\n return SyncState.Outcome.Succeeded({ snapshot: current.value });\n });\n const preserved = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n preserveComponentOutput(generation, watcher.duringRestore).pipe(\n Effect.tapErrorTag(\n \"ComponentNodeGroupError\",\n () => watcher.discardRestoreEchoes,\n ),\n Effect.catchTags({\n RemoveBusyError: (error) =>\n Effect.fail(\n new Evaluation.EvaluationError({\n diagnostic: renderCodegenError(error),\n }),\n ),\n // Output that cannot be restored leaves nothing to serve.\n PlatformError: Effect.die,\n }),\n );\n const validate = (\n paths: ReadonlyArray<ImplModulePath>,\n snapshot: GenerationSnapshot.GenerationSnapshot,\n ) =>\n Effect.gen(function* () {\n if (Array.isReadonlyArrayNonEmpty(paths)) {\n const validated = yield* Evaluation.validate(paths).pipe(\n Evaluation.catchAndLog,\n );\n if (Option.isNone(validated)) {\n return SyncState.Outcome.ValidationFailed({ paths, snapshot });\n }\n }\n return SyncState.Outcome.Succeeded({ snapshot });\n });\n const outcome = yield* SyncState.Operation.$match(operation, {\n Generate: () => regenerate(preserved(Evaluation.generateSnapshot)),\n Validate: ({ paths, snapshot }) => validate(paths, snapshot),\n Update: ({ snapshot, declarations, paths }) =>\n regenerate(\n preserved(\n Evaluation.updateDeclarations(snapshot, declarations, paths),\n ),\n ),\n });\n yield* Ref.set(phaseRef, SyncState.transition(outcome));\n if (SyncState.shouldRetry(phase, outcome)) {\n yield* watcher.requestRetry;\n }\n if (!SyncState.Outcome.$is(\"Succeeded\")(outcome)) return;\n\n const dirtyOptionalFiles = [\n ...(HashSet.has(optional, \"Http\")\n ? [syncOptionalFile(generateHttp, \"http.ts\")]\n : []),\n ...(HashSet.has(optional, \"Crons\")\n ? [syncOptionalFile(generateCrons, \"crons.ts\")]\n : []),\n ...(HashSet.has(optional, \"Auth\")\n ? [syncOptionalFile(generateAuthConfig, \"auth.config.ts\")]\n : []),\n ];\n\n yield* Array.isReadonlyArrayNonEmpty(dirtyOptionalFiles)\n ? Effect.all(dirtyOptionalFiles, { concurrency: \"unbounded\" })\n : Effect.void;\n yield* Ref.set(optionalPendingRef, HashSet.empty());\n\n if (SyncState.needsDeploymentNotification(phase))\n yield* touchConvexSchema;\n\n if (!SyncState.isDirty(yield* watcher.pending)) {\n yield* logSuccess(\"Generated files are up-to-date\");\n }\n }),\n );\n});\n\nconst syncOptionalFile = (generate: typeof generateHttp, convexFile: string) =>\n pipe(\n generate,\n Effect.andThen(\n Option.match({\n onSome: ({ change, convexFilePath }) =>\n Match.value(change).pipe(\n Match.when(\"Unchanged\", () => Effect.void),\n Match.whenOr(\"Added\", \"Modified\", (addedOrModified) =>\n logFileChangeIndented(addedOrModified, convexFilePath),\n ),\n Match.exhaustive,\n ),\n onNone: () =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const convexFilePath = path.join(convexDirectory, convexFile);\n\n if (yield* fs.exists(convexFilePath)) {\n yield* fs.remove(convexFilePath);\n yield* logFileChangeIndented(\"Removed\", convexFilePath);\n }\n }),\n }),\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,cAAc,WAClB,MAAM,MAAM,MAAM,CAAC,CAAC,KAClB,MAAM,KAAK,gBAAgB;CAAE,MAAM;CAAK,OAAOA;AAAW,EAAE,GAC5D,MAAM,KAAK,kBAAkB;CAAE,MAAM;CAAK,OAAOC;AAAS,EAAE,GAC5D,MAAM,KAAK,mBAAmB;CAAE,MAAM;CAAK,OAAOC;AAAa,EAAE,GACjE,MAAM,UACR;AAEF,MAAM,wBAAwB,OAAO,WAAW,WAC9C,QACA,UACA;CAIA,MAAM,UAAS,OAHY,YAAY,QAGV,OAFT,KAAK,KAAA,CAES;CAClC,MAAM,SAAS,KAAK,UAAU,OAAO,WAAW,MAAM,CAAC,IACnD,KAAK,UAAU,OAAO,MAAM,OAAO,MAAM,CAAC,IAC1C;CAEJ,MAAM,EAAE,MAAM,UAAU,WAAW,MAAM;CAEzC,OAAO,QAAQ,IACb,GAAG,MAAM,IAAI,EAAE,GAAGC,YAAiB,MAAM,IAAI,MAAM,MAAM,GAC3D;AACF,CAAC;AAED,MAAM,sBAAsB,OAAO,WAAW,WAC5C,UACA,SACA;CACA,MAAM,EACJ,gBACA,kBACA,eACA,aACA,kBACEC,KAAmB,UAAU,OAAO;CAExC,MAAM,gBACJ,YACA,SACA,UAEA,OAAO,QAAQ,aAAa,OAC1B,OAAO,QACL,MAAM,aACJ,QAAQ,OAAO,UAAU,OAAO,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC,CAChE,GACA,KACF,CACF;CAEF,OAAO,aAAa,eAAe,kBAAkB,kBAAkB;CACvE,OAAO,aAAa,aAAa,gBAAgB,gBAAgB;CACjE,OAAO,OA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MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,OAAO,SAAS,aAAa,oBACjC,sBAAsB,iBAAiB,cAAc,CACvD,GACA,MAAM,UACR;CACF,cACE,OAAO,IAAI,aAAa;EACtB,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,kBAAkB,OAAO,gBAAgB;EAC/C,MAAM,iBAAiB,KAAK,KAAK,iBAAiB,UAAU;EAE5D,IAAI,OAAO,GAAG,OAAO,cAAc,GAAG;GACpC,OAAO,GAAG,OAAO,cAAc;GAC/B,OAAO,sBAAsB,WAAW,cAAc;EACxD;CACF,CAAC;AACL,CAAC,CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"dev.mjs","names":["Ansi.green","Ansi.red","Ansi.magenta","Ansi.blackBright","FunctionPaths.diff","Evaluation.loadPreviousFunctionPaths","Watcher.make","Evaluation.prewarmedLayer","DirectoryOptions.flags","Watcher.CoalesceQuiescence","DirectoryOptions.layer","SyncState.isDirty","SyncState.forBackend","SyncState.plan","GenerationSnapshot.functionPaths","Evaluation.catchAndLog","Watcher.isRefreshSuccessful","Evaluation.EvaluationError","validate","Evaluation.validate","Evaluation.generateSnapshot","Evaluation.updateDeclarations","SyncState.transition","SyncState.shouldRetry","SyncState.needsDeploymentNotification"],"sources":["../../src/confect/dev.ts"],"sourcesContent":["import * as Command from \"effect/cli/Command\";\nimport * as Flag from \"effect/cli/Flag\";\nimport * as Duration from \"effect/Duration\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as Equal from \"effect/Equal\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Ref from \"effect/Ref\";\nimport * as Result from \"effect/Result\";\nimport * as String from \"effect/String\";\nimport type * as esbuild from \"esbuild\";\nimport * as Ansi from \"../Ansi.js\";\nimport { renderCodegenError } from \"../CodegenError.js\";\nimport * as SyncState from \"../SyncState.js\";\nimport type { OptionalFile } from \"../EntryPoint.js\";\nimport * as Watcher from \"../Watcher.js\";\nimport * as Evaluation from \"../Evaluation.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as DirectoryOptions from \"../DirectoryOptions.js\";\nimport * as FunctionPaths from \"../FunctionPaths.js\";\nimport * as GenerationSnapshot from \"../GenerationSnapshot.js\";\nimport type { ImplModulePath } from \"../ImplModulePath.js\";\nimport type * as GroupPath from \"../GroupPath.js\";\nimport type * as GroupPaths from \"../GroupPaths.js\";\nimport {\n logCoalescedBuildErrors,\n logCoalescedBuildWarnings,\n logFunctionAdded,\n logFunctionRemoved,\n logPending,\n logSuccess,\n} from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport { preserveComponentOutput } from \"../Rollback.js\";\nimport {\n generateAuthConfig,\n generateCrons,\n generateHttp,\n touchConvexSchema,\n} from \"../utils.js\";\nimport { isDeclared } from \"./declaration.js\";\n\nconst changeChar = (change: \"Added\" | \"Removed\" | \"Modified\") =>\n Match.value(change).pipe(\n Match.when(\"Added\", () => ({ char: \"+\", color: Ansi.green })),\n Match.when(\"Removed\", () => ({ char: \"-\", color: Ansi.red })),\n Match.when(\"Modified\", () => ({ char: \"~\", color: Ansi.magenta })),\n Match.exhaustive,\n );\n\nconst logFileChangeIndented = Effect.fnUntraced(function* (\n change: \"Added\" | \"Removed\" | \"Modified\",\n fullPath: string,\n) {\n const projectRoot = yield* ProjectRoot.get;\n const path = yield* Path.Path;\n\n const prefix = projectRoot + path.sep;\n const suffix = pipe(fullPath, String.startsWith(prefix))\n ? pipe(fullPath, String.slice(prefix.length))\n : fullPath;\n\n const { char, color } = changeChar(change);\n\n yield* Console.log(\n `${color(char)} ${Ansi.blackBright(prefix)}${color(suffix)}`,\n );\n});\n\nconst logFunctionPathDiff = Effect.fnUntraced(function* (\n previous: FunctionPaths.FunctionPaths,\n current: FunctionPaths.FunctionPaths,\n) {\n const {\n functionsAdded,\n functionsRemoved,\n groupsRemoved,\n groupsAdded,\n groupsChanged,\n } = FunctionPaths.diff(previous, current);\n\n const logForGroups = (\n groupPaths: GroupPaths.GroupPaths,\n fnPaths: FunctionPaths.FunctionPaths,\n logFn: typeof logFunctionAdded,\n ) =>\n Effect.forEach(groupPaths, (gp) =>\n Effect.forEach(\n Array.fromIterable(\n HashSet.filter(fnPaths, (fp) => Equal.equals(fp.groupPath, gp)),\n ),\n logFn,\n ),\n );\n\n yield* logForGroups(groupsRemoved, functionsRemoved, logFunctionRemoved);\n yield* logForGroups(groupsAdded, functionsAdded, logFunctionAdded);\n yield* Effect.forEach(\n groupsChanged,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsAdded, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionAdded,\n );\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsRemoved, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionRemoved,\n );\n }),\n );\n});\n\nexport const devHandler = Effect.gen(function* () {\n yield* logPending(\"Performing initial sync…\");\n const previousFunctionPaths = yield* Evaluation.loadPreviousFunctionPaths;\n\n const watcher = yield* Watcher.make();\n\n yield* Effect.all([watcher.run, syncLoop(previousFunctionPaths, watcher)], {\n concurrency: \"unbounded\",\n });\n}).pipe(Effect.provide(Evaluation.prewarmedLayer));\n\nexport const dev = Command.make(\n \"dev\",\n {\n ...DirectoryOptions.flags,\n coalesceMs: Flag.Int(\"coalesce-ms\").pipe(\n Flag.filter(\n (ms) => ms >= 0 && ms <= 5000,\n () =>\n \"Set --coalesce-ms to an integer between 0 and 5000 milliseconds.\",\n ),\n Flag.withDefault(\n Duration.toMillis(Watcher.CoalesceQuiescence.defaultValue()),\n ),\n Flag.withDescription(\n \"Quiet period before processing saved files, in milliseconds.\",\n ),\n ),\n },\n ({ coalesceMs }) =>\n devHandler.pipe(\n Effect.provideService(\n Watcher.CoalesceQuiescence,\n Duration.millis(coalesceMs),\n ),\n ),\n).pipe(\n Command.withDescription(\"Start the Confect development server\"),\n Command.provide(\n (options: { componentDir: Option.Option<string>; coalesceMs: number }) =>\n DirectoryOptions.layer(options),\n ),\n);\n\nconst esbuildMessageKey = (m: esbuild.Message): string =>\n `${m.location?.file ?? \"\"}:${m.location?.line ?? \"\"}:${m.location?.column ?? \"\"}:${m.text}`;\n\nconst dedupeWatcherMessages = (\n messages: ReadonlyArray<esbuild.Message>,\n): ReadonlyArray<esbuild.Message> =>\n pipe(\n messages,\n Array.dedupeWith(\n (messageA, messageB) =>\n esbuildMessageKey(messageA) === esbuildMessageKey(messageB),\n ),\n );\n\nconst watcherMessagesSignature = (\n messages: ReadonlyArray<esbuild.Message>,\n): string =>\n pipe(\n messages,\n Array.map(esbuildMessageKey),\n Array.dedupe,\n Array.sort(Order.String),\n Array.join(\"\\n\"),\n );\n\n/**\n * Log any watcher messages (errors or warnings) that haven't already been\n * logged at their current signature. Suppresses the per-watcher fanout that\n * happens when one root cause (e.g. a missing import) breaks every entry\n * point's build at the same source location.\n */\nconst logChangedWatcherMessages = Effect.fnUntraced(function* (\n messages: ReadonlyArray<esbuild.Message>,\n lastLoggedSignatureRef: Ref.Ref<string>,\n log: (messages: ReadonlyArray<esbuild.Message>) => Effect.Effect<void>,\n) {\n const signature = watcherMessagesSignature(messages);\n const previous = yield* Ref.get(lastLoggedSignatureRef);\n if (signature === previous) return;\n yield* Ref.set(lastLoggedSignatureRef, signature);\n if (messages.length === 0) return;\n yield* log(dedupeWatcherMessages(messages));\n});\n\nconst syncLoop = Effect.fnUntraced(function* (\n initialFunctionPaths: FunctionPaths.FunctionPaths,\n watcher: Watcher.Watcher,\n) {\n const functionPathsRef = yield* Ref.make(initialFunctionPaths);\n const lastLoggedErrorsRef = yield* Ref.make<string>(\"\");\n const lastLoggedWarningsRef = yield* Ref.make<string>(\"\");\n const phaseRef = yield* Ref.make<SyncState.Phase>(\n SyncState.Phase.Bootstrapping(),\n );\n const optionalPendingRef = yield* Ref.make(HashSet.empty<OptionalFile>());\n const logMessages = Effect.gen(function* () {\n const { errors, warnings } = yield* watcher.diagnostics;\n yield* logChangedWatcherMessages(\n errors,\n lastLoggedErrorsRef,\n logCoalescedBuildErrors,\n );\n yield* logChangedWatcherMessages(\n warnings,\n lastLoggedWarningsRef,\n logCoalescedBuildWarnings,\n );\n });\n\n return yield* Effect.forever(\n Effect.gen(function* () {\n yield* Effect.logDebug(\"Running sync loop…\");\n const taken = yield* watcher.next;\n\n const phase = yield* Ref.get(phaseRef);\n const firstSync = SyncState.Phase.$is(\"Bootstrapping\")(phase);\n if (!firstSync) yield* logMessages;\n\n if (!SyncState.isDirty(taken)) return;\n\n const declared = yield* isDeclared;\n const pending = SyncState.forBackend(\n {\n ...taken,\n optional: yield* Ref.updateAndGet(\n optionalPendingRef,\n HashSet.union(taken.optional),\n ),\n },\n {\n declared,\n component: (yield* ConvexDirectory.target).kind === \"component\",\n },\n );\n const optional = pending.optional;\n const operation = SyncState.plan(phase, pending);\n yield* Effect.logDebug(\"Planned development sync\").pipe(\n Effect.annotateLogs({\n phase: phase._tag,\n work: pending.work._tag,\n operation: operation._tag,\n }),\n );\n if (\n !firstSync &&\n !(\n SyncState.Operation.$is(\"Validate\")(operation) &&\n operation.paths.length === 0\n )\n )\n yield* logPending(\"Dependencies may have changed, reloading…\");\n\n const regenerate = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n Effect.gen(function* () {\n const current = yield* generation.pipe(\n Effect.tap((snapshot) =>\n Effect.gen(function* () {\n const nextFunctionPaths =\n GenerationSnapshot.functionPaths(snapshot);\n const previous = yield* Ref.get(functionPathsRef);\n yield* logFunctionPathDiff(previous, nextFunctionPaths);\n yield* Ref.set(functionPathsRef, nextFunctionPaths);\n }),\n ),\n Evaluation.catchAndLog,\n );\n if (Option.isNone(current)) {\n return SyncState.Outcome.GenerationFailed();\n }\n const refreshed = yield* watcher.refresh.pipe(Effect.result);\n if (Result.isFailure(refreshed)) {\n yield* Console.error(\n `Dependency watcher could not ${refreshed.failure.operation}: ${globalThis.String(refreshed.failure.cause)}`,\n );\n return SyncState.Outcome.ReconciliationFailed();\n }\n if (!Watcher.isRefreshSuccessful(refreshed.success)) {\n yield* logMessages;\n return SyncState.Outcome.ReconciliationFailed();\n }\n return SyncState.Outcome.Succeeded({ snapshot: current.value });\n });\n const preserved = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n preserveComponentOutput(generation, watcher.duringRestore).pipe(\n Effect.tapErrorTag(\n \"ComponentNodeGroupError\",\n () => watcher.discardRestoreEchoes,\n ),\n Effect.catchTags({\n RemoveBusyError: (error) =>\n Effect.fail(\n new Evaluation.EvaluationError({\n diagnostic: renderCodegenError(error),\n }),\n ),\n // Output that cannot be restored leaves nothing to serve.\n PlatformError: Effect.die,\n }),\n );\n const validate = (\n paths: ReadonlyArray<ImplModulePath>,\n snapshot: GenerationSnapshot.GenerationSnapshot,\n ) =>\n Effect.gen(function* () {\n if (Array.isReadonlyArrayNonEmpty(paths)) {\n const validated = yield* Evaluation.validate(paths).pipe(\n Evaluation.catchAndLog,\n );\n if (Option.isNone(validated)) {\n return SyncState.Outcome.ValidationFailed({ paths, snapshot });\n }\n }\n return SyncState.Outcome.Succeeded({ snapshot });\n });\n const outcome = yield* SyncState.Operation.$match(operation, {\n Generate: () => regenerate(preserved(Evaluation.generateSnapshot)),\n Validate: ({ paths, snapshot }) => validate(paths, snapshot),\n Update: ({ snapshot, declarations, paths }) =>\n regenerate(\n preserved(\n Evaluation.updateDeclarations(snapshot, declarations, paths),\n ),\n ),\n });\n yield* Ref.set(phaseRef, SyncState.transition(outcome));\n if (SyncState.shouldRetry(phase, outcome)) {\n yield* watcher.requestRetry;\n }\n if (!SyncState.Outcome.$is(\"Succeeded\")(outcome)) return;\n\n const dirtyOptionalFiles = [\n ...(HashSet.has(optional, \"Http\")\n ? [syncOptionalFile(generateHttp, \"http.ts\")]\n : []),\n ...(HashSet.has(optional, \"Crons\")\n ? [syncOptionalFile(generateCrons, \"crons.ts\")]\n : []),\n ...(HashSet.has(optional, \"Auth\")\n ? [syncOptionalFile(generateAuthConfig, \"auth.config.ts\")]\n : []),\n ];\n\n yield* Array.isReadonlyArrayNonEmpty(dirtyOptionalFiles)\n ? Effect.all(dirtyOptionalFiles, { concurrency: \"unbounded\" })\n : Effect.void;\n yield* Ref.set(optionalPendingRef, HashSet.empty());\n\n if (SyncState.needsDeploymentNotification(phase))\n yield* touchConvexSchema;\n\n if (!SyncState.isDirty(yield* watcher.pending)) {\n yield* logSuccess(\"Generated files are up-to-date\");\n }\n }),\n );\n});\n\nconst syncOptionalFile = (generate: typeof generateHttp, convexFile: string) =>\n pipe(\n generate,\n Effect.andThen(\n Option.match({\n onSome: ({ change, convexFilePath }) =>\n Match.value(change).pipe(\n Match.when(\"Unchanged\", () => Effect.void),\n Match.whenOr(\"Added\", \"Modified\", (addedOrModified) =>\n logFileChangeIndented(addedOrModified, convexFilePath),\n ),\n Match.exhaustive,\n ),\n onNone: () =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const convexFilePath = path.join(convexDirectory, convexFile);\n\n if (yield* fs.exists(convexFilePath)) {\n yield* fs.remove(convexFilePath);\n yield* logFileChangeIndented(\"Removed\", convexFilePath);\n }\n }),\n }),\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,cAAc,WAClB,MAAM,MAAM,MAAM,CAAC,CAAC,KAClB,MAAM,KAAK,g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