@gershy/util-http 0.0.14 → 0.0.15

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 CHANGED
@@ -22,11 +22,13 @@ export type HttpRes = {
22
22
  body: Json | Uint8Array;
23
23
  };
24
24
  export type HttpArgs<Req extends HttpReq, Res extends HttpRes> = {} & {
25
+ fetch?: typeof fetch;
26
+ } & {
25
27
  $req: Req;
26
28
  $res: Res;
27
29
  } & {
28
30
  netProc: NetProc;
29
- } & Omit<Req, 'cookies'> & {
31
+ } & Omit<Req, 'cookies' | 'query' | 'body'> & {
30
32
  headers?: Obj<string>;
31
33
  };
32
34
  export type HttpResult<Res extends HttpRes> = {
@@ -42,7 +44,7 @@ export type HttpResult<Res extends HttpRes> = {
42
44
  export type HttpRet<Res extends HttpRes> = Promise<HttpResult<Res>> & {
43
45
  end: () => void;
44
46
  };
45
- declare const _default: <Args extends HttpArgs<HttpReq, HttpRes>>(args: Args, params: Pick<Args, "query" | "body">) => Promise<{
47
+ declare const _default: <Req extends HttpReq, Res extends HttpRes>(args: HttpArgs<Req, Res>, params: Pick<Req, "query" | "body">) => Promise<{
46
48
  reqArgs: ({
47
49
  method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "SOKT";
48
50
  headers: [string, string][];
@@ -50,8 +52,8 @@ declare const _default: <Args extends HttpArgs<HttpReq, HttpRes>>(args: Args, pa
50
52
  } & {
51
53
  url: string;
52
54
  });
53
- code: any;
54
- body: Args["$res"]["body"];
55
+ code: number;
56
+ body: Res["body"];
55
57
  }> & {
56
58
  end: () => void;
57
59
  };
package/cmp/cjs/main.js CHANGED
@@ -23,6 +23,7 @@ __export(main_exports, {
23
23
  module.exports = __toCommonJS(main_exports);
24
24
  var import_clearing = require("@gershy/clearing");
25
25
  var main_default = (args, params) => {
26
+ const { fetch: fetcher = fetch } = args;
26
27
  const { netProc, path, headers = {} } = args;
27
28
  const { query = {}, body: reqBody = null } = params;
28
29
  const defPorts = { http: 80, https: 443 };
@@ -39,7 +40,8 @@ var main_default = (args, params) => {
39
40
  if (!cl.isCls(val, Object)) return yield { chain, val };
40
41
  for (const [k, v] of val[cl.walk]()) yield* chains(v, [...chain, k]);
41
42
  };
42
- return [...chains(query)][cl.map](({ chain, val }) => `${encodeURIComponent(chain.join("."))}=${encodeURIComponent(val)}`).join("&");
43
+ const pcs = [...chains(query)];
44
+ return pcs.length > 0 ? "?" + pcs[cl.map](({ chain, val }) => `${encodeURIComponent(chain.join("."))}=${encodeURIComponent(val)}`).join("&") : "";
43
45
  })()
44
46
  ].filter(Boolean).join("");
45
47
  const reqArgs = {
@@ -50,7 +52,7 @@ var main_default = (args, params) => {
50
52
  };
51
53
  const err = new Error("");
52
54
  const abort = new AbortController();
53
- const prm = fetch(url, { ...reqArgs, signal: abort.signal }).then(
55
+ const prm = fetcher(url, { ...reqArgs, signal: abort.signal }).then(
54
56
  async (res) => {
55
57
  const resBody = await (async () => {
56
58
  const t = new Uint8Array(await res.arrayBuffer());
@@ -71,8 +73,8 @@ var main_default = (args, params) => {
71
73
  },
72
74
  (cause) => {
73
75
  while (cl.isCls(cause.cause, Error)) cause = cause.cause;
74
- if (cause.code === "ENOTFOUND") return err[cl.fire]({ cause, retry: false });
75
- return err[cl.fire]({ cause });
76
+ if (cause.code === "ENOTFOUND") return err[cl.fire]({ cause, reqArgs, retry: false });
77
+ return err[cl.fire]({ cause, reqArgs });
76
78
  }
77
79
  );
78
80
  return Object.assign(prm, { end: () => abort.abort(Error("fetch aborted")[cl.suppress]()) });
package/cmp/esm/main.d.ts CHANGED
@@ -22,11 +22,13 @@ export type HttpRes = {
22
22
  body: Json | Uint8Array;
23
23
  };
24
24
  export type HttpArgs<Req extends HttpReq, Res extends HttpRes> = {} & {
25
+ fetch?: typeof fetch;
26
+ } & {
25
27
  $req: Req;
26
28
  $res: Res;
27
29
  } & {
28
30
  netProc: NetProc;
29
- } & Omit<Req, 'cookies'> & {
31
+ } & Omit<Req, 'cookies' | 'query' | 'body'> & {
30
32
  headers?: Obj<string>;
31
33
  };
32
34
  export type HttpResult<Res extends HttpRes> = {
@@ -42,7 +44,7 @@ export type HttpResult<Res extends HttpRes> = {
42
44
  export type HttpRet<Res extends HttpRes> = Promise<HttpResult<Res>> & {
43
45
  end: () => void;
44
46
  };
45
- declare const _default: <Args extends HttpArgs<HttpReq, HttpRes>>(args: Args, params: Pick<Args, "query" | "body">) => Promise<{
47
+ declare const _default: <Req extends HttpReq, Res extends HttpRes>(args: HttpArgs<Req, Res>, params: Pick<Req, "query" | "body">) => Promise<{
46
48
  reqArgs: ({
47
49
  method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "SOKT";
48
50
  headers: [string, string][];
@@ -50,8 +52,8 @@ declare const _default: <Args extends HttpArgs<HttpReq, HttpRes>>(args: Args, pa
50
52
  } & {
51
53
  url: string;
52
54
  });
53
- code: any;
54
- body: Args["$res"]["body"];
55
+ code: number;
56
+ body: Res["body"];
55
57
  }> & {
56
58
  end: () => void;
57
59
  };
package/cmp/esm/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import "@gershy/clearing";
2
2
  var main_default = (args, params) => {
3
+ const { fetch: fetcher = fetch } = args;
3
4
  const { netProc, path, headers = {} } = args;
4
5
  const { query = {}, body: reqBody = null } = params;
5
6
  const defPorts = { http: 80, https: 443 };
@@ -16,7 +17,8 @@ var main_default = (args, params) => {
16
17
  if (!cl.isCls(val, Object)) return yield { chain, val };
17
18
  for (const [k, v] of val[cl.walk]()) yield* chains(v, [...chain, k]);
18
19
  };
19
- return [...chains(query)][cl.map](({ chain, val }) => `${encodeURIComponent(chain.join("."))}=${encodeURIComponent(val)}`).join("&");
20
+ const pcs = [...chains(query)];
21
+ return pcs.length > 0 ? "?" + pcs[cl.map](({ chain, val }) => `${encodeURIComponent(chain.join("."))}=${encodeURIComponent(val)}`).join("&") : "";
20
22
  })()
21
23
  ].filter(Boolean).join("");
22
24
  const reqArgs = {
@@ -27,7 +29,7 @@ var main_default = (args, params) => {
27
29
  };
28
30
  const err = new Error("");
29
31
  const abort = new AbortController();
30
- const prm = fetch(url, { ...reqArgs, signal: abort.signal }).then(
32
+ const prm = fetcher(url, { ...reqArgs, signal: abort.signal }).then(
31
33
  async (res) => {
32
34
  const resBody = await (async () => {
33
35
  const t = new Uint8Array(await res.arrayBuffer());
@@ -48,8 +50,8 @@ var main_default = (args, params) => {
48
50
  },
49
51
  (cause) => {
50
52
  while (cl.isCls(cause.cause, Error)) cause = cause.cause;
51
- if (cause.code === "ENOTFOUND") return err[cl.fire]({ cause, retry: false });
52
- return err[cl.fire]({ cause });
53
+ if (cause.code === "ENOTFOUND") return err[cl.fire]({ cause, reqArgs, retry: false });
54
+ return err[cl.fire]({ cause, reqArgs });
53
55
  }
54
56
  );
55
57
  return Object.assign(prm, { end: () => abort.abort(Error("fetch aborted")[cl.suppress]()) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gershy/util-http",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
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.46"
23
+ "@gershy/clearing": "^0.0.47"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^24.10.1"