@nestia/fetcher 1.3.3 → 1.3.5

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/HttpError.js CHANGED
@@ -1,81 +1,81 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.HttpError = void 0;
19
- /**
20
- * HTTP Error.
21
- *
22
- * `HttpError` is a type of error class who've been thrown by the remote HTTP server.
23
- *
24
- * @author Jeongho Nam - https://github.com/samchon
25
- */
26
- var HttpError = /** @class */ (function (_super) {
27
- __extends(HttpError, _super);
28
- /**
29
- * Initializer Constructor.
30
- *
31
- * @param method Method of the HTTP request.
32
- * @param path Path of the HTTP request.
33
- * @param status Status code from the remote HTTP server.
34
- * @param message Error message from the remote HTTP server.
35
- */
36
- function HttpError(method, path, status, message) {
37
- var _newTarget = this.constructor;
38
- var _this = _super.call(this, message) || this;
39
- _this.method = method;
40
- _this.path = path;
41
- _this.status = status;
42
- /**
43
- * @internal
44
- */
45
- _this.body_ = NOT_YET;
46
- // INHERITANCE POLYFILL
47
- var proto = _newTarget.prototype;
48
- if (Object.setPrototypeOf)
49
- Object.setPrototypeOf(_this, proto);
50
- else
51
- _this.__proto__ = proto;
52
- return _this;
53
- }
54
- /**
55
- * `HttpError` to JSON.
56
- *
57
- * When you call `JSON.stringify()` function on current `HttpError` instance,
58
- * this `HttpError.toJSON()` method would be automatically called.
59
- *
60
- * Also, if response body from the remote HTTP server forms a JSON object,
61
- * this `HttpError.toJSON()` method would be useful because it returns the
62
- * parsed JSON object about the {@link message} property.
63
- *
64
- * @template T Expected type of the response body.
65
- * @returns JSON object of the `HttpError`.
66
- */
67
- HttpError.prototype.toJSON = function () {
68
- if (this.body_ === NOT_YET)
69
- this.body_ = JSON.parse(this.message);
70
- return {
71
- method: this.method,
72
- path: this.path,
73
- status: this.status,
74
- message: this.body_,
75
- };
76
- };
77
- return HttpError;
78
- }(Error));
79
- exports.HttpError = HttpError;
80
- var NOT_YET = {};
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HttpError = void 0;
19
+ /**
20
+ * HTTP Error.
21
+ *
22
+ * `HttpError` is a type of error class who've been thrown by the remote HTTP server.
23
+ *
24
+ * @author Jeongho Nam - https://github.com/samchon
25
+ */
26
+ var HttpError = /** @class */ (function (_super) {
27
+ __extends(HttpError, _super);
28
+ /**
29
+ * Initializer Constructor.
30
+ *
31
+ * @param method Method of the HTTP request.
32
+ * @param path Path of the HTTP request.
33
+ * @param status Status code from the remote HTTP server.
34
+ * @param message Error message from the remote HTTP server.
35
+ */
36
+ function HttpError(method, path, status, message) {
37
+ var _newTarget = this.constructor;
38
+ var _this = _super.call(this, message) || this;
39
+ _this.method = method;
40
+ _this.path = path;
41
+ _this.status = status;
42
+ /**
43
+ * @internal
44
+ */
45
+ _this.body_ = NOT_YET;
46
+ // INHERITANCE POLYFILL
47
+ var proto = _newTarget.prototype;
48
+ if (Object.setPrototypeOf)
49
+ Object.setPrototypeOf(_this, proto);
50
+ else
51
+ _this.__proto__ = proto;
52
+ return _this;
53
+ }
54
+ /**
55
+ * `HttpError` to JSON.
56
+ *
57
+ * When you call `JSON.stringify()` function on current `HttpError` instance,
58
+ * this `HttpError.toJSON()` method would be automatically called.
59
+ *
60
+ * Also, if response body from the remote HTTP server forms a JSON object,
61
+ * this `HttpError.toJSON()` method would be useful because it returns the
62
+ * parsed JSON object about the {@link message} property.
63
+ *
64
+ * @template T Expected type of the response body.
65
+ * @returns JSON object of the `HttpError`.
66
+ */
67
+ HttpError.prototype.toJSON = function () {
68
+ if (this.body_ === NOT_YET)
69
+ this.body_ = JSON.parse(this.message);
70
+ return {
71
+ method: this.method,
72
+ path: this.path,
73
+ status: this.status,
74
+ message: this.body_,
75
+ };
76
+ };
77
+ return HttpError;
78
+ }(Error));
79
+ exports.HttpError = HttpError;
80
+ var NOT_YET = {};
81
81
  //# sourceMappingURL=HttpError.js.map
