@gershy/util-http 0.0.16 → 0.0.18
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/cmp/cjs/main.d.ts +11 -37
- package/cmp/cjs/main.js +5 -5
- package/cmp/esm/main.d.ts +11 -37
- package/cmp/esm/main.js +5 -5
- package/package.json +2 -2
package/cmp/cjs/main.d.ts
CHANGED
|
@@ -5,55 +5,29 @@ export type NetProc = {
|
|
|
5
5
|
port: number;
|
|
6
6
|
};
|
|
7
7
|
type Built<T> = T | {
|
|
8
|
-
[
|
|
8
|
+
[K: string]: Built<T>;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
method: 'head' | 'get' | 'post' | 'put' | 'patch' | 'delete' | 'sokt';
|
|
13
|
-
cookies: Obj<Built<string>>;
|
|
14
|
-
query?: Obj<Built<string>>;
|
|
15
|
-
body?: Json;
|
|
16
|
-
};
|
|
17
|
-
export type HttpRes = {
|
|
18
|
-
code: number;
|
|
19
|
-
headers?: {
|
|
20
|
-
[key: string]: string | string[];
|
|
21
|
-
};
|
|
22
|
-
body: Json | Uint8Array;
|
|
23
|
-
};
|
|
24
|
-
export type HttpArgs<Req extends HttpReq, Res extends HttpRes> = {} & {
|
|
10
|
+
export type HttpMethod = 'head' | 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
11
|
+
export type HttpInp = {
|
|
25
12
|
fetch?: typeof fetch;
|
|
26
|
-
} & {
|
|
27
|
-
$req: Req;
|
|
28
|
-
$res: Res;
|
|
29
|
-
} & {
|
|
30
13
|
netProc: NetProc;
|
|
31
|
-
|
|
14
|
+
path: string[];
|
|
15
|
+
method: HttpMethod;
|
|
32
16
|
headers?: Obj<string>;
|
|
17
|
+
cookies?: Obj<Built<string>>;
|
|
18
|
+
query?: Obj<Built<string>>;
|
|
19
|
+
body?: Json;
|
|
33
20
|
};
|
|
34
|
-
|
|
35
|
-
reqArgs: {
|
|
36
|
-
url: string;
|
|
37
|
-
method: string;
|
|
38
|
-
headers: [string, string][];
|
|
39
|
-
body: string | null;
|
|
40
|
-
};
|
|
41
|
-
code: number;
|
|
42
|
-
body: Res['body'];
|
|
43
|
-
};
|
|
44
|
-
export type HttpRet<Res extends HttpRes> = Promise<HttpResult<Res>> & {
|
|
45
|
-
end: () => void;
|
|
46
|
-
};
|
|
47
|
-
declare const _default: <Req extends HttpReq, Res extends HttpRes>(args: HttpArgs<Req, Res>, params: Pick<Req, "query" | "body">) => Promise<{
|
|
21
|
+
declare const _default: <ResBody>(inp: HttpInp) => Promise<{
|
|
48
22
|
reqArgs: ({
|
|
49
|
-
method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE"
|
|
23
|
+
method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
50
24
|
headers: [string, string][];
|
|
51
25
|
body: string | null;
|
|
52
26
|
} & {
|
|
53
27
|
url: string;
|
|
54
28
|
});
|
|
55
29
|
code: number;
|
|
56
|
-
body:
|
|
30
|
+
body: ResBody;
|
|
57
31
|
}> & {
|
|
58
32
|
end: () => void;
|
|
59
33
|
};
|
package/cmp/cjs/main.js
CHANGED
|
@@ -22,10 +22,10 @@ __export(main_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(main_exports);
|
|
24
24
|
var import_clearing = require("@gershy/clearing");
|
|
25
|
-
var main_default = (
|
|
26
|
-
const { fetch: fetcher = fetch } =
|
|
27
|
-
const { netProc, path, headers = {} } =
|
|
28
|
-
const { query = {}, body: reqBody = null } =
|
|
25
|
+
var main_default = (inp) => {
|
|
26
|
+
const { fetch: fetcher = fetch } = inp;
|
|
27
|
+
const { netProc, path, headers = {} } = inp;
|
|
28
|
+
const { query = {}, body: reqBody = null } = inp;
|
|
29
29
|
const defPorts = { http: 80, https: 443 };
|
|
30
30
|
const url = [
|
|
31
31
|
// E.g. "http://pasta.com"
|
|
@@ -45,7 +45,7 @@ var main_default = (args, params) => {
|
|
|
45
45
|
})()
|
|
46
46
|
].filter(Boolean).join("");
|
|
47
47
|
const reqArgs = {
|
|
48
|
-
method:
|
|
48
|
+
method: inp.method[cl.upper](),
|
|
49
49
|
headers: headers[cl.toArr]((v, k) => [k.replace(/([A-Z])/g, "-$1")[cl.lower](), v]),
|
|
50
50
|
// Avoid `camelCase` util - want to keep this sovereign
|
|
51
51
|
body: [Object, Array].some((C) => cl.isCls(reqBody, C)) ? JSON.stringify(reqBody) : reqBody !== null ? `${reqBody}` : null
|
package/cmp/esm/main.d.ts
CHANGED
|
@@ -5,55 +5,29 @@ export type NetProc = {
|
|
|
5
5
|
port: number;
|
|
6
6
|
};
|
|
7
7
|
type Built<T> = T | {
|
|
8
|
-
[
|
|
8
|
+
[K: string]: Built<T>;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
method: 'head' | 'get' | 'post' | 'put' | 'patch' | 'delete' | 'sokt';
|
|
13
|
-
cookies: Obj<Built<string>>;
|
|
14
|
-
query?: Obj<Built<string>>;
|
|
15
|
-
body?: Json;
|
|
16
|
-
};
|
|
17
|
-
export type HttpRes = {
|
|
18
|
-
code: number;
|
|
19
|
-
headers?: {
|
|
20
|
-
[key: string]: string | string[];
|
|
21
|
-
};
|
|
22
|
-
body: Json | Uint8Array;
|
|
23
|
-
};
|
|
24
|
-
export type HttpArgs<Req extends HttpReq, Res extends HttpRes> = {} & {
|
|
10
|
+
export type HttpMethod = 'head' | 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
11
|
+
export type HttpInp = {
|
|
25
12
|
fetch?: typeof fetch;
|
|
26
|
-
} & {
|
|
27
|
-
$req: Req;
|
|
28
|
-
$res: Res;
|
|
29
|
-
} & {
|
|
30
13
|
netProc: NetProc;
|
|
31
|
-
|
|
14
|
+
path: string[];
|
|
15
|
+
method: HttpMethod;
|
|
32
16
|
headers?: Obj<string>;
|
|
17
|
+
cookies?: Obj<Built<string>>;
|
|
18
|
+
query?: Obj<Built<string>>;
|
|
19
|
+
body?: Json;
|
|
33
20
|
};
|
|
34
|
-
|
|
35
|
-
reqArgs: {
|
|
36
|
-
url: string;
|
|
37
|
-
method: string;
|
|
38
|
-
headers: [string, string][];
|
|
39
|
-
body: string | null;
|
|
40
|
-
};
|
|
41
|
-
code: number;
|
|
42
|
-
body: Res['body'];
|
|
43
|
-
};
|
|
44
|
-
export type HttpRet<Res extends HttpRes> = Promise<HttpResult<Res>> & {
|
|
45
|
-
end: () => void;
|
|
46
|
-
};
|
|
47
|
-
declare const _default: <Req extends HttpReq, Res extends HttpRes>(args: HttpArgs<Req, Res>, params: Pick<Req, "query" | "body">) => Promise<{
|
|
21
|
+
declare const _default: <ResBody>(inp: HttpInp) => Promise<{
|
|
48
22
|
reqArgs: ({
|
|
49
|
-
method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE"
|
|
23
|
+
method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
50
24
|
headers: [string, string][];
|
|
51
25
|
body: string | null;
|
|
52
26
|
} & {
|
|
53
27
|
url: string;
|
|
54
28
|
});
|
|
55
29
|
code: number;
|
|
56
|
-
body:
|
|
30
|
+
body: ResBody;
|
|
57
31
|
}> & {
|
|
58
32
|
end: () => void;
|
|
59
33
|
};
|
package/cmp/esm/main.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@gershy/clearing";
|
|
2
|
-
var main_default = (
|
|
3
|
-
const { fetch: fetcher = fetch } =
|
|
4
|
-
const { netProc, path, headers = {} } =
|
|
5
|
-
const { query = {}, body: reqBody = null } =
|
|
2
|
+
var main_default = (inp) => {
|
|
3
|
+
const { fetch: fetcher = fetch } = inp;
|
|
4
|
+
const { netProc, path, headers = {} } = inp;
|
|
5
|
+
const { query = {}, body: reqBody = null } = inp;
|
|
6
6
|
const defPorts = { http: 80, https: 443 };
|
|
7
7
|
const url = [
|
|
8
8
|
// E.g. "http://pasta.com"
|
|
@@ -22,7 +22,7 @@ var main_default = (args, params) => {
|
|
|
22
22
|
})()
|
|
23
23
|
].filter(Boolean).join("");
|
|
24
24
|
const reqArgs = {
|
|
25
|
-
method:
|
|
25
|
+
method: inp.method[cl.upper](),
|
|
26
26
|
headers: headers[cl.toArr]((v, k) => [k.replace(/([A-Z])/g, "-$1")[cl.lower](), v]),
|
|
27
27
|
// Avoid `camelCase` util - want to keep this sovereign
|
|
28
28
|
body: [Object, Array].some((C) => cl.isCls(reqBody, C)) ? JSON.stringify(reqBody) : reqBody !== null ? `${reqBody}` : null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gershy/util-http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"author": "Gershom Maes",
|
|
5
5
|
"description": "TODO",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@gershy/clearing": "^0.0.
|
|
23
|
+
"@gershy/clearing": "^0.0.50"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^24.10.1"
|