@peers-app/peers-sdk 0.27.3 → 0.27.4
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/dist/contracts/contract-proxy.d.ts +7 -0
- package/dist/contracts/contract-proxy.js +19 -2
- package/dist/contracts/create-local-consumer.js +16 -1
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/system/index.d.ts +2 -0
- package/dist/contracts/system/index.js +2 -0
- package/dist/contracts/system/invites-contract.js +2 -1
- package/dist/contracts/system/sync-check-contract.d.ts +97 -0
- package/dist/contracts/system/sync-check-contract.js +115 -0
- package/dist/contracts/tool-arguments.d.ts +15 -0
- package/dist/contracts/tool-arguments.js +41 -0
- package/dist/contracts/tool-catalog-service.js +2 -12
- package/dist/data/change-tracking.d.ts +40 -0
- package/dist/data/change-tracking.js +89 -0
- package/dist/data/orm/types.d.ts +24 -7
- package/dist/data/orm/types.js +97 -24
- package/dist/define/manifest.js +6 -34
- package/dist/package-loader/package-loader.js +27 -22
- package/dist/system-ids.d.ts +5 -0
- package/dist/system-ids.js +6 -1
- package/package.json +4 -2
- package/dist/context/user-context-identity.test.d.ts +0 -1
- package/dist/context/user-context-identity.test.js +0 -220
- package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
- package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
- package/dist/contracts/__tests__/also-implements.test.js +0 -110
- package/dist/contracts/__tests__/builder.test.d.ts +0 -1
- package/dist/contracts/__tests__/builder.test.js +0 -669
- package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-events.test.js +0 -199
- package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-observables.test.js +0 -290
- package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
- package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
- package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
- package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
- package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-transport.test.js +0 -163
- package/dist/contracts/__tests__/extract.test.d.ts +0 -1
- package/dist/contracts/__tests__/extract.test.js +0 -145
- package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
- package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
- package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
- package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
- package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
- package/dist/contracts/__tests__/integration.test.d.ts +0 -1
- package/dist/contracts/__tests__/integration.test.js +0 -348
- package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
- package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
- package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
- package/dist/contracts/__tests__/playground.test.d.ts +0 -1
- package/dist/contracts/__tests__/playground.test.js +0 -216
- package/dist/contracts/__tests__/registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/registry.test.js +0 -238
- package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
- package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/system-contracts.test.js +0 -247
- package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
- package/dist/contracts/__tests__/target-dispatch.js +0 -24
- package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
- package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
- package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
- package/dist/contracts/__tests__/validate.test.d.ts +0 -1
- package/dist/contracts/__tests__/validate.test.js +0 -991
- package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
- package/dist/contracts/__tests__/workflow-context.test.js +0 -50
- package/dist/data/access-level.test.d.ts +0 -1
- package/dist/data/access-level.test.js +0 -53
- package/dist/data/change-tracking.test.d.ts +0 -1
- package/dist/data/change-tracking.test.js +0 -62
- package/dist/data/files/files.test.d.ts +0 -1
- package/dist/data/files/files.test.js +0 -770
- package/dist/data/group-members.test.d.ts +0 -1
- package/dist/data/group-members.test.js +0 -336
- package/dist/data/group-share.test.d.ts +0 -1
- package/dist/data/group-share.test.js +0 -110
- package/dist/data/groups.test.d.ts +0 -1
- package/dist/data/groups.test.js +0 -153
- package/dist/data/orm/cursor.test.d.ts +0 -1
- package/dist/data/orm/cursor.test.js +0 -314
- package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
- package/dist/data/orm/data-query.mongo.test.js +0 -367
- package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
- package/dist/data/orm/data-query.sqlite.test.js +0 -365
- package/dist/data/orm/data-query.test.d.ts +0 -1
- package/dist/data/orm/data-query.test.js +0 -545
- package/dist/data/orm/dependency-injection.test.d.ts +0 -1
- package/dist/data/orm/dependency-injection.test.js +0 -171
- package/dist/data/orm/event-registry.test.d.ts +0 -1
- package/dist/data/orm/event-registry.test.js +0 -44
- package/dist/data/orm/multi-cursors.test.d.ts +0 -1
- package/dist/data/orm/multi-cursors.test.js +0 -463
- package/dist/data/orm/sql.data-source.test.d.ts +0 -1
- package/dist/data/orm/sql.data-source.test.js +0 -731
- package/dist/data/orm/table-container-events.test.d.ts +0 -1
- package/dist/data/orm/table-container-events.test.js +0 -101
- package/dist/data/orm/table-container.test.d.ts +0 -1
- package/dist/data/orm/table-container.test.js +0 -273
- package/dist/data/orm/table.event-source.test.d.ts +0 -1
- package/dist/data/orm/table.event-source.test.js +0 -331
- package/dist/data/orm/types.test.d.ts +0 -1
- package/dist/data/orm/types.test.js +0 -409
- package/dist/data/package-table-identity.test.d.ts +0 -1
- package/dist/data/package-table-identity.test.js +0 -46
- package/dist/data/package-version-permissions.test.d.ts +0 -1
- package/dist/data/package-version-permissions.test.js +0 -107
- package/dist/data/package-version-resolver.test.d.ts +0 -4
- package/dist/data/package-version-resolver.test.js +0 -543
- package/dist/data/package-versions.test.d.ts +0 -1
- package/dist/data/package-versions.test.js +0 -227
- package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
- package/dist/data/persistent-vars.conflict.test.js +0 -126
- package/dist/data/persistent-vars.migration.test.d.ts +0 -1
- package/dist/data/persistent-vars.migration.test.js +0 -133
- package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
- package/dist/data/persistent-vars.package-scope.test.js +0 -27
- package/dist/data/sync-recovery-queue.test.d.ts +0 -1
- package/dist/data/sync-recovery-queue.test.js +0 -215
- package/dist/data/table-signing.test.d.ts +0 -1
- package/dist/data/table-signing.test.js +0 -118
- package/dist/data/tool-access.test.d.ts +0 -1
- package/dist/data/tool-access.test.js +0 -166
- package/dist/data/user-permissions.test.d.ts +0 -1
- package/dist/data/user-permissions.test.js +0 -305
- package/dist/data/user-trust-levels.test.d.ts +0 -1
- package/dist/data/user-trust-levels.test.js +0 -37
- package/dist/define/also-implements.test.d.ts +0 -1
- package/dist/define/also-implements.test.js +0 -123
- package/dist/define/declare-contract.test.d.ts +0 -1
- package/dist/define/declare-contract.test.js +0 -573
- package/dist/define/define.test.d.ts +0 -1
- package/dist/define/define.test.js +0 -1010
- package/dist/define/empty-fields.test.d.ts +0 -1
- package/dist/define/empty-fields.test.js +0 -55
- package/dist/define/events-observables.test.d.ts +0 -1
- package/dist/define/events-observables.test.js +0 -1013
- package/dist/define/serve-members.test.d.ts +0 -1
- package/dist/define/serve-members.test.js +0 -630
- package/dist/define/vars.test.d.ts +0 -1
- package/dist/define/vars.test.js +0 -39
- package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
- package/dist/device/binary-peer-connection-v2.test.js +0 -730
- package/dist/device/binary-peer-connection.test.d.ts +0 -1
- package/dist/device/binary-peer-connection.test.js +0 -184
- package/dist/device/connection.test.d.ts +0 -1
- package/dist/device/connection.test.js +0 -613
- package/dist/device/device-election.test.d.ts +0 -1
- package/dist/device/device-election.test.js +0 -516
- package/dist/device/device.test.d.ts +0 -1
- package/dist/device/device.test.js +0 -243
- package/dist/device/frame-cipher.test.d.ts +0 -1
- package/dist/device/frame-cipher.test.js +0 -219
- package/dist/device/get-trust-level-fn.test.d.ts +0 -1
- package/dist/device/get-trust-level-fn.test.js +0 -685
- package/dist/device/streamed-socket.test.d.ts +0 -1
- package/dist/device/streamed-socket.test.js +0 -216
- package/dist/device/tx-encoding.test.d.ts +0 -1
- package/dist/device/tx-encoding.test.js +0 -295
- package/dist/device-pairing/cpace.test.d.ts +0 -1
- package/dist/device-pairing/cpace.test.js +0 -116
- package/dist/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/device-pairing/device-pairing.test.js +0 -211
- package/dist/hlc.test.d.ts +0 -1
- package/dist/hlc.test.js +0 -45
- package/dist/host-credentials.test.d.ts +0 -1
- package/dist/host-credentials.test.js +0 -88
- package/dist/identity/account-email.test.d.ts +0 -1
- package/dist/identity/account-email.test.js +0 -59
- package/dist/identity/anchor-document.test.d.ts +0 -1
- package/dist/identity/anchor-document.test.js +0 -16
- package/dist/identity/anchor-resolution.test.d.ts +0 -1
- package/dist/identity/anchor-resolution.test.js +0 -130
- package/dist/identity/key-change.test.d.ts +0 -1
- package/dist/identity/key-change.test.js +0 -811
- package/dist/invites/group-approval.test.d.ts +0 -1
- package/dist/invites/group-approval.test.js +0 -223
- package/dist/invites/invite-token.test.d.ts +0 -1
- package/dist/invites/invite-token.test.js +0 -123
- package/dist/keys.test.d.ts +0 -1
- package/dist/keys.test.js +0 -336
- package/dist/logging/console-logger.test.d.ts +0 -1
- package/dist/logging/console-logger.test.js +0 -300
- package/dist/logging/console-logs.table.test.d.ts +0 -1
- package/dist/logging/console-logs.table.test.js +0 -156
- package/dist/observable.test.d.ts +0 -1
- package/dist/observable.test.js +0 -309
- package/dist/package-build/build-package.test.d.ts +0 -1
- package/dist/package-build/build-package.test.js +0 -204
- package/dist/package-build/contract-add.test.d.ts +0 -1
- package/dist/package-build/contract-add.test.js +0 -467
- package/dist/package-build/freeze-contracts.test.d.ts +0 -1
- package/dist/package-build/freeze-contracts.test.js +0 -355
- package/dist/package-installer/package-author-signing.test.d.ts +0 -1
- package/dist/package-installer/package-author-signing.test.js +0 -200
- package/dist/package-installer/package-cloner.test.d.ts +0 -1
- package/dist/package-installer/package-cloner.test.js +0 -278
- package/dist/package-installer/package-creator.test.d.ts +0 -1
- package/dist/package-installer/package-creator.test.js +0 -908
- package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
- package/dist/package-installer/package-dev-tools.test.js +0 -64
- package/dist/package-installer/package-installer.test.d.ts +0 -1
- package/dist/package-installer/package-installer.test.js +0 -882
- package/dist/package-installer/package-propagation.test.d.ts +0 -1
- package/dist/package-installer/package-propagation.test.js +0 -1269
- package/dist/package-installer/package-publisher.test.d.ts +0 -1
- package/dist/package-installer/package-publisher.test.js +0 -153
- package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
- package/dist/package-installer/package-remote-checker.test.js +0 -334
- package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
- package/dist/package-installer/package-seed-installer.test.js +0 -123
- package/dist/package-installer/package-tarball.test.d.ts +0 -1
- package/dist/package-installer/package-tarball.test.js +0 -75
- package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
- package/dist/package-installer/peers-core-installer.test.js +0 -49
- package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
- package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
- package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
- package/dist/package-loader/contract-package-loader.test.js +0 -274
- package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
- package/dist/package-loader/host-authority-loading.test.js +0 -104
- package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
- package/dist/package-loader/host-dispatch-policy.test.js +0 -56
- package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
- package/dist/package-loader/isolated-artifact.test.js +0 -688
- package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
- package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-table-gateway.test.js +0 -633
- package/dist/package-loader/package-loader.test.d.ts +0 -1
- package/dist/package-loader/package-loader.test.js +0 -1764
- package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
- package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
- package/dist/serial-json.compat.test.d.ts +0 -1
- package/dist/serial-json.compat.test.js +0 -369
- package/dist/serial-json.test.d.ts +0 -1
- package/dist/serial-json.test.js +0 -401
- package/dist/testing/mock-host-contract.test.d.ts +0 -1
- package/dist/testing/mock-host-contract.test.js +0 -782
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -232
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const field_type_1 = require("../../types/field-type");
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const contract_proxy_1 = require("../contract-proxy");
|
|
6
|
-
const contract_transport_1 = require("../contract-transport");
|
|
7
|
-
describe("inProcessTransportPair", () => {
|
|
8
|
-
it("delivers a request to the peer handler and resolves with its return (ack)", async () => {
|
|
9
|
-
const [a, b] = (0, contract_transport_1.inProcessTransportPair)();
|
|
10
|
-
b.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, (x, y) => x + y);
|
|
11
|
-
await expect(a.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, 2, 3)).resolves.toBe(5);
|
|
12
|
-
});
|
|
13
|
-
it("awaits async handlers before resolving the emit", async () => {
|
|
14
|
-
const [a, b] = (0, contract_transport_1.inProcessTransportPair)();
|
|
15
|
-
b.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, async (value) => {
|
|
16
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
17
|
-
return `handled:${value}`;
|
|
18
|
-
});
|
|
19
|
-
await expect(a.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, "x")).resolves.toBe("handled:x");
|
|
20
|
-
});
|
|
21
|
-
it("propagates a thrown handler error as a rejected emit", async () => {
|
|
22
|
-
const [a, b] = (0, contract_transport_1.inProcessTransportPair)();
|
|
23
|
-
b.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, () => {
|
|
24
|
-
throw new Error("boom");
|
|
25
|
-
});
|
|
26
|
-
await expect(a.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, {})).rejects.toThrow("boom");
|
|
27
|
-
});
|
|
28
|
-
it("propagates a rejected async handler as a rejected emit", async () => {
|
|
29
|
-
const [a, b] = (0, contract_transport_1.inProcessTransportPair)();
|
|
30
|
-
b.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, async () => {
|
|
31
|
-
throw new Error("async-boom");
|
|
32
|
-
});
|
|
33
|
-
await expect(a.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, {})).rejects.toThrow("async-boom");
|
|
34
|
-
});
|
|
35
|
-
it("resolves undefined when the peer has no handler for the channel", async () => {
|
|
36
|
-
const [a] = (0, contract_transport_1.inProcessTransportPair)();
|
|
37
|
-
await expect(a.emit("no-such-channel", 1)).resolves.toBeUndefined();
|
|
38
|
-
});
|
|
39
|
-
it("stops delivering after unsubscribe", async () => {
|
|
40
|
-
const [a, b] = (0, contract_transport_1.inProcessTransportPair)();
|
|
41
|
-
const handler = jest.fn(() => "ok");
|
|
42
|
-
const unsubscribe = b.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, handler);
|
|
43
|
-
await expect(a.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, 1)).resolves.toBe("ok");
|
|
44
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
45
|
-
unsubscribe();
|
|
46
|
-
await expect(a.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, 1)).resolves.toBeUndefined();
|
|
47
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
48
|
-
});
|
|
49
|
-
it("is bidirectional: either end can emit and handle", async () => {
|
|
50
|
-
const [a, b] = (0, contract_transport_1.inProcessTransportPair)();
|
|
51
|
-
a.on("ping", (msg) => `a-got:${msg}`);
|
|
52
|
-
b.on("ping", (msg) => `b-got:${msg}`);
|
|
53
|
-
// a -> b uses b's handler; b -> a uses a's handler.
|
|
54
|
-
await expect(a.emit("ping", "hi")).resolves.toBe("b-got:hi");
|
|
55
|
-
await expect(b.emit("ping", "yo")).resolves.toBe("a-got:yo");
|
|
56
|
-
});
|
|
57
|
-
it("supports provider->consumer pushes on the notify channel (fire-and-forget)", async () => {
|
|
58
|
-
const [consumer, provider] = (0, contract_transport_1.inProcessTransportPair)();
|
|
59
|
-
const received = [];
|
|
60
|
-
consumer.on(contract_transport_1.CONTRACT_NOTIFY_CHANNEL, (payload) => {
|
|
61
|
-
received.push(payload);
|
|
62
|
-
});
|
|
63
|
-
// The provider pushes and ignores the returned promise, exactly as a notification would.
|
|
64
|
-
void provider.emit(contract_transport_1.CONTRACT_NOTIFY_CHANNEL, { event: "changed", id: "abc" });
|
|
65
|
-
// The ack is still available if awaited, but pushes typically drop it.
|
|
66
|
-
await expect(provider.emit(contract_transport_1.CONTRACT_NOTIFY_CHANNEL, { event: "again" })).resolves.toBeUndefined();
|
|
67
|
-
expect(received).toEqual([{ event: "changed", id: "abc" }, { event: "again" }]);
|
|
68
|
-
});
|
|
69
|
-
it("rejects multiple request handlers instead of using last-result-wins", () => {
|
|
70
|
-
const [, provider] = (0, contract_transport_1.inProcessTransportPair)();
|
|
71
|
-
provider.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, () => "first");
|
|
72
|
-
expect(() => provider.on(contract_transport_1.CONTRACT_REQUEST_CHANNEL, () => "second")).toThrow(/one provider router/);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe("connectionContractTransport", () => {
|
|
76
|
-
it("delegates emit to the underlying emitter", async () => {
|
|
77
|
-
const emit = jest.fn(async () => "result");
|
|
78
|
-
const emitter = { emit, on: jest.fn() };
|
|
79
|
-
const transport = (0, contract_transport_1.connectionContractTransport)(emitter);
|
|
80
|
-
await expect(transport.emit(contract_transport_1.CONTRACT_REQUEST_CHANNEL, { a: 1 })).resolves.toBe("result");
|
|
81
|
-
expect(emit).toHaveBeenCalledWith(contract_transport_1.CONTRACT_REQUEST_CHANNEL, { a: 1 });
|
|
82
|
-
});
|
|
83
|
-
it("removes only the requested handler from a shared channel dispatcher", async () => {
|
|
84
|
-
const listeners = new Map();
|
|
85
|
-
const on = jest.fn((channel, listener) => {
|
|
86
|
-
listeners.set(channel, listener);
|
|
87
|
-
});
|
|
88
|
-
const emitter = { emit: jest.fn(), on };
|
|
89
|
-
const transportA = (0, contract_transport_1.connectionContractTransport)(emitter);
|
|
90
|
-
const transportB = (0, contract_transport_1.connectionContractTransport)(emitter);
|
|
91
|
-
const handlerA = jest.fn();
|
|
92
|
-
const handlerB = jest.fn();
|
|
93
|
-
const unsubscribeA = transportA.on(contract_transport_1.CONTRACT_NOTIFY_CHANNEL, handlerA);
|
|
94
|
-
transportB.on(contract_transport_1.CONTRACT_NOTIFY_CHANNEL, handlerB);
|
|
95
|
-
expect(on).toHaveBeenCalledTimes(1);
|
|
96
|
-
await listeners.get(contract_transport_1.CONTRACT_NOTIFY_CHANNEL)?.("first");
|
|
97
|
-
expect(handlerA).toHaveBeenCalledWith("first");
|
|
98
|
-
expect(handlerB).toHaveBeenCalledWith("first");
|
|
99
|
-
unsubscribeA();
|
|
100
|
-
unsubscribeA();
|
|
101
|
-
await listeners.get(contract_transport_1.CONTRACT_NOTIFY_CHANNEL)?.("second");
|
|
102
|
-
expect(handlerA).toHaveBeenCalledTimes(1);
|
|
103
|
-
expect(handlerB).toHaveBeenLastCalledWith("second");
|
|
104
|
-
});
|
|
105
|
-
it("lets two consumers share notify traffic and dispose independently", async () => {
|
|
106
|
-
const listeners = new Map();
|
|
107
|
-
const emitter = {
|
|
108
|
-
emit: jest.fn(async () => undefined),
|
|
109
|
-
on: (channel, listener) => {
|
|
110
|
-
listeners.set(channel, listener);
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
const transport = (0, contract_transport_1.connectionContractTransport)(emitter);
|
|
114
|
-
const contract = {
|
|
115
|
-
contractId: (0, utils_1.newid)(),
|
|
116
|
-
version: 1,
|
|
117
|
-
devTag: "dev",
|
|
118
|
-
name: "Shared transport",
|
|
119
|
-
description: "Shared notify channel",
|
|
120
|
-
tables: [],
|
|
121
|
-
tools: [],
|
|
122
|
-
observables: [],
|
|
123
|
-
events: [
|
|
124
|
-
{
|
|
125
|
-
name: "changed",
|
|
126
|
-
description: "Changed",
|
|
127
|
-
payloadFields: [{ name: "id", type: field_type_1.FieldType.id }],
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
};
|
|
131
|
-
const consumerA = (0, contract_proxy_1.createContractConsumer)(contract, transport);
|
|
132
|
-
const consumerB = (0, contract_proxy_1.createContractConsumer)(contract, transport);
|
|
133
|
-
const receivedA = [];
|
|
134
|
-
const receivedB = [];
|
|
135
|
-
consumerA.events.changed.subscribe((value) => receivedA.push(value));
|
|
136
|
-
consumerB.events.changed.subscribe((value) => receivedB.push(value));
|
|
137
|
-
const subscribeCalls = emitter.emit.mock.calls
|
|
138
|
-
.filter(([channel, call]) => channel === contract_transport_1.CONTRACT_REQUEST_CHANNEL && call.operation === "subscribe")
|
|
139
|
-
.map(([, call]) => call);
|
|
140
|
-
const consumerASubscriptionId = subscribeCalls[0].subscriptionId;
|
|
141
|
-
const consumerBSubscriptionId = subscribeCalls[1].subscriptionId;
|
|
142
|
-
await listeners.get(contract_transport_1.CONTRACT_NOTIFY_CHANNEL)?.({
|
|
143
|
-
subscriptionId: consumerASubscriptionId,
|
|
144
|
-
value: "for-a",
|
|
145
|
-
});
|
|
146
|
-
expect(receivedA).toEqual(["for-a"]);
|
|
147
|
-
expect(receivedB).toEqual([]);
|
|
148
|
-
await listeners.get(contract_transport_1.CONTRACT_NOTIFY_CHANNEL)?.({
|
|
149
|
-
subscriptionId: consumerBSubscriptionId,
|
|
150
|
-
value: "before",
|
|
151
|
-
});
|
|
152
|
-
expect(receivedA).toEqual(["for-a"]);
|
|
153
|
-
expect(receivedB).toEqual(["before"]);
|
|
154
|
-
consumerA.dispose();
|
|
155
|
-
await listeners.get(contract_transport_1.CONTRACT_NOTIFY_CHANNEL)?.({
|
|
156
|
-
subscriptionId: consumerBSubscriptionId,
|
|
157
|
-
value: "after",
|
|
158
|
-
});
|
|
159
|
-
expect(receivedA).toEqual(["for-a"]);
|
|
160
|
-
expect(receivedB).toEqual(["before", "after"]);
|
|
161
|
-
consumerB.dispose();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const zod_1 = require("zod");
|
|
4
|
-
const types_1 = require("../../data/orm/types");
|
|
5
|
-
const field_type_1 = require("../../types/field-type");
|
|
6
|
-
const extract_1 = require("../extract");
|
|
7
|
-
// Wire in the real schemaToFields before tests run so we don't trigger the
|
|
8
|
-
// lazy require (which would pull in the full DI chain in some environments).
|
|
9
|
-
beforeAll(() => {
|
|
10
|
-
(0, extract_1.setSchemaToFieldsFn)(types_1.schemaToFields);
|
|
11
|
-
});
|
|
12
|
-
describe("extractTableShape", () => {
|
|
13
|
-
it("extracts shape from a Zod schema via schemaToFields", () => {
|
|
14
|
-
const schema = zod_1.z.object({
|
|
15
|
-
taskId: zod_1.z.string().describe("Primary key"),
|
|
16
|
-
title: zod_1.z.string().describe("Task title"),
|
|
17
|
-
done: zod_1.z.boolean().optional().describe("Completion flag"),
|
|
18
|
-
});
|
|
19
|
-
const def = {
|
|
20
|
-
metaData: {
|
|
21
|
-
name: "Tasks",
|
|
22
|
-
description: "Task tracking table",
|
|
23
|
-
primaryKeyName: "taskId",
|
|
24
|
-
fields: [],
|
|
25
|
-
},
|
|
26
|
-
schema,
|
|
27
|
-
};
|
|
28
|
-
const shape = (0, extract_1.extractTableShape)(def);
|
|
29
|
-
expect(shape.name).toBe("Tasks");
|
|
30
|
-
expect(shape.description).toBe("Task tracking table");
|
|
31
|
-
expect(shape.primaryKeyName).toBe("taskId");
|
|
32
|
-
expect(shape.fields).toHaveLength(3);
|
|
33
|
-
const taskIdField = shape.fields.find((f) => f.name === "taskId");
|
|
34
|
-
expect(taskIdField?.type).toBe(field_type_1.FieldType.string);
|
|
35
|
-
const titleField = shape.fields.find((f) => f.name === "title");
|
|
36
|
-
expect(titleField?.type).toBe(field_type_1.FieldType.string);
|
|
37
|
-
const doneField = shape.fields.find((f) => f.name === "done");
|
|
38
|
-
expect(doneField?.type).toBe(field_type_1.FieldType.boolean);
|
|
39
|
-
expect(doneField?.optional).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
it("falls back to metaData.fields when no schema is provided", () => {
|
|
42
|
-
const def = {
|
|
43
|
-
metaData: {
|
|
44
|
-
name: "Legacy",
|
|
45
|
-
description: "A legacy table",
|
|
46
|
-
primaryKeyName: "legacyId",
|
|
47
|
-
fields: [
|
|
48
|
-
{ name: "legacyId", type: field_type_1.FieldType.id, description: "Primary key" },
|
|
49
|
-
{ name: "label", type: field_type_1.FieldType.string, description: "Label" },
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
const shape = (0, extract_1.extractTableShape)(def);
|
|
54
|
-
expect(shape.name).toBe("Legacy");
|
|
55
|
-
expect(shape.fields).toHaveLength(2);
|
|
56
|
-
expect(shape.fields[0].name).toBe("legacyId");
|
|
57
|
-
expect(shape.fields[1].name).toBe("label");
|
|
58
|
-
});
|
|
59
|
-
it("does not mutate the original metaData.fields array", () => {
|
|
60
|
-
const originalFields = [{ name: "id", type: field_type_1.FieldType.id, description: "PK" }];
|
|
61
|
-
const def = {
|
|
62
|
-
metaData: {
|
|
63
|
-
name: "Test",
|
|
64
|
-
description: "Test",
|
|
65
|
-
primaryKeyName: "id",
|
|
66
|
-
fields: originalFields,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
const shape = (0, extract_1.extractTableShape)(def);
|
|
70
|
-
shape.fields.push({ name: "extra", type: field_type_1.FieldType.string });
|
|
71
|
-
expect(originalFields).toHaveLength(1);
|
|
72
|
-
});
|
|
73
|
-
it("handles arrays and complex Zod types", () => {
|
|
74
|
-
const schema = zod_1.z.object({
|
|
75
|
-
recordId: zod_1.z.string().describe("PK"),
|
|
76
|
-
tags: zod_1.z.string().array().describe("Tag list"),
|
|
77
|
-
metadata: zod_1.z.object({}).optional().describe("Arbitrary metadata"),
|
|
78
|
-
});
|
|
79
|
-
const def = {
|
|
80
|
-
metaData: {
|
|
81
|
-
name: "Records",
|
|
82
|
-
description: "Records with arrays",
|
|
83
|
-
primaryKeyName: "recordId",
|
|
84
|
-
fields: [],
|
|
85
|
-
},
|
|
86
|
-
schema,
|
|
87
|
-
};
|
|
88
|
-
const shape = (0, extract_1.extractTableShape)(def);
|
|
89
|
-
const tagsField = shape.fields.find((f) => f.name === "tags");
|
|
90
|
-
expect(tagsField?.type).toBe(field_type_1.FieldType.string);
|
|
91
|
-
expect(tagsField?.isArray).toBe(true);
|
|
92
|
-
const metadataField = shape.fields.find((f) => f.name === "metadata");
|
|
93
|
-
expect(metadataField?.type).toBe(field_type_1.FieldType.object);
|
|
94
|
-
expect(metadataField?.optional).toBe(true);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe("extractToolShape", () => {
|
|
98
|
-
it("extracts name and usageDescription from the tool", () => {
|
|
99
|
-
const inst = {
|
|
100
|
-
tool: {
|
|
101
|
-
name: "create-task",
|
|
102
|
-
usageDescription: "Creates a new task",
|
|
103
|
-
inputSchema: { fields: [] },
|
|
104
|
-
outputSchema: { fields: [] },
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
const shape = (0, extract_1.extractToolShape)(inst);
|
|
108
|
-
expect(shape.name).toBe("create-task");
|
|
109
|
-
expect(shape.usageDescription).toBe("Creates a new task");
|
|
110
|
-
});
|
|
111
|
-
it("extracts input and output fields from IOSchema", () => {
|
|
112
|
-
const inst = {
|
|
113
|
-
tool: {
|
|
114
|
-
name: "create-task",
|
|
115
|
-
usageDescription: "Creates a task",
|
|
116
|
-
inputSchema: {
|
|
117
|
-
fields: [
|
|
118
|
-
{ name: "title", type: field_type_1.FieldType.string, description: "Task title" },
|
|
119
|
-
{ name: "priority", type: field_type_1.FieldType.number, description: "Priority level" },
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
outputSchema: {
|
|
123
|
-
fields: [{ name: "taskId", type: field_type_1.FieldType.id, description: "Created task ID" }],
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
const shape = (0, extract_1.extractToolShape)(inst);
|
|
128
|
-
expect(shape.inputFields).toHaveLength(2);
|
|
129
|
-
expect(shape.inputFields[0].name).toBe("title");
|
|
130
|
-
expect(shape.inputFields[1].name).toBe("priority");
|
|
131
|
-
expect(shape.outputFields).toHaveLength(1);
|
|
132
|
-
expect(shape.outputFields[0].name).toBe("taskId");
|
|
133
|
-
});
|
|
134
|
-
it("returns empty field arrays when schemas are missing", () => {
|
|
135
|
-
const inst = {
|
|
136
|
-
tool: {
|
|
137
|
-
name: "no-io-tool",
|
|
138
|
-
usageDescription: "A tool with no I/O",
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
const shape = (0, extract_1.extractToolShape)(inst);
|
|
142
|
-
expect(shape.inputFields).toEqual([]);
|
|
143
|
-
expect(shape.outputFields).toEqual([]);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const field_type_1 = require("../../types/field-type");
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const frozen_contracts_1 = require("../frozen-contracts");
|
|
6
|
-
function contract(contractId, version, fieldType = field_type_1.FieldType.string) {
|
|
7
|
-
return {
|
|
8
|
-
contractId,
|
|
9
|
-
version,
|
|
10
|
-
devTag: "dev",
|
|
11
|
-
name: `Contract ${version}`,
|
|
12
|
-
description: "",
|
|
13
|
-
tables: [],
|
|
14
|
-
tools: [
|
|
15
|
-
{
|
|
16
|
-
name: "run",
|
|
17
|
-
usageDescription: "Run.",
|
|
18
|
-
inputFields: [{ name: "value", type: fieldType }],
|
|
19
|
-
outputFields: [],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
observables: [],
|
|
23
|
-
events: [],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe("frozen contracts", () => {
|
|
27
|
-
const id = (0, utils_1.newid)();
|
|
28
|
-
it("freezes what a release provides, without its dev tag, and keeps what it froze before", () => {
|
|
29
|
-
const first = (0, frozen_contracts_1.freezeContracts)(undefined, [contract(id, 1)], "1.0.0");
|
|
30
|
-
expect(first.added.map((frozen) => [frozen.version, frozen.frozenBy])).toEqual([[1, "1.0.0"]]);
|
|
31
|
-
expect(first.frozen.contracts[0]).not.toHaveProperty("devTag");
|
|
32
|
-
const second = (0, frozen_contracts_1.freezeContracts)(first.frozen, [contract(id, 1), contract(id, 2)], "1.1.0");
|
|
33
|
-
expect(second.frozen.contracts.map((frozen) => [frozen.version, frozen.frozenBy])).toEqual([
|
|
34
|
-
[1, "1.0.0"],
|
|
35
|
-
[2, "1.1.0"],
|
|
36
|
-
]);
|
|
37
|
-
expect(second.added.map((frozen) => frozen.version)).toEqual([2]);
|
|
38
|
-
});
|
|
39
|
-
it("refuses a changed shape, allows new descriptions, and notes a version no longer provided", () => {
|
|
40
|
-
const { frozen } = (0, frozen_contracts_1.freezeContracts)(undefined, [contract(id, 1), contract(id, 2)], "1.0.0");
|
|
41
|
-
const described = { ...contract(id, 1), description: "Use v2 instead." };
|
|
42
|
-
described.tools = [{ ...described.tools[0], usageDescription: "Deprecated." }];
|
|
43
|
-
expect((0, frozen_contracts_1.checkFrozenContracts)(frozen, [described, contract(id, 2)])).toEqual({
|
|
44
|
-
changed: [],
|
|
45
|
-
notProvided: [],
|
|
46
|
-
});
|
|
47
|
-
const changed = (0, frozen_contracts_1.checkFrozenContracts)(frozen, [contract(id, 1, field_type_1.FieldType.number)]);
|
|
48
|
-
expect(changed.changed.map(({ changes }) => changes)).toEqual([["tool run changed"]]);
|
|
49
|
-
expect(changed.notProvided.map((frozen) => frozen.version)).toEqual([2]);
|
|
50
|
-
expect((0, frozen_contracts_1.describeFrozenContractChanges)(changed)).toEqual([
|
|
51
|
-
`Contract 1 (${id}@1), frozen by 1.0.0: tool run changed. Declare a new version instead.`,
|
|
52
|
-
]);
|
|
53
|
-
const refused = (0, frozen_contracts_1.freezeContracts)(frozen, [contract(id, 1, field_type_1.FieldType.number)], "1.1.0");
|
|
54
|
-
expect(refused.added).toEqual([]);
|
|
55
|
-
expect(refused.frozen).toBe(frozen);
|
|
56
|
-
});
|
|
57
|
-
it("rejects duplicate provided identities instead of hiding a changed shape or freezing duplicates", () => {
|
|
58
|
-
const original = contract(id, 1);
|
|
59
|
-
const changed = contract(id, 1, field_type_1.FieldType.number);
|
|
60
|
-
const { frozen } = (0, frozen_contracts_1.freezeContracts)(undefined, [original], "1.0.0");
|
|
61
|
-
for (const provided of [
|
|
62
|
-
[changed, original],
|
|
63
|
-
[original, changed],
|
|
64
|
-
[original, original],
|
|
65
|
-
]) {
|
|
66
|
-
expect(() => (0, frozen_contracts_1.checkFrozenContracts)(frozen, provided)).toThrow(`Duplicate provided contract ${id}@1`);
|
|
67
|
-
expect(() => (0, frozen_contracts_1.freezeContracts)(undefined, provided, "1.0.0")).toThrow("Duplicate provided contract");
|
|
68
|
-
expect(() => (0, frozen_contracts_1.freezeContracts)(frozen, provided, "1.1.0")).toThrow("Duplicate provided contract");
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
const sample = {
|
|
73
|
-
contractId: (0, utils_1.newid)(),
|
|
74
|
-
version: 1,
|
|
75
|
-
name: "All members",
|
|
76
|
-
description: "",
|
|
77
|
-
tables: [
|
|
78
|
-
{
|
|
79
|
-
name: "Rows",
|
|
80
|
-
description: "",
|
|
81
|
-
primaryKeyName: "id",
|
|
82
|
-
fields: [{ name: "id", type: field_type_1.FieldType.id }],
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
tools: [
|
|
86
|
-
{
|
|
87
|
-
name: "run",
|
|
88
|
-
usageDescription: "",
|
|
89
|
-
inputFields: [{ name: "mode", type: field_type_1.FieldType.string, enumValues: ["on", "off"] }],
|
|
90
|
-
outputFields: [
|
|
91
|
-
{
|
|
92
|
-
name: "result",
|
|
93
|
-
type: field_type_1.FieldType.object,
|
|
94
|
-
fields: [{ name: "ok", type: field_type_1.FieldType.boolean }],
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
observables: [
|
|
100
|
-
{
|
|
101
|
-
name: "state",
|
|
102
|
-
description: "",
|
|
103
|
-
valueType: field_type_1.FieldType.string,
|
|
104
|
-
writable: false,
|
|
105
|
-
value: { type: field_type_1.FieldType.string, enumValues: ["on", "off"] },
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
events: [
|
|
109
|
-
{ name: "changed", description: "", payloadFields: [{ name: "id", type: field_type_1.FieldType.id }] },
|
|
110
|
-
],
|
|
111
|
-
};
|
|
112
|
-
test.each([
|
|
113
|
-
"tables",
|
|
114
|
-
"tools",
|
|
115
|
-
"observables",
|
|
116
|
-
"events",
|
|
117
|
-
])("detects added and removed %s", (kind) => {
|
|
118
|
-
const { frozen } = (0, frozen_contracts_1.freezeContracts)(undefined, [sample], "1.0.0");
|
|
119
|
-
const removed = { ...sample, [kind]: [] };
|
|
120
|
-
const added = {
|
|
121
|
-
...sample,
|
|
122
|
-
[kind]: [...(sample[kind] ?? []), { ...(sample[kind] ?? [])[0], name: "another" }],
|
|
123
|
-
};
|
|
124
|
-
for (const changed of [removed, added]) {
|
|
125
|
-
expect((0, frozen_contracts_1.checkFrozenContracts)(frozen, [changed]).changed).toHaveLength(1);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
test.each([
|
|
129
|
-
[
|
|
130
|
-
"primary key",
|
|
131
|
-
(value) => {
|
|
132
|
-
value.tables[0].primaryKeyName = "other";
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
"table field type",
|
|
137
|
-
(value) => {
|
|
138
|
-
value.tables[0].fields[0].type = field_type_1.FieldType.string;
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
[
|
|
142
|
-
"tool optionality",
|
|
143
|
-
(value) => {
|
|
144
|
-
value.tools[0].inputFields[0].optional = true;
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
[
|
|
148
|
-
"enum values",
|
|
149
|
-
(value) => {
|
|
150
|
-
value.tools[0].inputFields[0].enumValues = ["on"];
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
[
|
|
154
|
-
"nested field",
|
|
155
|
-
(value) => {
|
|
156
|
-
(value.tools[0].outputFields[0].fields ?? [])[0].type = field_type_1.FieldType.string;
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
[
|
|
160
|
-
"observable type",
|
|
161
|
-
(value) => {
|
|
162
|
-
value.observables[0].valueType = field_type_1.FieldType.object;
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
[
|
|
166
|
-
"observable writability",
|
|
167
|
-
(value) => {
|
|
168
|
-
value.observables[0].writable = true;
|
|
169
|
-
},
|
|
170
|
-
],
|
|
171
|
-
[
|
|
172
|
-
"observable enum",
|
|
173
|
-
(value) => {
|
|
174
|
-
value.observables[0].value = { type: field_type_1.FieldType.string, enumValues: ["on"] };
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
[
|
|
178
|
-
"event field",
|
|
179
|
-
(value) => {
|
|
180
|
-
(value.events ?? [])[0].payloadFields[0].isArray = true;
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
])("detects changed %s", (_label, mutate) => {
|
|
184
|
-
const { frozen } = (0, frozen_contracts_1.freezeContracts)(undefined, [sample], "1.0.0");
|
|
185
|
-
const changed = structuredClone(sample);
|
|
186
|
-
mutate(changed);
|
|
187
|
-
expect((0, frozen_contracts_1.checkFrozenContracts)(frozen, [changed]).changed).toHaveLength(1);
|
|
188
|
-
});
|
|
189
|
-
test("does not freeze without a package version", () => {
|
|
190
|
-
expect(() => (0, frozen_contracts_1.freezeContracts)(undefined, [sample], "")).toThrow("no version");
|
|
191
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../../index");
|
|
4
|
-
const target_dispatch_1 = require("./target-dispatch");
|
|
5
|
-
test.each([
|
|
6
|
-
true,
|
|
7
|
-
false,
|
|
8
|
-
])("host preserve admission is None and forwards context (explicit forwarding: %s)", async (forwardCallContext) => {
|
|
9
|
-
const userId = (0, index_1.newid)();
|
|
10
|
-
const groupId = (0, index_1.newid)();
|
|
11
|
-
const contractId = (0, index_1.newid)();
|
|
12
|
-
let role = index_1.GroupMemberRole.None;
|
|
13
|
-
const dc = {
|
|
14
|
-
dataContextId: groupId,
|
|
15
|
-
groupId,
|
|
16
|
-
tableContainer: {
|
|
17
|
-
getTable: (meta) => meta.name === "Groups"
|
|
18
|
-
? { get: async () => ({ founderUserId: (0, index_1.newid)() }) }
|
|
19
|
-
: { findOne: async () => ({ role }) },
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
Object.assign(dc, {
|
|
23
|
-
userContext: {
|
|
24
|
-
userId,
|
|
25
|
-
loadingPromise: Promise.resolve(),
|
|
26
|
-
userDataContext: dc,
|
|
27
|
-
getDataContext: () => dc,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
const targetsId = (0, index_1.newid)();
|
|
31
|
-
const route = {
|
|
32
|
-
tool: { toolId: (0, index_1.newid)(), name: "route", authorityPropagation: "preserve" },
|
|
33
|
-
toolFn: (name, ctx) => ctx.dispatchTool?.({ contractId: targetsId, version: 1, toolName: name }, {}),
|
|
34
|
-
};
|
|
35
|
-
const ordinary = {
|
|
36
|
-
tool: { toolId: (0, index_1.newid)(), name: "ordinary" },
|
|
37
|
-
toolFn: () => "ordinary",
|
|
38
|
-
};
|
|
39
|
-
const targets = Object.fromEntries([0, 20].map((level) => [
|
|
40
|
-
String(level),
|
|
41
|
-
{
|
|
42
|
-
tool: { toolId: (0, index_1.newid)(), name: String(level), accessLevel: level },
|
|
43
|
-
toolFn: () => "executed",
|
|
44
|
-
},
|
|
45
|
-
]));
|
|
46
|
-
const provider = (0, index_1.createContractProvider)({ contractId, version: 1, forwardCallContext, tools: { route, ordinary } }, { dispatchTool: (0, target_dispatch_1.targetDispatch)(targetsId, targets) });
|
|
47
|
-
const call = (name, target = "0") => provider({
|
|
48
|
-
contractId,
|
|
49
|
-
version: 1,
|
|
50
|
-
member: "tool",
|
|
51
|
-
name,
|
|
52
|
-
operation: "run",
|
|
53
|
-
args: [target],
|
|
54
|
-
dataContextId: groupId,
|
|
55
|
-
}, { callerUserId: userId, dataContext: dc });
|
|
56
|
-
role = index_1.GroupMemberRole.None;
|
|
57
|
-
await expect(call("route")).resolves.toBe("executed");
|
|
58
|
-
await expect(call("route", "20")).rejects.toThrow(/Permission denied/);
|
|
59
|
-
await expect(call("ordinary")).rejects.toThrow(/Permission denied/);
|
|
60
|
-
role = index_1.GroupMemberRole.Admin;
|
|
61
|
-
await expect(call("route", "20")).resolves.toBe("executed");
|
|
62
|
-
// The same wrapper without a preserve declaration is an ordinary unclassified (Self) tool.
|
|
63
|
-
route.tool.authorityPropagation = undefined;
|
|
64
|
-
await expect(call("route", "20")).rejects.toThrow(/Permission denied/);
|
|
65
|
-
});
|
|
66
|
-
test("host tool schema retains omitted admission for request-based defaults", () => {
|
|
67
|
-
const tool = index_1.toolSchema.parse({
|
|
68
|
-
toolId: (0, index_1.newid)(),
|
|
69
|
-
name: "route",
|
|
70
|
-
usageDescription: "route",
|
|
71
|
-
inputSchema: { type: "simple" },
|
|
72
|
-
outputSchema: { type: "simple" },
|
|
73
|
-
authorityPropagation: "preserve",
|
|
74
|
-
});
|
|
75
|
-
expect(tool.accessLevel).toBeUndefined();
|
|
76
|
-
});
|
|
77
|
-
test("generic dispatch binds a capped strict frame and rejects cross-context and remote targets", async () => {
|
|
78
|
-
const userId = (0, index_1.newid)();
|
|
79
|
-
const groupId = (0, index_1.newid)();
|
|
80
|
-
const contractId = (0, index_1.newid)();
|
|
81
|
-
const dc = {
|
|
82
|
-
dataContextId: groupId,
|
|
83
|
-
groupId,
|
|
84
|
-
tableContainer: {
|
|
85
|
-
getTable: (meta) => meta.name === "Groups"
|
|
86
|
-
? { get: async () => ({ founderUserId: (0, index_1.newid)() }) }
|
|
87
|
-
: { findOne: async () => ({ role: index_1.GroupMemberRole.Admin }) },
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
Object.assign(dc, {
|
|
91
|
-
userContext: {
|
|
92
|
-
userId,
|
|
93
|
-
loadingPromise: Promise.resolve(),
|
|
94
|
-
userDataContext: dc,
|
|
95
|
-
getDataContext: () => dc,
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
const selected = {
|
|
99
|
-
contractId: (0, index_1.newid)(),
|
|
100
|
-
version: 1,
|
|
101
|
-
toolName: "write",
|
|
102
|
-
providerPackageId: (0, index_1.newid)(),
|
|
103
|
-
};
|
|
104
|
-
const bridge = jest.fn(async (_ref, _args, context) => {
|
|
105
|
-
expect(context.authority).toMatchObject({
|
|
106
|
-
userId,
|
|
107
|
-
assistantAccessLevel: 20,
|
|
108
|
-
strictActionScope: true,
|
|
109
|
-
});
|
|
110
|
-
return "routed";
|
|
111
|
-
});
|
|
112
|
-
const router = {
|
|
113
|
-
tool: { name: "route", toolId: (0, index_1.newid)(), accessLevel: 20 },
|
|
114
|
-
toolFn: (args, ctx) => ctx.dispatchTool(args, {}),
|
|
115
|
-
};
|
|
116
|
-
const dispatch = (0, index_1.createContractProvider)({ contractId, version: 1, forwardCallContext: true, tools: { route: router } }, { dispatchTool: bridge });
|
|
117
|
-
const call = (ref) => dispatch({
|
|
118
|
-
contractId,
|
|
119
|
-
version: 1,
|
|
120
|
-
member: "tool",
|
|
121
|
-
name: "route",
|
|
122
|
-
operation: "run",
|
|
123
|
-
args: [ref],
|
|
124
|
-
dataContextId: groupId,
|
|
125
|
-
}, { callerUserId: userId, dataContext: dc });
|
|
126
|
-
await expect(call(selected)).resolves.toBe("routed");
|
|
127
|
-
await expect(call({ ...selected, dataContextId: (0, index_1.newid)() })).rejects.toThrow("Cross-context");
|
|
128
|
-
await expect(call({ ...selected, targetDeviceId: (0, index_1.newid)() })).rejects.toThrow("cannot target another device");
|
|
129
|
-
expect(bridge).toHaveBeenCalledTimes(1);
|
|
130
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|