@grafctory/blue 0.0.0-stage → 0.15.1
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 +509 -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 +154 -0
- package/dist/dictionary/assembler.js.map +1 -0
- package/dist/dictionary/index.d.ts +211 -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 +34 -0
- package/dist/dictionary/validator.d.ts.map +1 -0
- package/dist/dictionary/validator.js +91 -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 +898 -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 +1031 -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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape assembly.
|
|
3
|
+
*
|
|
4
|
+
* Combines a shape with the one it overrides: {@link narrowsShape} tests the override relation and
|
|
5
|
+
* {@link mergeShape} builds the merged shape, each routing the pair to the operators of the kind they share, so that a
|
|
6
|
+
* caller holding two shapes needs not know which kind it holds. The rules the kinds state alike, the datatype and the
|
|
7
|
+
* closed value domain among them, are stated here once, so that every kind holds an override to the same terms.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type Optional } from "@grafctory/core";
|
|
12
|
+
import { type Trace, type Validator } from "@grafctory/core/trace";
|
|
13
|
+
import type { Reference } from "@grafctory/qest/state";
|
|
14
|
+
import type { Shape } from "./index.js";
|
|
15
|
+
/**
|
|
16
|
+
* The value-domain constraints a scalar shape closes its domain with.
|
|
17
|
+
*/
|
|
18
|
+
type Enumerated = {
|
|
19
|
+
readonly in?: readonly (number | string)[];
|
|
20
|
+
readonly hasValue?: readonly (number | string)[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The datatype a literal shape states its values are typed as.
|
|
24
|
+
*/
|
|
25
|
+
type Datatyped = {
|
|
26
|
+
readonly datatype?: Reference;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Reports whether a shape narrows an inherited one.
|
|
30
|
+
*
|
|
31
|
+
* Routes the pair to the operators of the kind they share, so that a caller holding two shapes tests the override
|
|
32
|
+
* relation without knowing which kind it holds. Two shapes of different kinds never narrow one another, as an override
|
|
33
|
+
* refines what a member admits and never retypes it; the one exception is a shape of any other kind overriding a
|
|
34
|
+
* union, which narrows it exactly where it restricts a single one of its alternatives.
|
|
35
|
+
*
|
|
36
|
+
* A resource carries the class it belongs to as part of its value, so every class the inherited shape declares binds
|
|
37
|
+
* the resources the overriding shape admits: the override belongs to each of them, whether it states the class in its
|
|
38
|
+
* own right or inherits it from a shape it extends. An inherited shape declaring no class states no such obligation
|
|
39
|
+
* and holds the override to its members alone.
|
|
40
|
+
*
|
|
41
|
+
* @param target The overriding shape
|
|
42
|
+
* @param source The inherited shape
|
|
43
|
+
*
|
|
44
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
45
|
+
*/
|
|
46
|
+
export declare function narrowsShape(target: Shape, source: Shape): Optional<Trace>;
|
|
47
|
+
/**
|
|
48
|
+
* Merges a shape with an inherited one.
|
|
49
|
+
*
|
|
50
|
+
* Routes the pair to the operators of the kind they share, so that a caller holding two shapes builds the merged one
|
|
51
|
+
* without knowing which kind it holds. A shape of any other kind overriding a union is merged with the single
|
|
52
|
+
* alternative it restricts, the others being dropped, so the member is no longer polymorphic.
|
|
53
|
+
*
|
|
54
|
+
* @param target The overriding shape
|
|
55
|
+
* @param source The inherited shape
|
|
56
|
+
*
|
|
57
|
+
* @returns An immutable shape admitting the values both `target` and `source` admit
|
|
58
|
+
*
|
|
59
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
|
|
60
|
+
*/
|
|
61
|
+
export declare function mergeShape(target: Shape, source: Shape): Shape;
|
|
62
|
+
/**
|
|
63
|
+
* Rejects a shape operation an obstacle trace stands against.
|
|
64
|
+
*
|
|
65
|
+
* Lets an assembler state the outcome of a consistency or override test in a single call, throwing only where the
|
|
66
|
+
* test produced a trace.
|
|
67
|
+
*
|
|
68
|
+
* @param message The failure the trace details
|
|
69
|
+
* @param trace The obstacles found, or `undefined` where the test passed
|
|
70
|
+
*
|
|
71
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `trace` is defined
|
|
72
|
+
*/
|
|
73
|
+
export declare function reject(message: string, trace: Optional<Trace>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Reports whether an overriding shape keeps the datatype an inherited one states.
|
|
76
|
+
*
|
|
77
|
+
* States the datatype override rule once for every literal kind: a datatype carries through from whichever shape
|
|
78
|
+
* states it, and the two must agree where both do, as a member is stored under a single datatype.
|
|
79
|
+
*
|
|
80
|
+
* @param source The inherited shape
|
|
81
|
+
*
|
|
82
|
+
* @returns A validator reporting the mismatch between the datatype an overriding shape states and the inherited one
|
|
83
|
+
*/
|
|
84
|
+
export declare function narrowsDatatype(source: Datatyped): Validator<Datatyped>;
|
|
85
|
+
/**
|
|
86
|
+
* Reports whether an overriding shape keeps within the value domain an inherited one closes.
|
|
87
|
+
*
|
|
88
|
+
* States the enumeration override rules once for every scalar kind: a child listing a value the parent omits would be
|
|
89
|
+
* intersected away, leaving the state wider than the shape admits, and a required value the child omits would be
|
|
90
|
+
* unioned back in, leaving the child stating a weaker requirement than it enforces, so a widened set is rejected
|
|
91
|
+
* outright as with the bounds.
|
|
92
|
+
*
|
|
93
|
+
* @param source The inherited shape
|
|
94
|
+
*
|
|
95
|
+
* @returns A validator reporting the values an overriding shape adds to the admitted set and the required ones it drops
|
|
96
|
+
*/
|
|
97
|
+
export declare function narrowsDomain({ in: allowed, hasValue: required }: Enumerated): Validator<Enumerated>;
|
|
98
|
+
/**
|
|
99
|
+
* Checks a closed value domain for internal consistency.
|
|
100
|
+
*
|
|
101
|
+
* States once for every scalar kind the contradiction that would leave a shape requiring a value it doesn't admit.
|
|
102
|
+
*
|
|
103
|
+
* @returns A validator reporting the required values lying outside the admitted set
|
|
104
|
+
*/
|
|
105
|
+
export declare function checkDomain(): Validator<Enumerated>;
|
|
106
|
+
/**
|
|
107
|
+
* Combines the values an overriding shape admits with the inherited ones.
|
|
108
|
+
*
|
|
109
|
+
* @typeParam V The admitted values
|
|
110
|
+
*
|
|
111
|
+
* @param target The values the overriding shape admits, or `undefined` where it leaves the domain open
|
|
112
|
+
* @param source The values the inherited shape admits, or `undefined` where it leaves the domain open
|
|
113
|
+
*
|
|
114
|
+
* @returns The values both shapes admit, or `undefined` where neither closes the domain
|
|
115
|
+
*/
|
|
116
|
+
export declare function intersect<V extends number | string>(target: Optional<readonly V[]>, source: Optional<readonly V[]>): Optional<readonly V[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Combines the values an overriding shape requires with the inherited ones.
|
|
119
|
+
*
|
|
120
|
+
* @typeParam V The required values
|
|
121
|
+
*
|
|
122
|
+
* @param target The values the overriding shape requires, or `undefined` where it requires none
|
|
123
|
+
* @param source The values the inherited shape requires, or `undefined` where it requires none
|
|
124
|
+
*
|
|
125
|
+
* @returns The values either shape requires, or `undefined` where neither requires any
|
|
126
|
+
*/
|
|
127
|
+
export declare function unite<V extends number | string>(target: Optional<readonly V[]>, source: Optional<readonly V[]>): Optional<readonly V[]>;
|
|
128
|
+
export {};
|
|
129
|
+
//# sourceMappingURL=assembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.d.ts","sourceRoot":"","sources":["../../src/value/assembler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAa,KAAK,KAAK,EAAc,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAUvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAcxC;;GAEG;AACH,KAAK,UAAU,GAAG;IAEjB,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAEjD,CAAA;AAED;;GAEG;AACH,KAAK,SAAS,GAAG;IAEhB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAE9B,CAAA;AAGD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CA4B1E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,CAsB9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAMpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAUvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,CAmBpG;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,IAAI,SAAS,CAAC,UAAU,CAAC,CAUnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAClD,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,EAC9B,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAMxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC9C,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,EAC9B,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAMxB"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { union } from "@grafctory/core/arrays";
|
|
17
|
+
import { all, test, TraceError } from "@grafctory/core/trace";
|
|
18
|
+
import { mergeBoolean, narrowsBoolean } from "../boolean/assembler.js";
|
|
19
|
+
import { mergeDictionary, narrowsDictionary } from "../dictionary/assembler.js";
|
|
20
|
+
import { mergeNumber, narrowsNumber } from "../number/assembler.js";
|
|
21
|
+
import { mergeReference, narrowsReference } from "../reference/assembler.js";
|
|
22
|
+
import { mergeResource, narrowsResource } from "../resource/assembler.js";
|
|
23
|
+
import { mergeString, narrowsString } from "../string/assembler.js";
|
|
24
|
+
import { mergeUnion, narrowsUnion } from "../union/assembler.js";
|
|
25
|
+
import { getShapeBranches } from "../union/index.js";
|
|
26
|
+
/**
|
|
27
|
+
* Reports whether a shape narrows an inherited one.
|
|
28
|
+
*
|
|
29
|
+
* Routes the pair to the operators of the kind they share, so that a caller holding two shapes tests the override
|
|
30
|
+
* relation without knowing which kind it holds. Two shapes of different kinds never narrow one another, as an override
|
|
31
|
+
* refines what a member admits and never retypes it; the one exception is a shape of any other kind overriding a
|
|
32
|
+
* union, which narrows it exactly where it restricts a single one of its alternatives.
|
|
33
|
+
*
|
|
34
|
+
* A resource carries the class it belongs to as part of its value, so every class the inherited shape declares binds
|
|
35
|
+
* the resources the overriding shape admits: the override belongs to each of them, whether it states the class in its
|
|
36
|
+
* own right or inherits it from a shape it extends. An inherited shape declaring no class states no such obligation
|
|
37
|
+
* and holds the override to its members alone.
|
|
38
|
+
*
|
|
39
|
+
* @param target The overriding shape
|
|
40
|
+
* @param source The inherited shape
|
|
41
|
+
*
|
|
42
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
43
|
+
*/
|
|
44
|
+
export function narrowsShape(target, source) {
|
|
45
|
+
// a polymorphic inherited shape is narrowed to the single alternative the overriding one restricts, which thus
|
|
46
|
+
// restates no wrapper of its own
|
|
47
|
+
if (source.kind === "union" && target.kind !== "union") {
|
|
48
|
+
const claimed = claims(target, source);
|
|
49
|
+
return claimed.length === 1 ? undefined
|
|
50
|
+
: claimed.length === 0 ? ["{branches} restricts no inherited branch"]
|
|
51
|
+
: ["{branches} restricts several inherited branches"];
|
|
52
|
+
}
|
|
53
|
+
return target.kind !== source.kind ? [`{kind} mismatched kinds <${target.kind}> vs <${source.kind}>`]
|
|
54
|
+
: operate(target, source, {
|
|
55
|
+
boolean: narrowsBoolean,
|
|
56
|
+
number: narrowsNumber,
|
|
57
|
+
string: narrowsString,
|
|
58
|
+
dictionary: narrowsDictionary,
|
|
59
|
+
reference: narrowsReference,
|
|
60
|
+
union: narrowsUnion,
|
|
61
|
+
resource: narrowsResourceValue
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Merges a shape with an inherited one.
|
|
66
|
+
*
|
|
67
|
+
* Routes the pair to the operators of the kind they share, so that a caller holding two shapes builds the merged one
|
|
68
|
+
* without knowing which kind it holds. A shape of any other kind overriding a union is merged with the single
|
|
69
|
+
* alternative it restricts, the others being dropped, so the member is no longer polymorphic.
|
|
70
|
+
*
|
|
71
|
+
* @param target The overriding shape
|
|
72
|
+
* @param source The inherited shape
|
|
73
|
+
*
|
|
74
|
+
* @returns An immutable shape admitting the values both `target` and `source` admit
|
|
75
|
+
*
|
|
76
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
|
|
77
|
+
*/
|
|
78
|
+
export function mergeShape(target, source) {
|
|
79
|
+
reject("incompatible shape override", narrowsShape(target, source));
|
|
80
|
+
// the single alternative an overriding shape restricts is the one it is merged with, the rest being dropped
|
|
81
|
+
if (source.kind === "union" && target.kind !== "union") {
|
|
82
|
+
return mergeShape(target, claims(target, source)[0]);
|
|
83
|
+
}
|
|
84
|
+
return operate(target, source, {
|
|
85
|
+
boolean: mergeBoolean,
|
|
86
|
+
number: mergeNumber,
|
|
87
|
+
string: mergeString,
|
|
88
|
+
dictionary: mergeDictionary,
|
|
89
|
+
reference: mergeReference,
|
|
90
|
+
union: mergeUnion,
|
|
91
|
+
resource: mergeResource
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Rejects a shape operation an obstacle trace stands against.
|
|
96
|
+
*
|
|
97
|
+
* Lets an assembler state the outcome of a consistency or override test in a single call, throwing only where the
|
|
98
|
+
* test produced a trace.
|
|
99
|
+
*
|
|
100
|
+
* @param message The failure the trace details
|
|
101
|
+
* @param trace The obstacles found, or `undefined` where the test passed
|
|
102
|
+
*
|
|
103
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `trace` is defined
|
|
104
|
+
*/
|
|
105
|
+
export function reject(message, trace) {
|
|
106
|
+
if (trace !== undefined) {
|
|
107
|
+
throw new TraceError(message, trace);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reports whether an overriding shape keeps the datatype an inherited one states.
|
|
112
|
+
*
|
|
113
|
+
* States the datatype override rule once for every literal kind: a datatype carries through from whichever shape
|
|
114
|
+
* states it, and the two must agree where both do, as a member is stored under a single datatype.
|
|
115
|
+
*
|
|
116
|
+
* @param source The inherited shape
|
|
117
|
+
*
|
|
118
|
+
* @returns A validator reporting the mismatch between the datatype an overriding shape states and the inherited one
|
|
119
|
+
*/
|
|
120
|
+
export function narrowsDatatype(source) {
|
|
121
|
+
return test(({ datatype }) => {
|
|
122
|
+
return datatype === undefined || source.datatype === undefined || datatype === source.datatype || [
|
|
123
|
+
`{datatype} mismatched datatypes <${datatype}> and <${source.datatype}>`
|
|
124
|
+
];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reports whether an overriding shape keeps within the value domain an inherited one closes.
|
|
129
|
+
*
|
|
130
|
+
* States the enumeration override rules once for every scalar kind: a child listing a value the parent omits would be
|
|
131
|
+
* intersected away, leaving the state wider than the shape admits, and a required value the child omits would be
|
|
132
|
+
* unioned back in, leaving the child stating a weaker requirement than it enforces, so a widened set is rejected
|
|
133
|
+
* outright as with the bounds.
|
|
134
|
+
*
|
|
135
|
+
* @param source The inherited shape
|
|
136
|
+
*
|
|
137
|
+
* @returns A validator reporting the values an overriding shape adds to the admitted set and the required ones it drops
|
|
138
|
+
*/
|
|
139
|
+
export function narrowsDomain({ in: allowed, hasValue: required }) {
|
|
140
|
+
return all(test(({ in: values }) => {
|
|
141
|
+
return values === undefined || allowed === undefined || values.every(v => allowed.includes(v)) || [
|
|
142
|
+
`{in} unexpected values [${values.filter(v => !allowed.includes(v))}]`
|
|
143
|
+
];
|
|
144
|
+
}), test(({ hasValue }) => {
|
|
145
|
+
return hasValue === undefined || required === undefined || required.every(v => hasValue.includes(v)) || [
|
|
146
|
+
`{hasValue} missing required values [${required.filter(v => !hasValue.includes(v))}]`
|
|
147
|
+
];
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks a closed value domain for internal consistency.
|
|
152
|
+
*
|
|
153
|
+
* States once for every scalar kind the contradiction that would leave a shape requiring a value it doesn't admit.
|
|
154
|
+
*
|
|
155
|
+
* @returns A validator reporting the required values lying outside the admitted set
|
|
156
|
+
*/
|
|
157
|
+
export function checkDomain() {
|
|
158
|
+
return test(({ in: allowed, hasValue }) => {
|
|
159
|
+
return hasValue === undefined || allowed === undefined || hasValue.every(v => allowed.includes(v)) || [
|
|
160
|
+
`{hasValue/in} required values <${hasValue.filter(v => !allowed.includes(v))}> not in allowed set`
|
|
161
|
+
];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Combines the values an overriding shape admits with the inherited ones.
|
|
166
|
+
*
|
|
167
|
+
* @typeParam V The admitted values
|
|
168
|
+
*
|
|
169
|
+
* @param target The values the overriding shape admits, or `undefined` where it leaves the domain open
|
|
170
|
+
* @param source The values the inherited shape admits, or `undefined` where it leaves the domain open
|
|
171
|
+
*
|
|
172
|
+
* @returns The values both shapes admit, or `undefined` where neither closes the domain
|
|
173
|
+
*/
|
|
174
|
+
export function intersect(target, source) {
|
|
175
|
+
return target !== undefined && source !== undefined
|
|
176
|
+
? target.filter(v => source.includes(v))
|
|
177
|
+
: target ?? source;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Combines the values an overriding shape requires with the inherited ones.
|
|
181
|
+
*
|
|
182
|
+
* @typeParam V The required values
|
|
183
|
+
*
|
|
184
|
+
* @param target The values the overriding shape requires, or `undefined` where it requires none
|
|
185
|
+
* @param source The values the inherited shape requires, or `undefined` where it requires none
|
|
186
|
+
*
|
|
187
|
+
* @returns The values either shape requires, or `undefined` where neither requires any
|
|
188
|
+
*/
|
|
189
|
+
export function unite(target, source) {
|
|
190
|
+
return target !== undefined && source !== undefined
|
|
191
|
+
? union([target, source])
|
|
192
|
+
: target ?? source;
|
|
193
|
+
}
|
|
194
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
195
|
+
/**
|
|
196
|
+
* Reports whether a resource shape standing in for an inherited one narrows it.
|
|
197
|
+
*
|
|
198
|
+
* Holds the overriding shape to the classes the inherited one declares, on top of the member relation resource
|
|
199
|
+
* narrowing tests: a shape missing one from its lineage admits resources the inherited shape rejects, whatever its
|
|
200
|
+
* members state. The obligation is stated here rather than in resource narrowing, which serves an extending shape too,
|
|
201
|
+
* where a class of its own is exactly what a shape is expected to state.
|
|
202
|
+
*
|
|
203
|
+
* @param target The overriding shape
|
|
204
|
+
* @param source The inherited shape
|
|
205
|
+
*
|
|
206
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
207
|
+
*/
|
|
208
|
+
function narrowsResourceValue(target, source) {
|
|
209
|
+
const missing = lineage(source).filter(iri => !lineage(target).includes(iri));
|
|
210
|
+
return missing.length > 0
|
|
211
|
+
? [`{class} missing inherited classes [${missing}]`]
|
|
212
|
+
: narrowsResource(target, source);
|
|
213
|
+
/**
|
|
214
|
+
* Resolves the classes a resource shape belongs to: the one it states in its own right, where it states one,
|
|
215
|
+
* followed by the ones it inherits.
|
|
216
|
+
*/
|
|
217
|
+
function lineage({ class: declared, classes }) {
|
|
218
|
+
return [...declared === undefined ? [] : [declared], ...classes];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Routes a pair of shapes of the same kind to the operator serving that kind.
|
|
223
|
+
*
|
|
224
|
+
* @typeParam R The outcome the operators yield
|
|
225
|
+
*
|
|
226
|
+
* @param target The overriding shape
|
|
227
|
+
* @param source The inherited shape, of the same kind as `target`
|
|
228
|
+
* @param operators The operators to route the pair to
|
|
229
|
+
*
|
|
230
|
+
* @returns The outcome the operator of the shared kind yields
|
|
231
|
+
*/
|
|
232
|
+
function operate(target, source, operators) {
|
|
233
|
+
// the caller is what makes the lookup well-typed: both shapes are known to share target.kind by here
|
|
234
|
+
const operator = operators[target.kind]; // ;(cast) kinds known to match
|
|
235
|
+
return operator(target, source);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Resolves the alternatives of an inherited polymorphic shape an overriding shape restricts.
|
|
239
|
+
*
|
|
240
|
+
* @param target The overriding shape
|
|
241
|
+
* @param source The inherited polymorphic shape
|
|
242
|
+
*
|
|
243
|
+
* @returns The alternatives `target` narrows, in the order they were stated
|
|
244
|
+
*/
|
|
245
|
+
function claims(target, source) {
|
|
246
|
+
return getShapeBranches(source).filter(branch => narrowsShape(target, branch) === undefined);
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=assembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/value/assembler.ts"],"names":[],"mappings":"AAAA;;;;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