@stryke/http 0.5.1 → 0.5.2

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.
@@ -49,7 +49,7 @@ class StormURLBuilder {
49
49
  return this;
50
50
  }
51
51
  withPath(t) {
52
- const r = (0, _ufo.parsePath)(t);
52
+ const r = (0, _ufo.parsePath)(t.startsWith("/") ? t : `/${t}`);
53
53
  return this.#t = {
54
54
  ...this.#t,
55
55
  ...r,
@@ -1 +1 @@
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)}}
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.startsWith("/")?t:`/${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.5.1",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "A package containing HTTP communication utilities used by Storm Software.",
6
6
  "repository": {