@ontrails/core 1.0.0-beta.14 → 1.0.0-beta.15

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 (280) hide show
  1. package/.turbo/turbo-lint.log +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/README.md +17 -13
  4. package/dist/branded.d.ts +1 -1
  5. package/dist/branded.d.ts.map +1 -1
  6. package/dist/branded.js +1 -1
  7. package/dist/branded.js.map +1 -1
  8. package/dist/context.d.ts +13 -1
  9. package/dist/context.d.ts.map +1 -1
  10. package/dist/context.js +19 -3
  11. package/dist/context.js.map +1 -1
  12. package/dist/contour.d.ts +81 -0
  13. package/dist/contour.d.ts.map +1 -0
  14. package/dist/contour.js +176 -0
  15. package/dist/contour.js.map +1 -0
  16. package/dist/cross-schema.d.ts +18 -0
  17. package/dist/cross-schema.d.ts.map +1 -0
  18. package/dist/cross-schema.js +29 -0
  19. package/dist/cross-schema.js.map +1 -0
  20. package/dist/draft.d.ts +5 -5
  21. package/dist/draft.d.ts.map +1 -1
  22. package/dist/draft.js +28 -27
  23. package/dist/draft.js.map +1 -1
  24. package/dist/errors.d.ts +62 -4
  25. package/dist/errors.d.ts.map +1 -1
  26. package/dist/errors.js +44 -1
  27. package/dist/errors.js.map +1 -1
  28. package/dist/execute.d.ts +26 -9
  29. package/dist/execute.d.ts.map +1 -1
  30. package/dist/execute.js +441 -20
  31. package/dist/execute.js.map +1 -1
  32. package/dist/fire.d.ts +43 -0
  33. package/dist/fire.d.ts.map +1 -0
  34. package/dist/fire.js +185 -0
  35. package/dist/fire.js.map +1 -0
  36. package/dist/index.d.ts +31 -20
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +23 -13
  39. package/dist/index.js.map +1 -1
  40. package/dist/internal/cross-batch.d.ts +44 -0
  41. package/dist/internal/cross-batch.d.ts.map +1 -0
  42. package/dist/internal/cross-batch.js +58 -0
  43. package/dist/internal/cross-batch.js.map +1 -0
  44. package/dist/internal/fork-ctx.d.ts +41 -0
  45. package/dist/internal/fork-ctx.d.ts.map +1 -0
  46. package/dist/internal/fork-ctx.js +47 -0
  47. package/dist/internal/fork-ctx.js.map +1 -0
  48. package/dist/internal/signal-ref.d.ts +15 -0
  49. package/dist/internal/signal-ref.d.ts.map +1 -0
  50. package/dist/internal/signal-ref.js +41 -0
  51. package/dist/internal/signal-ref.js.map +1 -0
  52. package/dist/internal/topo-saves.d.ts +8 -2
  53. package/dist/internal/topo-saves.d.ts.map +1 -1
  54. package/dist/internal/topo-saves.js +162 -23
  55. package/dist/internal/topo-saves.js.map +1 -1
  56. package/dist/internal/topo-snapshots.d.ts +57 -0
  57. package/dist/internal/topo-snapshots.d.ts.map +1 -0
  58. package/dist/internal/topo-snapshots.js +372 -0
  59. package/dist/internal/topo-snapshots.js.map +1 -0
  60. package/dist/internal/topo-store-read.d.ts +23 -20
  61. package/dist/internal/topo-store-read.d.ts.map +1 -1
  62. package/dist/internal/topo-store-read.js +82 -83
  63. package/dist/internal/topo-store-read.js.map +1 -1
  64. package/dist/internal/topo-store.d.ts +19 -5
  65. package/dist/internal/topo-store.d.ts.map +1 -1
  66. package/dist/internal/topo-store.js +174 -124
  67. package/dist/internal/topo-store.js.map +1 -1
  68. package/dist/internal/tracing.d.ts +98 -0
  69. package/dist/internal/tracing.d.ts.map +1 -0
  70. package/dist/internal/tracing.js +102 -0
  71. package/dist/internal/tracing.js.map +1 -0
  72. package/dist/internal/trails-db.d.ts +2 -2
  73. package/dist/internal/trails-db.d.ts.map +1 -1
  74. package/dist/internal/trails-db.js +8 -8
  75. package/dist/internal/trails-db.js.map +1 -1
  76. package/dist/internal/zod-wrappers.d.ts +40 -0
  77. package/dist/internal/zod-wrappers.d.ts.map +1 -0
  78. package/dist/internal/zod-wrappers.js +59 -0
  79. package/dist/internal/zod-wrappers.js.map +1 -0
  80. package/dist/layer.d.ts +22 -5
  81. package/dist/layer.d.ts.map +1 -1
  82. package/dist/layer.js +20 -3
  83. package/dist/layer.js.map +1 -1
  84. package/dist/path-security.d.ts +1 -1
  85. package/dist/path-security.d.ts.map +1 -1
  86. package/dist/path-security.js +1 -1
  87. package/dist/path-security.js.map +1 -1
  88. package/dist/resilience.d.ts +1 -1
  89. package/dist/resilience.d.ts.map +1 -1
  90. package/dist/resilience.js +3 -3
  91. package/dist/resilience.js.map +1 -1
  92. package/dist/resource-config.d.ts +22 -0
  93. package/dist/resource-config.d.ts.map +1 -0
  94. package/dist/resource-config.js +210 -0
  95. package/dist/resource-config.js.map +1 -0
  96. package/dist/resource.d.ts +74 -0
  97. package/dist/resource.d.ts.map +1 -0
  98. package/dist/resource.js +61 -0
  99. package/dist/resource.js.map +1 -0
  100. package/dist/run.d.ts +4 -3
  101. package/dist/run.d.ts.map +1 -1
  102. package/dist/run.js +5 -4
  103. package/dist/run.js.map +1 -1
  104. package/dist/serialization.d.ts.map +1 -1
  105. package/dist/serialization.js +2 -1
  106. package/dist/serialization.js.map +1 -1
  107. package/dist/store/accessor-protocol.d.ts +51 -0
  108. package/dist/store/accessor-protocol.d.ts.map +1 -0
  109. package/dist/store/accessor-protocol.js +2 -0
  110. package/dist/store/accessor-protocol.js.map +1 -0
  111. package/dist/store/index.d.ts +2 -0
  112. package/dist/store/index.d.ts.map +1 -0
  113. package/dist/store/index.js +2 -0
  114. package/dist/store/index.js.map +1 -0
  115. package/dist/surface-filter.d.ts +13 -0
  116. package/dist/surface-filter.d.ts.map +1 -0
  117. package/dist/surface-filter.js +76 -0
  118. package/dist/surface-filter.js.map +1 -0
  119. package/dist/topo-store.d.ts +36 -22
  120. package/dist/topo-store.d.ts.map +1 -1
  121. package/dist/topo-store.js +215 -71
  122. package/dist/topo-store.js.map +1 -1
  123. package/dist/topo.d.ts +23 -9
  124. package/dist/topo.d.ts.map +1 -1
  125. package/dist/topo.js +175 -46
  126. package/dist/topo.js.map +1 -1
  127. package/dist/trail.d.ts +86 -19
  128. package/dist/trail.d.ts.map +1 -1
  129. package/dist/trail.js +59 -4
  130. package/dist/trail.js.map +1 -1
  131. package/dist/trails/derive-trail.d.ts +66 -0
  132. package/dist/trails/derive-trail.d.ts.map +1 -0
  133. package/dist/trails/derive-trail.js +378 -0
  134. package/dist/trails/derive-trail.js.map +1 -0
  135. package/dist/trails/index.d.ts +5 -0
  136. package/dist/trails/index.d.ts.map +1 -0
  137. package/dist/trails/index.js +3 -0
  138. package/dist/trails/index.js.map +1 -0
  139. package/dist/trails/ingest.d.ts +24 -0
  140. package/dist/trails/ingest.d.ts.map +1 -0
  141. package/dist/trails/ingest.js +63 -0
  142. package/dist/trails/ingest.js.map +1 -0
  143. package/dist/transport-error-map.d.ts +106 -0
  144. package/dist/transport-error-map.d.ts.map +1 -0
  145. package/dist/transport-error-map.js +24 -0
  146. package/dist/transport-error-map.js.map +1 -0
  147. package/dist/type-checks.test-d.d.ts +71 -0
  148. package/dist/type-checks.test-d.d.ts.map +1 -0
  149. package/dist/type-checks.test-d.js +12 -0
  150. package/dist/type-checks.test-d.js.map +1 -0
  151. package/dist/type-utils.d.ts +11 -2
  152. package/dist/type-utils.d.ts.map +1 -1
  153. package/dist/type-utils.js.map +1 -1
  154. package/dist/types.d.ts +113 -7
  155. package/dist/types.d.ts.map +1 -1
  156. package/dist/types.js.map +1 -1
  157. package/dist/validate-established-topo.js +2 -2
  158. package/dist/validate-established-topo.js.map +1 -1
  159. package/dist/validate-topo.d.ts.map +1 -1
  160. package/dist/validate-topo.js +24 -7
  161. package/dist/validate-topo.js.map +1 -1
  162. package/dist/workspace.d.ts +1 -1
  163. package/dist/workspace.d.ts.map +1 -1
  164. package/dist/workspace.js +1 -1
  165. package/dist/workspace.js.map +1 -1
  166. package/package.json +8 -2
  167. package/src/__tests__/branded.test.ts +5 -5
  168. package/src/__tests__/context.test.ts +3 -3
  169. package/src/__tests__/contour.test.ts +263 -0
  170. package/src/__tests__/derive-trail.test.ts +668 -0
  171. package/src/__tests__/errors.test.ts +118 -0
  172. package/src/__tests__/execute.test.ts +1179 -141
  173. package/src/__tests__/fire.test.ts +1056 -0
  174. package/src/__tests__/fork-ctx.test.ts +83 -0
  175. package/src/__tests__/ingest.test.ts +191 -0
  176. package/src/__tests__/{gate.test.ts → layer.test.ts} +21 -21
  177. package/src/__tests__/path-security.test.ts +7 -7
  178. package/src/__tests__/resilience.test.ts +8 -8
  179. package/src/__tests__/resource.test.ts +204 -0
  180. package/src/__tests__/run.test.ts +13 -13
  181. package/src/__tests__/service-config.test.ts +28 -32
  182. package/src/__tests__/surface-filter.test.ts +196 -0
  183. package/src/__tests__/topo-store-read.test.ts +41 -36
  184. package/src/__tests__/topo-store.test.ts +493 -93
  185. package/src/__tests__/topo.test.ts +350 -54
  186. package/src/__tests__/trail.test.ts +189 -24
  187. package/src/__tests__/trails-db.test.ts +32 -25
  188. package/src/__tests__/transport-error-map.test.ts +82 -0
  189. package/src/__tests__/type-utils.test.ts +29 -1
  190. package/src/__tests__/validate-topo.test.ts +147 -25
  191. package/src/__tests__/workspace.test.ts +6 -6
  192. package/src/__tests__/zod-wrappers.test.ts +62 -0
  193. package/src/branded.ts +1 -1
  194. package/src/context.ts +24 -4
  195. package/src/contour.ts +344 -0
  196. package/src/cross-schema.ts +36 -0
  197. package/src/draft.ts +56 -52
  198. package/src/errors.ts +62 -18
  199. package/src/execute.ts +840 -29
  200. package/src/fire.ts +295 -0
  201. package/src/index.ts +116 -29
  202. package/src/internal/cross-batch.ts +77 -0
  203. package/src/internal/fork-ctx.ts +69 -0
  204. package/src/internal/signal-ref.ts +87 -0
  205. package/src/internal/topo-snapshots.ts +517 -0
  206. package/src/internal/topo-store-read.ts +140 -132
  207. package/src/internal/topo-store.ts +291 -186
  208. package/src/internal/tracing.ts +187 -0
  209. package/src/internal/trails-db.ts +9 -11
  210. package/src/internal/zod-wrappers.ts +78 -0
  211. package/src/layer.ts +50 -0
  212. package/src/path-security.ts +1 -1
  213. package/src/resilience.ts +3 -3
  214. package/src/{provision-config.ts → resource-config.ts} +109 -123
  215. package/src/resource.ts +155 -0
  216. package/src/run.ts +5 -4
  217. package/src/serialization.ts +2 -0
  218. package/src/store/accessor-protocol.ts +56 -0
  219. package/src/store/index.ts +4 -0
  220. package/src/surface-filter.ts +182 -0
  221. package/src/topo-store.ts +313 -104
  222. package/src/topo.ts +328 -57
  223. package/src/trail.ts +199 -31
  224. package/src/trails/derive-trail.ts +842 -0
  225. package/src/trails/index.ts +9 -0
  226. package/src/trails/ingest.ts +146 -0
  227. package/src/transport-error-map.ts +56 -0
  228. package/src/type-checks.test-d.ts +106 -0
  229. package/src/type-utils.ts +17 -2
  230. package/src/types.ts +148 -11
  231. package/src/validate-established-topo.ts +2 -2
  232. package/src/validate-topo.ts +32 -8
  233. package/src/workspace.ts +1 -1
  234. package/tsconfig.tests.json +10 -0
  235. package/tsconfig.tsbuildinfo +1 -1
  236. package/dist/adapters.d.ts +0 -39
  237. package/dist/adapters.d.ts.map +0 -1
  238. package/dist/adapters.js +0 -2
  239. package/dist/adapters.js.map +0 -1
  240. package/dist/dispatch.d.ts +0 -27
  241. package/dist/dispatch.d.ts.map +0 -1
  242. package/dist/dispatch.js +0 -34
  243. package/dist/dispatch.js.map +0 -1
  244. package/dist/event.d.ts +0 -8
  245. package/dist/event.d.ts.map +0 -1
  246. package/dist/event.js +0 -7
  247. package/dist/event.js.map +0 -1
  248. package/dist/gate.d.ts +0 -17
  249. package/dist/gate.d.ts.map +0 -1
  250. package/dist/gate.js +0 -21
  251. package/dist/gate.js.map +0 -1
  252. package/dist/health.d.ts +0 -18
  253. package/dist/health.d.ts.map +0 -1
  254. package/dist/health.js +0 -5
  255. package/dist/health.js.map +0 -1
  256. package/dist/job.d.ts +0 -24
  257. package/dist/job.d.ts.map +0 -1
  258. package/dist/job.js +0 -17
  259. package/dist/job.js.map +0 -1
  260. package/dist/provision-config.d.ts +0 -22
  261. package/dist/provision-config.d.ts.map +0 -1
  262. package/dist/provision-config.js +0 -210
  263. package/dist/provision-config.js.map +0 -1
  264. package/dist/provision.d.ts +0 -71
  265. package/dist/provision.d.ts.map +0 -1
  266. package/dist/provision.js +0 -56
  267. package/dist/provision.js.map +0 -1
  268. package/dist/service-config.d.ts +0 -22
  269. package/dist/service-config.d.ts.map +0 -1
  270. package/dist/service-config.js +0 -210
  271. package/dist/service-config.js.map +0 -1
  272. package/dist/service.d.ts +0 -71
  273. package/dist/service.d.ts.map +0 -1
  274. package/dist/service.js +0 -56
  275. package/dist/service.js.map +0 -1
  276. package/src/__tests__/service.test.ts +0 -197
  277. package/src/event.ts +0 -15
  278. package/src/gate.ts +0 -44
  279. package/src/internal/topo-saves.ts +0 -429
  280. package/src/provision.ts +0 -148
