@agentshouse/mdruntime 0.1.0-cc7bd7a53214e → 0.1.0-ccbb89b0ca151
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 +187 -48
- 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 +44 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +223 -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 +159 -29
- 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 +765 -0
- package/dist/connection.d.ts +64 -25
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3926 -961
- package/dist/conversation.d.ts +54 -16
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +730 -243
- 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 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- 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 +136 -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 +19 -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 +124 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +195 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +207 -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 +73 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +79 -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 +71 -5
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +122 -40
- package/dist/reach.d.ts +17 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +251 -81
- 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 +39 -34
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +195 -81
- 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 +119 -58
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +362 -344
- package/dist/stored.d.ts +152 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +607 -0
- package/dist/tables.d.ts +352 -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 +174 -45
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +70 -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.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,8 @@ export type Select = 'all' | {
|
|
|
53
57
|
markdown?: true;
|
|
54
58
|
backlinks?: true;
|
|
55
59
|
change?: true;
|
|
60
|
+
fileId?: true;
|
|
61
|
+
revision?: true;
|
|
56
62
|
};
|
|
57
63
|
export type OrderOptions = {
|
|
58
64
|
nulls?: 'first' | 'last';
|
|
@@ -68,6 +74,8 @@ export type DocumentQuery = Filter & {
|
|
|
68
74
|
direction?: Direction;
|
|
69
75
|
} & OrderOptions)[];
|
|
70
76
|
limit?: number;
|
|
77
|
+
after?: string;
|
|
78
|
+
total?: true;
|
|
71
79
|
};
|
|
72
80
|
export type GroupQuery = Filter & {
|
|
73
81
|
groupBy: readonly Exclude<Key, 'path'>[];
|
|
@@ -76,6 +84,8 @@ export type GroupQuery = Filter & {
|
|
|
76
84
|
direction?: Direction;
|
|
77
85
|
}[];
|
|
78
86
|
limit?: number;
|
|
87
|
+
after?: string;
|
|
88
|
+
total?: true;
|
|
79
89
|
};
|
|
80
90
|
export type LocalQuery = DocumentQuery | GroupQuery;
|
|
81
91
|
export type Backlink = {
|
|
@@ -93,18 +103,50 @@ export type QueryDocument = {
|
|
|
93
103
|
markdown?: string;
|
|
94
104
|
backlinks?: readonly Backlink[];
|
|
95
105
|
change?: HeadChange | null;
|
|
106
|
+
fileId?: string | null;
|
|
107
|
+
revision?: string | null;
|
|
108
|
+
binaryFile?: BinaryFileRecord;
|
|
96
109
|
};
|
|
97
110
|
export type QueryGroup = {
|
|
98
111
|
key: readonly unknown[];
|
|
99
112
|
count: number;
|
|
100
113
|
};
|
|
101
|
-
export type
|
|
114
|
+
export type CoveredRoom = {
|
|
115
|
+
room: string;
|
|
116
|
+
generation: string;
|
|
117
|
+
current: boolean;
|
|
118
|
+
};
|
|
119
|
+
export type QueryCoverage = {
|
|
120
|
+
rooms: readonly CoveredRoom[];
|
|
121
|
+
indexes: readonly string[];
|
|
122
|
+
overlay: readonly string[];
|
|
123
|
+
};
|
|
124
|
+
export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
|
|
125
|
+
export type PendingRoom = {
|
|
126
|
+
room: string;
|
|
127
|
+
awaits: Awaits;
|
|
128
|
+
};
|
|
129
|
+
export type PendingResult = {
|
|
130
|
+
pending: readonly PendingRoom[];
|
|
131
|
+
};
|
|
132
|
+
export type DocumentRows = {
|
|
102
133
|
documents: readonly QueryDocument[];
|
|
134
|
+
next?: string;
|
|
135
|
+
total?: number;
|
|
103
136
|
};
|
|
104
|
-
export type
|
|
137
|
+
export type GroupRows = {
|
|
105
138
|
groups: readonly QueryGroup[];
|
|
139
|
+
next?: string;
|
|
140
|
+
total?: number;
|
|
141
|
+
};
|
|
142
|
+
export type QueryRows = DocumentRows | GroupRows;
|
|
143
|
+
export type DocumentResult = DocumentRows & {
|
|
144
|
+
coverage: QueryCoverage;
|
|
106
145
|
};
|
|
107
|
-
export type
|
|
146
|
+
export type GroupResult = GroupRows & {
|
|
147
|
+
coverage: QueryCoverage;
|
|
148
|
+
};
|
|
149
|
+
export type QueryResult = DocumentResult | GroupResult | PendingResult;
|
|
108
150
|
export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
|
|
109
151
|
export type RoomFacts = {
|
|
110
152
|
locator: string;
|
|
@@ -159,6 +201,8 @@ export type KeyPlan = {
|
|
|
159
201
|
of: 'path';
|
|
160
202
|
} | {
|
|
161
203
|
of: 'type';
|
|
204
|
+
} | {
|
|
205
|
+
of: 'folder';
|
|
162
206
|
} | {
|
|
163
207
|
of: 'field';
|
|
164
208
|
field: string;
|
|
@@ -171,6 +215,8 @@ export type DocumentShape = {
|
|
|
171
215
|
markdown: boolean;
|
|
172
216
|
backlinks: boolean;
|
|
173
217
|
change: boolean;
|
|
218
|
+
fileId: boolean;
|
|
219
|
+
revision: boolean;
|
|
174
220
|
orderBy: readonly {
|
|
175
221
|
key: KeyPlan;
|
|
176
222
|
options: OrderOptions & {
|
|
@@ -186,14 +232,28 @@ export type GroupShape = {
|
|
|
186
232
|
direction: Direction;
|
|
187
233
|
}[];
|
|
188
234
|
};
|
|
235
|
+
export type PlanArea = {
|
|
236
|
+
room: string;
|
|
237
|
+
path: string;
|
|
238
|
+
types: readonly string[];
|
|
239
|
+
};
|
|
189
240
|
export type PlanReach = {
|
|
190
241
|
rooms: readonly string[];
|
|
191
242
|
documents: readonly string[];
|
|
243
|
+
areas: readonly PlanArea[];
|
|
244
|
+
};
|
|
245
|
+
export type Continuation = {
|
|
246
|
+
text: string;
|
|
247
|
+
values: readonly unknown[] | null;
|
|
192
248
|
};
|
|
193
249
|
export type Plan = {
|
|
250
|
+
key: string;
|
|
194
251
|
rooms: readonly string[] | null;
|
|
195
252
|
reach: PlanReach | null;
|
|
253
|
+
locked: readonly string[];
|
|
196
254
|
root: Scope;
|
|
255
|
+
folder: string | null;
|
|
256
|
+
paths: readonly string[] | null;
|
|
197
257
|
hop: (Scope & {
|
|
198
258
|
field: string;
|
|
199
259
|
}) | null;
|
|
@@ -202,17 +262,23 @@ export type Plan = {
|
|
|
202
262
|
}) | null;
|
|
203
263
|
shape: DocumentShape | GroupShape;
|
|
204
264
|
limit: number | null;
|
|
265
|
+
after: Continuation | null;
|
|
266
|
+
total: boolean;
|
|
205
267
|
};
|
|
206
268
|
export declare class QueryError extends Error {
|
|
269
|
+
readonly code: QueryErrorCode;
|
|
270
|
+
readonly retryable = false;
|
|
207
271
|
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
208
272
|
}
|
|
209
273
|
type Entries = Readonly<Record<string, unknown>>;
|
|
210
274
|
export declare function invalid(at: string, problem: string): never;
|
|
211
275
|
export declare function plain(value: unknown): value is Entries;
|
|
212
276
|
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
277
|
+
export declare function flag(input: unknown, at: string): boolean;
|
|
213
278
|
export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
214
279
|
export declare function limitOf(input: unknown): number | null;
|
|
215
280
|
export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
281
|
+
export declare function queryKey(query: unknown): string;
|
|
216
282
|
export declare function identityOf(plan: Plan): string;
|
|
217
283
|
export {};
|
|
218
284
|
//# 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,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAItC,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAErD,MAAM,MAAM,SAAS,GACjB,KAAK,GACL;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GAC1B;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GAC1B;IAAE,KAAK,EAAE,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C,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAOtD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,QAI3E;AA6VD,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAIxD;AAmED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,IAAI,CA6B7F;AAWD,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMrD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,IAAI,CAI/F;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE/C;AAaD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C"}
|
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,13 +1,20 @@
|
|
|
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;
|
|
7
8
|
};
|
|
9
|
+
export type ReachedArea = {
|
|
10
|
+
readonly room: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly types: readonly string[];
|
|
13
|
+
};
|
|
8
14
|
export type PortReach = {
|
|
9
15
|
readonly rooms: readonly string[];
|
|
10
16
|
readonly documents: readonly ReachedDocument[];
|
|
17
|
+
readonly areas?: readonly ReachedArea[];
|
|
11
18
|
readonly conversations: boolean;
|
|
12
19
|
};
|
|
13
20
|
export type Deliver = (message: unknown) => void;
|
|
@@ -18,12 +25,18 @@ export type RuntimeView = {
|
|
|
18
25
|
};
|
|
19
26
|
export type NarrowedView = RuntimeView & {
|
|
20
27
|
narrow(reach: PortReach | null): void;
|
|
28
|
+
facts(port: ReadinessPort): void;
|
|
21
29
|
};
|
|
22
30
|
export type Reachable = RuntimeView & {
|
|
23
31
|
plan(input: unknown, reach: PortReach | null): Plan;
|
|
24
32
|
query(plan: Plan): Promise<QueryResult>;
|
|
25
33
|
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
26
|
-
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
34
|
+
search(input: unknown, reach: PortReach | null, locked: readonly string[]): Promise<SearchResult>;
|
|
35
|
+
watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
|
|
36
|
+
locked(room: string): boolean;
|
|
37
|
+
lockedRooms(): readonly string[];
|
|
38
|
+
watchLocks(notify: () => void): () => void;
|
|
39
|
+
located(room: string, path: string, destination: string): ReachedDocument | null;
|
|
27
40
|
};
|
|
28
41
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
29
42
|
export declare function governs(reach: PortReach | null, room: {
|
|
@@ -36,5 +49,5 @@ export declare function governs(reach: PortReach | null, room: {
|
|
|
36
49
|
readonly selection: boolean;
|
|
37
50
|
};
|
|
38
51
|
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
39
|
-
export declare function narrowed(runtime: Reachable, given: PortReach | null): NarrowedView;
|
|
52
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
|
|
40
53
|
//# 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;AAyBzB,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;AA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