@gaganref/confect-cli 10.3.1-fork.4 → 10.3.1-fork.41

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 (52) hide show
  1. package/dist/Bundler.mjs +22 -1
  2. package/dist/Bundler.mjs.map +1 -1
  3. package/dist/CodegenError.mjs +11 -2
  4. package/dist/CodegenError.mjs.map +1 -1
  5. package/dist/ConfectDirectory.mjs.map +1 -1
  6. package/dist/ConvexConfig.mjs.map +1 -1
  7. package/dist/ConvexDirectory.mjs.map +1 -1
  8. package/dist/Declaration.mjs +77 -14
  9. package/dist/Declaration.mjs.map +1 -1
  10. package/dist/DirectoryOptions.mjs.map +1 -1
  11. package/dist/EntryPoint.mjs +2 -0
  12. package/dist/EntryPoint.mjs.map +1 -1
  13. package/dist/Evaluation.mjs +39 -13
  14. package/dist/Evaluation.mjs.map +1 -1
  15. package/dist/EvaluationWorker.mjs +13 -1
  16. package/dist/EvaluationWorker.mjs.map +1 -1
  17. package/dist/FunctionModule.mjs +100 -24
  18. package/dist/FunctionModule.mjs.map +1 -1
  19. package/dist/FunctionPath.mjs.map +1 -1
  20. package/dist/FunctionPaths.mjs.map +1 -1
  21. package/dist/GenerationSnapshot.mjs.map +1 -1
  22. package/dist/GroupPaths.mjs.map +1 -1
  23. package/dist/ImplModulePath.mjs.map +1 -1
  24. package/dist/LeafModule.mjs +17 -17
  25. package/dist/LeafModule.mjs.map +1 -1
  26. package/dist/Remove.mjs.map +1 -1
  27. package/dist/Rollback.mjs.map +1 -1
  28. package/dist/SpecAssemblyNode.mjs.map +1 -1
  29. package/dist/SpecModulePath.mjs.map +1 -1
  30. package/dist/SyncState.mjs +1 -1
  31. package/dist/SyncState.mjs.map +1 -1
  32. package/dist/TableModule.mjs.map +1 -1
  33. package/dist/TableModulePath.mjs.map +1 -1
  34. package/dist/WatchBuild.mjs.map +1 -1
  35. package/dist/WatchTopology.mjs.map +1 -1
  36. package/dist/Watcher.mjs +57 -55
  37. package/dist/Watcher.mjs.map +1 -1
  38. package/dist/cliApp.mjs.map +1 -1
  39. package/dist/confect/codegen.mjs +76 -32
  40. package/dist/confect/codegen.mjs.map +1 -1
  41. package/dist/confect/declaration.mjs +20 -7
  42. package/dist/confect/declaration.mjs.map +1 -1
  43. package/dist/confect/dev.mjs +9 -4
  44. package/dist/confect/dev.mjs.map +1 -1
  45. package/dist/confect.mjs.map +1 -1
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/log.mjs.map +1 -1
  48. package/dist/templates.mjs +29 -15
  49. package/dist/templates.mjs.map +1 -1
  50. package/dist/utils.mjs +1 -1
  51. package/dist/utils.mjs.map +1 -1
  52. package/package.json +6 -5
@@ -1,9 +1,12 @@
1
1
  import { fromGroupModulePath, modulePath } from "./GroupPath.mjs";
2
+ import { ProjectRoot } from "./ProjectRoot.mjs";
2
3
  import { logFileAdded, logFileModified, logFileRemoved } from "./log.mjs";
4
+ import { UnownedConvexEntrypointError } from "./CodegenError.mjs";
3
5
  import { ConvexDirectory } from "./ConvexDirectory.mjs";
4
6
  import { ConfectDirectory } from "./ConfectDirectory.mjs";
5
7
  import { CodeBlockWriter } from "./CodeBlockWriter.mjs";
6
- import { removePathIfExists, toModuleImportPath } from "./utils.mjs";
8
+ import { crons, declaredHttp, http } from "./templates.mjs";
9
+ import { removePathIfExists, toModuleImportPath, toPosixPath } from "./utils.mjs";
7
10
  import { GroupPaths } from "./GroupPaths.mjs";
8
11
  import { functionPaths, plan } from "./GenerationSnapshot.mjs";
9
12
  import * as Effect from "effect/Effect";
@@ -14,6 +17,88 @@ import { pipe } from "effect/Function";
14
17
  import * as HashSet from "effect/HashSet";
15
18
  import * as Match from "effect/Match";
16
19
  //#region src/FunctionModule.ts