@@ -1,3 +1,3 @@
1
1
  $ oxlint ./src
2
2
  Found 0 warnings and 0 errors.
3
- Finished in 60ms on 76 files with 93 rules using 24 threads.
3
+ Finished in 66ms on 99 files with 93 rules using 24 threads.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @ontrails/core
2
2
 
3
+ ## 1.0.0-beta.15
4
+
5
+ ### Minor Changes
6
+
7
+ - 4ad6b25: Lexicon rename cleanup (ADR-0023). Breaking for `@ontrails/core`, `@ontrails/cli`, and `@ontrails/tracing` at the boundary; internal-only churn for `@ontrails/warden`.
8
+
9
+ - **core**: the topo store schema renames `topo_provisions` / `topo_trail_provisions` → `topo_resources` / `topo_trail_resources` and `provision_count` → `resource_count`. Schema version bumped v4→v5. Stores still carrying the legacy schema are detected on open, dropped, and recreated from the new DDL — previous topo saves are cleared. Stored-data helpers `listTopoStoreProvisions` / `getTopoStoreProvision` / `readProvisionUsage` / `mapProvisionRow` renamed to their `resource` counterparts. TS row types `TopoTrailProvisionRow` / `TopoProvisionRow` renamed to `TopoTrailResourceRow` / `TopoResourceRow`.
10
+ - **cli**: CLI output mode env vars are now derived from the topo name per ADR-0023. Legacy globals `TRAILS_JSON` / `TRAILS_JSONL` are no longer honored — a topo named `stash` reads `STASH_JSON` / `STASH_JSONL`. `ActionResultContext` gains a `topoName: string` field; `resolveOutputMode(flags, topoName)` takes a topo name argument.
11
+ - **tracing**: legacy `.trails/dev/tracker.db` migration path removed. Any user still running a pre-rename beta build with a `tracker.db` should delete it or migrate before upgrading.
12
+ - **warden**: internal-only rename of `provisionDeclarations` / `provisionExists` rules and their trails to `resourceDeclarations` / `resourceExists`. No behavior change.
13
+
3
14
  ## 1.0.0-beta.14
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -18,7 +18,7 @@ const greet = trail('greet', {
18
18
  blaze: (input) => Result.ok({ message: `Hello, ${input.name}!` }),
19
19
  });
