@signaldb/core 1.0.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 (102) hide show
  1. package/README.md +68 -0
  2. package/dist/.vite/manifest.json +222 -0
  3. package/dist/AutoFetchCollection.d.ts +60 -0
  4. package/dist/Collection/Cursor.d.ts +112 -0
  5. package/dist/Collection/Observer.d.ts +61 -0
  6. package/dist/Collection/createIndex.d.ts +15 -0
  7. package/dist/Collection/getIndexInfo.d.ts +41 -0
  8. package/dist/Collection/index.d.ts +235 -0
  9. package/dist/Collection/types.d.ts +25 -0
  10. package/dist/ReplicatedCollection.d.ts +60 -0
  11. package/dist/createIndexProvider.d.ts +8 -0
  12. package/dist/createMemoryAdapter.d.ts +7 -0
  13. package/dist/createReactivityAdapter.d.ts +8 -0
  14. package/dist/index.cjs.js +24 -0
  15. package/dist/index.cjs10.js +8 -0
  16. package/dist/index.cjs11.js +5 -0
  17. package/dist/index.cjs12.js +37 -0
  18. package/dist/index.cjs13.js +26 -0
  19. package/dist/index.cjs14.js +7 -0
  20. package/dist/index.cjs15.js +43 -0
  21. package/dist/index.cjs16.js +13 -0
  22. package/dist/index.cjs17.js +20 -0
  23. package/dist/index.cjs18.js +247 -0
  24. package/dist/index.cjs19.js +71 -0
  25. package/dist/index.cjs2.js +631 -0
  26. package/dist/index.cjs20.js +80 -0
  27. package/dist/index.cjs21.js +10 -0
  28. package/dist/index.cjs22.js +27 -0
  29. package/dist/index.cjs23.js +137 -0
  30. package/dist/index.cjs24.js +18 -0
  31. package/dist/index.cjs25.js +7 -0
  32. package/dist/index.cjs26.js +19 -0
  33. package/dist/index.cjs27.js +24 -0
  34. package/dist/index.cjs28.js +42 -0
  35. package/dist/index.cjs29.js +29 -0
  36. package/dist/index.cjs3.js +165 -0
  37. package/dist/index.cjs30.js +9 -0
  38. package/dist/index.cjs4.js +70 -0
  39. package/dist/index.cjs5.js +5 -0
  40. package/dist/index.cjs6.js +5 -0
  41. package/dist/index.cjs7.js +5 -0
  42. package/dist/index.cjs8.js +5 -0
  43. package/dist/index.cjs9.js +30 -0
  44. package/dist/index.d.ts +16 -0
  45. package/dist/index.mjs +24 -0
  46. package/dist/index10.mjs +9 -0
  47. package/dist/index11.mjs +6 -0
  48. package/dist/index12.mjs +37 -0
  49. package/dist/index13.mjs +27 -0
  50. package/dist/index14.mjs +8 -0
  51. package/dist/index15.mjs +43 -0
  52. package/dist/index16.mjs +14 -0
  53. package/dist/index17.mjs +21 -0
  54. package/dist/index18.mjs +247 -0
  55. package/dist/index19.mjs +71 -0
  56. package/dist/index2.mjs +632 -0
  57. package/dist/index20.mjs +80 -0
  58. package/dist/index21.mjs +11 -0
  59. package/dist/index22.mjs +28 -0
  60. package/dist/index23.mjs +138 -0
  61. package/dist/index24.mjs +18 -0
  62. package/dist/index25.mjs +8 -0
  63. package/dist/index26.mjs +20 -0
  64. package/dist/index27.mjs +25 -0
  65. package/dist/index28.mjs +43 -0
  66. package/dist/index29.mjs +30 -0
  67. package/dist/index3.mjs +166 -0
  68. package/dist/index30.mjs +10 -0
  69. package/dist/index4.mjs +70 -0
  70. package/dist/index5.mjs +6 -0
  71. package/dist/index6.mjs +6 -0
  72. package/dist/index7.mjs +6 -0
  73. package/dist/index8.mjs +6 -0
  74. package/dist/index9.mjs +31 -0
  75. package/dist/persistence/combinePersistenceAdapters.d.ts +32 -0
  76. package/dist/persistence/createPersistenceAdapter.d.ts +9 -0
  77. package/dist/types/Dependency.d.ts +4 -0
  78. package/dist/types/EventEmitter.d.ts +25 -0
  79. package/dist/types/IndexProvider.d.ts +19 -0
  80. package/dist/types/MemoryAdapter.d.ts +15 -0
  81. package/dist/types/Modifier.d.ts +39 -0
  82. package/dist/types/PersistenceAdapter.d.ts +20 -0
  83. package/dist/types/ReactivityAdapter.d.ts +6 -0
  84. package/dist/types/Selector.d.ts +47 -0
  85. package/dist/types/Signal.d.ts +4 -0
  86. package/dist/utils/compact.d.ts +9 -0
  87. package/dist/utils/createSignal.d.ts +14 -0
  88. package/dist/utils/deepClone.d.ts +17 -0
  89. package/dist/utils/get.d.ts +9 -0
  90. package/dist/utils/getMatchingKeys.d.ts +14 -0
  91. package/dist/utils/intersection.d.ts +9 -0
  92. package/dist/utils/isEqual.d.ts +14 -0
  93. package/dist/utils/isFieldExpression.d.ts +11 -0
  94. package/dist/utils/match.d.ts +12 -0
  95. package/dist/utils/modify.d.ts +14 -0
  96. package/dist/utils/project.d.ts +15 -0
  97. package/dist/utils/randomId.d.ts +7 -0
  98. package/dist/utils/serializeValue.d.ts +12 -0
  99. package/dist/utils/set.d.ts +13 -0
  100. package/dist/utils/sortItems.d.ts +12 -0
  101. package/dist/utils/uniqueBy.d.ts +10 -0
  102. package/package.json +58 -0
