@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,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dictionary shape types and operations.
|
|
3
|
+
*
|
|
4
|
+
* Defines the shape describing localised text, stated once per language, together with its constraint types, and
|
|
5
|
+
* provides the {@link dictionary} factory stating them, mapping
|
|
6
|
+
* [JSON-LD language maps](https://www.w3.org/TR/json-ld11/#language-maps) to
|
|
7
|
+
* [RDF 1.1](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) language-tagged strings. A property
|
|
8
|
+
* whose value varies by language takes one member rather than one per language.
|
|
9
|
+
*
|
|
10
|
+
* > [!IMPORTANT]
|
|
11
|
+
* > Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value.
|
|
12
|
+
* > Stating `minLength` above `maxLength` throws a {@link @grafctory/core!TraceError | TraceError}, and so does
|
|
13
|
+
* > requiring a language that `languageIn` rules out, since no map could then satisfy both constraints.
|
|
14
|
+
*
|
|
15
|
+
* How many strings a tag carries is fixed by {@link DictionaryConstraints.uniqueLang | uniqueLang}: a unique-tagged
|
|
16
|
+
* shape gives every tag a single string, and any other gives every tag an array. A member ranging over a dictionary
|
|
17
|
+
* carries the map whole, never in an array, whatever cardinality it states. A map carrying no text under any tag
|
|
18
|
+
* counts as no value, so a required localised member stating an empty map fails its cardinality.
|
|
19
|
+
*
|
|
20
|
+
* The tag-keyed map is the form a value is stored and submitted in. A localised member additionally *coalesces* under
|
|
21
|
+
* language negotiation when retrieved, at the same per-tag arity: the value may be retrieved as the negotiated content
|
|
22
|
+
* alone, and filtered by a plain string operand matched against it under ordinary textual semantics. Submission never
|
|
23
|
+
* coalesces: it accepts the tag-keyed form alone.
|
|
24
|
+
*
|
|
25
|
+
* **Compatibility**
|
|
26
|
+
*
|
|
27
|
+
* | JSON | JSON-LD | RDF 1.1 |
|
|
28
|
+
* | -------------------- | ---------------------------------- | ------------------------------- |
|
|
29
|
+
* | tag-keyed string map | `@language`-container language map | language-tagged string literals |
|
|
30
|
+
*
|
|
31
|
+
* **Defining language-tagged shapes**
|
|
32
|
+
*
|
|
33
|
+
* Values are tag-keyed maps; the [`und`](https://iso639-3.sil.org/code/und) tag carries content of undetermined
|
|
34
|
+
* language (a proper name, say), and the [`zxx`](https://iso639-3.sil.org/code/zxx) tag content with no language at
|
|
35
|
+
* all (identifiers, codes, formulae):
|
|
36
|
+
*
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { dictionary } from '@grafctory/blue/dictionary';
|
|
39
|
+
*
|
|
40
|
+
* const label = dictionary({ uniqueLang: true }); // a single string per tag
|
|
41
|
+
* const keywords = dictionary(); // an array of strings per tag
|
|
42
|
+
* const name = dictionary({ minLength: 1, maxLength: 200 });// length-constrained
|
|
43
|
+
* const abstract = dictionary({ languageIn: ["en", "it"] });// language-restricted
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* **Using in resource shapes**
|
|
47
|
+
*
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { multiple, optional, required, resource } from '@grafctory/blue/resource';
|
|
50
|
+
* import { dictionary } from '@grafctory/blue/dictionary';
|
|
51
|
+
*
|
|
52
|
+
* const Article = resource({
|
|
53
|
+
* title: required(dictionary({ uniqueLang: true, minLength: 1 })),
|
|
54
|
+
* abstract: optional(dictionary({ uniqueLang: true })),
|
|
55
|
+
* keywords: multiple(dictionary({ languageIn: ["en", "fr", "de"] }))
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* A member carries one map whatever cardinality it states, so `keywords` above reads as a single map of string arrays
|
|
60
|
+
* and never as an array of maps.
|
|
61
|
+
*
|
|
62
|
+
* @module
|
|
63
|
+
*
|
|
64
|
+
* @see {@link https://www.w3.org/TR/json-ld11/#language-maps JSON-LD 1.1 § 9.8 Language Maps}
|
|
65
|
+
* @see {@link https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string RDF 1.1 § 3.3 Literals}
|
|
66
|
+
*/
|
|
67
|
+
import type { TagRange } from "@grafctory/core/language";
|
|
68
|
+
/**
|
|
69
|
+
* Describes a localised textual value.
|
|
70
|
+
*
|
|
71
|
+
* Admits the [JSON-LD language maps](https://www.w3.org/TR/json-ld11/#language-maps) a resource may carry: a map keyed
|
|
72
|
+
* by [BCP 47](https://www.rfc-editor.org/info/bcp47) language tag, holding the content the resource states in each
|
|
73
|
+
* language, so that a property whose value varies by language is described by a single shape rather than by one member
|
|
74
|
+
* per language. Content of undetermined language (a proper name, say) is keyed by the
|
|
75
|
+
* [`und`](https://iso639-3.sil.org/code/und) tag, and content belonging to no language at all (an identifier, a code, a
|
|
76
|
+
* formula) by the [`zxx`](https://iso639-3.sil.org/code/zxx) tag. Each entry is stored as a
|
|
77
|
+
* [RDF 1.1](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) language-tagged string.
|
|
78
|
+
*
|
|
79
|
+
* How many strings a tag carries is fixed by {@link DictionaryConstraints.uniqueLang | uniqueLang}: a unique-tagged
|
|
80
|
+
* shape gives every tag a single string, and any other gives every tag an array. The map is a value set in its own
|
|
81
|
+
* right, so a member carries it whole, never in an array, whatever the bounds of the enclosing {@link value!Range}
|
|
82
|
+
* admit: those bounds count the values of the other branches of a two-natured range, which a resource carries in
|
|
83
|
+
* place of the map and never beside it. A map carrying no text under any tag counts as no value, so a required
|
|
84
|
+
* member stating one fails its minimum cardinality, as if the value had been left out.
|
|
85
|
+
*
|
|
86
|
+
* **Negotiation**
|
|
87
|
+
*
|
|
88
|
+
* The tag-keyed map is the form a value is stored and submitted in. On retrieval a localised member is additionally
|
|
89
|
+
* *coalesced* under language negotiation, at the same per-tag arity: the value may be retrieved as the negotiated
|
|
90
|
+
* content alone (a bare string under a unique-tagged shape, otherwise the array of strings the selected tag carries),
|
|
91
|
+
* and filtered by a plain string operand (a comparison, a text search or an option) matched against the negotiated
|
|
92
|
+
* content under ordinary textual semantics. Submission never coalesces: it accepts the tag-keyed form alone.
|
|
93
|
+
*
|
|
94
|
+
* **Inheritance**
|
|
95
|
+
*
|
|
96
|
+
* Where a {@link resource!ResourceShape} extends the shapes it lists as `parents`, localised members are merged
|
|
97
|
+
* according to the following rules. The *child* is the extending shape; the *parent* is the inherited one.
|
|
98
|
+
*
|
|
99
|
+
* | Field | Override Rule |
|
|
100
|
+
* | ------------- | -------------------------------------------------------------------------- |
|
|
101
|
+
* | `kind` | Cannot be overridden |
|
|
102
|
+
* | `minLength` | Child may only raise the minimum length |
|
|
103
|
+
* | `maxLength` | Child may only lower the maximum length |
|
|
104
|
+
* | `languageIn` | Child may only drop accepted ranges |
|
|
105
|
+
* | `hasLanguage` | Child may only add required ranges |
|
|
106
|
+
* | `uniqueLang` | Child may add but not drop; an inherited constraint always carries through |
|
|
107
|
+
*
|
|
108
|
+
* **Cross-field validation**
|
|
109
|
+
*
|
|
110
|
+
* - merged `minLength` must be ≤ merged `maxLength`
|
|
111
|
+
* - every merged `hasLanguage` range must be matchable by some tag the merged `languageIn` admits
|
|
112
|
+
*
|
|
113
|
+
* @see {@link https://www.w3.org/TR/json-ld11/#language-maps JSON-LD 1.1 § 9.8 Language Maps}
|
|
114
|
+
* @see {@link https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string RDF 1.1 § 3.3 Literals}
|
|
115
|
+
*/
|
|
116
|
+
export type DictionaryShape = DictionaryConstraints & {
|
|
117
|
+
/**
|
|
118
|
+
* Discriminator identifying this as a dictionary shape.
|
|
119
|
+
*
|
|
120
|
+
* **Inheritance** — cannot be overridden.
|
|
121
|
+
*/
|
|
122
|
+
readonly kind: "dictionary";
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Constraints accepted by the {@link dictionary} shape factory.
|
|
126
|
+
*
|
|
127
|
+
* Bounds the content a tag may carry, the languages the map may key it by, and the languages it must cover. Length
|
|
128
|
+
* bounds are matched against each string separately, so a value is held to them whatever language it is stated in.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://www.w3.org/TR/shacl/#core-components-string SHACL § 4.4 String-based Constraint Components}
|
|
131
|
+
*/
|
|
132
|
+
export type DictionaryConstraints = {
|
|
133
|
+
/**
|
|
134
|
+
* Restricts every tag to a single string.
|
|
135
|
+
*
|
|
136
|
+
* When `true`, a tag carries a single string, so that a member stating several values spreads them across languages
|
|
137
|
+
* rather than stacking them under one. Fixes the arity the content is resolved at: a bare string under every tag
|
|
138
|
+
* where the constraint is stated, an array of strings under every tag otherwise.
|
|
139
|
+
*
|
|
140
|
+
* **Inheritance** — a child may add the constraint but not drop it: overriding a unique-tagged parent with a
|
|
141
|
+
* non-unique-tagged child is rejected.
|
|
142
|
+
*
|
|
143
|
+
* @defaultValue `undefined` (several strings admitted per tag)
|
|
144
|
+
*
|
|
145
|
+
* @see {@link https://www.w3.org/TR/shacl/#UniqueLangConstraintComponent SHACL § 4.4.5 sh:uniqueLang}
|
|
146
|
+
*/
|
|
147
|
+
readonly uniqueLang?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Minimum string length in characters.
|
|
150
|
+
*
|
|
151
|
+
* **Inheritance** — child may only raise the minimum length.
|
|
152
|
+
*
|
|
153
|
+
* @defaultValue `undefined` (no minimum length)
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://www.w3.org/TR/shacl/#MinLengthConstraintComponent SHACL § 4.4.1 sh:minLength}
|
|
156
|
+
*/
|
|
157
|
+
readonly minLength?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum string length in characters.
|
|
160
|
+
*
|
|
161
|
+
* **Inheritance** — child may only lower the maximum length.
|
|
162
|
+
*
|
|
163
|
+
* @defaultValue `undefined` (no maximum length)
|
|
164
|
+
*
|
|
165
|
+
* @see {@link https://www.w3.org/TR/shacl/#MaxLengthConstraintComponent SHACL § 4.4.2 sh:maxLength}
|
|
166
|
+
*/
|
|
167
|
+
readonly maxLength?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Allowed language ranges.
|
|
170
|
+
*
|
|
171
|
+
* When specified, every tag the map is keyed by must match one of the given {@link TagRange} values under RFC 4647
|
|
172
|
+
* basic filtering. Each range is a basic language range (a sequence of subtags or the standalone `*` wildcard);
|
|
173
|
+
* extended ranges such as `en-*` are not accepted. Empty arrays are ignored. Language *tags*, which identify a
|
|
174
|
+
* language rather than select one, are described by {@link string!tag | tag} instead.
|
|
175
|
+
*
|
|
176
|
+
* **Inheritance** — child may only drop accepted ranges.
|
|
177
|
+
*
|
|
178
|
+
* @defaultValue `undefined` (no language constraint)
|
|
179
|
+
*
|
|
180
|
+
* @see {@link https://www.w3.org/TR/shacl/#LanguageInConstraintComponent SHACL § 4.4.4 sh:languageIn}
|
|
181
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc4647.html RFC 4647 - Matching of Language Tags}
|
|
182
|
+
*/
|
|
183
|
+
readonly languageIn?: readonly TagRange[];
|
|
184
|
+
/**
|
|
185
|
+
* Required language ranges.
|
|
186
|
+
*
|
|
187
|
+
* When specified, every listed {@link TagRange} must be matched under RFC 4647 basic filtering by a tag carrying
|
|
188
|
+
* some content, so that `en` is satisfied by an `en-US` entry and `*` by any entry at all. Empty arrays are ignored.
|
|
189
|
+
*
|
|
190
|
+
* The constraint holds the entries of a map that is given and leaves presence to the member cardinality, so an
|
|
191
|
+
* optional member left out, or stating a map with no content, satisfies it. Ranges that no tag admitted by
|
|
192
|
+
* {@link languageIn} could match are rejected at build time, before any value is ever held to them.
|
|
193
|
+
*
|
|
194
|
+
* **Inheritance** — child may only add required ranges.
|
|
195
|
+
*
|
|
196
|
+
* > [!NOTE]
|
|
197
|
+
* > SHACL has no native equivalent: each range maps to a qualified value shape requiring one matching entry.
|
|
198
|
+
*
|
|
199
|
+
* @defaultValue `undefined` (no required languages)
|
|
200
|
+
*
|
|
201
|
+
* @see {@link https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent SHACL § 4.7.3 sh:qualifiedValueShape}
|
|
202
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc4647.html RFC 4647 - Matching of Language Tags}
|
|
203
|
+
*/
|
|
204
|
+
readonly hasLanguage?: readonly TagRange[];
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Creates a dictionary shape.
|
|
208
|
+
*
|
|
209
|
+
* Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value.
|
|
210
|
+
*
|
|
211
|
+
* @typeParam C The stated constraints
|
|
212
|
+
*
|
|
213
|
+
* @param constraints Optional shape {@link DictionaryConstraints constraints}
|
|
214
|
+
*
|
|
215
|
+
* @returns An immutable shape admitting the language maps the constraints bound, carrying a single string per tag where
|
|
216
|
+
* they state {@link DictionaryConstraints.uniqueLang | uniqueLang}
|
|
217
|
+
*
|
|
218
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
*
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const label = required(dictionary({ uniqueLang: true }));
|
|
224
|
+
* const description = optional(dictionary({ languageIn: ["en", "it"] }));
|
|
225
|
+
* const keywords = multiple(dictionary({ languageIn: ["en"] }));
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export declare function dictionary<const C extends DictionaryConstraints = {}>(constraints?: C): DictionaryShape & {
|
|
229
|
+
/**
|
|
230
|
+
* Restricts every tag to a single string, exactly as stated.
|
|
231
|
+
*
|
|
232
|
+
* Carries the constraint at the value it was given rather than at the whole boolean domain, so that the content of
|
|
233
|
+
* a tag is typed at the arity the shape admits.
|
|
234
|
+
*/
|
|
235
|
+
readonly uniqueLang: C["uniqueLang"];
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dictionary/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAKzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG;IAErD;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAE3B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAEnC;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;;;;;OAQG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAE3B;;;;;;;;OAQG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAE3B;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAA;IAEzC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAA;CAE1C,CAAA;AAKD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,qBAAqB,GAAG,EAAE,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,eAAe,GAAG;IAE1G;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,YAAY,CAAC,CAAA;CAEpC,CAIA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
18
|
+
/**
|
|
19
|
+
* Creates a dictionary shape.
|
|
20
|
+
*
|
|
21
|
+
* Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam C The stated constraints
|
|
24
|
+
*
|
|
25
|
+
* @param constraints Optional shape {@link DictionaryConstraints constraints}
|
|
26
|
+
*
|
|
27
|
+
* @returns An immutable shape admitting the language maps the constraints bound, carrying a single string per tag where
|
|
28
|
+
* they state {@link DictionaryConstraints.uniqueLang | uniqueLang}
|
|
29
|
+
*
|
|
30
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where the stated constraints contradict one another
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const label = required(dictionary({ uniqueLang: true }));
|
|
36
|
+
* const description = optional(dictionary({ languageIn: ["en", "it"] }));
|
|
37
|
+
* const keywords = multiple(dictionary({ languageIn: ["en"] }));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function dictionary(constraints) {
|
|
41
|
+
return assemble(constraints ?? {});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dictionary/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAuEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAwJ1C,wHAAwH;AAExH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,UAAU,CAA6C,WAAe;IAYrF,OAAO,QAAQ,CAAkB,WAAW,IAAI,EAAE,CAAC,CAAC;AAErD,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dictionary value inference.
|
|
3
|
+
*
|
|
4
|
+
* Types every form a localised value takes from the dictionary shape that describes it: the tag-keyed map the value
|
|
5
|
+
* is stored and submitted as, and the negotiated text a retrieval returns in its place. Both forms follow the per-tag
|
|
6
|
+
* arity the shape admits, so stored and retrieved text never disagree on how many strings a tag carries.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { Eager, Lazy } from "@grafctory/core";
|
|
11
|
+
import type { Tag } from "@grafctory/core/language";
|
|
12
|
+
import type { DictionaryShape } from "./index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the tag-keyed map a dictionary shape describes.
|
|
15
|
+
*
|
|
16
|
+
* Yields a map keyed by language tag, carrying a single string under each tag where the shape states
|
|
17
|
+
* {@link DictionaryConstraints.uniqueLang | uniqueLang} and an array of strings under each tag otherwise, so that the
|
|
18
|
+
* content of a tag is typed at the arity the shape admits. A shape leaving the constraint unstated, or stating it only
|
|
19
|
+
* as a boolean, admits several strings under each tag.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam S The describing shape, possibly deferred to break definition cycles
|
|
22
|
+
*/
|
|
23
|
+
export type Tagged<S extends Lazy<DictionaryShape>> = {
|
|
24
|
+
readonly [tag: Tag]: Eager<S> extends {
|
|
25
|
+
readonly uniqueLang: true;
|
|
26
|
+
} ? string : readonly string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the negotiated text a dictionary shape coalesces to.
|
|
30
|
+
*
|
|
31
|
+
* A localised member asked for by the atomic placeholder comes back as plain text: the content of the one tag that
|
|
32
|
+
* language negotiation selects. The text is a single string where the shape states
|
|
33
|
+
* {@link DictionaryConstraints.uniqueLang | uniqueLang}, and an array of strings otherwise, matching the per-tag arity
|
|
34
|
+
* {@link Tagged} states for the map. A shape that leaves the constraint unstated, or states it only as a boolean, may
|
|
35
|
+
* carry several strings under a tag, so its text is always an array, however many strings the selected tag holds.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam S The describing shape, possibly deferred to break definition cycles
|
|
38
|
+
*/
|
|
39
|
+
export type Coalesced<S extends Lazy<DictionaryShape>> = Eager<S> extends {
|
|
40
|
+
readonly uniqueLang: true;
|
|
41
|
+
} ? string : readonly string[];
|
|
42
|
+
//# sourceMappingURL=inference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../src/dictionary/inference.ts"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAyB,eAAe,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;;;;GASG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,IAAI,CAAC,eAAe,CAAC,IAAI;IAErD,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS;QAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAA;KAAE,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CAEhG,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,IAAI,CAAC,eAAe,CAAC,IACpD,KAAK,CAAC,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=inference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference.js","sourceRoot":"","sources":["../../src/dictionary/inference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dictionary value validation.
|
|
3
|
+
*
|
|
4
|
+
* Holds a value to what a dictionary shape admits and reports everything wrong with it at once, keyed by the tag at
|
|
5
|
+
* fault, so that a caller may tell which language failed and why.
|
|
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 DictionaryShape } from "./index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Validates values against a dictionary shape.
|
|
15
|
+
*
|
|
16
|
+
* Reports a value that is not a language map as a `{kind}` violation, and each entry that breaks a constraint under
|
|
17
|
+
* its own facet, keyed by the tag it is stated under, so that a caller may tell which language failed and why. A tag
|
|
18
|
+
* carries a single string where the shape states
|
|
19
|
+
* {@link dictionary!DictionaryConstraints.uniqueLang | uniqueLang} and an array of strings otherwise; a value stated at
|
|
20
|
+
* the other arity is rejected as a malformed map rather than as a broken constraint.
|
|
21
|
+
*
|
|
22
|
+
* A required language with no entry in any map is reported against the value set as a whole, since no tag carries it.
|
|
23
|
+
* An empty set states no map and satisfies such a constraint, leaving presence to the cardinality of the member.
|
|
24
|
+
*
|
|
25
|
+
* @param values The values to validate
|
|
26
|
+
* @param shape The shape the values are matched against
|
|
27
|
+
* @param opts Validation options
|
|
28
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. A `"model"`
|
|
29
|
+
* placeholder asks for the text either coalesced, as the atomic placeholder, or per tag, as a map of the language
|
|
30
|
+
* ranges wanted. The map is keyed by range, the `*` wildcard included, where a value is keyed by tag
|
|
31
|
+
*
|
|
32
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateDictionary(values: readonly unknown[], shape: DictionaryShape, { scope }?: {
|
|
35
|
+
scope?: Scope;
|
|
36
|
+
}): Optional<Trace>;
|
|
37
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/dictionary/validator.ts"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AAEH,OAAO,EAA4C,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAgD,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AAEjH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,EAEtF,KAAe,EAEf,GAAE;IAEF,KAAK,CAAC,EAAE,KAAK,CAAA;CAER,GAAG,QAAQ,CAAC,KAAK,CAAC,CAkHvB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
* Dictionary value validation.
|
|
18
|
+
*
|
|
19
|
+
* Holds a value to what a dictionary shape admits and reports everything wrong with it at once, keyed by the tag at
|
|
20
|
+
* fault, so that a caller may tell which language failed and why.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { isArray, isObject, isString, opt as fold } from "@grafctory/core";
|
|
25
|
+
import { isTag, isTagRange, matchTag } from "@grafctory/core/language";
|
|
26
|
+
import { all, array, fail, length, object, pass, test } from "@grafctory/core/trace";
|
|
27
|
+
import { isAtomic } from "@grafctory/qest/model";
|
|
28
|
+
/**
|
|
29
|
+
* Validates values against a dictionary shape.
|
|
30
|
+
*
|
|
31
|
+
* Reports a value that is not a language map as a `{kind}` violation, and each entry that breaks a constraint under
|
|
32
|
+
* its own facet, keyed by the tag it is stated under, so that a caller may tell which language failed and why. A tag
|
|
33
|
+
* carries a single string where the shape states
|
|
34
|
+
* {@link dictionary!DictionaryConstraints.uniqueLang | uniqueLang} and an array of strings otherwise; a value stated at
|
|
35
|
+
* the other arity is rejected as a malformed map rather than as a broken constraint.
|
|
36
|
+
*
|
|
37
|
+
* A required language with no entry in any map is reported against the value set as a whole, since no tag carries it.
|
|
38
|
+
* An empty set states no map and satisfies such a constraint, leaving presence to the cardinality of the member.
|
|
39
|
+
*
|
|
40
|
+
* @param values The values to validate
|
|
41
|
+
* @param shape The shape the values are matched against
|
|
42
|
+
* @param opts Validation options
|
|
43
|
+
* @param opts.scope The {@link Scope | strictness} the shape is enforced at, defaulting to `"state"`. A `"model"`
|
|
44
|
+
* placeholder asks for the text either coalesced, as the atomic placeholder, or per tag, as a map of the language
|
|
45
|
+
* ranges wanted. The map is keyed by range, the `*` wildcard included, where a value is keyed by tag
|
|
46
|
+
*
|
|
47
|
+
* @returns A trace of the violations found, or `undefined` where every value matches `shape`
|
|
48
|
+
*/
|
|
49
|
+
export function validateDictionary(values, shape, { scope = "state" } = {}) {
|
|
50
|
+
switch (scope) {
|
|
51
|
+
case "state":
|
|
52
|
+
return state(shape)(values);
|
|
53
|
+
case "model":
|
|
54
|
+
return model()(values);
|
|
55
|
+
}
|
|
56
|
+
function state({ uniqueLang, minLength, maxLength, languageIn, hasLanguage }) {
|
|
57
|
+
return all(covers(), array((value) => !isObject(value) ? ["{kind} expected <dictionary> value"]
|
|
58
|
+
: object(([tag, text]) => !isTag(tag) ? [{ [tag]: ["invalid tag"] }]
|
|
59
|
+
: fold(entry(tag, text), trace => [{ [tag]: trace }]))(value)));
|
|
60
|
+
/**
|
|
61
|
+
* Holds the content of a tag to the stated arity, then to the length and language constraints; content stated
|
|
62
|
+
* at the other arity is rejected as malformed rather than as a broken constraint.
|
|
63
|
+
*/
|
|
64
|
+
function entry(tag, text) {
|
|
65
|
+
return uniqueLang === true
|
|
66
|
+
? isString(text)
|
|
67
|
+
? all(length(minLength, maxLength), accepts(tag))(text)
|
|
68
|
+
: ["expected string value"]
|
|
69
|
+
: isArray(text, isString)
|
|
70
|
+
? all(array(length(minLength, maxLength)), accepts(tag))(text)
|
|
71
|
+
: ["expected string array value"];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Requires every listed range to be matched by a tag carrying content at the stated arity, in any map of the
|
|
75
|
+
* set. An empty set states no map and passes; any violation concerns the whole set, so it leads the report.
|
|
76
|
+
*/
|
|
77
|
+
function covers() {
|
|
78
|
+
return test(values => {
|
|
79
|
+
const tags = values.filter(value => isObject(value)).flatMap(map => Object.entries(map)
|
|
80
|
+
.filter(([tag, text]) => isTag(tag) && (uniqueLang === true ? isString(text)
|
|
81
|
+
: isArray(text, isString) && text.length > 0))
|
|
82
|
+
.map(([tag]) => tag));
|
|
83
|
+
const unmatched = (hasLanguage ?? []).filter(range => !tags.some(tag => matchTag(tag, range)));
|
|
84
|
+
return values.length === 0 || unmatched.length === 0 || [
|
|
85
|
+
`{hasLanguage} missing entries for required ranges [${unmatched.join(", ")}]`
|
|
86
|
+
];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function accepts(tag) {
|
|
90
|
+
return languageIn === undefined || languageIn.some(range => matchTag(tag, range)) ? pass
|
|
91
|
+
: fail([`{languageIn} unsupported tag for allowed languages [${languageIn.join(", ")}]`]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The form alone: a localised member is asked for coalesced, as the atomic placeholder, or structurally, as a map
|
|
96
|
+
* naming the tag ranges wanted. Per-tag arity follows the shape, so a map entry asks for the value and no more.
|
|
97
|
+
*/
|
|
98
|
+
function model() {
|
|
99
|
+
return array((value) => isAtomic(value) ? undefined
|
|
100
|
+
: !isObject(value) ? ["{kind} expected <Atomic> or <Locale> placeholder"]
|
|
101
|
+
: object(([range, asked]) => !isTagRange(range) ? [{ [range]: ["invalid tag range"] }]
|
|
102
|
+
: isAtomic(asked) ? undefined
|
|
103
|
+
: [{ [range]: ["{type} expected <Atomic> value"] }])(value));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/dictionary/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,Q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C,EAAE,CAAC,gCAAgC,CAAC,EAAE,CAAC,CACrD,CAAC,KAAK,CAAC,CAET,CAAC;IAEH,CAAC;AAEF,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ResourceShape } from "./resource/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies retrieval policies to a validated template.
|
|
4
|
+
*
|
|
5
|
+
* Returns the template the server will actually honour, so that a caller may hold a request to what the service
|
|
6
|
+
* guarantees rather than to what the client happened to ask for. The template is rewritten where a policy requires it
|
|
7
|
+
* and returned unchanged everywhere else, keeping what the client asked for intact; a template stating no policy at
|
|
8
|
+
* all comes back as it went in.
|
|
9
|
+
*
|
|
10
|
+
* **Default paging**
|
|
11
|
+
*
|
|
12
|
+
* A collection left unpaged is given the largest page the service serves, so that a client omitting `#` is handed a
|
|
13
|
+
* bounded set rather than the whole of it. A collection already stating a page of its own is left alone, as is a
|
|
14
|
+
* single-valued or localised slot, which nothing pages, and a projection column, which holds one value per row and so
|
|
15
|
+
* reaches no collection of its own.
|
|
16
|
+
*
|
|
17
|
+
* The template is expected to have been validated against the shape: a malformed one is returned as it stands rather
|
|
18
|
+
* than reported.
|
|
19
|
+
*
|
|
20
|
+
* @param value The validated template to enforce
|
|
21
|
+
* @param shape The shape the template was validated against
|
|
22
|
+
* @param opts Enforcement options, each applied on its own
|
|
23
|
+
* @param opts.limit The page every unpaged collection is held to; omitted, or `0`, leaves paging to the client
|
|
24
|
+
*
|
|
25
|
+
* @returns A template structurally equivalent to `value`, rewritten where a policy requires it
|
|
26
|
+
*
|
|
27
|
+
* @throws {@link @grafctory/core!TraceError | TraceError} Where `shape` reaches itself through a cycle no link
|
|
28
|
+
* breaks, or where a union it reaches declares a shared member name inconsistently across its branches
|
|
29
|
+
*/
|
|
30
|
+
export declare function enforce(value: unknown, shape: ResourceShape, { limit }?: {
|
|
31
|
+
readonly limit?: number;
|
|
32
|
+
}): unknown;
|
|
33
|
+
//# sourceMappingURL=index.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.core.d.ts","sourceRoot":"","sources":["../src/index.core.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,EAE7D,KAAK,EAEL,GAAE;IAEF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAElB,GAAG,OAAO,CAgIf"}
|