20
20
 
21
- const app = topo('myapp', { greet });
21
+ const graph = topo('myapp', { greet });
22
22
  ```
23
23
 
24
24
  Trails compose other trails through `crosses` and `ctx.cross()`:
@@ -43,23 +43,24 @@ const onboard = trail('entity.onboard', {
43
43
  | --- | --- |
44
44
  | `trail(id, spec)` | Define a unit of work with typed input and `Result` output; use `crosses` for composition |
45
45
  | `signal(id, spec)` | Define a server-originated notification with a typed data schema |
46
- | `provision(id, spec)` | Define an infrastructure dependency with `create`, `dispose`, and optional `mock` |
46
+ | `resource(id, spec)` | Define an infrastructure dependency with `create`, `dispose`, and optional `mock` |
47
47
  | `topo(name, ...modules)` | Collect trail modules into a queryable topology |
48
+ | `deriveTrail(contour, operation, spec)` | Derive CRUD-shaped trail contracts from a contour on the `@ontrails/core/trails` subpath |
48
49
  | `validateTopo(topo)` | Structural validation: cross targets exist, no cycles, examples parse, output schemas present |
49
50
 
50
51
  ### Execution
51
52
 
52
53
  | Export | What it does |
53
54
  | --- | --- |
54
- | `executeTrail(trail, rawInput, options?)` | Centralized execution pipeline: validates input, builds context, composes gates, runs the implementation. Never throws -- exceptions become `Result.err(InternalError)`. |
55
+ | `executeTrail(trail, rawInput, options?)` | Centralized execution pipeline: validates input, builds context, composes layers, runs the implementation. Never throws -- exceptions become `Result.err(InternalError)`. |
55
56
  | `run(topo, id, input, options?)` | Headless trail execution by ID. Looks up the trail in the topo, then delegates to `executeTrail`. Returns `Result.err(NotFoundError)` if the ID is not registered. |
56
57
 
57
58
  ```typescript
