@agentshouse/mdruntime 0.1.0-cc7bd7a53214e → 0.1.0-ccd098ff75bbf
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/README.md +24 -11
- package/dist/adapter.d.ts +172 -49
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +15 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +64 -0
- 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 +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +39 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +187 -45
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -56
- package/dist/change.d.ts +45 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/client.d.ts +37 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +110 -27
- package/dist/collection.d.ts +9 -13
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +46 -56
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +740 -0
- package/dist/connection.d.ts +62 -25
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3831 -958
- package/dist/conversation.d.ts +56 -16
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +739 -242
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +5 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +19 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +151 -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/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +368 -0
- package/dist/host.d.ts +15 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +134 -31
- package/dist/identity.d.ts +4 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +16 -1
- package/dist/index.d.ts +20 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +167 -47
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/model.d.ts +17 -14
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +16 -4
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +19 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +113 -12
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +62 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +67 -1
- package/dist/overlay.d.ts +15 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +136 -180
- 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 +65 -5
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +122 -40
- package/dist/reach.d.ts +11 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +211 -75
- package/dist/react.d.ts +43 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -0
- package/dist/readiness.d.ts +64 -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 +100 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +198 -0
- package/dist/refresh.d.ts +19 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +125 -53
- package/dist/replica.d.ts +59 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +321 -156
- package/dist/room-draft.d.ts +41 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +186 -37
- package/dist/rows.d.ts +37 -34
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +187 -82
- package/dist/save.d.ts +72 -6
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +889 -178
- package/dist/search.d.ts +41 -29
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +37 -105
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +16 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +431 -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 +123 -58
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +359 -344
- package/dist/stored.d.ts +145 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +557 -0
- package/dist/tables.d.ts +354 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +624 -0
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +170 -45
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +69 -46
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +150 -0
- package/package.json +33 -10
- package/AGENTS.md +0 -215
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -377
package/dist/query.js
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
|
+
import { pointerFacts, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { referenceField } from './model.js';
|
|
1
3
|
import { normalize } from './paths.js';
|
|
4
|
+
import { decodedCursor } from './windows.js';
|
|
2
5
|
export class QueryError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
retryable = false;
|
|
3
8
|
constructor(code, at, problem) {
|
|
4
9
|
super(`${code} at ${at}: ${problem}`);
|
|
10
|
+
this.code = code;
|
|
5
11
|
}
|
|
6
12
|
}
|
|
7
13
|
const RANGE = ['$gt', '$gte', '$lt', '$lte'];
|
|
8
14
|
const SINGLE = ['$eq', '$ne', '$in', '$nin', '$all', '$size', '$exists'];
|
|
9
|
-
const FILTER = ['rooms', 'types', 'where', 'pathPrefix', 'hop', 'backlinks'];
|
|
15
|
+
const FILTER = ['rooms', 'types', 'where', 'pathPrefix', 'folder', 'paths', 'hop', 'backlinks'];
|
|
10
16
|
const RELATED = ['types', 'where', 'pathPrefix', 'field'];
|
|
11
|
-
const PARTS = [
|
|
17
|
+
const PARTS = [
|
|
18
|
+
'fields',
|
|
19
|
+
'sections',
|
|
20
|
+
'preamble',
|
|
21
|
+
'markdown',
|
|
22
|
+
'backlinks',
|
|
23
|
+
'change',
|
|
24
|
+
'fileId',
|
|
25
|
+
'revision',
|
|
26
|
+
];
|
|
12
27
|
const ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];
|
|
13
28
|
const CALENDAR_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
29
|
+
const STRAY_ESCAPE = /~(?![01])/u;
|
|
14
30
|
export function invalid(at, problem) {
|
|
15
31
|
throw new QueryError('invalid-query', at, problem);
|
|
16
32
|
}
|
|
@@ -54,6 +70,13 @@ function names(input, at) {
|
|
|
54
70
|
invalid(at, 'expects a list of names');
|
|
55
71
|
return [...new Set(listed)].sort();
|
|
56
72
|
}
|
|
73
|
+
function pathsOf(input) {
|
|
74
|
+
const listed = list(input, 'paths');
|
|
75
|
+
if (listed.some((item) => typeof item !== 'string' || item === '' || normalize(item) !== item)) {
|
|
76
|
+
invalid('paths', 'expects a list of Paths');
|
|
77
|
+
}
|
|
78
|
+
return [...new Set(listed)].sort();
|
|
79
|
+
}
|
|
57
80
|
function directory(input, at) {
|
|
58
81
|
if (typeof input !== 'string' || normalize(input) !== input) {
|
|
59
82
|
invalid(at, 'expects a normalized directory');
|
|
@@ -68,23 +91,29 @@ function calendarDate(value) {
|
|
|
68
91
|
const date = new Date(Date.UTC(year, month - 1, day));
|
|
69
92
|
return (date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day);
|
|
70
93
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
94
|
+
function itemOf(facts) {
|
|
95
|
+
return facts.type === 'array' ? facts.items : facts;
|
|
96
|
+
}
|
|
97
|
+
function fits(facts, value) {
|
|
98
|
+
const item = itemOf(facts);
|
|
99
|
+
if (item?.type === undefined)
|
|
100
|
+
return true;
|
|
101
|
+
if (item.values !== undefined)
|
|
102
|
+
return item.values.includes(value);
|
|
103
|
+
if (item.type === 'number')
|
|
74
104
|
return typeof value === 'number';
|
|
75
|
-
if (
|
|
105
|
+
if (item.type === 'integer')
|
|
106
|
+
return Number.isSafeInteger(value);
|
|
107
|
+
if (item.type === 'boolean')
|
|
108
|
+
return typeof value === 'boolean';
|
|
109
|
+
if (item.type !== 'string' || typeof value !== 'string')
|
|
76
110
|
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')
|
|
111
|
+
if (item.reference !== undefined)
|
|
82
112
|
return value !== '' && normalize(value) === value;
|
|
113
|
+
if (item.format === 'date')
|
|
114
|
+
return calendarDate(value);
|
|
83
115
|
return true;
|
|
84
116
|
}
|
|
85
|
-
function reference(spec) {
|
|
86
|
-
return spec.kind === 'reference' || (spec.kind === 'list' && spec.of.kind === 'reference');
|
|
87
|
-
}
|
|
88
117
|
function typing(facts, rooms, types, at) {
|
|
89
118
|
const read = rooms === null ? facts.rooms : facts.rooms.filter((room) => rooms.includes(room.locator));
|
|
90
119
|
const acquiring = !facts.listed &&
|
|
@@ -102,22 +131,46 @@ function typing(facts, rooms, types, at) {
|
|
|
102
131
|
types: types === null ? declared : declared.filter((type) => types.includes(type.name)),
|
|
103
132
|
};
|
|
104
133
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
134
|
+
function pointer(input, at) {
|
|
135
|
+
if (typeof input !== 'string' || !input.startsWith('/') || STRAY_ESCAPE.test(input)) {
|
|
136
|
+
invalid(at, 'expects a JSON Pointer');
|
|
137
|
+
}
|
|
138
|
+
return input;
|
|
139
|
+
}
|
|
140
|
+
function specs(typed, input, at) {
|
|
141
|
+
const field = pointer(input, at);
|
|
142
|
+
const declared = typed.types.flatMap((type) => {
|
|
143
|
+
const spec = pointerFacts(type, field);
|
|
144
|
+
return spec === undefined ? [] : [spec];
|
|
145
|
+
});
|
|
107
146
|
if (declared.length === 0 && !typed.untyped) {
|
|
108
147
|
throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`);
|
|
109
148
|
}
|
|
110
|
-
|
|
149
|
+
if (!declared.some((spec) => spec.conditional))
|
|
150
|
+
return declared;
|
|
151
|
+
return declared.map((spec) => ({
|
|
152
|
+
facts: { prose: false },
|
|
153
|
+
through: several(spec),
|
|
154
|
+
conditional: true,
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
function several(spec) {
|
|
158
|
+
return spec.through || spec.facts.type === 'array';
|
|
159
|
+
}
|
|
160
|
+
function single(spec) {
|
|
161
|
+
return spec.facts.type !== undefined && spec.facts.type !== 'array';
|
|
162
|
+
}
|
|
163
|
+
function every(declared, holds) {
|
|
164
|
+
return declared.length > 0 && declared.every(holds);
|
|
111
165
|
}
|
|
112
166
|
function kind(declared, checked, at) {
|
|
113
|
-
if (checked === null ||
|
|
167
|
+
if (checked === null ||
|
|
168
|
+
declared.length === 0 ||
|
|
169
|
+
declared.some((spec) => fits(spec.facts, checked))) {
|
|
114
170
|
return;
|
|
115
171
|
}
|
|
116
172
|
throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);
|
|
117
173
|
}
|
|
118
|
-
function listed(declared, list) {
|
|
119
|
-
return declared.length > 0 && declared.every((spec) => (spec.kind === 'list') === list);
|
|
120
|
-
}
|
|
121
174
|
function test(declared, input, at) {
|
|
122
175
|
if (!plain(input)) {
|
|
123
176
|
const equal = value(input, at);
|
|
@@ -131,8 +184,11 @@ function test(declared, input, at) {
|
|
|
131
184
|
const stray = operators.find((operator) => !RANGE.includes(operator));
|
|
132
185
|
if (stray !== undefined)
|
|
133
186
|
invalid(place(at, stray), 'cannot join a range');
|
|
134
|
-
if (
|
|
187
|
+
if (every(declared, (spec) => spec.facts.type === 'array'))
|
|
135
188
|
invalid(at, 'a range on a list');
|
|
189
|
+
if (every(declared, (spec) => spec.facts.type === 'boolean' || spec.facts.type === 'object')) {
|
|
190
|
+
throw new QueryError('wrong-kind', at, 'its field does not compare in order');
|
|
191
|
+
}
|
|
136
192
|
return {
|
|
137
193
|
op: 'range',
|
|
138
194
|
bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {
|
|
@@ -165,7 +221,7 @@ function test(declared, input, at) {
|
|
|
165
221
|
return { op: 'nin', values: compared };
|
|
166
222
|
if (compared.includes(null))
|
|
167
223
|
invalid(where, 'a list holds no null');
|
|
168
|
-
if (
|
|
224
|
+
if (every(declared, single))
|
|
169
225
|
invalid(where, 'the field is not a list');
|
|
170
226
|
return { op: 'all', values: compared };
|
|
171
227
|
}
|
|
@@ -173,7 +229,7 @@ function test(declared, input, at) {
|
|
|
173
229
|
if (!Number.isSafeInteger(operand) || operand < 0) {
|
|
174
230
|
invalid(where, 'expects a nonnegative integer');
|
|
175
231
|
}
|
|
176
|
-
if (
|
|
232
|
+
if (every(declared, single))
|
|
177
233
|
invalid(where, 'the field is not a list');
|
|
178
234
|
return { op: 'size', size: operand };
|
|
179
235
|
}
|
|
@@ -186,7 +242,7 @@ function condition(typed, input, at) {
|
|
|
186
242
|
invalid(at, 'expects an object of field predicates');
|
|
187
243
|
const conditions = [];
|
|
188
244
|
for (const name of Object.keys(input).sort()) {
|
|
189
|
-
const where = place(at, name);
|
|
245
|
+
const where = name.startsWith('/') ? `${at}${name}` : place(at, name);
|
|
190
246
|
const entry = input[name];
|
|
191
247
|
if (name === '$and' || name === '$or') {
|
|
192
248
|
const nested = list(entry, where).map((item, index) => condition(typed, item, `${where}[${index}]`));
|
|
@@ -215,19 +271,19 @@ function scope(facts, rooms, input, at) {
|
|
|
215
271
|
pathPrefix: input.pathPrefix === undefined ? null : directory(input.pathPrefix, place(at, 'pathPrefix')),
|
|
216
272
|
};
|
|
217
273
|
}
|
|
218
|
-
function
|
|
219
|
-
if (typeof field !== 'string')
|
|
220
|
-
invalid(at, 'expects a field name');
|
|
274
|
+
function referenceName(typed, field, at) {
|
|
221
275
|
const declared = specs(typed, field, at);
|
|
222
|
-
if (declared.length > 0 &&
|
|
276
|
+
if (declared.length > 0 &&
|
|
277
|
+
!declared.some((spec) => spec.conditional || referenceField(spec.facts))) {
|
|
223
278
|
invalid(at, 'not a reference field');
|
|
279
|
+
}
|
|
224
280
|
return field;
|
|
225
281
|
}
|
|
226
282
|
function hopOf(facts, rooms, root, input) {
|
|
227
283
|
if (!plain(input))
|
|
228
284
|
invalid('hop', 'expects an object');
|
|
229
285
|
known(input, RELATED, 'hop');
|
|
230
|
-
const field =
|
|
286
|
+
const field = referenceName(root, input.field, 'hop.field');
|
|
231
287
|
const { types, where, pathPrefix } = scope(facts, rooms, input, 'hop');
|
|
232
288
|
return { types, where, pathPrefix, field };
|
|
233
289
|
}
|
|
@@ -236,17 +292,20 @@ function backlinksOf(facts, rooms, input) {
|
|
|
236
292
|
invalid('backlinks', 'expects an object');
|
|
237
293
|
known(input, RELATED, 'backlinks');
|
|
238
294
|
const { typed, types, where, pathPrefix } = scope(facts, rooms, input, 'backlinks');
|
|
239
|
-
const field = input.field === undefined ? null :
|
|
295
|
+
const field = input.field === undefined ? null : referenceName(typed, input.field, 'backlinks.field');
|
|
240
296
|
return { types, where, pathPrefix, field };
|
|
241
297
|
}
|
|
242
298
|
function keyPlan(typed, input, at, path) {
|
|
243
|
-
if (input === 'room' || input === 'type' || (path && input === 'path'))
|
|
299
|
+
if (input === 'room' || input === 'type' || input === 'folder' || (path && input === 'path')) {
|
|
244
300
|
return { of: input };
|
|
245
|
-
|
|
246
|
-
|
|
301
|
+
}
|
|
302
|
+
if (plain(input) && Object.hasOwn(input, 'field') && Object.keys(input).length === 1) {
|
|
303
|
+
if (specs(typed, input.field, place(at, 'field')).some(several)) {
|
|
304
|
+
invalid(place(at, 'field'), 'a path that can hold several values');
|
|
305
|
+
}
|
|
247
306
|
return { of: 'field', field: input.field };
|
|
248
307
|
}
|
|
249
|
-
return invalid(at, path ? 'expects room, path, type or a field' : 'expects room, type or a field');
|
|
308
|
+
return invalid(at, path ? 'expects room, path, type, folder or a field' : 'expects room, type, folder or a field');
|
|
250
309
|
}
|
|
251
310
|
function direction(input, at) {
|
|
252
311
|
if (input === undefined)
|
|
@@ -301,14 +360,14 @@ function parts(typed, input, at, fields) {
|
|
|
301
360
|
return 'all';
|
|
302
361
|
const named = list(input, at);
|
|
303
362
|
named.forEach((name, index) => {
|
|
304
|
-
if (typeof name !== 'string')
|
|
305
|
-
invalid(`${at}[${index}]`, 'expects a name');
|
|
306
363
|
if (fields)
|
|
307
364
|
specs(typed, name, `${at}[${index}]`);
|
|
365
|
+
else if (typeof name !== 'string')
|
|
366
|
+
invalid(`${at}[${index}]`, 'expects a name');
|
|
308
367
|
});
|
|
309
368
|
return named;
|
|
310
369
|
}
|
|
311
|
-
function flag(input, at) {
|
|
370
|
+
export function flag(input, at) {
|
|
312
371
|
if (input === undefined)
|
|
313
372
|
return false;
|
|
314
373
|
if (input !== true)
|
|
@@ -336,6 +395,8 @@ function documentShape(typed, input) {
|
|
|
336
395
|
markdown: true,
|
|
337
396
|
backlinks: true,
|
|
338
397
|
change: true,
|
|
398
|
+
fileId: true,
|
|
399
|
+
revision: true,
|
|
339
400
|
orderBy,
|
|
340
401
|
};
|
|
341
402
|
}
|
|
@@ -350,6 +411,8 @@ function documentShape(typed, input) {
|
|
|
350
411
|
markdown: flag(select.markdown, 'select.markdown'),
|
|
351
412
|
backlinks: flag(select.backlinks, 'select.backlinks'),
|
|
352
413
|
change: flag(select.change, 'select.change'),
|
|
414
|
+
fileId: flag(select.fileId, 'select.fileId'),
|
|
415
|
+
revision: flag(select.revision, 'select.revision'),
|
|
353
416
|
orderBy,
|
|
354
417
|
};
|
|
355
418
|
}
|
|
@@ -380,20 +443,36 @@ export function planOf(input, facts, reach = null) {
|
|
|
380
443
|
invalid('select', 'a grouped query selects nothing');
|
|
381
444
|
if (!grouped && input.select === undefined)
|
|
382
445
|
invalid('select', 'a Document query must select');
|
|
383
|
-
known(input, [...FILTER, 'orderBy', 'limit', grouped ? 'groupBy' : 'select'], '');
|
|
446
|
+
known(input, [...FILTER, 'orderBy', 'limit', 'after', 'total', grouped ? 'groupBy' : 'select'], '');
|
|
384
447
|
const limit = limitOf(input.limit);
|
|
385
448
|
const rooms = input.rooms === undefined ? null : names(input.rooms, 'rooms');
|
|
386
449
|
const { typed, ...root } = scope(facts, rooms, input, '');
|
|
450
|
+
const shape = grouped ? groupShape(typed, input) : documentShape(typed, input);
|
|
387
451
|
return {
|
|
452
|
+
key: queryKey(input),
|
|
388
453
|
rooms,
|
|
389
454
|
reach,
|
|
455
|
+
locked: [],
|
|
390
456
|
root,
|
|
457
|
+
folder: input.folder === undefined ? null : directory(input.folder, 'folder'),
|
|
458
|
+
paths: input.paths === undefined ? null : pathsOf(input.paths),
|
|
391
459
|
hop: input.hop === undefined ? null : hopOf(facts, rooms, typed, input.hop),
|
|
392
460
|
backlinks: input.backlinks === undefined ? null : backlinksOf(facts, rooms, input.backlinks),
|
|
393
|
-
shape
|
|
461
|
+
shape,
|
|
394
462
|
limit,
|
|
463
|
+
after: continuationOf(input.after, shape.orderBy.length + 1),
|
|
464
|
+
total: flag(input.total, 'total'),
|
|
395
465
|
};
|
|
396
466
|
}
|
|
467
|
+
function continuationOf(input, arity) {
|
|
468
|
+
if (input === undefined)
|
|
469
|
+
return null;
|
|
470
|
+
const values = typeof input === 'string' ? decodedCursor(input) : null;
|
|
471
|
+
if (values === null || (values.length !== 0 && values.length !== arity)) {
|
|
472
|
+
invalid('after', 'expects the next an earlier result of this query returned');
|
|
473
|
+
}
|
|
474
|
+
return { text: input, values: values.length === 0 ? null : values };
|
|
475
|
+
}
|
|
397
476
|
export function limitOf(input) {
|
|
398
477
|
if (input === undefined)
|
|
399
478
|
return null;
|
|
@@ -408,6 +487,9 @@ export function filterOf(input, facts, reach = null) {
|
|
|
408
487
|
known(input, FILTER, '');
|
|
409
488
|
return planOf({ ...input, select: {} }, facts, reach);
|
|
410
489
|
}
|
|
490
|
+
export function queryKey(query) {
|
|
491
|
+
return canonical(query);
|
|
492
|
+
}
|
|
411
493
|
function canonical(value) {
|
|
412
494
|
if (Array.isArray(value))
|
|
413
495
|
return `[${value.map(canonical).join(',')}]`;
|
package/dist/reach.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { MdRuntime, RuntimeTopic } from './connection.js';
|
|
1
|
+
import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
|
|
2
2
|
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Readiness } from './readiness.js';
|
|
4
|
+
import { type SearchResult } from './search.js';
|
|
4
5
|
export type ReachedDocument = {
|
|
5
6
|
readonly room: string;
|
|
6
7
|
readonly path: string;
|
|
@@ -18,12 +19,18 @@ export type RuntimeView = {
|
|
|
18
19
|
};
|
|
19
20
|
export type NarrowedView = RuntimeView & {
|
|
20
21
|
narrow(reach: PortReach | null): void;
|
|
22
|
+
facts(port: ReadinessPort): void;
|
|
21
23
|
};
|
|
22
24
|
export type Reachable = RuntimeView & {
|
|
23
25
|
plan(input: unknown, reach: PortReach | null): Plan;
|
|
24
26
|
query(plan: Plan): Promise<QueryResult>;
|
|
25
27
|
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
26
|
-
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
28
|
+
search(input: unknown, reach: PortReach | null, locked: readonly string[]): Promise<SearchResult>;
|
|
29
|
+
watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
|
|
30
|
+
locked(room: string): boolean;
|
|
31
|
+
lockedRooms(): readonly string[];
|
|
32
|
+
watchLocks(notify: () => void): () => void;
|
|
33
|
+
located(room: string, path: string, destination: string): ReachedDocument | null;
|
|
27
34
|
};
|
|
28
35
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
29
36
|
export declare function governs(reach: PortReach | null, room: {
|
|
@@ -36,5 +43,5 @@ export declare function governs(reach: PortReach | null, room: {
|
|
|
36
43
|
readonly selection: boolean;
|
|
37
44
|
};
|
|
38
45
|
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
39
|
-
export declare function narrowed(runtime: Reachable, given: PortReach | null): NarrowedView;
|
|
46
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
|
|
40
47
|
//# 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,EAEV,SAAS,EACT,aAAa,EAEb,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAwBzB,OAAO,KAAK,EAAiB,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAGlE,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,SA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