@peers-app/peers-sdk 0.14.0 → 0.15.0

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 (210) hide show
  1. package/dist/context/data-context.d.ts +4 -4
  2. package/dist/context/data-context.js +1 -1
  3. package/dist/context/index.d.ts +3 -3
  4. package/dist/context/index.js +4 -0
  5. package/dist/context/user-context-singleton.js +13 -14
  6. package/dist/context/user-context.d.ts +4 -4
  7. package/dist/context/user-context.js +48 -31
  8. package/dist/data/assistants.d.ts +1 -1
  9. package/dist/data/assistants.js +35 -24
  10. package/dist/data/change-tracking.d.ts +8 -8
  11. package/dist/data/change-tracking.js +45 -39
  12. package/dist/data/channels.js +5 -5
  13. package/dist/data/data-locks.d.ts +2 -2
  14. package/dist/data/data-locks.js +21 -23
  15. package/dist/data/data-locks.test.js +73 -75
  16. package/dist/data/device-sync-info.d.ts +1 -1
  17. package/dist/data/device-sync-info.js +4 -4
  18. package/dist/data/devices.d.ts +1 -1
  19. package/dist/data/devices.js +9 -12
  20. package/dist/data/embeddings.js +14 -11
  21. package/dist/data/files/file-read-stream.d.ts +2 -2
  22. package/dist/data/files/file-read-stream.js +23 -14
  23. package/dist/data/files/file-write-stream.d.ts +2 -2
  24. package/dist/data/files/file-write-stream.js +8 -8
  25. package/dist/data/files/file.types.d.ts +2 -2
  26. package/dist/data/files/file.types.js +17 -11
  27. package/dist/data/files/files.d.ts +6 -6
  28. package/dist/data/files/files.js +17 -19
  29. package/dist/data/files/files.test.js +213 -214
  30. package/dist/data/files/index.d.ts +4 -4
  31. package/dist/data/files/index.js +4 -4
  32. package/dist/data/group-member-roles.js +2 -2
  33. package/dist/data/group-members.d.ts +5 -5
  34. package/dist/data/group-members.js +27 -18
  35. package/dist/data/group-members.test.js +73 -73
  36. package/dist/data/group-permissions.d.ts +3 -3
  37. package/dist/data/group-permissions.js +13 -11
  38. package/dist/data/group-share.d.ts +2 -2
  39. package/dist/data/group-share.js +29 -24
  40. package/dist/data/groups.d.ts +4 -4
  41. package/dist/data/groups.js +27 -19
  42. package/dist/data/groups.test.js +44 -44
  43. package/dist/data/index.d.ts +6 -6
  44. package/dist/data/index.js +6 -6
  45. package/dist/data/knowledge/peer-types.js +9 -9
  46. package/dist/data/messages.d.ts +5 -5
  47. package/dist/data/messages.js +43 -30
  48. package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
  49. package/dist/data/orm/client-proxy.data-source.js +10 -12
  50. package/dist/data/orm/cursor.d.ts +1 -1
  51. package/dist/data/orm/cursor.js +2 -2
  52. package/dist/data/orm/cursor.test.js +92 -93
  53. package/dist/data/orm/data-query.d.ts +3 -3
  54. package/dist/data/orm/data-query.js +24 -18
  55. package/dist/data/orm/data-query.mongo.d.ts +1 -1
  56. package/dist/data/orm/data-query.mongo.js +49 -51
  57. package/dist/data/orm/data-query.mongo.test.js +173 -204
  58. package/dist/data/orm/data-query.sqlite.d.ts +1 -1
  59. package/dist/data/orm/data-query.sqlite.js +84 -73
  60. package/dist/data/orm/data-query.sqlite.test.js +164 -176
  61. package/dist/data/orm/data-query.test.js +216 -224
  62. package/dist/data/orm/decorators.js +3 -3
  63. package/dist/data/orm/dependency-injection.test.js +53 -56
  64. package/dist/data/orm/doc.d.ts +4 -4
  65. package/dist/data/orm/doc.js +17 -21
  66. package/dist/data/orm/event-registry.d.ts +1 -1
  67. package/dist/data/orm/event-registry.test.js +16 -16
  68. package/dist/data/orm/factory.d.ts +2 -2
  69. package/dist/data/orm/factory.js +33 -33
  70. package/dist/data/orm/index.d.ts +10 -10
  71. package/dist/data/orm/index.js +10 -10
  72. package/dist/data/orm/multi-cursors.d.ts +1 -1
  73. package/dist/data/orm/multi-cursors.js +6 -6
  74. package/dist/data/orm/multi-cursors.test.js +152 -144
  75. package/dist/data/orm/sql.data-source.d.ts +7 -7
  76. package/dist/data/orm/sql.data-source.js +88 -93
  77. package/dist/data/orm/sql.data-source.test.js +109 -101
  78. package/dist/data/orm/subscribable.data-source.d.ts +4 -4
  79. package/dist/data/orm/subscribable.data-source.js +5 -5
  80. package/dist/data/orm/table-container-events.test.js +34 -26
  81. package/dist/data/orm/table-container.d.ts +6 -6
  82. package/dist/data/orm/table-container.js +33 -21
  83. package/dist/data/orm/table-container.test.js +64 -53
  84. package/dist/data/orm/table-definitions.system.d.ts +3 -3
  85. package/dist/data/orm/table-definitions.system.js +3 -3
  86. package/dist/data/orm/table-definitions.type.d.ts +5 -5
  87. package/dist/data/orm/table-dependencies.d.ts +2 -2
  88. package/dist/data/orm/table.d.ts +5 -5
  89. package/dist/data/orm/table.event-source.test.js +105 -115
  90. package/dist/data/orm/table.js +35 -34
  91. package/dist/data/orm/types.d.ts +3 -3
  92. package/dist/data/orm/types.js +26 -25
  93. package/dist/data/orm/types.test.js +166 -92
  94. package/dist/data/package-permissions.d.ts +1 -1
  95. package/dist/data/package-permissions.js +2 -2
  96. package/dist/data/package-version-permissions.d.ts +1 -1
  97. package/dist/data/package-version-permissions.js +2 -2
  98. package/dist/data/package-versions.d.ts +9 -9
  99. package/dist/data/package-versions.js +47 -33
  100. package/dist/data/packages.d.ts +2 -2
  101. package/dist/data/packages.js +36 -18
  102. package/dist/data/packages.utils.d.ts +2 -2
  103. package/dist/data/packages.utils.js +4 -4
  104. package/dist/data/persistent-vars.d.ts +15 -15
  105. package/dist/data/persistent-vars.js +165 -154
  106. package/dist/data/table-definitions-table.d.ts +5 -5
  107. package/dist/data/table-definitions-table.js +13 -12
  108. package/dist/data/tool-tests.js +6 -6
  109. package/dist/data/tools.js +29 -19
  110. package/dist/data/user-permissions.d.ts +1 -1
  111. package/dist/data/user-permissions.js +5 -5
  112. package/dist/data/user-permissions.test.js +90 -88
  113. package/dist/data/user-trust-levels.js +10 -10
  114. package/dist/data/users.d.ts +4 -4
  115. package/dist/data/users.js +16 -15
  116. package/dist/data/voice-messages.d.ts +2 -2
  117. package/dist/data/voice-messages.js +13 -13
  118. package/dist/data/welcome-modal.pvar.js +3 -1
  119. package/dist/data/workflow-logs.js +26 -18
  120. package/dist/data/workflow-runs.d.ts +6 -6
  121. package/dist/data/workflow-runs.js +70 -44
  122. package/dist/data/workflows.d.ts +2 -2
  123. package/dist/data/workflows.js +7 -9
  124. package/dist/device/binary-peer-connection-v2.d.ts +7 -7
  125. package/dist/device/binary-peer-connection-v2.js +32 -28
  126. package/dist/device/binary-peer-connection-v2.test.js +80 -67
  127. package/dist/device/binary-peer-connection.d.ts +7 -7
  128. package/dist/device/binary-peer-connection.js +29 -28
  129. package/dist/device/binary-peer-connection.test.js +35 -31
  130. package/dist/device/connection.d.ts +5 -5
  131. package/dist/device/connection.js +59 -48
  132. package/dist/device/connection.test.js +74 -68
  133. package/dist/device/device-election.d.ts +2 -2
  134. package/dist/device/device-election.js +25 -20
  135. package/dist/device/device-election.test.js +35 -36
  136. package/dist/device/device.d.ts +2 -2
  137. package/dist/device/device.js +10 -4
  138. package/dist/device/device.test.js +16 -17
  139. package/dist/device/get-trust-level-fn.d.ts +2 -2
  140. package/dist/device/get-trust-level-fn.js +22 -11
  141. package/dist/device/get-trust-level-fn.test.js +58 -58
  142. package/dist/device/socket-io-binary-peer.d.ts +1 -1
  143. package/dist/device/socket-io-binary-peer.js +16 -13
  144. package/dist/device/socket.type.d.ts +2 -2
  145. package/dist/device/streamed-socket.d.ts +2 -2
  146. package/dist/device/streamed-socket.js +8 -8
  147. package/dist/device/streamed-socket.test.js +40 -40
  148. package/dist/device/tx-encoding.test.js +77 -77
  149. package/dist/events.d.ts +1 -1
  150. package/dist/events.js +5 -2
  151. package/dist/group-invite/group-invite.js +110 -19
  152. package/dist/group-invite/group-invite.pvars.d.ts +2 -2
  153. package/dist/group-invite/group-invite.pvars.js +21 -13
  154. package/dist/group-invite/group-invite.types.d.ts +1 -1
  155. package/dist/group-invite/index.d.ts +3 -3
  156. package/dist/group-invite/index.js +1 -1
  157. package/dist/index.d.ts +25 -24
  158. package/dist/index.js +30 -25
  159. package/dist/keys.d.ts +3 -3
  160. package/dist/keys.js +31 -30
  161. package/dist/keys.test.js +69 -61
  162. package/dist/logging/console-logger.d.ts +1 -1
  163. package/dist/logging/console-logger.js +35 -40
  164. package/dist/logging/console-logger.test.js +115 -115
  165. package/dist/logging/console-logs.table.d.ts +3 -3
  166. package/dist/logging/console-logs.table.js +28 -23
  167. package/dist/mentions.js +16 -12
  168. package/dist/observable.d.ts +2 -2
  169. package/dist/observable.js +15 -9
  170. package/dist/observable.test.js +47 -47
  171. package/dist/package-loader/get-require.js +3 -4
  172. package/dist/package-loader/package-loader.d.ts +2 -2
  173. package/dist/package-loader/package-loader.js +52 -34
  174. package/dist/peers-ui/peers-ui.d.ts +2 -2
  175. package/dist/peers-ui/peers-ui.js +2 -4
  176. package/dist/peers-ui/peers-ui.types.d.ts +3 -3
  177. package/dist/peers-ui/peers-ui.types.js +0 -1
  178. package/dist/rpc-types.d.ts +61 -59
  179. package/dist/rpc-types.js +61 -55
  180. package/dist/serial-json.d.ts +1 -1
  181. package/dist/serial-json.js +50 -43
  182. package/dist/serial-json.test.js +22 -22
  183. package/dist/system-ids.js +8 -8
  184. package/dist/tools/index.d.ts +1 -1
  185. package/dist/tools/tools-factory.d.ts +1 -1
  186. package/dist/tools/tools-factory.js +2 -2
  187. package/dist/types/assistant-runner-args.d.ts +3 -3
  188. package/dist/types/peer-device.d.ts +1 -1
  189. package/dist/types/peers-package.d.ts +3 -3
  190. package/dist/types/workflow-logger.d.ts +1 -1
  191. package/dist/types/workflow-run-context.d.ts +4 -4
  192. package/dist/types/workflow.d.ts +4 -4
  193. package/dist/types/workflow.js +27 -14
  194. package/dist/types/zod-types.d.ts +2 -1
  195. package/dist/types/zod-types.js +9 -3
  196. package/dist/user-connect/connection-code.d.ts +1 -1
  197. package/dist/user-connect/connection-code.js +7 -7
  198. package/dist/user-connect/connection-code.test.js +106 -106
  199. package/dist/user-connect/index.d.ts +3 -3
  200. package/dist/user-connect/index.js +1 -1
  201. package/dist/user-connect/user-connect.pvars.js +13 -11
  202. package/dist/user-connect/user-connect.types.d.ts +3 -3
  203. package/dist/users.query.d.ts +2 -2
  204. package/dist/users.query.js +40 -30
  205. package/dist/utils.d.ts +2 -2
  206. package/dist/utils.js +34 -32
  207. package/dist/utils.test.js +12 -8
  208. package/dist/workflow-log-formatter.d.ts +1 -1
  209. package/dist/workflow-log-formatter.js +17 -18
  210. package/package.json +14 -8
