@agentshouse/mdruntime 0.1.0-ccbb89b0ca151 → 0.1.0-ccc0e3407f107
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 +1 -1
- package/dist/adapter.d.ts +74 -57
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +29 -47
- package/dist/bootstrap.d.ts +11 -18
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +85 -108
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/collection.d.ts +7 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -17
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +91 -270
- package/dist/connection.d.ts +10 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1009 -1063
- 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 +16 -13
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +229 -155
- package/dist/durability.d.ts +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -8
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +22 -27
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- 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 +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +10 -7
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +27 -4
- package/dist/memory.d.ts +11 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +167 -84
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +8 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -12
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +8 -3
- package/dist/outcome.d.ts +0 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -1
- 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 +4 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/reach.d.ts +9 -8
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +37 -48
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +3 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +29 -5
- package/dist/replica.d.ts +10 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +29 -14
- package/dist/room-draft.d.ts +21 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +98 -51
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +48 -184
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +20 -12
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +4 -3
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +21 -34
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +34 -77
- package/dist/stored.d.ts +11 -34
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +158 -241
- package/dist/tables.d.ts +23 -48
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +29 -66
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +42 -100
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +9 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -1
- package/package.json +2 -2
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -100
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/replica.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
3
|
import { collectionOf } from './collection.js';
|
|
4
|
+
import { storedModel } from './model.js';
|
|
4
5
|
import { acceptedBinaries, overlaying } from './overlay.js';
|
|
6
|
+
import { writtenFacts } from './rows.js';
|
|
5
7
|
import { effectiveIn, rewriting } from './save.js';
|
|
6
8
|
import { ROW_WEIGHT } from './turn.js';
|
|
7
|
-
export function compositionOf(record, builtIn) {
|
|
9
|
+
export function compositionOf(record, builtIn, typedPaths) {
|
|
8
10
|
return {
|
|
9
11
|
model: record.model,
|
|
10
12
|
selection: record.typedSelection === null
|
|
11
13
|
? null
|
|
12
14
|
: { roots: record.typedSelection.roots, model: builtIn },
|
|
15
|
+
typedPaths,
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
|
-
export function sameMembership(record, other) {
|
|
16
|
-
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
17
|
-
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
18
|
-
}
|
|
19
18
|
export function storedRecord(record) {
|
|
20
19
|
const { key: _key, ...stored } = record;
|
|
21
|
-
return JSON.stringify(stored);
|
|
20
|
+
return JSON.stringify({ ...stored, model: storedModel(stored.model) });
|
|
22
21
|
}
|
|
23
22
|
const PROBES = new Set([
|
|
24
23
|
'then',
|
|
@@ -63,7 +62,10 @@ export function* slicing(entries, paths) {
|
|
|
63
62
|
const fileIds = {};
|
|
64
63
|
const changes = {};
|
|
65
64
|
const written = {};
|
|
65
|
+
const facts = {};
|
|
66
66
|
for (const entry of entries) {
|
|
67
|
+
if (entry.facts !== null)
|
|
68
|
+
facts[entry.path] = entry.facts;
|
|
67
69
|
if (entry.binary !== null)
|
|
68
70
|
binaries[entry.path] = entry.binary;
|
|
69
71
|
else if (entry.content !== null)
|
|
@@ -85,6 +87,7 @@ export function* slicing(entries, paths) {
|
|
|
85
87
|
fileIds: strict(fileIds, held),
|
|
86
88
|
changes: strict(changes, held),
|
|
87
89
|
written: strict(written, held),
|
|
90
|
+
facts: strict(facts, held),
|
|
88
91
|
held,
|
|
89
92
|
};
|
|
90
93
|
}
|
|
@@ -107,8 +110,9 @@ export function* slicingWith(slice, set, removed) {
|
|
|
107
110
|
const entries = new Map();
|
|
108
111
|
for (const path of slice.held) {
|
|
109
112
|
const entry = entryAt(slice, path);
|
|
110
|
-
if (entry !== null)
|
|
111
|
-
entries.set(path, { ...entry, type: null });
|
|
113
|
+
if (entry !== null) {
|
|
114
|
+
entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
|
|
115
|
+
}
|
|
112
116
|
yield ROW_WEIGHT;
|
|
113
117
|
}
|
|
114
118
|
for (const path of removed)
|
|
@@ -172,8 +176,9 @@ export function* replaying(confirmed, queue, locator, composition) {
|
|
|
172
176
|
export function* overlayOf(visible, touched) {
|
|
173
177
|
const rows = [];
|
|
174
178
|
for (const path of touched) {
|
|
175
|
-
yield ROW_WEIGHT;
|
|
176
179
|
const entry = entryAt(visible, path);
|
|
180
|
+
yield ROW_WEIGHT + (entry?.content?.length ?? 0);
|
|
181
|
+
const text = entry?.binary === null ? entry.content : null;
|
|
177
182
|
rows.push(entry === null
|
|
178
183
|
? {
|
|
179
184
|
path,
|
|
@@ -184,8 +189,14 @@ export function* overlayOf(visible, touched) {
|
|
|
184
189
|
fileId: null,
|
|
185
190
|
change: null,
|
|
186
191
|
written: null,
|
|
192
|
+
facts: null,
|
|
187
193
|
}
|
|
188
|
-
: {
|
|
194
|
+
: {
|
|
195
|
+
...entry,
|
|
196
|
+
written: null,
|
|
197
|
+
present: true,
|
|
198
|
+
facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
|
|
199
|
+
});
|
|
189
200
|
}
|
|
190
201
|
return rows;
|
|
191
202
|
}
|
|
@@ -350,17 +361,19 @@ export function returnedPaths(submitted, accepted) {
|
|
|
350
361
|
}
|
|
351
362
|
return paths;
|
|
352
363
|
}
|
|
353
|
-
export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
364
|
+
export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
|
|
354
365
|
const documents = new Map();
|
|
355
366
|
const binaries = new Map();
|
|
356
367
|
const revisions = new Map();
|
|
357
368
|
const fileIds = new Map();
|
|
358
369
|
const changes = new Map();
|
|
359
370
|
const written = new Map();
|
|
371
|
+
const facts = new Map();
|
|
360
372
|
const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
|
|
361
373
|
for (const [path, content] of Object.entries(accepted.documents)) {
|
|
362
|
-
yield ROW_WEIGHT;
|
|
374
|
+
yield ROW_WEIGHT + content.length;
|
|
363
375
|
documents.set(path, content);
|
|
376
|
+
facts.set(path, writtenFacts(path, content, composition));
|
|
364
377
|
fileIds.set(path, undefined);
|
|
365
378
|
written.set(path, writtenAt);
|
|
366
379
|
}
|
|
@@ -412,16 +425,18 @@ export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
|
412
425
|
const set = [];
|
|
413
426
|
const removed = [];
|
|
414
427
|
for (const path of paths) {
|
|
415
|
-
yield ROW_WEIGHT;
|
|
416
428
|
const content = read(documents, confirmed.documents, path);
|
|
417
429
|
const binary = read(binaries, confirmed.binaries, path);
|
|
430
|
+
yield ROW_WEIGHT;
|
|
418
431
|
if (content === undefined && binary === undefined) {
|
|
419
432
|
removed.push(path);
|
|
420
433
|
continue;
|
|
421
434
|
}
|
|
435
|
+
const text = binary === undefined ? (content ?? null) : null;
|
|
422
436
|
set.push({
|
|
423
437
|
path,
|
|
424
|
-
content:
|
|
438
|
+
content: text,
|
|
439
|
+
facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
|
|
425
440
|
binary: binary ?? null,
|
|
426
441
|
revision: read(revisions, confirmed.revisions, path) ?? null,
|
|
427
442
|
fileId: read(fileIds, confirmed.fileIds, path) ?? null,
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export type RoomDraftParts = {
|
|
|
40
40
|
};
|
|
41
41
|
readonly file?: {
|
|
42
42
|
readonly blob: Blob;
|
|
43
|
+
readonly base?: string | null;
|
|
43
44
|
};
|
|
44
45
|
};
|
|
45
46
|
export type HeldFile = {
|
|
@@ -89,9 +90,9 @@ type ChangedUnderneath = {
|
|
|
89
90
|
readonly file?: string | null;
|
|
90
91
|
};
|
|
91
92
|
export type ReturnReason = ProviderRefusal & {
|
|
92
|
-
readonly kind: Open<'conflicted' | 'rejected' | '
|
|
93
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
|
|
93
94
|
};
|
|
94
|
-
export declare function returnedBy(kind: '
|
|
95
|
+
export declare function returnedBy(kind: 'withdrawn'): ReturnReason;
|
|
95
96
|
export type RoomDraft = {
|
|
96
97
|
readonly room: string;
|
|
97
98
|
readonly path: string;
|
|
@@ -112,7 +113,7 @@ export type RoomDraftWrite = {
|
|
|
112
113
|
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
113
114
|
export type ChangedPart = {
|
|
114
115
|
readonly path: string;
|
|
115
|
-
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | '
|
|
116
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
|
|
116
117
|
readonly name?: string;
|
|
117
118
|
};
|
|
118
119
|
export type RoomDraftRecord = {
|
|
@@ -126,13 +127,14 @@ export type SavedDraft = {
|
|
|
126
127
|
readonly path: string;
|
|
127
128
|
readonly parts: HeldParts;
|
|
128
129
|
};
|
|
129
|
-
export declare function readParts(value: unknown): RoomDraftParts;
|
|
130
|
+
export declare function readParts(value: unknown, path: string): RoomDraftParts;
|
|
130
131
|
export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
|
|
131
132
|
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
132
133
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
133
134
|
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
134
135
|
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
135
|
-
export declare function changedParts(path: string,
|
|
136
|
+
export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
|
|
137
|
+
export declare function lineEnded(text: string): string;
|
|
136
138
|
export type TextParts = {
|
|
137
139
|
readonly fields?: Readonly<Record<string, {
|
|
138
140
|
readonly value: unknown;
|
|
@@ -149,6 +151,20 @@ export declare function returnedInto(existing: HeldParts | undefined, returned:
|
|
|
149
151
|
export declare function moveTarget(move: {
|
|
150
152
|
readonly to: string;
|
|
151
153
|
}): string;
|
|
154
|
+
export declare function readSavedParts(named: readonly {
|
|
155
|
+
readonly path: string;
|
|
156
|
+
readonly parts: unknown;
|
|
157
|
+
}[]): readonly {
|
|
158
|
+
readonly path: string;
|
|
159
|
+
readonly parts: RoomDraftParts;
|
|
160
|
+
}[];
|
|
161
|
+
export declare function partsChanges(named: readonly {
|
|
162
|
+
readonly path: string;
|
|
163
|
+
readonly parts: unknown;
|
|
164
|
+
}[]): {
|
|
165
|
+
readonly changes: readonly Change[];
|
|
166
|
+
readonly preconditions: readonly Precondition[];
|
|
167
|
+
};
|
|
152
168
|
export declare function changesOf(path: string, parts: HeldParts): {
|
|
153
169
|
changes: readonly Change[];
|
|
154
170
|
bases: readonly Precondition[];
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,GACD;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;A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AED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,GACnE;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,CAgB1F;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,GACf;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,CA2ChE;AAkBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAkBzF;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,UAAU,EAAE,CAqBvB"}
|
package/dist/room-draft.js
CHANGED
|
@@ -9,52 +9,60 @@ export function returnedBy(kind) {
|
|
|
9
9
|
export function staleWrite(current) {
|
|
10
10
|
return { outcome: 'stale', code: 'stale', retryable: false, current };
|
|
11
11
|
}
|
|
12
|
-
function malformed() {
|
|
13
|
-
throw runtimeError('room-draft-malformed');
|
|
12
|
+
function malformed(at, needs) {
|
|
13
|
+
throw runtimeError('room-draft-malformed', at === undefined ? 'room-draft-malformed' : `room-draft-malformed at ${at}: ${needs}`);
|
|
14
14
|
}
|
|
15
15
|
function plain(value) {
|
|
16
16
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
17
|
}
|
|
18
|
-
function text(value) {
|
|
19
|
-
return typeof value === 'string' ? value : malformed();
|
|
18
|
+
function text(value, at) {
|
|
19
|
+
return typeof value === 'string' ? value : malformed(at, 'text');
|
|
20
20
|
}
|
|
21
|
-
function optionalText(value) {
|
|
22
|
-
return value === undefined ? undefined : text(value);
|
|
21
|
+
function optionalText(value, at) {
|
|
22
|
+
return value === undefined ? undefined : text(value, at);
|
|
23
23
|
}
|
|
24
|
-
function markdownBase(value) {
|
|
25
|
-
return value === null ? null : optionalText(value);
|
|
24
|
+
function markdownBase(value, at) {
|
|
25
|
+
return value === null ? null : optionalText(value, at);
|
|
26
26
|
}
|
|
27
|
-
function entries(value, each) {
|
|
27
|
+
function entries(value, at, each) {
|
|
28
28
|
if (!plain(value))
|
|
29
|
-
malformed();
|
|
29
|
+
malformed(at, 'an object of named values');
|
|
30
30
|
const read = {};
|
|
31
31
|
for (const [name, item] of Object.entries(value))
|
|
32
|
-
read[name] = each(item);
|
|
32
|
+
read[name] = each(item, `${at}.${name}`);
|
|
33
33
|
return read;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function frontmatter(item, at) {
|
|
36
|
+
return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
|
|
37
|
+
}
|
|
38
|
+
function fieldValue(value, at) {
|
|
36
39
|
if (value === null)
|
|
37
40
|
return null;
|
|
38
41
|
if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
|
|
39
|
-
malformed();
|
|
42
|
+
malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
|
|
40
43
|
}
|
|
41
44
|
return { value: value.value };
|
|
42
45
|
}
|
|
43
|
-
function textPart(value) {
|
|
46
|
+
function textPart(value, at) {
|
|
44
47
|
if (!plain(value))
|
|
45
|
-
malformed();
|
|
46
|
-
const base = optionalText(value.base);
|
|
47
|
-
return { value: text(value.value), ...(base === undefined ? {} : { base }) };
|
|
48
|
+
malformed(at, '{ value, base }');
|
|
49
|
+
const base = optionalText(value.base, `${at}.base`);
|
|
50
|
+
return { value: text(value.value, `${at}.value`), ...(base === undefined ? {} : { base }) };
|
|
48
51
|
}
|
|
49
|
-
function creationOf(value) {
|
|
52
|
+
function creationOf(value, at) {
|
|
50
53
|
if (!plain(value))
|
|
51
|
-
malformed();
|
|
54
|
+
malformed(at, '{ type, fields, sections }, or { markdown }');
|
|
52
55
|
if (Object.hasOwn(value, 'markdown'))
|
|
53
|
-
return { markdown: text(value.markdown) };
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
return { markdown: text(value.markdown, `${at}.markdown`) };
|
|
57
|
+
if (typeof value.type !== 'string')
|
|
58
|
+
malformed(`${at}.type`, 'a type name, or markdown in place of type, fields and sections');
|
|
59
|
+
return {
|
|
60
|
+
type: value.type,
|
|
61
|
+
fields: entries(value.fields, `${at}.fields`, frontmatter),
|
|
62
|
+
sections: entries(value.sections, `${at}.sections`, text),
|
|
63
|
+
};
|
|
56
64
|
}
|
|
57
|
-
const PART_NAMES =
|
|
65
|
+
const PART_NAMES = [
|
|
58
66
|
'fields',
|
|
59
67
|
'sections',
|
|
60
68
|
'preamble',
|
|
@@ -63,52 +71,57 @@ const PART_NAMES = new Set([
|
|
|
63
71
|
'move',
|
|
64
72
|
'removal',
|
|
65
73
|
'file',
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
];
|
|
75
|
+
const NAMED_PARTS = `a part named ${PART_NAMES.slice(0, -1).join(', ')} or ${PART_NAMES.at(-1)}`;
|
|
76
|
+
export function readParts(value, path) {
|
|
77
|
+
if (!plain(value))
|
|
78
|
+
malformed(path, 'an object of parts');
|
|
79
|
+
const unknown = Object.keys(value).find((name) => !PART_NAMES.includes(name));
|
|
80
|
+
if (unknown !== undefined)
|
|
81
|
+
malformed(`${path} ${unknown}`, NAMED_PARTS);
|
|
70
82
|
const parts = {};
|
|
71
83
|
if (value.fields !== undefined) {
|
|
72
|
-
parts.fields = entries(value.fields, (item) => {
|
|
84
|
+
parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
|
|
73
85
|
if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
|
|
74
|
-
malformed();
|
|
86
|
+
malformed(at, '{ value, base } with a frontmatter value');
|
|
75
87
|
}
|
|
76
88
|
return item.base === undefined
|
|
77
89
|
? { value: item.value }
|
|
78
|
-
: { value: item.value, base: fieldValue(item.base) };
|
|
90
|
+
: { value: item.value, base: fieldValue(item.base, `${at}.base`) };
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
93
|
if (value.sections !== undefined)
|
|
82
|
-
parts.sections = entries(value.sections, textPart);
|
|
94
|
+
parts.sections = entries(value.sections, `${path} sections`, textPart);
|
|
83
95
|
if (value.preamble !== undefined)
|
|
84
|
-
parts.preamble = textPart(value.preamble);
|
|
96
|
+
parts.preamble = textPart(value.preamble, `${path} preamble`);
|
|
85
97
|
if (value.markdown !== undefined)
|
|
86
|
-
parts.markdown = textPart(value.markdown);
|
|
98
|
+
parts.markdown = textPart(value.markdown, `${path} markdown`);
|
|
87
99
|
if (value.creation !== undefined)
|
|
88
|
-
parts.creation = creationOf(value.creation);
|
|
100
|
+
parts.creation = creationOf(value.creation, `${path} creation`);
|
|
89
101
|
if (value.move !== undefined) {
|
|
90
102
|
if (!plain(value.move))
|
|
91
|
-
malformed();
|
|
92
|
-
const base = markdownBase(value.move.base);
|
|
93
|
-
const room = optionalText(value.move.room);
|
|
103
|
+
malformed(`${path} move`, '{ to, room, base }');
|
|
104
|
+
const base = markdownBase(value.move.base, `${path} move.base`);
|
|
105
|
+
const room = optionalText(value.move.room, `${path} move.room`);
|
|
94
106
|
parts.move = {
|
|
95
|
-
to: text(value.move.to),
|
|
107
|
+
to: text(value.move.to, `${path} move.to`),
|
|
96
108
|
...(room === undefined ? {} : { room }),
|
|
97
109
|
...(base === undefined ? {} : { base }),
|
|
98
110
|
};
|
|
99
111
|
}
|
|
100
112
|
if (value.removal !== undefined) {
|
|
101
113
|
if (!plain(value.removal))
|
|
102
|
-
malformed();
|
|
103
|
-
const base = markdownBase(value.removal.base);
|
|
114
|
+
malformed(`${path} removal`, '{ base }');
|
|
115
|
+
const base = markdownBase(value.removal.base, `${path} removal.base`);
|
|
104
116
|
parts.removal = base === undefined ? {} : { base };
|
|
105
117
|
}
|
|
106
118
|
if (value.file !== undefined) {
|
|
107
119
|
if (!plain(value.file) || !(value.file.blob instanceof Blob))
|
|
108
|
-
malformed();
|
|
120
|
+
malformed(`${path} file`, '{ blob, base } with a Blob');
|
|
109
121
|
if (Object.keys(value).length > 1)
|
|
110
122
|
throw runtimeError('room-draft-file-exclusive');
|
|
111
|
-
|
|
123
|
+
const base = markdownBase(value.file.base, `${path} file.base`);
|
|
124
|
+
parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
|
|
112
125
|
}
|
|
113
126
|
return parts;
|
|
114
127
|
}
|
|
@@ -292,18 +305,22 @@ export async function heldFile(blob, base) {
|
|
|
292
305
|
};
|
|
293
306
|
}
|
|
294
307
|
export function binaryBase(visible, path) {
|
|
295
|
-
|
|
308
|
+
const binary = visible?.binaries[path];
|
|
309
|
+
if (binary === undefined)
|
|
310
|
+
return null;
|
|
311
|
+
return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
|
|
296
312
|
}
|
|
297
|
-
export function changedParts(path,
|
|
313
|
+
export function changedParts(path, parts, visible) {
|
|
314
|
+
const report = underneath(parts, path, visible);
|
|
315
|
+
const made = parts.file?.base === null;
|
|
298
316
|
return [
|
|
299
|
-
...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
|
|
300
317
|
...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
|
|
301
318
|
...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
|
|
302
319
|
...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
|
|
303
320
|
...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
|
|
304
321
|
...(report.move === undefined ? [] : [{ path, part: 'move' }]),
|
|
305
322
|
...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
|
|
306
|
-
...(report.file === undefined ? [] : [{ path, part: 'file' }]),
|
|
323
|
+
...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
|
|
307
324
|
];
|
|
308
325
|
}
|
|
309
326
|
function joined(existing, returned) {
|
|
@@ -313,7 +330,7 @@ function joined(existing, returned) {
|
|
|
313
330
|
merged[name] = part;
|
|
314
331
|
return Object.keys(merged).length === 0 ? undefined : merged;
|
|
315
332
|
}
|
|
316
|
-
function
|
|
333
|
+
export function lineEnded(text) {
|
|
317
334
|
return text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
318
335
|
}
|
|
319
336
|
function frontmatterOf(fields) {
|
|
@@ -337,7 +354,7 @@ export function partsAfter(markdown, parts) {
|
|
|
337
354
|
];
|
|
338
355
|
if (pieces.length === 0)
|
|
339
356
|
return markdown;
|
|
340
|
-
return `${
|
|
357
|
+
return `${lineEnded(markdown)}\n${pieces.map(lineEnded).join('')}`;
|
|
341
358
|
}
|
|
342
359
|
export function returnedInto(existing, returned) {
|
|
343
360
|
if (existing === undefined)
|
|
@@ -380,6 +397,36 @@ export function moveTarget(move) {
|
|
|
380
397
|
const to = normalize(move.to);
|
|
381
398
|
return to === null || to === '' ? move.to : to;
|
|
382
399
|
}
|
|
400
|
+
export function readSavedParts(named) {
|
|
401
|
+
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts, path) }));
|
|
402
|
+
read.forEach(({ path }, at) => {
|
|
403
|
+
if (path === '' || normalize(path) !== path)
|
|
404
|
+
malformed(path, 'a path inside the Room, such as notes/a.md');
|
|
405
|
+
if (read.findIndex((one) => one.path === path) !== at)
|
|
406
|
+
malformed(path, 'each path once in one save');
|
|
407
|
+
});
|
|
408
|
+
return read;
|
|
409
|
+
}
|
|
410
|
+
export function partsChanges(named) {
|
|
411
|
+
const changes = [];
|
|
412
|
+
const preconditions = [];
|
|
413
|
+
for (const { path, parts } of readSavedParts(named)) {
|
|
414
|
+
const parted = held(undefined, parts);
|
|
415
|
+
const made = changesOf(path, parted);
|
|
416
|
+
changes.push(...made.changes);
|
|
417
|
+
preconditions.push(...made.bases);
|
|
418
|
+
for (const change of made.changes) {
|
|
419
|
+
if (change.kind === 'create')
|
|
420
|
+
preconditions.push({ kind: 'absent', path });
|
|
421
|
+
if (change.kind === 'move')
|
|
422
|
+
preconditions.push({ kind: 'absent', path: change.to });
|
|
423
|
+
}
|
|
424
|
+
const revision = parted.markdown?.base ?? parted.move?.base ?? parted.removal?.base;
|
|
425
|
+
if (typeof revision === 'string')
|
|
426
|
+
preconditions.push({ kind: 'revision', path, revision });
|
|
427
|
+
}
|
|
428
|
+
return { changes, preconditions };
|
|
429
|
+
}
|
|
383
430
|
export function changesOf(path, parts) {
|
|
384
431
|
const changes = [];
|
|
385
432
|
const bases = [];
|
|
@@ -399,11 +446,11 @@ export function changesOf(path, parts) {
|
|
|
399
446
|
bases.push({ kind: 'field', path, name, value: part.base?.value });
|
|
400
447
|
}
|
|
401
448
|
for (const [name, part] of named(parts.sections)) {
|
|
402
|
-
changes.push({ kind: 'section', path, name, value: part.value });
|
|
449
|
+
changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
|
|
403
450
|
bases.push({ kind: 'section', path, name, value: part.base });
|
|
404
451
|
}
|
|
405
452
|
if (parts.preamble !== undefined) {
|
|
406
|
-
changes.push({ kind: 'preamble', path, value: parts.preamble.value });
|
|
453
|
+
changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
|
|
407
454
|
bases.push({ kind: 'preamble', path, value: parts.preamble.base });
|
|
408
455
|
}
|
|
409
456
|
if (parts.markdown !== undefined) {
|
|
@@ -415,7 +462,7 @@ export function changesOf(path, parts) {
|
|
|
415
462
|
if (base !== null && at !== path)
|
|
416
463
|
changes.push({ kind: 'move', path, to: at });
|
|
417
464
|
changes.push({ kind: 'binary', path: at, ...file });
|
|
418
|
-
if (base === null
|
|
465
|
+
if (base === null)
|
|
419
466
|
bases.push({ kind: 'absent', path: at });
|
|
420
467
|
return { changes, bases };
|
|
421
468
|
}
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import { type HeldValue } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { SavedFacts } from './adapter.js';
|
|
1
3
|
import { type Composition } from './collection.js';
|
|
2
|
-
|
|
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;
|
|
10
|
-
};
|
|
11
|
-
type LinkKind = 'field' | 'section' | 'body';
|
|
4
|
+
type LinkKind = 'field' | 'link';
|
|
12
5
|
type HeldLink = {
|
|
13
6
|
readonly kind: LinkKind;
|
|
14
7
|
readonly keys: string;
|
|
@@ -22,8 +15,14 @@ export type Described = {
|
|
|
22
15
|
readonly queried: boolean;
|
|
23
16
|
readonly folder: string;
|
|
24
17
|
readonly fields: string | null;
|
|
18
|
+
readonly links: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type Held = {
|
|
21
|
+
readonly type: string | null;
|
|
22
|
+
readonly fields: Readonly<Record<string, unknown>> | null;
|
|
23
|
+
readonly links: readonly string[];
|
|
25
24
|
};
|
|
26
|
-
export type Derived =
|
|
25
|
+
export type Derived = {
|
|
27
26
|
readonly values: readonly HeldValue[];
|
|
28
27
|
readonly links: readonly HeldLink[];
|
|
29
28
|
};
|
|
@@ -32,15 +31,9 @@ export declare function roomOfKey(key: string): string;
|
|
|
32
31
|
export declare function pathOfKey(key: string): string;
|
|
33
32
|
export declare function markdownPath(path: string): boolean;
|
|
34
33
|
export declare function folderOf(path: string): string;
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
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;
|
|
34
|
+
export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
|
|
35
|
+
export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
|
|
36
|
+
export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
|
|
37
|
+
export declare function derived(path: string, held: Held, composition: Composition): Derived;
|
|
45
38
|
export {};
|
|
46
39
|
//# 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":"AAAA,OAAO,EAA8C,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjC,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;IAC/B,QAAQ,CAAC,KAA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