@agentshouse/mdruntime 0.1.0-ca7c26c6bc27e → 0.1.0-cacb4c3f6734e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +53 -24
- package/README.md +10 -10
- package/dist/adapter.d.ts +24 -6
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +1 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -10
- package/dist/connection.d.ts +7 -6
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +25 -46
- package/dist/conversation.d.ts +17 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +167 -78
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +3 -11
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/memory.d.ts +2 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +13 -7
- package/dist/model.d.ts +3 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +4 -3
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +100 -33
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +9 -16
- package/dist/react.d.ts +32 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +62 -0
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +102 -46
- package/dist/replica.d.ts +2 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -10
- package/dist/rows.d.ts +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +75 -38
- package/dist/save.d.ts +1 -2
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +90 -48
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/wire.d.ts +1 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +1 -15
- package/package.json +14 -2
package/dist/react.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
export function useObserve(client, topic, ...input) {
|
|
3
|
+
const key = JSON.stringify([topic, ...input]);
|
|
4
|
+
const [held, setHeld] = useState(null);
|
|
5
|
+
const opened = useRef(input);
|
|
6
|
+
opened.current = input;
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (client === null)
|
|
9
|
+
return;
|
|
10
|
+
let live = true;
|
|
11
|
+
let observation = null;
|
|
12
|
+
const observe = client.observe;
|
|
13
|
+
void observe(topic, ...opened.current).then((open) => {
|
|
14
|
+
if (!live) {
|
|
15
|
+
open.close();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
observation = open;
|
|
19
|
+
const take = (value) => {
|
|
20
|
+
if (live)
|
|
21
|
+
setHeld({ client, key, value });
|
|
22
|
+
};
|
|
23
|
+
take(open.current());
|
|
24
|
+
open.subscribe(take);
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
live = false;
|
|
28
|
+
observation?.close();
|
|
29
|
+
};
|
|
30
|
+
}, [client, key]);
|
|
31
|
+
return held !== null && held.client === client && held.key === key ? held.value : undefined;
|
|
32
|
+
}
|
|
33
|
+
const IDLE = { busy: false, outcome: null, failure: null };
|
|
34
|
+
export async function saveRoomDrafts(client, room, roomDrafts) {
|
|
35
|
+
const kept = [];
|
|
36
|
+
for (const [path, parts] of roomDrafts) {
|
|
37
|
+
const prior = await client.roomDraft.read(room, path);
|
|
38
|
+
const write = await client.roomDraft.write(room, path, prior?.revision ?? null, parts);
|
|
39
|
+
if (write.outcome !== 'written' || write.roomDraft === null) {
|
|
40
|
+
throw new Error(`the Room Draft at ${path} was not written`);
|
|
41
|
+
}
|
|
42
|
+
kept.push({ path, revision: write.roomDraft.revision });
|
|
43
|
+
}
|
|
44
|
+
return client.save(room, kept);
|
|
45
|
+
}
|
|
46
|
+
export function useSave(client) {
|
|
47
|
+
const [state, setState] = useState(IDLE);
|
|
48
|
+
const save = useCallback(async (room, roomDrafts) => {
|
|
49
|
+
setState({ busy: true, outcome: null, failure: null });
|
|
50
|
+
try {
|
|
51
|
+
const outcome = await saveRoomDrafts(client, room, roomDrafts);
|
|
52
|
+
setState({ busy: false, outcome, failure: null });
|
|
53
|
+
return outcome;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
57
|
+
setState({ busy: false, outcome: null, failure });
|
|
58
|
+
throw failure;
|
|
59
|
+
}
|
|
60
|
+
}, [client]);
|
|
61
|
+
return { ...state, save };
|
|
62
|
+
}
|
package/dist/read-side.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC3F,OAAO,KAAK,EAOV,IAAI,EAIJ,WAAW,EAIZ,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAuDpD,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CACH,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,KAAK,IAAI,GACpD,MAAM,IAAI,CAAC;IACd,SAAS,IAAI,SAAS,gBAAgB,EAAE,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC9D,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AA+UF,wBAAgB,UAAU,CACxB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,WAAW,GAChB;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,CA4BpD;AAED,wBAAgB,cAAc,IAAI,QAAQ,CA4HzC"}
|
package/dist/read-side.js
CHANGED
|
@@ -1,54 +1,58 @@
|
|
|
1
|
-
import { and, BasicIndex, configureIndexDevMode, count, createCollection, createLiveQueryCollection, deepEquals, eq,
|
|
1
|
+
import { and, BasicIndex, configureIndexDevMode, count, createCollection, createLiveQueryCollection, deepEquals, eq, inArray, or, toArray, } from '@tanstack/db';
|
|
2
|
+
import { ARRAY_INDEX, pointerSegments } from '@agentshouse/mdmodel';
|
|
2
3
|
import { rowsOf } from './observation.js';
|
|
3
4
|
import { documentKey } from './rows.js';
|
|
4
5
|
function every(expressions) {
|
|
5
6
|
const [first, second, ...rest] = expressions;
|
|
6
7
|
return second === undefined ? first : and(first, second, ...rest);
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
return second === undefined ? first : or(first, second, ...rest);
|
|
9
|
+
function same(held, value) {
|
|
10
|
+
return Array.isArray(held) ? held.includes(value) : held === value;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function ordered(held, [operator, bound]) {
|
|
13
|
+
if (typeof held !== typeof bound || held === null || typeof held === 'object')
|
|
14
|
+
return false;
|
|
15
|
+
const left = held;
|
|
16
|
+
const right = bound;
|
|
17
|
+
if (operator === 'gt')
|
|
18
|
+
return left > right;
|
|
19
|
+
if (operator === 'gte')
|
|
20
|
+
return left >= right;
|
|
21
|
+
if (operator === 'lt')
|
|
22
|
+
return left < right;
|
|
23
|
+
return left <= right;
|
|
14
24
|
}
|
|
15
|
-
function
|
|
25
|
+
function satisfied(test, held) {
|
|
16
26
|
if (test.op === 'eq')
|
|
17
|
-
return
|
|
18
|
-
if (test.op === 'ne')
|
|
19
|
-
return test.value
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const compare = { gt, gte, lt, lte };
|
|
37
|
-
return every(test.bounds.map(([operator, bound]) => compare[operator](field, bound)));
|
|
38
|
-
}
|
|
39
|
-
if (test.op === 'all') {
|
|
40
|
-
return every([not(isUndefined(size)), ...test.values.map((value) => inArray(value, field))]);
|
|
41
|
-
}
|
|
42
|
-
if (test.op === 'size')
|
|
43
|
-
return eq(size, test.size);
|
|
44
|
-
return test.exists ? not(isUndefined(written)) : isUndefined(written);
|
|
27
|
+
return same(held, test.value);
|
|
28
|
+
if (test.op === 'ne')
|
|
29
|
+
return !same(held, test.value);
|
|
30
|
+
if (test.op === 'in')
|
|
31
|
+
return test.values.some((value) => same(held, value));
|
|
32
|
+
if (test.op === 'nin')
|
|
33
|
+
return !test.values.some((value) => same(held, value));
|
|
34
|
+
if (test.op === 'range')
|
|
35
|
+
return test.bounds.every((bound) => ordered(held, bound));
|
|
36
|
+
if (test.op === 'all')
|
|
37
|
+
return Array.isArray(held) && test.values.every((value) => same(held, value));
|
|
38
|
+
return Array.isArray(held) && held.length === test.size;
|
|
39
|
+
}
|
|
40
|
+
function tested(test, reached) {
|
|
41
|
+
if (test.op === 'exists')
|
|
42
|
+
return test.exists === (reached !== undefined);
|
|
43
|
+
if (reached === undefined)
|
|
44
|
+
return test.op === 'ne' || test.op === 'nin';
|
|
45
|
+
return reached.some((held) => satisfied(test, held));
|
|
45
46
|
}
|
|
46
47
|
function conditioned(condition, row) {
|
|
47
48
|
if ('every' in condition)
|
|
48
|
-
return
|
|
49
|
+
return condition.every.every((item) => conditioned(item, row));
|
|
49
50
|
if ('some' in condition)
|
|
50
|
-
return
|
|
51
|
-
return tested(condition.test, row.
|
|
51
|
+
return condition.some.some((item) => conditioned(item, row));
|
|
52
|
+
return tested(condition.test, row.reached[condition.field]);
|
|
53
|
+
}
|
|
54
|
+
function narrowed(query, where, alias) {
|
|
55
|
+
return where === null ? query : query.fn.where((row) => conditioned(where, row[alias]));
|
|
52
56
|
}
|
|
53
57
|
function reached(reach, room, document) {
|
|
54
58
|
return reach === null
|
|
@@ -62,7 +66,6 @@ function scoped(scope, row, rooms, reach) {
|
|
|
62
66
|
...reached(reach, row.room, row.key),
|
|
63
67
|
...(scope.types === null ? [] : [inArray(row.type, [...scope.types])]),
|
|
64
68
|
...(scope.pathPrefix === null ? [] : [inArray(scope.pathPrefix, row.directories)]),
|
|
65
|
-
...(scope.where === null ? [] : [conditioned(scope.where, row)]),
|
|
66
69
|
]);
|
|
67
70
|
}
|
|
68
71
|
function keyed(key, row) {
|
|
@@ -77,16 +80,17 @@ function live(query) {
|
|
|
77
80
|
function related(q, rows, scope, field, kept, reach) {
|
|
78
81
|
const matched = kept === 'source' ? 'target' : 'source';
|
|
79
82
|
const from = q.from({ r: rows });
|
|
80
|
-
|
|
81
|
-
.where(({ r }) => every([eq(r.kind, 'reference'), ...(field === null ? [] : [
|
|
83
|
+
const joined = from
|
|
84
|
+
.where(({ r }) => every([eq(r.kind, 'reference'), ...(field === null ? [] : [inArray(field, r.forms)])]))
|
|
82
85
|
.innerJoin({ m: rows }, ({ r, m }) => eq(r[matched], m.key))
|
|
83
|
-
.where(({ m }) => scoped(scope, m, null, reach))
|
|
86
|
+
.where(({ m }) => scoped(scope, m, null, reach));
|
|
87
|
+
return narrowed(joined, scope.where, 'm')
|
|
84
88
|
.groupBy(({ r }) => r[kept])
|
|
85
89
|
.select(({ r }) => ({ key: r[kept] }));
|
|
86
90
|
}
|
|
87
91
|
function filtered(q, rows, plan) {
|
|
88
92
|
const from = q.from({ d: rows });
|
|
89
|
-
let query = from.where(({ d }) => scoped(plan.root, d, plan.rooms, plan.reach));
|
|
93
|
+
let query = narrowed(from.where(({ d }) => scoped(plan.root, d, plan.rooms, plan.reach)), plan.root.where, 'd');
|
|
90
94
|
if (plan.hop !== null) {
|
|
91
95
|
const hop = related(q, rows, plan.hop, plan.hop.field, 'source', plan.reach);
|
|
92
96
|
query = query.innerJoin({ h: hop }, ({ d, h }) => eq(d.key, h.key));
|
|
@@ -117,8 +121,7 @@ function documents(q, rows, plan, shape) {
|
|
|
117
121
|
room: d.room,
|
|
118
122
|
path: d.path,
|
|
119
123
|
type: d.type,
|
|
120
|
-
...(shape.fields ===
|
|
121
|
-
...(Array.isArray(shape.fields) ? named('field', shape.fields, d.fields) : {}),
|
|
124
|
+
...(shape.fields === null ? {} : { fields: d.fields }),
|
|
122
125
|
...(shape.sections === 'all' ? { sections: b.sections } : {}),
|
|
123
126
|
...(Array.isArray(shape.sections) ? named('section', shape.sections, b.sections) : {}),
|
|
124
127
|
...(shape.preamble ? { preamble: b.preamble } : {}),
|
|
@@ -176,6 +179,55 @@ function part(row, prefix, names, whole) {
|
|
|
176
179
|
return whole;
|
|
177
180
|
return present(names.map((name, index) => [name, row[`${prefix}${index}`]]));
|
|
178
181
|
}
|
|
182
|
+
function masked(pointers) {
|
|
183
|
+
const root = { whole: false, members: new Map() };
|
|
184
|
+
for (const pointer of pointers) {
|
|
185
|
+
let mask = root;
|
|
186
|
+
for (const token of pointerSegments(pointer)) {
|
|
187
|
+
const next = mask.members.get(token) ?? { whole: false, members: new Map() };
|
|
188
|
+
mask.members.set(token, next);
|
|
189
|
+
mask = next;
|
|
190
|
+
}
|
|
191
|
+
mask.whole = true;
|
|
192
|
+
}
|
|
193
|
+
return root;
|
|
194
|
+
}
|
|
195
|
+
function merged(left, right) {
|
|
196
|
+
if (left === undefined)
|
|
197
|
+
return right;
|
|
198
|
+
const members = new Map(left.members);
|
|
199
|
+
for (const [token, mask] of right.members)
|
|
200
|
+
members.set(token, merged(members.get(token), mask));
|
|
201
|
+
return { whole: left.whole || right.whole, members };
|
|
202
|
+
}
|
|
203
|
+
function cut(value, mask) {
|
|
204
|
+
if (mask.whole)
|
|
205
|
+
return value;
|
|
206
|
+
if (Array.isArray(value)) {
|
|
207
|
+
const each = {
|
|
208
|
+
whole: false,
|
|
209
|
+
members: new Map([...mask.members].filter(([token]) => !ARRAY_INDEX.test(token))),
|
|
210
|
+
};
|
|
211
|
+
const kept = [];
|
|
212
|
+
value.forEach((item, index) => {
|
|
213
|
+
const part = cut(item, merged(mask.members.get(String(index)), each));
|
|
214
|
+
if (part !== undefined)
|
|
215
|
+
kept[index] = part;
|
|
216
|
+
});
|
|
217
|
+
return kept.length === 0 ? undefined : kept;
|
|
218
|
+
}
|
|
219
|
+
if (typeof value !== 'object' || value === null)
|
|
220
|
+
return undefined;
|
|
221
|
+
const kept = Object.entries(value).flatMap(([key, held]) => {
|
|
222
|
+
const member = mask.members.get(key);
|
|
223
|
+
const part = member === undefined ? undefined : cut(held, member);
|
|
224
|
+
return part === undefined ? [] : [[key, part]];
|
|
225
|
+
});
|
|
226
|
+
return kept.length === 0 ? undefined : Object.fromEntries(kept);
|
|
227
|
+
}
|
|
228
|
+
function selected(fields, pointers) {
|
|
229
|
+
return (cut(fields, masked(pointers)) ?? {});
|
|
230
|
+
}
|
|
179
231
|
function documentOf(row, shape) {
|
|
180
232
|
if (row.type === null)
|
|
181
233
|
return { room: row.room, path: row.path };
|
|
@@ -185,7 +237,11 @@ function documentOf(row, shape) {
|
|
|
185
237
|
type: row.type,
|
|
186
238
|
...(shape.fields === null
|
|
187
239
|
? {}
|
|
188
|
-
: {
|
|
240
|
+
: {
|
|
241
|
+
fields: shape.fields === 'all'
|
|
242
|
+
? row.fields
|
|
243
|
+
: selected(row.fields, shape.fields),
|
|
244
|
+
}),
|
|
189
245
|
...(shape.sections === null
|
|
190
246
|
? {}
|
|
191
247
|
: {
|
package/dist/replica.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type ChangeBatch } from './change.js';
|
|
2
2
|
import { type Collection, type Composition } from './collection.js';
|
|
3
3
|
import { type Layer } from './overlay.js';
|
|
4
|
-
import { type Rewriting } from './save.js';
|
|
5
4
|
import type { RoomAttachment } from './adapter.js';
|
|
6
5
|
import type { ReplicaRecord } from './store.js';
|
|
7
6
|
import type { Refused } from './transfer.js';
|
|
@@ -37,8 +36,8 @@ export declare function readReclassified(record: ReplicaRecord, previous: Confir
|
|
|
37
36
|
kind: 'deferred';
|
|
38
37
|
};
|
|
39
38
|
export declare function applyReturned(confirmed: ConfirmedLayer, documents: Readonly<Record<string, string>>, revisions: Readonly<Record<string, string>>, removals: readonly string[], attachments: readonly RoomAttachment[] | undefined, roomVersion: string, writtenAt: string): Staged;
|
|
40
|
-
export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[],
|
|
39
|
+
export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], previous?: Replica): Replica;
|
|
41
40
|
export declare function landed(batch: ChangeBatch, confirmed: ConfirmedLayer): boolean;
|
|
42
|
-
export declare function withdrawals(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean
|
|
41
|
+
export declare function withdrawals(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean): readonly ChangeBatch[];
|
|
43
42
|
export {};
|
|
44
43
|
//# sourceMappingURL=replica.d.ts.map
|
package/dist/replica.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,KAAK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WAAW,EAAE,CAmBxB"}
|
package/dist/replica.js
CHANGED
|
@@ -120,7 +120,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
120
120
|
}
|
|
121
121
|
return { layer, replay };
|
|
122
122
|
}
|
|
123
|
-
export function replicaOf(confirmed, queue,
|
|
123
|
+
export function replicaOf(confirmed, queue, previous) {
|
|
124
124
|
const batches = Object.freeze(queue.map(immutable));
|
|
125
125
|
if (batches.length === 0) {
|
|
126
126
|
return {
|
|
@@ -136,16 +136,11 @@ export function replicaOf(confirmed, queue, rewriting, previous) {
|
|
|
136
136
|
replay: [],
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
const
|
|
140
|
-
const layer = rewriting === 'provider'
|
|
141
|
-
? predictedState.layer
|
|
142
|
-
: previous === undefined
|
|
143
|
-
? overlay(confirmed.record, batches)
|
|
144
|
-
: overlayChanged(confirmed.record, batches, previous.confirmed.record, previous.queue, previous.visible);
|
|
139
|
+
const { layer, replay } = predicted(confirmed, batches, previous);
|
|
145
140
|
return {
|
|
146
141
|
confirmed,
|
|
147
142
|
queue: batches,
|
|
148
|
-
replay
|
|
143
|
+
replay,
|
|
149
144
|
visible: {
|
|
150
145
|
...layer,
|
|
151
146
|
collection: parseCollection(layer.documents, compositionOf(confirmed.record), previous === undefined
|
|
@@ -249,7 +244,7 @@ export function landed(batch, confirmed) {
|
|
|
249
244
|
});
|
|
250
245
|
});
|
|
251
246
|
}
|
|
252
|
-
export function withdrawals(confirmed, queue, withdrawable
|
|
247
|
+
export function withdrawals(confirmed, queue, withdrawable) {
|
|
253
248
|
if (!queue.some(withdrawable))
|
|
254
249
|
return [];
|
|
255
250
|
const composition = compositionOf(confirmed.record);
|
|
@@ -260,7 +255,7 @@ export function withdrawals(confirmed, queue, withdrawable, rewriting) {
|
|
|
260
255
|
withdrawn.push(batch);
|
|
261
256
|
continue;
|
|
262
257
|
}
|
|
263
|
-
const effective =
|
|
258
|
+
const effective = batch.changes.some((change) => change.kind === 'move')
|
|
264
259
|
? providerRewritten(batch, {
|
|
265
260
|
...layer,
|
|
266
261
|
collection: parseCollection(layer.documents, composition),
|
package/dist/rows.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type DocumentRow = {
|
|
|
10
10
|
type: string | null;
|
|
11
11
|
fields: Fields;
|
|
12
12
|
values: Fields;
|
|
13
|
-
|
|
13
|
+
reached: Readonly<Record<string, readonly unknown[]>>;
|
|
14
14
|
directories: readonly string[];
|
|
15
15
|
body: string;
|
|
16
16
|
change: HeadChange | null;
|
|
@@ -31,6 +31,7 @@ export type ReferenceRow = {
|
|
|
31
31
|
source: string;
|
|
32
32
|
target: string;
|
|
33
33
|
field: string;
|
|
34
|
+
forms: readonly string[];
|
|
34
35
|
path: string;
|
|
35
36
|
type: string;
|
|
36
37
|
};
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,C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target } from '@agentshouse/mdmodel';
|
|
1
|
+
import { ARRAY_INDEX, escapePointer, references, target, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { governing } from './collection.js';
|
|
3
3
|
import { definitionOf } from './model.js';
|
|
4
4
|
function keyOf(...parts) {
|
|
@@ -7,18 +7,59 @@ function keyOf(...parts) {
|
|
|
7
7
|
export function documentKey(room, path) {
|
|
8
8
|
return keyOf('d', room, path);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
function plainObject(value) {
|
|
11
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
13
|
+
function compared(reading, exact, value) {
|
|
14
|
+
if (!reading.references.has(exact))
|
|
15
|
+
return value;
|
|
16
|
+
return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
|
|
15
17
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
function record(reading, node, forms, exact) {
|
|
19
|
+
const value = Array.isArray(node)
|
|
20
|
+
? node.map((item, index) => compared(reading, `${exact}/${index}`, item))
|
|
21
|
+
: compared(reading, exact, node);
|
|
22
|
+
for (const form of forms) {
|
|
23
|
+
if (form.pending)
|
|
24
|
+
continue;
|
|
25
|
+
(reading.reached[form.text] ??= []).push(value);
|
|
26
|
+
if (!form.through && value !== undefined && !plainObject(value)) {
|
|
27
|
+
reading.values[form.text] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(node) || plainObject(node) || !reading.references.has(exact))
|
|
31
|
+
return;
|
|
32
|
+
const found = compared(reading, exact, node);
|
|
33
|
+
if (typeof found !== 'string')
|
|
34
|
+
return;
|
|
35
|
+
const field = forms
|
|
36
|
+
.map((form) => form.text)
|
|
37
|
+
.reduce((left, right) => (right.length < left.length ? right : left));
|
|
38
|
+
const known = reading.targets.get(`${field}\u0000${found}`);
|
|
39
|
+
const kept = known ?? { field, target: found, forms: new Set() };
|
|
40
|
+
for (const form of forms)
|
|
41
|
+
kept.forms.add(form.text);
|
|
42
|
+
reading.targets.set(`${field}\u0000${found}`, kept);
|
|
43
|
+
}
|
|
44
|
+
function walk(reading, node, forms, exact) {
|
|
45
|
+
record(reading, node, forms, exact);
|
|
46
|
+
if (Array.isArray(node)) {
|
|
47
|
+
node.forEach((item, index) => walk(reading, item, forms.flatMap((form) => [
|
|
48
|
+
...(form.pending
|
|
49
|
+
? []
|
|
50
|
+
: [{ text: `${form.text}/${index}`, through: form.through, pending: false }]),
|
|
51
|
+
{ text: form.text, through: true, pending: true },
|
|
52
|
+
]), `${exact}/${index}`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!plainObject(node))
|
|
56
|
+
return;
|
|
57
|
+
for (const [key, value] of Object.entries(node)) {
|
|
58
|
+
const segment = escapePointer(key);
|
|
59
|
+
walk(reading, value, forms.flatMap((form) => form.pending && ARRAY_INDEX.test(key)
|
|
60
|
+
? []
|
|
61
|
+
: [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
|
|
62
|
+
}
|
|
22
63
|
}
|
|
23
64
|
function directoriesOf(path) {
|
|
24
65
|
const parts = path.split('/').slice(0, -1);
|
|
@@ -37,7 +78,7 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
37
78
|
type: null,
|
|
38
79
|
fields: {},
|
|
39
80
|
values: {},
|
|
40
|
-
|
|
81
|
+
reached: {},
|
|
41
82
|
directories: directoriesOf(path),
|
|
42
83
|
body,
|
|
43
84
|
change,
|
|
@@ -46,32 +87,18 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
46
87
|
}
|
|
47
88
|
const type = document.type ?? 'any';
|
|
48
89
|
const definition = definitionOf(governing(composition, path), document.type);
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
90
|
+
const reading = {
|
|
91
|
+
path,
|
|
92
|
+
references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
|
|
93
|
+
values: {},
|
|
94
|
+
reached: {},
|
|
95
|
+
targets: new Map(),
|
|
96
|
+
};
|
|
52
97
|
for (const [name, value] of Object.entries(document.fields)) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
if (compared !== undefined)
|
|
56
|
-
values[name] = compared;
|
|
57
|
-
if (Array.isArray(value))
|
|
58
|
-
sizes[name] = value.length;
|
|
59
|
-
if (!reference)
|
|
60
|
-
continue;
|
|
61
|
-
const targets = [compared].flat().filter((found) => typeof found === 'string');
|
|
62
|
-
for (const found of new Set(targets)) {
|
|
63
|
-
references.push({
|
|
64
|
-
key: keyOf('r', room, path, name, found),
|
|
65
|
-
kind: 'reference',
|
|
66
|
-
room,
|
|
67
|
-
source: key,
|
|
68
|
-
target: documentKey(room, found),
|
|
69
|
-
field: name,
|
|
70
|
-
path,
|
|
71
|
-
type,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
98
|
+
const segment = escapePointer(name);
|
|
99
|
+
walk(reading, value, [{ text: `/${segment}`, through: false, pending: false }], `/${segment}`);
|
|
74
100
|
}
|
|
101
|
+
const { values, reached } = reading;
|
|
75
102
|
return [
|
|
76
103
|
{
|
|
77
104
|
key,
|
|
@@ -81,7 +108,7 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
81
108
|
type,
|
|
82
109
|
fields: document.fields,
|
|
83
110
|
values,
|
|
84
|
-
|
|
111
|
+
reached,
|
|
85
112
|
directories: directoriesOf(path),
|
|
86
113
|
body,
|
|
87
114
|
change,
|
|
@@ -95,6 +122,16 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
95
122
|
sections: document.sections,
|
|
96
123
|
markdown: document.content,
|
|
97
124
|
},
|
|
98
|
-
...
|
|
125
|
+
...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
|
|
126
|
+
key: keyOf('r', room, path, field, found),
|
|
127
|
+
kind: 'reference',
|
|
128
|
+
room,
|
|
129
|
+
source: key,
|
|
130
|
+
target: documentKey(room, found),
|
|
131
|
+
field,
|
|
132
|
+
forms: [...forms].sort(),
|
|
133
|
+
path,
|
|
134
|
+
type,
|
|
135
|
+
})),
|
|
99
136
|
];
|
|
100
137
|
}
|
package/dist/save.d.ts
CHANGED
|
@@ -10,15 +10,14 @@ export type SaveRefusal = {
|
|
|
10
10
|
referrers?: readonly string[];
|
|
11
11
|
parts?: readonly ChangedPart[];
|
|
12
12
|
};
|
|
13
|
-
export type Rewriting = 'runtime' | 'provider';
|
|
14
13
|
export type SaveInput = {
|
|
15
14
|
composition: Composition;
|
|
16
|
-
rewriting: Rewriting;
|
|
17
15
|
baseRoomVersion: string;
|
|
18
16
|
operations: import('./adapter.js').OperationScopes;
|
|
19
17
|
providerOwnedPaths: readonly string[];
|
|
20
18
|
providerLimits: readonly ProviderLimit[];
|
|
21
19
|
visible: VisibleLayer;
|
|
20
|
+
handle: string;
|
|
22
21
|
changes: readonly Change[];
|
|
23
22
|
bases: readonly Precondition[];
|
|
24
23
|
writtenBy?: WrittenBy;
|
package/dist/save.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC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