@signaldb/core 2.0.0-beta.0 → 2.0.0-beta.10

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 (128) hide show
  1. package/dist/.vite/manifest.json +128 -75
  2. package/dist/AsyncDataAdapter.d.ts +44 -7
  3. package/dist/AutoFetchDataAdapter.d.ts +5 -8
  4. package/dist/Collection/Cursor.d.ts +6 -5
  5. package/dist/Collection/Observer.d.ts +2 -0
  6. package/dist/Collection/index.d.ts +36 -25
  7. package/dist/Collection/types.d.ts +10 -2
  8. package/dist/DataAdapter.d.ts +18 -11
  9. package/dist/DefaultDataAdapter.d.ts +7 -6
  10. package/dist/WorkerDataAdapter.d.ts +7 -6
  11. package/dist/WorkerDataAdapterHost.d.ts +14 -11
  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 +3 -1
  19. package/dist/index.mjs +17 -32
  20. package/dist/index10.cjs.js +23 -0
  21. package/dist/index10.mjs +21 -17
  22. package/dist/index11.cjs.js +45 -0
  23. package/dist/index11.mjs +44 -15
  24. package/dist/index12.cjs.js +22 -0
  25. package/dist/index12.mjs +21 -339
  26. package/dist/index13.cjs.js +45 -0
  27. package/dist/index13.mjs +44 -407
  28. package/dist/index14.cjs.js +86 -0
  29. package/dist/index14.mjs +85 -190
  30. package/dist/index15.cjs.js +15 -0
  31. package/dist/index15.mjs +14 -341
  32. package/dist/index16.cjs.js +136 -0
  33. package/dist/index16.mjs +134 -569
  34. package/dist/index17.cjs.js +47 -0
  35. package/dist/index17.mjs +46 -150
  36. package/dist/index18.cjs.js +15 -0
  37. package/dist/index18.mjs +14 -26
  38. package/dist/index19.cjs.js +23 -0
  39. package/dist/index19.mjs +22 -42
  40. package/dist/index2.cjs.js +33 -0
  41. package/dist/index2.mjs +32 -254
  42. package/dist/index20.cjs.js +37 -0
  43. package/dist/index20.mjs +36 -104
  44. package/dist/index21.cjs.js +35 -0
  45. package/dist/index21.mjs +34 -128
  46. package/dist/index22.cjs.js +25 -0
  47. package/dist/index22.mjs +24 -7
  48. package/dist/index23.cjs.js +19 -0
  49. package/dist/index23.mjs +17 -26
  50. package/dist/index24.cjs.js +342 -0
  51. package/dist/index24.mjs +340 -6
  52. package/dist/index25.cjs.js +542 -0
  53. package/dist/index25.mjs +541 -10
  54. package/dist/index26.cjs.js +11 -0
  55. package/dist/index26.mjs +10 -29
  56. package/dist/index27.cjs.js +11 -0
  57. package/dist/index27.mjs +10 -5
  58. package/dist/index28.cjs.js +90 -0
  59. package/dist/index28.mjs +89 -8
  60. package/dist/index29.cjs.js +424 -0
  61. package/dist/index29.mjs +423 -29
  62. package/dist/index3.cjs.js +19 -0
  63. package/dist/index3.mjs +18 -537
  64. package/dist/index30.cjs.js +72 -0
  65. package/dist/index30.mjs +71 -42
  66. package/dist/index31.cjs.js +191 -0
  67. package/dist/index31.mjs +190 -9
  68. package/dist/index32.cjs.js +21 -0
  69. package/dist/index32.mjs +21 -0
  70. package/dist/index33.cjs.js +336 -0
  71. package/dist/index33.mjs +336 -0
  72. package/dist/index34.cjs.js +539 -0
  73. package/dist/index34.mjs +539 -0
  74. package/dist/index4.cjs.js +150 -0
  75. package/dist/index4.mjs +149 -5
  76. package/dist/index5.cjs.js +254 -0
  77. package/dist/index5.mjs +252 -4
  78. package/dist/index6.cjs.js +125 -0
  79. package/dist/index6.mjs +124 -29
  80. package/dist/index7.cjs.js +33 -0
  81. package/dist/index7.mjs +32 -12
  82. package/dist/index8.cjs.js +12 -0
  83. package/dist/index8.mjs +10 -4
  84. package/dist/index9.cjs.js +11 -0
  85. package/dist/index9.mjs +10 -133
  86. package/dist/types/IndexProvider.d.ts +2 -2
  87. package/dist/types/Modifier.d.ts +1 -1
  88. package/dist/types/ReactivityAdapter.d.ts +1 -1
  89. package/dist/utils/batchOnNextTick.d.ts +16 -0
  90. package/dist/utils/createSignal.d.ts +2 -2
  91. package/dist/utils/deepClone.d.ts +1 -1
  92. package/dist/utils/getMatchingKeys.d.ts +2 -2
  93. package/dist/utils/isFieldExpression.d.ts +1 -1
  94. package/dist/utils/match.d.ts +1 -1
  95. package/dist/utils/modify.d.ts +1 -1
  96. package/dist/utils/queryId.d.ts +2 -2
  97. package/dist/utils/reactiveOrAsync.d.ts +59 -0
  98. package/package.json +3 -3
  99. package/dist/index.cjs10.js +0 -18
  100. package/dist/index.cjs11.js +0 -15
  101. package/dist/index.cjs12.js +0 -339
  102. package/dist/index.cjs13.js +0 -407
  103. package/dist/index.cjs14.js +0 -190
  104. package/dist/index.cjs15.js +0 -341
  105. package/dist/index.cjs16.js +0 -570
  106. package/dist/index.cjs17.js +0 -150
  107. package/dist/index.cjs18.js +0 -26
  108. package/dist/index.cjs19.js +0 -43
  109. package/dist/index.cjs2.js +0 -255
  110. package/dist/index.cjs20.js +0 -104
  111. package/dist/index.cjs21.js +0 -129
  112. package/dist/index.cjs22.js +0 -7
  113. package/dist/index.cjs23.js +0 -27
  114. package/dist/index.cjs24.js +0 -7
  115. package/dist/index.cjs25.js +0 -10
  116. package/dist/index.cjs26.js +0 -29
  117. package/dist/index.cjs27.js +0 -5
  118. package/dist/index.cjs28.js +0 -7
  119. package/dist/index.cjs29.js +0 -29
  120. package/dist/index.cjs3.js +0 -538
  121. package/dist/index.cjs30.js +0 -42
  122. package/dist/index.cjs31.js +0 -9
  123. package/dist/index.cjs4.js +0 -5
  124. package/dist/index.cjs5.js +0 -5
  125. package/dist/index.cjs6.js +0 -29
  126. package/dist/index.cjs7.js +0 -12
  127. package/dist/index.cjs8.js +0 -5
  128. package/dist/index.cjs9.js +0 -133
