@danielfgray/pg-sourcerer 0.3.0 → 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,436 @@
1
+ import recast from "recast";
2
+ import { Context, Effect, Schema } from "effect";
3
+ const b = recast.types.builders;
4
+ function toExpr(node) {
5
+ return node;
6
+ }
7
+ // =============================================================================
8
+ // Error Types
9
+ // =============================================================================
10
+ /**
11
+ * Error thrown when two plugins try to register the same capability.
12
+ */
13
+ export class SymbolCollision extends Schema.TaggedError()("SymbolCollision", {
14
+ message: Schema.String,
15
+ capability: Schema.String,
16
+ existingSymbol: Schema.String,
17
+ newSymbol: Schema.String,
18
+ }) {
19
+ }
20
+ /**
21
+ * Error when trying to get a handle for an unregistered capability.
22
+ */
23
+ export class CapabilityNotFound extends Schema.TaggedError()("CapabilityNotFound", {
24
+ message: Schema.String,
25
+ capability: Schema.String,
26
+ }) {
27
+ }
28
+ /**
29
+ * Error when multiple plugins try to provide the same capability category.
30
+ */
31
+ export class CategoryConflict extends Schema.TaggedError()("CategoryConflict", {
32
+ message: Schema.String,
33
+ category: Schema.String,
34
+ existingProvider: Schema.String,
35
+ newProvider: Schema.String,
36
+ }) {
37
+ }
38
+ /**
39
+ * Creates a SymbolHandle that tracks cross-references.
40
+ *
41
+ * @param decl - The symbol being referenced
42
+ * @param metadata - Optional metadata from render phase (may include consume callback)
43
+ * @param onReference - Callback when ref() or call() is invoked (for import tracking)
44
+ */
45
+ export function createSymbolHandle(decl, metadata, onReference) {
46
+ // Extract consume callback from metadata if present
47
+ const consumeFn = metadata?.consume;
48
+ return {
49
+ name: decl.name,
50
+ capability: decl.capability,
51
+ metadata,
52
+ ref: () => {
53
+ onReference?.(decl.capability);
54
+ return b.identifier(decl.name);
55
+ },
56
+ call: (...args) => {
57
+ onReference?.(decl.capability);
58
+ return b.callExpression(b.identifier(decl.name), args.map(arg => toExpr(arg)));
59
+ },
60
+ consume: consumeFn
61
+ ? (input) => {
62
+ onReference?.(decl.capability);
63
+ return consumeFn(input);
64
+ }
65
+ : undefined,
66
+ };
67
+ }
68
+ /**
69
+ * Effect Context tag for SymbolRegistry service.
70
+ * Plugins access this in render phase via `yield* SymbolRegistry`.
71
+ */
72
+ export class SymbolRegistry extends Context.Tag("SymbolRegistry")() {
73
+ }
74
+ // =============================================================================
75
+ // SymbolRegistry Implementation
76
+ // =============================================================================
77
+ /**
78
+ * Internal registry implementation that tracks all declared symbols.
79
+ *
80
+ * Used during the two-phase plugin execution:
81
+ * 1. Declare phase: Plugins register symbols via register()
82
+ * 2. Render phase: Plugins lookup symbols via resolve()/import()
83
+ *
84
+ * During render phase, tracks cross-references between capabilities
85
+ * for import generation in the emit phase.
86
+ */
87
+ export class SymbolRegistryImpl {
88
+ symbols = new Map();
89
+ rendered = new Map();
90
+ referenceCallbacks = new Map();
91
+ /**
92
+ * Category providers: Maps category name -> provider plugin name.
93
+ * e.g., "queries" -> "kysely", "schema" -> "zod"
94
+ * Used to resolve generic capability prefixes to implementation-specific ones.
95
+ */
96
+ categoryProviders = new Map();
97
+ /**
98
+ * Cross-reference tracking: Maps source capability -> set of referenced capabilities.
99
+ * Populated during render phase when registry.import(cap).ref() is called.
100
+ */
101
+ references = new Map();
102
+ /**
103
+ * Current capabilities being rendered. Set by orchestrator before calling render().
104
+ * When a handle's ref()/call() is invoked, edges are added from these to the target.
105
+ *
106
+ * When forSymbol() is active, this contains only the single scoped capability.
107
+ */
108
+ currentCapabilities = [];
109
+ /**
110
+ * Declarations owned by the current plugin.
111
+ * Set by orchestrator before render phase.
112
+ */
113
+ ownedDeclarations = [];
114
+ /**
115
+ * Stack for nested forSymbol() calls (though nesting is unusual).
116
+ * Stores the previous currentCapabilities to restore after forSymbol() completes.
117
+ */
118
+ capabilityStack = [];
119
+ /**
120
+ * Register a symbol declaration. Called during declare phase.
121
+ * Returns Effect that fails with SymbolCollision if capability already registered.
122
+ */
123
+ register(decl) {
124
+ return Effect.gen(this, function* () {
125
+ if (this.symbols.has(decl.capability)) {
126
+ const existing = this.symbols.get(decl.capability);
127
+ return yield* new SymbolCollision({
128
+ message: `Capability "${decl.capability}" already registered by symbol "${existing.name}"`,
129
+ capability: decl.capability,
130
+ existingSymbol: existing.name,
131
+ newSymbol: decl.name,
132
+ });
133
+ }
134
+ this.symbols.set(decl.capability, decl);
135
+ });
136
+ }
137
+ /**
138
+ * Store rendered output for a symbol. Called during render phase.
139
+ */
140
+ setRendered(capability, node, metadata) {
141
+ this.rendered.set(capability, { node, metadata });
142
+ }
143
+ /**
144
+ * Get rendered metadata for a capability.
145
+ */
146
+ getRenderedMetadata(capability) {
147
+ return this.rendered.get(capability)?.metadata;
148
+ }
149
+ /**
150
+ * Register multiple declarations at once.
151
+ */
152
+ registerAll(decls) {
153
+ return Effect.forEach(decls, decl => this.register(decl), { discard: true });
154
+ }
155
+ // ===========================================================================
156
+ // Category Provider Registration
157
+ // ===========================================================================
158
+ /**
159
+ * Register a plugin as the provider for a capability category.
160
+ * Only one plugin can provide each category.
161
+ *
162
+ * @param category - Category name (e.g., "queries", "schema")
163
+ * @param pluginName - Name of the plugin providing this category
164
+ */
165
+ registerCategoryProvider(category, pluginName) {
166
+ return Effect.gen(this, function* () {
167
+ if (this.categoryProviders.has(category)) {
168
+ const existing = this.categoryProviders.get(category);
169
+ return yield* new CategoryConflict({
170
+ message: `Category "${category}" already provided by "${existing}", cannot add "${pluginName}"`,
171
+ category,
172
+ existingProvider: existing,
173
+ newProvider: pluginName,
174
+ });
175
+ }
176
+ this.categoryProviders.set(category, pluginName);
177
+ });
178
+ }
179
+ /**
180
+ * Get the provider name for a category.
181
+ */
182
+ getCategoryProvider(category) {
183
+ return this.categoryProviders.get(category);
184
+ }
185
+ /**
186
+ * Resolve a generic capability to implementation-specific.
187
+ *
188
+ * Examples:
189
+ * - "queries:User:findById" → "queries:kysely:User:findById" (if kysely provides queries)
190
+ * - "schema:UserInsert" → "schema:zod:UserInsert" (if zod provides schema)
191
+ * - "queries:kysely:User:findById" → unchanged (already specific)
192
+ * - "type:User" → unchanged (no category provider needed)
193
+ */
194
+ resolveCapability(capability) {
195
+ const colonIdx = capability.indexOf(":");
196
+ if (colonIdx === -1)
197
+ return capability;
198
+ const category = capability.slice(0, colonIdx);
199
+ const rest = capability.slice(colonIdx + 1);
200
+ const provider = this.categoryProviders.get(category);
201
+ if (!provider)
202
+ return capability; // No provider for this category
203
+ // Check if rest already starts with the provider name (already specific)
204
+ if (rest.startsWith(`${provider}:`))
205
+ return capability;
206
+ // Also check if rest starts with a known provider (different from current)
207
+ // This handles the case where the capability is already implementation-specific
208
+ // We can detect this by checking if there's another colon and the first segment
209
+ // looks like a provider name (lowercase, short)
210
+ const nextColonIdx = rest.indexOf(":");
211
+ if (nextColonIdx !== -1) {
212
+ const possibleProvider = rest.slice(0, nextColonIdx);
213
+ // If this looks like a provider name (e.g., "kysely", "zod", "drizzle"),
214
+ // assume it's already specific. Simple heuristic: no uppercase, short.
215
+ if (possibleProvider.length <= 15 && possibleProvider === possibleProvider.toLowerCase()) {
216
+ // Check if we have this registered as ANY category provider
217
+ for (const [, p] of this.categoryProviders) {
218
+ if (p === possibleProvider)
219
+ return capability; // Already specific
220
+ }
221
+ }
222
+ }
223
+ // Resolve: queries:User:findById → queries:kysely:User:findById
224
+ return `${category}:${provider}:${rest}`;
225
+ }
226
+ /**
227
+ * Resolve a capability to its symbol reference.
228
+ * Automatically resolves generic capabilities to implementation-specific.
229
+ * Returns undefined if not found.
230
+ */
231
+ resolve(capability) {
232
+ const resolved = this.resolveCapability(capability);
233
+ const decl = this.symbols.get(resolved);
234
+ if (!decl)
235
+ return undefined;
236
+ return { name: decl.name, capability: decl.capability };
237
+ }
238
+ /**
239
+ * Check if a capability is registered.
240
+ * Automatically resolves generic capabilities to implementation-specific.
241
+ */
242
+ has(capability) {
243
+ const resolved = this.resolveCapability(capability);
244
+ return this.symbols.has(resolved);
245
+ }
246
+ /**
247
+ * Register a callback to be invoked when a symbol is referenced.
248
+ * Used for import tracking across files.
249
+ */
250
+ onReference(capability, callback) {
251
+ const resolved = this.resolveCapability(capability);
252
+ if (!this.referenceCallbacks.has(resolved)) {
253
+ this.referenceCallbacks.set(resolved, new Set());
254
+ }
255
+ this.referenceCallbacks.get(resolved).add(callback);
256
+ }
257
+ /**
258
+ * Get a SymbolHandle for referencing another symbol.
259
+ * The handle tracks when ref()/call() are used for import generation.
260
+ * Automatically resolves generic capabilities to implementation-specific.
261
+ * Returns Effect that fails with CapabilityNotFound if not registered.
262
+ */
263
+ getHandle(capability) {
264
+ return Effect.gen(this, function* () {
265
+ const resolved = this.resolveCapability(capability);
266
+ const decl = this.symbols.get(resolved);
267
+ if (!decl) {
268
+ return yield* new CapabilityNotFound({
269
+ message: `Capability "${capability}" not found in registry (resolved to "${resolved}")`,
270
+ capability,
271
+ });
272
+ }
273
+ const metadata = this.getRenderedMetadata(resolved);
274
+ return createSymbolHandle(decl, metadata, cap => {
275
+ this.recordReference(cap);
276
+ const callbacks = this.referenceCallbacks.get(cap);
277
+ callbacks?.forEach(cb => cb(cap));
278
+ });
279
+ });
280
+ }
281
+ /**
282
+ * Get a SymbolHandle synchronously (for service interface).
283
+ * Automatically resolves generic capabilities to implementation-specific.
284
+ * Throws if not found.
285
+ */
286
+ import(capability) {
287
+ const resolved = this.resolveCapability(capability);
288
+ const decl = this.symbols.get(resolved);
289
+ if (!decl) {
290
+ throw new Error(`Capability "${capability}" not found in registry (resolved to "${resolved}")`);
291
+ }
292
+ const metadata = this.getRenderedMetadata(resolved);
293
+ return createSymbolHandle(decl, metadata, cap => {
294
+ this.recordReference(cap);
295
+ const callbacks = this.referenceCallbacks.get(cap);
296
+ callbacks?.forEach(cb => cb(cap));
297
+ });
298
+ }
299
+ /**
300
+ * Get all registered symbols.
301
+ */
302
+ all() {
303
+ return Array.from(this.symbols.values());
304
+ }
305
+ /**
306
+ * Get symbols that match a capability pattern.
307
+ * Pattern uses simple prefix matching: "type:" matches all types.
308
+ * Note: For category-based queries, use the implementation-specific prefix
309
+ * (e.g., "queries:kysely:") or query by category pattern (e.g., "queries:").
310
+ */
311
+ query(pattern) {
312
+ // If pattern is a bare category (e.g., "queries:"), resolve to provider prefix
313
+ const colonIdx = pattern.indexOf(":");
314
+ if (colonIdx !== -1 && pattern.endsWith(":")) {
315
+ const category = pattern.slice(0, colonIdx);
316
+ const provider = this.categoryProviders.get(category);
317
+ if (provider) {
318
+ // Query with resolved prefix: "queries:" → "queries:kysely:"
319
+ const resolvedPattern = `${category}:${provider}:`;
320
+ return this.all().filter(decl => decl.capability.startsWith(resolvedPattern));
321
+ }
322
+ }
323
+ return this.all().filter(decl => decl.capability.startsWith(pattern));
324
+ }
325
+ /**
326
+ * Get the declaration for a specific capability.
327
+ * Automatically resolves generic capabilities to implementation-specific.
328
+ */
329
+ get(capability) {
330
+ const resolved = this.resolveCapability(capability);
331
+ return this.symbols.get(resolved);
332
+ }
333
+ // ===========================================================================
334
+ // Reference Tracking (for render phase)
335
+ // ===========================================================================
336
+ /**
337
+ * Set the current capabilities being rendered.
338
+ * Called by orchestrator before each plugin's render() phase.
339
+ */
340
+ setCurrentCapabilities(caps) {
341
+ this.currentCapabilities = caps;
342
+ }
343
+ /**
344
+ * Clear current capabilities context.
345
+ * Called by orchestrator after each plugin's render() completes.
346
+ */
347
+ clearCurrentCapabilities() {
348
+ this.currentCapabilities = [];
349
+ this.ownedDeclarations = [];
350
+ this.capabilityStack = [];
351
+ }
352
+ /**
353
+ * Set the declarations owned by the current plugin.
354
+ * Called by orchestrator before render phase.
355
+ */
356
+ setOwnedDeclarations(decls) {
357
+ this.ownedDeclarations = decls;
358
+ }
359
+ /**
360
+ * Get declarations owned by the current plugin.
361
+ * Returns only the symbols declared by this plugin in Phase 1.
362
+ */
363
+ own() {
364
+ return this.ownedDeclarations;
365
+ }
366
+ /**
367
+ * Scope cross-reference tracking to a single symbol.
368
+ * All `import().ref()` calls within the callback are attributed
369
+ * only to the specified capability.
370
+ *
371
+ * @param capability - The capability to scope refs to
372
+ * @param fn - Function to execute with scoped context
373
+ * @returns The result of fn()
374
+ */
375
+ forSymbol(capability, fn) {
376
+ // Push current state onto stack
377
+ this.capabilityStack.push(this.currentCapabilities);
378
+ // Set single capability as current
379
+ this.currentCapabilities = [capability];
380
+ try {
381
+ return fn();
382
+ }
383
+ finally {
384
+ // Restore previous state
385
+ this.currentCapabilities = this.capabilityStack.pop() ?? [];
386
+ }
387
+ }
388
+ /**
389
+ * Record a reference from current capabilities to target.
390
+ * Called internally when SymbolHandle.ref() or .call() is invoked.
391
+ */
392
+ recordReference(target) {
393
+ for (const source of this.currentCapabilities) {
394
+ if (source === target)
395
+ continue;
396
+ if (!this.references.has(source)) {
397
+ this.references.set(source, new Set());
398
+ }
399
+ this.references.get(source).add(target);
400
+ }
401
+ }
402
+ /**
403
+ * Get all capabilities referenced by a given capability.
404
+ */
405
+ getReferences(capability) {
406
+ const refs = this.references.get(capability);
407
+ return refs ? Array.from(refs) : [];
408
+ }
409
+ /**
410
+ * Get the full reference map for emit phase.
411
+ * Maps: source capability -> capabilities it references
412
+ */
413
+ getAllReferences() {
414
+ const result = new Map();
415
+ for (const [source, targets] of this.references) {
416
+ result.set(source, Array.from(targets));
417
+ }
418
+ return result;
419
+ }
420
+ /**
421
+ * Create a service instance that conforms to SymbolRegistryService.
422
+ * Used by orchestrator to provide the service to plugins.
423
+ */
424
+ toService() {
425
+ return {
426
+ resolve: cap => this.resolve(cap),
427
+ import: cap => this.import(cap),
428
+ query: pattern => this.query(pattern),
429
+ has: cap => this.has(cap),
430
+ getMetadata: cap => this.getRenderedMetadata(cap),
431
+ own: () => this.own(),
432
+ forSymbol: (cap, fn) => this.forSymbol(cap, fn),
433
+ };
434
+ }
435
+ }
436
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/runtime/registry.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,SAAS,MAAM,CAAC,IAAkB;IAChC,OAAO,IAAsB,CAAC;AAChC,CAAC;AAED,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,MAAM,CAAC,WAAW,EAAmB,CAAC,iBAAiB,EAAE;IAC5F,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,UAAU,EAAE,MAAM,CAAC,MAAM;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM;IAC7B,SAAS,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC;CAAG;AAEL;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,WAAW,EAAsB,CAC9E,oBAAoB,EACpB;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,UAAU,EAAE,MAAM,CAAC,MAAM;CAC1B,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ACxE,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Runtime Types for Two-Phase Plugin Execution
3
+ */
4
+ import type { Effect } from "effect";
5
+ import type { IR } from "../services/ir.js";
6
+ import type { Inflection } from "../services/inflection.js";
7
+ import type { TypeHints } from "../services/type-hints.js";
8
+ import type { SymbolRegistry } from "./registry.js";
9
+ import type { DeclareError, RenderError } from "./errors.js";
10
+ import type { ExternalImport } from "./emit.js";
11
+ import type { FileRule } from "./file-assignment.js";
12
+ /**
13
+ * Capability identifier for symbol categorization.
14
+ *
15
+ * Examples:
16
+ * - "type:User" - A TypeScript type for the User entity
17
+ * - "schema:zod:User" - A Zod schema for User
18
+ * - "query:findUserById" - A query function
19
+ *
20
+ * Combined with `name`, forms a unique symbol identity.
21
+ */
22
+ export type Capability = string;
23
+ /**
24
+ * What a plugin declares it will produce in Phase 1.
25
+ *
26
+ * Symbols are identified by `(name, capability)` tuple, allowing
27
+ * multiple plugins to create symbols with the same name but different
28
+ * capabilities (e.g., "User" as type vs "User" as Zod schema).
29
+ */
30
+ export interface SymbolDeclaration {
31
+ /** Symbol name, e.g., "User", "findUserById" */
32
+ readonly name: string;
33
+ /** Capability identifier, e.g., "type:User", "query:findUserById" */
34
+ readonly capability: Capability;
35
+ /** Capabilities this symbol requires from other plugins */
36
+ readonly dependsOn?: readonly Capability[];
37
+ /**
38
+ * Explicit output path for this symbol.
39
+ * Relative to the output directory.
40
+ * If not set, the file assignment rules will determine the path.
41
+ */
42
+ readonly outputPath?: string;
43
+ /**
44
+ * The base entity name for file grouping purposes.
45
+ * For shapes like "CommentInsert", this would be "Comment".
46
+ * If not set, falls back to parsing from capability/name.
47
+ */
48
+ readonly baseEntityName?: string;
49
+ }
50
+ /**
51
+ * Reference to a symbol for cross-plugin dependencies.
52
+ */
53
+ export interface SymbolRef {
54
+ /** Symbol name */
55
+ readonly name: string;
56
+ /** Capability identifier */
57
+ readonly capability: Capability;
58
+ }
59
+ /**
60
+ * What `render()` returns for each symbol in Phase 2.
61
+ *
62
+ * Contains the AST node and optional export configuration.
63
+ */
64
+ export interface RenderedSymbol {
65
+ /** Symbol name */
66
+ readonly name: string;
67
+ /** Capability identifier */
68
+ readonly capability: Capability;
69
+ /** AST node (recast/AST types - kept loose for flexibility) */
70
+ readonly node: unknown;
71
+ /** Export behavior: false=internal, true='named', 'default'=default export */
72
+ readonly exports?: boolean | "default" | "named";
73
+ /** Plugin-specific metadata for consumers (e.g., QueryDescriptor for query plugins) */
74
+ readonly metadata?: unknown;
75
+ /** External imports needed by this symbol */
76
+ readonly externalImports?: readonly ExternalImport[];
77
+ }
78
+ /**
79
+ * Handle for referencing another symbol with automatic import tracking.
80
+ *
81
+ * Calling `.ref()` or `.call()` records the cross-reference, which the
82
+ * runtime uses to auto-generate imports between files.
83
+ */
84
+ export interface SymbolHandle {
85
+ /** Symbol name */
86
+ readonly name: string;
87
+ /** Capability identifier */
88
+ readonly capability: Capability;
89
+ /** Plugin-specific metadata (e.g., QueryDescriptor for query symbols) */
90
+ readonly metadata?: unknown;
91
+ /** Use as type reference - returns AST node and tracks reference */
92
+ ref: () => unknown;
93
+ /** Use as call expression - returns AST node and tracks reference */
94
+ call: (...args: unknown[]) => unknown;
95
+ /**
96
+ * Consume/validate input through this symbol.
97
+ *
98
+ * Used by schema plugins to provide validation wrappers that HTTP plugins
99
+ * can use without knowing the specific schema library.
100
+ *
101
+ * Examples:
102
+ * - Zod: `Schema.parse(input)` or `Schema.safeParse(input)`
103
+ * - ArkType: `Schema(input)` or `Schema.assert(input)`
104
+ * - Valibot: `v.parse(Schema, input)`
105
+ *
106
+ * Returns undefined if this symbol doesn't support consumption (e.g., types).
107
+ */
108
+ consume?: (input: unknown) => unknown;
109
+ }
110
+ /**
111
+ * Services available during declare phase.
112
+ * Plugins access these via `yield* ServiceTag`.
113
+ */
114
+ export type DeclareServices = IR | Inflection | TypeHints;
115
+ /**
116
+ * Services available during render phase.
117
+ * Includes DeclareServices plus SymbolRegistry for cross-plugin references.
118
+ */
119
+ export type RenderServices = DeclareServices | SymbolRegistry;
120
+ /**
121
+ * Plugin interface for two-phase code generation.
122
+ *
123
+ * Plugins are Effects that access services and return immutable data.
124
+ *
125
+ * Example:
126
+ * ```typescript
127
+ * const typesPlugin: Plugin = {
128
+ * name: "types",
129
+ * provides: ["type:User"],
130
+ *
131
+ * declare: Effect.gen(function* () {
132
+ * const ir = yield* IR
133
+ * return Array.from(ir.entities.values())
134
+ * .filter(isTableEntity)
135
+ * .map(e => ({ name: e.name, capability: `type:${e.name}` }))
136
+ * }),
137
+ *
138
+ * render: Effect.gen(function* () {
139
+ * const ir = yield* IR
140
+ * // ... generate AST
141
+ * return renderedSymbols
142
+ * }),
143
+ * }
144
+ * ```
145
+ */
146
+ export interface Plugin {
147
+ /** Plugin name for error messages and debugging */
148
+ readonly name: string;
149
+ /**
150
+ * Capabilities this plugin provides to the system.
151
+ *
152
+ * Can include:
153
+ * - **Category declarations**: e.g., `"queries"`, `"schema"` - declares this plugin
154
+ * as THE provider for that category. Only one plugin can provide each category.
155
+ * Consumer plugins use generic prefixes that resolve to the registered provider.
156
+ * - **Specific capabilities**: e.g., `"type:User"` - declares a specific symbol.
157
+ *
158
+ * For category providers, the registry resolves generic capabilities:
159
+ * - `queries:User:findById` → `queries:kysely:User:findById` (if kysely provides "queries")
160
+ * - `schema:UserInsert` → `schema:zod:UserInsert` (if zod provides "schema")
161
+ */
162
+ readonly provides: readonly Capability[];
163
+ /** Capabilities this plugin requires from other plugins */
164
+ readonly consumes?: readonly Capability[];
165
+ /**
166
+ * Capabilities to import during render phase.
167
+ * These will be tracked as cross-references for import generation.
168
+ * Alternative to calling registry.import() in render Effect.
169
+ */
170
+ readonly renderWithImports?: readonly Capability[];
171
+ /**
172
+ * Default file assignment rules for symbols this plugin produces.
173
+ * Users can override these via fileOverrides in their config.
174
+ * First matching rule wins.
175
+ */
176
+ readonly fileDefaults?: readonly FileRule[];
177
+ /** Phase 1: Declare symbols (Effect with DeclareServices) */
178
+ readonly declare: Effect.Effect<readonly SymbolDeclaration[], DeclareError, DeclareServices>;
179
+ /** Phase 2: Render symbol bodies (Effect with RenderServices) */
180
+ readonly render: Effect.Effect<readonly RenderedSymbol[], RenderError, RenderServices>;
181
+ }
182
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,qEAAqE;IACrE,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACx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