@agentshouse/mdruntime 0.1.0-c7274d650bd05 → 0.1.0-c7a479c99b4a4
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/AGENTS.md +8 -1
- package/README.md +2 -2
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +88 -35
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +13 -7
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +1 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +126 -43
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +7 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +8 -6
- package/dist/outcome.d.ts +2 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +19 -15
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +33 -24
- package/dist/replica.d.ts +2 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +40 -26
- package/dist/room-draft.d.ts +0 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +2 -18
- package/dist/rows.d.ts +2 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +7 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +25 -16
- package/dist/store.d.ts +21 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +194 -89
- package/package.json +2 -2
package/dist/connection.js
CHANGED
|
@@ -3,15 +3,16 @@ import { cached, modelTypes, NO_MODEL, sameModel, } from './model.js';
|
|
|
3
3
|
import { observing } from './observation.js';
|
|
4
4
|
import { filterOf, identityOf, planOf, } from './query.js';
|
|
5
5
|
import { createReadSide } from './read-side.js';
|
|
6
|
+
import { markdownPath, roomOfKey } from './rows.js';
|
|
6
7
|
import { createSearchIndex, searchPlanOf, } from './search.js';
|
|
7
8
|
import { bootstrapRoom } from './bootstrap.js';
|
|
8
9
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
9
10
|
import { createConversationStore, } from './conversation.js';
|
|
10
|
-
import {
|
|
11
|
+
import { validRoot } from './collection.js';
|
|
11
12
|
import { createLog } from './log.js';
|
|
12
13
|
import { refreshRoom } from './refresh.js';
|
|
13
14
|
import { buildBatch } from './save.js';
|
|
14
|
-
import { applyReturned, compositionOf,
|
|
15
|
+
import { applyReturned, compositionOf, confirmedOf, landed, readReclassified, replicaOf, sameMembership, withdrawals, } from './replica.js';
|
|
15
16
|
import { changedParts, changesOf, held, readParts, returnedInto, underneath, } from './room-draft.js';
|
|
16
17
|
import { settled, same, saving, STARTING, transferring, } from './status.js';
|
|
17
18
|
import { detectStorageLoss, nextGeneration } from './durability.js';
|
|
@@ -34,6 +35,7 @@ function declaredSelection(room) {
|
|
|
34
35
|
selection.roots.every((other, at) => at === index || !within(other, root)));
|
|
35
36
|
}
|
|
36
37
|
export function composeRuntime(options) {
|
|
38
|
+
const localSaves = options.adapter.localSaves === true;
|
|
37
39
|
let authorization = options.authorization;
|
|
38
40
|
let opening;
|
|
39
41
|
let store;
|
|
@@ -44,6 +46,7 @@ export function composeRuntime(options) {
|
|
|
44
46
|
let limits = [];
|
|
45
47
|
let capabilities = [];
|
|
46
48
|
const rooms = new Map();
|
|
49
|
+
const counted = new Map();
|
|
47
50
|
const unreadable = new Set();
|
|
48
51
|
const models = new Map();
|
|
49
52
|
const liveModels = new Map();
|
|
@@ -107,9 +110,12 @@ export function composeRuntime(options) {
|
|
|
107
110
|
const serviceModeListeners = new Set();
|
|
108
111
|
let member = null;
|
|
109
112
|
const memberListeners = new Set();
|
|
113
|
+
const materialized = new Set();
|
|
114
|
+
let everyRoom = false;
|
|
115
|
+
const transfers = new Map();
|
|
110
116
|
const conversations = createConversationStore({
|
|
111
117
|
agents: declaredAgents,
|
|
112
|
-
documents: (locator) =>
|
|
118
|
+
documents: (locator) => rowsQuery(planOf({ rooms: [locator], select: 'all' }, roomFacts())),
|
|
113
119
|
call: (name, input) => invokeAction(name, input),
|
|
114
120
|
durably,
|
|
115
121
|
stream: () => options.adapter.conversations,
|
|
@@ -185,7 +191,7 @@ export function composeRuntime(options) {
|
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
193
|
function pending() {
|
|
188
|
-
return [...replicas.values()].some((replica) => replica.queue.length > 0);
|
|
194
|
+
return !localSaves && [...replicas.values()].some((replica) => replica.queue.length > 0);
|
|
189
195
|
}
|
|
190
196
|
function attention() {
|
|
191
197
|
const attentionRequired = [];
|
|
@@ -214,8 +220,24 @@ export function composeRuntime(options) {
|
|
|
214
220
|
}
|
|
215
221
|
return { attentionRequired, reset };
|
|
216
222
|
}
|
|
223
|
+
function documentsIn(locator) {
|
|
224
|
+
const replica = replicas.get(locator);
|
|
225
|
+
if (replica === undefined)
|
|
226
|
+
return 0;
|
|
227
|
+
const roots = replica.confirmed.record.typedSelection?.roots ?? [];
|
|
228
|
+
let count = 0;
|
|
229
|
+
for (const path of Object.keys(replica.visible.documents)) {
|
|
230
|
+
if (markdownPath(path) && !roots.some((root) => beneath(root, path)))
|
|
231
|
+
count += 1;
|
|
232
|
+
}
|
|
233
|
+
return count;
|
|
234
|
+
}
|
|
217
235
|
function listed() {
|
|
218
|
-
return structuredClone([...rooms.values()])
|
|
236
|
+
return structuredClone([...rooms.values()].map((room) => {
|
|
237
|
+
const documents = documentsIn(room.locator);
|
|
238
|
+
counted.set(room.locator, documents);
|
|
239
|
+
return { ...room, documents };
|
|
240
|
+
}));
|
|
219
241
|
}
|
|
220
242
|
function roomFacts(reach = null) {
|
|
221
243
|
const held = [...rooms.values()]
|
|
@@ -270,6 +292,8 @@ export function composeRuntime(options) {
|
|
|
270
292
|
listener(shown);
|
|
271
293
|
}
|
|
272
294
|
function entryOf(batch) {
|
|
295
|
+
if (localSaves)
|
|
296
|
+
return Object.freeze({ batch, state: 'local' });
|
|
273
297
|
const state = pendings.get(batch.id);
|
|
274
298
|
if (state?.accepted !== undefined) {
|
|
275
299
|
return Object.freeze({ batch, state: 'accepted', roomVersion: state.accepted });
|
|
@@ -290,12 +314,47 @@ export function composeRuntime(options) {
|
|
|
290
314
|
}
|
|
291
315
|
}
|
|
292
316
|
function applyChangeSet(set) {
|
|
317
|
+
const held = everyRoom
|
|
318
|
+
? set
|
|
319
|
+
: { ...set, documents: set.documents.filter(({ locator }) => materialized.has(locator)) };
|
|
320
|
+
readSide.apply(held);
|
|
321
|
+
searchIndex.changed(held);
|
|
322
|
+
}
|
|
323
|
+
function materialize(locators) {
|
|
324
|
+
if (everyRoom)
|
|
325
|
+
return;
|
|
326
|
+
if (locators === null)
|
|
327
|
+
everyRoom = true;
|
|
328
|
+
const sets = [];
|
|
329
|
+
for (const locator of locators ?? [...replicas.keys()]) {
|
|
330
|
+
if (materialized.has(locator))
|
|
331
|
+
continue;
|
|
332
|
+
materialized.add(locator);
|
|
333
|
+
const replica = replicas.get(locator);
|
|
334
|
+
if (replica !== undefined)
|
|
335
|
+
sets.push(changeSet(locator, null, replica));
|
|
336
|
+
}
|
|
337
|
+
if (sets.length === 0)
|
|
338
|
+
return;
|
|
339
|
+
const set = mergeChangeSets(sets);
|
|
293
340
|
readSide.apply(set);
|
|
294
341
|
searchIndex.changed(set);
|
|
295
342
|
}
|
|
343
|
+
function reachedRooms(plan) {
|
|
344
|
+
if (plan.rooms !== null)
|
|
345
|
+
return plan.rooms;
|
|
346
|
+
if (plan.reach === null)
|
|
347
|
+
return null;
|
|
348
|
+
return [...plan.reach.rooms, ...plan.reach.documents.map(roomOfKey)];
|
|
349
|
+
}
|
|
350
|
+
function rowsQuery(plan) {
|
|
351
|
+
materialize(reachedRooms(plan));
|
|
352
|
+
return readSide.query(plan);
|
|
353
|
+
}
|
|
296
354
|
function publishChangeSet(set) {
|
|
297
355
|
applyChangeSet(set);
|
|
298
|
-
if (set.rooms.length > 0
|
|
356
|
+
if (set.rooms.length > 0 ||
|
|
357
|
+
[...new Set(set.documents.map(({ locator }) => locator))].some((locator) => rooms.has(locator) && counted.get(locator) !== documentsIn(locator)))
|
|
299
358
|
emitRooms();
|
|
300
359
|
for (const locator of set.queues)
|
|
301
360
|
emitQueue(locator);
|
|
@@ -369,10 +428,7 @@ export function composeRuntime(options) {
|
|
|
369
428
|
model: revoked,
|
|
370
429
|
selectionModel: revoked,
|
|
371
430
|
};
|
|
372
|
-
|
|
373
|
-
replicas.set(locator, read.kind === 'staged'
|
|
374
|
-
? replicaOf(read.confirmed, before.queue, before)
|
|
375
|
-
: { ...before, confirmed: { ...before.confirmed, record } });
|
|
431
|
+
replicas.set(locator, replicaOf(confirmedOf(record, before.confirmed), before.queue, before));
|
|
376
432
|
}
|
|
377
433
|
rooms.set(locator, {
|
|
378
434
|
...room,
|
|
@@ -439,7 +495,7 @@ export function composeRuntime(options) {
|
|
|
439
495
|
emitRooms();
|
|
440
496
|
}
|
|
441
497
|
function unlistedHeld(listed) {
|
|
442
|
-
return [...new Set([...rooms.keys(), ...roomDrafts.keys()])].filter((locator) => !listed.has(locator));
|
|
498
|
+
return [...new Set([...rooms.keys(), ...roomDrafts.keys(), ...transfers.keys()])].filter((locator) => !listed.has(locator));
|
|
443
499
|
}
|
|
444
500
|
async function dropUnlisted(listed, local) {
|
|
445
501
|
if (unlistedHeld(listed).length === 0)
|
|
@@ -458,6 +514,7 @@ export function composeRuntime(options) {
|
|
|
458
514
|
replicas.delete(locator);
|
|
459
515
|
rooms.delete(locator);
|
|
460
516
|
roomDrafts.delete(locator);
|
|
517
|
+
transfers.delete(locator);
|
|
461
518
|
unreadable.delete(locator);
|
|
462
519
|
stale.delete(locator);
|
|
463
520
|
scopedRefusals.delete(locator);
|
|
@@ -494,7 +551,7 @@ export function composeRuntime(options) {
|
|
|
494
551
|
return model;
|
|
495
552
|
}
|
|
496
553
|
async function hydrate(opened) {
|
|
497
|
-
const [records, queues, kept, presented, held, chatDrafts, lastCompleted, declared, named, known,] = await Promise.all([
|
|
554
|
+
const [records, queues, kept, presented, held, chatDrafts, lastCompleted, declared, named, known, staged,] = await Promise.all([
|
|
498
555
|
opened.all(),
|
|
499
556
|
opened.queues(),
|
|
500
557
|
opened.roomDrafts(),
|
|
@@ -505,7 +562,11 @@ export function composeRuntime(options) {
|
|
|
505
562
|
opened.providerLimits(),
|
|
506
563
|
opened.capabilities(),
|
|
507
564
|
opened.member(),
|
|
565
|
+
opened.transfers(),
|
|
508
566
|
]);
|
|
567
|
+
transfers.clear();
|
|
568
|
+
for (const record of staged)
|
|
569
|
+
transfers.set(record.locator, record);
|
|
509
570
|
limits = declared;
|
|
510
571
|
capabilities = named;
|
|
511
572
|
member = known;
|
|
@@ -528,14 +589,7 @@ export function composeRuntime(options) {
|
|
|
528
589
|
const model = restored(modelKey(record.locator, 'collection'), record.model);
|
|
529
590
|
const selectionModel = restored(modelKey(record.locator, 'typed-selection'), record.selectionModel);
|
|
530
591
|
const prior = previousReplicas.get(record.locator);
|
|
531
|
-
const
|
|
532
|
-
const read = readConfirmed(retyped, prior?.confirmed);
|
|
533
|
-
const confirmed = read.kind === 'staged'
|
|
534
|
-
? read.confirmed
|
|
535
|
-
: {
|
|
536
|
-
record: retyped,
|
|
537
|
-
collection: parseCollection(retyped.documents, compositionOf(retyped)),
|
|
538
|
-
};
|
|
592
|
+
const confirmed = confirmedOf({ ...record, model, selectionModel }, prior?.confirmed);
|
|
539
593
|
replicas.set(record.locator, replicaOf(confirmed, queuedBatches.get(record.locator) ?? [], prior));
|
|
540
594
|
const existing = rooms.get(record.locator);
|
|
541
595
|
if (existing === undefined)
|
|
@@ -556,10 +610,6 @@ export function composeRuntime(options) {
|
|
|
556
610
|
},
|
|
557
611
|
});
|
|
558
612
|
}
|
|
559
|
-
if (read.kind === 'refused') {
|
|
560
|
-
refusedSource(record, read);
|
|
561
|
-
declarationRefusals.add(record.locator);
|
|
562
|
-
}
|
|
563
613
|
}
|
|
564
614
|
return {
|
|
565
615
|
lastCompleted,
|
|
@@ -621,11 +671,11 @@ export function composeRuntime(options) {
|
|
|
621
671
|
return state !== undefined && state.submission.state !== 'submitted' && !state.lost;
|
|
622
672
|
}
|
|
623
673
|
async function settle(local, locator, before, confirmed, queue, settling = {}) {
|
|
624
|
-
const withdrawn = withdrawals(confirmed, queue, withdrawable);
|
|
674
|
+
const withdrawn = withdrawals(confirmed, queue, withdrawable, localSaves);
|
|
625
675
|
const kept = queue.filter((batch) => !withdrawn.includes(batch));
|
|
626
676
|
const unqueued = withdrawn.map((batch) => ({
|
|
627
677
|
batch,
|
|
628
|
-
returned: landed(batch, confirmed) ? null : { kind: 'withdrawn' },
|
|
678
|
+
returned: localSaves || landed(batch, confirmed) ? null : { kind: 'withdrawn' },
|
|
629
679
|
}));
|
|
630
680
|
const returning = [
|
|
631
681
|
...[...unqueued].reverse(),
|
|
@@ -649,6 +699,7 @@ export function composeRuntime(options) {
|
|
|
649
699
|
await local.write({
|
|
650
700
|
next: confirmed.record,
|
|
651
701
|
previous: before?.confirmed.record ?? null,
|
|
702
|
+
...(settling.stored === undefined ? {} : { stored: settling.stored }),
|
|
652
703
|
queue: kept,
|
|
653
704
|
previousQueue: before?.queue ?? [],
|
|
654
705
|
roomDrafts: [...written.values()],
|
|
@@ -660,7 +711,8 @@ export function composeRuntime(options) {
|
|
|
660
711
|
for (const record of written.values())
|
|
661
712
|
rememberRoomDraft(record);
|
|
662
713
|
for (const { batch, returned } of unqueued) {
|
|
663
|
-
|
|
714
|
+
const outcome = localSaves ? 'dropped' : returned === null ? 'landed' : 'withdrawn';
|
|
715
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
664
716
|
}
|
|
665
717
|
replicas.set(locator, replicaOf(confirmed, kept, before));
|
|
666
718
|
return changeSet(locator, before ?? null, replicas.get(locator) ?? null, {
|
|
@@ -700,7 +752,8 @@ export function composeRuntime(options) {
|
|
|
700
752
|
selection: taken(answers?.selection, held.selection, 'typed-selection'),
|
|
701
753
|
};
|
|
702
754
|
}
|
|
703
|
-
function publish(local, room, confirmed,
|
|
755
|
+
function publish(local, room, confirmed, landing = {}) {
|
|
756
|
+
const { base, stored } = landing;
|
|
704
757
|
return exclusive(async () => {
|
|
705
758
|
if (!continuing())
|
|
706
759
|
return true;
|
|
@@ -717,7 +770,9 @@ export function composeRuntime(options) {
|
|
|
717
770
|
const accepted = pendings.get(batch.id)?.accepted;
|
|
718
771
|
return (accepted !== undefined && options.adapter.reached(room.locator, roomVersion, accepted));
|
|
719
772
|
});
|
|
720
|
-
const set = await settle(local, room.locator, prior, confirmed, queue.filter((batch) => !accepted.includes(batch)), { room: true });
|
|
773
|
+
const set = await settle(local, room.locator, prior, confirmed, queue.filter((batch) => !accepted.includes(batch)), { room: true, ...(stored === undefined ? {} : { stored }) });
|
|
774
|
+
if (stored !== undefined)
|
|
775
|
+
transfers.delete(room.locator);
|
|
721
776
|
for (const batch of accepted)
|
|
722
777
|
pendings.delete(batch.id);
|
|
723
778
|
stale.delete(room.locator);
|
|
@@ -752,6 +807,7 @@ export function composeRuntime(options) {
|
|
|
752
807
|
return { outcome: 'refused', rule: 'changed-underneath', parts: changed };
|
|
753
808
|
const parts = saved.map(({ path, parts }) => changesOf(path, parts));
|
|
754
809
|
const built = buildBatch({
|
|
810
|
+
local: localSaves,
|
|
755
811
|
baseRoomVersion: replica.confirmed.record.roomVersion,
|
|
756
812
|
composition: compositionFor(replica.confirmed.record),
|
|
757
813
|
operations: room.operations,
|
|
@@ -781,7 +837,8 @@ export function composeRuntime(options) {
|
|
|
781
837
|
return { outcome: 'refused', rule: 'durable-write' };
|
|
782
838
|
}
|
|
783
839
|
pendings.set(built.batch.id, { drafts: saved, submission: { state: 'waiting' }, lost: false });
|
|
784
|
-
|
|
840
|
+
if (!localSaves)
|
|
841
|
+
recorded = false;
|
|
785
842
|
for (const path of consumed)
|
|
786
843
|
forgetRoomDraft(locator, path);
|
|
787
844
|
replicas.set(locator, replicaOf(replica.confirmed, batches, replica));
|
|
@@ -789,7 +846,7 @@ export function composeRuntime(options) {
|
|
|
789
846
|
queue: true,
|
|
790
847
|
drafts: consumed,
|
|
791
848
|
}));
|
|
792
|
-
moveTo({ ...saving(status), ...attention() });
|
|
849
|
+
moveTo({ ...(localSaves ? status : saving(status)), ...attention() });
|
|
793
850
|
submitLater(locator);
|
|
794
851
|
return { outcome: 'saved', identifier: built.batch.id };
|
|
795
852
|
}
|
|
@@ -934,14 +991,33 @@ export function composeRuntime(options) {
|
|
|
934
991
|
throw error;
|
|
935
992
|
}
|
|
936
993
|
}
|
|
937
|
-
|
|
994
|
+
function staging(local) {
|
|
995
|
+
return {
|
|
996
|
+
held: (locator) => transfers.get(locator) ?? null,
|
|
997
|
+
staged: (record) => local.staged(record),
|
|
998
|
+
stage: (record, page) => exclusive(async () => {
|
|
999
|
+
if (!continuing())
|
|
1000
|
+
return false;
|
|
1001
|
+
await local.stage(record, page);
|
|
1002
|
+
transfers.set(record.locator, record);
|
|
1003
|
+
return true;
|
|
1004
|
+
}),
|
|
1005
|
+
abandon: (locator) => exclusive(async () => {
|
|
1006
|
+
if (!continuing())
|
|
1007
|
+
return;
|
|
1008
|
+
await local.abandon(locator);
|
|
1009
|
+
transfers.delete(locator);
|
|
1010
|
+
}),
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
async function pullBootstrap(authorized, room, local) {
|
|
938
1014
|
if (!continuing())
|
|
939
1015
|
return unconfirmed;
|
|
940
1016
|
try {
|
|
941
1017
|
const result = await bootstrapRoom(options.adapter, authorized, room, {
|
|
942
1018
|
collection: modelOf(room.locator),
|
|
943
1019
|
selection: modelOf(room.locator, 'typed-selection'),
|
|
944
|
-
}, (models, held) => remodel(room.locator, models, held), continuing);
|
|
1020
|
+
}, (models, held) => remodel(room.locator, models, held), continuing, staging(local));
|
|
945
1021
|
const detail = result.kind === 'staged' ? result.confirmed.record.roomVersion : result.kind;
|
|
946
1022
|
journal.record(`transfer bootstrap ${room.locator} ${detail}`);
|
|
947
1023
|
return result;
|
|
@@ -969,7 +1045,7 @@ export function composeRuntime(options) {
|
|
|
969
1045
|
return null;
|
|
970
1046
|
}
|
|
971
1047
|
if (refreshed.kind === 'advanced') {
|
|
972
|
-
if (!(await publish(local, room, refreshed.confirmed, held.confirmed))) {
|
|
1048
|
+
if (!(await publish(local, room, refreshed.confirmed, { base: held.confirmed }))) {
|
|
973
1049
|
const now = replicas.get(room.locator)?.confirmed.record.roomVersion;
|
|
974
1050
|
const reached = now !== undefined &&
|
|
975
1051
|
options.adapter.reached(room.locator, now, refreshed.confirmed.record.roomVersion);
|
|
@@ -981,12 +1057,12 @@ export function composeRuntime(options) {
|
|
|
981
1057
|
if (refreshed.kind !== 'beyond-horizon')
|
|
982
1058
|
return refreshed;
|
|
983
1059
|
}
|
|
984
|
-
const bootstrapped = await pullBootstrap(authorized, room);
|
|
1060
|
+
const bootstrapped = await pullBootstrap(authorized, room, local);
|
|
985
1061
|
if (!continuing())
|
|
986
1062
|
return unconfirmed;
|
|
987
1063
|
if (bootstrapped.kind !== 'staged')
|
|
988
1064
|
return bootstrapped;
|
|
989
|
-
await publish(local, room, bootstrapped.confirmed);
|
|
1065
|
+
await publish(local, room, bootstrapped.confirmed, { stored: bootstrapped.stored });
|
|
990
1066
|
return null;
|
|
991
1067
|
}
|
|
992
1068
|
async function withhold(withheld, room, local, progress) {
|
|
@@ -1259,7 +1335,7 @@ export function composeRuntime(options) {
|
|
|
1259
1335
|
...(attached === 'collection' ? { model: next } : { selectionModel: next }),
|
|
1260
1336
|
};
|
|
1261
1337
|
const reclassified = sameMembership(declared, held.confirmed.record)
|
|
1262
|
-
?
|
|
1338
|
+
? { kind: 'staged', confirmed: confirmedOf(declared, held.confirmed) }
|
|
1263
1339
|
: readReclassified(declared, held.confirmed);
|
|
1264
1340
|
const record = reclassified.kind === 'staged'
|
|
1265
1341
|
? declared
|
|
@@ -1267,7 +1343,9 @@ export function composeRuntime(options) {
|
|
|
1267
1343
|
...declared,
|
|
1268
1344
|
typedSelection: held.confirmed.record.typedSelection,
|
|
1269
1345
|
};
|
|
1270
|
-
const read = reclassified.kind === 'deferred'
|
|
1346
|
+
const read = reclassified.kind === 'deferred'
|
|
1347
|
+
? { kind: 'staged', confirmed: confirmedOf(record, held.confirmed) }
|
|
1348
|
+
: reclassified;
|
|
1271
1349
|
await local.write({
|
|
1272
1350
|
next: record,
|
|
1273
1351
|
previous: held.confirmed.record,
|
|
@@ -1416,14 +1494,14 @@ export function composeRuntime(options) {
|
|
|
1416
1494
|
async function reload(room, local, progress) {
|
|
1417
1495
|
if (discoveryPaused || authorization === undefined)
|
|
1418
1496
|
return;
|
|
1419
|
-
const bootstrapped = await pullBootstrap(authorization, room);
|
|
1497
|
+
const bootstrapped = await pullBootstrap(authorization, room, local);
|
|
1420
1498
|
if (!continuing())
|
|
1421
1499
|
return;
|
|
1422
1500
|
if (bootstrapped.kind !== 'staged') {
|
|
1423
1501
|
await withhold(bootstrapped, room, local, progress);
|
|
1424
1502
|
return;
|
|
1425
1503
|
}
|
|
1426
|
-
await publish(local, room, bootstrapped.confirmed);
|
|
1504
|
+
await publish(local, room, bootstrapped.confirmed, { stored: bootstrapped.stored });
|
|
1427
1505
|
await caughtUp(room, local, progress);
|
|
1428
1506
|
}
|
|
1429
1507
|
async function discoverRooms(local, progress, attempt) {
|
|
@@ -1631,6 +1709,8 @@ export function composeRuntime(options) {
|
|
|
1631
1709
|
}
|
|
1632
1710
|
}
|
|
1633
1711
|
function submitLater(locator) {
|
|
1712
|
+
if (localSaves)
|
|
1713
|
+
return;
|
|
1634
1714
|
const running = submitting.get(locator);
|
|
1635
1715
|
if (running !== undefined) {
|
|
1636
1716
|
running.again = true;
|
|
@@ -1886,13 +1966,16 @@ export function composeRuntime(options) {
|
|
|
1886
1966
|
return planOf(input, roomFacts(reach), planReach(reach));
|
|
1887
1967
|
}
|
|
1888
1968
|
function watchPlan(plan, deliver) {
|
|
1969
|
+
materialize(reachedRooms(plan));
|
|
1889
1970
|
return readSide.watch(plan, identityOf(plan), deliver);
|
|
1890
1971
|
}
|
|
1891
1972
|
async function searched(input, reach) {
|
|
1892
1973
|
const plan = searchPlanOf(input);
|
|
1893
1974
|
const selected = plan.documents === undefined && reach === null
|
|
1894
1975
|
? null
|
|
1895
|
-
: (await
|
|
1976
|
+
: (await rowsQuery(filterOf(plan.documents ?? {}, roomFacts(reach), planReach(reach)))).documents;
|
|
1977
|
+
if (selected === null)
|
|
1978
|
+
materialize(null);
|
|
1896
1979
|
return searchIndex.search(reach === null || reach.conversations ? plan : { ...plan, conversations: [] }, selected);
|
|
1897
1980
|
}
|
|
1898
1981
|
const watch = (topic, input, deliver) => {
|
|
@@ -1996,7 +2079,7 @@ export function composeRuntime(options) {
|
|
|
1996
2079
|
rooms() {
|
|
1997
2080
|
return listed();
|
|
1998
2081
|
},
|
|
1999
|
-
query: ((input) =>
|
|
2082
|
+
query: ((input) => rowsQuery(planned(input, null))),
|
|
2000
2083
|
search: (input) => searched(input, null),
|
|
2001
2084
|
types(locator) {
|
|
2002
2085
|
return {
|
|
@@ -2123,7 +2206,7 @@ export function composeRuntime(options) {
|
|
|
2123
2206
|
md,
|
|
2124
2207
|
watch,
|
|
2125
2208
|
plan: planned,
|
|
2126
|
-
query: (plan) =>
|
|
2209
|
+
query: (plan) => rowsQuery(plan),
|
|
2127
2210
|
watchPlan,
|
|
2128
2211
|
search: searched,
|
|
2129
2212
|
};
|
package/dist/identity.d.ts
CHANGED
package/dist/identity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
package/dist/identity.js
CHANGED
|
@@ -10,8 +10,14 @@ export function changeBatchIdentity(at = Date.now()) {
|
|
|
10
10
|
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
11
11
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
function randomIdentity() {
|
|
14
14
|
const bytes = new Uint8Array(16);
|
|
15
15
|
crypto.getRandomValues(bytes);
|
|
16
16
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
17
17
|
}
|
|
18
|
+
export function roomDraftRevision() {
|
|
19
|
+
return randomIdentity();
|
|
20
|
+
}
|
|
21
|
+
export function transferIdentity() {
|
|
22
|
+
return randomIdentity();
|
|
23
|
+
}
|
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAItB,KAAK,cAAc,EACnB,KAAK,UAAU,EAGf,KAAK,kBAAkB,EACvB,KAAK,MAAM,EAGX,KAAK,aAAa,EAGlB,KAAK,SAAS,EACd,KAAK,cAA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,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI,CAAC;IAC7C,gBAAgB,CAAC,aAAa,EAAE,SAAS,kBAAkB,EAAE,GAAG,IAAI,CAAC;IACrE,MAAM,CAAC,SAAS,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACxD,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC1C,iBAAiB,CAAC,YAAY,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChF,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnD,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,SAAS,IAAI,SAAS,MAAM,EAAE,CAAC;IAC/B,uBAAuB,IAAI,SAAS,MAAM,EAAE,CAAC;CAC9C,CAAC;AA+CF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CA2brF"}
|
package/dist/memory.js
CHANGED
|
@@ -107,22 +107,24 @@ export function createMemoryAdapter(options = {}) {
|
|
|
107
107
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
function page(room,
|
|
110
|
+
function page(room, after) {
|
|
111
111
|
const paths = Object.keys(room.documents ?? {}).sort();
|
|
112
|
+
const opening = after === undefined;
|
|
113
|
+
const from = opening ? 0 : paths.filter((path) => path <= after).length;
|
|
112
114
|
const size = pageSize ?? paths.length;
|
|
113
115
|
const taken = paths.slice(from, from + size);
|
|
114
116
|
const next = from + taken.length;
|
|
115
|
-
const targets =
|
|
117
|
+
const targets = opening ? (room.binaryTargets ?? []) : [];
|
|
116
118
|
return {
|
|
117
119
|
kind: 'bootstrap',
|
|
118
120
|
roomVersion: room.roomVersion,
|
|
119
|
-
...(
|
|
121
|
+
...(opening ? { models: modelsOf(room) } : {}),
|
|
120
122
|
documents: named(room.documents ?? {}, taken),
|
|
121
123
|
revisions: named(room.revisions ?? {}, taken),
|
|
122
124
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
123
125
|
binaryTargets: targets,
|
|
124
|
-
...(
|
|
125
|
-
...(next < paths.length ? { pageToken:
|
|
126
|
+
...(opening && room.attachments !== undefined ? { attachments: room.attachments } : {}),
|
|
127
|
+
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
function advancement(room, from, at) {
|
|
@@ -386,7 +388,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
386
388
|
if (room === undefined) {
|
|
387
389
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
388
390
|
}
|
|
389
|
-
return page(room, request.pageToken
|
|
391
|
+
return page(room, request.pageToken);
|
|
390
392
|
}, request).then((answer) => note(request.locator, answer));
|
|
391
393
|
},
|
|
392
394
|
async refresh(_authorization, request) {
|
package/dist/outcome.d.ts
CHANGED
package/dist/outcome.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG,CACvD,UAAU,GACV;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAC/D,CAAC"}
|
|
1
|
+
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG,CACvD,UAAU,GACV;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAC/D,CAAC"}
|
package/dist/overlay.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type Layer = Heads & {
|
|
|
9
9
|
binaryTargets: readonly string[];
|
|
10
10
|
};
|
|
11
11
|
export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
|
|
12
|
-
export declare function overlay(base: Layer, queue: readonly ChangeBatch[]): Layer;
|
|
12
|
+
export declare function overlay(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Layer;
|
|
13
13
|
export declare function sameLayerText(left: Layer, right: Layer): boolean;
|
|
14
14
|
export declare function overlayChanged(base: Layer, queue: readonly ChangeBatch[], previousBase: Layer, previousQueue: readonly ChangeBatch[], previousVisible: Layer): Layer;
|
|
15
15
|
//# sourceMappingURL=overlay.d.ts.map
|
package/dist/overlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAU,WAAW,EAAgB,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG;IAC1B,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAQ/F;
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAU,WAAW,EAAgB,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG;IAC1B,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAQ/F;AAsJD,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,KAAK,CAmBjG;AAQD,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAQhE;AAmBD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,YAAY,EAAE,KAAK,EACnB,aAAa,EAAE,SAAS,WAAW,EAAE,EACrC,eAAe,EAAE,KAAK,GACrB,KAAK,CA4FP"}
|
package/dist/overlay.js
CHANGED
|
@@ -76,13 +76,15 @@ function edited(document, change, priors) {
|
|
|
76
76
|
function edit(staged, change, priors) {
|
|
77
77
|
const text = staged.documents[change.path];
|
|
78
78
|
if (text === undefined)
|
|
79
|
-
return;
|
|
79
|
+
return false;
|
|
80
80
|
const parsed = parse(text, change.path);
|
|
81
81
|
if (!parsed.ok)
|
|
82
|
-
return;
|
|
82
|
+
return false;
|
|
83
83
|
const next = edited(parsed.document, change, priors);
|
|
84
|
-
if (next?.outcome
|
|
85
|
-
|
|
84
|
+
if (next?.outcome !== 'applied')
|
|
85
|
+
return false;
|
|
86
|
+
staged.documents[change.path] = serialize(next.document);
|
|
87
|
+
return true;
|
|
86
88
|
}
|
|
87
89
|
function relocate(staged, from, to) {
|
|
88
90
|
const text = staged.documents[from];
|
|
@@ -94,9 +96,10 @@ function relocate(staged, from, to) {
|
|
|
94
96
|
staged.binaryTargets.add(to);
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
|
-
return;
|
|
99
|
+
return false;
|
|
98
100
|
}
|
|
99
101
|
moveHead(staged, from, to);
|
|
102
|
+
return true;
|
|
100
103
|
}
|
|
101
104
|
function moveHead(heads, from, to) {
|
|
102
105
|
const revision = heads.revisions[from];
|
|
@@ -117,28 +120,27 @@ function erase(staged, path) {
|
|
|
117
120
|
}
|
|
118
121
|
function stage(staged, change, priors) {
|
|
119
122
|
if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
|
|
120
|
-
edit(staged, change, priors);
|
|
121
|
-
return;
|
|
123
|
+
return edit(staged, change, priors);
|
|
122
124
|
}
|
|
123
125
|
if (change.kind === 'create') {
|
|
124
126
|
staged.documents[change.path] =
|
|
125
127
|
'content' in change ? change.content : compose(change.fields, change.sections);
|
|
126
128
|
delete staged.changes[change.path];
|
|
127
|
-
return;
|
|
129
|
+
return true;
|
|
128
130
|
}
|
|
129
131
|
if (change.kind === 'replace') {
|
|
130
132
|
if (staged.documents[change.path] === undefined)
|
|
131
|
-
return;
|
|
133
|
+
return false;
|
|
132
134
|
staged.documents[change.path] = change.content;
|
|
133
|
-
return;
|
|
135
|
+
return true;
|
|
134
136
|
}
|
|
135
137
|
if (change.kind === 'move') {
|
|
136
|
-
relocate(staged, change.path, change.to);
|
|
137
|
-
return;
|
|
138
|
+
return relocate(staged, change.path, change.to);
|
|
138
139
|
}
|
|
139
140
|
erase(staged, change.path);
|
|
141
|
+
return true;
|
|
140
142
|
}
|
|
141
|
-
export function overlay(base, queue) {
|
|
143
|
+
export function overlay(base, queue, unapplied) {
|
|
142
144
|
const staged = {
|
|
143
145
|
documents: { ...base.documents },
|
|
144
146
|
binaryTargets: new Set(base.binaryTargets),
|
|
@@ -147,8 +149,10 @@ export function overlay(base, queue) {
|
|
|
147
149
|
};
|
|
148
150
|
for (const batch of queue) {
|
|
149
151
|
const priors = priorsOf(batch.preconditions);
|
|
150
|
-
for (const change of batch.changes)
|
|
151
|
-
stage(staged, change, priors)
|
|
152
|
+
for (const change of batch.changes) {
|
|
153
|
+
if (!stage(staged, change, priors))
|
|
154
|
+
unapplied?.();
|
|
155
|
+
}
|
|
152
156
|
}
|
|
153
157
|
return {
|
|
154
158
|
documents: staged.documents,
|
package/dist/refresh.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { Adapter, AdapterFailure, Authorization, RetryableRefusal } from './adapter.js';
|
|
2
2
|
import type { Remodel } from './bootstrap.js';
|
|
3
3
|
import { type ConfirmedLayer } from './replica.js';
|
|
4
|
+
import type { ReplicaRecord } from './store.js';
|
|
4
5
|
import { type Refused, type Unconfirmed } from './transfer.js';
|
|
6
|
+
export type Advancement = {
|
|
7
|
+
kind: 'still-current';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'advanced';
|
|
10
|
+
record: ReplicaRecord;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'beyond-horizon';
|
|
13
|
+
} | RetryableRefusal | Unconfirmed | AdapterFailure;
|
|
5
14
|
export type RefreshOutcome = {
|
|
6
15
|
kind: 'still-current';
|
|
7
16
|
} | {
|
|
@@ -10,5 +19,6 @@ export type RefreshOutcome = {
|
|
|
10
19
|
} | {
|
|
11
20
|
kind: 'beyond-horizon';
|
|
12
21
|
} | RetryableRefusal | Unconfirmed | Refused | AdapterFailure;
|
|
22
|
+
export declare function advancement(adapter: Adapter, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean): Promise<Advancement>;
|
|
13
23
|
export declare function refreshRoom(adapter: Adapter, authorization: Authorization, confirmed: ConfirmedLayer, remodel: Remodel, continuing: () => boolean): Promise<RefreshOutcome>;
|
|
14
24
|
//# sourceMappingURL=refresh.d.ts.map
|
package/dist/refresh.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,aAAa,EAGb,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B,gBAAgB,GAChB,WAAW,GACX,OAAO,GACP,cAAc,CAAC;AAEnB,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,OAAO,GACxB,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,aAAa,EAGb,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAe,KAAK,OAA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