58
- // executeTrail — trailheads use this directly
59
+ // executeTrail — surfaces use this directly
59
60
  const result = await executeTrail(greet, { name: 'Alice' });
60
61
 
61
- // run — no-trailhead execution by trail ID
62
- const result = await run(app, 'greet', { name: 'Alice' });
62
+ // run — headless execution by trail ID
63
+ const result = await run(graph, 'greet', { name: 'Alice' });
63
64
  if (result.isOk()) console.log(result.value);
64
65
  ```
65
66
 
@@ -89,7 +90,7 @@ Beyond the `trail(id, spec)` builder, `Topo` exposes these accessors:
89
90
 
90
91
  | Type | What it describes |
91
92
  | --- | --- |
92
- | `ExecuteTrailOptions` | Options for `executeTrail`: `ctx`, `abortSignal`, `gates`, `createContext` |
93
+ | `ExecuteTrailOptions` | Options for `executeTrail`: `ctx`, `abortSignal`, `layers`, `createContext` |
93
94
  | `RunOptions` | Same shape as `ExecuteTrailOptions`; forwarded by `run` |
94
95
 
95
96
  ### Result
@@ -112,34 +113,37 @@ result.unwrapOr(fallback); // Value or fallback
112
113
 
113
114
  ### Error taxonomy
114
115
 
115
- 13 error classes across 10 categories. Each maps deterministically to exit codes, HTTP status, and JSON-RPC codes on every trailhead.
116
+ 15 error classes across 10 categories. Each maps deterministically to exit codes, HTTP status, and JSON-RPC codes on every surface.
116
117
 
117
118
  | Category | Classes | HTTP | Retryable |
118
119
  | --- | --- | --- | --- |
119
- | `validation` | `ValidationError`, `AmbiguousError`, `AssertionError` | 400 | No |
120
+ | `validation` | `ValidationError`, `AmbiguousError` | 400 | No |
120
121
  | `not_found` | `NotFoundError` | 404 | No |
121
122
  | `conflict` | `AlreadyExistsError`, `ConflictError` | 409 | No |
122
123
  | `permission` | `PermissionError` | 403 | No |
123
124
  | `timeout` | `TimeoutError` | 504 | Yes |
124
125
  | `rate_limit` | `RateLimitError` | 429 | Yes |
125
126
  | `network` | `NetworkError` | 502 | Yes |
126
- | `internal` | `InternalError` | 500 | No |
127
+ | `internal` | `InternalError`, `DerivationError`, `AssertionError` | 500 | No |
127
128
  | `auth` | `AuthError` | 401 | No |
128
129
  | `cancelled` | `CancelledError` | 499 | No |
129
130
 
130
- The developer returns `Result.err(new NotFoundError(...))`. The framework maps it to the right code on every trailhead.
131
+ `RetryExhaustedError` wraps another `TrailsError`, inherits the wrapped error's category for surface mappings, and always reports `retryable: false`.
132
+
133
+ The developer returns `Result.err(new NotFoundError(...))`. The framework maps it to the right code on every surface.
131
134
 
132
135
  ### Other exports
133
136
 
134
137
  - **Schema derivation** -- `deriveFields(schema)` extracts faithfully
135
138
  representable field metadata from Zod for prompts and forms
136
139
  - **Validation** -- `validateInput`, `formatZodIssues`, `zodToJsonSchema`
137
- - **Resilience** -- `retry`, `withTimeout`, `shouldRetry`, `getBackoffDelay`
140
+ - **Resilience** -- `retry`, `withTimeout`, `shouldRetry`, `deriveBackoffDelay`
138
141
  - **Serialization** -- `serializeError`, `deserializeError`
139
142
  - **Branded types** -- `uuid`, `email`, `nonEmptyString`, `positiveInt`
140
- - **Gates** -- cross-cutting gates via `composeGates`
143
+ - **Layers** -- cross-cutting layers via `composeLayers`
141
144
  - **Guards and collections** -- `isDefined`, `chunk`, `dedupe`, `groupBy`, `sortBy`
142
145
  - **Patterns** (`@ontrails/core/patterns`) -- reusable Zod schemas for pagination, bulk ops, timestamps, sorting
146
+ - **Trail factories** (`@ontrails/core/trails`) -- derive CRUD-shaped trail contracts from contours without re-authoring IDs, schemas, examples, or intents
143
147
  - **Redaction** (`@ontrails/core/redaction`) -- strip sensitive data before logging
144
148
 
145
149
  See the [API Reference](../../docs/api-reference.md) for the full list.
package/dist/branded.d.ts CHANGED
@@ -32,5 +32,5 @@ export declare const shortId: (length?: number) => string;
32
32
  * Produce a deterministic hex hash from an input string.
33
33
  * Uses a simple FNV-1a 32-bit hash — good enough for non-cryptographic IDs.
34
34
  */
35
- export declare const hashId: (input: string) => string;
35
+ export declare const deriveIdHash: (input: string) => string;
36
36
  //# sourceMappingURL=branded.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":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,KAAK,EAAE,eAAe,CASlE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,KACZ,MAAM,CAAC,cAAc,EAAE,eAAe,CAKxC,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,OAAO,MAAM,KACZ,MAAM,CAAC,WAAW,EAAE,eAAe,CASrC,CAAC;AASF;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,eAAU,KAAG,MAWpC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,MAY5C,CAAC"}
package/dist/branded.js CHANGED
@@ -73,7 +73,7 @@ export const shortId = (length = 8) => {
73
73
  * Produce a deterministic hex hash from an input string.
74
74
  * Uses a simple FNV-1a 32-bit hash — good enough for non-cryptographic IDs.
75
75
  */
76
- export const hashId = (input) => {
76
+ export const deriveIdHash = (input) => {
77
77
  // FNV offset basis
78
78
  let hash = 2_166_136_261;
79
79
  for (let i = 0; i < input.length; i += 1) {
@@ -1 +1 @@
1
- {"version":3,"file":"branded.js","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,aAAa,CAAC;AAS1C,kFAAkF;AAClF,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAS,EACT,KAAQ,EACS,EAAE,CAAC,KAAwB,CAAC;AAE/C,wDAAwD;AACxD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,KAAyB,EAAK,EAAE,CAAC,KAAU,CAAC;AAWvE,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,MAAM,OAAO,GACX,4EAA4E,CAAC;AAE/E,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAE9C,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAE9E,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC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AAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,EAAE,IAAI,YAAY,CAAC,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE;IACpD,mBAAmB;IACnB,IAAI,IAAI,GAAG,aAAa,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,kEAAkE;QAClE,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAClC,YAAY;QACZ,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACxC,CAAC;IACD,sCAAsC;IACtC,6IAA6I;IAC7I,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC,CAAC"}
package/dist/context.d.ts CHANGED
@@ -1,4 +1,16 @@
1
- import type { TrailContext, TrailContextInit } from './types.js';
1
+ import type { TrailContext, TrailContextInit, TraceFn } from './types.js';
2
+ /**
3
+ * Default passthrough `trace` used when a context is built outside
4
+ * `executeTrail`. `executeTrail` replaces this with a real sink-writing
5
+ * implementation. The passthrough runs `fn` without recording anything so
6
+ * direct `createTrailContext()` callers (tests, ad-hoc compositions) don't
7
+ * crash when invoking `ctx.trace(...)`.
8
+ *
9
+ * Declared `async` so both synchronous throws and async rejections from `fn`
10
+ * propagate as a rejected promise to the caller — matching the real
11
+ * sink-writing implementation's error semantics.
12
+ */
13
+ export declare const passthroughTrace: TraceFn;
2
14
  /**
3
15
  * Create a TrailContext with sensible defaults.
4
16
  *
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAMjE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,OAAO,CAAC,gBAAgB,CAAC,KACpC,YAWF,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAM1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAGJ,CAAC;AAE5B;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,OAAO,CAAC,gBAAgB,CAAC,KACpC,YAeF,CAAC"}
package/dist/context.js CHANGED
@@ -1,4 +1,16 @@
1
- import { createProvisionLookup } from './provision.js';
1
+ import { createResourceLookup } from './resource.js';
2
+ /**
3
+ * Default passthrough `trace` used when a context is built outside
4
+ * `executeTrail`. `executeTrail` replaces this with a real sink-writing
5
+ * implementation. The passthrough runs `fn` without recording anything so
6
+ * direct `createTrailContext()` callers (tests, ad-hoc compositions) don't
7
+ * crash when invoking `ctx.trace(...)`.
8
+ *
9
+ * Declared `async` so both synchronous throws and async rejections from `fn`
10
+ * propagate as a rejected promise to the caller — matching the real
11
+ * sink-writing implementation's error semantics.
12
+ */
13
+ export const passthroughTrace = async (_label, fn) => await fn();
2
14
  /**
3
15
  * Create a TrailContext with sensible defaults.
4
16
  *
@@ -12,10 +24,14 @@ export const createTrailContext = (overrides) => {
12
24
  cwd: process.cwd(),
13
25
  env: process.env,
14
26
  requestId: Bun.randomUUIDv7(),
27
+ trace: passthroughTrace,
15
28
  ...overrides,
16
29
  };
17
- const lookup = overrides?.provision ?? createProvisionLookup(() => ctx);
18
- ctx.provision = lookup;
30
+ const lookup = overrides?.resource ?? createResourceLookup(() => ctx);
31
+ ctx.resource = lookup;
32
+ if (ctx.trace === undefined) {
33
+ ctx.trace = passthroughTrace;
34
+ }
19
35
  return ctx;
20
36
  };
21
37
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAOvD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAqC,EACvB,EAAE;IAChB,MAAM,GAAG,GAAG;QACV,WAAW,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QACzC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,GAAG,EAAE,OAAO,CAAC,GAAyC;QACtD,SAAS,EAAE,GAAG,CAAC,YAAY,EAAE;QAC7B,GAAG,SAAS;KACU,CAAC;IACzB,MAAM,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI,qBAAqB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACxE,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC;IACvB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAOrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAY,KAAK,EAC5C,MAAc,EACd,EAAwB,EACZ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAqC,EACvB,EAAE;IAChB,MAAM,GAAG,GAAG;QACV,WAAW,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QACzC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,GAAG,EAAE,OAAO,CAAC,GAAyC;QACtD,SAAS,EAAE,GAAG,CAAC,YAAY,EAAE;QAC7B,KAAK,EAAE,gBAAgB;QACvB,GAAG,SAAS;KACU,CAAC;IACzB,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,IAAI,oBAAoB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACtE,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC;IACtB,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC5B,GAAG,CAAC,KAAK,GAAG,gBAAgB,CAAC;IAC/B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { z } from 'zod';
2
+ import type { Branded } from './branded.js';
3
+ /**
4
+ * Runtime options for a contour declaration.
5
+ */
6
+ export interface ContourOptions<TShape extends z.ZodRawShape, TIdentity extends keyof TShape & string> {
7
+ /** Field name that acts as the contour's primary identity. */
8
+ readonly identity: TIdentity;
9
+ /** Example instances validated against the contour schema at declaration time. */
10
+ readonly examples?: readonly z.output<z.ZodObject<TShape>>[] | undefined;
11
+ }
12
+ /** Type-level brand name applied to a contour's identity schema. */
13
+ export type ContourIdBrand<TName extends string> = `${Capitalize<TName>}Id`;
14
+ type BrandedSchema<TSchema extends z.core.$ZodType, TBrand extends string> = TSchema & z.ZodType<Branded<z.output<TSchema>, TBrand>>;
15
+ /** Output value of a branded contour identity schema. */
16
+ export type ContourIdValue<TSchema extends z.core.$ZodType, TName extends string> = Branded<z.output<TSchema>, ContourIdBrand<TName>>;
17
+ /** Runtime metadata attached to schemas returned from `contour.id()`. */
18
+ export interface ContourIdMetadata<TName extends string = string, TIdentity extends string = string> {
19
+ readonly contour: TName;
20
+ readonly identity: TIdentity;
21
+ }
22
+ /** A structural contour reference declared by another contour field schema. */
23
+ export interface ContourReference<TName extends string = string, TIdentity extends string = string> extends ContourIdMetadata<TName, TIdentity> {
24
+ readonly field: string;
25
+ }
26
+ /** Symbol used to tag branded contour reference schemas at runtime. */
27
+ export declare const CONTOUR_ID_METADATA: unique symbol;
28
+ /**
29
+ * A contour identity schema branded for one contour and tagged with runtime
30
+ * metadata so the topo layer can recognize declared references later on.
31
+ */
32
+ export type ContourIdSchema<TSchema extends z.core.$ZodType = z.core.$ZodType, TName extends string = string, TIdentity extends string = string> = BrandedSchema<TSchema, ContourIdBrand<TName>> & {
33
+ /** @deprecated Use `getContourIdMetadata()` — metadata lives in a WeakMap, not on the schema. */
34
+ readonly [CONTOUR_ID_METADATA]?: ContourIdMetadata<TName, TIdentity>;
35
+ };
36
+ /**
37
+ * A first-class domain object with schema, identity metadata, and examples.
38
+ *
39
+ * A contour behaves like the `ZodObject` it wraps, so standard Zod composition
40
+ * helpers such as `.pick()`, `.extend()`, and `.array()` continue to work.
41
+ */
42
+ export type Contour<TName extends string = string, TShape extends z.ZodRawShape = z.ZodRawShape, TIdentity extends keyof TShape & string = keyof TShape & string> = z.ZodObject<TShape> & {
43
+ readonly kind: 'contour';
44
+ readonly name: TName;
45
+ readonly identity: TIdentity;
46
+ readonly identitySchema: TShape[TIdentity];
47
+ readonly id: () => ContourIdSchema<TShape[TIdentity], TName, TIdentity>;
48
+ readonly examples?: readonly z.output<z.ZodObject<TShape>>[] | undefined;
49
+ };
50
+ /**
51
+ * Read contour-reference metadata from a schema returned by `contour.id()`.
52
+ *
53
+ * When the schema is wrapped by Zod combinators (`.optional()`, `.nullable()`,
54
+ * `.default()`, `.nullish()`, etc.) the `CONTOUR_ID_METADATA` symbol lives on
55
+ * the inner schema, not on the wrapper. The unwrap handles arbitrarily nested
56
+ * wrapper levels.
57
+ */
58
+ export declare const getContourIdMetadata: (schema: unknown) => ContourIdMetadata | undefined;
59
+ /** Inspect a contour schema for fields that reference other contours via `.id()`. */
60
+ export declare const getContourReferences: (contour: AnyContour) => readonly ContourReference[];
61
+ /**
62
+ * Create a contour definition from a raw Zod object shape.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const user = contour(
67
+ * 'user',
68
+ * {
69
+ * id: z.string().uuid(),
70
+ * email: z.string().email(),
71
+ * name: z.string(),
72
+ * },
73
+ * { identity: 'id' }
74
+ * );
75
+ * ```
76
+ */
77
+ export declare const contour: <TName extends string, TShape extends z.ZodRawShape, TIdentity extends keyof TShape & string>(name: TName, shape: TShape, options: ContourOptions<TShape, TIdentity>) => Contour<TName, TShape, TIdentity>;
78
+ /** Existential type for heterogeneous contour collections. */
79
+ export type AnyContour = Contour<string, z.ZodRawShape, string>;
80
+ export {};
81
+ //# sourceMappingURL=contour.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contour.d.ts","sourceRoot":"","sources":["../src/contour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,cAAc,CAC7B,MAAM,SAAS,CAAC,CAAC,WAAW,EAC5B,SAAS,SAAS,MAAM,MAAM,GAAG,MAAM;IAEvC,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;CAC1E;AAED,oEAAoE;AACpE,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;AAE5E,KAAK,aAAa,CAChB,OAAO,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAC/B,MAAM,SAAS,MAAM,IACnB,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAM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as at runtime. */
3
+ export const CONTOUR_ID_METADATA = Symbol.for('@ontrails/core/contour-id');
4
+ /**
5
+ * Module-level WeakMap storing contour identity metadata keyed by schema object.
6
+ *
7
+ * First-write-wins: when multiple contours share the same underlying schema
8
+ * (e.g. `contour('admin', { id: user.shape.id }, ...)`), the first contour to
9
+ * brand the schema claims it. Subsequent calls skip the write to prevent
10
+ * silent metadata corruption.
11
+ */
12
+ const contourIdMetadata = new WeakMap();
13
+ const formatExampleIssues = (issues) => issues
14
+ .map((issue) => {
15
+ const path = issue.path.length > 0 ? issue.path.join('.') : '<root>';
16
+ return `${path}: ${issue.message}`;
17
+ })
18
+ .join('; ');
19
+ const assertIdentityField = (name, shape, identity) => {
20
+ if (!Object.hasOwn(shape, identity)) {
21
+ throw new TypeError(`contour("${name}") identity "${identity}" must match a declared field`);
22
+ }
23
+ };
24
+ const assertExamples = (name, schema, examples) => {
25
+ for (const [index, example] of examples.entries()) {
26
+ const parsed = schema.safeParse(example);
27
+ if (!parsed.success) {
28
+ throw new TypeError(`contour("${name}") example ${index} is invalid: ${formatExampleIssues(parsed.error.issues)}`);
29
+ }
30
+ }
31
+ };
32
+ const validateExamples = (name, schema, examples) => {
33
+ if (examples) {
34
+ assertExamples(name, schema, examples);
35
+ }
36
+ };
37
+ const brandIdentitySchema = (contour, identity, schema) => {
38
+ const branded = schema.brand();
39
+ // First-write-wins: if another contour already claimed this schema object
40
+ // (possible when Zod v4 brand() returns `this`), preserve the original
41
+ // metadata rather than silently overwriting it.
42
+ if (!contourIdMetadata.has(branded)) {
43
+ contourIdMetadata.set(branded, {
44
+ contour,
45
+ identity,
46
+ });
47
+ }
48
+ return branded;
49
+ };
50
+ const attachContourMetadata = (schema, metadata) => {
51
+ Object.defineProperties(schema, {
52
+ examples: {
53
+ enumerable: true,
54
+ value: metadata.examples,
55
+ writable: false,
56
+ },
57
+ id: {
58
+ enumerable: true,
59
+ value: () => metadata.idSchema,
60
+ writable: false,
61
+ },
62
+ identity: {
63
+ enumerable: true,
64
+ value: metadata.identity,
65
+ writable: false,
66
+ },
67
+ identitySchema: {
68
+ enumerable: true,
69
+ value: metadata.identitySchema,
70
+ writable: false,
71
+ },
72
+ kind: {
73
+ enumerable: true,
74
+ value: 'contour',
75
+ writable: false,
76
+ },
77
+ name: {
78
+ enumerable: true,
79
+ value: metadata.name,
80
+ writable: false,
81
+ },
82
+ });
83
+ };
84
+ /** Read contour identity metadata from the module-level WeakMap, if present. */
85
+ const readMetadata = (schema) => typeof schema === 'object' && schema !== null
86
+ ? contourIdMetadata.get(schema)
87
+ : undefined;
88
+ /** Resolve the inner schema from a Zod wrapper (ZodOptional, ZodNullable, etc.). */
89
+ const unwrapInner = (schema) => {
90
+ const def = schema._def;
91
+ return (def?.['innerType'] ?? def?.['schema']);
92
+ };
93
+ /**
94
+ * Walk through Zod wrapper layers searching for `CONTOUR_ID_METADATA`.
95
+ *
96
+ * `.nullish()` produces `ZodOptional<ZodNullable<T>>` — two wrapper levels —
97
+ * so a single-step unwrap is insufficient. This iterates until it finds the
98
+ * metadata or exhausts all wrapper layers.
99
+ */
100
+ const unwrapToMetadata = (schema) => {
101
+ let current = schema;
102
+ while (typeof current === 'object' && current !== null) {
103
+ const inner = unwrapInner(current);
104
+ if (typeof inner !== 'object' || inner === null) {
105
+ return undefined;
106
+ }
107
+ const metadata = readMetadata(inner);
108
+ if (metadata !== undefined) {
109
+ return metadata;
110
+ }
111
+ current = inner;
112
+ }
113
+ return undefined;
114
+ };
115
+ /**
116
+ * Read contour-reference metadata from a schema returned by `contour.id()`.
117
+ *
118
+ * When the schema is wrapped by Zod combinators (`.optional()`, `.nullable()`,
119
+ * `.default()`, `.nullish()`, etc.) the `CONTOUR_ID_METADATA` symbol lives on
120
+ * the inner schema, not on the wrapper. The unwrap handles arbitrarily nested
121
+ * wrapper levels.
122
+ */
123
+ export const getContourIdMetadata = (schema) => readMetadata(schema) ?? unwrapToMetadata(schema);
124
+ /** Inspect a contour schema for fields that reference other contours via `.id()`. */
125
+ export const getContourReferences = (contour) => Object.entries(contour.shape)
126
+ .flatMap(([field, schema]) => {
127
+ if (field === contour.identity) {
128
+ return [];
129
+ }
130
+ const metadata = getContourIdMetadata(schema);
131
+ if (metadata === undefined) {
132
+ return [];
133
+ }
134
+ return [{ field, ...metadata }];
135
+ })
136
+ .toSorted((left, right) => left.field === right.field
137
+ ? left.contour.localeCompare(right.contour)
138
+ : left.field.localeCompare(right.field));
139
+ /**
140
+ * Create a contour definition from a raw Zod object shape.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const user = contour(
145
+ * 'user',
146
+ * {
147
+ * id: z.string().uuid(),
148
+ * email: z.string().email(),
149
+ * name: z.string(),
150
+ * },
151
+ * { identity: 'id' }
152
+ * );
153
+ * ```
154
+ */
155
+ export const contour = (name, shape, options) => {
156
+ assertIdentityField(name, shape, options.identity);
157
+ const schema = z.object(shape);
158
+ validateExamples(name, schema, options.examples);
159
+ const identitySchema = shape[options.identity];
160
+ if (!identitySchema) {
161
+ throw new TypeError(`contour("${name}") identity "${options.identity}" must resolve to a schema`);
162
+ }
163
+ const idSchema = brandIdentitySchema(name, options.identity, identitySchema);
164
+ const examples = options.examples
165
+ ? Object.freeze([...options.examples])
166
+ : undefined;
167
+ attachContourMetadata(schema, {
168
+ examples,
169
+ idSchema,
170
+ identity: options.identity,
171
+ identitySchema,
172
+ name,
173
+ });
174
+ return schema;
175
+ };
176
+ //# sourceMappingURL=contour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contour.js","sourceRoot":"","sources":["../src/contour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoDxB,uEAAuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAE3E;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAA6B,CAAC;AAkCnE,MAAM,mBAAmB,GAAG,CAAC,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AC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC7E,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ;QAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC,CAAC,SAAS,CAAC;IAEd,qBAAqB,CAAC,MAAM,EAAE;QAC5B,QAAQ;QACR,QAAQ;QACR,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,cAAc;QACd,IAAI;KACL,CAAC,CAAC;IAEH,OAAO,MAA2C,CAAC;AACrD,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Cross-invocation schema merging for trails with `crossInput`.
3
+ *
4
+ * When a trail declares `crossInput`, callers via `ctx.cross()` pass both
5
+ * public input and composition-only fields. The merged schema validates the
6
+ * combined shape so `executeTrail` doesn't reject the extra fields.
7
+ */
8
+ import { z } from 'zod';
9
+ import type { AnyTrail } from './trail.js';
10
+ /**
11
+ * Build the validation schema for a cross-invoked trail.
12
+ *
13
+ * When the target trail declares `crossInput`, returns the intersection of
14
+ * `trail.input` and `trail.crossInput`. Returns `undefined` when no
15
+ * `crossInput` is declared, signaling that normal input validation suffices.
16
+ */
17
+ export declare const buildCrossValidationSchema: (trailDef: AnyTrail) => z.ZodType | undefined;
18
+ //# sourceMappingURL=cross-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-schema.d.ts","sourceRoot":"","sources":["../src/cross-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,UAAU,QAAQ,KACjB,CAAC,CAAC,OAAO,GAAG,SAcd,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Cross-invocation schema merging for trails with `crossInput`.
3
+ *
4
+ * When a trail declares `crossInput`, callers via `ctx.cross()` pass both
5
+ * public input and composition-only fields. The merged schema validates the
6
+ * combined shape so `executeTrail` doesn't reject the extra fields.
7
+ */
8
+ import { z } from 'zod';
9
+ /**
10
+ * Build the validation schema for a cross-invoked trail.
11
+ *
12
+ * When the target trail declares `crossInput`, returns the intersection of
13
+ * `trail.input` and `trail.crossInput`. Returns `undefined` when no
14
+ * `crossInput` is declared, signaling that normal input validation suffices.
15
+ */
16
+ export const buildCrossValidationSchema = (trailDef) => {
17
+ if (!trailDef.crossInput) {
18
+ return undefined;
19
+ }
20
+ // Prefer .merge() for ZodObject pairs — produces a proper merged object
21
+ // schema that strips unknown keys and exposes .shape. Fall back to
22
+ // z.intersection for non-object schemas.
23
+ if (trailDef.input instanceof z.ZodObject &&
24
+ trailDef.crossInput instanceof z.ZodObject) {
25
+ return trailDef.input.merge(trailDef.crossInput);
26
+ }
27
+ return z.intersection(trailDef.input, trailDef.crossInput);
28
+ };
29
+ //# sourceMappingURL=cross-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-schema.js","sourceRoot":"","sources":["../src/cross-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,QAAkB,EACK,EAAE;IACzB,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,wEAAwE;IACxE,mEAAmE;IACnE,yCAAyC;IACzC,IACE,QAAQ,CAAC,KAAK,YAAY,CAAC,CAAC,SAAS;QACrC,QAAQ,CAAC,UAAU,YAAY,CAAC,CAAC,SAAS,EAC1C,CAAC;QACD,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC7D,CAAC,CAAC"}
package/dist/draft.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ValidationError } from './errors.js';
2
2
  import { Result } from './result.js';
