@agentshouse/mdruntime 0.1.0-ce531b51ff088 → 0.1.0-ce9f29a01a271
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 +280 -188
- package/README.md +21 -11
- package/dist/adapter.d.ts +156 -42
- 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 +47 -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 +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +21 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +114 -37
- package/dist/change-set.d.ts +7 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +54 -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/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -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 +28 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +99 -0
- package/dist/chat/markdown.d.ts +21 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +246 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +199 -0
- package/dist/chat/messages.d.ts +22 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +175 -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 +32 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +107 -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/pieces.d.ts +62 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +1110 -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 +64 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +637 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +69 -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/steady.d.ts +3 -0
- package/dist/chat/steady.d.ts.map +1 -0
- package/dist/chat/steady.js +26 -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 +32 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +82 -26
- package/dist/collection.d.ts +23 -13
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +349 -36
- package/dist/connection.d.ts +56 -24
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2292 -759
- package/dist/conversation.d.ts +52 -14
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +723 -237
- 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 +157 -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 +21 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +131 -45
- 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 +20 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +165 -46
- package/dist/model.d.ts +17 -14
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +16 -4
- package/dist/observation.d.ts +8 -1
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +44 -17
- 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 +38 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +45 -1
- package/dist/overlay.d.ts +18 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +247 -165
- 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 +68 -7
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +114 -43
- package/dist/reach.d.ts +45 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +319 -0
- package/dist/react.d.ts +43 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -0
- package/dist/read-side.d.ts +19 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +607 -152
- 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 -2
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +74 -40
- package/dist/replica.d.ts +17 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +167 -82
- package/dist/room-draft.d.ts +41 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +146 -36
- package/dist/rows.d.ts +12 -14
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +92 -50
- package/dist/save.d.ts +36 -5
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +604 -147
- package/dist/search.d.ts +52 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +192 -47
- 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 +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +398 -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 +92 -19
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +704 -283
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +64 -0
- package/dist/windows.d.ts +26 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +93 -0
- package/dist/wire.d.ts +178 -19
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +86 -61
- package/package.json +31 -7
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/query.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Definition } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
4
|
+
import type { Open } from './open.js';
|
|
3
5
|
export type Value = string | number | boolean | null;
|
|
4
6
|
export type Predicate = Value | {
|
|
5
7
|
$eq: Value;
|
|
@@ -36,6 +38,8 @@ export type Filter = {
|
|
|
36
38
|
types?: readonly string[];
|
|
37
39
|
where?: Where;
|
|
38
40
|
pathPrefix?: string;
|
|
41
|
+
folder?: string;
|
|
42
|
+
paths?: readonly string[];
|
|
39
43
|
hop?: Related & {
|
|
40
44
|
field: string;
|
|
41
45
|
};
|
|
@@ -43,7 +47,7 @@ export type Filter = {
|
|
|
43
47
|
field?: string;
|
|
44
48
|
};
|
|
45
49
|
};
|
|
46
|
-
export type Key = 'room' | 'path' | 'type' | {
|
|
50
|
+
export type Key = 'room' | 'path' | 'type' | 'folder' | {
|
|
47
51
|
field: string;
|
|
48
52
|
};
|
|
49
53
|
export type Select = 'all' | {
|
|
@@ -53,6 +57,7 @@ export type Select = 'all' | {
|
|
|
53
57
|
markdown?: true;
|
|
54
58
|
backlinks?: true;
|
|
55
59
|
change?: true;
|
|
60
|
+
fileId?: true;
|
|
56
61
|
};
|
|
57
62
|
export type OrderOptions = {
|
|
58
63
|
nulls?: 'first' | 'last';
|
|
@@ -68,6 +73,8 @@ export type DocumentQuery = Filter & {
|
|
|
68
73
|
direction?: Direction;
|
|
69
74
|
} & OrderOptions)[];
|
|
70
75
|
limit?: number;
|
|
76
|
+
after?: string;
|
|
77
|
+
total?: true;
|
|
71
78
|
};
|
|
72
79
|
export type GroupQuery = Filter & {
|
|
73
80
|
groupBy: readonly Exclude<Key, 'path'>[];
|
|
@@ -76,6 +83,8 @@ export type GroupQuery = Filter & {
|
|
|
76
83
|
direction?: Direction;
|
|
77
84
|
}[];
|
|
78
85
|
limit?: number;
|
|
86
|
+
after?: string;
|
|
87
|
+
total?: true;
|
|
79
88
|
};
|
|
80
89
|
export type LocalQuery = DocumentQuery | GroupQuery;
|
|
81
90
|
export type Backlink = {
|
|
@@ -93,18 +102,49 @@ export type QueryDocument = {
|
|
|
93
102
|
markdown?: string;
|
|
94
103
|
backlinks?: readonly Backlink[];
|
|
95
104
|
change?: HeadChange | null;
|
|
105
|
+
fileId?: string | null;
|
|
106
|
+
binaryFile?: BinaryFileRecord;
|
|
96
107
|
};
|
|
97
108
|
export type QueryGroup = {
|
|
98
109
|
key: readonly unknown[];
|
|
99
110
|
count: number;
|
|
100
111
|
};
|
|
101
|
-
export type
|
|
112
|
+
export type CoveredRoom = {
|
|
113
|
+
room: string;
|
|
114
|
+
generation: string;
|
|
115
|
+
current: boolean;
|
|
116
|
+
};
|
|
117
|
+
export type QueryCoverage = {
|
|
118
|
+
rooms: readonly CoveredRoom[];
|
|
119
|
+
indexes: readonly string[];
|
|
120
|
+
overlay: readonly string[];
|
|
121
|
+
};
|
|
122
|
+
export type Awaits = Open<'acquisition' | 'preparation' | 'index'>;
|
|
123
|
+
export type PendingRoom = {
|
|
124
|
+
room: string;
|
|
125
|
+
awaits: Awaits;
|
|
126
|
+
};
|
|
127
|
+
export type PendingResult = {
|
|
128
|
+
pending: readonly PendingRoom[];
|
|
129
|
+
};
|
|
130
|
+
export type DocumentRows = {
|
|
102
131
|
documents: readonly QueryDocument[];
|
|
132
|
+
next?: string;
|
|
133
|
+
total?: number;
|
|
103
134
|
};
|
|
104
|
-
export type
|
|
135
|
+
export type GroupRows = {
|
|
105
136
|
groups: readonly QueryGroup[];
|
|
137
|
+
next?: string;
|
|
138
|
+
total?: number;
|
|
106
139
|
};
|
|
107
|
-
export type
|
|
140
|
+
export type QueryRows = DocumentRows | GroupRows;
|
|
141
|
+
export type DocumentResult = DocumentRows & {
|
|
142
|
+
coverage: QueryCoverage;
|
|
143
|
+
};
|
|
144
|
+
export type GroupResult = GroupRows & {
|
|
145
|
+
coverage: QueryCoverage;
|
|
146
|
+
};
|
|
147
|
+
export type QueryResult = DocumentResult | GroupResult | PendingResult;
|
|
108
148
|
export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
|
|
109
149
|
export type RoomFacts = {
|
|
110
150
|
locator: string;
|
|
@@ -159,6 +199,8 @@ export type KeyPlan = {
|
|
|
159
199
|
of: 'path';
|
|
160
200
|
} | {
|
|
161
201
|
of: 'type';
|
|
202
|
+
} | {
|
|
203
|
+
of: 'folder';
|
|
162
204
|
} | {
|
|
163
205
|
of: 'field';
|
|
164
206
|
field: string;
|
|
@@ -171,6 +213,7 @@ export type DocumentShape = {
|
|
|
171
213
|
markdown: boolean;
|
|
172
214
|
backlinks: boolean;
|
|
173
215
|
change: boolean;
|
|
216
|
+
fileId: boolean;
|
|
174
217
|
orderBy: readonly {
|
|
175
218
|
key: KeyPlan;
|
|
176
219
|
options: OrderOptions & {
|
|
@@ -186,9 +229,21 @@ export type GroupShape = {
|
|
|
186
229
|
direction: Direction;
|
|
187
230
|
}[];
|
|
188
231
|
};
|
|
232
|
+
export type PlanReach = {
|
|
233
|
+
rooms: readonly string[];
|
|
234
|
+
documents: readonly string[];
|
|
235
|
+
};
|
|
236
|
+
export type Continuation = {
|
|
237
|
+
text: string;
|
|
238
|
+
values: readonly unknown[] | null;
|
|
239
|
+
};
|
|
189
240
|
export type Plan = {
|
|
241
|
+
key: string;
|
|
190
242
|
rooms: readonly string[] | null;
|
|
243
|
+
reach: PlanReach | null;
|
|
191
244
|
root: Scope;
|
|
245
|
+
folder: string | null;
|
|
246
|
+
paths: readonly string[] | null;
|
|
192
247
|
hop: (Scope & {
|
|
193
248
|
field: string;
|
|
194
249
|
}) | null;
|
|
@@ -197,17 +252,23 @@ export type Plan = {
|
|
|
197
252
|
}) | null;
|
|
198
253
|
shape: DocumentShape | GroupShape;
|
|
199
254
|
limit: number | null;
|
|
255
|
+
after: Continuation | null;
|
|
256
|
+
total: boolean;
|
|
200
257
|
};
|
|
201
258
|
export declare class QueryError extends Error {
|
|
259
|
+
readonly code: QueryErrorCode;
|
|
260
|
+
readonly retryable = false;
|
|
202
261
|
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
203
262
|
}
|
|
204
263
|
type Entries = Readonly<Record<string, unknown>>;
|
|
205
264
|
export declare function invalid(at: string, problem: string): never;
|
|
206
265
|
export declare function plain(value: unknown): value is Entries;
|
|
207
266
|
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
208
|
-
export declare function
|
|
267
|
+
export declare function flag(input: unknown, at: string): boolean;
|
|
268
|
+
export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
209
269
|
export declare function limitOf(input: unknown): number | null;
|
|
210
|
-
export declare function filterOf(input: unknown, facts: HeldRooms): Plan;
|
|
270
|
+
export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
271
|
+
export declare function queryKey(query: unknown): string;
|
|
211
272
|
export declare function identityOf(plan: Plan): string;
|
|
212
273
|
export {};
|
|
213
274
|
//# 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,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,K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alize } 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 = ['fields', 'sections', 'preamble', 'markdown', 'backlinks', 'change'];
|
|
17
|
+
const PARTS = ['fields', 'sections', 'preamble', 'markdown', 'backlinks', 'change', 'fileId'];
|
|
12
18
|
const ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];
|
|
13
19
|
const CALENDAR_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
20
|
+
const STRAY_ESCAPE = /~(?![01])/u;
|
|
14
21
|
export function invalid(at, problem) {
|
|
15
22
|
throw new QueryError('invalid-query', at, problem);
|
|
16
23
|
}
|
|
@@ -54,6 +61,13 @@ function names(input, at) {
|
|
|
54
61
|
invalid(at, 'expects a list of names');
|
|
55
62
|
return [...new Set(listed)].sort();
|
|
56
63
|
}
|
|
64
|
+
function pathsOf(input) {
|
|
65
|
+
const listed = list(input, 'paths');
|
|
66
|
+
if (listed.some((item) => typeof item !== 'string' || item === '' || normalize(item) !== item)) {
|
|
67
|
+
invalid('paths', 'expects a list of Paths');
|
|
68
|
+
}
|
|
69
|
+
return [...new Set(listed)].sort();
|
|
70
|
+
}
|
|
57
71
|
function directory(input, at) {
|
|
58
72
|
if (typeof input !== 'string' || normalize(input) !== input) {
|
|
59
73
|
invalid(at, 'expects a normalized directory');
|
|
@@ -68,23 +82,29 @@ function calendarDate(value) {
|
|
|
68
82
|
const date = new Date(Date.UTC(year, month - 1, day));
|
|
69
83
|
return (date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day);
|
|
70
84
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
function itemOf(facts) {
|
|
86
|
+
return facts.type === 'array' ? facts.items : facts;
|
|
87
|
+
}
|
|
88
|
+
function fits(facts, value) {
|
|
89
|
+
const item = itemOf(facts);
|
|
90
|
+
if (item?.type === undefined)
|
|
91
|
+
return true;
|
|
92
|
+
if (item.values !== undefined)
|
|
93
|
+
return item.values.includes(value);
|
|
94
|
+
if (item.type === 'number')
|
|
74
95
|
return typeof value === 'number';
|
|
75
|
-
if (
|
|
96
|
+
if (item.type === 'integer')
|
|
97
|
+
return Number.isSafeInteger(value);
|
|
98
|
+
if (item.type === 'boolean')
|
|
99
|
+
return typeof value === 'boolean';
|
|
100
|
+
if (item.type !== 'string' || typeof value !== 'string')
|
|
76
101
|
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')
|
|
102
|
+
if (item.reference !== undefined)
|
|
82
103
|
return value !== '' && normalize(value) === value;
|
|
104
|
+
if (item.format === 'date')
|
|
105
|
+
return calendarDate(value);
|
|
83
106
|
return true;
|
|
84
107
|
}
|
|
85
|
-
function reference(spec) {
|
|
86
|
-
return spec.kind === 'reference' || (spec.kind === 'list' && spec.of.kind === 'reference');
|
|
87
|
-
}
|
|
88
108
|
function typing(facts, rooms, types, at) {
|
|
89
109
|
const read = rooms === null ? facts.rooms : facts.rooms.filter((room) => rooms.includes(room.locator));
|
|
90
110
|
const acquiring = !facts.listed &&
|
|
@@ -102,22 +122,46 @@ function typing(facts, rooms, types, at) {
|
|
|
102
122
|
types: types === null ? declared : declared.filter((type) => types.includes(type.name)),
|
|
103
123
|
};
|
|
104
124
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
125
|
+
function pointer(input, at) {
|
|
126
|
+
if (typeof input !== 'string' || !input.startsWith('/') || STRAY_ESCAPE.test(input)) {
|
|
127
|
+
invalid(at, 'expects a JSON Pointer');
|
|
128
|
+
}
|
|
129
|
+
return input;
|
|
130
|
+
}
|
|
131
|
+
function specs(typed, input, at) {
|
|
132
|
+
const field = pointer(input, at);
|
|
133
|
+
const declared = typed.types.flatMap((type) => {
|
|
134
|
+
const spec = pointerFacts(type, field);
|
|
135
|
+
return spec === undefined ? [] : [spec];
|
|
136
|
+
});
|
|
107
137
|
if (declared.length === 0 && !typed.untyped) {
|
|
108
138
|
throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`);
|
|
109
139
|
}
|
|
110
|
-
|
|
140
|
+
if (!declared.some((spec) => spec.conditional))
|
|
141
|
+
return declared;
|
|
142
|
+
return declared.map((spec) => ({
|
|
143
|
+
facts: { prose: false },
|
|
144
|
+
through: several(spec),
|
|
145
|
+
conditional: true,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
function several(spec) {
|
|
149
|
+
return spec.through || spec.facts.type === 'array';
|
|
150
|
+
}
|
|
151
|
+
function single(spec) {
|
|
152
|
+
return spec.facts.type !== undefined && spec.facts.type !== 'array';
|
|
153
|
+
}
|
|
154
|
+
function every(declared, holds) {
|
|
155
|
+
return declared.length > 0 && declared.every(holds);
|
|
111
156
|
}
|
|
112
157
|
function kind(declared, checked, at) {
|
|
113
|
-
if (checked === null ||
|
|
158
|
+
if (checked === null ||
|
|
159
|
+
declared.length === 0 ||
|
|
160
|
+
declared.some((spec) => fits(spec.facts, checked))) {
|
|
114
161
|
return;
|
|
115
162
|
}
|
|
116
163
|
throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);
|
|
117
164
|
}
|
|
118
|
-
function listed(declared, list) {
|
|
119
|
-
return declared.length > 0 && declared.every((spec) => (spec.kind === 'list') === list);
|
|
120
|
-
}
|
|
121
165
|
function test(declared, input, at) {
|
|
122
166
|
if (!plain(input)) {
|
|
123
167
|
const equal = value(input, at);
|
|
@@ -131,8 +175,11 @@ function test(declared, input, at) {
|
|
|
131
175
|
const stray = operators.find((operator) => !RANGE.includes(operator));
|
|
132
176
|
if (stray !== undefined)
|
|
133
177
|
invalid(place(at, stray), 'cannot join a range');
|
|
134
|
-
if (
|
|
178
|
+
if (every(declared, (spec) => spec.facts.type === 'array'))
|
|
135
179
|
invalid(at, 'a range on a list');
|
|
180
|
+
if (every(declared, (spec) => spec.facts.type === 'boolean' || spec.facts.type === 'object')) {
|
|
181
|
+
throw new QueryError('wrong-kind', at, 'its field does not compare in order');
|
|
182
|
+
}
|
|
136
183
|
return {
|
|
137
184
|
op: 'range',
|
|
138
185
|
bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {
|
|
@@ -165,7 +212,7 @@ function test(declared, input, at) {
|
|
|
165
212
|
return { op: 'nin', values: compared };
|
|
166
213
|
if (compared.includes(null))
|
|
167
214
|
invalid(where, 'a list holds no null');
|
|
168
|
-
if (
|
|
215
|
+
if (every(declared, single))
|
|
169
216
|
invalid(where, 'the field is not a list');
|
|
170
217
|
return { op: 'all', values: compared };
|
|
171
218
|
}
|
|
@@ -173,7 +220,7 @@ function test(declared, input, at) {
|
|
|
173
220
|
if (!Number.isSafeInteger(operand) || operand < 0) {
|
|
174
221
|
invalid(where, 'expects a nonnegative integer');
|
|
175
222
|
}
|
|
176
|
-
if (
|
|
223
|
+
if (every(declared, single))
|
|
177
224
|
invalid(where, 'the field is not a list');
|
|
178
225
|
return { op: 'size', size: operand };
|
|
179
226
|
}
|
|
@@ -186,7 +233,7 @@ function condition(typed, input, at) {
|
|
|
186
233
|
invalid(at, 'expects an object of field predicates');
|
|
187
234
|
const conditions = [];
|
|
188
235
|
for (const name of Object.keys(input).sort()) {
|
|
189
|
-
const where = place(at, name);
|
|
236
|
+
const where = name.startsWith('/') ? `${at}${name}` : place(at, name);
|
|
190
237
|
const entry = input[name];
|
|
191
238
|
if (name === '$and' || name === '$or') {
|
|
192
239
|
const nested = list(entry, where).map((item, index) => condition(typed, item, `${where}[${index}]`));
|
|
@@ -215,19 +262,19 @@ function scope(facts, rooms, input, at) {
|
|
|
215
262
|
pathPrefix: input.pathPrefix === undefined ? null : directory(input.pathPrefix, place(at, 'pathPrefix')),
|
|
216
263
|
};
|
|
217
264
|
}
|
|
218
|
-
function
|
|
219
|
-
if (typeof field !== 'string')
|
|
220
|
-
invalid(at, 'expects a field name');
|
|
265
|
+
function referenceName(typed, field, at) {
|
|
221
266
|
const declared = specs(typed, field, at);
|
|
222
|
-
if (declared.length > 0 &&
|
|
267
|
+
if (declared.length > 0 &&
|
|
268
|
+
!declared.some((spec) => spec.conditional || referenceField(spec.facts))) {
|
|
223
269
|
invalid(at, 'not a reference field');
|
|
270
|
+
}
|
|
224
271
|
return field;
|
|
225
272
|
}
|
|
226
273
|
function hopOf(facts, rooms, root, input) {
|
|
227
274
|
if (!plain(input))
|
|
228
275
|
invalid('hop', 'expects an object');
|
|
229
276
|
known(input, RELATED, 'hop');
|
|
230
|
-
const field =
|
|
277
|
+
const field = referenceName(root, input.field, 'hop.field');
|
|
231
278
|
const { types, where, pathPrefix } = scope(facts, rooms, input, 'hop');
|
|
232
279
|
return { types, where, pathPrefix, field };
|
|
233
280
|
}
|
|
@@ -236,17 +283,20 @@ function backlinksOf(facts, rooms, input) {
|
|
|
236
283
|
invalid('backlinks', 'expects an object');
|
|
237
284
|
known(input, RELATED, 'backlinks');
|
|
238
285
|
const { typed, types, where, pathPrefix } = scope(facts, rooms, input, 'backlinks');
|
|
239
|
-
const field = input.field === undefined ? null :
|
|
286
|
+
const field = input.field === undefined ? null : referenceName(typed, input.field, 'backlinks.field');
|
|
240
287
|
return { types, where, pathPrefix, field };
|
|
241
288
|
}
|
|
242
289
|
function keyPlan(typed, input, at, path) {
|
|
243
|
-
if (input === 'room' || input === 'type' || (path && input === 'path'))
|
|
290
|
+
if (input === 'room' || input === 'type' || input === 'folder' || (path && input === 'path')) {
|
|
244
291
|
return { of: input };
|
|
245
|
-
|
|
246
|
-
|
|
292
|
+
}
|
|
293
|
+
if (plain(input) && Object.hasOwn(input, 'field') && Object.keys(input).length === 1) {
|
|
294
|
+
if (specs(typed, input.field, place(at, 'field')).some(several)) {
|
|
295
|
+
invalid(place(at, 'field'), 'a path that can hold several values');
|
|
296
|
+
}
|
|
247
297
|
return { of: 'field', field: input.field };
|
|
248
298
|
}
|
|
249
|
-
return invalid(at, path ? 'expects room, path, type or a field' : 'expects room, type or a field');
|
|
299
|
+
return invalid(at, path ? 'expects room, path, type, folder or a field' : 'expects room, type, folder or a field');
|
|
250
300
|
}
|
|
251
301
|
function direction(input, at) {
|
|
252
302
|
if (input === undefined)
|
|
@@ -301,14 +351,14 @@ function parts(typed, input, at, fields) {
|
|
|
301
351
|
return 'all';
|
|
302
352
|
const named = list(input, at);
|
|
303
353
|
named.forEach((name, index) => {
|
|
304
|
-
if (typeof name !== 'string')
|
|
305
|
-
invalid(`${at}[${index}]`, 'expects a name');
|
|
306
354
|
if (fields)
|
|
307
355
|
specs(typed, name, `${at}[${index}]`);
|
|
356
|
+
else if (typeof name !== 'string')
|
|
357
|
+
invalid(`${at}[${index}]`, 'expects a name');
|
|
308
358
|
});
|
|
309
359
|
return named;
|
|
310
360
|
}
|
|
311
|
-
function flag(input, at) {
|
|
361
|
+
export function flag(input, at) {
|
|
312
362
|
if (input === undefined)
|
|
313
363
|
return false;
|
|
314
364
|
if (input !== true)
|
|
@@ -336,6 +386,7 @@ function documentShape(typed, input) {
|
|
|
336
386
|
markdown: true,
|
|
337
387
|
backlinks: true,
|
|
338
388
|
change: true,
|
|
389
|
+
fileId: true,
|
|
339
390
|
orderBy,
|
|
340
391
|
};
|
|
341
392
|
}
|
|
@@ -350,6 +401,7 @@ function documentShape(typed, input) {
|
|
|
350
401
|
markdown: flag(select.markdown, 'select.markdown'),
|
|
351
402
|
backlinks: flag(select.backlinks, 'select.backlinks'),
|
|
352
403
|
change: flag(select.change, 'select.change'),
|
|
404
|
+
fileId: flag(select.fileId, 'select.fileId'),
|
|
353
405
|
orderBy,
|
|
354
406
|
};
|
|
355
407
|
}
|
|
@@ -372,7 +424,7 @@ function groupShape(typed, input) {
|
|
|
372
424
|
});
|
|
373
425
|
return { kind: 'groups', groupBy, orderBy };
|
|
374
426
|
}
|
|
375
|
-
export function planOf(input, facts) {
|
|
427
|
+
export function planOf(input, facts, reach = null) {
|
|
376
428
|
if (!plain(input))
|
|
377
429
|
invalid('query', 'expects a query object');
|
|
378
430
|
const grouped = input.groupBy !== undefined;
|
|
@@ -380,19 +432,35 @@ export function planOf(input, facts) {
|
|
|
380
432
|
invalid('select', 'a grouped query selects nothing');
|
|
381
433
|
if (!grouped && input.select === undefined)
|
|
382
434
|
invalid('select', 'a Document query must select');
|
|
383
|
-
known(input, [...FILTER, 'orderBy', 'limit', grouped ? 'groupBy' : 'select'], '');
|
|
435
|
+
known(input, [...FILTER, 'orderBy', 'limit', 'after', 'total', grouped ? 'groupBy' : 'select'], '');
|
|
384
436
|
const limit = limitOf(input.limit);
|
|
385
437
|
const rooms = input.rooms === undefined ? null : names(input.rooms, 'rooms');
|
|
386
438
|
const { typed, ...root } = scope(facts, rooms, input, '');
|
|
439
|
+
const shape = grouped ? groupShape(typed, input) : documentShape(typed, input);
|
|
387
440
|
return {
|
|
441
|
+
key: queryKey(input),
|
|
388
442
|
rooms,
|
|
443
|
+
reach,
|
|
389
444
|
root,
|
|
445
|
+
folder: input.folder === undefined ? null : directory(input.folder, 'folder'),
|
|
446
|
+
paths: input.paths === undefined ? null : pathsOf(input.paths),
|
|
390
447
|
hop: input.hop === undefined ? null : hopOf(facts, rooms, typed, input.hop),
|
|
391
448
|
backlinks: input.backlinks === undefined ? null : backlinksOf(facts, rooms, input.backlinks),
|
|
392
|
-
shape
|
|
449
|
+
shape,
|
|
393
450
|
limit,
|
|
451
|
+
after: continuationOf(input.after, shape.orderBy.length + 1),
|
|
452
|
+
total: flag(input.total, 'total'),
|
|
394
453
|
};
|
|
395
454
|
}
|
|
455
|
+
function continuationOf(input, arity) {
|
|
456
|
+
if (input === undefined)
|
|
457
|
+
return null;
|
|
458
|
+
const values = typeof input === 'string' ? decodedCursor(input) : null;
|
|
459
|
+
if (values === null || (values.length !== 0 && values.length !== arity)) {
|
|
460
|
+
invalid('after', 'expects the next an earlier result of this query returned');
|
|
461
|
+
}
|
|
462
|
+
return { text: input, values: values.length === 0 ? null : values };
|
|
463
|
+
}
|
|
396
464
|
export function limitOf(input) {
|
|
397
465
|
if (input === undefined)
|
|
398
466
|
return null;
|
|
@@ -401,11 +469,14 @@ export function limitOf(input) {
|
|
|
401
469
|
}
|
|
402
470
|
return input;
|
|
403
471
|
}
|
|
404
|
-
export function filterOf(input, facts) {
|
|
472
|
+
export function filterOf(input, facts, reach = null) {
|
|
405
473
|
if (!plain(input))
|
|
406
474
|
invalid('documents', 'expects a filter object');
|
|
407
475
|
known(input, FILTER, '');
|
|
408
|
-
return planOf({ ...input, select: {} }, facts);
|
|
476
|
+
return planOf({ ...input, select: {} }, facts, reach);
|
|
477
|
+
}
|
|
478
|
+
export function queryKey(query) {
|
|
479
|
+
return canonical(query);
|
|
409
480
|
}
|
|
410
481
|
function canonical(value) {
|
|
411
482
|
if (Array.isArray(value))
|
package/dist/reach.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReferrerScope } from './adapter.js';
|
|
2
|
+
import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
|
|
3
|
+
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
4
|
+
import type { Readiness } from './readiness.js';
|
|
5
|
+
import { type SearchResult } from './search.js';
|
|
6
|
+
export type ReachedDocument = {
|
|
7
|
+
readonly room: string;
|
|
8
|
+
readonly path: string;
|
|
9
|
+
};
|
|
10
|
+
export type PortReach = {
|
|
11
|
+
readonly rooms: readonly string[];
|
|
12
|
+
readonly documents: readonly ReachedDocument[];
|
|
13
|
+
readonly conversations: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type Deliver = (message: unknown) => void;
|
|
16
|
+
export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
|
|
17
|
+
export type RuntimeView = {
|
|
18
|
+
md: MdRuntime;
|
|
19
|
+
watch: Watch;
|
|
20
|
+
};
|
|
21
|
+
export type NarrowedView = RuntimeView & {
|
|
22
|
+
narrow(reach: PortReach | null): void;
|
|
23
|
+
facts(port: ReadinessPort): void;
|
|
24
|
+
};
|
|
25
|
+
export type Reachable = RuntimeView & {
|
|
26
|
+
plan(input: unknown, reach: PortReach | null): Plan;
|
|
27
|
+
query(plan: Plan): Promise<QueryResult>;
|
|
28
|
+
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
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;
|
|
32
|
+
};
|
|
33
|
+
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
34
|
+
export declare function governs(reach: PortReach | null, room: {
|
|
35
|
+
readonly locator: string;
|
|
36
|
+
readonly typedSelection: {
|
|
37
|
+
roots: readonly string[];
|
|
38
|
+
} | null;
|
|
39
|
+
}): {
|
|
40
|
+
readonly collection: boolean;
|
|
41
|
+
readonly selection: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
44
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
|
|
45
|
+
//# sourceMappingURL=reach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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