@byted-apaas/server-sdk-node 0.0.1-beta.3

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