@nestia/fetcher 2.0.0-dev.20230991 → 2.0.1

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.
@@ -1,4 +1,5 @@
1
1
  import { IConnection } from "./IConnection";
2
+ import { IPropagation } from "./IPropagation";
2
3
  import { Primitive } from "./Primitive";
3
4
  import { IFetchRoute } from "./internal/IFetchRoute";
4
5
  /**
@@ -40,4 +41,6 @@ export declare namespace EncryptedFetcher {
40
41
  * @return Response body data from the remote API
41
42
  */
42
43
  function fetch<Input, Output>(connection: IConnection, route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">, input?: Input, stringify?: (input: Input) => string): Promise<Primitive<Output>>;
44
+ function propagate<Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"GET" | "HEAD">): Promise<Output>;
45
+ function propagate<Input, Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input, stringify?: (input: Input) => string): Promise<Output>;
43
46
  }
@@ -94,5 +94,44 @@ var EncryptedFetcher;
94
94
  });
95
95
  }
96
96
  EncryptedFetcher.fetch = fetch;
97
+ function propagate(connection, route, input, stringify) {
98
+ var _a, _b, _c, _d;
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ var closure;
101
+ return __generator(this, function (_e) {
102
+ if ((((_a = route.request) === null || _a === void 0 ? void 0 : _a.encrypted) === true || ((_b = route.response) === null || _b === void 0 ? void 0 : _b.encrypted)) &&
103
+ connection.encryption === undefined)
104
+ throw new Error("Error on EncryptedFetcher.propagate(): the encryption password has not been configured.");
105
+ closure = typeof connection.encryption === "function"
106
+ ? function (direction) {
107
+ return function (headers, body) {
108
+ return connection.encryption({
109
+ headers: headers,
110
+ body: body,
111
+ direction: direction,
112
+ });
113
+ };
114
+ }
115
+ : function () { return function () { return connection.encryption; }; };
116
+ return [2 /*return*/, FetcherBase_1.FetcherBase.propagate({
117
+ className: "EncryptedFetcher",
118
+ encode: ((_c = route.request) === null || _c === void 0 ? void 0 : _c.encrypted) === true
119
+ ? function (input, headers) {
120
+ var p = closure("encode")(headers, input);
121
+ return AesPkcs5_1.AesPkcs5.encrypt(JSON.stringify(input), p.key, p.iv);
122
+ }
123
+ : function (input) { return input; },
124
+ decode: ((_d = route.response) === null || _d === void 0 ? void 0 : _d.encrypted) === true
125
+ ? function (input, headers) {
126
+ var p = closure("decode")(headers, input);
127
+ var str = AesPkcs5_1.AesPkcs5.decrypt(input, p.key, p.iv);
128
+ return str.length ? JSON.parse(str) : str;
129
+ }
130
+ : function (input) { return input; },
131
+ })(connection, route, input, stringify)];
132
+ });
133
+ });
134
+ }
135
+ EncryptedFetcher.propagate = propagate;
97
136
  })(EncryptedFetcher || (exports.EncryptedFetcher = EncryptedFetcher = {}));
98
137
  //# sourceMappingURL=EncryptedFetcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptedFetcher.js","sourceRoot":"","sources":["../src/EncryptedFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAsC;AAItC,sDAAqD;AAGrD;;;;;;;;;;;;;GAaG;AACH,IAAiB,gBAAgB,CAgGhC;AAhGD,WAAiB,gBAAgB;IAuC7B,SAAsB,KAAK,CACvB,UAAuB,EACvB,KAEC,EACD,KAAa,EACb,SAAoC;;;;;gBAEpC,IACI,CAAC,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,SAAS,MAAK,IAAI,KAAI,MAAA,KAAK,CAAC,QAAQ,0CAAE,SAAS,CAAA,CAAC;oBAChE,UAAU,CAAC,UAAU,KAAK,SAAS;oBAEnC,MAAM,IAAI,KAAK,CACX,qFAAqF,CACxF,CAAC;gBACA,OAAO,GACT,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU;oBACvC,CAAC,CAAC,UAAC,SAA8B;wBAC3B,OAAA,UACI,OAGC,EACD,IAAY;4BAEZ,OACI,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;4BAC9C,CAAC;4BACH,CAAC,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK;qBAC7B,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAoB,EAAC;;;KAC9D;IA3DqB,0BAAS,YA2D9B,CAAA;AACL,CAAC,EA3KgB,gBAAgB,gCAAhB,gBAAgB,QA2KhC"}
