@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.
Files changed (139) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +509 -2
  3. package/dist/boolean/assembler.d.ts +53 -0
  4. package/dist/boolean/assembler.d.ts.map +1 -0
  5. package/dist/boolean/assembler.js +78 -0
  6. package/dist/boolean/assembler.js.map +1 -0
  7. package/dist/boolean/index.d.ts +86 -0
  8. package/dist/boolean/index.d.ts.map +1 -0
  9. package/dist/boolean/index.js +99 -0
  10. package/dist/boolean/index.js.map +1 -0
  11. package/dist/boolean/validator.d.ts +30 -0
  12. package/dist/boolean/validator.d.ts.map +1 -0
  13. package/dist/boolean/validator.js +68 -0
  14. package/dist/boolean/validator.js.map +1 -0
  15. package/dist/dictionary/assembler.d.ts +70 -0
  16. package/dist/dictionary/assembler.d.ts.map +1 -0
  17. package/dist/dictionary/assembler.js +154 -0
  18. package/dist/dictionary/assembler.js.map +1 -0
  19. package/dist/dictionary/index.d.ts +211 -0
  20. package/dist/dictionary/index.d.ts.map +1 -0
  21. package/dist/dictionary/index.js +43 -0
  22. package/dist/dictionary/index.js.map +1 -0
  23. package/dist/dictionary/inference.d.ts +42 -0
  24. package/dist/dictionary/inference.d.ts.map +1 -0
  25. package/dist/dictionary/inference.js +17 -0
  26. package/dist/dictionary/inference.js.map +1 -0
  27. package/dist/dictionary/validator.d.ts +34 -0
  28. package/dist/dictionary/validator.d.ts.map +1 -0
  29. package/dist/dictionary/validator.js +91 -0
  30. package/dist/dictionary/validator.js.map +1 -0
  31. package/dist/index.core.d.ts +33 -0
  32. package/dist/index.core.d.ts.map +1 -0
  33. package/dist/index.core.js +149 -0
  34. package/dist/index.core.js.map +1 -0
  35. package/dist/index.d.ts +333 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +378 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/number/assembler.d.ts +70 -0
  40. package/dist/number/assembler.d.ts.map +1 -0
  41. package/dist/number/assembler.js +188 -0
  42. package/dist/number/assembler.js.map +1 -0
  43. package/dist/number/index.d.ts +329 -0
  44. package/dist/number/index.d.ts.map +1 -0
  45. package/dist/number/index.js +312 -0
  46. package/dist/number/index.js.map +1 -0
  47. package/dist/number/validator.d.ts +31 -0
  48. package/dist/number/validator.d.ts.map +1 -0
  49. package/dist/number/validator.js +57 -0
  50. package/dist/number/validator.js.map +1 -0
  51. package/dist/reference/accessors.d.ts +29 -0
  52. package/dist/reference/accessors.d.ts.map +1 -0
  53. package/dist/reference/accessors.js +38 -0
  54. package/dist/reference/accessors.js.map +1 -0
  55. package/dist/reference/assembler.d.ts +63 -0
  56. package/dist/reference/assembler.d.ts.map +1 -0
  57. package/dist/reference/assembler.js +127 -0
  58. package/dist/reference/assembler.js.map +1 -0
  59. package/dist/reference/index.d.ts +108 -0
  60. package/dist/reference/index.d.ts.map +1 -0
  61. package/dist/reference/index.js +40 -0
  62. package/dist/reference/index.js.map +1 -0
  63. package/dist/reference/validator.d.ts +33 -0
  64. package/dist/reference/validator.d.ts.map +1 -0
  65. package/dist/reference/validator.js +56 -0
  66. package/dist/reference/validator.js.map +1 -0
  67. package/dist/resource/accessors.d.ts +140 -0
  68. package/dist/resource/accessors.d.ts.map +1 -0
  69. package/dist/resource/accessors.js +173 -0
  70. package/dist/resource/accessors.js.map +1 -0
  71. package/dist/resource/assembler.d.ts +265 -0
  72. package/dist/resource/assembler.d.ts.map +1 -0
  73. package/dist/resource/assembler.js +816 -0
  74. package/dist/resource/assembler.js.map +1 -0
  75. package/dist/resource/index.d.ts +898 -0
  76. package/dist/resource/index.d.ts.map +1 -0
  77. package/dist/resource/index.js +160 -0
  78. package/dist/resource/index.js.map +1 -0
  79. package/dist/resource/inference.d.ts +310 -0
  80. package/dist/resource/inference.d.ts.map +1 -0
  81. package/dist/resource/inference.js +17 -0
  82. package/dist/resource/inference.js.map +1 -0
  83. package/dist/resource/validator.d.ts +158 -0
  84. package/dist/resource/validator.d.ts.map +1 -0
  85. package/dist/resource/validator.js +1031 -0
  86. package/dist/resource/validator.js.map +1 -0
  87. package/dist/string/assembler.d.ts +69 -0
  88. package/dist/string/assembler.d.ts.map +1 -0
  89. package/dist/string/assembler.js +143 -0
  90. package/dist/string/assembler.js.map +1 -0
  91. package/dist/string/index.d.ts +431 -0
  92. package/dist/string/index.d.ts.map +1 -0
  93. package/dist/string/index.js +528 -0
  94. package/dist/string/index.js.map +1 -0
  95. package/dist/string/validator.d.ts +30 -0
  96. package/dist/string/validator.d.ts.map +1 -0
  97. package/dist/string/validator.js +69 -0
  98. package/dist/string/validator.js.map +1 -0
  99. package/dist/union/accessors.d.ts +137 -0
  100. package/dist/union/accessors.d.ts.map +1 -0
  101. package/dist/union/accessors.js +253 -0
  102. package/dist/union/accessors.js.map +1 -0
  103. package/dist/union/assembler.d.ts +56 -0
  104. package/dist/union/assembler.d.ts.map +1 -0
  105. package/dist/union/assembler.js +140 -0
  106. package/dist/union/assembler.js.map +1 -0
  107. package/dist/union/index.d.ts +172 -0
  108. package/dist/union/index.d.ts.map +1 -0
  109. package/dist/union/index.js +45 -0
  110. package/dist/union/index.js.map +1 -0
  111. package/dist/union/inference.d.ts +30 -0
  112. package/dist/union/inference.d.ts.map +1 -0
  113. package/dist/union/inference.js +17 -0
  114. package/dist/union/inference.js.map +1 -0
  115. package/dist/union/validator.d.ts +94 -0
  116. package/dist/union/validator.d.ts.map +1 -0
  117. package/dist/union/validator.js +171 -0
  118. package/dist/union/validator.js.map +1 -0
  119. package/dist/value/accessors.d.ts +151 -0
  120. package/dist/value/accessors.d.ts.map +1 -0
  121. package/dist/value/accessors.js +468 -0
  122. package/dist/value/accessors.js.map +1 -0
  123. package/dist/value/assembler.d.ts +129 -0
  124. package/dist/value/assembler.d.ts.map +1 -0
  125. package/dist/value/assembler.js +248 -0
  126. package/dist/value/assembler.js.map +1 -0
  127. package/dist/value/index.d.ts +309 -0
  128. package/dist/value/index.d.ts.map +1 -0
  129. package/dist/value/index.js +26 -0
  130. package/dist/value/index.js.map +1 -0
  131. package/dist/value/inference.d.ts +292 -0
  132. package/dist/value/inference.d.ts.map +1 -0
  133. package/dist/value/inference.js +17 -0
  134. package/dist/value/inference.js.map +1 -0
  135. package/dist/value/validator.d.ts +76 -0
  136. package/dist/value/validator.d.ts.map +1 -0
  137. package/dist/value/validator.js +111 -0
  138. package/dist/value/validator.js.map +1 -0
  139. package/package.json +95 -4
