@agentshouse/mdruntime 0.1.0-alpha.2 → 0.1.0-alpha.3

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 (59) hide show
  1. package/dist/adapter.d.ts +12 -10
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/adapter.js.map +1 -1
  4. package/dist/bootstrap.d.ts +5 -12
  5. package/dist/bootstrap.d.ts.map +1 -1
  6. package/dist/bootstrap.js +13 -20
  7. package/dist/bootstrap.js.map +1 -1
  8. package/dist/change.d.ts +64 -0
  9. package/dist/change.d.ts.map +1 -0
  10. package/dist/change.js +12 -0
  11. package/dist/change.js.map +1 -0
  12. package/dist/collection.d.ts +1 -0
  13. package/dist/collection.d.ts.map +1 -1
  14. package/dist/collection.js +10 -6
  15. package/dist/collection.js.map +1 -1
  16. package/dist/connection.d.ts +19 -0
  17. package/dist/connection.d.ts.map +1 -1
  18. package/dist/connection.js +238 -32
  19. package/dist/connection.js.map +1 -1
  20. package/dist/index.d.ts +5 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/memory.d.ts +1 -0
  24. package/dist/memory.d.ts.map +1 -1
  25. package/dist/memory.js +67 -6
  26. package/dist/memory.js.map +1 -1
  27. package/dist/overlay.d.ts +8 -0
  28. package/dist/overlay.d.ts.map +1 -0
  29. package/dist/overlay.js +139 -0
  30. package/dist/overlay.js.map +1 -0
  31. package/dist/paths.d.ts +6 -0
  32. package/dist/paths.d.ts.map +1 -0
  33. package/dist/paths.js +47 -0
  34. package/dist/paths.js.map +1 -0
  35. package/dist/refresh.d.ts +13 -0
  36. package/dist/refresh.d.ts.map +1 -0
  37. package/dist/refresh.js +63 -0
  38. package/dist/refresh.js.map +1 -0
  39. package/dist/replica.d.ts +19 -0
  40. package/dist/replica.d.ts.map +1 -0
  41. package/dist/replica.js +36 -0
  42. package/dist/replica.js.map +1 -0
  43. package/dist/save.d.ts +26 -0
  44. package/dist/save.d.ts.map +1 -0
  45. package/dist/save.js +496 -0
  46. package/dist/save.js.map +1 -0
  47. package/dist/status.d.ts +15 -0
  48. package/dist/status.d.ts.map +1 -0
  49. package/dist/status.js +29 -0
  50. package/dist/status.js.map +1 -0
  51. package/dist/store.d.ts +21 -0
  52. package/dist/store.d.ts.map +1 -1
  53. package/dist/store.js +77 -2
  54. package/dist/store.js.map +1 -1
  55. package/dist/transfer.d.ts +5 -0
  56. package/dist/transfer.d.ts.map +1 -0
  57. package/dist/transfer.js +5 -0
  58. package/dist/transfer.js.map +1 -0
  59. package/package.json +3 -3
