@byted-apaas/server-sdk-node 0.0.2-beta.1
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/LICENSE.md +0 -0
- package/README.md +1 -0
- package/application/application.d.ts +27 -0
- package/application/application.js +3 -0
- package/application/application.js.map +1 -0
- package/application/application.ts +40 -0
- package/application/function/function.d.ts +14 -0
- package/application/function/function.js +22 -0
- package/application/function/function.js.map +1 -0
- package/application/function/function.ts +37 -0
- package/application/impl/common.d.ts +2 -0
- package/application/impl/common.js +51 -0
- package/application/impl/common.js.map +1 -0
- package/application/impl/common.ts +50 -0
- package/application/impl/impl.d.ts +16 -0
- package/application/impl/impl.js +39 -0
- package/application/impl/impl.js.map +1 -0
- package/application/impl/impl.ts +48 -0
- package/constants/constants.d.ts +10 -0
- package/constants/constants.js +14 -0
- package/constants/constants.js.map +1 -0
- package/constants/constants.ts +12 -0
- package/context/context.d.ts +74 -0
- package/context/context.js +24 -0
- package/context/context.js.map +1 -0
- package/context/context.ts +127 -0
- package/context/db/db.d.ts +73 -0
- package/context/db/db.js +3 -0
- package/context/db/db.js.map +1 -0
- package/context/db/db.ts +77 -0
- package/context/db/impl/IObject.d.ts +251 -0
- package/context/db/impl/IObject.js +4 -0
- package/context/db/impl/IObject.js.map +1 -0
- package/context/db/impl/IObject.ts +244 -0
- package/context/db/impl/db.d.ts +61 -0
- package/context/db/impl/db.js +87 -0
- package/context/db/impl/db.js.map +1 -0
- package/context/db/impl/db.ts +95 -0
- package/context/db/impl/object.d.ts +92 -0
- package/context/db/impl/object.js +523 -0
- package/context/db/impl/object.js.map +1 -0
- package/context/db/impl/object.ts +628 -0
- package/context/db/impl/oql/ioql.d.ts +6 -0
- package/context/db/impl/oql/ioql.js +3 -0
- package/context/db/impl/oql/ioql.js.map +1 -0
- package/context/db/impl/oql/ioql.ts +6 -0
- package/context/db/impl/oql/oql.d.ts +8 -0
- package/context/db/impl/oql/oql.js +20 -0
- package/context/db/impl/oql/oql.js.map +1 -0
- package/context/db/impl/oql/oql.ts +22 -0
- package/context/db/impl/order.d.ts +9 -0
- package/context/db/impl/order.js +14 -0
- package/context/db/impl/order.js.map +1 -0
- package/context/db/impl/order.ts +16 -0
- package/context/db/impl/propertiesStore.d.ts +8 -0
- package/context/db/impl/propertiesStore.js +28 -0
- package/context/db/impl/propertiesStore.js.map +1 -0
- package/context/db/impl/propertiesStore.ts +28 -0
- package/context/db/impl/queryBuilder.d.ts +29 -0
- package/context/db/impl/queryBuilder.js +77 -0
- package/context/db/impl/queryBuilder.js.map +1 -0
- package/context/db/impl/queryBuilder.ts +103 -0
- package/context/db/impl/transaction/index.d.ts +20 -0
- package/context/db/impl/transaction/index.js +276 -0
- package/context/db/impl/transaction/index.js.map +1 -0
- package/context/db/impl/transaction/index.ts +337 -0
- package/context/db/impl/transaction/operation.d.ts +27 -0
- package/context/db/impl/transaction/operation.js +70 -0
- package/context/db/impl/transaction/operation.js.map +1 -0
- package/context/db/impl/transaction/operation.ts +72 -0
- package/context/db/impl/transaction.d.ts +67 -0
- package/context/db/impl/transaction.js +3 -0
- package/context/db/impl/transaction.js.map +1 -0
- package/context/db/impl/transaction.ts +76 -0
- package/context/globalConfig/globalConfig.d.ts +7 -0
- package/context/globalConfig/globalConfig.js +15 -0
- package/context/globalConfig/globalConfig.js.map +1 -0
- package/context/globalConfig/globalConfig.ts +11 -0
- package/context/metadata/components/common.d.ts +6 -0
- package/context/metadata/components/common.js +16 -0
- package/context/metadata/components/common.js.map +1 -0
- package/context/metadata/components/common.ts +19 -0
- package/context/metadata/components/components.d.ts +12 -0
- package/context/metadata/components/components.js +18 -0
- package/context/metadata/components/components.js.map +1 -0
- package/context/metadata/components/components.ts +19 -0
- package/context/metadata/components/desktop/list.d.ts +16 -0
- package/context/metadata/components/desktop/list.js +403 -0
- package/context/metadata/components/desktop/list.js.map +1 -0
- package/context/metadata/components/desktop/list.ts +457 -0
- package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
- package/context/metadata/components/desktop/recordDetail.js +52 -0
- package/context/metadata/components/desktop/recordDetail.js.map +1 -0
- package/context/metadata/components/desktop/recordDetail.ts +64 -0
- package/context/metadata/components/mobile/list.d.ts +24 -0
- package/context/metadata/components/mobile/list.js +144 -0
- package/context/metadata/components/mobile/list.js.map +1 -0
- package/context/metadata/components/mobile/list.ts +176 -0
- package/context/metadata/metadata.d.ts +61 -0
- package/context/metadata/metadata.js +102 -0
- package/context/metadata/metadata.js.map +1 -0
- package/context/metadata/metadata.ts +175 -0
- package/context/metadata/objects/fields.d.ts +130 -0
- package/context/metadata/objects/fields.js +333 -0
- package/context/metadata/objects/fields.js.map +1 -0
- package/context/metadata/objects/fields.ts +454 -0
- package/context/metadata/objects/fields.util.d.ts +40 -0
- package/context/metadata/objects/fields.util.js +320 -0
- package/context/metadata/objects/fields.util.js.map +1 -0
- package/context/metadata/objects/fields.util.ts +360 -0
- package/context/metadata/objects/objects.d.ts +11 -0
- package/context/metadata/objects/objects.js +19 -0
- package/context/metadata/objects/objects.js.map +1 -0
- package/context/metadata/objects/objects.ts +27 -0
- package/context/metadata/types/common.d.ts +6 -0
- package/context/metadata/types/common.js +8 -0
- package/context/metadata/types/common.js.map +1 -0
- package/context/metadata/types/common.ts +10 -0
- package/context/metadata/types/components.d.ts +90 -0
- package/context/metadata/types/components.js +3 -0
- package/context/metadata/types/components.js.map +1 -0
- package/context/metadata/types/components.ts +105 -0
- package/context/metadata/types/objects.d.ts +226 -0
- package/context/metadata/types/objects.js +3 -0
- package/context/metadata/types/objects.js.map +1 -0
- package/context/metadata/types/objects.ts +251 -0
- package/context/msg/msg.d.ts +38 -0
- package/context/msg/msg.js +34 -0
- package/context/msg/msg.js.map +1 -0
- package/context/msg/msg.ts +49 -0
- package/context/resources/IResources.d.ts +66 -0
- package/context/resources/IResources.js +3 -0
- package/context/resources/IResources.js.map +1 -0
- package/context/resources/IResources.ts +73 -0
- package/context/resources/impl/resources.d.ts +42 -0
- package/context/resources/impl/resources.js +149 -0
- package/context/resources/impl/resources.js.map +1 -0
- package/context/resources/impl/resources.ts +170 -0
- package/context/tasks/tasks.d.ts +33 -0
- package/context/tasks/tasks.js +140 -0
- package/context/tasks/tasks.js.map +1 -0
- package/context/tasks/tasks.ts +159 -0
- package/data/index.d.ts +27 -0
- package/data/index.js +5 -0
- package/data/index.js.map +1 -0
- package/data/index.ts +30 -0
- package/hooks/api.d.ts +61 -0
- package/hooks/api.js +328 -0
- package/hooks/api.js.map +1 -0
- package/hooks/api.ts +341 -0
- package/hooks/hooks.d.ts +1 -0
- package/hooks/hooks.js +89 -0
- package/hooks/hooks.js.map +1 -0
- package/hooks/hooks.ts +100 -0
- package/kunlun/kunlun.d.ts +55 -0
- package/kunlun/kunlun.js +57 -0
- package/kunlun/kunlun.js.map +1 -0
- package/kunlun/kunlun.ts +69 -0
- package/kunlun/operator/IOperator.d.ts +158 -0
- package/kunlun/operator/IOperator.js +3 -0
- package/kunlun/operator/IOperator.js.map +1 -0
- package/kunlun/operator/IOperator.ts +163 -0
- package/kunlun/operator/impl/expression.d.ts +47 -0
- package/kunlun/operator/impl/expression.js +55 -0
- package/kunlun/operator/impl/expression.js.map +1 -0
- package/kunlun/operator/impl/expression.ts +71 -0
- package/kunlun/operator/impl/logic.d.ts +50 -0
- package/kunlun/operator/impl/logic.js +508 -0
- package/kunlun/operator/impl/logic.js.map +1 -0
- package/kunlun/operator/impl/logic.ts +595 -0
- package/kunlun/operator/impl/logicV2.d.ts +58 -0
- package/kunlun/operator/impl/logicV2.js +201 -0
- package/kunlun/operator/impl/logicV2.js.map +1 -0
- package/kunlun/operator/impl/logicV2.ts +254 -0
- package/kunlun/operator/impl/operator.d.ts +179 -0
- package/kunlun/operator/impl/operator.js +221 -0
- package/kunlun/operator/impl/operator.js.map +1 -0
- package/kunlun/operator/impl/operator.ts +255 -0
- package/kunlun/operator/impl/operatorV2.d.ts +180 -0
- package/kunlun/operator/impl/operatorV2.js +217 -0
- package/kunlun/operator/impl/operatorV2.js.map +1 -0
- package/kunlun/operator/impl/operatorV2.ts +249 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js +18 -0
- package/lib/core.js.map +1 -0
- package/lib/core.ts +4 -0
- package/package.json +50 -0
- package/request/common.d.ts +13 -0
- package/request/common.js +88 -0
- package/request/common.js.map +1 -0
- package/request/common.ts +91 -0
- package/request/constants.d.ts +10 -0
- package/request/constants.js +26 -0
- package/request/constants.js.map +1 -0
- package/request/constants.ts +25 -0
- package/request/faasinfra.d.ts +8 -0
- package/request/faasinfra.js +359 -0
- package/request/faasinfra.js.map +1 -0
- package/request/faasinfra.ts +393 -0
- package/request/innerapi.d.ts +67 -0
- package/request/innerapi.js +1411 -0
- package/request/innerapi.js.map +1 -0
- package/request/innerapi.ts +1645 -0
- package/request/interface.d.ts +95 -0
- package/request/interface.js +40 -0
- package/request/interface.js.map +1 -0
- package/request/interface.ts +166 -0
- package/request/openapi.d.ts +69 -0
- package/request/openapi.js +1013 -0
- package/request/openapi.js.map +1 -0
- package/request/openapi.ts +1220 -0
- package/types/types.d.ts +79 -0
- package/types/types.js +3 -0
- package/types/types.js.map +1 -0
- package/types/types.ts +105 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { ITransaction, ITransactionWithCurrentObject, TransactionObject } from "../transaction";
|
|
2
|
+
import { exceptions, checkUtils } from '@byted-apaas/server-common-node'
|
|
3
|
+
import * as Request from '../../../../request/interface'
|
|
4
|
+
import {
|
|
5
|
+
CreateOperation,
|
|
6
|
+
UpdateOperation,
|
|
7
|
+
DeleteOperation,
|
|
8
|
+
TransactionOperation,
|
|
9
|
+
BatchCreateOperation, BatchDeleteOperation, BatchUpdateSameValueOperation, BatchUpdateOperation
|
|
10
|
+
} from './operation'
|
|
11
|
+
import { _Cond, _CondRequireID } from "../../../../types/types";
|
|
12
|
+
import { currentObjApiName } from '../../../../data'
|
|
13
|
+
|
|
14
|
+
const assert = require('assert')
|
|
15
|
+
|
|
16
|
+
const { v4: uuidv4 } = require("uuid");
|
|
17
|
+
|
|
18
|
+
type uuidOrRecordIDResult = {
|
|
19
|
+
_id: uuidOrRecordID
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type uuidOrRecordID = number | string
|
|
23
|
+
|
|
24
|
+
export class Transaction<T, mt> implements ITransaction<mt>, ITransactionWithCurrentObject<mt> {
|
|
25
|
+
objectApiName: string
|
|
26
|
+
placeholders: Record<string, number>
|
|
27
|
+
operations: TransactionOperation[]
|
|
28
|
+
// 单个创建 uuid 到 result 的映射
|
|
29
|
+
uuid2result: Record<string, uuidOrRecordIDResult>
|
|
30
|
+
isCommit: boolean
|
|
31
|
+
|
|
32
|
+
// 批量创建 uuid 数组,commit 后变成真实 _id 的数组
|
|
33
|
+
batchResults: (string | number)[][];
|
|
34
|
+
|
|
35
|
+
constructor(objectApiName: string) {
|
|
36
|
+
this.objectApiName = objectApiName;
|
|
37
|
+
this.placeholders = {};
|
|
38
|
+
this.operations = [];
|
|
39
|
+
this.uuid2result = {};
|
|
40
|
+
this.isCommit = false;
|
|
41
|
+
this.batchResults = [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
currentObject(): TransactionObject<mt[currentObjApiName]> {
|
|
46
|
+
if (!this.objectApiName) {
|
|
47
|
+
throw new exceptions.InternalError(`objectApiName is empty`);
|
|
48
|
+
}
|
|
49
|
+
return this.object(this.objectApiName as any);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
object<T extends keyof mt>(objectApiName: T): TransactionObject<mt[T]> {
|
|
53
|
+
if (!objectApiName) {
|
|
54
|
+
throw new exceptions.InvalidParamError(`objectApiName is empty`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
// 注册创建的逻辑:
|
|
59
|
+
// 事务中进行创建和不使用事务其实是一样的,特别之处在于返回的 ID 是由 SDK 生成的 uuid。
|
|
60
|
+
// SDK 生成的 uuid 只是为了 Mock 住 ID 这个字段,在事务执行后并不会落库。
|
|
61
|
+
registerCreate: (oldRecord: _Cond<T>) => {
|
|
62
|
+
if (this.isCommit) {
|
|
63
|
+
throw new exceptions.InvalidParamError("Committed transaction cannot register operations");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!oldRecord) {
|
|
67
|
+
throw new exceptions.InvalidParamError("record is empty");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (checkUtils.isNotObject(oldRecord)) {
|
|
71
|
+
throw new exceptions.InvalidParamError("record is not object");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let record = { ...oldRecord };
|
|
75
|
+
|
|
76
|
+
let uuid: string = uuidv4();
|
|
77
|
+
let result = { _id: uuid };
|
|
78
|
+
(record as _Cond<T> & { _id: string })._id = uuid;
|
|
79
|
+
this.placeholders[uuid] = 0;
|
|
80
|
+
this.operations.push(new CreateOperation(objectApiName as string, record));
|
|
81
|
+
this.uuid2result[uuid] = result;
|
|
82
|
+
return result;
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// 注册更新的逻辑:
|
|
86
|
+
// 由于事务中创建的 Record 的 ID 是 uuid,而已经创建的 Record 的 ID 是 number 类型,因此在传入 ID 的情况下类型为 string | number
|
|
87
|
+
registerUpdate: (idOrRecord: string | number | _Cond<T>, record?: _Cond<T>) => {
|
|
88
|
+
let recordMap: _CondRequireID<T>
|
|
89
|
+
if (this.isCommit) {
|
|
90
|
+
throw new exceptions.InvalidParamError("Committed transaction cannot register operations");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (typeof idOrRecord === "number" || typeof idOrRecord === "string") {
|
|
94
|
+
recordMap = record as _CondRequireID<T>
|
|
95
|
+
recordMap["_id"] = idOrRecord as number
|
|
96
|
+
} else {
|
|
97
|
+
recordMap = idOrRecord as _CondRequireID<T>
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!recordMap) {
|
|
101
|
+
throw new exceptions.InvalidParamError("record is empty");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let recordID: number = recordMap['_id'];
|
|
105
|
+
if (!recordID) {
|
|
106
|
+
throw new exceptions.InvalidParamError("record._id is empty");
|
|
107
|
+
}
|
|
108
|
+
this.operations.push(new UpdateOperation(objectApiName as string, recordMap));
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
// 注册删除的逻辑:
|
|
112
|
+
// 注册删除和注册更新一样,ID 有可能是事务中创建的 Record,也有可能是现存的 Record,因此 ID 的类型是 string | number
|
|
113
|
+
registerDelete: (idOrRecord: string | number | _Cond<T>) => {
|
|
114
|
+
if (this.isCommit) {
|
|
115
|
+
throw new exceptions.InvalidParamError("Committed transaction cannot register operations");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!idOrRecord) {
|
|
119
|
+
throw new exceptions.InvalidParamError("record is empty");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let recordId: number | string = null;
|
|
123
|
+
if (typeof idOrRecord === "number" || typeof idOrRecord === "string") {
|
|
124
|
+
recordId = idOrRecord
|
|
125
|
+
} else {
|
|
126
|
+
if (checkUtils.isObject(idOrRecord)) {
|
|
127
|
+
if (!(idOrRecord as _CondRequireID<T>)._id) {
|
|
128
|
+
throw new exceptions.InvalidParamError("record._id is empty");
|
|
129
|
+
}
|
|
130
|
+
recordId = (idOrRecord as _CondRequireID<T>)._id;
|
|
131
|
+
} else {
|
|
132
|
+
throw new exceptions.InvalidParamError("param type should be number | string | Object. ")
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.operations.push(new DeleteOperation(objectApiName as string, { _id: recordId }));
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
// 注册批量创建
|
|
139
|
+
registerBatchCreate: (recordMaps: _Cond<T>[]) => {
|
|
140
|
+
if (this.isCommit) {
|
|
141
|
+
throw new exceptions.InvalidParamError("Committed transaction cannot register operations");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!recordMaps) {
|
|
145
|
+
throw new exceptions.InvalidParamError("recordMaps is empty");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!Array.isArray(recordMaps)) {
|
|
149
|
+
throw new exceptions.InvalidParamError("recordMaps is not Array");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (recordMaps.length < 1) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let result: (string | number)[] = [];
|
|
157
|
+
let records = [];
|
|
158
|
+
for (let oldRecord of recordMaps) {
|
|
159
|
+
let record = { ...oldRecord };
|
|
160
|
+
let uuid: string = uuidv4();
|
|
161
|
+
this.placeholders[uuid] = 0;
|
|
162
|
+
(record as any)['_id'] = uuid;
|
|
163
|
+
result.push(uuid);
|
|
164
|
+
records.push(record);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.operations.push(new BatchCreateOperation(objectApiName as string, records));
|
|
168
|
+
|
|
169
|
+
this.batchResults.push(result);
|
|
170
|
+
|
|
171
|
+
return result;
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
registerBatchUpdate: (recordMaps: _Cond<T>[]) => {
|
|
175
|
+
if (this.isCommit) {
|
|
176
|
+
throw new exceptions.InvalidParamError("Committed transaction cannot register operations");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!recordMaps) {
|
|
180
|
+
throw new exceptions.InvalidParamError("recordMaps is empty");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!Array.isArray(recordMaps)) {
|
|
184
|
+
throw new exceptions.InvalidParamError("recordMaps is not Array");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (recordMaps.length < 1) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 判断同字段同值更新标志
|
|
192
|
+
let isSameValue: boolean = true;
|
|
193
|
+
let ids = [];
|
|
194
|
+
let flag = recordMaps[0];
|
|
195
|
+
for (let record of recordMaps as _CondRequireID<T>[]) {
|
|
196
|
+
if (checkUtils.isNotObject(record)) {
|
|
197
|
+
throw new exceptions.InvalidParamError("one record of recordMaps is not object")
|
|
198
|
+
}
|
|
199
|
+
if (!record["_id"]) {
|
|
200
|
+
throw new exceptions.InvalidParamError(`one record of recordMaps has no _id ${JSON.stringify(record)}`)
|
|
201
|
+
}
|
|
202
|
+
ids.push(record["_id"])
|
|
203
|
+
if (!deepEqualExceptID(flag, record)) {
|
|
204
|
+
isSameValue = false;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (isSameValue) {
|
|
210
|
+
this.operations.push(new BatchUpdateSameValueOperation(objectApiName as string, {
|
|
211
|
+
'ids': ids,
|
|
212
|
+
'value': flag,
|
|
213
|
+
}))
|
|
214
|
+
} else {
|
|
215
|
+
for (const i in ids) {
|
|
216
|
+
(recordMaps as _CondRequireID<T>[])[i]["_id"] = ids[i]
|
|
217
|
+
}
|
|
218
|
+
this.operations.push(new BatchUpdateOperation(objectApiName as string, recordMaps));
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
// 注册批量删除
|
|
223
|
+
registerBatchDelete: (idOrRecords: (string | number | _Cond<T>)[]) => {
|
|
224
|
+
if (this.isCommit) {
|
|
225
|
+
throw new exceptions.InvalidParamError("Committed transaction cannot register operations");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!idOrRecords) {
|
|
229
|
+
throw new exceptions.InvalidParamError("idOrRecords is empty");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!Array.isArray(idOrRecords)) {
|
|
233
|
+
throw new exceptions.InvalidParamError("idOrRecords is not Array");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (idOrRecords.length < 1) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let ids: (string | number)[] = [];
|
|
241
|
+
for (const idOrRecord of idOrRecords) {
|
|
242
|
+
switch (typeof idOrRecord) {
|
|
243
|
+
case "string":
|
|
244
|
+
case "number":
|
|
245
|
+
ids.push(idOrRecord as (string | number));
|
|
246
|
+
break;
|
|
247
|
+
case "object":
|
|
248
|
+
if (!(idOrRecord as _CondRequireID<T>)['_id']) {
|
|
249
|
+
throw new exceptions.InvalidParamError("_id of one record is empty");
|
|
250
|
+
} else {
|
|
251
|
+
ids.push((idOrRecord as _CondRequireID<T>)['_id']);
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
throw new exceptions.InvalidParamError("type of one param is not string | number | object")
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
this.operations.push(new BatchDeleteOperation(objectApiName as string, { 'ids': ids }))
|
|
260
|
+
},
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async commit(): Promise<void> {
|
|
265
|
+
if (this.isCommit) {
|
|
266
|
+
throw new exceptions.InvalidParamError("The transaction cannot be committed repeatedly");
|
|
267
|
+
}
|
|
268
|
+
this.isCommit = true;
|
|
269
|
+
|
|
270
|
+
if (!this.operations || this.operations.length === 0) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let uuid2recordId: Map<string, number> = await Request.GetInstance().modifyRecordsWithTransaction(this.placeholders, this.operations);
|
|
275
|
+
if (!uuid2recordId) {
|
|
276
|
+
throw new exceptions.InternalError("uuid2recordId is empty");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// 单个注册结果映射
|
|
280
|
+
for (let uuid of Object.keys(this.uuid2result)) {
|
|
281
|
+
let preResult: uuidOrRecordIDResult = this.uuid2result[uuid];
|
|
282
|
+
let recordId = uuid2recordId.get(uuid);
|
|
283
|
+
if (!recordId) {
|
|
284
|
+
throw new exceptions.InternalError(`uuid (${uuid}) is not in uuid2recordId (${JSON.stringify(uuid2recordId)})`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (typeof (recordId) !== "number") {
|
|
288
|
+
throw new exceptions.InternalError(`the type (${typeof (recordId)}) of recordId (${recordId}) must be number`);
|
|
289
|
+
}
|
|
290
|
+
preResult._id = recordId;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (!this.batchResults) {
|
|
294
|
+
return
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 批量注册结果映射
|
|
298
|
+
for (let i = 0; i < this.batchResults.length; i++) {
|
|
299
|
+
if (!this.batchResults[i]) {
|
|
300
|
+
continue
|
|
301
|
+
}
|
|
302
|
+
for (let j = 0; j < this.batchResults[i].length; j++) {
|
|
303
|
+
if (!this.batchResults[i][j]) {
|
|
304
|
+
continue
|
|
305
|
+
}
|
|
306
|
+
let recordId = uuid2recordId.get(this.batchResults[i][j] as string);
|
|
307
|
+
if (!recordId) {
|
|
308
|
+
throw new exceptions.InternalError(`uuid (${this.batchResults[i][j]}) is not in uuid2recordId (${JSON.stringify(uuid2recordId)})`);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (typeof (recordId) !== "number") {
|
|
312
|
+
throw new exceptions.InternalError(`the type (${typeof (recordId)}) of recordId (${recordId}) must be number`);
|
|
313
|
+
}
|
|
314
|
+
this.batchResults[i][j] = recordId;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function deepEqualExceptID(left: any, right: any): boolean {
|
|
321
|
+
let leftID = left["_id"], rightID = right["_id"];
|
|
322
|
+
delete left["_id"];
|
|
323
|
+
delete right["_id"];
|
|
324
|
+
let result: boolean = deepEqual(left, right);
|
|
325
|
+
left["_id"] = leftID;
|
|
326
|
+
right["_id"] = rightID;
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function deepEqual(left: any, right: any): boolean {
|
|
331
|
+
try {
|
|
332
|
+
assert.deepStrictEqual(left, right);
|
|
333
|
+
} catch (e) {
|
|
334
|
+
return false
|
|
335
|
+
}
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class TransactionOperation {
|
|
2
|
+
operationType: number;
|
|
3
|
+
objectApiName: string;
|
|
4
|
+
input: string;
|
|
5
|
+
constructor(operationType: number, objectApiName: string, input: any);
|
|
6
|
+
}
|
|
7
|
+
export declare class CreateOperation extends TransactionOperation {
|
|
8
|
+
constructor(objectApiName: string, input: any);
|
|
9
|
+
}
|
|
10
|
+
export declare class UpdateOperation extends TransactionOperation {
|
|
11
|
+
constructor(objectApiName: string, input: any);
|
|
12
|
+
}
|
|
13
|
+
export declare class DeleteOperation extends TransactionOperation {
|
|
14
|
+
constructor(objectApiName: string, input: any);
|
|
15
|
+
}
|
|
16
|
+
export declare class BatchCreateOperation extends TransactionOperation {
|
|
17
|
+
constructor(objectApiName: string, input: any);
|
|
18
|
+
}
|
|
19
|
+
export declare class BatchUpdateOperation extends TransactionOperation {
|
|
20
|
+
constructor(objectApiName: string, input: any);
|
|
21
|
+
}
|
|
22
|
+
export declare class BatchDeleteOperation extends TransactionOperation {
|
|
23
|
+
constructor(objectApiName: string, input: any);
|
|
24
|
+
}
|
|
25
|
+
export declare class BatchUpdateSameValueOperation extends TransactionOperation {
|
|
26
|
+
constructor(objectApiName: string, input: any);
|
|
27
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BatchUpdateSameValueOperation = exports.BatchDeleteOperation = exports.BatchUpdateOperation = exports.BatchCreateOperation = exports.DeleteOperation = exports.UpdateOperation = exports.CreateOperation = exports.TransactionOperation = void 0;
|
|
4
|
+
const exceptions = require('@byted-apaas/server-common-node').exceptions;
|
|
5
|
+
var OperationType;
|
|
6
|
+
(function (OperationType) {
|
|
7
|
+
OperationType[OperationType["OPERATION_TYPE_CREATE"] = 1] = "OPERATION_TYPE_CREATE";
|
|
8
|
+
OperationType[OperationType["OPERATION_TYPE_UPDATE"] = 2] = "OPERATION_TYPE_UPDATE";
|
|
9
|
+
OperationType[OperationType["OPERATION_TYPE_DELETE"] = 3] = "OPERATION_TYPE_DELETE";
|
|
10
|
+
OperationType[OperationType["OPERATION_TYPE_BATCH_CREATE"] = 4] = "OPERATION_TYPE_BATCH_CREATE";
|
|
11
|
+
OperationType[OperationType["OPERATION_TYPE_BATCH_UPDATE"] = 5] = "OPERATION_TYPE_BATCH_UPDATE";
|
|
12
|
+
OperationType[OperationType["OPERATION_TYPE_BATCH_DELETE"] = 6] = "OPERATION_TYPE_BATCH_DELETE";
|
|
13
|
+
OperationType[OperationType["OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE"] = 7] = "OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE";
|
|
14
|
+
})(OperationType || (OperationType = {}));
|
|
15
|
+
class TransactionOperation {
|
|
16
|
+
constructor(operationType, objectApiName, input) {
|
|
17
|
+
this.operationType = operationType;
|
|
18
|
+
this.objectApiName = objectApiName;
|
|
19
|
+
try {
|
|
20
|
+
this.input = JSON.stringify(input);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new exceptions.InvalidParamError(e.message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TransactionOperation = TransactionOperation;
|
|
28
|
+
class CreateOperation extends TransactionOperation {
|
|
29
|
+
constructor(objectApiName, input) {
|
|
30
|
+
super(OperationType.OPERATION_TYPE_CREATE, objectApiName, input);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.CreateOperation = CreateOperation;
|
|
34
|
+
class UpdateOperation extends TransactionOperation {
|
|
35
|
+
constructor(objectApiName, input) {
|
|
36
|
+
super(OperationType.OPERATION_TYPE_UPDATE, objectApiName, input);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.UpdateOperation = UpdateOperation;
|
|
40
|
+
class DeleteOperation extends TransactionOperation {
|
|
41
|
+
constructor(objectApiName, input) {
|
|
42
|
+
super(OperationType.OPERATION_TYPE_DELETE, objectApiName, input);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.DeleteOperation = DeleteOperation;
|
|
46
|
+
class BatchCreateOperation extends TransactionOperation {
|
|
47
|
+
constructor(objectApiName, input) {
|
|
48
|
+
super(OperationType.OPERATION_TYPE_BATCH_CREATE, objectApiName, input);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.BatchCreateOperation = BatchCreateOperation;
|
|
52
|
+
class BatchUpdateOperation extends TransactionOperation {
|
|
53
|
+
constructor(objectApiName, input) {
|
|
54
|
+
super(OperationType.OPERATION_TYPE_BATCH_UPDATE, objectApiName, input);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.BatchUpdateOperation = BatchUpdateOperation;
|
|
58
|
+
class BatchDeleteOperation extends TransactionOperation {
|
|
59
|
+
constructor(objectApiName, input) {
|
|
60
|
+
super(OperationType.OPERATION_TYPE_BATCH_DELETE, objectApiName, input);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.BatchDeleteOperation = BatchDeleteOperation;
|
|
64
|
+
class BatchUpdateSameValueOperation extends TransactionOperation {
|
|
65
|
+
constructor(objectApiName, input) {
|
|
66
|
+
super(OperationType.OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE, objectApiName, input);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.BatchUpdateSameValueOperation = BatchUpdateSameValueOperation;
|
|
70
|
+
//# sourceMappingURL=operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.js","sourceRoot":"","sources":["operation.ts"],"names":[],"mappings":";;;AAAA,MAAM,UAAU,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC,UAAU,CAAC;AAEzE,IAAK,aAUJ;AAVD,WAAK,aAAa;IACd,mFAAyB,CAAA;IACzB,mFAAyB,CAAA;IACzB,mFAAyB,CAAA;IAEzB,+FAA+B,CAAA;IAC/B,+FAA+B,CAAA;IAC/B,+FAA+B,CAAA;IAE/B,qHAA0C,CAAA;AAC9C,CAAC,EAVI,aAAa,KAAb,aAAa,QAUjB;AAED,MAAa,oBAAoB;IAK7B,YAAY,aAAqB,EAAE,aAAqB,EAAE,KAAU;QAChE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI;YACA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACtC;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACrD;IACL,CAAC;CACJ;AAfD,oDAeC;AAED,MAAa,eAAgB,SAAQ,oBAAoB;IACrD,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,qBAAqB,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;CACJ;AAJD,0CAIC;AAED,MAAa,eAAgB,SAAQ,oBAAoB;IACrD,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,qBAAqB,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;CACJ;AAJD,0CAIC;AAED,MAAa,eAAgB,SAAQ,oBAAoB;IACrD,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,qBAAqB,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;CACJ;AAJD,0CAIC;AAED,MAAa,oBAAqB,SAAQ,oBAAoB;IAC1D,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,2BAA2B,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;CACJ;AAJD,oDAIC;AAED,MAAa,oBAAqB,SAAQ,oBAAoB;IAC1D,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,2BAA2B,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;CACJ;AAJD,oDAIC;AAED,MAAa,oBAAqB,SAAQ,oBAAoB;IAC1D,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,2BAA2B,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;CACJ;AAJD,oDAIC;AAED,MAAa,6BAA8B,SAAQ,oBAAoB;IACnE,YAAY,aAAqB,EAAE,KAAU;QACzC,KAAK,CAAC,aAAa,CAAC,sCAAsC,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACtF,CAAC;CACJ;AAJD,sEAIC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const exceptions = require('@byted-apaas/server-common-node').exceptions;
|
|
2
|
+
|
|
3
|
+
enum OperationType {
|
|
4
|
+
OPERATION_TYPE_CREATE = 1,
|
|
5
|
+
OPERATION_TYPE_UPDATE = 2,
|
|
6
|
+
OPERATION_TYPE_DELETE = 3,
|
|
7
|
+
|
|
8
|
+
OPERATION_TYPE_BATCH_CREATE = 4,
|
|
9
|
+
OPERATION_TYPE_BATCH_UPDATE = 5,
|
|
10
|
+
OPERATION_TYPE_BATCH_DELETE = 6,
|
|
11
|
+
|
|
12
|
+
OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE = 7,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class TransactionOperation {
|
|
16
|
+
operationType: number
|
|
17
|
+
objectApiName: string
|
|
18
|
+
input: string
|
|
19
|
+
|
|
20
|
+
constructor(operationType: number, objectApiName: string, input: any) {
|
|
21
|
+
this.operationType = operationType;
|
|
22
|
+
this.objectApiName = objectApiName;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
this.input = JSON.stringify(input);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
throw new exceptions.InvalidParamError(e.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class CreateOperation extends TransactionOperation {
|
|
33
|
+
constructor(objectApiName: string, input: any) {
|
|
34
|
+
super(OperationType.OPERATION_TYPE_CREATE, objectApiName, input);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class UpdateOperation extends TransactionOperation {
|
|
39
|
+
constructor(objectApiName: string, input: any) {
|
|
40
|
+
super(OperationType.OPERATION_TYPE_UPDATE, objectApiName, input);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class DeleteOperation extends TransactionOperation {
|
|
45
|
+
constructor(objectApiName: string, input: any) {
|
|
46
|
+
super(OperationType.OPERATION_TYPE_DELETE, objectApiName, input);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class BatchCreateOperation extends TransactionOperation {
|
|
51
|
+
constructor(objectApiName: string, input: any) {
|
|
52
|
+
super(OperationType.OPERATION_TYPE_BATCH_CREATE, objectApiName, input);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class BatchUpdateOperation extends TransactionOperation {
|
|
57
|
+
constructor(objectApiName: string, input: any) {
|
|
58
|
+
super(OperationType.OPERATION_TYPE_BATCH_UPDATE, objectApiName, input);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class BatchDeleteOperation extends TransactionOperation {
|
|
63
|
+
constructor(objectApiName: string, input: any) {
|
|
64
|
+
super(OperationType.OPERATION_TYPE_BATCH_DELETE, objectApiName, input);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class BatchUpdateSameValueOperation extends TransactionOperation {
|
|
69
|
+
constructor(objectApiName: string, input: any) {
|
|
70
|
+
super(OperationType.OPERATION_TYPE_BATCH_UPDATE_SAME_VALUE, objectApiName, input);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { _Cond } from '../../../types/types';
|
|
2
|
+
import { currentObjApiName } from "../../../data/index";
|
|
3
|
+
export declare type ITransactionGetter<T, mt> = T extends {
|
|
4
|
+
'objectApiName': string;
|
|
5
|
+
} ? ITransaction<mt> : ITransaction<mt> & ITransactionWithCurrentObject<mt>;
|
|
6
|
+
export interface ITransaction<mt> {
|
|
7
|
+
/**
|
|
8
|
+
* 操作指定对象的记录数据
|
|
9
|
+
* @param objectApiName 指定对象的 ApiName
|
|
10
|
+
*/
|
|
11
|
+
object<T extends keyof mt>(objectApiName: T): TransactionObject<mt[T]>;
|
|
12
|
+
/**
|
|
13
|
+
* 提交事务
|
|
14
|
+
*/
|
|
15
|
+
commit(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface ITransactionWithCurrentObject<mt> {
|
|
18
|
+
/**
|
|
19
|
+
* 无需入参,操作当前对象的记录数据
|
|
20
|
+
*/
|
|
21
|
+
currentObject(): TransactionObject<mt[currentObjApiName]>;
|
|
22
|
+
}
|
|
23
|
+
export interface TransactionObject<T> {
|
|
24
|
+
/**
|
|
25
|
+
* 注册创建单条记录,返回仅在事务中生效的临时记录 ID,该 ID 将在事务执行完毕后更新为实际记录 ID
|
|
26
|
+
* @param recordMap 用于创建的一条记录
|
|
27
|
+
*/
|
|
28
|
+
registerCreate(recordMap: _Cond<T>): {
|
|
29
|
+
_id: string | number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 注册删除单条记录
|
|
33
|
+
* @param recordID 用于删除的一条记录的 ID
|
|
34
|
+
*/
|
|
35
|
+
registerDelete(recordID: (string | number)): void;
|
|
36
|
+
/**
|
|
37
|
+
* 注册删除单条记录
|
|
38
|
+
* @param record 用于删除的一条完整记录
|
|
39
|
+
*/
|
|
40
|
+
registerDelete(record: _Cond<T>): void;
|
|
41
|
+
/**
|
|
42
|
+
* 注册更新单条记录
|
|
43
|
+
* @param recordMap 用于更新的一条记录,需对 _id 赋值
|
|
44
|
+
*/
|
|
45
|
+
registerUpdate(recordMap: _Cond<T>): void;
|
|
46
|
+
/**
|
|
47
|
+
* 注册更新单条记录
|
|
48
|
+
* @param _id 主键
|
|
49
|
+
* @param recordMap 用于更新的一条记录
|
|
50
|
+
*/
|
|
51
|
+
registerUpdate(_id: (string | number), recordMap: _Cond<T>): void;
|
|
52
|
+
/**
|
|
53
|
+
* 注册批量创建记录,返回仅在事务中生效的临时记录 ID 数组,该 ID 将在事务执行完毕后更新为实际记录 ID
|
|
54
|
+
* @param recordMaps 用于批量创建的一批记录
|
|
55
|
+
*/
|
|
56
|
+
registerBatchCreate(recordMaps: _Cond<T>[]): (string | number)[];
|
|
57
|
+
/**
|
|
58
|
+
* 注册批量删除记录
|
|
59
|
+
* @param recordIDs 用于删除的一批记录的 ID or 完整记录
|
|
60
|
+
*/
|
|
61
|
+
registerBatchDelete(recordIDs: (string | number | _Cond<T>)[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* 注册批量更新记录
|
|
64
|
+
* @param recordMaps 用于更新的一批记录,需对每个记录的 _id 赋值
|
|
65
|
+
*/
|
|
66
|
+
registerBatchUpdate(recordMaps: _Cond<T>[]): void;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["transaction.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {_Cond} from '../../../types/types'
|
|
2
|
+
import {currentObjApiName} from "../../../data/index";
|
|
3
|
+
|
|
4
|
+
export type ITransactionGetter<T, mt> = T extends { 'objectApiName': string } ? ITransaction<mt> : ITransaction<mt> & ITransactionWithCurrentObject<mt>;
|
|
5
|
+
|
|
6
|
+
export interface ITransaction<mt> {
|
|
7
|
+
/**
|
|
8
|
+
* 操作指定对象的记录数据
|
|
9
|
+
* @param objectApiName 指定对象的 ApiName
|
|
10
|
+
*/
|
|
11
|
+
object<T extends keyof mt>(objectApiName: T): TransactionObject<mt[T]>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 提交事务
|
|
15
|
+
*/
|
|
16
|
+
commit(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ITransactionWithCurrentObject<mt> {
|
|
20
|
+
/**
|
|
21
|
+
* 无需入参,操作当前对象的记录数据
|
|
22
|
+
*/
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
currentObject(): TransactionObject<mt[currentObjApiName]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TransactionObject<T> {
|
|
28
|
+
/**
|
|
29
|
+
* 注册创建单条记录,返回仅在事务中生效的临时记录 ID,该 ID 将在事务执行完毕后更新为实际记录 ID
|
|
30
|
+
* @param recordMap 用于创建的一条记录
|
|
31
|
+
*/
|
|
32
|
+
registerCreate(recordMap: _Cond<T>): { _id: string | number };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 注册删除单条记录
|
|
36
|
+
* @param recordID 用于删除的一条记录的 ID
|
|
37
|
+
*/
|
|
38
|
+
registerDelete(recordID: (string | number)): void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 注册删除单条记录
|
|
42
|
+
* @param record 用于删除的一条完整记录
|
|
43
|
+
*/
|
|
44
|
+
registerDelete(record: _Cond<T>): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 注册更新单条记录
|
|
48
|
+
* @param recordMap 用于更新的一条记录,需对 _id 赋值
|
|
49
|
+
*/
|
|
50
|
+
registerUpdate(recordMap: _Cond<T>): void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 注册更新单条记录
|
|
54
|
+
* @param _id 主键
|
|
55
|
+
* @param recordMap 用于更新的一条记录
|
|
56
|
+
*/
|
|
57
|
+
registerUpdate(_id: (string | number), recordMap: _Cond<T>): void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 注册批量创建记录,返回仅在事务中生效的临时记录 ID 数组,该 ID 将在事务执行完毕后更新为实际记录 ID
|
|
61
|
+
* @param recordMaps 用于批量创建的一批记录
|
|
62
|
+
*/
|
|
63
|
+
registerBatchCreate(recordMaps: _Cond<T>[]): (string | number)[];
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 注册批量删除记录
|
|
67
|
+
* @param recordIDs 用于删除的一批记录的 ID or 完整记录
|
|
68
|
+
*/
|
|
69
|
+
registerBatchDelete(recordIDs: (string | number | _Cond<T>)[]): void;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 注册批量更新记录
|
|
73
|
+
* @param recordMaps 用于更新的一批记录,需对每个记录的 _id 赋值
|
|
74
|
+
*/
|
|
75
|
+
registerBatchUpdate(recordMaps: _Cond<T>[]): void;
|
|
76
|
+
}
|