@@ -0,0 +1,86 @@
1
+ import type { Legal } from "../value/inference.js";
2
+ /**
3
+ * Describes a truth value.
4
+ *
5
+ * Admits the [JSON booleans](https://datatracker.ietf.org/doc/html/rfc8259#section-3) a resource may carry, closed to
6
+ * a single one where the shape enumerates it and typed as an
7
+ * [XSD 1.0](https://www.w3.org/TR/xmlschema-2/#built-in-datatypes) boolean, so that a validated value carries the
8
+ * datatype the shape states rather than the one JSON leaves unsaid.
9
+ *
10
+ * **Inheritance**
11
+ *
12
+ * Where a {@link resource!ResourceShape} extends the shapes it lists as `parents`, boolean-valued members are merged
13
+ * according to the following rules. The *child* is the extending shape; the *parent* is the inherited one.
14
+ *
15
+ * | Field | Override Rule |
16
+ * | ------ | ----------------------------------------------------------------------------------- |
17
+ * | `kind` | Cannot be overridden |
18
+ * | `in` | Must be strictly equal when both defined; the single defined value carries through |
19
+ *
20
+ * A child restating the value its parent admits narrows nothing and is accepted all the same; a child admitting the
21
+ * other value would leave the member admitting nothing and is rejected.
22
+ *
23
+ * @typeParam V The values the shape admits, narrowed to the enumerated one where it states an
24
+ * {@link BooleanConstraints.in | enumeration} and both truth values otherwise
25
+ *
26
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#boolean XSD 1.0 Part 2: Datatypes § 3.2.2 boolean}
27
+ */
28
+ export type BooleanShape<V extends boolean = boolean> = BooleanConstraints<V> & {
29
+ /**
30
+ * Discriminator identifying this as a boolean shape.
31
+ *
32
+ * **Inheritance** — cannot be overridden.
33
+ */
34
+ readonly kind: "boolean";
35
+ };
36
+ /**
37
+ * Constraints accepted by the {@link boolean} shape factory.
38
+ *
39
+ * @typeParam V The value the enumeration admits
40
+ */
41
+ export type BooleanConstraints<V extends boolean = boolean> = {
42
+ /**
43
+ * Allowed value (closed enumeration).
44
+ *
45
+ * When specified, values must be equal to it. The domain holds two values, so the constraint states the single
46
+ * admitted one rather than a list, which would either readmit the whole domain or close it to nothing; the
47
+ * {@link boolean} factory takes it as a bare value too. Closing the domain also narrows the value the shape
48
+ * describes to the stated one, wherever it is stated precisely enough to be told apart; a value only known to be a
49
+ * boolean leaves the shape admitting both.
50
+ *
51
+ * **Inheritance** — must be strictly equal when both parent and child define it; otherwise the single defined value
52
+ * carries through. A mismatch is reported as an error.
53
+ *
54
+ * @defaultValue `undefined` (both truth values admitted)
55
+ *
56
+ * @see {@link https://www.w3.org/TR/shacl/#InConstraintComponent SHACL § 4.8.3 sh:in}
57
+ */
58
+ readonly in?: V;
59
+ };
60
+ /**
61
+ * Creates a boolean shape.
62
+ *
63
+ * Admits `true` and `false` and nothing else, closed to the single enumerated value where the constraints state one;
64
+ * the domain is closed by the kind alone, so the constraints cannot be contradictory.
65
+ *
66
+ * @typeParam C The stated constraints
67
+ *
68
+ * @param constraints Optional shape {@link BooleanConstraints constraints}
69
+ *
70
+ * @returns An immutable shape admitting truth values, narrowed to the value the constraints enumerate
71
+ */
72
+ export declare function boolean<const C extends BooleanConstraints = {}>(constraints?: C): BooleanShape<Legal<C, boolean>>;
73
+ /**
74
+ * Creates a boolean shape admitting a single value.
75
+ *
76
+ * Reads a bare truth value as the enumeration closing the domain to it, so that a tag telling the alternatives of a
77
+ * union apart is stated as `boolean(true)` rather than as `boolean({ in: true })`.
78
+ *
79
+ * @typeParam V The value the shape admits
80
+ *
81
+ * @param value The single admitted truth value
82
+ *
83
+ * @returns An immutable shape admitting `value` alone
84
+ */
85
+ export declare function boolean<const V extends boolean>(value: V): BooleanShape<V>;
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/boolean/index.ts"],"names":[],"mappings":"AA6FA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAInD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG;IAE/E;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAExB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI;IAE7D;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CAEhB,CAAA;AAKD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,kBAAkB,GAAG,EAAE,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AAEnH;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,99 @@
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
+ * Boolean shape types and operations.
18
+ *
19
+ * Defines the shape describing the truth values a resource may carry and provides the {@link boolean} factory stating
20
+ * it, mapping the [JSON boolean](https://datatracker.ietf.org/doc/html/rfc8259#section-3) type to the
21
+ * [XSD 1.0](https://www.w3.org/TR/xmlschema-2/#built-in-datatypes) boolean datatype. The kind closes the domain to two
22
+ * values; an enumeration closes it further to one, so that a member may stand as the tag telling the alternatives of a
23
+ * union apart.
24
+ *
25
+ * | XSD Datatype ¹ | Factory | Description | Range |
26
+ * | -------------- | --------------- | ------------------- | ------------- |
27
+ * | [boolean][] | {@link boolean} | binary-valued logic | {true, false} |
28
+ *
29
+ * [boolean]: https://www.w3.org/TR/xmlschema-2/#boolean
30
+ *
31
+ * ¹ XSD 1.0 datatypes are referenced by [RDF 1.1](https://www.w3.org/TR/rdf11-concepts/) and
32
+ * [JSON-LD 1.1](https://www.w3.org/TR/json-ld11/) as normative
33
+ *
34
+ * **Compatibility**
35
+ *
36
+ * | JSON | XSD | JavaScript |
37
+ * | --------------- | ------------------------------ | --------------- |
38
+ * | `true`, `false` | {true, false, 1, 0} ¹ | `true`, `false` |
39
+ *
40
+ * ¹ Canonical form: `true`, `false`
41
+ *
42
+ * **Defining boolean shapes**
43
+ *
44
+ * ```typescript
45
+ * import { boolean } from '@grafctory/blue/boolean';
46
+ *
47
+ * const flag = boolean(); // either truth value
48
+ * const settled = boolean({ in: true }); // the single admitted value
49
+ * const paid = boolean(true); // the same, stated as a bare value
50
+ * ```
51
+ *
52
+ * > [!NOTE]
53
+ * > An enumeration also narrows the value the shape describes: `settled` admits `true`, not both truth values. The
54
+ * > domain holds two values, so the constraint states the single admitted one: a list would degenerate, admitting
55
+ * > either the whole domain or nothing at all.
56
+ *
57
+ * **Using in resource shapes**
58
+ *
59
+ * ```typescript
60
+ * import { optional, required, resource } from '@grafctory/blue/resource';
61
+ * import { boolean } from '@grafctory/blue/boolean';
62
+ *
63
+ * const Product = resource({
64
+ * available: required(boolean()),
65
+ * featured: optional(boolean())
66
+ * });
67
+ * ```
68
+ *
69
+ * **Tagging the alternatives of a union**
70
+ *
71
+ * ```typescript
72
+ * import { boolean } from '@grafctory/blue/boolean';
73
+ * import { date } from '@grafctory/blue/string';
74
+ * import { required, resource } from '@grafctory/blue/resource';
75
+ * import { union } from '@grafctory/blue/union';
76
+ *
77
+ * const Payment = union(
78
+ * resource({ settled: required(boolean(false)), due: required(date()) }),
79
+ * resource({ settled: required(boolean(true)), paid: required(date()) })
80
+ * );
81
+ * ```
82
+ *
83
+ * A stored value states one truth value, singling out the alternative it belongs to, and the type of the value the
84
+ * union describes is narrowed by the tag exactly as the shape is.
85
+ *
86
+ * @module
87
+ *
88
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc8259#section-3 RFC 8259 § 3 Values}
89
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#boolean XSD 1.0 Part 2: Datatypes § 3.2.2 boolean}
90
+ */
91
+ import { isBoolean } from "@grafctory/core";
92
+ import { assemble } from "./assembler.js";
93
+ /**
94
+ * Creates a boolean shape.
95
+ */
96
+ export function boolean(constraints) {
97
+ return assemble(isBoolean(constraints) ? { in: constraints } : { ...constraints });
98
+ }
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/boolean/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAkG1C;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,WAA0C;IAEjE,OAAO,QAAQ,CAAU,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;AAE7F,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Boolean value validation.
3
+ *
4
+ * Holds a value to what a boolean 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 { BooleanShape } from "./index.js";
13
+ /**
14
+ * Validates values against a boolean shape.
15
+ *
16
+ * Reports each value that is not a boolean as a `{type}` violation and each boolean the enumeration leaves out under
17
+ * its own facet, keying every element violation by its index, so that a caller may tell which value failed and why.
18
+ *
19
+ * @param values The values to validate
20
+ * @param shape The shape the values are matched against
21
+ * @param opts Validation options
22
+ * @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. `"model"` admits
23
+ * the atomic placeholder
24
+ *
25
+ * @returns A trace of the violations found, or `undefined` where every value matches `shape`
26
+ */
27
+ export declare const validateBoolean: (values: readonly unknown[], shape: BooleanShape, opts?: {
28
+ scope?: Scope;
29
+ }) => Optional<Trace>;
30
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/boolean/validator.ts"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AAEH,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAe,KAAK,KAAK,EAAwB,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,KAAK,KAAK,EAAU,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,EAAE,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE;IAEtF,KAAK,CAAC,EAAE,KAAK,CAAA;CAEb,KAAK,QAAQ,CAAC,KAAK,CAAwB,CAAC"}
@@ -0,0 +1,68 @@
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
+ * Boolean value validation.
18
+ *
19
+ * Holds a value to what a boolean 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 { isBoolean } from "@grafctory/core";
25
+ import { isAtomic } from "@grafctory/qest/model";
26
+ import { array, pass, type } from "@grafctory/core/trace";
27
+ import { scoped } from "../value/validator.js";
28
+ /**
29
+ * Validates values against a boolean shape.
30
+ *
31
+ * Reports each value that is not a boolean as a `{type}` violation and each boolean the enumeration leaves out under
32
+ * its own facet, keying every element violation by its index, so that a caller may tell which value failed and why.
33
+ *
34
+ * @param values The values to validate
35
+ * @param shape The shape the values are matched against
36
+ * @param opts Validation options
37
+ * @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. `"model"` admits
38
+ * the atomic placeholder
39
+ *
40
+ * @returns A trace of the violations found, or `undefined` where every value matches `shape`
41
+ */
42
+ export const validateBoolean = scoped(state, model);
43
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44
+ /**
45
+ * Every constraint: a legal element of the shape's domain.
46
+ */
47
+ function state({ in: allowed }) {
48
+ return array(type(isBoolean, domain(allowed)));
49
+ }
50
+ /**
51
+ * The form alone: a retrieval placeholder asks for the value as it stands and carries none of its own.
52
+ */
53
+ function model({}) {
54
+ return array(type(isAtomic));
55
+ }
56
+ /**
57
+ * Matches a boolean against the value a shape enumerates, admitting both truth values where it enumerates none.
58
+ */
59
+ function domain(allowed) {
60
+ if (allowed === undefined) {
61
+ return pass;
62
+ }
63
+ else {
64
+ const outside = [`{domain} expected value in [${allowed}]`];
65
+ return value => value === allowed ? undefined : outside;
66
+ }
67
+ }
68
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/boolean/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAc,IAAI,EAAkB,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAc,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,eAAe,GAIJ,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAG7C,wHAAwH;AAExH;;GAEG;AACH,SAAS,KAAK,CAAC,EAEd,EAAE,EAAE,OAAO,EAEG;IAEd,OAAO,KAAK,CACX,IAAI,CAAC,SAAS,EACb,MAAM,CAAC,OAAO,CAAC,CACf,CACD,CAAC;AAEH,CAAC;AAED;;GAEG;AACH,SAAS,KAAK,CAAC,EAAgB;IAE9B,OAAO,KAAK,CACX,IAAI,CAAC,QAAQ,CAAC,CACd,CAAC;AAEH,CAAC;AAED;;GAEG;AACH,SAAS,MAAM,CAAC,OAA0B;IAEzC,IAAK,OAAO,KAAK,SAAS,EAAG,CAAC;QAE7B,OAAO,IAAI,CAAC;IAEb,CAAC;SAAM,CAAC;QAEP,MAAM,OAAO,GAAG,CAAC,+BAA+B,OAAO,GAAG,CAAC,CAAC;QAE5D,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IAEzD,CAAC;AAEF,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Dictionary shape assembly.
3
+ *
4
+ * Builds the shape the factory states into the form its consumers read, and combines it with the one it overrides: a
5
+ * shape admitting no value at all is rejected as it is built rather than when a value is first matched against it, and
6
+ * an extension is held to the shape it refines before either is committed to.
7
+ *
8
+ * @module
9
+ */
10
+ import { type Optional } from "@grafctory/core";
11
+ import { type Trace } from "@grafctory/core/trace";
12
+ import { type DictionaryConstraints, type DictionaryShape } from "./index.js";
13
+ /**
14
+ * Assembles a dictionary shape.
15
+ *
16
+ * Backs the factory the {@link dictionary!} module exposes: contradictory constraints are rejected as the shape is
17
+ * built, so that a shape that exists admits at least one value.
18
+ *
19
+ * @typeParam U The per-tag arity the shape states, as stated by the signature of the calling factory
20
+ *
21
+ * @param constraints The stated shape {@link DictionaryConstraints constraints}
22
+ *
23
+ * @returns An immutable shape admitting the language maps the constraints bound
24
+ *
25
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
26
+ */
27
+ export declare function assemble<U extends undefined | boolean>(constraints: DictionaryConstraints): DictionaryShape & {
28
+ readonly uniqueLang: U;
29
+ };
30
+ /**
31
+ * Checks a set of localised constraints for internal consistency.
32
+ *
33
+ * Reports the contradictions that would leave a shape admitting no value at all, so that a shape is rejected as it is
34
+ * built rather than when a value is first matched against it.
35
+ *
36
+ * @param constraints The constraints to check
37
+ *
38
+ * @returns A trace of the inconsistencies found, or `undefined` where the constraints admit at least one value
39
+ */
40
+ export declare function checkDictionary(constraints: DictionaryConstraints): Optional<Trace>;
41
+ /**
42
+ * Reports whether a dictionary shape narrows an inherited one.
43
+ *
44
+ * Tests the override relation without building the merged shape, so that an incompatible extension is told apart from
45
+ * a legitimate refinement before either is committed to: a shape narrows the inherited one where it leaves neither
46
+ * length bound wider, adds no language range the inherited shape omits, keeps its per-tag arity, and yields a
47
+ * consistent set of merged constraints.
48
+ *
49
+ * @param target The overriding shape
50
+ * @param source The inherited shape
51
+ *
52
+ * @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
53
+ */
54
+ export declare function narrowsDictionary(target: DictionaryShape, source: DictionaryShape): Optional<Trace>;
55
+ /**
56
+ * Merges a dictionary shape with an inherited one.
57
+ *
58
+ * Yields the single shape an extending member is validated against, combining the inherited constraints with the
59
+ * overriding ones: length bounds accumulate, the accepted language ranges intersect, and `uniqueLang` carries through
60
+ * from whichever shape states it.
61
+ *
62
+ * @param target The overriding shape
63
+ * @param source The inherited shape
64
+ *
65
+ * @returns An immutable shape admitting the language maps both `target` and `source` admit
66
+ *
67
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
68
+ */
69
+ export declare function mergeDictionary(target: DictionaryShape, source: DictionaryShape): DictionaryShape;
70
+ //# sourceMappingURL=assembler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assembler.d.ts","sourceRoot":"","sources":["../../src/dictionary/assembler.ts"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAG9E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,GAAG,OAAO,EAAE,WAAW,EAAE,qBAAqB,GAAG,eAAe,GAAG;IAC9G,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;CACtB,CAcA;AAKD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,qBAAqB,GAAG,QAAQ,CAAC,KAAK,CAAC,CAUnF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,CAInG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAcjG"}
@@ -0,0 +1,154 @@
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 { immutable } from "@grafctory/core/values";
17
+ import { all, test } from "@grafctory/core/trace";
18
+ import { reject } from "../value/assembler.js";
19
+ /**
20
+ * Assembles a dictionary shape.
21
+ *
22
+ * Backs the factory the {@link dictionary!} module exposes: contradictory constraints are rejected as the shape is
23
+ * built, so that a shape that exists admits at least one value.
24
+ *
25
+ * @typeParam U The per-tag arity the shape states, as stated by the signature of the calling factory
26
+ *
27
+ * @param constraints The stated shape {@link DictionaryConstraints constraints}
28
+ *
29
+ * @returns An immutable shape admitting the language maps the constraints bound
30
+ *
31
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
32
+ */
33
+ export function assemble(constraints) {
34
+ const shape = immutable({
35
+ kind: "dictionary",
36
+ ...constraints
37
+ }); // ;(cast) the factory signature fixes the stated arity
38
+ reject("inconsistent dictionary shape constraints", checkDictionary(shape));
39
+ return shape;
40
+ }
41
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42
+ /**
43
+ * Checks a set of localised constraints for internal consistency.
44
+ *
45
+ * Reports the contradictions that would leave a shape admitting no value at all, so that a shape is rejected as it is
46
+ * built rather than when a value is first matched against it.
47
+ *
48
+ * @param constraints The constraints to check
49
+ *
50
+ * @returns A trace of the inconsistencies found, or `undefined` where the constraints admit at least one value
51
+ */
52
+ export function checkDictionary(constraints) {
53
+ return test(({ minLength, maxLength }) => {
54
+ return minLength === undefined || maxLength === undefined || minLength <= maxLength || [
55
+ `{minLength/maxLength} inconsistent bounds <${minLength}> > <${maxLength}>`
56
+ ];
57
+ })(constraints);
58
+ }
59
+ /**
60
+ * Reports whether a dictionary shape narrows an inherited one.
61
+ *
62
+ * Tests the override relation without building the merged shape, so that an incompatible extension is told apart from
63
+ * a legitimate refinement before either is committed to: a shape narrows the inherited one where it leaves neither
64
+ * length bound wider, adds no language range the inherited shape omits, keeps its per-tag arity, and yields a
65
+ * consistent set of merged constraints.
66
+ *
67
+ * @param target The overriding shape
68
+ * @param source The inherited shape
69
+ *
70
+ * @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
71
+ */
72
+ export function narrowsDictionary(target, source) {
73
+ return narrows(target, source, merge(target, source));
74
+ }
75
+ /**
76
+ * Merges a dictionary shape with an inherited one.
77
+ *
78
+ * Yields the single shape an extending member is validated against, combining the inherited constraints with the
79
+ * overriding ones: length bounds accumulate, the accepted language ranges intersect, and `uniqueLang` carries through
80
+ * from whichever shape states it.
81
+ *
82
+ * @param target The overriding shape
83
+ * @param source The inherited shape
84
+ *
85
+ * @returns An immutable shape admitting the language maps both `target` and `source` admit
86
+ *
87
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where `target` doesn't narrow `source`
88
+ */
89
+ export function mergeDictionary(target, source) {
90
+ const merged = merge(target, source);
91
+ reject("incompatible dictionary shape override", narrows(target, source, merged));
92
+ return immutable({
93
+ kind: "dictionary",
94
+ ...merged
95
+ });
96
+ }
97
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98
+ /**
99
+ * Reports the obstacles standing against a dictionary shape override.
100
+ *
101
+ * @param target The overriding shape
102
+ * @param source The inherited shape
103
+ * @param merged The constraints the two shapes combine into
104
+ *
105
+ * @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
106
+ */
107
+ function narrows(target, source, merged) {
108
+ const { languageIn: accepted } = source;
109
+ return all(test(({ uniqueLang }) => {
110
+ return uniqueLang !== false || source.uniqueLang !== true || [
111
+ `{uniqueLang} dropped unique language constraint`
112
+ ];
113
+ }), test(({ minLength }) => {
114
+ return minLength === undefined || source.minLength === undefined || minLength >= source.minLength || [
115
+ `{minLength} widened limit <${minLength}> beyond <${source.minLength}>`
116
+ ];
117
+ }), test(({ maxLength }) => {
118
+ return maxLength === undefined || source.maxLength === undefined || maxLength <= source.maxLength || [
119
+ `{maxLength} widened limit <${maxLength}> beyond <${source.maxLength}>`
120
+ ];
121
+ }), test(({ languageIn }) => {
122
+ // a range the parent omits would be intersected away, leaving the state wider than the shape admits,
123
+ // so a widened set is rejected outright as with the bounds
124
+ return languageIn === undefined || accepted === undefined
125
+ || languageIn.every(v => accepted.includes(v))
126
+ || [
127
+ `{languageIn} unexpected ranges [${languageIn.filter(v => !accepted.includes(v))}]`
128
+ ];
129
+ }), () => checkDictionary(merged) // post-merge constraint consistency
130
+ )(target);
131
+ }
132
+ /**
133
+ * Combines the constraints of an overriding shape with the inherited ones.
134
+ *
135
+ * @param target The overriding shape
136
+ * @param source The inherited shape
137
+ *
138
+ * @returns The merged constraints, as they stand before they are checked for consistency
139
+ */
140
+ function merge(target, source) {
141
+ const { languageIn: accepted } = source;
142
+ return {
143
+ // conjunctive: uniqueLang — added but never dropped
144
+ uniqueLang: target.uniqueLang ?? source.uniqueLang,
145
+ // conjunctive: lengths — the tighter bound
146
+ minLength: target.minLength ?? source.minLength,
147
+ maxLength: target.maxLength ?? source.maxLength,
148
+ // conjunctive: languageIn — intersection
149
+ languageIn: target.languageIn !== undefined && accepted !== undefined
150
+ ? target.languageIn.filter(v => accepted.includes(v))
151
+ : target.languageIn ?? accepted
152
+ };
153
+ }
154
+ //# sourceMappingURL=assembler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/dictionary/assembler.ts"],"names":[],"mappings":"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"}