@@ -1,17 +1,16 @@
1
- import type ReactivityAdapter from '../types/ReactivityAdapter';
2
- import EventEmitter from '../utils/EventEmitter';
3
- import type Selector from '../types/Selector';
4
- import type Modifier from '../types/Modifier';
5
- import type DataAdapter from '../DataAdapter';
6
- import type { QueryOptions } from '../DataAdapter';
7
- import type StorageAdapter from '../types/StorageAdapter';
8
- import Cursor from './Cursor';
9
- import type { BaseItem, FindOptions, Transform } from './types';
10
- export type { BaseItem, Transform, SortSpecifier, FieldSpecifier, FindOptions } from './types';
1
+ import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
2
+ import { default as EventEmitter } from '../utils/EventEmitter';
3
+ import { default as Selector } from '../types/Selector';
4
+ import { default as Modifier } from '../types/Modifier';
5
+ import { default as DataAdapter, QueryOptions } from '../DataAdapter';
6
+ import { default as StorageAdapter } from '../types/StorageAdapter';
7
+ import { default as Cursor } from './Cursor';
8
+ import { AsyncFindOptions, BaseItem, FindOptions, SyncFindOptions, Transform, TransformAll } from './types';
9
+ export type { AnyFindOptions, AsyncFindOptions, BaseItem, Transform, TransformAll, SortSpecifier, FieldSpecifier, FindOptions, SyncFindOptions, } from './types';
11
10
  export type { CursorOptions } from './Cursor';
12
11
  export type { ObserveCallbacks } from './Observer';
13
12
  export { default as createIndex } from '../createIndex';
