@gaganref/confect-cli 10.3.1-fork.9 → 10.3.1-fork.91
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/Bundler.mjs +22 -1
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodegenError.mjs +16 -1
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/Declaration.mjs +139 -26
- package/dist/Declaration.mjs.map +1 -1
- package/dist/EntryPoint.mjs +2 -0
- package/dist/EntryPoint.mjs.map +1 -1
- package/dist/Evaluation.mjs +39 -13
- package/dist/Evaluation.mjs.map +1 -1
- package/dist/EvaluationWorker.mjs +13 -1
- package/dist/EvaluationWorker.mjs.map +1 -1
- package/dist/FunctionModule.mjs +109 -24
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/LeafModule.mjs +56 -23
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ManifestSections.mjs +161 -0
- package/dist/ManifestSections.mjs.map +1 -0
- package/dist/SectionFiles.mjs +264 -0
- package/dist/SectionFiles.mjs.map +1 -0
- package/dist/SyncState.mjs +1 -1
- package/dist/SyncState.mjs.map +1 -1
- package/dist/TableModule.mjs +2 -1
- package/dist/TableModule.mjs.map +1 -1
- package/dist/Watcher.mjs +13 -7
- package/dist/Watcher.mjs.map +1 -1
- package/dist/confect/codegen.mjs +124 -42
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/declaration.mjs +160 -20
- package/dist/confect/declaration.mjs.map +1 -1
- package/dist/confect/dev.mjs +9 -4
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/templates.mjs +74 -43
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +14 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin","Declaration.isGenerated","Bundler.resolveModule","ConvexConfig.componentImportOf","Declaration.parse","Declaration.fileOf","ConvexConfig.CONVEX_CONFIG_FILENAME","templates.authConfig","digest","Declaration.digest","Declaration.manifest","Declaration.convexConfig","Declaration.authConfig","templates.http","http","templates.declaredHttp"],"sources":["../../src/confect/declaration.ts"],"sourcesContent":["import { App, Http } from \"@confect/core\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"../BuildError.js\";\nimport * as Bundler from \"../Bundler.js\";\nimport {\n HandWrittenConvexFileError,\n DeclarationKindMismatchError,\n InvalidDeclarationError,\n} from \"../CodegenError.js\";\nimport { ConfectDirectory } from \"../ConfectDirectory.js\";\nimport * as ConvexConfig from \"../ConvexConfig.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as Declaration from \"../Declaration.js\";\nimport { logFileRemoved } from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport * as templates from \"../templates.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n writeFileString,\n writeFileStringAndLog,\n} from \"../utils.js\";\n\n/**\n * Bumped when the generated files change shape, so a manifest written by an\n * older generator never matches a current one.\n */\nconst GENERATOR_FORMAT = \"1\";\n\nconst confectPath = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, file);\n});\n\n/**\n * A backend opts in to the declaration by writing `confect/app.ts`.\n */\nexport const isDeclared = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n return yield* fs.exists(yield* confectPath(\"app.ts\"));\n});\n\nconst displayPath = Effect.fnUntraced(function* (absolutePath: string) {\n const path = yield* Path.Path;\n return toPosixPath(path, path.relative(yield* ProjectRoot.get, absolutePath));\n});\n\nconst bundleDeclaration = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n const absolutePath = yield* confectPath(file);\n return yield* Bundler.bundle(absolutePath, {\n plugins: [ConvexConfig.componentConfigPlugin(path)],\n }).pipe(\n Effect.mapError((error) => fromBundlerError(`confect/${file}`, error)),\n );\n});\n\nconst invalid = (file: string) => (error: { readonly message: string }) =>\n new InvalidDeclarationError({\n declarationPath: `confect/${file}`,\n reason: error.message,\n });\n\n/**\n * Fail instead of overwriting a Convex file someone wrote by hand. A file with\n * the generated header, or one of the exact files an earlier codegen wrote\n * there, is ours to replace.\n */\nconst assertOwned = Effect.fnUntraced(function* (\n convexPath: string,\n declarationFile: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(convexPath))) return;\n if (Declaration.isGenerated(yield* fs.readFileString(convexPath), legacy)) {\n return;\n }\n return yield* new HandWrittenConvexFileError({\n convexPath: yield* displayPath(convexPath),\n declarationPath: `confect/${declarationFile}`,\n });\n});\n\nconst decodeVersion = Schema.decodeUnknownOption(\n Schema.fromJsonString(Schema.Struct({ version: Schema.String })),\n);\n\nconst packageVersion = Effect.fnUntraced(function* (\n name: string,\n from: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n return yield* Option.match(\n Bundler.resolveModule(`${name}/package.json`, path.join(from, \"_\")),\n {\n onNone: () => Effect.succeed(\"unresolved\"),\n onSome: (packageJson) =>\n fs.readFileString(packageJson).pipe(\n Effect.map((contents) =>\n Option.match(decodeVersion(contents), {\n onNone: () => \"unknown\",\n onSome: ({ version }) => version,\n }),\n ),\n ),\n },\n );\n});\n\n/**\n * Every first-party file the declaration modules import, by project-relative\n * path and contents. Files under `node_modules` and outside the project count\n * through package versions instead, so rebuilding a dependency does not change\n * the digest.\n */\nconst declarationInputs = Effect.fnUntraced(function* (\n bundles: ReadonlyArray<Bundler.Bundled>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const projectRoot = yield* ProjectRoot.get;\n const files = new Set<string>();\n for (const { metafile } of bundles) {\n for (const input of Object.keys(metafile.inputs)) {\n const relative = path.relative(projectRoot, input);\n if (\n path.isAbsolute(input) &&\n !relative.startsWith(\"..\") &&\n !relative.split(path.sep).includes(\"node_modules\")\n ) {\n files.add(input);\n }\n }\n }\n // Plugin namespaces (component config wrappers) appear as inputs too;\n // only real files count.\n const real = yield* Effect.filter([...files], (file) => fs.exists(file));\n return yield* Effect.forEach(real, (file) =>\n fs\n .readFileString(file)\n .pipe(\n Effect.map(\n (contents) =>\n [\n toPosixPath(path, path.relative(projectRoot, file)),\n contents,\n ] as const,\n ),\n ),\n );\n});\n\nconst componentImport = Effect.fnUntraced(function* () {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n return (definition: unknown): Option.Option<Declaration.ComponentImport> =>\n Option.map(ConvexConfig.componentImportOf(definition), (recorded) => {\n const bare =\n !recorded.specifier.startsWith(\".\") &&\n !path.isAbsolute(recorded.specifier);\n const relative = toPosixPath(\n path,\n path.relative(convexDirectory, recorded.path),\n ).replace(/\\.([cm]?)[jt]s$/, \".$1js\");\n return {\n importPath: bare\n ? recorded.specifier\n : relative.startsWith(\".\")\n ? relative\n : `./${relative}`,\n componentName:\n Predicate.hasProperty(definition, \"defaultName\") &&\n Predicate.isString(definition.defaultName)\n ? definition.defaultName\n : \"component\",\n };\n });\n});\n\nconst manifestPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, \"_generated\", \"manifest.ts\");\n});\n\n/**\n * Remove a file codegen wrote whose source is gone; leave anything else.\n */\nconst removeGenerated = Effect.fnUntraced(function* (\n filePath: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(filePath))) return;\n if (!Declaration.isGenerated(yield* fs.readFileString(filePath), legacy)) {\n return;\n }\n yield* removePathIfExists(filePath);\n yield* logFileRemoved(filePath);\n});\n\nconst removeManifest = Effect.gen(function* () {\n yield* removeGenerated(yield* manifestPath, []);\n});\n\nconst writeDeclaration = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const target = (yield* ConvexDirectory.target).kind;\n\n const app = yield* bundleDeclaration(\"app.ts\");\n const appValue: unknown = app.module.default;\n if (App.isApp(appValue) && appValue.kind !== target) {\n return yield* new DeclarationKindMismatchError({\n declarationPath: \"confect/app.ts\",\n declaredKind: appValue.kind,\n targetKind: target,\n });\n }\n const authPath = yield* confectPath(\"auth.ts\");\n const auth = (yield* fs.exists(authPath))\n ? Option.some(yield* bundleDeclaration(\"auth.ts\"))\n : Option.none();\n\n const declaration = yield* Declaration.parse({\n target,\n app: app.module.default,\n auth: Option.map(auth, ({ module }) => module.default),\n componentImport: yield* componentImport(),\n }).pipe(\n Result.mapError(\n (error) =>\n new InvalidDeclarationError({\n declarationPath: Declaration.fileOf(error),\n reason: error.message,\n }),\n ),\n Effect.fromResult,\n );\n\n const convexConfigPath = path.join(\n convexDirectory,\n ConvexConfig.CONVEX_CONFIG_FILENAME,\n );\n const authConfigPath = path.join(convexDirectory, \"auth.config.ts\");\n const authImportPath = yield* toModuleImportPath(\n path.relative(convexDirectory, authPath),\n );\n const legacyAuthConfigs = yield* Effect.forEach(\n [authImportPath, authImportPath.replace(/\\.js$/, \"\")],\n (importPath) => templates.authConfig({ authImportPath: importPath }),\n );\n yield* assertOwned(convexConfigPath, \"app.ts\", []);\n yield* assertOwned(authConfigPath, \"auth.ts\", legacyAuthConfigs);\n\n if (target === \"app\") {\n const digest = Declaration.digest({\n files: yield* declarationInputs([app, ...Option.toArray(auth)]),\n versions: [\n [\"convex\", yield* packageVersion(\"convex\", projectRoot)],\n [\"@confect/cli generator format\", GENERATOR_FORMAT],\n ],\n });\n yield* writeFileStringAndLog(\n yield* manifestPath,\n Declaration.manifest(declaration, digest),\n );\n }\n yield* writeFileStringAndLog(\n convexConfigPath,\n Declaration.convexConfig(declaration),\n );\n yield* Option.match(declaration.providers, {\n onNone: () =>\n Effect.gen(function* () {\n if (yield* fs.exists(authConfigPath)) {\n yield* removePathIfExists(authConfigPath);\n yield* logFileRemoved(authConfigPath);\n }\n }),\n onSome: (providers) =>\n writeFileStringAndLog(authConfigPath, Declaration.authConfig(providers)),\n });\n return App.isApp(appValue) ? Option.some(appValue) : Option.none<App.Any>();\n});\n\n/**\n * Write the declaration's Convex files and manifest from `confect/app.ts`,\n * `confect/env.ts` and `confect/auth.ts`, before anything else is validated. On\n * any failure the previous manifest is removed, so a stale manifest never\n * outlives a declaration that no longer produces it.\n */\nexport const syncDeclaration = Effect.gen(function* () {\n if (!(yield* isDeclared)) {\n yield* removeManifest;\n return Option.none<App.Any>();\n }\n return yield* writeDeclaration.pipe(Effect.tapError(() => removeManifest));\n});\n\n/**\n * Check every HTTP route the backend serves and write `convex/http.ts` from\n * `confect/http.ts`. Runs after generation, because `http.ts` imports its\n * handlers, which import generated services.\n */\nexport const syncDeclaredHttp = (app: App.Any) =>\n checkAndWriteHttp(app).pipe(Effect.tapError(() => removeManifest));\n\nconst checkAndWriteHttp = Effect.fnUntraced(function* (app: App.Any) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const confectDirectory = yield* ConfectDirectory.get;\n const httpPath = yield* confectPath(\"http.ts\");\n\n const convexHttpPath = path.join(convexDirectory, \"http.ts\");\n if (!(yield* fs.exists(httpPath))) {\n yield* Http.routes(app).pipe(\n Result.mapError(invalid(\"app.ts\")),\n Effect.fromResult,\n );\n yield* removeGenerated(convexHttpPath, [\n yield* templates.http({\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n }),\n ]);\n return Option.none();\n }\n\n const http = (yield* bundleDeclaration(\"http.ts\")).module.default;\n if (!Http.isHttp(http)) {\n return yield* new InvalidDeclarationError({\n declarationPath: \"confect/http.ts\",\n reason: \"it must default-export Http.make(...).\",\n });\n }\n yield* Http.routes(app, http).pipe(\n Result.mapError(invalid(\"http.ts\")),\n Effect.fromResult,\n );\n\n const contents = yield* templates.declaredHttp({\n schemaImportPath: yield* toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"_generated\", \"schema.ts\"),\n ),\n ),\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n });\n const change = yield* writeFileString(convexHttpPath, contents);\n return Option.some({ change, convexFilePath: convexHttpPath });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,mBAAmB;AAEzB,MAAM,cAAc,OAAO,WAAW,WAAW,MAAc;CAE7D,QAAO,OADa,KAAK,KAAA,CACb,KAAK,OAAO,iBAAiB,KAAK,IAAI;AACpD,CAAC;;;;AAKD,MAAa,aAAa,OAAO,IAAI,aAAa;CAEhD,OAAO,QAAO,OADI,WAAW,WAAA,CACZ,OAAO,OAAO,YAAY,QAAQ,CAAC;AACtD,CAAC;AAED,MAAM,cAAc,OAAO,WAAW,WAAW,cAAsB;CACrE,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,YAAY,MAAM,KAAK,SAAS,OAAO,YAAY,KAAK,YAAY,CAAC;AAC9E,CAAC;AAED,MAAM,oBAAoB,OAAO,WAAW,WAAW,MAAc;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,eAAe,OAAO,YAAY,IAAI;CAC5C,OAAO,OAAOA,OAAe,cAAc,EACzC,SAAS,CAACC,sBAAmC,IAAI,CAAC,EACpD,CAAC,CAAC,CAAC,KACD,OAAO,UAAU,UAAU,iBAAiB,WAAW,QAAQ,KAAK,CAAC,CACvE;AACF,CAAC;AAED,MAAM,WAAW,UAAkB,UACjC,IAAI,wBAAwB;CAC1B,iBAAiB,WAAW;CAC5B,QAAQ,MAAM;AAChB,CAAC;;;;;;AAOH,MAAM,cAAc,OAAO,WAAW,WACpC,YACA,iBACA,QACA;CACA,MAAM,KAAK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;CAC3D,IAAI,EAAE,OAAO,GAAG,OAAO,QAAQ,IAAI;EACjC,OAAO,KAAK,OAAO,GAAG,CAAC,CAAC,KACtB,OAAO,SAAS,QAAQ,QAAQ,CAAC,GACjC,OAAO,UACT;EACA,OAAO,gBAAgB,gBAAgB,CACrC,OAAOC,KAAe,EACpB,gBAAgB,OAAO,mBACrB,KAAK,SAAS,iBAAiB,QAAQ,CACzC,EACF,CAAC,CACH,CAAC;EACD,OAAO,OAAO,KAAK;CACrB;CAEA,MAAMC,UAAQ,OAAO,kBAAkB,SAAS,EAAA,CAAG,OAAO;CAC1D,IAAI,CAAC,KAAK,OAAOA,MAAI,GACnB,OAAO,OAAO,IAAI,wBAAwB;EACxC,iBAAiB;EACjB,QAAQ;CACV,CAAC;CAEH,OAAO,KAAK,OAAO,KAAKA,MAAI,CAAC,CAAC,KAC5B,OAAO,SAAS,QAAQ,SAAS,CAAC,GAClC,OAAO,UACT;CAEA,MAAM,WAAW,OAAOC,aAAuB;EAC7C,kBAAkB,OAAO,mBACvB,KAAK,SACH,iBACA,KAAK,KAAK,kBAAkB,cAAc,WAAW,CACvD,CACF;EACA,gBAAgB,OAAO,mBACrB,KAAK,SAAS,iBAAiB,QAAQ,CACzC;CACF,CAAC;CACD,MAAM,SAAS,OAAO,gBAAgB,gBAAgB,QAAQ;CAC9D,OAAO,OAAO,KAAK;EAAE;EAAQ,gBAAgB;CAAe,CAAC;AAC/D,CAAC"}
|
|
1
|
+
{"version":3,"file":"declaration.mjs","names":["Bundler.bundle","ConvexConfig.componentConfigPlugin","Declaration.isGenerated","Bundler.resolveModule","ConvexConfig.componentImportOf","Declaration.digest","ManifestSections.collect","ManifestSections.summarize","ManifestSections.check","Declaration.renderManifest","Declaration.parse","Declaration.fileOf","ManifestSections.declared","ConvexConfig.CONVEX_CONFIG_FILENAME","templates.authConfig","digest","sections","ManifestSections.sections","Declaration.manifest","Declaration.convexConfig","Declaration.authConfig","Declaration.authProviders","templates.http","http","templates.declaredHttp","ConvexConfig.resolveDefinition","ConvexConfig.discoverInstalledComponents"],"sources":["../../src/confect/declaration.ts"],"sourcesContent":["import { App, Http, Mount, type ManifestSection } from \"@confect/core\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport { fromBundlerError } from \"../BuildError.js\";\nimport * as Bundler from \"../Bundler.js\";\nimport {\n HandWrittenConvexFileError,\n DeclarationKindMismatchError,\n InvalidDeclarationError,\n logCodegenError,\n} from \"../CodegenError.js\";\nimport { ConfectDirectory } from \"../ConfectDirectory.js\";\nimport * as ConvexConfig from \"../ConvexConfig.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as Declaration from \"../Declaration.js\";\nimport * as ManifestSections from \"../ManifestSections.js\";\nimport type { LoadedLeafModule } from \"../LeafModule.js\";\nimport type * as SectionFiles from \"../SectionFiles.js\";\nimport { logWarn, logFileRemoved } from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport * as templates from \"../templates.js\";\nimport {\n removePathIfExists,\n toModuleImportPath,\n toPosixPath,\n writeFileString,\n writeFileStringAndLog,\n} from \"../utils.js\";\n\n/**\n * Bumped when the generated files change shape, so a manifest written by an\n * older generator never matches a current one.\n */\nconst GENERATOR_FORMAT = \"2\";\n\nconst confectPath = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, file);\n});\n\n/**\n * A backend opts in to the declaration by writing `confect/app.ts`.\n */\nexport const isDeclared = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n return yield* fs.exists(yield* confectPath(\"app.ts\"));\n});\n\nconst displayPath = Effect.fnUntraced(function* (absolutePath: string) {\n const path = yield* Path.Path;\n return toPosixPath(path, path.relative(yield* ProjectRoot.get, absolutePath));\n});\n\nconst bundleDeclaration = Effect.fnUntraced(function* (file: string) {\n const path = yield* Path.Path;\n const absolutePath = yield* confectPath(file);\n return yield* Bundler.bundle(absolutePath, {\n plugins: [ConvexConfig.componentConfigPlugin(path)],\n }).pipe(\n Effect.mapError((error) => fromBundlerError(`confect/${file}`, error)),\n );\n});\n\nconst invalid = (file: string) => (error: { readonly message: string }) =>\n new InvalidDeclarationError({\n declarationPath: `confect/${file}`,\n reason: error.message,\n });\n\n/**\n * Fail instead of overwriting a Convex file someone wrote by hand. A file with\n * the generated header, or one of the exact files an earlier codegen wrote\n * there, is ours to replace.\n */\nconst assertOwned = Effect.fnUntraced(function* (\n convexPath: string,\n declarationFile: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(convexPath))) return;\n if (Declaration.isGenerated(yield* fs.readFileString(convexPath), legacy)) {\n return;\n }\n return yield* new HandWrittenConvexFileError({\n convexPath: yield* displayPath(convexPath),\n declarationPath: `confect/${declarationFile}`,\n });\n});\n\nconst decodeVersion = Schema.decodeUnknownOption(\n Schema.fromJsonString(Schema.Struct({ version: Schema.String })),\n);\n\nconst packageVersion = Effect.fnUntraced(function* (\n name: string,\n from: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n return yield* Option.match(\n Bundler.resolveModule(`${name}/package.json`, path.join(from, \"_\")),\n {\n onNone: () => Effect.succeed(\"unresolved\"),\n onSome: (packageJson) =>\n fs.readFileString(packageJson).pipe(\n Effect.map((contents) =>\n Option.match(decodeVersion(contents), {\n onNone: () => \"unknown\",\n onSome: ({ version }) => version,\n }),\n ),\n ),\n },\n );\n});\n\n/**\n * Every first-party file the declaration modules import, by project-relative\n * path and contents. Files under `node_modules` and outside the project count\n * through package versions instead, so rebuilding a dependency does not change\n * the digest. The components registry is left out: codegen derives it from the\n * `convex.config.ts` this declaration writes, so its inputs are already here,\n * and a first run bundles a provisional registry that the real one replaces.\n */\nconst declarationInputs = Effect.fnUntraced(function* (\n bundles: ReadonlyArray<Bundler.Bundled>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const projectRoot = yield* ProjectRoot.get;\n const registry = path.join(\n yield* ConfectDirectory.get,\n \"_generated\",\n \"components.ts\",\n );\n const files = new Set<string>();\n for (const { metafile } of bundles) {\n for (const input of Object.keys(metafile.inputs)) {\n const relative = path.relative(projectRoot, input);\n if (\n path.isAbsolute(input) &&\n !relative.startsWith(\"..\") &&\n !relative.split(path.sep).includes(\"node_modules\") &&\n path.resolve(input) !== registry\n ) {\n files.add(input);\n }\n }\n }\n // Plugin namespaces (component config wrappers) appear as inputs too;\n // only real files count.\n const real = yield* Effect.filter([...files], (file) => fs.exists(file));\n return yield* Effect.forEach(real, (file) =>\n fs\n .readFileString(file)\n .pipe(\n Effect.map(\n (contents) =>\n [\n toPosixPath(path, path.relative(projectRoot, file)),\n contents,\n ] as const,\n ),\n ),\n );\n});\n\nconst componentImport = Effect.fnUntraced(function* () {\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n return (definition: unknown): Option.Option<Declaration.ComponentImport> =>\n Option.map(ConvexConfig.componentImportOf(definition), (recorded) => {\n const bare =\n !recorded.specifier.startsWith(\".\") &&\n !path.isAbsolute(recorded.specifier);\n const relative = toPosixPath(\n path,\n path.relative(convexDirectory, recorded.path),\n ).replace(/\\.([cm]?)[jt]s$/, \".$1js\");\n return {\n importPath: bare\n ? recorded.specifier\n : relative.startsWith(\".\")\n ? relative\n : `./${relative}`,\n componentName:\n Predicate.hasProperty(definition, \"defaultName\") &&\n Predicate.isString(definition.defaultName)\n ? definition.defaultName\n : \"component\",\n };\n });\n});\n\nconst manifestPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n return path.join(yield* ConfectDirectory.get, \"_generated\", \"manifest.ts\");\n});\n\n/**\n * Remove a file codegen wrote whose source is gone; leave anything else.\n */\nconst removeGenerated = Effect.fnUntraced(function* (\n filePath: string,\n legacy: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n if (!(yield* fs.exists(filePath))) return;\n if (!Declaration.isGenerated(yield* fs.readFileString(filePath), legacy)) {\n return;\n }\n yield* removePathIfExists(filePath);\n yield* logFileRemoved(filePath);\n});\n\nconst removeManifest = Effect.gen(function* () {\n yield* removeGenerated(yield* manifestPath, []);\n});\n\nconst readManifest = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const file = yield* manifestPath;\n if (!(yield* fs.exists(file))) return {} as Record<string, unknown>;\n const data: unknown = (yield* Bundler.bundle(file).pipe(\n Effect.mapError((error) =>\n fromBundlerError(\"confect/_generated/manifest.ts\", error),\n ),\n )).module.default;\n return Predicate.isObject(data) ? data : {};\n});\n\nexport const readPrevious = readManifest.pipe(\n Effect.orElseSucceed(() => ({}) as Record<string, unknown>),\n);\n\nconst sectionDigest = (\n base: string,\n sections: Readonly<Record<string, unknown>>,\n) =>\n Object.keys(sections).length === 0\n ? base\n : Declaration.digest({\n files: [[\"declaration\", base]],\n versions: [],\n sections,\n });\n\nexport const syncManifestSections = Effect.fnUntraced(\n function* (\n declared: ReadonlyArray<ManifestSection.Entry>,\n leaves: ReadonlyArray<LoadedLeafModule>,\n previous: Readonly<Record<string, unknown>>,\n baseDigest: string | undefined,\n modules: ReadonlyMap<string, ManifestSection.GenerateInput[\"modules\"]>,\n ) {\n if (baseDigest === undefined) return;\n const current = yield* readManifest;\n const registry = yield* Effect.fromResult(\n ManifestSections.collect(declared, leaves).pipe(\n Result.flatMap((described) =>\n ManifestSections.summarize(described, modules),\n ),\n ),\n );\n const checked = ManifestSections.check(registry, previous);\n for (const note of checked.notes) yield* logWarn(note);\n const [error, ...more] = checked.errors;\n for (const other of more) yield* logCodegenError(other);\n if (error !== undefined) return yield* error;\n const sections = Object.fromEntries(\n [...registry].map(([key, { data }]) => [key, data]),\n );\n const { name, env, http } = current;\n const digest = sectionDigest(baseDigest, sections);\n yield* writeFileStringAndLog(\n yield* manifestPath,\n Declaration.renderManifest({ name, env, http, digest, ...sections }),\n );\n },\n Effect.tapError(() => removeManifest),\n);\n\nconst authProvidersPath = Effect.gen(function* () {\n const path = yield* Path.Path;\n return path.join(\n yield* ConfectDirectory.get,\n \"_generated\",\n \"auth.providers.ts\",\n );\n});\n\nconst removeAuthProviders = Effect.gen(function* () {\n yield* removeGenerated(yield* authProvidersPath, []);\n});\n\nconst writeDeclaration = Effect.fnUntraced(function* (\n previous: Readonly<Record<string, unknown>>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const projectRoot = yield* ProjectRoot.get;\n const target = (yield* ConvexDirectory.target).kind;\n\n const app = yield* bundleDeclaration(\"app.ts\");\n const appValue: unknown = app.module.default;\n if (App.isApp(appValue) && appValue.kind !== target) {\n return yield* new DeclarationKindMismatchError({\n declarationPath: \"confect/app.ts\",\n declaredKind: appValue.kind,\n targetKind: target,\n });\n }\n const authPath = yield* confectPath(\"auth.ts\");\n const auth = (yield* fs.exists(authPath))\n ? Option.some(yield* bundleDeclaration(\"auth.ts\"))\n : Option.none();\n\n const declaration = yield* Declaration.parse({\n target,\n app: app.module.default,\n auth: Option.map(auth, ({ module }) => module.default),\n componentImport: yield* componentImport(),\n }).pipe(\n Result.mapError(\n (error) =>\n new InvalidDeclarationError({\n declarationPath: Declaration.fileOf(error),\n reason: error.message,\n }),\n ),\n Effect.fromResult,\n );\n const manifestSections = App.isApp(appValue) ? appValue.manifestSections : [];\n yield* Effect.fromResult(ManifestSections.declared(manifestSections));\n\n const convexConfigPath = path.join(\n convexDirectory,\n ConvexConfig.CONVEX_CONFIG_FILENAME,\n );\n const authConfigPath = path.join(convexDirectory, \"auth.config.ts\");\n const authImportPath = yield* toModuleImportPath(\n path.relative(convexDirectory, authPath),\n );\n const legacyAuthConfigs = yield* Effect.forEach(\n [authImportPath, authImportPath.replace(/\\.js$/, \"\")],\n (importPath) => templates.authConfig({ authImportPath: importPath }),\n );\n yield* assertOwned(convexConfigPath, \"app.ts\", []);\n yield* assertOwned(authConfigPath, \"auth.ts\", legacyAuthConfigs);\n\n let digest: string | undefined;\n if (target === \"app\") {\n digest = Declaration.digest({\n files: yield* declarationInputs([app, ...Option.toArray(auth)]),\n versions: [\n [\"convex\", yield* packageVersion(\"convex\", projectRoot)],\n [\"@confect/cli generator format\", GENERATOR_FORMAT],\n ],\n });\n const sections = ManifestSections.sections(previous);\n yield* writeFileStringAndLog(\n yield* manifestPath,\n Declaration.manifest(\n declaration,\n sectionDigest(digest, sections),\n sections,\n ),\n );\n }\n yield* writeFileStringAndLog(\n convexConfigPath,\n Declaration.convexConfig(declaration),\n );\n yield* Option.match(declaration.providers, {\n onNone: () =>\n Effect.gen(function* () {\n yield* removeAuthProviders;\n if (yield* fs.exists(authConfigPath)) {\n yield* removePathIfExists(authConfigPath);\n yield* logFileRemoved(authConfigPath);\n }\n }),\n onSome: (providers) =>\n Effect.gen(function* () {\n yield* writeFileStringAndLog(\n authConfigPath,\n Declaration.authConfig(providers),\n );\n yield* writeFileStringAndLog(\n yield* authProvidersPath,\n Declaration.authProviders(providers),\n );\n }),\n });\n const sectionTarget: ManifestSection.Target =\n target === \"app\"\n ? { kind: \"app\" }\n : { kind: \"component\", name: declaration.name };\n return {\n app: App.isApp(appValue) ? Option.some(appValue) : Option.none<App.Any>(),\n digest,\n backend: Option.some<SectionFiles.Backend>({\n target: sectionTarget,\n sections: manifestSections,\n }),\n };\n});\n\n/**\n * Write the declaration's Convex files and manifest from `confect/app.ts`,\n * `confect/env.ts` and `confect/auth.ts`, before anything else is validated. On\n * any failure the previous manifest is removed, so a stale manifest never\n * outlives a declaration that no longer produces it.\n */\nexport const syncDeclaration = Effect.fnUntraced(function* (\n previous: Readonly<Record<string, unknown>>,\n) {\n if (!(yield* isDeclared)) {\n yield* removeManifest;\n yield* removeAuthProviders;\n return {\n app: Option.none<App.Any>(),\n digest: undefined,\n backend: Option.none<SectionFiles.Backend>(),\n };\n }\n return yield* writeDeclaration(previous).pipe(\n Effect.tapError(() =>\n removeManifest.pipe(Effect.andThen(removeAuthProviders)),\n ),\n );\n});\n\n/**\n * Check every HTTP route the backend serves and write `convex/http.ts` from\n * `confect/http.ts`. Runs after generation, because `http.ts` imports its\n * handlers, which import generated services.\n */\nexport const syncDeclaredHttp = (\n app: App.Any,\n sectionFiles: ReadonlyArray<string>,\n) =>\n checkAndWriteHttp(app, sectionFiles).pipe(\n Effect.tapError(() => removeManifest),\n );\n\nconst checkAndWriteHttp = Effect.fnUntraced(function* (\n app: App.Any,\n sectionFiles: ReadonlyArray<string>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const confectDirectory = yield* ConfectDirectory.get;\n const httpPath = yield* confectPath(\"http.ts\");\n\n const convexHttpPath = path.join(convexDirectory, \"http.ts\");\n if (!(yield* fs.exists(httpPath))) {\n yield* Http.routes(app).pipe(\n Result.mapError(invalid(\"app.ts\")),\n Effect.fromResult,\n );\n yield* removeGenerated(convexHttpPath, [\n yield* templates.http({\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n }),\n ]);\n return Option.none();\n }\n\n const http = (yield* bundleDeclaration(\"http.ts\")).module.default;\n if (!Http.isHttp(http)) {\n return yield* new InvalidDeclarationError({\n declarationPath: \"confect/http.ts\",\n reason: \"it must default-export Http.make(...).\",\n });\n }\n yield* Http.routes(app, http).pipe(\n Result.mapError(invalid(\"http.ts\")),\n Effect.fromResult,\n );\n\n const contents = yield* templates.declaredHttp({\n runtimeImportPath: (yield* fs.exists(\n path.join(confectDirectory, \"runtime.ts\"),\n ))\n ? yield* toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"runtime.ts\"),\n ),\n )\n : undefined,\n schemaImportPath: yield* toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"_generated\", \"schema.ts\"),\n ),\n ),\n httpImportPath: yield* toModuleImportPath(\n path.relative(convexDirectory, httpPath),\n ),\n sectionImportPaths: yield* Effect.forEach(sectionFiles, (file) =>\n toModuleImportPath(\n path.relative(\n convexDirectory,\n path.join(confectDirectory, \"_generated\", file),\n ),\n ),\n ),\n });\n const change = yield* writeFileString(convexHttpPath, contents);\n return Option.some({ change, convexFilePath: convexHttpPath });\n});\n\nconst DEPLOY_MODULE = \"confectDeploy.ts\";\n\n/**\n * Whether a mounted component's own codegen wrote a deploy module, so a push\n * visits its mounts after its `init`.\n */\nconst hasDeployModule = Effect.fnUntraced(function* (\n component: ConvexConfig.InstalledComponent,\n config: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const directory = path.isAbsolute(component.componentDefinitionPath)\n ? Option.some(component.componentDefinitionPath)\n : Option.map(\n ConvexConfig.resolveDefinition(\n `${component.componentDefinitionPath}/convex.config`,\n config,\n path,\n ),\n path.dirname,\n );\n if (Option.isNone(directory)) return false;\n for (const file of [DEPLOY_MODULE, \"confectDeploy.js\"]) {\n if (yield* fs.exists(path.join(directory.value, file))) return true;\n }\n return false;\n});\n\n/**\n * The export of `confect/<name>.ts` that is the mount named `name`.\n */\nconst mountExport = Effect.fnUntraced(function* (name: string) {\n const fs = yield* FileSystem.FileSystem;\n const file = yield* confectPath(`${name}.ts`);\n const missing = new InvalidDeclarationError({\n declarationPath: \"confect/app.ts\",\n reason: `the mount ${name} runs at every push, so export it from confect/${name}.ts.`,\n });\n if (!(yield* fs.exists(file))) return yield* missing;\n const exports: Record<string, unknown> = (yield* bundleDeclaration(\n `${name}.ts`,\n )).module;\n const found = Object.entries(exports).find(\n ([, value]) =>\n Predicate.hasProperty(value, \"~@confect/core/Mount\") &&\n Mount.data(value as Mount.Any).name === name,\n );\n if (found === undefined) return yield* missing;\n return { file, exportName: found[0] };\n});\n\n/**\n * Write `convex/confectDeploy.ts`, the internal mutation a push calls for the\n * steps it runs at each mount: every mount whose component declares `init` or\n * has a deploy module of its own, in declaration order. Remove it when there\n * are none.\n */\nexport const syncDeployModule = Effect.fnUntraced(function* (\n app: Option.Option<App.Any>,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const deployPath = path.join(convexDirectory, DEPLOY_MODULE);\n const config = path.join(\n convexDirectory,\n ConvexConfig.CONVEX_CONFIG_FILENAME,\n );\n const installed =\n Option.isSome(app) && (yield* fs.exists(config))\n ? yield* ConvexConfig.discoverInstalledComponents(\n config,\n yield* displayPath(config),\n (yield* ConvexDirectory.target).kind,\n )\n : [];\n const entries: Array<string> = [];\n const imports: Array<string> = [];\n for (const mount of Option.match(app, {\n onNone: () => [],\n onSome: App.mounts,\n })) {\n const component = installed.find(({ name }) => name === mount.name);\n const nested =\n component !== undefined && (yield* hasDeployModule(component, config));\n if (mount.component.init === undefined && !nested) continue;\n const { file, exportName } = yield* mountExport(mount.name);\n const local = `mount${entries.length}`;\n imports.push(\n `import { ${exportName} as ${local} } from \"${yield* toModuleImportPath(path.relative(convexDirectory, file))}\";`,\n );\n entries.push(` { mount: ${local}, nested: ${nested} },`);\n }\n if (entries.length === 0) return yield* removeGenerated(deployPath, []);\n yield* writeFileStringAndLog(\n deployPath,\n [\n \"// Generated by `confect codegen` from confect/app.ts. Do not edit.\",\n 'import { MountInit } from \"@confect/server\";',\n ...imports,\n \"\",\n \"export const steps = MountInit.mutation([\",\n ...entries,\n \"]);\",\n \"\",\n ].join(\"\\n\"),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,mBAAmB;AAEzB,MAAM,cAAc,OAAO,WAAW,WAAW,MAAc;CAE7D,QAAO,OADa,KAAK,KAAA,CACb,KAAK,OAAO,iBAAiB,KAAK,IAAI;AACpD,CAAC;;;;AAKD,MAAa,aAAa,OAAO,IAAI,aAAa;CAEhD,OAAO,QAAO,OADI,WAAW,WAAA,CACZ,OAAO,OAAO,YAAY,QAAQ,CAAC;AACtD,CAAC;AAED,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ACA,GAAG;EACH;EACA;EACA,GAAG;EACH;EACA;CACF,CAAC,CAAC,KAAK,IAAI,CACb;AACF,CAAC"}
|
package/dist/confect/dev.mjs
CHANGED
|
@@ -10,8 +10,8 @@ import { functionPaths } from "../GenerationSnapshot.mjs";
|
|
|
10
10
|
import { preserveComponentOutput } from "../Rollback.mjs";
|
|
11
11
|
import { isDeclared } from "./declaration.mjs";
|
|
12
12
|
import { Operation, Outcome, Phase, forBackend, isDirty, needsDeploymentNotification, plan, shouldRetry, transition } from "../SyncState.mjs";
|
|
13
|
-
import { isRefreshSuccessful, make } from "../Watcher.mjs";
|
|
14
|
-
import { EvaluationError, catchAndLog, generateSnapshot, loadPreviousFunctionPaths, updateDeclarations, validate } from "../Evaluation.mjs";
|
|
13
|
+
import { CoalesceQuiescence, isRefreshSuccessful, make } from "../Watcher.mjs";
|
|
14
|
+
import { EvaluationError, catchAndLog, generateSnapshot, loadPreviousFunctionPaths, prewarmedLayer, updateDeclarations, validate } from "../Evaluation.mjs";
|
|
15
15
|
import * as Effect from "effect/Effect";
|
|
16
16
|
import * as Command from "effect/cli/Command";
|
|
17
17
|
import * as FileSystem from "effect/FileSystem";
|
|
@@ -26,6 +26,8 @@ import * as Ref from "effect/Ref";
|
|
|
26
26
|
import * as String from "effect/String";
|
|
27
27
|
import * as Console from "effect/Console";
|
|
28
28
|
import * as Order from "effect/Order";
|
|
29
|
+
import * as Flag from "effect/cli/Flag";
|
|
30
|
+
import * as Duration from "effect/Duration";
|
|
29
31
|
import * as Equal from "effect/Equal";
|
|
30
32
|
//#region src/confect/dev.ts
|
|
31
33
|
const changeChar = (change) => Match.value(change).pipe(Match.when("Added", () => ({
|
|
@@ -59,8 +61,11 @@ const devHandler = Effect.gen(function* () {
|
|
|
59
61
|
const previousFunctionPaths = yield* loadPreviousFunctionPaths;
|
|
60
62
|
const watcher = yield* make();
|
|
61
63
|
yield* Effect.all([watcher.run, syncLoop(previousFunctionPaths, watcher)], { concurrency: "unbounded" });
|
|
62
|
-
});
|
|
63
|
-
const dev = Command.make("dev",
|
|
64
|
+
}).pipe(Effect.provide(prewarmedLayer));
|
|
65
|
+
const dev = Command.make("dev", {
|
|
66
|
+
...flags,
|
|
67
|
+
coalesceMs: Flag.Int("coalesce-ms").pipe(Flag.filter((ms) => ms >= 0 && ms <= 5e3, () => "Set --coalesce-ms to an integer between 0 and 5000 milliseconds."), Flag.withDefault(Duration.toMillis(CoalesceQuiescence.defaultValue())), Flag.withDescription("Quiet period before processing saved files, in milliseconds."))
|
|
68
|
+
}, ({ coalesceMs }) => devHandler.pipe(Effect.provideService(CoalesceQuiescence, Duration.millis(coalesceMs)))).pipe(Command.withDescription("Start the Confect development server"), Command.provide((options) => layer(options)));
|
|
64
69
|
const esbuildMessageKey = (m) => `${m.location?.file ?? ""}:${m.location?.line ?? ""}:${m.location?.column ?? ""}:${m.text}`;
|
|
65
70
|
const dedupeWatcherMessages = (messages) => pipe(messages, Array.dedupeWith((messageA, messageB) => esbuildMessageKey(messageA) === esbuildMessageKey(messageB)));
|
|
66
71
|
const watcherMessagesSignature = (messages) => pipe(messages, Array.map(esbuildMessageKey), Array.dedupe, Array.sort(Order.String), Array.join("\n"));
|
package/dist/confect/dev.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.mjs","names":["Ansi.green","Ansi.red","Ansi.magenta","Ansi.blackBright","FunctionPaths.diff","Evaluation.loadPreviousFunctionPaths","Watcher.make","DirectoryOptions.flags","DirectoryOptions.layer","SyncState.isDirty","SyncState.forBackend","SyncState.plan","GenerationSnapshot.functionPaths","Evaluation.catchAndLog","Watcher.isRefreshSuccessful","Evaluation.EvaluationError","validate","Evaluation.validate","Evaluation.generateSnapshot","Evaluation.updateDeclarations","SyncState.transition","SyncState.shouldRetry","SyncState.needsDeploymentNotification"],"sources":["../../src/confect/dev.ts"],"sourcesContent":["import * as Command from \"effect/cli/Command\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as Equal from \"effect/Equal\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Ref from \"effect/Ref\";\nimport * as Result from \"effect/Result\";\nimport * as String from \"effect/String\";\nimport type * as esbuild from \"esbuild\";\nimport * as Ansi from \"../Ansi.js\";\nimport { renderCodegenError } from \"../CodegenError.js\";\nimport * as SyncState from \"../SyncState.js\";\nimport type { OptionalFile } from \"../EntryPoint.js\";\nimport * as Watcher from \"../Watcher.js\";\nimport * as Evaluation from \"../Evaluation.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as DirectoryOptions from \"../DirectoryOptions.js\";\nimport * as FunctionPaths from \"../FunctionPaths.js\";\nimport * as GenerationSnapshot from \"../GenerationSnapshot.js\";\nimport type { ImplModulePath } from \"../ImplModulePath.js\";\nimport type * as GroupPath from \"../GroupPath.js\";\nimport type * as GroupPaths from \"../GroupPaths.js\";\nimport {\n logCoalescedBuildErrors,\n logCoalescedBuildWarnings,\n logFunctionAdded,\n logFunctionRemoved,\n logPending,\n logSuccess,\n} from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport { preserveComponentOutput } from \"../Rollback.js\";\nimport {\n generateAuthConfig,\n generateCrons,\n generateHttp,\n touchConvexSchema,\n} from \"../utils.js\";\nimport { isDeclared } from \"./declaration.js\";\n\nconst changeChar = (change: \"Added\" | \"Removed\" | \"Modified\") =>\n Match.value(change).pipe(\n Match.when(\"Added\", () => ({ char: \"+\", color: Ansi.green })),\n Match.when(\"Removed\", () => ({ char: \"-\", color: Ansi.red })),\n Match.when(\"Modified\", () => ({ char: \"~\", color: Ansi.magenta })),\n Match.exhaustive,\n );\n\nconst logFileChangeIndented = Effect.fnUntraced(function* (\n change: \"Added\" | \"Removed\" | \"Modified\",\n fullPath: string,\n) {\n const projectRoot = yield* ProjectRoot.get;\n const path = yield* Path.Path;\n\n const prefix = projectRoot + path.sep;\n const suffix = pipe(fullPath, String.startsWith(prefix))\n ? pipe(fullPath, String.slice(prefix.length))\n : fullPath;\n\n const { char, color } = changeChar(change);\n\n yield* Console.log(\n `${color(char)} ${Ansi.blackBright(prefix)}${color(suffix)}`,\n );\n});\n\nconst logFunctionPathDiff = Effect.fnUntraced(function* (\n previous: FunctionPaths.FunctionPaths,\n current: FunctionPaths.FunctionPaths,\n) {\n const {\n functionsAdded,\n functionsRemoved,\n groupsRemoved,\n groupsAdded,\n groupsChanged,\n } = FunctionPaths.diff(previous, current);\n\n const logForGroups = (\n groupPaths: GroupPaths.GroupPaths,\n fnPaths: FunctionPaths.FunctionPaths,\n logFn: typeof logFunctionAdded,\n ) =>\n Effect.forEach(groupPaths, (gp) =>\n Effect.forEach(\n Array.fromIterable(\n HashSet.filter(fnPaths, (fp) => Equal.equals(fp.groupPath, gp)),\n ),\n logFn,\n ),\n );\n\n yield* logForGroups(groupsRemoved, functionsRemoved, logFunctionRemoved);\n yield* logForGroups(groupsAdded, functionsAdded, logFunctionAdded);\n yield* Effect.forEach(\n groupsChanged,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsAdded, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionAdded,\n );\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsRemoved, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionRemoved,\n );\n }),\n );\n});\n\nexport const devHandler = Effect.gen(function* () {\n yield* logPending(\"Performing initial sync…\");\n const previousFunctionPaths = yield* Evaluation.loadPreviousFunctionPaths;\n\n const watcher = yield* Watcher.make();\n\n yield* Effect.all([watcher.run, syncLoop(previousFunctionPaths, watcher)], {\n concurrency: \"unbounded\",\n });\n});\n\nexport const dev = Command.make(\n \"dev\",\n DirectoryOptions.flags,\n () => devHandler,\n).pipe(\n Command.withDescription(\"Start the Confect development server\"),\n Command.provide(DirectoryOptions.layer),\n);\n\nconst esbuildMessageKey = (m: esbuild.Message): string =>\n `${m.location?.file ?? \"\"}:${m.location?.line ?? \"\"}:${m.location?.column ?? \"\"}:${m.text}`;\n\nconst dedupeWatcherMessages = (\n messages: ReadonlyArray<esbuild.Message>,\n): ReadonlyArray<esbuild.Message> =>\n pipe(\n messages,\n Array.dedupeWith(\n (messageA, messageB) =>\n esbuildMessageKey(messageA) === esbuildMessageKey(messageB),\n ),\n );\n\nconst watcherMessagesSignature = (\n messages: ReadonlyArray<esbuild.Message>,\n): string =>\n pipe(\n messages,\n Array.map(esbuildMessageKey),\n Array.dedupe,\n Array.sort(Order.String),\n Array.join(\"\\n\"),\n );\n\n/**\n * Log any watcher messages (errors or warnings) that haven't already been\n * logged at their current signature. Suppresses the per-watcher fanout that\n * happens when one root cause (e.g. a missing import) breaks every entry\n * point's build at the same source location.\n */\nconst logChangedWatcherMessages = Effect.fnUntraced(function* (\n messages: ReadonlyArray<esbuild.Message>,\n lastLoggedSignatureRef: Ref.Ref<string>,\n log: (messages: ReadonlyArray<esbuild.Message>) => Effect.Effect<void>,\n) {\n const signature = watcherMessagesSignature(messages);\n const previous = yield* Ref.get(lastLoggedSignatureRef);\n if (signature === previous) return;\n yield* Ref.set(lastLoggedSignatureRef, signature);\n if (messages.length === 0) return;\n yield* log(dedupeWatcherMessages(messages));\n});\n\nconst syncLoop = Effect.fnUntraced(function* (\n initialFunctionPaths: FunctionPaths.FunctionPaths,\n watcher: Watcher.Watcher,\n) {\n const functionPathsRef = yield* Ref.make(initialFunctionPaths);\n const lastLoggedErrorsRef = yield* Ref.make<string>(\"\");\n const lastLoggedWarningsRef = yield* Ref.make<string>(\"\");\n const phaseRef = yield* Ref.make<SyncState.Phase>(\n SyncState.Phase.Bootstrapping(),\n );\n const optionalPendingRef = yield* Ref.make(HashSet.empty<OptionalFile>());\n const logMessages = Effect.gen(function* () {\n const { errors, warnings } = yield* watcher.diagnostics;\n yield* logChangedWatcherMessages(\n errors,\n lastLoggedErrorsRef,\n logCoalescedBuildErrors,\n );\n yield* logChangedWatcherMessages(\n warnings,\n lastLoggedWarningsRef,\n logCoalescedBuildWarnings,\n );\n });\n\n return yield* Effect.forever(\n Effect.gen(function* () {\n yield* Effect.logDebug(\"Running sync loop…\");\n const taken = yield* watcher.next;\n\n const phase = yield* Ref.get(phaseRef);\n const firstSync = SyncState.Phase.$is(\"Bootstrapping\")(phase);\n if (!firstSync) yield* logMessages;\n\n if (!SyncState.isDirty(taken)) return;\n\n const declared = yield* isDeclared;\n const pending = SyncState.forBackend(\n {\n ...taken,\n optional: yield* Ref.updateAndGet(\n optionalPendingRef,\n HashSet.union(taken.optional),\n ),\n },\n {\n declared,\n component: (yield* ConvexDirectory.target).kind === \"component\",\n },\n );\n const optional = pending.optional;\n const operation = SyncState.plan(phase, pending);\n yield* Effect.logDebug(\"Planned development sync\").pipe(\n Effect.annotateLogs({\n phase: phase._tag,\n work: pending.work._tag,\n operation: operation._tag,\n }),\n );\n if (\n !firstSync &&\n !(\n SyncState.Operation.$is(\"Validate\")(operation) &&\n operation.paths.length === 0\n )\n )\n yield* logPending(\"Dependencies may have changed, reloading…\");\n\n const regenerate = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n Effect.gen(function* () {\n const current = yield* generation.pipe(\n Effect.tap((snapshot) =>\n Effect.gen(function* () {\n const nextFunctionPaths =\n GenerationSnapshot.functionPaths(snapshot);\n const previous = yield* Ref.get(functionPathsRef);\n yield* logFunctionPathDiff(previous, nextFunctionPaths);\n yield* Ref.set(functionPathsRef, nextFunctionPaths);\n }),\n ),\n Evaluation.catchAndLog,\n );\n if (Option.isNone(current)) {\n return SyncState.Outcome.GenerationFailed();\n }\n const refreshed = yield* watcher.refresh.pipe(Effect.result);\n if (Result.isFailure(refreshed)) {\n yield* Console.error(\n `Dependency watcher could not ${refreshed.failure.operation}: ${globalThis.String(refreshed.failure.cause)}`,\n );\n return SyncState.Outcome.ReconciliationFailed();\n }\n if (!Watcher.isRefreshSuccessful(refreshed.success)) {\n yield* logMessages;\n return SyncState.Outcome.ReconciliationFailed();\n }\n return SyncState.Outcome.Succeeded({ snapshot: current.value });\n });\n const preserved = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n preserveComponentOutput(generation, watcher.duringRestore).pipe(\n Effect.tapErrorTag(\n \"ComponentNodeGroupError\",\n () => watcher.discardRestoreEchoes,\n ),\n Effect.catchTags({\n RemoveBusyError: (error) =>\n Effect.fail(\n new Evaluation.EvaluationError({\n diagnostic: renderCodegenError(error),\n }),\n ),\n // Output that cannot be restored leaves nothing to serve.\n PlatformError: Effect.die,\n }),\n );\n const validate = (\n paths: ReadonlyArray<ImplModulePath>,\n snapshot: GenerationSnapshot.GenerationSnapshot,\n ) =>\n Effect.gen(function* () {\n if (Array.isReadonlyArrayNonEmpty(paths)) {\n const validated = yield* Evaluation.validate(paths).pipe(\n Evaluation.catchAndLog,\n );\n if (Option.isNone(validated)) {\n return SyncState.Outcome.ValidationFailed({ paths, snapshot });\n }\n }\n return SyncState.Outcome.Succeeded({ snapshot });\n });\n const outcome = yield* SyncState.Operation.$match(operation, {\n Generate: () => regenerate(preserved(Evaluation.generateSnapshot)),\n Validate: ({ paths, snapshot }) => validate(paths, snapshot),\n Update: ({ snapshot, declarations, paths }) =>\n regenerate(\n preserved(\n Evaluation.updateDeclarations(snapshot, declarations, paths),\n ),\n ),\n });\n yield* Ref.set(phaseRef, SyncState.transition(outcome));\n if (SyncState.shouldRetry(phase, outcome)) {\n yield* watcher.requestRetry;\n }\n if (!SyncState.Outcome.$is(\"Succeeded\")(outcome)) return;\n\n const dirtyOptionalFiles = [\n ...(HashSet.has(optional, \"Http\")\n ? [syncOptionalFile(generateHttp, \"http.ts\")]\n : []),\n ...(HashSet.has(optional, \"Crons\")\n ? [syncOptionalFile(generateCrons, \"crons.ts\")]\n : []),\n ...(HashSet.has(optional, \"Auth\")\n ? [syncOptionalFile(generateAuthConfig, \"auth.config.ts\")]\n : []),\n ];\n\n yield* Array.isReadonlyArrayNonEmpty(dirtyOptionalFiles)\n ? Effect.all(dirtyOptionalFiles, { concurrency: \"unbounded\" })\n : Effect.void;\n yield* Ref.set(optionalPendingRef, HashSet.empty());\n\n if (SyncState.needsDeploymentNotification(phase))\n yield* touchConvexSchema;\n\n if (!SyncState.isDirty(yield* watcher.pending)) {\n yield* logSuccess(\"Generated files are up-to-date\");\n }\n }),\n );\n});\n\nconst syncOptionalFile = (generate: typeof generateHttp, convexFile: string) =>\n pipe(\n generate,\n Effect.andThen(\n Option.match({\n onSome: ({ change, convexFilePath }) =>\n Match.value(change).pipe(\n Match.when(\"Unchanged\", () => Effect.void),\n Match.whenOr(\"Added\", \"Modified\", (addedOrModified) =>\n logFileChangeIndented(addedOrModified, convexFilePath),\n ),\n Match.exhaustive,\n ),\n onNone: () =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const convexFilePath = path.join(convexDirectory, convexFile);\n\n if (yield* fs.exists(convexFilePath)) {\n yield* fs.remove(convexFilePath);\n yield* logFileChangeIndented(\"Removed\", convexFilePath);\n }\n }),\n }),\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,cAAc,WAClB,MAAM,MAAM,MAAM,CAAC,CAAC,KAClB,MAAM,KAAK,gBAAgB;CAAE,MAAM;CAAK,OAAOA;AAAW,EAAE,GAC5D,MAAM,KAAK,kBAAkB;CAAE,MAAM;CAAK,OAAOC;AAAS,EAAE,GAC5D,MAAM,KAAK,mBAAmB;CAAE,MAAM;CAAK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"file":"dev.mjs","names":["Ansi.green","Ansi.red","Ansi.magenta","Ansi.blackBright","FunctionPaths.diff","Evaluation.loadPreviousFunctionPaths","Watcher.make","Evaluation.prewarmedLayer","DirectoryOptions.flags","Watcher.CoalesceQuiescence","DirectoryOptions.layer","SyncState.isDirty","SyncState.forBackend","SyncState.plan","GenerationSnapshot.functionPaths","Evaluation.catchAndLog","Watcher.isRefreshSuccessful","Evaluation.EvaluationError","validate","Evaluation.validate","Evaluation.generateSnapshot","Evaluation.updateDeclarations","SyncState.transition","SyncState.shouldRetry","SyncState.needsDeploymentNotification"],"sources":["../../src/confect/dev.ts"],"sourcesContent":["import * as Command from \"effect/cli/Command\";\nimport * as Flag from \"effect/cli/Flag\";\nimport * as Duration from \"effect/Duration\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as Equal from \"effect/Equal\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Ref from \"effect/Ref\";\nimport * as Result from \"effect/Result\";\nimport * as String from \"effect/String\";\nimport type * as esbuild from \"esbuild\";\nimport * as Ansi from \"../Ansi.js\";\nimport { renderCodegenError } from \"../CodegenError.js\";\nimport * as SyncState from \"../SyncState.js\";\nimport type { OptionalFile } from \"../EntryPoint.js\";\nimport * as Watcher from \"../Watcher.js\";\nimport * as Evaluation from \"../Evaluation.js\";\nimport { ConvexDirectory } from \"../ConvexDirectory.js\";\nimport * as DirectoryOptions from \"../DirectoryOptions.js\";\nimport * as FunctionPaths from \"../FunctionPaths.js\";\nimport * as GenerationSnapshot from \"../GenerationSnapshot.js\";\nimport type { ImplModulePath } from \"../ImplModulePath.js\";\nimport type * as GroupPath from \"../GroupPath.js\";\nimport type * as GroupPaths from \"../GroupPaths.js\";\nimport {\n logCoalescedBuildErrors,\n logCoalescedBuildWarnings,\n logFunctionAdded,\n logFunctionRemoved,\n logPending,\n logSuccess,\n} from \"../log.js\";\nimport { ProjectRoot } from \"../ProjectRoot.js\";\nimport { preserveComponentOutput } from \"../Rollback.js\";\nimport {\n generateAuthConfig,\n generateCrons,\n generateHttp,\n touchConvexSchema,\n} from \"../utils.js\";\nimport { isDeclared } from \"./declaration.js\";\n\nconst changeChar = (change: \"Added\" | \"Removed\" | \"Modified\") =>\n Match.value(change).pipe(\n Match.when(\"Added\", () => ({ char: \"+\", color: Ansi.green })),\n Match.when(\"Removed\", () => ({ char: \"-\", color: Ansi.red })),\n Match.when(\"Modified\", () => ({ char: \"~\", color: Ansi.magenta })),\n Match.exhaustive,\n );\n\nconst logFileChangeIndented = Effect.fnUntraced(function* (\n change: \"Added\" | \"Removed\" | \"Modified\",\n fullPath: string,\n) {\n const projectRoot = yield* ProjectRoot.get;\n const path = yield* Path.Path;\n\n const prefix = projectRoot + path.sep;\n const suffix = pipe(fullPath, String.startsWith(prefix))\n ? pipe(fullPath, String.slice(prefix.length))\n : fullPath;\n\n const { char, color } = changeChar(change);\n\n yield* Console.log(\n `${color(char)} ${Ansi.blackBright(prefix)}${color(suffix)}`,\n );\n});\n\nconst logFunctionPathDiff = Effect.fnUntraced(function* (\n previous: FunctionPaths.FunctionPaths,\n current: FunctionPaths.FunctionPaths,\n) {\n const {\n functionsAdded,\n functionsRemoved,\n groupsRemoved,\n groupsAdded,\n groupsChanged,\n } = FunctionPaths.diff(previous, current);\n\n const logForGroups = (\n groupPaths: GroupPaths.GroupPaths,\n fnPaths: FunctionPaths.FunctionPaths,\n logFn: typeof logFunctionAdded,\n ) =>\n Effect.forEach(groupPaths, (gp) =>\n Effect.forEach(\n Array.fromIterable(\n HashSet.filter(fnPaths, (fp) => Equal.equals(fp.groupPath, gp)),\n ),\n logFn,\n ),\n );\n\n yield* logForGroups(groupsRemoved, functionsRemoved, logFunctionRemoved);\n yield* logForGroups(groupsAdded, functionsAdded, logFunctionAdded);\n yield* Effect.forEach(\n groupsChanged,\n Effect.fnUntraced(function* (gp: GroupPath.GroupPath) {\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsAdded, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionAdded,\n );\n yield* Effect.forEach(\n Array.fromIterable(\n HashSet.filter(functionsRemoved, (fp) =>\n Equal.equals(fp.groupPath, gp),\n ),\n ),\n logFunctionRemoved,\n );\n }),\n );\n});\n\nexport const devHandler = Effect.gen(function* () {\n yield* logPending(\"Performing initial sync…\");\n const previousFunctionPaths = yield* Evaluation.loadPreviousFunctionPaths;\n\n const watcher = yield* Watcher.make();\n\n yield* Effect.all([watcher.run, syncLoop(previousFunctionPaths, watcher)], {\n concurrency: \"unbounded\",\n });\n}).pipe(Effect.provide(Evaluation.prewarmedLayer));\n\nexport const dev = Command.make(\n \"dev\",\n {\n ...DirectoryOptions.flags,\n coalesceMs: Flag.Int(\"coalesce-ms\").pipe(\n Flag.filter(\n (ms) => ms >= 0 && ms <= 5000,\n () =>\n \"Set --coalesce-ms to an integer between 0 and 5000 milliseconds.\",\n ),\n Flag.withDefault(\n Duration.toMillis(Watcher.CoalesceQuiescence.defaultValue()),\n ),\n Flag.withDescription(\n \"Quiet period before processing saved files, in milliseconds.\",\n ),\n ),\n },\n ({ coalesceMs }) =>\n devHandler.pipe(\n Effect.provideService(\n Watcher.CoalesceQuiescence,\n Duration.millis(coalesceMs),\n ),\n ),\n).pipe(\n Command.withDescription(\"Start the Confect development server\"),\n Command.provide(\n (options: { componentDir: Option.Option<string>; coalesceMs: number }) =>\n DirectoryOptions.layer(options),\n ),\n);\n\nconst esbuildMessageKey = (m: esbuild.Message): string =>\n `${m.location?.file ?? \"\"}:${m.location?.line ?? \"\"}:${m.location?.column ?? \"\"}:${m.text}`;\n\nconst dedupeWatcherMessages = (\n messages: ReadonlyArray<esbuild.Message>,\n): ReadonlyArray<esbuild.Message> =>\n pipe(\n messages,\n Array.dedupeWith(\n (messageA, messageB) =>\n esbuildMessageKey(messageA) === esbuildMessageKey(messageB),\n ),\n );\n\nconst watcherMessagesSignature = (\n messages: ReadonlyArray<esbuild.Message>,\n): string =>\n pipe(\n messages,\n Array.map(esbuildMessageKey),\n Array.dedupe,\n Array.sort(Order.String),\n Array.join(\"\\n\"),\n );\n\n/**\n * Log any watcher messages (errors or warnings) that haven't already been\n * logged at their current signature. Suppresses the per-watcher fanout that\n * happens when one root cause (e.g. a missing import) breaks every entry\n * point's build at the same source location.\n */\nconst logChangedWatcherMessages = Effect.fnUntraced(function* (\n messages: ReadonlyArray<esbuild.Message>,\n lastLoggedSignatureRef: Ref.Ref<string>,\n log: (messages: ReadonlyArray<esbuild.Message>) => Effect.Effect<void>,\n) {\n const signature = watcherMessagesSignature(messages);\n const previous = yield* Ref.get(lastLoggedSignatureRef);\n if (signature === previous) return;\n yield* Ref.set(lastLoggedSignatureRef, signature);\n if (messages.length === 0) return;\n yield* log(dedupeWatcherMessages(messages));\n});\n\nconst syncLoop = Effect.fnUntraced(function* (\n initialFunctionPaths: FunctionPaths.FunctionPaths,\n watcher: Watcher.Watcher,\n) {\n const functionPathsRef = yield* Ref.make(initialFunctionPaths);\n const lastLoggedErrorsRef = yield* Ref.make<string>(\"\");\n const lastLoggedWarningsRef = yield* Ref.make<string>(\"\");\n const phaseRef = yield* Ref.make<SyncState.Phase>(\n SyncState.Phase.Bootstrapping(),\n );\n const optionalPendingRef = yield* Ref.make(HashSet.empty<OptionalFile>());\n const logMessages = Effect.gen(function* () {\n const { errors, warnings } = yield* watcher.diagnostics;\n yield* logChangedWatcherMessages(\n errors,\n lastLoggedErrorsRef,\n logCoalescedBuildErrors,\n );\n yield* logChangedWatcherMessages(\n warnings,\n lastLoggedWarningsRef,\n logCoalescedBuildWarnings,\n );\n });\n\n return yield* Effect.forever(\n Effect.gen(function* () {\n yield* Effect.logDebug(\"Running sync loop…\");\n const taken = yield* watcher.next;\n\n const phase = yield* Ref.get(phaseRef);\n const firstSync = SyncState.Phase.$is(\"Bootstrapping\")(phase);\n if (!firstSync) yield* logMessages;\n\n if (!SyncState.isDirty(taken)) return;\n\n const declared = yield* isDeclared;\n const pending = SyncState.forBackend(\n {\n ...taken,\n optional: yield* Ref.updateAndGet(\n optionalPendingRef,\n HashSet.union(taken.optional),\n ),\n },\n {\n declared,\n component: (yield* ConvexDirectory.target).kind === \"component\",\n },\n );\n const optional = pending.optional;\n const operation = SyncState.plan(phase, pending);\n yield* Effect.logDebug(\"Planned development sync\").pipe(\n Effect.annotateLogs({\n phase: phase._tag,\n work: pending.work._tag,\n operation: operation._tag,\n }),\n );\n if (\n !firstSync &&\n !(\n SyncState.Operation.$is(\"Validate\")(operation) &&\n operation.paths.length === 0\n )\n )\n yield* logPending(\"Dependencies may have changed, reloading…\");\n\n const regenerate = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n Effect.gen(function* () {\n const current = yield* generation.pipe(\n Effect.tap((snapshot) =>\n Effect.gen(function* () {\n const nextFunctionPaths =\n GenerationSnapshot.functionPaths(snapshot);\n const previous = yield* Ref.get(functionPathsRef);\n yield* logFunctionPathDiff(previous, nextFunctionPaths);\n yield* Ref.set(functionPathsRef, nextFunctionPaths);\n }),\n ),\n Evaluation.catchAndLog,\n );\n if (Option.isNone(current)) {\n return SyncState.Outcome.GenerationFailed();\n }\n const refreshed = yield* watcher.refresh.pipe(Effect.result);\n if (Result.isFailure(refreshed)) {\n yield* Console.error(\n `Dependency watcher could not ${refreshed.failure.operation}: ${globalThis.String(refreshed.failure.cause)}`,\n );\n return SyncState.Outcome.ReconciliationFailed();\n }\n if (!Watcher.isRefreshSuccessful(refreshed.success)) {\n yield* logMessages;\n return SyncState.Outcome.ReconciliationFailed();\n }\n return SyncState.Outcome.Succeeded({ snapshot: current.value });\n });\n const preserved = <R>(\n generation: Effect.Effect<\n GenerationSnapshot.GenerationSnapshot,\n Effect.Error<typeof Evaluation.generateSnapshot>,\n R\n >,\n ) =>\n preserveComponentOutput(generation, watcher.duringRestore).pipe(\n Effect.tapErrorTag(\n \"ComponentNodeGroupError\",\n () => watcher.discardRestoreEchoes,\n ),\n Effect.catchTags({\n RemoveBusyError: (error) =>\n Effect.fail(\n new Evaluation.EvaluationError({\n diagnostic: renderCodegenError(error),\n }),\n ),\n // Output that cannot be restored leaves nothing to serve.\n PlatformError: Effect.die,\n }),\n );\n const validate = (\n paths: ReadonlyArray<ImplModulePath>,\n snapshot: GenerationSnapshot.GenerationSnapshot,\n ) =>\n Effect.gen(function* () {\n if (Array.isReadonlyArrayNonEmpty(paths)) {\n const validated = yield* Evaluation.validate(paths).pipe(\n Evaluation.catchAndLog,\n );\n if (Option.isNone(validated)) {\n return SyncState.Outcome.ValidationFailed({ paths, snapshot });\n }\n }\n return SyncState.Outcome.Succeeded({ snapshot });\n });\n const outcome = yield* SyncState.Operation.$match(operation, {\n Generate: () => regenerate(preserved(Evaluation.generateSnapshot)),\n Validate: ({ paths, snapshot }) => validate(paths, snapshot),\n Update: ({ snapshot, declarations, paths }) =>\n regenerate(\n preserved(\n Evaluation.updateDeclarations(snapshot, declarations, paths),\n ),\n ),\n });\n yield* Ref.set(phaseRef, SyncState.transition(outcome));\n if (SyncState.shouldRetry(phase, outcome)) {\n yield* watcher.requestRetry;\n }\n if (!SyncState.Outcome.$is(\"Succeeded\")(outcome)) return;\n\n const dirtyOptionalFiles = [\n ...(HashSet.has(optional, \"Http\")\n ? [syncOptionalFile(generateHttp, \"http.ts\")]\n : []),\n ...(HashSet.has(optional, \"Crons\")\n ? [syncOptionalFile(generateCrons, \"crons.ts\")]\n : []),\n ...(HashSet.has(optional, \"Auth\")\n ? [syncOptionalFile(generateAuthConfig, \"auth.config.ts\")]\n : []),\n ];\n\n yield* Array.isReadonlyArrayNonEmpty(dirtyOptionalFiles)\n ? Effect.all(dirtyOptionalFiles, { concurrency: \"unbounded\" })\n : Effect.void;\n yield* Ref.set(optionalPendingRef, HashSet.empty());\n\n if (SyncState.needsDeploymentNotification(phase))\n yield* touchConvexSchema;\n\n if (!SyncState.isDirty(yield* watcher.pending)) {\n yield* logSuccess(\"Generated files are up-to-date\");\n }\n }),\n );\n});\n\nconst syncOptionalFile = (generate: typeof generateHttp, convexFile: string) =>\n pipe(\n generate,\n Effect.andThen(\n Option.match({\n onSome: ({ change, convexFilePath }) =>\n Match.value(change).pipe(\n Match.when(\"Unchanged\", () => Effect.void),\n Match.whenOr(\"Added\", \"Modified\", (addedOrModified) =>\n logFileChangeIndented(addedOrModified, convexFilePath),\n ),\n Match.exhaustive,\n ),\n onNone: () =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const convexDirectory = yield* ConvexDirectory.get;\n const convexFilePath = path.join(convexDirectory, convexFile);\n\n if (yield* fs.exists(convexFilePath)) {\n yield* fs.remove(convexFilePath);\n yield* logFileChangeIndented(\"Removed\", convexFilePath);\n }\n }),\n }),\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,cAAc,WAClB,MAAM,MAAM,MAAM,CAAC,CAAC,KAClB,MAAM,KAAK,gBAAgB;CAAE,MAAM;CAAK,OAAOA;AAAW,EAAE,GAC5D,MAAM,KAAK,kBAAkB;CAAE,MAAM;CAAK,OAAOC;AAAS,EAAE,GAC5D,MAAM,KAAK,mBAAmB;CAAE,MAAM;CAAK,OAAOC;AAAa,EAAE,GACjE,MAAM,UACR;AAEF,MAAM,wBAAwB,OAAO,WAAW,WAC9C,QACA,UACA;CAIA,MAAM,UAAS,OAHY,YAAY,QAGV,OAFT,KAAK,KAAA,CAES;CAClC,MAAM,SAAS,KAAK,UAAU,OAAO,WAAW,MAAM,CAAC,IACnD,KAAK,UAAU,OAAO,MAAM,OAAO,MAAM,CAAC,IAC1C;CAEJ,MAAM,EAAE,MAAM,UAAU,WAAW,MAAM;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ACH,CACF"}
|
package/dist/templates.mjs
CHANGED
|
@@ -162,14 +162,16 @@ const httpEffect = Effect.fnUntraced(function* ({ httpImportPath }) {
|
|
|
162
162
|
* Emit `convex/http.ts` for a declared backend: the Convex router serving
|
|
163
163
|
* `confect/http.ts`'s routes, typed by the generated database schema.
|
|
164
164
|
*/
|
|
165
|
-
const declaredHttp = Effect.fnUntraced(function* ({ schemaImportPath, httpImportPath }) {
|
|
165
|
+
const declaredHttp = Effect.fnUntraced(function* ({ schemaImportPath, httpImportPath, runtimeImportPath, sectionImportPaths = [] }) {
|
|
166
166
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
167
167
|
yield* cbw.writeLine("// Generated by `confect codegen` from confect/http.ts. Do not edit.");
|
|
168
|
+
for (const sectionImportPath of sectionImportPaths) yield* cbw.writeLine(`import "${sectionImportPath}";`);
|
|
168
169
|
yield* cbw.writeLine(`import { HttpRouter } from "@confect/server";`);
|
|
169
170
|
yield* cbw.writeLine(`import schema from "${schemaImportPath}";`);
|
|
170
171
|
yield* cbw.writeLine(`import http from "${httpImportPath}";`);
|
|
172
|
+
if (runtimeImportPath !== void 0) yield* cbw.writeLine(`import observability from "${runtimeImportPath}";`);
|
|
171
173
|
yield* cbw.newLine();
|
|
172
|
-
yield* cbw.writeLine(`export default HttpRouter.forSchema(schema)(http.routes, { api: http.api });`);
|
|
174
|
+
yield* cbw.writeLine(`export default HttpRouter.forSchema(schema)(http.routes, { api: http.api${runtimeImportPath === void 0 ? "" : ", observability"} });`);
|
|
173
175
|
return yield* cbw.toString();
|
|
174
176
|
});
|
|
175
177
|
const crons = ({ cronsImportPath }) => cronsEffect({ cronsImportPath });
|
|
@@ -229,19 +231,31 @@ const refsEffect = Effect.fnUntraced(function* ({ specImportPath }) {
|
|
|
229
231
|
yield* cbw.writeLine(`export default refs;`);
|
|
230
232
|
return yield* cbw.toString();
|
|
231
233
|
});
|
|
234
|
+
/**
|
|
235
|
+
* Emit `confect/_generated/component.ts`—the published contract. It passes
|
|
236
|
+
* `Component.contract` each table from its `_generated/tables/<name>` wrapper,
|
|
237
|
+
* so the contract carries the tables' groups. Importing a wrapper builds no
|
|
238
|
+
* schema, because a table's schema stays a thunk until something reads it.
|
|
239
|
+
*
|
|
240
|
+
* As in `convexSchema`, library imports and the spec carry a leading `$` so a
|
|
241
|
+
* table named `spec`, `scope` or `component` cannot collide with them.
|
|
242
|
+
*/
|
|
232
243
|
const componentContract = Effect.fnUntraced(function* ({ tableNames }) {
|
|
233
244
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
234
|
-
yield* cbw.writeLine("import { Component } from \"@confect/core\";");
|
|
235
|
-
yield* cbw.writeLine("import spec from \"./spec.js\";");
|
|
236
|
-
yield* cbw.writeLine("import { scope } from \"./id.js\";");
|
|
245
|
+
yield* cbw.writeLine("import { Component as $Component } from \"@confect/core\";");
|
|
246
|
+
yield* cbw.writeLine("import $spec from \"./spec.js\";");
|
|
247
|
+
yield* cbw.writeLine("import { scope as $scope } from \"./id.js\";");
|
|
248
|
+
if (tableNames.length > 0) {
|
|
249
|
+
yield* cbw.blankLine();
|
|
250
|
+
yield* Effect.forEach(tableNames, (name) => cbw.writeLine(`import ${name} from "./tables/${name}.js";`));
|
|
251
|
+
}
|
|
237
252
|
yield* cbw.blankLine();
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
yield* cbw.writeLine(
|
|
244
|
-
yield* cbw.writeLine("export default component;");
|
|
253
|
+
const systemTables = ["_storage", "_scheduled_functions"];
|
|
254
|
+
const names = Array.map([...tableNames, ...systemTables], (name) => `"${name}"`);
|
|
255
|
+
const entries = [...tableNames, ...Array.map(systemTables, (name) => `"${name}"`)];
|
|
256
|
+
const groups = `$Component.Groups<[${Array.map(tableNames, (name) => `typeof ${name}`).join(", ")}]>`;
|
|
257
|
+
yield* cbw.writeLine(`const $component: $Component.Component<typeof $spec, typeof $scope, ${names.join(" | ")}, ${groups}> = $Component.contract($spec, $scope, [${entries.join(", ")}]);`);
|
|
258
|
+
yield* cbw.writeLine("export default $component;");
|
|
245
259
|
return yield* cbw.toString();
|
|
246
260
|
});
|
|
247
261
|
/**
|
|
@@ -278,26 +292,39 @@ const docsEffect = Effect.fnUntraced(function* ({ schemaImportPath, tables }) {
|
|
|
278
292
|
yield* cbw.writeLine(`}`);
|
|
279
293
|
return yield* cbw.toString();
|
|
280
294
|
});
|
|
281
|
-
const registeredFunctionsForGroup = ({ spec, schemaImportPath, specImportPath, implImportPath }) => registeredFunctionsForGroupEffect({
|
|
295
|
+
const registeredFunctionsForGroup = ({ spec, schemaImportPath, specImportPath, implImportPath, groupPath = "", required = [], runtimeImportPath, sectionImportPaths = [] }) => registeredFunctionsForGroupEffect({
|
|
282
296
|
spec,
|
|
283
297
|
schemaImportPath,
|
|
284
298
|
specImportPath,
|
|
285
|
-
implImportPath
|
|
299
|
+
implImportPath,
|
|
300
|
+
groupPath,
|
|
301
|
+
required,
|
|
302
|
+
runtimeImportPath,
|
|
303
|
+
sectionImportPaths
|
|
286
304
|
});
|
|
287
|
-
const registeredFunctionsForGroupEffect = Effect.fnUntraced(function* ({ spec, schemaImportPath, specImportPath, implImportPath }) {
|
|
305
|
+
const registeredFunctionsForGroupEffect = Effect.fnUntraced(function* ({ spec, schemaImportPath, specImportPath, implImportPath, groupPath = "", required = [], runtimeImportPath, sectionImportPaths = [] }) {
|
|
288
306
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
307
|
+
for (const sectionImportPath of sectionImportPaths) yield* cbw.writeLine(`import "${sectionImportPath}";`);
|
|
308
|
+
if (runtimeImportPath !== void 0) {
|
|
309
|
+
yield* cbw.writeLine("import * as RegisteredFunction from \"@confect/server/RegisteredFunction\";");
|
|
310
|
+
yield* cbw.writeLine("import * as Layer from \"effect/Layer\";");
|
|
311
|
+
yield* cbw.writeLine(`import observability from "${runtimeImportPath}";`);
|
|
312
|
+
}
|
|
289
313
|
const useNode = spec.runtime === "Node";
|
|
290
314
|
const hasConfectFunctions = (group) => Object.values(group.functions).some((functionSpec) => functionSpec.functionProvenance._tag === "Confect") || Object.values(group.groups).some(hasConfectFunctions);
|
|
291
315
|
const forwarding = !useNode && hasConfectFunctions(spec);
|
|
292
316
|
if (useNode) yield* cbw.writeLine(`import { RegisteredNodeFunction } from "@confect/server/node";`);
|
|
293
317
|
else if (!forwarding) yield* cbw.writeLine(`import { RegisteredFunctions } from "@confect/server";`);
|
|
294
318
|
else yield* cbw.writeLine(`import { ConvexFunctionDefinitions, RegisteredConvexFunction, type RegisteredFunctions } from "@confect/server";`);
|
|
319
|
+
if (required.length > 0) yield* cbw.writeLine(`import { GroupImpl } from "@confect/server";`);
|
|
295
320
|
yield* cbw.writeLine(`import databaseSchema from "${schemaImportPath}";`);
|
|
296
321
|
yield* cbw.writeLine(`import groupLayer from "${implImportPath}";`);
|
|
297
322
|
yield* cbw.blankLine();
|
|
323
|
+
const finalizedLayer = required.length === 0 ? "groupLayer" : `groupLayer.pipe(GroupImpl.finalize({ required: [${required.map(({ key }) => `{ key: ${JSON.stringify(key)} }`).join(", ")}], groupPath: ${JSON.stringify(groupPath)} }))`;
|
|
324
|
+
const groupLayer = runtimeImportPath === void 0 ? finalizedLayer : `${finalizedLayer}.pipe(Layer.merge(Layer.succeed(RegisteredFunction.Observability, observability)))`;
|
|
298
325
|
const specType = `typeof import("${specImportPath}")["default"]`;
|
|
299
|
-
if (useNode) yield* cbw.writeLine(`export default RegisteredNodeFunction.buildForGroup<${specType}>(databaseSchema, groupLayer);`);
|
|
300
|
-
else if (!forwarding) yield* cbw.writeLine(`export default RegisteredFunctions.buildForGroup<${specType}>(databaseSchema, groupLayer);`);
|
|
326
|
+
if (useNode) yield* cbw.writeLine(`export default RegisteredNodeFunction.buildForGroup<${specType}>(databaseSchema, ${groupLayer});`);
|
|
327
|
+
else if (!forwarding) yield* cbw.writeLine(`export default RegisteredFunctions.buildForGroup<${specType}>(databaseSchema, ${groupLayer});`);
|
|
301
328
|
else {
|
|
302
329
|
const bindings = (group, path) => `{
|
|
303
330
|
${[...Object.entries(group.functions).map(([name, functionSpec]) => {
|
|
@@ -311,7 +338,7 @@ ${[...Object.entries(group.functions).map(([name, functionSpec]) => {
|
|
|
311
338
|
}`;
|
|
312
339
|
yield* cbw.writeLine(`const forward = <Ctx, Args, Returns>(handler: (ctx: Ctx, args: Args) => Promise<Returns>) => (ctx: Ctx, args: Args) => handler(ctx, args);
|
|
313
340
|
|
|
314
|
-
const definitions = ConvexFunctionDefinitions.buildForGroup<${specType}>(databaseSchema, groupLayer);
|
|
341
|
+
const definitions = ConvexFunctionDefinitions.buildForGroup<${specType}>(databaseSchema, ${groupLayer});
|
|
315
342
|
|
|
316
343
|
export default ${bindings(spec, "definitions")} as RegisteredFunctions.RegisteredFunctionsForGroupSpec<${specType}>;`);
|
|
317
344
|
}
|
|
@@ -325,17 +352,17 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
325
352
|
const cbw = new CodeBlockWriter({ indentNumberOfSpaces: 2 });
|
|
326
353
|
yield* cbw.writeLine("import {");
|
|
327
354
|
yield* cbw.indent(Effect.gen(function* () {
|
|
328
|
-
yield* cbw.writeLine("ActionCtx as ActionCtx_,");
|
|
355
|
+
if (!component) yield* cbw.writeLine("ActionCtx as ActionCtx_,");
|
|
329
356
|
yield* cbw.writeLine("ActionRunner as ActionRunner_,");
|
|
330
|
-
|
|
357
|
+
yield* cbw.writeLine("Auth as Auth_,");
|
|
331
358
|
yield* cbw.writeLine("type DataModel,");
|
|
332
359
|
yield* cbw.writeLine("DatabaseReader as DatabaseReader_,");
|
|
333
360
|
yield* cbw.writeLine("DatabaseWriter as DatabaseWriter_,");
|
|
334
361
|
yield* cbw.writeLine("ExecutionMetadata as ExecutionMetadata_,");
|
|
335
|
-
yield* cbw.writeLine("MutationCtx as MutationCtx_,");
|
|
362
|
+
if (!component) yield* cbw.writeLine("MutationCtx as MutationCtx_,");
|
|
336
363
|
yield* cbw.writeLine("MutationRunner as MutationRunner_,");
|
|
337
364
|
yield* cbw.writeLine("MutationTransactionContext as MutationTransactionContext_,");
|
|
338
|
-
yield* cbw.writeLine("QueryCtx as QueryCtx_,");
|
|
365
|
+
if (!component) yield* cbw.writeLine("QueryCtx as QueryCtx_,");
|
|
339
366
|
yield* cbw.writeLine("QueryRunner as QueryRunner_,");
|
|
340
367
|
yield* cbw.writeLine("QueryTransactionContext as QueryTransactionContext_,");
|
|
341
368
|
yield* cbw.writeLine("RequestMetadata as RequestMetadata_,");
|
|
@@ -356,6 +383,8 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
356
383
|
yield* cbw.writeLine("export const Auth = Auth_.Auth;");
|
|
357
384
|
yield* cbw.writeLine("export type Auth = typeof Auth.Identifier;");
|
|
358
385
|
}
|
|
386
|
+
yield* cbw.writeLine("export const MutationAuth = Auth_.MutationAuth;");
|
|
387
|
+
yield* cbw.writeLine("export type MutationAuth = typeof MutationAuth.Identifier;");
|
|
359
388
|
yield* cbw.blankLine();
|
|
360
389
|
yield* cbw.writeLine("export const ExecutionMetadata = ExecutionMetadata_.ExecutionMetadata;");
|
|
361
390
|
yield* cbw.writeLine("export type ExecutionMetadata = typeof ExecutionMetadata.Identifier;");
|
|
@@ -418,27 +447,29 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
418
447
|
yield* cbw.blankLine();
|
|
419
448
|
yield* cbw.writeLine("export const ActionRunner = ActionRunner_.ActionRunner;");
|
|
420
449
|
yield* cbw.writeLine("export type ActionRunner = typeof ActionRunner.Identifier;");
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
450
|
+
if (!component) {
|
|
451
|
+
yield* cbw.blankLine();
|
|
452
|
+
yield* cbw.writeLine("export const QueryCtx: QueryCtx_.QueryCtxTag<");
|
|
453
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
454
|
+
yield* cbw.writeLine("> = QueryCtx_.QueryCtx<");
|
|
455
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
456
|
+
yield* cbw.writeLine(">();");
|
|
457
|
+
yield* cbw.writeLine("export type QueryCtx = typeof QueryCtx.Identifier;");
|
|
458
|
+
yield* cbw.blankLine();
|
|
459
|
+
yield* cbw.writeLine("export const MutationCtx: MutationCtx_.MutationCtxTag<");
|
|
460
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
461
|
+
yield* cbw.writeLine("> = MutationCtx_.MutationCtx<");
|
|
462
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
463
|
+
yield* cbw.writeLine(">();");
|
|
464
|
+
yield* cbw.writeLine("export type MutationCtx = typeof MutationCtx.Identifier;");
|
|
465
|
+
yield* cbw.blankLine();
|
|
466
|
+
yield* cbw.writeLine("export const ActionCtx: ActionCtx_.ActionCtxTag<");
|
|
467
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
468
|
+
yield* cbw.writeLine("> = ActionCtx_.ActionCtx<");
|
|
469
|
+
yield* cbw.indent(cbw.writeLine("DataModel.ToConvex<DataModel.FromSchema<typeof schemaDefinition>>"));
|
|
470
|
+
yield* cbw.writeLine(">();");
|
|
471
|
+
yield* cbw.writeLine("export type ActionCtx = typeof ActionCtx.Identifier;");
|
|
472
|
+
}
|
|
442
473
|
return yield* cbw.toString();
|
|
443
474
|
});
|
|
444
475
|
const assembledSpec = ({ nodes }) => render(nodes);
|