@byted-apaas/server-sdk-node 0.0.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +1 -0
  3. package/application/application.d.ts +27 -0
  4. package/application/application.js +3 -0
  5. package/application/application.js.map +1 -0
  6. package/application/application.ts +40 -0
  7. package/application/function/function.d.ts +14 -0
  8. package/application/function/function.js +22 -0
  9. package/application/function/function.js.map +1 -0
  10. package/application/function/function.ts +37 -0
  11. package/application/impl/common.d.ts +2 -0
  12. package/application/impl/common.js +51 -0
  13. package/application/impl/common.js.map +1 -0
  14. package/application/impl/common.ts +50 -0
  15. package/application/impl/impl.d.ts +16 -0
  16. package/application/impl/impl.js +39 -0
  17. package/application/impl/impl.js.map +1 -0
  18. package/application/impl/impl.ts +48 -0
  19. package/constants/constants.d.ts +10 -0
  20. package/constants/constants.js +14 -0
  21. package/constants/constants.js.map +1 -0
  22. package/constants/constants.ts +12 -0
  23. package/context/context.d.ts +74 -0
  24. package/context/context.js +24 -0
  25. package/context/context.js.map +1 -0
  26. package/context/context.ts +127 -0
  27. package/context/db/db.d.ts +73 -0
  28. package/context/db/db.js +3 -0
  29. package/context/db/db.js.map +1 -0
  30. package/context/db/db.ts +77 -0
  31. package/context/db/impl/IObject.d.ts +251 -0
  32. package/context/db/impl/IObject.js +4 -0
  33. package/context/db/impl/IObject.js.map +1 -0
  34. package/context/db/impl/IObject.ts +244 -0
  35. package/context/db/impl/db.d.ts +61 -0
  36. package/context/db/impl/db.js +87 -0
  37. package/context/db/impl/db.js.map +1 -0
  38. package/context/db/impl/db.ts +95 -0
  39. package/context/db/impl/object.d.ts +92 -0
  40. package/context/db/impl/object.js +523 -0
  41. package/context/db/impl/object.js.map +1 -0
  42. package/context/db/impl/object.ts +628 -0
  43. package/context/db/impl/oql/ioql.d.ts +6 -0
  44. package/context/db/impl/oql/ioql.js +3 -0
  45. package/context/db/impl/oql/ioql.js.map +1 -0
  46. package/context/db/impl/oql/ioql.ts +6 -0
  47. package/context/db/impl/oql/oql.d.ts +8 -0
  48. package/context/db/impl/oql/oql.js +20 -0
  49. package/context/db/impl/oql/oql.js.map +1 -0
  50. package/context/db/impl/oql/oql.ts +22 -0
  51. package/context/db/impl/order.d.ts +9 -0
  52. package/context/db/impl/order.js +14 -0
  53. package/context/db/impl/order.js.map +1 -0
  54. package/context/db/impl/order.ts +16 -0
  55. package/context/db/impl/propertiesStore.d.ts +8 -0
  56. package/context/db/impl/propertiesStore.js +28 -0
  57. package/context/db/impl/propertiesStore.js.map +1 -0
  58. package/context/db/impl/propertiesStore.ts +28 -0
  59. package/context/db/impl/queryBuilder.d.ts +29 -0
  60. package/context/db/impl/queryBuilder.js +77 -0
  61. package/context/db/impl/queryBuilder.js.map +1 -0
  62. package/context/db/impl/queryBuilder.ts +103 -0
  63. package/context/db/impl/transaction/index.d.ts +20 -0
  64. package/context/db/impl/transaction/index.js +276 -0
  65. package/context/db/impl/transaction/index.js.map +1 -0
  66. package/context/db/impl/transaction/index.ts +337 -0
  67. package/context/db/impl/transaction/operation.d.ts +27 -0
  68. package/context/db/impl/transaction/operation.js +70 -0
  69. package/context/db/impl/transaction/operation.js.map +1 -0
  70. package/context/db/impl/transaction/operation.ts +72 -0
  71. package/context/db/impl/transaction.d.ts +67 -0
  72. package/context/db/impl/transaction.js +3 -0
  73. package/context/db/impl/transaction.js.map +1 -0
  74. package/context/db/impl/transaction.ts +76 -0
  75. package/context/globalConfig/globalConfig.d.ts +7 -0
  76. package/context/globalConfig/globalConfig.js +15 -0
  77. package/context/globalConfig/globalConfig.js.map +1 -0
  78. package/context/globalConfig/globalConfig.ts +11 -0
  79. package/context/metadata/components/common.d.ts +6 -0
  80. package/context/metadata/components/common.js +16 -0
  81. package/context/metadata/components/common.js.map +1 -0
  82. package/context/metadata/components/common.ts +19 -0
  83. package/context/metadata/components/components.d.ts +12 -0
  84. package/context/metadata/components/components.js +18 -0
  85. package/context/metadata/components/components.js.map +1 -0
  86. package/context/metadata/components/components.ts +19 -0
  87. package/context/metadata/components/desktop/list.d.ts +16 -0
  88. package/context/metadata/components/desktop/list.js +403 -0
  89. package/context/metadata/components/desktop/list.js.map +1 -0
  90. package/context/metadata/components/desktop/list.ts +457 -0
  91. package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
  92. package/context/metadata/components/desktop/recordDetail.js +52 -0
  93. package/context/metadata/components/desktop/recordDetail.js.map +1 -0
  94. package/context/metadata/components/desktop/recordDetail.ts +64 -0
  95. package/context/metadata/components/mobile/list.d.ts +24 -0
  96. package/context/metadata/components/mobile/list.js +144 -0
  97. package/context/metadata/components/mobile/list.js.map +1 -0
  98. package/context/metadata/components/mobile/list.ts +176 -0
  99. package/context/metadata/metadata.d.ts +61 -0
  100. package/context/metadata/metadata.js +102 -0
  101. package/context/metadata/metadata.js.map +1 -0
  102. package/context/metadata/metadata.ts +175 -0
  103. package/context/metadata/objects/fields.d.ts +130 -0
  104. package/context/metadata/objects/fields.js +333 -0
  105. package/context/metadata/objects/fields.js.map +1 -0
  106. package/context/metadata/objects/fields.ts +454 -0
  107. package/context/metadata/objects/fields.util.d.ts +40 -0
  108. package/context/metadata/objects/fields.util.js +320 -0
  109. package/context/metadata/objects/fields.util.js.map +1 -0
  110. package/context/metadata/objects/fields.util.ts +360 -0
  111. package/context/metadata/objects/objects.d.ts +11 -0
  112. package/context/metadata/objects/objects.js +19 -0
  113. package/context/metadata/objects/objects.js.map +1 -0
  114. package/context/metadata/objects/objects.ts +27 -0
  115. package/context/metadata/types/common.d.ts +6 -0
  116. package/context/metadata/types/common.js +8 -0
  117. package/context/metadata/types/common.js.map +1 -0
  118. package/context/metadata/types/common.ts +10 -0
  119. package/context/metadata/types/components.d.ts +90 -0
  120. package/context/metadata/types/components.js +3 -0
  121. package/context/metadata/types/components.js.map +1 -0
  122. package/context/metadata/types/components.ts +105 -0
  123. package/context/metadata/types/objects.d.ts +226 -0
  124. package/context/metadata/types/objects.js +3 -0
  125. package/context/metadata/types/objects.js.map +1 -0
  126. package/context/metadata/types/objects.ts +251 -0
  127. package/context/msg/msg.d.ts +38 -0
  128. package/context/msg/msg.js +34 -0
  129. package/context/msg/msg.js.map +1 -0
  130. package/context/msg/msg.ts +49 -0
  131. package/context/resources/IResources.d.ts +66 -0
  132. package/context/resources/IResources.js +3 -0
  133. package/context/resources/IResources.js.map +1 -0
  134. package/context/resources/IResources.ts +73 -0
  135. package/context/resources/impl/resources.d.ts +42 -0
  136. package/context/resources/impl/resources.js +149 -0
  137. package/context/resources/impl/resources.js.map +1 -0
  138. package/context/resources/impl/resources.ts +170 -0
  139. package/context/tasks/tasks.d.ts +33 -0
  140. package/context/tasks/tasks.js +140 -0
  141. package/context/tasks/tasks.js.map +1 -0
  142. package/context/tasks/tasks.ts +159 -0
  143. package/data/index.d.ts +27 -0
  144. package/data/index.js +5 -0
  145. package/data/index.js.map +1 -0
  146. package/data/index.ts +30 -0
  147. package/hooks/api.d.ts +61 -0
  148. package/hooks/api.js +328 -0
  149. package/hooks/api.js.map +1 -0
  150. package/hooks/api.ts +341 -0
  151. package/hooks/hooks.d.ts +1 -0
  152. package/hooks/hooks.js +89 -0
  153. package/hooks/hooks.js.map +1 -0
  154. package/hooks/hooks.ts +100 -0
  155. package/kunlun/kunlun.d.ts +55 -0
  156. package/kunlun/kunlun.js +57 -0
  157. package/kunlun/kunlun.js.map +1 -0
  158. package/kunlun/kunlun.ts +69 -0
  159. package/kunlun/operator/IOperator.d.ts +158 -0
  160. package/kunlun/operator/IOperator.js +3 -0
  161. package/kunlun/operator/IOperator.js.map +1 -0
  162. package/kunlun/operator/IOperator.ts +163 -0
  163. package/kunlun/operator/impl/expression.d.ts +47 -0
  164. package/kunlun/operator/impl/expression.js +55 -0
  165. package/kunlun/operator/impl/expression.js.map +1 -0
  166. package/kunlun/operator/impl/expression.ts +71 -0
  167. package/kunlun/operator/impl/logic.d.ts +50 -0
  168. package/kunlun/operator/impl/logic.js +508 -0
  169. package/kunlun/operator/impl/logic.js.map +1 -0
  170. package/kunlun/operator/impl/logic.ts +595 -0
  171. package/kunlun/operator/impl/logicV2.d.ts +58 -0
  172. package/kunlun/operator/impl/logicV2.js +201 -0
  173. package/kunlun/operator/impl/logicV2.js.map +1 -0
  174. package/kunlun/operator/impl/logicV2.ts +254 -0
  175. package/kunlun/operator/impl/operator.d.ts +179 -0
  176. package/kunlun/operator/impl/operator.js +221 -0
  177. package/kunlun/operator/impl/operator.js.map +1 -0
  178. package/kunlun/operator/impl/operator.ts +255 -0
  179. package/kunlun/operator/impl/operatorV2.d.ts +180 -0
  180. package/kunlun/operator/impl/operatorV2.js +217 -0
  181. package/kunlun/operator/impl/operatorV2.js.map +1 -0
  182. package/kunlun/operator/impl/operatorV2.ts +249 -0
  183. package/lib/core.d.ts +4 -0
  184. package/lib/core.js +18 -0
  185. package/lib/core.js.map +1 -0
  186. package/lib/core.ts +4 -0
  187. package/package.json +50 -0
  188. package/request/common.d.ts +13 -0
  189. package/request/common.js +88 -0
  190. package/request/common.js.map +1 -0
  191. package/request/common.ts +91 -0
  192. package/request/constants.d.ts +10 -0
  193. package/request/constants.js +26 -0
  194. package/request/constants.js.map +1 -0
  195. package/request/constants.ts +25 -0
  196. package/request/faasinfra.d.ts +8 -0
  197. package/request/faasinfra.js +359 -0
  198. package/request/faasinfra.js.map +1 -0
  199. package/request/faasinfra.ts +393 -0
  200. package/request/innerapi.d.ts +67 -0
  201. package/request/innerapi.js +1411 -0
  202. package/request/innerapi.js.map +1 -0
  203. package/request/innerapi.ts +1645 -0
  204. package/request/interface.d.ts +95 -0
  205. package/request/interface.js +40 -0
  206. package/request/interface.js.map +1 -0
  207. package/request/interface.ts +166 -0
  208. package/request/openapi.d.ts +69 -0
  209. package/request/openapi.js +1013 -0
  210. package/request/openapi.js.map +1 -0
  211. package/request/openapi.ts +1220 -0
  212. package/types/types.d.ts +79 -0
  213. package/types/types.js +3 -0
  214. package/types/types.js.map +1 -0
  215. package/types/types.ts +105 -0
