@ontrails/core 1.0.0-beta.0 → 1.0.0-beta.10
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.
- package/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +109 -0
- package/README.md +101 -131
- package/dist/derive.d.ts +1 -1
- package/dist/derive.d.ts.map +1 -1
- package/dist/derive.js +4 -1
- package/dist/derive.js.map +1 -1
- package/dist/dispatch.d.ts +27 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +34 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/event.d.ts +2 -2
- package/dist/event.d.ts.map +1 -1
- package/dist/event.js +1 -1
- package/dist/event.js.map +1 -1
- package/dist/execute.d.ts +30 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +64 -0
- package/dist/execute.js.map +1 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/patterns/status.d.ts +1 -1
- package/dist/result.d.ts +11 -11
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +15 -4
- package/dist/result.js.map +1 -1
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +45 -7
- package/dist/serialization.js.map +1 -1
- package/dist/topo.d.ts +4 -4
- package/dist/topo.d.ts.map +1 -1
- package/dist/topo.js +12 -16
- package/dist/topo.js.map +1 -1
- package/dist/trail.d.ts +16 -10
- package/dist/trail.d.ts.map +1 -1
- package/dist/trail.js +4 -2
- package/dist/trail.js.map +1 -1
- package/dist/type-utils.d.ts +24 -0
- package/dist/type-utils.d.ts.map +1 -0
- package/dist/type-utils.js +12 -0
- package/dist/type-utils.js.map +1 -0
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/validate-topo.d.ts +2 -2
- package/dist/validate-topo.d.ts.map +1 -1
- package/dist/validate-topo.js +59 -9
- package/dist/validate-topo.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/context.test.ts +4 -5
- package/src/__tests__/derive.test.ts +44 -0
- package/src/__tests__/dispatch.test.ts +154 -0
- package/src/__tests__/event.test.ts +5 -5
- package/src/__tests__/execute.test.ts +208 -0
- package/src/__tests__/layer.test.ts +11 -111
- package/src/__tests__/serialization.test.ts +166 -1
- package/src/__tests__/topo.test.ts +101 -79
- package/src/__tests__/trail.test.ts +73 -35
- package/src/__tests__/type-utils.test.ts +90 -0
- package/src/__tests__/validate-topo.test.ts +97 -20
- package/src/derive.ts +12 -2
- package/src/dispatch.ts +54 -0
- package/src/event.ts +3 -3
- package/src/execute.ts +96 -0
- package/src/index.ts +22 -18
- package/src/result.ts +29 -15
- package/src/serialization.ts +56 -11
- package/src/topo.ts +18 -23
- package/src/trail.ts +24 -13
- package/src/type-utils.ts +45 -0
- package/src/types.ts +1 -3
- package/src/validate-topo.ts +70 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/hike.d.ts +0 -36
- package/dist/hike.d.ts.map +0 -1
- package/dist/hike.js +0 -20
- package/dist/hike.js.map +0 -1
- package/src/__tests__/hike.test.ts +0 -117
- package/src/__tests__/job.test.ts +0 -98
- package/src/adapters.ts +0 -68
- package/src/health.ts +0 -23
- package/src/hike.ts +0 -77
- package/src/job.ts +0 -20
package/.turbo/turbo-lint.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,114 @@
|
|
|
1
1
|
# @ontrails/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.10
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Cleanup and hardening pass across all packages.
|
|
8
|
+
|
|
9
|
+
**core**: Deduplicate `DispatchOptions` as type alias of `ExecuteTrailOptions`. Replace `TrailContext` index signature with typed `extensions` field for type safety. Deep-merge `extensions` in `executeTrail` context resolution. Remove unused `Surface` type, `adapters.ts`, `health.ts`, and `job.ts` proof-of-concept from published package.
|
|
10
|
+
|
|
11
|
+
**cli**: Remove vestigial `kind` checks from build. Run `validateTopo()` automatically in `blaze()` with opt-out via `validate: false`.
|
|
12
|
+
|
|
13
|
+
**http**: Remove vestigial `kind` checks from build. Run `validateTopo()` automatically in `blaze()` with opt-out.
|
|
14
|
+
|
|
15
|
+
**mcp**: Remove vestigial `kind` checks from build. Run `validateTopo()` automatically in `blaze()` with opt-out.
|
|
16
|
+
|
|
17
|
+
**warden**: Project-aware rule context preserved in trail wrappers.
|
|
18
|
+
|
|
19
|
+
## 1.0.0-beta.9
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- Consolidated improvements across all surface packages.
|
|
24
|
+
|
|
25
|
+
**core**: Add `TrailResult<T>` utility type, `topo.ids()` and `topo.count` accessors, `dispatch()` for headless trail execution, and extract shared `executeTrail` pipeline used by CLI/MCP/HTTP.
|
|
26
|
+
|
|
27
|
+
**http**: Detect route path collisions and return `Result` from `buildHttpRoutes()`, wire request `AbortSignal` through to trail context, and make write → POST mapping explicit in intent-to-method lookup.
|
|
28
|
+
|
|
29
|
+
**mcp**: Return `Result` from `buildMcpTools()` on collision instead of throwing.
|
|
30
|
+
|
|
31
|
+
**cli**: Verify exception catching via centralized `executeTrail`.
|
|
32
|
+
|
|
33
|
+
**testing**: Follow context awareness improvements.
|
|
34
|
+
|
|
35
|
+
**warden**: Refactor rules as composable trails with examples.
|
|
36
|
+
|
|
37
|
+
**schema**: Error code and empty body fixes.
|
|
38
|
+
|
|
39
|
+
## 1.0.0-beta.8
|
|
40
|
+
|
|
41
|
+
## 1.0.0-beta.7
|
|
42
|
+
|
|
43
|
+
## 1.0.0-beta.6
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Fix Codex review findings on type-utils and follow-declarations.
|
|
48
|
+
|
|
49
|
+
**core**: `inputOf()`/`outputOf()` now preserve the exact Zod schema subtype instead of widening to `z.ZodType`.
|
|
50
|
+
|
|
51
|
+
**warden**: `follow-declarations` rule now recognizes single-object trail overload, detects any context parameter name (not just `ctx`), matches destructured `follow()` calls, resolves const identifiers in `follow` arrays, and restricts run body extraction to top-level config properties.
|
|
52
|
+
|
|
53
|
+
## 1.0.0-beta.5
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- Type utilities and follow-declarations warden rule.
|
|
58
|
+
|
|
59
|
+
**core**: Add `TrailInput<T>`, `TrailOutput<T>` utility types and `inputOf()`, `outputOf()` runtime schema accessors.
|
|
60
|
+
|
|
61
|
+
**warden**: Add `follow-declarations` rule — statically analyzes `ctx.follow()` calls against declared `follow: [...]` arrays. Errors on undeclared calls, warns on unused declarations.
|
|
62
|
+
|
|
63
|
+
## 1.0.0-beta.4
|
|
64
|
+
|
|
65
|
+
### Major Changes
|
|
66
|
+
|
|
67
|
+
- API simplification: unified trail model, intent enum, run, metadata.
|
|
68
|
+
|
|
69
|
+
**BREAKING CHANGES:**
|
|
70
|
+
|
|
71
|
+
- `hike()` removed — use `trail()` with optional `follow: [...]` field
|
|
72
|
+
- `follows` renamed to `follow` (singular, matching `ctx.follow()`)
|
|
73
|
+
- `topo.hikes` removed — single `topo.trails` map
|
|
74
|
+
- `kind: 'hike'` removed — everything is `kind: 'trail'`
|
|
75
|
+
- `readOnly`/`destructive` booleans replaced by `intent: 'read' | 'write' | 'destroy'`
|
|
76
|
+
- `implementation` field renamed to `run`
|
|
77
|
+
- `markers` field renamed to `metadata`
|
|
78
|
+
- `testHike` renamed to `testFollows`, `HikeScenario` to `FollowScenario`
|
|
79
|
+
- `blaze()` now returns the surface handle (`Command` for CLI, `Server` for MCP)
|
|
80
|
+
|
|
81
|
+
## 1.0.0-beta.3
|
|
82
|
+
|
|
83
|
+
### Minor Changes
|
|
84
|
+
|
|
85
|
+
- Bug fixes across all surface packages found via parallel Codex review.
|
|
86
|
+
|
|
87
|
+
**core**: Fix Result.toJson false circular detection on DAGs, deserializeError subclass round-trip, topo cross-kind ID collisions, validateTopo multi-node cycle detection, error example input validation bypass, and deriveFields array type collapse.
|
|
88
|
+
|
|
89
|
+
**cli**: Switch blaze to parseAsync for proper async error handling, add boolean flag negation (--no-flag), and strict number parsing that rejects partial input.
|
|
90
|
+
|
|
91
|
+
**mcp**: Align BlobRef with core (including ReadableStream support) and detect tool-name collisions after normalization.
|
|
92
|
+
|
|
93
|
+
**testing**: Include hikes in testContracts validation, with follow-context awareness.
|
|
94
|
+
|
|
95
|
+
**warden**: Collect hike detour targets, validate detour refs in hike specs, and stop implementation-returns-result from walking into nested function bodies.
|
|
96
|
+
|
|
97
|
+
## 1.0.0-beta.2
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- Fix workspace dependency resolution in published packages. Now using bun publish
|
|
102
|
+
which correctly replaces workspace:^ with actual version numbers.
|
|
103
|
+
|
|
104
|
+
## 1.0.0-beta.1
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- Fix two blocking bugs from real-world migration:
|
|
109
|
+
- Published packages now resolve correctly (workspace:^ instead of workspace:\*)
|
|
110
|
+
- Error forwarding works across different success types (Err no longer carries phantom T)
|
|
111
|
+
|
|
3
112
|
## 1.0.0-beta.0
|
|
4
113
|
|
|
5
114
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,179 +1,149 @@
|
|
|
1
1
|
# @ontrails/core
|
|
2
2
|
|
|
3
|
-
The foundation
|
|
3
|
+
The foundation. Define trails, compose them into topos, return typed Results, and let the framework derive everything else.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun add @ontrails/core
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
5
|
+
## Usage
|
|
12
6
|
|
|
13
7
|
```typescript
|
|
14
|
-
import { trail,
|
|
8
|
+
import { trail, topo, Result } from '@ontrails/core';
|
|
15
9
|
import { z } from 'zod';
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readOnly: true,
|
|
11
|
+
const greet = trail('greet', {
|
|
12
|
+
input: z.object({ name: z.string().describe('Who to greet') }),
|
|
13
|
+
output: z.object({ message: z.string() }),
|
|
14
|
+
intent: 'read',
|
|
22
15
|
examples: [
|
|
23
|
-
{
|
|
24
|
-
name: 'Show an entity',
|
|
25
|
-
input: { name: 'Alpha' },
|
|
26
|
-
expected: { name: 'Alpha', type: 'concept' },
|
|
27
|
-
},
|
|
16
|
+
{ name: 'Hello', input: { name: 'World' }, expected: { message: 'Hello, World!' } },
|
|
28
17
|
],
|
|
29
|
-
|
|
18
|
+
run: (input) => Result.ok({ message: `Hello, ${input.name}!` }),
|
|
30
19
|
});
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
const app = topo('myapp', { greet });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Trails compose other trails through `follow` and `ctx.follow()`:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const onboard = trail('entity.onboard', {
|
|
28
|
+
follow: ['entity.add', 'entity.relate'],
|
|
35
29
|
input: z.object({ name: z.string(), type: z.string() }),
|
|
36
|
-
|
|
30
|
+
run: async (input, ctx) => {
|
|
37
31
|
const added = await ctx.follow('entity.add', input);
|
|
38
32
|
if (added.isErr()) return added;
|
|
39
33
|
return Result.ok({ entity: added.value });
|
|
40
34
|
},
|
|
41
35
|
});
|
|
42
|
-
|
|
43
|
-
// Collect into an app
|
|
44
|
-
import * as entity from './trails/entity';
|
|
45
|
-
const app = topo('myapp', entity);
|
|
46
36
|
```
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## API Overview
|
|
38
|
+
## API
|
|
51
39
|
|
|
52
|
-
### Trail
|
|
40
|
+
### Trail primitives
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
| Export | What it does |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `trail(id, spec)` | Define a unit of work with typed input and `Result` output; use `follow` for composition |
|
|
45
|
+
| `event(id, spec)` | Define a server-originated push with a typed data schema |
|
|
46
|
+
| `topo(name, ...modules)` | Collect trail modules into a queryable topology |
|
|
47
|
+
| `validateTopo(topo)` | Structural validation: follow targets exist, no cycles, examples parse, output schemas present |
|
|
58
48
|
|
|
59
|
-
###
|
|
49
|
+
### Execution
|
|
60
50
|
|
|
61
|
-
|
|
51
|
+
| Export | What it does |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `executeTrail(trail, rawInput, options?)` | Centralized execution pipeline: validates input, builds context, composes layers, runs the implementation. Never throws -- exceptions become `Result.err(InternalError)`. |
|
|
54
|
+
| `dispatch(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. |
|
|
62
55
|
|
|
63
56
|
```typescript
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Result.combine(results); // Collect Result<T>[] into Result<T[]>
|
|
67
|
-
|
|
68
|
-
result.isOk(); // Type guard for Ok
|
|
69
|
-
result.isErr(); // Type guard for Err
|
|
70
|
-
result.map(fn); // Transform success value
|
|
71
|
-
result.flatMap(fn); // Chain Result-returning functions
|
|
72
|
-
result.match({ ok, err }); // Pattern match
|
|
73
|
-
result.unwrapOr(fallback); // Value or fallback
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Implementations return `Result`, never `throw`.
|
|
57
|
+
// executeTrail — surface adapters use this directly
|
|
58
|
+
const result = await executeTrail(greet, { name: 'Alice' });
|
|
77
59
|
|
|
78
|
-
|
|
60
|
+
// dispatch — no-surface execution by trail ID
|
|
61
|
+
const result = await dispatch(app, 'greet', { name: 'Alice' });
|
|
62
|
+
if (result.isOk()) console.log(result.value);
|
|
63
|
+
```
|
|
79
64
|
|
|
80
|
-
|
|
65
|
+
### Topo accessors
|
|
81
66
|
|
|
82
|
-
|
|
83
|
-
| --- | --- | --- | --- | --- |
|
|
84
|
-
| `validation` | `ValidationError`, `AmbiguousError`, `AssertionError` | 1 | 400 | No |
|
|
85
|
-
| `not_found` | `NotFoundError` | 2 | 404 | No |
|
|
86
|
-
| `conflict` | `AlreadyExistsError`, `ConflictError` | 3 | 409 | No |
|
|
87
|
-
| `permission` | `PermissionError` | 4 | 403 | No |
|
|
88
|
-
| `timeout` | `TimeoutError` | 5 | 504 | Yes |
|
|
89
|
-
| `rate_limit` | `RateLimitError` | 6 | 429 | Yes |
|
|
90
|
-
| `network` | `NetworkError` | 7 | 502 | Yes |
|
|
91
|
-
| `internal` | `InternalError` | 8 | 500 | No |
|
|
92
|
-
| `auth` | `AuthError` | 9 | 401 | No |
|
|
93
|
-
| `cancelled` | `CancelledError` | 130 | 499 | No |
|
|
67
|
+
Beyond the `trail(id, spec)` builder, `Topo` exposes these accessors:
|
|
94
68
|
|
|
95
|
-
|
|
69
|
+
| Accessor | What it returns |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `topo.ids()` | `string[]` of all registered trail IDs |
|
|
72
|
+
| `topo.count` | Number of registered trails |
|
|
73
|
+
| `topo.get(id)` | The `Trail` with that ID, or `undefined` |
|
|
74
|
+
| `topo.has(id)` | Whether a trail ID is registered |
|
|
75
|
+
| `topo.list()` | All registered trails as an array |
|
|
96
76
|
|
|
97
|
-
###
|
|
77
|
+
### Type utilities
|
|
98
78
|
|
|
99
|
-
|
|
79
|
+
| Export | What it does |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `TrailInput<T>` | Extract the input type from a `Trail` |
|
|
82
|
+
| `TrailOutput<T>` | Extract the output type from a `Trail` |
|
|
83
|
+
| `TrailResult<T>` | `Result<TrailOutput<T>, Error>` -- the Result type for a trail's output |
|
|
84
|
+
| `inputOf(trail)` | Get the input Zod schema from a trail instance |
|
|
85
|
+
| `outputOf(trail)` | Get the output Zod schema (or `undefined`) from a trail instance |
|
|
100
86
|
|
|
101
|
-
|
|
102
|
-
- **Bulk operations** -- `bulkInput`, `bulkOutput` (batch with per-item results)
|
|
103
|
-
- **Timestamps** -- `timestamps` (`createdAt`/`updatedAt`)
|
|
104
|
-
- **Date ranges** -- `dateRangeInput` (`since`/`until`)
|
|
105
|
-
- **Sorting** -- `sortInput` (`sortBy`/`sortOrder`)
|
|
106
|
-
- **Status** -- `statusField` (lifecycle state)
|
|
107
|
-
- **Change tracking** -- `changeOutput` (before/after snapshots)
|
|
108
|
-
- **Progress** -- `progressOutput` (completion reporting)
|
|
87
|
+
### Execution option types
|
|
109
88
|
|
|
110
|
-
|
|
89
|
+
| Type | What it describes |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `ExecuteTrailOptions` | Options for `executeTrail`: `ctx`, `signal`, `layers`, `createContext` |
|
|
92
|
+
| `DispatchOptions` | Same shape as `ExecuteTrailOptions`; forwarded by `dispatch` |
|
|
111
93
|
|
|
112
|
-
|
|
94
|
+
### Result
|
|
113
95
|
|
|
114
96
|
```typescript
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
97
|
+
Result.ok(value); // Success
|
|
98
|
+
Result.err(error); // Failure
|
|
99
|
+
Result.combine(results); // Result<T>[] → Result<T[]>
|
|
100
|
+
Result.fromJson(json); // Parse JSON string into Result
|
|
101
|
+
Result.toJson(value); // Serialize to JSON string as Result
|
|
102
|
+
Result.fromFetch(response); // Convert fetch Response to Result
|
|
103
|
+
|
|
104
|
+
result.isOk(); // Type guard
|
|
105
|
+
result.isErr(); // Type guard
|
|
106
|
+
result.map(fn); // Transform success
|
|
107
|
+
result.flatMap(fn); // Chain Result-returning functions
|
|
108
|
+
result.match({ ok, err }); // Pattern match
|
|
109
|
+
result.unwrapOr(fallback); // Value or fallback
|
|
125
110
|
```
|
|
126
111
|
|
|
127
|
-
###
|
|
128
|
-
|
|
129
|
-
- **`validateInput(schema, data)`** -- Validate data against a Zod schema, returning `Result`.
|
|
130
|
-
- **`formatZodIssues(issues)`** -- Format Zod issues into human-readable strings.
|
|
131
|
-
- **`zodToJsonSchema(schema)`** -- Convert a Zod schema to JSON Schema for MCP/HTTP surfaces.
|
|
112
|
+
### Error taxonomy
|
|
132
113
|
|
|
133
|
-
|
|
114
|
+
13 error classes across 10 categories. Each maps deterministically to exit codes, HTTP status, and JSON-RPC codes on every surface.
|
|
134
115
|
|
|
135
|
-
|
|
116
|
+
| Category | Classes | HTTP | Retryable |
|
|
117
|
+
| --- | --- | --- | --- |
|
|
118
|
+
| `validation` | `ValidationError`, `AmbiguousError`, `AssertionError` | 400 | No |
|
|
119
|
+
| `not_found` | `NotFoundError` | 404 | No |
|
|
120
|
+
| `conflict` | `AlreadyExistsError`, `ConflictError` | 409 | No |
|
|
121
|
+
| `permission` | `PermissionError` | 403 | No |
|
|
122
|
+
| `timeout` | `TimeoutError` | 504 | Yes |
|
|
123
|
+
| `rate_limit` | `RateLimitError` | 429 | Yes |
|
|
124
|
+
| `network` | `NetworkError` | 502 | Yes |
|
|
125
|
+
| `internal` | `InternalError` | 500 | No |
|
|
126
|
+
| `auth` | `AuthError` | 401 | No |
|
|
127
|
+
| `cancelled` | `CancelledError` | 499 | No |
|
|
136
128
|
|
|
137
|
-
|
|
138
|
-
import { uuid, email, nonEmptyString, positiveInt } from '@ontrails/core';
|
|
139
|
-
|
|
140
|
-
const id = uuid('550e8400-e29b-41d4-a716-446655440000');
|
|
141
|
-
const addr = email('user@example.com');
|
|
142
|
-
```
|
|
129
|
+
The developer returns `Result.err(new NotFoundError(...))`. The framework maps it to the right code on every surface.
|
|
143
130
|
|
|
144
|
-
###
|
|
131
|
+
### Other exports
|
|
145
132
|
|
|
146
|
-
- **
|
|
147
|
-
- **
|
|
133
|
+
- **Schema derivation** -- `deriveFields(schema)` extracts field metadata from Zod for prompts and forms
|
|
134
|
+
- **Validation** -- `validateInput`, `formatZodIssues`, `zodToJsonSchema`
|
|
148
135
|
- **Resilience** -- `retry`, `withTimeout`, `shouldRetry`, `getBackoffDelay`
|
|
149
|
-
- **Serialization** -- `serializeError`, `deserializeError
|
|
150
|
-
- **
|
|
151
|
-
- **
|
|
136
|
+
- **Serialization** -- `serializeError`, `deserializeError`
|
|
137
|
+
- **Branded types** -- `uuid`, `email`, `nonEmptyString`, `positiveInt`
|
|
138
|
+
- **Layers** -- cross-cutting middleware via `composeLayers`
|
|
139
|
+
- **Guards and collections** -- `isDefined`, `chunk`, `dedupe`, `groupBy`, `sortBy`
|
|
140
|
+
- **Patterns** (`@ontrails/core/patterns`) -- reusable Zod schemas for pagination, bulk ops, timestamps, sorting
|
|
141
|
+
- **Redaction** (`@ontrails/core/redaction`) -- strip sensitive data before logging
|
|
152
142
|
|
|
153
|
-
|
|
143
|
+
See the [API Reference](../../docs/api-reference.md) for the full list.
|
|
154
144
|
|
|
155
|
-
|
|
145
|
+
## Installation
|
|
156
146
|
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
name: 'logging',
|
|
160
|
-
wrap: (next, trail) => async (input, ctx) => {
|
|
161
|
-
ctx.logger.info(`Executing ${trail.id}`);
|
|
162
|
-
return next(input, ctx);
|
|
163
|
-
},
|
|
164
|
-
};
|
|
147
|
+
```bash
|
|
148
|
+
bun add @ontrails/core zod
|
|
165
149
|
```
|
|
166
|
-
|
|
167
|
-
## Subpath Exports
|
|
168
|
-
|
|
169
|
-
| Export | Contents |
|
|
170
|
-
| --- | --- |
|
|
171
|
-
| `@ontrails/core` | trail, hike, event, topo, Result, errors, types, validation, guards, collections, layers |
|
|
172
|
-
| `@ontrails/core/patterns` | Reusable Zod schema patterns |
|
|
173
|
-
| `@ontrails/core/redaction` | Redactor, default patterns and keys |
|
|
174
|
-
|
|
175
|
-
## Further Reading
|
|
176
|
-
|
|
177
|
-
- [Getting Started](../../docs/getting-started.md)
|
|
178
|
-
- [Architecture](../../docs/architecture.md)
|
|
179
|
-
- [Vocabulary](../../docs/vocabulary.md)
|
package/dist/derive.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { z } from 'zod';
|
|
|
8
8
|
/** A surface-agnostic field descriptor derived from a Zod schema. */
|
|
9
9
|
export interface Field {
|
|
10
10
|
readonly name: string;
|
|
11
|
-
readonly type: 'string' | 'number' | 'boolean' | 'enum' | 'multiselect';
|
|
11
|
+
readonly type: 'string' | 'number' | 'boolean' | 'enum' | 'multiselect' | 'string[]' | 'number[]';
|
|
12
12
|
readonly label: string;
|
|
13
13
|
readonly required: boolean;
|
|
14
14
|
readonly default?: unknown | undefined;
|
package/dist/derive.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAM7B,qEAAqE;AACrE,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAM7B,qEAAqE;AACrE,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EACT,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,aAAa,GACb,UAAU,GACV,UAAU,CAAC;IACf,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EACb,SAAS;QACP,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC3B,EAAE,GACH,SAAS,CAAC;CACf;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EACb,SAAS;QACP,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC3B,EAAE,GACH,SAAS,CAAC;CACf;AAsKD,eAAO,MAAM,YAAY,GACvB,QAAQ,CAAC,CAAC,OAAO,EACjB,YAAY,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KACxC,KAAK,EAeP,CAAC"}
|
package/dist/derive.js
CHANGED
|
@@ -60,7 +60,10 @@ const fieldTypeByDef = {
|
|
|
60
60
|
const entries = element._zod.def['entries'];
|
|
61
61
|
return { options: Object.values(entries), type: 'multiselect' };
|
|
62
62
|
}
|
|
63
|
-
return {
|
|
63
|
+
return {
|
|
64
|
+
options: undefined,
|
|
65
|
+
type: elementType === 'number' ? 'number[]' : 'string[]',
|
|
66
|
+
};
|
|
64
67
|
},
|
|
65
68
|
boolean: () => ({ options: undefined, type: 'boolean' }),
|
|
66
69
|
enum: (s) => {
|
package/dist/derive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyDH,8EAA8E;AAC9E,UAAU;A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CAAC,GAAG,CAAC,MAAM,CAAY,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAA6C,CAAC;IAC9E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACxD,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,CACnC,CAAC;IACF,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless trail execution — the "no-surface" surface.
|
|
3
|
+
*
|
|
4
|
+
* Looks up a trail by ID in a topo, then delegates to `executeTrail`.
|
|
5
|
+
* Returns a `Result` and never throws.
|
|
6
|
+
*/
|
|
7
|
+
import type { Topo } from './topo.js';
|
|
8
|
+
import type { ExecuteTrailOptions } from './execute.js';
|
|
9
|
+
import { Result } from './result.js';
|
|
10
|
+
/** Options forwarded to `executeTrail` from `dispatch`. */
|
|
11
|
+
export type DispatchOptions = ExecuteTrailOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Execute a trail by ID from a topo without mounting a surface.
|
|
14
|
+
*
|
|
15
|
+
* Resolves the trail from the topo, then runs it through the standard
|
|
16
|
+
* `executeTrail` pipeline. Returns `Result.err(NotFoundError)` if the
|
|
17
|
+
* trail ID is not registered. Never throws — unexpected exceptions are
|
|
18
|
+
* returned as `Result.err(InternalError)`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = await dispatch(myTopo, 'greet', { name: 'Alice' });
|
|
23
|
+
* if (result.isOk()) console.log(result.value);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const dispatch: (topo: Topo, id: string, input: unknown, options?: DispatchOptions) => Promise<Result<unknown, Error>>;
|
|
27
|
+
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAMrC,2DAA2D;AAC3D,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAMlD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ,GACnB,MAAM,IAAI,EACV,IAAI,MAAM,EACV,OAAO,OAAO,EACd,UAAU,eAAe,KACxB,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAUhC,CAAC"}
|
package/dist/dispatch.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless trail execution — the "no-surface" surface.
|
|
3
|
+
*
|
|
4
|
+
* Looks up a trail by ID in a topo, then delegates to `executeTrail`.
|
|
5
|
+
* Returns a `Result` and never throws.
|
|
6
|
+
*/
|
|
7
|
+
import { executeTrail } from './execute.js';
|
|
8
|
+
import { NotFoundError } from './errors.js';
|
|
9
|
+
import { Result } from './result.js';
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// dispatch()
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Execute a trail by ID from a topo without mounting a surface.
|
|
15
|
+
*
|
|
16
|
+
* Resolves the trail from the topo, then runs it through the standard
|
|
17
|
+
* `executeTrail` pipeline. Returns `Result.err(NotFoundError)` if the
|
|
18
|
+
* trail ID is not registered. Never throws — unexpected exceptions are
|
|
19
|
+
* returned as `Result.err(InternalError)`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const result = await dispatch(myTopo, 'greet', { name: 'Alice' });
|
|
24
|
+
* if (result.isOk()) console.log(result.value);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const dispatch = (topo, id, input, options) => {
|
|
28
|
+
const trail = topo.get(id);
|
|
29
|
+
if (trail === undefined) {
|
|
30
|
+
return Promise.resolve(Result.err(new NotFoundError(`Trail "${id}" not found in topo "${topo.name}"`)));
|
|
31
|
+
}
|
|
32
|
+
return executeTrail(trail, input, options);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAU,EACV,EAAU,EACV,KAAc,EACd,OAAyB,EACQ,EAAE;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,CACpB,MAAM,CAAC,GAAG,CACR,IAAI,aAAa,CAAC,UAAU,EAAE,wBAAwB,IAAI,CAAC,IAAI,GAAG,CAAC,CACpE,CACF,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
package/dist/event.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { z } from 'zod';
|
|
|
5
5
|
export interface EventSpec<T> {
|
|
6
6
|
readonly payload: z.ZodType<T>;
|
|
7
7
|
readonly description?: string | undefined;
|
|
8
|
-
readonly
|
|
8
|
+
readonly metadata?: Readonly<Record<string, unknown>> | undefined;
|
|
9
9
|
/** Trail IDs that produce this event (e.g. the trails it originates from). */
|
|
10
10
|
readonly from?: readonly string[] | undefined;
|
|
11
11
|
}
|
|
@@ -14,7 +14,7 @@ export interface Event<T> {
|
|
|
14
14
|
readonly kind: 'event';
|
|
15
15
|
readonly payload: z.ZodType<T>;
|
|
16
16
|
readonly description?: string | undefined;
|
|
17
|
-
readonly
|
|
17
|
+
readonly metadata?: Readonly<Record<string, unknown>> | undefined;
|
|
18
18
|
/** Trail IDs that produce this event (e.g. the trails it originates from). */
|
|
19
19
|
readonly from?: readonly string[] | undefined;
|
|
20
20
|
}
|
package/dist/event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAM7B,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,E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MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC"}
|
package/dist/event.js
CHANGED
|
@@ -10,7 +10,7 @@ export function event(idOrSpec, maybeSpec) {
|
|
|
10
10
|
from: resolvedSpec.from ? Object.freeze([...resolvedSpec.from]) : undefined,
|
|
11
11
|
id: resolvedId,
|
|
12
12
|
kind: 'event',
|
|
13
|
-
|
|
13
|
+
metadata: resolvedSpec.metadata,
|
|
14
14
|
payload: resolvedSpec.payload,
|
|
15
15
|
});
|
|
16
16
|
}
|
package/dist/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwDH,MAAM,UAAU,KAAK,CACnB,QAA2D,EAC3D,SAAwB;IAExB,MAAM,UAAU,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;IACzE,0GAA0G;IAC1G,MAAM,YAAY,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,WAAW,EAAE,YAAY,CAAC,WAAW;QACrC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QAC3E,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,OAAgB;QACtB,
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwDH,MAAM,UAAU,KAAK,CACnB,QAA2D,EAC3D,SAAwB;IAExB,MAAM,UAAU,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;IACzE,0GAA0G;IAC1G,MAAM,YAAY,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,WAAW,EAAE,YAAY,CAAC,WAAW;QACrC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QAC3E,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,OAAgB;QACtB,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,OAAO,EAAE,YAAY,CAAC,OAAO;KAC9B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized trail execution pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Validates input, builds context, composes layers, and runs the
|
|
5
|
+
* implementation. Surfaces (CLI, MCP, HTTP) delegate here instead
|
|
6
|
+
* of reimplementing the pipeline.
|
|
7
|
+
*/
|
|
8
|
+
import type { AnyTrail } from './trail.js';
|
|
9
|
+
import type { Layer } from './layer.js';
|
|
10
|
+
import type { TrailContext } from './types.js';
|
|
11
|
+
import { Result } from './result.js';
|
|
12
|
+
/** Options for executeTrail. */
|
|
13
|
+
export interface ExecuteTrailOptions {
|
|
14
|
+
/** Partial context overrides merged on top of the base context. */
|
|
15
|
+
readonly ctx?: Partial<TrailContext> | undefined;
|
|
16
|
+
/** AbortSignal override (takes final precedence over ctx and factory). */
|
|
17
|
+
readonly signal?: AbortSignal | undefined;
|
|
18
|
+
/** Layers to compose around the implementation. */
|
|
19
|
+
readonly layers?: readonly Layer[] | undefined;
|
|
20
|
+
/** Factory that produces a base TrailContext (takes precedence over defaults). */
|
|
21
|
+
readonly createContext?: (() => TrailContext | Promise<TrailContext>) | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Execute a trail through the standard validate-context-layers-run pipeline.
|
|
25
|
+
*
|
|
26
|
+
* The function never throws -- unexpected exceptions are caught and
|
|
27
|
+
* returned as `Result.err(InternalError)`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const executeTrail: (trail: AnyTrail, rawInput: unknown, options?: ExecuteTrailOptions) => Promise<Result<unknown, Error>>;
|
|
30
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACjD,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC1C,mDAAmD;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,CAAC;IAC/C,kFAAkF;IAClF,QAAQ,CAAC,aAAa,CAAC,EACnB,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,GAC5C,SAAS,CAAC;CACf;AAoCD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,QAAQ,EACf,UAAU,OAAO,EACjB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAehC,CAAC"}
|