@peers-app/peers-sdk 0.27.3 → 0.27.5

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.
Files changed (272) hide show
  1. package/dist/contracts/contract-proxy.d.ts +7 -0
  2. package/dist/contracts/contract-proxy.js +19 -2
  3. package/dist/contracts/contract-transport.d.ts +2 -1
  4. package/dist/contracts/contract-transport.js +24 -2
  5. package/dist/contracts/create-local-consumer.js +16 -1
  6. package/dist/contracts/index.d.ts +2 -0
  7. package/dist/contracts/index.js +2 -0
  8. package/dist/contracts/system/index.d.ts +2 -0
  9. package/dist/contracts/system/index.js +2 -0
  10. package/dist/contracts/system/invites-contract.js +2 -1
  11. package/dist/contracts/system/sync-check-contract.d.ts +97 -0
  12. package/dist/contracts/system/sync-check-contract.js +115 -0
  13. package/dist/contracts/tool-arguments.d.ts +15 -0
  14. package/dist/contracts/tool-arguments.js +41 -0
  15. package/dist/contracts/tool-catalog-service.js +2 -12
  16. package/dist/contracts/tool-catalog.js +6 -2
  17. package/dist/data/change-tracking.d.ts +40 -0
  18. package/dist/data/change-tracking.js +89 -0
  19. package/dist/data/orm/types.d.ts +24 -7
  20. package/dist/data/orm/types.js +97 -24
  21. package/dist/define/manifest.js +6 -34
  22. package/dist/device/binary-peer-connection-v2.d.ts +7 -15
  23. package/dist/device/binary-peer-connection-v2.js +14 -30
  24. package/dist/device/connection.d.ts +34 -43
  25. package/dist/device/connection.js +188 -186
  26. package/dist/device/device.d.ts +1 -8
  27. package/dist/device/device.js +1 -30
  28. package/dist/device/socket.type.d.ts +6 -12
  29. package/dist/package-loader/package-loader.js +27 -22
  30. package/dist/system-ids.d.ts +5 -0
  31. package/dist/system-ids.js +6 -1
  32. package/package.json +4 -2
  33. package/dist/context/user-context-identity.test.d.ts +0 -1
  34. package/dist/context/user-context-identity.test.js +0 -220
  35. package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
  36. package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
  37. package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
  38. package/dist/contracts/__tests__/also-implements.test.js +0 -110
  39. package/dist/contracts/__tests__/builder.test.d.ts +0 -1
  40. package/dist/contracts/__tests__/builder.test.js +0 -669
  41. package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
  42. package/dist/contracts/__tests__/contract-events.test.js +0 -199
  43. package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
  44. package/dist/contracts/__tests__/contract-observables.test.js +0 -290
  45. package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
  46. package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
  47. package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
  48. package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
  49. package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
  50. package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
  51. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
  52. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
  53. package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
  54. package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
  55. package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
  56. package/dist/contracts/__tests__/contract-transport.test.js +0 -163
  57. package/dist/contracts/__tests__/extract.test.d.ts +0 -1
  58. package/dist/contracts/__tests__/extract.test.js +0 -145
  59. package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
  60. package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
  61. package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
  62. package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
  63. package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
  64. package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
  65. package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
  66. package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
  67. package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
  68. package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
  69. package/dist/contracts/__tests__/integration.test.d.ts +0 -1
  70. package/dist/contracts/__tests__/integration.test.js +0 -348
  71. package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
  72. package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
  73. package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
  74. package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
  75. package/dist/contracts/__tests__/playground.test.d.ts +0 -1
  76. package/dist/contracts/__tests__/playground.test.js +0 -216
  77. package/dist/contracts/__tests__/registry.test.d.ts +0 -1
  78. package/dist/contracts/__tests__/registry.test.js +0 -238
  79. package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
  80. package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
  81. package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
  82. package/dist/contracts/__tests__/system-contracts.test.js +0 -247
  83. package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
  84. package/dist/contracts/__tests__/target-dispatch.js +0 -24
  85. package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
  86. package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
  87. package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
  88. package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
  89. package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
  90. package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
  91. package/dist/contracts/__tests__/validate.test.d.ts +0 -1
  92. package/dist/contracts/__tests__/validate.test.js +0 -991
  93. package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
  94. package/dist/contracts/__tests__/workflow-context.test.js +0 -50
  95. package/dist/data/access-level.test.d.ts +0 -1
  96. package/dist/data/access-level.test.js +0 -53
  97. package/dist/data/change-tracking.test.d.ts +0 -1
  98. package/dist/data/change-tracking.test.js +0 -62
  99. package/dist/data/files/files.test.d.ts +0 -1
  100. package/dist/data/files/files.test.js +0 -770
  101. package/dist/data/group-members.test.d.ts +0 -1
  102. package/dist/data/group-members.test.js +0 -336
  103. package/dist/data/group-share.test.d.ts +0 -1
  104. package/dist/data/group-share.test.js +0 -110
  105. package/dist/data/groups.test.d.ts +0 -1
  106. package/dist/data/groups.test.js +0 -153
  107. package/dist/data/orm/cursor.test.d.ts +0 -1
  108. package/dist/data/orm/cursor.test.js +0 -314
  109. package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
  110. package/dist/data/orm/data-query.mongo.test.js +0 -367
  111. package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
  112. package/dist/data/orm/data-query.sqlite.test.js +0 -365
  113. package/dist/data/orm/data-query.test.d.ts +0 -1
  114. package/dist/data/orm/data-query.test.js +0 -545
  115. package/dist/data/orm/dependency-injection.test.d.ts +0 -1
  116. package/dist/data/orm/dependency-injection.test.js +0 -171
  117. package/dist/data/orm/event-registry.test.d.ts +0 -1
  118. package/dist/data/orm/event-registry.test.js +0 -44
  119. package/dist/data/orm/multi-cursors.test.d.ts +0 -1
  120. package/dist/data/orm/multi-cursors.test.js +0 -463
  121. package/dist/data/orm/sql.data-source.test.d.ts +0 -1
  122. package/dist/data/orm/sql.data-source.test.js +0 -731
  123. package/dist/data/orm/table-container-events.test.d.ts +0 -1
  124. package/dist/data/orm/table-container-events.test.js +0 -101
  125. package/dist/data/orm/table-container.test.d.ts +0 -1
  126. package/dist/data/orm/table-container.test.js +0 -273
  127. package/dist/data/orm/table.event-source.test.d.ts +0 -1
  128. package/dist/data/orm/table.event-source.test.js +0 -331
  129. package/dist/data/orm/types.test.d.ts +0 -1
  130. package/dist/data/orm/types.test.js +0 -409
  131. package/dist/data/package-table-identity.test.d.ts +0 -1
  132. package/dist/data/package-table-identity.test.js +0 -46
  133. package/dist/data/package-version-permissions.test.d.ts +0 -1
  134. package/dist/data/package-version-permissions.test.js +0 -107
  135. package/dist/data/package-version-resolver.test.d.ts +0 -4
  136. package/dist/data/package-version-resolver.test.js +0 -543
  137. package/dist/data/package-versions.test.d.ts +0 -1
  138. package/dist/data/package-versions.test.js +0 -227
  139. package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
  140. package/dist/data/persistent-vars.conflict.test.js +0 -126
  141. package/dist/data/persistent-vars.migration.test.d.ts +0 -1
  142. package/dist/data/persistent-vars.migration.test.js +0 -133
  143. package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
  144. package/dist/data/persistent-vars.package-scope.test.js +0 -27
  145. package/dist/data/sync-recovery-queue.test.d.ts +0 -1
  146. package/dist/data/sync-recovery-queue.test.js +0 -215
  147. package/dist/data/table-signing.test.d.ts +0 -1
  148. package/dist/data/table-signing.test.js +0 -118
  149. package/dist/data/tool-access.test.d.ts +0 -1
  150. package/dist/data/tool-access.test.js +0 -166
  151. package/dist/data/user-permissions.test.d.ts +0 -1
  152. package/dist/data/user-permissions.test.js +0 -305
  153. package/dist/data/user-trust-levels.test.d.ts +0 -1
  154. package/dist/data/user-trust-levels.test.js +0 -37
  155. package/dist/define/also-implements.test.d.ts +0 -1
  156. package/dist/define/also-implements.test.js +0 -123
  157. package/dist/define/declare-contract.test.d.ts +0 -1
  158. package/dist/define/declare-contract.test.js +0 -573
  159. package/dist/define/define.test.d.ts +0 -1
  160. package/dist/define/define.test.js +0 -1010
  161. package/dist/define/empty-fields.test.d.ts +0 -1
  162. package/dist/define/empty-fields.test.js +0 -55
  163. package/dist/define/events-observables.test.d.ts +0 -1
  164. package/dist/define/events-observables.test.js +0 -1013
  165. package/dist/define/serve-members.test.d.ts +0 -1
  166. package/dist/define/serve-members.test.js +0 -630
  167. package/dist/define/vars.test.d.ts +0 -1
  168. package/dist/define/vars.test.js +0 -39
  169. package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
  170. package/dist/device/binary-peer-connection-v2.test.js +0 -730
  171. package/dist/device/binary-peer-connection.d.ts +0 -58
  172. package/dist/device/binary-peer-connection.js +0 -516
  173. package/dist/device/binary-peer-connection.test.d.ts +0 -1
  174. package/dist/device/binary-peer-connection.test.js +0 -184
  175. package/dist/device/connection.test.d.ts +0 -1
  176. package/dist/device/connection.test.js +0 -613
  177. package/dist/device/device-election.test.d.ts +0 -1
  178. package/dist/device/device-election.test.js +0 -516
  179. package/dist/device/device.test.d.ts +0 -1
  180. package/dist/device/device.test.js +0 -243
  181. package/dist/device/frame-cipher.test.d.ts +0 -1
  182. package/dist/device/frame-cipher.test.js +0 -219
  183. package/dist/device/get-trust-level-fn.test.d.ts +0 -1
  184. package/dist/device/get-trust-level-fn.test.js +0 -685
  185. package/dist/device/streamed-socket.d.ts +0 -23
  186. package/dist/device/streamed-socket.js +0 -255
  187. package/dist/device/streamed-socket.test.d.ts +0 -1
  188. package/dist/device/streamed-socket.test.js +0 -216
  189. package/dist/device/tx-encoding.test.d.ts +0 -1
  190. package/dist/device/tx-encoding.test.js +0 -295
  191. package/dist/device-pairing/cpace.test.d.ts +0 -1
  192. package/dist/device-pairing/cpace.test.js +0 -116
  193. package/dist/device-pairing/device-pairing.test.d.ts +0 -1
  194. package/dist/device-pairing/device-pairing.test.js +0 -211
  195. package/dist/hlc.test.d.ts +0 -1
  196. package/dist/hlc.test.js +0 -45
  197. package/dist/host-credentials.test.d.ts +0 -1
  198. package/dist/host-credentials.test.js +0 -88
  199. package/dist/identity/account-email.test.d.ts +0 -1
  200. package/dist/identity/account-email.test.js +0 -59
  201. package/dist/identity/anchor-document.test.d.ts +0 -1
  202. package/dist/identity/anchor-document.test.js +0 -16
  203. package/dist/identity/anchor-resolution.test.d.ts +0 -1
  204. package/dist/identity/anchor-resolution.test.js +0 -130
  205. package/dist/identity/key-change.test.d.ts +0 -1
  206. package/dist/identity/key-change.test.js +0 -811
  207. package/dist/invites/group-approval.test.d.ts +0 -1
  208. package/dist/invites/group-approval.test.js +0 -223
  209. package/dist/invites/invite-token.test.d.ts +0 -1
  210. package/dist/invites/invite-token.test.js +0 -123
  211. package/dist/keys.test.d.ts +0 -1
  212. package/dist/keys.test.js +0 -336
  213. package/dist/logging/console-logger.test.d.ts +0 -1
  214. package/dist/logging/console-logger.test.js +0 -300
  215. package/dist/logging/console-logs.table.test.d.ts +0 -1
  216. package/dist/logging/console-logs.table.test.js +0 -156
  217. package/dist/observable.test.d.ts +0 -1
  218. package/dist/observable.test.js +0 -309
  219. package/dist/package-build/build-package.test.d.ts +0 -1
  220. package/dist/package-build/build-package.test.js +0 -204
  221. package/dist/package-build/contract-add.test.d.ts +0 -1
  222. package/dist/package-build/contract-add.test.js +0 -467
  223. package/dist/package-build/freeze-contracts.test.d.ts +0 -1
  224. package/dist/package-build/freeze-contracts.test.js +0 -355
  225. package/dist/package-installer/package-author-signing.test.d.ts +0 -1
  226. package/dist/package-installer/package-author-signing.test.js +0 -200
  227. package/dist/package-installer/package-cloner.test.d.ts +0 -1
  228. package/dist/package-installer/package-cloner.test.js +0 -278
  229. package/dist/package-installer/package-creator.test.d.ts +0 -1
  230. package/dist/package-installer/package-creator.test.js +0 -908
  231. package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
  232. package/dist/package-installer/package-dev-tools.test.js +0 -64
  233. package/dist/package-installer/package-installer.test.d.ts +0 -1
  234. package/dist/package-installer/package-installer.test.js +0 -882
  235. package/dist/package-installer/package-propagation.test.d.ts +0 -1
  236. package/dist/package-installer/package-propagation.test.js +0 -1269
  237. package/dist/package-installer/package-publisher.test.d.ts +0 -1
  238. package/dist/package-installer/package-publisher.test.js +0 -153
  239. package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
  240. package/dist/package-installer/package-remote-checker.test.js +0 -334
  241. package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
  242. package/dist/package-installer/package-seed-installer.test.js +0 -123
  243. package/dist/package-installer/package-tarball.test.d.ts +0 -1
  244. package/dist/package-installer/package-tarball.test.js +0 -75
  245. package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
  246. package/dist/package-installer/peers-core-installer.test.js +0 -49
  247. package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
  248. package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
  249. package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
  250. package/dist/package-loader/contract-package-loader.test.js +0 -274
  251. package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
  252. package/dist/package-loader/host-authority-loading.test.js +0 -104
  253. package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
  254. package/dist/package-loader/host-dispatch-policy.test.js +0 -56
  255. package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
  256. package/dist/package-loader/isolated-artifact.test.js +0 -688
  257. package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
  258. package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
  259. package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
  260. package/dist/package-loader/isolated-table-gateway.test.js +0 -633
  261. package/dist/package-loader/package-loader.test.d.ts +0 -1
  262. package/dist/package-loader/package-loader.test.js +0 -1764
  263. package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
  264. package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
  265. package/dist/serial-json.compat.test.d.ts +0 -1
  266. package/dist/serial-json.compat.test.js +0 -369
  267. package/dist/serial-json.test.d.ts +0 -1
  268. package/dist/serial-json.test.js +0 -401
  269. package/dist/testing/mock-host-contract.test.d.ts +0 -1
  270. package/dist/testing/mock-host-contract.test.js +0 -782
  271. package/dist/utils.test.d.ts +0 -1
  272. package/dist/utils.test.js +0 -232
