@nestia/fetcher 1.4.0 → 1.5.0-dev.20230801
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 +18 -6
- package/lib/Fetcher.js +73 -8
- package/lib/Fetcher.js.map +1 -1
- package/lib/IConnection.d.ts +6 -2
- package/package.json +1 -1
- package/src/Fetcher.ts +25 -13
- package/src/IConnection.ts +18 -2
package/README.md
CHANGED
|
@@ -11,21 +11,27 @@ Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
|
11
11
|
|
|
12
12
|
- `@nestia/core`: super-fast decorators
|
|
13
13
|
- `@nestia/sdk`:
|
|
14
|
-
- SDK generator for clients
|
|
15
14
|
- Swagger generator evolved than ever
|
|
15
|
+
- SDK library generator for clients
|
|
16
|
+
- Mockup Simulator for client applications
|
|
16
17
|
- Automatic E2E test functions generator
|
|
18
|
+
- `@nestia/migrate`: migration from Swagger to NestJS
|
|
17
19
|
- `nestia`: just CLI (command line interface) tool
|
|
18
20
|
|
|
19
21
|
> **Note**
|
|
20
22
|
>
|
|
21
23
|
> - **Only one line** required, with pure TypeScript type
|
|
22
|
-
> -
|
|
23
|
-
>
|
|
24
|
-
>
|
|
24
|
+
> - Enhance performance **30x** up
|
|
25
|
+
> - Runtime validator is **20,000x faster** than `class-validator`
|
|
26
|
+
> - JSON serialization is **200x faster** than `class-transformer`
|
|
27
|
+
> - Software Development Kit
|
|
28
|
+
> - SDK is a collection of `fetch` functions with type definitions like [tRPC](https://trpc.io/)
|
|
29
|
+
> - Mockup simulator means embedded backend simulator in SDK
|
|
30
|
+
> - similar with [msw](https://mswjs.io/), but fully automated
|
|
25
31
|
|
|
26
32
|

|
|
27
33
|
|
|
28
|
-
> Left is server code, and right is client code utilizing SDK
|
|
34
|
+
> Left is NestJS server code, and right is client (frontend) code utilizing SDK
|
|
29
35
|
|
|
30
36
|
|
|
31
37
|
|
|
@@ -46,9 +52,9 @@ Check out the document in the [website](https://nestia.io/docs/):
|
|
|
46
52
|
### 🏠 Home
|
|
47
53
|
- [Introduction](https://nestia.io/docs/)
|
|
48
54
|
- [Setup](https://nestia.io/docs/setup/)
|
|
55
|
+
- [Pure TypeScript](https://nestia.io/docs/pure)
|
|
49
56
|
|
|
50
57
|
### 📖 Features
|
|
51
|
-
- [Pure TypeScript](https://nestia.io/docs/pure)
|
|
52
58
|
- Core Library
|
|
53
59
|
- [TypedRoute](https://nestia.io/docs/core/TypedRoute/)
|
|
54
60
|
- [TypedBody](https://nestia.io/docs/core/TypedBody/)
|
|
@@ -58,3 +64,9 @@ Check out the document in the [website](https://nestia.io/docs/):
|
|
|
58
64
|
- [Swagger Documents](https://nestia.io/docs/sdk/swagger/)
|
|
59
65
|
- [SDK Library](https://nestia.io/docs/sdk/sdk/)
|
|
60
66
|
- [E2E Functions](https://nestia.io/docs/sdk/e2e/)
|
|
67
|
+
- [Mockup Simulator](https://nestia.io/docs/sdk/simulator/)
|
|
68
|
+
- [Swagger to NestJS](https://nestia.io/docs/migrate/)
|
|
69
|
+
|
|
70
|
+
### 🔗 Appendix
|
|
71
|
+
- [⇲ Benchmark Result](https://github.com/samchon/nestia/tree/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz)
|
|
72
|
+
- [⇲ `dev.to` Articles](https://dev.to/samchon/series/22751)
|
package/lib/Fetcher.js
CHANGED
|
@@ -46,6 +46,33 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
60
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
61
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
62
|
+
if (!m) return o;
|
|
63
|
+
var i = m.call(o), r, ar = [], e;
|
|
64
|
+
try {
|
|
65
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
66
|
+
}
|
|
67
|
+
catch (error) { e = { error: error }; }
|
|
68
|
+
finally {
|
|
69
|
+
try {
|
|
70
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
71
|
+
}
|
|
72
|
+
finally { if (e) throw e.error; }
|
|
73
|
+
}
|
|
74
|
+
return ar;
|
|
75
|
+
};
|
|
49
76
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
77
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
78
|
};
|
|
@@ -82,13 +109,49 @@ var Fetcher = /** @class */ (function () {
|
|
|
82
109
|
if (encrypted.request === true || encrypted.response === true)
|
|
83
110
|
if (connection.encryption === undefined)
|
|
84
111
|
throw new Error("Error on nestia.Fetcher.encrypt(): the encryption password has not been configured.");
|
|
85
|
-
init = __assign(__assign({}, ((_a = connection.options) !== null && _a !== void 0 ? _a : {})), { method: method, headers:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
init = __assign(__assign({}, ((_a = connection.options) !== null && _a !== void 0 ? _a : {})), { method: method, headers: (function () {
|
|
113
|
+
var e_1, _a, e_2, _b;
|
|
114
|
+
var _c, _d;
|
|
115
|
+
var output = [];
|
|
116
|
+
try {
|
|
117
|
+
for (var _e = __values(Object.entries((_c = connection.headers) !== null && _c !== void 0 ? _c : {})), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
118
|
+
var _g = __read(_f.value, 2), key = _g[0], value = _g[1];
|
|
119
|
+
if (value === undefined)
|
|
120
|
+
continue;
|
|
121
|
+
else if (Array.isArray(value))
|
|
122
|
+
try {
|
|
123
|
+
for (var value_1 = (e_2 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
|
|
124
|
+
var v = value_1_1.value;
|
|
125
|
+
output.push([key, String(v)]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
129
|
+
finally {
|
|
130
|
+
try {
|
|
131
|
+
if (value_1_1 && !value_1_1.done && (_b = value_1.return)) _b.call(value_1);
|
|
132
|
+
}
|
|
133
|
+
finally { if (e_2) throw e_2.error; }
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
output.push([key, String(value)]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
140
|
+
finally {
|
|
141
|
+
try {
|
|
142
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
143
|
+
}
|
|
144
|
+
finally { if (e_1) throw e_1.error; }
|
|
145
|
+
}
|
|
146
|
+
if (((_d = connection.headers) === null || _d === void 0 ? void 0 : _d["Content-Type"]) === undefined)
|
|
147
|
+
output.push([
|
|
148
|
+
"Content-Type",
|
|
149
|
+
encrypted.request || typeof input === "string"
|
|
150
|
+
? "text/plain"
|
|
151
|
+
: "application/json",
|
|
152
|
+
]);
|
|
153
|
+
return output;
|
|
154
|
+
})() });
|
|
92
155
|
// REQUEST BODY (WITH ENCRYPTION)
|
|
93
156
|
if (input !== undefined)
|
|
94
157
|
init.body = (function () {
|
|
@@ -141,7 +204,9 @@ var Fetcher = /** @class */ (function () {
|
|
|
141
204
|
ret = content;
|
|
142
205
|
try {
|
|
143
206
|
// PARSE RESPONSE BODY
|
|
144
|
-
|
|
207
|
+
if (encrypted.response ||
|
|
208
|
+
((_b = response.headers.get("Content-Type")) !== null && _b !== void 0 ? _b : "").indexOf("application/json") !== -1)
|
|
209
|
+
ret = JSON.parse(ret);
|
|
145
210
|
// FIND __SET_HEADERS__ FIELD
|
|
146
211
|
if (ret.__set_headers__ !== undefined &&
|
|
147
212
|
typeof ret.__set_headers__ === "object") {
|
package/lib/Fetcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAM9B,uCAAsC;AACtC,yCAAwC;AACxC,kDAAiD;AAEjD;;;;;;;;;;;;;GAaG;AACH;IAAA;IAiLA,CAAC;IA5IuB,aAAK,GAAzB,UACI,UAAuB,EACvB,SAA6B,EAC7B,MAAmD,EACnD,IAAY,EACZ,KAAc,EACd,SAAqC;;;;;;;wBAErC,IAAI,SAAS,CAAC,OAAO,KAAK,IAAI,IAAI,SAAS,CAAC,QAAQ,KAAK,IAAI;4BACzD,IAAI,UAAU,CAAC,UAAU,KAAK,SAAS;gCACnC,MAAM,IAAI,KAAK,CACX,qFAAqF,CACxF,CAAC;wBAMJ,IAAI,yBACH,CAAC,MAAA,UAAU,CAAC,OAAO,mCAAI,EAAE,CAAC,KAC7B,MAAM,QAAA,EACN,OAAO,EAAE,CAAC;;;gCACN,IAAM,MAAM,GAAuB,EAAE,CAAC;;oCACtC,KAA2B,IAAA,KAAA,SAAA,MAAM,CAAC,OAAO,CACrC,MAAA,UAAU,CAAC,OAAO,mCAAI,EAAE,CAC3B,CAAA,gBAAA;wCAFU,IAAA,KAAA,mBAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;wCAGlB,IAAI,K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C,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAA,EAHjD,wBAGiD;qBAE7C,CAAA,MAAM,CAAC,KAAK,KAAK,SAAS,CAAA,EAA1B,wBAA0B;gBAC1B,KAAA,MAAM,CAAA;gBAAW,qBAAM,IAAA,iBAAO,EAAC,YAAY,CAAC,EAAA;;gBAA5C,GAAO,KAAK,GAAI,CAAC,SAA2B,CAAS,CAAC,OAAO,CAAC;;oBAClE,sBAAQ,MAAc,CAAC,KAAK,EAAC;oBAEjC,sBAAO,MAAM,CAAC,KAAK,EAAC;;;KACvB,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,OAAgB;IACvC,IAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,OAAO,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,GAAG,IAAK,OAAA,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAArB,CAAqB,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/lib/IConnection.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { IRandomGenerator } from "./IRandomGenerator";
|
|
|
15
15
|
* @author Jenogho Nam - https://github.com/samchon
|
|
16
16
|
* @author Seungjun We - https://github.com/SeungjunWe
|
|
17
17
|
*/
|
|
18
|
-
export interface IConnection {
|
|
18
|
+
export interface IConnection<Headers extends object = {}> {
|
|
19
19
|
/**
|
|
20
20
|
* Host address of the remote HTTP server.
|
|
21
21
|
*/
|
|
@@ -23,7 +23,7 @@ export interface IConnection {
|
|
|
23
23
|
/**
|
|
24
24
|
* Header values delivered to the remote HTTP server.
|
|
25
25
|
*/
|
|
26
|
-
headers?: Record<string,
|
|
26
|
+
headers?: Record<string, IConnection.HeaderValue> & IConnection.Headerify<Headers>;
|
|
27
27
|
/**
|
|
28
28
|
* Encryption password of its closure function.
|
|
29
29
|
*/
|
|
@@ -107,4 +107,8 @@ export declare namespace IConnection {
|
|
|
107
107
|
*/
|
|
108
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
109
|
}
|
|
110
|
+
type HeaderValue = string | boolean | number | bigint | string | Array<boolean> | Array<number> | Array<bigint> | Array<number> | Array<string>;
|
|
111
|
+
type Headerify<T extends object> = {
|
|
112
|
+
[P in keyof T]?: T[P] extends HeaderValue ? T[P] | undefined : never;
|
|
113
|
+
};
|
|
110
114
|
}
|
package/package.json
CHANGED
package/src/Fetcher.ts
CHANGED
|
@@ -80,19 +80,25 @@ export class Fetcher {
|
|
|
80
80
|
const init: RequestInit = {
|
|
81
81
|
...(connection.options ?? {}),
|
|
82
82
|
method,
|
|
83
|
-
headers:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
headers: (() => {
|
|
84
|
+
const output: [string, string][] = [];
|
|
85
|
+
for (const [key, value] of Object.entries(
|
|
86
|
+
connection.headers ?? {},
|
|
87
|
+
))
|
|
88
|
+
if (value === undefined) continue;
|
|
89
|
+
else if (Array.isArray(value))
|
|
90
|
+
for (const v of value) output.push([key, String(v)]);
|
|
91
|
+
else output.push([key, String(value)]);
|
|
92
|
+
if (connection.headers?.["Content-Type"] === undefined)
|
|
93
|
+
output.push([
|
|
94
|
+
"Content-Type",
|
|
95
|
+
encrypted.request || typeof input === "string"
|
|
96
|
+
? "text/plain"
|
|
97
|
+
: "application/json",
|
|
98
|
+
]);
|
|
99
|
+
return output;
|
|
100
|
+
})(),
|
|
92
101
|
};
|
|
93
|
-
if (encrypted.request || typeof input === "string")
|
|
94
|
-
(init.headers as Record<string, string>)["Content-Type"] =
|
|
95
|
-
"text/plain";
|
|
96
102
|
|
|
97
103
|
// REQUEST BODY (WITH ENCRYPTION)
|
|
98
104
|
if (input !== undefined)
|
|
@@ -172,7 +178,13 @@ export class Fetcher {
|
|
|
172
178
|
content as any;
|
|
173
179
|
try {
|
|
174
180
|
// PARSE RESPONSE BODY
|
|
175
|
-
|
|
181
|
+
if (
|
|
182
|
+
encrypted.response ||
|
|
183
|
+
(response.headers.get("Content-Type") ?? "").indexOf(
|
|
184
|
+
"application/json",
|
|
185
|
+
) !== -1
|
|
186
|
+
)
|
|
187
|
+
ret = JSON.parse(ret as any);
|
|
176
188
|
|
|
177
189
|
// FIND __SET_HEADERS__ FIELD
|
|
178
190
|
if (
|
package/src/IConnection.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { IRandomGenerator } from "./IRandomGenerator";
|
|
|
16
16
|
* @author Jenogho Nam - https://github.com/samchon
|
|
17
17
|
* @author Seungjun We - https://github.com/SeungjunWe
|
|
18
18
|
*/
|
|
19
|
-
export interface IConnection {
|
|
19
|
+
export interface IConnection<Headers extends object = {}> {
|
|
20
20
|
/**
|
|
21
21
|
* Host address of the remote HTTP server.
|
|
22
22
|
*/
|
|
@@ -25,7 +25,8 @@ export interface IConnection {
|
|
|
25
25
|
/**
|
|
26
26
|
* Header values delivered to the remote HTTP server.
|
|
27
27
|
*/
|
|
28
|
-
headers?: Record<string,
|
|
28
|
+
headers?: Record<string, IConnection.HeaderValue> &
|
|
29
|
+
IConnection.Headerify<Headers>;
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Encryption password of its closure function.
|
|
@@ -134,4 +135,19 @@ export namespace IConnection {
|
|
|
134
135
|
| "strict-origin-when-cross-origin"
|
|
135
136
|
| "unsafe-url";
|
|
136
137
|
}
|
|
138
|
+
|
|
139
|
+
export type HeaderValue =
|
|
140
|
+
| string
|
|
141
|
+
| boolean
|
|
142
|
+
| number
|
|
143
|
+
| bigint
|
|
144
|
+
| string
|
|
145
|
+
| Array<boolean>
|
|
146
|
+
| Array<number>
|
|
147
|
+
| Array<bigint>
|
|
148
|
+
| Array<number>
|
|
149
|
+
| Array<string>;
|
|
150
|
+
export type Headerify<T extends object> = {
|
|
151
|
+
[P in keyof T]?: T[P] extends HeaderValue ? T[P] | undefined : never;
|
|
152
|
+
};
|
|
137
153
|
}
|