14
- export interface CollectionOptions<T extends BaseItem<I>, I, U = T> {
13
+ export interface CollectionOptions<T extends BaseItem<I>, I, E extends BaseItem = T, U = E> {
15
14
  /**
16
15
  * @deprecated Use new constructor parameters instead.
17
16
  */
@@ -22,19 +21,26 @@ export interface CollectionOptions<T extends BaseItem<I>, I, U = T> {
22
21
  persistence?: StorageAdapter<T, I>;
23
22
  primaryKeyGenerator?: (item: Omit<T, 'id'>) => I;
24
23
  reactivity?: ReactivityAdapter;
25
- transform?: Transform<T, U>;
24
+ transform?: Transform<E, U>;
25
+ transformAll?: TransformAll<T, E>;
26
26
  indices?: string[];
27
27
  enableDebugMode?: boolean;
28
28
  fieldTracking?: boolean;
29
29
  }
30
- interface CollectionEvents<T extends BaseItem, U = T> {
30
+ interface CollectionEvents<T extends BaseItem, E extends BaseItem = T, U = E> {
31
31
  'added': (item: T) => void;
32
32
  'changed': (item: T, modifier: Modifier<T>) => void;
33
33
  'removed': (item: T) => void;
34
34
  'observer.created': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
35
35
  'observer.disposed': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
36
+ /**
37
+ * A query backing at least one live cursor failed and will not deliver
38
+ * results. The cursor keeps returning its neutral empty value, so without
39
+ * listening here a consumer cannot distinguish failure from "no data".
40
+ */
41
+ 'query.error': <O extends QueryOptions<T>>(error: Error, selector?: Selector<T>, options?: O) => void;
36
42
  'getItems': (selector: Selector<T> | undefined) => void;
37
- 'find': <O extends FindOptions<T, Async>, Async extends boolean>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<T, U, Async>) => void;
43
+ 'find': <Async extends boolean, O extends FindOptions<T, Async>>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
38
44
  'findOne': <O extends QueryOptions<T>>(selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
39
45
  'insert': (item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
40
46
  'updateOne': (selector: Selector<T>, modifier: Modifier<T>) => void;
@@ -44,8 +50,8 @@ interface CollectionEvents<T extends BaseItem, U = T> {
44
50
  'removeMany': (selector: Selector<T>) => void;
45
51
  'validate': (item: T) => void;
46
52
  '_debug.getItems': (callstack: string, selector: Selector<T> | undefined, measuredTime: number) => void;
47
- '_debug.find': <O extends FindOptions<T, Async>, Async extends boolean>(callstack: string, selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<T, U, Async>) => void;
48
- '_debug.findOne': <O extends FindOptions<T, Async>, Async extends boolean>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
53
+ '_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;
54
+ '_debug.findOne': <Async extends boolean, O extends FindOptions<T, Async>>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
49
55
  '_debug.insert': (callstack: string, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
50
56
  '_debug.updateOne': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
51
57
  '_debug.updateMany': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
@@ -61,14 +67,14 @@ interface CollectionEvents<T extends BaseItem, U = T> {
61
67
  * @template I - The type of the unique identifier for the items.
62
68
  * @template U - The transformed item type after applying transformations (default is T).
63
69
  */
64
- export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T> extends EventEmitter<CollectionEvents<T, U>> {
70
+ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E extends BaseItem = T, U = E> extends EventEmitter<CollectionEvents<T, E, U>> {
65
71
  private static collections;
66
72
  private static debugMode;
67
73
  private static batchOperationInProgress;
68
74
  private static fieldTracking;
69
75
  private static onCreationCallbacks;
70
76
  private static onDisposeCallbacks;
71
- static getCollections(): Collection<any, any, any>[];
77
+ static getCollections(): Collection<any, any, any, any>[];
72
78
  static onCreation(callback: (collection: Collection<any>) => void): void;
73
79
  static onDispose(callback: (collection: Collection<any>) => void): void;
74
80
  /**
@@ -102,6 +108,7 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
102
108
  private isDisposed;
103
109
  private postBatchCallbacks;
104
110
  private fieldTracking;
111
+ private queryListenersMap;
105
112
  /**
106
113
  * Initializes a new instance of the `Collection` class with optional configuration.
107
114
  * Sets up memory, persistence, reactivity, and indices as specified in the options.
@@ -119,9 +126,10 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
119
126
  * @param options.indices - An array of index providers for optimized querying.
120
127
  * @param options.enableDebugMode - A boolean to enable or disable debug mode.
121
128
  * @param options.fieldTracking - A boolean to enable or disable field tracking by default.
129
+ * @param options.transformAll - A function that will be able to solve the n+1 problem
122
130
  */
123
- constructor(options?: CollectionOptions<T, I, U>);
124
- constructor(name: string, dataAdapter: DataAdapter, options?: CollectionOptions<T, I, U>);
131
+ constructor(options?: CollectionOptions<T, I, E, U>);
132
+ constructor(name: string, dataAdapter: DataAdapter, options?: CollectionOptions<T, I, E, U>);
125
133
  isBatchOperationInProgress(): boolean;
126
134
  /**
127
135
  * Checks whether the collection is currently performing a pull operation
@@ -183,9 +191,11 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
183
191
  private profile;
184
192
  private executeInDebugMode;
185
193
  private transform;
194
+ private transformAll;
186
195
  private getItem;
187
196
  private getItems;
188
197
  private withPushState;
198
+ private queryListeners;
189
199
  /**
190
200
  * Disposes the collection, unregisters persistence adapters, clears memory, and
191
201
  * cleans up all resources used by the collection.
@@ -195,23 +205,24 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
195
205
  /**
196
206
  * Finds multiple items in the collection based on a selector and optional options.
197
207
  * Returns a cursor for reactive data queries.
198
- * @template O - The options type for the find operation.
199
208
  * @param [selector] - The criteria to select items.
200
209
  * @param [options] - Options for the find operation, such as limit and sort.
201
210
  * @returns A cursor to fetch and observe the matching items.
202
211
  */
203
- find<Async extends boolean = false, O extends FindOptions<T, Async> = FindOptions<T, Async>>(selector?: Selector<T>, options?: O): Cursor<T, U, Async>;
212
+ find(selector?: Selector<T>, options?: SyncFindOptions<T>): Cursor<E, U, false>;
213
+ find(selector: Selector<T> | undefined, options: AsyncFindOptions<T>): Cursor<E, U, true>;
214
+ find(selector?: Selector<T>, options?: FindOptions<T, boolean>): Cursor<E, U, boolean>;
204
215
  /**
205
216
  * Finds a single item in the collection based on a selector and optional options.
206
217
  * ⚡️ this function is reactive!
207
218
  * Returns the found item or undefined if no item matches.
208
- * @template Async - Whether to perform the operation asynchronously.
209
- * @template O - The options type for the find operation.
210
219
  * @param selector - The criteria to select the item.
211
220
  * @param [options] - Options for the find operation, such as projection.
212
221
  * @returns The found item or `undefined`.
213
222
  */
214
- 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;
223
+ findOne(selector: Selector<T>, options?: Omit<SyncFindOptions<T>, 'limit'>): U | undefined;
224
+ findOne(selector: Selector<T>, options: Omit<AsyncFindOptions<T>, 'limit'>): Promise<U | undefined>;
225
+ findOne(selector: Selector<T>, options?: Omit<FindOptions<T, boolean>, 'limit'>): Promise<U | undefined> | U | undefined;
215
226
  /**
216
227
  * Performs a batch operation, deferring index rebuilds and allowing multiple
217
228
  * modifications to be made atomically. Executes any post-batch callbacks afterwards.
@@ -1,9 +1,10 @@
1
- import type { QueryOptions } from '../DataAdapter';
2
- import type ReactivityAdapter from '../types/ReactivityAdapter';
1
+ import { QueryOptions } from '../DataAdapter';
2
+ import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
3
3
  export type BaseItem<I = any> = {
4
4
  id: I;
5
5
  } & Record<string, any>;
6
6
  export type Transform<T, U = T> = ((document: T) => U) | null | undefined;
7
+ export type TransformAll<T extends BaseItem, O extends BaseItem = T> = ((items: T[], fields: FieldSpecifier<O> | undefined) => O[]) | null | undefined;
7
8
  export type SortSpecifier<T> = {
8
9
  [P in keyof T]?: -1 | 1;
9
10
  } & Record<string, -1 | 1>;
@@ -18,3 +19,10 @@ export interface FindOptions<T extends BaseItem, Async extends boolean> extends
18
19
  /** pass `true` to execute the query asynchronously */
19
20
  async?: Async;
20
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>;
@@ -1,7 +1,6 @@
1
- import type { BaseItem, FieldSpecifier, SortSpecifier } from './Collection';
2
- import type Collection from './Collection';
3
- import type Modifier from './types/Modifier';
4
- import type Selector from './types/Selector';
1
+ import { BaseItem, FieldSpecifier, SortSpecifier, default as Collection } from './Collection';
2
+ import { default as Modifier } from './types/Modifier';
3
+ import { default as Selector } from './types/Selector';
5
4
  export interface QueryOptions<T extends BaseItem> {
6
5
  /** Sort order (default: natural order) */
7
6
  sort?: SortSpecifier<T> | undefined;
@@ -12,6 +11,7 @@ export interface QueryOptions<T extends BaseItem> {
12
11
  /** Dictionary of fields to return or exclude. */
13
12
  fields?: FieldSpecifier<T> | undefined;
14
13
  }
14
+ export type StateChangeCallback = (state: 'active' | 'complete' | 'error') => void;
15
15
  export interface CollectionBackend<T extends BaseItem<I>, I> {
16
16
  insert(item: T): Promise<T>;
17
17
  updateOne(selector: Selector<T>, modifier: Modifier<T>): Promise<T[]>;
@@ -19,15 +19,22 @@ export interface CollectionBackend<T extends BaseItem<I>, I> {
19
19
  replaceOne(selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): Promise<T[]>;
20
20
  removeOne(selector: Selector<T>): Promise<T[]>;
21
21
  removeMany(selector: Selector<T>): Promise<T[]>;
22
- registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options?: O): void;
23
- unregisterQuery<O extends QueryOptions<T>>(selector: Selector<T>, options?: O): void;
24
- getQueryState<O extends QueryOptions<T>>(selector: Selector<T>, options?: O): 'active' | 'complete' | 'error';
25
- getQueryError<O extends QueryOptions<T>>(selector: Selector<T>, options?: O): Error | null;
26
- getQueryResult<O extends QueryOptions<T>>(selector: Selector<T>, options?: O): T[];
27
- onQueryStateChange<O extends QueryOptions<T>>(selector: Selector<T> | undefined, options: O | undefined, callback: (state: 'active' | 'complete' | 'error') => void): () => void;
22
+ registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
23
+ unregisterQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
24
+ /**
25
+ * Re-runs a query that is currently in the `'error'` state. Optional so
26
+ * existing custom adapters keep compiling — an adapter that never surfaces
27
+ * an error state has nothing to implement.
28
+ */
29
+ retryQuery?<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
30
+ getQueryState<O extends QueryOptions<T>>(selector: Selector<T>, options: O): 'active' | 'complete' | 'error';
31
+ getQueryError<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Error | null;
32
+ getQueryResult<O extends QueryOptions<T>>(selector: Selector<T>, options: O): T[];
33
+ executeQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Promise<T[]>;
34
+ onQueryStateChange<O extends QueryOptions<T>>(selector: Selector<T>, options: O, callback: StateChangeCallback): () => void;
28
35
  dispose(): Promise<void>;
29
36
  isReady(): Promise<void>;
30
37
  }
31
38
  export default interface DataAdapter {
32
- createCollectionBackend<T extends BaseItem<I>, I = any, U = T>(collection: Collection<T, I, U>, indices: string[]): CollectionBackend<T, I>;
39
+ 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
40
  }
@@ -1,8 +1,6 @@
1
- import type { BaseItem } from './Collection';
2
- import type Collection from './Collection';
3
- import type DataAdapter from './DataAdapter';
4
- import type { CollectionBackend } from './DataAdapter';
5
- import type StorageAdapter from './types/StorageAdapter';
1
+ import { BaseItem, default as Collection } from './Collection';
2
+ import { default as DataAdapter, CollectionBackend } from './DataAdapter';
3
+ import { default as StorageAdapter } from './types/StorageAdapter';
6
4
  interface DefaultDataAdapterOptions {
7
5
  storage?: (name: string) => StorageAdapter<any, any> | undefined;
8
6
  onError?: (name: string, error: Error) => void;
@@ -11,6 +9,7 @@ export default class DefaultDataAdapter implements DataAdapter {
11
9
  private items;
12
10
  private options;
13
11
  private storageAdapters;
12
+ private collections;
14
13
  private indices;
15
14
  private activeQueries;
16
15
  private queryEmitters;
@@ -26,7 +25,9 @@ export default class DefaultDataAdapter implements DataAdapter {
26
25
  private queryItems;
27
26
  private executeQuery;
28
27
  private flushQueuedQueryUpdates;
28
+ private executeAndCacheQuery;
29
29
  private updateQueries;
30
- createCollectionBackend<T extends BaseItem<I>, I = any, U = T>(collection: Collection<T, I, U>, indices: string[]): CollectionBackend<T, I>;
30
+ createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
31
+ fetchItemsFromStorage<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection?: Collection<T, I, E, U>): Promise<void>;
31
32
  }
32
33
  export {};
@@ -1,9 +1,8 @@
1
- import type { BaseItem } from './Collection';
2
- import type Collection from './Collection';
3
- import type DataAdapter from './DataAdapter';
4
- import type { CollectionBackend } from './DataAdapter';
1
+ import { BaseItem, default as Collection } from './Collection';
2
+ import { default as DataAdapter, CollectionBackend } from './DataAdapter';
5
3
  interface WorkerDataAdapterOptions {
6
4
  id?: string;
5
+ log?: (message: string, ...args: any[]) => void;
7
6
  }
8
7
  export default class WorkerDataAdapter implements DataAdapter {
9
8
  private worker;
@@ -11,12 +10,14 @@ export default class WorkerDataAdapter implements DataAdapter {
11
10
  private id;
12
11
  private isDisposed;
13
12
  private workerReady;
13
+ private log;
14
14
  private collectionReady;
15
+ private batchExecutionHelpers;
15
16
  private queries;
16
17
  constructor(worker: Worker, options: WorkerDataAdapterOptions);
17
18
  private exec;
18
- private queryListeners;
19
+ private enqueueBatched;
19
20
  private updateQuery;
20
- createCollectionBackend<T extends BaseItem<I>, I = any, U = T>(collection: Collection<T, I, U>, indices?: string[]): CollectionBackend<T, I>;
21
+ createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
21
22
  }
22
23
  export {};
@@ -1,8 +1,8 @@
1
- import type { BaseItem } from './Collection';
2
- import type { QueryOptions } from './DataAdapter';
3
- import type Modifier from './types/Modifier';
4
- import type StorageAdapter from './types/StorageAdapter';
5
- import type Selector from './types/Selector';
1
+ import { BaseItem } from './Collection';
2
+ import { QueryOptions } from './DataAdapter';
3
+ import { default as Modifier } from './types/Modifier';
4
+ import { default as StorageAdapter } from './types/StorageAdapter';
5
+ import { default as Selector } from './types/Selector';
6
6
  interface WorkerContext {
7
7
  addEventListener: (type: 'message', listener: (event: MessageEvent) => any) => void;
8
8
  postMessage: (message: any) => void;
@@ -11,24 +11,27 @@ interface WorkerDataAdapterHostOptions {
11
11
  id?: string;
12
12
  storage: (name: string) => StorageAdapter<any, any>;
13
13
  onError?: (error: Error) => void;
14
+ log?: (message: string, ...args: any[]) => void;
14
15
  }
15
16
  type CollectionMethods<T extends BaseItem<I>, I = any> = {
16
17
  registerCollection: (collectionName: string, indices: string[]) => Promise<void>;
17
18
  unregisterCollection: (collectionName: string) => Promise<void>;
18
19
  registerQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
19
20
  unregisterQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
20
- insert: (collectionName: string, item: T) => Promise<T>;
21
- updateOne: (collectionName: string, selector: Selector<T>, modifier: Modifier<T>) => Promise<T[]>;
22
- updateMany: (collectionName: string, selector: Selector<T>, modifier: Modifier<T>) => Promise<T[]>;
23
- replaceOne: (collectionName: string, selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => Promise<T[]>;
24
- removeOne: (collectionName: string, selector: Selector<T>) => Promise<T[]>;
25
- removeMany: (collectionName: string, selector: Selector<T>) => Promise<T[]>;
21
+ executeQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<T[]>;
22
+ insert: (collectionName: string, items: [T][]) => Promise<(T | Error)[]>;
23
+ updateOne: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(T[] | Error)[]>;
24
+ updateMany: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(T[] | Error)[]>;
25
+ replaceOne: (collectionName: string, args: [Selector<T>, Omit<T, 'id'> & Partial<Pick<T, 'id'>>][]) => Promise<(T[] | Error)[]>;
26
+ removeOne: (collectionName: string, selectors: [Selector<T>][]) => Promise<(T[] | Error)[]>;
27
+ removeMany: (collectionName: string, selectors: [Selector<T>][]) => Promise<(T[] | Error)[]>;
26
28
  isReady: (collectionName: string) => Promise<void>;
27
29
  };
28
30
  export default class WorkerDataAdapterHost<T extends BaseItem<I>, I = any> {
29
31
  private workerContext;
30
32
  private options;
31
33
  private id;
34
+ private log;
32
35
  private storageAdapters;
33
36
  private storageAdapterReady;
34
37
  private collectionIndices;
@@ -1,7 +1,7 @@
1
- import type { BaseItem } from './Collection/types';
1
+ import { BaseItem } from './Collection/types';
2
2
  /**
3
3
  * creates an index for a specific field
4
4
  * @param field name of the field
5
5
  * @returns an index provider to pass to the `indices` option of the collection constructor
6
6
  */
7
- export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import("./types/IndexProvider").default<T, I>;
7
+ export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import('./types/IndexProvider').default<T, I>;
@@ -1,5 +1,5 @@
1
- import type { BaseItem } from './Collection';
2
- import type IndexProvider from './types/IndexProvider';
1
+ import { BaseItem } from './Collection';
2
+ import { default as IndexProvider } from './types/IndexProvider';
3
3
  /**
4
4
  * Creates an IndexProvider based on the given definition.
5
5
  * @param definition - The definition of the IndexProvider.
@@ -1,5 +1,5 @@
1
- import type Dependency from './types/Dependency';
2
- import type ReactivityAdapter from './types/ReactivityAdapter';
1
+ import { default as Dependency } from './types/Dependency';
2
+ import { default as ReactivityAdapter } from './types/ReactivityAdapter';
3
3
  /**
4
4
  * Creates an ReactivityAdapter based on the given definition.
5
5
  * @param definition - The definition of the ReactivityAdapter.
@@ -1,4 +1,4 @@
1
- import type StorageAdapter from './types/StorageAdapter';
1
+ import { default as StorageAdapter } from './types/StorageAdapter';
2
2
  /**
3
3
  * Creates an StorageAdapter based on the given definition.
4
4
  * @param definition - The definition of the StorageAdapter.
@@ -1,7 +1,6 @@
1
- import type { AsynchronousQueryFunction, SynchronousQueryFunction } from './types/IndexProvider';
2
- import type { FlatSelector } from './types/Selector';
3
- import type Selector from './types/Selector';
4
- import type { BaseItem } from './Collection/types';
1
+ import { AsynchronousQueryFunction, SynchronousQueryFunction } from './types/IndexProvider';
2
+ import { FlatSelector, default as Selector } from './types/Selector';
3
+ import { BaseItem } from './Collection/types';
5
4
  type IndexInfo<T extends BaseItem<I> = BaseItem, I = any> = {
6
5
  matched: boolean;
7
6
  ids: I[];
package/dist/index.cjs.js CHANGED
@@ -1,32 +1,34 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const Cursor = require("./index.cjs2.js");
4
- const index = require("./index.cjs3.js");
5
- const createStorageAdapter = require("./index.cjs4.js");
6
- const createReactivityAdapter = require("./index.cjs5.js");
7
- const isEqual = require("./index.cjs6.js");
8
- const modify = require("./index.cjs7.js");
9
- const randomId = require("./index.cjs8.js");
10
- const EventEmitter = require("./index.cjs9.js");
11
- const get = require("./index.cjs10.js");
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");
18
- exports.Cursor = Cursor.default;
19
- exports.Collection = index.default;
20
- exports.createStorageAdapter = createStorageAdapter;
21
- exports.createReactivityAdapter = createReactivityAdapter;
22
- exports.isEqual = isEqual;
23
- exports.modify = modify;
24
- exports.randomId = randomId;
25
- exports.EventEmitter = EventEmitter;
26
- exports.get = get;
27
- exports.serializeValue = serializeValue;
28
- exports.DefaultDataAdapter = DefaultDataAdapter;
29
- exports.AsyncDataAdapter = AsyncDataAdapter;
30
- exports.WorkerDataAdapter = WorkerDataAdapter;
31
- exports.WorkerDataAdapterHost = WorkerDataAdapterHost;
32
- exports.AutoFetchDataAdapter = AutoFetchDataAdapter;
2
+ const require_isEqual = require("./index2.cjs.js");
3
+ const require_Cursor = require("./index5.cjs.js");
4
+ const require_EventEmitter = require("./index6.cjs.js");
5
+ const require_randomId = require("./index8.cjs.js");
6
+ const require_get = require("./index10.cjs.js");
7
+ const require_serializeValue = require("./index12.cjs.js");
8
+ const require_modify = require("./index19.cjs.js");
9
+ const require_DefaultDataAdapter = require("./index24.cjs.js");
10
+ const require_index = require("./index25.cjs.js");
11
+ const require_createStorageAdapter = require("./index26.cjs.js");
12
+ const require_createReactivityAdapter = require("./index27.cjs.js");
13
+ const require_reactiveOrAsync = require("./index28.cjs.js");
14
+ const require_AsyncDataAdapter = require("./index29.cjs.js");
15
+ const require_WorkerDataAdapter = require("./index31.cjs.js");
16
+ const require_WorkerDataAdapterHost = require("./index33.cjs.js");
17
+ const require_AutoFetchDataAdapter = require("./index34.cjs.js");
18
+ exports.AsyncDataAdapter = require_AsyncDataAdapter.default;
19
+ exports.AutoFetchDataAdapter = require_AutoFetchDataAdapter.default;
20
+ exports.Collection = require_index.default;
21
+ exports.Cursor = require_Cursor.default;
22
+ exports.DefaultDataAdapter = require_DefaultDataAdapter.default;
23
+ exports.EventEmitter = require_EventEmitter.default;
24
+ exports.WorkerDataAdapter = require_WorkerDataAdapter.default;
25
+ exports.WorkerDataAdapterHost = require_WorkerDataAdapterHost.default;
26
+ exports.createReactivityAdapter = require_createReactivityAdapter.default;
27
+ exports.createStorageAdapter = require_createStorageAdapter.default;
28
+ exports.get = require_get.default;
29
+ exports.isEqual = require_isEqual.default;
30
+ exports.modify = require_modify.default;
31
+ exports.randomId = require_randomId.default;
32
+ exports.reactiveOrAsync = require_reactiveOrAsync.default;
33
+ exports.serializeValue = require_serializeValue.default;
34
+ exports.unwrap = require_reactiveOrAsync.unwrap;
package/dist/index.d.ts CHANGED
@@ -2,7 +2,8 @@ export type { default as ReactivityAdapter } from './types/ReactivityAdapter';
2
2
  export type { default as StorageAdapter, Changeset, } from './types/StorageAdapter';
3
3
  export type { default as Selector } from './types/Selector';
4
4
  export type { default as Modifier } from './types/Modifier';
5
- export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, SortSpecifier, FieldSpecifier, FindOptions, CollectionOptions, } from './Collection';
5
+ export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, TransformAll, SortSpecifier, FieldSpecifier, AnyFindOptions, AsyncFindOptions, FindOptions, SyncFindOptions, CollectionOptions, } from './Collection';
6
+ export type { default as DataAdapter } from './DataAdapter';
6
7
  export { default as Cursor } from './Collection/Cursor';
7
8
  export { default as Collection } from './Collection';
8
9
  export { default as createStorageAdapter } from './createStorageAdapter';
@@ -13,6 +14,7 @@ export { default as randomId } from './utils/randomId';
13
14
  export { default as EventEmitter } from './utils/EventEmitter';
14
15
  export { default as get } from './utils/get';
15
16
  export { default as serializeValue } from './utils/serializeValue';
17
+ export { default as reactiveOrAsync, unwrap } from './utils/reactiveOrAsync';
16
18
  export { default as DefaultDataAdapter } from './DefaultDataAdapter';
17
19
  export { default as AsyncDataAdapter } from './AsyncDataAdapter';
18
20
  export { default as WorkerDataAdapter } from './WorkerDataAdapter';
package/dist/index.mjs CHANGED
@@ -1,32 +1,17 @@
1
- import { default as default2 } from "./index2.mjs";
2
- import { default as default3 } from "./index3.mjs";
3
- import { default as default4 } from "./index4.mjs";
4
- import { default as default5 } from "./index5.mjs";
5
- import { default as default6 } from "./index6.mjs";
6
- import { default as default7 } from "./index7.mjs";
7
- import { default as default8 } from "./index8.mjs";
8
- import { default as default9 } from "./index9.mjs";
9
- import { default as default10 } from "./index10.mjs";
10
- import { default as default11 } from "./index11.mjs";
11
- import { default as default12 } from "./index12.mjs";
12
- import { default as default13 } from "./index13.mjs";
13
- import { default as default14 } from "./index14.mjs";
14
- import { default as default15 } from "./index15.mjs";
15
- import { default as default16 } from "./index16.mjs";
16
- export {
17
- default13 as AsyncDataAdapter,
18
- default16 as AutoFetchDataAdapter,
19
- default3 as Collection,
20
- default2 as Cursor,
21
- default12 as DefaultDataAdapter,
22
- default9 as EventEmitter,
23
- default14 as WorkerDataAdapter,
24
- default15 as WorkerDataAdapterHost,
25
- default5 as createReactivityAdapter,
26
- default4 as createStorageAdapter,
27
- default10 as get,
28
- default6 as isEqual,
29
- default7 as modify,
30
- default8 as randomId,
31
- default11 as serializeValue
32
- };
1
+ import isEqual from "./index2.mjs";
2
+ import Cursor from "./index5.mjs";
3
+ import EventEmitter from "./index6.mjs";
4
+ import randomId from "./index8.mjs";
5
+ import get from "./index10.mjs";
6
+ import serializeValue from "./index12.mjs";
7
+ import modify from "./index19.mjs";
8
+ import DefaultDataAdapter from "./index24.mjs";
9
+ import Collection from "./index25.mjs";
10
+ import createStorageAdapter from "./index26.mjs";
11
+ import createReactivityAdapter from "./index27.mjs";
12
+ import reactiveOrAsync, { unwrap } from "./index28.mjs";
13
+ import AsyncDataAdapter from "./index29.mjs";
14
+ import WorkerDataAdapter from "./index31.mjs";
15
+ import WorkerDataAdapterHost from "./index33.mjs";
16
+ import AutoFetchDataAdapter from "./index34.mjs";
17
+ export { AsyncDataAdapter, AutoFetchDataAdapter, Collection, Cursor, DefaultDataAdapter, EventEmitter, WorkerDataAdapter, WorkerDataAdapterHost, createReactivityAdapter, createStorageAdapter, get, isEqual, modify, randomId, reactiveOrAsync, serializeValue, unwrap };
@@ -0,0 +1,23 @@
1
+ //#region src/utils/get.ts
2
+ /**
3
+ * Retrieves the value at a specified path within an object.
4
+ * Supports dot and bracket notation for navigating nested properties.
5
+ * @template T - The type of the object to retrieve the value from.
6
+ * @param value - The object to navigate.
7
+ * @param path - The path (dot or bracket notation) to the desired value.
8
+ * @returns The value at the specified path, or `undefined` if the path does not exist.
9
+ */
10
+ function get(value, path) {
11
+ const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
12
+ if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) return;
13
+ const segments = normalized.split(".");
14
+ let current = value;
15
+ for (const key of segments) {
16
+ if (current == null) return;
17
+ current = current[key];
18
+ }
19
+ if (current === void 0) return;
20
+ return current;
21
+ }
22
+ //#endregion
23
+ exports.default = get;
package/dist/index10.mjs CHANGED
@@ -1,19 +1,23 @@
1
+ //#region src/utils/get.ts
2
+ /**
3
+ * Retrieves the value at a specified path within an object.
4
+ * Supports dot and bracket notation for navigating nested properties.
5
+ * @template T - The type of the object to retrieve the value from.
6
+ * @param value - The object to navigate.
7
+ * @param path - The path (dot or bracket notation) to the desired value.
8
+ * @returns The value at the specified path, or `undefined` if the path does not exist.
9
+ */
1
10
  function get(value, path) {
2
- const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
3
- if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) {
4
- return;
5
- }
6
- const segments = normalized.split(".");
7
- let current = value;
8
- for (const key of segments) {
9
- if (current == null)
10
- return;
11
- current = current[key];
12
- }
13
- if (current === void 0)
14
- return;
15
- return current;
11
+ const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
12
+ if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) return;
13
+ const segments = normalized.split(".");
14
+ let current = value;
15
+ for (const key of segments) {
16
+ if (current == null) return;
17
+ current = current[key];
18
+ }
19
+ if (current === void 0) return;
20
+ return current;
16
21
  }
17
- export {
18
- get as default
19
- };
22
+ //#endregion
23
+ export { get as default };