@chobantonov/jsonforms-extended-spec 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/conformance/authoring.json +2680 -0
- package/conformance/behavior.json +1602 -0
- package/conformance/config-consumption.json +1542 -0
- package/conformance/expected-invalid.json +20 -0
- package/docs/audit.md +150 -0
- package/docs/conditional-fields.md +122 -0
- package/docs/draft-07-visual-support.md +43 -0
- package/docs/external-resources-proposal.md +536 -0
- package/docs/implementation-guide.md +233 -0
- package/docs/implementation-pitfalls.md +968 -0
- package/docs/implementation-web-typescript.md +41 -0
- package/docs/renderer-and-demo.md +1347 -0
- package/docs/renderer-selection.md +99 -0
- package/docs/spec.md +8470 -0
- package/docs/todo.md +166 -0
- package/examples/README.md +127 -0
- package/examples/additional-errors/README.md +176 -0
- package/examples/additional-errors/config.json +3 -0
- package/examples/additional-errors/data.json +11 -0
- package/examples/additional-errors/schema.json +56 -0
- package/examples/additional-errors/translations.json +64 -0
- package/examples/additional-errors/uischema.json +158 -0
- package/examples/additional-items-pagination/README.md +8 -0
- package/examples/additional-items-pagination/config.json +10 -0
- package/examples/additional-items-pagination/data.json +22 -0
- package/examples/additional-items-pagination/schema.json +30 -0
- package/examples/additional-items-pagination/translations.json +16 -0
- package/examples/additional-items-pagination/uischema.json +39 -0
- package/examples/additional-properties/README.md +203 -0
- package/examples/additional-properties/config.json +5 -0
- package/examples/additional-properties/data.json +31 -0
- package/examples/additional-properties/schema.json +78 -0
- package/examples/additional-properties/translations.json +80 -0
- package/examples/additional-properties/uischema.json +104 -0
- package/examples/ag-grid/README.md +62 -0
- package/examples/ag-grid/config.json +14 -0
- package/examples/ag-grid/data.json +124 -0
- package/examples/ag-grid/schema.json +48 -0
- package/examples/ag-grid/translations.json +58 -0
- package/examples/ag-grid/uischema.json +671 -0
- package/examples/array-choices/README.md +150 -0
- package/examples/array-choices/config.json +4 -0
- package/examples/array-choices/data.json +10 -0
- package/examples/array-choices/schema.json +68 -0
- package/examples/array-choices/translations.json +64 -0
- package/examples/array-choices/uischema.json +97 -0
- package/examples/array-controls/README.md +237 -0
- package/examples/array-controls/config.json +4 -0
- package/examples/array-controls/data.json +147 -0
- package/examples/array-controls/schema.json +374 -0
- package/examples/array-controls/translations.json +186 -0
- package/examples/array-controls/uischema.json +685 -0
- package/examples/array-detail-modes/README.md +11 -0
- package/examples/array-detail-modes/data.json +38 -0
- package/examples/array-detail-modes/schema.json +89 -0
- package/examples/array-detail-modes/translations.json +36 -0
- package/examples/array-detail-modes/uischema.json +73 -0
- package/examples/array-detail-modes/uischemas.d.mts +2 -0
- package/examples/array-detail-modes/uischemas.json +15 -0
- package/examples/boolean-controls/README.md +109 -0
- package/examples/boolean-controls/config.json +3 -0
- package/examples/boolean-controls/data.json +27 -0
- package/examples/boolean-controls/schema.json +98 -0
- package/examples/boolean-controls/translations.json +94 -0
- package/examples/boolean-controls/uischema.json +126 -0
- package/examples/button-actions/README.md +259 -0
- package/examples/button-actions/config.json +7 -0
- package/examples/button-actions/data.json +5 -0
- package/examples/button-actions/host.mjs +14 -0
- package/examples/button-actions/schema.json +20 -0
- package/examples/button-actions/translations.json +60 -0
- package/examples/button-actions/uischema.json +179 -0
- package/examples/catalog.json +634 -0
- package/examples/categorization/README.md +132 -0
- package/examples/categorization/config.json +7 -0
- package/examples/categorization/data.json +8 -0
- package/examples/categorization/schema.json +29 -0
- package/examples/categorization/translations.json +72 -0
- package/examples/categorization/uischema.json +288 -0
- package/examples/choice-controls/README.md +136 -0
- package/examples/choice-controls/config.json +10 -0
- package/examples/choice-controls/data.json +61 -0
- package/examples/choice-controls/schema.json +406 -0
- package/examples/choice-controls/translations.json +154 -0
- package/examples/choice-controls/uischema.json +575 -0
- package/examples/choice-controls/uischemas.d.mts +2 -0
- package/examples/choice-controls/uischemas.json +16 -0
- package/examples/code-editor/README.md +74 -0
- package/examples/code-editor/data.json +8 -0
- package/examples/code-editor/schema.json +28 -0
- package/examples/code-editor/translations.json +20 -0
- package/examples/code-editor/uischema.json +77 -0
- package/examples/collection-pagination/README.md +5 -0
- package/examples/collection-pagination/config.json +1 -0
- package/examples/collection-pagination/data.json +64 -0
- package/examples/collection-pagination/schema.json +23 -0
- package/examples/collection-pagination/translations.json +14 -0
- package/examples/collection-pagination/uischema.json +14 -0
- package/examples/color-control/README.md +154 -0
- package/examples/color-control/config.json +7 -0
- package/examples/color-control/data.json +11 -0
- package/examples/color-control/schema.json +61 -0
- package/examples/color-control/translations.json +76 -0
- package/examples/color-control/uischema.json +106 -0
- package/examples/combinators/README.md +223 -0
- package/examples/combinators/config.json +9 -0
- package/examples/combinators/data.json +23 -0
- package/examples/combinators/schema.json +232 -0
- package/examples/combinators/translations.json +178 -0
- package/examples/combinators/uischema.json +158 -0
- package/examples/conditional-fields/README.md +27 -0
- package/examples/conditional-fields/config.json +5 -0
- package/examples/conditional-fields/data.json +7 -0
- package/examples/conditional-fields/schema.json +59 -0
- package/examples/conditional-fields/translations.json +32 -0
- package/examples/conditional-fields/uischema.json +131 -0
- package/examples/container-validation-indicator/README.md +187 -0
- package/examples/container-validation-indicator/config.json +9 -0
- package/examples/container-validation-indicator/data.json +68 -0
- package/examples/container-validation-indicator/schema.json +222 -0
- package/examples/container-validation-indicator/translations.json +120 -0
- package/examples/container-validation-indicator/uischema.json +98 -0
- package/examples/cron-control/README.md +155 -0
- package/examples/cron-control/data.json +15 -0
- package/examples/cron-control/schema.json +72 -0
- package/examples/cron-control/translations.json +80 -0
- package/examples/cron-control/uischema.json +91 -0
- package/examples/destructive-confirmation/README.md +210 -0
- package/examples/destructive-confirmation/config.json +17 -0
- package/examples/destructive-confirmation/data.json +86 -0
- package/examples/destructive-confirmation/schema.json +204 -0
- package/examples/destructive-confirmation/translations.json +112 -0
- package/examples/destructive-confirmation/uischema.json +105 -0
- package/examples/draft-07-metaschema/README.md +11 -0
- package/examples/draft-07-metaschema/config.json +3 -0
- package/examples/draft-07-metaschema/data.json +25 -0
- package/examples/draft-07-metaschema/schema.json +172 -0
- package/examples/draft-07-metaschema/translations.json +10 -0
- package/examples/draft-07-metaschema/uischema.json +14 -0
- package/examples/dynamic-playground/README.md +95 -0
- package/examples/dynamic-playground/config.json +8 -0
- package/examples/dynamic-playground/configuration.json +152 -0
- package/examples/dynamic-playground/data.json +15 -0
- package/examples/dynamic-playground/dynamic-uischema.json +379 -0
- package/examples/dynamic-playground/host.mjs +37 -0
- package/examples/dynamic-playground/schema.json +48 -0
- package/examples/dynamic-playground/translations.json +76 -0
- package/examples/dynamic-playground/uischema.json +36 -0
- package/examples/editor-details/README.md +10 -0
- package/examples/editor-details/data.json +18 -0
- package/examples/editor-details/schema.json +49 -0
- package/examples/editor-details/translations.json +28 -0
- package/examples/editor-details/uischema.json +53 -0
- package/examples/editor-details/uischemas.d.mts +2 -0
- package/examples/editor-details/uischemas.json +14 -0
- package/examples/file-control/README.md +108 -0
- package/examples/file-control/data.json +28 -0
- package/examples/file-control/schema.json +89 -0
- package/examples/file-control/translations.json +46 -0
- package/examples/file-control/uischema.json +152 -0
- package/examples/group-layout/README.md +149 -0
- package/examples/group-layout/config.json +10 -0
- package/examples/group-layout/data.json +9 -0
- package/examples/group-layout/schema.json +51 -0
- package/examples/group-layout/translations.json +62 -0
- package/examples/group-layout/uischema.json +249 -0
- package/examples/index.d.ts +17 -0
- package/examples/index.js +69 -0
- package/examples/input-adornments/README.md +68 -0
- package/examples/input-adornments/data.json +41 -0
- package/examples/input-adornments/schema.json +207 -0
- package/examples/input-adornments/translations.json +106 -0
- package/examples/input-adornments/uischema.json +695 -0
- package/examples/job-application/README.md +23 -0
- package/examples/job-application/config.json +10 -0
- package/examples/job-application/data.json +68 -0
- package/examples/job-application/schema.json +196 -0
- package/examples/job-application/translations.json +388 -0
- package/examples/job-application/uischema.json +218 -0
- package/examples/job-application/uischemas.json +153 -0
- package/examples/json-editor/README.md +28 -0
- package/examples/json-editor/schema.json +1 -0
- package/examples/json-editor/translations.json +10 -0
- package/examples/json-editor/uischema.json +16 -0
- package/examples/json-inference/README.md +33 -0
- package/examples/json-inference/translations.json +10 -0
- package/examples/json-inference/uischema.json +16 -0
- package/examples/kitchen-sink/README.md +86 -0
- package/examples/kitchen-sink/config.json +14 -0
- package/examples/kitchen-sink/data.json +263 -0
- package/examples/kitchen-sink/invalid-data.json +263 -0
- package/examples/kitchen-sink/schema.json +515 -0
- package/examples/kitchen-sink/translations.json +270 -0
- package/examples/kitchen-sink/uischema.json +722 -0
- package/examples/label-interpolation/README.md +241 -0
- package/examples/label-interpolation/config.json +14 -0
- package/examples/label-interpolation/data.json +13 -0
- package/examples/label-interpolation/schema.json +64 -0
- package/examples/label-interpolation/translations.json +94 -0
- package/examples/label-interpolation/uischema.json +379 -0
- package/examples/layout-sizing/README.md +162 -0
- package/examples/layout-sizing/config.json +10 -0
- package/examples/layout-sizing/data.json +14 -0
- package/examples/layout-sizing/schema.json +58 -0
- package/examples/layout-sizing/translations.json +42 -0
- package/examples/layout-sizing/uischema.json +558 -0
- package/examples/markup-label/README.md +109 -0
- package/examples/markup-label/config.json +16 -0
- package/examples/markup-label/data.json +5 -0
- package/examples/markup-label/schema.json +24 -0
- package/examples/markup-label/translations.json +40 -0
- package/examples/markup-label/uischema.json +149 -0
- package/examples/mixed-control/README.md +164 -0
- package/examples/mixed-control/config.json +11 -0
- package/examples/mixed-control/data.json +70 -0
- package/examples/mixed-control/schema.json +221 -0
- package/examples/mixed-control/translations.json +158 -0
- package/examples/mixed-control/uischema.json +211 -0
- package/examples/null-control/README.md +111 -0
- package/examples/null-control/config.json +4 -0
- package/examples/null-control/data.json +6 -0
- package/examples/null-control/schema.json +36 -0
- package/examples/null-control/translations.json +42 -0
- package/examples/null-control/uischema.json +56 -0
- package/examples/numeric-controls/README.md +94 -0
- package/examples/numeric-controls/config.json +4 -0
- package/examples/numeric-controls/data.json +8 -0
- package/examples/numeric-controls/schema.json +52 -0
- package/examples/numeric-controls/translations.json +56 -0
- package/examples/numeric-controls/uischema.json +77 -0
- package/examples/object-control/README.md +220 -0
- package/examples/object-control/config.json +4 -0
- package/examples/object-control/data.json +62 -0
- package/examples/object-control/schema.json +252 -0
- package/examples/object-control/translations.json +160 -0
- package/examples/object-control/uischema.json +275 -0
- package/examples/object-control/uischemas.d.mts +2 -0
- package/examples/object-control/uischemas.json +59 -0
- package/examples/password-control/README.md +119 -0
- package/examples/password-control/config.json +3 -0
- package/examples/password-control/data.json +18 -0
- package/examples/password-control/schema.json +65 -0
- package/examples/password-control/translations.json +64 -0
- package/examples/password-control/uischema.json +94 -0
- package/examples/pre-touch-errors/README.md +176 -0
- package/examples/pre-touch-errors/config.json +4 -0
- package/examples/pre-touch-errors/data.json +5 -0
- package/examples/pre-touch-errors/schema.json +56 -0
- package/examples/pre-touch-errors/translations.json +68 -0
- package/examples/pre-touch-errors/uischema.json +85 -0
- package/examples/presentation/README.md +148 -0
- package/examples/presentation/config.json +9 -0
- package/examples/presentation/data.json +6 -0
- package/examples/presentation/schema.json +21 -0
- package/examples/presentation/translations.json +64 -0
- package/examples/presentation/uischema.json +210 -0
- package/examples/property-pagination/README.md +5 -0
- package/examples/property-pagination/config.json +1 -0
- package/examples/property-pagination/data.json +17 -0
- package/examples/property-pagination/schema.json +14 -0
- package/examples/property-pagination/translations.json +10 -0
- package/examples/property-pagination/uischema.json +24 -0
- package/examples/recursive-tree/README.md +49 -0
- package/examples/recursive-tree/config.json +1 -0
- package/examples/recursive-tree/data.json +40 -0
- package/examples/recursive-tree/schema.json +89 -0
- package/examples/recursive-tree/translations.json +42 -0
- package/examples/recursive-tree/uischema.json +84 -0
- package/examples/recursive-tree/uischemas.d.mts +2 -0
- package/examples/recursive-tree/uischemas.json +51 -0
- package/examples/split-layout/README.md +123 -0
- package/examples/split-layout/config.json +3 -0
- package/examples/split-layout/data.json +13 -0
- package/examples/split-layout/schema.json +50 -0
- package/examples/split-layout/translations.json +50 -0
- package/examples/split-layout/uischema.json +204 -0
- package/examples/string-controls/README.md +159 -0
- package/examples/string-controls/config.json +5 -0
- package/examples/string-controls/data.json +13 -0
- package/examples/string-controls/schema.json +70 -0
- package/examples/string-controls/translations.json +76 -0
- package/examples/string-controls/uischema.json +148 -0
- package/examples/table-row-details/README.md +69 -0
- package/examples/table-row-details/config.json +7 -0
- package/examples/table-row-details/data.json +280 -0
- package/examples/table-row-details/schema.json +61 -0
- package/examples/table-row-details/translations.json +56 -0
- package/examples/table-row-details/uischema.json +1303 -0
- package/examples/template-layout/README.md +250 -0
- package/examples/template-layout/config.json +9 -0
- package/examples/template-layout/data.json +20 -0
- package/examples/template-layout/host.mjs +13 -0
- package/examples/template-layout/schema.json +48 -0
- package/examples/template-layout/translations.json +70 -0
- package/examples/template-layout/uischema.json +177 -0
- package/examples/template-slots/README.md +19 -0
- package/examples/template-slots/data.json +4 -0
- package/examples/template-slots/schema.json +11 -0
- package/examples/template-slots/translations.json +26 -0
- package/examples/template-slots/uischema.json +47 -0
- package/examples/template-slots/uischemas.d.mts +2 -0
- package/examples/template-slots/uischemas.json +56 -0
- package/examples/temporal-controls/README.md +325 -0
- package/examples/temporal-controls/data.json +44 -0
- package/examples/temporal-controls/schema.json +208 -0
- package/examples/temporal-controls/translations.json +156 -0
- package/examples/temporal-controls/uischema.json +297 -0
- package/examples/tree-max-depth/README.md +5 -0
- package/examples/tree-max-depth/config.json +3 -0
- package/examples/tree-max-depth/data.json +31 -0
- package/examples/tree-max-depth/schema.json +258 -0
- package/examples/tree-max-depth/translations.json +42 -0
- package/examples/tree-max-depth/uischema.json +16 -0
- package/examples/tree-max-depth/uischemas.d.mts +2 -0
- package/examples/tree-max-depth/uischemas.json +50 -0
- package/examples/tuple-control/README.md +335 -0
- package/examples/tuple-control/config.json +4 -0
- package/examples/tuple-control/data.json +61 -0
- package/examples/tuple-control/schema.json +218 -0
- package/examples/tuple-control/translations.json +142 -0
- package/examples/tuple-control/uischema.json +128 -0
- package/examples/tuple-control/uischemas.d.mts +2 -0
- package/examples/tuple-control/uischemas.json +125 -0
- package/examples/validator-profile/README.md +197 -0
- package/examples/validator-profile/config.json +9 -0
- package/examples/validator-profile/data.json +16 -0
- package/examples/validator-profile/schema.json +139 -0
- package/examples/validator-profile/translations.json +34 -0
- package/examples/validator-profile/uischema.json +59 -0
- package/package.json +83 -3
- package/provenance.json +140 -0
- package/schemas/README.md +82 -0
- package/schemas/example.schema.json +37 -0
- package/schemas/jsonforms-config.schema.json +427 -0
- package/schemas/jsonforms-dynamic-uischema.schema.json +220 -0
- package/schemas/jsonforms-extended-config.schema.json +332 -0
- package/schemas/jsonforms-extended-uischema.schema.json +1932 -0
- package/schemas/jsonforms-rule.schema.json +104 -0
- package/schemas/jsonforms-uischema.schema.json +1434 -0
- package/typescript/README.md +546 -0
- package/typescript/lib/authoring/cssLength.d.ts +33 -0
- package/typescript/lib/authoring/cssLength.js +25 -0
- package/typescript/lib/authoring/dynamic.d.ts +73 -0
- package/typescript/lib/authoring/dynamic.js +8 -0
- package/typescript/lib/authoring/forSchema.d.ts +385 -0
- package/typescript/lib/authoring/forSchema.js +84 -0
- package/typescript/lib/authoring/schemaTypes.d.ts +111 -0
- package/typescript/lib/authoring/schemaTypes.js +15 -0
- package/typescript/lib/index.d.ts +4 -0
- package/typescript/lib/index.js +20 -0
- package/typescript/package.json +1 -0
- package/typescript/src/authoring/cssLength.ts +79 -0
- package/typescript/src/authoring/dynamic.ts +96 -0
- package/typescript/src/authoring/forSchema.ts +428 -0
- package/typescript/src/authoring/schemaTypes.ts +143 -0
- package/typescript/src/index.ts +4 -0
- package/typescript/test/schemaContract.test.ts +638 -0
- package/typescript/test/tsconfig.json +10 -0
- package/typescript/test/typedAuthoring.test.ts +151 -0
- package/typescript/test/typedAuthoringCoverage.test.ts +178 -0
- package/typescript/test/typedAuthoringCssLength.test.ts +81 -0
- package/typescript/test/typedAuthoringNames.test.ts +90 -0
- package/typescript/test/typedDynamic.test.ts +88 -0
- package/typescript/tsconfig.json +15 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createAjv } from '@jsonforms/core';
|
|
3
|
+
import { forSchema, type TypedLayout } from '../src/authoring/forSchema';
|
|
4
|
+
import type { DataOf } from '../src/authoring/schemaTypes';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
Two halves, and the second is the one that matters.
|
|
8
|
+
|
|
9
|
+
The runtime half checks that the pointer this builds is the pointer
|
|
10
|
+
`Scope<P>` claims it builds - they are tied together by a cast, and a cast
|
|
11
|
+
is exactly the place where a type and a value drift apart unseen.
|
|
12
|
+
|
|
13
|
+
The compile-time half is written with `@ts-expect-error`. Each one asserts
|
|
14
|
+
that the line below it **does not compile**; if the checking ever stops
|
|
15
|
+
working, the directive becomes unused and `tsc` fails on the directive
|
|
16
|
+
itself. `vitest` alone would never notice, so this file is only a complete
|
|
17
|
+
guard when `tsc --noEmit -p test/tsconfig.json` runs - which `pnpm build`
|
|
18
|
+
does.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const schema = {
|
|
22
|
+
type: 'object',
|
|
23
|
+
required: ['email'],
|
|
24
|
+
properties: {
|
|
25
|
+
email: { type: 'string', format: 'email' },
|
|
26
|
+
age: { type: 'integer', minimum: 0 },
|
|
27
|
+
subscribed: { type: 'boolean' },
|
|
28
|
+
address: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
city: { type: 'string' },
|
|
32
|
+
postcode: { type: 'string' },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
orders: {
|
|
36
|
+
type: 'array',
|
|
37
|
+
items: { type: 'object', properties: { reference: { type: 'string' } } },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
const f = forSchema(schema);
|
|
43
|
+
|
|
44
|
+
describe('the pointer a typed scope produces', () => {
|
|
45
|
+
it('matches the literal type it is declared to have', () => {
|
|
46
|
+
// Each annotation is the `Scope<P>` the builder promises; assigning the
|
|
47
|
+
// produced string to it is what proves the two agree.
|
|
48
|
+
const top: '#/properties/email' = f.scope('email');
|
|
49
|
+
const nested: '#/properties/address/properties/city' =
|
|
50
|
+
f.scope('address.city');
|
|
51
|
+
expect(top).toBe('#/properties/email');
|
|
52
|
+
expect(nested).toBe('#/properties/address/properties/city');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('resolves against the schema it was built from', () => {
|
|
56
|
+
// The pointer has to be one Ajv can follow, not merely a tidy string.
|
|
57
|
+
const ajv = createAjv();
|
|
58
|
+
const validate = ajv.compile({
|
|
59
|
+
...schema,
|
|
60
|
+
properties: { ...schema.properties, value: { $ref: f.scope('address.city') } },
|
|
61
|
+
} as any);
|
|
62
|
+
expect(typeof validate).toBe('function');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('builds an ordinary portable element, with nothing extra on it', () => {
|
|
66
|
+
expect(f.control('age', { options: { slider: true } })).toEqual({
|
|
67
|
+
type: 'Control',
|
|
68
|
+
scope: '#/properties/age',
|
|
69
|
+
options: { slider: true },
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('what the types reject', () => {
|
|
75
|
+
it('rejects the mistakes a scope string cannot', () => {
|
|
76
|
+
// @ts-expect-error a misspelled property
|
|
77
|
+
f.control('emial');
|
|
78
|
+
// @ts-expect-error a misspelled nested property
|
|
79
|
+
f.control('address.postcod');
|
|
80
|
+
// @ts-expect-error a path that continues past a leaf
|
|
81
|
+
f.control('address.city.suburb');
|
|
82
|
+
// @ts-expect-error an array is terminal: an item scope is relative to it
|
|
83
|
+
f.control('orders.reference');
|
|
84
|
+
// @ts-expect-error a numeric option on a string
|
|
85
|
+
f.control('email', { options: { slider: true } });
|
|
86
|
+
// @ts-expect-error a string option on a number
|
|
87
|
+
f.control('age', { options: { multi: true } });
|
|
88
|
+
// @ts-expect-error the right option, the wrong value type
|
|
89
|
+
f.control('age', { options: { slider: 'yes' } });
|
|
90
|
+
// @ts-expect-error a misspelled element key
|
|
91
|
+
f.control('email', { labl: 'typo' });
|
|
92
|
+
f.control('email', {
|
|
93
|
+
rule: {
|
|
94
|
+
effect: 'HIDE',
|
|
95
|
+
// @ts-expect-error a rule's condition scope is checked too
|
|
96
|
+
condition: { scope: f.scope('nope'), schema: {} },
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
expect(true).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('derives the data type, including which keys are required', () => {
|
|
103
|
+
type Data = DataOf<typeof schema>;
|
|
104
|
+
const ok: Data = { email: 'a@b.c', age: 3, address: { city: 'Sofia' } };
|
|
105
|
+
// @ts-expect-error `age` is an integer
|
|
106
|
+
const wrongType: Data = { email: 'a@b.c', age: 'old' };
|
|
107
|
+
// @ts-expect-error `email` is required
|
|
108
|
+
const missing: Data = { age: 3 };
|
|
109
|
+
expect(ok.email).toBe('a@b.c');
|
|
110
|
+
expect(wrongType).toBeDefined();
|
|
111
|
+
expect(missing).toBeDefined();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('authors the upstream array detail modes without altering their spelling', () => {
|
|
116
|
+
for (const detail of ['DEFAULT', 'generate', 'REGISTERED', 'GENERATED', 'custom']) {
|
|
117
|
+
const control = f.control('orders', {options: {detail}});
|
|
118
|
+
expect(control.options?.detail).toBe(detail);
|
|
119
|
+
}
|
|
120
|
+
// @ts-expect-error Detail must be a mode or layout, not a boolean.
|
|
121
|
+
f.control('orders', {options: {detail: true}});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('authors editor modes and per-type mixed details', () => {
|
|
125
|
+
const editor = f.control('address', {options: {
|
|
126
|
+
detail: 'REGISTERED',
|
|
127
|
+
'object-detail': {type: 'Control', scope: '#/properties/city'},
|
|
128
|
+
recursiveTree: {childrenProperty: 'children', labelProperty: 'name', detail: 'GENERATE'}
|
|
129
|
+
}});
|
|
130
|
+
expect(editor.options?.detail).toBe('REGISTERED');
|
|
131
|
+
// @ts-expect-error Detail overrides must be editor layouts or strings.
|
|
132
|
+
f.control('address', {options: {'object-detail': true}});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('authors conditional fields with an explicit opt-out', () => {
|
|
136
|
+
expect(f.control('address', {options: {conditionalFields: true}}).options?.conditionalFields).toBe(true);
|
|
137
|
+
expect(f.control('address', {options: {conditionalFields: false}}).options?.conditionalFields).toBe(false);
|
|
138
|
+
// @ts-expect-error The opt-in is a boolean, not a presentation mode.
|
|
139
|
+
f.control('address', {options: {conditionalFields: 'auto'}});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
it('types conditional object presentation on layout entries', () => {
|
|
144
|
+
const layout: TypedLayout<typeof schema> = {type:'VerticalLayout',elements:[],options:{conditionalFields:true}};
|
|
145
|
+
expect(layout.options?.conditionalFields).toBe(true);
|
|
146
|
+
const invalid: TypedLayout<typeof schema> = {type:'Group',elements:[],options:{
|
|
147
|
+
// @ts-expect-error Layout conditionalFields must be a boolean.
|
|
148
|
+
conditionalFields:'auto'
|
|
149
|
+
}};
|
|
150
|
+
expect(invalid.type).toBe('Group');
|
|
151
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
forSchema,
|
|
4
|
+
type AuthoredSchema,
|
|
5
|
+
type DataOf,
|
|
6
|
+
} from '../src';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
"Can I express everything the JSON way can?"
|
|
10
|
+
|
|
11
|
+
This file is the answer, kept honest. Every element kind and awkward schema
|
|
12
|
+
shape that a real form uses is built here; the `@ts-expect-error` lines mark
|
|
13
|
+
the two things that are *not* expressible and cannot be, so that if either
|
|
14
|
+
ever becomes possible the directive goes unused and the build fails.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const schema = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
required: ['email'],
|
|
20
|
+
properties: {
|
|
21
|
+
email: { type: 'string' },
|
|
22
|
+
kind: { type: 'string', enum: ['a', 'b'] },
|
|
23
|
+
orders: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
items: { type: 'object', properties: { ref: { type: 'string' } } },
|
|
26
|
+
},
|
|
27
|
+
extras: { type: 'object', additionalProperties: { type: 'string' } },
|
|
28
|
+
choice: { oneOf: [{ type: 'string' }, { type: 'number' }] },
|
|
29
|
+
tuple: { type: 'array', items: [{ type: 'string' }, { type: 'number' }] },
|
|
30
|
+
home: { $ref: '#/$defs/addr' },
|
|
31
|
+
},
|
|
32
|
+
// `$defs` is why AuthoredSchema carries an index signature: JsonSchema7
|
|
33
|
+
// declares draft-07's `definitions` and not this.
|
|
34
|
+
$defs: { addr: { type: 'object', properties: { city: { type: 'string' } } } },
|
|
35
|
+
} as const satisfies AuthoredSchema;
|
|
36
|
+
|
|
37
|
+
const f = forSchema(schema);
|
|
38
|
+
|
|
39
|
+
describe('every element kind is expressible', () => {
|
|
40
|
+
it('authors Label substitution marker overrides without adding an inherited default', () => {
|
|
41
|
+
const inherited = f.label({ text: 'Membership details' });
|
|
42
|
+
expect(inherited.options?.textParamSpans).toBeUndefined();
|
|
43
|
+
for (const textParamSpans of [true, false]) {
|
|
44
|
+
const label = f.label({ text: 'Membership details', options: { textParamSpans } });
|
|
45
|
+
expect(label.options?.textParamSpans).toBe(textParamSpans);
|
|
46
|
+
}
|
|
47
|
+
// @ts-expect-error A local override must be boolean.
|
|
48
|
+
f.label({ text: 'Membership details', options: { textParamSpans: 'true' } });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('preserves host styling parts on controls and layout slots', () => {
|
|
52
|
+
const control = f.control('email', { options: { part: 'primary contact' } });
|
|
53
|
+
const ui = f.layout({
|
|
54
|
+
type: 'VerticalLayout',
|
|
55
|
+
options: { part: 'contact-section' },
|
|
56
|
+
elements: [
|
|
57
|
+
control,
|
|
58
|
+
f.label({ text: 'Contact details', options: { part: 'heading' } }),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
expect(ui.options?.part).toBe('contact-section');
|
|
62
|
+
expect(control.options?.part).toBe('primary contact');
|
|
63
|
+
// @ts-expect-error Parts use the serialized string shape, not an array.
|
|
64
|
+
f.control('email', { options: { part: ['primary'] } });
|
|
65
|
+
f.layout({
|
|
66
|
+
type: 'VerticalLayout',
|
|
67
|
+
// @ts-expect-error Layout markers use the same string shape.
|
|
68
|
+
options: { part: ['contact-section'] },
|
|
69
|
+
elements: [],
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('authors Group regions in the current schema context', () => {
|
|
74
|
+
const ui = f.layout({
|
|
75
|
+
type: 'Group',
|
|
76
|
+
label: 'Contact',
|
|
77
|
+
cover: f.raw({ type: 'ImageView', src: '/contact.jpg', alt: 'Office' }),
|
|
78
|
+
header: [f.label({ text: 'Verified' })],
|
|
79
|
+
elements: [f.control('email')],
|
|
80
|
+
footer: [f.raw({ type: 'Button', label: 'Verify', action: 'verify' })],
|
|
81
|
+
});
|
|
82
|
+
expect(ui.cover?.type).toBe('ImageView');
|
|
83
|
+
expect(ui.header).toHaveLength(1);
|
|
84
|
+
expect(ui.footer).toHaveLength(1);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('builds labels, categories, rules and the root scope', () => {
|
|
88
|
+
const ui = f.layout({
|
|
89
|
+
type: 'Categorization',
|
|
90
|
+
elements: [
|
|
91
|
+
f.category({
|
|
92
|
+
label: 'Contact',
|
|
93
|
+
elements: [
|
|
94
|
+
f.label({ text: 'Tell us how to reach you' }),
|
|
95
|
+
f.control('email', { i18n: 'email', label: { text: 'E', show: true } }),
|
|
96
|
+
f.control('kind', {
|
|
97
|
+
rule: {
|
|
98
|
+
effect: 'HIDE',
|
|
99
|
+
condition: {
|
|
100
|
+
type: 'AND',
|
|
101
|
+
conditions: [
|
|
102
|
+
{ scope: f.scope('email'), schema: { minLength: 1 } },
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
expect(ui.elements).toHaveLength(1);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('addresses the root of the schema', () => {
|
|
115
|
+
expect(f.control('')).toEqual({ type: 'Control', scope: '#' });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('takes anything it does not model through `raw`', () => {
|
|
119
|
+
// An extended element this module knows nothing about.
|
|
120
|
+
const button = f.raw({ type: 'Button', label: 'Go', action: 'submit' });
|
|
121
|
+
// An option the curated map does not carry - note the scope is still typed.
|
|
122
|
+
const withOption = f.raw({
|
|
123
|
+
type: 'Control',
|
|
124
|
+
scope: f.scope('email'),
|
|
125
|
+
options: { autocomplete: true },
|
|
126
|
+
});
|
|
127
|
+
expect(button.type).toBe('Button');
|
|
128
|
+
expect(withOption.scope).toBe('#/properties/email');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('the shapes that degrade rather than block', () => {
|
|
133
|
+
type D = DataOf<typeof schema>;
|
|
134
|
+
|
|
135
|
+
it('still addresses a combinator, a tuple, a map and a $ref as wholes', () => {
|
|
136
|
+
expect([
|
|
137
|
+
f.control('choice').scope,
|
|
138
|
+
f.control('tuple').scope,
|
|
139
|
+
f.control('extras').scope,
|
|
140
|
+
f.control('home').scope,
|
|
141
|
+
]).toEqual([
|
|
142
|
+
'#/properties/choice',
|
|
143
|
+
'#/properties/tuple',
|
|
144
|
+
'#/properties/extras',
|
|
145
|
+
'#/properties/home',
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('gives up on their data types rather than getting them wrong', () => {
|
|
150
|
+
// Each of these is `unknown`-ish: no checking, but nothing is blocked.
|
|
151
|
+
const combinator: D['choice'] = 'anything at all';
|
|
152
|
+
const viaRef: D['home'] = { city: 'Sofia' };
|
|
153
|
+
const dynamic: D['extras'] = { whatever: 'x' };
|
|
154
|
+
expect([combinator, viaRef, dynamic]).toHaveLength(3);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('cannot address what has no compile-time name', () => {
|
|
158
|
+
// @ts-expect-error a dynamic property has no name until runtime
|
|
159
|
+
f.control('extras.anything');
|
|
160
|
+
// @ts-expect-error a combinator branch is not traversed
|
|
161
|
+
f.control('choice.0');
|
|
162
|
+
expect(true).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('documented control variants', () => {
|
|
167
|
+
it('authors OTP and array variants without an escape hatch', () => {
|
|
168
|
+
const model = { type: 'object', properties: {
|
|
169
|
+
code: { type: 'string', format: 'password', minLength: 6, maxLength: 6 },
|
|
170
|
+
tags: { type: 'array', items: { type: 'string' } }
|
|
171
|
+
}} as const satisfies AuthoredSchema;
|
|
172
|
+
const author = forSchema(model);
|
|
173
|
+
expect(author.control('code', { options: { variant: 'otp' } }).options?.variant).toBe('otp');
|
|
174
|
+
for (const variant of ['chips', 'multi-select', 'tuple', 'ag-grid'] as const) {
|
|
175
|
+
expect(author.control('tags', { options: { variant } }).options?.variant).toBe(variant);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
forSchema,
|
|
4
|
+
type AuthoredSchema,
|
|
5
|
+
type CssLength,
|
|
6
|
+
} from '../src';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
The sizing options are the one place in this module where the type is
|
|
10
|
+
*narrower* than the runtime: `toCss` passes any string through, so this type
|
|
11
|
+
can only ever be a subset of what works. That makes a false rejection worse
|
|
12
|
+
than a missed mistake - it turns correct CSS into a build failure - so what
|
|
13
|
+
it accepts is pinned here rather than left to whoever edits the unit list.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const schema = {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: { note: { type: 'string' } },
|
|
19
|
+
} as const satisfies AuthoredSchema;
|
|
20
|
+
|
|
21
|
+
const f = forSchema(schema);
|
|
22
|
+
|
|
23
|
+
describe('what a sizing option accepts', () => {
|
|
24
|
+
it('takes the values this repository already authors', () => {
|
|
25
|
+
// Straight from the spec examples' uischemas.
|
|
26
|
+
const used: CssLength[] = [180, 120, 64, '1rem', '0.5rem', '1.5rem', '14rem', '10rem'];
|
|
27
|
+
expect(used).toHaveLength(8);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('takes the responsive notations, not only calc()', () => {
|
|
31
|
+
const responsive: CssLength[] = [
|
|
32
|
+
'calc(100% - 16px)',
|
|
33
|
+
'clamp(1rem, 2vw, 3rem)',
|
|
34
|
+
'min(100px, 50%)',
|
|
35
|
+
'max(20ch, 30%)',
|
|
36
|
+
'var(--field-width)',
|
|
37
|
+
'fit-content(20rem)',
|
|
38
|
+
];
|
|
39
|
+
expect(responsive).toHaveLength(6);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('takes units a short list would have broken', () => {
|
|
43
|
+
const units: CssLength[] = ['2vmin', '50dvh', '10pt', '3lh', '20ch', '0'];
|
|
44
|
+
expect(units).toHaveLength(6);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('takes the sizing keywords', () => {
|
|
48
|
+
const keywords: CssLength[] = ['auto', 'none', 'min-content', 'fit-content', 'stretch'];
|
|
49
|
+
expect(keywords).toHaveLength(5);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('rejects what is actually a mistake', () => {
|
|
53
|
+
// @ts-expect-error a number in a string, with no unit
|
|
54
|
+
const noUnit: CssLength = '100';
|
|
55
|
+
// @ts-expect-error not a length at all
|
|
56
|
+
const nonsense: CssLength = 'pixels';
|
|
57
|
+
// @ts-expect-error `fr` is a grid unit; these layouts are flex, so it
|
|
58
|
+
// would be accepted by the type and ignored by the browser
|
|
59
|
+
const gridUnit: CssLength = '1fr';
|
|
60
|
+
expect([noUnit, nonsense, gridUnit]).toHaveLength(3);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('the option names are the ones the renderer reads', () => {
|
|
65
|
+
it('accepts minWidth and friends', () => {
|
|
66
|
+
const control = f.control('note', {
|
|
67
|
+
options: {
|
|
68
|
+
layout: { span: 4, minWidth: '20ch', maxWidth: '40rem', height: 'auto' },
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
expect(control.options?.layout?.minWidth).toBe('20ch');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('rejects the short forms, which nothing reads', () => {
|
|
75
|
+
f.control('note', {
|
|
76
|
+
// @ts-expect-error `itemSizing` reads `minWidth`, never `min`
|
|
77
|
+
options: { layout: { min: 10 } },
|
|
78
|
+
});
|
|
79
|
+
expect(true).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createAjv } from '@jsonforms/core';
|
|
3
|
+
import {
|
|
4
|
+
forSchema,
|
|
5
|
+
type AuthoredSchema,
|
|
6
|
+
} from '../src';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
Property names that collide with the addressing scheme.
|
|
10
|
+
|
|
11
|
+
Three separate problems wearing the same clothes, and they do not have the
|
|
12
|
+
same answer:
|
|
13
|
+
|
|
14
|
+
- `properties` as a *name* is fine. `#/properties/properties` is the
|
|
15
|
+
keyword followed by the property, and nothing is ambiguous.
|
|
16
|
+
- `/` and `~` are legal in a pointer once escaped (RFC 6901), so they stay
|
|
17
|
+
addressable - the escaping is done for you, the same way core's own
|
|
18
|
+
`getPropPath` does it.
|
|
19
|
+
- `.` has no escape in JSON Forms' path grammar, so such a property has no
|
|
20
|
+
scope at all. It is left out of the offered paths rather than given a
|
|
21
|
+
pointer that resolves to nothing.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const schema = {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
// A property literally named `properties`, itself an object.
|
|
28
|
+
properties: { type: 'object', properties: { city: { type: 'string' } } },
|
|
29
|
+
// The two characters JSON Pointer reserves.
|
|
30
|
+
'a/b': { type: 'string' },
|
|
31
|
+
'c~d': { type: 'string' },
|
|
32
|
+
// Names that look like schema keywords but are only names here.
|
|
33
|
+
items: { type: 'string' },
|
|
34
|
+
type: { type: 'string' },
|
|
35
|
+
// Not addressable: the path grammar has no escape for a dot.
|
|
36
|
+
'first.name': { type: 'string' },
|
|
37
|
+
},
|
|
38
|
+
} as const satisfies AuthoredSchema;
|
|
39
|
+
|
|
40
|
+
const f = forSchema(schema);
|
|
41
|
+
|
|
42
|
+
/** Follows a `#/...` pointer by hand, decoding per RFC 6901. */
|
|
43
|
+
const resolve = (pointer: string): unknown =>
|
|
44
|
+
pointer
|
|
45
|
+
.slice(2)
|
|
46
|
+
.split('/')
|
|
47
|
+
.reduce<any>(
|
|
48
|
+
(node, raw) => node?.[raw.replace(/~1/g, '/').replace(/~0/g, '~')],
|
|
49
|
+
schema
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
describe('property names that collide with the addressing scheme', () => {
|
|
53
|
+
it('addresses a property named `properties`, nested or not', () => {
|
|
54
|
+
expect(f.scope('properties')).toBe('#/properties/properties');
|
|
55
|
+
expect(f.scope('properties.city')).toBe(
|
|
56
|
+
'#/properties/properties/properties/city'
|
|
57
|
+
);
|
|
58
|
+
// And both pointers land on a real sub-schema.
|
|
59
|
+
expect(resolve(f.scope('properties.city'))).toEqual({ type: 'string' });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('escapes the two characters a pointer reserves', () => {
|
|
63
|
+
expect(f.scope('a/b')).toBe('#/properties/a~1b');
|
|
64
|
+
expect(f.scope('c~d')).toBe('#/properties/c~0d');
|
|
65
|
+
// Unescaped, `#/properties/a/b` would walk into a property called `a`.
|
|
66
|
+
expect(resolve(f.scope('a/b'))).toEqual({ type: 'string' });
|
|
67
|
+
expect(resolve(f.scope('c~d'))).toEqual({ type: 'string' });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('addresses names that merely look like keywords', () => {
|
|
71
|
+
expect(resolve(f.scope('items'))).toEqual({ type: 'string' });
|
|
72
|
+
expect(resolve(f.scope('type'))).toEqual({ type: 'string' });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('refuses a name containing a dot instead of mis-addressing it', () => {
|
|
76
|
+
// @ts-expect-error `first.name` has no scope: the grammar has no escape
|
|
77
|
+
f.scope('first.name');
|
|
78
|
+
/*
|
|
79
|
+
What the wrong answer would have been. Left as an assertion because it
|
|
80
|
+
is the reason for the refusal: the pointer is well-formed, resolves to
|
|
81
|
+
nothing, and reports no error anywhere.
|
|
82
|
+
*/
|
|
83
|
+
expect(resolve('#/properties/first/properties/name')).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('still validates such data - the name is legal, only unaddressable', () => {
|
|
87
|
+
const validate = createAjv().compile(schema as any);
|
|
88
|
+
expect(validate({ 'first.name': 'Ada', 'a/b': 'x' })).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { forSchema } from '../src/authoring/forSchema';
|
|
3
|
+
import type { DynamicDescriptor, DynamicSpec, TrustedDynamicSpec } from '../src/authoring/dynamic';
|
|
4
|
+
import { withTrustedDynamic } from '../src/authoring/dynamic';
|
|
5
|
+
|
|
6
|
+
const form = forSchema({
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: { plan: { type: 'string' } },
|
|
9
|
+
} as const);
|
|
10
|
+
|
|
11
|
+
it('authors portable overlays on typed controls without losing static scope checking', () => {
|
|
12
|
+
const control = form.control('plan', {
|
|
13
|
+
$dynamic: [
|
|
14
|
+
{ overlay: { label: { bind: 'external.settings.label' } } },
|
|
15
|
+
{
|
|
16
|
+
when: { expression: "external.settings.presentation == 'radio'" },
|
|
17
|
+
overlay: { options: { format: 'radio', readonly: { bind: 'external.readonly' } } },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
expect(control.$dynamic).toHaveLength(2);
|
|
22
|
+
// @ts-expect-error portable conditions require boolean or an expression descriptor
|
|
23
|
+
const invalidCondition: DynamicSpec<{ label: string }> = [{ when: 'yes', overlay: {} }];
|
|
24
|
+
// @ts-expect-error known option values retain their declared types
|
|
25
|
+
form.control('plan', { $dynamic: { options: { readonly: 'yes' } } });
|
|
26
|
+
expect(invalidCondition).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('checks metadata, extension values, complete array entries and template targets', () => {
|
|
30
|
+
form.control('plan', { $dynamic: { options: { customExtension: { nested: { bind: 'external.value' } } } } });
|
|
31
|
+
// @ts-expect-error the current element cannot overwrite its own resolver metadata
|
|
32
|
+
const metadata: DynamicSpec<{ label: string }> = { $dynamic: {} };
|
|
33
|
+
// @ts-expect-error unknown portable extension keys cannot contain functions
|
|
34
|
+
const executable: DynamicSpec<{ label: string }> = { customExtension: () => 'unsafe' };
|
|
35
|
+
// @ts-expect-error templates return strings, not numeric targets
|
|
36
|
+
const numeric: DynamicSpec<{ count: number }> = { count: { template: '{data.count}' } };
|
|
37
|
+
// @ts-expect-error replacement array entries need the required type discriminator
|
|
38
|
+
const incomplete: DynamicSpec<{ elements: { type: 'Control'; scope: string }[] }> = { elements: [{ scope: '#' }] };
|
|
39
|
+
expect([metadata, executable, numeric, incomplete]).toHaveLength(4);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('attaches trusted overlays to an otherwise checked authored element', () => {
|
|
43
|
+
const control = withTrustedDynamic(form.control('plan'), {
|
|
44
|
+
label: (environment: Readonly<Record<string, unknown>>) => String(environment.locale),
|
|
45
|
+
});
|
|
46
|
+
expect(control.scope).toBe('#/properties/plan');
|
|
47
|
+
expect(control.$dynamic).toHaveProperty('label');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('keeps trusted function authoring separate from portable JSON', () => {
|
|
51
|
+
const trusted: TrustedDynamicSpec<{ label: string }> = {
|
|
52
|
+
label: (environment) => String(environment.locale),
|
|
53
|
+
};
|
|
54
|
+
// @ts-expect-error executable functions are not portable descriptor leaves
|
|
55
|
+
const portable: DynamicSpec<{ label: string }> = trusted;
|
|
56
|
+
expect(trusted).toBeDefined();
|
|
57
|
+
expect(portable).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('checks complete literal descriptor values', () => {
|
|
61
|
+
const valid: DynamicSpec<{ detail: { type: string; scope: string } }> = {
|
|
62
|
+
detail: { literal: { type: 'Control', scope: '#/properties/name' } },
|
|
63
|
+
};
|
|
64
|
+
// @ts-expect-error atomic replacement requires a complete target
|
|
65
|
+
const incomplete: DynamicDescriptor<{ type: string; scope: string }> = { literal: { type: 'Control' } };
|
|
66
|
+
expect(valid.detail).toBeDefined();
|
|
67
|
+
expect(incomplete).toBeDefined();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('permits a real literal field when another target key makes the object ordinary data', () => {
|
|
71
|
+
type Target = { custom: { literal: string; other: number } };
|
|
72
|
+
const portable: DynamicSpec<Target> = { custom: { literal: 'data', other: 1 } };
|
|
73
|
+
const trusted: TrustedDynamicSpec<Target> = { custom: { literal: 'data', other: () => 2 } };
|
|
74
|
+
// @ts-expect-error the real literal field retains its declared type
|
|
75
|
+
const wrong: DynamicSpec<Target> = { custom: { literal: 3, other: 1 } };
|
|
76
|
+
// Broad patches cannot prove the key-count distinction; explicit descriptors can.
|
|
77
|
+
// @ts-expect-error a complete object cannot be replaced with a string
|
|
78
|
+
const ambiguous: DynamicDescriptor<Target['custom']> = { literal: 'data' };
|
|
79
|
+
expect([portable, trusted, wrong, ambiguous]).toHaveLength(4);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('allows literal-named data beside unknown extension keys', () => {
|
|
83
|
+
type Target = { custom: { literal: string; known?: boolean }; options: { readonly?: boolean } };
|
|
84
|
+
const first: DynamicSpec<Target> = { custom: { literal: 'data', extra: 1 } };
|
|
85
|
+
const second: DynamicSpec<Target> = { options: { literal: 'data', theme: 'x' } };
|
|
86
|
+
const trusted: TrustedDynamicSpec<Target> = { options: { literal: 'data', theme: 'x' } };
|
|
87
|
+
expect([first, second, trusted]).toHaveLength(3);
|
|
88
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"outDir": "lib"
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"src/**/*.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|