34 lines
914 B
TypeScript
34 lines
914 B
TypeScript
import { adapter } from './adapter.ts';
|
|
import { QueryWs, QueryWsOpts } from './ws.ts';
|
|
import { Query } from './query.ts';
|
|
import { BaseQuery, QueryOptions, wrapperError } from './query.ts';
|
|
|
|
export { QueryOpts, QueryWs, Query, QueryWsOpts, adapter, BaseQuery, wrapperError };
|
|
export { QueryOptions }
|
|
export type { DataOpts, Result, Data } from './query.ts';
|
|
|
|
type QueryOpts = {
|
|
url?: string;
|
|
adapter?: typeof adapter;
|
|
headers?: Record<string, string>;
|
|
timeout?: number;
|
|
isClient?: boolean;
|
|
};
|
|
|
|
/**
|
|
* 前端调用后端QueryRouter, 封装 beforeRequest 和 wss
|
|
*/
|
|
export class QueryClient extends Query {
|
|
constructor(opts?: QueryOptions & { io?: boolean }) {
|
|
super(opts);
|
|
if (opts?.io) {
|
|
this.createWs();
|
|
}
|
|
}
|
|
createWs(opts?: QueryWsOpts) {
|
|
this.qws = new QueryWs({ url: this.url, ...opts });
|
|
}
|
|
}
|
|
// 移除默认生成的实例
|
|
// export const client = new QueryClient();
|