@agentshouse/mdmodel 0.1.0-ccf1367190878 → 0.1.0-cdbd463e01dc2
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 +197 -178
- package/README.md +21 -22
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +35 -20
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +112 -24
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +27 -17
- package/dist/document.d.ts +5 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +304 -187
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +230 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +39 -0
- package/dist/index.d.ts +22 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- 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 +2 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +107 -50
- 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 +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.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 +55 -4
- package/dist/types.d.ts +35 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +29 -4
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +301 -85
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +36 -3
- package/fixtures/README.md +26 -6
- 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 +7 -2
- package/dist/condition.d.ts +0 -149
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -500
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdmodel",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-cdbd463e01dc2",
|
|
4
4
|
"description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=24.
|
|
12
|
+
"node": ">=24.22.1"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
@@ -29,5 +29,10 @@
|
|
|
29
29
|
"@cfworker/json-schema": "4.1.1",
|
|
30
30
|
"decode-named-character-reference": "1.3.0",
|
|
31
31
|
"micromark-util-decode-numeric-character-reference": "2.0.2"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/agentshouse/core.git",
|
|
36
|
+
"directory": "mdmodel/packages/mdmodel"
|
|
32
37
|
}
|
|
33
38
|
}
|
package/dist/condition.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { type ValueFacts } from './definition.js';
|
|
2
|
-
import type { Document, VerifiedModel } from './types.js';
|
|
3
|
-
export type ConditionValue = string | number | boolean | {
|
|
4
|
-
readonly owner: true;
|
|
5
|
-
};
|
|
6
|
-
export type ConditionTest = {
|
|
7
|
-
readonly all: readonly ConditionTest[];
|
|
8
|
-
} | {
|
|
9
|
-
readonly any: readonly ConditionTest[];
|
|
10
|
-
} | {
|
|
11
|
-
readonly not: ConditionTest;
|
|
12
|
-
} | ({
|
|
13
|
-
readonly path: string;
|
|
14
|
-
} & ({
|
|
15
|
-
readonly eq: ConditionValue;
|
|
16
|
-
} | {
|
|
17
|
-
readonly in: readonly ConditionValue[];
|
|
18
|
-
} | {
|
|
19
|
-
readonly exists: boolean;
|
|
20
|
-
} | {
|
|
21
|
-
readonly contains: ConditionValue;
|
|
22
|
-
} | {
|
|
23
|
-
readonly gt: number | string;
|
|
24
|
-
} | {
|
|
25
|
-
readonly gte: number | string;
|
|
26
|
-
} | {
|
|
27
|
-
readonly lt: number | string;
|
|
28
|
-
} | {
|
|
29
|
-
readonly lte: number | string;
|
|
30
|
-
} | {
|
|
31
|
-
readonly prefix: string;
|
|
32
|
-
}));
|
|
33
|
-
export type ConditionScope = {
|
|
34
|
-
readonly type: string;
|
|
35
|
-
} | {
|
|
36
|
-
readonly folder: string;
|
|
37
|
-
} | {
|
|
38
|
-
readonly document: string;
|
|
39
|
-
};
|
|
40
|
-
type DocumentEventBase = {
|
|
41
|
-
readonly on: 'documents';
|
|
42
|
-
readonly scope: ConditionScope;
|
|
43
|
-
readonly by?: ConditionTest;
|
|
44
|
-
};
|
|
45
|
-
export type DocumentCondition = (DocumentEventBase & {
|
|
46
|
-
readonly mode: 'starts_matching';
|
|
47
|
-
readonly new_documents: boolean;
|
|
48
|
-
readonly match: ConditionTest;
|
|
49
|
-
}) | (DocumentEventBase & {
|
|
50
|
-
readonly mode: 'field_changes';
|
|
51
|
-
readonly field: string;
|
|
52
|
-
readonly from?: readonly ConditionValue[] | 'new';
|
|
53
|
-
readonly to?: readonly ConditionValue[] | 'deleted';
|
|
54
|
-
readonly match?: ConditionTest;
|
|
55
|
-
});
|
|
56
|
-
export type ItemCondition = {
|
|
57
|
-
readonly on: 'items';
|
|
58
|
-
readonly source?: string;
|
|
59
|
-
readonly address?: string;
|
|
60
|
-
readonly match?: ConditionTest;
|
|
61
|
-
};
|
|
62
|
-
export type CronCondition = {
|
|
63
|
-
readonly on: 'clock';
|
|
64
|
-
readonly cron: string;
|
|
65
|
-
readonly time_zone: string;
|
|
66
|
-
};
|
|
67
|
-
export type DateCondition = {
|
|
68
|
-
readonly on: 'clock';
|
|
69
|
-
readonly scope: {
|
|
70
|
-
readonly type: string;
|
|
71
|
-
};
|
|
72
|
-
readonly date: string;
|
|
73
|
-
readonly days: number;
|
|
74
|
-
readonly at: string;
|
|
75
|
-
readonly time_zone: string;
|
|
76
|
-
readonly match?: ConditionTest;
|
|
77
|
-
};
|
|
78
|
-
export type Condition = DocumentCondition | ItemCondition | CronCondition | DateCondition;
|
|
79
|
-
export type FactKind = 'string' | 'number' | 'boolean' | 'date' | 'time' | 'enum' | 'reference';
|
|
80
|
-
type Scalar = string | number | boolean;
|
|
81
|
-
export type Fact = {
|
|
82
|
-
readonly kind: FactKind;
|
|
83
|
-
readonly value: Scalar;
|
|
84
|
-
readonly member?: string;
|
|
85
|
-
} | {
|
|
86
|
-
readonly kind: 'prose';
|
|
87
|
-
} | {
|
|
88
|
-
readonly kind: 'null';
|
|
89
|
-
} | {
|
|
90
|
-
readonly kind: 'unreadable';
|
|
91
|
-
} | {
|
|
92
|
-
readonly kind: 'list';
|
|
93
|
-
readonly items: readonly Fact[];
|
|
94
|
-
} | {
|
|
95
|
-
readonly kind: 'object';
|
|
96
|
-
readonly fields: Readonly<Record<string, Fact>>;
|
|
97
|
-
};
|
|
98
|
-
export type DocumentFacts = {
|
|
99
|
-
readonly id: string;
|
|
100
|
-
readonly path: string;
|
|
101
|
-
readonly type: string | null;
|
|
102
|
-
readonly fields: Readonly<Record<string, Fact>>;
|
|
103
|
-
readonly sections: readonly string[];
|
|
104
|
-
};
|
|
105
|
-
export declare const WRITE_DOORS: readonly ['browser', 'agent', 'client'];
|
|
106
|
-
export type WriteDoor = (typeof WRITE_DOORS)[number];
|
|
107
|
-
export type Actor = {
|
|
108
|
-
readonly user?: string;
|
|
109
|
-
readonly site?: string;
|
|
110
|
-
readonly door?: WriteDoor;
|
|
111
|
-
};
|
|
112
|
-
export type DocumentEvent = {
|
|
113
|
-
readonly before: DocumentFacts | null;
|
|
114
|
-
readonly after: DocumentFacts | null;
|
|
115
|
-
readonly changed: readonly string[];
|
|
116
|
-
readonly by: Actor;
|
|
117
|
-
};
|
|
118
|
-
export type ItemFacts = {
|
|
119
|
-
readonly delivery: string;
|
|
120
|
-
readonly source: string | null;
|
|
121
|
-
readonly address: string | null;
|
|
122
|
-
readonly has_attachment: boolean;
|
|
123
|
-
readonly container: string | null;
|
|
124
|
-
readonly author: string | null;
|
|
125
|
-
readonly headers: Readonly<Record<string, string>>;
|
|
126
|
-
readonly json: {
|
|
127
|
-
readonly value: unknown;
|
|
128
|
-
} | null;
|
|
129
|
-
};
|
|
130
|
-
export type Resolved = {
|
|
131
|
-
readonly id: string;
|
|
132
|
-
readonly member?: string;
|
|
133
|
-
};
|
|
134
|
-
type Truth = boolean | undefined;
|
|
135
|
-
export declare function factKind(facts: ValueFacts): FactKind | null;
|
|
136
|
-
export declare function facts(document: Document, at: {
|
|
137
|
-
readonly id: string;
|
|
138
|
-
readonly path: string;
|
|
139
|
-
}, model: VerifiedModel, resolve: (target: string) => Resolved | undefined): DocumentFacts;
|
|
140
|
-
export declare function prosePaths(facts: DocumentFacts): string[];
|
|
141
|
-
export declare function datePointers(fields: Readonly<Record<string, ValueFacts>>): string[];
|
|
142
|
-
export declare function dated(value: unknown): value is string;
|
|
143
|
-
export declare function instant(value: unknown): bigint | undefined;
|
|
144
|
-
export declare function pointed(value: unknown, pointer: string): unknown;
|
|
145
|
-
export declare function holds(test: ConditionTest, document: DocumentFacts, owner: string): Truth;
|
|
146
|
-
export declare function fires(condition: DocumentCondition, event: DocumentEvent, owner: string): boolean;
|
|
147
|
-
export declare function itemFires(condition: ItemCondition, item: ItemFacts, owner: string): boolean;
|
|
148
|
-
export {};
|
|
149
|
-
//# sourceMappingURL=condition.d.ts.map
|
package/dist/condition.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../src/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,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,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC;AAElF,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAA;CAAE,GAC/B,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,CACzB;IAAE,QA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,EAAE,QAAQ,EAClB,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;AA4GD,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAAG,MAAM,EAAE,CAKnF;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAIrD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgC1D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAehE;AAiJD,wBAAgB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAExF;AAyFD,wBAAgB,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAehG;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3F"}
|
package/dist/condition.js
DELETED
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
import { ARRAY_INDEX, escapePointer, fieldFacts, itemFacts, memberFacts, pointerSegments, } from './definition.js';
|
|
2
|
-
import { target } from './paths.js';
|
|
3
|
-
import { isRecord, plain } from './yaml.js';
|
|
4
|
-
export const WRITE_DOORS = ['browser', 'agent', 'client'];
|
|
5
|
-
const PROSE = { kind: 'prose' };
|
|
6
|
-
const NULL = { kind: 'null' };
|
|
7
|
-
const UNREADABLE = { kind: 'unreadable' };
|
|
8
|
-
const UNREAD = { present: undefined, values: [undefined], items: [undefined] };
|
|
9
|
-
const NO_ITEM = { present: false, values: [], items: [] };
|
|
10
|
-
const DATE = /^\d{4}-\d{2}-\d{2}$/u;
|
|
11
|
-
const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/u;
|
|
12
|
-
export function factKind(facts) {
|
|
13
|
-
if (facts.reference !== undefined)
|
|
14
|
-
return 'reference';
|
|
15
|
-
if (facts.values !== undefined)
|
|
16
|
-
return 'enum';
|
|
17
|
-
if (facts.type === 'number' || facts.type === 'integer')
|
|
18
|
-
return 'number';
|
|
19
|
-
if (facts.type === 'boolean')
|
|
20
|
-
return 'boolean';
|
|
21
|
-
if (facts.type !== 'string')
|
|
22
|
-
return null;
|
|
23
|
-
if (facts.format === 'date')
|
|
24
|
-
return 'date';
|
|
25
|
-
if (facts.format === 'date-time')
|
|
26
|
-
return 'time';
|
|
27
|
-
return 'string';
|
|
28
|
-
}
|
|
29
|
-
function fits(kind, facts, value) {
|
|
30
|
-
if (!scalar(value))
|
|
31
|
-
return false;
|
|
32
|
-
if (kind === 'enum')
|
|
33
|
-
return (facts.values ?? []).includes(value);
|
|
34
|
-
if (kind === 'number')
|
|
35
|
-
return typeof value === 'number';
|
|
36
|
-
if (kind === 'boolean')
|
|
37
|
-
return typeof value === 'boolean';
|
|
38
|
-
if (typeof value !== 'string')
|
|
39
|
-
return false;
|
|
40
|
-
if (kind === 'date')
|
|
41
|
-
return dated(value);
|
|
42
|
-
if (kind === 'time')
|
|
43
|
-
return instant(value) !== undefined;
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
function factOf(value, declared, place) {
|
|
47
|
-
if (value === null)
|
|
48
|
-
return NULL;
|
|
49
|
-
if (Array.isArray(value)) {
|
|
50
|
-
if (declared?.type !== undefined && declared.type !== 'array')
|
|
51
|
-
return UNREADABLE;
|
|
52
|
-
return {
|
|
53
|
-
kind: 'list',
|
|
54
|
-
items: value.map((item, index) => factOf(item, declared === undefined ? undefined : itemFacts(declared, index), place)),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (plain(value)) {
|
|
58
|
-
if (declared?.type !== undefined && declared.type !== 'object')
|
|
59
|
-
return UNREADABLE;
|
|
60
|
-
const fields = Object.create(null);
|
|
61
|
-
for (const [key, held] of Object.entries(value))
|
|
62
|
-
fields[key] = factOf(held, declared === undefined ? undefined : memberFacts(declared, key), place);
|
|
63
|
-
return { kind: 'object', fields };
|
|
64
|
-
}
|
|
65
|
-
if (declared?.type === 'array' || declared?.type === 'object')
|
|
66
|
-
return UNREADABLE;
|
|
67
|
-
const kind = declared === undefined || declared.prose ? null : factKind(declared);
|
|
68
|
-
if (kind === null)
|
|
69
|
-
return PROSE;
|
|
70
|
-
if (!fits(kind, declared, value))
|
|
71
|
-
return UNREADABLE;
|
|
72
|
-
if (kind !== 'reference')
|
|
73
|
-
return { kind, value };
|
|
74
|
-
const reached = target(place.path, value);
|
|
75
|
-
const resolved = reached === null ? undefined : place.resolve(reached);
|
|
76
|
-
if (resolved === undefined)
|
|
77
|
-
return UNREADABLE;
|
|
78
|
-
return resolved.member === undefined
|
|
79
|
-
? { kind, value: resolved.id }
|
|
80
|
-
: { kind, value: resolved.id, member: resolved.member };
|
|
81
|
-
}
|
|
82
|
-
export function facts(document, at, model, resolve) {
|
|
83
|
-
const type = document.type ?? null;
|
|
84
|
-
const definition = type !== null && Object.hasOwn(model.types, type) ? model.types[type] : null;
|
|
85
|
-
const fields = Object.create(null);
|
|
86
|
-
const place = { path: at.path, resolve };
|
|
87
|
-
for (const [name, value] of Object.entries(document.fields)) {
|
|
88
|
-
const declared = definition === null ? undefined : fieldFacts(definition, name);
|
|
89
|
-
if (declared !== undefined)
|
|
90
|
-
fields[name] = factOf(value, declared, place);
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
id: at.id,
|
|
94
|
-
path: `/${at.path}`,
|
|
95
|
-
type,
|
|
96
|
-
fields,
|
|
97
|
-
sections: Object.keys(document.sections).sort(),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function rootOf(facts, prefix) {
|
|
101
|
-
return { pointer: prefix, fact: { kind: 'object', fields: facts.fields } };
|
|
102
|
-
}
|
|
103
|
-
export function prosePaths(facts) {
|
|
104
|
-
const paths = facts.sections.map((heading) => `/sections/${heading}`);
|
|
105
|
-
const visit = ({ pointer, fact }) => {
|
|
106
|
-
if (fact.kind === 'prose')
|
|
107
|
-
paths.push(pointer);
|
|
108
|
-
if (fact.kind === 'list')
|
|
109
|
-
fact.items.forEach((item, index) => visit({ pointer: `${pointer}/${index}`, fact: item }));
|
|
110
|
-
if (fact.kind === 'object')
|
|
111
|
-
for (const [key, held] of Object.entries(fact.fields))
|
|
112
|
-
visit({ pointer: `${pointer}/${escapePointer(key)}`, fact: held });
|
|
113
|
-
};
|
|
114
|
-
visit(rootOf(facts, '/fields'));
|
|
115
|
-
return paths.sort();
|
|
116
|
-
}
|
|
117
|
-
function walked(start, pointer) {
|
|
118
|
-
let reached = [start];
|
|
119
|
-
let several = false;
|
|
120
|
-
let missing = false;
|
|
121
|
-
const each = (from, next) => from.flatMap((one) => {
|
|
122
|
-
const found = next(one);
|
|
123
|
-
if (found === null)
|
|
124
|
-
missing = true;
|
|
125
|
-
return found ?? [];
|
|
126
|
-
});
|
|
127
|
-
for (const token of pointerSegments(pointer)) {
|
|
128
|
-
const step = ({ pointer: at, fact }) => {
|
|
129
|
-
if (fact.kind === 'unreadable')
|
|
130
|
-
return [{ pointer: at, fact }];
|
|
131
|
-
if (fact.kind === 'object')
|
|
132
|
-
return Object.hasOwn(fact.fields, token)
|
|
133
|
-
? [{ pointer: `${at}/${escapePointer(token)}`, fact: fact.fields[token] }]
|
|
134
|
-
: null;
|
|
135
|
-
if (fact.kind !== 'list')
|
|
136
|
-
return null;
|
|
137
|
-
if (ARRAY_INDEX.test(token)) {
|
|
138
|
-
const item = fact.items[Number(token)];
|
|
139
|
-
return item === undefined ? null : [{ pointer: `${at}/${token}`, fact: item }];
|
|
140
|
-
}
|
|
141
|
-
several = true;
|
|
142
|
-
return each(fact.items.map((item, index) => ({ pointer: `${at}/${index}`, fact: item })), step);
|
|
143
|
-
};
|
|
144
|
-
reached = each(reached, step);
|
|
145
|
-
}
|
|
146
|
-
return { reached, several, missing };
|
|
147
|
-
}
|
|
148
|
-
function expand(fact) {
|
|
149
|
-
return fact.kind === 'list' ? fact.items.flatMap(expand) : [fact];
|
|
150
|
-
}
|
|
151
|
-
function fieldHeld(fact) {
|
|
152
|
-
if (fact.kind === 'unreadable')
|
|
153
|
-
return undefined;
|
|
154
|
-
if (fact.kind === 'null')
|
|
155
|
-
return { kind: 'null' };
|
|
156
|
-
return 'value' in fact ? { kind: fact.kind, value: fact.value } : { kind: 'prose' };
|
|
157
|
-
}
|
|
158
|
-
function memberHeld(fact) {
|
|
159
|
-
if (fact.kind === 'unreadable')
|
|
160
|
-
return undefined;
|
|
161
|
-
return fact.kind === 'reference' && fact.member !== undefined
|
|
162
|
-
? { kind: 'member', value: fact.member }
|
|
163
|
-
: null;
|
|
164
|
-
}
|
|
165
|
-
function single(held) {
|
|
166
|
-
return { present: true, values: [held], items: null };
|
|
167
|
-
}
|
|
168
|
-
function documentRead({ reached, several, missing }, held) {
|
|
169
|
-
if (reached.length === 0)
|
|
170
|
-
return missing ? undefined : NO_ITEM;
|
|
171
|
-
const facts = reached.map(({ fact }) => fact);
|
|
172
|
-
const kept = (all) => all.map(held).filter((value) => value !== null);
|
|
173
|
-
const unknown = missing ? [undefined] : [];
|
|
174
|
-
const values = kept(facts.filter((fact) => fact.kind !== 'list'));
|
|
175
|
-
const listed = several || facts.some((fact) => fact.kind === 'list');
|
|
176
|
-
const present = facts.some((fact) => fact.kind === 'list') || values.some(Boolean);
|
|
177
|
-
return {
|
|
178
|
-
present: present ? true : values.length > 0 ? undefined : false,
|
|
179
|
-
values: [...values, ...unknown],
|
|
180
|
-
items: listed ? [...kept(facts.flatMap(expand)), ...unknown] : null,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function readDocument(facts, path) {
|
|
184
|
-
if (path === '/path')
|
|
185
|
-
return single({ kind: 'path', value: facts.path });
|
|
186
|
-
if (path === '/type')
|
|
187
|
-
return facts.type === null ? undefined : single({ kind: 'string', value: facts.type });
|
|
188
|
-
if (path.startsWith('/sections/'))
|
|
189
|
-
return facts.sections.includes(path.slice('/sections/'.length))
|
|
190
|
-
? single({ kind: 'prose' })
|
|
191
|
-
: undefined;
|
|
192
|
-
if (path.startsWith('/fields/'))
|
|
193
|
-
return documentRead(walked(rootOf(facts, '/fields'), path.slice('/fields'.length)), fieldHeld);
|
|
194
|
-
if (path.startsWith('/members/'))
|
|
195
|
-
return documentRead(walked(rootOf(facts, '/members'), path.slice('/members'.length)), memberHeld);
|
|
196
|
-
return undefined;
|
|
197
|
-
}
|
|
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
|
-
export function datePointers(fields) {
|
|
209
|
-
return Object.entries(fields)
|
|
210
|
-
.filter(([, facts]) => facts.type === 'string' && facts.format === 'date')
|
|
211
|
-
.map(([name]) => `/fields/${name}`)
|
|
212
|
-
.sort();
|
|
213
|
-
}
|
|
214
|
-
export function dated(value) {
|
|
215
|
-
return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
|
|
216
|
-
}
|
|
217
|
-
export function instant(value) {
|
|
218
|
-
if (typeof value !== 'string')
|
|
219
|
-
return undefined;
|
|
220
|
-
const parts = DATE_TIME.exec(value);
|
|
221
|
-
if (parts === null)
|
|
222
|
-
return undefined;
|
|
223
|
-
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
224
|
-
1, 2, 3, 4, 5, 6, 9, 10,
|
|
225
|
-
].map((at) => Number(parts[at] ?? 0));
|
|
226
|
-
const at = new Date(0);
|
|
227
|
-
at.setUTCFullYear(year, month - 1, day);
|
|
228
|
-
at.setUTCHours(hour, minute, second);
|
|
229
|
-
if (at.getUTCFullYear() !== year ||
|
|
230
|
-
at.getUTCMonth() !== month - 1 ||
|
|
231
|
-
at.getUTCDate() !== day ||
|
|
232
|
-
at.getUTCHours() !== hour ||
|
|
233
|
-
at.getUTCMinutes() !== minute ||
|
|
234
|
-
offsetHours > 23 ||
|
|
235
|
-
offsetMinutes > 59)
|
|
236
|
-
return undefined;
|
|
237
|
-
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
238
|
-
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
239
|
-
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
240
|
-
}
|
|
241
|
-
export function pointed(value, pointer) {
|
|
242
|
-
if (pointer === '')
|
|
243
|
-
return value;
|
|
244
|
-
let reached = value;
|
|
245
|
-
for (const part of pointer.slice(1).split('/')) {
|
|
246
|
-
const token = part.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
247
|
-
if (Array.isArray(reached)) {
|
|
248
|
-
if (!ARRAY_INDEX.test(token))
|
|
249
|
-
return undefined;
|
|
250
|
-
reached = reached[Number(token)];
|
|
251
|
-
}
|
|
252
|
-
else if (plain(reached) && Object.hasOwn(reached, token)) {
|
|
253
|
-
reached = reached[token];
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
return undefined;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return reached;
|
|
260
|
-
}
|
|
261
|
-
function scalar(value) {
|
|
262
|
-
return (typeof value === 'string' ||
|
|
263
|
-
typeof value === 'boolean' ||
|
|
264
|
-
(typeof value === 'number' && Number.isFinite(value)));
|
|
265
|
-
}
|
|
266
|
-
function jsonHeld(value) {
|
|
267
|
-
if (typeof value === 'string')
|
|
268
|
-
return {
|
|
269
|
-
kind: dated(value) ? 'date' : instant(value) === undefined ? 'string' : 'time',
|
|
270
|
-
value,
|
|
271
|
-
};
|
|
272
|
-
if (typeof value === 'boolean')
|
|
273
|
-
return { kind: 'boolean', value };
|
|
274
|
-
return { kind: 'number', value };
|
|
275
|
-
}
|
|
276
|
-
function jsonRead(value) {
|
|
277
|
-
if (value === undefined)
|
|
278
|
-
return undefined;
|
|
279
|
-
if (scalar(value))
|
|
280
|
-
return single(jsonHeld(value));
|
|
281
|
-
if (!Array.isArray(value))
|
|
282
|
-
return single({ kind: 'prose' });
|
|
283
|
-
return { present: true, values: [], items: value.filter(scalar).map(jsonHeld), loose: true };
|
|
284
|
-
}
|
|
285
|
-
function readItem(item, path) {
|
|
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) {
|
|
314
|
-
if (!('value' in held))
|
|
315
|
-
return undefined;
|
|
316
|
-
const expected = wanted(value, owner);
|
|
317
|
-
if (typeof expected !== typeof held.value)
|
|
318
|
-
return undefined;
|
|
319
|
-
if (held.kind !== 'time')
|
|
320
|
-
return expected === held.value;
|
|
321
|
-
const left = instant(held.value);
|
|
322
|
-
const right = instant(expected);
|
|
323
|
-
return left === undefined || right === undefined ? undefined : left === right;
|
|
324
|
-
}
|
|
325
|
-
function sign(left, right) {
|
|
326
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
327
|
-
}
|
|
328
|
-
function ordered(held, value, compare) {
|
|
329
|
-
if (!('value' in held))
|
|
330
|
-
return undefined;
|
|
331
|
-
if (held.kind === 'number') {
|
|
332
|
-
if (typeof value !== 'number' || typeof held.value !== 'number')
|
|
333
|
-
return undefined;
|
|
334
|
-
return compare(Math.sign(held.value - value));
|
|
335
|
-
}
|
|
336
|
-
if (held.kind === 'date') {
|
|
337
|
-
if (!dated(value) || !dated(held.value))
|
|
338
|
-
return undefined;
|
|
339
|
-
return compare(sign(held.value, value));
|
|
340
|
-
}
|
|
341
|
-
if (held.kind !== 'time')
|
|
342
|
-
return undefined;
|
|
343
|
-
const at = instant(held.value);
|
|
344
|
-
const wanted = instant(value);
|
|
345
|
-
if (at === undefined || wanted === undefined)
|
|
346
|
-
return undefined;
|
|
347
|
-
return compare(sign(at, wanted));
|
|
348
|
-
}
|
|
349
|
-
function anyOf(truths) {
|
|
350
|
-
if (truths.some((truth) => truth === true))
|
|
351
|
-
return true;
|
|
352
|
-
return truths.some((truth) => truth === undefined) ? undefined : false;
|
|
353
|
-
}
|
|
354
|
-
function allOf(truths) {
|
|
355
|
-
if (truths.some((truth) => truth === false))
|
|
356
|
-
return false;
|
|
357
|
-
return truths.some((truth) => truth === undefined) ? undefined : true;
|
|
358
|
-
}
|
|
359
|
-
function compared(test, held, owner) {
|
|
360
|
-
if ('eq' in test)
|
|
361
|
-
return equal(held, test.eq, owner);
|
|
362
|
-
if ('in' in test)
|
|
363
|
-
return anyOf(test.in.map((value) => equal(held, value, owner)));
|
|
364
|
-
if ('prefix' in test) {
|
|
365
|
-
if (!('value' in held) || typeof held.value !== 'string')
|
|
366
|
-
return undefined;
|
|
367
|
-
if (held.kind === 'number' || held.kind === 'reference' || held.kind === 'member')
|
|
368
|
-
return undefined;
|
|
369
|
-
return held.value.startsWith(test.prefix);
|
|
370
|
-
}
|
|
371
|
-
if ('gt' in test)
|
|
372
|
-
return ordered(held, test.gt, (sign) => sign > 0);
|
|
373
|
-
if ('gte' in test)
|
|
374
|
-
return ordered(held, test.gte, (sign) => sign >= 0);
|
|
375
|
-
if ('lt' in test)
|
|
376
|
-
return ordered(held, test.lt, (sign) => sign < 0);
|
|
377
|
-
return ordered(held, test.lte, (sign) => sign <= 0);
|
|
378
|
-
}
|
|
379
|
-
function leaf(test, read, owner) {
|
|
380
|
-
if ('exists' in test) {
|
|
381
|
-
const present = read === undefined ? false : read.present;
|
|
382
|
-
return present === undefined ? undefined : present === test.exists;
|
|
383
|
-
}
|
|
384
|
-
if (read === undefined)
|
|
385
|
-
return undefined;
|
|
386
|
-
if ('contains' in test) {
|
|
387
|
-
if (read.items === null)
|
|
388
|
-
return undefined;
|
|
389
|
-
const truths = read.items.map((item) => item === undefined ? undefined : equal(item, test.contains, owner));
|
|
390
|
-
return read.loose === true && !truths.includes(true) ? false : anyOf(truths);
|
|
391
|
-
}
|
|
392
|
-
if (read.values.length === 0)
|
|
393
|
-
return read === NO_ITEM ? false : undefined;
|
|
394
|
-
return anyOf(read.values.map((value) => (value === undefined ? undefined : compared(test, value, owner))));
|
|
395
|
-
}
|
|
396
|
-
function evaluated(test, read, owner) {
|
|
397
|
-
if ('all' in test)
|
|
398
|
-
return allOf(test.all.map((part) => evaluated(part, read, owner)));
|
|
399
|
-
if ('any' in test)
|
|
400
|
-
return anyOf(test.any.map((part) => evaluated(part, read, owner)));
|
|
401
|
-
if ('not' in test) {
|
|
402
|
-
const truth = evaluated(test.not, read, owner);
|
|
403
|
-
return truth === undefined ? undefined : !truth;
|
|
404
|
-
}
|
|
405
|
-
return leaf(test, read(test.path), owner);
|
|
406
|
-
}
|
|
407
|
-
export function holds(test, document, owner) {
|
|
408
|
-
return evaluated(test, (path) => readDocument(document, path), owner);
|
|
409
|
-
}
|
|
410
|
-
function inScope(scope, document) {
|
|
411
|
-
if (document === null)
|
|
412
|
-
return false;
|
|
413
|
-
if ('type' in scope)
|
|
414
|
-
return document.type === scope.type;
|
|
415
|
-
if ('document' in scope)
|
|
416
|
-
return document.id === scope.document;
|
|
417
|
-
return scope.folder === '/' || document.path.startsWith(`${scope.folder}/`);
|
|
418
|
-
}
|
|
419
|
-
function matched(condition, test, document, owner) {
|
|
420
|
-
if (!inScope(condition.scope, document))
|
|
421
|
-
return false;
|
|
422
|
-
return test === undefined || holds(test, document, owner) === true;
|
|
423
|
-
}
|
|
424
|
-
function reachedAt(document, field) {
|
|
425
|
-
if (document === null)
|
|
426
|
-
return [];
|
|
427
|
-
if (field.startsWith('/sections/'))
|
|
428
|
-
return document.sections.includes(field.slice('/sections/'.length))
|
|
429
|
-
? [{ pointer: field, fact: PROSE }]
|
|
430
|
-
: [];
|
|
431
|
-
if (!field.startsWith('/fields/'))
|
|
432
|
-
return [];
|
|
433
|
-
return walked(rootOf(document, '/fields'), field.slice('/fields'.length)).reached;
|
|
434
|
-
}
|
|
435
|
-
function valueOf(fact) {
|
|
436
|
-
if (fact.kind === 'list')
|
|
437
|
-
return { kind: fact.kind, items: fact.items.map(valueOf) };
|
|
438
|
-
if (fact.kind === 'object')
|
|
439
|
-
return {
|
|
440
|
-
kind: fact.kind,
|
|
441
|
-
fields: Object.keys(fact.fields)
|
|
442
|
-
.sort()
|
|
443
|
-
.map((key) => [key, valueOf(fact.fields[key])]),
|
|
444
|
-
};
|
|
445
|
-
if (fact.kind === 'time') {
|
|
446
|
-
const at = instant(fact.value);
|
|
447
|
-
if (at !== undefined)
|
|
448
|
-
return { kind: fact.kind, at: String(at) };
|
|
449
|
-
}
|
|
450
|
-
return 'value' in fact ? { kind: fact.kind, value: fact.value } : fact;
|
|
451
|
-
}
|
|
452
|
-
function signature(reached) {
|
|
453
|
-
return JSON.stringify(reached.map(({ fact }) => valueOf(fact)));
|
|
454
|
-
}
|
|
455
|
-
function among(values, document, field, owner) {
|
|
456
|
-
return holds({ path: field, in: values }, document, owner) === true;
|
|
457
|
-
}
|
|
458
|
-
function fieldChanged(condition, event, owner) {
|
|
459
|
-
const { field, from, to } = condition;
|
|
460
|
-
const before = reachedAt(event.before, field);
|
|
461
|
-
const after = reachedAt(event.after, field);
|
|
462
|
-
const pointers = [field, ...[...before, ...after].map(({ pointer }) => pointer)];
|
|
463
|
-
const prose = event.changed.some((changed) => pointers.some((pointer) => changed === pointer || changed.startsWith(`${pointer}/`)));
|
|
464
|
-
if (from === undefined && to === undefined && prose)
|
|
465
|
-
return true;
|
|
466
|
-
if (before.length === 0 && after.length === 0)
|
|
467
|
-
return false;
|
|
468
|
-
if (event.before !== null && event.after !== null && signature(before) === signature(after))
|
|
469
|
-
return false;
|
|
470
|
-
if (from === 'new'
|
|
471
|
-
? event.before !== null
|
|
472
|
-
: from !== undefined && (event.before === null || !among(from, event.before, field, owner)))
|
|
473
|
-
return false;
|
|
474
|
-
if (to === 'deleted'
|
|
475
|
-
? event.after !== null
|
|
476
|
-
: to !== undefined && (event.after === null || !among(to, event.after, field, owner)))
|
|
477
|
-
return false;
|
|
478
|
-
return true;
|
|
479
|
-
}
|
|
480
|
-
export function fires(condition, event, owner) {
|
|
481
|
-
if (condition.by !== undefined &&
|
|
482
|
-
evaluated(condition.by, (path) => readActor(event.by, path), owner) !== true)
|
|
483
|
-
return false;
|
|
484
|
-
if (condition.mode === 'starts_matching') {
|
|
485
|
-
if (event.before === null && !condition.new_documents)
|
|
486
|
-
return false;
|
|
487
|
-
return (matched(condition, condition.match, event.after, owner) &&
|
|
488
|
-
!matched(condition, condition.match, event.before, owner));
|
|
489
|
-
}
|
|
490
|
-
const side = event.after ?? event.before;
|
|
491
|
-
return matched(condition, condition.match, side, owner) && fieldChanged(condition, event, owner);
|
|
492
|
-
}
|
|
493
|
-
export function itemFires(condition, item, owner) {
|
|
494
|
-
if (condition.source !== undefined && item.source !== condition.source)
|
|
495
|
-
return false;
|
|
496
|
-
if (condition.address !== undefined && item.address !== condition.address)
|
|
497
|
-
return false;
|
|
498
|
-
return (condition.match === undefined ||
|
|
499
|
-
evaluated(condition.match, (path) => readItem(item, path), owner) === true);
|
|
500
|
-
}
|