@danielfgray/pg-sourcerer 0.2.2 → 0.4.0

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 (307) hide show
  1. package/bin/pgsourcerer +2 -0
  2. package/dist/__tests__/fixtures/index.d.ts +15 -0
  3. package/dist/__tests__/fixtures/index.d.ts.map +1 -0
  4. package/dist/__tests__/fixtures/index.js +19 -0
  5. package/dist/__tests__/fixtures/index.js.map +1 -0
  6. package/dist/__tests__/fixtures/introspection.json +40522 -0
  7. package/dist/cli.d.ts +0 -1
  8. package/dist/cli.js +7 -46
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +38 -5
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +13 -2
  13. package/dist/config.js.map +1 -1
  14. package/dist/{lib/conjure.d.ts → conjure/index.d.ts} +62 -3
  15. package/dist/conjure/index.d.ts.map +1 -0
  16. package/dist/{lib/conjure.js → conjure/index.js} +124 -3
  17. package/dist/conjure/index.js.map +1 -0
  18. package/dist/conjure/signature.d.ts +85 -0
  19. package/dist/conjure/signature.d.ts.map +1 -0
  20. package/dist/conjure/signature.js +130 -0
  21. package/dist/conjure/signature.js.map +1 -0
  22. package/dist/conjure/types.d.ts +97 -0
  23. package/dist/conjure/types.d.ts.map +1 -0
  24. package/dist/conjure/types.js +206 -0
  25. package/dist/conjure/types.js.map +1 -0
  26. package/dist/errors.d.ts +114 -139
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +82 -36
  29. package/dist/errors.js.map +1 -1
  30. package/dist/generate.d.ts +45 -46
  31. package/dist/generate.d.ts.map +1 -1
  32. package/dist/generate.js +86 -59
  33. package/dist/generate.js.map +1 -1
  34. package/dist/hex/builder.d.ts +12 -0
  35. package/dist/hex/builder.d.ts.map +1 -0
  36. package/dist/hex/builder.js +64 -0
  37. package/dist/hex/builder.js.map +1 -0
  38. package/dist/hex/ddl.d.ts +53 -0
  39. package/dist/hex/ddl.d.ts.map +1 -0
  40. package/dist/hex/ddl.js +306 -0
  41. package/dist/hex/ddl.js.map +1 -0
  42. package/dist/hex/index.d.ts +105 -0
  43. package/dist/hex/index.d.ts.map +1 -0
  44. package/dist/hex/index.js +81 -0
  45. package/dist/hex/index.js.map +1 -0
  46. package/dist/hex/primitives.d.ts +23 -0
  47. package/dist/hex/primitives.d.ts.map +1 -0
  48. package/dist/hex/primitives.js +38 -0
  49. package/dist/hex/primitives.js.map +1 -0
  50. package/dist/hex/query.d.ts +116 -0
  51. package/dist/hex/query.d.ts.map +1 -0
  52. package/dist/hex/query.js +219 -0
  53. package/dist/hex/query.js.map +1 -0
  54. package/dist/hex/types.d.ts +287 -0
  55. package/dist/hex/types.d.ts.map +1 -0
  56. package/dist/hex/types.js +431 -0
  57. package/dist/hex/types.js.map +1 -0
  58. package/dist/index.d.ts +17 -25
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +33 -44
  61. package/dist/index.js.map +1 -1
  62. package/dist/init.d.ts.map +1 -1
  63. package/dist/init.js +76 -140
  64. package/dist/init.js.map +1 -1
  65. package/dist/ir/extensions/queries.d.ts +6 -6
  66. package/dist/ir/extensions/queries.d.ts.map +1 -1
  67. package/dist/ir/extensions/queries.js +6 -4
  68. package/dist/ir/extensions/queries.js.map +1 -1
  69. package/dist/ir/extensions/schema-builder.d.ts.map +1 -1
  70. package/dist/ir/extensions/schema-builder.js.map +1 -1
  71. package/dist/ir/index.d.ts.map +1 -1
  72. package/dist/ir/index.js.map +1 -1
  73. package/dist/ir/relation-graph.d.ts.map +1 -1
  74. package/dist/ir/relation-graph.js +8 -8
  75. package/dist/ir/relation-graph.js.map +1 -1
  76. package/dist/ir/semantic-ir.d.ts +38 -0
  77. package/dist/ir/semantic-ir.d.ts.map +1 -1
  78. package/dist/ir/semantic-ir.js +50 -2
  79. package/dist/ir/semantic-ir.js.map +1 -1
  80. package/dist/ir/smart-tags.d.ts.map +1 -1
  81. package/dist/ir/smart-tags.js.map +1 -1
  82. package/dist/lib/field-utils.d.ts.map +1 -1
  83. package/dist/lib/field-utils.js +7 -7
  84. package/dist/lib/field-utils.js.map +1 -1
  85. package/dist/lib/join-graph.d.ts +95 -0
  86. package/dist/lib/join-graph.d.ts.map +1 -0
  87. package/dist/lib/join-graph.js +305 -0
  88. package/dist/lib/join-graph.js.map +1 -0
  89. package/dist/lib/picker.d.ts +60 -0
  90. package/dist/lib/picker.d.ts.map +1 -0
  91. package/dist/lib/picker.js +325 -0
  92. package/dist/lib/picker.js.map +1 -0
  93. package/dist/plugins/arktype.d.ts +20 -24
  94. package/dist/plugins/arktype.d.ts.map +1 -1
  95. package/dist/plugins/arktype.js +462 -386
  96. package/dist/plugins/arktype.js.map +1 -1
  97. package/dist/plugins/effect/http.d.ts +7 -0
  98. package/dist/plugins/effect/http.d.ts.map +1 -0
  99. package/dist/plugins/effect/http.js +460 -0
  100. package/dist/plugins/effect/http.js.map +1 -0
  101. package/dist/plugins/effect/index.d.ts +22 -0
  102. package/dist/plugins/effect/index.d.ts.map +1 -0
  103. package/dist/plugins/effect/index.js +65 -0
  104. package/dist/plugins/effect/index.js.map +1 -0
  105. package/dist/plugins/effect/models.d.ts +6 -0
  106. package/dist/plugins/effect/models.d.ts.map +1 -0
  107. package/dist/plugins/effect/models.js +116 -0
  108. package/dist/plugins/effect/models.js.map +1 -0
  109. package/dist/plugins/effect/repos.d.ts +21 -0
  110. package/dist/plugins/effect/repos.d.ts.map +1 -0
  111. package/dist/plugins/effect/repos.js +131 -0
  112. package/dist/plugins/effect/repos.js.map +1 -0
  113. package/dist/plugins/effect/schemas.d.ts +7 -0
  114. package/dist/plugins/effect/schemas.d.ts.map +1 -0
  115. package/dist/plugins/effect/schemas.js +75 -0
  116. package/dist/plugins/effect/schemas.js.map +1 -0
  117. package/dist/plugins/effect/shared.d.ts +116 -0
  118. package/dist/plugins/effect/shared.d.ts.map +1 -0
  119. package/dist/plugins/effect/shared.js +164 -0
  120. package/dist/plugins/effect/shared.js.map +1 -0
  121. package/dist/plugins/http-elysia.d.ts +20 -27
  122. package/dist/plugins/http-elysia.d.ts.map +1 -1
  123. package/dist/plugins/http-elysia.js +350 -475
  124. package/dist/plugins/http-elysia.js.map +1 -1
  125. package/dist/plugins/http-express.d.ts +20 -31
  126. package/dist/plugins/http-express.d.ts.map +1 -1
  127. package/dist/plugins/http-express.js +281 -268
  128. package/dist/plugins/http-express.js.map +1 -1
  129. package/dist/plugins/http-hono.d.ts +17 -33
  130. package/dist/plugins/http-hono.d.ts.map +1 -1
  131. package/dist/plugins/http-hono.js +317 -341
  132. package/dist/plugins/http-hono.js.map +1 -1
  133. package/dist/plugins/http-orpc.d.ts +34 -33
  134. package/dist/plugins/http-orpc.d.ts.map +1 -1
  135. package/dist/plugins/http-orpc.js +345 -257
  136. package/dist/plugins/http-orpc.js.map +1 -1
  137. package/dist/plugins/http-trpc.d.ts +33 -35
  138. package/dist/plugins/http-trpc.d.ts.map +1 -1
  139. package/dist/plugins/http-trpc.js +337 -241
  140. package/dist/plugins/http-trpc.js.map +1 -1
  141. package/dist/plugins/kysely.d.ts +54 -59
  142. package/dist/plugins/kysely.d.ts.map +1 -1
  143. package/dist/plugins/kysely.js +826 -687
  144. package/dist/plugins/kysely.js.map +1 -1
  145. package/dist/plugins/sql-queries.d.ts +38 -44
  146. package/dist/plugins/sql-queries.d.ts.map +1 -1
  147. package/dist/plugins/sql-queries.js +497 -897
  148. package/dist/plugins/sql-queries.js.map +1 -1
  149. package/dist/plugins/types.d.ts +12 -20
  150. package/dist/plugins/types.d.ts.map +1 -1
  151. package/dist/plugins/types.js +84 -227
  152. package/dist/plugins/types.js.map +1 -1
  153. package/dist/plugins/valibot.d.ts +7 -44
  154. package/dist/plugins/valibot.d.ts.map +1 -1
  155. package/dist/plugins/valibot.js +376 -382
  156. package/dist/plugins/valibot.js.map +1 -1
  157. package/dist/plugins/zod.d.ts +20 -24
  158. package/dist/plugins/zod.d.ts.map +1 -1
  159. package/dist/plugins/zod.js +370 -367
  160. package/dist/plugins/zod.js.map +1 -1
  161. package/dist/runtime/emit.d.ts +64 -0
  162. package/dist/runtime/emit.d.ts.map +1 -0
  163. package/dist/runtime/emit.js +445 -0
  164. package/dist/runtime/emit.js.map +1 -0
  165. package/dist/runtime/errors.d.ts +36 -0
  166. package/dist/runtime/errors.d.ts.map +1 -0
  167. package/dist/runtime/errors.js +29 -0
  168. package/dist/runtime/errors.js.map +1 -0
  169. package/dist/runtime/file-assignment.d.ts +161 -0
  170. package/dist/runtime/file-assignment.d.ts.map +1 -0
  171. package/dist/runtime/file-assignment.js +195 -0
  172. package/dist/runtime/file-assignment.js.map +1 -0
  173. package/dist/runtime/orchestrator.d.ts +62 -0
  174. package/dist/runtime/orchestrator.d.ts.map +1 -0
  175. package/dist/runtime/orchestrator.js +99 -0
  176. package/dist/runtime/orchestrator.js.map +1 -0
  177. package/dist/runtime/registry.d.ts +268 -0
  178. package/dist/runtime/registry.d.ts.map +1 -0
  179. package/dist/runtime/registry.js +436 -0
  180. package/dist/runtime/registry.js.map +1 -0
  181. package/dist/runtime/types.d.ts +182 -0
  182. package/dist/runtime/types.d.ts.map +1 -0
  183. package/dist/runtime/types.js +2 -0
  184. package/dist/runtime/types.js.map +1 -0
  185. package/dist/runtime/validation.d.ts +41 -0
  186. package/dist/runtime/validation.d.ts.map +1 -0
  187. package/dist/runtime/validation.js +70 -0
  188. package/dist/runtime/validation.js.map +1 -0
  189. package/dist/services/config-loader.d.ts.map +1 -1
  190. package/dist/services/config-loader.js +15 -6
  191. package/dist/services/config-loader.js.map +1 -1
  192. package/dist/services/config.d.ts +55 -25
  193. package/dist/services/config.d.ts.map +1 -1
  194. package/dist/services/config.js +60 -34
  195. package/dist/services/config.js.map +1 -1
  196. package/dist/services/file-writer.d.ts +3 -3
  197. package/dist/services/file-writer.d.ts.map +1 -1
  198. package/dist/services/file-writer.js +6 -8
  199. package/dist/services/file-writer.js.map +1 -1
  200. package/dist/services/inflection.d.ts +126 -27
  201. package/dist/services/inflection.d.ts.map +1 -1
  202. package/dist/services/inflection.js +300 -72
  203. package/dist/services/inflection.js.map +1 -1
  204. package/dist/services/introspection.d.ts.map +1 -1
  205. package/dist/services/introspection.js +6 -6
  206. package/dist/services/introspection.js.map +1 -1
  207. package/dist/services/ir-builder.d.ts.map +1 -1
  208. package/dist/services/ir-builder.js +73 -77
  209. package/dist/services/ir-builder.js.map +1 -1
  210. package/dist/services/ir.d.ts.map +1 -1
  211. package/dist/services/ir.js.map +1 -1
  212. package/dist/services/pg-types.d.ts.map +1 -1
  213. package/dist/services/pg-types.js +3 -3
  214. package/dist/services/pg-types.js.map +1 -1
  215. package/dist/services/smart-tags-parser.d.ts.map +1 -1
  216. package/dist/services/smart-tags-parser.js +4 -4
  217. package/dist/services/smart-tags-parser.js.map +1 -1
  218. package/dist/services/type-hints.d.ts.map +1 -1
  219. package/dist/services/type-hints.js +1 -1
  220. package/dist/services/type-hints.js.map +1 -1
  221. package/dist/services/user-module-parser.d.ts +46 -0
  222. package/dist/services/user-module-parser.d.ts.map +1 -0
  223. package/dist/services/user-module-parser.js +181 -0
  224. package/dist/services/user-module-parser.js.map +1 -0
  225. package/dist/shared/converters.d.ts +60 -0
  226. package/dist/shared/converters.d.ts.map +1 -0
  227. package/dist/shared/converters.js +168 -0
  228. package/dist/shared/converters.js.map +1 -0
  229. package/dist/shared/query-types.d.ts +95 -0
  230. package/dist/shared/query-types.d.ts.map +1 -0
  231. package/dist/shared/query-types.js +9 -0
  232. package/dist/shared/query-types.js.map +1 -0
  233. package/dist/testing.d.ts +125 -37
  234. package/dist/testing.d.ts.map +1 -1
  235. package/dist/testing.js +134 -42
  236. package/dist/testing.js.map +1 -1
  237. package/dist/user-module.d.ts +86 -0
  238. package/dist/user-module.d.ts.map +1 -0
  239. package/dist/user-module.js +55 -0
  240. package/dist/user-module.js.map +1 -0
  241. package/package.json +10 -6
  242. package/dist/lib/conjure.d.ts.map +0 -1
  243. package/dist/lib/conjure.js.map +0 -1
  244. package/dist/lib/hex.d.ts +0 -119
  245. package/dist/lib/hex.d.ts.map +0 -1
  246. package/dist/lib/hex.js +0 -188
  247. package/dist/lib/hex.js.map +0 -1
  248. package/dist/plugins/effect.d.ts +0 -53
  249. package/dist/plugins/effect.d.ts.map +0 -1
  250. package/dist/plugins/effect.js +0 -1074
  251. package/dist/plugins/effect.js.map +0 -1
  252. package/dist/plugins/kysely/queries.d.ts +0 -92
  253. package/dist/plugins/kysely/queries.d.ts.map +0 -1
  254. package/dist/plugins/kysely/queries.js +0 -1169
  255. package/dist/plugins/kysely/queries.js.map +0 -1
  256. package/dist/plugins/kysely/shared.d.ts +0 -59
  257. package/dist/plugins/kysely/shared.d.ts.map +0 -1
  258. package/dist/plugins/kysely/shared.js +0 -247
  259. package/dist/plugins/kysely/shared.js.map +0 -1
  260. package/dist/plugins/kysely/types.d.ts +0 -22
  261. package/dist/plugins/kysely/types.d.ts.map +0 -1
  262. package/dist/plugins/kysely/types.js +0 -428
  263. package/dist/plugins/kysely/types.js.map +0 -1
  264. package/dist/services/artifact-store.d.ts +0 -65
  265. package/dist/services/artifact-store.d.ts.map +0 -1
  266. package/dist/services/artifact-store.js +0 -57
  267. package/dist/services/artifact-store.js.map +0 -1
  268. package/dist/services/core-providers.d.ts +0 -15
  269. package/dist/services/core-providers.d.ts.map +0 -1
  270. package/dist/services/core-providers.js +0 -23
  271. package/dist/services/core-providers.js.map +0 -1
  272. package/dist/services/emissions.d.ts +0 -103
  273. package/dist/services/emissions.d.ts.map +0 -1
  274. package/dist/services/emissions.js +0 -241
  275. package/dist/services/emissions.js.map +0 -1
  276. package/dist/services/execution.d.ts +0 -35
  277. package/dist/services/execution.d.ts.map +0 -1
  278. package/dist/services/execution.js +0 -86
  279. package/dist/services/execution.js.map +0 -1
  280. package/dist/services/file-builder.d.ts +0 -85
  281. package/dist/services/file-builder.d.ts.map +0 -1
  282. package/dist/services/file-builder.js +0 -112
  283. package/dist/services/file-builder.js.map +0 -1
  284. package/dist/services/plugin-meta.d.ts +0 -33
  285. package/dist/services/plugin-meta.d.ts.map +0 -1
  286. package/dist/services/plugin-meta.js +0 -24
  287. package/dist/services/plugin-meta.js.map +0 -1
  288. package/dist/services/plugin-runner.d.ts +0 -42
  289. package/dist/services/plugin-runner.d.ts.map +0 -1
  290. package/dist/services/plugin-runner.js +0 -84
  291. package/dist/services/plugin-runner.js.map +0 -1
  292. package/dist/services/plugin.d.ts +0 -421
  293. package/dist/services/plugin.d.ts.map +0 -1
  294. package/dist/services/plugin.js +0 -197
  295. package/dist/services/plugin.js.map +0 -1
  296. package/dist/services/resolution.d.ts +0 -38
  297. package/dist/services/resolution.d.ts.map +0 -1
  298. package/dist/services/resolution.js +0 -242
  299. package/dist/services/resolution.js.map +0 -1
  300. package/dist/services/service-registry.d.ts +0 -74
  301. package/dist/services/service-registry.d.ts.map +0 -1
  302. package/dist/services/service-registry.js +0 -61
  303. package/dist/services/service-registry.js.map +0 -1
  304. package/dist/services/symbols.d.ts +0 -144
  305. package/dist/services/symbols.d.ts.map +0 -1
  306. package/dist/services/symbols.js +0 -144
  307. package/dist/services/symbols.js.map +0 -1
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Runtime Error Types
3
+ *
4
+ * All errors use Schema.TaggedError for:
5
+ * - Serializable errors (can send over network/save to DB)
6
+ * - Type-safe with built-in _tag for pattern matching
7
+ * - Yieldable directly without Effect.fail()
8
+ */
9
+ import { Schema } from "effect";
10
+ /**
11
+ * Error thrown when a plugin's declare phase fails.
12
+ */
13
+ export class DeclareError extends Schema.TaggedError()("DeclareError", {
14
+ message: Schema.String,
15
+ plugin: Schema.String,
16
+ cause: Schema.optional(Schema.Unknown),
17
+ }) {
18
+ }
19
+ /**
20
+ * Error thrown when a plugin's render phase fails.
21
+ */
22
+ export class RenderError extends Schema.TaggedError()("RenderError", {
23
+ message: Schema.String,
24
+ plugin: Schema.String,
25
+ symbol: Schema.optional(Schema.String),
26
+ cause: Schema.optional(Schema.Unknown),
27
+ }) {
28
+ }
29
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,MAAM,CAAC,WAAW,EAAgB,CAAC,cAAc,EAAE;IACnF,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;CACvC,CAAC;CAAG;AAEL;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAM,CAAC,WAAW,EAAe,CAAC,aAAa,EAAE;IAChF,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;CACvC,CAAC;CAAG"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * File assignment - assigns symbols to output files based on config rules
3
+ *
4
+ * Key insight: config controls file layout, not plugins. Plugins just declare
5
+ * symbols; this module decides where they go based on capability patterns.
6
+ *
7
+ * The inflection registry is used to determine the base entity for derived
8
+ * names like "UserInsert" → base entity "User". This ensures all shapes
9
+ * for an entity go to the same folder.
10
+ *
11
+ * Users can configure file naming via functions that receive entity info:
12
+ * { pattern: "type:", fileNaming: ({ name, schema }) => `${name.toLowerCase()}.ts` }
13
+ */
14
+ import type { SymbolDeclaration, Capability } from "./types.js";
15
+ import type { CoreInflection } from "../services/inflection.js";
16
+ /**
17
+ * Context provided to file naming functions
18
+ */
19
+ export interface FileNamingContext {
20
+ /** The symbol name (e.g., "User", "findUserById") */
21
+ readonly name: string;
22
+ /** The entity name extracted from capability (e.g., "User") */
23
+ readonly entityName: string;
24
+ /**
25
+ * The base entity name for file grouping.
26
+ * For shapes like "CommentInsert", this is "Comment".
27
+ * Falls back to entityName if not explicitly set.
28
+ */
29
+ readonly baseEntityName: string;
30
+ /**
31
+ * The folder name derived from baseEntityName via inflection.
32
+ * Default: uncapitalized baseEntityName (User → user, UserEmail → userEmail)
33
+ */
34
+ readonly folderName: string;
35
+ /**
36
+ * The shape variant, if this is a derived name (e.g., "insert", "update").
37
+ * Undefined for base entities, enums, functions.
38
+ */
39
+ readonly variant?: string;
40
+ /** The schema the entity belongs to */
41
+ readonly schema: string;
42
+ /** The full capability string */
43
+ readonly capability: Capability;
44
+ }
45
+ /**
46
+ * Function that determines the output file path for a symbol.
47
+ * Returns a path relative to the output directory.
48
+ */
49
+ export type FileNaming = (context: FileNamingContext) => string;
50
+ /**
51
+ * Normalize a file naming option to a FileNaming function.
52
+ * Accepts either a static string or a function.
53
+ * Used by plugins to support flexible config options.
54
+ */
55
+ export declare function normalizeFileNaming(option: string | FileNaming | undefined, defaultValue: string): FileNaming;
56
+ /**
57
+ * A symbol with its assigned output file path.
58
+ */
59
+ export interface AssignedSymbol {
60
+ readonly declaration: SymbolDeclaration;
61
+ readonly filePath: string;
62
+ }
63
+ /**
64
+ * Configuration for file assignment.
65
+ */
66
+ export interface FileAssignmentConfig {
67
+ /** Base output directory */
68
+ readonly outputDir: string;
69
+ /**
70
+ * Rules for assigning capabilities to files.
71
+ * Pattern matches capability prefix, first match wins.
72
+ */
73
+ readonly rules: readonly FileRule[];
74
+ /** Default file naming for unmatched symbols (relative to outputDir) */
75
+ readonly defaultFile?: string;
76
+ /**
77
+ * Inflection service with registry for name lookups.
78
+ * The registry is used to determine baseEntityName for derived names.
79
+ * folderName() transforms baseEntityName to folder format.
80
+ */
81
+ readonly inflection: CoreInflection;
82
+ }
83
+ /**
84
+ * A rule mapping capability patterns to output files.
85
+ */
86
+ export interface FileRule {
87
+ /** Capability pattern to match (prefix matching) */
88
+ readonly pattern: string;
89
+ /** Output subdirectory for this rule's files (relative to outputDir) */
90
+ readonly outputDir?: string;
91
+ /** Function to generate file name from entity info */
92
+ readonly fileNaming: FileNaming;
93
+ }
94
+ /**
95
+ * Input type for file rules that can be either a simple string or a full FileRule.
96
+ * Used for user config where simple patterns like "types.ts" are more convenient.
97
+ */
98
+ export type FileRuleInput = ({
99
+ pattern: string;
100
+ file: string;
101
+ outputDir?: string;
102
+ }) | ({
103
+ pattern: string;
104
+ file: FileNaming;
105
+ outputDir?: string;
106
+ });
107
+ /**
108
+ * Convert a FileRuleInput to a full FileRule.
109
+ * If file is a string, creates a function that returns that string.
110
+ */
111
+ export declare function normalizeFileRule(input: FileRuleInput): FileRule;
112
+ /**
113
+ * Merge file rules from plugins with user overrides.
114
+ * User overrides take precedence for matching patterns.
115
+ */
116
+ export declare function mergeFileRules(pluginDefaults: readonly FileRule[], userOverrides: readonly FileRuleInput[]): readonly FileRule[];
117
+ /**
118
+ * Extract entity name and schema from a capability string.
119
+ *
120
+ * Capability patterns:
121
+ * - "type:User" → entity is "User"
122
+ * - "type:public.User" → entity is "User", schema is "public"
123
+ * - "types:kysely:User" → entity is "User"
124
+ * - "queries:kysely:User:findById" → entity is "User"
125
+ * - "schema:zod:User" → entity is "User"
126
+ * - "http-routes:elysia:Post" → entity is "Post"
127
+ *
128
+ * The entity is the first PascalCase part after known prefixes and provider names.
129
+ */
130
+ export declare function parseCapabilityInfo(capability: Capability): {
131
+ entityName: string;
132
+ schema: string;
133
+ };
134
+ /**
135
+ * Assign symbols to output files based on config rules.
136
+ *
137
+ * @example
138
+ * const config = {
139
+ * outputDir: "src/generated",
140
+ * rules: [
141
+ * { pattern: "type:", fileNaming: ({ name }) => `${name.toLowerCase()}.ts` },
142
+ * { pattern: "schema:", fileNaming: ({ name }) => `schemas/${name.toLowerCase()}.ts` },
143
+ * ],
144
+ * }
145
+ * assignSymbolsToFiles(declarations, config)
146
+ */
147
+ export declare function assignSymbolsToFiles(declarations: readonly SymbolDeclaration[], config: FileAssignmentConfig): readonly AssignedSymbol[];
148
+ /**
149
+ * Group assigned symbols by file path.
150
+ */
151
+ export declare function groupByFile(assigned: readonly AssignedSymbol[]): ReadonlyMap<string, readonly AssignedSymbol[]>;
152
+ /**
153
+ * Find which file a capability would be assigned to.
154
+ * Returns a path relative to the output directory.
155
+ *
156
+ * Uses the inflection registry to determine the base entity for derived names.
157
+ * For example, "UserInsert" → baseEntity "User", so all User shapes go to
158
+ * the same folder.
159
+ */
160
+ export declare function getFileForCapability(declaration: SymbolDeclaration, config: FileAssignmentConfig): string;
161
+ //# sourceMappingURL=file-assignment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-assignment.d.ts","sourceRoot":"","sources":["../../src/runtime/file-assignment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,iBAAiB,KAAK,MAAM,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,mBA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QAAQ,EAAE,CAYrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAuCA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,SAAS,iBAAiB,EAAE,EAC1C,MAAM,EAAE,oBAAoB,GAC3B,SAAS,cAAc,EAAE,CAK3B;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,SAAS,cAAc,EAAE,GAClC,WAAW,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC,CAahD;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,iBAAiB,EAC9B,MAAM,EAAE,oBAAoB,GAC3B,MAAM,CAkER"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Normalize a file naming option to a FileNaming function.
3
+ * Accepts either a static string or a function.
4
+ * Used by plugins to support flexible config options.
5
+ */
6
+ export function normalizeFileNaming(option, defaultValue) {
7
+ if (option === undefined)
8
+ return () => defaultValue;
9
+ if (typeof option === "string")
10
+ return () => option;
11
+ return option;
12
+ }
13
+ /**
14
+ * Convert a FileRuleInput to a full FileRule.
15
+ * If file is a string, creates a function that returns that string.
16
+ */
17
+ export function normalizeFileRule(input) {
18
+ const fileValue = input.file;
19
+ if (typeof fileValue === "string") {
20
+ return {
21
+ pattern: input.pattern,
22
+ outputDir: input.outputDir,
23
+ fileNaming: () => fileValue,
24
+ };
25
+ }
26
+ return {
27
+ pattern: input.pattern,
28
+ outputDir: input.outputDir,
29
+ fileNaming: fileValue,
30
+ };
31
+ }
32
+ /**
33
+ * Merge file rules from plugins with user overrides.
34
+ * User overrides take precedence for matching patterns.
35
+ */
36
+ export function mergeFileRules(pluginDefaults, userOverrides) {
37
+ const overridePatterns = new Set(userOverrides.map((o) => o.pattern));
38
+ const merged = pluginDefaults
39
+ .filter((rule) => !overridePatterns.has(rule.pattern))
40
+ .map((rule) => rule);
41
+ for (const override of userOverrides) {
42
+ merged.push(normalizeFileRule(override));
43
+ }
44
+ return merged;
45
+ }
46
+ /**
47
+ * Extract entity name and schema from a capability string.
48
+ *
49
+ * Capability patterns:
50
+ * - "type:User" → entity is "User"
51
+ * - "type:public.User" → entity is "User", schema is "public"
52
+ * - "types:kysely:User" → entity is "User"
53
+ * - "queries:kysely:User:findById" → entity is "User"
54
+ * - "schema:zod:User" → entity is "User"
55
+ * - "http-routes:elysia:Post" → entity is "Post"
56
+ *
57
+ * The entity is the first PascalCase part after known prefixes and provider names.
58
+ */
59
+ export function parseCapabilityInfo(capability) {
60
+ const parts = capability.split(":");
61
+ // Known category prefixes that should be skipped
62
+ const knownCategories = new Set([
63
+ "type", "types", "schema", "schemas", "query", "queries",
64
+ "http-routes", "http-router", "http",
65
+ ]);
66
+ // Known provider names that should be skipped
67
+ const knownProviders = new Set([
68
+ "kysely", "drizzle", "effect-sql", "sql", "prisma",
69
+ "zod", "arktype", "effect", "valibot", "yup", "typebox",
70
+ "elysia", "hono", "fastify", "express", "trpc",
71
+ ]);
72
+ // Find the first part that looks like an entity name (PascalCase, not a known prefix/provider)
73
+ for (let i = 0; i < parts.length; i++) {
74
+ const part = parts[i];
75
+ const partLower = part.toLowerCase();
76
+ // Skip known categories and providers
77
+ if (knownCategories.has(partLower) || knownProviders.has(partLower)) {
78
+ continue;
79
+ }
80
+ // Check if part contains a schema qualifier (e.g., "public.User")
81
+ if (part.includes(".")) {
82
+ const [schemaPart, entityNamePart] = part.split(".");
83
+ return { entityName: entityNamePart ?? part, schema: schemaPart ?? "public" };
84
+ }
85
+ // This looks like an entity name (first char uppercase = PascalCase)
86
+ // If not PascalCase but we're past known prefixes, still use it
87
+ return { entityName: part, schema: "public" };
88
+ }
89
+ // Fallback: use the last part
90
+ return { entityName: parts[parts.length - 1] ?? capability, schema: "public" };
91
+ }
92
+ /**
93
+ * Assign symbols to output files based on config rules.
94
+ *
95
+ * @example
96
+ * const config = {
97
+ * outputDir: "src/generated",
98
+ * rules: [
99
+ * { pattern: "type:", fileNaming: ({ name }) => `${name.toLowerCase()}.ts` },
100
+ * { pattern: "schema:", fileNaming: ({ name }) => `schemas/${name.toLowerCase()}.ts` },
101
+ * ],
102
+ * }
103
+ * assignSymbolsToFiles(declarations, config)
104
+ */
105
+ export function assignSymbolsToFiles(declarations, config) {
106
+ return declarations.map((declaration) => {
107
+ const filePath = getFileForCapability(declaration, config);
108
+ return { declaration, filePath };
109
+ });
110
+ }
111
+ /**
112
+ * Group assigned symbols by file path.
113
+ */
114
+ export function groupByFile(assigned) {
115
+ const map = new Map();
116
+ for (const item of assigned) {
117
+ const existing = map.get(item.filePath);
118
+ if (existing) {
119
+ existing.push(item);
120
+ }
121
+ else {
122
+ map.set(item.filePath, [item]);
123
+ }
124
+ }
125
+ return map;
126
+ }
127
+ /**
128
+ * Find which file a capability would be assigned to.
129
+ * Returns a path relative to the output directory.
130
+ *
131
+ * Uses the inflection registry to determine the base entity for derived names.
132
+ * For example, "UserInsert" → baseEntity "User", so all User shapes go to
133
+ * the same folder.
134
+ */
135
+ export function getFileForCapability(declaration, config) {
136
+ // If declaration has explicit outputPath, use it directly
137
+ if (declaration.outputPath) {
138
+ return declaration.outputPath;
139
+ }
140
+ // Try to get entity info from registry first (most accurate)
141
+ const registryInfo = config.inflection.registry.lookup(declaration.name);
142
+ let entityName;
143
+ let baseEntityName;
144
+ let variant;
145
+ let schema;
146
+ if (registryInfo) {
147
+ // Registry has accurate info
148
+ baseEntityName = registryInfo.baseEntity;
149
+ variant = registryInfo.variant !== "entity" ? registryInfo.variant : undefined;
150
+ // For entityName in context, use the name from capability parsing for backwards compat
151
+ const parsed = parseCapabilityInfo(declaration.capability);
152
+ entityName = parsed.entityName;
153
+ schema = parsed.schema;
154
+ }
155
+ else if (declaration.baseEntityName) {
156
+ // Declaration has explicit baseEntityName - use it for both
157
+ // This is the canonical source when plugins set it explicitly
158
+ baseEntityName = declaration.baseEntityName;
159
+ entityName = declaration.baseEntityName;
160
+ const parsed = parseCapabilityInfo(declaration.capability);
161
+ schema = parsed.schema;
162
+ }
163
+ else {
164
+ // Fallback: parse from capability (legacy behavior)
165
+ const parsed = parseCapabilityInfo(declaration.capability);
166
+ entityName = parsed.entityName;
167
+ baseEntityName = parsed.entityName;
168
+ schema = parsed.schema;
169
+ }
170
+ // Compute folderName via inflection
171
+ const folderName = config.inflection.folderName(baseEntityName);
172
+ for (const rule of config.rules) {
173
+ if (declaration.capability.startsWith(rule.pattern)) {
174
+ const fileName = rule.fileNaming({
175
+ name: declaration.name,
176
+ entityName,
177
+ baseEntityName,
178
+ folderName,
179
+ variant,
180
+ schema,
181
+ capability: declaration.capability,
182
+ });
183
+ const baseDir = rule.outputDir ?? "";
184
+ if (baseDir) {
185
+ return `${baseDir}/${fileName}`;
186
+ }
187
+ return fileName;
188
+ }
189
+ }
190
+ if (config.defaultFile) {
191
+ return config.defaultFile;
192
+ }
193
+ throw new Error(`No file rule matches capability "${declaration.capability}" and no default file is configured`);
194
+ }
195
+ //# sourceMappingURL=file-assignment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-assignment.js","sourceRoot":"","sources":["../../src/runtime/file-assignment.ts"],"names":[],"mappings":"AAoDA;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAuC,EACvC,YAAoB;IAEpB,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC;IACpD,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;IACpD,OAAO,MAAM,CAAC;AAChB,CAAC;AAsDD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAoB;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;IAC7B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,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ACrC,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,GAAG,OAAO,IAAI,QAAQ,EAAE,CAAC;YAClC,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,MAAM,IAAI,KAAK,CACb,oCAAoC,WAAW,CAAC,UAAU,qCAAqC,CAChG,CAAC;AACJ,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { Effect } from "effect";
2
+ import type { Plugin, SymbolDeclaration, RenderedSymbol, Capability } from "./types.js";
3
+ import { SymbolRegistryImpl } from "./registry.js";
4
+ import type { AssignedSymbol } from "./file-assignment.js";
5
+ import { type CoreInflection } from "../services/inflection.js";
6
+ import { type TypeHintRegistry } from "../services/type-hints.js";
7
+ import type { SemanticIR } from "../ir/semantic-ir.js";
8
+ /**
9
+ * Result of running the orchestrator.
10
+ */
11
+ export interface OrchestratorResult {
12
+ /** All symbol declarations from all plugins */
13
+ readonly declarations: readonly SymbolDeclaration[];
14
+ /** All rendered symbols from all plugins */
15
+ readonly rendered: readonly RenderedSymbol[];
16
+ /** Symbols grouped by output file */
17
+ readonly fileGroups: ReadonlyMap<string, readonly AssignedSymbol[]>;
18
+ /** The symbol registry for lookups */
19
+ readonly registry: SymbolRegistryImpl;
20
+ /**
21
+ * Cross-references tracked during render phase.
22
+ * Maps: capability -> capabilities it references
23
+ * Used by emit phase to generate imports.
24
+ */
25
+ readonly references: ReadonlyMap<Capability, readonly Capability[]>;
26
+ }
27
+ /**
28
+ * Configuration for the orchestrator.
29
+ */
30
+ export interface OrchestratorConfig {
31
+ /** Plugins to run (or plugin factories) */
32
+ readonly plugins: readonly Plugin[];
33
+ /** Semantic IR */
34
+ readonly ir: SemanticIR;
35
+ /** Inflection service instance */
36
+ readonly inflection: CoreInflection;
37
+ /** Type hints registry */
38
+ readonly typeHints: TypeHintRegistry;
39
+ /** Default file for unmatched symbols */
40
+ readonly defaultFile?: string;
41
+ /** Base output directory (plugins' fileDefaults may use this via FileNamingContext) */
42
+ readonly outputDir: string;
43
+ }
44
+ /**
45
+ * Run plugins through two-phase execution.
46
+ *
47
+ * Phases:
48
+ * 1. Declare: All plugins declare their symbols (with IR, Inflection, TypeHints services)
49
+ * 2. Validate: Check capability satisfaction and dependency cycles
50
+ * 3. Assign: Assign symbols to output files
51
+ * 4. Render: All plugins render their symbol bodies (with SymbolRegistry service added)
52
+ *
53
+ * @param config - Orchestrator configuration
54
+ */
55
+ export declare const runPlugins: (config: OrchestratorConfig) => Effect.Effect<{
56
+ declarations: SymbolDeclaration[];
57
+ rendered: RenderedSymbol[];
58
+ fileGroups: ReadonlyMap<string, readonly AssignedSymbol[]>;
59
+ registry: SymbolRegistryImpl;
60
+ references: ReadonlyMap<string, readonly string[]>;
61
+ }, import("./registry.js").SymbolCollision | import("./registry.js").CategoryConflict | import("./errors.js").DeclareError | import("./errors.js").RenderError | import("./validation.js").UnsatisfiedCapability | import("./validation.js").CircularDependency, never>;
62
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/runtime/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,EAAkB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,KAAK,EAAwB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGjF,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAEpD,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAE7C,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC,CAAC;IAEpE,sCAAsC;IACtC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC;CACrE;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAEpC,kBAAkB;IAClB,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAC;IAExB,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IAEpC,0BAA0B;IAC1B,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IAErC,yCAAyC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B,uFAAuF;IACvF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,kBAAkB;;;;;;uQAqGjD,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { Effect, Layer, Array } from "effect";
2
+ import { SymbolRegistry, SymbolRegistryImpl } from "./registry.js";
3
+ import { validateAll } from "./validation.js";
4
+ import { assignSymbolsToFiles, groupByFile } from "./file-assignment.js";
5
+ import { IR } from "../services/ir.js";
6
+ import { Inflection } from "../services/inflection.js";
7
+ import { TypeHints } from "../services/type-hints.js";
8
+ /**
9
+ * Run plugins through two-phase execution.
10
+ *
11
+ * Phases:
12
+ * 1. Declare: All plugins declare their symbols (with IR, Inflection, TypeHints services)
13
+ * 2. Validate: Check capability satisfaction and dependency cycles
14
+ * 3. Assign: Assign symbols to output files
15
+ * 4. Render: All plugins render their symbol bodies (with SymbolRegistry service added)
16
+ *
17
+ * @param config - Orchestrator configuration
18
+ */
19
+ export const runPlugins = (config) => Effect.gen(function* () {
20
+ const registry = new SymbolRegistryImpl();
21
+ const plugins = config.plugins;
22
+ // Collect file defaults from all plugins
23
+ const pluginFileDefaults = Array.flatMap(plugins, p => p.fileDefaults ?? []);
24
+ // Use plugin file defaults directly (no user overrides - plugins handle their own config)
25
+ const mergedRules = pluginFileDefaults;
26
+ // Build file assignment config
27
+ const fileAssignment = {
28
+ outputDir: config.outputDir,
29
+ rules: mergedRules,
30
+ defaultFile: config.defaultFile ?? "index.ts",
31
+ inflection: config.inflection,
32
+ };
33
+ // Build service layers
34
+ const irLayer = Layer.succeed(IR, config.ir);
35
+ const inflectionLayer = Layer.succeed(Inflection, config.inflection);
36
+ const typeHintsLayer = Layer.succeed(TypeHints, config.typeHints);
37
+ const declareLayer = Layer.mergeAll(irLayer, inflectionLayer, typeHintsLayer);
38
+ // Phase 0: Register category providers
39
+ // Categories are bare strings in `provides` (no colons), e.g., "queries", "schema"
40
+ // This must happen before declare phase so capability resolution works
41
+ for (const plugin of plugins) {
42
+ for (const cap of plugin.provides) {
43
+ // A category is a bare string without colons
44
+ if (!cap.includes(":")) {
45
+ yield* registry.registerCategoryProvider(cap, plugin.name);
46
+ }
47
+ }
48
+ }
49
+ // Phase 1: Declare - collect all symbol declarations
50
+ // Track which plugin declared which capabilities for Phase 4
51
+ const allDeclarations = [];
52
+ const capabilitiesByPlugin = new Map();
53
+ for (const plugin of plugins) {
54
+ const decls = yield* plugin.declare.pipe(Effect.provide(declareLayer));
55
+ yield* registry.registerAll(decls);
56
+ allDeclarations.push(...decls);
57
+ capabilitiesByPlugin.set(plugin, decls.map(d => d.capability));
58
+ }
59
+ // Phase 2: Validate
60
+ yield* validateAll(plugins, registry);
61
+ // Phase 3: Assign symbols to files
62
+ const assigned = assignSymbolsToFiles(allDeclarations, fileAssignment);
63
+ const fileGroups = groupByFile(assigned);
64
+ // Phase 4: Render - add SymbolRegistry service
65
+ const registryLayer = Layer.succeed(SymbolRegistry, registry.toService());
66
+ const renderLayer = Layer.merge(declareLayer, registryLayer);
67
+ const allRendered = [];
68
+ for (const plugin of plugins) {
69
+ // Set context so registry knows which capabilities are being rendered
70
+ // Use the capabilities declared by this plugin in Phase 1
71
+ const pluginCapabilities = capabilitiesByPlugin.get(plugin) ?? [];
72
+ registry.setCurrentCapabilities(pluginCapabilities);
73
+ // Set owned declarations so plugins can iterate with registry.own()
74
+ const pluginDeclarations = allDeclarations.filter(d => pluginCapabilities.includes(d.capability));
75
+ registry.setOwnedDeclarations(pluginDeclarations);
76
+ // Handle renderWithImports - record references before render
77
+ // We need to actually call .ref() to trigger reference tracking
78
+ if (plugin.renderWithImports) {
79
+ for (const cap of plugin.renderWithImports) {
80
+ registry.import(cap).ref(); // Call ref() to record the reference
81
+ }
82
+ }
83
+ const rendered = yield* plugin.render.pipe(Effect.provide(renderLayer));
84
+ // Store rendered output and metadata for consumers
85
+ for (const symbol of rendered) {
86
+ registry.setRendered(symbol.capability, symbol.node, symbol.metadata);
87
+ }
88
+ allRendered.push(...rendered);
89
+ registry.clearCurrentCapabilities();
90
+ }
91
+ return {
92
+ declarations: allDeclarations,
93
+ rendered: allRendered,
94
+ fileGroups,
95
+ registry,
96
+ references: registry.getAllReferences(),
97
+ };
98
+ });
99
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/runtime/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,M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