@grafctory/blue 0.0.0-stage → 0.16.0
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/LICENSE +201 -0
- package/README.md +524 -2
- package/dist/boolean/assembler.d.ts +53 -0
- package/dist/boolean/assembler.d.ts.map +1 -0
- package/dist/boolean/assembler.js +78 -0
- package/dist/boolean/assembler.js.map +1 -0
- package/dist/boolean/index.d.ts +86 -0
- package/dist/boolean/index.d.ts.map +1 -0
- package/dist/boolean/index.js +99 -0
- package/dist/boolean/index.js.map +1 -0
- package/dist/boolean/validator.d.ts +30 -0
- package/dist/boolean/validator.d.ts.map +1 -0
- package/dist/boolean/validator.js +68 -0
- package/dist/boolean/validator.js.map +1 -0
- package/dist/dictionary/assembler.d.ts +70 -0
- package/dist/dictionary/assembler.d.ts.map +1 -0
- package/dist/dictionary/assembler.js +178 -0
- package/dist/dictionary/assembler.js.map +1 -0
- package/dist/dictionary/index.d.ts +237 -0
- package/dist/dictionary/index.d.ts.map +1 -0
- package/dist/dictionary/index.js +43 -0
- package/dist/dictionary/index.js.map +1 -0
- package/dist/dictionary/inference.d.ts +42 -0
- package/dist/dictionary/inference.d.ts.map +1 -0
- package/dist/dictionary/inference.js +17 -0
- package/dist/dictionary/inference.js.map +1 -0
- package/dist/dictionary/validator.d.ts +37 -0
- package/dist/dictionary/validator.d.ts.map +1 -0
- package/dist/dictionary/validator.js +106 -0
- package/dist/dictionary/validator.js.map +1 -0
- package/dist/index.core.d.ts +33 -0
- package/dist/index.core.d.ts.map +1 -0
- package/dist/index.core.js +149 -0
- package/dist/index.core.js.map +1 -0
- package/dist/index.d.ts +333 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +378 -0
- package/dist/index.js.map +1 -0
- package/dist/number/assembler.d.ts +70 -0
- package/dist/number/assembler.d.ts.map +1 -0
- package/dist/number/assembler.js +188 -0
- package/dist/number/assembler.js.map +1 -0
- package/dist/number/index.d.ts +329 -0
- package/dist/number/index.d.ts.map +1 -0
- package/dist/number/index.js +312 -0
- package/dist/number/index.js.map +1 -0
- package/dist/number/validator.d.ts +31 -0
- package/dist/number/validator.d.ts.map +1 -0
- package/dist/number/validator.js +57 -0
- package/dist/number/validator.js.map +1 -0
- package/dist/reference/accessors.d.ts +29 -0
- package/dist/reference/accessors.d.ts.map +1 -0
- package/dist/reference/accessors.js +38 -0
- package/dist/reference/accessors.js.map +1 -0
- package/dist/reference/assembler.d.ts +63 -0
- package/dist/reference/assembler.d.ts.map +1 -0
- package/dist/reference/assembler.js +127 -0
- package/dist/reference/assembler.js.map +1 -0
- package/dist/reference/index.d.ts +108 -0
- package/dist/reference/index.d.ts.map +1 -0
- package/dist/reference/index.js +40 -0
- package/dist/reference/index.js.map +1 -0
- package/dist/reference/validator.d.ts +33 -0
- package/dist/reference/validator.d.ts.map +1 -0
- package/dist/reference/validator.js +56 -0
- package/dist/reference/validator.js.map +1 -0
- package/dist/resource/accessors.d.ts +140 -0
- package/dist/resource/accessors.d.ts.map +1 -0
- package/dist/resource/accessors.js +173 -0
- package/dist/resource/accessors.js.map +1 -0
- package/dist/resource/assembler.d.ts +265 -0
- package/dist/resource/assembler.d.ts.map +1 -0
- package/dist/resource/assembler.js +816 -0
- package/dist/resource/assembler.js.map +1 -0
- package/dist/resource/index.d.ts +903 -0
- package/dist/resource/index.d.ts.map +1 -0
- package/dist/resource/index.js +160 -0
- package/dist/resource/index.js.map +1 -0
- package/dist/resource/inference.d.ts +310 -0
- package/dist/resource/inference.d.ts.map +1 -0
- package/dist/resource/inference.js +17 -0
- package/dist/resource/inference.js.map +1 -0
- package/dist/resource/validator.d.ts +158 -0
- package/dist/resource/validator.d.ts.map +1 -0
- package/dist/resource/validator.js +1013 -0
- package/dist/resource/validator.js.map +1 -0
- package/dist/string/assembler.d.ts +69 -0
- package/dist/string/assembler.d.ts.map +1 -0
- package/dist/string/assembler.js +143 -0
- package/dist/string/assembler.js.map +1 -0
- package/dist/string/index.d.ts +431 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/index.js +528 -0
- package/dist/string/index.js.map +1 -0
- package/dist/string/validator.d.ts +30 -0
- package/dist/string/validator.d.ts.map +1 -0
- package/dist/string/validator.js +69 -0
- package/dist/string/validator.js.map +1 -0
- package/dist/union/accessors.d.ts +137 -0
- package/dist/union/accessors.d.ts.map +1 -0
- package/dist/union/accessors.js +253 -0
- package/dist/union/accessors.js.map +1 -0
- package/dist/union/assembler.d.ts +56 -0
- package/dist/union/assembler.d.ts.map +1 -0
- package/dist/union/assembler.js +140 -0
- package/dist/union/assembler.js.map +1 -0
- package/dist/union/index.d.ts +172 -0
- package/dist/union/index.d.ts.map +1 -0
- package/dist/union/index.js +45 -0
- package/dist/union/index.js.map +1 -0
- package/dist/union/inference.d.ts +30 -0
- package/dist/union/inference.d.ts.map +1 -0
- package/dist/union/inference.js +17 -0
- package/dist/union/inference.js.map +1 -0
- package/dist/union/validator.d.ts +94 -0
- package/dist/union/validator.d.ts.map +1 -0
- package/dist/union/validator.js +171 -0
- package/dist/union/validator.js.map +1 -0
- package/dist/value/accessors.d.ts +151 -0
- package/dist/value/accessors.d.ts.map +1 -0
- package/dist/value/accessors.js +468 -0
- package/dist/value/accessors.js.map +1 -0
- package/dist/value/assembler.d.ts +129 -0
- package/dist/value/assembler.d.ts.map +1 -0
- package/dist/value/assembler.js +248 -0
- package/dist/value/assembler.js.map +1 -0
- package/dist/value/index.d.ts +309 -0
- package/dist/value/index.d.ts.map +1 -0
- package/dist/value/index.js +26 -0
- package/dist/value/index.js.map +1 -0
- package/dist/value/inference.d.ts +292 -0
- package/dist/value/inference.d.ts.map +1 -0
- package/dist/value/inference.js +17 -0
- package/dist/value/inference.js.map +1 -0
- package/dist/value/validator.d.ts +76 -0
- package/dist/value/validator.d.ts.map +1 -0
- package/dist/value/validator.js +111 -0
- package/dist/value/validator.js.map +1 -0
- package/package.json +95 -4
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource state and template validation.
|
|
3
|
+
*
|
|
4
|
+
* Holds a value to what a shape admits and reports everything wrong with it at once, keyed by the member at fault:
|
|
5
|
+
* {@link validateResource} for a resource in its own right, {@link validateResult} for one that came back narrowed by
|
|
6
|
+
* the template that asked for it, and {@link validateTemplate} for a template itself, so that a request is refused
|
|
7
|
+
* before it is issued rather than after it is served.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type Optional } from "@grafctory/core";
|
|
12
|
+
import { type Trace } from "@grafctory/core/trace";
|
|
13
|
+
import { type Reference } from "@grafctory/qest/state";
|
|
14
|
+
import { type Template } from "@grafctory/qest/model";
|
|
15
|
+
import { type Scope } from "../value/validator.js";
|
|
16
|
+
import type { ResourceShape } from "./index.js";
|
|
17
|
+
/**
|
|
18
|
+
* Validates values against a resource shape.
|
|
19
|
+
*
|
|
20
|
+
* Reports a value that is not a resource as a `{kind}` violation and each member that breaks a constraint under its
|
|
21
|
+
* own facet, keyed by the member it is stated under, so that a caller may tell which member failed and why. A resource
|
|
22
|
+
* shape is closed: a value carrying a member the shape doesn't declare is rejected.
|
|
23
|
+
*
|
|
24
|
+
* The custom {@link ResourceShape.validators | checks} a shape states run at `"state"` scope alone, each reporting
|
|
25
|
+
* under the name of the check: a template matched by form carries no values for them to read.
|
|
26
|
+
*
|
|
27
|
+
* A captive member is stated either as the link naming its target or as the resource itself, held in turn to the
|
|
28
|
+
* target shape, so that a resource and the ones it holds captive travel as a single value; `depth` caps how far the
|
|
29
|
+
* expansion reaches. A foreign member is written by the resources it points at, so a value stating one is rejected.
|
|
30
|
+
*
|
|
31
|
+
* A member ranging over a {@link dictionary!DictionaryShape | dictionary} states the language map whole, whatever
|
|
32
|
+
* bounds it carries: a map wrapped in an array is rejected, as is one stated beside values of other alternatives, and
|
|
33
|
+
* the bounds are held against those other values alone.
|
|
34
|
+
*
|
|
35
|
+
* A member ranging over resources treats a record carrying no content at any depth, such as `{}` or `{ detail: {} }`,
|
|
36
|
+
* as a value left unstated. Such a record doesn't count toward the member's bounds, so a required member stated only
|
|
37
|
+
* that way is reported as missing. A member ranging over plain values rejects the same record as a value of the wrong
|
|
38
|
+
* kind.
|
|
39
|
+
*
|
|
40
|
+
* @param values The values to validate
|
|
41
|
+
* @param shape The shape the values are matched against
|
|
42
|
+
* @param opts Validation options
|
|
43
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`
|
|
44
|
+
* @param opts.entry The identifier the resources are expected to be named by, where they state one at all
|
|
45
|
+
* @param opts.depth The nesting a captive member may be expanded to, counting each resource it descends into; `0`
|
|
46
|
+
* refuses every expansion while still admitting the identifier naming the resource
|
|
47
|
+
*
|
|
48
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
49
|
+
*/
|
|
50
|
+
export declare function validateResource(values: readonly unknown[], shape: ResourceShape, { scope, entry, depth }?: {
|
|
51
|
+
scope?: Scope;
|
|
52
|
+
entry?: Reference;
|
|
53
|
+
depth?: number;
|
|
54
|
+
}): Optional<Trace>;
|
|
55
|
+
/**
|
|
56
|
+
* Validates retrieval templates against a shape.
|
|
57
|
+
*
|
|
58
|
+
* Reports each slot of a template that asks for something the shape cannot give, keyed by the member it asks under, so
|
|
59
|
+
* that a caller may tell which part of a request will not be served before it is issued. A template describes what to
|
|
60
|
+
* retrieve rather than what is held, so the value-domain constraints are left alone: a placeholder carries no value of
|
|
61
|
+
* its own, and is held to asking for something the shape can give rather than to being a legal value of it.
|
|
62
|
+
*
|
|
63
|
+
* **What a slot may ask for**
|
|
64
|
+
*
|
|
65
|
+
* Every slot is one object, and the keys it carries say what it asks for: the atomic placeholder `{}` asks for the
|
|
66
|
+
* value as it stands, a nested template for the resource behind a link, a map of language ranges for localised text
|
|
67
|
+
* tag by tag, and a branch map for a polymorphic member one alternative at a time. A member that is not wanted is left
|
|
68
|
+
* out of the template: a slot stated as `undefined` is refused, as is any other slot that isn't an object. Cardinality
|
|
69
|
+
* is not stated by the notation, so a member admitting several values is asked for exactly as one admitting a single
|
|
70
|
+
* value is, except that its slot may carry the constraints filtering, ordering and paging the collection alongside the
|
|
71
|
+
* keys retrieving it. A member admitting one value has no collection to narrow and a localised member is filtered by
|
|
72
|
+
* its own tag ranges: both refuse a constraint, as does a branch of a polymorphic member, which stands for one value
|
|
73
|
+
* alone, the constraints narrowing a collection riding on the slot hosting the alternatives. A refused constraint is
|
|
74
|
+
* reported under the key stating it and leaves what the slot asks for held to the shape all the same, so one pass
|
|
75
|
+
* reports both.
|
|
76
|
+
*
|
|
77
|
+
* Within a branch map, a template may ask for members declared by different resource branches. A member several of
|
|
78
|
+
* them declare may take a different shape in each, and what is asked for it need fit only one of them. A localised
|
|
79
|
+
* branch standing among others takes a map of tag ranges under a branch map. If no other branch reaches a resource,
|
|
80
|
+
* the map may also be stated directly on the member. A tag range may also be a member name, so an object whose keys
|
|
81
|
+
* each name a member of a resource branch is read as a template, and any other object as a map of tag ranges.
|
|
82
|
+
*
|
|
83
|
+
* **What a constraint may test against**
|
|
84
|
+
*
|
|
85
|
+
* A membership filter tests the options it lists by equality, so an option is held to the type of the member alone and
|
|
86
|
+
* need not be a legal value of it. A localised member is filtered through the text it carries: either plainly, as the
|
|
87
|
+
* string or strings any tag may match, or as a map grouping the options by the tag they are to match under, a tag
|
|
88
|
+
* carrying as many as the filter lists whatever arity the member admits. The two forms are never mixed within one set,
|
|
89
|
+
* and a map keyed by anything but a language tag is reported under the key at fault.
|
|
90
|
+
*
|
|
91
|
+
* **What a projection may ask for**
|
|
92
|
+
*
|
|
93
|
+
* A collection may be asked for as a table rather than as resources, each column bound to a path through the shape and
|
|
94
|
+
* to the transforms reducing it. A binding naming a path the shape cannot resolve is reported, as is one repeating an
|
|
95
|
+
* identifier another column already binds. A binding whose path takes no step reaches the item the collection holds as
|
|
96
|
+
* it stands, so a link is asked for as the identifier naming its target or expanded through a nested template, while an
|
|
97
|
+
* embedded resource, naming no identifier to come back as, is refused. Where a projection groups the collection, every
|
|
98
|
+
* ordering and focus key must name a grouping key or reduce to an aggregate, as nothing else ranks a group. A grouping
|
|
99
|
+
* key holds one value per group, so it may rank the groups even if the member it reaches is multi-valued.
|
|
100
|
+
*
|
|
101
|
+
* A column holds one value per row, so it supplies no collection to narrow and refuses a constraint of its own; a
|
|
102
|
+
* collection reached below it, through a nested template, carries its constraints as any other collection does.
|
|
103
|
+
*
|
|
104
|
+
* @param values The templates to validate
|
|
105
|
+
* @param shape The shape the templates are matched against
|
|
106
|
+
* @param opts Validation options
|
|
107
|
+
* @param opts.plain Whether to refuse the transforms combining several values into one, leaving a template that
|
|
108
|
+
* retrieves rather than computes
|
|
109
|
+
* @param opts.depth The nesting a template may ask for, counting each resource it descends into; `0` refuses every
|
|
110
|
+
* nested template while still admitting the identifier naming the resource
|
|
111
|
+
* @param opts.limit The largest page a template may ask for; a collection asking for none is held to it, and one
|
|
112
|
+
* asking for more is refused. `0`, like omitting it, leaves the page to the caller
|
|
113
|
+
*
|
|
114
|
+
* @returns A trace of the violations found, or `undefined` where every template asks for what the shape can give
|
|
115
|
+
*
|
|
116
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `shape` reaches itself through a cycle no link
|
|
117
|
+
* breaks, or where a union it reaches declares a shared member name inconsistently across its branches
|
|
118
|
+
*/
|
|
119
|
+
export declare function validateTemplate(values: readonly unknown[], shape: ResourceShape, { plain, depth, limit }?: {
|
|
120
|
+
readonly plain?: boolean;
|
|
121
|
+
readonly depth?: number;
|
|
122
|
+
readonly limit?: number;
|
|
123
|
+
}): Optional<Trace>;
|
|
124
|
+
/**
|
|
125
|
+
* Validates retrieved resources against a shape, narrowed by the template that requested them.
|
|
126
|
+
*
|
|
127
|
+
* Reports each member the template asked for and the resource states wrongly, keyed by the member it is stated under,
|
|
128
|
+
* so that a caller may tell which part of what it asked for came back malformed. Only the members the template names
|
|
129
|
+
* are held to the shape: one it left out is neither required nor checked, so a partial retrieval passes on its own
|
|
130
|
+
* terms. The surface is closed the other way too: a member the resource states but the template didn't ask for is
|
|
131
|
+
* rejected, as the caller has no place to put it. The custom {@link ResourceShape.validators | checks} a shape states
|
|
132
|
+
* are left out, as they are written against a whole resource rather than the part of it a template asked for.
|
|
133
|
+
*
|
|
134
|
+
* A member reaching a resource comes back as the resource itself where a nested template asked for it, and as the
|
|
135
|
+
* identifier naming it where the atomic placeholder did; either way it is held to what was asked. A localised member
|
|
136
|
+
* comes back in the form its template asked for: the map it named tag ranges under, whole and never in an array, or,
|
|
137
|
+
* where the atomic placeholder asked for it, the text content negotiation settled on, at the arity the shape states
|
|
138
|
+
* per tag and held to the lengths it bounds rather than to the counts of the other alternatives.
|
|
139
|
+
*
|
|
140
|
+
* A polymorphic member comes back holding one variant alone. If the template reaches only some of its variants, the
|
|
141
|
+
* member may come back empty on a resource holding another, so its lower bound binds only if every variant is
|
|
142
|
+
* reached. If the atomic placeholder asks for localised text paired with other values, the text comes back folded
|
|
143
|
+
* among them as plain strings, and a value is admitted if any variant of the member admits it.
|
|
144
|
+
*
|
|
145
|
+
* @param values The retrieved resources to validate
|
|
146
|
+
* @param opts Validation options
|
|
147
|
+
* @param opts.shape The shape the resources are matched against
|
|
148
|
+
* @param opts.model The template that requested them, narrowing what is checked
|
|
149
|
+
* @param opts.entry The identifier the resources are expected to be named by, where one is expected
|
|
150
|
+
*
|
|
151
|
+
* @returns A trace of the violations found, or `undefined` where every resource matches what was asked for
|
|
152
|
+
*/
|
|
153
|
+
export declare function validateResult(values: readonly unknown[], { shape, model, entry }: {
|
|
154
|
+
readonly shape: ResourceShape;
|
|
155
|
+
readonly model: Template;
|
|
156
|
+
readonly entry?: Reference;
|
|
157
|
+
}): Optional<Trace>;
|
|
158
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/resource/validator.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AAEH,OAAO,EAQN,KAAK,QAAQ,EACb,MA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