@@ -9,6 +9,7 @@ export declare class HttpError extends Error {
9
9
  readonly method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
10
10
  readonly path: string;
11
11
  readonly status: number;
12
+ readonly headers: Record<string, string | string[]>;
12
13
  /**
13
14
  * Initializer Constructor.
14
15
  *
@@ -17,7 +18,7 @@ export declare class HttpError extends Error {
17
18
  * @param status Status code from the remote HTTP server.
18
19
  * @param message Error message from the remote HTTP server.
19
20
  */
20
- constructor(method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD", path: string, status: number, message: string);
21
+ constructor(method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD", path: string, status: number, headers: Record<string, string | string[]>, message: string);
21
22
  /**
22
23
  * `HttpError` to JSON.
23
24
  *
@@ -41,6 +42,7 @@ export declare namespace HttpError {
41
42
  method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
42
43
  path: string;
43
44
  status: number;
45
+ headers: Record<string, string | string[]>;
44
46
  message: T;
45
47
  }
46
48
  }
package/lib/HttpError.js CHANGED
@@ -33,12 +33,13 @@ var HttpError = /** @class */ (function (_super) {
33
33
  * @param status Status code from the remote HTTP server.
34
34
  * @param message Error message from the remote HTTP server.
35
35
  */
36
- function HttpError(method, path, status, message) {
36
+ function HttpError(method, path, status, headers, message) {
37
37
  var _newTarget = this.constructor;
38
38
  var _this = _super.call(this, message) || this;
39
39
  _this.method = method;
40
40
  _this.path = path;
41
41
  _this.status = status;
42
+ _this.headers = headers;
42
43
  /**
43
44
  * @internal
44
45
  */
@@ -76,6 +77,7 @@ var HttpError = /** @class */ (function (_super) {
76
77
  method: this.method,
77
78
  path: this.path,
78
79
  status: this.status,
80
+ headers: this.headers,
79
81
  message: this.body_,
80
82
  };
81
83
  };
@@ -1 +1 @@
1
- {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH;IAA+B,6BAAK;IAMhC;;;;;;;OAOG;IACH,mBACoB,MAMJ,EACI,IAAY,EACZ,MAAc,EAC9B,OAAe;;QAVnB,YAYI,kBAAM,OAAO,CAAC,SAMjB;QAjBmB,YAAM,GAAN,MAAM,CAMV;QACI,UAAI,GAAJ,IAAI,CAAQ;QACZ,YAAM,GAAN,MAAM,CAAQ;QAtBlC;;WAEG;QACK,WAAK,GAAQ,OAAO,CAAC;QAwBzB,uBAAuB;QACvB,IAAM,KAAK,GAAc,WAAW,SAAS,CAAC;QAC9C,IAAI,MAAM,CAAC,cAAc;YAAE,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,KAAK,CAAC,CAAC;;YACxD,KAAY,CAAC,SAAS,GAAG,KAAK,CAAC;;IACzC,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,0BAAM,GAAb;QACI,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO;YACtB,IAAI;gBACA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACzC;YAAC,WAAM;gBACJ,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC;aAC7B;QACL,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,KAAK;SACtB,CAAC;IACN,CAAC;IACL,gBAAC;AAAD,CAAC,AA7DD,CAA+B,KAAK,GA6DnC;AA7DY,8BAAS;AA0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AG,EAAS,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { Primitive } from "./Primitive";
2
+ /**
3
+ * Propagation type.
4
+ *
5
+ * `IPropagation` is a type gathering all possible status codes and their body
6
+ * data types as a discriminated union type. You can specify the status code and
7
+ * its body data type just by using conditional statement like below.
8
+ *
9
+ * ```typescript
10
+ * type Output = IPropagation<{
11
+ * 200: ISeller.IAuthorized;
12
+ * 400: TypeGuardError.IProps;
13
+ * >};
14
+ *
15
+ * const output: Output = await sdk.sellers.authenticate.join(input);
16
+ * if (output.success) {
17
+ * // automatically casted to "ISeller.IAuthorized" type
18
+ * const authorized: ISeller.IAuthorized = output.data;
19
+ * } else if (output.status === 400) {
20
+ * // automatically casted to "TypeGuardError.IProps" type
21
+ * const error: TypeGuardError.IProps = output.data;
22
+ * } else {
23
+ * // unknown type when out of pre-defined status codes
24
+ * const result: unknown = output.data;
25
+ * }
26
+ * ```
27
+ *
28
+ * For reference, this `IPropagation` type is utilized by SDK library generated by
29
+ * `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
30
+ * In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
31
+ * typed data directly, but returns this `IPropagation` typed object instead.
32
+ *
33
+ * @template StatusMap Map of status code and its body data type.
34
+ * @template Success Default success status code.
35
+ * @author Jeongho Nam - https://github.com/samchon
36
+ */
37
+ export type IPropagation<StatusMap extends {
38
+ [P in IPropagation.Status]?: any;
39
+ }, Success extends number = 200 | 201> = {
40
+ [P in keyof StatusMap]: IPropagation.IBranch<P extends Success ? true : false, P, StatusMap[P]>;
41
+ }[keyof StatusMap] | IPropagation.IBranch<false, unknown, unknown>;
42
+ export declare namespace IPropagation {
43
+ /**
44
+ * Type of configurable status codes.
45
+ *
46
+ * The special characters like `2XX`, `3XX`, `4XX`, `5XX` are meaning the range
47
+ * of status codes. If `5XX` is specified, it means the status code is in the
48
+ * range of `500` to `599`.
49
+ */
50
+ export type Status = number | "2XX" | "3XX" | "4XX" | "5XX";
51
+ /**
52
+ * Branch type of propagation.
53
+ *
54
+ * `IPropagation.IBranch` is a branch type composing `IPropagation` type,
55
+ * which is gathering all possible status codes and their body data types
56
+ * as a union type.
57
+ */
58
+ export interface IBranch<Success extends boolean, StatusValue, BodyData> {
59
+ success: Success;
60
+ status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX" ? StatusRange<StatusValue> : StatusValue extends number ? StatusValue : never;
61
+ data: Primitive<BodyData>;
62
+ headers: Record<string, string | string[]>;
63
+ }
64
+ /**
65
+ * Range of status codes by the first digit.
66
+ */
67
+ export type StatusRange<T extends "2XX" | "3XX" | "4XX" | "5XX"> = T extends 0 ? IntRange<200, 299> : T extends 3 ? IntRange<300, 399> : T extends 4 ? IntRange<400, 499> : IntRange<500, 599>;
68
+ type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
69
+ type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
70
+ export {};
71
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IPropagation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IPropagation.js","sourceRoot":"","sources":["../src/IPropagation.ts"],"names":[],"mappings":""}
@@ -1,6 +1,7 @@
1
1
  import { IConnection } from "./IConnection";
2
2
  import { Primitive } from "./Primitive";
3
3
  import { IFetchRoute } from "./internal/IFetchRoute";
4
+ import { IPropagation } from "./IPropagation";
4
5
  /**
5
6
  * Utility class for `fetch` functions used in `@nestia/sdk`.
6
7
  *
@@ -41,4 +42,6 @@ export declare namespace PlainFetcher {
41
42
  * @return Response body data from the remote API
42
43
  */
43
44
  function fetch<Input, Output>(connection: IConnection, route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">, input?: Input, stringify?: (input: Input) => string): Promise<Primitive<Output>>;
45
+ function propagate<Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"GET" | "HEAD">): Promise<Output>;
46
+ function propagate<Input, Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input, stringify?: (input: Input) => string): Promise<Output>;
44
47
  }
@@ -71,5 +71,21 @@ var PlainFetcher;
71
71
  });
72
72
  }
73
73
  PlainFetcher.fetch = fetch;
74
+ function propagate(connection, route, input, stringify) {
75
+ var _a, _b;
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ return __generator(this, function (_c) {
78
+ if (((_a = route.request) === null || _a === void 0 ? void 0 : _a.encrypted) === true ||
79
+ ((_b = route.response) === null || _b === void 0 ? void 0 : _b.encrypted) === true)
80
+ throw new Error("Error on PlainFetcher.propagate(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.");
81
+ return [2 /*return*/, FetcherBase_1.FetcherBase.propagate({
82
+ className: "PlainFetcher",
83
+ encode: function (input) { return input; },
84
+ decode: function (input) { return input; },
85
+ })(connection, route, input, stringify)];
86
+ });
87
+ });
88
+ }
89
+ PlainFetcher.propagate = propagate;
74
90
  })(PlainFetcher || (exports.PlainFetcher = PlainFetcher = {}));
