@grafctory/blue 0.15.1 → 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/README.md +102 -87
- package/dist/dictionary/assembler.d.ts +5 -5
- package/dist/dictionary/assembler.d.ts.map +1 -1
- package/dist/dictionary/assembler.js +39 -15
- package/dist/dictionary/assembler.js.map +1 -1
- package/dist/dictionary/index.d.ts +39 -13
- package/dist/dictionary/index.d.ts.map +1 -1
- package/dist/dictionary/index.js.map +1 -1
- package/dist/dictionary/validator.d.ts +3 -0
- package/dist/dictionary/validator.d.ts.map +1 -1
- package/dist/dictionary/validator.js +43 -28
- package/dist/dictionary/validator.js.map +1 -1
- package/dist/resource/index.d.ts +6 -1
- package/dist/resource/index.d.ts.map +1 -1
- package/dist/resource/index.js.map +1 -1
- package/dist/resource/validator.d.ts.map +1 -1
- package/dist/resource/validator.js +144 -162
- package/dist/resource/validator.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# @grafctory/blue
|
|
2
2
|
|
|
3
|
-
[![npm]
|
|
3
|
+
[![npm][npm-badge]][npm]
|
|
4
|
+
|
|
5
|
+
[npm-badge]: https://img.shields.io/npm/v/@grafctory/blue
|
|
6
|
+
[npm]: https://www.npmjs.com/package/@grafctory/blue
|
|
7
|
+
[grafctory]: https://github.com/grafctory
|
|
4
8
|
|
|
5
9
|
Declarative blueprints for model-driven linked data processing.
|
|
6
10
|
|
|
7
|
-
**@grafctory/blue**
|
|
8
|
-
by [@grafctory/qest]
|
|
11
|
+
**@grafctory/blue** is the schema module of the [Grafctory][grafctory] model-driven knowledge graph framework. It
|
|
12
|
+
describes resources as shapes over the data model defined by [@grafctory/qest], and the same shapes drive storage in
|
|
13
|
+
[@grafctory/keep] and HTTP endpoints in [@grafctory/gate].
|
|
9
14
|
|
|
10
15
|
Shape-based schemas go beyond structural validation, capturing the complete semantics of a resource (structure,
|
|
11
16
|
constraints, metadata, and relationships), enabling them to act as a single source of truth for automated validation,
|
|
@@ -23,11 +28,9 @@ validation engine:
|
|
|
23
28
|
- **Actionable Error Feedback**: per-value, per-property traces surface precise violations
|
|
24
29
|
- **Custom When Needed**: pluggable validators extend built-in constraints
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
> [@grafctory/qest integrated ecosystem](https://github.com/grafctory/qest#ecosystem)
|
|
30
|
-
> for rapid development of linked data applications.
|
|
31
|
+
[@grafctory/qest]: https://github.com/grafctory/qest
|
|
32
|
+
[@grafctory/keep]: https://github.com/grafctory/keep
|
|
33
|
+
[@grafctory/gate]: https://github.com/grafctory/gate
|
|
31
34
|
|
|
32
35
|
# Installation
|
|
33
36
|
|
|
@@ -48,15 +51,15 @@ npm install @grafctory/blue
|
|
|
48
51
|
>
|
|
49
52
|
> | Module | Description |
|
|
50
53
|
> |------------------------------|---------------------------------------|
|
|
51
|
-
> | [@grafctory/blue]
|
|
52
|
-
> | [@grafctory/blue/value]
|
|
53
|
-
> | [@grafctory/blue/boolean]
|
|
54
|
-
> | [@grafctory/blue/number]
|
|
55
|
-
> | [@grafctory/blue/string]
|
|
56
|
-
> | [@grafctory/blue/dictionary]
|
|
57
|
-
> | [@grafctory/blue/reference]
|
|
58
|
-
> | [@grafctory/blue/resource]
|
|
59
|
-
> | [@grafctory/blue/union]
|
|
54
|
+
> | [@grafctory/blue] | Linked data validation |
|
|
55
|
+
> | [@grafctory/blue/value] | Value shape types and operations |
|
|
56
|
+
> | [@grafctory/blue/boolean] | Boolean shape types and operations |
|
|
57
|
+
> | [@grafctory/blue/number] | Number shape types and operations |
|
|
58
|
+
> | [@grafctory/blue/string] | String shape types and operations |
|
|
59
|
+
> | [@grafctory/blue/dictionary] | Dictionary shape types and operations |
|
|
60
|
+
> | [@grafctory/blue/reference] | Reference shape types and operations |
|
|
61
|
+
> | [@grafctory/blue/resource] | Resource shape types and operations |
|
|
62
|
+
> | [@grafctory/blue/union] | Union shape types and operations |
|
|
60
63
|
|
|
61
64
|
[@grafctory/blue]: https://grafctory.github.io/blue/modules/index.html
|
|
62
65
|
|
|
@@ -90,6 +93,7 @@ import { dictionary } from "@grafctory/blue/dictionary";
|
|
|
90
93
|
import { reference } from "@grafctory/blue/reference";
|
|
91
94
|
import { id, multiple, optional, required, resource, type } from "@grafctory/blue/resource";
|
|
92
95
|
|
|
96
|
+
|
|
93
97
|
function Thing() {
|
|
94
98
|
return resource({
|
|
95
99
|
id: id(),
|
|
@@ -147,15 +151,15 @@ counterparts are.
|
|
|
147
151
|
|
|
148
152
|
A `dictionary()` range stands apart: a localised property carries its language map whole, never in an array, so it is
|
|
149
153
|
typed as the bare map at every cardinality. Where a dictionary sits in a union beside other branches, the property is
|
|
150
|
-
typed as either the map or the array those branches imply, since a resource carries one or the other and never both,
|
|
151
|
-
|
|
154
|
+
typed as either the map or the array those branches imply, since a resource carries one or the other and never both, and
|
|
155
|
+
the bounds count the other branches alone.
|
|
152
156
|
|
|
153
|
-
Each factory takes the constraints the property carries beyond its cardinality, such as IRI mappings, labels,
|
|
154
|
-
|
|
157
|
+
Each factory takes the constraints the property carries beyond its cardinality, such as IRI mappings, labels, ownership
|
|
158
|
+
flags, or a `hidden` flag withholding it from default serialisation, as a trailing argument:
|
|
155
159
|
`required(string(), { forward: schema })`. The `id()` and `type()` markers take the same `hidden` flag.
|
|
156
160
|
|
|
157
|
-
Cardinalities admitting absence also relax their key to an optional one, so a value literal spells out only the
|
|
158
|
-
|
|
161
|
+
Cardinalities admitting absence also relax their key to an optional one, so a value literal spells out only the members
|
|
162
|
+
it actually carries; reading an omitted member still yields `undefined`.
|
|
159
163
|
|
|
160
164
|
Resource members link to other resources in two ways. A `reference()` wrapper links to a **standalone resource**, an
|
|
161
165
|
independently identified and managed entity like `Vendor`. A direct shape inclusion defines an **embedded resource**, a
|
|
@@ -165,15 +169,17 @@ Properties accepting values of more than one type are modelled as unions of posi
|
|
|
165
169
|
regime: a stored **value** must single out **exactly one** branch (`sh:xone`), tested against all constraints, and is
|
|
166
170
|
rejected when it fits several (ambiguous) or none (unsatisfiable); a relational **bound** must likewise single out
|
|
167
171
|
exactly one, but keys on syntactic traits alone, as it need not be a legal value; a retrieval **placeholder** is tested
|
|
168
|
-
by form alone and must fit **at least one** branch (`sh:or`), may fit several, and is rejected only when it fits
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
by form alone and must fit **at least one** branch (`sh:or`), may fit several, and is rejected only when it fits none
|
|
173
|
+
(see [Validating Templates](#validating-templates)). A multi-valued property matches each of its values independently,
|
|
174
|
+
and values are stored as they stand with no branch wrapping.
|
|
171
175
|
|
|
172
176
|
Branches are expected to be **disjoint**: overlapping ones are accepted as the shape is built, and an ambiguous value is
|
|
173
177
|
rejected only when it is matched. Either of the following representations is accepted at the same `address` position:
|
|
174
178
|
|
|
175
179
|
```json
|
|
176
|
-
{
|
|
180
|
+
{
|
|
181
|
+
"address": "12 Harbour Street, Copenhagen"
|
|
182
|
+
}
|
|
177
183
|
```
|
|
178
184
|
|
|
179
185
|
```json
|
|
@@ -189,19 +195,19 @@ rejected only when it is matched. Either of the following representations is acc
|
|
|
189
195
|
|
|
190
196
|
Declare parent shapes first to inherit their members and constraints. Local members augment the parent and may override
|
|
191
197
|
inherited ones, but only by *narrowing*: an override restricts what it inherits and never relaxes it. Cardinality
|
|
192
|
-
narrows monotonically (`required` may override `optional`, but not the reverse), per-kind constraints intersect, and
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
narrows monotonically (`required` may override `optional`, but not the reverse), per-kind constraints intersect, and the
|
|
199
|
+
override is rejected at the call site when the child relaxes the parent. Names and descriptions restrict no value, so an
|
|
200
|
+
override may replace the ones it inherits to present the member in the terms of the child.
|
|
195
201
|
|
|
196
202
|
```ts
|
|
197
203
|
const NamedThing = resource({
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
id: id(),
|
|
205
|
+
name: required(string({ minLength: 1 }))
|
|
200
206
|
});
|
|
201
207
|
|
|
202
208
|
const Vendor = resource(NamedThing, {
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
name: required(string({ minLength: 3, maxLength: 80 })), // narrows minLength
|
|
210
|
+
rating: optional(number({ minInclusive: 0, maxInclusive: 5 }))
|
|
205
211
|
});
|
|
206
212
|
```
|
|
207
213
|
|
|
@@ -209,47 +215,47 @@ const Vendor = resource(NamedThing, {
|
|
|
209
215
|
|
|
210
216
|
A member holding a nested resource or a `reference(...)` is refined by re-pointing it at a shape that extends the
|
|
211
217
|
inherited target. The refining shape declares only what it adds or narrows: it reaches the inherited definition through
|
|
212
|
-
its own parents, so the parent definition is never restated. A `reference(...)` target that doesn't extend the
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
its own parents, so the parent definition is never restated. A `reference(...)` target that doesn't extend the inherited
|
|
219
|
+
one, the inherited target's own parent included, is rejected at the call site; a target deferred to break a definition
|
|
220
|
+
cycle is held to the same rule once its definition stands, so shapes reaching themselves or each other may be re-pointed
|
|
221
|
+
just as well.
|
|
216
222
|
|
|
217
223
|
```ts
|
|
218
224
|
const Organization = resource({
|
|
219
|
-
|
|
225
|
+
class: "https://schema.org/Organization"
|
|
220
226
|
}, {
|
|
221
|
-
|
|
222
|
-
|
|
227
|
+
id: id(),
|
|
228
|
+
name: required(string())
|
|
223
229
|
});
|
|
224
230
|
|
|
225
231
|
const University = resource(Organization, { class: "https://ec2u.eu/University" }, {
|
|
226
|
-
|
|
232
|
+
country: required(string())
|
|
227
233
|
});
|
|
228
234
|
|
|
229
235
|
const Unit = resource({
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
id: id(),
|
|
237
|
+
unitOf: required(reference(Organization)), // referenced target
|
|
238
|
+
host: required(Organization) // embedded target
|
|
233
239
|
});
|
|
234
240
|
|
|
235
241
|
const ResearchUnit = resource(Unit, {
|
|
236
|
-
|
|
237
|
-
|
|
242
|
+
unitOf: required(reference(University)), // re-pointed at the extending target
|
|
243
|
+
host: required(University)
|
|
238
244
|
});
|
|
239
245
|
```
|
|
240
246
|
|
|
241
247
|
Extending the inherited target is what makes the refinement legal for an embedded member: a nested resource value must
|
|
242
|
-
belong to every `class` the inherited target declares, whether the refining shape states it in its own right or
|
|
243
|
-
|
|
248
|
+
belong to every `class` the inherited target declares, whether the refining shape states it in its own right or inherits
|
|
249
|
+
it, so a standalone shape that merely repeats the inherited members is rejected.
|
|
244
250
|
|
|
245
251
|
### Narrowing Union Members
|
|
246
252
|
|
|
247
253
|
When the parent declares a `union(...)` member, an extending shape may narrow it in two forms:
|
|
248
254
|
|
|
249
255
|
- **Single-branch narrowing**: the child supplies a non-union shape that narrows exactly one of the parent's branches.
|
|
250
|
-
|
|
256
|
+
The merged member becomes a bare value shape, no longer polymorphic.
|
|
251
257
|
- **Branch subsetting**: the child supplies a smaller `union(...)`; each child branch narrows a distinct parent branch
|
|
252
|
-
|
|
258
|
+
(an injective pairing), the paired branches are merged, and unpaired parent branches are dropped.
|
|
253
259
|
|
|
254
260
|
A child branch narrowing no parent branch, several, or one already claimed by another child branch is rejected at the
|
|
255
261
|
call site.
|
|
@@ -281,6 +287,7 @@ Schemas double as TypeScript type definitions. `State` yields the value a resour
|
|
|
281
287
|
```ts
|
|
282
288
|
import { type State } from "@grafctory/blue/value";
|
|
283
289
|
|
|
290
|
+
|
|
284
291
|
type ProductType = State<typeof Product>;
|
|
285
292
|
|
|
286
293
|
// {
|
|
@@ -312,6 +319,7 @@ than everything the schema declares:
|
|
|
312
319
|
```ts
|
|
313
320
|
import { type Match } from "@grafctory/blue/value";
|
|
314
321
|
|
|
322
|
+
|
|
315
323
|
type ProductSummary = Match<typeof Product, { id: {}, price: {} }>;
|
|
316
324
|
|
|
317
325
|
// {
|
|
@@ -328,21 +336,23 @@ The retrieval models themselves are held to the schema where they are written:
|
|
|
328
336
|
|
|
329
337
|
- `Model` admits the templates a resource shape serves, rejecting a member the shape doesn't carry
|
|
330
338
|
- `Slice` admits the models a collection held by a property serves, merged with the criteria filtering, ordering and
|
|
331
|
-
|
|
339
|
+
paginating it
|
|
332
340
|
- `Items` types the items of such a collection, narrowed to what the model asked for
|
|
333
341
|
- `Frame` types a single item of such a collection, for code generic over the schema and the model
|
|
334
342
|
|
|
335
|
-
The `items` accessor gets those items from the resource a slice retrieval returns, typed as `Items`, without looking
|
|
336
|
-
|
|
343
|
+
The `items` accessor gets those items from the resource a slice retrieval returns, typed as `Items`, without looking up
|
|
344
|
+
the collection property by name.
|
|
337
345
|
|
|
338
346
|
## Validating Resources
|
|
339
347
|
|
|
340
348
|
The overloaded `validate` function checks a value against a schema and returns a
|
|
341
|
-
[Relay](https://grafctory.github.io/core/interfaces/relay.Relay.html) that dispatches to either a `value` or `trace`
|
|
349
|
+
[Relay](https://grafctory.github.io/core/interfaces/relay.Relay.html) that dispatches to either a `value` or `trace`
|
|
350
|
+
handler:
|
|
342
351
|
|
|
343
352
|
```ts
|
|
344
353
|
import { validate } from "@grafctory/blue";
|
|
345
354
|
|
|
355
|
+
|
|
346
356
|
validate(data, { shape: Product })({
|
|
347
357
|
value: product => {
|
|
348
358
|
// product is typed as State<typeof Product>
|
|
@@ -371,6 +381,7 @@ members the template asked for are checked, and the result is narrowed to them:
|
|
|
371
381
|
```ts
|
|
372
382
|
import { validate } from "@grafctory/blue";
|
|
373
383
|
|
|
384
|
+
|
|
374
385
|
const model = { id: {}, name: {} }; // projection requested by the caller
|
|
375
386
|
|
|
376
387
|
validate(response, { shape: Product, model })({
|
|
@@ -384,12 +395,11 @@ validate(response, { shape: Product, model })({
|
|
|
384
395
|
```
|
|
385
396
|
|
|
386
397
|
Constraints on members absent from `model` are not enforced, so an unrequested required member triggers no `minCount`
|
|
387
|
-
violation, nor does a polymorphic member coming back empty where the template reaches only some of its variants, as
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
the part of it a template asked for, even where the template asks for every member.
|
|
398
|
+
violation, nor does a polymorphic member coming back empty where the template reaches only some of its variants, as the
|
|
399
|
+
resource may hold another. A member the template didn't ask for is rejected all the same, as the caller has nowhere to
|
|
400
|
+
put it. A reference member additionally accepts an expanded nested resource, validated against the target shape narrowed
|
|
401
|
+
by the nested projection in `model`. Custom validators are not run, as they are written against a whole resource rather
|
|
402
|
+
than the part of it a template asked for, even where the template asks for every member.
|
|
393
403
|
|
|
394
404
|
## Validating Templates
|
|
395
405
|
|
|
@@ -399,6 +409,7 @@ The same `validate` function validates retrieval
|
|
|
399
409
|
```ts
|
|
400
410
|
import { validate } from "@grafctory/blue";
|
|
401
411
|
|
|
412
|
+
|
|
402
413
|
validate(data, { model: true, shape: Product });
|
|
403
414
|
validate(data, { model: true, shape: Product, plain: true });
|
|
404
415
|
validate(data, { model: true, shape: Product, depth: 0 });
|
|
@@ -430,21 +441,21 @@ no collection to narrow, and a localised member is filtered by its own tag range
|
|
|
430
441
|
What each kind of member may be asked for:
|
|
431
442
|
|
|
432
443
|
- **Reference**: either the atomic placeholder, retrieving the identifier naming the target, or a nested template
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
- **Union**: the keyed form (`{"0": …, "1": …}`), one placeholder per alternative wanted, where the alternatives
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
validated against the target shape. An embedded resource, naming no identifier to come back as, is reached through a
|
|
445
|
+
template alone.
|
|
446
|
+
- **Union**: the keyed form (`{"0": …, "1": …}`), one placeholder per alternative wanted, where the alternatives want
|
|
447
|
+
different shapes; where one shape serves them all, the atomic placeholder addresses the property directly. Keys are
|
|
448
|
+
opaque labels carrying no positional meaning: each placeholder is matched by form alone and retrieves every branch it
|
|
449
|
+
fits. The atomic placeholder requests every branch coming back as a value. A nested template reaches every resource
|
|
450
|
+
branch admitting at least one of the members it asks for, so it may span several, each answering the members it
|
|
451
|
+
admits. A member several branches declare may take a different shape in each, and what is asked for it need fit only
|
|
452
|
+
one of them. Only a placeholder fitting no branch at all is rejected. A tag range may also be a member name, so an
|
|
453
|
+
object whose keys each name a member of a resource branch is read as a template, and any other object as a map of tag
|
|
454
|
+
ranges.
|
|
444
455
|
- **Localised**: a map of the tag ranges wanted, each asking for the value a matched tag carries, or the atomic
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
456
|
+
placeholder, standing for the content language negotiation settles on. Per-tag arity follows the shape rather than the
|
|
457
|
+
template. A localised branch of a union takes the map under a branch map, or directly on the member if no other branch
|
|
458
|
+
reaches a resource, since the map then cannot be read as a template.
|
|
448
459
|
|
|
449
460
|
Constraint operands follow their own rules: comparison bounds and set-matching options carry content rather than
|
|
450
461
|
placeholders, so each must single out exactly one branch, a bound keying on kind and lexical pattern and an option on
|
|
@@ -458,7 +469,7 @@ Three options bound the query language a template may draw on:
|
|
|
458
469
|
- **`plain`**: rejects the aggregate transforms combining several values into one (`count`, `sum`, `min`, `max`, `avg`)
|
|
459
470
|
- **`depth`**: caps nested template expansion and property path length
|
|
460
471
|
- **`limit`**: caps the `#` pagination constraint, and is injected as a default where a collection states none; `0`,
|
|
461
|
-
|
|
472
|
+
like omitting it, leaves the page to the client
|
|
462
473
|
|
|
463
474
|
> [!CAUTION]
|
|
464
475
|
>
|
|
@@ -473,27 +484,29 @@ describing and validating RDF graphs. It defines *shapes* (sets of constraints t
|
|
|
473
484
|
covering structure, cardinality, value ranges, and logical combinations.
|
|
474
485
|
|
|
475
486
|
**@grafctory/blue** implements a controlled SHACL subset tailored to the
|
|
476
|
-
[JSON-LD](https://www.w3.org/TR/json-ld11/) profile defined by [@grafctory/qest]
|
|
477
|
-
|
|
487
|
+
[JSON-LD](https://www.w3.org/TR/json-ld11/) profile defined by [@grafctory/qest], enabling TypeScript developers to use
|
|
488
|
+
shape-based validation without mastering SHACL technicalities.
|
|
478
489
|
|
|
479
490
|
This controlled subset is specified by:
|
|
480
491
|
|
|
481
492
|
- [cardinality constraints](https://www.w3.org/TR/shacl/#core-components-count) (`sh:minCount`, `sh:maxCount`)
|
|
482
|
-
|
|
493
|
+
for specifying how many values a property must or may have
|
|
483
494
|
- [value range constraints](https://www.w3.org/TR/shacl/#core-components-range) (`sh:minExclusive`,
|
|
484
|
-
|
|
495
|
+
`sh:maxExclusive`, `sh:minInclusive`, `sh:maxInclusive`) for numeric value ranges
|
|
485
496
|
- [string constraints](https://www.w3.org/TR/shacl/#core-components-string) (`sh:minLength`, `sh:maxLength`,
|
|
486
|
-
|
|
497
|
+
`sh:pattern`, `sh:languageIn`, `sh:uniqueLang`) for text length, patterns, and language tags
|
|
487
498
|
- [value type constraints](https://www.w3.org/TR/shacl/#core-components-value-type) (`sh:class`, `sh:datatype`) for
|
|
488
|
-
|
|
489
|
-
|
|
499
|
+
declaring the expected type of resource instances and the RDF datatype of literals; `sh:class` is limited to a single
|
|
500
|
+
class
|
|
490
501
|
- [value constraints](https://www.w3.org/TR/shacl/#core-components-others) (`sh:in`, `sh:hasValue`) for enumerations and
|
|
491
|
-
|
|
502
|
+
required values
|
|
503
|
+
- [shape-based constraints](https://www.w3.org/TR/shacl/#core-components-shape) limited to `sh:qualifiedValueShape`
|
|
504
|
+
with `sh:qualifiedMinCount`, for requiring localised text to be stated in given languages
|
|
492
505
|
- [logical constraints](https://www.w3.org/TR/shacl/#core-components-logical) limited to `sh:xone` typed unions on
|
|
493
|
-
|
|
494
|
-
|
|
506
|
+
members, matched exactly-one on write and relaxed to at-least-one (`sh:or`) on read; the `sh:not`, `sh:and`, and
|
|
507
|
+
`sh:or` shape combinators are not supported for authoring
|
|
495
508
|
- [closed shapes](https://www.w3.org/TR/shacl/#ClosedConstraintComponent) enforced by default on all resource shapes;
|
|
496
|
-
|
|
509
|
+
unknown properties are always rejected
|
|
497
510
|
|
|
498
511
|
[Property pair constraints](https://www.w3.org/TR/shacl/#core-components-property-pairs) and
|
|
499
512
|
[property paths](https://www.w3.org/TR/shacl/#property-paths) are not supported; cross-property logic can be implemented
|
|
@@ -508,3 +521,5 @@ via custom [validators](https://grafctory.github.io/blue/modules/resource.html).
|
|
|
508
521
|
|
|
509
522
|
This project is licensed under the Apache 2.0 License –
|
|
510
523
|
see [LICENSE](https://github.com/grafctory/blue?tab=Apache-2.0-1-ov-file) file for details.
|
|
524
|
+
|
|
525
|
+
<sub>Grafctory™ is a trademark of Metreeca srl.</sub>
|
|
@@ -39,12 +39,12 @@ export declare function assemble<U extends undefined | boolean>(constraints: Dic
|
|
|
39
39
|
*/
|
|
40
40
|
export declare function checkDictionary(constraints: DictionaryConstraints): Optional<Trace>;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Tells whether a dictionary shape narrows an inherited one.
|
|
43
43
|
*
|
|
44
44
|
* Tests the override relation without building the merged shape, so that an incompatible extension is told apart from
|
|
45
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
|
|
47
|
-
* consistent set of merged constraints.
|
|
46
|
+
* length bound wider, adds no language range the inherited shape omits, drops no required one, keeps its per-tag
|
|
47
|
+
* arity, and yields a consistent set of merged constraints, so that the merged shape still admits some value.
|
|
48
48
|
*
|
|
49
49
|
* @param target The overriding shape
|
|
50
50
|
* @param source The inherited shape
|
|
@@ -56,8 +56,8 @@ export declare function narrowsDictionary(target: DictionaryShape, source: Dicti
|
|
|
56
56
|
* Merges a dictionary shape with an inherited one.
|
|
57
57
|
*
|
|
58
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,
|
|
60
|
-
* from whichever shape states it.
|
|
59
|
+
* overriding ones: length bounds accumulate, the accepted language ranges intersect, the required ones add up, and
|
|
60
|
+
* `uniqueLang` carries through from whichever shape states it, so that an arity the parent fixes is never lost.
|
|
61
61
|
*
|
|
62
62
|
* @param target The overriding shape
|
|
63
63
|
* @param source The inherited shape
|
|
@@ -1 +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;
|
|
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;AAGhD,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,CAsBnF;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"}
|
|
@@ -50,19 +50,25 @@ export function assemble(constraints) {
|
|
|
50
50
|
* @returns A trace of the inconsistencies found, or `undefined` where the constraints admit at least one value
|
|
51
51
|
*/
|
|
52
52
|
export function checkDictionary(constraints) {
|
|
53
|
-
return test(({ minLength, maxLength }) => {
|
|
53
|
+
return all(test(({ minLength, maxLength }) => {
|
|
54
54
|
return minLength === undefined || maxLength === undefined || minLength <= maxLength || [
|
|
55
55
|
`{minLength/maxLength} inconsistent bounds <${minLength}> > <${maxLength}>`
|
|
56
56
|
];
|
|
57
|
-
})(
|
|
57
|
+
}), test(({ languageIn: accepted = [], hasLanguage: required = [] }) => {
|
|
58
|
+
const unmatched = accepted.length === 0 ? []
|
|
59
|
+
: required.filter(range => !accepted.some(admitted => overlaps(range, admitted)));
|
|
60
|
+
return unmatched.length === 0 || [
|
|
61
|
+
`{hasLanguage/languageIn} required ranges <${unmatched}> not matched by any accepted range`
|
|
62
|
+
];
|
|
63
|
+
}))(constraints);
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
*
|
|
66
|
+
* Tells whether a dictionary shape narrows an inherited one.
|
|
61
67
|
*
|
|
62
68
|
* Tests the override relation without building the merged shape, so that an incompatible extension is told apart from
|
|
63
69
|
* 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
|
|
65
|
-
* consistent set of merged constraints.
|
|
70
|
+
* length bound wider, adds no language range the inherited shape omits, drops no required one, keeps its per-tag
|
|
71
|
+
* arity, and yields a consistent set of merged constraints, so that the merged shape still admits some value.
|
|
66
72
|
*
|
|
67
73
|
* @param target The overriding shape
|
|
68
74
|
* @param source The inherited shape
|
|
@@ -76,8 +82,8 @@ export function narrowsDictionary(target, source) {
|
|
|
76
82
|
* Merges a dictionary shape with an inherited one.
|
|
77
83
|
*
|
|
78
84
|
* 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,
|
|
80
|
-
* from whichever shape states it.
|
|
85
|
+
* overriding ones: length bounds accumulate, the accepted language ranges intersect, the required ones add up, and
|
|
86
|
+
* `uniqueLang` carries through from whichever shape states it, so that an arity the parent fixes is never lost.
|
|
81
87
|
*
|
|
82
88
|
* @param target The overriding shape
|
|
83
89
|
* @param source The inherited shape
|
|
@@ -105,7 +111,7 @@ export function mergeDictionary(target, source) {
|
|
|
105
111
|
* @returns A trace of the obstacles to the override, or `undefined` where `target` narrows `source`
|
|
106
112
|
*/
|
|
107
113
|
function narrows(target, source, merged) {
|
|
108
|
-
const { languageIn: accepted } = source;
|
|
114
|
+
const { languageIn: accepted, hasLanguage: required = [] } = source;
|
|
109
115
|
return all(test(({ uniqueLang }) => {
|
|
110
116
|
return uniqueLang !== false || source.uniqueLang !== true || [
|
|
111
117
|
`{uniqueLang} dropped unique language constraint`
|
|
@@ -121,11 +127,16 @@ function narrows(target, source, merged) {
|
|
|
121
127
|
}), test(({ languageIn }) => {
|
|
122
128
|
// a range the parent omits would be intersected away, leaving the state wider than the shape admits,
|
|
123
129
|
// so a widened set is rejected outright as with the bounds
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
const unexpected = languageIn === undefined || accepted === undefined ? []
|
|
131
|
+
: languageIn.filter(v => !accepted.includes(v));
|
|
132
|
+
return unexpected.length === 0 || [
|
|
133
|
+
`{languageIn} unexpected ranges [${unexpected}]`
|
|
134
|
+
];
|
|
135
|
+
}), test(({ hasLanguage }) => {
|
|
136
|
+
const missing = hasLanguage === undefined ? [] : required.filter(v => !hasLanguage.includes(v));
|
|
137
|
+
return missing.length === 0 || [
|
|
138
|
+
`{hasLanguage} missing required ranges [${missing}]`
|
|
139
|
+
];
|
|
129
140
|
}), () => checkDictionary(merged) // post-merge constraint consistency
|
|
130
141
|
)(target);
|
|
131
142
|
}
|
|
@@ -138,7 +149,7 @@ function narrows(target, source, merged) {
|
|
|
138
149
|
* @returns The merged constraints, as they stand before they are checked for consistency
|
|
139
150
|
*/
|
|
140
151
|
function merge(target, source) {
|
|
141
|
-
const { languageIn: accepted } = source;
|
|
152
|
+
const { languageIn: accepted, hasLanguage: required } = source;
|
|
142
153
|
return {
|
|
143
154
|
// conjunctive: uniqueLang — added but never dropped
|
|
144
155
|
uniqueLang: target.uniqueLang ?? source.uniqueLang,
|
|
@@ -148,7 +159,20 @@ function merge(target, source) {
|
|
|
148
159
|
// conjunctive: languageIn — intersection
|
|
149
160
|
languageIn: target.languageIn !== undefined && accepted !== undefined
|
|
150
161
|
? target.languageIn.filter(v => accepted.includes(v))
|
|
151
|
-
: target.languageIn ?? accepted
|
|
162
|
+
: target.languageIn ?? accepted,
|
|
163
|
+
// conjunctive: hasLanguage — union
|
|
164
|
+
hasLanguage: target.hasLanguage !== undefined && required !== undefined
|
|
165
|
+
? [...new Set([...target.hasLanguage, ...required])]
|
|
166
|
+
: target.hasLanguage ?? required
|
|
152
167
|
};
|
|
153
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Tells whether two basic language ranges may be matched by a single tag.
|
|
171
|
+
*
|
|
172
|
+
* Either range may be the wildcard or a subtag prefix of the other, so `en` overlaps `en-US` but `de` misses `deu`.
|
|
173
|
+
*/
|
|
174
|
+
function overlaps(x, y) {
|
|
175
|
+
const [a, b] = [x.toLowerCase(), y.toLowerCase()];
|
|
176
|
+
return a === "*" || b === "*" || a === b || a.startsWith(`${b}-`) || b.startsWith(`${a}-`);
|
|
177
|
+
}
|
|
154
178
|
//# sourceMappingURL=assembler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/dictionary/assembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/dictionary/assembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAeH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAc,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAgC,WAAkC;IAIzF,MAAM,KAAK,GAAG,SAAS,CAAC;QAEvB,IAAI,EAAE,Y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AQ,KAAK,SAAS;YACpE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACrD,CAAC,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ;QAEhC,mCAAmC;QAEnC,WAAW,EAAE,MAAM,CAAC,WAAW,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS;YACtE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;YACpD,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,QAAQ;KAEjC,CAAC;AAEH,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,CAAW,EAAE,CAAW;IAEzC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAElD,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE5F,CAAC"}
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
* whose value varies by language takes one member rather than one per language.
|
|
9
9
|
*
|
|
10
10
|
* > [!IMPORTANT]
|
|
11
|
-
* > Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value
|
|
12
|
-
* >
|
|
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.
|
|
13
14
|
*
|
|
14
15
|
* How many strings a tag carries is fixed by {@link DictionaryConstraints.uniqueLang | uniqueLang}: a unique-tagged
|
|
15
16
|
* shape gives every tag a single string, and any other gives every tag an array. A member ranging over a dictionary
|
|
16
|
-
* carries the map whole, never in an array, whatever cardinality it states.
|
|
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.
|
|
17
19
|
*
|
|
18
20
|
* The tag-keyed map is the form a value is stored and submitted in. A localised member additionally *coalesces* under
|
|
19
21
|
* language negotiation when retrieved, at the same per-tag arity: the value may be retrieved as the negotiated content
|
|
@@ -78,7 +80,8 @@ import type { TagRange } from "@grafctory/core/language";
|
|
|
78
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
|
|
79
81
|
* right, so a member carries it whole, never in an array, whatever the bounds of the enclosing {@link value!Range}
|
|
80
82
|
* admit: those bounds count the values of the other branches of a two-natured range, which a resource carries in
|
|
81
|
-
* place of the map and never beside it.
|
|
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.
|
|
82
85
|
*
|
|
83
86
|
* **Negotiation**
|
|
84
87
|
*
|
|
@@ -93,17 +96,19 @@ import type { TagRange } from "@grafctory/core/language";
|
|
|
93
96
|
* Where a {@link resource!ResourceShape} extends the shapes it lists as `parents`, localised members are merged
|
|
94
97
|
* according to the following rules. The *child* is the extending shape; the *parent* is the inherited one.
|
|
95
98
|
*
|
|
96
|
-
* | Field
|
|
97
|
-
* |
|
|
98
|
-
* | `kind`
|
|
99
|
-
* | `minLength`
|
|
100
|
-
* | `maxLength`
|
|
101
|
-
* | `languageIn`
|
|
102
|
-
* | `
|
|
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 |
|
|
103
107
|
*
|
|
104
108
|
* **Cross-field validation**
|
|
105
109
|
*
|
|
106
110
|
* - merged `minLength` must be ≤ merged `maxLength`
|
|
111
|
+
* - every merged `hasLanguage` range must be matchable by some tag the merged `languageIn` admits
|
|
107
112
|
*
|
|
108
113
|
* @see {@link https://www.w3.org/TR/json-ld11/#language-maps JSON-LD 1.1 § 9.8 Language Maps}
|
|
109
114
|
* @see {@link https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string RDF 1.1 § 3.3 Literals}
|
|
@@ -119,8 +124,8 @@ export type DictionaryShape = DictionaryConstraints & {
|
|
|
119
124
|
/**
|
|
120
125
|
* Constraints accepted by the {@link dictionary} shape factory.
|
|
121
126
|
*
|
|
122
|
-
* Bounds the content a tag may carry
|
|
123
|
-
* string separately, so a value is held to them whatever language it is stated in.
|
|
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.
|
|
124
129
|
*
|
|
125
130
|
* @see {@link https://www.w3.org/TR/shacl/#core-components-string SHACL § 4.4 String-based Constraint Components}
|
|
126
131
|
*/
|
|
@@ -176,6 +181,27 @@ export type DictionaryConstraints = {
|
|
|
176
181
|
* @see {@link https://www.rfc-editor.org/rfc/rfc4647.html RFC 4647 - Matching of Language Tags}
|
|
177
182
|
*/
|
|
178
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[];
|
|
179
205
|
};
|
|
180
206
|
/**
|
|
181
207
|
* Creates a dictionary shape.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dictionary/index.ts"],"names":[],"mappings":"AAgBA
|
|
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"}
|