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