@signaldb/core 2.0.0-beta.4 → 2.0.0-beta.6

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 (60) hide show
  1. package/dist/.vite/manifest.json +27 -21
  2. package/dist/Collection/Observer.d.ts +2 -0
  3. package/dist/Collection/index.d.ts +11 -10
  4. package/dist/Collection/types.d.ts +7 -0
  5. package/dist/DefaultDataAdapter.d.ts +2 -0
  6. package/dist/index.cjs.js +8 -5
  7. package/dist/index.cjs12.js +41 -346
  8. package/dist/index.cjs13.js +308 -359
  9. package/dist/index.cjs14.js +387 -177
  10. package/dist/index.cjs15.js +182 -364
  11. package/dist/index.cjs16.js +287 -478
  12. package/dist/index.cjs17.js +563 -136
  13. package/dist/index.cjs18.js +154 -23
  14. package/dist/index.cjs19.js +23 -39
  15. package/dist/index.cjs2.js +1 -1
  16. package/dist/index.cjs20.js +39 -13
  17. package/dist/index.cjs21.js +14 -102
  18. package/dist/index.cjs22.js +93 -118
  19. package/dist/index.cjs23.js +127 -5
  20. package/dist/index.cjs24.js +5 -25
  21. package/dist/index.cjs25.js +24 -7
  22. package/dist/index.cjs26.js +8 -27
  23. package/dist/index.cjs27.js +25 -42
  24. package/dist/index.cjs28.js +44 -6
  25. package/dist/index.cjs29.js +6 -7
  26. package/dist/index.cjs3.js +9 -26
  27. package/dist/index.cjs30.js +7 -3
  28. package/dist/index.cjs32.js +40 -27
  29. package/dist/index.cjs33.js +27 -40
  30. package/dist/index.cjs34.js +5 -0
  31. package/dist/index.cjs7.js +1 -1
  32. package/dist/index.d.ts +2 -1
  33. package/dist/index.mjs +10 -7
  34. package/dist/index12.mjs +40 -346
  35. package/dist/index13.mjs +308 -359
  36. package/dist/index14.mjs +387 -177
  37. package/dist/index15.mjs +182 -364
  38. package/dist/index16.mjs +287 -478
  39. package/dist/index17.mjs +563 -136
  40. package/dist/index18.mjs +154 -23
  41. package/dist/index19.mjs +23 -38
  42. package/dist/index2.mjs +1 -1
  43. package/dist/index20.mjs +38 -13
  44. package/dist/index21.mjs +14 -102
  45. package/dist/index22.mjs +93 -117
  46. package/dist/index23.mjs +126 -5
  47. package/dist/index24.mjs +5 -25
  48. package/dist/index25.mjs +24 -7
  49. package/dist/index26.mjs +8 -27
  50. package/dist/index27.mjs +25 -42
  51. package/dist/index28.mjs +44 -6
  52. package/dist/index29.mjs +6 -7
  53. package/dist/index3.mjs +9 -26
  54. package/dist/index30.mjs +7 -3
  55. package/dist/index32.mjs +40 -27
  56. package/dist/index33.mjs +27 -40
  57. package/dist/index34.mjs +6 -0
  58. package/dist/index7.mjs +1 -1
  59. package/dist/utils/reactiveOrAsync.d.ts +59 -0
  60. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "src/AsyncDataAdapter.ts": {
3
- "file": "index.cjs13.js",
3
+ "file": "index.cjs14.js",
4
4
  "name": "AsyncDataAdapter",
5
5
  "src": "src/AsyncDataAdapter.ts",
6
6
  "imports": [
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "src/AutoFetchDataAdapter.ts": {
19
- "file": "index.cjs16.js",
19
+ "file": "index.cjs17.js",
20
20
  "name": "AutoFetchDataAdapter",
21
21
  "src": "src/AutoFetchDataAdapter.ts",
22
22
  "imports": [
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  },
42
42
  "src/Collection/Observer.ts": {
43
- "file": "index.cjs17.js",
43
+ "file": "index.cjs18.js",
44
44
  "name": "Collection/Observer",
45
45
  "src": "src/Collection/Observer.ts",
46
46
  "imports": [
@@ -64,7 +64,7 @@
64
64
  ]
65
65
  },
66
66
  "src/DefaultDataAdapter.ts": {
67
- "file": "index.cjs12.js",
67
+ "file": "index.cjs13.js",
68
68
  "name": "DefaultDataAdapter",
69
69
  "src": "src/DefaultDataAdapter.ts",
70
70
  "imports": [
@@ -82,7 +82,7 @@
82
82
  ]
83
83
  },
84
84
  "src/WorkerDataAdapter.ts": {
85
- "file": "index.cjs14.js",
85
+ "file": "index.cjs15.js",
86
86
  "name": "WorkerDataAdapter",
87
87
  "src": "src/WorkerDataAdapter.ts",
88
88
  "imports": [
@@ -92,7 +92,7 @@
92
92
  ]
93
93
  },
94
94
  "src/WorkerDataAdapterHost.ts": {
95
- "file": "index.cjs15.js",
95
+ "file": "index.cjs16.js",
96
96
  "name": "WorkerDataAdapterHost",
97
97
  "src": "src/WorkerDataAdapterHost.ts",
98
98
  "imports": [
@@ -109,7 +109,7 @@
109
109
  ]
110
110
  },
111
111
  "src/createIndex.ts": {
112
- "file": "index.cjs21.js",
112
+ "file": "index.cjs22.js",
113
113
  "name": "createIndex",
114
114
  "src": "src/createIndex.ts",
115
115
  "imports": [
@@ -120,7 +120,7 @@
120
120
  ]
121
121
  },
122
122
  "src/createIndexProvider.ts": {
123
- "file": "index.cjs30.js",
123
+ "file": "index.cjs34.js",
124
124
  "name": "createIndexProvider",
125
125
  "src": "src/createIndexProvider.ts"
126
126
  },
@@ -135,7 +135,7 @@
135
135
  "src": "src/createStorageAdapter.ts"
136
136
  },
137
137
  "src/getIndexInfo.ts": {
138
- "file": "index.cjs22.js",
138
+ "file": "index.cjs23.js",
139
139
  "name": "getIndexInfo",
140
140
  "src": "src/getIndexInfo.ts",
141
141
  "imports": [
@@ -158,6 +158,7 @@
158
158
  "src/utils/EventEmitter.ts",
159
159
  "src/utils/get.ts",
160
160
  "src/utils/serializeValue.ts",
161
+ "src/utils/reactiveOrAsync.ts",
161
162
  "src/DefaultDataAdapter.ts",
162
163
  "src/AsyncDataAdapter.ts",
163
164
  "src/WorkerDataAdapter.ts",
@@ -171,22 +172,22 @@
171
172
  "src": "src/utils/EventEmitter.ts"
172
173
  },
173
174
  "src/utils/batchOnNextTick.ts": {
174
- "file": "index.cjs27.js",
175
+ "file": "index.cjs28.js",
175
176
  "name": "utils/batchOnNextTick",
176
177
  "src": "src/utils/batchOnNextTick.ts"
177
178
  },
178
179
  "src/utils/compact.ts": {
179
- "file": "index.cjs28.js",
180
+ "file": "index.cjs29.js",
180
181
  "name": "utils/compact",
181
182
  "src": "src/utils/compact.ts"
182
183
  },
183
184
  "src/utils/createSignal.ts": {
184
- "file": "index.cjs18.js",
185
+ "file": "index.cjs19.js",
185
186
  "name": "utils/createSignal",
186
187
  "src": "src/utils/createSignal.ts"
187
188
  },
188
189
  "src/utils/deepClone.ts": {
189
- "file": "index.cjs19.js",
190
+ "file": "index.cjs20.js",
190
191
  "name": "utils/deepClone",
191
192
  "src": "src/utils/deepClone.ts"
192
193
  },
@@ -196,7 +197,7 @@
196
197
  "src": "src/utils/get.ts"
197
198
  },
198
199
  "src/utils/getMatchingKeys.ts": {
199
- "file": "index.cjs26.js",
200
+ "file": "index.cjs27.js",
200
201
  "name": "utils/getMatchingKeys",
201
202
  "src": "src/utils/getMatchingKeys.ts",
202
203
  "imports": [
@@ -215,12 +216,12 @@
215
216
  "src": "src/utils/isEqual.ts"
216
217
  },
217
218
  "src/utils/isFieldExpression.ts": {
218
- "file": "index.cjs33.js",
219
+ "file": "index.cjs32.js",
219
220
  "name": "utils/isFieldExpression",
220
221
  "src": "src/utils/isFieldExpression.ts"
221
222
  },
222
223
  "src/utils/match.ts": {
223
- "file": "index.cjs23.js",
224
+ "file": "index.cjs24.js",
224
225
  "name": "utils/match",
225
226
  "src": "src/utils/match.ts"
226
227
  },
@@ -233,7 +234,7 @@
233
234
  ]
234
235
  },
235
236
  "src/utils/project.ts": {
236
- "file": "index.cjs24.js",
237
+ "file": "index.cjs25.js",
237
238
  "name": "utils/project",
238
239
  "src": "src/utils/project.ts",
239
240
  "imports": [
@@ -242,7 +243,7 @@
242
243
  ]
243
244
  },
244
245
  "src/utils/queryId.ts": {
245
- "file": "index.cjs20.js",
246
+ "file": "index.cjs21.js",
246
247
  "name": "utils/queryId",
247
248
  "src": "src/utils/queryId.ts"
248
249
  },
@@ -251,18 +252,23 @@
251
252
  "name": "utils/randomId",
252
253
  "src": "src/utils/randomId.ts"
253
254
  },
