@defjs/core 0.0.0-test-0006 → 0.0.0-test-0008
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/dist/index.d.ts +10 -4
- package/dist/index.js +45 -25
- package/package.json +23 -23
package/dist/index.d.ts
CHANGED
|
@@ -69,11 +69,17 @@ export declare function makeResponse<R>(options: MakeResponseOptions<R>): HttpRe
|
|
|
69
69
|
export type InterceptorFn = (req: HttpRequest, next: HttpHandler) => Promise<HttpResponse<unknown>>;
|
|
70
70
|
export type HttpResponseType = "arraybuffer" | "blob" | "json" | "text";
|
|
71
71
|
export interface HttpProgressEvent {
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Indicates whether the resources associated with Progress have a computable length.
|
|
74
|
+
* Otherwise, the Progress.total attribute will be a meaningless value.
|
|
75
|
+
*/
|
|
73
76
|
readonly lengthComputable: boolean;
|
|
74
|
-
/**
|
|
77
|
+
/** Indicates the workload of the underlying process. */
|
|
75
78
|
readonly loaded: number;
|
|
76
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* The total size of the data being processed or transmitted.
|
|
81
|
+
* If the Progress.lengthComputable attribute is false, this value is meaningless and should be ignored.
|
|
82
|
+
*/
|
|
77
83
|
readonly total: number;
|
|
78
84
|
}
|
|
79
85
|
export type HttpProgressFn = (value: HttpProgressEvent) => void;
|
|
@@ -242,7 +248,7 @@ export type RequestRefWithInput<T> = T extends RequestRef<unknown, infer Input>
|
|
|
242
248
|
export declare function doRequest<Ref extends RequestRef>(ref: RequestRefWithInput<Ref> extends true ? never : Ref, options?: DoRequestOptions): Promise<RequestRefOutput<Ref>>;
|
|
243
249
|
export declare function doRequest<Ref extends RequestRef>(ref: RequestRefWithInput<Ref> extends true ? Ref : never, input: RequestRefInput<Ref>, options?: DoRequestOptions): Promise<RequestRefOutput<Ref>>;
|
|
244
250
|
export type HttpHandler = (req: HttpRequest) => Promise<HttpResponse<unknown>>;
|
|
245
|
-
export declare
|
|
251
|
+
export declare function fetchHandler(httpRequest: HttpRequest): Promise<HttpResponse<unknown>>;
|
|
246
252
|
export interface ClientOptions {
|
|
247
253
|
host: string;
|
|
248
254
|
interceptors?: InterceptorFn[];
|
package/dist/index.js
CHANGED
|
@@ -176,10 +176,30 @@ async function fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
176
176
|
function inputIsObject(input2) {
|
|
177
177
|
return typeof input2 === "object" && input2 !== null;
|
|
178
178
|
}
|
|
179
|
+
function appendValue(sp, key, value) {
|
|
180
|
+
if (Array.isArray(value)) {
|
|
181
|
+
for (const v of value) {
|
|
182
|
+
sp.append(key, String(v));
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
sp.set(key, String(value));
|
|
186
|
+
}
|
|
187
|
+
return sp;
|
|
188
|
+
}
|
|
189
|
+
function setValue(sp, key, value) {
|
|
190
|
+
if (Array.isArray(value)) {
|
|
191
|
+
for (const v of value) {
|
|
192
|
+
sp.set(key, String(v));
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
sp.set(key, String(value));
|
|
196
|
+
}
|
|
197
|
+
return sp;
|
|
198
|
+
}
|
|
179
199
|
if (isField(fieldOrFieldGroup)) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
let params;
|
|
201
|
+
let queryParams;
|
|
202
|
+
let headers;
|
|
183
203
|
let body = undefined;
|
|
184
204
|
const fieldValue = input ?? fieldOrFieldGroup();
|
|
185
205
|
const meta = getFieldMetadata(fieldOrFieldGroup);
|
|
@@ -196,30 +216,28 @@ async function fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
196
216
|
if (!aliasName) {
|
|
197
217
|
throwAliaNotSet();
|
|
198
218
|
}
|
|
199
|
-
queryParams
|
|
219
|
+
queryParams = appendValue(new URLSearchParams, aliasName, fieldValue);
|
|
200
220
|
break;
|
|
201
221
|
}
|
|
202
222
|
case 3 /* Param */: {
|
|
203
223
|
if (!aliasName) {
|
|
204
224
|
throwAliaNotSet();
|
|
205
225
|
}
|
|
206
|
-
params
|
|
226
|
+
params = setValue(new Map, aliasName, fieldValue);
|
|
207
227
|
break;
|
|
208
228
|
}
|
|
209
229
|
case 4 /* Header */: {
|
|
210
230
|
if (!aliasName) {
|
|
211
231
|
throwAliaNotSet();
|
|
212
232
|
}
|
|
213
|
-
headers
|
|
233
|
+
headers = appendValue(new Headers, aliasName, fieldValue);
|
|
214
234
|
break;
|
|
215
235
|
}
|
|
216
236
|
case 5 /* Form */: {
|
|
217
237
|
if (!aliasName) {
|
|
218
238
|
throwAliaNotSet();
|
|
219
239
|
}
|
|
220
|
-
|
|
221
|
-
form.append(aliasName, String(fieldValue));
|
|
222
|
-
body = form;
|
|
240
|
+
body = appendValue(new FormData, aliasName, fieldValue);
|
|
223
241
|
break;
|
|
224
242
|
}
|
|
225
243
|
case 6 /* Body */:
|
|
@@ -227,17 +245,19 @@ async function fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
227
245
|
break;
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
|
-
|
|
248
|
+
if (params) {
|
|
249
|
+
request.endpoint = fillUrl(request.endpoint, params);
|
|
250
|
+
}
|
|
231
251
|
request.queryParams = queryParams;
|
|
232
252
|
request.headers = headers;
|
|
233
253
|
request.body = body;
|
|
234
254
|
return;
|
|
235
255
|
}
|
|
236
256
|
if (isFieldGroup(fieldOrFieldGroup) && inputIsObject(input)) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
257
|
+
let params = new Map;
|
|
258
|
+
let queryParams = new URLSearchParams;
|
|
259
|
+
let headers = new Headers;
|
|
260
|
+
let formData = new FormData;
|
|
241
261
|
const json = {};
|
|
242
262
|
let body = undefined;
|
|
243
263
|
for (const [propertyKey, field3] of Object.entries(fieldOrFieldGroup)) {
|
|
@@ -253,20 +273,21 @@ async function fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
253
273
|
case 1 /* Json */:
|
|
254
274
|
Object.defineProperty(json, valueKey, {
|
|
255
275
|
value,
|
|
256
|
-
writable: true
|
|
276
|
+
writable: true,
|
|
277
|
+
enumerable: true
|
|
257
278
|
});
|
|
258
279
|
break;
|
|
259
280
|
case 2 /* Query */:
|
|
260
|
-
queryParams
|
|
281
|
+
queryParams = appendValue(queryParams, valueKey, value);
|
|
261
282
|
break;
|
|
262
283
|
case 3 /* Param */:
|
|
263
|
-
params
|
|
284
|
+
params = setValue(params, valueKey, value);
|
|
264
285
|
break;
|
|
265
286
|
case 4 /* Header */:
|
|
266
|
-
headers
|
|
287
|
+
headers = appendValue(headers, valueKey, value);
|
|
267
288
|
break;
|
|
268
289
|
case 5 /* Form */:
|
|
269
|
-
formData
|
|
290
|
+
formData = appendValue(formData, valueKey, value);
|
|
270
291
|
break;
|
|
271
292
|
case 6 /* Body */:
|
|
272
293
|
body = value;
|
|
@@ -324,7 +345,7 @@ async function doRequest(...args) {
|
|
|
324
345
|
}
|
|
325
346
|
const clientOptions = getClientConfig(options?.client || getGlobalClient());
|
|
326
347
|
const req = {
|
|
327
|
-
host: clientOptions?.host
|
|
348
|
+
host: clientOptions?.host,
|
|
328
349
|
method: requestOptions.method,
|
|
329
350
|
endpoint: requestOptions.endpoint,
|
|
330
351
|
queryParams: new URLSearchParams,
|
|
@@ -475,15 +496,15 @@ function getContentLength(headers) {
|
|
|
475
496
|
}
|
|
476
497
|
return num;
|
|
477
498
|
}
|
|
478
|
-
async function
|
|
499
|
+
async function fetchHandler(httpRequest) {
|
|
500
|
+
const { downloadProgress } = httpRequest;
|
|
479
501
|
const request2 = createRequest(httpRequest);
|
|
480
|
-
const downloadProgress = httpRequest.downloadProgress;
|
|
481
502
|
let response2;
|
|
482
503
|
try {
|
|
483
504
|
response2 = await (globalThis || window).fetch(request2);
|
|
484
505
|
} catch (error) {
|
|
485
506
|
throw makeResponse({
|
|
486
|
-
error: error instanceof Error ? error : new Error("
|
|
507
|
+
error: error instanceof Error ? error : new Error("Network Error"),
|
|
487
508
|
url: request2.url
|
|
488
509
|
});
|
|
489
510
|
}
|
|
@@ -511,7 +532,7 @@ async function _request(httpRequest) {
|
|
|
511
532
|
body = parseBody(httpRequest, response2, chunksAll);
|
|
512
533
|
} catch (error) {
|
|
513
534
|
throw makeResponse({
|
|
514
|
-
error: error instanceof Error ? error : new Error("
|
|
535
|
+
error: error instanceof Error ? error : new Error("Parse response body error"),
|
|
515
536
|
url,
|
|
516
537
|
status,
|
|
517
538
|
statusText,
|
|
@@ -529,7 +550,6 @@ async function _request(httpRequest) {
|
|
|
529
550
|
});
|
|
530
551
|
}
|
|
531
552
|
var FETCH_CONFIG_KEY = makeHttpContextToken(() => ({}));
|
|
532
|
-
var fetchHandler = _request;
|
|
533
553
|
// src/client.ts
|
|
534
554
|
function isClient(value) {
|
|
535
555
|
return typeof value === "object" && value !== null && CLIENT in value;
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"name": "@defjs/core",
|
|
3
|
+
"version": "0.0.0-test-0008",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "bun run ./scripts/build.ts",
|
|
7
|
+
"test": "bun test",
|
|
8
|
+
"lint": "biome check",
|
|
9
|
+
"lint:fix": "biome check --write",
|
|
10
|
+
"pub": "npm publish"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"typescript": "^5.0"
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"module": "dist/index.js",
|
|
17
|
+
"typings": "dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"default": "./index.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
25
|
}
|