@agentshouse/mdruntime 0.1.0-c969b8dee6cc8 → 0.1.0-c96e80d38e5f0

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 (231) hide show
  1. package/README.md +19 -16
  2. package/dist/adapter.d.ts +134 -76
  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 +38 -4
  7. package/dist/binary.d.ts +0 -5
  8. package/dist/binary.d.ts.map +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bootstrap.d.ts +25 -10
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +180 -103
  13. package/dist/chain.d.ts +11 -0
  14. package/dist/chain.d.ts.map +1 -0
  15. package/dist/chain.js +64 -0
  16. package/dist/change-set.d.ts +9 -16
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +11 -89
  19. package/dist/change.d.ts +31 -1
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +10 -1
  22. package/dist/client.d.ts +13 -9
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +80 -7
  25. package/dist/collection.d.ts +10 -21
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +39 -291
  28. package/dist/compile.d.ts +16 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +789 -0
  31. package/dist/connection.d.ts +19 -15
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +3020 -1417
  34. package/dist/conversation.d.ts +23 -14
  35. package/dist/conversation.d.ts.map +1 -1
  36. package/dist/conversation.js +337 -179
  37. package/dist/digest.d.ts +7 -0
  38. package/dist/digest.d.ts.map +1 -0
  39. package/dist/digest.js +113 -0
  40. package/dist/durability.d.ts +2 -5
  41. package/dist/durability.d.ts.map +1 -1
  42. package/dist/durability.js +5 -0
  43. package/dist/entry.d.ts +4 -1
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +19 -23
  46. package/dist/file.d.ts +2 -19
  47. package/dist/file.d.ts.map +1 -1
  48. package/dist/file.js +7 -122
  49. package/dist/host.d.ts +4 -10
  50. package/dist/host.d.ts.map +1 -1
  51. package/dist/host.js +49 -31
  52. package/dist/identity.d.ts +0 -1
  53. package/dist/identity.d.ts.map +1 -1
  54. package/dist/identity.js +0 -3
  55. package/dist/index.d.ts +14 -11
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +6 -2
  58. package/dist/live.d.ts +22 -0
  59. package/dist/live.d.ts.map +1 -0
  60. package/dist/live.js +123 -0
  61. package/dist/media.d.ts +8 -0
  62. package/dist/media.d.ts.map +1 -0
  63. package/dist/media.js +218 -0
  64. package/dist/memory.d.ts +11 -7
  65. package/dist/memory.d.ts.map +1 -1
  66. package/dist/memory.js +198 -107
  67. package/dist/messages.d.ts +28 -0
  68. package/dist/messages.d.ts.map +1 -0
  69. package/dist/messages.js +89 -0
  70. package/dist/model.d.ts +6 -1
  71. package/dist/model.d.ts.map +1 -1
  72. package/dist/model.js +7 -10
  73. package/dist/name.d.ts +4 -0
  74. package/dist/name.d.ts.map +1 -0
  75. package/dist/name.js +122 -0
  76. package/dist/observation.d.ts +13 -0
  77. package/dist/observation.d.ts.map +1 -1
  78. package/dist/observation.js +84 -0
  79. package/dist/opened.d.ts +22 -0
  80. package/dist/opened.d.ts.map +1 -0
  81. package/dist/opened.js +107 -0
  82. package/dist/outcome.d.ts +40 -8
  83. package/dist/outcome.d.ts.map +1 -1
  84. package/dist/outcome.js +38 -2
  85. package/dist/overlay.d.ts +2 -5
  86. package/dist/overlay.d.ts.map +1 -1
  87. package/dist/overlay.js +87 -172
  88. package/dist/paths.d.ts +1 -0
  89. package/dist/paths.d.ts.map +1 -1
  90. package/dist/paths.js +4 -0
  91. package/dist/phrase.d.ts +3 -0
  92. package/dist/phrase.d.ts.map +1 -0
  93. package/dist/phrase.js +8 -0
  94. package/dist/query.d.ts +15 -1
  95. package/dist/query.d.ts.map +1 -1
  96. package/dist/query.js +33 -2
  97. package/dist/reach.d.ts +13 -4
  98. package/dist/reach.d.ts.map +1 -1
  99. package/dist/reach.js +200 -81
  100. package/dist/react.d.ts +1 -0
  101. package/dist/react.d.ts.map +1 -1
  102. package/dist/readiness.d.ts +14 -17
  103. package/dist/readiness.d.ts.map +1 -1
  104. package/dist/readiness.js +2 -8
  105. package/dist/recovery.d.ts +3 -2
  106. package/dist/recovery.d.ts.map +1 -1
  107. package/dist/recovery.js +34 -7
  108. package/dist/refresh.d.ts +18 -15
  109. package/dist/refresh.d.ts.map +1 -1
  110. package/dist/refresh.js +155 -58
  111. package/dist/replica.d.ts +54 -36
  112. package/dist/replica.d.ts.map +1 -1
  113. package/dist/replica.js +282 -189
  114. package/dist/room-draft.d.ts +22 -4
  115. package/dist/room-draft.d.ts.map +1 -1
  116. package/dist/room-draft.js +154 -67
  117. package/dist/rows.d.ts +39 -31
  118. package/dist/rows.d.ts.map +1 -1
  119. package/dist/rows.js +178 -101
  120. package/dist/save.d.ts +52 -14
  121. package/dist/save.d.ts.map +1 -1
  122. package/dist/save.js +513 -185
  123. package/dist/search.d.ts +12 -95
  124. package/dist/search.d.ts.map +1 -1
  125. package/dist/search.js +10 -266
  126. package/dist/shared.d.ts +7 -3
  127. package/dist/shared.d.ts.map +1 -1
  128. package/dist/shared.js +119 -66
  129. package/dist/status.d.ts +4 -3
  130. package/dist/status.d.ts.map +1 -1
  131. package/dist/status.js +3 -1
  132. package/dist/store.d.ts +91 -103
  133. package/dist/store.d.ts.map +1 -1
  134. package/dist/store.js +330 -693
  135. package/dist/stored.d.ts +162 -0
  136. package/dist/stored.d.ts.map +1 -0
  137. package/dist/stored.js +549 -0
  138. package/dist/tables.d.ts +353 -0
  139. package/dist/tables.d.ts.map +1 -0
  140. package/dist/tables.js +585 -0
  141. package/dist/transfer.d.ts +0 -5
  142. package/dist/transfer.d.ts.map +1 -1
  143. package/dist/turn.d.ts +5 -3
  144. package/dist/turn.d.ts.map +1 -1
  145. package/dist/turn.js +51 -21
  146. package/dist/validation.d.ts +29 -0
  147. package/dist/validation.d.ts.map +1 -0
  148. package/dist/validation.js +101 -0
  149. package/dist/windows.d.ts +2 -6
  150. package/dist/windows.d.ts.map +1 -1
  151. package/dist/windows.js +30 -34
  152. package/dist/wire.d.ts +18 -5
  153. package/dist/wire.d.ts.map +1 -1
  154. package/dist/wire.js +6 -2
  155. package/package.json +18 -19
  156. package/AGENTS.md +0 -305
  157. package/dist/acquisition.d.ts +0 -14
  158. package/dist/acquisition.d.ts.map +0 -1
  159. package/dist/acquisition.js +0 -24
  160. package/dist/chat/acts.d.ts +0 -33
  161. package/dist/chat/acts.d.ts.map +0 -1
  162. package/dist/chat/acts.js +0 -36
  163. package/dist/chat/context.d.ts +0 -3
  164. package/dist/chat/context.d.ts.map +0 -1
  165. package/dist/chat/context.js +0 -10
  166. package/dist/chat/earlier.d.ts +0 -10
  167. package/dist/chat/earlier.d.ts.map +0 -1
  168. package/dist/chat/earlier.js +0 -54
  169. package/dist/chat/input.d.ts +0 -9
  170. package/dist/chat/input.d.ts.map +0 -1
  171. package/dist/chat/input.js +0 -99
  172. package/dist/chat/kit.d.ts +0 -61
  173. package/dist/chat/kit.d.ts.map +0 -1
  174. package/dist/chat/kit.js +0 -123
  175. package/dist/chat/lasting.d.ts +0 -6
  176. package/dist/chat/lasting.d.ts.map +0 -1
  177. package/dist/chat/lasting.js +0 -19
  178. package/dist/chat/list.d.ts +0 -27
  179. package/dist/chat/list.d.ts.map +0 -1
  180. package/dist/chat/list.js +0 -99
  181. package/dist/chat/markdown.d.ts +0 -20
  182. package/dist/chat/markdown.d.ts.map +0 -1
  183. package/dist/chat/markdown.js +0 -188
  184. package/dist/chat/message.d.ts +0 -6
  185. package/dist/chat/message.d.ts.map +0 -1
  186. package/dist/chat/message.js +0 -192
  187. package/dist/chat/messages.d.ts +0 -22
  188. package/dist/chat/messages.d.ts.map +0 -1
  189. package/dist/chat/messages.js +0 -155
  190. package/dist/chat/name.d.ts +0 -6
  191. package/dist/chat/name.d.ts.map +0 -1
  192. package/dist/chat/name.js +0 -37
  193. package/dist/chat/opened.d.ts +0 -11
  194. package/dist/chat/opened.d.ts.map +0 -1
  195. package/dist/chat/opened.js +0 -17
  196. package/dist/chat/overlay.d.ts +0 -31
  197. package/dist/chat/overlay.d.ts.map +0 -1
  198. package/dist/chat/overlay.js +0 -97
  199. package/dist/chat/parts.d.ts +0 -57
  200. package/dist/chat/parts.d.ts.map +0 -1
  201. package/dist/chat/parts.js +0 -119
  202. package/dist/chat/process.d.ts +0 -20
  203. package/dist/chat/process.d.ts.map +0 -1
  204. package/dist/chat/process.js +0 -32
  205. package/dist/chat/provider.d.ts +0 -63
  206. package/dist/chat/provider.d.ts.map +0 -1
  207. package/dist/chat/provider.js +0 -628
  208. package/dist/chat/question.d.ts +0 -9
  209. package/dist/chat/question.d.ts.map +0 -1
  210. package/dist/chat/question.js +0 -69
  211. package/dist/chat/questions.d.ts +0 -31
  212. package/dist/chat/questions.d.ts.map +0 -1
  213. package/dist/chat/questions.js +0 -111
  214. package/dist/chat/read.d.ts +0 -5
  215. package/dist/chat/read.d.ts.map +0 -1
  216. package/dist/chat/read.js +0 -13
  217. package/dist/chat/ready.d.ts +0 -34
  218. package/dist/chat/ready.d.ts.map +0 -1
  219. package/dist/chat/ready.js +0 -91
  220. package/dist/chat/style.d.ts +0 -4
  221. package/dist/chat/style.d.ts.map +0 -1
  222. package/dist/chat/style.js +0 -302
  223. package/dist/chat.d.ts +0 -14
  224. package/dist/chat.d.ts.map +0 -1
  225. package/dist/chat.js +0 -8
  226. package/dist/read-side.d.ts +0 -25
  227. package/dist/read-side.d.ts.map +0 -1
  228. package/dist/read-side.js +0 -767
  229. package/dist/reads.d.ts +0 -11
  230. package/dist/reads.d.ts.map +0 -1
  231. package/dist/reads.js +0 -98