255
+ "src/utils/reactiveOrAsync.ts": {
256
+ "file": "index.cjs12.js",
257
+ "name": "utils/reactiveOrAsync",
258
+ "src": "src/utils/reactiveOrAsync.ts"
259
+ },
254
260
  "src/utils/serializeValue.ts": {
255
261
  "file": "index.cjs11.js",
256
262
  "name": "utils/serializeValue",
257
263
  "src": "src/utils/serializeValue.ts"
258
264
  },
259
265
  "src/utils/set.ts": {
260
- "file": "index.cjs32.js",
266
+ "file": "index.cjs33.js",
261
267
  "name": "utils/set",
262
268
  "src": "src/utils/set.ts"
263
269
  },
264
270
  "src/utils/sortItems.ts": {
265
- "file": "index.cjs25.js",
271
+ "file": "index.cjs26.js",
266
272
  "name": "utils/sortItems",
267
273
  "src": "src/utils/sortItems.ts",
268
274
  "imports": [
@@ -270,7 +276,7 @@
270
276
  ]
271
277
  },
272
278
  "src/utils/uniqueBy.ts": {
273
- "file": "index.cjs29.js",
279
+ "file": "index.cjs30.js",
274
280
  "name": "utils/uniqueBy",
275
281
  "src": "src/utils/uniqueBy.ts"
276
282
  }