package/dist/save.js ADDED
@@ -0,0 +1,496 @@
1
+ import { apply, links, serialize, validate } from '@agentshouse/mdmodel';
2
+ import { immutable } from './change.js';
3
+ import { parseCollection } from './collection.js';
4
+ import { overlay } from './overlay.js';
5
+ import { beneath, covered, normalize, relative, resolve } from './paths.js';
6
+ function refuse(rule, file, location) {
7
+ return {
8
+ kind: 'refused',
9
+ refusal: {
10
+ rule,
11
+ ...file === undefined ? {} : {
12
+ file
13
+ },
14
+ ...location === undefined ? {} : {
15
+ location
16
+ }
17
+ }
18
+ };
19
+ }
20
+ function members(visible, prefix) {
21
+ return [
22
+ ...Object.keys(visible.documents),
23
+ ...visible.binaryTargets
24
+ ].filter((path)=>beneath(prefix, path)).sort();
25
+ }
26
+ function spread(change, path, member) {
27
+ if (change.kind === 'remove') return {
28
+ kind: 'remove',
29
+ path: member
30
+ };
31
+ return {
32
+ kind: 'move',
33
+ path: member,
34
+ to: `${change.to}${member.slice(path.length)}`
35
+ };
36
+ }
37
+ function expand(changes, visible) {
38
+ const expanded = [];
39
+ for (const change of changes){
40
+ if (change.kind !== 'move' && change.kind !== 'remove') {
41
+ expanded.push(change);
42
+ continue;
43
+ }
44
+ const path = normalize(change.path);
45
+ const to = change.kind === 'move' ? normalize(change.to) : '';
46
+ if (path === null || path === '' || to === null || change.kind === 'move' && to === '') {
47
+ return {
48
+ kind: 'refused',
49
+ refusal: {
50
+ rule: 'room-root',
51
+ file: change.path
52
+ }
53
+ };
54
+ }
55
+ const structural = change.kind === 'move' ? {
56
+ ...change,
57
+ path,
58
+ to
59
+ } : {
60
+ ...change,
61
+ path
62
+ };
63
+ const present = visible.documents[path] !== undefined || visible.binaryTargets.includes(path);
64
+ if (present) {
65
+ expanded.push(structural);
66
+ continue;
67
+ }
68
+ const beneathIt = members(visible, path);
69
+ if (beneathIt.length === 0) {
70
+ return {
71
+ kind: 'refused',
72
+ refusal: {
73
+ rule: 'path-absent',
74
+ file: change.path
75
+ }
76
+ };
77
+ }
78
+ for (const member of beneathIt)expanded.push(spread(structural, path, member));
79
+ }
80
+ return {
81
+ kind: 'changes',
82
+ changes: expanded
83
+ };
84
+ }
85
+ function referenceField(spec) {
86
+ if (typeof spec !== 'object' || spec === null) return false;
87
+ const declared = spec;
88
+ return declared.kind === 'reference' || declared.kind === 'list' && declared.of === 'reference';
89
+ }
90
+ function definitionOf(types, type) {
91
+ return types.find((declared)=>declared.name === type);
92
+ }
93
+ function retarget(value, from, to, moves) {
94
+ if (Array.isArray(value)) {
95
+ const next = value.map((item)=>retarget(item, from, to, moves) ?? item);
96
+ return next.some((item, index)=>item !== value[index]) ? next : undefined;
97
+ }
98
+ if (typeof value !== 'string') return undefined;
99
+ const target = resolve(from, value);
100
+ if (target === null) return undefined;
101
+ const next = relative(to, moves.get(target) ?? target);
102
+ return next === value ? undefined : next;
103
+ }
104
+ function edited(document, path, changes) {
105
+ let next = document;
106
+ for (const change of changes){
107
+ if (change.path !== path) continue;
108
+ if (change.kind !== 'section' && change.kind !== 'preamble') continue;
109
+ const applied = apply(next, change.kind === 'preamble' ? {
110
+ kind: 'preamble',
111
+ value: change.value,
112
+ prior: next.preamble
113
+ } : {
114
+ kind: 'section',
115
+ name: change.name,
116
+ value: change.value,
117
+ prior: next.sections[change.name]
118
+ });
119
+ if (applied.outcome === 'applied') next = applied.document;
120
+ }
121
+ return next;
122
+ }
123
+ function bodies(path, before, after) {
124
+ const changes = [];
125
+ if (after.preamble !== before.preamble) {
126
+ changes.push({
127
+ kind: 'preamble',
128
+ path,
129
+ value: after.preamble
130
+ });
131
+ }
132
+ for (const [name, value] of Object.entries(after.sections)){
133
+ if (before.sections[name] === value) continue;
134
+ changes.push({
135
+ kind: 'section',
136
+ path,
137
+ name,
138
+ value
139
+ });
140
+ }
141
+ return changes;
142
+ }
143
+ function relinks(path, moved, before, moves) {
144
+ let after = before;
145
+ for (const link of links(before, path)){
146
+ const destination = moves.get(link.target) ?? link.target;
147
+ if (destination === link.target && moved === path) continue;
148
+ const to = relative(moved, destination);
149
+ if (to === relative(path, link.target)) continue;
150
+ const applied = apply(after, {
151
+ kind: 'link',
152
+ href: link.href,
153
+ to
154
+ });
155
+ if (applied.outcome === 'refuse') {
156
+ return {
157
+ kind: 'refused',
158
+ refusal: {
159
+ rule: applied.refusal.rule,
160
+ file: path,
161
+ ...applied.refusal.location === undefined ? {} : {
162
+ location: applied.refusal.location
163
+ }
164
+ }
165
+ };
166
+ }
167
+ after = applied.document;
168
+ }
169
+ if (after === before) return {
170
+ kind: 'changes',
171
+ changes: []
172
+ };
173
+ if (before.type === undefined) {
174
+ return {
175
+ kind: 'changes',
176
+ changes: [
177
+ {
178
+ kind: 'replace',
179
+ path,
180
+ content: serialize(after)
181
+ }
182
+ ]
183
+ };
184
+ }
185
+ return {
186
+ kind: 'changes',
187
+ changes: bodies(path, before, after)
188
+ };
189
+ }
190
+ function subsumed(merged, path) {
191
+ for(let index = merged.length - 1; index >= 0; index -= 1){
192
+ const item = merged[index];
193
+ if (item.path !== path) continue;
194
+ if (item.kind === 'section' || item.kind === 'preamble') merged.splice(index, 1);
195
+ }
196
+ }
197
+ function rewrites(changes, visible) {
198
+ const moves = new Map();
199
+ const settled = new Set();
200
+ for (const change of changes){
201
+ if (change.kind === 'move') moves.set(change.path, change.to);
202
+ if (change.kind === 'remove' || change.kind === 'replace' || change.kind === 'create') {
203
+ settled.add(change.path);
204
+ }
205
+ if (change.kind === 'field') settled.add(`${change.path} ${change.name}`);
206
+ }
207
+ if (moves.size === 0) return {
208
+ kind: 'changes',
209
+ changes
210
+ };
211
+ const merged = [
212
+ ...changes
213
+ ];
214
+ const added = [];
215
+ for (const [path, document] of Object.entries(visible.collection.documents)){
216
+ if (settled.has(path)) continue;
217
+ const moved = moves.get(path) ?? path;
218
+ const definition = definitionOf(visible.collection.types, document.type);
219
+ for (const [name, spec] of Object.entries(definition?.fields ?? {})){
220
+ if (!referenceField(spec) || settled.has(`${path} ${name}`)) continue;
221
+ const value = retarget(document.fields[name], path, moved, moves);
222
+ if (value === undefined) continue;
223
+ added.push({
224
+ kind: 'field',
225
+ path,
226
+ name,
227
+ value
228
+ });
229
+ }
230
+ const relinked = relinks(path, moved, edited(document, path, merged), moves);
231
+ if (relinked.kind === 'refused') return relinked;
232
+ for (const change of relinked.changes){
233
+ if (change.kind === 'replace') {
234
+ subsumed(merged, path);
235
+ added.push(change);
236
+ continue;
237
+ }
238
+ const index = merged.findIndex((item)=>item.kind === change.kind && item.path === path && (change.kind !== 'section' || item.kind === 'section' && item.name === change.name));
239
+ if (index === -1) added.push(change);
240
+ else merged[index] = change;
241
+ }
242
+ }
243
+ return {
244
+ kind: 'changes',
245
+ changes: [
246
+ ...added,
247
+ ...merged
248
+ ]
249
+ };
250
+ }
251
+ function targets(value, from) {
252
+ const values = Array.isArray(value) ? value : [
253
+ value
254
+ ];
255
+ const resolved = [];
256
+ for (const item of values){
257
+ if (typeof item !== 'string') continue;
258
+ const target = resolve(from, item);
259
+ if (target !== null) resolved.push(target);
260
+ }
261
+ return resolved;
262
+ }
263
+ function incoming(collection, removed) {
264
+ const found = new Map();
265
+ const note = (target, file)=>{
266
+ if (!removed.has(target)) return;
267
+ const referrers = found.get(target) ?? new Set();
268
+ referrers.add(file);
269
+ found.set(target, referrers);
270
+ };
271
+ for (const [path, document] of Object.entries(collection.documents)){
272
+ const definition = definitionOf(collection.types, document.type);
273
+ for (const [name, spec] of Object.entries(definition?.fields ?? {})){
274
+ if (!referenceField(spec)) continue;
275
+ for (const target of targets(document.fields[name], path))note(target, path);
276
+ }
277
+ for (const link of links(document, path))note(link.target, path);
278
+ }
279
+ const [first] = [
280
+ ...found.keys()
281
+ ].sort();
282
+ if (first === undefined) return null;
283
+ const every = new Set();
284
+ for (const referrers of found.values())for (const file of referrers)every.add(file);
285
+ return {
286
+ kind: 'refused',
287
+ refusal: {
288
+ rule: 'referenced-missing-file',
289
+ file: first,
290
+ referrers: [
291
+ ...every
292
+ ].sort()
293
+ }
294
+ };
295
+ }
296
+ function affected(change) {
297
+ return change.kind === 'move' ? [
298
+ change.path,
299
+ change.to
300
+ ] : [
301
+ change.path
302
+ ];
303
+ }
304
+ function guard(changes, input) {
305
+ const existing = new Set([
306
+ ...Object.keys(input.visible.documents),
307
+ ...input.visible.binaryTargets
308
+ ]);
309
+ for (const change of changes){
310
+ for (const path of affected(change)){
311
+ const normalized = normalize(path);
312
+ if (normalized === null || normalized === '') return refuse('room-root', path);
313
+ if (covered(input.providerOwnedPaths, normalized)) {
314
+ return refuse('provider-owned-path', normalized);
315
+ }
316
+ if (!covered(input.writeGrants, normalized)) return refuse('write-grant', normalized);
317
+ }
318
+ if (change.kind === 'create') {
319
+ if (existing.has(change.path)) return refuse('path-collision', change.path);
320
+ existing.add(change.path);
321
+ continue;
322
+ }
323
+ if (change.kind === 'move') {
324
+ if (!existing.has(change.path)) return refuse('path-absent', change.path);
325
+ if (existing.has(change.to)) return refuse('path-collision', change.to);
326
+ existing.delete(change.path);
327
+ existing.add(change.to);
328
+ continue;
329
+ }
330
+ if (!existing.has(change.path)) return refuse('path-absent', change.path);
331
+ if (change.kind === 'remove') {
332
+ existing.delete(change.path);
333
+ continue;
334
+ }
335
+ if (change.kind === 'replace') {
336
+ if (input.visible.revisions[change.path] === undefined) {
337
+ return refuse('unknown-revision', change.path);
338
+ }
339
+ continue;
340
+ }
341
+ const document = input.visible.collection.documents[change.path];
342
+ if (document === undefined) return refuse('path-absent', change.path);
343
+ if (change.kind === 'section' && document.sections[change.name] === undefined) {
344
+ return refuse('required-section', change.path, change.name);
345
+ }
346
+ }
347
+ return null;
348
+ }
349
+ function existence(visible, path) {
350
+ const revision = visible.revisions[path];
351
+ return revision === undefined ? {
352
+ kind: 'present',
353
+ path
354
+ } : {
355
+ kind: 'revision',
356
+ path,
357
+ revision
358
+ };
359
+ }
360
+ function preconditionsOf(changes, visible) {
361
+ const preconditions = [];
362
+ const seen = new Set();
363
+ const add = (precondition)=>{
364
+ const part = precondition.kind === 'field' || precondition.kind === 'section' ? precondition.name : '';
365
+ const identity = `${precondition.kind} ${precondition.path} ${part}`;
366
+ if (seen.has(identity)) return;
367
+ seen.add(identity);
368
+ preconditions.push(precondition);
369
+ };
370
+ for (const change of changes){
371
+ if (change.kind === 'field') {
372
+ const document = visible.collection.documents[change.path];
373
+ add({
374
+ kind: 'field',
375
+ path: change.path,
376
+ name: change.name,
377
+ value: document.fields[change.name]
378
+ });
379
+ continue;
380
+ }
381
+ if (change.kind === 'section') {
382
+ const document = visible.collection.documents[change.path];
383
+ add({
384
+ kind: 'section',
385
+ path: change.path,
386
+ name: change.name,
387
+ value: document.sections[change.name]
388
+ });
389
+ continue;
390
+ }
391
+ if (change.kind === 'preamble') {
392
+ const document = visible.collection.documents[change.path];
393
+ add({
394
+ kind: 'preamble',
395
+ path: change.path,
396
+ value: document.preamble
397
+ });
398
+ continue;
399
+ }
400
+ if (change.kind === 'create') {
401
+ add({
402
+ kind: 'absent',
403
+ path: change.path
404
+ });
405
+ continue;
406
+ }
407
+ add(existence(visible, change.path));
408
+ if (change.kind === 'move') add({
409
+ kind: 'absent',
410
+ path: change.to
411
+ });
412
+ }
413
+ return preconditions;
414
+ }
415
+ function depth(path) {
416
+ return path.split('/').length;
417
+ }
418
+ function exceeded(limits, changes, resulting) {
419
+ const written = changes.map((change)=>change.kind === 'move' ? change.to : change.path);
420
+ const created = changes.filter((change)=>change.kind === 'create' || change.kind === 'move').map((change)=>change.kind === 'move' ? change.to : change.path);
421
+ for (const limit of limits){
422
+ const value = limit.value;
423
+ if (typeof value !== 'number') continue;
424
+ if (limit.name === 'change-batch-operations' && changes.length > value) {
425
+ return refuse('provider-limit', undefined, limit.name);
426
+ }
427
+ if (limit.name === 'document-size') {
428
+ const large = written.find((path)=>(resulting.documents[path] ?? '').length > value);
429
+ if (large !== undefined) return refuse('provider-limit', large, limit.name);
430
+ }
431
+ if (limit.name === 'path-length') {
432
+ const long = created.find((path)=>path.length > value);
433
+ if (long !== undefined) return refuse('provider-limit', long, limit.name);
434
+ }
435
+ if (limit.name === 'path-depth') {
436
+ const deep = created.find((path)=>depth(path) > value);
437
+ if (deep !== undefined) return refuse('provider-limit', deep, limit.name);
438
+ }
439
+ }
440
+ return null;
441
+ }
442
+ export function buildBatch(input) {
443
+ const expanded = expand(input.changes, input.visible);
444
+ if (expanded.kind === 'refused') return expanded;
445
+ const rewritten = rewrites(expanded.changes, input.visible);
446
+ if (rewritten.kind === 'refused') return rewritten;
447
+ const changes = rewritten.changes;
448
+ if (changes.length === 0) return refuse('no-change');
449
+ const refusal = guard(changes, input);
450
+ if (refusal !== null) return refusal;
451
+ const preconditions = preconditionsOf(changes, input.visible);
452
+ const resulting = overlay(input.visible, [
453
+ {
454
+ id: '',
455
+ baseRoomVersion: input.baseRoomVersion,
456
+ changes,
457
+ preconditions
458
+ }
459
+ ]);
460
+ const removed = new Set(changes.filter((change)=>change.kind === 'remove').map((change)=>change.path));
461
+ if (removed.size > 0) {
462
+ const referenced = incoming(parseCollection(resulting.documents), removed);
463
+ if (referenced !== null) return referenced;
464
+ }
465
+ const verdict = validate(resulting.documents, {
466
+ binaryTargets: resulting.binaryTargets
467
+ });
468
+ if (verdict.verdict === 'refuse') {
469
+ return {
470
+ kind: 'refused',
471
+ refusal: {
472
+ rule: verdict.rule,
473
+ file: verdict.file,
474
+ ...verdict.location === undefined ? {} : {
475
+ location: verdict.location
476
+ },
477
+ ...verdict.referrers === undefined ? {} : {
478
+ referrers: verdict.referrers
479
+ }
480
+ }
481
+ };
482
+ }
483
+ const limited = exceeded(input.providerLimits, changes, resulting);
484
+ if (limited !== null) return limited;
485
+ return {
486
+ kind: 'batch',
487
+ batch: immutable({
488
+ id: crypto.randomUUID(),
489
+ baseRoomVersion: input.baseRoomVersion,
490
+ changes,
491
+ preconditions
492
+ })
493
+ };
494
+ }
495
+
496
+ //# sourceMappingURL=save.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/save.ts"],"sourcesContent":["import { apply, links, serialize, validate, type Document } from '@agentshouse/mdmodel';\nimport type { ProviderLimit } from './adapter.js';\nimport { immutable, type Change, type ChangeBatch, type Precondition } from './change.js';\nimport { parseCollection, type Collection, type MdType } from './collection.js';\nimport { overlay, type Layer } from './overlay.js';\nimport { beneath, covered, normalize, relative, resolve } from './paths.js';\nimport type { VisibleLayer } from './replica.js';\n\nexport type SaveRefusal = {\n rule: string;\n file?: string;\n location?: string;\n referrers?: readonly string[];\n};\n\nexport type SaveInput = {\n baseRoomVersion: string;\n writeGrants: readonly string[];\n providerOwnedPaths: readonly string[];\n providerLimits: readonly ProviderLimit[];\n visible: VisibleLayer;\n changes: readonly Change[];\n};\n\nexport type BatchResult =\n | { kind: 'batch'; batch: ChangeBatch }\n | { kind: 'refused'; refusal: SaveRefusal };\n\ntype Structural = { kind: 'move'; path: string; to: string } | { kind: 'remove'; path: string };\n\ntype Expansion =\n | { kind: 'changes'; changes: readonly Change[] }\n | { kind: 'refused'; refusal: SaveRefusal };\n\nfunction refuse(rule: string, file?: string, location?: string): BatchResult {\n return {\n kind: 'refused',\n refusal: {\n rule,\n ...(file === undefined ? {} : { file }),\n ...(location === undefined ? {} : { location }),\n },\n };\n}\n\nfunction members(visible: Layer, prefix: string): readonly string[] {\n return [...Object.keys(visible.documents), ...visible.binaryTargets]\n .filter((path) => beneath(prefix, path))\n .sort();\n}\n\nfunction spread(change: Structural, path: string, member: string): Change {\n if (change.kind === 'remove') return { kind: 'remove', path: member };\n return { kind: 'move', path: member, to: `${change.to}${member.slice(path.length)}` };\n}\n\nfunction expand(changes: readonly Change[], visible: VisibleLayer): Expansion {\n const expanded: Change[] = [];\n for (const change of changes) {\n if (change.kind !== 'move' && change.kind !== 'remove') {\n expanded.push(change);\n continue;\n }\n const path = normalize(change.path);\n const to = change.kind === 'move' ? normalize(change.to) : '';\n if (path === null || path === '' || to === null || (change.kind === 'move' && to === '')) {\n return { kind: 'refused', refusal: { rule: 'room-root', file: change.path } };\n }\n const structural = change.kind === 'move' ? { ...change, path, to } : { ...change, path };\n const present = visible.documents[path] !== undefined || visible.binaryTargets.includes(path);\n if (present) {\n expanded.push(structural);\n continue;\n }\n const beneathIt = members(visible, path);\n if (beneathIt.length === 0) {\n return { kind: 'refused', refusal: { rule: 'path-absent', file: change.path } };\n }\n for (const member of beneathIt) expanded.push(spread(structural, path, member));\n }\n return { kind: 'changes', changes: expanded };\n}\n\nfunction referenceField(spec: unknown): boolean {\n if (typeof spec !== 'object' || spec === null) return false;\n const declared = spec as { kind?: unknown; of?: unknown };\n return declared.kind === 'reference' || (declared.kind === 'list' && declared.of === 'reference');\n}\n\nfunction definitionOf(types: readonly MdType[], type: string | undefined) {\n return types.find((declared) => declared.name === type);\n}\n\nfunction retarget(\n value: unknown,\n from: string,\n to: string,\n moves: ReadonlyMap<string, string>,\n): unknown {\n if (Array.isArray(value)) {\n const next = value.map((item) => retarget(item, from, to, moves) ?? item);\n return next.some((item, index) => item !== value[index]) ? next : undefined;\n }\n if (typeof value !== 'string') return undefined;\n const target = resolve(from, value);\n if (target === null) return undefined;\n const next = relative(to, moves.get(target) ?? target);\n return next === value ? undefined : next;\n}\n\nfunction edited(document: Document, path: string, changes: readonly Change[]): Document {\n let next = document;\n for (const change of changes) {\n if (change.path !== path) continue;\n if (change.kind !== 'section' && change.kind !== 'preamble') continue;\n const applied = apply(\n next,\n change.kind === 'preamble'\n ? { kind: 'preamble', value: change.value, prior: next.preamble }\n : {\n kind: 'section',\n name: change.name,\n value: change.value,\n prior: next.sections[change.name],\n },\n );\n if (applied.outcome === 'applied') next = applied.document;\n }\n return next;\n}\n\nfunction bodies(path: string, before: Document, after: Document): readonly Change[] {\n const changes: Change[] = [];\n if (after.preamble !== before.preamble) {\n changes.push({ kind: 'preamble', path, value: after.preamble });\n }\n for (const [name, value] of Object.entries(after.sections)) {\n if (before.sections[name] === value) continue;\n changes.push({ kind: 'section', path, name, value });\n }\n return changes;\n}\n\nfunction relinks(\n path: string,\n moved: string,\n before: Document,\n moves: ReadonlyMap<string, string>,\n): Expansion {\n let after = before;\n for (const link of links(before, path)) {\n const destination = moves.get(link.target) ?? link.target;\n if (destination === link.target && moved === path) continue;\n const to = relative(moved, destination);\n if (to === relative(path, link.target)) continue;\n const applied = apply(after, { kind: 'link', href: link.href, to });\n if (applied.outcome === 'refuse') {\n return {\n kind: 'refused',\n refusal: {\n rule: applied.refusal.rule,\n file: path,\n ...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),\n },\n };\n }\n after = applied.document;\n }\n if (after === before) return { kind: 'changes', changes: [] };\n if (before.type === undefined) {\n return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };\n }\n return { kind: 'changes', changes: bodies(path, before, after) };\n}\n\nfunction subsumed(merged: Change[], path: string) {\n for (let index = merged.length - 1; index >= 0; index -= 1) {\n const item = merged[index];\n if (item.path !== path) continue;\n if (item.kind === 'section' || item.kind === 'preamble') merged.splice(index, 1);\n }\n}\n\nfunction rewrites(changes: readonly Change[], visible: VisibleLayer): Expansion {\n const moves = new Map<string, string>();\n const settled = new Set<string>();\n for (const change of changes) {\n if (change.kind === 'move') moves.set(change.path, change.to);\n if (change.kind === 'remove' || change.kind === 'replace' || change.kind === 'create') {\n settled.add(change.path);\n }\n if (change.kind === 'field') settled.add(`${change.path} ${change.name}`);\n }\n if (moves.size === 0) return { kind: 'changes', changes };\n const merged = [...changes];\n const added: Change[] = [];\n for (const [path, document] of Object.entries(visible.collection.documents)) {\n if (settled.has(path)) continue;\n const moved = moves.get(path) ?? path;\n const definition = definitionOf(visible.collection.types, document.type);\n for (const [name, spec] of Object.entries(definition?.fields ?? {})) {\n if (!referenceField(spec) || settled.has(`${path} ${name}`)) continue;\n const value = retarget(document.fields[name], path, moved, moves);\n if (value === undefined) continue;\n added.push({ kind: 'field', path, name, value });\n }\n const relinked = relinks(path, moved, edited(document, path, merged), moves);\n if (relinked.kind === 'refused') return relinked;\n for (const change of relinked.changes) {\n if (change.kind === 'replace') {\n subsumed(merged, path);\n added.push(change);\n continue;\n }\n const index = merged.findIndex(\n (item) =>\n item.kind === change.kind &&\n item.path === path &&\n (change.kind !== 'section' || (item.kind === 'section' && item.name === change.name)),\n );\n if (index === -1) added.push(change);\n else merged[index] = change;\n }\n }\n return { kind: 'changes', changes: [...added, ...merged] };\n}\n\nfunction targets(value: unknown, from: string): readonly string[] {\n const values = Array.isArray(value) ? value : [value];\n const resolved: string[] = [];\n for (const item of values) {\n if (typeof item !== 'string') continue;\n const target = resolve(from, item);\n if (target !== null) resolved.push(target);\n }\n return resolved;\n}\n\nfunction incoming(collection: Collection, removed: ReadonlySet<string>): BatchResult | null {\n const found = new Map<string, Set<string>>();\n const note = (target: string, file: string) => {\n if (!removed.has(target)) return;\n const referrers = found.get(target) ?? new Set<string>();\n referrers.add(file);\n found.set(target, referrers);\n };\n for (const [path, document] of Object.entries(collection.documents)) {\n const definition = definitionOf(collection.types, document.type);\n for (const [name, spec] of Object.entries(definition?.fields ?? {})) {\n if (!referenceField(spec)) continue;\n for (const target of targets(document.fields[name], path)) note(target, path);\n }\n for (const link of links(document, path)) note(link.target, path);\n }\n const [first] = [...found.keys()].sort();\n if (first === undefined) return null;\n const every = new Set<string>();\n for (const referrers of found.values()) for (const file of referrers) every.add(file);\n return {\n kind: 'refused',\n refusal: { rule: 'referenced-missing-file', file: first, referrers: [...every].sort() },\n };\n}\n\nfunction affected(change: Change): readonly string[] {\n return change.kind === 'move' ? [change.path, change.to] : [change.path];\n}\n\nfunction guard(changes: readonly Change[], input: SaveInput): BatchResult | null {\n const existing = new Set([\n ...Object.keys(input.visible.documents),\n ...input.visible.binaryTargets,\n ]);\n for (const change of changes) {\n for (const path of affected(change)) {\n const normalized = normalize(path);\n if (normalized === null || normalized === '') return refuse('room-root', path);\n if (covered(input.providerOwnedPaths, normalized)) {\n return refuse('provider-owned-path', normalized);\n }\n if (!covered(input.writeGrants, normalized)) return refuse('write-grant', normalized);\n }\n if (change.kind === 'create') {\n if (existing.has(change.path)) return refuse('path-collision', change.path);\n existing.add(change.path);\n continue;\n }\n if (change.kind === 'move') {\n if (!existing.has(change.path)) return refuse('path-absent', change.path);\n if (existing.has(change.to)) return refuse('path-collision', change.to);\n existing.delete(change.path);\n existing.add(change.to);\n continue;\n }\n if (!existing.has(change.path)) return refuse('path-absent', change.path);\n if (change.kind === 'remove') {\n existing.delete(change.path);\n continue;\n }\n if (change.kind === 'replace') {\n if (input.visible.revisions[change.path] === undefined) {\n return refuse('unknown-revision', change.path);\n }\n continue;\n }\n const document = input.visible.collection.documents[change.path];\n if (document === undefined) return refuse('path-absent', change.path);\n if (change.kind === 'section' && document.sections[change.name] === undefined) {\n return refuse('required-section', change.path, change.name);\n }\n }\n return null;\n}\n\nfunction existence(visible: VisibleLayer, path: string): Precondition {\n const revision = visible.revisions[path];\n return revision === undefined ? { kind: 'present', path } : { kind: 'revision', path, revision };\n}\n\nfunction preconditionsOf(\n changes: readonly Change[],\n visible: VisibleLayer,\n): readonly Precondition[] {\n const preconditions: Precondition[] = [];\n const seen = new Set<string>();\n const add = (precondition: Precondition) => {\n const part =\n precondition.kind === 'field' || precondition.kind === 'section' ? precondition.name : '';\n const identity = `${precondition.kind} ${precondition.path} ${part}`;\n if (seen.has(identity)) return;\n seen.add(identity);\n preconditions.push(precondition);\n };\n for (const change of changes) {\n if (change.kind === 'field') {\n const document = visible.collection.documents[change.path];\n add({\n kind: 'field',\n path: change.path,\n name: change.name,\n value: document.fields[change.name],\n });\n continue;\n }\n if (change.kind === 'section') {\n const document = visible.collection.documents[change.path];\n add({\n kind: 'section',\n path: change.path,\n name: change.name,\n value: document.sections[change.name],\n });\n continue;\n }\n if (change.kind === 'preamble') {\n const document = visible.collection.documents[change.path];\n add({ kind: 'preamble', path: change.path, value: document.preamble });\n continue;\n }\n if (change.kind === 'create') {\n add({ kind: 'absent', path: change.path });\n continue;\n }\n add(existence(visible, change.path));\n if (change.kind === 'move') add({ kind: 'absent', path: change.to });\n }\n return preconditions;\n}\n\nfunction depth(path: string) {\n return path.split('/').length;\n}\n\nfunction exceeded(\n limits: readonly ProviderLimit[],\n changes: readonly Change[],\n resulting: Layer,\n): BatchResult | null {\n const written = changes.map((change) => (change.kind === 'move' ? change.to : change.path));\n const created = changes\n .filter((change) => change.kind === 'create' || change.kind === 'move')\n .map((change) => (change.kind === 'move' ? change.to : change.path));\n for (const limit of limits) {\n const value = limit.value;\n if (typeof value !== 'number') continue;\n if (limit.name === 'change-batch-operations' && changes.length > value) {\n return refuse('provider-limit', undefined, limit.name);\n }\n if (limit.name === 'document-size') {\n const large = written.find((path) => (resulting.documents[path] ?? '').length > value);\n if (large !== undefined) return refuse('provider-limit', large, limit.name);\n }\n if (limit.name === 'path-length') {\n const long = created.find((path) => path.length > value);\n if (long !== undefined) return refuse('provider-limit', long, limit.name);\n }\n if (limit.name === 'path-depth') {\n const deep = created.find((path) => depth(path) > value);\n if (deep !== undefined) return refuse('provider-limit', deep, limit.name);\n }\n }\n return null;\n}\n\nexport function buildBatch(input: SaveInput): BatchResult {\n const expanded = expand(input.changes, input.visible);\n if (expanded.kind === 'refused') return expanded;\n const rewritten = rewrites(expanded.changes, input.visible);\n if (rewritten.kind === 'refused') return rewritten;\n const changes = rewritten.changes;\n if (changes.length === 0) return refuse('no-change');\n const refusal = guard(changes, input);\n if (refusal !== null) return refusal;\n const preconditions = preconditionsOf(changes, input.visible);\n const resulting = overlay(input.visible, [\n { id: '', baseRoomVersion: input.baseRoomVersion, changes, preconditions },\n ]);\n const removed = new Set(\n changes.filter((change) => change.kind === 'remove').map((change) => change.path),\n );\n if (removed.size > 0) {\n const referenced = incoming(parseCollection(resulting.documents), removed);\n if (referenced !== null) return referenced;\n }\n const verdict = validate(resulting.documents, { binaryTargets: resulting.binaryTargets });\n if (verdict.verdict === 'refuse') {\n return {\n kind: 'refused',\n refusal: {\n rule: verdict.rule,\n file: verdict.file,\n ...(verdict.location === undefined ? {} : { location: verdict.location }),\n ...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),\n },\n };\n }\n const limited = exceeded(input.providerLimits, changes, resulting);\n if (limited !== null) return limited;\n return {\n kind: 'batch',\n batch: immutable({\n id: crypto.randomUUID(),\n baseRoomVersion: input.baseRoomVersion,\n changes,\n preconditions,\n }),\n };\n}\n"],"names":["apply","links","serialize","validate","immutable","parseCollection","overlay","beneath","covered","normalize","relative","resolve","refuse","rule","file","location","kind","refusal","undefined","members","visible","prefix","Object","keys","documents","binaryTargets","filter","path","sort","spread","change","member","to","slice","length","expand","changes","expanded","push","structural","present","includes","beneathIt","referenceField","spec","declared","of","definitionOf","types","type","find","name","retarget","value","from","moves","Array","isArray","next","map","item","some","index","target","get","edited","document","applied","prior","preamble","sections","outcome","bodies","before","after","entries","relinks","moved","link","destination","href","content","subsumed","merged","splice","rewrites","Map","settled","Set","set","add","size","added","collection","has","definition","fields","relinked","findIndex","targets","values","resolved","incoming","removed","found","note","referrers","first","every","affected","guard","input","existing","normalized","providerOwnedPaths","writeGrants","delete","revisions","existence","revision","preconditionsOf","preconditions","seen","precondition","part","identity","depth","split","exceeded","limits","resulting","written","created","limit","large","long","deep","buildBatch","rewritten","id","baseRoomVersion","referenced","verdict","limited","providerLimits","batch","crypto","randomUUID"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,EAAEC,SAAS,EAAEC,QAAQ,QAAuB,uBAAuB;AAExF,SAASC,SAAS,QAA0D,cAAc;AAC1F,SAASC,eAAe,QAAsC,kBAAkB;AACh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,QAAQ;gBAAC,CAAC;gBACxE,GAAI+H,QAAQpC,SAAS,KAAKxF,YAAY,CAAC,IAAI;oBAAEwF,WAAWoC,QAAQpC,SAAS;gBAAC,CAAC;YAC7E;QACF;IACF;IACA,MAAMqC,UAAUf,SAASjB,MAAMiC,cAAc,EAAE5G,SAAS8F;IACxD,IAAIa,YAAY,MAAM,OAAOA;IAC7B,OAAO;QACL/H,MAAM;QACNiI,OAAO7I,UAAU;YACfuI,IAAIO,OAAOC,UAAU;YACrBP,iBAAiB7B,MAAM6B,eAAe;YACtCxG;YACAqF;QACF;IACF;AACF"}
@@ -0,0 +1,15 @@
1
+ export type SyncStatus = {
2
+ state: 'pending' | 'syncing' | 'synced';
3
+ lastCompleted: string | null;
4
+ providerUnreachable: boolean;
5
+ };
6
+ export type CycleProgress = {
7
+ complete: boolean;
8
+ reachable: boolean;
9
+ };
10
+ export declare const STARTING: SyncStatus;
11
+ export declare function transferring(status: SyncStatus): SyncStatus;
12
+ export declare function settled(status: SyncStatus, progress: CycleProgress, at: string, queued: boolean): SyncStatus;
13
+ export declare function saving(status: SyncStatus): SyncStatus;
14
+ export declare function same(one: SyncStatus, other: SyncStatus): boolean;
15
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,UAItB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D;AAED,wBAAgB,OAAO,CACrB,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,aAAa,EACvB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,OAAO,GACd,UAAU,CAMZ;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAErD;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAMhE"}
package/dist/status.js ADDED
@@ -0,0 +1,29 @@
1
+ export const STARTING = {
2
+ state: 'syncing',
3
+ lastCompleted: null,
4
+ providerUnreachable: false
5
+ };
6
+ export function transferring(status) {
7
+ return {
8
+ ...status,
9
+ state: 'syncing'
10
+ };
11
+ }
12
+ export function settled(status, progress, at, queued) {
13
+ return {
14
+ state: queued ? 'pending' : progress.complete ? 'synced' : status.state,
15
+ lastCompleted: progress.complete ? at : status.lastCompleted,
16
+ providerUnreachable: !progress.reachable
17
+ };
18
+ }
19
+ export function saving(status) {
20
+ return {
21
+ ...status,
22
+ state: 'pending'
23
+ };
24
+ }
25
+ export function same(one, other) {
26
+ return one.state === other.state && one.lastCompleted === other.lastCompleted && one.providerUnreachable === other.providerUnreachable;
27
+ }
28
+
29
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/status.ts"],"sourcesContent":["export type SyncStatus = {\n state: 'pending' | 'syncing' | 'synced';\n lastCompleted: string | null;\n providerUnreachable: boolean;\n};\n\nexport type CycleProgress = {\n complete: boolean;\n reachable: boolean;\n};\n\nexport const STARTING: SyncStatus = {\n state: 'syncing',\n lastCompleted: null,\n providerUnreachable: false,\n};\n\nexport function transferring(status: SyncStatus): SyncStatus {\n return { ...status, state: 'syncing' };\n}\n\nexport function settled(\n status: SyncStatus,\n progress: CycleProgress,\n at: string,\n queued: boolean,\n): SyncStatus {\n return {\n state: queued ? 'pending' : progress.complete ? 'synced' : status.state,\n lastCompleted: progress.complete ? at : status.lastCompleted,\n providerUnreachable: !progress.reachable,\n };\n}\n\nexport function saving(status: SyncStatus): SyncStatus {\n return { ...status, state: 'pending' };\n}\n\nexport function same(one: SyncStatus, other: SyncStatus): boolean {\n return (\n one.state === other.state &&\n one.lastCompleted === other.lastCompleted &&\n one.providerUnreachable === other.providerUnreachable\n );\n}\n"],"names":["STARTING","state","lastCompleted","providerUnreachable","transferring","status","settled","progress","at","queued","complete","reachable","saving","same","one","other"],"mappings":"AAWA,OAAO,MAAMA,WAAuB;IAClCC,OAAO;IACPC,eAAe;IACfC,qBAAqB;AACvB,EAAE;AAEF,OAAO,SAASC,aAAaC,MAAkB;IAC7C,OAAO;QAAE,GAAGA,MAAM;QAAEJ,OAAO;IAAU;AACvC;AAEA,OAAO,SAASK,QACdD,MAAkB,EAClBE,QAAuB,EACvBC,EAAU,EACVC,MAAe;IAEf,OAAO;QACLR,OAAOQ,SAAS,YAAYF,SAASG,QAAQ,GAAG,WAAWL,OAAOJ,KAAK;QACvEC,eAAeK,SAASG,QAAQ,GAAGF,KAAKH,OAAOH,aAAa;QAC5DC,qBAAqB,CAACI,SAASI,SAAS;IAC1C;AACF;AAEA,OAAO,SAASC,OAAOP,MAAkB;IACvC,OAAO;QAAE,GAAGA,MAAM;QAAEJ,OAAO;IAAU;AACvC;AAEA,OAAO,SAASY,KAAKC,GAAe,EAAEC,KAAiB;IACrD,OACED,IAAIb,KAAK,KAAKc,MAAMd,KAAK,IACzBa,IAAIZ,aAAa,KAAKa,MAAMb,aAAa,IACzCY,IAAIX,mBAAmB,KAAKY,MAAMZ,mBAAmB;AAEzD"}
package/dist/store.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { ProviderLimit } from './adapter.js';
2
+ import type { ChangeBatch } from './change.js';
1
3
  export type ReplicaRecord = {
2
4
  locator: string;
3
5
  name: string;
@@ -6,10 +8,29 @@ export type ReplicaRecord = {
6
8
  roomVersion: string;
7
9
  documents: Readonly<Record<string, string>>;
8
10
  binaryTargets: readonly string[];
11
+ revisions: Readonly<Record<string, string>>;
12
+ };
13
+ export type QueueRecord = {
14
+ locator: string;
15
+ batches: readonly ChangeBatch[];
16
+ };
17
+ export type DraftRecord = {
18
+ locator: string;
19
+ path: string;
20
+ content: unknown;
9
21
  };
10
22
  export type ReplicaStore = {
11
23
  all(): Promise<readonly ReplicaRecord[]>;
12
24
  publish(record: ReplicaRecord): Promise<void>;
25
+ lastCompleted(): Promise<string | null>;
26
+ complete(at: string): Promise<void>;
27
+ providerLimits(): Promise<readonly ProviderLimit[]>;
28
+ declare(limits: readonly ProviderLimit[]): Promise<void>;
29
+ queues(): Promise<readonly QueueRecord[]>;
30
+ drafts(): Promise<readonly DraftRecord[]>;
31
+ keep(draft: DraftRecord): Promise<void>;
32
+ discard(locator: string, path: string): Promise<void>;
33
+ append(queue: QueueRecord, consumed: readonly string[]): Promise<void>;
13
34
  close(): void;
14
35
  };
15
36
  export declare function openReplicaStore(): Promise<ReplicaStore>;
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,IAAI,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;IACzC,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAi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