@lovrabet/sdk 1.1.18 → 1.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/src/api/index.d.ts +51 -0
- package/dist/src/api/types.d.ts +18 -0
- package/dist/src/client/client.d.ts +5 -0
- package/package.json +3 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HttpClient } from '../http/http-client';
|
|
2
|
+
import type { SqlExecuteResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* API 命名空间 - 管理通用 API 调用(SQL、Function 等)
|
|
5
|
+
*
|
|
6
|
+
* 设计原则:
|
|
7
|
+
* 1. 依赖注入 - 通过构造函数注入 HttpClient
|
|
8
|
+
* 2. 类型安全 - 支持泛型,提供 TypeScript 类型推断
|
|
9
|
+
* 3. 统一错误处理 - 成功返回数据,失败抛出 LovrabetError
|
|
10
|
+
* 4. 风格一致 - 与 Model 的 getList/getOne 保持一致
|
|
11
|
+
*/
|
|
12
|
+
export declare class ApiNamespace {
|
|
13
|
+
private httpClient;
|
|
14
|
+
constructor(httpClient: HttpClient);
|
|
15
|
+
/**
|
|
16
|
+
* 执行自定义 SQL 查询
|
|
17
|
+
*
|
|
18
|
+
* @param sqlCode SQL代码(字符串格式 "appCode-sqlId" 或数字ID)
|
|
19
|
+
* @param params SQL参数对象(可选)
|
|
20
|
+
* @returns SQL执行结果(包含 execSuccess 和 execResult)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // 无参数查询
|
|
25
|
+
* const data = await client.api.executeSql('fc8e7777-06e3847d');
|
|
26
|
+
* if (data.execSuccess) {
|
|
27
|
+
* const results = data.execResult;
|
|
28
|
+
* results.forEach(item => console.log(item));
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // 参数化查询
|
|
32
|
+
* const data = await client.api.executeSql('fc8e7777-xxxxx', {
|
|
33
|
+
* userId: '123',
|
|
34
|
+
* startDate: '2025-01-01'
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // 带类型提示
|
|
38
|
+
* interface PageStat {
|
|
39
|
+
* creation_date: string;
|
|
40
|
+
* page_count: number;
|
|
41
|
+
* }
|
|
42
|
+
* const data = await client.api.executeSql<PageStat>('fc8e7777-06e3847d');
|
|
43
|
+
* if (data.execSuccess && data.execResult) {
|
|
44
|
+
* data.execResult.forEach(stat => {
|
|
45
|
+
* console.log(stat.creation_date, stat.page_count);
|
|
46
|
+
* });
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
executeSql<T = Record<string, any>>(sqlCode: string | number, params?: Record<string, string | number>): Promise<SqlExecuteResult<T>>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL 执行请求参数
|
|
3
|
+
*/
|
|
4
|
+
export interface SqlExecuteRequest {
|
|
5
|
+
/** SQL 代码(字符串格式 "appCode-sqlId" 或数字 ID) */
|
|
6
|
+
sqlCode: string | number;
|
|
7
|
+
/** SQL 参数对象(可选) */
|
|
8
|
+
params?: Record<string, string | number>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* SQL 执行结果数据
|
|
12
|
+
*/
|
|
13
|
+
export interface SqlExecuteResult<T = Record<string, any>> {
|
|
14
|
+
/** SQL 执行是否成功 */
|
|
15
|
+
execSuccess: boolean;
|
|
16
|
+
/** SQL 查询结果数组 */
|
|
17
|
+
execResult?: T[];
|
|
18
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ClientConfig, LovrabetClient as ILovrabetClient, Environment } from '../types';
|
|
2
|
+
import { ApiNamespace } from '../api';
|
|
2
3
|
/**
|
|
3
4
|
* Lovrabet SDK 核心客户端类
|
|
4
5
|
*
|
|
@@ -21,6 +22,10 @@ export declare class LovrabetClient implements ILovrabetClient {
|
|
|
21
22
|
* 内部调用 client.getModel() 方法,避免命名冲突
|
|
22
23
|
*/
|
|
23
24
|
models: any;
|
|
25
|
+
/**
|
|
26
|
+
* API 命名空间 - 提供通用 API 调用(SQL、Function 等)
|
|
27
|
+
*/
|
|
28
|
+
readonly api: ApiNamespace;
|
|
24
29
|
constructor(config: ClientConfig);
|
|
25
30
|
private validateConfig;
|
|
26
31
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovrabet/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.19",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"start": "npm run watch",
|
|
21
21
|
"watch": "npm run build:dev && npm run watch:files",
|
|
22
22
|
"watch:files": "chokidar \"src/**/*.ts\" \"index.ts\" -c \"npm run build:dev\"",
|
|
23
|
-
"test": "vitest",
|
|
23
|
+
"test": "vitest run",
|
|
24
24
|
"test:run": "vitest run",
|
|
25
25
|
"test:ui": "vitest --ui",
|
|
26
26
|
"test:coverage": "vitest run --coverage",
|
|
27
27
|
"test:watch": "vitest watch",
|
|
28
28
|
"types": "npx tsc --emitDeclarationOnly --declaration --outDir dist index.ts",
|
|
29
29
|
"beta-release": "bun run build && sh scripts/update-beta-version.sh && git push && git push origin --tag && bun publish",
|
|
30
|
-
"release": "bun run build &&
|
|
30
|
+
"release": "bun run build && sh scripts/update-latest-version.sh && git push && git push origin --tag && bun publish"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist"
|