@agentshouse/mdruntime 0.1.0-c2c52158b7381 → 0.1.0-c2e8a6f99866d

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 (97) hide show
  1. package/AGENTS.md +14 -10
  2. package/dist/adapter.d.ts +14 -5
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/bootstrap.d.ts +13 -6
  5. package/dist/bootstrap.d.ts.map +1 -1
  6. package/dist/bootstrap.js +86 -88
  7. package/dist/chain.d.ts +11 -0
  8. package/dist/chain.d.ts.map +1 -0
  9. package/dist/chain.js +64 -0
  10. package/dist/change-set.d.ts +5 -9
  11. package/dist/change-set.d.ts.map +1 -1
  12. package/dist/change-set.js +10 -86
  13. package/dist/chat/list.d.ts.map +1 -1
  14. package/dist/chat/list.js +1 -1
  15. package/dist/chat/message.d.ts.map +1 -1
  16. package/dist/chat/message.js +8 -1
  17. package/dist/chat/messages.d.ts +1 -0
  18. package/dist/chat/messages.d.ts.map +1 -1
  19. package/dist/chat/messages.js +9 -1
  20. package/dist/chat/provider.d.ts +2 -0
  21. package/dist/chat/provider.d.ts.map +1 -1
  22. package/dist/chat/provider.js +17 -1
  23. package/dist/client.d.ts +1 -0
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +1 -0
  26. package/dist/collection.d.ts +5 -19
  27. package/dist/collection.d.ts.map +1 -1
  28. package/dist/collection.js +22 -360
  29. package/dist/compile.d.ts +11 -0
  30. package/dist/compile.d.ts.map +1 -0
  31. package/dist/compile.js +712 -0
  32. package/dist/connection.d.ts +2 -2
  33. package/dist/connection.d.ts.map +1 -1
  34. package/dist/connection.js +1396 -624
  35. package/dist/conversation.d.ts +1 -1
  36. package/dist/conversation.d.ts.map +1 -1
  37. package/dist/conversation.js +26 -17
  38. package/dist/entry.d.ts +2 -1
  39. package/dist/entry.d.ts.map +1 -1
  40. package/dist/entry.js +17 -23
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/live.d.ts +22 -0
  44. package/dist/live.d.ts.map +1 -0
  45. package/dist/live.js +123 -0
  46. package/dist/memory.d.ts +1 -0
  47. package/dist/memory.d.ts.map +1 -1
  48. package/dist/memory.js +12 -0
  49. package/dist/observation.d.ts +12 -0
  50. package/dist/observation.d.ts.map +1 -1
  51. package/dist/observation.js +84 -0
  52. package/dist/overlay.d.ts +0 -3
  53. package/dist/overlay.d.ts.map +1 -1
  54. package/dist/overlay.js +1 -151
  55. package/dist/reach.d.ts.map +1 -1
  56. package/dist/reach.js +15 -35
  57. package/dist/reads.js +1 -1
  58. package/dist/refresh.d.ts +10 -13
  59. package/dist/refresh.d.ts.map +1 -1
  60. package/dist/refresh.js +74 -70
  61. package/dist/replica.d.ts +55 -38
  62. package/dist/replica.d.ts.map +1 -1
  63. package/dist/replica.js +273 -214
  64. package/dist/rows.d.ts +29 -31
  65. package/dist/rows.d.ts.map +1 -1
  66. package/dist/rows.js +113 -69
  67. package/dist/save.d.ts +9 -10
  68. package/dist/save.d.ts.map +1 -1
  69. package/dist/save.js +59 -57
  70. package/dist/search.d.ts +2 -2
  71. package/dist/search.d.ts.map +1 -1
  72. package/dist/search.js +60 -28
  73. package/dist/shared.d.ts +0 -3
  74. package/dist/shared.d.ts.map +1 -1
  75. package/dist/shared.js +1 -31
  76. package/dist/store.d.ts +79 -62
  77. package/dist/store.d.ts.map +1 -1
  78. package/dist/store.js +164 -330
  79. package/dist/stored.d.ts +143 -0
  80. package/dist/stored.d.ts.map +1 -0
  81. package/dist/stored.js +561 -0
  82. package/dist/tables.d.ts +246 -168
  83. package/dist/tables.d.ts.map +1 -1
  84. package/dist/tables.js +156 -25
  85. package/dist/turn.d.ts +1 -1
  86. package/dist/turn.d.ts.map +1 -1
  87. package/dist/turn.js +28 -20
  88. package/dist/validation.d.ts +30 -0
  89. package/dist/validation.d.ts.map +1 -0
  90. package/dist/validation.js +162 -0
  91. package/dist/windows.d.ts +2 -1
  92. package/dist/windows.d.ts.map +1 -1
  93. package/dist/windows.js +30 -25
  94. package/package.json +2 -3
  95. package/dist/read-side.d.ts +0 -27
  96. package/dist/read-side.d.ts.map +0 -1
  97. package/dist/read-side.js +0 -1179