@@ -4,41 +4,56 @@ exports.messageSchema = void 0;
4
4
  exports.Messages = Messages;
5
5
  exports.sendMessage = sendMessage;
6
6
  exports.getThreadVars = getThreadVars;
7
- const types_1 = require("./orm/types");
8
- const users_1 = require("./users");
9
- const groups_1 = require("./groups");
10
- const channels_1 = require("./channels");
11
- const workflow_runs_1 = require("./workflow-runs");
12
- const utils_1 = require("../utils");
13
7
  const zod_1 = require("zod");
14
- const zod_types_1 = require("../types/zod-types");
15
8
  const user_context_singleton_1 = require("../context/user-context-singleton");
9
+ const zod_types_1 = require("../types/zod-types");
10
+ const utils_1 = require("../utils");
11
+ const channels_1 = require("./channels");
12
+ const groups_1 = require("./groups");
16
13
  const table_definitions_system_1 = require("./orm/table-definitions.system");
14
+ const types_1 = require("./orm/types");
15
+ const users_1 = require("./users");
16
+ const workflow_runs_1 = require("./workflow-runs");
17
17
  exports.messageSchema = zod_1.z.object({
18
18
  messageId: zod_types_1.zodPeerId,
19
- channelId: zod_types_1.zodPeerId.describe('The id of the channel this message entry belongs to'),
20
- userId: zod_types_1.zodPeerId.describe('The id of the user who created this message entry'),
21
- messageParentId: zod_types_1.zodPeerId.optional().describe('The id of the parent message entry if this is part of a thread'),
22
- assistantId: zod_types_1.zodPeerId.optional().describe(`The id of the user's assistant that created this message entry operating on behalf of the user`),
23
- message: zod_1.z.string().describe('The markdown content of this message entry'),
19
+ channelId: zod_types_1.zodPeerId.describe("The id of the channel this message entry belongs to"),
20
+ userId: zod_types_1.zodPeerId.describe("The id of the user who created this message entry"),
21
+ messageParentId: zod_types_1.zodPeerId
22
+ .optional()
23
+ .describe("The id of the parent message entry if this is part of a thread"),
24
+ assistantId: zod_types_1.zodPeerId
25
+ .optional()
26
+ .describe(`The id of the user's assistant that created this message entry operating on behalf of the user`),
27
+ message: zod_1.z.string().describe("The markdown content of this message entry"),
24
28
  createdAt: zod_1.z.date(),
25
- editedAt: zod_1.z.date().optional().describe('The time this message entry was last edited, if it was edited'),
26
- fileIds: zod_types_1.zodPeerId.array().optional().describe('The ids of files attached to this message entry'),
27
- vars: zod_types_1.zodAnyObject.optional().describe('The variables that are associated with this message entry'),
29
+ editedAt: zod_1.z
30
+ .date()
31
+ .optional()
32
+ .describe("The time this message entry was last edited, if it was edited"),
33
+ fileIds: zod_types_1.zodPeerId.array().optional().describe("The ids of files attached to this message entry"),
34
+ vars: zod_types_1.zodAnyObject
35
+ .optional()
36
+ .describe("The variables that are associated with this message entry"),
28
37
  });
