@gaganref/confect-cli 10.3.1-fork.96 → 10.6.0-fork.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/Ansi.mjs +1 -2
  3. package/dist/BuildError.mjs +5 -5
  4. package/dist/BuildError.mjs.map +1 -1
  5. package/dist/Bundler.mjs +103 -76
  6. package/dist/Bundler.mjs.map +1 -1
  7. package/dist/CodeBlockWriter.mjs +1 -2
  8. package/dist/CodegenError.mjs +27 -17
  9. package/dist/CodegenError.mjs.map +1 -1
  10. package/dist/ConfectDirectory.mjs +8 -3
  11. package/dist/ConfectDirectory.mjs.map +1 -1
  12. package/dist/ConvexConfig.mjs +23 -15
  13. package/dist/ConvexConfig.mjs.map +1 -1
  14. package/dist/ConvexDirectory.mjs +6 -4
  15. package/dist/ConvexDirectory.mjs.map +1 -1
  16. package/dist/Declaration.mjs +92 -56
  17. package/dist/Declaration.mjs.map +1 -1
  18. package/dist/DirectoryOptions.mjs +13 -8
  19. package/dist/DirectoryOptions.mjs.map +1 -1
  20. package/dist/DocName.mjs +1 -2
  21. package/dist/EntryPoint.mjs +17 -15
  22. package/dist/EntryPoint.mjs.map +1 -1
  23. package/dist/Evaluation.mjs +24 -13
  24. package/dist/Evaluation.mjs.map +1 -1
  25. package/dist/EvaluationWorker.mjs +5 -6
  26. package/dist/EvaluationWorker.mjs.map +1 -1
  27. package/dist/FunctionModule.mjs +85 -47
  28. package/dist/FunctionModule.mjs.map +1 -1
  29. package/dist/FunctionPath.mjs +1 -2
  30. package/dist/FunctionPath.mjs.map +1 -1
  31. package/dist/FunctionPaths.mjs +2 -3
  32. package/dist/GenerationSnapshot.mjs +30 -22
  33. package/dist/GenerationSnapshot.mjs.map +1 -1
  34. package/dist/GroupPath.mjs +6 -3
  35. package/dist/GroupPath.mjs.map +1 -1
  36. package/dist/GroupPaths.mjs +1 -2
  37. package/dist/ImplModulePath.mjs +1 -2
  38. package/dist/Json.mjs +13 -0
  39. package/dist/Json.mjs.map +1 -0
  40. package/dist/LeafModule.mjs +121 -41
  41. package/dist/LeafModule.mjs.map +1 -1
  42. package/dist/ManifestSections.mjs +23 -19
  43. package/dist/ManifestSections.mjs.map +1 -1
  44. package/dist/PackageSelfReference.mjs +32 -0
  45. package/dist/PackageSelfReference.mjs.map +1 -0
  46. package/dist/ProjectRoot.mjs +11 -3
  47. package/dist/ProjectRoot.mjs.map +1 -1
  48. package/dist/RelativeModulePath.mjs +1 -2
  49. package/dist/Remove.mjs +2 -3
  50. package/dist/Remove.mjs.map +1 -1
  51. package/dist/RestoreWatcher.mjs +1 -2
  52. package/dist/Rollback.mjs +7 -6
  53. package/dist/Rollback.mjs.map +1 -1
  54. package/dist/SectionFiles.mjs +77 -48
  55. package/dist/SectionFiles.mjs.map +1 -1
  56. package/dist/SnapshotError.mjs +3 -3
  57. package/dist/SnapshotError.mjs.map +1 -1
  58. package/dist/SpecAssemblyNode.mjs +1 -2
  59. package/dist/SpecModulePath.mjs +4 -4
  60. package/dist/SpecModulePath.mjs.map +1 -1
  61. package/dist/SyncState.mjs +3 -4
  62. package/dist/SyncState.mjs.map +1 -1
  63. package/dist/TableModule.mjs +18 -10
  64. package/dist/TableModule.mjs.map +1 -1
  65. package/dist/TableModulePath.mjs +3 -3
  66. package/dist/TableModulePath.mjs.map +1 -1
  67. package/dist/TypeScriptConfig.mjs +135 -0
  68. package/dist/TypeScriptConfig.mjs.map +1 -0
  69. package/dist/WatchBuild.mjs +107 -32
  70. package/dist/WatchBuild.mjs.map +1 -1
  71. package/dist/WatchGraph.mjs +4 -4
  72. package/dist/WatchGraph.mjs.map +1 -1
  73. package/dist/WatchTopology.mjs +5 -4
  74. package/dist/WatchTopology.mjs.map +1 -1
  75. package/dist/Watcher.mjs +179 -108
  76. package/dist/Watcher.mjs.map +1 -1
  77. package/dist/cliApp.mjs +5 -3
  78. package/dist/cliApp.mjs.map +1 -1
  79. package/dist/confect/codegen.mjs +95 -53
  80. package/dist/confect/codegen.mjs.map +1 -1
  81. package/dist/confect/declaration.mjs +76 -42
  82. package/dist/confect/declaration.mjs.map +1 -1
  83. package/dist/confect/dev.mjs +18 -12
  84. package/dist/confect/dev.mjs.map +1 -1
  85. package/dist/confect.mjs +4 -2
  86. package/dist/confect.mjs.map +1 -1
  87. package/dist/index.mjs +1 -2
  88. package/dist/log.mjs +13 -5
  89. package/dist/log.mjs.map +1 -1
  90. package/dist/package.json.mjs +5 -0
  91. package/dist/package.json.mjs.map +1 -0
  92. package/dist/templates.mjs +34 -22
  93. package/dist/templates.mjs.map +1 -1
  94. package/dist/utils.mjs +36 -5
  95. package/dist/utils.mjs.map +1 -1
  96. package/package.json +10 -10
  97. package/dist/package.mjs +0 -6
  98. package/dist/package.mjs.map +0 -1
@@ -1,37 +1,42 @@
1
1
  import { fromBundlerError } from "./BuildError.mjs";
2
- import { logFileRemoved } from "./log.mjs";
3
2
  import { bundle } from "./Bundler.mjs";
4
3
  import { InvalidManifestSectionError, logCodegenError } from "./CodegenError.mjs";
5
4
  import { ConfectDirectory } from "./ConfectDirectory.mjs";
6
- import { removePathIfExists, toPosixPath, writeFileStringAndLog } from "./utils.mjs";
7
5
  import { componentConfigPlugin } from "./ConvexConfig.mjs";
6
+ import { logFileRemoved } from "./log.mjs";
7
+ import { removePathIfExists, toPosixPath, writeFileStringAndLog } from "./utils.mjs";
8
+ import { quote } from "./Json.mjs";
8
9
  import * as Effect from "effect/Effect";
9
10
  import * as FileSystem from "effect/FileSystem";
10
11
  import * as Path from "effect/Path";
12
+ import * as Arr from "effect/Array";
11
13
  import * as Result from "effect/Result";
14
+ import { pipe } from "effect/Function";
12
15
  import * as Option from "effect/Option";
16
+ import * as Record from "effect/Record";
13
17
  import * as Schema from "effect/Schema";
14
- //#region src/SectionFiles.ts
18
+ import * as Str from "effect/String";
19
+ // src/SectionFiles.ts
15
20
  /**
16
21
  * The files codegen writes directly in `confect/_generated`, current and
17
22
  * legacy, which no section may claim.
18
23
  */
19
- const builtIn = new Set(`spec schema convexSchema id components component refs docs services manifest
24
+ const builtIn = new Set(Arr.map(pipe(`spec schema convexSchema id components component refs docs services manifest
20
25
  auth.providers testing api nodeApi impl nodeImpl nodeSpec registeredFunctions
21
- nodeRegisteredFunctions`.split(/\s+/).map((name) => `${name}.ts`));
26
+ nodeRegisteredFunctions`, Str.split(/\s+/)), (name) => `${name}.ts`));
22
27
  const PREFIX = "// Generated by `confect codegen` from the manifest section ";
23
- const header = (key) => `${PREFIX}${JSON.stringify(key)}. Do not edit.`;
24
- const Sources = Schema.fromJsonString(Schema.Array(Schema.String));
25
- const encodeSources = Schema.encodeSync(Sources);
28
+ const header = (key) => `${PREFIX}${quote(key)}. Do not edit.`;
29
+ const Sources = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
30
+ const encodeSources = (sources) => Schema.encodeEffect(Sources)(sources).pipe(Effect.orDie);
26
31
  const decodeSources = Schema.decodeUnknownOption(Sources);
27
32
  const INPUTS = "sectionInputs.json";
28
33
  const VERIFY_INPUTS = "verifyInputs.json";
29
34
  const visit = (leaves, each) => {
30
35
  const walk = (group, path, source) => {
31
- for (const spec of Object.values(group.functions)) each(spec, `${path}:${spec.name}`, source);
32
- for (const [name, child] of Object.entries(group.groups)) walk(child, `${path}/${name}`, source);
36
+ for (const spec of Record.values(group.functions)) each(spec, `${path}:${spec.name}`, source);
37
+ for (const [name, child] of Record.toEntries(group.groups)) walk(child, `${path}/${name}`, source);
33
38
  };
34
- for (const leaf of leaves) walk(leaf.spec, leaf.pathSegments.join("/"), leaf.relativePath);
39
+ for (const leaf of leaves) walk(leaf.spec, Arr.join(leaf.pathSegments, "/"), leaf.relativePath);
35
40
  };
36
41
  /**
37
42
  * One claim per declared section that generates a file, ordered by file. A name
@@ -44,23 +49,24 @@ const claims = (sections) => Result.gen(function* () {
44
49
  const byFile = /* @__PURE__ */ new Map();