@@ -1,54 +1,110 @@
1
- import { IEncryptionPassword } from "./IEncryptionPassword";
2
- import { IRandomGenerator } from "./IRandomGenerator";
3
- /**
4
- * Connection information.
5
- *
6
- * `IConnection` is an interface ttype who represents connection information of the
7
- * remote HTTP server. You can target the remote HTTP server by wring the
8
- * {@link IConnection.host} variable down. Also, you can configure special header values
9
- * by specializing the {@link IConnection.headers} variable.
10
- *
11
- * If the remote HTTP server encrypts or decrypts its body data through the AES-128/256
12
- * algorithm, specify the {@link IConnection.encryption} with {@link IEncryptionPassword}
13
- * or {@link IEncryptionPassword.Closure} variable.
14
- *
15
- * @author Jenogho Nam - https://github.com/samchon
16
- */
17
- export interface IConnection {
18
- /**
19
- * Host address of the remote HTTP server.
20
- */
21
- host: string;
22
- /**
23
- * Header values delivered to the remote HTTP server.
24
- */
25
- headers?: Record<string, string>;
26
- /**
27
- * Encryption password of its closure function.
28
- */
29
- encryption?: IEncryptionPassword | IEncryptionPassword.Closure;
30
- /**
31
- * Use simulation mode.
32
- *
33
- * If you configure this property to be `true` or assign an {@link IRandomGenerator}
34
- * instance, your SDK library does not send any request to remote backend server,
35
- * but just returns random data generated by `typia.random<T>()` function with
36
- * request data validation.
37
- *
38
- * By the way, to utilize this simulation mode, SDK library must be generated with
39
- * {@link INestiaConfig.simulate} option, too. Open `nestia.config.ts` file, and
40
- * configure {@link INestiaConfig.simulate} property to be `true`. Them, newly
41
- * generated SDK library would have a built-in mock-up data generator.
42
- *
43
- * @default false
44
- */
45
- simulate?: boolean | Partial<IRandomGenerator>;
46
- /**
47
- * Use simulation mode.
48
- *
49
- * @default false
50
- * @deprecated Use {@link simulate} property instead.
51
- * This property would be erased after v2.0 update
52
- */
53
- random?: boolean | Partial<IRandomGenerator>;
54
- }
1
+ import { IEncryptionPassword } from "./IEncryptionPassword";
2
+ import { IRandomGenerator } from "./IRandomGenerator";
3
+ /**
4
+ * Connection information.
5
+ *
6
+ * `IConnection` is an interface ttype who represents connection information of the
7
+ * remote HTTP server. You can target the remote HTTP server by wring the
8
+ * {@link IConnection.host} variable down. Also, you can configure special header values
9
+ * by specializing the {@link IConnection.headers} variable.
10
+ *
11
+ * If the remote HTTP server encrypts or decrypts its body data through the AES-128/256
12
+ * algorithm, specify the {@link IConnection.encryption} with {@link IEncryptionPassword}
13
+ * or {@link IEncryptionPassword.Closure} variable.
14
+ *
15
+ * @author Jenogho Nam - https://github.com/samchon
16
+ * @author Seungjun We - https://github.com/SeungjunWe
17
+ */
18
+ export interface IConnection {
19
+ /**
20
+ * Host address of the remote HTTP server.
21
+ */
22
+ host: string;
23
+ /**
24
+ * Header values delivered to the remote HTTP server.
25
+ */
26
+ headers?: Record<string, string>;
27
+ /**
28
+ * Encryption password of its closure function.
29
+ */
30
+ encryption?: IEncryptionPassword | IEncryptionPassword.Closure;
31
+ /**
32
+ * Use simulation mode.
33
+ *
34
+ * If you configure this property to be `true` or assign an {@link IRandomGenerator}
35
+ * instance, your SDK library does not send any request to remote backend server,
36
+ * but just returns random data generated by `typia.random<T>()` function with
37
+ * request data validation.
38
+ *
39
+ * By the way, to utilize this simulation mode, SDK library must be generated with
40
+ * {@link INestiaConfig.simulate} option, too. Open `nestia.config.ts` file, and
41
+ * configure {@link INestiaConfig.simulate} property to be `true`. Them, newly
42
+ * generated SDK library would have a built-in mock-up data generator.
43
+ *
44
+ * @default false
45
+ */
46
+ simulate?: boolean | Partial<IRandomGenerator>;
47
+ /**
48
+ * Additional options for the `fetch` function.
49
+ */
50
+ options?: IConnection.IOptions;
51
+ }
52
+ export declare namespace IConnection {
53
+ /**
54
+ * Addiotional options for the `fetch` function.
55
+ *
56
+ * Almost same with {@link RequestInit} type of the {@link fetch} function,
57
+ * but `body`, `headers` and `method` properties are omitted.
58
+ *
59
+ * The reason why defining duplicated definition of {@link RequestInit}
60
+ * is for legacy NodeJS environments, which does not have the {@link fetch}
61
+ * function type.
62
+ */
63
+ interface IOptions {
64
+ /**
65
+ * A string indicating how the request will interact with the browser's
66
+ * cache to set request's cache.
67
+ */
68
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload";
69
+ /**
70
+ * A string indicating whether credentials will be sent with the request
71
+ * always, never, or only when sent to a same-origin URL. Sets request's
72
+ * credentials.
73
+ */
74
+ credentials?: "omit" | "same-origin" | "include";
75
+ /**
76
+ * A cryptographic hash of the resource to be fetched by request.
77
+ *
78
+ * Sets request's integrity.
79
+ */
80
+ integrity?: string;
81
+ /**
82
+ * A boolean to set request's keepalive.
83
+ */
84
+ keepalive?: boolean;
85
+ /**
86
+ * A string to indicate whether the request will use CORS, or will be
87
+ * restricted to same-origin URLs.
88
+ *
89
+ * Sets request's mode.
90
+ */
91
+ mode?: "cors" | "navigate" | "no-cors" | "same-origin";
92
+ /**
93
+ * A string indicating whether request follows redirects, results in
94
+ * an error upon encountering a redirect, or returns the redirect
95
+ * (in an opaque fashion).
96
+ *
97
+ * Sets request's redirect.
98
+ */
99
+ redirect?: "error" | "follow" | "manual";
100
+ /**
101
+ * A string whose value is a same-origin URL, "about:client", or the
102
+ * empty string, to set request's referrer.
103
+ */
104
+ referrer?: string;
105
+ /**
106
+ * A referrer policy to set request's referrerPolicy.
107
+ */
108
+ referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
109
+ }
110
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=IConnection.js.map
@@ -1,46 +1,46 @@
1
- /**
2
- * Encryption password.
3
- *
4
- * `IEncryptionPassword` is a type of interface who represents encryption password used by
5
- * the {@link Fetcher} with AES-128/256 algorithm. If your encryption password is not fixed
6
- * but changes according to the input content, you can utilize the
7
- * {@link IEncryptionPassword.Closure} function type.
8
- *
9
- * @author Jeongho Nam - https://github.com/samchon
10
- */
11
- export interface IEncryptionPassword {
12
- /**
13
- * Secret key.
14
- */
15
- key: string;
16
- /**
17
- * Initialization vector.
18
- */
19
- iv: string;
20
- }
21
- export declare namespace IEncryptionPassword {
22
- /**
23
- * Type of a closure function returning the {@link IEncryptionPassword} object.
24
- *
25
- * `IEncryptionPassword.Closure` is a type of closure function who are returning the
26
- * {@link IEncryptionPassword} object. It would be used when your encryption password
27
- * be changed according to the input content.
28
- */
29
- interface Closure {
30
- /**
31
- * Encryption password getter.
32
- *
33
- * @param param Request or response headers and body content
34
- * @param encoded Be encoded or to be decoded
35
- * @returns Encryption password
36
- */
37
- (param: IParameter, encoded: boolean): IEncryptionPassword;
38
- }
39
- /**
40
- * Parameter for the closure.
41
- */
42
- interface IParameter {
43
- headers: Record<string, string>;
44
- body: string;
45
- }
46
- }
1
+ /**
2
+ * Encryption password.
3
+ *
4
+ * `IEncryptionPassword` is a type of interface who represents encryption password used by
5
+ * the {@link Fetcher} with AES-128/256 algorithm. If your encryption password is not fixed
6
+ * but changes according to the input content, you can utilize the
7
+ * {@link IEncryptionPassword.Closure} function type.
8
+ *
9
+ * @author Jeongho Nam - https://github.com/samchon
10
+ */
11
+ export interface IEncryptionPassword {
12
+ /**
13
+ * Secret key.
14
+ */
15
+ key: string;
16
+ /**
17
+ * Initialization vector.
18
+ */
19
+ iv: string;
20
+ }
21
+ export declare namespace IEncryptionPassword {
22
+ /**
23
+ * Type of a closure function returning the {@link IEncryptionPassword} object.
24
+ *
25
+ * `IEncryptionPassword.Closure` is a type of closure function who are returning the
26
+ * {@link IEncryptionPassword} object. It would be used when your encryption password
27
+ * be changed according to the input content.
28
+ */
29
+ interface Closure {
30
+ /**
31
+ * Encryption password getter.
32
+ *
33
+ * @param param Request or response headers and body content
34
+ * @param encoded Be encoded or to be decoded
35
+ * @returns Encryption password
36
+ */
37
+ (param: IParameter, encoded: boolean): IEncryptionPassword;
38
+ }
39
+ /**
40
+ * Parameter for the closure.
41
+ */
42
+ interface IParameter {
43
+ headers: Record<string, string>;
44
+ body: string;
45
+ }
46
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=IEncryptionPassword.js.map
@@ -1,32 +1,32 @@
1
- export interface IRandomGenerator {
2
- boolean(): boolean;
3
- integer(minimum?: number, maximum?: number): number;
4
- number(minimum?: number, maximum?: number): number;
5
- bigint(minimum?: bigint, maximum?: bigint): bigint;
6
- string(length?: number): string;
7
- array<T>(closure: (index: number) => T, count?: number): T[];
8
- length(): number;
9
- uuid(): string;
10
- email(): string;
11
- url(): string;
12
- ipv4(): string;
13
- ipv6(): string;
14
- pattern(regex: RegExp): string;
15
- date(minimum?: number, maximum?: number): string;
16
- datetime(minimum?: number, maximum?: number): string;
17
- customs?: IRandomGenerator.CustomMap;
18
- }
19
- export declare namespace IRandomGenerator {
20
- type CustomMap = {
21
- [Type in keyof Customizable]?: (tags: ICommentTag[]) => Customizable[Type] | undefined;
22
- };
23
- type Customizable = {
24
- number: number;
25
- string: string;
26
- bigint: bigint;
27
- };
28
- interface ICommentTag {
29
- name: string;
30
- value?: string;
31
- }
32
- }
1
+ export interface IRandomGenerator {
2
+ boolean(): boolean;
3
+ integer(minimum?: number, maximum?: number): number;
4
+ number(minimum?: number, maximum?: number): number;
5
+ bigint(minimum?: bigint, maximum?: bigint): bigint;
6
+ string(length?: number): string;
7
+ array<T>(closure: (index: number) => T, count?: number): T[];
8
+ length(): number;
9
+ uuid(): string;
10
+ email(): string;
11
+ url(): string;
12
+ ipv4(): string;
13
+ ipv6(): string;
14
+ pattern(regex: RegExp): string;
15
+ date(minimum?: number, maximum?: number): string;
16
+ datetime(minimum?: number, maximum?: number): string;
17
+ customs?: IRandomGenerator.CustomMap;
18
+ }
19
+ export declare namespace IRandomGenerator {
20
+ type CustomMap = {
21
+ [Type in keyof Customizable]?: (tags: ICommentTag[]) => Customizable[Type] | undefined;
22
+ };
23
+ type Customizable = {
24
+ number: number;
25
+ string: string;
26
+ bigint: bigint;
27
+ };
28
+ interface ICommentTag {
29
+ name: string;
30
+ value?: string;
31
+ }
32
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=IRandomGenerator.js.map
@@ -1,54 +1,54 @@
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
- * @author Kyungsu Kang - https://github.com/kakasoo
31
- * @author Michael - https://github.com/8471919
32
- */
33
- export type Primitive<T> = Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>;
34
- type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
35
- type PrimitiveMain<Instance> = Instance extends [never] ? never : ValueOf<Instance> extends boolean | number | bigint | string ? ValueOf<Instance> : ValueOf<Instance> extends object ? Instance extends object ? Instance extends NativeClass ? {} : Instance extends IJsonable<infer Raw> ? ValueOf<Raw> extends object ? Raw extends object ? PrimitiveObject<Raw> : never : ValueOf<Raw> : PrimitiveObject<Instance> : never : ValueOf<Instance>;
36
- type PrimitiveObject<Instance extends object> = Instance extends Array<infer T> ? IsTuple<Instance> extends true ? PrimitiveTuple<Instance> : PrimitiveMain<T>[] : {
37
- [P in keyof Instance]: Instance[P] extends Function ? never : PrimitiveMain<Instance[P]>;
38
- };
39
- type PrimitiveTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [PrimitiveMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>] : T extends [(infer F)?] ? [PrimitiveMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>] : [];
40
- type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true ? boolean : IsValueOf<Instance, Number> extends true ? number : IsValueOf<Instance, String> extends true ? string : Instance;
41
- type NativeClass = Set<any> | Map<any, any> | WeakSet<any> | WeakMap<any, any> | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView;
42
- type IsTuple<T extends readonly any[] | {
43
- length: number;
44
- }> = [T] extends [
45
- never
46
- ] ? false : T extends readonly any[] ? number extends T["length"] ? false : true : false;
47
- type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
48
- interface IValueOf<T> {
49
- valueOf(): T;
50
- }
51
- interface IJsonable<T> {
52
- toJSON(): T;
53
- }
54
- export {};
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
+ * @author Kyungsu Kang - https://github.com/kakasoo
31
+ * @author Michael - https://github.com/8471919
32
+ */
33
+ export type Primitive<T> = Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>;
34
+ type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
35
+ type PrimitiveMain<Instance> = Instance extends [never] ? never : ValueOf<Instance> extends boolean | number | bigint | string ? ValueOf<Instance> : ValueOf<Instance> extends object ? Instance extends object ? Instance extends NativeClass ? {} : Instance extends IJsonable<infer Raw> ? ValueOf<Raw> extends object ? Raw extends object ? PrimitiveObject<Raw> : never : ValueOf<Raw> : PrimitiveObject<Instance> : never : ValueOf<Instance>;
36
+ type PrimitiveObject<Instance extends object> = Instance extends Array<infer T> ? IsTuple<Instance> extends true ? PrimitiveTuple<Instance> : PrimitiveMain<T>[] : {
37
+ [P in keyof Instance]: Instance[P] extends Function ? never : PrimitiveMain<Instance[P]>;
38
+ };
39
+ type PrimitiveTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [PrimitiveMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>] : T extends [(infer F)?] ? [PrimitiveMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>] : [];
40
+ type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true ? boolean : IsValueOf<Instance, Number> extends true ? number : IsValueOf<Instance, String> extends true ? string : Instance;
41
+ type NativeClass = Set<any> | Map<any, any> | WeakSet<any> | WeakMap<any, any> | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView;
42
+ type IsTuple<T extends readonly any[] | {
43
+ length: number;
44
+ }> = [T] extends [
45
+ never
46
+ ] ? false : T extends readonly any[] ? number extends T["length"] ? false : true : false;
47
+ type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
48
+ interface IValueOf<T> {
49
+ valueOf(): T;
50
+ }
51
+ interface IJsonable<T> {
52
+ toJSON(): T;
53
+ }
54
+ export {};
package/lib/Primitive.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=Primitive.js.map
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./IConnection";
2
- export * from "./IEncryptionPassword";
3
- export * from "./Primitive";
4
- export * from "./AesPkcs5";
5
- export * from "./Fetcher";
6
- export * from "./HttpError";
1
+ export * from "./IConnection";
2
+ export * from "./IEncryptionPassword";
3
+ export * from "./Primitive";
4
+ export * from "./AesPkcs5";
5
+ export * from "./Fetcher";
6
+ export * from "./HttpError";