@atolis-hq/wake 0.3.102 → 0.3.104
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.
|
@@ -73,7 +73,7 @@ function outcome(value) {
|
|
|
73
73
|
REJECTED: '\u{1F534} Changes Requested',
|
|
74
74
|
BLOCKED: '\u{1F7E0} Blocked',
|
|
75
75
|
FAILED: '\u274C Failed',
|
|
76
|
-
NEEDS_CLARIFICATION: '\u{1F7E0}
|
|
76
|
+
NEEDS_CLARIFICATION: '\u{1F7E0} Needs clarification',
|
|
77
77
|
}[value];
|
|
78
78
|
}
|
|
79
79
|
function fallback(value) {
|
|
@@ -40,7 +40,7 @@ export class FileEventJournal {
|
|
|
40
40
|
throw new Error(`Event id ${event.eventId} has already been used with different content`);
|
|
41
41
|
if (drafts.length > 0 && existing.every(isDefined))
|
|
42
42
|
return existing.filter(isDefined);
|
|
43
|
-
const streamEvents =
|
|
43
|
+
const streamEvents = this.cachedEventsForStream(stream);
|
|
44
44
|
if (streamEvents.length !== expectedSequence)
|
|
45
45
|
throw new WrongExpectedSequenceError(`Expected sequence ${expectedSequence} for ${key(stream)}, actual ${streamEvents.length}`);
|
|
46
46
|
for (const draft of drafts)
|
|
@@ -86,8 +86,12 @@ export class FileEventJournal {
|
|
|
86
86
|
async readStream(stream) {
|
|
87
87
|
const streamKey = key(stream);
|
|
88
88
|
const entries = await this.readCurrentEntries();
|
|
89
|
-
if (this.cached !== undefined
|
|
90
|
-
|
|
89
|
+
if (this.cached !== undefined) {
|
|
90
|
+
if (sameEntries(this.cached.entries, entries))
|
|
91
|
+
return this.cached.eventsByStream.get(streamKey) ?? [];
|
|
92
|
+
await this.scan(entries);
|
|
93
|
+
return this.cachedEventsForStream(stream);
|
|
94
|
+
}
|
|
91
95
|
const manifest = await this.loadManifest();
|
|
92
96
|
if (manifest !== undefined && isCompleteIndex(manifest, entries)) {
|
|
93
97
|
try {
|
|
@@ -180,11 +184,15 @@ export class FileEventJournal {
|
|
|
180
184
|
events: indexedEvents,
|
|
181
185
|
},
|
|
182
186
|
];
|
|
183
|
-
|
|
187
|
+
const events = [...priorEvents, ...newEnvelopes];
|
|
188
|
+
this.cached = { entries, events, eventsByStream: indexEventsByStream(events), segments };
|
|
184
189
|
}
|
|
185
190
|
manifestPath() {
|
|
186
191
|
return join(this.root, 'events', 'index-manifest.json');
|
|
187
192
|
}
|
|
193
|
+
cachedEventsForStream(stream) {
|
|
194
|
+
return this.cached?.eventsByStream.get(key(stream)) ?? [];
|
|
195
|
+
}
|
|
188
196
|
// Persisted alongside the segments, so any reader of the same on-disk
|
|
189
197
|
// journal — not just this instance — can skip straight to the segments
|
|
190
198
|
// that can hold what it's looking for on a cold cache. append() extends its
|
|
@@ -320,7 +328,7 @@ export class FileEventJournal {
|
|
|
320
328
|
events: indexedEvents,
|
|
321
329
|
});
|
|
322
330
|
}
|
|
323
|
-
this.cached = { entries, events, segments };
|
|
331
|
+
this.cached = { entries, events, eventsByStream: indexEventsByStream(events), segments };
|
|
324
332
|
return events;
|
|
325
333
|
}
|
|
326
334
|
}
|
|
@@ -380,6 +388,18 @@ function sameEntries(a, b) {
|
|
|
380
388
|
}));
|
|
381
389
|
}
|
|
382
390
|
const key = (stream) => `${stream.kind}:${stream.id}`;
|
|
391
|
+
function indexEventsByStream(events) {
|
|
392
|
+
const indexed = new Map();
|
|
393
|
+
for (const event of events) {
|
|
394
|
+
const streamKey = key(event.stream);
|
|
395
|
+
const streamEvents = indexed.get(streamKey);
|
|
396
|
+
if (streamEvents === undefined)
|
|
397
|
+
indexed.set(streamKey, [event]);
|
|
398
|
+
else
|
|
399
|
+
streamEvents.push(event);
|
|
400
|
+
}
|
|
401
|
+
return indexed;
|
|
402
|
+
}
|
|
383
403
|
const sameDraft = (event, draft) => isDeepStrictEqual({
|
|
384
404
|
eventId: event.eventId,
|
|
385
405
|
eventType: event.eventType,
|