@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
@@ -1,421 +0,0 @@
1
- /**
2
- * Plugin System
3
- *
4
- * A generic request/plugin coordination system. Core routes requests to plugins
5
- * without understanding what resources represent (schemas, queries, routes, etc.).
6
- *
7
- * Key concepts:
8
- * - Plugin: Handles requests for a resource kind
9
- * - Request: A need for a resource with specific params
10
- * - DeferredResource: A placeholder resolved after plugin execution
11
- *
12
- * Execution phases:
13
- * 1. Registration - Plugins registered, singletons identified
14
- * 2. Collection - Requests collected via ctx.request()
15
- * 3. Resolution - Match requests to plugins, build DAG
16
- * 4. Execution - Run plugins in topological order
17
- * 5. Finalization - Emit files, resolve imports
18
- */
19
- import { Context, Layer, Schema as S } from "effect";
20
- import type { FileBuilder } from "./file-builder.js";
21
- import type { SymbolRegistry } from "./symbols.js";
22
- import type { SemanticIR } from "../ir/semantic-ir.js";
23
- import type { TypeHintRegistry } from "./type-hints.js";
24
- import type { CoreInflection } from "./inflection.js";
25
- /**
26
- * A request for a resource of a specific kind with arbitrary params.
27
- *
28
- * Core does not interpret the params - they are opaque data passed to providers.
29
- */
30
- export interface ResourceRequest {
31
- /** The resource kind (e.g., "validation-schema", "query-functions") */
32
- readonly kind: string;
33
- /** Opaque params interpreted by the provider */
34
- readonly params: unknown;
35
- }
36
- /**
37
- * A service handler function that processes requests for a specific kind.
38
- *
39
- * Registered by plugins via ctx.registerHandler() and invoked by ctx.request().
40
- * This enables on-demand generation where a later plugin can request resources
41
- * from an earlier plugin's handler.
42
- *
43
- * @typeParam TParams - The request params shape
44
- * @typeParam TResult - The result shape
45
- */
46
- export type ServiceHandler<TParams = unknown, TResult = unknown> = (params: TParams, ctx: PluginContext) => TResult;
47
- /**
48
- * A deferred resource reference.
49
- *
50
- * Created when a provider calls ctx.request(). The result is populated
51
- * after the resolution and execution phases complete.
52
- */
53
- export interface DeferredResource<T = unknown> {
54
- /** The resource kind this request is for */
55
- readonly kind: string;
56
- /** The params used for this request */
57
- readonly params: unknown;
58
- /**
59
- * The resolved result. Accessing before resolution throws.
60
- * After resolution, contains the provider's return value.
61
- */
62
- readonly result: T;
63
- }
64
- /**
65
- * Context provided to plugins during the provide() call.
66
- *
67
- * Allows plugins to:
68
- * - Access the semantic IR
69
- * - Access type hints and inflection
70
- * - Register service handlers for on-demand requests
71
- * - Make requests to other plugins' handlers
72
- * - Emit files
73
- * - Register symbols
74
- */
75
- export interface PluginContext {
76
- /**
77
- * The semantic IR containing all entities, enums, relations, etc.
78
- */
79
- readonly ir: SemanticIR;
80
- /**
81
- * Type hint registry for user-configured type overrides.
82
- */
83
- readonly typeHints: TypeHintRegistry;
84
- /**
85
- * Inflection service for naming transformations.
86
- */
87
- readonly inflection: CoreInflection;
88
- /**
89
- * Register a service handler for a resource kind.
90
- *
91
- * Other plugins can then call ctx.request(kind, params) to invoke this handler.
92
- * This enables on-demand generation patterns where consumers drive what gets generated.
93
- *
94
- * @example
95
- * ```typescript
96
- * // In zod plugin:
97
- * ctx.registerHandler("schemas", (params, ctx) => {
98
- * if (params.variant === "params") {
99
- * return generateParamSchema(params.entity, params.method)
100
- * }
101
- * return generateEntitySchema(params.entity, params.shape)
102
- * })
103
- *
104
- * // In http-elysia plugin:
105
- * const schema = ctx.request("schemas", { entity: "User", method: "findById", variant: "params" })
106
- * ```
107
- *
108
- * @param kind - Resource kind this handler provides
109
- * @param handler - Function to handle requests
110
- */
111
- readonly registerHandler: <TParams = unknown, TResult = unknown>(kind: string, handler: ServiceHandler<TParams, TResult>) => void;
112
- /**
113
- * Request a resource from a registered handler.
114
- *
115
- * Invokes the handler registered for the given kind with the provided params.
116
- * If no handler is registered, falls back to the result cache (for static dependencies).
117
- *
118
- * @param kind - Resource kind to request
119
- * @param params - Opaque params for the handler
120
- * @returns The result from the handler
121
- * @throws If no handler is registered and no cached result exists
122
- */
123
- readonly request: <T = unknown>(kind: string, params: unknown) => T;
124
- /**
125
- * Create a FileBuilder for structured file emission.
126
- *
127
- * @param path - Output file path relative to outputDir
128
- */
129
- readonly file: (path: string) => FileBuilder;
130
- /**
131
- * Symbol registry for cross-file imports.
132
- * Also used for method symbol registration (plugin-to-plugin coordination).
133
- */
134
- readonly symbols: SymbolRegistry;
135
- }
136
- /**
137
- * A plugin handles requests for a specific resource kind.
138
- *
139
- * Core calls canProvide() to match requests to plugins, then calls
140
- * provide() to generate the resource.
141
- *
142
- * @typeParam TParams - The expected params shape (opaque to core)
143
- * @typeParam TResult - The result shape (opaque to core)
144
- */
145
- export interface Plugin<TParams = unknown, TResult = unknown> {
146
- /**
147
- * Unique plugin name for identification and error messages.
148
- */
149
- readonly name: string;
150
- /**
151
- * The resource kind this plugin handles.
152
- * Multiple plugins can handle the same kind - first match wins.
153
- */
154
- readonly kind: string;
155
- /**
156
- * If true, this plugin runs once automatically without explicit request.
157
- * The result is shared by all dependents.
158
- *
159
- * Typical singletons: introspection, semantic-ir
160
- */
161
- readonly singleton?: boolean;
162
- /**
163
- * Params to use for singleton execution.
164
- * Only meaningful when singleton is true.
165
- */
166
- readonly singletonParams?: TParams;
167
- /**
168
- * Check if this plugin can handle a request with the given params.
169
- *
170
- * Called during resolution to match requests to plugins.
171
- * First plugin that returns true wins.
172
- *
173
- * @param params - The request params (opaque to core)
174
- * @returns true if this plugin can handle the request
175
- */
176
- readonly canProvide: (params: TParams) => boolean;
177
- /**
178
- * Declare what resources this plugin needs before it can run.
179
- *
180
- * Used to build the dependency DAG. The results are passed to provide().
181
- *
182
- * @param params - The request params
183
- * @returns Array of resource requests that must be resolved first
184
- */
185
- readonly requires?: (params: TParams) => readonly ResourceRequest[];
186
- /**
187
- * Declare optional dependencies that enhance this plugin if available.
188
- *
189
- * Unlike `requires`, missing optional dependencies don't cause errors.
190
- * If a provider exists, the dependency is resolved and ordering is enforced.
191
- * If no provider exists, the dependency is silently skipped.
192
- *
193
- * Useful for plugins that have fallback behavior when an optional dependency
194
- * isn't available (e.g., http-elysia falling back to TypeBox when no schema
195
- * plugin is registered).
196
- *
197
- * @param params - The request params
198
- * @returns Array of optional resource requests
199
- */
200
- readonly optionalRequires?: (params: TParams) => readonly ResourceRequest[];
201
- /**
202
- * Generate the resource.
203
- *
204
- * Called during execution phase after all dependencies are resolved.
205
- *
206
- * @param params - The request params
207
- * @param deps - Resolved results from requires() in same order
208
- * @param ctx - Plugin context for sub-requests and emission
209
- * @returns The resource result (shape is plugin-defined)
210
- */
211
- readonly provide: (params: TParams, deps: readonly unknown[], ctx: PluginContext) => TResult;
212
- }
213
- declare const PluginNotFound_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
214
- readonly _tag: "PluginNotFound";
215
- } & Readonly<A>;
216
- /**
217
- * No plugin could handle a request.
218
- */
219
- export declare class PluginNotFound extends PluginNotFound_base<{
220
- readonly message: string;
221
- readonly kind: string;
222
- readonly params: unknown;
223
- readonly requestedBy?: string;
224
- }> {
225
- }
226
- declare const PluginCycle_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
227
- readonly _tag: "PluginCycle";
228
- } & Readonly<A>;
229
- /**
230
- * A cycle was detected in plugin dependencies.
231
- */
232
- export declare class PluginCycle extends PluginCycle_base<{
233
- readonly message: string;
234
- readonly cycle: readonly string[];
235
- }> {
236
- }
237
- declare const PluginExecutionFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
238
- readonly _tag: "PluginExecutionFailed";
239
- } & Readonly<A>;
240
- /**
241
- * A plugin failed during execution.
242
- */
243
- export declare class PluginExecutionFailed extends PluginExecutionFailed_base<{
244
- readonly message: string;
245
- readonly plugin: string;
246
- readonly kind: string;
247
- readonly params: unknown;
248
- readonly cause: unknown;
249
- }> {
250
- }
251
- declare const ResourceNotResolved_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
252
- readonly _tag: "ResourceNotResolved";
253
- } & Readonly<A>;
254
- /**
255
- * Attempted to access a deferred resource before resolution.
256
- */
257
- export declare class ResourceNotResolved extends ResourceNotResolved_base<{
258
- readonly message: string;
259
- readonly kind: string;
260
- readonly params: unknown;
261
- }> {
262
- }
263
- /**
264
- * Union of all plugin-related errors.
265
- */
266
- export type PluginError = PluginNotFound | PluginCycle | PluginExecutionFailed | ResourceNotResolved;
267
- /**
268
- * A pending request tracked by the registry.
269
- * @internal
270
- */
271
- export interface PendingRequest {
272
- readonly kind: string;
273
- readonly params: unknown;
274
- readonly requestedBy: string;
275
- readonly deferred: MutableDeferredResource;
276
- }
277
- /**
278
- * A mutable deferred resource used during resolution.
279
- * @internal
280
- */
281
- export interface MutableDeferredResource<T = unknown> {
282
- readonly kind: string;
283
- readonly params: unknown;
284
- resolved: boolean;
285
- value: T | undefined;
286
- }
287
- /**
288
- * Create a mutable deferred resource.
289
- * @internal
290
- */
291
- export declare const createDeferredResource: <T = unknown>(kind: string, params: unknown) => MutableDeferredResource<T>;
292
- /**
293
- * Create a read-only deferred resource view.
294
- * Throws if accessed before resolution.
295
- * @internal
296
- */
297
- export declare const asDeferredResource: <T>(mutable: MutableDeferredResource<T>) => DeferredResource<T>;
298
- /**
299
- * Registry for service handlers.
300
- *
301
- * Plugins register handlers during their provide() call.
302
- * Other plugins can then invoke these handlers via ctx.request().
303
- */
304
- export interface ServiceRegistry {
305
- /**
306
- * Register a handler for a resource kind.
307
- * Multiple handlers can be registered for the same kind - they're tried in order.
308
- *
309
- * @param kind - Resource kind this handler provides
310
- * @param handler - Function to handle requests
311
- * @param pluginName - Name of the plugin registering (for error messages)
312
- */
313
- readonly register: (kind: string, handler: ServiceHandler, pluginName: string) => void;
314
- /**
315
- * Invoke a handler for the given kind and params.
316
- *
317
- * @param kind - Resource kind to request
318
- * @param params - Opaque params for the handler
319
- * @param ctx - Plugin context to pass to handler
320
- * @returns The handler result, or undefined if no handler matched
321
- */
322
- readonly invoke: <T = unknown>(kind: string, params: unknown, ctx: PluginContext) => T | undefined;
323
- /**
324
- * Check if any handler is registered for a kind.
325
- */
326
- readonly hasHandler: (kind: string) => boolean;
327
- }
328
- /**
329
- * Create a service registry for handler registration and invocation.
330
- */
331
- export declare const createServiceRegistry: () => ServiceRegistry;
332
- declare const Services_base: Context.TagClass<Services, "Services", ServiceRegistry>;
333
- /**
334
- * Effect service tag for ServiceRegistry.
335
- */
336
- export declare class Services extends Services_base {
337
- }
338
- /**
339
- * Plugin registry service interface.
340
- *
341
- * Manages plugin registration and request collection during execution.
342
- */
343
- export interface PluginRegistry {
344
- /**
345
- * Register a plugin for a resource kind.
346
- *
347
- * @param plugin - The plugin to register
348
- */
349
- readonly register: (plugin: Plugin) => void;
350
- /**
351
- * Request a resource. Returns a deferred reference.
352
- *
353
- * The deferred is populated after resolution and execution phases.
354
- *
355
- * @param kind - Resource kind to request
356
- * @param params - Opaque params for the plugin
357
- * @param requestedBy - Name of the requester (for error messages)
358
- * @returns A deferred resource reference
359
- */
360
- readonly request: <T = unknown>(kind: string, params: unknown, requestedBy: string) => DeferredResource<T>;
361
- /**
362
- * Get all registered plugins.
363
- * @internal Used by resolution phase.
364
- */
365
- readonly getPlugins: () => readonly Plugin[];
366
- /**
367
- * Get all pending requests.
368
- * @internal Used by resolution phase.
369
- */
370
- readonly getPendingRequests: () => readonly PendingRequest[];
371
- /**
372
- * Get singleton plugins.
373
- * @internal Used by resolution phase to create implicit requests.
374
- */
375
- readonly getSingletons: () => readonly Plugin[];
376
- }
377
- declare const Plugins_base: Context.TagClass<Plugins, "Plugins", PluginRegistry>;
378
- /**
379
- * Effect service tag for PluginRegistry.
380
- */
381
- export declare class Plugins extends Plugins_base {
382
- }
383
- /**
384
- * Schema for ResourceRequest (for artifact serialization if needed).
385
- */
386
- export declare const ResourceRequestSchema: S.Struct<{
387
- kind: typeof S.String;
388
- params: typeof S.Unknown;
389
- }>;
390
- /**
391
- * Define a plugin with type inference.
392
- *
393
- * @example
394
- * ```typescript
395
- * const zodSchemas = definePlugin({
396
- * name: "zod-schemas",
397
- * kind: "validation-schema",
398
- * canProvide: (p) => !p.format || p.format === "zod",
399
- * requires: () => [{ kind: "semantic-ir", params: {} }],
400
- * provide: (params, [ir], ctx) => {
401
- * // Generate schema, return symbol ref
402
- * },
403
- * })
404
- * ```
405
- */
406
- export declare function definePlugin<TParams = unknown, TResult = unknown>(plugin: Plugin<TParams, TResult>): Plugin<TParams, TResult>;
407
- /**
408
- * Create a plugin registry for collecting plugins and requests.
409
- *
410
- * Used during generation to:
411
- * 1. Collect plugin registrations
412
- * 2. Collect requests during plugin execution
413
- * 3. Provide data to resolution phase
414
- */
415
- export declare const createPluginRegistry: () => PluginRegistry;
416
- /**
417
- * Layer providing a fresh plugin registry.
418
- */
419
- export declare const PluginsLive: Layer.Layer<Plugins, never, never>;
420
- export {};
421
- //# sourceMappingURL=plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/services/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,OAAO,EAAQ,KAAK,EAA6C,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AACrG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAMrD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CACzB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,CACjE,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,aAAa,KACf,OAAO,CAAA;AAEZ;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CACnB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B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,qBAAqB,QAAO,eA0CxC,CAAA;;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,aAAoD;CAAG;AAMrF;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAE3C;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAE1G;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,SAAS,MAAM,EAAE,CAAA;IAE5C;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,SAAS,cAAc,EAAE,CAAA;IAE5D;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,SAAS,MAAM,EAAE,CAAA;CAChD;;AAED;;GAEG;AACH,qBAAa,OAAQ,SAAQ,YAAiD;CAAG;AAMjF;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;EAGhC,CAAA;AAMF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC/D,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1B;AAMD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAAO,cA2CvC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,oCAA4C,CAAA"}
@@ -1,197 +0,0 @@
1
- /**
2
- * Plugin System
3
- *
4
- * A generic request/plugin coordination system. Core routes requests to plugins
5
- * without understanding what resources represent (schemas, queries, routes, etc.).
6
- *
7
- * Key concepts:
8
- * - Plugin: Handles requests for a resource kind
9
- * - Request: A need for a resource with specific params
10
- * - DeferredResource: A placeholder resolved after plugin execution
11
- *
12
- * Execution phases:
13
- * 1. Registration - Plugins registered, singletons identified
14
- * 2. Collection - Requests collected via ctx.request()
15
- * 3. Resolution - Match requests to plugins, build DAG
16
- * 4. Execution - Run plugins in topological order
17
- * 5. Finalization - Emit files, resolve imports
18
- */
19
- import { Context, Data, Layer, MutableHashMap, MutableList, Option, pipe, Schema as S } from "effect";
20
- // ============================================================================
21
- // Plugin Errors - Domain Agnostic
22
- // ============================================================================
23
- /**
24
- * No plugin could handle a request.
25
- */
26
- export class PluginNotFound extends Data.TaggedError("PluginNotFound") {
27
- }
28
- /**
29
- * A cycle was detected in plugin dependencies.
30
- */
31
- export class PluginCycle extends Data.TaggedError("PluginCycle") {
32
- }
33
- /**
34
- * A plugin failed during execution.
35
- */
36
- export class PluginExecutionFailed extends Data.TaggedError("PluginExecutionFailed") {
37
- }
38
- /**
39
- * Attempted to access a deferred resource before resolution.
40
- */
41
- export class ResourceNotResolved extends Data.TaggedError("ResourceNotResolved") {
42
- }
43
- /**
44
- * Create a mutable deferred resource.
45
- * @internal
46
- */
47
- export const createDeferredResource = (kind, params) => ({
48
- kind,
49
- params,
50
- resolved: false,
51
- value: undefined,
52
- });
53
- /**
54
- * Create a read-only deferred resource view.
55
- * Throws if accessed before resolution.
56
- * @internal
57
- */
58
- export const asDeferredResource = (mutable) => ({
59
- kind: mutable.kind,
60
- params: mutable.params,
61
- get result() {
62
- if (!mutable.resolved) {
63
- throw new ResourceNotResolved({
64
- message: `Resource "${mutable.kind}" has not been resolved yet`,
65
- kind: mutable.kind,
66
- params: mutable.params,
67
- });
68
- }
69
- return mutable.value;
70
- },
71
- });
72
- /**
73
- * Create a service registry for handler registration and invocation.
74
- */
75
- export const createServiceRegistry = () => {
76
- const handlers = MutableHashMap.empty();
77
- return {
78
- register: (kind, handler, pluginName) => {
79
- pipe(MutableHashMap.get(handlers, kind), Option.match({
80
- onNone: () => {
81
- MutableHashMap.set(handlers, kind, MutableList.make({ handler, plugin: pluginName }));
82
- },
83
- onSome: (list) => {
84
- MutableList.append(list, { handler, plugin: pluginName });
85
- },
86
- }));
87
- },
88
- invoke: (kind, params, ctx) => {
89
- return pipe(MutableHashMap.get(handlers, kind), Option.flatMap((list) => {
90
- // Try each handler until one returns a result
91
- for (const { handler } of list) {
92
- try {
93
- const result = handler(params, ctx);
94
- if (result !== undefined) {
95
- return Option.some(result);
96
- }
97
- }
98
- catch {
99
- // Handler threw - try next one
100
- continue;
101
- }
102
- }
103
- return Option.none();
104
- }), Option.getOrUndefined);
105
- },
106
- hasHandler: (kind) => MutableHashMap.has(handlers, kind),
107
- };
108
- };
109
- /**
110
- * Effect service tag for ServiceRegistry.
111
- */
112
- export class Services extends Context.Tag("Services")() {
113
- }
114
- /**
115
- * Effect service tag for PluginRegistry.
116
- */
117
- export class Plugins extends Context.Tag("Plugins")() {
118
- }
119
- // ============================================================================
120
- // Schema for Serialization (if needed)
121
- // ============================================================================
122
- /**
123
- * Schema for ResourceRequest (for artifact serialization if needed).
124
- */
125
- export const ResourceRequestSchema = S.Struct({
126
- kind: S.String,
127
- params: S.Unknown,
128
- });
129
- // ============================================================================
130
- // Helper: definePlugin
131
- // ============================================================================
132
- /**
133
- * Define a plugin with type inference.
134
- *
135
- * @example
136
- * ```typescript
137
- * const zodSchemas = definePlugin({
138
- * name: "zod-schemas",
139
- * kind: "validation-schema",
140
- * canProvide: (p) => !p.format || p.format === "zod",
141
- * requires: () => [{ kind: "semantic-ir", params: {} }],
142
- * provide: (params, [ir], ctx) => {
143
- * // Generate schema, return symbol ref
144
- * },
145
- * })
146
- * ```
147
- */
148
- export function definePlugin(plugin) {
149
- return plugin;
150
- }
151
- // ============================================================================
152
- // Plugin Registry Implementation
153
- // ============================================================================
154
- /**
155
- * Create a plugin registry for collecting plugins and requests.
156
- *
157
- * Used during generation to:
158
- * 1. Collect plugin registrations
159
- * 2. Collect requests during plugin execution
160
- * 3. Provide data to resolution phase
161
- */
162
- export const createPluginRegistry = () => {
163
- const pluginsByKind = MutableHashMap.empty();
164
- const allPlugins = MutableList.empty();
165
- const pendingRequests = MutableList.empty();
166
- return {
167
- register: (plugin) => {
168
- MutableList.append(allPlugins, plugin);
169
- pipe(MutableHashMap.get(pluginsByKind, plugin.kind), Option.match({
170
- onNone: () => {
171
- MutableHashMap.set(pluginsByKind, plugin.kind, MutableList.make(plugin));
172
- },
173
- onSome: (list) => {
174
- MutableList.append(list, plugin);
175
- },
176
- }));
177
- },
178
- request: (kind, params, requestedBy) => {
179
- const mutable = createDeferredResource(kind, params);
180
- MutableList.append(pendingRequests, {
181
- kind,
182
- params,
183
- requestedBy,
184
- deferred: mutable,
185
- });
186
- return asDeferredResource(mutable);
187
- },
188
- getPlugins: () => Array.from(allPlugins),
189
- getPendingRequests: () => Array.from(pendingRequests),
190
- getSingletons: () => pipe(Array.from(allPlugins), (plugins) => plugins.filter((p) => p.singleton === true)),
191
- };
192
- };
193
- /**
194
- * Layer providing a fresh plugin registry.
195
- */
196
- export const PluginsLive = Layer.sync(Plugins, createPluginRegistry);
197
- //# sourceMappingURL=plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/services/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AA+NrG,+EAA+E;AAC/E,kCAAkC;AAClC,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAKnE;CAAG;AAEL;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAG7D;CAAG;AAEL;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,IAAI,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OAAO,GAAG,sBAAsB,CAAI,IAAI,EAAE,MAAM,CAAC,CAAA;YACvD,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE;gBAClC,IAAI;gBACJ,MAAM;gBACN,WAAW;gBACX,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAA;YACF,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAA;QACpC,CAAC;QAED,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;QAExC,kBAAkB,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC;QAErD,aAAa,EAAE,GAAG,EAAE,CAClB,IAAI,CACF,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,EACtB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,CACzD;KACJ,CAAA;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA"}
@@ -1,38 +0,0 @@
1
- /**
2
- * Resolution Phase
3
- *
4
- * Matches requests to providers, expands dependencies, builds DAG,
5
- * detects cycles, and produces an execution plan.
6
- */
7
- import { Effect } from "effect";
8
- import { type PluginRegistry, type Plugin, type ResourceRequest, PluginCycle, PluginNotFound } from "./plugin.js";
9
- /**
10
- * A resolved request: a request matched to a provider.
11
- */
12
- export interface ResolvedRequest {
13
- readonly kind: string;
14
- readonly params: unknown;
15
- readonly provider: Plugin;
16
- /** Required dependencies (from provider.requires) - always resolved */
17
- readonly dependencies: readonly ResourceRequest[];
18
- /** Optional dependencies that were successfully resolved (from provider.optionalRequires) */
19
- readonly optionalDependencies: readonly ResourceRequest[];
20
- }
21
- /**
22
- * Execution plan: topologically sorted list of resolved requests.
23
- */
24
- export interface ExecutionPlan {
25
- readonly steps: readonly ResolvedRequest[];
26
- }
27
- /**
28
- * Resolve all requests and produce an execution plan.
29
- *
30
- * Steps:
31
- * 1. Collect all requests (pending + singletons + transitive dependencies)
32
- * 2. Match each request to a provider
33
- * 3. Build dependency DAG
34
- * 4. Detect cycles
35
- * 5. Topologically sort
36
- */
37
- export declare const resolve: (registry: PluginRegistry) => Effect.Effect<ExecutionPlan, PluginNotFound | PluginCycle>;
38
- //# sourceMappingURL=resolution.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../../src/services/resolution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAsB,MAAM,EAAyB,MAAM,QAAQ,CAAA;AAC1E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,WAAW,EACX,cAAc,EACf,MAAM,aAAa,CAAA;AAMpB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,SAAS,eAAe,EAAE,CAAA;IACjD,6FAA6F;IAC7F,QAAQ,CAAC,oBAAoB,EAAE,SAAS,eAAe,EAAE,CAAA;CAC1D;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAA;CAC3C;AA2UD;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,cAAc,KACvB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,GAAG,WAAW,CAUzD,CAAA"}