@agentshouse/mdruntime 0.1.0-c389df724fd2f → 0.1.0-c38dcfe165d81
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/README.md +24 -11
- package/dist/adapter.d.ts +175 -54
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +5 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +38 -4
- 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 +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +33 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +202 -48
- package/dist/chain.d.ts +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -56
- package/dist/change.d.ts +45 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/client.d.ts +37 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +123 -22
- package/dist/collection.d.ts +13 -14
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +52 -56
- package/dist/compile.d.ts +11 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +586 -0
- package/dist/connection.d.ts +59 -20
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3810 -905
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +50 -20
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +714 -242
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +4 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +159 -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/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/host.d.ts +11 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +128 -25
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +23 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +127 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +19 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +251 -98
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +89 -0
- package/dist/model.d.ts +13 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -5
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +120 -14
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +72 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +81 -1
- package/dist/overlay.d.ts +15 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +136 -180
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +42 -181
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -461
- package/dist/reach.d.ts +18 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +234 -69
- package/dist/react.d.ts +14 -8
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -17
- package/dist/readiness.d.ts +50 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +224 -0
- package/dist/refresh.d.ts +20 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +148 -59
- package/dist/replica.d.ts +59 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +320 -157
- package/dist/room-draft.d.ts +59 -11
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +276 -80
- package/dist/rows.d.ts +23 -35
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +61 -117
- package/dist/save.d.ts +73 -4
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +825 -150
- package/dist/search.d.ts +15 -54
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +421 -0
- package/dist/status.d.ts +7 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -9
- package/dist/store.d.ts +107 -62
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +318 -354
- package/dist/stored.d.ts +129 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +495 -0
- package/dist/tables.d.ts +326 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +574 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +169 -33
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +68 -31
- package/package.json +26 -15
- package/AGENTS.md +0 -253
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -433
package/dist/overlay.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { apply, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { drafted, entriesIn, settling } from './shared.js';
|
|
3
|
+
import { ROW_WEIGHT } from './turn.js';
|
|
4
|
+
export function* acceptedBinaries(files) {
|
|
5
|
+
for (const [path, file] of entriesIn(files))
|
|
6
|
+
yield [path, { state: 'accepted', ...file }];
|
|
7
|
+
}
|
|
8
|
+
export function sameBinary(left, right) {
|
|
9
|
+
if (left === undefined || right === undefined)
|
|
10
|
+
return left === right;
|
|
11
|
+
return (left.state === right.state &&
|
|
12
|
+
left.byteLength === right.byteLength &&
|
|
13
|
+
left.mediaType === right.mediaType &&
|
|
14
|
+
left.sha256 === right.sha256 &&
|
|
15
|
+
(left.state === 'accepted'
|
|
16
|
+
? right.state === 'accepted'
|
|
17
|
+
: right.state === 'pending' && left.localId === right.localId));
|
|
18
|
+
}
|
|
2
19
|
export function sameChange(left, right) {
|
|
3
20
|
if (left === undefined || right === undefined)
|
|
4
21
|
return left === right;
|
|
@@ -8,10 +25,13 @@ export function sameChange(left, right) {
|
|
|
8
25
|
left.author?.name === right.author?.name);
|
|
9
26
|
}
|
|
10
27
|
const EMPTY_FRONTMATTER = '---\n---\n';
|
|
28
|
+
function isPart(change) {
|
|
29
|
+
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
30
|
+
}
|
|
11
31
|
function at(path, name) {
|
|
12
32
|
return `${path} ${name}`;
|
|
13
33
|
}
|
|
14
|
-
function priorsOf(preconditions) {
|
|
34
|
+
function* priorsOf(preconditions) {
|
|
15
35
|
const fields = new Map();
|
|
16
36
|
const sections = new Map();
|
|
17
37
|
const preambles = new Map();
|
|
@@ -25,6 +45,7 @@ function priorsOf(preconditions) {
|
|
|
25
45
|
if (precondition.kind === 'preamble') {
|
|
26
46
|
preambles.set(precondition.path, precondition.value);
|
|
27
47
|
}
|
|
48
|
+
yield ROW_WEIGHT;
|
|
28
49
|
}
|
|
29
50
|
return {
|
|
30
51
|
field: (path, name) => fields.get(at(path, name)),
|
|
@@ -40,49 +61,50 @@ function compose(fields, sections) {
|
|
|
40
61
|
const opened = parse(skeleton);
|
|
41
62
|
if (!opened.ok)
|
|
42
63
|
return skeleton;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const next = apply(document, { kind: 'field', name, value, prior: undefined });
|
|
46
|
-
if (next.outcome === 'applied')
|
|
47
|
-
document = next.document;
|
|
48
|
-
}
|
|
49
|
-
return serialize(document);
|
|
64
|
+
const next = apply(opened.document, Object.entries(fields).flatMap(([name, value]) => frontmatterValue(value) ? [{ kind: 'field', name, value, prior: undefined }] : []));
|
|
65
|
+
return serialize(next.outcome === 'applied' ? next.document : opened.document);
|
|
50
66
|
}
|
|
51
|
-
function edited(
|
|
52
|
-
if (change.kind === 'field')
|
|
53
|
-
return
|
|
67
|
+
function edited(change, priors) {
|
|
68
|
+
if (change.kind === 'field')
|
|
69
|
+
return {
|
|
54
70
|
kind: 'field',
|
|
55
71
|
name: change.name,
|
|
56
72
|
value: change.value,
|
|
57
73
|
prior: priors.field(change.path, change.name),
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
kind: 'preamble',
|
|
63
|
-
value: change.value,
|
|
64
|
-
prior: priors.preamble(change.path),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (change.kind !== 'section')
|
|
68
|
-
return null;
|
|
69
|
-
return apply(document, {
|
|
74
|
+
};
|
|
75
|
+
if (change.kind === 'preamble')
|
|
76
|
+
return { kind: 'preamble', value: change.value, prior: priors.preamble(change.path) };
|
|
77
|
+
return {
|
|
70
78
|
kind: 'section',
|
|
71
79
|
name: change.name,
|
|
72
80
|
value: change.value,
|
|
73
81
|
prior: priors.section(change.path, change.name),
|
|
74
|
-
}
|
|
82
|
+
};
|
|
75
83
|
}
|
|
76
|
-
function edit(staged,
|
|
77
|
-
const
|
|
84
|
+
function edit(staged, changes, priors) {
|
|
85
|
+
const path = changes[0].path;
|
|
86
|
+
delete staged.revisions[path];
|
|
87
|
+
const text = staged.documents[path];
|
|
78
88
|
if (text === undefined)
|
|
79
|
-
return;
|
|
80
|
-
const parsed = parse(text,
|
|
89
|
+
return changes.length;
|
|
90
|
+
const parsed = parse(text, path);
|
|
81
91
|
if (!parsed.ok)
|
|
82
|
-
return;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
return changes.length;
|
|
93
|
+
const wanted = changes.map((change) => edited(change, priors));
|
|
94
|
+
const first = apply(parsed.document, wanted);
|
|
95
|
+
if (first.outcome === 'refuse')
|
|
96
|
+
return changes.length;
|
|
97
|
+
if (first.outcome === 'applied') {
|
|
98
|
+
staged.documents[path] = serialize(first.document);
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
const stale = new Set(first.stale);
|
|
102
|
+
const kept = wanted.filter((_, at) => !stale.has(at));
|
|
103
|
+
const rest = apply(parsed.document, kept);
|
|
104
|
+
if (rest.outcome !== 'applied')
|
|
105
|
+
return changes.length;
|
|
106
|
+
staged.documents[path] = serialize(rest.document);
|
|
107
|
+
return first.stale.length;
|
|
86
108
|
}
|
|
87
109
|
function relocate(staged, from, to) {
|
|
88
110
|
const text = staged.documents[from];
|
|
@@ -90,194 +112,128 @@ function relocate(staged, from, to) {
|
|
|
90
112
|
delete staged.documents[from];
|
|
91
113
|
staged.documents[to] = text;
|
|
92
114
|
}
|
|
93
|
-
else if (staged.
|
|
94
|
-
staged.
|
|
115
|
+
else if (staged.binaries[from] !== undefined) {
|
|
116
|
+
staged.binaries[to] = staged.binaries[from];
|
|
117
|
+
delete staged.binaries[from];
|
|
95
118
|
}
|
|
96
119
|
else {
|
|
97
|
-
return;
|
|
120
|
+
return false;
|
|
98
121
|
}
|
|
99
122
|
moveHead(staged, from, to);
|
|
123
|
+
return true;
|
|
100
124
|
}
|
|
101
125
|
function moveHead(heads, from, to) {
|
|
102
126
|
const revision = heads.revisions[from];
|
|
127
|
+
const fileId = heads.fileIds[from];
|
|
103
128
|
const change = heads.changes[from];
|
|
104
129
|
delete heads.revisions[from];
|
|
130
|
+
delete heads.fileIds[from];
|
|
105
131
|
delete heads.changes[from];
|
|
132
|
+
delete heads.fileIds[to];
|
|
106
133
|
delete heads.changes[to];
|
|
107
134
|
if (revision !== undefined)
|
|
108
135
|
heads.revisions[to] = revision;
|
|
136
|
+
if (fileId !== undefined)
|
|
137
|
+
heads.fileIds[to] = fileId;
|
|
109
138
|
if (change !== undefined)
|
|
110
139
|
heads.changes[to] = change;
|
|
111
140
|
}
|
|
112
141
|
function erase(staged, path) {
|
|
113
142
|
delete staged.documents[path];
|
|
114
143
|
delete staged.revisions[path];
|
|
144
|
+
delete staged.fileIds[path];
|
|
115
145
|
delete staged.changes[path];
|
|
116
|
-
staged.
|
|
146
|
+
delete staged.binaries[path];
|
|
117
147
|
}
|
|
118
|
-
function stage(staged, change
|
|
119
|
-
if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
|
|
120
|
-
edit(staged, change, priors);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
148
|
+
function stage(staged, change) {
|
|
123
149
|
if (change.kind === 'create') {
|
|
124
150
|
staged.documents[change.path] =
|
|
125
151
|
'content' in change ? change.content : compose(change.fields, change.sections);
|
|
152
|
+
delete staged.fileIds[change.path];
|
|
126
153
|
delete staged.changes[change.path];
|
|
127
|
-
return;
|
|
154
|
+
return true;
|
|
128
155
|
}
|
|
129
156
|
if (change.kind === 'replace') {
|
|
157
|
+
delete staged.revisions[change.path];
|
|
130
158
|
if (staged.documents[change.path] === undefined)
|
|
131
|
-
return;
|
|
159
|
+
return false;
|
|
132
160
|
staged.documents[change.path] = change.content;
|
|
133
|
-
return;
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
if (change.kind === 'binary') {
|
|
164
|
+
if (staged.documents[change.path] !== undefined)
|
|
165
|
+
return false;
|
|
166
|
+
staged.binaries[change.path] = {
|
|
167
|
+
state: 'pending',
|
|
168
|
+
localId: change.localId,
|
|
169
|
+
byteLength: change.byteLength,
|
|
170
|
+
mediaType: change.mediaType,
|
|
171
|
+
sha256: change.sha256,
|
|
172
|
+
};
|
|
173
|
+
delete staged.revisions[change.path];
|
|
174
|
+
delete staged.changes[change.path];
|
|
175
|
+
return true;
|
|
134
176
|
}
|
|
135
177
|
if (change.kind === 'move') {
|
|
136
|
-
relocate(staged, change.path, change.to);
|
|
137
|
-
|
|
178
|
+
return relocate(staged, change.path, change.to);
|
|
179
|
+
}
|
|
180
|
+
if (change.kind === 'arrival') {
|
|
181
|
+
erase(staged, change.path);
|
|
182
|
+
if ('content' in change)
|
|
183
|
+
staged.documents[change.path] = change.content;
|
|
184
|
+
else
|
|
185
|
+
staged.binaries[change.path] = { state: 'accepted', ...change.binary };
|
|
186
|
+
arrive(staged, change);
|
|
187
|
+
return true;
|
|
138
188
|
}
|
|
139
189
|
erase(staged, change.path);
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
function arrive(heads, change) {
|
|
193
|
+
if (change.revision !== undefined)
|
|
194
|
+
heads.revisions[change.path] = change.revision;
|
|
195
|
+
if (change.fileId !== undefined)
|
|
196
|
+
heads.fileIds[change.path] = change.fileId;
|
|
197
|
+
if (change.change !== undefined)
|
|
198
|
+
heads.changes[change.path] = change.change;
|
|
140
199
|
}
|
|
141
|
-
export function
|
|
200
|
+
export function* overlaying(base, queue, unapplied) {
|
|
142
201
|
const staged = {
|
|
143
|
-
documents:
|
|
144
|
-
|
|
145
|
-
revisions:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
for (const batch of queue) {
|
|
149
|
-
const priors = priorsOf(batch.preconditions);
|
|
150
|
-
for (const change of batch.changes)
|
|
151
|
-
stage(staged, change, priors);
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
documents: staged.documents,
|
|
155
|
-
binaryTargets: [...staged.binaryTargets].sort(),
|
|
156
|
-
revisions: staged.revisions,
|
|
157
|
-
changes: staged.changes,
|
|
202
|
+
documents: drafted(base.documents),
|
|
203
|
+
binaries: drafted(base.binaries),
|
|
204
|
+
revisions: drafted(base.revisions),
|
|
205
|
+
fileIds: drafted(base.fileIds),
|
|
206
|
+
changes: drafted(base.changes),
|
|
158
207
|
};
|
|
159
|
-
}
|
|
160
|
-
function pathsOf(batch) {
|
|
161
|
-
return batch.changes.flatMap((change) => change.kind === 'move' ? [change.path, change.to] : [change.path]);
|
|
162
|
-
}
|
|
163
|
-
export function sameLayerText(left, right) {
|
|
164
|
-
const paths = Object.keys(left.documents);
|
|
165
|
-
return (paths.length === Object.keys(right.documents).length &&
|
|
166
|
-
paths.every((path) => left.documents[path] === right.documents[path]) &&
|
|
167
|
-
left.binaryTargets.length === right.binaryTargets.length &&
|
|
168
|
-
left.binaryTargets.every((path) => right.binaryTargets.includes(path)));
|
|
169
|
-
}
|
|
170
|
-
function replayHeads(base, queue) {
|
|
171
|
-
const heads = { revisions: { ...base.revisions }, changes: { ...base.changes } };
|
|
172
208
|
for (const batch of queue) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
else if (change.kind === 'move') {
|
|
182
|
-
moveHead(heads, change.path, change.to);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return heads;
|
|
187
|
-
}
|
|
188
|
-
export function overlayChanged(base, queue, previousBase, previousQueue, previousVisible) {
|
|
189
|
-
const before = previousQueue.map((batch) => JSON.stringify(batch));
|
|
190
|
-
const after = queue.map((batch) => JSON.stringify(batch));
|
|
191
|
-
if (before.length === after.length &&
|
|
192
|
-
before.every((id, index) => id === after[index]) &&
|
|
193
|
-
sameLayerText(base, previousBase)) {
|
|
194
|
-
return {
|
|
195
|
-
documents: previousVisible.documents,
|
|
196
|
-
binaryTargets: previousVisible.binaryTargets,
|
|
197
|
-
...replayHeads(base, queue),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
const affected = new Set();
|
|
201
|
-
const paths = new Set([
|
|
202
|
-
...Object.keys(base.documents),
|
|
203
|
-
...Object.keys(previousBase.documents),
|
|
204
|
-
...Object.keys(base.revisions),
|
|
205
|
-
...Object.keys(previousBase.revisions),
|
|
206
|
-
...Object.keys(base.changes),
|
|
207
|
-
...Object.keys(previousBase.changes),
|
|
208
|
-
...base.binaryTargets,
|
|
209
|
-
...previousBase.binaryTargets,
|
|
210
|
-
]);
|
|
211
|
-
for (const path of paths) {
|
|
212
|
-
if (base.documents[path] !== previousBase.documents[path] ||
|
|
213
|
-
base.revisions[path] !== previousBase.revisions[path] ||
|
|
214
|
-
!sameChange(base.changes[path], previousBase.changes[path]) ||
|
|
215
|
-
base.binaryTargets.includes(path) !== previousBase.binaryTargets.includes(path))
|
|
216
|
-
affected.add(path);
|
|
217
|
-
}
|
|
218
|
-
const oldIds = new Set(before);
|
|
219
|
-
const newIds = new Set(after);
|
|
220
|
-
for (const batch of previousQueue) {
|
|
221
|
-
if (!newIds.has(JSON.stringify(batch)))
|
|
222
|
-
for (const path of pathsOf(batch))
|
|
223
|
-
affected.add(path);
|
|
224
|
-
}
|
|
225
|
-
for (const batch of queue) {
|
|
226
|
-
if (!oldIds.has(JSON.stringify(batch)))
|
|
227
|
-
for (const path of pathsOf(batch))
|
|
228
|
-
affected.add(path);
|
|
229
|
-
}
|
|
230
|
-
let expanded = true;
|
|
231
|
-
while (expanded) {
|
|
232
|
-
expanded = false;
|
|
233
|
-
for (const batch of queue) {
|
|
234
|
-
const touched = pathsOf(batch);
|
|
235
|
-
if (!touched.some((path) => affected.has(path)))
|
|
209
|
+
const priors = yield* priorsOf(batch.preconditions);
|
|
210
|
+
for (let index = 0; index < batch.changes.length; index += 1) {
|
|
211
|
+
const change = batch.changes[index];
|
|
212
|
+
if (!isPart(change)) {
|
|
213
|
+
if (!stage(staged, change))
|
|
214
|
+
unapplied?.();
|
|
215
|
+
yield ROW_WEIGHT;
|
|
236
216
|
continue;
|
|
237
|
-
for (const path of touched) {
|
|
238
|
-
if (affected.has(path))
|
|
239
|
-
continue;
|
|
240
|
-
affected.add(path);
|
|
241
|
-
expanded = true;
|
|
242
217
|
}
|
|
218
|
+
const run = [change];
|
|
219
|
+
while (index + 1 < batch.changes.length) {
|
|
220
|
+
const next = batch.changes[index + 1];
|
|
221
|
+
if (!isPart(next) || next.path !== change.path)
|
|
222
|
+
break;
|
|
223
|
+
run.push(next);
|
|
224
|
+
index += 1;
|
|
225
|
+
}
|
|
226
|
+
const text = staged.documents[change.path] ?? '';
|
|
227
|
+
for (let left = edit(staged, run, priors); left > 0; left -= 1)
|
|
228
|
+
unapplied?.();
|
|
229
|
+
yield ROW_WEIGHT + text.length;
|
|
243
230
|
}
|
|
244
231
|
}
|
|
245
|
-
const documents = {};
|
|
246
|
-
const revisions = {};
|
|
247
|
-
const changes = {};
|
|
248
|
-
for (const path of affected) {
|
|
249
|
-
if (base.documents[path] !== undefined)
|
|
250
|
-
documents[path] = base.documents[path];
|
|
251
|
-
if (base.revisions[path] !== undefined)
|
|
252
|
-
revisions[path] = base.revisions[path];
|
|
253
|
-
if (base.changes[path] !== undefined)
|
|
254
|
-
changes[path] = base.changes[path];
|
|
255
|
-
}
|
|
256
|
-
const staged = overlay({
|
|
257
|
-
documents,
|
|
258
|
-
revisions,
|
|
259
|
-
changes,
|
|
260
|
-
binaryTargets: base.binaryTargets.filter((path) => affected.has(path)),
|
|
261
|
-
}, queue.filter((batch) => pathsOf(batch).some((path) => affected.has(path))));
|
|
262
|
-
const mergedDocuments = { ...previousVisible.documents };
|
|
263
|
-
const mergedRevisions = { ...previousVisible.revisions };
|
|
264
|
-
const mergedChanges = { ...previousVisible.changes };
|
|
265
|
-
const mergedTargets = new Set(previousVisible.binaryTargets);
|
|
266
|
-
for (const path of affected) {
|
|
267
|
-
delete mergedDocuments[path];
|
|
268
|
-
delete mergedRevisions[path];
|
|
269
|
-
delete mergedChanges[path];
|
|
270
|
-
mergedTargets.delete(path);
|
|
271
|
-
}
|
|
272
|
-
Object.assign(mergedDocuments, staged.documents);
|
|
273
|
-
Object.assign(mergedRevisions, staged.revisions);
|
|
274
|
-
Object.assign(mergedChanges, staged.changes);
|
|
275
|
-
for (const path of staged.binaryTargets)
|
|
276
|
-
mergedTargets.add(path);
|
|
277
232
|
return {
|
|
278
|
-
documents:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
233
|
+
documents: yield* settling(staged.documents),
|
|
234
|
+
binaries: yield* settling(staged.binaries),
|
|
235
|
+
revisions: yield* settling(staged.revisions),
|
|
236
|
+
fileIds: yield* settling(staged.fileIds),
|
|
237
|
+
changes: yield* settling(staged.changes),
|
|
282
238
|
};
|
|
283
239
|
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function normalize(path: string): string | null;
|
|
2
2
|
export declare function beneath(prefix: string, path: string): boolean;
|
|
3
3
|
export declare function covered(prefixes: readonly string[], path: string): boolean;
|
|
4
|
+
export declare function ancestors(path: string): readonly string[];
|
|
4
5
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK1E"}
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK1E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAGzD"}
|
package/dist/paths.js
CHANGED
|
@@ -22,3 +22,7 @@ export function covered(prefixes, path) {
|
|
|
22
22
|
return normalized !== null && (normalized === '' || beneath(normalized, path));
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
export function ancestors(path) {
|
|
26
|
+
const parts = path.split('/');
|
|
27
|
+
return parts.slice(1).map((_, at) => parts.slice(0, at + 1).join('/'));
|
|
28
|
+
}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,83 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type HeldRooms, type QueryPlan } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
$eq: Value;
|
|
6
|
-
} | {
|
|
7
|
-
$ne: Value;
|
|
8
|
-
} | {
|
|
9
|
-
$in: readonly Value[];
|
|
10
|
-
} | {
|
|
11
|
-
$nin: readonly Value[];
|
|
12
|
-
} | {
|
|
13
|
-
$gt?: Value;
|
|
14
|
-
$gte?: Value;
|
|
15
|
-
$lt?: Value;
|
|
16
|
-
$lte?: Value;
|
|
17
|
-
} | {
|
|
18
|
-
$all: readonly Value[];
|
|
19
|
-
} | {
|
|
20
|
-
$size: number;
|
|
21
|
-
} | {
|
|
22
|
-
$exists: boolean;
|
|
23
|
-
};
|
|
24
|
-
export type Where = {
|
|
25
|
-
$and?: readonly Where[];
|
|
26
|
-
$or?: readonly Where[];
|
|
27
|
-
[field: string]: Predicate | readonly Where[] | undefined;
|
|
28
|
-
};
|
|
29
|
-
export type Related = {
|
|
30
|
-
types?: readonly string[];
|
|
31
|
-
where?: Where;
|
|
32
|
-
pathPrefix?: string;
|
|
33
|
-
};
|
|
34
|
-
export type Filter = {
|
|
35
|
-
rooms?: readonly string[];
|
|
36
|
-
types?: readonly string[];
|
|
37
|
-
where?: Where;
|
|
38
|
-
pathPrefix?: string;
|
|
39
|
-
hop?: Related & {
|
|
40
|
-
field: string;
|
|
41
|
-
};
|
|
42
|
-
backlinks?: Related & {
|
|
43
|
-
field?: string;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
export type Key = 'room' | 'path' | 'type' | {
|
|
47
|
-
field: string;
|
|
48
|
-
};
|
|
49
|
-
export type Select = 'all' | {
|
|
50
|
-
fields?: 'all' | readonly string[];
|
|
51
|
-
sections?: 'all' | readonly string[];
|
|
52
|
-
preamble?: true;
|
|
53
|
-
markdown?: true;
|
|
54
|
-
backlinks?: true;
|
|
55
|
-
change?: true;
|
|
56
|
-
};
|
|
57
|
-
export type OrderOptions = {
|
|
58
|
-
nulls?: 'first' | 'last';
|
|
59
|
-
stringSort?: 'lexical' | 'locale';
|
|
60
|
-
locale?: string;
|
|
61
|
-
localeOptions?: Readonly<Record<string, unknown>>;
|
|
62
|
-
};
|
|
63
|
-
export type Direction = 'asc' | 'desc';
|
|
64
|
-
export type DocumentQuery = Filter & {
|
|
65
|
-
select: Select;
|
|
66
|
-
orderBy?: readonly ({
|
|
67
|
-
by: Key;
|
|
68
|
-
direction?: Direction;
|
|
69
|
-
} & OrderOptions)[];
|
|
70
|
-
limit?: number;
|
|
71
|
-
};
|
|
72
|
-
export type GroupQuery = Filter & {
|
|
73
|
-
groupBy: readonly Exclude<Key, 'path'>[];
|
|
74
|
-
orderBy?: readonly {
|
|
75
|
-
by: 'count' | Exclude<Key, 'path'>;
|
|
76
|
-
direction?: Direction;
|
|
77
|
-
}[];
|
|
78
|
-
limit?: number;
|
|
79
|
-
};
|
|
80
|
-
export type LocalQuery = DocumentQuery | GroupQuery;
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
4
|
+
import type { Open } from './open.js';
|
|
81
5
|
export type Backlink = {
|
|
82
6
|
path: string;
|
|
83
7
|
type: string;
|
|
@@ -93,126 +17,63 @@ export type QueryDocument = {
|
|
|
93
17
|
markdown?: string;
|
|
94
18
|
backlinks?: readonly Backlink[];
|
|
95
19
|
change?: HeadChange | null;
|
|
20
|
+
fileId?: string | null;
|
|
21
|
+
revision?: string | null;
|
|
22
|
+
binaryFile?: BinaryFileRecord;
|
|
96
23
|
};
|
|
97
24
|
export type QueryGroup = {
|
|
98
25
|
key: readonly unknown[];
|
|
99
26
|
count: number;
|
|
100
27
|
};
|
|
101
|
-
export type
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
groups: readonly QueryGroup[];
|
|
28
|
+
export type CoveredRoom = {
|
|
29
|
+
room: string;
|
|
30
|
+
generation: string;
|
|
31
|
+
current: boolean;
|
|
106
32
|
};
|
|
107
|
-
export type
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
available: boolean;
|
|
112
|
-
types: readonly Definition[];
|
|
33
|
+
export type QueryCoverage = {
|
|
34
|
+
rooms: readonly CoveredRoom[];
|
|
35
|
+
indexes: readonly string[];
|
|
36
|
+
overlay: readonly string[];
|
|
113
37
|
};
|
|
114
|
-
export type
|
|
115
|
-
|
|
116
|
-
|
|
38
|
+
export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
|
|
39
|
+
export type PendingRoom = {
|
|
40
|
+
room: string;
|
|
41
|
+
awaits: Awaits;
|
|
117
42
|
};
|
|
118
|
-
export type
|
|
119
|
-
|
|
120
|
-
value: Value;
|
|
121
|
-
} | {
|
|
122
|
-
op: 'ne';
|
|
123
|
-
value: Value;
|
|
124
|
-
} | {
|
|
125
|
-
op: 'in';
|
|
126
|
-
values: readonly Value[];
|
|
127
|
-
} | {
|
|
128
|
-
op: 'nin';
|
|
129
|
-
values: readonly Value[];
|
|
130
|
-
} | {
|
|
131
|
-
op: 'range';
|
|
132
|
-
bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
|
|
133
|
-
} | {
|
|
134
|
-
op: 'all';
|
|
135
|
-
values: readonly Value[];
|
|
136
|
-
} | {
|
|
137
|
-
op: 'size';
|
|
138
|
-
size: number;
|
|
139
|
-
} | {
|
|
140
|
-
op: 'exists';
|
|
141
|
-
exists: boolean;
|
|
43
|
+
export type PendingResult = {
|
|
44
|
+
pending: readonly PendingRoom[];
|
|
142
45
|
};
|
|
143
|
-
export type
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
} | {
|
|
148
|
-
field: string;
|
|
149
|
-
test: Test;
|
|
46
|
+
export type DocumentRows = {
|
|
47
|
+
documents: readonly QueryDocument[];
|
|
48
|
+
next?: string;
|
|
49
|
+
total?: number;
|
|
150
50
|
};
|
|
151
|
-
export type
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
51
|
+
export type GroupRows = {
|
|
52
|
+
groups: readonly QueryGroup[];
|
|
53
|
+
next?: string;
|
|
54
|
+
total?: number;
|
|
155
55
|
};
|
|
156
|
-
export type
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
of: 'path';
|
|
160
|
-
} | {
|
|
161
|
-
of: 'type';
|
|
162
|
-
} | {
|
|
163
|
-
of: 'field';
|
|
164
|
-
field: string;
|
|
56
|
+
export type QueryRows = DocumentRows | GroupRows;
|
|
57
|
+
export type DocumentResult = DocumentRows & {
|
|
58
|
+
coverage: QueryCoverage;
|
|
165
59
|
};
|
|
166
|
-
export type
|
|
167
|
-
|
|
168
|
-
fields: 'all' | readonly string[] | null;
|
|
169
|
-
sections: 'all' | readonly string[] | null;
|
|
170
|
-
preamble: boolean;
|
|
171
|
-
markdown: boolean;
|
|
172
|
-
backlinks: boolean;
|
|
173
|
-
change: boolean;
|
|
174
|
-
orderBy: readonly {
|
|
175
|
-
key: KeyPlan;
|
|
176
|
-
options: OrderOptions & {
|
|
177
|
-
direction: Direction;
|
|
178
|
-
};
|
|
179
|
-
}[];
|
|
60
|
+
export type GroupResult = GroupRows & {
|
|
61
|
+
coverage: QueryCoverage;
|
|
180
62
|
};
|
|
181
|
-
export type
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
direction: Direction;
|
|
187
|
-
}[];
|
|
63
|
+
export type QueryResult = DocumentResult | GroupResult | PendingResult;
|
|
64
|
+
export type PlanArea = {
|
|
65
|
+
room: string;
|
|
66
|
+
path: string;
|
|
67
|
+
open: readonly string[];
|
|
188
68
|
};
|
|
189
69
|
export type PlanReach = {
|
|
190
70
|
rooms: readonly string[];
|
|
191
71
|
documents: readonly string[];
|
|
72
|
+
areas: readonly PlanArea[];
|
|
192
73
|
};
|
|
193
|
-
export type Plan = {
|
|
194
|
-
rooms: readonly string[] | null;
|
|
74
|
+
export type Plan = QueryPlan & {
|
|
195
75
|
reach: PlanReach | null;
|
|
196
|
-
|
|
197
|
-
hop: (Scope & {
|
|
198
|
-
field: string;
|
|
199
|
-
}) | null;
|
|
200
|
-
backlinks: (Scope & {
|
|
201
|
-
field: string | null;
|
|
202
|
-
}) | null;
|
|
203
|
-
shape: DocumentShape | GroupShape;
|
|
204
|
-
limit: number | null;
|
|
76
|
+
locked: readonly string[];
|
|
205
77
|
};
|
|
206
|
-
export declare
|
|
207
|
-
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
208
|
-
}
|
|
209
|
-
type Entries = Readonly<Record<string, unknown>>;
|
|
210
|
-
export declare function invalid(at: string, problem: string): never;
|
|
211
|
-
export declare function plain(value: unknown): value is Entries;
|
|
212
|
-
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
213
|
-
export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
214
|
-
export declare function limitOf(input: unknown): number | null;
|
|
215
|
-
export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
216
|
-
export declare function identityOf(plan: Plan): string;
|
|
217
|
-
export {};
|
|
78
|
+
export declare function planWithin(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
218
79
|
//# sourceMappingURL=query.d.ts.map
|