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

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 (348) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +61 -16
  3. package/package.json +9 -8
  4. package/src/activation-provenance.ts +111 -0
  5. package/src/activation-source-compatibility.ts +430 -0
  6. package/src/activation-source-projection.ts +221 -0
  7. package/src/activation-source.ts +91 -0
  8. package/src/blob-ref.ts +51 -0
  9. package/src/context.ts +4 -0
  10. package/src/{internal/cross-batch.ts → cross-batch.ts} +3 -11
  11. package/src/detours.ts +8 -0
  12. package/src/draft.ts +4 -0
  13. package/src/error-projection.ts +51 -0
  14. package/src/errors.ts +192 -39
  15. package/src/execute.ts +443 -44
  16. package/src/fire.ts +965 -91
  17. package/src/index.ts +285 -38
  18. package/src/layer-projection.ts +192 -0
  19. package/src/layer.ts +32 -1
  20. package/src/observe.ts +361 -0
  21. package/src/permits.ts +12 -0
  22. package/src/redaction/patterns.ts +6 -3
  23. package/src/resilience.ts +8 -8
  24. package/src/resource-config.ts +477 -44
  25. package/src/resource.ts +21 -1
  26. package/src/result.ts +18 -0
  27. package/src/run.ts +2 -2
  28. package/src/schedule-runtime.ts +689 -0
  29. package/src/schedule.ts +324 -0
  30. package/src/serialization.ts +90 -57
  31. package/src/signal-diagnostics.ts +633 -0
  32. package/src/{internal/signal-ref.ts → signal-ref.ts} +1 -1
  33. package/src/signal.ts +37 -0
  34. package/src/store/accessor-protocol.ts +5 -5
  35. package/src/structured-examples.ts +245 -0
  36. package/src/surface-derivation.ts +91 -0
  37. package/src/surface-filter.ts +7 -13
  38. package/src/topo.ts +386 -6
  39. package/src/tracing.ts +345 -0
  40. package/src/trail.ts +168 -22
  41. package/src/trails/derive-trail.ts +1 -1
  42. package/src/trails/ingest.ts +7 -15
  43. package/src/{internal/trails-db.ts → trails-db.ts} +42 -21
  44. package/src/transport-error-map.ts +146 -28
  45. package/src/types.ts +82 -28
  46. package/src/validate-established-topo.ts +6 -0
  47. package/src/validate-topo.ts +212 -5
  48. package/src/validation.ts +58 -1
  49. package/src/webhook.ts +276 -0
  50. package/src/{internal/zod-wrappers.ts → zod-wrappers.ts} +0 -6
  51. package/.turbo/turbo-build.log +0 -1
  52. package/.turbo/turbo-lint.log +0 -3
  53. package/.turbo/turbo-typecheck.log +0 -1
  54. package/dist/blob-ref.d.ts +0 -20
  55. package/dist/blob-ref.d.ts.map +0 -1
  56. package/dist/blob-ref.js +0 -22
  57. package/dist/blob-ref.js.map +0 -1
  58. package/dist/branded.d.ts +0 -36
  59. package/dist/branded.d.ts.map +0 -1
  60. package/dist/branded.js +0 -89
  61. package/dist/branded.js.map +0 -1
  62. package/dist/collections.d.ts +0 -31
  63. package/dist/collections.d.ts.map +0 -1
  64. package/dist/collections.js +0 -60
  65. package/dist/collections.js.map +0 -1
  66. package/dist/context.d.ts +0 -22
  67. package/dist/context.d.ts.map +0 -1
  68. package/dist/context.js +0 -37
  69. package/dist/context.js.map +0 -1
  70. package/dist/contour.d.ts +0 -81
  71. package/dist/contour.d.ts.map +0 -1
  72. package/dist/contour.js +0 -176
  73. package/dist/contour.js.map +0 -1
  74. package/dist/cross-schema.d.ts +0 -18
  75. package/dist/cross-schema.d.ts.map +0 -1
  76. package/dist/cross-schema.js +0 -29
  77. package/dist/cross-schema.js.map +0 -1
  78. package/dist/derive.d.ts +0 -44
  79. package/dist/derive.d.ts.map +0 -1
  80. package/dist/derive.js +0 -149
  81. package/dist/derive.js.map +0 -1
  82. package/dist/draft.d.ts +0 -28
  83. package/dist/draft.d.ts.map +0 -1
  84. package/dist/draft.js +0 -157
  85. package/dist/draft.js.map +0 -1
  86. package/dist/errors.d.ts +0 -141
  87. package/dist/errors.d.ts.map +0 -1
  88. package/dist/errors.js +0 -185
  89. package/dist/errors.js.map +0 -1
  90. package/dist/execute.d.ts +0 -52
  91. package/dist/execute.d.ts.map +0 -1
  92. package/dist/execute.js +0 -511
  93. package/dist/execute.js.map +0 -1
  94. package/dist/fetch.d.ts +0 -15
  95. package/dist/fetch.d.ts.map +0 -1
  96. package/dist/fetch.js +0 -102
  97. package/dist/fetch.js.map +0 -1
  98. package/dist/fire.d.ts +0 -43
  99. package/dist/fire.d.ts.map +0 -1
  100. package/dist/fire.js +0 -185
  101. package/dist/fire.js.map +0 -1
  102. package/dist/guards.d.ts +0 -17
  103. package/dist/guards.d.ts.map +0 -1
  104. package/dist/guards.js +0 -25
  105. package/dist/guards.js.map +0 -1
  106. package/dist/index.d.ts +0 -59
  107. package/dist/index.d.ts.map +0 -1
  108. package/dist/index.js +0 -61
  109. package/dist/index.js.map +0 -1
  110. package/dist/internal/cross-batch.d.ts +0 -44
  111. package/dist/internal/cross-batch.d.ts.map +0 -1
  112. package/dist/internal/cross-batch.js +0 -58
  113. package/dist/internal/cross-batch.js.map +0 -1
  114. package/dist/internal/fork-ctx.d.ts +0 -41
  115. package/dist/internal/fork-ctx.d.ts.map +0 -1
  116. package/dist/internal/fork-ctx.js +0 -47
  117. package/dist/internal/fork-ctx.js.map +0 -1
  118. package/dist/internal/signal-ref.d.ts +0 -15
  119. package/dist/internal/signal-ref.d.ts.map +0 -1
  120. package/dist/internal/signal-ref.js +0 -41
  121. package/dist/internal/signal-ref.js.map +0 -1
  122. package/dist/internal/topo-saves.d.ts +0 -53
  123. package/dist/internal/topo-saves.d.ts.map +0 -1
  124. package/dist/internal/topo-saves.js +0 -449
  125. package/dist/internal/topo-saves.js.map +0 -1
  126. package/dist/internal/topo-snapshots.d.ts +0 -57
  127. package/dist/internal/topo-snapshots.d.ts.map +0 -1
  128. package/dist/internal/topo-snapshots.js +0 -372
  129. package/dist/internal/topo-snapshots.js.map +0 -1
  130. package/dist/internal/topo-store-read.d.ts +0 -70
  131. package/dist/internal/topo-store-read.d.ts.map +0 -1
  132. package/dist/internal/topo-store-read.js +0 -221
  133. package/dist/internal/topo-store-read.js.map +0 -1
  134. package/dist/internal/topo-store.d.ts +0 -26
  135. package/dist/internal/topo-store.d.ts.map +0 -1
  136. package/dist/internal/topo-store.js +0 -621
  137. package/dist/internal/topo-store.js.map +0 -1
  138. package/dist/internal/tracing.d.ts +0 -98
  139. package/dist/internal/tracing.d.ts.map +0 -1
  140. package/dist/internal/tracing.js +0 -102
  141. package/dist/internal/tracing.js.map +0 -1
  142. package/dist/internal/trails-db.d.ts +0 -16
  143. package/dist/internal/trails-db.d.ts.map +0 -1
  144. package/dist/internal/trails-db.js +0 -118
  145. package/dist/internal/trails-db.js.map +0 -1
  146. package/dist/internal/zod-wrappers.d.ts +0 -40
  147. package/dist/internal/zod-wrappers.d.ts.map +0 -1
  148. package/dist/internal/zod-wrappers.js +0 -59
  149. package/dist/internal/zod-wrappers.js.map +0 -1
  150. package/dist/layer.d.ts +0 -23
  151. package/dist/layer.d.ts.map +0 -1
  152. package/dist/layer.js +0 -21
  153. package/dist/layer.js.map +0 -1
  154. package/dist/path-security.d.ts +0 -28
  155. package/dist/path-security.d.ts.map +0 -1
  156. package/dist/path-security.js +0 -63
  157. package/dist/path-security.js.map +0 -1
  158. package/dist/patterns/bulk.d.ts +0 -15
  159. package/dist/patterns/bulk.d.ts.map +0 -1
  160. package/dist/patterns/bulk.js +0 -14
  161. package/dist/patterns/bulk.js.map +0 -1
  162. package/dist/patterns/change.d.ts +0 -10
  163. package/dist/patterns/change.d.ts.map +0 -1
  164. package/dist/patterns/change.js +0 -10
  165. package/dist/patterns/change.js.map +0 -1
  166. package/dist/patterns/date-range.d.ts +0 -10
  167. package/dist/patterns/date-range.d.ts.map +0 -1
  168. package/dist/patterns/date-range.js +0 -10
  169. package/dist/patterns/date-range.js.map +0 -1
  170. package/dist/patterns/index.d.ts +0 -9
  171. package/dist/patterns/index.d.ts.map +0 -1
  172. package/dist/patterns/index.js +0 -9
  173. package/dist/patterns/index.js.map +0 -1
  174. package/dist/patterns/pagination.d.ts +0 -18
  175. package/dist/patterns/pagination.d.ts.map +0 -1
  176. package/dist/patterns/pagination.js +0 -18
  177. package/dist/patterns/pagination.js.map +0 -1
  178. package/dist/patterns/progress.d.ts +0 -11
  179. package/dist/patterns/progress.d.ts.map +0 -1
  180. package/dist/patterns/progress.js +0 -11
  181. package/dist/patterns/progress.js.map +0 -1
  182. package/dist/patterns/sorting.d.ts +0 -13
  183. package/dist/patterns/sorting.d.ts.map +0 -1
  184. package/dist/patterns/sorting.js +0 -10
  185. package/dist/patterns/sorting.js.map +0 -1
  186. package/dist/patterns/status.d.ts +0 -15
  187. package/dist/patterns/status.d.ts.map +0 -1
  188. package/dist/patterns/status.js +0 -9
  189. package/dist/patterns/status.js.map +0 -1
  190. package/dist/patterns/timestamps.d.ts +0 -10
  191. package/dist/patterns/timestamps.d.ts.map +0 -1
  192. package/dist/patterns/timestamps.js +0 -10
  193. package/dist/patterns/timestamps.js.map +0 -1
  194. package/dist/redaction/index.d.ts +0 -4
  195. package/dist/redaction/index.d.ts.map +0 -1
  196. package/dist/redaction/index.js +0 -3
  197. package/dist/redaction/index.js.map +0 -1
  198. package/dist/redaction/patterns.d.ts +0 -9
  199. package/dist/redaction/patterns.d.ts.map +0 -1
  200. package/dist/redaction/patterns.js +0 -39
  201. package/dist/redaction/patterns.js.map +0 -1
  202. package/dist/redaction/redactor.d.ts +0 -27
  203. package/dist/redaction/redactor.d.ts.map +0 -1
  204. package/dist/redaction/redactor.js +0 -89
  205. package/dist/redaction/redactor.js.map +0 -1
  206. package/dist/resilience.d.ts +0 -34
  207. package/dist/resilience.d.ts.map +0 -1
  208. package/dist/resilience.js +0 -164
  209. package/dist/resilience.js.map +0 -1
  210. package/dist/resource-config.d.ts +0 -22
  211. package/dist/resource-config.d.ts.map +0 -1
  212. package/dist/resource-config.js +0 -210
  213. package/dist/resource-config.js.map +0 -1
  214. package/dist/resource.d.ts +0 -74
  215. package/dist/resource.d.ts.map +0 -1
  216. package/dist/resource.js +0 -61
  217. package/dist/resource.js.map +0 -1
  218. package/dist/result.d.ts +0 -57
  219. package/dist/result.d.ts.map +0 -1
  220. package/dist/result.js +0 -156
  221. package/dist/result.js.map +0 -1
  222. package/dist/run.d.ts +0 -28
  223. package/dist/run.d.ts.map +0 -1
  224. package/dist/run.js +0 -35
  225. package/dist/run.js.map +0 -1
  226. package/dist/serialization.d.ts +0 -27
  227. package/dist/serialization.d.ts.map +0 -1
  228. package/dist/serialization.js +0 -154
  229. package/dist/serialization.js.map +0 -1
  230. package/dist/signal.d.ts +0 -33
  231. package/dist/signal.d.ts.map +0 -1
  232. package/dist/signal.js +0 -17
  233. package/dist/signal.js.map +0 -1
  234. package/dist/store/accessor-protocol.d.ts +0 -51
  235. package/dist/store/accessor-protocol.d.ts.map +0 -1
  236. package/dist/store/accessor-protocol.js +0 -2
  237. package/dist/store/accessor-protocol.js.map +0 -1
  238. package/dist/store/index.d.ts +0 -2
  239. package/dist/store/index.d.ts.map +0 -1
  240. package/dist/store/index.js +0 -2
  241. package/dist/store/index.js.map +0 -1
  242. package/dist/surface-filter.d.ts +0 -13
  243. package/dist/surface-filter.d.ts.map +0 -1
  244. package/dist/surface-filter.js +0 -76
  245. package/dist/surface-filter.js.map +0 -1
  246. package/dist/topo-store.d.ts +0 -62
  247. package/dist/topo-store.d.ts.map +0 -1
  248. package/dist/topo-store.js +0 -319
  249. package/dist/topo-store.js.map +0 -1
  250. package/dist/topo.d.ts +0 -39
  251. package/dist/topo.d.ts.map +0 -1
  252. package/dist/topo.js +0 -241
  253. package/dist/topo.js.map +0 -1
  254. package/dist/trail.d.ts +0 -163
  255. package/dist/trail.d.ts.map +0 -1
  256. package/dist/trail.js +0 -75
  257. package/dist/trail.js.map +0 -1
  258. package/dist/trails/derive-trail.d.ts +0 -66
  259. package/dist/trails/derive-trail.d.ts.map +0 -1
  260. package/dist/trails/derive-trail.js +0 -378
  261. package/dist/trails/derive-trail.js.map +0 -1
  262. package/dist/trails/index.d.ts +0 -5
  263. package/dist/trails/index.d.ts.map +0 -1
  264. package/dist/trails/index.js +0 -3
  265. package/dist/trails/index.js.map +0 -1
  266. package/dist/trails/ingest.d.ts +0 -24
  267. package/dist/trails/ingest.d.ts.map +0 -1
  268. package/dist/trails/ingest.js +0 -63
  269. package/dist/trails/ingest.js.map +0 -1
  270. package/dist/transport-error-map.d.ts +0 -106
  271. package/dist/transport-error-map.d.ts.map +0 -1
  272. package/dist/transport-error-map.js +0 -24
  273. package/dist/transport-error-map.js.map +0 -1
  274. package/dist/type-checks.test-d.d.ts +0 -71
  275. package/dist/type-checks.test-d.d.ts.map +0 -1
  276. package/dist/type-checks.test-d.js +0 -12
  277. package/dist/type-checks.test-d.js.map +0 -1
  278. package/dist/type-utils.d.ts +0 -33
  279. package/dist/type-utils.d.ts.map +0 -1
  280. package/dist/type-utils.js +0 -12
  281. package/dist/type-utils.js.map +0 -1
  282. package/dist/types.d.ts +0 -177
  283. package/dist/types.d.ts.map +0 -1
  284. package/dist/types.js +0 -3
  285. package/dist/types.js.map +0 -1
  286. package/dist/validate-established-topo.d.ts +0 -76
  287. package/dist/validate-established-topo.d.ts.map +0 -1
  288. package/dist/validate-established-topo.js +0 -43
  289. package/dist/validate-established-topo.js.map +0 -1
  290. package/dist/validate-topo.d.ts +0 -24
  291. package/dist/validate-topo.d.ts.map +0 -1
  292. package/dist/validate-topo.js +0 -193
  293. package/dist/validate-topo.js.map +0 -1
  294. package/dist/validation.d.ts +0 -27
  295. package/dist/validation.d.ts.map +0 -1
  296. package/dist/validation.js +0 -165
  297. package/dist/validation.js.map +0 -1
  298. package/dist/workspace.d.ts +0 -25
  299. package/dist/workspace.d.ts.map +0 -1
  300. package/dist/workspace.js +0 -57
  301. package/dist/workspace.js.map +0 -1
  302. package/src/__tests__/blob-ref.test.ts +0 -103
  303. package/src/__tests__/branded.test.ts +0 -148
  304. package/src/__tests__/collections.test.ts +0 -126
  305. package/src/__tests__/context.test.ts +0 -77
  306. package/src/__tests__/contour.test.ts +0 -263
  307. package/src/__tests__/derive-trail.test.ts +0 -668
  308. package/src/__tests__/derive.test.ts +0 -260
  309. package/src/__tests__/errors.test.ts +0 -427
  310. package/src/__tests__/execute.test.ts +0 -1563
  311. package/src/__tests__/fetch.test.ts +0 -217
  312. package/src/__tests__/fire.test.ts +0 -1056
  313. package/src/__tests__/fork-ctx.test.ts +0 -83
  314. package/src/__tests__/guards.test.ts +0 -102
  315. package/src/__tests__/ingest.test.ts +0 -191
  316. package/src/__tests__/layer.test.ts +0 -125
  317. package/src/__tests__/path-security.test.ts +0 -114
  318. package/src/__tests__/patterns.test.ts +0 -273
  319. package/src/__tests__/redaction.test.ts +0 -244
  320. package/src/__tests__/resilience.test.ts +0 -246
  321. package/src/__tests__/resource.test.ts +0 -204
  322. package/src/__tests__/result.test.ts +0 -155
  323. package/src/__tests__/run.test.ts +0 -181
  324. package/src/__tests__/serialization.test.ts +0 -401
  325. package/src/__tests__/service-config.test.ts +0 -224
  326. package/src/__tests__/signal.test.ts +0 -82
  327. package/src/__tests__/surface-filter.test.ts +0 -196
  328. package/src/__tests__/topo-store-read.test.ts +0 -256
  329. package/src/__tests__/topo-store.test.ts +0 -869
  330. package/src/__tests__/topo.test.ts +0 -573
  331. package/src/__tests__/trail-permit.test.ts +0 -60
  332. package/src/__tests__/trail.test.ts +0 -426
  333. package/src/__tests__/trails-db.test.ts +0 -198
  334. package/src/__tests__/transport-error-map.test.ts +0 -82
  335. package/src/__tests__/type-utils.test.ts +0 -118
  336. package/src/__tests__/validate-topo.test.ts +0 -611
  337. package/src/__tests__/validation.test.ts +0 -336
  338. package/src/__tests__/workspace.test.ts +0 -183
  339. package/src/__tests__/zod-wrappers.test.ts +0 -62
  340. package/src/internal/topo-snapshots.ts +0 -517
  341. package/src/internal/topo-store-read.ts +0 -481
  342. package/src/internal/topo-store.ts +0 -1192
  343. package/src/internal/tracing.ts +0 -187
  344. package/src/topo-store.ts +0 -510
  345. package/src/type-checks.test-d.ts +0 -106
  346. package/tsconfig.json +0 -9
  347. package/tsconfig.tests.json +0 -10
  348. package/tsconfig.tsbuildinfo +0 -1
