@hulla/api-request
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,325 +0,174 @@ | ||
import * as _hulla_api from '@hulla/api' | ||
import { Args, Call, Context, Fn, Obj, Resolver, TypeError } from '@hulla/api' | ||
import * as _hulla_api from '@hulla/api'; | ||
import { TypeError, Args, Fn, Resolver, Context, Call, Obj } from '@hulla/api'; | ||
type Methods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE' | ||
type Methods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE'; | ||
type LowercaseMethods = { | ||
[K in Methods]: Lowercase<K> | ||
}[Methods] | ||
type StaticConfig<M extends Methods | LowercaseMethods, U extends string = string, P extends boolean = true> = Partial< | ||
RequestInit & { | ||
method?: M | ||
data?: unknown | ||
checkParams?: P | ||
params?: Record<string, URICompoent> | ||
} | ||
> & { | ||
readonly url: U | ||
} & (Uppercase<M> extends 'HEAD' | 'GET' | ||
? { | ||
body?: TypeError< | ||
`ERROR: method "${M}" cannot contain a body`, | ||
'https://developer.mozilla.org/en-US/docs/Web/API/Request/body' | ||
> | ||
} | ||
: {}) | ||
type TypedRequestConfig< | ||
M extends LowercaseMethods | Methods, | ||
U extends string = string, | ||
P extends boolean = true, | ||
> = StaticConfig<M, U, P> & | ||
(P extends true | ||
? U extends string | ||
? HasPath<U> extends never | ||
? ParseSearch<U> extends never | ||
? {} | ||
: { | ||
params: URLToParams<U> | ||
} | ||
: { | ||
params: URLToParams<U> | ||
} | ||
: {} | ||
: {}) | ||
[K in Methods]: Lowercase<K>; | ||
}[Methods]; | ||
type StaticConfig<M extends Methods | LowercaseMethods, U extends string = string, P extends boolean = true> = Partial<RequestInit & { | ||
method?: M; | ||
data?: unknown; | ||
checkParams?: P; | ||
params?: Record<string, URICompoent>; | ||
}> & { | ||
readonly url: U; | ||
} & (Uppercase<M> extends 'HEAD' | 'GET' ? { | ||
body?: TypeError<`ERROR: method "${M}" cannot contain a body`, 'https://developer.mozilla.org/en-US/docs/Web/API/Request/body'>; | ||
} : {}); | ||
type TypedRequestConfig<M extends LowercaseMethods | Methods, U extends string = string, P extends boolean = true> = StaticConfig<M, U, P> & (P extends true ? U extends string ? HasPath<U> extends never ? ParseSearch<U> extends never ? {} : { | ||
params: URLToParams<U>; | ||
} : { | ||
params: URLToParams<U>; | ||
} : {} : {}); | ||
type RequestMap<CTX> = { | ||
[M in LowercaseMethods]: < | ||
const N extends string, | ||
const R extends TypedRequestConfig<M | Uppercase<M>> | string | URL | Request, | ||
A extends Args = [], | ||
const R2 = Promise<Response>, | ||
>( | ||
route: N, | ||
configOrConfigFn: Fn<A, R> | R, | ||
resolver?: Resolver<CTX & Context<N, M, A>, R, R2> | ||
) => Call<N, M, CTX, A, R, R2> | ||
} | ||
type URLType = InstanceType<typeof URL> | ||
type ExtractUrl<U> = U extends | ||
| { | ||
url: string | ||
} | ||
| string | ||
? U extends { | ||
url: string | ||
} | ||
? U['url'] | ||
: U | ||
: never | ||
type URICompoent = string | number | boolean | ||
type ParsePath< | ||
U extends | ||
| string | ||
| { | ||
url: string | ||
}, | ||
> = | ||
ExtractUrl<U> extends `${string}/:${infer Param}/${infer Rest}` | ||
? { | ||
[K in Param]: URICompoent | ||
} & ParsePath<Rest> | ||
: ExtractUrl<U> extends `${string}/:${infer Param}` | ||
? { | ||
[K in Param]: URICompoent | ||
} | ||
: {} | ||
type HasPath< | ||
U extends | ||
| string | ||
| { | ||
url: string | ||
}, | ||
> = | ||
ExtractUrl<U> extends `${string}/:${infer Param}/${infer Rest}` | ||
? { | ||
[K in Param]: URICompoent | ||
} & ParsePath<Rest> | ||
: ExtractUrl<U> extends `${string}/:${infer Param}` | ||
? { | ||
[K in Param]: URICompoent | ||
} | ||
: never | ||
type ParseSearch< | ||
U extends | ||
| string | ||
| { | ||
url: string | ||
}, | ||
> = | ||
ExtractUrl<U> extends `${string}?${infer Params}` | ||
? Params extends `${infer Key}&${infer Rest}` | ||
? { | ||
[K in Key]: URICompoent | ||
} & ParseSearch<`?${Rest}`> | ||
: Params extends `${infer Key}` | ||
? { | ||
[K in Key]: URICompoent | ||
} | ||
: never | ||
: never | ||
type URLToParams< | ||
U extends | ||
| string | ||
| { | ||
url: string | ||
}, | ||
> = U extends | ||
| { | ||
url: string | ||
} | ||
| string | ||
? { | ||
[K in keyof ParsePath<U>]: ParsePath<U>[K] | ||
} & { | ||
[K in keyof ParseSearch<U>]: ParseSearch<U>[K] | ||
} | ||
: never | ||
[M in LowercaseMethods]: <const N extends string, const R extends TypedRequestConfig<M | Uppercase<M>> | string | URL | Request, A extends Args = [], const R2 = Promise<Response>>(route: N, configOrConfigFn: Fn<A, R> | R, resolver?: Resolver<CTX & Context<N, M, A>, R, R2>) => Call<N, M, CTX, A, R, R2>; | ||
}; | ||
type URLType = InstanceType<typeof URL>; | ||
type ExtractUrl<U> = U extends { | ||
url: string; | ||
} | string ? (U extends { | ||
url: string; | ||
} ? U['url'] : U) : never; | ||
type URICompoent = string | number | boolean; | ||
type ParsePath<U extends string | { | ||
url: string; | ||
}> = ExtractUrl<U> extends `${string}/:${infer Param}/${infer Rest}` ? { | ||
[K in Param]: URICompoent; | ||
} & ParsePath<Rest> : ExtractUrl<U> extends `${string}/:${infer Param}` ? { | ||
[K in Param]: URICompoent; | ||
} : {}; | ||
type HasPath<U extends string | { | ||
url: string; | ||
}> = ExtractUrl<U> extends `${string}/:${infer Param}/${infer Rest}` ? { | ||
[K in Param]: URICompoent; | ||
} & ParsePath<Rest> : ExtractUrl<U> extends `${string}/:${infer Param}` ? { | ||
[K in Param]: URICompoent; | ||
} : never; | ||
type ParseSearch<U extends string | { | ||
url: string; | ||
}> = ExtractUrl<U> extends `${string}?${infer Params}` ? Params extends `${infer Key}&${infer Rest}` ? { | ||
[K in Key]: URICompoent; | ||
} & ParseSearch<`?${Rest}`> : Params extends `${infer Key}` ? { | ||
[K in Key]: URICompoent; | ||
} : never : never; | ||
type URLToParams<U extends string | { | ||
url: string; | ||
}> = U extends { | ||
url: string; | ||
} | string ? { | ||
[K in keyof ParsePath<U>]: ParsePath<U>[K]; | ||
} & { | ||
[K in keyof ParseSearch<U>]: ParseSearch<U>[K]; | ||
} : never; | ||
type Callables<T> = { | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never | ||
}[keyof T] | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never; | ||
}[keyof T]; | ||
declare function resolve< | ||
R, | ||
Req extends TypedRequestConfig<LowercaseMethods | Methods> | string | URL = | ||
| TypedRequestConfig<LowercaseMethods | Methods> | ||
| string | ||
| URL, | ||
T extends Callables<Response> = 'json', | ||
>(req: Req, ctx: Context<string, LowercaseMethods, Args, string>, transformer?: T): R | ||
declare function request<const CTX>(_ctx?: CTX): { | ||
get: <const N extends string, const U extends string, const R extends string | URL | Request | TypedRequestConfig<"GET" | "get", U>, A extends _hulla_api.Args = [], const R2 = Promise<Response>>(route: N, configOrConfigFn: R | _hulla_api.Fn<A, R>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N, "get", A>, R, R2>) => _hulla_api.Call<N, "get", CTX & _hulla_api.Context<N, "get", A>, A, R, R2>; | ||
post: <const N_1 extends string, const U_1 extends string, const R_1 extends string | URL | Request | TypedRequestConfig<"POST" | "post", U_1>, A_1 extends _hulla_api.Args = [], const R2_1 = Promise<Response>>(route: N_1, configOrConfigFn: R_1 | _hulla_api.Fn<A_1, R_1>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_1, "post", A_1>, R_1, R2_1>) => _hulla_api.Call<N_1, "post", CTX & _hulla_api.Context<N_1, "post", A_1>, A_1, R_1, R2_1>; | ||
patch: <const N_2 extends string, const U_2 extends string, const R_2 extends string | URL | Request | TypedRequestConfig<"PATCH" | "patch", U_2>, A_2 extends _hulla_api.Args = [], const R2_2 = Promise<Response>>(route: N_2, configOrConfigFn: R_2 | _hulla_api.Fn<A_2, R_2>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_2, "patch", A_2>, R_2, R2_2>) => _hulla_api.Call<N_2, "patch", CTX & _hulla_api.Context<N_2, "patch", A_2>, A_2, R_2, R2_2>; | ||
put: <const N_3 extends string, const U_3 extends string, const R_3 extends string | URL | Request | TypedRequestConfig<"PUT" | "put", U_3>, A_3 extends _hulla_api.Args = [], const R2_3 = Promise<Response>>(route: N_3, configOrConfigFn: R_3 | _hulla_api.Fn<A_3, R_3>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_3, "put", A_3>, R_3, R2_3>) => _hulla_api.Call<N_3, "put", CTX & _hulla_api.Context<N_3, "put", A_3>, A_3, R_3, R2_3>; | ||
delete: <const N_4 extends string, const U_4 extends string, const R_4 extends string | URL | Request | TypedRequestConfig<"DELETE" | "delete", U_4>, A_4 extends _hulla_api.Args = [], const R2_4 = Promise<Response>>(route: N_4, configOrConfigFn: R_4 | _hulla_api.Fn<A_4, R_4>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_4, "delete", A_4>, R_4, R2_4>) => _hulla_api.Call<N_4, "delete", CTX & _hulla_api.Context<N_4, "delete", A_4>, A_4, R_4, R2_4>; | ||
head: <const N_5 extends string, const U_5 extends string, const R_5 extends string | URL | Request | TypedRequestConfig<"HEAD" | "head", U_5>, A_5 extends _hulla_api.Args = [], const R2_5 = Promise<Response>>(route: N_5, configOrConfigFn: R_5 | _hulla_api.Fn<A_5, R_5>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_5, "head", A_5>, R_5, R2_5>) => _hulla_api.Call<N_5, "head", CTX & _hulla_api.Context<N_5, "head", A_5>, A_5, R_5, R2_5>; | ||
options: <const N_6 extends string, const U_6 extends string, const R_6 extends string | URL | Request | TypedRequestConfig<"OPTIONS" | "options", U_6>, A_6 extends _hulla_api.Args = [], const R2_6 = Promise<Response>>(route: N_6, configOrConfigFn: R_6 | _hulla_api.Fn<A_6, R_6>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_6, "options", A_6>, R_6, R2_6>) => _hulla_api.Call<N_6, "options", CTX & _hulla_api.Context<N_6, "options", A_6>, A_6, R_6, R2_6>; | ||
connect: <const N_7 extends string, const U_7 extends string, const R_7 extends string | URL | Request | TypedRequestConfig<"CONNECT" | "connect", U_7>, A_7 extends _hulla_api.Args = [], const R2_7 = Promise<Response>>(route: N_7, configOrConfigFn: R_7 | _hulla_api.Fn<A_7, R_7>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_7, "connect", A_7>, R_7, R2_7>) => _hulla_api.Call<N_7, "connect", CTX & _hulla_api.Context<N_7, "connect", A_7>, A_7, R_7, R2_7>; | ||
trace: <const N_8 extends string, const U_8 extends string, const R_8 extends string | URL | Request | TypedRequestConfig<"TRACE" | "trace", U_8>, A_8 extends _hulla_api.Args = [], const R2_8 = Promise<Response>>(route: N_8, configOrConfigFn: R_8 | _hulla_api.Fn<A_8, R_8>, resolver?: _hulla_api.Resolver<CTX & _hulla_api.Context<N_8, "trace", A_8>, R_8, R2_8>) => _hulla_api.Call<N_8, "trace", CTX & _hulla_api.Context<N_8, "trace", A_8>, A_8, R_8, R2_8>; | ||
}; | ||
declare function addParams<const U extends string>( | ||
req: TypedRequestConfig<LowercaseMethods | Methods, U> & { | ||
params?: Record<string, URICompoent> | ||
} | ||
): string | ||
declare function parseUrl<CTX extends Obj>( | ||
req: TypedRequestConfig<LowercaseMethods | Methods> | URL | string | Request, | ||
context?: CTX | ||
): URL | ||
declare function parseBody( | ||
req: TypedRequestConfig<LowercaseMethods | Methods> | URL | string | Request | ||
): RequestInit['body'] | ||
declare function parseRequest<M extends LowercaseMethods>( | ||
req: TypedRequestConfig<LowercaseMethods | Methods> | URL | string | Request, | ||
url: URL, | ||
body: RequestInit['body'], | ||
ctx: Context<string, M, Args, string> | ||
): | ||
| { | ||
body?: BodyInit | null | undefined | ||
url: URL | ||
method: M | ||
} | ||
| { | ||
body?: BodyInit | null | undefined | ||
url: URL | ||
hash: string | ||
host: string | ||
hostname: string | ||
href: string | ||
toString(): string | ||
origin: string | ||
password: string | ||
pathname: string | ||
port: string | ||
protocol: string | ||
search: string | ||
searchParams: URLSearchParams | ||
username: string | ||
toJSON(): string | ||
createObjectURL(obj: Blob): string | ||
revokeObjectURL(url: string): void | ||
canParse(url: string, base?: string | undefined): boolean | ||
method: M | ||
} | ||
| { | ||
body: BodyInit | null | ||
url: URL | ||
cache: RequestCache | ||
credentials: RequestCredentials | ||
destination: RequestDestination | ||
headers: Headers | ||
integrity: string | ||
keepalive: boolean | ||
method: string | ||
mode: RequestMode | ||
redirect: RequestRedirect | ||
referrer: string | ||
referrerPolicy: ReferrerPolicy | ||
signal: AbortSignal | ||
clone(): Request | ||
bodyUsed: boolean | ||
arrayBuffer(): Promise<ArrayBuffer> | ||
blob(): Promise<Blob> | ||
formData(): Promise<FormData> | ||
json(): Promise<any> | ||
text(): Promise<string> | ||
} | ||
| { | ||
body?: BodyInit | null | undefined | ||
url: URL | ||
cache?: RequestCache | undefined | ||
credentials?: RequestCredentials | undefined | ||
headers?: HeadersInit | undefined | ||
integrity?: string | undefined | ||
keepalive?: boolean | undefined | ||
method: | ||
| 'GET' | ||
| 'POST' | ||
| 'PUT' | ||
| 'PATCH' | ||
| 'DELETE' | ||
| 'OPTIONS' | ||
| 'HEAD' | ||
| 'CONNECT' | ||
| 'TRACE' | ||
| 'get' | ||
| 'post' | ||
| 'put' | ||
| 'patch' | ||
| 'delete' | ||
| 'options' | ||
| 'head' | ||
| 'connect' | ||
| 'trace' | ||
mode?: RequestMode | undefined | ||
priority?: RequestPriority | undefined | ||
redirect?: RequestRedirect | undefined | ||
referrer?: string | undefined | ||
referrerPolicy?: ReferrerPolicy | undefined | ||
signal?: AbortSignal | null | undefined | ||
window?: null | undefined | ||
data?: unknown | ||
checkParams?: true | undefined | ||
params?: Record<string, URICompoent> | undefined | ||
} | ||
declare function response< | ||
M extends LowercaseMethods | Methods, | ||
RQ extends TypedRequestConfig<M> | URL | string | Request, | ||
R2 = Promise<Response>, | ||
>(req: RQ, ctx: Context<string, Lowercase<M>, Args, string>): R2 | ||
declare function resolve<R, Req extends TypedRequestConfig<LowercaseMethods | Methods> | string | URL = TypedRequestConfig<LowercaseMethods | Methods> | string | URL, T extends Callables<Response> = 'json'>(req: Req, ctx: Context<string, LowercaseMethods, Args, string>, transformer?: T): R; | ||
declare function rq<const M extends LowercaseMethods | Methods, const U extends string, P extends boolean = true>( | ||
config: TypedRequestConfig<M, U, P> & { | ||
method: M | ||
} | ||
): Partial< | ||
RequestInit & { | ||
method?: M | undefined | ||
data?: unknown | ||
checkParams?: P | undefined | ||
params?: Record<string, URICompoent> | undefined | ||
} | ||
> & { | ||
readonly url: U | ||
} & (Uppercase<M> extends 'GET' | 'HEAD' | ||
? { | ||
body?: | ||
| _hulla_api.TypeError< | ||
`ERROR: method "${M}" cannot contain a body`, | ||
'https://developer.mozilla.org/en-US/docs/Web/API/Request/body' | ||
> | ||
| undefined | ||
} | ||
: {}) & | ||
(P extends true | ||
? U extends string | ||
? ( | ||
ExtractUrl<U> extends `${string}/:${infer Param}/${infer Rest}` | ||
? { [K in Param]: URICompoent } & ParsePath<Rest> | ||
: ExtractUrl<U> extends `${string}/:${infer Param_1}` | ||
? { [K_1 in Param_1]: URICompoent } | ||
: never | ||
) extends never | ||
? ParseSearch<U> extends never | ||
? {} | ||
: { | ||
params: URLToParams<U> | ||
} | ||
: { | ||
params: URLToParams<U> | ||
} | ||
: {} | ||
: {}) & { | ||
method: M | ||
} | ||
declare function addParams<const U extends string>(req: TypedRequestConfig<LowercaseMethods | Methods, U> & { | ||
params?: Record<string, URICompoent>; | ||
}): string; | ||
declare function parseUrl<CTX extends Obj>(req: TypedRequestConfig<LowercaseMethods | Methods> | URL | string | Request, context?: CTX): URL; | ||
declare function parseBody(req: TypedRequestConfig<LowercaseMethods | Methods> | URL | string | Request): RequestInit['body']; | ||
declare function parseRequest<M extends LowercaseMethods>(req: TypedRequestConfig<LowercaseMethods | Methods> | URL | string | Request, url: URL, body: RequestInit['body'], ctx: Context<string, M, Args, string>): { | ||
body?: BodyInit | null | undefined; | ||
url: URL; | ||
method: M; | ||
} | { | ||
body?: BodyInit | null | undefined; | ||
url: URL; | ||
hash: string; | ||
host: string; | ||
hostname: string; | ||
href: string; | ||
toString(): string; | ||
origin: string; | ||
password: string; | ||
pathname: string; | ||
port: string; | ||
protocol: string; | ||
search: string; | ||
searchParams: URLSearchParams; | ||
username: string; | ||
toJSON(): string; | ||
createObjectURL(obj: Blob): string; | ||
revokeObjectURL(url: string): void; | ||
canParse(url: string, base?: string | undefined): boolean; | ||
method: M; | ||
} | { | ||
body: BodyInit | null; | ||
url: URL; | ||
cache: RequestCache; | ||
credentials: RequestCredentials; | ||
destination: RequestDestination; | ||
headers: Headers; | ||
integrity: string; | ||
keepalive: boolean; | ||
method: string; | ||
mode: RequestMode; | ||
redirect: RequestRedirect; | ||
referrer: string; | ||
referrerPolicy: ReferrerPolicy; | ||
signal: AbortSignal; | ||
clone(): Request; | ||
bodyUsed: boolean; | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
blob(): Promise<Blob>; | ||
formData(): Promise<FormData>; | ||
json(): Promise<any>; | ||
text(): Promise<string>; | ||
} | { | ||
body?: BodyInit | null | undefined; | ||
url: URL; | ||
cache?: RequestCache | undefined; | ||
credentials?: RequestCredentials | undefined; | ||
headers?: HeadersInit | undefined; | ||
integrity?: string | undefined; | ||
keepalive?: boolean | undefined; | ||
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD" | "CONNECT" | "TRACE" | "get" | "post" | "put" | "patch" | "delete" | "options" | "head" | "connect" | "trace"; | ||
mode?: RequestMode | undefined; | ||
priority?: RequestPriority | undefined; | ||
redirect?: RequestRedirect | undefined; | ||
referrer?: string | undefined; | ||
referrerPolicy?: ReferrerPolicy | undefined; | ||
signal?: AbortSignal | null | undefined; | ||
window?: null | undefined; | ||
data?: unknown; | ||
checkParams?: true | undefined; | ||
params?: Record<string, URICompoent> | undefined; | ||
}; | ||
declare function response<M extends LowercaseMethods | Methods, RQ extends TypedRequestConfig<M> | URL | string | Request, R2 = Promise<Response>>(req: RQ, ctx: Context<string, Lowercase<M>, Args, string>): R2; | ||
export { | ||
addParams, | ||
parseBody, | ||
parseRequest, | ||
parseUrl, | ||
resolve, | ||
response, | ||
rq, | ||
type Callables, | ||
type ExtractUrl, | ||
type LowercaseMethods, | ||
type Methods, | ||
type ParsePath, | ||
type ParseSearch, | ||
type RequestMap, | ||
type StaticConfig, | ||
type TypedRequestConfig, | ||
type URICompoent, | ||
type URLToParams, | ||
type URLType, | ||
} | ||
declare function rq<const M extends LowercaseMethods | Methods, const U extends string, P extends boolean = true>(config: TypedRequestConfig<M, U, P> & { | ||
method: M; | ||
}): Partial<RequestInit & { | ||
method?: M | undefined; | ||
data?: unknown; | ||
checkParams?: P | undefined; | ||
params?: Record<string, URICompoent> | undefined; | ||
}> & { | ||
readonly url: U; | ||
} & (Uppercase<M> extends "GET" | "HEAD" ? { | ||
body?: _hulla_api.TypeError<`ERROR: method "${M}" cannot contain a body`, "https://developer.mozilla.org/en-US/docs/Web/API/Request/body"> | undefined; | ||
} : {}) & (P extends true ? U extends string ? (ExtractUrl<U> extends `${string}/:${infer Param}/${infer Rest}` ? { [K in Param]: URICompoent; } & ParsePath<Rest> : ExtractUrl<U> extends `${string}/:${infer Param_1}` ? { [K_1 in Param_1]: URICompoent; } : never) extends never ? ParseSearch<U> extends never ? {} : { | ||
params: URLToParams<U>; | ||
} : { | ||
params: URLToParams<U>; | ||
} : {} : {}) & { | ||
method: M; | ||
}; | ||
export { type Callables, type ExtractUrl, type LowercaseMethods, type Methods, type ParsePath, type ParseSearch, type RequestMap, type StaticConfig, type TypedRequestConfig, type URICompoent, type URLToParams, type URLType, addParams, parseBody, parseRequest, parseUrl, request, resolve, response, rq }; |
@@ -1,49 +0,1 @@ | ||
function e(e) { | ||
return e instanceof URL | ||
} | ||
function t(e) { | ||
let t = e.url, | ||
n = e.params ?? {} | ||
for (let e in n) | ||
t = (t = (t = t.replace(RegExp(':' + e, 'g'), encodeURIComponent(n[e]))).replace( | ||
RegExp('\\?' + e, 'g'), | ||
`?${e}=${encodeURIComponent(n[e])}` | ||
)).replace(RegExp('&' + e, 'g'), `&${e}=${encodeURIComponent(n[e])}`) | ||
return t | ||
} | ||
function n(n, r = {}) { | ||
let o = r.baseURL ?? '' | ||
if ('string' == typeof n) return new URL(`${o}${n}`) | ||
if (e(n)) return n | ||
if (n instanceof Request) return new URL(n.url) | ||
let s = t(n) | ||
return new URL(`${o}${s}`) | ||
} | ||
function r(e) { | ||
let t = e.data | ||
return e.body ? e.body : e.data ? ('string' == typeof t ? t : JSON.stringify(t)) : void 0 | ||
} | ||
function o(t, n, r, o) { | ||
return { | ||
...('string' == typeof t || e(t) ? { method: o.method } : { method: o.method, ...t }), | ||
url: n, | ||
...(void 0 === r ? {} : { body: r }), | ||
} | ||
} | ||
function s(e, t) { | ||
let s = n(e, t), | ||
p = r(e), | ||
u = o(e, s, p, t) | ||
return fetch(s, u) | ||
} | ||
;(exports.addParams = t), | ||
(exports.parseBody = r), | ||
(exports.parseRequest = o), | ||
(exports.parseUrl = n), | ||
(exports.resolve = function (e, t, n) { | ||
return s(e, t).then((e) => e[n ?? 'json']()) | ||
}), | ||
(exports.response = s), | ||
(exports.rq = function (e) { | ||
return e | ||
}) | ||
function e(e){return e instanceof URL}function t(e){let t=e.url,n=e.params??{};for(let e in n)t=(t=(t=t.replace(RegExp(":"+e,"g"),encodeURIComponent(n[e]))).replace(RegExp("\\?"+e,"g"),`?${e}=${encodeURIComponent(n[e])}`)).replace(RegExp("&"+e,"g"),`&${e}=${encodeURIComponent(n[e])}`);return t}function n(n,o={}){let r=o.baseURL??"";if("string"==typeof n)return new URL(`${r}${n}`);if(e(n))return new URL(`${r}${n.href}`);if(n instanceof Request)return new URL(`${r}${n.url}`);let p=t(n);return new URL(`${r}${p}`)}function o(e){let t=e.data;return e.body?e.body:e.data?"string"==typeof t?t:JSON.stringify(t):void 0}function r(t,n,o,r){return{..."string"==typeof t||e(t)?{method:r.method}:{method:r.method,...t},url:n,...void 0===o?{}:{body:o}}}function p(e,t){let p=n(e,t),s=o(e),u=r(e,p,s,t);return fetch(p,u)}const s=e=>(t,n,o=p)=>({route:t,method:e.toLowerCase(),fn:"function"==typeof n?n:()=>n,resolver:o});exports.addParams=t,exports.parseBody=o,exports.parseRequest=r,exports.parseUrl=n,exports.request=function(e){return{get:s("get"),post:s("post"),patch:s("patch"),put:s("put"),delete:s("delete"),head:s("head"),options:s("options"),connect:s("connect"),trace:s("trace")}},exports.resolve=function(e,t,n){return p(e,t).then(e=>e[n??"json"]())},exports.response=p,exports.rq=function(e){return e}; |
{ | ||
"name": "@hulla/api-request", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "The next-gen API/RPC manager 🚀", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27793
190
3