@stryke/http 0.4.1 → 0.5.1

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.cjs CHANGED
@@ -25,6 +25,17 @@ Object.keys(_formatDataUri).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
+ var _types = require("./types.cjs");
29
+ Object.keys(_types).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _types[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _types[key];
36
+ }
37
+ });
38
+ });
28
39
  var _urlBuilder = require("./url-builder.cjs");
29
40
  Object.keys(_urlBuilder).forEach(function (key) {
30
41
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./cookie";
2
2
  export * from "./format-data-uri";
3
+ export * from "./types";
3
4
  export * from "./url-builder";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./cookie";export*from"./format-data-uri";export*from"./url-builder";
1
+ export*from"./cookie";export*from"./format-data-uri";export*from"./types";export*from"./url-builder";
package/dist/types.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { ParsedURL } from "ufo";
2
2
  export type StormURL = ParsedURL & {
3
3
  __typename: "StormURL";
4
4
  queryParams: Record<string, any>;
5
+ paths: string[];
5
6
  username?: string;
6
7
  password?: string;
7
8
  hostname?: string;
@@ -8,89 +8,91 @@ var _stormJson = require("@stryke/json/storm-json");
8
8
  var _isString = require("@stryke/type-checks/is-string");
9
9
  var _ufo = require("ufo");
10
10
  class StormURLBuilder {
11
- #r;
12
- static create(r, t) {
13
- return new StormURLBuilder(r, t);
14
- }
15
- constructor(r, t) {
16
- const s = t?.decode ?? !0,
17
- n = (0, _isString.isString)(r) ? s ? (0, _ufo.parseURL)((0, _ufo.decode)(r)) : (0, _ufo.parseURL)(r) : r;
18
- this.#r = {
11
+ #t;
12
+ static create(t, r) {
13
+ return new StormURLBuilder(t, r);
14
+ }
15
+ constructor(t, r) {
16
+ const s = r?.decode ?? !0,
17
+ i = (0, _isString.isString)(t) ? s ? (0, _ufo.parseURL)((0, _ufo.decode)(t)) : (0, _ufo.parseURL)(t) : t;
18
+ this.#t = {
19
19
  __typename: "StormURL",
20
20
  queryParams: {},
21
- ...n
22
- }, this.#r.host && this.withHost(this.#r.host), this.#r.auth && this.withAuth(this.#r.auth);
21
+ ...i,
22
+ paths: i.pathname ? i.pathname.split("/").filter(Boolean) : []
23
+ }, this.#t.host && this.withHost(this.#t.host), this.#t.auth && this.withAuth(this.#t.auth);
23
24
  }
24
25
  get _url() {
25
- return this.#r;
26
+ return this.#t;
26
27
  }
27
- withProtocol(r) {
28
- return this.#r.protocol = r, this;
28
+ withProtocol(t) {
29
+ return this.#t.protocol = t, this;
29
30
  }
30
- withHostname(r) {
31
- return this.#r.hostname = r, this;
31
+ withHostname(t) {
32
+ return this.#t.hostname = t, this;
32
33
  }
33
- withPort(r) {
34
- return this.#r.port = String(r), this;
34
+ withPort(t) {
35
+ return this.#t.port = String(t), this;
35
36
  }
36
- withUsername(r) {
37
- return this.#r.username = r, this;
37
+ withUsername(t) {
38
+ return this.#t.username = t, this;
38
39
  }
39
- withPassword(r) {
40
- return this.#r.password = r, this;
40
+ withPassword(t) {
41
+ return this.#t.password = t, this;
41
42
  }
42
- withHost(r) {
43
- if ((0, _isString.isString)(r)) {
44
- this.#r.host = r;
45
- const t = (0, _ufo.parseAuth)(r);
46
- this.#r.username = t.username, this.#r.password = t.password;
47
- } else this.#r.hostname = r.hostname, this.#r.port = r.port, this.#r.auth = `${r.hostname}${r.port ? `:${r.port}` : ""}`;
43
+ withHost(t) {
44
+ if ((0, _isString.isString)(t)) {
45
+ this.#t.host = t;
46
+ const r = (0, _ufo.parseAuth)(t);
47
+ this.#t.username = r.username, this.#t.password = r.password;
48
+ } else this.#t.hostname = t.hostname, this.#t.port = t.port, this.#t.auth = `${t.hostname}${t.port ? `:${t.port}` : ""}`;
48
49
  return this;
49
50
  }
50
- withPath(r) {
51
- const t = (0, _ufo.parsePath)(r);
52
- return this.#r = {
53
- ...this.#r,
54
- ...t
51
+ withPath(t) {
52
+ const r = (0, _ufo.parsePath)(t);
53
+ return this.#t = {
54
+ ...this.#t,
55
+ ...r,
56
+ paths: r.pathname.split("/").filter(Boolean)
55
57
  }, this;
56
58
  }
57
- withHash(r) {
58
- return this.#r.hash = r, this;
59
+ withHash(t) {
60
+ return this.#t.hash = t, this;
59
61
  }
60
- withAuth(r) {
61
- if ((0, _isString.isString)(r)) {
62
- this.#r.auth = r;
63
- const t = (0, _ufo.parseAuth)(r);
64
- this.#r.username = t.username, this.#r.password = t.password;
65
- } else this.#r.username = r.username, this.#r.password = r.password, this.#r.auth = `${r.username}:${r.password}`;
62
+ withAuth(t) {
63
+ if ((0, _isString.isString)(t)) {
64
+ this.#t.auth = t;
65
+ const r = (0, _ufo.parseAuth)(t);
66
+ this.#t.username = r.username, this.#t.password = r.password;
67
+ } else this.#t.username = t.username, this.#t.password = t.password, this.#t.auth = `${t.username}:${t.password}`;
66
68
  return this;
67
69
  }
68
- withQuery(r) {
69
- return this.#r.queryParams = {}, this.addQueryParam(r), this;
70
+ withQuery(t) {
71
+ return this.#t.queryParams = {}, this.addQueryParam(t), this;
70
72
  }
71
- addQueryParam(r) {
72
- if ((0, _isString.isString)(r)) {
73
- const t = (0, _ufo.parseQuery)(r);
74
- for (const s of Object.entries(t)) s[0] && (this.#r.queryParams[s[0]] = this.parseQueryParamValue(s[1]));
75
- } else if (Array.isArray(r) && r.length === 2) this.#r.queryParams[r[0]] = this.parseQueryParamValue(r[1]);else for (const t of Object.entries(r)) t[0] && (this.#r.queryParams[t[0]] = this.parseQueryParamValue(t[1]));
73
+ addQueryParam(t) {
74
+ if ((0, _isString.isString)(t)) {
75
+ const r = (0, _ufo.parseQuery)(t);
76
+ for (const s of Object.entries(r)) s[0] && (this.#t.queryParams[s[0]] = this.parseQueryParamValue(s[1]));
77
+ } else if (Array.isArray(t) && t.length === 2) this.#t.queryParams[t[0]] = this.parseQueryParamValue(t[1]);else for (const r of Object.entries(t)) r[0] && (this.#t.queryParams[r[0]] = this.parseQueryParamValue(r[1]));
76
78
  return this;
77
79
  }
78
80
  build() {
79
- return this.#r;
81
+ return this.#t;
80
82
  }
81
83
  toString() {
82
- return (0, _ufo.cleanDoubleSlashes)((0, _ufo.stringifyParsedURL)(this.#r));
84
+ return (0, _ufo.cleanDoubleSlashes)((0, _ufo.stringifyParsedURL)(this.#t));
83
85
  }
84
86
  toEncoded() {
85
87
  return (0, _ufo.encode)(this.toString());
86
88
  }
87
- parseQueryParamValue(r) {
88
- if (Array.isArray(r)) {
89
- const t = [];
90
- for (const s of r) t.push(this.parseQueryParamValue(s));
91
- return t;
89
+ parseQueryParamValue(t) {
90
+ if (Array.isArray(t)) {
91
+ const r = [];
92
+ for (const s of t) r.push(this.parseQueryParamValue(s));
93
+ return r;
92
94
  }
93
- return _stormJson.StormJSON.parse(r);
95
+ return _stormJson.StormJSON.parse(t);
94
96
  }
95
97
  }
96
98
  exports.StormURLBuilder = StormURLBuilder;
@@ -1 +1 @@
1
- import{StormJSON as a}from"@stryke/json/storm-json";import{isString as i}from"@stryke/type-checks/is-string";import{cleanDoubleSlashes as u,decode as h,encode as p,parseAuth as e,parsePath as d,parseQuery as m,parseURL as o,stringifyParsedURL as c}from"ufo";export class StormURLBuilder{#r;static create(r,t){return new StormURLBuilder(r,t)}constructor(r,t){const s=t?.decode??!0,n=i(r)?s?o(h(r)):o(r):r;this.#r={__typename:"StormURL",queryParams:{},...n},this.#r.host&&this.withHost(this.#r.host),this.#r.auth&&this.withAuth(this.#r.auth)}get _url(){return this.#r}withProtocol(r){return this.#r.protocol=r,this}withHostname(r){return this.#r.hostname=r,this}withPort(r){return this.#r.port=String(r),this}withUsername(r){return this.#r.username=r,this}withPassword(r){return this.#r.password=r,this}withHost(r){if(i(r)){this.#r.host=r;const t=e(r);this.#r.username=t.username,this.#r.password=t.password}else this.#r.hostname=r.hostname,this.#r.port=r.port,this.#r.auth=`${r.hostname}${r.port?`:${r.port}`:""}`;return this}withPath(r){const t=d(r);return this.#r={...this.#r,...t},this}withHash(r){return this.#r.hash=r,this}withAuth(r){if(i(r)){this.#r.auth=r;const t=e(r);this.#r.username=t.username,this.#r.password=t.password}else this.#r.username=r.username,this.#r.password=r.password,this.#r.auth=`${r.username}:${r.password}`;return this}withQuery(r){return this.#r.queryParams={},this.addQueryParam(r),this}addQueryParam(r){if(i(r)){const t=m(r);for(const s of Object.entries(t))s[0]&&(this.#r.queryParams[s[0]]=this.parseQueryParamValue(s[1]))}else if(Array.isArray(r)&&r.length===2)this.#r.queryParams[r[0]]=this.parseQueryParamValue(r[1]);else for(const t of Object.entries(r))t[0]&&(this.#r.queryParams[t[0]]=this.parseQueryParamValue(t[1]));return this}build(){return this.#r}toString(){return u(c(this.#r))}toEncoded(){return p(this.toString())}parseQueryParamValue(r){if(Array.isArray(r)){const t=[];for(const s of r)t.push(this.parseQueryParamValue(s));return t}return a.parse(r)}}
1
+ import{StormJSON as a}from"@stryke/json/storm-json";import{isString as e}from"@stryke/type-checks/is-string";import{cleanDoubleSlashes as h,decode as u,encode as p,parseAuth as o,parsePath as m,parseQuery as d,parseURL as n,stringifyParsedURL as l}from"ufo";export class StormURLBuilder{#t;static create(t,r){return new StormURLBuilder(t,r)}constructor(t,r){const s=r?.decode??!0,i=e(t)?s?n(u(t)):n(t):t;this.#t={__typename:"StormURL",queryParams:{},...i,paths:i.pathname?i.pathname.split("/").filter(Boolean):[]},this.#t.host&&this.withHost(this.#t.host),this.#t.auth&&this.withAuth(this.#t.auth)}get _url(){return this.#t}withProtocol(t){return this.#t.protocol=t,this}withHostname(t){return this.#t.hostname=t,this}withPort(t){return this.#t.port=String(t),this}withUsername(t){return this.#t.username=t,this}withPassword(t){return this.#t.password=t,this}withHost(t){if(e(t)){this.#t.host=t;const r=o(t);this.#t.username=r.username,this.#t.password=r.password}else this.#t.hostname=t.hostname,this.#t.port=t.port,this.#t.auth=`${t.hostname}${t.port?`:${t.port}`:""}`;return this}withPath(t){const r=m(t);return this.#t={...this.#t,...r,paths:r.pathname.split("/").filter(Boolean)},this}withHash(t){return this.#t.hash=t,this}withAuth(t){if(e(t)){this.#t.auth=t;const r=o(t);this.#t.username=r.username,this.#t.password=r.password}else this.#t.username=t.username,this.#t.password=t.password,this.#t.auth=`${t.username}:${t.password}`;return this}withQuery(t){return this.#t.queryParams={},this.addQueryParam(t),this}addQueryParam(t){if(e(t)){const r=d(t);for(const s of Object.entries(r))s[0]&&(this.#t.queryParams[s[0]]=this.parseQueryParamValue(s[1]))}else if(Array.isArray(t)&&t.length===2)this.#t.queryParams[t[0]]=this.parseQueryParamValue(t[1]);else for(const r of Object.entries(t))r[0]&&(this.#t.queryParams[r[0]]=this.parseQueryParamValue(r[1]));return this}build(){return this.#t}toString(){return h(l(this.#t))}toEncoded(){return p(this.toString())}parseQueryParamValue(t){if(Array.isArray(t)){const r=[];for(const s of t)r.push(this.parseQueryParamValue(s));return r}return a.parse(t)}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/http",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "A package containing HTTP communication utilities used by Storm Software.",
6
6
  "repository": {
@@ -11,8 +11,8 @@
11
11
  "private": false,
12
12
  "dependencies": {
13
13
  "ufo": "1.5.4",
14
- "@stryke/json": ">=0.5.2",
15
- "@stryke/type-checks": ">=0.1.2"
14
+ "@stryke/json": ">=0.5.3",
15
+ "@stryke/type-checks": ">=0.1.3"
16
16
  },
17
17
  "devDependencies": { "@types/node": "^22.13.1" },
18
18
  "publishConfig": { "access": "public" },