typia 3.4.5 → 3.4.7
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 +5 -47
- package/lib/executable/typia.js +0 -0
- package/lib/factories/internal/iterate_metadata.js +1 -1
- package/lib/factories/internal/iterate_metadata.js.map +1 -1
- package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
- package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
- package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
- package/package.json +1 -1
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/TypiaSetupWizard.ts +148 -148
- package/src/executable/typia.ts +35 -35
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +52 -52
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/MetadataTagFactory.ts +347 -347
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/MetadataHelper.ts +12 -12
- package/src/factories/internal/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/explore_metadata.ts +91 -91
- package/src/factories/internal/iterate_metadata.ts +80 -81
- package/src/factories/internal/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/iterate_metadata_object.ts +45 -45
- package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
- package/src/factories/internal/iterate_metadata_union.ts +59 -59
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$number.ts +19 -19
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +122 -122
- package/src/metadata/Metadata.ts +477 -477
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertParseProgrammer.ts +45 -45
- package/src/programmers/AssertProgrammer.ts +444 -444
- package/src/programmers/AssertStringifyProgrammer.ts +45 -45
- package/src/programmers/CheckerProgrammer.ts +798 -798
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +51 -51
- package/src/programmers/IsProgrammer.ts +169 -169
- package/src/programmers/IsStringifyProgrammer.ts +49 -49
- package/src/programmers/StringifyProgrammer.ts +746 -746
- package/src/programmers/ValidateParseProgrammer.ts +49 -49
- package/src/programmers/ValidateProgrammer.ts +236 -236
- package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +18 -18
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_schema.ts +221 -221
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_number.ts +181 -181
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transform.ts +20 -20
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +4 -4
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Just type `npx typia setup`, that's all.
|
|
|
51
51
|
|
|
52
52
|
After the setup, you can compile `typia` utilized code by using `ttsc` ([`ttypescript`](https://github.com/cevek/ttypescript)) command. If you want to run your TypeScript file directly through `ts-node`, add `-C ttypescript` argument like below:
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
```bash
|
|
55
55
|
# COMPILE THROUGH TTYPESCRIPT
|
|
56
56
|
npx ttsc
|
|
57
57
|
|
|
@@ -59,28 +59,10 @@ npx ttsc
|
|
|
59
59
|
npx ts-node -C ttypescript src/index.ts
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
> If you want to use only `tsc` command, you can choose another option: [`ts-patch`](https://github.com/nonara/ts-patch).
|
|
63
|
-
>
|
|
64
|
-
> Set it up through `npx typia setup ts-patch` command and compile your project with pure(?) TypeScript compiler (`tsc`). When you want to run your TypeScript file directly, just use the pure `ts-node`, too.
|
|
65
|
-
>
|
|
66
|
-
> However, note that, the `ts-patch` will modify JavaScript files in `node_modules/typescript` directly. Therefore, it may cause some problems when you update typescript version after the `setup` process, until running `npm run prepare` command.
|
|
67
|
-
>
|
|
68
|
-
> ```bash
|
|
69
|
-
> # SETUP
|
|
70
|
-
> npx typia setup ts-patch
|
|
71
|
-
>
|
|
72
|
-
> #COMPILE
|
|
73
|
-
> npx tsc
|
|
74
|
-
> npx ts-node src/index.ts
|
|
75
|
-
>
|
|
76
|
-
> # AFTER UPDATE, HAVE TO RUN PREPARE COMMAND
|
|
77
|
-
> npm install --save-dev typescript@latest
|
|
78
|
-
> npm run prepare
|
|
79
|
-
> ``` -->
|
|
80
|
-
|
|
81
62
|
### Manual Setup
|
|
82
63
|
If you want to install and setup `typia` manually, read [Guide Documents - Setup](https://github.com/samchon/typia/wiki/Setup).
|
|
83
64
|
|
|
65
|
+
- [Setup Wizard](https://github.com/samchon/typia/wiki/Setup#setup-wizard)
|
|
84
66
|
- [NPM Packages](https://github.com/samchon/typia/wiki/Setup#npm-packages)
|
|
85
67
|
- [`tsconfig.json`](https://github.com/samchon/typia/wiki/Setup#tsconfigjson)
|
|
86
68
|
- [vite](https://github.com/samchon/typia/wiki/Setup#vite)
|
|
@@ -89,7 +71,7 @@ If you want to install and setup `typia` manually, read [Guide Documents - Setup
|
|
|
89
71
|
### vite
|
|
90
72
|
When you want to setup `typia` on your frontend project with [`vite`](https://vitejs.dev/), just configure `vite.config.ts` like below.
|
|
91
73
|
|
|
92
|
-
For reference, don't forget [
|
|
74
|
+
For reference, don't forget running [Setup Wizard](#setup-wizard) before.
|
|
93
75
|
|
|
94
76
|
```typescript
|
|
95
77
|
import { defineConfig } from "vite";
|
|
@@ -116,7 +98,7 @@ export default defineConfig({
|
|
|
116
98
|
|
|
117
99
|
In here README documents, only summarized informations are provided.
|
|
118
100
|
|
|
119
|
-
For more details,
|
|
101
|
+
For more details, refer to the [Guide Documents (wiki)](https://github.com/samchon/typia/wiki).
|
|
120
102
|
|
|
121
103
|
> - **Runtime Validators**
|
|
122
104
|
> - [powerful validator](https://github.com/samchon/typia/wiki/Runtime-Validators#powerful-validator)
|
|
@@ -163,31 +145,7 @@ export function createValidateEquals<T>(): (input: unknown) => IValidation<T>;
|
|
|
163
145
|
|
|
164
146
|
Also, if you want more strict validator functions that even do not allowing superfluous properties not written in the type `T`, you can use those functions instead; `equals()`, `assertEquals()`, `validateEquals()`. Otherwise you want to create resuable validator functions, you can utilize factory functions like `createIs()` instead.
|
|
165
147
|
|
|
166
|
-
When you want to add special validation logics, like limiting range of numeric values, you can do it through comment tags. If you want to know about it,
|
|
167
|
-
|
|
168
|
-
<!-- > By the way, comparing those validator functions with other competitive libaries, you can find that only `typia` is able to validate complicate union type. It is because `typia` is supporting entire TypeScript type specs. Therefore, adapt `typia` with confidence. It can validate everything.
|
|
169
|
-
>
|
|
170
|
-
> Moreover, validation speed of `typia` is extremely faster than any other validation libraries. For an example, `typia` is maximum 15,000x times faster than `class-validator`. Visit [benchmarks](https://github.com/samchon/typia/wiki/Benchmarks#validate-functions) section of Guide Documents and feel how fast `typia` is.
|
|
171
|
-
>
|
|
172
|
-
> Components | `typia` | `TypeBox` | `ajv` | `io-ts` | `zod` | `C.V.`
|
|
173
|
-
> -------------------------|--------|-----------|-------|---------|-------|------------------
|
|
174
|
-
> **Easy to use** | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
175
|
-
> [Object (simple)](https://github.com/samchon/typia/blob/master/test/structures/ObjectSimple.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
176
|
-
> [Object (hierarchical)](https://github.com/samchon/typia/blob/master/test/structures/ObjectHierarchical.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
177
|
-
> [Object (recursive)](https://github.com/samchon/typia/blob/master/test/structures/ObjectRecursive.ts) | ✔ | ❌ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
178
|
-
> [Object (union, implicit)](https://github.com/samchon/typia/blob/master/test/structures/ObjectUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
179
|
-
> [Object (union, explicit)](https://github.com/samchon/typia/blob/master/test/structures/ObjectUnionExplicit.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌
|
|
180
|
-
> [Object (additional tags)](https://github.com/samchon/typia/#comment-tags) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
181
|
-
> [Object (template literal types)](https://github.com/samchon/typia/blob/master/test/structures/TemplateUnion.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
182
|
-
> [Object (dynamic properties)](https://github.com/samchon/typia/blob/master/test/structures/DynamicTemplate.ts) | ✔ | ✔ | ✔ | ❌ | ❌ | ❌
|
|
183
|
-
> [Array (hierarchical)](https://github.com/samchon/typia/blob/master/test/structures/ArrayHierarchical.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
184
|
-
> [Array (recursive)](https://github.com/samchon/typia/blob/master/test/structures/ArrayRecursive.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌
|
|
185
|
-
> [Array (recursive, union)](https://github.com/samchon/typia/blob/master/test/structures/ArrayRecursiveUnionExplicit.ts) | ✔ | ✔ | ❌ | ✔ | ✔ | ❌
|
|
186
|
-
> [Array (R+U, implicit)](https://github.com/samchon/typia/blob/master/test/structures/ArrayRecursiveUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
187
|
-
> [**Ultimate Union Type**](https://github.com/samchon/typia/blob/master/src/schemas/IJsonSchema.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
188
|
-
>
|
|
189
|
-
> - typia: `typia`
|
|
190
|
-
> - C.V.: `class-validator` -->
|
|
148
|
+
When you want to add special validation logics, like limiting range of numeric values, you can do it through comment tags. If you want to know about it, visit the Guide Documents ([Features > Runtime Validators > Comment Tags](https://github.com/samchon/typia/wiki/Runtime-Validators#comment-tags)).
|
|
191
149
|
|
|
192
150
|
### Enhanced JSON
|
|
193
151
|
```typescript
|
package/lib/executable/typia.js
CHANGED
|
File without changes
|
|
@@ -32,7 +32,7 @@ var iterate_metadata = function (checker) {
|
|
|
32
32
|
(0, iterate_metadata_constant_1.iterate_metadata_constant)(checker)(options)(meta, type) ||
|
|
33
33
|
(0, iterate_metadata_template_1.iterate_metadata_template)(checker)(options)(collection)(meta, type) ||
|
|
34
34
|
(0, iterate_metadata_atomic_1.iterate_metadata_atomic)(meta, type) ||
|
|
35
|
-
(0, iterate_metadata_tuple_1.iterate_metadata_tuple)(checker)(options)(collection)(meta, type
|
|
35
|
+
(0, iterate_metadata_tuple_1.iterate_metadata_tuple)(checker)(options)(collection)(meta, type) ||
|
|
36
36
|
(0, iterate_metadata_array_1.iterate_metadata_array)(checker)(options)(collection)(meta, type) ||
|
|
37
37
|
(0, iterate_metadata_native_1.iterate_metadata_native)(checker)(meta, type) ||
|
|
38
38
|
(0, iterate_metadata_map_1.iterate_metadata_map)(checker)(options)(collection)(meta, type) ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterate_metadata.js","sourceRoot":"","sources":["../../../src/factories/internal/iterate_metadata.ts"],"names":[],"mappings":";;;AAIA,mDAAkD;AAIlD,mEAAkE;AAClE,qEAAoE;AACpE,yEAAwE;AACxE,yEAAwE;AACxE,+DAA8D;AAC9D,qEAAoE;AACpE,qEAAoE;AACpE,uEAAsE;AACtE,+DAA8D;AAC9D,yEAAwE;AACxE,mEAAkE;AAClE,mEAAkE;AAE3D,IAAM,gBAAgB,GACzB,UAAC,OAAuB;IACxB,OAAA,UAAC,OAAiC;QAClC,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAc,EAAE,IAAa,EAAE,cAAuB;gBACnD,IAAI,IAAI,CAAC,eAAe,EAAE,KAAK,IAAI;oBAC/B,MAAM,IAAI,KAAK,CACX,uFAAgF,IAAI,CAAC,OAAO,EAAE,MAAG,CACpG,CAAC;gBAGN,IACI,IAAA,+CAAsB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAChD,IAAI,EACJ,IAAI,EACJ,cAAc,CACjB;oBACD,IAAA,mDAAwB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAClD,IAAI,EACJ,IAAI,EACJ,cAAc,CACjB;oBAED,OAAO;gBAGX,IAAM,IAAI,GAA4B,OAAO,CAAC,cAAc,CACxD,IAAI,EACJ,SAAS,EACT,SAAS,CACZ,CAAC;gBACF,IAAI,IAAI,KAAK,SAAS,EAAE;oBAEpB,qBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;oBAC3C,OAAO;iBACV;gBAGD,IAAA,qDAAyB,EAAC,IAAI,EAAE,IAAI,CAAC;oBACjC,IAAA,qDAAyB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;oBACvD,IAAA,qDAAyB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CACnD,IAAI,EACJ,IAAI,CACP;oBACD,IAAA,iDAAuB,EAAC,IAAI,EAAE,IAAI,CAAC;oBACnC,IAAA,+CAAsB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAChD,IAAI,EACJ,
|
|
1
|
+
{"version":3,"file":"iterate_metadata.js","sourceRoot":"","sources":["../../../src/factories/internal/iterate_metadata.ts"],"names":[],"mappings":";;;AAIA,mDAAkD;AAIlD,mEAAkE;AAClE,qEAAoE;AACpE,yEAAwE;AACxE,yEAAwE;AACxE,+DAA8D;AAC9D,qEAAoE;AACpE,qEAAoE;AACpE,uEAAsE;AACtE,+DAA8D;AAC9D,yEAAwE;AACxE,mEAAkE;AAClE,mEAAkE;AAE3D,IAAM,gBAAgB,GACzB,UAAC,OAAuB;IACxB,OAAA,UAAC,OAAiC;QAClC,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAc,EAAE,IAAa,EAAE,cAAuB;gBACnD,IAAI,IAAI,CAAC,eAAe,EAAE,KAAK,IAAI;oBAC/B,MAAM,IAAI,KAAK,CACX,uFAAgF,IAAI,CAAC,OAAO,EAAE,MAAG,CACpG,CAAC;gBAGN,IACI,IAAA,+CAAsB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAChD,IAAI,EACJ,IAAI,EACJ,cAAc,CACjB;oBACD,IAAA,mDAAwB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAClD,IAAI,EACJ,IAAI,EACJ,cAAc,CACjB;oBAED,OAAO;gBAGX,IAAM,IAAI,GAA4B,OAAO,CAAC,cAAc,CACxD,IAAI,EACJ,SAAS,EACT,SAAS,CACZ,CAAC;gBACF,IAAI,IAAI,KAAK,SAAS,EAAE;oBAEpB,qBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;oBAC3C,OAAO;iBACV;gBAGD,IAAA,qDAAyB,EAAC,IAAI,EAAE,IAAI,CAAC;oBACjC,IAAA,qDAAyB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;oBACvD,IAAA,qDAAyB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CACnD,IAAI,EACJ,IAAI,CACP;oBACD,IAAA,iDAAuB,EAAC,IAAI,EAAE,IAAI,CAAC;oBACnC,IAAA,+CAAsB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAChD,IAAI,EACJ,IAAoB,CACvB;oBACD,IAAA,+CAAsB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;oBAChE,IAAA,iDAAuB,EAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;oBAC5C,IAAA,2CAAoB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;oBAC9D,IAAA,2CAAoB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;oBAC9D,IAAA,iDAAuB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CACjD,IAAI,EACJ,IAAI,EACJ,cAAc,CACjB,CAAC;YACV,CAAC;QAtDD,CAsDC;IAvDD,CAuDC;AAxDD,CAwDC,CAAC;AA1DO,QAAA,gBAAgB,oBA0DvB"}
|
|
@@ -2,4 +2,4 @@ import ts from "typescript";
|
|
|
2
2
|
import { Metadata } from "../../metadata/Metadata";
|
|
3
3
|
import { MetadataCollection } from "../MetadataCollection";
|
|
4
4
|
import { MetadataFactory } from "../MetadataFactory";
|
|
5
|
-
export declare const iterate_metadata_tuple: (checker: ts.TypeChecker) => (options: MetadataFactory.IOptions) => (collection: MetadataCollection) => (meta: Metadata, type: ts.
|
|
5
|
+
export declare const iterate_metadata_tuple: (checker: ts.TypeChecker) => (options: MetadataFactory.IOptions) => (collection: MetadataCollection) => (meta: Metadata, type: ts.TupleType) => boolean;
|
|
@@ -12,25 +12,17 @@ var explore_metadata_1 = require("./explore_metadata");
|
|
|
12
12
|
var iterate_metadata_tuple = function (checker) {
|
|
13
13
|
return function (options) {
|
|
14
14
|
return function (collection) {
|
|
15
|
-
return function (meta, type
|
|
16
|
-
var _a, _b;
|
|
15
|
+
return function (meta, type) {
|
|
16
|
+
var _a, _b, _c;
|
|
17
17
|
if (!checker.isTupleType(type))
|
|
18
18
|
return false;
|
|
19
|
-
|
|
20
|
-
var declarations = (_b = (_a = node.typeName) === null || _a === void 0 ? void 0 : _a.symbol) === null || _b === void 0 ? void 0 : _b.declarations;
|
|
21
|
-
if (!(declarations === null || declarations === void 0 ? void 0 : declarations.length))
|
|
22
|
-
break;
|
|
23
|
-
var alias = declarations[0];
|
|
24
|
-
if (!alias || !typescript_1.default.isTypeAliasDeclaration(alias))
|
|
25
|
-
break;
|
|
26
|
-
node = alias.type;
|
|
27
|
-
}
|
|
28
|
-
var elements = typescript_1.default.isTupleTypeNode(node) ? node.elements : undefined;
|
|
19
|
+
var elementFlags = (_c = (_a = type.elementFlags) !== null && _a !== void 0 ? _a : (_b = type.target) === null || _b === void 0 ? void 0 : _b.elementFlags) !== null && _c !== void 0 ? _c : [];
|
|
29
20
|
var children = checker
|
|
30
21
|
.getTypeArguments(type)
|
|
31
22
|
.map(function (elem, i) {
|
|
32
23
|
var child = (0, explore_metadata_1.explore_metadata)(checker)(options)(collection)(elem, false);
|
|
33
|
-
|
|
24
|
+
var flag = elementFlags[i];
|
|
25
|
+
if (flag !== typescript_1.default.ElementFlags.Rest)
|
|
34
26
|
return child;
|
|
35
27
|
var wrapper = Metadata_1.Metadata.initialize();
|
|
36
28
|
(0, Writable_1.Writable)(wrapper).rest = child;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterate_metadata_tuple.js","sourceRoot":"","sources":["../../../src/factories/internal/iterate_metadata_tuple.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,oDAAmD;AAEnD,mDAAkD;AAElD,mDAAkD;AAIlD,uDAAsD;AAE/C,IAAM,sBAAsB,GAC/B,UAAC,OAAuB;IACxB,OAAA,UAAC,OAAiC;QAClC,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"iterate_metadata_tuple.js","sourceRoot":"","sources":["../../../src/factories/internal/iterate_metadata_tuple.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,oDAAmD;AAEnD,mDAAkD;AAElD,mDAAkD;AAIlD,uDAAsD;AAE/C,IAAM,sBAAsB,GAC/B,UAAC,OAAuB;IACxB,OAAA,UAAC,OAAiC;QAClC,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAc,EAAE,IAAkB;;gBAC/B,IAAI,CAAE,OAAe,CAAC,WAAW,CAAC,IAAI,CAAC;oBAAE,OAAO,KAAK,CAAC;gBAEtD,IAAM,YAAY,GACd,MAAA,MAAA,IAAI,CAAC,YAAY,mCACjB,MAAC,IAAI,CAAC,MAAuB,0CAAE,YAAY,mCAC3C,EAAE,CAAC;gBAEP,IAAM,QAAQ,GAAe,OAAO;qBAC/B,gBAAgB,CAAC,IAAwB,CAAC;qBAC1C,GAAG,CAAC,UAAC,IAAI,EAAE,CAAC;oBACT,IAAM,KAAK,GAAa,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CACtD,UAAU,CACb,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;oBAEf,IAAM,IAAI,GAAgC,YAAY,CAAC,CAAC,CAAC,CAAC;oBAC1D,IAAI,IAAI,KAAK,oBAAE,CAAC,YAAY,CAAC,IAAI;wBAAE,OAAO,KAAK,CAAC;oBAEhD,IAAM,OAAO,GAAa,mBAAQ,CAAC,UAAU,EAAE,CAAC;oBAChD,IAAA,mBAAQ,EAAC,OAAO,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC;oBAC/B,OAAO,OAAO,CAAC;gBACnB,CAAC,CAAC,CAAC;gBACP,qBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBACvD,OAAO,IAAI,CAAC;YAChB,CAAC;QAxBD,CAwBC;IAzBD,CAyBC;AA1BD,CA0BC,CAAC;AA5BO,QAAA,sBAAsB,0BA4B7B;AAEN,SAAS,gBAAgB,CAAC,KAAiB;IACvC,OAAO,WAAI,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,EAAT,CAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAG,CAAC;AACzD,CAAC"}
|
package/package.json
CHANGED
package/src/IValidation.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export type IValidation<T = unknown> =
|
|
2
|
-
| IValidation.ISuccess<T>
|
|
3
|
-
| IValidation.IFailure;
|
|
4
|
-
export namespace IValidation {
|
|
5
|
-
export interface ISuccess<T = unknown> {
|
|
6
|
-
success: true;
|
|
7
|
-
data: T;
|
|
8
|
-
errors: [];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IFailure {
|
|
12
|
-
success: false;
|
|
13
|
-
errors: IError[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IError {
|
|
17
|
-
path: string;
|
|
18
|
-
expected: string;
|
|
19
|
-
value: any;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
export type IValidation<T = unknown> =
|
|
2
|
+
| IValidation.ISuccess<T>
|
|
3
|
+
| IValidation.IFailure;
|
|
4
|
+
export namespace IValidation {
|
|
5
|
+
export interface ISuccess<T = unknown> {
|
|
6
|
+
success: true;
|
|
7
|
+
data: T;
|
|
8
|
+
errors: [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IFailure {
|
|
12
|
+
success: false;
|
|
13
|
+
errors: IError[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IError {
|
|
17
|
+
path: string;
|
|
18
|
+
expected: string;
|
|
19
|
+
value: any;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/Primitive.ts
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Primitive type.
|
|
3
|
-
*
|
|
4
|
-
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
-
* primitive type.
|
|
6
|
-
*
|
|
7
|
-
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
-
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
-
* `string` or `number`.
|
|
10
|
-
*
|
|
11
|
-
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
-
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
-
* type of the TMP type finally be the primitive object.
|
|
14
|
-
*
|
|
15
|
-
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
-
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
-
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
-
*
|
|
19
|
-
* Before | After
|
|
20
|
-
* ------------------------|----------------------------------------
|
|
21
|
-
* `Boolean` | `boolean`
|
|
22
|
-
* `Number` | `number`
|
|
23
|
-
* `String` | `string`
|
|
24
|
-
* `Class` | `object`
|
|
25
|
-
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
-
* Others | No change
|
|
27
|
-
*
|
|
28
|
-
* @template Instance Target argument type.
|
|
29
|
-
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
-
*/
|
|
31
|
-
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
-
? T
|
|
33
|
-
: _Primitive<T>;
|
|
34
|
-
|
|
35
|
-
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
-
|
|
37
|
-
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
-
? Instance extends object
|
|
39
|
-
? Instance extends IJsonable<infer Raw>
|
|
40
|
-
? _ValueOf<Raw> extends object
|
|
41
|
-
? Raw extends object
|
|
42
|
-
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
-
: never // cannot be
|
|
44
|
-
: _ValueOf<Raw> // atomic value
|
|
45
|
-
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
-
: never // cannot be
|
|
47
|
-
: _ValueOf<Instance>;
|
|
48
|
-
|
|
49
|
-
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
-
? _Primitive<T>[]
|
|
51
|
-
: {
|
|
52
|
-
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
-
? never
|
|
54
|
-
: _Primitive<Instance[P]>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
-
? boolean
|
|
59
|
-
: _IsValueOf<Instance, Number> extends true
|
|
60
|
-
? number
|
|
61
|
-
: _IsValueOf<Instance, String> extends true
|
|
62
|
-
? string
|
|
63
|
-
: Instance;
|
|
64
|
-
|
|
65
|
-
type _IsValueOf<
|
|
66
|
-
Instance,
|
|
67
|
-
Object extends IValueOf<any>,
|
|
68
|
-
> = Instance extends Object
|
|
69
|
-
? Object extends IValueOf<infer Primitive>
|
|
70
|
-
? Instance extends Primitive
|
|
71
|
-
? false
|
|
72
|
-
: true // not Primitive, but Object
|
|
73
|
-
: false // cannot be
|
|
74
|
-
: false;
|
|
75
|
-
|
|
76
|
-
interface IValueOf<T> {
|
|
77
|
-
valueOf(): T;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface IJsonable<T> {
|
|
81
|
-
toJSON(): T;
|
|
82
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Primitive type.
|
|
3
|
+
*
|
|
4
|
+
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
+
* primitive type.
|
|
6
|
+
*
|
|
7
|
+
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
+
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
+
* `string` or `number`.
|
|
10
|
+
*
|
|
11
|
+
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
+
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
+
* type of the TMP type finally be the primitive object.
|
|
14
|
+
*
|
|
15
|
+
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
+
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
+
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
+
*
|
|
19
|
+
* Before | After
|
|
20
|
+
* ------------------------|----------------------------------------
|
|
21
|
+
* `Boolean` | `boolean`
|
|
22
|
+
* `Number` | `number`
|
|
23
|
+
* `String` | `string`
|
|
24
|
+
* `Class` | `object`
|
|
25
|
+
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
+
* Others | No change
|
|
27
|
+
*
|
|
28
|
+
* @template Instance Target argument type.
|
|
29
|
+
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
+
? T
|
|
33
|
+
: _Primitive<T>;
|
|
34
|
+
|
|
35
|
+
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
+
|
|
37
|
+
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
+
? Instance extends object
|
|
39
|
+
? Instance extends IJsonable<infer Raw>
|
|
40
|
+
? _ValueOf<Raw> extends object
|
|
41
|
+
? Raw extends object
|
|
42
|
+
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
+
: never // cannot be
|
|
44
|
+
: _ValueOf<Raw> // atomic value
|
|
45
|
+
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
+
: never // cannot be
|
|
47
|
+
: _ValueOf<Instance>;
|
|
48
|
+
|
|
49
|
+
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
+
? _Primitive<T>[]
|
|
51
|
+
: {
|
|
52
|
+
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
+
? never
|
|
54
|
+
: _Primitive<Instance[P]>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
+
? boolean
|
|
59
|
+
: _IsValueOf<Instance, Number> extends true
|
|
60
|
+
? number
|
|
61
|
+
: _IsValueOf<Instance, String> extends true
|
|
62
|
+
? string
|
|
63
|
+
: Instance;
|
|
64
|
+
|
|
65
|
+
type _IsValueOf<
|
|
66
|
+
Instance,
|
|
67
|
+
Object extends IValueOf<any>,
|
|
68
|
+
> = Instance extends Object
|
|
69
|
+
? Object extends IValueOf<infer Primitive>
|
|
70
|
+
? Instance extends Primitive
|
|
71
|
+
? false
|
|
72
|
+
: true // not Primitive, but Object
|
|
73
|
+
: false // cannot be
|
|
74
|
+
: false;
|
|
75
|
+
|
|
76
|
+
interface IValueOf<T> {
|
|
77
|
+
valueOf(): T;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface IJsonable<T> {
|
|
81
|
+
toJSON(): T;
|
|
82
|
+
}
|
package/src/TypeGuardError.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export class TypeGuardError extends Error {
|
|
2
|
-
public readonly method: string;
|
|
3
|
-
public readonly path: string | undefined;
|
|
4
|
-
public readonly expected: string;
|
|
5
|
-
public readonly value: any;
|
|
6
|
-
|
|
7
|
-
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
-
// MESSAGE CONSTRUCTION
|
|
9
|
-
super(
|
|
10
|
-
props.message ||
|
|
11
|
-
`Error on ${props.method}(): invalid type${
|
|
12
|
-
props.path ? ` on ${props.path}` : ""
|
|
13
|
-
}, expect to be ${props.expected}`,
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// INHERITANCE POLYFILL
|
|
17
|
-
const proto = new.target.prototype;
|
|
18
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
-
else (this as any).__proto__ = proto;
|
|
20
|
-
|
|
21
|
-
// ASSIGN MEMBERS
|
|
22
|
-
this.method = props.method;
|
|
23
|
-
this.path = props.path;
|
|
24
|
-
this.expected = props.expected;
|
|
25
|
-
this.value = props.value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export namespace TypeGuardError {
|
|
29
|
-
export interface IProps {
|
|
30
|
-
method: string;
|
|
31
|
-
path?: string;
|
|
32
|
-
expected: string;
|
|
33
|
-
value: any;
|
|
34
|
-
message?: string;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
export class TypeGuardError extends Error {
|
|
2
|
+
public readonly method: string;
|
|
3
|
+
public readonly path: string | undefined;
|
|
4
|
+
public readonly expected: string;
|
|
5
|
+
public readonly value: any;
|
|
6
|
+
|
|
7
|
+
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
+
// MESSAGE CONSTRUCTION
|
|
9
|
+
super(
|
|
10
|
+
props.message ||
|
|
11
|
+
`Error on ${props.method}(): invalid type${
|
|
12
|
+
props.path ? ` on ${props.path}` : ""
|
|
13
|
+
}, expect to be ${props.expected}`,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// INHERITANCE POLYFILL
|
|
17
|
+
const proto = new.target.prototype;
|
|
18
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
+
else (this as any).__proto__ = proto;
|
|
20
|
+
|
|
21
|
+
// ASSIGN MEMBERS
|
|
22
|
+
this.method = props.method;
|
|
23
|
+
this.path = props.path;
|
|
24
|
+
this.expected = props.expected;
|
|
25
|
+
this.value = props.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export namespace TypeGuardError {
|
|
29
|
+
export interface IProps {
|
|
30
|
+
method: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
expected: string;
|
|
33
|
+
value: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|