@@ -1,98 +0,0 @@
1
- /**
2
- * Intrinsic tracing primitives.
3
- *
4
- * This module is the home for the trace record type, the sink interface,
5
- * the sink registry, and the helpers `executeTrail` uses to create root
6
- * trace records and child spans. It is intentionally framework-internal —
7
- * the `@ontrails/tracing` package re-exports the public surface so callers
8
- * can continue to import from there.
9
- *
10
- * Tracing is intrinsic: every `executeTrail` call automatically produces a
11
- * root `TraceRecord`, and `ctx.trace(label, fn)` creates nested child spans
12
- * underneath it. A default no-op sink is installed at module load so core
13
- * never crashes when no real sink has been registered.
14
- */
15
- /** Evidence of a single trail execution or manual span. */
16
- export interface TraceRecord {
17
- readonly id: string;
18
- readonly traceId: string;
19
- readonly rootId: string;
20
- readonly parentId?: string | undefined;
21
- readonly kind: 'trail' | 'span';
22
- readonly name: string;
23
- readonly trailId?: string | undefined;
24
- readonly trailhead?: 'cli' | 'mcp' | 'http' | 'ws' | undefined;
25
- readonly intent?: 'read' | 'write' | 'destroy' | undefined;
26
- readonly startedAt: number;
27
- readonly endedAt?: number | undefined;
28
- readonly status: 'ok' | 'err' | 'cancelled';
29
- readonly errorCategory?: string | undefined;
30
- readonly permit?: {
31
- readonly id: string;
32
- readonly tenantId?: string;
33
- } | undefined;
34
- readonly attrs: Readonly<Record<string, unknown>>;
35
- }
36
- /**
37
- * Minimal shape a tracing sink must satisfy.
38
- *
39
- * Kept intentionally tiny so adapters in `@ontrails/tracing`,
40
- * `@ontrails/observe`, and user code can all satisfy it without
41
- * additional dependencies.
42
- */
43
- export interface TraceSink {
44
- readonly write: (record: TraceRecord) => void | Promise<void>;
45
- }
46
- /** Trace context carried through trail execution via `ctx.extensions`. */
47
- export interface TraceContext {
48
- readonly traceId: string;
49
- readonly spanId: string;
50
- readonly rootId: string;
51
- readonly sampled: boolean;
52
- }
53
- /** Key used to store trace context in `ctx.extensions`. */
54
- export declare const TRACE_CONTEXT_KEY = "__trace_context";
55
- /** Read trace context from trail context extensions. */
56
- export declare const getTraceContext: (ctx: {
57
- readonly extensions?: Readonly<Record<string, unknown>> | undefined;
58
- }) => TraceContext | undefined;
59
- /** No-op sink installed by default so core never crashes without configuration. */
60
- export declare const NOOP_SINK: TraceSink;
61
- /**
62
- * Register a trace sink globally.
63
- *
64
- * All trails executed via `executeTrail` will write their completed trace
65
- * records to this sink, as will every `ctx.trace(label, fn)` child span.
66
- * Registering `undefined` or calling {@link clearTraceSink} resets back to
67
- * the default no-op sink.
68
- */
69
- export declare const registerTraceSink: (sink: TraceSink | undefined) => void;
70
- /** Retrieve the currently registered sink (never undefined). */
71
- export declare const getTraceSink: () => TraceSink;
72
- /** True when tracing is effectively disabled and executeTrail should skip allocation. */
73
- export declare const isTracingDisabled: (sink?: TraceSink) => boolean;
74
- /** Reset the sink registry back to the default no-op sink. */
75
- export declare const clearTraceSink: () => void;
76
- /** Options for creating a trail-scoped {@link TraceRecord}. */
77
- interface CreateTraceRecordOptions {
78
- readonly trailId: string;
79
- readonly traceId?: string | undefined;
80
- readonly parentId?: string | undefined;
81
- readonly rootId?: string | undefined;
82
- readonly trailhead?: TraceRecord['trailhead'];
83
- readonly intent?: TraceRecord['intent'];
84
- readonly permit?: {
85
- readonly id: string;
86
- readonly tenantId?: string;
87
- } | undefined;
88
- }
89
- /** Create a fresh trail-kind {@link TraceRecord}. */
90
- export declare const createTraceRecord: (options: CreateTraceRecordOptions) => TraceRecord;
91
- /** Build a span record from a parent trace context. */
92
- export declare const createSpanRecord: (parent: TraceContext, label: string) => TraceRecord;
93
- /** Mark a record as completed with timing and status. */
94
- export declare const completeRecord: (record: TraceRecord, status: TraceRecord["status"], errorCategory?: string | undefined) => TraceRecord;
95
- /** Best-effort sink write that never throws. */
96
- export declare const writeToSink: (sink: TraceSink, record: TraceRecord) => Promise<void>;
97
- export {};
98
- //# sourceMappingURL=tracing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/internal/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,2D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AAC,EACZ;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GACnD,SAAS,CAAC;CACf;AAED,qDAAqD;AACrD,eAAO,MAAM,iBAAiB,GAC5B,SAAS,wBAAwB,KAChC,WAoBF,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,YAAY,EACpB,OAAO,MAAM,KACZ,WAeD,CAAC;AAEH,yDAAyD;AACzD,eAAO,MAAM,cAAc,GACzB,QAAQ,WAAW,EACnB,QAAQ,WAAW,CAAC,QAAQ,CAAC,EAC7B,gBAAgB,MAAM,GAAG,SAAS,KACjC,WAKD,CAAC;AAEH,gDAAgD;AAChD,eAAO,MAAM,WAAW,GACtB,MAAM,SAAS,EACf,QAAQ,WAAW,KAClB,OAAO,CAAC,IAAI,CAMd,CAAC"}
@@ -1,102 +0,0 @@
1
- /**
2
- * Intrinsic tracing primitives.
3
- *
4
- * This module is the home for the trace record type, the sink interface,
5
- * the sink registry, and the helpers `executeTrail` uses to create root
6
- * trace records and child spans. It is intentionally framework-internal —
7
- * the `@ontrails/tracing` package re-exports the public surface so callers
8
- * can continue to import from there.
9
- *
10
- * Tracing is intrinsic: every `executeTrail` call automatically produces a
11
- * root `TraceRecord`, and `ctx.trace(label, fn)` creates nested child spans
12
- * underneath it. A default no-op sink is installed at module load so core
13
- * never crashes when no real sink has been registered.
14
- */
15
- /** Key used to store trace context in `ctx.extensions`. */
16
- export const TRACE_CONTEXT_KEY = '__trace_context';
17
- /** Read trace context from trail context extensions. */
18
- export const getTraceContext = (ctx) => ctx.extensions?.[TRACE_CONTEXT_KEY];
19
- // ---------------------------------------------------------------------------
20
- // Default no-op sink + sink registry
21
- // ---------------------------------------------------------------------------
22
- /** No-op sink installed by default so core never crashes without configuration. */
23
- export const NOOP_SINK = {
24
- // oxlint-disable-next-line no-empty-function -- intentional no-op
25
- write: () => { },
26
- };
27
- // oxlint-disable-next-line eslint-plugin-jest/require-hook -- module-level sink registry, not test setup
28
- let currentSink = NOOP_SINK;
29
- /**
30
- * Register a trace sink globally.
31
- *
32
- * All trails executed via `executeTrail` will write their completed trace
33
- * records to this sink, as will every `ctx.trace(label, fn)` child span.
34
- * Registering `undefined` or calling {@link clearTraceSink} resets back to
35
- * the default no-op sink.
36
- */
37
- export const registerTraceSink = (sink) => {
38
- currentSink = sink ?? NOOP_SINK;
39
- };
40
- /** Retrieve the currently registered sink (never undefined). */
41
- export const getTraceSink = () => currentSink;
42
- /** True when tracing is effectively disabled and executeTrail should skip allocation. */
43
- export const isTracingDisabled = (sink = currentSink) => sink === NOOP_SINK;
44
- /** Reset the sink registry back to the default no-op sink. */
45
- export const clearTraceSink = () => {
46
- currentSink = NOOP_SINK;
47
- };
48
- /** Create a fresh trail-kind {@link TraceRecord}. */
49
- export const createTraceRecord = (options) => {
50
- const id = Bun.randomUUIDv7();
51
- const traceId = options.traceId ?? Bun.randomUUIDv7();
52
- return {
53
- attrs: {},
54
- endedAt: undefined,
55
- id,
56
- intent: options.intent,
57
- kind: 'trail',
58
- name: options.trailId,
59
- parentId: options.parentId,
60
- permit: options.permit,
61
- rootId: options.rootId ?? id,
62
- startedAt: Date.now(),
63
- status: 'ok',
64
- traceId,
65
- trailId: options.trailId,
66
- trailhead: options.trailhead,
67
- };
68
- };
69
- /** Build a span record from a parent trace context. */
70
- export const createSpanRecord = (parent, label) => ({
71
- attrs: {},
72
- endedAt: undefined,
73
- errorCategory: undefined,
74
- id: Bun.randomUUIDv7(),
75
- intent: undefined,
76
- kind: 'span',
77
- name: label,
78
- parentId: parent.spanId,
79
- rootId: parent.rootId,
80
- startedAt: Date.now(),
81
- status: 'ok',
82
- traceId: parent.traceId,
83
- trailId: undefined,
84
- trailhead: undefined,
85
- });
86
- /** Mark a record as completed with timing and status. */
87
- export const completeRecord = (record, status, errorCategory) => ({
88
- ...record,
89
- endedAt: Date.now(),
90
- errorCategory,
91
- status,
92
- });
93
- /** Best-effort sink write that never throws. */
94
- export const writeToSink = async (sink, record) => {
95
- try {
96
- await Promise.resolve(sink.write(record));
97
- }
98
- catch {
99
- // Sink failures must never affect trail result delivery.
100
- }
101
- };
102
- //# sourceMappingURL=tracing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/internal/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA0CH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD,wDAAwD;AACxD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAE/B,EAA4B,EAAE,CAC7B,GAAG,CAAC,UAAU,EAAE,CAAC,iBAAiB,CAA6B,CAAC;AAElE,8EAA8E;AAC9E,qCAAqC;AACrC,8EAA8E;AAE9E,mFAAmF;AACnF,MAAM,CAAC,MAAM,SAAS,GAAc;IAClC,kEAAkE;IAClE,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;CAChB,CAAC;AAEF,yGAAyG;AACzG,IAAI,WAAW,GAAc,SAAS,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAA2B,EAAQ,EAAE;IACrE,WAAW,GAAG,IAAI,IAAI,SAAS,CAAC;AAClC,CAAC,CAAC;AAEF,gEAAgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAc,EAAE,CAAC,WAAW,CAAC;AAEzD,yFAAyF;AACzF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAkB,WAAW,EAAW,EAAE,CAC1E,IAAI,KAAK,SAAS,CAAC;AAErB,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,GAAS,EAAE;IACvC,WAAW,GAAG,SAAS,CAAC;AAC1B,CAAC,CAAC;AAmBF,qDAAqD;AACrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAiC,EACpB,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rB,EAAE,CAAC,CAAC;IACjB,GAAG,MAAM;IACT,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;IACnB,aAAa;IACb,MAAM;CACP,CAAC,CAAC;AAEH,gDAAgD;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,IAAe,EACf,MAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,yDAAyD;IAC3D,CAAC;AACH,CAAC,CAAC"}
@@ -1,16 +0,0 @@
1
- import { Database } from 'bun:sqlite';
2
- export interface TrailsDbLocationOptions {
3
- readonly path?: string;
4
- readonly rootDir?: string;
5
- }
6
- export interface EnsureSubsystemSchemaOptions {
7
- readonly migrate: (currentVersion: number) => void;
8
- readonly subsystem: string;
9
- readonly version: number;
10
- }
11
- export declare const deriveTrailsDir: (options?: TrailsDbLocationOptions) => string;
12
- export declare const deriveTrailsDbPath: (options?: TrailsDbLocationOptions) => string;
13
- export declare const openWriteTrailsDb: (options?: TrailsDbLocationOptions) => Database;
14
- export declare const openReadTrailsDb: (options?: TrailsDbLocationOptions) => Database;
15
- export declare const ensureSubsystemSchema: (db: Database, options: EnsureSubsystemSchemaOptions) => void;
16
- //# sourceMappingURL=trails-db.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trails-db.d.ts","sourceRoot":"","sources":["../../src/internal/trails-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA2BtC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,OAAO,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AASD,eAAO,MAAM,eAAe,GAAI,UAAU,uBAAuB,KAAG,MACjB,CAAC;AAEpD,eAAO,MAAM,kBAAkB,GAAI,UAAU,uBAAuB,KAAG,MAGnB,CAAC;AAsFrD,eAAO,MAAM,iBAAiB,GAC5B,UAAU,uBAAuB,KAChC,QAgBF,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,UAAU,uBAAuB,KAChC,QAUF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,IAAI,QAAQ,EACZ,SAAS,4BAA4B,KACpC,IAYF,CAAC"}
@@ -1,118 +0,0 @@
1
- import { Database } from 'bun:sqlite';
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
- import { dirname, join, resolve } from 'node:path';
4
- import { NotFoundError } from '../errors.js';
5
- const TRAILS_DIR = '.trails';
6
- const TRAILS_DB_FILE = 'trails.db';
7
- const SCHEMA_VERSION_TABLE = 'meta_schema_versions';
8
- const WORKSPACE_SUBDIRS = ['config', 'dev', 'generated'];
9
- const REQUIRED_GITIGNORE_LINES = [
10
- '# Local config overrides',
11
- 'config/',
12
- '',
13
- '# Development state',
14
- 'dev/',
15
- '',
16
- '# Generated artifacts',
17
- 'generated/',
18
- '',
19
- '# Shared Trails database',
20
- 'trails.db',
21
- 'trails.db-shm',
22
- 'trails.db-wal',
23
- '',
24
- ];
25
- const deriveRootDir = (rootDir) => resolve(rootDir ?? process.cwd());
26
- export const deriveTrailsDir = (options) => join(deriveRootDir(options?.rootDir), TRAILS_DIR);
27
- export const deriveTrailsDbPath = (options) => options?.path
28
- ? resolve(options.path)
29
- : join(deriveTrailsDir(options), TRAILS_DB_FILE);
30
- const ensureDbParentDir = (dbPath) => {
31
- mkdirSync(dirname(dbPath), { recursive: true });
32
- };
33
- const GITIGNORE_TEMPLATE = `${REQUIRED_GITIGNORE_LINES.join('\n').trimEnd()}\n`;
34
- const appendMissingGitignoreLines = (gitignorePath, content) => {
35
- const existingLines = new Set(content.split('\n').map((l) => l.trim()));
36
- const missing = REQUIRED_GITIGNORE_LINES.filter((line) => line !== '' && !existingLines.has(line));
37
- if (missing.length === 0) {
38
- return;
39
- }
40
- const next = `${content.trimEnd()}\n\n${missing.join('\n')}`;
41
- writeFileSync(gitignorePath, `${next.trimEnd()}\n`);
42
- };
43
- const ensureWorkspaceGitignore = (trailsDir) => {
44
- const gitignorePath = join(trailsDir, '.gitignore');
45
- if (!existsSync(gitignorePath)) {
46
- writeFileSync(gitignorePath, GITIGNORE_TEMPLATE);
47
- return;
48
- }
49
- appendMissingGitignoreLines(gitignorePath, readFileSync(gitignorePath, 'utf8'));
50
- };
51
- const ensureWorkspaceDir = (rootDir) => {
52
- const trailsDir = deriveTrailsDir({ rootDir });
53
- mkdirSync(trailsDir, { recursive: true });
54
- for (const subdir of WORKSPACE_SUBDIRS) {
55
- mkdirSync(join(trailsDir, subdir), { recursive: true });
56
- }
57
- ensureWorkspaceGitignore(trailsDir);
58
- };
59
- const initializeWritePragmas = (db) => {
60
- db.run('PRAGMA journal_mode = WAL');
61
- db.run('PRAGMA synchronous = NORMAL');
62
- db.run('PRAGMA foreign_keys = ON');
63
- };
64
- const ensureSchemaVersionTable = (db) => {
65
- db.run(`CREATE TABLE IF NOT EXISTS ${SCHEMA_VERSION_TABLE} (
66
- subsystem TEXT PRIMARY KEY,
67
- version INTEGER NOT NULL,
68
- updated_at TEXT NOT NULL
69
- )`);
70
- };
71
- const readSubsystemVersion = (db, subsystem) => {
72
- const row = db
73
- .query(`SELECT version FROM ${SCHEMA_VERSION_TABLE} WHERE subsystem = ?`)
74
- .get(subsystem);
75
- return row?.version ?? 0;
76
- };
77
- const writeSubsystemVersion = (db, subsystem, version) => {
78
- db.run(`INSERT INTO ${SCHEMA_VERSION_TABLE} (subsystem, version, updated_at)
79
- VALUES (?, ?, ?)
80
- ON CONFLICT(subsystem) DO UPDATE SET
81
- version = excluded.version,
82
- updated_at = excluded.updated_at`, [subsystem, version, new Date().toISOString()]);
83
- };
84
- export const openWriteTrailsDb = (options) => {
85
- const rootDir = deriveRootDir(options?.rootDir);
86
- const dbPath = deriveTrailsDbPath(options?.path ? { path: options.path, rootDir } : { rootDir });
87
- if (options?.path === undefined) {
88
- ensureWorkspaceDir(rootDir);
89
- }
90
- else {
91
- ensureDbParentDir(dbPath);
92
- }
93
- const db = new Database(dbPath, { create: true });
94
- initializeWritePragmas(db);
95
- ensureSchemaVersionTable(db);
96
- return db;
97
- };
98
- export const openReadTrailsDb = (options) => {
99
- const dbPath = deriveTrailsDbPath(options);
100
- if (!existsSync(dbPath)) {
101
- throw new NotFoundError(`Trails database not found at "${dbPath}". Run a write operation first to initialize it.`);
102
- }
103
- const db = new Database(dbPath, { readonly: true });
104
- db.run('PRAGMA foreign_keys = ON');
105
- return db;
106
- };
107
- export const ensureSubsystemSchema = (db, options) => {
108
- ensureSchemaVersionTable(db);
109
- db.transaction(() => {
110
- const currentVersion = readSubsystemVersion(db, options.subsystem);
111
- if (currentVersion >= options.version) {
112
- return;
113
- }
114
- options.migrate(currentVersion);
115
- writeSubsystemVersion(db, options.subsystem, options.version);
116
- })();
117
- };
118
- //# sourceMappingURL=trails-db.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trails-db.js","sourceRoot":"","sources":["../../src/internal/trails-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,cAAc,GAAG,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OAAO,CAAC,CAAC;IAChE,CAAC,CAAC,EAAE,CAAC;AACP,CAAC,CAAC"}
@@ -1,40 +0,0 @@
1
- /**
2
- * Shared Zod wrapper helpers.
3
- *
4
- * These helpers walk the wrapper layers of a Zod schema (default, optional,
5
- * nullable) and rebuild the schema without any default wrappers so that
6
- * downstream `.partial()` calls do not silently re-materialize defaults during
7
- * validation. Both `@ontrails/core/trails/derive-trail.ts` and
8
- * `@ontrails/store/src/store.ts` previously shipped near-identical copies of
9
- * this walk — extracting them here keeps the wrapper semantics authored in one
10
- * place so the two call sites cannot drift.
11
- *
12
- * Canonical behavior: `optional` wrappers are intentionally dropped. Every
13
- * current call site applies `.partial()` to the stripped schema, which
14
- * re-introduces `optional` across the whole shape. Preserving `optional` here
15
- * would be redundant at best and would produce an `OptionalOptional<T>` shape
16
- * in edge cases at worst. `nullable` wrappers are preserved because nullability
17
- * is a semantic constraint that `.partial()` does not reintroduce.
18
- *
19
- * @internal
20
- */
21
- import type { z } from 'zod';
22
- /**
23
- * Strip `default` wrappers from a Zod type so that partial update schemas do
24
- * not silently re-materialize defaults. Walks through all wrapper layers
25
- * (`default`, `optional`, `nullable`), drops defaults, drops `optional` (the
26
- * downstream `.partial()` reintroduces it across the whole shape), and
27
- * preserves `nullable` so explicit nullability survives.
28
- *
29
- * @internal
30
- */
31
- export declare const stripDefaultWrappers: (schema: z.ZodType) => z.ZodType;
32
- /**
33
- * Apply {@link stripDefaultWrappers} to every field in a Zod object shape and
34
- * return the resulting shape record. Callers typically feed the result to
35
- * `.extend()` + `.partial()`.
36
- *
37
- * @internal
38
- */
39
- export declare const stripDefaultsFromShape: (schema: z.ZodType) => Record<string, z.ZodType>;
40
- //# sourceMappingURL=zod-wrappers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod-wrappers.d.ts","sourceRoot":"","sources":["../../src/internal/zod-wrappers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAU7B;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,OAY1D,CAAC;AAOF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,CAAC,CAAC,OAAO,KAChB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAS1B,CAAC"}
@@ -1,59 +0,0 @@
1
- /**
2
- * Shared Zod wrapper helpers.
3
- *
4
- * These helpers walk the wrapper layers of a Zod schema (default, optional,
5
- * nullable) and rebuild the schema without any default wrappers so that
6
- * downstream `.partial()` calls do not silently re-materialize defaults during
7
- * validation. Both `@ontrails/core/trails/derive-trail.ts` and
8
- * `@ontrails/store/src/store.ts` previously shipped near-identical copies of
9
- * this walk — extracting them here keeps the wrapper semantics authored in one
10
- * place so the two call sites cannot drift.
11
- *
12
- * Canonical behavior: `optional` wrappers are intentionally dropped. Every
13
- * current call site applies `.partial()` to the stripped schema, which
14
- * re-introduces `optional` across the whole shape. Preserving `optional` here
15
- * would be redundant at best and would produce an `OptionalOptional<T>` shape
16
- * in edge cases at worst. `nullable` wrappers are preserved because nullability
17
- * is a semantic constraint that `.partial()` does not reintroduce.
18
- *
19
- * @internal
20
- */
21
- const isWrapperType = (type) => type === 'default' || type === 'nullable' || type === 'optional';
22
- const readInnerType = (schema) => schema.def.innerType;
23
- /**
24
- * Strip `default` wrappers from a Zod type so that partial update schemas do
25
- * not silently re-materialize defaults. Walks through all wrapper layers
26
- * (`default`, `optional`, `nullable`), drops defaults, drops `optional` (the
27
- * downstream `.partial()` reintroduces it across the whole shape), and
28
- * preserves `nullable` so explicit nullability survives.
29
- *
30
- * @internal
31
- */
32
- export const stripDefaultWrappers = (schema) => {
33
- let current = schema;
34
- let isNullable = false;
35
- while (isWrapperType(current.def.type)) {
36
- if (current.def.type === 'nullable') {
37
- isNullable = true;
38
- }
39
- current = readInnerType(current);
40
- }
41
- return isNullable ? current.nullable() : current;
42
- };
43
- const asObjectSchema = (schema) => schema;
44
- /**
45
- * Apply {@link stripDefaultWrappers} to every field in a Zod object shape and
46
- * return the resulting shape record. Callers typically feed the result to
47
- * `.extend()` + `.partial()`.
48
- *
49
- * @internal
50
- */
51
- export const stripDefaultsFromShape = (schema) => {
52
- const stripped = {};
53
- const objectSchema = asObjectSchema(schema);
54
- for (const [field, value] of Object.entries(objectSchema.shape)) {
55
- stripped[field] = stripDefaultWrappers(value);
56
- }
57
- return stripped;
58
- };
59
- //# sourceMappingURL=zod-wrappers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod-wrappers.js","sourceRoot":"","sources":["../../src/internal/zod-wrappers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,aAAa,GAAG,CACpB,IAAY,EACiC,EAAE,CAC/C,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,UAAU,CAAC;AAEnE,MAAM,aAAa,GAAG,CAAC,MAAiB,EAAa,EAAE,CACpD,MAAM,CAAC,GAA2C,CAAC,SAAS,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAiB,EAAa,EAAE;IACnE,IAAI,OAAO,GAAG,MAAM,CAAC;IACrB,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,OAAO,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACpC,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACnD,CAAC,CAAC;AAIF,MAAM,cAAc,GAAG,CAAC,MAAiB,EAAmB,EAAE,CAC5D,MAAoC,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,MAAiB,EACU,EAAE;IAC7B,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAC/C,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAE5C,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,QAAQ,CAAC,KAAK,CAAC,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
package/dist/layer.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { AnyTrail } from './trail.js';
2
- import type { Implementation } from './types.js';
3
- /** A composable layer that wraps trail implementations. */
4
- export interface Layer {
5
- readonly name: string;
6
- readonly description?: string | undefined;
7
- /**
8
- * Wrap a trail's implementation, returning a new implementation.
9
- *
10
- * The trail is passed for metadata inspection (intent, schema, etc.).
11
- * The implementation and return type are generic over the input/output
12
- * types so layers remain type-safe when composed.
13
- */
14
- wrap<I, O>(trail: AnyTrail, implementation: Implementation<I, O>): Implementation<I, O>;
15
- }
16
- /**
17
- * Apply layers outermost-first: layers[0] wraps layers[1] wraps ... wraps
18
- * the base implementation.
19
- *
20
- * An empty layers array returns the implementation unchanged.
21
- */
22
- export declare const composeLayers: <I, O>(layers: readonly Layer[], trail: AnyTrail, implementation: Implementation<I, O>) => Implementation<I, O>;
23
- //# sourceMappingURL=layer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer.d.ts","sourceRoot":"","sources":["../src/layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD,2DAA2D;AAC3D,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1C;;;;;;OAMG;IACH,IAAI,CAAC,CAAC,EAAE,CAAC,EACP,KAAK,EAAE,QAAQ,EACf,cAAc,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GACnC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACzB;AAMD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,EAChC,QAAQ,SAAS,KAAK,EAAE,EACxB,OAAO,QAAQ,EACf,gBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,KACnC,cAAc,CAAC,CAAC,EAAE,CAAC,CAUrB,CAAC"}
package/dist/layer.js DELETED
@@ -1,21 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Composition
3
- // ---------------------------------------------------------------------------
4
- /**
5
- * Apply layers outermost-first: layers[0] wraps layers[1] wraps ... wraps
6
- * the base implementation.
7
- *
8
- * An empty layers array returns the implementation unchanged.
9
- */
10
- export const composeLayers = (layers, trail, implementation) => {
11
- // Fold right so layers[0] is the outermost wrapper.
12
- let result = implementation;
13
- for (let i = layers.length - 1; i >= 0; i -= 1) {
14
- const layer = layers[i];
15
- if (layer) {
16
- result = layer.wrap(trail, result);
17
- }
18
- }
19
- return result;
20
- };
21
- //# sourceMappingURL=layer.js.map
package/dist/layer.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer.js","sourceRoot":"","sources":["../src/layer.ts"],"names":[],"mappings":"AAyBA,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAwB,EACxB,KAAe,EACf,cAAoC,EACd,EAAE;IACxB,oDAAoD;IACpD,IAAI,MAAM,GAAG,cAAc,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -1,28 +0,0 @@
1
- /**
2
- * Path security utilities for preventing path traversal attacks.
3
- *
4
- * All functions are runtime-agnostic (Node / Bun compatible).
5
- */
6
- import { PermissionError } from './errors.js';
7
- import { Result } from './result.js';
8
- /**
9
- * Resolves `userPath` relative to `basePath` and ensures it stays within
10
- * the base directory. Returns the resolved absolute path on success, or a
11
- * `PermissionError` if the path escapes.
12
- *
13
- * Uses lexical path comparison (not `realpath`). Does not follow symlinks —
14
- * if an attacker can create symlinks inside `basePath`, those could point
15
- * outside the base. Use `realpath` before calling in symlink-sensitive environments.
16
- */
17
- export declare const securePath: (basePath: string, userPath: string) => Result<string, PermissionError>;
18
- /**
19
- * Returns `true` if `userPath` (resolved against `basePath`) stays within
20
- * `basePath`.
21
- */
22
- export declare const isPathSafe: (basePath: string, userPath: string) => boolean;
23
- /**
24
- * Joins multiple path segments, resolves them against `basePath`, and
25
- * validates the result stays within the base directory.
26
- */
27
- export declare const deriveSafePath: (basePath: string, ...segments: string[]) => Result<string, PermissionError>;
28
- //# sourceMappingURL=path-security.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-security.d.ts","sourceRoot":"","sources":["../src/path-security.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAmBrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,MAAM,CAAC,MAAM,EAAE,eAAe,CAgBhC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,EAAE,UAAU,MAAM,KAAG,OAI/D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,GAAG,UAAU,MAAM,EAAE,KACpB,MAAM,CAAC,MAAM,EAAE,eAAe,CAchC,CAAC"}
@@ -1,63 +0,0 @@
1
- /**
2
- * Path security utilities for preventing path traversal attacks.
3
- *
4
- * All functions are runtime-agnostic (Node / Bun compatible).
5
- */
6
- import { resolve, relative, normalize, isAbsolute } from 'node:path';
7
- import { PermissionError } from './errors.js';
8
- import { Result } from './result.js';
9
- // ---------------------------------------------------------------------------
10
- // Internal
11
- // ---------------------------------------------------------------------------
12
- /** Returns true when `target` is equal to or a descendant of `base`. */
13
- const isWithin = (base, target) => {
14
- const rel = relative(base, target);
15
- // Empty string means they are the same directory.
16
- // A relative path starting with ".." means it escapes.
17
- // An absolute path means a completely different tree.
18
- return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
19
- };
20
- // ---------------------------------------------------------------------------
21
- // Public API
22
- // ---------------------------------------------------------------------------
23
- /**
24
- * Resolves `userPath` relative to `basePath` and ensures it stays within
25
- * the base directory. Returns the resolved absolute path on success, or a
26
- * `PermissionError` if the path escapes.
27
- *
28
- * Uses lexical path comparison (not `realpath`). Does not follow symlinks —
29
- * if an attacker can create symlinks inside `basePath`, those could point
30
- * outside the base. Use `realpath` before calling in symlink-sensitive environments.
31
- */
32
- export const securePath = (basePath, userPath) => {
33
- const base = resolve(basePath);
34
- const resolved = resolve(base, userPath);
35
- if (!isWithin(base, resolved)) {
36
- return Result.err(new PermissionError(`Path traversal detected: "${userPath}" escapes "${basePath}"`, {
37
- context: { basePath: base, resolved, userPath },
38
- }));
39
- }
40
- return Result.ok(resolved);
41
- };
42
- /**
43
- * Returns `true` if `userPath` (resolved against `basePath`) stays within
44
- * `basePath`.
45
- */
46
- export const isPathSafe = (basePath, userPath) => {
47
- const base = resolve(basePath);
48
- const resolved = resolve(base, userPath);
49
- return isWithin(base, resolved);
50
- };
51
- /**
52
- * Joins multiple path segments, resolves them against `basePath`, and
53
- * validates the result stays within the base directory.
54
- */
55
- export const deriveSafePath = (basePath, ...segments) => {
56
- const base = resolve(basePath);
57
- const joined = resolve(base, ...segments.map((s) => normalize(s)));
58
- if (!isWithin(base, joined)) {
59
- return Result.err(new PermissionError(`Path traversal detected: segments escape "${basePath}"`, { context: { basePath: base, resolved: joined, segments } }));
60
- }
61
- return Result.ok(joined);
62
- };
63
- //# sourceMappingURL=path-security.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-security.js","sourceRoot":"","sources":["../src/path-security.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,8EAA8E;AAC9E,WAAW;AACX,8EAA8E;AAE9E,wEAAwE;AACxE,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,MAAc,EAAW,EAAE;IACzD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,kDAAkD;IAClD,uDAAuD;IACvD,sDAAsD;IACtD,OAAO,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,CAAC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AAe,CACjB,6CAA6C,QAAQ,GAAG,EACxD,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAC5D,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC,CAAC"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Bulk operation schema helpers for @ontrails/core/patterns
3
- */
4
- import { z } from 'zod';
5
- /** Bulk operation output wrapper for a given item schema. */
6
- export declare const bulkOutput: <T>(itemSchema: z.ZodType<T>) => z.ZodObject<{
7
- errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
8
- index: z.ZodNumber;
9
- message: z.ZodString;
10
- }, z.core.$strip>>>;
11
- failed: z.ZodNumber;
12
- items: z.ZodArray<z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>>;
13
- succeeded: z.ZodNumber;
14
- }, z.core.$strip>;
15
- //# sourceMappingURL=bulk.d.ts.map