@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 @@
1
+ {"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/number/assembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAcH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAc,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAa9G;;GAEG;AACH,MAAM,MAAM,GAAqB;IAChC,cAAc;IACd,cAAc;IACd,cAAc;IACd,cAAc;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,GAAkD;IAC7D,CAAC,cAAc,EAAE,cAAc,EAAE,IAAI,CAAC;IACtC,CAAC,cAAc,EAAE,cAAc,EAAE,KAAK,CAAC;IACvC,CAAC,cAAc,EAAE,cAAc,EAAE,IAAI,CAAC;IACtC,CAAC,cAAc,EAAE,cAAc,EAAE,IAAI,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,GAAiF;IAC5F,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,KAAK,IAAI,SAAS,CAAC;IAC1D,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,KAAK,IAAI,SAAS,CAAC;IAC1D,CAAC,cAAc,EAAE,CAAC,KAAK,EA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I,MAAM,CAAC,YAAY;QACxD,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY;QACxD,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY;QACxD,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY;QAExD,mDAAmD;QAEnD,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;QACnC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;KAEjD,CAAC;AAEH,CAAC"}
@@ -0,0 +1,329 @@
1
+ import type { Reference } from "@grafctory/qest/state";
2
+ import type { Legal } from "../value/inference.js";
3
+ /**
4
+ * Describes a numeric value.
5
+ *
6
+ * Admits the [JSON numbers](https://datatracker.ietf.org/doc/html/rfc8259#section-6) a resource may carry, bounded by
7
+ * range and enumeration constraints and typed as an [XSD 1.0](https://www.w3.org/TR/xmlschema-2/#built-in-datatypes)
8
+ * numeric datatype, so that a validated value carries the datatype the shape states rather than the one JSON leaves
9
+ * unsaid.
10
+ *
11
+ * **Inheritance**
12
+ *
13
+ * Where a {@link resource!ResourceShape} extends the shapes it lists as `parents`, numeric-valued members are merged
14
+ * according to the following rules. The *child* is the extending shape; the *parent* is the inherited one.
15
+ *
16
+ * | Field | Override Rule |
17
+ * | -------------- | ---------------------------------------------------------------------------------- |
18
+ * | `kind` | Cannot be overridden |
19
+ * | `datatype` | Must be strictly equal when both defined; the single defined value carries through |
20
+ * | `integral` | Child may add but not drop; an inherited constraint always carries through |
21
+ * | `minExclusive` | Child may only raise the exclusive lower bound |
22
+ * | `maxExclusive` | Child may only lower the exclusive upper bound |
23
+ * | `minInclusive` | Child may only raise the inclusive lower bound |
24
+ * | `maxInclusive` | Child may only lower the inclusive upper bound |
25
+ * | `in` | Child may only drop allowed values |
26
+ * | `hasValue` | Child may only add required values |
27
+ *
28
+ * Inclusive/exclusive pairs are independently merged: a child may define an exclusive bound alongside a parent's
29
+ * inclusive bound (or vice versa), narrowing the range without removing the original constraint.
30
+ *
31
+ * **Cross-field validation**
32
+ *
33
+ * - merged `minExclusive` must be < merged `maxExclusive`
34
+ * - merged `minInclusive` must be ≤ merged `maxInclusive`
35
+ * - exclusive and inclusive bounds must not contradict
36
+ * - all merged `hasValue` entries must be members of the merged `in` set (if defined)
37
+ *
38
+ * @typeParam V The values the shape admits, narrowed to the enumerated ones where it states an
39
+ * {@link NumberRangeConstraints.in | enumeration} and the whole numeric domain otherwise
40
+ *
41
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#built-in-datatypes XSD 1.0 Part 2: Datatypes § 3 Built-in Datatypes}
42
+ */
43
+ export type NumberShape<V extends number = number> = NumberConstraints<V> & {
44
+ /**
45
+ * Discriminator identifying this as a number shape.
46
+ *
47
+ * **Inheritance** — cannot be overridden.
48
+ */
49
+ readonly kind: "number";
50
+ };
51
+ /**
52
+ * Constraints accepted by the {@link number} shape factory.
53
+ *
54
+ * Adds the RDF datatype and the integrality flag, which only the general-purpose factory accepts, to the
55
+ * {@link NumberRangeConstraints range} constraints shared with the specialised factories.
56
+ *
57
+ * @typeParam V The values the enumeration admits
58
+ */
59
+ export type NumberConstraints<V extends number = number> = NumberRangeConstraints<V> & {
60
+ /**
61
+ * RDF datatype IRI for the numeric literal.
62
+ *
63
+ * States the RDF datatype of validated JSON values, which carry none of their own.
64
+ *
65
+ * **Inheritance** — must be strictly equal when both parent and child define it; otherwise the single defined value
66
+ * carries through. A mismatch is reported as an error.
67
+ *
68
+ * @defaultValue `undefined` (falls back to `xsd:double`)
69
+ *
70
+ * @see {@link https://www.w3.org/TR/shacl/#DatatypeConstraintComponent SHACL § 4.1.2 sh:datatype}
71
+ */
72
+ readonly datatype?: Reference;
73
+ /**
74
+ * Restricts values to integers.
75
+ *
76
+ * When `true`, validated values must be integers (no fractional part); fractional values are rejected. Decouples
77
+ * integrality from `datatype`, so custom or non-XSD integral types are declarable without relying on a recognised
78
+ * datatype IRI. The integer-family factories ({@link byte}, {@link short}, {@link int}, {@link long},
79
+ * {@link integer}) set it; {@link float}, {@link double}, and {@link decimal} leave it unset.
80
+ *
81
+ * **Inheritance** — a child may add the constraint but not drop it: overriding an integral parent with a
82
+ * non-integral child is rejected.
83
+ *
84
+ * @defaultValue `undefined` (fractional values allowed)
85
+ */
86
+ readonly integral?: boolean;
87
+ };
88
+ /**
89
+ * Value range bounds accepted by the number shape factories.
90
+ *
91
+ * Bounds the magnitudes admitted by a shape, independently of its datatype. Accepted on its own by the specialised
92
+ * factories, whose datatype and integrality are already fixed, and included in the full {@link NumberConstraints} set.
93
+ *
94
+ * @typeParam V The values the enumeration admits
95
+ *
96
+ * @see {@link https://www.w3.org/TR/shacl/#core-components-range SHACL § 4.3 Value Range Constraint Components}
97
+ */
98
+ export type NumberRangeConstraints<V extends number = number> = {
99
+ /**
100
+ * Exclusive minimum value (value must be strictly greater).
101
+ *
102
+ * **Inheritance** — child may only raise the exclusive lower bound.
103
+ *
104
+ * @defaultValue `undefined` (no minimum constraint)
105
+ *
106
+ * @see {@link https://www.w3.org/TR/shacl/#MinExclusiveConstraintComponent SHACL § 4.3.1 sh:minExclusive}
107
+ */
108
+ readonly minExclusive?: number;
109
+ /**
110
+ * Exclusive maximum value (value must be strictly less).
111
+ *
112
+ * **Inheritance** — child may only lower the exclusive upper bound.
113
+ *
114
+ * @defaultValue `undefined` (no maximum constraint)
115
+ *
116
+ * @see {@link https://www.w3.org/TR/shacl/#MaxExclusiveConstraintComponent SHACL § 4.3.3 sh:maxExclusive}
117
+ */
118
+ readonly maxExclusive?: number;
119
+ /**
120
+ * Inclusive minimum value (value must be greater than or equal).
121
+ *
122
+ * **Inheritance** — child may only raise the inclusive lower bound.
123
+ *
124
+ * @defaultValue `undefined` (no minimum constraint)
125
+ *
126
+ * @see {@link https://www.w3.org/TR/shacl/#MinInclusiveConstraintComponent SHACL § 4.3.2 sh:minInclusive}
127
+ */
128
+ readonly minInclusive?: number;
129
+ /**
130
+ * Inclusive maximum value (value must be less than or equal).
131
+ *
132
+ * **Inheritance** — child may only lower the inclusive upper bound.
133
+ *
134
+ * @defaultValue `undefined` (no maximum constraint)
135
+ *
136
+ * @see {@link https://www.w3.org/TR/shacl/#MaxInclusiveConstraintComponent SHACL § 4.3.4 sh:maxInclusive}
137
+ */
138
+ readonly maxInclusive?: number;
139
+ /**
140
+ * Allowed values (closed enumeration).
141
+ *
142
+ * When specified, values must be members of this list. Empty arrays are ignored; the {@link number} factory takes
143
+ * the list as bare arguments too. Closing the domain also narrows the value the shape describes to the listed
144
+ * values, wherever they are stated precisely enough to be told apart; a list whose values are only known to be
145
+ * numbers leaves it as the whole numeric domain.
146
+ *
147
+ * **Inheritance** — child may only drop allowed values.
148
+ *
149
+ * @defaultValue `undefined` (no enumeration constraint)
150
+ *
151
+ * @see {@link https://www.w3.org/TR/shacl/#InConstraintComponent SHACL § 4.8.3 sh:in}
152
+ */
153
+ readonly in?: readonly V[];
154
+ /**
155
+ * Values a member must carry.
156
+ *
157
+ * When specified, all listed values must appear among the ones the member carries. Empty arrays are ignored.
158
+ *
159
+ * **Inheritance** — child may only add required values.
160
+ *
161
+ * @defaultValue `undefined` (no required values)
162
+ *
163
+ * @see {@link https://www.w3.org/TR/shacl/#HasValueConstraintComponent SHACL § 4.8.2 sh:hasValue}
164
+ */
165
+ readonly hasValue?: readonly V[];
166
+ };
167
+ /**
168
+ * Creates a number shape.
169
+ *
170
+ * Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value.
171
+ *
172
+ * @typeParam C The stated constraints
173
+ *
174
+ * @param constraints Optional shape {@link NumberConstraints constraints}
175
+ *
176
+ * @returns An immutable shape admitting the numbers the constraints bound, narrowed to the values they enumerate
177
+ *
178
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
179
+ */
180
+ export declare function number<const C extends NumberConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
181
+ /**
182
+ * Creates a number shape admitting an enumerated set of values.
183
+ *
184
+ * Reads bare numbers as the enumeration closing the domain to them, so that a set of admitted values is stated as
185
+ * `number(1, 2, 3)` rather than as `number({ in: [1, 2, 3] })`.
186
+ *
187
+ * @typeParam V The values the shape admits
188
+ *
189
+ * @param values The admitted values
190
+ *
191
+ * @returns An immutable shape admitting `values` alone
192
+ */
193
+ export declare function number<const V extends readonly number[]>(...values: V): NumberShape<V[number]>;
194
+ /**
195
+ * Creates a shape for 8-bit signed integer values.
196
+ *
197
+ * Fixes the datatype to `xsd:byte`, marks the shape `integral` and defaults the range to `[-128, 127]`; supplied
198
+ * bounds override the defaults.
199
+ *
200
+ * @typeParam C The stated constraints
201
+ *
202
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
203
+ *
204
+ * @returns An immutable shape admitting 8-bit signed integers, narrowed to the values the constraints enumerate
205
+ *
206
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
207
+ *
208
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#byte XSD 1.0 Part 2: Datatypes § 3.3.19 byte}
209
+ */
210
+ export declare function byte<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
211
+ /**
212
+ * Creates a shape for 16-bit signed integer values.
213
+ *
214
+ * Fixes the datatype to `xsd:short`, marks the shape `integral` and defaults the range to `[-32768, 32767]`; supplied
215
+ * bounds override the defaults.
216
+ *
217
+ * @typeParam C The stated constraints
218
+ *
219
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
220
+ *
221
+ * @returns An immutable shape admitting 16-bit signed integers, narrowed to the values the constraints enumerate
222
+ *
223
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
224
+ *
225
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#short XSD 1.0 Part 2: Datatypes § 3.3.18 short}
226
+ */
227
+ export declare function short<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
228
+ /**
229
+ * Creates a shape for 32-bit signed integer values.
230
+ *
231
+ * Fixes the datatype to `xsd:int`, marks the shape `integral` and defaults the range to
232
+ * `[-2147483648, 2147483647]`; supplied bounds override the defaults.
233
+ *
234
+ * @typeParam C The stated constraints
235
+ *
236
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
237
+ *
238
+ * @returns An immutable shape admitting 32-bit signed integers, narrowed to the values the constraints enumerate
239
+ *
240
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
241
+ *
242
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#int XSD 1.0 Part 2: Datatypes § 3.3.17 int}
243
+ */
244
+ export declare function int<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
245
+ /**
246
+ * Creates a shape for 64-bit signed integer values.
247
+ *
248
+ * Fixes the datatype to `xsd:long`, marks the shape `integral` and defaults the range to
249
+ * {@link Number.MIN_SAFE_INTEGER}…{@link Number.MAX_SAFE_INTEGER} (±2⁵³−1), narrower than the datatype's
250
+ * nominal ±2⁶³−1, since values beyond the safe-integer range cannot be represented faithfully as `number`; supplied
251
+ * bounds override the defaults.
252
+ *
253
+ * @typeParam C The stated constraints
254
+ *
255
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
256
+ *
257
+ * @returns An immutable shape admitting 64-bit signed integers, narrowed to the values the constraints enumerate
258
+ *
259
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
260
+ *
261
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#long XSD 1.0 Part 2: Datatypes § 3.3.16 long}
262
+ */
263
+ export declare function long<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
264
+ /**
265
+ * Creates a shape for IEEE 754 single-precision floating-point values.
266
+ *
267
+ * Fixes the datatype to `xsd:float` and defaults the range to the finite single-precision interval
268
+ * `±(2 − 2⁻²³) × 2¹²⁷`; supplied bounds override the defaults.
269
+ *
270
+ * @typeParam C The stated constraints
271
+ *
272
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
273
+ *
274
+ * @returns An immutable shape admitting single-precision floats, narrowed to the values the constraints enumerate
275
+ *
276
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
277
+ *
278
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#float XSD 1.0 Part 2: Datatypes § 3.2.4 float}
279
+ */
280
+ export declare function float<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
281
+ /**
282
+ * Creates a shape for IEEE 754 double-precision floating-point values.
283
+ *
284
+ * Fixes the datatype to `xsd:double`.
285
+ *
286
+ * @typeParam C The stated constraints
287
+ *
288
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
289
+ *
290
+ * @returns An immutable shape admitting double-precision floats, narrowed to the values the constraints enumerate
291
+ *
292
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
293
+ *
294
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#double XSD 1.0 Part 2: Datatypes § 3.2.5 double}
295
+ */
296
+ export declare function double<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
297
+ /**
298
+ * Creates a shape for arbitrary-precision integer values.
299
+ *
300
+ * Fixes the datatype to `xsd:integer` and marks the shape `integral`.
301
+ *
302
+ * @typeParam C The stated constraints
303
+ *
304
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
305
+ *
306
+ * @returns An immutable shape admitting arbitrary-precision integers, narrowed to the values the constraints enumerate
307
+ *
308
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
309
+ *
310
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#integer XSD 1.0 Part 2: Datatypes § 3.3.13 integer}
311
+ */
312
+ export declare function integer<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
313
+ /**
314
+ * Creates a shape for arbitrary-precision decimal values.
315
+ *
316
+ * Fixes the datatype to `xsd:decimal`.
317
+ *
318
+ * @typeParam C The stated constraints
319
+ *
320
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
321
+ *
322
+ * @returns An immutable shape admitting arbitrary-precision decimals, narrowed to the values the constraints enumerate
323
+ *
324
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
325
+ *
326
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#decimal XSD 1.0 Part 2: Datatypes § 3.2.3 decimal}
327
+ */
328
+ export declare function decimal<const C extends NumberRangeConstraints = {}>(constraints?: C): NumberShape<Legal<C, number>>;
329
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAuHA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAanD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG;IAE3E;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAEvB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,sBAAsB,CAAC,CAAC,CAAC,GAAG;IAEtF;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAE9B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAE5B,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAE/D;;;;;;;;OAQG;IACH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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 shape types and operations.
18
+ *
19
+ * Defines the shape describing the numeric values a resource may carry and its constraint types, and provides the
20
+ * factories stating them, mapping the [JSON number](https://datatracker.ietf.org/doc/html/rfc8259#section-6) type to
21
+ * [XSD 1.0](https://www.w3.org/TR/xmlschema-2/#built-in-datatypes) numeric datatypes. The {@link number} factory
22
+ * bounds a shape by range and enumeration constraints; the typed factories fix the datatype and precision of a
23
+ * particular XSD type.
24
+ *
25
+ * > [!IMPORTANT]
26
+ * > Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value:
27
+ * > stating `minInclusive` above `maxInclusive` throws a {@link @grafctory/core!TraceError | TraceError}.
28
+ *
29
+ * | XSD Datatype ¹ | Factory | Description | Range |
30
+ * | --------------- | ----------------- | ---------------------------- | -------------------------- |
31
+ * | [byte][] | {@link byte} | 8-bit signed integer | [‑2⁷, 2⁷‑1] |
32
+ * | [short][] | {@link short} | 16-bit signed integer | [‑2¹⁵, 2¹⁵‑1] |
33
+ * | [int][] | {@link int} | 32-bit signed integer | [‑2³¹, 2³¹‑1] |
34
+ * | [long][] | {@link long} ² | 64-bit signed integer | [‑2⁶³, 2⁶³‑1] |
35
+ * | [float][] | {@link float} | IEEE 754 32-bit float | m < 2²⁴, e ∈ [‑126, 127] |
36
+ * | [double][] | {@link double} | IEEE 754 64-bit float | m < 2⁵³, e ∈ [‑1022, 1023] |
37
+ * | [integer][] | {@link integer} ² | arbitrary-precision integer | ±# |
38
+ * | [decimal][] | {@link decimal} ² | arbitrary-precision decimal | ±#.# |
39
+ *
40
+ * [byte]: https://www.w3.org/TR/xmlschema-2/#byte
41
+ * [short]: https://www.w3.org/TR/xmlschema-2/#short
42
+ * [int]: https://www.w3.org/TR/xmlschema-2/#int
43
+ * [long]: https://www.w3.org/TR/xmlschema-2/#long
44
+ * [float]: https://www.w3.org/TR/xmlschema-2/#float
45
+ * [double]: https://www.w3.org/TR/xmlschema-2/#double
46
+ * [integer]: https://www.w3.org/TR/xmlschema-2/#integer
47
+ * [decimal]: https://www.w3.org/TR/xmlschema-2/#decimal
48
+ *
49
+ * ¹ XSD 1.0 datatypes are referenced by [RDF 1.1](https://www.w3.org/TR/rdf11-concepts/) and
50
+ * [JSON-LD 1.1](https://www.w3.org/TR/json-ld11/) as normative
51
+ *
52
+ * ² Numeric types with ranges exceeding JavaScript's safe integer range (±2⁵³-1) or requiring
53
+ * arbitrary precision cannot be fully represented in JSON/JavaScript
54
+ *
55
+ * **Compatibility**
56
+ *
57
+ * | XSD datatype | JSON | JavaScript |
58
+ * | ----------------- | --------------------------- | ----------------------------------------- |
59
+ * | byte, short, int | integer | represented exactly |
60
+ * | long | integer | exact only within ±2⁵³‑1 |
61
+ * | float, double | number; no NaN, no ±INF | IEEE 754, NaN and ±Infinity included |
62
+ * | integer | integer | needs BigInt beyond ±2⁵³‑1 |
63
+ * | decimal | number | no native arbitrary-precision decimal |
64
+ *
65
+ * **Defining number shapes**
66
+ *
67
+ * ```typescript
68
+ * import { decimal, integer, number } from '@grafctory/blue/number';
69
+ *
70
+ * const count = number(); // unconstrained number
71
+ * const score = number({ minInclusive: 0, maxInclusive: 100 }); // constrained range
72
+ * const age = integer({ minInclusive: 0 }); // arbitrary-precision integer
73
+ * const price = decimal({ minInclusive: 0 }); // arbitrary-precision decimal
74
+ * const die = number({ in: [1, 2, 3, 4, 5, 6] }); // enumeration-constrained
75
+ * const coin = number(0, 1); // the same, stated as bare values
76
+ * ```
77
+ *
78
+ * > [!NOTE]
79
+ * > An enumeration also narrows the value the shape describes: `die` admits `1 | 2 | 3 | 4 | 5 | 6`, not the whole
80
+ * > numeric domain.
81
+ *
82
+ * **Typed numeric factories**
83
+ *
84
+ * Specialised factories map to XSD numeric datatypes with predefined precision:
85
+ *
86
+ * ```typescript
87
+ * import { byte, double, float, int, long, short } from '@grafctory/blue/number';
88
+ *
89
+ * const priority = byte(); // 8-bit signed integer
90
+ * const port = short(); // 16-bit signed integer
91
+ * const quantity = int(); // 32-bit signed integer
92
+ * const offset = long(); // 64-bit signed integer
93
+ * const ratio = float(); // IEEE 754 single-precision
94
+ * const measurement = double(); // IEEE 754 double-precision
95
+ * ```
96
+ *
97
+ * **Using in resource shapes**
98
+ *
99
+ * ```typescript
100
+ * import { optional, required, resource } from '@grafctory/blue/resource';
101
+ * import { decimal, integer } from '@grafctory/blue/number';
102
+ *
103
+ * const Product = resource({
104
+ * price: required(decimal({ minInclusive: 0 })),
105
+ * quantity: optional(integer({ minInclusive: 0 })),
106
+ * rating: optional(decimal({ minInclusive: 0, maxInclusive: 5 }))
107
+ * });
108
+ * ```
109
+ *
110
+ * @module
111
+ *
112
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc8259#section-6 RFC 8259 § 6 Numbers}
113
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#built-in-datatypes XSD 1.0 Part 2: Datatypes § 3 Built-in
114
+ * Datatypes}
115
+ */
116
+ import { isNumber } from "@grafctory/core";
117
+ import { xsd } from "@grafctory/core/datatype";
118
+ import { assemble } from "./assembler.js";
119
+ const ByteLimit = 2 ** 7 - 1;
120
+ const ShortLimit = 2 ** 15 - 1;
121
+ const IntLimit = 2 ** 31 - 1;
122
+ const LongLimit = Number.MAX_SAFE_INTEGER;
123
+ const FloatLimit = (2 - 2 ** -23) * 2 ** 127;
124
+ /**
125
+ * Creates a number shape.
126
+ */
127
+ export function number(...args) {
128
+ const [head] = args;
129
+ return assemble(isNumber(head) ? { in: args.filter(isNumber) } : { ...head });
130
+ }
131
+ //// Shorthands //////////////////////////////////////////////////////////////////////////////////////////////////////
132
+ /**
133
+ * Creates a shape for 8-bit signed integer values.
134
+ *
135
+ * Fixes the datatype to `xsd:byte`, marks the shape `integral` and defaults the range to `[-128, 127]`; supplied
136
+ * bounds override the defaults.
137
+ *
138
+ * @typeParam C The stated constraints
139
+ *
140
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
141
+ *
142
+ * @returns An immutable shape admitting 8-bit signed integers, narrowed to the values the constraints enumerate
143
+ *
144
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
145
+ *
146
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#byte XSD 1.0 Part 2: Datatypes § 3.3.19 byte}
147
+ */
148
+ export function byte(constraints) {
149
+ return assemble({
150
+ datatype: xsd.byte,
151
+ integral: true,
152
+ minInclusive: -ByteLimit - 1,
153
+ maxInclusive: ByteLimit,
154
+ ...constraints
155
+ });
156
+ }
157
+ /**
158
+ * Creates a shape for 16-bit signed integer values.
159
+ *
160
+ * Fixes the datatype to `xsd:short`, marks the shape `integral` and defaults the range to `[-32768, 32767]`; supplied
161
+ * bounds override the defaults.
162
+ *
163
+ * @typeParam C The stated constraints
164
+ *
165
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
166
+ *
167
+ * @returns An immutable shape admitting 16-bit signed integers, narrowed to the values the constraints enumerate
168
+ *
169
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
170
+ *
171
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#short XSD 1.0 Part 2: Datatypes § 3.3.18 short}
172
+ */
173
+ export function short(constraints) {
174
+ return assemble({
175
+ datatype: xsd.short,
176
+ integral: true,
177
+ minInclusive: -ShortLimit - 1,
178
+ maxInclusive: ShortLimit,
179
+ ...constraints
180
+ });
181
+ }
182
+ /**
183
+ * Creates a shape for 32-bit signed integer values.
184
+ *
185
+ * Fixes the datatype to `xsd:int`, marks the shape `integral` and defaults the range to
186
+ * `[-2147483648, 2147483647]`; supplied bounds override the defaults.
187
+ *
188
+ * @typeParam C The stated constraints
189
+ *
190
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
191
+ *
192
+ * @returns An immutable shape admitting 32-bit signed integers, narrowed to the values the constraints enumerate
193
+ *
194
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
195
+ *
196
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#int XSD 1.0 Part 2: Datatypes § 3.3.17 int}
197
+ */
198
+ export function int(constraints) {
199
+ return assemble({
200
+ datatype: xsd.int,
201
+ integral: true,
202
+ minInclusive: -IntLimit - 1,
203
+ maxInclusive: IntLimit,
204
+ ...constraints
205
+ });
206
+ }
207
+ /**
208
+ * Creates a shape for 64-bit signed integer values.
209
+ *
210
+ * Fixes the datatype to `xsd:long`, marks the shape `integral` and defaults the range to
211
+ * {@link Number.MIN_SAFE_INTEGER}…{@link Number.MAX_SAFE_INTEGER} (±2⁵³−1), narrower than the datatype's
212
+ * nominal ±2⁶³−1, since values beyond the safe-integer range cannot be represented faithfully as `number`; supplied
213
+ * bounds override the defaults.
214
+ *
215
+ * @typeParam C The stated constraints
216
+ *
217
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
218
+ *
219
+ * @returns An immutable shape admitting 64-bit signed integers, narrowed to the values the constraints enumerate
220
+ *
221
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
222
+ *
223
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#long XSD 1.0 Part 2: Datatypes § 3.3.16 long}
224
+ */
225
+ export function long(constraints) {
226
+ return assemble({
227
+ datatype: xsd.long,
228
+ integral: true,
229
+ minInclusive: -LongLimit,
230
+ maxInclusive: LongLimit,
231
+ ...constraints
232
+ });
233
+ }
234
+ /**
235
+ * Creates a shape for IEEE 754 single-precision floating-point values.
236
+ *
237
+ * Fixes the datatype to `xsd:float` and defaults the range to the finite single-precision interval
238
+ * `±(2 − 2⁻²³) × 2¹²⁷`; supplied bounds override the defaults.
239
+ *
240
+ * @typeParam C The stated constraints
241
+ *
242
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
243
+ *
244
+ * @returns An immutable shape admitting single-precision floats, narrowed to the values the constraints enumerate
245
+ *
246
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
247
+ *
248
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#float XSD 1.0 Part 2: Datatypes § 3.2.4 float}
249
+ */
250
+ export function float(constraints) {
251
+ return assemble({
252
+ datatype: xsd.float,
253
+ minInclusive: -FloatLimit,
254
+ maxInclusive: FloatLimit,
255
+ ...constraints
256
+ });
257
+ }
258
+ /**
259
+ * Creates a shape for IEEE 754 double-precision floating-point values.
260
+ *
261
+ * Fixes the datatype to `xsd:double`.
262
+ *
263
+ * @typeParam C The stated constraints
264
+ *
265
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
266
+ *
267
+ * @returns An immutable shape admitting double-precision floats, narrowed to the values the constraints enumerate
268
+ *
269
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
270
+ *
271
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#double XSD 1.0 Part 2: Datatypes § 3.2.5 double}
272
+ */
273
+ export function double(constraints) {
274
+ return assemble({ datatype: xsd.double, ...constraints });
275
+ }
276
+ /**
277
+ * Creates a shape for arbitrary-precision integer values.
278
+ *
279
+ * Fixes the datatype to `xsd:integer` and marks the shape `integral`.
280
+ *
281
+ * @typeParam C The stated constraints
282
+ *
283
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
284
+ *
285
+ * @returns An immutable shape admitting arbitrary-precision integers, narrowed to the values the constraints enumerate
286
+ *
287
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
288
+ *
289
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#integer XSD 1.0 Part 2: Datatypes § 3.3.13 integer}
290
+ */
291
+ export function integer(constraints) {
292
+ return assemble({ datatype: xsd.integer, integral: true, ...constraints });
293
+ }
294
+ /**
295
+ * Creates a shape for arbitrary-precision decimal values.
296
+ *
297
+ * Fixes the datatype to `xsd:decimal`.
298
+ *
299
+ * @typeParam C The stated constraints
300
+ *
301
+ * @param constraints Optional {@link NumberRangeConstraints range constraints}
302
+ *
303
+ * @returns An immutable shape admitting arbitrary-precision decimals, narrowed to the values the constraints enumerate
304
+ *
305
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
306
+ *
307
+ * @see {@link https://www.w3.org/TR/xmlschema-2/#decimal XSD 1.0 Part 2: Datatypes § 3.2.3 decimal}
308
+ */
309
+ export function decimal(constraints) {
310
+ return assemble({ datatype: xsd.decimal, ...constraints });
311
+ }
312
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,MAAM,SAAS,GAAG,CAAC,IAAE,CAAC,GAAC,CAAC,CAAC;AACzB,MAAM,UAAU,GAAG,CAAC,IAAE,EAAE,GAAC,CAAC,CAAC;AAC3B,MAAM,QAAQ,GAAG,CAAC,IAAE,EAAE,GAAC,CAAC,CAAC;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAC1C,MAAM,UAAU,GAAG,CAAC,CAAC,GAAC,CAAC,IAAG,CAAC,EAAE,CAAC,GAAC,CAAC,IAAE,GAAG,CAAC;AAyNtC;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,GAAG,IAA6C;IAEtE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