diff --git a/package.json b/package.json index f5e9c23..b4b5446 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/query", - "version": "0.0.7-alpha.0", + "version": "0.0.7-alpha.1", "main": "dist/index.js", "module": "dist/index.js", "types": "dist/index.d.ts", diff --git a/rollup.config.js b/rollup.config.js index 73110df..53a4a51 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -18,23 +18,24 @@ export default [ typescript({ allowImportingTsExtensions: true, noEmit: true, + exclude: ['src/node-adapter.ts'], }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件 ], }, - { - input: 'src/node-adapter.ts', // TypeScript 入口文件 - output: { - file: 'dist/node-adapter.js', // 输出文件 - format: 'es', // 输出格式设置为 ES 模块 - }, - plugins: [ - resolve(), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块 - typescript({ - allowImportingTsExtensions: true, - noEmit: true, - }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件 - ], - }, + // { + // input: 'src/node-adapter.ts', // TypeScript 入口文件 + // output: { + // file: 'dist/node-adapter.js', // 输出文件 + // format: 'es', // 输出格式设置为 ES 模块 + // }, + // plugins: [ + // resolve(), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块 + // typescript({ + // allowImportingTsExtensions: true, + // noEmit: true, + // }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件 + // ], + // }, { input: 'src/ws.ts', // TypeScript 入口文件 output: { @@ -46,6 +47,7 @@ export default [ typescript({ allowImportingTsExtensions: true, noEmit: true, + declaration: false, }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件 ], }, diff --git a/src/index.ts b/src/index.ts index d5fb1b7..16fd673 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { adapter } from './adapter.ts'; -import { QueryWs } from './ws.ts'; +import { QueryWs, QueryWsOpts } from './ws.ts'; export { QueryOpts, QueryWs }; type Fn = (opts: { url?: string; @@ -98,7 +98,7 @@ export class QueryClient extends Query { storage: Storage; token: string; qws: QueryWs; - constructor(opts?: QueryOpts & { tokenName?: string; storage?: Storage }) { + constructor(opts?: QueryOpts & { tokenName?: string; storage?: Storage; io?: boolean }) { super(opts); this.tokenName = opts?.tokenName || 'token'; this.storage = opts?.storage || localStorage; @@ -112,7 +112,12 @@ export class QueryClient extends Query { } 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() { return this.storage.getItem(this.tokenName); diff --git a/src/ws.ts b/src/ws.ts index 129410c..cf340dc 100644 --- a/src/ws.ts +++ b/src/ws.ts @@ -9,7 +9,7 @@ type QueryWsStore = { }; export type QuerySelectState = 'connecting' | 'connected' | 'disconnected'; export type QueryWsStoreListener = (newState: QueryWsStore, oldState: QueryWsStore) => void; -type QueryWsOpts = { +export type QueryWsOpts = { url?: string; store?: StoreApi; ws?: WebSocket;