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

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
@@ -40,12 +40,17 @@ var AuthForAnotherBackend = class extends Data.TaggedError("AuthForAnotherBacken
40
40
  return `confect/auth.ts declares auth for the "${this.backend}" backend, but confect/app.ts declares "${this.expectedBackend}".`;
41
41
  }
42
42
  };
43
+ var InvalidProviderEnv = class extends Data.TaggedError("InvalidProviderEnv") {
44
+ get message() {
45
+ return `Auth provider field "${this.field}" requires a non-secret, required string entry of the "${this.backend}" env; got "${this.key}".`;
46
+ }
47
+ };
43
48
  const ENV_KEY = /^[A-Za-z][A-Za-z0-9_]*$/;
44
49
  const MOUNT_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
45
50
  /**
46
51
  * The declaration file a parse error is about.
47
52
  */
48
- const fileOf = (error) => error._tag === "NotADeclaration" ? error.file : error._tag === "AuthForAnotherBackend" ? "confect/auth.ts" : "confect/app.ts";
53
+ const fileOf = (error) => error._tag === "NotADeclaration" ? error.file : error._tag === "AuthForAnotherBackend" || error._tag === "InvalidProviderEnv" ? "confect/auth.ts" : "confect/app.ts";
49
54
  /**
50
55
  * Parse the default exports of `confect/app.ts` and, when present,
51
56
  * `confect/auth.ts`. `componentImport` recovers how the generated config
@@ -119,16 +124,44 @@ const parseProviders = (auth, backend) => {
119
124
  backend: authBackend,
120
125
  expectedBackend: backend
121
126
  }));
122
- return Result.succeed(Auth.providers(auth).map((provider) => Object.entries(provider).map(([field, value]) => {
123
- const sitePath = Auth.siteUrlPath(value);
124
- return [field, sitePath === void 0 ? {
125
- kind: "value",
126
- value: Predicate.isString(value) ? value : JSON.stringify(value)
127
- } : {
128
- kind: "siteUrl",
129
- path: sitePath
130
- }];
131
- })));
127
+ return Result.gen(function* () {
128
+ const providers = [];
129
+ for (const provider of Auth.providers(auth)) {
130
+ const fields = [];
131
+ for (const [field, value] of Object.entries(provider)) {
132
+ const sitePath = Auth.siteUrlPath(value);
133
+ const cloudPath = Auth.cloudUrlPath(value);
134
+ let lowered;
135
+ if (Env.isEntry(value)) {
136
+ const { backend: owner, key } = Env.origin(value);
137
+ const descriptor = value["~@confect/core/Env/Entry"].descriptor;
138
+ if (owner !== backend || descriptor.optional || descriptor.kind === "secret" || !ENV_KEY.test(key)) return yield* Result.fail(new InvalidProviderEnv({
139
+ field,
140
+ key,
141
+ backend
142
+ }));
143
+ lowered = {
144
+ kind: "env",
145
+ key
146
+ };
147
+ } else if (sitePath !== void 0) lowered = {
148
+ kind: "siteUrl",
149
+ path: sitePath
150
+ };
151
+ else if (cloudPath !== void 0) lowered = {
152
+ kind: "cloudUrl",
153
+ path: cloudPath
154
+ };
155
+ else lowered = {
156
+ kind: "value",
157
+ value: Predicate.isString(value) ? value : JSON.stringify(value)
158
+ };
159
+ fields.push([field, lowered]);
160
+ }
161
+ providers.push(fields);
162
+ }
163
+ return providers;
164
+ });
132
165
  };
133
166
  const quote = (value) => JSON.stringify(value);
134
167
  const header = (source) => `// Generated by \`confect codegen\` from ${source}. Do not edit.`;
@@ -207,7 +240,13 @@ const convexConfig = (declaration) => {
207
240
  lines.push("", `export default ${self};`, "");
208
241
  return lines.join("\n");
209
242
  };
210
- const providerValue = (value) => value.kind === "value" ? quote(value.value) : `\`\${process.env.CONVEX_SITE_URL}${value.path.replaceAll(/[`$\\]/g, "\\$&")}\``;
243
+ const providerValue = (value) => {
244
+ switch (value.kind) {
245
+ case "value": return quote(value.value);
246
+ case "env": return `process.env[${quote(value.key)}]!`;
247
+ default: return `\`\${process.env.${value.kind === "siteUrl" ? "CONVEX_SITE_URL" : "CONVEX_CLOUD_URL"}}${value.path.replaceAll(/[`$\\]/g, "\\$&")}\``;
248
+ }
249
+ };
211
250
  /**
212
251
  * `convex/auth.config.ts`: Convex's provider list, with site URLs resolved
213
252
  * there.
@@ -220,13 +259,37 @@ const authConfig = (providers) => [
220
259
  providers.length === 0 ? " providers: []," : " providers: [",
221
260
  ...providers.length === 0 ? [] : [...providers.flatMap((provider) => [
222
261
  " {",
223
- ...provider.map(([field, value]) => ` ${field}: ${providerValue(value)},`),
262
+ ...provider.filter(([field]) => field !== "family" && field !== "name").map(([field, value]) => ` ${field}: ${providerValue(value)},`),
224
263
  " },"
225
264
  ]), " ],"],
226
265
  "} satisfies AuthConfig;",
227
266
  ""
228
267
  ].join("\n");
229
268
  /**
269
+ * Runtime issuer data with no dependency on declarations or component
270
+ * definitions.
271
+ */
272
+ const authProviders = (providers) => [
273
+ header("confect/auth.ts"),
274
+ "",
275
+ "export const providers = [",
276
+ ...providers.flatMap((provider) => [
277
+ " {",
278
+ ...provider.flatMap(([field, value]) => {
279
+ const key = field === "domain" ? "issuer" : field === "applicationID" ? "audience" : field;
280
+ return [
281
+ "issuer",
282
+ "audience",
283
+ "family",
284
+ "name"
285
+ ].includes(key) ? [` ${key}: ${providerValue(value)},`] : [];
286
+ }),
287
+ " },"
288
+ ]),
289
+ "] as const;",
290
+ ""
291
+ ].join("\n");
292
+ /**
230
293
  * `confect/_generated/manifest.ts`: plain data, no imports, for infra.
231
294
  */
