@verdant-web/store 3.0.0-next.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/index.d.ts +2 -2
- 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/index.d.ts +2 -2
- 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/index.ts +2 -2
- 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
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { DocumentBaseline, EventSubscriber, ObjectIdentifier, Operation, StorageFieldSchema } from '@verdant-web/common';
|
|
2
|
-
import { Entity } from './Entity.js';
|
|
3
|
-
import type { EntityStore } from './EntityStore.js';
|
|
4
|
-
import { Context } from '../context.js';
|
|
5
|
-
import { TaggedOperation } from '../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* Local operations: operations on this client that haven't
|
|
8
|
-
* yet been synced and are only applied in-memory. These are
|
|
9
|
-
* always applied after all other operations, they are conceptually
|
|
10
|
-
* 'in the future' as they are not yet synced or stored.
|
|
11
|
-
*
|
|
12
|
-
* Confirmed operations: operations that have been synced and
|
|
13
|
-
* stored in the database.
|
|
14
|
-
*
|
|
15
|
-
* Unconfirmed operations: operations received from sync which
|
|
16
|
-
* have not been stored yet and are only in memory. These exist
|
|
17
|
-
* because new incoming operations are synchronously applied to
|
|
18
|
-
* cached entities while storage goes on async.
|
|
19
|
-
*/
|
|
20
|
-
export declare class DocumentFamilyCache extends EventSubscriber<Record<`change:${string}`, () => void> & {
|
|
21
|
-
'change:*': (oid: ObjectIdentifier) => void;
|
|
22
|
-
}> {
|
|
23
|
-
readonly oid: ObjectIdentifier;
|
|
24
|
-
private operationsMap;
|
|
25
|
-
private localOperationsMap;
|
|
26
|
-
private baselinesMap;
|
|
27
|
-
private entities;
|
|
28
|
-
private context;
|
|
29
|
-
private storeTools;
|
|
30
|
-
private _initialized;
|
|
31
|
-
get initializedPromise(): Promise<boolean>;
|
|
32
|
-
setInitialized: () => void;
|
|
33
|
-
constructor({ oid, store, context, }: {
|
|
34
|
-
oid: ObjectIdentifier;
|
|
35
|
-
store: EntityStore;
|
|
36
|
-
context: Context;
|
|
37
|
-
});
|
|
38
|
-
get weakRef(): <T extends object>(value: T) => WeakRef<T>;
|
|
39
|
-
insertLocalOperations: (operations: Operation[]) => void;
|
|
40
|
-
insertOperations: (operations: TaggedOperation[], info: {
|
|
41
|
-
isLocal: boolean;
|
|
42
|
-
affectedOids?: Set<ObjectIdentifier>;
|
|
43
|
-
}) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Insert new baselines for objects in this family.
|
|
46
|
-
* Automatically drops operations before the new baseline.
|
|
47
|
-
*/
|
|
48
|
-
insertBaselines: (baselines: DocumentBaseline[], { affectedOids, }: {
|
|
49
|
-
isLocal: boolean;
|
|
50
|
-
affectedOids?: Set<string> | undefined;
|
|
51
|
-
}) => void;
|
|
52
|
-
addData: ({ operations, baselines, reset, isLocal, }: {
|
|
53
|
-
operations: TaggedOperation[];
|
|
54
|
-
baselines: DocumentBaseline[];
|
|
55
|
-
reset?: boolean | undefined;
|
|
56
|
-
isLocal?: boolean | undefined;
|
|
57
|
-
}) => void;
|
|
58
|
-
private applyOperations;
|
|
59
|
-
computeView: (oid: ObjectIdentifier) => {
|
|
60
|
-
view: any;
|
|
61
|
-
deleted: boolean;
|
|
62
|
-
lastTimestamp: number | null;
|
|
63
|
-
};
|
|
64
|
-
computeConfirmedView: (oid: ObjectIdentifier) => {
|
|
65
|
-
view: any;
|
|
66
|
-
deleted: boolean;
|
|
67
|
-
empty: boolean;
|
|
68
|
-
};
|
|
69
|
-
getLastTimestamp: (oid: ObjectIdentifier) => number | null;
|
|
70
|
-
getEntity: ({ oid, fieldSchema: schema, parent, readonlyKeys, fieldKey, }: {
|
|
71
|
-
oid: ObjectIdentifier;
|
|
72
|
-
fieldSchema: StorageFieldSchema;
|
|
73
|
-
parent?: Entity<any, any, any> | undefined;
|
|
74
|
-
readonlyKeys?: string[] | undefined;
|
|
75
|
-
fieldKey?: string | undefined;
|
|
76
|
-
}) => Entity;
|
|
77
|
-
hasOid: (oid: ObjectIdentifier) => boolean;
|
|
78
|
-
dispose: () => void;
|
|
79
|
-
reset: ({ operations, baselines, dropExistingUnconfirmed: dropUnconfirmed, unconfirmedOperations, dropAll, }: {
|
|
80
|
-
operations: TaggedOperation[];
|
|
81
|
-
unconfirmedOperations?: Operation[] | undefined;
|
|
82
|
-
baselines: DocumentBaseline[];
|
|
83
|
-
/**
|
|
84
|
-
* Whether to drop operations which are only in-memory. Unconfirmed operations
|
|
85
|
-
* will not be restored from storage until they are persisted, so it's not advisable
|
|
86
|
-
* to use this unless the intention is to completely clear the entities.
|
|
87
|
-
*/
|
|
88
|
-
dropExistingUnconfirmed?: boolean | undefined;
|
|
89
|
-
/**
|
|
90
|
-
* Drop unconfirmed and confirmed data before resetting to incoming data.
|
|
91
|
-
* This is dangerous due to race conditions. Only use when a full reset is
|
|
92
|
-
* required.
|
|
93
|
-
*/
|
|
94
|
-
dropAll?: boolean | undefined;
|
|
95
|
-
}) => void;
|
|
96
|
-
}
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentFamilyCache = void 0;
|
|
4
|
-
const common_1 = require("@verdant-web/common");
|
|
5
|
-
const Entity_js_1 = require("./Entity.js");
|
|
6
|
-
const Resolvable_js_1 = require("../utils/Resolvable.js");
|
|
7
|
-
/**
|
|
8
|
-
* Local operations: operations on this client that haven't
|
|
9
|
-
* yet been synced and are only applied in-memory. These are
|
|
10
|
-
* always applied after all other operations, they are conceptually
|
|
11
|
-
* 'in the future' as they are not yet synced or stored.
|
|
12
|
-
*
|
|
13
|
-
* Confirmed operations: operations that have been synced and
|
|
14
|
-
* stored in the database.
|
|
15
|
-
*
|
|
16
|
-
* Unconfirmed operations: operations received from sync which
|
|
17
|
-
* have not been stored yet and are only in memory. These exist
|
|
18
|
-
* because new incoming operations are synchronously applied to
|
|
19
|
-
* cached entities while storage goes on async.
|
|
20
|
-
*/
|
|
21
|
-
class DocumentFamilyCache extends common_1.EventSubscriber {
|
|
22
|
-
get initializedPromise() {
|
|
23
|
-
return this._initialized.promise;
|
|
24
|
-
}
|
|
25
|
-
constructor({ oid, store, context, }) {
|
|
26
|
-
super();
|
|
27
|
-
this.entities = new Map();
|
|
28
|
-
this._initialized = new Resolvable_js_1.Resolvable();
|
|
29
|
-
this.setInitialized = () => {
|
|
30
|
-
this._initialized.resolve(true);
|
|
31
|
-
};
|
|
32
|
-
this.insertLocalOperations = (operations) => {
|
|
33
|
-
const oidSet = new Set();
|
|
34
|
-
for (const operation of operations) {
|
|
35
|
-
const { oid } = operation;
|
|
36
|
-
oidSet.add(oid);
|
|
37
|
-
const existingOperations = this.localOperationsMap.get(oid) || [];
|
|
38
|
-
existingOperations.push(operation);
|
|
39
|
-
this.localOperationsMap.set(oid, existingOperations);
|
|
40
|
-
}
|
|
41
|
-
for (const oid of oidSet) {
|
|
42
|
-
const entityRef = this.entities.get(oid);
|
|
43
|
-
const entity = entityRef === null || entityRef === void 0 ? void 0 : entityRef.deref();
|
|
44
|
-
if (entity) {
|
|
45
|
-
(0, Entity_js_1.refreshEntity)(entity, { isLocal: true });
|
|
46
|
-
this.emit(`change:${oid}`);
|
|
47
|
-
this.emit('change:*', oid);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
this.insertOperations = (operations, info) => {
|
|
52
|
-
var _a;
|
|
53
|
-
for (const operation of operations) {
|
|
54
|
-
const { oid } = operation;
|
|
55
|
-
(_a = info.affectedOids) === null || _a === void 0 ? void 0 : _a.add(oid);
|
|
56
|
-
const existingOperations = this.operationsMap.get(oid) || [];
|
|
57
|
-
// insert in order of timestamp
|
|
58
|
-
const index = existingOperations.findIndex((op) => op.timestamp >= operation.timestamp);
|
|
59
|
-
// ensure the operation doesn't already exist in this position
|
|
60
|
-
if (index !== -1) {
|
|
61
|
-
if (existingOperations[index].timestamp === operation.timestamp) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
existingOperations.splice(index, 0, operation);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
existingOperations.push(operation);
|
|
68
|
-
}
|
|
69
|
-
this.operationsMap.set(oid, existingOperations);
|
|
70
|
-
// FIXME: seems inefficient
|
|
71
|
-
const unconfirmedOperations = this.localOperationsMap.get(oid);
|
|
72
|
-
if (unconfirmedOperations) {
|
|
73
|
-
this.localOperationsMap.set(oid, unconfirmedOperations.filter((op) => op.timestamp !== operation.timestamp));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Insert new baselines for objects in this family.
|
|
79
|
-
* Automatically drops operations before the new baseline.
|
|
80
|
-
*/
|
|
81
|
-
this.insertBaselines = (baselines, { affectedOids, }) => {
|
|
82
|
-
var _a;
|
|
83
|
-
for (const baseline of baselines) {
|
|
84
|
-
const { oid } = baseline;
|
|
85
|
-
// opt out if our baseline is newer.
|
|
86
|
-
const existing = this.baselinesMap.get(oid);
|
|
87
|
-
if ((existing === null || existing === void 0 ? void 0 : existing.timestamp) && existing.timestamp >= baseline.timestamp) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
affectedOids === null || affectedOids === void 0 ? void 0 : affectedOids.add(oid);
|
|
91
|
-
this.baselinesMap.set(oid, baseline);
|
|
92
|
-
// drop operations before the baseline
|
|
93
|
-
const ops = this.operationsMap.get(oid) || [];
|
|
94
|
-
while (((_a = ops[0]) === null || _a === void 0 ? void 0 : _a.timestamp) < baseline.timestamp) {
|
|
95
|
-
ops.shift();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
this.addData = ({ operations, baselines, reset, isLocal, }) => {
|
|
100
|
-
if (reset) {
|
|
101
|
-
this.operationsMap.clear();
|
|
102
|
-
this.baselinesMap.clear();
|
|
103
|
-
}
|
|
104
|
-
const info = {
|
|
105
|
-
isLocal: isLocal || false,
|
|
106
|
-
affectedOids: new Set(),
|
|
107
|
-
};
|
|
108
|
-
this.insertBaselines(baselines, info);
|
|
109
|
-
// for reset scenario, don't immediately update entities;
|
|
110
|
-
// we will update all of them in one go.
|
|
111
|
-
this.insertOperations(operations, info);
|
|
112
|
-
if (reset) {
|
|
113
|
-
for (const entityRef of this.entities.values()) {
|
|
114
|
-
const entity = entityRef.deref();
|
|
115
|
-
if (entity) {
|
|
116
|
-
(0, Entity_js_1.refreshEntity)(entity, info);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
for (const oid of info.affectedOids) {
|
|
122
|
-
const entityRef = this.entities.get(oid);
|
|
123
|
-
const entity = entityRef === null || entityRef === void 0 ? void 0 : entityRef.deref();
|
|
124
|
-
if (entity) {
|
|
125
|
-
(0, Entity_js_1.refreshEntity)(entity, info);
|
|
126
|
-
this.emit(`change:${oid}`);
|
|
127
|
-
this.emit('change:*', oid);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
this.applyOperations = (view, deleted, operations, after) => {
|
|
133
|
-
let futureSeen = undefined;
|
|
134
|
-
const now = this.storeTools.now;
|
|
135
|
-
for (const operation of operations) {
|
|
136
|
-
if (after && operation.timestamp <= after) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if ((0, common_1.compareTimestampSchemaVersions)(operation.timestamp, now) > 0) {
|
|
140
|
-
// we don't apply patches from future versions
|
|
141
|
-
futureSeen = operation.timestamp;
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
if (operation.data.op === 'delete') {
|
|
145
|
-
deleted = true;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
view = (0, common_1.applyPatch)(view, operation.data);
|
|
149
|
-
if (operation.data.op === 'initialize') {
|
|
150
|
-
deleted = false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (futureSeen) {
|
|
155
|
-
this.context.globalEvents.emit('futureSeen', futureSeen);
|
|
156
|
-
}
|
|
157
|
-
return { view, deleted, empty: !view && !operations.length };
|
|
158
|
-
};
|
|
159
|
-
this.computeView = (oid) => {
|
|
160
|
-
if (this.baselinesMap.size === 0 &&
|
|
161
|
-
this.operationsMap.size === 0 &&
|
|
162
|
-
this.localOperationsMap.size === 0) {
|
|
163
|
-
this.context.log('debug', `Entity ${oid} accessed with no data at all`);
|
|
164
|
-
return { view: null, deleted: true, lastTimestamp: null };
|
|
165
|
-
}
|
|
166
|
-
const confirmed = this.computeConfirmedView(oid);
|
|
167
|
-
const unconfirmedOperations = this.localOperationsMap.get(oid) || [];
|
|
168
|
-
if (confirmed.empty && !unconfirmedOperations.length) {
|
|
169
|
-
this.context.log('debug', `Entity ${oid} accessed with no local data at all`);
|
|
170
|
-
return { view: null, deleted: true, lastTimestamp: null };
|
|
171
|
-
}
|
|
172
|
-
let { view, deleted } = this.applyOperations(confirmed.view, confirmed.deleted, unconfirmedOperations);
|
|
173
|
-
if (view) {
|
|
174
|
-
(0, common_1.assignOid)(view, oid);
|
|
175
|
-
}
|
|
176
|
-
return { view, deleted, lastTimestamp: this.getLastTimestamp(oid) };
|
|
177
|
-
};
|
|
178
|
-
this.computeConfirmedView = (oid) => {
|
|
179
|
-
const baseline = this.baselinesMap.get(oid);
|
|
180
|
-
const operations = this.operationsMap.get(oid) || [];
|
|
181
|
-
const snapshot = (0, common_1.cloneDeep)((baseline === null || baseline === void 0 ? void 0 : baseline.snapshot) || undefined);
|
|
182
|
-
const result = this.applyOperations(snapshot, !snapshot, operations, baseline === null || baseline === void 0 ? void 0 : baseline.timestamp);
|
|
183
|
-
if (result.view) {
|
|
184
|
-
(0, common_1.assignOid)(result.view, oid);
|
|
185
|
-
}
|
|
186
|
-
if (result.empty) {
|
|
187
|
-
this.context.log('debug', `Entity ${oid} accessed with no confirmed data`);
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
190
|
-
};
|
|
191
|
-
this.getLastTimestamp = (oid) => {
|
|
192
|
-
var _a, _b, _c;
|
|
193
|
-
let operations = this.localOperationsMap.get(oid);
|
|
194
|
-
if (!(operations === null || operations === void 0 ? void 0 : operations.length)) {
|
|
195
|
-
operations = this.operationsMap.get(oid) || [];
|
|
196
|
-
}
|
|
197
|
-
let logicalTimestamp = null;
|
|
198
|
-
if (operations.length) {
|
|
199
|
-
logicalTimestamp = (_a = operations[operations.length - 1]) === null || _a === void 0 ? void 0 : _a.timestamp;
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
logicalTimestamp = (_c = (_b = this.baselinesMap.get(oid)) === null || _b === void 0 ? void 0 : _b.timestamp) !== null && _c !== void 0 ? _c : null;
|
|
203
|
-
}
|
|
204
|
-
if (!logicalTimestamp)
|
|
205
|
-
return null;
|
|
206
|
-
return this.storeTools.time.getWallClockTime(logicalTimestamp);
|
|
207
|
-
};
|
|
208
|
-
this.getEntity = ({ oid, fieldSchema: schema, parent, readonlyKeys, fieldKey, }) => {
|
|
209
|
-
var _a;
|
|
210
|
-
let entityRef = this.entities.get(oid);
|
|
211
|
-
let entity = entityRef === null || entityRef === void 0 ? void 0 : entityRef.deref();
|
|
212
|
-
if (!entity) {
|
|
213
|
-
entity = new Entity_js_1.Entity({
|
|
214
|
-
oid,
|
|
215
|
-
cache: this,
|
|
216
|
-
fieldSchema: schema,
|
|
217
|
-
store: this.storeTools,
|
|
218
|
-
parent,
|
|
219
|
-
readonlyKeys,
|
|
220
|
-
fieldPath: fieldKey
|
|
221
|
-
? [...((_a = parent === null || parent === void 0 ? void 0 : parent.fieldPath) !== null && _a !== void 0 ? _a : []), fieldKey]
|
|
222
|
-
: undefined,
|
|
223
|
-
});
|
|
224
|
-
// immediately add to cache and queue a removal if nobody subscribed
|
|
225
|
-
this.entities.set(oid, this.context.weakRef(entity));
|
|
226
|
-
}
|
|
227
|
-
return entity;
|
|
228
|
-
};
|
|
229
|
-
this.hasOid = (oid) => {
|
|
230
|
-
return this.operationsMap.has(oid) || this.baselinesMap.has(oid);
|
|
231
|
-
};
|
|
232
|
-
this.dispose = () => {
|
|
233
|
-
this.entities.forEach((entity) => { var _a; return (_a = entity.deref()) === null || _a === void 0 ? void 0 : _a.dispose(); });
|
|
234
|
-
this.entities.clear();
|
|
235
|
-
};
|
|
236
|
-
this.reset = ({ operations, baselines, dropExistingUnconfirmed: dropUnconfirmed = false, unconfirmedOperations, dropAll, }) => {
|
|
237
|
-
this.context.log('debug', `Resetting cache for ${this.oid} with ${operations.length} ops and ${baselines.length} baselines, dropUnconfirmed=${dropUnconfirmed}`);
|
|
238
|
-
const info = { isLocal: false, affectedOids: new Set() };
|
|
239
|
-
// NOTE: not clearing these maps... there are even more
|
|
240
|
-
// race conditions where we begin opening a cache, queue up a
|
|
241
|
-
// reset, then receive incoming operations before the reset
|
|
242
|
-
// actually hits this function, so those incoming ops are
|
|
243
|
-
// dropped.
|
|
244
|
-
// FIXME: include this in a future refactor of this
|
|
245
|
-
// whole system.
|
|
246
|
-
if (dropAll)
|
|
247
|
-
this.baselinesMap.clear();
|
|
248
|
-
this.insertBaselines(baselines, info);
|
|
249
|
-
if (dropAll)
|
|
250
|
-
this.operationsMap.clear();
|
|
251
|
-
this.insertOperations(operations, info);
|
|
252
|
-
if (unconfirmedOperations || dropUnconfirmed) {
|
|
253
|
-
this.localOperationsMap.clear();
|
|
254
|
-
if (unconfirmedOperations) {
|
|
255
|
-
this.insertLocalOperations(unconfirmedOperations);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
for (const oid of this.entities.keys()) {
|
|
259
|
-
const entityRef = this.entities.get(oid);
|
|
260
|
-
const entity = entityRef === null || entityRef === void 0 ? void 0 : entityRef.deref();
|
|
261
|
-
if (entity) {
|
|
262
|
-
(0, Entity_js_1.refreshEntity)(entity, info);
|
|
263
|
-
this.emit(`change:${oid}`);
|
|
264
|
-
this.emit('change:*', oid);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
this.oid = oid;
|
|
269
|
-
this.operationsMap = new Map();
|
|
270
|
-
this.localOperationsMap = new Map();
|
|
271
|
-
this.baselinesMap = new Map();
|
|
272
|
-
this.storeTools = {
|
|
273
|
-
addLocalOperations: store.addLocalOperations,
|
|
274
|
-
patchCreator: store.meta.patchCreator,
|
|
275
|
-
addFile: store.files.add,
|
|
276
|
-
getFile: store.files.get,
|
|
277
|
-
time: store.meta.time,
|
|
278
|
-
now: store.meta.now,
|
|
279
|
-
};
|
|
280
|
-
this.context = context;
|
|
281
|
-
}
|
|
282
|
-
get weakRef() {
|
|
283
|
-
return this.context.weakRef;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
exports.DocumentFamilyCache = DocumentFamilyCache;
|
|
287
|
-
//# sourceMappingURL=DocumentFamiliyCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentFamiliyCache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,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG;YACjB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY;YACrC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG;YACxB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;YACrB,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG;SACnB,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAC7B,CAAC;CAwVD;AA1YD,kDA0YC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module exists since I'm a little anxious about using WeakRef in production
|
|
3
|
-
* and want to be able to roll it back quickly to debug issues. Basically by adding
|
|
4
|
-
* import { WeakRef } from 'FakeWeakRef' to the top of the file, we can switch back
|
|
5
|
-
* to using a simple object reference.
|
|
6
|
-
*/
|
|
7
|
-
export declare class WeakRef<T> {
|
|
8
|
-
constructor(value: T);
|
|
9
|
-
value: T;
|
|
10
|
-
deref(): T | undefined;
|
|
11
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This module exists since I'm a little anxious about using WeakRef in production
|
|
4
|
-
* and want to be able to roll it back quickly to debug issues. Basically by adding
|
|
5
|
-
* import { WeakRef } from 'FakeWeakRef' to the top of the file, we can switch back
|
|
6
|
-
* to using a simple object reference.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.WeakRef = void 0;
|
|
10
|
-
class WeakRef {
|
|
11
|
-
constructor(value) {
|
|
12
|
-
this.value = value;
|
|
13
|
-
}
|
|
14
|
-
deref() {
|
|
15
|
-
return this.value;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.WeakRef = WeakRef;
|
|
19
|
-
//# sourceMappingURL=FakeWeakRef.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FakeWeakRef.js","sourceRoot":"","sources":["../../../src/entities/FakeWeakRef.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,MAAa,OAAO;IACnB,YAAY,KAAQ;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAID,KAAK;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAVD,0BAUC"}
|
package/dist/cjs/indexes.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { StorageCollectionSchema } from '@verdant-web/common';
|
|
2
|
-
export declare function computeSynthetics(schema: StorageCollectionSchema, obj: any): Record<string, any>;
|
|
3
|
-
export declare function computeCompoundIndices(schema: StorageCollectionSchema<any, any, any>, doc: any): any;
|
package/dist/cjs/indexes.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeCompoundIndices = exports.computeSynthetics = void 0;
|
|
4
|
-
const common_1 = require("@verdant-web/common");
|
|
5
|
-
function computeSynthetics(schema, obj) {
|
|
6
|
-
const result = {};
|
|
7
|
-
for (const [name, property] of Object.entries(schema.synthetics || {})) {
|
|
8
|
-
result[name] = property.compute(obj);
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
exports.computeSynthetics = computeSynthetics;
|
|
13
|
-
function computeCompoundIndices(schema, doc) {
|
|
14
|
-
return Object.entries(schema.compounds || {}).reduce((acc, [indexKey, index]) => {
|
|
15
|
-
acc[indexKey] = (0, common_1.createCompoundIndexValue)(...index.of.map((key) => doc[key]));
|
|
16
|
-
return acc;
|
|
17
|
-
}, {});
|
|
18
|
-
}
|
|
19
|
-
exports.computeCompoundIndices = computeCompoundIndices;
|
|
20
|
-
//# sourceMappingURL=indexes.js.map
|
package/dist/cjs/indexes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"indexes.js","sourceRoot":"","sources":["../../src/indexes.ts"],"names":[],"mappings":";;;AAAA,gDAM6B;AAE7B,SAAgB,iBAAiB,CAAC,MAA+B,EAAE,GAAQ;IAC1E,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE;QACvE,MAAM,CAAC,IAAI,CAAC,GAAI,QAA6C,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;KAC3E;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAND,8CAMC;AAED,SAAgB,sBAAsB,CACrC,MAA8C,EAC9C,GAAQ;IAER,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM,CAElD,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE;QAC5B,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAA,iCAAwB,EACvC,GAAI,KAA2C,CAAC,EAAE,CAAC,GAAG,CACrD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAoB,CACpC,CACD,CAAC;QACF,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAwC,CAAC,CAAC;AAC9C,CAAC;AAdD,wDAcC"}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { EntityValidationProblem, EventSubscriber, ObjectIdentifier, PatchCreator, StorageFieldSchema } from '@verdant-web/common';
|
|
2
|
-
import { Context } from '../../context.js';
|
|
3
|
-
import { FileManager } from '../../files/FileManager.js';
|
|
4
|
-
import { EntityCache } from './EntityCache.js';
|
|
5
|
-
import { EntityFamilyMetadata, EntityMetadataView } from './EntityMetadata.js';
|
|
6
|
-
import { BaseEntityValue, DataFromInit, DeepPartial, EntityChange, EntityEvents, ListEntity, ListItemInit, ListItemValue, ObjectEntity } from './types.js';
|
|
7
|
-
import { EntityStoreEvents } from './EntityStore.js';
|
|
8
|
-
export interface EntityInit {
|
|
9
|
-
oid: ObjectIdentifier;
|
|
10
|
-
schema: StorageFieldSchema;
|
|
11
|
-
entityFamily?: EntityCache;
|
|
12
|
-
metadataFamily: EntityFamilyMetadata;
|
|
13
|
-
parent?: Entity;
|
|
14
|
-
ctx: Context;
|
|
15
|
-
files: FileManager;
|
|
16
|
-
readonlyKeys?: string[];
|
|
17
|
-
fieldPath?: (string | number)[];
|
|
18
|
-
patchCreator: PatchCreator;
|
|
19
|
-
events: EntityStoreEvents;
|
|
20
|
-
}
|
|
21
|
-
export declare class Entity<Init = any, KeyValue extends BaseEntityValue = any, Snapshot extends any = DataFromInit<Init>> extends EventSubscriber<EntityEvents> implements ObjectEntity<Init, KeyValue, Snapshot>, ListEntity<Init, KeyValue, Snapshot> {
|
|
22
|
-
readonly oid: ObjectIdentifier;
|
|
23
|
-
private readonlyKeys;
|
|
24
|
-
private fieldPath;
|
|
25
|
-
private entityFamily;
|
|
26
|
-
private metadataFamily;
|
|
27
|
-
private schema;
|
|
28
|
-
private parent;
|
|
29
|
-
private ctx;
|
|
30
|
-
private files;
|
|
31
|
-
private patchCreator;
|
|
32
|
-
private events;
|
|
33
|
-
private _viewData;
|
|
34
|
-
private validationError;
|
|
35
|
-
private cachedDeepUpdatedAt;
|
|
36
|
-
private wasDeletedLastChange;
|
|
37
|
-
private cachedView;
|
|
38
|
-
constructor({ oid, schema, entityFamily: childCache, parent, ctx, metadataFamily, readonlyKeys, files, patchCreator, events, }: EntityInit);
|
|
39
|
-
private onAdd;
|
|
40
|
-
private onReplace;
|
|
41
|
-
private onResetAll;
|
|
42
|
-
private get metadata();
|
|
43
|
-
/**
|
|
44
|
-
* The view of this Entity, not including nested
|
|
45
|
-
* entities (that's the snapshot - see #getSnapshot())
|
|
46
|
-
*
|
|
47
|
-
* Nested entities are represented by refs.
|
|
48
|
-
*/
|
|
49
|
-
private get viewData();
|
|
50
|
-
/** convenience getter for viewData.view */
|
|
51
|
-
private get rawView();
|
|
52
|
-
/**
|
|
53
|
-
* An Entity's View includes the rendering of its underlying data,
|
|
54
|
-
* connecting of children where refs were, and validation
|
|
55
|
-
* and pruning according to schema.
|
|
56
|
-
*/
|
|
57
|
-
private get view();
|
|
58
|
-
private childIsNull;
|
|
59
|
-
get uid(): string;
|
|
60
|
-
get deleted(): boolean;
|
|
61
|
-
get invalid(): boolean;
|
|
62
|
-
get isList(): any;
|
|
63
|
-
get updatedAt(): number;
|
|
64
|
-
get deepUpdatedAt(): number;
|
|
65
|
-
/**
|
|
66
|
-
* @internal - this is relevant to Verdant's system, not users.
|
|
67
|
-
*
|
|
68
|
-
* Indicates whether this document is from an outdated version
|
|
69
|
-
* of the schema - which means it cannot be used until it is upgraded.
|
|
70
|
-
*/
|
|
71
|
-
get isOutdatedVersion(): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Pruning - when entities have invalid children, we 'prune' that
|
|
74
|
-
* data up to the nearest prunable point - a nullable field,
|
|
75
|
-
* or a list.
|
|
76
|
-
*/
|
|
77
|
-
protected validate: (...args: unknown[]) => EntityValidationProblem | undefined;
|
|
78
|
-
private viewWithMappedChildren;
|
|
79
|
-
/**
|
|
80
|
-
* A current snapshot of this Entity's data, including nested
|
|
81
|
-
* Entities.
|
|
82
|
-
*/
|
|
83
|
-
getSnapshot: () => any;
|
|
84
|
-
private addPendingOperations;
|
|
85
|
-
private addConfirmedData;
|
|
86
|
-
private replaceAllData;
|
|
87
|
-
private resetAllData;
|
|
88
|
-
private change;
|
|
89
|
-
protected deepChange: (target: Entity, ev: EntityChange) => void;
|
|
90
|
-
private getChild;
|
|
91
|
-
/**
|
|
92
|
-
* Gets a value from this Entity. If the value
|
|
93
|
-
* is an object, it will be wrapped in another
|
|
94
|
-
* Entity.
|
|
95
|
-
*/
|
|
96
|
-
get: <Key extends keyof KeyValue>(key: Key) => KeyValue[Key];
|
|
97
|
-
private processInputValue;
|
|
98
|
-
private getDeleteMode;
|
|
99
|
-
/**
|
|
100
|
-
* Returns the referent value of an item in the list, used for
|
|
101
|
-
* operations which act on items. if the item is an object,
|
|
102
|
-
* it will attempt to create an OID reference to it. If it
|
|
103
|
-
* is a primitive, it will return the primitive.
|
|
104
|
-
*/
|
|
105
|
-
private getItemRefValue;
|
|
106
|
-
set: <Key extends keyof Init>(key: Key, value: Init[Key]) => void;
|
|
107
|
-
/**
|
|
108
|
-
* Returns a destructured version of this Entity, where child
|
|
109
|
-
* Entities are accessible at their respective keys.
|
|
110
|
-
*/
|
|
111
|
-
getAll: () => KeyValue;
|
|
112
|
-
delete: (key: any) => void;
|
|
113
|
-
keys: () => string[];
|
|
114
|
-
entries: () => [string, Exclude<KeyValue[keyof KeyValue], undefined>][];
|
|
115
|
-
values: () => Exclude<KeyValue[keyof KeyValue], undefined>[];
|
|
116
|
-
update: (data: DeepPartial<Init>, { merge, replaceSubObjects, }?: {
|
|
117
|
-
replaceSubObjects?: boolean | undefined;
|
|
118
|
-
merge?: boolean | undefined;
|
|
119
|
-
}) => void;
|
|
120
|
-
get length(): number;
|
|
121
|
-
push: (value: ListItemInit<Init>) => void;
|
|
122
|
-
insert: (index: number, value: ListItemInit<Init>) => void;
|
|
123
|
-
move: (from: number, to: number) => void;
|
|
124
|
-
moveItem: (item: ListItemValue<KeyValue>, to: number) => void;
|
|
125
|
-
add: (value: ListItemValue<KeyValue>) => void;
|
|
126
|
-
removeAll: (item: ListItemValue<KeyValue>) => void;
|
|
127
|
-
removeFirst: (item: ListItemValue<KeyValue>) => void;
|
|
128
|
-
removeLast: (item: ListItemValue<KeyValue>) => void;
|
|
129
|
-
[Symbol.iterator](): {
|
|
130
|
-
next: () => {
|
|
131
|
-
readonly value: ListItemValue<KeyValue>;
|
|
132
|
-
readonly done: false;
|
|
133
|
-
} | {
|
|
134
|
-
readonly value: undefined;
|
|
135
|
-
readonly done: true;
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
map: <U>(callback: (value: ListItemValue<KeyValue>, index: number) => U) => U[];
|
|
139
|
-
filter: (callback: (value: ListItemValue<KeyValue>, index: number) => boolean) => ListItemValue<KeyValue>[];
|
|
140
|
-
has: (value: ListItemValue<KeyValue>) => boolean;
|
|
141
|
-
forEach: (callback: (value: ListItemValue<KeyValue>, index: number) => void) => void;
|
|
142
|
-
some: (predicate: (value: ListItemValue<KeyValue>) => boolean) => boolean;
|
|
143
|
-
every: (predicate: (value: ListItemValue<KeyValue>) => boolean) => boolean;
|
|
144
|
-
find: (predicate: (value: ListItemValue<KeyValue>) => boolean) => ListItemValue<KeyValue> | undefined;
|
|
145
|
-
includes: (value: ListItemValue<KeyValue>) => boolean;
|
|
146
|
-
__getViewData__: (oid: ObjectIdentifier, type: 'confirmed' | 'pending') => EntityMetadataView;
|
|
147
|
-
__getFamilyOids__: () => string[];
|
|
148
|
-
}
|