typia 3.4.6 → 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/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/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/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 +1 -2
- 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_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/$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/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/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/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_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_schema.ts +221 -221
- 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/transform.ts +20 -20
- 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/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/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,OAA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AI,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;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,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
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
-
return comments
|
|
6
|
-
.map((part) => part.text)
|
|
7
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
-
.join("");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
+
return comments
|
|
6
|
+
.map((part) => part.text)
|
|
7
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
+
.join("");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
-
return ts.factory.createStrictInequality(
|
|
6
|
-
ts.factory.createIdentifier("undefined"),
|
|
7
|
-
input,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
-
return ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
-
undefined,
|
|
15
|
-
[input],
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject(
|
|
20
|
-
input: ts.Expression,
|
|
21
|
-
nullChecked: boolean,
|
|
22
|
-
): ts.Expression {
|
|
23
|
-
const conditions: ts.Expression[] = [
|
|
24
|
-
ts.factory.createStrictEquality(
|
|
25
|
-
ts.factory.createStringLiteral("object"),
|
|
26
|
-
ts.factory.createTypeOfExpression(input),
|
|
27
|
-
),
|
|
28
|
-
];
|
|
29
|
-
if (nullChecked === true)
|
|
30
|
-
conditions.push(
|
|
31
|
-
ts.factory.createStrictInequality(
|
|
32
|
-
ts.factory.createNull(),
|
|
33
|
-
input,
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
return conditions.length === 1
|
|
38
|
-
? conditions[0]!
|
|
39
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isInstanceOf(
|
|
43
|
-
input: ts.Expression,
|
|
44
|
-
type: string,
|
|
45
|
-
): ts.Expression {
|
|
46
|
-
return ts.factory.createBinaryExpression(
|
|
47
|
-
input,
|
|
48
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
49
|
-
ts.factory.createIdentifier(type),
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
+
return ts.factory.createStrictInequality(
|
|
6
|
+
ts.factory.createIdentifier("undefined"),
|
|
7
|
+
input,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
+
return ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
+
undefined,
|
|
15
|
+
[input],
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isObject(
|
|
20
|
+
input: ts.Expression,
|
|
21
|
+
nullChecked: boolean,
|
|
22
|
+
): ts.Expression {
|
|
23
|
+
const conditions: ts.Expression[] = [
|
|
24
|
+
ts.factory.createStrictEquality(
|
|
25
|
+
ts.factory.createStringLiteral("object"),
|
|
26
|
+
ts.factory.createTypeOfExpression(input),
|
|
27
|
+
),
|
|
28
|
+
];
|
|
29
|
+
if (nullChecked === true)
|
|
30
|
+
conditions.push(
|
|
31
|
+
ts.factory.createStrictInequality(
|
|
32
|
+
ts.factory.createNull(),
|
|
33
|
+
input,
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return conditions.length === 1
|
|
38
|
+
? conditions[0]!
|
|
39
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isInstanceOf(
|
|
43
|
+
input: ts.Expression,
|
|
44
|
+
type: string,
|
|
45
|
+
): ts.Expression {
|
|
46
|
+
return ts.factory.createBinaryExpression(
|
|
47
|
+
input,
|
|
48
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
49
|
+
ts.factory.createIdentifier(type),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Escaper } from "../utils/Escaper";
|
|
4
|
-
|
|
5
|
-
export namespace IdentifierFactory {
|
|
6
|
-
export function generate(name: string) {
|
|
7
|
-
return Escaper.variable(name)
|
|
8
|
-
? ts.factory.createIdentifier(name)
|
|
9
|
-
: ts.factory.createStringLiteral(name);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
-
const postfix = generate(name);
|
|
14
|
-
return ts.isStringLiteral(postfix)
|
|
15
|
-
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
-
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function postfix(str: string): string {
|
|
20
|
-
return Escaper.variable(str)
|
|
21
|
-
? `".${str}"`
|
|
22
|
-
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function parameter(
|
|
26
|
-
name: string | ts.BindingName,
|
|
27
|
-
init?: ts.Expression,
|
|
28
|
-
) {
|
|
29
|
-
if (ts.version >= "4.8")
|
|
30
|
-
return ts.factory.createParameterDeclaration(
|
|
31
|
-
undefined,
|
|
32
|
-
undefined,
|
|
33
|
-
name,
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
init,
|
|
37
|
-
);
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
return ts.factory.createParameterDeclaration(
|
|
40
|
-
undefined,
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
name,
|
|
44
|
-
undefined,
|
|
45
|
-
undefined,
|
|
46
|
-
init,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// export function property(
|
|
51
|
-
// name: string | ts.PropertyName,
|
|
52
|
-
// value: ts.Expression,
|
|
53
|
-
// ): ts.PropertyDeclaration {
|
|
54
|
-
// if (ts.version >= "4.8")
|
|
55
|
-
// return ts.factory.createPropertyDeclaration(
|
|
56
|
-
// undefined,
|
|
57
|
-
// name,
|
|
58
|
-
// undefined,
|
|
59
|
-
// undefined,
|
|
60
|
-
// value,
|
|
61
|
-
// );
|
|
62
|
-
// // eslint-disable-next-line
|
|
63
|
-
// return ts.factory.createPropertyDeclaration(
|
|
64
|
-
// undefined,
|
|
65
|
-
// undefined,
|
|
66
|
-
// name,
|
|
67
|
-
// undefined,
|
|
68
|
-
// undefined,
|
|
69
|
-
// value,
|
|
70
|
-
// );
|
|
71
|
-
// }
|
|
72
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Escaper } from "../utils/Escaper";
|
|
4
|
+
|
|
5
|
+
export namespace IdentifierFactory {
|
|
6
|
+
export function generate(name: string) {
|
|
7
|
+
return Escaper.variable(name)
|
|
8
|
+
? ts.factory.createIdentifier(name)
|
|
9
|
+
: ts.factory.createStringLiteral(name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
+
const postfix = generate(name);
|
|
14
|
+
return ts.isStringLiteral(postfix)
|
|
15
|
+
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
+
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function postfix(str: string): string {
|
|
20
|
+
return Escaper.variable(str)
|
|
21
|
+
? `".${str}"`
|
|
22
|
+
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parameter(
|
|
26
|
+
name: string | ts.BindingName,
|
|
27
|
+
init?: ts.Expression,
|
|
28
|
+
) {
|
|
29
|
+
if (ts.version >= "4.8")
|
|
30
|
+
return ts.factory.createParameterDeclaration(
|
|
31
|
+
undefined,
|
|
32
|
+
undefined,
|
|
33
|
+
name,
|
|
34
|
+
undefined,
|
|
35
|
+
undefined,
|
|
36
|
+
init,
|
|
37
|
+
);
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
return ts.factory.createParameterDeclaration(
|
|
40
|
+
undefined,
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
name,
|
|
44
|
+
undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
init,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// export function property(
|
|
51
|
+
// name: string | ts.PropertyName,
|
|
52
|
+
// value: ts.Expression,
|
|
53
|
+
// ): ts.PropertyDeclaration {
|
|
54
|
+
// if (ts.version >= "4.8")
|
|
55
|
+
// return ts.factory.createPropertyDeclaration(
|
|
56
|
+
// undefined,
|
|
57
|
+
// name,
|
|
58
|
+
// undefined,
|
|
59
|
+
// undefined,
|
|
60
|
+
// value,
|
|
61
|
+
// );
|
|
62
|
+
// // eslint-disable-next-line
|
|
63
|
+
// return ts.factory.createPropertyDeclaration(
|
|
64
|
+
// undefined,
|
|
65
|
+
// undefined,
|
|
66
|
+
// name,
|
|
67
|
+
// undefined,
|
|
68
|
+
// undefined,
|
|
69
|
+
// value,
|
|
70
|
+
// );
|
|
71
|
+
// }
|
|
72
|
+
}
|