@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
@@ -7,7 +7,7 @@ exports.dataSourceCount = dataSourceCount;
7
7
  exports.filterToSkipPastValue = filterToSkipPastValue;
8
8
  class DataQuery {
9
9
  table;
10
- constructor(table, { page, pageSize, sortBy, filter, textSearch, textSearchExact, } = {}) {
10
+ constructor(table, { page, pageSize, sortBy, filter, textSearch, textSearchExact } = {}) {
11
11
  this.table = table;
12
12
  this.page = page;
13
13
  this.pageSize = pageSize;
@@ -32,8 +32,11 @@ class DataQuery {
32
32
  return null;
33
33
  }
34
34
  if (!buffer.length) {
35
- const sortBy = (this.sortBy?.length && this.sortBy || [this.table.metaData.primaryKeyName]);
36
- if (!sortBy.includes(this.table.metaData.primaryKeyName) && !sortBy.includes(`-${this.table.metaData.primaryKeyName}`)) {
35
+ const sortBy = ((this.sortBy?.length && this.sortBy) || [
36
+ this.table.metaData.primaryKeyName,
37
+ ]);
38
+ if (!sortBy.includes(this.table.metaData.primaryKeyName) &&
39
+ !sortBy.includes(`-${this.table.metaData.primaryKeyName}`)) {
37
40
  sortBy.push(this.table.metaData.primaryKeyName);
38
41
  }
39
42
  let filter = { ...this.filter };
@@ -45,7 +48,7 @@ class DataQuery {
45
48
  page: 1,
46
49
  pageSize: this.pageSize,
47
50
  sortBy: sortBy,
48
- textSearch: this.textSearch
51
+ textSearch: this.textSearch,
49
52
  });
50
53
  buffer = data;
51
54
  }
@@ -66,8 +69,11 @@ class DataQuery {
66
69
  if (!this.table.list) {
67
70
  throw new Error(`table does not support list`);
68
71
  }
69
- const sortBy = (this.sortBy?.length && this.sortBy || [this.table.metaData.primaryKeyName]);
70
- if (!sortBy.includes(this.table.metaData.primaryKeyName) && !sortBy.includes(`-${this.table.metaData.primaryKeyName}`)) {
72
+ const sortBy = ((this.sortBy?.length && this.sortBy) || [
73
+ this.table.metaData.primaryKeyName,
74
+ ]);
75
+ if (!sortBy.includes(this.table.metaData.primaryKeyName) &&
76
+ !sortBy.includes(`-${this.table.metaData.primaryKeyName}`)) {
71
77
  sortBy.push(this.table.metaData.primaryKeyName);
72
78
  }
73
79
  return this.table.list({ ...this.filter }, {
@@ -86,7 +92,7 @@ function iterableCursor(cursor) {
86
92
  next: async () => {
87
93
  const value = await cursor.next();
88
94
  return { value, done: !value };
89
- }
95
+ },
90
96
  };
91
97
  };
92
98
  return cursor;
@@ -96,7 +102,7 @@ function dataSourceCursor(dataSource, filter = {}, opts = {}) {
96
102
  // return dataSource.cursor(filter, opts);
97
103
  // }
98
104
  let buffer = [];
99
- let bufferPromise = undefined;
105
+ let bufferPromise;
100
106
  let eof = false;
101
107
  const primaryKeyName = dataSource.primaryKeyName;
102
108
  const pageSize = opts.pageSize || 100;
@@ -111,7 +117,7 @@ function dataSourceCursor(dataSource, filter = {}, opts = {}) {
111
117
  bufferPromise = undefined;
112
118
  }
113
119
  if (!buffer.length) {
114
- const sortBy = (opts.sortBy?.length && opts.sortBy || [primaryKeyName]);
120
+ const sortBy = ((opts.sortBy?.length && opts.sortBy) || [primaryKeyName]);
115
121
  if (!sortBy.includes(primaryKeyName) && !sortBy.includes(`-${primaryKeyName}`)) {
116
122
  sortBy.push(primaryKeyName);
117
123
  }
@@ -125,7 +131,7 @@ function dataSourceCursor(dataSource, filter = {}, opts = {}) {
125
131
  page: 1,
126
132
  pageSize,
127
133
  sortBy: sortBy,
128
- textSearch: opts.textSearch
134
+ textSearch: opts.textSearch,
129
135
  }));
130
136
  const nextSkipPast = buffer[buffer.length - 1];
131
137
  if (nextSkipPast) {
@@ -134,7 +140,7 @@ function dataSourceCursor(dataSource, filter = {}, opts = {}) {
134
140
  page: 1,
135
141
  pageSize,
136
142
  sortBy: sortBy,
137
- textSearch: opts.textSearch
143
+ textSearch: opts.textSearch,
138
144
  });
139
145
  }
140
146
  }
@@ -169,28 +175,28 @@ function filterToSkipPastValue(filter, sortBy, skipPast) {
169
175
  const filterEq = {};
170
176
  for (let j = i; j >= 0; j--) {
171
177
  const key = sortBy[j];
172
- const desc = key.startsWith('-');
178
+ const desc = key.startsWith("-");
173
179
  const fieldName = desc ? key.substring(1) : key;
174
180
  const value = skipPast[fieldName];
175
- let op = '';
181
+ let op = "";
176
182
  if (desc) {
177
183
  if (j === i) {
178
- op = '$lt';
184
+ op = "$lt";
179
185
  }
180
186
  else {
181
- op = '$eq';
187
+ op = "$eq";
182
188
  }
183
189
  }
184
190
  else {
185
191
  if (j === i) {
186
- op = '$gt';
192
+ op = "$gt";
187
193
  }
188
194
  else {
189
- op = '$eq';
195
+ op = "$eq";
190
196
  }
191
197
  }
192
198
  if (value === undefined || value === null) {
193
- if (op === '$eq') {
199
+ if (op === "$eq") {
194
200
  filterEq[fieldName] = { $exists: false };
195
201
  }
196
202
  else {
@@ -1,4 +1,4 @@
1
- import { DataFilter } from './data-query';
1
+ import type { DataFilter } from "./data-query";
2
2
  /**
3
3
  * Converts a DataFilter to a MongoDB query object
4
4
  */
@@ -26,7 +26,7 @@ function handleOrArray(filters) {
26
26
  if (filters.length === 1) {
27
27
  return dataFilterToMongoQuery(filters[0]);
28
28
  }
29
- return { $or: filters.map(f => dataFilterToMongoQuery(f)) };
29
+ return { $or: filters.map((f) => dataFilterToMongoQuery(f)) };
30
30
  }
31
31
  /**
32
32
  * Handles filter objects - processes each field
@@ -36,7 +36,7 @@ function handleFilterObject(filter) {
36
36
  for (const [fieldName, value] of Object.entries(filter)) {
37
37
  const result = handleFilterField(fieldName, value);
38
38
  // Merge the result into mongoFilter
39
- if (typeof result === 'object' && result !== null && !(0, lodash_1.isArray)(result)) {
39
+ if (typeof result === "object" && result !== null && !(0, lodash_1.isArray)(result)) {
40
40
  Object.assign(mongoFilter, result);
41
41
  }
42
42
  else {
@@ -49,22 +49,22 @@ function handleFilterObject(filter) {
49
49
  * Handles individual filter fields
50
50
  */
51
51
  function handleFilterField(fieldName, value) {
52
- if (fieldName === '$or') {
52
+ if (fieldName === "$or") {
53
53
  return { $or: value.map((v) => dataFilterToMongoQuery(v)) };
54
54
  }
55
- if (fieldName === '$and') {
55
+ if (fieldName === "$and") {
56
56
  if (value.length === 0) {
57
57
  return {}; // Empty $and matches everything
58
58
  }
59
59
  return { $and: value.map((v) => dataFilterToMongoQuery(v)) };
60
60
  }
61
- if (fieldName === '$matchWords') {
61
+ if (fieldName === "$matchWords") {
62
62
  return handleMatchWordsOperator(value);
63
63
  }
64
- if (fieldName === '$substr') {
64
+ if (fieldName === "$substr") {
65
65
  return handleSubstrOperator(value);
66
66
  }
67
- if (fieldName === '$expr') {
67
+ if (fieldName === "$expr") {
68
68
  return handleExprOperator(value);
69
69
  }
70
70
  return handleFieldCondition(fieldName, value);
@@ -79,7 +79,7 @@ function handleFieldCondition(fieldName, value) {
79
79
  if ((0, lodash_1.isArray)(value)) {
80
80
  throw new Error(`Invalid filter: Arrays are not allowed as direct field values. Use $in instead: { ${fieldName}: { $in: [...] } }`);
81
81
  }
82
- if (typeof value === 'object' && !(0, lodash_1.isDate)(value)) {
82
+ if (typeof value === "object" && !(0, lodash_1.isDate)(value)) {
83
83
  return { [fieldName]: handleObjectValue(value) };
84
84
  }
85
85
  return { [fieldName]: value };
@@ -90,7 +90,7 @@ function handleFieldCondition(fieldName, value) {
90
90
  function handleObjectValue(value) {
91
91
  const mongoValue = {};
92
92
  for (const [operator, operatorValue] of Object.entries(value)) {
93
- if (operator.startsWith('$')) {
93
+ if (operator.startsWith("$")) {
94
94
  mongoValue[operator] = handleOperatorValue(operator, operatorValue);
95
95
  }
96
96
  else {
@@ -104,23 +104,23 @@ function handleObjectValue(value) {
104
104
  */
105
105
  function handleOperatorValue(operator, value) {
106
106
  switch (operator) {
107
- case '$eq':
108
- case '$ne':
109
- case '$gt':
110
- case '$gte':
111
- case '$lt':
112
- case '$lte':
113
- case '$in':
114
- case '$nin':
115
- case '$exists':
107
+ case "$eq":
108
+ case "$ne":
109
+ case "$gt":
110
+ case "$gte":
111
+ case "$lt":
112
+ case "$lte":
113
+ case "$in":
114
+ case "$nin":
115
+ case "$exists":
116
116
  // These operators work directly in MongoDB
117
117
  return value;
118
- case '$matchWords':
119
- throw new Error('$matchWords should be handled at field level, not as nested operator');
120
- case '$substr':
121
- throw new Error('$substr should be handled at field level, not as nested operator');
122
- case '$expr':
123
- throw new Error('$expr should be handled at field level, not as nested operator');
118
+ case "$matchWords":
119
+ throw new Error("$matchWords should be handled at field level, not as nested operator");
120
+ case "$substr":
121
+ throw new Error("$substr should be handled at field level, not as nested operator");
122
+ case "$expr":
123
+ throw new Error("$expr should be handled at field level, not as nested operator");
124
124
  default:
125
125
  throw new Error(`Unknown operator: ${operator}`);
126
126
  }
@@ -129,10 +129,10 @@ function handleOperatorValue(operator, value) {
129
129
  * Converts $matchWords to MongoDB text search or regex
130
130
  */
131
131
  function handleMatchWordsOperator(searchText) {
132
- if (typeof searchText !== 'string') {
133
- throw new Error('$matchWords value must be a string');
132
+ if (typeof searchText !== "string") {
133
+ throw new Error("$matchWords value must be a string");
134
134
  }
135
- const words = searchText.split(' ').filter(word => word.trim());
135
+ const words = searchText.split(" ").filter((word) => word.trim());
136
136
  if (words.length === 0) {
137
137
  return {}; // Empty search matches everything
138
138
  }
@@ -140,33 +140,33 @@ function handleMatchWordsOperator(searchText) {
140
140
  // return { $text: { $search: searchText } };
141
141
  // Option 2: Use regex for each word (more compatible, works without indexes)
142
142
  if (words.length === 1) {
143
- return { $regex: escapeRegex(words[0]), $options: 'i' };
143
+ return { $regex: escapeRegex(words[0]), $options: "i" };
144
144
  }
145
145
  // For multiple words, create AND condition with regex for each word
146
- const regexConditions = words.map(word => ({
146
+ const _regexConditions = words.map((word) => ({
147
147
  $regex: escapeRegex(word),
148
- $options: 'i'
148
+ $options: "i",
149
149
  }));
150
150
  // This creates a field-level $and, which isn't standard MongoDB
151
151
  // We need to return this to be handled at a higher level
152
- throw new Error('$matchWords with multiple words requires field context - should be handled differently');
152
+ throw new Error("$matchWords with multiple words requires field context - should be handled differently");
153
153
  }
154
154
  /**
155
155
  * Converts $substr to MongoDB $expr with $substr
156
156
  */
157
157
  function handleSubstrOperator(args) {
158
158
  if (!(0, lodash_1.isArray)(args) || args.length !== 3) {
159
- throw new Error('$substr requires exactly 3 arguments: [string, start, length]');
159
+ throw new Error("$substr requires exactly 3 arguments: [string, start, length]");
160
160
  }
161
161
  const [str, start, length] = args;
162
162
  // Convert field references (strings starting with $)
163
- const mongoStr = typeof str === 'string' && str.startsWith('$')
163
+ const mongoStr = typeof str === "string" && str.startsWith("$")
164
164
  ? str // Keep MongoDB field reference format
165
165
  : str;
166
166
  return {
167
167
  $expr: {
168
- $substr: [mongoStr, start, length]
169
- }
168
+ $substr: [mongoStr, start, length],
169
+ },
170
170
  };
171
171
  }
172
172
  /**
@@ -174,7 +174,7 @@ function handleSubstrOperator(args) {
174
174
  */
175
175
  function handleExprOperator(exprArray) {
176
176
  if (!(0, lodash_1.isArray)(exprArray) || exprArray.length !== 2) {
177
- throw new Error('$expr requires exactly 2 arguments: [leftSide, rightSide]');
177
+ throw new Error("$expr requires exactly 2 arguments: [leftSide, rightSide]");
178
178
  }
179
179
  const [leftSide, rightSide] = exprArray;
180
180
  // Convert left side (usually a function like $substr)
@@ -182,37 +182,37 @@ function handleExprOperator(exprArray) {
182
182
  // Convert right side (usually a comparison)
183
183
  const mongoRight = convertExpressionPart(rightSide);
184
184
  // Determine the operation from rightSide
185
- if (typeof rightSide === 'object' && rightSide !== null) {
186
- const operators = Object.keys(rightSide).filter(k => k.startsWith('$'));
185
+ if (typeof rightSide === "object" && rightSide !== null) {
186
+ const operators = Object.keys(rightSide).filter((k) => k.startsWith("$"));
187
187
  if (operators.length === 1) {
188
188
  const op = operators[0];
189
189
  return {
190
190
  $expr: {
191
- [op]: [mongoLeft, rightSide[op]]
192
- }
191
+ [op]: [mongoLeft, rightSide[op]],
192
+ },
193
193
  };
194
194
  }
195
195
  }
196
196
  // Default to equality comparison
197
197
  return {
198
198
  $expr: {
199
- $eq: [mongoLeft, mongoRight]
200
- }
199
+ $eq: [mongoLeft, mongoRight],
200
+ },
201
201
  };
202
202
  }
203
203
  /**
204
204
  * Converts parts of expressions to MongoDB format
205
205
  */
206
206
  function convertExpressionPart(part) {
207
- if (typeof part === 'object' && part !== null && !(0, lodash_1.isArray)(part)) {
207
+ if (typeof part === "object" && part !== null && !(0, lodash_1.isArray)(part)) {
208
208
  // Handle function calls like { $substr: [...] }
209
209
  const keys = Object.keys(part);
210
- if (keys.length === 1 && keys[0].startsWith('$')) {
210
+ if (keys.length === 1 && keys[0].startsWith("$")) {
211
211
  const func = keys[0];
212
212
  const args = part[func];
213
- if (func === '$substr' && (0, lodash_1.isArray)(args) && args.length === 3) {
213
+ if (func === "$substr" && (0, lodash_1.isArray)(args) && args.length === 3) {
214
214
  const [str, start, length] = args;
215
- const mongoStr = typeof str === 'string' && str.startsWith('$') ? str : str;
215
+ const mongoStr = typeof str === "string" && str.startsWith("$") ? str : str;
216
216
  return { $substr: [mongoStr, start, length] };
217
217
  }
218
218
  }
@@ -223,15 +223,13 @@ function convertExpressionPart(part) {
223
223
  * Escapes special regex characters
224
224
  */
225
225
  function escapeRegex(text) {
226
- return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
226
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
227
227
  }
228
228
  /**
229
229
  * Checks if a value is a scalar (primitive) value
230
230
  */
231
231
  function isScalarValue(value) {
232
- return (typeof value !== 'object' ||
233
- (0, lodash_1.isDate)(value) ||
234
- value === null);
232
+ return typeof value !== "object" || (0, lodash_1.isDate)(value) || value === null;
235
233
  }
236
234
  /**
237
235
  * Converts DataQuery sort format to MongoDB sort format
@@ -242,7 +240,7 @@ function sortByToMongoSort(sortBy) {
242
240
  }
243
241
  const mongoSort = {};
244
242
  for (const field of sortBy) {
245
- if (field.startsWith('-')) {
243
+ if (field.startsWith("-")) {
246
244
  mongoSort[field.substring(1)] = -1; // Descending
247
245
  }
248
246
  else {