@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.
Files changed (215) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +1 -0
  3. package/application/application.d.ts +27 -0
  4. package/application/application.js +3 -0
  5. package/application/application.js.map +1 -0
  6. package/application/application.ts +40 -0
  7. package/application/function/function.d.ts +14 -0
  8. package/application/function/function.js +22 -0
  9. package/application/function/function.js.map +1 -0
  10. package/application/function/function.ts +37 -0
  11. package/application/impl/common.d.ts +2 -0
  12. package/application/impl/common.js +51 -0
  13. package/application/impl/common.js.map +1 -0
  14. package/application/impl/common.ts +50 -0
  15. package/application/impl/impl.d.ts +16 -0
  16. package/application/impl/impl.js +39 -0
  17. package/application/impl/impl.js.map +1 -0
  18. package/application/impl/impl.ts +48 -0
  19. package/constants/constants.d.ts +10 -0
  20. package/constants/constants.js +14 -0
  21. package/constants/constants.js.map +1 -0
  22. package/constants/constants.ts +12 -0
  23. package/context/context.d.ts +74 -0
  24. package/context/context.js +24 -0
  25. package/context/context.js.map +1 -0
  26. package/context/context.ts +127 -0
  27. package/context/db/db.d.ts +73 -0
  28. package/context/db/db.js +3 -0
  29. package/context/db/db.js.map +1 -0
  30. package/context/db/db.ts +77 -0
  31. package/context/db/impl/IObject.d.ts +251 -0
  32. package/context/db/impl/IObject.js +4 -0
  33. package/context/db/impl/IObject.js.map +1 -0
  34. package/context/db/impl/IObject.ts +244 -0
  35. package/context/db/impl/db.d.ts +61 -0
  36. package/context/db/impl/db.js +87 -0
  37. package/context/db/impl/db.js.map +1 -0
  38. package/context/db/impl/db.ts +95 -0
  39. package/context/db/impl/object.d.ts +92 -0
  40. package/context/db/impl/object.js +523 -0
  41. package/context/db/impl/object.js.map +1 -0
  42. package/context/db/impl/object.ts +628 -0
  43. package/context/db/impl/oql/ioql.d.ts +6 -0
  44. package/context/db/impl/oql/ioql.js +3 -0
  45. package/context/db/impl/oql/ioql.js.map +1 -0
  46. package/context/db/impl/oql/ioql.ts +6 -0
  47. package/context/db/impl/oql/oql.d.ts +8 -0
  48. package/context/db/impl/oql/oql.js +20 -0
  49. package/context/db/impl/oql/oql.js.map +1 -0
  50. package/context/db/impl/oql/oql.ts +22 -0
  51. package/context/db/impl/order.d.ts +9 -0
  52. package/context/db/impl/order.js +14 -0
  53. package/context/db/impl/order.js.map +1 -0
  54. package/context/db/impl/order.ts +16 -0
  55. package/context/db/impl/propertiesStore.d.ts +8 -0
  56. package/context/db/impl/propertiesStore.js +28 -0
  57. package/context/db/impl/propertiesStore.js.map +1 -0
  58. package/context/db/impl/propertiesStore.ts +28 -0
  59. package/context/db/impl/queryBuilder.d.ts +29 -0
  60. package/context/db/impl/queryBuilder.js +77 -0
  61. package/context/db/impl/queryBuilder.js.map +1 -0
  62. package/context/db/impl/queryBuilder.ts +103 -0
  63. package/context/db/impl/transaction/index.d.ts +20 -0
  64. package/context/db/impl/transaction/index.js +276 -0
  65. package/context/db/impl/transaction/index.js.map +1 -0
  66. package/context/db/impl/transaction/index.ts +337 -0
  67. package/context/db/impl/transaction/operation.d.ts +27 -0
  68. package/context/db/impl/transaction/operation.js +70 -0
  69. package/context/db/impl/transaction/operation.js.map +1 -0
  70. package/context/db/impl/transaction/operation.ts +72 -0
  71. package/context/db/impl/transaction.d.ts +67 -0
  72. package/context/db/impl/transaction.js +3 -0
  73. package/context/db/impl/transaction.js.map +1 -0
  74. package/context/db/impl/transaction.ts +76 -0
  75. package/context/globalConfig/globalConfig.d.ts +7 -0
  76. package/context/globalConfig/globalConfig.js +15 -0
  77. package/context/globalConfig/globalConfig.js.map +1 -0
  78. package/context/globalConfig/globalConfig.ts +11 -0
  79. package/context/metadata/components/common.d.ts +6 -0
  80. package/context/metadata/components/common.js +16 -0
  81. package/context/metadata/components/common.js.map +1 -0
  82. package/context/metadata/components/common.ts +19 -0
  83. package/context/metadata/components/components.d.ts +12 -0
  84. package/context/metadata/components/components.js +18 -0
  85. package/context/metadata/components/components.js.map +1 -0
  86. package/context/metadata/components/components.ts +19 -0
  87. package/context/metadata/components/desktop/list.d.ts +16 -0
  88. package/context/metadata/components/desktop/list.js +403 -0
  89. package/context/metadata/components/desktop/list.js.map +1 -0
  90. package/context/metadata/components/desktop/list.ts +457 -0
  91. package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
  92. package/context/metadata/components/desktop/recordDetail.js +52 -0
  93. package/context/metadata/components/desktop/recordDetail.js.map +1 -0
  94. package/context/metadata/components/desktop/recordDetail.ts +64 -0
  95. package/context/metadata/components/mobile/list.d.ts +24 -0
  96. package/context/metadata/components/mobile/list.js +144 -0
  97. package/context/metadata/components/mobile/list.js.map +1 -0
  98. package/context/metadata/components/mobile/list.ts +176 -0
  99. package/context/metadata/metadata.d.ts +61 -0
  100. package/context/metadata/metadata.js +102 -0
  101. package/context/metadata/metadata.js.map +1 -0
  102. package/context/metadata/metadata.ts +175 -0
  103. package/context/metadata/objects/fields.d.ts +130 -0
  104. package/context/metadata/objects/fields.js +333 -0
  105. package/context/metadata/objects/fields.js.map +1 -0
  106. package/context/metadata/objects/fields.ts +454 -0
  107. package/context/metadata/objects/fields.util.d.ts +40 -0
  108. package/context/metadata/objects/fields.util.js +320 -0
  109. package/context/metadata/objects/fields.util.js.map +1 -0
  110. package/context/metadata/objects/fields.util.ts +360 -0
  111. package/context/metadata/objects/objects.d.ts +11 -0
  112. package/context/metadata/objects/objects.js +19 -0
  113. package/context/metadata/objects/objects.js.map +1 -0
  114. package/context/metadata/objects/objects.ts +27 -0
  115. package/context/metadata/types/common.d.ts +6 -0
  116. package/context/metadata/types/common.js +8 -0
  117. package/context/metadata/types/common.js.map +1 -0
  118. package/context/metadata/types/common.ts +10 -0
  119. package/context/metadata/types/components.d.ts +90 -0
  120. package/context/metadata/types/components.js +3 -0
  121. package/context/metadata/types/components.js.map +1 -0
  122. package/context/metadata/types/components.ts +105 -0
  123. package/context/metadata/types/objects.d.ts +226 -0
  124. package/context/metadata/types/objects.js +3 -0
  125. package/context/metadata/types/objects.js.map +1 -0
  126. package/context/metadata/types/objects.ts +251 -0
  127. package/context/msg/msg.d.ts +38 -0
  128. package/context/msg/msg.js +34 -0
  129. package/context/msg/msg.js.map +1 -0
  130. package/context/msg/msg.ts +49 -0
  131. package/context/resources/IResources.d.ts +66 -0
  132. package/context/resources/IResources.js +3 -0
  133. package/context/resources/IResources.js.map +1 -0
  134. package/context/resources/IResources.ts +73 -0
  135. package/context/resources/impl/resources.d.ts +42 -0
  136. package/context/resources/impl/resources.js +149 -0
  137. package/context/resources/impl/resources.js.map +1 -0
  138. package/context/resources/impl/resources.ts +170 -0
  139. package/context/tasks/tasks.d.ts +33 -0
  140. package/context/tasks/tasks.js +140 -0
  141. package/context/tasks/tasks.js.map +1 -0
  142. package/context/tasks/tasks.ts +159 -0
  143. package/data/index.d.ts +27 -0
  144. package/data/index.js +5 -0
  145. package/data/index.js.map +1 -0
  146. package/data/index.ts +30 -0
  147. package/hooks/api.d.ts +61 -0
  148. package/hooks/api.js +328 -0
  149. package/hooks/api.js.map +1 -0
  150. package/hooks/api.ts +341 -0
  151. package/hooks/hooks.d.ts +1 -0
  152. package/hooks/hooks.js +89 -0
  153. package/hooks/hooks.js.map +1 -0
  154. package/hooks/hooks.ts +100 -0
  155. package/kunlun/kunlun.d.ts +55 -0
  156. package/kunlun/kunlun.js +57 -0
  157. package/kunlun/kunlun.js.map +1 -0
  158. package/kunlun/kunlun.ts +69 -0
  159. package/kunlun/operator/IOperator.d.ts +158 -0
  160. package/kunlun/operator/IOperator.js +3 -0
  161. package/kunlun/operator/IOperator.js.map +1 -0
  162. package/kunlun/operator/IOperator.ts +163 -0
  163. package/kunlun/operator/impl/expression.d.ts +47 -0
  164. package/kunlun/operator/impl/expression.js +55 -0
  165. package/kunlun/operator/impl/expression.js.map +1 -0
  166. package/kunlun/operator/impl/expression.ts +71 -0
  167. package/kunlun/operator/impl/logic.d.ts +50 -0
  168. package/kunlun/operator/impl/logic.js +508 -0
  169. package/kunlun/operator/impl/logic.js.map +1 -0
  170. package/kunlun/operator/impl/logic.ts +595 -0
  171. package/kunlun/operator/impl/logicV2.d.ts +58 -0
  172. package/kunlun/operator/impl/logicV2.js +201 -0
  173. package/kunlun/operator/impl/logicV2.js.map +1 -0
  174. package/kunlun/operator/impl/logicV2.ts +254 -0
  175. package/kunlun/operator/impl/operator.d.ts +179 -0
  176. package/kunlun/operator/impl/operator.js +221 -0
  177. package/kunlun/operator/impl/operator.js.map +1 -0
  178. package/kunlun/operator/impl/operator.ts +255 -0
  179. package/kunlun/operator/impl/operatorV2.d.ts +180 -0
  180. package/kunlun/operator/impl/operatorV2.js +217 -0
  181. package/kunlun/operator/impl/operatorV2.js.map +1 -0
  182. package/kunlun/operator/impl/operatorV2.ts +249 -0
  183. package/lib/core.d.ts +4 -0
  184. package/lib/core.js +18 -0
  185. package/lib/core.js.map +1 -0
  186. package/lib/core.ts +4 -0
  187. package/package.json +50 -0
  188. package/request/common.d.ts +13 -0
  189. package/request/common.js +88 -0
  190. package/request/common.js.map +1 -0
  191. package/request/common.ts +91 -0
  192. package/request/constants.d.ts +10 -0
  193. package/request/constants.js +26 -0
  194. package/request/constants.js.map +1 -0
  195. package/request/constants.ts +25 -0
  196. package/request/faasinfra.d.ts +8 -0
  197. package/request/faasinfra.js +359 -0
  198. package/request/faasinfra.js.map +1 -0
  199. package/request/faasinfra.ts +393 -0
  200. package/request/innerapi.d.ts +67 -0
  201. package/request/innerapi.js +1411 -0
  202. package/request/innerapi.js.map +1 -0
  203. package/request/innerapi.ts +1645 -0
  204. package/request/interface.d.ts +95 -0
  205. package/request/interface.js +40 -0
  206. package/request/interface.js.map +1 -0
  207. package/request/interface.ts +166 -0
  208. package/request/openapi.d.ts +69 -0
  209. package/request/openapi.js +1013 -0
  210. package/request/openapi.js.map +1 -0
  211. package/request/openapi.ts +1220 -0
  212. package/types/types.d.ts +79 -0
  213. package/types/types.js +3 -0
  214. package/types/types.js.map +1 -0
  215. package/types/types.ts +105 -0
