@agentshouse/mdmodel 0.1.0-alpha.8 → 0.1.0-c6b0c6dc1a195
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 +298 -0
- package/README.md +30 -172
- package/dist/blocks.d.ts +11 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +62 -0
- package/dist/condition.d.ts +133 -0
- package/dist/condition.d.ts.map +1 -0
- package/dist/condition.js +363 -0
- package/dist/definition.d.ts +15 -9
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +148 -133
- package/dist/divide.d.ts +3 -0
- package/dist/divide.d.ts.map +1 -0
- package/dist/divide.js +310 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +89 -120
- package/dist/fields.d.ts +4 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +618 -224
- package/dist/paths.d.ts +2 -3
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +27 -37
- package/dist/profile.js +1 -3
- package/dist/project.d.ts +19 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +83 -73
- package/dist/refuse.d.ts.map +1 -1
- package/dist/refuse.js +2 -10
- package/dist/schema.d.ts +3 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +24 -33
- package/dist/sections.d.ts +2 -1
- package/dist/sections.d.ts.map +1 -1
- package/dist/sections.js +45 -67
- package/dist/types.d.ts +30 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -3
- package/dist/validate.d.ts +5 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +145 -122
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -3
- package/dist/yaml.d.ts +1 -0
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +196 -187
- package/fixtures/README.md +77 -52
- package/fixtures/cases/binary-any-reference/expected.json +0 -1
- package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-document-collision/expected.json +1 -2
- package/fixtures/cases/binary-document-collision/schema.yaml +2 -0
- package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
- package/fixtures/cases/binary-link-outside-collection/schema.yaml +2 -0
- package/fixtures/cases/binary-prototype-reference/expected.json +0 -1
- package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-typed-reference/expected.json +0 -1
- package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
- package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
- package/fixtures/cases/declared-binary-links/schema.yaml +2 -0
- package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
- package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
- package/fixtures/cases/field-enum/expected.json +1 -2
- package/fixtures/cases/field-enum/schema.yaml +7 -0
- package/fixtures/cases/frontmatter-schema/expected.json +5 -0
- package/fixtures/cases/frontmatter-schema/schema.yaml +6 -0
- package/fixtures/cases/interrupted-link-definition/schema.yaml +2 -0
- package/fixtures/cases/long-fence-link-definition/schema.yaml +2 -0
- package/fixtures/cases/malformed-definition/expected.json +2 -4
- package/fixtures/cases/malformed-definition/schema.yaml +4 -0
- package/fixtures/cases/member-document/context.json +1 -0
- package/fixtures/cases/member-document/library/people/ana.md +5 -0
- package/fixtures/cases/member-document/schema.yaml +5 -0
- package/fixtures/cases/missing-binary-image/expected.json +1 -2
- package/fixtures/cases/missing-binary-image/schema.yaml +2 -0
- package/fixtures/cases/missing-binary-link/expected.json +1 -2
- package/fixtures/cases/missing-binary-link/schema.yaml +2 -0
- package/fixtures/cases/missing-required-field/expected.json +1 -2
- package/fixtures/cases/missing-required-field/schema.yaml +7 -0
- package/fixtures/cases/missing-section-item-kind/context.json +1 -0
- package/fixtures/cases/missing-section-item-kind/expected.json +5 -0
- package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
- package/fixtures/cases/paragraph-link-definition/schema.yaml +2 -0
- package/fixtures/cases/prototype-field/context.json +1 -0
- package/fixtures/cases/prototype-field/expected.json +6 -0
- package/fixtures/cases/prototype-field/library/item.md +9 -0
- package/fixtures/cases/prototype-field/schema.yaml +6 -0
- package/fixtures/cases/quoted-link-definition/expected.json +1 -2
- package/fixtures/cases/quoted-link-definition/schema.yaml +2 -0
- package/fixtures/cases/referenced-missing-file/expected.json +0 -1
- package/fixtures/cases/referenced-missing-file/schema.yaml +10 -0
- package/fixtures/cases/second-member-document/context.json +1 -0
- package/fixtures/cases/second-member-document/expected.json +5 -0
- package/fixtures/cases/second-member-document/schema.yaml +5 -0
- package/fixtures/cases/section-item-enum/context.json +1 -0
- package/fixtures/cases/section-item-enum/expected.json +6 -0
- package/fixtures/cases/section-item-enum/library/task.md +8 -0
- package/fixtures/cases/section-item-enum/schema.yaml +4 -0
- package/fixtures/cases/section-item-kind/context.json +1 -0
- package/fixtures/cases/section-item-kind/expected.json +6 -0
- package/fixtures/cases/section-item-kind/library/task.md +8 -0
- package/fixtures/cases/section-item-kind/schema.yaml +4 -0
- package/fixtures/cases/section-items/context.json +1 -0
- package/fixtures/cases/section-items/expected.json +1 -0
- package/fixtures/cases/section-items/library/other.md +3 -0
- package/fixtures/cases/section-items/library/page.md +28 -0
- package/fixtures/cases/section-items/schema.yaml +8 -0
- package/fixtures/cases/section-reference-path/context.json +1 -0
- package/fixtures/cases/section-reference-path/expected.json +6 -0
- package/fixtures/cases/section-reference-path/library/other.md +3 -0
- package/fixtures/cases/section-reference-path/library/page.md +7 -0
- package/fixtures/cases/section-reference-path/schema.yaml +4 -0
- package/fixtures/cases/section-reference-type/context.json +1 -0
- package/fixtures/cases/section-reference-type/expected.json +6 -0
- package/fixtures/cases/section-reference-type/library/note.md +1 -0
- package/fixtures/cases/section-reference-type/library/page.md +7 -0
- package/fixtures/cases/section-reference-type/schema.yaml +4 -0
- package/fixtures/cases/shortcut-reference-link/context.json +1 -0
- package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
- package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
- package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
- package/fixtures/cases/structured-section/expected.json +1 -2
- package/fixtures/cases/structured-section/schema.yaml +7 -0
- package/fixtures/cases/submission-keys/context.json +1 -0
- package/fixtures/cases/submission-keys/expected.json +1 -0
- package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
- package/fixtures/cases/submission-keys/schema.yaml +4 -0
- package/fixtures/cases/text-field-kind/context.json +1 -0
- package/fixtures/cases/text-field-kind/expected.json +6 -0
- package/fixtures/cases/text-field-kind/library/page.md +4 -0
- package/fixtures/cases/text-field-kind/schema.yaml +4 -0
- package/fixtures/cases/truncated-link-definition/expected.json +1 -2
- package/fixtures/cases/truncated-link-definition/schema.yaml +2 -0
- package/fixtures/cases/types-folder-content/context.json +1 -0
- package/fixtures/cases/types-folder-content/expected.json +1 -0
- package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
- package/fixtures/cases/types-folder-content/schema.yaml +4 -0
- package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
- package/fixtures/cases/undeclared-field/context.json +1 -0
- package/fixtures/cases/undeclared-field/expected.json +6 -0
- package/fixtures/cases/undeclared-field/library/item.md +9 -0
- package/fixtures/cases/undeclared-field/schema.yaml +6 -0
- package/fixtures/cases/unknown-type/context.json +1 -0
- package/fixtures/cases/unknown-type/expected.json +6 -0
- package/fixtures/cases/unknown-type/library/item.md +3 -0
- package/fixtures/cases/unknown-type/schema.yaml +4 -0
- package/fixtures/cases/unlisted-reference-type/context.json +1 -0
- package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
- package/fixtures/cases/unlisted-reference-type/schema.yaml +4 -0
- package/fixtures/cases/unresolved-link/expected.json +1 -2
- package/fixtures/cases/unresolved-link/schema.yaml +6 -0
- package/fixtures/cases/valid-typed-document/library/tasks/one.md +1 -0
- package/fixtures/cases/valid-typed-document/schema.yaml +15 -0
- package/fixtures/cases/wide-item-fence-link/schema.yaml +2 -0
- package/fixtures/division.json +409 -0
- package/fixtures/projection.json +77 -28
- package/package.json +3 -12
- package/dist/definition.js.map +0 -1
- package/dist/document.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/links.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/profile.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/refuse.js.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/sections.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/yaml.js.map +0 -1
- package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
- package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
- package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
- package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
- package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/field-enum/library/types/task.md +0 -8
- package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
- package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
- package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
- package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
- package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/prd-definition/library/types/task.md +0 -15
- package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
- package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
- package/fixtures/cases/structured-section/library/types/task.md +0 -8
- package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
- package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
- package/fixtures/cases/valid-typed-document/library/types/task.md +0 -12
- package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
- package/markdown-syntax-profile.md +0 -9
- /package/fixtures/cases/{prd-definition → frontmatter-schema}/context.json +0 -0
- /package/fixtures/cases/{prd-definition → member-document}/expected.json +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Document, VerifiedModel } from './types.js';
|
|
2
|
+
export type ConditionValue = string | number | boolean | {
|
|
3
|
+
readonly owner: true;
|
|
4
|
+
};
|
|
5
|
+
export type ConditionTest = {
|
|
6
|
+
readonly all: readonly ConditionTest[];
|
|
7
|
+
} | {
|
|
8
|
+
readonly any: readonly ConditionTest[];
|
|
9
|
+
} | {
|
|
10
|
+
readonly not: ConditionTest;
|
|
11
|
+
} | ({
|
|
12
|
+
readonly path: string;
|
|
13
|
+
} & ({
|
|
14
|
+
readonly eq: ConditionValue;
|
|
15
|
+
} | {
|
|
16
|
+
readonly in: readonly ConditionValue[];
|
|
17
|
+
} | {
|
|
18
|
+
readonly exists: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
readonly contains: ConditionValue;
|
|
21
|
+
} | {
|
|
22
|
+
readonly gt: number | string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly gte: number | string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly lt: number | string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly lte: number | string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly prefix: string;
|
|
31
|
+
}));
|
|
32
|
+
export type ConditionScope = {
|
|
33
|
+
readonly type: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly folder: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly document: string;
|
|
38
|
+
};
|
|
39
|
+
type DocumentEventBase = {
|
|
40
|
+
readonly on: 'documents';
|
|
41
|
+
readonly scope: ConditionScope;
|
|
42
|
+
readonly by?: ConditionTest;
|
|
43
|
+
};
|
|
44
|
+
export type DocumentCondition = (DocumentEventBase & {
|
|
45
|
+
readonly mode: 'starts_matching';
|
|
46
|
+
readonly new_documents: boolean;
|
|
47
|
+
readonly match: ConditionTest;
|
|
48
|
+
}) | (DocumentEventBase & {
|
|
49
|
+
readonly mode: 'field_changes';
|
|
50
|
+
readonly field: string;
|
|
51
|
+
readonly from?: readonly ConditionValue[] | 'new';
|
|
52
|
+
readonly to?: readonly ConditionValue[] | 'deleted';
|
|
53
|
+
readonly match?: ConditionTest;
|
|
54
|
+
});
|
|
55
|
+
export type ItemCondition = {
|
|
56
|
+
readonly on: 'items';
|
|
57
|
+
readonly source?: string;
|
|
58
|
+
readonly address?: string;
|
|
59
|
+
readonly match?: ConditionTest;
|
|
60
|
+
};
|
|
61
|
+
export type CronCondition = {
|
|
62
|
+
readonly on: 'clock';
|
|
63
|
+
readonly cron: string;
|
|
64
|
+
readonly time_zone: string;
|
|
65
|
+
};
|
|
66
|
+
export type DateCondition = {
|
|
67
|
+
readonly on: 'clock';
|
|
68
|
+
readonly scope: {
|
|
69
|
+
readonly type: string;
|
|
70
|
+
};
|
|
71
|
+
readonly date: string;
|
|
72
|
+
readonly days: number;
|
|
73
|
+
readonly at: string;
|
|
74
|
+
readonly time_zone: string;
|
|
75
|
+
readonly match?: ConditionTest;
|
|
76
|
+
};
|
|
77
|
+
export type Condition = DocumentCondition | ItemCondition | CronCondition | DateCondition;
|
|
78
|
+
export type Fact = {
|
|
79
|
+
readonly kind: 'string' | 'number' | 'date' | 'enum' | 'reference';
|
|
80
|
+
readonly value: string | number | readonly (string | number)[];
|
|
81
|
+
};
|
|
82
|
+
export type DocumentFacts = {
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly path: string;
|
|
85
|
+
readonly type: string | null;
|
|
86
|
+
readonly fields: Readonly<Record<string, Fact>>;
|
|
87
|
+
readonly members: Readonly<Record<string, string | readonly string[]>>;
|
|
88
|
+
readonly prose: readonly string[];
|
|
89
|
+
readonly unreadable: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
export declare const WRITE_DOORS: readonly ['browser', 'agent', 'client'];
|
|
92
|
+
export type WriteDoor = (typeof WRITE_DOORS)[number];
|
|
93
|
+
export type Actor = {
|
|
94
|
+
readonly user?: string;
|
|
95
|
+
readonly site?: string;
|
|
96
|
+
readonly door?: WriteDoor;
|
|
97
|
+
};
|
|
98
|
+
export type DocumentEvent = {
|
|
99
|
+
readonly before: DocumentFacts | null;
|
|
100
|
+
readonly after: DocumentFacts | null;
|
|
101
|
+
readonly changed: readonly string[];
|
|
102
|
+
readonly by: Actor;
|
|
103
|
+
};
|
|
104
|
+
export type ItemFacts = {
|
|
105
|
+
readonly delivery: string;
|
|
106
|
+
readonly source: string | null;
|
|
107
|
+
readonly address: string | null;
|
|
108
|
+
readonly has_attachment: boolean;
|
|
109
|
+
readonly provider: string | null;
|
|
110
|
+
readonly container: string | null;
|
|
111
|
+
readonly author: string | null;
|
|
112
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
113
|
+
readonly json: {
|
|
114
|
+
readonly value: unknown;
|
|
115
|
+
} | null;
|
|
116
|
+
};
|
|
117
|
+
export type Resolved = {
|
|
118
|
+
readonly id: string;
|
|
119
|
+
readonly member?: string;
|
|
120
|
+
};
|
|
121
|
+
type Truth = boolean | undefined;
|
|
122
|
+
export declare function facts(document: Document, at: {
|
|
123
|
+
readonly id: string;
|
|
124
|
+
readonly path: string;
|
|
125
|
+
}, model: VerifiedModel, resolve: (target: string) => Resolved | undefined): DocumentFacts;
|
|
126
|
+
export declare function dated(value: unknown): value is string;
|
|
127
|
+
export declare function instant(value: unknown): bigint | undefined;
|
|
128
|
+
export declare function pointed(value: unknown, pointer: string): unknown;
|
|
129
|
+
export declare function holds(test: ConditionTest, document: DocumentFacts, owner: string): Truth;
|
|
130
|
+
export declare function fires(condition: DocumentCondition, event: DocumentEvent, owner: string): boolean;
|
|
131
|
+
export declare function itemFires(condition: ItemCondition, item: ItemFacts, owner: string): boolean;
|
|
132
|
+
export {};
|
|
133
|
+
//# sourceMappingURL=condition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../src/condition.ts"],"names":[],"mappings":"AAGA,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,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,EAAE,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAChC;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GACjC;IA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AAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3F"}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { target } from './paths.js';
|
|
2
|
+
import { fitsValue } from './schema.js';
|
|
3
|
+
import { declaredFields } from './validate.js';
|
|
4
|
+
export const WRITE_DOORS = ['browser', 'agent', 'client'];
|
|
5
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/u;
|
|
6
|
+
const DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/u;
|
|
7
|
+
const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
8
|
+
function record(value) {
|
|
9
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function referenced(model, spec) {
|
|
12
|
+
const to = spec.kind === 'reference'
|
|
13
|
+
? spec.to
|
|
14
|
+
: spec.kind === 'list' && spec.of.kind === 'reference'
|
|
15
|
+
? spec.of.to
|
|
16
|
+
: null;
|
|
17
|
+
return to !== null && Object.hasOwn(model.types, to) && model.types[to].memberDocument;
|
|
18
|
+
}
|
|
19
|
+
function fitted(spec, value, path, resolve) {
|
|
20
|
+
if (!fitsValue(spec, value))
|
|
21
|
+
return undefined;
|
|
22
|
+
if (spec.kind !== 'reference')
|
|
23
|
+
return { value: value };
|
|
24
|
+
const reached = target(path, value);
|
|
25
|
+
return reached === null ? undefined : resolve(reached);
|
|
26
|
+
}
|
|
27
|
+
export function facts(document, at, model, resolve) {
|
|
28
|
+
const type = document.type ?? null;
|
|
29
|
+
const definition = type !== null && Object.hasOwn(model.types, type) ? model.types[type] : null;
|
|
30
|
+
const fields = {};
|
|
31
|
+
const members = {};
|
|
32
|
+
const prose = Object.keys(document.sections).map((heading) => `/sections/${heading}`);
|
|
33
|
+
const unreadable = [];
|
|
34
|
+
for (const [name, spec] of Object.entries(definition === null ? {} : declaredFields(definition))) {
|
|
35
|
+
const value = document.fields[name];
|
|
36
|
+
if (value === undefined || value === null)
|
|
37
|
+
continue;
|
|
38
|
+
const scalar = spec.kind === 'list' ? spec.of : spec;
|
|
39
|
+
const items = spec.kind === 'list' ? value : [value];
|
|
40
|
+
const held = Array.isArray(items)
|
|
41
|
+
? items.map((item) => fitted(scalar, item, at.path, resolve))
|
|
42
|
+
: [undefined];
|
|
43
|
+
if (held.some((item) => item === undefined)) {
|
|
44
|
+
unreadable.push(`/fields/${name}`);
|
|
45
|
+
if (referenced(model, spec))
|
|
46
|
+
unreadable.push(`/members/${name}`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (scalar.kind === 'text') {
|
|
50
|
+
prose.push(`/fields/${name}`);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const values = held.map((item) => ('id' in item ? item.id : item.value));
|
|
54
|
+
fields[name] = { kind: scalar.kind, value: spec.kind === 'list' ? values : values[0] };
|
|
55
|
+
if (!referenced(model, spec))
|
|
56
|
+
continue;
|
|
57
|
+
const bound = held.flatMap((item) => 'member' in item && item.member !== undefined ? [item.member] : []);
|
|
58
|
+
if (spec.kind === 'list')
|
|
59
|
+
members[name] = bound;
|
|
60
|
+
else if (bound[0] !== undefined)
|
|
61
|
+
members[name] = bound[0];
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
id: at.id,
|
|
65
|
+
path: `/${at.path}`,
|
|
66
|
+
type,
|
|
67
|
+
fields,
|
|
68
|
+
members,
|
|
69
|
+
prose: prose.sort(),
|
|
70
|
+
unreadable: unreadable.sort(),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function readDocument(facts, path) {
|
|
74
|
+
if (path === '/path')
|
|
75
|
+
return { kind: 'path', value: facts.path };
|
|
76
|
+
if (path === '/type')
|
|
77
|
+
return facts.type === null ? undefined : { kind: 'string', value: facts.type };
|
|
78
|
+
if (facts.unreadable.includes(path))
|
|
79
|
+
return { kind: 'unreadable' };
|
|
80
|
+
if (facts.prose.includes(path))
|
|
81
|
+
return { kind: 'present' };
|
|
82
|
+
if (path.startsWith('/fields/')) {
|
|
83
|
+
const name = path.slice('/fields/'.length);
|
|
84
|
+
return Object.hasOwn(facts.fields, name) ? facts.fields[name] : undefined;
|
|
85
|
+
}
|
|
86
|
+
if (path.startsWith('/members/')) {
|
|
87
|
+
const name = path.slice('/members/'.length);
|
|
88
|
+
return Object.hasOwn(facts.members, name)
|
|
89
|
+
? { kind: 'member', value: facts.members[name] }
|
|
90
|
+
: undefined;
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
function readActor(actor, path) {
|
|
95
|
+
const value = path === '/user'
|
|
96
|
+
? actor.user
|
|
97
|
+
: path === '/site'
|
|
98
|
+
? actor.site
|
|
99
|
+
: path === '/door'
|
|
100
|
+
? actor.door
|
|
101
|
+
: undefined;
|
|
102
|
+
return value === undefined ? undefined : { kind: 'actor', value };
|
|
103
|
+
}
|
|
104
|
+
function plain(value) {
|
|
105
|
+
if (!record(value))
|
|
106
|
+
return false;
|
|
107
|
+
const prototype = Object.getPrototypeOf(value);
|
|
108
|
+
return prototype === Object.prototype || prototype === null;
|
|
109
|
+
}
|
|
110
|
+
export function dated(value) {
|
|
111
|
+
return (typeof value === 'string' && DATE.test(value) && instant(`${value}T00:00:00Z`) !== undefined);
|
|
112
|
+
}
|
|
113
|
+
export function instant(value) {
|
|
114
|
+
if (typeof value !== 'string')
|
|
115
|
+
return undefined;
|
|
116
|
+
const parts = DATE_TIME.exec(value);
|
|
117
|
+
if (parts === null)
|
|
118
|
+
return undefined;
|
|
119
|
+
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
120
|
+
1, 2, 3, 4, 5, 6, 9, 10,
|
|
121
|
+
].map((at) => Number(parts[at] ?? 0));
|
|
122
|
+
const at = new Date(0);
|
|
123
|
+
at.setUTCFullYear(year, month - 1, day);
|
|
124
|
+
at.setUTCHours(hour, minute, second);
|
|
125
|
+
if (at.getUTCFullYear() !== year ||
|
|
126
|
+
at.getUTCMonth() !== month - 1 ||
|
|
127
|
+
at.getUTCDate() !== day ||
|
|
128
|
+
at.getUTCHours() !== hour ||
|
|
129
|
+
at.getUTCMinutes() !== minute ||
|
|
130
|
+
offsetHours > 23 ||
|
|
131
|
+
offsetMinutes > 59)
|
|
132
|
+
return undefined;
|
|
133
|
+
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
134
|
+
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
135
|
+
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
136
|
+
}
|
|
137
|
+
export function pointed(value, pointer) {
|
|
138
|
+
if (pointer === '')
|
|
139
|
+
return value;
|
|
140
|
+
let reached = value;
|
|
141
|
+
for (const part of pointer.slice(1).split('/')) {
|
|
142
|
+
const token = part.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
143
|
+
if (Array.isArray(reached)) {
|
|
144
|
+
if (!ARRAY_INDEX.test(token))
|
|
145
|
+
return undefined;
|
|
146
|
+
reached = reached[Number(token)];
|
|
147
|
+
}
|
|
148
|
+
else if (plain(reached) && Object.hasOwn(reached, token)) {
|
|
149
|
+
reached = reached[token];
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return reached;
|
|
156
|
+
}
|
|
157
|
+
function scalar(value) {
|
|
158
|
+
return (typeof value === 'string' ||
|
|
159
|
+
typeof value === 'boolean' ||
|
|
160
|
+
(typeof value === 'number' && Number.isFinite(value)));
|
|
161
|
+
}
|
|
162
|
+
function jsonHeld(value) {
|
|
163
|
+
if (value === undefined)
|
|
164
|
+
return undefined;
|
|
165
|
+
if (typeof value === 'string')
|
|
166
|
+
return {
|
|
167
|
+
kind: dated(value) ? 'date' : instant(value) === undefined ? 'string' : 'time',
|
|
168
|
+
value,
|
|
169
|
+
};
|
|
170
|
+
if (typeof value === 'boolean')
|
|
171
|
+
return { kind: 'boolean', value };
|
|
172
|
+
if (scalar(value))
|
|
173
|
+
return { kind: 'number', value };
|
|
174
|
+
if (Array.isArray(value))
|
|
175
|
+
return { kind: 'list', value: value.filter(scalar) };
|
|
176
|
+
return { kind: 'present' };
|
|
177
|
+
}
|
|
178
|
+
function readItem(item, path) {
|
|
179
|
+
if (path.startsWith('/json/')) {
|
|
180
|
+
if (item.json === null)
|
|
181
|
+
return { kind: 'unreadable' };
|
|
182
|
+
return jsonHeld(pointed(item.json.value, path.slice('/json'.length)));
|
|
183
|
+
}
|
|
184
|
+
if (path.startsWith('/headers/')) {
|
|
185
|
+
const name = path.slice('/headers/'.length);
|
|
186
|
+
return Object.hasOwn(item.headers, name)
|
|
187
|
+
? { kind: 'string', value: item.headers[name] }
|
|
188
|
+
: undefined;
|
|
189
|
+
}
|
|
190
|
+
if (path === '/has_attachment')
|
|
191
|
+
return { kind: 'boolean', value: item.has_attachment };
|
|
192
|
+
const value = path === '/delivery'
|
|
193
|
+
? item.delivery
|
|
194
|
+
: path === '/source'
|
|
195
|
+
? item.source
|
|
196
|
+
: path === '/provider'
|
|
197
|
+
? item.provider
|
|
198
|
+
: path === '/container'
|
|
199
|
+
? item.container
|
|
200
|
+
: path === '/author'
|
|
201
|
+
? item.author
|
|
202
|
+
: null;
|
|
203
|
+
return value === null ? undefined : { kind: 'string', value };
|
|
204
|
+
}
|
|
205
|
+
function wanted(value, owner) {
|
|
206
|
+
return record(value) && value.owner === true ? owner : value;
|
|
207
|
+
}
|
|
208
|
+
function equal(held, value, owner) {
|
|
209
|
+
if (held.kind === 'present' || Array.isArray(held.value))
|
|
210
|
+
return undefined;
|
|
211
|
+
const expected = wanted(value, owner);
|
|
212
|
+
if (typeof expected !== typeof held.value)
|
|
213
|
+
return undefined;
|
|
214
|
+
return expected === held.value;
|
|
215
|
+
}
|
|
216
|
+
function sign(left, right) {
|
|
217
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
218
|
+
}
|
|
219
|
+
function ordered(held, value, compare) {
|
|
220
|
+
if (held.kind === 'present' || Array.isArray(held.value))
|
|
221
|
+
return undefined;
|
|
222
|
+
if (held.kind === 'number') {
|
|
223
|
+
if (typeof value !== 'number' || typeof held.value !== 'number')
|
|
224
|
+
return undefined;
|
|
225
|
+
return compare(Math.sign(held.value - value));
|
|
226
|
+
}
|
|
227
|
+
if (held.kind === 'date') {
|
|
228
|
+
if (!dated(value) || !dated(held.value))
|
|
229
|
+
return undefined;
|
|
230
|
+
return compare(sign(held.value, value));
|
|
231
|
+
}
|
|
232
|
+
if (held.kind !== 'time')
|
|
233
|
+
return undefined;
|
|
234
|
+
const at = instant(held.value);
|
|
235
|
+
const wanted = instant(value);
|
|
236
|
+
if (at === undefined || wanted === undefined)
|
|
237
|
+
return undefined;
|
|
238
|
+
return compare(sign(at, wanted));
|
|
239
|
+
}
|
|
240
|
+
function anyOf(truths) {
|
|
241
|
+
if (truths.some((truth) => truth === true))
|
|
242
|
+
return true;
|
|
243
|
+
return truths.some((truth) => truth === undefined) ? undefined : false;
|
|
244
|
+
}
|
|
245
|
+
function allOf(truths) {
|
|
246
|
+
if (truths.some((truth) => truth === false))
|
|
247
|
+
return false;
|
|
248
|
+
return truths.some((truth) => truth === undefined) ? undefined : true;
|
|
249
|
+
}
|
|
250
|
+
function leaf(test, held, owner) {
|
|
251
|
+
if (held?.kind === 'unreadable')
|
|
252
|
+
return undefined;
|
|
253
|
+
if ('exists' in test)
|
|
254
|
+
return (held !== undefined) === test.exists;
|
|
255
|
+
if (held === undefined)
|
|
256
|
+
return undefined;
|
|
257
|
+
if ('eq' in test)
|
|
258
|
+
return equal(held, test.eq, owner);
|
|
259
|
+
if ('in' in test)
|
|
260
|
+
return anyOf(test.in.map((value) => equal(held, value, owner)));
|
|
261
|
+
if ('contains' in test) {
|
|
262
|
+
if (held.kind === 'present' || !Array.isArray(held.value))
|
|
263
|
+
return undefined;
|
|
264
|
+
const expected = wanted(test.contains, owner);
|
|
265
|
+
if (held.value.some((item) => item === expected))
|
|
266
|
+
return true;
|
|
267
|
+
if (held.kind === 'list')
|
|
268
|
+
return false;
|
|
269
|
+
return held.value.every((item) => typeof item === typeof expected) ? false : undefined;
|
|
270
|
+
}
|
|
271
|
+
if ('prefix' in test) {
|
|
272
|
+
if (held.kind === 'present' || typeof held.value !== 'string')
|
|
273
|
+
return undefined;
|
|
274
|
+
if (held.kind === 'number' || held.kind === 'reference' || held.kind === 'member')
|
|
275
|
+
return undefined;
|
|
276
|
+
return held.value.startsWith(test.prefix);
|
|
277
|
+
}
|
|
278
|
+
if ('gt' in test)
|
|
279
|
+
return ordered(held, test.gt, (sign) => sign > 0);
|
|
280
|
+
if ('gte' in test)
|
|
281
|
+
return ordered(held, test.gte, (sign) => sign >= 0);
|
|
282
|
+
if ('lt' in test)
|
|
283
|
+
return ordered(held, test.lt, (sign) => sign < 0);
|
|
284
|
+
return ordered(held, test.lte, (sign) => sign <= 0);
|
|
285
|
+
}
|
|
286
|
+
function evaluated(test, read, owner) {
|
|
287
|
+
if ('all' in test)
|
|
288
|
+
return allOf(test.all.map((part) => evaluated(part, read, owner)));
|
|
289
|
+
if ('any' in test)
|
|
290
|
+
return anyOf(test.any.map((part) => evaluated(part, read, owner)));
|
|
291
|
+
if ('not' in test) {
|
|
292
|
+
const truth = evaluated(test.not, read, owner);
|
|
293
|
+
return truth === undefined ? undefined : !truth;
|
|
294
|
+
}
|
|
295
|
+
return leaf(test, read(test.path), owner);
|
|
296
|
+
}
|
|
297
|
+
export function holds(test, document, owner) {
|
|
298
|
+
return evaluated(test, (path) => readDocument(document, path), owner);
|
|
299
|
+
}
|
|
300
|
+
function inScope(scope, document) {
|
|
301
|
+
if (document === null)
|
|
302
|
+
return false;
|
|
303
|
+
if ('type' in scope)
|
|
304
|
+
return document.type === scope.type;
|
|
305
|
+
if ('document' in scope)
|
|
306
|
+
return document.id === scope.document;
|
|
307
|
+
return scope.folder === '/' || document.path.startsWith(`${scope.folder}/`);
|
|
308
|
+
}
|
|
309
|
+
function matched(condition, test, document, owner) {
|
|
310
|
+
if (!inScope(condition.scope, document))
|
|
311
|
+
return false;
|
|
312
|
+
return test === undefined || holds(test, document, owner) === true;
|
|
313
|
+
}
|
|
314
|
+
function sameFact(left, right) {
|
|
315
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
316
|
+
}
|
|
317
|
+
function among(values, document, field, owner) {
|
|
318
|
+
return holds({ path: field, in: values }, document, owner) === true;
|
|
319
|
+
}
|
|
320
|
+
function fieldChanged(condition, event, owner) {
|
|
321
|
+
const { field, from, to } = condition;
|
|
322
|
+
if (from === undefined && to === undefined && event.changed.includes(field))
|
|
323
|
+
return true;
|
|
324
|
+
if (!field.startsWith('/fields/'))
|
|
325
|
+
return false;
|
|
326
|
+
const name = field.slice('/fields/'.length);
|
|
327
|
+
const before = event.before?.fields[name];
|
|
328
|
+
const after = event.after?.fields[name];
|
|
329
|
+
if (before === undefined && after === undefined)
|
|
330
|
+
return false;
|
|
331
|
+
if (event.before !== null && event.after !== null && sameFact(before, after))
|
|
332
|
+
return false;
|
|
333
|
+
if (from === 'new'
|
|
334
|
+
? event.before !== null
|
|
335
|
+
: from !== undefined && (event.before === null || !among(from, event.before, field, owner)))
|
|
336
|
+
return false;
|
|
337
|
+
if (to === 'deleted'
|
|
338
|
+
? event.after !== null
|
|
339
|
+
: to !== undefined && (event.after === null || !among(to, event.after, field, owner)))
|
|
340
|
+
return false;
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
export function fires(condition, event, owner) {
|
|
344
|
+
if (condition.by !== undefined &&
|
|
345
|
+
evaluated(condition.by, (path) => readActor(event.by, path), owner) !== true)
|
|
346
|
+
return false;
|
|
347
|
+
if (condition.mode === 'starts_matching') {
|
|
348
|
+
if (event.before === null && !condition.new_documents)
|
|
349
|
+
return false;
|
|
350
|
+
return (matched(condition, condition.match, event.after, owner) &&
|
|
351
|
+
!matched(condition, condition.match, event.before, owner));
|
|
352
|
+
}
|
|
353
|
+
const side = event.after ?? event.before;
|
|
354
|
+
return matched(condition, condition.match, side, owner) && fieldChanged(condition, event, owner);
|
|
355
|
+
}
|
|
356
|
+
export function itemFires(condition, item, owner) {
|
|
357
|
+
if (condition.source !== undefined && item.source !== condition.source)
|
|
358
|
+
return false;
|
|
359
|
+
if (condition.address !== undefined && item.address !== condition.address)
|
|
360
|
+
return false;
|
|
361
|
+
return (condition.match === undefined ||
|
|
362
|
+
evaluated(condition.match, (path) => readItem(item, path), owner) === true);
|
|
363
|
+
}
|
package/dist/definition.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type
|
|
1
|
+
import type { VerifiedModel } from './types.js';
|
|
2
|
+
export type TextSpec = {
|
|
3
|
+
readonly kind: 'text';
|
|
4
|
+
readonly required: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type ScalarSpec = TextSpec | {
|
|
3
7
|
readonly kind: 'string';
|
|
4
8
|
readonly required: boolean;
|
|
5
9
|
} | {
|
|
@@ -17,20 +21,22 @@ export type ScalarSpec = {
|
|
|
17
21
|
readonly required: boolean;
|
|
18
22
|
readonly to: string;
|
|
19
23
|
};
|
|
20
|
-
export type
|
|
24
|
+
export type ListSpec = {
|
|
21
25
|
readonly kind: 'list';
|
|
22
26
|
readonly required: boolean;
|
|
23
27
|
readonly of: ScalarSpec;
|
|
24
28
|
};
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
readonly required: boolean;
|
|
28
|
-
};
|
|
29
|
+
export type FieldSpec = ScalarSpec | ListSpec;
|
|
30
|
+
export type SectionSpec = TextSpec | ListSpec;
|
|
29
31
|
export type Definition = {
|
|
30
32
|
readonly name: string;
|
|
31
|
-
readonly
|
|
33
|
+
readonly memberDocument: boolean;
|
|
32
34
|
readonly fields: Readonly<Record<string, FieldSpec>>;
|
|
33
35
|
readonly sections: Readonly<Record<string, SectionSpec>>;
|
|
34
36
|
};
|
|
35
|
-
export
|
|
37
|
+
export type Failure = {
|
|
38
|
+
readonly rule: string;
|
|
39
|
+
readonly location?: string;
|
|
40
|
+
};
|
|
41
|
+
export declare function readSchema(text: string): VerifiedModel | Failure;
|
|
36
42
|
//# 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":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,UAAU,GAClB,QAAQ,GACR;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACzF;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,QA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