localdb-ces6q 0.0.2
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/LICENSE +21 -0
- package/README.md +2 -0
- package/package.json +49 -0
- package/src/LocalDB.d.ts +102 -0
- package/src/LocalDB.js +966 -0
- package/src/LocalDBDocument.d.ts +18 -0
- package/src/LocalDBDocument.js +55 -0
- package/src/LocalDBState.d.ts +14 -0
- package/src/LocalDBState.js +46 -0
- package/src/comparators.d.ts +15 -0
- package/src/comparators.js +105 -0
- package/src/hooks.d.ts +5 -0
- package/src/hooks.js +34 -0
- package/src/types.d.ts +100 -0
- package/src/types.js +1 -0
- package/test/LocalDB.test.d.ts +1 -0
- package/test/LocalDB.test.js +1137 -0
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            import { PubSub } from 'util-3gcvv/class/PubSub.js';
         | 
| 2 | 
            +
            import type { KeyOf } from 'util-3gcvv/types/types.js';
         | 
| 3 | 
            +
            export declare class LocalDBDocument<Data = any> extends PubSub<[
         | 
| 4 | 
            +
                Data,
         | 
| 5 | 
            +
                Data,
         | 
| 6 | 
            +
                Array<KeyOf<Data>>
         | 
| 7 | 
            +
            ]> {
         | 
| 8 | 
            +
                private _data;
         | 
| 9 | 
            +
                constructor(data: Data);
         | 
| 10 | 
            +
                toJSON(): Data;
         | 
| 11 | 
            +
                equals(other: LocalDBDocument<Data>): boolean;
         | 
| 12 | 
            +
                destroy(): void;
         | 
| 13 | 
            +
                get id(): string;
         | 
| 14 | 
            +
                get data(): Data;
         | 
| 15 | 
            +
                set data(next: Data);
         | 
| 16 | 
            +
                set(next: Data): void;
         | 
| 17 | 
            +
                update(update: Partial<Data>): void;
         | 
| 18 | 
            +
            }
         | 
| @@ -0,0 +1,55 @@ | |
| 1 | 
            +
            import { PubSub } from 'util-3gcvv/class/PubSub.js';
         | 
| 2 | 
            +
            import { deepEqual } from 'util-3gcvv/deepEqual.js';
         | 
| 3 | 
            +
            import { objectKeys } from 'util-3gcvv/object.js';
         | 
| 4 | 
            +
            export class LocalDBDocument extends PubSub {
         | 
| 5 | 
            +
                constructor(data) {
         | 
| 6 | 
            +
                    super();
         | 
| 7 | 
            +
                    this._data = data;
         | 
| 8 | 
            +
                }
         | 
| 9 | 
            +
                toJSON() {
         | 
| 10 | 
            +
                    return this._data;
         | 
| 11 | 
            +
                }
         | 
| 12 | 
            +
                equals(other) {
         | 
| 13 | 
            +
                    return deepEqual(this._data, other._data);
         | 
| 14 | 
            +
                }
         | 
| 15 | 
            +
                destroy() {
         | 
| 16 | 
            +
                    super.destroy();
         | 
| 17 | 
            +
                    this._data = null;
         | 
| 18 | 
            +
                }
         | 
| 19 | 
            +
                get id() {
         | 
| 20 | 
            +
                    return this._data.id;
         | 
| 21 | 
            +
                }
         | 
| 22 | 
            +
                get data() {
         | 
| 23 | 
            +
                    return this._data;
         | 
| 24 | 
            +
                }
         | 
| 25 | 
            +
                set data(next) {
         | 
| 26 | 
            +
                    this.set(next);
         | 
| 27 | 
            +
                }
         | 
| 28 | 
            +
                set(next) {
         | 
| 29 | 
            +
                    return this.update(next);
         | 
| 30 | 
            +
                }
         | 
| 31 | 
            +
                update(update) {
         | 
| 32 | 
            +
                    const prev = this._data;
         | 
| 33 | 
            +
                    const keys = objectKeys(update);
         | 
| 34 | 
            +
                    const changed = {};
         | 
| 35 | 
            +
                    const changedKeys = [];
         | 
| 36 | 
            +
                    const next = { ...prev };
         | 
| 37 | 
            +
                    for (let i = 0, il = keys.length; i < il; i += 1) {
         | 
| 38 | 
            +
                        const key = keys[i];
         | 
| 39 | 
            +
                        if (!deepEqual(update[key], prev[key])) {
         | 
| 40 | 
            +
                            changed[key] = update[key];
         | 
| 41 | 
            +
                            if (update[key] === undefined) {
         | 
| 42 | 
            +
                                delete next[key];
         | 
| 43 | 
            +
                            }
         | 
| 44 | 
            +
                            else {
         | 
| 45 | 
            +
                                next[key] = update[key];
         | 
| 46 | 
            +
                            }
         | 
| 47 | 
            +
                            changedKeys.push(key);
         | 
| 48 | 
            +
                        }
         | 
| 49 | 
            +
                    }
         | 
| 50 | 
            +
                    if (changedKeys.length) {
         | 
| 51 | 
            +
                        this._data = next;
         | 
| 52 | 
            +
                        this.emit(next, prev, changedKeys);
         | 
| 53 | 
            +
                    }
         | 
| 54 | 
            +
                }
         | 
| 55 | 
            +
            }
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            import { SmartState } from 'util-3gcvv/class/SmartState.js';
         | 