75
91
  //# sourceMappingURL=PlainFetcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlainFetcher.js","sourceRoot":"","sources":["../src/PlainFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,sDAAqD;AAErD;;;;;;;;;;;;;;GAcG;AACH,IAAiB,YAAY,CA4D5B;AA5DD,WAAiB,YAAY;IAuCzB,SAAsB,KAAK,CACvB,UAAuB,EACvB,KAEC,EACD,KAAa,EACb,SAAoC;;;;gBAEpC,IACI,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,SAAS,MAAK,IAAI;oBACjC,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,SAAS,MAAK,IAAI;oBAElC,MAAM,IAAI,KAAK,CACX,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,MAAA,KAAK,CAAC,OAAO,0CAAE,SAAS,MAAK,IAAI;oBACjC,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,SAAS,MAAK,IAAI;oBAElC,MAAM,IAAI,KAAK,CACX,gHAAgH,CACnH,CAAC;gBACN,sBAAO,yBAAW,CAAC,SAAS,CAAC;wBACzB,SAAS,EAAE,cAAc;wBACzB,MAAM,EAAE,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK;wBACxB,MAAM,EAAE,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK;qBAC3B,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAoB,EAAC;;;KAC9D;IAvBqB,sBAAS,YAuB9B,CAAA;AACL,CAAC,EAnGgB,YAAY,4BAAZ,YAAY,QAmG5B"}
