@agentshouse/mdruntime 0.1.0-cf6041a06849c → 0.1.0-cf6d5f0a5c9c8
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 +45 -23
- package/README.md +9 -9
- package/dist/adapter.d.ts +8 -0
- 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/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +89 -35
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +13 -7
- package/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +35 -0
- 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 +5 -2
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +165 -51
- package/dist/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +1 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/memory.d.ts +2 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +16 -6
- package/dist/model.d.ts +7 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -0
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +49 -19
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +1 -16
- package/dist/react.d.ts +22 -14
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +102 -46
- 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 +4 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +31 -25
- package/dist/room-draft.js +1 -1
- package/dist/rows.d.ts +4 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +84 -38
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +106 -53
- package/dist/store.d.ts +25 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +206 -90
- package/dist/wire.d.ts +1 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +1 -0
- package/package.json +2 -2
package/dist/rows.js
CHANGED
|
@@ -1,30 +1,80 @@
|
|
|
1
|
-
import { target } from '@agentshouse/mdmodel';
|
|
1
|
+
import { ARRAY_INDEX, escapePointer, references, target, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { governing } from './collection.js';
|
|
3
|
-
import { definitionOf
|
|
3
|
+
import { definitionOf } from './model.js';
|
|
4
4
|
function keyOf(...parts) {
|
|
5
5
|
return `${parts.join('\u0000')}\u0000`;
|
|
6
6
|
}
|
|
7
7
|
export function documentKey(room, path) {
|
|
8
8
|
return keyOf('d', room, path);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
export function roomOfKey(key) {
|
|
11
|
+
return key.split('\u0000')[1];
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
function plainObject(value) {
|
|
14
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function compared(reading, exact, value) {
|
|
17
|
+
if (!reading.references.has(exact))
|
|
18
|
+
return value;
|
|
19
|
+
return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
|
|
20
|
+
}
|
|
21
|
+
function record(reading, node, forms, exact) {
|
|
22
|
+
const value = Array.isArray(node)
|
|
23
|
+
? node.map((item, index) => compared(reading, `${exact}/${index}`, item))
|
|
24
|
+
: compared(reading, exact, node);
|
|
25
|
+
for (const form of forms) {
|
|
26
|
+
if (form.pending)
|
|
27
|
+
continue;
|
|
28
|
+
(reading.reached[form.text] ??= []).push(value);
|
|
29
|
+
if (!form.through && value !== undefined && !plainObject(value)) {
|
|
30
|
+
reading.values[form.text] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(node) || plainObject(node) || !reading.references.has(exact))
|
|
34
|
+
return;
|
|
35
|
+
const found = compared(reading, exact, node);
|
|
36
|
+
if (typeof found !== 'string')
|
|
37
|
+
return;
|
|
38
|
+
const field = forms
|
|
39
|
+
.map((form) => form.text)
|
|
40
|
+
.reduce((left, right) => (right.length < left.length ? right : left));
|
|
41
|
+
const known = reading.targets.get(`${field}\u0000${found}`);
|
|
42
|
+
const kept = known ?? { field, target: found, forms: new Set() };
|
|
43
|
+
for (const form of forms)
|
|
44
|
+
kept.forms.add(form.text);
|
|
45
|
+
reading.targets.set(`${field}\u0000${found}`, kept);
|
|
46
|
+
}
|
|
47
|
+
function walk(reading, node, forms, exact) {
|
|
48
|
+
record(reading, node, forms, exact);
|
|
49
|
+
if (Array.isArray(node)) {
|
|
50
|
+
node.forEach((item, index) => walk(reading, item, forms.flatMap((form) => [
|
|
51
|
+
...(form.pending
|
|
52
|
+
? []
|
|
53
|
+
: [{ text: `${form.text}/${index}`, through: form.through, pending: false }]),
|
|
54
|
+
{ text: form.text, through: true, pending: true },
|
|
55
|
+
]), `${exact}/${index}`));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!plainObject(node))
|
|
59
|
+
return;
|
|
60
|
+
for (const [key, value] of Object.entries(node)) {
|
|
61
|
+
const segment = escapePointer(key);
|
|
62
|
+
walk(reading, value, forms.flatMap((form) => form.pending && ARRAY_INDEX.test(key)
|
|
63
|
+
? []
|
|
64
|
+
: [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
|
|
65
|
+
}
|
|
19
66
|
}
|
|
20
67
|
function directoriesOf(path) {
|
|
21
68
|
const parts = path.split('/').slice(0, -1);
|
|
22
69
|
return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
|
|
23
70
|
}
|
|
71
|
+
export function markdownPath(path) {
|
|
72
|
+
return path.endsWith('.md');
|
|
73
|
+
}
|
|
24
74
|
export function rowsOf(room, path, document, composition, change) {
|
|
25
75
|
const key = documentKey(room, path);
|
|
26
76
|
const body = keyOf('b', room, path);
|
|
27
|
-
if (document === null || !path
|
|
77
|
+
if (document === null || !markdownPath(path)) {
|
|
28
78
|
return [
|
|
29
79
|
{
|
|
30
80
|
key,
|
|
@@ -34,7 +84,7 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
34
84
|
type: null,
|
|
35
85
|
fields: {},
|
|
36
86
|
values: {},
|
|
37
|
-
|
|
87
|
+
reached: {},
|
|
38
88
|
directories: directoriesOf(path),
|
|
39
89
|
body,
|
|
40
90
|
change,
|
|
@@ -43,32 +93,18 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
43
93
|
}
|
|
44
94
|
const type = document.type ?? 'any';
|
|
45
95
|
const definition = definitionOf(governing(composition, path), document.type);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
96
|
+
const reading = {
|
|
97
|
+
path,
|
|
98
|
+
references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
|
|
99
|
+
values: {},
|
|
100
|
+
reached: {},
|
|
101
|
+
targets: new Map(),
|
|
102
|
+
};
|
|
49
103
|
for (const [name, value] of Object.entries(document.fields)) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (compared !== undefined)
|
|
53
|
-
values[name] = compared;
|
|
54
|
-
if (Array.isArray(value))
|
|
55
|
-
sizes[name] = value.length;
|
|
56
|
-
if (!reference)
|
|
57
|
-
continue;
|
|
58
|
-
const targets = [compared].flat().filter((found) => typeof found === 'string');
|
|
59
|
-
for (const found of new Set(targets)) {
|
|
60
|
-
references.push({
|
|
61
|
-
key: keyOf('r', room, path, name, found),
|
|
62
|
-
kind: 'reference',
|
|
63
|
-
room,
|
|
64
|
-
source: key,
|
|
65
|
-
target: documentKey(room, found),
|
|
66
|
-
field: name,
|
|
67
|
-
path,
|
|
68
|
-
type,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
104
|
+
const segment = escapePointer(name);
|
|
105
|
+
walk(reading, value, [{ text: `/${segment}`, through: false, pending: false }], `/${segment}`);
|
|
71
106
|
}
|
|
107
|
+
const { values, reached } = reading;
|
|
72
108
|
return [
|
|
73
109
|
{
|
|
74
110
|
key,
|
|
@@ -78,7 +114,7 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
78
114
|
type,
|
|
79
115
|
fields: document.fields,
|
|
80
116
|
values,
|
|
81
|
-
|
|
117
|
+
reached,
|
|
82
118
|
directories: directoriesOf(path),
|
|
83
119
|
body,
|
|
84
120
|
change,
|
|
@@ -92,6 +128,16 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
92
128
|
sections: document.sections,
|
|
93
129
|
markdown: document.content,
|
|
94
130
|
},
|
|
95
|
-
...
|
|
131
|
+
...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
|
|
132
|
+
key: keyOf('r', room, path, field, found),
|
|
133
|
+
kind: 'reference',
|
|
134
|
+
room,
|
|
135
|
+
source: key,
|
|
136
|
+
target: documentKey(room, found),
|
|
137
|
+
field,
|
|
138
|
+
forms: [...forms].sort(),
|
|
139
|
+
path,
|
|
140
|
+
type,
|
|
141
|
+
})),
|
|
96
142
|
];
|
|
97
143
|
}
|
package/dist/save.d.ts
CHANGED
package/dist/save.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AAg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,GAAG,WAAW,CAOxF;AAkRD,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAiFxD"}
|
package/dist/save.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { definitionOf
|
|
2
|
-
import { apply, links, parse, retarget, serialize, target, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { definitionOf } from './model.js';
|
|
2
|
+
import { apply, ATTACHMENT, links, parse, pointerSegments, references, relative, relativize, retarget, serialize, target, } from '@agentshouse/mdmodel';
|
|
3
3
|
import { immutable, } from './change.js';
|
|
4
|
-
import {
|
|
4
|
+
import { collectionOf, documentsOf, governing, validateCollection, } from './collection.js';
|
|
5
5
|
import { changeBatchIdentity } from './identity.js';
|
|
6
6
|
import { overlay } from './overlay.js';
|
|
7
|
-
import { covered, normalize
|
|
7
|
+
import { covered, normalize } from './paths.js';
|
|
8
8
|
function refuse(rule, file, location) {
|
|
9
9
|
return {
|
|
10
10
|
kind: 'refused',
|
|
@@ -15,18 +15,34 @@ function refuse(rule, file, location) {
|
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
function repointed(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
18
|
+
function repointed(document, definition, from, to, moves, settled) {
|
|
19
|
+
const parsed = parse(document.content, from);
|
|
20
|
+
if (!parsed.ok)
|
|
21
|
+
return [];
|
|
22
|
+
let next = parsed.document;
|
|
23
|
+
const names = new Set();
|
|
24
|
+
for (const { pointer, value } of definition === undefined
|
|
25
|
+
? []
|
|
26
|
+
: references(document, definition)) {
|
|
27
|
+
const [name = ''] = pointerSegments(pointer);
|
|
28
|
+
const named = target(from, value);
|
|
29
|
+
if (named === null || settled.has(`${from} ${name}`))
|
|
30
|
+
continue;
|
|
31
|
+
const destination = moves.get(named) ?? named;
|
|
32
|
+
if (target(to, value) === destination)
|
|
33
|
+
continue;
|
|
34
|
+
const applied = apply(next, {
|
|
35
|
+
kind: 'reference',
|
|
36
|
+
pointer,
|
|
37
|
+
value: retarget(value, relative(to, destination)),
|
|
38
|
+
prior: value,
|
|
39
|
+
});
|
|
40
|
+
if (applied.outcome !== 'applied')
|
|
41
|
+
continue;
|
|
42
|
+
next = applied.document;
|
|
43
|
+
names.add(name);
|
|
22
44
|
}
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
25
|
-
const named = target(from, value);
|
|
26
|
-
if (named === null)
|
|
27
|
-
return undefined;
|
|
28
|
-
const destination = moves.get(named) ?? named;
|
|
29
|
-
return target(to, value) === destination ? undefined : retarget(value, relative(to, destination));
|
|
45
|
+
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
30
46
|
}
|
|
31
47
|
function edited(document, path, changes) {
|
|
32
48
|
let next = document;
|
|
@@ -114,19 +130,12 @@ function rewrites(changes, visible) {
|
|
|
114
130
|
return { kind: 'changes', changes };
|
|
115
131
|
const merged = [...changes];
|
|
116
132
|
const added = [];
|
|
117
|
-
for (const [path, document] of
|
|
133
|
+
for (const [path, document] of documentsOf(visible.collection)) {
|
|
118
134
|
if (settled.has(path))
|
|
119
135
|
continue;
|
|
120
136
|
const moved = moves.get(path) ?? path;
|
|
121
137
|
const definition = definitionOf(governing(visible.collection.composition, path), document.type);
|
|
122
|
-
|
|
123
|
-
if (!referenceField(spec) || settled.has(`${path} ${name}`))
|
|
124
|
-
continue;
|
|
125
|
-
const value = repointed(document.fields[name], path, moved, moves);
|
|
126
|
-
if (value === undefined)
|
|
127
|
-
continue;
|
|
128
|
-
added.push({ kind: 'field', path, name, value });
|
|
129
|
-
}
|
|
138
|
+
added.push(...repointed(document, definition, path, moved, moves, settled));
|
|
130
139
|
const relinked = relinks(path, moved, edited(document, path, merged), moves);
|
|
131
140
|
if (relinked.kind === 'refused')
|
|
132
141
|
return relinked;
|
|
@@ -163,18 +172,6 @@ export function providerRewritten(batch, visible) {
|
|
|
163
172
|
...anticipated(batch.changes, batch.preconditions, rewritten.changes, visible),
|
|
164
173
|
};
|
|
165
174
|
}
|
|
166
|
-
function targets(value, from) {
|
|
167
|
-
const values = Array.isArray(value) ? value : [value];
|
|
168
|
-
const resolved = [];
|
|
169
|
-
for (const item of values) {
|
|
170
|
-
if (typeof item !== 'string')
|
|
171
|
-
continue;
|
|
172
|
-
const named = target(from, item);
|
|
173
|
-
if (named !== null)
|
|
174
|
-
resolved.push(named);
|
|
175
|
-
}
|
|
176
|
-
return resolved;
|
|
177
|
-
}
|
|
178
175
|
function incoming(collection, removed) {
|
|
179
176
|
const found = new Map();
|
|
180
177
|
const note = (target, file) => {
|
|
@@ -184,16 +181,15 @@ function incoming(collection, removed) {
|
|
|
184
181
|
referrers.add(file);
|
|
185
182
|
found.set(target, referrers);
|
|
186
183
|
};
|
|
187
|
-
for (const [path, document] of
|
|
184
|
+
for (const [path, document] of documentsOf(collection)) {
|
|
188
185
|
const definition = definitionOf(governing(collection.composition, path), document.type);
|
|
189
|
-
for (const
|
|
190
|
-
if (
|
|
186
|
+
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
187
|
+
if (to.includes(ATTACHMENT))
|
|
191
188
|
continue;
|
|
192
|
-
|
|
189
|
+
const named = target(path, value);
|
|
190
|
+
if (named !== null)
|
|
193
191
|
note(named, path);
|
|
194
192
|
}
|
|
195
|
-
for (const link of links(document, path))
|
|
196
|
-
note(link.target, path);
|
|
197
193
|
}
|
|
198
194
|
const [first] = [...found.keys()].sort();
|
|
199
195
|
if (first === undefined)
|
|
@@ -260,7 +256,7 @@ function guard(changes, input) {
|
|
|
260
256
|
}
|
|
261
257
|
continue;
|
|
262
258
|
}
|
|
263
|
-
if (input.visible.collection.
|
|
259
|
+
if (input.visible.collection.document(change.path) === undefined) {
|
|
264
260
|
return refuse('path-absent', change.path);
|
|
265
261
|
}
|
|
266
262
|
}
|
|
@@ -297,7 +293,7 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
297
293
|
add(based);
|
|
298
294
|
continue;
|
|
299
295
|
}
|
|
300
|
-
const document = visible.collection.
|
|
296
|
+
const document = visible.collection.document(change.path);
|
|
301
297
|
if (change.kind === 'field') {
|
|
302
298
|
add({
|
|
303
299
|
kind: 'field',
|
|
@@ -365,19 +361,76 @@ function exceeded(limits, changes, resulting) {
|
|
|
365
361
|
}
|
|
366
362
|
return null;
|
|
367
363
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
364
|
+
function shellRelative(text, path, handle, definition) {
|
|
365
|
+
if (!text.includes(`/rooms/${handle}/`))
|
|
366
|
+
return null;
|
|
367
|
+
const parsed = parse(text, path);
|
|
368
|
+
if (!parsed.ok)
|
|
369
|
+
return null;
|
|
370
|
+
const result = relativize(parsed.document, path, handle, definition(parsed.document.type));
|
|
371
|
+
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
372
|
+
}
|
|
373
|
+
function relativeField(path, name, value, handle, definition) {
|
|
374
|
+
const opened = parse('---\n---\n');
|
|
375
|
+
if (definition === undefined ||
|
|
376
|
+
!opened.ok ||
|
|
377
|
+
!JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
378
|
+
return value;
|
|
379
|
+
const held = apply(opened.document, { kind: 'field', name, value, prior: undefined });
|
|
380
|
+
if (held.outcome !== 'applied')
|
|
381
|
+
return value;
|
|
382
|
+
const result = relativize(held.document, path, handle, definition);
|
|
383
|
+
return result.outcome === 'applied' ? result.document.fields[name] : value;
|
|
384
|
+
}
|
|
385
|
+
function relativeChanges(input) {
|
|
386
|
+
const { handle, composition, visible } = input;
|
|
387
|
+
const typed = (path) => (type) => definitionOf(governing(composition, path), type);
|
|
388
|
+
const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
|
|
389
|
+
return input.changes.map((change) => {
|
|
390
|
+
const definition = typed(change.path);
|
|
391
|
+
if (change.kind === 'field') {
|
|
392
|
+
const type = visible.collection.document(change.path)?.type;
|
|
393
|
+
const value = relativeField(change.path, change.name, change.value, handle, definition(type));
|
|
394
|
+
return value === change.value ? change : { ...change, value };
|
|
395
|
+
}
|
|
396
|
+
if (change.kind === 'section' || change.kind === 'preamble') {
|
|
397
|
+
const value = body(change.path, change.value);
|
|
398
|
+
return value === change.value ? change : { ...change, value };
|
|
399
|
+
}
|
|
400
|
+
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
401
|
+
const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
|
|
402
|
+
return content === change.content ? change : { ...change, content };
|
|
403
|
+
}
|
|
404
|
+
if (change.kind !== 'create')
|
|
405
|
+
return change;
|
|
406
|
+
const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
|
|
407
|
+
const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
|
|
408
|
+
name,
|
|
409
|
+
relativeField(change.path, name, value, handle, definition(type)),
|
|
410
|
+
]));
|
|
411
|
+
const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
|
|
412
|
+
return { ...change, fields, sections };
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function unmodeledType(collection, composition) {
|
|
416
|
+
for (const [path, document] of documentsOf(collection)) {
|
|
417
|
+
if (document.type !== undefined &&
|
|
372
418
|
document.type !== 'any' &&
|
|
373
|
-
governing(
|
|
419
|
+
governing(composition, path).status === 'unavailable')
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
export function buildBatch(input) {
|
|
425
|
+
const changes = relativeChanges(input);
|
|
426
|
+
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
427
|
+
if (structural !== undefined && unmodeledType(input.visible.collection, input.composition))
|
|
374
428
|
return refuse('model-unavailable', structural.path);
|
|
375
|
-
if (
|
|
429
|
+
if (changes.length === 0)
|
|
376
430
|
return refuse('no-change');
|
|
377
|
-
const rewritten = rewrites(
|
|
431
|
+
const rewritten = rewrites(changes, input.visible);
|
|
378
432
|
if (rewritten.kind === 'refused')
|
|
379
433
|
return rewritten;
|
|
380
|
-
const changes = input.changes;
|
|
381
434
|
const refusal = guard(changes, input);
|
|
382
435
|
if (refusal !== null)
|
|
383
436
|
return refusal;
|
|
@@ -388,7 +441,7 @@ export function buildBatch(input) {
|
|
|
388
441
|
]);
|
|
389
442
|
const removed = new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path));
|
|
390
443
|
if (removed.size > 0) {
|
|
391
|
-
const referenced = incoming(
|
|
444
|
+
const referenced = incoming(collectionOf(resulting.documents, input.composition), removed);
|
|
392
445
|
if (referenced !== null)
|
|
393
446
|
return referenced;
|
|
394
447
|
}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ModelState } from './model.js';
|
|
2
|
-
import type { Capability, HeadChange, OperationScopes, ProviderLimit, ReplicaAdmission, RoomAttachment, TypedSelection } from './adapter.js';
|
|
2
|
+
import type { Capability, HeadChange, Member, OperationScopes, ProviderLimit, ReplicaAdmission, RoomAttachment, TypedSelection } from './adapter.js';
|
|
3
3
|
import type { AcceptedMessage } from './adapter.js';
|
|
4
4
|
import type { ChangeBatch } from './change.js';
|
|
5
5
|
import type { ChatDraftFile } from './file.js';
|
|
6
6
|
import type { Submission } from './outcome.js';
|
|
7
7
|
import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
|
|
8
|
+
export declare const STORE_SCHEMA = 21;
|
|
8
9
|
export type ReplicaRecord = {
|
|
9
10
|
locator: string;
|
|
10
11
|
name: string;
|
|
12
|
+
handle: string;
|
|
11
13
|
operations: OperationScopes;
|
|
12
14
|
replica: ReplicaAdmission;
|
|
13
15
|
model: ModelState;
|
|
@@ -15,6 +17,7 @@ export type ReplicaRecord = {
|
|
|
15
17
|
selectionModel: ModelState;
|
|
16
18
|
providerOwnedPaths: readonly string[];
|
|
17
19
|
roomVersion: string;
|
|
20
|
+
transfer: string;
|
|
18
21
|
documents: Readonly<Record<string, string>>;
|
|
19
22
|
binaryTargets: readonly string[];
|
|
20
23
|
revisions: Readonly<Record<string, string>>;
|
|
@@ -22,6 +25,20 @@ export type ReplicaRecord = {
|
|
|
22
25
|
written: Readonly<Record<string, string>>;
|
|
23
26
|
attachments: readonly RoomAttachment[];
|
|
24
27
|
};
|
|
28
|
+
export type StagedLayer = Pick<ReplicaRecord, 'documents' | 'binaryTargets' | 'revisions' | 'changes' | 'written'>;
|
|
29
|
+
export type TransferRecord = {
|
|
30
|
+
locator: string;
|
|
31
|
+
transfer: string;
|
|
32
|
+
selection: string;
|
|
33
|
+
from: string;
|
|
34
|
+
last: string;
|
|
35
|
+
pageToken: string | null;
|
|
36
|
+
models: {
|
|
37
|
+
collection: ModelState;
|
|
38
|
+
selection: ModelState;
|
|
39
|
+
};
|
|
40
|
+
attachments: readonly (readonly RoomAttachment[])[];
|
|
41
|
+
};
|
|
25
42
|
export type PendingState = {
|
|
26
43
|
readonly drafts: readonly SavedDraft[];
|
|
27
44
|
readonly submission: Submission;
|
|
@@ -60,6 +77,7 @@ export type ChatDraftRecord = {
|
|
|
60
77
|
export type RecordWrite = {
|
|
61
78
|
next: ReplicaRecord;
|
|
62
79
|
previous: ReplicaRecord | null;
|
|
80
|
+
stored?: StagedLayer;
|
|
63
81
|
queue: readonly ChangeBatch[];
|
|
64
82
|
previousQueue?: readonly ChangeBatch[];
|
|
65
83
|
saved?: readonly SavedDraft[];
|
|
@@ -78,6 +96,8 @@ export type RuntimeStore = {
|
|
|
78
96
|
providerLimits(): Promise<readonly ProviderLimit[]>;
|
|
79
97
|
capabilities(): Promise<readonly Capability[]>;
|
|
80
98
|
declare(limits: readonly ProviderLimit[], capabilities: readonly Capability[]): Promise<void>;
|
|
99
|
+
member(): Promise<Member | null>;
|
|
100
|
+
keepMember(member: Member | null): Promise<void>;
|
|
81
101
|
queues(): Promise<readonly QueueRecord[]>;
|
|
82
102
|
submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
|
|
83
103
|
accept(locator: string, id: string, roomVersion: string): Promise<void>;
|
|
@@ -94,6 +114,10 @@ export type RuntimeStore = {
|
|
|
94
114
|
keepRoomDraft(record: RoomDraftRecord): Promise<void>;
|
|
95
115
|
discardRoomDraft(locator: string, path: string): Promise<void>;
|
|
96
116
|
dropRooms(locators: readonly string[]): Promise<void>;
|
|
117
|
+
transfers(): Promise<readonly TransferRecord[]>;
|
|
118
|
+
staged(record: TransferRecord): Promise<StagedLayer>;
|
|
119
|
+
stage(record: TransferRecord, page: StagedLayer): Promise<void>;
|
|
120
|
+
abandon(locator: string): Promise<void>;
|
|
97
121
|
generation(): Promise<string | null>;
|
|
98
122
|
rememberGeneration(value: string): Promise<void>;
|
|
99
123
|
close(): void;
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,MAAM,EACN,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,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