@lovrabet/sdk 1.1.20 → 1.1.21
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 +137 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/models/abstract-base-model.d.ts +2 -1
- package/dist/src/models/openapi-model.d.ts +6 -1
- package/dist/src/types/index.d.ts +102 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig, SortList, SelectOption, SelectOptionsParams } from '../types';
|
|
1
|
+
import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig, SortList, SelectOption, SelectOptionsParams, FilterParams } from '../types';
|
|
2
2
|
import type { HttpClient } from '../http/http-client';
|
|
3
3
|
/**
|
|
4
4
|
* 抽象基础模型类
|
|
@@ -15,6 +15,7 @@ export declare abstract class AbstractBaseModel implements BaseModelMethods {
|
|
|
15
15
|
protected abstract getApiPath(method: string): string;
|
|
16
16
|
protected abstract buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
17
17
|
getList<T = any>(params?: ListParams, sortList?: SortList): Promise<ListResponse<T>>;
|
|
18
|
+
filter<T = any>(params?: FilterParams): Promise<ListResponse<T>>;
|
|
18
19
|
getOne<T = any>(id: string | number): Promise<T>;
|
|
19
20
|
create<T = any>(data: Record<string, any>): Promise<T>;
|
|
20
21
|
update<T = any>(id: string | number, data: Record<string, any>): Promise<T>;
|
|
@@ -15,9 +15,14 @@ export declare class OpenApiModel extends AbstractBaseModel {
|
|
|
15
15
|
* 请求体只包含业务数据
|
|
16
16
|
*/
|
|
17
17
|
protected buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
18
|
+
/**
|
|
19
|
+
* OpenAPI 模式暂不支持 filter 操作
|
|
20
|
+
* @throws Error 当尝试调用 filter 时抛出错误
|
|
21
|
+
*/
|
|
22
|
+
filter(): Promise<any>;
|
|
18
23
|
/**
|
|
19
24
|
* OpenAPI 模式暂不支持 delete 操作
|
|
20
25
|
* @throws Error 当尝试调用 delete 时抛出错误
|
|
21
26
|
*/
|
|
22
|
-
delete(
|
|
27
|
+
delete(): Promise<void>;
|
|
23
28
|
}
|
|
@@ -62,6 +62,84 @@ export interface ListResponse<T> {
|
|
|
62
62
|
/** 每页数量 */
|
|
63
63
|
pageSize: number;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* 条件操作符类型
|
|
67
|
+
* @description 用于构建查询条件的操作符
|
|
68
|
+
*
|
|
69
|
+
* 支持的操作符:
|
|
70
|
+
* - $eq: 等于
|
|
71
|
+
* - $ne: 不等于
|
|
72
|
+
* - $gte / $gteq: 大于等于
|
|
73
|
+
* - $lte / $lteq: 小于等于
|
|
74
|
+
* - $in: 在集合内
|
|
75
|
+
* - $contain: 包含(模糊匹配)
|
|
76
|
+
* - $startWith: 以...开头
|
|
77
|
+
* - $endWith: 以...结尾
|
|
78
|
+
*/
|
|
79
|
+
export type ConditionOperator = '$eq' | '$ne' | '$gte' | '$gteq' | '$lte' | '$lteq' | '$in' | '$contain' | '$startWith' | '$endWith';
|
|
80
|
+
/**
|
|
81
|
+
* 字段条件类型
|
|
82
|
+
* @description 单个字段的查询条件
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // 等于
|
|
86
|
+
* { age: { $eq: 18 } }
|
|
87
|
+
* // 区间
|
|
88
|
+
* { age: { $gte: 18, $lte: 45 } }
|
|
89
|
+
* // 包含
|
|
90
|
+
* { country: { $in: ['中国', '美国', '日本'] } }
|
|
91
|
+
* // 模糊匹配
|
|
92
|
+
* { name: { $contain: 'hello' } }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export type FieldCondition = {
|
|
96
|
+
[K in ConditionOperator]?: any;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Where 条件类型
|
|
100
|
+
* @description 支持字段条件和逻辑连接符的递归定义
|
|
101
|
+
*/
|
|
102
|
+
export type WhereCondition = {
|
|
103
|
+
$and?: WhereCondition[];
|
|
104
|
+
$or?: WhereCondition[];
|
|
105
|
+
[field: string]: FieldCondition | WhereCondition[] | any;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Filter 参数接口
|
|
109
|
+
* @description 用于 filter 方法的查询参数
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const filterParams: FilterParams = {
|
|
113
|
+
* where: {
|
|
114
|
+
* $and: [
|
|
115
|
+
* { age: { $gte: 18, $lte: 45 } },
|
|
116
|
+
* { country: { $in: ['中国', '美国', '日本'] } },
|
|
117
|
+
* { vip: { $ne: null } },
|
|
118
|
+
* { name: { $contain: 'hello' } }
|
|
119
|
+
* ]
|
|
120
|
+
* },
|
|
121
|
+
* select: ['id', 'name', 'age', 'country', 'lastLoginAt'],
|
|
122
|
+
* orderBy: [
|
|
123
|
+
* { lastLoginAt: SortOrder.DESC },
|
|
124
|
+
* { name: SortOrder.ASC }
|
|
125
|
+
* ],
|
|
126
|
+
* currentPage: 1,
|
|
127
|
+
* pageSize: 20
|
|
128
|
+
* };
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export interface FilterParams {
|
|
132
|
+
/** Where 条件 */
|
|
133
|
+
where?: WhereCondition;
|
|
134
|
+
/** 选择返回的字段列表 */
|
|
135
|
+
select?: string[];
|
|
136
|
+
/** 排序规则 */
|
|
137
|
+
orderBy?: SortList;
|
|
138
|
+
/** 当前页码,从 1 开始 */
|
|
139
|
+
currentPage?: number;
|
|
140
|
+
/** 每页数量 */
|
|
141
|
+
pageSize?: number;
|
|
142
|
+
}
|
|
65
143
|
/**
|
|
66
144
|
* 下拉选项接口
|
|
67
145
|
* @description 用于 Select 组件的选项数据格式
|
|
@@ -203,6 +281,30 @@ export interface BaseModelMethods {
|
|
|
203
281
|
* @returns 返回分页数据
|
|
204
282
|
*/
|
|
205
283
|
getList<T = any>(params?: ListParams, sortList?: SortList): Promise<ListResponse<T>>;
|
|
284
|
+
/**
|
|
285
|
+
* 高级过滤查询(推荐使用)
|
|
286
|
+
* @template T 返回数据的类型
|
|
287
|
+
* @param params Filter 查询参数,支持复杂条件、字段选择、排序和分页
|
|
288
|
+
* @returns 返回分页数据
|
|
289
|
+
* @description 提供比 getList 更强大的查询能力,支持复杂的 where 条件、字段选择等(仅 WebAPI 模式支持)
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const result = await model.filter({
|
|
293
|
+
* where: {
|
|
294
|
+
* $and: [
|
|
295
|
+
* { age: { $gte: 18, $lte: 45 } },
|
|
296
|
+
* { country: { $in: ['中国', '美国', '日本'] } },
|
|
297
|
+
* { name: { $contain: 'hello' } }
|
|
298
|
+
* ]
|
|
299
|
+
* },
|
|
300
|
+
* select: ['id', 'name', 'age', 'country'],
|
|
301
|
+
* orderBy: [{ lastLoginAt: SortOrder.DESC }],
|
|
302
|
+
* currentPage: 1,
|
|
303
|
+
* pageSize: 20
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
filter<T = any>(params?: FilterParams): Promise<ListResponse<T>>;
|
|
206
308
|
/**
|
|
207
309
|
* 获取单条数据
|
|
208
310
|
* @template T 返回数据的类型
|