| 2 | 
            +
            import type { IDBOperationHistoryItem } from './types.js';
         | 
| 3 | 
            +
            export interface ILocalDBStateProps {
         | 
| 4 | 
            +
                history: IDBOperationHistoryItem[][];
         | 
| 5 | 
            +
                historyIndex: number;
         | 
| 6 | 
            +
                canRedo: boolean;
         | 
| 7 | 
            +
                canUndo: boolean;
         | 
| 8 | 
            +
                redoItem: IDBOperationHistoryItem[] | undefined;
         | 
| 9 | 
            +
                undoItem: IDBOperationHistoryItem[] | undefined;
         | 
| 10 | 
            +
            }
         | 
| 11 | 
            +
            type ComputedKeys = 'canUndo' | 'canRedo' | 'redoItem' | 'undoItem';
         | 
| 12 | 
            +
            export declare const LocalDBState: import("util-3gcvv/class/SmartState.js").SmartStateConstructor<ILocalDBStateProps, ComputedKeys, {}, import("util-3gcvv/class/SmartState.js").IEmptyInterface>;
         | 
| 13 | 
            +
            export type LocalDBState = SmartState<ILocalDBStateProps, ComputedKeys, {}>;
         | 
| 14 | 
            +
            export {};
         | 
| @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            import { defineSmartState } from 'util-3gcvv/class/SmartState.js';
         | 
| 2 | 
            +
            export const LocalDBState = defineSmartState({
         | 
| 3 | 
            +
                statics: {
         | 
| 4 | 
            +
                    name: 'LocalDBState',
         | 
| 5 | 
            +
                    fromJSON: (json) => new LocalDBState(json.state, json.config),
         | 
| 6 | 
            +
                },
         | 
| 7 | 
            +
                properties: {
         | 
| 8 | 
            +
                    history: { type: 'array', item: 'object' },
         | 
| 9 | 
            +
                    historyIndex: { type: 'number' },
         | 
| 10 | 
            +
                },
         | 
| 11 | 
            +
                computed: {
         | 
| 12 | 
            +
                    // []
         | 
| 13 | 
            +
                    // [a, b, c, d]
         | 
| 14 | 
            +
                    canRedo: {
         | 
| 15 | 
            +
                        type: 'boolean',
         | 
| 16 | 
            +
                        deps: ['redoItem'],
         | 
| 17 | 
            +
                        get({ redoItem }) {
         | 
| 18 | 
            +
                            return redoItem != null;
         | 
| 19 | 
            +
                        },
         | 
| 20 | 
            +
                    },
         | 
| 21 | 
            +
                    canUndo: {
         | 
| 22 | 
            +
                        type: 'boolean',
         | 
| 23 | 
            +
                        deps: ['undoItem'],
         | 
| 24 | 
            +
                        get({ undoItem }) {
         | 
| 25 | 
            +
                            return undoItem != null;
         | 
| 26 | 
            +
                        },
         | 
| 27 | 
            +
                    },
         | 
| 28 | 
            +
                    redoItem: {
         | 
| 29 | 
            +
                        type: 'array',
         | 
| 30 | 
            +
                        item: 'object',
         | 
| 31 | 
            +
                        deps: ['history', 'historyIndex'],
         | 
| 32 | 
            +
                        get({ history, historyIndex }) {
         | 
| 33 | 
            +
                            return history[historyIndex];
         | 
| 34 | 
            +
                        },
         | 
| 35 | 
            +
                    },
         | 
| 36 | 
            +
                    undoItem: {
         | 
| 37 | 
            +
                        type: 'array',
         | 
| 38 | 
            +
                        item: 'object',
         | 
| 39 | 
            +
                        deps: ['history', 'historyIndex'],
         | 
| 40 | 
            +
                        get({ history, historyIndex }) {
         | 
| 41 | 
            +
                            return history[historyIndex - 1];
         | 
| 42 | 
            +
                        },
         | 
| 43 | 
            +
                    },
         | 
| 44 | 
            +
                },
         | 
| 45 | 
            +
                drafts: [],
         | 
| 46 | 
            +
            });
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            export declare const compareNil: (a: any, b: any) => number | null;
         | 
