init query config

This commit is contained in:
xion 2025-03-21 21:35:54 +08:00
commit 31d1119007
7 changed files with 201 additions and 0 deletions

27
.gitignore vendored Normal file
View 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
View File

@ -0,0 +1,2 @@
//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN}
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

26
package.json Normal file
View 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
View File

@ -0,0 +1,7 @@
# query config for kevisual
## 安装
```bash
npm install @kevisual/query-config
```

99
src/query-config.ts Normal file
View 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
View 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
View 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',
});