@agentshouse/mdruntime 0.1.0-cfbf80d8d4644 → 0.1.0-cfcbb238a5fa0
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 +270 -203
- package/README.md +20 -10
- package/dist/acquisition.d.ts +14 -0
- package/dist/acquisition.d.ts.map +1 -0
- package/dist/acquisition.js +24 -0
- package/dist/adapter.d.ts +83 -20
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +18 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +113 -37
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +49 -16
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +33 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +61 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +27 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +63 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +22 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +155 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +629 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +34 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +25 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +75 -16
- package/dist/collection.d.ts +21 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +271 -23
- package/dist/connection.d.ts +44 -15
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1788 -400
- package/dist/conversation.d.ts +26 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +414 -148
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +156 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +18 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +97 -19
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +19 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/memory.d.ts +11 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +87 -25
- package/dist/model.d.ts +14 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +12 -1
- package/dist/observation.d.ts +5 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +22 -11
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +32 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -1
- package/dist/overlay.d.ts +16 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +118 -77
- package/dist/query.d.ts +40 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +60 -21
- package/dist/reach.d.ts +8 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +60 -24
- package/dist/react.d.ts +31 -18
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +15 -11
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +394 -129
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +13 -3
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +49 -38
- package/dist/replica.d.ts +9 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +125 -68
- package/dist/room-draft.d.ts +38 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +134 -25
- package/dist/rows.d.ts +11 -14
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +89 -49
- package/dist/save.d.ts +31 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +376 -47
- package/dist/search.d.ts +39 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +132 -46
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +61 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +6 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +75 -18
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +539 -200
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +141 -33
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +61 -31
- package/package.json +26 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/replica.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import { immutable } from './change.js';
|
|
3
|
-
import {
|
|
4
|
-
import { overlay, overlayChanged, sameLayerText } from './overlay.js';
|
|
1
|
+
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { immutable, landing } from './change.js';
|
|
3
|
+
import { changedCleanly, collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
|
+
import { acceptedBinaries, overlay, overlayChanged, sameLayerText, } from './overlay.js';
|
|
5
5
|
import { providerRewritten } from './save.js';
|
|
6
|
-
import {
|
|
7
|
-
import { declaredAttachments } from './attachment.js';
|
|
6
|
+
import { drafted, patched, settled, shared } from './shared.js';
|
|
8
7
|
export function compositionOf(record) {
|
|
9
8
|
return {
|
|
10
9
|
model: record.model,
|
|
@@ -13,70 +12,124 @@ export function compositionOf(record) {
|
|
|
13
12
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
function held(record) {
|
|
16
|
+
const documents = shared(record.documents);
|
|
17
|
+
const binaries = shared(record.binaries);
|
|
18
|
+
const revisions = shared(record.revisions);
|
|
19
|
+
const fileIds = shared(record.fileIds);
|
|
20
|
+
const changes = shared(record.changes);
|
|
21
|
+
const written = shared(record.written);
|
|
22
|
+
return documents === record.documents &&
|
|
23
|
+
binaries === record.binaries &&
|
|
24
|
+
revisions === record.revisions &&
|
|
25
|
+
fileIds === record.fileIds &&
|
|
26
|
+
changes === record.changes &&
|
|
27
|
+
written === record.written
|
|
28
|
+
? record
|
|
29
|
+
: { ...record, documents, binaries, revisions, fileIds, changes, written };
|
|
30
|
+
}
|
|
31
|
+
export function confirmedOf(record, previous) {
|
|
32
|
+
const kept = held(record);
|
|
33
|
+
return {
|
|
34
|
+
record: kept,
|
|
35
|
+
collection: collectionOf(kept.documents, compositionOf(kept), previous?.collection),
|
|
36
|
+
};
|
|
23
37
|
}
|
|
24
38
|
export function sameMembership(record, other) {
|
|
25
39
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
26
40
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
27
41
|
}
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
function cleanly(record, previous) {
|
|
43
|
+
if (previous === undefined)
|
|
44
|
+
return false;
|
|
45
|
+
const before = previous.record;
|
|
46
|
+
return changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
47
|
+
}
|
|
48
|
+
export function readStaged(staged, previous) {
|
|
49
|
+
const record = held(staged);
|
|
50
|
+
const textChanged = previous === undefined || !sameLayerText(record, previous.record);
|
|
51
|
+
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
52
|
+
if (modeled &&
|
|
53
|
+
(textChanged ||
|
|
54
|
+
record.model !== previous?.record.model ||
|
|
55
|
+
record.selectionModel !== previous?.record.selectionModel) &&
|
|
56
|
+
!cleanly(record, previous)) {
|
|
57
|
+
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
35
58
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
36
59
|
return { kind: 'refused', refusal: verdict };
|
|
37
60
|
}
|
|
61
|
+
if (verdict.verdict === 'refuse') {
|
|
62
|
+
const refused = unreadable(record.documents, previous?.record.documents);
|
|
63
|
+
if (refused !== null)
|
|
64
|
+
return refused;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (textChanged) {
|
|
68
|
+
const refused = unreadable(record.documents, previous?.record.documents);
|
|
69
|
+
if (refused !== null)
|
|
70
|
+
return refused;
|
|
38
71
|
}
|
|
39
|
-
return
|
|
72
|
+
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
40
73
|
}
|
|
41
74
|
export function readReclassified(record, previous) {
|
|
42
|
-
const verdict = validateCollection(record.documents, record.
|
|
75
|
+
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
43
76
|
if (verdict.verdict !== 'refuse')
|
|
44
|
-
return
|
|
77
|
+
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
45
78
|
return verdict.rule === 'model-unavailable'
|
|
46
79
|
? { kind: 'deferred' }
|
|
47
80
|
: { kind: 'refused', refusal: verdict };
|
|
48
81
|
}
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
82
|
+
function returnedBinaries(held, submitted, accepted) {
|
|
83
|
+
const binaries = drafted(held);
|
|
84
|
+
for (const change of submitted.changes) {
|
|
85
|
+
if (change.kind !== 'move')
|
|
86
|
+
continue;
|
|
87
|
+
const moved = binaries[change.path];
|
|
88
|
+
if (moved === undefined || accepted.revisions[change.to] === undefined)
|
|
89
|
+
continue;
|
|
90
|
+
binaries[change.to] = moved;
|
|
91
|
+
delete binaries[change.path];
|
|
92
|
+
}
|
|
93
|
+
Object.assign(binaries, acceptedBinaries(accepted.binaryFiles ?? {}));
|
|
94
|
+
for (const path of accepted.removals)
|
|
95
|
+
delete binaries[path];
|
|
96
|
+
return settled(binaries);
|
|
97
|
+
}
|
|
98
|
+
export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
|
|
99
|
+
const { documents, revisions, fileIds, changes, removals } = accepted;
|
|
100
|
+
const nextDocuments = drafted(confirmed.record.documents);
|
|
101
|
+
const nextRevisions = drafted(confirmed.record.revisions);
|
|
102
|
+
const nextFileIds = drafted(confirmed.record.fileIds);
|
|
103
|
+
const nextChanges = drafted(confirmed.record.changes);
|
|
104
|
+
const nextWritten = drafted(confirmed.record.written);
|
|
105
|
+
Object.assign(nextDocuments, documents);
|
|
106
|
+
Object.assign(nextRevisions, revisions);
|
|
107
|
+
for (const path of Object.keys({ ...documents, ...revisions }))
|
|
108
|
+
delete nextFileIds[path];
|
|
109
|
+
Object.assign(nextFileIds, fileIds);
|
|
110
|
+
for (const path of Object.keys(documents))
|
|
111
|
+
nextWritten[path] = writtenAt;
|
|
58
112
|
for (const [path, revision] of Object.entries(revisions)) {
|
|
59
113
|
if (confirmed.record.revisions[path] !== revision)
|
|
60
114
|
delete nextChanges[path];
|
|
61
115
|
}
|
|
116
|
+
Object.assign(nextChanges, changes);
|
|
62
117
|
for (const path of removals) {
|
|
63
118
|
delete nextDocuments[path];
|
|
64
119
|
delete nextRevisions[path];
|
|
120
|
+
delete nextFileIds[path];
|
|
65
121
|
delete nextChanges[path];
|
|
66
122
|
delete nextWritten[path];
|
|
67
|
-
binaryTargets.delete(path);
|
|
68
123
|
}
|
|
69
124
|
return readStaged({
|
|
70
125
|
...confirmed.record,
|
|
71
126
|
roomVersion,
|
|
72
|
-
documents: nextDocuments,
|
|
73
|
-
revisions: nextRevisions,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
? confirmed.record.attachments
|
|
79
|
-
: declaredAttachments([attachments]),
|
|
127
|
+
documents: settled(nextDocuments),
|
|
128
|
+
revisions: settled(nextRevisions),
|
|
129
|
+
fileIds: settled(nextFileIds),
|
|
130
|
+
changes: settled(nextChanges),
|
|
131
|
+
written: settled(nextWritten),
|
|
132
|
+
binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
|
|
80
133
|
}, confirmed);
|
|
81
134
|
}
|
|
82
135
|
function predicted(confirmed, batches, previous) {
|
|
@@ -97,9 +150,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
97
150
|
const collection = hasMove
|
|
98
151
|
? reuseRewrite
|
|
99
152
|
? old.collection
|
|
100
|
-
:
|
|
101
|
-
? { text: confirmed.record.documents, collection: confirmed.collection }
|
|
102
|
-
: { text: old.before.documents, collection: old.collection })
|
|
153
|
+
: collectionOf(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
103
154
|
: undefined;
|
|
104
155
|
const effective = collection === undefined
|
|
105
156
|
? batch
|
|
@@ -128,8 +179,9 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
128
179
|
queue: batches,
|
|
129
180
|
visible: {
|
|
130
181
|
documents: confirmed.record.documents,
|
|
131
|
-
|
|
182
|
+
binaries: confirmed.record.binaries,
|
|
132
183
|
revisions: confirmed.record.revisions,
|
|
184
|
+
fileIds: confirmed.record.fileIds,
|
|
133
185
|
changes: confirmed.record.changes,
|
|
134
186
|
collection: confirmed.collection,
|
|
135
187
|
},
|
|
@@ -143,14 +195,12 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
143
195
|
replay,
|
|
144
196
|
visible: {
|
|
145
197
|
...layer,
|
|
146
|
-
collection:
|
|
147
|
-
? undefined
|
|
148
|
-
: { text: previous.visible.documents, collection: previous.visible.collection }),
|
|
198
|
+
collection: collectionOf(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
149
199
|
},
|
|
150
200
|
};
|
|
151
201
|
}
|
|
152
202
|
function present(layer, path) {
|
|
153
|
-
return layer.documents[path] !== undefined || layer.
|
|
203
|
+
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
154
204
|
}
|
|
155
205
|
function holds(layer, preconditions) {
|
|
156
206
|
const parsed = new Map();
|
|
@@ -171,6 +221,8 @@ function holds(layer, preconditions) {
|
|
|
171
221
|
if (precondition.kind === 'revision') {
|
|
172
222
|
return present(layer, path) && layer.revisions[path] === precondition.revision;
|
|
173
223
|
}
|
|
224
|
+
if (precondition.kind === 'content')
|
|
225
|
+
return layer.documents[path] === precondition.content;
|
|
174
226
|
const document = documentAt(path);
|
|
175
227
|
if (document === null)
|
|
176
228
|
return false;
|
|
@@ -215,36 +267,33 @@ function effects(change) {
|
|
|
215
267
|
{ kind: 'present', path: change.to },
|
|
216
268
|
];
|
|
217
269
|
}
|
|
270
|
+
if (change.kind === 'binary')
|
|
271
|
+
return [{ kind: 'present', path }];
|
|
218
272
|
return [{ kind: 'absent', path }];
|
|
219
273
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (change.kind === 'remove')
|
|
226
|
-
return null;
|
|
227
|
-
if (change.kind === 'move')
|
|
228
|
-
at = change.to;
|
|
229
|
-
}
|
|
230
|
-
return at;
|
|
231
|
-
}
|
|
232
|
-
export function landed(batch, confirmed) {
|
|
233
|
-
const layer = confirmed.record;
|
|
274
|
+
export function landed(batch, confirmed, current = {}) {
|
|
275
|
+
const layer = {
|
|
276
|
+
...confirmed.record,
|
|
277
|
+
documents: patched(confirmed.record.documents, Object.entries(current)),
|
|
278
|
+
};
|
|
234
279
|
return batch.changes.every((change, index) => {
|
|
235
280
|
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
236
|
-
const at =
|
|
281
|
+
const at = landing(batch.changes, index, change.path);
|
|
237
282
|
return at === null || layer.documents[at] === change.content;
|
|
238
283
|
}
|
|
284
|
+
if (change.kind === 'binary') {
|
|
285
|
+
const at = landing(batch.changes, index, change.path);
|
|
286
|
+
return at === null || layer.binaries[at]?.sha256 === change.sha256;
|
|
287
|
+
}
|
|
239
288
|
return effects(change).every((effect) => {
|
|
240
289
|
if (effect.kind === 'absent')
|
|
241
290
|
return holds(layer, [effect]);
|
|
242
|
-
const at =
|
|
291
|
+
const at = landing(batch.changes, index, effect.path);
|
|
243
292
|
return at === null || holds(layer, [{ ...effect, path: at }]);
|
|
244
293
|
});
|
|
245
294
|
});
|
|
246
295
|
}
|
|
247
|
-
export function withdrawals(confirmed, queue, withdrawable) {
|
|
296
|
+
export function withdrawals(confirmed, queue, withdrawable, local) {
|
|
248
297
|
if (!queue.some(withdrawable))
|
|
249
298
|
return [];
|
|
250
299
|
const composition = compositionOf(confirmed.record);
|
|
@@ -258,10 +307,18 @@ export function withdrawals(confirmed, queue, withdrawable) {
|
|
|
258
307
|
const effective = batch.changes.some((change) => change.kind === 'move')
|
|
259
308
|
? providerRewritten(batch, {
|
|
260
309
|
...layer,
|
|
261
|
-
collection:
|
|
310
|
+
collection: collectionOf(layer.documents, composition),
|
|
262
311
|
})
|
|
263
312
|
: batch;
|
|
264
|
-
|
|
313
|
+
let unapplied = false;
|
|
314
|
+
const next = overlay(layer, [effective], () => {
|
|
315
|
+
unapplied = true;
|
|
316
|
+
});
|
|
317
|
+
if (local && unapplied) {
|
|
318
|
+
withdrawn.push(batch);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
layer = next;
|
|
265
322
|
}
|
|
266
323
|
return withdrawn;
|
|
267
324
|
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderRefusal } from './adapter.js';
|
|
2
|
+
import type { Open } from './open.js';
|
|
2
3
|
import type { Change, Precondition } from './change.js';
|
|
3
4
|
import type { VisibleLayer } from './replica.js';
|
|
4
5
|
export type FieldValue = {
|
|
@@ -36,6 +37,17 @@ export type RoomDraftParts = {
|
|
|
36
37
|
readonly removal?: {
|
|
37
38
|
readonly base?: string | null;
|
|
38
39
|
};
|
|
40
|
+
readonly file?: {
|
|
41
|
+
readonly blob: Blob;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type HeldFile = {
|
|
45
|
+
readonly blob: Blob;
|
|
46
|
+
readonly localId: string;
|
|
47
|
+
readonly byteLength: number;
|
|
48
|
+
readonly mediaType: string;
|
|
49
|
+
readonly sha256: string;
|
|
50
|
+
readonly base: string | null;
|
|
39
51
|
};
|
|
40
52
|
type HeldParts = {
|
|
41
53
|
readonly fields?: Readonly<Record<string, {
|
|
@@ -62,6 +74,7 @@ type HeldParts = {
|
|
|
62
74
|
readonly removal?: {
|
|
63
75
|
readonly base: string | null;
|
|
64
76
|
};
|
|
77
|
+
readonly file?: HeldFile;
|
|
65
78
|
};
|
|
66
79
|
type ChangedUnderneath = {
|
|
67
80
|
readonly fields?: Readonly<Record<string, FieldValue>>;
|
|
@@ -71,14 +84,12 @@ type ChangedUnderneath = {
|
|
|
71
84
|
readonly creation?: string;
|
|
72
85
|
readonly move?: string | null;
|
|
73
86
|
readonly removal?: string | null;
|
|
87
|
+
readonly file?: string | null;
|
|
74
88
|
};
|
|
75
|
-
export type ReturnReason =
|
|
76
|
-
readonly kind: 'conflicted' | 'rejected'
|
|
77
|
-
}) | {
|
|
78
|
-
readonly kind: 'expired';
|
|
79
|
-
} | {
|
|
80
|
-
readonly kind: 'withdrawn';
|
|
89
|
+
export type ReturnReason = ProviderRefusal & {
|
|
90
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
|
|
81
91
|
};
|
|
92
|
+
export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
|
|
82
93
|
export type RoomDraft = {
|
|
83
94
|
readonly room: string;
|
|
84
95
|
readonly path: string;
|
|
@@ -92,11 +103,14 @@ export type RoomDraftWrite = {
|
|
|
92
103
|
readonly roomDraft: RoomDraft | null;
|
|
93
104
|
} | {
|
|
94
105
|
readonly outcome: 'stale';
|
|
106
|
+
readonly code: string;
|
|
107
|
+
readonly retryable: boolean;
|
|
95
108
|
readonly current: RoomDraft | null;
|
|
96
109
|
};
|
|
110
|
+
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
97
111
|
export type ChangedPart = {
|
|
98
112
|
readonly path: string;
|
|
99
|
-
readonly part: 'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal'
|
|
113
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal' | 'file'>;
|
|
100
114
|
readonly name?: string;
|
|
101
115
|
};
|
|
102
116
|
export type RoomDraftRecord = {
|
|
@@ -111,10 +125,23 @@ export type SavedDraft = {
|
|
|
111
125
|
readonly parts: HeldParts;
|
|
112
126
|
};
|
|
113
127
|
export declare function readParts(value: unknown): RoomDraftParts;
|
|
114
|
-
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts): HeldParts;
|
|
115
|
-
export declare function equalValue(left: unknown, right: unknown): boolean;
|
|
128
|
+
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
116
129
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
130
|
+
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
131
|
+
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
117
132
|
export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
|
|
133
|
+
export type TextParts = {
|
|
134
|
+
readonly fields?: Readonly<Record<string, {
|
|
135
|
+
readonly value: unknown;
|
|
136
|
+
}>>;
|
|
137
|
+
readonly sections?: Readonly<Record<string, {
|
|
138
|
+
readonly value: string;
|
|
139
|
+
}>>;
|
|
140
|
+
readonly preamble?: {
|
|
141
|
+
readonly value: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export declare function partsAfter(markdown: string, parts: TextParts): string;
|
|
118
145
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
119
146
|
export declare function moveTarget(move: {
|
|
120
147
|
readonly to: string;
|
|
@@ -123,5 +150,7 @@ export declare function changesOf(path: string, parts: HeldParts): {
|
|
|
123
150
|
changes: readonly Change[];
|
|
124
151
|
bases: readonly Precondition[];
|
|
125
152
|
};
|
|
153
|
+
export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
|
|
154
|
+
export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
|
|
126
155
|
export {};
|
|
127
156
|
//# sourceMappingURL=room-draft.d.ts.map
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-draft.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