| 2 | 
            +
            export declare const defaultComparators: {
         | 
| 3 | 
            +
                string: {
         | 
| 4 | 
            +
                    asc: (a: string | null | undefined, b: string | null | undefined) => number;
         | 
| 5 | 
            +
                    desc: (a: string | null | undefined, b: string | null | undefined) => number;
         | 
| 6 | 
            +
                };
         | 
| 7 | 
            +
                number: {
         | 
| 8 | 
            +
                    asc: (a: number | null | undefined, b: number | null | undefined) => number;
         | 
| 9 | 
            +
                    desc: (a: number | null | undefined, b: number | null | undefined) => number;
         | 
| 10 | 
            +
                };
         | 
| 11 | 
            +
                boolean: {
         | 
| 12 | 
            +
                    asc: (a: boolean | null | undefined, b: boolean | null | undefined) => number;
         | 
| 13 | 
            +
                    desc: (a: boolean | null | undefined, b: boolean | null | undefined) => number;
         | 
| 14 | 
            +
                };
         | 
| 15 | 
            +
            };
         | 
| @@ -0,0 +1,105 @@ | |
| 1 | 
            +
            export const compareNil = (a, b) => {
         | 
| 2 | 
            +
                if (a === b)
         | 
| 3 | 
            +
                    return 0;
         | 
| 4 | 
            +
                if (a === undefined)
         | 
| 5 | 
            +
                    return 1;
         | 
| 6 | 
            +
                if (b === undefined)
         | 
| 7 | 
            +
                    return -1;
         | 
| 8 | 
            +
                if (a === null)
         | 
| 9 | 
            +
                    return 1;
         | 
| 10 | 
            +
                if (b === null)
         | 
| 11 | 
            +
                    return -1;
         | 
| 12 | 
            +
                return null;
         | 
| 13 | 
            +
            };
         | 