29
38
  const metaData = {
30
- name: 'Messages',
31
- description: 'Messages (chat entries) in a channel',
32
- primaryKeyName: 'messageId',
39
+ name: "Messages",
40
+ description: "Messages (chat entries) in a channel",
41
+ primaryKeyName: "messageId",
33
42
  fields: (0, types_1.schemaToFields)(exports.messageSchema),
34
43
  indexes: [
35
- { fields: ['channelId'] },
36
- { fields: ['messageParentId'] },
37
- { fields: ['userId'] },
38
- { fields: ['assistantId'] },
39
- { fields: ['channelId', { name: 'createdAt', order: 'DESC' }, { name: 'messageId', order: 'DESC' }] },
40
- { fields: ['messageParentId', 'createdAt', 'messageId'] },
41
- ]
44
+ { fields: ["channelId"] },
45
+ { fields: ["messageParentId"] },
46
+ { fields: ["userId"] },
47
+ { fields: ["assistantId"] },
48
+ {
49
+ fields: [
50
+ "channelId",
51
+ { name: "createdAt", order: "DESC" },
52
+ { name: "messageId", order: "DESC" },
53
+ ],
54
+ },
55
+ { fields: ["messageParentId", "createdAt", "messageId"] },
56
+ ],
42
57
  };