@@ -0,0 +1,235 @@
1
+ import type MemoryAdapter from '../types/MemoryAdapter';
2
+ import type ReactivityAdapter from '../types/ReactivityAdapter';
3
+ import type PersistenceAdapter from '../types/PersistenceAdapter';
4
+ import EventEmitter from '../types/EventEmitter';
5
+ import type Selector from '../types/Selector';
6
+ import type Modifier from '../types/Modifier';
7
+ import type IndexProvider from '../types/IndexProvider';
8
+ import Cursor from './Cursor';
9
+ import type { BaseItem, FindOptions, Transform } from './types';
10
+ export type { BaseItem, Transform, SortSpecifier, FieldSpecifier, FindOptions } from './types';
11
+ export type { CursorOptions } from './Cursor';
12
+ export type { ObserveCallbacks } from './Observer';
13
+ export { default as createIndex } from './createIndex';
14
+ export interface CollectionOptions<T extends BaseItem<I>, I, U = T> {
15
+ memory?: MemoryAdapter;
16
+ reactivity?: ReactivityAdapter;
17
+ transform?: Transform<T, U>;
18
+ persistence?: PersistenceAdapter<T, I>;
19
+ indices?: IndexProvider<T, I>[];
20
+ enableDebugMode?: boolean;
21
+ fieldTracking?: boolean;
22
+ }
23
+ interface CollectionEvents<T extends BaseItem, U = T> {
24
+ added: (item: T) => void;
25
+ changed: (item: T, modifier: Modifier<T>) => void;
26
+ removed: (item: T) => void;
27
+ 'persistence.init': () => void;
28
+ 'persistence.error': (error: Error) => void;
29
+ 'persistence.transmitted': () => void;
30
+ 'persistence.received': () => void;
31
+ 'persistence.pullStarted': () => void;
32
+ 'persistence.pullCompleted': () => void;
33
+ 'persistence.pushStarted': () => void;
34
+ 'persistence.pushCompleted': () => void;
35
+ 'observer.created': <O extends FindOptions<T>>(selector?: Selector<T>, options?: O) => void;
36
+ 'observer.disposed': <O extends FindOptions<T>>(selector?: Selector<T>, options?: O) => void;
37
+ getItems: (selector: Selector<T> | undefined) => void;
38
+ find: <O extends FindOptions<T>>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<T, U>) => void;
39
+ findOne: <O extends FindOptions<T>>(selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
40
+ insert: (item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
41
+ updateOne: (selector: Selector<T>, modifier: Modifier<T>) => void;
42
+ updateMany: (selector: Selector<T>, modifier: Modifier<T>) => void;
43
+ removeOne: (selector: Selector<T>) => void;
44
+ removeMany: (selector: Selector<T>) => void;
45
+ '_debug.getItems': (callstack: string, selector: Selector<T> | undefined, measuredTime: number) => void;
46
+ '_debug.find': <O extends FindOptions<T>>(callstack: string, selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<T, U>) => void;
47
+ '_debug.findOne': <O extends FindOptions<T>>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
48
+ '_debug.insert': (callstack: string, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
49
+ '_debug.updateOne': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
50
+ '_debug.updateMany': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
51
+ '_debug.removeOne': (callstack: string, selector: Selector<T>) => void;
52
+ '_debug.removeMany': (callstack: string, selector: Selector<T>) => void;
53
+ }
54
+ /**
55
+ * Represents a collection of data items with support for in-memory operations,
56
+ * persistence, reactivity, and event-based notifications. The collection provides
57
+ * CRUD operations, observer patterns, and batch operations.
58
+ * @template T - The type of the items stored in the collection.
59
+ * @template I - The type of the unique identifier for the items.
60
+ * @template U - The transformed item type after applying transformations (default is T).
61
+ */
62
+ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T> extends EventEmitter<CollectionEvents<T, U>> {
63
+ static collections: Collection<any, any>[];
64
+ static debugMode: boolean;
65
+ static batchOperationInProgress: boolean;
66
+ static fieldTracking: boolean;
67
+ /**
68
+ * Enables debug mode for all collections.
69
+ */
70
+ static enableDebugMode: () => void;
71
+ /**
72
+ * Enables field tracking for all collections.
73
+ * @param enable - A boolean indicating whether to enable field tracking.
74
+ */
75
+ static setFieldTracking: (enable: boolean) => void;
76
+ /**
77
+ * Executes a batch operation, allowing multiple modifications to the collection
78
+ * while deferring index rebuilding until all operations in the batch are completed.
79
+ * This improves performance by avoiding repetitive index recalculations and
80
+ * provides atomicity for the batch of operations.
81
+ * @param callback - The batch operation to execute.
82
+ */
83
+ static batch(callback: () => void): void;
84
+ private options;
85
+ private persistenceAdapter;
86
+ private isPullingSignal;
87
+ private isPushingSignal;
88
+ private indexProviders;
89
+ private indicesOutdated;
90
+ private idIndex;
91
+ private debugMode;
92
+ private batchOperationInProgress;
93
+ private isDisposed;
94
+ private postBatchCallbacks;
95
+ private fieldTracking;
96
+ /**
97
+ * Initializes a new instance of the `Collection` class with optional configuration.
98
+ * Sets up memory, persistence, reactivity, and indices as specified in the options.
99
+ * @template T - The type of the items stored in the collection.
100
+ * @template I - The type of the unique identifier for the items.
101
+ * @template U - The transformed item type after applying transformations (default is T).
102
+ * @param options - Optional configuration for the collection.
103
+ * @param options.memory - The in-memory adapter for storing items.
104
+ * @param options.reactivity - The reactivity adapter for observing changes in the collection.
105
+ * @param options.transform - A transformation function to apply to items when retrieving them.
106
+ * @param options.persistence - The persistence adapter for saving and loading items.
107
+ * @param options.indices - An array of index providers for optimized querying.
108
+ * @param options.enableDebugMode - A boolean to enable or disable debug mode.
109
+ * @param options.fieldTracking - A boolean to enable or disable field tracking by default.
110
+ */
111
+ constructor(options?: CollectionOptions<T, I, U>);
112
+ /**
113
+ * Checks whether the collection is currently performing a pull operation
114
+ * ⚡️ this function is reactive!
115
+ * (loading data from the persistence adapter).
116
+ * @returns A boolean indicating if the collection is in the process of pulling data.
117
+ */
118
+ isPulling(): boolean;
119
+ /**
120
+ * Checks whether the collection is currently performing a push operation
121
+ * ⚡️ this function is reactive!
122
+ * (saving data to the persistence adapter).
123
+ * @returns A boolean indicating if the collection is in the process of pushing data.
124
+ */
125
+ isPushing(): boolean;
126
+ /**
127
+ * Checks whether the collection is currently performing either a pull or push operation,
128
+ * ⚡️ this function is reactive!
129
+ * indicating that it is loading or saving data.
130
+ * @returns A boolean indicating if the collection is in the process of loading or saving data.
131
+ */
132
+ isLoading(): boolean;
133
+ /**
134
+ * Retrieves the current debug mode status of the collection.
135
+ * @returns A boolean indicating whether debug mode is enabled for the collection.
136
+ */
137
+ getDebugMode(): boolean;
138
+ /**
139
+ * Enables or disables debug mode for the collection.
140
+ * When debug mode is enabled, additional debugging information and events are emitted.
141
+ * @param enable - A boolean indicating whether to enable (`true`) or disable (`false`) debug mode.
142
+ */
143
+ setDebugMode(enable: boolean): void;
144
+ /**
145
+ * Enables or disables field tracking for the collection.
146
+ * @param enable - A boolean indicating whether to enable (`true`) or disable (`false`) field tracking.
147
+ */
148
+ setFieldTracking(enable: boolean): void;
149
+ private profile;
150
+ private executeInDebugMode;
151
+ private rebuildIndices;
152
+ private rebuildAllIndices;
153
+ private getIndexInfo;
154
+ private getItemAndIndex;
155
+ private deleteFromIdIndex;
156
+ private memory;
157
+ private memoryArray;
158
+ private transform;
159
+ private getItems;
160
+ /**
161
+ * Disposes the collection, unregisters persistence adapters, clears memory, and
162
+ * cleans up all resources used by the collection.
163
+ * @returns A promise that resolves when the collection is disposed.
164
+ */
165
+ dispose(): Promise<void>;
166
+ /**
167
+ * Finds multiple items in the collection based on a selector and optional options.
168
+ * Returns a cursor for reactive data queries.
169
+ * @template O - The options type for the find operation.
170
+ * @param [selector] - The criteria to select items.
171
+ * @param [options] - Options for the find operation, such as limit and sort.
172
+ * @returns A cursor to fetch and observe the matching items.
173
+ */
174
+ find<O extends FindOptions<T>>(selector?: Selector<T>, options?: O): Cursor<T, U>;
175
+ /**
176
+ * Finds a single item in the collection based on a selector and optional options.
177
+ * ⚡️ this function is reactive!
178
+ * Returns the found item or undefined if no item matches.
179
+ * @template O - The options type for the find operation.
180
+ * @param selector - The criteria to select the item.
181
+ * @param [options] - Options for the find operation, such as projection.
182
+ * @returns The found item or `undefined`.
183
+ */
184
+ findOne<O extends Omit<FindOptions<T>, 'limit'>>(selector: Selector<T>, options?: O): NonNullable<U> | undefined;
185
+ /**
186
+ * Performs a batch operation, deferring index rebuilds and allowing multiple
187
+ * modifications to be made atomically. Executes any post-batch callbacks afterwards.
188
+ * @param callback - The batch operation to execute.
189
+ */
190
+ batch(callback: () => void): void;
191
+ /**
192
+ * Inserts a single item into the collection. Generates a unique ID if not provided.
193
+ * @param item - The item to insert.
194
+ * @returns The ID of the inserted item.
195
+ * @throws {Error} If the collection is disposed or the item has an invalid ID.
196
+ */
197
+ insert(item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): I;
198
+ /**
199
+ * Inserts multiple items into the collection. Generates unique IDs for items if not provided.
200
+ * @param items - The items to insert.
201
+ * @returns An array of IDs of the inserted items.
202
+ * @throws {Error} If the collection is disposed or the items are invalid.
203
+ */
204
+ insertMany(items: Array<Omit<T, 'id'> & Partial<Pick<T, 'id'>>>): I[];
205
+ /**
206
+ * Updates a single item in the collection that matches the given selector.
207
+ * @param selector - The criteria to select the item to update.
208
+ * @param modifier - The modifications to apply to the item.
209
+ * @returns The number of items updated (0 or 1).
210
+ * @throws {Error} If the collection is disposed or invalid arguments are provided.
211
+ */
212
+ updateOne(selector: Selector<T>, modifier: Modifier<T>): 0 | 1;
213
+ /**
214
+ * Updates multiple items in the collection that match the given selector.
215
+ * @param selector - The criteria to select the items to update.
216
+ * @param modifier - The modifications to apply to the items.
217
+ * @returns The number of items updated.
218
+ * @throws {Error} If the collection is disposed or invalid arguments are provided.
219
+ */
220
+ updateMany(selector: Selector<T>, modifier: Modifier<T>): number;
221
+ /**
222
+ * Removes a single item from the collection that matches the given selector.
223
+ * @param selector - The criteria to select the item to remove.
224
+ * @returns The number of items removed (0 or 1).
225
+ * @throws {Error} If the collection is disposed or invalid arguments are provided.
226
+ */
227
+ removeOne(selector: Selector<T>): 0 | 1;
228
+ /**
229
+ * Removes multiple items from the collection that match the given selector.
230
+ * @param selector - The criteria to select the items to remove.
231
+ * @returns The number of items removed.
232
+ * @throws {Error} If the collection is disposed or invalid arguments are provided.
233
+ */
234
+ removeMany(selector: Selector<T>): number;
235
+ }
@@ -0,0 +1,25 @@
1
+ import type ReactivityAdapter from '../types/ReactivityAdapter';
2
+ export type BaseItem<I = any> = {
3
+ id: I;
4
+ } & Record<string, any>;
5
+ export type Transform<T, U = T> = ((doc: T) => U) | null | undefined;
6
+ export type SortSpecifier<T> = {
7
+ [P in keyof T]?: -1 | 1;
8
+ } & Record<string, -1 | 1>;
9
+ export type FieldSpecifier<T> = {
10
+ [P in keyof T]?: 0 | 1;
11
+ } & Record<string, 0 | 1>;
12
+ export interface FindOptions<T extends BaseItem> {
13
+ /** Sort order (default: natural order) */
14
+ sort?: SortSpecifier<T> | undefined;
15
+ /** Number of results to skip at the beginning */
16
+ skip?: number | undefined;
17
+ /** Maximum number of results to return */
18
+ limit?: number | undefined;
19
+ /** Dictionary of fields to return or exclude. */
20
+ fields?: FieldSpecifier<T> | undefined;
21
+ /** pass `false` to disable reactivity */
22
+ reactive?: ReactivityAdapter | false;
23
+ /** pass `true` to enable automatic field-level reactitivy */
24
+ fieldTracking?: boolean;
25
+ }
@@ -0,0 +1,60 @@
1
+ import Collection from './Collection';
2
+ import type { BaseItem, CollectionOptions } from './Collection';
3
+ import type { Changeset, LoadResponse } from './types/PersistenceAdapter';
4
+ interface ReplicationOptions<T extends {
5
+ id: I;
6
+ } & Record<string, any>, I> {
7
+ pull: () => Promise<LoadResponse<T>>;
8
+ push?(changes: Changeset<T>, items: T[]): Promise<void>;
9
+ registerRemoteChange?: (onChange: (data?: LoadResponse<T>) => void | Promise<void>) => Promise<void>;
10
+ }
11
+ /**
12
+ * Creates a persistence adapter for replicating a collection, enabling pull and push
13
+ * operations for synchronizing with a remote source. Supports optional remote change registration.
14
+ * @template T - The type of the items being replicated.
15
+ * @template I - The type of the unique identifier for the items.
16
+ * @param options - The options for configuring the replication adapter.
17
+ * @param options.pull - A function to fetch data from the remote source.
18
+ * @param options.push - An optional function to send changes and items to the remote source.
19
+ * @param options.registerRemoteChange - An optional function to register a listener for remote changes.
20
+ * @returns A persistence adapter configured for replication.
21
+ */
22
+ export declare function createReplicationAdapter<T extends {
23
+ id: I;
24
+ } & Record<string, any>, I>(options: ReplicationOptions<T, I>): import("./types/PersistenceAdapter").default<T, unknown>;
25
+ export type ReplicatedCollectionOptions<T extends BaseItem<I>, I, U = T> = CollectionOptions<T, I, U> & ReplicationOptions<T, I>;
26
+ /**
27
+ * Extends the `Collection` class to support replication with remote sources.
28
+ * Handles pull and push operations, remote change registration, and enhanced loading states.
29
+ * @template T - The type of the items in the collection.
30
+ * @template I - The type of the unique identifier for the items.
31
+ * @template U - The transformed item type after applying transformations (default is T).
32
+ */
33
+ export default class ReplicatedCollection<T extends BaseItem<I> = BaseItem, I = any, U = T> extends Collection<T, I, U> {
34
+ private isPullingRemoteSignal;
35
+ private isPushingRemoteSignal;
36
+ /**
37
+ * Creates a new instance of the `ReplicatedCollection` class.
38
+ * Sets up the replication adapter, combining it with an optional persistence adapter, and
39
+ * initializes signals for tracking remote pull and push operations.
40
+ * @param options - The configuration options for the replicated collection.
41
+ * @param options.pull - A function to fetch data from the remote source.
42
+ * @param options.push - An optional function to send changes and items to the remote source.
43
+ * @param options.registerRemoteChange - An optional function to register a listener for remote changes.
44
+ * @param options.persistence - An optional persistence adapter to combine with replication.
45
+ * @param options.reactivity - A reactivity adapter for observing changes in the collection.
46
+ * @param options.transform - A transformation function to apply to items when retrieving them.
47
+ * @param options.indices - An array of index providers for optimized querying.
48
+ * @param options.enableDebugMode - A boolean to enable or disable debug mode.
49
+ */
50
+ constructor(options: ReplicatedCollectionOptions<T, I, U>);
51
+ /**
52
+ * Checks whether the collection is currently performing any loading operation,
53
+ * including pulling or pushing data from/to the remote source, or standard
54
+ * persistence adapter operations.
55
+ * ⚡️ this function is reactive!
56
+ * @returns A boolean indicating if the collection is currently loading or synchronizing.
57
+ */
58
+ isLoading(): boolean;
59
+ }
60
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { BaseItem } from './Collection';
2
+ import type IndexProvider from './types/IndexProvider';
3
+ /**
4
+ * Creates an IndexProvider based on the given definition.
5
+ * @param definition - The definition of the IndexProvider.
6
+ * @returns The created IndexProvider.
7
+ */
8
+ export default function createIndexProvider<T extends BaseItem<I> = BaseItem, I = any>(definition: IndexProvider<T, I>): IndexProvider<T, I>;
@@ -0,0 +1,7 @@
1
+ import type MemoryAdapter from './types/MemoryAdapter';
2
+ /**
3
+ * Creates an MemoryAdapter based on the given definition.
4
+ * @param definition - The definition of the MemoryAdapter.
5
+ * @returns The created MemoryAdapter.
6
+ */
7
+ export default function createMemoryAdapter(definition: MemoryAdapter): MemoryAdapter<Record<string, any>>;
@@ -0,0 +1,8 @@
1
+ import type Dependency from './types/Dependency';
2
+ import type ReactivityAdapter from './types/ReactivityAdapter';
3
+ /**
4
+ * Creates an ReactivityAdapter based on the given definition.
5
+ * @param definition - The definition of the ReactivityAdapter.
6
+ * @returns The created ReactivityAdapter.
7
+ */
8
+ export default function createReactivityAdapter<T extends Dependency = Dependency>(definition: ReactivityAdapter<T>): ReactivityAdapter<T>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("./index.cjs2.js");
4
+ const AutoFetchCollection = require("./index.cjs3.js");
5
+ const combinePersistenceAdapters = require("./index.cjs4.js");
6
+ const createIndexProvider = require("./index.cjs5.js");
7
+ const createMemoryAdapter = require("./index.cjs6.js");
8
+ const createPersistenceAdapter = require("./index.cjs7.js");
9
+ const createReactivityAdapter = require("./index.cjs8.js");
10
+ const isEqual = require("./index.cjs9.js");
11
+ const modify = require("./index.cjs10.js");
12
+ const randomId = require("./index.cjs11.js");
13
+ const createIndex = require("./index.cjs12.js");
14
+ exports.Collection = index.default;
15
+ exports.AutoFetchCollection = AutoFetchCollection;
16
+ exports.combinePersistenceAdapters = combinePersistenceAdapters.default;
17
+ exports.createIndexProvider = createIndexProvider;
18
+ exports.createMemoryAdapter = createMemoryAdapter;
19
+ exports.createPersistenceAdapter = createPersistenceAdapter;
20
+ exports.createReactivityAdapter = createReactivityAdapter;
21
+ exports.isEqual = isEqual;
22
+ exports.modify = modify;
23
+ exports.randomId = randomId;
24
+ exports.createIndex = createIndex.default;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ const updater = require("mingo/updater");
3
+ function modify(item, modifier) {
4
+ const clonedItem = Object.assign({}, item);
5
+ updater.updateObject(clonedItem, modifier);
6
+ return clonedItem;
7
+ }
8
+ module.exports = modify;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ function randomId() {
3
+ return Math.floor(Math.random() * 1e17).toString(16);
4
+ }
5
+ module.exports = randomId;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const createIndexProvider = require("./index.cjs5.js");
4
+ const get = require("./index.cjs26.js");
5
+ const getMatchingKeys = require("./index.cjs27.js");
6
+ const serializeValue = require("./index.cjs16.js");
7
+ function createExternalIndex(field, index) {
8
+ return createIndexProvider({
9
+ query(selector) {
10
+ const keys = getMatchingKeys(field, selector);
11
+ if (keys == null)
12
+ return { matched: false };
13
+ const itemPositions = keys.reduce((memo, key) => [...memo, ...index.get(key) || []], []);
14
+ return {
15
+ matched: true,
16
+ positions: itemPositions,
17
+ fields: [field]
18
+ };
19
+ },
20
+ rebuild() {
21
+ }
22
+ });
23
+ }
24
+ function createIndex(field) {
25
+ const index = /* @__PURE__ */ new Map();
26
+ return Object.assign(Object.assign({}, createExternalIndex(field, index)), { rebuild(items) {
27
+ index.clear();
28
+ items.forEach((item, i) => {
29
+ const value = serializeValue(get(item, field));
30
+ const current = index.get(value) || /* @__PURE__ */ new Set();
31
+ current.add(i);
32
+ index.set(value, current);
33
+ });
34
+ } });
35
+ }
36
+ exports.createExternalIndex = createExternalIndex;
37
+ exports.default = createIndex;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ const events = require("events");
3
+ class EventEmitter extends events.EventEmitter {
4
+ /**
5
+ * Registers a listener for the specified event.
6
+ * @template K - The key of the event in the `Events` record.
7
+ * @param event - The name of the event to listen for.
8
+ * @param listener - The listener function to execute when the event is emitted.
9
+ * @returns The `EventEmitter` instance, allowing for method chaining.
10
+ */
11
+ on(event, listener) {
12
+ super.on(event, listener);
13
+ return this;
14
+ }
15
+ /**
16
+ * Emits the specified event, triggering all registered listeners for that event.
17
+ * @template K - The key of the event in the `Events` record.
18
+ * @param event - The name of the event to emit.
19
+ * @param args - The arguments to pass to the event listeners.
20
+ * @returns A boolean indicating whether any listeners were triggered.
21
+ */
22
+ emit(event, ...args) {
23
+ return super.emit(event, ...args);
24
+ }
25
+ }
26
+ module.exports = EventEmitter;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ const mingo = require("mingo");
3
+ function match(item, selector) {
4
+ const query = new mingo.Query(selector);
5
+ return query.test(item);
6
+ }
7
+ module.exports = match;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ function clone(value) {
4
+ if (typeof value === "function")
5
+ throw new Error("Cloning functions is not supported");
6
+ if (value === null || typeof value !== "object")
7
+ return value;
8
+ if (value instanceof Date)
9
+ return new Date(value.getTime());
10
+ if (Array.isArray(value))
11
+ return value.map((item) => clone(item));
12
+ if (value instanceof Map) {
13
+ const result2 = /* @__PURE__ */ new Map();
14
+ value.forEach((val, key) => {
15
+ result2.set(key, clone(val));
16
+ });
17
+ return result2;
18
+ }
19
+ if (value instanceof Set) {
20
+ const result2 = /* @__PURE__ */ new Set();
21
+ value.forEach((val) => {
22
+ result2.add(clone(val));
23
+ });
24
+ return result2;
25
+ }
26
+ if (value instanceof RegExp)
27
+ return new RegExp(value);
28
+ const result = {};
29
+ for (const key in value) {
30
+ if (Object.hasOwnProperty.call(value, key)) {
31
+ result[key] = clone(value[key]);
32
+ }
33
+ }
34
+ return result;
35
+ }
36
+ function deepClone(obj) {
37
+ if (typeof structuredClone === "function")
38
+ return structuredClone(obj);
39
+ /* istanbul ignore next -- @preserve */
40
+ return clone(obj);
41
+ }
42
+ exports.clone = clone;
43
+ exports.default = deepClone;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ function serializeValue(value) {
3
+ if (typeof value === "string")
4
+ return value;
5
+ if (typeof value === "number")
6
+ return value.toString();
7
+ if (typeof value === "boolean")
8
+ return value.toString();
9
+ if (value instanceof Date)
10
+ return value.toISOString();
11
+ return JSON.stringify(value);
12
+ }
13
+ module.exports = serializeValue;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ function createSignal(dependency, initialValue, isEqual = Object.is) {
3
+ let value = initialValue;
4
+ const signal = {
5
+ get() {
6
+ if (dependency)
7
+ dependency.depend();
8
+ return value;
9
+ },
10
+ set(newValue) {
11
+ if (isEqual(value, newValue))
12
+ return;
13
+ value = newValue;
14
+ if (dependency)
15
+ dependency.notify();
16
+ }
17
+ };
18
+ return signal;
19
+ }
20
+ module.exports = createSignal;