This commit is contained in:
parent
4e38c3a74e
commit
77e6394266
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/query",
|
"name": "@kevisual/query",
|
||||||
"version": "0.0.7-alpha.0",
|
"version": "0.0.7-alpha.1",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -18,23 +18,24 @@ export default [
|
|||||||
typescript({
|
typescript({
|
||||||
allowImportingTsExtensions: true,
|
allowImportingTsExtensions: true,
|
||||||
noEmit: true,
|
noEmit: true,
|
||||||
|
exclude: ['src/node-adapter.ts'],
|
||||||
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
input: 'src/node-adapter.ts', // TypeScript 入口文件
|
// input: 'src/node-adapter.ts', // TypeScript 入口文件
|
||||||
output: {
|
// output: {
|
||||||
file: 'dist/node-adapter.js', // 输出文件
|
// file: 'dist/node-adapter.js', // 输出文件
|
||||||
format: 'es', // 输出格式设置为 ES 模块
|
// format: 'es', // 输出格式设置为 ES 模块
|
||||||
},
|
// },
|
||||||
plugins: [
|
// plugins: [
|
||||||
resolve(), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块
|
// resolve(), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块
|
||||||
typescript({
|
// typescript({
|
||||||
allowImportingTsExtensions: true,
|
// allowImportingTsExtensions: true,
|
||||||
noEmit: true,
|
// noEmit: true,
|
||||||
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
// }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
input: 'src/ws.ts', // TypeScript 入口文件
|
input: 'src/ws.ts', // TypeScript 入口文件
|
||||||
output: {
|
output: {
|
||||||
@ -46,6 +47,7 @@ export default [
|
|||||||
typescript({
|
typescript({
|
||||||
allowImportingTsExtensions: true,
|
allowImportingTsExtensions: true,
|
||||||
noEmit: true,
|
noEmit: true,
|
||||||
|
declaration: false,
|
||||||
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
11
src/index.ts
11
src/index.ts
@ -1,5 +1,5 @@
|
|||||||
import { adapter } from './adapter.ts';
|
import { adapter } from './adapter.ts';
|
||||||
import { QueryWs } from './ws.ts';
|
import { QueryWs, QueryWsOpts } from './ws.ts';
|
||||||
export { QueryOpts, QueryWs };
|
export { QueryOpts, QueryWs };
|
||||||
type Fn = (opts: {
|
type Fn = (opts: {
|
||||||
url?: string;
|
url?: string;
|
||||||
@ -98,7 +98,7 @@ export class QueryClient<U = any, V = any> extends Query<U, V> {
|
|||||||
storage: Storage;
|
storage: Storage;
|
||||||
token: string;
|
token: string;
|
||||||
qws: QueryWs;
|
qws: QueryWs;
|
||||||
constructor(opts?: QueryOpts & { tokenName?: string; storage?: Storage }) {
|
constructor(opts?: QueryOpts & { tokenName?: string; storage?: Storage; io?: boolean }) {
|
||||||
super(opts);
|
super(opts);
|
||||||
this.tokenName = opts?.tokenName || 'token';
|
this.tokenName = opts?.tokenName || 'token';
|
||||||
this.storage = opts?.storage || localStorage;
|
this.storage = opts?.storage || localStorage;
|
||||||
@ -112,7 +112,12 @@ export class QueryClient<U = any, V = any> extends Query<U, V> {
|
|||||||
}
|
}
|
||||||
return opts;
|
return opts;
|
||||||
};
|
};
|
||||||
this.qws = new QueryWs({ url: opts?.url });
|
if (opts?.io) {
|
||||||
|
this.createWs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
createWs(opts?: QueryWsOpts) {
|
||||||
|
this.qws = new QueryWs({ url: this.url });
|
||||||
}
|
}
|
||||||
getToken() {
|
getToken() {
|
||||||
return this.storage.getItem(this.tokenName);
|
return this.storage.getItem(this.tokenName);
|
||||||
|
@ -9,7 +9,7 @@ type QueryWsStore = {
|
|||||||
};
|
};
|
||||||
export type QuerySelectState = 'connecting' | 'connected' | 'disconnected';
|
export type QuerySelectState = 'connecting' | 'connected' | 'disconnected';
|
||||||
export type QueryWsStoreListener = (newState: QueryWsStore, oldState: QueryWsStore) => void;
|
export type QueryWsStoreListener = (newState: QueryWsStore, oldState: QueryWsStore) => void;
|
||||||
type QueryWsOpts = {
|
export type QueryWsOpts = {
|
||||||
url?: string;
|
url?: string;
|
||||||
store?: StoreApi<QueryWsStore>;
|
store?: StoreApi<QueryWsStore>;
|
||||||
ws?: WebSocket;
|
ws?: WebSocket;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user