@verdant-web/store 3.0.0-next.0 → 3.0.1
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 +1 -1
- package/dist/bundle/index.js.map +4 -4
- package/dist/cjs/DocumentManager.d.ts +5 -6
- package/dist/cjs/DocumentManager.js +2 -2
- package/dist/cjs/DocumentManager.js.map +1 -1
- package/dist/cjs/client/Client.d.ts +3 -2
- package/dist/cjs/client/Client.js +1 -1
- package/dist/cjs/client/Client.js.map +1 -1
- package/dist/cjs/entities/Entity.d.ts +106 -171
- package/dist/cjs/entities/Entity.js +558 -383
- package/dist/cjs/entities/Entity.js.map +1 -1
- package/dist/cjs/entities/Entity.test.js.map +1 -0
- package/dist/cjs/entities/{2/EntityCache.d.ts → EntityCache.d.ts} +1 -1
- package/dist/cjs/entities/{2/EntityCache.js → EntityCache.js} +1 -1
- package/dist/cjs/entities/EntityCache.js.map +1 -0
- package/dist/{esm/entities/2 → cjs/entities}/EntityMetadata.d.ts +1 -1
- package/dist/cjs/entities/EntityMetadata.js.map +1 -0
- package/dist/cjs/entities/EntityStore.d.ts +63 -68
- package/dist/cjs/entities/EntityStore.js +296 -424
- package/dist/cjs/entities/EntityStore.js.map +1 -1
- package/dist/{esm/entities/2 → cjs/entities}/OperationBatcher.d.ts +2 -2
- package/dist/cjs/entities/OperationBatcher.js.map +1 -0
- package/dist/cjs/entities/{2/types.js.map → types.js.map} +1 -1
- package/dist/cjs/files/EntityFile.d.ts +5 -4
- package/dist/cjs/files/EntityFile.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/queries/BaseQuery.js +1 -1
- package/dist/cjs/queries/BaseQuery.js.map +1 -1
- package/dist/cjs/queries/CollectionQueries.d.ts +4 -2
- package/dist/cjs/queries/utils.js +1 -1
- package/dist/cjs/queries/utils.js.map +1 -1
- package/dist/esm/DocumentManager.d.ts +5 -6
- package/dist/esm/DocumentManager.js +2 -2
- package/dist/esm/DocumentManager.js.map +1 -1
- package/dist/esm/client/Client.d.ts +3 -2
- package/dist/esm/client/Client.js +1 -1
- package/dist/esm/client/Client.js.map +1 -1
- package/dist/esm/entities/Entity.d.ts +106 -171
- package/dist/esm/entities/Entity.js +559 -383
- package/dist/esm/entities/Entity.js.map +1 -1
- package/dist/esm/entities/Entity.test.js.map +1 -0
- package/dist/esm/entities/{2/EntityCache.d.ts → EntityCache.d.ts} +1 -1
- package/dist/esm/entities/{2/EntityCache.js → EntityCache.js} +1 -1
- package/dist/esm/entities/EntityCache.js.map +1 -0
- package/dist/{cjs/entities/2 → esm/entities}/EntityMetadata.d.ts +1 -1
- package/dist/esm/entities/EntityMetadata.js.map +1 -0
- package/dist/esm/entities/EntityStore.d.ts +63 -68
- package/dist/esm/entities/EntityStore.js +297 -425
- package/dist/esm/entities/EntityStore.js.map +1 -1
- package/dist/{cjs/entities/2 → esm/entities}/OperationBatcher.d.ts +2 -2
- package/dist/esm/entities/OperationBatcher.js.map +1 -0
- package/dist/esm/entities/{2/types.js.map → types.js.map} +1 -1
- package/dist/esm/files/EntityFile.d.ts +5 -4
- package/dist/esm/files/EntityFile.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/queries/BaseQuery.js +1 -1
- package/dist/esm/queries/BaseQuery.js.map +1 -1
- package/dist/esm/queries/CollectionQueries.d.ts +4 -2
- package/dist/esm/queries/utils.js +1 -1
- package/dist/esm/queries/utils.js.map +1 -1
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/DocumentManager.ts +7 -3
- package/src/__tests__/batching.test.ts +1 -1
- package/src/client/Client.ts +1 -1
- package/src/entities/{2/Entity.test.ts → Entity.test.ts} +2 -2
- package/src/entities/{2/Entity.ts → Entity.ts} +4 -4
- package/src/entities/{2/EntityCache.ts → EntityCache.ts} +1 -1
- package/src/entities/{2/EntityMetadata.ts → EntityMetadata.ts} +1 -1
- package/src/entities/{2/EntityStore.ts → EntityStore.ts} +12 -8
- package/src/entities/{2/OperationBatcher.ts → OperationBatcher.ts} +2 -2
- package/src/files/EntityFile.ts +6 -1
- package/src/index.ts +3 -3
- package/src/queries/BaseQuery.ts +1 -1
- package/src/queries/CollectionQueries.ts +2 -2
- package/src/queries/utils.ts +1 -1
- package/dist/cjs/entities/2/Entity.d.ts +0 -148
- package/dist/cjs/entities/2/Entity.js +0 -711
- package/dist/cjs/entities/2/Entity.js.map +0 -1
- package/dist/cjs/entities/2/Entity.test.js.map +0 -1
- package/dist/cjs/entities/2/EntityCache.js.map +0 -1
- package/dist/cjs/entities/2/EntityMetadata.js.map +0 -1
- package/dist/cjs/entities/2/EntityStore.d.ts +0 -78
- package/dist/cjs/entities/2/EntityStore.js +0 -352
- package/dist/cjs/entities/2/EntityStore.js.map +0 -1
- package/dist/cjs/entities/2/OperationBatcher.js.map +0 -1
- package/dist/cjs/entities/DocumentFamiliyCache.d.ts +0 -96
- package/dist/cjs/entities/DocumentFamiliyCache.js +0 -287
- package/dist/cjs/entities/DocumentFamiliyCache.js.map +0 -1
- package/dist/cjs/entities/FakeWeakRef.d.ts +0 -11
- package/dist/cjs/entities/FakeWeakRef.js +0 -19
- package/dist/cjs/entities/FakeWeakRef.js.map +0 -1
- package/dist/cjs/indexes.d.ts +0 -3
- package/dist/cjs/indexes.js +0 -20
- package/dist/cjs/indexes.js.map +0 -1
- package/dist/esm/entities/2/Entity.d.ts +0 -148
- package/dist/esm/entities/2/Entity.js +0 -707
- package/dist/esm/entities/2/Entity.js.map +0 -1
- package/dist/esm/entities/2/Entity.test.js.map +0 -1
- package/dist/esm/entities/2/EntityCache.js.map +0 -1
- package/dist/esm/entities/2/EntityMetadata.js.map +0 -1
- package/dist/esm/entities/2/EntityStore.d.ts +0 -78
- package/dist/esm/entities/2/EntityStore.js +0 -348
- package/dist/esm/entities/2/EntityStore.js.map +0 -1
- package/dist/esm/entities/2/OperationBatcher.js.map +0 -1
- package/dist/esm/entities/DocumentFamiliyCache.d.ts +0 -96
- package/dist/esm/entities/DocumentFamiliyCache.js +0 -283
- package/dist/esm/entities/DocumentFamiliyCache.js.map +0 -1
- package/dist/esm/entities/FakeWeakRef.d.ts +0 -11
- package/dist/esm/entities/FakeWeakRef.js +0 -15
- package/dist/esm/entities/FakeWeakRef.js.map +0 -1
- package/dist/esm/indexes.d.ts +0 -3
- package/dist/esm/indexes.js +0 -15
- package/dist/esm/indexes.js.map +0 -1
- package/src/entities/2/NOTES.md +0 -22
- package/src/entities/design.tldr +0 -808
- /package/dist/cjs/entities/{2/Entity.test.d.ts → Entity.test.d.ts} +0 -0
- /package/dist/cjs/entities/{2/Entity.test.js → Entity.test.js} +0 -0
- /package/dist/cjs/entities/{2/EntityMetadata.js → EntityMetadata.js} +0 -0
- /package/dist/cjs/entities/{2/OperationBatcher.js → OperationBatcher.js} +0 -0
- /package/dist/cjs/entities/{2/types.d.ts → types.d.ts} +0 -0
- /package/dist/cjs/entities/{2/types.js → types.js} +0 -0
- /package/dist/esm/entities/{2/Entity.test.d.ts → Entity.test.d.ts} +0 -0
- /package/dist/esm/entities/{2/Entity.test.js → Entity.test.js} +0 -0
- /package/dist/esm/entities/{2/EntityMetadata.js → EntityMetadata.js} +0 -0
- /package/dist/esm/entities/{2/OperationBatcher.js → OperationBatcher.js} +0 -0
- /package/dist/esm/entities/{2/types.d.ts → types.d.ts} +0 -0
- /package/dist/esm/entities/{2/types.js → types.js} +0 -0
- /package/src/entities/{2/types.ts → types.ts} +0 -0
|
@@ -2,478 +2,350 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityStore = void 0;
|
|
4
4
|
const common_1 = require("@verdant-web/common");
|
|
5
|
+
const Entity_js_1 = require("./Entity.js");
|
|
6
|
+
const Disposable_js_1 = require("../utils/Disposable.js");
|
|
7
|
+
const EntityMetadata_js_1 = require("./EntityMetadata.js");
|
|
8
|
+
const OperationBatcher_js_1 = require("./OperationBatcher.js");
|
|
9
|
+
const QueryableStorage_js_1 = require("../queries/QueryableStorage.js");
|
|
10
|
+
const weak_event_1 = require("weak-event");
|
|
5
11
|
const utils_js_1 = require("../files/utils.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return this.context.undoHistory;
|
|
18
|
-
}
|
|
19
|
-
get schema() {
|
|
20
|
-
return this.context.schema;
|
|
21
|
-
}
|
|
22
|
-
constructor({ context, meta, batchTimeout = 200, files, }) {
|
|
23
|
-
this.documentFamilyCaches = new Map();
|
|
24
|
-
this.unsubscribes = [];
|
|
25
|
-
this._disposed = false;
|
|
26
|
-
this.currentBatchKey = DEFAULT_BATCH_KEY;
|
|
27
|
-
this.setContext = (context) => {
|
|
28
|
-
this.context = context;
|
|
12
|
+
var AbortReason;
|
|
13
|
+
(function (AbortReason) {
|
|
14
|
+
AbortReason[AbortReason["Reset"] = 0] = "Reset";
|
|
15
|
+
})(AbortReason || (AbortReason = {}));
|
|
16
|
+
class EntityStore extends Disposable_js_1.Disposable {
|
|
17
|
+
constructor({ ctx, meta, files, }) {
|
|
18
|
+
super();
|
|
19
|
+
this.events = {
|
|
20
|
+
add: new weak_event_1.WeakEvent(),
|
|
21
|
+
replace: new weak_event_1.WeakEvent(),
|
|
22
|
+
resetAll: new weak_event_1.WeakEvent(),
|
|
29
23
|
};
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
this.refreshFamilyCache = async (familyCache, dropUnconfirmed = false, dropAll = false) => {
|
|
46
|
-
// avoid writing to disposed db
|
|
47
|
-
if (this._disposed) {
|
|
48
|
-
this.context.log('debug', `EntityStore is disposed, not refreshing ${familyCache.oid} cache`);
|
|
24
|
+
this.cache = new Map();
|
|
25
|
+
this.pendingEntityPromises = new Map();
|
|
26
|
+
// halts the current data queue processing
|
|
27
|
+
this.abortDataQueueController = new AbortController();
|
|
28
|
+
this.ongoingResetPromise = null;
|
|
29
|
+
this.entityFinalizationRegistry = new FinalizationRegistry((oid) => {
|
|
30
|
+
this.ctx.log('debug', 'Entity GC', oid);
|
|
31
|
+
});
|
|
32
|
+
// internal-ish API to load remote / stored data
|
|
33
|
+
this.addData = async (data) => {
|
|
34
|
+
if (this.disposed) {
|
|
35
|
+
this.ctx.log('warn', 'EntityStore is disposed, not adding incoming data');
|
|
49
36
|
return;
|
|
50
37
|
}
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
}, {
|
|
62
|
-
transaction,
|
|
63
|
-
mode: 'readwrite',
|
|
64
|
-
}),
|
|
65
|
-
this.meta.operations.iterateOverAllOperationsForDocument(familyCache.oid, (op) => {
|
|
66
|
-
op.confirmed = true;
|
|
67
|
-
operations.push(op);
|
|
68
|
-
}, { transaction, mode: 'readwrite' }),
|
|
69
|
-
]);
|
|
70
|
-
familyCache.reset({
|
|
71
|
-
operations,
|
|
72
|
-
baselines,
|
|
73
|
-
dropExistingUnconfirmed: dropUnconfirmed,
|
|
74
|
-
dropAll,
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
this.openFamilyCache = async (oid) => {
|
|
78
|
-
const documentOid = (0, common_1.getOidRoot)(oid);
|
|
79
|
-
let familyCache = this.documentFamilyCaches.get(documentOid);
|
|
80
|
-
if (!familyCache) {
|
|
81
|
-
this.context.log('debug', 'opening family cache for', documentOid);
|
|
82
|
-
// metadata must be loaded from database to initialize family cache
|
|
83
|
-
familyCache = new DocumentFamiliyCache_js_1.DocumentFamilyCache({
|
|
84
|
-
oid: documentOid,
|
|
85
|
-
store: this,
|
|
86
|
-
context: this.context,
|
|
38
|
+
// for resets - abort any other changes, reset everything,
|
|
39
|
+
// then proceed
|
|
40
|
+
if (data.reset) {
|
|
41
|
+
this.ctx.log('info', 'Resetting local store to replicate remote synced data - dropping any current transactions');
|
|
42
|
+
// cancel any other ongoing data - it will all
|
|
43
|
+
// be replaced by the reset
|
|
44
|
+
this.abortDataQueueController.abort(AbortReason.Reset);
|
|
45
|
+
this.abortDataQueueController = new AbortController();
|
|
46
|
+
this.ongoingResetPromise = this.resetData().finally(() => {
|
|
47
|
+
this.ongoingResetPromise = null;
|
|
87
48
|
});
|
|
88
|
-
// PROBLEM: because the next line is async, it yields to
|
|
89
|
-
// queued promises which may need data from this cache,
|
|
90
|
-
// but the cache is empty. But if we move the set to
|
|
91
|
-
// after the async, we can clobber an existing cache
|
|
92
|
-
// with race conditions...
|
|
93
|
-
// So as an attempt to fix that, I've added a promise
|
|
94
|
-
// on DocumentFamilyCache which I manually resolve
|
|
95
|
-
// with setInitialized, then await initializedPromise
|
|
96
|
-
// further down even if there was a cache hit.
|
|
97
|
-
// Surely there is a better pattern for this.
|
|
98
|
-
// FIXME:
|
|
99
|
-
this.documentFamilyCaches.set(documentOid, familyCache);
|
|
100
|
-
await this.refreshFamilyCache(familyCache);
|
|
101
|
-
familyCache.setInitialized();
|
|
102
|
-
// this.unsubscribes.push(
|
|
103
|
-
// familyCache.subscribe('change:*', this.onEntityChange),
|
|
104
|
-
// );
|
|
105
|
-
// TODO: cleanup cache when all documents are disposed
|
|
106
49
|
}
|
|
107
|
-
await
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
50
|
+
// await either the reset we just started, or any that was
|
|
51
|
+
// in progress when this data came in.
|
|
52
|
+
if (this.ongoingResetPromise) {
|
|
53
|
+
this.ctx.log('debug', 'Waiting for ongoing reset to complete');
|
|
54
|
+
await this.ongoingResetPromise;
|
|
55
|
+
this.ctx.log('debug', 'Ongoing reset complete');
|
|
56
|
+
}
|
|
57
|
+
await this.processData(data);
|
|
112
58
|
};
|
|
113
|
-
this.
|
|
114
|
-
if (this.
|
|
115
|
-
this.log('warn', 'EntityStore is disposed, not
|
|
59
|
+
this.resetData = async () => {
|
|
60
|
+
if (this.disposed) {
|
|
61
|
+
this.ctx.log('warn', 'EntityStore is disposed, not resetting local data');
|
|
116
62
|
return;
|
|
117
63
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
64
|
+
await this.meta.reset();
|
|
65
|
+
await this.queryableStorage.reset();
|
|
66
|
+
this.events.resetAll.invoke(this);
|
|
67
|
+
};
|
|
68
|
+
this.processData = async (data) => {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
if (this.disposed) {
|
|
71
|
+
this.ctx.log('warn', 'EntityStore is disposed, not processing incoming data');
|
|
123
72
|
return;
|
|
124
73
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
74
|
+
const baselines = (_a = data === null || data === void 0 ? void 0 : data.baselines) !== null && _a !== void 0 ? _a : [];
|
|
75
|
+
const operations = (_b = data === null || data === void 0 ? void 0 : data.operations) !== null && _b !== void 0 ? _b : [];
|
|
76
|
+
this.ctx.log('debug', 'Processing incoming data', {
|
|
77
|
+
operations: operations.length,
|
|
78
|
+
baselines: baselines.length,
|
|
79
|
+
reset: !!data.reset,
|
|
80
|
+
});
|
|
81
|
+
const allDocumentOids = Array.from(new Set(baselines
|
|
82
|
+
.map((b) => (0, common_1.getOidRoot)(b.oid))
|
|
83
|
+
.concat(operations.map((o) => (0, common_1.getOidRoot)(o.oid)))));
|
|
84
|
+
const baselinesGroupedByOid = (0, common_1.groupBaselinesByRootOid)(baselines);
|
|
85
|
+
const operationsGroupedByOid = (0, common_1.groupPatchesByRootOid)(operations);
|
|
86
|
+
this.ctx.log('debug', 'Applying data to live entities');
|
|
87
|
+
// synchronously add/replace data in any open entities via eventing
|
|
88
|
+
for (const oid of allDocumentOids) {
|
|
89
|
+
const baselines = baselinesGroupedByOid[oid];
|
|
90
|
+
const operations = (_c = operationsGroupedByOid[oid]) !== null && _c !== void 0 ? _c : [];
|
|
91
|
+
const groupedOperations = (0, common_1.groupPatchesByOid)(operations);
|
|
92
|
+
// what happens if an entity is being hydrated
|
|
93
|
+
// while this is happening? - we wait for the hydration promise
|
|
94
|
+
// to complete, then invoke the event
|
|
95
|
+
const event = data.reset ? this.events.replace : this.events.add;
|
|
96
|
+
const hydrationPromise = this.pendingEntityPromises.get(oid);
|
|
97
|
+
if (hydrationPromise) {
|
|
98
|
+
hydrationPromise.then(() => {
|
|
99
|
+
event.invoke(this, {
|
|
100
|
+
oid,
|
|
101
|
+
baselines,
|
|
102
|
+
operations: groupedOperations,
|
|
103
|
+
isLocal: false,
|
|
104
|
+
});
|
|
105
|
+
});
|
|
133
106
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
107
|
+
else {
|
|
108
|
+
if (this.cache.has(oid)) {
|
|
109
|
+
this.ctx.log('debug', 'Cache has', oid, ', an event should follow.');
|
|
110
|
+
}
|
|
111
|
+
event.invoke(this, {
|
|
112
|
+
oid,
|
|
113
|
+
baselines,
|
|
114
|
+
operations: groupedOperations,
|
|
115
|
+
isLocal: false,
|
|
116
|
+
});
|
|
138
117
|
}
|
|
139
118
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
119
|
+
const abortOptions = {
|
|
120
|
+
abort: this.abortDataQueueController.signal,
|
|
121
|
+
};
|
|
122
|
+
// then, asynchronously add to the database
|
|
123
|
+
await this.meta.insertData(data, abortOptions);
|
|
124
|
+
// FIXME: entities hydrated here are not seeing
|
|
125
|
+
// the operations just inserted above!!
|
|
126
|
+
// IDEA: can we coordinate here with hydrate promises
|
|
127
|
+
// based on affected OIDs?
|
|
128
|
+
// recompute all affected documents for querying
|
|
129
|
+
const entities = await Promise.all(allDocumentOids.map(async (oid) => {
|
|
130
|
+
const entity = await this.hydrate(oid, abortOptions);
|
|
131
|
+
// if the entity is not found, we return a stub that
|
|
132
|
+
// indicates it's deleted and should be cleared
|
|
133
|
+
return (entity !== null && entity !== void 0 ? entity : {
|
|
134
|
+
oid,
|
|
135
|
+
getSnapshot() {
|
|
136
|
+
return null;
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}));
|
|
140
|
+
try {
|
|
141
|
+
await this.queryableStorage.saveEntities(entities, abortOptions);
|
|
145
142
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
catch (err) {
|
|
144
|
+
if (this.disposed) {
|
|
145
|
+
this.ctx.log('warn', 'Error saving entities to queryable storage - EntityStore is disposed', err);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.ctx.log('error', 'Error saving entities to queryable storage', err);
|
|
149
|
+
}
|
|
152
150
|
}
|
|
153
|
-
return familyCache.getEntity({ oid, fieldSchema: schema, readonlyKeys });
|
|
154
151
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
152
|
+
// internal-ish API for creating Entities from OIDs
|
|
153
|
+
// when query results come in
|
|
154
|
+
this.hydrate = async (oid, opts) => {
|
|
155
|
+
if (!(0, common_1.isRootOid)(oid)) {
|
|
156
|
+
throw new Error('Cannot hydrate non-root entity');
|
|
157
|
+
}
|
|
158
|
+
if (this.cache.has(oid)) {
|
|
159
|
+
this.ctx.log('debug', 'Hydrating entity from cache', oid);
|
|
160
|
+
const cached = this.cache.get(oid);
|
|
161
|
+
if (cached) {
|
|
162
|
+
const entity = cached.deref();
|
|
163
|
+
if (entity) {
|
|
164
|
+
if (entity.deleted) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
return entity;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.ctx.log('debug', "Removing GC'd entity from cache", oid);
|
|
171
|
+
this.cache.delete(oid);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// we don't want to hydrate two entities in parallel, so
|
|
176
|
+
// we use a promise to ensure that only one is ever
|
|
177
|
+
// constructed at a time
|
|
178
|
+
const pendingPromise = this.pendingEntityPromises.get(oid);
|
|
179
|
+
if (!pendingPromise) {
|
|
180
|
+
this.ctx.log('debug', 'Hydrating entity from storage', oid);
|
|
181
|
+
const entity = this.constructEntity(oid);
|
|
182
|
+
if (!entity) {
|
|
165
183
|
return null;
|
|
166
184
|
}
|
|
167
|
-
|
|
185
|
+
const pendingPromise = this.loadEntity(entity, opts);
|
|
186
|
+
pendingPromise.finally(() => {
|
|
187
|
+
this.pendingEntityPromises.delete(oid);
|
|
188
|
+
});
|
|
189
|
+
this.pendingEntityPromises.set(oid, pendingPromise);
|
|
190
|
+
return pendingPromise;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
this.ctx.log('debug', 'Waiting for entity hydration', oid);
|
|
194
|
+
return pendingPromise;
|
|
168
195
|
}
|
|
169
|
-
return null;
|
|
170
196
|
};
|
|
197
|
+
this.destroy = async () => {
|
|
198
|
+
this.dispose();
|
|
199
|
+
await this.batcher.flushAll();
|
|
200
|
+
};
|
|
201
|
+
// public APIs for manipulating entities
|
|
171
202
|
/**
|
|
172
|
-
* Creates a new
|
|
173
|
-
* document is submitted to storage and sync.
|
|
203
|
+
* Creates a new Entity with the given initial data.
|
|
174
204
|
*/
|
|
175
|
-
this.create = async (initial, oid,
|
|
176
|
-
|
|
205
|
+
this.create = async (initial, oid, { undoable = true } = {}) => {
|
|
206
|
+
this.ctx.log('debug', 'Creating new entity', oid);
|
|
207
|
+
const { collection } = (0, common_1.decomposeOid)(oid);
|
|
208
|
+
// remove any OID associations from the initial data
|
|
177
209
|
(0, common_1.removeOidsFromAllSubObjects)(initial);
|
|
178
|
-
//
|
|
210
|
+
// grab files and replace them with refs
|
|
179
211
|
const processed = (0, utils_js_1.processValueFiles)(initial, this.files.add);
|
|
180
212
|
(0, common_1.assignOid)(processed, oid);
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// we do this so it can be immediately queryable from storage...
|
|
186
|
-
// only holding it in memory would introduce lag before it shows up
|
|
187
|
-
// in other queries.
|
|
188
|
-
await this.submitOperations(operations, options);
|
|
189
|
-
const { schema, readonlyKeys } = this.getDocumentSchema(oid);
|
|
190
|
-
if (!schema) {
|
|
191
|
-
throw new Error(`Cannot create a document in the ${(0, common_1.decomposeOid)(oid).collection} collection; it is not defined in the current schema version.`);
|
|
213
|
+
// creating a new Entity with no data, then preloading the operations
|
|
214
|
+
const entity = this.constructEntity(oid);
|
|
215
|
+
if (!entity) {
|
|
216
|
+
throw new Error(`Could not put new document: no schema exists for collection ${collection}`);
|
|
192
217
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
218
|
+
const operations = this.meta.patchCreator.createInitialize(processed, oid);
|
|
219
|
+
await this.batcher.commitOperations(operations, {
|
|
220
|
+
undoable: !!undoable,
|
|
221
|
+
source: entity,
|
|
222
|
+
});
|
|
223
|
+
// TODO: what happens if you create an entity with an OID that already
|
|
224
|
+
// exists?
|
|
225
|
+
// we still need to synchronously add the initial operations to the Entity
|
|
226
|
+
// even though they are flowing through the system
|
|
227
|
+
// TODO: this could be better aligned to avoid grouping here
|
|
228
|
+
const operationsGroupedByOid = (0, common_1.groupPatchesByOid)(operations);
|
|
229
|
+
this.events.add.invoke(this, {
|
|
230
|
+
operations: operationsGroupedByOid,
|
|
231
|
+
isLocal: true,
|
|
232
|
+
oid,
|
|
209
233
|
});
|
|
234
|
+
this.cache.set(oid, this.ctx.weakRef(entity));
|
|
235
|
+
return entity;
|
|
210
236
|
};
|
|
211
|
-
this.
|
|
212
|
-
|
|
213
|
-
|
|
237
|
+
this.deleteAll = async (oids, options) => {
|
|
238
|
+
this.ctx.log('info', 'Deleting documents', oids);
|
|
239
|
+
(0, common_1.assert)(oids.every((oid) => oid === (0, common_1.getOidRoot)(oid)), 'Only root documents may be deleted via client methods');
|
|
240
|
+
const allOids = await Promise.all(oids.flatMap(async (oid) => {
|
|
241
|
+
var _a;
|
|
242
|
+
const entity = await this.hydrate(oid);
|
|
243
|
+
return (_a = entity === null || entity === void 0 ? void 0 : entity.__getFamilyOids__()) !== null && _a !== void 0 ? _a : [];
|
|
244
|
+
}));
|
|
245
|
+
// remove the entities from cache
|
|
214
246
|
oids.forEach((oid) => {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
247
|
+
this.cache.delete(oid);
|
|
248
|
+
this.ctx.log('debug', 'Deleted document from cache', oid);
|
|
249
|
+
});
|
|
250
|
+
// create the delete patches and wait for them to be applied
|
|
251
|
+
const operations = this.meta.patchCreator.createDeleteAll(allOids.flat());
|
|
252
|
+
await this.batcher.commitOperations(operations, {
|
|
253
|
+
undoable: (options === null || options === void 0 ? void 0 : options.undoable) === undefined ? true : options.undoable,
|
|
220
254
|
});
|
|
221
255
|
};
|
|
222
|
-
this.
|
|
223
|
-
|
|
224
|
-
const baselinesByDocumentOid = (0, common_1.groupBaselinesByRootOid)(baselines);
|
|
225
|
-
const operationsByDocumentOid = (0, common_1.groupPatchesByRootOid)(operations);
|
|
226
|
-
const allDocumentOids = Array.from(new Set(Object.keys(baselinesByDocumentOid).concat(Object.keys(operationsByDocumentOid))));
|
|
227
|
-
for (const oid of allDocumentOids) {
|
|
228
|
-
const familyCache = this.documentFamilyCaches.get(oid);
|
|
229
|
-
if (familyCache) {
|
|
230
|
-
familyCache.addData({
|
|
231
|
-
operations: operationsByDocumentOid[oid] || [],
|
|
232
|
-
baselines: baselinesByDocumentOid[oid] || [],
|
|
233
|
-
reset,
|
|
234
|
-
isLocal,
|
|
235
|
-
});
|
|
236
|
-
this.log('debug', 'Added data to cache for', oid, (_b = (_a = operationsByDocumentOid[oid]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, 'operations', (_d = (_c = baselinesByDocumentOid[oid]) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0, 'baselines');
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
this.log('debug', 'Could not add data to cache for', oid, 'because it is not open');
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return allDocumentOids;
|
|
256
|
+
this.delete = async (oid, options) => {
|
|
257
|
+
return this.deleteAll([oid], options);
|
|
243
258
|
};
|
|
244
|
-
this.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const taggedOperations = operations;
|
|
253
|
-
for (const op of taggedOperations) {
|
|
254
|
-
op.confirmed = false;
|
|
255
|
-
}
|
|
256
|
-
let allDocumentOids = [];
|
|
257
|
-
// in a reset scenario, it only makes things confusing if we
|
|
258
|
-
// optimistically apply incoming operations, since the local
|
|
259
|
-
// history is out of sync
|
|
260
|
-
if (reset) {
|
|
261
|
-
this.log('Resetting local store to replicate remote synced data', baselines.length, 'baselines, and', operations.length, 'operations');
|
|
262
|
-
await this.meta.reset();
|
|
263
|
-
await this.resetStoredDocuments();
|
|
264
|
-
allDocumentOids = Array.from(new Set(baselines
|
|
265
|
-
.map((b) => (0, common_1.getOidRoot)(b.oid))
|
|
266
|
-
.concat(operations.map((o) => (0, common_1.getOidRoot)(o.oid)))));
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
// first, synchronously add data to any open caches for immediate change propagation
|
|
270
|
-
allDocumentOids = this.addDataToOpenCaches({
|
|
271
|
-
operations: taggedOperations,
|
|
272
|
-
baselines,
|
|
273
|
-
reset,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
// then, asynchronously add data to storage
|
|
277
|
-
await this.meta.insertRemoteBaselines(baselines);
|
|
278
|
-
await this.meta.insertRemoteOperations(operations);
|
|
279
|
-
if (reset) {
|
|
280
|
-
await this.refreshAllCaches(true, true);
|
|
281
|
-
}
|
|
282
|
-
// recompute all affected documents for querying
|
|
283
|
-
for (const oid of allDocumentOids) {
|
|
284
|
-
await this.writeDocumentToStorage(oid);
|
|
259
|
+
this.getCollectionSchema = (collectionName) => {
|
|
260
|
+
const schema = this.ctx.schema.collections[collectionName];
|
|
261
|
+
if (!schema) {
|
|
262
|
+
this.ctx.log('warn', `Missing schema for collection: ${collectionName}`);
|
|
263
|
+
return {
|
|
264
|
+
schema: null,
|
|
265
|
+
readonlyKeys: [],
|
|
266
|
+
};
|
|
285
267
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this.log('Adding local operations', operations.length);
|
|
293
|
-
this.addOperationsToOpenCaches(operations, {
|
|
294
|
-
isLocal: true,
|
|
295
|
-
confirmed: false,
|
|
296
|
-
});
|
|
297
|
-
this.operationBatcher.add({
|
|
298
|
-
key: this.currentBatchKey,
|
|
299
|
-
items: operations,
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
this.batch = ({ undoable = true, batchName = (0, common_1.generateId)(), max = null, timeout = this.defaultBatchTimeout, } = {}) => {
|
|
303
|
-
const internalBatch = this.operationBatcher.add({
|
|
304
|
-
key: batchName,
|
|
305
|
-
max,
|
|
306
|
-
timeout,
|
|
307
|
-
items: [],
|
|
308
|
-
userData: { undoable },
|
|
309
|
-
});
|
|
310
|
-
const externalApi = {
|
|
311
|
-
run: (fn) => {
|
|
312
|
-
// while the provided function runs, operations are forwarded
|
|
313
|
-
// to the new batch instead of default. this relies on the function
|
|
314
|
-
// being synchronous.
|
|
315
|
-
this.currentBatchKey = batchName;
|
|
316
|
-
fn();
|
|
317
|
-
this.currentBatchKey = DEFAULT_BATCH_KEY;
|
|
318
|
-
return externalApi;
|
|
319
|
-
},
|
|
320
|
-
flush: async () => {
|
|
321
|
-
// before running a batch, the default operations must be flushed
|
|
322
|
-
// this better preserves undo history behavior...
|
|
323
|
-
// if we left the default batch open while flushing a named batch,
|
|
324
|
-
// then the default batch would be flushed after the named batch,
|
|
325
|
-
// and the default batch could contain operations both prior and
|
|
326
|
-
// after the named batch. this would result in a confusing undo
|
|
327
|
-
// history where the first undo might reverse changes before and
|
|
328
|
-
// after a set of other changes.
|
|
329
|
-
await this.operationBatcher.flush(DEFAULT_BATCH_KEY);
|
|
330
|
-
return internalBatch.flush();
|
|
331
|
-
},
|
|
332
|
-
discard: () => {
|
|
333
|
-
this.operationBatcher.discard(batchName);
|
|
268
|
+
return {
|
|
269
|
+
// convert to object schema for compatibility
|
|
270
|
+
schema: {
|
|
271
|
+
type: 'object',
|
|
272
|
+
nullable: false,
|
|
273
|
+
properties: schema.fields,
|
|
334
274
|
},
|
|
275
|
+
readonlyKeys: [schema.primaryKey],
|
|
335
276
|
};
|
|
336
|
-
return externalApi;
|
|
337
277
|
};
|
|
338
278
|
/**
|
|
339
|
-
*
|
|
279
|
+
* Constructs an entity from an OID, but does not load it.
|
|
340
280
|
*/
|
|
341
|
-
this.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
347
|
-
this.flushOperations = async (operations, batchKey, meta) => {
|
|
348
|
-
if (!operations.length)
|
|
349
|
-
return;
|
|
350
|
-
this.log('Flushing operations', operations.length, 'to storage / sync');
|
|
351
|
-
// rewrite timestamps of all operations to now - this preserves
|
|
352
|
-
// the linear history of operations which are sent to the server.
|
|
353
|
-
// even if multiple batches are spun up in parallel and flushed
|
|
354
|
-
// after delay, the final operations in each one should reflect
|
|
355
|
-
// when the batch flushed, not when the changes were made.
|
|
356
|
-
// This also corresponds to user-observed behavior, since unconfirmed
|
|
357
|
-
// operations are applied universally after confirmed operations locally,
|
|
358
|
-
// so even operations which were made before a remote operation but
|
|
359
|
-
// have not been confirmed yet will appear to come after the remote one
|
|
360
|
-
// despite the provisional timestamp being earlier (see DocumentFamilyCache#computeView)
|
|
361
|
-
for (const op of operations) {
|
|
362
|
-
op.timestamp = this.meta.now;
|
|
363
|
-
}
|
|
364
|
-
await this.submitOperations(operations, meta);
|
|
365
|
-
};
|
|
366
|
-
this.submitOperations = async (operations, { undoable = true } = {}) => {
|
|
367
|
-
if (undoable) {
|
|
368
|
-
// FIXME: this is too slow and needs to be optimized.
|
|
369
|
-
this.undoHistory.addUndo(await this.createUndo(operations));
|
|
370
|
-
}
|
|
371
|
-
await this.meta.insertLocalOperation(operations);
|
|
372
|
-
// confirm the operations
|
|
373
|
-
this.addDataToOpenCaches({ operations, baselines: [] });
|
|
374
|
-
// recompute all affected documents for querying
|
|
375
|
-
const allDocumentOids = Array.from(new Set(operations.map((op) => (0, common_1.getOidRoot)(op.oid))));
|
|
376
|
-
for (const oid of allDocumentOids) {
|
|
377
|
-
await this.writeDocumentToStorage(oid);
|
|
378
|
-
}
|
|
379
|
-
// TODO: find a more efficient and straightforward way to update affected
|
|
380
|
-
// queries. Move to Metadata?
|
|
381
|
-
const affectedCollections = new Set(operations.map(({ oid }) => (0, common_1.decomposeOid)(oid).collection));
|
|
382
|
-
this.context.log('changes to collections', affectedCollections);
|
|
383
|
-
this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
|
|
384
|
-
};
|
|
385
|
-
this.getInverseOperations = async (ops) => {
|
|
386
|
-
const grouped = (0, common_1.groupPatchesByIdentifier)(ops);
|
|
387
|
-
const inverseOps = [];
|
|
388
|
-
const getNow = () => this.meta.now;
|
|
389
|
-
for (const [oid, patches] of Object.entries(grouped)) {
|
|
390
|
-
const familyCache = await this.openFamilyCache(oid);
|
|
391
|
-
let { view, deleted } = familyCache.computeConfirmedView(oid);
|
|
392
|
-
const inverse = (0, common_1.getUndoOperations)(oid, view, patches, getNow);
|
|
393
|
-
inverseOps.unshift(...inverse);
|
|
394
|
-
}
|
|
395
|
-
return inverseOps;
|
|
396
|
-
};
|
|
397
|
-
this.createUndo = async (ops) => {
|
|
398
|
-
const inverseOps = await this.getInverseOperations(ops);
|
|
399
|
-
return async () => {
|
|
400
|
-
const redo = await this.createUndo(inverseOps);
|
|
401
|
-
await this.submitOperations(inverseOps.map((op) => {
|
|
402
|
-
op.timestamp = this.meta.now;
|
|
403
|
-
return op;
|
|
404
|
-
}),
|
|
405
|
-
// undos should not generate their own undo operations
|
|
406
|
-
// since they already calculate redo as the inverse.
|
|
407
|
-
{ undoable: false });
|
|
408
|
-
return redo;
|
|
409
|
-
};
|
|
410
|
-
};
|
|
411
|
-
this.delete = async (oid, options) => {
|
|
412
|
-
(0, common_1.assert)(oid === (0, common_1.getOidRoot)(oid), 'Only root documents may be deleted via client methods');
|
|
413
|
-
// we need to get all sub-object oids to delete alongside the root
|
|
414
|
-
const allOids = await this.meta.getAllDocumentRelatedOids(oid);
|
|
415
|
-
const patches = this.meta.patchCreator.createDeleteAll(allOids);
|
|
416
|
-
// don't enqueue these, submit as distinct operation
|
|
417
|
-
await this.submitOperations(patches, options);
|
|
418
|
-
};
|
|
419
|
-
this.deleteAll = async (oids, options) => {
|
|
420
|
-
const allOids = await Promise.all(oids.map((oid) => this.meta.getAllDocumentRelatedOids(oid)));
|
|
421
|
-
const patches = this.meta.patchCreator.createDeleteAll(allOids.flat());
|
|
422
|
-
// don't enqueue these, submit as distinct operation
|
|
423
|
-
await this.submitOperations(patches, options);
|
|
424
|
-
};
|
|
425
|
-
this.reset = async () => {
|
|
426
|
-
this.context.log('warn', 'Resetting local database');
|
|
427
|
-
await this.resetStoredDocuments();
|
|
428
|
-
await this.refreshAllCaches(true);
|
|
429
|
-
// this.context.entityEvents.emit(
|
|
430
|
-
// 'collectionsChanged',
|
|
431
|
-
// Object.keys(this.schema.collections),
|
|
432
|
-
// );
|
|
433
|
-
};
|
|
434
|
-
this.destroy = async () => {
|
|
435
|
-
this._disposed = true;
|
|
436
|
-
for (const unsubscribe of this.unsubscribes) {
|
|
437
|
-
unsubscribe();
|
|
281
|
+
this.constructEntity = (oid) => {
|
|
282
|
+
const { collection } = (0, common_1.decomposeOid)(oid);
|
|
283
|
+
const { schema, readonlyKeys } = this.getCollectionSchema(collection);
|
|
284
|
+
if (!schema) {
|
|
285
|
+
return null;
|
|
438
286
|
}
|
|
439
|
-
|
|
440
|
-
|
|
287
|
+
if (this.disposed) {
|
|
288
|
+
throw new Error('Cannot hydrate entity after store has been disposed');
|
|
441
289
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
//
|
|
448
|
-
//
|
|
449
|
-
|
|
290
|
+
const metadataFamily = new EntityMetadata_js_1.EntityFamilyMetadata({
|
|
291
|
+
ctx: this.ctx,
|
|
292
|
+
onPendingOperations: this.onPendingOperations,
|
|
293
|
+
rootOid: oid,
|
|
294
|
+
});
|
|
295
|
+
// this is created synchronously so it's immediately available
|
|
296
|
+
// to begin capturing incoming data.
|
|
297
|
+
return new Entity_js_1.Entity({
|
|
298
|
+
ctx: this.ctx,
|
|
299
|
+
oid,
|
|
300
|
+
schema,
|
|
301
|
+
readonlyKeys,
|
|
302
|
+
files: this.files,
|
|
303
|
+
metadataFamily: metadataFamily,
|
|
304
|
+
patchCreator: this.meta.patchCreator,
|
|
305
|
+
events: this.events,
|
|
306
|
+
});
|
|
450
307
|
};
|
|
451
|
-
this.
|
|
452
|
-
|
|
453
|
-
for (const collection of Object.keys(this.schema.collections)) {
|
|
454
|
-
const store = tx.objectStore(collection);
|
|
455
|
-
await (0, idb_js_1.storeRequestPromise)(store.clear());
|
|
456
|
-
}
|
|
308
|
+
this.onPendingOperations = (operations) => {
|
|
309
|
+
this.batcher.addOperations(operations);
|
|
457
310
|
};
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
311
|
+
/**
|
|
312
|
+
* Loads initial Entity data from storage
|
|
313
|
+
*/
|
|
314
|
+
this.loadEntity = async (entity, opts) => {
|
|
315
|
+
const { operations, baselines } = await this.meta.getDocumentData(entity.oid, opts);
|
|
316
|
+
if (!baselines.length && !Object.keys(operations).length) {
|
|
317
|
+
this.ctx.log('debug', 'No data found for entity', entity.oid);
|
|
318
|
+
return null;
|
|
461
319
|
}
|
|
320
|
+
this.ctx.log('debug', 'Loaded entity from storage', entity.oid);
|
|
321
|
+
this.events.replace.invoke(this, {
|
|
322
|
+
oid: entity.oid,
|
|
323
|
+
baselines,
|
|
324
|
+
operations,
|
|
325
|
+
isLocal: false,
|
|
326
|
+
});
|
|
327
|
+
// only set the cache after loading.
|
|
328
|
+
// TODO: is this cache/promise stuff redundant?
|
|
329
|
+
this.cache.set(entity.oid, this.ctx.weakRef(entity));
|
|
330
|
+
this.entityFinalizationRegistry.register(entity, entity.oid);
|
|
331
|
+
return entity;
|
|
462
332
|
};
|
|
463
|
-
this.
|
|
464
|
-
this.defaultBatchTimeout = batchTimeout;
|
|
333
|
+
this.ctx = ctx;
|
|
465
334
|
this.meta = meta;
|
|
466
335
|
this.files = files;
|
|
467
|
-
this.
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
max: 100,
|
|
473
|
-
timeout: batchTimeout,
|
|
474
|
-
userData: { undoable: true },
|
|
336
|
+
this.queryableStorage = new QueryableStorage_js_1.QueryableStorage({ ctx });
|
|
337
|
+
this.batcher = new OperationBatcher_js_1.OperationBatcher({
|
|
338
|
+
ctx,
|
|
339
|
+
meta,
|
|
340
|
+
entities: this,
|
|
475
341
|
});
|
|
476
|
-
|
|
342
|
+
}
|
|
343
|
+
// expose batch APIs
|
|
344
|
+
get batch() {
|
|
345
|
+
return this.batcher.batch;
|
|
346
|
+
}
|
|
347
|
+
get flushAllBatches() {
|
|
348
|
+
return this.batcher.flushAll;
|
|
477
349
|
}
|
|
478
350
|
}
|
|
479
351
|
exports.EntityStore = EntityStore;
|