@verdant-web/store 3.4.0-next.0 → 3.4.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/esm/BackoffScheduler.d.ts +19 -0
- package/dist/esm/DocumentManager.d.ts +28 -0
- package/dist/esm/FakeWeakRef.d.ts +11 -0
- package/dist/esm/IDBService.d.ts +30 -0
- package/dist/esm/UndoHistory.d.ts +16 -0
- package/dist/esm/__tests__/batching.test.d.ts +1 -0
- package/dist/esm/__tests__/documents.test.d.ts +1 -0
- package/dist/esm/__tests__/fixtures/testStorage.d.ts +76 -0
- package/dist/esm/__tests__/legacyOids.test.d.ts +1 -0
- package/dist/esm/__tests__/mutations.test.d.ts +1 -0
- package/dist/esm/__tests__/queries.test.d.ts +1 -0
- package/dist/esm/__tests__/setup/indexedDB.d.ts +1 -0
- package/dist/esm/__tests__/undo.test.d.ts +1 -0
- package/dist/esm/backup.d.ts +10 -0
- package/dist/esm/client/Client.d.ts +98 -0
- package/dist/esm/client/ClientDescriptor.d.ts +76 -0
- package/dist/esm/client/constants.d.ts +1 -0
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/context.d.ts +38 -0
- package/dist/esm/entities/Entity.d.ts +148 -0
- package/dist/esm/entities/Entity.test.d.ts +1 -0
- package/dist/esm/entities/EntityCache.d.ts +15 -0
- package/dist/esm/entities/EntityMetadata.d.ts +68 -0
- package/dist/esm/entities/EntityStore.d.ts +81 -0
- package/dist/esm/entities/OperationBatcher.d.ts +52 -0
- package/dist/esm/entities/types.d.ts +103 -0
- package/dist/esm/files/EntityFile.d.ts +35 -0
- package/dist/esm/files/FileManager.d.ts +47 -0
- package/dist/esm/files/FileStorage.d.ts +39 -0
- package/dist/esm/files/utils.d.ts +10 -0
- package/dist/esm/files/utils.test.d.ts +1 -0
- package/dist/esm/idb.d.ts +13 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/metadata/AckInfoStore.d.ts +10 -0
- package/dist/esm/metadata/BaselinesStore.d.ts +40 -0
- package/dist/esm/metadata/LocalReplicaStore.d.ts +18 -0
- package/dist/esm/metadata/MessageCreator.d.ts +19 -0
- package/dist/esm/metadata/Metadata.d.ts +135 -0
- package/dist/esm/metadata/OperationsStore.d.ts +62 -0
- package/dist/esm/metadata/SchemaStore.d.ts +9 -0
- package/dist/esm/metadata/openMetadataDatabase.d.ts +19 -0
- package/dist/esm/migration/db.d.ts +8 -0
- package/dist/esm/migration/errors.d.ts +5 -0
- package/dist/esm/migration/openDatabase.d.ts +20 -0
- package/dist/esm/migration/paths.d.ts +6 -0
- package/dist/esm/migration/paths.test.d.ts +1 -0
- package/dist/esm/queries/BaseQuery.d.ts +53 -0
- package/dist/esm/queries/CollectionQueries.d.ts +55 -0
- package/dist/esm/queries/FindAllQuery.d.ts +12 -0
- package/dist/esm/queries/FindInfiniteQuery.d.ts +19 -0
- package/dist/esm/queries/FindOneQuery.d.ts +12 -0
- package/dist/esm/queries/FindPageQuery.d.ts +24 -0
- package/dist/esm/queries/GetQuery.d.ts +10 -0
- package/dist/esm/queries/QueryCache.d.ts +17 -0
- package/dist/esm/queries/QueryableStorage.d.ts +20 -0
- package/dist/esm/queries/dbQueries.d.ts +22 -0
- package/dist/esm/queries/keys.d.ts +10 -0
- package/dist/esm/queries/ranges.d.ts +2 -0
- package/dist/esm/queries/types.d.ts +6 -0
- package/dist/esm/queries/utils.d.ts +3 -0
- package/dist/esm/sync/FileSync.d.ts +24 -0
- package/dist/esm/sync/Heartbeat.d.ts +25 -0
- package/dist/esm/sync/PresenceManager.d.ts +55 -0
- package/dist/esm/sync/PushPullSync.d.ts +39 -0
- package/dist/esm/sync/ServerSyncEndpointProvider.d.ts +34 -0
- package/dist/esm/sync/Sync.d.ts +160 -0
- package/dist/esm/sync/WebSocketSync.d.ts +44 -0
- package/dist/esm/types.d.ts +12 -0
- package/dist/esm/utils/Disposable.d.ts +6 -0
- package/dist/esm/utils/Resolvable.d.ts +8 -0
- package/dist/esm/vanilla.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ClientMessage, DocumentBaseline, EventSubscriber, FileRef, HybridLogicalClockTimestampProvider, ObjectIdentifier, Operation, PatchCreator, StorageSchema } from '@verdant-web/common';
|
|
2
|
+
import { AckInfoStore } from './AckInfoStore.js';
|
|
3
|
+
import { BaselinesStore } from './BaselinesStore.js';
|
|
4
|
+
import { LocalReplicaInfo, LocalReplicaStore } from './LocalReplicaStore.js';
|
|
5
|
+
import { MessageCreator } from './MessageCreator.js';
|
|
6
|
+
import { OperationsStore } from './OperationsStore.js';
|
|
7
|
+
import { SchemaStore } from './SchemaStore.js';
|
|
8
|
+
import { Context } from '../context.js';
|
|
9
|
+
export interface ExportData {
|
|
10
|
+
operations: Operation[];
|
|
11
|
+
baselines: DocumentBaseline[];
|
|
12
|
+
localReplica: LocalReplicaInfo;
|
|
13
|
+
schema: StorageSchema;
|
|
14
|
+
}
|
|
15
|
+
export declare class Metadata extends EventSubscriber<{
|
|
16
|
+
message: (message: ClientMessage) => void;
|
|
17
|
+
rebase: (baselines: DocumentBaseline[]) => void;
|
|
18
|
+
filesDeleted: (files: FileRef[]) => void;
|
|
19
|
+
}> {
|
|
20
|
+
readonly operations: OperationsStore;
|
|
21
|
+
readonly baselines: BaselinesStore;
|
|
22
|
+
readonly localReplica: LocalReplicaStore;
|
|
23
|
+
readonly ackInfo: AckInfoStore;
|
|
24
|
+
readonly messageCreator: MessageCreator;
|
|
25
|
+
readonly patchCreator: PatchCreator;
|
|
26
|
+
readonly schema: SchemaStore;
|
|
27
|
+
readonly time: HybridLogicalClockTimestampProvider;
|
|
28
|
+
private readonly disableRebasing;
|
|
29
|
+
/**
|
|
30
|
+
* indicates the client is shutting down and we should stop
|
|
31
|
+
* accessing the database.
|
|
32
|
+
*/
|
|
33
|
+
private _closing;
|
|
34
|
+
private context;
|
|
35
|
+
constructor({ disableRebasing, context, }: {
|
|
36
|
+
disableRebasing?: boolean;
|
|
37
|
+
context: Omit<Context, 'documentDb' | 'getNow'>;
|
|
38
|
+
});
|
|
39
|
+
private get db();
|
|
40
|
+
private get log();
|
|
41
|
+
setContext: (context: Context) => void;
|
|
42
|
+
get now(): string;
|
|
43
|
+
close: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Methods for accessing data
|
|
46
|
+
*/
|
|
47
|
+
createTransaction: (stores: ('operations' | 'baselines')[], opts?: {
|
|
48
|
+
abort?: AbortSignal;
|
|
49
|
+
write?: boolean;
|
|
50
|
+
}) => IDBTransaction;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the OID and every sub-object OID for a given document.
|
|
53
|
+
* Includes any sub-objects that are not referenced by the root object
|
|
54
|
+
* but still happen to be in storage.
|
|
55
|
+
*/
|
|
56
|
+
getAllDocumentRelatedOids: (oid: ObjectIdentifier) => Promise<string[]>;
|
|
57
|
+
getAllCollectionRelatedOids: (oid: ObjectIdentifier) => Promise<string[]>;
|
|
58
|
+
getDocumentSnapshot: (oid: ObjectIdentifier, options?: {
|
|
59
|
+
to?: string;
|
|
60
|
+
}) => Promise<any>;
|
|
61
|
+
getDocumentData: (oid: ObjectIdentifier, opts?: {
|
|
62
|
+
abort?: AbortSignal;
|
|
63
|
+
}) => Promise<{
|
|
64
|
+
baselines: DocumentBaseline[];
|
|
65
|
+
operations: Record<string, Operation[]>;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Methods for writing data
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Acks that we have seen a timestamp to the server
|
|
72
|
+
* and stores it as our local ackedLogicalTime if it's
|
|
73
|
+
* greater than our current ackedLogicalTime.
|
|
74
|
+
*/
|
|
75
|
+
ack: (timestamp: string) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Applies a patch to the document and stores it in the database.
|
|
78
|
+
* @returns the oldest local history timestamp
|
|
79
|
+
*/
|
|
80
|
+
insertLocalOperations: (operations: Operation[], opts?: {
|
|
81
|
+
transaction?: IDBTransaction;
|
|
82
|
+
}) => Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Inserts remote operations. This does not affect local history.
|
|
85
|
+
* @returns a list of affected document OIDs
|
|
86
|
+
*/
|
|
87
|
+
insertRemoteOperations: (operations: Operation[], opts?: {
|
|
88
|
+
transaction?: IDBTransaction;
|
|
89
|
+
}) => Promise<string[]>;
|
|
90
|
+
insertRemoteBaselines: (baselines: DocumentBaseline[], opts?: {
|
|
91
|
+
transaction?: IDBTransaction;
|
|
92
|
+
}) => Promise<string[]>;
|
|
93
|
+
insertData: (data: {
|
|
94
|
+
baselines?: DocumentBaseline[];
|
|
95
|
+
operations?: Operation[];
|
|
96
|
+
isLocal?: boolean;
|
|
97
|
+
}, opts?: {
|
|
98
|
+
abort: AbortSignal;
|
|
99
|
+
}) => Promise<void>;
|
|
100
|
+
updateLastSynced: (timestamp: string) => Promise<void>;
|
|
101
|
+
lastSyncedTimestamp: () => Promise<string | null>;
|
|
102
|
+
private tryAutonomousRebase;
|
|
103
|
+
/**
|
|
104
|
+
* Attempt to autonomously rebase local documents without server intervention.
|
|
105
|
+
* This can currently only happen for a client who has never synced before.
|
|
106
|
+
* The goal is to allow local-only clients to compress their history to exactly
|
|
107
|
+
* their undo stack.
|
|
108
|
+
*/
|
|
109
|
+
private runRebase;
|
|
110
|
+
rebase: (oid: ObjectIdentifier, upTo: string, providedTx?: IDBTransaction) => Promise<{
|
|
111
|
+
oid: string;
|
|
112
|
+
snapshot: any;
|
|
113
|
+
timestamp: string;
|
|
114
|
+
}>;
|
|
115
|
+
reset: () => Promise<void>;
|
|
116
|
+
updateSchema: (schema: StorageSchema, overrideConflict?: number) => Promise<void>;
|
|
117
|
+
setGlobalAck: (timestamp: string) => Promise<void>;
|
|
118
|
+
export: () => Promise<ExportData>;
|
|
119
|
+
/**
|
|
120
|
+
* Resets local metadata and clears operation/baseline stores.
|
|
121
|
+
* DOES NOT add operations/baselines - this should be done
|
|
122
|
+
* through the normal higher level systems.
|
|
123
|
+
*/
|
|
124
|
+
resetFrom: (data: ExportData) => Promise<void>;
|
|
125
|
+
stats: () => Promise<{
|
|
126
|
+
operationsSize: {
|
|
127
|
+
count: number;
|
|
128
|
+
size: number;
|
|
129
|
+
};
|
|
130
|
+
baselinesSize: {
|
|
131
|
+
count: number;
|
|
132
|
+
size: number;
|
|
133
|
+
};
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ObjectIdentifier, Operation } from '@verdant-web/common';
|
|
2
|
+
import { IDBService } from '../IDBService.js';
|
|
3
|
+
export type ClientOperation = Operation & {
|
|
4
|
+
isLocal: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type StoredClientOperation = ClientOperation & {
|
|
7
|
+
oid_timestamp: string;
|
|
8
|
+
l_t: string;
|
|
9
|
+
d_t: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class OperationsStore extends IDBService {
|
|
12
|
+
constructor(db: IDBDatabase, opts: {
|
|
13
|
+
log?: (...args: any[]) => void;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Iterates over every patch for the root and every sub-object
|
|
17
|
+
* of a given document. Optionally limit by timestamp.
|
|
18
|
+
*/
|
|
19
|
+
iterateOverAllOperationsForDocument: (oid: ObjectIdentifier, iterator: (patch: StoredClientOperation, store: IDBObjectStore) => void, { to, from, after, mode, transaction: providedTx, }?: {
|
|
20
|
+
to?: string | undefined;
|
|
21
|
+
from?: string | undefined;
|
|
22
|
+
after?: string | undefined;
|
|
23
|
+
mode?: "readonly" | "readwrite" | undefined;
|
|
24
|
+
transaction?: IDBTransaction | undefined;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
iterateOverAllOperationsForEntity: (oid: ObjectIdentifier, iterator: (patch: StoredClientOperation, store: IDBObjectStore) => void, { after, to, mode, transaction: providedTx, }: {
|
|
27
|
+
after?: string | undefined;
|
|
28
|
+
to?: string | undefined;
|
|
29
|
+
mode?: "readonly" | "readwrite" | undefined;
|
|
30
|
+
transaction?: IDBTransaction | undefined;
|
|
31
|
+
}) => Promise<void>;
|
|
32
|
+
iterateOverAllOperationsForCollection: (collection: string, iterator: (patch: StoredClientOperation, store: IDBObjectStore) => void, { after, to, mode, transaction: providedTx, }: {
|
|
33
|
+
after?: string | undefined;
|
|
34
|
+
to?: string | undefined;
|
|
35
|
+
mode?: "readonly" | "readwrite" | undefined;
|
|
36
|
+
transaction?: IDBTransaction | undefined;
|
|
37
|
+
}) => Promise<void>;
|
|
38
|
+
iterateOverAllLocalOperations: (iterator: (patch: ClientOperation, store: IDBObjectStore) => void, { before, after, mode, transaction: providedTx, }: {
|
|
39
|
+
before?: string | null | undefined;
|
|
40
|
+
after?: string | null | undefined;
|
|
41
|
+
mode?: "readonly" | "readwrite" | undefined;
|
|
42
|
+
transaction?: IDBTransaction | undefined;
|
|
43
|
+
}) => Promise<void>;
|
|
44
|
+
iterateOverAllOperations: (iterator: (patch: ClientOperation, store: IDBObjectStore) => void, { before, transaction, mode, from, }: {
|
|
45
|
+
/** Ending timestamp, exclusive */
|
|
46
|
+
before?: string | null | undefined;
|
|
47
|
+
/** Starting timestamp, inclusive */
|
|
48
|
+
from?: string | null | undefined;
|
|
49
|
+
transaction?: IDBTransaction | undefined;
|
|
50
|
+
mode?: "readonly" | "readwrite" | undefined;
|
|
51
|
+
}) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Adds a set of patches to the database.
|
|
54
|
+
* @returns a list of affected root document OIDs.
|
|
55
|
+
*/
|
|
56
|
+
addOperations: (patches: ClientOperation[], { transaction }?: {
|
|
57
|
+
transaction?: IDBTransaction | undefined;
|
|
58
|
+
}) => Promise<ObjectIdentifier[]>;
|
|
59
|
+
private addCompoundIndexes;
|
|
60
|
+
private insert;
|
|
61
|
+
reset: () => Promise<undefined>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StorageSchema } from '@verdant-web/common';
|
|
2
|
+
export declare class SchemaStore {
|
|
3
|
+
private readonly db;
|
|
4
|
+
readonly currentVersion: number;
|
|
5
|
+
private cached;
|
|
6
|
+
constructor(db: IDBDatabase, currentVersion: number);
|
|
7
|
+
get: () => Promise<StorageSchema<any> | null>;
|
|
8
|
+
set: (schema: StorageSchema<any>) => Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function openMetadataDatabase({ indexedDB, namespace, log, metadataVersion, }: {
|
|
2
|
+
indexedDB?: IDBFactory;
|
|
3
|
+
namespace: string;
|
|
4
|
+
log?: (...args: any[]) => void;
|
|
5
|
+
metadataVersion?: number;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
wasInitialized: boolean;
|
|
8
|
+
db: IDBDatabase;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function openWIPMetadataDatabase({ wipNamespace, namespace, indexedDB, log, metadataVersion, }: {
|
|
11
|
+
indexedDB?: IDBFactory;
|
|
12
|
+
namespace: string;
|
|
13
|
+
wipNamespace: string;
|
|
14
|
+
log?: (...args: any[]) => void;
|
|
15
|
+
metadataVersion?: number;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
wasInitialized: boolean;
|
|
18
|
+
db: IDBDatabase;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function getDatabaseVersion(indexedDB: IDBFactory, namespace: string, version: number, log?: (...args: any[]) => void): Promise<number>;
|
|
2
|
+
export declare function closeDatabase(db: IDBDatabase): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Upgrades the database to the given version, using the given upgrader function.
|
|
5
|
+
*/
|
|
6
|
+
export declare function upgradeDatabase(indexedDb: IDBFactory, namespace: string, version: number, upgrader: (transaction: IDBTransaction, db: IDBDatabase, event: IDBVersionChangeEvent) => void, log?: (...args: any[]) => void): Promise<void>;
|
|
7
|
+
export declare function acquireLock(namespace: string, procedure: () => Promise<void>): Promise<void>;
|
|
8
|
+
export declare function openDatabase(indexedDb: IDBFactory, namespace: string, version: number, log?: (...args: any[]) => void): Promise<IDBDatabase>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Migration } from '@verdant-web/common';
|
|
2
|
+
import { Context } from '../context.js';
|
|
3
|
+
import { Metadata } from '../metadata/Metadata.js';
|
|
4
|
+
type OpenDocumentDbContext = Omit<Context, 'documentDb'>;
|
|
5
|
+
export declare function openDocumentDatabase({ version, indexedDB, migrations, meta, context, }: {
|
|
6
|
+
version: number;
|
|
7
|
+
migrations: Migration<any>[];
|
|
8
|
+
indexedDB?: IDBFactory;
|
|
9
|
+
meta: Metadata;
|
|
10
|
+
context: OpenDocumentDbContext;
|
|
11
|
+
}): Promise<IDBDatabase>;
|
|
12
|
+
export declare function openWIPDocumentDatabase({ version, indexedDB, migrations, meta, context, wipNamespace, }: {
|
|
13
|
+
version: number;
|
|
14
|
+
migrations: Migration<any>[];
|
|
15
|
+
indexedDB?: IDBFactory;
|
|
16
|
+
meta: Metadata;
|
|
17
|
+
context: OpenDocumentDbContext;
|
|
18
|
+
wipNamespace: string;
|
|
19
|
+
}): Promise<IDBDatabase>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Context } from '../context.js';
|
|
2
|
+
import { Disposable } from '../utils/Disposable.js';
|
|
3
|
+
export type BaseQueryEvents = {
|
|
4
|
+
change: (value: any) => void;
|
|
5
|
+
statusChange: (status: QueryStatus) => void;
|
|
6
|
+
};
|
|
7
|
+
export type BaseQueryOptions<T> = {
|
|
8
|
+
context: Context;
|
|
9
|
+
initial: T;
|
|
10
|
+
collection: string;
|
|
11
|
+
key: string;
|
|
12
|
+
shouldUpdate?: (updatedCollections: string[]) => boolean;
|
|
13
|
+
};
|
|
14
|
+
export type QueryStatus = 'initial' | 'initializing' | 'revalidating' | 'ready';
|
|
15
|
+
export declare const ON_ALL_UNSUBSCRIBED: unique symbol;
|
|
16
|
+
export declare const UPDATE: unique symbol;
|
|
17
|
+
export declare abstract class BaseQuery<T> extends Disposable {
|
|
18
|
+
private _rawValue;
|
|
19
|
+
private _value;
|
|
20
|
+
private _events;
|
|
21
|
+
private _internalUnsubscribes;
|
|
22
|
+
private _allUnsubscribedHandler?;
|
|
23
|
+
private _status;
|
|
24
|
+
private _executionPromise;
|
|
25
|
+
protected context: Context;
|
|
26
|
+
readonly collection: string;
|
|
27
|
+
readonly key: string;
|
|
28
|
+
constructor({ initial, context, collection, key, shouldUpdate, }: BaseQueryOptions<T>);
|
|
29
|
+
get current(): T;
|
|
30
|
+
get resolved(): Promise<T>;
|
|
31
|
+
get subscribed(): boolean;
|
|
32
|
+
get status(): QueryStatus;
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to changes in the query value.
|
|
35
|
+
*
|
|
36
|
+
* @deprecated use the two parameter form instead
|
|
37
|
+
*/
|
|
38
|
+
subscribe(callback: (value: T) => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to changes in the query value.
|
|
41
|
+
*/
|
|
42
|
+
subscribe(event: 'change', callback: (value: T) => void): () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to changes in the query state.
|
|
45
|
+
*/
|
|
46
|
+
subscribe(event: 'statusChange', callback: (status: QueryStatus) => void): () => void;
|
|
47
|
+
protected setValue: (value: T) => void;
|
|
48
|
+
protected refreshValue: () => void;
|
|
49
|
+
private subscribeToDeleteAndRestore;
|
|
50
|
+
execute: () => Promise<T>;
|
|
51
|
+
protected abstract run(): Promise<void>;
|
|
52
|
+
[ON_ALL_UNSUBSCRIBED]: (handler: (query: BaseQuery<T>) => void) => void;
|
|
53
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CollectionFilter } from '@verdant-web/common';
|
|
2
|
+
import { Context } from '../context.js';
|
|
3
|
+
import { EntityStore } from '../entities/EntityStore.js';
|
|
4
|
+
import { GetQuery } from './GetQuery.js';
|
|
5
|
+
import { QueryCache } from './QueryCache.js';
|
|
6
|
+
import { FindOneQuery } from './FindOneQuery.js';
|
|
7
|
+
import { FindPageQuery } from './FindPageQuery.js';
|
|
8
|
+
import { FindInfiniteQuery } from './FindInfiniteQuery.js';
|
|
9
|
+
import { FindAllQuery } from './FindAllQuery.js';
|
|
10
|
+
import { DocumentManager } from '../DocumentManager.js';
|
|
11
|
+
import { ObjectEntity } from '../index.js';
|
|
12
|
+
export declare class CollectionQueries<T extends ObjectEntity<any, any>, Init, Filter extends CollectionFilter> {
|
|
13
|
+
private cache;
|
|
14
|
+
private collection;
|
|
15
|
+
private hydrate;
|
|
16
|
+
private context;
|
|
17
|
+
private documentManager;
|
|
18
|
+
put: (init: Init, options?: {
|
|
19
|
+
undoable?: boolean;
|
|
20
|
+
}) => Promise<T>;
|
|
21
|
+
delete: (id: string, options?: {
|
|
22
|
+
undoable?: boolean;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
deleteAll: (ids: string[], options?: {
|
|
25
|
+
undoable?: boolean;
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
constructor({ collection, cache, entities, context, documentManager, }: {
|
|
28
|
+
collection: string;
|
|
29
|
+
cache: QueryCache;
|
|
30
|
+
entities: EntityStore;
|
|
31
|
+
context: Context;
|
|
32
|
+
documentManager: DocumentManager<any>;
|
|
33
|
+
});
|
|
34
|
+
private serializeIndex;
|
|
35
|
+
get: (id: string) => GetQuery<T>;
|
|
36
|
+
findOne: ({ index, key: providedKey, }?: {
|
|
37
|
+
index?: Filter | undefined;
|
|
38
|
+
key?: string | undefined;
|
|
39
|
+
}) => FindOneQuery<T>;
|
|
40
|
+
findAll: ({ index, key: providedKey, }?: {
|
|
41
|
+
index?: Filter | undefined;
|
|
42
|
+
key?: string | undefined;
|
|
43
|
+
}) => FindAllQuery<T>;
|
|
44
|
+
findPage: ({ index, pageSize, page, key: providedKey, }: {
|
|
45
|
+
index?: Filter | undefined;
|
|
46
|
+
pageSize: number;
|
|
47
|
+
page: number;
|
|
48
|
+
key?: string | undefined;
|
|
49
|
+
}) => FindPageQuery<T>;
|
|
50
|
+
findAllInfinite: ({ index, pageSize, key: providedKey, }: {
|
|
51
|
+
index?: Filter | undefined;
|
|
52
|
+
pageSize: number;
|
|
53
|
+
key?: string | undefined;
|
|
54
|
+
}) => FindInfiniteQuery<T>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CollectionFilter } from '@verdant-web/common';
|
|
2
|
+
import { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';
|
|
3
|
+
export declare class FindAllQuery<T> extends BaseQuery<T[]> {
|
|
4
|
+
private index;
|
|
5
|
+
private hydrate;
|
|
6
|
+
constructor({ index, hydrate, ...rest }: {
|
|
7
|
+
index?: CollectionFilter;
|
|
8
|
+
hydrate: (oid: string) => Promise<T>;
|
|
9
|
+
} & Omit<BaseQueryOptions<T[]>, 'initial'>);
|
|
10
|
+
protected run: () => Promise<void>;
|
|
11
|
+
[UPDATE]: (index: CollectionFilter | undefined) => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CollectionFilter } from '@verdant-web/common';
|
|
2
|
+
import { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';
|
|
3
|
+
export declare class FindInfiniteQuery<T> extends BaseQuery<T[]> {
|
|
4
|
+
private index;
|
|
5
|
+
private hydrate;
|
|
6
|
+
private _upToPage;
|
|
7
|
+
private _pageSize;
|
|
8
|
+
private _hasNextPage;
|
|
9
|
+
get pageSize(): number;
|
|
10
|
+
get hasMore(): boolean;
|
|
11
|
+
constructor({ hydrate, pageSize, index, ...rest }: {
|
|
12
|
+
hydrate: (oid: string) => Promise<T>;
|
|
13
|
+
pageSize: number;
|
|
14
|
+
index?: CollectionFilter;
|
|
15
|
+
} & Omit<BaseQueryOptions<T[]>, 'initial'>);
|
|
16
|
+
protected run: () => Promise<void>;
|
|
17
|
+
loadMore: () => Promise<void>;
|
|
18
|
+
[UPDATE]: (index: CollectionFilter | undefined) => void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CollectionFilter } from '@verdant-web/common';
|
|
2
|
+
import { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';
|
|
3
|
+
export declare class FindOneQuery<T> extends BaseQuery<T | null> {
|
|
4
|
+
private index;
|
|
5
|
+
private hydrate;
|
|
6
|
+
constructor({ index, hydrate, ...rest }: {
|
|
7
|
+
index?: CollectionFilter;
|
|
8
|
+
hydrate: (oid: string) => Promise<T>;
|
|
9
|
+
} & Omit<BaseQueryOptions<T | null>, 'initial'>);
|
|
10
|
+
protected run: () => Promise<void>;
|
|
11
|
+
[UPDATE]: (index: CollectionFilter | undefined) => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CollectionFilter } from '@verdant-web/common';
|
|
2
|
+
import { BaseQuery, BaseQueryOptions, UPDATE } from './BaseQuery.js';
|
|
3
|
+
export declare class FindPageQuery<T> extends BaseQuery<T[]> {
|
|
4
|
+
private index;
|
|
5
|
+
private hydrate;
|
|
6
|
+
private _pageSize;
|
|
7
|
+
private _page;
|
|
8
|
+
private _hasNextPage;
|
|
9
|
+
get pageSize(): number;
|
|
10
|
+
get page(): number;
|
|
11
|
+
get hasNextPage(): boolean;
|
|
12
|
+
get hasPreviousPage(): boolean;
|
|
13
|
+
constructor({ index, hydrate, pageSize, page, ...rest }: {
|
|
14
|
+
index?: CollectionFilter;
|
|
15
|
+
hydrate: (oid: string) => Promise<T>;
|
|
16
|
+
pageSize: number;
|
|
17
|
+
page: number;
|
|
18
|
+
} & Omit<BaseQueryOptions<T[]>, 'initial'>);
|
|
19
|
+
protected run: () => Promise<void>;
|
|
20
|
+
nextPage: () => Promise<void>;
|
|
21
|
+
previousPage: () => Promise<void>;
|
|
22
|
+
setPage: (page: number) => Promise<void>;
|
|
23
|
+
[UPDATE]: (index: CollectionFilter | undefined) => void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseQuery, BaseQueryOptions } from './BaseQuery.js';
|
|
2
|
+
export declare class GetQuery<T> extends BaseQuery<T | null> {
|
|
3
|
+
private hydrate;
|
|
4
|
+
private oid;
|
|
5
|
+
constructor({ id, hydrate, ...rest }: {
|
|
6
|
+
id: string;
|
|
7
|
+
hydrate: (oid: string) => Promise<T>;
|
|
8
|
+
} & Omit<BaseQueryOptions<T | null>, 'initial'>);
|
|
9
|
+
protected run: () => Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from '../context.js';
|
|
2
|
+
import { Disposable } from '../utils/Disposable.js';
|
|
3
|
+
import { BaseQuery } from './BaseQuery.js';
|
|
4
|
+
export declare class QueryCache extends Disposable {
|
|
5
|
+
private _cache;
|
|
6
|
+
private _evictionTime;
|
|
7
|
+
private context;
|
|
8
|
+
constructor({ evictionTime, context, }: {
|
|
9
|
+
evictionTime?: number;
|
|
10
|
+
context: Context;
|
|
11
|
+
});
|
|
12
|
+
get<T extends BaseQuery<any>>(key: string): T | null;
|
|
13
|
+
set<V extends BaseQuery<any>>(value: V): V;
|
|
14
|
+
getOrSet<V extends BaseQuery<any>>(key: string, create: () => V, update?: (query: V) => void): V;
|
|
15
|
+
private onQueryUnsubscribed;
|
|
16
|
+
dropAll: () => void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ObjectIdentifier } from '@verdant-web/common';
|
|
2
|
+
import { IDBService } from '../IDBService.js';
|
|
3
|
+
import { Context } from '../context.js';
|
|
4
|
+
export declare class QueryableStorage extends IDBService {
|
|
5
|
+
private ctx;
|
|
6
|
+
constructor({ ctx }: {
|
|
7
|
+
ctx: Context;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* DELETES EVERYTHING IN THE QUERYABLE DATABASE
|
|
11
|
+
*/
|
|
12
|
+
reset: () => Promise<void>;
|
|
13
|
+
saveEntities: (entities: {
|
|
14
|
+
oid: ObjectIdentifier;
|
|
15
|
+
getSnapshot: () => any;
|
|
16
|
+
}[], opts?: {
|
|
17
|
+
abort?: AbortSignal;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
private saveDocument;
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CollectionFilter } from '@verdant-web/common';
|
|
2
|
+
import { Context } from '../context.js';
|
|
3
|
+
export declare function findOneOid({ collection, index, context, }: {
|
|
4
|
+
collection: string;
|
|
5
|
+
index?: CollectionFilter;
|
|
6
|
+
context: Context;
|
|
7
|
+
}): Promise<string | null>;
|
|
8
|
+
export declare function findAllOids({ collection, index, context, }: {
|
|
9
|
+
collection: string;
|
|
10
|
+
index?: CollectionFilter;
|
|
11
|
+
context: Context;
|
|
12
|
+
}): Promise<string[]>;
|
|
13
|
+
export declare function findPageOfOids({ collection, index, context, limit, offset, }: {
|
|
14
|
+
collection: string;
|
|
15
|
+
index?: CollectionFilter;
|
|
16
|
+
context: Context;
|
|
17
|
+
limit?: number;
|
|
18
|
+
offset?: number;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
result: string[];
|
|
21
|
+
hasNextPage: boolean;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface QueryParams {
|
|
2
|
+
collection: string;
|
|
3
|
+
range: IDBKeyRange | IDBValidKey | undefined;
|
|
4
|
+
index?: string;
|
|
5
|
+
direction?: IDBCursorDirection;
|
|
6
|
+
limit?: number;
|
|
7
|
+
single?: boolean;
|
|
8
|
+
write?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function getQueryKey({ range, ...rest }: QueryParams): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FindAllQuery } from './FindAllQuery.js';
|
|
2
|
+
import type { FindPageQuery } from './FindPageQuery.js';
|
|
3
|
+
import type { FindOneQuery } from './FindOneQuery.js';
|
|
4
|
+
import type { FindInfiniteQuery } from './FindInfiniteQuery.js';
|
|
5
|
+
import type { GetQuery } from './GetQuery.js';
|
|
6
|
+
export type Query<T> = FindAllQuery<T> | FindPageQuery<T> | FindOneQuery<T> | FindInfiniteQuery<T> | GetQuery<T>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FileData } from '@verdant-web/common';
|
|
2
|
+
import { ServerSyncEndpointProvider } from './ServerSyncEndpointProvider.js';
|
|
3
|
+
export interface FileUploadResult {
|
|
4
|
+
success: boolean;
|
|
5
|
+
retry: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type FilePullResult = {
|
|
8
|
+
success: true;
|
|
9
|
+
data: FileData;
|
|
10
|
+
} | {
|
|
11
|
+
success: false;
|
|
12
|
+
retry: boolean;
|
|
13
|
+
error?: any;
|
|
14
|
+
};
|
|
15
|
+
export declare class FileSync {
|
|
16
|
+
private endpointProvider;
|
|
17
|
+
private log;
|
|
18
|
+
constructor({ endpointProvider, log, }: {
|
|
19
|
+
endpointProvider: ServerSyncEndpointProvider;
|
|
20
|
+
log: (...args: any[]) => any;
|
|
21
|
+
});
|
|
22
|
+
uploadFile: (data: FileData) => Promise<FileUploadResult>;
|
|
23
|
+
getFile: (id: string) => Promise<FilePullResult>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventSubscriber } from '@verdant-web/common';
|
|
2
|
+
export declare class Heartbeat extends EventSubscriber<{
|
|
3
|
+
missed: () => void;
|
|
4
|
+
beat: () => void;
|
|
5
|
+
}> {
|
|
6
|
+
private _interval;
|
|
7
|
+
private deadlineLength;
|
|
8
|
+
private nextBeat;
|
|
9
|
+
private deadline;
|
|
10
|
+
get interval(): number;
|
|
11
|
+
constructor({ interval, deadlineLength, restartOnTabFocus, }?: {
|
|
12
|
+
interval?: number;
|
|
13
|
+
deadlineLength?: number;
|
|
14
|
+
restartOnTabFocus?: boolean;
|
|
15
|
+
});
|
|
16
|
+
keepAlive: () => void;
|
|
17
|
+
start: (immediate?: boolean) => void;
|
|
18
|
+
stop: () => void;
|
|
19
|
+
private beat;
|
|
20
|
+
private onDeadline;
|
|
21
|
+
/**
|
|
22
|
+
* Only takes affect after the next beat
|
|
23
|
+
*/
|
|
24
|
+
setInterval: (interval: number) => void;
|
|
25
|
+
}
|