@signaldb/core 1.7.0 → 2.0.0-beta.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.
- package/dist/.vite/manifest.json +125 -82
- package/dist/AsyncDataAdapter.d.ts +64 -0
- package/dist/AutoFetchDataAdapter.d.ts +113 -0
- package/dist/Collection/Cursor.d.ts +9 -9
- package/dist/Collection/Observer.d.ts +3 -2
- package/dist/Collection/index.d.ts +52 -46
- package/dist/Collection/types.d.ts +4 -9
- package/dist/DataAdapter.d.ts +33 -0
- package/dist/DefaultDataAdapter.d.ts +32 -0
- package/dist/WorkerDataAdapter.d.ts +22 -0
- package/dist/WorkerDataAdapterHost.d.ts +59 -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 +337 -3
- package/dist/index.cjs13.js +384 -115
- package/dist/index.cjs14.js +183 -67
- package/dist/index.cjs15.js +339 -8
- package/dist/index.cjs16.js +563 -20
- package/dist/index.cjs17.js +16 -12
- package/dist/index.cjs18.js +24 -5
- package/dist/index.cjs2.js +27 -36
- package/dist/index.cjs20.js +102 -13
- package/dist/index.cjs21.js +124 -21
- package/dist/index.cjs22.js +5 -68
- package/dist/index.cjs23.js +22 -82
- package/dist/index.cjs24.js +5 -16
- package/dist/index.cjs25.js +8 -27
- package/dist/index.cjs26.js +27 -7
- package/dist/index.cjs27.js +3 -5
- package/dist/index.cjs28.js +5 -27
- package/dist/index.cjs29.js +27 -40
- package/dist/index.cjs3.js +242 -497
- package/dist/index.cjs30.js +42 -0
- package/dist/index.cjs31.js +9 -0
- package/dist/index.cjs4.js +3 -170
- package/dist/index.cjs5.js +3 -67
- 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 +10 -8
- package/dist/index.mjs +15 -11
- package/dist/index10.mjs +15 -26
- package/dist/index11.mjs +13 -10
- package/dist/index12.mjs +337 -3
- package/dist/index13.mjs +384 -115
- package/dist/index14.mjs +183 -66
- package/dist/index15.mjs +339 -8
- package/dist/index16.mjs +563 -20
- package/dist/index17.mjs +16 -12
- package/dist/index18.mjs +24 -5
- package/dist/index2.mjs +27 -36
- package/dist/index20.mjs +102 -13
- package/dist/index21.mjs +123 -21
- package/dist/index22.mjs +5 -67
- package/dist/index23.mjs +22 -81
- package/dist/index24.mjs +5 -16
- package/dist/index25.mjs +8 -27
- package/dist/index26.mjs +27 -7
- package/dist/index27.mjs +3 -5
- package/dist/index28.mjs +5 -27
- package/dist/index29.mjs +27 -40
- package/dist/index3.mjs +241 -497
- package/dist/index30.mjs +43 -0
- package/dist/index31.mjs +10 -0
- package/dist/index4.mjs +3 -170
- package/dist/index5.mjs +3 -66
- 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/objectId.d.ts +8 -0
- package/dist/utils/queryId.d.ts +9 -0
- package/package.json +2 -2
- 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 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
|
-
}
|