45
50
  for (const [key, { file }] of byKey) {
46
51
  const other = byFile.get(file);
47
- const refusal = builtIn.has(file) ? `claims confect/_generated/${file}, which codegen writes itself.` : !/^[\w-]+\.ts$/.test(file) ? `claims ${JSON.stringify(file)}; name a .ts file directly inside confect/_generated.` : other !== void 0 ? `claims confect/_generated/${file}, which the manifest section ${JSON.stringify(other)} also claims.` : void 0;
48
- if (refusal !== void 0) return yield* Result.fail(new InvalidManifestSectionError({
52
+ const refusal = builtIn.has(file) ? `claims confect/_generated/${file}, which codegen writes itself.` : !/^[\w-]+\.ts$/.test(file) ? `claims ${quote(file)}; name a .ts file directly inside confect/_generated.` : other !== void 0 ? `claims confect/_generated/${file}, which the manifest section ${quote(other)} also claims.` : void 0;
53
+ if (refusal !== void 0) return yield* Result.fail(InvalidManifestSectionError.make({
49
54
  sectionKey: key,
50
55
  reason: refusal
51
56
  }));
52
57
  byFile.set(file, key);
53
58
  }
54
- return [...byKey].map(([key, generate]) => ({
59
+ return Arr.map([...byKey], ([key, generate]) => ({
55
60
  key,
56
61
  generate
57
- })).sort((a, b) => a.generate.file.localeCompare(b.generate.file));
62
+ })).sort((a, b) => pipe(a.generate.file, Str.localeCompare(b.generate.file)));
58
63
  });
59
64
  const sourceFiles = Effect.gen(function* () {
60
65
  const fs = yield* FileSystem.FileSystem;
61
66
  const path = yield* Path.Path;
62
67
  const confectDirectory = yield* ConfectDirectory.get;
63
- return (yield* fs.readDirectory(confectDirectory, { recursive: true })).map((file) => toPosixPath(path, file)).filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts") && !file.split("/").includes("_generated")).sort();
68
+ const directory = yield* fs.readDirectory(confectDirectory, { recursive: true });
69
+ return pipe(directory, Arr.map((file) => toPosixPath(path, file)), Arr.filter((file) => pipe(file, Str.endsWith(".ts")) && !pipe(file, Str.endsWith(".d.ts")) && !pipe(file, Str.split("/")).includes("_generated"))).sort();
64
70
  });
65
71
  /**
66
72
  * Bundle each matched `confect/` file and return its exports, adding it and
@@ -75,24 +81,27 @@ const load = Effect.fnUntraced(function* (matched, watched, plugins = []) {
75
81
  const recordInputs = {
76
82
  name: "confect:section-inputs",
77
83
  setup: (build) => build.onEnd(({ metafile }) => {
78
- for (const loaded of Object.keys(metafile?.inputs ?? {})) {
84
+ for (const loaded of Record.keys(metafile?.inputs ?? {})) {
79
85
  if (/^[^/\\]+:/.test(loaded) && !path.isAbsolute(loaded)) continue;
80
86
  const file = toPosixPath(path, path.relative(confectDirectory, path.resolve(path.dirname(entry), loaded)));
81
- if (!file.startsWith("../") && !file.startsWith("_generated/")) watched.add(file);
87
+ if (!pipe(file, Str.startsWith("../")) && !pipe(file, Str.startsWith("_generated/"))) watched.add(file);
82
88
  }
83
89
  })
84
90
  };
85
- return bundle(entry, { plugins: [...plugins, recordInputs] }).pipe(Effect.map(({ module }) => ({
86
- relativePath,
87
- exports: module
88
- })), Effect.mapError((error) => fromBundlerError(`confect/${relativePath}`, error)));
91
+ return bundle(entry, { plugins: [...plugins, recordInputs] }).pipe(Effect.mapBoth({
92
+ onFailure: (error) => fromBundlerError(`confect/${relativePath}`, error),
93
+ onSuccess: ({ module }) => ({
94
+ relativePath,
95
+ exports: module
96
+ })
97
+ }));
89
98
  });
90
99
  });
91
100
  /**
92
101
  * Fail with the first of a section's refusals after logging the rest.
93
102
  */
94
103
  const refuse = Effect.fnUntraced(function* (key, reasons) {
95
- const [error, ...more] = reasons.map((reason) => new InvalidManifestSectionError({
104
+ const [error, ...more] = Arr.map(reasons, (reason) => InvalidManifestSectionError.make({
96
105
  sectionKey: key,
97
106
  reason
98
107
  }));
@@ -101,12 +110,12 @@ const refuse = Effect.fnUntraced(function* (key, reasons) {
101
110
  });
102
111
  const render = Effect.fnUntraced(function* ({ key, generate }, target, input, watched) {
103
112
  const confectDirectory = yield* ConfectDirectory.get;
104
- const failed = (cause) => new InvalidManifestSectionError({
113
+ const failed = (cause) => InvalidManifestSectionError.make({
105
114
  sectionKey: key,
106
115
  reason: `generate failed: ${String(cause)}`
107
116
  });
108
117
  const matched = yield* Effect.try({
109
- try: () => input.files.filter((file) => generate.match(file)),
118
+ try: () => Arr.filter(input.files, (file) => generate.match(file)),
110
119
  catch: failed
111
120
  });
112
121
  const modules = yield* load(matched, watched);
@@ -120,36 +129,46 @@ const render = Effect.fnUntraced(function* ({ key, generate }, target, input, wa
120
129
  catch: failed
121
130
  });
122
131
  yield* refuse(key, errors);
132
+ const sources = yield* encodeSources(matched);
123
133
  return {
124
134
  modules,
125
- contents: [
135
+ contents: Arr.join([
126
136
  header(key),
127
- `// Sources: ${encodeSources(matched)}`,
137
+ `// Sources: ${sources}`,
128
138
  contents
129
- ].join("\n")
139
+ ], "\n")
130
140
  };
131
141
  });
132
142
  /**
133
143
  * The files in `confect/_generated` a section wrote, which carry its header.
144
+ *
145
+ * @internal
134
146
  */
135
147
  const written = Effect.gen(function* () {
136
148
  const fs = yield* FileSystem.FileSystem;
137
149
  const path = yield* Path.Path;
138
- const generated = path.join(yield* ConfectDirectory.get, "_generated");
150
+ const confectDirectory = yield* ConfectDirectory.get;
151
+ const generated = path.join(confectDirectory, "_generated");
139
152
  if (!(yield* fs.exists(generated))) return [];
140
- return yield* Effect.filter((yield* fs.readDirectory(generated)).filter((file) => file.endsWith(".ts")), (file) => fs.readFileString(path.join(generated, file)).pipe(Effect.map((contents) => contents.startsWith(PREFIX))));
153
+ const directory = yield* fs.readDirectory(generated);
154
+ return yield* Effect.filter(Arr.filter(directory, (file) => pipe(file, Str.endsWith(".ts"))), (file) => fs.readFileString(path.join(generated, file)).pipe(Effect.map((contents) => pipe(contents, Str.startsWith(PREFIX)))));
141
155
  });
142
156
  const record = Effect.fnUntraced(function* (name) {
143
157
  const fs = yield* FileSystem.FileSystem;
144
- const file = (yield* Path.Path).join(yield* ConfectDirectory.get, "_generated", name);
158
+ const path = yield* Path.Path;
159
+ const confectDirectory = yield* ConfectDirectory.get;
160
+ const file = path.join(confectDirectory, "_generated", name);
145
161
  const none = [];
146
162
  if (!(yield* fs.exists(file))) return none;
147
- return Option.getOrElse(decodeSources(yield* fs.readFileString(file)), () => none);
163
+ const fileContents = yield* fs.readFileString(file);
164
+ return Option.getOrElse(decodeSources(fileContents), () => none);
148
165
  });
149
166
  /**
150
167
  * The `confect/` files the declared sections' `generate` and `verify` matched
151
168
  * and the `confect/` files those import, as recorded by the last codegen run
152
169
  * that loaded them.
170
+ *
171
+ * @internal
153
172
  */
154
173
  const inputs = Effect.map(Effect.all([record(INPUTS), record(VERIFY_INPUTS)]), ([rendered, verified]) => [.../* @__PURE__ */ new Set([...rendered, ...verified])].sort());
155
174
  /**
@@ -160,14 +179,17 @@ const inputs = Effect.map(Effect.all([record(INPUTS), record(VERIFY_INPUTS)]), (
160
179
  * keeping the previous inputs after a failure, so `confect dev` sees the fix.
161
180
  * Returns the claimed file names, whether they differ from the section files
162
181
  * that existed before, and the modules each section key matched.
182
+ *
183
+ * @internal
163
184
  */
164
185
  const sync = Effect.fnUntraced(function* (backend, leaves, mounts) {
165
186
  const path = yield* Path.Path;
166
- const generated = path.join(yield* ConfectDirectory.get, "_generated");
167
- const claimed = Option.isSome(backend) ? (yield* Effect.fromResult(claims(backend.value.sections))).map((claim) => ({
187
+ const confectDirectory = yield* ConfectDirectory.get;
188
+ const generated = path.join(confectDirectory, "_generated");
189
+ const claimed = Option.isSome(backend) ? yield* Effect.map(Effect.fromResult(claims(backend.value.sections)), Arr.map((claim) => ({
168
190
  claim,
169
191
  target: backend.value.target
170
- })) : [];
192
+ }))) : [];
171
193
  const functions = [];
172
194
  visit(leaves, (_, functionPath, source) => functions.push({
173
195
  path: functionPath,
@@ -184,17 +206,17 @@ const sync = Effect.fnUntraced(function* (backend, leaves, mounts) {
184
206
  ...output
185
207
  }))));
186
208
  if (failures.length > 0) for (const file of yield* record(INPUTS)) watched.add(file);
187
- yield* claimed.length === 0 ? removePathIfExists(path.join(generated, INPUTS)) : writeFileStringAndLog(path.join(generated, INPUTS), encodeSources([...watched].sort()));
209
+ yield* claimed.length === 0 ? removePathIfExists(path.join(generated, INPUTS)) : encodeSources([...watched].sort()).pipe(Effect.flatMap((sources) => writeFileStringAndLog(path.join(generated, INPUTS), sources)));
188
210
  const [error, ...more] = failures;
189
211
  for (const other of more) yield* logCodegenError(other);
190
212
  if (error !== void 0) return yield* error;
191
213
  const existing = yield* written;
192
214
  for (const { generate, contents } of rendered) yield* writeFileStringAndLog(path.join(generated, generate.file), contents);
193
- const names = rendered.map(({ generate }) => generate.file);
215
+ const names = Arr.map(rendered, ({ generate }) => generate.file);
194
216
  return {
195
- modules: new Map(rendered.map(({ key, modules }) => [key, modules])),
217
+ modules: new Map(Arr.map(rendered, ({ key, modules }) => [key, modules])),
196
218
  files: names,
197
- changed: names.length !== existing.length || names.some((file) => !existing.includes(file))
219
+ changed: names.length !== existing.length || Arr.some(names, (file) => !existing.includes(file))
198
220
  };
199
221
  });
200
222
  /**
@@ -205,13 +227,16 @@ const sync = Effect.fnUntraced(function* (backend, leaves, mounts) {
205
227
  * after logging the rest. The files each loaded are recorded as section inputs,
206
228
  * keeping the previous ones after a failure, so `confect dev` checks again when
207
229
  * one changes.
230
+ *
231
+ * @internal
208
232
  */
209
233
  const verify = Effect.fnUntraced(function* (backend, mounts) {
210
234
  const path = yield* Path.Path;
211
- const recorded = path.join(yield* ConfectDirectory.get, "_generated", VERIFY_INPUTS);
235
+ const confectDirectory = yield* ConfectDirectory.get;
236
+ const recorded = path.join(confectDirectory, "_generated", VERIFY_INPUTS);
212
237
  const checks = Option.match(backend, {
213
238
  onNone: () => [],
214
- onSome: ({ sections }) => sections.flatMap(({ key, section }) => section.generate?.verify === void 0 ? [] : [{
239
+ onSome: ({ sections }) => Arr.flatMap(sections, ({ key, section }) => section.generate?.verify === void 0 ? [] : [{
215
240
  key,
216
241
  verifier: section.generate.verify
217
242
  }])
@@ -221,26 +246,28 @@ const verify = Effect.fnUntraced(function* (backend, mounts) {
221
246
  const files = yield* sourceFiles;
222
247
  const watched = /* @__PURE__ */ new Set();
223
248
  const [, failures] = yield* Effect.partition(checks, ({ key, verifier }) => Effect.gen(function* () {
224
- const failed = (cause) => new InvalidManifestSectionError({
249
+ const failed = (cause) => InvalidManifestSectionError.make({
225
250
  sectionKey: key,
226
251
  reason: `verify failed: ${String(cause)}`
227
252
  });
228
253
  const matched = yield* Effect.try({
229
- try: () => files.filter((file) => verifier.match(file)),
254
+ try: () => Arr.filter(files, (file) => verifier.match(file)),
230
255
  catch: failed
231
256
  });
232
257
  const modules = yield* load(matched, watched, [componentConfigPlugin(path)]);
233
- yield* refuse(key, yield* Effect.try({
258
+ const tryValue = yield* Effect.try({
234
259
  try: () => verifier.check({
235
260
  modules,
236
261
  mounts,
237
262
  target
238
263
  }),
239
264
  catch: failed
240
- }));
265
+ });
266
+ yield* refuse(key, tryValue);
241
267
  }));
242
268
  if (failures.length > 0) for (const file of yield* record(VERIFY_INPUTS)) watched.add(file);
243
- yield* writeFileStringAndLog(recorded, encodeSources([...watched].sort()));
269
+ const sources = yield* encodeSources([...watched].sort());
270
+ yield* writeFileStringAndLog(recorded, sources);
244
271
  const [error, ...more] = failures;
245
272
  for (const other of more) yield* logCodegenError(other);
246
273
  if (error !== void 0) return yield* error;
@@ -249,16 +276,18 @@ const verify = Effect.fnUntraced(function* (backend, mounts) {
249
276
  * Remove each file a section wrote that is not in `files`. Codegen runs this
250
277
  * after it rewrites the registration files and the HTTP router, so a run that
251
278
  * fails earlier leaves no import of a removed file.
279
+ *
280
+ * @internal
252
281
  */
253
282
  const removeUnclaimed = Effect.fnUntraced(function* (files) {
254
283
  const path = yield* Path.Path;
255
- const generated = path.join(yield* ConfectDirectory.get, "_generated");
284
+ const confectDirectory = yield* ConfectDirectory.get;
285
+ const generated = path.join(confectDirectory, "_generated");
256
286
  for (const file of yield* written) if (!files.includes(file)) {
257
287
  yield* removePathIfExists(path.join(generated, file));
258
288
  yield* logFileRemoved(path.join(generated, file));
259
289
  }
260
290
  });
261
- //#endregion
262
291
  export { builtIn, claims, inputs, removeUnclaimed, sync, verify, written };
263
292
 
264
293
  //# sourceMappingURL=SectionFiles.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SectionFiles.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin"],"sources":["../src/SectionFiles.ts"],"sourcesContent":["import type { FunctionSpec, GroupSpec, ManifestSection } from \"@confect/core\";\nimport type * as esbuild from \"esbuild\";\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 Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"./BuildError.js\";\nimport * as Bundler from \"./Bundler.js\";\nimport {\n InvalidManifestSectionError,\n logCodegenError,\n} from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport * as ConvexConfig from \"./ConvexConfig.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport { logFileRemoved } from \"./log.js\";\nimport {\n removePathIfExists,\n toPosixPath,\n writeFileStringAndLog,\n} from \"./utils.js\";\n\ntype Leaf = Pick<LoadedLeafModule, \"spec\" | \"pathSegments\" | \"relativePath\">;\n\n/**\n * The files codegen writes directly in `confect/_generated`, current and\n * legacy, which no section may claim.\n */\nexport const builtIn: ReadonlySet<string> = new Set(\n `spec schema convexSchema id components component refs docs services manifest\n auth.providers testing api nodeApi impl nodeImpl nodeSpec registeredFunctions\n nodeRegisteredFunctions`\n .split(/\\s+/)\n .map((name) => `${name}.ts`),\n);\n\nconst PREFIX = \"// Generated by `confect codegen` from the manifest section \";\nconst header = (key: string) => `${PREFIX}${JSON.stringify(key)}. Do not edit.`;\nconst Sources = Schema.fromJsonString(Schema.Array(Schema.String));\nconst encodeSources = Schema.encodeSync(Sources);\nconst decodeSources = Schema.decodeUnknownOption(Sources);\nconst INPUTS = \"sectionInputs.json\";\nconst VERIFY_INPUTS = \"verifyInputs.json\";\n\ninterface Claim {\n readonly key: string;\n readonly generate: ManifestSection.Generate;\n}\n\n/**\n * A declared backend: the target codegen generates and the sections its\n * `App.make` names.\n */\nexport interface Backend {\n readonly target: ManifestSection.Target;\n readonly sections: ReadonlyArray<ManifestSection.Entry>;\n}\n\nconst visit = (\n leaves: ReadonlyArray<Leaf>,\n each: (spec: FunctionSpec.AnyWithProps, path: string, source: string) => void,\n) => {\n const walk = (\n group: GroupSpec.AnyWithProps,\n path: string,\n source: string,\n ) => {\n for (const spec of Object.values(group.functions))\n each(spec, `${path}:${spec.name}`, source);\n for (const [name, child] of Object.entries(group.groups))\n walk(child, `${path}/${name}`, source);\n };\n for (const leaf of leaves)\n walk(leaf.spec, leaf.pathSegments.join(\"/\"), leaf.relativePath);\n};\n\n/**\n * One claim per declared section that generates a file, ordered by file. A name\n * that is built in, not a `.ts` file directly in `_generated`, or claimed by\n * two keys is refused.\n */\nexport const claims = (sections: ReadonlyArray<ManifestSection.Entry>) =>\n Result.gen(function* () {\n const byKey = new Map<string, ManifestSection.Generate>();\n for (const { key, section } of sections)\n if (section.generate !== undefined) byKey.set(key, section.generate);\n const byFile = new Map<string, string>();\n for (const [key, { file }] of byKey) {\n const other = byFile.get(file);\n const refusal = builtIn.has(file)\n ? `claims confect/_generated/${file}, which codegen writes itself.`\n : !/^[\\w-]+\\.ts$/.test(file)\n ? `claims ${JSON.stringify(file)}; name a .ts file directly inside confect/_generated.`\n : other !== undefined\n ? `claims confect/_generated/${file}, which the manifest section ${JSON.stringify(other)} also claims.`\n : undefined;\n if (refusal !== undefined)\n return yield* Result.fail(\n new InvalidManifestSectionError({ sectionKey: key, reason: refusal }),\n );\n byFile.set(file, key);\n }\n return [...byKey]\n .map(([key, generate]) => ({ key, generate }))\n .sort((a, b) => a.generate.file.localeCompare(b.generate.file));\n });\n\nconst sourceFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n return (yield* fs.readDirectory(confectDirectory, { recursive: true }))\n .map((file) => toPosixPath(path, file))\n .filter(\n (file) =>\n file.endsWith(\".ts\") &&\n !file.endsWith(\".d.ts\") &&\n !file.split(\"/\").includes(\"_generated\"),\n )\n .sort();\n});\n\n/**\n * Bundle each matched `confect/` file and return its exports, adding it and\n * every first-party file it imports to `watched`.\n */\nconst load = Effect.fnUntraced(function* (\n matched: ReadonlyArray<string>,\n watched: Set<string>,\n plugins: ReadonlyArray<esbuild.Plugin> = [],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n for (const file of matched) watched.add(file);\n return yield* Effect.forEach(matched, (relativePath) => {\n const entry = path.join(confectDirectory, relativePath);\n // Inputs are recorded once esbuild finishes, before the module runs, so a\n // module that throws on load still has its imports watched. `confect dev`\n // sees changes only under `confect/`, and every run rewrites `_generated`,\n // so watching it would loop.\n const recordInputs: esbuild.Plugin = {\n name: \"confect:section-inputs\",\n setup: (build) =>\n build.onEnd(({ metafile }) => {\n for (const loaded of Object.keys(metafile?.inputs ?? {})) {\n // A plugin's own namespace, such as the component config\n // wrapper, is not a file.\n if (/^[^/\\\\]+:/.test(loaded) && !path.isAbsolute(loaded)) continue;\n const file = toPosixPath(\n path,\n path.relative(\n confectDirectory,\n path.resolve(path.dirname(entry), loaded),\n ),\n );\n if (!file.startsWith(\"../\") && !file.startsWith(\"_generated/\"))\n watched.add(file);\n }\n }),\n };\n return Bundler.bundle(entry, { plugins: [...plugins, recordInputs] }).pipe(\n Effect.map(({ module }) => ({ relativePath, exports: module })),\n Effect.mapError((error) =>\n fromBundlerError(`confect/${relativePath}`, error),\n ),\n );\n });\n});\n\n/**\n * Fail with the first of a section's refusals after logging the rest.\n */\nconst refuse = Effect.fnUntraced(function* (\n key: string,\n reasons: ReadonlyArray<string>,\n) {\n const [error, ...more] = reasons.map(\n (reason) => new InvalidManifestSectionError({ sectionKey: key, reason }),\n );\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\nconst render = Effect.fnUntraced(function* (\n { key, generate }: Claim,\n target: ManifestSection.Target,\n input: Pick<ManifestSection.GenerateInput, \"functions\" | \"mounts\" | \"files\">,\n watched: Set<string>,\n) {\n const confectDirectory = yield* ConfectDirectory.get;\n const failed = (cause: unknown) =>\n new InvalidManifestSectionError({\n sectionKey: key,\n reason: `generate failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => input.files.filter((file) => generate.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched);\n const { contents, errors } = yield* Effect.try({\n try: () => generate.render({ ...input, modules, target, confectDirectory }),\n catch: failed,\n });\n yield* refuse(key, errors);\n return {\n modules,\n contents: [\n header(key),\n `// Sources: ${encodeSources(matched)}`,\n contents,\n ].join(\"\\n\"),\n };\n});\n\n/**\n * The files in `confect/_generated` a section wrote, which carry its header.\n */\nexport const written = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const generated = path.join(yield* ConfectDirectory.get, \"_generated\");\n if (!(yield* fs.exists(generated))) return [];\n return yield* Effect.filter(\n (yield* fs.readDirectory(generated)).filter((file) => file.endsWith(\".ts\")),\n (file) =>\n fs\n .readFileString(path.join(generated, file))\n .pipe(Effect.map((contents) => contents.startsWith(PREFIX))),\n );\n});\n\nconst record = Effect.fnUntraced(function* (name: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const file = path.join(yield* ConfectDirectory.get, \"_generated\", name);\n const none: ReadonlyArray<string> = [];\n if (!(yield* fs.exists(file))) return none;\n return Option.getOrElse(\n decodeSources(yield* fs.readFileString(file)),\n () => none,\n );\n});\n\n/**\n * The `confect/` files the declared sections' `generate` and `verify` matched\n * and the `confect/` files those import, as recorded by the last codegen run\n * that loaded them.\n */\nexport const inputs = Effect.map(\n Effect.all([record(INPUTS), record(VERIFY_INPUTS)]),\n ([rendered, verified]) => [...new Set([...rendered, ...verified])].sort(),\n);\n\n/**\n * Write each claimed file into `confect/_generated` once every section the\n * declared backend names has rendered for its target; an undeclared backend\n * renders none. Every section renders before codegen fails with the first error\n * after logging the rest. The record of section inputs is written either way,\n * keeping the previous inputs after a failure, so `confect dev` sees the fix.\n * Returns the claimed file names, whether they differ from the section files\n * that existed before, and the modules each section key matched.\n */\nexport const sync = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n leaves: ReadonlyArray<Leaf>,\n mounts: ManifestSection.GenerateInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const generated = path.join(yield* ConfectDirectory.get, \"_generated\");\n const claimed = Option.isSome(backend)\n ? (yield* Effect.fromResult(claims(backend.value.sections))).map(\n (claim) => ({ claim, target: backend.value.target }),\n )\n : [];\n const functions: Array<{ path: string; source: string }> = [];\n visit(leaves, (_, functionPath, source) =>\n functions.push({ path: functionPath, source }),\n );\n const files = claimed.length === 0 ? [] : yield* sourceFiles;\n const watched = new Set<string>();\n const [rendered, failures] = yield* Effect.partition(\n claimed,\n ({ claim, target }) =>\n render(claim, target, { functions, mounts, files }, watched).pipe(\n Effect.map((output) => ({ ...claim, ...output })),\n ),\n );\n if (failures.length > 0)\n for (const file of yield* record(INPUTS)) watched.add(file);\n yield* claimed.length === 0\n ? removePathIfExists(path.join(generated, INPUTS))\n : writeFileStringAndLog(\n path.join(generated, INPUTS),\n encodeSources([...watched].sort()),\n );\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n const existing = yield* written;\n for (const { generate, contents } of rendered)\n yield* writeFileStringAndLog(path.join(generated, generate.file), contents);\n const names = rendered.map(({ generate }) => generate.file);\n return {\n modules: new Map(rendered.map(({ key, modules }) => [key, modules])),\n files: names,\n changed:\n names.length !== existing.length ||\n names.some((file) => !existing.includes(file)),\n };\n});\n\n/**\n * Run each declared section's `verify` once every `_generated` file exists:\n * bundle the `confect/` files its `match` selects as codegen bundles a\n * declaration, and hand their exports, the mounts and the target to its\n * `check`. Every section checks before codegen fails with the first refusal\n * after logging the rest. The files each loaded are recorded as section inputs,\n * keeping the previous ones after a failure, so `confect dev` checks again when\n * one changes.\n */\nexport const verify = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n mounts: ManifestSection.VerifyInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const recorded = path.join(\n yield* ConfectDirectory.get,\n \"_generated\",\n VERIFY_INPUTS,\n );\n const checks = Option.match(backend, {\n onNone: () => [],\n onSome: ({ sections }) =>\n sections.flatMap(({ key, section }) =>\n section.generate?.verify === undefined\n ? []\n : [{ key, verifier: section.generate.verify }],\n ),\n });\n if (Option.isNone(backend) || checks.length === 0)\n return yield* removePathIfExists(recorded);\n const { target } = backend.value;\n const files = yield* sourceFiles;\n const watched = new Set<string>();\n const [, failures] = yield* Effect.partition(checks, ({ key, verifier }) =>\n Effect.gen(function* () {\n const failed = (cause: unknown) =>\n new InvalidManifestSectionError({\n sectionKey: key,\n reason: `verify failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => files.filter((file) => verifier.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched, [\n ConvexConfig.componentConfigPlugin(path),\n ]);\n yield* refuse(\n key,\n yield* Effect.try({\n try: () => verifier.check({ modules, mounts, target }),\n catch: failed,\n }),\n );\n }),\n );\n if (failures.length > 0)\n for (const file of yield* record(VERIFY_INPUTS)) watched.add(file);\n yield* writeFileStringAndLog(recorded, encodeSources([...watched].sort()));\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\n/**\n * Remove each file a section wrote that is not in `files`. Codegen runs this\n * after it rewrites the registration files and the HTTP router, so a run that\n * fails earlier leaves no import of a removed file.\n */\nexport const removeUnclaimed = Effect.fnUntraced(function* (\n files: ReadonlyArray<string>,\n) {\n const path = yield* Path.Path;\n const generated = path.join(yield* ConfectDirectory.get, \"_generated\");\n for (const file of yield* written)\n if (!files.includes(file)) {\n yield* removePathIfExists(path.join(generated, file));\n yield* logFileRemoved(path.join(generated, file));\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA,MAAa,UAA+B,IAAI,IAC9C;;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aAAa,GAAG,QAAQ,IAAI,IAAI;CACnE,OAAO,sBAAsB,UAAU,cAAc,CAAC,GAAG,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;CACzE,MAAM,CAAC,OAAO,GAAG,QAAQ;CACzB,KAAK,MAAM,SAAS,MAAM,OAAO,gBAAgB,KAAK;CACtD,IAAI,UAAU,KAAA,GAAW,OAAO,OAAO;AACzC,CAAC;;;;;;AAOD,MAAa,kBAAkB,OAAO,WAAW,WAC/C,OACA;CACA,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,YAAY,KAAK,KAAK,OAAO,iBAAiB,KAAK,YAAY;CACrE,KAAK,MAAM,QAAQ,OAAO,SACxB,IAAI,CAAC,MAAM,SAAS,IAAI,GAAG;EACzB,OAAO,mBAAmB,KAAK,KAAK,WAAW,IAAI,CAAC;EACpD,OAAO,eAAe,KAAK,KAAK,WAAW,IAAI,CAAC;CAClD;AACJ,CAAC"}
1
+ {"version":3,"file":"SectionFiles.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin"],"sources":["../src/SectionFiles.ts"],"sourcesContent":["import type { FunctionSpec, GroupSpec, ManifestSection } from \"@confect/core\";\nimport type * as esbuild from \"esbuild\";\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 Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"./BuildError.js\";\nimport * as Bundler from \"./Bundler.js\";\nimport {\n InvalidManifestSectionError,\n logCodegenError,\n} from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport * as ConvexConfig from \"./ConvexConfig.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport { logFileRemoved } from \"./log.js\";\nimport {\n removePathIfExists,\n toPosixPath,\n writeFileStringAndLog,\n} from \"./utils.js\";\nimport * as Str from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Arr from \"effect/Array\";\nimport * as Record from \"effect/Record\";\nimport { quote } from \"./Json.js\";\n\ntype Leaf = Pick<LoadedLeafModule, \"spec\" | \"pathSegments\" | \"relativePath\">;\n\n/**\n * The files codegen writes directly in `confect/_generated`, current and\n * legacy, which no section may claim.\n */\nexport const builtIn: ReadonlySet<string> = new Set(\n Arr.map(\n pipe(\n `spec schema convexSchema id components component refs docs services manifest\n auth.providers testing api nodeApi impl nodeImpl nodeSpec registeredFunctions\n nodeRegisteredFunctions`,\n Str.split(/\\s+/),\n ),\n (name) => `${name}.ts`,\n ),\n);\n\nconst PREFIX = \"// Generated by `confect codegen` from the manifest section \";\nconst header = (key: string) => `${PREFIX}${quote(key)}. Do not edit.`;\nconst Sources = Schema.String.pipe(Schema.Array, Schema.fromJsonString);\nconst encodeSources = (sources: ReadonlyArray<string>) =>\n Schema.encodeEffect(Sources)(sources).pipe(Effect.orDie);\nconst decodeSources = Schema.decodeUnknownOption(Sources);\nconst INPUTS = \"sectionInputs.json\";\nconst VERIFY_INPUTS = \"verifyInputs.json\";\n\ninterface Claim {\n readonly key: string;\n readonly generate: ManifestSection.Generate;\n}\n\n/**\n * A declared backend: the target codegen generates and the sections its\n * `App.make` names.\n */\nexport interface Backend {\n readonly target: ManifestSection.Target;\n readonly sections: ReadonlyArray<ManifestSection.Entry>;\n}\n\nconst visit = (\n leaves: ReadonlyArray<Leaf>,\n each: (spec: FunctionSpec.AnyWithProps, path: string, source: string) => void,\n) => {\n const walk = (\n group: GroupSpec.AnyWithProps,\n path: string,\n source: string,\n ) => {\n for (const spec of Record.values(group.functions))\n each(spec, `${path}:${spec.name}`, source);\n for (const [name, child] of Record.toEntries(group.groups))\n walk(child, `${path}/${name}`, source);\n };\n for (const leaf of leaves)\n walk(leaf.spec, Arr.join(leaf.pathSegments, \"/\"), leaf.relativePath);\n};\n\n/**\n * One claim per declared section that generates a file, ordered by file. A name\n * that is built in, not a `.ts` file directly in `_generated`, or claimed by\n * two keys is refused.\n */\nexport const claims = (sections: ReadonlyArray<ManifestSection.Entry>) =>\n Result.gen(function* () {\n const byKey = new Map<string, ManifestSection.Generate>();\n for (const { key, section } of sections)\n if (section.generate !== undefined) byKey.set(key, section.generate);\n const byFile = new Map<string, string>();\n for (const [key, { file }] of byKey) {\n const other = byFile.get(file);\n const refusal = builtIn.has(file)\n ? `claims confect/_generated/${file}, which codegen writes itself.`\n : !/^[\\w-]+\\.ts$/.test(file)\n ? `claims ${quote(file)}; name a .ts file directly inside confect/_generated.`\n : other !== undefined\n ? `claims confect/_generated/${file}, which the manifest section ${quote(other)} also claims.`\n : undefined;\n if (refusal !== undefined)\n return yield* Result.fail(\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: refusal,\n }),\n );\n byFile.set(file, key);\n }\n return Arr.map([...byKey], ([key, generate]) => ({ key, generate })).sort(\n (a, b) => pipe(a.generate.file, Str.localeCompare(b.generate.file)),\n );\n });\n\nconst sourceFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const directory = yield* fs.readDirectory(confectDirectory, {\n recursive: true,\n });\n return pipe(\n directory,\n Arr.map((file) => toPosixPath(path, file)),\n Arr.filter(\n (file) =>\n pipe(file, Str.endsWith(\".ts\")) &&\n !pipe(file, Str.endsWith(\".d.ts\")) &&\n !pipe(file, Str.split(\"/\")).includes(\"_generated\"),\n ),\n ).sort();\n});\n\n/**\n * Bundle each matched `confect/` file and return its exports, adding it and\n * every first-party file it imports to `watched`.\n */\nconst load = Effect.fnUntraced(function* (\n matched: ReadonlyArray<string>,\n watched: Set<string>,\n plugins: ReadonlyArray<esbuild.Plugin> = [],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n for (const file of matched) watched.add(file);\n return yield* Effect.forEach(matched, (relativePath) => {\n const entry = path.join(confectDirectory, relativePath);\n // Inputs are recorded once esbuild finishes, before the module runs, so a\n // module that throws on load still has its imports watched. `confect dev`\n // sees changes only under `confect/`, and every run rewrites `_generated`,\n // so watching it would loop.\n const recordInputs: esbuild.Plugin = {\n name: \"confect:section-inputs\",\n setup: (build) =>\n build.onEnd(({ metafile }) => {\n for (const loaded of Record.keys(metafile?.inputs ?? {})) {\n // A plugin's own namespace, such as the component config\n // wrapper, is not a file.\n if (/^[^/\\\\]+:/.test(loaded) && !path.isAbsolute(loaded)) continue;\n const file = toPosixPath(\n path,\n path.relative(\n confectDirectory,\n path.resolve(path.dirname(entry), loaded),\n ),\n );\n if (\n !pipe(file, Str.startsWith(\"../\")) &&\n !pipe(file, Str.startsWith(\"_generated/\"))\n )\n watched.add(file);\n }\n }),\n };\n return Bundler.bundle(entry, { plugins: [...plugins, recordInputs] }).pipe(\n Effect.mapBoth({\n onFailure: (error) =>\n fromBundlerError(`confect/${relativePath}`, error),\n onSuccess: ({ module }) => ({ relativePath, exports: module }),\n }),\n );\n });\n});\n\n/**\n * Fail with the first of a section's refusals after logging the rest.\n */\nconst refuse = Effect.fnUntraced(function* (\n key: string,\n reasons: ReadonlyArray<string>,\n) {\n const [error, ...more] = Arr.map(reasons, (reason) =>\n InvalidManifestSectionError.make({ sectionKey: key, reason }),\n );\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\nconst render = Effect.fnUntraced(function* (\n { key, generate }: Claim,\n target: ManifestSection.Target,\n input: Pick<ManifestSection.GenerateInput, \"functions\" | \"mounts\" | \"files\">,\n watched: Set<string>,\n) {\n const confectDirectory = yield* ConfectDirectory.get;\n const failed = (cause: unknown) =>\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: `generate failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => Arr.filter(input.files, (file) => generate.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched);\n const { contents, errors } = yield* Effect.try({\n try: () => generate.render({ ...input, modules, target, confectDirectory }),\n catch: failed,\n });\n yield* refuse(key, errors);\n const sources = yield* encodeSources(matched);\n return {\n modules,\n contents: Arr.join([header(key), `// Sources: ${sources}`, contents], \"\\n\"),\n };\n});\n\n/**\n * The files in `confect/_generated` a section wrote, which carry its header.\n *\n * @internal\n */\nexport const written = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n if (!(yield* fs.exists(generated))) return [];\n const directory = yield* fs.readDirectory(generated);\n return yield* Effect.filter(\n Arr.filter(directory, (file) => pipe(file, Str.endsWith(\".ts\"))),\n (file) =>\n fs\n .readFileString(path.join(generated, file))\n .pipe(Effect.map((contents) => pipe(contents, Str.startsWith(PREFIX)))),\n );\n});\n\nconst record = Effect.fnUntraced(function* (name: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const file = path.join(confectDirectory, \"_generated\", name);\n const none: ReadonlyArray<string> = [];\n if (!(yield* fs.exists(file))) return none;\n const fileContents = yield* fs.readFileString(file);\n return Option.getOrElse(decodeSources(fileContents), () => none);\n});\n\n/**\n * The `confect/` files the declared sections' `generate` and `verify` matched\n * and the `confect/` files those import, as recorded by the last codegen run\n * that loaded them.\n *\n * @internal\n */\nexport const inputs = Effect.map(\n Effect.all([record(INPUTS), record(VERIFY_INPUTS)]),\n ([rendered, verified]) => [...new Set([...rendered, ...verified])].sort(),\n);\n\n/**\n * Write each claimed file into `confect/_generated` once every section the\n * declared backend names has rendered for its target; an undeclared backend\n * renders none. Every section renders before codegen fails with the first error\n * after logging the rest. The record of section inputs is written either way,\n * keeping the previous inputs after a failure, so `confect dev` sees the fix.\n * Returns the claimed file names, whether they differ from the section files\n * that existed before, and the modules each section key matched.\n *\n * @internal\n */\nexport const sync = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n leaves: ReadonlyArray<Leaf>,\n mounts: ManifestSection.GenerateInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n const claimed = Option.isSome(backend)\n ? yield* Effect.map(\n Effect.fromResult(claims(backend.value.sections)),\n Arr.map((claim) => ({ claim, target: backend.value.target })),\n )\n : [];\n const functions: Array<{ path: string; source: string }> = [];\n visit(leaves, (_, functionPath, source) =>\n functions.push({ path: functionPath, source }),\n );\n const files = claimed.length === 0 ? [] : yield* sourceFiles;\n const watched = new Set<string>();\n const [rendered, failures] = yield* Effect.partition(\n claimed,\n ({ claim, target }) =>\n render(claim, target, { functions, mounts, files }, watched).pipe(\n Effect.map((output) => ({ ...claim, ...output })),\n ),\n );\n if (failures.length > 0)\n for (const file of yield* record(INPUTS)) watched.add(file);\n yield* claimed.length === 0\n ? removePathIfExists(path.join(generated, INPUTS))\n : encodeSources([...watched].sort()).pipe(\n Effect.flatMap((sources) =>\n writeFileStringAndLog(path.join(generated, INPUTS), sources),\n ),\n );\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n const existing = yield* written;\n for (const { generate, contents } of rendered)\n yield* writeFileStringAndLog(path.join(generated, generate.file), contents);\n const names = Arr.map(rendered, ({ generate }) => generate.file);\n return {\n modules: new Map(Arr.map(rendered, ({ key, modules }) => [key, modules])),\n files: names,\n changed:\n names.length !== existing.length ||\n Arr.some(names, (file) => !existing.includes(file)),\n };\n});\n\n/**\n * Run each declared section's `verify` once every `_generated` file exists:\n * bundle the `confect/` files its `match` selects as codegen bundles a\n * declaration, and hand their exports, the mounts and the target to its\n * `check`. Every section checks before codegen fails with the first refusal\n * after logging the rest. The files each loaded are recorded as section inputs,\n * keeping the previous ones after a failure, so `confect dev` checks again when\n * one changes.\n *\n * @internal\n */\nexport const verify = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n mounts: ManifestSection.VerifyInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const recorded = path.join(confectDirectory, \"_generated\", VERIFY_INPUTS);\n const checks = Option.match(backend, {\n onNone: () => [],\n onSome: ({ sections }) =>\n Arr.flatMap(sections, ({ key, section }) =>\n section.generate?.verify === undefined\n ? []\n : [{ key, verifier: section.generate.verify }],\n ),\n });\n if (Option.isNone(backend) || checks.length === 0)\n return yield* removePathIfExists(recorded);\n const { target } = backend.value;\n const files = yield* sourceFiles;\n const watched = new Set<string>();\n const [, failures] = yield* Effect.partition(checks, ({ key, verifier }) =>\n Effect.gen(function* () {\n const failed = (cause: unknown) =>\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: `verify failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => Arr.filter(files, (file) => verifier.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched, [\n ConvexConfig.componentConfigPlugin(path),\n ]);\n const tryValue = yield* Effect.try({\n try: () => verifier.check({ modules, mounts, target }),\n catch: failed,\n });\n yield* refuse(key, tryValue);\n }),\n );\n if (failures.length > 0)\n for (const file of yield* record(VERIFY_INPUTS)) watched.add(file);\n const sources = yield* encodeSources([...watched].sort());\n yield* writeFileStringAndLog(recorded, sources);\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\n/**\n * Remove each file a section wrote that is not in `files`. Codegen runs this\n * after it rewrites the registration files and the HTTP router, so a run that\n * fails earlier leaves no import of a removed file.\n *\n * @internal\n */\nexport const removeUnclaimed = Effect.fnUntraced(function* (\n files: ReadonlyArray<string>,\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n for (const file of yield* written)\n if (!files.includes(file)) {\n yield* removePathIfExists(path.join(generated, file));\n yield* logFileRemoved(path.join(generated, file));\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,UAA+B,IAAI,IAC9C,IAAI,IACF,KACE;;4BAGA,IAAI,MAAM,KAAK,CACjB,IACC,SAAS,GA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schema.TaggedError()("SnapshotError", {
4
4
  reason: Schema.Literals([
5
5
  "InvalidShape",
6
6
  "NoncanonicalPath",
7
7
  "DuplicateLeaf",
8
- "NoncanonicalFunctionNames"
8
+ "NoncanonicalFunctionNames",
9
+ "InvalidContextReuse"
9
10
  ]),
10
11
  relativePath: Schema.String,
11
12
  pathSegments: Schema.Array(Schema.String),
@@ -15,7 +16,6 @@ var SnapshotError = class extends Schema.TaggedError()("SnapshotError", {
15
16
  return `Invalid generation snapshot (${this.reason}) at ${this.relativePath || "<snapshot>"}`;
16
17
  }
17
18
  };
18
- //#endregion
19
19
  export { SnapshotError };
20
20
 
21
21
  //# sourceMappingURL=SnapshotError.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SnapshotError.mjs","names":[],"sources":["../src/SnapshotError.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\nexport class SnapshotError extends Schema.TaggedError<SnapshotError>()(\n \"SnapshotError\",\n {\n reason: Schema.Literals([\n \"InvalidShape\",\n \"NoncanonicalPath\",\n \"DuplicateLeaf\",\n \"NoncanonicalFunctionNames\",\n ]),\n relativePath: Schema.String,\n pathSegments: Schema.Array(Schema.String),\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {\n override get message(): string {\n return `Invalid generation snapshot (${this.reason}) at ${this.relativePath || \"<snapshot>\"}`;\n }\n}\n"],"mappings":";;AAEA,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CACpE,iBACA;CACE,QAAQ,OAAO,SAAS;EACtB;EACA;EACA;EACA;CACF,CAAC;CACD,cAAc,OAAO;CACrB,cAAc,OAAO,MAAM,OAAO,MAAM;CACxC,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,gCAAgC,KAAK,OAAO,OAAO,KAAK,gBAAgB;CACjF;AACF"}
1
+ {"version":3,"file":"SnapshotError.mjs","names":[],"sources":["../src/SnapshotError.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\nexport class SnapshotError extends Schema.TaggedError<\n SnapshotError,\n { readonly brand: unique symbol }\n>()(\"SnapshotError\", {\n reason: Schema.Literals([\n \"InvalidShape\",\n \"NoncanonicalPath\",\n \"DuplicateLeaf\",\n \"NoncanonicalFunctionNames\",\n \"InvalidContextReuse\",\n ]),\n relativePath: Schema.String,\n pathSegments: Schema.Array(Schema.String),\n cause: Schema.optionalKey(Schema.Defect()),\n}) {\n override get message(): string {\n return `Invalid generation snapshot (${this.reason}) at ${this.relativePath || \"<snapshot>\"}`;\n }\n}\n"],"mappings":";;AAEA,IAAa,gBAAb,cAAmC,OAAO,YAGxC,CAAC,CAAC,iBAAiB;CACnB,QAAQ,OAAO,SAAS;EACtB;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,cAAc,OAAO;CACrB,cAAc,OAAO,MAAM,OAAO,MAAM;CACxC,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CAAC,CAAC,CAAC;CACD,IAAa,UAAkB;EAC7B,OAAO,gCAAgC,KAAK,OAAO,OAAO,KAAK,gBAAgB;CACjF;AACF"}
@@ -5,7 +5,7 @@ import { pipe } from "effect/Function";
5
5
  import * as Option from "effect/Option";
6
6
  import * as Record from "effect/Record";
7
7
  import * as Order from "effect/Order";
8
- //#region src/SpecAssemblyNode.ts
8
+ // src/SpecAssemblyNode.ts
9
9
  const importBindingFromLeaf = (leaf) => ({
10
10
  importPath: leaf.specImportPath,
11
11
  exportName: leaf.exportName,
@@ -85,7 +85,6 @@ const render = Effect.fnUntraced(function* (nodes) {
85
85
  yield* cbw.writeLine(`export default spec;`);
86
86
  return yield* cbw.toString();
87
87
  });
88
- //#endregion
89
88
  export { assemblyNodesFromLeaves, collectImportBindings, render };
90
89
 
91
90
  //# sourceMappingURL=SpecAssemblyNode.mjs.map
@@ -1,10 +1,10 @@
1
- import { withSuffix } from "./RelativeModulePath.mjs";
2
1
  import { ImplModulePath } from "./ImplModulePath.mjs";
2
+ import { withSuffix } from "./RelativeModulePath.mjs";
3
3
  import * as Schema from "effect/Schema";
4
- //#region src/SpecModulePath.ts
4
+ import * as String from "effect/String";
5
+ // src/SpecModulePath.ts
5
6
  const SpecModulePath = withSuffix(".spec.ts").pipe(Schema.brand("@confect/cli/SpecModulePath"));
6
- const toImpl = (path) => ImplModulePath.make(`${path.slice(0, -8)}.impl.ts`);
7
- //#endregion
7
+ const toImpl = (path) => ImplModulePath.make(`${String.slice(0, -8)(path)}.impl.ts`);
8
8
  export { SpecModulePath, toImpl };
9
9
 
10
10
  //# sourceMappingURL=SpecModulePath.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpecModulePath.mjs","names":["RelativeModulePath.withSuffix"],"sources":["../src/SpecModulePath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport { ImplModulePath } from \"./ImplModulePath.js\";\nimport * as RelativeModulePath from \"./RelativeModulePath.js\";\n\nexport const SpecModulePath = RelativeModulePath.withSuffix(\".spec.ts\").pipe(\n Schema.brand(\"@confect/cli/SpecModulePath\"),\n);\n\nexport type SpecModulePath = typeof SpecModulePath.Type;\n\nexport const toImpl = (path: SpecModulePath): ImplModulePath =>\n ImplModulePath.make(`${path.slice(0, -\".spec.ts\".length)}.impl.ts`);\n\nexport const fromImpl = (path: ImplModulePath): SpecModulePath =>\n SpecModulePath.make(`${path.slice(0, -\".impl.ts\".length)}.spec.ts`);\n"],"mappings":";;;;AAIA,MAAa,iBAAiBA,WAA8B,UAAU,CAAC,CAAC,KACtE,OAAO,MAAM,6BAA6B,CAC5C;AAIA,MAAa,UAAU,SACrB,eAAe,KAAK,GAAG,KAAK,MAAM,GAAG,EAAkB,EAAE,SAAS"}
1
+ {"version":3,"file":"SpecModulePath.mjs","names":["RelativeModulePath.withSuffix"],"sources":["../src/SpecModulePath.ts"],"sourcesContent":["import * as String from \"effect/String\";\nimport * as Schema from \"effect/Schema\";\nimport { ImplModulePath } from \"./ImplModulePath.js\";\nimport * as RelativeModulePath from \"./RelativeModulePath.js\";\n\nexport const SpecModulePath = RelativeModulePath.withSuffix(\".spec.ts\").pipe(\n Schema.brand(\"@confect/cli/SpecModulePath\"),\n);\n\nexport type SpecModulePath = typeof SpecModulePath.Type;\n\nexport const toImpl = (path: SpecModulePath): ImplModulePath =>\n ImplModulePath.make(`${String.slice(0, -\".spec.ts\".length)(path)}.impl.ts`);\n\nexport const fromImpl = (path: ImplModulePath): SpecModulePath =>\n SpecModulePath.make(`${String.slice(0, -\".impl.ts\".length)(path)}.spec.ts`);\n"],"mappings":";;;;;AAKA,MAAa,iBAAiBA,WAA8B,UAAU,CAAC,CAAC,KACtE,OAAO,MAAM,6BAA6B,CAC5C;AAIA,MAAa,UAAU,SACrB,eAAe,KAAK,GAAG,OAAO,MAAM,GAAG,EAAkB,CAAC,CAAC,IAAI,EAAE,SAAS"}
@@ -3,7 +3,7 @@ import * as HashSet from "effect/HashSet";
3
3
  import * as Match from "effect/Match";
4
4
  import * as HashMap from "effect/HashMap";
5
5
  import * as Data from "effect/Data";
6
- //#region src/SyncState.ts
6
+ // src/SyncState.ts
7
7
  const Work = Data.taggedEnum();
8
8
  const empty = {
9
9
  work: Work.None(),
@@ -33,7 +33,7 @@ const add = (pending, entries, forceFull = false) => {
33
33
  Reconcile: () => HashMap.empty(),
34
34
  Full: () => HashMap.empty(),
35
35
  Impls: () => HashMap.empty(),
36
- Declarations: ({ entries: declarations }) => HashMap.fromIterable(declarations.map((entry) => [`${entry._tag}:${entry.relativePath}`, entry]))
36
+ Declarations: ({ entries: declarations }) => HashMap.fromIterable(Array.map(declarations, (entry) => [`${entry._tag}:${entry.relativePath}`, entry]))
37
37
  }),
38
38
  optional: pending.optional
39
39
  }, (state, entry) => Match.value(entry).pipe(Match.tag("Impl", ({ relativePath }) => ({
@@ -50,7 +50,7 @@ const add = (pending, entries, forceFull = false) => {
50
50
  needsFull: true
51
51
  })), Match.exhaustive));
52
52
  const impls = Array.fromIterable(next.paths);
53
- const declarations = Array.fromIterable(HashMap.values(next.declarations));
53
+ const declarations = next.declarations.pipe(HashMap.values, Array.fromIterable);
54
54
  return {
55
55
  work: next.needsFull ? Work.Full() : Array.isReadonlyArrayNonEmpty(declarations) ? Work.Declarations({
56
56
  entries: declarations,
@@ -116,7 +116,6 @@ const plan = (phase, pending) => Phase.$match(phase, {
116
116
  paths: implsToValidate(ready, pending)
117
117
  })), Match.exhaustive)
118
118
  });
119
- //#endregion
120
119
  export { Operation, Outcome, Phase, Work, add, empty, forBackend, full, implsToValidate, isDirty, needsDeploymentNotification, plan, reconcile, shouldRetry, transition };
121
120
 
122
121
  //# sourceMappingURL=SyncState.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SyncState.mjs","names":[],"sources":["../src/SyncState.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Match from \"effect/Match\";\nimport type { Declaration, Kind, OptionalFile } from \"./EntryPoint.js\";\nimport type { ImplModulePath } from \"./ImplModulePath.js\";\nimport type { GenerationSnapshot } from \"./GenerationSnapshot.js\";\n\nexport type Work = Data.TaggedEnum<{\n None: {};\n Reconcile: {};\n Full: {};\n Impls: { readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath> };\n Declarations: {\n readonly entries: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Work = Data.taggedEnum<Work>();\n\nexport interface Pending {\n readonly work: Work;\n readonly optional: HashSet.HashSet<OptionalFile>;\n}\n\nexport const empty: Pending = { work: Work.None(), optional: HashSet.empty() };\nexport const isDirty = (pending: Pending): boolean =>\n !Work.$is(\"None\")(pending.work) || !HashSet.isEmpty(pending.optional);\nexport const full = (pending: Pending): Pending => ({\n ...pending,\n work: Work.Full(),\n});\n\nexport const reconcile = (pending: Pending): Pending => ({\n ...pending,\n work: Work.$is(\"None\")(pending.work) ? Work.Reconcile() : pending.work,\n});\n\nexport const add = (\n pending: Pending,\n entries: ReadonlyArray<Kind>,\n forceFull = false,\n): Pending => {\n const next = Array.reduce(\n entries,\n {\n needsFull: forceFull || Work.$is(\"Full\")(pending.work),\n paths: Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n declarations: Work.$match(pending.work, {\n None: () => HashMap.empty<string, Declaration>(),\n Reconcile: () => HashMap.empty<string, Declaration>(),\n Full: () => HashMap.empty<string, Declaration>(),\n Impls: () => HashMap.empty<string, Declaration>(),\n Declarations: ({ entries: declarations }) =>\n HashMap.fromIterable(\n declarations.map(\n (entry) =>\n [`${entry._tag}:${entry.relativePath}`, entry] as const,\n ),\n ),\n }),\n optional: pending.optional,\n },\n (state, entry) =>\n Match.value(entry).pipe(\n Match.tag(\"Impl\", ({ relativePath }) => ({\n ...state,\n paths: HashSet.add(state.paths, relativePath),\n })),\n Match.tag(\"Http\", \"Crons\", \"Auth\", ({ _tag }) => ({\n ...state,\n optional: HashSet.add(state.optional, _tag),\n })),\n Match.tag(\"Spec\", \"Table\", (declaration) => ({\n ...state,\n declarations: HashMap.set(\n state.declarations,\n `${declaration._tag}:${declaration.relativePath}`,\n declaration,\n ),\n })),\n Match.tag(\"Config\", \"Env\", \"App\", \"Callbacks\", \"Runtime\", () => ({\n ...state,\n needsFull: true,\n })),\n Match.exhaustive,\n ),\n );\n const impls = Array.fromIterable(next.paths);\n const declarations = Array.fromIterable(HashMap.values(next.declarations));\n return {\n work: next.needsFull\n ? Work.Full()\n : Array.isReadonlyArrayNonEmpty(declarations)\n ? Work.Declarations({ entries: declarations, paths: impls })\n : Array.isReadonlyArrayNonEmpty(impls)\n ? Work.Impls({ paths: impls })\n : Work.$is(\"Reconcile\")(pending.work)\n ? Work.Reconcile()\n : Work.None(),\n optional: next.optional,\n };\n};\n\nexport interface Backend {\n readonly declared: boolean;\n readonly component: boolean;\n}\n\n/**\n * Full generation writes a declared backend's `convex/http.ts` and\n * `auth.config.ts` and rejects a component's `auth.ts`, so those edits need it\n * instead of the optional-file writers.\n */\nexport const forBackend = (pending: Pending, backend: Backend): Pending => {\n const generated = HashSet.filter(pending.optional, (file) =>\n Match.value(file).pipe(\n Match.when(\"Http\", () => backend.declared),\n Match.when(\"Auth\", () => backend.declared || backend.component),\n Match.when(\"Crons\", () => false),\n Match.exhaustive,\n ),\n );\n if (HashSet.isEmpty(generated)) return pending;\n return {\n work: Work.Full(),\n optional: backend.declared\n ? HashSet.difference(pending.optional, generated)\n : pending.optional,\n };\n};\n\nexport type Phase = Data.TaggedEnum<{\n Bootstrapping: {};\n NeedsFullSync: {};\n Incremental: {\n readonly failedImpls: HashSet.HashSet<ImplModulePath>;\n readonly snapshot: GenerationSnapshot;\n };\n}>;\nexport const Phase = Data.taggedEnum<Phase>();\n\nexport type Outcome = Data.TaggedEnum<{\n Succeeded: { readonly snapshot: GenerationSnapshot };\n GenerationFailed: {};\n ReconciliationFailed: {};\n ValidationFailed: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Outcome = Data.taggedEnum<Outcome>();\n\nexport const transition = (outcome: Outcome): Phase =>\n Outcome.$match(outcome, {\n Succeeded: ({ snapshot }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.empty(),\n }),\n GenerationFailed: () => Phase.NeedsFullSync(),\n ReconciliationFailed: () => Phase.NeedsFullSync(),\n ValidationFailed: ({ snapshot, paths }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.fromIterable(paths),\n }),\n });\n\nexport const shouldRetry = (phase: Phase, outcome: Outcome): boolean =>\n Phase.$is(\"Bootstrapping\")(phase) && Outcome.$is(\"GenerationFailed\")(outcome);\n\nexport const needsDeploymentNotification = (phase: Phase): boolean =>\n Phase.$match(phase, {\n Bootstrapping: () => true,\n NeedsFullSync: () => true,\n Incremental: ({ failedImpls }) => !HashSet.isEmpty(failedImpls),\n });\n\nexport const implsToValidate = (\n phase: Phase,\n pending: Pending,\n): ReadonlyArray<ImplModulePath> =>\n Array.fromIterable(\n HashSet.union(\n Phase.$match(phase, {\n Bootstrapping: () => HashSet.empty<ImplModulePath>(),\n NeedsFullSync: () => HashSet.empty<ImplModulePath>(),\n Incremental: ({ failedImpls }) => failedImpls,\n }),\n Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n ),\n );\n\nexport type Operation = Data.TaggedEnum<{\n Generate: {};\n Validate: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n Update: {\n readonly snapshot: GenerationSnapshot;\n readonly declarations: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Operation = Data.taggedEnum<Operation>();\n\nexport const plan = (phase: Phase, pending: Pending): Operation =>\n Phase.$match(phase, {\n Bootstrapping: () => Operation.Generate(),\n NeedsFullSync: () => Operation.Generate(),\n Incremental: (ready) =>\n Match.value(pending.work).pipe(\n Match.tag(\"Full\", () => Operation.Generate()),\n Match.tag(\"None\", \"Reconcile\", \"Impls\", () =>\n Operation.Validate({\n snapshot: ready.snapshot,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.tag(\"Declarations\", ({ entries }) =>\n Operation.Update({\n snapshot: ready.snapshot,\n declarations: entries,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.exhaustive,\n ),\n });\n"],"mappings":";;;;;;AAmBA,MAAa,OAAO,KAAK,WAAiB;AAO1C,MAAa,QAAiB;CAAE,MA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CAAC,CACH,GACA,MAAM,IAAI,iBAAiB,EAAE,cAC3B,UAAU,OAAO;EACf,UAAU,MAAM;EAChB,cAAc;EACd,OAAO,gBAAgB,OAAO,OAAO;CACvC,CAAC,CACH,GACA,MAAM,UACR;AACJ,CAAC"}
1
+ {"version":3,"file":"SyncState.mjs","names":[],"sources":["../src/SyncState.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Match from \"effect/Match\";\nimport type { Declaration, Kind, OptionalFile } from \"./EntryPoint.js\";\nimport type { ImplModulePath } from \"./ImplModulePath.js\";\nimport type { GenerationSnapshot } from \"./GenerationSnapshot.js\";\n\nexport type Work = Data.TaggedEnum<{\n None: {};\n Reconcile: {};\n Full: {};\n Impls: { readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath> };\n Declarations: {\n readonly entries: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Work = Data.taggedEnum<Work>();\n\nexport interface Pending {\n readonly work: Work;\n readonly optional: HashSet.HashSet<OptionalFile>;\n}\n\nexport const empty: Pending = { work: Work.None(), optional: HashSet.empty() };\nexport const isDirty = (pending: Pending): boolean =>\n !Work.$is(\"None\")(pending.work) || !HashSet.isEmpty(pending.optional);\nexport const full = (pending: Pending): Pending => ({\n ...pending,\n work: Work.Full(),\n});\n\nexport const reconcile = (pending: Pending): Pending => ({\n ...pending,\n work: Work.$is(\"None\")(pending.work) ? Work.Reconcile() : pending.work,\n});\n\nexport const add = (\n pending: Pending,\n entries: ReadonlyArray<Kind>,\n forceFull: boolean = false,\n): Pending => {\n const next = Array.reduce(\n entries,\n {\n needsFull: forceFull || Work.$is(\"Full\")(pending.work),\n paths: Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n declarations: Work.$match(pending.work, {\n None: () => HashMap.empty<string, Declaration>(),\n Reconcile: () => HashMap.empty<string, Declaration>(),\n Full: () => HashMap.empty<string, Declaration>(),\n Impls: () => HashMap.empty<string, Declaration>(),\n Declarations: ({ entries: declarations }) =>\n HashMap.fromIterable(\n Array.map(\n declarations,\n (entry) =>\n [`${entry._tag}:${entry.relativePath}`, entry] as const,\n ),\n ),\n }),\n optional: pending.optional,\n },\n (state, entry) =>\n Match.value(entry).pipe(\n Match.tag(\"Impl\", ({ relativePath }) => ({\n ...state,\n paths: HashSet.add(state.paths, relativePath),\n })),\n Match.tag(\"Http\", \"Crons\", \"Auth\", ({ _tag }) => ({\n ...state,\n optional: HashSet.add(state.optional, _tag),\n })),\n Match.tag(\"Spec\", \"Table\", (declaration) => ({\n ...state,\n declarations: HashMap.set(\n state.declarations,\n `${declaration._tag}:${declaration.relativePath}`,\n declaration,\n ),\n })),\n Match.tag(\"Config\", \"Env\", \"App\", \"Callbacks\", \"Runtime\", () => ({\n ...state,\n needsFull: true,\n })),\n Match.exhaustive,\n ),\n );\n const impls = Array.fromIterable(next.paths);\n const declarations = next.declarations.pipe(\n HashMap.values,\n Array.fromIterable,\n );\n return {\n work: next.needsFull\n ? Work.Full()\n : Array.isReadonlyArrayNonEmpty(declarations)\n ? Work.Declarations({ entries: declarations, paths: impls })\n : Array.isReadonlyArrayNonEmpty(impls)\n ? Work.Impls({ paths: impls })\n : Work.$is(\"Reconcile\")(pending.work)\n ? Work.Reconcile()\n : Work.None(),\n optional: next.optional,\n };\n};\n\nexport interface Backend {\n readonly declared: boolean;\n readonly component: boolean;\n}\n\n/**\n * Full generation writes a declared backend's `convex/http.ts` and\n * `auth.config.ts` and rejects a component's `auth.ts`, so those edits need it\n * instead of the optional-file writers.\n */\nexport const forBackend = (pending: Pending, backend: Backend): Pending => {\n const generated = HashSet.filter(pending.optional, (file) =>\n Match.value(file).pipe(\n Match.when(\"Http\", () => backend.declared),\n Match.when(\"Auth\", () => backend.declared || backend.component),\n Match.when(\"Crons\", () => false),\n Match.exhaustive,\n ),\n );\n if (HashSet.isEmpty(generated)) return pending;\n return {\n work: Work.Full(),\n optional: backend.declared\n ? HashSet.difference(pending.optional, generated)\n : pending.optional,\n };\n};\n\nexport type Phase = Data.TaggedEnum<{\n Bootstrapping: {};\n NeedsFullSync: {};\n Incremental: {\n readonly failedImpls: HashSet.HashSet<ImplModulePath>;\n readonly snapshot: GenerationSnapshot;\n };\n}>;\nexport const Phase = Data.taggedEnum<Phase>();\n\nexport type Outcome = Data.TaggedEnum<{\n Succeeded: { readonly snapshot: GenerationSnapshot };\n GenerationFailed: {};\n ReconciliationFailed: {};\n ValidationFailed: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Outcome = Data.taggedEnum<Outcome>();\n\nexport const transition = (outcome: Outcome): Phase =>\n Outcome.$match(outcome, {\n Succeeded: ({ snapshot }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.empty(),\n }),\n GenerationFailed: () => Phase.NeedsFullSync(),\n ReconciliationFailed: () => Phase.NeedsFullSync(),\n ValidationFailed: ({ snapshot, paths }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.fromIterable(paths),\n }),\n });\n\nexport const shouldRetry = (phase: Phase, outcome: Outcome): boolean =>\n Phase.$is(\"Bootstrapping\")(phase) && Outcome.$is(\"GenerationFailed\")(outcome);\n\nexport const needsDeploymentNotification = (phase: Phase): boolean =>\n Phase.$match(phase, {\n Bootstrapping: () => true,\n NeedsFullSync: () => true,\n Incremental: ({ failedImpls }) => !HashSet.isEmpty(failedImpls),\n });\n\nexport const implsToValidate = (\n phase: Phase,\n pending: Pending,\n): ReadonlyArray<ImplModulePath> =>\n Array.fromIterable(\n HashSet.union(\n Phase.$match(phase, {\n Bootstrapping: () => HashSet.empty<ImplModulePath>(),\n NeedsFullSync: () => HashSet.empty<ImplModulePath>(),\n Incremental: ({ failedImpls }) => failedImpls,\n }),\n Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n ),\n );\n\nexport type Operation = Data.TaggedEnum<{\n Generate: {};\n Validate: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n Update: {\n readonly snapshot: GenerationSnapshot;\n readonly declarations: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Operation = Data.taggedEnum<Operation>();\n\nexport const plan = (phase: Phase, pending: Pending): Operation =>\n Phase.$match(phase, {\n Bootstrapping: () => Operation.Generate(),\n NeedsFullSync: () => Operation.Generate(),\n Incremental: (ready) =>\n Match.value(pending.work).pipe(\n Match.tag(\"Full\", () => Operation.Generate()),\n Match.tag(\"None\", \"Reconcile\", \"Impls\", () =>\n Operation.Validate({\n snapshot: ready.snapshot,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.tag(\"Declarations\", ({ entries }) =>\n Operation.Update({\n snapshot: ready.snapshot,\n declarations: entries,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.exhaustive,\n ),\n });\n"],"mappings":";;;;;;AAmBA,MAAa,OAAO,KAAK,WAAiB;AAO1C,MAAa,QAAiB;CAAE,MAAM,KAAK,KAAK;CAAG,UAAU,QAAQ,MAAM;AAAE;AAC7E,MAAa,WAAW,YACtB,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,QAAQ,QAAQ,QAAQ;AACtE,MAAa,QAAQ,aAA+B;CAClD,GAAG;CACH,MAAM,KAAK,KAAK;A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