@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,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource shape and state accessors.
|
|
3
|
+
*
|
|
4
|
+
* Reads off a shape what the resources it describes are named, classified and made of, resolving a deferred shape and
|
|
5
|
+
* following a link through to its target, so that a caller reaches a resource definition without walking the shape
|
|
6
|
+
* itself. A shape pointing at no resource at all answers every shape accessor with nothing rather than failing.
|
|
7
|
+
*
|
|
8
|
+
* Reads the identifier and the values of a validated state. Each value comes typed by the value shape it matches, so a
|
|
9
|
+
* caller converting a state into another form can switch on the kind of each value and handle it without a cast.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type Identifier, type Lazy, type Optional } from "@grafctory/core";
|
|
14
|
+
import type { Reference } from "@grafctory/qest/state";
|
|
15
|
+
import type { Shape, State } from "../value/index.js";
|
|
16
|
+
import { type UnionShape } from "../union/index.js";
|
|
17
|
+
import type { Members, Property, ResourceShape } from "./index.js";
|
|
18
|
+
/**
|
|
19
|
+
* One value a state holds, paired with the property holding it, its field name and the shape it matches.
|
|
20
|
+
*
|
|
21
|
+
* Narrowing an entry on `kind` narrows `shape` and `value` together, typing `value` as the {@link value!State | state}
|
|
22
|
+
* of `shape`. Union values are resolved to the branch they match, so no entry ever has kind `union`.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam S The value shapes an entry may match; defaults to every shape except unions
|
|
25
|
+
*/
|
|
26
|
+
export type Entry<S extends Shape = Exclude<Shape, UnionShape>> = S extends Shape ? {
|
|
27
|
+
/**
|
|
28
|
+
* The kind of value shape the value matches, discriminating the entry.
|
|
29
|
+
*/
|
|
30
|
+
readonly kind: S["kind"];
|
|
31
|
+
/**
|
|
32
|
+
* The field name the value is stated under in the state.
|
|
33
|
+
*/
|
|
34
|
+
readonly field: Identifier;
|
|
35
|
+
/**
|
|
36
|
+
* The property holding the value, carrying its range, cardinality and RDF predicates.
|
|
37
|
+
*/
|
|
38
|
+
readonly property: Property;
|
|
39
|
+
/**
|
|
40
|
+
* The value shape the value matches; for a union range, the branch the value belongs to.
|
|
41
|
+
*/
|
|
42
|
+
readonly shape: S;
|
|
43
|
+
/**
|
|
44
|
+
* The value, typed as the state of `shape`.
|
|
45
|
+
*/
|
|
46
|
+
readonly value: State<S>;
|
|
47
|
+
} : never;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the class the resources a shape describes belong to.
|
|
50
|
+
*
|
|
51
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
52
|
+
*
|
|
53
|
+
* @returns The class the target shape declares, or `undefined` where it declares none or `shape` points at no
|
|
54
|
+
* resource
|
|
55
|
+
*
|
|
56
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
57
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
58
|
+
*/
|
|
59
|
+
export declare function getShapeClass(shape: Lazy<Shape>): Optional<Reference>;
|
|
60
|
+
/**
|
|
61
|
+
* Resolves the classes the resources a shape describes belong to on top of their own.
|
|
62
|
+
*
|
|
63
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
64
|
+
*
|
|
65
|
+
* @returns The classes the target shape inherits, empty where it extends nothing stating one, or `undefined` where
|
|
66
|
+
* `shape` points at no resource
|
|
67
|
+
*
|
|
68
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
69
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
70
|
+
*/
|
|
71
|
+
export declare function getShapeClasses(shape: Lazy<Shape>): Optional<readonly Reference[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Resolves the name of the member naming the resources a shape describes.
|
|
74
|
+
*
|
|
75
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
76
|
+
*
|
|
77
|
+
* @returns The name the identifier is stated under, or `undefined` where the target states none or `shape` points at
|
|
78
|
+
* no resource
|
|
79
|
+
*
|
|
80
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
81
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
82
|
+
*/
|
|
83
|
+
export declare function getShapeId(shape: Lazy<Shape>): Optional<Identifier>;
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the name of the member typing the resources a shape describes.
|
|
86
|
+
*
|
|
87
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
88
|
+
*
|
|
89
|
+
* @returns The name the class is stated under, or `undefined` where the target states none or `shape` points at no
|
|
90
|
+
* resource
|
|
91
|
+
*
|
|
92
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
93
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
94
|
+
*/
|
|
95
|
+
export declare function getShapeType(shape: Lazy<Shape>): Optional<Identifier>;
|
|
96
|
+
/**
|
|
97
|
+
* Resolves the members the resources a shape describes carry.
|
|
98
|
+
*
|
|
99
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
100
|
+
*
|
|
101
|
+
* @returns The members of the target shape, or no member at all where `shape` points at no resource
|
|
102
|
+
*
|
|
103
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
104
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
105
|
+
*/
|
|
106
|
+
export declare function getShapeProperties(shape: Lazy<Shape>): Members;
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves the identifier of a state.
|
|
109
|
+
*
|
|
110
|
+
* @typeParam S The type of `shape`, fixing the type of `state`
|
|
111
|
+
*
|
|
112
|
+
* @param shape The resource shape `state` conforms to, possibly deferred to break definition cycles
|
|
113
|
+
* @param state The state to read
|
|
114
|
+
*
|
|
115
|
+
* @returns The identifier `state` states, or `undefined` where `shape` declares no id member or `state` states none
|
|
116
|
+
*
|
|
117
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `state` doesn't conform to `shape`, where a deferred
|
|
118
|
+
* definition reaches itself with no link to break the cycle, or where it states a target that doesn't narrow the
|
|
119
|
+
* one the link it is reached through overrides, as a re-pointed target must extend the one it replaces
|
|
120
|
+
*/
|
|
121
|
+
export declare function getStateId<S extends Lazy<ResourceShape>>(shape: S, state: State<S>): Optional<Reference>;
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves the values of a state.
|
|
124
|
+
*
|
|
125
|
+
* Each value comes as an {@link Entry} typed by the value shape it matches. Entries follow member declaration order,
|
|
126
|
+
* then value order within each member. The id and type members are not values and produce no entry.
|
|
127
|
+
*
|
|
128
|
+
* @typeParam S The type of `shape`, fixing the type of `state`
|
|
129
|
+
*
|
|
130
|
+
* @param shape The resource shape `state` conforms to, possibly deferred to break definition cycles
|
|
131
|
+
* @param state The state to read
|
|
132
|
+
*
|
|
133
|
+
* @returns One entry for each value `state` holds under a property `shape` declares
|
|
134
|
+
*
|
|
135
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `state` doesn't conform to `shape`, where a deferred
|
|
136
|
+
* definition reaches itself with no link to break the cycle, where it states a target that doesn't narrow the one
|
|
137
|
+
* the link it is reached through overrides, or where a union range declares a shared member name inconsistently
|
|
138
|
+
*/
|
|
139
|
+
export declare function getStateEntries<S extends Lazy<ResourceShape>>(shape: S, state: State<S>): readonly Entry[];
|
|
140
|
+
//# sourceMappingURL=accessors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../src/resource/accessors.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAS,KAAK,UAAU,EAAE,KAAK,IAAI,EAAO,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGxF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,mBAAmB,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AS,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAQxG;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,KAAK,EAAE,CAe1G"}
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* Resource shape and state accessors.
|
|
18
|
+
*
|
|
19
|
+
* Reads off a shape what the resources it describes are named, classified and made of, resolving a deferred shape and
|
|
20
|
+
* following a link through to its target, so that a caller reaches a resource definition without walking the shape
|
|
21
|
+
* itself. A shape pointing at no resource at all answers every shape accessor with nothing rather than failing.
|
|
22
|
+
*
|
|
23
|
+
* Reads the identifier and the values of a validated state. Each value comes typed by the value shape it matches, so a
|
|
24
|
+
* caller converting a state into another form can switch on the kind of each value and handle it without a cast.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import { error, opt } from "@grafctory/core";
|
|
29
|
+
import { some } from "@grafctory/core/arrays";
|
|
30
|
+
import { TraceError } from "@grafctory/core/trace";
|
|
31
|
+
import { getShapeTarget } from "../reference/index.js";
|
|
32
|
+
import { getShapeBranches, getStateBranch } from "../union/index.js";
|
|
33
|
+
import { validate } from "../index.js";
|
|
34
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the class the resources a shape describes belong to.
|
|
37
|
+
*
|
|
38
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
39
|
+
*
|
|
40
|
+
* @returns The class the target shape declares, or `undefined` where it declares none or `shape` points at no
|
|
41
|
+
* resource
|
|
42
|
+
*
|
|
43
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
44
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
45
|
+
*/
|
|
46
|
+
export function getShapeClass(shape) {
|
|
47
|
+
return getShapeTarget(shape)?.class;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the classes the resources a shape describes belong to on top of their own.
|
|
51
|
+
*
|
|
52
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
53
|
+
*
|
|
54
|
+
* @returns The classes the target shape inherits, empty where it extends nothing stating one, or `undefined` where
|
|
55
|
+
* `shape` points at no resource
|
|
56
|
+
*
|
|
57
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
58
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
59
|
+
*/
|
|
60
|
+
export function getShapeClasses(shape) {
|
|
61
|
+
return getShapeTarget(shape)?.classes;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the name of the member naming the resources a shape describes.
|
|
65
|
+
*
|
|
66
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
67
|
+
*
|
|
68
|
+
* @returns The name the identifier is stated under, or `undefined` where the target states none or `shape` points at
|
|
69
|
+
* no resource
|
|
70
|
+
*
|
|
71
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
72
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
73
|
+
*/
|
|
74
|
+
export function getShapeId(shape) {
|
|
75
|
+
return named(shape, "id");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Resolves the name of the member typing the resources a shape describes.
|
|
79
|
+
*
|
|
80
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
81
|
+
*
|
|
82
|
+
* @returns The name the class is stated under, or `undefined` where the target states none or `shape` points at no
|
|
83
|
+
* resource
|
|
84
|
+
*
|
|
85
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
86
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
87
|
+
*/
|
|
88
|
+
export function getShapeType(shape) {
|
|
89
|
+
return named(shape, "type");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolves the members the resources a shape describes carry.
|
|
93
|
+
*
|
|
94
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
95
|
+
*
|
|
96
|
+
* @returns The members of the target shape, or no member at all where `shape` points at no resource
|
|
97
|
+
*
|
|
98
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
99
|
+
* break the cycle, or states a target that doesn't narrow the one the link it is reached through overrides
|
|
100
|
+
*/
|
|
101
|
+
export function getShapeProperties(shape) {
|
|
102
|
+
return getShapeTarget(shape)?.members ?? {};
|
|
103
|
+
}
|
|
104
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the identifier of a state.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam S The type of `shape`, fixing the type of `state`
|
|
109
|
+
*
|
|
110
|
+
* @param shape The resource shape `state` conforms to, possibly deferred to break definition cycles
|
|
111
|
+
* @param state The state to read
|
|
112
|
+
*
|
|
113
|
+
* @returns The identifier `state` states, or `undefined` where `shape` declares no id member or `state` states none
|
|
114
|
+
*
|
|
115
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `state` doesn't conform to `shape`, where a deferred
|
|
116
|
+
* definition reaches itself with no link to break the cycle, or where it states a target that doesn't narrow the
|
|
117
|
+
* one the link it is reached through overrides, as a re-pointed target must extend the one it replaces
|
|
118
|
+
*/
|
|
119
|
+
export function getStateId(shape, state) {
|
|
120
|
+
const $state = validated(shape, state);
|
|
121
|
+
// ;(cast) the id member of a valid state holds a reference, if any
|
|
122
|
+
return opt(getShapeId(shape), id => $state[id]);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves the values of a state.
|
|
126
|
+
*
|
|
127
|
+
* Each value comes as an {@link Entry} typed by the value shape it matches. Entries follow member declaration order,
|
|
128
|
+
* then value order within each member. The id and type members are not values and produce no entry.
|
|
129
|
+
*
|
|
130
|
+
* @typeParam S The type of `shape`, fixing the type of `state`
|
|
131
|
+
*
|
|
132
|
+
* @param shape The resource shape `state` conforms to, possibly deferred to break definition cycles
|
|
133
|
+
* @param state The state to read
|
|
134
|
+
*
|
|
135
|
+
* @returns One entry for each value `state` holds under a property `shape` declares
|
|
136
|
+
*
|
|
137
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `state` doesn't conform to `shape`, where a deferred
|
|
138
|
+
* definition reaches itself with no link to break the cycle, where it states a target that doesn't narrow the one
|
|
139
|
+
* the link it is reached through overrides, or where a union range declares a shared member name inconsistently
|
|
140
|
+
*/
|
|
141
|
+
export function getStateEntries(shape, state) {
|
|
142
|
+
const $state = validated(shape, state);
|
|
143
|
+
// ;(cast) a valid value is the state of the branch it matches, never a union as getShapeBranches flattens unions
|
|
144
|
+
return Object.entries(getShapeProperties(shape)).flatMap(([field, property]) => property.kind === "property"
|
|
145
|
+
? some($state[field]).flatMap(value => opt(matched(value, getShapeBranches(property.range.shape)), branch => [{ kind: branch.kind, field, property, shape: branch, value }], []))
|
|
146
|
+
: []);
|
|
147
|
+
}
|
|
148
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
149
|
+
/**
|
|
150
|
+
* Validates a state against its shape, at no cost where the state was already found valid.
|
|
151
|
+
*
|
|
152
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `state` doesn't conform to `shape`
|
|
153
|
+
*/
|
|
154
|
+
function validated(shape, state) {
|
|
155
|
+
return validate(state, { shape })({
|
|
156
|
+
value: value => value,
|
|
157
|
+
trace: trace => error(new TraceError("invalid state", trace ?? []))
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolves the branch a valid value matches, matching it again only where a union leaves more than one branch.
|
|
162
|
+
*/
|
|
163
|
+
function matched(value, branches) {
|
|
164
|
+
return branches.length === 1 ? branches[0] : getStateBranch(value, branches);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Resolves the name the marker of a given kind is stated under.
|
|
168
|
+
*/
|
|
169
|
+
function named(shape, kind) {
|
|
170
|
+
return Object.entries(getShapeTarget(shape)?.members ?? {})
|
|
171
|
+
.find(([, declared]) => declared.kind === kind)?.[0];
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=accessors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.js","sourceRoot":"","sources":["../../src/resource/accessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAA8B,GAAG,EAAiB,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,E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AAC,KAAK,CAAC,EAAE,OAAO,IAAI,EAAE,CAAC;SACzD,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAC9C,EAAE,CAAC,CAAC,CAAC,CAAC;AAER,CAAC"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource shape assembly.
|
|
3
|
+
*
|
|
4
|
+
* Builds the shape a factory states into the merged form its consumers read: the shapes extended contribute their
|
|
5
|
+
* members and constraints, each declared member is held to the one it overrides, and the result is frozen, so that a
|
|
6
|
+
* shape admitting no resource at all is rejected as it is built rather than when a resource is first matched against
|
|
7
|
+
* it.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type Optional } from "@grafctory/core";
|
|
12
|
+
import { type Trace } from "@grafctory/core/trace";
|
|
13
|
+
import type { Member, Property, PropertyBounds, ResourceShape } from "./index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Assembles a resource shape.
|
|
16
|
+
*
|
|
17
|
+
* Backs the factory the {@link resource!} module exposes: reads the extended shapes, the constraints and the members
|
|
18
|
+
* off the arguments as they were stated, resolves each member's predicate against the effective space, and merges the
|
|
19
|
+
* inherited definitions in, so that the shape a caller holds states everything its resources carry.
|
|
20
|
+
*
|
|
21
|
+
* @param args The extended shapes, followed by the constraints, the members, or both, each optional; a lone declaration
|
|
22
|
+
* is read as members where it lists members, and as constraints otherwise
|
|
23
|
+
*
|
|
24
|
+
* @returns An immutable shape admitting the resources the members and constraints bound
|
|
25
|
+
*
|
|
26
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where the stated declarations are inconsistent with the
|
|
27
|
+
* inherited ones
|
|
28
|
+
* @throws {@link !TypeError TypeError} Where a lone declaration lists neither members nor constraints, of two
|
|
29
|
+
* declarations the last lists something other than members or the first something other than constraints, or
|
|
30
|
+
* the constraints state an identifier pattern that is not a well-formed absolute or root-relative path template
|
|
31
|
+
*/
|
|
32
|
+
export declare function assemble(args: readonly unknown[]): ResourceShape;
|
|
33
|
+
/**
|
|
34
|
+
* Declares a resource member.
|
|
35
|
+
*
|
|
36
|
+
* Backs the member factories the {@link resource!} module exposes, fixing what they share: the cardinality bounds are
|
|
37
|
+
* checked as they are stated, and the member is frozen as it is declared, so that a shape carrying it states the same
|
|
38
|
+
* member however many shapes it reaches.
|
|
39
|
+
*
|
|
40
|
+
* @typeParam M The member the calling factory states
|
|
41
|
+
*
|
|
42
|
+
* @param member The member to declare
|
|
43
|
+
*
|
|
44
|
+
* @returns An immutable member as stated
|
|
45
|
+
*
|
|
46
|
+
* @throws {@link !TypeError TypeError} Where the member states a negative bound, or bounds admitting no value at all
|
|
47
|
+
*/
|
|
48
|
+
export declare function declare<M>(member: Record<string, unknown>): M;
|
|
49
|
+
/**
|
|
50
|
+
* Merges the inheritance chain of a resource shape into a single shape.
|
|
51
|
+
*
|
|
52
|
+
* The merged shape states every member and constraint its resources are held to. A resource the shape admits is an
|
|
53
|
+
* instance of every shape extended: a member several of them state takes the narrowest definition, whatever order
|
|
54
|
+
* they are listed in, and a member the shape declares must narrow each inherited definition. Merging a shape already
|
|
55
|
+
* merged returns it unchanged at no cost, so every shape extending it may merge it again freely.
|
|
56
|
+
*
|
|
57
|
+
* @param shape The shape to merge
|
|
58
|
+
*
|
|
59
|
+
* @returns An immutable shape stating the inherited definitions alongside its own
|
|
60
|
+
*
|
|
61
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where the stated declarations are inconsistent with the
|
|
62
|
+
* inherited ones or with each other, where the extended shapes conflict on a field or member the shape leaves
|
|
63
|
+
* unstated, or where a member admitting literals states a reverse mapping, as a literal can't be a subject
|
|
64
|
+
*/
|
|
65
|
+
export declare function flatten(shape: ResourceShape): ResourceShape;
|
|
66
|
+
/**
|
|
67
|
+
* Checks whether a string is a well-formed identifier {@link ResourceConstraints.pattern | pattern}.
|
|
68
|
+
*
|
|
69
|
+
* @param value The string to check
|
|
70
|
+
*
|
|
71
|
+
* @returns `true` where `value` is an absolute or root-relative path of literal segments and `{name}` placeholders,
|
|
72
|
+
* optionally closed by `/` or by a `/*` wildcard; the wildcard may also stand alone on the root path
|
|
73
|
+
*/
|
|
74
|
+
export declare function isPattern(value: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Checks a set of resource constraints for internal consistency.
|
|
77
|
+
*
|
|
78
|
+
* Reports the contradictions that would leave a shape admitting no resource at all, so that a shape is rejected as it
|
|
79
|
+
* is built rather than when a resource is first matched against it.
|
|
80
|
+
*
|
|
81
|
+
* @param constraints The constraints to check
|
|
82
|
+
*
|
|
83
|
+
* @returns A trace of the inconsistencies found, or `undefined` where the constraints admit at least one resource
|
|
84
|
+
*/
|
|
85
|
+
export declare function checkResource(constraints: Partial<ResourceShape>): Optional<Trace>;
|
|
86
|
+
/**
|
|
87
|
+
* Checks a pair of cardinality bounds for internal consistency.
|
|
88
|
+
*
|
|
89
|
+
* Reports bounds that cross, leaving a member admitting no value at all, so that a contradiction between what is
|
|
90
|
+
* required and what is admitted surfaces as the member is settled rather than when a resource is first matched against
|
|
91
|
+
* it. An unstated bound leaves that end unbounded and crosses nothing.
|
|
92
|
+
*
|
|
93
|
+
* @param bounds The bounds to check
|
|
94
|
+
*
|
|
95
|
+
* @returns A trace of the inconsistency found, or `undefined` where the bounds admit at least one value
|
|
96
|
+
*/
|
|
97
|
+
export declare function checkBounds(bounds: Partial<PropertyBounds>): Optional<Trace>;
|
|
98
|
+
/**
|
|
99
|
+
* Checks the extended shapes for conflicts the extending shape leaves unsettled.
|
|
100
|
+
*
|
|
101
|
+
* Reports the inherited fields the extended shapes disagree on and the extending shape states no value for, so that a
|
|
102
|
+
* shape reaching the same field along two paths never resolves it by declaration order. The fields held to this rule
|
|
103
|
+
* are `space` on the resource and `hidden`, `name` and `description` on each of its properties, even where the
|
|
104
|
+
* extending shape redeclares the property; markers, which take `hidden` from their own declaration, are exempt.
|
|
105
|
+
*
|
|
106
|
+
* Also reports each undeclared member stated by several extended shapes if no definition narrows all the others.
|
|
107
|
+
* Such a member is rejected rather than settled by declaration order. The trace is keyed by the member name and lists
|
|
108
|
+
* why the closest definition fails to narrow the others, so a disagreement on a field is reported under that field.
|
|
109
|
+
*
|
|
110
|
+
* @param shape The extending shape
|
|
111
|
+
* @param parents The extended shapes, already merged
|
|
112
|
+
*
|
|
113
|
+
* @returns A trace of the conflicts found, or `undefined` where the extended shapes agree on every inherited field
|
|
114
|
+
*/
|
|
115
|
+
export declare function checkParents(shape: ResourceShape, parents: readonly ResourceShape[]): Optional<Trace>;
|
|
116
|
+
/**
|
|
117
|
+
* Checks that a shape states at most one identifier and one type.
|
|
118
|
+
*
|
|
119
|
+
* > [!IMPORTANT]
|
|
120
|
+
* > Members must be collapsed by name before they are counted: a marker reaching a shape under one name along several
|
|
121
|
+
* > inheritance paths, or redeclared over an inherited one, is a single member rather than a duplicate. Only markers
|
|
122
|
+
* > of the same kind held under *distinct* names are duplicates.
|
|
123
|
+
*
|
|
124
|
+
* @param members The merged members to check, collapsed by name
|
|
125
|
+
*
|
|
126
|
+
* @returns A trace of the duplicates found, or `undefined` where the shape states at most one of each
|
|
127
|
+
*/
|
|
128
|
+
export declare function checkSingletons(members: readonly {
|
|
129
|
+
readonly kind?: string;
|
|
130
|
+
}[]): Optional<Trace>;
|
|
131
|
+
/**
|
|
132
|
+
* Checks that no two members of a shape map to the same predicate.
|
|
133
|
+
*
|
|
134
|
+
* Forward and reverse mappings are counted apart, so the same IRI may serve both without conflict, but no two members
|
|
135
|
+
* may share a forward mapping, and no two a reverse one.
|
|
136
|
+
*
|
|
137
|
+
* @param shape The merged shape to check
|
|
138
|
+
*
|
|
139
|
+
* @returns A trace of the duplicates found, or `undefined` where every member maps to a predicate of its own
|
|
140
|
+
*/
|
|
141
|
+
export declare function checkPredicates(shape: ResourceShape): Optional<Trace>;
|
|
142
|
+
/**
|
|
143
|
+
* Checks that every reverse mapping of a shape ranges over resources alone.
|
|
144
|
+
*
|
|
145
|
+
* A reverse mapping makes each value the subject of the statement it writes, and a literal can't be a subject. A
|
|
146
|
+
* member stating a reverse mapping must therefore range over references, embedded resources, or unions of them. The
|
|
147
|
+
* check runs as the shape is built, so consumers never receive values they can't encode. A range or union branch
|
|
148
|
+
* deferred to break a definition cycle is exempt.
|
|
149
|
+
*
|
|
150
|
+
* @param shape The merged shape to check
|
|
151
|
+
*
|
|
152
|
+
* @returns A trace naming each member that maps a literal range in reverse, or `undefined` if every reverse mapping
|
|
153
|
+
* ranges over resources alone
|
|
154
|
+
*/
|
|
155
|
+
export declare function checkReverse(shape: ResourceShape): Optional<Trace>;
|
|
156
|
+
/**
|
|
157
|
+
* Reports whether a resource shape narrows an inherited one.
|
|
158
|
+
*
|
|
159
|
+
* Tests the override relation without building the merged shape, so that an incompatible extension is told apart from
|
|
160
|
+
* a legitimate refinement before either is committed to: a shape narrows the inherited one where its identifier
|
|
161
|
+
* `pattern` stays compatible, it adds no identifier the inherited shape omits, requires every identifier it requires,
|
|
162
|
+
* and every member it redeclares keeps its kind and narrows the one it overrides.
|
|
163
|
+
*
|
|
164
|
+
* The class a resource belongs to is settled apart, where a {@link value!Shape | shape} narrows another: a shape
|
|
165
|
+
* extending another is free to state a class of its own, while a shape standing in for another as a member range must
|
|
166
|
+
* belong to every class that one declares.
|
|
167
|
+
*
|
|
168
|
+
* @param target The overriding shape
|
|
169
|
+
* @param source The inherited shape
|
|
170
|
+
*
|
|
171
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
172
|
+
*/
|
|
173
|
+
export declare function narrowsResource(target: ResourceShape, source: ResourceShape): Optional<Trace>;
|
|
174
|
+
/**
|
|
175
|
+
* Reports whether a member narrows an inherited one.
|
|
176
|
+
*
|
|
177
|
+
* Tests the override relation without building the merged member. A member narrows the inherited one if both state
|
|
178
|
+
* the same `forward` and `reverse` mappings, `foreign` and `captive` have the same value wherever both sides state
|
|
179
|
+
* them, and its range narrows the inherited one, bound by bound and shape by shape. A child may take ownership of a
|
|
180
|
+
* member its parent left bare. It may also hide, label or describe the member regardless of what its parent states,
|
|
181
|
+
* as these facets restrict no value the member admits and the merged member takes the ones the child states.
|
|
182
|
+
*
|
|
183
|
+
* Mappings are compared as stated, unstated included: an override leaving them unstated must first take the inherited
|
|
184
|
+
* ones, as the {@link resource!resource | resource} factory does before testing the relation.
|
|
185
|
+
*
|
|
186
|
+
* @param target The overriding member
|
|
187
|
+
* @param source The inherited member
|
|
188
|
+
*
|
|
189
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
190
|
+
*/
|
|
191
|
+
export declare function narrowsProperty(target: Property, source: Property): Optional<Trace>;
|
|
192
|
+
/**
|
|
193
|
+
* Reports whether a member of any kind narrows an inherited one.
|
|
194
|
+
*
|
|
195
|
+
* Extends the {@link narrowsProperty | property override relation} to markers. A member narrows the inherited one if
|
|
196
|
+
* it keeps its kind and, for a property, narrows the inherited property. A marker narrows any marker of its kind,
|
|
197
|
+
* whatever their `hidden` flags, as the most derived declaration is taken whole.
|
|
198
|
+
*
|
|
199
|
+
* @param target The overriding member
|
|
200
|
+
* @param source The inherited member
|
|
201
|
+
*
|
|
202
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
203
|
+
*/
|
|
204
|
+
export declare function narrowsMember(target: Member, source: Member): Optional<Trace>;
|
|
205
|
+
/**
|
|
206
|
+
* Selects the narrowest of the definitions several shapes state for a member.
|
|
207
|
+
*
|
|
208
|
+
* Returns the definition narrowing every other, whatever order the definitions are listed in: the one every value of
|
|
209
|
+
* the member must satisfy. Among definitions narrowing each other, as markers of the same kind do, the first listed
|
|
210
|
+
* is returned. If no definition narrows every other, the result fails to narrow at least one of them, and callers
|
|
211
|
+
* must check it with {@link narrowsMember} before relying on it, reporting or rejecting the conflict it reveals.
|
|
212
|
+
*
|
|
213
|
+
* @param first The first definition stated for the member
|
|
214
|
+
* @param rest The other definitions stated for the member
|
|
215
|
+
*
|
|
216
|
+
* @returns The narrowest of the definitions stated
|
|
217
|
+
*/
|
|
218
|
+
export declare function narrowest(first: Member, ...rest: readonly Member[]): Member;
|
|
219
|
+
/**
|
|
220
|
+
* Merges a resource shape with an inherited one.
|
|
221
|
+
*
|
|
222
|
+
* Returns the single shape an extending resource is validated against, combining the inherited constraints with the
|
|
223
|
+
* overriding ones: the admitted identifiers intersect, the required ones accumulate, and members declared on both
|
|
224
|
+
* sides are merged one by one, a marker being taken whole from the overriding shape. A shape merged with itself is
|
|
225
|
+
* returned as it stands, so a shape inherited along several paths keeps its reference identity.
|
|
226
|
+
*
|
|
227
|
+
* @param target The overriding shape
|
|
228
|
+
* @param source The inherited shape
|
|
229
|
+
*
|
|
230
|
+
* @returns An immutable shape admitting the resources both `target` and `source` admit
|
|
231
|
+
*
|
|
232
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
|
|
233
|
+
*/
|
|
234
|
+
export declare function mergeResource(target: ResourceShape, source: ResourceShape): ResourceShape;
|
|
235
|
+
/**
|
|
236
|
+
* Merges a member with an inherited one.
|
|
237
|
+
*
|
|
238
|
+
* Returns the single member an extending resource is validated against: a range taking the tighter of the two
|
|
239
|
+
* cardinality bounds over the merged shape, the mappings both members share, and every other facet from whichever
|
|
240
|
+
* member states it. The overriding `hidden`, `name` and `description` take precedence; any other facet stated on both
|
|
241
|
+
* sides is the same, as the {@link narrowsProperty | override relation} requires.
|
|
242
|
+
*
|
|
243
|
+
* @param target The overriding member
|
|
244
|
+
* @param source The inherited member
|
|
245
|
+
*
|
|
246
|
+
* @returns An immutable member admitting the values both `target` and `source` admit
|
|
247
|
+
*
|
|
248
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
|
|
249
|
+
*/
|
|
250
|
+
export declare function mergeProperty(target: Property, source: Property): Property;
|
|
251
|
+
/**
|
|
252
|
+
* Merges a member of any kind with an inherited one.
|
|
253
|
+
*
|
|
254
|
+
* Returns the single member an extending resource is validated against: a {@link mergeProperty | merged property}
|
|
255
|
+
* where both are properties, and the overriding marker taken whole, `hidden` included, where both name a resource.
|
|
256
|
+
*
|
|
257
|
+
* @param target The overriding member
|
|
258
|
+
* @param source The inherited member
|
|
259
|
+
*
|
|
260
|
+
* @returns An immutable member admitting the values both `target` and `source` admit
|
|
261
|
+
*
|
|
262
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
|
|
263
|
+
*/
|
|
264
|
+
export declare function mergeMember(target: Member, source: Member): Member;
|
|
265
|
+
//# sourceMappingURL=assembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.d.ts","sourceRoot":"","sources":["../../src/resource/assembler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AAEH,OAAO,EAQN,KAAK,QAAQ,EACb,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAKpE,OAAO,KAAK,EACX,MAAM,EAGN,QAAQ,EACR,cAAc,EAEd,aAAa,EACb,MAAM,YAAY,CAAC;AAwBpB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,aAAa,CAqMhE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAmB7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAqG3D;AA8DD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AAGD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,KA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