From 31d11190070b8ffb27918e7db299acf3e3380bf9 Mon Sep 17 00:00:00 2001 From: xion Date: Fri, 21 Mar 2025 21:35:54 +0800 Subject: [PATCH] init query config --- .gitignore | 27 +++++++++++++ .npmrc | 2 + package.json | 26 ++++++++++++ readme.md | 7 ++++ src/query-config.ts | 99 +++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 28 +++++++++++++ tsup.config.ts | 12 ++++++ 7 files changed, 201 insertions(+) create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 package.json create mode 100644 readme.md create mode 100644 src/query-config.ts create mode 100644 tsconfig.json create mode 100644 tsup.config.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e440e68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +tsconfig.app.tsbuildinfo +tsconfig.node.tsbuildinfo \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..7446745 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN} +//registry.npmjs.org/:_authToken=${NPM_TOKEN} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..62cd8c0 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "@kevisual/query-config", + "version": "0.0.1", + "description": "", + "main": "dist/query-config.js", + "types": "dist/query-config.d.ts", + "scripts": { + "build": "tsup" + }, + "keywords": [], + "author": "abearxiong ", + "license": "MIT", + "type": "module", + "publishConfig": { + "access": "public" + }, + "peerDependencies": { + "@kevisual/query": "^0.0.12" + }, + "devDependencies": { + "tsup": "^8.4.0" + }, + "exports": { + ".": "./dist/query-config.js" + } +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..2968f38 --- /dev/null +++ b/readme.md @@ -0,0 +1,7 @@ +# query config for kevisual + +## 安装 + +```bash +npm install @kevisual/query-config +``` \ No newline at end of file diff --git a/src/query-config.ts b/src/query-config.ts new file mode 100644 index 0000000..c820f7f --- /dev/null +++ b/src/query-config.ts @@ -0,0 +1,99 @@ +import { Query } from '@kevisual/query'; +import type { Result } from '@kevisual/query/query'; +type QueryConfigOpts = { + query?: Query; +}; +export type Config = { + id?: string; + title?: string; + key?: string; + description?: string; + data?: T; + createdAt?: string; + updatedAt?: string; +}; +export type UploadConfig = { + key?: string; + version?: string; +}; +export class QueryConfig { + query: Query; + constructor(opts?: QueryConfigOpts) { + this.query = opts?.query || new Query(); + } + async post(data: any) { + return this.query.post({ path: 'config', ...data }); + } + async getConfig({ id, key }: { id?: string; key?: string }) { + return this.post({ + key: 'get', + data: { + id, + key, + }, + }); + } + async updateConfig(data: Config) { + return this.post({ + key: 'update', + data, + }); + } + async deleteConfig(id: string) { + return this.post({ + key: 'delete', + data: { id }, + }); + } + async listConfig() { + return this.post<{ list: Config[] }>({ + key: 'list', + }); + } + /** + * 获取上传配置 + * @returns + */ + async getUploadConfig() { + return this.post>>({ + key: 'getUploadConfig', + }); + } + /** + * 更新上传配置 + * @param data + * @returns + */ + async updateUploadConfig(data: Config) { + return this.post>>({ + key: 'updateUploadConfig', + data, + }); + } +} + +/** + * 会员配置, 获取 admin 账户的配置项 + * + */ +export class VipQueryConfig extends QueryConfig { + constructor(opts?: QueryConfigOpts) { + super(opts); + } + /** + * 获取会员配置, 是否开启会员,会员等级配置。 + * 请求数量配置 + * 资源上传配置 + * + * @returns + */ + async getVipConfig() { + return this.post>>({ + key: 'shareConfig', + data: { + type: 'vip', + username: 'admin', + }, + }); + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8f70d0f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "nodenext", + "target": "esnext", + "noImplicitAny": false, + "outDir": "./dist", + "sourceMap": false, + "allowJs": true, + "newLine": "LF", + "baseUrl": "./", + "typeRoots": [ + "node_modules/@types", + ], + "declaration": true, + "noEmit": false, + "allowImportingTsExtensions": true, + "emitDeclarationOnly": true, + "moduleResolution": "NodeNext", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "esModuleInterop": true, + "paths": { + "@/*": [ + "src/*" + ] + } + }, +} \ No newline at end of file diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000..a684b2d --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig({ + entry: ['src/query-config.ts'], + splitting: false, + sourcemap: false, + clean: true, + format: 'esm', + dts: true, + outDir: 'dist', + tsconfig: 'tsconfig.json', +});