@byted-apaas/server-sdk-node 0.0.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +0 -0
- package/README.md +1 -0
- package/application/application.d.ts +27 -0
- package/application/application.js +3 -0
- package/application/application.js.map +1 -0
- package/application/application.ts +40 -0
- package/application/function/function.d.ts +14 -0
- package/application/function/function.js +22 -0
- package/application/function/function.js.map +1 -0
- package/application/function/function.ts +37 -0
- package/application/impl/common.d.ts +2 -0
- package/application/impl/common.js +51 -0
- package/application/impl/common.js.map +1 -0
- package/application/impl/common.ts +50 -0
- package/application/impl/impl.d.ts +16 -0
- package/application/impl/impl.js +39 -0
- package/application/impl/impl.js.map +1 -0
- package/application/impl/impl.ts +48 -0
- package/constants/constants.d.ts +10 -0
- package/constants/constants.js +14 -0
- package/constants/constants.js.map +1 -0
- package/constants/constants.ts +12 -0
- package/context/context.d.ts +74 -0
- package/context/context.js +24 -0
- package/context/context.js.map +1 -0
- package/context/context.ts +127 -0
- package/context/db/db.d.ts +73 -0
- package/context/db/db.js +3 -0
- package/context/db/db.js.map +1 -0
- package/context/db/db.ts +77 -0
- package/context/db/impl/IObject.d.ts +251 -0
- package/context/db/impl/IObject.js +4 -0
- package/context/db/impl/IObject.js.map +1 -0
- package/context/db/impl/IObject.ts +244 -0
- package/context/db/impl/db.d.ts +61 -0
- package/context/db/impl/db.js +87 -0
- package/context/db/impl/db.js.map +1 -0
- package/context/db/impl/db.ts +95 -0
- package/context/db/impl/object.d.ts +92 -0
- package/context/db/impl/object.js +523 -0
- package/context/db/impl/object.js.map +1 -0
- package/context/db/impl/object.ts +628 -0
- package/context/db/impl/oql/ioql.d.ts +6 -0
- package/context/db/impl/oql/ioql.js +3 -0
- package/context/db/impl/oql/ioql.js.map +1 -0
- package/context/db/impl/oql/ioql.ts +6 -0
- package/context/db/impl/oql/oql.d.ts +8 -0
- package/context/db/impl/oql/oql.js +20 -0
- package/context/db/impl/oql/oql.js.map +1 -0
- package/context/db/impl/oql/oql.ts +22 -0
- package/context/db/impl/order.d.ts +9 -0
- package/context/db/impl/order.js +14 -0
- package/context/db/impl/order.js.map +1 -0
- package/context/db/impl/order.ts +16 -0
- package/context/db/impl/propertiesStore.d.ts +8 -0
- package/context/db/impl/propertiesStore.js +28 -0
- package/context/db/impl/propertiesStore.js.map +1 -0
- package/context/db/impl/propertiesStore.ts +28 -0
- package/context/db/impl/queryBuilder.d.ts +29 -0
- package/context/db/impl/queryBuilder.js +77 -0
- package/context/db/impl/queryBuilder.js.map +1 -0
- package/context/db/impl/queryBuilder.ts +103 -0
- package/context/db/impl/transaction/index.d.ts +20 -0
- package/context/db/impl/transaction/index.js +276 -0
- package/context/db/impl/transaction/index.js.map +1 -0
- package/context/db/impl/transaction/index.ts +337 -0
- package/context/db/impl/transaction/operation.d.ts +27 -0
- package/context/db/impl/transaction/operation.js +70 -0
- package/context/db/impl/transaction/operation.js.map +1 -0
- package/context/db/impl/transaction/operation.ts +72 -0
- package/context/db/impl/transaction.d.ts +67 -0
- package/context/db/impl/transaction.js +3 -0
- package/context/db/impl/transaction.js.map +1 -0
- package/context/db/impl/transaction.ts +76 -0
- package/context/globalConfig/globalConfig.d.ts +7 -0
- package/context/globalConfig/globalConfig.js +15 -0
- package/context/globalConfig/globalConfig.js.map +1 -0
- package/context/globalConfig/globalConfig.ts +11 -0
- package/context/metadata/components/common.d.ts +6 -0
- package/context/metadata/components/common.js +16 -0
- package/context/metadata/components/common.js.map +1 -0
- package/context/metadata/components/common.ts +19 -0
- package/context/metadata/components/components.d.ts +12 -0
- package/context/metadata/components/components.js +18 -0
- package/context/metadata/components/components.js.map +1 -0
- package/context/metadata/components/components.ts +19 -0
- package/context/metadata/components/desktop/list.d.ts +16 -0
- package/context/metadata/components/desktop/list.js +403 -0
- package/context/metadata/components/desktop/list.js.map +1 -0
- package/context/metadata/components/desktop/list.ts +457 -0
- package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
- package/context/metadata/components/desktop/recordDetail.js +52 -0
- package/context/metadata/components/desktop/recordDetail.js.map +1 -0
- package/context/metadata/components/desktop/recordDetail.ts +64 -0
- package/context/metadata/components/mobile/list.d.ts +24 -0
- package/context/metadata/components/mobile/list.js +144 -0
- package/context/metadata/components/mobile/list.js.map +1 -0
- package/context/metadata/components/mobile/list.ts +176 -0
- package/context/metadata/metadata.d.ts +61 -0
- package/context/metadata/metadata.js +102 -0
- package/context/metadata/metadata.js.map +1 -0
- package/context/metadata/metadata.ts +175 -0
- package/context/metadata/objects/fields.d.ts +130 -0
- package/context/metadata/objects/fields.js +333 -0
- package/context/metadata/objects/fields.js.map +1 -0
- package/context/metadata/objects/fields.ts +454 -0
- package/context/metadata/objects/fields.util.d.ts +40 -0
- package/context/metadata/objects/fields.util.js +320 -0
- package/context/metadata/objects/fields.util.js.map +1 -0
- package/context/metadata/objects/fields.util.ts +360 -0
- package/context/metadata/objects/objects.d.ts +11 -0
- package/context/metadata/objects/objects.js +19 -0
- package/context/metadata/objects/objects.js.map +1 -0
- package/context/metadata/objects/objects.ts +27 -0
- package/context/metadata/types/common.d.ts +6 -0
- package/context/metadata/types/common.js +8 -0
- package/context/metadata/types/common.js.map +1 -0
- package/context/metadata/types/common.ts +10 -0
- package/context/metadata/types/components.d.ts +90 -0
- package/context/metadata/types/components.js +3 -0
- package/context/metadata/types/components.js.map +1 -0
- package/context/metadata/types/components.ts +105 -0
- package/context/metadata/types/objects.d.ts +226 -0
- package/context/metadata/types/objects.js +3 -0
- package/context/metadata/types/objects.js.map +1 -0
- package/context/metadata/types/objects.ts +251 -0
- package/context/msg/msg.d.ts +38 -0
- package/context/msg/msg.js +34 -0
- package/context/msg/msg.js.map +1 -0
- package/context/msg/msg.ts +49 -0
- package/context/resources/IResources.d.ts +66 -0
- package/context/resources/IResources.js +3 -0
- package/context/resources/IResources.js.map +1 -0
- package/context/resources/IResources.ts +73 -0
- package/context/resources/impl/resources.d.ts +42 -0
- package/context/resources/impl/resources.js +149 -0
- package/context/resources/impl/resources.js.map +1 -0
- package/context/resources/impl/resources.ts +170 -0
- package/context/tasks/tasks.d.ts +33 -0
- package/context/tasks/tasks.js +140 -0
- package/context/tasks/tasks.js.map +1 -0
- package/context/tasks/tasks.ts +159 -0
- package/data/index.d.ts +27 -0
- package/data/index.js +5 -0
- package/data/index.js.map +1 -0
- package/data/index.ts +30 -0
- package/hooks/api.d.ts +61 -0
- package/hooks/api.js +328 -0
- package/hooks/api.js.map +1 -0
- package/hooks/api.ts +341 -0
- package/hooks/hooks.d.ts +1 -0
- package/hooks/hooks.js +89 -0
- package/hooks/hooks.js.map +1 -0
- package/hooks/hooks.ts +100 -0
- package/kunlun/kunlun.d.ts +55 -0
- package/kunlun/kunlun.js +57 -0
- package/kunlun/kunlun.js.map +1 -0
- package/kunlun/kunlun.ts +69 -0
- package/kunlun/operator/IOperator.d.ts +158 -0
- package/kunlun/operator/IOperator.js +3 -0
- package/kunlun/operator/IOperator.js.map +1 -0
- package/kunlun/operator/IOperator.ts +163 -0
- package/kunlun/operator/impl/expression.d.ts +47 -0
- package/kunlun/operator/impl/expression.js +55 -0
- package/kunlun/operator/impl/expression.js.map +1 -0
- package/kunlun/operator/impl/expression.ts +71 -0
- package/kunlun/operator/impl/logic.d.ts +50 -0
- package/kunlun/operator/impl/logic.js +508 -0
- package/kunlun/operator/impl/logic.js.map +1 -0
- package/kunlun/operator/impl/logic.ts +595 -0
- package/kunlun/operator/impl/logicV2.d.ts +58 -0
- package/kunlun/operator/impl/logicV2.js +201 -0
- package/kunlun/operator/impl/logicV2.js.map +1 -0
- package/kunlun/operator/impl/logicV2.ts +254 -0
- package/kunlun/operator/impl/operator.d.ts +179 -0
- package/kunlun/operator/impl/operator.js +221 -0
- package/kunlun/operator/impl/operator.js.map +1 -0
- package/kunlun/operator/impl/operator.ts +255 -0
- package/kunlun/operator/impl/operatorV2.d.ts +180 -0
- package/kunlun/operator/impl/operatorV2.js +217 -0
- package/kunlun/operator/impl/operatorV2.js.map +1 -0
- package/kunlun/operator/impl/operatorV2.ts +249 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js +18 -0
- package/lib/core.js.map +1 -0
- package/lib/core.ts +4 -0
- package/package.json +50 -0
- package/request/common.d.ts +13 -0
- package/request/common.js +88 -0
- package/request/common.js.map +1 -0
- package/request/common.ts +91 -0
- package/request/constants.d.ts +10 -0
- package/request/constants.js +26 -0
- package/request/constants.js.map +1 -0
- package/request/constants.ts +25 -0
- package/request/faasinfra.d.ts +8 -0
- package/request/faasinfra.js +359 -0
- package/request/faasinfra.js.map +1 -0
- package/request/faasinfra.ts +393 -0
- package/request/innerapi.d.ts +67 -0
- package/request/innerapi.js +1411 -0
- package/request/innerapi.js.map +1 -0
- package/request/innerapi.ts +1645 -0
- package/request/interface.d.ts +95 -0
- package/request/interface.js +40 -0
- package/request/interface.js.map +1 -0
- package/request/interface.ts +166 -0
- package/request/openapi.d.ts +69 -0
- package/request/openapi.js +1013 -0
- package/request/openapi.js.map +1 -0
- package/request/openapi.ts +1220 -0
- package/types/types.d.ts +79 -0
- package/types/types.js +3 -0
- package/types/types.js.map +1 -0
- package/types/types.ts +105 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import * as common from "@byted-apaas/server-common-node"
|
|
2
|
+
|
|
3
|
+
const headers = common.constants.headers;
|
|
4
|
+
const commonHttp = common.http;
|
|
5
|
+
const faasinfra = common.http.faasinfra;
|
|
6
|
+
const faasinfraHttpPath = common.http.faasinfraHttpPath;
|
|
7
|
+
const replaceKeys = common.http.replaceKeys;
|
|
8
|
+
const exceptions = common.exceptions;
|
|
9
|
+
const utils = common.utils;
|
|
10
|
+
const nodeCls = require("node-cls");
|
|
11
|
+
const distributedHandleMask = headers.distributedHandleMask;
|
|
12
|
+
const loopMasks = headers.loopMasks;
|
|
13
|
+
const loopMasksKey = headers.loopMasksKey;
|
|
14
|
+
const loopCtxKey = headers.loopCtxKey;
|
|
15
|
+
|
|
16
|
+
import {URL} from "url";
|
|
17
|
+
import {InternalError} from "@byted-apaas/server-common-node/utils/exceptions";
|
|
18
|
+
import {IFaaSInfraRequest} from "./interface";
|
|
19
|
+
|
|
20
|
+
export class FaaSInfraRequest implements IFaaSInfraRequest {
|
|
21
|
+
constructor() {
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async createDistributeTaskV1(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: any): Promise<any> {
|
|
25
|
+
// 1.获取 options
|
|
26
|
+
let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTask);
|
|
27
|
+
|
|
28
|
+
// 2.构造url
|
|
29
|
+
let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
30
|
+
|
|
31
|
+
// 3.请求
|
|
32
|
+
config.json = {
|
|
33
|
+
"domainName": utils.getTenantNameFromCtx(),
|
|
34
|
+
"namespace": utils.getNamespaceFromCtx(),
|
|
35
|
+
"userId": utils.getUserIDFromCtx(),
|
|
36
|
+
|
|
37
|
+
"dataset": dataset,
|
|
38
|
+
"handlerFunc": handlerFunc,
|
|
39
|
+
"progressCallbackFunc": progressCallbackFunc,
|
|
40
|
+
"completedCallbackFunc": completedCallbackFunc,
|
|
41
|
+
"options": options
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let task_id = utils.getTriggerTaskID();
|
|
45
|
+
if (task_id) {
|
|
46
|
+
config.json[headers.triggerTaskId] = task_id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let loopCtx = nodeCls.get(loopCtxKey);
|
|
50
|
+
if (checkLoopCtx(loopCtx)) {
|
|
51
|
+
config.json[loopMasksKey] = loopCtx.loopMasks;
|
|
52
|
+
if (!utils.isMicroservice() && (handlerFunc !== "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, handlerFunc))) ||
|
|
53
|
+
(progressCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, progressCallbackFunc))) ||
|
|
54
|
+
(completedCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, completedCallbackFunc)))) {
|
|
55
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return await faasinfra.doRequest(null, urlPath, config);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async createDistributeTaskV2(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: any): Promise<any> {
|
|
63
|
+
// 检查函数是否存在
|
|
64
|
+
utils.requireFunction(handlerFunc);
|
|
65
|
+
|
|
66
|
+
// 1.获取 options
|
|
67
|
+
let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTaskV2);
|
|
68
|
+
|
|
69
|
+
// 2.构造url
|
|
70
|
+
let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
71
|
+
|
|
72
|
+
// 3.请求
|
|
73
|
+
config.json = {
|
|
74
|
+
"domainName": utils.getTenantNameFromCtx(),
|
|
75
|
+
"namespace": utils.getNamespaceFromCtx(),
|
|
76
|
+
"userId": utils.getUserIDFromCtx(),
|
|
77
|
+
|
|
78
|
+
"dataset": dataset,
|
|
79
|
+
"handlerFunc": handlerFunc,
|
|
80
|
+
"progressCallbackFunc": progressCallbackFunc,
|
|
81
|
+
"completedCallbackFunc": completedCallbackFunc,
|
|
82
|
+
"options": options,
|
|
83
|
+
"extra": getDebugExtraInfo()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let task_id = utils.getTriggerTaskID();
|
|
87
|
+
if (task_id) {
|
|
88
|
+
config.json[headers.triggerTaskId] = task_id;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let loopCtx = nodeCls.get(loopCtxKey);
|
|
92
|
+
if (checkLoopCtx(loopCtx)) {
|
|
93
|
+
config.json[loopMasksKey] = loopCtx.loopMasks;
|
|
94
|
+
if ((handlerFunc !== "" && config.json[loopMasksKey].includes(handlerFunc)) ||
|
|
95
|
+
(progressCallbackFunc != "" && config.json[loopMasksKey].includes(progressCallbackFunc)) ||
|
|
96
|
+
(completedCallbackFunc != "" && config.json[loopMasksKey].includes(completedCallbackFunc))) {
|
|
97
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return await faasinfra.doRequest(null, urlPath, config);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async invokeMicroserviceSync(apiName: string, path: string, method: string, body: any): Promise<any> {
|
|
105
|
+
let reqPath = faasinfraHttpPath.invokeMicroserviceSync;
|
|
106
|
+
|
|
107
|
+
let options = commonHttp.getOptions(null, reqPath);
|
|
108
|
+
let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
109
|
+
|
|
110
|
+
options.json = {
|
|
111
|
+
"microserviceId": apiName,
|
|
112
|
+
"path": path,
|
|
113
|
+
"method": method,
|
|
114
|
+
"query": parseQueryParams(path),
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 处理 body 参数
|
|
118
|
+
if (method.toUpperCase() !== "GET") {
|
|
119
|
+
options.json.body = JSON.stringify(body);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return await faasinfra.doRequest(null, urlPath, options);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async invokeMicroserviceAsync(apiName: string, path: string, method: string, body: any): Promise<any> {
|
|
126
|
+
let reqPath = faasinfraHttpPath.invokeMicroserviceAsync;
|
|
127
|
+
|
|
128
|
+
let options = commonHttp.getOptions(null, reqPath);
|
|
129
|
+
let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
130
|
+
|
|
131
|
+
options.json = {
|
|
132
|
+
"microserviceId": apiName,
|
|
133
|
+
"path": path,
|
|
134
|
+
"method": method,
|
|
135
|
+
"query": parseQueryParams(path),
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 处理 body 参数
|
|
139
|
+
if (method.toUpperCase() !== "GET") {
|
|
140
|
+
options.json.body = JSON.stringify(body);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return await faasinfra.doRequest(null, urlPath, options);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
function getDebugExtraInfo() {
|
|
150
|
+
let extra: Record<string, string> = {
|
|
151
|
+
"FunctionFrameVersion": "FunctionFrameV2",
|
|
152
|
+
};
|
|
153
|
+
if (utils.isDebug()) {
|
|
154
|
+
extra.DebugInfo = utils.getDebugCode();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return extra
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function checkLoopCtx(reqCtx: any): any {
|
|
161
|
+
return reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function parseQueryParams(path: string): Record<string, string[]> {
|
|
165
|
+
let params: Record<string, string[]> = {};
|
|
166
|
+
|
|
167
|
+
let url = new URL(path, "https://aa.bb.cc");
|
|
168
|
+
for (let [k, v] of url.searchParams.entries()) {
|
|
169
|
+
if (typeof (k) !== "string") {
|
|
170
|
+
throw new InternalError(`The type of k should be string, but ${typeof (k)}`);
|
|
171
|
+
}
|
|
172
|
+
if (typeof (v) !== "string") {
|
|
173
|
+
throw new InternalError(`The type of v should be string, but ${typeof (v)}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
params[k] = v.split(",");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (Object.keys(params).length === 0) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
return params;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/*
|
|
186
|
+
export async function invokeFuncSync(apiName: string, params: any, oldFuncName: string, isSync: boolean) {
|
|
187
|
+
let result = await invokeFunc(apiName, params, oldFuncName, isSync);
|
|
188
|
+
if (result && result.code === "0") {
|
|
189
|
+
return result.data;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function invokeFunc(apiName: string, params: any, oldFuncName: string, isSync = false) {
|
|
195
|
+
let reqPath = faasinfraHttpPath.createAsyncTask;
|
|
196
|
+
if (isSync) {
|
|
197
|
+
reqPath = faasinfraHttpPath.invokeFuncSync;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
let options = commonHttp.getOptions(null, reqPath);
|
|
201
|
+
let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
202
|
+
|
|
203
|
+
let triggerCtx: Record<string, any> = {};
|
|
204
|
+
let task_id = utils.getTriggerTaskID();
|
|
205
|
+
if (task_id) {
|
|
206
|
+
triggerCtx[headers.triggerTaskId] = task_id;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let temp = utils.getDistributedHandleMask();
|
|
210
|
+
if (temp) {
|
|
211
|
+
triggerCtx[distributedHandleMask] = temp;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let reqCtx = nodeCls.get(loopCtxKey);
|
|
215
|
+
if (checkLoopCtx(reqCtx)) {
|
|
216
|
+
triggerCtx[loopMasks] = reqCtx.loopMasks
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 相等时,表示是新版本函数的场景
|
|
220
|
+
if (apiName === oldFuncName) {
|
|
221
|
+
options.json = {
|
|
222
|
+
"apiAlias": apiName,
|
|
223
|
+
"params": JSON.stringify(params),
|
|
224
|
+
"context": JSON.stringify(triggerCtx),
|
|
225
|
+
"triggerType": utils.getTriggerType(),
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
options.json = {
|
|
229
|
+
"function_name": apiName,
|
|
230
|
+
"params": JSON.stringify(params),
|
|
231
|
+
"context": JSON.stringify(triggerCtx),
|
|
232
|
+
"triggerType": utils.getTriggerType(),
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (utils.isMicroservice()) {
|
|
237
|
+
options.json.apiAlias = oldFuncName;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return await faasinfra.doRequest(null, urlPath, options);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export async function asyncTask(apiName: string, params: any) {
|
|
244
|
+
// 检查函数是否存在
|
|
245
|
+
utils.requireFunction(apiName);
|
|
246
|
+
|
|
247
|
+
let reqPath = faasinfraHttpPath.createAsyncTaskV2;
|
|
248
|
+
let options = commonHttp.getOptions(null, reqPath);
|
|
249
|
+
let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
250
|
+
|
|
251
|
+
let triggerCtx: Record<string, any> = {};
|
|
252
|
+
let task_id = utils.getTriggerTaskID();
|
|
253
|
+
if (task_id) {
|
|
254
|
+
triggerCtx[headers.triggerTaskId] = task_id;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
let temp = utils.getDistributedHandleMask();
|
|
258
|
+
if (temp) {
|
|
259
|
+
triggerCtx[distributedHandleMask] = temp;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let reqCtx = nodeCls.get(loopCtxKey);
|
|
263
|
+
if (checkLoopCtx(reqCtx)) {
|
|
264
|
+
triggerCtx[loopMasks] = reqCtx.loopMasks
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
options.json = {
|
|
268
|
+
"api_name": apiName,
|
|
269
|
+
"params": JSON.stringify(params),
|
|
270
|
+
"context": JSON.stringify(triggerCtx),
|
|
271
|
+
"triggerType": utils.getTriggerType(),
|
|
272
|
+
"extra": getDebugExtraInfo()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return await faasinfra.doRequest(null, urlPath, options);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export async function createDistributedTaskV1(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: _Options):
|
|
279
|
+
Promise<number> {
|
|
280
|
+
// 1.获取 options
|
|
281
|
+
let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTask);
|
|
282
|
+
|
|
283
|
+
// 2.构造url
|
|
284
|
+
let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
285
|
+
|
|
286
|
+
// 3.请求
|
|
287
|
+
config.json = {
|
|
288
|
+
"domainName": utils.getTenantNameFromCtx(),
|
|
289
|
+
"namespace": utils.getNamespaceFromCtx(),
|
|
290
|
+
"userId": utils.getUserIDFromCtx(),
|
|
291
|
+
|
|
292
|
+
"dataset": dataset,
|
|
293
|
+
"handlerFunc": handlerFunc,
|
|
294
|
+
"progressCallbackFunc": progressCallbackFunc,
|
|
295
|
+
"completedCallbackFunc": completedCallbackFunc,
|
|
296
|
+
"options": options
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let task_id = utils.getTriggerTaskID();
|
|
300
|
+
if (task_id) {
|
|
301
|
+
config.json[headers.triggerTaskId] = task_id;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let loopCtx = nodeCls.get(loopCtxKey);
|
|
305
|
+
if (checkLoopCtx(loopCtx)) {
|
|
306
|
+
config.json[loopMasksKey] = loopCtx.loopMasks;
|
|
307
|
+
if (!utils.isMicroservice() && (handlerFunc !== "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, handlerFunc))) ||
|
|
308
|
+
(progressCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, progressCallbackFunc))) ||
|
|
309
|
+
(completedCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, completedCallbackFunc)))) {
|
|
310
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return await faasinfra.doRequest(null, urlPath, config);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export async function createDistributedTask(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: _Options): Promise<number> {
|
|
318
|
+
if (utils.isOnlineDev()) {
|
|
319
|
+
return await createDistributedTaskV1(dataset, handlerFunc, progressCallbackFunc, completedCallbackFunc, options);
|
|
320
|
+
}
|
|
321
|
+
// 检查函数是否存在
|
|
322
|
+
utils.requireFunction(handlerFunc);
|
|
323
|
+
|
|
324
|
+
// 1.获取 options
|
|
325
|
+
let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTaskV2);
|
|
326
|
+
|
|
327
|
+
// 2.构造url
|
|
328
|
+
let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
329
|
+
|
|
330
|
+
// 3.请求
|
|
331
|
+
config.json = {
|
|
332
|
+
"domainName": utils.getTenantNameFromCtx(),
|
|
333
|
+
"namespace": utils.getNamespaceFromCtx(),
|
|
334
|
+
"userId": utils.getUserIDFromCtx(),
|
|
335
|
+
|
|
336
|
+
"dataset": dataset,
|
|
337
|
+
"handlerFunc": handlerFunc,
|
|
338
|
+
"progressCallbackFunc": progressCallbackFunc,
|
|
339
|
+
"completedCallbackFunc": completedCallbackFunc,
|
|
340
|
+
"options": options,
|
|
341
|
+
"extra": getDebugExtraInfo()
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let task_id = utils.getTriggerTaskID();
|
|
345
|
+
if (task_id) {
|
|
346
|
+
config.json[headers.triggerTaskId] = task_id;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let loopCtx = nodeCls.get(loopCtxKey);
|
|
350
|
+
if (checkLoopCtx(loopCtx)) {
|
|
351
|
+
config.json[loopMasksKey] = loopCtx.loopMasks;
|
|
352
|
+
if ((handlerFunc !== "" && config.json[loopMasksKey].includes(handlerFunc)) ||
|
|
353
|
+
(progressCallbackFunc != "" && config.json[loopMasksKey].includes(progressCallbackFunc)) ||
|
|
354
|
+
(completedCallbackFunc != "" && config.json[loopMasksKey].includes(completedCallbackFunc))) {
|
|
355
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return await faasinfra.doRequest(null, urlPath, config);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export async function invokeMicroserviceSync(apiName: string, path: string, method: string, body: any) {
|
|
363
|
+
return await invokeMicroservice(apiName, path, method, body, true);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export async function invokeMicroserviceAsync(apiName: string, path: string, method: string, body: any) {
|
|
367
|
+
return await invokeMicroservice(apiName, path, method, body, false);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async function invokeMicroservice(apiName: string, path: string, method: string, body: any, isSync = false) {
|
|
371
|
+
let reqPath = faasinfraHttpPath.invokeMicroserviceAsync;
|
|
372
|
+
if (isSync) {
|
|
373
|
+
reqPath = faasinfraHttpPath.invokeMicroserviceSync;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let options = commonHttp.getOptions(null, reqPath);
|
|
377
|
+
let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
|
|
378
|
+
|
|
379
|
+
options.json = {
|
|
380
|
+
"microserviceId": apiName,
|
|
381
|
+
"path": path,
|
|
382
|
+
"method": method,
|
|
383
|
+
"query": parseQueryParams(path),
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// 处理 body 参数
|
|
387
|
+
if (method.toUpperCase() !== "GET") {
|
|
388
|
+
options.json.body = JSON.stringify(body);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return await faasinfra.doRequest(null, urlPath, options);
|
|
392
|
+
}
|
|
393
|
+
*/
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Stream } from "stream";
|
|
4
|
+
import { Order } from "../context/db/impl/order";
|
|
5
|
+
import { Criterion } from "../kunlun/operator/impl/logic";
|
|
6
|
+
import { IInnerAPIRequest, OpenSDKGetRecordsReq, UploadFileResp } from "./interface";
|
|
7
|
+
import { ExecutionInfo, ExecutionResult, RevokeExecutionOptions } from "@byted-apaas/server-common-node/context/workflow/workflow";
|
|
8
|
+
import { AppCtx } from "../application/application";
|
|
9
|
+
export declare class RequestRpc implements IInnerAPIRequest {
|
|
10
|
+
constructor();
|
|
11
|
+
createRecordBySync(objectApiName: string, record: object): any;
|
|
12
|
+
updateRecordBySync(objectApiName: string, recordID: number, record: object): any;
|
|
13
|
+
deleteRecordBySync(objectApiName: string, recordID: number): any;
|
|
14
|
+
createRecordsByAsync(objectApiName: string, records: object[]): any;
|
|
15
|
+
updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>): any;
|
|
16
|
+
deleteRecordsByAsync(objectApiName: string, recordIDs: number[]): any;
|
|
17
|
+
createRecordsBySync(objectApiName: string, records: object[]): any;
|
|
18
|
+
updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any;
|
|
19
|
+
deleteRecordsBySync(objectApiName: string, recordIDs: number[]): any;
|
|
20
|
+
getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean): any;
|
|
21
|
+
updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): Promise<void>;
|
|
22
|
+
uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
|
|
23
|
+
downloadFileByID(fileID: string, filePath?: string): Promise<Buffer | void>;
|
|
24
|
+
downloadFileByToken(fileToken: string, filePath?: string): Promise<Buffer | void>;
|
|
25
|
+
createMessage(msg: any): Promise<number>;
|
|
26
|
+
updateMessage(msgId: number, msg: any): Promise<void>;
|
|
27
|
+
getFields(objectApiName: string): Promise<any>;
|
|
28
|
+
getField(objectApiName: string, fieldApiName: string): Promise<any>;
|
|
29
|
+
terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string): Promise<void>;
|
|
30
|
+
modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[]): Promise<Map<string, number>>;
|
|
31
|
+
getGlobalConfigByKey<valueT>(key: string): Promise<valueT>;
|
|
32
|
+
oql(oql: string, args: any[], namedArgs: Record<string, any>): Promise<string | any[]>;
|
|
33
|
+
invokeFuncSync(idOrName: {
|
|
34
|
+
APIId?: string;
|
|
35
|
+
APIName?: string;
|
|
36
|
+
isInvokeByAPIName: boolean;
|
|
37
|
+
}, params: any): Promise<any>;
|
|
38
|
+
invokeFuncWithAuth(idOrName: {
|
|
39
|
+
APIId?: string;
|
|
40
|
+
APIName?: string;
|
|
41
|
+
isInvokeByAPIName: boolean;
|
|
42
|
+
}, params: any): Promise<any>;
|
|
43
|
+
createAsyncTaskV1(idOrName: {
|
|
44
|
+
APIId?: string;
|
|
45
|
+
APIName?: string;
|
|
46
|
+
isInvokeByAPIName: boolean;
|
|
47
|
+
}, params: any): Promise<any>;
|
|
48
|
+
createAsyncTaskV2(name: string, params: any): Promise<any>;
|
|
49
|
+
getExecutionUserTaskInfo(executionId: bigint): Promise<any>;
|
|
50
|
+
executeFlow(APIName: string, options: any): Promise<ExecutionResult>;
|
|
51
|
+
revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void>;
|
|
52
|
+
getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
|
|
53
|
+
getTenantInfo(appCtx: AppCtx): Promise<any>;
|
|
54
|
+
openSDKCreateRecordBySync(objectApiName: string, record: object): any;
|
|
55
|
+
openSDKUpdateRecordBySync(objectApiName: string, recordID: number, record: object): any;
|
|
56
|
+
openSDKDeleteRecordBySync(objectApiName: string, recordID: number): any;
|
|
57
|
+
openSDKCreateRecordsBySync(objectApiName: string, records: object[]): any;
|
|
58
|
+
openSDKUpdateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any;
|
|
59
|
+
openSDKDeleteRecordsBySync(objectApiName: string, recordIDs: number[]): any;
|
|
60
|
+
openSDKGetRecords(objectApiName: string, param: OpenSDKGetRecordsReq): void;
|
|
61
|
+
openSDKUploadFile(fileName: string, data: Buffer): any;
|
|
62
|
+
openSDKUploadAvatar(fileName: string, data: Buffer): any;
|
|
63
|
+
openSDKDownloadAvatar(imageID: string): any;
|
|
64
|
+
}
|
|
65
|
+
export declare function revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void>;
|
|
66
|
+
export declare function getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
|
|
67
|
+
export declare function getExecutionUserTaskInfo(executionId: bigint): Promise<any>;
|