@agentshouse/mdruntime 0.1.0-cf28918c2bf91 → 0.1.0-cfbf80d8d4644
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 +33 -8
- package/README.md +10 -10
- package/dist/adapter.d.ts +51 -25
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +34 -0
- package/dist/bootstrap.d.ts +5 -3
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +3 -2
- 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 +10 -12
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +501 -512
- package/dist/conversation.d.ts +18 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +179 -78
- package/dist/host.d.ts +7 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +34 -31
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/memory.d.ts +11 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +78 -26
- package/dist/model.d.ts +4 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +4 -3
- package/dist/observation.d.ts +2 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +24 -14
- 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 +7 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +29 -20
- package/dist/reach.d.ts +40 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +270 -0
- package/dist/react.d.ts +31 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +62 -0
- package/dist/read-side.d.ts +4 -0
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +16 -10
- package/dist/refresh.d.ts +2 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +7 -3
- package/dist/replica.d.ts +4 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +12 -13
- package/dist/room-draft.d.ts +3 -0
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +6 -4
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +1 -4
- package/dist/save.d.ts +1 -2
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +90 -46
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/wire.d.ts +51 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +50 -59
- package/package.json +14 -2
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAItB,KAAK,cAAc,EACnB,KAAK,UAAU,EAGf,KAAK,kBAAkB,EAGvB,KAAK,aAAa,EAGlB,KAAK,SAAS,EACd,KAAK,cAAc,EAGnB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAkBtB,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG;IACxC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EA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AAG,IAAI,CAAC;IACxD,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC1C,iBAAiB,CAAC,YAAY,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChF,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnD,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,SAAS,IAAI,SAAS,MAAM,EAAE,CAAC;IAC/B,uBAAuB,IAAI,SAAS,MAAM,EAAE,CAAC;CAC9C,CAAC;AA+CF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAmbrF"}
|
package/dist/memory.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ROOM_CONTRACT_VERSION, } from './adapter.js';
|
|
2
|
-
import { MD_MODEL } from './collection.js';
|
|
3
1
|
import { sameChange } from './overlay.js';
|
|
4
2
|
const FIXTURE_RETENTION = {
|
|
5
3
|
history: { kind: 'duration', seconds: 1 },
|
|
@@ -15,6 +13,19 @@ function declaredRetention(value) {
|
|
|
15
13
|
}
|
|
16
14
|
throw new Error('history retention duration must be a finite positive number of seconds');
|
|
17
15
|
}
|
|
16
|
+
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
|
+
function modelsOf(room) {
|
|
18
|
+
return {
|
|
19
|
+
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
+
...(room.typedSelection === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function changedModels(room, from) {
|
|
26
|
+
const now = modelsOf(room);
|
|
27
|
+
return JSON.stringify(now) === JSON.stringify(modelsOf(from)) ? undefined : now;
|
|
28
|
+
}
|
|
18
29
|
function named(source, paths) {
|
|
19
30
|
const taken = {};
|
|
20
31
|
for (const path of paths) {
|
|
@@ -31,8 +42,6 @@ async function resolveScript(answer, fallback, request) {
|
|
|
31
42
|
}
|
|
32
43
|
export function createMemoryAdapter(options = {}) {
|
|
33
44
|
let rooms = options.rooms === undefined ? [] : [...options.rooms];
|
|
34
|
-
const mdModel = options.mdModel ?? MD_MODEL;
|
|
35
|
-
const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];
|
|
36
45
|
const capabilities = options.capabilities ?? [];
|
|
37
46
|
const providerLimits = options.providerLimits ?? [];
|
|
38
47
|
const retention = declaredRetention(options.retention);
|
|
@@ -47,7 +56,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
47
56
|
const unsealed = new Map();
|
|
48
57
|
const sealed = new Set();
|
|
49
58
|
const historyPageSize = options.historyPageSize;
|
|
50
|
-
let
|
|
59
|
+
let held = [];
|
|
60
|
+
let expiring = [];
|
|
51
61
|
let replicated = [];
|
|
52
62
|
let issued = 0;
|
|
53
63
|
function scriptConversations(entries) {
|
|
@@ -89,10 +99,10 @@ export function createMemoryAdapter(options = {}) {
|
|
|
89
99
|
return {
|
|
90
100
|
name: room.name,
|
|
91
101
|
locator: room.locator,
|
|
102
|
+
handle: room.handle,
|
|
92
103
|
roomVersion: room.roomVersion,
|
|
93
104
|
operations: room.operations,
|
|
94
105
|
replica: room.replica,
|
|
95
|
-
attachedModel: room.attachedModel,
|
|
96
106
|
...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
|
|
97
107
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
98
108
|
};
|
|
@@ -106,6 +116,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
106
116
|
return {
|
|
107
117
|
kind: 'bootstrap',
|
|
108
118
|
roomVersion: room.roomVersion,
|
|
119
|
+
...(from === 0 ? { models: modelsOf(room) } : {}),
|
|
109
120
|
documents: named(room.documents ?? {}, taken),
|
|
110
121
|
revisions: named(room.revisions ?? {}, taken),
|
|
111
122
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
@@ -136,9 +147,11 @@ export function createMemoryAdapter(options = {}) {
|
|
|
136
147
|
: [];
|
|
137
148
|
const attachments = room.attachments ?? [];
|
|
138
149
|
const declared = opening && JSON.stringify(attachments) !== JSON.stringify(from.attachments ?? []);
|
|
150
|
+
const models = opening ? changedModels(room, from) : undefined;
|
|
139
151
|
return {
|
|
140
152
|
kind: 'net-advancement',
|
|
141
153
|
roomVersion: room.roomVersion,
|
|
154
|
+
...(models === undefined ? {} : { models }),
|
|
142
155
|
documents: named(current, taken),
|
|
143
156
|
revisions: named(room.revisions ?? {}, taken),
|
|
144
157
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
@@ -221,11 +234,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
221
234
|
scripted.delete(named);
|
|
222
235
|
return { kind: 'action', result: { conversation: named } };
|
|
223
236
|
}
|
|
237
|
+
function announceList() {
|
|
238
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined ? [] : [{ conversation, ...listed }]);
|
|
239
|
+
for (const listener of listeners)
|
|
240
|
+
listener({ kind: 'list', entries });
|
|
241
|
+
}
|
|
224
242
|
function discovery() {
|
|
225
243
|
return {
|
|
226
244
|
kind: 'discovery',
|
|
227
|
-
supportedVersions,
|
|
228
|
-
mdModel,
|
|
229
245
|
rooms: rooms.map(declared),
|
|
230
246
|
capabilities,
|
|
231
247
|
providerLimits,
|
|
@@ -240,9 +256,21 @@ export function createMemoryAdapter(options = {}) {
|
|
|
240
256
|
setConversations(next) {
|
|
241
257
|
scriptConversations(next);
|
|
242
258
|
},
|
|
243
|
-
|
|
259
|
+
open() {
|
|
260
|
+
announceList();
|
|
261
|
+
for (const observer of observers)
|
|
262
|
+
observer({ kind: 'opened' });
|
|
263
|
+
},
|
|
264
|
+
close(revoked = false) {
|
|
265
|
+
for (const observer of observers)
|
|
266
|
+
observer({ kind: 'closed', revoked });
|
|
267
|
+
},
|
|
268
|
+
expire(locators) {
|
|
269
|
+
expiring = [...locators];
|
|
270
|
+
},
|
|
271
|
+
notifyRoomVersion({ locator, roomVersion }) {
|
|
244
272
|
for (const observer of observers)
|
|
245
|
-
observer(
|
|
273
|
+
observer({ kind: 'room-version', locator, roomVersion });
|
|
246
274
|
},
|
|
247
275
|
notifyConversation(event) {
|
|
248
276
|
if (event.kind === 'accepted-message') {
|
|
@@ -256,8 +284,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
256
284
|
for (const observer of modeObservers)
|
|
257
285
|
observer(mode);
|
|
258
286
|
},
|
|
259
|
-
|
|
260
|
-
return
|
|
287
|
+
heldRooms() {
|
|
288
|
+
return held;
|
|
261
289
|
},
|
|
262
290
|
replicatedConversations() {
|
|
263
291
|
return replicated;
|
|
@@ -281,12 +309,39 @@ export function createMemoryAdapter(options = {}) {
|
|
|
281
309
|
};
|
|
282
310
|
},
|
|
283
311
|
},
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
312
|
+
roomStream: {
|
|
313
|
+
hold(asked) {
|
|
314
|
+
held = asked.map((room) => room.locator);
|
|
315
|
+
const expired = expiring.filter((locator) => held.includes(locator));
|
|
316
|
+
expiring = [];
|
|
317
|
+
const moved = asked.flatMap((room) => {
|
|
318
|
+
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
319
|
+
return current === undefined ||
|
|
320
|
+
expired.includes(room.locator) ||
|
|
321
|
+
current.roomVersion === room.roomVersion
|
|
322
|
+
? []
|
|
323
|
+
: [{ locator: room.locator, roomVersion: current.roomVersion }];
|
|
324
|
+
});
|
|
325
|
+
queueMicrotask(() => {
|
|
326
|
+
for (const observer of observers) {
|
|
327
|
+
for (const room of moved)
|
|
328
|
+
observer({ kind: 'room-version', ...room });
|
|
329
|
+
observer({ kind: 'opening', expired });
|
|
330
|
+
}
|
|
331
|
+
});
|
|
287
332
|
},
|
|
288
333
|
observe(notify) {
|
|
289
334
|
observers.add(notify);
|
|
335
|
+
queueMicrotask(() => {
|
|
336
|
+
if (!observers.has(notify))
|
|
337
|
+
return;
|
|
338
|
+
if (options.unopened === true) {
|
|
339
|
+
notify({ kind: 'closed', revoked: false });
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
announceList();
|
|
343
|
+
notify({ kind: 'opened' });
|
|
344
|
+
});
|
|
290
345
|
return () => {
|
|
291
346
|
observers.delete(notify);
|
|
292
347
|
};
|
|
@@ -298,13 +353,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
298
353
|
else
|
|
299
354
|
scripts[operation] = answer;
|
|
300
355
|
},
|
|
301
|
-
async model(_authorization, request) {
|
|
302
|
-
return resolveScript(scripts.model, () => {
|
|
303
|
-
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
304
|
-
const answer = request.attached === 'collection' ? room?.model : room?.selectionModel;
|
|
305
|
-
return answer ?? { kind: 'model-unavailable', reason: 'not-readable' };
|
|
306
|
-
}, request);
|
|
307
|
-
},
|
|
308
356
|
async authorize() {
|
|
309
357
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
310
358
|
},
|
|
@@ -317,6 +365,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
317
365
|
});
|
|
318
366
|
},
|
|
319
367
|
reached,
|
|
368
|
+
follows(locator, roomVersion, next) {
|
|
369
|
+
const scripted = scripts.follows;
|
|
370
|
+
if (typeof scripted === 'boolean')
|
|
371
|
+
return scripted;
|
|
372
|
+
if (scripted !== undefined)
|
|
373
|
+
return scripted(locator, roomVersion, next);
|
|
374
|
+
return true;
|
|
375
|
+
},
|
|
320
376
|
async bootstrap(_authorization, request) {
|
|
321
377
|
return resolveScript(scripts.bootstrap, () => {
|
|
322
378
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
@@ -341,10 +397,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
341
397
|
}
|
|
342
398
|
return advancement(continuation.room, continuation.from, continuation.at);
|
|
343
399
|
}
|
|
344
|
-
if (request.minPosition !== undefined &&
|
|
345
|
-
!reached(room.locator, room.roomVersion, request.minPosition)) {
|
|
346
|
-
return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };
|
|
347
|
-
}
|
|
348
400
|
if (request.fromRoomVersion === room.roomVersion) {
|
|
349
401
|
return { kind: 'still-current' };
|
|
350
402
|
}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Definition,
|
|
1
|
+
import type { Definition, ValueFacts, VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
export type ModelIdentity = {
|
|
3
3
|
identity: string;
|
|
4
4
|
version: string;
|
|
@@ -6,23 +6,15 @@ export type ModelIdentity = {
|
|
|
6
6
|
export type ModelSnapshot = ModelIdentity & {
|
|
7
7
|
schema: string | null;
|
|
8
8
|
};
|
|
9
|
-
export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | '
|
|
9
|
+
export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | 'invalid';
|
|
10
10
|
export type ModelResult = {
|
|
11
11
|
kind: 'model';
|
|
12
12
|
snapshot: ModelSnapshot;
|
|
13
13
|
} | {
|
|
14
14
|
kind: 'model-unavailable';
|
|
15
15
|
reason: ModelUnavailableReason;
|
|
16
|
-
} | {
|
|
17
|
-
kind: 'transport-uncertainty';
|
|
18
|
-
} | {
|
|
19
|
-
kind: 'revoked-authorization';
|
|
20
|
-
};
|
|
21
|
-
export type MdType = {
|
|
22
|
-
name: string;
|
|
23
|
-
fields: Readonly<Record<string, FieldSpec>>;
|
|
24
|
-
sections: Readonly<Record<string, SectionSpec>>;
|
|
25
16
|
};
|
|
17
|
+
export type MdType = Definition;
|
|
26
18
|
export type ModelState = {
|
|
27
19
|
status: 'unavailable';
|
|
28
20
|
reason: ModelUnavailableReason;
|
|
@@ -52,4 +44,5 @@ export declare function definitionOf(state: ModelState, type: string | undefined
|
|
|
52
44
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
53
45
|
export declare function cached(state: ModelState): ModelState;
|
|
54
46
|
export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
|
|
47
|
+
export declare function referenceField(facts: ValueFacts | undefined): boolean;
|
|
55
48
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAElF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AACtE,MAAM,MAAM,sBAAsB,GAAG,cAAc,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC;AAC7F,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC;AAChC,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,GACzD;IACE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC/B,CAAC;AACN,MAAM,MAAM,WAAW,GACnB;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,GACzD;IACE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC;AACN,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAA;CAAE,CAAC;AACpG,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAGhG;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAczD;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAE5E;AACD,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAErE"}
|
package/dist/model.js
CHANGED
|
@@ -12,9 +12,7 @@ export function modelTypes(state) {
|
|
|
12
12
|
identity: state.snapshot.identity,
|
|
13
13
|
version: state.snapshot.version,
|
|
14
14
|
verifiedWith: { ...state.verifiedWith },
|
|
15
|
-
types: structuredClone(Object.values(state.types)
|
|
16
|
-
.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0))
|
|
17
|
-
.map(({ name, fields, sections }) => ({ name, fields, sections }))),
|
|
15
|
+
types: structuredClone(Object.values(state.types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)),
|
|
18
16
|
};
|
|
19
17
|
}
|
|
20
18
|
export function cached(state) {
|
|
@@ -23,3 +21,6 @@ export function cached(state) {
|
|
|
23
21
|
export function sameModel(left, right) {
|
|
24
22
|
return left.identity === right.identity && left.version === right.version;
|
|
25
23
|
}
|
|
24
|
+
export function referenceField(facts) {
|
|
25
|
+
return facts?.reference !== undefined || facts?.items?.reference !== undefined;
|
|
26
|
+
}
|
package/dist/observation.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type Observed = {
|
|
|
20
20
|
end(): void;
|
|
21
21
|
};
|
|
22
22
|
export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
|
|
23
|
+
export declare function applied(keyed: KeyedResult, change: QueryChange): KeyedResult;
|
|
23
24
|
export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
|
|
24
25
|
export declare function opened(watch: (deliver: (message: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
26
|
+
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
25
27
|
//# sourceMappingURL=observation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpD,KAAK,IAAI,IAAI,CAAC;C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1
|
export function rowsOf(result) {
|
|
2
2
|
return 'groups' in result ? result.groups : result.documents;
|
|
3
3
|
}
|
|
4
|
+
export function applied(keyed, change) {
|
|
5
|
+
const rows = rowsOf(keyed.result);
|
|
6
|
+
const byKey = new Map(keyed.keys.map((key, index) => [key, rows[index]]));
|
|
7
|
+
for (const key of change.removed)
|
|
8
|
+
byKey.delete(key);
|
|
9
|
+
for (const [key, row] of change.changed)
|
|
10
|
+
byKey.set(key, row);
|
|
11
|
+
const keys = change.order ?? keyed.keys.filter((key) => byKey.has(key));
|
|
12
|
+
const next = keys.map((key) => byKey.get(key));
|
|
13
|
+
return {
|
|
14
|
+
result: 'groups' in keyed.result
|
|
15
|
+
? { groups: next }
|
|
16
|
+
: { documents: next },
|
|
17
|
+
keys,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
4
20
|
function keyedResult(first) {
|
|
5
|
-
|
|
6
|
-
const rows = rowsOf(first.result);
|
|
7
|
-
const byKey = new Map(first.keys.map((key, index) => [key, rows[index]]));
|
|
8
|
-
let keys = first.keys;
|
|
21
|
+
let keyed = first;
|
|
9
22
|
return {
|
|
10
23
|
value: first.result,
|
|
11
24
|
next(message) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
byKey.delete(key);
|
|
15
|
-
for (const [key, row] of change.changed)
|
|
16
|
-
byKey.set(key, row);
|
|
17
|
-
keys = change.order ?? keys.filter((key) => byKey.has(key));
|
|
18
|
-
const next = keys.map((key) => byKey.get(key));
|
|
19
|
-
return grouped
|
|
20
|
-
? { groups: next }
|
|
21
|
-
: { documents: next };
|
|
25
|
+
keyed = applied(keyed, message);
|
|
26
|
+
return keyed.result;
|
|
22
27
|
},
|
|
23
28
|
};
|
|
24
29
|
}
|
|
@@ -83,3 +88,8 @@ export function opened(watch, keyed) {
|
|
|
83
88
|
}
|
|
84
89
|
});
|
|
85
90
|
}
|
|
91
|
+
export function observing(watch) {
|
|
92
|
+
return (topic, ...input) => opened((deliver) => watch(topic, input, (message) => {
|
|
93
|
+
deliver(structuredClone(message));
|
|
94
|
+
}), topic === 'query');
|
|
95
|
+
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare function normalize(path: string): string | null;
|
|
2
|
-
export declare function relative(from: string, target: string): string;
|
|
3
2
|
export declare function beneath(prefix: string, path: string): boolean;
|
|
4
3
|
export declare function covered(prefixes: readonly string[], path: string): boolean;
|
|
5
4
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK1E"}
|
package/dist/paths.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
function dirname(path) {
|
|
2
|
-
const index = path.lastIndexOf('/');
|
|
3
|
-
return index === -1 ? '' : path.slice(0, index);
|
|
4
|
-
}
|
|
5
1
|
export function normalize(path) {
|
|
6
2
|
const parts = [];
|
|
7
3
|
for (const part of path.split('/')) {
|
|
@@ -17,18 +13,6 @@ export function normalize(path) {
|
|
|
17
13
|
}
|
|
18
14
|
return parts.join('/');
|
|
19
15
|
}
|
|
20
|
-
export function relative(from, target) {
|
|
21
|
-
const base = dirname(from)
|
|
22
|
-
.split('/')
|
|
23
|
-
.filter((part) => part !== '');
|
|
24
|
-
const parts = target.split('/');
|
|
25
|
-
let shared = 0;
|
|
26
|
-
while (shared < base.length && shared + 1 < parts.length && base[shared] === parts[shared]) {
|
|
27
|
-
shared += 1;
|
|
28
|
-
}
|
|
29
|
-
const up = Array.from({ length: base.length - shared }, () => '..');
|
|
30
|
-
return [...up, ...parts.slice(shared)].join('/');
|
|
31
|
-
}
|
|
32
16
|
export function beneath(prefix, path) {
|
|
33
17
|
return path === prefix || path.startsWith(`${prefix}/`);
|
|
34
18
|
}
|
package/dist/query.d.ts
CHANGED
|
@@ -186,8 +186,13 @@ export type GroupShape = {
|
|
|
186
186
|
direction: Direction;
|
|
187
187
|
}[];
|
|
188
188
|
};
|
|
189
|
+
export type PlanReach = {
|
|
190
|
+
rooms: readonly string[];
|
|
191
|
+
documents: readonly string[];
|
|
192
|
+
};
|
|
189
193
|
export type Plan = {
|
|
190
194
|
rooms: readonly string[] | null;
|
|
195
|
+
reach: PlanReach | null;
|
|
191
196
|
root: Scope;
|
|
192
197
|
hop: (Scope & {
|
|
193
198
|
field: string;
|
|
@@ -205,9 +210,9 @@ type Entries = Readonly<Record<string, unknown>>;
|
|
|
205
210
|
export declare function invalid(at: string, problem: string): never;
|
|
206
211
|
export declare function plain(value: unknown): value is Entries;
|
|
207
212
|
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
208
|
-
export declare function planOf(input: unknown, facts: HeldRooms): Plan;
|
|
213
|
+
export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
209
214
|
export declare function limitOf(input: unknown): number | null;
|
|
210
|
-
export declare function filterOf(input: unknown, facts: HeldRooms): Plan;
|
|
215
|
+
export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
211
216
|
export declare function identityOf(plan: Plan): string;
|
|
212
217
|
export {};
|
|
213
218
|
//# sourceMappingURL=query.d.ts.map
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"A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XD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,IAAI,CAkB7F;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMrD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,IAAI,CAI/F;AAaD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C"}
|
package/dist/query.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { referenceField } from './model.js';
|
|
1
2
|
import { normalize } from './paths.js';
|
|
2
3
|
export class QueryError extends Error {
|
|
3
4
|
constructor(code, at, problem) {
|
|
@@ -68,23 +69,29 @@ function calendarDate(value) {
|
|
|
68
69
|
const date = new Date(Date.UTC(year, month - 1, day));
|
|
69
70
|
return (date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day);
|
|
70
71
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
function itemOf(facts) {
|
|
73
|
+
return facts.type === 'array' ? facts.items : facts;
|
|
74
|
+
}
|
|
75
|
+
function fits(facts, value) {
|
|
76
|
+
const item = itemOf(facts);
|
|
77
|
+
if (item?.type === undefined)
|
|
78
|
+
return true;
|
|
79
|
+
if (item.values !== undefined)
|
|
80
|
+
return item.values.includes(value);
|
|
81
|
+
if (item.type === 'number')
|
|
74
82
|
return typeof value === 'number';
|
|
75
|
-
if (
|
|
83
|
+
if (item.type === 'integer')
|
|
84
|
+
return Number.isSafeInteger(value);
|
|
85
|
+
if (item.type === 'boolean')
|
|
86
|
+
return typeof value === 'boolean';
|
|
87
|
+
if (item.type !== 'string' || typeof value !== 'string')
|
|
76
88
|
return false;
|
|
77
|
-
if (item.
|
|
78
|
-
return item.values.includes(value);
|
|
79
|
-
if (item.kind === 'date')
|
|
80
|
-
return calendarDate(value);
|
|
81
|
-
if (item.kind === 'reference')
|
|
89
|
+
if (item.reference !== undefined)
|
|
82
90
|
return value !== '' && normalize(value) === value;
|
|
91
|
+
if (item.format === 'date')
|
|
92
|
+
return calendarDate(value);
|
|
83
93
|
return true;
|
|
84
94
|
}
|
|
85
|
-
function reference(spec) {
|
|
86
|
-
return spec.kind === 'reference' || (spec.kind === 'list' && spec.of.kind === 'reference');
|
|
87
|
-
}
|
|
88
95
|
function typing(facts, rooms, types, at) {
|
|
89
96
|
const read = rooms === null ? facts.rooms : facts.rooms.filter((room) => rooms.includes(room.locator));
|
|
90
97
|
const acquiring = !facts.listed &&
|
|
@@ -116,7 +123,8 @@ function kind(declared, checked, at) {
|
|
|
116
123
|
throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);
|
|
117
124
|
}
|
|
118
125
|
function listed(declared, list) {
|
|
119
|
-
return declared.length > 0 &&
|
|
126
|
+
return (declared.length > 0 &&
|
|
127
|
+
declared.every((facts) => facts.type !== undefined && (facts.type === 'array') === list));
|
|
120
128
|
}
|
|
121
129
|
function test(declared, input, at) {
|
|
122
130
|
if (!plain(input)) {
|
|
@@ -215,11 +223,11 @@ function scope(facts, rooms, input, at) {
|
|
|
215
223
|
pathPrefix: input.pathPrefix === undefined ? null : directory(input.pathPrefix, place(at, 'pathPrefix')),
|
|
216
224
|
};
|
|
217
225
|
}
|
|
218
|
-
function
|
|
226
|
+
function referenceName(typed, field, at) {
|
|
219
227
|
if (typeof field !== 'string')
|
|
220
228
|
invalid(at, 'expects a field name');
|
|
221
229
|
const declared = specs(typed, field, at);
|
|
222
|
-
if (declared.length > 0 && !declared.some(
|
|
230
|
+
if (declared.length > 0 && !declared.some(referenceField))
|
|
223
231
|
invalid(at, 'not a reference field');
|
|
224
232
|
return field;
|
|
225
233
|
}
|
|
@@ -227,7 +235,7 @@ function hopOf(facts, rooms, root, input) {
|
|
|
227
235
|
if (!plain(input))
|
|
228
236
|
invalid('hop', 'expects an object');
|
|
229
237
|
known(input, RELATED, 'hop');
|
|
230
|
-
const field =
|
|
238
|
+
const field = referenceName(root, input.field, 'hop.field');
|
|
231
239
|
const { types, where, pathPrefix } = scope(facts, rooms, input, 'hop');
|
|
232
240
|
return { types, where, pathPrefix, field };
|
|
233
241
|
}
|
|
@@ -236,7 +244,7 @@ function backlinksOf(facts, rooms, input) {
|
|
|
236
244
|
invalid('backlinks', 'expects an object');
|
|
237
245
|
known(input, RELATED, 'backlinks');
|
|
238
246
|
const { typed, types, where, pathPrefix } = scope(facts, rooms, input, 'backlinks');
|
|
239
|
-
const field = input.field === undefined ? null :
|
|
247
|
+
const field = input.field === undefined ? null : referenceName(typed, input.field, 'backlinks.field');
|
|
240
248
|
return { types, where, pathPrefix, field };
|
|
241
249
|
}
|
|
242
250
|
function keyPlan(typed, input, at, path) {
|
|
@@ -372,7 +380,7 @@ function groupShape(typed, input) {
|
|
|
372
380
|
});
|
|
373
381
|
return { kind: 'groups', groupBy, orderBy };
|
|
374
382
|
}
|
|
375
|
-
export function planOf(input, facts) {
|
|
383
|
+
export function planOf(input, facts, reach = null) {
|
|
376
384
|
if (!plain(input))
|
|
377
385
|
invalid('query', 'expects a query object');
|
|
378
386
|
const grouped = input.groupBy !== undefined;
|
|
@@ -386,6 +394,7 @@ export function planOf(input, facts) {
|
|
|
386
394
|
const { typed, ...root } = scope(facts, rooms, input, '');
|
|
387
395
|
return {
|
|
388
396
|
rooms,
|
|
397
|
+
reach,
|
|
389
398
|
root,
|
|
390
399
|
hop: input.hop === undefined ? null : hopOf(facts, rooms, typed, input.hop),
|
|
391
400
|
backlinks: input.backlinks === undefined ? null : backlinksOf(facts, rooms, input.backlinks),
|
|
@@ -401,11 +410,11 @@ export function limitOf(input) {
|
|
|
401
410
|
}
|
|
402
411
|
return input;
|
|
403
412
|
}
|
|
404
|
-
export function filterOf(input, facts) {
|
|
413
|
+
export function filterOf(input, facts, reach = null) {
|
|
405
414
|
if (!plain(input))
|
|
406
415
|
invalid('documents', 'expects a filter object');
|
|
407
416
|
known(input, FILTER, '');
|
|
408
|
-
return planOf({ ...input, select: {} }, facts);
|
|
417
|
+
return planOf({ ...input, select: {} }, facts, reach);
|
|
409
418
|
}
|
|
410
419
|
function canonical(value) {
|
|
411
420
|
if (Array.isArray(value))
|
package/dist/reach.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MdRuntime, RuntimeTopic } from './connection.js';
|
|
2
|
+
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
3
|
+
import type { SearchResult } from './search.js';
|
|
4
|
+
export type ReachedDocument = {
|
|
5
|
+
readonly room: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
};
|
|
8
|
+
export type PortReach = {
|
|
9
|
+
readonly rooms: readonly string[];
|
|
10
|
+
readonly documents: readonly ReachedDocument[];
|
|
11
|
+
readonly conversations: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type Deliver = (message: unknown) => void;
|
|
14
|
+
export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
|
|
15
|
+
export type RuntimeView = {
|
|
16
|
+
md: MdRuntime;
|
|
17
|
+
watch: Watch;
|
|
18
|
+
};
|
|
19
|
+
export type NarrowedView = RuntimeView & {
|
|
20
|
+
narrow(reach: PortReach | null): void;
|
|
21
|
+
};
|
|
22
|
+
export type Reachable = RuntimeView & {
|
|
23
|
+
plan(input: unknown, reach: PortReach | null): Plan;
|
|
24
|
+
query(plan: Plan): Promise<QueryResult>;
|
|
25
|
+
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
26
|
+
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
27
|
+
};
|
|
28
|
+
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
29
|
+
export declare function governs(reach: PortReach | null, room: {
|
|
30
|
+
readonly locator: string;
|
|
31
|
+
readonly typedSelection: {
|
|
32
|
+
roots: readonly string[];
|
|
33
|
+
} | null;
|
|
34
|
+
}): {
|
|
35
|
+
readonly collection: boolean;
|
|
36
|
+
readonly selection: boolean;
|
|
37
|
+
};
|
|
38
|
+
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
39
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null): NarrowedView;
|
|
40
|
+
//# sourceMappingURL=reach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,SAAS,EAAe,YAAY,EAAc,MAAM,iBAAiB,CAAC;AAMjG,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;IAC/C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;AAEjD,MAAM,MAAM,KAAK,GAAG,CAClB,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,EAAE,OAAO,KACb,MAAM,IAAI,CAAC;AAEhB,MAAM,MAAM,WAAW,GAAG;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,YAAY,G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