43
58
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.messageSchema);
44
59
  function Messages(dataContext) {
@@ -84,15 +99,13 @@ async function sendMessage(args) {
84
99
  return message;
85
100
  }
86
101
  async function getThreadVars(message) {
87
- const $or = [
88
- { messageId: message.messageId },
89
- ];
102
+ const $or = [{ messageId: message.messageId }];
90
103
  if (message.messageParentId) {
91
104
  $or.push({ messageId: message.messageParentId });
92
105
  }
93
106
  const threadMessages = await Messages().list({
94
- $or
95
- }, { sortBy: ['createdAt'] });
107
+ $or,
108
+ }, { sortBy: ["createdAt"] });
96
109
  // Note that sort order is very important so that newer var values overwrite older ones
97
110
  const vars = threadMessages.reduce((acc, message) => {
98
111
  Object.assign(acc, message.vars ?? {});
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
- import { DataFilter, ICursorIterable, IDataQueryParams, IDataSource, ISaveOptions } from "./data-query";
3
- import { ITableMetaData } from "./types";
1
+ import type { z } from "zod";
2
+ import { type DataFilter, type ICursorIterable, type IDataQueryParams, type IDataSource, type ISaveOptions } from "./data-query";
3
+ import { type ITableMetaData } from "./types";
4
4
  export declare class ClientProxyDataSource<T extends {
5
5
  [key: string]: any;
6
6
  }> implements IDataSource<T> {
@@ -9,7 +9,7 @@ export declare class ClientProxyDataSource<T extends {
9
9
  readonly dataContextId: string;
10
10
  readonly tableName: string;
11
11
  readonly primaryKeyName: string;
12
- constructor(metaData: ITableMetaData, schema: z.AnyZodObject, dataContextId: string);
12
+ constructor(metaData: ITableMetaData, schema: z.AnyZodObject | undefined, dataContextId: string);
13
13
  get(id: string, opts?: {
14
14
  useCache?: boolean;
15
15
  cacheTtlMs?: number;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClientProxyDataSource = void 0;
4
4
  const rpc_types_1 = require("../../rpc-types");
5
+ const utils_1 = require("../../utils");
5
6
  const data_query_1 = require("./data-query");
6
7
  const types_1 = require("./types");
7
- const utils_1 = require("../../utils");
8
8
  class ClientProxyDataSource {
9
9
  metaData;
10
10
  schema;
@@ -17,39 +17,37 @@ class ClientProxyDataSource {
17
17
  this.dataContextId = dataContextId;
18
18
  this.tableName = (0, utils_1.getFullTableName)(metaData);
19
19
  this.primaryKeyName = metaData.primaryKeyName;
20
- const primaryKeyIsValid = metaData.fields.find(f => f.name === metaData.primaryKeyName);
20
+ const primaryKeyIsValid = metaData.fields.find((f) => f.name === metaData.primaryKeyName);
21
21
  if (!primaryKeyIsValid) {
22
22
  throw new Error(`Table "${this.tableName}", primary key "${metaData.primaryKeyName}" is not a valid field name`);
23
23
  }
24
24
  }
25
25
  async get(id, opts = {}) {
26
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'get', id, opts);
26
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "get", id, opts);
27
27
  }
28
28
  async list(filter = {}, opts = {}) {
29
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'list', filter, opts);
29
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "list", filter, opts);
30
30
  }
31
- ;
32
31
  async count(filter = {}) {
33
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'count', filter);
32
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "count", filter);
34
33
  }
35
- ;
36
34
  cursor(filter = {}, opts = {}) {
37
35
  return (0, data_query_1.dataSourceCursor)(this, filter, opts);
38
36
  }
39
37
  async findOne(filter = {}, opts) {
40
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'findOne', filter, opts);
38
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "findOne", filter, opts);
41
39
  }
