@agentshouse/mdruntime 0.1.0-cefbc8bb8a1c0 → 0.1.0-cf1e7fdb9c600
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 +1 -1
- package/dist/adapter.d.ts +69 -49
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +5 -8
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +20 -21
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +6 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +0 -1
- package/dist/collection.d.ts +2 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +1 -17
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +97 -281
- package/dist/connection.d.ts +5 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +816 -846
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +15 -13
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +133 -142
- package/dist/durability.d.ts +0 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +14 -5
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +12 -26
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +10 -7
- package/dist/memory.d.ts +9 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +132 -81
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +1 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -12
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +7 -2
- package/dist/outcome.d.ts +0 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/query.d.ts +5 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/reach.d.ts +7 -7
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +31 -44
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +2 -15
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +46 -6
- package/dist/replica.d.ts +2 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/room-draft.d.ts +2 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +65 -52
- package/dist/rows.d.ts +3 -19
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +36 -164
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +0 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +15 -19
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +40 -39
- package/dist/stored.d.ts +33 -6
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +87 -124
- package/dist/tables.d.ts +34 -33
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +21 -54
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +39 -97
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +1 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +1 -1
- package/package.json +2 -2
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -91
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/room-draft.js
CHANGED
|
@@ -9,52 +9,60 @@ export function returnedBy(kind) {
|
|
|
9
9
|
export function staleWrite(current) {
|
|
10
10
|
return { outcome: 'stale', code: 'stale', retryable: false, current };
|
|
11
11
|
}
|
|
12
|
-
function malformed() {
|
|
13
|
-
throw runtimeError('room-draft-malformed');
|
|
12
|
+
function malformed(at, needs) {
|
|
13
|
+
throw runtimeError('room-draft-malformed', at === undefined ? 'room-draft-malformed' : `room-draft-malformed at ${at}: ${needs}`);
|
|
14
14
|
}
|
|
15
15
|
function plain(value) {
|
|
16
16
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
17
|
}
|
|
18
|
-
function text(value) {
|
|
19
|
-
return typeof value === 'string' ? value : malformed();
|
|
18
|
+
function text(value, at) {
|
|
19
|
+
return typeof value === 'string' ? value : malformed(at, 'text');
|
|
20
20
|
}
|
|
21
|
-
function optionalText(value) {
|
|
22
|
-
return value === undefined ? undefined : text(value);
|
|
21
|
+
function optionalText(value, at) {
|
|
22
|
+
return value === undefined ? undefined : text(value, at);
|
|
23
23
|
}
|
|
24
|
-
function markdownBase(value) {
|
|
25
|
-
return value === null ? null : optionalText(value);
|
|
24
|
+
function markdownBase(value, at) {
|
|
25
|
+
return value === null ? null : optionalText(value, at);
|
|
26
26
|
}
|
|
27
|
-
function entries(value, each) {
|
|
27
|
+
function entries(value, at, each) {
|
|
28
28
|
if (!plain(value))
|
|
29
|
-
malformed();
|
|
29
|
+
malformed(at, 'an object of named values');
|
|
30
30
|
const read = {};
|
|
31
31
|
for (const [name, item] of Object.entries(value))
|
|
32
|
-
read[name] = each(item);
|
|
32
|
+
read[name] = each(item, `${at}.${name}`);
|
|
33
33
|
return read;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function frontmatter(item, at) {
|
|
36
|
+
return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
|
|
37
|
+
}
|
|
38
|
+
function fieldValue(value, at) {
|
|
36
39
|
if (value === null)
|
|
37
40
|
return null;
|
|
38
41
|
if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
|
|
39
|
-
malformed();
|
|
42
|
+
malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
|
|
40
43
|
}
|
|
41
44
|
return { value: value.value };
|
|
42
45
|
}
|
|
43
|
-
function textPart(value) {
|
|
46
|
+
function textPart(value, at) {
|
|
44
47
|
if (!plain(value))
|
|
45
|
-
malformed();
|
|
46
|
-
const base = optionalText(value.base);
|
|
47
|
-
return { value: text(value.value), ...(base === undefined ? {} : { base }) };
|
|
48
|
+
malformed(at, '{ value, base }');
|
|
49
|
+
const base = optionalText(value.base, `${at}.base`);
|
|
50
|
+
return { value: text(value.value, `${at}.value`), ...(base === undefined ? {} : { base }) };
|
|
48
51
|
}
|
|
49
|
-
function creationOf(value) {
|
|
52
|
+
function creationOf(value, at) {
|
|
50
53
|
if (!plain(value))
|
|
51
|
-
malformed();
|
|
54
|
+
malformed(at, '{ type, fields, sections }, or { markdown }');
|
|
52
55
|
if (Object.hasOwn(value, 'markdown'))
|
|
53
|
-
return { markdown: text(value.markdown) };
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
return { markdown: text(value.markdown, `${at}.markdown`) };
|
|
57
|
+
if (typeof value.type !== 'string')
|
|
58
|
+
malformed(`${at}.type`, 'a type name, or markdown in place of type, fields and sections');
|
|
59
|
+
return {
|
|
60
|
+
type: value.type,
|
|
61
|
+
fields: entries(value.fields, `${at}.fields`, frontmatter),
|
|
62
|
+
sections: entries(value.sections, `${at}.sections`, text),
|
|
63
|
+
};
|
|
56
64
|
}
|
|
57
|
-
const PART_NAMES =
|
|
65
|
+
const PART_NAMES = [
|
|
58
66
|
'fields',
|
|
59
67
|
'sections',
|
|
60
68
|
'preamble',
|
|
@@ -63,52 +71,56 @@ const PART_NAMES = new Set([
|
|
|
63
71
|
'move',
|
|
64
72
|
'removal',
|
|
65
73
|
'file',
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
];
|
|
75
|
+
const NAMED_PARTS = `a part named ${PART_NAMES.slice(0, -1).join(', ')} or ${PART_NAMES.at(-1)}`;
|
|
76
|
+
export function readParts(value, path) {
|
|
77
|
+
if (!plain(value))
|
|
78
|
+
malformed(path, 'an object of parts');
|
|
79
|
+
const unknown = Object.keys(value).find((name) => !PART_NAMES.includes(name));
|
|
80
|
+
if (unknown !== undefined)
|
|
81
|
+
malformed(`${path} ${unknown}`, NAMED_PARTS);
|
|
70
82
|
const parts = {};
|
|
71
83
|
if (value.fields !== undefined) {
|
|
72
|
-
parts.fields = entries(value.fields, (item) => {
|
|
84
|
+
parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
|
|
73
85
|
if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
|
|
74
|
-
malformed();
|
|
86
|
+
malformed(at, '{ value, base } with a frontmatter value');
|
|
75
87
|
}
|
|
76
88
|
return item.base === undefined
|
|
77
89
|
? { value: item.value }
|
|
78
|
-
: { value: item.value, base: fieldValue(item.base) };
|
|
90
|
+
: { value: item.value, base: fieldValue(item.base, `${at}.base`) };
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
93
|
if (value.sections !== undefined)
|
|
82
|
-
parts.sections = entries(value.sections, textPart);
|
|
94
|
+
parts.sections = entries(value.sections, `${path} sections`, textPart);
|
|
83
95
|
if (value.preamble !== undefined)
|
|
84
|
-
parts.preamble = textPart(value.preamble);
|
|
96
|
+
parts.preamble = textPart(value.preamble, `${path} preamble`);
|
|
85
97
|
if (value.markdown !== undefined)
|
|
86
|
-
parts.markdown = textPart(value.markdown);
|
|
98
|
+
parts.markdown = textPart(value.markdown, `${path} markdown`);
|
|
87
99
|
if (value.creation !== undefined)
|
|
88
|
-
parts.creation = creationOf(value.creation);
|
|
100
|
+
parts.creation = creationOf(value.creation, `${path} creation`);
|
|
89
101
|
if (value.move !== undefined) {
|
|
90
102
|
if (!plain(value.move))
|
|
91
|
-
malformed();
|
|
92
|
-
const base = markdownBase(value.move.base);
|
|
93
|
-
const room = optionalText(value.move.room);
|
|
103
|
+
malformed(`${path} move`, '{ to, room, base }');
|
|
104
|
+
const base = markdownBase(value.move.base, `${path} move.base`);
|
|
105
|
+
const room = optionalText(value.move.room, `${path} move.room`);
|
|
94
106
|
parts.move = {
|
|
95
|
-
to: text(value.move.to),
|
|
107
|
+
to: text(value.move.to, `${path} move.to`),
|
|
96
108
|
...(room === undefined ? {} : { room }),
|
|
97
109
|
...(base === undefined ? {} : { base }),
|
|
98
110
|
};
|
|
99
111
|
}
|
|
100
112
|
if (value.removal !== undefined) {
|
|
101
113
|
if (!plain(value.removal))
|
|
102
|
-
malformed();
|
|
103
|
-
const base = markdownBase(value.removal.base);
|
|
114
|
+
malformed(`${path} removal`, '{ base }');
|
|
115
|
+
const base = markdownBase(value.removal.base, `${path} removal.base`);
|
|
104
116
|
parts.removal = base === undefined ? {} : { base };
|
|
105
117
|
}
|
|
106
118
|
if (value.file !== undefined) {
|
|
107
119
|
if (!plain(value.file) || !(value.file.blob instanceof Blob))
|
|
108
|
-
malformed();
|
|
120
|
+
malformed(`${path} file`, '{ blob, base } with a Blob');
|
|
109
121
|
if (Object.keys(value).length > 1)
|
|
110
122
|
throw runtimeError('room-draft-file-exclusive');
|
|
111
|
-
const base = markdownBase(value.file.base);
|
|
123
|
+
const base = markdownBase(value.file.base, `${path} file.base`);
|
|
112
124
|
parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
|
|
113
125
|
}
|
|
114
126
|
return parts;
|
|
@@ -318,7 +330,7 @@ function joined(existing, returned) {
|
|
|
318
330
|
merged[name] = part;
|
|
319
331
|
return Object.keys(merged).length === 0 ? undefined : merged;
|
|
320
332
|
}
|
|
321
|
-
function
|
|
333
|
+
export function lineEnded(text) {
|
|
322
334
|
return text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
323
335
|
}
|
|
324
336
|
function frontmatterOf(fields) {
|
|
@@ -342,7 +354,7 @@ export function partsAfter(markdown, parts) {
|
|
|
342
354
|
];
|
|
343
355
|
if (pieces.length === 0)
|
|
344
356
|
return markdown;
|
|
345
|
-
return `${
|
|
357
|
+
return `${lineEnded(markdown)}\n${pieces.map(lineEnded).join('')}`;
|
|
346
358
|
}
|
|
347
359
|
export function returnedInto(existing, returned) {
|
|
348
360
|
if (existing === undefined)
|
|
@@ -386,12 +398,13 @@ export function moveTarget(move) {
|
|
|
386
398
|
return to === null || to === '' ? move.to : to;
|
|
387
399
|
}
|
|
388
400
|
export function readSavedParts(named) {
|
|
389
|
-
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts) }));
|
|
390
|
-
|
|
391
|
-
normalize(path) !== path
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
401
|
+
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts, path) }));
|
|
402
|
+
read.forEach(({ path }, at) => {
|
|
403
|
+
if (path === '' || normalize(path) !== path)
|
|
404
|
+
malformed(path, 'a path inside the Room, such as notes/a.md');
|
|
405
|
+
if (read.findIndex((one) => one.path === path) !== at)
|
|
406
|
+
malformed(path, 'each path once in one save');
|
|
407
|
+
});
|
|
395
408
|
return read;
|
|
396
409
|
}
|
|
397
410
|
export function partsChanges(named) {
|
|
@@ -433,11 +446,11 @@ export function changesOf(path, parts) {
|
|
|
433
446
|
bases.push({ kind: 'field', path, name, value: part.base?.value });
|
|
434
447
|
}
|
|
435
448
|
for (const [name, part] of named(parts.sections)) {
|
|
436
|
-
changes.push({ kind: 'section', path, name, value: part.value });
|
|
449
|
+
changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
|
|
437
450
|
bases.push({ kind: 'section', path, name, value: part.base });
|
|
438
451
|
}
|
|
439
452
|
if (parts.preamble !== undefined) {
|
|
440
|
-
changes.push({ kind: 'preamble', path, value: parts.preamble.value });
|
|
453
|
+
changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
|
|
441
454
|
bases.push({ kind: 'preamble', path, value: parts.preamble.base });
|
|
442
455
|
}
|
|
443
456
|
if (parts.markdown !== undefined) {
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
+
import { type HeldValue, type Outline } from '@agentshouse/mdmodel';
|
|
1
2
|
import { type Composition } from './collection.js';
|
|
2
|
-
export type ValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'undefined';
|
|
3
|
-
type HeldValue = {
|
|
4
|
-
readonly keys: string;
|
|
5
|
-
readonly places: string;
|
|
6
|
-
readonly item: number;
|
|
7
|
-
readonly kind: ValueKind;
|
|
8
|
-
readonly value: string | number | null;
|
|
9
|
-
readonly size: number | null;
|
|
10
|
-
};
|
|
11
3
|
type LinkKind = 'field' | 'section' | 'body';
|
|
12
4
|
type HeldLink = {
|
|
13
5
|
readonly kind: LinkKind;
|
|
@@ -32,15 +24,7 @@ export declare function roomOfKey(key: string): string;
|
|
|
32
24
|
export declare function pathOfKey(key: string): string;
|
|
33
25
|
export declare function markdownPath(path: string): boolean;
|
|
34
26
|
export declare function folderOf(path: string): string;
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
readonly keys: string;
|
|
38
|
-
readonly places: string;
|
|
39
|
-
readonly glob: boolean;
|
|
40
|
-
};
|
|
41
|
-
export declare function placedOf(pointer: string, reach: Reach): Placed;
|
|
42
|
-
export declare function kindOf(value: unknown): ValueKind;
|
|
43
|
-
export declare function described(path: string, content: string | null): Described;
|
|
44
|
-
export declare function derived(path: string, content: string | null, composition: Composition): Derived;
|
|
27
|
+
export declare function described(path: string, content: string | null, outlined: Outline | null): Described;
|
|
28
|
+
export declare function derived(path: string, content: string | null, outlined: Outline | null, composition: Composition): Derived;
|
|
45
29
|
export {};
|
|
46
30
|
//# sourceMappingURL=rows.d.ts.map
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,OAAO,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7C,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CACrC,CAAC;AAMF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AA4ED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,QAAQ,EAAE,OAAO,GAAG,IAAI,GACvB,SAAS,CAEX;AAED,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,QAAQ,EAAE,OAAO,GAAG,IAAI,EACxB,WAAW,EAAE,WAAW,GACvB,OAAO,CAOT"}
|
package/dist/rows.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { indexed, outline, sectionReferences, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { governing } from './collection.js';
|
|
3
3
|
import { definitionOf } from './model.js';
|
|
4
4
|
function keyOf(...parts) {
|
|
@@ -19,155 +19,14 @@ export function markdownPath(path) {
|
|
|
19
19
|
export function folderOf(path) {
|
|
20
20
|
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const keys = [first];
|
|
25
|
-
const gaps = [[]];
|
|
26
|
-
for (const segment of rest) {
|
|
27
|
-
if (ARRAY_INDEX.test(segment)) {
|
|
28
|
-
gaps.at(-1).push(segment);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
keys.push(segment);
|
|
32
|
-
gaps.push([]);
|
|
33
|
-
}
|
|
34
|
-
const places = gaps
|
|
35
|
-
.map((gap, at) => {
|
|
36
|
-
const open = at < gaps.length - 1 ? reach !== 'exact' : reach === 'link';
|
|
37
|
-
return `/${gap.map((number) => `[.:]${number}`).join('')}.${open ? '*' : ''}`;
|
|
38
|
-
})
|
|
39
|
-
.join('');
|
|
40
|
-
return {
|
|
41
|
-
keys: keys.map((key) => `/${key}`).join(''),
|
|
42
|
-
places,
|
|
43
|
-
glob: /[[*]/u.test(places),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function placesOf({ done, head, tail }) {
|
|
47
|
-
return `${done}/${head}${tail}.`;
|
|
48
|
-
}
|
|
49
|
-
function throughOf(keys, places) {
|
|
50
|
-
const gaps = places.split('/').slice(1);
|
|
51
|
-
return keys
|
|
52
|
-
.split('/')
|
|
53
|
-
.slice(1)
|
|
54
|
-
.map((key, at) => `/${key}${gaps[at].replace(/\.\d*/gu, '').replaceAll(':', '/')}`)
|
|
55
|
-
.join('');
|
|
56
|
-
}
|
|
57
|
-
function plainObject(value) {
|
|
58
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
59
|
-
}
|
|
60
|
-
function compared(reading, exact, value) {
|
|
61
|
-
if (!reading.references.has(exact))
|
|
62
|
-
return value;
|
|
63
|
-
return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
|
|
64
|
-
}
|
|
65
|
-
export function kindOf(value) {
|
|
66
|
-
if (value === undefined)
|
|
67
|
-
return 'undefined';
|
|
68
|
-
if (value === null)
|
|
69
|
-
return 'null';
|
|
70
|
-
if (Array.isArray(value))
|
|
71
|
-
return 'array';
|
|
72
|
-
if (typeof value === 'object')
|
|
73
|
-
return 'object';
|
|
74
|
-
return typeof value;
|
|
75
|
-
}
|
|
76
|
-
function scalarOf(value) {
|
|
77
|
-
if (typeof value === 'string' || typeof value === 'number')
|
|
78
|
-
return value;
|
|
79
|
-
if (typeof value === 'boolean')
|
|
80
|
-
return value ? 1 : 0;
|
|
81
|
-
if (Array.isArray(value))
|
|
82
|
-
return JSON.stringify(value);
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
function held(reading, keys, places, value) {
|
|
86
|
-
reading.values.push({
|
|
87
|
-
keys,
|
|
88
|
-
places,
|
|
89
|
-
item: -1,
|
|
90
|
-
kind: kindOf(value),
|
|
91
|
-
value: scalarOf(value),
|
|
92
|
-
size: Array.isArray(value) ? value.length : null,
|
|
93
|
-
});
|
|
94
|
-
if (!Array.isArray(value))
|
|
95
|
-
return;
|
|
96
|
-
value.forEach((item, index) => {
|
|
97
|
-
const itemKind = kindOf(item);
|
|
98
|
-
reading.values.push({
|
|
99
|
-
keys,
|
|
100
|
-
places,
|
|
101
|
-
item: index,
|
|
102
|
-
kind: itemKind,
|
|
103
|
-
value: itemKind === 'array' ? null : scalarOf(item),
|
|
104
|
-
size: null,
|
|
105
|
-
});
|
|
106
|
-
});
|
|
22
|
+
function bodyOf(targets) {
|
|
23
|
+
return targets.map((target) => ({ kind: 'body', keys: '', places: '', target, field: '' }));
|
|
107
24
|
}
|
|
108
|
-
function
|
|
109
|
-
const value = Array.isArray(node)
|
|
110
|
-
? node.map((item, index) => compared(reading, `${at.exact}/${index}`, item))
|
|
111
|
-
: compared(reading, at.exact, node);
|
|
112
|
-
const places = placesOf(at);
|
|
113
|
-
held(reading, at.keys, places, value);
|
|
114
|
-
if (typeof value !== 'string' || !reading.references.has(at.exact))
|
|
115
|
-
return;
|
|
116
|
-
reading.links.push({
|
|
117
|
-
kind: 'field',
|
|
118
|
-
keys: at.keys,
|
|
119
|
-
places,
|
|
120
|
-
target: value,
|
|
121
|
-
field: throughOf(at.keys, places),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
function walk(reading, node, at) {
|
|
125
|
-
record(reading, node, at);
|
|
126
|
-
if (Array.isArray(node)) {
|
|
127
|
-
node.forEach((item, index) => walk(reading, item, { ...at, tail: `${at.tail}.${index}`, exact: `${at.exact}/${index}` }));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (!plainObject(node))
|
|
131
|
-
return;
|
|
132
|
-
for (const [key, value] of Object.entries(node)) {
|
|
133
|
-
const segment = escapePointer(key);
|
|
134
|
-
const exact = `${at.exact}/${segment}`;
|
|
135
|
-
walk(reading, value, ARRAY_INDEX.test(segment)
|
|
136
|
-
? { ...at, head: `${at.head}${at.tail.replaceAll('.', ':')}:${segment}`, tail: '', exact }
|
|
137
|
-
: { keys: `${at.keys}/${segment}`, done: placesOf(at), head: '', tail: '', exact });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function bodyTargets(path, content) {
|
|
141
|
-
const seen = new Set();
|
|
142
|
-
const found = [];
|
|
143
|
-
for (const { target: reached } of bodyLinks(bodyAfterFrontmatter(content), path)) {
|
|
144
|
-
if (seen.has(reached))
|
|
145
|
-
continue;
|
|
146
|
-
seen.add(reached);
|
|
147
|
-
found.push({ kind: 'body', keys: '', places: '', target: reached, field: '' });
|
|
148
|
-
}
|
|
149
|
-
return found;
|
|
150
|
-
}
|
|
151
|
-
function typedRows(path, content, document, composition) {
|
|
25
|
+
function typedRows(path, content, document, composition, body) {
|
|
152
26
|
const definition = definitionOf(governing(composition, path), document.type);
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
values: [],
|
|
157
|
-
links: [],
|
|
158
|
-
};
|
|
159
|
-
for (const [name, value] of Object.entries(document.fields)) {
|
|
160
|
-
const segment = escapePointer(name);
|
|
161
|
-
walk(reading, value, {
|
|
162
|
-
keys: `/${segment}`,
|
|
163
|
-
done: '',
|
|
164
|
-
head: '',
|
|
165
|
-
tail: '',
|
|
166
|
-
exact: `/${segment}`,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
const links = reading.links;
|
|
170
|
-
if (definition !== undefined) {
|
|
27
|
+
const { values, links: fields } = indexed(path, document.fields, definition);
|
|
28
|
+
const links = [...fields];
|
|
29
|
+
if (definition !== undefined && content !== null) {
|
|
171
30
|
const sectioned = new Set();
|
|
172
31
|
for (const { target: reached } of sectionReferences(path, content, definition)) {
|
|
173
32
|
if (reached === null || sectioned.has(reached))
|
|
@@ -176,20 +35,14 @@ function typedRows(path, content, document, composition) {
|
|
|
176
35
|
links.push({ kind: 'section', keys: '', places: '', target: reached, field: '' });
|
|
177
36
|
}
|
|
178
37
|
}
|
|
179
|
-
return { values
|
|
38
|
+
return { values, links: [...links, ...body] };
|
|
180
39
|
}
|
|
181
|
-
function
|
|
40
|
+
function readOf(path, declared, document) {
|
|
182
41
|
const folder = folderOf(path);
|
|
183
42
|
const unread = { fields: null, folder, type: null };
|
|
184
|
-
if (
|
|
185
|
-
return { described: { ...unread, declared: null, queried: true }, document: null };
|
|
186
|
-
}
|
|
187
|
-
const parsed = parseFrontmatter(content, path);
|
|
188
|
-
const declared = parsed.ok ? (parsed.frontmatter.type ?? 'any') : null;
|
|
189
|
-
if (!markdownPath(path) || !parsed.ok) {
|
|
43
|
+
if (!markdownPath(path) || document === null) {
|
|
190
44
|
return { described: { ...unread, declared, queried: !markdownPath(path) }, document: null };
|
|
191
45
|
}
|
|
192
|
-
const document = parsed.frontmatter;
|
|
193
46
|
return {
|
|
194
47
|
described: {
|
|
195
48
|
type: document.type ?? 'any',
|
|
@@ -201,14 +54,33 @@ function read(path, content) {
|
|
|
201
54
|
document,
|
|
202
55
|
};
|
|
203
56
|
}
|
|
204
|
-
|
|
205
|
-
|
|
57
|
+
function read(path, content, outlined) {
|
|
58
|
+
const held = content === null ? outlined : outline(content, path);
|
|
59
|
+
if (held === null) {
|
|
60
|
+
return {
|
|
61
|
+
described: {
|
|
62
|
+
fields: null,
|
|
63
|
+
folder: folderOf(path),
|
|
64
|
+
type: null,
|
|
65
|
+
declared: null,
|
|
66
|
+
queried: true,
|
|
67
|
+
},
|
|
68
|
+
document: null,
|
|
69
|
+
links: [],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const type = held.type === null || held.type === 'any' ? undefined : held.type;
|
|
73
|
+
const document = held.fields === null ? null : { type, fields: held.fields };
|
|
74
|
+
return { ...readOf(path, held.type, document), links: held.links };
|
|
75
|
+
}
|
|
76
|
+
export function described(path, content, outlined) {
|
|
77
|
+
return read(path, content, outlined).described;
|
|
206
78
|
}
|
|
207
|
-
export function derived(path, content, composition) {
|
|
208
|
-
const { described: columns, document } = read(path, content);
|
|
79
|
+
export function derived(path, content, outlined, composition) {
|
|
80
|
+
const { described: columns, document, links } = read(path, content, outlined);
|
|
81
|
+
const body = bodyOf(links);
|
|
209
82
|
if (document !== null) {
|
|
210
|
-
return { ...columns, ...typedRows(path, content, document, composition) };
|
|
83
|
+
return { ...columns, ...typedRows(path, content, document, composition, body) };
|
|
211
84
|
}
|
|
212
|
-
|
|
213
|
-
return { ...columns, values: [], links };
|
|
85
|
+
return { ...columns, values: [], links: markdownPath(path) ? [] : body };
|
|
214
86
|
}
|
package/dist/search.d.ts
CHANGED
|
@@ -1,73 +1,22 @@
|
|
|
1
|
-
import type { ProviderRefusal } from './adapter.js';
|
|
2
|
-
import
|
|
3
|
-
import type { Open } from './open.js';
|
|
4
|
-
export type DocumentPart = Open<'fields' | 'sections' | 'preamble' | 'path'>;
|
|
1
|
+
import type { ProviderRefusal, SearchHit } from './adapter.js';
|
|
2
|
+
import type { Failure, Offline } from './outcome.js';
|
|
5
3
|
export type SearchRequest = {
|
|
6
4
|
text: string;
|
|
7
|
-
|
|
8
|
-
collection?: true;
|
|
9
|
-
conversations?: readonly string[];
|
|
10
|
-
limit?: number;
|
|
11
|
-
after?: string;
|
|
12
|
-
total?: true;
|
|
5
|
+
rooms?: readonly string[];
|
|
13
6
|
};
|
|
14
|
-
export type
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
at: readonly [number, number];
|
|
19
|
-
};
|
|
20
|
-
export type DocumentHit = {
|
|
21
|
-
room: string;
|
|
22
|
-
path: string;
|
|
23
|
-
type: string;
|
|
24
|
-
score: number;
|
|
25
|
-
matches: Readonly<Record<string, readonly DocumentPart[]>>;
|
|
26
|
-
snippet?: Snippet<DocumentPart>;
|
|
27
|
-
};
|
|
28
|
-
export type MessageHit = {
|
|
29
|
-
conversation: string;
|
|
30
|
-
identity: string;
|
|
31
|
-
score: number;
|
|
32
|
-
matches: Readonly<Record<string, readonly MessagePart[]>>;
|
|
33
|
-
snippet?: Snippet<MessagePart>;
|
|
34
|
-
};
|
|
35
|
-
export type SearchCoverage = {
|
|
36
|
-
rooms: readonly CoveredRoom[];
|
|
37
|
-
conversations: readonly string[];
|
|
38
|
-
overlay: readonly string[];
|
|
7
|
+
export type { SearchHit } from './adapter.js';
|
|
8
|
+
export type SearchFound = {
|
|
9
|
+
kind: 'found';
|
|
10
|
+
documents: readonly SearchHit[];
|
|
39
11
|
};
|
|
40
|
-
export type
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
export type SearchWindow = SearchHits & {
|
|
45
|
-
next?: string;
|
|
46
|
-
total?: {
|
|
47
|
-
documents: number;
|
|
48
|
-
messages: number;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
export type SearchPending = SearchHits & {
|
|
52
|
-
pending: readonly PendingRoom[];
|
|
53
|
-
coverage: SearchCoverage;
|
|
54
|
-
};
|
|
55
|
-
export type SearchUndeclared = ProviderRefusal & {
|
|
12
|
+
export type SearchResult = SearchFound | Offline | (ProviderRefusal & {
|
|
13
|
+
kind: 'rejected';
|
|
14
|
+
}) | (ProviderRefusal & {
|
|
56
15
|
kind: 'undeclared';
|
|
57
|
-
};
|
|
58
|
-
export type SearchResult = (SearchWindow & {
|
|
59
|
-
coverage: SearchCoverage;
|
|
60
|
-
}) | SearchPending | SearchUndeclared;
|
|
61
|
-
export declare function undeclaredSearch(): SearchUndeclared;
|
|
62
|
-
export type HitCursor = readonly [number, string, string] | readonly [] | null;
|
|
16
|
+
}) | Failure;
|
|
63
17
|
export type SearchPlan = {
|
|
64
18
|
text: string;
|
|
65
|
-
|
|
66
|
-
collection: boolean;
|
|
67
|
-
conversations: readonly string[] | null;
|
|
68
|
-
limit: number | null;
|
|
69
|
-
after: readonly [HitCursor, HitCursor] | null;
|
|
70
|
-
total: boolean;
|
|
19
|
+
rooms: readonly string[] | null;
|
|
71
20
|
};
|
|
72
21
|
export declare function searchPlanOf(input: unknown): SearchPlan;
|
|
73
22
|
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAExE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,OAAO,GACP,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GACxC,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,GAC1C,OAAO,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAYvD"}
|
package/dist/search.js
CHANGED
|
@@ -1,57 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { decodedCursor } from './windows.js';
|
|
3
|
-
export function undeclaredSearch() {
|
|
4
|
-
return {
|
|
5
|
-
kind: 'undeclared',
|
|
6
|
-
code: 'search-undeclared',
|
|
7
|
-
fields: { name: 'local_search' },
|
|
8
|
-
retryable: false,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function hitCursor(input) {
|
|
12
|
-
if (input === null)
|
|
13
|
-
return null;
|
|
14
|
-
if (!Array.isArray(input))
|
|
15
|
-
return undefined;
|
|
16
|
-
if (input.length === 0)
|
|
17
|
-
return [];
|
|
18
|
-
const [score, first, second] = input;
|
|
19
|
-
return input.length === 3 &&
|
|
20
|
-
typeof score === 'number' &&
|
|
21
|
-
typeof first === 'string' &&
|
|
22
|
-
typeof second === 'string'
|
|
23
|
-
? [score, first, second]
|
|
24
|
-
: undefined;
|
|
25
|
-
}
|
|
26
|
-
function searchAfter(input) {
|
|
27
|
-
if (input === undefined)
|
|
28
|
-
return null;
|
|
29
|
-
const decoded = typeof input === 'string' ? decodedCursor(input) : null;
|
|
30
|
-
const documents = decoded?.length === 2 ? hitCursor(decoded[0]) : undefined;
|
|
31
|
-
const messages = decoded?.length === 2 ? hitCursor(decoded[1]) : undefined;
|
|
32
|
-
if (documents === undefined || messages === undefined) {
|
|
33
|
-
invalid('after', 'expects the next an earlier search returned');
|
|
34
|
-
}
|
|
35
|
-
return [documents, messages];
|
|
36
|
-
}
|
|
1
|
+
import { invalid, known, plain } from '@agentshouse/mdmodel';
|
|
37
2
|
export function searchPlanOf(input) {
|
|
38
3
|
if (!plain(input))
|
|
39
4
|
invalid('search', 'expects a search object');
|
|
40
|
-
known(input, ['text', '
|
|
41
|
-
if (typeof input.text !== 'string')
|
|
42
|
-
invalid('text', 'expects
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
(!Array.isArray(
|
|
46
|
-
invalid('
|
|
5
|
+
known(input, ['text', 'rooms'], '');
|
|
6
|
+
if (typeof input.text !== 'string' || input.text.trim() === '')
|
|
7
|
+
invalid('text', 'expects words');
|
|
8
|
+
const rooms = input.rooms;
|
|
9
|
+
if (rooms !== undefined &&
|
|
10
|
+
(!Array.isArray(rooms) || rooms.some((named) => typeof named !== 'string'))) {
|
|
11
|
+
invalid('rooms', 'expects a list of Rooms');
|
|
47
12
|
}
|
|
48
|
-
return {
|
|
49
|
-
text: input.text,
|
|
50
|
-
documents: input.documents,
|
|
51
|
-
collection: flag(input.collection, 'collection'),
|
|
52
|
-
conversations: conversations ?? null,
|
|
53
|
-
limit: limitOf(input.limit),
|
|
54
|
-
after: searchAfter(input.after),
|
|
55
|
-
total: flag(input.total, 'total'),
|
|
56
|
-
};
|
|
13
|
+
return { text: input.text, rooms: rooms ?? null };
|
|
57
14
|
}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export type Paths<V> = Readonly<Record<string, V>>;
|
|
2
2
|
export declare function entriesIn<V>(map: Paths<V>): Generator<readonly [string, V]>;
|
|
3
|
-
export declare function keysIn(...maps: readonly Paths<unknown>[]): Generator<number, Set<string>, void>;
|
|
4
3
|
export declare function sortedKeys(map: Paths<unknown>): Generator<number, readonly string[], void>;
|
|
5
4
|
export declare function sorting(keys: Iterable<string>): Generator<number, readonly string[], void>;
|
|
6
5
|
export declare function sharing<V>(map: Paths<V>): Generator<number, Paths<V>, void>;
|