@@ -1,16 +1,17 @@
1
1
  /**
2
- * Primitive type.
2
+ * Primitive type of JSON.
3
3
  *
4
- * `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
5
- * primitive type.
4
+ * `Primitive<T>` is a TMP (Type Meta Programming) type which converts
5
+ * its argument as a primitive type within framework JSON.
6
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`.
7
+ * If the target argument is a built-in class which returns its origin primitive type
8
+ * through the `valueOf()` method like the `String` or `Number`, its return type would
9
+ * be the `string` or `number`. Otherwise, the built-in class does not have the
10
+ * `valueOf()` method, the return type would be an empty object (`{}`).
10
11
  *
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.
12
+ * Otherwise, the target argument is a type of custom class, all of its custom method
13
+ * would be erased and its prototype would be changed to the primitive `object`.
14
+ * Therefore, return type of the TMP type finally be the primitive object.
14
15
  *
15
16
  * In addition, if the target argument is a type of custom class and it has a special
16
17
  * method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
@@ -23,18 +24,19 @@
23
24
  * `String` | `string`
24
25
  * `Class` | `object`
25
26
  * `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
27
+ * Native Class | `{}`
26
28
  * Others | No change
27
29
  *
28
30
  * @template Instance Target argument type.
29
- * @author Jenogho Nam - https://github.com/samchon
31
+ * @author Jeongho Nam - https://github.com/samchon
30
32
  * @author Kyungsu Kang - https://github.com/kakasoo
31
33
  * @author Michael - https://github.com/8471919
32
34
  */
33
35
  export type Primitive<T> = Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>;
34
36
  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>;
37
+ type PrimitiveMain<Instance> = Instance extends [never] ? never : ValueOf<Instance> extends bigint ? never : ValueOf<Instance> extends boolean | number | string ? ValueOf<Instance> : Instance extends Function ? never : 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
38
  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]>;
39
+ [P in keyof Instance]: PrimitiveMain<Instance[P]>;
38
40
  };
39
41
  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
42
  type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true ? boolean : IsValueOf<Instance, Number> extends true ? number : IsValueOf<Instance, String> extends true ? string : Instance;
@@ -44,7 +46,7 @@ type IsTuple<T extends readonly any[] | {
44
46
  }> = [T] extends [
45
47
  never
46
48
  ] ? 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;
49
+ type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer U> ? Instance extends U ? false : true : false : false;
48
50
  interface IValueOf<T> {
49
51
  valueOf(): T;
50
52
  }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Resolved type erased every methods.
