@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
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* @module
|
|
25
25
|
*/
|
|
26
26
|
import { isArray, isIdentifier, isNumber, isObject, isString, opt as fold } from "@grafctory/core";
|
|
27
|
-
import { isTagRange } from "@grafctory/core/language";
|
|
27
|
+
import { isTag, isTagRange } from "@grafctory/core/language";
|
|
28
28
|
import { all, array, fail, object } from "@grafctory/core/trace";
|
|
29
29
|
import { isReference, isVacuous } from "@grafctory/qest/state";
|
|
30
30
|
import { decodeProbe, isAggregate, isAtomic, isBinding, isBranch, isSelector, isTemplate } from "@grafctory/qest/model";
|
|
@@ -84,7 +84,7 @@ export function validateResource(values, shape, { scope = "state", entry, depth
|
|
|
84
84
|
* Validates the values a member carries against its range and cardinality.
|
|
85
85
|
*/
|
|
86
86
|
function contents(value, member) {
|
|
87
|
-
const { range: {
|
|
87
|
+
const { range: { maxCount, shape: range }, foreign, captive } = member;
|
|
88
88
|
// a foreign member is written by the resources it points at, not by the one exposing it
|
|
89
89
|
if (foreign) {
|
|
90
90
|
return value !== undefined ? ["unexpected foreign member"] : undefined;
|
|
@@ -97,17 +97,16 @@ export function validateResource(values, shape, { scope = "state", entry, depth
|
|
|
97
97
|
// a localised value is a value set in its own right, holding its strings per tag at the arity its own shape
|
|
98
98
|
// states: a member carries it whole, never in an array and never beside the other values, and the bounds
|
|
99
99
|
// stated for the member count the other values alone
|
|
100
|
-
const present = value === undefined || isArray(value, [])
|
|
100
|
+
const present = value === undefined || isArray(value, [])
|
|
101
|
+
|| nesting && isVacuous(value)
|
|
102
|
+
|| isBlank(value, branches) ? undefined : value;
|
|
101
103
|
const carried = (present === undefined ? [] : isArray(present) ? present : [present])
|
|
102
104
|
.filter(element => !(nesting && isVacuous(element)));
|
|
103
|
-
const whole = isLocalised(present, branches, scope);
|
|
104
|
-
const bounds = whole ? undefined : all((minCount !== undefined && carried.length < minCount)
|
|
105
|
-
&& fail([`{minCount} expected at least <${minCount}> value(s)`]), (maxCount !== undefined && carried.length > maxCount)
|
|
106
|
-
&& fail([`{maxCount} expected at most <${maxCount}> value(s)`]))(undefined);
|
|
107
105
|
// the arity is reported first, then the values, then the cardinality
|
|
108
|
-
return (
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
return isLocalised(present, branches, scope) ? elements(carried, resolved, captive)
|
|
107
|
+
: arity(present, maxCount, branches, scope)
|
|
108
|
+
?? elements(carried, resolved, captive)
|
|
109
|
+
?? counts(carried.length, member);
|
|
111
110
|
}
|
|
112
111
|
/**
|
|
113
112
|
* Validates the elements a member carries, expanding the ones it holds captive.
|
|
@@ -211,19 +210,15 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
211
210
|
* Validates a template against the shape of the resources it asks for.
|
|
212
211
|
*/
|
|
213
212
|
function template(value, shape, depth) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
? slot(asked, shape.members[name], depth)
|
|
224
|
-
: isAtomic(asked) ? undefined : ["expected <Atomic> placeholder"], // the id/type members
|
|
225
|
-
// the id/type members
|
|
226
|
-
trace => [{ [name]: trace }])))(undefined);
|
|
213
|
+
return !isObject(value) ? ["expected <template> value"]
|
|
214
|
+
: exhausted(depth) ? ["exceeded maximum nesting depth"]
|
|
215
|
+
: all(...Object.entries(value).map(([name, asked]) => () => fold(!isIdentifier(name) ? ["expected property identifier"]
|
|
216
|
+
: !Object.hasOwn(shape.members, name) ? ["unknown property path"]
|
|
217
|
+
: shape.members[name].kind === "property"
|
|
218
|
+
? slot(asked, shape.members[name], depth)
|
|
219
|
+
: isAtomic(asked) ? undefined : ["expected <Atomic> placeholder"], // the id/type members
|
|
220
|
+
// the id/type members
|
|
221
|
+
trace => [{ [name]: trace }])))(undefined);
|
|
227
222
|
}
|
|
228
223
|
/**
|
|
229
224
|
* Validates what a slot asks for, retrieval keys and collection constraints together.
|
|
@@ -273,12 +268,8 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
273
268
|
* @param retrieval Validates what the placeholder asks for, once its constraints are set apart
|
|
274
269
|
*/
|
|
275
270
|
function unconstrained(value, refused, retrieval) {
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
const contents = isObject(value)
|
|
279
|
-
? Object.fromEntries(entries.filter(([key]) => !isSelector(key)))
|
|
280
|
-
: value;
|
|
281
|
-
return all(() => retrieval(contents), ...constraints.map(([selector]) => () => [{ [selector]: [refused] }]))(undefined);
|
|
271
|
+
const constraints = isObject(value) ? Object.keys(value).filter(key => isSelector(key)) : [];
|
|
272
|
+
return all(() => retrieval(retrieving(value)), ...constraints.map(selector => () => [{ [selector]: [refused] }]))(undefined);
|
|
282
273
|
}
|
|
283
274
|
/**
|
|
284
275
|
* Validates a placeholder standing for the value a branch admits.
|
|
@@ -310,17 +301,16 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
310
301
|
const [branch] = branches;
|
|
311
302
|
// with no branch reaching a resource, an object keyed by anything but branch indices can only be a locale
|
|
312
303
|
const localised = branches.every(alternative => getShapeTarget(alternative) === undefined)
|
|
313
|
-
|
|
314
|
-
: undefined;
|
|
304
|
+
&& branches.some(alternative => alternative.kind === "dictionary");
|
|
315
305
|
return branches.length > 1
|
|
316
306
|
// the atomic placeholder asks for the value as it stands, so it reaches every alternative coming back
|
|
317
307
|
// as one and needs no branch of its own
|
|
318
308
|
? isAtomic(value)
|
|
319
309
|
? branches.some(alternative => alternative.kind !== "resource") ? undefined
|
|
320
310
|
: ["{branches} no branch comes back as a value"]
|
|
321
|
-
: localised
|
|
311
|
+
: localised && !isObject(value, (_, key) => isBranch(key)) ? locale(value)
|
|
322
312
|
: indexed(value, branches, depth)
|
|
323
|
-
: branch.kind === "dictionary" ? locale(value
|
|
313
|
+
: branch.kind === "dictionary" ? locale(value)
|
|
324
314
|
: placeholder(value, branch, depth);
|
|
325
315
|
}
|
|
326
316
|
/**
|
|
@@ -349,7 +339,7 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
349
339
|
isTemplateModel(contents, branches) && isObject(contents)
|
|
350
340
|
? all(...Object.entries(contents).map(([name, nested]) => () => member(name, nested)))(undefined)
|
|
351
341
|
: branches.some(branch => branch.kind === "dictionary"
|
|
352
|
-
? locale(contents
|
|
342
|
+
? locale(contents) === undefined
|
|
353
343
|
: placeholder(contents, branch, depth) === undefined) ? undefined : ["{branches} no branch admits the placeholder"]);
|
|
354
344
|
}
|
|
355
345
|
/**
|
|
@@ -375,20 +365,13 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
375
365
|
* a matched tag carries.
|
|
376
366
|
*
|
|
377
367
|
* @param value The placeholder the slot states
|
|
378
|
-
* @param shape The localised shape the slot reaches
|
|
379
368
|
*/
|
|
380
|
-
function locale(value
|
|
369
|
+
function locale(value) {
|
|
381
370
|
return isAtomic(value) ? undefined
|
|
382
371
|
: !isObject(value) ? ["{kind} expected <Atomic> or <Locale> placeholder"]
|
|
383
|
-
:
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
* Validates the tags a localised slot wants, each asking for the value a matched tag carries.
|
|
387
|
-
*/
|
|
388
|
-
function tagged(value, {}) {
|
|
389
|
-
return object(([range, asked]) => !isTagRange(range) ? [{ [range]: ["invalid tag range"] }]
|
|
390
|
-
: isAtomic(asked) ? undefined
|
|
391
|
-
: [{ [range]: ["{type} expected <Atomic> value"] }])(value);
|
|
372
|
+
: object(([range, asked]) => !isTagRange(range) ? [{ [range]: ["invalid tag range"] }]
|
|
373
|
+
: isAtomic(asked) ? undefined
|
|
374
|
+
: [{ [range]: ["{type} expected <Atomic> value"] }])(value);
|
|
392
375
|
}
|
|
393
376
|
/**
|
|
394
377
|
* Identifies the grouping keys of a collection.
|
|
@@ -446,19 +429,21 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
446
429
|
if (branches.length > 1) {
|
|
447
430
|
return model(value, member.range, depth);
|
|
448
431
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
:
|
|
432
|
+
else {
|
|
433
|
+
switch (branch.kind) {
|
|
434
|
+
case "reference":
|
|
435
|
+
case "resource": {
|
|
436
|
+
const next = step(depth);
|
|
437
|
+
const target = branch.kind === "reference" ? eager(branch.target) : branch;
|
|
438
|
+
// a template descends into the resource, while a column resolves against the item as it stands,
|
|
439
|
+
// so an empty path leaves a link a link, asked for as the identifier naming its target
|
|
440
|
+
return isAtomic(value) ? placeholder(value, branch, depth)
|
|
441
|
+
: Object.keys(value).every(isIdentifier) ? template(value, target, next)
|
|
442
|
+
: projection(value, branch, next);
|
|
443
|
+
}
|
|
444
|
+
default:
|
|
445
|
+
return placeholder(value, branch, depth);
|
|
459
446
|
}
|
|
460
|
-
default:
|
|
461
|
-
return placeholder(value, branch, depth);
|
|
462
447
|
}
|
|
463
448
|
}
|
|
464
449
|
/**
|
|
@@ -472,42 +457,38 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
472
457
|
* carries its own constraints as any other collection does.
|
|
473
458
|
*/
|
|
474
459
|
function projection(value, shape, depth) {
|
|
475
|
-
|
|
476
|
-
return ["expected <projection> value"];
|
|
477
|
-
}
|
|
478
|
-
if (exhausted(depth)) {
|
|
479
|
-
return ["exceeded maximum nesting depth"];
|
|
480
|
-
}
|
|
481
|
-
const probes = new Map(Object.keys(value)
|
|
460
|
+
const probes = new Map((isObject(value) ? Object.keys(value) : [])
|
|
482
461
|
.filter(isBinding)
|
|
483
462
|
.map(binding => [binding, decodeProbe(binding)]));
|
|
484
463
|
// the identifiers a column may not bind twice, settled once for the whole table
|
|
485
464
|
const shared = new Set([...probes.values()]
|
|
486
465
|
.map(probe => probe.target)
|
|
487
466
|
.filter((target, index, targets) => targets.indexOf(target) !== index));
|
|
488
|
-
return
|
|
467
|
+
return !isObject(value) ? ["expected <projection> value"]
|
|
468
|
+
: exhausted(depth) ? ["exceeded maximum nesting depth"]
|
|
469
|
+
: all(...Object.entries(value).map(([binding, asked]) => () => fold(column(binding, asked), trace => [{ [binding]: trace }])))(undefined);
|
|
489
470
|
function column(binding, asked) {
|
|
490
471
|
const probe = probes.get(binding);
|
|
491
472
|
if (probe === undefined) {
|
|
492
473
|
return ["expected projection binding"];
|
|
493
474
|
}
|
|
494
|
-
if (depth !== undefined && probe.path.length > depth) {
|
|
475
|
+
else if (depth !== undefined && probe.path.length > depth) {
|
|
495
476
|
return ["exceeded maximum path length"];
|
|
496
477
|
}
|
|
497
|
-
if (plain && probe
|
|
478
|
+
else if (plain && aggregate(probe)) {
|
|
498
479
|
return ["disabled aggregate transforms"];
|
|
499
480
|
}
|
|
500
|
-
if (shared.has(probe.target)) {
|
|
481
|
+
else if (shared.has(probe.target)) {
|
|
501
482
|
return [`duplicate projection identifier <${probe.target}>`];
|
|
502
483
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
484
|
+
else {
|
|
485
|
+
const range = effective(shape, probe);
|
|
486
|
+
// a column holds one value per row, so it neither asks for a collection nor narrows one; a collection
|
|
487
|
+
// reached below it, through a nested template, carries its own constraints as any other does
|
|
488
|
+
return isString(range) ? [range] // the path the shape cannot resolve
|
|
489
|
+
: isArray(asked) ? ["unexpected array in projection value"]
|
|
490
|
+
: unconstrained(asked, "unexpected constraint in a projection column", contents => model(contents, range, depth));
|
|
491
|
+
}
|
|
511
492
|
}
|
|
512
493
|
}
|
|
513
494
|
/**
|
|
@@ -519,13 +500,9 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
519
500
|
function filters(constraints, member, depth, keys) {
|
|
520
501
|
// a selector resolves through the values the collection holds, one step below the collection itself
|
|
521
502
|
const next = step(depth);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
if (exhausted(next)) {
|
|
526
|
-
return ["exceeded maximum nesting depth"];
|
|
527
|
-
}
|
|
528
|
-
return all(...constraints.map(([selector, asked]) => () => fold(operator(selector, asked), trace => [{ [selector]: trace }])))(undefined);
|
|
503
|
+
return constraints.length === 0 ? undefined // a collection stated without constraints
|
|
504
|
+
: exhausted(next) ? ["exceeded maximum nesting depth"]
|
|
505
|
+
: all(...constraints.map(([selector, asked]) => () => fold(operator(selector, asked), trace => [{ [selector]: trace }])))(undefined);
|
|
529
506
|
function operator(selector, asked) {
|
|
530
507
|
if (!isSelector(selector)) {
|
|
531
508
|
return ["expected constraint operator"];
|
|
@@ -534,13 +511,19 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
534
511
|
if (next !== undefined && probe.path.length > next) {
|
|
535
512
|
return ["exceeded maximum path length"];
|
|
536
513
|
}
|
|
537
|
-
if (plain && probe
|
|
514
|
+
else if (plain && aggregate(probe)) {
|
|
538
515
|
return ["disabled aggregate transforms"];
|
|
539
516
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
return [range]
|
|
543
|
-
|
|
517
|
+
else {
|
|
518
|
+
const range = effective(member.range.shape, probe);
|
|
519
|
+
return isString(range) ? [range] // the path the shape cannot resolve
|
|
520
|
+
: operand(asked, probe, range);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Validates the operand a constraint states against what its operator tests.
|
|
525
|
+
*/
|
|
526
|
+
function operand(asked, probe, range) {
|
|
544
527
|
const branches = getShapeBranches(range.shape);
|
|
545
528
|
// a grouping key holds one value per group, however many the member it reaches holds per item
|
|
546
529
|
const single = range.maxCount === 1 || keyed(probe, keys);
|
|
@@ -572,47 +555,35 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
572
555
|
* Validates a relational bound, which singles out the branch it filters against.
|
|
573
556
|
*/
|
|
574
557
|
function bound(value, branches) {
|
|
575
|
-
if (branches.length === 0) {
|
|
576
|
-
return undefined;
|
|
577
|
-
} // nothing to filter against, the bound is immaterial
|
|
578
|
-
if (branches.length > 1) {
|
|
579
|
-
return verdict(branches.filter(branch => checkBound(value, branch) === undefined), "bound");
|
|
580
|
-
}
|
|
581
558
|
const [branch] = branches;
|
|
582
|
-
return
|
|
559
|
+
return branches.length === 0 ? undefined // nothing to filter against, the bound is immaterial
|
|
560
|
+
: branches.length > 1 ? verdict(branches.filter(branch => checkBound(value, branch) === undefined), "bound")
|
|
561
|
+
: checkBound(value, branch);
|
|
583
562
|
}
|
|
584
563
|
/**
|
|
585
564
|
* Validates a text search, which filters every textual branch at once rather than singling one out.
|
|
586
565
|
*/
|
|
587
566
|
function keywords(value, branches) {
|
|
588
|
-
if (branches.length === 0) {
|
|
589
|
-
return undefined;
|
|
590
|
-
} // nothing to search, the string is immaterial
|
|
591
|
-
if (branches.length > 1) {
|
|
592
|
-
return branches.some(branch => keywords(value, [branch]) === undefined) ? undefined
|
|
593
|
-
: ["{branches} no branch admits the search"];
|
|
594
|
-
}
|
|
595
567
|
const [branch] = branches;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
568
|
+
return branches.length === 0 ? undefined // nothing to search, the string is immaterial
|
|
569
|
+
: branches.length > 1 ? branches.some(branch => keywords(value, [branch]) === undefined) ? undefined
|
|
570
|
+
: ["{branches} no branch admits the search"]
|
|
571
|
+
: branch.kind === "string" || branch.kind === "dictionary"
|
|
572
|
+
? isString(value) ? undefined : ["expected string value"]
|
|
573
|
+
: [`unsupported constraint for <${branch.kind}> value`];
|
|
603
574
|
}
|
|
604
575
|
/**
|
|
605
576
|
* Validates the options a membership filter tests against.
|
|
606
577
|
*/
|
|
607
578
|
function options(value, branches) {
|
|
579
|
+
const [branch] = branches;
|
|
608
580
|
if (branches.length === 0) {
|
|
609
|
-
return undefined;
|
|
610
|
-
}
|
|
611
|
-
if (branches.length > 1) {
|
|
581
|
+
return undefined; // nothing to match, the options are immaterial
|
|
582
|
+
}
|
|
583
|
+
else if (branches.length > 1) {
|
|
612
584
|
return isArray(value) ? array(single)(value) : single(value);
|
|
613
585
|
}
|
|
614
|
-
|
|
615
|
-
if (branch.kind === "dictionary") {
|
|
586
|
+
else if (branch.kind === "dictionary") {
|
|
616
587
|
// a tag map, or a plain string standing for the strings the map carries, stated singly or as a set;
|
|
617
588
|
// the two forms are never mixed within one set
|
|
618
589
|
return isArray(value, isString) ? undefined
|
|
@@ -621,9 +592,11 @@ export function validateTemplate(values, shape, { plain, depth, limit } = {}) {
|
|
|
621
592
|
? ["mixed plain and tagged options"]
|
|
622
593
|
: [`unsupported constraint for <${branch.kind}> value`];
|
|
623
594
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
595
|
+
else {
|
|
596
|
+
return isArray(value)
|
|
597
|
+
? array((value) => checkOption(value, branch))(value)
|
|
598
|
+
: checkOption(value, branch);
|
|
599
|
+
}
|
|
627
600
|
/**
|
|
628
601
|
* Reports whether an option singles out one branch; an option stated as nothing at all is typeless and exempt.
|
|
629
602
|
*/
|
|
@@ -719,20 +692,20 @@ export function validateResult(values, { shape, model, entry }) {
|
|
|
719
692
|
* Validates the values a member came back with against its range and the template narrowing it.
|
|
720
693
|
*/
|
|
721
694
|
function contents(value, member, requested) {
|
|
722
|
-
const { range: { minCount,
|
|
695
|
+
const { range: { minCount, shape: range } } = member;
|
|
723
696
|
const branches = getShapeBranches(range);
|
|
724
697
|
const present = value === undefined || isArray(value, []) ? undefined : value;
|
|
698
|
+
// a localised member asked for by the atomic placeholder comes back as the text negotiation settled on rather
|
|
699
|
+
// than as the map, at the arity the shape states per tag; the tags are asked for as a map of language ranges
|
|
700
|
+
const negotiated = isAtomic(requested)
|
|
701
|
+
? branches.find((branch) => branch.kind === "dictionary")
|
|
702
|
+
: undefined;
|
|
725
703
|
if (present === undefined) {
|
|
726
704
|
return minCount !== undefined && minCount >= 1 && exhaustive(requested, branches)
|
|
727
705
|
? [`{minCount} expected at least <${minCount}> value(s)`]
|
|
728
706
|
: undefined;
|
|
729
707
|
}
|
|
730
|
-
|
|
731
|
-
// than as the map, at the arity the shape states per tag
|
|
732
|
-
const negotiated = branches
|
|
733
|
-
.flatMap(branch => branch.kind === "dictionary" ? [branch] : [])
|
|
734
|
-
.find(branch => plain(requested, branch));
|
|
735
|
-
if (negotiated !== undefined) {
|
|
708
|
+
else if (negotiated !== undefined) {
|
|
736
709
|
// the text folds into the values of the other variants, so a value is admitted where either admits it
|
|
737
710
|
const others = branches.filter(branch => branch !== negotiated);
|
|
738
711
|
const coalesced = text(present, negotiated);
|
|
@@ -740,12 +713,14 @@ export function validateResult(values, { shape, model, entry }) {
|
|
|
740
713
|
: valued(present, member, others, requested) === undefined ? undefined
|
|
741
714
|
: coalesced;
|
|
742
715
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
716
|
+
else {
|
|
717
|
+
// a localised member comes back as it is carried: one map, whole and never in an array, whatever bounds it
|
|
718
|
+
// states of the other values, and the bounds count those other values alone
|
|
719
|
+
// a map is matched against the range as it stands, the template narrowing the other values alone
|
|
720
|
+
return isLocalised(present, branches, "state")
|
|
721
|
+
? validateShape([present], eager(range))
|
|
722
|
+
: valued(present, member, branches, requested);
|
|
723
|
+
}
|
|
749
724
|
}
|
|
750
725
|
/**
|
|
751
726
|
* Validates the values a member came back with, other than a localised map, against the branches they may belong to.
|
|
@@ -763,24 +738,12 @@ export function validateResult(values, { shape, model, entry }) {
|
|
|
763
738
|
* holding another, and the bound then says nothing about what the resource holds.
|
|
764
739
|
*/
|
|
765
740
|
function exhaustive(requested, branches) {
|
|
766
|
-
const asked =
|
|
767
|
-
? Object.fromEntries(Object.entries(requested).filter(([key]) => !isSelector(key)))
|
|
768
|
-
: requested;
|
|
741
|
+
const asked = retrieving(requested);
|
|
769
742
|
const keyed = isObject(asked) && Object.keys(asked).length > 0 && Object.keys(asked).every(isBranch);
|
|
770
743
|
const alternatives = keyed ? Object.values(asked) : [asked];
|
|
771
744
|
const reached = new Set(alternatives.flatMap(alternative => getModelBranches(alternative, branches) ?? []));
|
|
772
745
|
return branches.length === 1 || reached.size === branches.length;
|
|
773
746
|
}
|
|
774
|
-
/**
|
|
775
|
-
* Reports whether a placeholder asked a localised shape for the text negotiation settles on.
|
|
776
|
-
*
|
|
777
|
-
* The atomic placeholder stands for that text, which is how a localised member is asked for where the tags are not
|
|
778
|
-
* wanted; the tags are stated as a map of language ranges instead. The arity the text comes back at follows the
|
|
779
|
-
* shape rather than the placeholder.
|
|
780
|
-
*/
|
|
781
|
-
function plain(requested, {}) {
|
|
782
|
-
return isAtomic(requested);
|
|
783
|
-
}
|
|
784
747
|
/**
|
|
785
748
|
* Validates the text a localised member came back with, where the atomic placeholder asked for it.
|
|
786
749
|
*
|
|
@@ -828,14 +791,10 @@ export function validateResult(values, { shape, model, entry }) {
|
|
|
828
791
|
const fields = isObject(head) ? head : {};
|
|
829
792
|
const keys = Object.keys(fields);
|
|
830
793
|
const indexed = keys.length > 0 && keys.some(key => !isIdentifier(key));
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
}
|
|
836
|
-
return verdict(branches.filter(admits => keys.some(key => fits(value, admits, fields[key]))), "value");
|
|
837
|
-
}
|
|
838
|
-
return verdict(branches.filter(admits => fits(value, admits, requested)), "value");
|
|
794
|
+
const malformed = keys.filter(key => !isBranch(key));
|
|
795
|
+
return !indexed ? verdict(branches.filter(admits => fits(value, admits, requested)), "value")
|
|
796
|
+
: malformed.length > 0 ? all(...malformed.map(key => () => [{ [key]: ["expected a branch key"] }]))(undefined)
|
|
797
|
+
: verdict(branches.filter(admits => keys.some(key => fits(value, admits, fields[key]))), "value");
|
|
839
798
|
}
|
|
840
799
|
/**
|
|
841
800
|
* Reports whether a branch admits a value under the template narrowing it.
|
|
@@ -855,14 +814,6 @@ export function validateResult(values, { shape, model, entry }) {
|
|
|
855
814
|
&& validateShape([value], admits) === undefined;
|
|
856
815
|
}
|
|
857
816
|
}
|
|
858
|
-
/**
|
|
859
|
-
* Reports the cardinality bounds the values a member came back with break.
|
|
860
|
-
*/
|
|
861
|
-
function counts(count, { range: { minCount, maxCount } }) {
|
|
862
|
-
return all((minCount !== undefined && count < minCount)
|
|
863
|
-
&& fail([`{minCount} expected at least <${minCount}> value(s)`]), (maxCount !== undefined && count > maxCount)
|
|
864
|
-
&& fail([`{maxCount} expected at most <${maxCount}> value(s)`]))(undefined);
|
|
865
|
-
}
|
|
866
817
|
/**
|
|
867
818
|
* Resolves the template a nested resource was requested through.
|
|
868
819
|
*
|
|
@@ -871,9 +822,7 @@ export function validateResult(values, { shape, model, entry }) {
|
|
|
871
822
|
* resource comes back with is unasked for.
|
|
872
823
|
*/
|
|
873
824
|
function nested(requested) {
|
|
874
|
-
const element =
|
|
875
|
-
? Object.fromEntries(Object.entries(requested).filter(([key]) => !isSelector(key)))
|
|
876
|
-
: requested;
|
|
825
|
+
const element = retrieving(requested);
|
|
877
826
|
return isTemplate(element) ? element : {};
|
|
878
827
|
}
|
|
879
828
|
}
|
|
@@ -935,6 +884,24 @@ function arity(present, maxCount, branches, scope) {
|
|
|
935
884
|
? [scalar ? "{kind} expected a single value" : "{kind} expected an array of values"]
|
|
936
885
|
: undefined;
|
|
937
886
|
}
|
|
887
|
+
/**
|
|
888
|
+
* Reports the cardinality bounds of a member that the count of the values it carries breaks.
|
|
889
|
+
*/
|
|
890
|
+
function counts(count, { range: { minCount, maxCount } }) {
|
|
891
|
+
return all((minCount !== undefined && count < minCount)
|
|
892
|
+
&& fail([`{minCount} expected at least <${minCount}> value(s)`]), (maxCount !== undefined && count > maxCount)
|
|
893
|
+
&& fail([`{maxCount} expected at most <${maxCount}> value(s)`]))(undefined);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Sets the constraints a slot states apart from the keys retrieving its values.
|
|
897
|
+
*
|
|
898
|
+
* @returns The object `value` less its constraint keys, or `value` itself where it is not an object
|
|
899
|
+
*/
|
|
900
|
+
function retrieving(value) {
|
|
901
|
+
return isObject(value)
|
|
902
|
+
? Object.fromEntries(Object.entries(value).filter(([key]) => !isSelector(key)))
|
|
903
|
+
: value;
|
|
904
|
+
}
|
|
938
905
|
/**
|
|
939
906
|
* Holds the value a marker states to the single absolute IRI it must be.
|
|
940
907
|
*/
|
|
@@ -971,6 +938,21 @@ function exhausted(depth) {
|
|
|
971
938
|
function isLocalised(value, branches, scope) {
|
|
972
939
|
return !isArray(value) && branches.some(branch => branch.kind === "dictionary" && validateShape([value], branch, { scope }) === undefined);
|
|
973
940
|
}
|
|
941
|
+
/**
|
|
942
|
+
* Checks whether a value is a language map carrying no content, which states nothing as an omitted value does.
|
|
943
|
+
*
|
|
944
|
+
* A tag carrying an empty array is blank only where the dictionary states its texts as arrays; where each tag holds
|
|
945
|
+
* a single text, the empty array is malformed, reported by the dictionary validation rather than read as absent.
|
|
946
|
+
*
|
|
947
|
+
* @param value The value to test
|
|
948
|
+
* @param branches The alternatives the member ranges over
|
|
949
|
+
*
|
|
950
|
+
* @returns `true` where `value` is a map one of the dictionary `branches` reads as carrying no text under any tag
|
|
951
|
+
*/
|
|
952
|
+
function isBlank(value, branches) {
|
|
953
|
+
return isObject(value) && branches.some(branch => branch.kind === "dictionary"
|
|
954
|
+
&& Object.entries(value).every(([tag, text]) => isTag(tag) && branch.uniqueLang !== true && isArray(text, [])));
|
|
955
|
+
}
|
|
974
956
|
/**
|
|
975
957
|
* Validates the identifier a resource states against the constraints its shape puts on identifiers.
|
|
976
958
|
*/
|