@signaldb/core 2.0.0-beta.2 → 2.0.0-beta.21

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 (145) hide show
  1. package/dist/.vite/manifest.json +183 -80
  2. package/dist/AsyncDataAdapter.d.ts +53 -7
  3. package/dist/AutoFetchDataAdapter.d.ts +4 -6
  4. package/dist/Collection/Cursor.d.ts +56 -4
  5. package/dist/Collection/Observer.d.ts +33 -0
  6. package/dist/Collection/index.d.ts +66 -19
  7. package/dist/Collection/types.d.ts +9 -2
  8. package/dist/DataAdapter.d.ts +24 -6
  9. package/dist/DefaultDataAdapter.d.ts +5 -5
  10. package/dist/WorkerDataAdapter.d.ts +57 -5
  11. package/dist/WorkerDataAdapterHost.d.ts +9 -7
  12. package/dist/createIndex.d.ts +2 -2
  13. package/dist/createIndexProvider.d.ts +2 -2
  14. package/dist/createReactivityAdapter.d.ts +2 -2
  15. package/dist/createStorageAdapter.d.ts +1 -1
  16. package/dist/getIndexInfo.d.ts +3 -4
  17. package/dist/index.cjs.js +33 -31
  18. package/dist/index.d.ts +6 -1
  19. package/dist/index.mjs +17 -32
  20. package/dist/index10.cjs.js +11 -0
  21. package/dist/index10.mjs +10 -18
  22. package/dist/index11.cjs.js +23 -0
  23. package/dist/index11.mjs +22 -15
  24. package/dist/index12.cjs.js +45 -0
  25. package/dist/index12.mjs +44 -353
  26. package/dist/index13.cjs.js +22 -0
  27. package/dist/index13.mjs +21 -419
  28. package/dist/index14.cjs.js +45 -0
  29. package/dist/index14.mjs +44 -206
  30. package/dist/index15.cjs.js +86 -0
  31. package/dist/index15.mjs +85 -388
  32. package/dist/index16.cjs.js +15 -0
  33. package/dist/index16.mjs +14 -579
  34. package/dist/index17.cjs.js +141 -0
  35. package/dist/index17.mjs +140 -152
  36. package/dist/index18.cjs.js +47 -0
  37. package/dist/index18.mjs +46 -26
  38. package/dist/index19.cjs.js +15 -0
  39. package/dist/index19.mjs +14 -41
  40. package/dist/index2.cjs.js +33 -0
  41. package/dist/index2.mjs +32 -258
  42. package/dist/index20.cjs.js +23 -0
  43. package/dist/index20.mjs +22 -16
  44. package/dist/index21.cjs.js +37 -0
  45. package/dist/index21.mjs +36 -104
  46. package/dist/index22.cjs.js +35 -0
  47. package/dist/index22.mjs +34 -128
  48. package/dist/index23.cjs.js +21 -0
  49. package/dist/index23.mjs +20 -7
  50. package/dist/index24.cjs.js +19 -0
  51. package/dist/index24.mjs +18 -27
  52. package/dist/index25.cjs.js +157 -0
  53. package/dist/index25.mjs +156 -11
  54. package/dist/index26.cjs.js +38 -0
  55. package/dist/index26.mjs +37 -29
  56. package/dist/index27.cjs.js +42 -0
  57. package/dist/index27.mjs +41 -46
  58. package/dist/index28.cjs.js +347 -0
  59. package/dist/index28.mjs +345 -7
  60. package/dist/index29.cjs.js +602 -0
  61. package/dist/index29.mjs +601 -7
  62. package/dist/index3.cjs.js +19 -0
  63. package/dist/index3.mjs +18 -556
  64. package/dist/index30.cjs.js +11 -0
  65. package/dist/index30.mjs +10 -42
  66. package/dist/index31.cjs.js +11 -0
  67. package/dist/index31.mjs +10 -29
  68. package/dist/index32.cjs.js +90 -0
  69. package/dist/index32.mjs +89 -10
  70. package/dist/index33.cjs.js +53 -0
  71. package/dist/index33.mjs +52 -5
  72. package/dist/index34.cjs.js +453 -0
  73. package/dist/index34.mjs +453 -0
  74. package/dist/index35.cjs.js +72 -0
  75. package/dist/index35.mjs +72 -0
  76. package/dist/index36.cjs.js +580 -0
  77. package/dist/index36.mjs +580 -0
  78. package/dist/index37.cjs.js +21 -0
  79. package/dist/index37.mjs +21 -0
  80. package/dist/index38.cjs.js +363 -0
  81. package/dist/index38.mjs +363 -0
  82. package/dist/index39.cjs.js +513 -0
  83. package/dist/index39.mjs +513 -0
  84. package/dist/index4.cjs.js +209 -0
  85. package/dist/index4.mjs +204 -5
  86. package/dist/index5.cjs.js +187 -0
  87. package/dist/index5.mjs +186 -5
  88. package/dist/index6.cjs.js +303 -0
  89. package/dist/index6.mjs +301 -28
  90. package/dist/index7.cjs.js +125 -0
  91. package/dist/index7.mjs +124 -12
  92. package/dist/index8.cjs.js +33 -0
  93. package/dist/index8.mjs +32 -5
  94. package/dist/index9.cjs.js +12 -0
  95. package/dist/index9.mjs +11 -133
  96. package/dist/types/IndexProvider.d.ts +2 -2
  97. package/dist/types/Modifier.d.ts +1 -1
  98. package/dist/types/ReactivityAdapter.d.ts +1 -1
  99. package/dist/types/StorageAdapter.d.ts +9 -1
  100. package/dist/utils/applyQueryOptions.d.ts +15 -0
  101. package/dist/utils/createSignal.d.ts +2 -2
  102. package/dist/utils/getMatchingKeys.d.ts +2 -2
  103. package/dist/utils/idIndexQuery.d.ts +20 -0
  104. package/dist/utils/incrementalQueryUpdate.d.ts +62 -0
  105. package/dist/utils/isFieldExpression.d.ts +1 -1
  106. package/dist/utils/match.d.ts +1 -1
  107. package/dist/utils/modify.d.ts +1 -1
  108. package/dist/utils/projectItems.d.ts +12 -0
  109. package/dist/utils/queryDelta.d.ts +83 -0
  110. package/dist/utils/queryId.d.ts +2 -2
  111. package/dist/utils/reactiveOrAsync.d.ts +59 -0
  112. package/dist/utils/storageIndexQuery.d.ts +20 -0
  113. package/package.json +1 -1
  114. package/dist/index.cjs10.js +0 -18
  115. package/dist/index.cjs11.js +0 -15
  116. package/dist/index.cjs12.js +0 -353
  117. package/dist/index.cjs13.js +0 -419
  118. package/dist/index.cjs14.js +0 -206
  119. package/dist/index.cjs15.js +0 -388
  120. package/dist/index.cjs16.js +0 -579
  121. package/dist/index.cjs17.js +0 -152
  122. package/dist/index.cjs18.js +0 -26
  123. package/dist/index.cjs19.js +0 -42
  124. package/dist/index.cjs2.js +0 -259
  125. package/dist/index.cjs20.js +0 -16
  126. package/dist/index.cjs21.js +0 -104
  127. package/dist/index.cjs22.js +0 -129
  128. package/dist/index.cjs23.js +0 -7
  129. package/dist/index.cjs24.js +0 -27
  130. package/dist/index.cjs25.js +0 -10
  131. package/dist/index.cjs26.js +0 -29
  132. package/dist/index.cjs27.js +0 -46
  133. package/dist/index.cjs28.js +0 -8
  134. package/dist/index.cjs29.js +0 -7
  135. package/dist/index.cjs3.js +0 -557
  136. package/dist/index.cjs30.js +0 -42
  137. package/dist/index.cjs31.js +0 -29
  138. package/dist/index.cjs32.js +0 -9
  139. package/dist/index.cjs33.js +0 -5
  140. package/dist/index.cjs4.js +0 -5
  141. package/dist/index.cjs5.js +0 -5
  142. package/dist/index.cjs6.js +0 -29
  143. package/dist/index.cjs7.js +0 -12
  144. package/dist/index.cjs8.js +0 -5
  145. package/dist/index.cjs9.js +0 -133