42
40
  async save(record, opts) {
43
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'save', record, opts);
41
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "save", record, opts);
44
42
  }
45
43
  async insert(record) {
46
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'insert', record);
44
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "insert", record);
47
45
  }
48
46
  async update(record) {
49
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'update', record);
47
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "update", record);
50
48
  }
51
49
  async delete(idOrRecord) {
52
- return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, 'delete', idOrRecord);
50
+ return rpc_types_1.rpcServerCalls.tableMethodCall(this.dataContextId, this.tableName, "delete", idOrRecord);
53
51
  }
54
52
  }
55
53
  exports.ClientProxyDataSource = ClientProxyDataSource;
@@ -1,4 +1,4 @@
1
- import { ICursorIterable, DataFilter, IDataQueryParams } from './data-query';
1
+ import { type DataFilter, type ICursorIterable, type IDataQueryParams } from "./data-query";
2
2
  export declare class Cursor<T> implements ICursorIterable<T> {
3
3
  private _cursor;
4
4
  constructor(_cursor: ICursorIterable<T>);
@@ -28,13 +28,13 @@ class Cursor {
28
28
  return new Cursor((0, multi_cursors_1.queryMerge)(dataSources, filter, opts));
29
29
  }
30
30
  static union(...cursors) {
31
- const unwrappedCursors = cursors.map(c => c instanceof Cursor ? c._cursor : c);
31
+ const unwrappedCursors = cursors.map((c) => (c instanceof Cursor ? c._cursor : c));
32
32
  return new Cursor((0, multi_cursors_1.cursorUnion)(unwrappedCursors));
33
33
  }
34
34
  // Instance methods
35
35
  union(...others) {
36
36
  const allCursors = [this, ...others];
37
- const unwrappedCursors = allCursors.map(c => c instanceof Cursor ? c._cursor : c);
37
+ const unwrappedCursors = allCursors.map((c) => (c instanceof Cursor ? c._cursor : c));
38
38
  return new Cursor((0, multi_cursors_1.cursorUnion)(unwrappedCursors));
39
39
  }
40
40
  map(mapFn) {
@@ -19,9 +19,9 @@ function createMockCursor(items) {
19
19
  };
20
20
  return (0, data_query_1.iterableCursor)(cursor);
21
21
  }
22
- describe('Cursor', () => {
23
- describe('basic functionality', () => {
24
- it('should wrap an ICursorIterable and implement the interface', async () => {
22
+ describe("Cursor", () => {
23
+ describe("basic functionality", () => {
24
+ it("should wrap an ICursorIterable and implement the interface", async () => {
25
25
  const mockCursor = createMockCursor([1, 2, 3]);
26
26
  const cursor = new cursor_1.Cursor(mockCursor);
27
27
  const results = [];
@@ -30,16 +30,16 @@ describe('Cursor', () => {
30
30
  }
31
31
  expect(results).toEqual([1, 2, 3]);
32
32
  });
33
- it('should support manual next() calls', async () => {
34
- const mockCursor = createMockCursor(['a', 'b', 'c']);
33
+ it("should support manual next() calls", async () => {
34
+ const mockCursor = createMockCursor(["a", "b", "c"]);
35
35
  const cursor = new cursor_1.Cursor(mockCursor);
36
36
  const results = [];
37
37
  while (await cursor.next()) {
38
38
  results.push(cursor.value);
39
39
  }
40
- expect(results).toEqual(['a', 'b', 'c']);
40
+ expect(results).toEqual(["a", "b", "c"]);
41
41
  });
42
- it('should maintain cursor.value correctly', async () => {
42
+ it("should maintain cursor.value correctly", async () => {
43
43
  const mockCursor = createMockCursor([10, 20]);
44
44
  const cursor = new cursor_1.Cursor(mockCursor);
45
45
  expect(cursor.value).toBeNull();
@@ -52,8 +52,8 @@ describe('Cursor', () => {
52
52
  expect(cursor.value).toBeNull();
53
53
  });
54
54
  });
55
- describe('static factory methods', () => {
56
- it('should create cursor from ICursorIterable using from()', async () => {
55
+ describe("static factory methods", () => {
56
+ it("should create cursor from ICursorIterable using from()", async () => {
57
57
  const mockCursor = createMockCursor([1, 2, 3]);
58
58
  const cursor = cursor_1.Cursor.from(mockCursor);
59
59
  const results = [];
@@ -62,7 +62,7 @@ describe('Cursor', () => {
62
62
  }
63
63
  expect(results).toEqual([1, 2, 3]);
64
64
  });
65
- it('should create union cursor using static union()', async () => {
65
+ it("should create union cursor using static union()", async () => {
66
66
  const cursor1 = createMockCursor([1, 2]);
67
67
  const cursor2 = createMockCursor([3, 4]);
68
68
  const cursor3 = createMockCursor([5, 6]);
@@ -73,7 +73,7 @@ describe('Cursor', () => {
73
73
  }
74
74
  expect(results).toEqual([1, 2, 3, 4, 5, 6]);
75
75
  });
76
- it('should handle mix of Cursor and ICursorIterable in static union()', async () => {
76
+ it("should handle mix of Cursor and ICursorIterable in static union()", async () => {
77
77
  const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2]));
78
78
  const cursor2 = createMockCursor([3, 4]);
79
79
  const unionCursor = cursor_1.Cursor.union(cursor1, cursor2);
@@ -84,8 +84,8 @@ describe('Cursor', () => {
84
84
  expect(results).toEqual([1, 2, 3, 4]);
85
85
  });
86
86
  });
87
- describe('instance methods', () => {
88
- it('should create union cursor using instance union()', async () => {
87
+ describe("instance methods", () => {
88
+ it("should create union cursor using instance union()", async () => {
89
89
  const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2]));
90
90
  const cursor2 = createMockCursor([3, 4]);
91
91
  const cursor3 = new cursor_1.Cursor(createMockCursor([5, 6]));
@@ -96,7 +96,7 @@ describe('Cursor', () => {
96
96
  }
97
97
  expect(results).toEqual([1, 2, 3, 4, 5, 6]);
98
98
  });
99
- it('should map cursor values using instance map()', async () => {
99
+ it("should map cursor values using instance map()", async () => {
100
100
  const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5]));
101
101
  const mappedCursor = cursor.map((x) => x * 2);
102
102
  const results = [];
@@ -105,36 +105,36 @@ describe('Cursor', () => {
105
105
  }
106
106
  expect(results).toEqual([2, 4, 6, 8, 10]);
107
107
  });
108
- it('should support async mapping functions', async () => {
109
- const cursor = new cursor_1.Cursor(createMockCursor(['hello', 'world']));
108
+ it("should support async mapping functions", async () => {
109
+ const cursor = new cursor_1.Cursor(createMockCursor(["hello", "world"]));
110
110
  const mappedCursor = cursor.map(async (x) => {
111
- await new Promise(resolve => setTimeout(resolve, 1));
111
+ await new Promise((resolve) => setTimeout(resolve, 1));
112
112
  return x.toUpperCase();
113
113
  });
114
114
  const results = [];
115
115
  for await (const item of mappedCursor) {
116
116
  results.push(item);
117
117
  }
118
- expect(results).toEqual(['HELLO', 'WORLD']);
118
+ expect(results).toEqual(["HELLO", "WORLD"]);
119
119
  });
120
- it('should support method chaining', async () => {
120
+ it("should support method chaining", async () => {
121
121
  const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2]));
122
122
  const cursor2 = createMockCursor([3, 4]);
123
123
  const result = cursor1
124
124
  .union(cursor2)
125
- .map(x => x * 10)
126
- .map(x => `num: ${x}`);
125
+ .map((x) => x * 10)
126
+ .map((x) => `num: ${x}`);
127
127
  const results = [];
128
128
  for await (const item of result) {
129
129
  results.push(item);
130
130
  }
131
- expect(results).toEqual(['num: 10', 'num: 20', 'num: 30', 'num: 40']);
131
+ expect(results).toEqual(["num: 10", "num: 20", "num: 30", "num: 40"]);
132
132
  });
133
- it('should handle empty cursors in operations', async () => {
133
+ it("should handle empty cursors in operations", async () => {
134
134
  const cursor1 = new cursor_1.Cursor(createMockCursor([]));
135
135
  const cursor2 = createMockCursor([1, 2]);
136
136
  const unionCursor = cursor1.union(cursor2);
137
- const mappedCursor = unionCursor.map(x => x * 2);
137
+ const mappedCursor = unionCursor.map((x) => x * 2);
138
138
  const results = [];
139
139
  for await (const item of mappedCursor) {
140
140
  results.push(item);
@@ -142,17 +142,17 @@ describe('Cursor', () => {
142
142
  expect(results).toEqual([2, 4]);
143
143
  });
144
144
  });
145
- describe('error handling', () => {
146
- it('should propagate skipPast errors from map()', async () => {
145
+ describe("error handling", () => {
146
+ it("should propagate skipPast errors from map()", async () => {
147
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');
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
150
  });
151
- it('should propagate async errors from mapping functions', async () => {
151
+ it("should propagate async errors from mapping functions", async () => {
152
152
  const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3]));
153
153
  const mappedCursor = cursor.map(async (x) => {
154
154
  if (x === 2) {
155
- throw new Error('Test error');
155
+ throw new Error("Test error");
156
156
  }
157
157
  return x * 2;
158
158
  });
@@ -165,87 +165,86 @@ describe('Cursor', () => {
165
165
  }
166
166
  catch (error) {
167
167
  errorCaught = true;
168
- expect(error.message).toBe('Test error');
168
+ expect(error.message).toBe("Test error");
169
169
  }
170
170
  expect(errorCaught).toBe(true);
171
171
  expect(results).toEqual([2]); // Only first item before error
172
172
  });
173
173
  });
174
- describe('static factory methods for data sources', () => {
175
- it('should create cursor from single dataSource using fromDataSource', async () => {
174
+ describe("static factory methods for data sources", () => {
175
+ it("should create cursor from single dataSource using fromDataSource", async () => {
176
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'] });
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
182
  const results = [];
183
183
  for await (const item of cursor) {
184
184
  results.push(item);
185
185
  }
186
- expect(results.map(r => r.name)).toEqual(['Alice', 'Bob', 'Charlie']);
186
+ expect(results.map((r) => r.name)).toEqual(["Alice", "Bob", "Charlie"]);
187
187
  });
188
- it('should create cursor from multiple dataSources using fromDataSources', async () => {
188
+ it("should create cursor from multiple dataSources using fromDataSources", async () => {
189
189
  const dataSource1 = (0, factory_1.arrayAsTable)([
190
- { id: 1, name: 'Alice' },
191
- { id: 3, name: 'Charlie' },
192
- ], { name: 'users1' });
190
+ { id: 1, name: "Alice" },
191
+ { id: 3, name: "Charlie" },
192
+ ], { name: "users1" });
193
193
  const dataSource2 = (0, factory_1.arrayAsTable)([
194
- { id: 2, name: 'Bob' },
195
- { id: 4, name: 'David' },
196
- ], { name: 'users2' });
194
+ { id: 2, name: "Bob" },
195
+ { id: 4, name: "David" },
196
+ ], { name: "users2" });
197
197
  const cursor = cursor_1.Cursor.fromDataSources([dataSource1, dataSource2]);
198
198
  const results = [];
199
199
  for await (const item of cursor) {
200
200
  results.push(item);
201
201
  }
202
- expect(results.map(r => r.id)).toEqual([1, 2, 3, 4]);
202
+ expect(results.map((r) => r.id)).toEqual([1, 2, 3, 4]);
203
203
  });
204
- it('should support filters and options with fromDataSource', async () => {
204
+ it("should support filters and options with fromDataSource", async () => {
205
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'] });
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
211
  const results = [];
212
212
  for await (const item of cursor) {
213
213
  results.push(item);
214
214
  }
215
215
  // Should only get Bob and Charlie (age >= 30), sorted by name
216
- expect(results.map(r => r.name)).toEqual(['Bob', 'Charlie']);
216
+ expect(results.map((r) => r.name)).toEqual(["Bob", "Charlie"]);
217
217
  });
218
- it('should support filters and options with fromDataSources', async () => {
218
+ it("should support filters and options with fromDataSources", async () => {
219
219
  const dataSource1 = (0, factory_1.arrayAsTable)([
220
- { id: 1, name: 'Alice', age: 25 },
221
- { id: 2, name: 'Bob', age: 30 },
222
- ], { name: 'users1' });
220
+ { id: 1, name: "Alice", age: 25 },
221
+ { id: 2, name: "Bob", age: 30 },
222
+ ], { name: "users1" });
223
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'] });
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
228
  const results = [];
229
229
  for await (const item of cursor) {
230
230
  results.push(item);
231
231
  }
232
232
  // Should get Alice, Bob, Charlie (age >= 25), sorted by name
233
- expect(results.map(r => r.name)).toEqual(['Alice', 'Bob', 'Charlie']);
233
+ expect(results.map((r) => r.name)).toEqual(["Alice", "Bob", "Charlie"]);
234
234
  });
235
- it('should work with method chaining after fromDataSource', async () => {
235
+ it("should work with method chaining after fromDataSource", async () => {
236
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)
241
- .map(item => item.name.toUpperCase());
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());
242
241
  const results = [];
243
242
  for await (const item of cursor) {
244
243
  results.push(item);
245
244
  }
246
- expect(results).toEqual(['ALICE', 'BOB']);
245
+ expect(results).toEqual(["ALICE", "BOB"]);
247
246
  });
248
- it('should filter cursor values using instance filter()', async () => {
247
+ it("should filter cursor values using instance filter()", async () => {
249
248
  const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
250
249
  const filteredCursor = cursor.filter((x) => x % 3 === 0);
251
250
  const results = [];
@@ -254,57 +253,57 @@ describe('Cursor', () => {
254
253
  }
255
254
  expect(results).toEqual([3, 6, 9]);
256
255
  });
257
- it('should support async filter functions', async () => {
258
- const cursor = new cursor_1.Cursor(createMockCursor(['apple', 'banana', 'cherry', 'date', 'elderberry']));
256
+ it("should support async filter functions", async () => {
257
+ const cursor = new cursor_1.Cursor(createMockCursor(["apple", "banana", "cherry", "date", "elderberry"]));
259
258
  const filteredCursor = cursor.filter(async (x) => {
260
- await new Promise(resolve => setTimeout(resolve, 1));
261
- return x.startsWith('a') || x.startsWith('e');
259
+ await new Promise((resolve) => setTimeout(resolve, 1));
260
+ return x.startsWith("a") || x.startsWith("e");
262
261
  });
263
262
  const results = [];
264
263
  for await (const item of filteredCursor) {
265
264
  results.push(item);
266
265
  }
267
- expect(results).toEqual(['apple', 'elderberry']);
266
+ expect(results).toEqual(["apple", "elderberry"]);
268
267
  });
269
- it('should support method chaining with filter', async () => {
268
+ it("should support method chaining with filter", async () => {
270
269
  const cursor = new cursor_1.Cursor(createMockCursor([
271
- { id: 1, name: 'Alice', age: 25 },
272
- { id: 2, name: 'Bob', age: 30 },
273
- { id: 3, name: 'Charlie', age: 35 },
274
- { id: 4, name: 'David', age: 20 }
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 },
275
274
  ]));
276
275
  const result = cursor
277
- .filter(person => person.age >= 25)
278
- .map(person => person.name.toUpperCase())
279
- .filter(name => name.includes('A'));
276
+ .filter((person) => person.age >= 25)
277
+ .map((person) => person.name.toUpperCase())
278
+ .filter((name) => name.includes("A"));
280
279
  const results = [];
281
280
  for await (const item of result) {
282
281
  results.push(item);
283
282
  }
284
- expect(results).toEqual(['ALICE', 'CHARLIE']);
283
+ expect(results).toEqual(["ALICE", "CHARLIE"]);
285
284
  });
286
- it('should handle empty results after filtering', async () => {
285
+ it("should handle empty results after filtering", async () => {
287
286
  const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5]));
288
- const filteredCursor = cursor.filter(x => x > 10);
287
+ const filteredCursor = cursor.filter((x) => x > 10);
289
288
  const results = [];
290
289
  for await (const item of filteredCursor) {
291
290
  results.push(item);
292
291
  }
293
292
  expect(results).toEqual([]);
294
293
  });
295
- it('should propagate skipPast errors from filter()', async () => {
294
+ it("should propagate skipPast errors from filter()", async () => {
296
295
  const cursor = new cursor_1.Cursor(createMockCursor([1, 2, 3, 4, 5]));
297
- const filteredCursor = cursor.filter(x => x > 2);
298
- await expect(filteredCursor.next(3)).rejects.toThrow('skipPast is not supported for cursorFilter since filtering changes the cursor iteration order');
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");
299
298
  });
300
- it('should support complex method chaining with union, filter, and map', async () => {
299
+ it("should support complex method chaining with union, filter, and map", async () => {
301
300
  const cursor1 = new cursor_1.Cursor(createMockCursor([1, 2, 3]));
302
301
  const cursor2 = createMockCursor([4, 5, 6]);
303
302
  const cursor3 = createMockCursor([7, 8, 9]);
304
303
  const result = cursor1
305
304
  .union(cursor2, cursor3)
306
- .filter(x => x % 2 === 1) // odd numbers
307
- .map(x => x * 10);
305
+ .filter((x) => x % 2 === 1) // odd numbers
306
+ .map((x) => x * 10);
308
307
  const results = [];
309
308
  for await (const item of result) {
310
309
  results.push(item);
@@ -44,7 +44,7 @@ export interface IDataQueryParams<T extends Record<string, any>> {
44
44
  }
45
45
  export declare class DataQuery<T extends Record<string, any>> {
46
46
  readonly table: ITable<T>;
47
- constructor(table: ITable<T>, { page, pageSize, sortBy, filter, textSearch, textSearchExact, }?: IDataQueryParams<T>);
47
+ constructor(table: ITable<T>, { page, pageSize, sortBy, filter, textSearch, textSearchExact }?: IDataQueryParams<T>);
48
48
  page?: number;
49
49
  pageSize?: number;
50
50
  sortBy?: SortBy<T>;
@@ -77,9 +77,9 @@ export type SortBy<T extends {
77
77
  [key: string]: any;
78
78
  }> = (keyof T extends string | number ? keyof T | `-${keyof T}` : never)[];
79
79
  export type DataFieldScalar = boolean | number | string | Date | null;
80
- export type DataFilterValueOperator = '$eq' | '$ne' | '$gt' | '$gte' | '$lt' | '$lte' | '$exists' | '$matchWords' | '$substr' | '$expr' | '$in';
80
+ export type DataFilterValueOperator = "$eq" | "$ne" | "$gt" | "$gte" | "$lt" | "$lte" | "$exists" | "$matchWords" | "$substr" | "$expr" | "$in";
81
81
  export type DataFilterValue = DataFieldScalar | DataFieldScalar[] | {
82
- [key in Exclude<DataFilterValueOperator, '$in'>]?: DataFieldScalar;
82
+ [key in Exclude<DataFilterValueOperator, "$in">]?: DataFieldScalar;
83
83
  } | {
84
84
  $nin: DataFieldScalar[];
85
85
  } | {