@peers-app/peers-sdk 0.27.2 → 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/data/persistent-vars.d.ts +5 -0
- package/dist/data/persistent-vars.js +24 -6
- 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
package/dist/serial-json.test.js
DELETED
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const serial_json_1 = require("./serial-json");
|
|
4
|
-
describe("serial-json", () => {
|
|
5
|
-
describe("Uint8Array serialization", () => {
|
|
6
|
-
it("should serialize and deserialize Uint8Array correctly", () => {
|
|
7
|
-
const originalData = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); // "Hello World"
|
|
8
|
-
const testObj = {
|
|
9
|
-
data: originalData,
|
|
10
|
-
name: "test",
|
|
11
|
-
number: 42,
|
|
12
|
-
};
|
|
13
|
-
// Test toJSON/fromJSON
|
|
14
|
-
const serialized = (0, serial_json_1.toJSON)(testObj);
|
|
15
|
-
expect(serialized.data).toMatch(/^__UINT8ARRAY /);
|
|
16
|
-
const deserialized = (0, serial_json_1.fromJSON)(serialized);
|
|
17
|
-
expect(deserialized.data).toBeInstanceOf(Uint8Array);
|
|
18
|
-
expect(deserialized.data).toEqual(originalData);
|
|
19
|
-
expect(deserialized.name).toBe("test");
|
|
20
|
-
expect(deserialized.number).toBe(42);
|
|
21
|
-
});
|
|
22
|
-
it("should serialize and deserialize nested Uint8Array correctly", () => {
|
|
23
|
-
const data1 = new Uint8Array([1, 2, 3]);
|
|
24
|
-
const data2 = new Uint8Array([4, 5, 6]);
|
|
25
|
-
const testObj = {
|
|
26
|
-
chunks: [data1, data2],
|
|
27
|
-
metadata: {
|
|
28
|
-
firstChunk: data1,
|
|
29
|
-
totalSize: 6,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const serialized = (0, serial_json_1.toJSON)(testObj);
|
|
33
|
-
const deserialized = (0, serial_json_1.fromJSON)(serialized);
|
|
34
|
-
expect(deserialized.chunks).toHaveLength(2);
|
|
35
|
-
expect(deserialized.chunks[0]).toBeInstanceOf(Uint8Array);
|
|
36
|
-
expect(deserialized.chunks[1]).toBeInstanceOf(Uint8Array);
|
|
37
|
-
expect(deserialized.chunks[0]).toEqual(data1);
|
|
38
|
-
expect(deserialized.chunks[1]).toEqual(data2);
|
|
39
|
-
expect(deserialized.metadata.firstChunk).toBeInstanceOf(Uint8Array);
|
|
40
|
-
expect(deserialized.metadata.firstChunk).toEqual(data1);
|
|
41
|
-
expect(deserialized.metadata.totalSize).toBe(6);
|
|
42
|
-
});
|
|
43
|
-
it("should work with JSON string serialization", () => {
|
|
44
|
-
const originalData = new Uint8Array([255, 0, 128, 64]);
|
|
45
|
-
const testObj = { binaryData: originalData };
|
|
46
|
-
const jsonString = (0, serial_json_1.toJSONString)(testObj);
|
|
47
|
-
expect(typeof jsonString).toBe("string");
|
|
48
|
-
expect(jsonString).toContain("__UINT8ARRAY");
|
|
49
|
-
const deserialized = (0, serial_json_1.fromJSONString)(jsonString);
|
|
50
|
-
expect(deserialized.binaryData).toBeInstanceOf(Uint8Array);
|
|
51
|
-
expect(deserialized.binaryData).toEqual(originalData);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("Buffer backward compatibility", () => {
|
|
55
|
-
it("should serialize and deserialize Buffer correctly", () => {
|
|
56
|
-
const originalBuffer = Buffer.from("Hello Buffer");
|
|
57
|
-
const testObj = { bufferData: originalBuffer };
|
|
58
|
-
const serialized = (0, serial_json_1.toJSON)(testObj);
|
|
59
|
-
expect(serialized.bufferData).toMatch(/^__BUFFER /);
|
|
60
|
-
const deserialized = (0, serial_json_1.fromJSON)(serialized);
|
|
61
|
-
expect(Buffer.isBuffer(deserialized.bufferData)).toBe(true);
|
|
62
|
-
expect(deserialized.bufferData).toEqual(originalBuffer);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
// Signatures sign toJSON output (`canonicalJSONString` in keys.ts), so these strings are frozen.
|
|
66
|
-
describe("encoded form (pinned)", () => {
|
|
67
|
-
it("encodes each extended type as a sentinel string", () => {
|
|
68
|
-
const value = {
|
|
69
|
-
d: new Date("2023-01-01T00:00:00.000Z"),
|
|
70
|
-
u8: new Uint8Array([1, 2, 3]),
|
|
71
|
-
buf: Buffer.from([1, 2, 3]),
|
|
72
|
-
u: undefined,
|
|
73
|
-
nan: NaN,
|
|
74
|
-
inf: Infinity,
|
|
75
|
-
re: /a+b/gi,
|
|
76
|
-
n: null,
|
|
77
|
-
t: true,
|
|
78
|
-
s: "x",
|
|
79
|
-
num: 1.5,
|
|
80
|
-
};
|
|
81
|
-
const encoded = (0, serial_json_1.toJSONString)(value);
|
|
82
|
-
expect(encoded).toBe('{"d":"__DATE 2023-01-01T00:00:00.000Z","u8":"__UINT8ARRAY AQID","buf":"__BUFFER AQID",' +
|
|
83
|
-
'"u":"__UNDEFINED","nan":"__NAN","inf":"__INFINITY","re":"__REGEXP /a+b/gi","n":null,' +
|
|
84
|
-
'"t":true,"s":"x","num":1.5}');
|
|
85
|
-
const decoded = (0, serial_json_1.fromJSONString)(encoded);
|
|
86
|
-
expect(decoded.d).toEqual(value.d);
|
|
87
|
-
expect(decoded.u8).toBeInstanceOf(Uint8Array);
|
|
88
|
-
expect(Buffer.isBuffer(decoded.u8)).toBe(false);
|
|
89
|
-
expect(Buffer.isBuffer(decoded.buf)).toBe(true);
|
|
90
|
-
expect("u" in decoded).toBe(true);
|
|
91
|
-
expect(decoded.u).toBeUndefined();
|
|
92
|
-
expect(decoded.nan).toBeNaN();
|
|
93
|
-
expect(decoded.inf).toBe(Infinity);
|
|
94
|
-
expect(decoded.re).toEqual(/a+b/gi);
|
|
95
|
-
expect(decoded).toMatchObject({ n: null, t: true, s: "x", num: 1.5 });
|
|
96
|
-
});
|
|
97
|
-
it("encodes an Error as its stack and a function as one-way source text", () => {
|
|
98
|
-
const encoded = (0, serial_json_1.toJSON)({
|
|
99
|
-
e: new Error("boom"),
|
|
100
|
-
f: function named() {
|
|
101
|
-
return 1;
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
expect(encoded.e).toMatch(/^__ERROR Error: boom\n/);
|
|
105
|
-
expect(encoded.f).toMatch(/^__FUNCTION function named\(\)/);
|
|
106
|
-
const decoded = (0, serial_json_1.fromJSON)(encoded);
|
|
107
|
-
expect(decoded.e).toBeInstanceOf(Error);
|
|
108
|
-
expect(decoded.e.stack).toBe(encoded.e.substring(8));
|
|
109
|
-
expect(decoded.f).toBe(encoded.f);
|
|
110
|
-
});
|
|
111
|
-
it("tags the first copy of a shared object and points the others at it", () => {
|
|
112
|
-
const shared = { s: 1 };
|
|
113
|
-
const encoded = (0, serial_json_1.toJSONString)({ a: shared, b: shared, c: [shared] });
|
|
114
|
-
expect(encoded).toBe('{"a":{"s":1,"__this_ref":"__duplicate_ref_obj_2"},"b":"__duplicate_ref_obj_2",' +
|
|
115
|
-
'"c":["__duplicate_ref_obj_2"]}');
|
|
116
|
-
const decoded = (0, serial_json_1.fromJSONString)(encoded);
|
|
117
|
-
expect(decoded.a).toEqual({ s: 1 });
|
|
118
|
-
expect(decoded.b).toBe(decoded.a);
|
|
119
|
-
expect(decoded.c[0]).toBe(decoded.a);
|
|
120
|
-
});
|
|
121
|
-
it("tags a shared array with an extra first element", () => {
|
|
122
|
-
const shared = ["a", "b"];
|
|
123
|
-
const encoded = (0, serial_json_1.toJSONString)({ x: shared, y: shared });
|
|
124
|
-
expect(encoded).toBe('{"x":["__this_ref:__duplicate_ref_ary_2","a","b"],"y":"__duplicate_ref_ary_2"}');
|
|
125
|
-
const decoded = (0, serial_json_1.fromJSONString)(encoded);
|
|
126
|
-
expect(decoded.x).toEqual(["a", "b"]);
|
|
127
|
-
expect(decoded.y).toBe(decoded.x);
|
|
128
|
-
});
|
|
129
|
-
it("encodes cycles, placing the tag wherever the copy has got to", () => {
|
|
130
|
-
const obj = { n: 1 };
|
|
131
|
-
obj.self = obj;
|
|
132
|
-
const list = [1];
|
|
133
|
-
list.push(list);
|
|
134
|
-
const root = { child: { grand: {} } };
|
|
135
|
-
root.child.grand.up = root;
|
|
136
|
-
expect((0, serial_json_1.toJSONString)(obj)).toBe('{"n":1,"__this_ref":"__duplicate_ref_obj_1","self":"__duplicate_ref_obj_1"}');
|
|
137
|
-
expect((0, serial_json_1.toJSONString)(list)).toBe('["__this_ref:__duplicate_ref_ary_1",1,"__duplicate_ref_ary_1"]');
|
|
138
|
-
expect((0, serial_json_1.toJSONString)(root)).toBe('{"__this_ref":"__duplicate_ref_obj_1","child":{"grand":{"up":"__duplicate_ref_obj_1"}}}');
|
|
139
|
-
const decodedObj = (0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)(obj));
|
|
140
|
-
expect(decodedObj.self).toBe(decodedObj);
|
|
141
|
-
expect(decodedObj.n).toBe(1);
|
|
142
|
-
const decodedList = (0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)(list));
|
|
143
|
-
expect(decodedList).toHaveLength(2);
|
|
144
|
-
expect(decodedList[1]).toBe(decodedList);
|
|
145
|
-
const decodedRoot = (0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)(root));
|
|
146
|
-
expect(decodedRoot.child.grand.up).toBe(decodedRoot);
|
|
147
|
-
});
|
|
148
|
-
it("resolves a reference that appears before its target", () => {
|
|
149
|
-
const decoded = (0, serial_json_1.fromJSONString)('{"b":"__duplicate_ref_obj_2","a":{"k":1,"__this_ref":"__duplicate_ref_obj_2"}}');
|
|
150
|
-
expect(decoded.a).toEqual({ k: 1 });
|
|
151
|
-
expect(decoded.b).toBe(decoded.a);
|
|
152
|
-
});
|
|
153
|
-
it("escapes keys that start with $", () => {
|
|
154
|
-
const encoded = (0, serial_json_1.toJSONString)({ $a: 1, $: 2, plain: { $nested: 3 } });
|
|
155
|
-
expect(encoded).toBe('{"__DOLLAR_a":1,"__DOLLAR_":2,"plain":{"__DOLLAR_nested":3}}');
|
|
156
|
-
expect((0, serial_json_1.fromJSONString)(encoded)).toEqual({ $a: 1, $: 2, plain: { $nested: 3 } });
|
|
157
|
-
});
|
|
158
|
-
it("leaves top-level primitives alone", () => {
|
|
159
|
-
expect((0, serial_json_1.toJSON)(NaN)).toBeNaN();
|
|
160
|
-
expect((0, serial_json_1.toJSONString)(NaN)).toBe("null");
|
|
161
|
-
expect((0, serial_json_1.toJSON)(undefined)).toBeUndefined();
|
|
162
|
-
expect((0, serial_json_1.toJSONString)(undefined)).toBeUndefined();
|
|
163
|
-
expect((0, serial_json_1.toJSON)("__UNDEFINED")).toBe("__UNDEFINED");
|
|
164
|
-
expect((0, serial_json_1.toJSON)(5)).toBe(5);
|
|
165
|
-
expect((0, serial_json_1.toJSON)(new Date(0))).toBe("__DATE 1970-01-01T00:00:00.000Z");
|
|
166
|
-
expect((0, serial_json_1.fromJSON)("__DATE 1970-01-01T00:00:00.000Z")).toEqual(new Date(0));
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
// Behavior that is wrong or lossy today. Each test changes when its gap is fixed.
|
|
170
|
-
describe("known gaps (pinned until fixed)", () => {
|
|
171
|
-
it("decodes ordinary strings that look like markers as the marked value", () => {
|
|
172
|
-
// The orphan marker warns; restore so the spy doesn't leak into later tests.
|
|
173
|
-
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
174
|
-
const decoded = (0, serial_json_1.fromJSON)((0, serial_json_1.toJSON)({
|
|
175
|
-
u: "__UNDEFINED",
|
|
176
|
-
n: "__NAN",
|
|
177
|
-
d: "__DATE tomorrow",
|
|
178
|
-
e: "__ERROR oops",
|
|
179
|
-
r: "__duplicate_ref_obj_9",
|
|
180
|
-
}));
|
|
181
|
-
warn.mockRestore();
|
|
182
|
-
expect(decoded.u).toBeUndefined();
|
|
183
|
-
expect(decoded.n).toBeNaN();
|
|
184
|
-
expect(decoded.d).toBeInstanceOf(Date);
|
|
185
|
-
expect(decoded.d.getTime()).toBeNaN();
|
|
186
|
-
expect(decoded.e).toBeInstanceOf(Error);
|
|
187
|
-
expect(decoded.r).toEqual({});
|
|
188
|
-
});
|
|
189
|
-
it("turns a __DOLLAR_ key into a $ key", () => {
|
|
190
|
-
expect((0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)({ __DOLLAR_b: 2 }))).toEqual({ $b: 2 });
|
|
191
|
-
});
|
|
192
|
-
it("treats a __this_ref key as a shared-reference tag unless its value is falsy", () => {
|
|
193
|
-
expect((0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)({ __this_ref: "mine", a: 1 }))).toEqual({ a: 1 });
|
|
194
|
-
expect((0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)({ __this_ref: "", a: 1 }))).toEqual({
|
|
195
|
-
__this_ref: "",
|
|
196
|
-
a: 1,
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
it("loses -Infinity and -0 in JSON text", () => {
|
|
200
|
-
expect((0, serial_json_1.toJSONString)({ a: -Infinity, z: -0 })).toBe('{"a":null,"z":0}');
|
|
201
|
-
});
|
|
202
|
-
it("stores Map, Set and class instances as plain objects", () => {
|
|
203
|
-
class Point {
|
|
204
|
-
x = 1;
|
|
205
|
-
}
|
|
206
|
-
const encoded = (0, serial_json_1.toJSONString)({ m: new Map([[1, 2]]), s: new Set([1]), p: new Point() });
|
|
207
|
-
expect(encoded).toBe('{"m":{},"s":{},"p":{"x":1}}');
|
|
208
|
-
expect(Object.getPrototypeOf((0, serial_json_1.fromJSONString)(encoded).p)).toBe(Object.prototype);
|
|
209
|
-
});
|
|
210
|
-
it("drops symbols and throws on BigInt and invalid dates", () => {
|
|
211
|
-
expect((0, serial_json_1.toJSONString)({ s: Symbol("x"), a: [Symbol("y")] })).toBe('{"a":[null]}');
|
|
212
|
-
expect(() => (0, serial_json_1.toJSONString)({ b: BigInt(1) })).toThrow(TypeError);
|
|
213
|
-
expect(() => (0, serial_json_1.toJSONString)({ d: new Date(Number.NaN) })).toThrow(RangeError);
|
|
214
|
-
});
|
|
215
|
-
it("throws SyntaxError on a malformed regular expression", () => {
|
|
216
|
-
// working/tools/foreman/test/host.test.mjs relies on this error.
|
|
217
|
-
expect(() => (0, serial_json_1.fromJSON)("__REGEXP /[/")).toThrow(SyntaxError);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
// Intended differences from the frozen oracle (serial-json.compat.test.ts covers the rest).
|
|
221
|
-
describe("decoding changes since the oracle", () => {
|
|
222
|
-
let warn;
|
|
223
|
-
beforeEach(() => {
|
|
224
|
-
warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
225
|
-
});
|
|
226
|
-
afterEach(() => {
|
|
227
|
-
warn.mockRestore();
|
|
228
|
-
});
|
|
229
|
-
it("returns values that are already decoded as they are", () => {
|
|
230
|
-
const value = {
|
|
231
|
-
bytes: new Uint8Array([1, 2]),
|
|
232
|
-
buffer: Buffer.from([3]),
|
|
233
|
-
error: new Error("boom"),
|
|
234
|
-
pattern: /x/g,
|
|
235
|
-
when: new Date(0),
|
|
236
|
-
};
|
|
237
|
-
const decoded = (0, serial_json_1.fromJSON)({ ...value, encoded: "__DATE 1970-01-01T00:00:00.000Z" });
|
|
238
|
-
for (const key of Object.keys(value)) {
|
|
239
|
-
expect(decoded[key]).toBe(value[key]);
|
|
240
|
-
}
|
|
241
|
-
expect(decoded.encoded).toEqual(new Date(0));
|
|
242
|
-
});
|
|
243
|
-
it("builds new arrays and objects and leaves the input untouched", () => {
|
|
244
|
-
const input = Object.freeze({
|
|
245
|
-
list: Object.freeze(["__this_ref:__duplicate_ref_ary_2", 1]),
|
|
246
|
-
tagged: Object.freeze({ __this_ref: "__duplicate_ref_obj_3", $: Object.freeze({}) }),
|
|
247
|
-
again: "__duplicate_ref_ary_2",
|
|
248
|
-
});
|
|
249
|
-
const decoded = (0, serial_json_1.fromJSON)(input);
|
|
250
|
-
expect(decoded).toEqual({ list: [1], tagged: { $: {} }, again: [1] });
|
|
251
|
-
expect(decoded.again).toBe(decoded.list);
|
|
252
|
-
expect(decoded.list).not.toBe(input.list);
|
|
253
|
-
expect(decoded.tagged).not.toBe(input.tagged);
|
|
254
|
-
expect(decoded.tagged.$).not.toBe(input.tagged.$);
|
|
255
|
-
});
|
|
256
|
-
it("copies untagged nested values instead of sharing live change values", () => {
|
|
257
|
-
const input = { nested: { list: [{ value: 1 }] } };
|
|
258
|
-
const decoded = (0, serial_json_1.fromJSON)(input);
|
|
259
|
-
decoded.nested.list[0].value = 2;
|
|
260
|
-
decoded.nested.list.push({});
|
|
261
|
-
expect(input).toEqual({ nested: { list: [{ value: 1 }] } });
|
|
262
|
-
});
|
|
263
|
-
it("does not let an object fill an array target, or an array an object target", () => {
|
|
264
|
-
// The oracle shared them, so `{"length":4e9}` under an array marker decoded to a huge
|
|
265
|
-
// array that hung whatever re-encoded or cloned it, and `{"length":-1}` threw.
|
|
266
|
-
const decoded = (0, serial_json_1.fromJSONString)('["__duplicate_ref_ary_1",{"__this_ref":"__duplicate_ref_ary_1","length":4000000000,"a":1},' +
|
|
267
|
-
'["__this_ref:__duplicate_ref_ary_1","last"],["__this_ref:__duplicate_ref_obj_1",1],' +
|
|
268
|
-
'{"__this_ref":"__duplicate_ref_obj_1","b":2}]');
|
|
269
|
-
expect(decoded[0]).toBe(decoded[2]);
|
|
270
|
-
expect(decoded[0]).toEqual(["last"]);
|
|
271
|
-
expect(decoded[1]).toEqual({ length: 4000000000, a: 1 });
|
|
272
|
-
expect(decoded[3]).toEqual([1]);
|
|
273
|
-
expect(decoded[4]).toEqual({ b: 2 });
|
|
274
|
-
expect(warn).not.toHaveBeenCalled();
|
|
275
|
-
expect((0, serial_json_1.fromJSONString)('["__duplicate_ref_ary_2",{"__this_ref":"__duplicate_ref_ary_2","length":-1}]')).toEqual([[], { length: -1 }]);
|
|
276
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
277
|
-
expect(warn).toHaveBeenCalledWith(expect.stringContaining("__duplicate_ref_ary_2"));
|
|
278
|
-
});
|
|
279
|
-
it("warns about an object marker with only a rejected array tag", () => {
|
|
280
|
-
const marker = "__duplicate_ref_obj_rejected_array";
|
|
281
|
-
expect((0, serial_json_1.fromJSON)([marker, [`__this_ref:${marker}`, 1]])).toEqual([{}, [1]]);
|
|
282
|
-
(0, serial_json_1.fromJSON)([marker, [`__this_ref:${marker}`, 2]]);
|
|
283
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
284
|
-
expect(warn).toHaveBeenCalledWith(expect.stringContaining(marker));
|
|
285
|
-
});
|
|
286
|
-
it("accepts a later matching tag after rejecting a conflicting tag", () => {
|
|
287
|
-
const marker = "__duplicate_ref_obj_later_target";
|
|
288
|
-
const decoded = (0, serial_json_1.fromJSON)([
|
|
289
|
-
marker,
|
|
290
|
-
[`__this_ref:${marker}`, 1],
|
|
291
|
-
{ __this_ref: marker, value: 2 },
|
|
292
|
-
]);
|
|
293
|
-
expect(decoded).toEqual([{ value: 2 }, [1], { value: 2 }]);
|
|
294
|
-
expect(decoded[0]).toBe(decoded[2]);
|
|
295
|
-
expect(warn).not.toHaveBeenCalled();
|
|
296
|
-
});
|
|
297
|
-
it("leaves the browser-only __HTML and __WINDOW sentinels as strings", () => {
|
|
298
|
-
expect((0, serial_json_1.fromJSON)({ html: "__HTML <b>x</b>", win: "__WINDOW" })).toEqual({
|
|
299
|
-
html: "__HTML <b>x</b>",
|
|
300
|
-
win: "__WINDOW",
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
it("warns once, in one string, about a marker with no target", () => {
|
|
304
|
-
const marker = "__duplicate_ref_obj_9001";
|
|
305
|
-
expect((0, serial_json_1.fromJSON)({ a: marker, b: { __this_ref: "__duplicate_ref_obj_9002" } })).toEqual({
|
|
306
|
-
a: {},
|
|
307
|
-
b: {},
|
|
308
|
-
});
|
|
309
|
-
(0, serial_json_1.fromJSON)({ again: marker });
|
|
310
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
311
|
-
expect(warn.mock.calls[0]).toHaveLength(1);
|
|
312
|
-
expect(warn.mock.calls[0][0]).toContain(marker);
|
|
313
|
-
expect(warn.mock.calls[0][0]).not.toContain("9002");
|
|
314
|
-
});
|
|
315
|
-
it("does not warn about a marker whose target comes later", () => {
|
|
316
|
-
(0, serial_json_1.fromJSON)({ b: "__duplicate_ref_obj_9003", a: { __this_ref: "__duplicate_ref_obj_9003" } });
|
|
317
|
-
expect(warn).not.toHaveBeenCalled();
|
|
318
|
-
});
|
|
319
|
-
it("caps warnings at 100 distinct markers across calls", () => {
|
|
320
|
-
jest.isolateModules(() => {
|
|
321
|
-
const isolated = require("./serial-json");
|
|
322
|
-
for (let i = 0; i < 110; i++) {
|
|
323
|
-
const marker = `__duplicate_ref_obj_cap_${i}`;
|
|
324
|
-
isolated.fromJSON([marker, marker]);
|
|
325
|
-
isolated.fromJSON(marker);
|
|
326
|
-
}
|
|
327
|
-
expect(warn).toHaveBeenCalledTimes(100);
|
|
328
|
-
expect(warn.mock.calls.every((args) => args.length === 1 && typeof args[0] === "string")).toBe(true);
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
it("can decode its warning through the log pipeline without warning again", () => {
|
|
332
|
-
warn.mockImplementation((message) => {
|
|
333
|
-
expect((0, serial_json_1.fromJSONString)((0, serial_json_1.toJSONString)({ message }))).toEqual({ message });
|
|
334
|
-
});
|
|
335
|
-
(0, serial_json_1.fromJSON)("__duplicate_ref_obj_log_pipeline");
|
|
336
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
describe("untrusted input", () => {
|
|
340
|
-
afterEach(() => {
|
|
341
|
-
// A failing case must not leak a polluted prototype into later tests.
|
|
342
|
-
delete Object.prototype.polluted;
|
|
343
|
-
delete Object.prototype[0];
|
|
344
|
-
delete Object.polluted;
|
|
345
|
-
});
|
|
346
|
-
it("does not resolve an object's shared-reference tag to Object.prototype", () => {
|
|
347
|
-
const decoded = (0, serial_json_1.fromJSONString)('{"__this_ref":"__proto__","polluted":"yes"}');
|
|
348
|
-
expect({}.polluted).toBeUndefined();
|
|
349
|
-
expect(decoded).toEqual({ polluted: "yes" });
|
|
350
|
-
});
|
|
351
|
-
it("does not resolve an array's shared-reference tag to Object.prototype", () => {
|
|
352
|
-
const decoded = (0, serial_json_1.fromJSONString)('["__this_ref:__proto__","yes"]');
|
|
353
|
-
expect({}[0]).toBeUndefined();
|
|
354
|
-
expect(decoded).toEqual(["yes"]);
|
|
355
|
-
});
|
|
356
|
-
it("does not resolve a shared-reference tag to the Object constructor", () => {
|
|
357
|
-
const decoded = (0, serial_json_1.fromJSONString)('{"__this_ref":"constructor","polluted":"yes"}');
|
|
358
|
-
expect(Object.polluted).toBeUndefined();
|
|
359
|
-
expect(decoded).toEqual({ polluted: "yes" });
|
|
360
|
-
});
|
|
361
|
-
it("keeps constructor and prototype properties local to the decoded value", () => {
|
|
362
|
-
const decoded = (0, serial_json_1.fromJSONString)('{"constructor":{"prototype":{"polluted":"yes"}},"prototype":{"polluted":"yes"}}');
|
|
363
|
-
expect({}.polluted).toBeUndefined();
|
|
364
|
-
expect(Object.polluted).toBeUndefined();
|
|
365
|
-
expect(decoded.constructor.prototype.polluted).toBe("yes");
|
|
366
|
-
});
|
|
367
|
-
it("ignores a shared-reference tag that is an object instead of coercing it", () => {
|
|
368
|
-
const decoded = (0, serial_json_1.fromJSONString)('{"a":{"__this_ref":{"toString":"x"},"k":1},"b":{"__this_ref":{},"k":2}}');
|
|
369
|
-
expect(decoded).toEqual({ a: { k: 1 }, b: { k: 2 } });
|
|
370
|
-
expect(decoded.a).not.toBe(decoded.b);
|
|
371
|
-
});
|
|
372
|
-
it("drops __proto__ keys instead of setting the decoded object's prototype", () => {
|
|
373
|
-
const decoded = (0, serial_json_1.fromJSONString)('{"__proto__":{"polluted":"yes"},"b":{"__proto__":[]}}');
|
|
374
|
-
expect(Object.getPrototypeOf(decoded)).toBe(Object.prototype);
|
|
375
|
-
expect(Object.getPrototypeOf(decoded.b)).toBe(Object.prototype);
|
|
376
|
-
expect(decoded.polluted).toBeUndefined();
|
|
377
|
-
expect(Object.keys(decoded)).toEqual(["b"]);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
describe("existing functionality", () => {
|
|
381
|
-
it("should still handle other special types", () => {
|
|
382
|
-
const testObj = {
|
|
383
|
-
date: new Date("2023-01-01T00:00:00.000Z"),
|
|
384
|
-
regex: /test/gi,
|
|
385
|
-
error: new Error("test error"),
|
|
386
|
-
nan: NaN,
|
|
387
|
-
infinity: Infinity,
|
|
388
|
-
undef: undefined,
|
|
389
|
-
};
|
|
390
|
-
const deserialized = (0, serial_json_1.fromJSON)((0, serial_json_1.toJSON)(testObj));
|
|
391
|
-
expect(deserialized.date).toBeInstanceOf(Date);
|
|
392
|
-
expect(deserialized.date.toISOString()).toBe("2023-01-01T00:00:00.000Z");
|
|
393
|
-
expect(deserialized.regex).toBeInstanceOf(RegExp);
|
|
394
|
-
expect(deserialized.regex.toString()).toBe("/test/gi");
|
|
395
|
-
expect(deserialized.error).toBeInstanceOf(Error);
|
|
396
|
-
expect(Number.isNaN(deserialized.nan)).toBe(true);
|
|
397
|
-
expect(deserialized.infinity).toBe(Infinity);
|
|
398
|
-
expect(deserialized.undef).toBeUndefined();
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|