@byted-apaas/server-sdk-node 0.0.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/LICENSE +7 -0
  2. package/NOTICE +3 -0
  3. package/README.md +1 -0
  4. package/application/application.d.ts +27 -0
  5. package/application/application.js +2 -0
  6. package/application/application.ts +40 -0
  7. package/application/function/function.d.ts +14 -0
  8. package/application/function/function.js +21 -0
  9. package/application/function/function.ts +37 -0
  10. package/application/impl/common.d.ts +2 -0
  11. package/application/impl/common.js +50 -0
  12. package/application/impl/common.ts +50 -0
  13. package/application/impl/impl.d.ts +16 -0
  14. package/application/impl/impl.js +38 -0
  15. package/application/impl/impl.ts +48 -0
  16. package/constants/constants.d.ts +10 -0
  17. package/constants/constants.js +15 -0
  18. package/constants/constants.ts +15 -0
  19. package/context/context.d.ts +74 -0
  20. package/context/context.js +25 -0
  21. package/context/context.ts +130 -0
  22. package/context/db/db.d.ts +73 -0
  23. package/context/db/db.js +4 -0
  24. package/context/db/db.ts +80 -0
  25. package/context/db/impl/IObject.d.ts +251 -0
  26. package/context/db/impl/IObject.js +5 -0
  27. package/context/db/impl/IObject.ts +247 -0
  28. package/context/db/impl/db.d.ts +61 -0
  29. package/context/db/impl/db.js +86 -0
  30. package/context/db/impl/db.ts +95 -0
  31. package/context/db/impl/object.d.ts +92 -0
  32. package/context/db/impl/object.js +524 -0
  33. package/context/db/impl/object.ts +631 -0
  34. package/context/db/impl/oql/ioql.d.ts +6 -0
  35. package/context/db/impl/oql/ioql.js +4 -0
  36. package/context/db/impl/oql/ioql.ts +9 -0
  37. package/context/db/impl/oql/oql.d.ts +8 -0
  38. package/context/db/impl/oql/oql.js +21 -0
  39. package/context/db/impl/oql/oql.ts +25 -0
  40. package/context/db/impl/order.d.ts +9 -0
  41. package/context/db/impl/order.js +15 -0
  42. package/context/db/impl/order.ts +19 -0
  43. package/context/db/impl/propertiesStore.d.ts +8 -0
  44. package/context/db/impl/propertiesStore.js +29 -0
  45. package/context/db/impl/propertiesStore.ts +31 -0
  46. package/context/db/impl/queryBuilder.d.ts +29 -0
  47. package/context/db/impl/queryBuilder.js +78 -0
  48. package/context/db/impl/queryBuilder.ts +106 -0
  49. package/context/db/impl/transaction/index.d.ts +20 -0
  50. package/context/db/impl/transaction/index.js +277 -0
  51. package/context/db/impl/transaction/index.ts +340 -0
  52. package/context/db/impl/transaction/operation.d.ts +27 -0
  53. package/context/db/impl/transaction/operation.js +69 -0
  54. package/context/db/impl/transaction/operation.ts +72 -0
  55. package/context/db/impl/transaction.d.ts +67 -0
  56. package/context/db/impl/transaction.js +4 -0
  57. package/context/db/impl/transaction.ts +79 -0
  58. package/context/globalConfig/globalConfig.d.ts +7 -0
  59. package/context/globalConfig/globalConfig.js +16 -0
  60. package/context/globalConfig/globalConfig.ts +14 -0
  61. package/context/metadata/components/common.d.ts +6 -0
  62. package/context/metadata/components/common.js +17 -0
  63. package/context/metadata/components/common.ts +22 -0
  64. package/context/metadata/components/components.d.ts +12 -0
  65. package/context/metadata/components/components.js +19 -0
  66. package/context/metadata/components/components.ts +22 -0
  67. package/context/metadata/components/desktop/list.d.ts +16 -0
  68. package/context/metadata/components/desktop/list.js +402 -0
  69. package/context/metadata/components/desktop/list.ts +457 -0
  70. package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
  71. package/context/metadata/components/desktop/recordDetail.js +53 -0
  72. package/context/metadata/components/desktop/recordDetail.ts +67 -0
  73. package/context/metadata/components/mobile/list.d.ts +24 -0
  74. package/context/metadata/components/mobile/list.js +145 -0
  75. package/context/metadata/components/mobile/list.ts +179 -0
  76. package/context/metadata/metadata.d.ts +61 -0
  77. package/context/metadata/metadata.js +103 -0
  78. package/context/metadata/metadata.ts +178 -0
  79. package/context/metadata/objects/fields.d.ts +130 -0
  80. package/context/metadata/objects/fields.js +334 -0
  81. package/context/metadata/objects/fields.ts +457 -0
  82. package/context/metadata/objects/fields.util.d.ts +40 -0
  83. package/context/metadata/objects/fields.util.js +319 -0
  84. package/context/metadata/objects/fields.util.ts +360 -0
  85. package/context/metadata/objects/objects.d.ts +11 -0
  86. package/context/metadata/objects/objects.js +20 -0
  87. package/context/metadata/objects/objects.ts +30 -0
  88. package/context/metadata/types/common.d.ts +6 -0
  89. package/context/metadata/types/common.js +9 -0
  90. package/context/metadata/types/common.ts +13 -0
  91. package/context/metadata/types/components.d.ts +90 -0
  92. package/context/metadata/types/components.js +4 -0
  93. package/context/metadata/types/components.ts +108 -0
  94. package/context/metadata/types/objects.d.ts +226 -0
  95. package/context/metadata/types/objects.js +4 -0
  96. package/context/metadata/types/objects.ts +254 -0
  97. package/context/msg/msg.d.ts +38 -0
  98. package/context/msg/msg.js +35 -0
  99. package/context/msg/msg.ts +52 -0
  100. package/context/resources/IResources.d.ts +66 -0
  101. package/context/resources/IResources.js +2 -0
  102. package/context/resources/IResources.ts +73 -0
  103. package/context/resources/impl/resources.d.ts +42 -0
  104. package/context/resources/impl/resources.js +150 -0
  105. package/context/resources/impl/resources.ts +173 -0
  106. package/context/tasks/tasks.d.ts +33 -0
  107. package/context/tasks/tasks.js +139 -0
  108. package/context/tasks/tasks.ts +159 -0
  109. package/data/index.d.ts +27 -0
  110. package/data/index.js +4 -0
  111. package/data/index.ts +30 -0
  112. package/hooks/api.d.ts +61 -0
  113. package/hooks/api.js +327 -0
  114. package/hooks/api.ts +341 -0
  115. package/hooks/hooks.d.ts +1 -0
  116. package/hooks/hooks.js +88 -0
  117. package/hooks/hooks.ts +100 -0
  118. package/kunlun/kunlun.d.ts +55 -0
  119. package/kunlun/kunlun.js +58 -0
  120. package/kunlun/kunlun.ts +72 -0
  121. package/kunlun/operator/IOperator.d.ts +158 -0
  122. package/kunlun/operator/IOperator.js +4 -0
  123. package/kunlun/operator/IOperator.ts +166 -0
  124. package/kunlun/operator/impl/expression.d.ts +47 -0
  125. package/kunlun/operator/impl/expression.js +56 -0
  126. package/kunlun/operator/impl/expression.ts +74 -0
  127. package/kunlun/operator/impl/logic.d.ts +50 -0
  128. package/kunlun/operator/impl/logic.js +509 -0
  129. package/kunlun/operator/impl/logic.ts +598 -0
  130. package/kunlun/operator/impl/logicV2.d.ts +58 -0
  131. package/kunlun/operator/impl/logicV2.js +200 -0
  132. package/kunlun/operator/impl/logicV2.ts +254 -0
  133. package/kunlun/operator/impl/operator.d.ts +179 -0
  134. package/kunlun/operator/impl/operator.js +222 -0
  135. package/kunlun/operator/impl/operator.ts +258 -0
  136. package/kunlun/operator/impl/operatorV2.d.ts +180 -0
  137. package/kunlun/operator/impl/operatorV2.js +216 -0
  138. package/kunlun/operator/impl/operatorV2.ts +249 -0
  139. package/lib/core.d.ts +4 -0
  140. package/lib/core.js +19 -0
  141. package/lib/core.ts +7 -0
  142. package/package.json +50 -0
  143. package/request/common.d.ts +13 -0
  144. package/request/common.js +87 -0
  145. package/request/common.ts +91 -0
  146. package/request/constants.d.ts +10 -0
  147. package/request/constants.js +25 -0
  148. package/request/constants.ts +25 -0
  149. package/request/faasinfra.d.ts +8 -0
  150. package/request/faasinfra.js +358 -0
  151. package/request/faasinfra.ts +393 -0
  152. package/request/innerapi.d.ts +67 -0
  153. package/request/innerapi.js +1412 -0
  154. package/request/innerapi.ts +1648 -0
  155. package/request/interface.d.ts +95 -0
  156. package/request/interface.js +41 -0
  157. package/request/interface.ts +169 -0
  158. package/request/openapi.d.ts +69 -0
  159. package/request/openapi.js +1014 -0
  160. package/request/openapi.ts +1223 -0
  161. package/types/types.d.ts +79 -0
  162. package/types/types.js +4 -0
  163. package/types/types.ts +108 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright © 2022 byted-apaas authors.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,3 @@
