@kevisual/query 0.0.47 → 0.0.49
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/query-api.d.ts +13 -6
- package/dist/query-api.js +13787 -17
- package/dist/query-browser.d.ts +3 -1
- package/dist/query-browser.js +13 -0
- package/dist/query.d.ts +3 -1
- package/dist/query.js +13 -0
- package/package.json +2 -2
- package/src/create-query/index.ts +9 -0
- package/src/query-api.ts +14 -5
- package/src/query.ts +16 -1
package/dist/query-api.d.ts
CHANGED
|
@@ -107,13 +107,14 @@ type QueryOpts = {
|
|
|
107
107
|
} & AdapterOpts;
|
|
108
108
|
type QueryOptions = {
|
|
109
109
|
url?: string;
|
|
110
|
+
baseURL?: string;
|
|
111
|
+
beforeRequest?: Fn;
|
|
110
112
|
adapter?: typeof adapter;
|
|
111
113
|
headers?: Record<string, string>;
|
|
112
114
|
timeout?: number;
|
|
113
115
|
isClient?: boolean;
|
|
114
116
|
tokenName?: string;
|
|
115
117
|
storage?: Storage;
|
|
116
|
-
beforeRequest?: Fn;
|
|
117
118
|
};
|
|
118
119
|
type Data = {
|
|
119
120
|
path?: string;
|
|
@@ -149,6 +150,7 @@ type DataOpts = Partial<QueryOpts> & {
|
|
|
149
150
|
*/
|
|
150
151
|
declare class Query {
|
|
151
152
|
adapter: typeof adapter;
|
|
153
|
+
baseURL: string;
|
|
152
154
|
url: string;
|
|
153
155
|
/**
|
|
154
156
|
* 请求前处理函数
|
|
@@ -291,20 +293,25 @@ type InferType<T> = T extends z.ZodType<infer U> ? U : T extends {
|
|
|
291
293
|
} ? InferFromJSONSchema<T> : T extends {
|
|
292
294
|
properties: infer P;
|
|
293
295
|
} ? InferFromJSONSchema<T> : T;
|
|
296
|
+
type IsOptional<T> = T extends {
|
|
297
|
+
optional: true;
|
|
298
|
+
} ? true : false;
|
|
294
299
|
type ExtractArgsFromMetadata<T> = T extends {
|
|
295
300
|
metadata?: {
|
|
296
301
|
args?: infer A;
|
|
297
302
|
};
|
|
298
|
-
} ? A extends Record<string, any> ? {
|
|
299
|
-
[K in keyof A]: InferType<A[K]>;
|
|
300
|
-
}
|
|
303
|
+
} ? A extends Record<string, any> ? ({
|
|
304
|
+
[K in keyof A as IsOptional<A[K]> extends true ? never : K]: InferType<A[K]>;
|
|
305
|
+
} & {
|
|
306
|
+
[K in keyof A as IsOptional<A[K]> extends true ? K : never]?: InferType<A[K]>;
|
|
307
|
+
}) : never : never;
|
|
301
308
|
type ApiMethods<P extends {
|
|
302
309
|
[path: string]: {
|
|
303
310
|
[key: string]: Pos;
|
|
304
311
|
};
|
|
305
312
|
}> = {
|
|
306
313
|
[Path in keyof P]: {
|
|
307
|
-
[Key in keyof P[Path]]: (data?:
|
|
314
|
+
[Key in keyof P[Path]]: (data?: ExtractArgsFromMetadata<P[Path][Key]>, opts?: DataOpts) => ReturnType<Query['post']>;
|
|
308
315
|
};
|
|
309
316
|
};
|
|
310
317
|
type QueryApiOpts<P extends {
|
|
@@ -322,7 +329,7 @@ declare class QueryApi<P extends {
|
|
|
322
329
|
} = {}> {
|
|
323
330
|
query: Query;
|
|
324
331
|
constructor(opts?: QueryApiOpts<P>);
|
|
325
|
-
post<T extends Pos>(pos: T, data?:
|
|
332
|
+
post<T extends Pos>(pos: T, data?: ExtractArgsFromMetadata<T>, opts?: DataOpts): Promise<{
|
|
326
333
|
code: number;
|
|
327
334
|
data?: any;
|
|
328
335
|
message?: string;
|