@kevisual/query 0.0.40 → 0.0.42
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-adapter.js +107 -124
- package/dist/query-api.d.ts +317 -0
- package/dist/query-api.js +449 -0
- package/dist/query-browser.d.ts +1 -8
- package/dist/query-browser.js +489 -582
- package/dist/query-ws.js +163 -181
- package/dist/query.d.ts +1 -8
- package/dist/query.js +278 -359
- package/package.json +13 -25
- package/src/adapter.ts +1 -1
- package/src/create-query/index.ts +159 -0
- package/src/query-api.ts +136 -0
- package/src/query-browser.ts +2 -2
- package/src/query.ts +1 -10
package/dist/query-adapter.js
CHANGED
|
@@ -1,131 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// src/adapter.ts
|
|
2
|
+
var methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"];
|
|
3
|
+
var isTextForContentType = (contentType) => {
|
|
4
|
+
if (!contentType)
|
|
5
|
+
return false;
|
|
6
|
+
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
|
|
7
|
+
return textTypes.some((type) => contentType.includes(type));
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
...opts.params,
|
|
50
|
-
};
|
|
51
|
-
const searchParams = new URLSearchParams(params);
|
|
52
|
-
if (typeof opts.body === 'object' && opts.body !== null) {
|
|
53
|
-
// 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
|
|
54
|
-
let body = opts.body || {};
|
|
55
|
-
if (!params.path && body?.path) {
|
|
56
|
-
searchParams.set('path', body.path);
|
|
57
|
-
if (body?.key) {
|
|
58
|
-
searchParams.set('key', body.key);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
9
|
+
var adapter = async (opts = {}, overloadOpts) => {
|
|
10
|
+
const controller = new AbortController;
|
|
11
|
+
const signal = controller.signal;
|
|
12
|
+
const isPostFile = opts.isPostFile || false;
|
|
13
|
+
let responseType = opts.responseType || "json";
|
|
14
|
+
if (opts.isBlob) {
|
|
15
|
+
responseType = "blob";
|
|
16
|
+
} else if (opts.isText) {
|
|
17
|
+
responseType = "text";
|
|
18
|
+
}
|
|
19
|
+
const timeout = opts.timeout || 60000 * 3;
|
|
20
|
+
const timer = setTimeout(() => {
|
|
21
|
+
controller.abort();
|
|
22
|
+
}, timeout);
|
|
23
|
+
let method = overloadOpts?.method || opts?.method || "POST";
|
|
24
|
+
let headers = { ...opts?.headers, ...overloadOpts?.headers };
|
|
25
|
+
let origin = "";
|
|
26
|
+
let url;
|
|
27
|
+
if (opts?.url?.startsWith("http")) {
|
|
28
|
+
url = new URL(opts.url);
|
|
29
|
+
} else {
|
|
30
|
+
origin = globalThis?.location?.origin || "http://localhost:51515";
|
|
31
|
+
url = new URL(opts?.url || "", origin);
|
|
32
|
+
}
|
|
33
|
+
const isGet = method === "GET";
|
|
34
|
+
const oldSearchParams = url.searchParams;
|
|
35
|
+
if (isGet) {
|
|
36
|
+
let searchParams = new URLSearchParams({ ...Object.fromEntries(oldSearchParams), ...opts?.params, ...opts?.body });
|
|
37
|
+
url.search = searchParams.toString();
|
|
38
|
+
} else {
|
|
39
|
+
const params = {
|
|
40
|
+
...Object.fromEntries(oldSearchParams),
|
|
41
|
+
...opts.params
|
|
42
|
+
};
|
|
43
|
+
const searchParams = new URLSearchParams(params);
|
|
44
|
+
if (typeof opts.body === "object" && opts.body !== null) {
|
|
45
|
+
let body2 = opts.body || {};
|
|
46
|
+
if (!params.path && body2?.path) {
|
|
47
|
+
searchParams.set("path", body2.path);
|
|
48
|
+
if (body2?.key) {
|
|
49
|
+
searchParams.set("key", body2.key);
|
|
61
50
|
}
|
|
62
|
-
|
|
51
|
+
}
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
url.search = searchParams.toString();
|
|
54
|
+
}
|
|
55
|
+
let body = undefined;
|
|
56
|
+
if (isGet) {
|
|
57
|
+
body = undefined;
|
|
58
|
+
} else if (isPostFile) {
|
|
59
|
+
body = opts.body;
|
|
60
|
+
} else {
|
|
61
|
+
if (opts.body && typeof opts.body === "object" && !(opts.body instanceof FormData)) {
|
|
62
|
+
headers = {
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
...headers
|
|
65
|
+
};
|
|
66
|
+
body = JSON.stringify(opts.body);
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
}
|
|
69
|
+
return fetch(url, {
|
|
70
|
+
method: method.toUpperCase(),
|
|
71
|
+
signal,
|
|
72
|
+
body,
|
|
73
|
+
...overloadOpts,
|
|
74
|
+
headers
|
|
75
|
+
}).then(async (response) => {
|
|
76
|
+
const contentType = response.headers.get("Content-Type");
|
|
77
|
+
if (responseType === "blob") {
|
|
78
|
+
return await response.blob();
|
|
70
79
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
const isText = responseType === "text";
|
|
81
|
+
const isJson = contentType && contentType.includes("application/json");
|
|
82
|
+
if (isJson && !isText) {
|
|
83
|
+
return await response.json();
|
|
84
|
+
} else if (isTextForContentType(contentType)) {
|
|
85
|
+
return {
|
|
86
|
+
code: response.status,
|
|
87
|
+
status: response.status,
|
|
88
|
+
data: await response.text()
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
return response;
|
|
79
92
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
code: response.status,
|
|
102
|
-
status: response.status,
|
|
103
|
-
data: await response.text(), // 直接返回文本内容
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
return response;
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
.catch((err) => {
|
|
111
|
-
if (err.name === 'AbortError') {
|
|
112
|
-
return {
|
|
113
|
-
code: 408,
|
|
114
|
-
message: '请求超时',
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
code: 500,
|
|
119
|
-
message: err.message || '网络错误',
|
|
120
|
-
};
|
|
121
|
-
})
|
|
122
|
-
.finally(() => {
|
|
123
|
-
clearTimeout(timer);
|
|
124
|
-
});
|
|
93
|
+
}).catch((err) => {
|
|
94
|
+
if (err.name === "AbortError") {
|
|
95
|
+
return {
|
|
96
|
+
code: 408,
|
|
97
|
+
message: "请求超时"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
code: 500,
|
|
102
|
+
message: err.message || "网络错误"
|
|
103
|
+
};
|
|
104
|
+
}).finally(() => {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
var queryFetch = adapter;
|
|
109
|
+
export {
|
|
110
|
+
queryFetch,
|
|
111
|
+
methods,
|
|
112
|
+
isTextForContentType,
|
|
113
|
+
adapter
|
|
125
114
|
};
|
|
126
|
-
/**
|
|
127
|
-
* adapter
|
|
128
|
-
*/
|
|
129
|
-
const queryFetch = adapter;
|
|
130
|
-
|
|
131
|
-
export { adapter, isTextForContentType, methods, queryFetch };
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { StoreApi } from 'zustand/vanilla';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const methods: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"];
|
|
5
|
+
type Method = (typeof methods)[number];
|
|
6
|
+
type AdapterOpts = {
|
|
7
|
+
url?: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* 只用户POST请求,传递的查询参数,
|
|
11
|
+
* GET请求默认方body自己转化为查询参数
|
|
12
|
+
*/
|
|
13
|
+
params?: Record<string, any>;
|
|
14
|
+
body?: Record<string, any> | FormData;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
method?: Method;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use responseType
|
|
19
|
+
*/
|
|
20
|
+
isBlob?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated use responseType
|
|
23
|
+
*/
|
|
24
|
+
isText?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 响应类型,
|
|
27
|
+
* */
|
|
28
|
+
responseType?: 'json' | 'text' | 'blob';
|
|
29
|
+
isPostFile?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param opts
|
|
34
|
+
* @param overloadOpts 覆盖fetch的默认配置
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
declare const adapter: (opts?: AdapterOpts, overloadOpts?: RequestInit) => Promise<any>;
|
|
38
|
+
|
|
39
|
+
type QueryWsStore = {
|
|
40
|
+
connected: boolean;
|
|
41
|
+
status: 'connecting' | 'connected' | 'disconnected';
|
|
42
|
+
setConnected: (connected: boolean) => void;
|
|
43
|
+
setStatus: (status: QuerySelectState) => void;
|
|
44
|
+
};
|
|
45
|
+
type QuerySelectState = 'connecting' | 'connected' | 'disconnected';
|
|
46
|
+
type QueryWsOpts = {
|
|
47
|
+
url?: string;
|
|
48
|
+
store?: StoreApi<QueryWsStore>;
|
|
49
|
+
ws?: WebSocket;
|
|
50
|
+
};
|
|
51
|
+
declare class QueryWs {
|
|
52
|
+
url: string;
|
|
53
|
+
store: StoreApi<QueryWsStore>;
|
|
54
|
+
ws: WebSocket;
|
|
55
|
+
constructor(opts?: QueryWsOpts);
|
|
56
|
+
/**
|
|
57
|
+
* 连接 WebSocket
|
|
58
|
+
*/
|
|
59
|
+
connect(opts?: {
|
|
60
|
+
timeout?: number;
|
|
61
|
+
}): Promise<unknown>;
|
|
62
|
+
/**
|
|
63
|
+
* ws.onopen 必须用这个去获取,否者会丢失链接信息
|
|
64
|
+
* @param callback
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
listenConnect(callback: () => void): () => void;
|
|
68
|
+
listenClose(callback: () => void): () => void;
|
|
69
|
+
onMessage<T = any, U = any>(fn: (data: U, event: MessageEvent) => void, opts?: {
|
|
70
|
+
/**
|
|
71
|
+
* 是否将数据转换为 JSON
|
|
72
|
+
*/
|
|
73
|
+
isJson?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 选择器
|
|
76
|
+
*/
|
|
77
|
+
selector?: (data: T) => U;
|
|
78
|
+
}): () => void;
|
|
79
|
+
close(): void;
|
|
80
|
+
/**
|
|
81
|
+
* 发送消息
|
|
82
|
+
*
|
|
83
|
+
* @param data
|
|
84
|
+
* @param opts
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
send<T = any, U = any>(data: T, opts?: {
|
|
88
|
+
/**
|
|
89
|
+
* 是否将数据转换为 JSON
|
|
90
|
+
*/
|
|
91
|
+
isJson?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* 包装数据
|
|
94
|
+
*/
|
|
95
|
+
wrapper?: (data: T) => U;
|
|
96
|
+
}): void;
|
|
97
|
+
getOpen(): boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 请求前处理函数
|
|
102
|
+
* @param opts 请求配置
|
|
103
|
+
* @returns 请求配置
|
|
104
|
+
*/
|
|
105
|
+
type Fn = (opts: {
|
|
106
|
+
url?: string;
|
|
107
|
+
headers?: Record<string, string>;
|
|
108
|
+
body?: Record<string, any>;
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
timeout?: number;
|
|
111
|
+
}) => Promise<Record<string, any> | false>;
|
|
112
|
+
type QueryOpts = {
|
|
113
|
+
adapter?: typeof adapter;
|
|
114
|
+
[key: string]: any;
|
|
115
|
+
} & AdapterOpts;
|
|
116
|
+
type QueryOptions = {
|
|
117
|
+
url?: string;
|
|
118
|
+
adapter?: typeof adapter;
|
|
119
|
+
headers?: Record<string, string>;
|
|
120
|
+
timeout?: number;
|
|
121
|
+
isClient?: boolean;
|
|
122
|
+
beforeRequest?: Fn;
|
|
123
|
+
};
|
|
124
|
+
type Data = {
|
|
125
|
+
path?: string;
|
|
126
|
+
key?: string;
|
|
127
|
+
payload?: Record<string, any>;
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
};
|
|
130
|
+
type Result<S = any, U = {}> = {
|
|
131
|
+
code: number;
|
|
132
|
+
data?: S;
|
|
133
|
+
message?: string;
|
|
134
|
+
} & U;
|
|
135
|
+
type DataOpts = Partial<QueryOpts> & {
|
|
136
|
+
beforeRequest?: Fn;
|
|
137
|
+
afterResponse?: <S = any>(result: Result<S>, ctx?: {
|
|
138
|
+
req?: any;
|
|
139
|
+
res?: any;
|
|
140
|
+
fetch?: any;
|
|
141
|
+
}) => Promise<Result<S>>;
|
|
142
|
+
/**
|
|
143
|
+
* 是否在stop的时候不请求
|
|
144
|
+
*/
|
|
145
|
+
noStop?: boolean;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* const query = new Query();
|
|
149
|
+
* const res = await query.post({
|
|
150
|
+
* path: 'demo',
|
|
151
|
+
* key: '1',
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* U是参数 V是返回值
|
|
155
|
+
*/
|
|
156
|
+
declare class Query {
|
|
157
|
+
adapter: typeof adapter;
|
|
158
|
+
url: string;
|
|
159
|
+
/**
|
|
160
|
+
* 请求前处理函数
|
|
161
|
+
*/
|
|
162
|
+
beforeRequest?: DataOpts['beforeRequest'];
|
|
163
|
+
/**
|
|
164
|
+
* 请求后处理函数
|
|
165
|
+
*/
|
|
166
|
+
afterResponse?: DataOpts['afterResponse'];
|
|
167
|
+
headers?: Record<string, string>;
|
|
168
|
+
timeout?: number;
|
|
169
|
+
/**
|
|
170
|
+
* 需要突然停止请求,比如401的时候
|
|
171
|
+
*/
|
|
172
|
+
stop?: boolean;
|
|
173
|
+
qws: QueryWs;
|
|
174
|
+
/**
|
|
175
|
+
* 默认是 /client/router或者 默认是 /api/router
|
|
176
|
+
*/
|
|
177
|
+
isClient: boolean;
|
|
178
|
+
constructor(opts?: QueryOptions);
|
|
179
|
+
setQueryWs(qws: QueryWs): void;
|
|
180
|
+
/**
|
|
181
|
+
* 突然停止请求
|
|
182
|
+
*/
|
|
183
|
+
setStop(stop: boolean): void;
|
|
184
|
+
/**
|
|
185
|
+
* 发送 get 请求,转到 post 请求
|
|
186
|
+
* T是请求类型自定义
|
|
187
|
+
* S是返回类型自定义
|
|
188
|
+
* @param params 请求参数
|
|
189
|
+
* @param options 请求配置
|
|
190
|
+
* @returns 请求结果
|
|
191
|
+
*/
|
|
192
|
+
get<R = any, P = any>(params: Data & P, options?: DataOpts): Promise<Result<R>>;
|
|
193
|
+
/**
|
|
194
|
+
* 发送 post 请求
|
|
195
|
+
* T是请求类型自定义
|
|
196
|
+
* S是返回类型自定义
|
|
197
|
+
* @param body 请求体
|
|
198
|
+
* @param options 请求配置
|
|
199
|
+
* @returns 请求结果
|
|
200
|
+
*/
|
|
201
|
+
post<R = any, P = any>(body: Data & P, options?: DataOpts): Promise<Result<R>>;
|
|
202
|
+
/**
|
|
203
|
+
* 设置请求前处理,设置请求前处理函数
|
|
204
|
+
* @param fn 处理函数
|
|
205
|
+
*/
|
|
206
|
+
before(fn: DataOpts['beforeRequest']): void;
|
|
207
|
+
/**
|
|
208
|
+
* 设置请求后处理,设置请求后处理函数
|
|
209
|
+
* @param fn 处理函数
|
|
210
|
+
*/
|
|
211
|
+
after(fn: DataOpts['afterResponse']): void;
|
|
212
|
+
fetchText(urlOrOptions?: string | QueryOpts, options?: QueryOpts): Promise<Result<any>>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
type RouteInfo = {
|
|
216
|
+
path: string;
|
|
217
|
+
key: string;
|
|
218
|
+
id: string;
|
|
219
|
+
description?: string;
|
|
220
|
+
metadata?: {
|
|
221
|
+
summary?: string;
|
|
222
|
+
args?: Record<string, any>;
|
|
223
|
+
viewItem?: {
|
|
224
|
+
type?: string;
|
|
225
|
+
api?: {
|
|
226
|
+
query?: any;
|
|
227
|
+
};
|
|
228
|
+
worker?: {
|
|
229
|
+
worker?: any;
|
|
230
|
+
};
|
|
231
|
+
context?: {
|
|
232
|
+
router?: any;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
declare const createQueryByRoutes: (list: RouteInfo[]) => string;
|
|
238
|
+
|
|
239
|
+
type Pos = {
|
|
240
|
+
path?: string;
|
|
241
|
+
key?: string;
|
|
242
|
+
id?: string;
|
|
243
|
+
metadata?: {
|
|
244
|
+
args?: Record<string, any>;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
type InferFromJSONSchema<T> = T extends {
|
|
248
|
+
type: "string";
|
|
249
|
+
enum: readonly (infer E)[];
|
|
250
|
+
} ? E : T extends {
|
|
251
|
+
type: "string";
|
|
252
|
+
enum: (infer E)[];
|
|
253
|
+
} ? E : T extends {
|
|
254
|
+
type: "string";
|
|
255
|
+
} ? string : T extends {
|
|
256
|
+
type: "number";
|
|
257
|
+
} ? number : T extends {
|
|
258
|
+
type: "integer";
|
|
259
|
+
} ? number : T extends {
|
|
260
|
+
type: "boolean";
|
|
261
|
+
} ? boolean : T extends {
|
|
262
|
+
type: "object";
|
|
263
|
+
properties: infer P;
|
|
264
|
+
} ? {
|
|
265
|
+
[K in keyof P]: InferFromJSONSchema<P[K]>;
|
|
266
|
+
} : T extends {
|
|
267
|
+
type: "array";
|
|
268
|
+
items: infer I;
|
|
269
|
+
} ? Array<InferFromJSONSchema<I>> : unknown;
|
|
270
|
+
type InferType<T> = T extends z.ZodType<infer U> ? U : T extends {
|
|
271
|
+
type: infer TType;
|
|
272
|
+
} ? InferFromJSONSchema<T> : T;
|
|
273
|
+
type ExtractArgsFromMetadata<T> = T extends {
|
|
274
|
+
metadata?: {
|
|
275
|
+
args?: infer A;
|
|
276
|
+
};
|
|
277
|
+
} ? A extends Record<string, any> ? {
|
|
278
|
+
[K in keyof A]: InferType<A[K]>;
|
|
279
|
+
} : never : never;
|
|
280
|
+
type ApiMethods<P extends {
|
|
281
|
+
[path: string]: {
|
|
282
|
+
[key: string]: Pos;
|
|
283
|
+
};
|
|
284
|
+
}> = {
|
|
285
|
+
[Path in keyof P]: {
|
|
286
|
+
[Key in keyof P[Path]]: (data?: Partial<ExtractArgsFromMetadata<P[Path][Key]>>, opts?: DataOpts) => ReturnType<Query['post']>;
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
type QueryApiOpts<P extends {
|
|
290
|
+
[path: string]: {
|
|
291
|
+
[key: string]: Pos;
|
|
292
|
+
};
|
|
293
|
+
} = {}> = {
|
|
294
|
+
query?: Query;
|
|
295
|
+
api?: P;
|
|
296
|
+
};
|
|
297
|
+
declare class QueryApi<P extends {
|
|
298
|
+
[path: string]: {
|
|
299
|
+
[key: string]: Pos;
|
|
300
|
+
};
|
|
301
|
+
} = {}> {
|
|
302
|
+
query: Query;
|
|
303
|
+
constructor(opts?: QueryApiOpts<P>);
|
|
304
|
+
post<T extends Pos>(pos: T, data?: Partial<ExtractArgsFromMetadata<T>>, opts?: DataOpts): Promise<{
|
|
305
|
+
code: number;
|
|
306
|
+
data?: any;
|
|
307
|
+
message?: string;
|
|
308
|
+
}>;
|
|
309
|
+
createApi(api: P): asserts this is this & ApiMethods<P>;
|
|
310
|
+
}
|
|
311
|
+
declare function createQueryApi<P extends {
|
|
312
|
+
[path: string]: {
|
|
313
|
+
[key: string]: Pos;
|
|
314
|
+
};
|
|
315
|
+
}>(opts?: QueryApiOpts<P>): QueryApi<P> & ApiMethods<P>;
|
|
316
|
+
|
|
317
|
+
export { QueryApi, createQueryApi, createQueryByRoutes };
|