@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
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const zod_1 = require("zod");
|
|
4
|
-
const data_context_1 = require("../../context/data-context");
|
|
5
|
-
const field_type_1 = require("../../types/field-type");
|
|
6
|
-
const _1 = require(".");
|
|
7
|
-
describe("Dependency Injection Pattern", () => {
|
|
8
|
-
const testSchema = zod_1.z.object({
|
|
9
|
-
id: zod_1.z.string(),
|
|
10
|
-
name: zod_1.z.string(),
|
|
11
|
-
});
|
|
12
|
-
const testMetaData = {
|
|
13
|
-
name: "TestTable",
|
|
14
|
-
description: "Test table for DI pattern",
|
|
15
|
-
primaryKeyName: "id",
|
|
16
|
-
fields: [
|
|
17
|
-
{ name: "id", type: field_type_1.FieldType.string, description: "ID field" },
|
|
18
|
-
{ name: "name", type: field_type_1.FieldType.string, description: "Name field" },
|
|
19
|
-
],
|
|
20
|
-
};
|
|
21
|
-
it("should create table using new DI constructor", () => {
|
|
22
|
-
// Create mock dependencies
|
|
23
|
-
const mockDeps = {
|
|
24
|
-
dataSource: {
|
|
25
|
-
tableName: "TestTable",
|
|
26
|
-
primaryKeyName: "id",
|
|
27
|
-
list: jest.fn().mockResolvedValue([]),
|
|
28
|
-
get: jest.fn().mockResolvedValue(null),
|
|
29
|
-
save: jest.fn().mockResolvedValue({}),
|
|
30
|
-
insert: jest.fn().mockResolvedValue({}),
|
|
31
|
-
update: jest.fn().mockResolvedValue({}),
|
|
32
|
-
delete: jest.fn().mockResolvedValue(undefined),
|
|
33
|
-
},
|
|
34
|
-
eventRegistry: {
|
|
35
|
-
getEmitter: jest.fn().mockReturnValue({
|
|
36
|
-
event: { subscribe: jest.fn() },
|
|
37
|
-
emit: jest.fn(),
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
// Create table using new DI pattern
|
|
42
|
-
const table = new _1.Table(testMetaData, mockDeps);
|
|
43
|
-
// Verify table was created correctly
|
|
44
|
-
expect(table.tableName).toBe("TestTable");
|
|
45
|
-
expect(table.primaryKeyName).toBe("id");
|
|
46
|
-
// Verify schema works by parsing test data successfully
|
|
47
|
-
const testData = { id: "test-id", name: "test-name" };
|
|
48
|
-
expect(() => table.schema.parse(testData)).not.toThrow();
|
|
49
|
-
expect(table.metaData).toBe(testMetaData);
|
|
50
|
-
expect(table.dataSource).toBe(mockDeps.dataSource);
|
|
51
|
-
});
|
|
52
|
-
it("should allow easy custom table extension with DI pattern", () => {
|
|
53
|
-
// Example custom table class
|
|
54
|
-
class CustomTable extends _1.Table {
|
|
55
|
-
// Custom business method
|
|
56
|
-
async findByName(name) {
|
|
57
|
-
return this.list({ name });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const mockDeps = {
|
|
61
|
-
dataSource: {
|
|
62
|
-
tableName: "CustomTable",
|
|
63
|
-
primaryKeyName: "id",
|
|
64
|
-
list: jest.fn().mockResolvedValue([{ id: "1", name: "test" }]),
|
|
65
|
-
get: jest.fn(),
|
|
66
|
-
save: jest.fn(),
|
|
67
|
-
insert: jest.fn(),
|
|
68
|
-
update: jest.fn(),
|
|
69
|
-
delete: jest.fn(),
|
|
70
|
-
},
|
|
71
|
-
eventRegistry: {
|
|
72
|
-
getEmitter: jest.fn().mockReturnValue({
|
|
73
|
-
event: { subscribe: jest.fn() },
|
|
74
|
-
emit: jest.fn(),
|
|
75
|
-
}),
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
const customTable = new CustomTable(testMetaData, mockDeps);
|
|
79
|
-
// Verify custom table works
|
|
80
|
-
expect(customTable).toBeInstanceOf(_1.Table);
|
|
81
|
-
expect(customTable).toBeInstanceOf(CustomTable);
|
|
82
|
-
// Verify custom method exists
|
|
83
|
-
expect(typeof customTable.findByName).toBe("function");
|
|
84
|
-
});
|
|
85
|
-
it("should create table dependencies using DataContext factory method", () => {
|
|
86
|
-
// Create mock DataContext
|
|
87
|
-
const mockUserContext = {
|
|
88
|
-
userId: () => "test-user",
|
|
89
|
-
dataSourceFactory: jest.fn().mockReturnValue({
|
|
90
|
-
tableName: "TestTable",
|
|
91
|
-
primaryKeyName: "id",
|
|
92
|
-
list: jest.fn(),
|
|
93
|
-
}),
|
|
94
|
-
};
|
|
95
|
-
const dataContext = new data_context_1.DataContext(mockUserContext);
|
|
96
|
-
// Use factory method to create dependencies
|
|
97
|
-
const deps = dataContext.createTableDependencies(testMetaData, testSchema);
|
|
98
|
-
// Verify dependencies were created correctly
|
|
99
|
-
expect(deps.dataSource).toBeDefined();
|
|
100
|
-
expect(deps.eventRegistry).toBeDefined();
|
|
101
|
-
expect(deps.schema).toBe(testSchema); // Schema should be passed through when explicitly provided
|
|
102
|
-
expect(deps.eventRegistry).toBe(dataContext.eventRegistry);
|
|
103
|
-
});
|
|
104
|
-
it("should compute schema from metaData when not provided in dependencies", () => {
|
|
105
|
-
// Create mock dependencies without schema
|
|
106
|
-
const mockDeps = {
|
|
107
|
-
dataSource: {
|
|
108
|
-
tableName: "TestTable",
|
|
109
|
-
primaryKeyName: "id",
|
|
110
|
-
list: jest.fn().mockResolvedValue([]),
|
|
111
|
-
get: jest.fn().mockResolvedValue(null),
|
|
112
|
-
save: jest.fn().mockResolvedValue({}),
|
|
113
|
-
insert: jest.fn().mockResolvedValue({}),
|
|
114
|
-
update: jest.fn().mockResolvedValue({}),
|
|
115
|
-
delete: jest.fn().mockResolvedValue(undefined),
|
|
116
|
-
},
|
|
117
|
-
eventRegistry: {
|
|
118
|
-
getEmitter: jest.fn().mockReturnValue({
|
|
119
|
-
event: { subscribe: jest.fn() },
|
|
120
|
-
emit: jest.fn(),
|
|
121
|
-
}),
|
|
122
|
-
},
|
|
123
|
-
// Note: no schema provided
|
|
124
|
-
};
|
|
125
|
-
// Create table - schema should be computed from metaData.fields
|
|
126
|
-
const table = new _1.Table(testMetaData, mockDeps);
|
|
127
|
-
// Verify schema was computed correctly by testing it works
|
|
128
|
-
const testData = { id: "test-id", name: "test-name" };
|
|
129
|
-
expect(() => table.schema.parse(testData)).not.toThrow();
|
|
130
|
-
});
|
|
131
|
-
it("should create tables using DataContext convenience method", () => {
|
|
132
|
-
// Create mock DataContext
|
|
133
|
-
const mockUserContext = {
|
|
134
|
-
userId: () => "test-user",
|
|
135
|
-
dataSourceFactory: jest.fn().mockReturnValue({
|
|
136
|
-
tableName: "TestTable",
|
|
137
|
-
primaryKeyName: "id",
|
|
138
|
-
list: jest.fn(),
|
|
139
|
-
}),
|
|
140
|
-
};
|
|
141
|
-
const dataContext = new data_context_1.DataContext(mockUserContext);
|
|
142
|
-
// Use convenience method to create table
|
|
143
|
-
const table = dataContext.createTable(testMetaData, testSchema);
|
|
144
|
-
// Verify table was created correctly
|
|
145
|
-
expect(table).toBeInstanceOf(_1.Table);
|
|
146
|
-
expect(table.tableName).toBe("TestTable");
|
|
147
|
-
// Table merges fields-derived schema with code schema, so it's not the same reference
|
|
148
|
-
const testData = { id: "test-id", name: "test-name" };
|
|
149
|
-
expect(() => table.schema.parse(testData)).not.toThrow();
|
|
150
|
-
});
|
|
151
|
-
it("should create tables through TableFactory using new DI pattern internally", () => {
|
|
152
|
-
// Create mock DataContext
|
|
153
|
-
const mockUserContext = {
|
|
154
|
-
userId: () => "test-user",
|
|
155
|
-
dataSourceFactory: jest.fn().mockReturnValue({
|
|
156
|
-
tableName: "TestTable",
|
|
157
|
-
primaryKeyName: "id",
|
|
158
|
-
list: jest.fn(),
|
|
159
|
-
}),
|
|
160
|
-
};
|
|
161
|
-
const dataContext = new data_context_1.DataContext(mockUserContext);
|
|
162
|
-
// Use TableFactory (which should internally use DI pattern now)
|
|
163
|
-
const table = dataContext.tableContainer.getTable(testMetaData, testSchema);
|
|
164
|
-
// Verify table was created correctly through TableFactory
|
|
165
|
-
expect(table).toBeInstanceOf(_1.Table);
|
|
166
|
-
expect(table.tableName).toBe("TestTable");
|
|
167
|
-
// Table merges fields-derived schema with code schema, so it's not the same reference
|
|
168
|
-
expect(() => table.schema.parse({ id: "test-id", name: "test-name" })).not.toThrow();
|
|
169
|
-
expect(table.metaData).toBe(testMetaData);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const event_registry_1 = require("./event-registry");
|
|
4
|
-
describe("EventRegistry", () => {
|
|
5
|
-
let registry;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
const mockDataContext = {
|
|
8
|
-
dataContextId: "test-context",
|
|
9
|
-
};
|
|
10
|
-
registry = new event_registry_1.EventRegistry(mockDataContext);
|
|
11
|
-
});
|
|
12
|
-
it("should return the same emitter for the same event name", () => {
|
|
13
|
-
const emitter1 = registry.getEmitter("test-event");
|
|
14
|
-
const emitter2 = registry.getEmitter("test-event");
|
|
15
|
-
expect(emitter1).toBe(emitter2);
|
|
16
|
-
expect(registry.getEmitterCount()).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
it("should return different emitters for different event names", () => {
|
|
19
|
-
const emitter1 = registry.getEmitter("event-1");
|
|
20
|
-
const emitter2 = registry.getEmitter("event-2");
|
|
21
|
-
expect(emitter1).not.toBe(emitter2);
|
|
22
|
-
expect(registry.getEmitterCount()).toBe(2);
|
|
23
|
-
});
|
|
24
|
-
it("should clear all emitters", () => {
|
|
25
|
-
registry.getEmitter("event-1");
|
|
26
|
-
registry.getEmitter("event-2");
|
|
27
|
-
expect(registry.getEmitterCount()).toBe(2);
|
|
28
|
-
registry.clear();
|
|
29
|
-
expect(registry.getEmitterCount()).toBe(0);
|
|
30
|
-
});
|
|
31
|
-
it("should handle event emission and subscription across shared emitters", async () => {
|
|
32
|
-
const emitter1 = registry.getEmitter("shared-event");
|
|
33
|
-
const emitter2 = registry.getEmitter("shared-event");
|
|
34
|
-
// They should be the same instance
|
|
35
|
-
expect(emitter1).toBe(emitter2);
|
|
36
|
-
// Test event flow
|
|
37
|
-
let receivedData;
|
|
38
|
-
emitter1.event.subscribe((data) => {
|
|
39
|
-
receivedData = data;
|
|
40
|
-
});
|
|
41
|
-
await emitter2.emit("test-data");
|
|
42
|
-
expect(receivedData).toBe("test-data");
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const field_type_1 = require("../../types/field-type");
|
|
4
|
-
const data_query_1 = require("./data-query");
|
|
5
|
-
const factory_1 = require("./factory");
|
|
6
|
-
const multi_cursors_1 = require("./multi-cursors");
|
|
7
|
-
function createMockCursor(items) {
|
|
8
|
-
let index = 0;
|
|
9
|
-
const cursor = {
|
|
10
|
-
value: null,
|
|
11
|
-
next: async (_skipPast) => {
|
|
12
|
-
if (index >= items.length) {
|
|
13
|
-
cursor.value = null;
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
cursor.value = items[index];
|
|
17
|
-
index++;
|
|
18
|
-
return cursor.value;
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
return (0, data_query_1.iterableCursor)(cursor);
|
|
22
|
-
}
|
|
23
|
-
describe("cursorUnion", () => {
|
|
24
|
-
it("should return items from first cursor, then second cursor in order", async () => {
|
|
25
|
-
const cursor1 = createMockCursor([1, 2, 3]);
|
|
26
|
-
const cursor2 = createMockCursor([4, 5, 6]);
|
|
27
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1, cursor2]);
|
|
28
|
-
const results = [];
|
|
29
|
-
for await (const item of unionCursor) {
|
|
30
|
-
results.push(item);
|
|
31
|
-
}
|
|
32
|
-
expect(results).toEqual([1, 2, 3, 4, 5, 6]);
|
|
33
|
-
});
|
|
34
|
-
it("should handle empty cursors gracefully", async () => {
|
|
35
|
-
const cursor1 = createMockCursor([1, 2]);
|
|
36
|
-
const cursor2 = createMockCursor([]);
|
|
37
|
-
const cursor3 = createMockCursor([3, 4]);
|
|
38
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1, cursor2, cursor3]);
|
|
39
|
-
const results = [];
|
|
40
|
-
for await (const item of unionCursor) {
|
|
41
|
-
results.push(item);
|
|
42
|
-
}
|
|
43
|
-
expect(results).toEqual([1, 2, 3, 4]);
|
|
44
|
-
});
|
|
45
|
-
it("should return empty result when all cursors are empty", async () => {
|
|
46
|
-
const cursor1 = createMockCursor([]);
|
|
47
|
-
const cursor2 = createMockCursor([]);
|
|
48
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1, cursor2]);
|
|
49
|
-
const results = [];
|
|
50
|
-
for await (const item of unionCursor) {
|
|
51
|
-
results.push(item);
|
|
52
|
-
}
|
|
53
|
-
expect(results).toEqual([]);
|
|
54
|
-
});
|
|
55
|
-
it("should work with single cursor", async () => {
|
|
56
|
-
const cursor1 = createMockCursor(["a", "b", "c"]);
|
|
57
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1]);
|
|
58
|
-
const results = [];
|
|
59
|
-
for await (const item of unionCursor) {
|
|
60
|
-
results.push(item);
|
|
61
|
-
}
|
|
62
|
-
expect(results).toEqual(["a", "b", "c"]);
|
|
63
|
-
});
|
|
64
|
-
it("should work with no cursors", async () => {
|
|
65
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([]);
|
|
66
|
-
const results = [];
|
|
67
|
-
for await (const item of unionCursor) {
|
|
68
|
-
results.push(item);
|
|
69
|
-
}
|
|
70
|
-
expect(results).toEqual([]);
|
|
71
|
-
});
|
|
72
|
-
it("should work with manual next() calls", async () => {
|
|
73
|
-
const cursor1 = createMockCursor([10, 20]);
|
|
74
|
-
const cursor2 = createMockCursor([30, 40]);
|
|
75
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1, cursor2]);
|
|
76
|
-
const results = [];
|
|
77
|
-
while (await unionCursor.next()) {
|
|
78
|
-
results.push(unionCursor.value);
|
|
79
|
-
}
|
|
80
|
-
expect(results).toEqual([10, 20, 30, 40]);
|
|
81
|
-
});
|
|
82
|
-
it("should handle different data types", async () => {
|
|
83
|
-
const cursor1 = createMockCursor([
|
|
84
|
-
{ id: 1, name: "John" },
|
|
85
|
-
{ id: 2, name: "Jane" },
|
|
86
|
-
]);
|
|
87
|
-
const cursor2 = createMockCursor([{ id: 3, name: "Bob" }]);
|
|
88
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1, cursor2]);
|
|
89
|
-
const results = [];
|
|
90
|
-
for await (const item of unionCursor) {
|
|
91
|
-
results.push(item);
|
|
92
|
-
}
|
|
93
|
-
expect(results).toEqual([
|
|
94
|
-
{ id: 1, name: "John" },
|
|
95
|
-
{ id: 2, name: "Jane" },
|
|
96
|
-
{ id: 3, name: "Bob" },
|
|
97
|
-
]);
|
|
98
|
-
});
|
|
99
|
-
it("should maintain cursor.value correctly", async () => {
|
|
100
|
-
const cursor1 = createMockCursor(["first", "second"]);
|
|
101
|
-
const cursor2 = createMockCursor(["third"]);
|
|
102
|
-
const unionCursor = (0, multi_cursors_1.cursorUnion)([cursor1, cursor2]);
|
|
103
|
-
// First item
|
|
104
|
-
await unionCursor.next();
|
|
105
|
-
expect(unionCursor.value).toBe("first");
|
|
106
|
-
// Second item
|
|
107
|
-
await unionCursor.next();
|
|
108
|
-
expect(unionCursor.value).toBe("second");
|
|
109
|
-
// Third item (from second cursor)
|
|
110
|
-
await unionCursor.next();
|
|
111
|
-
expect(unionCursor.value).toBe("third");
|
|
112
|
-
// End of data
|
|
113
|
-
const result = await unionCursor.next();
|
|
114
|
-
expect(result).toBeNull();
|
|
115
|
-
expect(unionCursor.value).toBeNull();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
function createMockDataSource(items, tableName, primaryKeyName = "id") {
|
|
119
|
-
return (0, factory_1.arrayAsTable)(items, {
|
|
120
|
-
name: tableName,
|
|
121
|
-
primaryKeyName,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
describe("sortLikeSQL", () => {
|
|
125
|
-
it("should sort by ascending field correctly", () => {
|
|
126
|
-
const a = { id: 1, name: "Alice" };
|
|
127
|
-
const b = { id: 2, name: "Bob" };
|
|
128
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["id"], a, b)).toBe(-1); // a < b
|
|
129
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["id"], b, a)).toBe(1); // b > a
|
|
130
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["id"], a, a)).toBe(0); // a === a
|
|
131
|
-
});
|
|
132
|
-
it("should sort by descending field correctly", () => {
|
|
133
|
-
const a = { id: 1, name: "Alice" };
|
|
134
|
-
const b = { id: 2, name: "Bob" };
|
|
135
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["-id"], a, b)).toBe(1); // a > b (desc)
|
|
136
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["-id"], b, a)).toBe(-1); // b < a (desc)
|
|
137
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["-id"], a, a)).toBe(0); // a === a
|
|
138
|
-
});
|
|
139
|
-
it("should handle multiple sort fields", () => {
|
|
140
|
-
const a = { name: "Alice", age: 25 };
|
|
141
|
-
const b = { name: "Alice", age: 30 };
|
|
142
|
-
const c = { name: "Bob", age: 25 };
|
|
143
|
-
// First by name, then by age
|
|
144
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["name", "age"], a, b)).toBe(-1); // same name, a.age < b.age
|
|
145
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["name", "age"], a, c)).toBe(-1); // a.name < c.name
|
|
146
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["name", "age"], c, a)).toBe(1); // c.name > a.name
|
|
147
|
-
});
|
|
148
|
-
it("should handle null/undefined values like SQL", () => {
|
|
149
|
-
const a = { id: 1, name: null };
|
|
150
|
-
const b = { id: 2, name: "Bob" };
|
|
151
|
-
const c = { id: 3 }; // name is undefined
|
|
152
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["name"], a, b)).toBe(-1); // null < string (treated as -Infinity)
|
|
153
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["name"], c, b)).toBe(-1); // undefined < string (treated as -Infinity)
|
|
154
|
-
expect((0, multi_cursors_1.sortLikeSQL)(["name"], a, c)).toBe(0); // null === undefined (both -Infinity)
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe("queryMerge", () => {
|
|
158
|
-
it("should merge data from multiple sources in sorted order", async () => {
|
|
159
|
-
const dataSource1 = createMockDataSource([
|
|
160
|
-
{ id: 1, name: "Alice" },
|
|
161
|
-
{ id: 3, name: "Charlie" },
|
|
162
|
-
{ id: 5, name: "Eve" },
|
|
163
|
-
], "table1");
|
|
164
|
-
const dataSource2 = createMockDataSource([
|
|
165
|
-
{ id: 2, name: "Bob" },
|
|
166
|
-
{ id: 4, name: "David" },
|
|
167
|
-
{ id: 6, name: "Frank" },
|
|
168
|
-
], "table2");
|
|
169
|
-
const cursor = (0, multi_cursors_1.queryMerge)([dataSource1, dataSource2]);
|
|
170
|
-
const results = [];
|
|
171
|
-
for await (const item of cursor) {
|
|
172
|
-
results.push(item);
|
|
173
|
-
}
|
|
174
|
-
expect(results.map((r) => r.id)).toEqual([1, 2, 3, 4, 5, 6]);
|
|
175
|
-
expect(results.map((r) => r.name)).toEqual([
|
|
176
|
-
"Alice",
|
|
177
|
-
"Bob",
|
|
178
|
-
"Charlie",
|
|
179
|
-
"David",
|
|
180
|
-
"Eve",
|
|
181
|
-
"Frank",
|
|
182
|
-
]);
|
|
183
|
-
});
|
|
184
|
-
it("should handle empty data sources", async () => {
|
|
185
|
-
const dataSource1 = (0, factory_1.arrayAsTable)([], {
|
|
186
|
-
name: "table1",
|
|
187
|
-
primaryKeyName: "id",
|
|
188
|
-
fields: [
|
|
189
|
-
{ name: "id", type: field_type_1.FieldType.number },
|
|
190
|
-
{ name: "name", type: field_type_1.FieldType.string },
|
|
191
|
-
],
|
|
192
|
-
});
|
|
193
|
-
const dataSource2 = createMockDataSource([{ id: 1, name: "Alice" }], "table2");
|
|
194
|
-
const cursor = (0, multi_cursors_1.queryMerge)([dataSource1, dataSource2]);
|
|
195
|
-
const results = [];
|
|
196
|
-
for await (const item of cursor) {
|
|
197
|
-
results.push(item);
|
|
198
|
-
}
|
|
199
|
-
expect(results).toEqual([{ id: 1, name: "Alice" }]);
|
|
200
|
-
});
|
|
201
|
-
it("should handle no data sources", async () => {
|
|
202
|
-
const cursor = (0, multi_cursors_1.queryMerge)([]);
|
|
203
|
-
const results = [];
|
|
204
|
-
for await (const item of cursor) {
|
|
205
|
-
results.push(item);
|
|
206
|
-
}
|
|
207
|
-
expect(results).toEqual([]);
|
|
208
|
-
});
|
|
209
|
-
it("should respect custom sort order", async () => {
|
|
210
|
-
// Use pre-sorted data to avoid arrayAsTable sorting issues
|
|
211
|
-
const dataSource1 = createMockDataSource([
|
|
212
|
-
{ id: 1, name: "Alice", age: 30 },
|
|
213
|
-
{ id: 3, name: "Charlie", age: 25 },
|
|
214
|
-
], "table1");
|
|
215
|
-
const dataSource2 = createMockDataSource([
|
|
216
|
-
{ id: 2, name: "Bob", age: 28 },
|
|
217
|
-
{ id: 4, name: "David", age: 22 },
|
|
218
|
-
], "table2");
|
|
219
|
-
// Sort by name ascending - data sources already have data in correct order
|
|
220
|
-
const cursor = (0, multi_cursors_1.queryMerge)([dataSource1, dataSource2], {}, { sortBy: ["name"] });
|
|
221
|
-
const results = [];
|
|
222
|
-
for await (const item of cursor) {
|
|
223
|
-
results.push(item);
|
|
224
|
-
}
|
|
225
|
-
expect(results.map((r) => r.name)).toEqual(["Alice", "Bob", "Charlie", "David"]);
|
|
226
|
-
});
|
|
227
|
-
it("should work with single data source", async () => {
|
|
228
|
-
const dataSource = createMockDataSource([
|
|
229
|
-
{ id: 1, name: "Alice" },
|
|
230
|
-
{ id: 2, name: "Bob" },
|
|
231
|
-
{ id: 3, name: "Charlie" },
|
|
232
|
-
], "table1");
|
|
233
|
-
const cursor = (0, multi_cursors_1.queryMerge)([dataSource]);
|
|
234
|
-
const results = [];
|
|
235
|
-
for await (const item of cursor) {
|
|
236
|
-
results.push(item);
|
|
237
|
-
}
|
|
238
|
-
// Should be sorted by id (default primary key sort)
|
|
239
|
-
expect(results.map((r) => r.id)).toEqual([1, 2, 3]);
|
|
240
|
-
});
|
|
241
|
-
it("should work with manual next() calls", async () => {
|
|
242
|
-
const dataSource1 = createMockDataSource([{ id: 1, name: "Alice" }], "table1");
|
|
243
|
-
const dataSource2 = createMockDataSource([{ id: 2, name: "Bob" }], "table2");
|
|
244
|
-
const cursor = (0, multi_cursors_1.queryMerge)([dataSource1, dataSource2]);
|
|
245
|
-
const results = [];
|
|
246
|
-
while (await cursor.next()) {
|
|
247
|
-
results.push(cursor.value);
|
|
248
|
-
}
|
|
249
|
-
expect(results.map((r) => r?.id)).toEqual([1, 2]);
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
describe("cursorMap", () => {
|
|
253
|
-
it("should map cursor values using synchronous function", async () => {
|
|
254
|
-
const sourceCursor = createMockCursor([1, 2, 3, 4, 5]);
|
|
255
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, (x) => x * 2);
|
|
256
|
-
const results = [];
|
|
257
|
-
for await (const item of mappedCursor) {
|
|
258
|
-
results.push(item);
|
|
259
|
-
}
|
|
260
|
-
expect(results).toEqual([2, 4, 6, 8, 10]);
|
|
261
|
-
});
|
|
262
|
-
it("should map cursor values using async function", async () => {
|
|
263
|
-
const sourceCursor = createMockCursor(["a", "b", "c"]);
|
|
264
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, async (x) => {
|
|
265
|
-
// Simulate async operation
|
|
266
|
-
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
267
|
-
return x.toUpperCase();
|
|
268
|
-
});
|
|
269
|
-
const results = [];
|
|
270
|
-
for await (const item of mappedCursor) {
|
|
271
|
-
results.push(item);
|
|
272
|
-
}
|
|
273
|
-
expect(results).toEqual(["A", "B", "C"]);
|
|
274
|
-
});
|
|
275
|
-
it("should transform data types correctly", async () => {
|
|
276
|
-
const sourceCursor = createMockCursor([
|
|
277
|
-
{ id: 1, name: "Alice", age: 25 },
|
|
278
|
-
{ id: 2, name: "Bob", age: 30 },
|
|
279
|
-
{ id: 3, name: "Charlie", age: 35 },
|
|
280
|
-
]);
|
|
281
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, (person) => `${person.name} is ${person.age} years old`);
|
|
282
|
-
const results = [];
|
|
283
|
-
for await (const item of mappedCursor) {
|
|
284
|
-
results.push(item);
|
|
285
|
-
}
|
|
286
|
-
expect(results).toEqual([
|
|
287
|
-
"Alice is 25 years old",
|
|
288
|
-
"Bob is 30 years old",
|
|
289
|
-
"Charlie is 35 years old",
|
|
290
|
-
]);
|
|
291
|
-
});
|
|
292
|
-
it("should handle empty cursors", async () => {
|
|
293
|
-
const sourceCursor = createMockCursor([]);
|
|
294
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, (x) => x * 2);
|
|
295
|
-
const results = [];
|
|
296
|
-
for await (const item of mappedCursor) {
|
|
297
|
-
results.push(item);
|
|
298
|
-
}
|
|
299
|
-
expect(results).toEqual([]);
|
|
300
|
-
});
|
|
301
|
-
it("should work with manual next() calls", async () => {
|
|
302
|
-
const sourceCursor = createMockCursor([10, 20, 30]);
|
|
303
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, (x) => x / 10);
|
|
304
|
-
const results = [];
|
|
305
|
-
while (await mappedCursor.next()) {
|
|
306
|
-
results.push(mappedCursor.value);
|
|
307
|
-
}
|
|
308
|
-
expect(results).toEqual([1, 2, 3]);
|
|
309
|
-
});
|
|
310
|
-
it("should maintain cursor.value correctly", async () => {
|
|
311
|
-
const sourceCursor = createMockCursor(["hello", "world"]);
|
|
312
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, (x) => x.length);
|
|
313
|
-
// First item
|
|
314
|
-
await mappedCursor.next();
|
|
315
|
-
expect(mappedCursor.value).toBe(5);
|
|
316
|
-
// Second item
|
|
317
|
-
await mappedCursor.next();
|
|
318
|
-
expect(mappedCursor.value).toBe(5);
|
|
319
|
-
// End of data
|
|
320
|
-
const result = await mappedCursor.next();
|
|
321
|
-
expect(result).toBeNull();
|
|
322
|
-
expect(mappedCursor.value).toBeNull();
|
|
323
|
-
});
|
|
324
|
-
it("should handle async errors in map function", async () => {
|
|
325
|
-
const sourceCursor = createMockCursor([1, 2, 3]);
|
|
326
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, async (x) => {
|
|
327
|
-
if (x === 2) {
|
|
328
|
-
throw new Error("Test error");
|
|
329
|
-
}
|
|
330
|
-
return x * 2;
|
|
331
|
-
});
|
|
332
|
-
const results = [];
|
|
333
|
-
let errorCaught = false;
|
|
334
|
-
try {
|
|
335
|
-
for await (const item of mappedCursor) {
|
|
336
|
-
results.push(item);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
catch (error) {
|
|
340
|
-
errorCaught = true;
|
|
341
|
-
expect(error.message).toBe("Test error");
|
|
342
|
-
}
|
|
343
|
-
expect(errorCaught).toBe(true);
|
|
344
|
-
expect(results).toEqual([2]); // Only first item before error
|
|
345
|
-
});
|
|
346
|
-
it("should throw error when skipPast is used", async () => {
|
|
347
|
-
const sourceCursor = createMockCursor([1, 2, 3]);
|
|
348
|
-
const mappedCursor = (0, multi_cursors_1.cursorMap)(sourceCursor, (x) => x * 2);
|
|
349
|
-
await expect(mappedCursor.next(4)).rejects.toThrow("skipPast is not supported for cursorMap since the mapped cursor has a different type than the source cursor");
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
describe("cursorFilter", () => {
|
|
353
|
-
it("should filter cursor values using synchronous predicate", async () => {
|
|
354
|
-
const sourceCursor = createMockCursor([1, 2, 3, 4, 5, 6]);
|
|
355
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (x) => x % 2 === 0);
|
|
356
|
-
const results = [];
|
|
357
|
-
for await (const item of filteredCursor) {
|
|
358
|
-
results.push(item);
|
|
359
|
-
}
|
|
360
|
-
expect(results).toEqual([2, 4, 6]);
|
|
361
|
-
});
|
|
362
|
-
it("should filter cursor values using async predicate", async () => {
|
|
363
|
-
const sourceCursor = createMockCursor(["apple", "banana", "cherry", "date"]);
|
|
364
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, async (x) => {
|
|
365
|
-
// Simulate async operation
|
|
366
|
-
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
367
|
-
return x.length > 5;
|
|
368
|
-
});
|
|
369
|
-
const results = [];
|
|
370
|
-
for await (const item of filteredCursor) {
|
|
371
|
-
results.push(item);
|
|
372
|
-
}
|
|
373
|
-
expect(results).toEqual(["banana", "cherry"]);
|
|
374
|
-
});
|
|
375
|
-
it("should filter objects based on properties", async () => {
|
|
376
|
-
const sourceCursor = createMockCursor([
|
|
377
|
-
{ id: 1, name: "Alice", age: 25 },
|
|
378
|
-
{ id: 2, name: "Bob", age: 30 },
|
|
379
|
-
{ id: 3, name: "Charlie", age: 35 },
|
|
380
|
-
{ id: 4, name: "David", age: 20 },
|
|
381
|
-
]);
|
|
382
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (person) => person.age >= 30);
|
|
383
|
-
const results = [];
|
|
384
|
-
for await (const item of filteredCursor) {
|
|
385
|
-
results.push(item);
|
|
386
|
-
}
|
|
387
|
-
expect(results).toEqual([
|
|
388
|
-
{ id: 2, name: "Bob", age: 30 },
|
|
389
|
-
{ id: 3, name: "Charlie", age: 35 },
|
|
390
|
-
]);
|
|
391
|
-
});
|
|
392
|
-
it("should handle empty cursors", async () => {
|
|
393
|
-
const sourceCursor = createMockCursor([]);
|
|
394
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (x) => x > 0);
|
|
395
|
-
const results = [];
|
|
396
|
-
for await (const item of filteredCursor) {
|
|
397
|
-
results.push(item);
|
|
398
|
-
}
|
|
399
|
-
expect(results).toEqual([]);
|
|
400
|
-
});
|
|
401
|
-
it("should handle cursors where no items match filter", async () => {
|
|
402
|
-
const sourceCursor = createMockCursor([1, 2, 3, 4, 5]);
|
|
403
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (x) => x > 10);
|
|
404
|
-
const results = [];
|
|
405
|
-
for await (const item of filteredCursor) {
|
|
406
|
-
results.push(item);
|
|
407
|
-
}
|
|
408
|
-
expect(results).toEqual([]);
|
|
409
|
-
});
|
|
410
|
-
it("should work with manual next() calls", async () => {
|
|
411
|
-
const sourceCursor = createMockCursor([10, 15, 20, 25, 30]);
|
|
412
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (x) => x >= 20);
|
|
413
|
-
const results = [];
|
|
414
|
-
while (await filteredCursor.next()) {
|
|
415
|
-
results.push(filteredCursor.value);
|
|
416
|
-
}
|
|
417
|
-
expect(results).toEqual([20, 25, 30]);
|
|
418
|
-
});
|
|
419
|
-
it("should maintain cursor.value correctly", async () => {
|
|
420
|
-
const sourceCursor = createMockCursor(["hello", "hi", "world", "test"]);
|
|
421
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (x) => x.length > 3);
|
|
422
|
-
// First item
|
|
423
|
-
await filteredCursor.next();
|
|
424
|
-
expect(filteredCursor.value).toBe("hello");
|
|
425
|
-
// Second item
|
|
426
|
-
await filteredCursor.next();
|
|
427
|
-
expect(filteredCursor.value).toBe("world");
|
|
428
|
-
// Third item
|
|
429
|
-
await filteredCursor.next();
|
|
430
|
-
expect(filteredCursor.value).toBe("test");
|
|
431
|
-
// End of data
|
|
432
|
-
const result = await filteredCursor.next();
|
|
433
|
-
expect(result).toBeNull();
|
|
434
|
-
expect(filteredCursor.value).toBeNull();
|
|
435
|
-
});
|
|
436
|
-
it("should throw error when skipPast is used", async () => {
|
|
437
|
-
const sourceCursor = createMockCursor([1, 2, 3]);
|
|
438
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, (x) => x > 1);
|
|
439
|
-
await expect(filteredCursor.next(2)).rejects.toThrow("skipPast is not supported for cursorFilter since filtering changes the cursor iteration order");
|
|
440
|
-
});
|
|
441
|
-
it("should handle async errors in filter function", async () => {
|
|
442
|
-
const sourceCursor = createMockCursor([1, 2, 3]);
|
|
443
|
-
const filteredCursor = (0, multi_cursors_1.cursorFilter)(sourceCursor, async (x) => {
|
|
444
|
-
if (x === 2) {
|
|
445
|
-
throw new Error("Filter error");
|
|
446
|
-
}
|
|
447
|
-
return x > 0;
|
|
448
|
-
});
|
|
449
|
-
const results = [];
|
|
450
|
-
let errorCaught = false;
|
|
451
|
-
try {
|
|
452
|
-
for await (const item of filteredCursor) {
|
|
453
|
-
results.push(item);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
catch (error) {
|
|
457
|
-
errorCaught = true;
|
|
458
|
-
expect(error.message).toBe("Filter error");
|
|
459
|
-
}
|
|
460
|
-
expect(errorCaught).toBe(true);
|
|
461
|
-
expect(results).toEqual([1]); // Only first item before error
|
|
462
|
-
});
|
|
463
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../../index";
|