simpler-forms 0.1.0-alpha.1 → 0.2.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 +300 -76
- package/dist/src/casing.d.ts +43 -0
- package/dist/src/casing.js +146 -0
- package/dist/src/casing.js.map +1 -0
- package/dist/src/decorators/index.d.ts +1 -0
- package/dist/src/decorators/index.js +1 -0
- package/dist/src/decorators/index.js.map +1 -1
- package/dist/src/decorators/mapping.d.ts +17 -0
- package/dist/src/decorators/mapping.js +122 -0
- package/dist/src/decorators/mapping.js.map +1 -0
- package/dist/src/decorators/meta.d.ts +15 -5
- package/dist/src/decorators/meta.js +31 -4
- package/dist/src/decorators/meta.js.map +1 -1
- package/dist/src/decorators/shared.d.ts +2 -2
- package/dist/src/decorators/shared.js.map +1 -1
- package/dist/src/decorators/ui.d.ts +14 -12
- package/dist/src/decorators/ui.js +20 -43
- package/dist/src/decorators/ui.js.map +1 -1
- package/dist/src/emitter.d.ts +8 -0
- package/dist/src/emitter.js +55 -16
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/emitters/block-ui.d.ts +14 -3
- package/dist/src/emitters/block-ui.js +81 -119
- package/dist/src/emitters/block-ui.js.map +1 -1
- package/dist/src/emitters/layout-ui.d.ts +12 -0
- package/dist/src/emitters/layout-ui.js +225 -0
- package/dist/src/emitters/layout-ui.js.map +1 -0
- package/dist/src/emitters/overlay.d.ts +10 -8
- package/dist/src/emitters/overlay.js +30 -105
- package/dist/src/emitters/overlay.js.map +1 -1
- package/dist/src/forms.d.ts +23 -0
- package/dist/src/forms.js +54 -0
- package/dist/src/forms.js.map +1 -0
- package/dist/src/index.d.ts +22 -8
- package/dist/src/index.js +17 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/layout.d.ts +50 -0
- package/dist/src/layout.js +397 -0
- package/dist/src/layout.js.map +1 -0
- package/dist/src/lib.d.ts +585 -39
- package/dist/src/lib.js +258 -15
- package/dist/src/lib.js.map +1 -1
- package/dist/src/linter.js +8 -43
- package/dist/src/linter.js.map +1 -1
- package/dist/src/mapping-from.d.ts +21 -0
- package/dist/src/mapping-from.js +169 -0
- package/dist/src/mapping-from.js.map +1 -0
- package/dist/src/mapping.d.ts +65 -0
- package/dist/src/mapping.js +209 -0
- package/dist/src/mapping.js.map +1 -0
- package/dist/src/model.d.ts +143 -23
- package/dist/src/model.js +108 -21
- package/dist/src/model.js.map +1 -1
- package/dist/src/public.d.ts +20 -4
- package/dist/src/public.js +28 -4
- package/dist/src/public.js.map +1 -1
- package/dist/src/validate.d.ts +2 -1
- package/dist/src/validate.js +208 -58
- package/dist/src/validate.js.map +1 -1
- package/lib/main.tsp +1 -0
- package/lib/mapping.tsp +173 -0
- package/lib/meta.tsp +25 -6
- package/lib/types.tsp +24 -63
- package/lib/ui.tsp +34 -17
- package/package.json +17 -11
- package/src/casing.ts +172 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/mapping.ts +200 -0
- package/src/decorators/meta.ts +56 -13
- package/src/decorators/shared.ts +6 -1
- package/src/decorators/ui.ts +43 -59
- package/src/emitter.ts +76 -16
- package/src/emitters/block-ui.ts +83 -135
- package/src/emitters/layout-ui.ts +280 -0
- package/src/emitters/overlay.ts +43 -116
- package/src/forms.ts +82 -0
- package/src/index.ts +17 -3
- package/src/layout.ts +592 -0
- package/src/lib.ts +264 -15
- package/src/linter.ts +17 -49
- package/src/mapping-from.ts +216 -0
- package/src/mapping.ts +358 -0
- package/src/model.ts +287 -46
- package/src/public.ts +60 -6
- package/src/validate.ts +221 -60
- package/dist/src/emitters/override-condition.d.ts +0 -12
- package/dist/src/emitters/override-condition.js +0 -25
- package/dist/src/emitters/override-condition.js.map +0 -1
- package/src/emitters/override-condition.ts +0 -37
package/src/validate.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Enum,
|
|
3
|
+
EnumMember,
|
|
3
4
|
Model,
|
|
4
5
|
ModelProperty,
|
|
5
6
|
Namespace,
|
|
@@ -19,7 +20,6 @@ import {
|
|
|
19
20
|
cardinalityRequiredWhen,
|
|
20
21
|
childBlock,
|
|
21
22
|
conditionSourceModel,
|
|
22
|
-
orderedProps,
|
|
23
23
|
propCalculationMaterialization,
|
|
24
24
|
propComputed,
|
|
25
25
|
readBlock,
|
|
@@ -28,14 +28,32 @@ import {
|
|
|
28
28
|
modelProperties,
|
|
29
29
|
propEnabledWhen,
|
|
30
30
|
propNotBefore,
|
|
31
|
-
propOmit,
|
|
32
31
|
propReadOnlyWhen,
|
|
33
32
|
propRequiredWhen,
|
|
34
|
-
propSection,
|
|
35
33
|
propVisibleWhen,
|
|
36
34
|
propValidationConstraintsWhen,
|
|
37
35
|
scalarType,
|
|
36
|
+
declaredWidgetSets,
|
|
37
|
+
widgetMembers,
|
|
38
|
+
declaredTagSets,
|
|
39
|
+
tagMembers,
|
|
40
|
+
declaredEntitySets,
|
|
41
|
+
entityMembers,
|
|
42
|
+
allMappingLinks,
|
|
43
|
+
allMappingPathLinks,
|
|
44
|
+
allTransformedProps,
|
|
45
|
+
declaredTransformSets,
|
|
46
|
+
propTransform,
|
|
47
|
+
propMatch,
|
|
48
|
+
declaredMappingSets,
|
|
49
|
+
allLayouts,
|
|
50
|
+
allMappingFromLinks,
|
|
38
51
|
} from "./model.js";
|
|
52
|
+
import { resolveMappingWithProblems } from "./mapping.js";
|
|
53
|
+
import { resolveMappingFrom } from "./mapping-from.js";
|
|
54
|
+
import { resolveForms } from "./forms.js";
|
|
55
|
+
import { resolveLayout } from "./layout.js";
|
|
56
|
+
import { emitLayoutUi } from "./emitters/layout-ui.js";
|
|
39
57
|
|
|
40
58
|
/**
|
|
41
59
|
* Whole-program checks whose failure means the emitted artifacts would be wrong.
|
|
@@ -44,18 +62,19 @@ import {
|
|
|
44
62
|
* one exists because the defect it catches is currently invisible: a question named after a
|
|
45
63
|
* form, two blocks colliding on one output path, a condition comparing against a value the
|
|
46
64
|
* source enum does not have, a calculation that depends on itself, a field that is required
|
|
47
|
-
* but can be hidden,
|
|
65
|
+
* but can be hidden, a widget no renderer was declared to provide, a form that cannot be
|
|
66
|
+
* published, and a layout that misplaces a field.
|
|
48
67
|
*/
|
|
49
68
|
export function $onValidate(program: Program): void {
|
|
50
69
|
const blocks = allBlocks(program);
|
|
51
70
|
|
|
52
71
|
checkQuestionIds(program, blocks);
|
|
53
72
|
checkDuplicateIds(program, blocks);
|
|
73
|
+
program.reportDiagnostics(resolveForms(program).problems);
|
|
74
|
+
checkLayouts(program);
|
|
54
75
|
|
|
55
76
|
for (const block of blocks) {
|
|
56
77
|
if (block.model.kind !== "Model") continue;
|
|
57
|
-
checkSections(program, block);
|
|
58
|
-
checkOverridePaths(program, block);
|
|
59
78
|
for (const prop of block.model.properties.values()) {
|
|
60
79
|
checkConditions(program, prop);
|
|
61
80
|
checkRequiredButHidden(program, prop);
|
|
@@ -63,6 +82,9 @@ export function $onValidate(program: Program): void {
|
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
|
|
85
|
+
checkWidgets(program);
|
|
86
|
+
checkCatalogue(program);
|
|
87
|
+
checkMappings(program);
|
|
66
88
|
checkDateOrders(program);
|
|
67
89
|
checkCardinalityPaths(program);
|
|
68
90
|
checkCalculationCycles(program, blocks);
|
|
@@ -284,6 +306,182 @@ function checkDateOrders(program: Program): void {
|
|
|
284
306
|
visit(program.getGlobalNamespaceType());
|
|
285
307
|
}
|
|
286
308
|
|
|
309
|
+
/**
|
|
310
|
+
* A widget is a contract with the program's renderers, which this library knows nothing about,
|
|
311
|
+
* so the program declares the set it provides with `@UI.widgets`. A member of any other enum
|
|
312
|
+
* would be emitted under a name no renderer has promised to handle.
|
|
313
|
+
*/
|
|
314
|
+
function checkWidgets(program: Program): void {
|
|
315
|
+
const declared = declaredWidgetSets(program);
|
|
316
|
+
for (const [prop, member] of widgetMembers(program)) {
|
|
317
|
+
if (declared.has(member.enum)) continue;
|
|
318
|
+
reportDiagnostic(program, {
|
|
319
|
+
code: "widget-not-declared",
|
|
320
|
+
target: prop,
|
|
321
|
+
format: {
|
|
322
|
+
name: prop.name,
|
|
323
|
+
widget: member.name,
|
|
324
|
+
enumName: member.enum.name,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Tags and entities are the program's catalogue vocabulary, declared with `@Meta.tags` and
|
|
332
|
+
* `@Meta.entities` as widgets are with `@UI.widgets`. A member of any other enum would be
|
|
333
|
+
* catalogued under a heading the program never named.
|
|
334
|
+
*/
|
|
335
|
+
function checkCatalogue(program: Program): void {
|
|
336
|
+
const tagSets = declaredTagSets(program);
|
|
337
|
+
for (const [type, members] of tagMembers(program)) {
|
|
338
|
+
for (const member of members) {
|
|
339
|
+
if (tagSets.has(member.enum)) continue;
|
|
340
|
+
reportDiagnostic(program, {
|
|
341
|
+
code: "tag-not-declared",
|
|
342
|
+
target: type,
|
|
343
|
+
format: {
|
|
344
|
+
name: type.name,
|
|
345
|
+
tag: member.name,
|
|
346
|
+
enumName: member.enum.name,
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const entitySets = declaredEntitySets(program);
|
|
352
|
+
for (const [type, member] of entityMembers(program)) {
|
|
353
|
+
if (entitySets.has(member.enum)) continue;
|
|
354
|
+
reportDiagnostic(program, {
|
|
355
|
+
code: "entity-not-declared",
|
|
356
|
+
target: type,
|
|
357
|
+
format: {
|
|
358
|
+
name: type.name,
|
|
359
|
+
entity: member.name,
|
|
360
|
+
enumName: member.enum.name,
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* A mapping is a contract with one of the program's emitters, declared with
|
|
368
|
+
* `@Mapping.targets` as a widget is with `@UI.widgets`. Each model linked in a mapping is
|
|
369
|
+
* resolved through everything it composes, and every link that does not hold there is
|
|
370
|
+
* reported once, however many forms compose the model it is declared on.
|
|
371
|
+
*/
|
|
372
|
+
function checkMappings(program: Program): void {
|
|
373
|
+
const declared = declaredMappingSets(program);
|
|
374
|
+
const links = allMappingLinks(program);
|
|
375
|
+
const undeclared = (target: Model | ModelProperty, mapping: EnumMember) => {
|
|
376
|
+
if (declared.has(mapping.enum)) return;
|
|
377
|
+
reportDiagnostic(program, {
|
|
378
|
+
code: "mapping-target-undeclared",
|
|
379
|
+
target,
|
|
380
|
+
format: {
|
|
381
|
+
name: target.name || "an anonymous model",
|
|
382
|
+
mapping: mapping.name,
|
|
383
|
+
enumName: mapping.enum.name,
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
for (const [model, paths] of allMappingPathLinks(program))
|
|
388
|
+
for (const { mapping } of paths) undeclared(model, mapping);
|
|
389
|
+
|
|
390
|
+
const transforms = declaredTransformSets(program);
|
|
391
|
+
for (const prop of allTransformedProps(program)) {
|
|
392
|
+
const { member } = propTransform(program, prop)!;
|
|
393
|
+
if (propMatch(program, prop))
|
|
394
|
+
reportDiagnostic(program, {
|
|
395
|
+
code: "mapping-match-and-transform",
|
|
396
|
+
target: prop,
|
|
397
|
+
format: { name: prop.name },
|
|
398
|
+
});
|
|
399
|
+
if (transforms.has(member.enum)) continue;
|
|
400
|
+
reportDiagnostic(program, {
|
|
401
|
+
code: "mapping-transform-undeclared",
|
|
402
|
+
target: prop,
|
|
403
|
+
format: {
|
|
404
|
+
name: prop.name,
|
|
405
|
+
transform: member.name,
|
|
406
|
+
enumName: member.enum.name,
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const roots: [Model, EnumMember][] = [];
|
|
412
|
+
for (const [target, list] of links) {
|
|
413
|
+
const seen = new Set<EnumMember>();
|
|
414
|
+
for (const { mapping, mappedTo } of list) {
|
|
415
|
+
undeclared(target, mapping);
|
|
416
|
+
if (seen.has(mapping)) {
|
|
417
|
+
reportDiagnostic(program, {
|
|
418
|
+
code: "mapping-duplicate",
|
|
419
|
+
target,
|
|
420
|
+
format: {
|
|
421
|
+
name: target.name || "an anonymous model",
|
|
422
|
+
mapping: mapping.name,
|
|
423
|
+
},
|
|
424
|
+
});
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
seen.add(mapping);
|
|
428
|
+
if (mappedTo.kind !== target.kind) {
|
|
429
|
+
reportDiagnostic(program, {
|
|
430
|
+
code: "mapping-type-mismatch",
|
|
431
|
+
target,
|
|
432
|
+
format: {
|
|
433
|
+
mapping: mapping.name,
|
|
434
|
+
source: target.name || "an anonymous model",
|
|
435
|
+
target: mappedTo.name || "an anonymous model",
|
|
436
|
+
reason:
|
|
437
|
+
target.kind === "Model"
|
|
438
|
+
? "a model corresponds to a model, not a property"
|
|
439
|
+
: "a property corresponds to a property, not a model",
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (target.kind === "Model") roots.push([target, mapping]);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const reported = new Set<string>();
|
|
449
|
+
for (const [model, mapping] of roots) {
|
|
450
|
+
for (const problem of resolveMappingWithProblems(program, model, mapping)
|
|
451
|
+
?.problems ?? []) {
|
|
452
|
+
const key = JSON.stringify([problem.code, problem.format]);
|
|
453
|
+
if (reported.has(key)) continue;
|
|
454
|
+
reported.add(key);
|
|
455
|
+
reportDiagnostic(program, problem);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
for (const [target, links] of allMappingFromLinks(program)) {
|
|
460
|
+
for (const { mapping } of links) undeclared(target, mapping);
|
|
461
|
+
if (target.kind !== "Model") continue;
|
|
462
|
+
for (const { mapping, select } of links)
|
|
463
|
+
if (select)
|
|
464
|
+
reportDiagnostic(program, {
|
|
465
|
+
code: "mapping-from-select-on-model",
|
|
466
|
+
target,
|
|
467
|
+
format: { mapping: mapping.name, target: target.name },
|
|
468
|
+
});
|
|
469
|
+
for (const { mapping, source } of links) {
|
|
470
|
+
if (source.kind !== "Model") continue;
|
|
471
|
+
for (const problem of resolveMappingFrom(program, source, mapping)
|
|
472
|
+
?.problems ?? []) {
|
|
473
|
+
// A wrapper element is a limit of what an emitter writes, not a broken link: the
|
|
474
|
+
// emitter whose output cannot hold one reports it.
|
|
475
|
+
if (problem.code === "simpler-forms/mapping-from-wrapper") continue;
|
|
476
|
+
const key = JSON.stringify([problem.code, problem.message]);
|
|
477
|
+
if (reported.has(key)) continue;
|
|
478
|
+
reported.add(key);
|
|
479
|
+
program.reportDiagnostic(problem);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
287
485
|
function checkEncodedCheckboxGroup(
|
|
288
486
|
program: Program,
|
|
289
487
|
prop: ModelProperty,
|
|
@@ -505,6 +703,21 @@ function checkComputedPaths(program: Program, blocks: Block[]): void {
|
|
|
505
703
|
}
|
|
506
704
|
}
|
|
507
705
|
|
|
706
|
+
// ---------------------------------------------------------------------------
|
|
707
|
+
// layouts
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Every layout is resolved and laid out here, published or not, so a preview-only layout
|
|
711
|
+
* is checked as strictly as a form's.
|
|
712
|
+
*/
|
|
713
|
+
function checkLayouts(program: Program): void {
|
|
714
|
+
for (const [layout, presented] of allLayouts(program)) {
|
|
715
|
+
const resolved = resolveLayout(program, layout, presented);
|
|
716
|
+
program.reportDiagnostics(resolved.diagnostics);
|
|
717
|
+
program.reportDiagnostics(emitLayoutUi(program, resolved).diagnostics);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
508
721
|
// ---------------------------------------------------------------------------
|
|
509
722
|
// identity
|
|
510
723
|
|
|
@@ -573,7 +786,7 @@ function checkDuplicateIds(program: Program, blocks: Block[]): void {
|
|
|
573
786
|
}
|
|
574
787
|
}
|
|
575
788
|
|
|
576
|
-
const name = (type: Model | Scalar) => type.name || "an anonymous model";
|
|
789
|
+
const name = (type: Model | Scalar | Enum) => type.name || "an anonymous model";
|
|
577
790
|
|
|
578
791
|
// ---------------------------------------------------------------------------
|
|
579
792
|
// conditions
|
|
@@ -691,58 +904,7 @@ function checkRequiredButHidden(program: Program, prop: ModelProperty): void {
|
|
|
691
904
|
}
|
|
692
905
|
|
|
693
906
|
// ---------------------------------------------------------------------------
|
|
694
|
-
//
|
|
695
|
-
|
|
696
|
-
function checkSections(program: Program, block: Block): void {
|
|
697
|
-
if (block.kind !== "form" || !block.sections) return;
|
|
698
|
-
for (const prop of orderedProps(program, block)) {
|
|
699
|
-
if (propOmit(program, prop)) continue;
|
|
700
|
-
if (propSection(program, prop)) continue;
|
|
701
|
-
if (typeof block.overrides[prop.name]?.section === "string") continue;
|
|
702
|
-
reportDiagnostic(program, {
|
|
703
|
-
code: "section-orphan",
|
|
704
|
-
target: prop,
|
|
705
|
-
format: { name: prop.name },
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* An override addresses a field by the path an applicant's answer takes. A path that does
|
|
712
|
-
* not resolve is a silently ignored override -- the CommonGrants bank's stringly-typed
|
|
713
|
-
* override table, caught at compile time instead of at website build time.
|
|
714
|
-
*/
|
|
715
|
-
function checkOverridePaths(program: Program, block: Block): void {
|
|
716
|
-
const paths = Object.keys(block.overrides);
|
|
717
|
-
for (const [overridePath, override] of Object.entries(block.overrides)) {
|
|
718
|
-
if (override.visibleReadOnly === true && override.readOnly !== true) {
|
|
719
|
-
reportDiagnostic(program, {
|
|
720
|
-
code: "visible-read-only-without-read-only",
|
|
721
|
-
target: block.model,
|
|
722
|
-
format: { path: overridePath },
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
const condition = override.enabledWhen;
|
|
726
|
-
const enabledWhen = condition as Record<string, unknown> | undefined;
|
|
727
|
-
if (
|
|
728
|
-
enabledWhen &&
|
|
729
|
-
typeof enabledWhen === "object" &&
|
|
730
|
-
!Array.isArray(enabledWhen) &&
|
|
731
|
-
typeof enabledWhen.path === "string"
|
|
732
|
-
) {
|
|
733
|
-
paths.push(enabledWhen.path);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
for (const path of paths) {
|
|
737
|
-
const reason = resolvePath(program, block.model as Model, path.split("."));
|
|
738
|
-
if (!reason) continue;
|
|
739
|
-
reportDiagnostic(program, {
|
|
740
|
-
code: "override-path-unresolved",
|
|
741
|
-
target: block.model,
|
|
742
|
-
format: { path, reason },
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
}
|
|
907
|
+
// paths
|
|
746
908
|
|
|
747
909
|
/** Undefined when the path resolves; otherwise why it did not. */
|
|
748
910
|
function resolvePath(
|
|
@@ -790,7 +952,6 @@ function objectBehind(
|
|
|
790
952
|
return type;
|
|
791
953
|
}
|
|
792
954
|
|
|
793
|
-
/** A widget declaration naming a section the form does not have would render nothing. */
|
|
794
955
|
// ---------------------------------------------------------------------------
|
|
795
956
|
// calculations
|
|
796
957
|
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** The bounded, target-neutral condition shape supported by @UI.overrides.enabledWhen. */
|
|
2
|
-
export type NormalizedOverrideCondition = {
|
|
3
|
-
sourcePath: string[];
|
|
4
|
-
operator: "equals";
|
|
5
|
-
value: string | number | boolean | null;
|
|
6
|
-
} | {
|
|
7
|
-
sourcePath: string[];
|
|
8
|
-
operator: "in";
|
|
9
|
-
values: (string | number | boolean | null)[];
|
|
10
|
-
};
|
|
11
|
-
/** Parse enabledWhen once so canonical and target-specific UI emitters cannot drift. */
|
|
12
|
-
export declare function normalizedOverrideEnabledWhen(override: Record<string, unknown>): NormalizedOverrideCondition | undefined;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const primitive = (value) => value === null ||
|
|
2
|
-
typeof value === "string" ||
|
|
3
|
-
typeof value === "number" ||
|
|
4
|
-
typeof value === "boolean";
|
|
5
|
-
/** Parse enabledWhen once so canonical and target-specific UI emitters cannot drift. */
|
|
6
|
-
export function normalizedOverrideEnabledWhen(override) {
|
|
7
|
-
const raw = override.enabledWhen;
|
|
8
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
9
|
-
return undefined;
|
|
10
|
-
const condition = raw;
|
|
11
|
-
const path = condition.path;
|
|
12
|
-
if (typeof path !== "string" || !path)
|
|
13
|
-
return undefined;
|
|
14
|
-
const sourcePath = path.split(".").filter(Boolean);
|
|
15
|
-
if (!sourcePath.length)
|
|
16
|
-
return undefined;
|
|
17
|
-
const values = condition.in;
|
|
18
|
-
if (Array.isArray(values) && values.length > 0 && values.every(primitive)) {
|
|
19
|
-
return { sourcePath, operator: "in", values };
|
|
20
|
-
}
|
|
21
|
-
if (!primitive(condition.equals))
|
|
22
|
-
return undefined;
|
|
23
|
-
return { sourcePath, operator: "equals", value: condition.equals };
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=override-condition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"override-condition.js","sourceRoot":"","sources":["../../../src/emitters/override-condition.ts"],"names":[],"mappings":"AAaA,MAAM,SAAS,GAAG,CAAC,KAAc,EAA6C,EAAE,CAC9E,KAAK,KAAK,IAAI;IACd,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,KAAK,SAAS,CAAC;AAE7B,wFAAwF;AACxF,MAAM,UAAU,6BAA6B,CAC3C,QAAiC;IAEjC,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC;IACjC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5E,MAAM,SAAS,GAAG,GAA8B,CAAC;IACjD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAC5B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,UAAU,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAChD,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** The bounded, target-neutral condition shape supported by @UI.overrides.enabledWhen. */
|
|
2
|
-
export type NormalizedOverrideCondition =
|
|
3
|
-
| {
|
|
4
|
-
sourcePath: string[];
|
|
5
|
-
operator: "equals";
|
|
6
|
-
value: string | number | boolean | null;
|
|
7
|
-
}
|
|
8
|
-
| {
|
|
9
|
-
sourcePath: string[];
|
|
10
|
-
operator: "in";
|
|
11
|
-
values: (string | number | boolean | null)[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const primitive = (value: unknown): value is string | number | boolean | null =>
|
|
15
|
-
value === null ||
|
|
16
|
-
typeof value === "string" ||
|
|
17
|
-
typeof value === "number" ||
|
|
18
|
-
typeof value === "boolean";
|
|
19
|
-
|
|
20
|
-
/** Parse enabledWhen once so canonical and target-specific UI emitters cannot drift. */
|
|
21
|
-
export function normalizedOverrideEnabledWhen(
|
|
22
|
-
override: Record<string, unknown>,
|
|
23
|
-
): NormalizedOverrideCondition | undefined {
|
|
24
|
-
const raw = override.enabledWhen;
|
|
25
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
26
|
-
const condition = raw as Record<string, unknown>;
|
|
27
|
-
const path = condition.path;
|
|
28
|
-
if (typeof path !== "string" || !path) return undefined;
|
|
29
|
-
const sourcePath = path.split(".").filter(Boolean);
|
|
30
|
-
if (!sourcePath.length) return undefined;
|
|
31
|
-
const values = condition.in;
|
|
32
|
-
if (Array.isArray(values) && values.length > 0 && values.every(primitive)) {
|
|
33
|
-
return { sourcePath, operator: "in", values };
|
|
34
|
-
}
|
|
35
|
-
if (!primitive(condition.equals)) return undefined;
|
|
36
|
-
return { sourcePath, operator: "equals", value: condition.equals };
|
|
37
|
-
}
|