232
295
  const manifest = (declaration, digest) => {
@@ -253,6 +316,6 @@ const digest = (input) => {
253
316
  return `sha256:${hash.digest("hex")}`;
254
317
  };
255
318
  //#endregion
256
- export { AuthForAnotherBackend, ForeignEnvBinding, InvalidBinding, InvalidEnvKey, InvalidMountName, NotADeclaration, UnknownComponentImport, authConfig, convexConfig, digest, fileOf, header, isGenerated, manifest, parse };
319
+ export { AuthForAnotherBackend, ForeignEnvBinding, InvalidBinding, InvalidEnvKey, InvalidMountName, InvalidProviderEnv, NotADeclaration, UnknownComponentImport, authConfig, authProviders, convexConfig, digest, fileOf, header, isGenerated, manifest, parse };
257
320
 
258
321
  //# sourceMappingURL=Declaration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Declaration.mjs","names":[],"sources":["../src/Declaration.ts"],"sourcesContent":["import { App, Auth, Env } from \"@confect/core\";\nimport * as Data from \"effect/Data\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\n// oxlint-disable-next-line effecttsgo/node-builtin-import -- a synchronous hash of in-memory strings in a pure function; Effect's Crypto is a service.\nimport { createHash } from \"node:crypto\";\n\n/**\n * A backend's declaration (`confect/env.ts`, `app.ts`, `auth.ts`) reduced to\n * the plain data codegen renders. The evaluated modules are parsed into this\n * once, at {@link parse}; every renderer below is a pure function of it.\n */\nexport interface Declaration {\n readonly target: \"app\" | \"component\";\n readonly name: string;\n readonly env: ReadonlyArray<readonly [string, Env.Descriptor]>;\n readonly mounts: ReadonlyArray<Mount>;\n readonly providers: Option.Option<ReadonlyArray<Provider>>;\n}\n\nexport interface Mount {\n readonly name: string;\n readonly importPath: string;\n readonly componentName: string;\n readonly httpPrefix: string | undefined;\n readonly env: ReadonlyArray<readonly [string, Binding]>;\n}\n\nexport type Binding =\n | { readonly kind: \"value\"; readonly value: string }\n | { readonly kind: \"env\"; readonly key: string };\n\nexport type ProviderValue =\n | { readonly kind: \"value\"; readonly value: string }\n | { readonly kind: \"siteUrl\"; readonly path: string };\n\nexport type Provider = ReadonlyArray<readonly [string, ProviderValue]>;\n\nexport class NotADeclaration extends Data.TaggedError(\"NotADeclaration\")<{\n readonly file: string;\n readonly expected: string;\n}> {\n override get message(): string {\n return `${this.file} must default-export ${this.expected}.`;\n }\n}\n\nexport class InvalidEnvKey extends Data.TaggedError(\"InvalidEnvKey\")<{\n readonly key: string;\n}> {\n override get message(): string {\n return `\"${this.key}\" is not a valid Convex environment variable name; use letters, digits and underscores, starting with a letter.`;\n }\n}\n\nexport class InvalidMountName extends Data.TaggedError(\"InvalidMountName\")<{\n readonly mount: string;\n}> {\n override get message(): string {\n return `\"${this.mount}\" is not a valid mount name; use letters, digits and underscores, starting with a letter or underscore.`;\n }\n}\n\nexport class ForeignEnvBinding extends Data.TaggedError(\"ForeignEnvBinding\")<{\n readonly mount: string;\n readonly slot: string;\n readonly backend: string;\n readonly key: string;\n readonly expectedBackend: string;\n}> {\n override get message(): string {\n return `The mount \"${this.mount}\" binds ${this.slot} to ${this.key} of the \"${this.backend}\" env, but this backend's env is \"${this.expectedBackend}\".`;\n }\n}\n\nexport class InvalidBinding extends Data.TaggedError(\"InvalidBinding\")<{\n readonly mount: string;\n readonly slot: string;\n}> {\n override get message(): string {\n return `The mount \"${this.mount}\" binds ${this.slot} to something other than a string or an entry of this backend's env.`;\n }\n}\n\nexport class UnknownComponentImport extends Data.TaggedError(\n \"UnknownComponentImport\",\n)<{ readonly mount: string }> {\n override get message(): string {\n return `The mount \"${this.mount}\" must pass the default export of a component's convex.config module, imported directly in the declaration.`;\n }\n}\n\nexport class AuthForAnotherBackend extends Data.TaggedError(\n \"AuthForAnotherBackend\",\n)<{ readonly backend: string; readonly expectedBackend: string }> {\n override get message(): string {\n return `confect/auth.ts declares auth for the \"${this.backend}\" backend, but confect/app.ts declares \"${this.expectedBackend}\".`;\n }\n}\n\nexport type DeclarationError =\n | NotADeclaration\n | InvalidEnvKey\n | InvalidMountName\n | ForeignEnvBinding\n | InvalidBinding\n | UnknownComponentImport\n | AuthForAnotherBackend;\n\nconst ENV_KEY = /^[A-Za-z][A-Za-z0-9_]*$/;\nconst MOUNT_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * The declaration file a parse error is about.\n */\nexport const fileOf = (error: DeclarationError): string =>\n error._tag === \"NotADeclaration\"\n ? error.file\n : error._tag === \"AuthForAnotherBackend\"\n ? \"confect/auth.ts\"\n : \"confect/app.ts\";\n\n/**\n * A mounted component's import as the generated `convex.config.ts` writes it.\n */\nexport interface ComponentImport {\n readonly importPath: string;\n readonly componentName: string;\n}\n\n/**\n * Parse the default exports of `confect/app.ts` and, when present,\n * `confect/auth.ts`. `componentImport` recovers how the generated config\n * imports a mounted definition; codegen's bundler records it.\n */\nexport const parse = (input: {\n readonly target: \"app\" | \"component\";\n readonly app: unknown;\n readonly auth: Option.Option<unknown>;\n readonly componentImport: (\n definition: unknown,\n ) => Option.Option<ComponentImport>;\n}): Result.Result<Declaration, DeclarationError> =>\n Result.gen(function* () {\n if (!App.isApp(input.app)) {\n return yield* Result.fail(\n new NotADeclaration({\n file: \"confect/app.ts\",\n expected: \"App.make(...)\",\n }),\n );\n }\n const env = App.env(input.app);\n const name = Env.name(env);\n const descriptors = Env.descriptors(env);\n for (const [key] of descriptors) {\n if (!ENV_KEY.test(key))\n return yield* Result.fail(new InvalidEnvKey({ key }));\n }\n\n const mounts: Array<Mount> = [];\n for (const mount of App.mounts(input.app)) {\n if (!MOUNT_NAME.test(mount.name)) {\n return yield* Result.fail(new InvalidMountName({ mount: mount.name }));\n }\n const component = input.componentImport(mount.definition);\n if (Option.isNone(component)) {\n return yield* Result.fail(\n new UnknownComponentImport({ mount: mount.name }),\n );\n }\n const bindings: Array<readonly [string, Binding]> = [];\n for (const [slot, bound] of Object.entries(mount.env)) {\n if (bound === undefined) continue;\n if (typeof bound === \"string\") {\n bindings.push([slot, { kind: \"value\", value: bound }]);\n continue;\n }\n if (!Env.isEntry(bound)) {\n return yield* Result.fail(\n new InvalidBinding({ mount: mount.name, slot }),\n );\n }\n const origin = Env.origin(bound);\n if (origin.backend !== name) {\n return yield* Result.fail(\n new ForeignEnvBinding({\n mount: mount.name,\n slot,\n backend: origin.backend,\n key: origin.key,\n expectedBackend: name,\n }),\n );\n }\n bindings.push([slot, { kind: \"env\", key: origin.key }]);\n }\n mounts.push({\n name: mount.name,\n importPath: component.value.importPath,\n componentName: component.value.componentName,\n httpPrefix: mount.httpPrefix,\n env: bindings,\n });\n }\n\n const providers: Option.Option<ReadonlyArray<Provider>> = Option.isNone(\n input.auth,\n )\n ? Option.none()\n : Option.some(yield* parseProviders(input.auth.value, name));\n\n return {\n target: input.target,\n name,\n env: descriptors,\n mounts,\n providers,\n };\n });\n\nconst parseProviders = (\n auth: unknown,\n backend: string,\n): Result.Result<ReadonlyArray<Provider>, DeclarationError> => {\n if (!Auth.isAuth(auth)) {\n return Result.fail(\n new NotADeclaration({\n file: \"confect/auth.ts\",\n expected: \"Auth.make(app, ...)\",\n }),\n );\n }\n const authBackend = Env.name(App.env(auth.app));\n if (authBackend !== backend) {\n return Result.fail(\n new AuthForAnotherBackend({\n backend: authBackend,\n expectedBackend: backend,\n }),\n );\n }\n return Result.succeed(\n Auth.providers(auth).map((provider) =>\n Object.entries(provider).map(([field, value]) => {\n const sitePath = Auth.siteUrlPath(value);\n return [\n field,\n sitePath === undefined\n ? {\n kind: \"value\",\n value: Predicate.isString(value)\n ? value\n : JSON.stringify(value),\n }\n : { kind: \"siteUrl\", path: sitePath },\n ] as const;\n }),\n ),\n );\n};\n\nconst quote = (value: string): string => JSON.stringify(value);\n\nexport const header = (source: string): string =>\n `// Generated by \\`confect codegen\\` from ${source}. Do not edit.`;\n\nconst GENERATED_PREFIX = \"// Generated by `confect codegen` from \";\n\n/**\n * Whether codegen may overwrite or remove an existing file: it carries the\n * generated header, or it is exactly one of the files an earlier codegen wrote\n * there (`legacy`).\n */\nexport const isGenerated = (\n contents: string,\n legacy: ReadonlyArray<string>,\n): boolean =>\n contents.startsWith(GENERATED_PREFIX) || legacy.includes(contents);\n\nconst validator = (descriptor: Env.Descriptor): string => {\n const base =\n descriptor.kind === \"literals\"\n ? descriptor.values.length === 1\n ? `v.literal(${quote(descriptor.values[0])})`\n : `v.union(${descriptor.values.map((value) => `v.literal(${quote(value)})`).join(\", \")})`\n : \"v.string()\";\n return descriptor.optional ? `v.optional(${base})` : base;\n};\n\nconst RESERVED = new Set(\n \"await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield\".split(\n \" \",\n ),\n);\n\n/**\n * A safe import name for a component, from its Convex name.\n */\nconst identifier = (name: string): string => {\n const cleaned = name.replaceAll(/[^A-Za-z0-9_$]/g, \"_\");\n const valid = /^[A-Za-z_$]/.test(cleaned) ? cleaned : `_${cleaned}`;\n return RESERVED.has(valid) ? `${valid}Component` : valid;\n};\n\n/**\n * `convex/convex.config.ts`: Convex's own app or component definition.\n */\nexport const convexConfig = (declaration: Declaration): string => {\n const self = declaration.target === \"app\" ? \"app\" : \"component\";\n const aliases = new Map<string, string>();\n const taken = new Set([self, \"v\", \"defineApp\", \"defineComponent\"]);\n for (const mount of declaration.mounts) {\n if (aliases.has(mount.importPath)) continue;\n const base = identifier(mount.componentName);\n let alias = base;\n for (let n = 2; taken.has(alias); n++) alias = `${base}${n}`;\n taken.add(alias);\n aliases.set(mount.importPath, alias);\n }\n\n const lines = [header(\"confect/app.ts\")];\n lines.push(\n declaration.target === \"app\"\n ? 'import { defineApp } from \"convex/server\";'\n : 'import { defineComponent } from \"convex/server\";',\n );\n if (declaration.env.length > 0)\n lines.push('import { v } from \"convex/values\";');\n for (const [importPath, alias] of aliases) {\n lines.push(`import ${alias} from ${quote(importPath)};`);\n }\n lines.push(\"\");\n\n const envBlock =\n declaration.env.length === 0\n ? []\n : [\n \" env: {\",\n ...declaration.env.map(\n ([key, descriptor]) => ` ${key}: ${validator(descriptor)},`,\n ),\n \" },\",\n ];\n if (declaration.target === \"app\") {\n lines.push(\n envBlock.length === 0\n ? \"const app = defineApp();\"\n : [\"const app = defineApp({\", ...envBlock, \"});\"].join(\"\\n\"),\n );\n } else {\n lines.push(\n envBlock.length === 0\n ? `const component = defineComponent(${quote(declaration.name)});`\n : [\n `const component = defineComponent(${quote(declaration.name)}, {`,\n ...envBlock,\n \"});\",\n ].join(\"\\n\"),\n );\n }\n\n for (const mount of declaration.mounts) {\n lines.push(\"\");\n lines.push(`${self}.use(${aliases.get(mount.importPath)}, {`);\n lines.push(` name: ${quote(mount.name)},`);\n if (mount.httpPrefix !== undefined) {\n lines.push(` httpPrefix: ${quote(mount.httpPrefix)},`);\n }\n if (mount.env.length > 0) {\n lines.push(\" env: {\");\n for (const [slot, binding] of mount.env) {\n lines.push(\n ` ${slot}: ${binding.kind === \"value\" ? quote(binding.value) : `${self}.env.${binding.key}`},`,\n );\n }\n lines.push(\" },\");\n }\n lines.push(\"});\");\n }\n\n lines.push(\"\", `export default ${self};`, \"\");\n return lines.join(\"\\n\");\n};\n\nconst providerValue = (value: ProviderValue): string =>\n value.kind === \"value\"\n ? quote(value.value)\n : `\\`\\${process.env.CONVEX_SITE_URL}${value.path.replaceAll(/[`$\\\\]/g, \"\\\\$&\")}\\``;\n\n/**\n * `convex/auth.config.ts`: Convex's provider list, with site URLs resolved\n * there.\n */\nexport const authConfig = (providers: ReadonlyArray<Provider>): string =>\n [\n header(\"confect/auth.ts\"),\n 'import type { AuthConfig } from \"convex/server\";',\n \"\",\n \"export default {\",\n providers.length === 0 ? \" providers: [],\" : \" providers: [\",\n ...(providers.length === 0\n ? []\n : [\n ...providers.flatMap((provider) => [\n \" {\",\n ...provider.map(\n ([field, value]) => ` ${field}: ${providerValue(value)},`,\n ),\n \" },\",\n ]),\n \" ],\",\n ]),\n \"} satisfies AuthConfig;\",\n \"\",\n ].join(\"\\n\");\n\n/**\n * `confect/_generated/manifest.ts`: plain data, no imports, for infra.\n */\nexport const manifest = (declaration: Declaration, digest: string): string => {\n const data = {\n name: declaration.name,\n env: Object.fromEntries(declaration.env),\n http: {\n mounts: Object.fromEntries(\n declaration.mounts.flatMap(({ name, httpPrefix }) =>\n httpPrefix === undefined ? [] : [[name, httpPrefix]],\n ),\n ),\n },\n digest,\n };\n return `${header(\"confect/env.ts and confect/app.ts\")}\\n\\nexport default ${JSON.stringify(data, null, 2)} as const;\\n`;\n};\n\n/**\n * A digest of the declaration's inputs: every first-party file its modules\n * import (by project-relative path and contents) and the versions of the\n * packages that shape the generated output.\n */\nexport const digest = (input: {\n readonly files: ReadonlyArray<readonly [string, string]>;\n readonly versions: ReadonlyArray<readonly [string, string]>;\n}): string => {\n const hash = createHash(\"sha256\");\n const byFirst = (\n a: readonly [string, string],\n b: readonly [string, string],\n ) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);\n hash.update(\n JSON.stringify({\n files: [...input.files].sort(byFirst),\n versions: [...input.versions].sort(byFirst),\n }),\n );\n return `sha256:${hash.digest(\"hex\")}`;\n};\n"],"mappings":";;;;;;;AAuCA,IAAa,kBAAb,cAAqC,KAAK,YAAY,iBAAiB,CAAC,CAGrE;CACD,IAAa,UAAkB;EAC7B,OAAO,GAAG,KAAK,KAAK,uBAAuB,KAAK,SAAS;CAC3D;AACF;AAEA,IAAa,gBAAb,cAAmC,KAAK,YAAY,eAAe,CAAC,CAEjE;CACD,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,IAAI;CACtB;AACF;AAEA,IAAa,mBAAb,cAAsC,KAAK,YAAY,kBAAkB,CAAC,CAEvE;CACD,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,MAAM;CACxB;AACF;AAEA,IAAa,oBAAb,cAAuC,KAAK,YAAY,mBAAmB,CAAC,CAMzE;CACD,IAAa,UAAkB;EAC7B,OAAO,cAAc,KAAK,MAAM,UAAU,KAAK,KAAK,MAAM,KAAK,IAAI,WAAW,KAAK,QAAQ,oCAAoC,KAAK,gBAAgB;CACtJ;AACF;AAEA,IAAa,iBAAb,cAAoC,KAAK,YAAY,gBAAgB,CAAC,CAGnE;CACD,IAAa,UAAkB;EAC7B,OAAO,cAAc,KAAK,MAAM,UAAU,KAAK,KAAK;CACtD;AACF;AAEA,IAAa,yBAAb,cAA4C,KAAK,YAC/C,wBACF,CAAC,CAA6B;CAC5B,IAAa,UAAkB;EAC7B,OAA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K,IAAI;CAC3C,KAAK,OACH,KAAK,UAAU;EACb,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,KAAK,OAAO;EACpC,UAAU,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,KAAK,OAAO;CAC5C,CAAC,CACH;CACA,OAAO,UAAU,KAAK,OAAO,KAAK;AACpC"}
1
+ {"version":3,"file":"Declaration.mjs","names":[],"sources":["../src/Declaration.ts"],"sourcesContent":["import { App, Auth, Env } from \"@confect/core\";\nimport * as Data from \"effect/Data\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\n// oxlint-disable-next-line effecttsgo/node-builtin-import -- a synchronous hash of in-memory strings in a pure function; Effect's Crypto is a service.\nimport { createHash } from \"node:crypto\";\n\n/**\n * A backend's declaration (`confect/env.ts`, `app.ts`, `auth.ts`) reduced to\n * the plain data codegen renders. The evaluated modules are parsed into this\n * once, at {@link parse}; every renderer below is a pure function of it.\n */\nexport interface Declaration {\n readonly target: \"app\" | \"component\";\n readonly name: string;\n readonly env: ReadonlyArray<readonly [string, Env.Descriptor]>;\n readonly mounts: ReadonlyArray<Mount>;\n readonly providers: Option.Option<ReadonlyArray<Provider>>;\n}\n\nexport interface Mount {\n readonly name: string;\n readonly importPath: string;\n readonly componentName: string;\n readonly httpPrefix: string | undefined;\n readonly env: ReadonlyArray<readonly [string, Binding]>;\n}\n\nexport type Binding =\n | { readonly kind: \"value\"; readonly value: string }\n | { readonly kind: \"env\"; readonly key: string };\n\nexport type ProviderValue =\n | { readonly kind: \"value\"; readonly value: string }\n | { readonly kind: \"siteUrl\" | \"cloudUrl\"; readonly path: string }\n | { readonly kind: \"env\"; readonly key: string };\n\nexport type Provider = ReadonlyArray<readonly [string, ProviderValue]>;\n\nexport class NotADeclaration extends Data.TaggedError(\"NotADeclaration\")<{\n readonly file: string;\n readonly expected: string;\n}> {\n override get message(): string {\n return `${this.file} must default-export ${this.expected}.`;\n }\n}\n\nexport class InvalidEnvKey extends Data.TaggedError(\"InvalidEnvKey\")<{\n readonly key: string;\n}> {\n override get message(): string {\n return `\"${this.key}\" is not a valid Convex environment variable name; use letters, digits and underscores, starting with a letter.`;\n }\n}\n\nexport class InvalidMountName extends Data.TaggedError(\"InvalidMountName\")<{\n readonly mount: string;\n}> {\n override get message(): string {\n return `\"${this.mount}\" is not a valid mount name; use letters, digits and underscores, starting with a letter or underscore.`;\n }\n}\n\nexport class ForeignEnvBinding extends Data.TaggedError(\"ForeignEnvBinding\")<{\n readonly mount: string;\n readonly slot: string;\n readonly backend: string;\n readonly key: string;\n readonly expectedBackend: string;\n}> {\n override get message(): string {\n return `The mount \"${this.mount}\" binds ${this.slot} to ${this.key} of the \"${this.backend}\" env, but this backend's env is \"${this.expectedBackend}\".`;\n }\n}\n\nexport class InvalidBinding extends Data.TaggedError(\"InvalidBinding\")<{\n readonly mount: string;\n readonly slot: string;\n}> {\n override get message(): string {\n return `The mount \"${this.mount}\" binds ${this.slot} to something other than a string or an entry of this backend's env.`;\n }\n}\n\nexport class UnknownComponentImport extends Data.TaggedError(\n \"UnknownComponentImport\",\n)<{ readonly mount: string }> {\n override get message(): string {\n return `The mount \"${this.mount}\" must pass the default export of a component's convex.config module, imported directly in the declaration.`;\n }\n}\n\nexport class AuthForAnotherBackend extends Data.TaggedError(\n \"AuthForAnotherBackend\",\n)<{ readonly backend: string; readonly expectedBackend: string }> {\n override get message(): string {\n return `confect/auth.ts declares auth for the \"${this.backend}\" backend, but confect/app.ts declares \"${this.expectedBackend}\".`;\n }\n}\n\nexport class InvalidProviderEnv extends Data.TaggedError(\"InvalidProviderEnv\")<{\n readonly field: string;\n readonly key: string;\n readonly backend: string;\n}> {\n override get message(): string {\n return `Auth provider field \"${this.field}\" requires a non-secret, required string entry of the \"${this.backend}\" env; got \"${this.key}\".`;\n }\n}\n\nexport type DeclarationError =\n | NotADeclaration\n | InvalidEnvKey\n | InvalidMountName\n | ForeignEnvBinding\n | InvalidBinding\n | UnknownComponentImport\n | AuthForAnotherBackend\n | InvalidProviderEnv;\n\nconst ENV_KEY = /^[A-Za-z][A-Za-z0-9_]*$/;\nconst MOUNT_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * The declaration file a parse error is about.\n */\nexport const fileOf = (error: DeclarationError): string =>\n error._tag === \"NotADeclaration\"\n ? error.file\n : error._tag === \"AuthForAnotherBackend\" ||\n error._tag === \"InvalidProviderEnv\"\n ? \"confect/auth.ts\"\n : \"confect/app.ts\";\n\n/**\n * A mounted component's import as the generated `convex.config.ts` writes it.\n */\nexport interface ComponentImport {\n readonly importPath: string;\n readonly componentName: string;\n}\n\n/**\n * Parse the default exports of `confect/app.ts` and, when present,\n * `confect/auth.ts`. `componentImport` recovers how the generated config\n * imports a mounted definition; codegen's bundler records it.\n */\nexport const parse = (input: {\n readonly target: \"app\" | \"component\";\n readonly app: unknown;\n readonly auth: Option.Option<unknown>;\n readonly componentImport: (\n definition: unknown,\n ) => Option.Option<ComponentImport>;\n}): Result.Result<Declaration, DeclarationError> =>\n Result.gen(function* () {\n if (!App.isApp(input.app)) {\n return yield* Result.fail(\n new NotADeclaration({\n file: \"confect/app.ts\",\n expected: \"App.make(...)\",\n }),\n );\n }\n const env = App.env(input.app);\n const name = Env.name(env);\n const descriptors = Env.descriptors(env);\n for (const [key] of descriptors) {\n if (!ENV_KEY.test(key))\n return yield* Result.fail(new InvalidEnvKey({ key }));\n }\n\n const mounts: Array<Mount> = [];\n for (const mount of App.mounts(input.app)) {\n if (!MOUNT_NAME.test(mount.name)) {\n return yield* Result.fail(new InvalidMountName({ mount: mount.name }));\n }\n const component = input.componentImport(mount.definition);\n if (Option.isNone(component)) {\n return yield* Result.fail(\n new UnknownComponentImport({ mount: mount.name }),\n );\n }\n const bindings: Array<readonly [string, Binding]> = [];\n for (const [slot, bound] of Object.entries(mount.env)) {\n if (bound === undefined) continue;\n if (typeof bound === \"string\") {\n bindings.push([slot, { kind: \"value\", value: bound }]);\n continue;\n }\n if (!Env.isEntry(bound)) {\n return yield* Result.fail(\n new InvalidBinding({ mount: mount.name, slot }),\n );\n }\n const origin = Env.origin(bound);\n if (origin.backend !== name) {\n return yield* Result.fail(\n new ForeignEnvBinding({\n mount: mount.name,\n slot,\n backend: origin.backend,\n key: origin.key,\n expectedBackend: name,\n }),\n );\n }\n bindings.push([slot, { kind: \"env\", key: origin.key }]);\n }\n mounts.push({\n name: mount.name,\n importPath: component.value.importPath,\n componentName: component.value.componentName,\n httpPrefix: mount.httpPrefix,\n env: bindings,\n });\n }\n\n const providers: Option.Option<ReadonlyArray<Provider>> = Option.isNone(\n input.auth,\n )\n ? Option.none()\n : Option.some(yield* parseProviders(input.auth.value, name));\n\n return {\n target: input.target,\n name,\n env: descriptors,\n mounts,\n providers,\n };\n });\n\nconst parseProviders = (\n auth: unknown,\n backend: string,\n): Result.Result<ReadonlyArray<Provider>, DeclarationError> => {\n if (!Auth.isAuth(auth)) {\n return Result.fail(\n new NotADeclaration({\n file: \"confect/auth.ts\",\n expected: \"Auth.make(app, ...)\",\n }),\n );\n }\n const authBackend = Env.name(App.env(auth.app));\n if (authBackend !== backend) {\n return Result.fail(\n new AuthForAnotherBackend({\n backend: authBackend,\n expectedBackend: backend,\n }),\n );\n }\n return Result.gen(function* () {\n const providers: Provider[] = [];\n for (const provider of Auth.providers(auth)) {\n const fields: Array<readonly [string, ProviderValue]> = [];\n for (const [field, value] of Object.entries(provider)) {\n const sitePath = Auth.siteUrlPath(value);\n const cloudPath = Auth.cloudUrlPath(value);\n let lowered: ProviderValue;\n if (Env.isEntry(value)) {\n const { backend: owner, key } = Env.origin(value);\n const descriptor = value[\"~@confect/core/Env/Entry\"].descriptor;\n if (\n owner !== backend ||\n descriptor.optional ||\n descriptor.kind === \"secret\" ||\n !ENV_KEY.test(key)\n ) {\n return yield* Result.fail(\n new InvalidProviderEnv({ field, key, backend }),\n );\n }\n lowered = { kind: \"env\", key };\n } else if (sitePath !== undefined) {\n lowered = { kind: \"siteUrl\", path: sitePath };\n } else if (cloudPath !== undefined) {\n lowered = { kind: \"cloudUrl\", path: cloudPath };\n } else {\n lowered = {\n kind: \"value\",\n value: Predicate.isString(value) ? value : JSON.stringify(value),\n };\n }\n fields.push([field, lowered]);\n }\n providers.push(fields);\n }\n return providers;\n });\n};\n\nconst quote = (value: string): string => JSON.stringify(value);\n\nexport const header = (source: string): string =>\n `// Generated by \\`confect codegen\\` from ${source}. Do not edit.`;\n\nconst GENERATED_PREFIX = \"// Generated by `confect codegen` from \";\n\n/**\n * Whether codegen may overwrite or remove an existing file: it carries the\n * generated header, or it is exactly one of the files an earlier codegen wrote\n * there (`legacy`).\n */\nexport const isGenerated = (\n contents: string,\n legacy: ReadonlyArray<string>,\n): boolean =>\n contents.startsWith(GENERATED_PREFIX) || legacy.includes(contents);\n\nconst validator = (descriptor: Env.Descriptor): string => {\n const base =\n descriptor.kind === \"literals\"\n ? descriptor.values.length === 1\n ? `v.literal(${quote(descriptor.values[0])})`\n : `v.union(${descriptor.values.map((value) => `v.literal(${quote(value)})`).join(\", \")})`\n : \"v.string()\";\n return descriptor.optional ? `v.optional(${base})` : base;\n};\n\nconst RESERVED = new Set(\n \"await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield\".split(\n \" \",\n ),\n);\n\n/**\n * A safe import name for a component, from its Convex name.\n */\nconst identifier = (name: string): string => {\n const cleaned = name.replaceAll(/[^A-Za-z0-9_$]/g, \"_\");\n const valid = /^[A-Za-z_$]/.test(cleaned) ? cleaned : `_${cleaned}`;\n return RESERVED.has(valid) ? `${valid}Component` : valid;\n};\n\n/**\n * `convex/convex.config.ts`: Convex's own app or component definition.\n */\nexport const convexConfig = (declaration: Declaration): string => {\n const self = declaration.target === \"app\" ? \"app\" : \"component\";\n const aliases = new Map<string, string>();\n const taken = new Set([self, \"v\", \"defineApp\", \"defineComponent\"]);\n for (const mount of declaration.mounts) {\n if (aliases.has(mount.importPath)) continue;\n const base = identifier(mount.componentName);\n let alias = base;\n for (let n = 2; taken.has(alias); n++) alias = `${base}${n}`;\n taken.add(alias);\n aliases.set(mount.importPath, alias);\n }\n\n const lines = [header(\"confect/app.ts\")];\n lines.push(\n declaration.target === \"app\"\n ? 'import { defineApp } from \"convex/server\";'\n : 'import { defineComponent } from \"convex/server\";',\n );\n if (declaration.env.length > 0)\n lines.push('import { v } from \"convex/values\";');\n for (const [importPath, alias] of aliases) {\n lines.push(`import ${alias} from ${quote(importPath)};`);\n }\n lines.push(\"\");\n\n const envBlock =\n declaration.env.length === 0\n ? []\n : [\n \" env: {\",\n ...declaration.env.map(\n ([key, descriptor]) => ` ${key}: ${validator(descriptor)},`,\n ),\n \" },\",\n ];\n if (declaration.target === \"app\") {\n lines.push(\n envBlock.length === 0\n ? \"const app = defineApp();\"\n : [\"const app = defineApp({\", ...envBlock, \"});\"].join(\"\\n\"),\n );\n } else {\n lines.push(\n envBlock.length === 0\n ? `const component = defineComponent(${quote(declaration.name)});`\n : [\n `const component = defineComponent(${quote(declaration.name)}, {`,\n ...envBlock,\n \"});\",\n ].join(\"\\n\"),\n );\n }\n\n for (const mount of declaration.mounts) {\n lines.push(\"\");\n lines.push(`${self}.use(${aliases.get(mount.importPath)}, {`);\n lines.push(` name: ${quote(mount.name)},`);\n if (mount.httpPrefix !== undefined) {\n lines.push(` httpPrefix: ${quote(mount.httpPrefix)},`);\n }\n if (mount.env.length > 0) {\n lines.push(\" env: {\");\n for (const [slot, binding] of mount.env) {\n lines.push(\n ` ${slot}: ${binding.kind === \"value\" ? quote(binding.value) : `${self}.env.${binding.key}`},`,\n );\n }\n lines.push(\" },\");\n }\n lines.push(\"});\");\n }\n\n lines.push(\"\", `export default ${self};`, \"\");\n return lines.join(\"\\n\");\n};\n\nconst providerValue = (value: ProviderValue): string => {\n switch (value.kind) {\n case \"value\":\n return quote(value.value);\n case \"env\":\n return `process.env[${quote(value.key)}]!`;\n default:\n return `\\`\\${process.env.${value.kind === \"siteUrl\" ? \"CONVEX_SITE_URL\" : \"CONVEX_CLOUD_URL\"}}${value.path.replaceAll(/[`$\\\\]/g, \"\\\\$&\")}\\``;\n }\n};\n\n/**\n * `convex/auth.config.ts`: Convex's provider list, with site URLs resolved\n * there.\n */\nexport const authConfig = (providers: ReadonlyArray<Provider>): string =>\n [\n header(\"confect/auth.ts\"),\n 'import type { AuthConfig } from \"convex/server\";',\n \"\",\n \"export default {\",\n providers.length === 0 ? \" providers: [],\" : \" providers: [\",\n ...(providers.length === 0\n ? []\n : [\n ...providers.flatMap((provider) => [\n \" {\",\n ...provider\n .filter(([field]) => field !== \"family\" && field !== \"name\")\n .map(\n ([field, value]) => ` ${field}: ${providerValue(value)},`,\n ),\n \" },\",\n ]),\n \" ],\",\n ]),\n \"} satisfies AuthConfig;\",\n \"\",\n ].join(\"\\n\");\n\n/**\n * Runtime issuer data with no dependency on declarations or component\n * definitions.\n */\nexport const authProviders = (providers: ReadonlyArray<Provider>): string =>\n [\n header(\"confect/auth.ts\"),\n \"\",\n \"export const providers = [\",\n ...providers.flatMap((provider) => [\n \" {\",\n ...provider.flatMap(([field, value]) => {\n const key =\n field === \"domain\"\n ? \"issuer\"\n : field === \"applicationID\"\n ? \"audience\"\n : field;\n return [\"issuer\", \"audience\", \"family\", \"name\"].includes(key)\n ? [` ${key}: ${providerValue(value)},`]\n : [];\n }),\n \" },\",\n ]),\n \"] as const;\",\n \"\",\n ].join(\"\\n\");\n\n/**\n * `confect/_generated/manifest.ts`: plain data, no imports, for infra.\n */\nexport const manifest = (declaration: Declaration, digest: string): string => {\n const data = {\n name: declaration.name,\n env: Object.fromEntries(declaration.env),\n http: {\n mounts: Object.fromEntries(\n declaration.mounts.flatMap(({ name, httpPrefix }) =>\n httpPrefix === undefined ? [] : [[name, httpPrefix]],\n ),\n ),\n },\n digest,\n };\n return `${header(\"confect/env.ts and confect/app.ts\")}\\n\\nexport default ${JSON.stringify(data, null, 2)} as const;\\n`;\n};\n\n/**\n * A digest of the declaration's inputs: every first-party file its modules\n * import (by project-relative path and contents) and the versions of the\n * packages that shape the generated output.\n */\nexport const digest = (input: {\n readonly files: ReadonlyArray<readonly [string, string]>;\n readonly versions: ReadonlyArray<readonly [string, string]>;\n}): string => {\n const hash = createHash(\"sha256\");\n const byFirst = (\n a: readonly [string, string],\n b: readonly [string, string],\n ) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);\n hash.update(\n JSON.stringify({\n files: [...input.files].sort(byFirst),\n versions: [...input.versions].sort(byFirst),\n }),\n );\n return `sha256:${hash.digest(\"hex\")}`;\n};\n"],"mappings":";;;;;;;AAwCA,IAAa,kBAAb,cAAqC,KAAK,YAAY,iBAAiB,CAAC,CAGrE;CACD,IAAa,UAAkB;EAC7B,OAAO,GAAG,KAAK,KAAK,uBAAuB,KAAK,SAAS;CAC3D;AACF;AAEA,IAAa,gBAAb,cAAmC,KAAK,YAAY,eAAe,CAAC,CAEjE;CACD,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,IAAI;CACtB;AACF;AAEA,IAAa,mBAAb,cAAsC,KAAK,YAAY,kBAAkB,CAAC,CAEvE;CACD,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,MAAM;CACxB;AACF;AAEA,IAAa,oBAAb,cAAuC,KAAK,YAAY,mBAAmB,CAAC,CAMzE;CACD,IAAa,UAAkB;EAC7B,OAAO,cAAc,KAAK,MAAM,UAAU,KAAK,KAAK,MAAM,KAAK,IAAI,WAAW,KAAK,QAAQ,oCAAoC,KAAK,gBAAgB;CACtJ;AACF;AAEA,IAAa,iBAAb,cAAoC,KAAK,YAAY,gBAAgB,CAAC,CAGnE;CACD,IAAa,UAAkB;EAC7B,OAAO,cAAc,KAAK,MAAM,UAAU,KAAK,KAAK;CACtD;AACF;AAEA,IAAa,yBAAb,cAA4C,KAAK,YAC/C,wBACF,CAAC,CAA6B;CAC5B,IAAa,UAAkB;EAC7B,OAAO,cAAc,KAAK,MAAM;CAClC;AACF;AA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M,OAAO,WAAW,QAAQ;CAChC,MAAM,WACJ,GACA,MACI,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;CAC3C,KAAK,OACH,KAAK,UAAU;EACb,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,KAAK,OAAO;EACpC,UAAU,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,KAAK,OAAO;CAC5C,CAAC,CACH;CACA,OAAO,UAAU,KAAK,OAAO,KAAK;AACpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DirectoryOptions.mjs","names":["ProjectRoot.layer","ProjectRoot.ProjectRoot","ProjectRoot.findProjectRootFrom","ConvexDirectory.layer","ConvexDirectory.ConvexDirectory","ConvexDirectory.ConvexDirectoryNotFoundError"],"sources":["../src/DirectoryOptions.ts"],"sourcesContent":["import { IdScope } from \"@confect/core\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as Flag from \"effect/cli/Flag\";\nimport * as ConfectDirectory from \"./ConfectDirectory\";\nimport * as ConvexDirectory from \"./ConvexDirectory\";\nimport * as ProjectRoot from \"./ProjectRoot\";\n\nexport const flags = {\n componentDir: Flag.String(\"component-dir\").pipe(\n Flag.withDescription(\n \"Generate a component instead of the application; its sibling confect/ directory contains the source.\",\n ),\n Flag.optional,\n ),\n};\n\nexport const layer = ({\n componentDir,\n}: {\n componentDir: Option.Option<string>;\n}) => {\n const projectRootLayer = Option.match(componentDir, {\n onNone: () => ProjectRoot.layer,\n onSome: (directory) =>\n Layer.effect(\n ProjectRoot.ProjectRoot,\n Effect.map(ProjectRoot.findProjectRootFrom(directory), (root) =>\n ProjectRoot.ProjectRoot.of({\n get: Effect.succeed(root),\n }),\n ),\n ),\n });\n const convex: Layer.Layer<\n ConvexDirectory.ConvexDirectory,\n Layer.Error<typeof ConvexDirectory.layer> | Schema.SchemaError,\n FileSystem.FileSystem | Path.Path\n > = Option.match(componentDir, {\n onNone: () => ConvexDirectory.layer,\n onSome: (directory) =>\n Layer.effect(\n ConvexDirectory.ConvexDirectory,\n Effect.gen(function* () {\n const path = yield* Path.Path;\n const fs = yield* FileSystem.FileSystem;\n const projectRoot = yield* ProjectRoot.ProjectRoot.get;\n const absolute = path.resolve(directory);\n // A declared component's `convex.config.ts` is codegen output, so\n // its sibling `confect/app.ts` also marks the directory.\n if (\n !(yield* fs.exists(path.join(absolute, \"convex.config.ts\"))) &&\n !(yield* fs.exists(\n path.join(path.dirname(absolute), \"confect\", \"app.ts\"),\n ))\n ) {\n return yield* new ConvexDirectory.ConvexDirectoryNotFoundError();\n }\n const pkg = yield* fs\n .readFileString(path.join(projectRoot, \"package.json\"))\n .pipe(\n Effect.flatMap(\n Schema.decodeEffect(\n Schema.fromJsonString(Schema.Struct({ name: Schema.String })),\n ),\n ),\n );\n const definition = `${pkg.name}:${path.relative(projectRoot, absolute).split(path.sep).join(\"/\")}`;\n return ConvexDirectory.ConvexDirectory.of({\n get: Effect.succeed(absolute),\n target: {\n kind: \"component\",\n scope: IdScope.component(definition),\n },\n });\n }),\n ).pipe(Layer.provide(projectRootLayer)),\n });\n return Layer.mergeAll(\n projectRootLayer,\n ConfectDirectory.layerFromConvexDirectory.pipe(Layer.provideMerge(convex)),\n );\n};\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,QAAQ,EACnB,cAAc,KAAK,OAAO,eAAe,CAAC,CAAC,KACzC,KAAK,gBACH,sGACF,GACA,KAAK,QACP,EACF;AAEA,MAAa,SAAS,EACpB,mBAGI;CACJ,MAAM,mBAAmB,OAAO,MAAM,cAAc;EAClD,cAAcA;EACd,SAAS,cACP,MAAM,OACJC,aACA,OAAO,IAAIC,oBAAgC,SAAS,IAAI,SAAA,YAC9B,GAAG,EACzB,KAAK,OAAO,QAAQ,IAAI,EAC1B,CAAC,CACH,CACF;CACJ,CAAC;CACD,MAAM,SAIF,OAAO,MAAM,cAAc;EAC7B,cAAcC;EACd,SAAS,cACP,MAAM,OACJC,iBACA,OAAO,IAAI,aAAa;GACtB,MAAM,OAAO,OAAO,KAAK;GACzB,MAAM,KAAK,OAAO,WAAW;GAC7B,MAAM,cAAc,OAAA,YAA+B;GACnD,MAAM,WAAW,KAAK,QAAQ,SAAS;GAGvC,IACE,EAAE,OAAO,GAAG,OAAO,KAAK,KAAK,UAAU,kBAAkB,CAAC,MAC1D,EAAE,OAAO,GAAG,OACV,KAAK,KAAK,KAAK,QAAQ,QAAQ,GAAG,WAAW,QAAQ,CACvD,IAEA,OAAO,OAAO,IAAIC,6BAA6C;GAWjE,MAAM,aAAa,IAAG,OATH,GAChB,eAAe,KAAK,KAAK,aAAa,cAAc,CAAC,CAAC,CACtD,KACC,OAAO,QACL,OAAO,aACL,OAAO,eAAe,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,CAAC,CAC9D,CACF,CACF,EAAA,CACwB,KAAK,GAAG,KAAK,SAAS,aAAa,QAAQ,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;GAC/F,OAAA,gBAAuC,GAAG;IACxC,KAAK,OAAO,QAAQ,QAAQ;IAC5B,QAAQ;KACN,MAAM;KACN,OAAO,QAAQ,UAAU,UAAU;IACrC;GACF,CAAC;EACH,CAAC,CACH,CAAC,CAAC,KAAK,MAAM,QAAQ,gBAAgB,CAAC;CAC1C,CAAC;CACD,OAAO,MAAM,SACX,kBAAA,yBAC0C,KAAK,MAAM,aAAa,MAAM,CAAC,CAC3E;AACF"}
1
+ {"version":3,"file":"DirectoryOptions.mjs","names":["ProjectRoot.layer","ProjectRoot.ProjectRoot","ProjectRoot.findProjectRootFrom","ConvexDirectory.layer","ConvexDirectory.ConvexDirectory","ConvexDirectory.ConvexDirectoryNotFoundError"],"sources":["../src/DirectoryOptions.ts"],"sourcesContent":["import { IdScope } from \"@confect/core\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as Flag from \"effect/cli/Flag\";\nimport * as ConfectDirectory from \"./ConfectDirectory.js\";\nimport * as ConvexDirectory from \"./ConvexDirectory.js\";\nimport * as ProjectRoot from \"./ProjectRoot.js\";\n\nexport const flags = {\n componentDir: Flag.String(\"component-dir\").pipe(\n Flag.withDescription(\n \"Generate a component instead of the application; its sibling confect/ directory contains the source.\",\n ),\n Flag.optional,\n ),\n};\n\nexport const layer = ({\n componentDir,\n}: {\n componentDir: Option.Option<string>;\n}) => {\n const projectRootLayer = Option.match(componentDir, {\n onNone: () => ProjectRoot.layer,\n onSome: (directory) =>\n Layer.effect(\n ProjectRoot.ProjectRoot,\n Effect.map(ProjectRoot.findProjectRootFrom(directory), (root) =>\n ProjectRoot.ProjectRoot.of({\n get: Effect.succeed(root),\n }),\n ),\n ),\n });\n const convex: Layer.Layer<\n ConvexDirectory.ConvexDirectory,\n Layer.Error<typeof ConvexDirectory.layer> | Schema.SchemaError,\n FileSystem.FileSystem | Path.Path\n > = Option.match(componentDir, {\n onNone: () => ConvexDirectory.layer,\n onSome: (directory) =>\n Layer.effect(\n ConvexDirectory.ConvexDirectory,\n Effect.gen(function* () {\n const path = yield* Path.Path;\n const fs = yield* FileSystem.FileSystem;\n const projectRoot = yield* ProjectRoot.ProjectRoot.get;\n const absolute = path.resolve(directory);\n // A declared component's `convex.config.ts` is codegen output, so\n // its sibling `confect/app.ts` also marks the directory.\n if (\n !(yield* fs.exists(path.join(absolute, \"convex.config.ts\"))) &&\n !(yield* fs.exists(\n path.join(path.dirname(absolute), \"confect\", \"app.ts\"),\n ))\n ) {\n return yield* new ConvexDirectory.ConvexDirectoryNotFoundError();\n }\n const pkg = yield* fs\n .readFileString(path.join(projectRoot, \"package.json\"))\n .pipe(\n Effect.flatMap(\n Schema.decodeEffect(\n Schema.fromJsonString(Schema.Struct({ name: Schema.String })),\n ),\n ),\n );\n const definition = `${pkg.name}:${path.relative(projectRoot, absolute).split(path.sep).join(\"/\")}`;\n return ConvexDirectory.ConvexDirectory.of({\n get: Effect.succeed(absolute),\n target: {\n kind: \"component\",\n scope: IdScope.component(definition),\n },\n });\n }),\n ).pipe(Layer.provide(projectRootLayer)),\n });\n return Layer.mergeAll(\n projectRootLayer,\n ConfectDirectory.layerFromConvexDirectory.pipe(Layer.provideMerge(convex)),\n );\n};\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,QAAQ,EACnB,cAAc,KAAK,OAAO,eAAe,CAAC,CAAC,KACzC,KAAK,gBACH,sGACF,GACA,KAAK,QACP,EACF;AAEA,MAAa,SAAS,EACpB,mBAGI;CACJ,MAAM,mBAAmB,OAAO,MAAM,cAAc;EAClD,cAAcA;EACd,SAAS,cACP,MAAM,OACJC,aACA,OAAO,IAAIC,oBAAgC,SAAS,IAAI,SAAA,YAC9B,GAAG,EACzB,KAAK,OAAO,QAAQ,IAAI,EAC1B,CAAC,CACH,CACF;CACJ,CAAC;CACD,MAAM,SAIF,OAAO,MAAM,cAAc;EAC7B,cAAcC;EACd,SAAS,cACP,MAAM,OACJC,iBACA,OAAO,IAAI,aAAa;GACtB,MAAM,OAAO,OAAO,KAAK;GACzB,MAAM,KAAK,OAAO,WAAW;GAC7B,MAAM,cAAc,OAAA,YAA+B;GACnD,MAAM,WAAW,KAAK,QAAQ,SAAS;GAGvC,IACE,EAAE,OAAO,GAAG,OAAO,KAAK,KAAK,UAAU,kBAAkB,CAAC,MAC1D,EAAE,OAAO,GAAG,OACV,KAAK,KAAK,KAAK,QAAQ,QAAQ,GAAG,WAAW,QAAQ,CACvD,IAEA,OAAO,OAAO,IAAIC,6BAA6C;GAWjE,MAAM,aAAa,IAAG,OATH,GAChB,eAAe,KAAK,KAAK,aAAa,cAAc,CAAC,CAAC,CACtD,KACC,OAAO,QACL,OAAO,aACL,OAAO,eAAe,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,CAAC,CAC9D,CACF,CACF,EAAA,CACwB,KAAK,GAAG,KAAK,SAAS,aAAa,QAAQ,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;GAC/F,OAAA,gBAAuC,GAAG;IACxC,KAAK,OAAO,QAAQ,QAAQ;IAC5B,QAAQ;KACN,MAAM;KACN,OAAO,QAAQ,UAAU,UAAU;IACrC;GACF,CAAC;EACH,CAAC,CACH,CAAC,CAAC,KAAK,MAAM,QAAQ,gBAAgB,CAAC;CAC1C,CAAC;CACD,OAAO,MAAM,SACX,kBAAA,yBAC0C,KAAK,MAAM,aAAa,MAAM,CAAC,CAC3E;AACF"}
@@ -46,6 +46,7 @@ const planDeclarations = (declarations, affectedImpls, path) => {
46
46
  };
47
47
  const isOptional = Predicate.or(Kind.$is("Http"), Predicate.or(Kind.$is("Crons"), Kind.$is("Auth")));
48
48
  const parse = (relativePath) => {
49
+ if (relativePath === "runtime.ts") return Option.some(Kind.Runtime({ relativePath }));
49
50
  if (relativePath === "env.ts") return Option.some(Kind.Env({ relativePath }));
50
51
  if (relativePath === "app.ts") return Option.some(Kind.App({ relativePath }));
51
52
  if (relativePath === "callbacks.ts") return Option.some(Kind.Callbacks({ relativePath }));
@@ -74,6 +75,7 @@ const discover = Effect.gen(function* () {
74
75
  const declaration = yield* tryEntry(Kind.App({ relativePath: "app.ts" }));
75
76
  const fixedEntryOptions = yield* Effect.all([
76
77
  tryEntry(Kind.Env({ relativePath: "env.ts" })),
78
+ tryEntry(Kind.Runtime({ relativePath: "runtime.ts" })),
77
79
  Effect.succeed(declaration),
78
80
  (yield* ConvexDirectory.target).kind === "component" ? tryEntry(Kind.Callbacks({ relativePath: "callbacks.ts" })) : Effect.succeedNone,
79
81
  tryEntry(Kind.Http({ relativePath: "http.ts" })),
@@ -1 +1 @@
1
- {"version":3,"file":"EntryPoint.mjs","names":["SpecModulePath.SpecModulePath","SpecModulePath.toImpl"],"sources":["../src/EntryPoint.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Chunk from \"effect/Chunk\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport { ImplModulePath } from \"./ImplModulePath\";\nimport * as SpecModulePath from \"./SpecModulePath\";\nimport { TableModulePath } from \"./TableModulePath\";\nimport { ConfectDirectory } from \"./ConfectDirectory\";\nimport { ConvexDirectory } from \"./ConvexDirectory\";\nimport { CONVEX_CONFIG_FILENAME } from \"./ConvexConfig\";\nimport { discoverLeafImplFiles, discoverLeafSpecFiles } from \"./LeafModule\";\nimport { discoverTableFiles, type TableModule } from \"./TableModule\";\n\nexport type Kind = Data.TaggedEnum<{\n Env: { readonly relativePath: \"env.ts\" };\n App: { readonly relativePath: \"app.ts\" };\n Callbacks: { readonly relativePath: \"callbacks.ts\" };\n Spec: { readonly relativePath: SpecModulePath.SpecModulePath };\n Impl: { readonly relativePath: ImplModulePath };\n Table: { readonly relativePath: TableModulePath };\n Http: { readonly relativePath: \"http.ts\" };\n Crons: { readonly relativePath: \"crons.ts\" };\n Auth: { readonly relativePath: \"auth.ts\" };\n Config: {};\n}>;\n\nexport const Kind = Data.taggedEnum<Kind>();\nexport const Declaration = Schema.TaggedUnion({\n Spec: { relativePath: SpecModulePath.SpecModulePath },\n Table: { relativePath: TableModulePath },\n});\nexport type Declaration = typeof Declaration.Type;\n\nexport const planDeclarations = (\n declarations: Array.NonEmptyReadonlyArray<Declaration>,\n affectedImpls: ReadonlyArray<ImplModulePath>,\n path: Path.Path,\n): {\n readonly tables: ReadonlyArray<TableModule>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n} => {\n const plan = Array.reduce(\n declarations,\n {\n tables: Chunk.empty<TableModule>(),\n paths: HashSet.fromIterable(affectedImpls),\n },\n (state, declaration) =>\n Declaration.match(declaration, {\n Spec: ({ relativePath }) => ({\n ...state,\n paths: HashSet.add(state.paths, SpecModulePath.toImpl(relativePath)),\n }),\n Table: ({ relativePath }) => ({\n ...state,\n tables: Chunk.append(state.tables, {\n relativePath,\n tableName: path.parse(relativePath).name,\n }),\n }),\n }),\n );\n return {\n tables: Chunk.toReadonlyArray(plan.tables),\n paths: Array.fromIterable(plan.paths),\n };\n};\n\nexport type EntryPoint = Kind & {\n readonly absolutePath: string;\n readonly inputPath: string;\n};\nexport type OptionalFile = \"Http\" | \"Crons\" | \"Auth\";\n\nexport const isOptional = Predicate.or(\n Kind.$is(\"Http\"),\n Predicate.or(Kind.$is(\"Crons\"), Kind.$is(\"Auth\")),\n);\n\nexport const parse = (\n relativePath: string,\n): Option.Option<Exclude<Kind, { readonly _tag: \"Config\" }>> => {\n if (relativePath === \"env.ts\") return Option.some(Kind.Env({ relativePath }));\n if (relativePath === \"app.ts\") return Option.some(Kind.App({ relativePath }));\n if (relativePath === \"callbacks.ts\")\n return Option.some(Kind.Callbacks({ relativePath }));\n if (relativePath === \"http.ts\")\n return Option.some(Kind.Http({ relativePath }));\n if (relativePath === \"crons.ts\")\n return Option.some(Kind.Crons({ relativePath }));\n if (relativePath === \"auth.ts\")\n return Option.some(Kind.Auth({ relativePath }));\n const tablePath = Schema.decodeOption(TableModulePath)(relativePath);\n if (Option.isSome(tablePath))\n return Option.some(Kind.Table({ relativePath: tablePath.value }));\n const specPath = Schema.decodeOption(SpecModulePath.SpecModulePath)(\n relativePath,\n );\n if (Option.isSome(specPath))\n return Option.some(Kind.Spec({ relativePath: specPath.value }));\n return Schema.decodeOption(ImplModulePath)(relativePath).pipe(\n Option.map((implPath) => Kind.Impl({ relativePath: implPath })),\n );\n};\n\nexport const discover = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const tryEntry = Effect.fnUntraced(function* (\n kind: Exclude<Kind, { readonly _tag: \"Config\" }>,\n ) {\n const absolutePath = path.join(confectDirectory, kind.relativePath);\n if (!(yield* fs.exists(absolutePath))) {\n return Option.none<EntryPoint>();\n }\n return Option.some<EntryPoint>({\n ...kind,\n absolutePath,\n inputPath: yield* fs\n .realPath(absolutePath)\n .pipe(Effect.orElseSucceed(() => absolutePath)),\n });\n });\n\n const declaration = yield* tryEntry(Kind.App({ relativePath: \"app.ts\" }));\n const fixedEntryOptions = yield* Effect.all([\n tryEntry(Kind.Env({ relativePath: \"env.ts\" })),\n Effect.succeed(declaration),\n (yield* ConvexDirectory.target).kind === \"component\"\n ? tryEntry(Kind.Callbacks({ relativePath: \"callbacks.ts\" }))\n : Effect.succeedNone,\n tryEntry(Kind.Http({ relativePath: \"http.ts\" })),\n tryEntry(Kind.Crons({ relativePath: \"crons.ts\" })),\n tryEntry(Kind.Auth({ relativePath: \"auth.ts\" })),\n ]);\n\n const moduleRelativePaths = yield* Effect.all([\n discoverLeafSpecFiles,\n discoverLeafImplFiles,\n discoverTableFiles,\n ]).pipe(Effect.map(Array.flatten));\n const moduleEntryOptions = yield* Effect.forEach(\n Array.getSomes(moduleRelativePaths.map(parse)),\n tryEntry,\n );\n\n // `convex/convex.config.ts` feeds the generated components registry, so\n // edits to it (or to a locally-defined component definition it imports—npm component definitions are externalized and not watched) must re-run\n // codegen.\n const convexDirectory = yield* ConvexDirectory.get;\n const convexConfigEntryOption = yield* Effect.gen(function* () {\n const absolutePath = path.join(convexDirectory, CONVEX_CONFIG_FILENAME);\n // A declared backend's `convex.config.ts` is codegen output, not input.\n if (Option.isSome(declaration) || !(yield* fs.exists(absolutePath))) {\n return Option.none<EntryPoint>();\n }\n return Option.some<EntryPoint>({\n ...Kind.Config(),\n absolutePath,\n inputPath: yield* fs\n .realPath(absolutePath)\n .pipe(Effect.orElseSucceed(() => absolutePath)),\n });\n });\n\n return Array.getSomes([\n ...fixedEntryOptions,\n convexConfigEntryOption,\n ...moduleEntryOptions,\n ]);\n}).pipe(\n Effect.retry({\n times: 3,\n while: (error) =>\n error._tag === \"PlatformError\" && error.reason._tag === \"NotFound\",\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,MAAa,OAAO,KAAK,WAAiB;AAC1C,MAAa,cAAc,OAAO,YAAY;CAC5C,MAAM,EAAE,cAAcA,eAA8B;CACpD,OAAO,EAAE,cAAc,gBAAgB;AACzC,CAAC;AAGD,MAAa,oBACX,cACA,eACA,SAIG;CACH,MAAM,OAAO,MAAM,OACjB,cACA;EACE,QAAQ,MAAM,MAAmB;EACjC,OAAO,QAAQ,aAAa,aAAa;CAC3C,IACC,OAAO,gBACN,YAAY,MAAM,aAAa;EAC7B,OAAO,EAAE,oBAAoB;GAC3B,GAAG;GACH,OAAO,QAAQ,IAAI,MAAM,OAAOC,OAAsB,YAAY,CAAC;EACrE;EACA,QAAQ,EAAE,oBAAoB;GAC5B,GAAG;GACH,QAAQ,MAAM,OAAO,MAAM,QAAQ;IACjC;IACA,WAAW,KAAK,MAAM,YAAY,CAAC,CAAC;GACtC,CAAC;EACH;CACF,CAAC,CACL;CACA,OAAO;EACL,QAAQ,MAAM,gBAAgB,KAAK,MAAM;EACzC,OAAO,MAAM,aAAa,KAAK,KAAK;CACtC;AACF;AAQA,MAAa,aAAa,UAAU,GAClC,KAAK,IAAI,MAAM,GACf,UAAU,GAAG,KAAK,IAAI,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,CAClD;AAEA,MAAa,SACX,iBAC8D;CAC9D,IAAI,iBAAiB,UAAU,OAAO,OAAO,KAAK,KAAK,IAAI,EAAE,aAAa,CAAC,CAAC;CAC5E,IAAI,iBAAiB,UAAU,OAAO,OAAO,KAAK,KAAK,IAAI,EAAE,aAAa,CAAC,CAAC;CAC5E,IAAI,iBAAiB,gBACnB,OAAO,OAAO,KAAK,KAAK,UAAU,EAAE,aAAa,CAAC,CAAC;CAC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sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Chunk from \"effect/Chunk\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport { ImplModulePath } from \"./ImplModulePath.js\";\nimport * as SpecModulePath from \"./SpecModulePath.js\";\nimport { TableModulePath } from \"./TableModulePath.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport { CONVEX_CONFIG_FILENAME } from \"./ConvexConfig.js\";\nimport { discoverLeafImplFiles, discoverLeafSpecFiles } from \"./LeafModule.js\";\nimport { discoverTableFiles, type TableModule } from \"./TableModule.js\";\n\nexport type Kind = Data.TaggedEnum<{\n Env: { readonly relativePath: \"env.ts\" };\n App: { readonly relativePath: \"app.ts\" };\n Runtime: { readonly relativePath: \"runtime.ts\" };\n Callbacks: { readonly relativePath: \"callbacks.ts\" };\n Spec: { readonly relativePath: SpecModulePath.SpecModulePath };\n Impl: { readonly relativePath: ImplModulePath };\n Table: { readonly relativePath: TableModulePath };\n Http: { readonly relativePath: \"http.ts\" };\n Crons: { readonly relativePath: \"crons.ts\" };\n Auth: { readonly relativePath: \"auth.ts\" };\n Config: {};\n}>;\n\nexport const Kind = Data.taggedEnum<Kind>();\nexport const Declaration = Schema.TaggedUnion({\n Spec: { relativePath: SpecModulePath.SpecModulePath },\n Table: { relativePath: TableModulePath },\n});\nexport type Declaration = typeof Declaration.Type;\n\nexport const planDeclarations = (\n declarations: Array.NonEmptyReadonlyArray<Declaration>,\n affectedImpls: ReadonlyArray<ImplModulePath>,\n path: Path.Path,\n): {\n readonly tables: ReadonlyArray<TableModule>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n} => {\n const plan = Array.reduce(\n declarations,\n {\n tables: Chunk.empty<TableModule>(),\n paths: HashSet.fromIterable(affectedImpls),\n },\n (state, declaration) =>\n Declaration.match(declaration, {\n Spec: ({ relativePath }) => ({\n ...state,\n paths: HashSet.add(state.paths, SpecModulePath.toImpl(relativePath)),\n }),\n Table: ({ relativePath }) => ({\n ...state,\n tables: Chunk.append(state.tables, {\n relativePath,\n tableName: path.parse(relativePath).name,\n }),\n }),\n }),\n );\n return {\n tables: Chunk.toReadonlyArray(plan.tables),\n paths: Array.fromIterable(plan.paths),\n };\n};\n\nexport type EntryPoint = Kind & {\n readonly absolutePath: string;\n readonly inputPath: string;\n};\nexport type OptionalFile = \"Http\" | \"Crons\" | \"Auth\";\n\nexport const isOptional = Predicate.or(\n Kind.$is(\"Http\"),\n Predicate.or(Kind.$is(\"Crons\"), Kind.$is(\"Auth\")),\n);\n\nexport const parse = (\n relativePath: string,\n): Option.Option<Exclude<Kind, { readonly _tag: \"Config\" }>> => {\n if (relativePath === \"runtime.ts\")\n return Option.some(Kind.Runtime({ relativePath }));\n if (relativePath === \"env.ts\") return Option.some(Kind.Env({ relativePath }));\n if (relativePath === \"app.ts\") return Option.some(Kind.App({ relativePath }));\n if (relativePath === \"callbacks.ts\")\n return Option.some(Kind.Callbacks({ relativePath }));\n if (relativePath === \"http.ts\")\n return Option.some(Kind.Http({ relativePath }));\n if (relativePath === \"crons.ts\")\n return Option.some(Kind.Crons({ relativePath }));\n if (relativePath === \"auth.ts\")\n return Option.some(Kind.Auth({ relativePath }));\n const tablePath = Schema.decodeOption(TableModulePath)(relativePath);\n if (Option.isSome(tablePath))\n return Option.some(Kind.Table({ relativePath: tablePath.value }));\n const specPath = Schema.decodeOption(SpecModulePath.SpecModulePath)(\n relativePath,\n );\n if (Option.isSome(specPath))\n return Option.some(Kind.Spec({ relativePath: specPath.value }));\n return Schema.decodeOption(ImplModulePath)(relativePath).pipe(\n Option.map((implPath) => Kind.Impl({ relativePath: implPath })),\n );\n};\n\nexport const discover = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const tryEntry = Effect.fnUntraced(function* (\n kind: Exclude<Kind, { readonly _tag: \"Config\" }>,\n ) {\n const absolutePath = path.join(confectDirectory, kind.relativePath);\n if (!(yield* fs.exists(absolutePath))) {\n return Option.none<EntryPoint>();\n }\n return Option.some<EntryPoint>({\n ...kind,\n absolutePath,\n inputPath: yield* fs\n .realPath(absolutePath)\n .pipe(Effect.orElseSucceed(() => absolutePath)),\n });\n });\n\n const declaration = yield* tryEntry(Kind.App({ relativePath: \"app.ts\" }));\n const fixedEntryOptions = yield* Effect.all([\n tryEntry(Kind.Env({ relativePath: \"env.ts\" })),\n tryEntry(Kind.Runtime({ relativePath: \"runtime.ts\" })),\n Effect.succeed(declaration),\n (yield* ConvexDirectory.target).kind === \"component\"\n ? tryEntry(Kind.Callbacks({ relativePath: \"callbacks.ts\" }))\n : Effect.succeedNone,\n tryEntry(Kind.Http({ relativePath: \"http.ts\" })),\n tryEntry(Kind.Crons({ relativePath: \"crons.ts\" })),\n tryEntry(Kind.Auth({ relativePath: \"auth.ts\" })),\n ]);\n\n const moduleRelativePaths = yield* Effect.all([\n discoverLeafSpecFiles,\n discoverLeafImplFiles,\n discoverTableFiles,\n ]).pipe(Effect.map(Array.flatten));\n const moduleEntryOptions = yield* Effect.forEach(\n Array.getSomes(moduleRelativePaths.map(parse)),\n tryEntry,\n );\n\n // `convex/convex.config.ts` feeds the generated components registry, so\n // edits to it (or to a locally-defined component definition it imports—npm component definitions are externalized and not watched) must re-run\n // codegen.\n const convexDirectory = yield* ConvexDirectory.get;\n const convexConfigEntryOption = yield* Effect.gen(function* () {\n const absolutePath = path.join(convexDirectory, CONVEX_CONFIG_FILENAME);\n // A declared backend's `convex.config.ts` is codegen output, not input.\n if (Option.isSome(declaration) || !(yield* fs.exists(absolutePath))) {\n return Option.none<EntryPoint>();\n }\n return Option.some<EntryPoint>({\n ...Kind.Config(),\n absolutePath,\n inputPath: yield* fs\n .realPath(absolutePath)\n .pipe(Effect.orElseSucceed(() => absolutePath)),\n });\n });\n\n return Array.getSomes([\n ...fixedEntryOptions,\n convexConfigEntryOption,\n ...moduleEntryOptions,\n ]);\n}).pipe(\n Effect.retry({\n times: 3,\n while: (error) =>\n error._tag === \"PlatformError\" && error.reason._tag === \"NotFound\",\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAa,OAAO,KAAK,WAAiB;AAC1C,MAAa,cAAc,OAAO,YAAY;CAC5C,MAAM,EAAE,cAAcA,eAA8B;CACpD,OAAO,EAAE,cAAc,gBAAgB;AACzC,CAAC;AAGD,MAAa,oBACX,cACA,eACA,SAIG;CACH,MAAM,OAAO,MAAM,OACjB,cACA;EACE,QAAQ,MAAM,MAAmB;EACjC,OAAO,QAAQ,aAAa,aAAa;CAC3C,IACC,OAAO,gBACN,YAAY,MAAM,aAAa;EAC7B,OAAO,EAAE,oBAAoB;GAC3B,GAAG;GACH,OAAO,QAAQ,IAAI,MAAM,OAAOC,OAAsB,YAAY,CAAC;EACrE;EACA,QAAQ,EAAE,oBAAoB;GAC5B,GAAG;GACH,QAAQ,MAAM,OAAO,MAAM,QAAQ;IACjC;IACA,WAAW,KAAK,MAAM,YAAY,CAAC,CAAC;GACtC,CAAC;EACH;CACF,CAAC,CACL;CACA,OAAO;EACL,QAAQ,MAAM,gBAAgB,KAAK,MAAM;EACzC,OAAO,MAAM,aAAa,KAAK,KAAK;CACtC;AACF;AAQA,MAAa,aAAa,UAAU,GAClC,KAAK,IAAI,MAAM,GACf,UAAU,GAAG,KAAK,IAAI,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,CAClD;AAEA,MAAa,SACX,iBAC8D;CAC9D,IAAI,iBAAiB,cACnB,OAAO,OAAO,KAAK,KAAK,QAAQ,EAAE,aAAa,CAAC,CAAC;CACnD,IAAI,iBAAiB,UAAU,OAAO,OAAO,KAAK,KAAK,IAAI,EAAE,aAAa,C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G;CACL,CAAC;AACH,CAAC,CAAC,CAAC,KACD,OAAO,MAAM;CACX,OAAO;CACP,QAAQ,UACN,MAAM,SAAS,mBAAmB,MAAM,OAAO,SAAS;AAC5D,CAAC,CACH"}
@@ -12,11 +12,13 @@ import * as Path from "effect/Path";
12
12
  import * as HashSet from "effect/HashSet";
13
13
  import * as Match from "effect/Match";
14
14
  import * as Option from "effect/Option";
15
+ import * as Context from "effect/Context";
15
16
  import * as Schema from "effect/Schema";
16
17
  import * as Console from "effect/Console";
17
18
  import * as Layer from "effect/Layer";
18
19
  import * as NodeWorker from "@effect/platform-node/NodeWorker";
19
20
  import { fork } from "node:child_process";
21
+ import * as Pool from "effect/Pool";
20
22
  import * as LogLevel from "effect/LogLevel";
21
23
  import * as References from "effect/References";
22
24
  import * as Rpc from "effect/rpc/Rpc";
@@ -35,7 +37,7 @@ const RequestContext = Schema.Struct({
35
37
  });
36
38
  var EvaluationError = class extends Schema.TaggedError()("EvaluationError", { diagnostic: Schema.String }) {};
37
39
  const Failure = Schema.Union([EvaluationError, ComponentNodeGroupError]);
38
- const requests = RpcGroup.make(Rpc.make("Previous", {
40
+ const requests = RpcGroup.make(Rpc.make("Ready", { success: Schema.Void }), Rpc.make("Previous", {
39
41
  payload: RequestContext,
40
42
  success: FunctionPaths,
41
43
  error: Failure
@@ -60,6 +62,29 @@ const requests = RpcGroup.make(Rpc.make("Previous", {
60
62
  success: GenerationSnapshot,
61
63
  error: Failure
62
64
  }));
65
+ const acquireWorker = Effect.gen(function* () {
66
+ const child = yield* Effect.acquireRelease(Effect.sync(() => fork(new URL("../dist/EvaluationWorker.mjs", import.meta.url), { serialization: "advanced" })), (evaluator) => Effect.callback((resume) => {
67
+ if (evaluator.exitCode !== null || evaluator.signalCode !== null) {
68
+ resume(Effect.void);
69
+ return;
70
+ }
71
+ evaluator.once("exit", () => resume(Effect.void));
72
+ evaluator.kill("SIGKILL");
73
+ }));
74
+ const protocol = yield* Layer.build(RpcClient.layerProtocolWorker({ size: 1 }).pipe(Layer.provide(NodeWorker.layer(() => child))));
75
+ const client = yield* RpcClient.make(requests).pipe(Effect.provideContext(protocol));
76
+ yield* client.Ready();
77
+ yield* Effect.logDebug("Evaluator ready").pipe(Effect.annotateLogs({ pid: child.pid }));
78
+ return {
79
+ child,
80
+ client
81
+ };
82
+ });
83
+ var Standby = class extends Context.Service()("@confect/cli/Evaluation/Standby") {};
84
+ const prewarmedLayer = Layer.effect(Standby, Pool.make({
85
+ acquire: acquireWorker,
86
+ size: 1
87
+ }));
63
88
  const withWorker = Effect.fn("Evaluation.withWorker")(function* (run) {
64
89
  const requestContext = {
65
90
  projectRoot: yield* ProjectRoot.get,
@@ -72,17 +97,18 @@ const withWorker = Effect.fn("Evaluation.withWorker")(function* (run) {
72
97
  minimumLogLevel: yield* References.MinimumLogLevel
73
98
  };
74
99
  return yield* Effect.scoped(Effect.gen(function* () {
75
- const child = yield* Effect.acquireRelease(Effect.sync(() => fork(new URL("../dist/EvaluationWorker.mjs", import.meta.url), { serialization: "advanced" })), (evaluator) => Effect.callback((resume) => {
76
- if (evaluator.exitCode !== null || evaluator.signalCode !== null) {
77
- resume(Effect.void);
78
- return;
79
- }
80
- evaluator.once("exit", () => resume(Effect.void));
81
- evaluator.kill("SIGKILL");
82
- }));
83
- return yield* Effect.gen(function* () {
84
- return yield* run(yield* RpcClient.make(requests), requestContext);
85
- }).pipe(Effect.provide(RpcClient.layerProtocolWorker({ size: 1 }).pipe(Layer.provide(NodeWorker.layer(() => child)))));
100
+ const standby = yield* Effect.serviceOption(Standby);
101
+ return yield* run((yield* Option.match(standby, {
102
+ onNone: () => acquireWorker,
103
+ onSome: (pool) => Effect.gen(function* () {
104
+ while (true) {
105
+ const candidate = yield* Pool.get(pool);
106
+ yield* Effect.addFinalizer(() => Pool.invalidate(pool, candidate));
107
+ if (candidate.child.connected && candidate.child.exitCode === null && candidate.child.signalCode === null) return candidate;
108
+ yield* Pool.invalidate(pool, candidate);
109
+ }
110
+ })
111
+ })).client, requestContext);
86
112
  })).pipe(Effect.catchTags({
87
113
  WorkerError: (error) => Effect.fail(new EvaluationError({ diagnostic: error.message })),
88
114
  RpcClientError: (error) => Effect.fail(new EvaluationError({ diagnostic: error.message }))
@@ -112,6 +138,6 @@ const catchAndLog = (effect) => effect.pipe(Effect.asSome, Effect.catchTags({
112
138
  ComponentNodeGroupError: (error) => logCodegenError(error).pipe(Effect.as(Option.none()))
113
139
  }));
114
140
  //#endregion
115
- export { EvaluationError, RequestContext, catchAndLog, generateSnapshot, loadPreviousFunctionPaths, requests, updateDeclarations, validate };
141
+ export { EvaluationError, RequestContext, catchAndLog, generateSnapshot, loadPreviousFunctionPaths, prewarmedLayer, requests, updateDeclarations, validate };
116
142
 
117
143
  //# sourceMappingURL=Evaluation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Evaluation.mjs","names":["GenerationSnapshot.GenerationSnapshot","EntryPoint.Declaration","GenerationSnapshot.functionPaths"],"sources":["../src/Evaluation.ts"],"sourcesContent":["import * as NodeWorker from \"@effect/platform-node/NodeWorker\";\nimport { fork } from \"node:child_process\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Layer from \"effect/Layer\";\nimport * as LogLevel from \"effect/LogLevel\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as References from \"effect/References\";\nimport * as Rpc from \"effect/rpc/Rpc\";\nimport * as RpcClient from \"effect/rpc/RpcClient\";\nimport type { RpcClientError } from \"effect/rpc/RpcClientError\";\nimport * as RpcGroup from \"effect/rpc/RpcGroup\";\nimport type * as Array from \"effect/Array\";\nimport * as Match from \"effect/Match\";\nimport { ComponentNodeGroupError, logCodegenError } from \"./CodegenError\";\nimport * as EntryPoint from \"./EntryPoint\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot\";\nimport { ConfectDirectory } from \"./ConfectDirectory\";\nimport { ConvexDirectory } from \"./ConvexDirectory\";\nimport { FunctionPaths } from \"./FunctionPaths\";\nimport { ImplModulePath } from \"./ImplModulePath\";\nimport { ProjectRoot } from \"./ProjectRoot\";\n\nexport const RequestContext = Schema.Struct({\n projectRoot: Schema.String,\n confectDirectory: Schema.String,\n convexDirectory: Schema.String,\n target: Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"app\") }),\n Schema.Struct({\n kind: Schema.Literal(\"component\"),\n definition: Schema.String,\n }),\n ]),\n minimumLogLevel: Schema.Literals(LogLevel.values),\n});\nexport type RequestContext = typeof RequestContext.Type;\n\nexport class EvaluationError extends Schema.TaggedError<EvaluationError>()(\n \"EvaluationError\",\n { diagnostic: Schema.String },\n) {}\n\n// A rejected Node group stays typed so the caller can restore component output.\nconst Failure = Schema.Union([EvaluationError, ComponentNodeGroupError]);\n\nexport const requests = RpcGroup.make(\n Rpc.make(\"Previous\", {\n payload: RequestContext,\n success: FunctionPaths,\n error: Failure,\n }),\n Rpc.make(\"Generate\", {\n payload: RequestContext,\n success: GenerationSnapshot.GenerationSnapshot,\n error: Failure,\n }),\n Rpc.make(\"Validate\", {\n payload: Schema.Struct({\n ...RequestContext.fields,\n paths: Schema.Array(ImplModulePath),\n }),\n success: Schema.Void,\n error: Failure,\n }),\n Rpc.make(\"Update\", {\n payload: Schema.Struct({\n ...RequestContext.fields,\n snapshot: GenerationSnapshot.GenerationSnapshot,\n declarations: Schema.NonEmptyArray(EntryPoint.Declaration),\n paths: Schema.Array(ImplModulePath),\n }),\n success: GenerationSnapshot.GenerationSnapshot,\n error: Failure,\n }),\n);\n\nconst withWorker = Effect.fn(\"Evaluation.withWorker\")(function* <A>(\n run: (\n client: RpcClient.RpcClient<RpcGroup.Rpcs<typeof requests>, RpcClientError>,\n requestContext: RequestContext,\n ) => Effect.Effect<\n A,\n EvaluationError | ComponentNodeGroupError | RpcClientError\n >,\n) {\n const requestContext = {\n projectRoot: yield* ProjectRoot.get,\n confectDirectory: yield* ConfectDirectory.get,\n convexDirectory: yield* ConvexDirectory.get,\n target: Match.value(yield* ConvexDirectory.target).pipe(\n Match.when({ kind: \"app\" }, () => ({ kind: \"app\" as const })),\n Match.when({ kind: \"component\" }, ({ scope }) => ({\n kind: \"component\" as const,\n definition: scope.slice(\"component:\".length),\n })),\n Match.exhaustive,\n ),\n minimumLogLevel: yield* References.MinimumLogLevel,\n };\n return yield* Effect.scoped(\n Effect.gen(function* () {\n const child = yield* Effect.acquireRelease(\n Effect.sync(() =>\n fork(new URL(\"../dist/EvaluationWorker.mjs\", import.meta.url), {\n serialization: \"advanced\",\n }),\n ),\n (evaluator) =>\n Effect.callback<void>((resume) => {\n if (evaluator.exitCode !== null || evaluator.signalCode !== null) {\n resume(Effect.void);\n return;\n }\n evaluator.once(\"exit\", () => resume(Effect.void));\n evaluator.kill(\"SIGKILL\");\n }),\n );\n return yield* Effect.gen(function* () {\n const client = yield* RpcClient.make(requests);\n return yield* run(client, requestContext);\n }).pipe(\n Effect.provide(\n RpcClient.layerProtocolWorker({ size: 1 }).pipe(\n Layer.provide(NodeWorker.layer(() => child)),\n ),\n ),\n );\n }),\n ).pipe(\n Effect.catchTags({\n WorkerError: (error) =>\n Effect.fail(new EvaluationError({ diagnostic: error.message })),\n RpcClientError: (error) =>\n Effect.fail(new EvaluationError({ diagnostic: error.message })),\n }),\n );\n});\n\nexport const loadPreviousFunctionPaths = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n if (\n !(yield* fs.exists(path.join(confectDirectory, \"_generated\", \"spec.ts\")))\n ) {\n return FunctionPaths.make(HashSet.empty());\n }\n return yield* withWorker((client, requestContext) =>\n client.Previous(requestContext),\n );\n});\n\nexport const generateSnapshot = withWorker((client, requestContext) =>\n client.Generate(requestContext),\n);\n\nexport const generate = generateSnapshot.pipe(\n Effect.map(GenerationSnapshot.functionPaths),\n);\n\nexport const updateDeclarations = (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n declarations: Array.NonEmptyReadonlyArray<EntryPoint.Declaration>,\n paths: ReadonlyArray<ImplModulePath>,\n) =>\n withWorker((client, requestContext) =>\n client.Update({\n ...requestContext,\n snapshot,\n declarations,\n paths,\n }),\n );\n\nexport const validate = (paths: ReadonlyArray<ImplModulePath>) =>\n withWorker((client, requestContext) =>\n client.Validate({ ...requestContext, paths }),\n );\n\nexport const catchAndLog = <A, R>(\n effect: Effect.Effect<A, EvaluationError | ComponentNodeGroupError, R>,\n): Effect.Effect<Option.Option<A>, never, R> =>\n effect.pipe(\n Effect.asSome,\n Effect.catchTags({\n EvaluationError: ({ diagnostic }) =>\n Console.error(diagnostic).pipe(Effect.as(Option.none<A>())),\n ComponentNodeGroupError: (error) =>\n logCodegenError(error).pipe(Effect.as(Option.none<A>())),\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,iBAAiB,OAAO,OAAO;CAC1C,aAAa,OAAO;CACpB,kBAAkB,OAAO;CACzB,iBAAiB,OAAO;CACxB,QAAQ,OAAO,MAAM,CACnB,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,KAAK,EAAE,CAAC,GAC7C,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,WAAW;EAChC,YAAY,OAAO;CACrB,CAAC,CACH,CAAC;CACD,iBAAiB,OAAO,SAAS,SAAS,MAAM;AAClD,CAAC;AAGD,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CACxE,mBACA,EAAE,YAAY,OAAO,OAAO,CAC9B,CAAC,CAAC,CAAC;AAGH,MAAM,UAAU,OAAO,MAAM,CAAC,iBAAiB,uBAAuB,CAAC;AAEvE,MAAa,WAAW,SAAS,KAC/B,IAAI,KAAK,YAAY;CACnB,SAAS;CACT,SAAS;CACT,OAAO;AACT,CAAC,GACD,IAAI,KAAK,YAAY;CACnB,SAAS;CACT,SAASA;CACT,OAAO;AACT,CAAC,GACD,IAAI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K,CAAC,CAAC,KAAK,OAAO,GAAG,OAAO,KAAQ,CAAC,CAAC;AAC3D,CAAC,CACH"}
1
+ {"version":3,"file":"Evaluation.mjs","names":["GenerationSnapshot.GenerationSnapshot","EntryPoint.Declaration","GenerationSnapshot.functionPaths"],"sources":["../src/Evaluation.ts"],"sourcesContent":["import * as NodeWorker from \"@effect/platform-node/NodeWorker\";\nimport { fork } from \"node:child_process\";\nimport * as Console from \"effect/Console\";\nimport * as Context from \"effect/Context\";\nimport * as Pool from \"effect/Pool\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Layer from \"effect/Layer\";\nimport * as LogLevel from \"effect/LogLevel\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Schema from \"effect/Schema\";\nimport * as References from \"effect/References\";\nimport * as Rpc from \"effect/rpc/Rpc\";\nimport * as RpcClient from \"effect/rpc/RpcClient\";\nimport type { RpcClientError } from \"effect/rpc/RpcClientError\";\nimport * as RpcGroup from \"effect/rpc/RpcGroup\";\nimport type * as Array from \"effect/Array\";\nimport * as Match from \"effect/Match\";\nimport { ComponentNodeGroupError, logCodegenError } from \"./CodegenError.js\";\nimport * as EntryPoint from \"./EntryPoint.js\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport { FunctionPaths } from \"./FunctionPaths.js\";\nimport { ImplModulePath } from \"./ImplModulePath.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\n\nexport const RequestContext = Schema.Struct({\n projectRoot: Schema.String,\n confectDirectory: Schema.String,\n convexDirectory: Schema.String,\n target: Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"app\") }),\n Schema.Struct({\n kind: Schema.Literal(\"component\"),\n definition: Schema.String,\n }),\n ]),\n minimumLogLevel: Schema.Literals(LogLevel.values),\n});\nexport type RequestContext = typeof RequestContext.Type;\n\nexport class EvaluationError extends Schema.TaggedError<EvaluationError>()(\n \"EvaluationError\",\n { diagnostic: Schema.String },\n) {}\n\n// A rejected Node group stays typed so the caller can restore component output.\nconst Failure = Schema.Union([EvaluationError, ComponentNodeGroupError]);\n\nexport const requests = RpcGroup.make(\n Rpc.make(\"Ready\", { success: Schema.Void }),\n Rpc.make(\"Previous\", {\n payload: RequestContext,\n success: FunctionPaths,\n error: Failure,\n }),\n Rpc.make(\"Generate\", {\n payload: RequestContext,\n success: GenerationSnapshot.GenerationSnapshot,\n error: Failure,\n }),\n Rpc.make(\"Validate\", {\n payload: Schema.Struct({\n ...RequestContext.fields,\n paths: Schema.Array(ImplModulePath),\n }),\n success: Schema.Void,\n error: Failure,\n }),\n Rpc.make(\"Update\", {\n payload: Schema.Struct({\n ...RequestContext.fields,\n snapshot: GenerationSnapshot.GenerationSnapshot,\n declarations: Schema.NonEmptyArray(EntryPoint.Declaration),\n paths: Schema.Array(ImplModulePath),\n }),\n success: GenerationSnapshot.GenerationSnapshot,\n error: Failure,\n }),\n);\n\nconst acquireWorker = Effect.gen(function* () {\n const child = yield* Effect.acquireRelease(\n Effect.sync(() =>\n fork(new URL(\"../dist/EvaluationWorker.mjs\", import.meta.url), {\n serialization: \"advanced\",\n }),\n ),\n (evaluator) =>\n Effect.callback<void>((resume) => {\n if (evaluator.exitCode !== null || evaluator.signalCode !== null) {\n resume(Effect.void);\n return;\n }\n evaluator.once(\"exit\", () => resume(Effect.void));\n evaluator.kill(\"SIGKILL\");\n }),\n );\n const protocol = yield* Layer.build(\n RpcClient.layerProtocolWorker({ size: 1 }).pipe(\n Layer.provide(NodeWorker.layer(() => child)),\n ),\n );\n const client = yield* RpcClient.make(requests).pipe(\n Effect.provideContext(protocol),\n );\n yield* client.Ready();\n yield* Effect.logDebug(\"Evaluator ready\").pipe(\n Effect.annotateLogs({ pid: child.pid }),\n );\n return { child, client };\n});\n\nclass Standby extends Context.Service<\n Standby,\n Pool.Pool<\n Effect.Success<typeof acquireWorker>,\n Effect.Error<typeof acquireWorker>\n >\n>()(\"@confect/cli/Evaluation/Standby\") {}\n\n// Each evaluator handles one evaluation to isolate globals and module caches.\n// Discarding it bounds memory and recovers from crashes. Dev prepares the next\n// evaluator between saves.\nexport const prewarmedLayer = Layer.effect(\n Standby,\n Pool.make({ acquire: acquireWorker, size: 1 }),\n);\n\nconst withWorker = Effect.fn(\"Evaluation.withWorker\")(function* <A>(\n run: (\n client: RpcClient.RpcClient<RpcGroup.Rpcs<typeof requests>, RpcClientError>,\n requestContext: RequestContext,\n ) => Effect.Effect<\n A,\n EvaluationError | ComponentNodeGroupError | RpcClientError\n >,\n) {\n const requestContext = {\n projectRoot: yield* ProjectRoot.get,\n confectDirectory: yield* ConfectDirectory.get,\n convexDirectory: yield* ConvexDirectory.get,\n target: Match.value(yield* ConvexDirectory.target).pipe(\n Match.when({ kind: \"app\" }, () => ({ kind: \"app\" as const })),\n Match.when({ kind: \"component\" }, ({ scope }) => ({\n kind: \"component\" as const,\n definition: scope.slice(\"component:\".length),\n })),\n Match.exhaustive,\n ),\n minimumLogLevel: yield* References.MinimumLogLevel,\n };\n return yield* Effect.scoped(\n Effect.gen(function* () {\n const standby = yield* Effect.serviceOption(Standby);\n const worker = yield* Option.match(standby, {\n onNone: () => acquireWorker,\n onSome: (pool) =>\n Effect.gen(function* () {\n while (true) {\n const candidate = yield* Pool.get(pool);\n yield* Effect.addFinalizer(() =>\n Pool.invalidate(pool, candidate),\n );\n // An idle exit has no pending RPC to fail.\n if (\n candidate.child.connected &&\n candidate.child.exitCode === null &&\n candidate.child.signalCode === null\n )\n return candidate;\n yield* Pool.invalidate(pool, candidate);\n }\n }),\n });\n return yield* run(worker.client, requestContext);\n }),\n ).pipe(\n Effect.catchTags({\n WorkerError: (error) =>\n Effect.fail(new EvaluationError({ diagnostic: error.message })),\n RpcClientError: (error) =>\n Effect.fail(new EvaluationError({ diagnostic: error.message })),\n }),\n );\n});\n\nexport const loadPreviousFunctionPaths = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n if (\n !(yield* fs.exists(path.join(confectDirectory, \"_generated\", \"spec.ts\")))\n ) {\n return FunctionPaths.make(HashSet.empty());\n }\n return yield* withWorker((client, requestContext) =>\n client.Previous(requestContext),\n );\n});\n\nexport const generateSnapshot = withWorker((client, requestContext) =>\n client.Generate(requestContext),\n);\n\nexport const generate = generateSnapshot.pipe(\n Effect.map(GenerationSnapshot.functionPaths),\n);\n\nexport const updateDeclarations = (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n declarations: Array.NonEmptyReadonlyArray<EntryPoint.Declaration>,\n paths: ReadonlyArray<ImplModulePath>,\n) =>\n withWorker((client, requestContext) =>\n client.Update({\n ...requestContext,\n snapshot,\n declarations,\n paths,\n }),\n );\n\nexport const validate = (paths: ReadonlyArray<ImplModulePath>) =>\n withWorker((client, requestContext) =>\n client.Validate({ ...requestContext, paths }),\n );\n\nexport const catchAndLog = <A, R>(\n effect: Effect.Effect<A, EvaluationError | ComponentNodeGroupError, R>,\n): Effect.Effect<Option.Option<A>, never, R> =>\n effect.pipe(\n Effect.asSome,\n Effect.catchTags({\n EvaluationError: ({ diagnostic }) =>\n Console.error(diagnostic).pipe(Effect.as(Option.none<A>())),\n ComponentNodeGroupError: (error) =>\n logCodegenError(error).pipe(Effect.as(Option.none<A>())),\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,iBAAiB,OAAO,OAAO;CAC1C,aAAa,OAAO;CACpB,kBAAkB,OAAO;CACzB,iBAAiB,OAAO;CACxB,QAAQ,OAAO,MAAM,CACnB,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,KAAK,EAAE,CAAC,GAC7C,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,WAAW;EAChC,YAAY,OAAO;CACrB,CAAC,CACH,CAAC;CACD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AC,KAAK,OAAO,GAAG,OAAO,KAAQ,CAAC,CAAC;AAC3D,CAAC,CACH"}
@@ -15,6 +15,7 @@ import * as Schema from "effect/Schema";
15
15
  import * as esbuild from "esbuild";
16
16
  import * as Layer from "effect/Layer";
17
17
  import * as IdScope from "@confect/core/IdScope";
18
+ import * as Schedule from "effect/Schedule";
18
19
  import * as References from "effect/References";
19
20
  import * as NodeWorkerRunner from "@effect/platform-node/NodeWorkerRunner";
20
21
  import * as RpcServer from "effect/rpc/RpcServer";
@@ -34,12 +35,23 @@ const evaluate = (requestContext, effect) => effect.pipe(Effect.provideService(R
34
35
  return Effect.fail(new EvaluationError({ diagnostic: Option.isSome(failure) && isCodegenError(failure.value) ? renderCodegenError(failure.value) : Cause.pretty(cause) }));
35
36
  }));
36
37
  const handlers = requests.toLayer({
38
+ Ready: () => Effect.void,
37
39
  Previous: (requestContext) => evaluate(requestContext, loadPreviousFunctionPaths),
38
40
  Generate: (requestContext) => evaluate(requestContext, generateWithSnapshot.pipe(Effect.map(({ snapshot }) => snapshot))),
39
41
  Validate: (request) => evaluate(request, validateImplFiles(request.paths)),
40
42
  Update: (request) => evaluate(request, updateDeclarations(request.snapshot, request.declarations, request.paths))
41
43
  });
42
- RpcServer.layer(requests).pipe(Layer.provide(handlers), Layer.provide(NodeServices.layer), Layer.provide(RpcServer.layerProtocolWorkerRunner.pipe(Layer.provide(NodeWorkerRunner.layer))), Layer.launch, Effect.ensuring(Effect.promise(() => esbuild.stop())), NodeRuntime.runMain);
44
+ const parentPid = process.ppid;
45
+ process.once("disconnect", () => process.exit(0));
46
+ const watchParent = Effect.sync(() => {
47
+ if (!process.connected || process.ppid !== parentPid) process.exit(0);
48
+ try {
49
+ process.kill(parentPid, 0);
50
+ } catch {
51
+ process.exit(0);
52
+ }
53
+ }).pipe(Effect.repeat({ schedule: Schedule.spaced("1 second") }));
54
+ RpcServer.layer(requests).pipe(Layer.provide(handlers), Layer.provide(NodeServices.layer), Layer.provide(RpcServer.layerProtocolWorkerRunner.pipe(Layer.provide(NodeWorkerRunner.layer))), Layer.launch, Effect.raceFirst(watchParent), Effect.ensuring(Effect.promise(() => esbuild.stop())), NodeRuntime.runMain);
43
55
  //#endregion
44
56
  export {};
45
57
 
@@ -1 +1 @@
1
- {"version":3,"file":"EvaluationWorker.mjs","names":["CodegenError.ComponentNodeGroupError","CodegenError.isCodegenError","CodegenError.renderCodegenError"],"sources":["../src/EvaluationWorker.ts"],"sourcesContent":["import * as NodeRuntime from \"@effect/platform-node/NodeRuntime\";\nimport * as NodeServices from \"@effect/platform-node/NodeServices\";\nimport * as NodeWorkerRunner from \"@effect/platform-node/NodeWorkerRunner\";\nimport * as IdScope from \"@confect/core/IdScope\";\nimport * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as References from \"effect/References\";\nimport * as Schema from \"effect/Schema\";\nimport * as RpcServer from \"effect/rpc/RpcServer\";\nimport * as esbuild from \"esbuild\";\nimport * as CodegenError from \"./CodegenError\";\nimport { ConfectDirectory } from \"./ConfectDirectory\";\nimport { ConvexDirectory } from \"./ConvexDirectory\";\nimport type { RequestContext } from \"./Evaluation\";\nimport { EvaluationError, requests } from \"./Evaluation\";\nimport { validateImplFiles } from \"./LeafModule\";\nimport { ProjectRoot } from \"./ProjectRoot\";\nimport {\n generateWithSnapshot,\n loadPreviousFunctionPaths,\n updateDeclarations,\n} from \"./confect/codegen\";\n\nconst evaluate = <A, E, R>(\n requestContext: RequestContext,\n effect: Effect.Effect<A, E, R>,\n) =>\n effect.pipe(\n Effect.provideService(\n References.MinimumLogLevel,\n requestContext.minimumLogLevel,\n ),\n Effect.provideService(ProjectRoot, {\n get: Effect.succeed(requestContext.projectRoot),\n }),\n Effect.provideService(ConfectDirectory, {\n get: Effect.succeed(requestContext.confectDirectory),\n }),\n Effect.provideService(ConvexDirectory, {\n get: Effect.succeed(requestContext.convexDirectory),\n target: Match.value(requestContext.target).pipe(\n Match.when({ kind: \"app\" }, () => ({\n kind: \"app\" as const,\n scope: IdScope.app,\n })),\n Match.when({ kind: \"component\" }, ({ definition }) => ({\n kind: \"component\" as const,\n scope: IdScope.component(definition),\n })),\n Match.exhaustive,\n ),\n }),\n Effect.catchCause(\n (\n cause,\n ): Effect.Effect<\n never,\n EvaluationError | CodegenError.ComponentNodeGroupError\n > => {\n const failure = Cause.findErrorOption(cause);\n if (\n Option.isSome(failure) &&\n Schema.is(CodegenError.ComponentNodeGroupError)(failure.value)\n )\n return Effect.fail(failure.value);\n return Effect.fail(\n new EvaluationError({\n diagnostic:\n Option.isSome(failure) &&\n CodegenError.isCodegenError(failure.value)\n ? CodegenError.renderCodegenError(failure.value)\n : Cause.pretty(cause),\n }),\n );\n },\n ),\n );\n\nconst handlers = requests.toLayer({\n Previous: (requestContext) =>\n evaluate(requestContext, loadPreviousFunctionPaths),\n Generate: (requestContext) =>\n evaluate(\n requestContext,\n generateWithSnapshot.pipe(Effect.map(({ snapshot }) => snapshot)),\n ),\n Validate: (request) => evaluate(request, validateImplFiles(request.paths)),\n Update: (request) =>\n evaluate(\n request,\n updateDeclarations(request.snapshot, request.declarations, request.paths),\n ),\n});\n\nRpcServer.layer(requests).pipe(\n Layer.provide(handlers),\n Layer.provide(NodeServices.layer),\n Layer.provide(\n RpcServer.layerProtocolWorkerRunner.pipe(\n Layer.provide(NodeWorkerRunner.layer),\n ),\n ),\n Layer.launch,\n Effect.ensuring(Effect.promise(() => esbuild.stop())),\n NodeRuntime.runMain,\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,YACJ,gBACA,WAEA,OAAO,KACL,OAAO,eACL,WAAW,iBACX,eAAe,eACjB,GACA,OAAO,eAAe,aAAa,EACjC,KAAK,OAAO,QAAQ,eAAe,WAAW,EAChD,CAAC,GACD,OAAO,eAAe,kBAAkB,EACtC,KAAK,OAAO,QAAQ,eAAe,gBAAgB,EACrD,C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,CAAC,CAAC,GACpD,YAAY,OACd"}
1
+ {"version":3,"file":"EvaluationWorker.mjs","names":["CodegenError.ComponentNodeGroupError","CodegenError.isCodegenError","CodegenError.renderCodegenError"],"sources":["../src/EvaluationWorker.ts"],"sourcesContent":["import * as NodeRuntime from \"@effect/platform-node/NodeRuntime\";\nimport * as NodeServices from \"@effect/platform-node/NodeServices\";\nimport * as NodeWorkerRunner from \"@effect/platform-node/NodeWorkerRunner\";\nimport * as IdScope from \"@confect/core/IdScope\";\nimport * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as References from \"effect/References\";\nimport * as Schema from \"effect/Schema\";\nimport * as Schedule from \"effect/Schedule\";\nimport * as RpcServer from \"effect/rpc/RpcServer\";\nimport * as esbuild from \"esbuild\";\nimport * as CodegenError from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport type { RequestContext } from \"./Evaluation.js\";\nimport { EvaluationError, requests } from \"./Evaluation.js\";\nimport { validateImplFiles } from \"./LeafModule.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\nimport {\n generateWithSnapshot,\n loadPreviousFunctionPaths,\n updateDeclarations,\n} from \"./confect/codegen.js\";\n\nconst evaluate = <A, E, R>(\n requestContext: RequestContext,\n effect: Effect.Effect<A, E, R>,\n) =>\n effect.pipe(\n Effect.provideService(\n References.MinimumLogLevel,\n requestContext.minimumLogLevel,\n ),\n Effect.provideService(ProjectRoot, {\n get: Effect.succeed(requestContext.projectRoot),\n }),\n Effect.provideService(ConfectDirectory, {\n get: Effect.succeed(requestContext.confectDirectory),\n }),\n Effect.provideService(ConvexDirectory, {\n get: Effect.succeed(requestContext.convexDirectory),\n target: Match.value(requestContext.target).pipe(\n Match.when({ kind: \"app\" }, () => ({\n kind: \"app\" as const,\n scope: IdScope.app,\n })),\n Match.when({ kind: \"component\" }, ({ definition }) => ({\n kind: \"component\" as const,\n scope: IdScope.component(definition),\n })),\n Match.exhaustive,\n ),\n }),\n Effect.catchCause(\n (\n cause,\n ): Effect.Effect<\n never,\n EvaluationError | CodegenError.ComponentNodeGroupError\n > => {\n const failure = Cause.findErrorOption(cause);\n if (\n Option.isSome(failure) &&\n Schema.is(CodegenError.ComponentNodeGroupError)(failure.value)\n )\n return Effect.fail(failure.value);\n return Effect.fail(\n new EvaluationError({\n diagnostic:\n Option.isSome(failure) &&\n CodegenError.isCodegenError(failure.value)\n ? CodegenError.renderCodegenError(failure.value)\n : Cause.pretty(cause),\n }),\n );\n },\n ),\n );\n\nconst handlers = requests.toLayer({\n Ready: () => Effect.void,\n Previous: (requestContext) =>\n evaluate(requestContext, loadPreviousFunctionPaths),\n Generate: (requestContext) =>\n evaluate(\n requestContext,\n generateWithSnapshot.pipe(Effect.map(({ snapshot }) => snapshot)),\n ),\n Validate: (request) => evaluate(request, validateImplFiles(request.paths)),\n Update: (request) =>\n evaluate(\n request,\n updateDeclarations(request.snapshot, request.declarations, request.paths),\n ),\n});\n\n// Evaluators must not outlive the CLI, even when it is killed without cleanup.\nconst parentPid = process.ppid;\nprocess.once(\"disconnect\", () => process.exit(0));\nconst watchParent = Effect.sync(() => {\n if (!process.connected || process.ppid !== parentPid) process.exit(0);\n try {\n process.kill(parentPid, 0);\n } catch {\n process.exit(0);\n }\n}).pipe(Effect.repeat({ schedule: Schedule.spaced(\"1 second\") }));\n\nRpcServer.layer(requests).pipe(\n Layer.provide(handlers),\n Layer.provide(NodeServices.layer),\n Layer.provide(\n RpcServer.layerProtocolWorkerRunner.pipe(\n Layer.provide(NodeWorkerRunner.layer),\n ),\n ),\n Layer.launch,\n Effect.raceFirst(watchParent),\n Effect.ensuring(Effect.promise(() => esbuild.stop())),\n NodeRuntime.runMain,\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,YACJ,gBACA,WAEA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