@byted-apaas/server-sdk-node 1.1.23 → 1.1.24-beta.0
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/application/application.d.ts +33 -0
- package/application/application.js +2 -0
- package/application/function/function.d.ts +14 -0
- package/application/function/function.js +20 -0
- package/application/impl/common.d.ts +2 -0
- package/application/impl/common.js +52 -0
- package/application/impl/impl.d.ts +19 -0
- package/application/impl/impl.js +45 -0
- package/common/structs.d.ts +15 -0
- package/common/structs.js +21 -0
- package/constants/constants.d.ts +13 -0
- package/constants/constants.js +18 -0
- package/context/context.d.ts +44 -0
- package/context/context.js +25 -0
- package/context/db/db.d.ts +110 -0
- package/context/db/db.js +2 -0
- package/context/db/impl/IObject.d.ts +303 -0
- package/context/db/impl/IObject.js +5 -0
- package/context/db/impl/IObjectV3.d.ts +239 -0
- package/context/db/impl/IObjectV3.js +5 -0
- package/context/db/impl/db.d.ts +62 -0
- package/context/db/impl/db.js +84 -0
- package/context/db/impl/dbV3.d.ts +35 -0
- package/context/db/impl/dbV3.js +50 -0
- package/context/db/impl/object.d.ts +123 -0
- package/context/db/impl/object.js +1008 -0
- package/context/db/impl/oql/ioql.d.ts +14 -0
- package/context/db/impl/oql/ioql.js +4 -0
- package/context/db/impl/oql/oql.d.ts +14 -0
- package/context/db/impl/oql/oql.js +39 -0
- package/context/db/impl/order.d.ts +9 -0
- package/context/db/impl/order.js +15 -0
- package/context/db/impl/propertiesStore.d.ts +8 -0
- package/context/db/impl/propertiesStore.js +29 -0
- package/context/db/impl/queryBuilder.d.ts +33 -0
- package/context/db/impl/queryBuilder.js +72 -0
- package/context/db/impl/transaction/index.d.ts +25 -0
- package/context/db/impl/transaction/index.js +300 -0
- package/context/db/impl/transaction/operation.d.ts +27 -0
- package/context/db/impl/transaction/operation.js +69 -0
- package/context/db/impl/transaction.d.ts +70 -0
- package/context/db/impl/transaction.js +4 -0
- package/context/globalConfig/globalConfig.d.ts +7 -0
- package/context/globalConfig/globalConfig.js +16 -0
- package/context/integration/IIntegration.d.ts +30 -0
- package/context/integration/IIntegration.js +4 -0
- package/context/integration/impl/integration.d.ts +16 -0
- package/context/integration/impl/integration.js +62 -0
- package/context/metadata/components/common.d.ts +6 -0
- package/context/metadata/components/common.js +17 -0
- package/context/metadata/components/components.d.ts +12 -0
- package/context/metadata/components/components.js +19 -0
- package/context/metadata/components/desktop/list.d.ts +16 -0
- package/context/metadata/components/desktop/list.js +402 -0
- package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
- package/context/metadata/components/desktop/recordDetail.js +53 -0
- package/context/metadata/components/mobile/list.d.ts +24 -0
- package/context/metadata/components/mobile/list.js +145 -0
- package/context/metadata/metadata.d.ts +63 -0
- package/context/metadata/metadata.js +125 -0
- package/context/metadata/objects/fields.d.ts +158 -0
- package/context/metadata/objects/fields.js +369 -0
- package/context/metadata/objects/fields.util.d.ts +52 -0
- package/context/metadata/objects/fields.util.js +420 -0
- package/context/metadata/objects/fieldsV3.d.ts +159 -0
- package/context/metadata/objects/fieldsV3.js +369 -0
- package/context/metadata/objects/objects.d.ts +11 -0
- package/context/metadata/objects/objects.js +20 -0
- package/context/metadata/types/common.d.ts +11 -0
- package/context/metadata/types/common.js +33 -0
- package/context/metadata/types/components.d.ts +90 -0
- package/context/metadata/types/components.js +4 -0
- package/context/metadata/types/objects.d.ts +246 -0
- package/context/metadata/types/objects.js +4 -0
- package/context/metadata/types/objectsV3.d.ts +128 -0
- package/context/metadata/types/objectsV3.js +4 -0
- package/context/msg/msg.d.ts +38 -0
- package/context/msg/msg.js +35 -0
- package/context/resources/IResources.d.ts +68 -0
- package/context/resources/IResources.js +2 -0
- package/context/resources/impl/resources.d.ts +42 -0
- package/context/resources/impl/resources.js +161 -0
- package/context/tasks/tasks.d.ts +33 -0
- package/context/tasks/tasks.js +139 -0
- package/data/index.d.ts +27 -0
- package/data/index.js +4 -0
- package/global/application/flow/flow.d.ts +99 -0
- package/global/application/flow/flow.js +8 -0
- package/global/application/flow/impl/flow.d.ts +20 -0
- package/global/application/flow/impl/flow.js +56 -0
- package/global/application/globalVar/globalVar.d.ts +7 -0
- package/global/application/globalVar/globalVar.js +2 -0
- package/global/global.d.ts +70 -0
- package/global/global.js +3 -0
- package/hooks/api.d.ts +65 -0
- package/hooks/api.js +347 -0
- package/hooks/hooks.d.ts +1 -0
- package/hooks/hooks.js +107 -0
- package/kunlun/kunlun.d.ts +55 -0
- package/kunlun/kunlun.js +58 -0
- package/kunlun/operator/IOperator.d.ts +158 -0
- package/kunlun/operator/IOperator.js +4 -0
- package/kunlun/operator/impl/expression.d.ts +75 -0
- package/kunlun/operator/impl/expression.js +96 -0
- package/kunlun/operator/impl/logic.d.ts +68 -0
- package/kunlun/operator/impl/logic.js +573 -0
- package/kunlun/operator/impl/logicV2.d.ts +59 -0
- package/kunlun/operator/impl/logicV2.js +197 -0
- package/kunlun/operator/impl/operator.d.ts +179 -0
- package/kunlun/operator/impl/operator.js +222 -0
- package/kunlun/operator/impl/operatorV2.d.ts +180 -0
- package/kunlun/operator/impl/operatorV2.js +216 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js +19 -0
- package/package.json +1 -1
- package/request/common.d.ts +13 -0
- package/request/common.js +88 -0
- package/request/constants.d.ts +12 -0
- package/request/constants.js +29 -0
- package/request/faasinfra.d.ts +8 -0
- package/request/faasinfra.js +146 -0
- package/request/interface.d.ts +121 -0
- package/request/interface.js +30 -0
- package/request/openapi.d.ts +84 -0
- package/request/openapi.js +1533 -0
- package/request/structs.d.ts +99 -0
- package/request/structs.js +15 -0
- package/types/types.d.ts +79 -0
- package/types/types.js +4 -0
- package/version/version.d.ts +2 -0
- package/version/version.js +8 -0
package/hooks/api.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as common from '@byted-apaas/server-common-node';
|
|
2
|
+
import { Tasks } from '../context/tasks/tasks';
|
|
3
|
+
import { DB } from '../context/db/impl/db';
|
|
4
|
+
import { _Resources } from '../context/resources/impl/resources';
|
|
5
|
+
import { Message } from '../context/msg/msg';
|
|
6
|
+
import { IMetaData } from '../context/metadata/metadata';
|
|
7
|
+
import { ExecuteOptions, ExecutionInfo, ExecutionResult, FlowTaskInfo, RevokeExecutionOptions } from '@byted-apaas/server-common-node/context/workflow/workflow';
|
|
8
|
+
type invokeGlobalFuncT = (funcNames: string) => {
|
|
9
|
+
invoke: (params?: any) => Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
export declare function getFunctionSync(context?: any, logger?: common.Logger): invokeGlobalFuncT;
|
|
12
|
+
export declare function setRespHeader(): () => void;
|
|
13
|
+
export declare function toString(value: any): string;
|
|
14
|
+
export declare function setRedirectLocation(context: any): (location: string) => void;
|
|
15
|
+
export declare function method(): string;
|
|
16
|
+
export declare function mountMetadata(context: any): void;
|
|
17
|
+
export declare function mountWorkflowFeature(context: any): void;
|
|
18
|
+
export declare function terminateWorkflow(): (workflowInstanceId: number, options: any) => Promise<void>;
|
|
19
|
+
export declare function mockFlowFeature(context: any): any;
|
|
20
|
+
export declare function mockGetExecutionUserTaskInfo(): (executionId: bigint) => Promise<FlowTaskInfo[]>;
|
|
21
|
+
export declare function mockExecuteFlow(): (apiName: string, options?: ExecuteOptions) => Promise<ExecutionResult>;
|
|
22
|
+
export declare function mockRevokeExecution(): (executionId: number, options: RevokeExecutionOptions) => Promise<void>;
|
|
23
|
+
export declare function mockGetExecutionInfo(): (executionId: number) => Promise<ExecutionInfo>;
|
|
24
|
+
export declare function invokeMicroservice(): (apiName: string) => {
|
|
25
|
+
/**
|
|
26
|
+
* 同步调用微服务
|
|
27
|
+
* @param path 请求路径,如:/ping
|
|
28
|
+
* @param method 请求方法,默认为 GET
|
|
29
|
+
* @param params 请求参数,默认为 undefined
|
|
30
|
+
*/
|
|
31
|
+
invoke: (path: string, method?: string, params?: any) => Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* 异步调用微服务
|
|
34
|
+
* @param path 请求路径,如:/ping
|
|
35
|
+
* @param method 请求方法,默认为 GET
|
|
36
|
+
* @param params 请求参数,默认为 undefined
|
|
37
|
+
*/
|
|
38
|
+
invokeAsync: (path: string, method?: string, params?: any) => Promise<any>;
|
|
39
|
+
};
|
|
40
|
+
export declare const db: DB<import("@byted-apaas/server-common-node/context/IContext").IContext, import("../data").metadataMap>;
|
|
41
|
+
export declare const resources: _Resources;
|
|
42
|
+
export declare const msg: Message;
|
|
43
|
+
export declare const tasks: Tasks<unknown>;
|
|
44
|
+
export declare const cloudfunction: invokeGlobalFuncT;
|
|
45
|
+
export declare const microservice: (apiName: string) => {
|
|
46
|
+
/**
|
|
47
|
+
* 同步调用微服务
|
|
48
|
+
* @param path 请求路径,如:/ping
|
|
49
|
+
* @param method 请求方法,默认为 GET
|
|
50
|
+
* @param params 请求参数,默认为 undefined
|
|
51
|
+
*/
|
|
52
|
+
invoke: (path: string, method?: string, params?: any) => Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* 异步调用微服务
|
|
55
|
+
* @param path 请求路径,如:/ping
|
|
56
|
+
* @param method 请求方法,默认为 GET
|
|
57
|
+
* @param params 请求参数,默认为 undefined
|
|
58
|
+
*/
|
|
59
|
+
invokeAsync: (path: string, method?: string, params?: any) => Promise<any>;
|
|
60
|
+
};
|
|
61
|
+
export declare const workflow: {
|
|
62
|
+
terminate: (workflowInstanceId: number, options: any) => Promise<void>;
|
|
63
|
+
};
|
|
64
|
+
export declare const metaData: IMetaData<{}>;
|
|
65
|
+
export { Application } from '../application/impl/impl';
|
package/hooks/api.js
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Application = exports.metaData = exports.workflow = exports.microservice = exports.cloudfunction = exports.tasks = exports.msg = exports.resources = exports.db = exports.invokeMicroservice = exports.mockGetExecutionInfo = exports.mockRevokeExecution = exports.mockExecuteFlow = exports.mockGetExecutionUserTaskInfo = exports.mockFlowFeature = exports.terminateWorkflow = exports.mountWorkflowFeature = exports.mountMetadata = exports.method = exports.setRedirectLocation = exports.toString = exports.setRespHeader = exports.getFunctionSync = void 0;
|
|
4
|
+
const common = require("@byted-apaas/server-common-node");
|
|
5
|
+
const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
|
|
6
|
+
const api = require("../hooks/api");
|
|
7
|
+
const metadataApi = require("../context/metadata/metadata");
|
|
8
|
+
const tasks_1 = require("../context/tasks/tasks");
|
|
9
|
+
const db_1 = require("../context/db/impl/db");
|
|
10
|
+
const resources_1 = require("../context/resources/impl/resources");
|
|
11
|
+
const msg_1 = require("../context/msg/msg");
|
|
12
|
+
const Request = require("../request/interface");
|
|
13
|
+
const constants = require("../constants/constants");
|
|
14
|
+
const metadata_1 = require("../context/metadata/metadata");
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
16
|
+
const nodeCls = require('node-cls'); //nolint:byted_s_ts_no_require_imports
|
|
17
|
+
const nodeClsCtx = common.nodeClsCtx;
|
|
18
|
+
const exceptions = common.exceptions;
|
|
19
|
+
const utils = common.utils;
|
|
20
|
+
const checkUtils = common.checkUtils;
|
|
21
|
+
const functionSources = common.constants.functionSources;
|
|
22
|
+
// 同步调用云函数
|
|
23
|
+
function getFunctionSync(context, logger) {
|
|
24
|
+
return (funcName) => {
|
|
25
|
+
if (utils.isOnlineDev()) {
|
|
26
|
+
let oldFuncName = funcName;
|
|
27
|
+
if (!utils.isMicroservice()) {
|
|
28
|
+
funcName = utils.handleFuncName(null, funcName);
|
|
29
|
+
if (!funcName) {
|
|
30
|
+
throw new exceptions.InvalidParamError(`The function (${oldFuncName}) does not exist, please confirm ${oldFuncName} exists and has been deployed.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
funcName = undefined;
|
|
35
|
+
}
|
|
36
|
+
let idOrName = {};
|
|
37
|
+
// 2.0 通过 apiAlias 触发
|
|
38
|
+
if (funcName === oldFuncName) {
|
|
39
|
+
idOrName = {
|
|
40
|
+
APIName: funcName,
|
|
41
|
+
isInvokeByAPIName: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else if (utils.isMicroservice()) {
|
|
45
|
+
// 微服务
|
|
46
|
+
idOrName = {
|
|
47
|
+
APIName: oldFuncName,
|
|
48
|
+
isInvokeByAPIName: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else { // 1.0 通过 apiID 触发
|
|
52
|
+
idOrName = {
|
|
53
|
+
APIId: funcName,
|
|
54
|
+
isInvokeByAPIName: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
invoke: async (params) => {
|
|
59
|
+
// 微服务的场景
|
|
60
|
+
if (utils.isMicroservice()) {
|
|
61
|
+
return await Request.GetInstance().invokeFuncSync(idOrName, params);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
let func = utils.getGlobalFunc(null, funcName);
|
|
65
|
+
if (!func) {
|
|
66
|
+
// 改为远程调用
|
|
67
|
+
return await Request.GetInstance().invokeFuncSync(idOrName, params);
|
|
68
|
+
}
|
|
69
|
+
let loopMasks = [funcName];
|
|
70
|
+
const reqCtx = nodeCls.get('loopCtx');
|
|
71
|
+
if (reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)) {
|
|
72
|
+
if (reqCtx.loopMasks.includes(funcName)) {
|
|
73
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
74
|
+
}
|
|
75
|
+
loopMasks.push(...reqCtx.loopMasks);
|
|
76
|
+
}
|
|
77
|
+
// 修改 source 全局函数
|
|
78
|
+
const ctx = nodeCls.create('loopCtx');
|
|
79
|
+
ctx.loopMasks = loopMasks;
|
|
80
|
+
return await ctx.run(async () => {
|
|
81
|
+
const dynCtx = nodeClsCtx.getDynCtx();
|
|
82
|
+
dynCtx.source = functionSources.globalFunction;
|
|
83
|
+
return await dynCtx.run(async () => {
|
|
84
|
+
return await common.hooks.invoke(func, params, context, logger);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
invoke: async (params) => {
|
|
93
|
+
// 非微服务场景
|
|
94
|
+
if (!utils.isMicroservice()) {
|
|
95
|
+
let func = undefined;
|
|
96
|
+
let requireFunc = utils.getRequireFunc();
|
|
97
|
+
if (requireFunc) {
|
|
98
|
+
try {
|
|
99
|
+
func = requireFunc(funcName);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (func) {
|
|
105
|
+
// 本地调用
|
|
106
|
+
let loopMasks = [funcName];
|
|
107
|
+
const reqCtx = nodeCls.get('loopCtx');
|
|
108
|
+
if (reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)) {
|
|
109
|
+
if (reqCtx.loopMasks.includes(funcName)) {
|
|
110
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
111
|
+
}
|
|
112
|
+
loopMasks.push(...reqCtx.loopMasks);
|
|
113
|
+
}
|
|
114
|
+
// 修改 source 全局函数
|
|
115
|
+
const ctx = nodeCls.create('loopCtx');
|
|
116
|
+
ctx.loopMasks = loopMasks;
|
|
117
|
+
return await ctx.run(async () => {
|
|
118
|
+
const dynCtx = nodeClsCtx.getDynCtx();
|
|
119
|
+
dynCtx.source = functionSources.globalFunction;
|
|
120
|
+
return await dynCtx.run(async () => {
|
|
121
|
+
return await common.hooks.invoke(func, params, context, logger);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// 远程调用 微服务 | 函数找不到
|
|
127
|
+
return await Request.GetInstance().invokeFuncSync({
|
|
128
|
+
APIName: funcName,
|
|
129
|
+
isInvokeByAPIName: true
|
|
130
|
+
}, params);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
exports.getFunctionSync = getFunctionSync;
|
|
136
|
+
// 设置请求头
|
|
137
|
+
function setRespHeader() {
|
|
138
|
+
return function () {
|
|
139
|
+
switch (arguments.length) {
|
|
140
|
+
case 1:
|
|
141
|
+
if (checkUtils.isObject(arguments[0])) {
|
|
142
|
+
try {
|
|
143
|
+
for (let k of Object.keys(arguments[0])) {
|
|
144
|
+
utils.setHttpHeaders(k, toString(arguments[0][k]));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
throw new exceptions.InternalError(err.message);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw new exceptions.InvalidParamError('setResponseHeaders param is not a object');
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
case 2:
|
|
156
|
+
try {
|
|
157
|
+
utils.setHttpHeaders(arguments[0], toString(arguments[1]));
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
throw new exceptions.InternalError(err.message);
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
throw new exceptions.InvalidParamError('the number of setResponseHeaders param is 1 or 2');
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
exports.setRespHeader = setRespHeader;
|
|
169
|
+
function toString(value) {
|
|
170
|
+
if (value instanceof Array) {
|
|
171
|
+
let arr = [];
|
|
172
|
+
for (let v of value) {
|
|
173
|
+
if (typeof v === 'string') {
|
|
174
|
+
arr.push(v);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
arr.push(utils.stringify(v));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return arr.join(', ');
|
|
181
|
+
}
|
|
182
|
+
else if (typeof value === 'string') {
|
|
183
|
+
return value;
|
|
184
|
+
}
|
|
185
|
+
return utils.stringify(value);
|
|
186
|
+
}
|
|
187
|
+
exports.toString = toString;
|
|
188
|
+
function setRedirectLocation(context) {
|
|
189
|
+
return function (location) {
|
|
190
|
+
context.setResponseHeader(constants.httpHeaderKeys.location, location);
|
|
191
|
+
context.setResponseHeader(constants.httpHeaderKeys.statusCode, String(constants.httpStatusCodes.redirect));
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
exports.setRedirectLocation = setRedirectLocation;
|
|
195
|
+
// 请求方法
|
|
196
|
+
function method() {
|
|
197
|
+
return utils.getHttpMethod();
|
|
198
|
+
}
|
|
199
|
+
exports.method = method;
|
|
200
|
+
function mountMetadata(context) {
|
|
201
|
+
// 1.挂载metadata
|
|
202
|
+
context.metadata = metadataApi.metadata(context);
|
|
203
|
+
// 2.挂载metaType
|
|
204
|
+
if (!global.kunlun) {
|
|
205
|
+
global.kunlun = {};
|
|
206
|
+
}
|
|
207
|
+
global.kunlun.metaType = metadataApi.metaType();
|
|
208
|
+
}
|
|
209
|
+
exports.mountMetadata = mountMetadata;
|
|
210
|
+
function mountWorkflowFeature(context) {
|
|
211
|
+
if (context && context.workflow) {
|
|
212
|
+
context.workflow.updateVariable = common.updateVariable(context, Request.GetInstance().updateWorkflowVariables);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
context.workflow = {};
|
|
216
|
+
}
|
|
217
|
+
// 此处挂载保证了 terminate 存在
|
|
218
|
+
context.workflow.terminate = terminateWorkflow();
|
|
219
|
+
}
|
|
220
|
+
exports.mountWorkflowFeature = mountWorkflowFeature;
|
|
221
|
+
function terminateWorkflow() {
|
|
222
|
+
return async (workflowInstanceId, options) => {
|
|
223
|
+
let operator = utils.getUser()._id, reason = null;
|
|
224
|
+
if (options && options.reason) {
|
|
225
|
+
// instanceof 改动5
|
|
226
|
+
// if (options.reason instanceof common.fieldType.Multilingual) {
|
|
227
|
+
if (common.fieldType.isKFieldTypeMultilingual(options.reason)) {
|
|
228
|
+
reason = options.reason.toString();
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
reason = new common.fieldType.Multilingual(options.reason).toString();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
await Request.GetInstance().terminateWorkflowInstance(workflowInstanceId, operator, reason);
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
exports.terminateWorkflow = terminateWorkflow;
|
|
238
|
+
function mockFlowFeature(context) {
|
|
239
|
+
if (!context.flow) {
|
|
240
|
+
context.flow = {};
|
|
241
|
+
}
|
|
242
|
+
context.flow.updateVariable = common.updateVariable(context, Request.GetInstance().updateWorkflowVariables);
|
|
243
|
+
context.flow.getExecutionUserTaskInfo = mockGetExecutionUserTaskInfo();
|
|
244
|
+
context.flow.execute = mockExecuteFlow();
|
|
245
|
+
context.flow.revokeExecution = mockRevokeExecution();
|
|
246
|
+
context.flow.getExecutionInfo = mockGetExecutionInfo();
|
|
247
|
+
return context.flow;
|
|
248
|
+
}
|
|
249
|
+
exports.mockFlowFeature = mockFlowFeature;
|
|
250
|
+
function mockGetExecutionUserTaskInfo() {
|
|
251
|
+
return async (executionId) => {
|
|
252
|
+
if (!executionId || typeof executionId !== 'number') {
|
|
253
|
+
throw new exceptions_1.InvalidParamError(`param's type (${executionId}) need number, but is ${typeof executionId}`);
|
|
254
|
+
}
|
|
255
|
+
return await Request.GetInstance().getExecutionUserTaskInfo(executionId);
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
exports.mockGetExecutionUserTaskInfo = mockGetExecutionUserTaskInfo;
|
|
259
|
+
function mockExecuteFlow() {
|
|
260
|
+
return async (apiName, options) => {
|
|
261
|
+
if (!apiName || typeof apiName !== 'string') {
|
|
262
|
+
throw new exceptions_1.InvalidParamError(`param's type (${apiName}) need string, but is ${typeof apiName}`);
|
|
263
|
+
}
|
|
264
|
+
if (options && options.params && checkUtils.isNotObject(options.params)) {
|
|
265
|
+
throw new exceptions_1.InvalidParamError(`options.params's type (${options}) need object, but is ${Array.isArray(options) ? 'array' : typeof options.params}`);
|
|
266
|
+
}
|
|
267
|
+
if (!options) {
|
|
268
|
+
options = {};
|
|
269
|
+
}
|
|
270
|
+
return await Request.GetInstance().executeFlow(apiName, options, false);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
exports.mockExecuteFlow = mockExecuteFlow;
|
|
274
|
+
function mockRevokeExecution() {
|
|
275
|
+
return async (executionId, options) => {
|
|
276
|
+
if (!executionId || typeof executionId !== 'number') {
|
|
277
|
+
throw new exceptions_1.InvalidParamError(`param's type (${executionId}) is need number, but is ${typeof executionId}`);
|
|
278
|
+
}
|
|
279
|
+
return await Request.GetInstance().revokeExecution(executionId, options);
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
exports.mockRevokeExecution = mockRevokeExecution;
|
|
283
|
+
function mockGetExecutionInfo() {
|
|
284
|
+
return async (executionId) => {
|
|
285
|
+
if (!executionId || typeof executionId !== 'number') {
|
|
286
|
+
throw new exceptions_1.InvalidParamError(`param's type (${executionId}) is not matched to number, but is ${typeof executionId}`);
|
|
287
|
+
}
|
|
288
|
+
return await Request.GetInstance().getExecutionInfo(executionId);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
exports.mockGetExecutionInfo = mockGetExecutionInfo;
|
|
292
|
+
function invokeMicroservice() {
|
|
293
|
+
/**
|
|
294
|
+
* 微服务
|
|
295
|
+
* @param apiName 微服务的名称
|
|
296
|
+
*/
|
|
297
|
+
return function (apiName) {
|
|
298
|
+
if (!apiName || typeof (apiName) !== 'string') {
|
|
299
|
+
throw new exceptions_1.InvalidParamError(`The apiName (${apiName}) is invalid and should be a non-empty field string.`);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
/**
|
|
303
|
+
* 同步调用微服务
|
|
304
|
+
* @param path 请求路径,如:/ping
|
|
305
|
+
* @param method 请求方法,默认为 GET
|
|
306
|
+
* @param params 请求参数,默认为 undefined
|
|
307
|
+
*/
|
|
308
|
+
invoke: async (path, method = 'GET', params = undefined) => {
|
|
309
|
+
if (!path || typeof (path) !== 'string') {
|
|
310
|
+
throw new exceptions_1.InvalidParamError(`The path (${path}) is invalid and should be a non-empty field string.`);
|
|
311
|
+
}
|
|
312
|
+
if (!method || typeof (method) !== 'string') {
|
|
313
|
+
throw new exceptions_1.InvalidParamError(`The method (${method}) is invalid and should be a non-empty field string.`);
|
|
314
|
+
}
|
|
315
|
+
return await Request.GetFaaSInfraInstance().invokeMicroserviceSync(apiName, path, method, params);
|
|
316
|
+
},
|
|
317
|
+
/**
|
|
318
|
+
* 异步调用微服务
|
|
319
|
+
* @param path 请求路径,如:/ping
|
|
320
|
+
* @param method 请求方法,默认为 GET
|
|
321
|
+
* @param params 请求参数,默认为 undefined
|
|
322
|
+
*/
|
|
323
|
+
invokeAsync: async (path, method = 'GET', params = undefined) => {
|
|
324
|
+
if (!path || typeof (path) !== 'string') {
|
|
325
|
+
throw new exceptions_1.InvalidParamError(`The path (${path}) is invalid and should be a non-empty field string.`);
|
|
326
|
+
}
|
|
327
|
+
if (!method || typeof (method) !== 'string') {
|
|
328
|
+
throw new exceptions_1.InvalidParamError(`The method (${method}) is invalid and should be a non-empty field string.`);
|
|
329
|
+
}
|
|
330
|
+
return await Request.GetFaaSInfraInstance().invokeMicroserviceAsync(apiName, path, method, params);
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
exports.invokeMicroservice = invokeMicroservice;
|
|
336
|
+
exports.db = new db_1.DB();
|
|
337
|
+
exports.resources = new resources_1._Resources();
|
|
338
|
+
exports.msg = new msg_1.Message();
|
|
339
|
+
exports.tasks = new tasks_1.Tasks();
|
|
340
|
+
exports.cloudfunction = api.getFunctionSync();
|
|
341
|
+
exports.microservice = api.invokeMicroservice();
|
|
342
|
+
exports.workflow = {
|
|
343
|
+
terminate: terminateWorkflow(),
|
|
344
|
+
};
|
|
345
|
+
exports.metaData = new metadata_1.MetaData(null);
|
|
346
|
+
var impl_1 = require("../application/impl/impl");
|
|
347
|
+
Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return impl_1.Application; } });
|
package/hooks/hooks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/hooks/hooks.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const resources_1 = require("../context/resources/impl/resources");
|
|
4
|
+
const tasks_1 = require("../context/tasks/tasks");
|
|
5
|
+
const msg_1 = require("../context/msg/msg");
|
|
6
|
+
const server_common_node_1 = require("@byted-apaas/server-common-node");
|
|
7
|
+
const api = require("./api");
|
|
8
|
+
const operator_1 = require("../kunlun/operator/impl/operator");
|
|
9
|
+
const db_1 = require("../context/db/impl/db");
|
|
10
|
+
const common_1 = require("../request/common");
|
|
11
|
+
const integration_1 = require("../context/integration/impl/integration");
|
|
12
|
+
const metadataApi = require("../context/metadata/metadata");
|
|
13
|
+
const flow_1 = require("../global/application/flow/flow");
|
|
14
|
+
/**
|
|
15
|
+
* 根据 key 获取对应的全局变量
|
|
16
|
+
* @param key 全局变量的 key
|
|
17
|
+
*/
|
|
18
|
+
function getVar(key) {
|
|
19
|
+
return server_common_node_1.utils.getGlobalVariableByKey(key);
|
|
20
|
+
}
|
|
21
|
+
function pre(params, context, logger, requireFunc) {
|
|
22
|
+
// 初始化 kunlun
|
|
23
|
+
if (!global.kunlun) {
|
|
24
|
+
// 缺省的情况,先对 kunlun 进行初始化
|
|
25
|
+
global.kunlun = {};
|
|
26
|
+
}
|
|
27
|
+
global.kunlun.operator = new operator_1.Operator();
|
|
28
|
+
global.kunlun.getVar = getVar;
|
|
29
|
+
global.kunlun.tool.getTenantInfo = common_1.getTenantInfo;
|
|
30
|
+
// 对 context 下的能力进行初始化
|
|
31
|
+
mountContext(context, logger, requireFunc);
|
|
32
|
+
mountApplication(context);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* mountContext 函数用于初始化 context 在 core 包中实现的部分,包括:
|
|
36
|
+
* - db
|
|
37
|
+
* - (global function 场景下): setRespHeader, setRedirectLocation
|
|
38
|
+
* - task, function, msg, resources
|
|
39
|
+
* @param context 系统代理函数中经由 common 创建的用户 context,根据 source 分为不同类型
|
|
40
|
+
* @param logger Logger
|
|
41
|
+
* @param requireFunc
|
|
42
|
+
*/
|
|
43
|
+
function mountContext(context, logger, requireFunc) {
|
|
44
|
+
// 1. 全量挂载
|
|
45
|
+
context.db = new db_1.DBWithCurrentObject(context.objectApiName);
|
|
46
|
+
// set response headers
|
|
47
|
+
context.setResponseHeader = api.setRespHeader();
|
|
48
|
+
context.setRedirectLocation = api.setRedirectLocation(context);
|
|
49
|
+
context.method = server_common_node_1.utils.getHttpMethod();
|
|
50
|
+
// 2. 初始化 core 包中需要初始化的内容,因此强转为 IContext 类型
|
|
51
|
+
// - function
|
|
52
|
+
// - tasks
|
|
53
|
+
// - msg
|
|
54
|
+
// - resources
|
|
55
|
+
// - microservice
|
|
56
|
+
// - getVar
|
|
57
|
+
context.function = api.getFunctionSync(context, logger);
|
|
58
|
+
context.tasks = new tasks_1.Tasks(context.function);
|
|
59
|
+
context.msg = new msg_1.Message();
|
|
60
|
+
context.resources = new resources_1._Resources();
|
|
61
|
+
context.integration = new integration_1._Integration();
|
|
62
|
+
context.getVar = getVar;
|
|
63
|
+
context.microservice = api.invokeMicroservice();
|
|
64
|
+
api.mountWorkflowFeature(context);
|
|
65
|
+
// 挂载 metadata
|
|
66
|
+
api.mountMetadata(context);
|
|
67
|
+
api.mockFlowFeature(context);
|
|
68
|
+
// 防止 context.function 被串改
|
|
69
|
+
Object.freeze(context.function);
|
|
70
|
+
}
|
|
71
|
+
function mountApplication(context) {
|
|
72
|
+
if (!global.application) {
|
|
73
|
+
global.application = {};
|
|
74
|
+
}
|
|
75
|
+
global.application.data = new db_1.DB();
|
|
76
|
+
// (global as any).application.dataV3 = new DBV3<IGfCtx>();
|
|
77
|
+
// publicAPI
|
|
78
|
+
if (!global.application.publicAPI) {
|
|
79
|
+
global.application.publicAPI = {};
|
|
80
|
+
}
|
|
81
|
+
global.application.publicAPI.setResponseHeader = api.setRespHeader();
|
|
82
|
+
global.application.publicAPI.setRedirectLocation = api.setRedirectLocation(context);
|
|
83
|
+
global.application.publicAPI.method = server_common_node_1.utils.getHttpMethod();
|
|
84
|
+
global.application.publicAPI.headers = server_common_node_1.utils.getHttpHeaders();
|
|
85
|
+
global.application.msg = new msg_1.Message();
|
|
86
|
+
global.application.resources = new resources_1._Resources();
|
|
87
|
+
global.application.metadata = metadataApi.metadata(context);
|
|
88
|
+
// (global as any).application.metadataV3 = metadataApi.metadataV3(context);
|
|
89
|
+
// globalVar
|
|
90
|
+
if (!global.application.globalVar) {
|
|
91
|
+
global.application.globalVar = {};
|
|
92
|
+
}
|
|
93
|
+
global.application.globalVar.getVar = getVar;
|
|
94
|
+
// constants
|
|
95
|
+
if (!global.application.constants) {
|
|
96
|
+
global.application.constants = {};
|
|
97
|
+
}
|
|
98
|
+
global.application.constants.metaType = metadataApi.metaType();
|
|
99
|
+
// flow
|
|
100
|
+
global.application.flow = (0, flow_1.newFlow)(context);
|
|
101
|
+
// operator
|
|
102
|
+
global.application.operator = new operator_1.Operator();
|
|
103
|
+
global.application.integration = new integration_1._Integration();
|
|
104
|
+
}
|
|
105
|
+
module.exports = {
|
|
106
|
+
pre,
|
|
107
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IOperator } from './operator/IOperator';
|
|
2
|
+
import { GMTOffset as GMT } from '@byted-apaas/server-common-node/constants/timeZone';
|
|
3
|
+
import { area2code } from '@byted-apaas/server-common-node/constants/countryCode';
|
|
4
|
+
import { ITool, IToolsExtra } from '@byted-apaas/server-common-node/kunlun/tool/Itool';
|
|
5
|
+
import { errCodes } from '@byted-apaas/server-common-node/utils/exceptions';
|
|
6
|
+
import * as common from '@byted-apaas/server-common-node';
|
|
7
|
+
declare global {
|
|
8
|
+
export namespace kunlun {
|
|
9
|
+
/**
|
|
10
|
+
* 指令操作符
|
|
11
|
+
*/
|
|
12
|
+
let operator: IOperator;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare namespace kunlun {
|
|
16
|
+
/**
|
|
17
|
+
* 引用时区信息
|
|
18
|
+
*/
|
|
19
|
+
const GMTOffset: typeof GMT;
|
|
20
|
+
/**
|
|
21
|
+
* 引用国际区号
|
|
22
|
+
*/
|
|
23
|
+
const countryCode: typeof area2code;
|
|
24
|
+
/**
|
|
25
|
+
* 工具方法
|
|
26
|
+
*/
|
|
27
|
+
let tool: ITool & IToolsExtra;
|
|
28
|
+
/**
|
|
29
|
+
* 生成复杂数据结构
|
|
30
|
+
*/
|
|
31
|
+
namespace type {
|
|
32
|
+
export import Multilingual = common.fieldType.Multilingual;
|
|
33
|
+
export import Phone = common.fieldType.Phone;
|
|
34
|
+
export import Date = common.fieldType.Date;
|
|
35
|
+
export import DateTime = common.fieldType.DateTime;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 错误码
|
|
39
|
+
*/
|
|
40
|
+
const errorCode: {
|
|
41
|
+
/**
|
|
42
|
+
* 限流错误码
|
|
43
|
+
*/
|
|
44
|
+
RATE_LIMIT_ERROR: errCodes;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 根据 key 获取对应的全局变量
|
|
48
|
+
* @param key 全局变量的 key
|
|
49
|
+
*/
|
|
50
|
+
function getVar(key: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* 指令操作符
|
|
53
|
+
*/
|
|
54
|
+
const operator: IOperator;
|
|
55
|
+
}
|
package/kunlun/kunlun.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.kunlun = void 0;
|
|
6
|
+
const timeZone_1 = require("@byted-apaas/server-common-node/constants/timeZone");
|
|
7
|
+
const countryCode_1 = require("@byted-apaas/server-common-node/constants/countryCode");
|
|
8
|
+
const tool_1 = require("@byted-apaas/server-common-node/kunlun/tool/impl/tool");
|
|
9
|
+
const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
|
|
10
|
+
const operator_1 = require("./operator/impl/operator");
|
|
11
|
+
const common = require("@byted-apaas/server-common-node");
|
|
12
|
+
const Request = require("../request/interface");
|
|
13
|
+
var kunlun;
|
|
14
|
+
(function (kunlun) {
|
|
15
|
+
/**
|
|
16
|
+
* 引用时区信息
|
|
17
|
+
*/
|
|
18
|
+
kunlun.GMTOffset = timeZone_1.GMTOffset;
|
|
19
|
+
/**
|
|
20
|
+
* 引用国际区号
|
|
21
|
+
*/
|
|
22
|
+
kunlun.countryCode = countryCode_1.area2code;
|
|
23
|
+
/**
|
|
24
|
+
* 工具方法
|
|
25
|
+
*/
|
|
26
|
+
kunlun.tool = new tool_1.Tool();
|
|
27
|
+
/**
|
|
28
|
+
* 生成复杂数据结构
|
|
29
|
+
*/
|
|
30
|
+
let type;
|
|
31
|
+
(function (type) {
|
|
32
|
+
type.Multilingual = common.fieldType.Multilingual;
|
|
33
|
+
type.Phone = common.fieldType.Phone;
|
|
34
|
+
type.Date = common.fieldType.Date;
|
|
35
|
+
type.DateTime = common.fieldType.DateTime;
|
|
36
|
+
})(type = kunlun.type || (kunlun.type = {}));
|
|
37
|
+
/**
|
|
38
|
+
* 错误码
|
|
39
|
+
*/
|
|
40
|
+
kunlun.errorCode = {
|
|
41
|
+
/**
|
|
42
|
+
* 限流错误码
|
|
43
|
+
*/
|
|
44
|
+
RATE_LIMIT_ERROR: exceptions_1.errCodes.RATE_LIMIT_ERROR,
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 根据 key 获取对应的全局变量
|
|
48
|
+
* @param key 全局变量的 key
|
|
49
|
+
*/
|
|
50
|
+
async function getVar(key) {
|
|
51
|
+
return await Request.GetInstance().getGlobalConfigByKey(key);
|
|
52
|
+
}
|
|
53
|
+
kunlun.getVar = getVar;
|
|
54
|
+
/**
|
|
55
|
+
* 指令操作符
|
|
56
|
+
*/
|
|
57
|
+
kunlun.operator = new operator_1.Operator();
|
|
58
|
+
})(kunlun = exports.kunlun || (exports.kunlun = {}));
|