@strictly/define 0.0.1 → 0.0.2
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/.out/index.d.ts +17 -11
- package/.out/index.js +17 -11
- package/.out/transformers/copies/copy.d.ts +3 -3
- package/.out/transformers/copies/copy_to.d.ts +3 -3
- package/.out/transformers/copies/copy_to.js +4 -0
- package/.out/transformers/copies/mobx_copy.d.ts +4 -4
- package/.out/transformers/copies/mobx_copy.js +1 -1
- package/.out/transformers/copies/specs/copy_to.tests.js +8 -8
- package/.out/transformers/copies/specs/mobx_copy.tests.js +1 -1
- package/.out/transformers/flatteners/flatten_accessors_of_type.d.ts +5 -0
- package/.out/transformers/flatteners/flatten_accessors_of_type.js +11 -0
- package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.d.ts +2 -2
- package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.js +2 -2
- package/.out/transformers/flatteners/{flatten_type_def_to.d.ts → flatten_type_to.d.ts} +1 -1
- package/.out/transformers/flatteners/{flatten_type_def_to.js → flatten_type_to.js} +1 -1
- package/.out/transformers/flatteners/{flatten_type_defs_of.d.ts → flatten_types_of_type.d.ts} +1 -1
- package/.out/transformers/flatteners/flatten_types_of_type.js +7 -0
- package/.out/transformers/flatteners/flatten_validation_errors_of_type.d.ts +22 -0
- package/.out/transformers/flatteners/flatten_validation_errors_of_type.js +10 -0
- package/.out/transformers/flatteners/flatten_validators_of_validating_type.d.ts +4 -0
- package/.out/transformers/flatteners/flatten_validators_of_validating_type.js +17 -0
- package/.out/transformers/flatteners/{flatten_value_type_to.d.ts → flatten_value_to.d.ts} +4 -4
- package/.out/transformers/flatteners/{flatten_value_type_to.js → flatten_value_to.js} +7 -2
- package/.out/transformers/flatteners/flatten_values_of_type.d.ts +3 -0
- package/.out/transformers/flatteners/flatten_values_of_type.js +7 -0
- package/.out/transformers/flatteners/specs/{flatten_accessors_of.tests.js → flatten_accessors_of_type.tests.js} +5 -6
- package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.js +6 -6
- package/.out/transformers/flatteners/specs/{flatten_type_def_to.tests.js → flatten_type_to.tests.js} +15 -13
- package/.out/transformers/flatteners/specs/flatten_types_of_type.tests.js +18 -0
- package/.out/transformers/flatteners/specs/flatten_validation_errors_of_type.tests.js +25 -0
- package/.out/transformers/flatteners/specs/{flatten_value_type_to.tests.js → flatten_value_to.tests.js} +81 -58
- package/.out/transformers/flatteners/specs/{flatten_value_types_of.tests.js → flatten_values_of_type.tests.js} +4 -4
- package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.js +5 -3
- package/.out/transformers/flatteners/value_path_to_type_path.d.ts +1 -1
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/builders.d.ts +55 -29
- package/.out/types/builders.js +116 -32
- package/.out/types/definitions.d.ts +1 -1
- package/.out/types/flattened_accessors_of_type.d.ts +9 -0
- package/.out/types/{flattened_type_defs_of.d.ts → flattened_types_of_type.d.ts} +9 -6
- package/.out/types/flattened_types_of_validating_type.d.ts +25 -0
- package/.out/types/flattened_validators_of_validating_type.d.ts +10 -0
- package/.out/types/flattened_values_of_type.d.ts +6 -0
- package/.out/types/{mobx_value_type_of.d.ts → mobx_value_of_type.d.ts} +2 -2
- package/.out/types/{partial_type_def_of.d.ts → partial_type_of_type.d.ts} +1 -1
- package/.out/types/path_of.d.ts +1 -0
- package/.out/types/{json_paths_of.d.ts → paths_of_type.d.ts} +5 -5
- package/.out/types/readonly_type_of_type.d.ts +29 -0
- package/.out/types/specs/builder.tests.js +73 -23
- package/.out/types/specs/{flattened_accessors_of.tests.js → flattened_accessors_of_type.tests.js} +1 -1
- package/.out/types/specs/{flattened_type_defs_of.tests.js → flattened_types_of_type.tests.js} +22 -15
- package/.out/types/specs/flattened_validators_of_validating_type.tests.js +24 -0
- package/.out/types/specs/flattened_values_of_type.tests.js +18 -0
- package/.out/types/specs/{partial_type_def_of.tests.js → partial_type_of_type.tests.js} +4 -4
- package/.out/types/specs/{json_paths_of.tests.js → paths_of_type.tests.js} +19 -19
- package/.out/types/specs/{readonly_type_def_of.tests.js → readonly_type_of_type.tests.js} +6 -6
- package/.out/types/specs/type_of_type.tests.d.ts +1 -0
- package/.out/types/specs/type_of_type.tests.js +27 -0
- package/.out/types/specs/value_of_type.tests.d.ts +1 -0
- package/.out/types/specs/{value_type_of.tests.js → value_of_type.tests.js} +1 -1
- package/.out/types/specs/value_to_type_paths_of_type.tests.d.ts +1 -0
- package/.out/types/specs/{value_to_type_paths_of.tests.js → value_to_type_paths_of_type.tests.js} +9 -9
- package/.out/types/specs/value_types_of_discriminated_union.tests.js +2 -2
- package/.out/types/strict_definitions.d.ts +2 -2
- package/.out/types/type_of_type.d.ts +49 -0
- package/.out/types/type_of_type.js +70 -0
- package/.out/types/validating_definitions.d.ts +49 -0
- package/.out/types/validating_definitions.js +1 -0
- package/.out/types/validating_type_def_with_error.d.ts +55 -0
- package/.out/types/validating_type_def_with_error.js +1 -0
- package/.out/types/value_of_type.d.ts +24 -0
- package/.out/types/value_of_type.js +1 -0
- package/.out/types/{value_to_type_paths_of.d.ts → value_to_type_paths_of_type.d.ts} +13 -13
- package/.out/types/value_to_type_paths_of_type.js +1 -0
- package/.out/types/value_types_of_discriminated_union.d.ts +5 -4
- package/.out/validation/errors_of_validators.d.ts +4 -0
- package/.out/validation/errors_of_validators.js +1 -0
- package/.out/validation/specs/errors_of_validators.tests.d.ts +1 -0
- package/.out/validation/specs/errors_of_validators.tests.js +9 -0
- package/.out/validation/specs/validators_of_values.tests.d.ts +1 -0
- package/.out/validation/specs/validators_of_values.tests.js +21 -0
- package/.out/validation/validator.d.ts +21 -0
- package/.out/validation/validator.js +26 -0
- package/.out/validation/validators/defined_validator.d.ts +10 -0
- package/.out/validation/validators/defined_validator.js +18 -0
- package/.out/validation/validators/minimum_string_length_validator.d.ts +16 -0
- package/.out/validation/validators/minimum_string_length_validator.js +23 -0
- package/.out/validation/validators_of_values.d.ts +4 -0
- package/.out/validation/validators_of_values.js +1 -0
- package/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/README.md +16 -2
- package/dist/index.cjs +364 -76
- package/dist/index.d.cts +365 -114
- package/dist/index.d.ts +365 -114
- package/dist/index.js +355 -73
- package/index.ts +17 -11
- package/package.json +11 -3
- package/transformers/copies/copy.ts +4 -4
- package/transformers/copies/copy_to.ts +11 -7
- package/transformers/copies/mobx_copy.ts +6 -6
- package/transformers/copies/specs/copy_to.tests.ts +8 -8
- package/transformers/copies/specs/mobx_copy.tests.ts +3 -3
- package/transformers/flatteners/{flatten_accessors_of.ts → flatten_accessors_of_type.ts} +10 -10
- package/transformers/flatteners/flatten_json_value_to_type_paths_of.ts +5 -5
- package/transformers/flatteners/{flatten_type_def_to.ts → flatten_type_to.ts} +1 -1
- package/transformers/flatteners/{flatten_type_defs_of.ts → flatten_types_of_type.ts} +3 -3
- package/transformers/flatteners/flatten_validation_errors_of_type.ts +93 -0
- package/transformers/flatteners/flatten_validators_of_validating_type.ts +32 -0
- package/transformers/flatteners/{flatten_value_type_to.ts → flatten_value_to.ts} +12 -7
- package/transformers/flatteners/{flatten_value_types_of.ts → flatten_values_of_type.ts} +6 -6
- package/transformers/flatteners/specs/{flatten_accessors_of.tests.ts → flatten_accessors_of_type.tests.ts} +10 -11
- package/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.ts +6 -6
- package/transformers/flatteners/specs/{flatten_type_def_to.tests.ts → flatten_type_to.tests.ts} +15 -13
- package/transformers/flatteners/specs/flatten_types_of_type.tests.ts +27 -0
- package/transformers/flatteners/specs/flatten_validation_errors_of_type.tests.ts +48 -0
- package/transformers/flatteners/specs/{flatten_value_type_to.tests.ts → flatten_value_to.tests.ts} +124 -91
- package/transformers/flatteners/specs/{flatten_value_types_of.tests.ts → flatten_values_of_type.tests.ts} +4 -4
- package/transformers/flatteners/specs/value_path_to_type_path.tests.ts +20 -18
- package/transformers/flatteners/value_path_to_type_path.ts +4 -4
- package/types/builders.ts +239 -71
- package/types/definitions.ts +2 -2
- package/types/{flattened_accessors_of.ts → flattened_accessors_of_type.ts} +3 -3
- package/types/{flattened_type_defs_of.ts → flattened_types_of_type.ts} +22 -12
- package/types/flattened_types_of_validating_type.ts +152 -0
- package/types/flattened_validators_of_validating_type.ts +33 -0
- package/types/flattened_values_of_type.ts +11 -0
- package/types/{mobx_value_type_of.ts → mobx_value_of_type.ts} +2 -2
- package/types/{partial_type_def_of.ts → partial_type_of_type.ts} +3 -1
- package/types/{json_path_of.ts → path_of.ts} +1 -1
- package/types/{json_paths_of.ts → paths_of_type.ts} +5 -5
- package/types/readonly_type_of_type.ts +54 -0
- package/types/specs/builder.tests.ts +205 -54
- package/types/specs/{flattened_accessors_of.tests.ts → flattened_accessors_of_type.tests.ts} +3 -3
- package/types/specs/{flattened_type_defs_of.tests.ts → flattened_types_of_type.tests.ts} +82 -34
- package/types/specs/flattened_validators_of_validating_type.tests.ts +47 -0
- package/types/specs/flattened_values_of_type.tests.ts +39 -0
- package/types/specs/{partial_type_def_of.tests.ts → partial_type_of_type.tests.ts} +11 -11
- package/types/specs/{json_paths_of.tests.ts → paths_of_type.tests.ts} +47 -47
- package/types/specs/{readonly_type_def_of.tests.ts → readonly_type_of_type.tests.ts} +14 -14
- package/types/specs/type_of_type.tests.ts +60 -0
- package/types/specs/{value_type_of.tests.ts → value_of_type.tests.ts} +15 -15
- package/types/specs/{value_to_type_paths_of.tests.ts → value_to_type_paths_of_type.tests.ts} +26 -25
- package/types/specs/value_types_of_discriminated_union.tests.ts +6 -6
- package/types/strict_definitions.ts +3 -3
- package/types/type_of_type.ts +178 -0
- package/types/validating_definitions.ts +109 -0
- package/types/validating_type_def_with_error.ts +93 -0
- package/types/value_of_type.ts +84 -0
- package/types/{value_to_type_paths_of.ts → value_to_type_paths_of_type.ts} +30 -29
- package/types/value_types_of_discriminated_union.ts +4 -3
- package/validation/errors_of_validators.ts +10 -0
- package/validation/specs/errors_of_validators.tests.ts +20 -0
- package/validation/specs/validators_of_values.tests.ts +68 -0
- package/validation/validator.ts +103 -0
- package/validation/validators/defined_validator.ts +22 -0
- package/validation/validators/minimum_string_length_validator.ts +36 -0
- package/validation/validators_of_values.ts +17 -0
- package/.out/transformers/flatteners/flatten_accessors_of.d.ts +0 -5
- package/.out/transformers/flatteners/flatten_accessors_of.js +0 -11
- package/.out/transformers/flatteners/flatten_type_defs_of.js +0 -7
- package/.out/transformers/flatteners/flatten_value_types_of.d.ts +0 -3
- package/.out/transformers/flatteners/flatten_value_types_of.js +0 -7
- package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.js +0 -17
- package/.out/types/flattened_accessors_of.d.ts +0 -9
- package/.out/types/flattened_value_types_of.d.ts +0 -6
- package/.out/types/json_path_of.d.ts +0 -1
- package/.out/types/readonly_type_def_of.d.ts +0 -29
- package/.out/types/specs/flattened_value_types_of.tests.js +0 -11
- package/.out/types/value_type_of.d.ts +0 -24
- package/transformers/flatteners/specs/flatten_type_defs_of.tests.ts +0 -26
- package/types/flattened_value_types_of.ts +0 -11
- package/types/readonly_type_def_of.ts +0 -53
- package/types/specs/flattened_value_types_of.tests.ts +0 -21
- package/types/value_type_of.ts +0 -84
- /package/.out/transformers/flatteners/specs/{flatten_accessors_of.tests.d.ts → flatten_accessors_of_type.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_type_def_to.tests.d.ts → flatten_type_to.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_type_defs_of.tests.d.ts → flatten_types_of_type.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_value_type_to.tests.d.ts → flatten_validation_errors_of_type.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_value_types_of.tests.d.ts → flatten_value_to.tests.d.ts} +0 -0
- /package/.out/{types/flattened_accessors_of.js → transformers/flatteners/specs/flatten_values_of_type.tests.d.ts} +0 -0
- /package/.out/types/{flattened_type_defs_of.js → flattened_accessors_of_type.js} +0 -0
- /package/.out/types/{flattened_value_types_of.js → flattened_types_of_type.js} +0 -0
- /package/.out/types/{json_path_of.js → flattened_types_of_validating_type.js} +0 -0
- /package/.out/types/{json_paths_of.js → flattened_validators_of_validating_type.js} +0 -0
- /package/.out/types/{partial_type_def_of.js → flattened_values_of_type.js} +0 -0
- /package/.out/types/{mobx_value_type_of.js → mobx_value_of_type.js} +0 -0
- /package/.out/types/{readonly_type_def_of.js → partial_type_of_type.js} +0 -0
- /package/.out/types/{specs/flattened_accessors_of.tests.d.ts → path_of.js} +0 -0
- /package/.out/types/{specs/flattened_type_defs_of.tests.d.ts → paths_of_type.js} +0 -0
- /package/.out/types/{specs/flattened_value_types_of.tests.d.ts → readonly_type_of_type.js} +0 -0
- /package/.out/types/specs/{json_paths_of.tests.d.ts → flattened_accessors_of_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{partial_type_def_of.tests.d.ts → flattened_types_of_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{readonly_type_def_of.tests.d.ts → flattened_validators_of_validating_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{value_to_type_paths_of.tests.d.ts → flattened_values_of_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{value_type_of.tests.d.ts → partial_type_of_type.tests.d.ts} +0 -0
- /package/.out/types/{value_to_type_paths_of.js → specs/paths_of_type.tests.d.ts} +0 -0
- /package/.out/types/{value_type_of.js → specs/readonly_type_of_type.tests.d.ts} +0 -0
package/index.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
export * from './transformers/copies/copy'
|
|
2
2
|
export * from './transformers/copies/mobx_copy'
|
|
3
|
-
export * from './transformers/flatteners/
|
|
3
|
+
export * from './transformers/flatteners/flatten_accessors_of_type'
|
|
4
4
|
export * from './transformers/flatteners/flatten_json_value_to_type_paths_of'
|
|
5
|
-
export * from './transformers/flatteners/
|
|
6
|
-
export * from './transformers/flatteners/
|
|
5
|
+
export * from './transformers/flatteners/flatten_types_of_type'
|
|
6
|
+
export * from './transformers/flatteners/flatten_validators_of_validating_type'
|
|
7
|
+
export * from './transformers/flatteners/flatten_value_to'
|
|
8
|
+
export * from './transformers/flatteners/flatten_values_of_type'
|
|
7
9
|
export * from './transformers/flatteners/json_path'
|
|
8
10
|
export * from './transformers/flatteners/value_path_to_type_path'
|
|
9
11
|
export * from './types/builders'
|
|
10
12
|
export * from './types/definitions'
|
|
11
|
-
export * from './types/
|
|
12
|
-
export * from './types/
|
|
13
|
-
export * from './types/
|
|
14
|
-
export * from './types/
|
|
15
|
-
export * from './types/
|
|
16
|
-
export * from './types/
|
|
13
|
+
export * from './types/flattened_accessors_of_type'
|
|
14
|
+
export * from './types/flattened_types_of_type'
|
|
15
|
+
export * from './types/flattened_values_of_type'
|
|
16
|
+
export * from './types/mobx_value_of_type'
|
|
17
|
+
export * from './types/paths_of_type'
|
|
18
|
+
export * from './types/readonly_type_of_type'
|
|
17
19
|
export * from './types/strict_definitions'
|
|
18
|
-
export * from './types/
|
|
19
|
-
export * from './types/
|
|
20
|
+
export * from './types/value_of_type'
|
|
21
|
+
export * from './types/value_to_type_paths_of_type'
|
|
20
22
|
export * from './types/value_types_of_discriminated_union'
|
|
23
|
+
export * from './validation/validator'
|
|
24
|
+
export * from './validation/validators/defined_validator'
|
|
25
|
+
export * from './validation/validators/minimum_string_length_validator'
|
|
26
|
+
export * from './validation/validators_of_values'
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"author": "Chris <chris.glover@gmail.com> (@madmaw)",
|
|
2
3
|
"dependencies": {
|
|
3
4
|
"@strictly/base": "*",
|
|
4
5
|
"mobx": "^6.13.5"
|
|
@@ -6,20 +7,27 @@
|
|
|
6
7
|
"devDependencies": {
|
|
7
8
|
"@strictly/support-vite": "*"
|
|
8
9
|
},
|
|
10
|
+
"homepage": "https://madmaw.github.io/strictly/define",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react",
|
|
13
|
+
"state management",
|
|
14
|
+
"types"
|
|
15
|
+
],
|
|
9
16
|
"license": "MIT",
|
|
10
17
|
"name": "@strictly/define",
|
|
18
|
+
"packageManager": "yarn@1.22.22",
|
|
11
19
|
"publishConfig": {
|
|
12
20
|
"access": "public"
|
|
13
21
|
},
|
|
14
22
|
"repository": {
|
|
15
23
|
"directory": "packages/define",
|
|
16
24
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/madmaw/
|
|
25
|
+
"url": "git+https://github.com/madmaw/strictly.git"
|
|
18
26
|
},
|
|
19
27
|
"scripts": {
|
|
20
28
|
"build": "tsup",
|
|
21
29
|
"check-types": "tsc",
|
|
22
|
-
"clean": "del-cli dist",
|
|
30
|
+
"clean": "del-cli dist .out .turbo",
|
|
23
31
|
"lint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint . --max-warnings=0",
|
|
24
32
|
"lint:fix": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint . --fix",
|
|
25
33
|
"release:exports": "json -f package.json -f package.exports.json --merge > package.release.json",
|
|
@@ -27,7 +35,7 @@
|
|
|
27
35
|
"test:watch": "vitest"
|
|
28
36
|
},
|
|
29
37
|
"type": "module",
|
|
30
|
-
"version": "0.0.
|
|
38
|
+
"version": "0.0.2",
|
|
31
39
|
"exports": {
|
|
32
40
|
".": {
|
|
33
41
|
"import": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ReadonlyTypeOfType } from 'types/readonly_type_of_type'
|
|
2
2
|
import { type StrictType } from 'types/strict_definitions'
|
|
3
|
-
import { type
|
|
3
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
4
4
|
import {
|
|
5
5
|
type AnyValueType,
|
|
6
6
|
copyTo,
|
|
@@ -12,7 +12,7 @@ function identity(v: AnyValueType): AnyValueType {
|
|
|
12
12
|
|
|
13
13
|
export function copy<T extends StrictType>(
|
|
14
14
|
t: T,
|
|
15
|
-
proto:
|
|
16
|
-
):
|
|
15
|
+
proto: ValueOfType<ReadonlyTypeOfType<T>>,
|
|
16
|
+
): ValueOfType<T> {
|
|
17
17
|
return copyTo(t, proto, identity)
|
|
18
18
|
}
|
|
@@ -10,18 +10,18 @@ import {
|
|
|
10
10
|
TypeDefType,
|
|
11
11
|
type UnionKey,
|
|
12
12
|
} from 'types/definitions'
|
|
13
|
-
import { type
|
|
13
|
+
import { type ReadonlyTypeOfType } from 'types/readonly_type_of_type'
|
|
14
14
|
import {
|
|
15
15
|
type StrictListTypeDef,
|
|
16
16
|
type StrictLiteralTypeDef,
|
|
17
17
|
type StrictObjectTypeDef,
|
|
18
|
+
type StrictObjectTypeDefFields,
|
|
18
19
|
type StrictRecordTypeDef,
|
|
19
|
-
type StrictStructuredTypeDefFields,
|
|
20
20
|
type StrictType,
|
|
21
21
|
type StrictTypeDef,
|
|
22
22
|
type StrictUnionTypeDef,
|
|
23
23
|
} from 'types/strict_definitions'
|
|
24
|
-
import { type
|
|
24
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
25
25
|
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
27
|
export type AnyValueType = any
|
|
@@ -30,10 +30,10 @@ export type Copier<R> = (v: AnyValueType, t: StrictTypeDef) => R
|
|
|
30
30
|
|
|
31
31
|
export function copyTo<
|
|
32
32
|
T extends StrictType,
|
|
33
|
-
R extends
|
|
33
|
+
R extends ValueOfType<ReadonlyTypeOfType<T>>,
|
|
34
34
|
>(
|
|
35
35
|
{ definition }: T,
|
|
36
|
-
value:
|
|
36
|
+
value: ValueOfType<ReadonlyTypeOfType<T>>,
|
|
37
37
|
copier: Copier<R>,
|
|
38
38
|
): R {
|
|
39
39
|
return internalCopyTo(
|
|
@@ -54,6 +54,10 @@ function internalCopyTo<R>(
|
|
|
54
54
|
value: AnyValueType,
|
|
55
55
|
copier: Copier<R>,
|
|
56
56
|
): R {
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
// don't copy things that don't exist
|
|
59
|
+
return undefined!
|
|
60
|
+
}
|
|
57
61
|
switch (definition.type) {
|
|
58
62
|
case TypeDefType.Literal:
|
|
59
63
|
return copyLiteral(
|
|
@@ -94,7 +98,7 @@ function copyLiteral<
|
|
|
94
98
|
R,
|
|
95
99
|
>(
|
|
96
100
|
typeDef: StrictLiteralTypeDef,
|
|
97
|
-
value:
|
|
101
|
+
value: ValueOfType<{ definition: StrictLiteralTypeDef }>,
|
|
98
102
|
copier: Copier<R>,
|
|
99
103
|
): R {
|
|
100
104
|
// mutable and immutable literals should be the same type
|
|
@@ -146,7 +150,7 @@ function copyObjectFields<
|
|
|
146
150
|
R,
|
|
147
151
|
Extra extends Record<string, UnionKey>,
|
|
148
152
|
>(
|
|
149
|
-
fields:
|
|
153
|
+
fields: StrictObjectTypeDefFields,
|
|
150
154
|
value: Record<ObjectFieldKey, AnyValueType>,
|
|
151
155
|
copier: Copier<R>,
|
|
152
156
|
extra: Extra,
|
|
@@ -7,18 +7,18 @@ import {
|
|
|
7
7
|
makeObservable,
|
|
8
8
|
observable,
|
|
9
9
|
} from 'mobx'
|
|
10
|
-
import { getUnionTypeDef } from 'transformers/flatteners/
|
|
10
|
+
import { getUnionTypeDef } from 'transformers/flatteners/flatten_value_to'
|
|
11
11
|
import {
|
|
12
12
|
type ObjectFieldKey,
|
|
13
13
|
TypeDefType,
|
|
14
14
|
} from 'types/definitions'
|
|
15
|
-
import { type
|
|
16
|
-
import { type
|
|
15
|
+
import { type MobxValueOfType } from 'types/mobx_value_of_type'
|
|
16
|
+
import { type ReadonlyTypeOfType } from 'types/readonly_type_of_type'
|
|
17
17
|
import {
|
|
18
18
|
type StrictType,
|
|
19
19
|
type StrictTypeDef,
|
|
20
20
|
} from 'types/strict_definitions'
|
|
21
|
-
import { type
|
|
21
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
22
22
|
import {
|
|
23
23
|
type AnyValueType,
|
|
24
24
|
copyTo,
|
|
@@ -75,7 +75,7 @@ function observeValue(
|
|
|
75
75
|
|
|
76
76
|
export function mobxCopy<T extends StrictType>(
|
|
77
77
|
t: T,
|
|
78
|
-
proto:
|
|
79
|
-
):
|
|
78
|
+
proto: ValueOfType<ReadonlyTypeOfType<T>>,
|
|
79
|
+
): MobxValueOfType<T> {
|
|
80
80
|
return copyTo(t, proto, observeValue)
|
|
81
81
|
}
|
|
@@ -72,9 +72,9 @@ describe('copyTo', function () {
|
|
|
72
72
|
|
|
73
73
|
describe('object', function () {
|
|
74
74
|
const typeDef = object()
|
|
75
|
-
.
|
|
76
|
-
.
|
|
77
|
-
.
|
|
75
|
+
.field('a', numberType)
|
|
76
|
+
.field('b', booleanType)
|
|
77
|
+
.field('c', stringType)
|
|
78
78
|
it('copies', function () {
|
|
79
79
|
const c = copyTo(
|
|
80
80
|
typeDef,
|
|
@@ -96,9 +96,9 @@ describe('copyTo', function () {
|
|
|
96
96
|
describe('union', function () {
|
|
97
97
|
describe('non-discriminated', function () {
|
|
98
98
|
const typeDef = union()
|
|
99
|
-
.
|
|
100
|
-
.
|
|
101
|
-
.
|
|
99
|
+
.or('0', list(numberType))
|
|
100
|
+
.or('1', literal(['b']))
|
|
101
|
+
.or('2', literal([false]))
|
|
102
102
|
it('copies string literal', function () {
|
|
103
103
|
const c = copyTo(
|
|
104
104
|
typeDef,
|
|
@@ -120,8 +120,8 @@ describe('copyTo', function () {
|
|
|
120
120
|
|
|
121
121
|
describe('discriminated', function () {
|
|
122
122
|
const typeDef = union('d')
|
|
123
|
-
.
|
|
124
|
-
.
|
|
123
|
+
.or('a', object().field('x', numberType))
|
|
124
|
+
.or('b', object().field('y', booleanType))
|
|
125
125
|
|
|
126
126
|
it('copies', function () {
|
|
127
127
|
const c = copyTo(
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
numberType,
|
|
4
4
|
object,
|
|
5
5
|
} from 'types/builders'
|
|
6
|
-
import { type
|
|
6
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
7
7
|
|
|
8
8
|
describe('mobxCopy', function () {
|
|
9
9
|
describe('object', function () {
|
|
10
10
|
describe('optional field', function () {
|
|
11
|
-
const type = object().
|
|
12
|
-
type T =
|
|
11
|
+
const type = object().optionalField('n', numberType)
|
|
12
|
+
type T = ValueOfType<typeof type>
|
|
13
13
|
it('copies unpopulated', function () {
|
|
14
14
|
const v: T = {}
|
|
15
15
|
const c = mobxCopy(type, v)
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
} from 'types/definitions'
|
|
5
5
|
import {
|
|
6
6
|
type Accessor,
|
|
7
|
-
type
|
|
8
|
-
} from 'types/
|
|
9
|
-
import { type
|
|
7
|
+
type FlattenedAccessorsOfType,
|
|
8
|
+
} from 'types/flattened_accessors_of_type'
|
|
9
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
10
10
|
import {
|
|
11
11
|
type AnyValueType,
|
|
12
|
-
|
|
12
|
+
flattenValueTo,
|
|
13
13
|
type Setter,
|
|
14
|
-
} from './
|
|
14
|
+
} from './flatten_value_to'
|
|
15
15
|
|
|
16
16
|
function mapAccessor(
|
|
17
17
|
_t: TypeDef,
|
|
@@ -24,17 +24,17 @@ function mapAccessor(
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function
|
|
27
|
+
export function flattenAccessorsOfType<
|
|
28
28
|
T extends Type,
|
|
29
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
R extends Readonly<Record<string, Accessor<any>>> =
|
|
30
|
+
R extends Readonly<Record<string, Accessor<any>>> = FlattenedAccessorsOfType<T>,
|
|
31
31
|
>(
|
|
32
32
|
t: T,
|
|
33
|
-
value:
|
|
34
|
-
setValue: Setter<
|
|
33
|
+
value: ValueOfType<T>,
|
|
34
|
+
setValue: Setter<ValueOfType<T>>,
|
|
35
35
|
): R {
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
return
|
|
37
|
+
return flattenValueTo<T, Accessor<any>, R>(
|
|
38
38
|
t,
|
|
39
39
|
value,
|
|
40
40
|
setValue,
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
type Type,
|
|
3
3
|
type TypeDef,
|
|
4
4
|
} from 'types/definitions'
|
|
5
|
-
import { type
|
|
5
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
6
6
|
import {
|
|
7
7
|
type AnyValueType,
|
|
8
|
-
|
|
8
|
+
flattenValueTo,
|
|
9
9
|
type Setter,
|
|
10
|
-
} from './
|
|
10
|
+
} from './flatten_value_to'
|
|
11
11
|
|
|
12
12
|
function mapTypePaths(
|
|
13
13
|
_t: TypeDef,
|
|
@@ -23,12 +23,12 @@ export function flattenJsonValueToTypePathsOf<
|
|
|
23
23
|
R extends Record<string, string | number | symbol>,
|
|
24
24
|
>(
|
|
25
25
|
t: T,
|
|
26
|
-
value:
|
|
26
|
+
value: ValueOfType<T>,
|
|
27
27
|
// TODO
|
|
28
28
|
// : FlattenedJsonValueToTypePathsOf<T>
|
|
29
29
|
): R {
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
31
|
-
return
|
|
31
|
+
return flattenValueTo(
|
|
32
32
|
t,
|
|
33
33
|
value,
|
|
34
34
|
function () {
|
|
@@ -20,7 +20,7 @@ export type AnyValueType = any
|
|
|
20
20
|
|
|
21
21
|
export type Mapper<R> = (t: StrictTypeDef) => R
|
|
22
22
|
|
|
23
|
-
export function
|
|
23
|
+
export function flattenTypeTo<M, R extends Readonly<Record<string, M>>>(
|
|
24
24
|
{ definition }: StrictType,
|
|
25
25
|
mapper: Mapper<M>,
|
|
26
26
|
): R {
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
type TypeDef,
|
|
4
4
|
} from 'types/definitions'
|
|
5
5
|
import { type StrictType } from 'types/strict_definitions'
|
|
6
|
-
import {
|
|
6
|
+
import { flattenTypeTo } from './flatten_type_to'
|
|
7
7
|
|
|
8
|
-
export function
|
|
8
|
+
export function flattenTypesOfType<T extends StrictType>(t: T) {
|
|
9
9
|
// Type should be FlattenedTypeDefsOf<T>, but infinite depth error
|
|
10
|
-
return
|
|
10
|
+
return flattenTypeTo<StrictType, Record<string, Type>>(
|
|
11
11
|
t,
|
|
12
12
|
function (definition: TypeDef) {
|
|
13
13
|
return { definition }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type AnyValueType } from 'transformers/copies/copy_to'
|
|
2
|
+
import {
|
|
3
|
+
flattenValueTo,
|
|
4
|
+
type Setter,
|
|
5
|
+
} from 'transformers/flatteners/flatten_value_to'
|
|
6
|
+
import {
|
|
7
|
+
type ReadonlyDeep,
|
|
8
|
+
type ValueOf,
|
|
9
|
+
} from 'type-fest'
|
|
10
|
+
import { type Type } from 'types/definitions'
|
|
11
|
+
import { type FlattenedTypesOfType } from 'types/flattened_types_of_type'
|
|
12
|
+
import { type FlattenedValuesOfType } from 'types/flattened_values_of_type'
|
|
13
|
+
import { type ReadonlyTypeOfType } from 'types/readonly_type_of_type'
|
|
14
|
+
import { type StrictTypeDef } from 'types/strict_definitions'
|
|
15
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
16
|
+
import {
|
|
17
|
+
validate,
|
|
18
|
+
type Validator,
|
|
19
|
+
} from 'validation/validator'
|
|
20
|
+
|
|
21
|
+
type ErrorOfValidator<V extends Validator> = V extends Validator<infer _V, infer E> ? E | null : never
|
|
22
|
+
|
|
23
|
+
export type ErrorsOfFlattenedValidators<
|
|
24
|
+
TypePathsToValidators extends Readonly<Record<string, Validator>>,
|
|
25
|
+
> = {
|
|
26
|
+
[K in keyof TypePathsToValidators]: ErrorOfValidator<TypePathsToValidators[K]>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type FlattenedTypePathsToValidatorsOf<
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
FlattenedValues extends Readonly<Record<string, any>>,
|
|
32
|
+
Context,
|
|
33
|
+
> = {
|
|
34
|
+
readonly [
|
|
35
|
+
K in keyof FlattenedValues
|
|
36
|
+
// TODO would be better to use the equivalent readonly typedef, but it causes typescript to
|
|
37
|
+
// infinitely recurse
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
]?: Validator<ReadonlyDeep<FlattenedValues[K]>, any, any, Context>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ValuePathsToValidatorsOf<
|
|
43
|
+
TypePathsToAdapters extends Partial<Readonly<Record<string, Validator>>>,
|
|
44
|
+
ValuePathsToTypePaths extends Readonly<Record<string, string>>,
|
|
45
|
+
> = keyof TypePathsToAdapters extends ValueOf<ValuePathsToTypePaths> ? {
|
|
46
|
+
readonly [
|
|
47
|
+
K in keyof ValuePathsToTypePaths as unknown extends TypePathsToAdapters[ValuePathsToTypePaths[K]] ? never : K
|
|
48
|
+
]: NonNullable<TypePathsToAdapters[ValuePathsToTypePaths[K]]>
|
|
49
|
+
}
|
|
50
|
+
: never
|
|
51
|
+
|
|
52
|
+
export type FlattenedValidatorsOfType<
|
|
53
|
+
T extends Type,
|
|
54
|
+
Flattened extends Readonly<Record<string, Type>> = FlattenedTypesOfType<T, '*'>,
|
|
55
|
+
> = {
|
|
56
|
+
[K in keyof Flattened]: Validator
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function flattenValidationErrorsOfType<
|
|
60
|
+
T extends Type,
|
|
61
|
+
ValueToTypePaths extends Readonly<Record<string, string>>,
|
|
62
|
+
TypePathsToValidators extends FlattenedTypePathsToValidatorsOf<
|
|
63
|
+
FlattenedValuesOfType<T, '*'>,
|
|
64
|
+
ValueOfType<ReadonlyTypeOfType<T>>
|
|
65
|
+
>,
|
|
66
|
+
ValuePathsToValidators extends ValuePathsToValidatorsOf<TypePathsToValidators, ValueToTypePaths> =
|
|
67
|
+
ValuePathsToValidatorsOf<
|
|
68
|
+
TypePathsToValidators,
|
|
69
|
+
ValueToTypePaths
|
|
70
|
+
>,
|
|
71
|
+
>(
|
|
72
|
+
type: T,
|
|
73
|
+
value: ValueOfType<T>,
|
|
74
|
+
validators: TypePathsToValidators,
|
|
75
|
+
): ErrorsOfFlattenedValidators<ValuePathsToValidators> {
|
|
76
|
+
return flattenValueTo(
|
|
77
|
+
type,
|
|
78
|
+
value,
|
|
79
|
+
() => {},
|
|
80
|
+
function (
|
|
81
|
+
_t: StrictTypeDef,
|
|
82
|
+
v: AnyValueType,
|
|
83
|
+
_setter: Setter<AnyValueType>,
|
|
84
|
+
typePath: string,
|
|
85
|
+
valuePath: string,
|
|
86
|
+
) {
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
88
|
+
const validator = validators[typePath as keyof TypePathsToValidators]
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
90
|
+
return validator != null ? validate(validator as Validator, v, valuePath, value) : null
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type FlattenedTypesOfValidatingType } from 'types/flattened_types_of_validating_type'
|
|
2
|
+
import { type FlattenedValidatorsOfValidatingType } from 'types/flattened_validators_of_validating_type'
|
|
3
|
+
import {
|
|
4
|
+
type ValidatingType,
|
|
5
|
+
type ValidatingTypeDef,
|
|
6
|
+
} from 'types/validating_definitions'
|
|
7
|
+
import { type Validator } from 'validation/validator'
|
|
8
|
+
import { flattenTypeTo } from './flatten_type_to'
|
|
9
|
+
|
|
10
|
+
export function flattenValidatorsOfValidatingType<
|
|
11
|
+
T extends ValidatingType,
|
|
12
|
+
TypePathsToValuePaths extends Readonly<Record<keyof FlattenedTypes, string>>,
|
|
13
|
+
FlattenedTypes extends Readonly<Record<string, ValidatingType>> = FlattenedTypesOfValidatingType<T, '*'>,
|
|
14
|
+
>(type: T): FlattenedValidatorsOfValidatingType<T, TypePathsToValuePaths, FlattenedTypes> {
|
|
15
|
+
return flattenTypeTo(type, function (definition): Validator {
|
|
16
|
+
const {
|
|
17
|
+
rule,
|
|
18
|
+
readonly,
|
|
19
|
+
required,
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
21
|
+
} = definition as ValidatingTypeDef
|
|
22
|
+
return {
|
|
23
|
+
annotations: function () {
|
|
24
|
+
return {
|
|
25
|
+
readonly,
|
|
26
|
+
required,
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
validate: rule,
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
TypeDefType,
|
|
8
8
|
type UnionTypeDef,
|
|
9
9
|
} from 'types/definitions'
|
|
10
|
-
import { type
|
|
10
|
+
import { type ReadonlyTypeOfType } from 'types/readonly_type_of_type'
|
|
11
11
|
import {
|
|
12
12
|
type StrictListTypeDef,
|
|
13
13
|
type StrictObjectTypeDef,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type StrictTypeDef,
|
|
17
17
|
type StrictUnionTypeDef,
|
|
18
18
|
} from 'types/strict_definitions'
|
|
19
|
-
import { type
|
|
19
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
20
20
|
import { jsonPath } from './json_path'
|
|
21
21
|
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -31,14 +31,14 @@ export type Mapper<R> = (
|
|
|
31
31
|
valuePath: string,
|
|
32
32
|
) => R
|
|
33
33
|
|
|
34
|
-
export function
|
|
34
|
+
export function flattenValueTo<
|
|
35
35
|
T extends StrictType,
|
|
36
36
|
M,
|
|
37
37
|
R extends Readonly<Record<string, M>>,
|
|
38
38
|
>(
|
|
39
39
|
{ definition }: T,
|
|
40
|
-
v:
|
|
41
|
-
setter: Setter<
|
|
40
|
+
v: ValueOfType<T>,
|
|
41
|
+
setter: Setter<ValueOfType<T>>,
|
|
42
42
|
mapper: Mapper<M>,
|
|
43
43
|
): R {
|
|
44
44
|
const r: Record<string, AnyValueType> = {}
|
|
@@ -65,7 +65,12 @@ function internalFlattenValue<M>(
|
|
|
65
65
|
r: Record<string, M>,
|
|
66
66
|
) {
|
|
67
67
|
r[valuePath] = mapper(typeDef, v, setter, typePath, valuePath)
|
|
68
|
-
|
|
68
|
+
// assume undefined means the field is optional and not populated
|
|
69
|
+
// TODO: actually capture if field is optional in typedef (or in builder for creating validator)
|
|
70
|
+
if (v !== undefined) {
|
|
71
|
+
return internalFlattenValueChildren(valuePath, typePath, '', typeDef, v, mapper, r)
|
|
72
|
+
}
|
|
73
|
+
return r
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
function internalFlattenValueChildren<M>(
|
|
@@ -199,7 +204,7 @@ function internalFlattenUnionChildren<M>(
|
|
|
199
204
|
|
|
200
205
|
export function getUnionTypeDef<T extends UnionTypeDef>(
|
|
201
206
|
typeDef: T,
|
|
202
|
-
v:
|
|
207
|
+
v: ValueOfType<ReadonlyTypeOfType<{
|
|
203
208
|
definition: T,
|
|
204
209
|
}>>,
|
|
205
210
|
) {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { type Type } from 'types/definitions'
|
|
2
2
|
import { type StrictTypeDef } from 'types/strict_definitions'
|
|
3
|
-
import { type
|
|
3
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
4
4
|
import {
|
|
5
5
|
type AnyValueType,
|
|
6
|
-
|
|
7
|
-
} from './
|
|
6
|
+
flattenValueTo,
|
|
7
|
+
} from './flatten_value_to'
|
|
8
8
|
|
|
9
9
|
function mapper(_t: StrictTypeDef, v: AnyValueType) {
|
|
10
10
|
return v
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function
|
|
13
|
+
export function flattenValuesOfType<T extends Type>(
|
|
14
14
|
typeDef: Type,
|
|
15
|
-
value:
|
|
15
|
+
value: ValueOfType<T>,
|
|
16
16
|
) {
|
|
17
|
-
return
|
|
17
|
+
return flattenValueTo(
|
|
18
18
|
typeDef,
|
|
19
19
|
value,
|
|
20
20
|
() => {},
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { expectDefinedAndReturn } from '@strictly/base'
|
|
2
|
-
import {
|
|
2
|
+
import { flattenAccessorsOfType } from 'transformers/flatteners/flatten_accessors_of_type'
|
|
3
3
|
import {
|
|
4
4
|
booleanType,
|
|
5
5
|
list,
|
|
6
6
|
numberType,
|
|
7
7
|
object,
|
|
8
8
|
} from 'types/builders'
|
|
9
|
-
import { type
|
|
10
|
-
import { type
|
|
9
|
+
import { type FlattenedAccessorsOfType } from 'types/flattened_accessors_of_type'
|
|
10
|
+
import { type ValueOfType } from 'types/value_of_type'
|
|
11
11
|
import {
|
|
12
12
|
type Mock,
|
|
13
13
|
vi,
|
|
14
14
|
} from 'vitest'
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('flattenAccessorsOfType', function () {
|
|
17
17
|
let setter: Mock
|
|
18
18
|
const builder = object()
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.narrow
|
|
19
|
+
.field('a', list(numberType))
|
|
20
|
+
.field('b', booleanType)
|
|
22
21
|
|
|
23
|
-
let flattened:
|
|
24
|
-
let value:
|
|
22
|
+
let flattened: FlattenedAccessorsOfType<typeof builder>
|
|
23
|
+
let value: ValueOfType<typeof builder>
|
|
25
24
|
|
|
26
25
|
beforeEach(function () {
|
|
27
26
|
setter = vi.fn()
|
|
@@ -33,7 +32,7 @@ describe('flattenAccessorsOf', function () {
|
|
|
33
32
|
],
|
|
34
33
|
b: false,
|
|
35
34
|
}
|
|
36
|
-
flattened =
|
|
35
|
+
flattened = flattenAccessorsOfType<typeof builder>(
|
|
37
36
|
builder,
|
|
38
37
|
value,
|
|
39
38
|
setter,
|
|
@@ -100,7 +99,7 @@ describe('flattenAccessorsOf', function () {
|
|
|
100
99
|
})
|
|
101
100
|
|
|
102
101
|
it('sets the top level value', function () {
|
|
103
|
-
const newValue:
|
|
102
|
+
const newValue: ValueOfType<typeof builder> = {
|
|
104
103
|
a: [
|
|
105
104
|
-1,
|
|
106
105
|
5,
|
|
@@ -56,8 +56,8 @@ describe('flattenJsonValueToTypePathsOf', function () {
|
|
|
56
56
|
|
|
57
57
|
describe('object', function () {
|
|
58
58
|
const typeDef = object()
|
|
59
|
-
.
|
|
60
|
-
.
|
|
59
|
+
.field('a', numberType)
|
|
60
|
+
.field('b', booleanType)
|
|
61
61
|
const flattened = flattenJsonValueToTypePathsOf(typeDef, {
|
|
62
62
|
a: 1,
|
|
63
63
|
b: true,
|
|
@@ -75,8 +75,8 @@ describe('flattenJsonValueToTypePathsOf', function () {
|
|
|
75
75
|
describe('union', function () {
|
|
76
76
|
describe('non-discriminated', function () {
|
|
77
77
|
const typeDef = union()
|
|
78
|
-
.
|
|
79
|
-
.
|
|
78
|
+
.or('a', list(numberType))
|
|
79
|
+
.or('b', nullType)
|
|
80
80
|
const flattened = flattenJsonValueToTypePathsOf(typeDef, [
|
|
81
81
|
1,
|
|
82
82
|
2,
|
|
@@ -95,8 +95,8 @@ describe('flattenJsonValueToTypePathsOf', function () {
|
|
|
95
95
|
|
|
96
96
|
describe('discriminated', function () {
|
|
97
97
|
const typeDef = union('d')
|
|
98
|
-
.
|
|
99
|
-
.
|
|
98
|
+
.or('x', object().field('a', numberType).field('b', booleanType))
|
|
99
|
+
.or('y', object().field('c', stringType).field('d', booleanType))
|
|
100
100
|
const flattened = flattenJsonValueToTypePathsOf(typeDef, {
|
|
101
101
|
d: 'x',
|
|
102
102
|
a: 1,
|