@gaganref/confect-cli 10.6.0-fork.2 → 10.6.0-fork.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Declaration.mjs +12 -2
- package/dist/Declaration.mjs.map +1 -1
- package/dist/FunctionModule.mjs +17 -4
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/SectionFiles.mjs +3 -1
- package/dist/SectionFiles.mjs.map +1 -1
- package/dist/SyncState.mjs +2 -2
- package/dist/SyncState.mjs.map +1 -1
- package/dist/confect/codegen.mjs +19 -1
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/dev.mjs +1 -1
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/templates.mjs +19 -3
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +10 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -3
package/dist/Declaration.mjs
CHANGED
|
@@ -28,6 +28,11 @@ var InvalidMountName = class extends Schema.TaggedError()("InvalidMountName", {
|
|
|
28
28
|
return `"${this.mount}" is not a valid mount name; use letters, digits and underscores, starting with a letter or underscore.`;
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
+
var ReservedMountName = class extends Schema.TaggedError()("ReservedMountName", { mount: Schema.String }) {
|
|
32
|
+
get message() {
|
|
33
|
+
return `The mount name "${this.mount}" is reserved for the root app or docs page; choose another mount name.`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
31
36
|
var ForeignEnvBinding = class extends Schema.TaggedError()("ForeignEnvBinding", {
|
|
32
37
|
mount: Schema.String,
|
|
33
38
|
slot: Schema.String,
|
|
@@ -123,7 +128,10 @@ const parse = (input) => Result.gen(function* () {
|
|
|
123
128
|
const env = App.env(input.app);
|
|
124
129
|
const name = Env.name(env);
|
|
125
130
|
const descriptors = Env.descriptors(env);
|
|
126
|
-
for (const [key] of descriptors)
|
|
131
|
+
for (const [key] of descriptors) {
|
|
132
|
+
yield* Env.validateKey(key);
|
|
133
|
+
if (!ENV_KEY.test(key)) return yield* Result.fail(InvalidEnvKey.make({ key }));
|
|
134
|
+
}
|
|
127
135
|
const definitions = /* @__PURE__ */ new Map();
|
|
128
136
|
for (const [index, definition] of App.components(input.app).entries()) {
|
|
129
137
|
const component = input.componentImport(definition);
|
|
@@ -139,6 +147,7 @@ const parse = (input) => Result.gen(function* () {
|
|
|
139
147
|
}
|
|
140
148
|
const mounts = [];
|
|
141
149
|
for (const mount of App.mounts(input.app)) {
|
|
150
|
+
if (mount.name === "app" || mount.name === "docs") return yield* Result.fail(ReservedMountName.make({ mount: mount.name }));
|
|
142
151
|
if (!MOUNT_NAME.test(mount.name)) return yield* Result.fail(InvalidMountName.make({ mount: mount.name }));
|
|
143
152
|
const component = definitions.get(mount.component.name);
|
|
144
153
|
if (component === void 0) return yield* Result.fail(MountWithoutDefinition.make({
|
|
@@ -153,6 +162,7 @@ const parse = (input) => Result.gen(function* () {
|
|
|
153
162
|
}));
|
|
154
163
|
const bindings = [];
|
|
155
164
|
for (const [slot, bound] of Rec.toEntries(mount.env ?? {})) {
|
|
165
|
+
yield* Env.validateKey(slot);
|
|
156
166
|
if (bound === void 0) continue;
|
|
157
167
|
if (typeof bound === "string") {
|
|
158
168
|
bindings.push([slot, {
|
|
@@ -402,6 +412,6 @@ const digest = (input) => {
|
|
|
402
412
|
}));
|
|
403
413
|
return `sha256:${hash.digest("hex")}`;
|
|
404
414
|
};
|
|
405
|
-
export { AuthForAnotherBackend, DefinitionWithoutMount, DuplicateDefinitionName, DuplicateMountName, ForeignEnvBinding, InvalidBinding, InvalidComponentDefinition, InvalidEnvKey, InvalidMountName, InvalidProviderEnv, MountWithoutDefinition, NotADeclaration, authConfig, authProviders, convexConfig, digest, fileOf, header, isGenerated, manifest, parse, renderManifest };
|
|
415
|
+
export { AuthForAnotherBackend, DefinitionWithoutMount, DuplicateDefinitionName, DuplicateMountName, ForeignEnvBinding, InvalidBinding, InvalidComponentDefinition, InvalidEnvKey, InvalidMountName, InvalidProviderEnv, MountWithoutDefinition, NotADeclaration, ReservedMountName, authConfig, authProviders, convexConfig, digest, fileOf, header, isGenerated, manifest, parse, renderManifest };
|
|
406
416
|
|
|
407
417
|
//# sourceMappingURL=Declaration.mjs.map
|
package/dist/Declaration.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Declaration.mjs","names":[],"sources":["../src/Declaration.ts"],"sourcesContent":["import { App, Auth, Env } from \"@confect/core\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\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\";\nimport * as String from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Arr from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\nimport { quote, stringify } from \"./Json.js\";\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 Schema.TaggedError<\n NotADeclaration,\n { readonly brand: unique symbol }\n>()(\"NotADeclaration\", { file: Schema.String, expected: Schema.String }) {\n override get message(): string {\n return `${this.file} must default-export ${this.expected}.`;\n }\n}\n\nexport class InvalidEnvKey extends Schema.TaggedError<\n InvalidEnvKey,\n { readonly brand: unique symbol }\n>()(\"InvalidEnvKey\", { key: Schema.String }) {\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 Schema.TaggedError<\n InvalidMountName,\n { readonly brand: unique symbol }\n>()(\"InvalidMountName\", { mount: Schema.String }) {\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 Schema.TaggedError<\n ForeignEnvBinding,\n { readonly brand: unique symbol }\n>()(\"ForeignEnvBinding\", {\n mount: Schema.String,\n slot: Schema.String,\n backend: Schema.String,\n key: Schema.String,\n expectedBackend: Schema.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 Schema.TaggedError<\n InvalidBinding,\n { readonly brand: unique symbol }\n>()(\"InvalidBinding\", { mount: Schema.String, slot: Schema.String }) {\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 InvalidComponentDefinition extends Schema.TaggedError<\n InvalidComponentDefinition,\n { readonly brand: unique symbol }\n>()(\"InvalidComponentDefinition\", { index: Schema.Finite }) {\n override get message(): string {\n return `App.make's components[${this.index}] must be the default export of a component's convex.config module, imported directly in the declaration.`;\n }\n}\n\nexport class MountWithoutDefinition extends Schema.TaggedError<\n MountWithoutDefinition,\n { readonly brand: unique symbol }\n>()(\"MountWithoutDefinition\", {\n mount: Schema.String,\n component: Schema.String,\n}) {\n override get message(): string {\n return `The mount \"${this.mount}\" mounts the component \"${this.component}\", but App.make's components lists no definition named \"${this.component}\".`;\n }\n}\n\nexport class DefinitionWithoutMount extends Schema.TaggedError<\n DefinitionWithoutMount,\n { readonly brand: unique symbol }\n>()(\"DefinitionWithoutMount\", {\n component: Schema.String,\n importPath: Schema.String,\n}) {\n override get message(): string {\n return `App.make's components lists the definition \"${this.component}\" from ${this.importPath}, but no mount mounts it.`;\n }\n}\n\nexport class DuplicateMountName extends Schema.TaggedError<\n DuplicateMountName,\n { readonly brand: unique symbol }\n>()(\"DuplicateMountName\", {\n mount: Schema.String,\n first: Schema.String,\n second: Schema.String,\n}) {\n override get message(): string {\n return `Two mounts are named \"${this.mount}\", one of \"${this.first}\" and one of \"${this.second}\"; give each mount its own name.`;\n }\n}\n\nexport class DuplicateDefinitionName extends Schema.TaggedError<\n DuplicateDefinitionName,\n { readonly brand: unique symbol }\n>()(\"DuplicateDefinitionName\", {\n component: Schema.String,\n first: Schema.String,\n second: Schema.String,\n}) {\n override get message(): string {\n return `Two component definitions are named \"${this.component}\", from ${this.first} and ${this.second}; give each definition its own name.`;\n }\n}\n\nexport class AuthForAnotherBackend extends Schema.TaggedError<\n AuthForAnotherBackend,\n { readonly brand: unique symbol }\n>()(\"AuthForAnotherBackend\", {\n backend: Schema.String,\n expectedBackend: Schema.String,\n}) {\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 Schema.TaggedError<\n InvalidProviderEnv,\n { readonly brand: unique symbol }\n>()(\"InvalidProviderEnv\", {\n field: Schema.String,\n key: Schema.String,\n backend: Schema.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 | InvalidComponentDefinition\n | MountWithoutDefinition\n | DefinitionWithoutMount\n | DuplicateMountName\n | DuplicateDefinitionName\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 listed definition; codegen's bundler records it. Each mount takes\n * the definition whose `defineComponent` name is its component's name.\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 NotADeclaration.make({\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(InvalidEnvKey.make({ key }));\n }\n\n const definitions = new Map<string, ComponentImport>();\n for (const [index, definition] of App.components(input.app).entries()) {\n const component = input.componentImport(definition);\n if (Option.isNone(component)) {\n return yield* Result.fail(InvalidComponentDefinition.make({ index }));\n }\n const { componentName, importPath } = component.value;\n const named = definitions.get(componentName);\n if (named !== undefined && named.importPath !== importPath) {\n return yield* Result.fail(\n DuplicateDefinitionName.make({\n component: componentName,\n first: named.importPath,\n second: importPath,\n }),\n );\n }\n definitions.set(componentName, component.value);\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(InvalidMountName.make({ mount: mount.name }));\n }\n const component = definitions.get(mount.component.name);\n if (component === undefined) {\n return yield* Result.fail(\n MountWithoutDefinition.make({\n mount: mount.name,\n component: mount.component.name,\n }),\n );\n }\n const named = Option.getOrUndefined(\n Arr.findFirst(mounts, (declared) => declared.name === mount.name),\n );\n if (named !== undefined) {\n return yield* Result.fail(\n DuplicateMountName.make({\n mount: mount.name,\n first: named.componentName,\n second: component.componentName,\n }),\n );\n }\n const bindings: Array<readonly [string, Binding]> = [];\n for (const [slot, bound] of Rec.toEntries(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 InvalidBinding.make({ mount: mount.name, slot }),\n );\n }\n const origin = Env.origin(bound);\n if (origin.backend !== name) {\n return yield* Result.fail(\n ForeignEnvBinding.make({\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.importPath,\n componentName: component.componentName,\n httpPrefix: mount.httpPrefix,\n env: bindings,\n });\n }\n for (const [component, { importPath }] of definitions) {\n if (\n !Arr.some(mounts, ({ componentName }) => componentName === component)\n ) {\n return yield* Result.fail(\n DefinitionWithoutMount.make({ component, importPath }),\n );\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 NotADeclaration.make({\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 AuthForAnotherBackend.make({\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 Rec.toEntries<\n string,\n Auth.Provider[keyof Auth.Provider]\n >(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 InvalidProviderEnv.make({ 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 : stringify(value),\n };\n }\n fields.push([field, lowered]);\n }\n providers.push(fields);\n }\n return providers;\n });\n};\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 pipe(contents, String.startsWith(GENERATED_PREFIX)) ||\n 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(${pipe(\n descriptor.values,\n Arr.map((value) => `v.literal(${quote(value)})`),\n Arr.join(\", \"),\n )})`\n : \"v.string()\";\n return descriptor.optional ? `v.optional(${base})` : base;\n};\n\nconst RESERVED = new Set(\n pipe(\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\",\n String.split(\" \"),\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 = pipe(name, String.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 ...Arr.map(\n declaration.env,\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 : Arr.join([\"const app = defineApp({\", ...envBlock, \"});\"], \"\\n\"),\n );\n } else {\n lines.push(\n envBlock.length === 0\n ? `const component = defineComponent(${quote(declaration.name)});`\n : Arr.join(\n [\n `const component = defineComponent(${quote(declaration.name)}, {`,\n ...envBlock,\n \"});\",\n ],\n \"\\n\",\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 Arr.join(lines, \"\\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\"}}${pipe(value.path, String.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 Arr.join(\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 ...Arr.flatMap(providers, (provider) => [\n \" {\",\n ...pipe(\n provider,\n Arr.filter(([field]) => field !== \"family\" && field !== \"name\"),\n Arr.map(\n ([field, value]) =>\n ` ${field}: ${providerValue(value)},`,\n ),\n ),\n \" },\",\n ]),\n \" ],\",\n ]),\n \"} satisfies AuthConfig;\",\n \"\",\n ],\n \"\\n\",\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 Arr.join(\n [\n header(\"confect/auth.ts\"),\n \"\",\n \"export const providers = [\",\n ...Arr.flatMap(providers, (provider) => [\n \" {\",\n ...Arr.flatMap(provider, ([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 ],\n \"\\n\",\n );\n\n/**\n * `confect/_generated/manifest.ts`: plain data, no imports, for infra.\n */\nexport const manifest = (\n declaration: Declaration,\n digest: string,\n sections: Readonly<Record<string, unknown>> = {},\n): string => {\n const data = {\n name: declaration.name,\n env: Rec.fromEntries(declaration.env),\n http: {\n mounts: Rec.fromEntries(\n Arr.flatMap(declaration.mounts, ({ name, httpPrefix }) =>\n httpPrefix === undefined ? [] : [[name, httpPrefix]],\n ),\n ),\n },\n digest,\n ...sections,\n };\n return renderManifest(data);\n};\n\nexport const renderManifest = (\n data: Readonly<Record<string, unknown>>,\n): string =>\n `${header(\"confect/env.ts and confect/app.ts\")}\\n\\nexport default ${stringify(data, 2)} as const;\\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 readonly sections?: Readonly<Record<string, unknown>>;\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 stringify({\n files: [...input.files].sort(byFirst),\n versions: [...input.versions].sort(byFirst),\n ...(input.sections === undefined ? {} : { sections: input.sections }),\n }),\n );\n return `sha256:${hash.digest(\"hex\")}`;\n};\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB;CAAE,MAAM,OAAO;CAAQ,UAAU,OAAO;AAAO,CAAC,CAAC,CAAC;CACvE,IAAa,UAAkB;EAC7B,OAAO,GAAG,KAAK,KAAK,uBAAuB,KAAK,SAAS;CAC3D;AACF;AAEA,IAAa,gBAAb,cAAmC,OAAO,YAGxC,CAAC,CAAC,iBAAiB,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC;CAC3C,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,IAAI;CACtB;AACF;AAEA,IAAa,mBAAb,cAAsC,OAAO,YAG3C,CAAC,CAAC,oBAAoB,EAAE,OAAO,OAAO,OAAO,CAAC,CAAC,CAAC;CAChD,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,MAAM;CACxB;AACF;AAEA,IAAa,oBAAb,cAAuC,OAAO,YAG5C,CAAC,CAAC,qBAAqB;CACvB,OAAO,OAAO;CACd,MAAM,OAAO;CACb,SAAS,OAAO;CAChB,KAAK,OAAO;CACZ,iBAAiB,OAAO;AAC1B,CAAC,CAAC,CAAC;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,OAAO,YAGzC,CAAC,CAAC,kBAAkB;CAAE,OAAO,OAAO;CAAQ,MAAM,OAAO;AAAO,CAAC,CAAC,CAAC;CACnE,IAAa,UAAkB;EAC7B,OAAO,cAAc,KAAK,MAAM,UAAU,KAAK,KAA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K,CAAC,CAAC,KAAK,OAAO;EACpC,UAAU,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,KAAK,OAAO;EAC1C,GAAI,MAAM,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,MAAM,SAAS;CACrE,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 Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\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\";\nimport * as String from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Arr from \"effect/Array\";\nimport * as Rec from \"effect/Record\";\nimport { quote, stringify } from \"./Json.js\";\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 Schema.TaggedError<\n NotADeclaration,\n { readonly brand: unique symbol }\n>()(\"NotADeclaration\", { file: Schema.String, expected: Schema.String }) {\n override get message(): string {\n return `${this.file} must default-export ${this.expected}.`;\n }\n}\n\nexport class InvalidEnvKey extends Schema.TaggedError<\n InvalidEnvKey,\n { readonly brand: unique symbol }\n>()(\"InvalidEnvKey\", { key: Schema.String }) {\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 Schema.TaggedError<\n InvalidMountName,\n { readonly brand: unique symbol }\n>()(\"InvalidMountName\", { mount: Schema.String }) {\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 ReservedMountName extends Schema.TaggedError<\n ReservedMountName,\n { readonly brand: unique symbol }\n>()(\"ReservedMountName\", { mount: Schema.String }) {\n override get message(): string {\n return `The mount name \"${this.mount}\" is reserved for the root app or docs page; choose another mount name.`;\n }\n}\n\nexport class ForeignEnvBinding extends Schema.TaggedError<\n ForeignEnvBinding,\n { readonly brand: unique symbol }\n>()(\"ForeignEnvBinding\", {\n mount: Schema.String,\n slot: Schema.String,\n backend: Schema.String,\n key: Schema.String,\n expectedBackend: Schema.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 Schema.TaggedError<\n InvalidBinding,\n { readonly brand: unique symbol }\n>()(\"InvalidBinding\", { mount: Schema.String, slot: Schema.String }) {\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 InvalidComponentDefinition extends Schema.TaggedError<\n InvalidComponentDefinition,\n { readonly brand: unique symbol }\n>()(\"InvalidComponentDefinition\", { index: Schema.Finite }) {\n override get message(): string {\n return `App.make's components[${this.index}] must be the default export of a component's convex.config module, imported directly in the declaration.`;\n }\n}\n\nexport class MountWithoutDefinition extends Schema.TaggedError<\n MountWithoutDefinition,\n { readonly brand: unique symbol }\n>()(\"MountWithoutDefinition\", {\n mount: Schema.String,\n component: Schema.String,\n}) {\n override get message(): string {\n return `The mount \"${this.mount}\" mounts the component \"${this.component}\", but App.make's components lists no definition named \"${this.component}\".`;\n }\n}\n\nexport class DefinitionWithoutMount extends Schema.TaggedError<\n DefinitionWithoutMount,\n { readonly brand: unique symbol }\n>()(\"DefinitionWithoutMount\", {\n component: Schema.String,\n importPath: Schema.String,\n}) {\n override get message(): string {\n return `App.make's components lists the definition \"${this.component}\" from ${this.importPath}, but no mount mounts it.`;\n }\n}\n\nexport class DuplicateMountName extends Schema.TaggedError<\n DuplicateMountName,\n { readonly brand: unique symbol }\n>()(\"DuplicateMountName\", {\n mount: Schema.String,\n first: Schema.String,\n second: Schema.String,\n}) {\n override get message(): string {\n return `Two mounts are named \"${this.mount}\", one of \"${this.first}\" and one of \"${this.second}\"; give each mount its own name.`;\n }\n}\n\nexport class DuplicateDefinitionName extends Schema.TaggedError<\n DuplicateDefinitionName,\n { readonly brand: unique symbol }\n>()(\"DuplicateDefinitionName\", {\n component: Schema.String,\n first: Schema.String,\n second: Schema.String,\n}) {\n override get message(): string {\n return `Two component definitions are named \"${this.component}\", from ${this.first} and ${this.second}; give each definition its own name.`;\n }\n}\n\nexport class AuthForAnotherBackend extends Schema.TaggedError<\n AuthForAnotherBackend,\n { readonly brand: unique symbol }\n>()(\"AuthForAnotherBackend\", {\n backend: Schema.String,\n expectedBackend: Schema.String,\n}) {\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 Schema.TaggedError<\n InvalidProviderEnv,\n { readonly brand: unique symbol }\n>()(\"InvalidProviderEnv\", {\n field: Schema.String,\n key: Schema.String,\n backend: Schema.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 | ReservedMountName\n | ForeignEnvBinding\n | InvalidBinding\n | InvalidComponentDefinition\n | MountWithoutDefinition\n | DefinitionWithoutMount\n | DuplicateMountName\n | DuplicateDefinitionName\n | AuthForAnotherBackend\n | InvalidProviderEnv\n | Env.ReservedEnvKey;\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 listed definition; codegen's bundler records it. Each mount takes\n * the definition whose `defineComponent` name is its component's name.\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 NotADeclaration.make({\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 yield* Env.validateKey(key);\n if (!ENV_KEY.test(key))\n return yield* Result.fail(InvalidEnvKey.make({ key }));\n }\n\n const definitions = new Map<string, ComponentImport>();\n for (const [index, definition] of App.components(input.app).entries()) {\n const component = input.componentImport(definition);\n if (Option.isNone(component)) {\n return yield* Result.fail(InvalidComponentDefinition.make({ index }));\n }\n const { componentName, importPath } = component.value;\n const named = definitions.get(componentName);\n if (named !== undefined && named.importPath !== importPath) {\n return yield* Result.fail(\n DuplicateDefinitionName.make({\n component: componentName,\n first: named.importPath,\n second: importPath,\n }),\n );\n }\n definitions.set(componentName, component.value);\n }\n\n const mounts: Array<Mount> = [];\n for (const mount of App.mounts(input.app)) {\n if (mount.name === \"app\" || mount.name === \"docs\") {\n return yield* Result.fail(\n ReservedMountName.make({ mount: mount.name }),\n );\n }\n if (!MOUNT_NAME.test(mount.name)) {\n return yield* Result.fail(InvalidMountName.make({ mount: mount.name }));\n }\n const component = definitions.get(mount.component.name);\n if (component === undefined) {\n return yield* Result.fail(\n MountWithoutDefinition.make({\n mount: mount.name,\n component: mount.component.name,\n }),\n );\n }\n const named = Option.getOrUndefined(\n Arr.findFirst(mounts, (declared) => declared.name === mount.name),\n );\n if (named !== undefined) {\n return yield* Result.fail(\n DuplicateMountName.make({\n mount: mount.name,\n first: named.componentName,\n second: component.componentName,\n }),\n );\n }\n const bindings: Array<readonly [string, Binding]> = [];\n for (const [slot, bound] of Rec.toEntries(mount.env ?? {})) {\n yield* Env.validateKey(slot);\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 InvalidBinding.make({ mount: mount.name, slot }),\n );\n }\n const origin = Env.origin(bound);\n if (origin.backend !== name) {\n return yield* Result.fail(\n ForeignEnvBinding.make({\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.importPath,\n componentName: component.componentName,\n httpPrefix: mount.httpPrefix,\n env: bindings,\n });\n }\n for (const [component, { importPath }] of definitions) {\n if (\n !Arr.some(mounts, ({ componentName }) => componentName === component)\n ) {\n return yield* Result.fail(\n DefinitionWithoutMount.make({ component, importPath }),\n );\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 NotADeclaration.make({\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 AuthForAnotherBackend.make({\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 Rec.toEntries<\n string,\n Auth.Provider[keyof Auth.Provider]\n >(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 InvalidProviderEnv.make({ 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 : stringify(value),\n };\n }\n fields.push([field, lowered]);\n }\n providers.push(fields);\n }\n return providers;\n });\n};\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 pipe(contents, String.startsWith(GENERATED_PREFIX)) ||\n 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(${pipe(\n descriptor.values,\n Arr.map((value) => `v.literal(${quote(value)})`),\n Arr.join(\", \"),\n )})`\n : \"v.string()\";\n return descriptor.optional ? `v.optional(${base})` : base;\n};\n\nconst RESERVED = new Set(\n pipe(\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\",\n String.split(\" \"),\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 = pipe(name, String.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 ...Arr.map(\n declaration.env,\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 : Arr.join([\"const app = defineApp({\", ...envBlock, \"});\"], \"\\n\"),\n );\n } else {\n lines.push(\n envBlock.length === 0\n ? `const component = defineComponent(${quote(declaration.name)});`\n : Arr.join(\n [\n `const component = defineComponent(${quote(declaration.name)}, {`,\n ...envBlock,\n \"});\",\n ],\n \"\\n\",\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 Arr.join(lines, \"\\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\"}}${pipe(value.path, String.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 Arr.join(\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 ...Arr.flatMap(providers, (provider) => [\n \" {\",\n ...pipe(\n provider,\n Arr.filter(([field]) => field !== \"family\" && field !== \"name\"),\n Arr.map(\n ([field, value]) =>\n ` ${field}: ${providerValue(value)},`,\n ),\n ),\n \" },\",\n ]),\n \" ],\",\n ]),\n \"} satisfies AuthConfig;\",\n \"\",\n ],\n \"\\n\",\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 Arr.join(\n [\n header(\"confect/auth.ts\"),\n \"\",\n \"export const providers = [\",\n ...Arr.flatMap(providers, (provider) => [\n \" {\",\n ...Arr.flatMap(provider, ([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 ],\n \"\\n\",\n );\n\n/**\n * `confect/_generated/manifest.ts`: plain data, no imports, for infra.\n */\nexport const manifest = (\n declaration: Declaration,\n digest: string,\n sections: Readonly<Record<string, unknown>> = {},\n): string => {\n const data = {\n name: declaration.name,\n env: Rec.fromEntries(declaration.env),\n http: {\n mounts: Rec.fromEntries(\n Arr.flatMap(declaration.mounts, ({ name, httpPrefix }) =>\n httpPrefix === undefined ? [] : [[name, httpPrefix]],\n ),\n ),\n },\n digest,\n ...sections,\n };\n return renderManifest(data);\n};\n\nexport const renderManifest = (\n data: Readonly<Record<string, unknown>>,\n): string =>\n `${header(\"confect/env.ts and confect/app.ts\")}\\n\\nexport default ${stringify(data, 2)} as const;\\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 readonly sections?: Readonly<Record<string, unknown>>;\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 stringify({\n files: [...input.files].sort(byFirst),\n versions: [...input.versions].sort(byFirst),\n ...(input.sections === undefined ? {} : { sections: input.sections }),\n }),\n );\n return `sha256:${hash.digest(\"hex\")}`;\n};\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB;CAAE,MAAM,OAAO;CAAQ,UAAU,OAAO;AAAO,CAAC,CAAC,CAAC;CACvE,IAAa,UAAkB;EAC7B,OAAO,GAAG,KAAK,KAAK,uBAAuB,KAAK,SAAS;CAC3D;AACF;AAEA,IAAa,gBAAb,cAAmC,OAAO,YAGxC,CAAC,CAAC,iBAAiB,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC;CAC3C,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,IAAI;CACtB;AACF;AAEA,IAAa,mBAAb,cAAsC,OAAO,YAG3C,CAAC,CAAC,oBAAoB,EAAE,OAAO,OAAO,OAAO,CAAC,CAAC,CAAC;CAChD,IAAa,UAAkB;EAC7B,OAAO,IAAI,KAAK,MAAM;CACxB;AACF;AAEA,IAAa,oBAAb,cAAuC,OAAO,YAG5C,CAAC,CAAC,qBAAqB,EAAE,OAAO,OAAO,OAAO,CAAC,CAAC,CAAC;CACjD,IAAa,UAAkB;EAC7B,OAAO,mBAAmB,KAAK,MAAM;CACvC;AACF;AAEA,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AAK,EAAE,EAAE,IACvC,CAAC;EACP,CAAC;EACD;CACF,CAAC;CACD;CACA;AACF,GACA,IACF;;;;AAKF,MAAa,YACX,aACA,QACA,WAA8C,CAAC,MACpC;CACX,MAAM,OAAO;EACX,MAAM,YAAY;EAClB,KAAK,IAAI,YAAY,YAAY,GAAG;EACpC,MAAM,EACJ,QAAQ,IAAI,YACV,IAAI,QAAQ,YAAY,SAAS,EAAE,MAAM,iBACvC,eAAe,KAAA,IAAY,CAAC,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,CACrD,CACF,EACF;EACA;EACA,GAAG;CACL;CACA,OAAO,eAAe,IAAI;AAC5B;AAEA,MAAa,kBACX,SAEA,GAAG,OAAO,mCAAmC,EAAE,qBAAqB,UAAU,MAAM,CAAC,EAAE;;;;;;AAOzF,MAAa,UAAU,UAIT;CACZ,MAAM,OAAO,WAAW,QAAQ;CAChC,MAAM,WACJ,GACA,MACI,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;CAC3C,KAAK,OACH,UAAU;EACR,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,KAAK,OAAO;EACpC,UAAU,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,KAAK,OAAO;EAC1C,GAAI,MAAM,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,MAAM,SAAS;CACrE,CAAC,CACH;CACA,OAAO,UAAU,KAAK,OAAO,KAAK;AACpC"}
|
package/dist/FunctionModule.mjs
CHANGED
|
@@ -45,7 +45,7 @@ const getEntrypoints = Effect.gen(function* () {
|
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
const tokenize = (source, modulePath, path) => {
|
|
48
|
-
const token = /\s+|\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[$A-Z_a-z][$\w]
|
|
48
|
+
const token = /\s+|\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[$A-Z_a-z][$\w]*|=>|[{}()[\].,:;=<>]/y;
|
|
49
49
|
const tokens = [];
|
|
50
50
|
while (token.lastIndex < source.length) {
|
|
51
51
|
const match = token.exec(source);
|
|
@@ -69,6 +69,7 @@ const matchesShape = (actual, expected) => {
|
|
|
69
69
|
return index === actual.length;
|
|
70
70
|
};
|
|
71
71
|
const legacyRouter = String.replace("HttpRouter.make(schema, http.routes, ", "HttpRouter.forSchema(schema)(http.routes, ");
|
|
72
|
+
const legacyCrons = String.replace("wraps.reduce<CronJobs.CronJobs>(", "wraps.reduce(");
|
|
72
73
|
/**
|
|
73
74
|
* @internal
|
|
74
75
|
*/
|
|
@@ -91,9 +92,21 @@ const assertOwnedEntrypoints = Effect.gen(function* () {
|
|
|
91
92
|
runtimeImportPath: yield* importFromConvex("runtime.ts")
|
|
92
93
|
})
|
|
93
94
|
];
|
|
94
|
-
const optional = /* @__PURE__ */ new Map([["http.ts", Array.flatMap(httpTemplates, (template) => [template, legacyRouter(template)])]
|
|
95
|
+
const optional = /* @__PURE__ */ new Map([["http.ts", Array.flatMap(httpTemplates, (template) => [template, legacyRouter(template)])]]);
|
|
95
96
|
const written2 = yield* written;
|
|
96
|
-
const sectionImports = new
|
|
97
|
+
const sectionImports = new Map(Array.map(written2, (file) => [quote(path.join(confect, "_generated", path.basename(file, ".ts"))), file]));
|
|
98
|
+
const cronsShapes = Effect.fnUntraced(function* (tokens) {
|
|
99
|
+
const wrapped = Array.flatMap(tokens, (token, index) => {
|
|
100
|
+
const file = sectionImports.get(token);
|
|
101
|
+
return tokens[index - 1] === "from" && file !== void 0 ? [file] : [];
|
|
102
|
+
});
|
|
103
|
+
if (new Set(wrapped).size !== wrapped.length) return [];
|
|
104
|
+
const template = yield* crons({
|
|
105
|
+
cronsImportPath: yield* importFromConvex("crons.ts"),
|
|
106
|
+
sectionImportPaths: yield* Effect.forEach(wrapped, (file) => importFromConvex(`_generated/${file}`))
|
|
107
|
+
});
|
|
108
|
+
return [template, legacyCrons(template)];
|
|
109
|
+
});
|
|
97
110
|
const withoutSectionImports = (tokens) => tokens[0] === "import" && sectionImports.has(tokens[1] ?? "") ? withoutSectionImports(tokens.slice(tokens[2] === ";" ? 3 : 2)) : tokens;
|
|
98
111
|
const refused = [];
|
|
99
112
|
for (const relative of yield* getEntrypoints) {
|
|
@@ -102,7 +115,7 @@ const assertOwnedEntrypoints = Effect.gen(function* () {
|
|
|
102
115
|
if (relative === DEPLOY_MODULE && isGenerated(contents, [])) continue;
|
|
103
116
|
const tokens = tokenize(contents, absolute, path);
|
|
104
117
|
if (tokens !== void 0) {
|
|
105
|
-
const shapes = optional.get(relative);
|
|
118
|
+
const shapes = relative === "crons.ts" ? yield* cronsShapes(tokens) : optional.get(relative);
|
|
106
119
|
if (shapes !== void 0 && Array.some(shapes, (template) => matchesShape(relative === "http.ts" ? withoutSectionImports(tokens) : tokens, tokenize(template, absolute, path)))) continue;
|
|
107
120
|
if (path.extname(relative) === ".ts") {
|
|
108
121
|
const names = Array.flatMap(tokens, (token, index) => token === "export" && tokens[index + 1] === "const" ? [tokens[index + 2]] : []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionModule.mjs","names":["templates.http","templates.declaredHttp","templates.crons","SectionFiles.written","Declaration.isGenerated","GroupPath.fromGroupModulePath","GroupPath.modulePath","modulePath","GenerationSnapshot.plan","GenerationSnapshot.functionPaths"],"sources":["../src/FunctionModule.ts"],"sourcesContent":["import * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as String from \"effect/String\";\nimport { UnownedConvexEntrypointError } from \"./CodegenError.js\";\nimport * as Declaration from \"./Declaration.js\";\nimport * as SectionFiles from \"./SectionFiles.js\";\nimport * as templates from \"./templates.js\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport * as GroupPaths from \"./GroupPaths.js\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter.js\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n} from \"./utils.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\nimport * as Option from \"effect/Option\";\nimport { quote } from \"./Json.js\";\n\nconst RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n]);\n\n// Only the root module is codegen's; a nested group may take the name.\nconst DEPLOY_MODULE = \"confectDeploy.ts\";\n\n// Keep ownership and removal aligned with Convex's bundler entryPoints filter.\nconst getEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const files = yield* fs.readDirectory(convex, { recursive: true });\n const components = pipe(\n files,\n Array.filter(\n (file) =>\n path.basename(file) === \"convex.config.ts\" &&\n path.dirname(file) !== \".\",\n ),\n Array.map((file) => path.dirname(file) + path.sep),\n );\n return Array.filter(files, (file) => {\n const base = path.basename(file);\n return (\n !pipe(file, String.startsWith(\"_generated\" + path.sep)) &&\n !Array.some(components, (component) =>\n pipe(file, String.startsWith(component)),\n ) &&\n /\\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) &&\n !pipe(base, String.startsWith(\".\")) &&\n !pipe(base, String.startsWith(\"#\")) &&\n pipe(\n base,\n String.match(/\\./g),\n Option.match({ onNone: () => 0, onSome: (dots) => dots.length }),\n ) === 1 &&\n base !== \"schema.ts\" &&\n base !== \"schema.js\" &&\n !pipe(file, String.includes(\" \"))\n );\n });\n});\n\nconst tokenize = (\n source: string,\n modulePath: string,\n path: Path.Path,\n): string[] | undefined => {\n const token =\n /\\s+|\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/|\"(?:\\\\.|[^\"\\\\\\r\\n])*\"|'(?:\\\\.|[^'\\\\\\r\\n])*'|[$A-Z_a-z][$\\w]*|[{}()[\\].,:;=]/y;\n const tokens: string[] = [];\n while (token.lastIndex < source.length) {\n const match = token.exec(source);\n if (match === null) return undefined;\n const value = match[0];\n if (/^\\s|^\\//.test(value)) continue;\n if (\n pipe(value, String.startsWith('\"')) ||\n pipe(value, String.startsWith(\"'\"))\n ) {\n const literal = pipe(value, String.slice(1, -1));\n tokens.push(\n quote(\n pipe(literal, String.startsWith(\".\"))\n ? path.resolve(\n path.dirname(modulePath),\n pipe(literal, String.replace(/\\.js$/, \"\")),\n )\n : literal,\n ),\n );\n } else tokens.push(value);\n }\n return tokens;\n};\n\nconst matchesShape = (\n actual: readonly string[],\n expected: readonly string[],\n) => {\n let index = 0;\n for (const token of expected) {\n if (token === \";\" && actual[index] !== \";\") continue;\n if (actual[index] === \",\" && (token === \"}\" || token === \")\")) index++;\n if (actual[index++] !== token) return false;\n }\n return index === actual.length;\n};\n\n// Before the schema-first HttpRouter.make, codegen emitted forSchema; codegen\n// owns that output so it can rewrite it.\nconst legacyRouter = String.replace(\n \"HttpRouter.make(schema, http.routes, \",\n \"HttpRouter.forSchema(schema)(http.routes, \",\n);\n\n/**\n * @internal\n */\nexport const assertOwnedEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const confect = yield* ConfectDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const importFromConvex = (file: string) =>\n toModuleImportPath(path.relative(convex, path.join(confect, file)));\n const httpTemplates = [\n yield* templates.http({\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n runtimeImportPath: yield* importFromConvex(\"runtime.ts\"),\n }),\n ];\n const optional = new Map([\n [\n \"http.ts\",\n Array.flatMap(httpTemplates, (template) => [\n template,\n legacyRouter(template),\n ]),\n ],\n [\n \"crons.ts\",\n [\n yield* templates.crons({\n cronsImportPath: yield* importFromConvex(\"crons.ts\"),\n }),\n ],\n ],\n ]);\n const written2 = yield* SectionFiles.written;\n // The declared HTTP router first imports each file a manifest section wrote.\n const sectionImports = new Set(\n Array.map(written2, (file) =>\n quote(path.join(confect, \"_generated\", path.basename(file, \".ts\"))),\n ),\n );\n const withoutSectionImports = (\n tokens: ReadonlyArray<string>,\n ): ReadonlyArray<string> =>\n tokens[0] === \"import\" && sectionImports.has(tokens[1] ?? \"\")\n ? withoutSectionImports(tokens.slice(tokens[2] === \";\" ? 3 : 2))\n : tokens;\n const refused: string[] = [];\n for (const relative of yield* getEntrypoints) {\n const absolute = path.join(convex, relative);\n const contents = yield* fs.readFileString(absolute);\n if (relative === DEPLOY_MODULE && Declaration.isGenerated(contents, []))\n continue;\n const tokens = tokenize(contents, absolute, path);\n if (tokens !== undefined) {\n const shapes = optional.get(relative);\n if (\n shapes !== undefined &&\n Array.some(shapes, (template) =>\n matchesShape(\n relative === \"http.ts\" ? withoutSectionImports(tokens) : tokens,\n tokenize(template, absolute, path)!,\n ),\n )\n )\n continue;\n if (path.extname(relative) === \".ts\") {\n const names = Array.flatMap(tokens, (token, index) =>\n token === \"export\" && tokens[index + 1] === \"const\"\n ? [tokens[index + 2]!]\n : [],\n );\n const group = yield* GroupPath.fromGroupModulePath(relative);\n const reusesContext = names.includes(\"experimental_reuseContext\");\n const functionNames = Array.filter(\n names,\n (name) => name !== \"experimental_reuseContext\",\n );\n const template = yield* render({\n functionNames,\n registeredFunctionsImportPath:\n yield* registeredFunctionsImportPathForGroup(group, absolute),\n useNode: tokens[0] === '\"use node\"',\n experimental_reuseContext: reusesContext,\n });\n if (\n functionNames.length > 0 &&\n new Set(functionNames).size === functionNames.length &&\n matchesShape(tokens, tokenize(template, absolute, path)!)\n )\n continue;\n }\n }\n refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));\n }\n if (refused.length > 0)\n return yield* UnownedConvexEntrypointError.make({\n filePaths: refused.sort(),\n });\n});\n\nexport const render = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: Parameters<typeof renderEffect>[0]) =>\n renderEffect({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\nconst renderEffect = Effect.fnUntraced(function* ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: {\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n experimental_reuseContext?: boolean;\n}) {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(`\"use node\";`);\n yield* cbw.blankLine();\n }\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n if (experimental_reuseContext) {\n yield* cbw.writeLine(\"export const experimental_reuseContext = true;\");\n yield* cbw.newLine();\n }\n yield* Effect.forEach(functionNames, (name) =>\n cbw.writeLine(`export const ${name} = registeredFunctions.${name};`),\n );\n\n return yield* cbw.toString();\n});\n\n/**\n * @internal\n */\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: Parameters<typeof generateGroupModuleEffect>[0]) =>\n generateGroupModuleEffect({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\nconst generateGroupModuleEffect = Effect.fnUntraced(function* ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n experimental_reuseContext?: boolean;\n}) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const functionsContentsString = yield* render({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n});\n\n/**\n * Compute the module import specifier (relative to `modulePath`) for a group's\n * registry file under `confect/_generated/registeredFunctions/`. The registry\n * path mirrors the group's path one-to-one (see\n * `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and\n * Node groups.\n *\n * @internal\n */\nexport const registeredFunctionsImportPathForGroup = Effect.fnUntraced(\n function* (groupPath: GroupPath.GroupPath, modulePath: string) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const registeredFunctionsPath =\n path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n ...groupPath.pathSegments,\n ) + \".ts\";\n\n return yield* toModuleImportPath(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n },\n);\n\nconst logGroupPaths = Effect.fnUntraced(function* <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n): Effect.fn.Return<void, never, R | Path.Path | ConvexDirectory> {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(\n groupPaths,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n});\n\n/**\n * @internal\n */\nexport const generateFunctions = Effect.fnUntraced(function* (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n) {\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n yield* applyFunctionPlan(GenerationSnapshot.plan(snapshot, groupPathsFromFs));\n return GenerationSnapshot.functionPaths(snapshot);\n});\n\n/**\n * @internal\n */\nexport const applyFunctionPlan = Effect.fnUntraced(function* (\n plan: GenerationSnapshot.ModulePlan,\n) {\n const removed = GroupPaths.GroupPaths.make(\n HashSet.fromIterable(plan.removed),\n );\n yield* removeGroups(removed);\n yield* logGroupPaths(removed, logFileRemoved);\n yield* writeGroups(plan.changed);\n});\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const path = yield* Path.Path;\n const allConvexPaths = yield* getEntrypoints;\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&\n convexPath !== DEPLOY_MODULE,\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return GroupPaths.GroupPaths.make(HashSet.fromIterable(groupPathArray));\n});\n\n/**\n * @internal\n */\nexport const removeGroups = Effect.fnUntraced(function* (\n groupPaths: GroupPaths.GroupPaths,\n) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* removePathIfExists(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n});\n\n/**\n * @internal\n */\nexport const writeGroups = (\n groups: ReadonlyArray<GenerationSnapshot.GroupSummary>,\n) =>\n Effect.forEach(\n groups,\n Effect.fnUntraced(function* (group: GenerationSnapshot.GroupSummary) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const relativeModulePath = yield* GroupPath.modulePath(group.path);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n const registeredFunctionsImportPath =\n yield* registeredFunctionsImportPathForGroup(group.path, modulePath);\n const change = yield* generateGroupModule({\n groupPath: group.path,\n functionNames: group.functionNames,\n registeredFunctionsImportPath,\n useNode: group.runtime === \"Node\",\n experimental_reuseContext: group.experimental_reuseContext === true,\n });\n yield* Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(modulePath)),\n Match.when(\"Modified\", () => logFileModified(modulePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n );\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,gDAAgC,IAAI,IAAI;CAC5C;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAM,gBAAgB;AAGtB,MAAM,iBAAiB,OAAO,IAAI,aAAa;CAC7C,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,SAAS,OAAO,gBAAgB;CACtC,MAAM,QAAQ,OAAO,GAAG,cAAc,QAAQ,EAAE,WAAW,KAAK,CAAC;CACjE,MAAM,aAAa,KACjB,OACA,MAAM,QACH,SACC,KAAK,SAAS,IAAI,MAAM,sBACxB,KAAK,QAAQ,IAAI,MAAM,GAC3B,GACA,MAAM,KAAK,SAAS,KAAK,QAAQ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EACrB;EACA,SAAS,MAAM,YAAY;EAC3B,2BAA2B,MAAM,8BAA8B;CACjE,CAAC;CACD,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KACzB,MAAM,KAAK,eAAe,aAAaA,YAAU,CAAC,GAClD,MAAM,KAAK,kBAAkB,gBAAgBA,YAAU,CAAC,GACxD,MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,UACR;AACF,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"FunctionModule.mjs","names":["templates.http","templates.declaredHttp","SectionFiles.written","templates.crons","Declaration.isGenerated","GroupPath.fromGroupModulePath","GroupPath.modulePath","modulePath","GenerationSnapshot.plan","GenerationSnapshot.functionPaths"],"sources":["../src/FunctionModule.ts"],"sourcesContent":["import * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as String from \"effect/String\";\nimport { UnownedConvexEntrypointError } from \"./CodegenError.js\";\nimport * as Declaration from \"./Declaration.js\";\nimport * as SectionFiles from \"./SectionFiles.js\";\nimport * as templates from \"./templates.js\";\nimport * as GenerationSnapshot from \"./GenerationSnapshot.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport * as GroupPaths from \"./GroupPaths.js\";\nimport { CodeBlockWriter } from \"./CodeBlockWriter.js\";\nimport { logFileAdded, logFileModified, logFileRemoved } from \"./log.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { ConvexDirectory } from \"./ConvexDirectory.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n} from \"./utils.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\nimport * as Option from \"effect/Option\";\nimport { quote } from \"./Json.js\";\n\nconst RESERVED_CONVEX_TS_FILE_NAMES = new Set([\n \"schema.ts\",\n \"http.ts\",\n \"crons.ts\",\n \"auth.config.ts\",\n \"convex.config.ts\",\n]);\n\n// Only the root module is codegen's; a nested group may take the name.\nconst DEPLOY_MODULE = \"confectDeploy.ts\";\n\n// Keep ownership and removal aligned with Convex's bundler entryPoints filter.\nconst getEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const files = yield* fs.readDirectory(convex, { recursive: true });\n const components = pipe(\n files,\n Array.filter(\n (file) =>\n path.basename(file) === \"convex.config.ts\" &&\n path.dirname(file) !== \".\",\n ),\n Array.map((file) => path.dirname(file) + path.sep),\n );\n return Array.filter(files, (file) => {\n const base = path.basename(file);\n return (\n !pipe(file, String.startsWith(\"_generated\" + path.sep)) &&\n !Array.some(components, (component) =>\n pipe(file, String.startsWith(component)),\n ) &&\n /\\.(?:js|mjs|cjs|ts|tsx|mts|cts|jsx)$/.test(base) &&\n !pipe(base, String.startsWith(\".\")) &&\n !pipe(base, String.startsWith(\"#\")) &&\n pipe(\n base,\n String.match(/\\./g),\n Option.match({ onNone: () => 0, onSome: (dots) => dots.length }),\n ) === 1 &&\n base !== \"schema.ts\" &&\n base !== \"schema.js\" &&\n !pipe(file, String.includes(\" \"))\n );\n });\n});\n\nconst tokenize = (\n source: string,\n modulePath: string,\n path: Path.Path,\n): string[] | undefined => {\n const token =\n /\\s+|\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/|\"(?:\\\\.|[^\"\\\\\\r\\n])*\"|'(?:\\\\.|[^'\\\\\\r\\n])*'|[$A-Z_a-z][$\\w]*|=>|[{}()[\\].,:;=<>]/y;\n const tokens: string[] = [];\n while (token.lastIndex < source.length) {\n const match = token.exec(source);\n if (match === null) return undefined;\n const value = match[0];\n if (/^\\s|^\\//.test(value)) continue;\n if (\n pipe(value, String.startsWith('\"')) ||\n pipe(value, String.startsWith(\"'\"))\n ) {\n const literal = pipe(value, String.slice(1, -1));\n tokens.push(\n quote(\n pipe(literal, String.startsWith(\".\"))\n ? path.resolve(\n path.dirname(modulePath),\n pipe(literal, String.replace(/\\.js$/, \"\")),\n )\n : literal,\n ),\n );\n } else tokens.push(value);\n }\n return tokens;\n};\n\nconst matchesShape = (\n actual: readonly string[],\n expected: readonly string[],\n) => {\n let index = 0;\n for (const token of expected) {\n if (token === \";\" && actual[index] !== \";\") continue;\n if (actual[index] === \",\" && (token === \"}\" || token === \")\")) index++;\n if (actual[index++] !== token) return false;\n }\n return index === actual.length;\n};\n\n// Before the schema-first HttpRouter.make, codegen emitted forSchema; codegen\n// owns that output so it can rewrite it.\nconst legacyRouter = String.replace(\n \"HttpRouter.make(schema, http.routes, \",\n \"HttpRouter.forSchema(schema)(http.routes, \",\n);\n\n// @gaganref/confect-cli 10.6.0-fork.12 wrote `wraps.reduce(` without the type\n// argument. Codegen owns that output so it can rewrite it. Drop this once no\n// consumer pins a release before the type argument.\nconst legacyCrons = String.replace(\n \"wraps.reduce<CronJobs.CronJobs>(\",\n \"wraps.reduce(\",\n);\n\n/**\n * @internal\n */\nexport const assertOwnedEntrypoints = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convex = yield* ConvexDirectory.get;\n const confect = yield* ConfectDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const importFromConvex = (file: string) =>\n toModuleImportPath(path.relative(convex, path.join(confect, file)));\n const httpTemplates = [\n yield* templates.http({\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n }),\n yield* templates.declaredHttp({\n schemaImportPath: yield* importFromConvex(\"_generated/schema.ts\"),\n httpImportPath: yield* importFromConvex(\"http.ts\"),\n runtimeImportPath: yield* importFromConvex(\"runtime.ts\"),\n }),\n ];\n const optional = new Map([\n [\n \"http.ts\",\n Array.flatMap(httpTemplates, (template) => [\n template,\n legacyRouter(template),\n ]),\n ],\n ]);\n const written2 = yield* SectionFiles.written;\n // The declared HTTP router first imports each file a manifest section wrote.\n const sectionImports = new Map(\n Array.map(written2, (file) => [\n quote(path.join(confect, \"_generated\", path.basename(file, \".ts\"))),\n file,\n ]),\n );\n // This check only keeps codegen from overwriting hand-written code, and later\n // in the same run codegen writes `convex/crons.ts` with exactly this run's\n // wrappers. So the crons template holds nothing to lose when it wraps\n // distinct files a section wrote, in any order, even ones that no longer\n // wrap. The same-run rewrite holds for declared backends; an undeclared\n // backend without `confect/crons.ts` keeps a leftover entry, as before.\n const cronsShapes = Effect.fnUntraced(function* (\n tokens: ReadonlyArray<string>,\n ) {\n const wrapped = Array.flatMap(tokens, (token, index) => {\n const file = sectionImports.get(token);\n return tokens[index - 1] === \"from\" && file !== undefined ? [file] : [];\n });\n if (new Set(wrapped).size !== wrapped.length) return [];\n const template = yield* templates.crons({\n cronsImportPath: yield* importFromConvex(\"crons.ts\"),\n sectionImportPaths: yield* Effect.forEach(wrapped, (file) =>\n importFromConvex(`_generated/${file}`),\n ),\n });\n return [template, legacyCrons(template)];\n });\n const withoutSectionImports = (\n tokens: ReadonlyArray<string>,\n ): ReadonlyArray<string> =>\n tokens[0] === \"import\" && sectionImports.has(tokens[1] ?? \"\")\n ? withoutSectionImports(tokens.slice(tokens[2] === \";\" ? 3 : 2))\n : tokens;\n const refused: string[] = [];\n for (const relative of yield* getEntrypoints) {\n const absolute = path.join(convex, relative);\n const contents = yield* fs.readFileString(absolute);\n if (relative === DEPLOY_MODULE && Declaration.isGenerated(contents, []))\n continue;\n const tokens = tokenize(contents, absolute, path);\n if (tokens !== undefined) {\n const shapes =\n relative === \"crons.ts\"\n ? yield* cronsShapes(tokens)\n : optional.get(relative);\n if (\n shapes !== undefined &&\n Array.some(shapes, (template) =>\n matchesShape(\n relative === \"http.ts\" ? withoutSectionImports(tokens) : tokens,\n tokenize(template, absolute, path)!,\n ),\n )\n )\n continue;\n if (path.extname(relative) === \".ts\") {\n const names = Array.flatMap(tokens, (token, index) =>\n token === \"export\" && tokens[index + 1] === \"const\"\n ? [tokens[index + 2]!]\n : [],\n );\n const group = yield* GroupPath.fromGroupModulePath(relative);\n const reusesContext = names.includes(\"experimental_reuseContext\");\n const functionNames = Array.filter(\n names,\n (name) => name !== \"experimental_reuseContext\",\n );\n const template = yield* render({\n functionNames,\n registeredFunctionsImportPath:\n yield* registeredFunctionsImportPathForGroup(group, absolute),\n useNode: tokens[0] === '\"use node\"',\n experimental_reuseContext: reusesContext,\n });\n if (\n functionNames.length > 0 &&\n new Set(functionNames).size === functionNames.length &&\n matchesShape(tokens, tokenize(template, absolute, path)!)\n )\n continue;\n }\n }\n refused.push(toPosixPath(path, path.relative(projectRoot, absolute)));\n }\n if (refused.length > 0)\n return yield* UnownedConvexEntrypointError.make({\n filePaths: refused.sort(),\n });\n});\n\nexport const render = ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: Parameters<typeof renderEffect>[0]) =>\n renderEffect({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\nconst renderEffect = Effect.fnUntraced(function* ({\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: {\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n experimental_reuseContext?: boolean;\n}) {\n const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });\n\n if (useNode) {\n yield* cbw.writeLine(`\"use node\";`);\n yield* cbw.blankLine();\n }\n\n yield* cbw.writeLine(\n `import registeredFunctions from \"${registeredFunctionsImportPath}\";`,\n );\n yield* cbw.newLine();\n if (experimental_reuseContext) {\n yield* cbw.writeLine(\"export const experimental_reuseContext = true;\");\n yield* cbw.newLine();\n }\n yield* Effect.forEach(functionNames, (name) =>\n cbw.writeLine(`export const ${name} = registeredFunctions.${name};`),\n );\n\n return yield* cbw.toString();\n});\n\n/**\n * @internal\n */\nexport const generateGroupModule = ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: Parameters<typeof generateGroupModuleEffect>[0]) =>\n generateGroupModuleEffect({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\nconst generateGroupModuleEffect = Effect.fnUntraced(function* ({\n groupPath,\n functionNames,\n registeredFunctionsImportPath,\n useNode = false,\n experimental_reuseContext = false,\n}: {\n groupPath: GroupPath.GroupPath;\n functionNames: ReadonlyArray<string>;\n registeredFunctionsImportPath: string;\n useNode?: boolean;\n experimental_reuseContext?: boolean;\n}) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n const directoryPath = path.dirname(modulePath);\n if (!(yield* fs.exists(directoryPath))) {\n yield* fs.makeDirectory(directoryPath, { recursive: true });\n }\n\n const functionsContentsString = yield* render({\n functionNames,\n registeredFunctionsImportPath,\n useNode,\n experimental_reuseContext,\n });\n\n if (!(yield* fs.exists(modulePath))) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Added\" as const;\n }\n const existing = yield* fs.readFileString(modulePath);\n if (existing !== functionsContentsString) {\n yield* fs.writeFileString(modulePath, functionsContentsString);\n return \"Modified\" as const;\n }\n return \"Unchanged\" as const;\n});\n\n/**\n * Compute the module import specifier (relative to `modulePath`) for a group's\n * registry file under `confect/_generated/registeredFunctions/`. The registry\n * path mirrors the group's path one-to-one (see\n * `registeredFunctionsRelativePath` in `LeafModule.ts`) for both Convex and\n * Node groups.\n *\n * @internal\n */\nexport const registeredFunctionsImportPathForGroup = Effect.fnUntraced(\n function* (groupPath: GroupPath.GroupPath, modulePath: string) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const registeredFunctionsPath =\n path.join(\n confectDirectory,\n \"_generated\",\n \"registeredFunctions\",\n ...groupPath.pathSegments,\n ) + \".ts\";\n\n return yield* toModuleImportPath(\n path.relative(path.dirname(modulePath), registeredFunctionsPath),\n );\n },\n);\n\nconst logGroupPaths = Effect.fnUntraced(function* <R>(\n groupPaths: GroupPaths.GroupPaths,\n logFn: (fullPath: string) => Effect.Effect<void, never, R>,\n): Effect.fn.Return<void, never, R | Path.Path | ConvexDirectory> {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.forEach(\n groupPaths,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n const relativeModulePath = yield* GroupPath.modulePath(gp);\n yield* logFn(path.join(convexDirectory, relativeModulePath));\n }),\n );\n});\n\n/**\n * @internal\n */\nexport const generateFunctions = Effect.fnUntraced(function* (\n snapshot: GenerationSnapshot.GenerationSnapshot,\n) {\n const groupPathsFromFs = yield* getGroupPathsFromFs;\n yield* applyFunctionPlan(GenerationSnapshot.plan(snapshot, groupPathsFromFs));\n return GenerationSnapshot.functionPaths(snapshot);\n});\n\n/**\n * @internal\n */\nexport const applyFunctionPlan = Effect.fnUntraced(function* (\n plan: GenerationSnapshot.ModulePlan,\n) {\n const removed = GroupPaths.GroupPaths.make(\n HashSet.fromIterable(plan.removed),\n );\n yield* removeGroups(removed);\n yield* logGroupPaths(removed, logFileRemoved);\n yield* writeGroups(plan.changed);\n});\n\nconst getGroupPathsFromFs = Effect.gen(function* () {\n const path = yield* Path.Path;\n const allConvexPaths = yield* getEntrypoints;\n const groupPathArray = yield* pipe(\n allConvexPaths,\n Array.filter(\n (convexPath) =>\n path.extname(convexPath) === \".ts\" &&\n !RESERVED_CONVEX_TS_FILE_NAMES.has(path.basename(convexPath)) &&\n convexPath !== DEPLOY_MODULE,\n ),\n Effect.forEach((groupModulePath) =>\n GroupPath.fromGroupModulePath(groupModulePath),\n ),\n );\n return GroupPaths.GroupPaths.make(HashSet.fromIterable(groupPathArray));\n});\n\n/**\n * @internal\n */\nexport const removeGroups = Effect.fnUntraced(function* (\n groupPaths: GroupPaths.GroupPaths,\n) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n\n yield* Effect.all(\n HashSet.map(groupPaths, (groupPath) =>\n Effect.gen(function* () {\n const relativeModulePath = yield* GroupPath.modulePath(groupPath);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n\n yield* Effect.logDebug(`Removing group '${relativeModulePath}'...`);\n\n yield* removePathIfExists(modulePath);\n yield* Effect.logDebug(`Group '${relativeModulePath}' removed`);\n }),\n ),\n { concurrency: \"unbounded\" },\n );\n});\n\n/**\n * @internal\n */\nexport const writeGroups = (\n groups: ReadonlyArray<GenerationSnapshot.GroupSummary>,\n) =>\n Effect.forEach(\n groups,\n Effect.fnUntraced(function* (group: GenerationSnapshot.GroupSummary) {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const relativeModulePath = yield* GroupPath.modulePath(group.path);\n const modulePath = path.join(convexDirectory, relativeModulePath);\n const registeredFunctionsImportPath =\n yield* registeredFunctionsImportPathForGroup(group.path, modulePath);\n const change = yield* generateGroupModule({\n groupPath: group.path,\n functionNames: group.functionNames,\n registeredFunctionsImportPath,\n useNode: group.runtime === \"Node\",\n experimental_reuseContext: group.experimental_reuseContext === true,\n });\n yield* Match.value(change).pipe(\n Match.when(\"Added\", () => logFileAdded(modulePath)),\n Match.when(\"Modified\", () => logFileModified(modulePath)),\n Match.when(\"Unchanged\", () => Effect.void),\n Match.exhaustive,\n );\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,gDAAgC,IAAI,IAAI;CAC5C;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAM,gBAAgB;AAGtB,MAAM,iBAAiB,OAAO,IAAI,aAAa;CAC7C,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,SAAS,OAAO,gBAAgB;CACtC,MAAM,QAAQ,OAAO,GAA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C,OAAO,OAAO,IACZ,QAAQ,IAAI,aAAa,cACvB,OAAO,IAAI,aAAa;EACtB,MAAM,qBAAqB,OAAOC,WAAqB,SAAS;EAChE,MAAMC,eAAa,KAAK,KAAK,iBAAiB,kBAAkB;EAEhE,OAAO,OAAO,SAAS,mBAAmB,mBAAmB,KAAK;EAElE,OAAO,mBAAmBA,YAAU;EACpC,OAAO,OAAO,SAAS,UAAU,mBAAmB,UAAU;CAChE,CAAC,CACH,GACA,EAAE,aAAa,YAAY,CAC7B;AACF,CAAC;;;;AAKD,MAAa,eACX,WAEA,OAAO,QACL,QACA,OAAO,WAAW,WAAW,OAAwC;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,kBAAkB,OAAO,gBAAgB;CAC/C,MAAM,qBAAqB,OAAOD,WAAqB,MAAM,IAAI;CACjE,MAAMC,eAAa,KAAK,KAAK,iBAAiB,kBAAkB;CAChE,MAAM,gCACJ,OAAO,sCAAsC,MAAM,MAAMA,YAAU;CACrE,MAAM,SAAS,OAAO,oBAAoB;EACxC,WAAW,MAAM;EACjB,eAAe,MAAM;EACrB;EACA,SAAS,MAAM,YAAY;EAC3B,2BAA2B,MAAM,8BAA8B;CACjE,CAAC;CACD,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KACzB,MAAM,KAAK,eAAe,aAAaA,YAAU,CAAC,GAClD,MAAM,KAAK,kBAAkB,gBAAgBA,YAAU,CAAC,GACxD,MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,UACR;AACF,CAAC,CACH"}
|
package/dist/SectionFiles.mjs
CHANGED
|
@@ -178,7 +178,8 @@ const inputs = Effect.map(Effect.all([record(INPUTS), record(VERIFY_INPUTS)]), (
|
|
|
178
178
|
* after logging the rest. The record of section inputs is written either way,
|
|
179
179
|
* keeping the previous inputs after a failure, so `confect dev` sees the fix.
|
|
180
180
|
* Returns the claimed file names, whether they differ from the section files
|
|
181
|
-
* that existed before,
|
|
181
|
+
* that existed before, the modules each section key matched, and the files of
|
|
182
|
+
* the sections that wrap crons, in the order `App.make` declares them.
|
|
182
183
|
*
|
|
183
184
|
* @internal
|
|
184
185
|
*/
|
|
@@ -216,6 +217,7 @@ const sync = Effect.fnUntraced(function* (backend, leaves, mounts) {
|
|
|
216
217
|
return {
|
|
217
218
|
modules: new Map(Arr.map(rendered, ({ key, modules }) => [key, modules])),
|
|
218
219
|
files: names,
|
|
220
|
+
crons: Option.isNone(backend) ? [] : Arr.flatMap(backend.value.sections, ({ section: { generate } }) => generate?.wrapsCrons === true ? [generate.file] : []),
|
|
219
221
|
changed: names.length !== existing.length || Arr.some(names, (file) => !existing.includes(file))
|
|
220
222
|
};
|
|
221
223
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionFiles.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin"],"sources":["../src/SectionFiles.ts"],"sourcesContent":["import type { FunctionSpec, GroupSpec, ManifestSection } from \"@confect/core\";\nimport type * as esbuild from \"esbuild\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"./BuildError.js\";\nimport * as Bundler from \"./Bundler.js\";\nimport {\n InvalidManifestSectionError,\n logCodegenError,\n} from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport * as ConvexConfig from \"./ConvexConfig.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport { logFileRemoved } from \"./log.js\";\nimport {\n removePathIfExists,\n toPosixPath,\n writeFileStringAndLog,\n} from \"./utils.js\";\nimport * as Str from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Arr from \"effect/Array\";\nimport * as Record from \"effect/Record\";\nimport { quote } from \"./Json.js\";\n\ntype Leaf = Pick<LoadedLeafModule, \"spec\" | \"pathSegments\" | \"relativePath\">;\n\n/**\n * The files codegen writes directly in `confect/_generated`, current and\n * legacy, which no section may claim.\n */\nexport const builtIn: ReadonlySet<string> = new Set(\n Arr.map(\n pipe(\n `spec schema convexSchema id components component refs docs services manifest\n auth.providers testing api nodeApi impl nodeImpl nodeSpec registeredFunctions\n nodeRegisteredFunctions`,\n Str.split(/\\s+/),\n ),\n (name) => `${name}.ts`,\n ),\n);\n\nconst PREFIX = \"// Generated by `confect codegen` from the manifest section \";\nconst header = (key: string) => `${PREFIX}${quote(key)}. Do not edit.`;\nconst Sources = Schema.String.pipe(Schema.Array, Schema.fromJsonString);\nconst encodeSources = (sources: ReadonlyArray<string>) =>\n Schema.encodeEffect(Sources)(sources).pipe(Effect.orDie);\nconst decodeSources = Schema.decodeUnknownOption(Sources);\nconst INPUTS = \"sectionInputs.json\";\nconst VERIFY_INPUTS = \"verifyInputs.json\";\n\ninterface Claim {\n readonly key: string;\n readonly generate: ManifestSection.Generate;\n}\n\n/**\n * A declared backend: the target codegen generates and the sections its\n * `App.make` names.\n */\nexport interface Backend {\n readonly target: ManifestSection.Target;\n readonly sections: ReadonlyArray<ManifestSection.Entry>;\n}\n\nconst visit = (\n leaves: ReadonlyArray<Leaf>,\n each: (spec: FunctionSpec.AnyWithProps, path: string, source: string) => void,\n) => {\n const walk = (\n group: GroupSpec.AnyWithProps,\n path: string,\n source: string,\n ) => {\n for (const spec of Record.values(group.functions))\n each(spec, `${path}:${spec.name}`, source);\n for (const [name, child] of Record.toEntries(group.groups))\n walk(child, `${path}/${name}`, source);\n };\n for (const leaf of leaves)\n walk(leaf.spec, Arr.join(leaf.pathSegments, \"/\"), leaf.relativePath);\n};\n\n/**\n * One claim per declared section that generates a file, ordered by file. A name\n * that is built in, not a `.ts` file directly in `_generated`, or claimed by\n * two keys is refused.\n */\nexport const claims = (sections: ReadonlyArray<ManifestSection.Entry>) =>\n Result.gen(function* () {\n const byKey = new Map<string, ManifestSection.Generate>();\n for (const { key, section } of sections)\n if (section.generate !== undefined) byKey.set(key, section.generate);\n const byFile = new Map<string, string>();\n for (const [key, { file }] of byKey) {\n const other = byFile.get(file);\n const refusal = builtIn.has(file)\n ? `claims confect/_generated/${file}, which codegen writes itself.`\n : !/^[\\w-]+\\.ts$/.test(file)\n ? `claims ${quote(file)}; name a .ts file directly inside confect/_generated.`\n : other !== undefined\n ? `claims confect/_generated/${file}, which the manifest section ${quote(other)} also claims.`\n : undefined;\n if (refusal !== undefined)\n return yield* Result.fail(\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: refusal,\n }),\n );\n byFile.set(file, key);\n }\n return Arr.map([...byKey], ([key, generate]) => ({ key, generate })).sort(\n (a, b) => pipe(a.generate.file, Str.localeCompare(b.generate.file)),\n );\n });\n\nconst sourceFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const directory = yield* fs.readDirectory(confectDirectory, {\n recursive: true,\n });\n return pipe(\n directory,\n Arr.map((file) => toPosixPath(path, file)),\n Arr.filter(\n (file) =>\n pipe(file, Str.endsWith(\".ts\")) &&\n !pipe(file, Str.endsWith(\".d.ts\")) &&\n !pipe(file, Str.split(\"/\")).includes(\"_generated\"),\n ),\n ).sort();\n});\n\n/**\n * Bundle each matched `confect/` file and return its exports, adding it and\n * every first-party file it imports to `watched`.\n */\nconst load = Effect.fnUntraced(function* (\n matched: ReadonlyArray<string>,\n watched: Set<string>,\n plugins: ReadonlyArray<esbuild.Plugin> = [],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n for (const file of matched) watched.add(file);\n return yield* Effect.forEach(matched, (relativePath) => {\n const entry = path.join(confectDirectory, relativePath);\n // Inputs are recorded once esbuild finishes, before the module runs, so a\n // module that throws on load still has its imports watched. `confect dev`\n // sees changes only under `confect/`, and every run rewrites `_generated`,\n // so watching it would loop.\n const recordInputs: esbuild.Plugin = {\n name: \"confect:section-inputs\",\n setup: (build) =>\n build.onEnd(({ metafile }) => {\n for (const loaded of Record.keys(metafile?.inputs ?? {})) {\n // A plugin's own namespace, such as the component config\n // wrapper, is not a file.\n if (/^[^/\\\\]+:/.test(loaded) && !path.isAbsolute(loaded)) continue;\n const file = toPosixPath(\n path,\n path.relative(\n confectDirectory,\n path.resolve(path.dirname(entry), loaded),\n ),\n );\n if (\n !pipe(file, Str.startsWith(\"../\")) &&\n !pipe(file, Str.startsWith(\"_generated/\"))\n )\n watched.add(file);\n }\n }),\n };\n return Bundler.bundle(entry, { plugins: [...plugins, recordInputs] }).pipe(\n Effect.mapBoth({\n onFailure: (error) =>\n fromBundlerError(`confect/${relativePath}`, error),\n onSuccess: ({ module }) => ({ relativePath, exports: module }),\n }),\n );\n });\n});\n\n/**\n * Fail with the first of a section's refusals after logging the rest.\n */\nconst refuse = Effect.fnUntraced(function* (\n key: string,\n reasons: ReadonlyArray<string>,\n) {\n const [error, ...more] = Arr.map(reasons, (reason) =>\n InvalidManifestSectionError.make({ sectionKey: key, reason }),\n );\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\nconst render = Effect.fnUntraced(function* (\n { key, generate }: Claim,\n target: ManifestSection.Target,\n input: Pick<ManifestSection.GenerateInput, \"functions\" | \"mounts\" | \"files\">,\n watched: Set<string>,\n) {\n const confectDirectory = yield* ConfectDirectory.get;\n const failed = (cause: unknown) =>\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: `generate failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => Arr.filter(input.files, (file) => generate.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched);\n const { contents, errors } = yield* Effect.try({\n try: () => generate.render({ ...input, modules, target, confectDirectory }),\n catch: failed,\n });\n yield* refuse(key, errors);\n const sources = yield* encodeSources(matched);\n return {\n modules,\n contents: Arr.join([header(key), `// Sources: ${sources}`, contents], \"\\n\"),\n };\n});\n\n/**\n * The files in `confect/_generated` a section wrote, which carry its header.\n *\n * @internal\n */\nexport const written = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n if (!(yield* fs.exists(generated))) return [];\n const directory = yield* fs.readDirectory(generated);\n return yield* Effect.filter(\n Arr.filter(directory, (file) => pipe(file, Str.endsWith(\".ts\"))),\n (file) =>\n fs\n .readFileString(path.join(generated, file))\n .pipe(Effect.map((contents) => pipe(contents, Str.startsWith(PREFIX)))),\n );\n});\n\nconst record = Effect.fnUntraced(function* (name: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const file = path.join(confectDirectory, \"_generated\", name);\n const none: ReadonlyArray<string> = [];\n if (!(yield* fs.exists(file))) return none;\n const fileContents = yield* fs.readFileString(file);\n return Option.getOrElse(decodeSources(fileContents), () => none);\n});\n\n/**\n * The `confect/` files the declared sections' `generate` and `verify` matched\n * and the `confect/` files those import, as recorded by the last codegen run\n * that loaded them.\n *\n * @internal\n */\nexport const inputs = Effect.map(\n Effect.all([record(INPUTS), record(VERIFY_INPUTS)]),\n ([rendered, verified]) => [...new Set([...rendered, ...verified])].sort(),\n);\n\n/**\n * Write each claimed file into `confect/_generated` once every section the\n * declared backend names has rendered for its target; an undeclared backend\n * renders none. Every section renders before codegen fails with the first error\n * after logging the rest. The record of section inputs is written either way,\n * keeping the previous inputs after a failure, so `confect dev` sees the fix.\n * Returns the claimed file names, whether they differ from the section files\n * that existed before, and the modules each section key matched.\n *\n * @internal\n */\nexport const sync = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n leaves: ReadonlyArray<Leaf>,\n mounts: ManifestSection.GenerateInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n const claimed = Option.isSome(backend)\n ? yield* Effect.map(\n Effect.fromResult(claims(backend.value.sections)),\n Arr.map((claim) => ({ claim, target: backend.value.target })),\n )\n : [];\n const functions: Array<{ path: string; source: string }> = [];\n visit(leaves, (_, functionPath, source) =>\n functions.push({ path: functionPath, source }),\n );\n const files = claimed.length === 0 ? [] : yield* sourceFiles;\n const watched = new Set<string>();\n const [rendered, failures] = yield* Effect.partition(\n claimed,\n ({ claim, target }) =>\n render(claim, target, { functions, mounts, files }, watched).pipe(\n Effect.map((output) => ({ ...claim, ...output })),\n ),\n );\n if (failures.length > 0)\n for (const file of yield* record(INPUTS)) watched.add(file);\n yield* claimed.length === 0\n ? removePathIfExists(path.join(generated, INPUTS))\n : encodeSources([...watched].sort()).pipe(\n Effect.flatMap((sources) =>\n writeFileStringAndLog(path.join(generated, INPUTS), sources),\n ),\n );\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n const existing = yield* written;\n for (const { generate, contents } of rendered)\n yield* writeFileStringAndLog(path.join(generated, generate.file), contents);\n const names = Arr.map(rendered, ({ generate }) => generate.file);\n return {\n modules: new Map(Arr.map(rendered, ({ key, modules }) => [key, modules])),\n files: names,\n changed:\n names.length !== existing.length ||\n Arr.some(names, (file) => !existing.includes(file)),\n };\n});\n\n/**\n * Run each declared section's `verify` once every `_generated` file exists:\n * bundle the `confect/` files its `match` selects as codegen bundles a\n * declaration, and hand their exports, the mounts and the target to its\n * `check`. Every section checks before codegen fails with the first refusal\n * after logging the rest. The files each loaded are recorded as section inputs,\n * keeping the previous ones after a failure, so `confect dev` checks again when\n * one changes.\n *\n * @internal\n */\nexport const verify = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n mounts: ManifestSection.VerifyInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const recorded = path.join(confectDirectory, \"_generated\", VERIFY_INPUTS);\n const checks = Option.match(backend, {\n onNone: () => [],\n onSome: ({ sections }) =>\n Arr.flatMap(sections, ({ key, section }) =>\n section.generate?.verify === undefined\n ? []\n : [{ key, verifier: section.generate.verify }],\n ),\n });\n if (Option.isNone(backend) || checks.length === 0)\n return yield* removePathIfExists(recorded);\n const { target } = backend.value;\n const files = yield* sourceFiles;\n const watched = new Set<string>();\n const [, failures] = yield* Effect.partition(checks, ({ key, verifier }) =>\n Effect.gen(function* () {\n const failed = (cause: unknown) =>\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: `verify failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => Arr.filter(files, (file) => verifier.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched, [\n ConvexConfig.componentConfigPlugin(path),\n ]);\n const tryValue = yield* Effect.try({\n try: () => verifier.check({ modules, mounts, target }),\n catch: failed,\n });\n yield* refuse(key, tryValue);\n }),\n );\n if (failures.length > 0)\n for (const file of yield* record(VERIFY_INPUTS)) watched.add(file);\n const sources = yield* encodeSources([...watched].sort());\n yield* writeFileStringAndLog(recorded, sources);\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\n/**\n * Remove each file a section wrote that is not in `files`. Codegen runs this\n * after it rewrites the registration files and the HTTP router, so a run that\n * fails earlier leaves no import of a removed file.\n *\n * @internal\n */\nexport const removeUnclaimed = Effect.fnUntraced(function* (\n files: ReadonlyArray<string>,\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n for (const file of yield* written)\n if (!files.includes(file)) {\n yield* removePathIfExists(path.join(generated, file));\n yield* logFileRemoved(path.join(generated, file));\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,UAA+B,IAAI,IAC9C,IAAI,IACF,KACE;;4BAGA,IAAI,MAAM,KAAK,CACjB,IACC,SAAS,GAAG,KAAK,IACpB,CACF;AAEA,MAAM,SAAS;AACf,MAAM,UAAU,QAAgB,GAAG,SAAS,MAAM,GAAG,EAAE;AACvD,MAAM,UAAU,OAAO,OAAO,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AAI,OAAO,QAAQ,SAAS,SAAS,MAAM,IAAI,CAAC;GAC3D,OAAO;EACT,CAAC;EACD,MAAM,UAAU,OAAO,KAAK,SAAS,SAAS,CAC5CC,sBAAmC,IAAI,CACzC,CAAC;EACD,MAAM,WAAW,OAAO,OAAO,IAAI;GACjC,WAAW,SAAS,MAAM;IAAE;IAAS;IAAQ;GAAO,CAAC;GACrD,OAAO;EACT,CAAC;EACD,OAAO,OAAO,KAAK,QAAQ;CAC7B,CAAC,CACH;CACA,IAAI,SAAS,SAAS,GACpB,KAAK,MAAM,QAAQ,OAAO,OAAO,aAAa,GAAG,QAAQ,IAAI,IAAI;CACnE,MAAM,UAAU,OAAO,cAAc,CAAC,GAAG,OAAO,CAAC,CAAC,KAAK,CAAC;CACxD,OAAO,sBAAsB,UAAU,OAAO;CAC9C,MAAM,CAAC,OAAO,GAAG,QAAQ;CACzB,KAAK,MAAM,SAAS,MAAM,OAAO,gBAAgB,KAAK;CACtD,IAAI,UAAU,KAAA,GAAW,OAAO,OAAO;AACzC,CAAC;;;;;;;;AASD,MAAa,kBAAkB,OAAO,WAAW,WAC/C,OACA;CACA,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,mBAAmB,OAAO,iBAAiB;CACjD,MAAM,YAAY,KAAK,KAAK,kBAAkB,YAAY;CAC1D,KAAK,MAAM,QAAQ,OAAO,SACxB,IAAI,CAAC,MAAM,SAAS,IAAI,GAAG;EACzB,OAAO,mBAAmB,KAAK,KAAK,WAAW,IAAI,CAAC;EACpD,OAAO,eAAe,KAAK,KAAK,WAAW,IAAI,CAAC;CAClD;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"SectionFiles.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin"],"sources":["../src/SectionFiles.ts"],"sourcesContent":["import type { FunctionSpec, GroupSpec, ManifestSection } from \"@confect/core\";\nimport type * as esbuild from \"esbuild\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"./BuildError.js\";\nimport * as Bundler from \"./Bundler.js\";\nimport {\n InvalidManifestSectionError,\n logCodegenError,\n} from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport * as ConvexConfig from \"./ConvexConfig.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport { logFileRemoved } from \"./log.js\";\nimport {\n removePathIfExists,\n toPosixPath,\n writeFileStringAndLog,\n} from \"./utils.js\";\nimport * as Str from \"effect/String\";\nimport { pipe } from \"effect/Function\";\nimport * as Arr from \"effect/Array\";\nimport * as Record from \"effect/Record\";\nimport { quote } from \"./Json.js\";\n\ntype Leaf = Pick<LoadedLeafModule, \"spec\" | \"pathSegments\" | \"relativePath\">;\n\n/**\n * The files codegen writes directly in `confect/_generated`, current and\n * legacy, which no section may claim.\n */\nexport const builtIn: ReadonlySet<string> = new Set(\n Arr.map(\n pipe(\n `spec schema convexSchema id components component refs docs services manifest\n auth.providers testing api nodeApi impl nodeImpl nodeSpec registeredFunctions\n nodeRegisteredFunctions`,\n Str.split(/\\s+/),\n ),\n (name) => `${name}.ts`,\n ),\n);\n\nconst PREFIX = \"// Generated by `confect codegen` from the manifest section \";\nconst header = (key: string) => `${PREFIX}${quote(key)}. Do not edit.`;\nconst Sources = Schema.String.pipe(Schema.Array, Schema.fromJsonString);\nconst encodeSources = (sources: ReadonlyArray<string>) =>\n Schema.encodeEffect(Sources)(sources).pipe(Effect.orDie);\nconst decodeSources = Schema.decodeUnknownOption(Sources);\nconst INPUTS = \"sectionInputs.json\";\nconst VERIFY_INPUTS = \"verifyInputs.json\";\n\ninterface Claim {\n readonly key: string;\n readonly generate: ManifestSection.Generate;\n}\n\n/**\n * A declared backend: the target codegen generates and the sections its\n * `App.make` names.\n */\nexport interface Backend {\n readonly target: ManifestSection.Target;\n readonly sections: ReadonlyArray<ManifestSection.Entry>;\n}\n\nconst visit = (\n leaves: ReadonlyArray<Leaf>,\n each: (spec: FunctionSpec.AnyWithProps, path: string, source: string) => void,\n) => {\n const walk = (\n group: GroupSpec.AnyWithProps,\n path: string,\n source: string,\n ) => {\n for (const spec of Record.values(group.functions))\n each(spec, `${path}:${spec.name}`, source);\n for (const [name, child] of Record.toEntries(group.groups))\n walk(child, `${path}/${name}`, source);\n };\n for (const leaf of leaves)\n walk(leaf.spec, Arr.join(leaf.pathSegments, \"/\"), leaf.relativePath);\n};\n\n/**\n * One claim per declared section that generates a file, ordered by file. A name\n * that is built in, not a `.ts` file directly in `_generated`, or claimed by\n * two keys is refused.\n */\nexport const claims = (sections: ReadonlyArray<ManifestSection.Entry>) =>\n Result.gen(function* () {\n const byKey = new Map<string, ManifestSection.Generate>();\n for (const { key, section } of sections)\n if (section.generate !== undefined) byKey.set(key, section.generate);\n const byFile = new Map<string, string>();\n for (const [key, { file }] of byKey) {\n const other = byFile.get(file);\n const refusal = builtIn.has(file)\n ? `claims confect/_generated/${file}, which codegen writes itself.`\n : !/^[\\w-]+\\.ts$/.test(file)\n ? `claims ${quote(file)}; name a .ts file directly inside confect/_generated.`\n : other !== undefined\n ? `claims confect/_generated/${file}, which the manifest section ${quote(other)} also claims.`\n : undefined;\n if (refusal !== undefined)\n return yield* Result.fail(\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: refusal,\n }),\n );\n byFile.set(file, key);\n }\n return Arr.map([...byKey], ([key, generate]) => ({ key, generate })).sort(\n (a, b) => pipe(a.generate.file, Str.localeCompare(b.generate.file)),\n );\n });\n\nconst sourceFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const directory = yield* fs.readDirectory(confectDirectory, {\n recursive: true,\n });\n return pipe(\n directory,\n Arr.map((file) => toPosixPath(path, file)),\n Arr.filter(\n (file) =>\n pipe(file, Str.endsWith(\".ts\")) &&\n !pipe(file, Str.endsWith(\".d.ts\")) &&\n !pipe(file, Str.split(\"/\")).includes(\"_generated\"),\n ),\n ).sort();\n});\n\n/**\n * Bundle each matched `confect/` file and return its exports, adding it and\n * every first-party file it imports to `watched`.\n */\nconst load = Effect.fnUntraced(function* (\n matched: ReadonlyArray<string>,\n watched: Set<string>,\n plugins: ReadonlyArray<esbuild.Plugin> = [],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n for (const file of matched) watched.add(file);\n return yield* Effect.forEach(matched, (relativePath) => {\n const entry = path.join(confectDirectory, relativePath);\n // Inputs are recorded once esbuild finishes, before the module runs, so a\n // module that throws on load still has its imports watched. `confect dev`\n // sees changes only under `confect/`, and every run rewrites `_generated`,\n // so watching it would loop.\n const recordInputs: esbuild.Plugin = {\n name: \"confect:section-inputs\",\n setup: (build) =>\n build.onEnd(({ metafile }) => {\n for (const loaded of Record.keys(metafile?.inputs ?? {})) {\n // A plugin's own namespace, such as the component config\n // wrapper, is not a file.\n if (/^[^/\\\\]+:/.test(loaded) && !path.isAbsolute(loaded)) continue;\n const file = toPosixPath(\n path,\n path.relative(\n confectDirectory,\n path.resolve(path.dirname(entry), loaded),\n ),\n );\n if (\n !pipe(file, Str.startsWith(\"../\")) &&\n !pipe(file, Str.startsWith(\"_generated/\"))\n )\n watched.add(file);\n }\n }),\n };\n return Bundler.bundle(entry, { plugins: [...plugins, recordInputs] }).pipe(\n Effect.mapBoth({\n onFailure: (error) =>\n fromBundlerError(`confect/${relativePath}`, error),\n onSuccess: ({ module }) => ({ relativePath, exports: module }),\n }),\n );\n });\n});\n\n/**\n * Fail with the first of a section's refusals after logging the rest.\n */\nconst refuse = Effect.fnUntraced(function* (\n key: string,\n reasons: ReadonlyArray<string>,\n) {\n const [error, ...more] = Arr.map(reasons, (reason) =>\n InvalidManifestSectionError.make({ sectionKey: key, reason }),\n );\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\nconst render = Effect.fnUntraced(function* (\n { key, generate }: Claim,\n target: ManifestSection.Target,\n input: Pick<ManifestSection.GenerateInput, \"functions\" | \"mounts\" | \"files\">,\n watched: Set<string>,\n) {\n const confectDirectory = yield* ConfectDirectory.get;\n const failed = (cause: unknown) =>\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: `generate failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => Arr.filter(input.files, (file) => generate.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched);\n const { contents, errors } = yield* Effect.try({\n try: () => generate.render({ ...input, modules, target, confectDirectory }),\n catch: failed,\n });\n yield* refuse(key, errors);\n const sources = yield* encodeSources(matched);\n return {\n modules,\n contents: Arr.join([header(key), `// Sources: ${sources}`, contents], \"\\n\"),\n };\n});\n\n/**\n * The files in `confect/_generated` a section wrote, which carry its header.\n *\n * @internal\n */\nexport const written = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n if (!(yield* fs.exists(generated))) return [];\n const directory = yield* fs.readDirectory(generated);\n return yield* Effect.filter(\n Arr.filter(directory, (file) => pipe(file, Str.endsWith(\".ts\"))),\n (file) =>\n fs\n .readFileString(path.join(generated, file))\n .pipe(Effect.map((contents) => pipe(contents, Str.startsWith(PREFIX)))),\n );\n});\n\nconst record = Effect.fnUntraced(function* (name: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const file = path.join(confectDirectory, \"_generated\", name);\n const none: ReadonlyArray<string> = [];\n if (!(yield* fs.exists(file))) return none;\n const fileContents = yield* fs.readFileString(file);\n return Option.getOrElse(decodeSources(fileContents), () => none);\n});\n\n/**\n * The `confect/` files the declared sections' `generate` and `verify` matched\n * and the `confect/` files those import, as recorded by the last codegen run\n * that loaded them.\n *\n * @internal\n */\nexport const inputs = Effect.map(\n Effect.all([record(INPUTS), record(VERIFY_INPUTS)]),\n ([rendered, verified]) => [...new Set([...rendered, ...verified])].sort(),\n);\n\n/**\n * Write each claimed file into `confect/_generated` once every section the\n * declared backend names has rendered for its target; an undeclared backend\n * renders none. Every section renders before codegen fails with the first error\n * after logging the rest. The record of section inputs is written either way,\n * keeping the previous inputs after a failure, so `confect dev` sees the fix.\n * Returns the claimed file names, whether they differ from the section files\n * that existed before, the modules each section key matched, and the files of\n * the sections that wrap crons, in the order `App.make` declares them.\n *\n * @internal\n */\nexport const sync = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n leaves: ReadonlyArray<Leaf>,\n mounts: ManifestSection.GenerateInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n const claimed = Option.isSome(backend)\n ? yield* Effect.map(\n Effect.fromResult(claims(backend.value.sections)),\n Arr.map((claim) => ({ claim, target: backend.value.target })),\n )\n : [];\n const functions: Array<{ path: string; source: string }> = [];\n visit(leaves, (_, functionPath, source) =>\n functions.push({ path: functionPath, source }),\n );\n const files = claimed.length === 0 ? [] : yield* sourceFiles;\n const watched = new Set<string>();\n const [rendered, failures] = yield* Effect.partition(\n claimed,\n ({ claim, target }) =>\n render(claim, target, { functions, mounts, files }, watched).pipe(\n Effect.map((output) => ({ ...claim, ...output })),\n ),\n );\n if (failures.length > 0)\n for (const file of yield* record(INPUTS)) watched.add(file);\n yield* claimed.length === 0\n ? removePathIfExists(path.join(generated, INPUTS))\n : encodeSources([...watched].sort()).pipe(\n Effect.flatMap((sources) =>\n writeFileStringAndLog(path.join(generated, INPUTS), sources),\n ),\n );\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n const existing = yield* written;\n for (const { generate, contents } of rendered)\n yield* writeFileStringAndLog(path.join(generated, generate.file), contents);\n const names = Arr.map(rendered, ({ generate }) => generate.file);\n return {\n modules: new Map(Arr.map(rendered, ({ key, modules }) => [key, modules])),\n files: names,\n crons: Option.isNone(backend)\n ? []\n : Arr.flatMap(backend.value.sections, ({ section: { generate } }) =>\n generate?.wrapsCrons === true ? [generate.file] : [],\n ),\n changed:\n names.length !== existing.length ||\n Arr.some(names, (file) => !existing.includes(file)),\n };\n});\n\n/**\n * Run each declared section's `verify` once every `_generated` file exists:\n * bundle the `confect/` files its `match` selects as codegen bundles a\n * declaration, and hand their exports, the mounts and the target to its\n * `check`. Every section checks before codegen fails with the first refusal\n * after logging the rest. The files each loaded are recorded as section inputs,\n * keeping the previous ones after a failure, so `confect dev` checks again when\n * one changes.\n *\n * @internal\n */\nexport const verify = Effect.fnUntraced(function* (\n backend: Option.Option<Backend>,\n mounts: ManifestSection.VerifyInput[\"mounts\"],\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const recorded = path.join(confectDirectory, \"_generated\", VERIFY_INPUTS);\n const checks = Option.match(backend, {\n onNone: () => [],\n onSome: ({ sections }) =>\n Arr.flatMap(sections, ({ key, section }) =>\n section.generate?.verify === undefined\n ? []\n : [{ key, verifier: section.generate.verify }],\n ),\n });\n if (Option.isNone(backend) || checks.length === 0)\n return yield* removePathIfExists(recorded);\n const { target } = backend.value;\n const files = yield* sourceFiles;\n const watched = new Set<string>();\n const [, failures] = yield* Effect.partition(checks, ({ key, verifier }) =>\n Effect.gen(function* () {\n const failed = (cause: unknown) =>\n InvalidManifestSectionError.make({\n sectionKey: key,\n reason: `verify failed: ${String(cause)}`,\n });\n const matched = yield* Effect.try({\n try: () => Arr.filter(files, (file) => verifier.match(file)),\n catch: failed,\n });\n const modules = yield* load(matched, watched, [\n ConvexConfig.componentConfigPlugin(path),\n ]);\n const tryValue = yield* Effect.try({\n try: () => verifier.check({ modules, mounts, target }),\n catch: failed,\n });\n yield* refuse(key, tryValue);\n }),\n );\n if (failures.length > 0)\n for (const file of yield* record(VERIFY_INPUTS)) watched.add(file);\n const sources = yield* encodeSources([...watched].sort());\n yield* writeFileStringAndLog(recorded, sources);\n const [error, ...more] = failures;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n});\n\n/**\n * Remove each file a section wrote that is not in `files`. Codegen runs this\n * after it rewrites the registration files and the HTTP router, so a run that\n * fails earlier leaves no import of a removed file.\n *\n * @internal\n */\nexport const removeUnclaimed = Effect.fnUntraced(function* (\n files: ReadonlyArray<string>,\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const generated = path.join(confectDirectory, \"_generated\");\n for (const file of yield* written)\n if (!files.includes(file)) {\n yield* removePathIfExists(path.join(generated, file));\n yield* logFileRemoved(path.join(generated, file));\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,UAA+B,IAAI,IAC9C,IAAI,IACF,KACE;;4BAGA,IAAI,MAAM,KAAK,CACjB,IACC,SAAS,GAAG,KAAK,IACpB,CACF;AAEA,MAAM,SAAS;AACf,MAAM,UAAU,QAAgB,GAAG,SAAS,MAAM,GAAG,EAAE;AACvD,MAAM,UAAU,OAAO,OAAO,KAAK,OAAO,OAAO,OAAO,cAAc;AACtE,MAAM,iBAAiB,YACrB,OAAO,aAAa,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,OAAO,KAAK;AACzD,MAAM,gBAAgB,OAAO,oBAAoB,OAAO;AACxD,MAAM,SAAS;AACf,MAAM,gBAAgB;AAgBtB,MAAM,SACJ,QACA,SACG;CACH,MAAM,QACJ,OACA,MACA,WACG;EACH,KAAK,MAAM,QAAQ,OAAO,OAAO,MAAM,SAAS,GAC9C,KAAK,MAAM,GAAG,KAAK,GAAG,KAAK,QAAQ,MAAM;EAC3C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,UAAU,MAAM,MAAM,GACvD,KAAK,OAAO,GAAG,KAAK,GAAG,QAAQ,MAAM;CACzC;CACA,KAAK,MAAM,QAAQ,QACjB,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK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IAAI,IAAI;CACnE,MAAM,UAAU,OAAO,cAAc,CAAC,GAAG,OAAO,CAAC,CAAC,KAAK,CAAC;CACxD,OAAO,sBAAsB,UAAU,OAAO;CAC9C,MAAM,CAAC,OAAO,GAAG,QAAQ;CACzB,KAAK,MAAM,SAAS,MAAM,OAAO,gBAAgB,KAAK;CACtD,IAAI,UAAU,KAAA,GAAW,OAAO,OAAO;AACzC,CAAC;;;;;;;;AASD,MAAa,kBAAkB,OAAO,WAAW,WAC/C,OACA;CACA,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,mBAAmB,OAAO,iBAAiB;CACjD,MAAM,YAAY,KAAK,KAAK,kBAAkB,YAAY;CAC1D,KAAK,MAAM,QAAQ,OAAO,SACxB,IAAI,CAAC,MAAM,SAAS,IAAI,GAAG;EACzB,OAAO,mBAAmB,KAAK,KAAK,WAAW,IAAI,CAAC;EACpD,OAAO,eAAe,KAAK,KAAK,WAAW,IAAI,CAAC;CAClD;AACJ,CAAC"}
|
package/dist/SyncState.mjs
CHANGED
|
@@ -60,12 +60,12 @@ const add = (pending, entries, forceFull = false) => {
|
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
/**
|
|
63
|
-
* Full generation writes a declared backend's `convex/http.ts` and
|
|
63
|
+
* Full generation writes a declared backend's `convex/http.ts`, `crons.ts` and
|
|
64
64
|
* `auth.config.ts` and rejects a component's `auth.ts`, so those edits need it
|
|
65
65
|
* instead of the optional-file writers.
|
|
66
66
|
*/
|
|
67
67
|
const forBackend = (pending, backend) => {
|
|
68
|
-
const generated = HashSet.filter(pending.optional, (file) => Match.value(file).pipe(Match.when("Http", () => backend.declared), Match.when("Auth", () => backend.declared || backend.component), Match.when("Crons", () =>
|
|
68
|
+
const generated = HashSet.filter(pending.optional, (file) => Match.value(file).pipe(Match.when("Http", () => backend.declared), Match.when("Auth", () => backend.declared || backend.component), Match.when("Crons", () => backend.declared), Match.exhaustive));
|
|
69
69
|
if (HashSet.isEmpty(generated)) return pending;
|
|
70
70
|
return {
|
|
71
71
|
work: Work.Full(),
|
package/dist/SyncState.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncState.mjs","names":[],"sources":["../src/SyncState.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Match from \"effect/Match\";\nimport type { Declaration, Kind, OptionalFile } from \"./EntryPoint.js\";\nimport type { ImplModulePath } from \"./ImplModulePath.js\";\nimport type { GenerationSnapshot } from \"./GenerationSnapshot.js\";\n\nexport type Work = Data.TaggedEnum<{\n None: {};\n Reconcile: {};\n Full: {};\n Impls: { readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath> };\n Declarations: {\n readonly entries: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Work = Data.taggedEnum<Work>();\n\nexport interface Pending {\n readonly work: Work;\n readonly optional: HashSet.HashSet<OptionalFile>;\n}\n\nexport const empty: Pending = { work: Work.None(), optional: HashSet.empty() };\nexport const isDirty = (pending: Pending): boolean =>\n !Work.$is(\"None\")(pending.work) || !HashSet.isEmpty(pending.optional);\nexport const full = (pending: Pending): Pending => ({\n ...pending,\n work: Work.Full(),\n});\n\nexport const reconcile = (pending: Pending): Pending => ({\n ...pending,\n work: Work.$is(\"None\")(pending.work) ? Work.Reconcile() : pending.work,\n});\n\nexport const add = (\n pending: Pending,\n entries: ReadonlyArray<Kind>,\n forceFull: boolean = false,\n): Pending => {\n const next = Array.reduce(\n entries,\n {\n needsFull: forceFull || Work.$is(\"Full\")(pending.work),\n paths: Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n declarations: Work.$match(pending.work, {\n None: () => HashMap.empty<string, Declaration>(),\n Reconcile: () => HashMap.empty<string, Declaration>(),\n Full: () => HashMap.empty<string, Declaration>(),\n Impls: () => HashMap.empty<string, Declaration>(),\n Declarations: ({ entries: declarations }) =>\n HashMap.fromIterable(\n Array.map(\n declarations,\n (entry) =>\n [`${entry._tag}:${entry.relativePath}`, entry] as const,\n ),\n ),\n }),\n optional: pending.optional,\n },\n (state, entry) =>\n Match.value(entry).pipe(\n Match.tag(\"Impl\", ({ relativePath }) => ({\n ...state,\n paths: HashSet.add(state.paths, relativePath),\n })),\n Match.tag(\"Http\", \"Crons\", \"Auth\", ({ _tag }) => ({\n ...state,\n optional: HashSet.add(state.optional, _tag),\n })),\n Match.tag(\"Spec\", \"Table\", (declaration) => ({\n ...state,\n declarations: HashMap.set(\n state.declarations,\n `${declaration._tag}:${declaration.relativePath}`,\n declaration,\n ),\n })),\n Match.tag(\"Config\", \"Env\", \"App\", \"Callbacks\", \"Runtime\", () => ({\n ...state,\n needsFull: true,\n })),\n Match.exhaustive,\n ),\n );\n const impls = Array.fromIterable(next.paths);\n const declarations = next.declarations.pipe(\n HashMap.values,\n Array.fromIterable,\n );\n return {\n work: next.needsFull\n ? Work.Full()\n : Array.isReadonlyArrayNonEmpty(declarations)\n ? Work.Declarations({ entries: declarations, paths: impls })\n : Array.isReadonlyArrayNonEmpty(impls)\n ? Work.Impls({ paths: impls })\n : Work.$is(\"Reconcile\")(pending.work)\n ? Work.Reconcile()\n : Work.None(),\n optional: next.optional,\n };\n};\n\nexport interface Backend {\n readonly declared: boolean;\n readonly component: boolean;\n}\n\n/**\n * Full generation writes a declared backend's `convex/http.ts` and\n * `auth.config.ts` and rejects a component's `auth.ts`, so those edits need it\n * instead of the optional-file writers.\n */\nexport const forBackend = (pending: Pending, backend: Backend): Pending => {\n const generated = HashSet.filter(pending.optional, (file) =>\n Match.value(file).pipe(\n Match.when(\"Http\", () => backend.declared),\n Match.when(\"Auth\", () => backend.declared || backend.component),\n Match.when(\"Crons\", () => false),\n Match.exhaustive,\n ),\n );\n if (HashSet.isEmpty(generated)) return pending;\n return {\n work: Work.Full(),\n optional: backend.declared\n ? HashSet.difference(pending.optional, generated)\n : pending.optional,\n };\n};\n\nexport type Phase = Data.TaggedEnum<{\n Bootstrapping: {};\n NeedsFullSync: {};\n Incremental: {\n readonly failedImpls: HashSet.HashSet<ImplModulePath>;\n readonly snapshot: GenerationSnapshot;\n };\n}>;\nexport const Phase = Data.taggedEnum<Phase>();\n\nexport type Outcome = Data.TaggedEnum<{\n Succeeded: { readonly snapshot: GenerationSnapshot };\n GenerationFailed: {};\n ReconciliationFailed: {};\n ValidationFailed: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Outcome = Data.taggedEnum<Outcome>();\n\nexport const transition = (outcome: Outcome): Phase =>\n Outcome.$match(outcome, {\n Succeeded: ({ snapshot }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.empty(),\n }),\n GenerationFailed: () => Phase.NeedsFullSync(),\n ReconciliationFailed: () => Phase.NeedsFullSync(),\n ValidationFailed: ({ snapshot, paths }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.fromIterable(paths),\n }),\n });\n\nexport const shouldRetry = (phase: Phase, outcome: Outcome): boolean =>\n Phase.$is(\"Bootstrapping\")(phase) && Outcome.$is(\"GenerationFailed\")(outcome);\n\nexport const needsDeploymentNotification = (phase: Phase): boolean =>\n Phase.$match(phase, {\n Bootstrapping: () => true,\n NeedsFullSync: () => true,\n Incremental: ({ failedImpls }) => !HashSet.isEmpty(failedImpls),\n });\n\nexport const implsToValidate = (\n phase: Phase,\n pending: Pending,\n): ReadonlyArray<ImplModulePath> =>\n Array.fromIterable(\n HashSet.union(\n Phase.$match(phase, {\n Bootstrapping: () => HashSet.empty<ImplModulePath>(),\n NeedsFullSync: () => HashSet.empty<ImplModulePath>(),\n Incremental: ({ failedImpls }) => failedImpls,\n }),\n Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n ),\n );\n\nexport type Operation = Data.TaggedEnum<{\n Generate: {};\n Validate: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n Update: {\n readonly snapshot: GenerationSnapshot;\n readonly declarations: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Operation = Data.taggedEnum<Operation>();\n\nexport const plan = (phase: Phase, pending: Pending): Operation =>\n Phase.$match(phase, {\n Bootstrapping: () => Operation.Generate(),\n NeedsFullSync: () => Operation.Generate(),\n Incremental: (ready) =>\n Match.value(pending.work).pipe(\n Match.tag(\"Full\", () => Operation.Generate()),\n Match.tag(\"None\", \"Reconcile\", \"Impls\", () =>\n Operation.Validate({\n snapshot: ready.snapshot,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.tag(\"Declarations\", ({ entries }) =>\n Operation.Update({\n snapshot: ready.snapshot,\n declarations: entries,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.exhaustive,\n ),\n });\n"],"mappings":";;;;;;AAmBA,MAAa,OAAO,KAAK,WAAiB;AAO1C,MAAa,QAAiB;CAAE,MAAM,KAAK,KAAK;CAAG,UAAU,QAAQ,MAAM;AAAE;AAC7E,MAAa,WAAW,YACtB,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,QAAQ,QAAQ,QAAQ;AACtE,MAAa,QAAQ,aAA+B;CAClD,GAAG;CACH,MAAM,KAAK,KAAK;AAClB;AAEA,MAAa,aAAa,aAA+B;CACvD,GAAG;CACH,MAAM,KAAK,IAAI,MAAM,CAA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AAC,CAAC,KAAK,KAAK,QAAQ,IAAI,kBAAkB,CAAC,CAAC,OAAO;AAE9E,MAAa,+BAA+B,UAC1C,MAAM,OAAO,OAAO;CAClB,qBAAqB;CACrB,qBAAqB;CACrB,cAAc,EAAE,kBAAkB,CAAC,QAAQ,QAAQ,WAAW;AAChE,CAAC;AAEH,MAAa,mBACX,OACA,YAEA,MAAM,aACJ,QAAQ,MACN,MAAM,OAAO,OAAO;CAClB,qBAAqB,QAAQ,MAAsB;CACnD,qBAAqB,QAAQ,MAAsB;CACnD,cAAc,EAAE,kBAAkB;AACpC,CAAC,GACD,KAAK,OAAO,QAAQ,MAAM;CACxB,YAAY,QAAQ,MAAsB;CAC1C,iBAAiB,QAAQ,MAAsB;CAC/C,YAAY,QAAQ,MAAsB;CAC1C,QAAQ,EAAE,YAAY,QAAQ,aAAa,KAAK;CAChD,eAAe,EAAE,YAAY,QAAQ,aAAa,KAAK;AACzD,CAAC,CACH,CACF;AAcF,MAAa,YAAY,KAAK,WAAsB;AAEpD,MAAa,QAAQ,OAAc,YACjC,MAAM,OAAO,OAAO;CAClB,qBAAqB,UAAU,SAAS;CACxC,qBAAqB,UAAU,SAAS;CACxC,cAAc,UACZ,MAAM,MAAM,QAAQ,IAAI,CAAC,CAAC,KACxB,MAAM,IAAI,cAAc,UAAU,SAAS,CAAC,GAC5C,MAAM,IAAI,QAAQ,aAAa,eAC7B,UAAU,SAAS;EACjB,UAAU,MAAM;EAChB,OAAO,gBAAgB,OAAO,OAAO;CACvC,CAAC,CACH,GACA,MAAM,IAAI,iBAAiB,EAAE,cAC3B,UAAU,OAAO;EACf,UAAU,MAAM;EAChB,cAAc;EACd,OAAO,gBAAgB,OAAO,OAAO;CACvC,CAAC,CACH,GACA,MAAM,UACR;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"SyncState.mjs","names":[],"sources":["../src/SyncState.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Match from \"effect/Match\";\nimport type { Declaration, Kind, OptionalFile } from \"./EntryPoint.js\";\nimport type { ImplModulePath } from \"./ImplModulePath.js\";\nimport type { GenerationSnapshot } from \"./GenerationSnapshot.js\";\n\nexport type Work = Data.TaggedEnum<{\n None: {};\n Reconcile: {};\n Full: {};\n Impls: { readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath> };\n Declarations: {\n readonly entries: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Work = Data.taggedEnum<Work>();\n\nexport interface Pending {\n readonly work: Work;\n readonly optional: HashSet.HashSet<OptionalFile>;\n}\n\nexport const empty: Pending = { work: Work.None(), optional: HashSet.empty() };\nexport const isDirty = (pending: Pending): boolean =>\n !Work.$is(\"None\")(pending.work) || !HashSet.isEmpty(pending.optional);\nexport const full = (pending: Pending): Pending => ({\n ...pending,\n work: Work.Full(),\n});\n\nexport const reconcile = (pending: Pending): Pending => ({\n ...pending,\n work: Work.$is(\"None\")(pending.work) ? Work.Reconcile() : pending.work,\n});\n\nexport const add = (\n pending: Pending,\n entries: ReadonlyArray<Kind>,\n forceFull: boolean = false,\n): Pending => {\n const next = Array.reduce(\n entries,\n {\n needsFull: forceFull || Work.$is(\"Full\")(pending.work),\n paths: Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n declarations: Work.$match(pending.work, {\n None: () => HashMap.empty<string, Declaration>(),\n Reconcile: () => HashMap.empty<string, Declaration>(),\n Full: () => HashMap.empty<string, Declaration>(),\n Impls: () => HashMap.empty<string, Declaration>(),\n Declarations: ({ entries: declarations }) =>\n HashMap.fromIterable(\n Array.map(\n declarations,\n (entry) =>\n [`${entry._tag}:${entry.relativePath}`, entry] as const,\n ),\n ),\n }),\n optional: pending.optional,\n },\n (state, entry) =>\n Match.value(entry).pipe(\n Match.tag(\"Impl\", ({ relativePath }) => ({\n ...state,\n paths: HashSet.add(state.paths, relativePath),\n })),\n Match.tag(\"Http\", \"Crons\", \"Auth\", ({ _tag }) => ({\n ...state,\n optional: HashSet.add(state.optional, _tag),\n })),\n Match.tag(\"Spec\", \"Table\", (declaration) => ({\n ...state,\n declarations: HashMap.set(\n state.declarations,\n `${declaration._tag}:${declaration.relativePath}`,\n declaration,\n ),\n })),\n Match.tag(\"Config\", \"Env\", \"App\", \"Callbacks\", \"Runtime\", () => ({\n ...state,\n needsFull: true,\n })),\n Match.exhaustive,\n ),\n );\n const impls = Array.fromIterable(next.paths);\n const declarations = next.declarations.pipe(\n HashMap.values,\n Array.fromIterable,\n );\n return {\n work: next.needsFull\n ? Work.Full()\n : Array.isReadonlyArrayNonEmpty(declarations)\n ? Work.Declarations({ entries: declarations, paths: impls })\n : Array.isReadonlyArrayNonEmpty(impls)\n ? Work.Impls({ paths: impls })\n : Work.$is(\"Reconcile\")(pending.work)\n ? Work.Reconcile()\n : Work.None(),\n optional: next.optional,\n };\n};\n\nexport interface Backend {\n readonly declared: boolean;\n readonly component: boolean;\n}\n\n/**\n * Full generation writes a declared backend's `convex/http.ts`, `crons.ts` and\n * `auth.config.ts` and rejects a component's `auth.ts`, so those edits need it\n * instead of the optional-file writers.\n */\nexport const forBackend = (pending: Pending, backend: Backend): Pending => {\n const generated = HashSet.filter(pending.optional, (file) =>\n Match.value(file).pipe(\n Match.when(\"Http\", () => backend.declared),\n Match.when(\"Auth\", () => backend.declared || backend.component),\n Match.when(\"Crons\", () => backend.declared),\n Match.exhaustive,\n ),\n );\n if (HashSet.isEmpty(generated)) return pending;\n return {\n work: Work.Full(),\n optional: backend.declared\n ? HashSet.difference(pending.optional, generated)\n : pending.optional,\n };\n};\n\nexport type Phase = Data.TaggedEnum<{\n Bootstrapping: {};\n NeedsFullSync: {};\n Incremental: {\n readonly failedImpls: HashSet.HashSet<ImplModulePath>;\n readonly snapshot: GenerationSnapshot;\n };\n}>;\nexport const Phase = Data.taggedEnum<Phase>();\n\nexport type Outcome = Data.TaggedEnum<{\n Succeeded: { readonly snapshot: GenerationSnapshot };\n GenerationFailed: {};\n ReconciliationFailed: {};\n ValidationFailed: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: Array.NonEmptyReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Outcome = Data.taggedEnum<Outcome>();\n\nexport const transition = (outcome: Outcome): Phase =>\n Outcome.$match(outcome, {\n Succeeded: ({ snapshot }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.empty(),\n }),\n GenerationFailed: () => Phase.NeedsFullSync(),\n ReconciliationFailed: () => Phase.NeedsFullSync(),\n ValidationFailed: ({ snapshot, paths }) =>\n Phase.Incremental({\n snapshot,\n failedImpls: HashSet.fromIterable(paths),\n }),\n });\n\nexport const shouldRetry = (phase: Phase, outcome: Outcome): boolean =>\n Phase.$is(\"Bootstrapping\")(phase) && Outcome.$is(\"GenerationFailed\")(outcome);\n\nexport const needsDeploymentNotification = (phase: Phase): boolean =>\n Phase.$match(phase, {\n Bootstrapping: () => true,\n NeedsFullSync: () => true,\n Incremental: ({ failedImpls }) => !HashSet.isEmpty(failedImpls),\n });\n\nexport const implsToValidate = (\n phase: Phase,\n pending: Pending,\n): ReadonlyArray<ImplModulePath> =>\n Array.fromIterable(\n HashSet.union(\n Phase.$match(phase, {\n Bootstrapping: () => HashSet.empty<ImplModulePath>(),\n NeedsFullSync: () => HashSet.empty<ImplModulePath>(),\n Incremental: ({ failedImpls }) => failedImpls,\n }),\n Work.$match(pending.work, {\n None: () => HashSet.empty<ImplModulePath>(),\n Reconcile: () => HashSet.empty<ImplModulePath>(),\n Full: () => HashSet.empty<ImplModulePath>(),\n Impls: ({ paths }) => HashSet.fromIterable(paths),\n Declarations: ({ paths }) => HashSet.fromIterable(paths),\n }),\n ),\n );\n\nexport type Operation = Data.TaggedEnum<{\n Generate: {};\n Validate: {\n readonly snapshot: GenerationSnapshot;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n Update: {\n readonly snapshot: GenerationSnapshot;\n readonly declarations: Array.NonEmptyReadonlyArray<Declaration>;\n readonly paths: ReadonlyArray<ImplModulePath>;\n };\n}>;\nexport const Operation = Data.taggedEnum<Operation>();\n\nexport const plan = (phase: Phase, pending: Pending): Operation =>\n Phase.$match(phase, {\n Bootstrapping: () => Operation.Generate(),\n NeedsFullSync: () => Operation.Generate(),\n Incremental: (ready) =>\n Match.value(pending.work).pipe(\n Match.tag(\"Full\", () => Operation.Generate()),\n Match.tag(\"None\", \"Reconcile\", \"Impls\", () =>\n Operation.Validate({\n snapshot: ready.snapshot,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.tag(\"Declarations\", ({ entries }) =>\n Operation.Update({\n snapshot: ready.snapshot,\n declarations: entries,\n paths: implsToValidate(ready, pending),\n }),\n ),\n Match.exhaustive,\n ),\n });\n"],"mappings":";;;;;;AAmBA,MAAa,OAAO,KAAK,WAAiB;AAO1C,MAAa,QAAiB;CAAE,MAAM,KAAK,KAAK;CAAG,UAAU,QAAQ,MAAM;AAAE;AAC7E,MAAa,WAAW,YACtB,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,QAAQ,QAAQ,QAAQ;AACtE,MAAa,QAAQ,aAA+B;CAClD,GAAG;CACH,MAAM,KAAK,KAAK;AAClB;AAEA,MAAa,aAAa,aAA+B;CACvD,GAAG;CACH,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,QAAQ,IAAI,IAAI,KAAK,UAAU,IAAI,QAAQ;AACpE;AAEA,MAAa,OACX,SACA,SACA,YAAqB,UACT;CACZ,MAAM,OAAO,MAAM,OACjB,SACA;EACE,WAAW,aAAa,KAAK,IAAI,MAAM,CAAC,CAAC,QAAQ,IAAI;EACrD,O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