@ontrails/core 1.0.0-beta.14 → 1.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +11 -0
- package/README.md +17 -13
- 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/draft.d.ts +5 -5
- package/dist/draft.d.ts.map +1 -1
- package/dist/draft.js +28 -27
- package/dist/draft.js.map +1 -1
- 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 +31 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -13
- 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 +8 -2
- package/dist/internal/topo-saves.d.ts.map +1 -1
- package/dist/internal/topo-saves.js +162 -23
- package/dist/internal/topo-saves.js.map +1 -1
- 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 +23 -20
- package/dist/internal/topo-store-read.d.ts.map +1 -1
- package/dist/internal/topo-store-read.js +82 -83
- package/dist/internal/topo-store-read.js.map +1 -1
- package/dist/internal/topo-store.d.ts +19 -5
- package/dist/internal/topo-store.d.ts.map +1 -1
- package/dist/internal/topo-store.js +174 -124
- package/dist/internal/topo-store.js.map +1 -1
- 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 +2 -2
- package/dist/internal/trails-db.d.ts.map +1 -1
- package/dist/internal/trails-db.js +8 -8
- package/dist/internal/trails-db.js.map +1 -1
- 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 +36 -22
- package/dist/topo-store.d.ts.map +1 -1
- package/dist/topo-store.js +215 -71
- package/dist/topo-store.js.map +1 -1
- 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.js +2 -2
- package/dist/validate-established-topo.js.map +1 -1
- package/dist/validate-topo.d.ts.map +1 -1
- package/dist/validate-topo.js +24 -7
- 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 +8 -2
- 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__/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 +41 -36
- package/src/__tests__/topo-store.test.ts +493 -93
- package/src/__tests__/topo.test.ts +350 -54
- package/src/__tests__/trail.test.ts +189 -24
- package/src/__tests__/trails-db.test.ts +32 -25
- 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 +147 -25
- 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/draft.ts +56 -52
- package/src/errors.ts +62 -18
- package/src/execute.ts +840 -29
- package/src/fire.ts +295 -0
- package/src/index.ts +116 -29
- 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 +140 -132
- package/src/internal/topo-store.ts +291 -186
- package/src/internal/tracing.ts +187 -0
- package/src/internal/trails-db.ts +9 -11
- 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 +313 -104
- 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 +2 -2
- package/src/validate-topo.ts +32 -8
- 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/internal/topo-saves.ts +0 -429
- package/src/provision.ts +0 -148
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { Database, SQLQueryBindings } from 'bun:sqlite';
|
|
2
2
|
|
|
3
3
|
import { ValidationError } from '../errors.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
ListTopoSnapshotsOptions,
|
|
6
|
+
TopoSnapshot,
|
|
7
|
+
} from './topo-snapshots.js';
|
|
5
8
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from './topo-saves.js';
|
|
9
|
+
listTopoSnapshots,
|
|
10
|
+
readPinnedTopoSnapshot,
|
|
11
|
+
readTopoSnapshot,
|
|
12
|
+
} from './topo-snapshots.js';
|
|
11
13
|
import type { StoredTopoExport } from './topo-store.js';
|
|
12
14
|
import { getStoredTopoExport } from './topo-store.js';
|
|
13
15
|
|
|
14
16
|
export interface TopoStoreRef {
|
|
15
17
|
readonly pin?: string;
|
|
16
|
-
readonly
|
|
18
|
+
readonly snapshotId?: string;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export interface TopoStoreTrailRecord {
|
|
@@ -26,8 +28,9 @@ export interface TopoStoreTrailRecord {
|
|
|
26
28
|
readonly intent: 'destroy' | 'read' | 'write';
|
|
27
29
|
readonly kind: 'trail';
|
|
28
30
|
readonly meta: Readonly<Record<string, unknown>> | null;
|
|
31
|
+
readonly pattern: string | null;
|
|
29
32
|
readonly safety: '-' | 'destroy' | 'read' | 'write';
|
|
30
|
-
readonly
|
|
33
|
+
readonly snapshotId: string;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export interface TopoStoreExampleRecord {
|
|
@@ -41,25 +44,27 @@ export interface TopoStoreExampleRecord {
|
|
|
41
44
|
|
|
42
45
|
export interface TopoStoreTrailDetailRecord extends TopoStoreTrailRecord {
|
|
43
46
|
readonly crosses: readonly string[];
|
|
44
|
-
readonly detours:
|
|
47
|
+
readonly detours:
|
|
48
|
+
| readonly { readonly on: string; readonly maxAttempts: number }[]
|
|
49
|
+
| null;
|
|
45
50
|
readonly examples: readonly TopoStoreExampleRecord[];
|
|
46
|
-
readonly
|
|
51
|
+
readonly resources: readonly string[];
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
export interface
|
|
54
|
+
export interface TopoStoreResourceRecord {
|
|
50
55
|
readonly description: string | null;
|
|
51
56
|
readonly hasHealth: boolean;
|
|
52
57
|
readonly hasMock: boolean;
|
|
53
58
|
readonly health: 'available' | 'none';
|
|
54
59
|
readonly id: string;
|
|
55
|
-
readonly kind: '
|
|
60
|
+
readonly kind: 'resource';
|
|
56
61
|
readonly lifetime: 'singleton';
|
|
57
|
-
readonly
|
|
62
|
+
readonly snapshotId: string;
|
|
58
63
|
readonly usedBy: readonly string[];
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
export interface TopoStoreExportRecord extends StoredTopoExport {
|
|
62
|
-
readonly
|
|
67
|
+
readonly snapshot: TopoSnapshot;
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
interface TopoTrailRow {
|
|
@@ -71,15 +76,16 @@ interface TopoTrailRow {
|
|
|
71
76
|
readonly idempotent: number;
|
|
72
77
|
readonly intent: string | null;
|
|
73
78
|
readonly meta: string | null;
|
|
74
|
-
readonly
|
|
79
|
+
readonly pattern: string | null;
|
|
80
|
+
readonly snapshot_id: string;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
interface TopoCrossingRow {
|
|
78
84
|
readonly target_id: string;
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
interface
|
|
82
|
-
readonly
|
|
87
|
+
interface TopoTrailResourceRow {
|
|
88
|
+
readonly resource_id: string;
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
interface TopoExampleRow {
|
|
@@ -91,29 +97,32 @@ interface TopoExampleRow {
|
|
|
91
97
|
readonly ordinal: number;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
interface
|
|
100
|
+
interface TopoResourceRow {
|
|
95
101
|
readonly has_health: number;
|
|
96
102
|
readonly has_mock: number;
|
|
97
103
|
readonly id: string;
|
|
98
|
-
readonly
|
|
104
|
+
readonly snapshot_id: string;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
interface
|
|
107
|
+
interface StoredSurfaceMapEntry {
|
|
102
108
|
readonly description?: string;
|
|
103
|
-
readonly detours?:
|
|
109
|
+
readonly detours?: readonly {
|
|
110
|
+
readonly on: string;
|
|
111
|
+
readonly maxAttempts: number;
|
|
112
|
+
}[];
|
|
104
113
|
readonly healthcheck?: boolean;
|
|
105
114
|
readonly id: string;
|
|
106
|
-
readonly kind: '
|
|
115
|
+
readonly kind: 'contour' | 'resource' | 'signal' | 'trail';
|
|
107
116
|
}
|
|
108
117
|
|
|
109
|
-
interface
|
|
110
|
-
readonly entries: readonly
|
|
118
|
+
interface StoredSurfaceMap {
|
|
119
|
+
readonly entries: readonly StoredSurfaceMapEntry[];
|
|
111
120
|
}
|
|
112
121
|
|
|
113
122
|
const ensureSingleRefSelector = (ref?: TopoStoreRef): void => {
|
|
114
|
-
if (ref?.pin !== undefined && ref.
|
|
123
|
+
if (ref?.pin !== undefined && ref.snapshotId !== undefined) {
|
|
115
124
|
throw new ValidationError(
|
|
116
|
-
'Topo store references may use pin or
|
|
125
|
+
'Topo store references may use pin or snapshotId, not both'
|
|
117
126
|
);
|
|
118
127
|
}
|
|
119
128
|
};
|
|
@@ -148,37 +157,36 @@ const parseMeta = (
|
|
|
148
157
|
|
|
149
158
|
const parseJson = (value: string): unknown => JSON.parse(value) as unknown;
|
|
150
159
|
|
|
151
|
-
const
|
|
160
|
+
const readSnapshotRef = (
|
|
152
161
|
db: Database,
|
|
153
162
|
ref?: TopoStoreRef
|
|
154
|
-
):
|
|
163
|
+
): TopoSnapshot | undefined => {
|
|
155
164
|
ensureSingleRefSelector(ref);
|
|
156
165
|
|
|
157
|
-
if (ref?.
|
|
158
|
-
return
|
|
166
|
+
if (ref?.snapshotId !== undefined) {
|
|
167
|
+
return readTopoSnapshot(db, ref.snapshotId);
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
if (ref?.pin !== undefined) {
|
|
162
|
-
|
|
163
|
-
return pin === undefined ? undefined : getTopoSave(db, pin.saveId);
|
|
171
|
+
return readPinnedTopoSnapshot(db, ref.pin);
|
|
164
172
|
}
|
|
165
173
|
|
|
166
|
-
return
|
|
174
|
+
return listTopoSnapshots(db, { limit: 1 })[0];
|
|
167
175
|
};
|
|
168
176
|
|
|
169
177
|
const readStoredEntry = (
|
|
170
178
|
db: Database,
|
|
171
|
-
|
|
172
|
-
kind:
|
|
179
|
+
snapshotId: string,
|
|
180
|
+
kind: StoredSurfaceMapEntry['kind'],
|
|
173
181
|
id: string
|
|
174
|
-
):
|
|
175
|
-
const stored = getStoredTopoExport(db,
|
|
182
|
+
): StoredSurfaceMapEntry | undefined => {
|
|
183
|
+
const stored = getStoredTopoExport(db, snapshotId);
|
|
176
184
|
if (stored === undefined) {
|
|
177
185
|
return undefined;
|
|
178
186
|
}
|
|
179
187
|
|
|
180
|
-
const map = JSON.parse(stored.
|
|
181
|
-
return map.entries.find((entry) => entry.
|
|
188
|
+
const map = JSON.parse(stored.surfaceMapJson) as StoredSurfaceMap;
|
|
189
|
+
return map.entries.find((entry) => entry.id === id && entry.kind === kind);
|
|
182
190
|
};
|
|
183
191
|
|
|
184
192
|
const mapTrailRow = (row: TopoTrailRow): TopoStoreTrailRecord => {
|
|
@@ -194,54 +202,55 @@ const mapTrailRow = (row: TopoTrailRow): TopoStoreTrailRecord => {
|
|
|
194
202
|
intent,
|
|
195
203
|
kind: 'trail',
|
|
196
204
|
meta: parseMeta(row.meta),
|
|
205
|
+
pattern: row.pattern,
|
|
197
206
|
safety: safetyForIntent(intent),
|
|
198
|
-
|
|
207
|
+
snapshotId: row.snapshot_id,
|
|
199
208
|
};
|
|
200
209
|
};
|
|
201
210
|
|
|
202
211
|
const readTrailCrossings = (
|
|
203
212
|
db: Database,
|
|
204
|
-
|
|
213
|
+
snapshotId: string,
|
|
205
214
|
trailId: string
|
|
206
215
|
): readonly string[] =>
|
|
207
216
|
db
|
|
208
217
|
.query<TopoCrossingRow, [string, string]>(
|
|
209
218
|
`SELECT target_id
|
|
210
219
|
FROM topo_crossings
|
|
211
|
-
WHERE
|
|
220
|
+
WHERE snapshot_id = ? AND source_id = ?
|
|
212
221
|
ORDER BY target_id ASC`
|
|
213
222
|
)
|
|
214
|
-
.all(
|
|
223
|
+
.all(snapshotId, trailId)
|
|
215
224
|
.map((row) => row.target_id);
|
|
216
225
|
|
|
217
|
-
const
|
|
226
|
+
const readTrailResourceIds = (
|
|
218
227
|
db: Database,
|
|
219
|
-
|
|
228
|
+
snapshotId: string,
|
|
220
229
|
trailId: string
|
|
221
230
|
): readonly string[] =>
|
|
222
231
|
db
|
|
223
|
-
.query<
|
|
224
|
-
`SELECT
|
|
225
|
-
FROM
|
|
226
|
-
WHERE
|
|
227
|
-
ORDER BY
|
|
232
|
+
.query<TopoTrailResourceRow, [string, string]>(
|
|
233
|
+
`SELECT resource_id
|
|
234
|
+
FROM topo_trail_resources
|
|
235
|
+
WHERE snapshot_id = ? AND trail_id = ?
|
|
236
|
+
ORDER BY resource_id ASC`
|
|
228
237
|
)
|
|
229
|
-
.all(
|
|
230
|
-
.map((row) => row.
|
|
238
|
+
.all(snapshotId, trailId)
|
|
239
|
+
.map((row) => row.resource_id);
|
|
231
240
|
|
|
232
241
|
const readTrailExamples = (
|
|
233
242
|
db: Database,
|
|
234
|
-
|
|
243
|
+
snapshotId: string,
|
|
235
244
|
trailId: string
|
|
236
245
|
): readonly TopoStoreExampleRecord[] =>
|
|
237
246
|
db
|
|
238
247
|
.query<TopoExampleRow, [string, string]>(
|
|
239
248
|
`SELECT ordinal, name, description, input, expected, error
|
|
240
249
|
FROM topo_examples
|
|
241
|
-
WHERE
|
|
250
|
+
WHERE snapshot_id = ? AND trail_id = ?
|
|
242
251
|
ORDER BY ordinal ASC`
|
|
243
252
|
)
|
|
244
|
-
.all(
|
|
253
|
+
.all(snapshotId, trailId)
|
|
245
254
|
.map((row) => ({
|
|
246
255
|
description: row.description,
|
|
247
256
|
error: row.error,
|
|
@@ -251,24 +260,24 @@ const readTrailExamples = (
|
|
|
251
260
|
ordinal: row.ordinal,
|
|
252
261
|
}));
|
|
253
262
|
|
|
254
|
-
const
|
|
263
|
+
const readResourceUsage = (
|
|
255
264
|
db: Database,
|
|
256
|
-
|
|
265
|
+
snapshotId: string
|
|
257
266
|
): ReadonlyMap<string, readonly string[]> => {
|
|
258
267
|
const rows = db
|
|
259
|
-
.query<{
|
|
260
|
-
`SELECT
|
|
261
|
-
FROM
|
|
262
|
-
WHERE
|
|
263
|
-
ORDER BY
|
|
268
|
+
.query<{ resource_id: string; trail_id: string }, [string]>(
|
|
269
|
+
`SELECT resource_id, trail_id
|
|
270
|
+
FROM topo_trail_resources
|
|
271
|
+
WHERE snapshot_id = ?
|
|
272
|
+
ORDER BY resource_id ASC, trail_id ASC`
|
|
264
273
|
)
|
|
265
|
-
.all(
|
|
274
|
+
.all(snapshotId);
|
|
266
275
|
|
|
267
276
|
const usage = new Map<string, string[]>();
|
|
268
277
|
for (const row of rows) {
|
|
269
|
-
const trails = usage.get(row.
|
|
278
|
+
const trails = usage.get(row.resource_id) ?? [];
|
|
270
279
|
trails.push(row.trail_id);
|
|
271
|
-
usage.set(row.
|
|
280
|
+
usage.set(row.resource_id, trails);
|
|
272
281
|
}
|
|
273
282
|
|
|
274
283
|
return new Map(
|
|
@@ -276,34 +285,33 @@ const readProvisionUsage = (
|
|
|
276
285
|
);
|
|
277
286
|
};
|
|
278
287
|
|
|
279
|
-
export const
|
|
288
|
+
export const readTopoStoreSnapshot = (
|
|
280
289
|
db: Database,
|
|
281
290
|
ref?: TopoStoreRef
|
|
282
|
-
):
|
|
291
|
+
): TopoSnapshot | undefined => readSnapshotRef(db, ref);
|
|
283
292
|
|
|
284
|
-
export const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
listTopoSaves(db);
|
|
293
|
+
export const listTopoStoreSnapshots = (
|
|
294
|
+
db: Database,
|
|
295
|
+
options?: ListTopoSnapshotsOptions
|
|
296
|
+
): readonly TopoSnapshot[] => listTopoSnapshots(db, options);
|
|
289
297
|
|
|
290
298
|
export const getTopoStoreExport = (
|
|
291
299
|
db: Database,
|
|
292
300
|
ref?: TopoStoreRef
|
|
293
301
|
): TopoStoreExportRecord | undefined => {
|
|
294
|
-
const
|
|
295
|
-
if (
|
|
302
|
+
const snapshot = readSnapshotRef(db, ref);
|
|
303
|
+
if (snapshot === undefined) {
|
|
296
304
|
return undefined;
|
|
297
305
|
}
|
|
298
306
|
|
|
299
|
-
const stored = getStoredTopoExport(db,
|
|
307
|
+
const stored = getStoredTopoExport(db, snapshot.id);
|
|
300
308
|
if (stored === undefined) {
|
|
301
309
|
return undefined;
|
|
302
310
|
}
|
|
303
311
|
|
|
304
312
|
return {
|
|
305
313
|
...stored,
|
|
306
|
-
|
|
314
|
+
snapshot,
|
|
307
315
|
};
|
|
308
316
|
};
|
|
309
317
|
|
|
@@ -311,36 +319,36 @@ export const listTopoStoreTrails = (
|
|
|
311
319
|
db: Database,
|
|
312
320
|
options?: {
|
|
313
321
|
readonly intent?: TopoStoreTrailRecord['intent'];
|
|
314
|
-
readonly
|
|
322
|
+
readonly snapshot?: TopoStoreRef;
|
|
315
323
|
}
|
|
316
324
|
): readonly TopoStoreTrailRecord[] => {
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
325
|
+
const snapshot = readSnapshotRef(db, options?.snapshot);
|
|
326
|
+
if (snapshot === undefined) {
|
|
319
327
|
return [];
|
|
320
328
|
}
|
|
321
329
|
|
|
322
|
-
const baseQuery = `SELECT id, intent, idempotent, has_output, has_examples, example_count, description, meta,
|
|
330
|
+
const baseQuery = `SELECT id, intent, idempotent, has_output, has_examples, example_count, description, pattern, meta, snapshot_id
|
|
323
331
|
FROM topo_trails`;
|
|
324
332
|
|
|
325
333
|
let rows: TopoTrailRow[];
|
|
326
334
|
if (options?.intent === undefined) {
|
|
327
335
|
rows = db
|
|
328
336
|
.query<TopoTrailRow, [string]>(
|
|
329
|
-
`${baseQuery} WHERE
|
|
337
|
+
`${baseQuery} WHERE snapshot_id = ? ORDER BY id ASC`
|
|
330
338
|
)
|
|
331
|
-
.all(
|
|
339
|
+
.all(snapshot.id);
|
|
332
340
|
} else if (options.intent === 'write') {
|
|
333
341
|
rows = db
|
|
334
342
|
.query<TopoTrailRow, [string]>(
|
|
335
|
-
`${baseQuery} WHERE
|
|
343
|
+
`${baseQuery} WHERE snapshot_id = ? AND intent = 'write' ORDER BY id ASC`
|
|
336
344
|
)
|
|
337
|
-
.all(
|
|
345
|
+
.all(snapshot.id);
|
|
338
346
|
} else {
|
|
339
347
|
rows = db
|
|
340
348
|
.query<TopoTrailRow, [string, string]>(
|
|
341
|
-
`${baseQuery} WHERE
|
|
349
|
+
`${baseQuery} WHERE snapshot_id = ? AND intent = ? ORDER BY id ASC`
|
|
342
350
|
)
|
|
343
|
-
.all(
|
|
351
|
+
.all(snapshot.id, options.intent);
|
|
344
352
|
}
|
|
345
353
|
|
|
346
354
|
return rows.map(mapTrailRow);
|
|
@@ -349,42 +357,42 @@ export const listTopoStoreTrails = (
|
|
|
349
357
|
export const getTopoStoreTrail = (
|
|
350
358
|
db: Database,
|
|
351
359
|
trailId: string,
|
|
352
|
-
options?: { readonly
|
|
360
|
+
options?: { readonly snapshot?: TopoStoreRef }
|
|
353
361
|
): TopoStoreTrailDetailRecord | undefined => {
|
|
354
|
-
const
|
|
355
|
-
if (
|
|
362
|
+
const snapshot = readSnapshotRef(db, options?.snapshot);
|
|
363
|
+
if (snapshot === undefined) {
|
|
356
364
|
return undefined;
|
|
357
365
|
}
|
|
358
366
|
|
|
359
367
|
const row = db
|
|
360
368
|
.query<TopoTrailRow, [string, string]>(
|
|
361
|
-
`SELECT id, intent, idempotent, has_output, has_examples, example_count, description, meta,
|
|
369
|
+
`SELECT id, intent, idempotent, has_output, has_examples, example_count, description, pattern, meta, snapshot_id
|
|
362
370
|
FROM topo_trails
|
|
363
|
-
WHERE
|
|
371
|
+
WHERE snapshot_id = ? AND id = ?
|
|
364
372
|
LIMIT 1`
|
|
365
373
|
)
|
|
366
|
-
.get(
|
|
374
|
+
.get(snapshot.id, trailId);
|
|
367
375
|
|
|
368
376
|
if (row === null || row === undefined) {
|
|
369
377
|
return undefined;
|
|
370
378
|
}
|
|
371
379
|
|
|
372
|
-
const storedEntry = readStoredEntry(db,
|
|
380
|
+
const storedEntry = readStoredEntry(db, snapshot.id, 'trail', trailId);
|
|
373
381
|
|
|
374
382
|
return {
|
|
375
383
|
...mapTrailRow(row),
|
|
376
|
-
crosses: readTrailCrossings(db,
|
|
384
|
+
crosses: readTrailCrossings(db, snapshot.id, trailId),
|
|
377
385
|
detours: storedEntry?.detours ?? null,
|
|
378
|
-
examples: readTrailExamples(db,
|
|
379
|
-
|
|
386
|
+
examples: readTrailExamples(db, snapshot.id, trailId),
|
|
387
|
+
resources: readTrailResourceIds(db, snapshot.id, trailId),
|
|
380
388
|
};
|
|
381
389
|
};
|
|
382
390
|
|
|
383
|
-
const
|
|
384
|
-
row:
|
|
391
|
+
const mapResourceRow = (
|
|
392
|
+
row: TopoResourceRow,
|
|
385
393
|
usedBy: readonly string[],
|
|
386
|
-
storedEntry?:
|
|
387
|
-
):
|
|
394
|
+
storedEntry?: StoredSurfaceMapEntry
|
|
395
|
+
): TopoStoreResourceRecord => ({
|
|
388
396
|
description: storedEntry?.description ?? null,
|
|
389
397
|
hasHealth: row.has_health === 1,
|
|
390
398
|
hasMock: row.has_mock === 1,
|
|
@@ -393,73 +401,73 @@ const mapProvisionRow = (
|
|
|
393
401
|
? 'available'
|
|
394
402
|
: 'none',
|
|
395
403
|
id: row.id,
|
|
396
|
-
kind: '
|
|
404
|
+
kind: 'resource',
|
|
397
405
|
lifetime: 'singleton',
|
|
398
|
-
|
|
406
|
+
snapshotId: row.snapshot_id,
|
|
399
407
|
usedBy,
|
|
400
408
|
});
|
|
401
409
|
|
|
402
|
-
export const
|
|
410
|
+
export const listTopoStoreResources = (
|
|
403
411
|
db: Database,
|
|
404
|
-
options?: { readonly
|
|
405
|
-
): readonly
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
412
|
+
options?: { readonly snapshot?: TopoStoreRef }
|
|
413
|
+
): readonly TopoStoreResourceRecord[] => {
|
|
414
|
+
const snapshot = readSnapshotRef(db, options?.snapshot);
|
|
415
|
+
if (snapshot === undefined) {
|
|
408
416
|
return [];
|
|
409
417
|
}
|
|
410
418
|
|
|
411
|
-
const usage =
|
|
419
|
+
const usage = readResourceUsage(db, snapshot.id);
|
|
412
420
|
const rows = db
|
|
413
|
-
.query<
|
|
414
|
-
`SELECT id, has_mock, has_health,
|
|
415
|
-
FROM
|
|
416
|
-
WHERE
|
|
421
|
+
.query<TopoResourceRow, [string]>(
|
|
422
|
+
`SELECT id, has_mock, has_health, snapshot_id
|
|
423
|
+
FROM topo_resources
|
|
424
|
+
WHERE snapshot_id = ?
|
|
417
425
|
ORDER BY id ASC`
|
|
418
426
|
)
|
|
419
|
-
.all(
|
|
427
|
+
.all(snapshot.id);
|
|
420
428
|
|
|
421
|
-
const stored = getStoredTopoExport(db,
|
|
429
|
+
const stored = getStoredTopoExport(db, snapshot.id);
|
|
422
430
|
const entries = stored
|
|
423
|
-
? (JSON.parse(stored.
|
|
431
|
+
? (JSON.parse(stored.surfaceMapJson) as StoredSurfaceMap).entries
|
|
424
432
|
: [];
|
|
425
433
|
|
|
426
434
|
return rows.map((row) =>
|
|
427
|
-
|
|
435
|
+
mapResourceRow(
|
|
428
436
|
row,
|
|
429
437
|
usage.get(row.id) ?? [],
|
|
430
|
-
entries.find((
|
|
438
|
+
entries.find((entry) => entry.id === row.id && entry.kind === 'resource')
|
|
431
439
|
)
|
|
432
440
|
);
|
|
433
441
|
};
|
|
434
442
|
|
|
435
|
-
export const
|
|
443
|
+
export const getTopoStoreResource = (
|
|
436
444
|
db: Database,
|
|
437
|
-
|
|
438
|
-
options?: { readonly
|
|
439
|
-
):
|
|
440
|
-
const
|
|
441
|
-
if (
|
|
445
|
+
resourceId: string,
|
|
446
|
+
options?: { readonly snapshot?: TopoStoreRef }
|
|
447
|
+
): TopoStoreResourceRecord | undefined => {
|
|
448
|
+
const snapshot = readSnapshotRef(db, options?.snapshot);
|
|
449
|
+
if (snapshot === undefined) {
|
|
442
450
|
return undefined;
|
|
443
451
|
}
|
|
444
452
|
|
|
445
453
|
const row = db
|
|
446
|
-
.query<
|
|
447
|
-
`SELECT id, has_mock, has_health,
|
|
448
|
-
FROM
|
|
449
|
-
WHERE
|
|
454
|
+
.query<TopoResourceRow, [string, string]>(
|
|
455
|
+
`SELECT id, has_mock, has_health, snapshot_id
|
|
456
|
+
FROM topo_resources
|
|
457
|
+
WHERE snapshot_id = ? AND id = ?
|
|
450
458
|
LIMIT 1`
|
|
451
459
|
)
|
|
452
|
-
.get(
|
|
460
|
+
.get(snapshot.id, resourceId);
|
|
453
461
|
|
|
454
462
|
if (row === null || row === undefined) {
|
|
455
463
|
return undefined;
|
|
456
464
|
}
|
|
457
465
|
|
|
458
|
-
const usage =
|
|
459
|
-
return
|
|
466
|
+
const usage = readResourceUsage(db, snapshot.id);
|
|
467
|
+
return mapResourceRow(
|
|
460
468
|
row,
|
|
461
|
-
usage.get(
|
|
462
|
-
readStoredEntry(db,
|
|
469
|
+
usage.get(resourceId) ?? [],
|
|
470
|
+
readStoredEntry(db, snapshot.id, 'resource', resourceId)
|
|
463
471
|
);
|
|
464
472
|
};
|
|
465
473
|
|