@agentshouse/mdruntime 0.1.0-c3903a68dcbbf → 0.1.0-c7b0ab1aa40a3
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 +51 -29
- package/README.md +11 -11
- package/dist/adapter.d.ts +78 -51
- 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 +2 -3
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +2 -6
- package/dist/client.d.ts +4 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -16
- package/dist/collection.d.ts +0 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +2 -12
- package/dist/connection.d.ts +10 -28
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +516 -639
- package/dist/conversation.d.ts +22 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +250 -105
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +37 -57
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/memory.d.ts +11 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +77 -27
- 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/outcome.d.ts +5 -21
- package/dist/outcome.d.ts.map +1 -1
- 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 +14 -19
- 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 +0 -2
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +5 -11
- package/dist/store.d.ts +5 -16
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +10 -32
- package/dist/wire.d.ts +51 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +50 -65
- package/package.json +14 -2
package/dist/outcome.d.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
import type { ActionResult
|
|
1
|
+
import type { ActionResult } from './adapter.js';
|
|
2
2
|
import type { ChangeBatch } from './change.js';
|
|
3
|
-
export type AffectedState = Readonly<Record<string, string>>;
|
|
4
3
|
export type CallResult = ActionResult | {
|
|
5
4
|
kind: 'undeclared';
|
|
6
5
|
};
|
|
7
|
-
export type AcceptedOutcome = {
|
|
8
|
-
kind: 'accepted';
|
|
9
|
-
roomVersion: string;
|
|
10
|
-
author?: string;
|
|
11
|
-
time?: string;
|
|
12
|
-
};
|
|
13
|
-
export type SubmissionOutcome = AcceptedOutcome | (ProviderRefusal & {
|
|
14
|
-
kind: 'conflicted';
|
|
15
|
-
roomVersion?: string;
|
|
16
|
-
affected: AffectedState;
|
|
17
|
-
}) | (ProviderRefusal & {
|
|
18
|
-
kind: 'rejected';
|
|
19
|
-
affected: AffectedState;
|
|
20
|
-
}) | {
|
|
21
|
-
kind: 'expired';
|
|
22
|
-
} | {
|
|
23
|
-
kind: 'withdrawn';
|
|
24
|
-
};
|
|
25
6
|
export type Submission = {
|
|
26
7
|
readonly state: 'waiting' | 'submitted';
|
|
27
8
|
} | {
|
|
@@ -30,5 +11,8 @@ export type Submission = {
|
|
|
30
11
|
};
|
|
31
12
|
export type QueueEntry = {
|
|
32
13
|
readonly batch: ChangeBatch;
|
|
33
|
-
} & Submission
|
|
14
|
+
} & (Submission | {
|
|
15
|
+
readonly state: 'accepted';
|
|
16
|
+
readonly roomVersion: string;
|
|
17
|
+
});
|
|
34
18
|
//# sourceMappingURL=outcome.d.ts.map
|
package/dist/outcome.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG,CACvD,UAAU,GACV;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAC/D,CAAC"}
|
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":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAA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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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AAC,WAAW,CAAC,CAAC;IACxC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACxE,CAAC;AA2BF,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMpE;AAMD,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,IAAI,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAC/F;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAU/D;AAcD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CASnE;AA8ED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,YAAY,CAgKlF"}
|
package/dist/reach.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { unheldView } from './conversation.js';
|
|
2
|
+
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
|
+
import { applied, observing } from './observation.js';
|
|
4
|
+
import { beneath } from './paths.js';
|
|
5
|
+
import { reconciled } from './read-side.js';
|
|
6
|
+
import { moveTarget, readParts } from './room-draft.js';
|
|
7
|
+
import { documentKey } from './rows.js';
|
|
8
|
+
const UNHELD_TYPES = { collection: modelTypes(NO_MODEL), typedSelection: null };
|
|
9
|
+
const UNDECLARED = { kind: 'undeclared' };
|
|
10
|
+
function undeclared() {
|
|
11
|
+
return Promise.resolve(UNDECLARED);
|
|
12
|
+
}
|
|
13
|
+
const NO_CONVERSATION = {
|
|
14
|
+
list: () => Promise.resolve([]),
|
|
15
|
+
read: (conversation) => Promise.resolve(unheldView(conversation)),
|
|
16
|
+
create: undeclared,
|
|
17
|
+
send: undeclared,
|
|
18
|
+
answer: undeclared,
|
|
19
|
+
interrupt: undeclared,
|
|
20
|
+
kill: undeclared,
|
|
21
|
+
cancel: undeclared,
|
|
22
|
+
delete: undeclared,
|
|
23
|
+
};
|
|
24
|
+
const NO_CHAT_DRAFT = {
|
|
25
|
+
write: () => Promise.resolve(),
|
|
26
|
+
discard: () => Promise.resolve(),
|
|
27
|
+
};
|
|
28
|
+
export function holds(reach, room) {
|
|
29
|
+
return (reach === null ||
|
|
30
|
+
reach.rooms.includes(room) ||
|
|
31
|
+
reach.documents.some((document) => document.room === room));
|
|
32
|
+
}
|
|
33
|
+
function wholly(reach, room) {
|
|
34
|
+
return reach === null || reach.rooms.includes(room);
|
|
35
|
+
}
|
|
36
|
+
export function governs(reach, room) {
|
|
37
|
+
if (wholly(reach, room.locator)) {
|
|
38
|
+
return { collection: true, selection: room.typedSelection !== null };
|
|
39
|
+
}
|
|
40
|
+
const selected = (path) => room.typedSelection?.roots.some((root) => beneath(root, path)) ?? false;
|
|
41
|
+
const paths = reach.documents
|
|
42
|
+
.filter((document) => document.room === room.locator)
|
|
43
|
+
.map(({ path }) => path);
|
|
44
|
+
return { collection: paths.some((path) => !selected(path)), selection: paths.some(selected) };
|
|
45
|
+
}
|
|
46
|
+
function covers(reach, room, path) {
|
|
47
|
+
return (reach === null ||
|
|
48
|
+
reach.rooms.includes(room) ||
|
|
49
|
+
reach.documents.some((document) => document.room === room && document.path === path));
|
|
50
|
+
}
|
|
51
|
+
function conversing(reach) {
|
|
52
|
+
return reach === null || reach.conversations;
|
|
53
|
+
}
|
|
54
|
+
export function planReach(reach) {
|
|
55
|
+
return reach === null
|
|
56
|
+
? null
|
|
57
|
+
: {
|
|
58
|
+
rooms: [...new Set(reach.rooms)].sort(),
|
|
59
|
+
documents: [
|
|
60
|
+
...new Set(reach.documents.map(({ room, path }) => documentKey(room, path))),
|
|
61
|
+
].sort(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function roomsWithin(reach, rooms) {
|
|
65
|
+
return rooms.filter((room) => wholly(reach, room.locator));
|
|
66
|
+
}
|
|
67
|
+
function typesWithin(reach, room, types) {
|
|
68
|
+
if (room === undefined)
|
|
69
|
+
return structuredClone(UNHELD_TYPES);
|
|
70
|
+
const governed = governs(reach, room);
|
|
71
|
+
return {
|
|
72
|
+
collection: governed.collection ? types.collection : modelTypes(NO_MODEL),
|
|
73
|
+
typedSelection: governed.selection ? types.typedSelection : null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function moves(reach, room, move) {
|
|
77
|
+
return move === undefined || covers(reach, room, moveTarget(move));
|
|
78
|
+
}
|
|
79
|
+
function draftWithin(reach, draft) {
|
|
80
|
+
return covers(reach, draft.room, draft.path) && moves(reach, draft.room, draft.parts.move);
|
|
81
|
+
}
|
|
82
|
+
function draftsWithin(reach, drafts) {
|
|
83
|
+
return drafts.filter((draft) => draftWithin(reach, draft));
|
|
84
|
+
}
|
|
85
|
+
function shownDraft(reach, draft) {
|
|
86
|
+
return draft !== null && draftWithin(reach, draft) ? draft : null;
|
|
87
|
+
}
|
|
88
|
+
function writeWithin(reach, write) {
|
|
89
|
+
return write.outcome === 'written'
|
|
90
|
+
? { outcome: 'written', roomDraft: shownDraft(reach, write.roomDraft) }
|
|
91
|
+
: { outcome: 'stale', current: shownDraft(reach, write.current) };
|
|
92
|
+
}
|
|
93
|
+
function savedWithin(reach, room, result) {
|
|
94
|
+
if (reach === null || result.outcome === 'saved')
|
|
95
|
+
return result;
|
|
96
|
+
const { file, location, referrers, ...refusal } = result;
|
|
97
|
+
const hidden = file !== undefined && !covers(reach, room, file);
|
|
98
|
+
return {
|
|
99
|
+
...refusal,
|
|
100
|
+
...(file === undefined || hidden ? {} : { file }),
|
|
101
|
+
...(location === undefined || hidden ? {} : { location }),
|
|
102
|
+
...(referrers === undefined
|
|
103
|
+
? {}
|
|
104
|
+
: { referrers: referrers.filter((path) => covers(reach, room, path)) }),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function statusWithin(reach, status) {
|
|
108
|
+
return {
|
|
109
|
+
...status,
|
|
110
|
+
attentionRequired: status.attentionRequired.filter((entry) => covers(reach, entry.room, entry.path)),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function queueWithin(reach, room, entries) {
|
|
114
|
+
return entries.filter(({ batch }) => batch.changes.every((change) => covers(reach, room, change.path) &&
|
|
115
|
+
(change.kind !== 'move' || covers(reach, room, change.to))));
|
|
116
|
+
}
|
|
117
|
+
function unreached(room) {
|
|
118
|
+
return new Error(`No Local Replica for ${room}`);
|
|
119
|
+
}
|
|
120
|
+
export function narrowed(runtime, given) {
|
|
121
|
+
const { md, watch } = runtime;
|
|
122
|
+
let reach = given;
|
|
123
|
+
const open = new Set();
|
|
124
|
+
function following(begin) {
|
|
125
|
+
let stop = begin();
|
|
126
|
+
const restart = () => {
|
|
127
|
+
stop();
|
|
128
|
+
stop = begin();
|
|
129
|
+
};
|
|
130
|
+
open.add(restart);
|
|
131
|
+
return () => {
|
|
132
|
+
open.delete(restart);
|
|
133
|
+
stop();
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const within = (topic, input, deliver) => {
|
|
137
|
+
if (topic === 'rooms') {
|
|
138
|
+
return following(() => watch(topic, input, (rooms) => deliver(roomsWithin(reach, rooms))));
|
|
139
|
+
}
|
|
140
|
+
if (topic === 'sync-status') {
|
|
141
|
+
return following(() => watch(topic, input, (status) => deliver(statusWithin(reach, status))));
|
|
142
|
+
}
|
|
143
|
+
if (topic === 'room-drafts') {
|
|
144
|
+
return following(() => watch(topic, input, (drafts) => deliver(draftsWithin(reach, drafts))));
|
|
145
|
+
}
|
|
146
|
+
if (topic === 'queue') {
|
|
147
|
+
const room = input[0];
|
|
148
|
+
return following(() => {
|
|
149
|
+
if (!holds(reach, room)) {
|
|
150
|
+
deliver([]);
|
|
151
|
+
return () => { };
|
|
152
|
+
}
|
|
153
|
+
return watch(topic, input, (entries) => deliver(queueWithin(reach, room, entries)));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (topic === 'query') {
|
|
157
|
+
const plan = runtime.plan(input[0], reach);
|
|
158
|
+
let held = null;
|
|
159
|
+
return following(() => {
|
|
160
|
+
let first = true;
|
|
161
|
+
return runtime.watchPlan({ ...plan, reach: planReach(reach) }, (message) => {
|
|
162
|
+
if (!first) {
|
|
163
|
+
held = applied(held, message);
|
|
164
|
+
deliver(message);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
first = false;
|
|
168
|
+
if (held === null) {
|
|
169
|
+
held = message;
|
|
170
|
+
deliver(message);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const next = reconciled(held, message);
|
|
174
|
+
if (next === null)
|
|
175
|
+
return;
|
|
176
|
+
held = next.keyed;
|
|
177
|
+
deliver(next.change);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (topic === 'conversation') {
|
|
182
|
+
return following(() => {
|
|
183
|
+
if (conversing(reach))
|
|
184
|
+
return watch(topic, input, deliver);
|
|
185
|
+
deliver(unheldView(input[0]));
|
|
186
|
+
return () => { };
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (topic === 'conversations') {
|
|
190
|
+
return following(() => {
|
|
191
|
+
if (conversing(reach))
|
|
192
|
+
return watch(topic, input, deliver);
|
|
193
|
+
deliver([]);
|
|
194
|
+
return () => { };
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return watch(topic, input, deliver);
|
|
198
|
+
};
|
|
199
|
+
const conversation = () => (conversing(reach) ? md.conversation : NO_CONVERSATION);
|
|
200
|
+
const chatDraft = () => (conversing(reach) ? md.chatDraft : NO_CHAT_DRAFT);
|
|
201
|
+
const view = {
|
|
202
|
+
...md,
|
|
203
|
+
rooms: () => roomsWithin(reach, md.rooms()),
|
|
204
|
+
query: ((input) => runtime.query(runtime.plan(input, reach))),
|
|
205
|
+
search: (input) => runtime.search(input, reach),
|
|
206
|
+
types(room) {
|
|
207
|
+
if (wholly(reach, room))
|
|
208
|
+
return md.types(room);
|
|
209
|
+
if (!holds(reach, room))
|
|
210
|
+
return structuredClone(UNHELD_TYPES);
|
|
211
|
+
const listed = md.rooms().find(({ locator }) => locator === room);
|
|
212
|
+
return typesWithin(reach, listed, md.types(room));
|
|
213
|
+
},
|
|
214
|
+
async save(room, roomDrafts, writtenBy) {
|
|
215
|
+
if (!holds(reach, room))
|
|
216
|
+
throw unreached(room);
|
|
217
|
+
const outside = roomDrafts.find(({ path }) => !covers(reach, room, path) ||
|
|
218
|
+
!moves(reach, room, md.roomDraft.read(room, path)?.parts.move));
|
|
219
|
+
if (outside !== undefined)
|
|
220
|
+
return { outcome: 'refused', rule: 'stale', file: outside.path };
|
|
221
|
+
return savedWithin(reach, room, await md.save(room, roomDrafts, writtenBy));
|
|
222
|
+
},
|
|
223
|
+
history: (room, path, query) => covers(reach, room, path)
|
|
224
|
+
? md.history(room, path, query)
|
|
225
|
+
: Promise.resolve({ kind: 'room-not-readable', locator: room }),
|
|
226
|
+
reached: (room, roomVersion, path) => (path === undefined ? wholly(reach, room) : covers(reach, room, path)) &&
|
|
227
|
+
md.reached(room, roomVersion, path),
|
|
228
|
+
log: () => (reach === null ? md.log() : ''),
|
|
229
|
+
roomDraft: {
|
|
230
|
+
list: () => md.roomDraft.list().then((drafts) => draftsWithin(reach, drafts)),
|
|
231
|
+
read: (room, path) => covers(reach, room, path) ? shownDraft(reach, md.roomDraft.read(room, path)) : null,
|
|
232
|
+
async write(room, path, revision, parts) {
|
|
233
|
+
if (!covers(reach, room, path) || !moves(reach, room, readParts(parts).move)) {
|
|
234
|
+
throw unreached(room);
|
|
235
|
+
}
|
|
236
|
+
return writeWithin(reach, await md.roomDraft.write(room, path, revision, parts));
|
|
237
|
+
},
|
|
238
|
+
async discard(room, path, revision) {
|
|
239
|
+
if (!covers(reach, room, path))
|
|
240
|
+
return { outcome: 'stale', current: null };
|
|
241
|
+
return writeWithin(reach, await md.roomDraft.discard(room, path, revision));
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
conversation: {
|
|
245
|
+
list: () => conversation().list(),
|
|
246
|
+
read: (id, options) => conversation().read(id, options),
|
|
247
|
+
create: (input) => conversation().create(input),
|
|
248
|
+
send: (id) => conversation().send(id),
|
|
249
|
+
answer: (id, answer) => conversation().answer(id, answer),
|
|
250
|
+
interrupt: (id) => conversation().interrupt(id),
|
|
251
|
+
kill: (id) => conversation().kill(id),
|
|
252
|
+
cancel: (id, turn) => conversation().cancel(id, turn),
|
|
253
|
+
delete: (id) => conversation().delete(id),
|
|
254
|
+
},
|
|
255
|
+
chatDraft: {
|
|
256
|
+
write: (id, draft) => chatDraft().write(id, draft),
|
|
257
|
+
discard: (id) => chatDraft().discard(id),
|
|
258
|
+
},
|
|
259
|
+
observe: observing(within),
|
|
260
|
+
};
|
|
261
|
+
return {
|
|
262
|
+
md: view,
|
|
263
|
+
watch: within,
|
|
264
|
+
narrow(next) {
|
|
265
|
+
reach = next;
|
|
266
|
+
for (const restart of [...open])
|
|
267
|
+
restart();
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from './client.js';
|
|
2
|
+
import type { AppRoom, ConnectionRefusal, SaveResult } from './connection.js';
|
|
3
|
+
import type { ServiceMode } from './adapter.js';
|
|
4
|
+
import type { ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
5
|
+
import type { QueueEntry } from './outcome.js';
|
|
6
|
+
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
7
|
+
import type { RoomDraft, RoomDraftParts } from './room-draft.js';
|
|
8
|
+
import type { SyncStatus } from './status.js';
|
|
9
|
+
type Client = MdRuntimeClient | null;
|
|
10
|
+
export declare function useObserve(client: Client, topic: 'deployment-facts'): unknown;
|
|
11
|
+
export declare function useObserve(client: Client, topic: 'rooms'): readonly AppRoom[] | undefined;
|
|
12
|
+
export declare function useObserve(client: Client, topic: 'connection-refusal'): ConnectionRefusal | null | undefined;
|
|
13
|
+
export declare function useObserve(client: Client, topic: 'storage-loss'): string | null | undefined;
|
|
14
|
+
export declare function useObserve(client: Client, topic: 'sync-status'): SyncStatus | undefined;
|
|
15
|
+
export declare function useObserve(client: Client, topic: 'service-mode'): ServiceMode | undefined;
|
|
16
|
+
export declare function useObserve(client: Client, topic: 'query', query: DocumentQuery): DocumentResult | undefined;
|
|
17
|
+
export declare function useObserve(client: Client, topic: 'query', query: GroupQuery): GroupResult | undefined;
|
|
18
|
+
export declare function useObserve(client: Client, topic: 'queue', locator: string): readonly QueueEntry[] | undefined;
|
|
19
|
+
export declare function useObserve(client: Client, topic: 'room-drafts'): readonly RoomDraft[] | undefined;
|
|
20
|
+
export declare function useObserve(client: Client, topic: 'presentation'): unknown;
|
|
21
|
+
export declare function useObserve(client: Client, topic: 'conversation', conversation: string, options: ConversationOptions): ConversationView | undefined;
|
|
22
|
+
export declare function useObserve(client: Client, topic: 'conversations'): readonly ConversationEntry[] | undefined;
|
|
23
|
+
export type Saving = {
|
|
24
|
+
readonly busy: boolean;
|
|
25
|
+
readonly outcome: SaveResult | null;
|
|
26
|
+
readonly failure: Error | null;
|
|
27
|
+
save(room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
28
|
+
};
|
|
29
|
+
export declare function useSave(client: MdRuntimeClient): Saving;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,wBAAgB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAkBvD"}
|
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
|
+
async function written(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 written(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
CHANGED
|
@@ -10,5 +10,9 @@ export type ReadSide = {
|
|
|
10
10
|
document(room: string, path: string): SearchedDocument | null;
|
|
11
11
|
close(): void;
|
|
12
12
|
};
|
|
13
|
+
export declare function reconciled(previous: KeyedResult, next: KeyedResult): {
|
|
14
|
+
keyed: KeyedResult;
|
|
15
|
+
change: QueryChange;
|
|
16
|
+
} | null;
|
|
13
17
|
export declare function createReadSide(): ReadSide;
|
|
14
18
|
//# sourceMappingURL=read-side.d.ts.map
|
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":"AA2BA,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,
|
|
1
|
+
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAU,KAAK,WAAW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