@byted-apaas/server-sdk-node 1.0.17 → 1.1.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +11 -0
  2. package/application/application.d.ts +9 -7
  3. package/application/function/function.d.ts +1 -1
  4. package/application/function/function.js +0 -1
  5. package/application/impl/common.d.ts +1 -1
  6. package/application/impl/common.js +13 -12
  7. package/application/impl/impl.d.ts +8 -6
  8. package/application/impl/impl.js +6 -4
  9. package/common/structs.d.ts +15 -0
  10. package/common/structs.js +21 -0
  11. package/constants/constants.js +4 -4
  12. package/context/context.d.ts +8 -38
  13. package/context/context.js +2 -2
  14. package/context/db/db.d.ts +11 -19
  15. package/context/db/impl/IObject.d.ts +41 -40
  16. package/context/db/impl/db.d.ts +9 -9
  17. package/context/db/impl/db.js +6 -6
  18. package/context/db/impl/object.d.ts +4 -3
  19. package/context/db/impl/object.js +62 -50
  20. package/context/db/impl/oql/oql.d.ts +1 -1
  21. package/context/db/impl/oql/oql.js +1 -1
  22. package/context/db/impl/order.js +1 -1
  23. package/context/db/impl/propertiesStore.js +1 -1
  24. package/context/db/impl/transaction/index.d.ts +1 -1
  25. package/context/db/impl/transaction/index.js +51 -46
  26. package/context/db/impl/transaction.d.ts +0 -5
  27. package/context/integration/IIntegration.d.ts +30 -0
  28. package/context/integration/IIntegration.js +4 -0
  29. package/context/integration/impl/integration.d.ts +16 -0
  30. package/context/integration/impl/integration.js +62 -0
  31. package/context/metadata/components/common.js +3 -3
  32. package/context/metadata/components/components.d.ts +4 -4
  33. package/context/metadata/components/desktop/list.d.ts +3 -3
  34. package/context/metadata/components/desktop/list.js +23 -23
  35. package/context/metadata/components/desktop/recordDetail.d.ts +2 -2
  36. package/context/metadata/components/mobile/list.d.ts +4 -4
  37. package/context/metadata/components/mobile/list.js +1 -1
  38. package/context/metadata/metadata.d.ts +5 -6
  39. package/context/metadata/metadata.js +5 -6
  40. package/context/metadata/objects/fields.d.ts +6 -6
  41. package/context/metadata/objects/fields.js +57 -57
  42. package/context/metadata/objects/fields.util.d.ts +3 -3
  43. package/context/metadata/objects/fields.util.js +21 -21
  44. package/context/metadata/objects/objects.d.ts +1 -1
  45. package/context/metadata/objects/objects.js +1 -1
  46. package/context/metadata/types/components.d.ts +5 -5
  47. package/context/metadata/types/objects.d.ts +88 -88
  48. package/context/msg/msg.d.ts +2 -2
  49. package/context/resources/IResources.d.ts +6 -4
  50. package/context/resources/impl/resources.d.ts +6 -6
  51. package/context/resources/impl/resources.js +5 -5
  52. package/context/tasks/tasks.d.ts +3 -3
  53. package/context/tasks/tasks.js +5 -5
  54. package/data/index.d.ts +2 -2
  55. package/global/application/flow/flow.d.ts +85 -0
  56. package/global/application/flow/flow.js +2 -0
  57. package/global/application/globalVar/globalVar.d.ts +7 -0
  58. package/global/application/globalVar/globalVar.js +2 -0
  59. package/global/global.d.ts +64 -0
  60. package/global/global.js +3 -0
  61. package/hooks/api.d.ts +12 -7
  62. package/hooks/api.js +28 -23
  63. package/hooks/hooks.js +41 -0
  64. package/kunlun/kunlun.d.ts +5 -5
  65. package/kunlun/operator/IOperator.d.ts +16 -16
  66. package/kunlun/operator/impl/expression.d.ts +2 -2
  67. package/kunlun/operator/impl/expression.js +5 -5
  68. package/kunlun/operator/impl/logic.js +48 -31
  69. package/kunlun/operator/impl/logicV2.d.ts +2 -2
  70. package/kunlun/operator/impl/logicV2.js +12 -13
  71. package/kunlun/operator/impl/operator.d.ts +17 -17
  72. package/kunlun/operator/impl/operator.js +38 -38
  73. package/kunlun/operator/impl/operatorV2.d.ts +17 -17
  74. package/kunlun/operator/impl/operatorV2.js +38 -38
  75. package/lib/core.d.ts +3 -3
  76. package/package.json +2 -2
  77. package/request/common.d.ts +1 -1
  78. package/request/common.js +4 -3
  79. package/request/constants.d.ts +1 -1
  80. package/request/constants.js +6 -6
  81. package/request/faasinfra.d.ts +1 -1
  82. package/request/faasinfra.js +41 -253
  83. package/request/innerapi.d.ts +14 -10
  84. package/request/innerapi.js +220 -66
  85. package/request/interface.d.ts +68 -54
  86. package/request/interface.js +8 -9
  87. package/request/openapi.d.ts +15 -11
  88. package/request/openapi.js +266 -158
