mindoodb 0.2.9 → 0.3.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/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +23 -18
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +94 -28
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.d.ts +5 -1
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.js +13 -3
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +19 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +90 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/browser/index.mjs +33 -0
- package/dist/core/BaseMindooTenantDirectory.d.ts +86 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +353 -12
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/accesscontrol/directoryProjection.d.ts.map +1 -1
- package/dist/core/accesscontrol/directoryProjection.js +1 -0
- package/dist/core/accesscontrol/directoryProjection.js.map +1 -1
- package/dist/core/accesscontrol/types.d.ts +11 -2
- package/dist/core/accesscontrol/types.d.ts.map +1 -1
- package/dist/core/accesscontrol/types.js +3 -0
- package/dist/core/accesscontrol/types.js.map +1 -1
- package/dist/core/activity/ActivityIndex.d.ts +80 -0
- package/dist/core/activity/ActivityIndex.d.ts.map +1 -0
- package/dist/core/activity/ActivityIndex.js +378 -0
- package/dist/core/activity/ActivityIndex.js.map +1 -0
- package/dist/core/activity/MemoryActivityTable.d.ts +52 -0
- package/dist/core/activity/MemoryActivityTable.d.ts.map +1 -0
- package/dist/core/activity/MemoryActivityTable.js +196 -0
- package/dist/core/activity/MemoryActivityTable.js.map +1 -0
- package/dist/core/activity/SqliteActivityTable.d.ts +41 -0
- package/dist/core/activity/SqliteActivityTable.d.ts.map +1 -0
- package/dist/core/activity/SqliteActivityTable.js +302 -0
- package/dist/core/activity/SqliteActivityTable.js.map +1 -0
- package/dist/core/activity/index.d.ts +7 -0
- package/dist/core/activity/index.d.ts.map +1 -0
- package/dist/core/activity/index.js +37 -0
- package/dist/core/activity/index.js.map +1 -0
- package/dist/core/activity/mindoodbActivitySource.d.ts +17 -0
- package/dist/core/activity/mindoodbActivitySource.d.ts.map +1 -0
- package/dist/core/activity/mindoodbActivitySource.js +44 -0
- package/dist/core/activity/mindoodbActivitySource.js.map +1 -0
- package/dist/core/activity/summaryRuleClassifier.d.ts +57 -0
- package/dist/core/activity/summaryRuleClassifier.d.ts.map +1 -0
- package/dist/core/activity/summaryRuleClassifier.js +157 -0
- package/dist/core/activity/summaryRuleClassifier.js.map +1 -0
- package/dist/core/activity/types.d.ts +221 -0
- package/dist/core/activity/types.d.ts.map +1 -0
- package/dist/core/activity/types.js +37 -0
- package/dist/core/activity/types.js.map +1 -0
- package/dist/core/appendonlystores/network/AuthenticationService.d.ts +20 -0
- package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/AuthenticationService.js +47 -6
- package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -1
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts +6 -1
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.d.ts +14 -0
- package/dist/core/appendonlystores/network/types.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.js.map +1 -1
- package/dist/core/builtinDbInvariants.d.ts +4 -1
- package/dist/core/builtinDbInvariants.d.ts.map +1 -1
- package/dist/core/builtinDbInvariants.js +4 -1
- package/dist/core/builtinDbInvariants.js.map +1 -1
- package/dist/core/guestAdmissions.d.ts +133 -0
- package/dist/core/guestAdmissions.d.ts.map +1 -0
- package/dist/core/guestAdmissions.js +207 -0
- package/dist/core/guestAdmissions.js.map +1 -0
- package/dist/core/guestTickets.d.ts +25 -6
- package/dist/core/guestTickets.d.ts.map +1 -1
- package/dist/core/guestTickets.js +56 -21
- package/dist/core/guestTickets.js.map +1 -1
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +23 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/live/LiveSubChannel.d.ts +91 -0
- package/dist/core/live/LiveSubChannel.d.ts.map +1 -0
- package/dist/core/live/LiveSubChannel.js +222 -0
- package/dist/core/live/LiveSubChannel.js.map +1 -0
- package/dist/core/types.d.ts +35 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/guest/guestCall.d.ts +148 -0
- package/dist/guest/guestCall.d.ts.map +1 -0
- package/dist/guest/guestCall.js +248 -0
- package/dist/guest/guestCall.js.map +1 -0
- package/dist/guest/guestChat.d.ts +79 -0
- package/dist/guest/guestChat.d.ts.map +1 -0
- package/dist/guest/guestChat.js +297 -0
- package/dist/guest/guestChat.js.map +1 -0
- package/dist/guest/guestLink.d.ts +25 -3
- package/dist/guest/guestLink.d.ts.map +1 -1
- package/dist/guest/guestLink.js +44 -2
- package/dist/guest/guestLink.js.map +1 -1
- package/dist/guest/index.d.ts +4 -1
- package/dist/guest/index.d.ts.map +1 -1
- package/dist/guest/index.js +17 -1
- package/dist/guest/index.js.map +1 -1
- package/dist/node/server/MindooDBServer.d.ts.map +1 -1
- package/dist/node/server/MindooDBServer.js +1 -1
- package/dist/node/server/MindooDBServer.js.map +1 -1
- package/dist/server/GuestAdmissionService.d.ts +34 -0
- package/dist/server/GuestAdmissionService.d.ts.map +1 -0
- package/dist/server/GuestAdmissionService.js +36 -0
- package/dist/server/GuestAdmissionService.js.map +1 -0
- package/dist/server/GuestTicketService.d.ts.map +1 -1
- package/dist/server/GuestTicketService.js +15 -9
- package/dist/server/GuestTicketService.js.map +1 -1
- package/dist/server/SyncEventBus.d.ts +8 -0
- package/dist/server/SyncEventBus.d.ts.map +1 -1
- package/dist/server/SyncEventBus.js.map +1 -1
- package/dist/server/TenantManager.d.ts +24 -0
- package/dist/server/TenantManager.d.ts.map +1 -1
- package/dist/server/TenantManager.js +40 -1
- package/dist/server/TenantManager.js.map +1 -1
- package/dist/server/http/MindooDBServerCore.d.ts +5 -0
- package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
- package/dist/server/http/MindooDBServerCore.js +123 -13
- package/dist/server/http/MindooDBServerCore.js.map +1 -1
- package/dist/server/http/types.d.ts +9 -0
- package/dist/server/http/types.d.ts.map +1 -1
- package/dist/server/http/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActivityIndex = exports.DEFAULT_ACTIVITY_INITIAL_WINDOW_MS = exports.DEFAULT_ACTIVITY_SESSION_GAP_MS = void 0;
|
|
4
|
+
exports.DEFAULT_ACTIVITY_SESSION_GAP_MS = 15 * 60 * 1000;
|
|
5
|
+
exports.DEFAULT_ACTIVITY_INITIAL_WINDOW_MS = 30 * 24 * 60 * 60 * 1000;
|
|
6
|
+
const FEED_ENTRY_TYPES = new Set(["doc_create", "doc_change", "doc_delete", "doc_undelete"]);
|
|
7
|
+
/** Documents that never appear in a feed: setup, sealed key series, internal ids. */
|
|
8
|
+
function isTechnicalDocId(docId) {
|
|
9
|
+
return docId === "dbsetup" || docId.startsWith("$") || docId.startsWith("acl_");
|
|
10
|
+
}
|
|
11
|
+
function baseVerb(entryType) {
|
|
12
|
+
switch (entryType) {
|
|
13
|
+
case "doc_create":
|
|
14
|
+
return "create";
|
|
15
|
+
case "doc_delete":
|
|
16
|
+
return "delete";
|
|
17
|
+
case "doc_undelete":
|
|
18
|
+
return "restore";
|
|
19
|
+
default:
|
|
20
|
+
return "edit";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function toRawEntry(meta) {
|
|
24
|
+
const trusted = typeof meta.receivedAt === "number";
|
|
25
|
+
return {
|
|
26
|
+
entryId: meta.id,
|
|
27
|
+
docId: meta.docId,
|
|
28
|
+
entryType: meta.entryType,
|
|
29
|
+
createdAt: meta.createdAt,
|
|
30
|
+
trustedTime: trusted ? meta.receivedAt : meta.createdAt,
|
|
31
|
+
trusted,
|
|
32
|
+
actorKey: meta.createdByPublicKey,
|
|
33
|
+
dependencyIds: meta.dependencyIds ?? [],
|
|
34
|
+
decryptionKeyId: meta.decryptionKeyId,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function sameValue(a, b) {
|
|
38
|
+
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Builds and maintains the activity feed of one database: reads the store's
|
|
42
|
+
* entries after its cursor (metadata only), drops what the reader cannot
|
|
43
|
+
* decrypt and what the classifier does not report, maps parts to their
|
|
44
|
+
* subject and groups the entries into sessions (see {@link ActivityEvent}).
|
|
45
|
+
*
|
|
46
|
+
* Call {@link update} after syncs and local writes (and periodically); it is
|
|
47
|
+
* incremental, resumable and idempotent. The cursor is written in the same
|
|
48
|
+
* table write as the events, so a crash only repeats work.
|
|
49
|
+
*/
|
|
50
|
+
class ActivityIndex {
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.running = null;
|
|
53
|
+
this.queued = null;
|
|
54
|
+
this.feedKey = options.feedKey;
|
|
55
|
+
this.source = options.source;
|
|
56
|
+
this.classifier = options.classifier;
|
|
57
|
+
this.table = options.table;
|
|
58
|
+
this.gap = options.sessionGapMs ?? exports.DEFAULT_ACTIVITY_SESSION_GAP_MS;
|
|
59
|
+
this.initialWindow = options.initialWindowMs ?? exports.DEFAULT_ACTIVITY_INITIAL_WINDOW_MS;
|
|
60
|
+
this.pageSize = Math.max(1, options.pageSize ?? 500);
|
|
61
|
+
this.now = options.now ?? Date.now;
|
|
62
|
+
}
|
|
63
|
+
/** Events of this feed, newest first. */
|
|
64
|
+
query(query = {}) {
|
|
65
|
+
return this.table.query({ ...query, feedKeys: [this.feedKey] });
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Bring the feed up to date with the store. Concurrent calls share one
|
|
69
|
+
* run; a call during a run gets one follow-up run.
|
|
70
|
+
*/
|
|
71
|
+
update() {
|
|
72
|
+
if (!this.running) {
|
|
73
|
+
this.running = this.runUpdate().finally(() => {
|
|
74
|
+
this.running = null;
|
|
75
|
+
});
|
|
76
|
+
return this.running;
|
|
77
|
+
}
|
|
78
|
+
if (!this.queued) {
|
|
79
|
+
this.queued = this.running.then(() => {
|
|
80
|
+
this.queued = null;
|
|
81
|
+
return this.update();
|
|
82
|
+
}, () => {
|
|
83
|
+
this.queued = null;
|
|
84
|
+
return this.update();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return this.queued;
|
|
88
|
+
}
|
|
89
|
+
/** Remove events older than `before` and never take such entries in again. */
|
|
90
|
+
async prune(before) {
|
|
91
|
+
await this.running?.catch(() => undefined);
|
|
92
|
+
const state = await this.table.readState(this.feedKey);
|
|
93
|
+
const removed = await this.table.prune(this.feedKey, before);
|
|
94
|
+
if (state && state.since < before) {
|
|
95
|
+
await this.table.write(this.feedKey, {
|
|
96
|
+
state: { ...state, since: before },
|
|
97
|
+
events: [],
|
|
98
|
+
entries: [],
|
|
99
|
+
docMappings: [],
|
|
100
|
+
subjectFields: [],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return removed;
|
|
104
|
+
}
|
|
105
|
+
async runUpdate() {
|
|
106
|
+
const result = { scanned: 0, added: 0, events: 0 };
|
|
107
|
+
let state = await this.table.readState(this.feedKey);
|
|
108
|
+
const epoch = this.source.epoch ? await this.source.epoch() : null;
|
|
109
|
+
let clearDocMappings = false;
|
|
110
|
+
if (!state) {
|
|
111
|
+
state = { cursor: null, epoch, rulesFingerprint: this.classifier.fingerprint, since: this.now() - this.initialWindow };
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (epoch !== null && state.epoch !== null && state.epoch !== epoch) {
|
|
115
|
+
// Another numbering of the store: scan again. Entries already in the
|
|
116
|
+
// feed are recognised by id, so nothing is counted twice.
|
|
117
|
+
state = { ...state, cursor: null };
|
|
118
|
+
}
|
|
119
|
+
state = { ...state, epoch };
|
|
120
|
+
if (state.rulesFingerprint !== this.classifier.fingerprint) {
|
|
121
|
+
clearDocMappings = true;
|
|
122
|
+
state = { ...state, rulesFingerprint: this.classifier.fingerprint };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
await this.classifier.prepare?.();
|
|
126
|
+
const keyCache = new Map();
|
|
127
|
+
for (;;) {
|
|
128
|
+
const page = await this.source.scan(state.cursor, this.pageSize);
|
|
129
|
+
result.scanned += page.entries.length;
|
|
130
|
+
const next = { ...state, cursor: page.nextCursor ?? state.cursor };
|
|
131
|
+
const change = await this.processPage(page.entries, next, keyCache, clearDocMappings);
|
|
132
|
+
clearDocMappings = false;
|
|
133
|
+
result.added += change.added;
|
|
134
|
+
result.events += change.write.events.length;
|
|
135
|
+
await this.table.write(this.feedKey, change.write);
|
|
136
|
+
state = next;
|
|
137
|
+
if (!page.hasMore || !page.nextCursor)
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
async processPage(metas, state, keyCache, clearDocMappings) {
|
|
143
|
+
const write = {
|
|
144
|
+
state,
|
|
145
|
+
events: [],
|
|
146
|
+
entries: [],
|
|
147
|
+
docMappings: [],
|
|
148
|
+
subjectFields: [],
|
|
149
|
+
clearDocMappings,
|
|
150
|
+
};
|
|
151
|
+
// 1. Candidate entries: document entries in the window that the reader can decrypt.
|
|
152
|
+
const candidates = [];
|
|
153
|
+
for (const meta of metas) {
|
|
154
|
+
if (!FEED_ENTRY_TYPES.has(meta.entryType) || isTechnicalDocId(meta.docId))
|
|
155
|
+
continue;
|
|
156
|
+
const entry = toRawEntry(meta);
|
|
157
|
+
if (entry.trustedTime < state.since)
|
|
158
|
+
continue;
|
|
159
|
+
let readable = keyCache.get(entry.decryptionKeyId);
|
|
160
|
+
if (readable === undefined) {
|
|
161
|
+
readable = await this.source.hasKey(entry.decryptionKeyId);
|
|
162
|
+
keyCache.set(entry.decryptionKeyId, readable);
|
|
163
|
+
}
|
|
164
|
+
if (readable)
|
|
165
|
+
candidates.push(entry);
|
|
166
|
+
}
|
|
167
|
+
if (candidates.length === 0)
|
|
168
|
+
return { write, added: 0 };
|
|
169
|
+
const events = new Map();
|
|
170
|
+
const touched = new Set();
|
|
171
|
+
// 2. Entries already in the feed (rescan, or now witnessed).
|
|
172
|
+
const known = await this.table.readEntries(this.feedKey, candidates.map((entry) => entry.entryId));
|
|
173
|
+
const fresh = [];
|
|
174
|
+
const witnessed = [];
|
|
175
|
+
for (const entry of candidates) {
|
|
176
|
+
const existing = known.get(entry.entryId);
|
|
177
|
+
if (!existing)
|
|
178
|
+
fresh.push(entry);
|
|
179
|
+
else if (entry.trusted && !existing.trusted)
|
|
180
|
+
witnessed.push({ entry, eventId: existing.eventId });
|
|
181
|
+
}
|
|
182
|
+
if (witnessed.length) {
|
|
183
|
+
for (const event of await this.table.readEvents([...new Set(witnessed.map((w) => w.eventId))])) {
|
|
184
|
+
events.set(event.id, event);
|
|
185
|
+
}
|
|
186
|
+
for (const { entry, eventId } of witnessed) {
|
|
187
|
+
const event = events.get(eventId);
|
|
188
|
+
if (!event)
|
|
189
|
+
continue;
|
|
190
|
+
event.untrusted = Math.max(0, event.untrusted - 1);
|
|
191
|
+
event.trusted = event.untrusted === 0;
|
|
192
|
+
touched.add(eventId);
|
|
193
|
+
write.entries.push({ entryId: entry.entryId, eventId, trusted: true });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (fresh.length === 0) {
|
|
197
|
+
write.events = [...touched].map((id) => events.get(id)).filter(Boolean);
|
|
198
|
+
return { write, added: 0 };
|
|
199
|
+
}
|
|
200
|
+
// 3. Classify the changed documents (cached mapping first).
|
|
201
|
+
const docIds = [...new Set(fresh.map((entry) => entry.docId))];
|
|
202
|
+
const mappings = clearDocMappings ? new Map() : await this.table.readDocMappings(this.feedKey, docIds);
|
|
203
|
+
const missing = docIds.filter((docId) => !mappings.has(docId));
|
|
204
|
+
if (missing.length) {
|
|
205
|
+
const classified = await this.classifier.classify(missing);
|
|
206
|
+
for (const docId of missing) {
|
|
207
|
+
const found = classified.get(docId) ?? null;
|
|
208
|
+
// The mapping is kept; field values are not (they are read fresh per run).
|
|
209
|
+
const classification = found ? { ...found } : null;
|
|
210
|
+
if (classification)
|
|
211
|
+
delete classification.subjectFields;
|
|
212
|
+
const mapping = { classification };
|
|
213
|
+
// A document the classifier cannot see yet (deleted before it was
|
|
214
|
+
// summarized) is not remembered as "not taking part".
|
|
215
|
+
if (classified.has(docId))
|
|
216
|
+
write.docMappings.push({ docId, mapping });
|
|
217
|
+
mappings.set(docId, mapping);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Current field values of the subjects touched by this page.
|
|
221
|
+
const subjects = [
|
|
222
|
+
...new Set(docIds
|
|
223
|
+
.map((docId) => mappings.get(docId)?.classification?.subjectDocId)
|
|
224
|
+
.filter((id) => typeof id === "string")),
|
|
225
|
+
];
|
|
226
|
+
const current = subjects.length ? await this.classifier.classify(subjects) : new Map();
|
|
227
|
+
const fresherFields = new Map();
|
|
228
|
+
for (const subjectDocId of subjects) {
|
|
229
|
+
const fields = current.get(subjectDocId)?.subjectFields;
|
|
230
|
+
if (fields)
|
|
231
|
+
fresherFields.set(subjectDocId, fields);
|
|
232
|
+
}
|
|
233
|
+
// Last known values: for subjects the classifier no longer sees (deleted).
|
|
234
|
+
const previousFields = subjects.length
|
|
235
|
+
? await this.table.readSubjectFields(this.feedKey, subjects)
|
|
236
|
+
: new Map();
|
|
237
|
+
// Which event earlier entries (the parents of this page's entries) belong to.
|
|
238
|
+
const owners = new Map();
|
|
239
|
+
const parentIds = [...new Set(fresh.flatMap((entry) => entry.dependencyIds))];
|
|
240
|
+
if (parentIds.length) {
|
|
241
|
+
for (const [entryId, owner] of await this.table.readEntries(this.feedKey, parentIds))
|
|
242
|
+
owners.set(entryId, owner.eventId);
|
|
243
|
+
}
|
|
244
|
+
// 4. Group into sessions.
|
|
245
|
+
const oldestFresh = Math.min(...fresh.map((entry) => entry.trustedTime));
|
|
246
|
+
const recent = subjects.length
|
|
247
|
+
? await this.table.readRecentEvents(this.feedKey, subjects, oldestFresh - this.gap)
|
|
248
|
+
: [];
|
|
249
|
+
for (const event of recent)
|
|
250
|
+
if (!events.has(event.id))
|
|
251
|
+
events.set(event.id, event);
|
|
252
|
+
let added = 0;
|
|
253
|
+
for (const entry of fresh) {
|
|
254
|
+
const classification = mappings.get(entry.docId)?.classification;
|
|
255
|
+
if (!classification)
|
|
256
|
+
continue;
|
|
257
|
+
const verb = classification.partVerb && classification.subjectDocId !== entry.docId
|
|
258
|
+
? classification.partVerb
|
|
259
|
+
: baseVerb(entry.entryType);
|
|
260
|
+
if (classification.report && !classification.report.includes(verb))
|
|
261
|
+
continue;
|
|
262
|
+
const event = this.openEventFor(events, classification.subjectDocId, entry.actorKey, verb, entry.trustedTime)
|
|
263
|
+
?? this.newEvent(entry, classification, verb);
|
|
264
|
+
events.set(event.id, event);
|
|
265
|
+
this.addEntry(event, entry, owners);
|
|
266
|
+
owners.set(entry.entryId, event.id);
|
|
267
|
+
const fields = fresherFields.get(classification.subjectDocId) ?? previousFields.get(classification.subjectDocId);
|
|
268
|
+
if (fields)
|
|
269
|
+
event.fields = fields;
|
|
270
|
+
touched.add(event.id);
|
|
271
|
+
write.entries.push({ entryId: entry.entryId, eventId: event.id, trusted: entry.trusted });
|
|
272
|
+
added++;
|
|
273
|
+
}
|
|
274
|
+
// 5. Business events from field changes of the subjects.
|
|
275
|
+
if (fresherFields.size) {
|
|
276
|
+
const previous = previousFields;
|
|
277
|
+
for (const [subjectDocId, fields] of fresherFields) {
|
|
278
|
+
const rules = current.get(subjectDocId)?.fieldEvents ?? [];
|
|
279
|
+
const classification = current.get(subjectDocId);
|
|
280
|
+
const before = previous.get(subjectDocId);
|
|
281
|
+
if (before && rules.length) {
|
|
282
|
+
const lastEntry = [...fresh].reverse().find((entry) => mappings.get(entry.docId)?.classification?.subjectDocId === subjectDocId);
|
|
283
|
+
if (lastEntry) {
|
|
284
|
+
for (const rule of rules) {
|
|
285
|
+
if (!this.fieldRuleFires(rule, before[rule.when.field], fields[rule.when.field]))
|
|
286
|
+
continue;
|
|
287
|
+
const event = this.newEvent(lastEntry, classification, rule.id);
|
|
288
|
+
event.id = `${this.feedKey}|${lastEntry.entryId}#${rule.id}`;
|
|
289
|
+
this.addEntry(event, lastEntry, owners);
|
|
290
|
+
event.fields = fields;
|
|
291
|
+
if (rule.highlight)
|
|
292
|
+
event.highlight = true;
|
|
293
|
+
events.set(event.id, event);
|
|
294
|
+
touched.add(event.id);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (!before || !sameValue(before, fields))
|
|
299
|
+
write.subjectFields.push({ subjectDocId, fields });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
write.events = [...touched].map((id) => events.get(id)).filter(Boolean);
|
|
303
|
+
return { write, added };
|
|
304
|
+
}
|
|
305
|
+
fieldRuleFires(rule, before, after) {
|
|
306
|
+
if (sameValue(before, after))
|
|
307
|
+
return false;
|
|
308
|
+
if (rule.when.to !== undefined)
|
|
309
|
+
return sameValue(after, rule.when.to);
|
|
310
|
+
if (rule.when.from !== undefined)
|
|
311
|
+
return sameValue(before, rule.when.from);
|
|
312
|
+
return rule.when.changed === true;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The newest event of this subject and author within the gap that the
|
|
316
|
+
* entry may join: the same verb, or a `create` followed by edits.
|
|
317
|
+
*/
|
|
318
|
+
openEventFor(events, subjectDocId, actorKey, verb, time) {
|
|
319
|
+
let best = null;
|
|
320
|
+
for (const event of events.values()) {
|
|
321
|
+
if (event.subjectDocId !== subjectDocId || event.actorKey !== actorKey)
|
|
322
|
+
continue;
|
|
323
|
+
if (event.highlight || event.id.includes("#"))
|
|
324
|
+
continue;
|
|
325
|
+
if (event.verb !== verb && !(event.verb === "create" && verb === "edit"))
|
|
326
|
+
continue;
|
|
327
|
+
if (time > event.lastTime + this.gap || time < event.firstTime - this.gap)
|
|
328
|
+
continue;
|
|
329
|
+
if (!best || event.lastTime > best.lastTime)
|
|
330
|
+
best = event;
|
|
331
|
+
}
|
|
332
|
+
return best;
|
|
333
|
+
}
|
|
334
|
+
newEvent(entry, classification, verb) {
|
|
335
|
+
const event = {
|
|
336
|
+
id: `${this.feedKey}|${entry.entryId}`,
|
|
337
|
+
feedKey: this.feedKey,
|
|
338
|
+
subjectDocId: classification.subjectDocId,
|
|
339
|
+
verb,
|
|
340
|
+
actorKey: entry.actorKey,
|
|
341
|
+
firstTime: entry.trustedTime,
|
|
342
|
+
lastTime: entry.trustedTime,
|
|
343
|
+
trusted: true,
|
|
344
|
+
untrusted: 0,
|
|
345
|
+
entryCount: 0,
|
|
346
|
+
docs: [],
|
|
347
|
+
};
|
|
348
|
+
if (classification.kind !== undefined)
|
|
349
|
+
event.kind = classification.kind;
|
|
350
|
+
return event;
|
|
351
|
+
}
|
|
352
|
+
/** Add `entry` to `event`; `owners` names the event of every earlier entry known so far. */
|
|
353
|
+
addEntry(event, entry, owners) {
|
|
354
|
+
event.firstTime = Math.min(event.firstTime, entry.trustedTime);
|
|
355
|
+
event.lastTime = Math.max(event.lastTime, entry.trustedTime);
|
|
356
|
+
event.entryCount++;
|
|
357
|
+
if (!entry.trusted) {
|
|
358
|
+
event.untrusted++;
|
|
359
|
+
event.trusted = false;
|
|
360
|
+
}
|
|
361
|
+
let doc = event.docs.find((candidate) => candidate.docId === entry.docId);
|
|
362
|
+
if (!doc) {
|
|
363
|
+
doc = { docId: entry.docId, before: [], after: [], entryCount: 0 };
|
|
364
|
+
event.docs.push(doc);
|
|
365
|
+
}
|
|
366
|
+
doc.entryCount++;
|
|
367
|
+
// `before`: parents of the event's changes that lie outside the event.
|
|
368
|
+
for (const dep of entry.dependencyIds) {
|
|
369
|
+
if (owners.get(dep) !== event.id && !doc.before.includes(dep))
|
|
370
|
+
doc.before.push(dep);
|
|
371
|
+
}
|
|
372
|
+
// `after`: the event's heads of this document.
|
|
373
|
+
doc.after = doc.after.filter((id) => !entry.dependencyIds.includes(id));
|
|
374
|
+
doc.after.push(entry.entryId);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
exports.ActivityIndex = ActivityIndex;
|
|
378
|
+
//# sourceMappingURL=ActivityIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivityIndex.js","sourceRoot":"","sources":["../../../src/core/activity/ActivityIndex.ts"],"names":[],"mappings":";;;AAmDa,QAAA,+BAA+B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACjD,QAAA,kCAAkC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC;AAE7F,qFAAqF;AACrF,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAClF,CAAC;AAED,SAAS,QAAQ,CAAC,SAAiB;IACjC,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,QAAQ,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,QAAQ,CAAC;QAClB,KAAK,c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EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;YACnE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,GAAG,CAAC,UAAU,EAAE,CAAC;QACjB,uEAAuE;QACvE,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;YACtC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtF,CAAC;QACD,+CAA+C;QAC/C,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QACxE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACF;AApVD,sCAoVC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ActivityDocMapping, type ActivityEvent, type ActivityFeedState, type ActivityQuery, type ActivityQueryResult, type ActivityTable, type ActivityTableWrite } from "./types";
|
|
2
|
+
/** Matches `query` except for the keyset position. */
|
|
3
|
+
export declare function activityEventMatches(event: ActivityEvent, query: ActivityQuery): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* {@link ActivityTable} in memory: for tests, small databases and hosts
|
|
6
|
+
* without SQLite. Values are copied in and out, like a real table.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MemoryActivityTable implements ActivityTable {
|
|
9
|
+
private readonly feeds;
|
|
10
|
+
private feed;
|
|
11
|
+
readState(feedKey: string): Promise<ActivityFeedState | null>;
|
|
12
|
+
readDocMappings(feedKey: string, docIds: readonly string[]): Promise<Map<string, ActivityDocMapping>>;
|
|
13
|
+
readSubjectFields(feedKey: string, subjectDocIds: readonly string[]): Promise<Map<string, Record<string, unknown>>>;
|
|
14
|
+
readRecentEvents(feedKey: string, subjectDocIds: readonly string[], since: number): Promise<ActivityEvent[]>;
|
|
15
|
+
readEntries(feedKey: string, entryIds: readonly string[]): Promise<Map<string, {
|
|
16
|
+
eventId: string;
|
|
17
|
+
trusted: boolean;
|
|
18
|
+
}>>;
|
|
19
|
+
readEvents(eventIds: readonly string[]): Promise<ActivityEvent[]>;
|
|
20
|
+
write(feedKey: string, change: ActivityTableWrite): Promise<void>;
|
|
21
|
+
query(query: ActivityQuery): Promise<ActivityQueryResult>;
|
|
22
|
+
prune(feedKey: string, before: number): Promise<number>;
|
|
23
|
+
clear(feedKey: string): Promise<void>;
|
|
24
|
+
/** Feeds held here. */
|
|
25
|
+
feedKeys(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Everything of one feed as plain JSON, for hosts that persist the table
|
|
28
|
+
* themselves (e.g. encrypted in IndexedDB); `null` for an unknown feed.
|
|
29
|
+
*/
|
|
30
|
+
exportFeed(feedKey: string): ActivityFeedSnapshot | null;
|
|
31
|
+
/** Replace one feed with a snapshot from {@link exportFeed}. */
|
|
32
|
+
importFeed(feedKey: string, snapshot: ActivityFeedSnapshot): void;
|
|
33
|
+
}
|
|
34
|
+
/** One feed of a {@link MemoryActivityTable} as plain JSON. */
|
|
35
|
+
export interface ActivityFeedSnapshot {
|
|
36
|
+
state: ActivityFeedState | null;
|
|
37
|
+
events: ActivityEvent[];
|
|
38
|
+
entries: Array<{
|
|
39
|
+
entryId: string;
|
|
40
|
+
eventId: string;
|
|
41
|
+
trusted: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
docMappings: Array<{
|
|
44
|
+
docId: string;
|
|
45
|
+
mapping: ActivityDocMapping;
|
|
46
|
+
}>;
|
|
47
|
+
subjectFields: Array<{
|
|
48
|
+
subjectDocId: string;
|
|
49
|
+
fields: Record<string, unknown>;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=MemoryActivityTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryActivityTable.d.ts","sourceRoot":"","sources":["../../../src/core/activity/MemoryActivityTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,SAAS,CAAC;AAcjB,sDAAsD;AACtD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAQxF;AAED;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IAErD,OAAO,CAAC,IAAI;IASN,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAI7D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAWrG,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAWnH,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAW5G,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAA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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CACjF"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryActivityTable = void 0;
|
|
4
|
+
exports.activityEventMatches = activityEventMatches;
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
function clone(value) {
|
|
7
|
+
return value === undefined ? value : JSON.parse(JSON.stringify(value));
|
|
8
|
+
}
|
|
9
|
+
/** Matches `query` except for the keyset position. */
|
|
10
|
+
function activityEventMatches(event, query) {
|
|
11
|
+
if (query.feedKeys && !query.feedKeys.includes(event.feedKey))
|
|
12
|
+
return false;
|
|
13
|
+
if (query.subjectDocId !== undefined && event.subjectDocId !== query.subjectDocId)
|
|
14
|
+
return false;
|
|
15
|
+
if (query.actorKeys && !query.actorKeys.includes(event.actorKey))
|
|
16
|
+
return false;
|
|
17
|
+
if (query.excludeActorKeys && query.excludeActorKeys.includes(event.actorKey))
|
|
18
|
+
return false;
|
|
19
|
+
if (query.verbs && !query.verbs.includes(event.verb))
|
|
20
|
+
return false;
|
|
21
|
+
if (query.since !== undefined && event.lastTime < query.since)
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* {@link ActivityTable} in memory: for tests, small databases and hosts
|
|
27
|
+
* without SQLite. Values are copied in and out, like a real table.
|
|
28
|
+
*/
|
|
29
|
+
class MemoryActivityTable {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.feeds = new Map();
|
|
32
|
+
}
|
|
33
|
+
feed(feedKey) {
|
|
34
|
+
let data = this.feeds.get(feedKey);
|
|
35
|
+
if (!data) {
|
|
36
|
+
data = { state: null, events: new Map(), entries: new Map(), docMappings: new Map(), subjectFields: new Map() };
|
|
37
|
+
this.feeds.set(feedKey, data);
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
async readState(feedKey) {
|
|
42
|
+
return clone(this.feeds.get(feedKey)?.state ?? null);
|
|
43
|
+
}
|
|
44
|
+
async readDocMappings(feedKey, docIds) {
|
|
45
|
+
const result = new Map();
|
|
46
|
+
const data = this.feeds.get(feedKey);
|
|
47
|
+
if (!data)
|
|
48
|
+
return result;
|
|
49
|
+
for (const docId of docIds) {
|
|
50
|
+
const mapping = data.docMappings.get(docId);
|
|
51
|
+
if (mapping)
|
|
52
|
+
result.set(docId, clone(mapping));
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
async readSubjectFields(feedKey, subjectDocIds) {
|
|
57
|
+
const result = new Map();
|
|
58
|
+
const data = this.feeds.get(feedKey);
|
|
59
|
+
if (!data)
|
|
60
|
+
return result;
|
|
61
|
+
for (const id of subjectDocIds) {
|
|
62
|
+
const fields = data.subjectFields.get(id);
|
|
63
|
+
if (fields)
|
|
64
|
+
result.set(id, clone(fields));
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
async readRecentEvents(feedKey, subjectDocIds, since) {
|
|
69
|
+
const data = this.feeds.get(feedKey);
|
|
70
|
+
if (!data)
|
|
71
|
+
return [];
|
|
72
|
+
const subjects = new Set(subjectDocIds);
|
|
73
|
+
const result = [];
|
|
74
|
+
for (const event of data.events.values()) {
|
|
75
|
+
if (subjects.has(event.subjectDocId) && event.lastTime >= since)
|
|
76
|
+
result.push(clone(event));
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
async readEntries(feedKey, entryIds) {
|
|
81
|
+
const result = new Map();
|
|
82
|
+
const data = this.feeds.get(feedKey);
|
|
83
|
+
if (!data)
|
|
84
|
+
return result;
|
|
85
|
+
for (const id of entryIds) {
|
|
86
|
+
const entry = data.entries.get(id);
|
|
87
|
+
if (entry)
|
|
88
|
+
result.set(id, { ...entry });
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
async readEvents(eventIds) {
|
|
93
|
+
const result = [];
|
|
94
|
+
for (const id of eventIds) {
|
|
95
|
+
for (const data of this.feeds.values()) {
|
|
96
|
+
const event = data.events.get(id);
|
|
97
|
+
if (event) {
|
|
98
|
+
result.push(clone(event));
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
async write(feedKey, change) {
|
|
106
|
+
const data = this.feed(feedKey);
|
|
107
|
+
if (change.clearDocMappings)
|
|
108
|
+
data.docMappings.clear();
|
|
109
|
+
for (const event of change.events)
|
|
110
|
+
data.events.set(event.id, clone(event));
|
|
111
|
+
for (const entry of change.entries)
|
|
112
|
+
data.entries.set(entry.entryId, { eventId: entry.eventId, trusted: entry.trusted });
|
|
113
|
+
for (const { docId, mapping } of change.docMappings)
|
|
114
|
+
data.docMappings.set(docId, clone(mapping));
|
|
115
|
+
for (const { subjectDocId, fields } of change.subjectFields)
|
|
116
|
+
data.subjectFields.set(subjectDocId, clone(fields));
|
|
117
|
+
data.state = clone(change.state);
|
|
118
|
+
}
|
|
119
|
+
async query(query) {
|
|
120
|
+
const limit = (0, types_1.activityQueryLimit)(query.limit);
|
|
121
|
+
const matches = [];
|
|
122
|
+
for (const [feedKey, data] of this.feeds) {
|
|
123
|
+
if (query.feedKeys && !query.feedKeys.includes(feedKey))
|
|
124
|
+
continue;
|
|
125
|
+
for (const event of data.events.values()) {
|
|
126
|
+
if (!activityEventMatches(event, query))
|
|
127
|
+
continue;
|
|
128
|
+
if (query.after && (0, types_1.compareActivityEvents)(event, query.after) <= 0)
|
|
129
|
+
continue;
|
|
130
|
+
matches.push(event);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
matches.sort(types_1.compareActivityEvents);
|
|
134
|
+
const page = matches.slice(0, limit).map((event) => clone(event));
|
|
135
|
+
const last = page[page.length - 1];
|
|
136
|
+
return {
|
|
137
|
+
events: page,
|
|
138
|
+
nextCursor: matches.length > limit && last ? { lastTime: last.lastTime, id: last.id } : null,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async prune(feedKey, before) {
|
|
142
|
+
const data = this.feeds.get(feedKey);
|
|
143
|
+
if (!data)
|
|
144
|
+
return 0;
|
|
145
|
+
const removed = new Set();
|
|
146
|
+
for (const [id, event] of data.events) {
|
|
147
|
+
if (event.lastTime < before) {
|
|
148
|
+
data.events.delete(id);
|
|
149
|
+
removed.add(id);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (removed.size) {
|
|
153
|
+
for (const [entryId, entry] of data.entries) {
|
|
154
|
+
if (removed.has(entry.eventId))
|
|
155
|
+
data.entries.delete(entryId);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return removed.size;
|
|
159
|
+
}
|
|
160
|
+
async clear(feedKey) {
|
|
161
|
+
this.feeds.delete(feedKey);
|
|
162
|
+
}
|
|
163
|
+
/** Feeds held here. */
|
|
164
|
+
feedKeys() {
|
|
165
|
+
return [...this.feeds.keys()];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Everything of one feed as plain JSON, for hosts that persist the table
|
|
169
|
+
* themselves (e.g. encrypted in IndexedDB); `null` for an unknown feed.
|
|
170
|
+
*/
|
|
171
|
+
exportFeed(feedKey) {
|
|
172
|
+
const data = this.feeds.get(feedKey);
|
|
173
|
+
if (!data)
|
|
174
|
+
return null;
|
|
175
|
+
return clone({
|
|
176
|
+
state: data.state,
|
|
177
|
+
events: [...data.events.values()],
|
|
178
|
+
entries: [...data.entries].map(([entryId, entry]) => ({ entryId, ...entry })),
|
|
179
|
+
docMappings: [...data.docMappings].map(([docId, mapping]) => ({ docId, mapping })),
|
|
180
|
+
subjectFields: [...data.subjectFields].map(([subjectDocId, fields]) => ({ subjectDocId, fields })),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** Replace one feed with a snapshot from {@link exportFeed}. */
|
|
184
|
+
importFeed(feedKey, snapshot) {
|
|
185
|
+
const copy = clone(snapshot);
|
|
186
|
+
this.feeds.set(feedKey, {
|
|
187
|
+
state: copy.state,
|
|
188
|
+
events: new Map(copy.events.map((event) => [event.id, event])),
|
|
189
|
+
entries: new Map(copy.entries.map(({ entryId, eventId, trusted }) => [entryId, { eventId, trusted }])),
|
|
190
|
+
docMappings: new Map(copy.docMappings.map(({ docId, mapping }) => [docId, mapping])),
|
|
191
|
+
subjectFields: new Map(copy.subjectFields.map(({ subjectDocId, fields }) => [subjectDocId, fields])),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.MemoryActivityTable = MemoryActivityTable;
|
|
196
|
+
//# sourceMappingURL=MemoryActivityTable.js.map
|