@signaldb/core 1.7.1 → 2.0.0-beta.1
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.
- package/dist/.vite/manifest.json +138 -82
- package/dist/AsyncDataAdapter.d.ts +64 -0
- package/dist/AutoFetchDataAdapter.d.ts +112 -0
- package/dist/Collection/Cursor.d.ts +9 -9
- package/dist/Collection/Observer.d.ts +3 -2
- package/dist/Collection/index.d.ts +54 -46
- package/dist/Collection/types.d.ts +4 -9
- package/dist/DataAdapter.d.ts +34 -0
- package/dist/DefaultDataAdapter.d.ts +33 -0
- package/dist/WorkerDataAdapter.d.ts +25 -0
- package/dist/WorkerDataAdapterHost.d.ts +62 -0
- package/dist/createIndex.d.ts +7 -0
- package/dist/createStorageAdapter.d.ts +9 -0
- package/dist/{Collection/getIndexInfo.d.ts → getIndexInfo.d.ts} +17 -19
- package/dist/index.cjs.js +21 -17
- package/dist/index.cjs10.js +15 -26
- package/dist/index.cjs11.js +13 -10
- package/dist/index.cjs12.js +348 -3
- package/dist/index.cjs13.js +396 -110
- package/dist/index.cjs14.js +178 -68
- package/dist/index.cjs15.js +384 -8
- package/dist/index.cjs16.js +572 -20
- package/dist/index.cjs17.js +12 -4
- package/dist/index.cjs18.js +24 -5
- package/dist/index.cjs2.js +29 -32
- package/dist/index.cjs20.js +5 -13
- package/dist/index.cjs21.js +99 -21
- package/dist/index.cjs22.js +108 -58
- package/dist/index.cjs23.js +5 -82
- package/dist/index.cjs24.js +23 -14
- package/dist/index.cjs25.js +8 -27
- package/dist/index.cjs26.js +27 -7
- package/dist/index.cjs27.js +44 -5
- package/dist/index.cjs28.js +6 -27
- package/dist/index.cjs29.js +7 -40
- package/dist/index.cjs3.js +198 -444
- package/dist/index.cjs30.js +5 -0
- package/dist/index.cjs31.js +7 -0
- package/dist/index.cjs32.js +29 -0
- package/dist/index.cjs33.js +42 -0
- package/dist/index.cjs4.js +3 -165
- package/dist/index.cjs5.js +3 -66
- package/dist/index.cjs6.js +27 -3
- package/dist/index.cjs7.js +10 -3
- package/dist/index.cjs8.js +3 -3
- package/dist/index.cjs9.js +131 -3
- package/dist/index.d.ts +11 -8
- package/dist/index.mjs +15 -11
- package/dist/index10.mjs +15 -26
- package/dist/index11.mjs +13 -10
- package/dist/index12.mjs +348 -3
- package/dist/index13.mjs +396 -110
- package/dist/index14.mjs +178 -67
- package/dist/index15.mjs +384 -8
- package/dist/index16.mjs +572 -20
- package/dist/index17.mjs +12 -4
- package/dist/index18.mjs +24 -5
- package/dist/index2.mjs +29 -32
- package/dist/index20.mjs +5 -13
- package/dist/index21.mjs +99 -21
- package/dist/index22.mjs +108 -58
- package/dist/index23.mjs +5 -81
- package/dist/index24.mjs +23 -14
- package/dist/index25.mjs +8 -27
- package/dist/index26.mjs +27 -7
- package/dist/index27.mjs +44 -5
- package/dist/index28.mjs +6 -27
- package/dist/index29.mjs +7 -40
- package/dist/index3.mjs +198 -445
- package/dist/index30.mjs +6 -0
- package/dist/index31.mjs +8 -0
- package/dist/index32.mjs +30 -0
- package/dist/index33.mjs +43 -0
- package/dist/index4.mjs +3 -165
- package/dist/index5.mjs +3 -65
- package/dist/index6.mjs +27 -3
- package/dist/index7.mjs +10 -3
- package/dist/index8.mjs +3 -3
- package/dist/index9.mjs +131 -3
- package/dist/types/IndexProvider.d.ts +12 -7
- package/dist/types/StorageAdapter.d.ts +20 -0
- package/dist/utils/batchOnNextTick.d.ts +16 -0
- package/dist/utils/objectId.d.ts +8 -0
- package/dist/utils/queryId.d.ts +9 -0
- package/package.json +1 -1
- package/dist/AutoFetchCollection.d.ts +0 -60
- package/dist/Collection/createIndex.d.ts +0 -15
- package/dist/ReplicatedCollection.d.ts +0 -60
- package/dist/createMemoryAdapter.d.ts +0 -7
- package/dist/persistence/combinePersistenceAdapters.d.ts +0 -32
- package/dist/persistence/createPersistenceAdapter.d.ts +0 -9
- package/dist/types/MemoryAdapter.d.ts +0 -15
- package/dist/types/PersistenceAdapter.d.ts +0 -20
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from './Collection';
|
|
2
|
-
import type { ReplicatedCollectionOptions } from './ReplicatedCollection';
|
|
3
|
-
import ReplicatedCollection from './ReplicatedCollection';
|
|
4
|
-
import type Selector from './types/Selector';
|
|
5
|
-
interface AutoFetchOptions<T extends {
|
|
6
|
-
id: I;
|
|
7
|
-
} & Record<string, any>, I> {
|
|
8
|
-
fetchQueryItems: (selector: Selector<T>) => ReturnType<ReplicatedCollectionOptions<T, I>['pull']>;
|
|
9
|
-
purgeDelay?: number;
|
|
10
|
-
registerRemoteChange?: (onChange: () => Promise<void>) => Promise<void>;
|
|
11
|
-
mergeItems?: (itemA: T, itemB: T) => T;
|
|
12
|
-
}
|
|
13
|
-
export type AutoFetchCollectionOptions<T extends BaseItem<I>, I, U = T> = Omit<ReplicatedCollectionOptions<T, I, U>, 'pull' | 'registerRemoteChange'> & AutoFetchOptions<T, I>;
|
|
14
|
-
/**
|
|
15
|
-
* A special collection that automatically fetches items when they are needed.
|
|
16
|
-
*/
|
|
17
|
-
export default class AutoFetchCollection<T extends BaseItem<I> = BaseItem, I = any, U = T> extends ReplicatedCollection<T, I, U> {
|
|
18
|
-
private activeObservers;
|
|
19
|
-
private observerTimeouts;
|
|
20
|
-
private purgeDelay;
|
|
21
|
-
private idQueryCache;
|
|
22
|
-
private itemsCache;
|
|
23
|
-
private fetchQueryItems;
|
|
24
|
-
private triggerReload;
|
|
25
|
-
private reactivityAdapter;
|
|
26
|
-
private loadingSignals;
|
|
27
|
-
private isFetchingSignal;
|
|
28
|
-
private mergeItems;
|
|
29
|
-
/**
|
|
30
|
-
* @param options {Object} - Options for the collection.
|
|
31
|
-
* @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property.
|
|
32
|
-
* @param options.purgeDelay {Number} - The delay in milliseconds before purging an item from the cache.
|
|
33
|
-
*/
|
|
34
|
-
constructor(options: AutoFetchCollectionOptions<T, I, U>);
|
|
35
|
-
/**
|
|
36
|
-
* Registers a query manually that items should be fetched for it
|
|
37
|
-
* @param selector {Object} Selector of the query
|
|
38
|
-
*/
|
|
39
|
-
registerQuery(selector: Selector<T>): void;
|
|
40
|
-
/**
|
|
41
|
-
* Unregisters a query manually that items are not fetched anymore for it
|
|
42
|
-
* @param selector {Object} Selector of the query
|
|
43
|
-
*/
|
|
44
|
-
unregisterQuery(selector: Selector<T>): void;
|
|
45
|
-
private getKeyForSelector;
|
|
46
|
-
private forceRefetch;
|
|
47
|
-
private fetchSelector;
|
|
48
|
-
private handleObserverCreation;
|
|
49
|
-
private handleObserverDisposal;
|
|
50
|
-
private ensureSignal;
|
|
51
|
-
private setLoading;
|
|
52
|
-
/**
|
|
53
|
-
* Indicates wether a query is currently been loaded
|
|
54
|
-
* ⚡️ this function is reactive!
|
|
55
|
-
* @param selector {Object} Selector of the query
|
|
56
|
-
* @returns The loading state
|
|
57
|
-
*/
|
|
58
|
-
isLoading(selector?: Selector<T>): boolean;
|
|
59
|
-
}
|
|
60
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type IndexProvider from '../types/IndexProvider';
|
|
2
|
-
import type { BaseItem } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* creates an index for a specific field but uses an external map to store the index
|
|
5
|
-
* @param field name of the field
|
|
6
|
-
* @param index the external map to use for the index
|
|
7
|
-
* @returns an index provider to pass to the `indices` option of the collection constructor
|
|
8
|
-
*/
|
|
9
|
-
export declare function createExternalIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string, index: Map<string | undefined | null, Set<number>>): IndexProvider<T, I>;
|
|
10
|
-
/**
|
|
11
|
-
* creates an index for a specific field
|
|
12
|
-
* @param field name of the field
|
|
13
|
-
* @returns an index provider to pass to the `indices` option of the collection constructor
|
|
14
|
-
*/
|
|
15
|
-
export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): IndexProvider<T, I>;
|
|
@@ -1,60 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,7 +0,0 @@
|
|
|
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>>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type PersistenceAdapter from '../types/PersistenceAdapter';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that executes two asynchronous functions sequentially.
|
|
4
|
-
* The first function is tried first, and if it resolves, its value is used.
|
|
5
|
-
* If the first function fails or a fallback is required, the second function is executed.
|
|
6
|
-
* An optional cache mechanism can store the result temporarily to improve performance.
|
|
7
|
-
* @template Arguments - The argument types for the promise functions.
|
|
8
|
-
* @template ReturnValue - The return value type of the promise functions.
|
|
9
|
-
* @param firstResolvingPromiseFunction - The primary promise-based function to execute.
|
|
10
|
-
* @param secondResolvingPromiseFunction - The secondary fallback promise-based function to execute.
|
|
11
|
-
* @param [options] - Optional configuration.
|
|
12
|
-
* @param [options.onResolve] - Callback executed when a promise resolves.
|
|
13
|
-
* @param [options.cacheTimeout] - Time (in ms) to cache the resolved result.
|
|
14
|
-
* @returns A function that executes the two promises as described.
|
|
15
|
-
*/
|
|
16
|
-
export declare function createTemporaryFallbackExecutor<Arguments extends Array<any>, ReturnValue>(firstResolvingPromiseFunction: (...args: Arguments) => Promise<ReturnValue>, secondResolvingPromiseFunction: (...args: Arguments) => Promise<ReturnValue>, options?: {
|
|
17
|
-
onResolve?: (returnValue: ReturnValue) => void;
|
|
18
|
-
cacheTimeout?: number;
|
|
19
|
-
}): (...args: Arguments) => Promise<ReturnValue>;
|
|
20
|
-
/**
|
|
21
|
-
* Combines two persistence adapters (fast and slow) into a single interface.
|
|
22
|
-
* The fast adapter is used for quick read and write operations, while the slow adapter
|
|
23
|
-
* ensures data persistence and durability. The adapters sync automatically on read and save operations.
|
|
24
|
-
* @template T - The type of the persisted data items.
|
|
25
|
-
* @template I - The type of the identifier for persisted data items.
|
|
26
|
-
* @param slowAdapter - The slow persistence adapter for long-term storage.
|
|
27
|
-
* @param fastAdapter - The fast persistence adapter for quick access.
|
|
28
|
-
* @returns A combined persistence adapter that manages synchronization between the two adapters.
|
|
29
|
-
*/
|
|
30
|
-
export default function combinePersistenceAdapters<T extends {
|
|
31
|
-
id: I;
|
|
32
|
-
} & Record<string, any>, I>(slowAdapter: PersistenceAdapter<T, I>, fastAdapter: PersistenceAdapter<T, I>): PersistenceAdapter<T, I>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type PersistenceAdapter from '../types/PersistenceAdapter';
|
|
2
|
-
/**
|
|
3
|
-
* Creates an PersistenceAdapter based on the given definition.
|
|
4
|
-
* @param definition - The definition of the PersistenceAdapter.
|
|
5
|
-
* @returns The created PersistenceAdapter.
|
|
6
|
-
*/
|
|
7
|
-
export default function createPersistenceAdapter<T extends {
|
|
8
|
-
id: I;
|
|
9
|
-
} & Record<string, any>, I>(definition: PersistenceAdapter<T, I>): PersistenceAdapter<T, I>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Abstract class representing a memory adapter that implements methods
|
|
3
|
-
* from the JavaScript `Array` class for data manipulation.
|
|
4
|
-
* Designed to be extended and customized for specific use cases.
|
|
5
|
-
* @template T - The type of the items stored in the memory adapter (default is a record of key-value pairs).
|
|
6
|
-
*/
|
|
7
|
-
export default abstract class MemoryAdapter<T = Record<string, any>> {
|
|
8
|
-
abstract push(item: T): void;
|
|
9
|
-
abstract pop(): T | undefined;
|
|
10
|
-
abstract splice(start: number, deleteCount?: number, ...items: T[]): T[];
|
|
11
|
-
abstract map<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[];
|
|
12
|
-
abstract find(predicate: (value: T, index: number, object: T[]) => boolean): T | undefined;
|
|
13
|
-
abstract filter(predicate: (value: T, index: number, array: T[]) => unknown): T[];
|
|
14
|
-
abstract findIndex(predicate: (value: T, index: number, object: T[]) => boolean): number;
|
|
15
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface Changeset<T> {
|
|
2
|
-
added: T[];
|
|
3
|
-
modified: T[];
|
|
4
|
-
removed: T[];
|
|
5
|
-
}
|
|
6
|
-
export type LoadResponse<T> = {
|
|
7
|
-
items: T[];
|
|
8
|
-
changes?: never;
|
|
9
|
-
} | {
|
|
10
|
-
changes: Changeset<T>;
|
|
11
|
-
items?: never;
|
|
12
|
-
};
|
|
13
|
-
export default interface PersistenceAdapter<T extends {
|
|
14
|
-
id: I;
|
|
15
|
-
} & Record<string, any>, I> {
|
|
16
|
-
load(): Promise<LoadResponse<T>>;
|
|
17
|
-
save(items: T[], changes: Changeset<T>): Promise<void>;
|
|
18
|
-
register(onChange: (data?: LoadResponse<T>) => void | Promise<void>): Promise<void>;
|
|
19
|
-
unregister?(): Promise<void>;
|
|
20
|
-
}
|