@@ -0,0 +1,1411 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExecutionUserTaskInfo = exports.getExecutionInfo = exports.revokeExecution = exports.RequestRpc = void 0;
4
+ const common = require("@byted-apaas/server-common-node");
5
+ const stream_to_buffer_1 = require("@jorgeferrero/stream-to-buffer");
6
+ const constants_1 = require("../constants/constants");
7
+ const common_1 = require("./common");
8
+ const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
9
+ const rpc = common.rpc;
10
+ const exceptions = common.exceptions;
11
+ const utils = common.utils;
12
+ const fs = require("fs");
13
+ const checkUtils = common.checkUtils;
14
+ const path = require('path');
15
+ async function pre(isTransUser) {
16
+ let ctx;
17
+ try {
18
+ ctx = await rpc.rebuildRpcCtx(isTransUser);
19
+ }
20
+ catch (err) {
21
+ throw new exceptions.InternalError(`RebuildRpcCtx failed: ${err.message}`);
22
+ }
23
+ return ctx;
24
+ }
25
+ function post(baseResp) {
26
+ if (!baseResp) {
27
+ throw new exceptions.InternalError(`Call InnerAPI resp is empty`);
28
+ }
29
+ if (baseResp.KStatusCode !== "") {
30
+ let msg = baseResp.KStatusMessage;
31
+ if (baseResp.StatusMessage !== "") {
32
+ msg = baseResp.StatusMessage;
33
+ }
34
+ if (baseResp.extra["is_system_error"] === "true") {
35
+ throw new exceptions.InternalError(`${msg} [${baseResp.KStatusCode}]`);
36
+ }
37
+ throw new exceptions.InvalidParamError(`${msg} [${baseResp.KStatusCode}]`);
38
+ }
39
+ }
40
+ async function createRecordBySync(objectApiName, record) {
41
+ // 1.check
42
+ if (!objectApiName) {
43
+ throw new exceptions.InvalidParamError("objectApiName is empty");
44
+ }
45
+ // 2.前置处理
46
+ let ctx = await pre();
47
+ // 3.构造 params
48
+ let param = {};
49
+ let task_id = utils.getTriggerTaskID();
50
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
51
+ param.ObjectAPIAlias = objectApiName;
52
+ param.Data = utils.stringify(record);
53
+ param.Operator = BigInt(-1);
54
+ if (task_id) {
55
+ param.TaskID = BigInt(task_id);
56
+ }
57
+ // 4.发起请求
58
+ let resp;
59
+ try {
60
+ resp = await rpc.getInnerAPICli().CreateRecordBySync(ctx, param);
61
+ }
62
+ catch (err) {
63
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
64
+ }
65
+ // 5.后置处理
66
+ post(resp.BaseResp);
67
+ return { _id: Number(resp.RecordID) };
68
+ }
69
+ async function updateRecordBySync(objectApiName, recordID, record) {
70
+ // 1.check
71
+ if (!objectApiName) {
72
+ throw new exceptions.InvalidParamError("objectApiName is empty");
73
+ }
74
+ // 2.前置处理
75
+ let ctx = await pre();
76
+ // 3.构造 params
77
+ let param = {};
78
+ let task_id = utils.getTriggerTaskID();
79
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
80
+ param.ObjectAPIAlias = objectApiName;
81
+ param.RecordID = BigInt(recordID);
82
+ param.Data = utils.stringify(record);
83
+ param.Operator = BigInt(-1);
84
+ if (task_id) {
85
+ param.TaskID = BigInt(task_id);
86
+ }
87
+ // 4.发起请求
88
+ let resp;
89
+ try {
90
+ resp = await rpc.getInnerAPICli().UpdateRecordBySync(ctx, param);
91
+ }
92
+ catch (err) {
93
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
94
+ }
95
+ // 5.后置处理
96
+ post(resp.BaseResp);
97
+ return;
98
+ }
99
+ async function deleteRecordBySync(objectApiName, recordID) {
100
+ // 1.check
101
+ if (!objectApiName) {
102
+ throw new exceptions.InvalidParamError("objectApiName is empty");
103
+ }
104
+ // 2.前置处理
105
+ let ctx = await pre();
106
+ // 3.构造 params
107
+ let param = {};
108
+ let task_id = utils.getTriggerTaskID();
109
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
110
+ param.ObjectAPIAlias = objectApiName;
111
+ param.RecordID = BigInt(recordID);
112
+ param.Operator = BigInt(-1);
113
+ if (task_id) {
114
+ param.TaskID = BigInt(task_id);
115
+ }
116
+ // 4.发起请求
117
+ let resp;
118
+ try {
119
+ resp = await rpc.getInnerAPICli().DeleteRecordBySync(ctx, param);
120
+ }
121
+ catch (err) {
122
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
123
+ }
124
+ // 5.后置处理
125
+ post(resp.BaseResp);
126
+ return;
127
+ }
128
+ async function createRecordsByAsync(objectApiName, records) {
129
+ // 1.check
130
+ if (!objectApiName) {
131
+ throw new exceptions.InvalidParamError("objectApiName is empty");
132
+ }
133
+ // 2.前置处理
134
+ let ctx = await pre();
135
+ // 3.构造 params
136
+ let param = {};
137
+ let task_id = utils.getTriggerTaskID();
138
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
139
+ param.ObjectAPIAlias = objectApiName;
140
+ param.Data = utils.stringify(records);
141
+ param.OperatorID = BigInt(-1);
142
+ if (task_id) {
143
+ param.AutomationTaskID = BigInt(task_id);
144
+ }
145
+ // 4.发起请求
146
+ let resp;
147
+ try {
148
+ resp = await rpc.getInnerAPICli().BatchCreateRecordByAsync(ctx, param);
149
+ }
150
+ catch (err) {
151
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
152
+ }
153
+ // 5.后置处理
154
+ post(resp.BaseResp);
155
+ return { taskID: Number(resp.TaskID) };
156
+ }
157
+ async function updateRecordsByAsync(objectApiName, recordMap) {
158
+ // 1.check
159
+ if (!objectApiName) {
160
+ throw new exceptions.InvalidParamError("objectApiName is empty");
161
+ }
162
+ // 2.前置处理
163
+ let ctx = await pre();
164
+ // 3.构造 params
165
+ let param = {};
166
+ let task_id = utils.getTriggerTaskID();
167
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
168
+ param.ObjectAPIAlias = objectApiName;
169
+ param.Data = utils.stringify(recordMap);
170
+ param.OperatorID = BigInt(-1);
171
+ if (task_id) {
172
+ param.AutomationTaskID = BigInt(task_id);
173
+ }
174
+ // 4.发起请求
175
+ let resp;
176
+ try {
177
+ resp = await rpc.getInnerAPICli().BatchUpdateRecordByAsync(ctx, param);
178
+ }
179
+ catch (err) {
180
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
181
+ }
182
+ // 5.后置处理
183
+ post(resp.BaseResp);
184
+ return { taskID: Number(resp.TaskID) };
185
+ }
186
+ async function deleteRecordsByAsync(objectApiName, recordIDs) {
187
+ // 1.check
188
+ if (!objectApiName) {
189
+ throw new exceptions.InvalidParamError("objectApiName is empty");
190
+ }
191
+ // 2.前置处理
192
+ let ctx = await pre();
193
+ // 3.构造 params
194
+ let param = {};
195
+ let task_id = utils.getTriggerTaskID();
196
+ let recordIDList = new Array();
197
+ recordIDs.forEach((v, idx) => {
198
+ recordIDList.push(BigInt(v));
199
+ });
200
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
201
+ param.ObjectAPIAlias = objectApiName;
202
+ param.RecordIDList = recordIDList;
203
+ param.OperatorID = BigInt(-1);
204
+ if (task_id) {
205
+ param.AutomationTaskID = BigInt(task_id);
206
+ }
207
+ // 4.发起请求
208
+ let resp;
209
+ try {
210
+ resp = await rpc.getInnerAPICli().BatchDeleteRecordByAsync(ctx, param);
211
+ }
212
+ catch (err) {
213
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
214
+ }
215
+ // 5.后置处理
216
+ post(resp.BaseResp);
217
+ return { taskID: Number(resp.TaskID) };
218
+ }
219
+ async function createRecordsBySync(objectApiName, records) {
220
+ // 1.check
221
+ if (!objectApiName) {
222
+ throw new exceptions.InvalidParamError("objectApiName is empty");
223
+ }
224
+ // 2.前置处理
225
+ let ctx = await pre();
226
+ // 3.构造 params
227
+ let param = {};
228
+ let task_id = utils.getTriggerTaskID();
229
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
230
+ param.ObjectAPIAlias = objectApiName;
231
+ param.Data = utils.stringify(records);
232
+ param.OperatorID = BigInt(-1);
233
+ if (task_id) {
234
+ param.AutomationTaskID = BigInt(task_id);
235
+ }
236
+ // 4.发起请求
237
+ let resp;
238
+ try {
239
+ resp = await rpc.getInnerAPICli().BatchCreateRecordBySync(ctx, param);
240
+ }
241
+ catch (err) {
242
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
243
+ }
244
+ // 5.后置处理
245
+ post(resp.BaseResp);
246
+ let recordIDList = new Array();
247
+ let errMap = new Map();
248
+ resp.RecordIDs.forEach((v, idx) => {
249
+ recordIDList.push(Number(v));
250
+ });
251
+ resp.ErrMap.forEach((v, k) => {
252
+ errMap.set(Number(k), v);
253
+ });
254
+ return {
255
+ record_ids: recordIDList,
256
+ err_map: errMap
257
+ };
258
+ }
259
+ async function updateRecordsBySync(objectApiName, recordMap) {
260
+ // 1.check
261
+ if (!objectApiName) {
262
+ throw new exceptions.InvalidParamError("objectApiName is empty");
263
+ }
264
+ // 2.前置处理
265
+ let ctx = await pre();
266
+ // 3.构造 params
267
+ let param = {};
268
+ let task_id = utils.getTriggerTaskID();
269
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
270
+ param.ObjectAPIAlias = objectApiName;
271
+ param.Data = utils.stringify(recordMap);
272
+ param.OperatorID = BigInt(-1);
273
+ if (task_id) {
274
+ param.AutomationTaskID = BigInt(task_id);
275
+ }
276
+ // 4.发起请求
277
+ let resp;
278
+ try {
279
+ resp = await rpc.getInnerAPICli().BatchUpdateRecordBySync(ctx, param);
280
+ }
281
+ catch (err) {
282
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
283
+ }
284
+ // 5.后置处理
285
+ post(resp.BaseResp);
286
+ let errMap = new Map();
287
+ resp.ErrMap.forEach((v, k) => {
288
+ errMap.set(Number(k), v);
289
+ });
290
+ return { err_map: errMap };
291
+ }
292
+ async function deleteRecordsBySync(objectApiName, recordIDs) {
293
+ // 1.check
294
+ if (!objectApiName) {
295
+ throw new exceptions.InvalidParamError("objectApiName is empty");
296
+ }
297
+ // 2.前置处理
298
+ let ctx = await pre();
299
+ // 3.构造 params
300
+ let param = {};
301
+ let task_id = utils.getTriggerTaskID();
302
+ let recordIDList = new Array();
303
+ recordIDs.forEach((v, idx) => {
304
+ recordIDList.push(BigInt(v));
305
+ });
306
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
307
+ param.ObjectAPIAlias = objectApiName;
308
+ param.RecordIDs = recordIDList;
309
+ param.OperatorID = BigInt(-1);
310
+ if (task_id) {
311
+ param.AutomationTaskID = BigInt(task_id);
312
+ }
313
+ // 4.发起请求
314
+ let resp;
315
+ try {
316
+ resp = await rpc.getInnerAPICli().BatchDeleteRecordBySync(ctx, param);
317
+ }
318
+ catch (err) {
319
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
320
+ }
321
+ // 5.后置处理
322
+ post(resp.BaseResp);
323
+ let errMap = new Map();
324
+ resp.ErrMap.forEach((v, k) => {
325
+ errMap.set(Number(k), v);
326
+ });
327
+ return { err_map: errMap };
328
+ }
329
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
330
+ if (limit > 1000) {
331
+ limit = 1000;
332
+ }
333
+ // 1.check
334
+ if (!objectApiName) {
335
+ throw new exceptions.InvalidParamError("objectApiName is empty");
336
+ }
337
+ // 2.前置处理
338
+ let ctx = await pre();
339
+ // 3.构造 params
340
+ let param = {};
341
+ let orders = new Array();
342
+ order.forEach((v, idx) => {
343
+ orders.push({
344
+ field: v.field,
345
+ type: v.type,
346
+ direction: v.direction,
347
+ });
348
+ });
349
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
350
+ param.ObjectAPIAlias = objectApiName;
351
+ param.Criterion = criterion;
352
+ param.Order = orders;
353
+ param.IgnoreBackLookupField = ignoreBackLookupField;
354
+ param.Limit = BigInt(limit);
355
+ param.offset = BigInt(offset);
356
+ param.FieldAPIAPIAliases = fieldApiNames;
357
+ param.NeedFilterUserPermission = false;
358
+ param.NeedTotalCount = needCount;
359
+ // 4.发起请求
360
+ let resp;
361
+ try {
362
+ resp = await rpc.getInnerAPICli().BatchGetRecordWithCriterionV3(ctx, param);
363
+ }
364
+ catch (err) {
365
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
366
+ }
367
+ // 5.后置处理
368
+ post(resp.BaseResp);
369
+ if (needCount) {
370
+ return Number(resp.Total);
371
+ }
372
+ else {
373
+ return JSON.parse(resp.DataList);
374
+ }
375
+ }
376
+ async function updateWorkflowVariables(iCtx, instanceId, variables, variableTypes) {
377
+ // 1.前置处理
378
+ let ctx = await pre();
379
+ // 2.构造 params
380
+ let param = {};
381
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
382
+ param.WorkflowInstanceID = BigInt(instanceId);
383
+ param.Variables = variables;
384
+ // 3.发起请求
385
+ let resp;
386
+ try {
387
+ resp = await rpc.getInnerAPICli().UpdateVariablesByAPIAlias(ctx, param);
388
+ }
389
+ catch (err) {
390
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
391
+ }
392
+ // 4.后置处理
393
+ post(resp.BaseResp);
394
+ return;
395
+ }
396
+ async function uploadFile(data, expire) {
397
+ // 1.前置处理
398
+ let ctx = await pre();
399
+ // 2.构造 params
400
+ let param = {};
401
+ param.Data = await (0, stream_to_buffer_1.streamToBuffer)(data);
402
+ param.Name = "file";
403
+ param.EncryptType = 1;
404
+ param.PermissionConf = {
405
+ PermissionType: "",
406
+ PermissionInfo: "",
407
+ IgnoreUserID: true
408
+ };
409
+ if (expire) {
410
+ param.ExpireSecond = expire;
411
+ }
412
+ // 3.发起请求
413
+ let resp;
414
+ try {
415
+ resp = await rpc.getInnerAPICli().UploadAttachmentForRPC(ctx, param);
416
+ }
417
+ catch (err) {
418
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
419
+ }
420
+ // 4.后置处理
421
+ post(resp.BaseResp);
422
+ return {
423
+ id: resp.ID,
424
+ token: resp.Token,
425
+ size: resp.Size,
426
+ mimeType: resp.MimeType,
427
+ name: resp.Filename,
428
+ };
429
+ }
430
+ async function downloadFileByID(fileID, filePath) {
431
+ // 1. build parameters
432
+ let param = {};
433
+ param.FileID = fileID;
434
+ // 2. prepare request
435
+ let ctx = await pre();
436
+ // 3. do request
437
+ let resp;
438
+ try {
439
+ resp = await rpc.getInnerAPICli().DownloadFile(ctx, param);
440
+ }
441
+ catch (err) {
442
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
443
+ }
444
+ // 4. deal with response
445
+ post(resp.BaseResp);
446
+ if (filePath) {
447
+ checkUtils.checkFile(filePath);
448
+ utils.mkdirs(path.dirname(filePath));
449
+ fs.writeFileSync(filePath, resp.Data);
450
+ return;
451
+ }
452
+ else {
453
+ return resp.Data;
454
+ }
455
+ }
456
+ async function downloadFileByToken(fileToken, filePath) {
457
+ // 1. build parameters
458
+ let param = {};
459
+ param.Token = fileToken;
460
+ // 2. prepare request
461
+ let ctx = await pre();
462
+ // 3. do request
463
+ let resp;
464
+ try {
465
+ resp = await rpc.getInnerAPICli().DownloadAttachment(ctx, param);
466
+ }
467
+ catch (err) {
468
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
469
+ }
470
+ // 4. deal with response
471
+ post(resp.BaseResp);
472
+ if (filePath) {
473
+ checkUtils.checkFile(filePath);
474
+ utils.mkdirs(path.dirname(filePath));
475
+ fs.writeFileSync(filePath, resp.Data);
476
+ return;
477
+ }
478
+ else {
479
+ return resp.Data;
480
+ }
481
+ }
482
+ async function createMessage(msg) {
483
+ // 1. prepare args
484
+ if (!msg.icon) {
485
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
486
+ }
487
+ if (typeof (msg.icon) != 'string') {
488
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
489
+ }
490
+ let params = {};
491
+ let modelKeySearchData = new Map().set("icon_type", msg.icon);
492
+ let receiverIds = msg["target_users"] || [];
493
+ if (!(receiverIds instanceof Array)) {
494
+ throw new exceptions.InvalidParamError(`Invalid format of parameter target_users, target_users should be array.`);
495
+ }
496
+ if (receiverIds.length === 0) {
497
+ throw new exceptions.InvalidParamError(`parameter target_users is required!`);
498
+ }
499
+ let percent = msg["percent"];
500
+ if (percent !== undefined && percent !== null) {
501
+ if (typeof (percent) != 'number') {
502
+ throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
503
+ }
504
+ if (percent < 0 || percent > 100) {
505
+ throw new exceptions.InvalidParamError(`Invalid value of parameter percent, the value should be in range [0, 100].`);
506
+ }
507
+ else {
508
+ modelKeySearchData.set("percent", JSON.stringify(percent));
509
+ }
510
+ }
511
+ // kunlun类型
512
+ if (common.checkUtils.isObject(msg)) {
513
+ for (let key of Object.keys(msg)) {
514
+ if (common.fieldType.isKFieldType(msg[key])) {
515
+ // instanceof 改动6
516
+ // if (msg[key] instanceof fieldType.Multilingual) {
517
+ if (common.fieldType.isKFieldTypeMultilingual((msg[key]))) {
518
+ let value = JSON.stringify(msg[key].toJSON());
519
+ params[key] = JSON.stringify({ "value": value });
520
+ }
521
+ else {
522
+ params[key] = JSON.stringify(msg[key].toJSON());
523
+ }
524
+ }
525
+ else {
526
+ params[key] = JSON.stringify(msg[key]);
527
+ }
528
+ }
529
+ }
530
+ // 2. prepare for request
531
+ let ctx = await pre();
532
+ // 3. build parameters
533
+ let param = {};
534
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
535
+ param.NotifyModelKey = constants_1.notifyModel.key;
536
+ param.ReceiverIDs = receiverIds;
537
+ param.ParamsRawData = params;
538
+ param.Percent = percent;
539
+ param.ModelKeySearchData = modelKeySearchData;
540
+ // 4. do request
541
+ let resp;
542
+ try {
543
+ resp = await rpc.getInnerAPICli().CreateNotifyTask(ctx, param);
544
+ }
545
+ catch (err) {
546
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
547
+ }
548
+ // 5. deal with response
549
+ post(resp.BaseResp);
550
+ return Number(resp.TaskID);
551
+ }
552
+ async function updateMessage(msgId, msg) {
553
+ // 1. prepare args
554
+ if (!msgId) {
555
+ throw new exceptions.InvalidParamError(`parameter msgId is required!`);
556
+ }
557
+ if (typeof (msgId) != 'number') {
558
+ throw new exceptions.InvalidParamError(`Invalid format of parameter msgId, msgId should be number.`);
559
+ }
560
+ if (!msg.icon) {
561
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
562
+ }
563
+ if (typeof (msg.icon) != 'string') {
564
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
565
+ }
566
+ let params = new Map();
567
+ let modelKeySearchData = new Map().set("icon_type", msg.icon);
568
+ let percent = msg["percent"];
569
+ if (percent !== undefined && percent !== null) {
570
+ if (typeof (percent) != 'number') {
571
+ throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
572
+ }
573
+ if (percent < 0 || percent > 100) {
574
+ throw new exceptions.InvalidParamError(`Invalid value of parameter percent in message ${msgId}, the value should be in range [0, 100].`);
575
+ }
576
+ else {
577
+ modelKeySearchData.set("percent", JSON.stringify(percent));
578
+ }
579
+ }
580
+ // kunlun类型
581
+ if (common.checkUtils.isObject(msg)) {
582
+ for (let key of Object.keys(msg)) {
583
+ if (common.fieldType.isKFieldType(msg[key])) {
584
+ // instanceof 改动7
585
+ // if (msg[key] instanceof fieldType.Multilingual) {
586
+ if (common.fieldType.isKFieldTypeMultilingual(msg[key])) {
587
+ let value = JSON.stringify(msg[key].toJSON());
588
+ params.set(key, JSON.stringify({ "value": value }));
589
+ }
590
+ else {
591
+ params.set(key, JSON.stringify(msg[key].toJSON()));
592
+ }
593
+ }
594
+ else {
595
+ params.set(key, JSON.stringify(msg[key]));
596
+ }
597
+ }
598
+ }
599
+ // 2. prepare for request
600
+ let ctx = await pre();
601
+ // 3. build parameters
602
+ let param = {};
603
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
604
+ param.TaskID = BigInt(msgId);
605
+ param.NotifyModelKey = constants_1.notifyModel.key;
606
+ param.ParamsRawData = params;
607
+ param.Percent = percent;
608
+ param.ModelKeySearchData = modelKeySearchData;
609
+ param.IsBackground = true;
610
+ // 4. do request
611
+ let resp;
612
+ try {
613
+ resp = await rpc.getInnerAPICli().UpdateNotifyTask(ctx, param);
614
+ }
615
+ catch (err) {
616
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
617
+ }
618
+ // 5. deal with response
619
+ post(resp.BaseResp);
620
+ }
621
+ async function getFields(objectApiName) {
622
+ // 1. prepare request
623
+ let ctx = await pre();
624
+ // 2. build parameters
625
+ let param = {};
626
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
627
+ param.ObjectAPIName = objectApiName;
628
+ // 3. do request
629
+ let resp;
630
+ try {
631
+ resp = await rpc.getInnerAPICli().GetObjectFields(ctx, param);
632
+ }
633
+ catch (err) {
634
+ throw new exceptions.InternalError(`Call InnerAPI getFields failed: ${err.message}`);
635
+ }
636
+ // 4.后置处理
637
+ post(resp.BaseResp);
638
+ try {
639
+ return JSON.parse(resp.Data);
640
+ }
641
+ catch (e) {
642
+ throw new exceptions.InternalError(`JSON parse failed: ${e.message}`);
643
+ }
644
+ }
645
+ async function getField(objectApiName, fieldApiName) {
646
+ // 1. prepare request
647
+ let ctx = await pre();
648
+ // 2. build parameters
649
+ let param = {};
650
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
651
+ param.ObjectAPIName = objectApiName;
652
+ param.FieldAPIName = fieldApiName;
653
+ // 3. do request
654
+ let resp;
655
+ try {
656
+ resp = await rpc.getInnerAPICli().GetObjectField(ctx, param);
657
+ }
658
+ catch (err) {
659
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
660
+ }
661
+ // 4. deal with response
662
+ post(resp.BaseResp);
663
+ try {
664
+ return JSON.parse(resp.Data);
665
+ }
666
+ catch (e) {
667
+ throw new exceptions.InternalError(`JSON parse failed: ${e.message}`);
668
+ }
669
+ }
670
+ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
671
+ // 1. prepare args
672
+ if (typeof (workflowInstanceId) !== "number") {
673
+ throw new exceptions.InvalidParamError(`The type of workflowInstanceId should be number, but ${typeof (workflowInstanceId)}.`);
674
+ }
675
+ // 2. prepare request
676
+ let ctx = await pre();
677
+ // 3. build parameters
678
+ let param = {};
679
+ param.WorkflowInstanceID = BigInt(workflowInstanceId);
680
+ param.Operator = BigInt(operator);
681
+ param.Reason = reason;
682
+ // 4. do request
683
+ let resp;
684
+ try {
685
+ resp = await rpc.getInnerAPICli().TerminateWorkflowInstance(ctx, param);
686
+ }
687
+ catch (err) {
688
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
689
+ }
690
+ // 5. deal with response
691
+ post(resp.BaseResp);
692
+ }
693
+ async function modifyRecordsWithTransaction(placeholders, operations) {
694
+ // 1. prepare args
695
+ // TODO: change placeholders type
696
+ let ph = new Map();
697
+ for (let key of Object.keys(placeholders)) {
698
+ ph.set(key, BigInt(placeholders[key]));
699
+ }
700
+ // 2. build parameters
701
+ let param = {};
702
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
703
+ param.Placeholders = ph;
704
+ // TODO: change operations type
705
+ param.Operations = operations;
706
+ param.OperatorID = BigInt(-1);
707
+ const taskID = utils.getTriggerTaskID();
708
+ if (taskID) {
709
+ param.TaskID = BigInt(taskID);
710
+ }
711
+ // 3. prepare request
712
+ let ctx = await pre();
713
+ // 4. do request
714
+ let resp;
715
+ try {
716
+ resp = await rpc.getInnerAPICli().ModifyRecordsWithTX(ctx, param);
717
+ }
718
+ catch (err) {
719
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
720
+ }
721
+ // 5. deal with response
722
+ post(resp.BaseResp);
723
+ return resp.Placeholders;
724
+ }
725
+ async function getGlobalConfigByKey(key) {
726
+ // 1. prepare request
727
+ let ctx = await pre();
728
+ // 2. get all global configs by page
729
+ let pageSize = 100, offset = 0;
730
+ for (let i = 0;; i++) {
731
+ let param = {};
732
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
733
+ param.BizType = "GlobalVariables";
734
+ param.UsedBy = "UsedBySystem";
735
+ param.Filter = {
736
+ Offset: BigInt(offset * i),
737
+ Limit: BigInt(pageSize),
738
+ };
739
+ // 3. do request
740
+ let resp;
741
+ try {
742
+ resp = await rpc.getInnerAPICli().GetAllConfig(ctx, param);
743
+ }
744
+ catch (err) {
745
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
746
+ }
747
+ post(resp.BaseResp);
748
+ // 4. find the config
749
+ for (let config of resp.Configs) {
750
+ if (config.Key === key) {
751
+ return config.Value;
752
+ }
753
+ }
754
+ // 5. check if there is next page
755
+ if (resp.Configs.length < 100) {
756
+ break;
757
+ }
758
+ }
759
+ throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
760
+ }
761
+ async function oql(oql, args, namedArgs) {
762
+ // 1. build parameters
763
+ const queryData = JSON.stringify({
764
+ "query": oql,
765
+ "args": args,
766
+ "named_args": namedArgs,
767
+ "compat": true
768
+ });
769
+ // 2. prepare args
770
+ let param = {};
771
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
772
+ param.QueryData = Buffer.from(queryData);
773
+ // 3. prepare request
774
+ let ctx = await pre();
775
+ // 4. do request
776
+ let resp;
777
+ try {
778
+ resp = await rpc.getInnerAPICli().QueryRecordsByOQL(ctx, param);
779
+ }
780
+ catch (err) {
781
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
782
+ }
783
+ // 5. deal with response
784
+ post(resp.BaseResp);
785
+ try {
786
+ return JSON.parse(resp.Rows ? resp.Rows : "[]");
787
+ }
788
+ catch (e) {
789
+ throw new exceptions.InternalError(`oql result parse failed: ${e.message}`);
790
+ }
791
+ }
792
+ async function openSDKCreateRecordBySync(objectApiName, record) {
793
+ // 1. prepare args
794
+ if (typeof (objectApiName) !== "string") {
795
+ throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
796
+ }
797
+ // 2. prepare request
798
+ let ctx = await pre();
799
+ // 3. build parameters
800
+ let param = {};
801
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
802
+ param.ObjectAPIName = objectApiName;
803
+ param.Record = record;
804
+ // 4. do request
805
+ let resp;
806
+ try {
807
+ resp = await rpc.getInnerAPICli().CreateRecord(ctx, param);
808
+ }
809
+ catch (err) {
810
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
811
+ }
812
+ // 5. deal with response
813
+ post(resp.BaseResp);
814
+ }
815
+ async function openSDKUpdateRecordBySync(objectApiName, recordID, record) {
816
+ // 1. prepare args
817
+ if (typeof (objectApiName) !== "string") {
818
+ throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
819
+ }
820
+ if (typeof (recordID) !== "number") {
821
+ throw new exceptions.InvalidParamError(`The type of recordID should be number, but ${typeof (recordID)}.`);
822
+ }
823
+ // 2. prepare request
824
+ let ctx = await pre();
825
+ // 3. build parameters
826
+ let param = {};
827
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
828
+ param.ObjectAPIName = objectApiName;
829
+ param.RecordID = BigInt(recordID);
830
+ param.Record = record;
831
+ // 4. do request
832
+ let resp;
833
+ try {
834
+ resp = await rpc.getInnerAPICli().UpdateRecord(ctx, param);
835
+ }
836
+ catch (err) {
837
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
838
+ }
839
+ // 5. deal with response
840
+ post(resp.BaseResp);
841
+ }
842
+ async function openSDKDeleteRecordBySync(objectApiName, recordID) {
843
+ // 1. prepare args
844
+ if (typeof (objectApiName) !== "string") {
845
+ throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
846
+ }
847
+ if (typeof (recordID) !== "number") {
848
+ throw new exceptions.InvalidParamError(`The type of recordID should be number, but ${typeof (recordID)}.`);
849
+ }
850
+ // 2. prepare request
851
+ let ctx = await pre();
852
+ // 3. build parameters
853
+ let param = {};
854
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
855
+ param.ObjectAPIName = objectApiName;
856
+ param.RecordID = BigInt(recordID);
857
+ // 4. do request
858
+ let resp;
859
+ try {
860
+ resp = await rpc.getInnerAPICli().DeleteRecord(ctx, param);
861
+ }
862
+ catch (err) {
863
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
864
+ }
865
+ // 5. deal with response
866
+ post(resp.BaseResp);
867
+ }
868
+ async function openSDKCreateRecordsBySync(objectApiName, records) {
869
+ // 1. prepare args
870
+ if (typeof (objectApiName) !== "string") {
871
+ throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
872
+ }
873
+ // 2. prepare request
874
+ let ctx = await pre();
875
+ // 3. build parameters
876
+ let param = {};
877
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
878
+ param.ObjectAPIName = objectApiName;
879
+ param.Records = records;
880
+ // 4. do request
881
+ let resp;
882
+ try {
883
+ resp = await rpc.getInnerAPICli().BatchCreateRecords(ctx, param);
884
+ }
885
+ catch (err) {
886
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
887
+ }
888
+ // 5. deal with response
889
+ post(resp.BaseResp);
890
+ }
891
+ async function openSDKUpdateRecordsBySync(objectApiName, recordMap) {
892
+ // 1. prepare args
893
+ if (typeof (objectApiName) !== "string") {
894
+ throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
895
+ }
896
+ // 2. prepare request
897
+ let ctx = await pre();
898
+ // 3. build parameters
899
+ let param = {};
900
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
901
+ param.ObjectAPIName = objectApiName;
902
+ param.RecordMap = recordMap;
903
+ // 4. do request
904
+ let resp;
905
+ try {
906
+ resp = await rpc.getInnerAPICli().BatchUpdateRecords(ctx, param);
907
+ }
908
+ catch (err) {
909
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
910
+ }
911
+ // 5. deal with response
912
+ post(resp.BaseResp);
913
+ }
914
+ async function openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
915
+ // 1. prepare args
916
+ if (typeof (objectApiName) !== "string") {
917
+ throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
918
+ }
919
+ // 2. prepare request
920
+ let ctx = await pre();
921
+ // 3. build parameters
922
+ let param = {};
923
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
924
+ param.ObjectAPIName = objectApiName;
925
+ param.RecordIDs = recordIDs;
926
+ // 4. do request
927
+ let resp;
928
+ try {
929
+ resp = await rpc.getInnerAPICli().BatchDeleteRecords(ctx, param);
930
+ }
931
+ catch (err) {
932
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
933
+ }
934
+ // 5. deal with response
935
+ post(resp.BaseResp);
936
+ }
937
+ async function openSDKGetRecords(objectApiName, param) {
938
+ // 1. prepare args
939
+ if (param.limit <= 0 || param.limit > 200) {
940
+ param.limit = 200;
941
+ }
942
+ let req;
943
+ req.ObjectAPIAlias = objectApiName;
944
+ req.Filter = JSON.stringify(param.filter);
945
+ req.Limit = BigInt(param.limit);
946
+ req.Offset = BigInt(param.offset);
947
+ req.FiledAPIAlias = param.fields;
948
+ req.NeedTotalCount = param.count;
949
+ let sortList = [];
950
+ if (param.sort) {
951
+ param.sort.forEach((sort) => {
952
+ sortList.push({
953
+ FieldApiAlias: sort.field,
954
+ Type: sort.type,
955
+ Direction: sort.direction,
956
+ });
957
+ });
958
+ }
959
+ req.Sort = sortList;
960
+ // 2. prepare request
961
+ let ctx = await pre();
962
+ // 3. do request
963
+ let resp;
964
+ try {
965
+ resp = await rpc.getInnerAPICli().GetRecordList(ctx, req);
966
+ }
967
+ catch (err) {
968
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
969
+ }
970
+ // 4. deal with response
971
+ post(resp.BaseResp);
972
+ // 5. return result
973
+ if (param.count) {
974
+ return resp.Total;
975
+ }
976
+ else {
977
+ return resp.Data;
978
+ }
979
+ }
980
+ ;
981
+ async function openSDKUploadFile(fileName, data) {
982
+ // 1. prepare args
983
+ let param;
984
+ param.Name = fileName;
985
+ param.EncryptType = 1; // no encrypt
986
+ param.Data = data;
987
+ // 2. prepare request
988
+ let ctx = await pre();
989
+ // 3. do request
990
+ let resp;
991
+ try {
992
+ resp = await rpc.getAttachmentCli().UploadFileForRPC(ctx, param);
993
+ }
994
+ catch (err) {
995
+ throw new exceptions.InternalError(`Call Attachment failed: ${err.message}`);
996
+ }
997
+ // 4. deal with response
998
+ post(resp.BaseResp);
999
+ return resp;
1000
+ }
1001
+ async function openSDKUploadAvatar(fileName, data) {
1002
+ // 1. prepare args
1003
+ let param;
1004
+ param.EncryptType = 1; // no encrypt
1005
+ param.Data = data;
1006
+ // 2. prepare request
1007
+ let ctx = await pre();
1008
+ // 3. do request
1009
+ let resp;
1010
+ try {
1011
+ resp = await rpc.getAttachmentCli().UploadAvatarForRPC(ctx, param);
1012
+ }
1013
+ catch (err) {
1014
+ throw new exceptions.InternalError(`Call Attachment failed: ${err.message}`);
1015
+ }
1016
+ // 4. deal with response
1017
+ post(resp.BaseResp);
1018
+ return resp;
1019
+ }
1020
+ async function openSDKDownloadAvatar(imageID) {
1021
+ // 1. prepare args
1022
+ let param;
1023
+ param.ImageID = imageID;
1024
+ // 2. prepare request
1025
+ let ctx = await pre();
1026
+ // 3. do request
1027
+ let resp;
1028
+ try {
1029
+ resp = await rpc.getAttachmentCli().DownloadAvatarForRPC(ctx, param);
1030
+ }
1031
+ catch (err) {
1032
+ throw new exceptions.InternalError(`Call Attachment failed: ${err.message}`);
1033
+ }
1034
+ // 4. deal with response
1035
+ post(resp.BaseResp);
1036
+ return resp.Data;
1037
+ }
1038
+ class RequestRpc {
1039
+ constructor() {
1040
+ this.updateWorkflowVariables = updateWorkflowVariables;
1041
+ this.createRecordBySync = createRecordBySync;
1042
+ this.updateRecordBySync = updateRecordBySync;
1043
+ this.deleteRecordBySync = deleteRecordBySync;
1044
+ this.createRecordsByAsync = createRecordsByAsync;
1045
+ this.updateRecordsByAsync = updateRecordsByAsync;
1046
+ this.deleteRecordsByAsync = deleteRecordsByAsync;
1047
+ this.createRecordsBySync = createRecordsBySync;
1048
+ this.updateRecordsBySync = updateRecordsBySync;
1049
+ this.deleteRecordsBySync = deleteRecordsBySync;
1050
+ this.getRecordsOrCountByCriterion = getRecordsOrCountByCriterion;
1051
+ this.uploadFile = uploadFile;
1052
+ this.downloadFileByID = downloadFileByID;
1053
+ this.downloadFileByToken = downloadFileByToken;
1054
+ this.createMessage = createMessage;
1055
+ this.updateMessage = updateMessage;
1056
+ this.getFields = getFields;
1057
+ this.getField = getField;
1058
+ this.terminateWorkflowInstance = terminateWorkflowInstance;
1059
+ this.modifyRecordsWithTransaction = modifyRecordsWithTransaction;
1060
+ this.getGlobalConfigByKey = getGlobalConfigByKey;
1061
+ this.oql = oql;
1062
+ // open sdk api
1063
+ this.openSDKCreateRecordBySync = openSDKCreateRecordBySync;
1064
+ this.openSDKUpdateRecordBySync = openSDKUpdateRecordBySync;
1065
+ this.openSDKDeleteRecordBySync = openSDKDeleteRecordBySync;
1066
+ this.openSDKCreateRecordsBySync = openSDKCreateRecordsBySync;
1067
+ this.openSDKUpdateRecordsBySync = openSDKUpdateRecordsBySync;
1068
+ this.openSDKDeleteRecordsBySync = openSDKDeleteRecordsBySync;
1069
+ this.openSDKGetRecords = openSDKGetRecords;
1070
+ this.openSDKUploadFile = openSDKUploadFile;
1071
+ this.openSDKUploadAvatar = openSDKUploadAvatar;
1072
+ this.openSDKDownloadAvatar = openSDKDownloadAvatar;
1073
+ }
1074
+ createRecordBySync(objectApiName, record) {
1075
+ }
1076
+ updateRecordBySync(objectApiName, recordID, record) {
1077
+ }
1078
+ deleteRecordBySync(objectApiName, recordID) {
1079
+ }
1080
+ createRecordsByAsync(objectApiName, records) {
1081
+ }
1082
+ updateRecordsByAsync(objectApiName, recordMap) {
1083
+ }
1084
+ deleteRecordsByAsync(objectApiName, recordIDs) {
1085
+ }
1086
+ createRecordsBySync(objectApiName, records) {
1087
+ }
1088
+ updateRecordsBySync(objectApiName, recordMap) {
1089
+ }
1090
+ deleteRecordsBySync(objectApiName, recordIDs) {
1091
+ }
1092
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
1093
+ }
1094
+ async updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1095
+ }
1096
+ async uploadFile(data, expire) {
1097
+ return null;
1098
+ }
1099
+ async downloadFileByID(fileID, filePath) {
1100
+ return null;
1101
+ }
1102
+ async downloadFileByToken(fileToken, filePath) {
1103
+ return null;
1104
+ }
1105
+ async createMessage(msg) {
1106
+ return null;
1107
+ }
1108
+ async updateMessage(msgId, msg) {
1109
+ return null;
1110
+ }
1111
+ async getFields(objectApiName) {
1112
+ }
1113
+ async getField(objectApiName, fieldApiName) {
1114
+ }
1115
+ async terminateWorkflowInstance(workflowInstanceId, operator, reason) {
1116
+ }
1117
+ async modifyRecordsWithTransaction(placeholders, operations) {
1118
+ return null;
1119
+ }
1120
+ async getGlobalConfigByKey(key) {
1121
+ return null;
1122
+ }
1123
+ async oql(oql, args, namedArgs) {
1124
+ return [];
1125
+ }
1126
+ async invokeFuncSync(idOrName, params) {
1127
+ return await invokeFuncSync(idOrName, params);
1128
+ }
1129
+ async invokeFuncWithAuth(idOrName, params) {
1130
+ return await invokeFuncWithAuth(idOrName, params);
1131
+ }
1132
+ async createAsyncTaskV1(idOrName, params) {
1133
+ return await createAsyncTaskV1(idOrName, params);
1134
+ }
1135
+ async createAsyncTaskV2(name, params) {
1136
+ return await createAsyncTaskV2(name, params);
1137
+ }
1138
+ async getExecutionUserTaskInfo(executionId) {
1139
+ return await getExecutionUserTaskInfo(executionId);
1140
+ }
1141
+ async executeFlow(APIName, options) {
1142
+ return await executeFlow(APIName, options);
1143
+ }
1144
+ async revokeExecution(executionId, revokeOptions) {
1145
+ return await revokeExecution(executionId, revokeOptions);
1146
+ }
1147
+ async getExecutionInfo(executionId) {
1148
+ return await getExecutionInfo(executionId);
1149
+ }
1150
+ async getTenantInfo(appCtx) {
1151
+ return await appCtx.credential.getTenantInfo();
1152
+ }
1153
+ // open sdk empty implement
1154
+ openSDKCreateRecordBySync(objectApiName, record) {
1155
+ }
1156
+ ;
1157
+ openSDKUpdateRecordBySync(objectApiName, recordID, record) {
1158
+ }
1159
+ ;
1160
+ openSDKDeleteRecordBySync(objectApiName, recordID) {
1161
+ }
1162
+ ;
1163
+ openSDKCreateRecordsBySync(objectApiName, records) {
1164
+ }
1165
+ ;
1166
+ openSDKUpdateRecordsBySync(objectApiName, recordMap) {
1167
+ }
1168
+ ;
1169
+ openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
1170
+ }
1171
+ ;
1172
+ openSDKGetRecords(objectApiName, param) {
1173
+ }
1174
+ ;
1175
+ openSDKUploadFile(fileName, data) {
1176
+ }
1177
+ ;
1178
+ openSDKUploadAvatar(fileName, data) {
1179
+ }
1180
+ ;
1181
+ openSDKDownloadAvatar(imageID) {
1182
+ }
1183
+ ;
1184
+ }
1185
+ exports.RequestRpc = RequestRpc;
1186
+ async function invokeFuncWithAuth(idOrName, params) {
1187
+ let ctx = await pre(true);
1188
+ let param = {};
1189
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1190
+ if (idOrName.isInvokeByAPIName) {
1191
+ param.ApiName = idOrName.APIName;
1192
+ }
1193
+ else {
1194
+ param.ApiID = idOrName.APIId;
1195
+ }
1196
+ param.Params = JSON.stringify(params);
1197
+ param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1198
+ let resp = undefined;
1199
+ try {
1200
+ resp = await rpc.getInnerAPICli().InvokeFunctionWithAuth(ctx, param);
1201
+ }
1202
+ catch (err) {
1203
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1204
+ }
1205
+ post(resp.BaseResp);
1206
+ let result;
1207
+ try {
1208
+ result = JSON.parse(resp.result);
1209
+ }
1210
+ catch (e) {
1211
+ throw new exceptions.InternalError(`JSON parse failed for ${resp.result}`);
1212
+ }
1213
+ if (!result || result.code !== "0") {
1214
+ throw new exceptions.InvalidParamError(`result is invalid for code: ${result ? result.code : ""} msg: ${result ? result.msg : ""}`);
1215
+ }
1216
+ return result.data;
1217
+ }
1218
+ async function executeFlow(APIName, options) {
1219
+ let ctx = await pre();
1220
+ let param = {};
1221
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1222
+ param.Operator = BigInt(utils.getUserIDFromCtx());
1223
+ param.FlowAPIName = APIName;
1224
+ param.variables = JSON.stringify((0, common_1.transMapToFlowVariable)(options.params));
1225
+ param.LoopMasks = utils.getLoopMasks();
1226
+ let resp = undefined;
1227
+ try {
1228
+ resp = await rpc.getInnerAPICli().Execute(ctx, param);
1229
+ }
1230
+ catch (err) {
1231
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1232
+ }
1233
+ // 5.后置处理
1234
+ post(resp.BaseResp);
1235
+ let outParams = [];
1236
+ try {
1237
+ if (resp.OutParams) {
1238
+ outParams = JSON.parse(resp.OutParams);
1239
+ }
1240
+ }
1241
+ catch (e) {
1242
+ throw new exceptions_1.InternalError(`Execute OutParams in Result is invalid (${resp.OutParams}), err: ${e.message}`);
1243
+ }
1244
+ return {
1245
+ executionId: Number(resp.ExecutionID),
1246
+ status: resp.Status,
1247
+ data: (0, common_1.transFlowVariableToMap)(outParams),
1248
+ errCode: resp.errCode ? resp.errCode : undefined,
1249
+ errMsg: resp.errMsg ? resp.errMsg : undefined,
1250
+ };
1251
+ }
1252
+ async function revokeExecution(executionId, revokeOptions) {
1253
+ let ctx = await pre();
1254
+ let param = {};
1255
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1256
+ param.Operator = BigInt(utils.getUserIDFromCtx());
1257
+ param.ExecutionID = BigInt(executionId);
1258
+ let reason = undefined;
1259
+ if (revokeOptions && revokeOptions.reason) {
1260
+ reason = {
1261
+ En: revokeOptions.reason.en_US,
1262
+ Zh: revokeOptions.reason.zh_CN
1263
+ };
1264
+ }
1265
+ param.Reason = reason;
1266
+ let resp = undefined;
1267
+ try {
1268
+ resp = await rpc.getInnerAPICli().RevokeExecution(ctx, param);
1269
+ }
1270
+ catch (err) {
1271
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1272
+ }
1273
+ // 5.后置处理
1274
+ post(resp.BaseResp);
1275
+ }
1276
+ exports.revokeExecution = revokeExecution;
1277
+ async function getExecutionInfo(executionId) {
1278
+ let ctx = await pre();
1279
+ let param = {};
1280
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1281
+ param.ExecutionID = BigInt(executionId);
1282
+ param.Operator = BigInt(utils.getUserIDFromCtx());
1283
+ let resp = undefined;
1284
+ try {
1285
+ resp = await rpc.getInnerAPICli().GetExecutionInfo(ctx, param);
1286
+ }
1287
+ catch (err) {
1288
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1289
+ }
1290
+ // 5.后置处理
1291
+ post(resp.BaseResp);
1292
+ if (!resp || !resp.ExecutionInfo) {
1293
+ throw new exceptions_1.InternalError(`GetExecutionInfo Response is empty`);
1294
+ }
1295
+ let outParams = [];
1296
+ try {
1297
+ if (resp.ExecutionInfo.outParams) {
1298
+ outParams = JSON.parse(resp.ExecutionInfo.outParams);
1299
+ }
1300
+ }
1301
+ catch (e) {
1302
+ throw new exceptions_1.InternalError(`GetExecutionInfo OutParams in Result is invalid (${resp.ExecutionInfo.outParams}), err: ${e.message}`);
1303
+ }
1304
+ return {
1305
+ status: resp.ExecutionInfo.status,
1306
+ data: (0, common_1.transFlowVariableToMap)(outParams),
1307
+ errCode: resp.ExecutionInfo.errCode ? resp.ExecutionInfo.errCode : undefined,
1308
+ errMsg: resp.ExecutionInfo.errMsg ? resp.ExecutionInfo.errMsg : undefined,
1309
+ };
1310
+ }
1311
+ exports.getExecutionInfo = getExecutionInfo;
1312
+ async function getExecutionUserTaskInfo(executionId) {
1313
+ let ctx = await pre();
1314
+ let param = {};
1315
+ param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1316
+ param.ExecutionID = BigInt(executionId);
1317
+ param.Operator = BigInt(utils.getUserIDFromCtx());
1318
+ let resp = undefined;
1319
+ try {
1320
+ resp = await rpc.getInnerAPICli().GetExecutionUserTaskInfo(ctx, param);
1321
+ }
1322
+ catch (err) {
1323
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1324
+ }
1325
+ // 5.后置处理
1326
+ post(resp.BaseResp);
1327
+ return resp.taskList;
1328
+ }
1329
+ exports.getExecutionUserTaskInfo = getExecutionUserTaskInfo;
1330
+ async function invokeFuncSync(idOrName, params) {
1331
+ let ctx = await pre(true);
1332
+ let param = {};
1333
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1334
+ if (idOrName.isInvokeByAPIName) {
1335
+ param.FunctionName = "";
1336
+ param.APIAlias = idOrName.APIName;
1337
+ }
1338
+ else {
1339
+ param.FunctionName = idOrName.APIId;
1340
+ param.APIAlias = "";
1341
+ }
1342
+ param.Params = JSON.stringify(params);
1343
+ param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1344
+ param.TriggerType = utils.getTriggerType();
1345
+ let resp;
1346
+ try {
1347
+ resp = await rpc.getInnerAPICli().InvokeFuncSync(ctx, param);
1348
+ }
1349
+ catch (err) {
1350
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1351
+ }
1352
+ // 5.后置处理
1353
+ post(resp.BaseResp);
1354
+ let result = {};
1355
+ try {
1356
+ result = JSON.parse(resp.Result);
1357
+ }
1358
+ catch (e) {
1359
+ throw new exceptions.InternalError(`Parse Result failed: ${e.message}`);
1360
+ }
1361
+ if (result && result.code === "0") {
1362
+ return result.data;
1363
+ }
1364
+ throw new exceptions.InternalError(`[${result.code}] ${result.msg}`);
1365
+ }
1366
+ async function createAsyncTaskV1(idOrName, params) {
1367
+ let ctx = await pre(true);
1368
+ let param = {};
1369
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1370
+ if (idOrName.isInvokeByAPIName) {
1371
+ param.Alias = idOrName.APIName;
1372
+ param.Name = ""; // required
1373
+ }
1374
+ else {
1375
+ param.Name = idOrName.APIId;
1376
+ }
1377
+ param.Params = JSON.stringify(params);
1378
+ param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1379
+ param.TriggerType = utils.getTriggerType();
1380
+ let resp;
1381
+ try {
1382
+ resp = await rpc.getInnerAPICli().CreateAsyncTaskOld(ctx, param);
1383
+ }
1384
+ catch (err) {
1385
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1386
+ }
1387
+ // 5.后置处理
1388
+ post(resp.BaseResp);
1389
+ return Number(resp.TaskID);
1390
+ }
1391
+ async function createAsyncTaskV2(APIName, params) {
1392
+ let ctx = await pre(true);
1393
+ let param = {};
1394
+ param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1395
+ param.APIAlias = APIName;
1396
+ param.Params = JSON.stringify(params);
1397
+ param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1398
+ param.TriggerType = utils.getTriggerType();
1399
+ param.Extra = (0, common_1.getDebugExtraInfo)();
1400
+ let resp;
1401
+ try {
1402
+ resp = await rpc.getInnerAPICli().CreateAsyncTask(ctx, param);
1403
+ }
1404
+ catch (err) {
1405
+ throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1406
+ }
1407
+ // 5.后置处理
1408
+ post(resp.BaseResp);
1409
+ return Number(resp.TaskID);
1410
+ }
1411
+ //# sourceMappingURL=innerapi.js.map