package/dist/index13.mjs CHANGED
@@ -1,420 +1,22 @@
1
- import deepClone from "./index19.mjs";
2
- import match from "./index23.mjs";
3
- import modify from "./index7.mjs";
4
- import queryId from "./index20.mjs";
5
- import isEqual from "./index6.mjs";
6
- import getIndexInfo from "./index22.mjs";
7
- import getMatchingKeys from "./index26.mjs";
8
- import sortItems from "./index25.mjs";
9
- import project from "./index24.mjs";
10
- class AsyncDataAdapter {
11
- options;
12
- id;
13
- onError;
14
- // Per-collection resources
15
- storageAdapters = /* @__PURE__ */ new Map();
16
- storageAdapterReady = /* @__PURE__ */ new Map();
17
- collectionIndices = /* @__PURE__ */ new Map();
18
- // Per-collection query registries
19
- queries = /* @__PURE__ */ new Map();
20
- constructor(options) {
21
- this.options = options;
22
- this.id = options.id || "async-data-adapter";
23
- this.onError = options.onError ?? ((error) => {
24
- console.error(error);
25
- });
26
- }
27
- createCollectionBackend(collection, indices) {
28
- this.collectionIndices.set(collection.name, indices);
29
- this.queries.set(collection.name, /* @__PURE__ */ new Map());
30
- this.ensureStorageAdapter(collection.name);
31
- const ready = (async () => {
32
- try {
33
- await this.setupStorage(collection.name, indices);
34
- } catch (error) {
35
- this.onError(error);
36
- throw error;
37
- }
38
- })();
39
- this.storageAdapterReady.set(collection.name, ready);
40
- const registerQuery = (selector, options) => {
41
- const qid = queryId(selector, options);
42
- const registry = this.queries.get(collection.name);
43
- if (!registry)
44
- throw new Error(`Collection ${collection.name} not initialized!`);
45
- registry.set(qid, {
46
- selector,
47
- options,
48
- items: [],
49
- listeners: /* @__PURE__ */ new Set(),
50
- ...registry.get(qid),
51
- state: "active",
52
- error: null
53
- });
54
- void this.fulfillQuery(collection.name, selector, options).catch(this.onError);
55
- };
56
- const unregisterQuery = (selector, options) => {
57
- const qid = queryId(selector, options);
58
- this.queries.get(collection.name)?.delete(qid);
59
- };
60
- const getQueryState = (selector, options) => {
61
- const q = this.queries.get(collection.name)?.get(queryId(selector, options));
62
- return q?.state ?? "active";
63
- };
64
- const getQueryError = (selector, options) => {
65
- const q = this.queries.get(collection.name)?.get(queryId(selector, options));
66
- return q?.error ?? null;
67
- };
68
- const getQueryResult = (selector, options) => {
69
- const q = this.queries.get(collection.name)?.get(queryId(selector, options));
70
- return q?.items ?? [];
71
- };
72
- const onQueryStateChange = (selector, options, callback) => {
73
- const qid = queryId(selector, options);
74
- const registry = this.queries.get(collection.name);
75
- if (!registry)
76
- throw new Error(`Collection ${collection.name} not initialized!`);
77
- if (!registry.has(qid)) {
78
- registry.set(qid, {
79
- selector,
80
- options,
81
- state: "active",
82
- error: null,
83
- items: [],
84
- listeners: /* @__PURE__ */ new Set()
85
- });
86
- }
87
- registry.get(qid)?.listeners.add(callback);
88
- return () => registry.get(qid)?.listeners.delete(callback);
89
- };
90
- return {
91
- insert: async (item) => {
92
- await ready;
93
- const inserted = await this.insert(collection.name, item);
94
- return inserted;
95
- },
96
- updateOne: async (selector, modifier) => {
97
- await ready;
98
- return this.updateOne(collection.name, selector, modifier);
99
- },
100
- updateMany: async (selector, modifier) => {
101
- await ready;
102
- return this.updateMany(collection.name, selector, modifier);
103
- },
104
- replaceOne: async (selector, replacement) => {
105
- await ready;
106
- return this.replaceOne(collection.name, selector, replacement);
107
- },
108
- removeOne: async (selector) => {
109
- await ready;
110
- return this.removeOne(collection.name, selector);
111
- },
112
- removeMany: async (selector) => {
113
- await ready;
114
- return this.removeMany(collection.name, selector);
115
- },
116
- registerQuery,
117
- unregisterQuery,
118
- getQueryState,
119
- getQueryError,
120
- getQueryResult,
121
- onQueryStateChange,
122
- executeQuery: async (selector, options) => {
123
- await ready;
124
- registerQuery(selector, options);
125
- const result = getQueryResult(selector, options);
126
- unregisterQuery(selector, options);
127
- return result;
128
- },
129
- dispose: async () => {
130
- this.storageAdapters.delete(collection.name);
131
- this.queries.delete(collection.name);
132
- this.collectionIndices.delete(collection.name);
133
- this.storageAdapterReady.delete(collection.name);
134
- },
135
- isReady: async () => {
136
- await ready;
137
- }
138
- };
139
- }
140
- async setupStorage(collectionName, indices) {
141
- const storage = this.storageAdapters.get(collectionName);
142
- if (!storage)
143
- throw new Error(`No persistence adapter for collection ${collectionName}`);
144
- await storage.setup();
145
- await Promise.all(indices.map((index) => storage.createIndex(index)));
146
- }
147
- ensureStorageAdapter(name) {
148
- if (this.storageAdapters.has(name))
149
- return;
150
- const adapter = this.options.storage(name);
151
- if (!adapter)
152
- return;
153
- this.storageAdapters.set(name, adapter);
154
- }
155
- /**
156
- * Compute and publish the result for a specific query
157
- * @param collectionName - name of the collection
158
- * @param selector - query selector
159
- * @param options - query options
160
- */
161
- async fulfillQuery(collectionName, selector, options) {
162
- const qid = queryId(selector, options);
163
- const registry = this.queries.get(collectionName);
164
- if (!registry)
165
- throw new Error(`Collection ${collectionName} not initialized!`);
166
- const rec = registry.get(qid);
167
- if (!rec)
168
- return;
169
- this.publishState(collectionName, qid, "active", null);
170
- try {
171
- const items = await this.executeQuery(collectionName, selector, options);
172
- this.publishResult(collectionName, qid, items);
173
- this.publishState(collectionName, qid, "complete", null);
174
- } catch (error) {
175
- this.publishState(collectionName, qid, "error", error);
176
- }
177
- }
178
- /**
179
- * Notify listeners about state changes and keep the cache updated
180
- * @param collectionName - name of the collection
181
- * @param qid - query id
182
- * @param state - new state
183
- * @param error - error if state is 'error', null otherwise
184
- */
185
- publishState(collectionName, qid, state, error) {
186
- const rec = this.queries.get(collectionName)?.get(qid);
187
- if (!rec)
188
- return;
189
- rec.state = state;
190
- rec.error = error;
191
- for (const callback of rec.listeners) {
192
- try {
193
- callback(state);
194
- } catch (error_) {
195
- this.onError(error_);
196
- }
197
- }
198
- }
199
- publishResult(collectionName, qid, items) {
200
- const rec = this.queries.get(collectionName)?.get(qid);
201
- if (!rec)
202
- return;
203
- rec.items = items;
204
- }
205
- async getIndexInfo(collectionName, selector) {
206
- const storageAdapter = this.storageAdapters.get(collectionName);
207
- if (!storageAdapter)
208
- throw new Error(`No persistence adapter for collection ${collectionName}`);
209
- if (selector != null && Object.keys(selector).length === 1 && "id" in selector && typeof selector.id !== "object") {
210
- return {
211
- matched: true,
212
- ids: [selector.id].filter(Boolean),
213
- optimizedSelector: {}
214
- };
215
- }
216
- if (selector == null) {
217
- return {
218
- matched: false,
219
- ids: [],
220
- optimizedSelector: {}
221
- };
222
- }
223
- const indices = this.collectionIndices.get(collectionName) ?? [];
224
- return getIndexInfo(indices.map((field) => async (flatSelector) => {
225
- if (!Object.hasOwnProperty.call(flatSelector, field))
226
- return { matched: false };
227
- const index = await storageAdapter.readIndex(field);
228
- const fieldSelector = flatSelector[field];
229
- const filtersForNull = fieldSelector == null || fieldSelector.$exists === false;
230
- const keys = filtersForNull ? { include: null, exclude: [...index.keys()].filter((key) => key != null) } : getMatchingKeys(field, flatSelector);
231
- if (keys.include == null && keys.exclude == null)
232
- return { matched: false };
233
- let includedIds = [];
234
- if (keys.include == null) {
235
- for (const set of index.values())
236
- for (const pos of set)
237
- includedIds.push(pos);
238
- } else {
239
- for (const key of keys.include) {
240
- const idSet = index.get(key);
241
- if (idSet)
242
- for (const id of idSet)
243
- includedIds.push(id);
244
- }
245
- }
246
- if (keys.exclude != null) {
247
- const excludeIds = /* @__PURE__ */ new Set();
248
- for (const key of keys.exclude) {
249
- const idSet = index.get(key);
250
- if (idSet)
251
- for (const id of idSet)
252
- excludeIds.add(id);
253
- }
254
- includedIds = includedIds.filter((pos) => !excludeIds.has(pos));
255
- }
256
- return { matched: true, ids: includedIds, fields: [field], keepSelector: filtersForNull };
257
- }), selector);
258
- }
259
- async queryItems(collectionName, selector) {
260
- const storage = this.storageAdapters.get(collectionName);
261
- if (!storage)
262
- throw new Error(`No persistence adapter for collection ${collectionName}`);
263
- const index = await this.getIndexInfo(collectionName, selector);
264
- const matchItems = (item) => {
265
- if (index.optimizedSelector == null)
266
- return true;
267
- if (Object.keys(index.optimizedSelector).length <= 0)
268
- return true;
269
- return match(item, index.optimizedSelector);
270
- };
271
- if (index.matched) {
272
- const items = await storage.readIds(index.ids);
273
- if (isEqual(index.optimizedSelector, {}))
274
- return items;
275
- return items.filter(matchItems);
276
- } else {
277
- const allItems = await storage.readAll();
278
- if (isEqual(selector, {}))
279
- return allItems;
280
- return allItems.filter(matchItems);
281
- }
282
- }
283
- async executeQuery(collectionName, selector, options) {
284
- const items = await this.queryItems(collectionName, selector || {});
285
- const { sort, skip, limit, fields } = options || {};
286
- const sorted = sort ? sortItems(items, sort) : items;
287
- const skipped = skip ? sorted.slice(skip) : sorted;
288
- const limited = limit ? skipped.slice(0, limit) : skipped;
289
- const idExcluded = fields && fields.id === 0;
290
- return limited.map((item) => {
291
- if (!fields)
292
- return item;
293
- return { ...idExcluded ? {} : { id: item.id }, ...project(item, fields) };
294
- });
295
- }
296
- /**
297
- * After mutations, recompute and push updates for affected active queries
298
- * @param collectionName - name of the collection
299
- * @param changedItems - items that were inserted/updated/replaced/removed
300
- */
301
- async checkQueryUpdates(collectionName, changedItems) {
302
- const registry = this.queries.get(collectionName);
303
- if (!registry)
304
- throw new Error(`Collection ${collectionName} not initialized!`);
305
- if (registry.size === 0)
306
- return;
307
- const affected = [...registry.values()].filter(({ selector }) => changedItems.some((item) => match(item, selector)));
308
- if (affected.length === 0)
309
- return;
310
- for (const { selector, options } of affected) {
311
- const qid = queryId(selector, options);
312
- this.publishState(collectionName, qid, "active", null);
313
- }
314
- await Promise.all(affected.map(async ({ selector, options }) => {
315
- const qid = queryId(selector, options);
316
- try {
317
- const items = await this.executeQuery(collectionName, selector, options);
318
- this.publishResult(collectionName, qid, items);
319
- this.publishState(collectionName, qid, "complete", null);
320
- } catch (error) {
321
- this.publishState(collectionName, qid, "error", error);
322
- }
323
- }));
324
- }
325
- async insert(collectionName, newItem) {
326
- const storage = this.storageAdapters.get(collectionName);
327
- if (!storage)
328
- throw new Error(`No persistence adapter for collection ${collectionName}`);
329
- const existingItems = await storage.readIds([newItem.id]);
330
- if (existingItems.length > 0)
331
- throw new Error(`Item with id ${String(newItem.id)} already exists`);
332
- await storage.insert([newItem]);
333
- await this.checkQueryUpdates(collectionName, [newItem]);
334
- return newItem;
335
- }
336
- async updateOne(collectionName, selector, modifier) {
337
- const storage = this.storageAdapters.get(collectionName);
338
- if (!storage)
339
- throw new Error(`No persistence adapter for collection ${collectionName}`);
340
- const items = await this.executeQuery(collectionName, selector, { limit: 1 });
341
- const [item] = items;
342
- const { $setOnInsert, ...rest } = modifier;
343
- if (item == null)
344
- return [];
345
- const modified = modify(deepClone(item), rest);
346
- if (item.id !== modified.id) {
347
- const existing = await this.executeQuery(collectionName, { id: modified.id }, { limit: 1 });
348
- if (existing.length > 0)
349
- throw new Error(`Item with id ${String(modified.id)} already exists`);
350
- }
351
- await storage.replace([modified]);
352
- await this.checkQueryUpdates(collectionName, [modified]);
353
- return [modified];
354
- }
355
- async updateMany(collectionName, selector, modifier) {
356
- const storage = this.storageAdapters.get(collectionName);
357
- if (!storage)
358
- throw new Error(`No persistence adapter for collection ${collectionName}`);
359
- const items = await this.executeQuery(collectionName, selector);
360
- if (items.length === 0)
361
- return [];
362
- const { $setOnInsert, ...rest } = modifier;
363
- const changed = await Promise.all(items.map(async (item) => {
364
- const modified = modify(deepClone(item), rest);
365
- if (item.id !== modified.id) {
366
- const existing = await this.executeQuery(collectionName, { id: modified.id }, { limit: 1 });
367
- if (existing.length > 0)
368
- throw new Error(`Item with id ${String(modified.id)} already exists`);
369
- }
370
- return modified;
371
- }));
372
- await storage.replace(changed);
373
- await this.checkQueryUpdates(collectionName, changed);
374
- return changed;
375
- }
376
- async replaceOne(collectionName, selector, replacement) {
377
- const storage = this.storageAdapters.get(collectionName);
378
- if (!storage)
379
- throw new Error(`No persistence adapter for collection ${collectionName}`);
380
- const items = await this.executeQuery(collectionName, selector, { limit: 1 });
381
- const [item] = items;
382
- if (item == null)
383
- return [];
384
- const modified = { ...replacement, id: replacement.id ?? item.id };
385
- if (item.id !== modified.id) {
386
- const existing = await this.executeQuery(collectionName, { id: modified.id }, { limit: 1 });
387
- if (existing.length > 0)
388
- throw new Error(`Item with id ${String(modified.id)} already exists`);
389
- }
390
- await storage.replace([modified]);
391
- await this.checkQueryUpdates(collectionName, [modified]);
392
- return [modified];
393
- }
394
- async removeOne(collectionName, selector) {
395
- const storage = this.storageAdapters.get(collectionName);
396
- if (!storage)
397
- throw new Error(`No persistence adapter for collection ${collectionName}`);
398
- const items = await this.executeQuery(collectionName, selector, { limit: 1 });
399
- const [item] = items;
400
- if (item == null)
401
- return [];
402
- await storage.remove([item]);
403
- await this.checkQueryUpdates(collectionName, [item]);
404
- return [item];
405
- }
406
- async removeMany(collectionName, selector) {
407
- const storage = this.storageAdapters.get(collectionName);
408
- if (!storage)
409
- throw new Error(`No persistence adapter for collection ${collectionName}`);
410
- const items = await this.executeQuery(collectionName, selector);
411
- if (items.length === 0)
412
- return [];
413
- await storage.remove(items);
414
- await this.checkQueryUpdates(collectionName, items);
415
- return items;
416
- }
1
+ //#region src/utils/serializeValue.ts
2
+ /**
3
+ * Serializes a value into a string representation.
4
+ * Handles various types, including strings, numbers, booleans, dates, and objects.
5
+ * Falls back to JSON stringification for unsupported types.
6
+ * @param value - The value to serialize.
7
+ * - Strings are returned as-is.
8
+ * - Numbers and booleans are converted to their string representation.
9
+ * - Dates are converted to ISO string format.
10
+ * - Other values are stringified using `JSON.stringify`.
11
+ * @returns A string representation of the value.
12
+ */
13
+ function serializeValue(value) {
14
+ if (value == null) return null;
15
+ if (typeof value === "string") return value;
16
+ if (typeof value === "number") return value.toString();
17
+ if (typeof value === "boolean") return value.toString();
18
+ if (value instanceof Date) return value.toISOString();
19
+ return JSON.stringify(value);
417
20
  }
418
- export {
419
- AsyncDataAdapter as default
420
- };
21
+ //#endregion
22
+ export { serializeValue as default };
@@ -0,0 +1,45 @@
1
+ const require_isFieldExpression = require("./index12.cjs.js");
2
+ const require_serializeValue = require("./index13.cjs.js");
3
+ //#region src/utils/getMatchingKeys.ts
4
+ /**
5
+ * Extracts the matching and excluded keys for a given field in a selector.
6
+ * Supports serialized values and `$in`/`$nin` field expressions for optimization.
7
+ * Returns `null` for include/exclude if the field cannot be optimized.
8
+ * @template T - The type of the items in the selector.
9
+ * @template I - The type of the unique identifier for the items.
10
+ * @param field - The name of the field to extract matching keys for.
11
+ * @param selector - The selector object containing query criteria.
12
+ * @returns An object containing arrays of serialized included and excluded keys,
13
+ * or `null` if the field cannot be optimized.
14
+ */
15
+ function getMatchingKeys(field, selector) {
16
+ const result = {
17
+ include: null,
18
+ exclude: null
19
+ };
20
+ const fieldSelector = selector[field];
21
+ if (fieldSelector instanceof RegExp) return result;
22
+ if (fieldSelector == null) return result;
23
+ if (require_isFieldExpression.default(fieldSelector)) {
24
+ if (fieldSelector.$ne != null) {
25
+ result.exclude = [require_serializeValue.default(fieldSelector.$ne)];
26
+ return result;
27
+ }
28
+ if (Array.isArray(fieldSelector.$in) && fieldSelector.$in.length > 0) {
29
+ result.include = fieldSelector.$in.map(require_serializeValue.default);
30
+ return result;
31
+ }
32
+ if (Array.isArray(fieldSelector.$nin) && fieldSelector.$nin.length > 0) {
33
+ result.exclude = fieldSelector.$nin.map(require_serializeValue.default);
34
+ return result;
35
+ }
36
+ return {
37
+ include: null,
38
+ exclude: null
39
+ };
40
+ }
41
+ result.include = [require_serializeValue.default(fieldSelector)];
42
+ return result;
43
+ }
44
+ //#endregion
45
+ exports.default = getMatchingKeys;