@nestia/fetcher 3.0.0-dev.20231209 → 3.0.0
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 +12 -9
- package/lib/{internal/AesPkcs5.d.ts → AesPkcs5.d.ts} +2 -2
- package/lib/{internal/AesPkcs5.js → AesPkcs5.js} +8 -16
- package/lib/AesPkcs5.js.map +1 -0
- package/lib/EncryptedFetcher.d.ts +3 -4
- package/lib/EncryptedFetcher.js +8 -11
- package/lib/EncryptedFetcher.js.map +1 -1
- package/lib/IConnection.d.ts +11 -2
- package/lib/IEncryptionPassword.d.ts +2 -8
- package/lib/IFetchEvent.d.ts +11 -0
- package/lib/IFetchEvent.js +21 -0
- package/lib/IFetchEvent.js.map +1 -0
- package/lib/{internal/IFetchRoute.d.ts → IFetchRoute.d.ts} +1 -1
- package/lib/{internal/IFetchRoute.js.map → IFetchRoute.js.map} +1 -1
- package/lib/NestiaSimulator.d.ts +13 -0
- package/lib/NestiaSimulator.js +62 -0
- package/lib/NestiaSimulator.js.map +1 -0
- package/lib/PlainFetcher.d.ts +3 -4
- package/lib/PlainFetcher.js +2 -2
- package/lib/PlainFetcher.js.map +1 -1
- package/lib/Resolved.d.ts +5 -5
- 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 +5 -6
- package/lib/internal/FetcherBase.js +143 -70
- package/lib/internal/FetcherBase.js.map +1 -1
- package/package.json +2 -2
- package/src/{internal/AesPkcs5.ts → AesPkcs5.ts} +50 -66
- package/src/EncryptedFetcher.ts +174 -179
- package/src/HttpError.ts +85 -85
- package/src/IConnection.ts +247 -237
- package/src/IEncryptionPassword.ts +50 -56
- package/src/IFetchEvent.ts +31 -0
- package/src/{internal/IFetchRoute.ts → IFetchRoute.ts} +62 -62
- package/src/IPropagation.ts +102 -102
- package/src/IRandomGenerator.ts +38 -38
- package/src/NestiaSimulator.ts +82 -0
- package/src/PlainFetcher.ts +105 -106
- package/src/Primitive.ts +136 -135
- package/src/Resolved.ts +119 -116
- package/src/index.ts +9 -7
- package/src/internal/FetcherBase.ts +124 -72
- package/src/internal/Singleton.ts +20 -20
- package/lib/internal/AesPkcs5.js.map +0 -1
- /package/lib/{internal/IFetchRoute.js → IFetchRoute.js} +0 -0
package/src/Resolved.ts
CHANGED
|
@@ -1,116 +1,119 @@
|
|
|
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
|
|
26
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
27
|
-
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
28
|
-
*/
|
|
29
|
-
export type Resolved<T> =
|
|
30
|
-
? T
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
? [
|
|
80
|
-
: T extends [infer F
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
?
|
|
94
|
-
:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
?
|
|
103
|
-
: true
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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 T 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> =
|
|
30
|
+
Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
|
|
31
|
+
|
|
32
|
+
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
33
|
+
|
|
34
|
+
type ResolvedMain<T> = T extends [never]
|
|
35
|
+
? never // (special trick for jsonable | null) type
|
|
36
|
+
: ValueOf<T> extends boolean | number | bigint | string
|
|
37
|
+
? ValueOf<T>
|
|
38
|
+
: T extends Function
|
|
39
|
+
? never
|
|
40
|
+
: T extends object
|
|
41
|
+
? ResolvedObject<T>
|
|
42
|
+
: ValueOf<T>;
|
|
43
|
+
|
|
44
|
+
type ResolvedObject<T extends object> =
|
|
45
|
+
T extends Array<infer U>
|
|
46
|
+
? IsTuple<T> extends true
|
|
47
|
+
? ResolvedTuple<T>
|
|
48
|
+
: ResolvedMain<U>[]
|
|
49
|
+
: T extends Set<infer U>
|
|
50
|
+
? Set<ResolvedMain<U>>
|
|
51
|
+
: T extends Map<infer K, infer V>
|
|
52
|
+
? Map<ResolvedMain<K>, ResolvedMain<V>>
|
|
53
|
+
: T extends WeakSet<any> | WeakMap<any, any>
|
|
54
|
+
? never
|
|
55
|
+
: T extends
|
|
56
|
+
| Date
|
|
57
|
+
| Uint8Array
|
|
58
|
+
| Uint8ClampedArray
|
|
59
|
+
| Uint16Array
|
|
60
|
+
| Uint32Array
|
|
61
|
+
| BigUint64Array
|
|
62
|
+
| Int8Array
|
|
63
|
+
| Int16Array
|
|
64
|
+
| Int32Array
|
|
65
|
+
| BigInt64Array
|
|
66
|
+
| Float32Array
|
|
67
|
+
| Float64Array
|
|
68
|
+
| ArrayBuffer
|
|
69
|
+
| SharedArrayBuffer
|
|
70
|
+
| DataView
|
|
71
|
+
| Blob
|
|
72
|
+
| File
|
|
73
|
+
? T
|
|
74
|
+
: {
|
|
75
|
+
[P in keyof T]: ResolvedMain<T[P]>;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type ResolvedTuple<T extends readonly any[]> = T extends []
|
|
79
|
+
? []
|
|
80
|
+
: T extends [infer F]
|
|
81
|
+
? [ResolvedMain<F>]
|
|
82
|
+
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
83
|
+
? [ResolvedMain<F>, ...ResolvedTuple<Rest>]
|
|
84
|
+
: T extends [(infer F)?]
|
|
85
|
+
? [ResolvedMain<F>?]
|
|
86
|
+
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
87
|
+
? [ResolvedMain<F>?, ...ResolvedTuple<Rest>]
|
|
88
|
+
: [];
|
|
89
|
+
|
|
90
|
+
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
91
|
+
never,
|
|
92
|
+
]
|
|
93
|
+
? false
|
|
94
|
+
: T extends readonly any[]
|
|
95
|
+
? number extends T["length"]
|
|
96
|
+
? false
|
|
97
|
+
: true
|
|
98
|
+
: false;
|
|
99
|
+
|
|
100
|
+
type ValueOf<Instance> =
|
|
101
|
+
IsValueOf<Instance, Boolean> extends true
|
|
102
|
+
? boolean
|
|
103
|
+
: IsValueOf<Instance, Number> extends true
|
|
104
|
+
? number
|
|
105
|
+
: IsValueOf<Instance, String> extends true
|
|
106
|
+
? string
|
|
107
|
+
: Instance;
|
|
108
|
+
|
|
109
|
+
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
110
|
+
? Object extends IValueOf<infer Primitive>
|
|
111
|
+
? Instance extends Primitive
|
|
112
|
+
? false
|
|
113
|
+
: true // not Primitive, but Object
|
|
114
|
+
: false // cannot be
|
|
115
|
+
: false;
|
|
116
|
+
|
|
117
|
+
interface IValueOf<T> {
|
|
118
|
+
valueOf(): T;
|
|
119
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
1
|
+
export * from "./HttpError";
|
|
2
|
+
export * from "./IConnection";
|
|
3
|
+
export * from "./IEncryptionPassword";
|
|
4
|
+
export * from "./IFetchEvent";
|
|
5
|
+
export * from "./IFetchRoute";
|
|
6
|
+
export * from "./IPropagation";
|
|
7
|
+
export * from "./IRandomGenerator";
|
|
8
|
+
export * from "./Primitive";
|
|
9
|
+
export * from "./Resolved";
|
|
@@ -2,9 +2,9 @@ import import2 from "import2";
|
|
|
2
2
|
|
|
3
3
|
import { HttpError } from "../HttpError";
|
|
4
4
|
import { IConnection } from "../IConnection";
|
|
5
|
+
import { IFetchEvent } from "../IFetchEvent";
|
|
6
|
+
import { IFetchRoute } from "../IFetchRoute";
|
|
5
7
|
import { IPropagation } from "../IPropagation";
|
|
6
|
-
import { Primitive } from "../Primitive";
|
|
7
|
-
import { IFetchRoute } from "./IFetchRoute";
|
|
8
8
|
import { Singleton } from "./Singleton";
|
|
9
9
|
|
|
10
10
|
export namespace FetcherBase {
|
|
@@ -13,9 +13,9 @@ export namespace FetcherBase {
|
|
|
13
13
|
encode: (
|
|
14
14
|
input: any,
|
|
15
15
|
headers: Record<string, IConnection.HeaderValue | undefined>,
|
|
16
|
-
) => string
|
|
16
|
+
) => string;
|
|
17
17
|
decode: (
|
|
18
|
-
input: string
|
|
18
|
+
input: string,
|
|
19
19
|
headers: Record<string, IConnection.HeaderValue | undefined>,
|
|
20
20
|
) => any;
|
|
21
21
|
}
|
|
@@ -27,7 +27,7 @@ export namespace FetcherBase {
|
|
|
27
27
|
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">,
|
|
28
28
|
input?: Input,
|
|
29
29
|
stringify?: (input: Input) => string,
|
|
30
|
-
): Promise<
|
|
30
|
+
): Promise<Output> => {
|
|
31
31
|
const result = await _Propagate("fetch")(props)(
|
|
32
32
|
connection,
|
|
33
33
|
route,
|
|
@@ -42,7 +42,7 @@ export namespace FetcherBase {
|
|
|
42
42
|
result.headers,
|
|
43
43
|
result.data as string,
|
|
44
44
|
);
|
|
45
|
-
return result.data as
|
|
45
|
+
return result.data as Output;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export const propagate =
|
|
@@ -63,7 +63,9 @@ export namespace FetcherBase {
|
|
|
63
63
|
(props: IProps) =>
|
|
64
64
|
async <Input>(
|
|
65
65
|
connection: IConnection,
|
|
66
|
-
|
|
66
|
+
metadata: IFetchRoute<
|
|
67
|
+
"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"
|
|
68
|
+
>,
|
|
67
69
|
input?: Input,
|
|
68
70
|
stringify?: (input: Input) => string,
|
|
69
71
|
): Promise<IPropagation<any, any>> => {
|
|
@@ -74,18 +76,18 @@ export namespace FetcherBase {
|
|
|
74
76
|
const headers: Record<string, IConnection.HeaderValue | undefined> = {
|
|
75
77
|
...(connection.headers ?? {}),
|
|
76
78
|
};
|
|
77
|
-
if (input !== undefined)
|
|
78
|
-
if (
|
|
79
|
+
if (input !== undefined)
|
|
80
|
+
if (metadata.request?.type === undefined)
|
|
79
81
|
throw new Error(
|
|
80
82
|
`Error on ${props.className}.fetch(): no content-type being configured.`,
|
|
81
83
|
);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
else if (metadata.request.type !== "multipart/form-data")
|
|
85
|
+
headers["Content-Type"] = metadata.request.type;
|
|
84
86
|
|
|
85
87
|
// INIT REQUEST DATA
|
|
86
88
|
const init: RequestInit = {
|
|
87
89
|
...(connection.options ?? {}),
|
|
88
|
-
method:
|
|
90
|
+
method: metadata.method,
|
|
89
91
|
headers: (() => {
|
|
90
92
|
const output: [string, string][] = [];
|
|
91
93
|
for (const [key, value] of Object.entries(headers))
|
|
@@ -101,12 +103,13 @@ export namespace FetcherBase {
|
|
|
101
103
|
if (input !== undefined)
|
|
102
104
|
init.body = props.encode(
|
|
103
105
|
// BODY TRANSFORM
|
|
104
|
-
|
|
106
|
+
metadata.request?.type === "application/x-www-form-urlencoded"
|
|
105
107
|
? request_query_body(input)
|
|
106
|
-
:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
: metadata.request?.type === "multipart/form-data"
|
|
109
|
+
? request_form_data_body(input as any)
|
|
110
|
+
: metadata.request?.type !== "text/plain"
|
|
111
|
+
? (stringify ?? JSON.stringify)(input)
|
|
112
|
+
: input,
|
|
110
113
|
headers,
|
|
111
114
|
);
|
|
112
115
|
|
|
@@ -116,59 +119,81 @@ export namespace FetcherBase {
|
|
|
116
119
|
// URL SPECIFICATION
|
|
117
120
|
const path: string =
|
|
118
121
|
connection.host[connection.host.length - 1] !== "/" &&
|
|
119
|
-
|
|
120
|
-
? `/${
|
|
121
|
-
:
|
|
122
|
+
metadata.path[0] !== "/"
|
|
123
|
+
? `/${metadata.path}`
|
|
124
|
+
: metadata.path;
|
|
122
125
|
const url: URL = new URL(`${connection.host}${path}`);
|
|
123
126
|
|
|
124
127
|
// DO FETCH
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
const event: IFetchEvent = {
|
|
129
|
+
route: metadata,
|
|
130
|
+
path,
|
|
131
|
+
status: null,
|
|
132
|
+
input,
|
|
133
|
+
output: undefined,
|
|
134
|
+
started_at: new Date(),
|
|
135
|
+
respond_at: null,
|
|
136
|
+
completed_at: null!,
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
// TRY FETCH
|
|
140
|
+
const response: Response = await (
|
|
141
|
+
connection.fetch ?? (await polyfill.get())
|
|
142
|
+
)(url.href, init);
|
|
143
|
+
event.respond_at = new Date();
|
|
144
|
+
event.status = response.status;
|
|
128
145
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
// CONSTRUCT RESULT DATA
|
|
147
|
+
const result: IPropagation<any, any> = {
|
|
148
|
+
success:
|
|
149
|
+
response.status === 200 ||
|
|
150
|
+
response.status === 201 ||
|
|
151
|
+
response.status == metadata.status,
|
|
152
|
+
status: response.status,
|
|
153
|
+
headers: response_headers_to_object(response.headers),
|
|
154
|
+
data: undefined!,
|
|
155
|
+
} as any;
|
|
156
|
+
if ((result as any).success === false) {
|
|
157
|
+
// WHEN FAILED
|
|
158
|
+
result.data = await response.text();
|
|
159
|
+
const type = response.headers.get("content-type");
|
|
160
|
+
if (
|
|
161
|
+
method !== "fetch" &&
|
|
162
|
+
type &&
|
|
163
|
+
type.indexOf("application/json") !== -1
|
|
164
|
+
)
|
|
165
|
+
try {
|
|
166
|
+
result.data = JSON.parse(result.data);
|
|
167
|
+
} catch {}
|
|
168
|
+
} else {
|
|
169
|
+
// WHEN SUCCESS
|
|
170
|
+
if (metadata.method === "HEAD") result.data = undefined!;
|
|
171
|
+
else if (metadata.response?.type === "application/json") {
|
|
172
|
+
const text: string = await response.text();
|
|
173
|
+
result.data = text.length ? JSON.parse(text) : undefined;
|
|
174
|
+
} else if (
|
|
175
|
+
metadata.response?.type === "application/x-www-form-urlencoded"
|
|
176
|
+
) {
|
|
177
|
+
const query: URLSearchParams = new URLSearchParams(
|
|
178
|
+
await response.text(),
|
|
179
|
+
);
|
|
180
|
+
result.data = metadata.parseQuery
|
|
181
|
+
? metadata.parseQuery(query)
|
|
182
|
+
: query;
|
|
183
|
+
} else
|
|
184
|
+
result.data = props.decode(await response.text(), result.headers);
|
|
185
|
+
}
|
|
186
|
+
event.output = result.data;
|
|
187
|
+
return result;
|
|
188
|
+
} catch (exp) {
|
|
189
|
+
throw exp;
|
|
190
|
+
} finally {
|
|
191
|
+
event.completed_at = new Date();
|
|
192
|
+
if (connection.logger)
|
|
148
193
|
try {
|
|
149
|
-
|
|
194
|
+
await connection.logger(event);
|
|
150
195
|
} catch {}
|
|
151
|
-
} else {
|
|
152
|
-
// WHEN SUCCESS
|
|
153
|
-
if (route.method === "HEAD") result.data = undefined!;
|
|
154
|
-
else if (route.response?.type === "application/json") {
|
|
155
|
-
const text: string = await response.text();
|
|
156
|
-
result.data = text.length ? JSON.parse(text) : undefined;
|
|
157
|
-
} else if (
|
|
158
|
-
route.response?.type === "application/x-www-form-urlencoded"
|
|
159
|
-
) {
|
|
160
|
-
const query: URLSearchParams = new URLSearchParams(
|
|
161
|
-
await response.text(),
|
|
162
|
-
);
|
|
163
|
-
result.data = route.parseQuery ? route.parseQuery(query) : query;
|
|
164
|
-
} else if (route.response?.type === "application/octet-stream")
|
|
165
|
-
result.data = props.decode(
|
|
166
|
-
new Uint8Array(await response.arrayBuffer()),
|
|
167
|
-
result.headers,
|
|
168
|
-
);
|
|
169
|
-
else result.data = await response.text();
|
|
170
196
|
}
|
|
171
|
-
return result;
|
|
172
197
|
};
|
|
173
198
|
}
|
|
174
199
|
|
|
@@ -176,18 +201,27 @@ export namespace FetcherBase {
|
|
|
176
201
|
* @internal
|
|
177
202
|
*/
|
|
178
203
|
const polyfill = new Singleton(async (): Promise<typeof fetch> => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
204
|
+
function is_node_process(m: typeof global | null): boolean {
|
|
205
|
+
return (
|
|
206
|
+
m !== null &&
|
|
207
|
+
typeof m.process === "object" &&
|
|
208
|
+
m.process !== null &&
|
|
209
|
+
typeof m.process.versions === "object" &&
|
|
210
|
+
m.process.versions !== null &&
|
|
211
|
+
typeof m.process.versions.node !== "undefined"
|
|
212
|
+
);
|
|
187
213
|
}
|
|
188
|
-
|
|
214
|
+
if (typeof global === "object" && is_node_process(global)) {
|
|
215
|
+
const m: any = global as any;
|
|
216
|
+
m.fetch ??= ((await import2("node-fetch")) as any).default;
|
|
217
|
+
return (m as any).fetch;
|
|
218
|
+
}
|
|
219
|
+
return self.fetch;
|
|
189
220
|
});
|
|
190
221
|
|
|
222
|
+
/**
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
191
225
|
const request_query_body = (input: any): URLSearchParams => {
|
|
192
226
|
const q: URLSearchParams = new URLSearchParams();
|
|
193
227
|
for (const [key, value] of Object.entries(input))
|
|
@@ -198,6 +232,24 @@ const request_query_body = (input: any): URLSearchParams => {
|
|
|
198
232
|
return q;
|
|
199
233
|
};
|
|
200
234
|
|
|
235
|
+
/**
|
|
236
|
+
* @internal
|
|
237
|
+
*/
|
|
238
|
+
const request_form_data_body = (input: Record<string, any>): FormData => {
|
|
239
|
+
const encoded: FormData = new FormData();
|
|
240
|
+
const append = (key: string) => (value: any) => {
|
|
241
|
+
if (value === undefined) return;
|
|
242
|
+
else if (value instanceof Blob)
|
|
243
|
+
if (value instanceof File) encoded.append(key, value, value.name);
|
|
244
|
+
else encoded.append(key, value);
|
|
245
|
+
else encoded.append(key, String(value));
|
|
246
|
+
};
|
|
247
|
+
for (const [key, value] of Object.entries(input))
|
|
248
|
+
if (Array.isArray(value)) value.map(append(key));
|
|
249
|
+
else append(key)(value);
|
|
250
|
+
return encoded;
|
|
251
|
+
};
|
|
252
|
+
|
|
201
253
|
/**
|
|
202
254
|
* @internal
|
|
203
255
|
*/
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
|
-
export class Singleton<T> {
|
|
5
|
-
private value_: T | object;
|
|
6
|
-
|
|
7
|
-
public constructor(private readonly closure_: () => T) {
|
|
8
|
-
this.value_ = NOT_MOUNTED_YET;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public get(): T {
|
|
12
|
-
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
|
|
13
|
-
return this.value_ as T;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
const NOT_MOUNTED_YET = {};
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export class Singleton<T> {
|
|
5
|
+
private value_: T | object;
|
|
6
|
+
|
|
7
|
+
public constructor(private readonly closure_: () => T) {
|
|
8
|
+
this.value_ = NOT_MOUNTED_YET;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get(): T {
|
|
12
|
+
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
|
|
13
|
+
return this.value_ as T;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
const NOT_MOUNTED_YET = {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AesPkcs5.js","sourceRoot":"","sources":["../../src/internal/AesPkcs5.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA4B;AAE5B;;;;;;;;;GASG;AACH,IAAiB,QAAQ,CAqDxB;AArDD,WAAiB,QAAQ;IACvB;;;;;;;OAOG;IACU,gBAAO,GAAG,UACrB,IAAyB,EACzB,GAAW,EACX,EAAU;QAEV,IAAM,KAAK,GAAW,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAM,MAAM,GAAkB,gBAAM,CAAC,cAAc,CACjD,cAAO,KAAK,SAAM,EAClB,GAAG,EACH,EAAE,CACH,CAAC;QACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC;IAEF;;;;;;;OAOG;IACU,gBAAO,GAAG,UACrB,IAAgB,EAChB,GAAW,EACX,EAAU;QAEV,IAAM,KAAK,GAAW,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAM,QAAQ,GAAoB,gBAAM,CAAC,gBAAgB,CACvD,cAAO,KAAK,SAAM,EAClB,GAAG,EACH,EAAE,CACH,CAAC;QACF,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC;IAEF;;OAEG;IACH,IAAM,MAAM,GAAG,UAAC,CAAS,EAAE,CAAS;QAClC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC,EArDgB,QAAQ,wBAAR,QAAQ,QAqDxB"}
|
|
File without changes
|