@unshared/client 0.2.3 → 0.3.0
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/HttpHeaders.cjs +4 -0
- package/dist/HttpHeaders.cjs.map +1 -0
- package/dist/{chunks/8BFCFxqa.d.ts → HttpHeaders.d.ts} +1 -1
- package/dist/HttpHeaders.js +5 -0
- package/dist/HttpHeaders.js.map +1 -0
- package/dist/HttpMethods.cjs +4 -0
- package/dist/HttpMethods.cjs.map +1 -0
- package/dist/{chunks/DZp6zyqV.d.ts → HttpMethods.d.ts} +1 -98
- package/dist/HttpMethods.js +5 -0
- package/dist/HttpMethods.js.map +1 -0
- package/dist/HttpStatusCodes.cjs +4 -0
- package/dist/HttpStatusCodes.cjs.map +1 -0
- package/dist/HttpStatusCodes.d.ts +615 -0
- package/dist/HttpStatusCodes.js +5 -0
- package/dist/HttpStatusCodes.js.map +1 -0
- package/dist/chunks/B92aAMq0.d.ts +144 -0
- package/dist/chunks/{D-WqCFul.js → Biic1J5b.js} +11 -9
- package/dist/chunks/Biic1J5b.js.map +1 -0
- package/dist/chunks/CfKxYeRr.cjs +155 -0
- package/dist/chunks/CfKxYeRr.cjs.map +1 -0
- package/dist/chunks/CjU0376e.d.ts +229 -0
- package/dist/chunks/{xRZPkxch.cjs → CtW2aMuA.cjs} +11 -9
- package/dist/chunks/CtW2aMuA.cjs.map +1 -0
- package/dist/chunks/D51s1VII.js +156 -0
- package/dist/chunks/D51s1VII.js.map +1 -0
- package/dist/chunks/iA98-4f5.cjs +8 -0
- package/dist/chunks/iA98-4f5.cjs.map +1 -0
- package/dist/chunks/lMH6B5BV.js +9 -0
- package/dist/chunks/lMH6B5BV.js.map +1 -0
- package/dist/createClient.cjs +81 -18
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +93 -29
- package/dist/createClient.js +83 -20
- package/dist/createClient.js.map +1 -1
- package/dist/createService.cjs +17 -0
- package/dist/createService.cjs.map +1 -0
- package/dist/createService.d.ts +38 -0
- package/dist/createService.js +19 -0
- package/dist/createService.js.map +1 -0
- package/dist/index.cjs +22 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -624
- package/dist/index.js +24 -19
- package/dist/index.js.map +1 -1
- package/dist/openapi.cjs +3 -15
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.d.ts +7 -35
- package/dist/openapi.js +3 -15
- package/dist/openapi.js.map +1 -1
- package/dist/utils.cjs +13 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +57 -27
- package/dist/utils.js +11 -9
- package/package.json +23 -8
- package/dist/chunks/B2OrSen1.d.ts +0 -185
- package/dist/chunks/B5hc73Po.js +0 -96
- package/dist/chunks/B5hc73Po.js.map +0 -1
- package/dist/chunks/CKfJvIQ8.js +0 -50
- package/dist/chunks/CKfJvIQ8.js.map +0 -1
- package/dist/chunks/Cx8m1YzL.cjs +0 -49
- package/dist/chunks/Cx8m1YzL.cjs.map +0 -1
- package/dist/chunks/D-WqCFul.js.map +0 -1
- package/dist/chunks/D8Tsm7xC.cjs +0 -95
- package/dist/chunks/D8Tsm7xC.cjs.map +0 -1
- package/dist/chunks/r8pYO6Hx.d.ts +0 -38
- package/dist/chunks/xRZPkxch.cjs.map +0 -1
- package/dist/fetch.cjs +0 -8
- package/dist/fetch.cjs.map +0 -1
- package/dist/fetch.d.ts +0 -16
- package/dist/fetch.js +0 -9
- package/dist/fetch.js.map +0 -1
@@ -1,185 +0,0 @@
|
|
1
|
-
import { Pretty, UnionMerge, Override, CollectKey, StringSplit, LooseDeep } from '@unshared/types';
|
2
|
-
import { H as HttpHeader } from './8BFCFxqa.js';
|
3
|
-
|
4
|
-
declare namespace OpenAPIV2 {
|
5
|
-
type ServerUrl<T> = T extends {
|
6
|
-
host: infer Host extends string;
|
7
|
-
basePath?: infer BasePath extends string;
|
8
|
-
schemes?: Array<infer Scheme extends string>;
|
9
|
-
} ? `${Scheme}://${Host}${BasePath}` : string;
|
10
|
-
/*************************************************************************/
|
11
|
-
/*************************************************************************/
|
12
|
-
type InferSchemaObject<T> = T extends {
|
13
|
-
properties: infer P extends Record<string, any>;
|
14
|
-
required: Array<infer R extends string>;
|
15
|
-
} ? ({
|
16
|
-
[K in keyof P as K extends R ? K : never]: InferSchema<P[K]>;
|
17
|
-
} & {
|
18
|
-
[K in keyof P as K extends R ? never : K]?: InferSchema<P[K]>;
|
19
|
-
}) : T extends {
|
20
|
-
properties: infer P extends Record<string, any>;
|
21
|
-
} ? {
|
22
|
-
[K in keyof P]?: InferSchema<P[K]>;
|
23
|
-
} : Record<string, unknown>;
|
24
|
-
type InferSchemaArray<T> = T extends {
|
25
|
-
items?: infer U;
|
26
|
-
additionalItems?: infer U;
|
27
|
-
} ? Array<InferSchema<U>> : unknown[];
|
28
|
-
type InferSchema<T> = Pretty<(T extends {
|
29
|
-
anyOf: Array<infer U>;
|
30
|
-
} ? InferSchema<U> : T extends {
|
31
|
-
oneOf: Array<infer U>;
|
32
|
-
} ? InferSchema<U> : T extends {
|
33
|
-
allOf: Array<infer U>;
|
34
|
-
} ? UnionMerge<InferSchema<U>> : T extends {
|
35
|
-
schema: infer U;
|
36
|
-
} ? InferSchema<U> : T extends {
|
37
|
-
type: 'array';
|
38
|
-
} ? InferSchemaArray<T> : T extends {
|
39
|
-
type: 'object';
|
40
|
-
} ? InferSchemaObject<T> : T extends {
|
41
|
-
type: 'string';
|
42
|
-
} ? T extends {
|
43
|
-
enum: Array<infer U>;
|
44
|
-
} ? U : string : T extends {
|
45
|
-
type: 'integer' | 'number';
|
46
|
-
} ? number : T extends {
|
47
|
-
type: 'boolean';
|
48
|
-
} ? boolean : never) | (T extends {
|
49
|
-
nullable: true;
|
50
|
-
} ? undefined : never)>;
|
51
|
-
/*************************************************************************/
|
52
|
-
/*************************************************************************/
|
53
|
-
type Parameters<T, I extends string> = UnionMerge<T extends {
|
54
|
-
parameters: Array<infer U>;
|
55
|
-
} ? U extends {
|
56
|
-
in: I;
|
57
|
-
name: infer N extends string;
|
58
|
-
} ? Record<N, InferSchema<U> | (U extends {
|
59
|
-
required: true;
|
60
|
-
} ? never : undefined)> : never : never>;
|
61
|
-
type RequestBody<T> = Parameters<T, 'body'> extends Record<string, infer U> ? U : never;
|
62
|
-
type RequestHeaders<T> = UnionMerge<Parameters<T, 'header'> | Partial<Record<HttpHeader, string | undefined>> | (T extends {
|
63
|
-
consumes: Array<infer C>;
|
64
|
-
} ? {
|
65
|
-
'Content-Type'?: C;
|
66
|
-
} : never)>;
|
67
|
-
type RequestData<T> = Pretty<Parameters<T, 'path'> & Parameters<T, 'query'> & RequestBody<T>>;
|
68
|
-
type RequestInit<T, U> = Pretty<Override<globalThis.RequestInit, {
|
69
|
-
baseUrl?: ServerUrl<T>;
|
70
|
-
body?: RequestBody<U>;
|
71
|
-
query?: Parameters<U, 'query'>;
|
72
|
-
headers?: RequestHeaders<U>;
|
73
|
-
parameters?: Parameters<U, 'path'>;
|
74
|
-
data?: RequestData<U>;
|
75
|
-
}>>;
|
76
|
-
/*************************************************************************/
|
77
|
-
/*************************************************************************/
|
78
|
-
type ResponseBody<T> = T extends {
|
79
|
-
responses: Record<200, {
|
80
|
-
schema: infer S;
|
81
|
-
}>;
|
82
|
-
} ? InferSchema<S> : never;
|
83
|
-
type Response<T> = T extends {
|
84
|
-
responses: infer R;
|
85
|
-
} ? ({
|
86
|
-
[P in keyof R]: Override<globalThis.Response, {
|
87
|
-
status: P extends 'default' ? number : P;
|
88
|
-
json: InferSchema<R[P]> extends infer V ? [never] extends V ? never : () => Promise<V> : never;
|
89
|
-
}>;
|
90
|
-
}) extends infer Result ? Result[keyof Result] : never : never;
|
91
|
-
/*************************************************************************/
|
92
|
-
/*************************************************************************/
|
93
|
-
type OperationId<T> = T extends {
|
94
|
-
paths: infer P;
|
95
|
-
} ? P extends Record<string, infer R> ? R extends Record<string, infer O> ? O extends {
|
96
|
-
operationId: infer N;
|
97
|
-
} ? N : string : string : string : string;
|
98
|
-
type Route<T> = T extends {
|
99
|
-
paths: infer P;
|
100
|
-
} ? CollectKey<P> extends Record<string, infer R> ? CollectKey<R> extends Record<string, infer O> ? O extends {
|
101
|
-
$key: [infer P extends string, infer M extends string];
|
102
|
-
} ? `${Uppercase<M>} ${P}` : string : string : string : string;
|
103
|
-
type OperationById<T, U extends OperationId<T>> = T extends {
|
104
|
-
paths: infer P;
|
105
|
-
} ? CollectKey<P> extends Record<string, infer R> ? CollectKey<R> extends Record<string, infer O> ? O extends {
|
106
|
-
$key: [infer P extends string, infer M extends string];
|
107
|
-
operationId: U;
|
108
|
-
} ? Pretty<{
|
109
|
-
method: M;
|
110
|
-
path: P;
|
111
|
-
} & Omit<O, '$key'>> : never : never : never : never;
|
112
|
-
type OperationByRoute<T, U extends Route<T>> = StringSplit<U, ' '> extends [infer M extends string, infer P extends string] ? T extends {
|
113
|
-
paths: infer U;
|
114
|
-
} ? U extends Record<P, infer R> ? R extends Record<Lowercase<M>, infer O> ? Pretty<{
|
115
|
-
method: Lowercase<M>;
|
116
|
-
path: P;
|
117
|
-
} & O> : never : never : never : never;
|
118
|
-
}
|
119
|
-
|
120
|
-
declare namespace OpenAPIV3 {
|
121
|
-
type ServerUrl<T> = T extends {
|
122
|
-
servers: Array<{
|
123
|
-
url: infer U extends string;
|
124
|
-
}>;
|
125
|
-
} ? U : string;
|
126
|
-
type ServerHeaders<T> = T extends {
|
127
|
-
servers: Array<{
|
128
|
-
variables: infer V;
|
129
|
-
}>;
|
130
|
-
} ? V extends {
|
131
|
-
[K in keyof V]: {
|
132
|
-
enum: Array<infer U>;
|
133
|
-
};
|
134
|
-
} ? {
|
135
|
-
[K in keyof V]: U;
|
136
|
-
} : never : never;
|
137
|
-
type ServerQuery<T> = T extends {
|
138
|
-
components: {
|
139
|
-
securitySchemes: {
|
140
|
-
api_key: {
|
141
|
-
in: 'query';
|
142
|
-
name: infer U extends string;
|
143
|
-
};
|
144
|
-
};
|
145
|
-
};
|
146
|
-
} ? Partial<Record<U, string>> : never;
|
147
|
-
/*************************************************************************/
|
148
|
-
/*************************************************************************/
|
149
|
-
type RequestBody<T> = T extends {
|
150
|
-
requestBody: {
|
151
|
-
content: infer C;
|
152
|
-
};
|
153
|
-
} ? C extends Record<string, {
|
154
|
-
schema: infer S;
|
155
|
-
}> ? OpenAPIV2.InferSchema<S> : object : object;
|
156
|
-
type RequestData<T, U> = Pretty<OpenAPIV2.Parameters<U, 'path'> & OpenAPIV2.Parameters<U, 'query'> & RequestBody<U> & ServerQuery<T>>;
|
157
|
-
type RequestInit<T, U> = Pretty<Override<globalThis.RequestInit, {
|
158
|
-
body?: RequestBody<U>;
|
159
|
-
query?: OpenAPIV2.Parameters<U, 'query'> & ServerQuery<T>;
|
160
|
-
headers?: OpenAPIV2.RequestHeaders<U>;
|
161
|
-
parameters?: OpenAPIV2.Parameters<U, 'path'>;
|
162
|
-
data?: LooseDeep<RequestData<T, U>>;
|
163
|
-
}>>;
|
164
|
-
/*************************************************************************/
|
165
|
-
/*************************************************************************/
|
166
|
-
type ResponseBody<U> = U extends {
|
167
|
-
responses: Record<200, {
|
168
|
-
content: Record<string, {
|
169
|
-
schema: infer Schema;
|
170
|
-
}>;
|
171
|
-
}>;
|
172
|
-
} ? OpenAPIV2.InferSchema<Schema> : never;
|
173
|
-
type Response<U> = U extends {
|
174
|
-
responses: infer Responses;
|
175
|
-
} ? ({
|
176
|
-
[Status in keyof Responses]: Responses[Status] extends {
|
177
|
-
content: Record<'application/json', infer Schema>;
|
178
|
-
} ? Pretty<Override<globalThis.Response, {
|
179
|
-
status: Status;
|
180
|
-
json: OpenAPIV2.InferSchema<Schema> extends infer V ? [never] extends V ? never : () => Promise<V> : never;
|
181
|
-
}>> : never;
|
182
|
-
}) extends infer Result ? Result[keyof Result] : never : never;
|
183
|
-
}
|
184
|
-
|
185
|
-
export { OpenAPIV2 as O, OpenAPIV3 as a };
|
package/dist/chunks/B5hc73Po.js
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
function isFormDataLike(value) {
|
2
|
-
if (typeof value != "object" || value === null) return !1;
|
3
|
-
if (value instanceof FormData) return !0;
|
4
|
-
const values = Object.values(value);
|
5
|
-
return values.length === 0 ? !1 : values.every((x) => x instanceof File ? !0 : Array.isArray(x) ? x.every((item) => item instanceof File) : x instanceof Blob);
|
6
|
-
}
|
7
|
-
function isObjectLike(value) {
|
8
|
-
return typeof value == "object" && value !== null && value.constructor === Object;
|
9
|
-
}
|
10
|
-
function toFormData(object) {
|
11
|
-
if (object instanceof FormData) return object;
|
12
|
-
const formData = new FormData();
|
13
|
-
for (const key in object) {
|
14
|
-
const value = object[key];
|
15
|
-
if (value !== void 0)
|
16
|
-
if (Array.isArray(value))
|
17
|
-
for (const item of value)
|
18
|
-
formData.append(key, item);
|
19
|
-
else
|
20
|
-
formData.append(key, value);
|
21
|
-
}
|
22
|
-
return formData;
|
23
|
-
}
|
24
|
-
function parseRequestBody(route, options, context) {
|
25
|
-
const { data, body = data } = options, { init } = context;
|
26
|
-
["get", "head", "delete"].includes(init.method ?? "get") || body != null && (isFormDataLike(body) ? (init.body = toFormData(body), init.headers = init.headers ?? {}, init.headers = { ...init.headers, "Content-Type": "multipart/form-data" }) : body instanceof ReadableStream ? init.body = body : body instanceof File ? (init.body = body.stream(), init.headers = init.headers ?? {}, init.headers = { ...init.headers, "Content-Type": "application/octet-stream" }) : isObjectLike(body) ? (init.body = JSON.stringify(body), init.headers = init.headers ?? {}, init.headers = { ...init.headers, "Content-Type": "application/json" }) : init.body = body);
|
27
|
-
}
|
28
|
-
function parseRequestHeaders(route, options, context) {
|
29
|
-
const { headers = {} } = options, { init } = context;
|
30
|
-
for (const key in headers) {
|
31
|
-
const value = headers[key];
|
32
|
-
value !== void 0 && typeof value == "string" && (init.headers = init.headers ?? {}, init.headers = { ...init.headers, [key]: value });
|
33
|
-
}
|
34
|
-
}
|
35
|
-
const EXP_PATH_PARAMETER = /:([\w-]+)|%7B([\w-]+)%7D/g;
|
36
|
-
function parseRequestParameters(route, options, context) {
|
37
|
-
const { url } = context, { data, parameters = {} } = options;
|
38
|
-
if (!url) throw new Error("Could not resolve the `RequestInit` object: the `url` is missing.");
|
39
|
-
const pathParameters = url.pathname.match(EXP_PATH_PARAMETER);
|
40
|
-
if (pathParameters)
|
41
|
-
for (const parameter of pathParameters.values()) {
|
42
|
-
const key = parameter.replaceAll(EXP_PATH_PARAMETER, "$1$2"), value = parameters[key];
|
43
|
-
value !== void 0 && typeof value == "string" ? url.pathname = url.pathname.replace(parameter, value) : isObjectLike(data) && data[key] !== void 0 && typeof data[key] == "string" && (url.pathname = url.pathname.replace(parameter, data[key]), delete data[key]);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
function toSearchParams(object, options = {}) {
|
47
|
-
const { searchArrayFormat = "flat" } = options, search = new URLSearchParams();
|
48
|
-
for (const key in object) {
|
49
|
-
const value = object[key];
|
50
|
-
if (value !== void 0)
|
51
|
-
if (Array.isArray(value)) {
|
52
|
-
if (searchArrayFormat === "brackets") for (const v of value) search.append(`${key}[]`, String(v));
|
53
|
-
else if (searchArrayFormat === "indices") for (const [i, v] of value.entries()) search.append(`${key}[${i}]`, String(v));
|
54
|
-
else if (searchArrayFormat === "comma") search.append(key, value.join(","));
|
55
|
-
else if (searchArrayFormat === "path") for (const [i, v] of value.entries()) search.append(`${key}.${i}`, String(v));
|
56
|
-
else if (searchArrayFormat === "flat") for (const v of value) search.append(key, String(v));
|
57
|
-
} else
|
58
|
-
search.append(key, value.toString());
|
59
|
-
}
|
60
|
-
return search;
|
61
|
-
}
|
62
|
-
function parseRequestQuery(route, options, context) {
|
63
|
-
const { url, init } = context, { data, query = {}, searchArrayFormat } = options;
|
64
|
-
if (!url) throw new Error("Could not resolve the `RequestInit` object: the `url` is missing.");
|
65
|
-
if (!["post", "put", "patch"].includes(init.method ?? "get") && isObjectLike(data))
|
66
|
-
for (const key in data)
|
67
|
-
data[key] !== void 0 && query[key] === void 0 && (query[key] = data[key], delete data[key]);
|
68
|
-
url.search = toSearchParams(query, { searchArrayFormat }).toString();
|
69
|
-
}
|
70
|
-
const EXP_REQUEST = /^((?<method>[a-z]+) )?(?<url>[^:]+?:\/{2}[^/]+)?(?<path>\/[^\s?]*)/i, METHODS = /* @__PURE__ */ new Set(["get", "post", "put", "patch", "delete", "head", "options"]);
|
71
|
-
function parseRequestUrl(route, options, context) {
|
72
|
-
const { method, baseUrl } = options, match = EXP_REQUEST.exec(route);
|
73
|
-
if (!match?.groups) throw new Error("Could not resolve the `RequestInit` object: Invalid route name.");
|
74
|
-
const routeMethod = method ?? match.groups.method ?? "get", routeBaseUrl = baseUrl ?? match.groups.url;
|
75
|
-
if (!routeBaseUrl) throw new Error("Could not resolve the `RequestInit` object: the `baseUrl` is missing.");
|
76
|
-
const methodLower = routeMethod.toLowerCase();
|
77
|
-
if (!METHODS.has(methodLower)) throw new Error(`Could not resolve the \`RequestInit\` object:, the method \`${routeMethod}\` is invalid.`);
|
78
|
-
context.init = context.init ?? {}, context.init.method = methodLower, context.url = new URL(routeBaseUrl), context.url.pathname += context.url.pathname.endsWith("/") ? match.groups.path.slice(1) : match.groups.path;
|
79
|
-
}
|
80
|
-
function parseRequest(route, options) {
|
81
|
-
const { data, body, query, headers, parameters, baseUrl, method, searchArrayFormat, ...requestInit } = options, context = { init: requestInit };
|
82
|
-
return parseRequestUrl(route, { baseUrl, method }, context), parseRequestParameters(route, { data, parameters }, context), parseRequestQuery(route, { data, query, searchArrayFormat }, context), parseRequestBody(route, { data, body }, context), parseRequestHeaders(route, { headers }, context), context;
|
83
|
-
}
|
84
|
-
export {
|
85
|
-
isObjectLike as a,
|
86
|
-
parseRequestBody as b,
|
87
|
-
parseRequestHeaders as c,
|
88
|
-
parseRequestParameters as d,
|
89
|
-
parseRequestQuery as e,
|
90
|
-
parseRequestUrl as f,
|
91
|
-
toSearchParams as g,
|
92
|
-
isFormDataLike as i,
|
93
|
-
parseRequest as p,
|
94
|
-
toFormData as t
|
95
|
-
};
|
96
|
-
//# sourceMappingURL=B5hc73Po.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"B5hc73Po.js","sources":["../../utils/isFormDataLike.ts","../../utils/isObjectLike.ts","../../utils/toFormData.ts","../../utils/parseRequestBody.ts","../../utils/parseRequestHeaders.ts","../../utils/parseRequestParameters.ts","../../utils/toSearchParams.ts","../../utils/parseRequestQuery.ts","../../utils/parseRequestUrl.ts","../../utils/parseRequest.ts"],"sourcesContent":["/**\n * A type that represents a FormData-like object, which is a plain object with\n * nested Blob, File, or FileList values. Or a FormData instance.\n */\nexport type FormDataLike = FormData | Record<string, Blob | File | FileList>\n\n/**\n * Predicate to check if a value is FormData-like, meaning it is a plain object\n * with nested Blob, File, or FileList values.\n *\n * @param value The value to check.\n * @returns `true` if the value is FormData-like, `false` otherwise.\n * @example isFormDataLike({ file: new File(['test'], 'test.txt') }) // true\n */\nexport function isFormDataLike(value: unknown): value is FormDataLike {\n if (typeof value !== 'object' || value === null) return false\n if (value instanceof FormData) return true\n const values = Object.values(value)\n if (values.length === 0) return false\n return values.every((x) => {\n if (x instanceof File) return true\n if (Array.isArray(x)) return x.every(item => item instanceof File)\n return x instanceof Blob\n })\n}\n","/**\n * Predicate to check if a value is an object-like value.\n *\n * @param value The value to check.\n * @returns `true` if the value is an object-like value, `false` otherwise.\n * @example isObjectLike({}) // true\n */\nexport function isObjectLike(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && value.constructor === Object\n}\n","import type { FormDataLike } from './isFormDataLike'\n\n/**\n * Casts an object that may contain `Blob`, `File`, or `FileList` values to a `FormData` object.\n *\n * @param object The object to cast to a `FormData` object.\n * @returns The `FormData` object.\n */\nexport function toFormData(object: FormDataLike): FormData {\n if (object instanceof FormData) return object\n const formData = new FormData()\n for (const key in object) {\n const value = object[key]\n if (value === undefined) continue\n if (Array.isArray(value)) {\n for (const item of value)\n formData.append(key, item as Blob | string)\n }\n else {\n formData.append(key, value as Blob | string)\n }\n }\n return formData\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\nimport { isFormDataLike } from './isFormDataLike'\nimport { isObjectLike } from './isObjectLike'\nimport { toFormData } from './toFormData'\n\n/**\n * Parse the request body based on the provided data and options.\n *\n * @param route The route path.\n * @param options The request options.\n * @param context The request context.\n */\nexport function parseRequestBody(route: string, options: Pick<RequestOptions, 'body' | 'data'>, context: RequestContext): void {\n const { data, body = data } = options\n const { init } = context\n\n // --- If the method is `GET`, `HEAD`, or `DELETE`, return early.\n if (['get', 'head', 'delete'].includes(init.method ?? 'get')) return\n\n // --- If no data is provided, return early.\n if (body === null || body === undefined) return\n\n // --- If data contains a `File` object, create a FormData object.\n if (isFormDataLike(body)) {\n init.body = toFormData(body)\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, 'Content-Type': 'multipart/form-data' }\n }\n\n // --- If the data is a `ReadableStream`, pass it directly to the body.\n else if (body instanceof ReadableStream) {\n init.body = body\n }\n\n // --- If the data is a Blob, pass it directly to the body.\n else if (body instanceof File) {\n init.body = body.stream()\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, 'Content-Type': 'application/octet-stream' }\n }\n\n // --- Otherwise, stringify the data and set the content type to JSON.\n else if (isObjectLike(body)) {\n init.body = JSON.stringify(body)\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, 'Content-Type': 'application/json' }\n }\n\n // --- For all other data types, set the body directly.\n else {\n init.body = body\n }\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\n\n/**\n * Parse the request headers based on the provided data and options.\n *\n * @param route The route path.\n * @param options The request options.\n * @param context The request context.\n */\nexport function parseRequestHeaders(route: string, options: Pick<RequestOptions, 'headers'>, context: RequestContext): void {\n const { headers = {} } = options\n const { init } = context\n\n // --- Merge the headers with the existing headers.\n for (const key in headers) {\n const value = headers[key]\n if (value === undefined) continue\n if (typeof value !== 'string') continue\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, [key]: value }\n }\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\nimport { isObjectLike } from './isObjectLike'\n\n/** Regular expression to match path parameters in the URL. */\nconst EXP_PATH_PARAMETER = /:([\\w-]+)|%7B([\\w-]+)%7D/g\n\n/**\n * Parse the request parameters from the request data. This function will append\n * the path parameters to the URL based on the method and the data provided.\n *\n * @param route The name of the route to fetch. (ignored)\n * @param options The options to pass to the request.\n * @param context The request context to modify.\n * @example\n * // Using `express` style path parameters.\n * parseRequestParameters('GET /users/:id', { data: { id: 1 } }, context)\n *\n * // Using `OpenAPI` style path parameters.\n * parseRequestParameters('GET /users/{id}', { data: { id: 1 } }, context)\n */\nexport function parseRequestParameters(route: string, options: Pick<RequestOptions, 'data' | 'parameters'>, context: RequestContext): void {\n const { url } = context\n const { data, parameters = {} } = options\n\n // --- If the method has a parameter, fill the path with the data.\n if (!url) throw new Error('Could not resolve the `RequestInit` object: the `url` is missing.')\n const pathParameters = url.pathname.match(EXP_PATH_PARAMETER)\n if (!pathParameters) return\n\n // --- Apply the path parameters to the URL.\n for (const parameter of pathParameters.values()) {\n const key = parameter.replaceAll(EXP_PATH_PARAMETER, '$1$2')\n\n // --- If the parameter is provided, replace the path with the value.\n const value = parameters[key]\n if (value !== undefined && typeof value === 'string') {\n url.pathname = url.pathname.replace(parameter, value)\n }\n\n // --- If the data contains the parameter, use it and remove it from the data.\n else if (isObjectLike(data) && data[key] !== undefined && typeof data[key] === 'string') {\n url.pathname = url.pathname.replace(parameter, data[key])\n delete data[key]\n }\n }\n}\n","/* eslint-disable unicorn/prevent-abbreviations */\nimport type { MaybeArray } from '@unshared/types'\n\n/** An object that can be converted to a query string. */\nexport type SearchParamsObject = Record<string, MaybeArray<boolean | number | string> | undefined>\n\n/** The search array format options. */\nexport type SearchArrayFormat = 'brackets' | 'comma' | 'flat' | 'indices' | 'path'\n\n/** Options for the query string conversion. */\nexport interface ToSearchParamsOptions {\n\n /**\n * Defines how to handle arrays in the object. There is no standard way to\n * represent arrays in query strings, so this option allows you to choose\n * how to handle them. Additionally, you can provide a custom function to\n * handle it yourself.\n *\n * - `brackets` (default): Convert arrays to `key[]=value&key[]=value` format.\n * - `indices`: Convert arrays to `key[0]=value&key[1]=value` format.\n * - `comma`: Convert arrays to `key=value1,value2` format.\n * - `path`: Convert arrays to `key.0=value&key.1=value` format.\n * - `flat`: Convert arrays to `key=value1&key=value2` format.\n *\n * @default 'flat'\n */\n searchArrayFormat?: SearchArrayFormat\n}\n\n/**\n * Convert object to query string parameters. Converting all values to strings\n * and arrays to `key[0]=value&key[1]=value` format.\n *\n * @param object The object to convert to a query string.\n * @param options The query string options.\n * @returns The `URLSearchParams` object.\n */\nexport function toSearchParams(object: SearchParamsObject, options: ToSearchParamsOptions = {}): URLSearchParams {\n const { searchArrayFormat = 'flat' } = options\n const search = new URLSearchParams()\n for (const key in object) {\n const value = object[key]\n if (value === undefined) continue\n\n // --- Convert arrays based on the format.\n if (Array.isArray(value)) {\n if (searchArrayFormat === 'brackets') for (const v of value) search.append(`${key}[]`, String(v))\n else if (searchArrayFormat === 'indices') for (const [i, v] of value.entries()) search.append(`${key}[${i}]`, String(v))\n else if (searchArrayFormat === 'comma') search.append(key, value.join(','))\n else if (searchArrayFormat === 'path') for (const [i, v] of value.entries()) search.append(`${key}.${i}`, String(v))\n else if (searchArrayFormat === 'flat') for (const v of value) search.append(key, String(v))\n }\n\n // --- Convert all values to strings.\n else { search.append(key, value.toString()) }\n }\n\n // --- Return the query string.\n return search\n}\n","/* eslint-disable unicorn/prevent-abbreviations */\nimport type { RequestContext, RequestOptions } from './parseRequest'\nimport { isObjectLike } from './isObjectLike'\nimport { toSearchParams } from './toSearchParams'\n\n/**\n * Parse the query parameters from the request data. This function will append\n * the query parameters to the URL based on the method and the data provided.\n *\n * @param route The name of the route to fetch. (ignored)\n * @param options The options to pass to the request.\n * @param context The request context to modify.\n */\nexport function parseRequestQuery(route: string, options: Pick<RequestOptions, 'data' | 'query' | 'searchArrayFormat'>, context: RequestContext): void {\n const { url, init } = context\n const { data, query = {}, searchArrayFormat } = options\n if (!url) throw new Error('Could not resolve the `RequestInit` object: the `url` is missing.')\n\n // --- Append the `data` to the query parameters if the method does not expect a body.\n const isExpectingBody = ['post', 'put', 'patch'].includes(init.method ?? 'get')\n if (!isExpectingBody && isObjectLike(data)) {\n for (const key in data) {\n if (data[key] === undefined) continue\n if (query[key] !== undefined) continue\n // @ts-expect-error: Ignore type mismatch.\n query[key] = data[key]\n delete data[key]\n }\n }\n\n // --- Apply the query parameters to the URL.\n url.search = toSearchParams(query, { searchArrayFormat }).toString()\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\n\n/** Regular expression to match the request method and URL. */\nconst EXP_REQUEST = /^((?<method>[a-z]+) )?(?<url>[^:]+?:\\/{2}[^/]+)?(?<path>\\/[^\\s?]*)/i\n\n/** Valid HTTP methods. */\nconst METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'options'])\n\n/**\n * Parses the route name to extract the URL and method. It allows the url and method to be\n * provided in the route name, or in the options object. The method will default to 'get'.\n *\n * @param route The name of the route to fetch.\n * @param options The options to pass to the request.\n * @param context The request context to modify.\n * @example parseRequestUrl('GET /users', { baseUrl: 'https://api.example.com' }, context)\n */\nexport function parseRequestUrl(route: string, options: Pick<RequestOptions, 'baseUrl' | 'method'>, context: RequestContext): void {\n const { method, baseUrl } = options\n\n // --- Extract the path, method, and base URL from the route name.\n const match = EXP_REQUEST.exec(route)\n if (!match?.groups) throw new Error('Could not resolve the `RequestInit` object: Invalid route name.')\n const routeMethod = method ?? match.groups.method ?? 'get'\n const routeBaseUrl = baseUrl ?? match.groups.url\n\n // --- Assert the base URL is provided, either in the options or the route name.\n if (!routeBaseUrl) throw new Error('Could not resolve the `RequestInit` object: the `baseUrl` is missing.')\n\n // --- Assert the method is valid.\n const methodLower = routeMethod.toLowerCase()\n const methodIsValid = METHODS.has(methodLower)\n if (!methodIsValid) throw new Error(`Could not resolve the \\`RequestInit\\` object:, the method \\`${routeMethod}\\` is invalid.`)\n\n // --- Create the url and apply the method.\n context.init = context.init ?? {}\n context.init.method = methodLower\n context.url = new URL(routeBaseUrl)\n\n // --- Append the path to the URL while making sure there are no double slashes.\n context.url.pathname += context.url.pathname.endsWith('/') ? match.groups.path.slice(1) : match.groups.path\n}\n","/* eslint-disable unicorn/prevent-abbreviations */\nimport type { MaybeLiteral } from '@unshared/types'\nimport type { Override } from '@unshared/types'\nimport type { HttpHeader, HttpMethod } from '../types'\nimport type { SearchArrayFormat, SearchParamsObject } from './toSearchParams'\nimport { parseRequestBody } from './parseRequestBody'\nimport { parseRequestHeaders } from './parseRequestHeaders'\nimport { parseRequestParameters } from './parseRequestParameters'\nimport { parseRequestQuery } from './parseRequestQuery'\nimport { parseRequestUrl } from './parseRequestUrl'\n\n/** The methods to use for the request. */\nexport type RequestMethod = Lowercase<keyof typeof HttpMethod> | Uppercase<keyof typeof HttpMethod>\n\n/** Headers to include in the request. */\nexport type RequestHeaders = Partial<Record<MaybeLiteral<HttpHeader>, string>>\n\n/** The types of data that can be passed to the request. */\nexport type RequestBody = File | FormData | ReadableStream | Record<string, unknown> | string\n\n/** Options to pass to the request. */\nexport type RequestOptions = Override<RequestInit, {\n\n /**\n * The method to use for the request.\n *\n * @example 'GET'\n */\n method?: RequestMethod\n\n /**\n * The base URL to use for the request. This URL will be used to resolve the\n * path and query parameters of the request.\n *\n * @example 'https://api.example.com'\n */\n baseUrl?: string\n\n /**\n * The data to pass to the request. This data will be used to fill the path\n * parameters, query parameters, body, and form data of the request based on\n * the route method.\n */\n data?: RequestBody\n\n /**\n * The body to include in the request.\n */\n body?: RequestBody\n\n /**\n * The headers to include in the request.\n */\n headers?: RequestHeaders\n\n /**\n * Query parameters to include in the request.\n */\n query?: SearchParamsObject\n\n /**\n * The format to use when serializing the query parameters.\n */\n searchArrayFormat?: SearchArrayFormat\n\n /**\n * The path parameters to include in the request.\n */\n parameters?: Record<string, number | string>\n}>\n\nexport interface RequestContext {\n url?: URL\n init: RequestInit\n}\n\n/**\n * Resolves the request body and/or query parameters based on the method type. This function\n * will mutate the `init` object to include the request body and headers based on the data type.\n *\n * @param route The name of the route to fetch.\n * @param options The options to pass to the request.\n * @returns The URL and the `RequestInit` object.\n */\nexport function parseRequest(route: string, options: RequestOptions): RequestContext {\n const { data, body, query, headers, parameters, baseUrl, method, searchArrayFormat, ...requestInit } = options\n const context: RequestContext = { init: requestInit }\n parseRequestUrl(route, { baseUrl, method }, context)\n parseRequestParameters(route, { data, parameters }, context)\n parseRequestQuery(route, { data, query, searchArrayFormat }, context)\n parseRequestBody(route, { data, body }, context)\n parseRequestHeaders(route, { headers }, context)\n return context\n}\n"],"names":[],"mappings":"AAcO,SAAS,eAAe,OAAuC;AACpE,MAAI,OAAO,SAAU,YAAY,UAAU,KAAa,QAAA;AACpD,MAAA,iBAAiB,SAAiB,QAAA;AAChC,QAAA,SAAS,OAAO,OAAO,KAAK;AAC9B,SAAA,OAAO,WAAW,IAAU,KACzB,OAAO,MAAM,CAAC,MACf,aAAa,OAAa,KAC1B,MAAM,QAAQ,CAAC,IAAU,EAAE,MAAM,UAAQ,gBAAgB,IAAI,IAC1D,aAAa,IACrB;AACH;ACjBO,SAAS,aAAa,OAAkD;AAC7E,SAAO,OAAO,SAAU,YAAY,UAAU,QAAQ,MAAM,gBAAgB;AAC9E;ACDO,SAAS,WAAW,QAAgC;AACrD,MAAA,kBAAkB,SAAiB,QAAA;AACjC,QAAA,WAAW,IAAI,SAAS;AAC9B,aAAW,OAAO,QAAQ;AAClB,UAAA,QAAQ,OAAO,GAAG;AACxB,QAAI,UAAU;AACV,UAAA,MAAM,QAAQ,KAAK;AACrB,mBAAW,QAAQ;AACR,mBAAA,OAAO,KAAK,IAAqB;AAAA;AAGnC,iBAAA,OAAO,KAAK,KAAsB;AAAA,EAAA;AAGxC,SAAA;AACT;ACXgB,SAAA,iBAAiB,OAAe,SAAgD,SAA+B;AACvH,QAAA,EAAE,MAAM,OAAO,SAAS,SACxB,EAAE,SAAS;AAGb,GAAC,OAAO,QAAQ,QAAQ,EAAE,SAAS,KAAK,UAA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O,EAAE,MAAM,OAAO,qBAAqB,OAAO,GACpE,iBAAiB,OAAO,EAAE,MAAM,KAAQ,GAAA,OAAO,GAC/C,oBAAoB,OAAO,EAAE,QAAQ,GAAG,OAAO,GACxC;AACT;"}
|
package/dist/chunks/CKfJvIQ8.js
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
import { awaitable } from "@unshared/functions/awaitable";
|
2
|
-
async function* createResponseStreamJsonIterator(response, options) {
|
3
|
-
const { onError, onSuccess, onData, onEnd } = options;
|
4
|
-
try {
|
5
|
-
const body = response.body;
|
6
|
-
if (body === null) throw new Error("Could not read the response body, it is empty.");
|
7
|
-
const reader = body.getReader();
|
8
|
-
for (; ; ) {
|
9
|
-
const { done, value } = await reader.read();
|
10
|
-
if (done) break;
|
11
|
-
const parts = new TextDecoder().decode(value).trim().split("\0").filter(Boolean);
|
12
|
-
for (const part of parts) {
|
13
|
-
const payload = JSON.parse(part);
|
14
|
-
onData && onData(payload), yield payload;
|
15
|
-
}
|
16
|
-
}
|
17
|
-
onSuccess && onSuccess(response);
|
18
|
-
} catch (error) {
|
19
|
-
onError && onError(error);
|
20
|
-
} finally {
|
21
|
-
onEnd && onEnd(response);
|
22
|
-
}
|
23
|
-
}
|
24
|
-
function handleResponseStreamJson(response, options) {
|
25
|
-
const responseIterator = createResponseStreamJsonIterator(response, options);
|
26
|
-
return awaitable(responseIterator);
|
27
|
-
}
|
28
|
-
async function handleResponse(response, options) {
|
29
|
-
const { onError, onSuccess, onData, onEnd, onFailure } = options, contentType = response.headers.get("Content-Type");
|
30
|
-
if (!response.ok)
|
31
|
-
throw onFailure && onFailure(response), onEnd && onEnd(response), new Error(response.statusText);
|
32
|
-
if (response.status === 204) {
|
33
|
-
onSuccess && onSuccess(response), onEnd && onEnd(response);
|
34
|
-
return;
|
35
|
-
}
|
36
|
-
return contentType?.startsWith("text/") ? await response.text().then((data) => (onData && onData(data), onSuccess && onSuccess(response), data)).catch((error) => {
|
37
|
-
throw onError && onError(error), error;
|
38
|
-
}).finally(() => {
|
39
|
-
onEnd && onEnd(response);
|
40
|
-
}) : contentType === "application/json" ? await response.json().then((data) => (onData && onData(data), onSuccess && onSuccess(response), data)).catch((error) => {
|
41
|
-
throw onError && onError(error), error;
|
42
|
-
}).finally(() => {
|
43
|
-
onEnd && onEnd(response);
|
44
|
-
}) : contentType === "application/stream+json" ? handleResponseStreamJson(response, options) : (onSuccess && onSuccess(response), onEnd && onEnd(response), response.body);
|
45
|
-
}
|
46
|
-
export {
|
47
|
-
handleResponseStreamJson as a,
|
48
|
-
handleResponse as h
|
49
|
-
};
|
50
|
-
//# sourceMappingURL=CKfJvIQ8.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"CKfJvIQ8.js","sources":["../../utils/handleResponseStreamJson.ts","../../utils/handleResponse.ts"],"sourcesContent":["import type { Awaitable } from '@unshared/functions/awaitable'\nimport type { RequestHooks } from './handleResponse'\nimport { awaitable } from '@unshared/functions/awaitable'\n\nasync function * createResponseStreamJsonIterator(response: Response, options: RequestHooks) {\n const { onError, onSuccess, onData, onEnd } = options\n try {\n const body = response.body\n if (body === null) throw new Error('Could not read the response body, it is empty.')\n const reader = body.getReader()\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n const parts = new TextDecoder().decode(value).trim().split('\\0').filter(Boolean)\n\n // --- For each part, parse as JSON and yield the data.\n for (const part of parts) {\n const payload = JSON.parse(part) as unknown\n if (onData) onData(payload)\n yield payload\n }\n }\n if (onSuccess) onSuccess(response)\n }\n catch (error) {\n if (onError) onError(error as Error)\n }\n finally {\n if (onEnd) onEnd(response)\n }\n}\n\n/**\n * Handle a request response where the content type is a stream of JSON objects. This function\n * will parse the JSON objects and yield the data to the caller. If an error occurs, the `onError`\n * callback will be called and the function will return.\n *\n * @param response The response to handle.\n * @param options The options to pass to the request.\n * @returns An awaitable iterator that yields the parsed JSON objects.\n */\nexport function handleResponseStreamJson<T>(response: Response, options: RequestHooks): Awaitable<AsyncIterable<T>, T[]> {\n const responseIterator = createResponseStreamJsonIterator(response, options)\n return awaitable(responseIterator) as Awaitable<AsyncIterable<T>, T[]>\n}\n","import { handleResponseStreamJson } from './handleResponseStreamJson'\n\nexport interface RequestHooks {\n\n /**\n * The callback that is called when an error occurs during the request.\n */\n onError?: (error: Error) => any\n\n /**\n * The callback that is called when data is received from the request. This callback\n * will be called for each chunk of data that is received from the request.\n */\n onData?: (data: unknown) => any\n\n /**\n * The callback that is called when the request is successful. This callback will be\n * called after the request is complete and all data has been received.\n */\n onSuccess?: (response: Response) => any\n\n /**\n * The callback that is called when the status code is not OK. This callback will be called\n * after the request is complete and before the data is consumed.\n */\n onFailure?: (response: Response) => any\n\n /**\n * The callback that is called when the request is complete. This callback will be called\n * after the request is complete and all data has been received.\n */\n onEnd?: (response: Response) => any\n}\n\n/**\n * Handle a request response. This function will parse the response based on the content type and\n * return the data. If an error occurs, the `onError` callback will be called and the function will\n * throw an error.\n *\n * @param response The response to handle.\n * @param options The options to pass to the request.\n * @returns The parsed data from the response.\n */\nexport async function handleResponse(response: Response, options: RequestHooks): Promise<unknown> {\n const { onError, onSuccess, onData, onEnd, onFailure } = options\n const contentType = response.headers.get('Content-Type')\n\n // --- If the response is not OK, throw an error with the response message.\n if (!response.ok) {\n if (onFailure) onFailure(response)\n if (onEnd) onEnd(response)\n throw new Error(response.statusText)\n }\n\n // --- If the status code is 204, return an empty response early.\n if (response.status === 204) {\n if (onSuccess) onSuccess(response)\n if (onEnd) onEnd(response)\n return\n }\n\n // --- If the response is a text content type, return the text response.\n if (contentType?.startsWith('text/')) {\n return await response.text()\n .then((data) => {\n if (onData) onData(data)\n if (onSuccess) onSuccess(response)\n return data\n })\n .catch((error: Error) => {\n if (onError) onError(error)\n throw error\n })\n .finally(() => {\n if (onEnd) onEnd(response)\n })\n }\n\n // --- If the response is a application/json, parse the JSON and return it.\n if (contentType === 'application/json') {\n return await response.json()\n .then((data) => {\n if (onData) onData(data)\n if (onSuccess) onSuccess(response)\n return data as unknown\n })\n .catch((error: Error) => {\n if (onError) onError(error)\n throw error\n })\n .finally(() => {\n if (onEnd) onEnd(response)\n })\n }\n\n // --- If the response is a application/stream+json, return an iterator that parses the JSON.\n if (contentType === 'application/stream+json')\n return handleResponseStreamJson(response, options)\n\n // --- Otherwise, fallback to returning the response body as-is.\n if (onSuccess) onSuccess(response)\n if (onEnd) onEnd(response)\n return response.body\n}\n"],"names":[],"mappings":";AAIA,gBAAiB,iCAAiC,UAAoB,SAAuB;AAC3F,QAAM,EAAE,SAAS,WAAW,QAAQ,MAAU,IAAA;AAC1C,MAAA;AACF,UAAM,OAAO,SAAS;AACtB,QAAI,SAAS,KAAY,OAAA,IAAI,MAAM,gDAAgD;AAC7E,UAAA,SAAS,KAAK,UAAU;AACjB,eAAA;AACX,YAAM,EAAE,MAAM,MAAU,IAAA,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,YAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,KAAK,EAAE,KAAA,EAAO,MAAM,IAAI,EAAE,OAAO,OAAO;AAG/E,iBAAW,QAAQ,OAAO;AAClB,cAAA,UAAU,KAAK,MAAM,IAAI;AAC3B,kBAAQ,OAAO,OAAO,GAC1B,MAAM;AAAA,MAAA;AAAA,IACR;AAEE,iBAAW,UAAU,QAAQ;AAAA,WAE5B,OAAO;AACR,eAAS,QAAQ,KAAc;AAAA,EAAA,UAErC;AACM,aAAO,MAAM,QAAQ;AAAA,EAAA;AAE7B;AAWgB,SAAA,yBAA4B,UAAoB,SAAyD;AACjH,QAAA,mBAAmB,iCAAiC,UAAU,OAAO;AAC3E,SAAO,UAAU,gBAAgB;AACnC;ACDsB,eAAA,eAAe,UAAoB,SAAyC;AAChG,QAAM,EAAE,SAAS,WAAW,QAAQ,OAAO,UAAA,IAAc,SACnD,cAAc,SAAS,QAAQ,IAAI,cAAc;AAGvD,MAAI,CAAC,SAAS;AACR,UAAA,aAAW,UAAU,QAAQ,GAC7B,SAAO,MAAM,QAAQ,GACnB,IAAI,MAAM,SAAS,UAAU;AAIjC,MAAA,SAAS,WAAW,KAAK;AACvB,iBAAW,UAAU,QAAQ,GAC7B,SAAO,MAAM,QAAQ;AACzB;AAAA,EAAA;AAIE,SAAA,aAAa,WAAW,OAAO,IAC1B,MAAM,SAAS,KACnB,EAAA,KAAK,CAAC,UACD,UAAQ,OAAO,IAAI,GACnB,aAAW,UAAU,QAAQ,GAC1B,KACR,EACA,MAAM,CAAC,UAAiB;AACnB,UAAA,WAAS,QAAQ,KAAK,GACpB;AAAA,EAAA,CACP,EACA,QAAQ,MAAM;AACT,aAAO,MAAM,QAAQ;AAAA,EAAA,CAC1B,IAID,gBAAgB,qBACX,MAAM,SAAS,OACnB,KAAK,CAAC,UACD,UAAQ,OAAO,IAAI,GACnB,aAAW,UAAU,QAAQ,GAC1B,KACR,EACA,MAAM,CAAC,UAAiB;AACnB,UAAA,WAAS,QAAQ,KAAK,GACpB;AAAA,EAAA,CACP,EACA,QAAQ,MAAM;AACT,aAAO,MAAM,QAAQ;AAAA,EAAA,CAC1B,IAID,gBAAgB,4BACX,yBAAyB,UAAU,OAAO,KAG/C,aAAW,UAAU,QAAQ,GAC7B,SAAO,MAAM,QAAQ,GAClB,SAAS;AAClB;"}
|
package/dist/chunks/Cx8m1YzL.cjs
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var awaitable = require("@unshared/functions/awaitable");
|
3
|
-
async function* createResponseStreamJsonIterator(response, options) {
|
4
|
-
const { onError, onSuccess, onData, onEnd } = options;
|
5
|
-
try {
|
6
|
-
const body = response.body;
|
7
|
-
if (body === null) throw new Error("Could not read the response body, it is empty.");
|
8
|
-
const reader = body.getReader();
|
9
|
-
for (; ; ) {
|
10
|
-
const { done, value } = await reader.read();
|
11
|
-
if (done) break;
|
12
|
-
const parts = new TextDecoder().decode(value).trim().split("\0").filter(Boolean);
|
13
|
-
for (const part of parts) {
|
14
|
-
const payload = JSON.parse(part);
|
15
|
-
onData && onData(payload), yield payload;
|
16
|
-
}
|
17
|
-
}
|
18
|
-
onSuccess && onSuccess(response);
|
19
|
-
} catch (error) {
|
20
|
-
onError && onError(error);
|
21
|
-
} finally {
|
22
|
-
onEnd && onEnd(response);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
function handleResponseStreamJson(response, options) {
|
26
|
-
const responseIterator = createResponseStreamJsonIterator(response, options);
|
27
|
-
return awaitable.awaitable(responseIterator);
|
28
|
-
}
|
29
|
-
async function handleResponse(response, options) {
|
30
|
-
const { onError, onSuccess, onData, onEnd, onFailure } = options, contentType = response.headers.get("Content-Type");
|
31
|
-
if (!response.ok)
|
32
|
-
throw onFailure && onFailure(response), onEnd && onEnd(response), new Error(response.statusText);
|
33
|
-
if (response.status === 204) {
|
34
|
-
onSuccess && onSuccess(response), onEnd && onEnd(response);
|
35
|
-
return;
|
36
|
-
}
|
37
|
-
return contentType?.startsWith("text/") ? await response.text().then((data) => (onData && onData(data), onSuccess && onSuccess(response), data)).catch((error) => {
|
38
|
-
throw onError && onError(error), error;
|
39
|
-
}).finally(() => {
|
40
|
-
onEnd && onEnd(response);
|
41
|
-
}) : contentType === "application/json" ? await response.json().then((data) => (onData && onData(data), onSuccess && onSuccess(response), data)).catch((error) => {
|
42
|
-
throw onError && onError(error), error;
|
43
|
-
}).finally(() => {
|
44
|
-
onEnd && onEnd(response);
|
45
|
-
}) : contentType === "application/stream+json" ? handleResponseStreamJson(response, options) : (onSuccess && onSuccess(response), onEnd && onEnd(response), response.body);
|
46
|
-
}
|
47
|
-
exports.handleResponse = handleResponse;
|
48
|
-
exports.handleResponseStreamJson = handleResponseStreamJson;
|
49
|
-
//# sourceMappingURL=Cx8m1YzL.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Cx8m1YzL.cjs","sources":["../../utils/handleResponseStreamJson.ts","../../utils/handleResponse.ts"],"sourcesContent":["import type { Awaitable } from '@unshared/functions/awaitable'\nimport type { RequestHooks } from './handleResponse'\nimport { awaitable } from '@unshared/functions/awaitable'\n\nasync function * createResponseStreamJsonIterator(response: Response, options: RequestHooks) {\n const { onError, onSuccess, onData, onEnd } = options\n try {\n const body = response.body\n if (body === null) throw new Error('Could not read the response body, it is empty.')\n const reader = body.getReader()\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n const parts = new TextDecoder().decode(value).trim().split('\\0').filter(Boolean)\n\n // --- For each part, parse as JSON and yield the data.\n for (const part of parts) {\n const payload = JSON.parse(part) as unknown\n if (onData) onData(payload)\n yield payload\n }\n }\n if (onSuccess) onSuccess(response)\n }\n catch (error) {\n if (onError) onError(error as Error)\n }\n finally {\n if (onEnd) onEnd(response)\n }\n}\n\n/**\n * Handle a request response where the content type is a stream of JSON objects. This function\n * will parse the JSON objects and yield the data to the caller. If an error occurs, the `onError`\n * callback will be called and the function will return.\n *\n * @param response The response to handle.\n * @param options The options to pass to the request.\n * @returns An awaitable iterator that yields the parsed JSON objects.\n */\nexport function handleResponseStreamJson<T>(response: Response, options: RequestHooks): Awaitable<AsyncIterable<T>, T[]> {\n const responseIterator = createResponseStreamJsonIterator(response, options)\n return awaitable(responseIterator) as Awaitable<AsyncIterable<T>, T[]>\n}\n","import { handleResponseStreamJson } from './handleResponseStreamJson'\n\nexport interface RequestHooks {\n\n /**\n * The callback that is called when an error occurs during the request.\n */\n onError?: (error: Error) => any\n\n /**\n * The callback that is called when data is received from the request. This callback\n * will be called for each chunk of data that is received from the request.\n */\n onData?: (data: unknown) => any\n\n /**\n * The callback that is called when the request is successful. This callback will be\n * called after the request is complete and all data has been received.\n */\n onSuccess?: (response: Response) => any\n\n /**\n * The callback that is called when the status code is not OK. This callback will be called\n * after the request is complete and before the data is consumed.\n */\n onFailure?: (response: Response) => any\n\n /**\n * The callback that is called when the request is complete. This callback will be called\n * after the request is complete and all data has been received.\n */\n onEnd?: (response: Response) => any\n}\n\n/**\n * Handle a request response. This function will parse the response based on the content type and\n * return the data. If an error occurs, the `onError` callback will be called and the function will\n * throw an error.\n *\n * @param response The response to handle.\n * @param options The options to pass to the request.\n * @returns The parsed data from the response.\n */\nexport async function handleResponse(response: Response, options: RequestHooks): Promise<unknown> {\n const { onError, onSuccess, onData, onEnd, onFailure } = options\n const contentType = response.headers.get('Content-Type')\n\n // --- If the response is not OK, throw an error with the response message.\n if (!response.ok) {\n if (onFailure) onFailure(response)\n if (onEnd) onEnd(response)\n throw new Error(response.statusText)\n }\n\n // --- If the status code is 204, return an empty response early.\n if (response.status === 204) {\n if (onSuccess) onSuccess(response)\n if (onEnd) onEnd(response)\n return\n }\n\n // --- If the response is a text content type, return the text response.\n if (contentType?.startsWith('text/')) {\n return await response.text()\n .then((data) => {\n if (onData) onData(data)\n if (onSuccess) onSuccess(response)\n return data\n })\n .catch((error: Error) => {\n if (onError) onError(error)\n throw error\n })\n .finally(() => {\n if (onEnd) onEnd(response)\n })\n }\n\n // --- If the response is a application/json, parse the JSON and return it.\n if (contentType === 'application/json') {\n return await response.json()\n .then((data) => {\n if (onData) onData(data)\n if (onSuccess) onSuccess(response)\n return data as unknown\n })\n .catch((error: Error) => {\n if (onError) onError(error)\n throw error\n })\n .finally(() => {\n if (onEnd) onEnd(response)\n })\n }\n\n // --- If the response is a application/stream+json, return an iterator that parses the JSON.\n if (contentType === 'application/stream+json')\n return handleResponseStreamJson(response, options)\n\n // --- Otherwise, fallback to returning the response body as-is.\n if (onSuccess) onSuccess(response)\n if (onEnd) onEnd(response)\n return response.body\n}\n"],"names":["awaitable"],"mappings":";;AAIA,gBAAiB,iCAAiC,UAAoB,SAAuB;AAC3F,QAAM,EAAE,SAAS,WAAW,QAAQ,MAAU,IAAA;AAC1C,MAAA;AACF,UAAM,OAAO,SAAS;AACtB,QAAI,SAAS,KAAY,OAAA,IAAI,MAAM,gDAAgD;AAC7E,UAAA,SAAS,KAAK,UAAU;AACjB,eAAA;AACX,YAAM,EAAE,MAAM,MAAU,IAAA,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,YAAM,QAAQ,IAAI,YAA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;AAAA,EAAA,CACP,EACA,QAAQ,MAAM;AACT,aAAO,MAAM,QAAQ;AAAA,EAAA,CAC1B,IAID,gBAAgB,4BACX,yBAAyB,UAAU,OAAO,KAG/C,aAAW,UAAU,QAAQ,GAC7B,SAAO,MAAM,QAAQ,GAClB,SAAS;AAClB;;;"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"D-WqCFul.js","sources":["../../openapi/getBaseUrl.ts","../../openapi/getOperationById.ts"],"sourcesContent":["import type { OpenAPI } from 'openapi-types'\n\n/**\n * Given an OpenAPI specification, get the first base URL.\n *\n * @param specification The OpenAPI specification.\n * @returns The first base URL.\n * @example getBaseUrl(specification) // 'https://api.example.com/v1'\n */\nexport function getBaseUrl(specification: OpenAPI.Document): string {\n\n // --- Handle OpenAPI 3.0 specifications.\n if ('servers' in specification && Array.isArray(specification.servers) && specification.servers.length > 0)\n return specification.servers[0].url\n\n // --- Handle OpenAPI 2.0 specifications.\n if ('host' in specification && typeof specification.host === 'string') {\n const scheme = specification.schemes && specification.schemes.length > 0 ? specification.schemes[0] : 'https'\n const basePath = specification.basePath && typeof specification.basePath === 'string' ? specification.basePath : '/'\n return `${scheme}://${specification.host}${basePath}`\n }\n\n throw new Error('No base URL found in the OpenAPI specification.')\n}\n","import type { OpenAPI } from 'openapi-types'\nimport type { OpenAPIV2 } from './OpenApiV2'\n\n/** The HTTP methods supported by OpenAPI. */\nconst methods = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch'] as const\n\n/**\n * Given an OpenAPI specification, find an operation by its operationId.\n *\n * @param specification The OpenAPI specification.\n * @param operationId The operationId of the operation to resolve.\n * @returns The resolved operation.\n * @example openapiGetOperation(specification, 'getUser') // { method: 'get', path: '/users/{username}', ... }\n */\nexport function getOperationById<T, U extends OpenAPIV2.OperationId<T>>(\n specification: T,\n operationId: U,\n): OpenAPIV2.OperationById<T, U> {\n\n // --- Validate the specification.\n if (!specification\n || typeof specification !== 'object'\n || specification === null\n || 'paths' in specification === false\n || typeof specification.paths !== 'object'\n || specification.paths === null)\n throw new Error('Missing paths object in the OpenAPI specification.')\n\n // --- Search for the operation in the specification's paths.\n const paths = specification.paths as OpenAPI.Document['paths']\n for (const path in paths) {\n const route = paths[path]\n if (typeof route !== 'object' || route === null) continue\n\n // --- Search in each method for the operation.\n for (const method of methods) {\n const operation = route[method]\n if (method in route === false\n || typeof operation !== 'object'\n || operation === null\n || 'operationId' in operation === false\n || operation.operationId !== operationId) continue\n\n // --- Route was found, return the operation.\n return { ...route[method], method, path } as OpenAPIV2.OperationById<T, U>\n }\n }\n\n // --- Throw an error if the operation was not found.\n throw new Error(`Operation \"${operationId}\" not found in specification.`)\n}\n"],"names":[],"mappings":"AASO,SAAS,WAAW,eAAyC;AAG9D,MAAA,aAAa,iBAAiB,MAAM,QAAQ,cAAc,OAAO,KAAK,cAAc,QAAQ,SAAS;AAChG,WAAA,cAAc,QAAQ,CAAC,EAAE;AAGlC,MAAI,UAAU,iBAAiB,OAAO,cAAc,QAAS,UAAU;AAC/D,UAAA,SAAS,cAAc,WAAW,cAAc,QAAQ,SAAS,IAAI,cAAc,QAAQ,CAAC,IAAI,SAChG,WAAW,cAAc,YAAY,OAAO,cAAc,YAAa,WAAW,cAAc,WAAW;AACjH,WAAO,GAAG,MAAM,MAAM,cAAc,IAAI,GAAG,QAAQ;AAAA,EAAA;AAG/C,QAAA,IAAI,MAAM,iDAAiD;AACnE;ACnBA,MAAM,UAAU,CAAC,OAAO,OAAO,QAAQ,UAAU,WAAW,QAAQ,OAAO;AAU3D,SAAA,iBACd,eACA,aAC+B;AAG/B,MAAI,CAAC,iBACA,OAAO,iBAAkB,YACzB,kBAAkB,QAClB,EAAW,WAAA,kBACX,OAAO,cAAc,SAAU,YAC/B,cAAc,UAAU;AACrB,UAAA,IAAI,MAAM,oDAAoD;AAGtE,QAAM,QAAQ,cAAc;AAC5B,aAAW,QAAQ,OAAO;AAClB,UAAA,QAAQ,MAAM,IAAI;AACpB,QAAA,EAAA,OAAO,SAAU,YAAY,UAAU;AAG3C,iBAAW,UAAU,SAAS;AACtB,cAAA,YAAY,MAAM,MAAM;AAC1B,YAAA,EAAA,EAAA,UAAU,UACT,OAAO,aAAc,YACrB,cAAc,QACd,EAAA,iBAAiB,cACjB,UAAU,gBAAgB;AAG/B,iBAAO,EAAE,GAAG,MAAM,MAAM,GAAG,QAAQ,KAAK;AAAA,MAAA;AAAA,EAC1C;AAIF,QAAM,IAAI,MAAM,cAAc,WAAW,+BAA+B;AAC1E;"}
|
package/dist/chunks/D8Tsm7xC.cjs
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
function isFormDataLike(value) {
|
3
|
-
if (typeof value != "object" || value === null) return !1;
|
4
|
-
if (value instanceof FormData) return !0;
|
5
|
-
const values = Object.values(value);
|
6
|
-
return values.length === 0 ? !1 : values.every((x) => x instanceof File ? !0 : Array.isArray(x) ? x.every((item) => item instanceof File) : x instanceof Blob);
|
7
|
-
}
|
8
|
-
function isObjectLike(value) {
|
9
|
-
return typeof value == "object" && value !== null && value.constructor === Object;
|
10
|
-
}
|
11
|
-
function toFormData(object) {
|
12
|
-
if (object instanceof FormData) return object;
|
13
|
-
const formData = new FormData();
|
14
|
-
for (const key in object) {
|
15
|
-
const value = object[key];
|
16
|
-
if (value !== void 0)
|
17
|
-
if (Array.isArray(value))
|
18
|
-
for (const item of value)
|
19
|
-
formData.append(key, item);
|
20
|
-
else
|
21
|
-
formData.append(key, value);
|
22
|
-
}
|
23
|
-
return formData;
|
24
|
-
}
|
25
|
-
function parseRequestBody(route, options, context) {
|
26
|
-
const { data, body = data } = options, { init } = context;
|
27
|
-
["get", "head", "delete"].includes(init.method ?? "get") || body != null && (isFormDataLike(body) ? (init.body = toFormData(body), init.headers = init.headers ?? {}, init.headers = { ...init.headers, "Content-Type": "multipart/form-data" }) : body instanceof ReadableStream ? init.body = body : body instanceof File ? (init.body = body.stream(), init.headers = init.headers ?? {}, init.headers = { ...init.headers, "Content-Type": "application/octet-stream" }) : isObjectLike(body) ? (init.body = JSON.stringify(body), init.headers = init.headers ?? {}, init.headers = { ...init.headers, "Content-Type": "application/json" }) : init.body = body);
|
28
|
-
}
|
29
|
-
function parseRequestHeaders(route, options, context) {
|
30
|
-
const { headers = {} } = options, { init } = context;
|
31
|
-
for (const key in headers) {
|
32
|
-
const value = headers[key];
|
33
|
-
value !== void 0 && typeof value == "string" && (init.headers = init.headers ?? {}, init.headers = { ...init.headers, [key]: value });
|
34
|
-
}
|
35
|
-
}
|
36
|
-
const EXP_PATH_PARAMETER = /:([\w-]+)|%7B([\w-]+)%7D/g;
|
37
|
-
function parseRequestParameters(route, options, context) {
|
38
|
-
const { url } = context, { data, parameters = {} } = options;
|
39
|
-
if (!url) throw new Error("Could not resolve the `RequestInit` object: the `url` is missing.");
|
40
|
-
const pathParameters = url.pathname.match(EXP_PATH_PARAMETER);
|
41
|
-
if (pathParameters)
|
42
|
-
for (const parameter of pathParameters.values()) {
|
43
|
-
const key = parameter.replaceAll(EXP_PATH_PARAMETER, "$1$2"), value = parameters[key];
|
44
|
-
value !== void 0 && typeof value == "string" ? url.pathname = url.pathname.replace(parameter, value) : isObjectLike(data) && data[key] !== void 0 && typeof data[key] == "string" && (url.pathname = url.pathname.replace(parameter, data[key]), delete data[key]);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
function toSearchParams(object, options = {}) {
|
48
|
-
const { searchArrayFormat = "flat" } = options, search = new URLSearchParams();
|
49
|
-
for (const key in object) {
|
50
|
-
const value = object[key];
|
51
|
-
if (value !== void 0)
|
52
|
-
if (Array.isArray(value)) {
|
53
|
-
if (searchArrayFormat === "brackets") for (const v of value) search.append(`${key}[]`, String(v));
|
54
|
-
else if (searchArrayFormat === "indices") for (const [i, v] of value.entries()) search.append(`${key}[${i}]`, String(v));
|
55
|
-
else if (searchArrayFormat === "comma") search.append(key, value.join(","));
|
56
|
-
else if (searchArrayFormat === "path") for (const [i, v] of value.entries()) search.append(`${key}.${i}`, String(v));
|
57
|
-
else if (searchArrayFormat === "flat") for (const v of value) search.append(key, String(v));
|
58
|
-
} else
|
59
|
-
search.append(key, value.toString());
|
60
|
-
}
|
61
|
-
return search;
|
62
|
-
}
|
63
|
-
function parseRequestQuery(route, options, context) {
|
64
|
-
const { url, init } = context, { data, query = {}, searchArrayFormat } = options;
|
65
|
-
if (!url) throw new Error("Could not resolve the `RequestInit` object: the `url` is missing.");
|
66
|
-
if (!["post", "put", "patch"].includes(init.method ?? "get") && isObjectLike(data))
|
67
|
-
for (const key in data)
|
68
|
-
data[key] !== void 0 && query[key] === void 0 && (query[key] = data[key], delete data[key]);
|
69
|
-
url.search = toSearchParams(query, { searchArrayFormat }).toString();
|
70
|
-
}
|
71
|
-
const EXP_REQUEST = /^((?<method>[a-z]+) )?(?<url>[^:]+?:\/{2}[^/]+)?(?<path>\/[^\s?]*)/i, METHODS = /* @__PURE__ */ new Set(["get", "post", "put", "patch", "delete", "head", "options"]);
|
72
|
-
function parseRequestUrl(route, options, context) {
|
73
|
-
const { method, baseUrl } = options, match = EXP_REQUEST.exec(route);
|
74
|
-
if (!match?.groups) throw new Error("Could not resolve the `RequestInit` object: Invalid route name.");
|
75
|
-
const routeMethod = method ?? match.groups.method ?? "get", routeBaseUrl = baseUrl ?? match.groups.url;
|
76
|
-
if (!routeBaseUrl) throw new Error("Could not resolve the `RequestInit` object: the `baseUrl` is missing.");
|
77
|
-
const methodLower = routeMethod.toLowerCase();
|
78
|
-
if (!METHODS.has(methodLower)) throw new Error(`Could not resolve the \`RequestInit\` object:, the method \`${routeMethod}\` is invalid.`);
|
79
|
-
context.init = context.init ?? {}, context.init.method = methodLower, context.url = new URL(routeBaseUrl), context.url.pathname += context.url.pathname.endsWith("/") ? match.groups.path.slice(1) : match.groups.path;
|
80
|
-
}
|
81
|
-
function parseRequest(route, options) {
|
82
|
-
const { data, body, query, headers, parameters, baseUrl, method, searchArrayFormat, ...requestInit } = options, context = { init: requestInit };
|
83
|
-
return parseRequestUrl(route, { baseUrl, method }, context), parseRequestParameters(route, { data, parameters }, context), parseRequestQuery(route, { data, query, searchArrayFormat }, context), parseRequestBody(route, { data, body }, context), parseRequestHeaders(route, { headers }, context), context;
|
84
|
-
}
|
85
|
-
exports.isFormDataLike = isFormDataLike;
|
86
|
-
exports.isObjectLike = isObjectLike;
|
87
|
-
exports.parseRequest = parseRequest;
|
88
|
-
exports.parseRequestBody = parseRequestBody;
|
89
|
-
exports.parseRequestHeaders = parseRequestHeaders;
|
90
|
-
exports.parseRequestParameters = parseRequestParameters;
|
91
|
-
exports.parseRequestQuery = parseRequestQuery;
|
92
|
-
exports.parseRequestUrl = parseRequestUrl;
|
93
|
-
exports.toFormData = toFormData;
|
94
|
-
exports.toSearchParams = toSearchParams;
|
95
|
-
//# sourceMappingURL=D8Tsm7xC.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"D8Tsm7xC.cjs","sources":["../../utils/isFormDataLike.ts","../../utils/isObjectLike.ts","../../utils/toFormData.ts","../../utils/parseRequestBody.ts","../../utils/parseRequestHeaders.ts","../../utils/parseRequestParameters.ts","../../utils/toSearchParams.ts","../../utils/parseRequestQuery.ts","../../utils/parseRequestUrl.ts","../../utils/parseRequest.ts"],"sourcesContent":["/**\n * A type that represents a FormData-like object, which is a plain object with\n * nested Blob, File, or FileList values. Or a FormData instance.\n */\nexport type FormDataLike = FormData | Record<string, Blob | File | FileList>\n\n/**\n * Predicate to check if a value is FormData-like, meaning it is a plain object\n * with nested Blob, File, or FileList values.\n *\n * @param value The value to check.\n * @returns `true` if the value is FormData-like, `false` otherwise.\n * @example isFormDataLike({ file: new File(['test'], 'test.txt') }) // true\n */\nexport function isFormDataLike(value: unknown): value is FormDataLike {\n if (typeof value !== 'object' || value === null) return false\n if (value instanceof FormData) return true\n const values = Object.values(value)\n if (values.length === 0) return false\n return values.every((x) => {\n if (x instanceof File) return true\n if (Array.isArray(x)) return x.every(item => item instanceof File)\n return x instanceof Blob\n })\n}\n","/**\n * Predicate to check if a value is an object-like value.\n *\n * @param value The value to check.\n * @returns `true` if the value is an object-like value, `false` otherwise.\n * @example isObjectLike({}) // true\n */\nexport function isObjectLike(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && value.constructor === Object\n}\n","import type { FormDataLike } from './isFormDataLike'\n\n/**\n * Casts an object that may contain `Blob`, `File`, or `FileList` values to a `FormData` object.\n *\n * @param object The object to cast to a `FormData` object.\n * @returns The `FormData` object.\n */\nexport function toFormData(object: FormDataLike): FormData {\n if (object instanceof FormData) return object\n const formData = new FormData()\n for (const key in object) {\n const value = object[key]\n if (value === undefined) continue\n if (Array.isArray(value)) {\n for (const item of value)\n formData.append(key, item as Blob | string)\n }\n else {\n formData.append(key, value as Blob | string)\n }\n }\n return formData\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\nimport { isFormDataLike } from './isFormDataLike'\nimport { isObjectLike } from './isObjectLike'\nimport { toFormData } from './toFormData'\n\n/**\n * Parse the request body based on the provided data and options.\n *\n * @param route The route path.\n * @param options The request options.\n * @param context The request context.\n */\nexport function parseRequestBody(route: string, options: Pick<RequestOptions, 'body' | 'data'>, context: RequestContext): void {\n const { data, body = data } = options\n const { init } = context\n\n // --- If the method is `GET`, `HEAD`, or `DELETE`, return early.\n if (['get', 'head', 'delete'].includes(init.method ?? 'get')) return\n\n // --- If no data is provided, return early.\n if (body === null || body === undefined) return\n\n // --- If data contains a `File` object, create a FormData object.\n if (isFormDataLike(body)) {\n init.body = toFormData(body)\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, 'Content-Type': 'multipart/form-data' }\n }\n\n // --- If the data is a `ReadableStream`, pass it directly to the body.\n else if (body instanceof ReadableStream) {\n init.body = body\n }\n\n // --- If the data is a Blob, pass it directly to the body.\n else if (body instanceof File) {\n init.body = body.stream()\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, 'Content-Type': 'application/octet-stream' }\n }\n\n // --- Otherwise, stringify the data and set the content type to JSON.\n else if (isObjectLike(body)) {\n init.body = JSON.stringify(body)\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, 'Content-Type': 'application/json' }\n }\n\n // --- For all other data types, set the body directly.\n else {\n init.body = body\n }\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\n\n/**\n * Parse the request headers based on the provided data and options.\n *\n * @param route The route path.\n * @param options The request options.\n * @param context The request context.\n */\nexport function parseRequestHeaders(route: string, options: Pick<RequestOptions, 'headers'>, context: RequestContext): void {\n const { headers = {} } = options\n const { init } = context\n\n // --- Merge the headers with the existing headers.\n for (const key in headers) {\n const value = headers[key]\n if (value === undefined) continue\n if (typeof value !== 'string') continue\n init.headers = init.headers ?? {}\n init.headers = { ...init.headers, [key]: value }\n }\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\nimport { isObjectLike } from './isObjectLike'\n\n/** Regular expression to match path parameters in the URL. */\nconst EXP_PATH_PARAMETER = /:([\\w-]+)|%7B([\\w-]+)%7D/g\n\n/**\n * Parse the request parameters from the request data. This function will append\n * the path parameters to the URL based on the method and the data provided.\n *\n * @param route The name of the route to fetch. (ignored)\n * @param options The options to pass to the request.\n * @param context The request context to modify.\n * @example\n * // Using `express` style path parameters.\n * parseRequestParameters('GET /users/:id', { data: { id: 1 } }, context)\n *\n * // Using `OpenAPI` style path parameters.\n * parseRequestParameters('GET /users/{id}', { data: { id: 1 } }, context)\n */\nexport function parseRequestParameters(route: string, options: Pick<RequestOptions, 'data' | 'parameters'>, context: RequestContext): void {\n const { url } = context\n const { data, parameters = {} } = options\n\n // --- If the method has a parameter, fill the path with the data.\n if (!url) throw new Error('Could not resolve the `RequestInit` object: the `url` is missing.')\n const pathParameters = url.pathname.match(EXP_PATH_PARAMETER)\n if (!pathParameters) return\n\n // --- Apply the path parameters to the URL.\n for (const parameter of pathParameters.values()) {\n const key = parameter.replaceAll(EXP_PATH_PARAMETER, '$1$2')\n\n // --- If the parameter is provided, replace the path with the value.\n const value = parameters[key]\n if (value !== undefined && typeof value === 'string') {\n url.pathname = url.pathname.replace(parameter, value)\n }\n\n // --- If the data contains the parameter, use it and remove it from the data.\n else if (isObjectLike(data) && data[key] !== undefined && typeof data[key] === 'string') {\n url.pathname = url.pathname.replace(parameter, data[key])\n delete data[key]\n }\n }\n}\n","/* eslint-disable unicorn/prevent-abbreviations */\nimport type { MaybeArray } from '@unshared/types'\n\n/** An object that can be converted to a query string. */\nexport type SearchParamsObject = Record<string, MaybeArray<boolean | number | string> | undefined>\n\n/** The search array format options. */\nexport type SearchArrayFormat = 'brackets' | 'comma' | 'flat' | 'indices' | 'path'\n\n/** Options for the query string conversion. */\nexport interface ToSearchParamsOptions {\n\n /**\n * Defines how to handle arrays in the object. There is no standard way to\n * represent arrays in query strings, so this option allows you to choose\n * how to handle them. Additionally, you can provide a custom function to\n * handle it yourself.\n *\n * - `brackets` (default): Convert arrays to `key[]=value&key[]=value` format.\n * - `indices`: Convert arrays to `key[0]=value&key[1]=value` format.\n * - `comma`: Convert arrays to `key=value1,value2` format.\n * - `path`: Convert arrays to `key.0=value&key.1=value` format.\n * - `flat`: Convert arrays to `key=value1&key=value2` format.\n *\n * @default 'flat'\n */\n searchArrayFormat?: SearchArrayFormat\n}\n\n/**\n * Convert object to query string parameters. Converting all values to strings\n * and arrays to `key[0]=value&key[1]=value` format.\n *\n * @param object The object to convert to a query string.\n * @param options The query string options.\n * @returns The `URLSearchParams` object.\n */\nexport function toSearchParams(object: SearchParamsObject, options: ToSearchParamsOptions = {}): URLSearchParams {\n const { searchArrayFormat = 'flat' } = options\n const search = new URLSearchParams()\n for (const key in object) {\n const value = object[key]\n if (value === undefined) continue\n\n // --- Convert arrays based on the format.\n if (Array.isArray(value)) {\n if (searchArrayFormat === 'brackets') for (const v of value) search.append(`${key}[]`, String(v))\n else if (searchArrayFormat === 'indices') for (const [i, v] of value.entries()) search.append(`${key}[${i}]`, String(v))\n else if (searchArrayFormat === 'comma') search.append(key, value.join(','))\n else if (searchArrayFormat === 'path') for (const [i, v] of value.entries()) search.append(`${key}.${i}`, String(v))\n else if (searchArrayFormat === 'flat') for (const v of value) search.append(key, String(v))\n }\n\n // --- Convert all values to strings.\n else { search.append(key, value.toString()) }\n }\n\n // --- Return the query string.\n return search\n}\n","/* eslint-disable unicorn/prevent-abbreviations */\nimport type { RequestContext, RequestOptions } from './parseRequest'\nimport { isObjectLike } from './isObjectLike'\nimport { toSearchParams } from './toSearchParams'\n\n/**\n * Parse the query parameters from the request data. This function will append\n * the query parameters to the URL based on the method and the data provided.\n *\n * @param route The name of the route to fetch. (ignored)\n * @param options The options to pass to the request.\n * @param context The request context to modify.\n */\nexport function parseRequestQuery(route: string, options: Pick<RequestOptions, 'data' | 'query' | 'searchArrayFormat'>, context: RequestContext): void {\n const { url, init } = context\n const { data, query = {}, searchArrayFormat } = options\n if (!url) throw new Error('Could not resolve the `RequestInit` object: the `url` is missing.')\n\n // --- Append the `data` to the query parameters if the method does not expect a body.\n const isExpectingBody = ['post', 'put', 'patch'].includes(init.method ?? 'get')\n if (!isExpectingBody && isObjectLike(data)) {\n for (const key in data) {\n if (data[key] === undefined) continue\n if (query[key] !== undefined) continue\n // @ts-expect-error: Ignore type mismatch.\n query[key] = data[key]\n delete data[key]\n }\n }\n\n // --- Apply the query parameters to the URL.\n url.search = toSearchParams(query, { searchArrayFormat }).toString()\n}\n","import type { RequestContext, RequestOptions } from './parseRequest'\n\n/** Regular expression to match the request method and URL. */\nconst EXP_REQUEST = /^((?<method>[a-z]+) )?(?<url>[^:]+?:\\/{2}[^/]+)?(?<path>\\/[^\\s?]*)/i\n\n/** Valid HTTP methods. */\nconst METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'options'])\n\n/**\n * Parses the route name to extract the URL and method. It allows the url and method to be\n * provided in the route name, or in the options object. The method will default to 'get'.\n *\n * @param route The name of the route to fetch.\n * @param options The options to pass to the request.\n * @param context The request context to modify.\n * @example parseRequestUrl('GET /users', { baseUrl: 'https://api.example.com' }, context)\n */\nexport function parseRequestUrl(route: string, options: Pick<RequestOptions, 'baseUrl' | 'method'>, context: RequestContext): void {\n const { method, baseUrl } = options\n\n // --- Extract the path, method, and base URL from the route name.\n const match = EXP_REQUEST.exec(route)\n if (!match?.groups) throw new Error('Could not resolve the `RequestInit` object: Invalid route name.')\n const routeMethod = method ?? match.groups.method ?? 'get'\n const routeBaseUrl = baseUrl ?? match.groups.url\n\n // --- Assert the base URL is provided, either in the options or the route name.\n if (!routeBaseUrl) throw new Error('Could not resolve the `RequestInit` object: the `baseUrl` is missing.')\n\n // --- Assert the method is valid.\n const methodLower = routeMethod.toLowerCase()\n const methodIsValid = METHODS.has(methodLower)\n if (!methodIsValid) throw new Error(`Could not resolve the \\`RequestInit\\` object:, the method \\`${routeMethod}\\` is invalid.`)\n\n // --- Create the url and apply the method.\n context.init = context.init ?? {}\n context.init.method = methodLower\n context.url = new URL(routeBaseUrl)\n\n // --- Append the path to the URL while making sure there are no double slashes.\n context.url.pathname += context.url.pathname.endsWith('/') ? match.groups.path.slice(1) : match.groups.path\n}\n","/* eslint-disable unicorn/prevent-abbreviations */\nimport type { MaybeLiteral } from '@unshared/types'\nimport type { Override } from '@unshared/types'\nimport type { HttpHeader, HttpMethod } from '../types'\nimport type { SearchArrayFormat, SearchParamsObject } from './toSearchParams'\nimport { parseRequestBody } from './parseRequestBody'\nimport { parseRequestHeaders } from './parseRequestHeaders'\nimport { parseRequestParameters } from './parseRequestParameters'\nimport { parseRequestQuery } from './parseRequestQuery'\nimport { parseRequestUrl } from './parseRequestUrl'\n\n/** The methods to use for the request. */\nexport type RequestMethod = Lowercase<keyof typeof HttpMethod> | Uppercase<keyof typeof HttpMethod>\n\n/** Headers to include in the request. */\nexport type RequestHeaders = Partial<Record<MaybeLiteral<HttpHeader>, string>>\n\n/** The types of data that can be passed to the request. */\nexport type RequestBody = File | FormData | ReadableStream | Record<string, unknown> | string\n\n/** Options to pass to the request. */\nexport type RequestOptions = Override<RequestInit, {\n\n /**\n * The method to use for the request.\n *\n * @example 'GET'\n */\n method?: RequestMethod\n\n /**\n * The base URL to use for the request. This URL will be used to resolve the\n * path and query parameters of the request.\n *\n * @example 'https://api.example.com'\n */\n baseUrl?: string\n\n /**\n * The data to pass to the request. This data will be used to fill the path\n * parameters, query parameters, body, and form data of the request based on\n * the route method.\n */\n data?: RequestBody\n\n /**\n * The body to include in the request.\n */\n body?: RequestBody\n\n /**\n * The headers to include in the request.\n */\n headers?: RequestHeaders\n\n /**\n * Query parameters to include in the request.\n */\n query?: SearchParamsObject\n\n /**\n * The format to use when serializing the query parameters.\n */\n searchArrayFormat?: SearchArrayFormat\n\n /**\n * The path parameters to include in the request.\n */\n parameters?: Record<string, number | string>\n}>\n\nexport interface RequestContext {\n url?: URL\n init: RequestInit\n}\n\n/**\n * Resolves the request body and/or query parameters based on the method type. This function\n * will mutate the `init` object to include the request body and headers based on the data type.\n *\n * @param route The name of the route to fetch.\n * @param options The options to pass to the request.\n * @returns The URL and the `RequestInit` object.\n */\nexport function parseRequest(route: string, options: RequestOptions): RequestContext {\n const { data, body, query, headers, parameters, baseUrl, method, searchArrayFormat, ...requestInit } = options\n const context: RequestContext = { init: requestInit }\n parseRequestUrl(route, { baseUrl, method }, context)\n parseRequestParameters(route, { data, parameters }, context)\n parseRequestQuery(route, { data, query, searchArrayFormat }, context)\n parseRequestBody(route, { data, body }, context)\n parseRequestHeaders(route, { headers }, context)\n return context\n}\n"],"names":[],"mappings":";AAcO,SAAS,eAAe,OAAuC;AACpE,MAAI,OAAO,SAAU,YAAY,UAAU,KAAa,QAAA;AACpD,MAAA,iBAAiB,SAAiB,QAAA;AAChC,QAAA,SAAS,OAAO,OAAO,KAAK;AAC9B,SAAA,OAAO,WAAW,IAAU,KACzB,OAAO,MAAM,CAAC,MACf,aAAa,OAAa,KAC1B,MAAM,QAAQ,CAAC,IAAU,EAAE,MAAM,UAAQ,gBAAgB,IAAI,IAC1D,aAAa,IACrB;AACH;ACjBO,SAAS,aAAa,OAAkD;AAC7E,SAAO,OAAO,SAAU,YAAY,U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