@byted-apaas/server-sdk-node 1.1.23 → 1.1.24-beta.0
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/application/application.d.ts +33 -0
- package/application/application.js +2 -0
- package/application/function/function.d.ts +14 -0
- package/application/function/function.js +20 -0
- package/application/impl/common.d.ts +2 -0
- package/application/impl/common.js +52 -0
- package/application/impl/impl.d.ts +19 -0
- package/application/impl/impl.js +45 -0
- package/common/structs.d.ts +15 -0
- package/common/structs.js +21 -0
- package/constants/constants.d.ts +13 -0
- package/constants/constants.js +18 -0
- package/context/context.d.ts +44 -0
- package/context/context.js +25 -0
- package/context/db/db.d.ts +110 -0
- package/context/db/db.js +2 -0
- package/context/db/impl/IObject.d.ts +303 -0
- package/context/db/impl/IObject.js +5 -0
- package/context/db/impl/IObjectV3.d.ts +239 -0
- package/context/db/impl/IObjectV3.js +5 -0
- package/context/db/impl/db.d.ts +62 -0
- package/context/db/impl/db.js +84 -0
- package/context/db/impl/dbV3.d.ts +35 -0
- package/context/db/impl/dbV3.js +50 -0
- package/context/db/impl/object.d.ts +123 -0
- package/context/db/impl/object.js +1008 -0
- package/context/db/impl/oql/ioql.d.ts +14 -0
- package/context/db/impl/oql/ioql.js +4 -0
- package/context/db/impl/oql/oql.d.ts +14 -0
- package/context/db/impl/oql/oql.js +39 -0
- package/context/db/impl/order.d.ts +9 -0
- package/context/db/impl/order.js +15 -0
- package/context/db/impl/propertiesStore.d.ts +8 -0
- package/context/db/impl/propertiesStore.js +29 -0
- package/context/db/impl/queryBuilder.d.ts +33 -0
- package/context/db/impl/queryBuilder.js +72 -0
- package/context/db/impl/transaction/index.d.ts +25 -0
- package/context/db/impl/transaction/index.js +300 -0
- package/context/db/impl/transaction/operation.d.ts +27 -0
- package/context/db/impl/transaction/operation.js +69 -0
- package/context/db/impl/transaction.d.ts +70 -0
- package/context/db/impl/transaction.js +4 -0
- package/context/globalConfig/globalConfig.d.ts +7 -0
- package/context/globalConfig/globalConfig.js +16 -0
- package/context/integration/IIntegration.d.ts +30 -0
- package/context/integration/IIntegration.js +4 -0
- package/context/integration/impl/integration.d.ts +16 -0
- package/context/integration/impl/integration.js +62 -0
- package/context/metadata/components/common.d.ts +6 -0
- package/context/metadata/components/common.js +17 -0
- package/context/metadata/components/components.d.ts +12 -0
- package/context/metadata/components/components.js +19 -0
- package/context/metadata/components/desktop/list.d.ts +16 -0
- package/context/metadata/components/desktop/list.js +402 -0
- package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
- package/context/metadata/components/desktop/recordDetail.js +53 -0
- package/context/metadata/components/mobile/list.d.ts +24 -0
- package/context/metadata/components/mobile/list.js +145 -0
- package/context/metadata/metadata.d.ts +63 -0
- package/context/metadata/metadata.js +125 -0
- package/context/metadata/objects/fields.d.ts +158 -0
- package/context/metadata/objects/fields.js +369 -0
- package/context/metadata/objects/fields.util.d.ts +52 -0
- package/context/metadata/objects/fields.util.js +420 -0
- package/context/metadata/objects/fieldsV3.d.ts +159 -0
- package/context/metadata/objects/fieldsV3.js +369 -0
- package/context/metadata/objects/objects.d.ts +11 -0
- package/context/metadata/objects/objects.js +20 -0
- package/context/metadata/types/common.d.ts +11 -0
- package/context/metadata/types/common.js +33 -0
- package/context/metadata/types/components.d.ts +90 -0
- package/context/metadata/types/components.js +4 -0
- package/context/metadata/types/objects.d.ts +246 -0
- package/context/metadata/types/objects.js +4 -0
- package/context/metadata/types/objectsV3.d.ts +128 -0
- package/context/metadata/types/objectsV3.js +4 -0
- package/context/msg/msg.d.ts +38 -0
- package/context/msg/msg.js +35 -0
- package/context/resources/IResources.d.ts +68 -0
- package/context/resources/IResources.js +2 -0
- package/context/resources/impl/resources.d.ts +42 -0
- package/context/resources/impl/resources.js +161 -0
- package/context/tasks/tasks.d.ts +33 -0
- package/context/tasks/tasks.js +139 -0
- package/data/index.d.ts +27 -0
- package/data/index.js +4 -0
- package/global/application/flow/flow.d.ts +99 -0
- package/global/application/flow/flow.js +8 -0
- package/global/application/flow/impl/flow.d.ts +20 -0
- package/global/application/flow/impl/flow.js +56 -0
- package/global/application/globalVar/globalVar.d.ts +7 -0
- package/global/application/globalVar/globalVar.js +2 -0
- package/global/global.d.ts +70 -0
- package/global/global.js +3 -0
- package/hooks/api.d.ts +65 -0
- package/hooks/api.js +347 -0
- package/hooks/hooks.d.ts +1 -0
- package/hooks/hooks.js +107 -0
- package/kunlun/kunlun.d.ts +55 -0
- package/kunlun/kunlun.js +58 -0
- package/kunlun/operator/IOperator.d.ts +158 -0
- package/kunlun/operator/IOperator.js +4 -0
- package/kunlun/operator/impl/expression.d.ts +75 -0
- package/kunlun/operator/impl/expression.js +96 -0
- package/kunlun/operator/impl/logic.d.ts +68 -0
- package/kunlun/operator/impl/logic.js +573 -0
- package/kunlun/operator/impl/logicV2.d.ts +59 -0
- package/kunlun/operator/impl/logicV2.js +197 -0
- package/kunlun/operator/impl/operator.d.ts +179 -0
- package/kunlun/operator/impl/operator.js +222 -0
- package/kunlun/operator/impl/operatorV2.d.ts +180 -0
- package/kunlun/operator/impl/operatorV2.js +216 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js +19 -0
- package/package.json +1 -1
- package/request/common.d.ts +13 -0
- package/request/common.js +88 -0
- package/request/constants.d.ts +12 -0
- package/request/constants.js +29 -0
- package/request/faasinfra.d.ts +8 -0
- package/request/faasinfra.js +146 -0
- package/request/interface.d.ts +121 -0
- package/request/interface.js +30 -0
- package/request/openapi.d.ts +84 -0
- package/request/openapi.js +1533 -0
- package/request/structs.d.ts +99 -0
- package/request/structs.js +15 -0
- package/types/types.d.ts +79 -0
- package/types/types.js +4 -0
- package/version/version.d.ts +2 -0
- package/version/version.js +8 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { _Cond, _Record, _WhereCond } from '../../../types/types';
|
|
2
|
+
import { BatchResult } from '../../../common/structs';
|
|
3
|
+
export interface _IKAllEndpoint<T> extends _IKSyncEndpoint<T>, _IKAsyncEndpoint<T> {
|
|
4
|
+
}
|
|
5
|
+
export interface _IKSyncEndpoint<T> {
|
|
6
|
+
/**
|
|
7
|
+
* 创建记录
|
|
8
|
+
* @param recordMap 用于创建的一条记录
|
|
9
|
+
* @paramExample {_name: 'John', age: 19, gender: 'male'}
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* application.data.object('_department').create({
|
|
13
|
+
* _name: new application.constants.type.Multilingual({ zh: '部门' }),
|
|
14
|
+
* _manager: { _id: 1660000000 },
|
|
15
|
+
* _status: '_active'
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
create(recordMap: _Cond<T>): Promise<{
|
|
20
|
+
_id: number | string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* 删除记录
|
|
24
|
+
* @param recordID 用于删除的一条记录的 ID
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* application.data.object('_user').delete(123456789123)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
delete(recordID: number): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* 删除记录
|
|
33
|
+
* @param record 用于删除的一条完整记录
|
|
34
|
+
* @example
|
|
35
|
+
* ```
|
|
36
|
+
* application.data.object('_user').delete(context.targetRecord.original)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
delete(record: _Cond<T>): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 指定 _id 后,更新对应记录
|
|
42
|
+
* @param _id 主键
|
|
43
|
+
* @param recordMap 用于更新的一条记录
|
|
44
|
+
* @paramExample {_name: 'John', age: 19, gender: 'male'}
|
|
45
|
+
* @example
|
|
46
|
+
* ```
|
|
47
|
+
* application.data.object('_user').update(1660000000, {
|
|
48
|
+
* gender: 'male'
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
update(_id: number, recordMap: _Cond<T>): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* 指定 _id 后,更新对应记录
|
|
55
|
+
* @param recordMap 用于更新的一条记录,需对 _id 赋值
|
|
56
|
+
* @paramExample {_id: 1660000000, _name: 'John', age: 19, gender: 'male'}
|
|
57
|
+
* @example
|
|
58
|
+
* ```
|
|
59
|
+
* application.data.object('_user').update({
|
|
60
|
+
* _id: 1660000000,
|
|
61
|
+
* gender: 'male'
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
update(recordMap: _Cond<T>): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* 批量创建记录
|
|
68
|
+
* @param recordMapList 多条用于创建的记录数据组成的数组
|
|
69
|
+
* @paramExample [{_name: 'John', age: 19, gender: 'male'}, {_name: 'Alis', age: 16, gender: 'female'}]
|
|
70
|
+
*/
|
|
71
|
+
batchCreate(recordMapList: _Cond<T>[]): Promise<number[] | string[]>;
|
|
72
|
+
/**
|
|
73
|
+
* 批量删除记录
|
|
74
|
+
* @param recordIdList 多个用于删除的记录 ID 组成的数组
|
|
75
|
+
* @paramExample [1001, 1002, 1003]
|
|
76
|
+
*/
|
|
77
|
+
batchDelete(recordIdList: number[]): Promise<BatchResult>;
|
|
78
|
+
/**
|
|
79
|
+
* 批量删除记录
|
|
80
|
+
* @param recordList 多条用于删除的记录数据组成的数组,记录数据需对 _id 赋值
|
|
81
|
+
* @paramExample [{_id: 1001, _name: 'John', gender: 'male'}, {_id: 1002, _name: 'Alis', gender: 'female'}]
|
|
82
|
+
*/
|
|
83
|
+
batchDelete(recordList: _Cond<T>[]): Promise<BatchResult>;
|
|
84
|
+
/**
|
|
85
|
+
* 根据 _id 批量更新记录
|
|
86
|
+
* @param recordMapList 多条用于更新的记录数据组成的数组,记录数据需对 _id 赋值
|
|
87
|
+
* @paramExample [{_id: 1001, _name: 'John', gender: 'male'}, {_id: 1002, _name: 'Alis', gender: 'female'}]
|
|
88
|
+
*/
|
|
89
|
+
batchUpdate(recordMapList: _Cond<T>[]): Promise<BatchResult>;
|
|
90
|
+
/**
|
|
91
|
+
* 用户级鉴权
|
|
92
|
+
*/
|
|
93
|
+
useUserAuth(): this;
|
|
94
|
+
/**
|
|
95
|
+
* 系统级鉴权
|
|
96
|
+
*/
|
|
97
|
+
useSystemAuth(): this;
|
|
98
|
+
}
|
|
99
|
+
export interface _IKAsyncEndpoint<T> {
|
|
100
|
+
/**
|
|
101
|
+
* 批量创建记录(为异步任务)
|
|
102
|
+
* @param recordMapList 用于创建的多条记录
|
|
103
|
+
* @paramExample [{_name: 'John', age: 19, gender: 'male'}, {_name: 'Alis', age: 16, gender: 'female'}]
|
|
104
|
+
*/
|
|
105
|
+
batchCreateAsync(recordMapList: _Cond<T>[]): Promise<{
|
|
106
|
+
taskID: number;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* 批量删除记录(为异步任务)
|
|
110
|
+
* @param recordIDList 用于删除的多条记录的 ID 列表
|
|
111
|
+
*/
|
|
112
|
+
batchDeleteAsync(recordIDList: number[]): Promise<{
|
|
113
|
+
taskID: number;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* 批量删除记录(为异步任务)
|
|
117
|
+
* @param recordList 用于删除的多条完整记录的列表
|
|
118
|
+
*/
|
|
119
|
+
batchDeleteAsync(recordList: _Cond<T>[]): Promise<{
|
|
120
|
+
taskID: number;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* 根据 _id 批量更新记录(为异步任务)
|
|
124
|
+
* @param recordMapList 用于更新的多条记录,需对 _id 赋值
|
|
125
|
+
* @paramExample [{_id: 1001, _name: 'John', gender: 'male'}, {_id: 1002, _name: 'Alis', gender: 'female'}]
|
|
126
|
+
*/
|
|
127
|
+
batchUpdateAsync(recordMapList: _Cond<T>[]): Promise<{
|
|
128
|
+
taskID: number;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* 用户级鉴权
|
|
132
|
+
*/
|
|
133
|
+
useUserAuth(): this;
|
|
134
|
+
/**
|
|
135
|
+
* 系统级鉴权
|
|
136
|
+
*/
|
|
137
|
+
useSystemAuth(): this;
|
|
138
|
+
}
|
|
139
|
+
export interface _IKQuery<T> {
|
|
140
|
+
/**
|
|
141
|
+
* @Deprecated Use FindStream instead.
|
|
142
|
+
*
|
|
143
|
+
* 无需入参,返回全部符合条件的记录
|
|
144
|
+
* @example
|
|
145
|
+
* ```
|
|
146
|
+
* application.data.object('_user').where({
|
|
147
|
+
* gender: 'male'
|
|
148
|
+
* }).findAll()
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
findAll(): Promise<_Record<T>[]>;
|
|
152
|
+
/**
|
|
153
|
+
* 遍历全部符合条件的记录
|
|
154
|
+
* 注:
|
|
155
|
+
* 如果未设置排序字段,默认以 _id 增序查询;
|
|
156
|
+
* 如果有设置排序字段,必须设置具有唯一属性的字段,否则会有数据重复的风险;
|
|
157
|
+
* @param handler 业务处理函数
|
|
158
|
+
* @param pageLimit 分页查询的数量,可选参数,默认值为 200,
|
|
159
|
+
* @example
|
|
160
|
+
* ```
|
|
161
|
+
* await application.data.object('_user').findStream(async (records) => {
|
|
162
|
+
* // doSomething ...
|
|
163
|
+
* }, 300);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
findStream: (handler: (records: object[]) => Promise<void>, pageLimit?: number) => Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* 无需入参,返回符合条件的记录,单次返回 200 条
|
|
169
|
+
* @example
|
|
170
|
+
* ```
|
|
171
|
+
* application.data.object('_user').where({
|
|
172
|
+
* gender: 'male'
|
|
173
|
+
* }).find()
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
find(): Promise<_Record<T>[]>;
|
|
177
|
+
/**
|
|
178
|
+
* 无需入参,返回排在第一位的记录
|
|
179
|
+
* @example
|
|
180
|
+
* ```
|
|
181
|
+
* application.data.object('_user').where({
|
|
182
|
+
* gender: 'male'
|
|
183
|
+
* }).findOne()
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
findOne(): Promise<_Record<T>>;
|
|
187
|
+
/**
|
|
188
|
+
* 根据指定字段升序排序(a -> z, 0 -> 9)
|
|
189
|
+
* @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
|
|
190
|
+
* @example
|
|
191
|
+
* ```
|
|
192
|
+
* application.data.object('_user').orderBy(['_email', '_phoneNumber']).find()
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
orderBy<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
196
|
+
/**
|
|
197
|
+
* 根据指定字段升序排序(a -> z, 0 -> 9)
|
|
198
|
+
* @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
|
|
199
|
+
* @example
|
|
200
|
+
* ```
|
|
201
|
+
* application.data.object('_user').orderBy('_email', '_phoneNumber').find()
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
orderBy<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
205
|
+
/**
|
|
206
|
+
* 根据指定字段降序排序(z -> a, 9 -> 0)
|
|
207
|
+
* @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
|
|
208
|
+
* @example
|
|
209
|
+
* ```
|
|
210
|
+
* application.data.object('_user').orderByDesc('_email', '_phoneNumber').find()
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
orderByDesc<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
214
|
+
/**
|
|
215
|
+
* 根据指定字段降序排序(z -> a, 9 -> 0)
|
|
216
|
+
* @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
|
|
217
|
+
* @example
|
|
218
|
+
* ```
|
|
219
|
+
* application.data.object('_user').orderByDesc('_email', '_phoneNumber').find()
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
orderByDesc<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
223
|
+
/**
|
|
224
|
+
* 指定需返回的字段
|
|
225
|
+
* @param fieldApiNames 需返回的字段数组
|
|
226
|
+
* @example
|
|
227
|
+
* ```
|
|
228
|
+
* application.data.object('_user').select(['_name', '_email']).find()
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
select<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
232
|
+
/**
|
|
233
|
+
* 指定需返回的字段
|
|
234
|
+
* @param fieldApiNames 需返回的字段,用逗号分隔
|
|
235
|
+
* @example
|
|
236
|
+
* ```
|
|
237
|
+
* application.data.object('_user').select('_name', '_email').find()
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
select<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
241
|
+
/**
|
|
242
|
+
* 设置查询条件
|
|
243
|
+
* @param conditionMap 对字段赋值以指定查询筛选条件
|
|
244
|
+
* @paramExample {gender: 'male'}
|
|
245
|
+
* @example
|
|
246
|
+
* ```
|
|
247
|
+
* application.data.object('_user').where({
|
|
248
|
+
* gender: 'male'
|
|
249
|
+
* }).find()
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
where(conditionMap: _WhereCond<T>): Omit<_IKQuery<T>, 'findAll'>;
|
|
253
|
+
/**
|
|
254
|
+
* 设置查询条件
|
|
255
|
+
*/
|
|
256
|
+
where(): Omit<_IKQuery<T>, 'findAll'>;
|
|
257
|
+
/**
|
|
258
|
+
* 模糊查询:与 where 之间是与关系
|
|
259
|
+
* @param keyword 模糊查询的关键字,必填且不可以为空串
|
|
260
|
+
* @param fieldAPINames 『可搜索字段』的字段列表,不可为空
|
|
261
|
+
* @example
|
|
262
|
+
* ```
|
|
263
|
+
* application.data.object('_user').fuzzySearch('张三', ['_name']).find()
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
fuzzySearch(keyword: string, fieldAPINames: string[]): Omit<_IKQuery<T>, 'findAll'>;
|
|
267
|
+
/**
|
|
268
|
+
* 指定分页查询的数量
|
|
269
|
+
* @param limit 分页查询的数量
|
|
270
|
+
* @paramExample 10
|
|
271
|
+
* @example
|
|
272
|
+
* ```
|
|
273
|
+
* application.data.object('_user').limit(10)
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
limit(limit: number): Omit<_IKQuery<T>, 'findAll'>;
|
|
277
|
+
/**
|
|
278
|
+
* 指定分页查询的偏移量
|
|
279
|
+
* @param offset 分页查询的偏移量
|
|
280
|
+
* @paramExample 0
|
|
281
|
+
* @example
|
|
282
|
+
* ```
|
|
283
|
+
* application.data.object('_user').offset(0)
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
offset(offset: number): Omit<_IKQuery<T>, 'findAll'>;
|
|
287
|
+
/**
|
|
288
|
+
* 指定条件的行数
|
|
289
|
+
* @example
|
|
290
|
+
* ```
|
|
291
|
+
* application.data.object('_user').count()
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
count(): Promise<number>;
|
|
295
|
+
/**
|
|
296
|
+
* 用户级鉴权
|
|
297
|
+
*/
|
|
298
|
+
useUserAuth(): this;
|
|
299
|
+
/**
|
|
300
|
+
* 系统级鉴权
|
|
301
|
+
*/
|
|
302
|
+
useSystemAuth(): this;
|
|
303
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { _Cond, _Record, _WhereCond } from '../../../types/types';
|
|
2
|
+
import { BatchResult } from '../../../common/structs';
|
|
3
|
+
export interface _IKAllEndpointV3<T> extends _IKSyncEndpointV3<T>, _IKAsyncEndpointV3<T> {
|
|
4
|
+
}
|
|
5
|
+
export interface _IKSyncEndpointV3<T> {
|
|
6
|
+
/**
|
|
7
|
+
* 创建记录
|
|
8
|
+
* @param recordMap 用于创建的一条记录
|
|
9
|
+
* @paramExample {_name: 'John', age: 19, gender: 'male'}
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* application.data.object('_department').create({
|
|
13
|
+
* _name: new application.constants.type.Multilingual({ zh: '部门' }),
|
|
14
|
+
* _manager: { _id: 1660000000 },
|
|
15
|
+
* _status: '_active'
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
create(recordMap: _Cond<T>): Promise<{
|
|
20
|
+
_id: number | string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* 删除记录
|
|
24
|
+
* @param recordID 用于删除的一条完整记录
|
|
25
|
+
* @example 传 id
|
|
26
|
+
* ```
|
|
27
|
+
* application.data.object('_user').delete("123456789123")
|
|
28
|
+
* ```
|
|
29
|
+
* @example 传记录
|
|
30
|
+
* ```
|
|
31
|
+
* application.data.object('_user').delete(context.targetRecord.original)
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
delete(recordID: number | string | _Cond<T>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* 指定 _id 后,更新对应记录
|
|
37
|
+
* @param _id 主键
|
|
38
|
+
* @param recordMap 用于更新的一条记录
|
|
39
|
+
* @paramExample {_name: 'John', age: 19, gender: 'male'}
|
|
40
|
+
* @example
|
|
41
|
+
* ```
|
|
42
|
+
* application.data.object('_user').update(1660000000, {
|
|
43
|
+
* gender: 'male'
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
update(_id: number | string, recordMap: _Cond<T>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* 指定 _id 后,更新对应记录
|
|
50
|
+
* @param recordMap 用于更新的一条记录,需对 _id 赋值
|
|
51
|
+
* @paramExample {_id: 1660000000, _name: 'John', age: 19, gender: 'male'}
|
|
52
|
+
* @example
|
|
53
|
+
* ```
|
|
54
|
+
* application.data.object('_user').update({
|
|
55
|
+
* _id: 1660000000,
|
|
56
|
+
* gender: 'male'
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
update(recordMap: _Cond<T>): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* 批量创建记录
|
|
63
|
+
* @param recordMapList 多条用于创建的记录数据组成的数组
|
|
64
|
+
* @paramExample [{_name: 'John', age: 19, gender: 'male'}, {_name: 'Alis', age: 16, gender: 'female'}]
|
|
65
|
+
*/
|
|
66
|
+
batchCreate(recordMapList: _Cond<T>[]): Promise<number[] | string[]>;
|
|
67
|
+
/**
|
|
68
|
+
* 批量删除记录
|
|
69
|
+
* @param recordList 多个用于删除的记录 ID 组成的数组,或者多条用于删除的记录数据组成的数组,记录数据需对 _id 赋值
|
|
70
|
+
* @paramExample [{_id: 1001, _name: 'John', gender: 'male'}, {_id: 1002, _name: 'Alis', gender: 'female'}]
|
|
71
|
+
* @paramExample [1001, 1002, 1003]
|
|
72
|
+
*/
|
|
73
|
+
batchDelete(recordList: string[] | _Cond<T>[]): Promise<BatchResult>;
|
|
74
|
+
/**
|
|
75
|
+
* 根据 _id 批量更新记录
|
|
76
|
+
* @param recordMapList 多条用于更新的记录数据组成的数组,记录数据需对 _id 赋值
|
|
77
|
+
* @paramExample [{_id: 1001, _name: 'John', gender: 'male'}, {_id: 1002, _name: 'Alis', gender: 'female'}]
|
|
78
|
+
*/
|
|
79
|
+
batchUpdate(recordMapList: _Cond<T>[]): Promise<BatchResult>;
|
|
80
|
+
/**
|
|
81
|
+
* 用户级鉴权
|
|
82
|
+
*/
|
|
83
|
+
useUserAuth(): this;
|
|
84
|
+
/**
|
|
85
|
+
* 系统级鉴权
|
|
86
|
+
*/
|
|
87
|
+
useSystemAuth(): this;
|
|
88
|
+
}
|
|
89
|
+
export interface _IKAsyncEndpointV3<T> {
|
|
90
|
+
}
|
|
91
|
+
export interface _IKQueryV3<T> {
|
|
92
|
+
/**
|
|
93
|
+
* 遍历全部符合条件的记录
|
|
94
|
+
* 注:
|
|
95
|
+
* 如果未设置排序字段,默认以 _id 增序查询;
|
|
96
|
+
* 如果有设置排序字段,必须设置具有唯一属性的字段,否则会有数据重复的风险;
|
|
97
|
+
* @param handler 业务处理函数
|
|
98
|
+
* @param pageLimit 分页查询的数量,可选参数,默认值为 200,
|
|
99
|
+
* @example
|
|
100
|
+
* ```
|
|
101
|
+
* await application.data.object('_user').findStream(async (records) => {
|
|
102
|
+
* // doSomething ...
|
|
103
|
+
* }, 300);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
findStream: (handler: (records: object[]) => Promise<void>, pageLimit?: number) => Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* 无需入参,返回符合条件的记录,单次返回 200 条
|
|
109
|
+
* @example
|
|
110
|
+
* ```
|
|
111
|
+
* application.data.object('_user').where({
|
|
112
|
+
* gender: 'male'
|
|
113
|
+
* }).find()
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
find(): Promise<_Record<T>[]>;
|
|
117
|
+
/**
|
|
118
|
+
* 无需入参,返回排在第一位的记录
|
|
119
|
+
* @example
|
|
120
|
+
* ```
|
|
121
|
+
* application.data.object('_user').where({
|
|
122
|
+
* gender: 'male'
|
|
123
|
+
* }).findOne()
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
findOne(): Promise<_Record<T>>;
|
|
127
|
+
/**
|
|
128
|
+
* 根据指定字段升序排序(a -> z, 0 -> 9)
|
|
129
|
+
* @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
|
|
130
|
+
* @example
|
|
131
|
+
* ```
|
|
132
|
+
* application.data.object('_user').orderBy(['_email', '_phoneNumber']).find()
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
orderBy<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
136
|
+
/**
|
|
137
|
+
* 根据指定字段升序排序(a -> z, 0 -> 9)
|
|
138
|
+
* @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
|
|
139
|
+
* @example
|
|
140
|
+
* ```
|
|
141
|
+
* application.data.object('_user').orderBy('_email', '_phoneNumber').find()
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
orderBy<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
145
|
+
/**
|
|
146
|
+
* 根据指定字段降序排序(z -> a, 9 -> 0)
|
|
147
|
+
* @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
|
|
148
|
+
* @example
|
|
149
|
+
* ```
|
|
150
|
+
* application.data.object('_user').orderByDesc('_email', '_phoneNumber').find()
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
orderByDesc<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
154
|
+
/**
|
|
155
|
+
* 根据指定字段降序排序(z -> a, 9 -> 0)
|
|
156
|
+
* @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
|
|
157
|
+
* @example
|
|
158
|
+
* ```
|
|
159
|
+
* application.data.object('_user').orderByDesc('_email', '_phoneNumber').find()
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
orderByDesc<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
163
|
+
/**
|
|
164
|
+
* 指定需返回的字段
|
|
165
|
+
* @param fieldApiNames 需返回的字段数组
|
|
166
|
+
* @example
|
|
167
|
+
* ```
|
|
168
|
+
* application.data.object('_user').select(['_name', '_email']).find()
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
select<K extends keyof T>(fieldApiNames: K[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
172
|
+
/**
|
|
173
|
+
* 指定需返回的字段
|
|
174
|
+
* @param fieldApiNames 需返回的字段,用逗号分隔
|
|
175
|
+
* @example
|
|
176
|
+
* ```
|
|
177
|
+
* application.data.object('_user').select('_name', '_email').find()
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
select<K extends keyof T>(...fieldApiNames: K[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
181
|
+
/**
|
|
182
|
+
* 设置查询条件
|
|
183
|
+
* @param conditionMap 对字段赋值以指定查询筛选条件
|
|
184
|
+
* @paramExample {gender: 'male'}
|
|
185
|
+
* @example
|
|
186
|
+
* ```
|
|
187
|
+
* application.data.object('_user').where({
|
|
188
|
+
* gender: 'male'
|
|
189
|
+
* }).find()
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
where(conditionMap?: _WhereCond<T>): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
193
|
+
/**
|
|
194
|
+
* 模糊查询:与 where 之间是与关系
|
|
195
|
+
* @param keyword 模糊查询的关键字,必填且不可以为空串
|
|
196
|
+
* @param fieldAPINames 『可搜索字段』的字段列表,不可为空
|
|
197
|
+
* @example
|
|
198
|
+
* ```
|
|
199
|
+
* application.data.object('_user').fuzzySearch('张三', ['_name']).find()
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
fuzzySearch(keyword: string, fieldAPINames: string[]): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
203
|
+
/**
|
|
204
|
+
* 指定分页查询的数量
|
|
205
|
+
* @param limit 分页查询的数量
|
|
206
|
+
* @paramExample 10
|
|
207
|
+
* @example
|
|
208
|
+
* ```
|
|
209
|
+
* application.data.object('_user').limit(10)
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
limit(limit: number): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
213
|
+
/**
|
|
214
|
+
* 指定分页查询的偏移量
|
|
215
|
+
* @param offset 分页查询的偏移量
|
|
216
|
+
* @paramExample 0
|
|
217
|
+
* @example
|
|
218
|
+
* ```
|
|
219
|
+
* application.data.object('_user').offset(0)
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
offset(offset: number): Omit<_IKQueryV3<T>, 'findAll'>;
|
|
223
|
+
/**
|
|
224
|
+
* 指定条件的行数
|
|
225
|
+
* @example
|
|
226
|
+
* ```
|
|
227
|
+
* application.data.object('_user').count()
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
count(): Promise<number>;
|
|
231
|
+
/**
|
|
232
|
+
* 用户级鉴权
|
|
233
|
+
*/
|
|
234
|
+
useUserAuth(): this;
|
|
235
|
+
/**
|
|
236
|
+
* 系统级鉴权
|
|
237
|
+
*/
|
|
238
|
+
useSystemAuth(): this;
|
|
239
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { _IKAllEndpoint, _IKSyncEndpoint, _IKQuery } from './IObject';
|
|
2
|
+
import { ITransactionGetter } from './transaction';
|
|
3
|
+
import { IDB, IDBSync, IDBWithCurrentObject } from '../db';
|
|
4
|
+
import { currentObjApiName, metadataMap } from '../../../data/index';
|
|
5
|
+
import { IOql } from './oql/ioql';
|
|
6
|
+
import { AppCtx } from '../../../application/application';
|
|
7
|
+
export declare class DB<T, mt = metadataMap> implements IDB<T, mt> {
|
|
8
|
+
objectApiName: string;
|
|
9
|
+
constructor(objectApiName?: string);
|
|
10
|
+
/**
|
|
11
|
+
* 操作指定对象的记录数据
|
|
12
|
+
* @param objectApiName 指定对象的 ApiName
|
|
13
|
+
* @example
|
|
14
|
+
* ```
|
|
15
|
+
* context.db.object('_user').where({
|
|
16
|
+
* gender: 'male'
|
|
17
|
+
* }).find()
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
object<K extends keyof mt>(objectApiName: K): _IKAllEndpoint<mt[K]> & _IKQuery<mt[K]>;
|
|
21
|
+
/**
|
|
22
|
+
* 创建一个新的空事务
|
|
23
|
+
* @example
|
|
24
|
+
* ```
|
|
25
|
+
* let tx = context.db.newTransaction();
|
|
26
|
+
* let user = tx.object('_user').registerCreate({
|
|
27
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1', en: 'user1' }),
|
|
28
|
+
* });
|
|
29
|
+
* let contract = tx.object('contract').registerCreate({
|
|
30
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1的合同', en: 'user1's contract' }),
|
|
31
|
+
* user: {id: user._id}
|
|
32
|
+
* });
|
|
33
|
+
* await tx.commit();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
newTransaction(): ITransactionGetter<T, mt>;
|
|
37
|
+
/**
|
|
38
|
+
* OQL 操作
|
|
39
|
+
* @param oql 指定 OQL 语句
|
|
40
|
+
* @example
|
|
41
|
+
* ```
|
|
42
|
+
* let users = await context.db.oql('select _email from _user').execute();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
oql(oql: string): IOql;
|
|
46
|
+
oql(oql: string, nameArgs: Record<string, any>): IOql;
|
|
47
|
+
}
|
|
48
|
+
export declare class DBWithCurrentObject<T, mt = metadataMap> extends DB<T, mt> implements IDB<T, mt>, IDBWithCurrentObject<T, mt> {
|
|
49
|
+
/**
|
|
50
|
+
* 无需入参,操作当前对象的记录数据
|
|
51
|
+
*/
|
|
52
|
+
currentObject(): _IKAllEndpoint<mt[currentObjApiName]> & _IKQuery<mt[currentObjApiName]>;
|
|
53
|
+
constructor(objectApiName: string);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* ApplicationDB: 用于支持 OpenSDK 相关能力的 DB 相关类,目前仅实现 DB 同步操作接口
|
|
57
|
+
*/
|
|
58
|
+
export declare class ApplicationDB implements IDBSync {
|
|
59
|
+
appCtx: AppCtx;
|
|
60
|
+
constructor(appCtx: AppCtx);
|
|
61
|
+
object(objectApiName: string): _IKSyncEndpoint<{}> & _IKQuery<{}>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationDB = exports.DBWithCurrentObject = exports.DB = void 0;
|
|
4
|
+
const object_1 = require("./object");
|
|
5
|
+
const server_common_node_1 = require("@byted-apaas/server-common-node");
|
|
6
|
+
const index_1 = require("./transaction/index");
|
|
7
|
+
const oql_1 = require("./oql/oql");
|
|
8
|
+
class DB {
|
|
9
|
+
constructor(objectApiName) {
|
|
10
|
+
this.objectApiName = objectApiName;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 操作指定对象的记录数据
|
|
14
|
+
* @param objectApiName 指定对象的 ApiName
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* context.db.object('_user').where({
|
|
18
|
+
* gender: 'male'
|
|
19
|
+
* }).find()
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
object(objectApiName) {
|
|
23
|
+
return new object_1._KObject(objectApiName);
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
/**
|
|
27
|
+
* 创建一个新的空事务
|
|
28
|
+
* @example
|
|
29
|
+
* ```
|
|
30
|
+
* let tx = context.db.newTransaction();
|
|
31
|
+
* let user = tx.object('_user').registerCreate({
|
|
32
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1', en: 'user1' }),
|
|
33
|
+
* });
|
|
34
|
+
* let contract = tx.object('contract').registerCreate({
|
|
35
|
+
* _name: new kunlun.type.Multilingual({ zh: '用户1的合同', en: 'user1's contract' }),
|
|
36
|
+
* user: {id: user._id}
|
|
37
|
+
* });
|
|
38
|
+
* await tx.commit();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
newTransaction() {
|
|
42
|
+
const appCtx = {
|
|
43
|
+
dataVersion: 'v1',
|
|
44
|
+
};
|
|
45
|
+
return new index_1.Transaction(this.objectApiName, appCtx);
|
|
46
|
+
}
|
|
47
|
+
;
|
|
48
|
+
oql(oql, nameArgs) {
|
|
49
|
+
if (nameArgs) {
|
|
50
|
+
return new oql_1.Oql(oql, nameArgs);
|
|
51
|
+
}
|
|
52
|
+
return new oql_1.Oql(oql);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.DB = DB;
|
|
56
|
+
class DBWithCurrentObject extends DB {
|
|
57
|
+
/**
|
|
58
|
+
* 无需入参,操作当前对象的记录数据
|
|
59
|
+
*/
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
currentObject() {
|
|
62
|
+
if (!this.objectApiName) {
|
|
63
|
+
throw new server_common_node_1.exceptions.InternalError(`context.objectApiName is empty`);
|
|
64
|
+
}
|
|
65
|
+
return new object_1._KObject(this.objectApiName);
|
|
66
|
+
}
|
|
67
|
+
;
|
|
68
|
+
constructor(objectApiName) {
|
|
69
|
+
super(objectApiName);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.DBWithCurrentObject = DBWithCurrentObject;
|
|
73
|
+
/**
|
|
74
|
+
* ApplicationDB: 用于支持 OpenSDK 相关能力的 DB 相关类,目前仅实现 DB 同步操作接口
|
|
75
|
+
*/
|
|
76
|
+
class ApplicationDB {
|
|
77
|
+
constructor(appCtx) {
|
|
78
|
+
this.appCtx = appCtx;
|
|
79
|
+
}
|
|
80
|
+
object(objectApiName) {
|
|
81
|
+
return new object_1._KApplicationObject(objectApiName, this.appCtx);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ApplicationDB = ApplicationDB;
|