init query config
This commit is contained in:
		
							
								
								
									
										27
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
							
								
								
									
										2
									
								
								.npmrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.npmrc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN}
 | 
			
		||||
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
 | 
			
		||||
							
								
								
									
										26
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							@@ -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 <xiongxiao@xiongxiao.me>",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "type": "module",
 | 
			
		||||
  "publishConfig": {
 | 
			
		||||
    "access": "public"
 | 
			
		||||
  },
 | 
			
		||||
  "peerDependencies": {
 | 
			
		||||
    "@kevisual/query": "^0.0.12"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "tsup": "^8.4.0"
 | 
			
		||||
  },
 | 
			
		||||
  "exports": {
 | 
			
		||||
    ".": "./dist/query-config.js"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								readme.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
# query config for kevisual
 | 
			
		||||
 | 
			
		||||
## 安装
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
npm install @kevisual/query-config
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										99
									
								
								src/query-config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								src/query-config.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
			
		||||
import { Query } from '@kevisual/query';
 | 
			
		||||
import type { Result } from '@kevisual/query/query';
 | 
			
		||||
type QueryConfigOpts = {
 | 
			
		||||
  query?: Query;
 | 
			
		||||
};
 | 
			
		||||
export type Config<T = any> = {
 | 
			
		||||
  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<T = Config>(data: any) {
 | 
			
		||||
    return this.query.post<T>({ 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<Result<Config<UploadConfig>>>({
 | 
			
		||||
      key: 'getUploadConfig',
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
  /**
 | 
			
		||||
   * 更新上传配置
 | 
			
		||||
   * @param data
 | 
			
		||||
   * @returns
 | 
			
		||||
   */
 | 
			
		||||
  async updateUploadConfig(data: Config) {
 | 
			
		||||
    return this.post<Result<Config<UploadConfig>>>({
 | 
			
		||||
      key: 'updateUploadConfig',
 | 
			
		||||
      data,
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 会员配置, 获取 admin 账户的配置项
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
export class VipQueryConfig extends QueryConfig {
 | 
			
		||||
  constructor(opts?: QueryConfigOpts) {
 | 
			
		||||
    super(opts);
 | 
			
		||||
  }
 | 
			
		||||
  /**
 | 
			
		||||
   * 获取会员配置, 是否开启会员,会员等级配置。
 | 
			
		||||
   * 请求数量配置
 | 
			
		||||
   * 资源上传配置
 | 
			
		||||
   *
 | 
			
		||||
   * @returns
 | 
			
		||||
   */
 | 
			
		||||
  async getVipConfig() {
 | 
			
		||||
    return this.post<Result<Config<UploadConfig>>>({
 | 
			
		||||
      key: 'shareConfig',
 | 
			
		||||
      data: {
 | 
			
		||||
        type: 'vip',
 | 
			
		||||
        username: 'admin',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -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/*"
 | 
			
		||||
      ]
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								tsup.config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								tsup.config.ts
									
									
									
									
									
										Normal file
									
								
							@@ -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',
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user