@@ -43,8 +43,10 @@ export default class Observer<T extends {
43
43
  */
44
44
  runChecks(getItems: () => Promise<T[]> | T[]): void;
45
45
  private checkItems;
46
+ private stopped;
46
47
  /**
47
48
  * Stops the observer by unbinding all events and cleaning up resources.
49
+ * Safe to call multiple times - will only unbind once.
48
50
  */
49
51
  stop(): void;
50
52
  /**
@@ -6,8 +6,8 @@ import type DataAdapter from '../DataAdapter';
6
6
  import type { QueryOptions } from '../DataAdapter';
7
7
  import type StorageAdapter from '../types/StorageAdapter';
8
8
  import Cursor from './Cursor';
9
- import type { BaseItem, FindOptions, Transform, TransformAll } from './types';
10
- export type { BaseItem, Transform, TransformAll, SortSpecifier, FieldSpecifier, FindOptions } from './types';
9
+ import type { AsyncFindOptions, BaseItem, FindOptions, SyncFindOptions, Transform, TransformAll } from './types';
10
+ export type { AnyFindOptions, AsyncFindOptions, BaseItem, Transform, TransformAll, SortSpecifier, FieldSpecifier, FindOptions, SyncFindOptions, } from './types';
11
11
  export type { CursorOptions } from './Cursor';
12
12
  export type { ObserveCallbacks } from './Observer';
13
13
  export { default as createIndex } from '../createIndex';
@@ -35,7 +35,7 @@ interface CollectionEvents<T extends BaseItem, E extends BaseItem = T, U = E> {
35
35
  'observer.created': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
36
36
  'observer.disposed': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
37
37
  'getItems': (selector: Selector<T> | undefined) => void;
38
- 'find': <O extends FindOptions<T, Async>, Async extends boolean>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
38
+ 'find': <Async extends boolean, O extends FindOptions<T, Async>>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
39
39
  'findOne': <O extends QueryOptions<T>>(selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
40
40
  'insert': (item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
41
41
  'updateOne': (selector: Selector<T>, modifier: Modifier<T>) => void;
@@ -45,8 +45,8 @@ interface CollectionEvents<T extends BaseItem, E extends BaseItem = T, U = E> {
45
45
  'removeMany': (selector: Selector<T>) => void;
46
46
  'validate': (item: T) => void;
47
47
  '_debug.getItems': (callstack: string, selector: Selector<T> | undefined, measuredTime: number) => void;
48
- '_debug.find': <O extends FindOptions<T, Async>, Async extends boolean>(callstack: string, selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
49
- '_debug.findOne': <O extends FindOptions<T, Async>, Async extends boolean>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
48
+ '_debug.find': <Async extends boolean, O extends FindOptions<T, Async>>(callstack: string, selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
49
+ '_debug.findOne': <Async extends boolean, O extends FindOptions<T, Async>>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
50
50
  '_debug.insert': (callstack: string, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
51
51
  '_debug.updateOne': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
52
52
  '_debug.updateMany': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
@@ -200,23 +200,24 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E ext
200
200
  /**
201
201
  * Finds multiple items in the collection based on a selector and optional options.
202
202
  * Returns a cursor for reactive data queries.
203
- * @template O - The options type for the find operation.
204
203
  * @param [selector] - The criteria to select items.
205
204
  * @param [options] - Options for the find operation, such as limit and sort.
206
205
  * @returns A cursor to fetch and observe the matching items.
207
206
  */
208
- find<Async extends boolean = false, O extends FindOptions<T, Async> = FindOptions<T, Async>>(selector?: Selector<T>, options?: O): Cursor<E, U, Async>;
207
+ find(selector?: Selector<T>, options?: SyncFindOptions<T>): Cursor<E, U, false>;
208
+ find(selector: Selector<T> | undefined, options: AsyncFindOptions<T>): Cursor<E, U, true>;
209
+ find(selector?: Selector<T>, options?: FindOptions<T, boolean>): Cursor<E, U, boolean>;
209
210
  /**
210
211
  * Finds a single item in the collection based on a selector and optional options.
211
212
  * ⚡️ this function is reactive!
212
213
  * Returns the found item or undefined if no item matches.
213
- * @template Async - Whether to perform the operation asynchronously.
214
- * @template O - The options type for the find operation.
215
214
  * @param selector - The criteria to select the item.
216
215
  * @param [options] - Options for the find operation, such as projection.
217
216
  * @returns The found item or `undefined`.
218
217
  */
219
- findOne<Async extends boolean = false, O extends Omit<FindOptions<T, Async>, 'limit'> = Omit<FindOptions<T, Async>, 'limit'>>(selector: Selector<T>, options?: O): Async extends true ? Promise<U | undefined> : U | undefined;
218
+ findOne(selector: Selector<T>, options?: Omit<SyncFindOptions<T>, 'limit'>): U | undefined;
219
+ findOne(selector: Selector<T>, options: Omit<AsyncFindOptions<T>, 'limit'>): Promise<U | undefined>;
220
+ findOne(selector: Selector<T>, options?: Omit<FindOptions<T, boolean>, 'limit'>): Promise<U | undefined> | U | undefined;
220
221
  /**
221
222
  * Performs a batch operation, deferring index rebuilds and allowing multiple
222
223
  * modifications to be made atomically. Executes any post-batch callbacks afterwards.
@@ -19,3 +19,10 @@ export interface FindOptions<T extends BaseItem, Async extends boolean> extends
19
19
  /** pass `true` to execute the query asynchronously */
20
20
  async?: Async;
21
21
  }
