@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,1220 @@
1
+ import FormData = require("form-data");
2
+ import {Stream} from "stream";
3
+ import {notifyModel} from "../constants/constants";
4
+ import * as common from "@byted-apaas/server-common-node";
5
+ import {Order} from "../context/db/impl/order"
6
+ import {Criterion} from "../kunlun/operator/impl/logic";
7
+ import {openapiHttpPath as coreOapiHttpPath} from "./constants"
8
+ import {IInnerAPIRequest, OpenSDKGetRecordsReq, UploadFileResp} from "./interface";
9
+ import {headers} from "@byted-apaas/server-common-node/constants/constants";
10
+ import {
11
+ ExecutionInfo,
12
+ ExecutionResult,
13
+ FlowTaskInfo,
14
+ RevokeExecutionOptions
15
+ } from "@byted-apaas/server-common-node/context/workflow/workflow";
16
+ import {AppCtx} from "../application/application";
17
+ import {
18
+ getDebugExtraInfo,
19
+ getNamespaceForOpenAndFaaSSDK,
20
+ transFlowVariableToMap,
21
+ transMapToFlowVariable
22
+ } from "./common";
23
+
24
+ const nodeCls = require("node-cls");
25
+
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+ const commonHttp = common.http;
29
+ const openapi = common.http.openapi;
30
+ const openapiHttpPath = common.http.openapiHttpPath;
31
+ const replaceKeys = common.http.replaceKeys;
32
+ const exceptions = common.exceptions;
33
+ const fieldType = common.fieldType;
34
+ const utils = common.utils;
35
+ const checkUtils = common.checkUtils;
36
+
37
+ export async function updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object) {
38
+ let options = commonHttp.getOptions(null, openapiHttpPath.workflowUpdateVariablesV2);
39
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
40
+
41
+ // 2.请求
42
+ options.json = {
43
+ "operator": -1,
44
+ "workflowInstanceID": instanceId,
45
+ "variables": JSON.parse(variables as any),
46
+ "variableTypes": JSON.parse(variableTypes as any),
47
+ };
48
+
49
+ await openapi.doRequest(null, urlPath, options);
50
+ }
51
+
52
+ async function createRecordBySync(objectApiName: string, record: object) {
53
+ // 1.check
54
+ if (!objectApiName) {
55
+ throw new exceptions.InvalidParamError("objectApiName is empty");
56
+ }
57
+
58
+ // 2.获取 options
59
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordBySyncV2);
60
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
61
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
62
+
63
+ // 3.请求
64
+ options.json = {
65
+ "operator": -1,
66
+ "data": record,
67
+ }
68
+
69
+ let task_id = utils.getTriggerTaskID();
70
+ if (task_id) {
71
+ options.json["task_id"] = task_id;
72
+ }
73
+
74
+ let data = await openapi.doRequest(null, urlPath, options)
75
+
76
+ if (data && data.record_id) {
77
+ return {_id: data.record_id};
78
+ }
79
+
80
+ if (data && data.recordID) {
81
+ return {_id: data.recordID};
82
+ }
83
+
84
+ return data;
85
+ }
86
+
87
+ async function updateRecordBySync(objectApiName: string, recordID: number, record: object) {
88
+ // 1.check
89
+ if (!objectApiName) {
90
+ throw new exceptions.InvalidParamError("objectApiName is empty");
91
+ }
92
+
93
+ // 2.获取 options
94
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordBySyncV2);
95
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
96
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
97
+
98
+ // 3.请求
99
+ options.json = {
100
+ "operator": -1,
101
+ "record_id": recordID,
102
+ "data": record,
103
+ }
104
+
105
+ let task_id = utils.getTriggerTaskID();
106
+ if (task_id) {
107
+ options.json["task_id"] = task_id;
108
+ }
109
+
110
+ return openapi.doRequest(null, urlPath, options);
111
+ }
112
+
113
+ async function deleteRecordBySync(objectApiName: string, recordID: number) {
114
+ // 1.check
115
+ if (!objectApiName) {
116
+ throw new exceptions.InvalidParamError("objectApiName is empty");
117
+ }
118
+
119
+ // 2.获取 options
120
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordBySyncV2);
121
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
122
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
123
+
124
+ // 3.请求
125
+ options.json = {
126
+ "operator": -1,
127
+ "record_id": recordID,
128
+ }
129
+
130
+ let task_id = utils.getTriggerTaskID();
131
+ if (task_id) {
132
+ options.json["task_id"] = task_id;
133
+ }
134
+
135
+ return openapi.doRequest(null, urlPath, options);
136
+ }
137
+
138
+ async function createRecordsByAsync(objectApiName: string, records: object[]) {
139
+ // 1.获取 options
140
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordsByAsyncV2);
141
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
142
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
143
+
144
+ // 2.请求
145
+ options.json = {
146
+ "operator": -1,
147
+ "data": records,
148
+ };
149
+
150
+ let task_id = utils.getTriggerTaskID();
151
+ if (task_id) {
152
+ options.json["automation_task_id"] = task_id;
153
+ }
154
+ return openapi.doRequest(null, urlPath, options);
155
+ }
156
+
157
+ async function updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>) {
158
+ // 1.获取 options
159
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordsByAsyncV2);
160
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
161
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
162
+
163
+ // 2.请求
164
+ options.json = {
165
+ "operator": -1,
166
+ "data": recordMap,
167
+ };
168
+
169
+ let task_id = utils.getTriggerTaskID();
170
+ if (task_id) {
171
+ options.json["automation_task_id"] = task_id;
172
+ }
173
+ return openapi.doRequest(null, urlPath, options);
174
+ }
175
+
176
+ async function deleteRecordsByAsync(objectApiName: string, recordIDs: number[]) {
177
+ // 1.获取 options
178
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordsByAsyncV2);
179
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
180
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
181
+
182
+ // 2.请求
183
+ options.json = {
184
+ "operator": -1,
185
+ "record_id_list": recordIDs,
186
+ };
187
+
188
+ let task_id = utils.getTriggerTaskID();
189
+ if (task_id) {
190
+ options.json["automation_task_id"] = task_id;
191
+ }
192
+ return openapi.doRequest(null, urlPath, options);
193
+ }
194
+
195
+ async function createRecordsBySync(objectApiName: string, records: object[]) {
196
+ // 1.获取 options
197
+ let options = commonHttp.getOptions(null, openapiHttpPath.mCreateRecordsBySyncV2);
198
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
199
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
200
+
201
+ // 2.请求
202
+ options.json = {
203
+ "operator": -1,
204
+ "data": records,
205
+ };
206
+
207
+ let task_id = utils.getTriggerTaskID();
208
+ if (task_id) {
209
+ options.json["automation_task_id"] = task_id;
210
+ }
211
+ return openapi.doRequest(null, urlPath, options);
212
+ }
213
+
214
+ async function updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>) {
215
+ // 1.获取 options
216
+ let options = commonHttp.getOptions(null, openapiHttpPath.mUpdateRecordsBySyncV2);
217
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
218
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
219
+
220
+ // 2.请求
221
+ options.json = {
222
+ "operator": -1,
223
+ "data": recordMap,
224
+ };
225
+
226
+ let task_id = utils.getTriggerTaskID();
227
+ if (task_id) {
228
+ options.json["automation_task_id"] = task_id;
229
+ }
230
+ return openapi.doRequest(null, urlPath, options);
231
+ }
232
+
233
+ async function deleteRecordsBySync(objectApiName: string, recordIDs: number[]) {
234
+ // 1.获取 options
235
+ let options = commonHttp.getOptions(null, openapiHttpPath.mDeleteRecordsBySyncV2);
236
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
237
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
238
+
239
+ // 2.请求
240
+ options.json = {
241
+ "operator": -1,
242
+ "record_id_list": recordIDs,
243
+ };
244
+
245
+ let task_id = utils.getTriggerTaskID();
246
+ if (task_id) {
247
+ options.json["automation_task_id"] = task_id;
248
+ }
249
+ return openapi.doRequest(null, urlPath, options);
250
+ }
251
+
252
+ function handleResponse(data: Record<string, unknown>, needCount: boolean) {
253
+ // 返回数据的特殊处理
254
+ if (needCount) {
255
+ if (checkUtils.isObject(data) && data["total"]) {
256
+ return data["total"]
257
+ }
258
+ return 0;
259
+ } else {
260
+ if (checkUtils.isObject(data) && data["data_list"]) {
261
+ return data["data_list"];
262
+ }
263
+ return [];
264
+ }
265
+ }
266
+
267
+ async function getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean) {
268
+ if (limit > 1000) {
269
+ limit = 1000;
270
+ }
271
+
272
+ // 1.check
273
+ if (!objectApiName) {
274
+ throw new exceptions.InternalError("objectApiName is empty");
275
+ }
276
+
277
+ // 2.获取 options
278
+ let options = commonHttp.getOptions(null, needCount ? openapiHttpPath.mGetCountByCriterionV2 : openapiHttpPath.mGetRecordByCriterionV2);
279
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
280
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
281
+
282
+ // 3.请求
283
+ options.json = {
284
+ "criterion": JSON.parse(criterion as any),
285
+ "order": order,
286
+ "ignore_back_lookup_field": ignoreBackLookupField,
287
+ "field_api_names": fieldApiNames,
288
+ "offset": offset,
289
+ "limit": limit,
290
+ "need_filter_user_permission": false,
291
+ "need_total_count": needCount,
292
+ };
293
+
294
+ let data = await openapi.doRequest(null, urlPath, options);
295
+ return handleResponse(data, needCount)
296
+ }
297
+
298
+ /**
299
+ * 上传文件
300
+ *
301
+ * @param ctx
302
+ * @param datas:filePath;Stream
303
+ * @param expire(seconds)
304
+ * @returns {Promise<*|string>}
305
+ */
306
+ async function uploadFile(datas: Stream, expire: number = 0): Promise<UploadFileResp> {
307
+ let formData = new FormData();
308
+ formData.append('file', datas);
309
+ formData.append('expireSeconds', expire.toString());
310
+ formData.append('ignoreUserId', 'true');
311
+ let formHeaders = formData.getHeaders();
312
+
313
+ // 1.获取config
314
+ let options = commonHttp.getOptions(null, openapiHttpPath.uploadAttachment);
315
+ let urlPath: string = options._reqPath;
316
+
317
+ options.responseType = 'buffer';
318
+ for (let key of Object.keys(formHeaders)) {
319
+ options.headers[key] = formHeaders[key];
320
+ }
321
+ options.body = formData;
322
+
323
+ // 2.请求
324
+ return await openapi.doRequest(null, urlPath, options);
325
+ }
326
+
327
+ async function downloadFileByID(id: string, filePath?: string): Promise<Buffer | void> {
328
+ // 1.获取 options
329
+ let options = commonHttp.getOptions(null, openapiHttpPath.downloadFile);
330
+ let urlPath = options._reqPath.replace(replaceKeys.fileID, id)
331
+ options.responseType = "buffer";
332
+
333
+ // 2.请求
334
+ let data = await openapi.doRequest(null, urlPath, options);
335
+
336
+ // 3.写入文件
337
+ data = Buffer.from(data, 'binary');
338
+ if (filePath) {
339
+ checkUtils.checkFile(filePath);
340
+ utils.mkdirs(path.dirname(filePath));
341
+ fs.writeFileSync(filePath, data);
342
+ return;
343
+ }
344
+
345
+ return data;
346
+ }
347
+
348
+ async function downloadFileByToken(fileToken: string, filePath?: string): Promise<Buffer | void> {
349
+ // 1.获取 options
350
+ let options = commonHttp.getOptions(null, openapiHttpPath.downloadAttachment);
351
+ let urlPath = options._reqPath + `?token=${fileToken}`;
352
+ options.responseType = "buffer";
353
+
354
+ // 2.请求
355
+ let data = await openapi.doRequest(null, urlPath, options);
356
+
357
+ // 3.写入文件
358
+ data = Buffer.from(data, 'binary');
359
+ if (filePath) {
360
+ checkUtils.checkFile(filePath);
361
+ utils.mkdirs(path.dirname(filePath));
362
+ fs.writeFileSync(filePath, data);
363
+ return;
364
+ }
365
+
366
+ return data;
367
+ }
368
+
369
+ async function mGetFileToken(ids: string[]): Promise<Record<string, string>> {
370
+ // 1.获取 options
371
+ let options = commonHttp.getOptions(null, coreOapiHttpPath.getBatchAttachmentToken);
372
+ let urlPath = options._reqPath;
373
+
374
+ // 2.请求
375
+ options.json = {
376
+ attachmentIds: ids
377
+ }
378
+ return await openapi.doRequest(null, urlPath, options);
379
+ }
380
+
381
+ async function createMessage(msg: any): Promise<number> {
382
+ // 1.解析参数 icon/receiverIds/percent
383
+ if (!msg.icon) {
384
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
385
+ }
386
+
387
+ if (typeof (msg.icon) != 'string') {
388
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
389
+ }
390
+ let params: any = {};
391
+ let modelKeySearchData: Record<string, any> = {"icon_type": msg.icon};
392
+
393
+ let receiverIds = msg["target_users"] || [];
394
+ if (!(receiverIds instanceof Array)) {
395
+ throw new exceptions.InvalidParamError(`Invalid format of parameter target_users, target_users should be array.`);
396
+ }
397
+ if (receiverIds.length === 0) {
398
+ throw new exceptions.InvalidParamError(`parameter target_users is required!`);
399
+ }
400
+
401
+ let percent = msg["percent"];
402
+ if (percent !== undefined && percent !== null) {
403
+ if (typeof (percent) != 'number') {
404
+ throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
405
+ }
406
+ if (percent < 0 || percent > 100) {
407
+ throw new exceptions.InvalidParamError(`Invalid value of parameter percent, the value should be in range [0, 100].`);
408
+ } else {
409
+ modelKeySearchData["percent"] = JSON.stringify(percent);
410
+ }
411
+ }
412
+
413
+ // kunlun类型
414
+ if (checkUtils.isObject(msg)) {
415
+ for (let key of Object.keys(msg)) {
416
+ if (fieldType.isKFieldType(msg[key])) {
417
+ // instanceof 改动6
418
+ // if (msg[key] instanceof fieldType.Multilingual) {
419
+ if (fieldType.isKFieldTypeMultilingual((msg[key]))) {
420
+ let value = JSON.stringify(msg[key].toJSON());
421
+ params[key] = JSON.stringify({"value": value});
422
+ } else {
423
+ params[key] = JSON.stringify(msg[key].toJSON());
424
+ }
425
+ } else {
426
+ params[key] = JSON.stringify(msg[key]);
427
+ }
428
+ }
429
+ }
430
+
431
+ // 2.获取 options
432
+ let options = commonHttp.getOptions(null, openapiHttpPath.createMessage);
433
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK())
434
+
435
+ // 3.请求
436
+ options.json = {
437
+ "NotifyModelKey": notifyModel.key,
438
+ "ReceiverIDs": receiverIds,
439
+ "ParamsRawData": params,
440
+ "Percent": percent,
441
+ "ModelKeySearchData": modelKeySearchData
442
+ }
443
+
444
+ let res = await openapi.doRequest(null, urlPath, options);
445
+ return Number((res as any).taskID);
446
+ }
447
+
448
+ async function updateMessage(msgId: number, msg: any): Promise<void> {
449
+ // 1.解析参数 msgId/icon/percent
450
+ if (!msgId) {
451
+ throw new exceptions.InvalidParamError(`parameter msgId is required!`);
452
+ }
453
+
454
+ if (typeof (msgId) != 'number') {
455
+ throw new exceptions.InvalidParamError(`Invalid format of parameter msgId, msgId should be number.`);
456
+ }
457
+
458
+ if (!msg.icon) {
459
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
460
+ }
461
+ if (typeof (msg.icon) != 'string') {
462
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
463
+ }
464
+ let params: Record<string, any> = {};
465
+ let modelKeySearchData: Record<string, any> = {"icon_type": msg.icon};
466
+
467
+ let percent = msg["percent"];
468
+ if (percent !== undefined && percent !== null) {
469
+ if (typeof (percent) != 'number') {
470
+ throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
471
+ }
472
+ if (percent < 0 || percent > 100) {
473
+ throw new exceptions.InvalidParamError(`Invalid value of parameter percent in message ${msgId}, the value should be in range [0, 100].`);
474
+ } else {
475
+ modelKeySearchData["percent"] = JSON.stringify(percent);
476
+ }
477
+ }
478
+
479
+ // kunlun类型
480
+ if (checkUtils.isObject(msg)) {
481
+ for (let key of Object.keys(msg)) {
482
+ if (fieldType.isKFieldType(msg[key])) {
483
+ // instanceof 改动7
484
+ // if (msg[key] instanceof fieldType.Multilingual) {
485
+ if (fieldType.isKFieldTypeMultilingual(msg[key])) {
486
+ let value = JSON.stringify(msg[key].toJSON());
487
+ params[key] = JSON.stringify({"value": value});
488
+ } else {
489
+ params[key] = JSON.stringify(msg[key].toJSON());
490
+ }
491
+ } else {
492
+ params[key] = JSON.stringify(msg[key])
493
+ }
494
+ }
495
+ }
496
+
497
+ // 2.获取 options
498
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateMessage);
499
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK())
500
+
501
+ // 3.请求
502
+ options.json = {
503
+ "TaskID": msgId,
504
+ "Percent": percent,
505
+ "NotifyModelKey": notifyModel.key,
506
+ "ParamsRawData": params,
507
+ "IsBackground": true,
508
+ "ModelKeySearchData": modelKeySearchData
509
+ }
510
+
511
+ return await openapi.doRequest(null, urlPath, options);
512
+ }
513
+
514
+ async function getFields(objectApiName: string) {
515
+ // 1.check
516
+ if (!objectApiName) {
517
+ throw new exceptions.InvalidParamError("objectApiName is empty");
518
+ }
519
+
520
+ // 2.获取config
521
+ let options = commonHttp.getOptions(null, openapiHttpPath.getFieldsV5);
522
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK())
523
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
524
+
525
+ let obj = await openapi.doRequest(null, urlPath, options)
526
+ if (!obj || !obj.fields) {
527
+ return [];
528
+ }
529
+
530
+ return obj.fields;
531
+ }
532
+
533
+ async function getField(objectApiName: string, fieldApiName: string) {
534
+ // 1.check
535
+ if (!objectApiName) {
536
+ throw new exceptions.InternalError("objectApiName is empty");
537
+ }
538
+ if (!fieldApiName) {
539
+ throw new exceptions.InternalError("fieldApiName is empty");
540
+ }
541
+
542
+ // 2.获取 options
543
+ let options = commonHttp.getOptions(null, openapiHttpPath.getFieldV5);
544
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
545
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
546
+ urlPath = urlPath.replace(replaceKeys.fieldApiName, fieldApiName);
547
+
548
+ // 3.请求
549
+ return await openapi.doRequest(null, urlPath, options)
550
+ }
551
+
552
+ async function terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string) {
553
+ // 1.check
554
+ if (typeof (workflowInstanceId) !== "number") {
555
+ throw new exceptions.InvalidParamError(`The type of workflowInstanceId should be number, but ${typeof (workflowInstanceId)}.`);
556
+ }
557
+
558
+ // 2.获取 options
559
+ let options = commonHttp.getOptions(null, openapiHttpPath.terminateWorkflowInstance);
560
+ let urlPath = options._reqPath;
561
+
562
+ // 3.请求
563
+ options.json = {
564
+ "workflowInstanceID": workflowInstanceId,
565
+ "operator": operator,
566
+ "reason": reason,
567
+ }
568
+
569
+ await openapi.doRequest(null, urlPath, options);
570
+ }
571
+
572
+ async function modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[]): Promise<Map<string, number>> {
573
+ // 1.获取 options
574
+ let options = commonHttp.getOptions(null, openapiHttpPath.modifyRecordsWithTransaction);
575
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
576
+
577
+ // 2.请求
578
+ options.json = {
579
+ "placeholders": placeholders,
580
+ "operations": operations,
581
+ "operatorId": -1,
582
+ }
583
+
584
+ let taskId = utils.getTriggerTaskID();
585
+ if (taskId) {
586
+ options.json["taskId"] = taskId;
587
+ }
588
+
589
+ let result = await openapi.doRequest(null, urlPath, options);
590
+ let retPlaceholders = new Map<string, number>();
591
+ if (result && result.placeholders) {
592
+ for (let key of Object.keys(result.placeholders)) {
593
+ retPlaceholders.set(key, result.placeholders[key]);
594
+ }
595
+ }
596
+ return retPlaceholders
597
+ };
598
+
599
+ async function getGlobalConfigByKey<valueT>(key: string): Promise<valueT> {
600
+ // 1.获取 options
601
+ let options = commonHttp.getOptions(null, openapiHttpPath.getAllGlobalConfigs);
602
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
603
+
604
+ // 2.请求
605
+ let pageSize = 100, offset = 0;
606
+ for (let i = 0; ; i++) {
607
+ options.json = {
608
+ "biz_type": "GlobalVariables",
609
+ "used_by": "UsedBySystem",
610
+ "filter": {
611
+ "offset": offset * i,
612
+ "limit": pageSize
613
+ },
614
+ }
615
+
616
+ let data = await openapi.doRequest(null, urlPath, options);
617
+ for (let config of data.configs) {
618
+ if (config.key === key) {
619
+ return config.value;
620
+ }
621
+ }
622
+
623
+ if (data.configs.length < pageSize) {
624
+ break;
625
+ }
626
+ }
627
+
628
+ throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
629
+ }
630
+
631
+
632
+ async function oql(oql: string, args: any[], namedArgs: Record<string, any>) {
633
+ // 1.获取 options
634
+ let options = commonHttp.getOptions(null, coreOapiHttpPath.oql);
635
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
636
+
637
+ // 2.请求
638
+ options.json = {
639
+ "query": oql,
640
+ "args": args,
641
+ "namedArgs": namedArgs,
642
+ "compat": true,
643
+ }
644
+
645
+ let result = await openapi.doRequest(null, urlPath, options);
646
+ if (result && result.rows) {
647
+ return result.rows;
648
+ }
649
+
650
+ return [];
651
+ }
652
+
653
+ async function openSDKCreateRecordBySync(objectApiName: string, record: object): Promise<any> {
654
+ // 1.获取 options
655
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKCreateRecord);
656
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
657
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
658
+
659
+ // 2.请求
660
+ options.json = record;
661
+
662
+ return await openapi.doRequest(null, urlPath, options);
663
+ };
664
+
665
+ async function openSDKUpdateRecordBySync(objectApiName: string, recordID: number, record: object): Promise<any> {
666
+ // 1.获取 options
667
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUpdateRecord);
668
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
669
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
670
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID.toString());
671
+
672
+ // 2.请求
673
+ options.json = record;
674
+
675
+ return await openapi.doRequest(null, urlPath, options);
676
+ };
677
+
678
+ async function openSDKDeleteRecordBySync(objectApiName: string, recordID: number): Promise<any> {
679
+ // 1.获取 options
680
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDeleteRecord);
681
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
682
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
683
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID.toString());
684
+
685
+ // 2.请求
686
+ return await openapi.doRequest(null, urlPath, options);
687
+ };
688
+
689
+ async function openSDKCreateRecordsBySync(objectApiName: string, records: object[]): Promise<any> {
690
+ // 1.获取 options
691
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchCreateRecord);
692
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
693
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
694
+
695
+ // 2.请求
696
+ options.json = records;
697
+
698
+ return await openapi.doRequest(null, urlPath, options);
699
+ };
700
+
701
+ async function openSDKUpdateRecordsBySync(objectApiName: string, records: object[]): Promise<any> {
702
+ // 1.获取 options
703
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchUpdateRecord);
704
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
705
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
706
+
707
+ // 2.请求
708
+ options.json = records;
709
+
710
+ return await openapi.doRequest(null, urlPath, options);
711
+ };
712
+
713
+ async function openSDKDeleteRecordsBySync(objectApiName: string, recordIDs: number[]): Promise<any> {
714
+ // 1.获取 options
715
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchDeleteRecord);
716
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
717
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
718
+
719
+ // 2.请求
720
+ options.json = recordIDs;
721
+
722
+ return await openapi.doRequest(null, urlPath, options);
723
+ };
724
+
725
+ async function openSDKGetRecords(objectApiName: string, param: OpenSDKGetRecordsReq): Promise<any | number> {
726
+ // 1.获取 options
727
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKGetRecords);
728
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
729
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
730
+
731
+ if (param.limit <= 0 || param.limit > 200) {
732
+ param.limit = 200;
733
+ }
734
+
735
+ // 2.请求
736
+ options.json = param;
737
+
738
+ const data = await openapi.doRequest(null, urlPath, options);
739
+ if (param.count) {
740
+ return JSON.parse(data.records);
741
+ } else {
742
+ return data.total;
743
+ }
744
+ }
745
+
746
+ async function openSDKUploadFile(fileName: string, data: Buffer): Promise<any> {
747
+ // 1.获取 options
748
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUploadFile);
749
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
750
+
751
+ let formData = new FormData();
752
+ formData.append('file', data);
753
+ formData.append('ignoreUserId', 'true');
754
+ let formHeaders = formData.getHeaders();
755
+
756
+ options.responseType = 'buffer';
757
+ for (let key of Object.keys(formHeaders)) {
758
+ options.headers[key] = formHeaders[key];
759
+ }
760
+ options.body = formData;
761
+
762
+ // 2.请求
763
+ return await openapi.doRequest(null, urlPath, options);
764
+ }
765
+
766
+ async function openSDKUploadAvatar(fileName: string, data: Buffer): Promise<any> {
767
+ // 1.获取 options
768
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUploadAvatar);
769
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
770
+
771
+ let formData = new FormData();
772
+ formData.append('file', data);
773
+ formData.append('ignoreUserId', 'true');
774
+ let formHeaders = formData.getHeaders();
775
+
776
+ options.responseType = 'buffer';
777
+ for (let key of Object.keys(formHeaders)) {
778
+ options.headers[key] = formHeaders[key];
779
+ }
780
+ options.body = formData;
781
+
782
+ // 2.请求
783
+ return await openapi.doRequest(null, urlPath, options);
784
+
785
+ }
786
+
787
+ async function openSDKDownloadAvatar(imageID: string): Promise<Buffer> {
788
+ // 1.获取 options
789
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDownloadAvatar);
790
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
791
+ urlPath = urlPath.replace(replaceKeys.fileID, imageID);
792
+
793
+ // 2.请求
794
+ let data = await openapi.doRequest(null, urlPath, options);
795
+
796
+ // 3.写入文件
797
+ data = Buffer.from(data, 'binary');
798
+
799
+ return data;
800
+ }
801
+
802
+ export class RequestHttp implements IInnerAPIRequest {
803
+
804
+ constructor() {
805
+ this.updateWorkflowVariables = updateWorkflowVariables;
806
+ this.createRecordBySync = createRecordBySync;
807
+ this.updateRecordBySync = updateRecordBySync;
808
+ this.deleteRecordBySync = deleteRecordBySync;
809
+ this.createRecordsByAsync = createRecordsByAsync;
810
+ this.updateRecordsByAsync = updateRecordsByAsync;
811
+ this.deleteRecordsByAsync = deleteRecordsByAsync;
812
+ this.createRecordsBySync = createRecordsBySync;
813
+ this.updateRecordsBySync = updateRecordsBySync;
814
+ this.deleteRecordsBySync = deleteRecordsBySync;
815
+ this.getRecordsOrCountByCriterion = getRecordsOrCountByCriterion;
816
+ this.uploadFile = uploadFile;
817
+ this.downloadFileByID = downloadFileByID;
818
+ this.downloadFileByToken = downloadFileByToken;
819
+ this.createMessage = createMessage;
820
+ this.updateMessage = updateMessage;
821
+ this.getFields = getFields;
822
+ this.getField = getField;
823
+ this.terminateWorkflowInstance = terminateWorkflowInstance;
824
+ this.modifyRecordsWithTransaction = modifyRecordsWithTransaction;
825
+ this.getGlobalConfigByKey = getGlobalConfigByKey;
826
+ this.oql = oql;
827
+ // TODO: open sdk api test
828
+ this.openSDKCreateRecordBySync = openSDKCreateRecordBySync;
829
+ this.openSDKUpdateRecordBySync = openSDKUpdateRecordBySync;
830
+ this.openSDKDeleteRecordBySync = openSDKDeleteRecordBySync;
831
+ this.openSDKCreateRecordsBySync = openSDKCreateRecordsBySync;
832
+ this.openSDKUpdateRecordsBySync = openSDKUpdateRecordsBySync;
833
+ this.openSDKDeleteRecordsBySync = openSDKDeleteRecordsBySync;
834
+ this.openSDKGetRecords = openSDKGetRecords;
835
+ this.openSDKUploadFile = openSDKUploadFile;
836
+ this.openSDKUploadAvatar = openSDKUploadAvatar;
837
+ this.openSDKDownloadAvatar = openSDKDownloadAvatar;
838
+ }
839
+
840
+ updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): any {
841
+ }
842
+
843
+ createRecordBySync(objectApiName: string, record: object): any {
844
+ }
845
+
846
+ updateRecordBySync(objectApiName: string, recordID: number, record: object): any {
847
+ }
848
+
849
+ deleteRecordBySync(objectApiName: string, recordID: number): any {
850
+ }
851
+
852
+ createRecordsByAsync(objectApiName: string, records: object[]): any {
853
+ }
854
+
855
+ updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>): any {
856
+ }
857
+
858
+ deleteRecordsByAsync(objectApiName: string, recordIDs: number[]): any {
859
+ }
860
+
861
+ createRecordsBySync(objectApiName: string, records: object[]): any {
862
+ }
863
+
864
+ updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any {
865
+ }
866
+
867
+ deleteRecordsBySync(objectApiName: string, recordIDs: number[]): any {
868
+ }
869
+
870
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean): any {
871
+ }
872
+
873
+ uploadFile(data: Stream, expire: number): Promise<UploadFileResp> {
874
+ return null;
875
+ }
876
+
877
+ downloadFileByID(fileID: string, filePath?: string): Promise<void | Buffer> {
878
+ return null;
879
+ }
880
+
881
+ downloadFileByToken(fileToken: string, filePath?: string): Promise<Buffer | void> {
882
+ return null;
883
+ }
884
+
885
+ createMessage(msg: any): Promise<number> {
886
+ return null;
887
+ }
888
+
889
+ updateMessage(msgId: number, msg: any): Promise<void> {
890
+ return null;
891
+ }
892
+
893
+ getFields(objectApiName: string): any {
894
+ }
895
+
896
+ getField(objectApiName: string, fieldApiName: string): any {
897
+ }
898
+
899
+ terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string): any {
900
+ }
901
+
902
+ modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[]): Promise<Map<string, number>> {
903
+ return null;
904
+ }
905
+
906
+ getGlobalConfigByKey<valueT>(key: string): Promise<valueT> {
907
+ return null;
908
+ }
909
+
910
+ oql(oql: string, args: any[], namedArgs: Record<string, any>): any {
911
+ }
912
+
913
+ async invokeFuncSync(idOrName: { APIId?: string; APIName?: string; isInvokeByAPIName: boolean }, params: any): Promise<any> {
914
+ return await invokeFuncSync(idOrName, params);
915
+ }
916
+
917
+ async invokeFuncWithAuth(idOrName: { APIId?: string; APIName?: string; isInvokeByAPIName: boolean }, params: any): Promise<any> {
918
+ return await invokeFuncWithAuth(idOrName, params);
919
+ }
920
+
921
+ async createAsyncTaskV1(idOrName: { APIId?: string; APIName?: string; isInvokeByAPIName: boolean }, params: any): Promise<any> {
922
+ return await createAsyncTaskV1(idOrName, params);
923
+ }
924
+
925
+ async createAsyncTaskV2(name: string, params: any): Promise<any> {
926
+ return await createAsyncTaskV2(name, params);
927
+ }
928
+
929
+ async getExecutionUserTaskInfo(executionId: bigint): Promise<any> {
930
+ return await getExecutionUserTaskInfo(executionId);
931
+ }
932
+
933
+ async executeFlow(APIName: string, options: any): Promise<ExecutionResult> {
934
+ return await executeFlow(APIName, options);
935
+ }
936
+
937
+ async revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void> {
938
+ return await revokeExecution(executionId, revokeOptions);
939
+ }
940
+
941
+ async getExecutionInfo(executionId: number): Promise<ExecutionInfo> {
942
+ return await getExecutionInfo(executionId);
943
+ }
944
+
945
+ async getTenantInfo(appCtx: AppCtx): Promise<any> {
946
+ return await appCtx.credential.getTenantInfo();
947
+ }
948
+
949
+ // open sdk empty implement
950
+ openSDKCreateRecordBySync(objectApiName: string, record: object): any {
951
+ };
952
+
953
+ openSDKUpdateRecordBySync(objectApiName: string, recordID: number, record: object): any {
954
+ };
955
+
956
+ openSDKDeleteRecordBySync(objectApiName: string, recordID: number): any {
957
+ };
958
+
959
+ openSDKCreateRecordsBySync(objectApiName: string, records: object[]): any {
960
+ };
961
+
962
+ openSDKUpdateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any {
963
+ };
964
+
965
+ openSDKDeleteRecordsBySync(objectApiName: string, recordIDs: number[]): any {
966
+ };
967
+
968
+ openSDKGetRecords(objectApiName: string, param: OpenSDKGetRecordsReq): Promise<any | number> {
969
+ return null;
970
+ };
971
+
972
+ openSDKUploadFile(fileName: string, data: Buffer): any {
973
+ };
974
+
975
+ openSDKUploadAvatar(fileName: string, data: Buffer): any {
976
+ };
977
+
978
+ openSDKDownloadAvatar(imageID: string): Promise<Buffer> {
979
+ return null
980
+ };
981
+ }
982
+
983
+ async function invokeFuncWithAuth(idOrName: { APIId?: string; APIName?: string; isInvokeByAPIName: boolean }, params: any): Promise<any> {
984
+ let options = commonHttp.getOptions(null, openapiHttpPath.invokeFuncWithAuthInnerAPI);
985
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
986
+ urlPath = urlPath.replace(replaceKeys.apiName, idOrName.APIName);
987
+
988
+ options.headers["User"] = utils.getUserIDFromCtx();
989
+
990
+ options.json = {
991
+ "params": params,
992
+ "context": getTriggerCtx(),
993
+ }
994
+
995
+ if (!idOrName.isInvokeByAPIName) {
996
+ options.json.apiID = idOrName.APIId;
997
+ }
998
+
999
+ let res = await openapi.doRequest(null, urlPath, options);
1000
+
1001
+ if (!res || !res.result) {
1002
+ throw new exceptions.InternalError(`result is empty`)
1003
+ }
1004
+
1005
+ let result: { code: string, msg: string, data: any; };
1006
+ try {
1007
+ result = JSON.parse(res.result);
1008
+ } catch (e) {
1009
+ throw new exceptions.InternalError(`JSON parse failed for ${res.result}`);
1010
+ }
1011
+ if (!result || result.code !== "0") {
1012
+ throw new exceptions.InvalidParamError(`result is invalid for code: ${result ? result.code : ""} msg: ${result ? result.msg : ""}`)
1013
+ }
1014
+ return result.data;
1015
+ }
1016
+
1017
+ async function invokeFuncSync(idOrName: { APIId?: string; APIName?: string; isInvokeByAPIName: boolean }, params: any): Promise<any> {
1018
+
1019
+ let options = commonHttp.getOptions(null, openapiHttpPath.invokeFuncSyncInnerAPI);
1020
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
1021
+
1022
+ options.headers["User"] = utils.getUserIDFromCtx();
1023
+
1024
+ options.json = {
1025
+ "params": JSON.stringify(params),
1026
+ "context": JSON.stringify(getTriggerCtx()),
1027
+ "triggerType": utils.getTriggerType(),
1028
+ }
1029
+
1030
+ // 相等时,表示是新版本函数的场景
1031
+ if (idOrName.isInvokeByAPIName) {
1032
+ options.json.apiAlias = idOrName.APIName;
1033
+ options.json.function_name = "";
1034
+ } else {
1035
+ options.json.function_name = idOrName.APIId;
1036
+ options.json.apiAlias = "";
1037
+ }
1038
+
1039
+ let res = await openapi.doRequest(null, urlPath, options);
1040
+ if (res && res.code === "0") {
1041
+ return res.data;
1042
+ }
1043
+ throw new exceptions.InternalError(`invokeFuncSync result.code(${res.code}) is invalid`)
1044
+ }
1045
+
1046
+ async function createAsyncTaskV1(idOrName: { APIId?: string; APIName?: string; isInvokeByAPIName: boolean }, params: any): Promise<any> {
1047
+
1048
+ let options = commonHttp.getOptions(null, openapiHttpPath.createAsyncTaskInnerAPIV1);
1049
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
1050
+
1051
+ options.headers["User"] = utils.getUserIDFromCtx();
1052
+
1053
+ options.json = {
1054
+ "params": JSON.stringify(params),
1055
+ "context": JSON.stringify(getTriggerCtx()),
1056
+ "triggerType": utils.getTriggerType(),
1057
+ }
1058
+
1059
+ // 相等时,表示是新版本函数的场景
1060
+ if (idOrName.isInvokeByAPIName) {
1061
+ options.json.apiAlias = idOrName.APIName;
1062
+ options.json.function_name = ""; // required
1063
+ } else {
1064
+ options.json.function_name = idOrName.APIId;
1065
+ }
1066
+
1067
+ let res = await openapi.doRequest(null, urlPath, options);
1068
+ if (res && res.task_id) {
1069
+ return res.task_id;
1070
+ }
1071
+ throw new exceptions.InternalError(`createAsyncTaskV1 result is empty`)
1072
+ }
1073
+
1074
+ async function createAsyncTaskV2(APIName: string, params: any): Promise<any> {
1075
+
1076
+ let options = commonHttp.getOptions(null, openapiHttpPath.createAsyncTaskInnerAPIV2);
1077
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK());
1078
+
1079
+ let triggerCtx: Record<string, any> = {}, taskID = utils.getTriggerTaskID();
1080
+ if (taskID) {
1081
+ triggerCtx[headers.triggerTaskId] = taskID;
1082
+ }
1083
+
1084
+ let temp = utils.getDistributedHandleMask();
1085
+ if (temp) {
1086
+ triggerCtx[headers.distributedHandleMask] = temp;
1087
+ }
1088
+
1089
+ let reqCtx = nodeCls.get(headers.loopCtxKey);
1090
+ if (checkLoopCtx(reqCtx)) {
1091
+ triggerCtx[headers.loopMasks] = reqCtx.loopMasks
1092
+ }
1093
+
1094
+ options.headers["User"] = utils.getUserIDFromCtx();
1095
+
1096
+ options.json = {
1097
+ "apiAlias": APIName,
1098
+ "params": JSON.stringify(params),
1099
+ "context": JSON.stringify(getTriggerCtx()),
1100
+ "triggerType": utils.getTriggerType(),
1101
+ "extra": getDebugExtraInfo()
1102
+ }
1103
+
1104
+ let res = await openapi.doRequest(null, urlPath, options);
1105
+ if (res && res.task_id) {
1106
+ return res.task_id;
1107
+ }
1108
+ throw new exceptions.InternalError(`createAsyncTaskV2 result is empty`)
1109
+ }
1110
+
1111
+ function checkLoopCtx(reqCtx: any): any {
1112
+ return reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)
1113
+ }
1114
+
1115
+
1116
+ function getTriggerCtx(): any {
1117
+ let triggerCtx: Record<string, any> = {}, taskID = utils.getTriggerTaskID();
1118
+ if (taskID) {
1119
+ triggerCtx[headers.triggerTaskId] = taskID;
1120
+ }
1121
+
1122
+ let temp = utils.getDistributedHandleMask();
1123
+ if (temp) {
1124
+ triggerCtx[headers.distributedHandleMask] = temp;
1125
+ }
1126
+
1127
+ let reqCtx = nodeCls.get(headers.loopCtxKey);
1128
+ if (checkLoopCtx(reqCtx)) {
1129
+ triggerCtx[headers.loopMasks] = reqCtx.loopMasks
1130
+ }
1131
+ return triggerCtx;
1132
+ }
1133
+
1134
+ export async function getExecutionUserTaskInfo(executionId: bigint): Promise<any> {
1135
+ if (!executionId) {
1136
+ throw new exceptions.InvalidParamError(`executionId is empty`);
1137
+ }
1138
+
1139
+ let options = commonHttp.getOptions(null, coreOapiHttpPath.getExecutionUserTaskInfo);
1140
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK()).replace(replaceKeys.id, `${executionId}`);
1141
+ urlPath += `?operator=${utils.getUserIDFromCtx()}`
1142
+
1143
+ let res = await openapi.doRequest(null, urlPath, options);
1144
+
1145
+ if (!res) {
1146
+ throw new exceptions.InternalError(`getExecutionUserTaskInfo result is empty`);
1147
+ }
1148
+
1149
+ return res.taskList;
1150
+ }
1151
+
1152
+ export async function executeFlow(APIName: string, option: any): Promise<ExecutionResult> {
1153
+ if (!APIName) {
1154
+ throw new exceptions.InvalidParamError(`flow apiName is empty`);
1155
+ }
1156
+
1157
+ let options = commonHttp.getOptions(null, coreOapiHttpPath.executeFlow);
1158
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK()).replace(replaceKeys.apiName, APIName);
1159
+
1160
+ options.json = {
1161
+ "operator": utils.getUserIDFromCtx(),
1162
+ "variables": transMapToFlowVariable(option.params),
1163
+ "loopMasks": utils.getLoopMasks(),
1164
+ }
1165
+ let res = await openapi.doRequest(null, urlPath, options);
1166
+ return {
1167
+ executionId: res.executionId,
1168
+ status: res.status,
1169
+ data: transFlowVariableToMap(res.outParams),
1170
+ errCode: res.errCode ? res.errCode : undefined,
1171
+ errMsg: res.errMsg ? res.errMsg : undefined,
1172
+ };
1173
+ }
1174
+
1175
+ export async function revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void> {
1176
+ if (!executionId) {
1177
+ throw new exceptions.InvalidParamError(`executionId is empty`);
1178
+ }
1179
+ let options = commonHttp.getOptions(null, coreOapiHttpPath.revokeExecution);
1180
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK()).replace(replaceKeys.id, `${executionId}`);
1181
+
1182
+ let reason: { en_US?: string, zh_CN?: string } = undefined;
1183
+
1184
+ if (revokeOptions && revokeOptions.reason) {
1185
+ reason = {
1186
+ en_US: revokeOptions.reason.en_US,
1187
+ zh_CN: revokeOptions.reason.zh_CN
1188
+ }
1189
+ }
1190
+
1191
+ options.json = {
1192
+ "operator": utils.getUserIDFromCtx(),
1193
+ "reason": reason,
1194
+ };
1195
+
1196
+ return await openapi.doRequest(null, urlPath, options);
1197
+ }
1198
+
1199
+ export async function getExecutionInfo(executionId: number): Promise<ExecutionInfo> {
1200
+ if (!executionId) {
1201
+ throw new exceptions.InvalidParamError(`executionId is empty`);
1202
+ }
1203
+
1204
+ let options = commonHttp.getOptions(null, coreOapiHttpPath.getExecutionInfo);
1205
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await getNamespaceForOpenAndFaaSSDK()).replace(replaceKeys.id, `${executionId}`);
1206
+ urlPath += `?operator=${utils.getUserIDFromCtx()}`
1207
+
1208
+ let res = await openapi.doRequest(null, urlPath, options);
1209
+
1210
+ if (!res || !res.executionInfo) {
1211
+ throw new exceptions.InternalError(`getExecutionInfo result is empty`);
1212
+ }
1213
+
1214
+ return {
1215
+ status: res.executionInfo.status,
1216
+ data: transFlowVariableToMap(res.executionInfo.outParams),
1217
+ errCode: res.executionInfo.errCode ? res.executionInfo.errCode : undefined,
1218
+ errMsg: res.executionInfo.errMsg ? res.executionInfo.errMsg : undefined,
1219
+ };
1220
+ }