@@ -4,24 +4,24 @@ exports.OperatorV2 = exports.operates = void 0;
4
4
  const server_common_node_1 = require("@byted-apaas/server-common-node");
5
5
  const logicV2_1 = require("./logicV2");
6
6
  exports.operates = {
7
- AND: "and",
8
- OR: "or",
9
- EMPTY: "isEmpty",
10
- NOT_EMPTY: "isNotEmpty",
11
- EQ: "equals",
12
- NEQ: "notEquals",
13
- LT: "lessThan",
14
- LTE: "lessThanOrEquals",
15
- GT: "greaterThan",
16
- GTE: "greaterThanOrEquals",
17
- CONTAIN: "contains",
18
- NOT_CONTAIN: "notContains",
19
- IN: "isAnyOf",
20
- NIN: "isNoneOf",
21
- HAS_ANY_OF: "hasAnyOf",
22
- HAS_NONE_OF: "hasNoneOf",
23
- isOnOrBefore: "lt",
24
- isOnOrAfter: "gt",
7
+ AND: 'and',
8
+ OR: 'or',
9
+ EMPTY: 'isEmpty',
10
+ NOT_EMPTY: 'isNotEmpty',
11
+ EQ: 'equals',
12
+ NEQ: 'notEquals',
13
+ LT: 'lessThan',
14
+ LTE: 'lessThanOrEquals',
15
+ GT: 'greaterThan',
16
+ GTE: 'greaterThanOrEquals',
17
+ CONTAIN: 'contains',
18
+ NOT_CONTAIN: 'notContains',
19
+ IN: 'isAnyOf',
20
+ NIN: 'isNoneOf',
21
+ HAS_ANY_OF: 'hasAnyOf',
22
+ HAS_NONE_OF: 'hasNoneOf',
23
+ isOnOrBefore: 'lt',
24
+ isOnOrAfter: 'gt',
25
25
  };