| 14 | 
            +
            export const defaultComparators = {
         | 
| 15 | 
            +
                string: {
         | 
| 16 | 
            +
                    // a -> z
         | 
| 17 | 
            +
                    asc: (a, b) => {
         | 
| 18 | 
            +
                        if (a === b)
         | 
| 19 | 
            +
                            return 0;
         | 
| 20 | 
            +
                        if (a === undefined)
         | 
| 21 | 
            +
                            return 1;
         | 
| 22 | 
            +
                        if (b === undefined)
         | 
| 23 | 
            +
                            return -1;
         | 
| 24 | 
            +
                        if (a === null)
         | 
| 25 | 
            +
                            return 1;
         | 
| 26 | 
            +
                        if (b === null)
         | 
| 27 | 
            +
                            return -1;
         | 
| 28 | 
            +
                        return a.localeCompare(b);
         | 
| 29 | 
            +
                    },
         | 
| 30 | 
            +
                    // z -> a
         | 
| 31 | 
            +
                    desc: (a, b) => {
         | 
| 32 | 
            +
                        if (a === b)
         | 
| 33 | 
            +
                            return 0;
         | 
| 34 | 
            +
                        if (a === undefined)
         | 
| 35 | 
            +
                            return 1;
         | 
| 36 | 
            +
                        if (b === undefined)
         | 
| 37 | 
            +
                            return -1;
         | 
| 38 | 
            +
                        if (a === null)
         | 
| 39 | 
            +
                            return 1;
         | 
| 40 | 
            +
                        if (b === null)
         | 
| 41 | 
            +
                            return -1;
         | 
| 42 | 
            +
                        return b.localeCompare(a);
         | 
| 43 | 
            +
                    },
         | 
| 44 | 
            +
                },
         | 
| 45 | 
            +
                number: {
         | 
| 46 | 
            +
                    // 0 -> 9
         | 
| 47 | 
            +
                    asc: (a, b) => {
         | 
| 48 | 
            +
                        if (a === b)
         | 
| 49 | 
            +
                            return 0;
         | 
| 50 | 
            +
                        if (a === undefined)
         | 
| 51 | 
            +
                            return 1;
         | 
| 52 | 
            +
                        if (b === undefined)
         | 
| 53 | 
            +
                            return -1;
         | 
| 54 | 
            +
                        if (a === null)
         | 
| 55 | 
            +
                            return 1;
         | 
| 56 | 
            +
                        if (b === null)
         | 
| 57 | 
            +
                            return -1;
         | 
| 58 | 
            +
                        return a - b;
         | 
| 59 | 
            +
                    },
         | 
| 60 | 
            +
                    // 9 -> 0
         | 
| 61 | 
            +
                    desc: (a, b) => {
         | 
| 62 | 
            +
                        if (a === b)
         | 
| 63 | 
            +
                            return 0;
         | 
| 64 | 
            +
                        if (a === undefined)
         | 
| 65 | 
            +
                            return 1;
         | 
| 66 | 
            +
                        if (b === undefined)
         | 
| 67 | 
            +
                            return -1;
         | 
| 68 | 
            +
                        if (a === null)
         | 
| 69 | 
            +
                            return 1;
         | 
| 70 | 
            +
                        if (b === null)
         | 
| 71 | 
            +
                            return -1;
         | 
| 72 | 
            +
                        return b - a;
         | 
| 73 | 
            +
                    },
         | 
| 74 | 
            +
                },
         | 
| 75 | 
            +
                boolean: {
         | 
| 76 | 
            +
                    // false -> true
         | 
| 77 | 
            +
                    asc: (a, b) => {
         | 
| 78 | 
            +
                        if (a === b)
         | 
| 79 | 
            +
                            return 0;
         | 
| 80 | 
            +
                        if (a === undefined)
         | 
| 81 | 
            +
                            return 1;
         | 
| 82 | 
            +
                        if (b === undefined)
         | 
| 83 | 
            +
                            return -1;
         | 
| 84 | 
            +
                        if (a === null)
         | 
| 85 | 
            +
                            return 1;
         | 
| 86 | 
            +
                        if (b === null)
         | 
| 87 | 
            +
                            return -1;
         | 
| 88 | 
            +
                        return (a ? 1 : 0) - (b ? 1 : 0);
         | 
| 89 | 
            +
                    },
         | 
| 90 | 
            +
                    // true -> false
         | 
| 91 | 
            +
                    desc: (a, b) => {
         | 
| 92 | 
            +
                        if (a === b)
         | 
| 93 | 
            +
                            return 0;
         | 
| 94 | 
            +
                        if (a === undefined)
         | 
| 95 | 
            +
                            return 1;
         | 
| 96 | 
            +
                        if (b === undefined)
         | 
| 97 | 
            +
                            return -1;
         | 
| 98 | 
            +
                        if (a === null)
         | 
| 99 | 
            +
                            return 1;
         | 
| 100 | 
            +
                        if (b === null)
         | 
| 101 | 
            +
                            return -1;
         | 
| 102 | 
            +
                        return (b ? 1 : 0) - (a ? 1 : 0);
         | 
| 103 | 
            +
                    },
         | 
| 104 | 
            +
                },
         | 
| 105 | 
            +
            };
         | 
    
        package/src/hooks.d.ts
    ADDED
    
    | @@ -0,0 +1,5 @@ | |
| 1 | 
            +
            import type { LocalDB } from './LocalDB.js';
         | 
| 2 | 
            +
            import type { IDocument } from './types.js';
         | 
| 3 | 
            +
            import type { KeyOf } from 'util-3gcvv/types/types.js';
         | 
| 4 | 
            +
            export declare const useLocalDbDoc: <T extends Record<string, IDocument>, K extends KeyOf<T>>(db: LocalDB<T>, col: K, id: string, deps?: any[]) => T[K] | undefined;
         | 
