@haibun/core 4.0.0-alpha.2 → 4.0.0-alpha.3
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/build/currentVersion.d.ts +1 -1
- package/build/currentVersion.js +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/kireji/converter.d.ts +2 -2
- package/build/kireji/converter.d.ts.map +1 -1
- package/build/kireji/converter.js +12 -9
- package/build/kireji/converter.js.map +1 -1
- package/build/kireji/withAction.d.ts +16 -4
- package/build/kireji/withAction.d.ts.map +1 -1
- package/build/kireji/withAction.js +40 -11
- package/build/kireji/withAction.js.map +1 -1
- package/build/lib/EventLogger.d.ts +5 -5
- package/build/lib/EventLogger.d.ts.map +1 -1
- package/build/lib/EventLogger.js +39 -37
- package/build/lib/EventLogger.js.map +1 -1
- package/build/lib/PhaseRunner.d.ts +3 -3
- package/build/lib/PhaseRunner.d.ts.map +1 -1
- package/build/lib/PhaseRunner.js +7 -5
- package/build/lib/PhaseRunner.js.map +1 -1
- package/build/lib/astepper.d.ts +90 -13
- package/build/lib/astepper.d.ts.map +1 -1
- package/build/lib/astepper.js +35 -6
- package/build/lib/astepper.js.map +1 -1
- package/build/lib/base-prompt-manager.d.ts +1 -1
- package/build/lib/base-prompt-manager.d.ts.map +1 -1
- package/build/lib/base-prompt-manager.js.map +1 -1
- package/build/lib/capture-locator.d.ts +1 -1
- package/build/lib/capture-locator.d.ts.map +1 -1
- package/build/lib/capture-locator.js +5 -5
- package/build/lib/capture-locator.js.map +1 -1
- package/build/lib/core/flow-runner.d.ts +8 -7
- package/build/lib/core/flow-runner.d.ts.map +1 -1
- package/build/lib/core/flow-runner.js +42 -71
- package/build/lib/core/flow-runner.js.map +1 -1
- package/build/lib/core-domains.d.ts +2 -2
- package/build/lib/core-domains.d.ts.map +1 -1
- package/build/lib/core-domains.js +17 -18
- package/build/lib/core-domains.js.map +1 -1
- package/build/lib/defs.d.ts +2 -13
- package/build/lib/defs.d.ts.map +1 -1
- package/build/lib/defs.js.map +1 -1
- package/build/lib/document-content.d.ts +18 -0
- package/build/lib/document-content.d.ts.map +1 -0
- package/build/lib/document-content.js +158 -0
- package/build/lib/document-content.js.map +1 -0
- package/build/lib/domains.d.ts +31 -0
- package/build/lib/domains.d.ts.map +1 -0
- package/build/lib/domains.js +105 -0
- package/build/lib/domains.js.map +1 -0
- package/build/lib/execution.d.ts +304 -0
- package/build/lib/execution.d.ts.map +1 -0
- package/build/lib/execution.js +23 -0
- package/build/lib/execution.js.map +1 -0
- package/build/lib/feature-variables.d.ts +21 -50
- package/build/lib/feature-variables.d.ts.map +1 -1
- package/build/lib/feature-variables.js +122 -232
- package/build/lib/feature-variables.js.map +1 -1
- package/build/lib/features.d.ts +2 -2
- package/build/lib/features.d.ts.map +1 -1
- package/build/lib/features.js +13 -17
- package/build/lib/features.js.map +1 -1
- package/build/lib/fixme.d.ts.map +1 -1
- package/build/lib/host-id.d.ts +44 -0
- package/build/lib/host-id.d.ts.map +1 -0
- package/build/lib/host-id.js +51 -0
- package/build/lib/host-id.js.map +1 -0
- package/build/lib/http-observations.d.ts +15 -2
- package/build/lib/http-observations.d.ts.map +1 -1
- package/build/lib/http-observations.js +40 -23
- package/build/lib/http-observations.js.map +1 -1
- package/build/lib/hypermedia.d.ts +62 -0
- package/build/lib/hypermedia.d.ts.map +1 -0
- package/build/lib/hypermedia.js +228 -0
- package/build/lib/hypermedia.js.map +1 -0
- package/build/lib/namedVars.d.ts +2 -2
- package/build/lib/namedVars.d.ts.map +1 -1
- package/build/lib/namedVars.js +25 -30
- package/build/lib/namedVars.js.map +1 -1
- package/build/lib/node-http-events.d.ts +3 -3
- package/build/lib/node-http-events.d.ts.map +1 -1
- package/build/lib/node-http-events.js +26 -26
- package/build/lib/node-http-events.js.map +1 -1
- package/build/lib/populateActionArgs.d.ts +4 -4
- package/build/lib/populateActionArgs.d.ts.map +1 -1
- package/build/lib/populateActionArgs.js +4 -6
- package/build/lib/populateActionArgs.js.map +1 -1
- package/build/lib/prompter.d.ts.map +1 -1
- package/build/lib/prompter.js +10 -7
- package/build/lib/prompter.js.map +1 -1
- package/build/lib/quad-store.d.ts +34 -10
- package/build/lib/quad-store.d.ts.map +1 -1
- package/build/lib/quad-store.js +169 -21
- package/build/lib/quad-store.js.map +1 -1
- package/build/lib/quad-types.d.ts +80 -9
- package/build/lib/quad-types.d.ts.map +1 -1
- package/build/lib/quad-types.js +46 -2
- package/build/lib/quad-types.js.map +1 -1
- package/build/lib/readline-prompter.d.ts +1 -1
- package/build/lib/readline-prompter.js +4 -4
- package/build/lib/remote-stepper-proxy.d.ts +56 -0
- package/build/lib/remote-stepper-proxy.d.ts.map +1 -0
- package/build/lib/remote-stepper-proxy.js +123 -0
- package/build/lib/remote-stepper-proxy.js.map +1 -0
- package/build/lib/resolver-features.d.ts +1 -1
- package/build/lib/resolver-features.d.ts.map +1 -1
- package/build/lib/resolver-features.js +2 -2
- package/build/lib/resolver-features.js.map +1 -1
- package/build/lib/resources.d.ts +461 -0
- package/build/lib/resources.d.ts.map +1 -0
- package/build/lib/resources.js +249 -0
- package/build/lib/resources.js.map +1 -0
- package/build/lib/rpc-client.d.ts +68 -0
- package/build/lib/rpc-client.d.ts.map +1 -0
- package/build/lib/rpc-client.js +186 -0
- package/build/lib/rpc-client.js.map +1 -0
- package/build/lib/sse-subscriber.d.ts +57 -0
- package/build/lib/sse-subscriber.d.ts.map +1 -0
- package/build/lib/sse-subscriber.js +110 -0
- package/build/lib/sse-subscriber.js.map +1 -0
- package/build/lib/step-dispatch.d.ts +92 -28
- package/build/lib/step-dispatch.d.ts.map +1 -1
- package/build/lib/step-dispatch.js +331 -75
- package/build/lib/step-dispatch.js.map +1 -1
- package/build/lib/step-validation.d.ts +3 -3
- package/build/lib/step-validation.d.ts.map +1 -1
- package/build/lib/step-validation.js +2 -2
- package/build/lib/step-validation.js.map +1 -1
- package/build/lib/stepper-cycles.d.ts +5 -0
- package/build/lib/stepper-cycles.d.ts.map +1 -0
- package/build/lib/stepper-cycles.js +31 -0
- package/build/lib/stepper-cycles.js.map +1 -0
- package/build/lib/stepper-registry.d.ts +6 -3
- package/build/lib/stepper-registry.d.ts.map +1 -1
- package/build/lib/stepper-registry.js +9 -8
- package/build/lib/stepper-registry.js.map +1 -1
- package/build/lib/subprocess-runner.d.ts +35 -0
- package/build/lib/subprocess-runner.d.ts.map +1 -0
- package/build/lib/subprocess-runner.js +60 -0
- package/build/lib/subprocess-runner.js.map +1 -0
- package/build/lib/subprocess-transport.d.ts +37 -0
- package/build/lib/subprocess-transport.d.ts.map +1 -0
- package/build/lib/subprocess-transport.js +113 -0
- package/build/lib/subprocess-transport.js.map +1 -0
- package/build/lib/test/EventCollectorStepper.d.ts +3 -3
- package/build/lib/test/EventCollectorStepper.d.ts.map +1 -1
- package/build/lib/test/EventCollectorStepper.js +3 -3
- package/build/lib/test/EventCollectorStepper.js.map +1 -1
- package/build/lib/test/SetTimeStepper.d.ts +3 -3
- package/build/lib/test/SetTimeStepper.d.ts.map +1 -1
- package/build/lib/test/SetTimeStepper.js +7 -7
- package/build/lib/test/SetTimeStepper.js.map +1 -1
- package/build/lib/test/TestSteps.d.ts +7 -7
- package/build/lib/test/TestSteps.d.ts.map +1 -1
- package/build/lib/test/TestSteps.js +7 -7
- package/build/lib/test/TestSteps.js.map +1 -1
- package/build/lib/test/TestStepsWithOptions.d.ts +6 -6
- package/build/lib/test/TestStepsWithOptions.js +7 -7
- package/build/lib/test/lib.d.ts +3 -3
- package/build/lib/test/lib.d.ts.map +1 -1
- package/build/lib/test/lib.js +27 -21
- package/build/lib/test/lib.js.map +1 -1
- package/build/lib/test/resolvedTestFeatures.d.ts +6 -6
- package/build/lib/test/resolvedTestFeatures.d.ts.map +1 -1
- package/build/lib/test/resolvedTestFeatures.js +5 -5
- package/build/lib/test/subprocess-fixture.d.ts +8 -0
- package/build/lib/test/subprocess-fixture.d.ts.map +1 -0
- package/build/lib/test/subprocess-fixture.js +27 -0
- package/build/lib/test/subprocess-fixture.js.map +1 -0
- package/build/lib/ttag.d.ts +7 -1
- package/build/lib/ttag.d.ts.map +1 -1
- package/build/lib/ttag.js +5 -4
- package/build/lib/ttag.js.map +1 -1
- package/build/lib/util/dot-path.d.ts +2 -2
- package/build/lib/util/dot-path.d.ts.map +1 -1
- package/build/lib/util/dot-path.js +8 -7
- package/build/lib/util/dot-path.js.map +1 -1
- package/build/lib/util/index.d.ts +10 -24
- package/build/lib/util/index.d.ts.map +1 -1
- package/build/lib/util/index.js +43 -93
- package/build/lib/util/index.js.map +1 -1
- package/build/lib/util/node/actualURI.d.ts +4 -0
- package/build/lib/util/node/actualURI.d.ts.map +1 -0
- package/build/lib/util/node/actualURI.js +10 -0
- package/build/lib/util/node/actualURI.js.map +1 -0
- package/build/lib/util/node/module-loader.d.ts +14 -0
- package/build/lib/util/node/module-loader.d.ts.map +1 -0
- package/build/lib/util/node/module-loader.js +51 -0
- package/build/lib/util/node/module-loader.js.map +1 -0
- package/build/lib/util/node/workspace-lib.d.ts +15 -0
- package/build/lib/util/node/workspace-lib.d.ts.map +1 -0
- package/build/lib/util/node/workspace-lib.js +119 -0
- package/build/lib/util/node/workspace-lib.js.map +1 -0
- package/build/lib/util/secret-utils.d.ts.map +1 -1
- package/build/lib/util/secret-utils.js +2 -2
- package/build/lib/util/secret-utils.js.map +1 -1
- package/build/lib/vertex-crud.d.ts +22 -0
- package/build/lib/vertex-crud.d.ts.map +1 -0
- package/build/lib/vertex-crud.js +73 -0
- package/build/lib/vertex-crud.js.map +1 -0
- package/build/lib/workspace-discovery.d.ts +1 -1
- package/build/lib/workspace-discovery.d.ts.map +1 -1
- package/build/lib/workspace-discovery.js +10 -10
- package/build/lib/workspace-discovery.js.map +1 -1
- package/build/lib/zcap-like-authority.d.ts +38 -0
- package/build/lib/zcap-like-authority.d.ts.map +1 -0
- package/build/lib/zcap-like-authority.js +56 -0
- package/build/lib/zcap-like-authority.js.map +1 -0
- package/build/monitor/index.d.ts +1 -1
- package/build/monitor/index.d.ts.map +1 -1
- package/build/monitor/index.js +1 -1
- package/build/monitor/index.js.map +1 -1
- package/build/phases/Executor.d.ts +31 -7
- package/build/phases/Executor.d.ts.map +1 -1
- package/build/phases/Executor.js +201 -219
- package/build/phases/Executor.js.map +1 -1
- package/build/phases/Resolver.d.ts +2 -2
- package/build/phases/Resolver.d.ts.map +1 -1
- package/build/phases/Resolver.js +35 -30
- package/build/phases/Resolver.js.map +1 -1
- package/build/phases/collector.d.ts +3 -3
- package/build/phases/collector.d.ts.map +1 -1
- package/build/phases/collector.js +19 -17
- package/build/phases/collector.js.map +1 -1
- package/build/run-policy/run-policy-schema.d.ts +3 -5
- package/build/run-policy/run-policy-schema.d.ts.map +1 -1
- package/build/run-policy/run-policy-schema.js +41 -37
- package/build/run-policy/run-policy-schema.js.map +1 -1
- package/build/run-policy/run-policy-types.d.ts +1 -1
- package/build/run-policy/run-policy-types.d.ts.map +1 -1
- package/build/run-policy/run-policy-types.js +19 -16
- package/build/run-policy/run-policy-types.js.map +1 -1
- package/build/runner.d.ts +4 -4
- package/build/runner.d.ts.map +1 -1
- package/build/runner.js +15 -13
- package/build/runner.js.map +1 -1
- package/build/schema/protocol.d.ts +153 -61
- package/build/schema/protocol.d.ts.map +1 -1
- package/build/schema/protocol.js +177 -148
- package/build/schema/protocol.js.map +1 -1
- package/build/steps/activities-stepper.d.ts +13 -13
- package/build/steps/activities-stepper.d.ts.map +1 -1
- package/build/steps/activities-stepper.js +105 -79
- package/build/steps/activities-stepper.js.map +1 -1
- package/build/steps/conformance.d.ts +5 -5
- package/build/steps/conformance.js +4 -4
- package/build/steps/console-monitor-stepper.d.ts +2 -2
- package/build/steps/console-monitor-stepper.d.ts.map +1 -1
- package/build/steps/console-monitor-stepper.js +22 -22
- package/build/steps/console-monitor-stepper.js.map +1 -1
- package/build/steps/debugger-stepper.d.ts +11 -11
- package/build/steps/debugger-stepper.d.ts.map +1 -1
- package/build/steps/debugger-stepper.js +65 -64
- package/build/steps/debugger-stepper.js.map +1 -1
- package/build/steps/finalizer-stepper.d.ts +3 -4
- package/build/steps/finalizer-stepper.d.ts.map +1 -1
- package/build/steps/finalizer-stepper.js +16 -19
- package/build/steps/finalizer-stepper.js.map +1 -1
- package/build/steps/haibun.d.ts +27 -20
- package/build/steps/haibun.d.ts.map +1 -1
- package/build/steps/haibun.js +76 -67
- package/build/steps/haibun.js.map +1 -1
- package/build/steps/lib/tts.d.ts +1 -1
- package/build/steps/lib/tts.d.ts.map +1 -1
- package/build/steps/lib/tts.js +28 -28
- package/build/steps/lib/tts.js.map +1 -1
- package/build/steps/logic-stepper.d.ts +5 -5
- package/build/steps/logic-stepper.d.ts.map +1 -1
- package/build/steps/logic-stepper.js +76 -76
- package/build/steps/logic-stepper.js.map +1 -1
- package/build/steps/narrator.d.ts +9 -9
- package/build/steps/narrator.d.ts.map +1 -1
- package/build/steps/narrator.js +32 -28
- package/build/steps/narrator.js.map +1 -1
- package/build/steps/resources-stepper.d.ts +47 -0
- package/build/steps/resources-stepper.d.ts.map +1 -0
- package/build/steps/resources-stepper.js +100 -0
- package/build/steps/resources-stepper.js.map +1 -0
- package/build/steps/variables-stepper.d.ts +57 -57
- package/build/steps/variables-stepper.d.ts.map +1 -1
- package/build/steps/variables-stepper.js +252 -224
- package/build/steps/variables-stepper.js.map +1 -1
- package/build/steps/zcap-like-stepper.d.ts +50 -0
- package/build/steps/zcap-like-stepper.d.ts.map +1 -0
- package/build/steps/zcap-like-stepper.js +113 -0
- package/build/steps/zcap-like-stepper.js.map +1 -0
- package/package.json +1 -1
- package/build/lib/consts.d.ts +0 -5
- package/build/lib/consts.d.ts.map +0 -1
- package/build/lib/consts.js +0 -5
- package/build/lib/consts.js.map +0 -1
- package/build/lib/step-helpers.d.ts +0 -10
- package/build/lib/step-helpers.d.ts.map +0 -1
- package/build/lib/step-helpers.js +0 -16
- package/build/lib/step-helpers.js.map +0 -1
package/build/lib/quad-store.js
CHANGED
|
@@ -1,19 +1,90 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* QuadStore - In-memory quad store
|
|
2
|
+
* QuadStore - In-memory quad store with optional backing store routing
|
|
3
3
|
*
|
|
4
|
-
* Stores
|
|
5
|
-
*
|
|
4
|
+
* Stores quads as Subject-Predicate-Object-namedGraph with timestamps and optional properties.
|
|
5
|
+
* Backing stores can be registered for specific named graphs — writes route to the owning store,
|
|
6
|
+
* reads merge across all stores.
|
|
7
|
+
* Methods return Promises (via Promise.resolve) to satisfy the async IQuadStore interface.
|
|
6
8
|
*/
|
|
7
9
|
export class QuadStore {
|
|
8
10
|
quads = [];
|
|
11
|
+
backingStores = new Map();
|
|
12
|
+
registeredGraphs = new Set();
|
|
13
|
+
/** Register a backing store for specific named graphs. Writes route to it, reads merge. */
|
|
14
|
+
registerStore(store, namedGraphs) {
|
|
15
|
+
for (const ng of namedGraphs) {
|
|
16
|
+
this.backingStores.set(ng, store);
|
|
17
|
+
this.registeredGraphs.add(ng);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Copy backing store registrations to another QuadStore (for scenario boundary inheritance). */
|
|
21
|
+
inheritBackingStores(target) {
|
|
22
|
+
for (const [ng, store] of this.backingStores) {
|
|
23
|
+
target.backingStores.set(ng, store);
|
|
24
|
+
target.registeredGraphs.add(ng);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
storeFor(namedGraph) {
|
|
28
|
+
return this.backingStores.get(namedGraph);
|
|
29
|
+
}
|
|
30
|
+
get allStores() {
|
|
31
|
+
return [...new Set(this.backingStores.values())];
|
|
32
|
+
}
|
|
33
|
+
set(subject, predicate, object, namedGraph, properties) {
|
|
34
|
+
const backing = this.storeFor(namedGraph);
|
|
35
|
+
if (backing)
|
|
36
|
+
return backing.set(subject, predicate, object, namedGraph, properties);
|
|
37
|
+
this.quads = this.quads.filter((q) => !(q.subject === subject && q.predicate === predicate && q.namedGraph === namedGraph));
|
|
38
|
+
this.quads.push({ subject, predicate, object, namedGraph, timestamp: Date.now(), ...(properties ? { properties } : {}) });
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
}
|
|
41
|
+
get(subject, predicate, namedGraph) {
|
|
42
|
+
if (namedGraph) {
|
|
43
|
+
const backing = this.storeFor(namedGraph);
|
|
44
|
+
if (backing)
|
|
45
|
+
return backing.get(subject, predicate, namedGraph);
|
|
46
|
+
}
|
|
47
|
+
// Search local first
|
|
48
|
+
for (let i = this.quads.length - 1; i >= 0; i--) {
|
|
49
|
+
const q = this.quads[i];
|
|
50
|
+
if (q.subject === subject && q.predicate === predicate && (namedGraph === undefined || q.namedGraph === namedGraph))
|
|
51
|
+
return Promise.resolve(q.object);
|
|
52
|
+
}
|
|
53
|
+
// Then search backing stores if no namedGraph filter
|
|
54
|
+
if (namedGraph === undefined) {
|
|
55
|
+
return this.getFromBackingStores(subject, predicate);
|
|
56
|
+
}
|
|
57
|
+
return Promise.resolve(undefined);
|
|
58
|
+
}
|
|
59
|
+
async getFromBackingStores(subject, predicate) {
|
|
60
|
+
for (const store of this.allStores) {
|
|
61
|
+
const result = await store.get(subject, predicate);
|
|
62
|
+
if (result !== undefined)
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
9
67
|
add(quad) {
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
68
|
+
const backing = this.storeFor(quad.namedGraph);
|
|
69
|
+
if (backing)
|
|
70
|
+
return backing.add(quad);
|
|
71
|
+
this.quads.push({ ...quad, timestamp: Date.now() });
|
|
72
|
+
return Promise.resolve();
|
|
14
73
|
}
|
|
15
|
-
query(pattern) {
|
|
16
|
-
|
|
74
|
+
async query(pattern) {
|
|
75
|
+
if (pattern.namedGraph) {
|
|
76
|
+
const backing = this.storeFor(pattern.namedGraph);
|
|
77
|
+
if (backing)
|
|
78
|
+
return backing.query(pattern);
|
|
79
|
+
return this.localQuery(pattern);
|
|
80
|
+
}
|
|
81
|
+
// No namedGraph filter — merge local + all backing stores
|
|
82
|
+
const local = this.localQuery(pattern);
|
|
83
|
+
const backingResults = await Promise.all(this.allStores.map((s) => s.query(pattern)));
|
|
84
|
+
return [...local, ...backingResults.flat()].sort((a, b) => a.timestamp - b.timestamp);
|
|
85
|
+
}
|
|
86
|
+
localQuery(pattern) {
|
|
87
|
+
return this.quads.filter((q) => {
|
|
17
88
|
if (pattern.subject !== undefined && q.subject !== pattern.subject)
|
|
18
89
|
return false;
|
|
19
90
|
if (pattern.predicate !== undefined && q.predicate !== pattern.predicate)
|
|
@@ -25,23 +96,26 @@ export class QuadStore {
|
|
|
25
96
|
return true;
|
|
26
97
|
});
|
|
27
98
|
}
|
|
28
|
-
select(subject, predicate) {
|
|
29
|
-
const matches = this.query({ subject, predicate });
|
|
30
|
-
if (matches.length === 0)
|
|
31
|
-
return undefined;
|
|
32
|
-
// Return most recent
|
|
33
|
-
return matches[matches.length - 1].object;
|
|
34
|
-
}
|
|
35
99
|
clear(namedGraph) {
|
|
36
100
|
if (namedGraph) {
|
|
37
|
-
|
|
101
|
+
// Don't clear persistent backing stores — only clear ephemeral (local) data
|
|
102
|
+
if (this.registeredGraphs.has(namedGraph))
|
|
103
|
+
return Promise.resolve();
|
|
104
|
+
this.quads = this.quads.filter((q) => q.namedGraph !== namedGraph);
|
|
38
105
|
}
|
|
39
106
|
else {
|
|
107
|
+
// Clear ephemeral only
|
|
40
108
|
this.quads = [];
|
|
41
109
|
}
|
|
110
|
+
return Promise.resolve();
|
|
42
111
|
}
|
|
43
112
|
remove(pattern) {
|
|
44
|
-
|
|
113
|
+
if (pattern.namedGraph) {
|
|
114
|
+
const backing = this.storeFor(pattern.namedGraph);
|
|
115
|
+
if (backing)
|
|
116
|
+
return backing.remove(pattern);
|
|
117
|
+
}
|
|
118
|
+
this.quads = this.quads.filter((q) => {
|
|
45
119
|
if (pattern.subject !== undefined && q.subject !== pattern.subject)
|
|
46
120
|
return true;
|
|
47
121
|
if (pattern.predicate !== undefined && q.predicate !== pattern.predicate)
|
|
@@ -50,11 +124,85 @@ export class QuadStore {
|
|
|
50
124
|
return true;
|
|
51
125
|
if (pattern.namedGraph !== undefined && q.namedGraph !== pattern.namedGraph)
|
|
52
126
|
return true;
|
|
53
|
-
return false;
|
|
127
|
+
return false;
|
|
54
128
|
});
|
|
129
|
+
return Promise.resolve();
|
|
130
|
+
}
|
|
131
|
+
async all() {
|
|
132
|
+
const local = [...this.quads];
|
|
133
|
+
const backingResults = await Promise.all(this.allStores.map((s) => s.all()));
|
|
134
|
+
return [...local, ...backingResults.flat()].sort((a, b) => a.timestamp - b.timestamp);
|
|
135
|
+
}
|
|
136
|
+
// --- Vertex operations: route to backing store or local emulation ---
|
|
137
|
+
idFields = {};
|
|
138
|
+
schemas = {};
|
|
139
|
+
registerVertexType(label, schema, idField) {
|
|
140
|
+
this.schemas[label] = schema;
|
|
141
|
+
this.idFields[label] = idField;
|
|
142
|
+
}
|
|
143
|
+
async upsertVertex(label, data) {
|
|
144
|
+
const backing = this.storeFor(label);
|
|
145
|
+
if (backing)
|
|
146
|
+
return backing.upsertVertex(label, data);
|
|
147
|
+
const schema = this.schemas[label];
|
|
148
|
+
const validated = (schema ? schema.parse(data) : data);
|
|
149
|
+
const idField = this.idFields[label] ?? "id";
|
|
150
|
+
const id = String(validated[idField]);
|
|
151
|
+
if (!id)
|
|
152
|
+
throw new Error(`Missing identity field "${idField}" for ${label}`);
|
|
153
|
+
await this.remove({ subject: id, namedGraph: label });
|
|
154
|
+
for (const [key, value] of Object.entries(validated)) {
|
|
155
|
+
if (value !== undefined && value !== null) {
|
|
156
|
+
await this.add({ subject: id, predicate: key, object: value, namedGraph: label });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return id;
|
|
160
|
+
}
|
|
161
|
+
async getVertex(label, id) {
|
|
162
|
+
const backing = this.storeFor(label);
|
|
163
|
+
if (backing)
|
|
164
|
+
return backing.getVertex(label, id);
|
|
165
|
+
const quads = await this.query({ subject: id, namedGraph: label });
|
|
166
|
+
if (quads.length === 0)
|
|
167
|
+
return undefined;
|
|
168
|
+
const result = {};
|
|
169
|
+
for (const q of quads)
|
|
170
|
+
result[q.predicate] = q.object;
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
async deleteVertex(label, id) {
|
|
174
|
+
const backing = this.storeFor(label);
|
|
175
|
+
if (backing)
|
|
176
|
+
return backing.deleteVertex(label, id);
|
|
177
|
+
await this.remove({ subject: id, namedGraph: label });
|
|
178
|
+
}
|
|
179
|
+
async queryVertices(label, filters, options) {
|
|
180
|
+
const backing = this.storeFor(label);
|
|
181
|
+
if (backing)
|
|
182
|
+
return backing.queryVertices(label, filters, options);
|
|
183
|
+
const allQuads = await this.query({ namedGraph: label });
|
|
184
|
+
const subjects = [...new Set(allQuads.map((q) => q.subject))];
|
|
185
|
+
let vertices = [];
|
|
186
|
+
for (const subject of subjects) {
|
|
187
|
+
const vertex = await this.getVertex(label, subject);
|
|
188
|
+
if (vertex)
|
|
189
|
+
vertices.push(vertex);
|
|
190
|
+
}
|
|
191
|
+
if (filters) {
|
|
192
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
193
|
+
vertices = vertices.filter((v) => v[key] === value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const offset = options?.offset ?? 0;
|
|
197
|
+
const limit = options?.limit ?? vertices.length;
|
|
198
|
+
return vertices.slice(offset, offset + limit);
|
|
55
199
|
}
|
|
56
|
-
|
|
57
|
-
|
|
200
|
+
async distinctPropertyValues(label, property) {
|
|
201
|
+
const backing = this.storeFor(label);
|
|
202
|
+
if (backing)
|
|
203
|
+
return backing.distinctPropertyValues(label, property);
|
|
204
|
+
const quads = await this.query({ predicate: property, namedGraph: label });
|
|
205
|
+
return [...new Set(quads.map((q) => String(q.object)))].sort();
|
|
58
206
|
}
|
|
59
207
|
}
|
|
60
208
|
//# sourceMappingURL=quad-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quad-store.js","sourceRoot":"","sources":["../../src/lib/quad-store.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quad-store.js","sourceRoot":"","sources":["../../src/lib/quad-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,OAAO,SAAS;IACb,KAAK,GAAY,EAAE,CAAC;IACpB,aAAa,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC9C,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7C,2FAA2F;IAC3F,aAAa,CAAC,KAAiB,EAAE,WAAqB;QACrD,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;YAC9B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAClC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;IACF,CAAC;IAED,iGAAiG;IACjG,oBAAoB,CAAC,MAAiB;QACrC,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC9C,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACpC,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjC,CAAC;IACF,CAAC;IAEO,QAAQ,CAAC,UAAkB;QAClC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED,IAAY,SAAS;QACpB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,GAAG,CACF,OAAe,EACf,SAAiB,EACjB,MAAe,EACf,UAAkB,EAClB,UAAoC;QAEpC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,C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K,CAAC,CAAC;YACrD,CAAC;QACF,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC;QAChD,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAQ,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,KAAa,EAAE,QAAgB;QAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC,sBAAsB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACpE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3E,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChE,CAAC;CACD"}
|
|
@@ -1,14 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* QuadStore Types for Core
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Property graph quad model — each quad can carry optional properties,
|
|
5
|
+
* aligning with AGE's vertex properties for seamless PG persistence.
|
|
6
|
+
* All methods are async to support both in-memory and database-backed stores.
|
|
5
7
|
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
export declare const DOMAIN_GRAPH_QUERY = "graph-query";
|
|
10
|
+
export declare const SearchConditionSchema: z.ZodObject<{
|
|
11
|
+
predicate: z.ZodString;
|
|
12
|
+
operator: z.ZodEnum<{
|
|
13
|
+
eq: "eq";
|
|
14
|
+
contains: "contains";
|
|
15
|
+
gt: "gt";
|
|
16
|
+
lt: "lt";
|
|
17
|
+
gte: "gte";
|
|
18
|
+
lte: "lte";
|
|
19
|
+
between: "between";
|
|
20
|
+
}>;
|
|
21
|
+
value: z.ZodString;
|
|
22
|
+
value2: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export declare const GraphQuerySchema: z.ZodObject<{
|
|
25
|
+
label: z.ZodOptional<z.ZodString>;
|
|
26
|
+
filters: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
27
|
+
predicate: z.ZodString;
|
|
28
|
+
operator: z.ZodEnum<{
|
|
29
|
+
eq: "eq";
|
|
30
|
+
contains: "contains";
|
|
31
|
+
gt: "gt";
|
|
32
|
+
lt: "lt";
|
|
33
|
+
gte: "gte";
|
|
34
|
+
lte: "lte";
|
|
35
|
+
between: "between";
|
|
36
|
+
}>;
|
|
37
|
+
value: z.ZodString;
|
|
38
|
+
value2: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>>>;
|
|
40
|
+
textQuery: z.ZodOptional<z.ZodString>;
|
|
41
|
+
sortBy: z.ZodOptional<z.ZodString>;
|
|
42
|
+
sortOrder: z.ZodDefault<z.ZodEnum<{
|
|
43
|
+
asc: "asc";
|
|
44
|
+
desc: "desc";
|
|
45
|
+
}>>;
|
|
46
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
47
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
48
|
+
accessLevel: z.ZodDefault<z.ZodEnum<{
|
|
49
|
+
private: "private";
|
|
50
|
+
public: "public";
|
|
51
|
+
opened: "opened";
|
|
52
|
+
all: "all";
|
|
53
|
+
}>>;
|
|
54
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
55
|
+
explain: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
export type TGraphQuery = z.infer<typeof GraphQuerySchema>;
|
|
58
|
+
export { type ResourceRels, buildResourceRels, parseTimestampValue } from "./hypermedia.js";
|
|
6
59
|
export interface TQuad {
|
|
7
60
|
subject: string;
|
|
8
61
|
predicate: string;
|
|
9
62
|
object: unknown;
|
|
10
63
|
namedGraph: string;
|
|
11
64
|
timestamp: number;
|
|
65
|
+
properties?: Record<string, unknown>;
|
|
12
66
|
}
|
|
13
67
|
export interface TQuadPattern {
|
|
14
68
|
subject?: string;
|
|
@@ -16,18 +70,35 @@ export interface TQuadPattern {
|
|
|
16
70
|
object?: unknown;
|
|
17
71
|
namedGraph?: string;
|
|
18
72
|
}
|
|
73
|
+
/** Emit a quadObservation event via an event logger. Canonical envelope for all quad emissions. */
|
|
74
|
+
export declare function emitQuadObservation(logger: {
|
|
75
|
+
emit: (e: Record<string, unknown>) => void;
|
|
76
|
+
}, id: string, quad: TQuad): void;
|
|
77
|
+
/** Extract quadObservation quads from haibun event log entries. */
|
|
78
|
+
export declare function extractQuadsFromEvents(events: Record<string, unknown>[]): TQuad[];
|
|
19
79
|
export interface IQuadStore {
|
|
20
|
-
/**
|
|
21
|
-
|
|
80
|
+
/** Set a value (upserts: replaces existing quad with same subject+predicate+namedGraph) */
|
|
81
|
+
set(subject: string, predicate: string, object: unknown, namedGraph: string, properties?: Record<string, unknown>): Promise<void>;
|
|
82
|
+
/** Get the most recent value for a subject-predicate pair */
|
|
83
|
+
get(subject: string, predicate: string, namedGraph?: string): Promise<unknown | undefined>;
|
|
84
|
+
/** Add a quad to the store (appends, does not upsert) */
|
|
85
|
+
add(quad: Omit<TQuad, "timestamp">): Promise<void>;
|
|
22
86
|
/** Query quads matching a pattern */
|
|
23
|
-
query(pattern: TQuadPattern): TQuad[]
|
|
24
|
-
/** Select the most recent value for a subject-predicate pair */
|
|
25
|
-
select(subject: string, predicate: string): unknown | undefined;
|
|
87
|
+
query(pattern: TQuadPattern): Promise<TQuad[]>;
|
|
26
88
|
/** Clear quads, optionally filtered by namedGraph */
|
|
27
|
-
clear(namedGraph?: string): void
|
|
89
|
+
clear(namedGraph?: string): Promise<void>;
|
|
28
90
|
/** Remove quads matching a pattern */
|
|
29
|
-
remove(pattern: TQuadPattern): void
|
|
91
|
+
remove(pattern: TQuadPattern): Promise<void>;
|
|
30
92
|
/** Get all quads */
|
|
31
|
-
all(): TQuad[]
|
|
93
|
+
all(): Promise<TQuad[]>;
|
|
94
|
+
/** Vertex operations — convenience over quads. namedGraph = vertex label. */
|
|
95
|
+
upsertVertex(label: string, data: unknown): Promise<string>;
|
|
96
|
+
getVertex<T = Record<string, unknown>>(label: string, id: string): Promise<T | undefined>;
|
|
97
|
+
deleteVertex(label: string, id: string): Promise<void>;
|
|
98
|
+
queryVertices<T = Record<string, unknown>>(label: string, filters?: Record<string, unknown>, options?: {
|
|
99
|
+
limit?: number;
|
|
100
|
+
offset?: number;
|
|
101
|
+
}): Promise<T[]>;
|
|
102
|
+
distinctPropertyValues(label: string, property: string): Promise<string[]>;
|
|
32
103
|
}
|
|
33
104
|
//# sourceMappingURL=quad-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quad-types.d.ts","sourceRoot":"","sources":["../../src/lib/quad-types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quad-types.d.ts","sourceRoot":"","sources":["../../src/lib/quad-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;iBAKhC,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAW3B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE3D,OAAO,EAAE,KAAK,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE5F,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
|
|
2
2
|
* QuadStore Types for Core
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Property graph quad model — each quad can carry optional properties,
|
|
5
|
+
* aligning with AGE's vertex properties for seamless PG persistence.
|
|
6
|
+
* All methods are async to support both in-memory and database-backed stores.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// --- Graph query schema (core domain, used by any graph/quad query UI) ---
|
|
10
|
+
export const DOMAIN_GRAPH_QUERY = "graph-query";
|
|
11
|
+
export const SearchConditionSchema = z.object({
|
|
12
|
+
predicate: z.string().min(1),
|
|
13
|
+
operator: z.enum(["eq", "contains", "gt", "lt", "gte", "lte", "between"]),
|
|
14
|
+
value: z.string(),
|
|
15
|
+
value2: z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
export const GraphQuerySchema = z.object({
|
|
18
|
+
label: z.string().optional(),
|
|
19
|
+
filters: z.array(SearchConditionSchema).default([]),
|
|
20
|
+
textQuery: z.string().optional(),
|
|
21
|
+
sortBy: z.string().optional(),
|
|
22
|
+
sortOrder: z.enum(["asc", "desc"]).default("desc"),
|
|
23
|
+
limit: z.number().int().positive().default(50),
|
|
24
|
+
offset: z.number().int().nonnegative().default(0),
|
|
25
|
+
accessLevel: z.enum(["private", "public", "opened", "all"]).default("private"),
|
|
26
|
+
fields: z.array(z.string()).optional(),
|
|
27
|
+
explain: z.boolean().default(false),
|
|
28
|
+
});
|
|
29
|
+
export { buildResourceRels, parseTimestampValue } from "./hypermedia.js";
|
|
30
|
+
/** Emit a quadObservation event via an event logger. Canonical envelope for all quad emissions. */
|
|
31
|
+
export function emitQuadObservation(logger, id, quad) {
|
|
32
|
+
logger.emit({
|
|
33
|
+
id, timestamp: quad.timestamp, source: "haibun", level: "debug", kind: "artifact", artifactType: "json", mimetype: "application/json",
|
|
34
|
+
json: { quadObservation: quad },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Extract quadObservation quads from haibun event log entries. */
|
|
38
|
+
export function extractQuadsFromEvents(events) {
|
|
39
|
+
const quads = [];
|
|
40
|
+
for (const e of events) {
|
|
41
|
+
if (e.kind !== "artifact" || e.artifactType !== "json")
|
|
42
|
+
continue;
|
|
43
|
+
const json = e.json;
|
|
44
|
+
const q = json?.quadObservation;
|
|
45
|
+
if (q?.subject && q.predicate && q.namedGraph) {
|
|
46
|
+
quads.push({ subject: q.subject, predicate: q.predicate, object: q.object, namedGraph: q.namedGraph, timestamp: q.timestamp ?? e.timestamp ?? Date.now(), properties: q.properties });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return quads;
|
|
50
|
+
}
|
|
7
51
|
//# sourceMappingURL=quad-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quad-types.js","sourceRoot":"","sources":["../../src/lib/quad-types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quad-types.js","sourceRoot":"","sources":["../../src/lib/quad-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,4EAA4E;AAE5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEhD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IACzE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE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AAQ,EAAE,kBAAkB;QACrI,IAAI,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE;KAC/B,CAAC,CAAC;AACJ,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,sBAAsB,CAAC,MAAiC;IACvE,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,YAAY,KAAK,MAAM;YAAE,SAAS;QACjE,MAAM,IAAI,GAAG,CAAC,CAAC,IAA+C,CAAC;QAC/D,MAAM,CAAC,GAAG,IAAI,EAAE,eAAe,CAAC;QAChC,IAAI,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;YAC/C,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,IAAK,CAAC,CAAC,SAAoB,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;QACnM,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createInterface } from
|
|
2
|
-
import { stdin as input, stdout as output } from
|
|
1
|
+
import { createInterface } from "readline/promises";
|
|
2
|
+
import { stdin as input, stdout as output } from "process";
|
|
3
3
|
export class ReadlinePrompter {
|
|
4
4
|
rl;
|
|
5
5
|
currentPromptId;
|
|
@@ -14,10 +14,10 @@ export class ReadlinePrompter {
|
|
|
14
14
|
output,
|
|
15
15
|
history: this.history,
|
|
16
16
|
historySize: 100,
|
|
17
|
-
removeHistoryDuplicates: true
|
|
17
|
+
removeHistoryDuplicates: true,
|
|
18
18
|
});
|
|
19
19
|
try {
|
|
20
|
-
const answer = await this.rl.question(`${prompt.message} ${prompt.options?.join(
|
|
20
|
+
const answer = await this.rl.question(`${prompt.message} ${prompt.options?.join(", ") ?? ""}: `);
|
|
21
21
|
if (answer && answer.trim() && !this.history.includes(answer.trim())) {
|
|
22
22
|
this.history.unshift(answer.trim());
|
|
23
23
|
if (this.history.length > 100) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* remote-stepper-proxy.ts
|
|
3
|
+
*
|
|
4
|
+
* Client-side proxy for a remote haibun host. Fetches step descriptors via
|
|
5
|
+
* the host's step.list RPC endpoint, then injects proxy StepTools into
|
|
6
|
+
* the parent registry. Each proxy handler forwards calls over HTTP with
|
|
7
|
+
* an Authorization: Bearer header.
|
|
8
|
+
*
|
|
9
|
+
* Follows the same pattern as SubprocessTransport.injectInto() but uses
|
|
10
|
+
* HTTP/JSON-RPC instead of Node.js fork() IPC.
|
|
11
|
+
*/
|
|
12
|
+
import { AStepper } from "./astepper.js";
|
|
13
|
+
import type { TWorld } from "./execution.js";
|
|
14
|
+
import { type StepRegistry } from "./step-dispatch.js";
|
|
15
|
+
import type { StepDescriptor } from "./stepper-registry.js";
|
|
16
|
+
export declare class RemoteStepperProxy extends AStepper {
|
|
17
|
+
private remoteUrl;
|
|
18
|
+
private token?;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
private stepDescriptors;
|
|
21
|
+
private rpc;
|
|
22
|
+
/**
|
|
23
|
+
* Remote host's hostId, discovered at setWorld via session.beginAction.
|
|
24
|
+
* Used to prefix registry keys so multiple remotes (and local) don't
|
|
25
|
+
* collide on identical method names.
|
|
26
|
+
*/
|
|
27
|
+
private hostId;
|
|
28
|
+
constructor(remoteUrl: string, token?: string);
|
|
29
|
+
setWorld(world: TWorld, steppers: AStepper[]): Promise<void>;
|
|
30
|
+
/** Read hostId from session.beginAction so injected tools carry a correct prefix. */
|
|
31
|
+
private discoverHostId;
|
|
32
|
+
/** The remote host's hostId. Undefined before setWorld completes. */
|
|
33
|
+
get remoteHostId(): number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Fetch step.list from the remote host. step.list is introspection,
|
|
36
|
+
* explicitly exempt from the seqPath-required rule (per commit 5), so
|
|
37
|
+
* we pass an empty seqPath — the remote's step.list handler doesn't
|
|
38
|
+
* look at it.
|
|
39
|
+
*/
|
|
40
|
+
private fetchStepDescriptors;
|
|
41
|
+
/**
|
|
42
|
+
* Inject proxy StepTools into the parent registry. Remote tools are
|
|
43
|
+
* keyed `${hostId}:${method}` so they never collide with local tools
|
|
44
|
+
* (bare method names) or with other remote hosts.
|
|
45
|
+
*/
|
|
46
|
+
injectInto(registry: StepRegistry): void;
|
|
47
|
+
/** Call a step on the remote host via shared RpcClient. */
|
|
48
|
+
private call;
|
|
49
|
+
/** IStepTransport.attach — duck-typed, no import needed from web-server-hono. */
|
|
50
|
+
attach(registry: StepRegistry, _webserver: unknown): void;
|
|
51
|
+
/** IStepTransport.detach — nothing to clean up for HTTP transport. */
|
|
52
|
+
detach(): void;
|
|
53
|
+
get descriptors(): StepDescriptor[];
|
|
54
|
+
steps: {};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=remote-stepper-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-stepper-proxy.d.ts","sourceRoot":"","sources":["../../src/lib/remote-stepper-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAiB,KAAK,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AAC5F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,qBAAa,kBAAmB,SAAQ,QAAQ;IAY9C,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK,CAAC;IAZf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,GAAG,CAAY;IACvB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAqB;gBAG1B,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM;IASjB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMlE,qFAAqF;YACvE,cAAc;IAY5B,qEAAqE;IACrE,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;;;;OAKG;YACW,oBAAoB;IAQlC;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IA+BxC,2DAA2D;YAC7C,IAAI;IAQlB,iFAAiF;IACjF,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI;IAIzD,sEAAsE;IACtE,MAAM,IAAI,IAAI;IAId,IAAI,WAAW,IAAI,cAAc,EAAE,CAElC;IAED,KAAK,KAAM;CACX"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* remote-stepper-proxy.ts
|
|
3
|
+
*
|
|
4
|
+
* Client-side proxy for a remote haibun host. Fetches step descriptors via
|
|
5
|
+
* the host's step.list RPC endpoint, then injects proxy StepTools into
|
|
6
|
+
* the parent registry. Each proxy handler forwards calls over HTTP with
|
|
7
|
+
* an Authorization: Bearer header.
|
|
8
|
+
*
|
|
9
|
+
* Follows the same pattern as SubprocessTransport.injectInto() but uses
|
|
10
|
+
* HTTP/JSON-RPC instead of Node.js fork() IPC.
|
|
11
|
+
*/
|
|
12
|
+
import { AStepper } from "./astepper.js";
|
|
13
|
+
import { actionNotOK } from "./util/index.js";
|
|
14
|
+
import { hostScopedMethodName } from "./step-dispatch.js";
|
|
15
|
+
import { RpcClient } from "./rpc-client.js";
|
|
16
|
+
export class RemoteStepperProxy extends AStepper {
|
|
17
|
+
remoteUrl;
|
|
18
|
+
token;
|
|
19
|
+
name;
|
|
20
|
+
stepDescriptors = [];
|
|
21
|
+
rpc;
|
|
22
|
+
/**
|
|
23
|
+
* Remote host's hostId, discovered at setWorld via session.beginAction.
|
|
24
|
+
* Used to prefix registry keys so multiple remotes (and local) don't
|
|
25
|
+
* collide on identical method names.
|
|
26
|
+
*/
|
|
27
|
+
hostId;
|
|
28
|
+
constructor(remoteUrl, token) {
|
|
29
|
+
super();
|
|
30
|
+
this.remoteUrl = remoteUrl;
|
|
31
|
+
this.token = token;
|
|
32
|
+
const host = new URL(remoteUrl).host;
|
|
33
|
+
this.name = `RemoteProxy_${host.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
34
|
+
this.description = `Proxy for remote stepper host at ${remoteUrl}`;
|
|
35
|
+
this.rpc = new RpcClient({ baseUrl: remoteUrl, capabilityToken: token });
|
|
36
|
+
}
|
|
37
|
+
async setWorld(world, steppers) {
|
|
38
|
+
await super.setWorld(world, steppers);
|
|
39
|
+
await this.discoverHostId();
|
|
40
|
+
await this.fetchStepDescriptors();
|
|
41
|
+
}
|
|
42
|
+
/** Read hostId from session.beginAction so injected tools carry a correct prefix. */
|
|
43
|
+
async discoverHostId() {
|
|
44
|
+
const result = await this.rpc.call("session.beginAction", {}, []);
|
|
45
|
+
if ("error" in result) {
|
|
46
|
+
throw new Error(`RemoteStepperProxy: session.beginAction failed at ${this.remoteUrl}: ${result.error}`);
|
|
47
|
+
}
|
|
48
|
+
const id = result.hostId ?? result.seqPath?.[0];
|
|
49
|
+
if (typeof id !== "number") {
|
|
50
|
+
throw new Error(`RemoteStepperProxy: session.beginAction at ${this.remoteUrl} did not surface a hostId`);
|
|
51
|
+
}
|
|
52
|
+
this.hostId = id;
|
|
53
|
+
}
|
|
54
|
+
/** The remote host's hostId. Undefined before setWorld completes. */
|
|
55
|
+
get remoteHostId() {
|
|
56
|
+
return this.hostId;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetch step.list from the remote host. step.list is introspection,
|
|
60
|
+
* explicitly exempt from the seqPath-required rule (per commit 5), so
|
|
61
|
+
* we pass an empty seqPath — the remote's step.list handler doesn't
|
|
62
|
+
* look at it.
|
|
63
|
+
*/
|
|
64
|
+
async fetchStepDescriptors() {
|
|
65
|
+
const result = await this.rpc.call("step.list", {}, []);
|
|
66
|
+
if ("error" in result) {
|
|
67
|
+
throw new Error(`RemoteStepperProxy: step.list failed at ${this.remoteUrl}: ${result.error}`);
|
|
68
|
+
}
|
|
69
|
+
this.stepDescriptors = result.steps ?? [];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Inject proxy StepTools into the parent registry. Remote tools are
|
|
73
|
+
* keyed `${hostId}:${method}` so they never collide with local tools
|
|
74
|
+
* (bare method names) or with other remote hosts.
|
|
75
|
+
*/
|
|
76
|
+
injectInto(registry) {
|
|
77
|
+
if (this.hostId === undefined)
|
|
78
|
+
throw new Error("RemoteStepperProxy.injectInto called before setWorld discovered the host id");
|
|
79
|
+
for (const descriptor of this.stepDescriptors) {
|
|
80
|
+
const prefixedMethod = hostScopedMethodName(this.hostId, descriptor.method);
|
|
81
|
+
const tool = {
|
|
82
|
+
name: prefixedMethod,
|
|
83
|
+
description: descriptor.pattern,
|
|
84
|
+
inputSchema: descriptor.inputSchema ?? { type: "object" },
|
|
85
|
+
paramSchemas: new Map(),
|
|
86
|
+
paramDomainKeys: new Map(),
|
|
87
|
+
stepperName: descriptor.stepperName,
|
|
88
|
+
stepName: descriptor.stepName,
|
|
89
|
+
capability: descriptor.capability,
|
|
90
|
+
isAsync: true,
|
|
91
|
+
transport: "remote",
|
|
92
|
+
remoteHost: new URL(this.remoteUrl).host,
|
|
93
|
+
// Dispatch over RPC using the un-prefixed method name — the prefix is
|
|
94
|
+
// a local registry-naming concern, not part of the wire call.
|
|
95
|
+
handler: (_featureStep, _world) => this.call(descriptor.method, _featureStep.action?.stepValuesMap
|
|
96
|
+
? Object.fromEntries(Object.entries(_featureStep.action.stepValuesMap).map(([k, v]) => [k, v.term]))
|
|
97
|
+
: {}, _featureStep.seqPath),
|
|
98
|
+
};
|
|
99
|
+
registry.set(tool);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Call a step on the remote host via shared RpcClient. */
|
|
103
|
+
async call(method, params, seqPath = []) {
|
|
104
|
+
const result = await this.rpc.call(method, params, seqPath);
|
|
105
|
+
if ("error" in result && typeof result.error === "string") {
|
|
106
|
+
return actionNotOK(`${method}: ${result.error}`);
|
|
107
|
+
}
|
|
108
|
+
return { ok: true, products: result };
|
|
109
|
+
}
|
|
110
|
+
/** IStepTransport.attach — duck-typed, no import needed from web-server-hono. */
|
|
111
|
+
attach(registry, _webserver) {
|
|
112
|
+
this.injectInto(registry);
|
|
113
|
+
}
|
|
114
|
+
/** IStepTransport.detach — nothing to clean up for HTTP transport. */
|
|
115
|
+
detach() {
|
|
116
|
+
/* no-op */
|
|
117
|
+
}
|
|
118
|
+
get descriptors() {
|
|
119
|
+
return this.stepDescriptors;
|
|
120
|
+
}
|
|
121
|
+
steps = {};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=remote-stepper-proxy.js.map
|