@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
@@ -1,398 +1,367 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const data_query_mongo_1 = require("./data-query.mongo");
4
- describe('dataFilterToMongoQuery', () => {
5
- describe('Scalar values', () => {
6
- it('should handle null values', () => {
4
+ describe("dataFilterToMongoQuery", () => {
5
+ describe("Scalar values", () => {
6
+ it("should handle null values", () => {
7
7
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(null)).toBe(null);
8
8
  });
9
- it('should handle undefined values', () => {
9
+ it("should handle undefined values", () => {
10
10
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(undefined)).toBe(undefined);
11
11
  });
12
- it('should handle primitive values', () => {
12
+ it("should handle primitive values", () => {
13
13
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(42)).toBe(42);
14
- expect((0, data_query_mongo_1.dataFilterToMongoQuery)('test')).toBe('test');
14
+ expect((0, data_query_mongo_1.dataFilterToMongoQuery)("test")).toBe("test");
15
15
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(true)).toBe(true);
16
16
  });
17
- it('should handle Date objects', () => {
18
- const date = new Date('2023-01-01');
17
+ it("should handle Date objects", () => {
18
+ const date = new Date("2023-01-01");
19
19
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(date)).toBe(date);
20
20
  });
21
21
  });
22
- describe('Empty filters', () => {
23
- it('should handle empty object filters', () => {
22
+ describe("Empty filters", () => {
23
+ it("should handle empty object filters", () => {
24
24
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)({})).toEqual({});
25
25
  });
26
- it('should handle empty array filters', () => {
26
+ it("should handle empty array filters", () => {
27
27
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)([])).toEqual({});
28
28
  });
29
29
  });
30
- describe('Simple field conditions', () => {
31
- it('should handle basic field equality', () => {
32
- const filter = { name: 'John' };
33
- expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: 'John' });
30
+ describe("Simple field conditions", () => {
31
+ it("should handle basic field equality", () => {
32
+ const filter = { name: "John" };
33
+ expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: "John" });
34
34
  });
35
- it('should handle multiple fields', () => {
36
- const filter = { name: 'John', age: 30 };
37
- expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: 'John', age: 30 });
35
+ it("should handle multiple fields", () => {
36
+ const filter = { name: "John", age: 30 };
37
+ expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: "John", age: 30 });
38
38
  });
39
- it('should handle null field values', () => {
39
+ it("should handle null field values", () => {
40
40
  const filter = { name: null };
41
41
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: null });
42
42
  });
43
- it('should handle undefined field values', () => {
43
+ it("should handle undefined field values", () => {
44
44
  const filter = { name: undefined };
45
45
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: null });
46
46
  });
47
- it('should throw error for direct array usage', () => {
48
- const filter = { names: ['John', 'Jane'] };
49
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('Invalid filter: Arrays are not allowed as direct field values. Use $in instead');
47
+ it("should throw error for direct array usage", () => {
48
+ const filter = { names: ["John", "Jane"] };
49
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("Invalid filter: Arrays are not allowed as direct field values. Use $in instead");
50
50
  });
51
51
  });
52
- describe('MongoDB operators (direct mapping)', () => {
53
- describe('$eq operator', () => {
54
- it('should handle $eq operator', () => {
52
+ describe("MongoDB operators (direct mapping)", () => {
53
+ describe("$eq operator", () => {
54
+ it("should handle $eq operator", () => {
55
55
  const filter = { age: { $eq: 30 } };
56
56
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $eq: 30 } });
57
57
  });
58
58
  });
59
- describe('$ne operator', () => {
60
- it('should handle $ne operator', () => {
59
+ describe("$ne operator", () => {
60
+ it("should handle $ne operator", () => {
61
61
  const filter = { age: { $ne: 30 } };
62
62
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $ne: 30 } });
63
63
  });
64
64
  });
65
- describe('Comparison operators', () => {
66
- it('should handle $gt operator', () => {
65
+ describe("Comparison operators", () => {
66
+ it("should handle $gt operator", () => {
67
67
  const filter = { age: { $gt: 18 } };
68
68
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $gt: 18 } });
69
69
  });
70
- it('should handle $gte operator', () => {
70
+ it("should handle $gte operator", () => {
71
71
  const filter = { age: { $gte: 18 } };
72
72
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $gte: 18 } });
73
73
  });
74
- it('should handle $lt operator', () => {
74
+ it("should handle $lt operator", () => {
75
75
  const filter = { age: { $lt: 65 } };
76
76
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $lt: 65 } });
77
77
  });
78
- it('should handle $lte operator', () => {
78
+ it("should handle $lte operator", () => {
79
79
  const filter = { age: { $lte: 65 } };
80
80
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $lte: 65 } });
81
81
  });
82
- it('should handle multiple comparison operators', () => {
82
+ it("should handle multiple comparison operators", () => {
83
83
  const filter = { age: { $gte: 18, $lt: 65 } };
84
84
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $gte: 18, $lt: 65 } });
85
85
  });
86
86
  });
87
- describe('$in and $nin operators', () => {
88
- it('should handle $in operator', () => {
89
- const filter = { status: { $in: ['active', 'pending'] } };
90
- expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $in: ['active', 'pending'] } });
87
+ describe("$in and $nin operators", () => {
88
+ it("should handle $in operator", () => {
89
+ const filter = { status: { $in: ["active", "pending"] } };
90
+ expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $in: ["active", "pending"] } });
91
91
  });
92
- it('should handle $nin operator', () => {
93
- const filter = { status: { $nin: ['inactive', 'deleted'] } };
94
- expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $nin: ['inactive', 'deleted'] } });
92
+ it("should handle $nin operator", () => {
93
+ const filter = { status: { $nin: ["inactive", "deleted"] } };
94
+ expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
95
+ status: { $nin: ["inactive", "deleted"] },
96
+ });
95
97
  });
96
- it('should handle empty arrays', () => {
98
+ it("should handle empty arrays", () => {
97
99
  const filter = { status: { $in: [] } };
98
100
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $in: [] } });
99
101
  });
100
102
  });
101
- describe('$exists operator', () => {
102
- it('should handle $exists: true', () => {
103
+ describe("$exists operator", () => {
104
+ it("should handle $exists: true", () => {
103
105
  const filter = { email: { $exists: true } };
104
106
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ email: { $exists: true } });
105
107
  });
106
- it('should handle $exists: false', () => {
108
+ it("should handle $exists: false", () => {
107
109
  const filter = { email: { $exists: false } };
108
110
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ email: { $exists: false } });
109
111
  });
110
112
  });
111
113
  });
112
- describe('Logical operators', () => {
113
- describe('$or operator', () => {
114
- it('should handle $or with multiple conditions', () => {
115
- const filter = { $or: [{ name: 'John' }, { age: 30 }] };
114
+ describe("Logical operators", () => {
115
+ describe("$or operator", () => {
116
+ it("should handle $or with multiple conditions", () => {
117
+ const filter = { $or: [{ name: "John" }, { age: 30 }] };
116
118
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
117
- $or: [{ name: 'John' }, { age: 30 }]
119
+ $or: [{ name: "John" }, { age: 30 }],
118
120
  });
119
121
  });
120
- it('should handle empty $or array', () => {
122
+ it("should handle empty $or array", () => {
121
123
  const filter = { $or: [] };
122
124
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ $or: [] });
123
125
  });
124
- it('should handle $or with complex conditions', () => {
126
+ it("should handle $or with complex conditions", () => {
125
127
  const filter = {
126
- $or: [
127
- { name: 'John', age: { $gte: 18 } },
128
- { status: { $in: ['active', 'pending'] } }
129
- ]
128
+ $or: [{ name: "John", age: { $gte: 18 } }, { status: { $in: ["active", "pending"] } }],
130
129
  };
131
130
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
132
- $or: [
133
- { name: 'John', age: { $gte: 18 } },
134
- { status: { $in: ['active', 'pending'] } }
135
- ]
131
+ $or: [{ name: "John", age: { $gte: 18 } }, { status: { $in: ["active", "pending"] } }],
136
132
  });
137
133
  });
138
134
  });
139
- describe('$and operator', () => {
140
- it('should handle $and with multiple conditions', () => {
141
- const filter = { $and: [{ name: 'John' }, { age: 30 }] };
135
+ describe("$and operator", () => {
136
+ it("should handle $and with multiple conditions", () => {
137
+ const filter = { $and: [{ name: "John" }, { age: 30 }] };
142
138
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
143
- $and: [{ name: 'John' }, { age: 30 }]
139
+ $and: [{ name: "John" }, { age: 30 }],
144
140
  });
145
141
  });
146
- it('should handle empty $and array', () => {
142
+ it("should handle empty $and array", () => {
147
143
  const filter = { $and: [] };
148
144
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({});
149
145
  });
150
- it('should handle nested $and and $or', () => {
146
+ it("should handle nested $and and $or", () => {
151
147
  const filter = {
152
148
  $and: [
153
- { status: 'active' },
149
+ { status: "active" },
154
150
  {
155
- $or: [
156
- { age: { $gte: 18 } },
157
- { verified: true }
158
- ]
159
- }
160
- ]
151
+ $or: [{ age: { $gte: 18 } }, { verified: true }],
152
+ },
153
+ ],
161
154
  };
162
155
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
163
156
  $and: [
164
- { status: 'active' },
157
+ { status: "active" },
165
158
  {
166
- $or: [
167
- { age: { $gte: 18 } },
168
- { verified: true }
169
- ]
170
- }
171
- ]
159
+ $or: [{ age: { $gte: 18 } }, { verified: true }],
160
+ },
161
+ ],
172
162
  });
173
163
  });
174
164
  });
175
- describe('Array filters (OR logic)', () => {
176
- it('should handle single condition arrays', () => {
177
- const filter = [{ name: 'John' }];
178
- expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: 'John' });
165
+ describe("Array filters (OR logic)", () => {
166
+ it("should handle single condition arrays", () => {
167
+ const filter = [{ name: "John" }];
168
+ expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: "John" });
179
169
  });
180
- it('should handle multiple condition arrays', () => {
181
- const filter = [{ name: 'John' }, { age: 30 }, { city: 'NYC' }];
170
+ it("should handle multiple condition arrays", () => {
171
+ const filter = [{ name: "John" }, { age: 30 }, { city: "NYC" }];
182
172
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
183
- $or: [{ name: 'John' }, { age: 30 }, { city: 'NYC' }]
173
+ $or: [{ name: "John" }, { age: 30 }, { city: "NYC" }],
184
174
  });
185
175
  });
186
- it('should handle complex array conditions', () => {
176
+ it("should handle complex array conditions", () => {
187
177
  const filter = [
188
- { name: 'John', age: { $gte: 18 } },
189
- { status: { $in: ['active', 'pending'] } }
178
+ { name: "John", age: { $gte: 18 } },
179
+ { status: { $in: ["active", "pending"] } },
190
180
  ];
191
181
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
192
- $or: [
193
- { name: 'John', age: { $gte: 18 } },
194
- { status: { $in: ['active', 'pending'] } }
195
- ]
182
+ $or: [{ name: "John", age: { $gte: 18 } }, { status: { $in: ["active", "pending"] } }],
196
183
  });
197
184
  });
198
185
  });
199
186
  });
200
- describe('Custom operators', () => {
201
- describe('$matchWords operator', () => {
202
- it('should throw error for $matchWords (needs field context)', () => {
203
- const filter = { $matchWords: 'hello world' };
204
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$matchWords with multiple words requires field context');
187
+ describe("Custom operators", () => {
188
+ describe("$matchWords operator", () => {
189
+ it("should throw error for $matchWords (needs field context)", () => {
190
+ const filter = { $matchWords: "hello world" };
191
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$matchWords with multiple words requires field context");
205
192
  });
206
- it('should throw error for non-string values', () => {
193
+ it("should throw error for non-string values", () => {
207
194
  const filter = { $matchWords: 123 };
208
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$matchWords value must be a string');
195
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$matchWords value must be a string");
209
196
  });
210
197
  });
211
- describe('$substr operator', () => {
212
- it('should convert $substr to MongoDB $expr format', () => {
213
- const filter = { $substr: ['$fieldName', 1, 3] };
198
+ describe("$substr operator", () => {
199
+ it("should convert $substr to MongoDB $expr format", () => {
200
+ const filter = { $substr: ["$fieldName", 1, 3] };
214
201
  const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
215
202
  expect(result).toEqual({
216
203
  $expr: {
217
- $substr: ['$fieldName', 1, 3]
218
- }
204
+ $substr: ["$fieldName", 1, 3],
205
+ },
219
206
  });
220
207
  });
221
- it('should handle string literals in $substr', () => {
222
- const filter = { $substr: ['literal text', 0, 5] };
208
+ it("should handle string literals in $substr", () => {
209
+ const filter = { $substr: ["literal text", 0, 5] };
223
210
  const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
224
211
  expect(result).toEqual({
225
212
  $expr: {
226
- $substr: ['literal text', 0, 5]
227
- }
213
+ $substr: ["literal text", 0, 5],
214
+ },
228
215
  });
229
216
  });
230
- it('should throw error for invalid $substr arguments', () => {
231
- const filter = { $substr: ['$field'] }; // Missing arguments
232
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$substr requires exactly 3 arguments');
217
+ it("should throw error for invalid $substr arguments", () => {
218
+ const filter = { $substr: ["$field"] }; // Missing arguments
219
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$substr requires exactly 3 arguments");
233
220
  });
234
- it('should throw error for non-array $substr', () => {
235
- const filter = { $substr: 'invalid' };
236
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$substr requires exactly 3 arguments');
221
+ it("should throw error for non-array $substr", () => {
222
+ const filter = { $substr: "invalid" };
223
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$substr requires exactly 3 arguments");
237
224
  });
238
225
  });
239
- describe('$expr operator', () => {
240
- it('should convert simple $expr to MongoDB format', () => {
241
- const filter = { $expr: [{ $substr: ['$id', 0, 1] }, { $eq: 'A' }] };
226
+ describe("$expr operator", () => {
227
+ it("should convert simple $expr to MongoDB format", () => {
228
+ const filter = { $expr: [{ $substr: ["$id", 0, 1] }, { $eq: "A" }] };
242
229
  const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
243
230
  expect(result).toEqual({
244
231
  $expr: {
245
- $eq: [
246
- { $substr: ['$id', 0, 1] },
247
- 'A'
248
- ]
249
- }
232
+ $eq: [{ $substr: ["$id", 0, 1] }, "A"],
233
+ },
250
234
  });
251
235
  });
252
- it('should handle $expr with different operators', () => {
253
- const filter = { $expr: [{ $substr: ['$name', 0, 1] }, { $ne: 'Z' }] };
236
+ it("should handle $expr with different operators", () => {
237
+ const filter = { $expr: [{ $substr: ["$name", 0, 1] }, { $ne: "Z" }] };
254
238
  const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
255
239
  expect(result).toEqual({
256
240
  $expr: {
257
- $ne: [
258
- { $substr: ['$name', 0, 1] },
259
- 'Z'
260
- ]
261
- }
241
+ $ne: [{ $substr: ["$name", 0, 1] }, "Z"],
242
+ },
262
243
  });
263
244
  });
264
- it('should default to $eq for simple expressions', () => {
265
- const filter = { $expr: ['$field1', '$field2'] };
245
+ it("should default to $eq for simple expressions", () => {
246
+ const filter = { $expr: ["$field1", "$field2"] };
266
247
  const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
267
248
  expect(result).toEqual({
268
249
  $expr: {
269
- $eq: ['$field1', '$field2']
270
- }
250
+ $eq: ["$field1", "$field2"],
251
+ },
271
252
  });
272
253
  });
273
- it('should throw error for invalid $expr format', () => {
274
- const filter = { $expr: ['single_argument'] };
275
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$expr requires exactly 2 arguments');
254
+ it("should throw error for invalid $expr format", () => {
255
+ const filter = { $expr: ["single_argument"] };
256
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$expr requires exactly 2 arguments");
276
257
  });
277
258
  });
278
259
  });
279
- describe('Error cases', () => {
280
- it('should throw error for unknown operators', () => {
281
- const filter = { field: { $unknown: 'value' } };
282
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('Unknown operator: $unknown');
260
+ describe("Error cases", () => {
261
+ it("should throw error for unknown operators", () => {
262
+ const filter = { field: { $unknown: "value" } };
263
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("Unknown operator: $unknown");
283
264
  });
284
- it('should throw error for operators without $ prefix', () => {
285
- const filter = { field: { invalidOp: 'value' } };
286
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('Invalid operator: invalidOp. Operators must start with $');
265
+ it("should throw error for operators without $ prefix", () => {
266
+ const filter = { field: { invalidOp: "value" } };
267
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("Invalid operator: invalidOp. Operators must start with $");
287
268
  });
288
- it('should throw error for nested $matchWords', () => {
289
- const filter = { field: { $matchWords: 'test' } };
290
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$matchWords should be handled at field level');
269
+ it("should throw error for nested $matchWords", () => {
270
+ const filter = { field: { $matchWords: "test" } };
271
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$matchWords should be handled at field level");
291
272
  });
292
- it('should throw error for nested $substr', () => {
293
- const filter = { field: { $substr: ['$other', 0, 1] } };
294
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$substr should be handled at field level');
273
+ it("should throw error for nested $substr", () => {
274
+ const filter = { field: { $substr: ["$other", 0, 1] } };
275
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$substr should be handled at field level");
295
276
  });
296
- it('should throw error for nested $expr', () => {
297
- const filter = { field: { $expr: ['$a', '$b'] } };
298
- expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow('$expr should be handled at field level');
277
+ it("should throw error for nested $expr", () => {
278
+ const filter = { field: { $expr: ["$a", "$b"] } };
279
+ expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$expr should be handled at field level");
299
280
  });
300
281
  });
301
- describe('Complex nested scenarios', () => {
302
- it('should handle deeply nested conditions', () => {
282
+ describe("Complex nested scenarios", () => {
283
+ it("should handle deeply nested conditions", () => {
303
284
  const filter = {
304
285
  $and: [
305
- { status: 'active' },
286
+ { status: "active" },
306
287
  {
307
- $or: [
308
- { age: { $gte: 18, $lt: 65 } },
309
- { verified: true }
310
- ]
288
+ $or: [{ age: { $gte: 18, $lt: 65 } }, { verified: true }],
311
289
  },
312
- { role: { $in: ['user', 'admin'] } }
313
- ]
290
+ { role: { $in: ["user", "admin"] } },
291
+ ],
314
292
  };
315
293
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
316
294
  $and: [
317
- { status: 'active' },
295
+ { status: "active" },
318
296
  {
319
- $or: [
320
- { age: { $gte: 18, $lt: 65 } },
321
- { verified: true }
322
- ]
297
+ $or: [{ age: { $gte: 18, $lt: 65 } }, { verified: true }],
323
298
  },
324
- { role: { $in: ['user', 'admin'] } }
325
- ]
299
+ { role: { $in: ["user", "admin"] } },
300
+ ],
326
301
  });
327
302
  });
328
- it('should handle mixed array and object filters', () => {
303
+ it("should handle mixed array and object filters", () => {
329
304
  const filter = [
330
- { name: 'John', age: { $gte: 18 } },
305
+ { name: "John", age: { $gte: 18 } },
331
306
  {
332
- $and: [
333
- { status: 'active' },
334
- { verified: true }
335
- ]
336
- }
307
+ $and: [{ status: "active" }, { verified: true }],
308
+ },
337
309
  ];
338
310
  expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
339
311
  $or: [
340
- { name: 'John', age: { $gte: 18 } },
312
+ { name: "John", age: { $gte: 18 } },
341
313
  {
342
- $and: [
343
- { status: 'active' },
344
- { verified: true }
345
- ]
346
- }
347
- ]
314
+ $and: [{ status: "active" }, { verified: true }],
315
+ },
316
+ ],
348
317
  });
349
318
  });
350
319
  });
351
320
  });
352
- describe('sortByToMongoSort', () => {
353
- it('should handle empty sort', () => {
321
+ describe("sortByToMongoSort", () => {
322
+ it("should handle empty sort", () => {
354
323
  expect((0, data_query_mongo_1.sortByToMongoSort)()).toEqual({});
355
324
  expect((0, data_query_mongo_1.sortByToMongoSort)([])).toEqual({});
356
325
  });
357
- it('should handle ascending sort', () => {
358
- expect((0, data_query_mongo_1.sortByToMongoSort)(['name'])).toEqual({ name: 1 });
326
+ it("should handle ascending sort", () => {
327
+ expect((0, data_query_mongo_1.sortByToMongoSort)(["name"])).toEqual({ name: 1 });
359
328
  });
360
- it('should handle descending sort', () => {
361
- expect((0, data_query_mongo_1.sortByToMongoSort)(['-name'])).toEqual({ name: -1 });
329
+ it("should handle descending sort", () => {
330
+ expect((0, data_query_mongo_1.sortByToMongoSort)(["-name"])).toEqual({ name: -1 });
362
331
  });
363
- it('should handle multiple sort fields', () => {
364
- expect((0, data_query_mongo_1.sortByToMongoSort)(['name', '-age', 'created'])).toEqual({
332
+ it("should handle multiple sort fields", () => {
333
+ expect((0, data_query_mongo_1.sortByToMongoSort)(["name", "-age", "created"])).toEqual({
365
334
  name: 1,
366
335
  age: -1,
367
- created: 1
336
+ created: 1,
368
337
  });
369
338
  });
370
- it('should handle complex field names', () => {
371
- expect((0, data_query_mongo_1.sortByToMongoSort)(['-user.name', 'profile.age'])).toEqual({
372
- 'user.name': -1,
373
- 'profile.age': 1
339
+ it("should handle complex field names", () => {
340
+ expect((0, data_query_mongo_1.sortByToMongoSort)(["-user.name", "profile.age"])).toEqual({
341
+ "user.name": -1,
342
+ "profile.age": 1,
374
343
  });
375
344
  });
376
345
  });
377
- describe('paginationToMongoSkipLimit', () => {
378
- it('should handle no pagination', () => {
346
+ describe("paginationToMongoSkipLimit", () => {
347
+ it("should handle no pagination", () => {
379
348
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)()).toEqual({});
380
349
  });
381
- it('should handle only pageSize', () => {
350
+ it("should handle only pageSize", () => {
382
351
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(undefined, 10)).toEqual({ limit: 10 });
383
352
  });
384
- it('should handle only page (no effect without pageSize)', () => {
353
+ it("should handle only page (no effect without pageSize)", () => {
385
354
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(2)).toEqual({});
386
355
  });
387
- it('should handle page and pageSize', () => {
356
+ it("should handle page and pageSize", () => {
388
357
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(1, 10)).toEqual({ limit: 10 });
389
358
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(2, 10)).toEqual({ limit: 10, skip: 10 });
390
359
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(3, 20)).toEqual({ limit: 20, skip: 40 });
391
360
  });
392
- it('should handle fractional numbers', () => {
361
+ it("should handle fractional numbers", () => {
393
362
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(2.7, 10.3)).toEqual({ limit: 10, skip: 21 });
394
363
  });
395
- it('should handle zero page', () => {
364
+ it("should handle zero page", () => {
396
365
  expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(0, 10)).toEqual({ limit: 10 });
397
366
  });
398
367
  });
@@ -1,4 +1,4 @@
1
- import { DataFilter, DataQuery } from './data-query';
1
+ import type { DataFilter, DataQuery } from "./data-query";
2
2
  export declare function dataFilterToSqlWhere(filter: DataFilter<any>): string;
3
3
  /**
4
4
  * Converts a DataQuery to a complete SQLite query string