typia 3.4.22 → 3.4.24
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 +57 -23
- package/lib/programmers/internal/check_dynamic_properties.js +5 -1
- package/lib/programmers/internal/check_dynamic_properties.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/CommandParser.ts +15 -15
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- 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/functional/$every.ts +11 -11
- 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/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/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- 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/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -47
- 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_number.ts +76 -76
- 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 +29 -29
- package/src/programmers/internal/check_dynamic_properties.ts +164 -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_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 +26 -26
- 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/NodeTransformer.ts +19 -19
- 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/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
|
@@ -224,29 +224,63 @@ export function createAssertStringify<T>(): (input: T) => string;
|
|
|
224
224
|
|
|
225
225
|
[Nestia](https://github.com/samchon/nestia) is a set of helper libraries for `NestJS`, supporting below features:
|
|
226
226
|
|
|
227
|
-
-
|
|
228
|
-
-
|
|
227
|
+
- `@nestia/core`: **15,000x times faster** validation decorators
|
|
228
|
+
- `@nestia/sdk`: evolved **SDK** and **Swagger** generators
|
|
229
|
+
- SDK (Software Development Kit)
|
|
230
|
+
- interaction library for client developers
|
|
231
|
+
- almost same with [tRPC](https://github.com/trpc/trpc)
|
|
229
232
|
- `nestia`: just CLI (command line interface) tool
|
|
230
233
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
234
|
+

|
|
235
|
+
|
|
236
|
+
### Reactia
|
|
237
|
+
> Not published yet, but soon
|
|
238
|
+
|
|
239
|
+
[](https://github.com/samchon/reactia/blob/master/LICENSE)
|
|
240
|
+
[](https://github.com/samchon/reactia/actions?query=workflow%3Abuild)
|
|
241
|
+
[](https://github.com/samchon/reactia/wiki)
|
|
242
|
+
|
|
243
|
+
[Reactia](https://github.com/samchon/reactia) is an automatic React components generator, just by analyzing TypeScript type.
|
|
244
|
+
|
|
245
|
+
- `@reactia/core`: Core Library analyzing TypeScript type
|
|
246
|
+
- `@reactia/mui`: Material UI Theme for `core` and `nest`
|
|
247
|
+
- `@reactia/nest`: Automatic Frontend Application Builder for `NestJS`
|
|
248
|
+
|
|
249
|
+

|
|
250
|
+
|
|
251
|
+
When you want to automate an individual component, just use `@reactia/core`.
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
import ReactDOM from "react-dom";
|
|
255
|
+
|
|
256
|
+
import typia from "typia";
|
|
257
|
+
import { ReactiaComponent } from "@reactia/core";
|
|
258
|
+
import { MuiInputTheme } from "@reactia/mui";
|
|
259
|
+
|
|
260
|
+
const RequestInput = ReactiaComponent<IRequestDto>(MuiInputTheme());
|
|
261
|
+
const input: IRequestDto = { ... };
|
|
262
|
+
|
|
263
|
+
ReactDOM.render(
|
|
264
|
+
<RequestInput input={input} />,
|
|
265
|
+
document.body
|
|
266
|
+
);
|
|
252
267
|
```
|
|
268
|
+
|
|
269
|
+
Otherwise, you can fully automate frontend application development through `@reactia/nest`.
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
import React from "react";
|
|
273
|
+
import ReactDOM from "react-dom";
|
|
274
|
+
|
|
275
|
+
import { ISwagger } "@nestia/swagger";
|
|
276
|
+
import { MuiApplicationTheme } from "@reactia/mui";
|
|
277
|
+
import { ReactiaApplication } from "@reactia/nest";
|
|
278
|
+
|
|
279
|
+
const swagger: ISwagger = await import("./swagger.json");
|
|
280
|
+
const App: React.FC = ReactiaApplication(MuiApplicationTheme())(swagger);
|
|
281
|
+
|
|
282
|
+
ReactDOM.render(
|
|
283
|
+
<App />,
|
|
284
|
+
document.body
|
|
285
|
+
);
|
|
286
|
+
```
|
|
@@ -47,13 +47,17 @@ var check_everything_1 = require("./check_everything");
|
|
|
47
47
|
var metadata_to_pattern_1 = require("./metadata_to_pattern");
|
|
48
48
|
var check_dynamic_properties = function (props) {
|
|
49
49
|
return function (regular, dynamic) {
|
|
50
|
+
var length = props.equals === true && dynamic.length === 0
|
|
51
|
+
? typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createNumericLiteral(regular.filter(function (r) { return r.meta.required; }).length), IdentifierFactory_1.IdentifierFactory.join(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("Object.keys"), undefined, [typescript_1.default.factory.createIdentifier("input")]), "length"))
|
|
52
|
+
: null;
|
|
50
53
|
var criteria = props.entries
|
|
51
54
|
? typescript_1.default.factory.createCallExpression(props.entries, undefined, [
|
|
52
55
|
typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("Object.keys"), undefined, [typescript_1.default.factory.createIdentifier("input")]),
|
|
53
56
|
check_dynamic_property(props)(regular, dynamic),
|
|
54
57
|
])
|
|
55
58
|
: typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.join(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("Object.keys"), undefined, [typescript_1.default.factory.createIdentifier("input")]), props.assert ? "every" : "map"), undefined, [check_dynamic_property(props)(regular, dynamic)]);
|
|
56
|
-
|
|
59
|
+
var right = (props.halt || (function (elem) { return elem; }))(props.assert ? criteria : (0, check_everything_1.check_everything)(criteria));
|
|
60
|
+
return length ? typescript_1.default.factory.createLogicalOr(length, right) : right;
|
|
57
61
|
};
|
|
58
62
|
};
|
|
59
63
|
exports.check_dynamic_properties = check_dynamic_properties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check_dynamic_properties.js","sourceRoot":"","sources":["../../../src/programmers/internal/check_dynamic_properties.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,uEAAsE;AACtE,qEAAoE;AAGpE,uDAAsD;AAEtD,6DAA4D;AAKrD,IAAM,wBAAwB,GACjC,UAAC,KAA0B;IAC3B,OAAA,UACI,OAA2B,EAC3B,OAA2B;QAE3B,IAAM,QAAQ,GAAG,KAAK,CAAC,OAAO;YAC1B,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE;gBACtD,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAC1C,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACzC;gBACD,sBAAsB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC;aAClD,CAAC;YACJ,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,qCAAiB,CAAC,IAAI,CAClB,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAC1C,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACzC,EACD,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CACjC,EACD,SAAS,EACT,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CACpD,CAAC;QACR,
|
|
1
|
+
{"version":3,"file":"check_dynamic_properties.js","sourceRoot":"","sources":["../../../src/programmers/internal/check_dynamic_properties.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,uEAAsE;AACtE,qEAAoE;AAGpE,uDAAsD;AAEtD,6DAA4D;AAKrD,IAAM,wBAAwB,GACjC,UAAC,KAA0B;IAC3B,OAAA,UACI,OAA2B,EAC3B,OAA2B;QAE3B,IAAM,MAAM,GACR,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YACzC,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,OAAO,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAf,CAAe,CAAC,CAAC,MAAM,CAChD,EACD,qCAAiB,CAAC,IAAI,CAClB,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAC1C,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACzC,EACD,QAAQ,CACX,CACJ;YACH,CAAC,CAAC,IAAI,CAAC;QAEf,IAAM,QAAQ,GAAG,KAAK,CAAC,OAAO;YAC1B,CAAC,CAAC,o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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,15 +1,15 @@
|
|
|
1
|
-
export namespace CommandParser {
|
|
2
|
-
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
-
const output: Record<string, string> = {};
|
|
4
|
-
argList.forEach((arg, i) => {
|
|
5
|
-
if (arg.startsWith("--") === false) return;
|
|
6
|
-
|
|
7
|
-
const key = arg.slice(2);
|
|
8
|
-
const value: string | undefined = argList[i + 1];
|
|
9
|
-
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
-
|
|
11
|
-
output[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -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,66 +1,66 @@
|
|
|
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
|
-
options: {
|
|
22
|
-
checkNull: boolean;
|
|
23
|
-
checkArray: boolean;
|
|
24
|
-
},
|
|
25
|
-
): ts.Expression {
|
|
26
|
-
const conditions: ts.Expression[] = [
|
|
27
|
-
ts.factory.createStrictEquality(
|
|
28
|
-
ts.factory.createStringLiteral("object"),
|
|
29
|
-
ts.factory.createTypeOfExpression(input),
|
|
30
|
-
),
|
|
31
|
-
];
|
|
32
|
-
if (options.checkNull === true)
|
|
33
|
-
conditions.push(
|
|
34
|
-
ts.factory.createStrictInequality(
|
|
35
|
-
ts.factory.createNull(),
|
|
36
|
-
input,
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
if (options.checkArray === true)
|
|
40
|
-
conditions.push(
|
|
41
|
-
ts.factory.createStrictEquality(
|
|
42
|
-
ts.factory.createFalse(),
|
|
43
|
-
ts.factory.createCallExpression(
|
|
44
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
-
undefined,
|
|
46
|
-
[input],
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return conditions.length === 1
|
|
52
|
-
? conditions[0]!
|
|
53
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isInstanceOf(
|
|
57
|
-
input: ts.Expression,
|
|
58
|
-
type: string,
|
|
59
|
-
): ts.Expression {
|
|
60
|
-
return ts.factory.createBinaryExpression(
|
|
61
|
-
input,
|
|
62
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
-
ts.factory.createIdentifier(type),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
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
|
+
options: {
|
|
22
|
+
checkNull: boolean;
|
|
23
|
+
checkArray: boolean;
|
|
24
|
+
},
|
|
25
|
+
): ts.Expression {
|
|
26
|
+
const conditions: ts.Expression[] = [
|
|
27
|
+
ts.factory.createStrictEquality(
|
|
28
|
+
ts.factory.createStringLiteral("object"),
|
|
29
|
+
ts.factory.createTypeOfExpression(input),
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
if (options.checkNull === true)
|
|
33
|
+
conditions.push(
|
|
34
|
+
ts.factory.createStrictInequality(
|
|
35
|
+
ts.factory.createNull(),
|
|
36
|
+
input,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
if (options.checkArray === true)
|
|
40
|
+
conditions.push(
|
|
41
|
+
ts.factory.createStrictEquality(
|
|
42
|
+
ts.factory.createFalse(),
|
|
43
|
+
ts.factory.createCallExpression(
|
|
44
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
+
undefined,
|
|
46
|
+
[input],
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return conditions.length === 1
|
|
52
|
+
? conditions[0]!
|
|
53
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isInstanceOf(
|
|
57
|
+
input: ts.Expression,
|
|
58
|
+
type: string,
|
|
59
|
+
): ts.Expression {
|
|
60
|
+
return ts.factory.createBinaryExpression(
|
|
61
|
+
input,
|
|
62
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
+
ts.factory.createIdentifier(type),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|