@agentshouse/mdmodel 0.1.0-caf3d712ed842 → 0.1.0-cb304fd2c27f9
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/API.md +37 -2
- package/README.md +5 -3
- package/dist/condition.d.ts +2 -4
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +8 -43
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +141 -0
- package/dist/query/language.d.ts +218 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +526 -0
- package/dist/query/match.d.ts +12 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +118 -0
- package/dist/query/rows.d.ts +32 -0
- package/dist/query/rows.d.ts.map +1 -0
- package/dist/query/rows.js +161 -0
- package/dist/query/sql.d.ts +39 -0
- package/dist/query/sql.d.ts.map +1 -0
- package/dist/query/sql.js +279 -0
- package/fixtures/README.md +13 -0
- package/fixtures/queries.json +913 -0
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -307,6 +307,41 @@ divided out of one free-text field value addresses that whole value, because a Y
|
|
|
307
307
|
positions are the only ones its source has, and a Span carrying part of one internal link's label
|
|
308
308
|
addresses that whole link, because a cut never falls inside link syntax.
|
|
309
309
|
|
|
310
|
+
## Queries
|
|
311
|
+
|
|
312
|
+
`planOf(query, rooms)` checks one query against the MD Types of the Rooms `rooms` lists, each
|
|
313
|
+
`{ locator, available, types }` with `listed` when the list is whole, and answers its
|
|
314
|
+
`QueryPlan` or throws a `QueryError` whose `code` is `invalid-query`, `unknown-type`,
|
|
315
|
+
`unknown-field` or `wrong-kind` and whose message names where. A query is data: `types`, `where`
|
|
316
|
+
field predicates by JSON Pointer (`$eq`, `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`,
|
|
317
|
+
`$all`, `$size`, `$exists`, `$prefix`, `$and`, `$or`), `pathPrefix`, `folder`, `paths`,
|
|
318
|
+
`fileIds`, `hop`, `backlinks`, `text`, then `select` or `groupBy`, `orderBy`, `limit`, `after`
|
|
319
|
+
and `total`. `queryKey` and `identityOf` are a query's and a plan's canonical text, `bodied`
|
|
320
|
+
says a shape reads text, `cursorOf` and `decodedCursor` write and read the `after` a window
|
|
321
|
+
continues from, and `invalid`, `known` and `plain` are the check's refusal and tests.
|
|
322
|
+
|
|
323
|
+
`KINDS` is the one table of kinds a value compares as, `kindOf(facts)` a declared value's kind
|
|
324
|
+
and `fitsKind(kind, facts, value)` whether a value fits it: a `date`, `date-time` or `time` is
|
|
325
|
+
exactly what document validation admits as that format, a `date` is `dated`, a `date-time`
|
|
326
|
+
compares as the instant `instant` reads, which `instantKey` writes as text that sorts as the
|
|
327
|
+
instant does, and a `reference` as the Room Path it resolves to. `compared(left, right,
|
|
328
|
+
ordering)` orders plain values: numbers and booleans, then text by locale or `byCodePoint`,
|
|
329
|
+
then lists item by item.
|
|
330
|
+
|
|
331
|
+
Two evaluators answer a plan's tests on one Document alike, a test on a missing value false and
|
|
332
|
+
its negation (`$ne`, `$nin`, `$exists: false`) true. `matches(plan, candidate)` answers in
|
|
333
|
+
memory over one `Candidate`: its `path`, `type`, `fileId`, `fields`, `definition` and the
|
|
334
|
+
`text` held. The `sql` namespace compiles them to SQL over a collection: `indexed(path, fields,
|
|
335
|
+
definition)` derives a Document's values and field links, its date-times with their instants,
|
|
336
|
+
`sql.VALUE_TABLE` holds those values and `sql.insertedValues` writes them, and `sql.tests(alias,
|
|
337
|
+
plan)` tests a document row of `id`, `path`, `folder`, `type`, `file_id` and `content`, its
|
|
338
|
+
phrase through the function a connection registers as `sql.HOLDS_PHRASE` with `sql.holdsPhrase`.
|
|
339
|
+
`sql.scoped`, `sql.placed`, `sql.sorted`, `sql.beyond`, `sql.following` and `sql.sortValue`
|
|
340
|
+
render a scope, a pointer, an order and a window's continuation, a date-time ordering as its
|
|
341
|
+
instant between numbers and text; `sql.fragment`, `sql.joined`, `sql.all`, `sql.any`,
|
|
342
|
+
`sql.grouped`, `sql.listed` and `sql.exists` build statements, and `heldKind` is the index's value
|
|
343
|
+
kind. `fixtures/queries.json` holds both evaluators to one table.
|
|
344
|
+
|
|
310
345
|
## Conditions
|
|
311
346
|
|
|
312
347
|
`facts(document, { id, path }, model, resolve)` reads one Document as the `DocumentFacts` a
|
|
@@ -353,9 +388,9 @@ side never fires; `from: 'new'` admits only a creation and `to: 'deleted'` only
|
|
|
353
388
|
`itemFires(condition, item)` compares `source` and `address` where given and holds `match` over the
|
|
354
389
|
`ITEM_PATHS`, a `/json` test unknown for an item with no JSON; `notificationFires(condition, notification)`
|
|
355
390
|
holds `match`, where given, over a delivered notification's Document facts, and `messageFires(condition, message)`
|
|
356
|
-
over a message's `MessageFacts` at the `MESSAGE_PATHS`, a `/
|
|
391
|
+
over a message's `MessageFacts` at the `MESSAGE_PATHS`, a `/agent_function` or `/path` test unknown where its request names none.
|
|
357
392
|
`prosePaths(facts)` lists the prose and section paths whose text builds `changed`; `pointed(value, pointer)` reads a JSON Pointer,
|
|
358
|
-
`undefined` where nothing is; `dated(value)` checks a `YYYY-MM-DD` date, and `instant(value)` reads
|
|
393
|
+
`undefined` where nothing is; `dated(value)` checks a `YYYY-MM-DD` date, and `instant(value)` reads what validation admits as a `date-time` as epoch nanoseconds, a `bigint`.
|
|
359
394
|
|
|
360
395
|
What a condition names of one MD Type: `datePointers(fields)` lists, sorted, its date fields as escaped
|
|
361
396
|
`/fields/` pointers, the only `date`s a `DateCondition` takes; `changeFields(definition)` lists each
|
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# `@agentshouse/mdmodel`
|
|
2
2
|
|
|
3
|
-
Typed Markdown documents: MD Types declared in JSON Schema, a parser, a validator,
|
|
4
|
-
deterministic application of one structured change to a Document,
|
|
5
|
-
|
|
3
|
+
Typed Markdown documents: MD Types declared in JSON Schema, a parser, a validator, the
|
|
4
|
+
deterministic application of one structured change to a Document, and one query language
|
|
5
|
+
answered in SQL over a collection or in memory over one Document, plus a conformance
|
|
6
|
+
fixture corpus.
|
|
6
7
|
|
|
7
8
|
It runs in the browser and in Node, makes no network call, and reads no
|
|
8
9
|
filesystem on its own. It ships one ESM artifact that Node 24.22.1 and later
|
|
@@ -45,6 +46,7 @@ if (parsed.ok) {
|
|
|
45
46
|
| `escapePointer` | Write one key as a JSON Pointer token |
|
|
46
47
|
| `project`, `divide` | Embedding projection input and its division into Spans |
|
|
47
48
|
| `facts`, `factKind`, `holds`, `fires` | A condition over a Document and over one of its changes |
|
|
49
|
+
| `planOf`, `matches`, `sql` | Check a query, answer it over one Document or compile it to SQL |
|
|
48
50
|
| `MARKDOWN_SYNTAX_PROFILE`, `VERSION` | The pinned Markdown profile (GFM 0.29) and MD model version |
|
|
49
51
|
| `MEMBER_FIELD`, `SITE_FIELD`, `RECEIVED_FIELD` | The field names validation counts as declared beyond a type's own |
|
|
50
52
|
|
package/dist/condition.d.ts
CHANGED
|
@@ -140,7 +140,7 @@ export type ItemFacts = {
|
|
|
140
140
|
};
|
|
141
141
|
export type MessageFacts = {
|
|
142
142
|
readonly sender: string;
|
|
143
|
-
readonly
|
|
143
|
+
readonly agent_function: string | null;
|
|
144
144
|
readonly path: string | null;
|
|
145
145
|
};
|
|
146
146
|
export type Resolved = {
|
|
@@ -149,7 +149,7 @@ export type Resolved = {
|
|
|
149
149
|
};
|
|
150
150
|
type Truth = boolean | undefined;
|
|
151
151
|
export declare function factKind(facts: ValueFacts): FactKind | null;
|
|
152
|
-
export declare function facts(document: Document, at: {
|
|
152
|
+
export declare function facts(document: Pick<Document, 'type' | 'fields' | 'sections'>, at: {
|
|
153
153
|
readonly id: string;
|
|
154
154
|
readonly path: string;
|
|
155
155
|
}, model: VerifiedModel, resolve: (target: string) => Resolved | undefined): DocumentFacts;
|
|
@@ -167,8 +167,6 @@ export declare function actorOperators(path: string): readonly ConditionOperator
|
|
|
167
167
|
export declare function itemOperators(path: string): readonly ConditionOperator[];
|
|
168
168
|
export declare function messageOperators(path: string): readonly ConditionOperator[];
|
|
169
169
|
export declare function itemKind(path: string): FactKind | null;
|
|
170
|
-
export declare function dated(value: unknown): value is string;
|
|
171
|
-
export declare function instant(value: unknown): bigint | undefined;
|
|
172
170
|
export declare function pointed(value: unknown, pointer: string): unknown;
|
|
173
171
|
export declare function members(document: DocumentFacts, path: string): readonly string[];
|
|
174
172
|
export declare function holds(test: ConditionTest, document: DocumentFacts): Truth;
|
package/dist/condition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../src/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,UAAU,EAEf,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../src/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,UAAU,EAEf,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvD,eAAO,MAAM,mBAAmB,YAC9B,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,CACA,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,C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AAgB,OAAO,CACrB,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI,GAC3D,OAAO,CAKT;AA2ED,wBAAgB,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAiBjF;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAM5E;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,qBAAqB,EAChC,YAAY,EAAE,aAAa,GAC1B,OAAO,CAET;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAKxF"}
|
package/dist/condition.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
2
|
+
import { dated, instant, kindOf } from './kinds.js';
|
|
2
3
|
import { roomPath, target } from './paths.js';
|
|
3
4
|
import { plain } from './yaml.js';
|
|
4
5
|
export const CONDITION_OPERATORS = [
|
|
@@ -19,25 +20,16 @@ const NULL = { kind: 'null' };
|
|
|
19
20
|
const UNREADABLE = { kind: 'unreadable' };
|
|
20
21
|
const UNREAD = { present: undefined, values: [undefined], items: [undefined] };
|
|
21
22
|
const NO_ITEM = { present: false, values: [], items: [] };
|
|
22
|
-
const DATE = /^\d{4}-\d{2}-\d{2}$/u;
|
|
23
23
|
const HEADER = /^\/headers\/[!#$%&'*+.^_`|~0-9a-z-]+$/u;
|
|
24
|
-
const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/u;
|
|
25
24
|
export function factKind(facts) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (facts.values !== undefined)
|
|
29
|
-
return 'enum';
|
|
30
|
-
if (facts.type === 'number' || facts.type === 'integer')
|
|
25
|
+
const kind = kindOf(facts);
|
|
26
|
+
if (kind === 'integer')
|
|
31
27
|
return 'number';
|
|
32
|
-
if (
|
|
33
|
-
return 'boolean';
|
|
34
|
-
if (facts.type !== 'string')
|
|
35
|
-
return null;
|
|
36
|
-
if (facts.format === 'date')
|
|
37
|
-
return 'date';
|
|
38
|
-
if (facts.format === 'date-time')
|
|
28
|
+
if (kind === 'date-time')
|
|
39
29
|
return 'time';
|
|
40
|
-
|
|
30
|
+
if (kind === 'time')
|
|
31
|
+
return 'string';
|
|
32
|
+
return kind;
|
|
41
33
|
}
|
|
42
34
|
function fits(kind, facts, value) {
|
|
43
35
|
if (!scalar(value))
|
|
@@ -330,7 +322,7 @@ const ITEM_TESTS = [
|
|
|
330
322
|
];
|
|
331
323
|
const MESSAGE_TESTS = [
|
|
332
324
|
envelope('/sender', 'enum', (message) => message.sender),
|
|
333
|
-
envelope('/
|
|
325
|
+
envelope('/agent_function', 'string', (message) => message.agent_function),
|
|
334
326
|
envelope('/path', 'string', (message) => message.path),
|
|
335
327
|
];
|
|
336
328
|
export const DOCUMENT_PATHS = DOCUMENT_TESTS.map(({ path }) => path);
|
|
@@ -357,33 +349,6 @@ export function messageOperators(path) {
|
|
|
357
349
|
export function itemKind(path) {
|
|
358
350
|
return tested(ITEM_TESTS, path)?.kind ?? null;
|
|
359
351
|
}
|
|
360
|
-
export function dated(value) {
|
|
361
|
-
return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
|
|
362
|
-
}
|
|
363
|
-
export function instant(value) {
|
|
364
|
-
if (typeof value !== 'string')
|
|
365
|
-
return undefined;
|
|
366
|
-
const parts = DATE_TIME.exec(value);
|
|
367
|
-
if (parts === null)
|
|
368
|
-
return undefined;
|
|
369
|
-
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
370
|
-
1, 2, 3, 4, 5, 6, 9, 10,
|
|
371
|
-
].map((at) => Number(parts[at] ?? 0));
|
|
372
|
-
const at = new Date(0);
|
|
373
|
-
at.setUTCFullYear(year, month - 1, day);
|
|
374
|
-
at.setUTCHours(hour, minute, second);
|
|
375
|
-
if (at.getUTCFullYear() !== year ||
|
|
376
|
-
at.getUTCMonth() !== month - 1 ||
|
|
377
|
-
at.getUTCDate() !== day ||
|
|
378
|
-
at.getUTCHours() !== hour ||
|
|
379
|
-
at.getUTCMinutes() !== minute ||
|
|
380
|
-
offsetHours > 23 ||
|
|
381
|
-
offsetMinutes > 59)
|
|
382
|
-
return undefined;
|
|
383
|
-
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
384
|
-
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
385
|
-
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
386
|
-
}
|
|
387
352
|
export function pointed(value, pointer) {
|
|
388
353
|
let reached = value;
|
|
389
354
|
for (const token of pointerSegments(pointer)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
export { ACTOR_PATHS, actorOperators, changeFields, CONDITION_OPERATORS,
|
|
1
|
+
export { ACTOR_PATHS, actorOperators, changeFields, CONDITION_OPERATORS, datePointers, DOCUMENT_PATHS, factKind, facts, fires, holds, inScope, ITEM_PATHS, itemFires, itemKind, itemOperators, memberPointers, members, MESSAGE_PATHS, messageFires, messageOperators, notificationFires, pointed, prosePaths, testOperators, TEXT_FIELD, valuedChange, WRITE_DOORS, } from './condition.js';
|
|
2
2
|
export type { Actor, Condition, ConditionOperator, ConditionScope, ConditionTest, ConditionValue, CronCondition, DateCondition, DocumentCondition, DocumentEvent, DocumentFacts, Fact, FactKind, ItemCondition, ItemFacts, MessageCondition, MessageFacts, NotificationCondition, Resolved, WriteDoor, } from './condition.js';
|
|
3
|
+
export { byCodePoint, compared, dated, fitsKind, instant, instantKey, KINDS, kindOf, } from './kinds.js';
|
|
4
|
+
export type { Kind, Ordering } from './kinds.js';
|
|
5
|
+
export { bodied, cursorOf, decodedCursor, identityOf, invalid, known, planOf, QueryError, queryKey, } from './query/language.js';
|
|
6
|
+
export type { Clause, Continuation, Direction, DocumentQuery, DocumentShape, Filter, GroupQuery, GroupShape, HeldRooms, Key, KeyPlan, LocalQuery, OrderOptions, Predicate, QueryErrorCode, QueryPlan, Related, RoomFacts, Scope, Select, Test, Value, Where, } from './query/language.js';
|
|
7
|
+
export { matches } from './query/match.js';
|
|
8
|
+
export type { Candidate } from './query/match.js';
|
|
9
|
+
export { heldKind, indexed } from './query/rows.js';
|
|
10
|
+
export type { HeldKind, HeldLink, HeldValue, Indexed, Reach } from './query/rows.js';
|
|
11
|
+
export * as sql from './query/sql.js';
|
|
3
12
|
export { headingLines } from './blocks.js';
|
|
4
13
|
export type { HeadingLine } from './blocks.js';
|
|
5
14
|
export { divide } from './divide.js';
|
|
@@ -17,6 +26,6 @@ export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Docume
|
|
|
17
26
|
export { assess, bodyRoomLinks, checkDocument, resolves, roomReferences, sectionReferences, validate, validating, verdicts, verify, } from './validate.js';
|
|
18
27
|
export type { Assessment, Verdicts } from './validate.js';
|
|
19
28
|
export { VERSION } from './version.js';
|
|
20
|
-
export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
|
|
29
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue, plain } from './yaml.js';
|
|
21
30
|
export type { FrontmatterValue } from './yaml.js';
|
|
22
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,SAAS,EACT,QAAQ,EACR,aAAa,EACb,cAAc,EACd,OAAO,EACP,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACZ,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,KAAK,EACL,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,QAAQ,EACR,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,OAAO,EACP,UAAU,EACV,KAAK,EACL,MAAM,GACP,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,MAAM,EACN,QAAQ,EACR,aAAa,EACb,UAAU,EACV,OAAO,EACP,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,MAAM,EACN,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,MAAM,EACN,UAAU,EACV,UAAU,EACV,SAAS,EACT,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,EACT,OAAO,EACP,SAAS,EACT,KAAK,EACL,M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EACZ,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,KAAK,EACL,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,OAAO,EACP,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,MAAM,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACtF,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
export { ACTOR_PATHS, actorOperators, changeFields, CONDITION_OPERATORS,
|
|
1
|
+
export { ACTOR_PATHS, actorOperators, changeFields, CONDITION_OPERATORS, datePointers, DOCUMENT_PATHS, factKind, facts, fires, holds, inScope, ITEM_PATHS, itemFires, itemKind, itemOperators, memberPointers, members, MESSAGE_PATHS, messageFires, messageOperators, notificationFires, pointed, prosePaths, testOperators, TEXT_FIELD, valuedChange, WRITE_DOORS, } from './condition.js';
|
|
2
|
+
export { byCodePoint, compared, dated, fitsKind, instant, instantKey, KINDS, kindOf, } from './kinds.js';
|
|
3
|
+
export { bodied, cursorOf, decodedCursor, identityOf, invalid, known, planOf, QueryError, queryKey, } from './query/language.js';
|
|
4
|
+
export { matches } from './query/match.js';
|
|
5
|
+
export { heldKind, indexed } from './query/rows.js';
|
|
6
|
+
export * as sql from './query/sql.js';
|
|
2
7
|
export { headingLines } from './blocks.js';
|
|
3
8
|
export { divide } from './divide.js';
|
|
4
9
|
export { apply, bodyLinks, links, outline, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
@@ -11,4 +16,4 @@ export { isDocumentPath, isReservedName, RESERVED_NAMES, ROOM_DESCRIPTION } from
|
|
|
11
16
|
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, JSON_POINTER, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
12
17
|
export { assess, bodyRoomLinks, checkDocument, resolves, roomReferences, sectionReferences, validate, validating, verdicts, verify, } from './validate.js';
|
|
13
18
|
export { VERSION } from './version.js';
|
|
14
|
-
export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
|
|
19
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue, plain } from './yaml.js';
|
package/dist/kinds.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ValueFacts } from './definition.js';
|
|
2
|
+
export declare const KINDS: readonly ['string', 'number', 'integer', 'boolean', 'date', 'date-time', 'time', 'enum', 'reference'];
|
|
3
|
+
export type Kind = (typeof KINDS)[number];
|
|
4
|
+
export type Ordering = {
|
|
5
|
+
readonly direction: 'asc' | 'desc';
|
|
6
|
+
readonly nulls: 'first' | 'last';
|
|
7
|
+
readonly stringSort: 'lexical' | 'locale';
|
|
8
|
+
readonly locale: string | undefined;
|
|
9
|
+
readonly localeOptions: Intl.CollatorOptions | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare function kindOf(facts: ValueFacts): Kind | null;
|
|
12
|
+
export declare function fitsKind(kind: Kind, facts: ValueFacts, value: unknown): boolean;
|
|
13
|
+
export declare function dated(value: unknown): value is string;
|
|
14
|
+
export declare function instant(value: unknown): bigint | undefined;
|
|
15
|
+
export declare function instantKey(value: unknown): string | null;
|
|
16
|
+
export declare function byCodePoint(left: string, right: string): number;
|
|
17
|
+
export declare function compared(left: unknown, right: unknown, ordering: Ordering): number;
|
|
18
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,eAAO,MAAM,KAAK,YAChB,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,MAAM,EACN,WAAW,EACX,MAAM,EACN,MAAM,EACN,WAAW,CACH,CAAC;AAEX,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1C,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,SAAS,EAAE,KAAK,GAAG,MAAM,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;CAC1D,CAAC;AASF,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAWrD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAW/E;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAErD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAqB1D;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAGxD;AAaD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAO/D;AA4BD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAMlF"}
|
package/dist/kinds.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { format } from '@cfworker/json-schema';
|
|
2
|
+
import { normalize } from './paths.js';
|
|
3
|
+
export const KINDS = [
|
|
4
|
+
'string',
|
|
5
|
+
'number',
|
|
6
|
+
'integer',
|
|
7
|
+
'boolean',
|
|
8
|
+
'date',
|
|
9
|
+
'date-time',
|
|
10
|
+
'time',
|
|
11
|
+
'enum',
|
|
12
|
+
'reference',
|
|
13
|
+
];
|
|
14
|
+
const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt\s](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2})(?::?(\d{2}))?)$/u;
|
|
15
|
+
const BEFORE_YEAR_ZERO = 62200000000000000000n;
|
|
16
|
+
const INSTANT_DIGITS = 21;
|
|
17
|
+
export function kindOf(facts) {
|
|
18
|
+
if (facts.reference !== undefined)
|
|
19
|
+
return 'reference';
|
|
20
|
+
if (facts.values !== undefined)
|
|
21
|
+
return 'enum';
|
|
22
|
+
if (facts.type === 'number')
|
|
23
|
+
return 'number';
|
|
24
|
+
if (facts.type === 'integer')
|
|
25
|
+
return 'integer';
|
|
26
|
+
if (facts.type === 'boolean')
|
|
27
|
+
return 'boolean';
|
|
28
|
+
if (facts.type !== 'string')
|
|
29
|
+
return null;
|
|
30
|
+
if (facts.format === 'date')
|
|
31
|
+
return 'date';
|
|
32
|
+
if (facts.format === 'date-time')
|
|
33
|
+
return 'date-time';
|
|
34
|
+
if (facts.format === 'time')
|
|
35
|
+
return 'time';
|
|
36
|
+
return 'string';
|
|
37
|
+
}
|
|
38
|
+
export function fitsKind(kind, facts, value) {
|
|
39
|
+
if (kind === 'enum')
|
|
40
|
+
return (facts.values ?? []).includes(value);
|
|
41
|
+
if (kind === 'number')
|
|
42
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
43
|
+
if (kind === 'integer')
|
|
44
|
+
return Number.isSafeInteger(value);
|
|
45
|
+
if (kind === 'boolean')
|
|
46
|
+
return typeof value === 'boolean';
|
|
47
|
+
if (typeof value !== 'string')
|
|
48
|
+
return false;
|
|
49
|
+
if (kind === 'reference')
|
|
50
|
+
return value !== '' && normalize(value) === value;
|
|
51
|
+
if (kind === 'date')
|
|
52
|
+
return dated(value);
|
|
53
|
+
if (kind === 'date-time')
|
|
54
|
+
return instant(value) !== undefined;
|
|
55
|
+
if (kind === 'time')
|
|
56
|
+
return format.time(value);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
export function dated(value) {
|
|
60
|
+
return typeof value === 'string' && format.date(value);
|
|
61
|
+
}
|
|
62
|
+
export function instant(value) {
|
|
63
|
+
if (typeof value !== 'string' || !format['date-time'](value))
|
|
64
|
+
return undefined;
|
|
65
|
+
const parts = DATE_TIME.exec(value);
|
|
66
|
+
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
67
|
+
1, 2, 3, 4, 5, 6, 9, 10,
|
|
68
|
+
].map((at) => Number(parts[at] ?? 0));
|
|
69
|
+
const at = new Date(0);
|
|
70
|
+
at.setUTCFullYear(year, month - 1, day);
|
|
71
|
+
at.setUTCHours(hour, minute, second);
|
|
72
|
+
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
73
|
+
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
74
|
+
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
75
|
+
}
|
|
76
|
+
export function instantKey(value) {
|
|
77
|
+
const at = instant(value);
|
|
78
|
+
return at === undefined ? null : (at + BEFORE_YEAR_ZERO).toString().padStart(INSTANT_DIGITS, '0');
|
|
79
|
+
}
|
|
80
|
+
function rank(value) {
|
|
81
|
+
if (typeof value === 'boolean' || typeof value === 'number')
|
|
82
|
+
return 1;
|
|
83
|
+
if (typeof value === 'string')
|
|
84
|
+
return 2;
|
|
85
|
+
return Array.isArray(value) ? 3 : 4;
|
|
86
|
+
}
|
|
87
|
+
function unit(code) {
|
|
88
|
+
if (code >= 0xd800 && code < 0xe000)
|
|
89
|
+
return code + 0x2000;
|
|
90
|
+
return code >= 0xe000 ? code - 0x800 : code;
|
|
91
|
+
}
|
|
92
|
+
export function byCodePoint(left, right) {
|
|
93
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
94
|
+
const ours = left.charCodeAt(at);
|
|
95
|
+
const theirs = right.charCodeAt(at);
|
|
96
|
+
if (ours !== theirs)
|
|
97
|
+
return unit(ours) - unit(theirs);
|
|
98
|
+
}
|
|
99
|
+
return left.length - right.length;
|
|
100
|
+
}
|
|
101
|
+
function ascending(left, right, ordering) {
|
|
102
|
+
if (left == null && right == null)
|
|
103
|
+
return 0;
|
|
104
|
+
if (left == null)
|
|
105
|
+
return ordering.nulls === 'first' ? -1 : 1;
|
|
106
|
+
if (right == null)
|
|
107
|
+
return ordering.nulls === 'first' ? 1 : -1;
|
|
108
|
+
const ranked = rank(left) - rank(right);
|
|
109
|
+
if (ranked !== 0)
|
|
110
|
+
return ranked;
|
|
111
|
+
if (typeof left === 'string' && typeof right === 'string') {
|
|
112
|
+
return ordering.stringSort === 'locale'
|
|
113
|
+
? left.localeCompare(right, ordering.locale, ordering.localeOptions)
|
|
114
|
+
: byCodePoint(left, right);
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
117
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
118
|
+
const result = ascending(left[at], right[at], ordering);
|
|
119
|
+
if (result !== 0)
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
return left.length - right.length;
|
|
123
|
+
}
|
|
124
|
+
if (typeof left === 'object')
|
|
125
|
+
return 0;
|
|
126
|
+
const held = left;
|
|
127
|
+
const other = right;
|
|
128
|
+
if (held < other)
|
|
129
|
+
return -1;
|
|
130
|
+
if (held > other)
|
|
131
|
+
return 1;
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
export function compared(left, right, ordering) {
|
|
135
|
+
if (ordering.direction === 'asc')
|
|
136
|
+
return ascending(left, right, ordering);
|
|
137
|
+
return ascending(right, left, {
|
|
138
|
+
...ordering,
|
|
139
|
+
nulls: ordering.nulls === 'first' ? 'last' : 'first',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { type Definition } from '../definition.js';
|
|
2
|
+
export type Value = string | number | boolean | null;
|
|
3
|
+
export type Predicate = Value | {
|
|
4
|
+
$eq: Value;
|
|
5
|
+
} | {
|
|
6
|
+
$ne: Value;
|
|
7
|
+
} | {
|
|
8
|
+
$in: readonly Value[];
|
|
9
|
+
} | {
|
|
10
|
+
$nin: readonly Value[];
|
|
11
|
+
} | {
|
|
12
|
+
$gt?: Value;
|
|
13
|
+
$gte?: Value;
|
|
14
|
+
$lt?: Value;
|
|
15
|
+
$lte?: Value;
|
|
16
|
+
} | {
|
|
17
|
+
$all: readonly Value[];
|
|
18
|
+
} | {
|
|
19
|
+
$size: number;
|
|
20
|
+
} | {
|
|
21
|
+
$exists: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
$prefix: string;
|
|
24
|
+
};
|
|
25
|
+
export type Where = {
|
|
26
|
+
$and?: readonly Where[];
|
|
27
|
+
$or?: readonly Where[];
|
|
28
|
+
[field: string]: Predicate | readonly Where[] | undefined;
|
|
29
|
+
};
|
|
30
|
+
export type Related = {
|
|
31
|
+
types?: readonly string[];
|
|
32
|
+
where?: Where;
|
|
33
|
+
pathPrefix?: string;
|
|
34
|
+
};
|
|
35
|
+
export type Filter = {
|
|
36
|
+
rooms?: readonly string[];
|
|
37
|
+
types?: readonly string[];
|
|
38
|
+
where?: Where;
|
|
39
|
+
pathPrefix?: string;
|
|
40
|
+
folder?: string;
|
|
41
|
+
paths?: readonly string[];
|
|
42
|
+
fileIds?: readonly string[];
|
|
43
|
+
hop?: Related & {
|
|
44
|
+
field: string;
|
|
45
|
+
};
|
|
46
|
+
backlinks?: Related & {
|
|
47
|
+
field?: string;
|
|
48
|
+
};
|
|
49
|
+
text?: string;
|
|
50
|
+
};
|
|
51
|
+
export type Key = 'room' | 'path' | 'type' | 'folder' | {
|
|
52
|
+
field: string;
|
|
53
|
+
};
|
|
54
|
+
export type Select = 'all' | {
|
|
55
|
+
fields?: 'all' | readonly string[];
|
|
56
|
+
sections?: 'all' | readonly string[];
|
|
57
|
+
preamble?: true;
|
|
58
|
+
markdown?: true;
|
|
59
|
+
backlinks?: true;
|
|
60
|
+
change?: true;
|
|
61
|
+
fileId?: true;
|
|
62
|
+
revision?: true;
|
|
63
|
+
};
|
|
64
|
+
export type OrderOptions = {
|
|
65
|
+
nulls?: 'first' | 'last';
|
|
66
|
+
stringSort?: 'lexical' | 'locale';
|
|
67
|
+
locale?: string;
|
|
68
|
+
localeOptions?: Readonly<Record<string, unknown>>;
|
|
69
|
+
};
|
|
70
|
+
export type Direction = 'asc' | 'desc';
|
|
71
|
+
export type DocumentQuery = Filter & {
|
|
72
|
+
select: Select;
|
|
73
|
+
orderBy?: readonly ({
|
|
74
|
+
by: Key;
|
|
75
|
+
direction?: Direction;
|
|
76
|
+
} & OrderOptions)[];
|
|
77
|
+
limit?: number;
|
|
78
|
+
after?: string;
|
|
79
|
+
total?: true;
|
|
80
|
+
};
|
|
81
|
+
export type GroupQuery = Filter & {
|
|
82
|
+
groupBy: readonly Exclude<Key, 'path'>[];
|
|
83
|
+
orderBy?: readonly {
|
|
84
|
+
by: 'count' | Exclude<Key, 'path'>;
|
|
85
|
+
direction?: Direction;
|
|
86
|
+
}[];
|
|
87
|
+
limit?: number;
|
|
88
|
+
after?: string;
|
|
89
|
+
total?: true;
|
|
90
|
+
};
|
|
91
|
+
export type LocalQuery = DocumentQuery | GroupQuery;
|
|
92
|
+
export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
|
|
93
|
+
export type RoomFacts = {
|
|
94
|
+
locator: string;
|
|
95
|
+
available: boolean;
|
|
96
|
+
types: readonly Definition[];
|
|
97
|
+
};
|
|
98
|
+
export type HeldRooms = {
|
|
99
|
+
listed: boolean;
|
|
100
|
+
rooms: readonly RoomFacts[];
|
|
101
|
+
};
|
|
102
|
+
export type Test = {
|
|
103
|
+
op: 'eq';
|
|
104
|
+
value: Value;
|
|
105
|
+
} | {
|
|
106
|
+
op: 'ne';
|
|
107
|
+
value: Value;
|
|
108
|
+
} | {
|
|
109
|
+
op: 'in';
|
|
110
|
+
values: readonly Value[];
|
|
111
|
+
} | {
|
|
112
|
+
op: 'nin';
|
|
113
|
+
values: readonly Value[];
|
|
114
|
+
} | {
|
|
115
|
+
op: 'range';
|
|
116
|
+
bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
|
|
117
|
+
} | {
|
|
118
|
+
op: 'all';
|
|
119
|
+
values: readonly Value[];
|
|
120
|
+
} | {
|
|
121
|
+
op: 'size';
|
|
122
|
+
size: number;
|
|
123
|
+
} | {
|
|
124
|
+
op: 'exists';
|
|
125
|
+
exists: boolean;
|
|
126
|
+
} | {
|
|
127
|
+
op: 'prefix';
|
|
128
|
+
prefix: string;
|
|
129
|
+
};
|
|
130
|
+
export type Clause = {
|
|
131
|
+
every: readonly Clause[];
|
|
132
|
+
} | {
|
|
133
|
+
some: readonly Clause[];
|
|
134
|
+
} | {
|
|
135
|
+
field: string;
|
|
136
|
+
test: Test;
|
|
137
|
+
};
|
|
138
|
+
export type Scope = {
|
|
139
|
+
types: readonly string[] | null;
|
|
140
|
+
where: Clause | null;
|
|
141
|
+
pathPrefix: string | null;
|
|
142
|
+
};
|
|
143
|
+
export type KeyPlan = {
|
|
144
|
+
of: 'room';
|
|
145
|
+
} | {
|
|
146
|
+
of: 'path';
|
|
147
|
+
} | {
|
|
148
|
+
of: 'type';
|
|
149
|
+
} | {
|
|
150
|
+
of: 'folder';
|
|
151
|
+
} | {
|
|
152
|
+
of: 'field';
|
|
153
|
+
field: string;
|
|
154
|
+
};
|
|
155
|
+
export type DocumentShape = {
|
|
156
|
+
kind: 'documents';
|
|
157
|
+
fields: 'all' | readonly string[] | null;
|
|
158
|
+
sections: 'all' | readonly string[] | null;
|
|
159
|
+
preamble: boolean;
|
|
160
|
+
markdown: boolean;
|
|
161
|
+
backlinks: boolean;
|
|
162
|
+
change: boolean;
|
|
163
|
+
fileId: boolean;
|
|
164
|
+
revision: boolean;
|
|
165
|
+
orderBy: readonly {
|
|
166
|
+
key: KeyPlan;
|
|
167
|
+
options: OrderOptions & {
|
|
168
|
+
direction: Direction;
|
|
169
|
+
};
|
|
170
|
+
}[];
|
|
171
|
+
};
|
|
172
|
+
export type GroupShape = {
|
|
173
|
+
kind: 'groups';
|
|
174
|
+
groupBy: readonly KeyPlan[];
|
|
175
|
+
orderBy: readonly {
|
|
176
|
+
by: 'count' | number;
|
|
177
|
+
direction: Direction;
|
|
178
|
+
}[];
|
|
179
|
+
};
|
|
180
|
+
export type Continuation = {
|
|
181
|
+
text: string;
|
|
182
|
+
values: readonly unknown[] | null;
|
|
183
|
+
};
|
|
184
|
+
export type QueryPlan = {
|
|
185
|
+
key: string;
|
|
186
|
+
rooms: readonly string[] | null;
|
|
187
|
+
root: Scope;
|
|
188
|
+
folder: string | null;
|
|
189
|
+
paths: readonly string[] | null;
|
|
190
|
+
fileIds: readonly string[] | null;
|
|
191
|
+
hop: (Scope & {
|
|
192
|
+
field: string;
|
|
193
|
+
}) | null;
|
|
194
|
+
backlinks: (Scope & {
|
|
195
|
+
field: string | null;
|
|
196
|
+
}) | null;
|
|
197
|
+
text: string | null;
|
|
198
|
+
shape: DocumentShape | GroupShape;
|
|
199
|
+
limit: number | null;
|
|
200
|
+
after: Continuation | null;
|
|
201
|
+
total: boolean;
|
|
202
|
+
};
|
|
203
|
+
export declare class QueryError extends Error {
|
|
204
|
+
readonly code: QueryErrorCode;
|
|
205
|
+
readonly retryable = false;
|
|
206
|
+
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
207
|
+
}
|
|
208
|
+
type Entries = Readonly<Record<string, unknown>>;
|
|
209
|
+
export declare function bodied(shape: DocumentShape): boolean;
|
|
210
|
+
export declare function invalid(at: string, problem: string): never;
|
|
211
|
+
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
212
|
+
export declare function planOf(input: unknown, facts: HeldRooms): QueryPlan;
|
|
213
|
+
export declare function cursorOf(values: readonly unknown[]): string;
|
|
214
|
+
export declare function decodedCursor(text: string): readonly unknown[] | null;
|
|
215
|
+
export declare function queryKey(query: unknown): string;
|
|
216
|
+
export declare function identityOf(plan: QueryPlan): string;
|
|
217
|
+
export {};
|
|
218
|
+
//# sourceMappingURL=language.d.ts.map
|