@verdant-web/store 3.8.3 → 3.9.0-next.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/bundle/index.js +8 -8
- package/dist/bundle/index.js.map +4 -4
- package/dist/esm/IDBService.d.ts +1 -1
- package/dist/esm/IDBService.js +7 -2
- package/dist/esm/IDBService.js.map +1 -1
- package/dist/esm/__tests__/entities.test.js +21 -16
- package/dist/esm/__tests__/entities.test.js.map +1 -1
- package/dist/esm/__tests__/fixtures/testStorage.d.ts +4 -0
- package/dist/esm/__tests__/fixtures/testStorage.js +3 -0
- package/dist/esm/__tests__/fixtures/testStorage.js.map +1 -1
- package/dist/esm/authorization.d.ts +4 -0
- package/dist/esm/authorization.js +6 -0
- package/dist/esm/authorization.js.map +1 -0
- package/dist/esm/client/Client.d.ts +29 -1
- package/dist/esm/client/Client.js +25 -2
- package/dist/esm/client/Client.js.map +1 -1
- package/dist/esm/context.d.ts +6 -0
- package/dist/esm/{DocumentManager.d.ts → entities/DocumentManager.d.ts} +12 -6
- package/dist/esm/entities/DocumentManager.js +77 -0
- package/dist/esm/entities/DocumentManager.js.map +1 -0
- package/dist/esm/entities/Entity.d.ts +8 -0
- package/dist/esm/entities/Entity.js +23 -3
- package/dist/esm/entities/Entity.js.map +1 -1
- package/dist/esm/entities/EntityMetadata.d.ts +1 -0
- package/dist/esm/entities/EntityMetadata.js +18 -3
- package/dist/esm/entities/EntityMetadata.js.map +1 -1
- package/dist/esm/entities/EntityStore.d.ts +6 -4
- package/dist/esm/entities/EntityStore.js +22 -10
- package/dist/esm/entities/EntityStore.js.map +1 -1
- package/dist/esm/entities/types.d.ts +1 -0
- package/dist/esm/files/EntityFile.d.ts +1 -1
- package/dist/esm/files/EntityFile.js +7 -1
- package/dist/esm/files/EntityFile.js.map +1 -1
- package/dist/esm/files/FileManager.d.ts +11 -2
- package/dist/esm/files/FileManager.js +45 -8
- package/dist/esm/files/FileManager.js.map +1 -1
- package/dist/esm/files/FileStorage.d.ts +6 -0
- package/dist/esm/files/FileStorage.js +6 -1
- package/dist/esm/files/FileStorage.js.map +1 -1
- package/dist/esm/files/utils.d.ts +1 -2
- package/dist/esm/files/utils.js +11 -5
- package/dist/esm/files/utils.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metadata/LocalReplicaStore.d.ts +1 -0
- package/dist/esm/metadata/LocalReplicaStore.js +1 -0
- package/dist/esm/metadata/LocalReplicaStore.js.map +1 -1
- package/dist/esm/metadata/MessageCreator.js +4 -16
- package/dist/esm/metadata/MessageCreator.js.map +1 -1
- package/dist/esm/metadata/Metadata.d.ts +8 -0
- package/dist/esm/metadata/Metadata.js +32 -0
- package/dist/esm/metadata/Metadata.js.map +1 -1
- package/dist/esm/metadata/OperationsStore.js +3 -3
- package/dist/esm/metadata/OperationsStore.js.map +1 -1
- package/dist/esm/migration/engine.js +12 -2
- package/dist/esm/migration/engine.js.map +1 -1
- package/dist/esm/queries/CollectionQueries.d.ts +8 -2
- package/dist/esm/queries/CollectionQueries.js +2 -1
- package/dist/esm/queries/CollectionQueries.js.map +1 -1
- package/dist/esm/sync/FileSync.d.ts +1 -0
- package/dist/esm/sync/FileSync.js +5 -2
- package/dist/esm/sync/FileSync.js.map +1 -1
- package/dist/esm/sync/PushPullSync.d.ts +2 -1
- package/dist/esm/sync/PushPullSync.js +10 -6
- package/dist/esm/sync/PushPullSync.js.map +1 -1
- package/dist/esm/sync/ServerSyncEndpointProvider.d.ts +10 -1
- package/dist/esm/sync/ServerSyncEndpointProvider.js +13 -2
- package/dist/esm/sync/ServerSyncEndpointProvider.js.map +1 -1
- package/dist/esm/sync/Sync.d.ts +5 -4
- package/dist/esm/sync/Sync.js +22 -7
- package/dist/esm/sync/Sync.js.map +1 -1
- package/dist/esm/sync/WebSocketSync.d.ts +2 -1
- package/dist/esm/sync/WebSocketSync.js +5 -2
- package/dist/esm/sync/WebSocketSync.js.map +1 -1
- package/package.json +6 -6
- package/src/IDBService.ts +8 -4
- package/src/__tests__/entities.test.ts +29 -5
- package/src/__tests__/fixtures/testStorage.ts +3 -0
- package/src/authorization.ts +6 -0
- package/src/client/Client.ts +37 -6
- package/src/context.ts +6 -0
- package/src/entities/DocumentManager.ts +154 -0
- package/src/entities/Entity.ts +26 -2
- package/src/entities/EntityMetadata.ts +22 -0
- package/src/entities/EntityStore.ts +29 -11
- package/src/entities/types.ts +1 -0
- package/src/files/EntityFile.ts +6 -2
- package/src/files/FileManager.ts +57 -9
- package/src/files/FileStorage.ts +7 -1
- package/src/files/utils.ts +17 -8
- package/src/index.ts +1 -0
- package/src/metadata/LocalReplicaStore.ts +2 -0
- package/src/metadata/MessageCreator.ts +4 -15
- package/src/metadata/Metadata.ts +37 -0
- package/src/metadata/OperationsStore.ts +3 -3
- package/src/migration/engine.ts +14 -2
- package/src/queries/CollectionQueries.ts +23 -4
- package/src/sync/FileSync.ts +6 -7
- package/src/sync/PushPullSync.ts +7 -2
- package/src/sync/ServerSyncEndpointProvider.ts +22 -2
- package/src/sync/Sync.ts +27 -6
- package/src/sync/WebSocketSync.ts +6 -2
- package/dist/esm/DocumentManager.js +0 -46
- package/dist/esm/DocumentManager.js.map +0 -1
- package/src/DocumentManager.ts +0 -97
|
@@ -59,6 +59,10 @@ export class WebSocketSync
|
|
|
59
59
|
this.heartbeat.subscribe('beat', this.sendHeartbeat);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
get hasSynced() {
|
|
63
|
+
return this.synced;
|
|
64
|
+
}
|
|
65
|
+
|
|
62
66
|
private onOpen = () => {
|
|
63
67
|
if (!this.socket) {
|
|
64
68
|
throw new Error('Invalid sync state: online but socket is null');
|
|
@@ -251,11 +255,11 @@ export class WebSocketSync
|
|
|
251
255
|
this.stop();
|
|
252
256
|
};
|
|
253
257
|
|
|
254
|
-
start = () => {
|
|
258
|
+
start = async () => {
|
|
255
259
|
if (this.socket) {
|
|
256
260
|
return;
|
|
257
261
|
}
|
|
258
|
-
this.initializeSocket();
|
|
262
|
+
await this.initializeSocket();
|
|
259
263
|
this._status = 'active';
|
|
260
264
|
};
|
|
261
265
|
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { addFieldDefaults, constrainEntity, assert, createOid, } from '@verdant-web/common';
|
|
2
|
-
/**
|
|
3
|
-
* Exposes functionality for creating documents,
|
|
4
|
-
* the only mutation which is available as an entry
|
|
5
|
-
* point in the storage system.
|
|
6
|
-
*/
|
|
7
|
-
export class DocumentManager {
|
|
8
|
-
constructor(meta, schema, entities) {
|
|
9
|
-
this.meta = meta;
|
|
10
|
-
this.schema = schema;
|
|
11
|
-
this.entities = entities;
|
|
12
|
-
this.getOid = (collection, init) => {
|
|
13
|
-
const primaryKeyName = this.schema.collections[collection]
|
|
14
|
-
.primaryKey;
|
|
15
|
-
const primaryKey = init[primaryKeyName];
|
|
16
|
-
assert(primaryKey, `Document must have a primary key: ${primaryKeyName.toString()} (got: ${JSON.stringify(init)})`);
|
|
17
|
-
return createOid(collection, primaryKey);
|
|
18
|
-
};
|
|
19
|
-
this.addDefaults = (collectionName, init) => {
|
|
20
|
-
const collection = this.schema.collections[collectionName];
|
|
21
|
-
return addFieldDefaults(collection, init);
|
|
22
|
-
};
|
|
23
|
-
this.validate = (collectionName, init) => {
|
|
24
|
-
const collection = this.schema.collections[collectionName];
|
|
25
|
-
return constrainEntity(collection.fields, init);
|
|
26
|
-
};
|
|
27
|
-
this.create = (collection, init, options = {}) => {
|
|
28
|
-
const defaulted = this.addDefaults(collection, init);
|
|
29
|
-
const validated = this.validate(collection, defaulted);
|
|
30
|
-
const oid = this.getOid(collection, validated);
|
|
31
|
-
// documents are always objects at the root
|
|
32
|
-
return this.entities.create(validated, oid, options);
|
|
33
|
-
};
|
|
34
|
-
this.delete = async (collection, primaryKey, options = {}) => {
|
|
35
|
-
const oid = createOid(collection, primaryKey);
|
|
36
|
-
return this.entities.delete(oid, options);
|
|
37
|
-
};
|
|
38
|
-
this.deleteAll = async (ids, options = {}) => {
|
|
39
|
-
return this.entities.deleteAll(ids.map(([collection, primaryKey]) => createOid(collection, primaryKey)), options);
|
|
40
|
-
};
|
|
41
|
-
this.deleteAllFromCollection = async (collection, ids, options = {}) => {
|
|
42
|
-
return this.entities.deleteAll(ids.map((primaryKey) => createOid(collection, primaryKey)), options);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=DocumentManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentManager.js","sourceRoot":"","sources":["../../src/DocumentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,SAAS,GAKT,MAAM,qBAAqB,CAAC;AAI7B;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAC3B,YACS,IAAc,EACd,MAAc,EACd,QAAqB;QAFrB,SAAI,GAAJ,IAAI,CAAU;QACd,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAa;QAGtB,WAAM,GAAG,CAAC,UAAkB,EAAE,IAAS,EAAE,EAAE;YAClD,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC;iBACxD,UAGD,CAAC;YACF,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;YACxC,MAAM,CACL,UAAU,EACV,qCAAqC,cAAc,CAAC,QAAQ,EAAE,UAAU,IAAI,CAAC,SAAS,CACrF,IAAI,CACJ,GAAG,CACJ,CAAC;YACF,OAAO,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC1C,CAAC,CAAC;QAEM,gBAAW,GAAG,CAAC,cAAsB,EAAE,IAAS,EAAE,EAAE;YAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CACzC,cAAc,CACa,CAAC;YAC7B,OAAO,gBAA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AAC;QAEF,4BAAuB,GAAG,KAAK,EAC9B,UAAkB,EAClB,GAAa,EACb,UAAkC,EAAE,EACnC,EAAE;YACH,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAC7B,GAAG,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,EAC1D,OAAO,CACP,CAAC;QACH,CAAC,CAAC;IAxEC,CAAC;CAyEJ"}
|
package/src/DocumentManager.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addFieldDefaults,
|
|
3
|
-
constrainEntity,
|
|
4
|
-
assert,
|
|
5
|
-
createOid,
|
|
6
|
-
SchemaCollection,
|
|
7
|
-
StorageCollectionSchema,
|
|
8
|
-
StorageDocument,
|
|
9
|
-
StorageSchema,
|
|
10
|
-
} from '@verdant-web/common';
|
|
11
|
-
import { EntityStore } from './entities/EntityStore.js';
|
|
12
|
-
import { Metadata } from './metadata/Metadata.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Exposes functionality for creating documents,
|
|
16
|
-
* the only mutation which is available as an entry
|
|
17
|
-
* point in the storage system.
|
|
18
|
-
*/
|
|
19
|
-
export class DocumentManager<Schema extends StorageSchema<any>> {
|
|
20
|
-
constructor(
|
|
21
|
-
private meta: Metadata,
|
|
22
|
-
private schema: Schema,
|
|
23
|
-
private entities: EntityStore,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
private getOid = (collection: string, init: any) => {
|
|
27
|
-
const primaryKeyName = this.schema.collections[collection]
|
|
28
|
-
.primaryKey as Exclude<
|
|
29
|
-
keyof StorageDocument<SchemaCollection<Schema, any>>,
|
|
30
|
-
symbol
|
|
31
|
-
>;
|
|
32
|
-
const primaryKey = init[primaryKeyName];
|
|
33
|
-
assert(
|
|
34
|
-
primaryKey,
|
|
35
|
-
`Document must have a primary key: ${primaryKeyName.toString()} (got: ${JSON.stringify(
|
|
36
|
-
init,
|
|
37
|
-
)})`,
|
|
38
|
-
);
|
|
39
|
-
return createOid(collection, primaryKey);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
private addDefaults = (collectionName: string, init: any) => {
|
|
43
|
-
const collection = this.schema.collections[
|
|
44
|
-
collectionName
|
|
45
|
-
] as StorageCollectionSchema;
|
|
46
|
-
return addFieldDefaults(collection, init);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
private validate = (collectionName: string, init: any) => {
|
|
50
|
-
const collection = this.schema.collections[
|
|
51
|
-
collectionName
|
|
52
|
-
] as StorageCollectionSchema;
|
|
53
|
-
return constrainEntity(collection.fields, init);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
create = (
|
|
57
|
-
collection: string,
|
|
58
|
-
init: any,
|
|
59
|
-
options: { undoable?: boolean } = {},
|
|
60
|
-
) => {
|
|
61
|
-
const defaulted = this.addDefaults(collection, init);
|
|
62
|
-
const validated = this.validate(collection, defaulted);
|
|
63
|
-
const oid = this.getOid(collection, validated);
|
|
64
|
-
// documents are always objects at the root
|
|
65
|
-
return this.entities.create(validated, oid, options) as any;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
delete = async (
|
|
69
|
-
collection: string,
|
|
70
|
-
primaryKey: string,
|
|
71
|
-
options: { undoable?: boolean } = {},
|
|
72
|
-
) => {
|
|
73
|
-
const oid = createOid(collection, primaryKey);
|
|
74
|
-
return this.entities.delete(oid, options);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
deleteAll = async (
|
|
78
|
-
ids: [string, string][],
|
|
79
|
-
options: { undoable?: boolean } = {},
|
|
80
|
-
) => {
|
|
81
|
-
return this.entities.deleteAll(
|
|
82
|
-
ids.map(([collection, primaryKey]) => createOid(collection, primaryKey)),
|
|
83
|
-
options,
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
deleteAllFromCollection = async (
|
|
88
|
-
collection: string,
|
|
89
|
-
ids: string[],
|
|
90
|
-
options: { undoable?: boolean } = {},
|
|
91
|
-
) => {
|
|
92
|
-
return this.entities.deleteAll(
|
|
93
|
-
ids.map((primaryKey) => createOid(collection, primaryKey)),
|
|
94
|
-
options,
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
}
|