vue-api-kit 1.0.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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # vue-api-kit
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun install
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run index.ts
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.3.4. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
@@ -0,0 +1,5 @@
1
+ import { ApiClientOptions, ApiMutation, ApiQuery, Infer, MutationResult, QueryResult, UseMutationOptions, UseQueryOptions } from './types';
2
+ export declare function createApiClient<Q extends Record<string, ApiQuery>, M extends Record<string, ApiMutation>>(options: ApiClientOptions<Q, M>): {
3
+ query: { [K in keyof Q]: (options?: UseQueryOptions<Infer<Q[K]["params"]>>) => QueryResult<Infer<Q[K]["response"]>>; };
4
+ mutation: { [K_1 in keyof M]: (options?: UseMutationOptions) => MutationResult<Infer<M[K_1]["response"]>, Infer<M[K_1]["data"]>>; };
5
+ };
@@ -0,0 +1,68 @@
1
+ import { InternalAxiosRequestConfig } from 'axios';
2
+ import { Ref } from 'vue';
3
+ import { ZodType } from 'zod';
4
+ import { $ZodIssue } from 'zod/v4/core';
5
+ export type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
6
+ export type Infer<T> = T extends ZodType<infer U> ? U : any;
7
+ export interface ApiQuery<TParams extends ZodType<any> | undefined = ZodType<any> | undefined, TResponse extends ZodType<any> | undefined = ZodType<any> | undefined> {
8
+ method?: Extract<HTTPMethod, "GET">;
9
+ path: string;
10
+ params?: TParams;
11
+ response?: TResponse;
12
+ }
13
+ export interface ApiMutation<TData extends ZodType<any> | undefined = ZodType<any> | undefined, TResponse extends ZodType<any> | undefined = ZodType<any> | undefined, TParams extends ZodType<any> | undefined = ZodType<any> | undefined> {
14
+ method: HTTPMethod;
15
+ path: string;
16
+ params?: TParams;
17
+ data?: TData;
18
+ response?: TResponse;
19
+ isMultipart?: boolean;
20
+ }
21
+ export interface ApiClientOptions<Q extends Record<string, ApiQuery> = Record<string, ApiQuery>, M extends Record<string, ApiMutation> = Record<string, ApiMutation>> {
22
+ baseURL: string;
23
+ headers?: Record<string, string>;
24
+ withCredentials?: boolean;
25
+ queries?: Q;
26
+ mutations?: M;
27
+ beforeRequest?: (config: InternalAxiosRequestConfig<any>) => Promise<any> | any;
28
+ onError?: (error: {
29
+ message: string;
30
+ status?: number;
31
+ code?: string;
32
+ data?: any;
33
+ }) => void;
34
+ onZodError?: (issues: Omit<$ZodIssue, "input">[]) => void;
35
+ }
36
+ export interface UseQueryOptions<TParams = any> {
37
+ params?: TParams;
38
+ loadOnMount?: boolean;
39
+ debounce?: number;
40
+ onResult?: (data: any) => void;
41
+ onError?: (error: string) => void;
42
+ onZodError?: (issues: Omit<$ZodIssue, "input">[]) => void;
43
+ }
44
+ export interface UseMutationOptions<_TData = any> {
45
+ onResult?: (data: any) => void;
46
+ onError?: (error: string) => void;
47
+ onZodError?: (issues: Omit<$ZodIssue, "input">[]) => void;
48
+ onUploadProgress?: (progress: number) => void;
49
+ }
50
+ export interface QueryResult<T> {
51
+ result: Ref<T | undefined>;
52
+ error: Ref<string | undefined>;
53
+ zodErrors: Ref<Omit<$ZodIssue, "input">[] | undefined>;
54
+ isLoading: Ref<boolean>;
55
+ isDone: Ref<boolean>;
56
+ refetch: () => Promise<void>;
57
+ }
58
+ export interface MutationResult<T, TData> {
59
+ result: Ref<T | undefined>;
60
+ error: Ref<string | undefined>;
61
+ zodErrors: Ref<Omit<$ZodIssue, "input">[] | undefined>;
62
+ isLoading: Ref<boolean>;
63
+ isDone: Ref<boolean>;
64
+ uploadProgress: Ref<number>;
65
+ mutate: (data: TData & {
66
+ params?: any;
67
+ }) => Promise<void>;
68
+ }
@@ -0,0 +1,3 @@
1
+ export * as z from 'zod';
2
+ export { createApiClient } from './core/client';
3
+ export type * from './core/types';