@agentshouse/mdmodel 0.1.0-c4fe1bc82bc55 → 0.1.0-c520180b7a33f
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 +264 -250
- package/README.md +21 -22
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +35 -20
- package/dist/definition.d.ts +17 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +321 -45
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +27 -17
- package/dist/document.d.ts +6 -3
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +326 -171
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +230 -0
- package/dist/fields.d.ts +2 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +7 -0
- package/dist/index.d.ts +24 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -7
- package/dist/kinds.d.ts +19 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +161 -0
- package/dist/links.d.ts +3 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +108 -51
- package/dist/paths.d.ts +10 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +118 -12
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +355 -0
- package/dist/project.d.ts +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +38 -15
- package/dist/query/language.d.ts +223 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +565 -0
- package/dist/query/match.d.ts +14 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +121 -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/dist/references.d.ts +2 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- package/dist/reserved.d.ts +5 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +20 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +57 -6
- package/dist/types.d.ts +57 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +31 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +400 -115
- package/dist/yaml.d.ts +1 -2
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +75 -32
- package/fixtures/README.md +27 -7
- package/fixtures/cases/conditional-section/context.json +1 -0
- package/fixtures/cases/conditional-section/expected.json +6 -0
- package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
- package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
- package/fixtures/cases/conditional-section/schema.yaml +14 -0
- package/fixtures/cases/cross-room-link/context.json +1 -0
- package/fixtures/cases/cross-room-link/expected.json +1 -0
- package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
- package/fixtures/cases/cross-room-link/schema.yaml +3 -0
- package/fixtures/cases/cross-room-reference/context.json +1 -0
- package/fixtures/cases/cross-room-reference/expected.json +1 -0
- package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
- package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
- package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
- package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
- package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
- package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/context.json +1 -0
- package/fixtures/cases/member-on-another-type/expected.json +6 -0
- package/fixtures/cases/member-on-another-type/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
- package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
- package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
- package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
- package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
- package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
- package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
- package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
- package/fixtures/division.json +26 -26
- package/fixtures/queries.json +913 -0
- package/package.json +10 -3
- package/dist/condition.d.ts +0 -149
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -491
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1D,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC;AAEhG,K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,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA0EzE,wBAAgB,KAAK,CACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC,EACxD,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAClD,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,GAChD,aAAa,CAgBf;AAMD,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAYzD;AA4BD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAWhF;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAahE;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAS7E;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE,CAK7D;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAOnF;AA+BD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,GAAG,SAAS,CAiB9D"}
|
package/dist/event.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
2
|
+
import { dated, instant, kindOf } from './kinds.js';
|
|
3
|
+
import { roomPath, target } from './paths.js';
|
|
4
|
+
import { plain } from './yaml.js';
|
|
5
|
+
export const TEXT_FIELD = '/text';
|
|
6
|
+
export const WRITE_DOORS = ['browser', 'agent', 'client', 'function'];
|
|
7
|
+
const PROSE = { kind: 'prose' };
|
|
8
|
+
const NULL = { kind: 'null' };
|
|
9
|
+
const UNREADABLE = { kind: 'unreadable' };
|
|
10
|
+
function factKind(facts) {
|
|
11
|
+
const kind = kindOf(facts);
|
|
12
|
+
if (kind === 'integer')
|
|
13
|
+
return 'number';
|
|
14
|
+
if (kind === 'date-time')
|
|
15
|
+
return 'time';
|
|
16
|
+
if (kind === 'time')
|
|
17
|
+
return 'string';
|
|
18
|
+
return kind;
|
|
19
|
+
}
|
|
20
|
+
function scalar(value) {
|
|
21
|
+
return (typeof value === 'string' ||
|
|
22
|
+
typeof value === 'boolean' ||
|
|
23
|
+
(typeof value === 'number' && Number.isFinite(value)));
|
|
24
|
+
}
|
|
25
|
+
function fits(kind, facts, value) {
|
|
26
|
+
if (!scalar(value))
|
|
27
|
+
return false;
|
|
28
|
+
if (kind === 'enum')
|
|
29
|
+
return (facts.values ?? []).includes(value);
|
|
30
|
+
if (kind === 'number')
|
|
31
|
+
return typeof value === 'number';
|
|
32
|
+
if (kind === 'boolean')
|
|
33
|
+
return typeof value === 'boolean';
|
|
34
|
+
if (typeof value !== 'string')
|
|
35
|
+
return false;
|
|
36
|
+
if (kind === 'date')
|
|
37
|
+
return dated(value);
|
|
38
|
+
if (kind === 'time')
|
|
39
|
+
return instant(value) !== undefined;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
function factOf(value, declared, place) {
|
|
43
|
+
if (value === null)
|
|
44
|
+
return NULL;
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
if (declared?.type !== undefined && declared.type !== 'array')
|
|
47
|
+
return UNREADABLE;
|
|
48
|
+
return {
|
|
49
|
+
kind: 'list',
|
|
50
|
+
items: value.map((item, index) => factOf(item, declared === undefined ? undefined : itemFacts(declared, index), place)),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (plain(value)) {
|
|
54
|
+
if (declared?.type !== undefined && declared.type !== 'object')
|
|
55
|
+
return UNREADABLE;
|
|
56
|
+
const fields = Object.create(null);
|
|
57
|
+
for (const [key, held] of Object.entries(value))
|
|
58
|
+
fields[key] = factOf(held, declared === undefined ? undefined : memberFacts(declared, key), place);
|
|
59
|
+
return { kind: 'object', fields };
|
|
60
|
+
}
|
|
61
|
+
if (declared?.type === 'array' || declared?.type === 'object')
|
|
62
|
+
return UNREADABLE;
|
|
63
|
+
const kind = declared === undefined || declared.prose ? null : factKind(declared);
|
|
64
|
+
if (kind === null)
|
|
65
|
+
return PROSE;
|
|
66
|
+
if (!fits(kind, declared, value))
|
|
67
|
+
return UNREADABLE;
|
|
68
|
+
if (kind !== 'reference')
|
|
69
|
+
return { kind, value };
|
|
70
|
+
const reached = target(place.path, value) ?? roomPath(value);
|
|
71
|
+
const resolved = reached === null ? undefined : place.resolve(reached);
|
|
72
|
+
if (resolved === undefined)
|
|
73
|
+
return UNREADABLE;
|
|
74
|
+
return resolved.member === undefined
|
|
75
|
+
? { kind, value: resolved.id }
|
|
76
|
+
: { kind, value: resolved.id, member: resolved.member };
|
|
77
|
+
}
|
|
78
|
+
export function facts(document, at, model, resolve) {
|
|
79
|
+
const type = document.type ?? null;
|
|
80
|
+
const definition = type !== null && Object.hasOwn(model.types, type) ? model.types[type] : null;
|
|
81
|
+
const fields = Object.create(null);
|
|
82
|
+
const place = { path: at.path, resolve };
|
|
83
|
+
for (const [name, value] of Object.entries(document.fields)) {
|
|
84
|
+
const declared = definition === null ? undefined : fieldFacts(definition, name);
|
|
85
|
+
if (declared !== undefined)
|
|
86
|
+
fields[name] = factOf(value, declared, place);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
id: at.id,
|
|
90
|
+
path: `/${at.path}`,
|
|
91
|
+
type,
|
|
92
|
+
fields,
|
|
93
|
+
sections: Object.keys(document.sections).sort(),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function rootOf(facts, prefix) {
|
|
97
|
+
return { pointer: prefix, fact: { kind: 'object', fields: facts.fields } };
|
|
98
|
+
}
|
|
99
|
+
export function prosePaths(facts) {
|
|
100
|
+
const paths = facts.sections.map((heading) => `/sections/${heading}`);
|
|
101
|
+
const visit = ({ pointer, fact }) => {
|
|
102
|
+
if (fact.kind === 'prose')
|
|
103
|
+
paths.push(pointer);
|
|
104
|
+
if (fact.kind === 'list')
|
|
105
|
+
fact.items.forEach((item, index) => visit({ pointer: `${pointer}/${index}`, fact: item }));
|
|
106
|
+
if (fact.kind === 'object')
|
|
107
|
+
for (const [key, held] of Object.entries(fact.fields))
|
|
108
|
+
visit({ pointer: `${pointer}/${escapePointer(key)}`, fact: held });
|
|
109
|
+
};
|
|
110
|
+
visit(rootOf(facts, '/fields'));
|
|
111
|
+
return paths.sort();
|
|
112
|
+
}
|
|
113
|
+
function walked(start, pointer) {
|
|
114
|
+
let reached = [start];
|
|
115
|
+
for (const token of pointerSegments(pointer)) {
|
|
116
|
+
const step = ({ pointer: at, fact }) => {
|
|
117
|
+
if (fact.kind === 'object')
|
|
118
|
+
return Object.hasOwn(fact.fields, token)
|
|
119
|
+
? [{ pointer: `${at}/${escapePointer(token)}`, fact: fact.fields[token] }]
|
|
120
|
+
: [];
|
|
121
|
+
if (fact.kind !== 'list')
|
|
122
|
+
return [];
|
|
123
|
+
if (ARRAY_INDEX.test(token)) {
|
|
124
|
+
const item = fact.items[Number(token)];
|
|
125
|
+
return item === undefined ? [] : [{ pointer: `${at}/${token}`, fact: item }];
|
|
126
|
+
}
|
|
127
|
+
return fact.items
|
|
128
|
+
.map((item, index) => ({ pointer: `${at}/${index}`, fact: item }))
|
|
129
|
+
.flatMap(step);
|
|
130
|
+
};
|
|
131
|
+
reached = reached.flatMap(step);
|
|
132
|
+
}
|
|
133
|
+
return reached;
|
|
134
|
+
}
|
|
135
|
+
function expand(fact) {
|
|
136
|
+
return fact.kind === 'list' ? fact.items.flatMap(expand) : [fact];
|
|
137
|
+
}
|
|
138
|
+
export function members(document, path) {
|
|
139
|
+
if (!path.startsWith('/members/'))
|
|
140
|
+
return [];
|
|
141
|
+
return [
|
|
142
|
+
...new Set(walked(rootOf(document, '/members'), path.slice('/members'.length))
|
|
143
|
+
.flatMap(({ fact }) => expand(fact))
|
|
144
|
+
.flatMap((fact) => fact.kind === 'reference' && fact.member !== undefined ? [fact.member] : [])),
|
|
145
|
+
].sort();
|
|
146
|
+
}
|
|
147
|
+
export function pointed(value, pointer) {
|
|
148
|
+
let reached = value;
|
|
149
|
+
for (const token of pointerSegments(pointer)) {
|
|
150
|
+
if (Array.isArray(reached)) {
|
|
151
|
+
if (!ARRAY_INDEX.test(token))
|
|
152
|
+
return undefined;
|
|
153
|
+
reached = reached[Number(token)];
|
|
154
|
+
}
|
|
155
|
+
else if (plain(reached) && Object.hasOwn(reached, token)) {
|
|
156
|
+
reached = reached[token];
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return reached;
|
|
163
|
+
}
|
|
164
|
+
export function valuedChange(definition, pointer) {
|
|
165
|
+
const reached = pointerFacts(definition, pointer);
|
|
166
|
+
return (reached !== undefined &&
|
|
167
|
+
!reached.through &&
|
|
168
|
+
reached.facts.type !== 'array' &&
|
|
169
|
+
!reached.facts.prose &&
|
|
170
|
+
kindOf(reached.facts) !== null);
|
|
171
|
+
}
|
|
172
|
+
export function datePointers(definition) {
|
|
173
|
+
return Object.entries(definition.fields)
|
|
174
|
+
.filter(([, held]) => kindOf(held) === 'date')
|
|
175
|
+
.map(([name]) => `/${escapePointer(name)}`)
|
|
176
|
+
.sort();
|
|
177
|
+
}
|
|
178
|
+
export function memberPointers(definition, memberType) {
|
|
179
|
+
return Object.entries(definition.fields)
|
|
180
|
+
.filter(([, held]) => (held.type === 'array' ? held.items : held)?.reference?.includes(memberType) === true)
|
|
181
|
+
.map(([name]) => `/members/${escapePointer(name)}`);
|
|
182
|
+
}
|
|
183
|
+
function plainOf(fact) {
|
|
184
|
+
if (fact.kind === 'list')
|
|
185
|
+
return fact.items.map(plainOf);
|
|
186
|
+
if (fact.kind === 'object')
|
|
187
|
+
return Object.fromEntries(Object.entries(fact.fields).flatMap(([key, held]) => {
|
|
188
|
+
const value = plainOf(held);
|
|
189
|
+
return value === undefined ? [] : [[key, value]];
|
|
190
|
+
}));
|
|
191
|
+
if (fact.kind === 'prose')
|
|
192
|
+
return true;
|
|
193
|
+
if (fact.kind === 'null')
|
|
194
|
+
return null;
|
|
195
|
+
if (fact.kind === 'unreadable')
|
|
196
|
+
return undefined;
|
|
197
|
+
return fact.value;
|
|
198
|
+
}
|
|
199
|
+
function shapeOf(fact) {
|
|
200
|
+
if (fact.kind === 'list')
|
|
201
|
+
return { type: 'array', prose: false, prefix: fact.items.map(shapeOf) };
|
|
202
|
+
if (fact.kind === 'object')
|
|
203
|
+
return {
|
|
204
|
+
type: 'object',
|
|
205
|
+
prose: false,
|
|
206
|
+
properties: Object.fromEntries(Object.entries(fact.fields).map(([key, held]) => [key, shapeOf(held)])),
|
|
207
|
+
};
|
|
208
|
+
if (fact.kind === 'time')
|
|
209
|
+
return { type: 'string', format: 'date-time', prose: false };
|
|
210
|
+
return { prose: false };
|
|
211
|
+
}
|
|
212
|
+
export function candidateOf(document) {
|
|
213
|
+
const fields = {};
|
|
214
|
+
const properties = {};
|
|
215
|
+
for (const [name, fact] of Object.entries(document.fields)) {
|
|
216
|
+
const value = plainOf(fact);
|
|
217
|
+
if (value === undefined)
|
|
218
|
+
continue;
|
|
219
|
+
fields[name] = value;
|
|
220
|
+
properties[name] = shapeOf(fact);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
path: document.path.slice(1),
|
|
224
|
+
type: document.type,
|
|
225
|
+
fileId: document.id,
|
|
226
|
+
fields,
|
|
227
|
+
definition: { frontmatter: { type: 'object', prose: false, properties } },
|
|
228
|
+
text: null,
|
|
229
|
+
};
|
|
230
|
+
}
|
package/dist/fields.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export declare const TYPE_FIELD = "type";
|
|
1
2
|
export declare const MEMBER_FIELD = "member";
|
|
2
3
|
export declare const SITE_FIELD = "site";
|
|
3
4
|
export declare const RECEIVED_FIELD = "received";
|
|
5
|
+
export declare const HOUSE_FIELDS: readonly string[];
|
|
4
6
|
//# sourceMappingURL=fields.d.ts.map
|
package/dist/fields.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAKzC,CAAC"}
|
package/dist/fields.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { Actor,
|
|
1
|
+
export { candidateOf, datePointers, facts, memberPointers, members, pointed, prosePaths, TEXT_FIELD, valuedChange, WRITE_DOORS, } from './event.js';
|
|
2
|
+
export type { Actor, DocumentEvent, DocumentFacts, Fact, FactKind, ItemFacts, MessageFacts, Resolved, WriteDoor, } from './event.js';
|
|
3
|
+
export { byCodePoint, compared, dated, fitsKind, instant, instantKey, KINDS, kindOf, kindWords, } from './kinds.js';
|
|
4
|
+
export type { Kind, Ordering } from './kinds.js';
|
|
5
|
+
export { bodied, cursorOf, decodedCursor, identityOf, invalid, known, placeText, planOf, QueryError, queryKey, } from './query/language.js';
|
|
6
|
+
export type { Clause, Continuation, Direction, DocumentQuery, DocumentShape, Filter, GroupQuery, GroupShape, HeldRooms, Key, KeyPlan, LocalQuery, OrderOptions, Place, Predicate, QueryErrorCode, QueryPlan, Related, RoomFacts, Scope, Select, Test, Value, Where, } from './query/language.js';
|
|
7
|
+
export { heldAt, 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';
|
|
12
|
+
export { headingLines } from './blocks.js';
|
|
13
|
+
export type { HeadingLine } from './blocks.js';
|
|
3
14
|
export { divide } from './divide.js';
|
|
4
|
-
export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
5
|
-
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
6
|
-
export { relative, retarget, target } from './paths.js';
|
|
15
|
+
export { apply, bodyLinks, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
16
|
+
export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
17
|
+
export { relative, retarget, roomPath, roomTarget, target } from './paths.js';
|
|
18
|
+
export type { RoomTarget } from './paths.js';
|
|
7
19
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
8
20
|
export { project } from './project.js';
|
|
9
21
|
export { references } from './references.js';
|
|
10
|
-
export {
|
|
11
|
-
export
|
|
12
|
-
export type {
|
|
13
|
-
export {
|
|
22
|
+
export { isDocumentPath, isReservedName, RESERVED_NAMES, ROOM_DESCRIPTION } from './reserved.js';
|
|
23
|
+
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, JSON_POINTER, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
24
|
+
export type { Definition, FieldRules, JsonType, PatternFacts, PointerFacts, RuleValue, SectionSpec, Shape, Transition, ValueFacts, } from './definition.js';
|
|
25
|
+
export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, DocumentCheck, Frontmatter, FrontmatterResult, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Reached, Reference, Refusal, RoomReference, Span, TypedPath, Validation, ValidationContext, ValidationStep, VerifiedModel, } from './types.js';
|
|
26
|
+
export { assess, bodyRoomLinks, checkDocument, resolves, roomReferences, sectionReferences, validate, validating, verdicts, verify, } from './validate.js';
|
|
27
|
+
export type { Assessment, Verdicts } from './validate.js';
|
|
14
28
|
export { VERSION } from './version.js';
|
|
15
|
-
export { equalValue, frontmatterValue } from './yaml.js';
|
|
29
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue, plain } from './yaml.js';
|
|
16
30
|
export type { FrontmatterValue } from './yaml.js';
|
|
17
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,KAAK,EACL,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,KAAK,EACL,cAAc,EACd,OAAO,EACP,OAAO,EACP,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,KAAK,EACL,aAAa,EACb,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,KAAK,EACL,QAAQ,E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,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,12 +1,19 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { candidateOf, datePointers, facts, memberPointers, members, pointed, prosePaths, TEXT_FIELD, valuedChange, WRITE_DOORS, } from './event.js';
|
|
2
|
+
export { byCodePoint, compared, dated, fitsKind, instant, instantKey, KINDS, kindOf, kindWords, } from './kinds.js';
|
|
3
|
+
export { bodied, cursorOf, decodedCursor, identityOf, invalid, known, placeText, planOf, QueryError, queryKey, } from './query/language.js';
|
|
4
|
+
export { heldAt, matches } from './query/match.js';
|
|
5
|
+
export { heldKind, indexed } from './query/rows.js';
|
|
6
|
+
export * as sql from './query/sql.js';
|
|
7
|
+
export { headingLines } from './blocks.js';
|
|
2
8
|
export { divide } from './divide.js';
|
|
3
|
-
export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
4
|
-
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
5
|
-
export { relative, retarget, target } from './paths.js';
|
|
9
|
+
export { apply, bodyLinks, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
10
|
+
export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
11
|
+
export { relative, retarget, roomPath, roomTarget, target } from './paths.js';
|
|
6
12
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
7
13
|
export { project } from './project.js';
|
|
8
14
|
export { references } from './references.js';
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
15
|
+
export { isDocumentPath, isReservedName, RESERVED_NAMES, ROOM_DESCRIPTION } from './reserved.js';
|
|
16
|
+
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, JSON_POINTER, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
17
|
+
export { assess, bodyRoomLinks, checkDocument, resolves, roomReferences, sectionReferences, validate, validating, verdicts, verify, } from './validate.js';
|
|
11
18
|
export { VERSION } from './version.js';
|
|
12
|
-
export { equalValue, frontmatterValue } from './yaml.js';
|
|
19
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue, plain } from './yaml.js';
|
package/dist/kinds.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 kindWords(facts: ValueFacts | undefined): readonly string[];
|
|
14
|
+
export declare function dated(value: unknown): value is string;
|
|
15
|
+
export declare function instant(value: unknown): bigint | undefined;
|
|
16
|
+
export declare function instantKey(value: unknown): string | null;
|
|
17
|
+
export declare function byCodePoint(left: string, right: string): number;
|
|
18
|
+
export declare function compared(left: unknown, right: unknown, ordering: Ordering): number;
|
|
19
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","s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;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,161 @@
|
|
|
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 kindWords(facts) {
|
|
60
|
+
const kind = facts === undefined ? null : kindOf(facts);
|
|
61
|
+
if (kind === 'enum')
|
|
62
|
+
return (facts.values ?? []).map((value) => typeof value === 'string' ? value : JSON.stringify(value));
|
|
63
|
+
if (kind === 'number')
|
|
64
|
+
return ['a number'];
|
|
65
|
+
if (kind === 'integer')
|
|
66
|
+
return ['an integer'];
|
|
67
|
+
if (kind === 'boolean')
|
|
68
|
+
return ['true', 'false'];
|
|
69
|
+
if (kind === 'date')
|
|
70
|
+
return ['a date as YYYY-MM-DD'];
|
|
71
|
+
if (kind === 'date-time')
|
|
72
|
+
return ['a date-time with its offset, such as 2026-10-10T09:30:00Z'];
|
|
73
|
+
if (kind === 'time')
|
|
74
|
+
return ['a time as HH:MM:SS'];
|
|
75
|
+
if (kind === 'reference')
|
|
76
|
+
return [`the Room Path of a ${facts.reference.join(' or ')} document, such as notes/a.md`];
|
|
77
|
+
return kind === 'string' ? ['a string'] : [];
|
|
78
|
+
}
|
|
79
|
+
export function dated(value) {
|
|
80
|
+
return typeof value === 'string' && format.date(value);
|
|
81
|
+
}
|
|
82
|
+
export function instant(value) {
|
|
83
|
+
if (typeof value !== 'string' || !format['date-time'](value))
|
|
84
|
+
return undefined;
|
|
85
|
+
const parts = DATE_TIME.exec(value);
|
|
86
|
+
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
87
|
+
1, 2, 3, 4, 5, 6, 9, 10,
|
|
88
|
+
].map((at) => Number(parts[at] ?? 0));
|
|
89
|
+
const at = new Date(0);
|
|
90
|
+
at.setUTCFullYear(year, month - 1, day);
|
|
91
|
+
at.setUTCHours(hour, minute, second);
|
|
92
|
+
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
93
|
+
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
94
|
+
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
95
|
+
}
|
|
96
|
+
export function instantKey(value) {
|
|
97
|
+
const at = instant(value);
|
|
98
|
+
return at === undefined ? null : (at + BEFORE_YEAR_ZERO).toString().padStart(INSTANT_DIGITS, '0');
|
|
99
|
+
}
|
|
100
|
+
function rank(value) {
|
|
101
|
+
if (typeof value === 'boolean' || typeof value === 'number')
|
|
102
|
+
return 1;
|
|
103
|
+
if (typeof value === 'string')
|
|
104
|
+
return 2;
|
|
105
|
+
return Array.isArray(value) ? 3 : 4;
|
|
106
|
+
}
|
|
107
|
+
function unit(code) {
|
|
108
|
+
if (code >= 0xd800 && code < 0xe000)
|
|
109
|
+
return code + 0x2000;
|
|
110
|
+
return code >= 0xe000 ? code - 0x800 : code;
|
|
111
|
+
}
|
|
112
|
+
export function byCodePoint(left, right) {
|
|
113
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
114
|
+
const ours = left.charCodeAt(at);
|
|
115
|
+
const theirs = right.charCodeAt(at);
|
|
116
|
+
if (ours !== theirs)
|
|
117
|
+
return unit(ours) - unit(theirs);
|
|
118
|
+
}
|
|
119
|
+
return left.length - right.length;
|
|
120
|
+
}
|
|
121
|
+
function ascending(left, right, ordering) {
|
|
122
|
+
if (left == null && right == null)
|
|
123
|
+
return 0;
|
|
124
|
+
if (left == null)
|
|
125
|
+
return ordering.nulls === 'first' ? -1 : 1;
|
|
126
|
+
if (right == null)
|
|
127
|
+
return ordering.nulls === 'first' ? 1 : -1;
|
|
128
|
+
const ranked = rank(left) - rank(right);
|
|
129
|
+
if (ranked !== 0)
|
|
130
|
+
return ranked;
|
|
131
|
+
if (typeof left === 'string' && typeof right === 'string') {
|
|
132
|
+
return ordering.stringSort === 'locale'
|
|
133
|
+
? left.localeCompare(right, ordering.locale, ordering.localeOptions)
|
|
134
|
+
: byCodePoint(left, right);
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
137
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
138
|
+
const result = ascending(left[at], right[at], ordering);
|
|
139
|
+
if (result !== 0)
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
return left.length - right.length;
|
|
143
|
+
}
|
|
144
|
+
if (typeof left === 'object')
|
|
145
|
+
return 0;
|
|
146
|
+
const held = left;
|
|
147
|
+
const other = right;
|
|
148
|
+
if (held < other)
|
|
149
|
+
return -1;
|
|
150
|
+
if (held > other)
|
|
151
|
+
return 1;
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
export function compared(left, right, ordering) {
|
|
155
|
+
if (ordering.direction === 'asc')
|
|
156
|
+
return ascending(left, right, ordering);
|
|
157
|
+
return ascending(right, left, {
|
|
158
|
+
...ordering,
|
|
159
|
+
nulls: ordering.nulls === 'first' ? 'last' : 'first',
|
|
160
|
+
});
|
|
161
|
+
}
|
package/dist/links.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare function escapes(text: string, index: number): boolean;
|
|
2
|
+
export declare function spanCursor(spans: readonly (readonly [number, number])[]): (index: number) => number | undefined;
|
|
1
3
|
export type HrefOccurrence = {
|
|
2
4
|
readonly href: string;
|
|
3
5
|
readonly start: number;
|
|
@@ -22,5 +24,6 @@ export type LinkInventory = {
|
|
|
22
24
|
};
|
|
23
25
|
export declare function fenceSpans(text: string): readonly (readonly [number, number])[];
|
|
24
26
|
export declare function linkInventory(body: string): LinkInventory;
|
|
27
|
+
export declare function destinations(inventory: LinkInventory): readonly HrefOccurrence[];
|
|
25
28
|
export declare function hrefOccurrences(body: string): readonly HrefOccurrence[];
|
|
26
29
|
//# sourceMappingURL=links.d.ts.map
|
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAgiBA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D;AAyLD,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAC5C,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAOvC;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,Q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