package/hooks/api.ts ADDED
@@ -0,0 +1,341 @@
1
+ import * as common from "@byted-apaas/server-common-node";
2
+ import {IGfCtx} from "@byted-apaas/server-common-node/context/IContext";
3
+ import {InvalidParamError} from "@byted-apaas/server-common-node/utils/exceptions";
4
+
5
+ import * as api from "../hooks/api";
6
+ import * as metadataApi from '../context/metadata/metadata'
7
+
8
+ import {Tasks} from "../context/tasks/tasks";
9
+ import {DB} from "../context/db/impl/db";
10
+ import {_Resources} from "../context/resources/impl/resources";
11
+ import {Message} from "../context/msg/msg";
12
+ import * as Request from "../request/interface"
13
+ import * as constants from "../constants/constants";
14
+ import {getRequireFunc} from "@byted-apaas/server-common-node/utils/utils";
15
+ import {IMetaData, MetaData} from "../context/metadata/metadata";
16
+ import {
17
+ ExecuteOptions,
18
+ ExecutionInfo,
19
+ ExecutionResult,
20
+ FlowTaskInfo,
21
+ RevokeExecutionOptions
22
+ } from "@byted-apaas/server-common-node/context/workflow/workflow";
23
+
24
+ const nodeCls = require("node-cls");
25
+ const nodeClsCtx = common.nodeClsCtx;
26
+ const exceptions = common.exceptions;
27
+ const utils = common.utils;
28
+ const checkUtils = common.checkUtils;
29
+ const functionSources = common.constants.functionSources;
30
+
31
+ type invokeGlobalFuncT = (funcNames: string) => { invoke: (params?: any) => Promise<any>; }
32
+
33
+ // 同步调用云函数
34
+ export function getFunctionSync(context?: any, logger?: common.Logger): invokeGlobalFuncT {
35
+ return (funcName: string) => {
36
+ if (utils.isOnlineDev()) {
37
+ let oldFuncName = funcName;
38
+ if (!utils.isMicroservice()) {
39
+ funcName = utils.handleFuncName(null, funcName);
40
+ if (!funcName) {
41
+ throw new exceptions.InvalidParamError(`The function (${oldFuncName}) does not exist, please confirm ${oldFuncName} exists and has been deployed.`);
42
+ }
43
+ } else {
44
+ funcName = undefined;
45
+ }
46
+
47
+ let idOrName: any = {};
48
+ // 2.0 通过 apiAlias 触发
49
+ if (funcName === oldFuncName) {
50
+ idOrName = {
51
+ APIName: funcName,
52
+ isInvokeByAPIName: true,
53
+ }
54
+ } else if (utils.isMicroservice()) {
55
+ // 微服务
56
+ idOrName = {
57
+ APIName: oldFuncName,
58
+ isInvokeByAPIName: true,
59
+ }
60
+ } else { // 1.0 通过 apiID 触发
61
+ idOrName = {
62
+ APIId: funcName,
63
+ isInvokeByAPIName: false,
64
+ }
65
+ }
66
+
67
+ return {
68
+ invoke: async (params?: any) => {
69
+ // 微服务的场景
70
+ if (utils.isMicroservice()) {
71
+ return await Request.GetInstance().invokeFuncSync(idOrName, params)
72
+ } else {
73
+ let func = utils.getGlobalFunc(null, funcName);
74
+ if (!func) {
75
+ // 改为远程调用
76
+ return await Request.GetInstance().invokeFuncSync(idOrName, params)
77
+ }
78
+
79
+ let loopMasks = [funcName];
80
+ let reqCtx = nodeCls.get("loopCtx");
81
+ if (reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)) {
82
+ if (reqCtx.loopMasks.includes(funcName)) {
83
+ throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
84
+ }
85
+ loopMasks.push(...reqCtx.loopMasks);
86
+ }
87
+ // 修改 source 全局函数
88
+ let ctx = nodeCls.create("loopCtx");
89
+ ctx.loopMasks = loopMasks;
90
+ return await ctx.run(async () => {
91
+ const dynCtx = nodeClsCtx.getDynCtx();
92
+ dynCtx.source = functionSources.globalFunction;
93
+ return await dynCtx.run(async () => {
94
+ return await common.hooks.invoke(func, params, context as any, logger);
95
+ });
96
+ });
97
+ }
98
+ }
99
+ };
100
+ }
101
+
102
+ return {
103
+ invoke: async (params?: any) => {
104
+ let func = getRequireFunc()(funcName);
105
+ if (!func) {
106
+ throw new exceptions.InvalidParamError(`The function (${funcName}) does not exist.`);
107
+ }
108
+
109
+ let loopMasks = [funcName];
110
+ let reqCtx = nodeCls.get("loopCtx");
111
+ if (reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)) {
112
+ if (reqCtx.loopMasks.includes(funcName)) {
113
+ throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
114
+ }
115
+ loopMasks.push(...reqCtx.loopMasks);
116
+ }
117
+ // 修改 source 全局函数
118
+ let ctx = nodeCls.create("loopCtx");
119
+ ctx.loopMasks = loopMasks;
120
+ return await ctx.run(async () => {
121
+ const dynCtx = nodeClsCtx.getDynCtx();
122
+ dynCtx.source = functionSources.globalFunction;
123
+ return await dynCtx.run(async () => {
124
+ return await common.hooks.invoke(func, params, context as any, logger);
125
+ });
126
+ });
127
+ }
128
+ };
129
+ };
130
+ }
131
+
132
+ // 设置请求头
133
+ export function setRespHeader() {
134
+ return function () {
135
+ switch (arguments.length) {
136
+ case 1:
137
+ if (checkUtils.isObject(arguments[0])) {
138
+ try {
139
+ for (let k of Object.keys(arguments[0])) {
140
+ utils.setHttpHeaders(k, toString(arguments[0][k]));
141
+ }
142
+ } catch (err) {
143
+ throw new exceptions.InternalError(err.message);
144
+ }
145
+ } else {
146
+ throw new exceptions.InvalidParamError("setResponseHeaders param is not a object");
147
+ }
148
+ break;
149
+ case 2:
150
+ try {
151
+ utils.setHttpHeaders(arguments[0], toString(arguments[1]));
152
+ } catch (err) {
153
+ throw new exceptions.InternalError(err.message);
154
+ }
155
+ break;
156
+ default:
157
+ throw new exceptions.InvalidParamError("the number of setResponseHeaders param is 1 or 2");
158
+ }
159
+ }
160
+ }
161
+
162
+ export function toString(value: any) {
163
+ if (value instanceof Array) {
164
+ let arr = [];
165
+ for (let v of value) {
166
+ if (typeof v === "string") {
167
+ arr.push(v);
168
+ } else {
169
+ arr.push(utils.stringify(v));
170
+ }
171
+ }
172
+ return arr.join(", ");
173
+ } else if (typeof value === "string") {
174
+ return value;
175
+ }
176
+ return utils.stringify(value);
177
+ }
178
+
179
+ export function setRedirectLocation(context: any) {
180
+ return function (location: string) {
181
+ context.setResponseHeader(constants.httpHeaderKeys.location, location);
182
+ context.setResponseHeader(constants.httpHeaderKeys.statusCode, String(constants.httpStatusCodes.redirect));
183
+ }
184
+ }
185
+
186
+ // 请求方法
187
+ export function method() {
188
+ return utils.getHttpMethod();
189
+ }
190
+
191
+ export function mountMetadata(context: any) {
192
+ // 1.挂载metadata
193
+ context.metadata = metadataApi.metadata(context);
194
+
195
+ // 2.挂载metaType
196
+ if (!global.kunlun) {
197
+ (global as any).kunlun = {};
198
+ }
199
+ (global as any).kunlun.metaType = metadataApi.metaType();
200
+ }
201
+
202
+ export function mountWorkflowFeature(context: any) {
203
+ if (context && context.workflow) {
204
+ context.workflow.updateVariable = common.updateVariable(context, Request.GetInstance().updateWorkflowVariables);
205
+ } else {
206
+ context.workflow = {};
207
+ }
208
+ // 此处挂载保证了 terminate 存在
209
+ context.workflow.terminate = terminateWorkflow();
210
+ }
211
+
212
+ export function terminateWorkflow() {
213
+ return async (workflowInstanceId: number, options: any) => {
214
+ let operator: number = utils.getUser()._id, reason: string = null;
215
+ if (options && options.reason) {
216
+ // instanceof 改动5
217
+ // if (options.reason instanceof common.fieldType.Multilingual) {
218
+ if (common.fieldType.isKFieldTypeMultilingual(options.reason)) {
219
+ reason = options.reason.toString();
220
+ } else {
221
+ reason = new common.fieldType.Multilingual(options.reason).toString();
222
+ }
223
+ }
224
+
225
+ await Request.GetInstance().terminateWorkflowInstance(workflowInstanceId, operator, reason);
226
+ };
227
+ }
228
+
229
+ export function mockFlowFeature(context: any) {
230
+ if (!context.flow) {
231
+ context.flow = {};
232
+ }
233
+
234
+ context.flow.updateVariable = common.updateVariable(context, Request.GetInstance().updateWorkflowVariables);
235
+
236
+ context.flow.getExecutionUserTaskInfo = mockGetExecutionUserTaskInfo();
237
+
238
+ context.flow.execute = mockExecuteFlow();
239
+ context.flow.revokeExecution = mockRevokeExecution();
240
+ context.flow.getExecutionInfo = mockGetExecutionInfo();
241
+ return context.flow;
242
+ }
243
+
244
+ function mockGetExecutionUserTaskInfo() {
245
+ return async (executionId: bigint): Promise<FlowTaskInfo[]> => {
246
+ if (!executionId || typeof executionId !== "number") {
247
+ throw new InvalidParamError(`param's type (${executionId}) need number, but is ${typeof executionId}`);
248
+ }
249
+ return await Request.GetInstance().getExecutionUserTaskInfo(executionId);
250
+ };
251
+ }
252
+
253
+ function mockExecuteFlow() {
254
+ return async (APIName: string, options?: ExecuteOptions): Promise<ExecutionResult> => {
255
+ if (!APIName || typeof APIName !== "string") {
256
+ throw new InvalidParamError(`param's type (${APIName}) need string, but is ${typeof APIName}`);
257
+ }
258
+ if (options && options.params && checkUtils.isNotObject(options.params)) {
259
+ throw new InvalidParamError(`options.params's type (${options}) need object, but is ${Array.isArray(options) ? "array" : typeof options.params}`);
260
+ }
261
+ if (!options) {
262
+ options = {} as any;
263
+ }
264
+ return await Request.GetInstance().executeFlow(APIName, options);
265
+ };
266
+ }
267
+
268
+ function mockRevokeExecution() {
269
+ return async (executionId: number, options: RevokeExecutionOptions): Promise<void> => {
270
+ if (!executionId || typeof executionId !== "number") {
271
+ throw new InvalidParamError(`param's type (${executionId}) is need number, but is ${typeof executionId}`);
272
+ }
273
+ return await Request.GetInstance().revokeExecution(executionId, options);
274
+ };
275
+ }
276
+
277
+ function mockGetExecutionInfo() {
278
+ return async (executionId: number): Promise<ExecutionInfo> => {
279
+ if (!executionId || typeof executionId !== "number") {
280
+ throw new InvalidParamError(`param's type (${executionId}) is not matched to number, but is ${typeof executionId}`);
281
+ }
282
+ return await Request.GetInstance().getExecutionInfo(executionId);
283
+ };
284
+ }
285
+
286
+ export function invokeMicroservice() {
287
+ /**
288
+ * 微服务
289
+ * @param apiName 微服务的名称
290
+ */
291
+ return function (apiName: string) {
292
+ if (!apiName || typeof (apiName) !== "string") {
293
+ throw new InvalidParamError(`The apiName (${apiName}) is invalid and should be a non-empty field string.`);
294
+ }
295
+
296
+ return {
297
+ /**
298
+ * 同步调用微服务
299
+ * @param path 请求路径,如:/ping
300
+ * @param method 请求方法,默认为 GET
301
+ * @param params 请求参数,默认为 undefined
302
+ */
303
+ invoke: async function (path: string, method: string = "GET", params: any = undefined) {
304
+ if (!path || typeof (path) !== "string") {
305
+ throw new InvalidParamError(`The path (${path}) is invalid and should be a non-empty field string.`);
306
+ }
307
+ if (!method || typeof (method) !== "string") {
308
+ throw new InvalidParamError(`The method (${method}) is invalid and should be a non-empty field string.`);
309
+ }
310
+ return await Request.GetFaaSInfraInstance().invokeMicroserviceSync(apiName, path, method, params);
311
+ },
312
+ /**
313
+ * 异步调用微服务
314
+ * @param path 请求路径,如:/ping
315
+ * @param method 请求方法,默认为 GET
316
+ * @param params 请求参数,默认为 undefined
317
+ */
318
+ invokeAsync: async function (path: string, method: string = "GET", params: any = undefined) {
319
+ if (!path || typeof (path) !== "string") {
320
+ throw new InvalidParamError(`The path (${path}) is invalid and should be a non-empty field string.`);
321
+ }
322
+ if (!method || typeof (method) !== "string") {
323
+ throw new InvalidParamError(`The method (${method}) is invalid and should be a non-empty field string.`);
324
+ }
325
+ return await Request.GetFaaSInfraInstance().invokeMicroserviceAsync(apiName, path, method, params);
326
+ },
327
+ };
328
+ };
329
+ }
330
+
331
+ export const db = new DB<IGfCtx>();
332
+ export const resources = new _Resources();
333
+ export const msg = new Message();
334
+ export const tasks = new Tasks();
335
+ export const cloudfunction = api.getFunctionSync();
336
+ export const microservice = api.invokeMicroservice();
337
+ export const workflow = {
338
+ terminate: terminateWorkflow(),
339
+ };
340
+ export const metaData: IMetaData<{}> = new MetaData<{}>(null)
341
+ export {Application} from "../application/impl/impl";
@@ -0,0 +1 @@
1
+ export {};
package/hooks/hooks.js ADDED
@@ -0,0 +1,89 @@
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 constants_1 = require("@byted-apaas/server-common-node/constants/constants");
10
+ const db_1 = require("../context/db/impl/db");
11
+ const common_1 = require("../request/common");
12
+ /**
13
+ * 根据 key 获取对应的全局变量
14
+ * @param key 全局变量的 key
15
+ */
16
+ function getVar(key) {
17
+ return server_common_node_1.utils.getGlobalVariableByKey(key);
18
+ }
19
+ function pre(params, context, logger, requireFunc) {
20
+ // 初始化 kunlun
21
+ if (!global.kunlun) {
22
+ // 缺省的情况,先对 kunlun 进行初始化
23
+ global.kunlun = {};
24
+ }
25
+ global.kunlun.operator = new operator_1.Operator();
26
+ global.kunlun.getVar = getVar;
27
+ global.kunlun.tool.getTenantInfo = common_1.getTenantInfo;
28
+ // 对 context 下的能力进行初始化
29
+ mountContext(context, logger, requireFunc);
30
+ }
31
+ /**
32
+ * mountContext 函数用于初始化 context 在 core 包中实现的部分,包括:
33
+ * - db
34
+ * - (global function 场景下): setRespHeader, setRedirectLocation
35
+ * - task, function, msg, resources
36
+ * @param context 系统代理函数中经由 common 创建的用户 context,根据 source 分为不同类型
37
+ * @param logger Logger
38
+ * @param requireFunc
39
+ */
40
+ function mountContext(context, logger, requireFunc) {
41
+ const source = server_common_node_1.utils.getSource();
42
+ // 1. 根据不同调用场景差异化初始化内容
43
+ // - db 是否包含 currentObject,transaction 是否包含 currentObject
44
+ // - global function 场景需要初始化 setRespHeader 和 RedirectLocation 方法,以及 method 属性
45
+ switch (source) {
46
+ case constants_1.functionSources.workflow:
47
+ context.db = new db_1.DBWithCurrentObject(context.objectApiName);
48
+ break;
49
+ case constants_1.functionSources.globalFunction:
50
+ context.db = new db_1.DBWithCurrentObject(null);
51
+ // set response headers
52
+ context.setResponseHeader = api.setRespHeader();
53
+ context.setRedirectLocation = api.setRedirectLocation(context);
54
+ // 暴露context.method属性
55
+ context.method = server_common_node_1.utils.getHttpMethod();
56
+ break;
57
+ case constants_1.functionSources.recordAutomation:
58
+ context.db = new db_1.DBWithCurrentObject(context.objectApiName);
59
+ break;
60
+ case constants_1.functionSources.scheduleAutomation:
61
+ context.db = new db_1.DBWithCurrentObject(null);
62
+ break;
63
+ default:
64
+ throw new server_common_node_1.exceptions.InvalidParamError(`This npm package does not contain this source ${source}`);
65
+ }
66
+ // 2. 初始化 core 包中需要初始化的内容,因此强转为 IContext 类型
67
+ // - function
68
+ // - tasks
69
+ // - msg
70
+ // - resources
71
+ // - microservice
72
+ // - getVar
73
+ context.function = api.getFunctionSync(context, logger);
74
+ context.tasks = new tasks_1.Tasks(context.function);
75
+ context.msg = new msg_1.Message();
76
+ context.resources = new resources_1._Resources();
77
+ context.getVar = getVar;
78
+ context.microservice = api.invokeMicroservice();
79
+ api.mountWorkflowFeature(context);
80
+ // 挂载 metadata
81
+ api.mountMetadata(context);
82
+ api.mockFlowFeature(context);
83
+ // 防止 context.function 被串改
84
+ Object.freeze(context.function);
85
+ }
86
+ module.exports = {
87
+ pre,
88
+ };
89
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["hooks.ts"],"names":[],"mappings":"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"}
package/hooks/hooks.ts ADDED
@@ -0,0 +1,100 @@
1
+ import * as common from "@byted-apaas/server-common-node";
2
+ import { IContext } from "../context/context";
3
+ import { _Resources } from "../context/resources/impl/resources";
4
+ import { Tasks } from "../context/tasks/tasks";
5
+ import { Message } from "../context/msg/msg";
6
+ import { exceptions, utils } from '@byted-apaas/server-common-node'
7
+ import * as api from './api'
8
+ import { Operator } from "../kunlun/operator/impl/operator";
9
+ import { functionSources } from "@byted-apaas/server-common-node/constants/constants";
10
+ import { IWfCtx, IGfCtx, IRaCtx, ISaCtx } from '@byted-apaas/server-common-node/context/IContext'
11
+ import { DBWithCurrentObject } from "../context/db/impl/db";
12
+ import { getTenantInfo } from "../request/common";
13
+
14
+ type AllICtx = IGfCtx | IWfCtx | IRaCtx | ISaCtx;
15
+
16
+ /**
17
+ * 根据 key 获取对应的全局变量
18
+ * @param key 全局变量的 key
19
+ */
20
+ function getVar(key: string): string | number | number[] {
21
+ return utils.getGlobalVariableByKey(key);
22
+ }
23
+
24
+ function pre(params: any, context: AllICtx, logger: common.Logger, requireFunc: Function) {
25
+ // 初始化 kunlun
26
+ if (!global.kunlun) {
27
+ // 缺省的情况,先对 kunlun 进行初始化
28
+ (global as any).kunlun = {}
29
+ }
30
+ global.kunlun.operator = new Operator();
31
+ ((global.kunlun as any).getVar as any) = getVar;
32
+ ((global.kunlun as any).tool as any).getTenantInfo = getTenantInfo as any;
33
+ // 对 context 下的能力进行初始化
34
+ mountContext(context, logger, requireFunc);
35
+ }
36
+
37
+ /**
38
+ * mountContext 函数用于初始化 context 在 core 包中实现的部分,包括:
39
+ * - db
40
+ * - (global function 场景下): setRespHeader, setRedirectLocation
41
+ * - task, function, msg, resources
42
+ * @param context 系统代理函数中经由 common 创建的用户 context,根据 source 分为不同类型
43
+ * @param logger Logger
44
+ * @param requireFunc
45
+ */
46
+ function mountContext(context: AllICtx, logger: common.Logger, requireFunc: Function) {
47
+ const source: string = utils.getSource();
48
+
49
+ // 1. 根据不同调用场景差异化初始化内容
50
+ // - db 是否包含 currentObject,transaction 是否包含 currentObject
51
+ // - global function 场景需要初始化 setRespHeader 和 RedirectLocation 方法,以及 method 属性
52
+ switch (source) {
53
+ case functionSources.workflow:
54
+ (context as IContext<IWfCtx> & IWfCtx).db = new DBWithCurrentObject<IWfCtx>((context as IWfCtx).objectApiName)
55
+ break;
56
+ case functionSources.globalFunction:
57
+ (context as IContext<IGfCtx> & IGfCtx).db = new DBWithCurrentObject<IGfCtx>(null);
58
+
59
+ // set response headers
60
+ (context as IGfCtx).setResponseHeader = api.setRespHeader();
61
+ (context as IGfCtx).setRedirectLocation = api.setRedirectLocation(context as IGfCtx);
62
+
63
+ // 暴露context.method属性
64
+ (context as IGfCtx).method = utils.getHttpMethod();
65
+ break;
66
+ case functionSources.recordAutomation:
67
+ (context as IContext<IRaCtx> & IRaCtx).db = new DBWithCurrentObject<IRaCtx>((context as IRaCtx).objectApiName)
68
+ break;
69
+ case functionSources.scheduleAutomation:
70
+ (context as IContext<ISaCtx> & ISaCtx).db = new DBWithCurrentObject<ISaCtx>(null)
71
+ break;
72
+ default:
73
+ throw new exceptions.InvalidParamError(`This npm package does not contain this source ${source}`)
74
+ }
75
+
76
+ // 2. 初始化 core 包中需要初始化的内容,因此强转为 IContext 类型
77
+ // - function
78
+ // - tasks
79
+ // - msg
80
+ // - resources
81
+ // - microservice
82
+ // - getVar
83
+ (context as unknown as IContext<null>).function = api.getFunctionSync(context, logger);
84
+ (context as unknown as IContext<null>).tasks = new Tasks((context as unknown as IContext<null>).function);
85
+ (context as unknown as IContext<null>).msg = new Message();
86
+ (context as unknown as IContext<null>).resources = new _Resources();
87
+ ((context as unknown as IContext<null>).getVar as any) = getVar;
88
+ (context as any).microservice = api.invokeMicroservice();
89
+ api.mountWorkflowFeature(context);
90
+ // 挂载 metadata
91
+ api.mountMetadata(context);
92
+ api.mockFlowFeature(context as any);
93
+
94
+ // 防止 context.function 被串改
95
+ Object.freeze((context as unknown as IContext<null>).function);
96
+ }
97
+
98
+ module.exports = {
99
+ pre,
100
+ }
@@ -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
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kunlun = void 0;
4
+ const timeZone_1 = require("@byted-apaas/server-common-node/constants/timeZone");
5
+ const countryCode_1 = require("@byted-apaas/server-common-node/constants/countryCode");
6
+ const tool_1 = require("@byted-apaas/server-common-node/kunlun/tool/impl/tool");
7
+ const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
8
+ const operator_1 = require("./operator/impl/operator");
9
+ const common = require("@byted-apaas/server-common-node");
10
+ const Request = require("../request/interface");
11
+ var kunlun;
12
+ (function (kunlun) {
13
+ /**
14
+ * 引用时区信息
15
+ */
16
+ kunlun.GMTOffset = timeZone_1.GMTOffset;
17
+ /**
18
+ * 引用国际区号
19
+ */
20
+ kunlun.countryCode = countryCode_1.area2code;
21
+ /**
22
+ * 工具方法
23
+ */
24
+ kunlun.tool = new tool_1.Tool();
25
+ /**
26
+ * 生成复杂数据结构
27
+ */
28
+ let type;
29
+ (function (type) {
30
+ type.Multilingual = common.fieldType.Multilingual;
31
+ type.Phone = common.fieldType.Phone;
32
+ type.Date = common.fieldType.Date;
33
+ type.DateTime = common.fieldType.DateTime;
34
+ })(type = kunlun.type || (kunlun.type = {}));
35
+ /**
36
+ * 错误码
37
+ */
38
+ kunlun.errorCode = {
39
+ /**
40
+ * 限流错误码
41
+ */
42
+ RATE_LIMIT_ERROR: exceptions_1.errCodes.RATE_LIMIT_ERROR,
43
+ };
44
+ /**
45
+ * 根据 key 获取对应的全局变量
46
+ * @param key 全局变量的 key
47
+ */
48
+ async function getVar(key) {
49
+ return await Request.GetInstance().getGlobalConfigByKey(key);
50
+ }
51
+ kunlun.getVar = getVar;
52
+ /**
53
+ * 指令操作符
54
+ */
55
+ kunlun.operator = new operator_1.Operator();
56
+ })(kunlun = exports.kunlun || (exports.kunlun = {}));
57
+ //# sourceMappingURL=kunlun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kunlun.js","sourceRoot":"","sources":["kunlun.ts"],"names":[],"mappings":";;;AAEA,iFAAsF;AACtF,uFAAkF;AAElF,gFAA6E;AAC7E,iFAA4E;AAC5E,uDAAoD;AACpD,0DAA0D;AAC1D,gDAAgD;AAWhD,IAAiB,MAAM,CAgDtB;AAhDD,WAAiB,MAAM;IACnB;;OAEG;IACU,gBAAS,GAAe,oBAAG,CAAC;IAEzC;;OAEG;IACU,kBAAW,GAAqB,uBAAS,CAAC;IAEvD;;OAEG;IACQ,WAAI,GAAwB,IAAI,WAAI,EAAE,CAAC;IAElD;;OAEG;IACH,IAAiB,IAAI,CAKpB;IALD,WAAiB,IAAI;QACH,iBAAY,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAA;QAC5C,UAAK,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAA;QAC9B,SAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAA;QAC5B,aAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAA;IACtD,CAAC,EALgB,IAAI,GAAJ,WAAI,KAAJ,WAAI,QAKpB;IAED;;OAEG;IACU,gBAAS,GAAG;QACrB;;WAEG;QACH,gBAAgB,EAAE,qBAAQ,CAAC,gBAAgB;KAC9C,CAAA;IAED;;;OAGG;IACI,KAAK,UAAU,MAAM,CAAC,GAAW;QACpC,OAAO,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACjE,CAAC;IAFqB,aAAM,SAE3B,CAAA;IAED;;OAEG;IACU,eAAQ,GAAc,IAAI,mBAAQ,EAAE,CAAC;AACtD,CAAC,EAhDgB,MAAM,GAAN,cAAM,KAAN,cAAM,QAgDtB"}