@ryneex/api-client 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +6 -6
- package/index.js +3 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -11,12 +11,12 @@ type ClientPayload<TInput, TVariables> = {} & (unknown extends TInput ? unknown
|
|
|
11
11
|
type OptionalPayload<T> = object extends T ? void : T;
|
|
12
12
|
type ClientOptions<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.output<TOutputSchema>, TInputCoerced = z.output<TInputSchema>, TVariablesCoerced = z.output<TVariablesSchema>> = {
|
|
13
13
|
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
14
|
-
path: string | ((payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => string);
|
|
15
|
-
axiosOptions?: (payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => AxiosRequestConfig
|
|
14
|
+
path: string | ((payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => string | Promise<string>);
|
|
15
|
+
axiosOptions?: (payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => AxiosRequestConfig | Promise<AxiosRequestConfig>;
|
|
16
16
|
variablesSchema?: TVariablesSchema;
|
|
17
17
|
inputSchema?: TInputSchema;
|
|
18
18
|
outputSchema: TOutputSchema;
|
|
19
|
-
transform?: (data: z.output<TOutputSchema>, payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => TOutput
|
|
19
|
+
transform?: (data: z.output<TOutputSchema>, payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => TOutput | Promise<TOutput>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
type ReactQueryOptions<TOutput, TInput, TVariables> = Omit<UseQueryOptions<TOutput, ClientError>, "queryFn" | "queryKey"> & {
|
|
@@ -55,10 +55,10 @@ declare function createClient(axios: AxiosInstance): {
|
|
|
55
55
|
variablesSchema: undefined extends TVariablesSchema ? undefined : NonNullable<TVariablesSchema>;
|
|
56
56
|
axios: AxiosInstance;
|
|
57
57
|
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
58
|
-
path: string | ((payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => string);
|
|
59
|
-
axiosOptions?: ((payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => axios.AxiosRequestConfig) | undefined;
|
|
58
|
+
path: string | ((payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => string | Promise<string>);
|
|
59
|
+
axiosOptions?: ((payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => axios.AxiosRequestConfig | Promise<axios.AxiosRequestConfig>) | undefined;
|
|
60
60
|
outputSchema: TOutputSchema;
|
|
61
|
-
transform?: ((data: z.core.output<TOutputSchema>, payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => TOutput) | undefined;
|
|
61
|
+
transform?: ((data: z.core.output<TOutputSchema>, payload: ClientPayload<TInputCoerced, TVariablesCoerced>) => TOutput | Promise<TOutput>) | undefined;
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
};
|
package/index.js
CHANGED
|
@@ -85,8 +85,8 @@ async function callApi(opts, _data) {
|
|
|
85
85
|
);
|
|
86
86
|
data.variables = parsedResult.data;
|
|
87
87
|
}
|
|
88
|
-
const axiosOptions = opts.axiosOptions?.(data);
|
|
89
|
-
const url = typeof opts.path === "function" ? opts.path(data) : opts.path;
|
|
88
|
+
const axiosOptions = await opts.axiosOptions?.(data);
|
|
89
|
+
const url = typeof opts.path === "function" ? await opts.path(data) : opts.path;
|
|
90
90
|
if (opts.method === "GET") {
|
|
91
91
|
return await getResponse(
|
|
92
92
|
opts.axios.get(url, axiosOptions),
|
|
@@ -136,7 +136,7 @@ async function getResponse(request, opts, payload) {
|
|
|
136
136
|
})
|
|
137
137
|
);
|
|
138
138
|
if (opts.transform) {
|
|
139
|
-
return ok(opts.transform(parsedResult.data, payload), response);
|
|
139
|
+
return ok(await opts.transform(parsedResult.data, payload), response);
|
|
140
140
|
}
|
|
141
141
|
return ok(parsedResult.data, response);
|
|
142
142
|
} catch (error) {
|