26
26
  class OperatorV2 {
27
27
  /**
@@ -29,10 +29,10 @@ class OperatorV2 {
29
29
  * @param conditions 多个条件,用逗号分隔
30
30
  * @example
31
31
  * ```
32
- * context.db.object("_user").where(kunlun.operator.and({
33
- * age: "22"
32
+ * context.db.object('_user').where(kunlun.operator.and({
33
+ * age: '22'
34
34
  * },{
35
- * gender: "male"
35
+ * gender: 'male'
36
36
  * }))
37
37
  * ```
38
38
  */
@@ -46,10 +46,10 @@ class OperatorV2 {
46
46
  * @param conditions 多个条件,用逗号分隔
47
47
  * @example
48
48
  * ```
49
- * context.db.object("_user").where(kunlun.operator.or({
50
- * age: "22"
49
+ * context.db.object('_user').where(kunlun.operator.or({
50
+ * age: '22'
51
51
  * },{
52
- * age: "25"
52
+ * age: '25'
53
53
  * }))
54
54
  * ```
55
55
  */
@@ -63,7 +63,7 @@ class OperatorV2 {
63
63
  * @param value 判定是否包含的文本值
64
64
  * @example
65
65
  * ```
66
- * context.db.object("_user").where({_name: kunlun.operator.contain("a")})
66
+ * context.db.object('_user').where({_name: kunlun.operator.contain('a')})
67
67
  * ```
68
68
  */
69
69
  contain(value) {
@@ -75,7 +75,7 @@ class OperatorV2 {
75
75
  * @param value 判定是否不包含的文本值
76
76
  * @example
77
77
  * ```
78
- * context.db.object("_user").where({_name: kunlun.operator.notContain("a")})
78
+ * context.db.object('_user').where({_name: kunlun.operator.notContain('a')})
79
79
  * ```
80
80
  */
81
81
  notContain(value) {
@@ -86,7 +86,7 @@ class OperatorV2 {
86
86
  * 无需入参,判断是否为空
87
87
  * @example
88
88
  * ```
89
- * context.db.object("_user").where({employeeType: kunlun.operator.empty()})
89
+ * context.db.object('_user').where({employeeType: kunlun.operator.empty()})
90
90
  * ```
91
91
  */
92
92
  empty() {
@@ -97,7 +97,7 @@ class OperatorV2 {
97
97
  * 无需入参,判断是否为空
98
98
  * @example
99
99
  * ```
100
- * context.db.object("_user").where({employeeType: kunlun.operator.notEmpty()})
100
+ * context.db.object('_user').where({employeeType: kunlun.operator.notEmpty()})
101
101
  * ```
102
102
  */
103
103
  notEmpty() {
@@ -109,7 +109,7 @@ class OperatorV2 {
109
109
  * @param value 判定是否相等的值
110
110
  * @example
111
111
  * ```
112
- * context.db.object("_user").where({age: kunlun.operator.eq(20)})
112
+ * context.db.object('_user').where({age: kunlun.operator.eq(20)})
113
113
  * ```
114
114
  */
115
115
  eq(value) {
@@ -121,7 +121,7 @@ class OperatorV2 {
121
121
  * @param value 判定是否不相等的值
122
122
  * @example
123
123
  * ```
124
- * context.db.object("_user").where({age: kunlun.operator.neq(20)})
124
+ * context.db.object('_user').where({age: kunlun.operator.neq(20)})
125
125
  * ```
126
126
  */
127
127
  neq(value) {
@@ -133,7 +133,7 @@ class OperatorV2 {
133
133
  * @param value 判定是否大于或晚于的值
134
134
  * @example
135
135
  * ```
136
- * kunlun.operator.gt(new Date("2020-11-26").getTime())
136
+ * kunlun.operator.gt(new Date('2020-11-26').getTime())
137
137
  * ```
138
138
  */
139
139
  gt(value) {
@@ -145,7 +145,7 @@ class OperatorV2 {
145
145
  * @param value 判定是否大于等于或晚于等于的值
146
146
  * @example
147
147
  * ```
148
- * kunlun.operator.gte(new Date("2020-11-26").getTime())
148
+ * kunlun.operator.gte(new Date('2020-11-26').getTime())
149
149
  * ```
150
150
  */
151
151
  gte(value) {
@@ -157,7 +157,7 @@ class OperatorV2 {
157
157
  * @param value 判定是否小于或早于的值
158
158
  * @example
159
159
  * ```
160
- * kunlun.operator.lt(new Date("2020-11-26").getTime())
160
+ * kunlun.operator.lt(new Date('2020-11-26').getTime())
161
161
  * ```
162
162
  */
163
163
  lt(value) {
@@ -169,7 +169,7 @@ class OperatorV2 {
169
169
  * @param value 判定是否小于等于或早于等于的值
170
170
  * @example
171
171
  * ```
172
- * kunlun.operator.lte(new Date("2020-11-26").getTime())
172
+ * kunlun.operator.lte(new Date('2020-11-26').getTime())
173
173
  * ```
174
174
  */
175
175
  lte(value) {
@@ -180,7 +180,7 @@ class OperatorV2 {
180
180
  value = !value ? [] : value;
181
181
  const argList = server_common_node_1.utils.argsToList(value, restValues);
182
182
  if (argList.length === 0) {
183
- throw new server_common_node_1.exceptions.InvalidParamError("can not IN empty list");
183
+ throw new server_common_node_1.exceptions.InvalidParamError('can not IN empty list');
184
184
  }
185
185
  return new logicV2_1.ArithmeticExpression(null, exports.operates.IN, argList);
186
186
  }
@@ -189,7 +189,7 @@ class OperatorV2 {
189
189
  value = !value ? [] : value;
190
190
  const argList = server_common_node_1.utils.argsToList(value, restValues);
191
191
  if (argList.length === 0) {
192
- throw new server_common_node_1.exceptions.InvalidParamError("can not NOT_IN empty list");
192
+ throw new server_common_node_1.exceptions.InvalidParamError('can not NOT_IN empty list');
193
193
  }
194
194
  return new logicV2_1.ArithmeticExpression(null, exports.operates.NIN, argList);
195
195
  }
@@ -198,7 +198,7 @@ class OperatorV2 {
198
198
  value = !value ? [] : value;
199
199
  const argList = server_common_node_1.utils.argsToList(value, restValues);
200
200
  if (argList.length === 0) {
201
- throw new server_common_node_1.exceptions.InvalidParamError("can not HAS_ANY_OF empty list");
201
+ throw new server_common_node_1.exceptions.InvalidParamError('can not HAS_ANY_OF empty list');
202
202
  }
203
203
  return new logicV2_1.ArithmeticExpression(null, exports.operates.HAS_ANY_OF, argList);
204
204
  }
@@ -207,7 +207,7 @@ class OperatorV2 {
207
207
  value = !value ? [] : value;
208
208
  const argList = server_common_node_1.utils.argsToList(value, restValues);
209
209
  if (argList.length === 0) {
210
- throw new server_common_node_1.exceptions.InvalidParamError("can not HAS_NONE_OF empty list");
210
+ throw new server_common_node_1.exceptions.InvalidParamError('can not HAS_NONE_OF empty list');
211
211
  }
212
212
  return new logicV2_1.ArithmeticExpression(null, exports.operates.HAS_NONE_OF, argList);
213
213
  }
package/lib/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * as hooks from "../hooks/hooks";
1
+ export * as hooks from '../hooks/hooks';
2
2
  export declare const isNewSystemProxyFunc: boolean;
3
- export { kunlun } from "../kunlun/kunlun";
4
- export { db, resources, msg, tasks, cloudfunction, microservice, workflow, metaData, Application } from "../hooks/api";
3
+ export { kunlun } from '../kunlun/kunlun';
4
+ export { db, resources, msg, tasks, cloudfunction, microservice, workflow, metaData, Application } from '../hooks/api';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.0.17",
3
+ "version": "1.1.0-beta.11",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -12,7 +12,7 @@
12
12
  "pre-build": "rm -rf build && tsc"
13
13
  },
14
14
  "dependencies": {
15
- "@byted-apaas/server-common-node": "^1.0.15",
15
+ "@byted-apaas/server-common-node": "^1.0.28",
16
16
  "@jorgeferrero/stream-to-buffer": "^2.0.6",
17
17
  "dayjs": "^1.9.6",
18
18
  "form-data": "^3.0.0",
@@ -1,4 +1,4 @@
1
- import { AppCtx } from "../application/application";
1
+ import { AppCtx } from '../application/application';
2
2
  export declare function getDebugExtraInfo(): Record<string, string>;
3
3
  export declare function getTriggerCtx(): any;
4
4
  export declare function transMapToFlowVariable(params: Record<string, any>): {
package/request/common.js CHANGED
@@ -10,13 +10,14 @@ const common_1 = require("../application/impl/common");
10
10
  const utils = common.utils;
11
11
  const checkUtils = common.checkUtils;
12
12
  const exceptions = common.exceptions;
13
- const nodeCls = require("node-cls");
13
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
14
+ const nodeCls = require('node-cls');
14
15
  function checkLoopCtx(reqCtx) {
15
16
  return reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks);
16
17
  }
17
18
  function getDebugExtraInfo() {
18
19
  let extra = {
19
- "FunctionFrameVersion": "FunctionFrameV2",
20
+ 'FunctionFrameVersion': 'FunctionFrameV2',
20
21
  };
21
22
  if (utils.isDebug()) {
22
23
  extra.DebugInfo = utils.getDebugCode();
@@ -66,7 +67,7 @@ exports.transFlowVariableToMap = transFlowVariableToMap;
66
67
  async function getTenantInfo(appCtx) {
67
68
  if (!appCtx) {
68
69
  appCtx = {
69
- mode: "faasSDK",
70
+ mode: 'faasSDK',
70
71
  credential: new credential_1.AppCredential(utils.getClientId(), utils.getClientSecret(), true)
71
72
  };
72
73
  }
@@ -1,4 +1,4 @@
1
- import { GetHttpConfig, PostHttpConfig } from "@byted-apaas/server-common-node/http/config";
1
+ import { GetHttpConfig, PostHttpConfig } from '@byted-apaas/server-common-node/http/config';
2
2
  export declare const metricsMethodKeys: Record<string, string>;
3
3
  export declare const openapiHttpPath: {
4
4
  getBatchAttachmentToken: PostHttpConfig;
@@ -6,13 +6,13 @@ const constants_1 = require("@byted-apaas/server-common-node/http/constants");
6
6
  exports.metricsMethodKeys = {
7
7
  // openapi
8
8
  // file upload & download
9
- getBatchAttachmentToken: "openapi_getBatchAttachmentToken",
10
- oql: "openapi_oql",
9
+ getBatchAttachmentToken: 'openapi_getBatchAttachmentToken',
10
+ oql: 'openapi_oql',
11
11
  // flow
12
- getExecutionUserTaskInfo: "openapi_getExecutionUserTaskInfo",
13
- getExecutionInfo: "openapi_getExecutionInfo",
14
- revokeExecution: "openapi_revokeExecution",
15
- executeFlow: "openapi_executeFlow",
12
+ getExecutionUserTaskInfo: 'openapi_getExecutionUserTaskInfo',
13
+ getExecutionInfo: 'openapi_getExecutionInfo',
14
+ revokeExecution: 'openapi_revokeExecution',
15
+ executeFlow: 'openapi_executeFlow',
16
16
  };
17
17
  exports.openapiHttpPath = {
18
18
  getBatchAttachmentToken: new config_1.PostHttpConfig(`/attachment/v1/getBatchAttachmentToken`, exports.metricsMethodKeys.getBatchAttachmentToken),
@@ -1,4 +1,4 @@
1
- import { IFaaSInfraRequest } from "./interface";
1
+ import { IFaaSInfraRequest } from './interface';
2
2
  export declare class FaaSInfraRequest implements IFaaSInfraRequest {
3
3
  constructor();
4
4
  createDistributeTaskV1(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: any): Promise<any>;
@@ -9,9 +9,8 @@ const faasinfraHttpPath = common.http.faasinfraHttpPath;
9
9
  const replaceKeys = common.http.replaceKeys;
10
10
  const exceptions = common.exceptions;
11
11
  const utils = common.utils;
12
- const nodeCls = require("node-cls");
13
- const distributedHandleMask = headers.distributedHandleMask;
14
- const loopMasks = headers.loopMasks;
12
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
13
+ const nodeCls = require('node-cls'); //nolint:byted_s_ts_no_require_imports
15
14
  const loopMasksKey = headers.loopMasksKey;
16
15
  const loopCtxKey = headers.loopCtxKey;
17
16
  const url_1 = require("url");
@@ -26,14 +25,14 @@ class FaaSInfraRequest {
26
25
  let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
27
26
  // 3.请求
28
27
  config.json = {
29
- "domainName": utils.getTenantNameFromCtx(),
30
- "namespace": utils.getNamespaceFromCtx(),
31
- "userId": utils.getUserIDFromCtx(),
32
- "dataset": dataset,
33
- "handlerFunc": handlerFunc,
34
- "progressCallbackFunc": progressCallbackFunc,
35
- "completedCallbackFunc": completedCallbackFunc,
36
- "options": options
28
+ 'domainName': utils.getTenantNameFromCtx(),
29
+ 'namespace': utils.getNamespaceFromCtx(),
30
+ 'userId': utils.getUserIDFromCtx(),
31
+ dataset,
32
+ handlerFunc,
33
+ progressCallbackFunc,
34
+ completedCallbackFunc,
35
+ options,
37
36
  };
38
37
  let task_id = utils.getTriggerTaskID();
39
38
  if (task_id) {
@@ -42,32 +41,30 @@ class FaaSInfraRequest {
42
41
  let loopCtx = nodeCls.get(loopCtxKey);
43
42
  if (checkLoopCtx(loopCtx)) {
44
43
  config.json[loopMasksKey] = loopCtx.loopMasks;
45
- if (!utils.isMicroservice() && (handlerFunc !== "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, handlerFunc))) ||
46
- (progressCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, progressCallbackFunc))) ||
47
- (completedCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, completedCallbackFunc)))) {
48
- throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
44
+ if (!utils.isMicroservice() && (handlerFunc !== '' && config.json[loopMasksKey].includes(utils.handleFuncName({}, handlerFunc))) ||
45
+ (progressCallbackFunc !== '' && config.json[loopMasksKey].includes(utils.handleFuncName({}, progressCallbackFunc))) ||
46
+ (completedCallbackFunc !== '' && config.json[loopMasksKey].includes(utils.handleFuncName({}, completedCallbackFunc)))) {
47
+ throw new exceptions.InvalidParamError('Task execution forms a loop.');
49
48
  }
50
49
  }
51
50
  return await faasinfra.doRequest(null, urlPath, config);
52
51
  }
53
52
  async createDistributeTaskV2(dataset, handlerFunc, progressCallbackFunc, completedCallbackFunc, options) {
54
- // 检查函数是否存在
55
- utils.requireFunction(handlerFunc);
56
53
  // 1.获取 options
57
54
  let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTaskV2);
58
55
  // 2.构造url
59
56
  let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
60
57
  // 3.请求
61
58
  config.json = {
62
- "domainName": utils.getTenantNameFromCtx(),
63
- "namespace": utils.getNamespaceFromCtx(),
64
- "userId": utils.getUserIDFromCtx(),
65
- "dataset": dataset,
66
- "handlerFunc": handlerFunc,
67
- "progressCallbackFunc": progressCallbackFunc,
68
- "completedCallbackFunc": completedCallbackFunc,
69
- "options": options,
70
- "extra": getDebugExtraInfo()
59
+ 'domainName': utils.getTenantNameFromCtx(),
60
+ 'namespace': utils.getNamespaceFromCtx(),
61
+ 'userId': utils.getUserIDFromCtx(),
62
+ dataset,
63
+ handlerFunc,
64
+ progressCallbackFunc,
65
+ completedCallbackFunc,
66
+ options,
67
+ 'extra': getDebugExtraInfo(),
71
68
  };
72
69
  let task_id = utils.getTriggerTaskID();
73
70
  if (task_id) {
@@ -76,9 +73,9 @@ class FaaSInfraRequest {
76
73
  let loopCtx = nodeCls.get(loopCtxKey);
77
74
  if (checkLoopCtx(loopCtx)) {
78
75
  config.json[loopMasksKey] = loopCtx.loopMasks;
79
- if ((handlerFunc !== "" && config.json[loopMasksKey].includes(handlerFunc)) ||
80
- (progressCallbackFunc != "" && config.json[loopMasksKey].includes(progressCallbackFunc)) ||
81
- (completedCallbackFunc != "" && config.json[loopMasksKey].includes(completedCallbackFunc))) {
76
+ if ((handlerFunc !== '' && config.json[loopMasksKey].includes(handlerFunc)) ||
77
+ (progressCallbackFunc !== '' && config.json[loopMasksKey].includes(progressCallbackFunc)) ||
78
+ (completedCallbackFunc !== '' && config.json[loopMasksKey].includes(completedCallbackFunc))) {
82
79
  throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
83
80
  }
84
81
  }
@@ -89,13 +86,13 @@ class FaaSInfraRequest {
89
86
  let options = commonHttp.getOptions(null, reqPath);
90
87
  let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
91
88
  options.json = {
92
- "microserviceId": apiName,
93
- "path": path,
94
- "method": method,
95
- "query": parseQueryParams(path),
89
+ 'microserviceId': apiName,
90
+ path,
91
+ method,
92
+ 'query': parseQueryParams(path),
96
93
  };
97
94
  // 处理 body 参数
98
- if (method.toUpperCase() !== "GET") {
95
+ if (method.toUpperCase() !== 'GET') {
99
96
  options.json.body = JSON.stringify(body);
100
97
  }
101
98
  return await faasinfra.doRequest(null, urlPath, options);
@@ -105,13 +102,13 @@ class FaaSInfraRequest {
105
102
  let options = commonHttp.getOptions(null, reqPath);
106
103
  let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
107
104
  options.json = {
108
- "microserviceId": apiName,
109
- "path": path,
110
- "method": method,
111
- "query": parseQueryParams(path),
105
+ 'microserviceId': apiName,
106
+ path,
107
+ method,
108
+ 'query': parseQueryParams(path),
112
109
  };
113
110
  // 处理 body 参数
114
- if (method.toUpperCase() !== "GET") {
111
+ if (method.toUpperCase() !== 'GET') {
115
112
  options.json.body = JSON.stringify(body);
116
113
  }
117
114
  return await faasinfra.doRequest(null, urlPath, options);
@@ -120,7 +117,7 @@ class FaaSInfraRequest {
120
117
  exports.FaaSInfraRequest = FaaSInfraRequest;
121
118
  function getDebugExtraInfo() {
122
119
  let extra = {
123
- "FunctionFrameVersion": "FunctionFrameV2",
120
+ 'FunctionFrameVersion': 'FunctionFrameV2',
124
121
  };
125
122
  if (utils.isDebug()) {
126
123
  extra.DebugInfo = utils.getDebugCode();
@@ -132,227 +129,18 @@ function checkLoopCtx(reqCtx) {
132
129
  }
133
130
  function parseQueryParams(path) {
134
131
  let params = {};
135
- let url = new url_1.URL(path, "https://aa.bb.cc");
132
+ const url = new url_1.URL(path, 'https://aa.bb.cc');
136
133
  for (let [k, v] of url.searchParams.entries()) {
137
- if (typeof (k) !== "string") {
134
+ if (typeof (k) !== 'string') {
138
135
  throw new exceptions_1.InternalError(`The type of k should be string, but ${typeof (k)}`);
139
136
  }
140
- if (typeof (v) !== "string") {
137
+ if (typeof (v) !== 'string') {
141
138
  throw new exceptions_1.InternalError(`The type of v should be string, but ${typeof (v)}`);
142
139
  }
143
- params[k] = v.split(",");
140
+ params[k] = v.split(',');
144
141
  }
145
142
  if (Object.keys(params).length === 0) {
146
143
  return undefined;
147
144
  }
148
145
  return params;
149
146
  }
150
- /*
151
- export async function invokeFuncSync(apiName: string, params: any, oldFuncName: string, isSync: boolean) {
152
- let result = await invokeFunc(apiName, params, oldFuncName, isSync);
153
- if (result && result.code === "0") {
154
- return result.data;
155
- }
156
- return result;
157
- }
158
-
159
- async function invokeFunc(apiName: string, params: any, oldFuncName: string, isSync = false) {
160
- let reqPath = faasinfraHttpPath.createAsyncTask;
161
- if (isSync) {
162
- reqPath = faasinfraHttpPath.invokeFuncSync;
163
- }
164
-
165
- let options = commonHttp.getOptions(null, reqPath);
166
- let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
167
-
168
- let triggerCtx: Record<string, any> = {};
169
- let task_id = utils.getTriggerTaskID();
170
- if (task_id) {
171
- triggerCtx[headers.triggerTaskId] = task_id;
172
- }
173
-
174
- let temp = utils.getDistributedHandleMask();
175
- if (temp) {
176
- triggerCtx[distributedHandleMask] = temp;
177
- }
178
-
179
- let reqCtx = nodeCls.get(loopCtxKey);
180
- if (checkLoopCtx(reqCtx)) {
181
- triggerCtx[loopMasks] = reqCtx.loopMasks
182
- }
183
-
184
- // 相等时,表示是新版本函数的场景
185
- if (apiName === oldFuncName) {
186
- options.json = {
187
- "apiAlias": apiName,
188
- "params": JSON.stringify(params),
189
- "context": JSON.stringify(triggerCtx),
190
- "triggerType": utils.getTriggerType(),
191
- }
192
- } else {
193
- options.json = {
194
- "function_name": apiName,
195
- "params": JSON.stringify(params),
196
- "context": JSON.stringify(triggerCtx),
197
- "triggerType": utils.getTriggerType(),
198
- }
199
- }
200
-
201
- if (utils.isMicroservice()) {
202
- options.json.apiAlias = oldFuncName;
203
- }
204
-
205
- return await faasinfra.doRequest(null, urlPath, options);
206
- }
207
-
208
- export async function asyncTask(apiName: string, params: any) {
209
- // 检查函数是否存在
210
- utils.requireFunction(apiName);
211
-
212
- let reqPath = faasinfraHttpPath.createAsyncTaskV2;
213
- let options = commonHttp.getOptions(null, reqPath);
214
- let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
215
-
216
- let triggerCtx: Record<string, any> = {};
217
- let task_id = utils.getTriggerTaskID();
218
- if (task_id) {
219
- triggerCtx[headers.triggerTaskId] = task_id;
220
- }
221
-
222
- let temp = utils.getDistributedHandleMask();
223
- if (temp) {
224
- triggerCtx[distributedHandleMask] = temp;
225
- }
226
-
227
- let reqCtx = nodeCls.get(loopCtxKey);
228
- if (checkLoopCtx(reqCtx)) {
229
- triggerCtx[loopMasks] = reqCtx.loopMasks
230
- }
231
-
232
- options.json = {
233
- "api_name": apiName,
234
- "params": JSON.stringify(params),
235
- "context": JSON.stringify(triggerCtx),
236
- "triggerType": utils.getTriggerType(),
237
- "extra": getDebugExtraInfo()
238
- }
239
-
240
- return await faasinfra.doRequest(null, urlPath, options);
241
- }
242
-
243
- export async function createDistributedTaskV1(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: _Options):
244
- Promise<number> {
245
- // 1.获取 options
246
- let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTask);
247
-
248
- // 2.构造url
249
- let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
250
-
251
- // 3.请求
252
- config.json = {
253
- "domainName": utils.getTenantNameFromCtx(),
254
- "namespace": utils.getNamespaceFromCtx(),
255
- "userId": utils.getUserIDFromCtx(),
256
-
257
- "dataset": dataset,
258
- "handlerFunc": handlerFunc,
259
- "progressCallbackFunc": progressCallbackFunc,
260
- "completedCallbackFunc": completedCallbackFunc,
261
- "options": options
262
- }
263
-
264
- let task_id = utils.getTriggerTaskID();
265
- if (task_id) {
266
- config.json[headers.triggerTaskId] = task_id;
267
- }
268
-
269
- let loopCtx = nodeCls.get(loopCtxKey);
270
- if (checkLoopCtx(loopCtx)) {
271
- config.json[loopMasksKey] = loopCtx.loopMasks;
272
- if (!utils.isMicroservice() && (handlerFunc !== "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, handlerFunc))) ||
273
- (progressCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, progressCallbackFunc))) ||
274
- (completedCallbackFunc != "" && config.json[loopMasksKey].includes(utils.handleFuncName({}, completedCallbackFunc)))) {
275
- throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
276
- }
277
- }
278
-
279
- return await faasinfra.doRequest(null, urlPath, config);
280
- }
281
-
282
- export async function createDistributedTask(dataset: any, handlerFunc: string, progressCallbackFunc: string, completedCallbackFunc: string, options: _Options): Promise<number> {
283
- if (utils.isOnlineDev()) {
284
- return await createDistributedTaskV1(dataset, handlerFunc, progressCallbackFunc, completedCallbackFunc, options);
285
- }
286
- // 检查函数是否存在
287
- utils.requireFunction(handlerFunc);
288
-
289
- // 1.获取 options
290
- let config = commonHttp.getOptions(null, faasinfraHttpPath.createDistributedTaskV2);
291
-
292
- // 2.构造url
293
- let urlPath = config._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
294
-
295
- // 3.请求
296
- config.json = {
297
- "domainName": utils.getTenantNameFromCtx(),
298
- "namespace": utils.getNamespaceFromCtx(),
299
- "userId": utils.getUserIDFromCtx(),
300
-
301
- "dataset": dataset,
302
- "handlerFunc": handlerFunc,
303
- "progressCallbackFunc": progressCallbackFunc,
304
- "completedCallbackFunc": completedCallbackFunc,
305
- "options": options,
306
- "extra": getDebugExtraInfo()
307
- }
308
-
309
- let task_id = utils.getTriggerTaskID();
310
- if (task_id) {
311
- config.json[headers.triggerTaskId] = task_id;
312
- }
313
-
314
- let loopCtx = nodeCls.get(loopCtxKey);
315
- if (checkLoopCtx(loopCtx)) {
316
- config.json[loopMasksKey] = loopCtx.loopMasks;
317
- if ((handlerFunc !== "" && config.json[loopMasksKey].includes(handlerFunc)) ||
318
- (progressCallbackFunc != "" && config.json[loopMasksKey].includes(progressCallbackFunc)) ||
319
- (completedCallbackFunc != "" && config.json[loopMasksKey].includes(completedCallbackFunc))) {
320
- throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
321
- }
322
- }
323
-
324
- return await faasinfra.doRequest(null, urlPath, config);
325
- }
326
-
327
- export async function invokeMicroserviceSync(apiName: string, path: string, method: string, body: any) {
328
- return await invokeMicroservice(apiName, path, method, body, true);
329
- }
330
-
331
- export async function invokeMicroserviceAsync(apiName: string, path: string, method: string, body: any) {
332
- return await invokeMicroservice(apiName, path, method, body, false);
333
- }
334
-
335
- async function invokeMicroservice(apiName: string, path: string, method: string, body: any, isSync = false) {
336
- let reqPath = faasinfraHttpPath.invokeMicroserviceAsync;
337
- if (isSync) {
338
- reqPath = faasinfraHttpPath.invokeMicroserviceSync;
339
- }
340
-
341
- let options = commonHttp.getOptions(null, reqPath);
342
- let urlPath = options._reqPath.replace(replaceKeys.namespace, utils.getNamespaceFromCtx());
343
-
344
- options.json = {
345
- "microserviceId": apiName,
346
- "path": path,
347
- "method": method,
348
- "query": parseQueryParams(path),
349
- }
350
-
351
- // 处理 body 参数
352
- if (method.toUpperCase() !== "GET") {
353
- options.json.body = JSON.stringify(body);
354
- }
355
-
356
- return await faasinfra.doRequest(null, urlPath, options);
357
- }
358
- */