@gaganref/confect-cli 10.3.1-fork.96 → 10.6.0-fork.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/Ansi.mjs +1 -2
  3. package/dist/BuildError.mjs +5 -5
  4. package/dist/BuildError.mjs.map +1 -1
  5. package/dist/Bundler.mjs +103 -76
  6. package/dist/Bundler.mjs.map +1 -1
  7. package/dist/CodeBlockWriter.mjs +1 -2
  8. package/dist/CodegenError.mjs +27 -17
  9. package/dist/CodegenError.mjs.map +1 -1
  10. package/dist/ConfectDirectory.mjs +8 -3
  11. package/dist/ConfectDirectory.mjs.map +1 -1
  12. package/dist/ConvexConfig.mjs +23 -15
  13. package/dist/ConvexConfig.mjs.map +1 -1
  14. package/dist/ConvexDirectory.mjs +6 -4
  15. package/dist/ConvexDirectory.mjs.map +1 -1
  16. package/dist/Declaration.mjs +92 -56
  17. package/dist/Declaration.mjs.map +1 -1
  18. package/dist/DirectoryOptions.mjs +13 -8
  19. package/dist/DirectoryOptions.mjs.map +1 -1
  20. package/dist/DocName.mjs +1 -2
  21. package/dist/EntryPoint.mjs +17 -15
  22. package/dist/EntryPoint.mjs.map +1 -1
  23. package/dist/Evaluation.mjs +24 -13
  24. package/dist/Evaluation.mjs.map +1 -1
  25. package/dist/EvaluationWorker.mjs +5 -6
  26. package/dist/EvaluationWorker.mjs.map +1 -1
  27. package/dist/FunctionModule.mjs +85 -47
  28. package/dist/FunctionModule.mjs.map +1 -1
  29. package/dist/FunctionPath.mjs +1 -2
  30. package/dist/FunctionPath.mjs.map +1 -1
  31. package/dist/FunctionPaths.mjs +2 -3
  32. package/dist/GenerationSnapshot.mjs +30 -22
  33. package/dist/GenerationSnapshot.mjs.map +1 -1
  34. package/dist/GroupPath.mjs +6 -3
  35. package/dist/GroupPath.mjs.map +1 -1
  36. package/dist/GroupPaths.mjs +1 -2
  37. package/dist/ImplModulePath.mjs +1 -2
  38. package/dist/Json.mjs +13 -0
  39. package/dist/Json.mjs.map +1 -0
  40. package/dist/LeafModule.mjs +121 -41
  41. package/dist/LeafModule.mjs.map +1 -1
  42. package/dist/ManifestSections.mjs +23 -19
  43. package/dist/ManifestSections.mjs.map +1 -1
  44. package/dist/PackageSelfReference.mjs +32 -0
  45. package/dist/PackageSelfReference.mjs.map +1 -0
  46. package/dist/ProjectRoot.mjs +11 -3
  47. package/dist/ProjectRoot.mjs.map +1 -1
  48. package/dist/RelativeModulePath.mjs +1 -2
  49. package/dist/Remove.mjs +2 -3
  50. package/dist/Remove.mjs.map +1 -1
  51. package/dist/RestoreWatcher.mjs +1 -2
  52. package/dist/Rollback.mjs +7 -6
  53. package/dist/Rollback.mjs.map +1 -1
  54. package/dist/SectionFiles.mjs +77 -48
  55. package/dist/SectionFiles.mjs.map +1 -1
  56. package/dist/SnapshotError.mjs +3 -3
  57. package/dist/SnapshotError.mjs.map +1 -1
  58. package/dist/SpecAssemblyNode.mjs +1 -2
  59. package/dist/SpecModulePath.mjs +4 -4
  60. package/dist/SpecModulePath.mjs.map +1 -1
  61. package/dist/SyncState.mjs +3 -4
  62. package/dist/SyncState.mjs.map +1 -1
  63. package/dist/TableModule.mjs +18 -10
  64. package/dist/TableModule.mjs.map +1 -1
  65. package/dist/TableModulePath.mjs +3 -3
  66. package/dist/TableModulePath.mjs.map +1 -1
  67. package/dist/TypeScriptConfig.mjs +135 -0
  68. package/dist/TypeScriptConfig.mjs.map +1 -0
  69. package/dist/WatchBuild.mjs +107 -32
  70. package/dist/WatchBuild.mjs.map +1 -1
  71. package/dist/WatchGraph.mjs +4 -4
  72. package/dist/WatchGraph.mjs.map +1 -1
  73. package/dist/WatchTopology.mjs +5 -4
  74. package/dist/WatchTopology.mjs.map +1 -1
  75. package/dist/Watcher.mjs +179 -108
  76. package/dist/Watcher.mjs.map +1 -1
  77. package/dist/cliApp.mjs +5 -3
  78. package/dist/cliApp.mjs.map +1 -1
  79. package/dist/confect/codegen.mjs +95 -53
  80. package/dist/confect/codegen.mjs.map +1 -1
  81. package/dist/confect/declaration.mjs +76 -42
  82. package/dist/confect/declaration.mjs.map +1 -1
  83. package/dist/confect/dev.mjs +18 -12
  84. package/dist/confect/dev.mjs.map +1 -1
  85. package/dist/confect.mjs +4 -2
  86. package/dist/confect.mjs.map +1 -1
  87. package/dist/index.mjs +1 -2
  88. package/dist/log.mjs +13 -5
  89. package/dist/log.mjs.map +1 -1
  90. package/dist/package.json.mjs +5 -0
  91. package/dist/package.json.mjs.map +1 -0
  92. package/dist/templates.mjs +34 -22
  93. package/dist/templates.mjs.map +1 -1
  94. package/dist/utils.mjs +36 -5
  95. package/dist/utils.mjs.map +1 -1
  96. package/package.json +10 -10
  97. package/dist/package.mjs +0 -6
  98. package/dist/package.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"GenerationSnapshot.mjs","names":["GroupPath.GroupPath","GroupPath.make","GroupPath.append"],"sources":["../src/GenerationSnapshot.ts"],"sourcesContent":["import { type GroupSpec, Identifier } from \"@confect/core\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as String from \"effect/String\";\nimport { ParentChildNameCollisionError } from \"./CodegenError.js\";\nimport * as FunctionPath from \"./FunctionPath.js\";\nimport * as FunctionPaths from \"./FunctionPaths.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport * as SpecModulePath from \"./SpecModulePath.js\";\nimport { SnapshotError } from \"./SnapshotError.js\";\n\nexport { SnapshotError } from \"./SnapshotError.js\";\n\nexport const GroupSummary = Schema.Struct({\n path: GroupPath.GroupPath,\n runtime: Schema.Literals([\"Convex\", \"Node\"]),\n functionNames: Schema.Array(Schema.NonEmptyString),\n});\nexport interface GroupSummary extends Schema.Schema.Type<typeof GroupSummary> {}\n\nexport interface GroupTree {\n readonly runtime: \"Convex\" | \"Node\";\n readonly functionNames: ReadonlyArray<string>;\n readonly groups: { readonly [name: string]: GroupTree };\n}\n\nexport const GroupTree: Schema.Codec<GroupTree> = Schema.Struct({\n runtime: GroupSummary.fields.runtime,\n functionNames: GroupSummary.fields.functionNames,\n groups: Schema.Record(\n Schema.String,\n Schema.suspend(() => GroupTree),\n ),\n});\n\nclass Snapshot {\n readonly #leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>;\n\n private constructor(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ) {\n this.#leaves = leaves;\n }\n\n static parseLeaves(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ): Result.Result<GenerationSnapshot, ParentChildNameCollisionError> {\n return Result.map(\n parseNoParentChildNameCollisions(leaves),\n (parsed) => new Snapshot(parsed),\n );\n }\n\n get leaves(): HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree> {\n return this.#leaves;\n }\n}\n\nexport interface GenerationSnapshot extends Snapshot {}\n\nconst Entries = Schema.Array(Schema.Tuple([Schema.String, GroupTree]));\nconst CanonicalSpecPath = SpecModulePath.SpecModulePath.check(\n Schema.makeFilter((path) => !path.includes(\"\\\\\")),\n);\nconst rootPath = (path: SpecModulePath.SpecModulePath) =>\n GroupPath.make(String.split(path.slice(0, -\".spec.ts\".length), \"/\"));\n\nconst parseTree = (\n relativePath: SpecModulePath.SpecModulePath,\n path: GroupPath.GroupPath,\n tree: GroupTree,\n): Result.Result<GroupTree, SnapshotError> =>\n Result.gen(function* () {\n yield* Result.try({\n try: () => {\n for (const name of tree.functionNames)\n Identifier.validateConfectFunctionIdentifier(name);\n },\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (\n HashSet.size(HashSet.fromIterable(tree.functionNames)) !==\n tree.functionNames.length\n ) {\n return yield* Result.fail(\n new SnapshotError({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n for (const [name, child] of Object.entries(tree.groups)) {\n yield* Result.try({\n try: () => Identifier.validateConfectFunctionIdentifier(name),\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: [...path.pathSegments, name],\n }),\n });\n yield* parseTree(relativePath, GroupPath.append(path, name), child);\n }\n return tree;\n });\n\nconst fromEntries = (\n entries: ReadonlyArray<readonly [string, GroupTree]>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n let leaves = HashMap.empty<SpecModulePath.SpecModulePath, GroupTree>();\n for (const [key, tree] of entries) {\n const relativePath = yield* Schema.decodeResult(CanonicalSpecPath)(\n key,\n ).pipe(\n Result.mapError(\n (cause) =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath: key,\n pathSegments: [],\n cause,\n }),\n ),\n );\n const path = rootPath(relativePath);\n yield* Result.try({\n try: () => {\n for (const segment of path.pathSegments)\n Identifier.validateConfectFunctionIdentifier(segment);\n },\n catch: () =>\n new SnapshotError({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (HashMap.has(leaves, relativePath)) {\n return yield* Result.fail(\n new SnapshotError({\n reason: \"DuplicateLeaf\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n const parsed = yield* parseTree(relativePath, path, tree);\n leaves = HashMap.set(leaves, relativePath, parsed);\n }\n return yield* Snapshot.parseLeaves(leaves);\n });\n\nexport const parse = (\n input: unknown,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Schema.decodeUnknownResult(Entries)(input).pipe(\n Result.mapError(\n (cause) =>\n new SnapshotError({\n reason: \"InvalidShape\",\n relativePath: \"\",\n pathSegments: [],\n cause,\n }),\n ),\n Result.flatMap(fromEntries),\n );\n\nexport const GenerationSnapshot = Entries.pipe(\n Schema.decodeTo(\n Schema.declare<GenerationSnapshot>((input) => input instanceof Snapshot),\n {\n decode: SchemaGetter.transformEffect((entries, options) =>\n Effect.fromResult(fromEntries(entries)).pipe(\n Effect.mapError(\n (error) =>\n new SchemaIssue.InvalidValue(\n {\n message: Match.value(error).pipe(\n Match.tagsExhaustive({\n SnapshotError: (failure) => failure.message,\n ParentChildNameCollisionError: (failure) =>\n `${failure.parentSpecPath} declares a ${failure.collisionKind} named ${failure.collisionName} that collides with ${failure.childSpecPath}`,\n }),\n ),\n },\n entries,\n options,\n ),\n ),\n ),\n ),\n encode: SchemaGetter.transform((snapshot) =>\n HashMap.toEntries(snapshot.leaves),\n ),\n },\n ),\n);\n\nconst summarize = (group: GroupSpec.AnyWithProps): GroupTree => ({\n runtime: group.runtime,\n functionNames: Record.keys(group.functions),\n groups: Record.map(group.groups, summarize),\n});\n\nexport const update = (\n snapshot: GenerationSnapshot,\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n if (leaves.length === 0) return snapshot;\n const replacement = yield* fromLoadedLeaves(leaves);\n return yield* Snapshot.parseLeaves(\n HashMap.union(snapshot.leaves, replacement.leaves),\n );\n });\n\nexport const fromLoadedLeaves = (\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n parse(\n leaves.map(\n (leaf) =>\n [\n leaf.relativePath.replaceAll(\"\\\\\", \"/\"),\n summarize(leaf.spec),\n ] as const,\n ),\n );\n\nconst groups = (snapshot: GenerationSnapshot): ReadonlyArray<GroupSummary> => {\n const visit = (\n path: GroupPath.GroupPath,\n tree: GroupTree,\n ): ReadonlyArray<GroupSummary> => [\n {\n path,\n runtime: tree.runtime,\n functionNames: Array.sort(tree.functionNames, String.Order),\n },\n ...Array.flatMap(\n Array.sort(Object.keys(tree.groups), String.Order),\n (name: string) => visit(GroupPath.append(path, name), tree.groups[name]!),\n ),\n ];\n return Array.flatMap(Array.fromIterable(snapshot.leaves), ([path, tree]) =>\n visit(rootPath(path), tree),\n );\n};\n\nexport const functionPaths = (\n snapshot: GenerationSnapshot,\n): FunctionPaths.FunctionPaths =>\n FunctionPaths.FunctionPaths.make(\n HashSet.fromIterable(\n Array.flatMap(groups(snapshot), (group) =>\n group.functionNames.map((name) =>\n FunctionPath.FunctionPath.make({ groupPath: group.path, name }),\n ),\n ),\n ),\n );\n\nconst generatedGroups = (snapshot: GenerationSnapshot) =>\n HashMap.fromIterable(\n Array.filterMap(groups(snapshot), (group) =>\n group.functionNames.length === 0\n ? Result.fail(undefined)\n : Result.succeed([group.path, group] as const),\n ),\n );\n\nexport interface ModulePlan {\n readonly removed: ReadonlyArray<GroupPath.GroupPath>;\n readonly changed: ReadonlyArray<GroupSummary>;\n}\n\nexport const plan = (\n snapshot: GenerationSnapshot,\n existing: Iterable<GroupPath.GroupPath>,\n): ModulePlan => {\n const current = generatedGroups(snapshot);\n return {\n removed: Array.fromIterable(existing).filter(\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.fromIterable(HashMap.values(current)),\n };\n};\n\nconst equivalentGroup = Schema.toEquivalence(GroupSummary);\n\nexport const diff = (\n before: GenerationSnapshot,\n after: GenerationSnapshot,\n): ModulePlan => {\n const previous = generatedGroups(before);\n const current = generatedGroups(after);\n return {\n removed: Array.filter(\n HashMap.keys(previous),\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.filter(HashMap.values(current), (group) => {\n const old = HashMap.get(previous, group.path);\n return Option.isNone(old) || !equivalentGroup(old.value, group);\n }),\n };\n};\n\nconst parseNoParentChildNameCollisions = (\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n): Result.Result<\n HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ParentChildNameCollisionError\n> => {\n for (const childPath of HashMap.keys(leaves)) {\n const segments = rootPath(childPath).pathSegments;\n for (let depth = 1; depth < segments.length; depth++) {\n const parentPath = SpecModulePath.SpecModulePath.make(\n `${segments.slice(0, depth).join(\"/\")}.spec.ts`,\n );\n const parent = HashMap.get(leaves, parentPath);\n if (Option.isNone(parent)) continue;\n const collisionName = segments[depth]!;\n const collisionKind = parent.value.functionNames.includes(collisionName)\n ? \"function\"\n : Object.hasOwn(parent.value.groups, collisionName)\n ? \"group\"\n : undefined;\n if (collisionKind !== undefined) {\n return Result.fail(\n new ParentChildNameCollisionError({\n parentSpecPath: parentPath,\n childSpecPath: childPath,\n collisionName,\n collisionKind,\n }),\n );\n }\n }\n }\n return Result.succeed(leaves);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,eAAe,OAAO,OAAO;CACxC,MAAMA;CACN,SAAS,OAAO,SAAS,CAAC,UAAU,MAAM,CAAC;CAC3C,eAAe,OAAO,MAAM,OAAO,cAAc;AACnD,CAAC;AASD,MAAa,YAAqC,OAAO,OAAO;CAC9D,SAAS,aAAa,OAAO;CAC7B,eAAe,aAAa,OAAO;CACnC,QAAQ,OAAO,OACb,OAAO,QACP,OAAO,cAAc,SAAS,CAChC;AACF,CAAC;AAED,IAAM,WAAN,MAAM,SAAS;CACb;CAEA,YACE,QACA;EACA,KAAK,UAAU;CACjB;CAEA,OAAO,YACL,QACkE;EAClE,OAAO,OAAO,IACZ,iCAAiC,MAAM,IACtC,WAAW,IAAI,SAAS,MAAM,CACjC;CACF;CAEA,IAAI,SAAoE;EACtE,OAAO,KAAK;CACd;AACF;AAIA,MAAM,UAAU,OAAO,MAAM,OAAO,MAAM,CAAC,OAAO,QAAQ,SAAS,CAAC,CAAC;AACrE,MAAM,oBAAA,eAAkD,MACt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":["GroupPath.GroupPath","GroupPath.make","GroupPath.append"],"sources":["../src/GenerationSnapshot.ts"],"sourcesContent":["import { type GroupSpec, Identifier } from \"@confect/core\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as String from \"effect/String\";\nimport { ParentChildNameCollisionError } from \"./CodegenError.js\";\nimport * as FunctionPath from \"./FunctionPath.js\";\nimport * as FunctionPaths from \"./FunctionPaths.js\";\nimport * as GroupPath from \"./GroupPath.js\";\nimport type { LoadedLeafModule } from \"./LeafModule.js\";\nimport * as SpecModulePath from \"./SpecModulePath.js\";\nimport { SnapshotError } from \"./SnapshotError.js\";\n\nexport { SnapshotError } from \"./SnapshotError.js\";\n\nexport const GroupSummary = Schema.Struct({\n path: GroupPath.GroupPath,\n runtime: Schema.Literals([\"Convex\", \"Node\"]),\n experimental_reuseContext: Schema.optionalKey(Schema.Boolean),\n functionNames: Schema.Array(Schema.NonEmptyString),\n});\nexport type GroupSummary = typeof GroupSummary.Type;\n\nexport interface GroupTree {\n readonly runtime: \"Convex\" | \"Node\";\n readonly experimental_reuseContext?: boolean;\n readonly functionNames: ReadonlyArray<string>;\n readonly groups: { readonly [name: string]: GroupTree };\n}\n\nexport const GroupTree: Schema.Codec<GroupTree> = Schema.Struct({\n runtime: GroupSummary.fields.runtime,\n experimental_reuseContext: GroupSummary.fields.experimental_reuseContext,\n functionNames: GroupSummary.fields.functionNames,\n groups: Schema.Record(\n Schema.String,\n Schema.suspend(() => GroupTree),\n ),\n});\n\nclass Snapshot {\n readonly #leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>;\n\n private constructor(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ) {\n this.#leaves = leaves;\n }\n\n static parseLeaves(\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ): Result.Result<GenerationSnapshot, ParentChildNameCollisionError> {\n return Result.map(\n parseNoParentChildNameCollisions(leaves),\n (parsed) => new Snapshot(parsed),\n );\n }\n\n get leaves(): HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree> {\n return this.#leaves;\n }\n}\n\nexport interface GenerationSnapshot extends Snapshot {}\n\nconst Entries = Schema.Array(Schema.Tuple([Schema.String, GroupTree]));\nconst CanonicalSpecPath = SpecModulePath.SpecModulePath.check(\n Schema.makeFilter((path) => !String.includes(\"\\\\\")(path)),\n);\nconst rootPath = (path: SpecModulePath.SpecModulePath) =>\n GroupPath.make(String.split(String.slice(0, -\".spec.ts\".length)(path), \"/\"));\n\nconst parseTree = (\n relativePath: SpecModulePath.SpecModulePath,\n path: GroupPath.GroupPath,\n tree: GroupTree,\n): Result.Result<GroupTree, SnapshotError> =>\n Result.gen(function* () {\n if (\n tree.experimental_reuseContext === true &&\n (tree.runtime === \"Node\" ||\n tree.functionNames.includes(\"experimental_reuseContext\"))\n ) {\n return yield* Result.fail(\n SnapshotError.make({\n reason: \"InvalidContextReuse\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n yield* Result.try({\n try: () => {\n for (const name of tree.functionNames)\n Identifier.validateConfectFunctionIdentifier(name);\n },\n catch: () =>\n SnapshotError.make({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (\n HashSet.size(HashSet.fromIterable(tree.functionNames)) !==\n tree.functionNames.length\n ) {\n return yield* Result.fail(\n SnapshotError.make({\n reason: \"NoncanonicalFunctionNames\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n for (const [name, child] of Record.toEntries(tree.groups)) {\n yield* Result.try({\n try: () => Identifier.validateConfectFunctionIdentifier(name),\n catch: () =>\n SnapshotError.make({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: [...path.pathSegments, name],\n }),\n });\n yield* parseTree(relativePath, GroupPath.append(path, name), child);\n }\n return tree;\n });\n\nconst fromEntries = (\n entries: ReadonlyArray<readonly [string, GroupTree]>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n let leaves = HashMap.empty<SpecModulePath.SpecModulePath, GroupTree>();\n for (const [key, tree] of entries) {\n const relativePath = yield* Schema.decodeResult(CanonicalSpecPath)(\n key,\n ).pipe(\n Result.mapError((cause) =>\n SnapshotError.make({\n reason: \"NoncanonicalPath\",\n relativePath: key,\n pathSegments: [],\n cause,\n }),\n ),\n );\n const path = rootPath(relativePath);\n yield* Result.try({\n try: () => {\n for (const segment of path.pathSegments)\n Identifier.validateConfectFunctionIdentifier(segment);\n },\n catch: () =>\n SnapshotError.make({\n reason: \"NoncanonicalPath\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n });\n if (HashMap.has(leaves, relativePath)) {\n return yield* Result.fail(\n SnapshotError.make({\n reason: \"DuplicateLeaf\",\n relativePath,\n pathSegments: path.pathSegments,\n }),\n );\n }\n const parsed = yield* parseTree(relativePath, path, tree);\n leaves = HashMap.set(leaves, relativePath, parsed);\n }\n return yield* Snapshot.parseLeaves(leaves);\n });\n\nexport const parse = (\n input: unknown,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Schema.decodeUnknownResult(Entries)(input).pipe(\n Result.mapError((cause) =>\n SnapshotError.make({\n reason: \"InvalidShape\",\n relativePath: \"\",\n pathSegments: [],\n cause,\n }),\n ),\n Result.flatMap(fromEntries),\n );\n\nexport const GenerationSnapshot = Entries.pipe(\n Schema.decodeTo(\n Schema.declare<GenerationSnapshot>((input) => input instanceof Snapshot),\n {\n decode: SchemaGetter.transformEffect((entries, options) =>\n Effect.fromResult(fromEntries(entries)).pipe(\n Effect.mapError(\n (error) =>\n new SchemaIssue.InvalidValue(\n {\n message: Match.value(error).pipe(\n Match.tagsExhaustive({\n SnapshotError: (failure) => failure.message,\n ParentChildNameCollisionError: (failure) =>\n `${failure.parentSpecPath} declares a ${failure.collisionKind} named ${failure.collisionName} that collides with ${failure.childSpecPath}`,\n }),\n ),\n },\n entries,\n options,\n ),\n ),\n ),\n ),\n encode: SchemaGetter.transform((snapshot) =>\n HashMap.toEntries(snapshot.leaves),\n ),\n },\n ),\n);\n\nconst summarize = (group: GroupSpec.AnyWithProps): GroupTree => ({\n runtime: group.runtime,\n ...(group.experimental_reuseContext\n ? { experimental_reuseContext: true }\n : {}),\n functionNames: Record.keys(group.functions),\n groups: Record.map(group.groups, summarize),\n});\n\nexport const update = (\n snapshot: GenerationSnapshot,\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n Result.gen(function* () {\n if (leaves.length === 0) return snapshot;\n const replacement = yield* fromLoadedLeaves(leaves);\n return yield* Snapshot.parseLeaves(\n HashMap.union(snapshot.leaves, replacement.leaves),\n );\n });\n\nexport const fromLoadedLeaves = (\n leaves: ReadonlyArray<LoadedLeafModule>,\n): Result.Result<\n GenerationSnapshot,\n SnapshotError | ParentChildNameCollisionError\n> =>\n parse(\n Array.map(\n leaves,\n (leaf) =>\n [\n String.replaceAll(\"\\\\\", \"/\")(leaf.relativePath),\n summarize(leaf.spec),\n ] as const,\n ),\n );\n\nconst groups = (snapshot: GenerationSnapshot): ReadonlyArray<GroupSummary> => {\n const visit = (\n path: GroupPath.GroupPath,\n tree: GroupTree,\n ): ReadonlyArray<GroupSummary> => [\n {\n path,\n runtime: tree.runtime,\n ...(tree.experimental_reuseContext === true\n ? { experimental_reuseContext: true }\n : {}),\n functionNames: Array.sort(tree.functionNames, String.Order),\n },\n ...Array.flatMap(\n Array.sort(Record.keys(tree.groups), String.Order),\n (name: string) => visit(GroupPath.append(path, name), tree.groups[name]!),\n ),\n ];\n return Array.flatMap(Array.fromIterable(snapshot.leaves), ([path, tree]) =>\n visit(rootPath(path), tree),\n );\n};\n\nexport const functionPaths = (\n snapshot: GenerationSnapshot,\n): FunctionPaths.FunctionPaths =>\n FunctionPaths.FunctionPaths.make(\n HashSet.fromIterable(\n Array.flatMap(groups(snapshot), (group) =>\n Array.map(group.functionNames, (name) =>\n FunctionPath.FunctionPath.make({ groupPath: group.path, name }),\n ),\n ),\n ),\n );\n\nconst generatedGroups = (snapshot: GenerationSnapshot) =>\n HashMap.fromIterable(\n Array.filterMap(groups(snapshot), (group) =>\n group.functionNames.length === 0\n ? Result.fail(undefined)\n : Result.succeed([group.path, group] as const),\n ),\n );\n\nexport interface ModulePlan {\n readonly removed: ReadonlyArray<GroupPath.GroupPath>;\n readonly changed: ReadonlyArray<GroupSummary>;\n}\n\nexport const plan = (\n snapshot: GenerationSnapshot,\n existing: Iterable<GroupPath.GroupPath>,\n): ModulePlan => {\n const current = generatedGroups(snapshot);\n return {\n removed: Array.filter(\n Array.fromIterable(existing),\n (path) => !HashMap.has(current, path),\n ),\n changed: current.pipe(HashMap.values, Array.fromIterable),\n };\n};\n\nconst equivalentGroup = Schema.toEquivalence(GroupSummary);\n\nexport const diff = (\n before: GenerationSnapshot,\n after: GenerationSnapshot,\n): ModulePlan => {\n const previous = generatedGroups(before);\n const current = generatedGroups(after);\n return {\n removed: Array.filter(\n HashMap.keys(previous),\n (path) => !HashMap.has(current, path),\n ),\n changed: Array.filter(HashMap.values(current), (group) => {\n const old = HashMap.get(previous, group.path);\n return Option.isNone(old) || !equivalentGroup(old.value, group);\n }),\n };\n};\n\nconst parseNoParentChildNameCollisions = (\n leaves: HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n): Result.Result<\n HashMap.HashMap<SpecModulePath.SpecModulePath, GroupTree>,\n ParentChildNameCollisionError\n> => {\n for (const childPath of HashMap.keys(leaves)) {\n const segments = rootPath(childPath).pathSegments;\n for (let depth = 1; depth < segments.length; depth++) {\n const parentPath = SpecModulePath.SpecModulePath.make(\n `${Array.join(segments.slice(0, depth), \"/\")}.spec.ts`,\n );\n const parent = HashMap.get(leaves, parentPath);\n if (Option.isNone(parent)) continue;\n const collisionName = segments[depth]!;\n const collisionKind = parent.value.functionNames.includes(collisionName)\n ? \"function\"\n : Record.has(parent.value.groups, collisionName)\n ? \"group\"\n : undefined;\n if (collisionKind !== undefined) {\n return Result.fail(\n ParentChildNameCollisionError.make({\n parentSpecPath: parentPath,\n childSpecPath: childPath,\n collisionName,\n collisionKind,\n }),\n );\n }\n }\n }\n return Result.succeed(leaves);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,eAAe,OAAO,OAAO;CACxC,MAAMA;CACN,SAAS,OAAO,SAAS,CAAC,UAAU,MAAM,CAAC;CAC3C,2BAA2B,OAAO,YAAY,OAAO,OAAO;CAC5D,eAAe,OAAO,MAAM,OAAO,cAAc;AACnD,CAAC;AAUD,MAAa,YAAqC,OAAO,OAAO;CAC9D,SAAS,aAAa,OAAO;CAC7B,2BAA2B,aAAa,OAAO;CAC/C,eAAe,aAAa,OAAO;CACnC,QAAQ,OAAO,OACb,OAAO,QACP,OAAO,cAAc,SAAS,CAChC;AACF,CAAC;AAED,IAAM,WAAN,MAAM,SAAS;CACb;CAEA,YACE,QACA;EACA,KAAK,UAAU;CACjB;CAEA,OAAO,YACL,QACkE;EAClE,OAAO,OAAO,IACZ,iCAAiC,MAAM,IACtC,WAAW,IAAI,SAAS,MAAM,CACjC;CACF;CAEA,IAAI,SAAoE;EACtE,OAAO,KAAK;CACd;AACF;AAIA,MAAM,UAAU,OAAO,MAAM,OAAO,MAAM,CAAC,OAAO,QAAQ,SAAS,CAAC,CAAC;AACrE,MAAM,oBAAA,eAAkD,MACtD,OAAO,YAAY,SAAS,CAAC,OAAO,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,CAC1D;AACA,MAAM,YAAY,SAChBC,K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E,aACA,OAAO,IAAI,OAAO,MAAM,QAAQ,aAAa,IAC3C,UACA,KAAA;GACN,IAAI,kBAAkB,KAAA,GACpB,OAAO,OAAO,KACZ,8BAA8B,KAAK;IACjC,gBAAgB;IAChB,eAAe;IACf;IACA;GACF,CAAC,CACH;EAEJ;CACF;CACA,OAAO,OAAO,QAAQ,MAAM;AAC9B"}
@@ -7,7 +7,7 @@ import "effect/Option";
7
7
  import "effect/Record";
8
8
  import * as Schema from "effect/Schema";
9
9
  import * as String from "effect/String";
10
- //#region src/GroupPath.ts
10
+ // src/GroupPath.ts
11
11
  /**
12
12
  * The path to a group in the Confect API.
13
13
  */
@@ -23,6 +23,8 @@ const append = (groupPath, groupName) => make([...groupPath.pathSegments, groupN
23
23
  /**
24
24
  * Expects a path string of the form `./group1/group2.ts`, relative to the
25
25
  * Convex functions directory.
26
+ *
27
+ * @internal
26
28
  */
27
29
  const fromGroupModulePath = Effect.fnUntraced(function* (groupModulePath) {
28
30
  const path = yield* Path.Path;
@@ -31,10 +33,12 @@ const fromGroupModulePath = Effect.fnUntraced(function* (groupModulePath) {
31
33
  const dirSegments = Array.filter(String.split(dir, path.sep), String.isNonEmpty);
32
34
  yield* Effect.logDebug(Array.append(dirSegments, name));
33
35
  return make(Array.append(dirSegments, name));
34
- } else return yield* new GroupModulePathIsNotATypeScriptFileError({ path: groupModulePath });
36
+ } else return yield* GroupModulePathIsNotATypeScriptFileError.make({ path: groupModulePath });
35
37
  });
36
38
  /**
37
39
  * Get the module path for a group, relative to the Convex functions directory.
40
+ *
41
+ * @internal
38
42
  */
39
43
  const modulePath = Effect.fnUntraced(function* (groupPath) {
40
44
  return (yield* Path.Path).join(...groupPath.pathSegments) + ".ts";
@@ -45,7 +49,6 @@ var GroupModulePathIsNotATypeScriptFileError = class extends Schema.TaggedError(
45
49
  return `Expected group module path to end with .ts, got ${this.path}`;
46
50
  }
47
51
  };
48
- //#endregion
49
52
  export { GroupModulePathIsNotATypeScriptFileError, GroupPath, append, fromGroupModulePath, make, modulePath, toString };
50
53
 
51
54
  //# sourceMappingURL=GroupPath.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"GroupPath.mjs","names":[],"sources":["../src/GroupPath.ts"],"sourcesContent":["import { type GroupSpec, Spec } from \"@confect/core\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as String from \"effect/String\";\n\n/**\n * The path to a group in the Confect API.\n */\nexport class GroupPath extends Schema.Class<GroupPath>(\"GroupPath\")({\n pathSegments: Schema.NonEmptyArray(Schema.NonEmptyString),\n}) {}\n\n/**\n * Create a GroupPath from path segments.\n */\nexport const make = (pathSegments: readonly [string, ...string[]]): GroupPath =>\n GroupPath.make({ pathSegments });\n\n/**\n * Append a group name to a GroupPath to create a new GroupPath.\n */\nexport const append = (groupPath: GroupPath, groupName: string): GroupPath =>\n make([...groupPath.pathSegments, groupName]);\n\n/**\n * Expects a path string of the form `./group1/group2.ts`, relative to the\n * Convex functions directory.\n */\nexport const fromGroupModulePath = Effect.fnUntraced(function* (\n groupModulePath: string,\n) {\n const path = yield* Path.Path;\n\n const { dir, name, ext } = path.parse(groupModulePath);\n\n if (ext === \".ts\") {\n const dirSegments = Array.filter(\n String.split(dir, path.sep),\n String.isNonEmpty,\n );\n yield* Effect.logDebug(Array.append(dirSegments, name));\n return make(Array.append(dirSegments, name));\n } else {\n return yield* new GroupModulePathIsNotATypeScriptFileError({\n path: groupModulePath,\n });\n }\n});\n\n/**\n * Get the module path for a group, relative to the Convex functions directory.\n */\nexport const modulePath = Effect.fnUntraced(function* (groupPath: GroupPath) {\n const path = yield* Path.Path;\n\n return path.join(...groupPath.pathSegments) + \".ts\";\n});\n\nexport const getGroupSpec = (\n spec: Spec.AnyWithProps,\n groupPath: GroupPath,\n): Option.Option<GroupSpec.AnyWithProps> =>\n pipe(\n groupPath.pathSegments,\n Array.matchLeft({\n onEmpty: () => Option.none(),\n onNonEmpty: (head, tail) =>\n pipe(\n Record.get(Spec.groups(spec), head),\n Option.flatMap((group) =>\n Array.isArrayNonEmpty(tail)\n ? getGroupSpecHelper(group, tail)\n : Option.some(group),\n ),\n ),\n }),\n );\n\nconst getGroupSpecHelper = (\n group: GroupSpec.AnyWithProps,\n remainingPath: ReadonlyArray<string>,\n): Option.Option<GroupSpec.AnyWithProps> =>\n pipe(\n remainingPath,\n Array.matchLeft({\n onEmpty: () => Option.some(group),\n onNonEmpty: (head, tail) =>\n pipe(\n Record.get(group.groups, head),\n Option.flatMap((subGroup) =>\n Array.isArrayNonEmpty(tail)\n ? getGroupSpecHelper(subGroup, tail)\n : Option.some(subGroup),\n ),\n ),\n }),\n );\n\nexport const toString = (groupPath: GroupPath) =>\n Array.join(groupPath.pathSegments, \".\");\n\nexport class GroupModulePathIsNotATypeScriptFileError extends Schema.TaggedError<GroupModulePathIsNotATypeScriptFileError>()(\n \"GroupModulePathIsNotATypeScriptFileError\",\n {\n path: Schema.NonEmptyString,\n },\n) {\n override get message(): string {\n return `Expected group module path to end with .ts, got ${this.path}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAa,YAAb,cAA+B,OAAO,MAAiB,WAAW,CAAC,CAAC,EAClE,cAAc,OAAO,cAAc,OAAO,cAAc,EAC1D,CAAC,CAAC,CAAC,CAAC;;;;AAKJ,MAAa,QAAQ,iBACnB,UAAU,KAAK,EAAE,aAAa,CAAC;;;;AAKjC,MAAa,UAAU,WAAsB,cAC3C,KAAK,CAAC,GAAG,UAAU,cAAc,SAAS,CAAC;;;;;AAM7C,MAAa,sBAAsB,OAAO,WAAW,WACnD,iBACA;CACA,MAAM,OAAO,OAAO,KAAK;CAEzB,MAAM,EAAE,KAAK,MAAM,QAAQ,KAAK,MAAM,eAAe;CAErD,IAAI,QAAQ,OAAO;EACjB,MAAM,cAAc,MAAM,OACxB,OAAO,MAAM,KAAK,KAAK,GAAG,GAC1B,OAAO,UACT;EACA,OAAO,OAAO,SAAS,MAAM,OAAO,aAAa,IAAI,CAAC;EACtD,OAAO,KAAK,MAAM,OAAO,aAAa,IAAI,CAAC;CAC7C,OACE,OAAO,OAAO,IAAI,yCAAyC,EACzD,MAAM,gBACR,CAAC;AAEL,CAAC;;;;AAKD,MAAa,aAAa,OAAO,WAAW,WAAW,WAAsB;CAG3E,QAAO,OAFa,KAAK,KAAA,CAEb,KAAK,GAAG,UAAU,YAAY,IAAI;AAChD,CAAC;AA0CD,MAAa,YAAY,cACvB,MAAM,KAAK,UAAU,cAAc,GAAG;AAExC,IAAa,2CAAb,cAA8D,OAAO,YAAsD,CAAC,CAC1H,4CACA,EACE,MAAM,OAAO,eACf,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,mDAAmD,KAAK;CACjE;AACF"}
1
+ {"version":3,"file":"GroupPath.mjs","names":[],"sources":["../src/GroupPath.ts"],"sourcesContent":["import { type GroupSpec, Spec } from \"@confect/core\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Record from \"effect/Record\";\nimport * as Schema from \"effect/Schema\";\nimport * as String from \"effect/String\";\n\n/**\n * The path to a group in the Confect API.\n */\nexport class GroupPath extends Schema.Class<GroupPath, {}>(\"GroupPath\")({\n pathSegments: Schema.NonEmptyArray(Schema.NonEmptyString),\n}) {}\n\n/**\n * Create a GroupPath from path segments.\n */\nexport const make = (pathSegments: readonly [string, ...string[]]): GroupPath =>\n GroupPath.make({ pathSegments });\n\n/**\n * Append a group name to a GroupPath to create a new GroupPath.\n */\nexport const append = (groupPath: GroupPath, groupName: string): GroupPath =>\n make([...groupPath.pathSegments, groupName]);\n\n/**\n * Expects a path string of the form `./group1/group2.ts`, relative to the\n * Convex functions directory.\n *\n * @internal\n */\nexport const fromGroupModulePath = Effect.fnUntraced(function* (\n groupModulePath: string,\n) {\n const path = yield* Path.Path;\n\n const { dir, name, ext } = path.parse(groupModulePath);\n\n if (ext === \".ts\") {\n const dirSegments = Array.filter(\n String.split(dir, path.sep),\n String.isNonEmpty,\n );\n yield* Effect.logDebug(Array.append(dirSegments, name));\n return make(Array.append(dirSegments, name));\n } else {\n return yield* GroupModulePathIsNotATypeScriptFileError.make({\n path: groupModulePath,\n });\n }\n});\n\n/**\n * Get the module path for a group, relative to the Convex functions directory.\n *\n * @internal\n */\nexport const modulePath = Effect.fnUntraced(function* (groupPath: GroupPath) {\n const path = yield* Path.Path;\n\n return path.join(...groupPath.pathSegments) + \".ts\";\n});\n\nexport const getGroupSpec = (\n spec: Spec.AnyWithProps,\n groupPath: GroupPath,\n): Option.Option<GroupSpec.AnyWithProps> =>\n pipe(\n groupPath.pathSegments,\n Array.matchLeft({\n onEmpty: () => Option.none(),\n onNonEmpty: (head, tail) =>\n pipe(\n Record.get(Spec.groups(spec), head),\n Option.flatMap((group) =>\n Array.isArrayNonEmpty(tail)\n ? getGroupSpecHelper(group, tail)\n : Option.some(group),\n ),\n ),\n }),\n );\n\nconst getGroupSpecHelper = (\n group: GroupSpec.AnyWithProps,\n remainingPath: ReadonlyArray<string>,\n): Option.Option<GroupSpec.AnyWithProps> =>\n pipe(\n remainingPath,\n Array.matchLeft({\n onEmpty: () => Option.some(group),\n onNonEmpty: (head, tail) =>\n pipe(\n Record.get(group.groups, head),\n Option.flatMap((subGroup) =>\n Array.isArrayNonEmpty(tail)\n ? getGroupSpecHelper(subGroup, tail)\n : Option.some(subGroup),\n ),\n ),\n }),\n );\n\nexport const toString = (groupPath: GroupPath) =>\n Array.join(groupPath.pathSegments, \".\");\n\nexport class GroupModulePathIsNotATypeScriptFileError extends Schema.TaggedError<\n GroupModulePathIsNotATypeScriptFileError,\n { readonly brand: unique symbol }\n>()(\"GroupModulePathIsNotATypeScriptFileError\", {\n path: Schema.NonEmptyString,\n}) {\n override get message(): string {\n return `Expected group module path to end with .ts, got ${this.path}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAa,YAAb,cAA+B,OAAO,MAAqB,WAAW,CAAC,CAAC,EACtE,cAAc,OAAO,cAAc,OAAO,cAAc,EAC1D,CAAC,CAAC,CAAC,CAAC;;;;AAKJ,MAAa,QAAQ,iBACnB,UAAU,KAAK,EAAE,aAAa,CAAC;;;;AAKjC,MAAa,UAAU,WAAsB,cAC3C,KAAK,CAAC,GAAG,UAAU,cAAc,SAAS,CAAC;;;;;;;AAQ7C,MAAa,sBAAsB,OAAO,WAAW,WACnD,iBACA;CACA,MAAM,OAAO,OAAO,KAAK;CAEzB,MAAM,EAAE,KAAK,MAAM,QAAQ,KAAK,MAAM,eAAe;CAErD,IAAI,QAAQ,OAAO;EACjB,MAAM,cAAc,MAAM,OACxB,OAAO,MAAM,KAAK,KAAK,GAAG,GAC1B,OAAO,UACT;EACA,OAAO,OAAO,SAAS,MAAM,OAAO,aAAa,IAAI,CAAC;EACtD,OAAO,KAAK,MAAM,OAAO,aAAa,IAAI,CAAC;CAC7C,OACE,OAAO,OAAO,yCAAyC,KAAK,EAC1D,MAAM,gBACR,CAAC;AAEL,CAAC;;;;;;AAOD,MAAa,aAAa,OAAO,WAAW,WAAW,WAAsB;CAG3E,QAAO,OAFa,KAAK,KAAA,CAEb,KAAK,GAAG,UAAU,YAAY,IAAI;AAChD,CAAC;AA0CD,MAAa,YAAY,cACvB,MAAM,KAAK,UAAU,cAAc,GAAG;AAExC,IAAa,2CAAb,cAA8D,OAAO,YAGnE,CAAC,CAAC,4CAA4C,EAC9C,MAAM,OAAO,eACf,CAAC,CAAC,CAAC;CACD,IAAa,UAAkB;EAC7B,OAAO,mDAAmD,KAAK;CACjE;AACF"}
@@ -1,8 +1,7 @@
1
1
  import { GroupPath } from "./GroupPath.mjs";
2
2
  import * as Schema from "effect/Schema";
3
- //#region src/GroupPaths.ts
3
+ // src/GroupPaths.ts
4
4
  const GroupPaths = Schema.HashSet(GroupPath).pipe(Schema.brand("@confect/cli/GroupPaths"));
5
- //#endregion
6
5
  export { GroupPaths };
7
6
 
8
7
  //# sourceMappingURL=GroupPaths.mjs.map
@@ -1,8 +1,7 @@
1
1
  import { withSuffix } from "./RelativeModulePath.mjs";
2
2
  import * as Schema from "effect/Schema";
3
- //#region src/ImplModulePath.ts
3
+ // src/ImplModulePath.ts
4
4
  const ImplModulePath = withSuffix(".impl.ts").pipe(Schema.brand("@confect/cli/ImplModulePath"));
5
- //#endregion
6
5
  export { ImplModulePath };
7
6
 
8
7
  //# sourceMappingURL=ImplModulePath.mjs.map
package/dist/Json.mjs ADDED
@@ -0,0 +1,13 @@
1
+ // src/Json.ts
2
+ /**
3
+ * JSON text for a value. Generated source takes its string literals and the
4
+ * manifest's body from here, so quoting and escaping follow one rule.
5
+ */
6
+ const stringify = (value, space) => JSON.stringify(value, null, space);
7
+ /**
8
+ * A JavaScript string literal for `value`.
9
+ */
10
+ const quote = (value) => stringify(value);
11
+ export { quote, stringify };
12
+
13
+ //# sourceMappingURL=Json.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Json.mjs","names":[],"sources":["../src/Json.ts"],"sourcesContent":["/**\n * JSON text for a value. Generated source takes its string literals and the\n * manifest's body from here, so quoting and escaping follow one rule.\n */\nexport const stringify = (value: unknown, space?: number): string =>\n // oxlint-disable-next-line effecttsgo/global-json -- JSON's syntax and escaping are what generated source needs, and the CLI passes only JSON data, which always serializes.\n JSON.stringify(value, null, space);\n\n/**\n * A JavaScript string literal for `value`.\n */\nexport const quote = (value: string): string => stringify(value);\n"],"mappings":";;;;;AAIA,MAAa,aAAa,OAAgB,UAExC,KAAK,UAAU,OAAO,MAAM,KAAK;;;;AAKnC,MAAa,SAAS,UAA0B,UAAU,KAAK"}
@@ -1,16 +1,21 @@
1
1
  import { BundleFailedError, fromBundlerError } from "./BuildError.mjs";
2
2
  import { bundle, directlyImports, importersOfPackage, withBatch } from "./Bundler.mjs";
3
- import { ImplMissingDefaultLayerError, ImplMissingFunctionsError, ImplMissingMiddlewareError, ImplMissingSpecImportError, ImplNotFinalizedError, InvalidDeclarationError, InvalidMiddlewareAttachmentError, MissingImplFileError, MissingSpecFileError, RequiredMiddlewareError, SpecImportsServerError, SpecMissingDefaultGroupSpecError } from "./CodegenError.mjs";
3
+ import { ImplMissingDefaultLayerError, ImplMissingFunctionsError, ImplMissingMiddlewareError, ImplMissingSpecImportError, ImplNotFinalizedError, InvalidContextReuseError, InvalidDeclarationError, InvalidMiddlewareAttachmentError, MissingImplFileError, MissingSpecFileError, RequiredMiddlewareError, SpecImportsServerError, SpecMissingDefaultGroupSpecError } from "./CodegenError.mjs";
4
4
  import { ConfectDirectory } from "./ConfectDirectory.mjs";
5
- import { readDirectorySorted, removePathExtension, toPosixPath } from "./utils.mjs";
6
5
  import { ImplModulePath } from "./ImplModulePath.mjs";
6
+ import { readDirectorySorted, removePathExtension, toPosixPath } from "./utils.mjs";
7
+ import { logWarn } from "./log.mjs";
7
8
  import * as Effect from "effect/Effect";
8
9
  import { GroupSpec, MiddlewareAttachment } from "@confect/core";
9
10
  import * as FileSystem from "effect/FileSystem";
10
11
  import * as Path from "effect/Path";
11
12
  import * as Array from "effect/Array";
13
+ import * as Result from "effect/Result";
14
+ import { pipe } from "effect/Function";
12
15
  import * as HashSet from "effect/HashSet";
13
16
  import * as Option from "effect/Option";
17
+ import * as Record from "effect/Record";
18
+ import * as Iterable from "effect/Iterable";
14
19
  import * as Ref from "effect/Ref";
15
20
  import * as Schema from "effect/Schema";
16
21
  import * as String from "effect/String";
@@ -18,7 +23,7 @@ import * as Layer from "effect/Layer";
18
23
  import * as Brand from "effect/Brand";
19
24
  import { Registry, RegistryItems } from "@confect/server";
20
25
  import * as GroupImpl from "@confect/server/GroupImpl";
21
- //#region src/LeafModule.ts
26
+ // src/LeafModule.ts
22
27
  const LoadedLeafModule = Brand.nominal();
23
28
  const VALIDATION_CONCURRENCY = 4;
24
29
  const SPEC_SUFFIX = ".spec.ts";
@@ -26,20 +31,26 @@ const IMPL_SUFFIX = ".impl.ts";
26
31
  const swapModuleSuffix = Effect.fnUntraced(function* (relativePath, fromSuffix, toSuffix) {
27
32
  const path = yield* Path.Path;
28
33
  const { dir, name, ext } = path.parse(relativePath);
29
- if (ext !== ".ts" || !name.endsWith(fromSuffix.slice(0, -3))) return relativePath;
30
- const nextName = `${name.slice(0, -fromSuffix.slice(0, -3).length)}${toSuffix.slice(0, -3)}`;
34
+ if (ext !== ".ts" || !String.endsWith(String.slice(0, -3)(fromSuffix))(name)) return relativePath;
35
+ const nextName = `${String.slice(0, -String.slice(0, -3)(fromSuffix).length)(name)}${String.slice(0, -3)(toSuffix)}`;
31
36
  return dir.length > 0 ? path.join(dir, `${nextName}${ext}`) : `${nextName}${ext}`;
32
37
  });
33
- const isLeafSpecPath = (relativePath) => relativePath.endsWith(SPEC_SUFFIX);
38
+ const isLeafSpecPath = (relativePath) => String.endsWith(SPEC_SUFFIX)(relativePath);
39
+ /**
40
+ * @internal
41
+ */
34
42
  const exportNameFromModulePath = Effect.fnUntraced(function* (relativePath) {
35
43
  const { name, ext } = (yield* Path.Path).parse(relativePath);
36
44
  if (ext !== ".ts") return name;
37
- return name.endsWith(".spec") ? name.slice(0, -5) : name;
45
+ return String.endsWith(".spec")(name) ? String.slice(0, -5)(name) : name;
38
46
  });
47
+ /**
48
+ * @internal
49
+ */
39
50
  const groupPathFromRelativeModulePath = Effect.fnUntraced(function* (relativePath) {
40
51
  const path = yield* Path.Path;
41
52
  const { dir, name, ext } = path.parse(relativePath);
42
- const stem = ext === ".ts" && name.endsWith(".spec") ? name.slice(0, -5) : name;
53
+ const stem = ext === ".ts" && String.endsWith(".spec")(name) ? String.slice(0, -5)(name) : name;
43
54
  const dirSegments = Array.filter(String.split(dir, path.sep), String.isNonEmpty);
44
55
  const pathSegments = Array.append(dirSegments, stem);
45
56
  return {
@@ -47,15 +58,31 @@ const groupPathFromRelativeModulePath = Effect.fnUntraced(function* (relativePat
47
58
  groupPathDot: Array.join(pathSegments, ".")
48
59
  };
49
60
  });
61
+ /**
62
+ * @internal
63
+ */
50
64
  const specImportPathFromGenerated = Effect.fnUntraced(function* (specRelativePath) {
51
65
  const path = yield* Path.Path;
52
- return `../${toPosixPath(path, yield* removePathExtension(specRelativePath))}.js`;
66
+ const pathWithoutExtension = yield* removePathExtension(specRelativePath);
67
+ return `../${toPosixPath(path, pathWithoutExtension)}.js`;
53
68
  });
69
+ /**
70
+ * @internal
71
+ */
54
72
  const specPathForImpl = (implRelativePath) => swapModuleSuffix(implRelativePath, IMPL_SUFFIX, SPEC_SUFFIX);
73
+ /**
74
+ * @internal
75
+ */
55
76
  const implPathForSpec = (specRelativePath) => swapModuleSuffix(specRelativePath, SPEC_SUFFIX, IMPL_SUFFIX);
77
+ /**
78
+ * @internal
79
+ */
56
80
  const registeredFunctionsRelativePath = Effect.fnUntraced(function* (leaf) {
57
81
  return (yield* Path.Path).join("registeredFunctions", ...leaf.pathSegments) + ".ts";
58
82
  });
83
+ /**
84
+ * @internal
85
+ */
59
86
  const discoverLeafSpecFiles = Effect.gen(function* () {
60
87
  const path = yield* Path.Path;
61
88
  const confectDirectory = yield* ConfectDirectory.get;
@@ -69,6 +96,9 @@ const discoverLeafSpecFiles = Effect.gen(function* () {
69
96
  return !Array.some(segments, (segment) => HashSet.has(excludedDirs, segment));
70
97
  });
71
98
  });
99
+ /**
100
+ * @internal
101
+ */
72
102
  const discoverLeafImplFiles = Effect.gen(function* () {
73
103
  const path = yield* Path.Path;
74
104
  const confectDirectory = yield* ConfectDirectory.get;
@@ -79,6 +109,9 @@ const discoverLeafImplFiles = Effect.gen(function* () {
79
109
  return !Array.some(segments, (segment) => HashSet.has(excludedDirs, segment));
80
110
  });
81
111
  });
112
+ /**
113
+ * @internal
114
+ */
82
115
  const toLeafModule = Effect.fnUntraced(function* (specRelativePath) {
83
116
  const exportName = yield* exportNameFromModulePath(specRelativePath);
84
117
  const { pathSegments, groupPathDot } = yield* groupPathFromRelativeModulePath(specRelativePath);
@@ -113,27 +146,28 @@ const absoluteModulePath = Effect.fnUntraced(function* (relativePath) {
113
146
  */
114
147
  const validateClientSafety = Effect.fnUntraced(function* (leaf, bundled) {
115
148
  const path = yield* Path.Path;
116
- const confectDirectory = path.resolve(yield* ConfectDirectory.get);
149
+ const directory = yield* ConfectDirectory.get;
150
+ const confectDirectory = path.resolve(directory);
117
151
  const isCheckedUserModule = (absolutePath) => {
118
152
  const relative = path.relative(confectDirectory, absolutePath);
119
- return !relative.startsWith("..") && !path.isAbsolute(relative);
153
+ return !String.startsWith("..")(relative) && !path.isAbsolute(relative);
120
154
  };
121
155
  const importers = importersOfPackage(bundled, "@confect/server", isCheckedUserModule);
122
- if (importers.length > 0) return yield* new SpecImportsServerError({
156
+ if (importers.length > 0) return yield* SpecImportsServerError.make({
123
157
  specPath: leaf.relativePath,
124
158
  importerPaths: Array.map(importers, (absolutePath) => toPosixPath(path, path.relative(confectDirectory, absolutePath)))
125
159
  });
126
160
  });
127
161
  const validateReservedArguments = Effect.fnUntraced(function* (group, specPath, groupPath) {
128
- for (const spec of Object.values(group.functions)) {
162
+ for (const spec of Record.values(group.functions)) {
129
163
  const name = spec.reservedArgument;
130
164
  const provenance = spec.functionProvenance;
131
- if (name !== void 0 && provenance._tag === "Confect" && Object.hasOwn(provenance.args.fields, name)) return yield* new InvalidDeclarationError({
165
+ if (name !== void 0 && provenance._tag === "Confect" && Record.has(provenance.args.fields, name)) return yield* InvalidDeclarationError.make({
132
166
  declarationPath: `confect/${specPath}`,
133
167
  reason: `${groupPath}:${spec.name} declares the argument "${name}", which its profile reserves. Rename the argument.`
134
168
  });
135
169
  }
136
- for (const [name, child] of Object.entries(group.groups)) yield* validateReservedArguments(child, specPath, `${groupPath}/${name}`);
170
+ for (const [name, child] of Record.toEntries(group.groups)) yield* validateReservedArguments(child, specPath, `${groupPath}/${name}`);
137
171
  });
138
172
  /**
139
173
  * Validate that the leaf's spec file default-exports a `GroupSpec`, and that
@@ -141,15 +175,19 @@ const validateReservedArguments = Effect.fnUntraced(function* (group, specPath,
141
175
  * {@link validateClientSafety}). Returns the leaf paired with its validated
142
176
  * spec, so subsequent operations reuse that association without re-bundling.
143
177
  * The runtime is declared by the spec, not its file location.
178
+ *
179
+ * @internal
144
180
  */
145
181
  const loadSpec = Effect.fn("LeafModule.loadSpec")(function* (leaf) {
146
182
  const absolutePath = yield* absoluteModulePath(leaf.relativePath);
147
183
  const bundled = yield* bundle(absolutePath).pipe(Effect.mapError((error) => fromBundlerError(leaf.relativePath, error)));
148
184
  const groupSpec = bundled.module.default;
149
- if (!GroupSpec.isGroupSpec(groupSpec)) return yield* new SpecMissingDefaultGroupSpecError({ specPath: leaf.relativePath });
185
+ if (!GroupSpec.isGroupSpec(groupSpec)) return yield* SpecMissingDefaultGroupSpecError.make({ specPath: leaf.relativePath });
150
186
  yield* validateClientSafety(leaf, bundled);
151
- yield* validateReservedArguments(groupSpec, leaf.relativePath, leaf.pathSegments.join("/"));
152
- yield* Effect.fromResult(GroupSpec.validateMiddleware(groupSpec)).pipe(Effect.mapError((error) => new InvalidMiddlewareAttachmentError({
187
+ yield* validateReservedArguments(groupSpec, leaf.relativePath, Array.join(leaf.pathSegments, "/"));
188
+ const warnings = yield* Effect.fromResult(validateContextReuse(groupSpec, leaf.relativePath, leaf.groupPathDot));
189
+ for (const groupPath of warnings) yield* logWarn(`${leaf.relativePath}, group ${groupPath}: experimental_reuseContext has no effect on actions; this group contains only actions.`);
190
+ yield* Effect.fromResult(GroupSpec.validateMiddleware(groupSpec)).pipe(Effect.mapError((error) => InvalidMiddlewareAttachmentError.make({
153
191
  specPath: leaf.relativePath,
154
192
  message: MiddlewareAttachment.formatValidationError(error)
155
193
  })));
@@ -158,6 +196,30 @@ const loadSpec = Effect.fn("LeafModule.loadSpec")(function* (leaf) {
158
196
  spec: groupSpec
159
197
  });
160
198
  });
199
+ const validateContextReuse = (group, specPath, groupPath) => Result.gen(function* () {
200
+ const isEnabled = group.experimental_reuseContext;
201
+ if (isEnabled !== void 0 && typeof isEnabled !== "boolean") return yield* Result.fail(InvalidContextReuseError.make({
202
+ specPath,
203
+ groupPath,
204
+ reason: "InvalidOption"
205
+ }));
206
+ if (isEnabled) {
207
+ if (group.runtime === "Node") return yield* Result.fail(InvalidContextReuseError.make({
208
+ specPath,
209
+ groupPath,
210
+ reason: "NodeRuntime"
211
+ }));
212
+ if (Record.has(group.functions, "experimental_reuseContext")) return yield* Result.fail(InvalidContextReuseError.make({
213
+ specPath,
214
+ groupPath,
215
+ reason: "ReservedFunctionName"
216
+ }));
217
+ }
218
+ const functions = Record.values(group.functions);
219
+ const warnings = isEnabled && functions.length > 0 && Array.every(functions, (fn) => fn.runtimeAndFunctionType.functionType === "action") ? [groupPath] : [];
220
+ const childWarnings = yield* pipe(group.groups, Record.toEntries, Iterable.map(([name, child]) => validateContextReuse(child, specPath, `${groupPath}.${name}`)), Result.all);
221
+ return [...warnings, ...Array.flatten(childWarnings)];
222
+ });
161
223
  /**
162
224
  * Walk the built `Context` for a `Finalized` `GroupImpl` service value. The
163
225
  * lookup is value-shaped (via `GroupImpl.isFinalizedGroupImpl`) so we don't
@@ -181,6 +243,8 @@ const buildImplLayer = Effect.fnUntraced(function* (implLayer) {
181
243
  * a finalized `GroupImpl` layer, and provides a `FunctionImpl` for every
182
244
  * function declared by the spec. Return uncovered middleware requirements for
183
245
  * the caller to report across groups.
246
+ *
247
+ * @internal
184
248
  */
185
249
  /**
186
250
  * An implementation's unresolved import of a `confect/_generated` file is a
@@ -189,56 +253,63 @@ const buildImplLayer = Effect.fnUntraced(function* (implLayer) {
189
253
  */
190
254
  const nameUnwrittenSectionFiles = Effect.fnUntraced(function* (error, bundleDirectory) {
191
255
  const path = yield* Path.Path;
192
- const generated = path.join(yield* ConfectDirectory.get, "_generated");
193
- const errors = error.errors.map((message) => {
256
+ const confectDirectory = yield* ConfectDirectory.get;
257
+ const generated = path.join(confectDirectory, "_generated");
258
+ const errors = Array.map(error.errors, (message) => {
194
259
  const specifier = /^Could not resolve "(.+)"$/.exec(message.text)?.[1];
195
260
  if (specifier === void 0 || message.location === null) return message;
196
261
  const file = path.relative(generated, path.resolve(bundleDirectory, path.dirname(message.location.file), specifier));
197
- if (file.startsWith("..") || path.isAbsolute(file)) return message;
262
+ if (pipe(file, String.startsWith("..")) || path.isAbsolute(file)) return message;
198
263
  const extension = path.extname(file);
199
- const name = toPosixPath(path, extension === "" ? `${file}.ts` : extension === ".js" ? `${file.slice(0, -extension.length)}.ts` : file);
264
+ const name = toPosixPath(path, extension === "" ? `${file}.ts` : extension === ".js" ? `${pipe(file, String.slice(0, -extension.length))}.ts` : file);
200
265
  return Object.assign({}, message, { text: `No manifest section this backend declares writes _generated/${name}. Declare its section on App.make({ manifestSections }) in confect/app.ts.` });
201
266
  });
202
- return new BundleFailedError({
267
+ return BundleFailedError.make({
203
268
  file: error.file,
204
269
  errors
205
270
  });
206
271
  });
272
+ /**
273
+ * @internal
274
+ */
207
275
  const validateImpl = Effect.fn("LeafModule.validateImpl")(function* (leaf, required = []) {
208
276
  const path = yield* Path.Path;
209
277
  const implRelativePath = yield* implPathForSpec(leaf.relativePath);
210
278
  const implAbsolutePath = yield* absoluteModulePath(implRelativePath);
211
279
  const specAbsolutePath = yield* absoluteModulePath(leaf.relativePath);
212
280
  const bundled = yield* bundle(implAbsolutePath).pipe(Effect.mapError((error) => fromBundlerError(implRelativePath, error)), Effect.catchTag("BundleFailedError", (error) => Effect.flip(nameUnwrittenSectionFiles(error, path.dirname(implAbsolutePath)))));
213
- if (!(yield* directlyImports(bundled, implAbsolutePath, specAbsolutePath))) return yield* new ImplMissingSpecImportError({
281
+ if (!(yield* directlyImports(bundled, implAbsolutePath, specAbsolutePath))) return yield* ImplMissingSpecImportError.make({
214
282
  implPath: implRelativePath,
215
283
  expectedSpecPath: leaf.relativePath
216
284
  });
217
- if (!Layer.isLayer(bundled.module.default)) return yield* new ImplMissingDefaultLayerError({ implPath: implRelativePath });
285
+ if (!Layer.isLayer(bundled.module.default)) return yield* ImplMissingDefaultLayerError.make({ implPath: implRelativePath });
218
286
  const groupSpec = leaf.spec;
219
- const expectedFunctionNames = Object.keys(groupSpec.functions);
287
+ const expectedFunctionNames = Record.keys(groupSpec.functions);
220
288
  const { context, items } = yield* buildImplLayer(bundled.module.default);
221
289
  const finalizedGroupImpl = yield* Option.match(findFinalizedGroupImpl(context), {
222
- onNone: () => new ImplNotFinalizedError({ implPath: implRelativePath }),
290
+ onNone: () => ImplNotFinalizedError.make({ implPath: implRelativePath }),
223
291
  onSome: Effect.succeed
224
292
  });
225
293
  const registeredSet = HashSet.fromIterable(finalizedGroupImpl.registeredFunctionNames);
226
- const missing = expectedFunctionNames.filter((name) => !HashSet.has(registeredSet, name));
227
- if (missing.length > 0) return yield* new ImplMissingFunctionsError({
294
+ const missing = Array.filter(expectedFunctionNames, (name) => !HashSet.has(registeredSet, name));
295
+ if (missing.length > 0) return yield* ImplMissingFunctionsError.make({
228
296
  implPath: implRelativePath,
229
297
  groupPath: leaf.groupPathDot,
230
298
  missingFunctionNames: missing
231
299
  });
232
- const expectedMiddlewareKeys = Array.dedupe([...(groupSpec.middlewareSpecs ?? []).map((middlewareSpec) => middlewareSpec.key), ...Object.values(groupSpec.functions).flatMap((function_) => (function_.middlewareSpecs ?? []).map((middlewareSpec) => middlewareSpec.key))]);
300
+ const expectedMiddlewareKeys = Array.dedupe([...Array.map(groupSpec.middlewareSpecs ?? [], (middlewareSpec) => middlewareSpec.key), ...Array.flatMap(Record.values(groupSpec.functions), (function_) => Array.map(function_.middlewareSpecs ?? [], (middlewareSpec) => middlewareSpec.key))]);
233
301
  const registeredMiddlewareKeys = HashSet.fromIterable(finalizedGroupImpl.registeredMiddlewareKeys ?? []);
234
302
  const missingMiddleware = Array.filter(expectedMiddlewareKeys, (key) => !HashSet.has(registeredMiddlewareKeys, key));
235
- if (missingMiddleware.length > 0) return yield* new ImplMissingMiddlewareError({
303
+ if (missingMiddleware.length > 0) return yield* ImplMissingMiddlewareError.make({
236
304
  implPath: implRelativePath,
237
305
  groupPath: leaf.groupPathDot,
238
306
  missingMiddlewareKeys: missingMiddleware
239
307
  });
240
308
  return RegistryItems.missingRequired(items, required, leaf.groupPathDot);
241
309
  });
310
+ /**
311
+ * @internal
312
+ */
242
313
  const withImplFiles = Effect.fnUntraced(function* (relativePaths, use) {
243
314
  const fs = yield* FileSystem.FileSystem;
244
315
  const path = yield* Path.Path;
@@ -247,39 +318,49 @@ const withImplFiles = Effect.fnUntraced(function* (relativePaths, use) {
247
318
  implRelativePath,
248
319
  specRelativePath
249
320
  }))));
250
- return yield* withBatch(pairs.flatMap(({ implRelativePath, specRelativePath }) => [path.resolve(confectDirectory, implRelativePath), path.resolve(confectDirectory, specRelativePath)]), Effect.gen(function* () {
321
+ return yield* withBatch(Array.flatMap(pairs, ({ implRelativePath, specRelativePath }) => [path.resolve(confectDirectory, implRelativePath), path.resolve(confectDirectory, specRelativePath)]), Effect.gen(function* () {
251
322
  return yield* use(yield* Effect.forEach(pairs, Effect.fnUntraced(function* ({ implRelativePath, specRelativePath }) {
252
- if (!(yield* fs.exists(path.join(confectDirectory, specRelativePath)))) return yield* new MissingSpecFileError({
323
+ if (!(yield* fs.exists(path.join(confectDirectory, specRelativePath)))) return yield* MissingSpecFileError.make({
253
324
  implPath: implRelativePath,
254
325
  expectedSpecPath: specRelativePath
255
326
  });
256
- if (!(yield* fs.exists(path.join(confectDirectory, implRelativePath)))) return yield* new MissingImplFileError({
327
+ if (!(yield* fs.exists(path.join(confectDirectory, implRelativePath)))) return yield* MissingImplFileError.make({
257
328
  specPath: specRelativePath,
258
329
  expectedImplPath: implRelativePath
259
330
  });
260
- return yield* loadSpec(yield* toLeafModule(specRelativePath));
331
+ const leafModule = yield* toLeafModule(specRelativePath);
332
+ return yield* loadSpec(leafModule);
261
333
  }), { concurrency: VALIDATION_CONCURRENCY }));
262
334
  }));
263
335
  });
336
+ /**
337
+ * @internal
338
+ */
264
339
  const validateImplFiles = Effect.fn("LeafModule.validateImplFiles")((relativePaths) => withImplFiles(relativePaths, validateAllImpls));
340
+ /**
341
+ * @internal
342
+ */
265
343
  const validateAllImpls = Effect.fnUntraced(function* (leaves, required = []) {
266
344
  const path = yield* Path.Path;
267
345
  const confectDirectory = yield* ConfectDirectory.get;
268
346
  const implementationPaths = yield* Effect.forEach(leaves, ({ relativePath }) => implPathForSpec(relativePath).pipe(Effect.map((implPath) => path.resolve(confectDirectory, implPath))));
269
- const missing = (yield* withBatch(implementationPaths, Effect.forEach(leaves, (leaf) => validateImpl(leaf, required), { concurrency: VALIDATION_CONCURRENCY }))).flat().sort((left, right) => left.functionName.localeCompare(right.functionName));
270
- if (missing.length > 0) return yield* new RequiredMiddlewareError({ missing });
347
+ const missing = (yield* withBatch(implementationPaths, Effect.forEach(leaves, (leaf) => validateImpl(leaf, required), { concurrency: VALIDATION_CONCURRENCY }))).flat().sort((left, right) => pipe(left.functionName, String.localeCompare(right.functionName)));
348
+ if (missing.length > 0) return yield* RequiredMiddlewareError.make({ missing });
271
349
  });
350
+ /**
351
+ * @internal
352
+ */
272
353
  const loadAll = Effect.gen(function* () {
273
354
  const fs = yield* FileSystem.FileSystem;
274
355
  const path = yield* Path.Path;
275
356
  const confectDirectory = yield* ConfectDirectory.get;
276
357
  const specFiles = yield* discoverLeafSpecFiles;
277
- const results = yield* withBatch(specFiles.map((relativePath) => path.resolve(confectDirectory, relativePath)), Effect.forEach(specFiles, Effect.fnUntraced(function* (specRelativePath) {
358
+ const results = yield* withBatch(Array.map(specFiles, (relativePath) => path.resolve(confectDirectory, relativePath)), Effect.forEach(specFiles, Effect.fnUntraced(function* (specRelativePath) {
278
359
  const discovered = yield* toLeafModule(specRelativePath);
279
360
  const leaf = yield* loadSpec(discovered);
280
361
  const implRelativePath = yield* implPathForSpec(specRelativePath);
281
362
  const implAbsolutePath = path.join(confectDirectory, implRelativePath);
282
- if (!(yield* fs.exists(implAbsolutePath))) return yield* new MissingImplFileError({
363
+ if (!(yield* fs.exists(implAbsolutePath))) return yield* MissingImplFileError.make({
283
364
  specPath: specRelativePath,
284
365
  expectedImplPath: implRelativePath
285
366
  });
@@ -306,13 +387,12 @@ const validateOrphanImpls = Effect.fnUntraced(function* (specFiles) {
306
387
  const specRelativePath = yield* specPathForImpl(implRelativePath);
307
388
  if (HashSet.has(specPaths, specRelativePath)) return;
308
389
  const specAbsolutePath = path.join(confectDirectory, specRelativePath);
309
- if (!(yield* fs.exists(specAbsolutePath))) return yield* new MissingSpecFileError({
390
+ if (!(yield* fs.exists(specAbsolutePath))) return yield* MissingSpecFileError.make({
310
391
  implPath: implRelativePath,
311
392
  expectedSpecPath: specRelativePath
312
393
  });
313
394
  }));
314
395
  });
315
- //#endregion
316
396
  export { IMPL_SUFFIX, SPEC_SUFFIX, discoverLeafImplFiles, discoverLeafSpecFiles, exportNameFromModulePath, groupPathFromRelativeModulePath, implPathForSpec, isLeafSpecPath, loadAll, loadSpec, registeredFunctionsRelativePath, specImportPathFromGenerated, specPathForImpl, toLeafModule, validateAllImpls, validateImpl, validateImplFiles, withImplFiles };
317
397
 
318
398
  //# sourceMappingURL=LeafModule.mjs.map