@agentshouse/mdruntime 0.1.0-cd3486bd400ed → 0.1.0-cd35ccee27a19
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 +22 -10
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +308 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +195 -91
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -41
- package/dist/attempt.d.ts.map +1 -1
- package/dist/attempt.js +14 -1
- package/dist/binary.d.ts +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +31 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +311 -92
- 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 +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +13 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -62
- package/dist/change.d.ts +42 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +36 -0
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +49 -21
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +131 -17
- package/dist/collection.d.ts +31 -9
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +49 -80
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +711 -0
- package/dist/connection.d.ts +8 -111
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +107 -2218
- 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 +136 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +249 -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 +71 -42
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1068 -586
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +148 -0
- package/dist/durability.d.ts +19 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +161 -0
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- 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 +28 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +163 -19
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +3 -0
- package/dist/index.d.ts +37 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/install.d.ts +54 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +538 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +272 -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 +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +33 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +50 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +24 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +289 -96
- package/dist/messages.d.ts +49 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +150 -0
- package/dist/model.d.ts +11 -12
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -15
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +156 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +127 -26
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +56 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +49 -0
- package/dist/overlay.d.ts +17 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +161 -187
- 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 +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -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 +233 -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 +270 -0
- package/dist/query.d.ts +51 -183
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -464
- package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +13 -2
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts +21 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +313 -72
- package/dist/react.d.ts +20 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +17 -18
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +49 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +174 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +232 -0
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +145 -58
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +53 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +348 -166
- package/dist/room-draft.d.ts +55 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -73
- 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 +30 -35
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +60 -126
- 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 +44 -22
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +950 -169
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +413 -0
- package/dist/search.d.ts +15 -55
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +145 -0
- package/dist/shared.d.ts +10 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +339 -0
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -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 +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -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 +170 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +5 -2
- 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 +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +430 -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 +109 -117
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +155 -494
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +649 -0
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +521 -0
- package/dist/tables.d.ts +412 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +737 -0
- 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/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +220 -34
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +73 -31
- package/package.json +27 -15
- package/AGENTS.md +0 -290
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/chat/acts.d.ts +0 -34
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/messages.d.ts +0 -21
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -151
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts +0 -57
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -119
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -57
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -637
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat.d.ts +0 -7
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -2
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -433
package/dist/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';
|
|
@@ -32,11 +33,24 @@ export type RoomDraftParts = {
|
|
|
32
33
|
readonly creation?: RoomDraftCreation;
|
|
33
34
|
readonly move?: {
|
|
34
35
|
readonly to: string;
|
|
36
|
+
readonly room?: string;
|
|
35
37
|
readonly base?: string | null;
|
|
36
38
|
};
|
|
37
39
|
readonly removal?: {
|
|
38
40
|
readonly base?: string | null;
|
|
39
41
|
};
|
|
42
|
+
readonly file?: {
|
|
43
|
+
readonly blob: Blob;
|
|
44
|
+
readonly base?: string | null;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type HeldFile = {
|
|
48
|
+
readonly localId: string;
|
|
49
|
+
readonly name?: string;
|
|
50
|
+
readonly byteLength: number;
|
|
51
|
+
readonly mediaType: string;
|
|
52
|
+
readonly sha256: string;
|
|
53
|
+
readonly base: string | null;
|
|
40
54
|
};
|
|
41
55
|
type HeldParts = {
|
|
42
56
|
readonly fields?: Readonly<Record<string, {
|
|
@@ -58,11 +72,13 @@ type HeldParts = {
|
|
|
58
72
|
readonly creation?: RoomDraftCreation;
|
|
59
73
|
readonly move?: {
|
|
60
74
|
readonly to: string;
|
|
75
|
+
readonly room?: string;
|
|
61
76
|
readonly base: string | null;
|
|
62
77
|
};
|
|
63
78
|
readonly removal?: {
|
|
64
79
|
readonly base: string | null;
|
|
65
80
|
};
|
|
81
|
+
readonly file?: HeldFile;
|
|
66
82
|
};
|
|
67
83
|
type ChangedUnderneath = {
|
|
68
84
|
readonly fields?: Readonly<Record<string, FieldValue>>;
|
|
@@ -72,11 +88,12 @@ type ChangedUnderneath = {
|
|
|
72
88
|
readonly creation?: string;
|
|
73
89
|
readonly move?: string | null;
|
|
74
90
|
readonly removal?: string | null;
|
|
91
|
+
readonly file?: string | null;
|
|
75
92
|
};
|
|
76
93
|
export type ReturnReason = ProviderRefusal & {
|
|
77
|
-
readonly kind: 'conflicted' | 'rejected' | '
|
|
94
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
|
|
78
95
|
};
|
|
79
|
-
export declare function returnedBy(
|
|
96
|
+
export declare function returnedBy(): ReturnReason;
|
|
80
97
|
export type RoomDraft = {
|
|
81
98
|
readonly room: string;
|
|
82
99
|
readonly path: string;
|
|
@@ -90,14 +107,12 @@ export type RoomDraftWrite = {
|
|
|
90
107
|
readonly roomDraft: RoomDraft | null;
|
|
91
108
|
} | {
|
|
92
109
|
readonly outcome: 'stale';
|
|
93
|
-
readonly code: string;
|
|
94
|
-
readonly retryable: boolean;
|
|
95
110
|
readonly current: RoomDraft | null;
|
|
96
111
|
};
|
|
97
112
|
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
98
113
|
export type ChangedPart = {
|
|
99
114
|
readonly path: string;
|
|
100
|
-
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | '
|
|
115
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
|
|
101
116
|
readonly name?: string;
|
|
102
117
|
};
|
|
103
118
|
export type RoomDraftRecord = {
|
|
@@ -111,17 +126,48 @@ export type SavedDraft = {
|
|
|
111
126
|
readonly path: string;
|
|
112
127
|
readonly parts: HeldParts;
|
|
113
128
|
};
|
|
114
|
-
export declare function readParts(value: unknown): RoomDraftParts;
|
|
115
|
-
export declare function
|
|
129
|
+
export declare function readParts(value: unknown, path: string): RoomDraftParts;
|
|
130
|
+
export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
|
|
131
|
+
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
116
132
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
117
|
-
export declare function
|
|
118
|
-
export declare function
|
|
133
|
+
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
134
|
+
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
135
|
+
export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
|
|
136
|
+
export declare function lineEnded(text: string): string;
|
|
137
|
+
export type TextParts = {
|
|
138
|
+
readonly fields?: Readonly<Record<string, {
|
|
139
|
+
readonly value: unknown;
|
|
140
|
+
}>>;
|
|
141
|
+
readonly sections?: Readonly<Record<string, {
|
|
142
|
+
readonly value: string;
|
|
143
|
+
}>>;
|
|
144
|
+
readonly preamble?: {
|
|
145
|
+
readonly value: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
export declare function partsAfter(markdown: string, parts: TextParts, definitions?: DefinitionOf): string;
|
|
149
|
+
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts, definitions?: DefinitionOf): HeldParts;
|
|
119
150
|
export declare function moveTarget(move: {
|
|
120
151
|
readonly to: string;
|
|
121
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
|
+
};
|
|
122
167
|
export declare function changesOf(path: string, parts: HeldParts): {
|
|
123
168
|
changes: readonly Change[];
|
|
124
169
|
bases: readonly Precondition[];
|
|
125
170
|
};
|
|
171
|
+
export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
|
|
126
172
|
export {};
|
|
127
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,OAAO,EASL,KAAK,YAAY,EAElB,MAAM,sBAAsB,CAAC;AAC9B,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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AQ,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,58 +1,68 @@
|
|
|
1
|
-
import { apply, equalValue, frontmatterValue, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, create, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
|
+
import { sha256 } from './digest.js';
|
|
4
|
+
import { binaryLocalId } from './identity.js';
|
|
3
5
|
import { normalize } from './paths.js';
|
|
4
|
-
export function returnedBy(
|
|
5
|
-
return { kind, code:
|
|
6
|
+
export function returnedBy() {
|
|
7
|
+
return { kind: 'withdrawn', code: 'withdrawn', fields: {}, retryable: false };
|
|
6
8
|
}
|
|
7
9
|
export function staleWrite(current) {
|
|
8
|
-
return { outcome: 'stale',
|
|
10
|
+
return { outcome: 'stale', current };
|
|
9
11
|
}
|
|
10
|
-
function malformed() {
|
|
11
|
-
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}`);
|
|
12
14
|
}
|
|
13
15
|
function plain(value) {
|
|
14
16
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
17
|
}
|
|
16
|
-
function text(value) {
|
|
17
|
-
return typeof value === 'string' ? value : malformed();
|
|
18
|
+
function text(value, at) {
|
|
19
|
+
return typeof value === 'string' ? value : malformed(at, 'text');
|
|
18
20
|
}
|
|
19
|
-
function optionalText(value) {
|
|
20
|
-
return value === undefined ? undefined : text(value);
|
|
21
|
+
function optionalText(value, at) {
|
|
22
|
+
return value === undefined ? undefined : text(value, at);
|
|
21
23
|
}
|
|
22
|
-
function markdownBase(value) {
|
|
23
|
-
return value === null ? null : optionalText(value);
|
|
24
|
+
function markdownBase(value, at) {
|
|
25
|
+
return value === null ? null : optionalText(value, at);
|
|
24
26
|
}
|
|
25
|
-
function entries(value, each) {
|
|
27
|
+
function entries(value, at, each) {
|
|
26
28
|
if (!plain(value))
|
|
27
|
-
malformed();
|
|
29
|
+
malformed(at, 'an object of named values');
|
|
28
30
|
const read = {};
|
|
29
31
|
for (const [name, item] of Object.entries(value))
|
|
30
|
-
read[name] = each(item);
|
|
32
|
+
read[name] = each(item, `${at}.${name}`);
|
|
31
33
|
return read;
|
|
32
34
|
}
|
|
33
|
-
function
|
|
35
|
+
function frontmatter(item, at) {
|
|
36
|
+
return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
|
|
37
|
+
}
|
|
38
|
+
function fieldValue(value, at) {
|
|
34
39
|
if (value === null)
|
|
35
40
|
return null;
|
|
36
41
|
if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
|
|
37
|
-
malformed();
|
|
42
|
+
malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
|
|
38
43
|
}
|
|
39
44
|
return { value: value.value };
|
|
40
45
|
}
|
|
41
|
-
function textPart(value) {
|
|
46
|
+
function textPart(value, at) {
|
|
42
47
|
if (!plain(value))
|
|
43
|
-
malformed();
|
|
44
|
-
const base = optionalText(value.base);
|
|
45
|
-
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 }) };
|
|
46
51
|
}
|
|
47
|
-
function creationOf(value) {
|
|
52
|
+
function creationOf(value, at) {
|
|
48
53
|
if (!plain(value))
|
|
49
|
-
malformed();
|
|
54
|
+
malformed(at, '{ type, fields, sections }, or { markdown }');
|
|
50
55
|
if (Object.hasOwn(value, 'markdown'))
|
|
51
|
-
return { markdown: text(value.markdown) };
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
};
|
|
54
64
|
}
|
|
55
|
-
const PART_NAMES =
|
|
65
|
+
const PART_NAMES = [
|
|
56
66
|
'fields',
|
|
57
67
|
'sections',
|
|
58
68
|
'preamble',
|
|
@@ -60,41 +70,59 @@ const PART_NAMES = new Set([
|
|
|
60
70
|
'creation',
|
|
61
71
|
'move',
|
|
62
72
|
'removal',
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
'file',
|
|
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);
|
|
67
82
|
const parts = {};
|
|
68
83
|
if (value.fields !== undefined) {
|
|
69
|
-
parts.fields = entries(value.fields, (item) => {
|
|
84
|
+
parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
|
|
70
85
|
if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
|
|
71
|
-
malformed();
|
|
86
|
+
malformed(at, '{ value, base } with a frontmatter value');
|
|
72
87
|
}
|
|
73
88
|
return item.base === undefined
|
|
74
89
|
? { value: item.value }
|
|
75
|
-
: { value: item.value, base: fieldValue(item.base) };
|
|
90
|
+
: { value: item.value, base: fieldValue(item.base, `${at}.base`) };
|
|
76
91
|
});
|
|
77
92
|
}
|
|
78
93
|
if (value.sections !== undefined)
|
|
79
|
-
parts.sections = entries(value.sections, textPart);
|
|
94
|
+
parts.sections = entries(value.sections, `${path} sections`, textPart);
|
|
80
95
|
if (value.preamble !== undefined)
|
|
81
|
-
parts.preamble = textPart(value.preamble);
|
|
96
|
+
parts.preamble = textPart(value.preamble, `${path} preamble`);
|
|
82
97
|
if (value.markdown !== undefined)
|
|
83
|
-
parts.markdown = textPart(value.markdown);
|
|
98
|
+
parts.markdown = textPart(value.markdown, `${path} markdown`);
|
|
84
99
|
if (value.creation !== undefined)
|
|
85
|
-
parts.creation = creationOf(value.creation);
|
|
100
|
+
parts.creation = creationOf(value.creation, `${path} creation`);
|
|
86
101
|
if (value.move !== undefined) {
|
|
87
102
|
if (!plain(value.move))
|
|
88
|
-
malformed();
|
|
89
|
-
const base = markdownBase(value.move.base);
|
|
90
|
-
|
|
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`);
|
|
106
|
+
parts.move = {
|
|
107
|
+
to: text(value.move.to, `${path} move.to`),
|
|
108
|
+
...(room === undefined ? {} : { room }),
|
|
109
|
+
...(base === undefined ? {} : { base }),
|
|
110
|
+
};
|
|
91
111
|
}
|
|
92
112
|
if (value.removal !== undefined) {
|
|
93
113
|
if (!plain(value.removal))
|
|
94
|
-
malformed();
|
|
95
|
-
const base = markdownBase(value.removal.base);
|
|
114
|
+
malformed(`${path} removal`, '{ base }');
|
|
115
|
+
const base = markdownBase(value.removal.base, `${path} removal.base`);
|
|
96
116
|
parts.removal = base === undefined ? {} : { base };
|
|
97
117
|
}
|
|
118
|
+
if (value.file !== undefined) {
|
|
119
|
+
if (!plain(value.file) || !(value.file.blob instanceof Blob))
|
|
120
|
+
malformed(`${path} file`, '{ blob, base } with a Blob');
|
|
121
|
+
if (Object.keys(value).length > 1)
|
|
122
|
+
throw runtimeError('room-draft-file-exclusive');
|
|
123
|
+
const base = markdownBase(value.file.base, `${path} file.base`);
|
|
124
|
+
parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
|
|
125
|
+
}
|
|
98
126
|
return parts;
|
|
99
127
|
}
|
|
100
128
|
function named(record) {
|
|
@@ -110,15 +138,76 @@ function kept(prior, base) {
|
|
|
110
138
|
throw runtimeError('room-draft-base-missing');
|
|
111
139
|
return base;
|
|
112
140
|
}
|
|
141
|
+
function movePart(current, move) {
|
|
142
|
+
return {
|
|
143
|
+
to: move.to,
|
|
144
|
+
...(move.room === undefined ? {} : { room: move.room }),
|
|
145
|
+
base: kept(current, move.base),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
113
148
|
function editsText(parts) {
|
|
114
149
|
return (parts.preamble !== undefined ||
|
|
115
150
|
named(parts.fields).length > 0 ||
|
|
116
151
|
named(parts.sections).length > 0);
|
|
117
152
|
}
|
|
118
|
-
|
|
153
|
+
function partNames(parts) {
|
|
154
|
+
const names = [];
|
|
155
|
+
for (const [name, part] of Object.entries(parts)) {
|
|
156
|
+
if (name === 'preamble' || name === 'markdown')
|
|
157
|
+
names.push(name);
|
|
158
|
+
else if ((name === 'fields' || name === 'sections') && plain(part))
|
|
159
|
+
names.push(...Object.keys(part).map((one) => `${name}/${one}`));
|
|
160
|
+
else
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
return names.sort().join('\u0000');
|
|
164
|
+
}
|
|
165
|
+
function withBaseOf(prior, part) {
|
|
166
|
+
return plain(part) && plain(prior) && Object.hasOwn(prior, 'base')
|
|
167
|
+
? { ...part, base: prior.base }
|
|
168
|
+
: part;
|
|
169
|
+
}
|
|
170
|
+
export function gatheredParts(earlier, later) {
|
|
171
|
+
if (!plain(earlier) || !plain(later))
|
|
172
|
+
return null;
|
|
173
|
+
const named = partNames(earlier);
|
|
174
|
+
if (named === null || named !== partNames(later))
|
|
175
|
+
return null;
|
|
176
|
+
return Object.fromEntries(Object.entries(later).map(([name, part]) => [
|
|
177
|
+
name,
|
|
178
|
+
name === 'fields' || name === 'sections'
|
|
179
|
+
? Object.fromEntries(Object.entries(part).map(([one, value]) => [
|
|
180
|
+
one,
|
|
181
|
+
withBaseOf(earlier[name][one], value),
|
|
182
|
+
]))
|
|
183
|
+
: withBaseOf(earlier[name], part),
|
|
184
|
+
]));
|
|
185
|
+
}
|
|
186
|
+
export function held(current, parts, file) {
|
|
119
187
|
if (parts.markdown !== undefined && editsText(parts)) {
|
|
120
188
|
throw runtimeError('room-draft-markdown-exclusive');
|
|
121
189
|
}
|
|
190
|
+
if (file !== undefined) {
|
|
191
|
+
if (current !== undefined && current.file === undefined) {
|
|
192
|
+
throw runtimeError('room-draft-file-exclusive');
|
|
193
|
+
}
|
|
194
|
+
return { file: { ...file, base: current?.file === undefined ? file.base : current.file.base } };
|
|
195
|
+
}
|
|
196
|
+
if (current?.file !== undefined) {
|
|
197
|
+
if (editsText(parts) ||
|
|
198
|
+
parts.markdown !== undefined ||
|
|
199
|
+
parts.creation !== undefined ||
|
|
200
|
+
(parts.move === undefined && parts.removal === undefined)) {
|
|
201
|
+
throw runtimeError('room-draft-file-exclusive');
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
file: current.file,
|
|
205
|
+
...(parts.move === undefined ? {} : { move: movePart(current.move, parts.move) }),
|
|
206
|
+
...(parts.removal === undefined
|
|
207
|
+
? {}
|
|
208
|
+
: { removal: { base: kept(current.removal, parts.removal.base) } }),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
122
211
|
const next = {};
|
|
123
212
|
const fields = named(parts.fields);
|
|
124
213
|
if (fields.length > 0) {
|
|
@@ -148,9 +237,8 @@ export function held(current, parts) {
|
|
|
148
237
|
}
|
|
149
238
|
if (parts.creation !== undefined)
|
|
150
239
|
next.creation = parts.creation;
|
|
151
|
-
if (parts.move !== undefined)
|
|
152
|
-
next.move =
|
|
153
|
-
}
|
|
240
|
+
if (parts.move !== undefined)
|
|
241
|
+
next.move = movePart(current?.move, parts.move);
|
|
154
242
|
if (parts.removal !== undefined) {
|
|
155
243
|
next.removal = { base: kept(current?.removal, parts.removal.base) };
|
|
156
244
|
}
|
|
@@ -198,17 +286,41 @@ export function underneath(parts, path, visible) {
|
|
|
198
286
|
report.move = markdown;
|
|
199
287
|
if (parts.removal !== undefined && markdown !== parts.removal.base)
|
|
200
288
|
report.removal = markdown;
|
|
289
|
+
if (parts.file !== undefined) {
|
|
290
|
+
const file = binaryBase(visible, path);
|
|
291
|
+
if (file !== parts.file.base || markdown !== null)
|
|
292
|
+
report.file = file;
|
|
293
|
+
}
|
|
201
294
|
return report;
|
|
202
295
|
}
|
|
203
|
-
|
|
296
|
+
const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
|
|
297
|
+
export async function heldFile(blob, base) {
|
|
298
|
+
return {
|
|
299
|
+
localId: binaryLocalId(),
|
|
300
|
+
...(blob instanceof File ? { name: blob.name } : {}),
|
|
301
|
+
byteLength: blob.size,
|
|
302
|
+
mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
|
|
303
|
+
sha256: await sha256(blob),
|
|
304
|
+
base,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
export function binaryBase(visible, path) {
|
|
308
|
+
const binary = visible?.binaries[path];
|
|
309
|
+
if (binary === undefined)
|
|
310
|
+
return null;
|
|
311
|
+
return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
|
|
312
|
+
}
|
|
313
|
+
export function changedParts(path, parts, visible) {
|
|
314
|
+
const report = underneath(parts, path, visible);
|
|
315
|
+
const made = parts.file?.base === null;
|
|
204
316
|
return [
|
|
205
|
-
...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
|
|
206
317
|
...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
|
|
207
318
|
...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
|
|
208
319
|
...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
|
|
209
320
|
...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
|
|
210
321
|
...(report.move === undefined ? [] : [{ path, part: 'move' }]),
|
|
211
322
|
...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
|
|
323
|
+
...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
|
|
212
324
|
];
|
|
213
325
|
}
|
|
214
326
|
function joined(existing, returned) {
|
|
@@ -218,34 +330,46 @@ function joined(existing, returned) {
|
|
|
218
330
|
merged[name] = part;
|
|
219
331
|
return Object.keys(merged).length === 0 ? undefined : merged;
|
|
220
332
|
}
|
|
221
|
-
function
|
|
333
|
+
export function lineEnded(text) {
|
|
222
334
|
return text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
223
335
|
}
|
|
224
|
-
function
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (next.outcome !== 'applied')
|
|
232
|
-
return malformed();
|
|
233
|
-
document = next.document;
|
|
234
|
-
}
|
|
235
|
-
return serialize(document);
|
|
336
|
+
function written(start, changes, definition) {
|
|
337
|
+
const next = apply(start, changes, definition);
|
|
338
|
+
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
339
|
+
}
|
|
340
|
+
function empty(definition) {
|
|
341
|
+
const parsed = parse('', '', definition);
|
|
342
|
+
return parsed.ok ? parsed.document : malformed();
|
|
236
343
|
}
|
|
237
|
-
function
|
|
344
|
+
export function partsAfter(markdown, parts, definitions) {
|
|
238
345
|
const fields = named(parts.fields);
|
|
346
|
+
const sections = named(parts.sections);
|
|
347
|
+
if (fields.length === 0 && sections.length === 0 && parts.preamble === undefined)
|
|
348
|
+
return markdown;
|
|
349
|
+
const whole = parse(markdown, '', definitions);
|
|
350
|
+
const definition = whole.ok ? definitions?.(whole.document.type) : undefined;
|
|
351
|
+
const head = [
|
|
352
|
+
...fields.map(([name, part]) => ({
|
|
353
|
+
kind: 'field',
|
|
354
|
+
name,
|
|
355
|
+
value: part.value,
|
|
356
|
+
prior: undefined,
|
|
357
|
+
})),
|
|
358
|
+
...(parts.preamble === undefined
|
|
359
|
+
? []
|
|
360
|
+
: [{ kind: 'preamble', value: lineEnded(parts.preamble.value), prior: '' }]),
|
|
361
|
+
];
|
|
239
362
|
const pieces = [
|
|
240
|
-
...(
|
|
241
|
-
|
|
242
|
-
|
|
363
|
+
...(head.length === 0
|
|
364
|
+
? []
|
|
365
|
+
: [
|
|
366
|
+
written(fields.length === 0 ? empty(definition) : create(undefined, definition), head, definition),
|
|
367
|
+
]),
|
|
368
|
+
...sections.map(([name, part]) => written(empty(definition), [{ kind: 'section', name, value: lineEnded(part.value), prior: undefined }], definition)),
|
|
243
369
|
];
|
|
244
|
-
|
|
245
|
-
return markdown;
|
|
246
|
-
return `${ended(markdown)}\n${pieces.map(ended).join('')}`;
|
|
370
|
+
return `${lineEnded(markdown)}\n${pieces.join('')}`;
|
|
247
371
|
}
|
|
248
|
-
export function returnedInto(existing, returned) {
|
|
372
|
+
export function returnedInto(existing, returned, definitions) {
|
|
249
373
|
if (existing === undefined)
|
|
250
374
|
return returned;
|
|
251
375
|
const next = { ...existing };
|
|
@@ -265,24 +389,57 @@ export function returnedInto(existing, returned) {
|
|
|
265
389
|
delete next.fields;
|
|
266
390
|
delete next.sections;
|
|
267
391
|
delete next.preamble;
|
|
268
|
-
const value =
|
|
392
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned, definitions);
|
|
269
393
|
next.markdown = { value, base: whole.base };
|
|
270
394
|
}
|
|
271
395
|
const creation = existing.creation ?? returned.creation;
|
|
272
396
|
const move = existing.move ?? returned.move;
|
|
273
397
|
const removal = existing.removal ?? returned.removal;
|
|
398
|
+
const file = existing.file ?? returned.file;
|
|
274
399
|
if (creation !== undefined)
|
|
275
400
|
next.creation = creation;
|
|
276
401
|
if (move !== undefined)
|
|
277
402
|
next.move = move;
|
|
278
403
|
if (removal !== undefined)
|
|
279
404
|
next.removal = removal;
|
|
405
|
+
if (file !== undefined)
|
|
406
|
+
next.file = file;
|
|
280
407
|
return next;
|
|
281
408
|
}
|
|
282
409
|
export function moveTarget(move) {
|
|
283
410
|
const to = normalize(move.to);
|
|
284
411
|
return to === null || to === '' ? move.to : to;
|
|
285
412
|
}
|
|
413
|
+
export function readSavedParts(named) {
|
|
414
|
+
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts, path) }));
|
|
415
|
+
read.forEach(({ path }, at) => {
|
|
416
|
+
if (path === '' || normalize(path) !== path)
|
|
417
|
+
malformed(path, 'a path inside the Room, such as notes/a.md');
|
|
418
|
+
if (read.findIndex((one) => one.path === path) !== at)
|
|
419
|
+
malformed(path, 'each path once in one save');
|
|
420
|
+
});
|
|
421
|
+
return read;
|
|
422
|
+
}
|
|
423
|
+
export function partsChanges(named) {
|
|
424
|
+
const changes = [];
|
|
425
|
+
const preconditions = [];
|
|
426
|
+
for (const { path, parts } of readSavedParts(named)) {
|
|
427
|
+
const parted = held(undefined, parts);
|
|
428
|
+
const made = changesOf(path, parted);
|
|
429
|
+
changes.push(...made.changes);
|
|
430
|
+
preconditions.push(...made.bases);
|
|
431
|
+
for (const change of made.changes) {
|
|
432
|
+
if (change.kind === 'create')
|
|
433
|
+
preconditions.push({ kind: 'absent', path });
|
|
434
|
+
if (change.kind === 'move')
|
|
435
|
+
preconditions.push({ kind: 'absent', path: change.to });
|
|
436
|
+
}
|
|
437
|
+
const revision = parted.markdown?.base ?? parted.move?.base ?? parted.removal?.base;
|
|
438
|
+
if (typeof revision === 'string')
|
|
439
|
+
preconditions.push({ kind: 'revision', path, revision });
|
|
440
|
+
}
|
|
441
|
+
return { changes, preconditions };
|
|
442
|
+
}
|
|
286
443
|
export function changesOf(path, parts) {
|
|
287
444
|
const changes = [];
|
|
288
445
|
const bases = [];
|
|
@@ -302,19 +459,51 @@ export function changesOf(path, parts) {
|
|
|
302
459
|
bases.push({ kind: 'field', path, name, value: part.base?.value });
|
|
303
460
|
}
|
|
304
461
|
for (const [name, part] of named(parts.sections)) {
|
|
305
|
-
changes.push({ kind: 'section', path, name, value: part.value });
|
|
462
|
+
changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
|
|
306
463
|
bases.push({ kind: 'section', path, name, value: part.base });
|
|
307
464
|
}
|
|
308
465
|
if (parts.preamble !== undefined) {
|
|
309
|
-
changes.push({ kind: 'preamble', path, value: parts.preamble.value });
|
|
466
|
+
changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
|
|
310
467
|
bases.push({ kind: 'preamble', path, value: parts.preamble.base });
|
|
311
468
|
}
|
|
312
469
|
if (parts.markdown !== undefined) {
|
|
313
470
|
changes.push({ kind: 'replace', path, content: parts.markdown.value });
|
|
314
471
|
}
|
|
472
|
+
if (parts.file !== undefined && parts.removal === undefined) {
|
|
473
|
+
const { base, name: _name, ...file } = parts.file;
|
|
474
|
+
const at = parts.move === undefined ? path : moveTarget(parts.move);
|
|
475
|
+
if (base !== null && at !== path)
|
|
476
|
+
changes.push({ kind: 'move', path, to: at });
|
|
477
|
+
changes.push({ kind: 'binary', path: at, ...file });
|
|
478
|
+
if (base === null)
|
|
479
|
+
bases.push({ kind: 'absent', path: at });
|
|
480
|
+
return { changes, bases };
|
|
481
|
+
}
|
|
482
|
+
if (parts.file?.base === null)
|
|
483
|
+
return { changes, bases };
|
|
315
484
|
if (parts.move !== undefined)
|
|
316
485
|
changes.push({ kind: 'move', path, to: moveTarget(parts.move) });
|
|
317
486
|
if (parts.removal !== undefined)
|
|
318
487
|
changes.push({ kind: 'remove', path });
|
|
319
488
|
return { changes, bases };
|
|
320
489
|
}
|
|
490
|
+
export function withdrawnDrafts(drafts, changes) {
|
|
491
|
+
return drafts.flatMap((draft) => {
|
|
492
|
+
const file = draft.parts.file;
|
|
493
|
+
const at = draft.parts.move?.to ?? draft.path;
|
|
494
|
+
const change = changes.find((item) => (item.kind === 'move' || item.kind === 'remove') && item.path === at);
|
|
495
|
+
if (file === undefined || change === undefined)
|
|
496
|
+
return [draft];
|
|
497
|
+
if (change.kind === 'move') {
|
|
498
|
+
return [
|
|
499
|
+
{
|
|
500
|
+
path: draft.path,
|
|
501
|
+
parts: change.to === draft.path ? { file } : { file, move: { to: change.to, base: null } },
|
|
502
|
+
},
|
|
503
|
+
];
|
|
504
|
+
}
|
|
505
|
+
return file.base === null
|
|
506
|
+
? []
|
|
507
|
+
: [{ path: draft.path, parts: { file, removal: { base: null } } }];
|
|
508
|
+
});
|
|
509
|
+
}
|
|
@@ -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
|