@agentshouse/mdruntime 0.1.0-cfbf80d8d4644 → 0.1.0-cfcbb238a5fa0
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 +270 -203
- package/README.md +20 -10
- package/dist/acquisition.d.ts +14 -0
- package/dist/acquisition.d.ts.map +1 -0
- package/dist/acquisition.js +24 -0
- package/dist/adapter.d.ts +83 -20
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +18 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +113 -37
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +49 -16
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +33 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +61 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +27 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +63 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +22 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +155 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +629 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +34 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +25 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +75 -16
- package/dist/collection.d.ts +21 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +271 -23
- package/dist/connection.d.ts +44 -15
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1788 -400
- package/dist/conversation.d.ts +26 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +414 -148
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +156 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +18 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +97 -19
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +19 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/memory.d.ts +11 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +87 -25
- package/dist/model.d.ts +14 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +12 -1
- package/dist/observation.d.ts +5 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +22 -11
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +32 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -1
- package/dist/overlay.d.ts +16 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +118 -77
- package/dist/query.d.ts +40 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +60 -21
- package/dist/reach.d.ts +8 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +60 -24
- package/dist/react.d.ts +31 -18
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +15 -11
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +394 -129
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +13 -3
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +49 -38
- package/dist/replica.d.ts +9 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +125 -68
- package/dist/room-draft.d.ts +38 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +134 -25
- package/dist/rows.d.ts +11 -14
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +89 -49
- package/dist/save.d.ts +31 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +376 -47
- package/dist/search.d.ts +39 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +132 -46
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +61 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +6 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +75 -18
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +539 -200
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +141 -33
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +61 -31
- package/package.json +26 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/query.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
import { pointerFacts, } from '@agentshouse/mdmodel';
|
|
1
2
|
import { referenceField } from './model.js';
|
|
2
3
|
import { normalize } from './paths.js';
|
|
3
4
|
export class QueryError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
retryable = false;
|
|
4
7
|
constructor(code, at, problem) {
|
|
5
8
|
super(`${code} at ${at}: ${problem}`);
|
|
9
|
+
this.code = code;
|
|
6
10
|
}
|
|
7
11
|
}
|
|
8
12
|
const RANGE = ['$gt', '$gte', '$lt', '$lte'];
|
|
9
13
|
const SINGLE = ['$eq', '$ne', '$in', '$nin', '$all', '$size', '$exists'];
|
|
10
14
|
const FILTER = ['rooms', 'types', 'where', 'pathPrefix', 'hop', 'backlinks'];
|
|
11
15
|
const RELATED = ['types', 'where', 'pathPrefix', 'field'];
|
|
12
|
-
const PARTS = ['fields', 'sections', 'preamble', 'markdown', 'backlinks', 'change'];
|
|
16
|
+
const PARTS = ['fields', 'sections', 'preamble', 'markdown', 'backlinks', 'change', 'fileId'];
|
|
13
17
|
const ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];
|
|
14
18
|
const CALENDAR_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
19
|
+
const STRAY_ESCAPE = /~(?![01])/u;
|
|
15
20
|
export function invalid(at, problem) {
|
|
16
21
|
throw new QueryError('invalid-query', at, problem);
|
|
17
22
|
}
|
|
@@ -109,23 +114,46 @@ function typing(facts, rooms, types, at) {
|
|
|
109
114
|
types: types === null ? declared : declared.filter((type) => types.includes(type.name)),
|
|
110
115
|
};
|
|
111
116
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
117
|
+
function pointer(input, at) {
|
|
118
|
+
if (typeof input !== 'string' || !input.startsWith('/') || STRAY_ESCAPE.test(input)) {
|
|
119
|
+
invalid(at, 'expects a JSON Pointer');
|
|
120
|
+
}
|
|
121
|
+
return input;
|
|
122
|
+
}
|
|
123
|
+
function specs(typed, input, at) {
|
|
124
|
+
const field = pointer(input, at);
|
|
125
|
+
const declared = typed.types.flatMap((type) => {
|
|
126
|
+
const spec = pointerFacts(type, field);
|
|
127
|
+
return spec === undefined ? [] : [spec];
|
|
128
|
+
});
|
|
114
129
|
if (declared.length === 0 && !typed.untyped) {
|
|
115
130
|
throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`);
|
|
116
131
|
}
|
|
117
|
-
|
|
132
|
+
if (!declared.some((spec) => spec.conditional))
|
|
133
|
+
return declared;
|
|
134
|
+
return declared.map((spec) => ({
|
|
135
|
+
facts: { prose: false },
|
|
136
|
+
through: several(spec),
|
|
137
|
+
conditional: true,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
function several(spec) {
|
|
141
|
+
return spec.through || spec.facts.type === 'array';
|
|
142
|
+
}
|
|
143
|
+
function single(spec) {
|
|
144
|
+
return spec.facts.type !== undefined && spec.facts.type !== 'array';
|
|
145
|
+
}
|
|
146
|
+
function every(declared, holds) {
|
|
147
|
+
return declared.length > 0 && declared.every(holds);
|
|
118
148
|
}
|
|
119
149
|
function kind(declared, checked, at) {
|
|
120
|
-
if (checked === null ||
|
|
150
|
+
if (checked === null ||
|
|
151
|
+
declared.length === 0 ||
|
|
152
|
+
declared.some((spec) => fits(spec.facts, checked))) {
|
|
121
153
|
return;
|
|
122
154
|
}
|
|
123
155
|
throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);
|
|
124
156
|
}
|
|
125
|
-
function listed(declared, list) {
|
|
126
|
-
return (declared.length > 0 &&
|
|
127
|
-
declared.every((facts) => facts.type !== undefined && (facts.type === 'array') === list));
|
|
128
|
-
}
|
|
129
157
|
function test(declared, input, at) {
|
|
130
158
|
if (!plain(input)) {
|
|
131
159
|
const equal = value(input, at);
|
|
@@ -139,8 +167,11 @@ function test(declared, input, at) {
|
|
|
139
167
|
const stray = operators.find((operator) => !RANGE.includes(operator));
|
|
140
168
|
if (stray !== undefined)
|
|
141
169
|
invalid(place(at, stray), 'cannot join a range');
|
|
142
|
-
if (
|
|
170
|
+
if (every(declared, (spec) => spec.facts.type === 'array'))
|
|
143
171
|
invalid(at, 'a range on a list');
|
|
172
|
+
if (every(declared, (spec) => spec.facts.type === 'boolean' || spec.facts.type === 'object')) {
|
|
173
|
+
throw new QueryError('wrong-kind', at, 'its field does not compare in order');
|
|
174
|
+
}
|
|
144
175
|
return {
|
|
145
176
|
op: 'range',
|
|
146
177
|
bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {
|
|
@@ -173,7 +204,7 @@ function test(declared, input, at) {
|
|
|
173
204
|
return { op: 'nin', values: compared };
|
|
174
205
|
if (compared.includes(null))
|
|
175
206
|
invalid(where, 'a list holds no null');
|
|
176
|
-
if (
|
|
207
|
+
if (every(declared, single))
|
|
177
208
|
invalid(where, 'the field is not a list');
|
|
178
209
|
return { op: 'all', values: compared };
|
|
179
210
|
}
|
|
@@ -181,7 +212,7 @@ function test(declared, input, at) {
|
|
|
181
212
|
if (!Number.isSafeInteger(operand) || operand < 0) {
|
|
182
213
|
invalid(where, 'expects a nonnegative integer');
|
|
183
214
|
}
|
|
184
|
-
if (
|
|
215
|
+
if (every(declared, single))
|
|
185
216
|
invalid(where, 'the field is not a list');
|
|
186
217
|
return { op: 'size', size: operand };
|
|
187
218
|
}
|
|
@@ -194,7 +225,7 @@ function condition(typed, input, at) {
|
|
|
194
225
|
invalid(at, 'expects an object of field predicates');
|
|
195
226
|
const conditions = [];
|
|
196
227
|
for (const name of Object.keys(input).sort()) {
|
|
197
|
-
const where = place(at, name);
|
|
228
|
+
const where = name.startsWith('/') ? `${at}${name}` : place(at, name);
|
|
198
229
|
const entry = input[name];
|
|
199
230
|
if (name === '$and' || name === '$or') {
|
|
200
231
|
const nested = list(entry, where).map((item, index) => condition(typed, item, `${where}[${index}]`));
|
|
@@ -224,11 +255,11 @@ function scope(facts, rooms, input, at) {
|
|
|
224
255
|
};
|
|
225
256
|
}
|
|
226
257
|
function referenceName(typed, field, at) {
|
|
227
|
-
if (typeof field !== 'string')
|
|
228
|
-
invalid(at, 'expects a field name');
|
|
229
258
|
const declared = specs(typed, field, at);
|
|
230
|
-
if (declared.length > 0 &&
|
|
259
|
+
if (declared.length > 0 &&
|
|
260
|
+
!declared.some((spec) => spec.conditional || referenceField(spec.facts))) {
|
|
231
261
|
invalid(at, 'not a reference field');
|
|
262
|
+
}
|
|
232
263
|
return field;
|
|
233
264
|
}
|
|
234
265
|
function hopOf(facts, rooms, root, input) {
|
|
@@ -250,8 +281,10 @@ function backlinksOf(facts, rooms, input) {
|
|
|
250
281
|
function keyPlan(typed, input, at, path) {
|
|
251
282
|
if (input === 'room' || input === 'type' || (path && input === 'path'))
|
|
252
283
|
return { of: input };
|
|
253
|
-
if (plain(input) &&
|
|
254
|
-
specs(typed, input.field, place(at, 'field'))
|
|
284
|
+
if (plain(input) && Object.hasOwn(input, 'field') && Object.keys(input).length === 1) {
|
|
285
|
+
if (specs(typed, input.field, place(at, 'field')).some(several)) {
|
|
286
|
+
invalid(place(at, 'field'), 'a path that can hold several values');
|
|
287
|
+
}
|
|
255
288
|
return { of: 'field', field: input.field };
|
|
256
289
|
}
|
|
257
290
|
return invalid(at, path ? 'expects room, path, type or a field' : 'expects room, type or a field');
|
|
@@ -309,14 +342,14 @@ function parts(typed, input, at, fields) {
|
|
|
309
342
|
return 'all';
|
|
310
343
|
const named = list(input, at);
|
|
311
344
|
named.forEach((name, index) => {
|
|
312
|
-
if (typeof name !== 'string')
|
|
313
|
-
invalid(`${at}[${index}]`, 'expects a name');
|
|
314
345
|
if (fields)
|
|
315
346
|
specs(typed, name, `${at}[${index}]`);
|
|
347
|
+
else if (typeof name !== 'string')
|
|
348
|
+
invalid(`${at}[${index}]`, 'expects a name');
|
|
316
349
|
});
|
|
317
350
|
return named;
|
|
318
351
|
}
|
|
319
|
-
function flag(input, at) {
|
|
352
|
+
export function flag(input, at) {
|
|
320
353
|
if (input === undefined)
|
|
321
354
|
return false;
|
|
322
355
|
if (input !== true)
|
|
@@ -344,6 +377,7 @@ function documentShape(typed, input) {
|
|
|
344
377
|
markdown: true,
|
|
345
378
|
backlinks: true,
|
|
346
379
|
change: true,
|
|
380
|
+
fileId: true,
|
|
347
381
|
orderBy,
|
|
348
382
|
};
|
|
349
383
|
}
|
|
@@ -358,6 +392,7 @@ function documentShape(typed, input) {
|
|
|
358
392
|
markdown: flag(select.markdown, 'select.markdown'),
|
|
359
393
|
backlinks: flag(select.backlinks, 'select.backlinks'),
|
|
360
394
|
change: flag(select.change, 'select.change'),
|
|
395
|
+
fileId: flag(select.fileId, 'select.fileId'),
|
|
361
396
|
orderBy,
|
|
362
397
|
};
|
|
363
398
|
}
|
|
@@ -393,6 +428,7 @@ export function planOf(input, facts, reach = null) {
|
|
|
393
428
|
const rooms = input.rooms === undefined ? null : names(input.rooms, 'rooms');
|
|
394
429
|
const { typed, ...root } = scope(facts, rooms, input, '');
|
|
395
430
|
return {
|
|
431
|
+
key: queryKey(input),
|
|
396
432
|
rooms,
|
|
397
433
|
reach,
|
|
398
434
|
root,
|
|
@@ -416,6 +452,9 @@ export function filterOf(input, facts, reach = null) {
|
|
|
416
452
|
known(input, FILTER, '');
|
|
417
453
|
return planOf({ ...input, select: {} }, facts, reach);
|
|
418
454
|
}
|
|
455
|
+
export function queryKey(query) {
|
|
456
|
+
return canonical(query);
|
|
457
|
+
}
|
|
419
458
|
function canonical(value) {
|
|
420
459
|
if (Array.isArray(value))
|
|
421
460
|
return `[${value.map(canonical).join(',')}]`;
|
package/dist/reach.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReferrerScope } from './adapter.js';
|
|
2
|
+
import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
|
|
2
3
|
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
3
|
-
import type {
|
|
4
|
+
import type { Readiness } from './readiness.js';
|
|
5
|
+
import { type SearchResult } from './search.js';
|
|
4
6
|
export type ReachedDocument = {
|
|
5
7
|
readonly room: string;
|
|
6
8
|
readonly path: string;
|
|
@@ -18,12 +20,15 @@ export type RuntimeView = {
|
|
|
18
20
|
};
|
|
19
21
|
export type NarrowedView = RuntimeView & {
|
|
20
22
|
narrow(reach: PortReach | null): void;
|
|
23
|
+
facts(port: ReadinessPort): void;
|
|
21
24
|
};
|
|
22
25
|
export type Reachable = RuntimeView & {
|
|
23
26
|
plan(input: unknown, reach: PortReach | null): Plan;
|
|
24
27
|
query(plan: Plan): Promise<QueryResult>;
|
|
25
28
|
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
26
29
|
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
30
|
+
watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
|
|
31
|
+
referrerScope(referrer: unknown): ReferrerScope | null;
|
|
27
32
|
};
|
|
28
33
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
29
34
|
export declare function governs(reach: PortReach | null, room: {
|
|
@@ -36,5 +41,5 @@ export declare function governs(reach: PortReach | null, room: {
|
|
|
36
41
|
readonly selection: boolean;
|
|
37
42
|
};
|
|
38
43
|
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
39
|
-
export declare function narrowed(runtime: Reachable, given: PortReach | null): NarrowedView;
|
|
44
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
|
|
40
45
|
//# sourceMappingURL=reach.d.ts.map
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EAEb,YAAY,EAEb,MAAM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xC,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;IACvE,cAAc,CACZ,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GACtC,MAAM,IAAI,CAAC;IACd,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAAC;CACxD,CAAC;AAyBF,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;AA2BD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CASnE;AA8ED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,IAAI,EAAE,aAAa,GAClB,YAAY,CAuLd"}
|
package/dist/reach.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { unheldView } from './conversation.js';
|
|
2
2
|
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
3
|
import { applied, observing } from './observation.js';
|
|
4
|
+
import { runtimeError } from './failure.js';
|
|
5
|
+
import { failure, undeclared, } from './outcome.js';
|
|
4
6
|
import { beneath } from './paths.js';
|
|
5
7
|
import { reconciled } from './read-side.js';
|
|
6
|
-
import { moveTarget, readParts } from './room-draft.js';
|
|
8
|
+
import { moveTarget, readParts, staleWrite, } from './room-draft.js';
|
|
7
9
|
import { documentKey } from './rows.js';
|
|
10
|
+
import { undeclaredSearch } from './search.js';
|
|
8
11
|
const UNHELD_TYPES = { collection: modelTypes(NO_MODEL), typedSelection: null };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return Promise.resolve(UNDECLARED);
|
|
12
|
+
function unconversed(name) {
|
|
13
|
+
return () => Promise.resolve(undeclared(name));
|
|
12
14
|
}
|
|
13
15
|
const NO_CONVERSATION = {
|
|
14
16
|
list: () => Promise.resolve([]),
|
|
15
17
|
read: (conversation) => Promise.resolve(unheldView(conversation)),
|
|
16
|
-
create:
|
|
17
|
-
send:
|
|
18
|
-
answer:
|
|
19
|
-
interrupt:
|
|
20
|
-
kill:
|
|
21
|
-
cancel:
|
|
22
|
-
delete:
|
|
18
|
+
create: unconversed('conversation.create'),
|
|
19
|
+
send: unconversed('conversation.send'),
|
|
20
|
+
answer: unconversed('conversation.answer'),
|
|
21
|
+
interrupt: unconversed('conversation.interrupt'),
|
|
22
|
+
kill: unconversed('conversation.kill'),
|
|
23
|
+
cancel: unconversed('conversation.cancel'),
|
|
24
|
+
delete: unconversed('conversation.delete'),
|
|
23
25
|
};
|
|
24
26
|
const NO_CHAT_DRAFT = {
|
|
25
27
|
write: () => Promise.resolve(),
|
|
@@ -51,6 +53,20 @@ function covers(reach, room, path) {
|
|
|
51
53
|
function conversing(reach) {
|
|
52
54
|
return reach === null || reach.conversations;
|
|
53
55
|
}
|
|
56
|
+
function refers(reach, scope) {
|
|
57
|
+
if (reach === null)
|
|
58
|
+
return true;
|
|
59
|
+
if (scope === null)
|
|
60
|
+
return false;
|
|
61
|
+
if (scope.kind === 'conversations')
|
|
62
|
+
return reach.conversations;
|
|
63
|
+
return scope.path === undefined
|
|
64
|
+
? wholly(reach, scope.locator)
|
|
65
|
+
: covers(reach, scope.locator, scope.path);
|
|
66
|
+
}
|
|
67
|
+
function unreachedReference(fileRef) {
|
|
68
|
+
return { kind: 'absent', code: 'binary-file-absent', fields: { fileRef }, retryable: false };
|
|
69
|
+
}
|
|
54
70
|
export function planReach(reach) {
|
|
55
71
|
return reach === null
|
|
56
72
|
? null
|
|
@@ -88,7 +104,7 @@ function shownDraft(reach, draft) {
|
|
|
88
104
|
function writeWithin(reach, write) {
|
|
89
105
|
return write.outcome === 'written'
|
|
90
106
|
? { outcome: 'written', roomDraft: shownDraft(reach, write.roomDraft) }
|
|
91
|
-
:
|
|
107
|
+
: staleWrite(shownDraft(reach, write.current));
|
|
92
108
|
}
|
|
93
109
|
function savedWithin(reach, room, result) {
|
|
94
110
|
if (reach === null || result.outcome === 'saved')
|
|
@@ -107,7 +123,7 @@ function savedWithin(reach, room, result) {
|
|
|
107
123
|
function statusWithin(reach, status) {
|
|
108
124
|
return {
|
|
109
125
|
...status,
|
|
110
|
-
attentionRequired: status.attentionRequired.filter((entry) => covers(reach, entry.room, entry.path)),
|
|
126
|
+
attentionRequired: status.attentionRequired.filter((entry) => 'refusal' in entry ? wholly(reach, entry.room) : covers(reach, entry.room, entry.path)),
|
|
111
127
|
};
|
|
112
128
|
}
|
|
113
129
|
function queueWithin(reach, room, entries) {
|
|
@@ -115,11 +131,12 @@ function queueWithin(reach, room, entries) {
|
|
|
115
131
|
(change.kind !== 'move' || covers(reach, room, change.to))));
|
|
116
132
|
}
|
|
117
133
|
function unreached(room) {
|
|
118
|
-
return
|
|
134
|
+
return runtimeError('room-not-held', `No Local Replica for ${room}`);
|
|
119
135
|
}
|
|
120
|
-
export function narrowed(runtime, given) {
|
|
136
|
+
export function narrowed(runtime, given, told) {
|
|
121
137
|
const { md, watch } = runtime;
|
|
122
138
|
let reach = given;
|
|
139
|
+
let port = told;
|
|
123
140
|
const open = new Set();
|
|
124
141
|
function following(begin) {
|
|
125
142
|
let stop = begin();
|
|
@@ -137,6 +154,9 @@ export function narrowed(runtime, given) {
|
|
|
137
154
|
if (topic === 'rooms') {
|
|
138
155
|
return following(() => watch(topic, input, (rooms) => deliver(roomsWithin(reach, rooms))));
|
|
139
156
|
}
|
|
157
|
+
if (topic === 'readiness') {
|
|
158
|
+
return following(() => runtime.watchReadiness(port, reach, deliver));
|
|
159
|
+
}
|
|
140
160
|
if (topic === 'sync-status') {
|
|
141
161
|
return following(() => watch(topic, input, (status) => deliver(statusWithin(reach, status))));
|
|
142
162
|
}
|
|
@@ -174,7 +194,7 @@ export function narrowed(runtime, given) {
|
|
|
174
194
|
if (next === null)
|
|
175
195
|
return;
|
|
176
196
|
held = next.keyed;
|
|
177
|
-
deliver(next.
|
|
197
|
+
deliver(next.message);
|
|
178
198
|
});
|
|
179
199
|
});
|
|
180
200
|
}
|
|
@@ -186,7 +206,7 @@ export function narrowed(runtime, given) {
|
|
|
186
206
|
return () => { };
|
|
187
207
|
});
|
|
188
208
|
}
|
|
189
|
-
if (topic === 'conversations') {
|
|
209
|
+
if (topic === 'conversations' || topic === 'agents') {
|
|
190
210
|
return following(() => {
|
|
191
211
|
if (conversing(reach))
|
|
192
212
|
return watch(topic, input, deliver);
|
|
@@ -202,7 +222,9 @@ export function narrowed(runtime, given) {
|
|
|
202
222
|
...md,
|
|
203
223
|
rooms: () => roomsWithin(reach, md.rooms()),
|
|
204
224
|
query: ((input) => runtime.query(runtime.plan(input, reach))),
|
|
205
|
-
search: (input) =>
|
|
225
|
+
search: (input) => port.search === 'required'
|
|
226
|
+
? runtime.search(input, reach)
|
|
227
|
+
: Promise.resolve(undeclaredSearch()),
|
|
206
228
|
types(room) {
|
|
207
229
|
if (wholly(reach, room))
|
|
208
230
|
return md.types(room);
|
|
@@ -216,13 +238,22 @@ export function narrowed(runtime, given) {
|
|
|
216
238
|
throw unreached(room);
|
|
217
239
|
const outside = roomDrafts.find(({ path }) => !covers(reach, room, path) ||
|
|
218
240
|
!moves(reach, room, md.roomDraft.read(room, path)?.parts.move));
|
|
219
|
-
if (outside !== undefined)
|
|
220
|
-
return { outcome: 'refused',
|
|
241
|
+
if (outside !== undefined) {
|
|
242
|
+
return { outcome: 'refused', code: 'stale', retryable: false, file: outside.path };
|
|
243
|
+
}
|
|
221
244
|
return savedWithin(reach, room, await md.save(room, roomDrafts, writtenBy));
|
|
222
245
|
},
|
|
223
246
|
history: (room, path, query) => covers(reach, room, path)
|
|
224
247
|
? md.history(room, path, query)
|
|
225
|
-
: Promise.resolve({ kind: 'room-not-readable', locator: room }),
|
|
248
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
249
|
+
binaryFile: {
|
|
250
|
+
read: (room, path, revision) => covers(reach, room, path)
|
|
251
|
+
? md.binaryFile.read(room, path, revision)
|
|
252
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
253
|
+
readReference: (reference) => refers(reach, runtime.referrerScope(reference.referrer))
|
|
254
|
+
? md.binaryFile.readReference(reference)
|
|
255
|
+
: Promise.resolve(unreachedReference(reference.fileRef)),
|
|
256
|
+
},
|
|
226
257
|
reached: (room, roomVersion, path) => (path === undefined ? wholly(reach, room) : covers(reach, room, path)) &&
|
|
227
258
|
md.reached(room, roomVersion, path),
|
|
228
259
|
log: () => (reach === null ? md.log() : ''),
|
|
@@ -237,7 +268,7 @@ export function narrowed(runtime, given) {
|
|
|
237
268
|
},
|
|
238
269
|
async discard(room, path, revision) {
|
|
239
270
|
if (!covers(reach, room, path))
|
|
240
|
-
return
|
|
271
|
+
return staleWrite(null);
|
|
241
272
|
return writeWithin(reach, await md.roomDraft.discard(room, path, revision));
|
|
242
273
|
},
|
|
243
274
|
},
|
|
@@ -245,7 +276,7 @@ export function narrowed(runtime, given) {
|
|
|
245
276
|
list: () => conversation().list(),
|
|
246
277
|
read: (id, options) => conversation().read(id, options),
|
|
247
278
|
create: (input) => conversation().create(input),
|
|
248
|
-
send: (id) => conversation().send(id),
|
|
279
|
+
send: (id, operation, draft) => conversation().send(id, operation, draft),
|
|
249
280
|
answer: (id, answer) => conversation().answer(id, answer),
|
|
250
281
|
interrupt: (id) => conversation().interrupt(id),
|
|
251
282
|
kill: (id) => conversation().kill(id),
|
|
@@ -253,7 +284,7 @@ export function narrowed(runtime, given) {
|
|
|
253
284
|
delete: (id) => conversation().delete(id),
|
|
254
285
|
},
|
|
255
286
|
chatDraft: {
|
|
256
|
-
write: (id, draft) => chatDraft().write(id, draft),
|
|
287
|
+
write: (id, draft, revision) => chatDraft().write(id, draft, revision),
|
|
257
288
|
discard: (id) => chatDraft().discard(id),
|
|
258
289
|
},
|
|
259
290
|
observe: observing(within),
|
|
@@ -266,5 +297,10 @@ export function narrowed(runtime, given) {
|
|
|
266
297
|
for (const restart of [...open])
|
|
267
298
|
restart();
|
|
268
299
|
},
|
|
300
|
+
facts(next) {
|
|
301
|
+
port = next;
|
|
302
|
+
for (const restart of [...open])
|
|
303
|
+
restart();
|
|
304
|
+
},
|
|
269
305
|
};
|
|
270
306
|
}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
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';
|
|
2
|
+
import type { AppRoom, ConnectionRefusal, SavedRoomDraft, SaveResult } from './connection.js';
|
|
3
|
+
import type { Member, ServiceMode } from './adapter.js';
|
|
4
|
+
import type { ConversationAgent, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
5
|
+
import { type RuntimeError } from './failure.js';
|
|
5
6
|
import type { QueueEntry } from './outcome.js';
|
|
6
|
-
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
7
|
+
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
|
|
8
|
+
import type { Readiness } from './readiness.js';
|
|
7
9
|
import type { RoomDraft, RoomDraftParts } from './room-draft.js';
|
|
8
10
|
import type { SyncStatus } from './status.js';
|
|
9
11
|
type Client = MdRuntimeClient | null;
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function useObserve(client: Client, topic: '
|
|
17
|
-
export declare function useObserve(client: Client, topic: '
|
|
18
|
-
export declare function useObserve(client: Client, topic: '
|
|
19
|
-
export declare function useObserve(client: Client, topic: '
|
|
20
|
-
export declare function useObserve(client: Client, topic: '
|
|
21
|
-
export declare function useObserve(client: Client, topic: '
|
|
22
|
-
export declare function useObserve(client: Client, topic: '
|
|
12
|
+
export type Observed<T> = {
|
|
13
|
+
readonly state: 'loading';
|
|
14
|
+
} | {
|
|
15
|
+
readonly state: 'ready';
|
|
16
|
+
readonly value: T;
|
|
17
|
+
};
|
|
18
|
+
export declare function useObserve(client: Client, topic: 'deployment-facts'): Observed<unknown>;
|
|
19
|
+
export declare function useObserve(client: Client, topic: 'rooms'): Observed<readonly AppRoom[]>;
|
|
20
|
+
export declare function useObserve(client: Client, topic: 'readiness'): Observed<Readiness>;
|
|
21
|
+
export declare function useObserve(client: Client, topic: 'connection-refusal'): Observed<ConnectionRefusal | null>;
|
|
22
|
+
export declare function useObserve(client: Client, topic: 'storage-loss'): Observed<string | null>;
|
|
23
|
+
export declare function useObserve(client: Client, topic: 'sync-status'): Observed<SyncStatus>;
|
|
24
|
+
export declare function useObserve(client: Client, topic: 'service-mode'): Observed<ServiceMode>;
|
|
25
|
+
export declare function useObserve(client: Client, topic: 'member'): Observed<Member | null>;
|
|
26
|
+
export declare function useObserve(client: Client, topic: 'query', query: DocumentQuery): Observed<DocumentResult | PendingResult>;
|
|
27
|
+
export declare function useObserve(client: Client, topic: 'query', query: GroupQuery): Observed<GroupResult | PendingResult>;
|
|
28
|
+
export declare function useObserve(client: Client, topic: 'queue', locator: string): Observed<readonly QueueEntry[]>;
|
|
29
|
+
export declare function useObserve(client: Client, topic: 'room-drafts'): Observed<readonly RoomDraft[]>;
|
|
30
|
+
export declare function useObserve(client: Client, topic: 'presentation'): Observed<unknown>;
|
|
31
|
+
export declare function useObserve(client: Client, topic: 'conversation', conversation: string, options: ConversationOptions): Observed<ConversationView>;
|
|
32
|
+
export declare function useObserve(client: Client, topic: 'conversations'): Observed<readonly ConversationEntry[]>;
|
|
33
|
+
export declare function useObserve(client: Client, topic: 'agents'): Observed<readonly ConversationAgent[]>;
|
|
23
34
|
export type Saving = {
|
|
24
35
|
readonly busy: boolean;
|
|
25
36
|
readonly outcome: SaveResult | null;
|
|
26
|
-
readonly failure:
|
|
37
|
+
readonly failure: RuntimeError | null;
|
|
27
38
|
save(room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
39
|
+
saveWritten(room: string, roomDrafts: readonly SavedRoomDraft[]): Promise<SaveResult>;
|
|
28
40
|
};
|
|
41
|
+
export declare function saveRoomDrafts(client: MdRuntimeClient, room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
29
42
|
export declare function useSave(client: MdRuntimeClient): Saving;
|
|
30
43
|
export {};
|
|
31
44
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,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AM,EACd,KAAK,EAAE,cAAc,EACrB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,GAC3B,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAC9B,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACrB,QAAQ,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;AAC1C,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;AAsCpG,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACzF,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACvF,CAAC;AAMF,wBAAsB,cAAc,CAClC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAC9C,OAAO,CAAC,UAAU,CAAC,CAcrB;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAyBvD"}
|
package/dist/react.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { failed, runtimeError } from './failure.js';
|
|
3
|
+
const LOADING = { state: 'loading' };
|
|
2
4
|
export function useObserve(client, topic, ...input) {
|
|
3
5
|
const key = JSON.stringify([topic, ...input]);
|
|
4
6
|
const [held, setHeld] = useState(null);
|
|
5
7
|
const opened = useRef(input);
|
|
6
8
|
opened.current = input;
|
|
7
|
-
|
|
9
|
+
useLayoutEffect(() => {
|
|
8
10
|
if (client === null)
|
|
9
11
|
return;
|
|
10
12
|
let live = true;
|
|
@@ -18,7 +20,7 @@ export function useObserve(client, topic, ...input) {
|
|
|
18
20
|
observation = open;
|
|
19
21
|
const take = (value) => {
|
|
20
22
|
if (live)
|
|
21
|
-
setHeld({ client, key, value });
|
|
23
|
+
setHeld({ client, key, observed: { state: 'ready', value } });
|
|
22
24
|
};
|
|
23
25
|
take(open.current());
|
|
24
26
|
open.subscribe(take);
|
|
@@ -28,16 +30,16 @@ export function useObserve(client, topic, ...input) {
|
|
|
28
30
|
observation?.close();
|
|
29
31
|
};
|
|
30
32
|
}, [client, key]);
|
|
31
|
-
return held !== null && held.client === client && held.key === key ? held.
|
|
33
|
+
return held !== null && held.client === client && held.key === key ? held.observed : LOADING;
|
|
32
34
|
}
|
|
33
35
|
const IDLE = { busy: false, outcome: null, failure: null };
|
|
34
|
-
async function
|
|
36
|
+
export async function saveRoomDrafts(client, room, roomDrafts) {
|
|
35
37
|
const kept = [];
|
|
36
38
|
for (const [path, parts] of roomDrafts) {
|
|
37
39
|
const prior = await client.roomDraft.read(room, path);
|
|
38
40
|
const write = await client.roomDraft.write(room, path, prior?.revision ?? null, parts);
|
|
39
41
|
if (write.outcome !== 'written' || write.roomDraft === null) {
|
|
40
|
-
throw
|
|
42
|
+
throw runtimeError(write.outcome === 'stale' ? write.code : 'room-draft-unwritten', `the Room Draft at ${path} was not written`);
|
|
41
43
|
}
|
|
42
44
|
kept.push({ path, revision: write.roomDraft.revision });
|
|
43
45
|
}
|
|
@@ -45,18 +47,20 @@ async function written(client, room, roomDrafts) {
|
|
|
45
47
|
}
|
|
46
48
|
export function useSave(client) {
|
|
47
49
|
const [state, setState] = useState(IDLE);
|
|
48
|
-
const
|
|
50
|
+
const settled = useCallback(async (saving) => {
|
|
49
51
|
setState({ busy: true, outcome: null, failure: null });
|
|
50
52
|
try {
|
|
51
|
-
const outcome = await
|
|
53
|
+
const outcome = await saving();
|
|
52
54
|
setState({ busy: false, outcome, failure: null });
|
|
53
55
|
return outcome;
|
|
54
56
|
}
|
|
55
57
|
catch (error) {
|
|
56
|
-
const failure =
|
|
58
|
+
const failure = failed(error);
|
|
57
59
|
setState({ busy: false, outcome: null, failure });
|
|
58
60
|
throw failure;
|
|
59
61
|
}
|
|
60
|
-
}, [
|
|
61
|
-
|
|
62
|
+
}, []);
|
|
63
|
+
const save = useCallback((room, roomDrafts) => settled(() => saveRoomDrafts(client, room, roomDrafts)), [client, settled]);
|
|
64
|
+
const saveWritten = useCallback((room, roomDrafts) => settled(() => client.save(room, roomDrafts)), [client, settled]);
|
|
65
|
+
return { ...state, save, saveWritten };
|
|
62
66
|
}
|
package/dist/read-side.d.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import type { ChangeSet } from './change-set.js';
|
|
2
|
-
import { type KeyedResult, type
|
|
3
|
-
import type { Plan,
|
|
2
|
+
import { type KeyedResult, type QueryMessage } from './observation.js';
|
|
3
|
+
import type { PendingResult, Plan, QueryCoverage, QueryRows } from './query.js';
|
|
4
4
|
import type { SearchedDocument } from './search.js';
|
|
5
|
+
export type Cover = {
|
|
6
|
+
coverage: QueryCoverage;
|
|
7
|
+
} | PendingResult;
|
|
5
8
|
export type ReadSide = {
|
|
6
9
|
apply(set: ChangeSet): void;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
recover(): void;
|
|
11
|
+
query<T>(plan: Plan, at: () => T): Promise<{
|
|
12
|
+
rows: QueryRows;
|
|
13
|
+
at: T;
|
|
14
|
+
}>;
|
|
15
|
+
watch(plan: Plan, identity: string, cover: () => Cover, deliver: (message: QueryMessage) => void): () => void;
|
|
16
|
+
room(room: string): readonly string[];
|
|
10
17
|
document(room: string, path: string): SearchedDocument | null;
|
|
11
18
|
close(): void;
|
|
12
19
|
};
|
|
13
20
|
export declare function reconciled(previous: KeyedResult, next: KeyedResult): {
|
|
14
21
|
keyed: KeyedResult;
|
|
15
|
-
|
|
22
|
+
message: QueryMessage;
|
|
16
23
|
} | null;
|
|
17
24
|
export declare function createReadSide(): ReadSide;
|
|
18
25
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAe,MAAM,kBAAkB,CAAC;AACpF,OAAO,KAAK,EAOV,aAAa,EACb,IAAI,EAEJ,aAAa,EAGb,SAAS,EAIV,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA4CpD,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,EAAE,aAAa,CAAA;CAAE,GAAG,aAAa,CAAC;AAuBhE,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC;IAChB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,EAAE,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IACvE,KAAK,CACH,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,KAAK,EAClB,OAAO,EAAE,CAAC,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