| 5 | 
            +
            export declare const useLocalDbDocs: <T extends Record<string, IDocument>, K extends KeyOf<T>>(db: LocalDB<T>, col: K, ids: string[] | null | undefined, deps?: any[]) => (T[K] | undefined)[];
         | 
    
        package/src/hooks.js
    ADDED
    
    | @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            import { useEffect, useRef, useState } from 'react';
         | 
| 2 | 
            +
            import { arraysEqual } from 'util-3gcvv/array.js';
         | 
| 3 | 
            +
            export const useLocalDbDoc = (db, col, id, deps = [db, col, id]) => {
         | 
| 4 | 
            +
                const [doc, setDoc] = useState(() => db.doc(col, id));
         | 
| 5 | 
            +
                useEffect(() => {
         | 
| 6 | 
            +
                    setDoc(db.doc(col, id));
         | 
| 7 | 
            +
                    return db.subToDoc(col, id, setDoc);
         | 
| 8 | 
            +
                    // eslint-disable-next-line react-hooks/exhaustive-deps
         | 
| 9 | 
            +
                }, deps);
         | 
| 10 | 
            +
                return doc;
         | 
| 11 | 
            +
            };
         | 
| 12 | 
            +
            export const useLocalDbDocs = (db, col, ids, deps = [db, col, ids]) => {
         | 
| 13 | 
            +
                const [docs, setDocs] = useState(() => ids?.length ? db.docs(col, ids) : []);
         | 
| 14 | 
            +
                const docsRef = useRef(docs);
         | 
| 15 | 
            +
                useEffect(() => {
         | 
| 16 | 
            +
                    const newDocs = ids?.length ? db.docs(col, ids) : [];
         | 
| 17 | 
            +
                    if (!arraysEqual(docsRef.current, newDocs)) {
         | 
| 18 | 
            +
                        docsRef.current = newDocs;
         | 
| 19 | 
            +
                        setDocs(newDocs);
         | 
| 20 | 
            +
                    }
         | 
| 21 | 
            +
                    if (!ids?.length)
         | 
| 22 | 
            +
                        return;
         | 
| 23 | 
            +
                    return db.subToCol(col, (next, prev, change) => {
         | 
| 24 | 
            +
                        for (let i = 0, il = ids.length; i < il; i += 1) {
         | 
| 25 | 
            +
                            if (ids[i] in change) {
         | 
| 26 | 
            +
                                docsRef.current = ids.map((id) => next[id]);
         | 
| 27 | 
            +
                                return setDocs(docsRef.current);
         | 
| 28 | 
            +
                            }
         | 
| 29 | 
            +
                        }
         | 
| 30 | 
            +
                    });
         | 
| 31 | 
            +
                    // eslint-disable-next-line react-hooks/exhaustive-deps
         | 
| 32 | 
            +
                }, deps);
         | 
| 33 | 
            +
                return docs;
         | 
| 34 | 
            +
            };
         | 
    
        package/src/types.d.ts
    ADDED
    
    | @@ -0,0 +1,100 @@ | |
| 1 | 
            +
            import type { LocalDB } from './LocalDB.js';
         | 
| 2 | 
            +
            import type { KeyOf } from 'util-3gcvv/types/types.js';
         | 
| 3 | 
            +
            export interface IDocument {
         | 
| 4 | 
            +
                id: string;
         | 
| 5 | 
            +
            }
         | 
| 6 | 
            +
            export type Collections<CollectionTypes extends Record<string, IDocument>> = {
         | 
| 7 | 
            +
                [ColName in KeyOf<CollectionTypes>]: {
         | 
| 8 | 
            +
                    [id in string]: CollectionTypes[ColName];
         | 
| 9 | 
            +
                };
         | 
| 10 | 
            +
            };
         | 
| 11 | 
            +
            export type CollectionsChange<CollectionTypes extends Record<string, IDocument>> = {
         | 
| 12 | 
            +
                [ColName in KeyOf<CollectionTypes>]?: {
         | 
| 13 | 
            +
                    [id in string]: Partial<CollectionTypes[ColName]> | null;
         | 
| 14 | 
            +
                };
         | 
| 15 | 
            +
            };
         | 
| 16 | 
            +
            export type CollectionsChangeMap<CollectionTypes extends Record<string, IDocument>> = {
         | 
| 17 | 
            +
                [ColName in KeyOf<CollectionTypes>]?: {
         | 
| 18 | 
            +
                    [Field in KeyOf<CollectionTypes[ColName]>]: true;
         | 
| 19 | 
            +
                };
         | 
| 20 | 
            +
            };
         | 