package/dist/replica.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { equalValue, parse } from '@agentshouse/mdmodel';
2
2
  import { immutable, landing } from './change.js';
3
- import { changedCleanly, collecting, unreadable, validateCollection, } from './collection.js';
4
- import { acceptedBinaries, overlayChanged, overlaying, sameText, } from './overlay.js';
3
+ import { collectionOf } from './collection.js';
4
+ import { acceptedBinaries, overlaying } from './overlay.js';
5
5
  import { effectiveIn, rewriting } from './save.js';
6
- import { drafted, entriesIn, patched, settling, sharing } from './shared.js';
7
- import { ROW_WEIGHT, stepped } from './turn.js';
6
+ import { ROW_WEIGHT } from './turn.js';
8
7
  export function compositionOf(record) {
9
8
  return {
10
9
  model: record.model,
@@ -13,230 +12,187 @@ export function compositionOf(record) {
13
12
  : { roots: record.typedSelection.roots, model: record.selectionModel },
14
13
  };
15
14
  }
16
- function* holding(record) {
17
- const documents = yield* sharing(record.documents);
18
- const binaries = yield* sharing(record.binaries);
19
- const revisions = yield* sharing(record.revisions);
20
- const fileIds = yield* sharing(record.fileIds);
21
- const changes = yield* sharing(record.changes);
22
- const written = yield* sharing(record.written);
23
- return documents === record.documents &&
24
- binaries === record.binaries &&
25
- revisions === record.revisions &&
26
- fileIds === record.fileIds &&
27
- changes === record.changes &&
28
- written === record.written
29
- ? record
30
- : { ...record, documents, binaries, revisions, fileIds, changes, written };
31
- }
32
- export function confirmedOf(record, previous) {
33
- return stepped(confirming(record, previous));
34
- }
35
- function* confirming(record, previous) {
36
- const kept = yield* holding(record);
37
- return {
38
- record: kept,
39
- collection: yield* collecting(kept.documents, compositionOf(kept), previous?.collection),
40
- };
41
- }
42
15
  export function sameMembership(record, other) {
43
16
  return (JSON.stringify(record.typedSelection?.roots ?? null) ===
44
17
  JSON.stringify(other.typedSelection?.roots ?? null));
45
18
  }
46
- function* cleanly(record, previous) {
47
- if (previous === undefined)
48
- return false;
49
- const before = previous.record;
50
- return yield* changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
19
+ export function storedRecord(record) {
20
+ const { key: _key, ...stored } = record;
21
+ return JSON.stringify(stored);
51
22
  }
52
- function* staging(staged, previous) {
53
- const record = yield* holding(staged);
54
- const textChanged = previous === undefined || !(yield* sameText(record, previous.record));
55
- const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
56
- if (modeled &&
57
- (textChanged ||
58
- record.model !== previous?.record.model ||
59
- record.selectionModel !== previous?.record.selectionModel) &&
60
- !(yield* cleanly(record, previous))) {
61
- const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
62
- if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
63
- return { kind: 'refused', refusal: verdict };
64
- }
65
- if (verdict.verdict === 'refuse') {
66
- const refused = yield* unreadable(record.documents, previous?.record.documents);
67
- if (refused !== null)
68
- return refused;
69
- }
70
- }
71
- else if (textChanged) {
72
- const refused = yield* unreadable(record.documents, previous?.record.documents);
73
- if (refused !== null)
74
- return refused;
23
+ const PROBES = new Set([
24
+ 'then',
25
+ 'toJSON',
26
+ 'constructor',
27
+ 'valueOf',
28
+ 'toString',
29
+ ]);
30
+ class UnreadPath extends Error {
31
+ constructor(path) {
32
+ super(`the replica slice holds no row for ${path}`);
75
33
  }
76
- return { kind: 'staged', confirmed: yield* confirming(record, previous) };
77
- }
78
- export function readStaged(staged, previous) {
79
- return stepped(staging(staged, previous));
80
- }
81
- function* reclassifying(record, previous) {
82
- const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
83
- if (verdict.verdict !== 'refuse')
84
- return { kind: 'staged', confirmed: yield* confirming(record, previous) };
85
- return verdict.rule === 'model-unavailable'
86
- ? { kind: 'deferred' }
87
- : { kind: 'refused', refusal: verdict };
88
- }
89
- export function readReclassified(record, previous) {
90
- return stepped(reclassifying(record, previous));
91
34
  }
92
- function* returnedBinaries(held, submitted, accepted) {
93
- const binaries = drafted(held);
94
- for (const change of submitted.changes) {
95
- if (change.kind === 'arrival' && 'binary' in change) {
96
- if (accepted.revisions[change.path] !== undefined)
97
- binaries[change.path] = { state: 'accepted', ...change.binary };
98
- continue;
35
+ function strict(values, held) {
36
+ const guard = (property) => {
37
+ if (typeof property === 'string' && !held.has(property) && !PROBES.has(property)) {
38
+ throw new UnreadPath(property);
99
39
  }
100
- if (change.kind !== 'move')
101
- continue;
102
- const moved = binaries[change.path];
103
- if (moved === undefined || accepted.revisions[change.to] === undefined)
104
- continue;
105
- binaries[change.to] = moved;
106
- delete binaries[change.path];
107
- }
108
- for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {})) {
109
- binaries[path] = binary;
110
- yield ROW_WEIGHT;
111
- }
112
- for (const path of accepted.removals) {
113
- delete binaries[path];
114
- yield ROW_WEIGHT;
115
- }
116
- return yield* settling(binaries);
40
+ };
41
+ return new Proxy(values, {
42
+ get(target, property, receiver) {
43
+ guard(property);
44
+ return Reflect.get(target, property, receiver);
45
+ },
46
+ has(target, property) {
47
+ guard(property);
48
+ return Reflect.has(target, property);
49
+ },
50
+ getOwnPropertyDescriptor(target, property) {
51
+ guard(property);
52
+ return Reflect.getOwnPropertyDescriptor(target, property);
53
+ },
54
+ });
117
55
  }
118
- function* returning(confirmed, submitted, accepted, roomVersion, writtenAt) {
119
- const held = confirmed.record;
120
- const documents = drafted(held.documents);
121
- const revisions = drafted(held.revisions);
122
- const fileIds = drafted(held.fileIds);
123
- const changes = drafted(held.changes);
124
- const written = drafted(held.written);
125
- for (const [path, content] of entriesIn(accepted.documents)) {
126
- documents[path] = content;
127
- delete fileIds[path];
128
- written[path] = writtenAt;
129
- yield ROW_WEIGHT + content.length;
130
- }
131
- for (const [path, revision] of entriesIn(accepted.revisions)) {
132
- revisions[path] = revision;
133
- delete fileIds[path];
134
- if (held.revisions[path] !== revision)
135
- delete changes[path];
56
+ export function* slicing(entries, paths) {
57
+ const held = new Set(paths);
58
+ for (const entry of entries)
59
+ held.add(entry.path);
60
+ const documents = {};
61
+ const binaries = {};
62
+ const revisions = {};
63
+ const fileIds = {};
64
+ const changes = {};
65
+ const written = {};
66
+ for (const entry of entries) {
67
+ if (entry.binary !== null)
68
+ binaries[entry.path] = entry.binary;
69
+ else if (entry.content !== null)
70
+ documents[entry.path] = entry.content;
71
+ if (entry.revision !== null)
72
+ revisions[entry.path] = entry.revision;
73
+ if (entry.fileId !== null)
74
+ fileIds[entry.path] = entry.fileId;
75
+ if (entry.change !== null)
76
+ changes[entry.path] = entry.change;
77
+ if (entry.written !== null)
78
+ written[entry.path] = entry.written;
136
79
  yield ROW_WEIGHT;
137
80
  }
138
- for (const [path, fileId] of entriesIn(accepted.fileIds ?? {})) {
139
- fileIds[path] = fileId;
140
- yield ROW_WEIGHT;
141
- }
142
- for (const [path, change] of entriesIn(accepted.changes)) {
143
- changes[path] = change;
144
- yield ROW_WEIGHT;
145
- }
146
- for (const path of accepted.removals) {
147
- delete documents[path];
148
- delete revisions[path];
149
- delete fileIds[path];
150
- delete changes[path];
151
- delete written[path];
81
+ return {
82
+ documents: strict(documents, held),
83
+ binaries: strict(binaries, held),
84
+ revisions: strict(revisions, held),
85
+ fileIds: strict(fileIds, held),
86
+ changes: strict(changes, held),
87
+ written: strict(written, held),
88
+ held,
89
+ };
90
+ }
91
+ export function entryAt(layer, path) {
92
+ const content = layer.documents[path];
93
+ const binary = layer.binaries[path];
94
+ if (content === undefined && binary === undefined)
95
+ return null;
96
+ return {
97
+ path,
98
+ content: content ?? null,
99
+ binary: binary ?? null,
100
+ revision: layer.revisions[path] ?? null,
101
+ fileId: layer.fileIds[path] ?? null,
102
+ change: layer.changes[path] ?? null,
103
+ written: layer.written?.[path] ?? null,
104
+ };
105
+ }
106
+ export function* slicingWith(slice, set, removed) {
107
+ const entries = new Map();
108
+ for (const path of slice.held) {
109
+ const entry = entryAt(slice, path);
110
+ if (entry !== null)
111
+ entries.set(path, { ...entry, type: null });
152
112
  yield ROW_WEIGHT;
153
113
  }
154
- return yield* staging({
155
- ...held,
156
- roomVersion,
157
- documents: yield* settling(documents),
158
- revisions: yield* settling(revisions),
159
- fileIds: yield* settling(fileIds),
160
- changes: yield* settling(changes),
161
- written: yield* settling(written),
162
- binaries: yield* returnedBinaries(held.binaries, submitted, accepted),
163
- }, confirmed);
114
+ for (const path of removed)
115
+ entries.delete(path);
116
+ for (const entry of set)
117
+ entries.set(entry.path, { ...entry, type: null });
118
+ return yield* slicing([...entries.values()], [...slice.held, ...set.map(({ path }) => path), ...removed]);
164
119
  }
165
- export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
166
- return stepped(returning(confirmed, submitted, accepted, roomVersion, writtenAt));
120
+ function changePaths(change) {
121
+ return change.kind === 'move' ? [change.path, change.to] : [change.path];
167
122
  }
168
- function* predicting(confirmed, batches, previous) {
169
- const composition = compositionOf(confirmed.record);
170
- const locator = confirmed.record.locator;
171
- let layer = confirmed.record;
172
- const replay = [];
173
- const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);
174
- for (const batch of batches) {
175
- const before = layer;
176
- const old = prior.get(batch.id);
177
- const hasMove = rewriting(batch, locator);
178
- const reuseRewrite = old?.collection !== undefined &&
179
- (yield* sameText(before, old.before)) &&
180
- old.collection.composition.model === composition.model &&
181
- old.collection.composition.selection?.model === composition.selection?.model &&
182
- JSON.stringify(old.collection.composition.selection?.roots) ===
183
- JSON.stringify(composition.selection?.roots);
184
- const collection = hasMove
185
- ? reuseRewrite
186
- ? old.collection
187
- : yield* collecting(before.documents, composition, old?.collection ?? confirmed.collection)
188
- : undefined;
189
- const effective = collection === undefined
190
- ? batch
191
- : reuseRewrite
192
- ? old.effective
193
- : yield* effectiveIn(batch, locator, { ...before, collection });
194
- layer =
195
- old === undefined
196
- ? yield* overlaying(before, [effective])
197
- : yield* overlayChanged(before, effective, old.before, old.effective, old.after);
198
- replay.push({
199
- id: batch.id,
200
- before,
201
- after: layer,
202
- effective,
203
- ...(collection === undefined ? {} : { collection }),
204
- });
123
+ export function touchedBy(queue) {
124
+ const paths = new Set();
125
+ for (const batch of queue) {
126
+ for (const change of batch.changes)
127
+ for (const path of changePaths(change))
128
+ paths.add(path);
129
+ for (const precondition of batch.preconditions)
130
+ paths.add(precondition.path);
131
+ for (const move of batch.between?.moves ?? [])
132
+ paths.add(move.path);
205
133
  }
206
- return { layer, replay };
134
+ return paths;
207
135
  }
208
- export function* replicating(confirmed, queue, previous) {
209
- const batches = Object.freeze(queue.map(immutable));
210
- if (batches.length === 0) {
211
- return {
212
- confirmed,
213
- queue: batches,
214
- visible: {
215
- documents: confirmed.record.documents,
216
- binaries: confirmed.record.binaries,
217
- revisions: confirmed.record.revisions,
218
- fileIds: confirmed.record.fileIds,
219
- changes: confirmed.record.changes,
220
- collection: confirmed.collection,
221
- },
222
- replay: [],
223
- };
136
+ export function movedBy(queue, locator) {
137
+ const paths = new Set();
138
+ for (const batch of queue) {
139
+ if (!rewriting(batch, locator))
140
+ continue;
141
+ for (const change of batch.changes)
142
+ if (change.kind === 'move')
143
+ paths.add(change.path);
144
+ if (batch.between?.source.room === locator) {
145
+ for (const move of batch.between.moves)
146
+ paths.add(move.path);
147
+ }
148
+ }
149
+ return paths;
150
+ }
151
+ export function* replaying(confirmed, queue, locator, composition) {
152
+ let layer = confirmed;
153
+ const touched = new Set();
154
+ for (const batch of queue) {
155
+ const effective = rewriting(batch, locator)
156
+ ? yield* effectiveIn(batch, locator, {
157
+ ...layer,
158
+ collection: collectionOf(layer.documents, composition),
159
+ })
160
+ : batch;
161
+ for (const change of effective.changes)
162
+ for (const path of changePaths(change))
163
+ touched.add(path);
164
+ layer = yield* overlaying(layer, [effective]);
165
+ yield ROW_WEIGHT;
224
166
  }
225
- const { layer, replay } = yield* predicting(confirmed, batches, previous);
226
167
  return {
227
- confirmed,
228
- queue: batches,
229
- replay,
230
- visible: {
231
- ...layer,
232
- collection: yield* collecting(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
233
- },
168
+ visible: { ...layer, collection: collectionOf(layer.documents, composition) },
169
+ touched,
234
170
  };
235
171
  }
172
+ export function* overlayOf(visible, touched) {
173
+ const rows = [];
174
+ for (const path of touched) {
175
+ yield ROW_WEIGHT;
176
+ const entry = entryAt(visible, path);
177
+ rows.push(entry === null
178
+ ? {
179
+ path,
180
+ present: false,
181
+ content: null,
182
+ binary: null,
183
+ revision: null,
184
+ fileId: null,
185
+ change: null,
186
+ written: null,
187
+ }
188
+ : { ...entry, written: null, present: true });
189
+ }
190
+ return rows;
191
+ }
236
192
  function present(layer, path) {
237
193
  return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
238
194
  }
239
- function holds(layer, preconditions) {
195
+ export function holds(layer, preconditions) {
240
196
  const parsed = new Map();
241
197
  const documentAt = (path) => {
242
198
  if (!parsed.has(path)) {
@@ -306,10 +262,14 @@ function effects(change) {
306
262
  return [{ kind: 'absent', path }];
307
263
  }
308
264
  export function landed(batch, confirmed, current = {}) {
309
- const layer = {
310
- ...confirmed.record,
311
- documents: patched(confirmed.record.documents, Object.entries(current)),
312
- };
265
+ const documents = new Proxy(confirmed.documents, {
266
+ get(target, property, receiver) {
267
+ if (typeof property === 'string' && Object.hasOwn(current, property))
268
+ return current[property];
269
+ return Reflect.get(target, property, receiver);
270
+ },
271
+ });
272
+ const layer = { ...confirmed, documents };
313
273
  return batch.changes.every((change, index) => {
314
274
  if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
315
275
  const at = landing(batch.changes, index, change.path);
@@ -341,11 +301,10 @@ function founded(batch, layer) {
341
301
  });
342
302
  return changed ? immutable({ ...batch, preconditions }) : batch;
343
303
  }
344
- export function* standing(confirmed, queue, withdrawable, local) {
304
+ export function* standing(confirmed, queue, withdrawable, local, locator, composition) {
345
305
  if (!queue.some(withdrawable))
346
306
  return { withdrawn: [], kept: queue };
347
- const composition = compositionOf(confirmed.record);
348
- let layer = confirmed.record;
307
+ let layer = confirmed;
349
308
  const withdrawn = [];
350
309
  const kept = [];
351
310
  for (const batch of queue) {
@@ -353,10 +312,10 @@ export function* standing(confirmed, queue, withdrawable, local) {
353
312
  withdrawn.push(batch);
354
313
  continue;
355
314
  }
356
- const effective = rewriting(batch, confirmed.record.locator)
357
- ? yield* effectiveIn(batch, confirmed.record.locator, {
315
+ const effective = rewriting(batch, locator)
316
+ ? yield* effectiveIn(batch, locator, {
358
317
  ...layer,
359
- collection: yield* collecting(layer.documents, composition),
318
+ collection: collectionOf(layer.documents, composition),
360
319
  })
361
320
  : batch;
362
321
  let unapplied = false;
@@ -372,3 +331,103 @@ export function* standing(confirmed, queue, withdrawable, local) {
372
331
  }
373
332
  return { withdrawn, kept };
374
333
  }
334
+ export function returnedPaths(submitted, accepted) {
335
+ const paths = new Set([
336
+ ...Object.keys(accepted.documents),
337
+ ...Object.keys(accepted.revisions),
338
+ ...Object.keys(accepted.fileIds ?? {}),
339
+ ...Object.keys(accepted.changes),
340
+ ...Object.keys(accepted.binaryFiles ?? {}),
341
+ ...accepted.removals,
342
+ ]);
343
+ for (const change of submitted.changes) {
344
+ if (change.kind === 'move') {
345
+ paths.add(change.path);
346
+ paths.add(change.to);
347
+ }
348
+ if (change.kind === 'arrival')
349
+ paths.add(change.path);
350
+ }
351
+ return paths;
352
+ }
353
+ export function* returning(confirmed, submitted, accepted, writtenAt) {
354
+ const documents = new Map();
355
+ const binaries = new Map();
356
+ const revisions = new Map();
357
+ const fileIds = new Map();
358
+ const changes = new Map();
359
+ const written = new Map();
360
+ const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
361
+ for (const [path, content] of Object.entries(accepted.documents)) {
362
+ yield ROW_WEIGHT;
363
+ documents.set(path, content);
364
+ fileIds.set(path, undefined);
365
+ written.set(path, writtenAt);
366
+ }
367
+ for (const [path, revision] of Object.entries(accepted.revisions)) {
368
+ yield ROW_WEIGHT;
369
+ revisions.set(path, revision);
370
+ fileIds.set(path, undefined);
371
+ if (confirmed.revisions[path] !== revision)
372
+ changes.set(path, undefined);
373
+ }
374
+ for (const [path, fileId] of Object.entries(accepted.fileIds ?? {}))
375
+ fileIds.set(path, fileId);
376
+ for (const [path, change] of Object.entries(accepted.changes))
377
+ changes.set(path, change);
378
+ for (const path of accepted.removals) {
379
+ documents.set(path, undefined);
380
+ revisions.set(path, undefined);
381
+ fileIds.set(path, undefined);
382
+ changes.set(path, undefined);
383
+ written.set(path, undefined);
384
+ }
385
+ for (const change of submitted.changes) {
386
+ if (change.kind === 'arrival' && 'binary' in change) {
387
+ if (accepted.revisions[change.path] !== undefined) {
388
+ binaries.set(change.path, { state: 'accepted', ...change.binary });
389
+ }
390
+ continue;
391
+ }
392
+ if (change.kind !== 'move')
393
+ continue;
394
+ const moved = read(binaries, confirmed.binaries, change.path);
395
+ if (moved === undefined || accepted.revisions[change.to] === undefined)
396
+ continue;
397
+ binaries.set(change.to, moved);
398
+ binaries.set(change.path, undefined);
399
+ }
400
+ for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
401
+ binaries.set(path, binary);
402
+ for (const path of accepted.removals)
403
+ binaries.set(path, undefined);
404
+ const paths = new Set([
405
+ ...documents.keys(),
406
+ ...binaries.keys(),
407
+ ...revisions.keys(),
408
+ ...fileIds.keys(),
409
+ ...changes.keys(),
410
+ ...written.keys(),
411
+ ]);
412
+ const set = [];
413
+ const removed = [];
414
+ for (const path of paths) {
415
+ yield ROW_WEIGHT;
416
+ const content = read(documents, confirmed.documents, path);
417
+ const binary = read(binaries, confirmed.binaries, path);
418
+ if (content === undefined && binary === undefined) {
419
+ removed.push(path);
420
+ continue;
421
+ }
422
+ set.push({
423
+ path,
424
+ content: binary === undefined ? (content ?? null) : null,
425
+ binary: binary ?? null,
426
+ revision: read(revisions, confirmed.revisions, path) ?? null,
427
+ fileId: read(fileIds, confirmed.fileIds, path) ?? null,
428
+ change: read(changes, confirmed.changes, path) ?? null,
429
+ written: read(written, confirmed.written, path) ?? null,
430
+ });
431
+ }
432
+ return { set, removed };
433
+ }
package/dist/rows.d.ts CHANGED
@@ -1,39 +1,37 @@
1
- import { type Frontmatter } from '@agentshouse/mdmodel';
2
- import type { HeadChange } from './adapter.js';
3
- import type { BinaryFileRecord } from './binary.js';
4
1
  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;
2
+ export type ValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'undefined';
3
+ type HeldValue = {
4
+ readonly form: string;
5
+ readonly held: number;
6
+ readonly item: number;
7
+ readonly kind: ValueKind;
8
+ readonly value: string | number | null;
9
+ readonly size: number | null;
10
+ readonly single: boolean;
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 form: string;
16
+ readonly target: string;
17
+ readonly field: string;
18
+ };
19
+ export type Derived = {
20
+ readonly type: string | null;
21
+ readonly declared: string | null;
22
+ readonly queried: boolean;
23
+ readonly folder: string;
24
+ readonly fields: string | null;
25
+ readonly values: readonly HeldValue[];
26
+ readonly links: readonly HeldLink[];
32
27
  };
33
- export type Row = DocumentRow | ReferenceRow;
34
28
  export declare function documentKey(room: string, path: string): string;
35
29
  export declare function roomOfKey(key: string): string;
30
+ export declare function pathOfKey(key: string): string;
36
31
  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[];
32
+ export declare function settingsTextPath(path: string): boolean;
33
+ export declare function folderOf(path: string): string;
34
+ export declare function kindOf(value: unknown): ValueKind;
35
+ export declare function derived(path: string, content: string | null, composition: Composition): Derived;
38
36
  export {};
39
37
  //# 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,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,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,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,gBAAgB,GAAG,IAA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