3
+ *
4
+ * `Resolved` is a type of TMP (Type Meta Programming) type which converts
5
+ * its argument as a resolved type that erased every method properties.
6
+ *
7
+ * If the target argument is a built-in class which returns its origin primitive type
8
+ * through the `valueOf()` method like the `String` or `Number`, its return type would
9
+ * be the `string` or `number`. Otherwise, the built-in class does not have the
10
+ * `valueOf()` method, the return type would be same with the target argument.
11
+ *
12
+ * Otherwise, the target argument is a type of custom class, all of its custom methods
13
+ * would be erased and its prototype would be changed to the primitive `object`.
14
+ * Therefore, return type of the TMP type finally be the resolved object.
15
+ *
16
+ * Before | After
17
+ * ------------------------|----------------------------------------
18
+ * `Boolean` | `boolean`
19
+ * `Number` | `number`
20
+ * `BigInt` | `bigint`
21
+ * `String` | `string`
22
+ * `Class` | `interface`
23
+ * Native Class or Others | No change
24
+ *
25
+ * @template Instance Target argument type.
26
+ * @author Jeongho Nam - https://github.com/samchon
27
+ * @author Kyungsu Kang - https://github.com/kakasoo
28
+ */
29
+ export type Resolved<T> = Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
30
+ type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
31
+ type ResolvedMain<Instance> = Instance extends [never] ? never : ValueOf<Instance> extends boolean | number | bigint | string ? ValueOf<Instance> : Instance extends Function ? never : Instance extends object ? ResolvedObject<Instance> : ValueOf<Instance>;
32
+ type ResolvedObject<Instance extends object> = Instance extends Array<infer T> ? IsTuple<Instance> extends true ? ResolvedTuple<Instance> : ResolvedMain<T>[] : Instance extends Set<infer U> ? Set<ResolvedMain<U>> : Instance extends Map<infer K, infer V> ? Map<ResolvedMain<K>, ResolvedMain<V>> : Instance extends WeakSet<any> | WeakMap<any, any> ? never : Instance extends Date | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView ? Instance : {
33
+ [P in keyof Instance]: ResolvedMain<Instance[P]>;
34
+ };
35
+ type ResolvedTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [ResolvedMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [ResolvedMain<F>, ...ResolvedTuple<Rest>] : T extends [(infer F)?] ? [ResolvedMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [ResolvedMain<F>?, ...ResolvedTuple<Rest>] : [];
36
+ type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true ? boolean : IsValueOf<Instance, Number> extends true ? number : IsValueOf<Instance, String> extends true ? string : Instance;
37
+ type IsTuple<T extends readonly any[] | {
38
+ length: number;
39
+ }> = [T] extends [
40
+ never
41
+ ] ? false : T extends readonly any[] ? number extends T["length"] ? false : true : false;
42
+ type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
43
+ interface IValueOf<T> {
44
+ valueOf(): T;
45
+ }
46
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Resolved.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Resolved.js","sourceRoot":"","sources":["../src/Resolved.ts"],"names":[],"mappings":""}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./IConnection";
2
2
  export * from "./IEncryptionPassword";
3
+ export * from "./IPropagation";
3
4
  export * from "./IRandomGenerator";
4
- export * from "./Primitive";
5
5
  export * from "./HttpError";
6
+ export * from "./Primitive";
7
+ export * from "./Resolved";
package/lib/index.js CHANGED
@@ -16,7 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./IConnection"), exports);
18
18
  __exportStar(require("./IEncryptionPassword"), exports);
19
+ __exportStar(require("./IPropagation"), exports);
19
20
  __exportStar(require("./IRandomGenerator"), exports);
20
- __exportStar(require("./Primitive"), exports);
21
21
  __exportStar(require("./HttpError"), exports);
22
+ __exportStar(require("./Primitive"), exports);
23
+ __exportStar(require("./Resolved"), exports);
22
24
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,wDAAsC;AACtC,qDAAmC;AACnC,8CAA4B;AAC5B,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,wDAAsC;AACtC,iDAA+B;AAC/B,qDAAmC;AACnC,8CAA4B;AAC5B,8CAA4B;AAC5B,6CAA2B"}
@@ -1,6 +1,7 @@
1
1
  import { IConnection } from "../IConnection";
2
2
  import { Primitive } from "../Primitive";
3
3
  import { IFetchRoute } from "./IFetchRoute";
4
+ import { IPropagation } from "../IPropagation";
4
5
  export declare namespace FetcherBase {
5
6
  interface IProps {
6
7
  className: string;
@@ -8,4 +9,5 @@ export declare namespace FetcherBase {
8
9
  decode: (input: string, headers: Record<string, IConnection.HeaderValue | undefined>) => any;
9
10
  }
10
11
  const fetch: (props: IProps) => <Input, Output>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input | undefined, stringify?: ((input: Input) => string) | undefined) => Promise<Primitive<Output>>;
12
+ const propagate: (props: IProps) => <Input>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input | undefined, stringify?: ((input: Input) => string) | undefined) => Promise<IPropagation<any, any>>;
11
13
  }