| 21 | 
            +
            export type Collection<CollectionTypes extends Record<string, IDocument>, ColName extends KeyOf<CollectionTypes>> = Record<string, CollectionTypes[ColName]>;
         | 
| 22 | 
            +
            export type ICollectionFieldsConfig<Doc extends IDocument> = {
         | 
| 23 | 
            +
                [P in KeyOf<Doc>]: {
         | 
| 24 | 
            +
                    type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'boolean[]' | 'number[]' | 'string[]' | 'array[]' | 'object[]';
         | 
| 25 | 
            +
                    nullable?: boolean;
         | 
| 26 | 
            +
                    normalize?(next: Doc[P], doc: Doc): Doc[P];
         | 
| 27 | 
            +
                    equals?(a: Doc[P], b: Doc[P]): boolean;
         | 
| 28 | 
            +
                    compare?(a: Doc[P] | null | undefined, b: Doc[P] | null | undefined): number;
         | 
| 29 | 
            +
                    index?: 'asc' | 'desc';
         | 
| 30 | 
            +
                };
         | 
| 31 | 
            +
            };
         | 
| 32 | 
            +
            export interface ICollectionConfig<CollectionTypes extends Record<string, IDocument>, Doc extends IDocument> {
         | 
| 33 | 
            +
                localStorageKey?: string;
         | 
| 34 | 
            +
                localStorageSetWait?: number;
         | 
| 35 | 
            +
                remoteStorageKey?: string;
         | 
| 36 | 
            +
                remoteStorageSetWait?: number;
         | 
| 37 | 
            +
                indexes?: Array<KeyOf<Doc> | Array<KeyOf<Doc>>>;
         | 
| 38 | 
            +
                idFields?: Array<KeyOf<Doc>>;
         | 
| 39 | 
            +
                fields: ICollectionFieldsConfig<Doc>;
         | 
| 40 | 
            +
                computes?: Array<{
         | 
| 41 | 
            +
                    deps: Array<KeyOf<Doc>>;
         | 
| 42 | 
            +
                    mutates: Array<KeyOf<Doc>>;
         | 
| 43 | 
            +
                    compute: (next: Doc, prev: Doc) => Partial<Doc> | null;
         | 
| 44 | 
            +
                }>;
         | 
| 45 | 
            +
                foreignComputes?: Array<{
         | 
| 46 | 
            +
                    mutates: Array<KeyOf<CollectionTypes>>;
         | 
| 47 | 
            +
                    compute: (db: LocalDB<CollectionTypes>, updates: Array<{
         | 
| 48 | 
            +
                        next: Doc | null;
         | 
| 49 | 
            +
                        prev: Doc | null;
         | 
| 50 | 
            +
                    }>) => void;
         | 
| 51 | 
            +
                }>;
         | 
| 52 | 
            +
            }
         | 
| 53 | 
            +
            export type ICollectionsConfig<CollectionTypes extends Record<string, IDocument>> = {
         | 
| 54 | 
            +
                [ColName in KeyOf<CollectionTypes>]: ICollectionConfig<CollectionTypes, CollectionTypes[ColName]>;
         | 
| 55 | 
            +
            };
         | 
| 56 | 
            +
            export type ICollectionsFields<CollectionTypes extends Record<string, IDocument>> = {
         | 
| 57 | 
            +
                [ColName in KeyOf<CollectionTypes>]: Array<KeyOf<CollectionTypes[ColName]>>;
         | 
| 58 | 
            +
            };
         | 
| 59 | 
            +
            export type FieldListener<CollectionTypes extends Record<string, IDocument>, ColName extends KeyOf<CollectionTypes>, FieldName extends KeyOf<CollectionTypes[ColName]>> = (nextField: CollectionTypes[ColName][FieldName], prevField: CollectionTypes[ColName][FieldName], nextDoc: CollectionTypes[ColName], prevDoc: CollectionTypes[ColName], context: IDBTxContext) => void;
         | 
| 60 | 
            +
            export type DocListener<CollectionTypes extends Record<string, IDocument>, ColName extends KeyOf<CollectionTypes>> = (nextDoc: CollectionTypes[ColName], prevDoc: CollectionTypes[ColName], change: Partial<CollectionTypes[ColName]> | null, context: IDBTxContext) => void;
         | 
