@agentshouse/mdruntime 0.1.0-c6e4c19c13638 → 0.1.0-c6f02ec9468d4

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.
Files changed (184) hide show
  1. package/README.md +23 -10
  2. package/dist/adapter.d.ts +156 -43
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +53 -6
  7. package/dist/attempt.d.ts +16 -0
  8. package/dist/attempt.d.ts.map +1 -0
  9. package/dist/attempt.js +70 -0
  10. package/dist/binary.d.ts +18 -0
  11. package/dist/binary.d.ts.map +1 -0
  12. package/dist/binary.js +8 -0
  13. package/dist/bootstrap.d.ts +33 -5
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +201 -48
  16. package/dist/chain.d.ts +11 -0
  17. package/dist/chain.d.ts.map +1 -0
  18. package/dist/chain.js +64 -0
  19. package/dist/change-set.d.ts +9 -14
  20. package/dist/change-set.d.ts.map +1 -1
  21. package/dist/change-set.js +11 -56
  22. package/dist/change.d.ts +45 -0
  23. package/dist/change.d.ts.map +1 -1
  24. package/dist/change.js +34 -0
  25. package/dist/client.d.ts +37 -16
  26. package/dist/client.d.ts.map +1 -1
  27. package/dist/client.js +156 -20
  28. package/dist/collection.d.ts +12 -14
  29. package/dist/collection.d.ts.map +1 -1
  30. package/dist/collection.js +52 -56
  31. package/dist/compile.d.ts +16 -0
  32. package/dist/compile.d.ts.map +1 -0
  33. package/dist/compile.js +786 -0
  34. package/dist/connection.d.ts +61 -20
  35. package/dist/connection.d.ts.map +1 -1
  36. package/dist/connection.js +3877 -885
  37. package/dist/conversation.d.ts +48 -19
  38. package/dist/conversation.d.ts.map +1 -1
  39. package/dist/conversation.js +723 -240
  40. package/dist/digest.d.ts +7 -0
  41. package/dist/digest.d.ts.map +1 -0
  42. package/dist/digest.js +113 -0
  43. package/dist/durability.d.ts +4 -1
  44. package/dist/durability.d.ts.map +1 -1
  45. package/dist/durability.js +5 -0
  46. package/dist/entry.d.ts +20 -0
  47. package/dist/entry.d.ts.map +1 -0
  48. package/dist/entry.js +151 -0
  49. package/dist/expectation.d.ts +21 -0
  50. package/dist/expectation.d.ts.map +1 -0
  51. package/dist/expectation.js +70 -0
  52. package/dist/failure.d.ts +13 -0
  53. package/dist/failure.d.ts.map +1 -0
  54. package/dist/failure.js +19 -0
  55. package/dist/fence.d.ts +6 -0
  56. package/dist/fence.d.ts.map +1 -0
  57. package/dist/fence.js +10 -0
  58. package/dist/file.d.ts +2 -19
  59. package/dist/file.d.ts.map +1 -1
  60. package/dist/file.js +7 -122
  61. package/dist/fulltext.d.ts +27 -0
  62. package/dist/fulltext.d.ts.map +1 -0
  63. package/dist/fulltext.js +370 -0
  64. package/dist/host.d.ts +13 -2
  65. package/dist/host.d.ts.map +1 -1
  66. package/dist/host.js +134 -24
  67. package/dist/identity.d.ts +4 -0
  68. package/dist/identity.d.ts.map +1 -1
  69. package/dist/identity.js +16 -1
  70. package/dist/index.d.ts +20 -9
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +9 -0
  73. package/dist/live.d.ts +22 -0
  74. package/dist/live.d.ts.map +1 -0
  75. package/dist/live.js +123 -0
  76. package/dist/media.d.ts +8 -0
  77. package/dist/media.d.ts.map +1 -0
  78. package/dist/media.js +218 -0
  79. package/dist/memory.d.ts +18 -7
  80. package/dist/memory.d.ts.map +1 -1
  81. package/dist/memory.js +252 -92
  82. package/dist/messages.d.ts +28 -0
  83. package/dist/messages.d.ts.map +1 -0
  84. package/dist/messages.js +90 -0
  85. package/dist/model.d.ts +19 -4
  86. package/dist/model.d.ts.map +1 -1
  87. package/dist/model.js +10 -2
  88. package/dist/name.d.ts +4 -0
  89. package/dist/name.d.ts.map +1 -0
  90. package/dist/name.js +122 -0
  91. package/dist/observation.d.ts +20 -2
  92. package/dist/observation.d.ts.map +1 -1
  93. package/dist/observation.js +113 -12
  94. package/dist/open.d.ts +2 -0
  95. package/dist/open.d.ts.map +1 -0
  96. package/dist/open.js +1 -0
  97. package/dist/opened.d.ts +22 -0
  98. package/dist/opened.d.ts.map +1 -0
  99. package/dist/opened.js +107 -0
  100. package/dist/outcome.d.ts +72 -5
  101. package/dist/outcome.d.ts.map +1 -1
  102. package/dist/outcome.js +81 -1
  103. package/dist/overlay.d.ts +15 -5
  104. package/dist/overlay.d.ts.map +1 -1
  105. package/dist/overlay.js +136 -180
  106. package/dist/paths.d.ts +1 -0
  107. package/dist/paths.d.ts.map +1 -1
  108. package/dist/paths.js +4 -0
  109. package/dist/query.d.ts +70 -4
  110. package/dist/query.d.ts.map +1 -1
  111. package/dist/query.js +53 -38
  112. package/dist/reach.d.ts +18 -4
  113. package/dist/reach.d.ts.map +1 -1
  114. package/dist/reach.js +235 -64
  115. package/dist/react.d.ts +32 -19
  116. package/dist/react.d.ts.map +1 -1
  117. package/dist/react.js +13 -21
  118. package/dist/readiness.d.ts +52 -0
  119. package/dist/readiness.d.ts.map +1 -0
  120. package/dist/readiness.js +27 -0
  121. package/dist/recovery.d.ts +26 -0
  122. package/dist/recovery.d.ts.map +1 -0
  123. package/dist/recovery.js +224 -0
  124. package/dist/refresh.d.ts +20 -7
  125. package/dist/refresh.d.ts.map +1 -1
  126. package/dist/refresh.js +148 -59
  127. package/dist/replica.d.ts +58 -33
  128. package/dist/replica.d.ts.map +1 -1
  129. package/dist/replica.js +320 -157
  130. package/dist/room-draft.d.ts +57 -10
  131. package/dist/room-draft.d.ts.map +1 -1
  132. package/dist/room-draft.js +222 -39
  133. package/dist/rows.d.ts +39 -35
  134. package/dist/rows.d.ts.map +1 -1
  135. package/dist/rows.js +176 -99
  136. package/dist/save.d.ts +73 -4
  137. package/dist/save.d.ts.map +1 -1
  138. package/dist/save.js +825 -150
  139. package/dist/search.d.ts +41 -29
  140. package/dist/search.d.ts.map +1 -1
  141. package/dist/search.js +37 -105
  142. package/dist/seed.d.ts +16 -0
  143. package/dist/seed.d.ts.map +1 -0
  144. package/dist/seed.js +75 -0
  145. package/dist/shared.d.ts +15 -0
  146. package/dist/shared.d.ts.map +1 -0
  147. package/dist/shared.js +421 -0
  148. package/dist/status.d.ts +7 -2
  149. package/dist/status.d.ts.map +1 -1
  150. package/dist/status.js +3 -9
  151. package/dist/store.d.ts +110 -59
  152. package/dist/store.d.ts.map +1 -1
  153. package/dist/store.js +324 -344
  154. package/dist/stored.d.ts +130 -0
  155. package/dist/stored.d.ts.map +1 -0
  156. package/dist/stored.js +560 -0
  157. package/dist/tables.d.ts +325 -0
  158. package/dist/tables.d.ts.map +1 -0
  159. package/dist/tables.js +578 -0
  160. package/dist/transfer.d.ts +0 -5
  161. package/dist/transfer.d.ts.map +1 -1
  162. package/dist/turn.d.ts +9 -0
  163. package/dist/turn.d.ts.map +1 -0
  164. package/dist/turn.js +75 -0
  165. package/dist/validation.d.ts +29 -0
  166. package/dist/validation.d.ts.map +1 -0
  167. package/dist/validation.js +101 -0
  168. package/dist/windows.d.ts +22 -0
  169. package/dist/windows.d.ts.map +1 -0
  170. package/dist/windows.js +89 -0
  171. package/dist/wire.d.ts +170 -33
  172. package/dist/wire.d.ts.map +1 -1
  173. package/dist/wire.js +69 -31
  174. package/dist/words.d.ts +19 -0
  175. package/dist/words.d.ts.map +1 -0
  176. package/dist/words.js +156 -0
  177. package/package.json +26 -15
  178. package/AGENTS.md +0 -241
  179. package/dist/attachment.d.ts +0 -3
  180. package/dist/attachment.d.ts.map +0 -1
  181. package/dist/attachment.js +0 -8
  182. package/dist/read-side.d.ts +0 -18
  183. package/dist/read-side.d.ts.map +0 -1
  184. package/dist/read-side.js +0 -433
