@ontrails/core 1.0.0-beta.13 → 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.
- package/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +17 -0
- package/README.md +19 -14
- package/dist/branded.d.ts +1 -1
- package/dist/branded.d.ts.map +1 -1
- package/dist/branded.js +1 -1
- package/dist/branded.js.map +1 -1
- package/dist/context.d.ts +13 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +19 -3
- package/dist/context.js.map +1 -1
- package/dist/contour.d.ts +81 -0
- package/dist/contour.d.ts.map +1 -0
- package/dist/contour.js +176 -0
- package/dist/contour.js.map +1 -0
- package/dist/cross-schema.d.ts +18 -0
- package/dist/cross-schema.d.ts.map +1 -0
- package/dist/cross-schema.js +29 -0
- package/dist/cross-schema.js.map +1 -0
- package/dist/derive.d.ts +6 -0
- package/dist/derive.d.ts.map +1 -1
- package/dist/derive.js +29 -5
- package/dist/derive.js.map +1 -1
- package/dist/draft.d.ts +28 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +157 -0
- package/dist/draft.js.map +1 -0
- package/dist/errors.d.ts +62 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +44 -1
- package/dist/errors.js.map +1 -1
- package/dist/execute.d.ts +26 -9
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +441 -20
- package/dist/execute.js.map +1 -1
- package/dist/fire.d.ts +43 -0
- package/dist/fire.d.ts.map +1 -0
- package/dist/fire.js +185 -0
- package/dist/fire.js.map +1 -0
- package/dist/index.d.ts +33 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/internal/cross-batch.d.ts +44 -0
- package/dist/internal/cross-batch.d.ts.map +1 -0
- package/dist/internal/cross-batch.js +58 -0
- package/dist/internal/cross-batch.js.map +1 -0
- package/dist/internal/fork-ctx.d.ts +41 -0
- package/dist/internal/fork-ctx.d.ts.map +1 -0
- package/dist/internal/fork-ctx.js +47 -0
- package/dist/internal/fork-ctx.js.map +1 -0
- package/dist/internal/signal-ref.d.ts +15 -0
- package/dist/internal/signal-ref.d.ts.map +1 -0
- package/dist/internal/signal-ref.js +41 -0
- package/dist/internal/signal-ref.js.map +1 -0
- package/dist/internal/topo-saves.d.ts +53 -0
- package/dist/internal/topo-saves.d.ts.map +1 -0
- package/dist/internal/topo-saves.js +449 -0
- package/dist/internal/topo-saves.js.map +1 -0
- package/dist/internal/topo-snapshots.d.ts +57 -0
- package/dist/internal/topo-snapshots.d.ts.map +1 -0
- package/dist/internal/topo-snapshots.js +372 -0
- package/dist/internal/topo-snapshots.js.map +1 -0
- package/dist/internal/topo-store-read.d.ts +70 -0
- package/dist/internal/topo-store-read.d.ts.map +1 -0
- package/dist/internal/topo-store-read.js +221 -0
- package/dist/internal/topo-store-read.js.map +1 -0
- package/dist/internal/topo-store.d.ts +26 -0
- package/dist/internal/topo-store.d.ts.map +1 -0
- package/dist/internal/topo-store.js +621 -0
- package/dist/internal/topo-store.js.map +1 -0
- package/dist/internal/tracing.d.ts +98 -0
- package/dist/internal/tracing.d.ts.map +1 -0
- package/dist/internal/tracing.js +102 -0
- package/dist/internal/tracing.js.map +1 -0
- package/dist/internal/trails-db.d.ts +16 -0
- package/dist/internal/trails-db.d.ts.map +1 -0
- package/dist/internal/trails-db.js +118 -0
- package/dist/internal/trails-db.js.map +1 -0
- package/dist/internal/zod-wrappers.d.ts +40 -0
- package/dist/internal/zod-wrappers.d.ts.map +1 -0
- package/dist/internal/zod-wrappers.js +59 -0
- package/dist/internal/zod-wrappers.js.map +1 -0
- package/dist/layer.d.ts +22 -5
- package/dist/layer.d.ts.map +1 -1
- package/dist/layer.js +20 -3
- package/dist/layer.js.map +1 -1
- package/dist/path-security.d.ts +1 -1
- package/dist/path-security.d.ts.map +1 -1
- package/dist/path-security.js +1 -1
- package/dist/path-security.js.map +1 -1
- package/dist/resilience.d.ts +1 -1
- package/dist/resilience.d.ts.map +1 -1
- package/dist/resilience.js +3 -3
- package/dist/resilience.js.map +1 -1
- package/dist/resource-config.d.ts +22 -0
- package/dist/resource-config.d.ts.map +1 -0
- package/dist/resource-config.js +210 -0
- package/dist/resource-config.js.map +1 -0
- package/dist/resource.d.ts +74 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +61 -0
- package/dist/resource.js.map +1 -0
- package/dist/run.d.ts +4 -3
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +5 -4
- package/dist/run.js.map +1 -1
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +2 -1
- package/dist/serialization.js.map +1 -1
- package/dist/store/accessor-protocol.d.ts +51 -0
- package/dist/store/accessor-protocol.d.ts.map +1 -0
- package/dist/store/accessor-protocol.js +2 -0
- package/dist/store/accessor-protocol.js.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +2 -0
- package/dist/store/index.js.map +1 -0
- package/dist/surface-filter.d.ts +13 -0
- package/dist/surface-filter.d.ts.map +1 -0
- package/dist/surface-filter.js +76 -0
- package/dist/surface-filter.js.map +1 -0
- package/dist/topo-store.d.ts +62 -0
- package/dist/topo-store.d.ts.map +1 -0
- package/dist/topo-store.js +319 -0
- package/dist/topo-store.js.map +1 -0
- package/dist/topo.d.ts +23 -9
- package/dist/topo.d.ts.map +1 -1
- package/dist/topo.js +175 -46
- package/dist/topo.js.map +1 -1
- package/dist/trail.d.ts +86 -19
- package/dist/trail.d.ts.map +1 -1
- package/dist/trail.js +59 -4
- package/dist/trail.js.map +1 -1
- package/dist/trails/derive-trail.d.ts +66 -0
- package/dist/trails/derive-trail.d.ts.map +1 -0
- package/dist/trails/derive-trail.js +378 -0
- package/dist/trails/derive-trail.js.map +1 -0
- package/dist/trails/index.d.ts +5 -0
- package/dist/trails/index.d.ts.map +1 -0
- package/dist/trails/index.js +3 -0
- package/dist/trails/index.js.map +1 -0
- package/dist/trails/ingest.d.ts +24 -0
- package/dist/trails/ingest.d.ts.map +1 -0
- package/dist/trails/ingest.js +63 -0
- package/dist/trails/ingest.js.map +1 -0
- package/dist/transport-error-map.d.ts +106 -0
- package/dist/transport-error-map.d.ts.map +1 -0
- package/dist/transport-error-map.js +24 -0
- package/dist/transport-error-map.js.map +1 -0
- package/dist/type-checks.test-d.d.ts +71 -0
- package/dist/type-checks.test-d.d.ts.map +1 -0
- package/dist/type-checks.test-d.js +12 -0
- package/dist/type-checks.test-d.js.map +1 -0
- package/dist/type-utils.d.ts +11 -2
- package/dist/type-utils.d.ts.map +1 -1
- package/dist/type-utils.js.map +1 -1
- package/dist/types.d.ts +113 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validate-established-topo.d.ts +76 -0
- package/dist/validate-established-topo.d.ts.map +1 -0
- package/dist/validate-established-topo.js +43 -0
- package/dist/validate-established-topo.js.map +1 -0
- package/dist/validate-topo.d.ts.map +1 -1
- package/dist/validate-topo.js +27 -8
- package/dist/validate-topo.js.map +1 -1
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +1 -1
- package/dist/workspace.js.map +1 -1
- package/package.json +10 -1
- package/src/__tests__/branded.test.ts +5 -5
- package/src/__tests__/context.test.ts +3 -3
- package/src/__tests__/contour.test.ts +263 -0
- package/src/__tests__/derive-trail.test.ts +668 -0
- package/src/__tests__/derive.test.ts +58 -1
- package/src/__tests__/errors.test.ts +118 -0
- package/src/__tests__/execute.test.ts +1179 -141
- package/src/__tests__/fire.test.ts +1056 -0
- package/src/__tests__/fork-ctx.test.ts +83 -0
- package/src/__tests__/ingest.test.ts +191 -0
- package/src/__tests__/{gate.test.ts → layer.test.ts} +21 -21
- package/src/__tests__/path-security.test.ts +7 -7
- package/src/__tests__/resilience.test.ts +8 -8
- package/src/__tests__/resource.test.ts +204 -0
- package/src/__tests__/run.test.ts +13 -13
- package/src/__tests__/service-config.test.ts +28 -32
- package/src/__tests__/surface-filter.test.ts +196 -0
- package/src/__tests__/topo-store-read.test.ts +256 -0
- package/src/__tests__/topo-store.test.ts +869 -0
- package/src/__tests__/topo.test.ts +350 -54
- package/src/__tests__/trail.test.ts +189 -24
- package/src/__tests__/trails-db.test.ts +198 -0
- package/src/__tests__/transport-error-map.test.ts +82 -0
- package/src/__tests__/type-utils.test.ts +29 -1
- package/src/__tests__/validate-topo.test.ts +305 -16
- package/src/__tests__/workspace.test.ts +6 -6
- package/src/__tests__/zod-wrappers.test.ts +62 -0
- package/src/branded.ts +1 -1
- package/src/context.ts +24 -4
- package/src/contour.ts +344 -0
- package/src/cross-schema.ts +36 -0
- package/src/derive.ts +39 -8
- package/src/draft.ts +338 -0
- package/src/errors.ts +62 -18
- package/src/execute.ts +840 -29
- package/src/fire.ts +295 -0
- package/src/index.ts +142 -26
- package/src/internal/cross-batch.ts +77 -0
- package/src/internal/fork-ctx.ts +69 -0
- package/src/internal/signal-ref.ts +87 -0
- package/src/internal/topo-snapshots.ts +517 -0
- package/src/internal/topo-store-read.ts +481 -0
- package/src/internal/topo-store.ts +1192 -0
- package/src/internal/tracing.ts +187 -0
- package/src/internal/trails-db.ts +187 -0
- package/src/internal/zod-wrappers.ts +78 -0
- package/src/layer.ts +50 -0
- package/src/path-security.ts +1 -1
- package/src/resilience.ts +3 -3
- package/src/{provision-config.ts → resource-config.ts} +109 -123
- package/src/resource.ts +155 -0
- package/src/run.ts +5 -4
- package/src/serialization.ts +2 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/surface-filter.ts +182 -0
- package/src/topo-store.ts +510 -0
- package/src/topo.ts +328 -57
- package/src/trail.ts +199 -31
- package/src/trails/derive-trail.ts +842 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +146 -0
- package/src/transport-error-map.ts +56 -0
- package/src/type-checks.test-d.ts +106 -0
- package/src/type-utils.ts +17 -2
- package/src/types.ts +148 -11
- package/src/validate-established-topo.ts +63 -0
- package/src/validate-topo.ts +37 -9
- package/src/workspace.ts +1 -1
- package/tsconfig.tests.json +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/adapters.d.ts +0 -39
- package/dist/adapters.d.ts.map +0 -1
- package/dist/adapters.js +0 -2
- package/dist/adapters.js.map +0 -1
- package/dist/dispatch.d.ts +0 -27
- package/dist/dispatch.d.ts.map +0 -1
- package/dist/dispatch.js +0 -34
- package/dist/dispatch.js.map +0 -1
- package/dist/event.d.ts +0 -8
- package/dist/event.d.ts.map +0 -1
- package/dist/event.js +0 -7
- package/dist/event.js.map +0 -1
- package/dist/gate.d.ts +0 -17
- package/dist/gate.d.ts.map +0 -1
- package/dist/gate.js +0 -21
- package/dist/gate.js.map +0 -1
- package/dist/health.d.ts +0 -18
- package/dist/health.d.ts.map +0 -1
- package/dist/health.js +0 -5
- package/dist/health.js.map +0 -1
- package/dist/job.d.ts +0 -24
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -17
- package/dist/job.js.map +0 -1
- package/dist/provision-config.d.ts +0 -22
- package/dist/provision-config.d.ts.map +0 -1
- package/dist/provision-config.js +0 -210
- package/dist/provision-config.js.map +0 -1
- package/dist/provision.d.ts +0 -71
- package/dist/provision.d.ts.map +0 -1
- package/dist/provision.js +0 -56
- package/dist/provision.js.map +0 -1
- package/dist/service-config.d.ts +0 -22
- package/dist/service-config.d.ts.map +0 -1
- package/dist/service-config.js +0 -210
- package/dist/service-config.js.map +0 -1
- package/dist/service.d.ts +0 -71
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -56
- package/dist/service.js.map +0 -1
- package/src/__tests__/service.test.ts +0 -197
- package/src/event.ts +0 -15
- package/src/gate.ts +0 -44
- package/src/provision.ts +0 -148
package/dist/topo.js
CHANGED
|
@@ -2,30 +2,42 @@
|
|
|
2
2
|
* Application entry point — scans module exports to build a topology graph.
|
|
3
3
|
*/
|
|
4
4
|
import { ValidationError } from './errors.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getLateBoundSignalRef, parseLateBoundSignalMarker, } from './internal/signal-ref.js';
|
|
6
|
+
import { isResource } from './resource.js';
|
|
6
7
|
const isRegistrable = (value) => {
|
|
7
8
|
if (typeof value !== 'object' || value === null) {
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
10
11
|
const { kind } = value;
|
|
11
|
-
return kind === 'trail' || kind === 'signal';
|
|
12
|
+
return kind === 'contour' || kind === 'trail' || kind === 'signal';
|
|
12
13
|
};
|
|
13
14
|
// ---------------------------------------------------------------------------
|
|
14
15
|
// Topo implementation
|
|
15
16
|
// ---------------------------------------------------------------------------
|
|
16
|
-
const createTopo = (
|
|
17
|
+
const createTopo = (identity, contours, trails, signals, resources) => ({
|
|
18
|
+
contourCount: contours.size,
|
|
19
|
+
contourIds() {
|
|
20
|
+
return [...contours.keys()];
|
|
21
|
+
},
|
|
22
|
+
contours,
|
|
17
23
|
count: trails.size,
|
|
18
24
|
get(id) {
|
|
19
25
|
return trails.get(id);
|
|
20
26
|
},
|
|
21
|
-
|
|
22
|
-
return
|
|
27
|
+
getContour(contourName) {
|
|
28
|
+
return contours.get(contourName);
|
|
29
|
+
},
|
|
30
|
+
getResource(id) {
|
|
31
|
+
return resources.get(id);
|
|
23
32
|
},
|
|
24
33
|
has(id) {
|
|
25
34
|
return trails.has(id);
|
|
26
35
|
},
|
|
27
|
-
|
|
28
|
-
return
|
|
36
|
+
hasContour(contourName) {
|
|
37
|
+
return contours.has(contourName);
|
|
38
|
+
},
|
|
39
|
+
hasResource(id) {
|
|
40
|
+
return resources.has(id);
|
|
29
41
|
},
|
|
30
42
|
ids() {
|
|
31
43
|
return [...trails.keys()];
|
|
@@ -33,48 +45,153 @@ const createTopo = (name, trails, signals, provisions) => ({
|
|
|
33
45
|
list() {
|
|
34
46
|
return [...trails.values()];
|
|
35
47
|
},
|
|
36
|
-
|
|
37
|
-
return [...
|
|
48
|
+
listContours() {
|
|
49
|
+
return [...contours.values()];
|
|
50
|
+
},
|
|
51
|
+
listResources() {
|
|
52
|
+
return [...resources.values()];
|
|
38
53
|
},
|
|
39
54
|
listSignals() {
|
|
40
55
|
return [...signals.values()];
|
|
41
56
|
},
|
|
42
|
-
name,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
name: identity.name,
|
|
58
|
+
...(identity.version !== undefined && { version: identity.version }),
|
|
59
|
+
...(identity.description !== undefined && {
|
|
60
|
+
description: identity.description,
|
|
61
|
+
}),
|
|
62
|
+
resourceCount: resources.size,
|
|
63
|
+
resourceIds() {
|
|
64
|
+
return [...resources.keys()];
|
|
46
65
|
},
|
|
47
|
-
|
|
66
|
+
resources,
|
|
48
67
|
signals,
|
|
49
68
|
trails,
|
|
50
69
|
});
|
|
51
70
|
// ---------------------------------------------------------------------------
|
|
52
71
|
// topo()
|
|
53
72
|
// ---------------------------------------------------------------------------
|
|
73
|
+
const registerUnique = (collection, id, value, duplicateMessage) => {
|
|
74
|
+
const existing = collection.get(id);
|
|
75
|
+
if (existing === value) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (existing !== undefined) {
|
|
79
|
+
throw new ValidationError(duplicateMessage);
|
|
80
|
+
}
|
|
81
|
+
collection.set(id, value);
|
|
82
|
+
};
|
|
83
|
+
const registerContour = (contour, contours) => {
|
|
84
|
+
registerUnique(contours, contour.name, contour, `Duplicate contour name: "${contour.name}"`);
|
|
85
|
+
};
|
|
86
|
+
const registerResourceValue = (resource, resources) => {
|
|
87
|
+
registerUnique(resources, resource.id, resource, `Duplicate resource ID: "${resource.id}"`);
|
|
88
|
+
};
|
|
89
|
+
const registerSignal = (signal, signals) => {
|
|
90
|
+
registerUnique(signals, signal.id, signal, `Duplicate signal ID: "${signal.id}"`);
|
|
91
|
+
};
|
|
92
|
+
const registerResourceSignals = (resource, signals) => {
|
|
93
|
+
for (const derived of resource.signals ?? []) {
|
|
94
|
+
registerSignal(derived, signals);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const registerTrail = (trail, trails) => {
|
|
98
|
+
registerUnique(trails, trail.id, trail, `Duplicate trail ID: "${trail.id}"`);
|
|
99
|
+
};
|
|
100
|
+
const registerLateBoundSignalId = (byToken, signal) => {
|
|
101
|
+
const ref = getLateBoundSignalRef(signal);
|
|
102
|
+
if (!ref) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const ids = byToken.get(ref.token) ?? new Set();
|
|
106
|
+
ids.add(signal.id);
|
|
107
|
+
byToken.set(ref.token, ids);
|
|
108
|
+
};
|
|
109
|
+
const collectLateBoundSignalIdsByToken = (resources) => {
|
|
110
|
+
const byToken = new Map();
|
|
111
|
+
for (const resource of resources.values()) {
|
|
112
|
+
for (const signal of resource.signals ?? []) {
|
|
113
|
+
registerLateBoundSignalId(byToken, signal);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return new Map([...byToken.entries()].map(([token, ids]) => [token, [...ids]]));
|
|
117
|
+
};
|
|
118
|
+
const resolveLateBoundSignalId = (trailId, signalId, lateBoundSignalIdsByToken) => {
|
|
119
|
+
const marker = parseLateBoundSignalMarker(signalId);
|
|
120
|
+
if (!marker) {
|
|
121
|
+
return signalId;
|
|
122
|
+
}
|
|
123
|
+
const matches = lateBoundSignalIdsByToken.get(marker.token) ?? [];
|
|
124
|
+
if (matches.length === 1) {
|
|
125
|
+
return matches[0] ?? signalId;
|
|
126
|
+
}
|
|
127
|
+
if (matches.length === 0) {
|
|
128
|
+
// Intentional throw: split-topo composition (where a trail and the
|
|
129
|
+
// store that backs its signals live in different topos) is not yet
|
|
130
|
+
// supported. Failing loudly here surfaces the case at assembly time
|
|
131
|
+
// instead of silently producing a trail with an unresolved store
|
|
132
|
+
// reference that would misbehave at runtime.
|
|
133
|
+
throw new ValidationError(`Trail "${trailId}" references store-derived signal "${marker.displayId}", but no resource bound in this topo exposes it. ` +
|
|
134
|
+
'This usually means the store that backs this signal is not bound in this topo. ' +
|
|
135
|
+
`Bind the store via resource() in the same topo() call as "${trailId}", or compose this topo with the topo that binds the store. ` +
|
|
136
|
+
'Splitting a trail and its backing store across independent topos is not yet supported.');
|
|
137
|
+
}
|
|
138
|
+
throw new ValidationError(`Trail "${trailId}" references late-bound signal "${marker.displayId}" but it resolves to multiple bound resource signals: ${matches.join(', ')}. Use canonical scoped ids when the same store definition is bound more than once.`);
|
|
139
|
+
};
|
|
140
|
+
const resolveTrailSignalIds = (trailId, signalIds, lateBoundSignalIdsByToken) => {
|
|
141
|
+
let changed = false;
|
|
142
|
+
const ids = Object.freeze(signalIds.map((signalId) => {
|
|
143
|
+
const resolved = resolveLateBoundSignalId(trailId, signalId, lateBoundSignalIdsByToken);
|
|
144
|
+
changed ||= resolved !== signalId;
|
|
145
|
+
return resolved;
|
|
146
|
+
}));
|
|
147
|
+
return { changed, ids };
|
|
148
|
+
};
|
|
149
|
+
const finalizeTrailSignals = (trails, resources) => {
|
|
150
|
+
const lateBoundSignalIdsByToken = collectLateBoundSignalIdsByToken(resources);
|
|
151
|
+
const finalized = new Map();
|
|
152
|
+
for (const trail of trails.values()) {
|
|
153
|
+
const resolvedFires = resolveTrailSignalIds(trail.id, trail.fires ?? [], lateBoundSignalIdsByToken);
|
|
154
|
+
const resolvedOn = resolveTrailSignalIds(trail.id, trail.on ?? [], lateBoundSignalIdsByToken);
|
|
155
|
+
if (!resolvedFires.changed && !resolvedOn.changed) {
|
|
156
|
+
finalized.set(trail.id, trail);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
finalized.set(trail.id, Object.freeze({
|
|
160
|
+
...trail,
|
|
161
|
+
fires: resolvedFires.ids,
|
|
162
|
+
on: resolvedOn.ids,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
return finalized;
|
|
166
|
+
};
|
|
54
167
|
/** Register a single registrable value into the appropriate map. */
|
|
55
|
-
const register = (value, trails, signals,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
168
|
+
const register = (value, contours, trails, signals, resources) => {
|
|
169
|
+
switch (value.kind) {
|
|
170
|
+
case 'contour': {
|
|
171
|
+
registerContour(value, contours);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'resource': {
|
|
175
|
+
registerResourceValue(value, resources);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case 'signal': {
|
|
179
|
+
registerSignal(value, signals);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case 'trail': {
|
|
183
|
+
registerTrail(value, trails);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
default: {
|
|
187
|
+
throw new ValidationError('Unsupported registrable value in topo()');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const registerTrailContours = (trail, contours, trails, signals, resources) => {
|
|
192
|
+
for (const contour of trail.contours ?? []) {
|
|
193
|
+
register(contour, contours, trails, signals, resources);
|
|
194
|
+
}
|
|
78
195
|
};
|
|
79
196
|
const markUniqueObject = (value, seenValues) => {
|
|
80
197
|
if (typeof value !== 'object' || value === null) {
|
|
@@ -86,27 +203,39 @@ const markUniqueObject = (value, seenValues) => {
|
|
|
86
203
|
seenValues.add(value);
|
|
87
204
|
return true;
|
|
88
205
|
};
|
|
89
|
-
const registerModuleValue = (value, trails, signals,
|
|
90
|
-
if (
|
|
91
|
-
register(value, trails, signals,
|
|
206
|
+
const registerModuleValue = (value, contours, trails, signals, resources) => {
|
|
207
|
+
if (isResource(value) || isRegistrable(value)) {
|
|
208
|
+
register(value, contours, trails, signals, resources);
|
|
209
|
+
}
|
|
210
|
+
if (isResource(value)) {
|
|
211
|
+
registerResourceSignals(value, signals);
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === 'object' &&
|
|
214
|
+
value !== null &&
|
|
215
|
+
value.kind === 'trail') {
|
|
216
|
+
registerTrailContours(value, contours, trails, signals, resources);
|
|
92
217
|
}
|
|
93
218
|
};
|
|
94
|
-
const registerModuleValues = (mod, trails, signals,
|
|
219
|
+
const registerModuleValues = (mod, contours, trails, signals, resources) => {
|
|
95
220
|
const seenValues = new WeakSet();
|
|
96
221
|
for (const value of Object.values(mod)) {
|
|
97
222
|
if (!markUniqueObject(value, seenValues)) {
|
|
98
223
|
continue;
|
|
99
224
|
}
|
|
100
|
-
registerModuleValue(value, trails, signals,
|
|
225
|
+
registerModuleValue(value, contours, trails, signals, resources);
|
|
101
226
|
}
|
|
102
227
|
};
|
|
103
|
-
export const topo = (
|
|
228
|
+
export const topo = (nameOrIdentity, ...modules) => {
|
|
229
|
+
const identity = typeof nameOrIdentity === 'string'
|
|
230
|
+
? { name: nameOrIdentity }
|
|
231
|
+
: nameOrIdentity;
|
|
232
|
+
const contours = new Map();
|
|
104
233
|
const trails = new Map();
|
|
105
234
|
const signals = new Map();
|
|
106
|
-
const
|
|
235
|
+
const resources = new Map();
|
|
107
236
|
for (const mod of modules) {
|
|
108
|
-
registerModuleValues(mod, trails, signals,
|
|
237
|
+
registerModuleValues(mod, contours, trails, signals, resources);
|
|
109
238
|
}
|
|
110
|
-
return createTopo(
|
|
239
|
+
return createTopo(identity, contours, finalizeTrailSignals(trails, resources), signals, resources);
|
|
111
240
|
};
|
|
112
241
|
//# sourceMappingURL=topo.js.map
|
package/dist/topo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topo.js","sourceRoot":"","sources":["../src/topo.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"topo.js","sourceRoot":"","sources":["../src/topo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAA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,SAAS,CACV,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/trail.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
+
import type { AnyContour } from './contour.js';
|
|
2
3
|
import type { FieldOverride } from './derive.js';
|
|
3
4
|
import type { Result } from './result.js';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
5
|
+
import type { AnyResource } from './resource.js';
|
|
6
|
+
import type { AnySignal } from './signal.js';
|
|
7
|
+
import type { TrailsError } from './errors.js';
|
|
8
|
+
import type { Detour, Implementation, PermitRequirement, TrailContext } from './types.js';
|
|
6
9
|
/**
|
|
7
10
|
* A named example for documentation and testing.
|
|
8
11
|
*
|
|
@@ -17,53 +20,115 @@ export interface TrailExample<I, O> {
|
|
|
17
20
|
readonly description?: string | undefined;
|
|
18
21
|
/** The input value — fields with schema defaults may be omitted */
|
|
19
22
|
readonly input: Partial<I>;
|
|
20
|
-
/** Expected output for success-path examples */
|
|
23
|
+
/** Expected output for success-path examples (deep equality) */
|
|
21
24
|
readonly expected?: O | undefined;
|
|
25
|
+
/** Partial output assertion — declared fields must match, others ignored */
|
|
26
|
+
readonly expectedMatch?: Partial<O> | undefined;
|
|
22
27
|
/** Error class name for error-path examples */
|
|
23
28
|
readonly error?: string | undefined;
|
|
24
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* The input type received by a trail's blaze function.
|
|
32
|
+
*
|
|
33
|
+
* When a trail declares `crossInput`, the runtime merges those fields into
|
|
34
|
+
* the input object before calling blaze. This type makes the compiler aware
|
|
35
|
+
* of the merged shape so developers can access crossInput fields without a
|
|
36
|
+
* cast. Falls back to plain `I` when `CI` is `never` (the default).
|
|
37
|
+
*/
|
|
38
|
+
export type BlazeInput<I, CI> = [CI] extends [never] ? I : I & CI;
|
|
25
39
|
/** Everything needed to define a trail (minus the id) */
|
|
26
|
-
export interface TrailSpec<I, O> {
|
|
40
|
+
export interface TrailSpec<I, O, CI = never> {
|
|
27
41
|
/** Zod schema for validating input */
|
|
28
42
|
readonly input: z.ZodType<I>;
|
|
29
43
|
/** Zod schema for validating output (optional — some trails are fire-and-forget) */
|
|
30
44
|
readonly output?: z.ZodType<O> | undefined;
|
|
31
45
|
/** The pure function that does the work (sync or async authoring) */
|
|
32
|
-
readonly blaze: Implementation<I, O>;
|
|
46
|
+
readonly blaze: Implementation<BlazeInput<I, CI>, O>;
|
|
33
47
|
/** Human-readable description */
|
|
34
48
|
readonly description?: string | undefined;
|
|
49
|
+
/** Declared operational shape for governance, derivation, and agent guidance. */
|
|
50
|
+
readonly pattern?: string | undefined;
|
|
35
51
|
/** Named examples for docs and testing */
|
|
36
52
|
readonly examples?: readonly TrailExample<I, O>[] | undefined;
|
|
37
53
|
/** What this trail does to the world: read, write (default), or destroy */
|
|
38
54
|
readonly intent?: 'read' | 'write' | 'destroy' | undefined;
|
|
39
55
|
/** Trail is idempotent (safe to retry) */
|
|
40
56
|
readonly idempotent?: boolean | undefined;
|
|
57
|
+
/** Whether trailheads expose this trail by default. */
|
|
58
|
+
readonly visibility?: TrailVisibility | undefined;
|
|
41
59
|
/** Arbitrary meta for tooling and filtering */
|
|
42
60
|
readonly meta?: Readonly<Record<string, unknown>> | undefined;
|
|
43
|
-
/**
|
|
44
|
-
readonly detours?:
|
|
61
|
+
/** Recovery paths activated when blaze fails with a matching error class. */
|
|
62
|
+
readonly detours?: readonly Detour<I, O, TrailsError>[] | undefined;
|
|
45
63
|
/** Per-field overrides for deriveFields() (labels, hints, options) */
|
|
46
64
|
readonly fields?: Readonly<Record<string, FieldOverride>> | undefined;
|
|
47
|
-
/**
|
|
48
|
-
readonly
|
|
49
|
-
/**
|
|
50
|
-
readonly
|
|
65
|
+
/** Contours this trail operates on. */
|
|
66
|
+
readonly contours?: readonly AnyContour[] | undefined;
|
|
67
|
+
/** IDs or trail objects of downstream trails this trail may invoke via ctx.cross() */
|
|
68
|
+
readonly crosses?: readonly (string | AnyTrail)[] | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Composition-only input schema — merged with `input` for `ctx.cross()` calls,
|
|
71
|
+
* invisible to public trailheads (CLI, MCP, HTTP).
|
|
72
|
+
*
|
|
73
|
+
* Fields here are available in the blaze but are not derived into CLI flags,
|
|
74
|
+
* MCP tool parameters, or HTTP request bodies. Use for data that only makes
|
|
75
|
+
* sense when one trail crosses another (e.g. `forkedFrom`).
|
|
76
|
+
*/
|
|
77
|
+
readonly crossInput?: z.ZodType<CI> | undefined;
|
|
78
|
+
/** Resources this trail may access via resource.from(ctx) */
|
|
79
|
+
readonly resources?: readonly AnyResource[] | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Signals this trail emits via `ctx.fire()`.
|
|
82
|
+
*
|
|
83
|
+
* Accepts either a string id or a `Signal` value. Both forms are
|
|
84
|
+
* normalized to the signal's id at trail definition time, so
|
|
85
|
+
* `trail.fires` is always `readonly string[]`.
|
|
86
|
+
*
|
|
87
|
+
* Note: `crosses` also accepts trail objects (normalized to IDs),
|
|
88
|
+
* following the same pattern as signal references here.
|
|
89
|
+
*/
|
|
90
|
+
readonly fires?: readonly (string | AnySignal)[] | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Signals that activate this trail (framework auto-subscribes).
|
|
93
|
+
*
|
|
94
|
+
* Accepts either a string id or a `Signal` value. Both forms are
|
|
95
|
+
* normalized to the signal's id at trail definition time.
|
|
96
|
+
*/
|
|
97
|
+
readonly on?: readonly (string | AnySignal)[] | undefined;
|
|
51
98
|
/** Auth requirement: scopes object, 'public', or omitted (undeclared) */
|
|
52
99
|
readonly permit?: PermitRequirement | undefined;
|
|
100
|
+
/** Primary input fields and their order. CLI projects as positional args. */
|
|
101
|
+
readonly args?: readonly string[] | false | undefined;
|
|
53
102
|
}
|
|
54
103
|
/** Intent describes what a trail does to the world */
|
|
55
104
|
export type Intent = 'read' | 'write' | 'destroy';
|
|
105
|
+
/** Whether trailheads expose a trail by default. */
|
|
106
|
+
export type TrailVisibility = 'public' | 'internal';
|
|
56
107
|
/** A fully-defined trail — the unit of work in the Trails system */
|
|
57
|
-
export interface Trail<I, O> extends Omit<TrailSpec<I, O>, 'blaze' | 'crosses' | 'intent' | '
|
|
108
|
+
export interface Trail<I, O, CI = never> extends Omit<TrailSpec<I, O, CI>, 'args' | 'blaze' | 'contours' | 'crosses' | 'crossInput' | 'detours' | 'fires' | 'intent' | 'on' | 'resources'> {
|
|
58
109
|
readonly kind: 'trail';
|
|
59
110
|
readonly id: string;
|
|
60
|
-
readonly blaze: Implementation<I, O>;
|
|
111
|
+
readonly blaze: Implementation<BlazeInput<I, CI>, O>;
|
|
112
|
+
/** Contours this trail operates on (always present, default []). */
|
|
113
|
+
readonly contours: readonly AnyContour[];
|
|
61
114
|
/** IDs of downstream trails this trail may invoke via ctx.cross() (always present, default []) */
|
|
62
115
|
readonly crosses: readonly string[];
|
|
63
|
-
/**
|
|
64
|
-
readonly
|
|
116
|
+
/** Composition-only input schema, merged with `input` for ctx.cross() calls (optional) */
|
|
117
|
+
readonly crossInput?: z.ZodType<CI> | undefined;
|
|
118
|
+
/** Recovery paths activated when blaze fails with a matching error (always present, default []). */
|
|
119
|
+
readonly detours: readonly Detour<I, O, TrailsError>[];
|
|
120
|
+
/** Resources this trail may access via resource.from(ctx) (always present, default []) */
|
|
121
|
+
readonly resources: readonly AnyResource[];
|
|
122
|
+
/** IDs of signals this trail emits via ctx.fire() (always present, default []) */
|
|
123
|
+
readonly fires: readonly string[];
|
|
124
|
+
/** IDs of signals that activate this trail (always present, default []) */
|
|
125
|
+
readonly on: readonly string[];
|
|
65
126
|
/** What this trail does to the world (always present, default 'write') */
|
|
66
127
|
readonly intent: Intent;
|
|
128
|
+
/** Whether trailheads expose this trail by default (always present, default 'public'). */
|
|
129
|
+
readonly visibility: TrailVisibility;
|
|
130
|
+
/** Primary input fields and their order (always present, default undefined) */
|
|
131
|
+
readonly args?: readonly string[] | false | undefined;
|
|
67
132
|
}
|
|
68
133
|
/**
|
|
69
134
|
* Create a trail definition.
|
|
@@ -87,10 +152,12 @@ export interface Trail<I, O> extends Omit<TrailSpec<I, O>, 'blaze' | 'crosses' |
|
|
|
87
152
|
* });
|
|
88
153
|
* ```
|
|
89
154
|
*/
|
|
90
|
-
export declare function trail<I, O>(id: string, spec: TrailSpec<I, O>): Trail<I, O>;
|
|
91
|
-
export declare function trail<I, O>(spec: TrailSpec<I, O> & {
|
|
155
|
+
export declare function trail<I, O, CI = never>(id: string, spec: TrailSpec<I, O, CI>): Trail<I, O, CI>;
|
|
156
|
+
export declare function trail<I, O, CI = never>(spec: TrailSpec<I, O, CI> & {
|
|
92
157
|
readonly id: string;
|
|
93
|
-
}): Trail<I, O>;
|
|
94
|
-
export type AnyTrail = Trail<any, any
|
|
158
|
+
}): Trail<I, O, CI>;
|
|
159
|
+
export type AnyTrail = Omit<Trail<any, any, any>, 'blaze'> & {
|
|
160
|
+
readonly blaze: Implementation<any, any>;
|
|
161
|
+
};
|
|
95
162
|
export type { Implementation, TrailContext, Result };
|
|
96
163
|
//# sourceMappingURL=trail.d.ts.map
|
package/dist/trail.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trail.d.ts","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"trail.d.ts","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,E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,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAClD,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAiDnB,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG;IAC3D,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAC1C,CAAC;AAGF,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/trail.js
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
import { createLateBoundSignalMarker, getLateBoundSignalRef, } from './internal/signal-ref.js';
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Factory
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Canonical scoped-signal id shape: `<scope>:<table>.<event>`.
|
|
7
|
+
*
|
|
8
|
+
* Matches exactly one `:` separating a non-empty scope from a non-empty
|
|
9
|
+
* dotted tail of at least two segments (e.g. `identity:users.created`).
|
|
10
|
+
* The scope forbids only `:` and whitespace so resource ids may contain
|
|
11
|
+
* dots for namespacing (e.g. `demo.store:gists.created`). Tail segments
|
|
12
|
+
* forbid both `:` and `.` so strings like `foo:bar` (no dot) or
|
|
13
|
+
* `a:b.c.d` stay unambiguous.
|
|
14
|
+
*/
|
|
15
|
+
const SCOPED_SIGNAL_ID = /^[^:\s]+:[^:.\s]+(?:\.[^:.\s]+)+$/;
|
|
16
|
+
const normalizeSignalRef = (entry) => {
|
|
17
|
+
if (typeof entry === 'string') {
|
|
18
|
+
return entry;
|
|
19
|
+
}
|
|
20
|
+
const ref = getLateBoundSignalRef(entry);
|
|
21
|
+
if (!ref) {
|
|
22
|
+
return entry.id;
|
|
23
|
+
}
|
|
24
|
+
// Already-scoped canonical ids (e.g. "identity:users.created") must pass
|
|
25
|
+
// through unchanged. Rewriting them to a bare marker token collapses
|
|
26
|
+
// multi-binding cases where the same store definition is bound under two
|
|
27
|
+
// separate resources: both bindings share the late-bound token, so the
|
|
28
|
+
// caller's explicit choice of scope would be lost and topo resolution
|
|
29
|
+
// would throw an ambiguity error.
|
|
30
|
+
//
|
|
31
|
+
// Use a strict predicate that matches the canonical scoped shape
|
|
32
|
+
// `<scope>:<table>.<event>` (exactly one `:` separating a non-empty scope
|
|
33
|
+
// from a non-empty dotted tail of at least two segments). A looser
|
|
34
|
+
// `includes(':')` check would let unscoped ids that happen to contain `:`
|
|
35
|
+
// slip past markerization and then fail to resolve at topo finalization.
|
|
36
|
+
if (SCOPED_SIGNAL_ID.test(entry.id)) {
|
|
37
|
+
return entry.id;
|
|
38
|
+
}
|
|
39
|
+
return createLateBoundSignalMarker(ref, entry.id);
|
|
40
|
+
};
|
|
41
|
+
/** Normalize a crosses entry — trail objects are reduced to their id. */
|
|
42
|
+
const normalizeCrossRef = (entry) => typeof entry === 'string' ? entry : entry.id;
|
|
43
|
+
/** Freeze and normalize all collection fields from a trail spec. */
|
|
44
|
+
const normalizeCollections = (spec) => ({
|
|
45
|
+
args: Array.isArray(spec.args) ? Object.freeze([...spec.args]) : spec.args,
|
|
46
|
+
contours: Object.freeze([...(spec.contours ?? [])]),
|
|
47
|
+
detours: Object.freeze([...(spec.detours ?? [])]),
|
|
48
|
+
fires: Object.freeze((spec.fires ?? []).map(normalizeSignalRef)),
|
|
49
|
+
on: Object.freeze((spec.on ?? []).map(normalizeSignalRef)),
|
|
50
|
+
resources: Object.freeze([...(spec.resources ?? [])]),
|
|
51
|
+
});
|
|
1
52
|
export function trail(idOrSpec, maybeSpec) {
|
|
2
53
|
const resolved = typeof idOrSpec === 'string'
|
|
3
54
|
? { id: idOrSpec, spec: maybeSpec }
|
|
@@ -5,16 +56,20 @@ export function trail(idOrSpec, maybeSpec) {
|
|
|
5
56
|
if (!resolved.spec) {
|
|
6
57
|
throw new TypeError('trail() requires a spec when an id is provided');
|
|
7
58
|
}
|
|
8
|
-
const { blaze, crosses: rawCrosses, intent: rawIntent,
|
|
9
|
-
|
|
59
|
+
const { blaze, crossInput, crosses: rawCrosses, intent: rawIntent, visibility: rawVisibility,
|
|
60
|
+
// Destructure away fields handled by normalizeCollections
|
|
61
|
+
args: _a, contours: _c, detours: _d, fires: _f, on: _o, resources: _r, ...spec } = resolved.spec;
|
|
62
|
+
const collections = normalizeCollections(resolved.spec);
|
|
10
63
|
return Object.freeze({
|
|
11
64
|
...spec,
|
|
65
|
+
...collections,
|
|
12
66
|
blaze: async (input, ctx) => await blaze(input, ctx),
|
|
13
|
-
|
|
67
|
+
crossInput,
|
|
68
|
+
crosses: Object.freeze((rawCrosses ?? []).map(normalizeCrossRef)),
|
|
14
69
|
id: resolved.id,
|
|
15
70
|
intent: rawIntent ?? 'write',
|
|
16
71
|
kind: 'trail',
|
|
17
|
-
|
|
72
|
+
visibility: rawVisibility ?? 'public',
|
|
18
73
|
});
|
|
19
74
|
}
|
|
20
75
|
//# sourceMappingURL=trail.js.map
|
package/dist/trail.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trail.js","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trail.js","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAuKlC,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,MAAM,kBAAkB,GAAG,CAAC,KAAyB,EAAU,EAAE;IAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,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