3
3
  import type { Topo } from './topo.js';
4
4
  export declare const DRAFT_ID_PREFIX = "_draft.";
5
- export type DraftDependencyKind = 'cross' | 'detour' | 'provision' | 'replaced-by' | 'signal-from';
5
+ export type DraftDependencyKind = 'cross' | 'contour' | 'resource' | 'replaced-by' | 'schema-reference' | 'signal-from';
6
6
  export interface DraftDependency {
7
7
  readonly fromId: string;
8
8
  readonly kind: DraftDependencyKind;
@@ -10,19 +10,19 @@ export interface DraftDependency {
10
10
  }
11
11
  export interface DraftFinding {
12
12
  readonly id: string;
13
- readonly kind: 'provision' | 'signal' | 'trail' | 'unknown';
13
+ readonly kind: 'contour' | 'resource' | 'signal' | 'trail' | 'unknown';
14
14
  readonly message: string;
15
15
  readonly rule: 'draft-contamination' | 'draft-id';
16
16
  readonly via?: DraftDependencyKind | undefined;
17
17
  readonly dependsOn?: string | undefined;
18
18
  }
19
- export interface DraftStateAnalysis {
19
+ export interface DraftReport {
20
20
  readonly contaminatedIds: ReadonlySet<string>;
21
21
  readonly declaredDraftIds: ReadonlySet<string>;
22
22
  readonly dependencies: readonly DraftDependency[];
23
23
  readonly findings: readonly DraftFinding[];
24
24
  }
25
25
  export declare const isDraftId: (id: string) => boolean;
26
- export declare const analyzeDraftState: (topo: Topo) => DraftStateAnalysis;
27
- export declare const validateEstablishedTopo: (topo: Topo) => Result<void, ValidationError>;
26
+ export declare const deriveDraftReport: (topo: Topo) => DraftReport;
27
+ export declare const validateDraftFreeTopo: (topo: Topo) => Result<void, ValidationError>;
28
28
  //# sourceMappingURL=draft.d.ts.map
@@ -1 +1 @@
1
- {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