22
+ export type AsyncFindOptions<T extends BaseItem> = Omit<FindOptions<T, true>, 'async'> & {
23
+ async: true;
24
+ };
25
+ export type SyncFindOptions<T extends BaseItem> = Omit<FindOptions<T, false>, 'async'> & {
26
+ async?: false;
27
+ };
28
+ export type AnyFindOptions<T extends BaseItem> = AsyncFindOptions<T> | SyncFindOptions<T>;
@@ -11,6 +11,7 @@ export default class DefaultDataAdapter implements DataAdapter {
11
11
  private items;
12
12
  private options;
13
13
  private storageAdapters;
14
+ private collections;
14
15
  private indices;
15
16
  private activeQueries;
16
17
  private queryEmitters;
@@ -29,5 +30,6 @@ export default class DefaultDataAdapter implements DataAdapter {
29
30
  private executeAndCacheQuery;
30
31
  private updateQueries;
31
32
  createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
33
+ fetchItemsFromStorage<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection?: Collection<T, I, E, U>): Promise<void>;
32
34
  }
33
35
  export {};
package/dist/index.cjs.js CHANGED
@@ -10,11 +10,12 @@ const randomId = require("./index.cjs8.js");
10
10
  const EventEmitter = require("./index.cjs9.js");
11
11
  const get = require("./index.cjs10.js");
