@agentshouse/mdruntime 0.1.0-ca6edc1abd618 → 0.1.0-ca8707258fdde
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 +2 -2
- package/dist/acceptance.d.ts +26 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +384 -0
- package/dist/adapter.d.ts +102 -70
- 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 +16 -14
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +272 -129
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/client.d.ts +20 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -6
- 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 +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +278 -282
- package/dist/connection.d.ts +22 -44
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1600 -3577
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +27 -18
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +484 -258
- 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 +18 -8
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +29 -32
- 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 +20 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/install.d.ts +86 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +62 -20
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- 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 +12 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +216 -85
- package/dist/messages.d.ts +27 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +97 -19
- package/dist/model.d.ts +8 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +5 -17
- 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 +14 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +19 -2
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -0
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- 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 +18 -207
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +32 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +118 -0
- package/dist/reach.d.ts +18 -11
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +206 -126
- package/dist/react.d.ts +5 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +3 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/reads.d.ts +34 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +114 -86
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +35 -1
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +33 -5
- package/dist/replica.d.ts +10 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +52 -20
- 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/room-drafts.d.ts +29 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/rows.d.ts +18 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +45 -153
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +22 -13
- package/dist/saves.d.ts +96 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +999 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +16 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +66 -0
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket.d.ts +43 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +96 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +408 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/watchers.d.ts +15 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +36 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +76 -158
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +117 -403
- package/dist/stored.d.ts +66 -55
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +343 -273
- package/dist/tables.d.ts +118 -65
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +199 -99
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- 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 +23 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +8 -2
- package/package.json +2 -2
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/replica.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type TypedPath } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { BootstrapInventory, SavedFacts, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
|
|
2
3
|
import { type ChangeBatch, type Precondition } from './change.js';
|
|
3
4
|
import { type Collection, type Composition } from './collection.js';
|
|
4
|
-
import type
|
|
5
|
+
import { type ModelState } from './model.js';
|
|
5
6
|
import { type Layer } from './overlay.js';
|
|
6
7
|
import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
|
|
7
8
|
export type ReplicaRecord = {
|
|
@@ -15,31 +16,29 @@ export type ReplicaRecord = {
|
|
|
15
16
|
readonly providerOwnedPaths: readonly string[];
|
|
16
17
|
readonly roomVersion: string;
|
|
17
18
|
readonly transfer: string;
|
|
18
|
-
readonly inventory: BootstrapInventory
|
|
19
|
+
readonly inventory: BootstrapInventory;
|
|
19
20
|
readonly key: number;
|
|
20
21
|
};
|
|
21
22
|
export type HeldReplica = {
|
|
22
23
|
readonly record: ReplicaRecord;
|
|
23
24
|
readonly queue: readonly ChangeBatch[];
|
|
24
25
|
readonly overlaid: ReadonlySet<string>;
|
|
25
|
-
readonly count: number;
|
|
26
|
-
readonly confirmed: number;
|
|
27
|
-
readonly indexed: boolean;
|
|
28
26
|
};
|
|
29
27
|
export type VisibleLayer = Layer & {
|
|
30
28
|
readonly collection: Collection;
|
|
31
29
|
};
|
|
32
30
|
export type Slice = Layer & {
|
|
33
31
|
readonly written: Readonly<Record<string, string>>;
|
|
32
|
+
readonly facts: Readonly<Record<string, SavedFacts>>;
|
|
34
33
|
readonly held: ReadonlySet<string>;
|
|
35
34
|
};
|
|
36
|
-
export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState): Composition;
|
|
37
|
-
export declare function sameMembership(record: Pick<ReplicaRecord, 'typedSelection'>, other: Pick<ReplicaRecord, 'typedSelection'>): boolean;
|
|
35
|
+
export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
|
|
38
36
|
export declare function storedRecord(record: ReplicaRecord): string;
|
|
39
37
|
export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
|
|
38
|
+
export type LayerEntry = Omit<StoredEntry, 'facts'>;
|
|
40
39
|
export declare function entryAt(layer: Layer & {
|
|
41
40
|
readonly written?: Readonly<Record<string, string>>;
|
|
42
|
-
}, path: string):
|
|
41
|
+
}, path: string): LayerEntry | null;
|
|
43
42
|
export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
|
|
44
43
|
export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
|
|
45
44
|
export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
|
|
@@ -48,7 +47,7 @@ export type Replayed = {
|
|
|
48
47
|
readonly touched: ReadonlySet<string>;
|
|
49
48
|
};
|
|
50
49
|
export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
|
|
51
|
-
export declare function overlayOf(visible:
|
|
50
|
+
export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
|
|
52
51
|
export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
|
|
53
52
|
export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
|
|
54
53
|
export type Standing = {
|
|
@@ -64,6 +63,6 @@ export type Returned = {
|
|
|
64
63
|
readonly removed: readonly string[];
|
|
65
64
|
};
|
|
66
65
|
export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
|
|
67
|
-
export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string): Generator<number, Returned, void>;
|
|
66
|
+
export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
|
|
68
67
|
export {};
|
|
69
68
|
//# sourceMappingURL=replica.d.ts.map
|
package/dist/replica.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EAEV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAmC,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAiD,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAGzF,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGxE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,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;AAED,wBAAiB,SAAS,CACxB,SAAS,EAAE,KAAK,EAChB,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CA6FnC"}
|
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',
|
|
@@ -61,9 +60,13 @@ export function* slicing(entries, paths) {
|
|
|
61
60
|
const binaries = {};
|
|
62
61
|
const revisions = {};
|
|
63
62
|
const fileIds = {};
|
|
63
|
+
const created = {};
|
|
64
64
|
const changes = {};
|
|
65
65
|
const written = {};
|
|
66
|
+
const facts = {};
|
|
66
67
|
for (const entry of entries) {
|
|
68
|
+
if (entry.facts !== null)
|
|
69
|
+
facts[entry.path] = entry.facts;
|
|
67
70
|
if (entry.binary !== null)
|
|
68
71
|
binaries[entry.path] = entry.binary;
|
|
69
72
|
else if (entry.content !== null)
|
|
@@ -72,6 +75,8 @@ export function* slicing(entries, paths) {
|
|
|
72
75
|
revisions[entry.path] = entry.revision;
|
|
73
76
|
if (entry.fileId !== null)
|
|
74
77
|
fileIds[entry.path] = entry.fileId;
|
|
78
|
+
if (entry.created !== null)
|
|
79
|
+
created[entry.path] = entry.created;
|
|
75
80
|
if (entry.change !== null)
|
|
76
81
|
changes[entry.path] = entry.change;
|
|
77
82
|
if (entry.written !== null)
|
|
@@ -83,8 +88,10 @@ export function* slicing(entries, paths) {
|
|
|
83
88
|
binaries: strict(binaries, held),
|
|
84
89
|
revisions: strict(revisions, held),
|
|
85
90
|
fileIds: strict(fileIds, held),
|
|
91
|
+
created: strict(created, held),
|
|
86
92
|
changes: strict(changes, held),
|
|
87
93
|
written: strict(written, held),
|
|
94
|
+
facts: strict(facts, held),
|
|
88
95
|
held,
|
|
89
96
|
};
|
|
90
97
|
}
|
|
@@ -99,6 +106,7 @@ export function entryAt(layer, path) {
|
|
|
99
106
|
binary: binary ?? null,
|
|
100
107
|
revision: layer.revisions[path] ?? null,
|
|
101
108
|
fileId: layer.fileIds[path] ?? null,
|
|
109
|
+
created: layer.created[path] ?? null,
|
|
102
110
|
change: layer.changes[path] ?? null,
|
|
103
111
|
written: layer.written?.[path] ?? null,
|
|
104
112
|
};
|
|
@@ -107,8 +115,9 @@ export function* slicingWith(slice, set, removed) {
|
|
|
107
115
|
const entries = new Map();
|
|
108
116
|
for (const path of slice.held) {
|
|
109
117
|
const entry = entryAt(slice, path);
|
|
110
|
-
if (entry !== null)
|
|
111
|
-
entries.set(path, { ...entry, type: null });
|
|
118
|
+
if (entry !== null) {
|
|
119
|
+
entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
|
|
120
|
+
}
|
|
112
121
|
yield ROW_WEIGHT;
|
|
113
122
|
}
|
|
114
123
|
for (const path of removed)
|
|
@@ -172,8 +181,9 @@ export function* replaying(confirmed, queue, locator, composition) {
|
|
|
172
181
|
export function* overlayOf(visible, touched) {
|
|
173
182
|
const rows = [];
|
|
174
183
|
for (const path of touched) {
|
|
175
|
-
yield ROW_WEIGHT;
|
|
176
184
|
const entry = entryAt(visible, path);
|
|
185
|
+
yield ROW_WEIGHT + (entry?.content?.length ?? 0);
|
|
186
|
+
const text = entry?.binary === null ? entry.content : null;
|
|
177
187
|
rows.push(entry === null
|
|
178
188
|
? {
|
|
179
189
|
path,
|
|
@@ -182,10 +192,17 @@ export function* overlayOf(visible, touched) {
|
|
|
182
192
|
binary: null,
|
|
183
193
|
revision: null,
|
|
184
194
|
fileId: null,
|
|
195
|
+
created: null,
|
|
185
196
|
change: null,
|
|
186
197
|
written: null,
|
|
198
|
+
facts: null,
|
|
187
199
|
}
|
|
188
|
-
: {
|
|
200
|
+
: {
|
|
201
|
+
...entry,
|
|
202
|
+
written: null,
|
|
203
|
+
present: true,
|
|
204
|
+
facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
|
|
205
|
+
});
|
|
189
206
|
}
|
|
190
207
|
return rows;
|
|
191
208
|
}
|
|
@@ -350,17 +367,20 @@ export function returnedPaths(submitted, accepted) {
|
|
|
350
367
|
}
|
|
351
368
|
return paths;
|
|
352
369
|
}
|
|
353
|
-
export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
370
|
+
export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
|
|
354
371
|
const documents = new Map();
|
|
355
372
|
const binaries = new Map();
|
|
356
373
|
const revisions = new Map();
|
|
357
374
|
const fileIds = new Map();
|
|
375
|
+
const created = new Map();
|
|
358
376
|
const changes = new Map();
|
|
359
377
|
const written = new Map();
|
|
378
|
+
const facts = new Map();
|
|
360
379
|
const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
|
|
361
380
|
for (const [path, content] of Object.entries(accepted.documents)) {
|
|
362
|
-
yield ROW_WEIGHT;
|
|
381
|
+
yield ROW_WEIGHT + content.length;
|
|
363
382
|
documents.set(path, content);
|
|
383
|
+
facts.set(path, writtenFacts(path, content, composition));
|
|
364
384
|
fileIds.set(path, undefined);
|
|
365
385
|
written.set(path, writtenAt);
|
|
366
386
|
}
|
|
@@ -383,48 +403,60 @@ export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
|
383
403
|
written.set(path, undefined);
|
|
384
404
|
}
|
|
385
405
|
for (const change of submitted.changes) {
|
|
386
|
-
if (change.kind === 'arrival'
|
|
387
|
-
if (accepted.revisions[change.path]
|
|
406
|
+
if (change.kind === 'arrival') {
|
|
407
|
+
if (accepted.revisions[change.path] === undefined)
|
|
408
|
+
continue;
|
|
409
|
+
created.set(change.path, change.created);
|
|
410
|
+
if ('binary' in change)
|
|
388
411
|
binaries.set(change.path, { state: 'accepted', ...change.binary });
|
|
389
|
-
}
|
|
390
412
|
continue;
|
|
391
413
|
}
|
|
392
|
-
if (change.kind !== 'move')
|
|
414
|
+
if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
|
|
393
415
|
continue;
|
|
416
|
+
created.set(change.to, read(created, confirmed.created, change.path));
|
|
417
|
+
created.set(change.path, undefined);
|
|
394
418
|
const moved = read(binaries, confirmed.binaries, change.path);
|
|
395
|
-
if (moved === undefined
|
|
419
|
+
if (moved === undefined)
|
|
396
420
|
continue;
|
|
397
421
|
binaries.set(change.to, moved);
|
|
398
422
|
binaries.set(change.path, undefined);
|
|
399
423
|
}
|
|
400
424
|
for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
|
|
401
425
|
binaries.set(path, binary);
|
|
402
|
-
for (const path of accepted.removals)
|
|
426
|
+
for (const path of accepted.removals) {
|
|
403
427
|
binaries.set(path, undefined);
|
|
428
|
+
created.set(path, undefined);
|
|
429
|
+
}
|
|
404
430
|
const paths = new Set([
|
|
405
431
|
...documents.keys(),
|
|
406
432
|
...binaries.keys(),
|
|
407
433
|
...revisions.keys(),
|
|
408
434
|
...fileIds.keys(),
|
|
435
|
+
...created.keys(),
|
|
409
436
|
...changes.keys(),
|
|
410
437
|
...written.keys(),
|
|
411
438
|
]);
|
|
412
439
|
const set = [];
|
|
413
440
|
const removed = [];
|
|
414
441
|
for (const path of paths) {
|
|
415
|
-
yield ROW_WEIGHT;
|
|
416
442
|
const content = read(documents, confirmed.documents, path);
|
|
417
443
|
const binary = read(binaries, confirmed.binaries, path);
|
|
444
|
+
yield ROW_WEIGHT;
|
|
418
445
|
if (content === undefined && binary === undefined) {
|
|
419
446
|
removed.push(path);
|
|
420
447
|
continue;
|
|
421
448
|
}
|
|
449
|
+
const text = binary === undefined ? (content ?? null) : null;
|
|
450
|
+
const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
|
|
422
451
|
set.push({
|
|
423
452
|
path,
|
|
424
|
-
content:
|
|
453
|
+
content: text,
|
|
454
|
+
facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
|
|
425
455
|
binary: binary ?? null,
|
|
426
456
|
revision: read(revisions, confirmed.revisions, path) ?? null,
|
|
427
457
|
fileId: read(fileIds, confirmed.fileIds, path) ?? null,
|
|
458
|
+
created: read(created, confirmed.created, path) ??
|
|
459
|
+
(fresh ? (read(changes, confirmed.changes, path)?.time ?? null) : null),
|
|
428
460
|
change: read(changes, confirmed.changes, path) ?? null,
|
|
429
461
|
written: read(written, confirmed.written, path) ?? null,
|
|
430
462
|
});
|
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,IA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G,MAAM,CAGhE;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,GACnE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,EAAE,CAStE;AAED,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
|
}
|