20
+ const RESERVED_CONVEX_TS_FILE_NAMES = /* @__PURE__ */ new Set([
21
+ "schema.ts",
22
+ "http.ts",
23
+ "crons.ts",
24
+ "auth.config.ts",
25
+ "convex.config.ts"
26
+ ]);
27
+ const getEntrypoints = Effect.gen(function* () {
28
+ const fs = yield* FileSystem.FileSystem;
29
+ const path = yield* Path.Path;
30
+ const convex = yield* ConvexDirectory.get;
31
+ const files = yield* fs.readDirectory(convex, { recursive: true });
32
+ const components = files.filter((file) => path.basename(file) === "convex.config.ts" && path.dirname(file) !== ".").map((file) => path.dirname(file) + path.sep);
33
+ return files.filter((file) => {
34
+ const base = path.basename(file);
35
+ return !file.startsWith("_generated" + path.sep) && !components.some((component) => file.startsWith(component)) && /\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) && !base.startsWith(".") && !base.startsWith("#") && (base.match(/\./g)?.length ?? 0) === 1 && base !== "schema.ts" && base !== "schema.js" && !file.includes(" ");
36
+ });
37
+ });
38
+ const tokenize = (source, modulePath, path) => {
39
+ const token = /\s+|\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[$A-Z_a-z][$\w]*|[{}()[\].,:;=]/y;
40
+ const tokens = [];
41
+ while (token.lastIndex < source.length) {
42
+ const match = token.exec(source);
43
+ if (match === null) return void 0;
44
+ const value = match[0];
45
+ if (/^\s|^\//.test(value)) continue;
46
+ if (value.startsWith("\"") || value.startsWith("'")) {
47
+ const literal = value.slice(1, -1);
48
+ tokens.push(JSON.stringify(literal.startsWith(".") ? path.resolve(path.dirname(modulePath), literal.replace(/\.js$/, "")) : literal));
49
+ } else tokens.push(value);
50
+ }
51
+ return tokens;
52
+ };
53
+ const matchesShape = (actual, expected) => {
54
+ let index = 0;
55
+ for (const token of expected) {
56
+ if (token === ";" && actual[index] !== ";") continue;
57
+ if (actual[index] === "," && (token === "}" || token === ")")) index++;
58
+ if (actual[index++] !== token) return false;
59
+ }
60
+ return index === actual.length;
61
+ };
62
+ const assertOwnedEntrypoints = Effect.gen(function* () {
63
+ const fs = yield* FileSystem.FileSystem;
64
+ const path = yield* Path.Path;
65
+ const convex = yield* ConvexDirectory.get;
66
+ const confect = yield* ConfectDirectory.get;
67
+ const projectRoot = yield* ProjectRoot.get;
68
+ const importFromConvex = (file) => toModuleImportPath(path.relative(convex, path.join(confect, file)));
69
+ const optional = /* @__PURE__ */ new Map([["http.ts", [
70
+ yield* http({ httpImportPath: yield* importFromConvex("http.ts") }),
71
+ yield* declaredHttp({
72
+ schemaImportPath: yield* importFromConvex("_generated/schema.ts"),
73
+ httpImportPath: yield* importFromConvex("http.ts")
74
+ }),
75
+ yield* declaredHttp({
76
+ schemaImportPath: yield* importFromConvex("_generated/schema.ts"),
77
+ httpImportPath: yield* importFromConvex("http.ts"),
78
+ runtimeImportPath: yield* importFromConvex("runtime.ts")
79
+ })
80
+ ]], ["crons.ts", [yield* crons({ cronsImportPath: yield* importFromConvex("crons.ts") })]]]);
81
+ const refused = [];
82
+ for (const relative of yield* getEntrypoints) {
83
+ const absolute = path.join(convex, relative);
84
+ const tokens = tokenize(yield* fs.readFileString(absolute), absolute, path);
85
+ if (tokens !== void 0) {
86
+ if (optional.get(relative)?.some((template) => matchesShape(tokens, tokenize(template, absolute, path)))) continue;
87
+ if (path.extname(relative) === ".ts") {
88
+ const names = tokens.flatMap((token, index) => token === "export" && tokens[index + 1] === "const" ? [tokens[index + 2]] : []);
89
+ const group = yield* fromGroupModulePath(relative);
90
+ const template = yield* render({
91
+ functionNames: names,
92
+ registeredFunctionsImportPath: yield* registeredFunctionsImportPathForGroup(group, absolute),
93
+ useNode: tokens[0] === "\"use node\""
94
+ });
95
+ if (names.length > 0 && new Set(names).size === names.length && matchesShape(tokens, tokenize(template, absolute, path))) continue;
96
+ }
97
+ }
98
+ refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));
99
+ }
100
+ if (refused.length > 0) return yield* new UnownedConvexEntrypointError({ filePaths: refused.sort() });
101
+ });
17
102
  const render = ({ functionNames, registeredFunctionsImportPath, useNode = false }) => renderEffect({
18
103
  functionNames,
19
104
  registeredFunctionsImportPath,
@@ -41,20 +126,20 @@ const generateGroupModuleEffect = Effect.fnUntraced(function* ({ groupPath, func
41
126
  const path = yield* Path.Path;
42
127
  const convexDirectory = yield* ConvexDirectory.get;
43
128
  const relativeModulePath = yield* modulePath(groupPath);
44
- const modulePath$3 = path.join(convexDirectory, relativeModulePath);
45
- const directoryPath = path.dirname(modulePath$3);
129
+ const modulePath$2 = path.join(convexDirectory, relativeModulePath);
130
+ const directoryPath = path.dirname(modulePath$2);
46
131
  if (!(yield* fs.exists(directoryPath))) yield* fs.makeDirectory(directoryPath, { recursive: true });
47
132
  const functionsContentsString = yield* render({
48
133
  functionNames,
49
134
  registeredFunctionsImportPath,
50
135
  useNode
51
136
  });
52
- if (!(yield* fs.exists(modulePath$3))) {
53
- yield* fs.writeFileString(modulePath$3, functionsContentsString);
137
+ if (!(yield* fs.exists(modulePath$2))) {
138
+ yield* fs.writeFileString(modulePath$2, functionsContentsString);
54
139
  return "Added";
55
140
  }
56
- if ((yield* fs.readFileString(modulePath$3)) !== functionsContentsString) {
57
- yield* fs.writeFileString(modulePath$3, functionsContentsString);
141
+ if ((yield* fs.readFileString(modulePath$2)) !== functionsContentsString) {
142
+ yield* fs.writeFileString(modulePath$2, functionsContentsString);
58
143
  return "Modified";
59
144
  }
60
145
  return "Unchanged";
@@ -92,18 +177,9 @@ const applyFunctionPlan = Effect.fnUntraced(function* (plan) {
92
177
  yield* writeGroups(plan.changed);
93
178
  });
94
179
  const getGroupPathsFromFs = Effect.gen(function* () {
95
- const fs = yield* FileSystem.FileSystem;
96
180
  const path = yield* Path.Path;
97
- const convexDirectory = yield* ConvexDirectory.get;
98
- const RESERVED_CONVEX_TS_FILE_NAMES = /* @__PURE__ */ new Set([
99
- "schema.ts",
100
- "http.ts",
101
- "crons.ts",
102
- "auth.config.ts",
103
- "convex.config.ts"
104
- ]);
105
- const allConvexPaths = yield* fs.readDirectory(convexDirectory, { recursive: true });
106
- const groupPathArray = yield* pipe(allConvexPaths, Array.filter((convexPath) => path.extname(convexPath) === ".ts" && !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) && path.basename(path.dirname(convexPath)) !== "_generated"), Effect.forEach((groupModulePath) => fromGroupModulePath(groupModulePath)));
181
+ const allConvexPaths = yield* getEntrypoints;
182
+ const groupPathArray = yield* pipe(allConvexPaths, Array.filter((convexPath) => path.extname(convexPath) === ".ts" && !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath))), Effect.forEach((groupModulePath) => fromGroupModulePath(groupModulePath)));
107
183
  return GroupPaths.make(HashSet.fromIterable(groupPathArray));
108
184
  });
109
185
  const removeGroups = Effect.fnUntraced(function* (groupPaths) {
@@ -111,9 +187,9 @@ const removeGroups = Effect.fnUntraced(function* (groupPaths) {
111
187
  const convexDirectory = yield* ConvexDirectory.get;
112
188
  yield* Effect.all(HashSet.map(groupPaths, (groupPath) => Effect.gen(function* () {
113
189
  const relativeModulePath = yield* modulePath(groupPath);
114
- const modulePath$2 = path.join(convexDirectory, relativeModulePath);
190
+ const modulePath$1 = path.join(convexDirectory, relativeModulePath);
115
191
  yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);
116
- yield* removePathIfExists(modulePath$2);
192
+ yield* removePathIfExists(modulePath$1);
117
193
  yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);
118
194
  })), { concurrency: "unbounded" });
119
195
  });
@@ -121,17 +197,17 @@ const writeGroups = (groups) => Effect.forEach(groups, Effect.fnUntraced(functio
121
197
  const path = yield* Path.Path;
122
198
  const convexDirectory = yield* ConvexDirectory.get;
123
199
  const relativeModulePath = yield* modulePath(group.path);
124
- const modulePath$1 = path.join(convexDirectory, relativeModulePath);
125
- const registeredFunctionsImportPath = yield* registeredFunctionsImportPathForGroup(group.path, modulePath$1);
200
+ const modulePath$3 = path.join(convexDirectory, relativeModulePath);
201
+ const registeredFunctionsImportPath = yield* registeredFunctionsImportPathForGroup(group.path, modulePath$3);
126
202
  const change = yield* generateGroupModule({
127
203
  groupPath: group.path,
128
204
  functionNames: group.functionNames,
129
205
  registeredFunctionsImportPath,
130
206
  useNode: group.runtime === "Node"
131
207
  });
132
- yield* Match.value(change).pipe(Match.when("Added", () => logFileAdded(modulePath$1)), Match.when("Modified", () => logFileModified(modulePath$1)), Match.when("Unchanged", () => Effect.void), Match.exhaustive);
208
+ yield* Match.value(change).pipe(Match.when("Added", () => logFileAdded(modulePath$3)), Match.when("Modified", () => logFileModified(modulePath$3)), Match.when("Unchanged", () => Effect.void), Match.exhaustive);
133
209
  }));
134
210
  //#endregion
135
- export { applyFunctionPlan, generateFunctions, generateGroupModule, registeredFunctionsImportPathForGroup, removeGroups, render, writeGroups };
211
+ export { applyFunctionPlan, assertOwnedEntrypoints, generateFunctions, generateGroupModule, registeredFunctionsImportPathForGroup, removeGroups, render, writeGroups };
136
212
 
137
213
  //# sourceMappingURL=FunctionModule.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionModule.mjs","names":["GroupPath.modulePath","modulePath","GenerationSnapshot.plan","GenerationSnapshot.functionPaths","GroupPath.fromGroupModulePath"],"sources":["../src/FunctionModule.ts"],"sourcesContent":["import * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot\";\nimport * as GroupPath from \"./GroupPath\";\nimport * as GroupPaths from \"./GroupPaths\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log\";\nimport { ConfectDirectory } from \"./ConfectDirectory\";\nimport { ConvexDirectory } from \"./ConvexDirectory\";\nimport { removePathIfExists, toModuleImportPath } from \"./utils\";\n\nexport const render = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: Parameters<typeof renderEffect>[0]) =>\n renderEffect({ functionNames, registeredFunctionsImportPath, useNode });\n\nconst renderEffect = Effect.fnUntraced(function* ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(`\"use node\";`);\n yield* cbw.blankLine();\n }\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n yield* Effect.forEach(functionNames, (name) =>\n cbw.writeLine(`export const ${name} = registeredFunctions.${name};`),\n );\n\n return yield* cbw.toString();\n});\n\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: Parameters<typeof generateGroupModuleEffect>[0]) =>\n generateGroupModuleEffect({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n });\n\nconst generateGroupModuleEffect = Effect.fnUntraced(function* ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const functionsContentsString = yield* render({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n});\n\n/**\n * Compute the module import specifier (relative to `modulePath`) for a group's\n * registry file under `confect/_generated/registeredFunctions/`. The registry\n * path mirrors the group's path one-to-one (see\n * `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and\n * Node groups.\n */\nexport const registeredFunctionsImportPathForGroup = Effect.fnUntraced(\n function* (groupPath: GroupPath.GroupPath, modulePath: string) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const registeredFunctionsPath =\n path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n ...groupPath.pathSegments,\n ) + \".ts\";\n\n return yield* toModuleImportPath(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n },\n);\n\nconst logGroupPaths = Effect.fnUntraced(function* <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n): Effect.fn.Return<void, never, R | Path.Path | ConvexDirectory> {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(\n groupPaths,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n});\n\nexport const generateFunctions = Effect.fnUntraced(function* (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n) {\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n yield* applyFunctionPlan(GenerationSnapshot.plan(snapshot, groupPathsFromFs));\n return GenerationSnapshot.functionPaths(snapshot);\n});\n\nexport const applyFunctionPlan = Effect.fnUntraced(function* (\n plan: GenerationSnapshot.ModulePlan,\n) {\n const removed = GroupPaths.GroupPaths.make(\n HashSet.fromIterable(plan.removed),\n );\n yield* removeGroups(removed);\n yield* logGroupPaths(removed, logFileRemoved);\n yield* writeGroups(plan.changed);\n});\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n ]);\n\n const allConvexPaths = yield* fs.readDirectory(convexDirectory, {\n recursive: true,\n });\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&\n path.basename(path.dirname(convexPath)) !== \"_generated\",\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return GroupPaths.GroupPaths.make(HashSet.fromIterable(groupPathArray));\n});\n\nexport const removeGroups = Effect.fnUntraced(function* (\n groupPaths: GroupPaths.GroupPaths,\n) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* removePathIfExists(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n});\n\nexport const writeGroups = (\n groups: ReadonlyArray<GenerationSnapshot.GroupSummary>,\n) =>\n Effect.forEach(\n groups,\n Effect.fnUntraced(function* (group: GenerationSnapshot.GroupSummary) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const relativeModulePath = yield* GroupPath.modulePath(group.path);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n const registeredFunctionsImportPath =\n yield* registeredFunctionsImportPathForGroup(group.path, modulePath);\n const change = yield* generateGroupModule({\n groupPath: group.path,\n functionNames: group.functionNames,\n registeredFunctionsImportPath,\n useNode: group.runtime === \"Node\",\n });\n yield* Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(modulePath)),\n Match.when(\"Modified\", () => logFileModified(modulePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n );\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAa,UAAU,EACrB,eACA,+BACA,UAAU,YAEV,aAAa;CAAE;CAAe;CAA+B;AAAQ,CAAC;AAExE,MAAM,eAAe,OAAO,WAAW,WAAW,EAChD,eACA,+BACA,UAAU,SAKT;CACD,MAAM,MAAM,IAAI,gBAAgB,EAAE,sBAAsB,EAAE,CAAC;CAE3D,IAAI,SAAS;EACX,OAAO,IAAI,UAAU,aAAa;EAClC,OAAO,IAAI,UAAU;CACvB;CAEA,OAAO,IAAI,UACT,oCAAoC,8BAA8B,GACpE;CACA,OAAO,IAAI,QAAQ;CACnB,OAAO,OAAO,QAAQ,gBAAgB,SACpC,IAAI,UAAU,gBAAgB,KAAK,yBAAyB,KAAK,EAAE,CACrE;CAEA,OAAO,OAAO,IAAI,SAAS;AAC7B,CAAC;AAED,MAAa,uBAAuB,EAClC,WACA,eACA,+BACA,UAAU,YAEV,0BAA0B;CACxB;CACA;CACA;CACA;AACF,CAAC;AAEH,MAAM,4BAA4B,OAAO,WAAW,WAAW,EAC7D,WACA,eACA,+BACA,UAAU,SAMT;CACD,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,kBAAkB,OAAO,gBAAgB;CAE/C,MAAM,qBAAqB,OAAOA,WAAqB,SAAS;CAChE,MAAMC,eAAa,KAAK,KAAK,iBAAiB,kBAAkB;CAEhE,MAAM,gBAAgB,KAAK,QAAQA,YAAU;CAC7C,IAAI,EAAE,OAAO,GAAG,OAAO,aAAa,IAClC,OAAO,GAAG,cAAc,eAAe,EAAE,WAAW,KAAK,CAAC;CAG5D,MAAM,0BAA0B,OAAO,OAAO;EAC5C;EACA;EACA;CACF,CAAC;CAED,IAAI,EAAE,OAAO,GAAG,OAAOA,YAA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ACxC,WAAW,MAAM;EACjB,eAAe,MAAM;EACrB;EACA,SAAS,MAAM,YAAY;CAC7B,CAAC;CACD,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KACzB,MAAM,KAAK,eAAe,aAAaA,YAAU,CAAC,GAClD,MAAM,KAAK,kBAAkB,gBAAgBA,YAAU,CAAC,GACxD,MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,UACR;AACF,CAAC,CACH"}
1
+ {"version":3,"file":"FunctionModule.mjs","names":["templates.http","templates.declaredHttp","templates.crons","GroupPath.fromGroupModulePath","GroupPath.modulePath","modulePath","GenerationSnapshot.plan","GenerationSnapshot.functionPaths"],"sources":["../src/FunctionModule.ts"],"sourcesContent":["import * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport { UnownedConvexEntrypointError } from \"./CodegenError.js\";\nimport * as templates from \"./templates.js\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport * as GroupPaths from \"./GroupPaths.js\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter.js\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n} from \"./utils.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\n\nconst RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n]);\n\n// Keep ownership and removal aligned with Convex's bundler entryPoints filter.\nconst getEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const files = yield* fs.readDirectory(convex, { recursive: true });\n const components = files\n .filter(\n (file) =>\n path.basename(file) === \"convex.config.ts\" &&\n path.dirname(file) !== \".\",\n )\n .map((file) => path.dirname(file) + path.sep);\n return files.filter((file) => {\n const base = path.basename(file);\n return (\n !file.startsWith(\"_generated\" + path.sep) &&\n !components.some((component) => file.startsWith(component)) &&\n /\\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) &&\n !base.startsWith(\".\") &&\n !base.startsWith(\"#\") &&\n (base.match(/\\./g)?.length ?? 0) === 1 &&\n base !== \"schema.ts\" &&\n base !== \"schema.js\" &&\n !file.includes(\" \")\n );\n });\n});\n\nconst tokenize = (\n source: string,\n modulePath: string,\n path: Path.Path,\n): string[] | undefined => {\n const token =\n /\\s+|\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/|\"(?:\\\\.|[^\"\\\\\\r\\n])*\"|'(?:\\\\.|[^'\\\\\\r\\n])*'|[$A-Z_a-z][$\\w]*|[{}()[\\].,:;=]/y;\n const tokens: string[] = [];\n while (token.lastIndex < source.length) {\n const match = token.exec(source);\n if (match === null) return undefined;\n const value = match[0];\n if (/^\\s|^\\//.test(value)) continue;\n if (value.startsWith('\"') || value.startsWith(\"'\")) {\n const literal = value.slice(1, -1);\n tokens.push(\n JSON.stringify(\n literal.startsWith(\".\")\n ? path.resolve(\n path.dirname(modulePath),\n literal.replace(/\\.js$/, \"\"),\n )\n : literal,\n ),\n );\n } else tokens.push(value);\n }\n return tokens;\n};\n\nconst matchesShape = (\n actual: readonly string[],\n expected: readonly string[],\n) => {\n let index = 0;\n for (const token of expected) {\n if (token === \";\" && actual[index] !== \";\") continue;\n if (actual[index] === \",\" && (token === \"}\" || token === \")\")) index++;\n if (actual[index++] !== token) return false;\n }\n return index === actual.length;\n};\n\nexport const assertOwnedEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const confect = yield* ConfectDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const importFromConvex = (file: string) =>\n toModuleImportPath(path.relative(convex, path.join(confect, file)));\n const optional = new Map([\n [\n \"http.ts\",\n [\n yield* templates.http({\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n runtimeImportPath: yield* importFromConvex(\"runtime.ts\"),\n }),\n ],\n ],\n [\n \"crons.ts\",\n [\n yield* templates.crons({\n cronsImportPath: yield* importFromConvex(\"crons.ts\"),\n }),\n ],\n ],\n ]);\n const refused: string[] = [];\n for (const relative of yield* getEntrypoints) {\n const absolute = path.join(convex, relative);\n const tokens = tokenize(yield* fs.readFileString(absolute), absolute, path);\n if (tokens !== undefined) {\n if (\n optional\n .get(relative)\n ?.some((template) =>\n matchesShape(tokens, tokenize(template, absolute, path)!),\n )\n )\n continue;\n if (path.extname(relative) === \".ts\") {\n const names = tokens.flatMap((token, index) =>\n token === \"export\" && tokens[index + 1] === \"const\"\n ? [tokens[index + 2]!]\n : [],\n );\n const group = yield* GroupPath.fromGroupModulePath(relative);\n const template = yield* render({\n functionNames: names,\n registeredFunctionsImportPath:\n yield* registeredFunctionsImportPathForGroup(group, absolute),\n useNode: tokens[0] === '\"use node\"',\n });\n if (\n names.length > 0 &&\n new Set(names).size === names.length &&\n matchesShape(tokens, tokenize(template, absolute, path)!)\n )\n continue;\n }\n }\n refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));\n }\n if (refused.length > 0)\n return yield* new UnownedConvexEntrypointError({\n filePaths: refused.sort(),\n });\n});\n\nexport const render = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: Parameters<typeof renderEffect>[0]) =>\n renderEffect({ functionNames, registeredFunctionsImportPath, useNode });\n\nconst renderEffect = Effect.fnUntraced(function* ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(`\"use node\";`);\n yield* cbw.blankLine();\n }\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n yield* Effect.forEach(functionNames, (name) =>\n cbw.writeLine(`export const ${name} = registeredFunctions.${name};`),\n );\n\n return yield* cbw.toString();\n});\n\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: Parameters<typeof generateGroupModuleEffect>[0]) =>\n generateGroupModuleEffect({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n });\n\nconst generateGroupModuleEffect = Effect.fnUntraced(function* ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n}) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const functionsContentsString = yield* render({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n});\n\n/**\n * Compute the module import specifier (relative to `modulePath`) for a group's\n * registry file under `confect/_generated/registeredFunctions/`. The registry\n * path mirrors the group's path one-to-one (see\n * `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and\n * Node groups.\n */\nexport const registeredFunctionsImportPathForGroup = Effect.fnUntraced(\n function* (groupPath: GroupPath.GroupPath, modulePath: string) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const registeredFunctionsPath =\n path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n ...groupPath.pathSegments,\n ) + \".ts\";\n\n return yield* toModuleImportPath(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n },\n);\n\nconst logGroupPaths = Effect.fnUntraced(function* <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n): Effect.fn.Return<void, never, R | Path.Path | ConvexDirectory> {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(\n groupPaths,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n});\n\nexport const generateFunctions = Effect.fnUntraced(function* (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n) {\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n yield* applyFunctionPlan(GenerationSnapshot.plan(snapshot, groupPathsFromFs));\n return GenerationSnapshot.functionPaths(snapshot);\n});\n\nexport const applyFunctionPlan = Effect.fnUntraced(function* (\n plan: GenerationSnapshot.ModulePlan,\n) {\n const removed = GroupPaths.GroupPaths.make(\n HashSet.fromIterable(plan.removed),\n );\n yield* removeGroups(removed);\n yield* logGroupPaths(removed, logFileRemoved);\n yield* writeGroups(plan.changed);\n});\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const path = yield* Path.Path;\n const allConvexPaths = yield* getEntrypoints;\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)),\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return GroupPaths.GroupPaths.make(HashSet.fromIterable(groupPathArray));\n});\n\nexport const removeGroups = Effect.fnUntraced(function* (\n groupPaths: GroupPaths.GroupPaths,\n) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* removePathIfExists(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n});\n\nexport const writeGroups = (\n groups: ReadonlyArray<GenerationSnapshot.GroupSummary>,\n) =>\n Effect.forEach(\n groups,\n Effect.fnUntraced(function* (group: GenerationSnapshot.GroupSummary) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const relativeModulePath = yield* GroupPath.modulePath(group.path);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n const registeredFunctionsImportPath =\n yield* registeredFunctionsImportPathForGroup(group.path, modulePath);\n const change = yield* generateGroupModule({\n groupPath: group.path,\n functionNames: group.functionNames,\n registeredFunctionsImportPath,\n useNode: group.runtime === \"Node\",\n });\n yield* Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(modulePath)),\n Match.when(\"Modified\", () => logFileModified(modulePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n );\n }),\n );\n"],"mappings":";;;;;;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AAkB;EAEhE,OAAO,OAAO,SAAS,mBAAmB,mBAAmB,KAAK;EAElE,OAAO,mBAAmBA,YAAU;EACpC,OAAO,OAAO,SAAS,UAAU,mBAAmB,UAAU;CAChE,CAAC,CACH,GACA,EAAE,aAAa,YAAY,CAC7B;AACF,CAAC;AAED,MAAa,eACX,WAEA,OAAO,QACL,QACA,OAAO,WAAW,WAAW,OAAwC;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,kBAAkB,OAAO,gBAAgB;CAC/C,MAAM,qBAAqB,OAAOD,WAAqB,MAAM,IAAI;CACjE,MAAMC,eAAa,KAAK,KAAK,iBAAiB,kBAAkB;CAChE,MAAM,gCACJ,OAAO,sCAAsC,MAAM,MAAMA,YAAU;CACrE,MAAM,SAAS,OAAO,oBAAoB;EACxC,WAAW,MAAM;EACjB,eAAe,MAAM;EACrB;EACA,SAAS,MAAM,YAAY;CAC7B,CAAC;CACD,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KACzB,MAAM,KAAK,eAAe,aAAaA,YAAU,CAAC,GAClD,MAAM,KAAK,kBAAkB,gBAAgBA,YAAU,CAAC,GACxD,MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,UACR;AACF,CAAC,CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionPath.mjs","names":["GroupPath.GroupPath"],"sources":["../src/FunctionPath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as GroupPath from \"./GroupPath\";\n\n/**\n * The path to a function in the Confect API.\n */\nexport class FunctionPath extends Schema.Class<FunctionPath>(\"FunctionPath\")({\n groupPath: GroupPath.GroupPath,\n name: Schema.NonEmptyString,\n}) {}\n\n/**\n * Get the group path from a function path.\n */\nexport const groupPath = (functionPath: FunctionPath): GroupPath.GroupPath =>\n functionPath.groupPath;\n\n/**\n * Get the function name from a function path.\n */\nexport const name = (functionPath: FunctionPath): string => functionPath.name;\n\n/**\n * Get the function path as a string.\n */\nexport const toString = (functionPath: FunctionPath): string =>\n `${GroupPath.toString(functionPath.groupPath)}.${functionPath.name}`;\n"],"mappings":";;;;;;AAMA,IAAa,eAAb,cAAkC,OAAO,MAAoB,cAAc,CAAC,CAAC;CAC3E,WAAWA;CACX,MAAM,OAAO;AACf,CAAC,CAAC,CAAC,CAAC;;;;AAKJ,MAAa,aAAa,iBACxB,aAAa"}
1
+ {"version":3,"file":"FunctionPath.mjs","names":["GroupPath.GroupPath"],"sources":["../src/FunctionPath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as GroupPath from \"./GroupPath.js\";\n\n/**\n * The path to a function in the Confect API.\n */\nexport class FunctionPath extends Schema.Class<FunctionPath>(\"FunctionPath\")({\n groupPath: GroupPath.GroupPath,\n name: Schema.NonEmptyString,\n}) {}\n\n/**\n * Get the group path from a function path.\n */\nexport const groupPath = (functionPath: FunctionPath): GroupPath.GroupPath =>\n functionPath.groupPath;\n\n/**\n * Get the function name from a function path.\n */\nexport const name = (functionPath: FunctionPath): string => functionPath.name;\n\n/**\n * Get the function path as a string.\n */\nexport const toString = (functionPath: FunctionPath): string =>\n `${GroupPath.toString(functionPath.groupPath)}.${functionPath.name}`;\n"],"mappings":";;;;;;AAMA,IAAa,eAAb,cAAkC,OAAO,MAAoB,cAAc,CAAC,CAAC;CAC3E,WAAWA;CACX,MAAM,OAAO;AACf,CAAC,CAAC,CAAC,CAAC;;;;AAKJ,MAAa,aAAa,iBACxB,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionPaths.mjs","names":["FunctionPath.FunctionPath","GroupPath.make","GroupPath.append","FunctionPath.groupPath"],"sources":["../src/FunctionPaths.ts"],"sourcesContent":["import { type GroupSpec, Spec } from \"@confect/core\";\nimport { pipe } from \"effect/Function\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as FunctionPath from \"./FunctionPath\";\nimport * as GroupPath from \"./GroupPath\";\nimport * as GroupPaths from \"./GroupPaths\";\n\nexport const FunctionPaths = Schema.HashSet(FunctionPath.FunctionPath).pipe(\n Schema.brand(\"@confect/cli/FunctionPaths\"),\n);\nexport type FunctionPaths = typeof FunctionPaths.Type;\n\nexport const make = (spec: Spec.AnyWithProps): FunctionPaths =>\n makeHelper(\n Spec.groups(spec),\n Option.none(),\n FunctionPaths.make(HashSet.empty()),\n );\n\nconst makeHelper = (\n groups: {\n [key: string]: GroupSpec.AnyWithProps;\n },\n currentGroupPath: Option.Option<GroupPath.GroupPath>,\n apiPaths: FunctionPaths,\n): FunctionPaths =>\n Record.reduce(groups, apiPaths, (acc, group, groupName) => {\n const groupPath = Option.match(currentGroupPath, {\n onNone: () => GroupPath.make([groupName]),\n onSome: (path) => GroupPath.append(path, groupName),\n });\n\n const accWithFunctions = Record.reduce(\n group.functions,\n acc,\n (acc_, _fn, name) =>\n FunctionPaths.make(\n HashSet.add(\n acc_,\n FunctionPath.FunctionPath.make({\n groupPath,\n name,\n }),\n ),\n ),\n );\n\n return makeHelper(group.groups, Option.some(groupPath), accWithFunctions);\n });\n\nexport const groupPaths = (\n functionPaths: FunctionPaths,\n): GroupPaths.GroupPaths =>\n pipe(functionPaths, HashSet.map(FunctionPath.groupPath), (paths) =>\n GroupPaths.GroupPaths.make(paths),\n );\n\nexport const diff = (\n previousFunctions: FunctionPaths,\n currentFunctions: FunctionPaths,\n): {\n functionsAdded: FunctionPaths;\n functionsRemoved: FunctionPaths;\n groupsRemoved: GroupPaths.GroupPaths;\n groupsAdded: GroupPaths.GroupPaths;\n groupsChanged: GroupPaths.GroupPaths;\n} => {\n const currentGroups = groupPaths(currentFunctions);\n const previousGroups = groupPaths(previousFunctions);\n\n const groupsAdded = GroupPaths.GroupPaths.make(\n HashSet.difference(currentGroups, previousGroups),\n );\n const groupsRemoved = GroupPaths.GroupPaths.make(\n HashSet.difference(previousGroups, currentGroups),\n );\n\n const functionsAdded = FunctionPaths.make(\n HashSet.difference(currentFunctions, previousFunctions),\n );\n const existingGroupsToWhichFunctionsWereAdded = GroupPaths.GroupPaths.make(\n HashSet.intersection(currentGroups, groupPaths(functionsAdded)),\n );\n\n const functionsRemoved = FunctionPaths.make(\n HashSet.difference(previousFunctions, currentFunctions),\n );\n const existingGroupsToWhichFunctionsWereRemoved = GroupPaths.GroupPaths.make(\n HashSet.intersection(previousGroups, groupPaths(functionsRemoved)),\n );\n\n const groupsChanged = pipe(\n existingGroupsToWhichFunctionsWereAdded,\n HashSet.union(existingGroupsToWhichFunctionsWereRemoved),\n HashSet.difference(HashSet.union(groupsAdded, groupsRemoved)),\n (paths) => GroupPaths.GroupPaths.make(paths),\n );\n\n return {\n functionsAdded,\n functionsRemoved,\n groupsRemoved,\n groupsAdded,\n groupsChanged,\n };\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,gBAAgB,OAAO,QAAQA,YAAyB,CAAC,CAAC,KACrE,OAAO,MAAM,4BAA4B,CAC3C;AAGA,MAAa,QAAQ,SACnB,WACE,KAAK,OAAO,IAAI,GAChB,OAAO,KAAK,GACZ,cAAc,KAAK,QAAQ,MAAM,CAAC,CACpC;AAEF,MAAM,cACJ,QAGA,kBACA,aAEA,OAAO,OAAO,QAAQ,WAAW,KAAK,OAAO,cAAc;CACzD,MAAM,YAAY,OAAO,MAAM,kBAAkB;EAC/C,cAAcC,OAAe,CAAC,SAAS,CAAC;EACxC,SAAS,SAASC,OAAiB,MAAM,SAAS;CACpD,CAAC;CAED,MAAM,mBAAmB,OAAO,OAC9B,MAAM,WACN,MACC,MAAM,KAAK,SACV,cAAc,KACZ,QAAQ,IACN,MAAA,aAC0B,KAAK;EAC7B;EACA;CACF,CAAC,CACH,CACF,CACJ;CAEA,OAAO,WAAW,MAAM,QAAQ,OAAO,KAAK,SAAS,GAAG,gBAAgB;AAC1E,CAAC;AAEH,MAAa,cACX,kBAEA,KAAK,eAAe,QAAQ,IAAIC,SAAsB,IAAI,UAAA,WAClC,KAAK,KAAK,CAClC;AAEF,MAAa,QACX,mBACA,qBAOG;CACH,MAAM,gBAAgB,WAAW,gBAAgB;CACjD,MAAM,iBAAiB,WAAW,iBAAiB;CAEnD,MAAM,cAAA,WAAoC,KACxC,QAAQ,WAAW,eAAe,cAAc,CAClD;CACA,MAAM,gBAAA,WAAsC,KAC1C,QAAQ,WAAW,gBAAgB,aAAa,CAClD;CAEA,MAAM,iBAAiB,cAAc,KACnC,QAAQ,WAAW,kBAAkB,iBAAiB,CACxD;CACA,MAAM,0CAAA,WAAgE,KACpE,QAAQ,aAAa,eAAe,WAAW,cAAc,CAAC,CAChE;CAEA,MAAM,mBAAmB,cAAc,KACrC,QAAQ,WAAW,mBAAmB,gBAAgB,CACxD;CACA,MAAM,4CAAA,WAAkE,KACtE,QAAQ,aAAa,gBAAgB,WAAW,gBAAgB,CAAC,CACnE;CASA,OAAO;EACL;EACA;EACA;EACA;EACA,eAZoB,KACpB,yCACA,QAAQ,MAAM,yCAAyC,GACvD,QAAQ,WAAW,QAAQ,MAAM,aAAa,aAAa,CAAC,IAC3D,UAAA,WAAgC,KAAK,KAAK,CAQ/B;CACd;AACF"}
1
+ {"version":3,"file":"FunctionPaths.mjs","names":["FunctionPath.FunctionPath","GroupPath.make","GroupPath.append","FunctionPath.groupPath"],"sources":["../src/FunctionPaths.ts"],"sourcesContent":["import { type GroupSpec, Spec } from \"@confect/core\";\nimport { pipe } from \"effect/Function\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as FunctionPath from \"./FunctionPath.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport * as GroupPaths from \"./GroupPaths.js\";\n\nexport const FunctionPaths = Schema.HashSet(FunctionPath.FunctionPath).pipe(\n Schema.brand(\"@confect/cli/FunctionPaths\"),\n);\nexport type FunctionPaths = typeof FunctionPaths.Type;\n\nexport const make = (spec: Spec.AnyWithProps): FunctionPaths =>\n makeHelper(\n Spec.groups(spec),\n Option.none(),\n FunctionPaths.make(HashSet.empty()),\n );\n\nconst makeHelper = (\n groups: {\n [key: string]: GroupSpec.AnyWithProps;\n },\n currentGroupPath: Option.Option<GroupPath.GroupPath>,\n apiPaths: FunctionPaths,\n): FunctionPaths =>\n Record.reduce(groups, apiPaths, (acc, group, groupName) => {\n const groupPath = Option.match(currentGroupPath, {\n onNone: () => GroupPath.make([groupName]),\n onSome: (path) => GroupPath.append(path, groupName),\n });\n\n const accWithFunctions = Record.reduce(\n group.functions,\n acc,\n (acc_, _fn, name) =>\n FunctionPaths.make(\n HashSet.add(\n acc_,\n FunctionPath.FunctionPath.make({\n groupPath,\n name,\n }),\n ),\n ),\n );\n\n return makeHelper(group.groups, Option.some(groupPath), accWithFunctions);\n });\n\nexport const groupPaths = (\n functionPaths: FunctionPaths,\n): GroupPaths.GroupPaths =>\n pipe(functionPaths, HashSet.map(FunctionPath.groupPath), (paths) =>\n GroupPaths.GroupPaths.make(paths),\n );\n\nexport const diff = (\n previousFunctions: FunctionPaths,\n currentFunctions: FunctionPaths,\n): {\n functionsAdded: FunctionPaths;\n functionsRemoved: FunctionPaths;\n groupsRemoved: GroupPaths.GroupPaths;\n groupsAdded: GroupPaths.GroupPaths;\n groupsChanged: GroupPaths.GroupPaths;\n} => {\n const currentGroups = groupPaths(currentFunctions);\n const previousGroups = groupPaths(previousFunctions);\n\n const groupsAdded = GroupPaths.GroupPaths.make(\n HashSet.difference(currentGroups, previousGroups),\n );\n const groupsRemoved = GroupPaths.GroupPaths.make(\n HashSet.difference(previousGroups, currentGroups),\n );\n\n const functionsAdded = FunctionPaths.make(\n HashSet.difference(currentFunctions, previousFunctions),\n );\n const existingGroupsToWhichFunctionsWereAdded = GroupPaths.GroupPaths.make(\n HashSet.intersection(currentGroups, groupPaths(functionsAdded)),\n );\n\n const functionsRemoved = FunctionPaths.make(\n HashSet.difference(previousFunctions, currentFunctions),\n );\n const existingGroupsToWhichFunctionsWereRemoved = GroupPaths.GroupPaths.make(\n HashSet.intersection(previousGroups, groupPaths(functionsRemoved)),\n );\n\n const groupsChanged = pipe(\n existingGroupsToWhichFunctionsWereAdded,\n HashSet.union(existingGroupsToWhichFunctionsWereRemoved),\n HashSet.difference(HashSet.union(groupsAdded, groupsRemoved)),\n (paths) => GroupPaths.GroupPaths.make(paths),\n );\n\n return {\n functionsAdded,\n functionsRemoved,\n groupsRemoved,\n groupsAdded,\n groupsChanged,\n };\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,gBAAgB,OAAO,QAAQA,YAAyB,CAAC,CAAC,KACrE,OAAO,MAAM,4BAA4B,CAC3C;AAGA,MAAa,QAAQ,SACnB,WACE,KAAK,OAAO,IAAI,GAChB,OAAO,KAAK,GACZ,cAAc,KAAK,QAAQ,MAAM,CAAC,CACpC;AAEF,MAAM,cACJ,QAGA,kBACA,aAEA,OAAO,OAAO,QAAQ,WAAW,KAAK,OAAO,cAAc;CACzD,MAAM,YAAY,OAAO,MAAM,kBAAkB;EAC/C,cAAcC,OAAe,CAAC,SAAS,CAAC;EACxC,SAAS,SAASC,OAAiB,MAAM,SAAS;CACpD,CAAC;CAED,MAAM,mBAAmB,OAAO,OAC9B,MAAM,WACN,MACC,MAAM,KAAK,SACV,cAAc,KACZ,QAAQ,IACN,MAAA,aAC0B,KAAK;EAC7B;EACA;CACF,CAAC,CACH,CACF,CACJ;CAEA,OAAO,WAAW,MAAM,QAAQ,OAAO,KAAK,SAAS,GAAG,gBAAgB;AAC1E,CAAC;AAEH,MAAa,cACX,kBAEA,KAAK,eAAe,QAAQ,IAAIC,SAAsB,IAAI,UAAA,WAClC,KAAK,KAAK,CAClC;AAEF,MAAa,QACX,mBACA,qBAOG;CACH,MAAM,gBAAgB,WAAW,gBAAgB;CACjD,MAAM,iBAAiB,WAAW,iBAAiB;CAEnD,MAAM,cAAA,WAAoC,KACxC,QAAQ,WAAW,eAAe,cAAc,CAClD;CACA,MAAM,gBAAA,WAAsC,KAC1C,QAAQ,WAAW,gBAAgB,aAAa,CAClD;CAEA,MAAM,iBAAiB,cAAc,KACnC,QAAQ,WAAW,kBAAkB,iBAAiB,CACxD;CACA,MAAM,0CAAA,WAAgE,KACpE,QAAQ,aAAa,eAAe,WAAW,cAAc,CAAC,CAChE;CAEA,MAAM,mBAAmB,cAAc,KACrC,QAAQ,WAAW,mBAAmB,gBAAgB,CACxD;CACA,MAAM,4CAAA,WAAkE,KACtE,QAAQ,aAAa,gBAAgB,WAAW,gBAAgB,CAAC,CACnE;CASA,OAAO;EACL;EACA;EACA;EACA;EACA,eAZoB,KACpB,yCACA,QAAQ,MAAM,yCAAyC,GACvD,QAAQ,WAAW,QAAQ,MAAM,aAAa,aAAa,CAAC,IAC3D,UAAA,WAAgC,KAAK,KAAK,CAQ/B;CACd;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"GenerationSnapshot.mjs","names":["GroupPath.GroupPath","GroupPath.make","GroupPath.append"],"sources":["../src/GenerationSnapshot.ts"],"sourcesContent":["import { type GroupSpec, Identifier } from \"@confect/core\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as String from \"effect/String\";\nimport { ParentChildNameCollisionError } from \"./CodegenError\";\nimport * as FunctionPath from \"./FunctionPath\";\nimport * as FunctionPaths from \"./FunctionPaths\";\nimport * as GroupPath from \"./GroupPath\";\nimport type { LoadedLeafModule } from \"./LeafModule\";\nimport * as SpecModulePath from \"./SpecModulePath\";\nimport { SnapshotError } from \"./SnapshotError\";\n\nexport { SnapshotError } from \"./SnapshotError\";\n\nexport const GroupSummary = Schema.Struct({\n path: GroupPath.GroupPath,\n runtime: Schema.Literals([\"Convex\", \"Node\"]),\n functionNames: Schema.Array(Schema.NonEmptyString),\n});\nexport interface GroupSummary extends Schema.Schema.Type<typeof GroupSummary> {}\n\nexport interface GroupTree {\n readonly runtime: \"Convex\" | \"Node\";\n readonly functionNames: ReadonlyArray<string>;\n readonly groups: { readonly [name: string]: GroupTree };\n}\n\nexport const GroupTree: Schema.Codec<GroupTree> = Schema.Struct({\n runtime: GroupSummary.fields.runtime,\n functionNames: GroupSummary.fields.functionNames,\n groups: Schema.Record(\n Schema.String,\n Schema.suspend(() => GroupTree),\n ),\n});\n\nclass Snapshot {\n readonly #leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>;\n\n private constructor(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ) {\n this.#leaves = leaves;\n }\n\n static parseLeaves(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ): Result.Result<GenerationSnapshot, ParentChildNameCollisionError> {\n return Result.map(\n parseNoParentChildNameCollisions(leaves),\n (parsed) => new Snapshot(parsed),\n );\n }\n\n get leaves(): HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree> {\n return this.#leaves;\n }\n}\n\nexport interface GenerationSnapshot extends Snapshot {}\n\nconst Entries = Schema.Array(Schema.Tuple([Schema.String, GroupTree]));\nconst CanonicalSpecPath = SpecModulePath.SpecModulePath.check(\n Schema.makeFilter((path) => !path.includes(\"\\\\\")),\n);\nconst rootPath = (path: SpecModulePath.SpecModulePath) =>\n GroupPath.make(String.split(path.slice(0, -\".spec.ts\".length), \"/\"));\n\nconst parseTree = (\n relativePath: SpecModulePath.SpecModulePath,\n path: GroupPath.GroupPath,\n tree: GroupTree,\n): Result.Result<GroupTree, SnapshotError> =>\n Result.gen(function* () {\n yield* Result.try({\n try: () => {\n for (const name of tree.functionNames)\n Identifier.validateConfectFunctionIdentifier(name);\n },\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (\n HashSet.size(HashSet.fromIterable(tree.functionNames)) !==\n tree.functionNames.length\n ) {\n return yield* Result.fail(\n new SnapshotError({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n for (const [name, child] of Object.entries(tree.groups)) {\n yield* Result.try({\n try: () => Identifier.validateConfectFunctionIdentifier(name),\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: [...path.pathSegments, name],\n }),\n });\n yield* parseTree(relativePath, GroupPath.append(path, name), child);\n }\n return tree;\n });\n\nconst fromEntries = (\n entries: ReadonlyArray<readonly [string, GroupTree]>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n let leaves = HashMap.empty<SpecModulePath.SpecModulePath, GroupTree>();\n for (const [key, tree] of entries) {\n const relativePath = yield* Schema.decodeResult(CanonicalSpecPath)(\n key,\n ).pipe(\n Result.mapError(\n (cause) =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath: key,\n pathSegments: [],\n cause,\n }),\n ),\n );\n const path = rootPath(relativePath);\n yield* Result.try({\n try: () => {\n for (const segment of path.pathSegments)\n Identifier.validateConfectFunctionIdentifier(segment);\n },\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (HashMap.has(leaves, relativePath)) {\n return yield* Result.fail(\n new SnapshotError({\n reason: \"DuplicateLeaf\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n const parsed = yield* parseTree(relativePath, path, tree);\n leaves = HashMap.set(leaves, relativePath, parsed);\n }\n return yield* Snapshot.parseLeaves(leaves);\n });\n\nexport const parse = (\n input: unknown,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Schema.decodeUnknownResult(Entries)(input).pipe(\n Result.mapError(\n (cause) =>\n new SnapshotError({\n reason: \"InvalidShape\",\n relativePath: \"\",\n pathSegments: [],\n cause,\n }),\n ),\n Result.flatMap(fromEntries),\n );\n\nexport const GenerationSnapshot = Entries.pipe(\n Schema.decodeTo(\n Schema.declare<GenerationSnapshot>((input) => input instanceof Snapshot),\n {\n decode: SchemaGetter.transformEffect((entries, options) =>\n Effect.fromResult(fromEntries(entries)).pipe(\n Effect.mapError(\n (error) =>\n new SchemaIssue.InvalidValue(\n {\n message: Match.value(error).pipe(\n Match.tagsExhaustive({\n SnapshotError: (failure) => failure.message,\n ParentChildNameCollisionError: (failure) =>\n `${failure.parentSpecPath} declares a ${failure.collisionKind} named ${failure.collisionName} that collides with ${failure.childSpecPath}`,\n }),\n ),\n },\n entries,\n options,\n ),\n ),\n ),\n ),\n encode: SchemaGetter.transform((snapshot) =>\n HashMap.toEntries(snapshot.leaves),\n ),\n },\n ),\n);\n\nconst summarize = (group: GroupSpec.AnyWithProps): GroupTree => ({\n runtime: group.runtime,\n functionNames: Record.keys(group.functions),\n groups: Record.map(group.groups, summarize),\n});\n\nexport const update = (\n snapshot: GenerationSnapshot,\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n if (leaves.length === 0) return snapshot;\n const replacement = yield* fromLoadedLeaves(leaves);\n return yield* Snapshot.parseLeaves(\n HashMap.union(snapshot.leaves, replacement.leaves),\n );\n });\n\nexport const fromLoadedLeaves = (\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n parse(\n leaves.map(\n (leaf) =>\n [\n leaf.relativePath.replaceAll(\"\\\\\", \"/\"),\n summarize(leaf.spec),\n ] as const,\n ),\n );\n\nconst groups = (snapshot: GenerationSnapshot): ReadonlyArray<GroupSummary> => {\n const visit = (\n path: GroupPath.GroupPath,\n tree: GroupTree,\n ): ReadonlyArray<GroupSummary> => [\n {\n path,\n runtime: tree.runtime,\n functionNames: Array.sort(tree.functionNames, String.Order),\n },\n ...Array.flatMap(\n Array.sort(Object.keys(tree.groups), String.Order),\n (name: string) => visit(GroupPath.append(path, name), tree.groups[name]!),\n ),\n ];\n return Array.flatMap(Array.fromIterable(snapshot.leaves), ([path, tree]) =>\n visit(rootPath(path), tree),\n );\n};\n\nexport const functionPaths = (\n snapshot: GenerationSnapshot,\n): FunctionPaths.FunctionPaths =>\n FunctionPaths.FunctionPaths.make(\n HashSet.fromIterable(\n Array.flatMap(groups(snapshot), (group) =>\n group.functionNames.map((name) =>\n FunctionPath.FunctionPath.make({ groupPath: group.path, name }),\n ),\n ),\n ),\n );\n\nconst generatedGroups = (snapshot: GenerationSnapshot) =>\n HashMap.fromIterable(\n Array.filterMap(groups(snapshot), (group) =>\n group.functionNames.length === 0\n ? Result.fail(undefined)\n : Result.succeed([group.path, group] as const),\n ),\n );\n\nexport interface ModulePlan {\n readonly removed: ReadonlyArray<GroupPath.GroupPath>;\n readonly changed: ReadonlyArray<GroupSummary>;\n}\n\nexport const plan = (\n snapshot: GenerationSnapshot,\n existing: Iterable<GroupPath.GroupPath>,\n): ModulePlan => {\n const current = generatedGroups(snapshot);\n return {\n removed: Array.fromIterable(existing).filter(\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.fromIterable(HashMap.values(current)),\n };\n};\n\nconst equivalentGroup = Schema.toEquivalence(GroupSummary);\n\nexport const diff = (\n before: GenerationSnapshot,\n after: GenerationSnapshot,\n): ModulePlan => {\n const previous = generatedGroups(before);\n const current = generatedGroups(after);\n return {\n removed: Array.filter(\n HashMap.keys(previous),\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.filter(HashMap.values(current), (group) => {\n const old = HashMap.get(previous, group.path);\n return Option.isNone(old) || !equivalentGroup(old.value, group);\n }),\n };\n};\n\nconst parseNoParentChildNameCollisions = (\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n): Result.Result<\n HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ParentChildNameCollisionError\n> => {\n for (const childPath of HashMap.keys(leaves)) {\n const segments = rootPath(childPath).pathSegments;\n for (let depth = 1; depth < segments.length; depth++) {\n const parentPath = SpecModulePath.SpecModulePath.make(\n `${segments.slice(0, depth).join(\"/\")}.spec.ts`,\n );\n const parent = HashMap.get(leaves, parentPath);\n if (Option.isNone(parent)) continue;\n const collisionName = segments[depth]!;\n const collisionKind = parent.value.functionNames.includes(collisionName)\n ? \"function\"\n : Object.hasOwn(parent.value.groups, collisionName)\n ? \"group\"\n : undefined;\n if (collisionKind !== undefined) {\n return Result.fail(\n new ParentChildNameCollisionError({\n parentSpecPath: parentPath,\n childSpecPath: childPath,\n collisionName,\n collisionKind,\n }),\n );\n }\n }\n }\n return Result.succeed(leaves);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,eAAe,OAAO,OAAO;CACxC,MAAMA;CACN,SAAS,OAAO,SAAS,CAAC,UAAU,MAAM,CAAC;CAC3C,eAAe,OAAO,MAAM,OAAO,cAAc;AACnD,CAAC;AASD,MAAa,YAAqC,OAAO,OAAO;CAC9D,SAAS,aAAa,OAAO;CAC7B,eAAe,aAAa,OAAO;CACnC,QAAQ,OAAO,OACb,OAAO,QACP,OAAO,cAAc,SAAS,CAChC;AACF,CAAC;AAED,IAAM,WAAN,MAAM,SAAS;CACb;CAEA,YACE,QACA;EACA,KAAK,UAAU;CACjB;CAEA,OAAO,YACL,QACkE;EAClE,OAAO,OAAO,IACZ,iCAAiC,MAAM,IACtC,WAAW,IAAI,SAAS,MAAM,CACjC;CACF;CAEA,IAAI,SAAoE;EACtE,OAAO,KAAK;CACd;AACF;AAIA,MAAM,UAAU,OAAO,MAAM,OAAO,MAAM,CAAC,OAAO,QAAQ,SAAS,CAAC,CAAC;AACrE,MAAM,oBAAA,eAAkD,MACtD,OAAO,YAAY,SAAS,CAAC,KAAK,SAAS,IAAI,CAAC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erationSnapshot.ts"],"sourcesContent":["import { type GroupSpec, Identifier } from \"@confect/core\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as String from \"effect/String\";\nimport { ParentChildNameCollisionError } from \"./CodegenError.js\";\nimport * as FunctionPath from \"./FunctionPath.js\";\nimport * as FunctionPaths from \"./FunctionPaths.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport * as SpecModulePath from \"./SpecModulePath.js\";\nimport { SnapshotError } from \"./SnapshotError.js\";\n\nexport { SnapshotError } from \"./SnapshotError.js\";\n\nexport const GroupSummary = Schema.Struct({\n path: GroupPath.GroupPath,\n runtime: Schema.Literals([\"Convex\", \"Node\"]),\n functionNames: Schema.Array(Schema.NonEmptyString),\n});\nexport interface GroupSummary extends Schema.Schema.Type<typeof GroupSummary> {}\n\nexport interface GroupTree {\n readonly runtime: \"Convex\" | \"Node\";\n readonly functionNames: ReadonlyArray<string>;\n readonly groups: { readonly [name: string]: GroupTree };\n}\n\nexport const GroupTree: Schema.Codec<GroupTree> = Schema.Struct({\n runtime: GroupSummary.fields.runtime,\n functionNames: GroupSummary.fields.functionNames,\n groups: Schema.Record(\n Schema.String,\n Schema.suspend(() => GroupTree),\n ),\n});\n\nclass Snapshot {\n readonly #leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>;\n\n private constructor(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ) {\n this.#leaves = leaves;\n }\n\n static parseLeaves(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ): Result.Result<GenerationSnapshot, ParentChildNameCollisionError> {\n return Result.map(\n parseNoParentChildNameCollisions(leaves),\n (parsed) => new Snapshot(parsed),\n );\n }\n\n get leaves(): HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree> {\n return this.#leaves;\n }\n}\n\nexport interface GenerationSnapshot extends Snapshot {}\n\nconst Entries = Schema.Array(Schema.Tuple([Schema.String, GroupTree]));\nconst CanonicalSpecPath = SpecModulePath.SpecModulePath.check(\n Schema.makeFilter((path) => !path.includes(\"\\\\\")),\n);\nconst rootPath = (path: SpecModulePath.SpecModulePath) =>\n GroupPath.make(String.split(path.slice(0, -\".spec.ts\".length), \"/\"));\n\nconst parseTree = (\n relativePath: SpecModulePath.SpecModulePath,\n path: GroupPath.GroupPath,\n tree: GroupTree,\n): Result.Result<GroupTree, SnapshotError> =>\n Result.gen(function* () {\n yield* Result.try({\n try: () => {\n for (const name of tree.functionNames)\n Identifier.validateConfectFunctionIdentifier(name);\n },\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (\n HashSet.size(HashSet.fromIterable(tree.functionNames)) !==\n tree.functionNames.length\n ) {\n return yield* Result.fail(\n new SnapshotError({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n for (const [name, child] of Object.entries(tree.groups)) {\n yield* Result.try({\n try: () => Identifier.validateConfectFunctionIdentifier(name),\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: [...path.pathSegments, name],\n }),\n });\n yield* parseTree(relativePath, GroupPath.append(path, name), child);\n }\n return tree;\n });\n\nconst fromEntries = (\n entries: ReadonlyArray<readonly [string, GroupTree]>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n let leaves = HashMap.empty<SpecModulePath.SpecModulePath, GroupTree>();\n for (const [key, tree] of entries) {\n const relativePath = yield* Schema.decodeResult(CanonicalSpecPath)(\n key,\n ).pipe(\n Result.mapError(\n (cause) =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath: key,\n pathSegments: [],\n cause,\n }),\n ),\n );\n const path = rootPath(relativePath);\n yield* Result.try({\n try: () => {\n for (const segment of path.pathSegments)\n Identifier.validateConfectFunctionIdentifier(segment);\n },\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (HashMap.has(leaves, relativePath)) {\n return yield* Result.fail(\n new SnapshotError({\n reason: \"DuplicateLeaf\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n const parsed = yield* parseTree(relativePath, path, tree);\n leaves = HashMap.set(leaves, relativePath, parsed);\n }\n return yield* Snapshot.parseLeaves(leaves);\n });\n\nexport const parse = (\n input: unknown,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Schema.decodeUnknownResult(Entries)(input).pipe(\n Result.mapError(\n (cause) =>\n new SnapshotError({\n reason: \"InvalidShape\",\n relativePath: \"\",\n pathSegments: [],\n cause,\n }),\n ),\n Result.flatMap(fromEntries),\n );\n\nexport const GenerationSnapshot = Entries.pipe(\n Schema.decodeTo(\n Schema.declare<GenerationSnapshot>((input) => input instanceof Snapshot),\n {\n decode: SchemaGetter.transformEffect((entries, options) =>\n Effect.fromResult(fromEntries(entries)).pipe(\n Effect.mapError(\n (error) =>\n new SchemaIssue.InvalidValue(\n {\n message: Match.value(error).pipe(\n Match.tagsExhaustive({\n SnapshotError: (failure) => failure.message,\n ParentChildNameCollisionError: (failure) =>\n `${failure.parentSpecPath} declares a ${failure.collisionKind} named ${failure.collisionName} that collides with ${failure.childSpecPath}`,\n }),\n ),\n },\n entries,\n options,\n ),\n ),\n ),\n ),\n encode: SchemaGetter.transform((snapshot) =>\n HashMap.toEntries(snapshot.leaves),\n ),\n },\n ),\n);\n\nconst summarize = (group: GroupSpec.AnyWithProps): GroupTree => ({\n runtime: group.runtime,\n functionNames: Record.keys(group.functions),\n groups: Record.map(group.groups, summarize),\n});\n\nexport const update = (\n snapshot: GenerationSnapshot,\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n if (leaves.length === 0) return snapshot;\n const replacement = yield* fromLoadedLeaves(leaves);\n return yield* Snapshot.parseLeaves(\n HashMap.union(snapshot.leaves, replacement.leaves),\n );\n });\n\nexport const fromLoadedLeaves = (\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n parse(\n leaves.map(\n (leaf) =>\n [\n leaf.relativePath.replaceAll(\"\\\\\", \"/\"),\n summarize(leaf.spec),\n ] as const,\n ),\n );\n\nconst groups = (snapshot: GenerationSnapshot): ReadonlyArray<GroupSummary> => {\n const visit = (\n path: GroupPath.GroupPath,\n tree: GroupTree,\n ): ReadonlyArray<GroupSummary> => [\n {\n path,\n runtime: tree.runtime,\n functionNames: Array.sort(tree.functionNames, String.Order),\n },\n ...Array.flatMap(\n Array.sort(Object.keys(tree.groups), String.Order),\n (name: string) => visit(GroupPath.append(path, name), tree.groups[name]!),\n ),\n ];\n return Array.flatMap(Array.fromIterable(snapshot.leaves), ([path, tree]) =>\n visit(rootPath(path), tree),\n );\n};\n\nexport const functionPaths = (\n snapshot: GenerationSnapshot,\n): FunctionPaths.FunctionPaths =>\n FunctionPaths.FunctionPaths.make(\n HashSet.fromIterable(\n Array.flatMap(groups(snapshot), (group) =>\n group.functionNames.map((name) =>\n FunctionPath.FunctionPath.make({ groupPath: group.path, name }),\n ),\n ),\n ),\n );\n\nconst generatedGroups = (snapshot: GenerationSnapshot) =>\n HashMap.fromIterable(\n Array.filterMap(groups(snapshot), (group) =>\n group.functionNames.length === 0\n ? Result.fail(undefined)\n : Result.succeed([group.path, group] as const),\n ),\n );\n\nexport interface ModulePlan {\n readonly removed: ReadonlyArray<GroupPath.GroupPath>;\n readonly changed: ReadonlyArray<GroupSummary>;\n}\n\nexport const plan = (\n snapshot: GenerationSnapshot,\n existing: Iterable<GroupPath.GroupPath>,\n): ModulePlan => {\n const current = generatedGroups(snapshot);\n return {\n removed: Array.fromIterable(existing).filter(\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.fromIterable(HashMap.values(current)),\n };\n};\n\nconst equivalentGroup = Schema.toEquivalence(GroupSummary);\n\nexport const diff = (\n before: GenerationSnapshot,\n after: GenerationSnapshot,\n): ModulePlan => {\n const previous = generatedGroups(before);\n const current = generatedGroups(after);\n return {\n removed: Array.filter(\n HashMap.keys(previous),\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.filter(HashMap.values(current), (group) => {\n const old = HashMap.get(previous, group.path);\n return Option.isNone(old) || !equivalentGroup(old.value, group);\n }),\n };\n};\n\nconst parseNoParentChildNameCollisions = (\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n): Result.Result<\n HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ParentChildNameCollisionError\n> => {\n for (const childPath of HashMap.keys(leaves)) {\n const segments = rootPath(childPath).pathSegments;\n for (let depth = 1; depth < segments.length; depth++) {\n const parentPath = SpecModulePath.SpecModulePath.make(\n `${segments.slice(0, depth).join(\"/\")}.spec.ts`,\n );\n const parent = HashMap.get(leaves, parentPath);\n if (Option.isNone(parent)) continue;\n const collisionName = segments[depth]!;\n const collisionKind = parent.value.functionNames.includes(collisionName)\n ? \"function\"\n : Object.hasOwn(parent.value.groups, collisionName)\n ? \"group\"\n : undefined;\n if (collisionKind !== undefined) {\n return Result.fail(\n new ParentChildNameCollisionError({\n parentSpecPath: parentPath,\n childSpecPath: childPath,\n collisionName,\n collisionKind,\n }),\n );\n }\n }\n }\n return Result.succeed(leaves);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;A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MAAM,WAAW,SAAS,SAAS,CAAC,CAAC;EACrC,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;GACpD,MAAM,aAAA,eAA2C,KAC/C,GAAG,SAAS,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,GAAG,EAAE,SACxC;GACA,MAAM,SAAS,QAAQ,IAAI,QAAQ,UAAU;GAC7C,IAAI,OAAO,OAAO,MAAM,GAAG;GAC3B,MAAM,gBAAgB,SAAS;GAC/B,MAAM,gBAAgB,OAAO,MAAM,cAAc,SAAS,aAAa,IACnE,aACA,OAAO,OAAO,OAAO,MAAM,QAAQ,aAAa,IAC9C,UACA,KAAA;GACN,IAAI,kBAAkB,KAAA,GACpB,OAAO,OAAO,KACZ,IAAI,8BAA8B;IAChC,gBAAgB;IAChB,eAAe;IACf;IACA;GACF,CAAC,CACH;EAEJ;CACF;CACA,OAAO,OAAO,QAAQ,MAAM;AAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"GroupPaths.mjs","names":["GroupPath.GroupPath"],"sources":["../src/GroupPaths.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as GroupPath from \"./GroupPath\";\n\nexport const GroupPaths = Schema.HashSet(GroupPath.GroupPath).pipe(\n Schema.brand(\"@confect/cli/GroupPaths\"),\n);\nexport type GroupPaths = typeof GroupPaths.Type;\n"],"mappings":";;;AAGA,MAAa,aAAa,OAAO,QAAQA,SAAmB,CAAC,CAAC,KAC5D,OAAO,MAAM,yBAAyB,CACxC"}
1
+ {"version":3,"file":"GroupPaths.mjs","names":["GroupPath.GroupPath"],"sources":["../src/GroupPaths.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as GroupPath from \"./GroupPath.js\";\n\nexport const GroupPaths = Schema.HashSet(GroupPath.GroupPath).pipe(\n Schema.brand(\"@confect/cli/GroupPaths\"),\n);\nexport type GroupPaths = typeof GroupPaths.Type;\n"],"mappings":";;;AAGA,MAAa,aAAa,OAAO,QAAQA,SAAmB,CAAC,CAAC,KAC5D,OAAO,MAAM,yBAAyB,CACxC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ImplModulePath.mjs","names":["RelativeModulePath.withSuffix"],"sources":["../src/ImplModulePath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as RelativeModulePath from \"./RelativeModulePath\";\n\nexport const ImplModulePath = RelativeModulePath.withSuffix(\".impl.ts\").pipe(\n Schema.brand(\"@confect/cli/ImplModulePath\"),\n);\n\nexport type ImplModulePath = typeof ImplModulePath.Type;\n"],"mappings":";;;AAGA,MAAa,iBAAiBA,WAA8B,UAAU,CAAC,CAAC,KACtE,OAAO,MAAM,6BAA6B,CAC5C"}
1
+ {"version":3,"file":"ImplModulePath.mjs","names":["RelativeModulePath.withSuffix"],"sources":["../src/ImplModulePath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as RelativeModulePath from \"./RelativeModulePath.js\";\n\nexport const ImplModulePath = RelativeModulePath.withSuffix(\".impl.ts\").pipe(\n Schema.brand(\"@confect/cli/ImplModulePath\"),\n);\n\nexport type ImplModulePath = typeof ImplModulePath.Type;\n"],"mappings":";;;AAGA,MAAa,iBAAiBA,WAA8B,UAAU,CAAC,CAAC,KACtE,OAAO,MAAM,6BAA6B,CAC5C"}
@@ -1,6 +1,6 @@
1
1
  import { fromBundlerError } from "./BuildError.mjs";
2
2
  import { bundle, directlyImports, importersOfPackage, withBatch } from "./Bundler.mjs";
3
- import { ImplMissingDefaultLayerError, ImplMissingFunctionsError, ImplMissingMiddlewareError, ImplMissingSpecImportError, ImplNotFinalizedError, InvalidMiddlewareAttachmentError, MissingImplFileError, MissingSpecFileError, SpecImportsServerError, SpecMissingDefaultGroupSpecError } from "./CodegenError.mjs";
3
+ import { ImplMissingDefaultLayerError, ImplMissingFunctionsError, ImplMissingMiddlewareError, ImplMissingSpecImportError, ImplNotFinalizedError, InvalidMiddlewareAttachmentError, MissingImplFileError, MissingSpecFileError, RequiredMiddlewareError, SpecImportsServerError, SpecMissingDefaultGroupSpecError } from "./CodegenError.mjs";
4
4
  import { ConfectDirectory } from "./ConfectDirectory.mjs";
5
5
  import { removePathExtension, toPosixPath } from "./utils.mjs";
6
6
  import { ImplModulePath } from "./ImplModulePath.mjs";
@@ -16,7 +16,7 @@ import * as Schema from "effect/Schema";
16
16
  import * as String from "effect/String";
17
17
  import * as Layer from "effect/Layer";
18
18
  import * as Brand from "effect/Brand";
19
- import { Registry } from "@confect/server";
19
+ import { Registry, RegistryItems } from "@confect/server";
20
20
  import * as GroupImpl from "@confect/server/GroupImpl";
21
21
  //#region src/LeafModule.ts
22
22
  const LoadedLeafModule = Brand.nominal();
@@ -49,7 +49,7 @@ const groupPathFromRelativeModulePath = Effect.fnUntraced(function* (relativePat
49
49
  });
50
50
  const specImportPathFromGenerated = Effect.fnUntraced(function* (specRelativePath) {
51
51
  const path = yield* Path.Path;
52
- return `../${toPosixPath(path, yield* removePathExtension(specRelativePath))}`;
52
+ return `../${toPosixPath(path, yield* removePathExtension(specRelativePath))}.js`;
53
53
  });
54
54
  const specPathForImpl = (implRelativePath) => swapModuleSuffix(implRelativePath, IMPL_SUFFIX, SPEC_SUFFIX);
55
55
  const implPathForSpec = (specRelativePath) => swapModuleSuffix(specRelativePath, SPEC_SUFFIX, IMPL_SUFFIX);
@@ -156,22 +156,23 @@ const loadSpec = Effect.fn("LeafModule.loadSpec")(function* (leaf) {
156
156
  const findFinalizedGroupImpl = (context) => Array.findFirst(context.mapUnsafe.values(), GroupImpl.isFinalizedGroupImpl);
157
157
  /**
158
158
  * Build the impl layer with a fresh `Registry` so each validation is isolated
159
- * from prior validations' `FunctionImpl.make` writes. The CLI no longer reads
160
- * the registry directly—`GroupImpl.finalize` snapshots the registered function
161
- * names onto the produced `Finalized` `GroupImpl` service value—but a fresh
162
- * `Ref` is still required because the default `Context.Reference` is cached
163
- * globally and would otherwise accumulate items across impls.
159
+ * from prior validations' `FunctionImpl.make` writes. Retain its items to check
160
+ * required middleware against actual function attachments.
164
161
  */
165
162
  const buildImplLayer = Effect.fnUntraced(function* (implLayer) {
166
163
  const registry = Ref.makeUnsafe({});
167
- return yield* Layer.build(implLayer).pipe(Effect.provideService(Registry.Registry, registry));
164
+ return {
165
+ context: yield* Layer.build(implLayer).pipe(Effect.provideService(Registry.Registry, registry)),
166
+ items: yield* Ref.get(registry)
167
+ };
168
168
  }, Effect.scoped);
169
169
  /**
170
170
  * Validate that the leaf's sibling impl file imports the spec, default-exports
171
171
  * a finalized `GroupImpl` layer, and provides a `FunctionImpl` for every
172
- * function declared by the spec.
172
+ * function declared by the spec. Return uncovered middleware requirements for
173
+ * the caller to report across groups.
173
174
  */
174
- const validateImpl = Effect.fn("LeafModule.validateImpl")(function* (leaf) {
175
+ const validateImpl = Effect.fn("LeafModule.validateImpl")(function* (leaf, required = []) {
175
176
  const implRelativePath = yield* implPathForSpec(leaf.relativePath);
176
177
  const implAbsolutePath = yield* absoluteModulePath(implRelativePath);
177
178
  const specAbsolutePath = yield* absoluteModulePath(leaf.relativePath);
@@ -183,7 +184,7 @@ const validateImpl = Effect.fn("LeafModule.validateImpl")(function* (leaf) {
183
184
  if (!Layer.isLayer(bundled.module.default)) return yield* new ImplMissingDefaultLayerError({ implPath: implRelativePath });
184
185
  const groupSpec = leaf.spec;
185
186
  const expectedFunctionNames = Object.keys(groupSpec.functions);
186
- const context = yield* buildImplLayer(bundled.module.default);
187
+ const { context, items } = yield* buildImplLayer(bundled.module.default);
187
188
  const finalizedGroupImpl = yield* Option.match(findFinalizedGroupImpl(context), {
188
189
  onNone: () => new ImplNotFinalizedError({ implPath: implRelativePath }),
189
190
  onSome: Effect.succeed
@@ -203,6 +204,7 @@ const validateImpl = Effect.fn("LeafModule.validateImpl")(function* (leaf) {
203
204
  groupPath: leaf.groupPathDot,
204
205
  missingMiddlewareKeys: missingMiddleware
205
206
  });
207
+ return RegistryItems.missingRequired(items, required, leaf.groupPathDot);
206
208
  });
207
209
  const withImplFiles = Effect.fnUntraced(function* (relativePaths, use) {
208
210
  const fs = yield* FileSystem.FileSystem;
@@ -227,14 +229,12 @@ const withImplFiles = Effect.fnUntraced(function* (relativePaths, use) {
227
229
  }));
228
230
  });
229
231
  const validateImplFiles = Effect.fn("LeafModule.validateImplFiles")((relativePaths) => withImplFiles(relativePaths, validateAllImpls));
230
- const validateAllImpls = Effect.fnUntraced(function* (leaves) {
232
+ const validateAllImpls = Effect.fnUntraced(function* (leaves, required = []) {
231
233
  const path = yield* Path.Path;
232
234
  const confectDirectory = yield* ConfectDirectory.get;
233
235
  const implementationPaths = yield* Effect.forEach(leaves, ({ relativePath }) => implPathForSpec(relativePath).pipe(Effect.map((implPath) => path.resolve(confectDirectory, implPath))));
234
- yield* withBatch(implementationPaths, Effect.forEach(leaves, validateImpl, {
235
- concurrency: VALIDATION_CONCURRENCY,
236
- discard: true
237
- }));
236
+ const missing = (yield* withBatch(implementationPaths, Effect.forEach(leaves, (leaf) => validateImpl(leaf, required), { concurrency: VALIDATION_CONCURRENCY }))).flat().sort((left, right) => left.functionName.localeCompare(right.functionName));
237
+ if (missing.length > 0) return yield* new RequiredMiddlewareError({ missing });
238
238
  });
239
239
  const loadAll = Effect.gen(function* () {
240
240
  const fs = yield* FileSystem.FileSystem;