1
+ Authors:
2
+
3
+ ByteDance Ltd. and/or its affiliates
package/README.md ADDED
@@ -0,0 +1 @@
1
+ ## aPaaS Server SDK 版本说明:
@@ -0,0 +1,27 @@
1
+ import { _IOpenSDKResources } from "../context/resources/IResources";
2
+ import { ITool, IToolsExtra } from "@byted-apaas/server-common-node/kunlun/tool/Itool";
3
+ import { AppCredential } from "@byted-apaas/server-common-node/credential/credential";
4
+ import { IDBSync } from "../context/db/db";
5
+ import { IFunction } from "./function/function";
6
+ import { PlatformEnvType } from "@byted-apaas/server-common-node/constants/constants";
7
+ /**
8
+ * IApplication 为 OpenSDK 能力的核心接口
9
+ * - data: 元数据相关能力
10
+ * - resource: 资源相关能力
11
+ * - tools: 工具相关能力
12
+ */
13
+ export interface IApplication {
14
+ data: IDBSync;
15
+ resources: _IOpenSDKResources;
16
+ tools: ITool & IToolsExtra;
17
+ cloudfunction(funcName: string): IFunction;
18
+ env(platformEnvType: PlatformEnvType): IApplication;
19
+ localDebugMode(): IApplication;
20
+ }
21
+ export declare type AppMode = 'openSDK' | 'faasSDK';
22
+ export interface AppCtx {
23
+ mode: AppMode;
24
+ env?: PlatformEnvType;
25
+ credential: AppCredential;
26
+ debugType?: "0" | "2";
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,40 @@
1
+ import {_IOpenSDKResources} from "../context/resources/IResources";
2
+ import {ITool, IToolsExtra} from "@byted-apaas/server-common-node/kunlun/tool/Itool";
3
+ import {AppCredential} from "@byted-apaas/server-common-node/credential/credential";
4
+ import {IDBSync} from "../context/db/db";
5
+ import {IFunction} from "./function/function";
6
+ import {PlatformEnvType} from "@byted-apaas/server-common-node/constants/constants";
7
+
8
+ /**
9
+ * IApplication 为 OpenSDK 能力的核心接口
10
+ * - data: 元数据相关能力
11
+ * - resource: 资源相关能力
12
+ * - tools: 工具相关能力
13
+ */
14
+ export interface IApplication {
15
+ // data 相关能力
16
+ data: IDBSync;
17
+ // resource 相关能力
18
+ resources: _IOpenSDKResources;
19
+ // tools 相关能力
20
+ tools: ITool & IToolsExtra;
21
+
22
+ // 调用云函数能力
23
+ cloudfunction(funcName: string): IFunction;
24
+
25
+ // 设置平台环境类型
26
+ env(platformEnvType: PlatformEnvType): IApplication;
27
+
28
+ // 设置本地调试模式
29
+ localDebugMode(): IApplication;
30
+ }
31
+
32
+ export type AppMode = 'openSDK' | 'faasSDK';
33
+
34
+ export interface AppCtx {
35
+ mode: AppMode
36
+ env?: PlatformEnvType
37
+ credential: AppCredential
38
+ debugType?: "0" | "2"
39
+ }
40
+
@@ -0,0 +1,14 @@
1
+ import { AppCtx } from "../application";
2
+ export interface IFunction {
3
+ /**
4
+ * 调用函数
5
+ * @param params 函数入参
6
+ */
7
+ invoke(params: Record<string, any>): Promise<any>;
8
+ }
9
+ export declare class Function implements IFunction {
10
+ appCtx: AppCtx;
11
+ apiName: string;
12
+ constructor(appCtx: AppCtx, apiName: string);
13
+ invoke(params: Record<string, any>): Promise<any>;
14
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Function = void 0;
4
+ const interface_1 = require("../../request/interface");
5
+ const common_1 = require("../impl/common");
6
+ const crypto = require("crypto");
7
+ class Function {
8
+ constructor(appCtx, apiName) {
9
+ this.appCtx = appCtx;
10
+ this.apiName = apiName;
11
+ }
12
+ async invoke(params) {
13
+ return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
14
+ return await (0, interface_1.GetInstance)().invokeFuncWithAuth({
15
+ APIName: this.apiName,
16
+ isInvokeByAPIName: true
17
+ }, params);
18
+ });
19
+ }
20
+ }
21
+ exports.Function = Function;
@@ -0,0 +1,37 @@
1
+ import {AppCtx} from "../application";
2
+
3
+ import {GetInstance} from "../../request/interface"
4
+ import * as nodeClsCtx from "@byted-apaas/server-common-node/utils/nodeClsCtx";
5
+ import * as utils from "@byted-apaas/server-common-node/utils/utils";
6
+ import {InvalidParamError} from "@byted-apaas/server-common-node/utils/exceptions";
7
+ import {setModeForOpenSDK} from "@byted-apaas/server-common-node/utils/utils";
8
+ import {runCtxForOpenSDK} from "../impl/common";
9
+
10
+ const crypto = require("crypto")
11
+
12
+ export interface IFunction {
13
+ /**
14
+ * 调用函数
15
+ * @param params 函数入参
16
+ */
17
+ invoke(params: Record<string, any>): Promise<any>;
18
+ }
19
+
20
+ export class Function implements IFunction {
21
+ appCtx: AppCtx
22
+ apiName: string
23
+
24
+ constructor(appCtx: AppCtx, apiName: string) {
25
+ this.appCtx = appCtx
26
+ this.apiName = apiName;
27
+ }
28
+
29
+ async invoke(params: Record<string, any>): Promise<any> {
30
+ return await runCtxForOpenSDK(this.appCtx, async () => {
31
+ return await GetInstance().invokeFuncWithAuth({
32
+ APIName: this.apiName,
33
+ isInvokeByAPIName: true
34
+ }, params);
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ import { AppCtx } from "../application";
2
+ export declare function runCtxForOpenSDK(appCtx: AppCtx, promise: Function): Promise<any>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCtxForOpenSDK = void 0;
4
+ const utils = require("@byted-apaas/server-common-node/utils/utils");
5
+ const nodeClsCtx = require("@byted-apaas/server-common-node/utils/nodeClsCtx");
6
+ const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
7
+ const crypto = require("crypto");
8
+ async function runCtxForOpenSDK(appCtx, promise) {
9
+ if (appCtx && appCtx.mode === "openSDK") {
10
+ if (!appCtx.credential) {
11
+ throw new exceptions_1.InvalidParamError(`credential is empty for openSDK`);
12
+ }
13
+ return nodeClsCtx.getReqCtx().run(async () => {
14
+ utils.setModeForOpenSDK(appCtx.mode);
15
+ utils.setCredential(appCtx.credential);
16
+ utils.setDebugType(appCtx.debugType);
17
+ switch (appCtx.env) {
18
+ // @ts-ignore
19
+ case "developmentboe":
20
+ utils.setEnv('development');
21
+ utils.setBoe("boe");
22
+ break;
23
+ // @ts-ignore
24
+ case "stagingboe":
25
+ utils.setEnv('staging');
26
+ utils.setBoe("boe");
27
+ break;
28
+ case "staging":
29
+ utils.setEnv('staging');
30
+ break;
31
+ case "gray":
32
+ utils.setEnv("gray");
33
+ break;
34
+ case "online":
35
+ utils.setEnv("online");
36
+ break;
37
+ default:
38
+ throw new exceptions_1.InvalidParamError(`platformEnvType is invalid for ${appCtx.env}`);
39
+ }
40
+ utils.setInvokeFuncName("openSDK");
41
+ utils.setTenant(await appCtx.credential.getTenantInfo());
42
+ if (!utils.getLogID()) {
43
+ utils.setLogID(crypto.randomBytes(16).toString('hex'));
44
+ }
45
+ return await promise();
46
+ });
47
+ }
48
+ return await promise();
49
+ }
50
+ exports.runCtxForOpenSDK = runCtxForOpenSDK;
@@ -0,0 +1,50 @@
1
+ import {AppCtx} from "../application";
2
+ import * as utils from "@byted-apaas/server-common-node/utils/utils";
3
+ import * as nodeClsCtx from "@byted-apaas/server-common-node/utils/nodeClsCtx";
4
+ import {InvalidParamError} from "@byted-apaas/server-common-node/utils/exceptions";
5
+
6
+ const crypto = require("crypto");
7
+
8
+ export async function runCtxForOpenSDK(appCtx: AppCtx, promise: Function): Promise<any> {
9
+ if (appCtx && appCtx.mode === "openSDK") {
10
+ if (!appCtx.credential) {
11
+ throw new InvalidParamError(`credential is empty for openSDK`);
12
+ }
13
+ return nodeClsCtx.getReqCtx().run(async () => {
14
+ utils.setModeForOpenSDK(appCtx.mode);
15
+ utils.setCredential(appCtx.credential);
16
+ utils.setDebugType(appCtx.debugType);
17
+ switch (appCtx.env) {
18
+ // @ts-ignore
19
+ case "developmentboe":
20
+ utils.setEnv('development');
21
+ utils.setBoe("boe");
22
+ break;
23
+ // @ts-ignore
24
+ case "stagingboe":
25
+ utils.setEnv('staging');
26
+ utils.setBoe("boe");
27
+ break;
28
+ case "staging":
29
+ utils.setEnv('staging');
30
+ break;
31
+ case "gray":
32
+ utils.setEnv("gray");
33
+ break;
34
+ case "online":
35
+ utils.setEnv("online");
36
+ break;
37
+ default:
38
+ throw new InvalidParamError(`platformEnvType is invalid for ${appCtx.env}`);
39
+ }
40
+ utils.setInvokeFuncName("openSDK");
41
+ utils.setTenant(await appCtx.credential.getTenantInfo());
42
+ if (!utils.getLogID()) {
43
+ utils.setLogID(crypto.randomBytes(16).toString('hex'));
44
+ }
45
+ return await promise();
46
+ }
47
+ )
48
+ }
49
+ return await promise();
50
+ }
@@ -0,0 +1,16 @@
1
+ import { ITool, IToolsExtra } from "@byted-apaas/server-common-node/kunlun/tool/Itool";
2
+ import { IFunction } from "../function/function";
3
+ import { IApplication } from "../application";
4
+ import { _IOpenSDKResources } from "../../context/resources/IResources";
5
+ import { IDBSync } from "../../context/db/db";
6
+ import { PlatformEnvType } from "@byted-apaas/server-common-node/constants/constants";
7
+ export declare class Application implements IApplication {
8
+ private appCtx;
9
+ data: IDBSync;
10
+ resources: _IOpenSDKResources;
11
+ tools: ITool & IToolsExtra;
12
+ constructor(clientID: string, clientSecret: string);
13
+ cloudfunction(funcName: string): IFunction;
14
+ env(platformEnvType: PlatformEnvType): IApplication;
15
+ localDebugMode(): IApplication;
16
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Application = void 0;
4
+ const credential_1 = require("@byted-apaas/server-common-node/credential/credential");
5
+ const db_1 = require("../../context/db/impl/db");
6
+ const tool_1 = require("@byted-apaas/server-common-node/kunlun/tool/impl/tool");
7
+ const function_1 = require("../function/function");
8
+ const common_1 = require("../../request/common");
9
+ const resources_1 = require("../../context/resources/impl/resources");
10
+ class Application {
11
+ constructor(clientID, clientSecret) {
12
+ this.appCtx = {
13
+ mode: "openSDK",
14
+ credential: new credential_1.AppCredential(clientID, clientSecret),
15
+ debugType: "0",
16
+ env: "online"
17
+ };
18
+ this.data = new db_1.ApplicationDB(this.appCtx);
19
+ this.resources = new resources_1._OpenSDKResources(this.appCtx);
20
+ this.tools = new tool_1.Tool();
21
+ this.tools.getTenantInfo = async () => {
22
+ return await (0, common_1.getTenantInfo)(this.appCtx);
23
+ };
24
+ }
25
+ cloudfunction(funcName) {
26
+ return new function_1.Function(this.appCtx, funcName);
27
+ }
28
+ env(platformEnvType) {
29
+ this.appCtx.env = platformEnvType;
30
+ return this;
31
+ }
32
+ // 设置本地调试模式
33
+ localDebugMode() {
34
+ this.appCtx.debugType = "2";
35
+ return this;
36
+ }
37
+ }
38
+ exports.Application = Application;
@@ -0,0 +1,48 @@
1
+ import {ITool, IToolsExtra} from "@byted-apaas/server-common-node/kunlun/tool/Itool";
2
+ import {AppCredential} from "@byted-apaas/server-common-node/credential/credential";
3
+ import {ApplicationDB} from "../../context/db/impl/db";
4
+ import {Tool} from "@byted-apaas/server-common-node/kunlun/tool/impl/tool";
5
+ import {Function, IFunction} from "../function/function";
6
+ import {AppCtx, IApplication} from "../application";
7
+ import {getTenantInfo} from "../../request/common";
8
+ import {_IOpenSDKResources} from "../../context/resources/IResources";
9
+ import {IDBSync} from "../../context/db/db";
10
+ import {_OpenSDKResources} from "../../context/resources/impl/resources";
11
+ import {PlatformEnvType} from "@byted-apaas/server-common-node/constants/constants";
12
+
13
+ export class Application implements IApplication {
14
+ private appCtx: AppCtx;
15
+ data: IDBSync;
16
+ resources: _IOpenSDKResources;
17
+ tools: ITool & IToolsExtra;
18
+
19
+ constructor(clientID: string, clientSecret: string) {
20
+ this.appCtx = {
21
+ mode: "openSDK",
22
+ credential: new AppCredential(clientID, clientSecret),
23
+ debugType: "0",
24
+ env: "online"
25
+ }
26
+ this.data = new ApplicationDB(this.appCtx);
27
+ this.resources = new _OpenSDKResources(this.appCtx);
28
+ this.tools = new Tool();
29
+ this.tools.getTenantInfo = async () => {
30
+ return await getTenantInfo(this.appCtx);
31
+ }
32
+ }
33
+
34
+ cloudfunction(funcName: string): IFunction {
35
+ return new Function(this.appCtx, funcName);
36
+ }
37
+
38
+ env(platformEnvType: PlatformEnvType): IApplication {
39
+ this.appCtx.env = platformEnvType;
40
+ return this;
41
+ }
42
+
43
+ // 设置本地调试模式
44
+ localDebugMode(): IApplication {
45
+ this.appCtx.debugType = "2";
46
+ return this;
47
+ }
48
+ }
@@ -0,0 +1,10 @@
1
+ export declare const notifyModel: {
2
+ key: string;
3
+ };
4
+ export declare const httpHeaderKeys: {
5
+ statusCode: string;
6
+ location: string;
7
+ };
8
+ export declare const httpStatusCodes: {
9
+ redirect: number;
10
+ };
@@ -0,0 +1,15 @@
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.httpStatusCodes = exports.httpHeaderKeys = exports.notifyModel = void 0;
6
+ exports.notifyModel = {
7
+ key: "ee.kunlun.cloudfunction.faas_buildin",
8
+ };
9
+ exports.httpHeaderKeys = {
10
+ statusCode: "X-Kunlun-Status-Code",
11
+ location: "Location",
12
+ };
13
+ exports.httpStatusCodes = {
14
+ redirect: 302,
15
+ };
@@ -0,0 +1,15 @@
1
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ export const notifyModel = {
5
+ key: "ee.kunlun.cloudfunction.faas_buildin",
6
+ }
7
+
8
+ export const httpHeaderKeys = {
9
+ statusCode: "X-Kunlun-Status-Code",
10
+ location: "Location",
11
+ }
12
+
13
+ export const httpStatusCodes = {
14
+ redirect: 302,
15
+ }
@@ -0,0 +1,74 @@
1
+ import { _Resources } from "./resources/impl/resources";
2
+ import { Tasks } from "./tasks/tasks";
3
+ import { Message } from "./msg/msg";
4
+ import { IDBGetter } from "./db/db";
5
+ import { Context as CommonContext } from '@byted-apaas/server-common-node';
6
+ import { IMetaData } from "./metadata/metadata";
7
+ export declare class Context<T, mt, cf, gv> extends CommonContext<T> implements IContext<T, mt, cf, gv> {
8
+ /**
9
+ * 操作数据库中的记录数据
10
+ */
11
+ db: IDBGetter<T, mt>;
12
+ /**
13
+ * 元数据读写
14
+ */
15
+ metadata: IMetaData<mt>;
16
+ /**
17
+ * 静态资源类操作
18
+ */
19
+ resources: _Resources;
20
+ /**
21
+ * 全局函数
22
+ * @param funcName 函数名
23
+ */
24
+ function(funcName: cf): {
25
+ invoke: (params: any) => Promise<any>;
26
+ };
27
+ /**
28
+ * 任务操作
29
+ */
30
+ tasks: Tasks<cf>;
31
+ /**
32
+ * 向消息中心推送及更新消息
33
+ */
34
+ msg: Message;
35
+ /**
36
+ * 根据 apiName 获取对应的全局变量
37
+ * @param apiName 全局变量的 API Name
38
+ */
39
+ getVar<Key extends keyof gv>(apiName: Key): Promise<gv[Key]>;
40
+ }
41
+ export interface IContext<T, mt = {}, cf = "", gv = {}> {
42
+ /**
43
+ * 操作数据库中的记录数据
44
+ */
45
+ db: IDBGetter<T, mt>;
46
+ /**
47
+ * 元数据读写
48
+ */
49
+ metadata: IMetaData<mt>;
50
+ /**
51
+ * 静态资源类操作
52
+ */
53
+ resources: _Resources;
54
+ /**
55
+ * 全局函数
56
+ * @param funcName 函数名
57
+ */
58
+ function(funcName: cf): {
59
+ invoke: (params: any) => Promise<any>;
60
+ };
61
+ /**
62
+ * 任务操作
63
+ */
64
+ tasks: Tasks<cf>;
65
+ /**
66
+ * 向消息中心推送及更新消息
67
+ */
68
+ msg: Message;
69
+ /**
70
+ * 根据 apiName 获取对应的全局变量
71
+ * @param apiName 全局变量的 API Name
72
+ */
73
+ getVar<Key extends keyof gv>(apiName: Key): Promise<gv[Key]>;
74
+ }
@@ -0,0 +1,25 @@
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.Context = void 0;
6
+ const server_common_node_1 = require("@byted-apaas/server-common-node");
7
+ // TODO MERGE cf
8
+ class Context extends server_common_node_1.Context {
9
+ /**
10
+ * 全局函数
11
+ * @param funcName 函数名
12
+ */
13
+ function(funcName) {
14
+ return null;
15
+ }
16
+ /**
17
+ * 根据 apiName 获取对应的全局变量
18
+ * @param apiName 全局变量的 API Name
19
+ */
20
+ async getVar(apiName) {
21
+ return null;
22
+ }
23
+ ;
24
+ }
25
+ exports.Context = Context;
@@ -0,0 +1,130 @@
1
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { _Resources } from "./resources/impl/resources";
5
+ import { Tasks } from "./tasks/tasks";
6
+ import { Message } from "./msg/msg";
7
+ import { IDBGetter } from "./db/db";
8
+ import { Context as CommonContext } from '@byted-apaas/server-common-node'
9
+ import { IMetaData } from "./metadata/metadata";
10
+ // TODO MERGE cf
11
+
12
+ export class Context<T, mt, cf, gv> extends CommonContext<T> implements IContext<T, mt, cf, gv> {
13
+ /**
14
+ * 操作数据库中的记录数据
15
+ */
16
+ db: IDBGetter<T, mt>;
17
+ /**
18
+ * 元数据读写
19
+ */
20
+ metadata: IMetaData<mt>;
21
+ /**
22
+ * 静态资源类操作
23
+ */
24
+ resources: _Resources;
25
+
26
+ /**
27
+ * 全局函数
28
+ * @param funcName 函数名
29
+ */
30
+ function(funcName: cf): { invoke: (params: any) => Promise<any>; } {
31
+ return null;
32
+ }
33
+
34
+ /**
35
+ * 任务操作
36
+ */
37
+ tasks: Tasks<cf>;
38
+ /**
39
+ * 向消息中心推送及更新消息
40
+ */
41
+ msg: Message;
42
+
43
+ /**
44
+ * 根据 apiName 获取对应的全局变量
45
+ * @param apiName 全局变量的 API Name
46
+ */
47
+ async getVar<Key extends keyof gv>(apiName: Key): Promise<gv[Key]> {
48
+ return null;
49
+ };
50
+
51
+ // /**
52
+ // * 微服务
53
+ // * @param apiName 微服务的名称
54
+ // */
55
+ // microservice(apiName: string): {
56
+ // /**
57
+ // * 同步调用微服务
58
+ // * @param path 请求路径,如:/ping
59
+ // * @param method 请求方法,默认为 GET
60
+ // * @param params 请求参数,默认为 undefined
61
+ // */
62
+ // invoke: (path: string, method?: string, params?: any) => Promise<any>;
63
+ // /**
64
+ // * 异步调用微服务
65
+ // * @param path 请求路径,如:/ping
66
+ // * @param method 请求方法,默认为 GET
67
+ // * @param params 请求参数,默认为 undefined
68
+ // */
69
+ // invokeAsync: (path: string, method?: string, params?: any) => Promise<any>;
70
+ // } {
71
+ // return undefined;
72
+ // };
73
+ }
74
+
75
+ export interface IContext<T, mt = {}, cf = "", gv = {}> {
76
+ /**
77
+ * 操作数据库中的记录数据
78
+ */
79
+ db: IDBGetter<T, mt>;
80
+ /**
81
+ * 元数据读写
82
+ */
83
+ metadata: IMetaData<mt>;
84
+ /**
85
+ * 静态资源类操作
86
+ */
87
+ resources: _Resources;
88
+
89
+ /**
90
+ * 全局函数
91
+ * @param funcName 函数名
92
+ */
93
+ function(funcName: cf): { invoke: (params: any) => Promise<any>; };
94
+
95
+ /**
96
+ * 任务操作
97
+ */
98
+ tasks: Tasks<cf>;
99
+ /**
100
+ * 向消息中心推送及更新消息
101
+ */
102
+ msg: Message;
103
+
104
+ /**
105
+ * 根据 apiName 获取对应的全局变量
106
+ * @param apiName 全局变量的 API Name
107
+ */
108
+ getVar<Key extends keyof gv>(apiName: Key): Promise<gv[Key]>;
109
+
110
+ // /**
111
+ // * 微服务
112
+ // * @param apiName 微服务的名称
113
+ // */
114
+ // microservice(apiName: string): {
115
+ // /**
116
+ // * 同步调用微服务
117
+ // * @param path 请求路径,如:/ping
118
+ // * @param method 请求方法,默认为 GET
119
+ // * @param params 请求参数,默认为 undefined
120
+ // */
121
+ // invoke: (path: string, method?: string, params?: any) => Promise<any>;
122
+ // /**
123
+ // * 异步调用微服务
124
+ // * @param path 请求路径,如:/ping
125
+ // * @param method 请求方法,默认为 GET
126
+ // * @param params 请求参数,默认为 undefined
127
+ // */
128
+ // invokeAsync: (path: string, method?: string, params?: any) => Promise<any>;
129
+ // };
130
+ }