| 61 | 
            +
            export type ColListener<CollectionTypes extends Record<string, IDocument>, ColName extends KeyOf<CollectionTypes>> = (nextCol: Record<string, CollectionTypes[ColName]>, prevCol: Record<string, CollectionTypes[ColName]>, change: CollectionsChange<CollectionTypes>[ColName], changedFields: CollectionsChangeMap<CollectionTypes>[ColName], context: IDBTxContext) => void;
         | 
| 62 | 
            +
            export type DBListener<CollectionTypes extends Record<string, IDocument>> = (nextDb: Collections<CollectionTypes>, prevDb: Collections<CollectionTypes>, change: CollectionsChange<CollectionTypes>, changedFields: CollectionsChangeMap<CollectionTypes>, context: IDBTxContext) => void;
         | 
| 63 | 
            +
            export interface IDBOperations<CollectionTypes extends Record<string, IDocument> = any> {
         | 
| 64 | 
            +
                setDoc<ColName extends KeyOf<CollectionTypes>>(colName: ColName, doc: CollectionTypes[ColName]): void;
         | 
| 65 | 
            +
                setDocs<ColName extends KeyOf<CollectionTypes>>(colName: ColName, docs: Array<CollectionTypes[ColName]>): void;
         | 
| 66 | 
            +
                updateDoc<ColName extends KeyOf<CollectionTypes>>(colName: ColName, id: string, updater: Partial<CollectionTypes[ColName]> | ((prev: CollectionTypes[ColName]) => Partial<CollectionTypes[ColName]> | null | undefined)): void;
         | 
| 67 | 
            +
                updateDocs<ColName extends KeyOf<CollectionTypes>>(colName: ColName, updater: Record<string, Partial<CollectionTypes[ColName]>> | ((prev: Collections<CollectionTypes>[ColName]) => Record<string, Partial<CollectionTypes[ColName]> | null | undefined> | null | undefined)): void;
         | 
| 68 | 
            +
                deleteDoc<ColName extends KeyOf<CollectionTypes>>(colName: ColName, id: string): void;
         | 
| 69 | 
            +
                deleteDocs<ColName extends KeyOf<CollectionTypes>>(colName: ColName, ids: string[]): void;
         | 
| 70 | 
            +
            }
         | 
| 71 | 
            +
            export type DBOpType = KeyOf<IDBOperations>;
         | 
| 72 | 
            +
            export type IDBOperation = {
         | 
| 73 | 
            +
                [Op in KeyOf<IDBOperations>]: {
         | 
| 74 | 
            +
                    op: Op;
         | 
| 75 | 
            +
                    args: Parameters<IDBOperations[Op]>;
         | 
| 76 | 
            +
                };
         | 
| 77 | 
            +
            }[KeyOf<IDBOperations>];
         | 
| 78 | 
            +
            export interface IDBOperationHistoryItem {
         | 
| 79 | 
            +
                undo: IDBOperation;
         | 
| 80 | 
            +
                redo: IDBOperation;
         | 
| 81 | 
            +
            }
         | 
| 82 | 
            +
            export interface IDBTxContext {
         | 
| 83 | 
            +
                [key: string]: any;
         | 
| 84 | 
            +
            }
         | 
| 85 | 
            +
            export interface IDBTxOptions {
         | 
| 86 | 
            +
                undoable?: boolean;
         | 
| 87 | 
            +
                noEvent?: boolean;
         | 
| 88 | 
            +
                ignoreNotFound?: boolean;
         | 
| 89 | 
            +
                idempotent?: boolean;
         | 
| 90 | 
            +
                context?: IDBTxContext;
         | 
| 91 | 
            +
            }
         | 
| 92 | 
            +
            export interface IDBQuery<CollectionTypes extends Record<string, IDocument>, ColName extends KeyOf<CollectionTypes>> {
         | 
| 93 | 
            +
                collection: ColName;
         | 
| 94 | 
            +
                orderBy: string;
         | 
| 95 | 
            +
                limit: number;
         | 
| 96 | 
            +
                endAfter?: any;
         | 
| 97 | 
            +
                endAt?: any;
         | 
| 98 | 
            +
                startAfter?: any;
         | 
| 99 | 
            +
                startAt?: any;
         | 
| 100 | 
            +
            }
         | 
    
        package/src/types.js
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            export {};
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            export {};
         |