12
12
  const serializeValue = require("./index.cjs11.js");
13
- const DefaultDataAdapter = require("./index.cjs12.js");
14
- const AsyncDataAdapter = require("./index.cjs13.js");
15
- const WorkerDataAdapter = require("./index.cjs14.js");
16
- const WorkerDataAdapterHost = require("./index.cjs15.js");
17
- const AutoFetchDataAdapter = require("./index.cjs16.js");
13
+ const reactiveOrAsync = require("./index.cjs12.js");
14
+ const DefaultDataAdapter = require("./index.cjs13.js");
15
+ const AsyncDataAdapter = require("./index.cjs14.js");
16
+ const WorkerDataAdapter = require("./index.cjs15.js");
17
+ const WorkerDataAdapterHost = require("./index.cjs16.js");
18
+ const AutoFetchDataAdapter = require("./index.cjs17.js");
18
19
  exports.Cursor = Cursor.default;
19
20
  exports.Collection = index.default;
20
21
  exports.createStorageAdapter = createStorageAdapter;
@@ -25,6 +26,8 @@ exports.randomId = randomId;
25
26
  exports.EventEmitter = EventEmitter;
26
27
  exports.get = get;
27
28
  exports.serializeValue = serializeValue;
29
+ exports.reactiveOrAsync = reactiveOrAsync.default;
30
+ exports.unwrap = reactiveOrAsync.unwrap;
28
31
  exports.DefaultDataAdapter = DefaultDataAdapter;
29
32
  exports.AsyncDataAdapter = AsyncDataAdapter;
30
33
  exports.WorkerDataAdapter = WorkerDataAdapter;