@agentshouse/mdruntime 0.1.0-c44866799613e → 0.1.0-c44d5cc00aee5
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 -17
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +299 -0
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +302 -0
- package/dist/adapter.d.ts +110 -112
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +28 -51
- package/dist/bootstrap.d.ts +15 -18
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +252 -158
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +27 -21
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +36 -17
- package/dist/collection.d.ts +23 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +13 -19
- package/dist/compile.d.ts +8 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +288 -329
- package/dist/connection.d.ts +5 -143
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +109 -5104
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +143 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +254 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +65 -48
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +987 -838
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +150 -0
- package/dist/durability.d.ts +19 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +4 -0
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +19 -9
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +21 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +73 -40
- 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 +34 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -5
- package/dist/install.d.ts +54 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +530 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +277 -0
- package/dist/listing.d.ts +48 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +139 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +64 -23
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +32 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +2 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +23 -13
- package/dist/memory.d.ts +17 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +210 -97
- package/dist/messages.d.ts +33 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +104 -36
- package/dist/model.d.ts +2 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -23
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/observation.d.ts +4 -3
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +23 -17
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +53 -0
- package/dist/outcome.d.ts +7 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +18 -0
- package/dist/overlay.d.ts +6 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +47 -21
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +4 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +13 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +227 -0
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +282 -0
- package/dist/query.d.ts +14 -210
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +29 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +115 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +450 -0
- package/dist/reach.d.ts +15 -12
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +240 -149
- package/dist/react.d.ts +15 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -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 +4 -19
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/reads.d.ts +38 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +163 -85
- package/dist/recovery.d.ts +3 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +57 -1
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +35 -7
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +12 -18
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +64 -34
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +24 -10
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +142 -106
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -186
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +42 -84
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +349 -170
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +410 -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 +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- package/dist/shown.d.ts +33 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +302 -0
- 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/lanes.d.ts +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -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/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +67 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +164 -0
- package/dist/source.d.ts +54 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -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/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +214 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +438 -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/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -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 +120 -171
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +166 -414
- package/dist/stored.d.ts +62 -57
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +317 -239
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +220 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +535 -0
- package/dist/tables.d.ts +126 -65
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +250 -113
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -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 +65 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +22 -5
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- 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/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/retried.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { refusedForSpace } from './durability.js';
|
|
2
|
+
export const STEPS = [
|
|
3
|
+
'database',
|
|
4
|
+
'sign_in',
|
|
5
|
+
'connection',
|
|
6
|
+
'code',
|
|
7
|
+
'download',
|
|
8
|
+
'conversations',
|
|
9
|
+
'sending',
|
|
10
|
+
'reading',
|
|
11
|
+
];
|
|
12
|
+
export class Unanswered extends Error {
|
|
13
|
+
}
|
|
14
|
+
export function uncertainError(uncertainty) {
|
|
15
|
+
return 'failure' in uncertainty ? uncertainty.failure : new Unanswered();
|
|
16
|
+
}
|
|
17
|
+
export function createRetries(shell) {
|
|
18
|
+
const failing = new Map();
|
|
19
|
+
const handedErrors = new WeakSet();
|
|
20
|
+
function failingIn(step, instance) {
|
|
21
|
+
const instances = failing.get(step) ?? new Set();
|
|
22
|
+
instances.add(instance);
|
|
23
|
+
failing.set(step, instances);
|
|
24
|
+
}
|
|
25
|
+
function handed(failure, instance) {
|
|
26
|
+
failingIn(failure.step, instance);
|
|
27
|
+
shell.retried?.(failure);
|
|
28
|
+
}
|
|
29
|
+
const retries = {
|
|
30
|
+
failed(step, instance, error) {
|
|
31
|
+
if (refusedForSpace(error))
|
|
32
|
+
return;
|
|
33
|
+
if (typeof error === 'object' && error !== null) {
|
|
34
|
+
if (handedErrors.has(error)) {
|
|
35
|
+
failingIn(step, instance);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
handedErrors.add(error);
|
|
39
|
+
}
|
|
40
|
+
if (error instanceof Unanswered)
|
|
41
|
+
retries.unanswered(step, instance);
|
|
42
|
+
else
|
|
43
|
+
handed({ step, answered: true, error }, instance);
|
|
44
|
+
},
|
|
45
|
+
unanswered(step, instance) {
|
|
46
|
+
handed({ step, answered: false }, instance);
|
|
47
|
+
},
|
|
48
|
+
uncertain(step, instance, uncertainty) {
|
|
49
|
+
if ('failure' in uncertainty)
|
|
50
|
+
retries.failed(step, instance, uncertainty.failure);
|
|
51
|
+
else
|
|
52
|
+
retries.unanswered(step, instance);
|
|
53
|
+
},
|
|
54
|
+
succeeded(step, instance) {
|
|
55
|
+
const instances = failing.get(step);
|
|
56
|
+
if (instances === undefined || !instances.delete(instance) || instances.size > 0)
|
|
57
|
+
return;
|
|
58
|
+
failing.delete(step);
|
|
59
|
+
shell.succeeded?.(step);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
return retries;
|
|
63
|
+
}
|
|
64
|
+
export function retrying(retries, step, instance, ask) {
|
|
65
|
+
return () => ask().then((answer) => {
|
|
66
|
+
retries.succeeded(step, instance);
|
|
67
|
+
return answer;
|
|
68
|
+
}, (error) => {
|
|
69
|
+
retries.failed(step, instance, error);
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DefinitionOf } from '@agentshouse/mdmodel';
|
|
1
2
|
import type { ProviderRefusal } from './adapter.js';
|
|
2
3
|
import type { Open } from './open.js';
|
|
3
4
|
import type { Change, Precondition } from './change.js';
|
|
@@ -40,6 +41,7 @@ export type RoomDraftParts = {
|
|
|
40
41
|
};
|
|
41
42
|
readonly file?: {
|
|
42
43
|
readonly blob: Blob;
|
|
44
|
+
readonly base?: string | null;
|
|
43
45
|
};
|
|
44
46
|
};
|
|
45
47
|
export type HeldFile = {
|
|
@@ -89,9 +91,9 @@ type ChangedUnderneath = {
|
|
|
89
91
|
readonly file?: string | null;
|
|
90
92
|
};
|
|
91
93
|
export type ReturnReason = ProviderRefusal & {
|
|
92
|
-
readonly kind: Open<'conflicted' | 'rejected' | '
|
|
94
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
|
|
93
95
|
};
|
|
94
|
-
export declare function returnedBy(
|
|
96
|
+
export declare function returnedBy(): ReturnReason;
|
|
95
97
|
export type RoomDraft = {
|
|
96
98
|
readonly room: string;
|
|
97
99
|
readonly path: string;
|
|
@@ -105,14 +107,12 @@ export type RoomDraftWrite = {
|
|
|
105
107
|
readonly roomDraft: RoomDraft | null;
|
|
106
108
|
} | {
|
|
107
109
|
readonly outcome: 'stale';
|
|
108
|
-
readonly code: string;
|
|
109
|
-
readonly retryable: boolean;
|
|
110
110
|
readonly current: RoomDraft | null;
|
|
111
111
|
};
|
|
112
112
|
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
113
113
|
export type ChangedPart = {
|
|
114
114
|
readonly path: string;
|
|
115
|
-
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | '
|
|
115
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
|
|
116
116
|
readonly name?: string;
|
|
117
117
|
};
|
|
118
118
|
export type RoomDraftRecord = {
|
|
@@ -126,13 +126,14 @@ export type SavedDraft = {
|
|
|
126
126
|
readonly path: string;
|
|
127
127
|
readonly parts: HeldParts;
|
|
128
128
|
};
|
|
129
|
-
export declare function readParts(value: unknown): RoomDraftParts;
|
|
129
|
+
export declare function readParts(value: unknown, path: string): RoomDraftParts;
|
|
130
130
|
export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
|
|
131
131
|
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
132
132
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
133
133
|
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
134
134
|
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
135
|
-
export declare function changedParts(path: string,
|
|
135
|
+
export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
|
|
136
|
+
export declare function lineEnded(text: string): string;
|
|
136
137
|
export type TextParts = {
|
|
137
138
|
readonly fields?: Readonly<Record<string, {
|
|
138
139
|
readonly value: unknown;
|
|
@@ -144,16 +145,29 @@ export type TextParts = {
|
|
|
144
145
|
readonly value: string;
|
|
145
146
|
};
|
|
146
147
|
};
|
|
147
|
-
export declare function partsAfter(markdown: string, parts: TextParts): string;
|
|
148
|
-
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
148
|
+
export declare function partsAfter(markdown: string, parts: TextParts, definitions?: DefinitionOf): string | null;
|
|
149
|
+
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts, definitions?: DefinitionOf): HeldParts | null;
|
|
149
150
|
export declare function moveTarget(move: {
|
|
150
151
|
readonly to: string;
|
|
151
152
|
}): string;
|
|
153
|
+
export declare function readSavedParts(named: readonly {
|
|
154
|
+
readonly path: string;
|
|
155
|
+
readonly parts: unknown;
|
|
156
|
+
}[]): readonly {
|
|
157
|
+
readonly path: string;
|
|
158
|
+
readonly parts: RoomDraftParts;
|
|
159
|
+
}[];
|
|
160
|
+
export declare function partsChanges(named: readonly {
|
|
161
|
+
readonly path: string;
|
|
162
|
+
readonly parts: unknown;
|
|
163
|
+
}[]): {
|
|
164
|
+
readonly changes: readonly Change[];
|
|
165
|
+
readonly preconditions: readonly Precondition[];
|
|
166
|
+
};
|
|
152
167
|
export declare function changesOf(path: string, parts: HeldParts): {
|
|
153
168
|
changes: readonly Change[];
|
|
154
169
|
bases: readonly Precondition[];
|
|
155
170
|
};
|
|
156
|
-
export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
|
|
157
171
|
export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
|
|
158
172
|
export {};
|
|
159
173
|
//# sourceMappingURL=room-draft.d.ts.map
|
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":"
|
|
1
|
+
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AAAA,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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;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
|
@@ -1,60 +1,69 @@
|
|
|
1
|
-
import { apply, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, create, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { governing } from './collection.js';
|
|
2
3
|
import { runtimeError } from './failure.js';
|
|
3
4
|
import { sha256 } from './digest.js';
|
|
4
5
|
import { binaryLocalId } from './identity.js';
|
|
5
6
|
import { normalize } from './paths.js';
|
|
6
|
-
export function returnedBy(
|
|
7
|
-
return { kind, code:
|
|
7
|
+
export function returnedBy() {
|
|
8
|
+
return { kind: 'withdrawn', code: 'withdrawn', fields: {}, retryable: false };
|
|
8
9
|
}
|
|
9
10
|
export function staleWrite(current) {
|
|
10
|
-
return { outcome: 'stale',
|
|
11
|
+
return { outcome: 'stale', current };
|
|
11
12
|
}
|
|
12
|
-
function malformed() {
|
|
13
|
-
throw runtimeError('room-draft-malformed');
|
|
13
|
+
function malformed(at, needs) {
|
|
14
|
+
throw runtimeError('room-draft-malformed', at === undefined ? 'room-draft-malformed' : `room-draft-malformed at ${at}: ${needs}`);
|
|
14
15
|
}
|
|
15
16
|
function plain(value) {
|
|
16
17
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
18
|
}
|
|
18
|
-
function text(value) {
|
|
19
|
-
return typeof value === 'string' ? value : malformed();
|
|
19
|
+
function text(value, at) {
|
|
20
|
+
return typeof value === 'string' ? value : malformed(at, 'text');
|
|
20
21
|
}
|
|
21
|
-
function optionalText(value) {
|
|
22
|
-
return value === undefined ? undefined : text(value);
|
|
22
|
+
function optionalText(value, at) {
|
|
23
|
+
return value === undefined ? undefined : text(value, at);
|
|
23
24
|
}
|
|
24
|
-
function markdownBase(value) {
|
|
25
|
-
return value === null ? null : optionalText(value);
|
|
25
|
+
function markdownBase(value, at) {
|
|
26
|
+
return value === null ? null : optionalText(value, at);
|
|
26
27
|
}
|
|
27
|
-
function entries(value, each) {
|
|
28
|
+
function entries(value, at, each) {
|
|
28
29
|
if (!plain(value))
|
|
29
|
-
malformed();
|
|
30
|
+
malformed(at, 'an object of named values');
|
|
30
31
|
const read = {};
|
|
31
32
|
for (const [name, item] of Object.entries(value))
|
|
32
|
-
read[name] = each(item);
|
|
33
|
+
read[name] = each(item, `${at}.${name}`);
|
|
33
34
|
return read;
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function frontmatter(item, at) {
|
|
37
|
+
return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
|
|
38
|
+
}
|
|
39
|
+
function fieldValue(value, at) {
|
|
36
40
|
if (value === null)
|
|
37
41
|
return null;
|
|
38
42
|
if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
|
|
39
|
-
malformed();
|
|
43
|
+
malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
|
|
40
44
|
}
|
|
41
45
|
return { value: value.value };
|
|
42
46
|
}
|
|
43
|
-
function textPart(value) {
|
|
47
|
+
function textPart(value, at) {
|
|
44
48
|
if (!plain(value))
|
|
45
|
-
malformed();
|
|
46
|
-
const base = optionalText(value.base);
|
|
47
|
-
return { value: text(value.value), ...(base === undefined ? {} : { base }) };
|
|
49
|
+
malformed(at, '{ value, base }');
|
|
50
|
+
const base = optionalText(value.base, `${at}.base`);
|
|
51
|
+
return { value: text(value.value, `${at}.value`), ...(base === undefined ? {} : { base }) };
|
|
48
52
|
}
|
|
49
|
-
function creationOf(value) {
|
|
53
|
+
function creationOf(value, at) {
|
|
50
54
|
if (!plain(value))
|
|
51
|
-
malformed();
|
|
55
|
+
malformed(at, '{ type, fields, sections }, or { markdown }');
|
|
52
56
|
if (Object.hasOwn(value, 'markdown'))
|
|
53
|
-
return { markdown: text(value.markdown) };
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
return { markdown: text(value.markdown, `${at}.markdown`) };
|
|
58
|
+
if (typeof value.type !== 'string')
|
|
59
|
+
malformed(`${at}.type`, 'a type name, or markdown in place of type, fields and sections');
|
|
60
|
+
return {
|
|
61
|
+
type: value.type,
|
|
62
|
+
fields: entries(value.fields, `${at}.fields`, frontmatter),
|
|
63
|
+
sections: entries(value.sections, `${at}.sections`, text),
|
|
64
|
+
};
|
|
56
65
|
}
|
|
57
|
-
const PART_NAMES =
|
|
66
|
+
const PART_NAMES = [
|
|
58
67
|
'fields',
|
|
59
68
|
'sections',
|
|
60
69
|
'preamble',
|
|
@@ -63,52 +72,57 @@ const PART_NAMES = new Set([
|
|
|
63
72
|
'move',
|
|
64
73
|
'removal',
|
|
65
74
|
'file',
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
];
|
|
76
|
+
const NAMED_PARTS = `a part named ${PART_NAMES.slice(0, -1).join(', ')} or ${PART_NAMES.slice(-1).join('')}`;
|
|
77
|
+
export function readParts(value, path) {
|
|
78
|
+
if (!plain(value))
|
|
79
|
+
malformed(path, 'an object of parts');
|
|
80
|
+
const unknown = Object.keys(value).find((name) => !PART_NAMES.includes(name));
|
|
81
|
+
if (unknown !== undefined)
|
|
82
|
+
malformed(`${path} ${unknown}`, NAMED_PARTS);
|
|
70
83
|
const parts = {};
|
|
71
84
|
if (value.fields !== undefined) {
|
|
72
|
-
parts.fields = entries(value.fields, (item) => {
|
|
85
|
+
parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
|
|
73
86
|
if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
|
|
74
|
-
malformed();
|
|
87
|
+
malformed(at, '{ value, base } with a frontmatter value');
|
|
75
88
|
}
|
|
76
89
|
return item.base === undefined
|
|
77
90
|
? { value: item.value }
|
|
78
|
-
: { value: item.value, base: fieldValue(item.base) };
|
|
91
|
+
: { value: item.value, base: fieldValue(item.base, `${at}.base`) };
|
|
79
92
|
});
|
|
80
93
|
}
|
|
81
94
|
if (value.sections !== undefined)
|
|
82
|
-
parts.sections = entries(value.sections, textPart);
|
|
95
|
+
parts.sections = entries(value.sections, `${path} sections`, textPart);
|
|
83
96
|
if (value.preamble !== undefined)
|
|
84
|
-
parts.preamble = textPart(value.preamble);
|
|
97
|
+
parts.preamble = textPart(value.preamble, `${path} preamble`);
|
|
85
98
|
if (value.markdown !== undefined)
|
|
86
|
-
parts.markdown = textPart(value.markdown);
|
|
99
|
+
parts.markdown = textPart(value.markdown, `${path} markdown`);
|
|
87
100
|
if (value.creation !== undefined)
|
|
88
|
-
parts.creation = creationOf(value.creation);
|
|
101
|
+
parts.creation = creationOf(value.creation, `${path} creation`);
|
|
89
102
|
if (value.move !== undefined) {
|
|
90
103
|
if (!plain(value.move))
|
|
91
|
-
malformed();
|
|
92
|
-
const base = markdownBase(value.move.base);
|
|
93
|
-
const room = optionalText(value.move.room);
|
|
104
|
+
malformed(`${path} move`, '{ to, room, base }');
|
|
105
|
+
const base = markdownBase(value.move.base, `${path} move.base`);
|
|
106
|
+
const room = optionalText(value.move.room, `${path} move.room`);
|
|
94
107
|
parts.move = {
|
|
95
|
-
to: text(value.move.to),
|
|
108
|
+
to: text(value.move.to, `${path} move.to`),
|
|
96
109
|
...(room === undefined ? {} : { room }),
|
|
97
110
|
...(base === undefined ? {} : { base }),
|
|
98
111
|
};
|
|
99
112
|
}
|
|
100
113
|
if (value.removal !== undefined) {
|
|
101
114
|
if (!plain(value.removal))
|
|
102
|
-
malformed();
|
|
103
|
-
const base = markdownBase(value.removal.base);
|
|
115
|
+
malformed(`${path} removal`, '{ base }');
|
|
116
|
+
const base = markdownBase(value.removal.base, `${path} removal.base`);
|
|
104
117
|
parts.removal = base === undefined ? {} : { base };
|
|
105
118
|
}
|
|
106
119
|
if (value.file !== undefined) {
|
|
107
120
|
if (!plain(value.file) || !(value.file.blob instanceof Blob))
|
|
108
|
-
malformed();
|
|
121
|
+
malformed(`${path} file`, '{ blob, base } with a Blob');
|
|
109
122
|
if (Object.keys(value).length > 1)
|
|
110
123
|
throw runtimeError('room-draft-file-exclusive');
|
|
111
|
-
|
|
124
|
+
const base = markdownBase(value.file.base, `${path} file.base`);
|
|
125
|
+
parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
|
|
112
126
|
}
|
|
113
127
|
return parts;
|
|
114
128
|
}
|
|
@@ -242,8 +256,10 @@ export function underneath(parts, path, visible) {
|
|
|
242
256
|
const markdown = visible?.documents[path] ?? null;
|
|
243
257
|
const document = visible?.collection.document(path);
|
|
244
258
|
const report = {};
|
|
259
|
+
const unread = document?.type !== undefined &&
|
|
260
|
+
governing(visible.collection.composition, path).status === 'unavailable';
|
|
245
261
|
const fields = {};
|
|
246
|
-
for (const [name, part] of named(parts.fields)) {
|
|
262
|
+
for (const [name, part] of unread ? [] : named(parts.fields)) {
|
|
247
263
|
const current = document !== undefined && Object.hasOwn(document.fields, name)
|
|
248
264
|
? { value: document.fields[name] }
|
|
249
265
|
: null;
|
|
@@ -253,7 +269,7 @@ export function underneath(parts, path, visible) {
|
|
|
253
269
|
if (Object.keys(fields).length > 0)
|
|
254
270
|
report.fields = fields;
|
|
255
271
|
const sections = {};
|
|
256
|
-
for (const [name, part] of named(parts.sections)) {
|
|
272
|
+
for (const [name, part] of unread ? [] : named(parts.sections)) {
|
|
257
273
|
const current = document !== undefined && Object.hasOwn(document.sections, name)
|
|
258
274
|
? document.sections[name]
|
|
259
275
|
: null;
|
|
@@ -263,8 +279,9 @@ export function underneath(parts, path, visible) {
|
|
|
263
279
|
if (Object.keys(sections).length > 0)
|
|
264
280
|
report.sections = sections;
|
|
265
281
|
const preamble = document?.preamble ?? null;
|
|
266
|
-
if (parts.preamble !== undefined && preamble !== parts.preamble.base)
|
|
282
|
+
if (!unread && parts.preamble !== undefined && preamble !== parts.preamble.base) {
|
|
267
283
|
report.preamble = preamble;
|
|
284
|
+
}
|
|
268
285
|
if (parts.markdown !== undefined && markdown !== parts.markdown.base)
|
|
269
286
|
report.markdown = markdown;
|
|
270
287
|
if (parts.creation !== undefined && markdown !== null)
|
|
@@ -292,18 +309,22 @@ export async function heldFile(blob, base) {
|
|
|
292
309
|
};
|
|
293
310
|
}
|
|
294
311
|
export function binaryBase(visible, path) {
|
|
295
|
-
|
|
312
|
+
const binary = visible?.binaries[path];
|
|
313
|
+
if (binary === undefined)
|
|
314
|
+
return null;
|
|
315
|
+
return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
|
|
296
316
|
}
|
|
297
|
-
export function changedParts(path,
|
|
317
|
+
export function changedParts(path, parts, visible) {
|
|
318
|
+
const report = underneath(parts, path, visible);
|
|
319
|
+
const made = parts.file?.base === null;
|
|
298
320
|
return [
|
|
299
|
-
...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
|
|
300
321
|
...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
|
|
301
322
|
...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
|
|
302
323
|
...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
|
|
303
324
|
...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
|
|
304
325
|
...(report.move === undefined ? [] : [{ path, part: 'move' }]),
|
|
305
326
|
...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
|
|
306
|
-
...(report.file === undefined ? [] : [{ path, part: 'file' }]),
|
|
327
|
+
...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
|
|
307
328
|
];
|
|
308
329
|
}
|
|
309
330
|
function joined(existing, returned) {
|
|
@@ -313,33 +334,45 @@ function joined(existing, returned) {
|
|
|
313
334
|
merged[name] = part;
|
|
314
335
|
return Object.keys(merged).length === 0 ? undefined : merged;
|
|
315
336
|
}
|
|
316
|
-
function
|
|
337
|
+
export function lineEnded(text) {
|
|
317
338
|
return text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
318
339
|
}
|
|
319
|
-
function
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
value: part.value,
|
|
327
|
-
prior: undefined,
|
|
328
|
-
})));
|
|
329
|
-
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
340
|
+
function written(start, changes, definition) {
|
|
341
|
+
const next = apply(start, changes, definition);
|
|
342
|
+
return next.outcome === 'applied' ? next.document : malformed();
|
|
343
|
+
}
|
|
344
|
+
function empty(definition) {
|
|
345
|
+
const parsed = parse('', '', definition);
|
|
346
|
+
return parsed.ok ? parsed.document : malformed();
|
|
330
347
|
}
|
|
331
|
-
export function partsAfter(markdown, parts) {
|
|
348
|
+
export function partsAfter(markdown, parts, definitions) {
|
|
332
349
|
const fields = named(parts.fields);
|
|
350
|
+
const sections = named(parts.sections);
|
|
351
|
+
if (fields.length === 0 && sections.length === 0 && parts.preamble === undefined)
|
|
352
|
+
return markdown;
|
|
353
|
+
const whole = parse(markdown, '', definitions);
|
|
354
|
+
const type = whole.ok ? whole.document.type : undefined;
|
|
355
|
+
const definition = definitions?.(type);
|
|
356
|
+
if (type !== undefined && definition === undefined)
|
|
357
|
+
return null;
|
|
358
|
+
const valued = fields.length === 0
|
|
359
|
+
? empty(definition)
|
|
360
|
+
: written(create(type, definition), fields.map(([name, part]) => ({
|
|
361
|
+
kind: 'field',
|
|
362
|
+
name,
|
|
363
|
+
value: part.value,
|
|
364
|
+
prior: undefined,
|
|
365
|
+
})), definition);
|
|
366
|
+
const head = parts.preamble === undefined
|
|
367
|
+
? valued
|
|
368
|
+
: written(valued, [{ kind: 'preamble', value: lineEnded(parts.preamble.value), prior: valued.preamble }], definition);
|
|
333
369
|
const pieces = [
|
|
334
|
-
...(fields.length === 0 ? [] : [
|
|
335
|
-
...(
|
|
336
|
-
...named(parts.sections).map(([name, part]) => `## ${name}\n${part.value}`),
|
|
370
|
+
...(fields.length === 0 && parts.preamble === undefined ? [] : [serialize(head)]),
|
|
371
|
+
...sections.map(([name, part]) => serialize(written(empty(definition), [{ kind: 'section', name, value: lineEnded(part.value), prior: undefined }], definition))),
|
|
337
372
|
];
|
|
338
|
-
|
|
339
|
-
return markdown;
|
|
340
|
-
return `${ended(markdown)}\n${pieces.map(ended).join('')}`;
|
|
373
|
+
return `${lineEnded(markdown)}\n${pieces.join('')}`;
|
|
341
374
|
}
|
|
342
|
-
export function returnedInto(existing, returned) {
|
|
375
|
+
export function returnedInto(existing, returned, definitions) {
|
|
343
376
|
if (existing === undefined)
|
|
344
377
|
return returned;
|
|
345
378
|
const next = { ...existing };
|
|
@@ -359,7 +392,9 @@ export function returnedInto(existing, returned) {
|
|
|
359
392
|
delete next.fields;
|
|
360
393
|
delete next.sections;
|
|
361
394
|
delete next.preamble;
|
|
362
|
-
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
|
|
395
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned, definitions);
|
|
396
|
+
if (value === null)
|
|
397
|
+
return null;
|
|
363
398
|
next.markdown = { value, base: whole.base };
|
|
364
399
|
}
|
|
365
400
|
const creation = existing.creation ?? returned.creation;
|
|
@@ -380,6 +415,36 @@ export function moveTarget(move) {
|
|
|
380
415
|
const to = normalize(move.to);
|
|
381
416
|
return to === null || to === '' ? move.to : to;
|
|
382
417
|
}
|
|
418
|
+
export function readSavedParts(named) {
|
|
419
|
+
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts, path) }));
|
|
420
|
+
read.forEach(({ path }, at) => {
|
|
421
|
+
if (path === '' || normalize(path) !== path)
|
|
422
|
+
malformed(path, 'a path inside the Room, such as notes/a.md');
|
|
423
|
+
if (read.findIndex((one) => one.path === path) !== at)
|
|
424
|
+
malformed(path, 'each path once in one save');
|
|
425
|
+
});
|
|
426
|
+
return read;
|
|
427
|
+
}
|
|
428
|
+
export function partsChanges(named) {
|
|
429
|
+
const changes = [];
|
|
430
|
+
const preconditions = [];
|
|
431
|
+
for (const { path, parts } of readSavedParts(named)) {
|
|
432
|
+
const parted = held(undefined, parts);
|
|
433
|
+
const made = changesOf(path, parted);
|
|
434
|
+
changes.push(...made.changes);
|
|
435
|
+
preconditions.push(...made.bases);
|
|
436
|
+
for (const change of made.changes) {
|
|
437
|
+
if (change.kind === 'create')
|
|
438
|
+
preconditions.push({ kind: 'absent', path });
|
|
439
|
+
if (change.kind === 'move')
|
|
440
|
+
preconditions.push({ kind: 'absent', path: change.to });
|
|
441
|
+
}
|
|
442
|
+
const revision = parted.markdown?.base ?? parted.move?.base ?? parted.removal?.base;
|
|
443
|
+
if (typeof revision === 'string')
|
|
444
|
+
preconditions.push({ kind: 'revision', path, revision });
|
|
445
|
+
}
|
|
446
|
+
return { changes, preconditions };
|
|
447
|
+
}
|
|
383
448
|
export function changesOf(path, parts) {
|
|
384
449
|
const changes = [];
|
|
385
450
|
const bases = [];
|
|
@@ -399,11 +464,11 @@ export function changesOf(path, parts) {
|
|
|
399
464
|
bases.push({ kind: 'field', path, name, value: part.base?.value });
|
|
400
465
|
}
|
|
401
466
|
for (const [name, part] of named(parts.sections)) {
|
|
402
|
-
changes.push({ kind: 'section', path, name, value: part.value });
|
|
467
|
+
changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
|
|
403
468
|
bases.push({ kind: 'section', path, name, value: part.base });
|
|
404
469
|
}
|
|
405
470
|
if (parts.preamble !== undefined) {
|
|
406
|
-
changes.push({ kind: 'preamble', path, value: parts.preamble.value });
|
|
471
|
+
changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
|
|
407
472
|
bases.push({ kind: 'preamble', path, value: parts.preamble.base });
|
|
408
473
|
}
|
|
409
474
|
if (parts.markdown !== undefined) {
|
|
@@ -415,7 +480,7 @@ export function changesOf(path, parts) {
|
|
|
415
480
|
if (base !== null && at !== path)
|
|
416
481
|
changes.push({ kind: 'move', path, to: at });
|
|
417
482
|
changes.push({ kind: 'binary', path: at, ...file });
|
|
418
|
-
if (base === null
|
|
483
|
+
if (base === null)
|
|
419
484
|
bases.push({ kind: 'absent', path: at });
|
|
420
485
|
return { changes, bases };
|
|
421
486
|
}
|
|
@@ -427,35 +492,6 @@ export function changesOf(path, parts) {
|
|
|
427
492
|
changes.push({ kind: 'remove', path });
|
|
428
493
|
return { changes, bases };
|
|
429
494
|
}
|
|
430
|
-
function rebased(before, after) {
|
|
431
|
-
return before === undefined ? after : { ...after, base: before.base };
|
|
432
|
-
}
|
|
433
|
-
function rebasedAll(before, after) {
|
|
434
|
-
return {
|
|
435
|
-
...before,
|
|
436
|
-
...Object.fromEntries(Object.entries(after).map(([name, part]) => [name, rebased(before?.[name], part)])),
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
export function joinedDraft(carried, saved) {
|
|
440
|
-
const draft = saved.find((item) => item.path === carried.path);
|
|
441
|
-
if (draft === undefined)
|
|
442
|
-
return carried;
|
|
443
|
-
const held = carried.parts;
|
|
444
|
-
const next = draft.parts;
|
|
445
|
-
return {
|
|
446
|
-
path: carried.path,
|
|
447
|
-
parts: {
|
|
448
|
-
...held,
|
|
449
|
-
...next,
|
|
450
|
-
...(next.fields === undefined ? {} : { fields: rebasedAll(held.fields, next.fields) }),
|
|
451
|
-
...(next.sections === undefined
|
|
452
|
-
? {}
|
|
453
|
-
: { sections: rebasedAll(held.sections, next.sections) }),
|
|
454
|
-
...(next.preamble === undefined ? {} : { preamble: rebased(held.preamble, next.preamble) }),
|
|
455
|
-
...(next.markdown === undefined ? {} : { markdown: rebased(held.markdown, next.markdown) }),
|
|
456
|
-
},
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
495
|
export function withdrawnDrafts(drafts, changes) {
|
|
460
496
|
return drafts.flatMap((draft) => {
|
|
461
497
|
const file = draft.parts.file;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ChangeSet } from './change-set.js';
|
|
2
|
+
import { type VisibleLayer } from './replica.js';
|
|
3
|
+
import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { Store } from './store.js';
|
|
6
|
+
export type RoomDraftSurface = {
|
|
7
|
+
list(): Promise<readonly RoomDraft[]>;
|
|
8
|
+
read(room: string, path: string): Promise<RoomDraft | null>;
|
|
9
|
+
write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
|
|
10
|
+
discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
|
|
11
|
+
};
|
|
12
|
+
export type PresentationSurface = {
|
|
13
|
+
read(app: string): Promise<unknown>;
|
|
14
|
+
write(app: string, value: unknown): Promise<void>;
|
|
15
|
+
edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
|
|
18
|
+
export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
|
|
19
|
+
export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
|
|
20
|
+
export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
|
|
21
|
+
export declare function presentationSurface(runtime: Runtime): PresentationSurface;
|
|
22
|
+
export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
|
|
23
|
+
export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
|
|
24
|
+
//# sourceMappingURL=room-drafts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-drafts.d.ts","sourceRoot":"","sources":["../src/room-drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAQL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAC5D,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAChF,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KA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