@agentshouse/mdmodel 0.1.0-cbce4f1da228f → 0.1.0-cc58fdf3541b7
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 +152 -142
- package/README.md +16 -19
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +29 -7
- package/dist/condition.d.ts +42 -10
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +220 -87
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +105 -21
- package/dist/divide.js +9 -9
- package/dist/document.d.ts +6 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +309 -187
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +85 -39
- package/dist/paths.d.ts +9 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +28 -2
- 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.map +1 -1
- package/dist/project.js +7 -7
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +55 -4
- package/dist/types.d.ts +32 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +27 -4
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +225 -70
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +36 -3
- package/fixtures/README.md +9 -4
- 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/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/division.json +26 -26
- package/package.json +7 -2
package/dist/condition.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type ValueFacts } from './definition.js';
|
|
1
|
+
import { type Definition, type ValueFacts } from './definition.js';
|
|
2
2
|
import type { Document, VerifiedModel } from './types.js';
|
|
3
|
-
export type ConditionValue = string | number | boolean
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export type ConditionValue = string | number | boolean;
|
|
4
|
+
export declare const CONDITION_OPERATORS: readonly ['eq', 'in', 'exists', 'contains', 'gt', 'gte', 'lt', 'lte', 'prefix'];
|
|
5
|
+
export type ConditionOperator = (typeof CONDITION_OPERATORS)[number];
|
|
6
6
|
export type ConditionTest = {
|
|
7
7
|
readonly all: readonly ConditionTest[];
|
|
8
8
|
} | {
|
|
@@ -41,6 +41,7 @@ type DocumentEventBase = {
|
|
|
41
41
|
readonly on: 'documents';
|
|
42
42
|
readonly scope: ConditionScope;
|
|
43
43
|
readonly by?: ConditionTest;
|
|
44
|
+
readonly moved_between_rooms?: boolean;
|
|
44
45
|
};
|
|
45
46
|
export type DocumentCondition = (DocumentEventBase & {
|
|
46
47
|
readonly mode: 'starts_matching';
|
|
@@ -75,7 +76,15 @@ export type DateCondition = {
|
|
|
75
76
|
readonly time_zone: string;
|
|
76
77
|
readonly match?: ConditionTest;
|
|
77
78
|
};
|
|
78
|
-
export type
|
|
79
|
+
export type NotificationCondition = {
|
|
80
|
+
readonly on: 'notifications';
|
|
81
|
+
readonly match?: ConditionTest;
|
|
82
|
+
};
|
|
83
|
+
export type MessageCondition = {
|
|
84
|
+
readonly on: 'messages';
|
|
85
|
+
readonly match?: ConditionTest;
|
|
86
|
+
};
|
|
87
|
+
export type Condition = DocumentCondition | ItemCondition | CronCondition | DateCondition | NotificationCondition | MessageCondition;
|
|
79
88
|
export type FactKind = 'string' | 'number' | 'boolean' | 'date' | 'time' | 'enum' | 'reference';
|
|
80
89
|
type Scalar = string | number | boolean;
|
|
81
90
|
export type Fact = {
|
|
@@ -102,11 +111,13 @@ export type DocumentFacts = {
|
|
|
102
111
|
readonly fields: Readonly<Record<string, Fact>>;
|
|
103
112
|
readonly sections: readonly string[];
|
|
104
113
|
};
|
|
105
|
-
export declare const
|
|
114
|
+
export declare const TEXT_FIELD = "/text";
|
|
115
|
+
export declare const WRITE_DOORS: readonly ['browser', 'agent', 'client', 'function'];
|
|
106
116
|
export type WriteDoor = (typeof WRITE_DOORS)[number];
|
|
107
117
|
export type Actor = {
|
|
108
118
|
readonly user?: string;
|
|
109
119
|
readonly site?: string;
|
|
120
|
+
readonly app?: string;
|
|
110
121
|
readonly door?: WriteDoor;
|
|
111
122
|
};
|
|
112
123
|
export type DocumentEvent = {
|
|
@@ -114,12 +125,12 @@ export type DocumentEvent = {
|
|
|
114
125
|
readonly after: DocumentFacts | null;
|
|
115
126
|
readonly changed: readonly string[];
|
|
116
127
|
readonly by: Actor;
|
|
128
|
+
readonly moved_between_rooms: boolean;
|
|
117
129
|
};
|
|
118
130
|
export type ItemFacts = {
|
|
119
131
|
readonly delivery: string;
|
|
120
132
|
readonly source: string | null;
|
|
121
133
|
readonly address: string | null;
|
|
122
|
-
readonly has_attachment: boolean;
|
|
123
134
|
readonly container: string | null;
|
|
124
135
|
readonly author: string | null;
|
|
125
136
|
readonly headers: Readonly<Record<string, string>>;
|
|
@@ -127,6 +138,11 @@ export type ItemFacts = {
|
|
|
127
138
|
readonly value: unknown;
|
|
128
139
|
} | null;
|
|
129
140
|
};
|
|
141
|
+
export type MessageFacts = {
|
|
142
|
+
readonly sender: string;
|
|
143
|
+
readonly routine: string | null;
|
|
144
|
+
readonly path: string | null;
|
|
145
|
+
};
|
|
130
146
|
export type Resolved = {
|
|
131
147
|
readonly id: string;
|
|
132
148
|
readonly member?: string;
|
|
@@ -139,11 +155,27 @@ export declare function facts(document: Document, at: {
|
|
|
139
155
|
}, model: VerifiedModel, resolve: (target: string) => Resolved | undefined): DocumentFacts;
|
|
140
156
|
export declare function prosePaths(facts: DocumentFacts): string[];
|
|
141
157
|
export declare function datePointers(fields: Readonly<Record<string, ValueFacts>>): string[];
|
|
158
|
+
export declare function valuedChange(definition: Definition, field: string): boolean;
|
|
159
|
+
export declare function changeFields(definition: Definition): string[];
|
|
160
|
+
export declare function memberPointers(definition: Definition, memberType: string): string[];
|
|
161
|
+
export declare const DOCUMENT_PATHS: readonly string[];
|
|
162
|
+
export declare const ACTOR_PATHS: readonly string[];
|
|
163
|
+
export declare const ITEM_PATHS: readonly string[];
|
|
164
|
+
export declare const MESSAGE_PATHS: readonly string[];
|
|
165
|
+
export declare function testOperators(definitions: readonly Definition[], path: string, memberType: string | null): readonly ConditionOperator[];
|
|
166
|
+
export declare function actorOperators(path: string): readonly ConditionOperator[];
|
|
167
|
+
export declare function itemOperators(path: string): readonly ConditionOperator[];
|
|
168
|
+
export declare function messageOperators(path: string): readonly ConditionOperator[];
|
|
169
|
+
export declare function itemKind(path: string): FactKind | null;
|
|
142
170
|
export declare function dated(value: unknown): value is string;
|
|
143
171
|
export declare function instant(value: unknown): bigint | undefined;
|
|
144
172
|
export declare function pointed(value: unknown, pointer: string): unknown;
|
|
145
|
-
export declare function
|
|
146
|
-
export declare function
|
|
147
|
-
export declare function
|
|
173
|
+
export declare function members(document: DocumentFacts, path: string): readonly string[];
|
|
174
|
+
export declare function holds(test: ConditionTest, document: DocumentFacts): Truth;
|
|
175
|
+
export declare function inScope(scope: ConditionScope, document: Pick<DocumentFacts, 'id' | 'path' | 'type'> | null): boolean;
|
|
176
|
+
export declare function fires(condition: DocumentCondition, event: DocumentEvent): boolean;
|
|
177
|
+
export declare function itemFires(condition: ItemCondition, item: ItemFacts): boolean;
|
|
178
|
+
export declare function notificationFires(condition: NotificationCondition, notification: DocumentFacts): boolean;
|
|
179
|
+
export declare function messageFires(condition: MessageCondition, message: MessageFacts): boolean;
|
|
148
180
|
export {};
|
|
149
181
|
//# sourceMappingURL=condition.d.ts.map
|
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,
|
|
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;AAEzB,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;CAA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BAAgB,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAahF;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,GAAG,KAAK,CAEzE;AAED,wBAAgB,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,13 +1,26 @@
|
|
|
1
|
-
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerSegments, } from './definition.js';
|
|
2
|
-
import { target } from './paths.js';
|
|
3
|
-
import {
|
|
4
|
-
export const
|
|
1
|
+
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
|
|
2
|
+
import { roomPath, target } from './paths.js';
|
|
3
|
+
import { plain } from './yaml.js';
|
|
4
|
+
export const CONDITION_OPERATORS = [
|
|
5
|
+
'eq',
|
|
6
|
+
'in',
|
|
7
|
+
'exists',
|
|
8
|
+
'contains',
|
|
9
|
+
'gt',
|
|
10
|
+
'gte',
|
|
11
|
+
'lt',
|
|
12
|
+
'lte',
|
|
13
|
+
'prefix',
|
|
14
|
+
];
|
|
15
|
+
export const TEXT_FIELD = '/text';
|
|
16
|
+
export const WRITE_DOORS = ['browser', 'agent', 'client', 'function'];
|
|
5
17
|
const PROSE = { kind: 'prose' };
|
|
6
18
|
const NULL = { kind: 'null' };
|
|
7
19
|
const UNREADABLE = { kind: 'unreadable' };
|
|
8
20
|
const UNREAD = { present: undefined, values: [undefined], items: [undefined] };
|
|
9
21
|
const NO_ITEM = { present: false, values: [], items: [] };
|
|
10
22
|
const DATE = /^\d{4}-\d{2}-\d{2}$/u;
|
|
23
|
+
const HEADER = /^\/headers\/[!#$%&'*+.^_`|~0-9a-z-]+$/u;
|
|
11
24
|
const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/u;
|
|
12
25
|
export function factKind(facts) {
|
|
13
26
|
if (facts.reference !== undefined)
|
|
@@ -71,7 +84,7 @@ function factOf(value, declared, place) {
|
|
|
71
84
|
return UNREADABLE;
|
|
72
85
|
if (kind !== 'reference')
|
|
73
86
|
return { kind, value };
|
|
74
|
-
const reached = target(place.path, value);
|
|
87
|
+
const reached = target(place.path, value) ?? roomPath(value);
|
|
75
88
|
const resolved = reached === null ? undefined : place.resolve(reached);
|
|
76
89
|
if (resolved === undefined)
|
|
77
90
|
return UNREADABLE;
|
|
@@ -181,10 +194,9 @@ function documentRead({ reached, several, missing }, held) {
|
|
|
181
194
|
};
|
|
182
195
|
}
|
|
183
196
|
function readDocument(facts, path) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return facts.type === null ? undefined : single({ kind: 'string', value: facts.type });
|
|
197
|
+
const own = tested(DOCUMENT_TESTS, path);
|
|
198
|
+
if (own !== undefined)
|
|
199
|
+
return own.read(facts, path);
|
|
188
200
|
if (path.startsWith('/sections/'))
|
|
189
201
|
return facts.sections.includes(path.slice('/sections/'.length))
|
|
190
202
|
? single({ kind: 'prose' })
|
|
@@ -195,22 +207,156 @@ function readDocument(facts, path) {
|
|
|
195
207
|
return documentRead(walked(rootOf(facts, '/members'), path.slice('/members'.length)), memberHeld);
|
|
196
208
|
return undefined;
|
|
197
209
|
}
|
|
198
|
-
function readActor(actor, path) {
|
|
199
|
-
const value = path === '/user'
|
|
200
|
-
? actor.user
|
|
201
|
-
: path === '/site'
|
|
202
|
-
? actor.site
|
|
203
|
-
: path === '/door'
|
|
204
|
-
? actor.door
|
|
205
|
-
: undefined;
|
|
206
|
-
return value === undefined ? undefined : single({ kind: 'actor', value });
|
|
207
|
-
}
|
|
208
210
|
export function datePointers(fields) {
|
|
209
211
|
return Object.entries(fields)
|
|
210
212
|
.filter(([, facts]) => facts.type === 'string' && facts.format === 'date')
|
|
211
|
-
.map(([name]) => `/fields/${name}`)
|
|
213
|
+
.map(([name]) => `/fields/${escapePointer(name)}`)
|
|
212
214
|
.sort();
|
|
213
215
|
}
|
|
216
|
+
export function valuedChange(definition, field) {
|
|
217
|
+
if (!field.startsWith('/fields/'))
|
|
218
|
+
return false;
|
|
219
|
+
const reached = pointerFacts(definition, field.slice('/fields'.length));
|
|
220
|
+
return (reached !== undefined &&
|
|
221
|
+
!reached.through &&
|
|
222
|
+
reached.facts.type !== 'array' &&
|
|
223
|
+
!reached.facts.prose &&
|
|
224
|
+
factKind(reached.facts) !== null);
|
|
225
|
+
}
|
|
226
|
+
export function changeFields(definition) {
|
|
227
|
+
return [
|
|
228
|
+
...Object.keys(definition.fields).map((name) => `/fields/${escapePointer(name)}`),
|
|
229
|
+
...Object.keys(definition.sections).map((heading) => `/sections/${heading}`),
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
export function memberPointers(definition, memberType) {
|
|
233
|
+
return Object.entries(definition.fields)
|
|
234
|
+
.filter(([, facts]) => (facts.type === 'array' ? facts.items : facts)?.reference?.includes(memberType) === true)
|
|
235
|
+
.map(([name]) => `/members/${escapePointer(name)}`);
|
|
236
|
+
}
|
|
237
|
+
function kindOperators(kind) {
|
|
238
|
+
switch (kind) {
|
|
239
|
+
case 'string':
|
|
240
|
+
return ['eq', 'in', 'prefix', 'exists'];
|
|
241
|
+
case 'boolean':
|
|
242
|
+
return ['eq', 'exists'];
|
|
243
|
+
case 'number':
|
|
244
|
+
case 'date':
|
|
245
|
+
case 'time':
|
|
246
|
+
return ['eq', 'in', 'gt', 'gte', 'lt', 'lte', 'exists'];
|
|
247
|
+
default:
|
|
248
|
+
return ['eq', 'in', 'exists'];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function pointerOperators({ facts, through }) {
|
|
252
|
+
const scalar = facts.type === 'array' ? facts.items : facts;
|
|
253
|
+
const kind = scalar === undefined || scalar.prose ? null : factKind(scalar);
|
|
254
|
+
if (kind === null)
|
|
255
|
+
return ['exists'];
|
|
256
|
+
if (facts.type === 'array')
|
|
257
|
+
return ['contains', 'exists'];
|
|
258
|
+
const own = kindOperators(kind);
|
|
259
|
+
return through ? [...own.filter((operator) => operator !== 'exists'), 'contains', 'exists'] : own;
|
|
260
|
+
}
|
|
261
|
+
function typeOperators(definition, path, memberType) {
|
|
262
|
+
if (path.startsWith('/sections/'))
|
|
263
|
+
return Object.hasOwn(definition.sections, path.slice('/sections/'.length)) ? ['exists'] : [];
|
|
264
|
+
const pointer = path.startsWith('/fields/')
|
|
265
|
+
? path.slice('/fields'.length)
|
|
266
|
+
: memberType !== null && memberPointers(definition, memberType).includes(path)
|
|
267
|
+
? path.slice('/members'.length)
|
|
268
|
+
: undefined;
|
|
269
|
+
const reached = pointer === undefined ? undefined : pointerFacts(definition, pointer);
|
|
270
|
+
return reached === undefined ? [] : pointerOperators(reached);
|
|
271
|
+
}
|
|
272
|
+
function envelope(path, kind, value) {
|
|
273
|
+
return {
|
|
274
|
+
path,
|
|
275
|
+
names: (named) => named === path,
|
|
276
|
+
kind,
|
|
277
|
+
operators: kindOperators(kind),
|
|
278
|
+
read: (facts) => {
|
|
279
|
+
const held = value(facts);
|
|
280
|
+
return held === null || held === undefined ? undefined : single({ kind, value: held });
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function tested(tests, path) {
|
|
285
|
+
return tests.find(({ names }) => names(path));
|
|
286
|
+
}
|
|
287
|
+
function reader(tests, facts) {
|
|
288
|
+
return (path) => tested(tests, path)?.read(facts, path);
|
|
289
|
+
}
|
|
290
|
+
const DOCUMENT_TESTS = [
|
|
291
|
+
{
|
|
292
|
+
path: '/path',
|
|
293
|
+
names: (named) => named === '/path',
|
|
294
|
+
kind: 'string',
|
|
295
|
+
operators: ['eq', 'in', 'prefix'],
|
|
296
|
+
read: (facts) => single({ kind: 'string', value: facts.path }),
|
|
297
|
+
},
|
|
298
|
+
envelope('/type', 'enum', (facts) => facts.type),
|
|
299
|
+
];
|
|
300
|
+
const ACTOR_TESTS = [
|
|
301
|
+
envelope('/user', 'enum', (actor) => actor.user),
|
|
302
|
+
envelope('/site', 'enum', (actor) => actor.site),
|
|
303
|
+
envelope('/app', 'enum', (actor) => actor.app),
|
|
304
|
+
envelope('/door', 'enum', (actor) => actor.door),
|
|
305
|
+
];
|
|
306
|
+
const ITEM_TESTS = [
|
|
307
|
+
envelope('/delivery', 'enum', (item) => item.delivery),
|
|
308
|
+
envelope('/source', 'enum', (item) => item.source),
|
|
309
|
+
envelope('/container', 'string', (item) => item.container),
|
|
310
|
+
envelope('/author', 'string', (item) => item.author),
|
|
311
|
+
{
|
|
312
|
+
path: '/headers/<lowercase name>',
|
|
313
|
+
names: (named) => HEADER.test(named),
|
|
314
|
+
kind: 'string',
|
|
315
|
+
operators: kindOperators('string'),
|
|
316
|
+
read: (item, path) => {
|
|
317
|
+
const name = path.slice('/headers/'.length);
|
|
318
|
+
return Object.hasOwn(item.headers, name)
|
|
319
|
+
? single({ kind: 'string', value: item.headers[name] })
|
|
320
|
+
: undefined;
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
path: '/json/<JSON Pointer>',
|
|
325
|
+
names: (named) => named.startsWith('/json/'),
|
|
326
|
+
kind: null,
|
|
327
|
+
operators: CONDITION_OPERATORS,
|
|
328
|
+
read: (item, path) => item.json === null ? UNREAD : jsonRead(pointed(item.json.value, path.slice('/json'.length))),
|
|
329
|
+
},
|
|
330
|
+
];
|
|
331
|
+
const MESSAGE_TESTS = [
|
|
332
|
+
envelope('/sender', 'enum', (message) => message.sender),
|
|
333
|
+
envelope('/routine', 'string', (message) => message.routine),
|
|
334
|
+
envelope('/path', 'string', (message) => message.path),
|
|
335
|
+
];
|
|
336
|
+
export const DOCUMENT_PATHS = DOCUMENT_TESTS.map(({ path }) => path);
|
|
337
|
+
export const ACTOR_PATHS = ACTOR_TESTS.map(({ path }) => path);
|
|
338
|
+
export const ITEM_PATHS = ITEM_TESTS.map(({ path }) => path);
|
|
339
|
+
export const MESSAGE_PATHS = MESSAGE_TESTS.map(({ path }) => path);
|
|
340
|
+
export function testOperators(definitions, path, memberType) {
|
|
341
|
+
const own = tested(DOCUMENT_TESTS, path);
|
|
342
|
+
if (own !== undefined)
|
|
343
|
+
return own.operators;
|
|
344
|
+
return [
|
|
345
|
+
...new Set(definitions.flatMap((definition) => typeOperators(definition, path, memberType))),
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
export function actorOperators(path) {
|
|
349
|
+
return tested(ACTOR_TESTS, path)?.operators ?? [];
|
|
350
|
+
}
|
|
351
|
+
export function itemOperators(path) {
|
|
352
|
+
return tested(ITEM_TESTS, path)?.operators ?? [];
|
|
353
|
+
}
|
|
354
|
+
export function messageOperators(path) {
|
|
355
|
+
return tested(MESSAGE_TESTS, path)?.operators ?? [];
|
|
356
|
+
}
|
|
357
|
+
export function itemKind(path) {
|
|
358
|
+
return tested(ITEM_TESTS, path)?.kind ?? null;
|
|
359
|
+
}
|
|
214
360
|
export function dated(value) {
|
|
215
361
|
return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
|
|
216
362
|
}
|
|
@@ -239,11 +385,8 @@ export function instant(value) {
|
|
|
239
385
|
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
240
386
|
}
|
|
241
387
|
export function pointed(value, pointer) {
|
|
242
|
-
if (pointer === '')
|
|
243
|
-
return value;
|
|
244
388
|
let reached = value;
|
|
245
|
-
for (const
|
|
246
|
-
const token = part.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
389
|
+
for (const token of pointerSegments(pointer)) {
|
|
247
390
|
if (Array.isArray(reached)) {
|
|
248
391
|
if (!ARRAY_INDEX.test(token))
|
|
249
392
|
return undefined;
|
|
@@ -282,44 +425,15 @@ function jsonRead(value) {
|
|
|
282
425
|
return single({ kind: 'prose' });
|
|
283
426
|
return { present: true, values: [], items: value.filter(scalar).map(jsonHeld), loose: true };
|
|
284
427
|
}
|
|
285
|
-
function
|
|
286
|
-
if (path.startsWith('/json/')) {
|
|
287
|
-
if (item.json === null)
|
|
288
|
-
return UNREAD;
|
|
289
|
-
return jsonRead(pointed(item.json.value, path.slice('/json'.length)));
|
|
290
|
-
}
|
|
291
|
-
if (path.startsWith('/headers/')) {
|
|
292
|
-
const name = path.slice('/headers/'.length);
|
|
293
|
-
return Object.hasOwn(item.headers, name)
|
|
294
|
-
? single({ kind: 'string', value: item.headers[name] })
|
|
295
|
-
: undefined;
|
|
296
|
-
}
|
|
297
|
-
if (path === '/has_attachment')
|
|
298
|
-
return single({ kind: 'boolean', value: item.has_attachment });
|
|
299
|
-
const value = path === '/delivery'
|
|
300
|
-
? item.delivery
|
|
301
|
-
: path === '/source'
|
|
302
|
-
? item.source
|
|
303
|
-
: path === '/container'
|
|
304
|
-
? item.container
|
|
305
|
-
: path === '/author'
|
|
306
|
-
? item.author
|
|
307
|
-
: null;
|
|
308
|
-
return value === null ? undefined : single({ kind: 'string', value });
|
|
309
|
-
}
|
|
310
|
-
function wanted(value, owner) {
|
|
311
|
-
return isRecord(value) && value.owner === true ? owner : value;
|
|
312
|
-
}
|
|
313
|
-
function equal(held, value, owner) {
|
|
428
|
+
function equal(held, value) {
|
|
314
429
|
if (!('value' in held))
|
|
315
430
|
return undefined;
|
|
316
|
-
|
|
317
|
-
if (typeof expected !== typeof held.value)
|
|
431
|
+
if (typeof value !== typeof held.value)
|
|
318
432
|
return undefined;
|
|
319
433
|
if (held.kind !== 'time')
|
|
320
|
-
return
|
|
434
|
+
return value === held.value;
|
|
321
435
|
const left = instant(held.value);
|
|
322
|
-
const right = instant(
|
|
436
|
+
const right = instant(value);
|
|
323
437
|
return left === undefined || right === undefined ? undefined : left === right;
|
|
324
438
|
}
|
|
325
439
|
function sign(left, right) {
|
|
@@ -356,11 +470,11 @@ function allOf(truths) {
|
|
|
356
470
|
return false;
|
|
357
471
|
return truths.some((truth) => truth === undefined) ? undefined : true;
|
|
358
472
|
}
|
|
359
|
-
function compared(test, held
|
|
473
|
+
function compared(test, held) {
|
|
360
474
|
if ('eq' in test)
|
|
361
|
-
return equal(held, test.eq
|
|
475
|
+
return equal(held, test.eq);
|
|
362
476
|
if ('in' in test)
|
|
363
|
-
return anyOf(test.in.map((value) => equal(held, value
|
|
477
|
+
return anyOf(test.in.map((value) => equal(held, value)));
|
|
364
478
|
if ('prefix' in test) {
|
|
365
479
|
if (!('value' in held) || typeof held.value !== 'string')
|
|
366
480
|
return undefined;
|
|
@@ -376,7 +490,7 @@ function compared(test, held, owner) {
|
|
|
376
490
|
return ordered(held, test.lt, (sign) => sign < 0);
|
|
377
491
|
return ordered(held, test.lte, (sign) => sign <= 0);
|
|
378
492
|
}
|
|
379
|
-
function leaf(test, read
|
|
493
|
+
function leaf(test, read) {
|
|
380
494
|
if ('exists' in test) {
|
|
381
495
|
const present = read === undefined ? false : read.present;
|
|
382
496
|
return present === undefined ? undefined : present === test.exists;
|
|
@@ -386,28 +500,39 @@ function leaf(test, read, owner) {
|
|
|
386
500
|
if ('contains' in test) {
|
|
387
501
|
if (read.items === null)
|
|
388
502
|
return undefined;
|
|
389
|
-
const truths = read.items.map((item) => item === undefined ? undefined : equal(item, test.contains
|
|
503
|
+
const truths = read.items.map((item) => item === undefined ? undefined : equal(item, test.contains));
|
|
390
504
|
return read.loose === true && !truths.includes(true) ? false : anyOf(truths);
|
|
391
505
|
}
|
|
392
506
|
if (read.values.length === 0)
|
|
393
507
|
return read === NO_ITEM ? false : undefined;
|
|
394
|
-
return anyOf(read.values.map((value) => (value === undefined ? undefined : compared(test, value
|
|
508
|
+
return anyOf(read.values.map((value) => (value === undefined ? undefined : compared(test, value))));
|
|
395
509
|
}
|
|
396
|
-
function evaluated(test, read
|
|
510
|
+
function evaluated(test, read) {
|
|
397
511
|
if ('all' in test)
|
|
398
|
-
return allOf(test.all.map((part) => evaluated(part, read
|
|
512
|
+
return allOf(test.all.map((part) => evaluated(part, read)));
|
|
399
513
|
if ('any' in test)
|
|
400
|
-
return anyOf(test.any.map((part) => evaluated(part, read
|
|
514
|
+
return anyOf(test.any.map((part) => evaluated(part, read)));
|
|
401
515
|
if ('not' in test) {
|
|
402
|
-
const truth = evaluated(test.not, read
|
|
516
|
+
const truth = evaluated(test.not, read);
|
|
403
517
|
return truth === undefined ? undefined : !truth;
|
|
404
518
|
}
|
|
405
|
-
return leaf(test, read(test.path)
|
|
519
|
+
return leaf(test, read(test.path));
|
|
406
520
|
}
|
|
407
|
-
export function
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
521
|
+
export function members(document, path) {
|
|
522
|
+
if (!path.startsWith('/members/'))
|
|
523
|
+
return [];
|
|
524
|
+
const read = readDocument(document, path);
|
|
525
|
+
const values = read === undefined ? [] : [...read.values, ...(read.items ?? [])];
|
|
526
|
+
return [
|
|
527
|
+
...new Set(values.flatMap((value) => value !== undefined && value.kind === 'member' && 'value' in value
|
|
528
|
+
? [String(value.value)]
|
|
529
|
+
: [])),
|
|
530
|
+
].sort();
|
|
531
|
+
}
|
|
532
|
+
export function holds(test, document) {
|
|
533
|
+
return evaluated(test, (path) => readDocument(document, path));
|
|
534
|
+
}
|
|
535
|
+
export function inScope(scope, document) {
|
|
411
536
|
if (document === null)
|
|
412
537
|
return false;
|
|
413
538
|
if ('type' in scope)
|
|
@@ -416,10 +541,10 @@ function inScope(scope, document) {
|
|
|
416
541
|
return document.id === scope.document;
|
|
417
542
|
return scope.folder === '/' || document.path.startsWith(`${scope.folder}/`);
|
|
418
543
|
}
|
|
419
|
-
function matched(condition, test, document
|
|
544
|
+
function matched(condition, test, document) {
|
|
420
545
|
if (!inScope(condition.scope, document))
|
|
421
546
|
return false;
|
|
422
|
-
return test === undefined || holds(test, document
|
|
547
|
+
return test === undefined || holds(test, document) === true;
|
|
423
548
|
}
|
|
424
549
|
function reachedAt(document, field) {
|
|
425
550
|
if (document === null)
|
|
@@ -452,10 +577,10 @@ function valueOf(fact) {
|
|
|
452
577
|
function signature(reached) {
|
|
453
578
|
return JSON.stringify(reached.map(({ fact }) => valueOf(fact)));
|
|
454
579
|
}
|
|
455
|
-
function among(values, document, field
|
|
456
|
-
return holds({ path: field, in: values }, document
|
|
580
|
+
function among(values, document, field) {
|
|
581
|
+
return holds({ path: field, in: values }, document) === true;
|
|
457
582
|
}
|
|
458
|
-
function fieldChanged(condition, event
|
|
583
|
+
function fieldChanged(condition, event) {
|
|
459
584
|
const { field, from, to } = condition;
|
|
460
585
|
const before = reachedAt(event.before, field);
|
|
461
586
|
const after = reachedAt(event.after, field);
|
|
@@ -469,32 +594,40 @@ function fieldChanged(condition, event, owner) {
|
|
|
469
594
|
return false;
|
|
470
595
|
if (from === 'new'
|
|
471
596
|
? event.before !== null
|
|
472
|
-
: from !== undefined && (event.before === null || !among(from, event.before, field
|
|
597
|
+
: from !== undefined && (event.before === null || !among(from, event.before, field)))
|
|
473
598
|
return false;
|
|
474
599
|
if (to === 'deleted'
|
|
475
600
|
? event.after !== null
|
|
476
|
-
: to !== undefined && (event.after === null || !among(to, event.after, field
|
|
601
|
+
: to !== undefined && (event.after === null || !among(to, event.after, field)))
|
|
477
602
|
return false;
|
|
478
603
|
return true;
|
|
479
604
|
}
|
|
480
|
-
export function fires(condition, event
|
|
481
|
-
if (condition.
|
|
482
|
-
|
|
605
|
+
export function fires(condition, event) {
|
|
606
|
+
if (condition.moved_between_rooms !== undefined &&
|
|
607
|
+
condition.moved_between_rooms !== event.moved_between_rooms)
|
|
608
|
+
return false;
|
|
609
|
+
if (condition.by !== undefined && evaluated(condition.by, reader(ACTOR_TESTS, event.by)) !== true)
|
|
483
610
|
return false;
|
|
484
611
|
if (condition.mode === 'starts_matching') {
|
|
485
612
|
if (event.before === null && !condition.new_documents)
|
|
486
613
|
return false;
|
|
487
|
-
return (matched(condition, condition.match, event.after
|
|
488
|
-
!matched(condition, condition.match, event.before
|
|
614
|
+
return (matched(condition, condition.match, event.after) &&
|
|
615
|
+
!matched(condition, condition.match, event.before));
|
|
489
616
|
}
|
|
490
617
|
const side = event.after ?? event.before;
|
|
491
|
-
return matched(condition, condition.match, side
|
|
618
|
+
return matched(condition, condition.match, side) && fieldChanged(condition, event);
|
|
492
619
|
}
|
|
493
|
-
export function itemFires(condition, item
|
|
620
|
+
export function itemFires(condition, item) {
|
|
494
621
|
if (condition.source !== undefined && item.source !== condition.source)
|
|
495
622
|
return false;
|
|
496
623
|
if (condition.address !== undefined && item.address !== condition.address)
|
|
497
624
|
return false;
|
|
625
|
+
return (condition.match === undefined || evaluated(condition.match, reader(ITEM_TESTS, item)) === true);
|
|
626
|
+
}
|
|
627
|
+
export function notificationFires(condition, notification) {
|
|
628
|
+
return condition.match === undefined || holds(condition.match, notification) === true;
|
|
629
|
+
}
|
|
630
|
+
export function messageFires(condition, message) {
|
|
498
631
|
return (condition.match === undefined ||
|
|
499
|
-
evaluated(condition.match, (
|
|
632
|
+
evaluated(condition.match, reader(MESSAGE_TESTS, message)) === true);
|
|
500
633
|
}
|
package/dist/definition.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type ValueFacts = {
|
|
|
5
5
|
readonly format?: string;
|
|
6
6
|
readonly values?: readonly unknown[];
|
|
7
7
|
readonly reference?: readonly string[];
|
|
8
|
+
readonly crossRoom?: true;
|
|
8
9
|
readonly prose: boolean;
|
|
9
10
|
readonly conditional?: true;
|
|
10
11
|
readonly prefix?: readonly ValueFacts[];
|
|
@@ -59,6 +60,7 @@ export declare const JSON_TYPES: readonly JsonType[];
|
|
|
59
60
|
export declare const BUILT_IN_TYPE = "any";
|
|
60
61
|
export declare const ATTACHMENT = "attachment";
|
|
61
62
|
export declare const ARRAY_INDEX: RegExp;
|
|
63
|
+
export declare const JSON_POINTER: RegExp;
|
|
62
64
|
export declare function escapePointer(key: string): string;
|
|
63
65
|
export declare function pointerSegments(pointer: string): string[];
|
|
64
66
|
export declare function refTarget(reference: string, defs: Readonly<Record<string, unknown>>): {
|
|
@@ -76,5 +78,5 @@ export type PointerFacts = {
|
|
|
76
78
|
export declare function crossedFacts(facts: ValueFacts): ValueFacts[];
|
|
77
79
|
export declare function fieldFacts(definition: Definition, key: string): ValueFacts | undefined;
|
|
78
80
|
export declare function pointerFacts(definition: Definition, pointer: string): PointerFacts | undefined;
|
|
79
|
-
export declare function readSchema(text: string): VerifiedModel | Failure;
|
|
81
|
+
export declare function readSchema(text: string, provided?: VerifiedModel): VerifiedModel | Failure;
|
|
80
82
|
//# sourceMappingURL=definition.d.ts.map
|
package/dist/definition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjG,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC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