@agentshouse/mdruntime 0.1.0-cf24798931067 → 0.1.0-cf281e8224a5d
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 +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +385 -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 +177 -54
- 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 +324 -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 +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -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 +50 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +110 -9
- package/dist/collection.d.ts +11 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +38 -79
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +711 -0
- package/dist/connection.d.ts +8 -111
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +104 -2219
- 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 +248 -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 +57 -40
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +992 -543
- 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 +175 -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/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 +12 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +132 -18
- 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 +35 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +554 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +268 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +176 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +163 -0
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +61 -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 +61 -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 +21 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +271 -91
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +162 -0
- package/dist/model.d.ts +11 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -10
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +195 -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 +57 -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 +16 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +140 -177
- package/dist/{chat/parts.d.ts → parts.d.ts} +12 -9
- package/dist/parts.d.ts.map +1 -0
- package/dist/{chat/parts.js → parts.js} +53 -46
- 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 +226 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -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/reach.d.ts +21 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +291 -69
- 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 +171 -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 +143 -56
- 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 +59 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +342 -158
- package/dist/room-draft.d.ts +54 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +268 -63
- 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 +59 -124
- package/dist/runtime.d.ts +43 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +74 -3
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +812 -153
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1005 -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 +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +292 -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/rooms.d.ts +44 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -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 +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -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/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/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 +431 -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 +106 -117
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +137 -496
- 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 +532 -0
- package/dist/tables.d.ts +416 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +740 -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 +181 -31
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +62 -29
- package/package.json +26 -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.map +0 -1
- 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
|
@@ -32,11 +32,24 @@ export type RoomDraftParts = {
|
|
|
32
32
|
readonly creation?: RoomDraftCreation;
|
|
33
33
|
readonly move?: {
|
|
34
34
|
readonly to: string;
|
|
35
|
+
readonly room?: string;
|
|
35
36
|
readonly base?: string | null;
|
|
36
37
|
};
|
|
37
38
|
readonly removal?: {
|
|
38
39
|
readonly base?: string | null;
|
|
39
40
|
};
|
|
41
|
+
readonly file?: {
|
|
42
|
+
readonly blob: Blob;
|
|
43
|
+
readonly base?: string | null;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type HeldFile = {
|
|
47
|
+
readonly localId: string;
|
|
48
|
+
readonly name?: string;
|
|
49
|
+
readonly byteLength: number;
|
|
50
|
+
readonly mediaType: string;
|
|
51
|
+
readonly sha256: string;
|
|
52
|
+
readonly base: string | null;
|
|
40
53
|
};
|
|
41
54
|
type HeldParts = {
|
|
42
55
|
readonly fields?: Readonly<Record<string, {
|
|
@@ -58,11 +71,13 @@ type HeldParts = {
|
|
|
58
71
|
readonly creation?: RoomDraftCreation;
|
|
59
72
|
readonly move?: {
|
|
60
73
|
readonly to: string;
|
|
74
|
+
readonly room?: string;
|
|
61
75
|
readonly base: string | null;
|
|
62
76
|
};
|
|
63
77
|
readonly removal?: {
|
|
64
78
|
readonly base: string | null;
|
|
65
79
|
};
|
|
80
|
+
readonly file?: HeldFile;
|
|
66
81
|
};
|
|
67
82
|
type ChangedUnderneath = {
|
|
68
83
|
readonly fields?: Readonly<Record<string, FieldValue>>;
|
|
@@ -72,11 +87,12 @@ type ChangedUnderneath = {
|
|
|
72
87
|
readonly creation?: string;
|
|
73
88
|
readonly move?: string | null;
|
|
74
89
|
readonly removal?: string | null;
|
|
90
|
+
readonly file?: string | null;
|
|
75
91
|
};
|
|
76
92
|
export type ReturnReason = ProviderRefusal & {
|
|
77
|
-
readonly kind: 'conflicted' | 'rejected' | '
|
|
93
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
|
|
78
94
|
};
|
|
79
|
-
export declare function returnedBy(
|
|
95
|
+
export declare function returnedBy(): ReturnReason;
|
|
80
96
|
export type RoomDraft = {
|
|
81
97
|
readonly room: string;
|
|
82
98
|
readonly path: string;
|
|
@@ -90,14 +106,12 @@ export type RoomDraftWrite = {
|
|
|
90
106
|
readonly roomDraft: RoomDraft | null;
|
|
91
107
|
} | {
|
|
92
108
|
readonly outcome: 'stale';
|
|
93
|
-
readonly code: string;
|
|
94
|
-
readonly retryable: boolean;
|
|
95
109
|
readonly current: RoomDraft | null;
|
|
96
110
|
};
|
|
97
111
|
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
98
112
|
export type ChangedPart = {
|
|
99
113
|
readonly path: string;
|
|
100
|
-
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | '
|
|
114
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
|
|
101
115
|
readonly name?: string;
|
|
102
116
|
};
|
|
103
117
|
export type RoomDraftRecord = {
|
|
@@ -111,17 +125,49 @@ export type SavedDraft = {
|
|
|
111
125
|
readonly path: string;
|
|
112
126
|
readonly parts: HeldParts;
|
|
113
127
|
};
|
|
114
|
-
export declare function readParts(value: unknown): RoomDraftParts;
|
|
115
|
-
export declare function
|
|
128
|
+
export declare function readParts(value: unknown, path: string): RoomDraftParts;
|
|
129
|
+
export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
|
|
130
|
+
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
116
131
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
117
|
-
export declare function
|
|
132
|
+
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
133
|
+
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
134
|
+
export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
|
|
135
|
+
export declare function lineEnded(text: string): string;
|
|
136
|
+
export type TextParts = {
|
|
137
|
+
readonly fields?: Readonly<Record<string, {
|
|
138
|
+
readonly value: unknown;
|
|
139
|
+
}>>;
|
|
140
|
+
readonly sections?: Readonly<Record<string, {
|
|
141
|
+
readonly value: string;
|
|
142
|
+
}>>;
|
|
143
|
+
readonly preamble?: {
|
|
144
|
+
readonly value: string;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
export declare function partsAfter(markdown: string, parts: TextParts): string;
|
|
118
148
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
119
149
|
export declare function moveTarget(move: {
|
|
120
150
|
readonly to: string;
|
|
121
151
|
}): string;
|
|
152
|
+
export declare function readSavedParts(named: readonly {
|
|
153
|
+
readonly path: string;
|
|
154
|
+
readonly parts: unknown;
|
|
155
|
+
}[]): readonly {
|
|
156
|
+
readonly path: string;
|
|
157
|
+
readonly parts: RoomDraftParts;
|
|
158
|
+
}[];
|
|
159
|
+
export declare function partsChanges(named: readonly {
|
|
160
|
+
readonly path: string;
|
|
161
|
+
readonly parts: unknown;
|
|
162
|
+
}[]): {
|
|
163
|
+
readonly changes: readonly Change[];
|
|
164
|
+
readonly preconditions: readonly Precondition[];
|
|
165
|
+
};
|
|
122
166
|
export declare function changesOf(path: string, parts: HeldParts): {
|
|
123
167
|
changes: readonly Change[];
|
|
124
168
|
bases: readonly Precondition[];
|
|
125
169
|
};
|
|
170
|
+
export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
|
|
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":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ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ACzB,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, 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,23 +330,22 @@ 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
336
|
function frontmatterOf(fields) {
|
|
225
337
|
const opened = parse('---\n---\n');
|
|
226
338
|
if (!opened.ok)
|
|
227
339
|
return malformed();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return serialize(document);
|
|
340
|
+
const next = apply(opened.document, fields.map(([name, part]) => ({
|
|
341
|
+
kind: 'field',
|
|
342
|
+
name,
|
|
343
|
+
value: part.value,
|
|
344
|
+
prior: undefined,
|
|
345
|
+
})));
|
|
346
|
+
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
236
347
|
}
|
|
237
|
-
function
|
|
348
|
+
export function partsAfter(markdown, parts) {
|
|
238
349
|
const fields = named(parts.fields);
|
|
239
350
|
const pieces = [
|
|
240
351
|
...(fields.length === 0 ? [] : [frontmatterOf(fields)]),
|
|
@@ -243,7 +354,7 @@ function concatenated(markdown, parts) {
|
|
|
243
354
|
];
|
|
244
355
|
if (pieces.length === 0)
|
|
245
356
|
return markdown;
|
|
246
|
-
return `${
|
|
357
|
+
return `${lineEnded(markdown)}\n${pieces.map(lineEnded).join('')}`;
|
|
247
358
|
}
|
|
248
359
|
export function returnedInto(existing, returned) {
|
|
249
360
|
if (existing === undefined)
|
|
@@ -265,24 +376,57 @@ export function returnedInto(existing, returned) {
|
|
|
265
376
|
delete next.fields;
|
|
266
377
|
delete next.sections;
|
|
267
378
|
delete next.preamble;
|
|
268
|
-
const value =
|
|
379
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
|
|
269
380
|
next.markdown = { value, base: whole.base };
|
|
270
381
|
}
|
|
271
382
|
const creation = existing.creation ?? returned.creation;
|
|
272
383
|
const move = existing.move ?? returned.move;
|
|
273
384
|
const removal = existing.removal ?? returned.removal;
|
|
385
|
+
const file = existing.file ?? returned.file;
|
|
274
386
|
if (creation !== undefined)
|
|
275
387
|
next.creation = creation;
|
|
276
388
|
if (move !== undefined)
|
|
277
389
|
next.move = move;
|
|
278
390
|
if (removal !== undefined)
|
|
279
391
|
next.removal = removal;
|
|
392
|
+
if (file !== undefined)
|
|
393
|
+
next.file = file;
|
|
280
394
|
return next;
|
|
281
395
|
}
|
|
282
396
|
export function moveTarget(move) {
|
|
283
397
|
const to = normalize(move.to);
|
|
284
398
|
return to === null || to === '' ? move.to : to;
|
|
285
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
|
+
}
|
|
286
430
|
export function changesOf(path, parts) {
|
|
287
431
|
const changes = [];
|
|
288
432
|
const bases = [];
|
|
@@ -302,19 +446,80 @@ export function changesOf(path, parts) {
|
|
|
302
446
|
bases.push({ kind: 'field', path, name, value: part.base?.value });
|
|
303
447
|
}
|
|
304
448
|
for (const [name, part] of named(parts.sections)) {
|
|
305
|
-
changes.push({ kind: 'section', path, name, value: part.value });
|
|
449
|
+
changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
|
|
306
450
|
bases.push({ kind: 'section', path, name, value: part.base });
|
|
307
451
|
}
|
|
308
452
|
if (parts.preamble !== undefined) {
|
|
309
|
-
changes.push({ kind: 'preamble', path, value: parts.preamble.value });
|
|
453
|
+
changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
|
|
310
454
|
bases.push({ kind: 'preamble', path, value: parts.preamble.base });
|
|
311
455
|
}
|
|
312
456
|
if (parts.markdown !== undefined) {
|
|
313
457
|
changes.push({ kind: 'replace', path, content: parts.markdown.value });
|
|
314
458
|
}
|
|
459
|
+
if (parts.file !== undefined && parts.removal === undefined) {
|
|
460
|
+
const { base, name: _name, ...file } = parts.file;
|
|
461
|
+
const at = parts.move === undefined ? path : moveTarget(parts.move);
|
|
462
|
+
if (base !== null && at !== path)
|
|
463
|
+
changes.push({ kind: 'move', path, to: at });
|
|
464
|
+
changes.push({ kind: 'binary', path: at, ...file });
|
|
465
|
+
if (base === null)
|
|
466
|
+
bases.push({ kind: 'absent', path: at });
|
|
467
|
+
return { changes, bases };
|
|
468
|
+
}
|
|
469
|
+
if (parts.file?.base === null)
|
|
470
|
+
return { changes, bases };
|
|
315
471
|
if (parts.move !== undefined)
|
|
316
472
|
changes.push({ kind: 'move', path, to: moveTarget(parts.move) });
|
|
317
473
|
if (parts.removal !== undefined)
|
|
318
474
|
changes.push({ kind: 'remove', path });
|
|
319
475
|
return { changes, bases };
|
|
320
476
|
}
|
|
477
|
+
function rebased(before, after) {
|
|
478
|
+
return before === undefined ? after : { ...after, base: before.base };
|
|
479
|
+
}
|
|
480
|
+
function rebasedAll(before, after) {
|
|
481
|
+
return {
|
|
482
|
+
...before,
|
|
483
|
+
...Object.fromEntries(Object.entries(after).map(([name, part]) => [name, rebased(before?.[name], part)])),
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
export function joinedDraft(carried, saved) {
|
|
487
|
+
const draft = saved.find((item) => item.path === carried.path);
|
|
488
|
+
if (draft === undefined)
|
|
489
|
+
return carried;
|
|
490
|
+
const held = carried.parts;
|
|
491
|
+
const next = draft.parts;
|
|
492
|
+
return {
|
|
493
|
+
path: carried.path,
|
|
494
|
+
parts: {
|
|
495
|
+
...held,
|
|
496
|
+
...next,
|
|
497
|
+
...(next.fields === undefined ? {} : { fields: rebasedAll(held.fields, next.fields) }),
|
|
498
|
+
...(next.sections === undefined
|
|
499
|
+
? {}
|
|
500
|
+
: { sections: rebasedAll(held.sections, next.sections) }),
|
|
501
|
+
...(next.preamble === undefined ? {} : { preamble: rebased(held.preamble, next.preamble) }),
|
|
502
|
+
...(next.markdown === undefined ? {} : { markdown: rebased(held.markdown, next.markdown) }),
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
export function withdrawnDrafts(drafts, changes) {
|
|
507
|
+
return drafts.flatMap((draft) => {
|
|
508
|
+
const file = draft.parts.file;
|
|
509
|
+
const at = draft.parts.move?.to ?? draft.path;
|
|
510
|
+
const change = changes.find((item) => (item.kind === 'move' || item.kind === 'remove') && item.path === at);
|
|
511
|
+
if (file === undefined || change === undefined)
|
|
512
|
+
return [draft];
|
|
513
|
+
if (change.kind === 'move') {
|
|
514
|
+
return [
|
|
515
|
+
{
|
|
516
|
+
path: draft.path,
|
|
517
|
+
parts: change.to === draft.path ? { file } : { file, move: { to: change.to, base: null } },
|
|
518
|
+
},
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
return file.base === null
|
|
522
|
+
? []
|
|
523
|
+
: [{ path: draft.path, parts: { file, removal: { base: null } } }];
|
|
524
|
+
});
|
|
525
|
+
}
|
|
@@ -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,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