@gaganref/confect-cli 10.3.1-fork.96 → 10.6.0-fork.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/dist/Ansi.mjs +1 -2
- package/dist/BuildError.mjs +5 -5
- package/dist/BuildError.mjs.map +1 -1
- package/dist/Bundler.mjs +103 -76
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodeBlockWriter.mjs +1 -2
- package/dist/CodegenError.mjs +27 -17
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/ConfectDirectory.mjs +8 -3
- package/dist/ConfectDirectory.mjs.map +1 -1
- package/dist/ConvexConfig.mjs +23 -15
- package/dist/ConvexConfig.mjs.map +1 -1
- package/dist/ConvexDirectory.mjs +6 -4
- package/dist/ConvexDirectory.mjs.map +1 -1
- package/dist/Declaration.mjs +92 -56
- package/dist/Declaration.mjs.map +1 -1
- package/dist/DirectoryOptions.mjs +13 -8
- package/dist/DirectoryOptions.mjs.map +1 -1
- package/dist/DocName.mjs +1 -2
- package/dist/EntryPoint.mjs +17 -15
- package/dist/EntryPoint.mjs.map +1 -1
- package/dist/Evaluation.mjs +24 -13
- package/dist/Evaluation.mjs.map +1 -1
- package/dist/EvaluationWorker.mjs +5 -6
- package/dist/EvaluationWorker.mjs.map +1 -1
- package/dist/FunctionModule.mjs +85 -47
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/FunctionPath.mjs +1 -2
- package/dist/FunctionPath.mjs.map +1 -1
- package/dist/FunctionPaths.mjs +2 -3
- package/dist/GenerationSnapshot.mjs +30 -22
- package/dist/GenerationSnapshot.mjs.map +1 -1
- package/dist/GroupPath.mjs +6 -3
- package/dist/GroupPath.mjs.map +1 -1
- package/dist/GroupPaths.mjs +1 -2
- package/dist/ImplModulePath.mjs +1 -2
- package/dist/Json.mjs +13 -0
- package/dist/Json.mjs.map +1 -0
- package/dist/LeafModule.mjs +121 -41
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ManifestSections.mjs +23 -19
- package/dist/ManifestSections.mjs.map +1 -1
- package/dist/PackageSelfReference.mjs +32 -0
- package/dist/PackageSelfReference.mjs.map +1 -0
- package/dist/ProjectRoot.mjs +11 -3
- package/dist/ProjectRoot.mjs.map +1 -1
- package/dist/RelativeModulePath.mjs +1 -2
- package/dist/Remove.mjs +2 -3
- package/dist/Remove.mjs.map +1 -1
- package/dist/RestoreWatcher.mjs +1 -2
- package/dist/Rollback.mjs +7 -6
- package/dist/Rollback.mjs.map +1 -1
- package/dist/SectionFiles.mjs +77 -48
- package/dist/SectionFiles.mjs.map +1 -1
- package/dist/SnapshotError.mjs +3 -3
- package/dist/SnapshotError.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +1 -2
- package/dist/SpecModulePath.mjs +4 -4
- package/dist/SpecModulePath.mjs.map +1 -1
- package/dist/SyncState.mjs +3 -4
- package/dist/SyncState.mjs.map +1 -1
- package/dist/TableModule.mjs +18 -10
- package/dist/TableModule.mjs.map +1 -1
- package/dist/TableModulePath.mjs +3 -3
- package/dist/TableModulePath.mjs.map +1 -1
- package/dist/TypeScriptConfig.mjs +135 -0
- package/dist/TypeScriptConfig.mjs.map +1 -0
- package/dist/WatchBuild.mjs +107 -32
- package/dist/WatchBuild.mjs.map +1 -1
- package/dist/WatchGraph.mjs +4 -4
- package/dist/WatchGraph.mjs.map +1 -1
- package/dist/WatchTopology.mjs +5 -4
- package/dist/WatchTopology.mjs.map +1 -1
- package/dist/Watcher.mjs +179 -108
- package/dist/Watcher.mjs.map +1 -1
- package/dist/cliApp.mjs +5 -3
- package/dist/cliApp.mjs.map +1 -1
- package/dist/confect/codegen.mjs +95 -53
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/declaration.mjs +76 -42
- package/dist/confect/declaration.mjs.map +1 -1
- package/dist/confect/dev.mjs +18 -12
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/confect.mjs +4 -2
- package/dist/confect.mjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/log.mjs +13 -5
- package/dist/log.mjs.map +1 -1
- package/dist/package.json.mjs +5 -0
- package/dist/package.json.mjs.map +1 -0
- package/dist/templates.mjs +34 -22
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +36 -5
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -10
- package/dist/package.mjs +0 -6
- package/dist/package.mjs.map +0 -1
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","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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,CACvD,GACA,MAAM,UACR;CACF,cACE,OAAO,IAAI,aAAa;EACtB,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,kBAAkB,OAAO,gBAAgB;EAC/C,MAAM,iBAAiB,KAAK,KAAK,iBAAiB,UAAU;EAE5D,IAAI,OAAO,GAAG,OAAO,cAAc,GAAG;GACpC,OAAO,GAAG,OAAO,cAAc;GAC/B,OAAO,sBAAsB,WAAW,cAAc;EACxD;CACF,CAAC;AACL,CAAC,CACH,CACF"}
|
|
1
|
+
{"version":3,"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","validate","Evaluation.validate","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\n/**\n * @internal\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 // oxlint-disable-next-line effecttsgo/strict-effect-provide -- `confect dev` is an entry point: its watch loop runs under the prewarmed evaluator for the whole session.\n}).pipe(Effect.provide(Evaluation.prewarmedLayer));\n\n/**\n * @internal\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 Evaluation.EvaluationError.make({\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: () => Evaluation.generateSnapshot.pipe(preserved, regenerate),\n Validate: ({ paths, snapshot }) => validate(paths, snapshot),\n Update: ({ snapshot, declarations, paths }) =>\n Evaluation.updateDeclarations(snapshot, declarations, paths).pipe(\n preserved,\n regenerate,\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 const remaining = yield* watcher.pending;\n if (!SyncState.isDirty(remaining)) {\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,K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ACX,SAAS,EAAE,QAAQ,qBACjB,MAAM,MAAM,MAAM,CAAC,CAAC,KAClB,MAAM,KAAK,mBAAmB,OAAO,IAAI,GACzC,MAAM,OAAO,SAAS,aAAa,oBACjC,sBAAsB,iBAAiB,cAAc,CACvD,GACA,MAAM,UACR;CACF,cACE,OAAO,IAAI,aAAa;EACtB,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,kBAAkB,OAAO,gBAAgB;EAC/C,MAAM,iBAAiB,KAAK,KAAK,iBAAiB,UAAU;EAE5D,IAAI,OAAO,GAAG,OAAO,cAAc,GAAG;GACpC,OAAO,GAAG,OAAO,cAAc;GAC/B,OAAO,sBAAsB,WAAW,cAAc;EACxD;CACF,CAAC;AACL,CAAC,CACH,CACF"}
|
package/dist/confect.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { codegen } from "./confect/codegen.mjs";
|
|
2
2
|
import { dev } from "./confect/dev.mjs";
|
|
3
3
|
import * as Command from "effect/cli/Command";
|
|
4
|
-
|
|
4
|
+
// src/confect.ts
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
5
8
|
const confect = Command.make("confect").pipe(Command.withDescription("Generate and sync Confect files with Convex"), Command.withSubcommands([codegen, dev]));
|
|
6
|
-
//#endregion
|
|
7
9
|
export { confect };
|
|
8
10
|
|
|
9
11
|
//# sourceMappingURL=confect.mjs.map
|
package/dist/confect.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confect.mjs","names":[],"sources":["../src/confect.ts"],"sourcesContent":["import * as Command from \"effect/cli/Command\";\nimport { codegen } from \"./confect/codegen.js\";\nimport { dev } from \"./confect/dev.js\";\n\nexport const confect = Command.make(\"confect\").pipe(\n Command.withDescription(\"Generate and sync Confect files with Convex\"),\n Command.withSubcommands([codegen, dev]),\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"confect.mjs","names":[],"sources":["../src/confect.ts"],"sourcesContent":["import * as Command from \"effect/cli/Command\";\nimport { codegen } from \"./confect/codegen.js\";\nimport { dev } from \"./confect/dev.js\";\n\n/**\n * @internal\n */\nexport const confect = Command.make(\"confect\").pipe(\n Command.withDescription(\"Generate and sync Confect files with Convex\"),\n Command.withSubcommands([codegen, dev]),\n);\n"],"mappings":";;;;;;;AAOA,MAAa,UAAU,QAAQ,KAAK,SAAS,CAAC,CAAC,KAC7C,QAAQ,gBAAgB,6CAA6C,GACrE,QAAQ,gBAAgB,CAAC,SAAS,GAAG,CAAC,CACxC"}
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { cliApp } from "./cliApp.mjs";
|
|
|
3
3
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
4
4
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
|
-
|
|
6
|
+
// src/index.ts
|
|
7
7
|
const canReRaiseSignals = process.platform !== "win32";
|
|
8
8
|
let interrupted = false;
|
|
9
9
|
process.prependListener("SIGINT", () => {
|
|
@@ -13,7 +13,6 @@ process.on("exit", () => {
|
|
|
13
13
|
if (interrupted && canReRaiseSignals) process.kill(process.pid, "SIGINT");
|
|
14
14
|
});
|
|
15
15
|
cliApp.pipe(Effect.provide(NodeServices.layer), NodeRuntime.runMain);
|
|
16
|
-
//#endregion
|
|
17
16
|
export {};
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=index.mjs.map
|
package/dist/log.mjs
CHANGED
|
@@ -11,15 +11,15 @@ import * as String from "effect/String";
|
|
|
11
11
|
import * as esbuild from "esbuild";
|
|
12
12
|
import * as Console from "effect/Console";
|
|
13
13
|
import * as Predicate from "effect/Predicate";
|
|
14
|
-
|
|
14
|
+
// src/log.ts
|
|
15
15
|
/**
|
|
16
16
|
* Render a relative path with the directory portion dimmed (`Ansi.blackBright`)
|
|
17
17
|
* and the file leaf rendered in the default terminal color.
|
|
18
18
|
*/
|
|
19
19
|
const formatPath = (relativePath) => {
|
|
20
|
-
const lastSep = Math.max(
|
|
21
|
-
const dir = lastSep < 0 ? "" :
|
|
22
|
-
const leaf = lastSep < 0 ? relativePath :
|
|
20
|
+
const lastSep = Math.max(Option.getOrElse(String.lastIndexOf("/")(relativePath), () => -1), Option.getOrElse(String.lastIndexOf("\\")(relativePath), () => -1));
|
|
21
|
+
const dir = lastSep < 0 ? "" : String.slice(0, lastSep + 1)(relativePath);
|
|
22
|
+
const leaf = lastSep < 0 ? relativePath : String.slice(lastSep + 1)(relativePath);
|
|
23
23
|
return blackBright(dir) + leaf;
|
|
24
24
|
};
|
|
25
25
|
const logFile = (char, color) => Effect.fnUntraced(function* (fullPath) {
|
|
@@ -27,8 +27,17 @@ const logFile = (char, color) => Effect.fnUntraced(function* (fullPath) {
|
|
|
27
27
|
const suffix = pipe(fullPath, String.startsWith(prefix)) ? pipe(fullPath, String.slice(prefix.length)) : fullPath;
|
|
28
28
|
yield* Console.log(`${color(char)} ${blackBright(prefix)}${color(suffix)}`);
|
|
29
29
|
});
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
30
33
|
const logFileAdded = logFile("+", green);
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
31
37
|
const logFileRemoved = logFile("-", red);
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
32
41
|
const logFileModified = logFile("~", yellow);
|
|
33
42
|
const logFunction = (char, color) => (functionPath) => Console.log(` ${color(char)} ${blackBright(toString(functionPath.groupPath) + ".")}${color(functionPath.name)}`);
|
|
34
43
|
const logFunctionAdded = logFunction("+", green);
|
|
@@ -101,7 +110,6 @@ const renderCoalescedBuildWarnings = (messages) => {
|
|
|
101
110
|
return `${`${warningSign} Build warnings`}\n${pipe(formatted, Array.join(""), String.trimEnd, withGutterBlock(gutter(yellow)))}`;
|
|
102
111
|
};
|
|
103
112
|
const logCoalescedBuildWarnings = (messages) => messages.length === 0 ? Effect.void : Console.error(renderCoalescedBuildWarnings(messages));
|
|
104
|
-
//#endregion
|
|
105
113
|
export { formatEsbuildMessages, formatPath, logCoalescedBuildErrors, logCoalescedBuildWarnings, logFileAdded, logFileModified, logFileRemoved, logFunctionAdded, logFunctionRemoved, logPending, logSuccess, logWarn, renderBuildError };
|
|
106
114
|
|
|
107
115
|
//# sourceMappingURL=log.mjs.map
|
package/dist/log.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.mjs","names":["Ansi.blackBright","Ansi.green","Ansi.red","Ansi.yellow","GroupPath.toString"],"sources":["../src/log.ts"],"sourcesContent":["import { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as String from \"effect/String\";\nimport * as esbuild from \"esbuild\";\nimport type {\n BuildError,\n BundleFailedError,\n ImportFailedError,\n} from \"./BuildError.js\";\nimport * as Ansi from \"./Ansi.js\";\nimport type * as FunctionPath from \"./FunctionPath.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\n\n// --- Path styling ---\n\n/**\n * Render a relative path with the directory portion dimmed (`Ansi.blackBright`)\n * and the file leaf rendered in the default terminal color.\n */\nexport const formatPath = (relativePath: string): string => {\n const lastSep = Math.max(\n relativePath.lastIndexOf(\"/\"),\n relativePath.lastIndexOf(\"\\\\\"),\n );\n const dir = lastSep < 0 ? \"\" : relativePath.slice(0, lastSep + 1);\n const leaf = lastSep < 0 ? relativePath : relativePath.slice(lastSep + 1);\n return Ansi.blackBright(dir) + leaf;\n};\n\n// --- File operation logs ---\n\nconst logFile = (char: string, color: Ansi.Style) =>\n Effect.fnUntraced(function* (fullPath: string) {\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 yield* Console.log(\n `${color(char)} ${Ansi.blackBright(prefix)}${color(suffix)}`,\n );\n });\n\nexport const logFileAdded = logFile(\"+\", Ansi.green);\n\nexport const logFileRemoved = logFile(\"-\", Ansi.red);\n\nexport const logFileModified = logFile(\"~\", Ansi.yellow);\n\n// --- Function subline logs ---\n\nconst logFunction =\n (char: string, color: Ansi.Style) =>\n (functionPath: FunctionPath.FunctionPath) =>\n Console.log(\n ` ${color(char)} ${Ansi.blackBright(\n GroupPath.toString(functionPath.groupPath) + \".\",\n )}${color(functionPath.name)}`,\n );\n\nexport const logFunctionAdded = logFunction(\"+\", Ansi.green);\n\nexport const logFunctionRemoved = logFunction(\"-\", Ansi.red);\n\n// --- Process status logs ---\n\nconst logStatus = (char: string, charColor: Ansi.Style) => (message: string) =>\n Console.log(`${charColor(char)} ${message}`);\n\nexport const logSuccess = logStatus(\"✔︎\", Ansi.green);\n\nexport const logFailure = logStatus(\"✘\", Ansi.red);\n\nexport const logPending = logStatus(\"⭘\", Ansi.yellow);\n\nexport const logWarn = logStatus(\"⚠\", Ansi.yellow);\n\n// --- Build message rendering ---\n\nconst cross = Ansi.red(\"✘\");\n\nconst warningSign = Ansi.yellow(\"⚠\");\n\nconst gutter = (color: Ansi.Style): string => color(\"│\");\n\nconst errorGutter = gutter(Ansi.red);\n\nconst withGutterBlock =\n (gutterChar: string) =>\n (output: string): string =>\n pipe(\n String.split(output, \"\\n\"),\n Array.map((line) =>\n pipe(line, String.trim) === \"\" ? gutterChar : `${gutterChar} ${line}`,\n ),\n Array.join(\"\\n\"),\n (guttered) => `${gutterChar}\\n${guttered}\\n${gutterChar}`,\n );\n\nconst withErrorGutterBlock = withGutterBlock(errorGutter);\n\nconst formatBuildMessage = (\n error: esbuild.Message | undefined,\n formattedMessage: string,\n): string => {\n const lines = String.split(formattedMessage, \"\\n\");\n const redErrorText = Ansi.red(error?.text ?? \"\");\n const replaced = pipe(\n Array.findFirstIndex(lines, (l) => pipe(l, String.trim, String.isNonEmpty)),\n Option.flatMap((index) => Array.modify(lines, index, () => redErrorText)),\n Option.getOrElse(() => lines),\n );\n return pipe(replaced, Array.join(\"\\n\"));\n};\n\n/**\n * Render a list of esbuild messages into a styled, gutter-prefixed block.\n */\nexport const formatEsbuildMessages = (\n errors: readonly esbuild.Message[],\n formattedMessages: readonly string[],\n): string =>\n pipe(\n formattedMessages,\n Array.map((message, i) => formatBuildMessage(errors[i], message)),\n Array.join(\"\"),\n String.trimEnd,\n withErrorGutterBlock,\n );\n\nconst renderImportFailedError = (error: ImportFailedError): string => {\n const causeMessage = Predicate.isError(error.cause)\n ? error.cause.message\n : Predicate.isString(error.cause)\n ? error.cause\n : globalThis.String(error.cause);\n const oneLineCause = pipe(\n String.split(causeMessage, \"\\n\"),\n Array.findFirst((line) => pipe(line, String.trim, String.isNonEmpty)),\n Option.map(String.trim),\n Option.getOrElse(() => \"unknown error\"),\n );\n return `${cross} Failed to load bundled module ${formatPath(\n error.file,\n )}: ${oneLineCause}; check the file's top-level imports and side effects.`;\n};\n\n/**\n * Render a {@link BundleFailedError} as a multi-line, ANSI-styled string: a\n * one-line `✘ <file>: build errors` header followed by the gutter-prefixed\n * esbuild diagnostic block. Multi-line is appropriate here because a single\n * `BundleFailedError` carries an array of distinct esbuild messages.\n */\nconst renderBundleFailedError = (error: BundleFailedError): string => {\n const messages = error.errors as readonly esbuild.Message[];\n const formatted = esbuild.formatMessagesSync(messages as esbuild.Message[], {\n kind: \"error\",\n color: true,\n terminalWidth: 80,\n });\n const header = `${cross} ${formatPath(error.file)}: build errors`;\n return `${header}\\n${formatEsbuildMessages(messages, formatted)}`;\n};\n\n/**\n * Render any {@link BuildError} into a styled, ready-to-print string.\n * `ImportFailedError` collapses to a single line; `BundleFailedError` expands\n * to a header plus one diagnostic block per esbuild message.\n */\nexport const renderBuildError = (error: BuildError): string =>\n Match.value(error).pipe(\n Match.tag(\"BundleFailedError\", renderBundleFailedError),\n Match.tag(\"ImportFailedError\", renderImportFailedError),\n Match.exhaustive,\n );\n\nexport const logBuildError = (error: BuildError) =>\n Console.error(renderBuildError(error));\n\n/**\n * Render a flat list of esbuild messages as a single error block with a generic\n * `✘ Build errors` header.\n */\nconst renderCoalescedBuildErrors = (\n messages: readonly esbuild.Message[],\n): string => {\n const formatted = esbuild.formatMessagesSync(messages as esbuild.Message[], {\n kind: \"error\",\n color: true,\n terminalWidth: 80,\n });\n const header = `${cross} Build errors`;\n return `${header}\\n${formatEsbuildMessages(messages, formatted)}`;\n};\n\nexport const logCoalescedBuildErrors = (\n messages: readonly esbuild.Message[],\n) =>\n messages.length === 0\n ? Effect.void\n : Console.error(renderCoalescedBuildErrors(messages));\n\nconst renderCoalescedBuildWarnings = (\n messages: readonly esbuild.Message[],\n): string => {\n const formatted = esbuild.formatMessagesSync(messages as esbuild.Message[], {\n kind: \"warning\",\n color: true,\n terminalWidth: 80,\n });\n const header = `${warningSign} Build warnings`;\n const body = pipe(\n formatted,\n Array.join(\"\"),\n String.trimEnd,\n withGutterBlock(gutter(Ansi.yellow)),\n );\n return `${header}\\n${body}`;\n};\n\nexport const logCoalescedBuildWarnings = (\n messages: readonly esbuild.Message[],\n) =>\n messages.length === 0\n ? Effect.void\n : Console.error(renderCoalescedBuildWarnings(messages));\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0BA,MAAa,cAAc,iBAAiC;CAC1D,MAAM,UAAU,KAAK,IACnB,aAAa,YAAY,GAAG,GAC5B,aAAa,YAAY,IAAI,CAC/B;CACA,MAAM,MAAM,UAAU,IAAI,KAAK,aAAa,MAAM,GAAG,UAAU,CAAC;CAChE,MAAM,OAAO,UAAU,IAAI,eAAe,aAAa,MAAM,UAAU,CAAC;CACxE,OAAOA,YAAiB,GAAG,IAAI;AACjC;AAIA,MAAM,WAAW,MAAc,UAC7B,OA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AAK,CAAC,CAAC,KACjB,MAAM,IAAI,qBAAqB,uBAAuB,GACtD,MAAM,IAAI,qBAAqB,uBAAuB,GACtD,MAAM,UACR;;;;;AASF,MAAM,8BACJ,aACW;CACX,MAAM,YAAY,QAAQ,mBAAmB,UAA+B;EAC1E,MAAM;EACN,OAAO;EACP,eAAe;CACjB,CAAC;CAED,OAAO,GAAG,GADQ,MAAM,eACP,IAAI,sBAAsB,UAAU,SAAS;AAChE;AAEA,MAAa,2BACX,aAEA,SAAS,WAAW,IAChB,OAAO,OACP,QAAQ,MAAM,2BAA2B,QAAQ,CAAC;AAExD,MAAM,gCACJ,aACW;CACX,MAAM,YAAY,QAAQ,mBAAmB,UAA+B;EAC1E,MAAM;EACN,OAAO;EACP,eAAe;CACjB,CAAC;CAQD,OAAO,GAAG,GAPQ,YAAY,iBAOb,IANJ,KACX,WACA,MAAM,KAAK,EAAE,GACb,OAAO,SACP,gBAAgB,OAAOC,MAAW,CAAC,CAEb;AAC1B;AAEA,MAAa,6BACX,aAEA,SAAS,WAAW,IAChB,OAAO,OACP,QAAQ,MAAM,6BAA6B,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"log.mjs","names":["Ansi.blackBright","Ansi.green","Ansi.red","Ansi.yellow","GroupPath.toString"],"sources":["../src/log.ts"],"sourcesContent":["import { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Console from \"effect/Console\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as String from \"effect/String\";\nimport * as esbuild from \"esbuild\";\nimport type {\n BuildError,\n BundleFailedError,\n ImportFailedError,\n} from \"./BuildError.js\";\nimport * as Ansi from \"./Ansi.js\";\nimport type * as FunctionPath from \"./FunctionPath.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport { ProjectRoot } from \"./ProjectRoot.js\";\n\n// --- Path styling ---\n\n/**\n * Render a relative path with the directory portion dimmed (`Ansi.blackBright`)\n * and the file leaf rendered in the default terminal color.\n */\nexport const formatPath = (relativePath: string): string => {\n const lastSep = Math.max(\n Option.getOrElse(String.lastIndexOf(\"/\")(relativePath), () => -1),\n Option.getOrElse(String.lastIndexOf(\"\\\\\")(relativePath), () => -1),\n );\n const dir = lastSep < 0 ? \"\" : String.slice(0, lastSep + 1)(relativePath);\n const leaf =\n lastSep < 0 ? relativePath : String.slice(lastSep + 1)(relativePath);\n return Ansi.blackBright(dir) + leaf;\n};\n\n// --- File operation logs ---\n\nconst logFile = (char: string, color: Ansi.Style) =>\n Effect.fnUntraced(function* (fullPath: string) {\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 yield* Console.log(\n `${color(char)} ${Ansi.blackBright(prefix)}${color(suffix)}`,\n );\n });\n\n/**\n * @internal\n */\nexport const logFileAdded = logFile(\"+\", Ansi.green);\n\n/**\n * @internal\n */\nexport const logFileRemoved = logFile(\"-\", Ansi.red);\n\n/**\n * @internal\n */\nexport const logFileModified = logFile(\"~\", Ansi.yellow);\n\n// --- Function subline logs ---\n\nconst logFunction =\n (char: string, color: Ansi.Style) =>\n (functionPath: FunctionPath.FunctionPath) =>\n Console.log(\n ` ${color(char)} ${Ansi.blackBright(\n GroupPath.toString(functionPath.groupPath) + \".\",\n )}${color(functionPath.name)}`,\n );\n\nexport const logFunctionAdded = logFunction(\"+\", Ansi.green);\n\nexport const logFunctionRemoved = logFunction(\"-\", Ansi.red);\n\n// --- Process status logs ---\n\nconst logStatus = (char: string, charColor: Ansi.Style) => (message: string) =>\n Console.log(`${charColor(char)} ${message}`);\n\nexport const logSuccess = logStatus(\"✔︎\", Ansi.green);\n\nexport const logFailure = logStatus(\"✘\", Ansi.red);\n\nexport const logPending = logStatus(\"⭘\", Ansi.yellow);\n\nexport const logWarn = logStatus(\"⚠\", Ansi.yellow);\n\n// --- Build message rendering ---\n\nconst cross = Ansi.red(\"✘\");\n\nconst warningSign = Ansi.yellow(\"⚠\");\n\nconst gutter = (color: Ansi.Style): string => color(\"│\");\n\nconst errorGutter = gutter(Ansi.red);\n\nconst withGutterBlock =\n (gutterChar: string) =>\n (output: string): string =>\n pipe(\n String.split(output, \"\\n\"),\n Array.map((line) =>\n pipe(line, String.trim) === \"\" ? gutterChar : `${gutterChar} ${line}`,\n ),\n Array.join(\"\\n\"),\n (guttered) => `${gutterChar}\\n${guttered}\\n${gutterChar}`,\n );\n\nconst withErrorGutterBlock = withGutterBlock(errorGutter);\n\nconst formatBuildMessage = (\n error: esbuild.Message | undefined,\n formattedMessage: string,\n): string => {\n const lines = String.split(formattedMessage, \"\\n\");\n const redErrorText = Ansi.red(error?.text ?? \"\");\n const replaced = pipe(\n Array.findFirstIndex(lines, (l) => pipe(l, String.trim, String.isNonEmpty)),\n Option.flatMap((index) => Array.modify(lines, index, () => redErrorText)),\n Option.getOrElse(() => lines),\n );\n return pipe(replaced, Array.join(\"\\n\"));\n};\n\n/**\n * Render a list of esbuild messages into a styled, gutter-prefixed block.\n */\nexport const formatEsbuildMessages = (\n errors: readonly esbuild.Message[],\n formattedMessages: readonly string[],\n): string =>\n pipe(\n formattedMessages,\n Array.map((message, i) => formatBuildMessage(errors[i], message)),\n Array.join(\"\"),\n String.trimEnd,\n withErrorGutterBlock,\n );\n\nconst renderImportFailedError = (error: ImportFailedError): string => {\n const causeMessage = Predicate.isError(error.cause)\n ? error.cause.message\n : Predicate.isString(error.cause)\n ? error.cause\n : globalThis.String(error.cause);\n const oneLineCause = pipe(\n String.split(causeMessage, \"\\n\"),\n Array.findFirst((line) => pipe(line, String.trim, String.isNonEmpty)),\n Option.map(String.trim),\n Option.getOrElse(() => \"unknown error\"),\n );\n return `${cross} Failed to load bundled module ${formatPath(\n error.file,\n )}: ${oneLineCause}; check the file's top-level imports and side effects.`;\n};\n\n/**\n * Render a {@link BundleFailedError} as a multi-line, ANSI-styled string: a\n * one-line `✘ <file>: build errors` header followed by the gutter-prefixed\n * esbuild diagnostic block. Multi-line is appropriate here because a single\n * `BundleFailedError` carries an array of distinct esbuild messages.\n */\nconst renderBundleFailedError = (error: BundleFailedError): string => {\n const messages = error.errors as readonly esbuild.Message[];\n const formatted = esbuild.formatMessagesSync(messages as esbuild.Message[], {\n kind: \"error\",\n color: true,\n terminalWidth: 80,\n });\n const header = `${cross} ${formatPath(error.file)}: build errors`;\n return `${header}\\n${formatEsbuildMessages(messages, formatted)}`;\n};\n\n/**\n * Render any {@link BuildError} into a styled, ready-to-print string.\n * `ImportFailedError` collapses to a single line; `BundleFailedError` expands\n * to a header plus one diagnostic block per esbuild message.\n */\nexport const renderBuildError = (error: BuildError): string =>\n Match.value(error).pipe(\n Match.tag(\"BundleFailedError\", renderBundleFailedError),\n Match.tag(\"ImportFailedError\", renderImportFailedError),\n Match.exhaustive,\n );\n\nexport const logBuildError = (error: BuildError) =>\n pipe(error, renderBuildError, Console.error);\n\n/**\n * Render a flat list of esbuild messages as a single error block with a generic\n * `✘ Build errors` header.\n */\nconst renderCoalescedBuildErrors = (\n messages: readonly esbuild.Message[],\n): string => {\n const formatted = esbuild.formatMessagesSync(messages as esbuild.Message[], {\n kind: \"error\",\n color: true,\n terminalWidth: 80,\n });\n const header = `${cross} Build errors`;\n return `${header}\\n${formatEsbuildMessages(messages, formatted)}`;\n};\n\nexport const logCoalescedBuildErrors = (messages: readonly esbuild.Message[]) =>\n messages.length === 0\n ? Effect.void\n : Console.error(renderCoalescedBuildErrors(messages));\n\nconst renderCoalescedBuildWarnings = (\n messages: readonly esbuild.Message[],\n): string => {\n const formatted = esbuild.formatMessagesSync(messages as esbuild.Message[], {\n kind: \"warning\",\n color: true,\n terminalWidth: 80,\n });\n const header = `${warningSign} Build warnings`;\n const body = pipe(\n formatted,\n Array.join(\"\"),\n String.trimEnd,\n withGutterBlock(gutter(Ansi.yellow)),\n );\n return `${header}\\n${body}`;\n};\n\nexport const logCoalescedBuildWarnings = (\n messages: readonly esbuild.Message[],\n) =>\n messages.length === 0\n ? Effect.void\n : Console.error(renderCoalescedBuildWarnings(messages));\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0BA,MAAa,cAAc,iBAAiC;CAC1D,MAAM,UAAU,KAAK,IACnB,OAAO,UAAU,OAAO,YAAY,GAAG,CAAC,CAAC,YAAY,SAAS,EAAE,GAChE,OAAO,UAAU,OAAO,YAAY,IAAI,CAAC,CAAC,YAAY,SAAS,EAAE,CACnE;CACA,MAAM,MAAM,UAAU,IAAI,KAAK,OAAO,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY;CACxE,MAAM,OACJ,UAAU,IAAI,eAAe,OAAO,MAAM,UAAU,CAAC,CAAC,CAAC,YAAY;CACrE,OAAOA,YAAiB,GAAG,IAAI;AACjC;AAIA,MAAM,WAAW,MAAc,UAC7B,OAAO,WAAW,WAAW,UAAkB;CAI7C,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,OAAO,QAAQ,IACb,GAAG,MAAM,IAAI,EAAE,GAAGA,YAAiB,MAAM,IAAI,MAAM,MAAM,GAC3D;AACF,CAAC;;;;AAKH,MAAa,eAAe,QAAQ,KAAKC,KAAU;;;;AAKnD,MAAa,iBAAiB,QAAQ,KAAKC,GAAQ;;;;AAKnD,MAAa,kBAAkB,QAAQ,KAAKC,MAAW;AAIvD,MAAM,eACH,MAAc,WACd,iBACC,QAAQ,IACN,KAAK,MAAM,IAAI,EAAE,GAAGH,YAClBI,SAAmB,aAAa,SAAS,IAAI,GAC/C,IAAI,MAAM,aAAa,IAAI,GAC7B;AAEJ,MAAa,mBAAmB,YAAY,KAAKH,KAAU;AAE3D,MAAa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,6BACX,aAEA,SAAS,WAAW,IAChB,OAAO,OACP,QAAQ,MAAM,6BAA6B,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.mjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/templates.mjs
CHANGED
|
@@ -2,7 +2,11 @@ import { CodeBlockWriter } from "./CodeBlockWriter.mjs";
|
|
|
2
2
|
import { render } from "./SpecAssemblyNode.mjs";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Array from "effect/Array";
|
|
5
|
-
|
|
5
|
+
import { pipe } from "effect/Function";
|
|
6
|
+
import * as Record from "effect/Record";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as String from "effect/String";
|
|
9
|
+
// src/templates.ts
|
|
6
10
|
/**
|
|
7
11
|
* Emit `convex/schema.ts` as a one-line re-export of the codegen-emitted deploy
|
|
8
12
|
* schema in `confect/_generated/convexSchema.ts`. Deploy-time consumers (the
|
|
@@ -118,10 +122,10 @@ const idEffect = Effect.fnUntraced(function* ({ tableNames, scope }) {
|
|
|
118
122
|
yield* cbw.writeLine(`import type { SystemTableNames } from "convex/server";`);
|
|
119
123
|
yield* cbw.blankLine();
|
|
120
124
|
if (scope !== void 0) {
|
|
121
|
-
yield* cbw.writeLine(`export const scope = IdScope.component(${JSON.stringify(scope.slice(10))});`);
|
|
125
|
+
yield* cbw.writeLine(`export const scope = IdScope.component(${JSON.stringify(pipe(scope, String.slice(10)))});`);
|
|
122
126
|
yield* cbw.writeLine(`export const target = { kind: "component", scope } as const;`);
|
|
123
127
|
}
|
|
124
|
-
const union = tableNames.length === 0 ? "never" :
|
|
128
|
+
const union = tableNames.length === 0 ? "never" : Array.join(Array.map(tableNames, (n) => `"${n}"`), " | ");
|
|
125
129
|
yield* cbw.writeLine(`export type TableNames = ${union};`);
|
|
126
130
|
yield* cbw.blankLine();
|
|
127
131
|
yield* cbw.writeLine(`export type Id<TableName extends TableNames | SystemTableNames> = GenericId.GenericId<TableName${scope === void 0 ? "" : ", typeof scope"}>;`);
|
|
@@ -171,7 +175,7 @@ const declaredHttp = Effect.fnUntraced(function* ({ schemaImportPath, httpImport
|
|
|
171
175
|
yield* cbw.writeLine(`import http from "${httpImportPath}";`);
|
|
172
176
|
if (runtimeImportPath !== void 0) yield* cbw.writeLine(`import observability from "${runtimeImportPath}";`);
|
|
173
177
|
yield* cbw.newLine();
|
|
174
|
-
yield* cbw.writeLine(`export default HttpRouter.
|
|
178
|
+
yield* cbw.writeLine(`export default HttpRouter.make(schema, http.routes, { api: http.api${runtimeImportPath === void 0 ? "" : ", observability"} });`);
|
|
175
179
|
return yield* cbw.toString();
|
|
176
180
|
});
|
|
177
181
|
const crons = ({ cronsImportPath }) => cronsEffect({ cronsImportPath });
|
|
@@ -253,8 +257,8 @@ const componentContract = Effect.fnUntraced(function* ({ tableNames }) {
|
|
|
253
257
|
const systemTables = ["_storage", "_scheduled_functions"];
|
|
254
258
|
const names = Array.map([...tableNames, ...systemTables], (name) => `"${name}"`);
|
|
255
259
|
const entries = [...tableNames, ...Array.map(systemTables, (name) => `"${name}"`)];
|
|
256
|
-
const groups = `$Component.Groups<[${Array.map(tableNames, (name) => `typeof ${name}`)
|
|
257
|
-
yield* cbw.writeLine(`const $component: $Component.Component<typeof $spec, typeof $scope, ${
|
|
260
|
+
const groups = `$Component.Groups<[${Array.join(Array.map(tableNames, (name) => `typeof ${name}`), ", ")}]>`;
|
|
261
|
+
yield* cbw.writeLine(`const $component: $Component.Component<typeof $spec, typeof $scope, ${Array.join(names, " | ")}, ${groups}> = $Component.contract($spec, $scope, [${Array.join(entries, ", ")}]);`);
|
|
258
262
|
yield* cbw.writeLine("export default $component;");
|
|
259
263
|
return yield* cbw.toString();
|
|
260
264
|
});
|
|
@@ -311,7 +315,7 @@ const registeredFunctionsForGroupEffect = Effect.fnUntraced(function* ({ spec, s
|
|
|
311
315
|
yield* cbw.writeLine(`import observability from "${runtimeImportPath}";`);
|
|
312
316
|
}
|
|
313
317
|
const useNode = spec.runtime === "Node";
|
|
314
|
-
const hasConfectFunctions = (group) =>
|
|
318
|
+
const hasConfectFunctions = (group) => Array.some(Record.values(group.functions), (functionSpec) => functionSpec.functionProvenance._tag === "Confect") || Array.some(Record.values(group.groups), hasConfectFunctions);
|
|
315
319
|
const forwarding = !useNode && hasConfectFunctions(spec);
|
|
316
320
|
if (useNode) yield* cbw.writeLine(`import { RegisteredNodeFunction } from "@confect/server/node";`);
|
|
317
321
|
else if (!forwarding) yield* cbw.writeLine(`import { RegisteredFunctions } from "@confect/server";`);
|
|
@@ -320,27 +324,31 @@ const registeredFunctionsForGroupEffect = Effect.fnUntraced(function* ({ spec, s
|
|
|
320
324
|
yield* cbw.writeLine(`import databaseSchema from "${schemaImportPath}";`);
|
|
321
325
|
yield* cbw.writeLine(`import groupLayer from "${implImportPath}";`);
|
|
322
326
|
yield* cbw.blankLine();
|
|
323
|
-
const finalizedLayer = required.length === 0 ? "groupLayer" : `groupLayer.pipe(GroupImpl.finalize({ required: [${
|
|
327
|
+
const finalizedLayer = required.length === 0 ? "groupLayer" : `groupLayer.pipe(GroupImpl.finalize({ required: [${Array.join(", ")(Array.map(required, ({ key }) => `{ key: ${JSON.stringify(key)} }`))}], groupPath: ${JSON.stringify(groupPath)} }))`;
|
|
324
328
|
const groupLayer = runtimeImportPath === void 0 ? finalizedLayer : `${finalizedLayer}.pipe(Layer.merge(Layer.succeed(RegisteredFunction.Observability, observability)))`;
|
|
325
329
|
const specType = `typeof import("${specImportPath}")["default"]`;
|
|
326
330
|
if (useNode) yield* cbw.writeLine(`export default RegisteredNodeFunction.buildForGroup<${specType}>(databaseSchema, ${groupLayer});`);
|
|
327
331
|
else if (!forwarding) yield* cbw.writeLine(`export default RegisteredFunctions.buildForGroup<${specType}>(databaseSchema, ${groupLayer});`);
|
|
328
332
|
else {
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
333
|
+
const JsonString = Schema.fromJsonString(Schema.String);
|
|
334
|
+
const bindings = (group, path) => Effect.gen(function* () {
|
|
335
|
+
const functions = yield* Effect.forEach(Record.toEntries(group.functions), Effect.fnUntraced(function* ([name, functionSpec]) {
|
|
336
|
+
const key = yield* Schema.encodeEffect(JsonString)(name).pipe(Effect.orDie);
|
|
337
|
+
const definition = `${path}[${key}]`;
|
|
338
|
+
return `[${key}]: ${functionSpec.functionProvenance._tag === "Convex" ? `${definition}.handler` : `RegisteredConvexFunction.register({ ...${definition}, handler: forward(${definition}.handler) })`},`;
|
|
339
|
+
}));
|
|
340
|
+
const groups = yield* Effect.forEach(Record.toEntries(group.groups), Effect.fnUntraced(function* ([name, child]) {
|
|
341
|
+
const key = yield* Schema.encodeEffect(JsonString)(name).pipe(Effect.orDie);
|
|
342
|
+
return `[${key}]: ${yield* bindings(child, `${path}[${key}]`)},`;
|
|
343
|
+
}));
|
|
344
|
+
return `{\n${Array.join([...functions, ...groups], "\n")}\n}`;
|
|
345
|
+
});
|
|
346
|
+
const registered = yield* bindings(spec, "definitions");
|
|
339
347
|
yield* cbw.writeLine(`const forward = <Ctx, Args, Returns>(handler: (ctx: Ctx, args: Args) => Promise<Returns>) => (ctx: Ctx, args: Args) => handler(ctx, args);
|
|
340
348
|
|
|
341
349
|
const definitions = ConvexFunctionDefinitions.buildForGroup<${specType}>(databaseSchema, ${groupLayer});
|
|
342
350
|
|
|
343
|
-
export default ${
|
|
351
|
+
export default ${registered} as RegisteredFunctions.RegisteredFunctionsForGroupSpec<${specType}>;`);
|
|
344
352
|
}
|
|
345
353
|
return yield* cbw.toString();
|
|
346
354
|
});
|
|
@@ -354,11 +362,13 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
354
362
|
yield* cbw.indent(Effect.gen(function* () {
|
|
355
363
|
if (!component) yield* cbw.writeLine("ActionCtx as ActionCtx_,");
|
|
356
364
|
yield* cbw.writeLine("ActionRunner as ActionRunner_,");
|
|
357
|
-
yield* cbw.writeLine("Auth as Auth_,");
|
|
365
|
+
if (!component) yield* cbw.writeLine("Auth as Auth_,");
|
|
358
366
|
yield* cbw.writeLine("type DataModel,");
|
|
359
367
|
yield* cbw.writeLine("DatabaseReader as DatabaseReader_,");
|
|
360
368
|
yield* cbw.writeLine("DatabaseWriter as DatabaseWriter_,");
|
|
369
|
+
yield* cbw.writeLine("DocumentIds as DocumentIds_,");
|
|
361
370
|
yield* cbw.writeLine("ExecutionMetadata as ExecutionMetadata_,");
|
|
371
|
+
yield* cbw.writeLine("MutationAuth as MutationAuth_,");
|
|
362
372
|
if (!component) yield* cbw.writeLine("MutationCtx as MutationCtx_,");
|
|
363
373
|
yield* cbw.writeLine("MutationRunner as MutationRunner_,");
|
|
364
374
|
yield* cbw.writeLine("MutationTransactionContext as MutationTransactionContext_,");
|
|
@@ -383,7 +393,7 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
383
393
|
yield* cbw.writeLine("export const Auth = Auth_.Auth;");
|
|
384
394
|
yield* cbw.writeLine("export type Auth = typeof Auth.Identifier;");
|
|
385
395
|
}
|
|
386
|
-
yield* cbw.writeLine("export const MutationAuth =
|
|
396
|
+
yield* cbw.writeLine("export const MutationAuth = MutationAuth_.MutationAuth;");
|
|
387
397
|
yield* cbw.writeLine("export type MutationAuth = typeof MutationAuth.Identifier;");
|
|
388
398
|
yield* cbw.blankLine();
|
|
389
399
|
yield* cbw.writeLine("export const ExecutionMetadata = ExecutionMetadata_.ExecutionMetadata;");
|
|
@@ -417,6 +427,9 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
417
427
|
yield* cbw.writeLine("> = VectorSearch_.VectorSearch<DataModel.FromSchema<typeof schemaDefinition>>();");
|
|
418
428
|
yield* cbw.writeLine("export type VectorSearch = typeof VectorSearch.Identifier;");
|
|
419
429
|
yield* cbw.blankLine();
|
|
430
|
+
yield* cbw.writeLine("export const DocumentIds: DocumentIds_.DocumentIdsTag<typeof schemaDefinition> = DocumentIds_.DocumentIds<typeof schemaDefinition>();");
|
|
431
|
+
yield* cbw.writeLine("export type DocumentIds = typeof DocumentIds.Identifier;");
|
|
432
|
+
yield* cbw.blankLine();
|
|
420
433
|
yield* cbw.writeLine("export const DatabaseReader: DatabaseReader_.DatabaseReaderTag<");
|
|
421
434
|
yield* cbw.indent(Effect.gen(function* () {
|
|
422
435
|
yield* cbw.writeLine("typeof schemaDefinition,");
|
|
@@ -473,7 +486,6 @@ const servicesEffect = Effect.fnUntraced(function* ({ schemaImportPath, componen
|
|
|
473
486
|
return yield* cbw.toString();
|
|
474
487
|
});
|
|
475
488
|
const assembledSpec = ({ nodes }) => render(nodes);
|
|
476
|
-
//#endregion
|
|
477
489
|
export { assembledSpec, authConfig, componentContract, components, convexSchema, crons, declaredHttp, docs, http, id, refs, registeredFunctionsForGroup, runtimeSchema, schema, services, tableWrapper };
|
|
478
490
|
|
|
479
491
|
//# sourceMappingURL=templates.mjs.map
|