@@ -1,6 +1,6 @@
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 { hexDigest } from './file.js';
3
+ import { sha256 } from './digest.js';
4
4
  import { binaryLocalId } from './identity.js';
5
5
  import { normalize } from './paths.js';
6
6
  export function returnedBy(kind) {
@@ -9,52 +9,60 @@ export function returnedBy(kind) {
9
9
  export function staleWrite(current) {
10
10
  return { outcome: 'stale', code: 'stale', retryable: false, current };
11
11
  }
12
- function malformed() {
13
- throw runtimeError('room-draft-malformed');
12
+ function malformed(at, needs) {
13
+ throw runtimeError('room-draft-malformed', at === undefined ? 'room-draft-malformed' : `room-draft-malformed at ${at}: ${needs}`);
14
14
  }
15
15
  function plain(value) {
16
16
  return typeof value === 'object' && value !== null && !Array.isArray(value);
17
17
  }
18
- function text(value) {
19
- return typeof value === 'string' ? value : malformed();
18
+ function text(value, at) {
19
+ return typeof value === 'string' ? value : malformed(at, 'text');
20
20
  }
21
- function optionalText(value) {
22
- return value === undefined ? undefined : text(value);
21
+ function optionalText(value, at) {
22
+ return value === undefined ? undefined : text(value, at);
23
23
  }
24
- function markdownBase(value) {
25
- return value === null ? null : optionalText(value);
24
+ function markdownBase(value, at) {
25
+ return value === null ? null : optionalText(value, at);
26
26
  }
27
- function entries(value, each) {
27
+ function entries(value, at, each) {
28
28
  if (!plain(value))
29
- malformed();
29
+ malformed(at, 'an object of named values');
30
30
  const read = {};
31
31
  for (const [name, item] of Object.entries(value))
32
- read[name] = each(item);
32
+ read[name] = each(item, `${at}.${name}`);
33
33
  return read;
34
34
  }
35
- function fieldValue(value) {
35
+ function frontmatter(item, at) {
36
+ return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
37
+ }
38
+ function fieldValue(value, at) {
36
39
  if (value === null)
37
40
  return null;
38
41
  if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
39
- malformed();
42
+ malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
40
43
  }
41
44
  return { value: value.value };
42
45
  }
43
- function textPart(value) {
46
+ function textPart(value, at) {
44
47
  if (!plain(value))
45
- malformed();
46
- const base = optionalText(value.base);
47
- return { value: text(value.value), ...(base === undefined ? {} : { base }) };
48
+ malformed(at, '{ value, base }');
49
+ const base = optionalText(value.base, `${at}.base`);
50
+ return { value: text(value.value, `${at}.value`), ...(base === undefined ? {} : { base }) };
48
51
  }
49
- function creationOf(value) {
52
+ function creationOf(value, at) {
50
53
  if (!plain(value))
51
- malformed();
54
+ malformed(at, '{ type, fields, sections }, or { markdown }');
52
55
  if (Object.hasOwn(value, 'markdown'))
53
- return { markdown: text(value.markdown) };
54
- const fields = entries(value.fields, (item) => (frontmatterValue(item) ? item : malformed()));
55
- return { type: text(value.type), fields, sections: entries(value.sections, text) };
56
+ return { markdown: text(value.markdown, `${at}.markdown`) };
57
+ if (typeof value.type !== 'string')
58
+ malformed(`${at}.type`, 'a type name, or markdown in place of type, fields and sections');
59
+ return {
60
+ type: value.type,
61
+ fields: entries(value.fields, `${at}.fields`, frontmatter),
62
+ sections: entries(value.sections, `${at}.sections`, text),
63
+ };
56
64
  }
57
- const PART_NAMES = new Set([
65
+ const PART_NAMES = [
58
66
  'fields',
59
67
  'sections',
60
68
  'preamble',
@@ -63,47 +71,57 @@ const PART_NAMES = new Set([
63
71
  'move',
64
72
  'removal',
65
73
  'file',
66
- ]);
67
- export function readParts(value) {
68
- if (!plain(value) || Object.keys(value).some((name) => !PART_NAMES.has(name)))
69
- malformed();
74
+ ];
75
+ const NAMED_PARTS = `a part named ${PART_NAMES.slice(0, -1).join(', ')} or ${PART_NAMES.at(-1)}`;
76
+ export function readParts(value, path) {
77
+ if (!plain(value))
78
+ malformed(path, 'an object of parts');
79
+ const unknown = Object.keys(value).find((name) => !PART_NAMES.includes(name));
80
+ if (unknown !== undefined)
81
+ malformed(`${path} ${unknown}`, NAMED_PARTS);
70
82
  const parts = {};
71
83
  if (value.fields !== undefined) {
72
- parts.fields = entries(value.fields, (item) => {
84
+ parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
73
85
  if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
74
- malformed();
86
+ malformed(at, '{ value, base } with a frontmatter value');
75
87
  }
76
88
  return item.base === undefined
77
89
  ? { value: item.value }
78
- : { value: item.value, base: fieldValue(item.base) };
90
+ : { value: item.value, base: fieldValue(item.base, `${at}.base`) };
79
91
  });
80
92
  }
81
93
  if (value.sections !== undefined)
82
- parts.sections = entries(value.sections, textPart);
94
+ parts.sections = entries(value.sections, `${path} sections`, textPart);
83
95
  if (value.preamble !== undefined)
84
- parts.preamble = textPart(value.preamble);
96
+ parts.preamble = textPart(value.preamble, `${path} preamble`);
85
97
  if (value.markdown !== undefined)
86
- parts.markdown = textPart(value.markdown);
98
+ parts.markdown = textPart(value.markdown, `${path} markdown`);
87
99
  if (value.creation !== undefined)
88
- parts.creation = creationOf(value.creation);
100
+ parts.creation = creationOf(value.creation, `${path} creation`);
89
101
  if (value.move !== undefined) {
90
102
  if (!plain(value.move))
91
- malformed();
92
- const base = markdownBase(value.move.base);
93
- parts.move = { to: text(value.move.to), ...(base === undefined ? {} : { base }) };
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
+ };
94
111
  }
95
112
  if (value.removal !== undefined) {
96
113
  if (!plain(value.removal))
97
- malformed();
98
- const base = markdownBase(value.removal.base);
114
+ malformed(`${path} removal`, '{ base }');
115
+ const base = markdownBase(value.removal.base, `${path} removal.base`);
99
116
  parts.removal = base === undefined ? {} : { base };
100
117
  }
101
118
  if (value.file !== undefined) {
102
119
  if (!plain(value.file) || !(value.file.blob instanceof Blob))
103
- malformed();
120
+ malformed(`${path} file`, '{ blob, base } with a Blob');
104
121
  if (Object.keys(value).length > 1)
105
122
  throw runtimeError('room-draft-file-exclusive');
106
- parts.file = { blob: value.file.blob };
123
+ const base = markdownBase(value.file.base, `${path} file.base`);
124
+ parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
107
125
  }
108
126
  return parts;
109
127
  }
@@ -120,11 +138,51 @@ function kept(prior, base) {
120
138
  throw runtimeError('room-draft-base-missing');
121
139
  return base;
122
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
+ }
123
148
  function editsText(parts) {
124
149
  return (parts.preamble !== undefined ||
125
150
  named(parts.fields).length > 0 ||
126
151
  named(parts.sections).length > 0);
127
152
  }
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
+ }
128
186
  export function held(current, parts, file) {
129
187
  if (parts.markdown !== undefined && editsText(parts)) {
130
188
  throw runtimeError('room-draft-markdown-exclusive');
@@ -144,9 +202,7 @@ export function held(current, parts, file) {
144
202
  }
145
203
  return {
146
204
  file: current.file,
147
- ...(parts.move === undefined
148
- ? {}
149
- : { move: { to: parts.move.to, base: kept(current.move, parts.move.base) } }),
205
+ ...(parts.move === undefined ? {} : { move: movePart(current.move, parts.move) }),
150
206
  ...(parts.removal === undefined
151
207
  ? {}
152
208
  : { removal: { base: kept(current.removal, parts.removal.base) } }),
@@ -181,9 +237,8 @@ export function held(current, parts, file) {
181
237
  }
182
238
  if (parts.creation !== undefined)
183
239
  next.creation = parts.creation;
184
- if (parts.move !== undefined) {
185
- next.move = { to: parts.move.to, base: kept(current?.move, parts.move.base) };
186
- }
240
+ if (parts.move !== undefined)
241
+ next.move = movePart(current?.move, parts.move);
187
242
  if (parts.removal !== undefined) {
188
243
  next.removal = { base: kept(current?.removal, parts.removal.base) };
189
244
  }
@@ -240,29 +295,32 @@ export function underneath(parts, path, visible) {
240
295
  }
241
296
  const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
242
297
  export async function heldFile(blob, base) {
243
- const bytes = await blob.arrayBuffer();
244
298
  return {
245
- blob,
246
299
  localId: binaryLocalId(),
247
- byteLength: bytes.byteLength,
300
+ ...(blob instanceof File ? { name: blob.name } : {}),
301
+ byteLength: blob.size,
248
302
  mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
249
- sha256: hexDigest(await crypto.subtle.digest('SHA-256', bytes)),
303
+ sha256: await sha256(blob),
250
304
  base,
251
305
  };
252
306
  }
253
307
  export function binaryBase(visible, path) {
254
- return visible?.binaries[path] === undefined ? null : (visible.revisions[path] ?? null);
308
+ const binary = visible?.binaries[path];
309
+ if (binary === undefined)
310
+ return null;
311
+ return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
255
312
  }
256
- export function changedParts(path, report) {
313
+ export function changedParts(path, parts, visible) {
314
+ const report = underneath(parts, path, visible);
315
+ const made = parts.file?.base === null;
257
316
  return [
258
- ...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
259
317
  ...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
260
318
  ...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
261
319
  ...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
262
320
  ...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
263
321
  ...(report.move === undefined ? [] : [{ path, part: 'move' }]),
264
322
  ...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
265
- ...(report.file === undefined ? [] : [{ path, part: 'file' }]),
323
+ ...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
266
324
  ];
267
325
  }
268
326
  function joined(existing, returned) {
@@ -279,14 +337,13 @@ function frontmatterOf(fields) {
279
337
  const opened = parse('---\n---\n');
280
338
  if (!opened.ok)
281
339
  return malformed();
282
- let document = opened.document;
283
- for (const [name, part] of fields) {
284
- const next = apply(document, { kind: 'field', name, value: part.value, prior: undefined });
285
- if (next.outcome !== 'applied')
286
- return malformed();
287
- document = next.document;
288
- }
289
- 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();
290
347
  }
291
348
  export function partsAfter(markdown, parts) {
292
349
  const fields = named(parts.fields);
@@ -340,6 +397,36 @@ export function moveTarget(move) {
340
397
  const to = normalize(move.to);
341
398
  return to === null || to === '' ? move.to : to;
342
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
+ }
343
430
  export function changesOf(path, parts) {
344
431
  const changes = [];
345
432
  const bases = [];
@@ -370,12 +457,12 @@ export function changesOf(path, parts) {
370
457
  changes.push({ kind: 'replace', path, content: parts.markdown.value });
371
458
  }
372
459
  if (parts.file !== undefined && parts.removal === undefined) {
373
- const { base, ...file } = parts.file;
460
+ const { base, name: _name, ...file } = parts.file;
374
461
  const at = parts.move === undefined ? path : moveTarget(parts.move);
375
462
  if (base !== null && at !== path)
376
463
  changes.push({ kind: 'move', path, to: at });
377
464
  changes.push({ kind: 'binary', path: at, ...file });
378
- if (base === null && at !== path)
465
+ if (base === null)
379
466
  bases.push({ kind: 'absent', path: at });
380
467
  return { changes, bases };
381
468
  }
package/dist/rows.d.ts CHANGED
@@ -1,39 +1,47 @@
1
- import { type Frontmatter } from '@agentshouse/mdmodel';
2
- import type { HeadChange } from './adapter.js';
3
- import type { BinaryFileRecord } from './binary.js';
1
+ import { type Outline } from '@agentshouse/mdmodel';
4
2
  import { type Composition } from './collection.js';
5
- type Fields = Readonly<Record<string, unknown>>;
6
- export type DocumentRow = {
7
- key: string;
8
- kind: 'document';
9
- room: string;
10
- path: string;
11
- type: string | null;
12
- fields: Fields;
13
- values: Fields;
14
- reached: Readonly<Record<string, readonly unknown[]>>;
15
- directories: readonly string[];
16
- folder: string;
17
- text: string | null;
18
- change: HeadChange | null;
19
- fileId: string | null;
20
- binary: BinaryFileRecord | null;
3
+ export type ValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'undefined';
4
+ type HeldValue = {
5
+ readonly keys: string;
6
+ readonly places: string;
7
+ readonly item: number;
8
+ readonly kind: ValueKind;
9
+ readonly value: string | number | null;
10
+ readonly size: number | null;
21
11
  };
22
- export type ReferenceRow = {
23
- key: string;
24
- kind: 'reference';
25
- room: string;
26
- source: string;
27
- target: string;
28
- field: string;
29
- forms: readonly string[];
30
- path: string;
31
- type: string;
12
+ type LinkKind = 'field' | 'section' | 'body';
13
+ type HeldLink = {
14
+ readonly kind: LinkKind;
15
+ readonly keys: string;
16
+ readonly places: string;
17
+ readonly target: string;
18
+ readonly field: string;
19
+ };
20
+ export type Described = {
21
+ readonly type: string | null;
22
+ readonly declared: string | null;
23
+ readonly queried: boolean;
24
+ readonly folder: string;
25
+ readonly fields: string | null;
26
+ };
27
+ export type Derived = Described & {
28
+ readonly values: readonly HeldValue[];
29
+ readonly links: readonly HeldLink[];
32
30
  };
33
- export type Row = DocumentRow | ReferenceRow;
34
31
  export declare function documentKey(room: string, path: string): string;
35
32
  export declare function roomOfKey(key: string): string;
33
+ export declare function pathOfKey(key: string): string;
36
34
  export declare function markdownPath(path: string): boolean;
37
- export declare function rowsOf(room: string, path: string, document: Frontmatter | null, composition: Composition, change: HeadChange | null, fileId: string | null, binary: BinaryFileRecord | null): readonly Row[];
35
+ export declare function folderOf(path: string): string;
36
+ export type Reach = 'exact' | 'value' | 'link';
37
+ export type Placed = {
38
+ readonly keys: string;
39
+ readonly places: string;
40
+ readonly glob: boolean;
41
+ };
42
+ export declare function placedOf(pointer: string, reach: Reach): Placed;
43
+ export declare function kindOf(value: unknown): ValueKind;
44
+ export declare function described(path: string, content: string | null, outlined: Outline | null): Described;
45
+ export declare function derived(path: string, content: string | null, outlined: Outline | null, composition: Composition): Derived;
38
46
  export {};
39
47
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources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