@nestia/fetcher 2.0.0-dev.20230906 → 2.0.0-dev.20230908
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/EncryptedFetcher.d.ts +3 -0
- package/lib/EncryptedFetcher.js +39 -0
- package/lib/EncryptedFetcher.js.map +1 -1
- package/lib/HttpError.d.ts +3 -1
- package/lib/HttpError.js +3 -1
- package/lib/HttpError.js.map +1 -1
- package/lib/IPropagation.d.ts +42 -0
- package/lib/IPropagation.js +3 -0
- package/lib/IPropagation.js.map +1 -0
- package/lib/PlainFetcher.d.ts +3 -0
- package/lib/PlainFetcher.js +16 -0
- package/lib/PlainFetcher.js.map +1 -1
- package/lib/Primitive.d.ts +15 -13
- package/lib/Resolved.d.ts +46 -0
- package/lib/Resolved.js +3 -0
- package/lib/Resolved.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/internal/FetcherBase.d.ts +2 -0
- package/lib/internal/FetcherBase.js +153 -99
- package/lib/internal/FetcherBase.js.map +1 -1
- package/package.json +1 -1
- package/src/EncryptedFetcher.ts +74 -0
- package/src/HttpError.ts +3 -0
- package/src/IPropagation.ts +73 -0
- package/src/PlainFetcher.ts +38 -0
- package/src/Primitive.ts +20 -16
- package/src/Resolved.ts +116 -0
- package/src/index.ts +3 -1
- package/src/internal/FetcherBase.ts +87 -39
|
@@ -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<"HEAD">): Promise<Output>;
|
|
45
|
+
function propagate<Input, Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"HEAD">, input?: Input, stringify?: (input: Input) => string): Promise<Output>;
|
|
43
46
|
}
|
package/lib/EncryptedFetcher.js
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"EncryptedFetcher.js","sourceRoot":"","sources":["../src/EncryptedFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAsC;AAKtC,sDAAqD;AAGrD;;;;;;;;;;;;;GAaG;AACH,IAAiB,gBAAgB,CAyKhC;AAzKD,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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ACN,CAAC;4BACH,CAAC,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK;wBAC1B,MAAM,EACF,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,SAAS,MAAK,IAAI;4BAC9B,CAAC,CAAC,UAAC,KAAK,EAAE,OAAO;gCACX,IAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gCAC5C,IAAM,GAAG,GAAG,mBAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;gCACjD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;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,EAzKgB,gBAAgB,gCAAhB,gBAAgB,QAyKhC"}
|
package/lib/HttpError.d.ts
CHANGED
|
@@ -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
|
};
|
package/lib/HttpError.js.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file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|
+
/**
|
|
2
|
+
* Propagation type.
|
|
3
|
+
*
|
|
4
|
+
* @template StatusMap Map of status code and its body data type.
|
|
5
|
+
* @template Success Default success status code.
|
|
6
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
7
|
+
*/
|
|
8
|
+
export type IPropagation<StatusMap extends {
|
|
9
|
+
[P in IPropagation.Status]?: any;
|
|
10
|
+
}, Success extends number = 200 | 201> = {
|
|
11
|
+
[P in keyof StatusMap]: IPropagation.IBranch<P extends Success ? true : false, P, StatusMap[P]>;
|
|
12
|
+
}[keyof StatusMap] | IPropagation.IBranch<false, number, any>;
|
|
13
|
+
export declare namespace IPropagation {
|
|
14
|
+
/**
|
|
15
|
+
* Type of configurable status codes.
|
|
16
|
+
*
|
|
17
|
+
* The special characters like `2XX`, `3XX`, `4XX`, `5XX` are meaning the range
|
|
18
|
+
* of status codes. If `5XX` is specified, it means the status code is in the
|
|
19
|
+
* range of `500` to `599`.
|
|
20
|
+
*/
|
|
21
|
+
export type Status = number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
22
|
+
/**
|
|
23
|
+
* Branch type of propagation.
|
|
24
|
+
*
|
|
25
|
+
* `IPropagation.IBranch` is a branch type composing `IPropagation` type,
|
|
26
|
+
* which is gathering all possible status codes and their body data types
|
|
27
|
+
* as a union type.
|
|
28
|
+
*/
|
|
29
|
+
export interface IBranch<Success extends boolean, StatusValue, BodyData> {
|
|
30
|
+
success: Success;
|
|
31
|
+
status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX" ? StatusRange<StatusValue> : StatusValue extends number ? StatusValue : never;
|
|
32
|
+
data: BodyData;
|
|
33
|
+
headers: Record<string, string | string[]>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Range of status codes by the first digit.
|
|
37
|
+
*/
|
|
38
|
+
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>;
|
|
39
|
+
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
40
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
|
|
41
|
+
export {};
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPropagation.js","sourceRoot":"","sources":["../src/IPropagation.ts"],"names":[],"mappings":""}
|
package/lib/PlainFetcher.d.ts
CHANGED
|
@@ -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<"HEAD">): Promise<Output>;
|
|
46
|
+
function propagate<Input, Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"HEAD">, input?: Input, stringify?: (input: Input) => string): Promise<Output>;
|
|
44
47
|
}
|
package/lib/PlainFetcher.js
CHANGED
|
@@ -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
|
package/lib/PlainFetcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainFetcher.js","sourceRoot":"","sources":["../src/PlainFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,sDAAqD;
|
|
1
|
+
{"version":3,"file":"PlainFetcher.js","sourceRoot":"","sources":["../src/PlainFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,sDAAqD;AAGrD;;;;;;;;;;;;;;GAcG;AACH,IAAiB,YAAY,CAiG5B;AAjGD,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,4GAA4G,CAC/G,CAAC;gBACN,sBAAO,yBAAW,CAAC,KAAK,CAAC;wBACrB,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,CAAC,EAAC;;;KAC3C;IApBqB,kBAAK,QAoB1B,CAAA;IAcD,SAAsB,SAAS,CAI3B,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,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,EAjGgB,YAAY,4BAAZ,YAAY,QAiG5B"}
|
package/lib/Primitive.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Primitive type.
|
|
2
|
+
* Primitive type of JSON.
|
|
3
3
|
*
|
|
4
|
-
* `Primitive
|
|
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
|
|
8
|
-
* the `valueOf()` method like the `String` or `Number`, its return type would
|
|
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
|
|
12
|
-
* be erased and its prototype would be changed to the primitive `object`.
|
|
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
|
|
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 |
|
|
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]:
|
|
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
|
|
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 {};
|
package/lib/Resolved.js
ADDED
|
@@ -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
|
}
|