@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,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number value validation.
|
|
3
|
+
*
|
|
4
|
+
* Holds a value to what a number shape admits and reports everything wrong with it at once, keyed by the facet at
|
|
5
|
+
* fault, at the strictness the caller asks for: a stored value or a retrieval placeholder.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type Optional } from "@grafctory/core";
|
|
10
|
+
import { type Trace } from "@grafctory/core/trace";
|
|
11
|
+
import { type Scope } from "../value/validator.js";
|
|
12
|
+
import { type NumberShape } from "./index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Validates values against a number shape.
|
|
15
|
+
*
|
|
16
|
+
* Reports each value that is not a number as a `{type}` violation and each number that breaks a constraint under its
|
|
17
|
+
* own facet, keying every element violation by its index, so that a caller may tell which value failed and why;
|
|
18
|
+
* membership over the whole set (`hasValue`) is reported as a leading bare message.
|
|
19
|
+
*
|
|
20
|
+
* @param values The values to validate
|
|
21
|
+
* @param shape The shape the values are matched against
|
|
22
|
+
* @param opts Validation options
|
|
23
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. `"model"` admits
|
|
24
|
+
* the atomic placeholder
|
|
25
|
+
*
|
|
26
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
27
|
+
*/
|
|
28
|
+
export declare const validateNumber: (values: readonly unknown[], shape: NumberShape, opts?: {
|
|
29
|
+
scope?: Scope;
|
|
30
|
+
}) => Optional<Trace>;
|
|
31
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/number/validator.ts"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AAEH,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAiD,KAAK,KAAK,EAA4C,MACxG,uBAAuB,CAAC;AAC9B,OAAO,EAAE,KAAK,KAAK,EAAU,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE;IAEpF,KAAK,CAAC,EAAE,KAAK,CAAA;CAEb,KAAK,QAAQ,CAAC,KAAK,CAAwB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
* Number value validation.
|
|
18
|
+
*
|
|
19
|
+
* Holds a value to what a number shape admits and reports everything wrong with it at once, keyed by the facet at
|
|
20
|
+
* fault, at the strictness the caller asks for: a stored value or a retrieval placeholder.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { isNumber } from "@grafctory/core";
|
|
25
|
+
import { isAtomic } from "@grafctory/qest/model";
|
|
26
|
+
import { all, array, domain, gt, gte, integer, lt, lte, type, values as contains } from "@grafctory/core/trace";
|
|
27
|
+
import { scoped } from "../value/validator.js";
|
|
28
|
+
/**
|
|
29
|
+
* Validates values against a number shape.
|
|
30
|
+
*
|
|
31
|
+
* Reports each value that is not a number as a `{type}` violation and each number that breaks a constraint under its
|
|
32
|
+
* own facet, keying every element violation by its index, so that a caller may tell which value failed and why;
|
|
33
|
+
* membership over the whole set (`hasValue`) is reported as a leading bare message.
|
|
34
|
+
*
|
|
35
|
+
* @param values The values to validate
|
|
36
|
+
* @param shape The shape the values are matched against
|
|
37
|
+
* @param opts Validation options
|
|
38
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. `"model"` admits
|
|
39
|
+
* the atomic placeholder
|
|
40
|
+
*
|
|
41
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
42
|
+
*/
|
|
43
|
+
export const validateNumber = scoped(state, model);
|
|
44
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
45
|
+
/**
|
|
46
|
+
* Every constraint: a legal element of the shape's domain.
|
|
47
|
+
*/
|
|
48
|
+
function state({ minExclusive, maxExclusive, minInclusive, maxInclusive, integral, in: allowed, hasValue: required }) {
|
|
49
|
+
return array(type(isNumber, all(integral && integer(), gt(minExclusive), lt(maxExclusive), gte(minInclusive), lte(maxInclusive), domain(allowed))), contains(required));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The form alone: a retrieval placeholder asks for the value as it stands and carries none of its own.
|
|
53
|
+
*/
|
|
54
|
+
function model({}) {
|
|
55
|
+
return array(type(isAtomic));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/number/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAiB,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAc,IAAI,EAAkB,MAAM,IAAI,QAAQ,EAAE,MACxG,uBAAuB,CAAC;AAC9B,OAAO,EAAc,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,cAAc,GAIH,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAG7C,wHAAwH;AAExH;;GAEG;AACH,SAAS,KAAK,CAAC,EAEd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EAEZ,QAAQ,EAER,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,QAAQ,EAEL;IAEb,OAAO,KAAK,CACX,IAAI,CAAC,QAAQ,EACZ,GAAG,CACF,QAAQ,IAAI,OAAO,EAAE,EACrB,EAAE,CAAC,YAAY,CAAC,EAChB,EAAE,CAAC,YAAY,CAAC,EAChB,GAAG,CAAC,YAAY,CAAC,EACjB,GAAG,CAAC,YAAY,CAAC,EACjB,MAAM,CAAC,OAAO,CAAC,CACf,CACD,EACD,QAAQ,CAAC,QAAQ,CAAC,CAClB,CAAC;AAEH,CAAC;AAED;;GAEG;AACH,SAAS,KAAK,CAAC,EAAe;IAE7B,OAAO,KAAK,CACX,IAAI,CAAC,QAAQ,CAAC,CACd,CAAC;AAEH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference shape accessors.
|
|
3
|
+
*
|
|
4
|
+
* Reads off a shape the resource shape it reaches, crossing a link and taking a resource to itself, so that a caller
|
|
5
|
+
* needs not tell a link from a resource carried inline. Crossing a link whose target was deferred to break a
|
|
6
|
+
* definition cycle is where a re-pointed target is held to the one it overrides.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type Lazy, type Optional } from "@grafctory/core";
|
|
11
|
+
import type { ResourceShape } from "../resource/index.js";
|
|
12
|
+
import { type Shape } from "../value/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the resource shape a shape points at.
|
|
15
|
+
*
|
|
16
|
+
* Crosses a reference to the shape it points at and takes a resource shape to itself, so that a caller reaching for
|
|
17
|
+
* the members behind a shape needs not tell a link from a resource carried inline. A shape describing a plain or
|
|
18
|
+
* localised value, or a union, points at no resource and yields nothing.
|
|
19
|
+
*
|
|
20
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
21
|
+
*
|
|
22
|
+
* @returns The resource shape `shape` points at, merged with the shapes it extends, or `undefined` where it points at
|
|
23
|
+
* none
|
|
24
|
+
*
|
|
25
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
26
|
+
* break the cycle, or where a deferred target doesn't narrow the target of the link it overrides
|
|
27
|
+
*/
|
|
28
|
+
export declare function getShapeTarget(shape: Lazy<Shape>): Optional<ResourceShape>;
|
|
29
|
+
//# sourceMappingURL=accessors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../src/reference/accessors.ts"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAS,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,CAQ1E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { eager } from "../value/index.js";
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the resource shape a shape points at.
|
|
19
|
+
*
|
|
20
|
+
* Crosses a reference to the shape it points at and takes a resource shape to itself, so that a caller reaching for
|
|
21
|
+
* the members behind a shape needs not tell a link from a resource carried inline. A shape describing a plain or
|
|
22
|
+
* localised value, or a union, points at no resource and yields nothing.
|
|
23
|
+
*
|
|
24
|
+
* @param shape The shape to resolve, possibly deferred to break definition cycles
|
|
25
|
+
*
|
|
26
|
+
* @returns The resource shape `shape` points at, merged with the shapes it extends, or `undefined` where it points at
|
|
27
|
+
* none
|
|
28
|
+
*
|
|
29
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself with no link to
|
|
30
|
+
* break the cycle, or where a deferred target doesn't narrow the target of the link it overrides
|
|
31
|
+
*/
|
|
32
|
+
export function getShapeTarget(shape) {
|
|
33
|
+
const resolved = eager(shape);
|
|
34
|
+
return resolved.kind === "resource" ? resolved
|
|
35
|
+
: resolved.kind === "reference" ? eager(resolved.target)
|
|
36
|
+
: undefined;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=accessors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.js","sourceRoot":"","sources":["../../src/reference/accessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAeH,OAAO,EAAE,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAGtD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,KAAkB;IAEhD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAE9B,OAAO,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ;QAC7C,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;YACvD,CAAC,CAAC,SAAS,CAAC;AAEf,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference shape assembly.
|
|
3
|
+
*
|
|
4
|
+
* Builds the shape the factory states into the form its consumers read, and combines it with the one it overrides: an
|
|
5
|
+
* extension is held to the shape it refines, narrowing exactly when its target is the inherited target or extends it,
|
|
6
|
+
* with a target deferred to break a definition cycle held to the same rule as the link is first crossed.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type Lazy, type Optional } from "@grafctory/core";
|
|
11
|
+
import { type Trace } from "@grafctory/core/trace";
|
|
12
|
+
import type { ResourceShape } from "../resource/index.js";
|
|
13
|
+
import type { ReferenceShape } from "./index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Assembles a reference shape.
|
|
16
|
+
*
|
|
17
|
+
* Backs the factory the {@link reference!} module exposes. The target is kept as it was stated, deferred or not, so
|
|
18
|
+
* that a cycle among definitions is broken by whichever end defers.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam T The shape the reference points at
|
|
21
|
+
*
|
|
22
|
+
* @param target The shape describing the resource the reference points at
|
|
23
|
+
*
|
|
24
|
+
* @returns An immutable shape admitting the IRIs naming resources of the stated target shape
|
|
25
|
+
*/
|
|
26
|
+
export declare function assemble<T extends Lazy<ResourceShape>>(target: T): ReferenceShape<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Reports whether a reference shape narrows an inherited one.
|
|
29
|
+
*
|
|
30
|
+
* Tests the override relation without building the merged shape. A reference states nothing of its own beyond the
|
|
31
|
+
* shape it points at, so it narrows the inherited one exactly when its target is the inherited target or extends it,
|
|
32
|
+
* directly or transitively.
|
|
33
|
+
*
|
|
34
|
+
* A deferred target is admitted unread: a link is deferred exactly so that a definition may reach itself, so resolving
|
|
35
|
+
* one here would state a definition the shape being built is part of, which is what a deferral withholds. The
|
|
36
|
+
* obligation is not waived but carried by {@link mergeReference} to the link itself, which holds the target to the
|
|
37
|
+
* inherited chain when it is first crossed.
|
|
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` or defers the
|
|
43
|
+
* shape it points at
|
|
44
|
+
*/
|
|
45
|
+
export declare function narrowsReference(target: ReferenceShape, source: ReferenceShape): Optional<Trace>;
|
|
46
|
+
/**
|
|
47
|
+
* Merges a reference shape with an inherited one.
|
|
48
|
+
*
|
|
49
|
+
* Yields the single shape an extending member is validated against: the overriding target, which already carries the
|
|
50
|
+
* inherited definition through its own inheritance chain. A target stated outright is held to that chain at once; a
|
|
51
|
+
* deferred one is held to it as the link is first crossed, its chain standing only then, so that a shape re-pointed at
|
|
52
|
+
* one extending it merges whatever order the definitions happen to be built in.
|
|
53
|
+
*
|
|
54
|
+
* @param target The overriding shape
|
|
55
|
+
* @param source The inherited shape
|
|
56
|
+
*
|
|
57
|
+
* @returns An immutable shape pointing at the narrower of the two targets, deferred where `target` defers it
|
|
58
|
+
*
|
|
59
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` states a shape that doesn't narrow `source`;
|
|
60
|
+
* where it defers one, the same report is raised as the link is crossed
|
|
61
|
+
*/
|
|
62
|
+
export declare function mergeReference(target: ReferenceShape, source: ReferenceShape): ReferenceShape;
|
|
63
|
+
//# sourceMappingURL=assembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.d.ts","sourceRoot":"","sources":["../../src/reference/assembler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AAEH,OAAO,EAAc,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAUpF;AAKD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAC,CAIhG;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,cAAc,CAkB7F"}
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
* Reference shape assembly.
|
|
18
|
+
*
|
|
19
|
+
* Builds the shape the factory states into the form its consumers read, and combines it with the one it overrides: an
|
|
20
|
+
* extension is held to the shape it refines, narrowing exactly when its target is the inherited target or extends it,
|
|
21
|
+
* with a target deferred to break a definition cycle held to the same rule as the link is first crossed.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { isFunction } from "@grafctory/core";
|
|
26
|
+
import { equals, immutable } from "@grafctory/core/values";
|
|
27
|
+
import { reject } from "../value/assembler.js";
|
|
28
|
+
import { eager } from "../value/index.js";
|
|
29
|
+
/**
|
|
30
|
+
* Assembles a reference shape.
|
|
31
|
+
*
|
|
32
|
+
* Backs the factory the {@link reference!} module exposes. The target is kept as it was stated, deferred or not, so
|
|
33
|
+
* that a cycle among definitions is broken by whichever end defers.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam T The shape the reference points at
|
|
36
|
+
*
|
|
37
|
+
* @param target The shape describing the resource the reference points at
|
|
38
|
+
*
|
|
39
|
+
* @returns An immutable shape admitting the IRIs naming resources of the stated target shape
|
|
40
|
+
*/
|
|
41
|
+
export function assemble(target) {
|
|
42
|
+
return immutable({
|
|
43
|
+
kind: "reference",
|
|
44
|
+
target
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
48
|
+
/**
|
|
49
|
+
* Reports whether a reference shape narrows an inherited one.
|
|
50
|
+
*
|
|
51
|
+
* Tests the override relation without building the merged shape. A reference states nothing of its own beyond the
|
|
52
|
+
* shape it points at, so it narrows the inherited one exactly when its target is the inherited target or extends it,
|
|
53
|
+
* directly or transitively.
|
|
54
|
+
*
|
|
55
|
+
* A deferred target is admitted unread: a link is deferred exactly so that a definition may reach itself, so resolving
|
|
56
|
+
* one here would state a definition the shape being built is part of, which is what a deferral withholds. The
|
|
57
|
+
* obligation is not waived but carried by {@link mergeReference} to the link itself, which holds the target to the
|
|
58
|
+
* inherited chain when it is first crossed.
|
|
59
|
+
*
|
|
60
|
+
* @param target The overriding shape
|
|
61
|
+
* @param source The inherited shape
|
|
62
|
+
*
|
|
63
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source` or defers the
|
|
64
|
+
* shape it points at
|
|
65
|
+
*/
|
|
66
|
+
export function narrowsReference(target, source) {
|
|
67
|
+
return narrowsTarget(target.target, source);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Merges a reference shape with an inherited one.
|
|
71
|
+
*
|
|
72
|
+
* Yields the single shape an extending member is validated against: the overriding target, which already carries the
|
|
73
|
+
* inherited definition through its own inheritance chain. A target stated outright is held to that chain at once; a
|
|
74
|
+
* deferred one is held to it as the link is first crossed, its chain standing only then, so that a shape re-pointed at
|
|
75
|
+
* one extending it merges whatever order the definitions happen to be built in.
|
|
76
|
+
*
|
|
77
|
+
* @param target The overriding shape
|
|
78
|
+
* @param source The inherited shape
|
|
79
|
+
*
|
|
80
|
+
* @returns An immutable shape pointing at the narrower of the two targets, deferred where `target` defers it
|
|
81
|
+
*
|
|
82
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `target` states a shape that doesn't narrow `source`;
|
|
83
|
+
* where it defers one, the same report is raised as the link is crossed
|
|
84
|
+
*/
|
|
85
|
+
export function mergeReference(target, source) {
|
|
86
|
+
const { target: pointed } = target;
|
|
87
|
+
return assemble(isFunction(pointed) ? () => narrowed(eager(pointed)) : narrowed(pointed));
|
|
88
|
+
/**
|
|
89
|
+
* Holds a stated target to the inherited chain.
|
|
90
|
+
*/
|
|
91
|
+
function narrowed(shape) {
|
|
92
|
+
reject("incompatible reference shape override", narrowsTarget(shape, source));
|
|
93
|
+
return shape;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
97
|
+
/**
|
|
98
|
+
* Reports whether the shape a link points at narrows the inherited target.
|
|
99
|
+
*
|
|
100
|
+
* @param pointed The shape the overriding link points at, possibly deferred to break definition cycles
|
|
101
|
+
* @param source The inherited shape
|
|
102
|
+
*
|
|
103
|
+
* @returns A trace of the obstacles to the override, or `undefined` where `pointed` narrows the target of `source` or
|
|
104
|
+
* is deferred
|
|
105
|
+
*/
|
|
106
|
+
function narrowsTarget(pointed, source) {
|
|
107
|
+
return isFunction(pointed) || extended(eager(pointed), eager(source.target))
|
|
108
|
+
? undefined
|
|
109
|
+
: [`{target} incompatible <target> override`];
|
|
110
|
+
/**
|
|
111
|
+
* Reports whether a target is an inherited one or extends it, directly or transitively.
|
|
112
|
+
*/
|
|
113
|
+
function extended(pointed, inherited) {
|
|
114
|
+
return lineage(pointed).some(ancestor => equals(ancestor, inherited));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Lists a resource shape and the shapes it extends.
|
|
118
|
+
*
|
|
119
|
+
* @param shape The shape to walk
|
|
120
|
+
*
|
|
121
|
+
* @returns `shape` followed by every shape it extends, directly or transitively
|
|
122
|
+
*/
|
|
123
|
+
function lineage(shape) {
|
|
124
|
+
return [shape, ...shape.parents.flatMap(parent => lineage(eager(parent)))];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=assembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/reference/assembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAA4B,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI1C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CAAgC,MAAS;IAEhE,OAAO,SAAS,CAAC;QAEhB,IAAI,EAAE,WAAW;QAEjB,MAAM;KAEN,CAAC,CAAC;AAEJ,CAAC;AAGD,wHAAwH;AAExH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAsB,EAAE,MAAsB;IAE9E,OAAO,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7C,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB,EAAE,MAAsB;IAE5E,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEnC,OAAO,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAG1F;;OAEG;IACH,SAAS,QAAQ,CAAC,KAAoB;QAErC,MAAM,CAAC,uCAAuC,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;QAE9E,OAAO,KAAK,CAAC;IAEd,CAAC;AAEF,CAAC;AAGD,wHAAwH;AAExH;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAA4B,EAAE,MAAsB;IAE1E,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3E,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,yCAAyC,CAAC,CAAC;IAG/C;;OAEG;IACH,SAAS,QAAQ,CAAC,OAAsB,EAAE,SAAwB;QACjE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IACvE,CAAC;IAGD;;;;;;OAMG;IACH,SAAS,OAAO,CAAC,KAAoB;QACpC,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;AAEF,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference shape types and operations.
|
|
3
|
+
*
|
|
4
|
+
* Defines the shape linking a resource to another **standalone resource**, named by an absolute IRI, and provides the
|
|
5
|
+
* {@link reference} factory stating it and the accessor reading its target. The factory pairs the IRI with the
|
|
6
|
+
* {@link resource!ResourceShape | shape} describing the resource it points at, deferred where a definition cycle
|
|
7
|
+
* requires it, so a member pointing at a resource carries the identifier alone and leaves the resource to be retrieved
|
|
8
|
+
* in its own right.
|
|
9
|
+
*
|
|
10
|
+
* **Defining reference members**
|
|
11
|
+
*
|
|
12
|
+
* Wrap a target resource shape with {@link reference} and give it a cardinality:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { id, multiple, required, resource } from '@grafctory/blue/resource';
|
|
16
|
+
* import { reference } from '@grafctory/blue/reference';
|
|
17
|
+
*
|
|
18
|
+
* const Vendor = resource({
|
|
19
|
+
* id: id()
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const Product = resource({
|
|
23
|
+
* id: id(),
|
|
24
|
+
* vendor: required(reference(Vendor)),
|
|
25
|
+
* suppliers: multiple(reference(Vendor))
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* **Standalone and embedded resources**
|
|
30
|
+
*
|
|
31
|
+
* A reference links to a **standalone resource**, identified and managed in its own right. A resource shape included
|
|
32
|
+
* directly, without the wrapper, describes an **embedded resource**: a nested value with no identity of its own,
|
|
33
|
+
* created and managed together with the resource carrying it.
|
|
34
|
+
*
|
|
35
|
+
* Ownership and lifecycle are stated on the member rather than on the reference: see
|
|
36
|
+
* {@link resource!PropertyConstraints.foreign | foreign} and {@link resource!PropertyConstraints.captive | captive}.
|
|
37
|
+
*
|
|
38
|
+
* **Reading a target off a shape**
|
|
39
|
+
*
|
|
40
|
+
* {@link getShapeTarget} resolves the resource shape a shape points at, crossing a link and taking a resource carried
|
|
41
|
+
* inline to itself, so that a caller reaching for what lies behind a shape needs not tell the two apart.
|
|
42
|
+
*
|
|
43
|
+
* @module
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://www.w3.org/TR/shacl/#node-shapes SHACL § 2.2 Node Shapes}
|
|
46
|
+
*/
|
|
47
|
+
import type { Lazy } from "@grafctory/core";
|
|
48
|
+
import type { ResourceShape } from "../resource/index.js";
|
|
49
|
+
export { getShapeTarget } from "./accessors.js";
|
|
50
|
+
/**
|
|
51
|
+
* Describes a link to a standalone resource.
|
|
52
|
+
*
|
|
53
|
+
* Admits the absolute IRI naming the resource the link points at, so that a member pointing at a resource carries the
|
|
54
|
+
* identifier alone and leaves the resource itself to be retrieved in its own right. The shape states what the target
|
|
55
|
+
* is, so the constraints the target puts on its own identifiers bound the link as well.
|
|
56
|
+
*
|
|
57
|
+
* **Inheritance**
|
|
58
|
+
*
|
|
59
|
+
* Where a {@link resource!ResourceShape} extends the shapes it lists as `parents`, reference-valued members are merged
|
|
60
|
+
* according to the following rules. The *child* is the extending shape; the *parent* is the inherited one.
|
|
61
|
+
*
|
|
62
|
+
* | Field | Override Rule |
|
|
63
|
+
* | -------- | ------------------------------------------------------------ |
|
|
64
|
+
* | `kind` | Cannot be overridden |
|
|
65
|
+
* | `target` | May be re-pointed at a shape extending the inherited target |
|
|
66
|
+
*
|
|
67
|
+
* @typeParam T The shape the reference points at, possibly deferred to break definition cycles
|
|
68
|
+
*
|
|
69
|
+
* @see {@link https://www.w3.org/TR/shacl/#node-shapes SHACL § 2.2 Node Shapes}
|
|
70
|
+
*/
|
|
71
|
+
export type ReferenceShape<T extends Lazy<ResourceShape> = Lazy<ResourceShape>> = {
|
|
72
|
+
/**
|
|
73
|
+
* Discriminator identifying this as a reference shape.
|
|
74
|
+
*
|
|
75
|
+
* **Inheritance** — cannot be overridden.
|
|
76
|
+
*/
|
|
77
|
+
readonly kind: "reference";
|
|
78
|
+
/**
|
|
79
|
+
* Shape describing the resource the reference points at, possibly deferred to break definition cycles.
|
|
80
|
+
*
|
|
81
|
+
* **Inheritance** — may be re-pointed at a shape that lists the inherited target among its `parents`, directly or
|
|
82
|
+
* transitively, so an extending shape refines what a link admits by naming the narrower target alone; the inherited
|
|
83
|
+
* definition reaches the refined target through its own inheritance chain and is never restated. Any other target
|
|
84
|
+
* is rejected. A target deferred to break a definition cycle is held to the same rule once its definition stands,
|
|
85
|
+
* so a shape may be re-pointed at one extending it, and a pair of shapes reaching each other at each other.
|
|
86
|
+
*/
|
|
87
|
+
readonly target: T;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Creates a reference shape.
|
|
91
|
+
*
|
|
92
|
+
* @typeParam T The shape the reference points at
|
|
93
|
+
*
|
|
94
|
+
* @param target The shape describing the resource the reference points at, possibly deferred to break definition
|
|
95
|
+
* cycles
|
|
96
|
+
*
|
|
97
|
+
* @returns An immutable shape admitting the IRIs naming resources of the stated target shape
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const vendor = required(reference(Vendor));
|
|
103
|
+
* const children = multiple(reference(Target), { foreign: true });
|
|
104
|
+
* const parts = multiple(reference(Part), { captive: true });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function reference<T extends Lazy<ResourceShape>>(target: T): ReferenceShape<T>;
|
|
108
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reference/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI;IAEjF;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAE1B;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAElB,CAAA;AAKD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAIrF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { assemble } from "./assembler.js";
|
|
17
|
+
export { getShapeTarget } from "./accessors.js";
|
|
18
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
/**
|
|
20
|
+
* Creates a reference shape.
|
|
21
|
+
*
|
|
22
|
+
* @typeParam T The shape the reference points at
|
|
23
|
+
*
|
|
24
|
+
* @param target The shape describing the resource the reference points at, possibly deferred to break definition
|
|
25
|
+
* cycles
|
|
26
|
+
*
|
|
27
|
+
* @returns An immutable shape admitting the IRIs naming resources of the stated target shape
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const vendor = required(reference(Vendor));
|
|
33
|
+
* const children = multiple(reference(Target), { foreign: true });
|
|
34
|
+
* const parts = multiple(reference(Part), { captive: true });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function reference(target) {
|
|
38
|
+
return assemble(target);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reference/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmDH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA+ChD,wHAAwH;AAExH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CAAgC,MAAS;IAEjE,OAAO,QAAQ,CAAI,MAAM,CAAC,CAAC;AAE5B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference value validation.
|
|
3
|
+
*
|
|
4
|
+
* Holds a value to what a reference shape admits and reports everything wrong with it at once: an IRI naming a
|
|
5
|
+
* resource of the target shape, held to the target's own identifier constraints at the strictness the caller asks for.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type Optional } from "@grafctory/core";
|
|
10
|
+
import { type Trace } from "@grafctory/core/trace";
|
|
11
|
+
import { type Scope } from "../value/validator.js";
|
|
12
|
+
import type { ReferenceShape } from "./index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Validates values against a reference shape.
|
|
15
|
+
*
|
|
16
|
+
* Reports each value that is not an IRI naming a resource as a `{type}` violation and each IRI the target refuses
|
|
17
|
+
* under its own facet, keying every element violation by its index, so that a caller may tell which link failed and
|
|
18
|
+
* why; membership over the whole set (`hasValue`) is reported as a leading bare message. A reference states no
|
|
19
|
+
* constraint of its own, so the ones enforced are the ones the target puts on its own identifiers.
|
|
20
|
+
*
|
|
21
|
+
* @param values The values to validate
|
|
22
|
+
* @param shape The shape the values are matched against
|
|
23
|
+
* @param opts Validation options
|
|
24
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. A `"model"` skips
|
|
25
|
+
* every target constraint and admits the atomic placeholder alone, a link left unexpanded coming back as the
|
|
26
|
+
* IRI naming its target
|
|
27
|
+
*
|
|
28
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateReference(values: readonly unknown[], shape: ReferenceShape, { scope }?: {
|
|
31
|
+
scope?: Scope;
|
|
32
|
+
}): Optional<Trace>;
|
|
33
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/reference/validator.ts"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAMN,KAAK,KAAK,EAIV,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAAS,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,EAEpF,KAAe,EAEf,GAAE;IAEF,KAAK,CAAC,EAAE,KAAK,CAAA;CAER,GAAG,QAAQ,CAAC,KAAK,CAAC,CA+CvB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { all, array, domain, pass, test, type, values as contains } from "@grafctory/core/trace";
|
|
17
|
+
import { isAtomic } from "@grafctory/qest/model";
|
|
18
|
+
import { isReference } from "@grafctory/qest/state";
|
|
19
|
+
import { eager } from "../value/index.js";
|
|
20
|
+
import { match } from "../value/validator.js";
|
|
21
|
+
/**
|
|
22
|
+
* Validates values against a reference shape.
|
|
23
|
+
*
|
|
24
|
+
* Reports each value that is not an IRI naming a resource as a `{type}` violation and each IRI the target refuses
|
|
25
|
+
* under its own facet, keying every element violation by its index, so that a caller may tell which link failed and
|
|
26
|
+
* why; membership over the whole set (`hasValue`) is reported as a leading bare message. A reference states no
|
|
27
|
+
* constraint of its own, so the ones enforced are the ones the target puts on its own identifiers.
|
|
28
|
+
*
|
|
29
|
+
* @param values The values to validate
|
|
30
|
+
* @param shape The shape the values are matched against
|
|
31
|
+
* @param opts Validation options
|
|
32
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. A `"model"` skips
|
|
33
|
+
* every target constraint and admits the atomic placeholder alone, a link left unexpanded coming back as the
|
|
34
|
+
* IRI naming its target
|
|
35
|
+
*
|
|
36
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
37
|
+
*/
|
|
38
|
+
export function validateReference(values, shape, { scope = "state" } = {}) {
|
|
39
|
+
const target = eager(shape.target);
|
|
40
|
+
switch (scope) {
|
|
41
|
+
case "state":
|
|
42
|
+
return state(target)(values);
|
|
43
|
+
case "model":
|
|
44
|
+
return model(target)(values);
|
|
45
|
+
}
|
|
46
|
+
function state({ pattern, in: allowed, hasValue: required }) {
|
|
47
|
+
return array(type(isReference, all(matches(pattern), domain(allowed))), contains(required));
|
|
48
|
+
}
|
|
49
|
+
function model({}) {
|
|
50
|
+
return array(type(isAtomic));
|
|
51
|
+
}
|
|
52
|
+
function matches(pattern) {
|
|
53
|
+
return pattern === undefined ? pass : test(value => match(value, pattern) || [`{pattern} expected IRI matching pattern <${pattern}>`]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/reference/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EACN,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EAEJ,IAAI,EAEJ,MAAM,IAAI,QAAQ,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAc,MAAM,uBAAuB,CAAC;AAI1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA0B,EAAE,KAAqB,EAAE,EAEpF,KAAK,GAAG,OAAO,KAMZ,EAAE;IAEL,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEnC,QAAS,KAAK,EAAG,CAAC;QAEjB,KAAK,OAAO;YAEX,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;QAE9B,KAAK,OAAO;YAEX,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;IAE/B,CAAC;IAGD,SAAS,KAAK,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAiB;QAEzE,OAAO,KAAK,CACX,IAAI,CAAC,WAAW,EACf,GAAG,CACF,OAAO,CAAC,OAAO,CAAC,EAChB,MAAM,CAAC,OAAO,CAAC,CACf,CACD,EACD,QAAQ,CAAC,QAAQ,CAAC,CAClB,CAAC;IAEH,CAAC;IAED,SAAS,KAAK,CAAC,EAAiB;QAE/B,OAAO,KAAK,CACX,IAAI,CAAC,QAAQ,CAAC,CACd,CAAC;IAEH,CAAC;IAED,SAAS,OAAO,CAAC,OAAyB;QAEzC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAS,KAAK,CAAC,EAAE,CAC1D,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,4CAA4C,OAAO,GAAG,CAAC,CACjF,CAAC;IAEH,CAAC;AAEF,CAAC"}
|