@@ -1,4 +1,5 @@
1
1
  import type { ProviderRefusal } from './adapter.js';
2
+ import type { Open } from './open.js';
2
3
  import type { Change, Precondition } from './change.js';
3
4
  import type { VisibleLayer } from './replica.js';
4
5
  export type FieldValue = {
@@ -31,11 +32,24 @@ export type RoomDraftParts = {
31
32
  readonly creation?: RoomDraftCreation;
32
33
  readonly move?: {
33
34
  readonly to: string;
35
+ readonly room?: string;
34
36
  readonly base?: string | null;
35
37
  };
36
38
  readonly removal?: {
37
39
  readonly base?: string | null;
38
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;
39
53
  };
40
54
  type HeldParts = {
41
55
  readonly fields?: Readonly<Record<string, {
@@ -57,11 +71,13 @@ type HeldParts = {
57
71
  readonly creation?: RoomDraftCreation;
58
72
  readonly move?: {
59
73
  readonly to: string;
74
+ readonly room?: string;
60
75
  readonly base: string | null;
61
76
  };
62
77
  readonly removal?: {
63
78
  readonly base: string | null;
64
79
  };
80
+ readonly file?: HeldFile;
65
81
  };
66
82
  type ChangedUnderneath = {
67
83
  readonly fields?: Readonly<Record<string, FieldValue>>;
@@ -71,14 +87,12 @@ type ChangedUnderneath = {
71
87
  readonly creation?: string;
72
88
  readonly move?: string | null;
73
89
  readonly removal?: string | null;
90
+ readonly file?: string | null;
74
91
  };
75
- export type ReturnReason = (ProviderRefusal & {
76
- readonly kind: 'conflicted' | 'rejected';
77
- }) | {
78
- readonly kind: 'expired';
79
- } | {
80
- readonly kind: 'withdrawn';
92
+ export type ReturnReason = ProviderRefusal & {
93
+ readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
81
94
  };
95
+ export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
82
96
  export type RoomDraft = {
83
97
  readonly room: string;
84
98
  readonly path: string;
@@ -92,11 +106,14 @@ export type RoomDraftWrite = {
92
106
  readonly roomDraft: RoomDraft | null;
93
107
  } | {
94
108
  readonly outcome: 'stale';
109
+ readonly code: string;
110
+ readonly retryable: boolean;
95
111
  readonly current: RoomDraft | null;
96
112
  };
113
+ export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
97
114
  export type ChangedPart = {
98
115
  readonly path: string;
99
- readonly part: 'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal';
116
+ readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
100
117
  readonly name?: string;
101
118
  };
102
119
  export type RoomDraftRecord = {
@@ -111,17 +128,47 @@ export type SavedDraft = {
111
128
  readonly parts: HeldParts;
112
129
  };
113
130
  export declare function readParts(value: unknown): RoomDraftParts;
114
- export declare function held(current: HeldParts | undefined, parts: RoomDraftParts): HeldParts;
115
- export declare function equalValue(left: unknown, right: unknown): boolean;
131
+ export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
132
+ export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
116
133
  export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
117
- export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
134
+ export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
135
+ export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
136
+ export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
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): string;
118
149
  export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): 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 joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
172
+ export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
126
173
  export {};
127
174
  //# sourceMappingURL=room-draft.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,GACD;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CACxB,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,E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C,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,CAgB1F;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,GACf;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,CA2ChE;AAkBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAkBzF;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,UAAU,EAAE,CAqBvB"}
@@ -1,19 +1,20 @@
1
- import { apply, parse, serialize } from '@agentshouse/mdmodel';
1
+ import { apply, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
2
+ import { runtimeError } from './failure.js';
3
+ import { sha256 } from './digest.js';
4
+ import { binaryLocalId } from './identity.js';
2
5
  import { normalize } from './paths.js';
6
+ export function returnedBy(kind) {
7
+ return { kind, code: kind, fields: {}, retryable: false };
8
+ }
9
+ export function staleWrite(current) {
10
+ return { outcome: 'stale', code: 'stale', retryable: false, current };
11
+ }
3
12
  function malformed() {
4
- throw new Error('room-draft-malformed');
13
+ throw runtimeError('room-draft-malformed');
5
14
  }
6
15
  function plain(value) {
7
16
  return typeof value === 'object' && value !== null && !Array.isArray(value);
8
17
  }
9
- function frontmatterValue(value) {
10
- if (Array.isArray(value))
11
- return value.every(frontmatterValue);
12
- return (value === null ||
13
- typeof value === 'string' ||
14
- typeof value === 'boolean' ||
15
- (typeof value === 'number' && Number.isFinite(value)));
16
- }
17
18
  function text(value) {
18
19
  return typeof value === 'string' ? value : malformed();
19
20
  }
@@ -61,6 +62,7 @@ const PART_NAMES = new Set([
61
62
  'creation',
62
63
  'move',
63
64
  'removal',
65
+ 'file',
64
66
  ]);
65
67
  export function readParts(value) {
66
68
  if (!plain(value) || Object.keys(value).some((name) => !PART_NAMES.has(name)))
@@ -88,7 +90,12 @@ export function readParts(value) {
88
90
  if (!plain(value.move))
89
91
  malformed();
90
92
  const base = markdownBase(value.move.base);
91
- parts.move = { to: text(value.move.to), ...(base === undefined ? {} : { base }) };
93
+ const room = optionalText(value.move.room);
94
+ parts.move = {
95
+ to: text(value.move.to),
96
+ ...(room === undefined ? {} : { room }),
97
+ ...(base === undefined ? {} : { base }),
98
+ };
92
99
  }
93
100
  if (value.removal !== undefined) {
94
101
  if (!plain(value.removal))
@@ -96,6 +103,14 @@ export function readParts(value) {
96
103
  const base = markdownBase(value.removal.base);
97
104
  parts.removal = base === undefined ? {} : { base };
98
105
  }
106
+ if (value.file !== undefined) {
107
+ if (!plain(value.file) || !(value.file.blob instanceof Blob))
108
+ malformed();
109
+ if (Object.keys(value).length > 1)
110
+ throw runtimeError('room-draft-file-exclusive');
111
+ const base = markdownBase(value.file.base);
112
+ parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
113
+ }
99
114
  return parts;
100
115
  }
101
116
  function named(record) {
@@ -108,17 +123,78 @@ function kept(prior, base) {
108
123
  if (prior !== undefined)
109
124
  return prior.base;
110
125
  if (base === undefined)
111
- throw new Error('room-draft-base-missing');
126
+ throw runtimeError('room-draft-base-missing');
112
127
  return base;
113
128
  }
129
+ function movePart(current, move) {
130
+ return {
131
+ to: move.to,
132
+ ...(move.room === undefined ? {} : { room: move.room }),
133
+ base: kept(current, move.base),
134
+ };
135
+ }
114
136
  function editsText(parts) {
115
137
  return (parts.preamble !== undefined ||
116
138
  named(parts.fields).length > 0 ||
117
139
  named(parts.sections).length > 0);
118
140
  }
119
- export function held(current, parts) {
141
+ function partNames(parts) {
142
+ const names = [];
143
+ for (const [name, part] of Object.entries(parts)) {
144
+ if (name === 'preamble' || name === 'markdown')
145
+ names.push(name);
146
+ else if ((name === 'fields' || name === 'sections') && plain(part))
147
+ names.push(...Object.keys(part).map((one) => `${name}/${one}`));
148
+ else
149
+ return null;
150
+ }
151
+ return names.sort().join('\u0000');
152
+ }
153
+ function withBaseOf(prior, part) {
154
+ return plain(part) && plain(prior) && Object.hasOwn(prior, 'base')
155
+ ? { ...part, base: prior.base }
156
+ : part;
157
+ }
158
+ export function gatheredParts(earlier, later) {
159
+ if (!plain(earlier) || !plain(later))
160
+ return null;
161
+ const named = partNames(earlier);
162
+ if (named === null || named !== partNames(later))
163
+ return null;
164
+ return Object.fromEntries(Object.entries(later).map(([name, part]) => [
165
+ name,
166
+ name === 'fields' || name === 'sections'
167
+ ? Object.fromEntries(Object.entries(part).map(([one, value]) => [
168
+ one,
169
+ withBaseOf(earlier[name][one], value),
170
+ ]))
171
+ : withBaseOf(earlier[name], part),
172
+ ]));
173
+ }
174
+ export function held(current, parts, file) {
120
175
  if (parts.markdown !== undefined && editsText(parts)) {
121
- throw new Error('room-draft-markdown-exclusive');
176
+ throw runtimeError('room-draft-markdown-exclusive');
177
+ }
178
+ if (file !== undefined) {
179
+ if (current !== undefined && current.file === undefined) {
180
+ throw runtimeError('room-draft-file-exclusive');
181
+ }
182
+ return { file: { ...file, base: current?.file === undefined ? file.base : current.file.base } };
183
+ }
184
+ if (current?.file !== undefined) {
185
+ if (editsText(parts) ||
186
+ parts.markdown !== undefined ||
187
+ parts.creation !== undefined ||
188
+ (parts.move === undefined && parts.removal === undefined)) {
189
+ throw runtimeError('room-draft-file-exclusive');
190
+ }
191
+ return {
192
+ file: current.file,
193
+ ...(parts.move === undefined ? {} : { move: movePart(current.move, parts.move) }),
194
+ ...(parts.removal === undefined
195
+ ? {}
196
+ : { removal: { base: kept(current.removal, parts.removal.base) } }),
197
+ };
122
198
  }
123
199
  const next = {};
124
200
  const fields = named(parts.fields);
@@ -149,24 +225,15 @@ export function held(current, parts) {
149
225
  }
150
226
  if (parts.creation !== undefined)
151
227
  next.creation = parts.creation;
152
- if (parts.move !== undefined) {
153
- next.move = { to: parts.move.to, base: kept(current?.move, parts.move.base) };
154
- }
228
+ if (parts.move !== undefined)
229
+ next.move = movePart(current?.move, parts.move);
155
230
  if (parts.removal !== undefined) {
156
231
  next.removal = { base: kept(current?.removal, parts.removal.base) };
157
232
  }
158
233
  if (Object.keys(next).length === 0)
159
- throw new Error('room-draft-empty');
234
+ throw runtimeError('room-draft-empty');
160
235
  return next;
161
236
  }
162
- export function equalValue(left, right) {
163
- if (left === right)
164
- return true;
165
- return (Array.isArray(left) &&
166
- Array.isArray(right) &&
167
- left.length === right.length &&
168
- left.every((item, index) => equalValue(item, right[index])));
169
- }
170
237
  function sameField(left, right) {
171
238
  if (left === null || right === null)
172
239
  return left === right;
@@ -174,7 +241,7 @@ function sameField(left, right) {
174
241
  }
175
242
  export function underneath(parts, path, visible) {
176
243
  const markdown = visible?.documents[path] ?? null;
177
- const document = visible?.collection.documents[path];
244
+ const document = visible?.collection.document(path);
178
245
  const report = {};
179
246
  const fields = {};
180
247
  for (const [name, part] of named(parts.fields)) {
@@ -207,17 +274,41 @@ export function underneath(parts, path, visible) {
207
274
  report.move = markdown;
208
275
  if (parts.removal !== undefined && markdown !== parts.removal.base)
209
276
  report.removal = markdown;
277
+ if (parts.file !== undefined) {
278
+ const file = binaryBase(visible, path);
279
+ if (file !== parts.file.base || markdown !== null)
280
+ report.file = file;
281
+ }
210
282
  return report;
211
283
  }
212
- export function changedParts(path, report) {
284
+ const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
285
+ export async function heldFile(blob, base) {
286
+ return {
287
+ localId: binaryLocalId(),
288
+ ...(blob instanceof File ? { name: blob.name } : {}),
289
+ byteLength: blob.size,
290
+ mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
291
+ sha256: await sha256(blob),
292
+ base,
293
+ };
294
+ }
295
+ export function binaryBase(visible, path) {
296
+ const binary = visible?.binaries[path];
297
+ if (binary === undefined)
298
+ return null;
299
+ return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
300
+ }
301
+ export function changedParts(path, parts, visible) {
302
+ const report = underneath(parts, path, visible);
303
+ const made = parts.file?.base === null;
213
304
  return [
214
- ...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
215
305
  ...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
216
306
  ...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
217
307
  ...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
218
308
  ...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
219
309
  ...(report.move === undefined ? [] : [{ path, part: 'move' }]),
220
310
  ...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
311
+ ...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
221
312
  ];
222
313
  }
223
314
  function joined(existing, returned) {
@@ -234,16 +325,15 @@ function frontmatterOf(fields) {
234
325
  const opened = parse('---\n---\n');
235
326
  if (!opened.ok)
236
327
  return malformed();
237
- let document = opened.document;
238
- for (const [name, part] of fields) {
239
- const next = apply(document, { kind: 'field', name, value: part.value, prior: undefined });
240
- if (next.outcome !== 'applied')
241
- return malformed();
242
- document = next.document;
243
- }
244
- return serialize(document);
328
+ const next = apply(opened.document, fields.map(([name, part]) => ({
329
+ kind: 'field',
330
+ name,
331
+ value: part.value,
332
+ prior: undefined,
333
+ })));
334
+ return next.outcome === 'applied' ? serialize(next.document) : malformed();
245
335
  }
246
- function concatenated(markdown, parts) {
336
+ export function partsAfter(markdown, parts) {
247
337
  const fields = named(parts.fields);
248
338
  const pieces = [
249
339
  ...(fields.length === 0 ? [] : [frontmatterOf(fields)]),
@@ -274,24 +364,56 @@ export function returnedInto(existing, returned) {
274
364
  delete next.fields;
275
365
  delete next.sections;
276
366
  delete next.preamble;
277
- const value = concatenated(whole.value, existing.markdown === undefined ? existing : returned);
367
+ const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
278
368
  next.markdown = { value, base: whole.base };
279
369
  }
280
370
  const creation = existing.creation ?? returned.creation;
281
371
  const move = existing.move ?? returned.move;
282
372
  const removal = existing.removal ?? returned.removal;
373
+ const file = existing.file ?? returned.file;
283
374
  if (creation !== undefined)
284
375
  next.creation = creation;
285
376
  if (move !== undefined)
286
377
  next.move = move;
287
378
  if (removal !== undefined)
288
379
  next.removal = removal;
380
+ if (file !== undefined)
381
+ next.file = file;
289
382
  return next;
290
383
  }
291
384
  export function moveTarget(move) {
292
385
  const to = normalize(move.to);
293
386
  return to === null || to === '' ? move.to : to;
294
387
  }
388
+ export function readSavedParts(named) {
389
+ const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts) }));
390
+ if (read.some(({ path }, at) => path === '' ||
391
+ normalize(path) !== path ||
392
+ read.findIndex((one) => one.path === path) !== at)) {
393
+ throw runtimeError('room-draft-malformed');
394
+ }
395
+ return read;
396
+ }
397
+ export function partsChanges(named) {
398
+ const changes = [];
399
+ const preconditions = [];
400
+ for (const { path, parts } of readSavedParts(named)) {
401
+ const parted = held(undefined, parts);
402
+ const made = changesOf(path, parted);
403
+ changes.push(...made.changes);
404
+ preconditions.push(...made.bases);
405
+ for (const change of made.changes) {
406
+ if (change.kind === 'create')
407
+ preconditions.push({ kind: 'absent', path });
408
+ if (change.kind === 'move')
409
+ preconditions.push({ kind: 'absent', path: change.to });
410
+ }
411
+ const revision = parted.markdown?.base ?? parted.move?.base ?? parted.removal?.base;
412
+ if (typeof revision === 'string')
413
+ preconditions.push({ kind: 'revision', path, revision });
414
+ }
415
+ return { changes, preconditions };
416
+ }
295
417
  export function changesOf(path, parts) {
296
418
  const changes = [];
297
419
  const bases = [];
@@ -321,9 +443,70 @@ export function changesOf(path, parts) {
321
443
  if (parts.markdown !== undefined) {
322
444
  changes.push({ kind: 'replace', path, content: parts.markdown.value });
323
445
  }
446
+ if (parts.file !== undefined && parts.removal === undefined) {
447
+ const { base, name: _name, ...file } = parts.file;
448
+ const at = parts.move === undefined ? path : moveTarget(parts.move);
449
+ if (base !== null && at !== path)
450
+ changes.push({ kind: 'move', path, to: at });
451
+ changes.push({ kind: 'binary', path: at, ...file });
452
+ if (base === null)
453
+ bases.push({ kind: 'absent', path: at });
454
+ return { changes, bases };
455
+ }
456
+ if (parts.file?.base === null)
457
+ return { changes, bases };
324
458
  if (parts.move !== undefined)
325
459
  changes.push({ kind: 'move', path, to: moveTarget(parts.move) });
326
460
  if (parts.removal !== undefined)
327
461
  changes.push({ kind: 'remove', path });
328
462
  return { changes, bases };
329
463
  }
464
+ function rebased(before, after) {
465
+ return before === undefined ? after : { ...after, base: before.base };
466
+ }
467
+ function rebasedAll(before, after) {
468
+ return {
469
+ ...before,
470
+ ...Object.fromEntries(Object.entries(after).map(([name, part]) => [name, rebased(before?.[name], part)])),
471
+ };
472
+ }
473
+ export function joinedDraft(carried, saved) {
474
+ const draft = saved.find((item) => item.path === carried.path);
475
+ if (draft === undefined)
476
+ return carried;
477
+ const held = carried.parts;
478
+ const next = draft.parts;
479
+ return {
480
+ path: carried.path,
481
+ parts: {
482
+ ...held,
483
+ ...next,
484
+ ...(next.fields === undefined ? {} : { fields: rebasedAll(held.fields, next.fields) }),
485
+ ...(next.sections === undefined
486
+ ? {}
487
+ : { sections: rebasedAll(held.sections, next.sections) }),
488
+ ...(next.preamble === undefined ? {} : { preamble: rebased(held.preamble, next.preamble) }),
489
+ ...(next.markdown === undefined ? {} : { markdown: rebased(held.markdown, next.markdown) }),
490
+ },
491
+ };
492
+ }
493
+ export function withdrawnDrafts(drafts, changes) {
494
+ return drafts.flatMap((draft) => {
495
+ const file = draft.parts.file;
496
+ const at = draft.parts.move?.to ?? draft.path;
497
+ const change = changes.find((item) => (item.kind === 'move' || item.kind === 'remove') && item.path === at);
498
+ if (file === undefined || change === undefined)
499
+ return [draft];
500
+ if (change.kind === 'move') {
501
+ return [
502
+ {
503
+ path: draft.path,
504
+ parts: change.to === draft.path ? { file } : { file, move: { to: change.to, base: null } },
505
+ },
506
+ ];
507
+ }
508
+ return file.base === null
509
+ ? []
510
+ : [{ path: draft.path, parts: { file, removal: { base: null } } }];
511
+ });
512
+ }
package/dist/rows.d.ts CHANGED
@@ -1,42 +1,46 @@
1
- import { type Document } from '@agentshouse/mdmodel';
2
- import type { HeadChange } from './adapter.js';
3
1
  import { type Composition } from './collection.js';
4
- type Fields = Readonly<Record<string, unknown>>;
5
- export type DocumentRow = {
6
- key: string;
7
- kind: 'document';
8
- room: string;
9
- path: string;
10
- type: string | null;
11
- fields: Fields;
12
- values: Fields;
13
- reached: Readonly<Record<string, readonly unknown[]>>;
14
- directories: readonly string[];
15
- body: string;
16
- change: HeadChange | null;
2
+ export type ValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'undefined';
3
+ type HeldValue = {
4
+ readonly keys: string;
5
+ readonly places: string;
6
+ readonly item: number;
7
+ readonly kind: ValueKind;
8
+ readonly value: string | number | null;
9
+ readonly size: number | null;
17
10
  };
18
- export type BodyRow = {
19
- key: string;
20
- kind: 'body';
21
- room: string;
22
- path: string;
23
- preamble: string;
24
- sections: Readonly<Record<string, string>>;
25
- markdown: string;
11
+ type LinkKind = 'field' | 'section' | 'body';
12
+ type HeldLink = {
13
+ readonly kind: LinkKind;
14
+ readonly keys: string;
15
+ readonly places: string;
16
+ readonly target: string;
17
+ readonly field: string;
26
18
  };
27
- export type ReferenceRow = {
28
- key: string;
29
- kind: 'reference';
30
- room: string;
31
- source: string;
32
- target: string;
33
- field: string;
34
- forms: readonly string[];
35
- path: string;
36
- type: string;
19
+ export type Described = {
20
+ readonly type: string | null;
21
+ readonly declared: string | null;
22
+ readonly queried: boolean;
23
+ readonly folder: string;
24
+ readonly fields: string | null;
25
+ };
26
+ export type Derived = Described & {
27
+ readonly values: readonly HeldValue[];
28
+ readonly links: readonly HeldLink[];
37
29
  };
38
- export type Row = DocumentRow | BodyRow | ReferenceRow;
39
30
  export declare function documentKey(room: string, path: string): string;
40
- export declare function rowsOf(room: string, path: string, document: Document | null, composition: Composition, change: HeadChange | null): readonly Row[];
31
+ export declare function roomOfKey(key: string): string;
32
+ export declare function pathOfKey(key: string): string;
33
+ export declare function markdownPath(path: string): boolean;
34
+ export declare function folderOf(path: string): string;
35
+ export type Reach = 'exact' | 'value' | 'link';
36
+ export type Placed = {
37
+ readonly keys: string;
38
+ readonly places: string;
39
+ readonly glob: boolean;
40
+ };
41
+ export declare function placedOf(pointer: string, reach: Reach): Placed;
42
+ export declare function kindOf(value: unknown): ValueKind;
43
+ export declare function described(path: string, content: string | null): Described;
44
+ export declare function derived(path: string, content: string | null, composition: Composition): Derived;
41
45
  export {};
42
46
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,CAAC;IACtD,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EA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