@@ -1,314 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cursor_1 = require("./cursor");
4
- const data_query_1 = require("./data-query");
5
- const factory_1 = require("./factory");
6
- function createMockCursor(items) {
7
- let index = 0;
8
- const cursor = {
9
- value: null,
10
- next: async (_skipPast) => {
11
- if (index >= items.length) {
12
- cursor.value = null;
13
- return null;
14
- }
15
- cursor.value = items[index];
16
- index++;
17
- return cursor.value;
18
- },
19
- };
20
- return (0, data_query_1.iterableCursor)(cursor);
21
- }
22
- describe("Cursor", () => {
23
- describe("basic functionality", () => {
24
- it("should wrap an ICursorIterable and implement the interface", async () => {
25
- const mockCursor = createMockCursor([1, 2, 3]);
26
- const cursor = new cursor_1.Cursor(mockCursor);
27
- const results = [];
28
- for await (const item of cursor) {
29
- results.push(item);
30
- }
31
- expect(results).toEqual([1, 2, 3]);
32
- });
33
- it("should support manual next() calls", async () => {
34
- const mockCursor = createMockCursor(["a", "b", "c"]);
35
- const cursor = new cursor_1.Cursor(mockCursor);
36
- const results = [];
37
- while (await cursor.next()) {
38
- results.push(cursor.value);
39
- }
40
- expect(results).toEqual(["a", "b", "c"]);
41
- });
42
- it("should maintain cursor.value correctly", async () => {
43
- const mockCursor = createMockCursor([10, 20]);
44
- const cursor = new cursor_1.Cursor(mockCursor);
45
- expect(cursor.value).toBeNull();
46
- await cursor.next();
47
- expect(cursor.value).toBe(10);
48
- await cursor.next();
49
- expect(cursor.value).toBe(20);
50
- const result = await cursor.next();
51
- expect(result).toBeNull();
52
- expect(cursor.value).toBeNull();
53
- });
54
- });
55
- describe("static factory methods", () => {
56
- it("should create cursor from ICursorIterable using from()", async () => {
57
- const mockCursor = createMockCursor([1, 2, 3]);
58
- const cursor = cursor_1.Cursor.from(mockCursor);
59
- const results = [];
60
- for await (const item of cursor) {
61
- results.push(item);
62
- }
63
- expect(results).toEqual([1, 2, 3]);
64
- });
65
- it("should create union cursor using static union()", async () => {
66
- const cursor1 = createMockCursor([1, 2]);
67
- const cursor2 = createMockCursor([3, 4]);
68
- const cursor3 = createMockCursor([5, 6]);
69
- const unionCursor = cursor_1.Cursor.union(cursor1, cursor2, cursor3);
70
- const results = [];
71
- for await (const item of unionCursor) {
72
- results.push(item);
73
- }
74
- expect(results).toEqual([1, 2, 3, 4, 5, 6]);
75
- });
76
- it("should handle mix of Cursor and ICursorIterable in static union()", async () => {
77
- const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2]));
78
- const cursor2 = createMockCursor([3, 4]);
79
- const unionCursor = cursor_1.Cursor.union(cursor1, cursor2);
80
- const results = [];
81
- for await (const item of unionCursor) {
82
- results.push(item);
83
- }
84
- expect(results).toEqual([1, 2, 3, 4]);
85
- });
86
- });
87
- describe("instance methods", () => {
88
- it("should create union cursor using instance union()", async () => {
89
- const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2]));
90
- const cursor2 = createMockCursor([3, 4]);
91
- const cursor3 = new cursor_1.Cursor(createMockCursor([5, 6]));
92
- const unionCursor = cursor1.union(cursor2, cursor3);
93
- const results = [];
94
- for await (const item of unionCursor) {
95
- results.push(item);
96
- }
97
- expect(results).toEqual([1, 2, 3, 4, 5, 6]);
98
- });
99
- it("should map cursor values using instance map()", async () => {
100
- const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5]));
101
- const mappedCursor = cursor.map((x) => x * 2);
102
- const results = [];
103
- for await (const item of mappedCursor) {
104
- results.push(item);
105
- }
106
- expect(results).toEqual([2, 4, 6, 8, 10]);
107
- });
108
- it("should support async mapping functions", async () => {
109
- const cursor = new cursor_1.Cursor(createMockCursor(["hello", "world"]));
110
- const mappedCursor = cursor.map(async (x) => {
111
- await new Promise((resolve) => setTimeout(resolve, 1));
112
- return x.toUpperCase();
113
- });
114
- const results = [];
115
- for await (const item of mappedCursor) {
116
- results.push(item);
117
- }
118
- expect(results).toEqual(["HELLO", "WORLD"]);
119
- });
120
- it("should support method chaining", async () => {
121
- const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2]));
122
- const cursor2 = createMockCursor([3, 4]);
123
- const result = cursor1
124
- .union(cursor2)
125
- .map((x) => x * 10)
126
- .map((x) => `num: ${x}`);
127
- const results = [];
128
- for await (const item of result) {
129
- results.push(item);
130
- }
131
- expect(results).toEqual(["num: 10", "num: 20", "num: 30", "num: 40"]);
132
- });
133
- it("should handle empty cursors in operations", async () => {
134
- const cursor1 = new cursor_1.Cursor(createMockCursor([]));
135
- const cursor2 = createMockCursor([1, 2]);
136
- const unionCursor = cursor1.union(cursor2);
137
- const mappedCursor = unionCursor.map((x) => x * 2);
138
- const results = [];
139
- for await (const item of mappedCursor) {
140
- results.push(item);
141
- }
142
- expect(results).toEqual([2, 4]);
143
- });
144
- });
145
- describe("error handling", () => {
146
- it("should propagate skipPast errors from map()", async () => {
147
- const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3]));
148
- const mappedCursor = cursor.map((x) => x * 2);
149
- 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");
150
- });
151
- it("should propagate async errors from mapping functions", async () => {
152
- const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3]));
153
- const mappedCursor = cursor.map(async (x) => {
154
- if (x === 2) {
155
- throw new Error("Test error");
156
- }
157
- return x * 2;
158
- });
159
- const results = [];
160
- let errorCaught = false;
161
- try {
162
- for await (const item of mappedCursor) {
163
- results.push(item);
164
- }
165
- }
166
- catch (error) {
167
- errorCaught = true;
168
- expect(error.message).toBe("Test error");
169
- }
170
- expect(errorCaught).toBe(true);
171
- expect(results).toEqual([2]); // Only first item before error
172
- });
173
- });
174
- describe("static factory methods for data sources", () => {
175
- it("should create cursor from single dataSource using fromDataSource", async () => {
176
- const dataSource = (0, factory_1.arrayAsTable)([
177
- { id: 1, name: "Alice" },
178
- { id: 2, name: "Bob" },
179
- { id: 3, name: "Charlie" },
180
- ], { name: "users" });
181
- const cursor = cursor_1.Cursor.fromDataSource(dataSource, {}, { sortBy: ["name"] });
182
- const results = [];
183
- for await (const item of cursor) {
184
- results.push(item);
185
- }
186
- expect(results.map((r) => r.name)).toEqual(["Alice", "Bob", "Charlie"]);
187
- });
188
- it("should create cursor from multiple dataSources using fromDataSources", async () => {
189
- const dataSource1 = (0, factory_1.arrayAsTable)([
190
- { id: 1, name: "Alice" },
191
- { id: 3, name: "Charlie" },
192
- ], { name: "users1" });
193
- const dataSource2 = (0, factory_1.arrayAsTable)([
194
- { id: 2, name: "Bob" },
195
- { id: 4, name: "David" },
196
- ], { name: "users2" });
197
- const cursor = cursor_1.Cursor.fromDataSources([dataSource1, dataSource2]);
198
- const results = [];
199
- for await (const item of cursor) {
200
- results.push(item);
201
- }
202
- expect(results.map((r) => r.id)).toEqual([1, 2, 3, 4]);
203
- });
204
- it("should support filters and options with fromDataSource", async () => {
205
- const dataSource = (0, factory_1.arrayAsTable)([
206
- { id: 1, name: "Alice", age: 25 },
207
- { id: 2, name: "Bob", age: 30 },
208
- { id: 3, name: "Charlie", age: 35 },
209
- ], { name: "users" });
210
- const cursor = cursor_1.Cursor.fromDataSource(dataSource, { age: { $gte: 30 } }, { sortBy: ["name"] });
211
- const results = [];
212
- for await (const item of cursor) {
213
- results.push(item);
214
- }
215
- // Should only get Bob and Charlie (age >= 30), sorted by name
216
- expect(results.map((r) => r.name)).toEqual(["Bob", "Charlie"]);
217
- });
218
- it("should support filters and options with fromDataSources", async () => {
219
- const dataSource1 = (0, factory_1.arrayAsTable)([
220
- { id: 1, name: "Alice", age: 25 },
221
- { id: 2, name: "Bob", age: 30 },
222
- ], { name: "users1" });
223
- const dataSource2 = (0, factory_1.arrayAsTable)([
224
- { id: 3, name: "Charlie", age: 35 },
225
- { id: 4, name: "David", age: 20 },
226
- ], { name: "users2" });
227
- const cursor = cursor_1.Cursor.fromDataSources([dataSource1, dataSource2], { age: { $gte: 25 } }, { sortBy: ["name"] });
228
- const results = [];
229
- for await (const item of cursor) {
230
- results.push(item);
231
- }
232
- // Should get Alice, Bob, Charlie (age >= 25), sorted by name
233
- expect(results.map((r) => r.name)).toEqual(["Alice", "Bob", "Charlie"]);
234
- });
235
- it("should work with method chaining after fromDataSource", async () => {
236
- const dataSource = (0, factory_1.arrayAsTable)([
237
- { id: 1, name: "Alice" },
238
- { id: 2, name: "Bob" },
239
- ], { name: "users" });
240
- const cursor = cursor_1.Cursor.fromDataSource(dataSource).map((item) => item.name.toUpperCase());
241
- const results = [];
242
- for await (const item of cursor) {
243
- results.push(item);
244
- }
245
- expect(results).toEqual(["ALICE", "BOB"]);
246
- });
247
- it("should filter cursor values using instance filter()", async () => {
248
- const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
249
- const filteredCursor = cursor.filter((x) => x % 3 === 0);
250
- const results = [];
251
- for await (const item of filteredCursor) {
252
- results.push(item);
253
- }
254
- expect(results).toEqual([3, 6, 9]);
255
- });
256
- it("should support async filter functions", async () => {
257
- const cursor = new cursor_1.Cursor(createMockCursor(["apple", "banana", "cherry", "date", "elderberry"]));
258
- const filteredCursor = cursor.filter(async (x) => {
259
- await new Promise((resolve) => setTimeout(resolve, 1));
260
- return x.startsWith("a") || x.startsWith("e");
261
- });
262
- const results = [];
263
- for await (const item of filteredCursor) {
264
- results.push(item);
265
- }
266
- expect(results).toEqual(["apple", "elderberry"]);
267
- });
268
- it("should support method chaining with filter", async () => {
269
- const cursor = new cursor_1.Cursor(createMockCursor([
270
- { id: 1, name: "Alice", age: 25 },
271
- { id: 2, name: "Bob", age: 30 },
272
- { id: 3, name: "Charlie", age: 35 },
273
- { id: 4, name: "David", age: 20 },
274
- ]));
275
- const result = cursor
276
- .filter((person) => person.age >= 25)
277
- .map((person) => person.name.toUpperCase())
278
- .filter((name) => name.includes("A"));
279
- const results = [];
280
- for await (const item of result) {
281
- results.push(item);
282
- }
283
- expect(results).toEqual(["ALICE", "CHARLIE"]);
284
- });
285
- it("should handle empty results after filtering", async () => {
286
- const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5]));
287
- const filteredCursor = cursor.filter((x) => x > 10);
288
- const results = [];
289
- for await (const item of filteredCursor) {
290
- results.push(item);
291
- }
292
- expect(results).toEqual([]);
293
- });
294
- it("should propagate skipPast errors from filter()", async () => {
295
- const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5]));
296
- const filteredCursor = cursor.filter((x) => x > 2);
297
- await expect(filteredCursor.next(3)).rejects.toThrow("skipPast is not supported for cursorFilter since filtering changes the cursor iteration order");
298
- });
299
- it("should support complex method chaining with union, filter, and map", async () => {
300
- const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2, 3]));
301
- const cursor2 = createMockCursor([4, 5, 6]);
302
- const cursor3 = createMockCursor([7, 8, 9]);
303
- const result = cursor1
304
- .union(cursor2, cursor3)
305
- .filter((x) => x % 2 === 1) // odd numbers
306
- .map((x) => x * 10);
307
- const results = [];
308
- for await (const item of result) {
309
- results.push(item);
310
- }
311
- expect(results).toEqual([10, 30, 50, 70, 90]);
312
- });
313
- });
314
- });
@@ -1 +0,0 @@
1
- export {};