@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.
- package/README.md +68 -0
- package/dist/.vite/manifest.json +222 -0
- package/dist/AutoFetchCollection.d.ts +60 -0
- package/dist/Collection/Cursor.d.ts +112 -0
- package/dist/Collection/Observer.d.ts +61 -0
- package/dist/Collection/createIndex.d.ts +15 -0
- package/dist/Collection/getIndexInfo.d.ts +41 -0
- package/dist/Collection/index.d.ts +235 -0
- package/dist/Collection/types.d.ts +25 -0
- package/dist/ReplicatedCollection.d.ts +60 -0
- package/dist/createIndexProvider.d.ts +8 -0
- package/dist/createMemoryAdapter.d.ts +7 -0
- package/dist/createReactivityAdapter.d.ts +8 -0
- package/dist/index.cjs.js +24 -0
- package/dist/index.cjs10.js +8 -0
- package/dist/index.cjs11.js +5 -0
- package/dist/index.cjs12.js +37 -0
- package/dist/index.cjs13.js +26 -0
- package/dist/index.cjs14.js +7 -0
- package/dist/index.cjs15.js +43 -0
- package/dist/index.cjs16.js +13 -0
- package/dist/index.cjs17.js +20 -0
- package/dist/index.cjs18.js +247 -0
- package/dist/index.cjs19.js +71 -0
- package/dist/index.cjs2.js +631 -0
- package/dist/index.cjs20.js +80 -0
- package/dist/index.cjs21.js +10 -0
- package/dist/index.cjs22.js +27 -0
- package/dist/index.cjs23.js +137 -0
- package/dist/index.cjs24.js +18 -0
- package/dist/index.cjs25.js +7 -0
- package/dist/index.cjs26.js +19 -0
- package/dist/index.cjs27.js +24 -0
- package/dist/index.cjs28.js +42 -0
- package/dist/index.cjs29.js +29 -0
- package/dist/index.cjs3.js +165 -0
- package/dist/index.cjs30.js +9 -0
- package/dist/index.cjs4.js +70 -0
- package/dist/index.cjs5.js +5 -0
- package/dist/index.cjs6.js +5 -0
- package/dist/index.cjs7.js +5 -0
- package/dist/index.cjs8.js +5 -0
- package/dist/index.cjs9.js +30 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.mjs +24 -0
- package/dist/index10.mjs +9 -0
- package/dist/index11.mjs +6 -0
- package/dist/index12.mjs +37 -0
- package/dist/index13.mjs +27 -0
- package/dist/index14.mjs +8 -0
- package/dist/index15.mjs +43 -0
- package/dist/index16.mjs +14 -0
- package/dist/index17.mjs +21 -0
- package/dist/index18.mjs +247 -0
- package/dist/index19.mjs +71 -0
- package/dist/index2.mjs +632 -0
- package/dist/index20.mjs +80 -0
- package/dist/index21.mjs +11 -0
- package/dist/index22.mjs +28 -0
- package/dist/index23.mjs +138 -0
- package/dist/index24.mjs +18 -0
- package/dist/index25.mjs +8 -0
- package/dist/index26.mjs +20 -0
- package/dist/index27.mjs +25 -0
- package/dist/index28.mjs +43 -0
- package/dist/index29.mjs +30 -0
- package/dist/index3.mjs +166 -0
- package/dist/index30.mjs +10 -0
- package/dist/index4.mjs +70 -0
- package/dist/index5.mjs +6 -0
- package/dist/index6.mjs +6 -0
- package/dist/index7.mjs +6 -0
- package/dist/index8.mjs +6 -0
- package/dist/index9.mjs +31 -0
- package/dist/persistence/combinePersistenceAdapters.d.ts +32 -0
- package/dist/persistence/createPersistenceAdapter.d.ts +9 -0
- package/dist/types/Dependency.d.ts +4 -0
- package/dist/types/EventEmitter.d.ts +25 -0
- package/dist/types/IndexProvider.d.ts +19 -0
- package/dist/types/MemoryAdapter.d.ts +15 -0
- package/dist/types/Modifier.d.ts +39 -0
- package/dist/types/PersistenceAdapter.d.ts +20 -0
- package/dist/types/ReactivityAdapter.d.ts +6 -0
- package/dist/types/Selector.d.ts +47 -0
- package/dist/types/Signal.d.ts +4 -0
- package/dist/utils/compact.d.ts +9 -0
- package/dist/utils/createSignal.d.ts +14 -0
- package/dist/utils/deepClone.d.ts +17 -0
- package/dist/utils/get.d.ts +9 -0
- package/dist/utils/getMatchingKeys.d.ts +14 -0
- package/dist/utils/intersection.d.ts +9 -0
- package/dist/utils/isEqual.d.ts +14 -0
- package/dist/utils/isFieldExpression.d.ts +11 -0
- package/dist/utils/match.d.ts +12 -0
- package/dist/utils/modify.d.ts +14 -0
- package/dist/utils/project.d.ts +15 -0
- package/dist/utils/randomId.d.ts +7 -0
- package/dist/utils/serializeValue.d.ts +12 -0
- package/dist/utils/set.d.ts +13 -0
- package/dist/utils/sortItems.d.ts +12 -0
- package/dist/utils/uniqueBy.d.ts +10 -0
- package/package.json +58 -0
package/dist/index8.mjs
ADDED
package/dist/index9.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function isEqual(a, b) {
|
|
2
|
+
if (Object.is(a, b))
|
|
3
|
+
return true;
|
|
4
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
5
|
+
return a.toString() === b.toString();
|
|
6
|
+
if (a instanceof Date && b instanceof Date)
|
|
7
|
+
return a.getTime() === b.getTime();
|
|
8
|
+
if (typeof a !== "object")
|
|
9
|
+
return false;
|
|
10
|
+
if (typeof b !== "object")
|
|
11
|
+
return false;
|
|
12
|
+
if (a === null)
|
|
13
|
+
return false;
|
|
14
|
+
if (b === null)
|
|
15
|
+
return false;
|
|
16
|
+
const aKeys = Object.keys(a);
|
|
17
|
+
const bKeys = Object.keys(b);
|
|
18
|
+
if (aKeys.length !== bKeys.length)
|
|
19
|
+
return false;
|
|
20
|
+
for (let i = 0; i < aKeys.length; i += 1) {
|
|
21
|
+
const key = aKeys[i];
|
|
22
|
+
if (!bKeys.includes(key))
|
|
23
|
+
return false;
|
|
24
|
+
if (!isEqual(a[key], b[key]))
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
isEqual as default
|
|
31
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 Args - The argument types for the promise functions.
|
|
8
|
+
* @template ReturnVal - The return value type of the promise functions.
|
|
9
|
+
* @param firstResolvingPromiseFn - The primary promise-based function to execute.
|
|
10
|
+
* @param secondResolvingPromiseFn - 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<Args extends Array<any>, ReturnVal>(firstResolvingPromiseFn: (...args: Args) => Promise<ReturnVal>, secondResolvingPromiseFn: (...args: Args) => Promise<ReturnVal>, options?: {
|
|
17
|
+
onResolve?: (returnValue: ReturnVal) => void;
|
|
18
|
+
cacheTimeout?: number;
|
|
19
|
+
}): (...args: Args) => Promise<ReturnVal>;
|
|
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>;
|
|
@@ -0,0 +1,9 @@
|
|
|
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>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventEmitter as BaseEventEmitter } from 'events';
|
|
2
|
+
/**
|
|
3
|
+
* Extends the `EventEmitter` class from Node.js to provide a strongly-typed
|
|
4
|
+
* event emitter that enforces type safety for events and their corresponding listeners.
|
|
5
|
+
* @template Events - A record where keys represent event names (string or symbol),
|
|
6
|
+
* and values represent the listener function types for those events.
|
|
7
|
+
*/
|
|
8
|
+
export default class EventEmitter<Events extends Record<string | symbol, any>> extends BaseEventEmitter {
|
|
9
|
+
/**
|
|
10
|
+
* Registers a listener for the specified event.
|
|
11
|
+
* @template K - The key of the event in the `Events` record.
|
|
12
|
+
* @param event - The name of the event to listen for.
|
|
13
|
+
* @param listener - The listener function to execute when the event is emitted.
|
|
14
|
+
* @returns The `EventEmitter` instance, allowing for method chaining.
|
|
15
|
+
*/
|
|
16
|
+
on<K extends keyof Events>(event: K, listener: Events[K]): this;
|
|
17
|
+
/**
|
|
18
|
+
* Emits the specified event, triggering all registered listeners for that event.
|
|
19
|
+
* @template K - The key of the event in the `Events` record.
|
|
20
|
+
* @param event - The name of the event to emit.
|
|
21
|
+
* @param args - The arguments to pass to the event listeners.
|
|
22
|
+
* @returns A boolean indicating whether any listeners were triggered.
|
|
23
|
+
*/
|
|
24
|
+
emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BaseItem } from '../Collection';
|
|
2
|
+
import type { FlatSelector } from './Selector';
|
|
3
|
+
type IndexResult = {
|
|
4
|
+
positions: number[];
|
|
5
|
+
fields: string[];
|
|
6
|
+
matched: true;
|
|
7
|
+
} | {
|
|
8
|
+
positions?: never;
|
|
9
|
+
fields?: never;
|
|
10
|
+
matched: false;
|
|
11
|
+
};
|
|
12
|
+
interface IndexProvider<T extends BaseItem<I> = BaseItem, I = any> {
|
|
13
|
+
query(selector: FlatSelector<T>): IndexResult;
|
|
14
|
+
rebuild(items: T[]): void;
|
|
15
|
+
}
|
|
16
|
+
export type LowLevelIndexProvider<T extends BaseItem<I> = BaseItem, I = any> = IndexProvider<T, I> & {
|
|
17
|
+
_index: Map<string, Set<number>>;
|
|
18
|
+
};
|
|
19
|
+
export default IndexProvider;
|
|
@@ -0,0 +1,15 @@
|
|
|
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, obj: T[]) => boolean): T | undefined;
|
|
13
|
+
abstract filter(predicate: (value: T, index: number, array: T[]) => unknown): T[];
|
|
14
|
+
abstract findIndex(predicate: (value: T, index: number, obj: T[]) => boolean): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type Dictionary<T> = Record<string, T>;
|
|
2
|
+
type PartialMapTo<T, M> = Partial<Record<keyof T, M>>;
|
|
3
|
+
type OnlyElementsOfArrays<T> = T extends any[] ? Partial<T[0]> : never;
|
|
4
|
+
type ElementsOf<T> = {
|
|
5
|
+
[P in keyof T]?: OnlyElementsOfArrays<T[P]>;
|
|
6
|
+
};
|
|
7
|
+
type PushModifier<T> = {
|
|
8
|
+
[P in keyof T]?: OnlyElementsOfArrays<T[P]> | {
|
|
9
|
+
$each?: T[P] | undefined;
|
|
10
|
+
$position?: number | undefined;
|
|
11
|
+
$slice?: number | undefined;
|
|
12
|
+
$sort?: 1 | -1 | Dictionary<number> | undefined;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type ArraysOrEach<T> = {
|
|
16
|
+
[P in keyof T]?: OnlyElementsOfArrays<T[P]> | {
|
|
17
|
+
$each: T[P];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type CurrentDateModifier = {
|
|
21
|
+
$type: 'timestamp' | 'date';
|
|
22
|
+
} | true;
|
|
23
|
+
type Modifier<T extends Dictionary<any> = Dictionary<any>> = {
|
|
24
|
+
$currentDate?: (Partial<Record<keyof T, CurrentDateModifier>> & Dictionary<CurrentDateModifier>) | undefined;
|
|
25
|
+
$inc?: (PartialMapTo<T, number> & Dictionary<number>) | undefined;
|
|
26
|
+
$min?: (PartialMapTo<T, Date | number> & Dictionary<Date | number>) | undefined;
|
|
27
|
+
$max?: (PartialMapTo<T, Date | number> & Dictionary<Date | number>) | undefined;
|
|
28
|
+
$mul?: (PartialMapTo<T, number> & Dictionary<number>) | undefined;
|
|
29
|
+
$rename?: (PartialMapTo<T, string> & Dictionary<string>) | undefined;
|
|
30
|
+
$set?: (Partial<T> & Dictionary<any>) | undefined;
|
|
31
|
+
$setOnInsert?: (Partial<T> & Dictionary<any>) | undefined;
|
|
32
|
+
$unset?: (PartialMapTo<T, string | boolean | 1 | 0> & Dictionary<any>) | undefined;
|
|
33
|
+
$addToSet?: (ArraysOrEach<T> & Dictionary<any>) | undefined;
|
|
34
|
+
$push?: (PushModifier<T> & Dictionary<any>) | undefined;
|
|
35
|
+
$pull?: (ElementsOf<T> & Dictionary<any>) | undefined;
|
|
36
|
+
$pullAll?: (Partial<T> & Dictionary<any>) | undefined;
|
|
37
|
+
$pop?: (PartialMapTo<T, 1 | -1> & Dictionary<1 | -1>) | undefined;
|
|
38
|
+
};
|
|
39
|
+
export default Modifier;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface FieldExpression<T> {
|
|
2
|
+
$eq?: T | undefined;
|
|
3
|
+
$gt?: T | undefined;
|
|
4
|
+
$gte?: T | undefined;
|
|
5
|
+
$lt?: T | undefined;
|
|
6
|
+
$lte?: T | undefined;
|
|
7
|
+
$in?: T[] | undefined;
|
|
8
|
+
$nin?: T[] | undefined;
|
|
9
|
+
$ne?: T | undefined;
|
|
10
|
+
$exists?: boolean | undefined;
|
|
11
|
+
$not?: FieldExpression<T> | undefined;
|
|
12
|
+
$expr?: FieldExpression<T> | undefined;
|
|
13
|
+
$jsonSchema?: any;
|
|
14
|
+
$mod?: number[] | undefined;
|
|
15
|
+
$regex?: RegExp | string | undefined;
|
|
16
|
+
$options?: string | undefined;
|
|
17
|
+
$text?: {
|
|
18
|
+
$search: string;
|
|
19
|
+
$language?: string | undefined;
|
|
20
|
+
$caseSensitive?: boolean | undefined;
|
|
21
|
+
$diacriticSensitive?: boolean | undefined;
|
|
22
|
+
} | undefined;
|
|
23
|
+
$where?: string | ((item: T) => boolean) | undefined;
|
|
24
|
+
$all?: T[] | undefined;
|
|
25
|
+
$elemMatch?: T extends object ? Query<T> : FieldExpression<T> | undefined;
|
|
26
|
+
$size?: number | undefined;
|
|
27
|
+
$bitsAllClear?: any;
|
|
28
|
+
$bitsAllSet?: any;
|
|
29
|
+
$bitsAnyClear?: any;
|
|
30
|
+
$bitsAnySet?: any;
|
|
31
|
+
}
|
|
32
|
+
type Flatten<T> = T extends any[] ? T[0] : T;
|
|
33
|
+
type FlatQuery<T> = {
|
|
34
|
+
[P in keyof T]?: Flatten<T[P]> | RegExp | FieldExpression<Flatten<T[P]>>;
|
|
35
|
+
} & Record<string, any>;
|
|
36
|
+
type Query<T> = FlatQuery<T> & {
|
|
37
|
+
$or?: Query<T>[] | undefined;
|
|
38
|
+
$and?: Query<T>[] | undefined;
|
|
39
|
+
$nor?: Query<T>[] | undefined;
|
|
40
|
+
};
|
|
41
|
+
export type FlatSelector<T extends Record<string, any> = Record<string, any>> = FlatQuery<T> & {
|
|
42
|
+
$or?: never;
|
|
43
|
+
$and?: never;
|
|
44
|
+
$nor?: never;
|
|
45
|
+
};
|
|
46
|
+
type Selector<T extends Record<string, any> = Record<string, any>> = Query<T>;
|
|
47
|
+
export default Selector;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T;
|
|
2
|
+
/**
|
|
3
|
+
* Filters out falsy values (`false`, `''`, `0`, `null`, `undefined`) from an array.
|
|
4
|
+
* @template T - The type of the elements in the array.
|
|
5
|
+
* @param array - The array to filter.
|
|
6
|
+
* @returns A new array containing only the truthy values from the input array.
|
|
7
|
+
*/
|
|
8
|
+
export default function compact<T>(array: T[]): Truthy<T>[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Dependency from '../types/Dependency';
|
|
2
|
+
import type Signal from '../types/Signal';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a reactive signal for managing state and triggering dependencies.
|
|
5
|
+
* The signal holds a value and provides methods to get and set the value,
|
|
6
|
+
* with optional equality checks and dependency tracking.
|
|
7
|
+
* @template T - The type of the value held by the signal.
|
|
8
|
+
* @param dependency - An optional dependency object for tracking and notifying reactivity.
|
|
9
|
+
* @param initialValue - The initial value of the signal.
|
|
10
|
+
* @param isEqual - A custom equality function to determine if the new value is different
|
|
11
|
+
* from the current value (default is `Object.is`).
|
|
12
|
+
* @returns A signal object with `get` and `set` methods to manage the value.
|
|
13
|
+
*/
|
|
14
|
+
export default function createSignal<T>(dependency: Dependency | undefined, initialValue: T, isEqual?: (a: T, b: T) => boolean): Signal<T>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a deep clone of a value, supporting various types including arrays, objects,
|
|
3
|
+
* Maps, Sets, Dates, and RegExps. Functions are not supported and will throw an error.
|
|
4
|
+
* @template T - The type of the value to clone.
|
|
5
|
+
* @param value - The value to deep clone.
|
|
6
|
+
* @returns A deep copy of the provided value.
|
|
7
|
+
* @throws An error if the value is a function, as cloning functions is not supported.
|
|
8
|
+
*/
|
|
9
|
+
export declare function clone<T>(value: T): T;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a deep clone of an object. Uses the `structuredClone` function if available,
|
|
12
|
+
* otherwise falls back to a manual deep clone implementation.
|
|
13
|
+
* @template T - The type of the object to clone.
|
|
14
|
+
* @param obj - The object to deep clone.
|
|
15
|
+
* @returns A deep copy of the provided object.
|
|
16
|
+
*/
|
|
17
|
+
export default function deepClone<T>(obj: T): T;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the value at a specified path within an object.
|
|
3
|
+
* Supports dot and bracket notation for navigating nested properties.
|
|
4
|
+
* @template T - The type of the object to retrieve the value from.
|
|
5
|
+
* @param value - The object to navigate.
|
|
6
|
+
* @param path - The path (dot or bracket notation) to the desired value.
|
|
7
|
+
* @returns The value at the specified path, or `undefined` if the path does not exist.
|
|
8
|
+
*/
|
|
9
|
+
export default function get<T extends Record<string, any>>(value: T, path: string): any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseItem } from '../Collection/types';
|
|
2
|
+
import type { FlatSelector } from '../types/Selector';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts the matching keys for a given field in a selector.
|
|
5
|
+
* Supports serialized values and `$in` field expressions for optimization.
|
|
6
|
+
* Returns `null` if the field cannot be optimized.
|
|
7
|
+
* @template T - The type of the items in the selector.
|
|
8
|
+
* @template I - The type of the unique identifier for the items.
|
|
9
|
+
* @param field - The name of the field to extract matching keys for.
|
|
10
|
+
* @param selector - The selector object containing query criteria.
|
|
11
|
+
* @returns An array of serialized matching keys for the field, or `null` if the field
|
|
12
|
+
* cannot be optimized (e.g., if it's a `RegExp` or non-optimizable field expression).
|
|
13
|
+
*/
|
|
14
|
+
export default function getMatchingKeys<T extends BaseItem<I> = BaseItem, I = any>(field: string, selector: FlatSelector<T>): string[] | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the intersection of multiple arrays, returning an array of unique elements
|
|
3
|
+
* that are present in all the input arrays.
|
|
4
|
+
* @template T - The type of elements in the arrays.
|
|
5
|
+
* @param arrays - A variable number of arrays to compute the intersection of.
|
|
6
|
+
* @returns An array containing the unique elements found in all the input arrays.
|
|
7
|
+
* - If no arrays are provided, returns an empty array.
|
|
8
|
+
*/
|
|
9
|
+
export default function intersection<T>(...arrays: T[][]): T[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values for deep equality.
|
|
3
|
+
* @param a - The first value to compare.
|
|
4
|
+
* @param b - The second value to compare.
|
|
5
|
+
* @returns - Returns `true` if the two values are deeply equal, otherwise `false`.
|
|
6
|
+
* @example
|
|
7
|
+
* isEqual({ a: 1 }, { a: 1 }); // true
|
|
8
|
+
* isEqual([1, 2], [1, 2]); // true
|
|
9
|
+
* isEqual(new Date(0), new Date(0)); // true
|
|
10
|
+
* isEqual(/abc/, /abc/); // true
|
|
11
|
+
* isEqual({ a: 1 }, { a: 2 }); // false
|
|
12
|
+
* isEqual(null, null); // true
|
|
13
|
+
*/
|
|
14
|
+
export default function isEqual<T, K>(a: T, b: K): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FieldExpression } from '../types/Selector';
|
|
2
|
+
/**
|
|
3
|
+
* Determines whether a given object is a valid field expression.
|
|
4
|
+
* A field expression is an object containing query operators supported by MongoDB-style queries.
|
|
5
|
+
* @template T - The type of the field expression.
|
|
6
|
+
* @param expression - The object to test.
|
|
7
|
+
* @returns A boolean indicating whether the object is a valid field expression.
|
|
8
|
+
* - `true` if the object contains only recognized query operators.
|
|
9
|
+
* - `false` otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export default function isFieldExpression<T>(expression: any): expression is FieldExpression<T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type Selector from '../types/Selector';
|
|
2
|
+
type BaseItem = Record<string, any>;
|
|
3
|
+
/**
|
|
4
|
+
* Tests whether a given item matches a specified selector.
|
|
5
|
+
* Uses the `mingo` library to evaluate the query.
|
|
6
|
+
* @template T - The type of the item being tested.
|
|
7
|
+
* @param item - The item to test against the selector.
|
|
8
|
+
* @param selector - The query selector used to match the item.
|
|
9
|
+
* @returns A boolean indicating whether the item matches the selector.
|
|
10
|
+
*/
|
|
11
|
+
export default function match<T extends BaseItem = BaseItem>(item: T, selector: Selector<T>): boolean;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Modifier from '../types/Modifier';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a modifier to an object and returns a new modified object.
|
|
4
|
+
* @template T - The type of the object to be modified.
|
|
5
|
+
* @param item - The object to be modified.
|
|
6
|
+
* @param modifier - The modifier to apply. This can be any transformation logic.
|
|
7
|
+
* @returns - Returns a new object with the modifications applied.
|
|
8
|
+
* @example
|
|
9
|
+
* const item = { a: 1, b: 2 }
|
|
10
|
+
* const modifier = { $set: { b: 3, c: 4 } }
|
|
11
|
+
* const result = modify(item, modifier)
|
|
12
|
+
* // result: { a: 1, b: 3, c: 4 }
|
|
13
|
+
*/
|
|
14
|
+
export default function modify<T extends Record<string, any>>(item: T, modifier: Modifier): T;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projects the fields of an object based on a specified fields configuration.
|
|
3
|
+
* Supports inclusion (`1`) and exclusion (`0`) of specific fields. Creates a new object
|
|
4
|
+
* with the desired fields included or excluded, based on the configuration.
|
|
5
|
+
* @template T - The type of the object being projected.
|
|
6
|
+
* @param item - The original object to project fields from.
|
|
7
|
+
* @param fields - An object defining the fields to include (`1`) or exclude (`0`).
|
|
8
|
+
* - Keys are the field names, and values are either `1` (include) or `0` (exclude).
|
|
9
|
+
* @returns A new object with the specified fields included or excluded.
|
|
10
|
+
* - If all fields are set to `0`, the excluded fields are removed from the result.
|
|
11
|
+
* - If fields are set to `1`, only the included fields are retained.
|
|
12
|
+
*/
|
|
13
|
+
export default function project<T extends Record<string, any>>(item: T, fields: {
|
|
14
|
+
[P in keyof T]?: 0 | 1;
|
|
15
|
+
} & Record<string, 0 | 1>): T;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes a value into a string representation.
|
|
3
|
+
* Handles various types, including strings, numbers, booleans, dates, and objects.
|
|
4
|
+
* Falls back to JSON stringification for unsupported types.
|
|
5
|
+
* @param value - The value to serialize.
|
|
6
|
+
* - Strings are returned as-is.
|
|
7
|
+
* - Numbers and booleans are converted to their string representation.
|
|
8
|
+
* - Dates are converted to ISO string format.
|
|
9
|
+
* - Other values are stringified using `JSON.stringify`.
|
|
10
|
+
* @returns A string representation of the value.
|
|
11
|
+
*/
|
|
12
|
+
export default function serializeValue(value: any): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a value at a specified path within an object. Creates nested structures
|
|
3
|
+
* (arrays or objects) as needed to set the value at the correct location. Supports
|
|
4
|
+
* deleting the key if the value is `undefined` and the `deleteIfUndefined` flag is set to `true`.
|
|
5
|
+
* @template T - The type of the object to modify.
|
|
6
|
+
* @template K - The type of the value to set.
|
|
7
|
+
* @param obj - The object to modify. The object is mutated directly.
|
|
8
|
+
* @param path - The path (dot or bracket notation) where the value should be set.
|
|
9
|
+
* @param value - The value to set at the specified path.
|
|
10
|
+
* @param deleteIfUndefined - A boolean indicating whether to delete the key if the value is `undefined` (default: `false`).
|
|
11
|
+
* @returns The modified object.
|
|
12
|
+
*/
|
|
13
|
+
export default function set<T extends object, K>(obj: T, path: string, value: K, deleteIfUndefined?: boolean): T;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sorts an array of items based on multiple fields and their specified sort order.
|
|
3
|
+
* Uses the `fast-sort` library for efficient sorting.
|
|
4
|
+
* @template T - The type of the items in the array.
|
|
5
|
+
* @param items - The array of items to be sorted.
|
|
6
|
+
* @param sortFields - An object defining the sort order for each field.
|
|
7
|
+
* - Keys are the field names, and values are either `1` (ascending) or `-1` (descending).
|
|
8
|
+
* @returns A new array of items sorted based on the specified fields and their order.
|
|
9
|
+
*/
|
|
10
|
+
export default function sortItems<T extends Record<string, any>>(items: T[], sortFields: {
|
|
11
|
+
[P in keyof T]?: -1 | 1;
|
|
12
|
+
} & Record<string, -1 | 1>): T[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters an array to ensure unique values based on a specified key or transformation function.
|
|
3
|
+
* @template T - The type of the elements in the array.
|
|
4
|
+
* @param arr - The array to filter for unique values.
|
|
5
|
+
* @param fn - A key or transformation function to determine uniqueness.
|
|
6
|
+
* - If a key is provided, it will use the corresponding property of each element for uniqueness.
|
|
7
|
+
* - If a function is provided, it will use the return value of the function applied to each element for uniqueness.
|
|
8
|
+
* @returns A new array containing only unique elements based on the specified key or transformation.
|
|
9
|
+
*/
|
|
10
|
+
export default function uniqueBy<T>(arr: T[], fn: keyof T | ((item: T) => any)): T[];
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signaldb/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON interface to places such as localStorage.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "rimraf dist && vite build"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/maxnowack/signaldb.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://signaldb.js.org",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"client-database",
|
|
15
|
+
"client",
|
|
16
|
+
"database",
|
|
17
|
+
"local-database",
|
|
18
|
+
"meteor",
|
|
19
|
+
"minimongo",
|
|
20
|
+
"mongodb",
|
|
21
|
+
"offline-first",
|
|
22
|
+
"optimistic-ui",
|
|
23
|
+
"reactive",
|
|
24
|
+
"replication",
|
|
25
|
+
"synchronization",
|
|
26
|
+
"tracker",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"author": "Max Nowack <max.nowack@gmail.com>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.mjs",
|
|
36
|
+
"require": "./dist/index.cjs.js",
|
|
37
|
+
"default": "./dist/index.cjs.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"main": "./dist/index.cjs.js",
|
|
41
|
+
"module": "./dist/index.mjs",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
"*": [
|
|
46
|
+
"./dist/*",
|
|
47
|
+
"./dist/index.d.ts"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist"
|
|
53
|
+
],
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"fast-sort": "^3.4.1",
|
|
56
|
+
"mingo": "^6.5.1"
|
|
57
|
+
}
|
|
58
|
+
}
|