@agentshouse/mdruntime 0.1.0-c698c0ebd65bd → 0.1.0-c6dd3e87e3f5e
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 +18 -15
- package/dist/adapter.d.ts +125 -50
- 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/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +27 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +184 -85
- package/dist/chain.d.ts +11 -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 -63
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/client.d.ts +25 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +97 -11
- package/dist/collection.d.ts +10 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +38 -79
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +786 -0
- package/dist/connection.d.ts +44 -17
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3496 -976
- package/dist/conversation.d.ts +33 -14
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +571 -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 +6 -3
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -23
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +370 -0
- package/dist/host.d.ts +12 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +125 -19
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +3 -0
- package/dist/index.d.ts +16 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -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 +14 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +198 -94
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/model.d.ts +9 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -2
- 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 +20 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +113 -12
- 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 +45 -7
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +39 -0
- package/dist/overlay.d.ts +3 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +100 -182
- 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 +66 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +48 -7
- package/dist/reach.d.ts +18 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +220 -73
- package/dist/react.d.ts +8 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/readiness.d.ts +52 -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 +16 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +115 -51
- package/dist/replica.d.ts +55 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +297 -154
- package/dist/room-draft.d.ts +34 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +105 -31
- package/dist/rows.d.ts +37 -37
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +173 -104
- package/dist/save.d.ts +53 -9
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +537 -170
- package/dist/search.d.ts +39 -28
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +37 -105
- 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 +5 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +96 -80
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +306 -523
- package/dist/stored.d.ts +130 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +560 -0
- package/dist/tables.d.ts +325 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +578 -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 +101 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +164 -32
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +55 -31
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +156 -0
- package/package.json +18 -19
- package/AGENTS.md +0 -299
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/context.js +0 -10
- package/dist/chat/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- package/dist/chat/kit.d.ts +0 -60
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -26
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -62
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -21
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -151
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts +0 -57
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -119
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -620
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -80
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -33
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.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 -440
package/dist/room-draft.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { apply, equalValue, frontmatterValue, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sha256 } from './digest.js';
|
|
4
4
|
import { binaryLocalId } from './identity.js';
|
|
5
5
|
import { normalize } from './paths.js';
|
|
6
6
|
export function returnedBy(kind) {
|
|
@@ -90,7 +90,12 @@ export function readParts(value) {
|
|
|
90
90
|
if (!plain(value.move))
|
|
91
91
|
malformed();
|
|
92
92
|
const base = markdownBase(value.move.base);
|
|
93
|
-
|
|
93
|
+
const room = optionalText(value.move.room);
|
|
94
|
+
parts.move = {
|
|
95
|
+
to: text(value.move.to),
|
|
96
|
+
...(room === undefined ? {} : { room }),
|
|
97
|
+
...(base === undefined ? {} : { base }),
|
|
98
|
+
};
|
|
94
99
|
}
|
|
95
100
|
if (value.removal !== undefined) {
|
|
96
101
|
if (!plain(value.removal))
|
|
@@ -103,7 +108,8 @@ export function readParts(value) {
|
|
|
103
108
|
malformed();
|
|
104
109
|
if (Object.keys(value).length > 1)
|
|
105
110
|
throw runtimeError('room-draft-file-exclusive');
|
|
106
|
-
|
|
111
|
+
const base = markdownBase(value.file.base);
|
|
112
|
+
parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
|
|
107
113
|
}
|
|
108
114
|
return parts;
|
|
109
115
|
}
|
|
@@ -120,11 +126,51 @@ function kept(prior, base) {
|
|
|
120
126
|
throw runtimeError('room-draft-base-missing');
|
|
121
127
|
return base;
|
|
122
128
|
}
|
|
129
|
+
function movePart(current, move) {
|
|
130
|
+
return {
|
|
131
|
+
to: move.to,
|
|
132
|
+
...(move.room === undefined ? {} : { room: move.room }),
|
|
133
|
+
base: kept(current, move.base),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
123
136
|
function editsText(parts) {
|
|
124
137
|
return (parts.preamble !== undefined ||
|
|
125
138
|
named(parts.fields).length > 0 ||
|
|
126
139
|
named(parts.sections).length > 0);
|
|
127
140
|
}
|
|
141
|
+
function partNames(parts) {
|
|
142
|
+
const names = [];
|
|
143
|
+
for (const [name, part] of Object.entries(parts)) {
|
|
144
|
+
if (name === 'preamble' || name === 'markdown')
|
|
145
|
+
names.push(name);
|
|
146
|
+
else if ((name === 'fields' || name === 'sections') && plain(part))
|
|
147
|
+
names.push(...Object.keys(part).map((one) => `${name}/${one}`));
|
|
148
|
+
else
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return names.sort().join('\u0000');
|
|
152
|
+
}
|
|
153
|
+
function withBaseOf(prior, part) {
|
|
154
|
+
return plain(part) && plain(prior) && Object.hasOwn(prior, 'base')
|
|
155
|
+
? { ...part, base: prior.base }
|
|
156
|
+
: part;
|
|
157
|
+
}
|
|
158
|
+
export function gatheredParts(earlier, later) {
|
|
159
|
+
if (!plain(earlier) || !plain(later))
|
|
160
|
+
return null;
|
|
161
|
+
const named = partNames(earlier);
|
|
162
|
+
if (named === null || named !== partNames(later))
|
|
163
|
+
return null;
|
|
164
|
+
return Object.fromEntries(Object.entries(later).map(([name, part]) => [
|
|
165
|
+
name,
|
|
166
|
+
name === 'fields' || name === 'sections'
|
|
167
|
+
? Object.fromEntries(Object.entries(part).map(([one, value]) => [
|
|
168
|
+
one,
|
|
169
|
+
withBaseOf(earlier[name][one], value),
|
|
170
|
+
]))
|
|
171
|
+
: withBaseOf(earlier[name], part),
|
|
172
|
+
]));
|
|
173
|
+
}
|
|
128
174
|
export function held(current, parts, file) {
|
|
129
175
|
if (parts.markdown !== undefined && editsText(parts)) {
|
|
130
176
|
throw runtimeError('room-draft-markdown-exclusive');
|
|
@@ -144,9 +190,7 @@ export function held(current, parts, file) {
|
|
|
144
190
|
}
|
|
145
191
|
return {
|
|
146
192
|
file: current.file,
|
|
147
|
-
...(parts.move === undefined
|
|
148
|
-
? {}
|
|
149
|
-
: { move: { to: parts.move.to, base: kept(current.move, parts.move.base) } }),
|
|
193
|
+
...(parts.move === undefined ? {} : { move: movePart(current.move, parts.move) }),
|
|
150
194
|
...(parts.removal === undefined
|
|
151
195
|
? {}
|
|
152
196
|
: { removal: { base: kept(current.removal, parts.removal.base) } }),
|
|
@@ -181,9 +225,8 @@ export function held(current, parts, file) {
|
|
|
181
225
|
}
|
|
182
226
|
if (parts.creation !== undefined)
|
|
183
227
|
next.creation = parts.creation;
|
|
184
|
-
if (parts.move !== undefined)
|
|
185
|
-
next.move =
|
|
186
|
-
}
|
|
228
|
+
if (parts.move !== undefined)
|
|
229
|
+
next.move = movePart(current?.move, parts.move);
|
|
187
230
|
if (parts.removal !== undefined) {
|
|
188
231
|
next.removal = { base: kept(current?.removal, parts.removal.base) };
|
|
189
232
|
}
|
|
@@ -240,29 +283,32 @@ export function underneath(parts, path, visible) {
|
|
|
240
283
|
}
|
|
241
284
|
const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
|
|
242
285
|
export async function heldFile(blob, base) {
|
|
243
|
-
const bytes = await blob.arrayBuffer();
|
|
244
286
|
return {
|
|
245
|
-
blob,
|
|
246
287
|
localId: binaryLocalId(),
|
|
247
|
-
|
|
288
|
+
...(blob instanceof File ? { name: blob.name } : {}),
|
|
289
|
+
byteLength: blob.size,
|
|
248
290
|
mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
|
|
249
|
-
sha256:
|
|
291
|
+
sha256: await sha256(blob),
|
|
250
292
|
base,
|
|
251
293
|
};
|
|
252
294
|
}
|
|
253
295
|
export function binaryBase(visible, path) {
|
|
254
|
-
|
|
296
|
+
const binary = visible?.binaries[path];
|
|
297
|
+
if (binary === undefined)
|
|
298
|
+
return null;
|
|
299
|
+
return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
|
|
255
300
|
}
|
|
256
|
-
export function changedParts(path,
|
|
301
|
+
export function changedParts(path, parts, visible) {
|
|
302
|
+
const report = underneath(parts, path, visible);
|
|
303
|
+
const made = parts.file?.base === null;
|
|
257
304
|
return [
|
|
258
|
-
...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
|
|
259
305
|
...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
|
|
260
306
|
...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
|
|
261
307
|
...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
|
|
262
308
|
...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
|
|
263
309
|
...(report.move === undefined ? [] : [{ path, part: 'move' }]),
|
|
264
310
|
...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
|
|
265
|
-
...(report.file === undefined ? [] : [{ path, part: 'file' }]),
|
|
311
|
+
...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
|
|
266
312
|
];
|
|
267
313
|
}
|
|
268
314
|
function joined(existing, returned) {
|
|
@@ -279,16 +325,15 @@ function frontmatterOf(fields) {
|
|
|
279
325
|
const opened = parse('---\n---\n');
|
|
280
326
|
if (!opened.ok)
|
|
281
327
|
return malformed();
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
function concatenated(markdown, parts) {
|
|
328
|
+
const next = apply(opened.document, fields.map(([name, part]) => ({
|
|
329
|
+
kind: 'field',
|
|
330
|
+
name,
|
|
331
|
+
value: part.value,
|
|
332
|
+
prior: undefined,
|
|
333
|
+
})));
|
|
334
|
+
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
335
|
+
}
|
|
336
|
+
export function partsAfter(markdown, parts) {
|
|
292
337
|
const fields = named(parts.fields);
|
|
293
338
|
const pieces = [
|
|
294
339
|
...(fields.length === 0 ? [] : [frontmatterOf(fields)]),
|
|
@@ -319,7 +364,7 @@ export function returnedInto(existing, returned) {
|
|
|
319
364
|
delete next.fields;
|
|
320
365
|
delete next.sections;
|
|
321
366
|
delete next.preamble;
|
|
322
|
-
const value =
|
|
367
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
|
|
323
368
|
next.markdown = { value, base: whole.base };
|
|
324
369
|
}
|
|
325
370
|
const creation = existing.creation ?? returned.creation;
|
|
@@ -340,6 +385,35 @@ export function moveTarget(move) {
|
|
|
340
385
|
const to = normalize(move.to);
|
|
341
386
|
return to === null || to === '' ? move.to : to;
|
|
342
387
|
}
|
|
388
|
+
export function readSavedParts(named) {
|
|
389
|
+
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts) }));
|
|
390
|
+
if (read.some(({ path }, at) => path === '' ||
|
|
391
|
+
normalize(path) !== path ||
|
|
392
|
+
read.findIndex((one) => one.path === path) !== at)) {
|
|
393
|
+
throw runtimeError('room-draft-malformed');
|
|
394
|
+
}
|
|
395
|
+
return read;
|
|
396
|
+
}
|
|
397
|
+
export function partsChanges(named) {
|
|
398
|
+
const changes = [];
|
|
399
|
+
const preconditions = [];
|
|
400
|
+
for (const { path, parts } of readSavedParts(named)) {
|
|
401
|
+
const parted = held(undefined, parts);
|
|
402
|
+
const made = changesOf(path, parted);
|
|
403
|
+
changes.push(...made.changes);
|
|
404
|
+
preconditions.push(...made.bases);
|
|
405
|
+
for (const change of made.changes) {
|
|
406
|
+
if (change.kind === 'create')
|
|
407
|
+
preconditions.push({ kind: 'absent', path });
|
|
408
|
+
if (change.kind === 'move')
|
|
409
|
+
preconditions.push({ kind: 'absent', path: change.to });
|
|
410
|
+
}
|
|
411
|
+
const revision = parted.markdown?.base ?? parted.move?.base ?? parted.removal?.base;
|
|
412
|
+
if (typeof revision === 'string')
|
|
413
|
+
preconditions.push({ kind: 'revision', path, revision });
|
|
414
|
+
}
|
|
415
|
+
return { changes, preconditions };
|
|
416
|
+
}
|
|
343
417
|
export function changesOf(path, parts) {
|
|
344
418
|
const changes = [];
|
|
345
419
|
const bases = [];
|
|
@@ -370,12 +444,12 @@ export function changesOf(path, parts) {
|
|
|
370
444
|
changes.push({ kind: 'replace', path, content: parts.markdown.value });
|
|
371
445
|
}
|
|
372
446
|
if (parts.file !== undefined && parts.removal === undefined) {
|
|
373
|
-
const { base, ...file } = parts.file;
|
|
447
|
+
const { base, name: _name, ...file } = parts.file;
|
|
374
448
|
const at = parts.move === undefined ? path : moveTarget(parts.move);
|
|
375
449
|
if (base !== null && at !== path)
|
|
376
450
|
changes.push({ kind: 'move', path, to: at });
|
|
377
451
|
changes.push({ kind: 'binary', path: at, ...file });
|
|
378
|
-
if (base === null
|
|
452
|
+
if (base === null)
|
|
379
453
|
bases.push({ kind: 'absent', path: at });
|
|
380
454
|
return { changes, bases };
|
|
381
455
|
}
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { type Document } from '@agentshouse/mdmodel';
|
|
2
|
-
import type { HeadChange } from './adapter.js';
|
|
3
|
-
import type { BinaryFileRecord } from './binary.js';
|
|
4
1
|
import { type Composition } from './collection.js';
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
values: Fields;
|
|
14
|
-
reached: Readonly<Record<string, readonly unknown[]>>;
|
|
15
|
-
directories: readonly string[];
|
|
16
|
-
body: string;
|
|
17
|
-
change: HeadChange | null;
|
|
18
|
-
binary: BinaryFileRecord | null;
|
|
2
|
+
export type ValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'undefined';
|
|
3
|
+
type HeldValue = {
|
|
4
|
+
readonly keys: string;
|
|
5
|
+
readonly places: string;
|
|
6
|
+
readonly item: number;
|
|
7
|
+
readonly kind: ValueKind;
|
|
8
|
+
readonly value: string | number | null;
|
|
9
|
+
readonly size: number | null;
|
|
19
10
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
kind:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
markdown: string;
|
|
11
|
+
type LinkKind = 'field' | 'section' | 'body';
|
|
12
|
+
type HeldLink = {
|
|
13
|
+
readonly kind: LinkKind;
|
|
14
|
+
readonly keys: string;
|
|
15
|
+
readonly places: string;
|
|
16
|
+
readonly target: string;
|
|
17
|
+
readonly field: string;
|
|
28
18
|
};
|
|
29
|
-
export type
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
export type Described = {
|
|
20
|
+
readonly type: string | null;
|
|
21
|
+
readonly declared: string | null;
|
|
22
|
+
readonly queried: boolean;
|
|
23
|
+
readonly folder: string;
|
|
24
|
+
readonly fields: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type Derived = Described & {
|
|
27
|
+
readonly values: readonly HeldValue[];
|
|
28
|
+
readonly links: readonly HeldLink[];
|
|
39
29
|
};
|
|
40
|
-
export type Row = DocumentRow | BodyRow | ReferenceRow;
|
|
41
30
|
export declare function documentKey(room: string, path: string): string;
|
|
42
31
|
export declare function roomOfKey(key: string): string;
|
|
32
|
+
export declare function pathOfKey(key: string): string;
|
|
43
33
|
export declare function markdownPath(path: string): boolean;
|
|
44
|
-
export declare function
|
|
34
|
+
export declare function folderOf(path: string): string;
|
|
35
|
+
export type Reach = 'exact' | 'value' | 'link';
|
|
36
|
+
export type Placed = {
|
|
37
|
+
readonly keys: string;
|
|
38
|
+
readonly places: string;
|
|
39
|
+
readonly glob: boolean;
|
|
40
|
+
};
|
|
41
|
+
export declare function placedOf(pointer: string, reach: Reach): Placed;
|
|
42
|
+
export declare function kindOf(value: unknown): ValueKind;
|
|
43
|
+
export declare function described(path: string, content: string | null): Described;
|
|
44
|
+
export declare function derived(path: string, content: string | null, composition: Composition): Derived;
|
|
45
45
|
export {};
|
|
46
46
|
//# sourceMappingURL=rows.d.ts.map
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAWA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpG,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,KAAK,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7C,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CACrC,CAAC;AAMF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAWD,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/C,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhG,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAuB9D;AAwBD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAMhD;AAiJD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAEzE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAO/F"}
|
package/dist/rows.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ARRAY_INDEX, escapePointer, references, target, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { ARRAY_INDEX, bodyAfterFrontmatter, bodyLinks, escapePointer, parseFrontmatter, references, sectionReferences, target, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { governing } from './collection.js';
|
|
3
3
|
import { definitionOf } from './model.js';
|
|
4
4
|
function keyOf(...parts) {
|
|
@@ -10,6 +10,50 @@ export function documentKey(room, path) {
|
|
|
10
10
|
export function roomOfKey(key) {
|
|
11
11
|
return key.split('\u0000')[1];
|
|
12
12
|
}
|
|
13
|
+
export function pathOfKey(key) {
|
|
14
|
+
return key.split('\u0000')[2];
|
|
15
|
+
}
|
|
16
|
+
export function markdownPath(path) {
|
|
17
|
+
return path.endsWith('.md');
|
|
18
|
+
}
|
|
19
|
+
export function folderOf(path) {
|
|
20
|
+
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
21
|
+
}
|
|
22
|
+
export function placedOf(pointer, reach) {
|
|
23
|
+
const [first = '', ...rest] = pointer.split('/').slice(1);
|
|
24
|
+
const keys = [first];
|
|
25
|
+
const gaps = [[]];
|
|
26
|
+
for (const segment of rest) {
|
|
27
|
+
if (ARRAY_INDEX.test(segment)) {
|
|
28
|
+
gaps.at(-1).push(segment);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
keys.push(segment);
|
|
32
|
+
gaps.push([]);
|
|
33
|
+
}
|
|
34
|
+
const places = gaps
|
|
35
|
+
.map((gap, at) => {
|
|
36
|
+
const open = at < gaps.length - 1 ? reach !== 'exact' : reach === 'link';
|
|
37
|
+
return `/${gap.map((number) => `[.:]${number}`).join('')}.${open ? '*' : ''}`;
|
|
38
|
+
})
|
|
39
|
+
.join('');
|
|
40
|
+
return {
|
|
41
|
+
keys: keys.map((key) => `/${key}`).join(''),
|
|
42
|
+
places,
|
|
43
|
+
glob: /[[*]/u.test(places),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function placesOf({ done, head, tail }) {
|
|
47
|
+
return `${done}/${head}${tail}.`;
|
|
48
|
+
}
|
|
49
|
+
function throughOf(keys, places) {
|
|
50
|
+
const gaps = places.split('/').slice(1);
|
|
51
|
+
return keys
|
|
52
|
+
.split('/')
|
|
53
|
+
.slice(1)
|
|
54
|
+
.map((key, at) => `/${key}${gaps[at].replace(/\.\d*/gu, '').replaceAll(':', '/')}`)
|
|
55
|
+
.join('');
|
|
56
|
+
}
|
|
13
57
|
function plainObject(value) {
|
|
14
58
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
59
|
}
|
|
@@ -18,128 +62,153 @@ function compared(reading, exact, value) {
|
|
|
18
62
|
return value;
|
|
19
63
|
return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
|
|
20
64
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
65
|
+
export function kindOf(value) {
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return 'undefined';
|
|
68
|
+
if (value === null)
|
|
69
|
+
return 'null';
|
|
70
|
+
if (Array.isArray(value))
|
|
71
|
+
return 'array';
|
|
72
|
+
if (typeof value === 'object')
|
|
73
|
+
return 'object';
|
|
74
|
+
return typeof value;
|
|
75
|
+
}
|
|
76
|
+
function scalarOf(value) {
|
|
77
|
+
if (typeof value === 'string' || typeof value === 'number')
|
|
78
|
+
return value;
|
|
79
|
+
if (typeof value === 'boolean')
|
|
80
|
+
return value ? 1 : 0;
|
|
81
|
+
if (Array.isArray(value))
|
|
82
|
+
return JSON.stringify(value);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
function held(reading, keys, places, value) {
|
|
86
|
+
reading.values.push({
|
|
87
|
+
keys,
|
|
88
|
+
places,
|
|
89
|
+
item: -1,
|
|
90
|
+
kind: kindOf(value),
|
|
91
|
+
value: scalarOf(value),
|
|
92
|
+
size: Array.isArray(value) ? value.length : null,
|
|
93
|
+
});
|
|
94
|
+
if (!Array.isArray(value))
|
|
34
95
|
return;
|
|
35
|
-
|
|
36
|
-
|
|
96
|
+
value.forEach((item, index) => {
|
|
97
|
+
const itemKind = kindOf(item);
|
|
98
|
+
reading.values.push({
|
|
99
|
+
keys,
|
|
100
|
+
places,
|
|
101
|
+
item: index,
|
|
102
|
+
kind: itemKind,
|
|
103
|
+
value: itemKind === 'array' ? null : scalarOf(item),
|
|
104
|
+
size: null,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function record(reading, node, at) {
|
|
109
|
+
const value = Array.isArray(node)
|
|
110
|
+
? node.map((item, index) => compared(reading, `${at.exact}/${index}`, item))
|
|
111
|
+
: compared(reading, at.exact, node);
|
|
112
|
+
const places = placesOf(at);
|
|
113
|
+
held(reading, at.keys, places, value);
|
|
114
|
+
if (typeof value !== 'string' || !reading.references.has(at.exact))
|
|
37
115
|
return;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
record(reading, node, forms, exact);
|
|
116
|
+
reading.links.push({
|
|
117
|
+
kind: 'field',
|
|
118
|
+
keys: at.keys,
|
|
119
|
+
places,
|
|
120
|
+
target: value,
|
|
121
|
+
field: throughOf(at.keys, places),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function walk(reading, node, at) {
|
|
125
|
+
record(reading, node, at);
|
|
49
126
|
if (Array.isArray(node)) {
|
|
50
|
-
node.forEach((item, index) => walk(reading, item,
|
|
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}`));
|
|
127
|
+
node.forEach((item, index) => walk(reading, item, { ...at, tail: `${at.tail}.${index}`, exact: `${at.exact}/${index}` }));
|
|
56
128
|
return;
|
|
57
129
|
}
|
|
58
130
|
if (!plainObject(node))
|
|
59
131
|
return;
|
|
60
132
|
for (const [key, value] of Object.entries(node)) {
|
|
61
133
|
const segment = escapePointer(key);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
134
|
+
const exact = `${at.exact}/${segment}`;
|
|
135
|
+
walk(reading, value, ARRAY_INDEX.test(segment)
|
|
136
|
+
? { ...at, head: `${at.head}${at.tail.replaceAll('.', ':')}:${segment}`, tail: '', exact }
|
|
137
|
+
: { keys: `${at.keys}/${segment}`, done: placesOf(at), head: '', tail: '', exact });
|
|
65
138
|
}
|
|
66
139
|
}
|
|
67
|
-
function
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const key = documentKey(room, path);
|
|
76
|
-
const body = keyOf('b', room, path);
|
|
77
|
-
if (document === null || !markdownPath(path)) {
|
|
78
|
-
return [
|
|
79
|
-
{
|
|
80
|
-
key,
|
|
81
|
-
kind: 'document',
|
|
82
|
-
room,
|
|
83
|
-
path,
|
|
84
|
-
type: null,
|
|
85
|
-
fields: {},
|
|
86
|
-
values: {},
|
|
87
|
-
reached: {},
|
|
88
|
-
directories: directoriesOf(path),
|
|
89
|
-
body,
|
|
90
|
-
change,
|
|
91
|
-
binary,
|
|
92
|
-
},
|
|
93
|
-
];
|
|
140
|
+
function bodyTargets(path, content) {
|
|
141
|
+
const seen = new Set();
|
|
142
|
+
const found = [];
|
|
143
|
+
for (const { target: reached } of bodyLinks(bodyAfterFrontmatter(content), path)) {
|
|
144
|
+
if (seen.has(reached))
|
|
145
|
+
continue;
|
|
146
|
+
seen.add(reached);
|
|
147
|
+
found.push({ kind: 'body', keys: '', places: '', target: reached, field: '' });
|
|
94
148
|
}
|
|
95
|
-
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
function typedRows(path, content, document, composition) {
|
|
96
152
|
const definition = definitionOf(governing(composition, path), document.type);
|
|
97
153
|
const reading = {
|
|
98
154
|
path,
|
|
99
155
|
references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
|
|
100
|
-
values:
|
|
101
|
-
|
|
102
|
-
targets: new Map(),
|
|
156
|
+
values: [],
|
|
157
|
+
links: [],
|
|
103
158
|
};
|
|
104
159
|
for (const [name, value] of Object.entries(document.fields)) {
|
|
105
160
|
const segment = escapePointer(name);
|
|
106
|
-
walk(reading, value,
|
|
161
|
+
walk(reading, value, {
|
|
162
|
+
keys: `/${segment}`,
|
|
163
|
+
done: '',
|
|
164
|
+
head: '',
|
|
165
|
+
tail: '',
|
|
166
|
+
exact: `/${segment}`,
|
|
167
|
+
});
|
|
107
168
|
}
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
169
|
+
const links = reading.links;
|
|
170
|
+
if (definition !== undefined) {
|
|
171
|
+
const sectioned = new Set();
|
|
172
|
+
for (const { target: reached } of sectionReferences(path, content, definition)) {
|
|
173
|
+
if (reached === null || sectioned.has(reached))
|
|
174
|
+
continue;
|
|
175
|
+
sectioned.add(reached);
|
|
176
|
+
links.push({ kind: 'section', keys: '', places: '', target: reached, field: '' });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { values: reading.values, links: [...links, ...bodyTargets(path, content)] };
|
|
180
|
+
}
|
|
181
|
+
function read(path, content) {
|
|
182
|
+
const folder = folderOf(path);
|
|
183
|
+
const unread = { fields: null, folder, type: null };
|
|
184
|
+
if (content === null) {
|
|
185
|
+
return { described: { ...unread, declared: null, queried: true }, document: null };
|
|
186
|
+
}
|
|
187
|
+
const parsed = parseFrontmatter(content, path);
|
|
188
|
+
const declared = parsed.ok ? (parsed.frontmatter.type ?? 'any') : null;
|
|
189
|
+
if (!markdownPath(path) || !parsed.ok) {
|
|
190
|
+
return { described: { ...unread, declared, queried: !markdownPath(path) }, document: null };
|
|
191
|
+
}
|
|
192
|
+
const document = parsed.frontmatter;
|
|
193
|
+
return {
|
|
194
|
+
described: {
|
|
195
|
+
type: document.type ?? 'any',
|
|
196
|
+
declared,
|
|
197
|
+
queried: true,
|
|
198
|
+
folder,
|
|
199
|
+
fields: JSON.stringify(document.fields),
|
|
132
200
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
];
|
|
201
|
+
document,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export function described(path, content) {
|
|
205
|
+
return read(path, content).described;
|
|
206
|
+
}
|
|
207
|
+
export function derived(path, content, composition) {
|
|
208
|
+
const { described: columns, document } = read(path, content);
|
|
209
|
+
if (document !== null) {
|
|
210
|
+
return { ...columns, ...typedRows(path, content, document, composition) };
|
|
211
|
+
}
|
|
212
|
+
const links = content === null || markdownPath(path) ? [] : bodyTargets(path, content);
|
|
213
|
+
return { ...columns, values: [], links };
|
|
145
214
|
}
|