@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
@@ -0,0 +1,150 @@
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._Resources = exports._OpenSDKResources = exports._KunlunFile = exports._KunlunOpenSDKFile = void 0;
6
+ const stream_1 = require("stream");
7
+ const Request = require("../../../request/interface");
8
+ const common_1 = require("../../../application/impl/common");
9
+ const common = require("@byted-apaas/server-common-node");
10
+ const stream_to_buffer_1 = require("@jorgeferrero/stream-to-buffer");
11
+ const exceptions = common.exceptions;
12
+ const fs = require('fs');
13
+ class _KunlunOpenSDKFile {
14
+ constructor(appCtx) {
15
+ this.appCtx = appCtx;
16
+ }
17
+ async Upload(fileName, source) {
18
+ // 1. check parameters type
19
+ if (typeof fileName !== 'string') {
20
+ throw new exceptions.InvalidParamError('upload method parameter fileName must be string. ');
21
+ }
22
+ if (typeof source !== 'string' && !(source instanceof stream_1.Stream) && !(source instanceof Buffer)) {
23
+ throw new exceptions.InvalidParamError('upload method parameter source must be string or stream or buffer. ');
24
+ }
25
+ // 2. divide by source type
26
+ if (typeof source === 'string') {
27
+ // upload from path
28
+ if (!fs.existsSync(source)) {
29
+ throw new exceptions.InvalidParamError(`no such file '${source}'`);
30
+ }
31
+ source = fs.createReadStream(source);
32
+ }
33
+ if (source instanceof stream_1.Stream) {
34
+ // upload from stream
35
+ source = await (0, stream_to_buffer_1.streamToBuffer)(source);
36
+ }
37
+ if (source instanceof Buffer) {
38
+ return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
39
+ return await Request.GetInstance().openSDKUploadFile(fileName, source);
40
+ });
41
+ }
42
+ return null;
43
+ }
44
+ ;
45
+ async UploadAvatar(fileName, source) {
46
+ // 1. check parameters type
47
+ if (typeof fileName !== 'string') {
48
+ throw new exceptions.InvalidParamError('upload method parameter fileName must be string. ');
49
+ }
50
+ if (typeof source !== 'string' && !(source instanceof stream_1.Stream) && !(source instanceof Buffer)) {
51
+ throw new exceptions.InvalidParamError('upload method parameter source must be string or stream or buffer. ');
52
+ }
53
+ // 2. divide by source type
54
+ if (typeof source === 'string') {
55
+ // upload from path
56
+ if (!fs.existsSync(source)) {
57
+ throw new exceptions.InvalidParamError(`no such file '${source}'`);
58
+ }
59
+ source = fs.createReadStream(source);
60
+ }
61
+ if (source instanceof stream_1.Stream) {
62
+ // upload from stream
63
+ source = await (0, stream_to_buffer_1.streamToBuffer)(source);
64
+ }
65
+ if (source instanceof Buffer) {
66
+ // upload from buffer
67
+ return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
68
+ return await Request.GetInstance().openSDKUploadAvatar(fileName, source);
69
+ });
70
+ }
71
+ return null;
72
+ }
73
+ ;
74
+ async Download(fileID) {
75
+ // 1. check parameters type
76
+ if (typeof fileID !== 'string') {
77
+ throw new exceptions.InvalidParamError('download method parameter fileID must be string. ');
78
+ }
79
+ return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
80
+ return await Request.GetInstance().downloadFileByID(fileID);
81
+ });
82
+ }
83
+ ;
84
+ async DownloadAvatar(imageID) {
85
+ // 1. check parameters type
86
+ if (typeof imageID !== 'string') {
87
+ throw new exceptions.InvalidParamError('download method parameter imageID must be string. ');
88
+ }
89
+ return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
90
+ return await Request.GetInstance().openSDKDownloadAvatar(imageID);
91
+ });
92
+ }
93
+ ;
94
+ }
95
+ exports._KunlunOpenSDKFile = _KunlunOpenSDKFile;
96
+ class _KunlunFile {
97
+ async download(fileTokenOrInfo, filePath) {
98
+ if (typeof (fileTokenOrInfo) === "string") {
99
+ return await Request.GetInstance().downloadFileByToken(fileTokenOrInfo, filePath);
100
+ }
101
+ else if (typeof (fileTokenOrInfo) === "object") {
102
+ if (!fileTokenOrInfo.id) {
103
+ throw new exceptions.InvalidParamError(`The value of fileInfo.id is empty`);
104
+ }
105
+ if (typeof (fileTokenOrInfo.id) !== "string") {
106
+ throw new exceptions.InvalidParamError(`The type of fileInfo.id should be string, but ${typeof (fileTokenOrInfo)}`);
107
+ }
108
+ return await Request.GetInstance().downloadFileByID(fileTokenOrInfo.id, filePath);
109
+ }
110
+ else {
111
+ throw new exceptions.InvalidParamError(`The type of first param should be string or object, but ${typeof (fileTokenOrInfo)}`);
112
+ }
113
+ }
114
+ async upload(data, expire, ...ret) {
115
+ if (ret.length > 0) {
116
+ throw new exceptions.InvalidParamError(`params is too many, as ${ret.length + 2}`);
117
+ }
118
+ if (!data) {
119
+ throw new exceptions.InvalidParamError(`params is null`);
120
+ }
121
+ // 1. data is filePath, read it from disk, convert it to Steam.
122
+ if (typeof (data) === 'string') {
123
+ if (!fs.existsSync(data)) {
124
+ throw new exceptions.InvalidParamError(`no such file '${data}'`);
125
+ }
126
+ data = fs.createReadStream(data);
127
+ }
128
+ // 2. data must be Stream at here.
129
+ return await Request.GetInstance().uploadFile(data, expire);
130
+ }
131
+ }
132
+ exports._KunlunFile = _KunlunFile;
133
+ /**
134
+ * OpenSDK 静态资源操作类
135
+ */
136
+ class _OpenSDKResources {
137
+ constructor(appCtx) {
138
+ this.file = new _KunlunOpenSDKFile(appCtx);
139
+ }
140
+ }
141
+ exports._OpenSDKResources = _OpenSDKResources;
142
+ /**
143
+ * 静态资源操作类
144
+ */
145
+ class _Resources {
146
+ constructor() {
147
+ this.file = new _KunlunFile();
148
+ }
149
+ }
150
+ exports._Resources = _Resources;
@@ -0,0 +1,173 @@
1
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Stream } from "stream";
5
+ import { _FileInfo, _IKunlunFile, _IOpenSDKFile, UploadAvatarResult, FileUploadResult } from "../IResources";
6
+ import * as Request from "../../../request/interface";
7
+ import { runCtxForOpenSDK } from "../../../application/impl/common";
8
+ import * as common from "@byted-apaas/server-common-node"
9
+ import { AppCtx } from "../../../application/application";
10
+ import { streamToBuffer } from "@jorgeferrero/stream-to-buffer";
11
+
12
+ const exceptions = common.exceptions;
13
+
14
+ const fs = require('fs');
15
+
16
+ export class _KunlunOpenSDKFile implements _IOpenSDKFile {
17
+ appCtx: AppCtx
18
+
19
+ constructor(appCtx: AppCtx) {
20
+ this.appCtx = appCtx;
21
+ }
22
+
23
+ async Upload(fileName: string, path: string): Promise<FileUploadResult>;
24
+ async Upload(fileName: string, reader: Stream): Promise<FileUploadResult>;
25
+ async Upload(fileName: string, buffer: Buffer): Promise<FileUploadResult>;
26
+ async Upload(fileName: string, source: string | Stream | Buffer): Promise<FileUploadResult> {
27
+ // 1. check parameters type
28
+ if (typeof fileName !== 'string') {
29
+ throw new exceptions.InvalidParamError('upload method parameter fileName must be string. ');
30
+ }
31
+ if (typeof source !== 'string' && !(source instanceof Stream) && !(source instanceof Buffer)) {
32
+ throw new exceptions.InvalidParamError('upload method parameter source must be string or stream or buffer. ');
33
+ }
34
+ // 2. divide by source type
35
+ if (typeof source === 'string') {
36
+ // upload from path
37
+ if (!fs.existsSync(source)) {
38
+ throw new exceptions.InvalidParamError(`no such file '${source}'`)
39
+ }
40
+ source = fs.createReadStream(source);
41
+ }
42
+ if (source instanceof Stream) {
43
+ // upload from stream
44
+ source = await streamToBuffer(source as any);
45
+ }
46
+ if (source instanceof Buffer) {
47
+ return await runCtxForOpenSDK(this.appCtx, async () => {
48
+ return await Request.GetInstance().openSDKUploadFile(fileName, source as Buffer);
49
+ });
50
+ }
51
+ return null;
52
+ };
53
+ async UploadAvatar(fileName: string, path: string): Promise<UploadAvatarResult>;
54
+ async UploadAvatar(fileName: string, reader: Stream): Promise<UploadAvatarResult>;
55
+ async UploadAvatar(fileName: string, buffer: Buffer): Promise<UploadAvatarResult>;
56
+ async UploadAvatar(fileName: string, source: string | Stream | Buffer): Promise<UploadAvatarResult> {
57
+ // 1. check parameters type
58
+ if (typeof fileName !== 'string') {
59
+ throw new exceptions.InvalidParamError('upload method parameter fileName must be string. ');
60
+ }
61
+ if (typeof source !== 'string' && !(source instanceof Stream) && !(source instanceof Buffer)) {
62
+ throw new exceptions.InvalidParamError('upload method parameter source must be string or stream or buffer. ');
63
+ }
64
+ // 2. divide by source type
65
+ if (typeof source === 'string') {
66
+ // upload from path
67
+ if (!fs.existsSync(source)) {
68
+ throw new exceptions.InvalidParamError(`no such file '${source}'`)
69
+ }
70
+ source = fs.createReadStream(source);
71
+ }
72
+ if (source instanceof Stream) {
73
+ // upload from stream
74
+ source = await streamToBuffer(source as any);
75
+ }
76
+ if (source instanceof Buffer) {
77
+ // upload from buffer
78
+ return await runCtxForOpenSDK(this.appCtx, async () => {
79
+ return await Request.GetInstance().openSDKUploadAvatar(fileName, source as Buffer);
80
+ })
81
+ }
82
+ return null;
83
+ };
84
+ async Download(fileID: string): Promise<Buffer> {
85
+ // 1. check parameters type
86
+ if (typeof fileID !== 'string') {
87
+ throw new exceptions.InvalidParamError('download method parameter fileID must be string. ');
88
+ }
89
+ return await runCtxForOpenSDK(this.appCtx, async () => {
90
+ return await Request.GetInstance().downloadFileByID(fileID) as Buffer;
91
+ })
92
+ };
93
+ async DownloadAvatar(imageID: string): Promise<Buffer> {
94
+ // 1. check parameters type
95
+ if (typeof imageID !== 'string') {
96
+ throw new exceptions.InvalidParamError('download method parameter imageID must be string. ');
97
+ }
98
+ return await runCtxForOpenSDK(this.appCtx, async () => {
99
+ return await Request.GetInstance().openSDKDownloadAvatar(imageID) as Buffer;
100
+ })
101
+ };
102
+ }
103
+
104
+ export class _KunlunFile implements _IKunlunFile {
105
+ async download(fileToken: string): Promise<Buffer>;
106
+ async download(fileToken: string, filePath?: string): Promise<void>;
107
+ async download(fileToken: _FileInfo): Promise<Buffer>;
108
+ async download(fileInfo: _FileInfo, filePath: string): Promise<void>;
109
+ async download(fileTokenOrInfo: string | _FileInfo, filePath?: string): Promise<Buffer | void> {
110
+ if (typeof (fileTokenOrInfo) === "string") {
111
+ return await Request.GetInstance().downloadFileByToken(fileTokenOrInfo, filePath);
112
+ } else if (typeof (fileTokenOrInfo) === "object") {
113
+ if (!fileTokenOrInfo.id) {
114
+ throw new exceptions.InvalidParamError(`The value of fileInfo.id is empty`);
115
+ }
116
+
117
+ if (typeof (fileTokenOrInfo.id) !== "string") {
118
+ throw new exceptions.InvalidParamError(`The type of fileInfo.id should be string, but ${typeof (fileTokenOrInfo)}`);
119
+ }
120
+ return await Request.GetInstance().downloadFileByID(fileTokenOrInfo.id, filePath);
121
+ } else {
122
+ throw new exceptions.InvalidParamError(`The type of first param should be string or object, but ${typeof (fileTokenOrInfo)}`);
123
+ }
124
+ }
125
+
126
+ async upload(filePath: string): Promise<Request.UploadFileResp>;
127
+ async upload(stream: Stream): Promise<Request.UploadFileResp>;
128
+ async upload(filePath: string, expire: number): Promise<Request.UploadFileResp>;
129
+ async upload(stream: Stream, expire: number): Promise<Request.UploadFileResp>;
130
+ async upload(data: string | Stream, expire?: number, ...ret: string[]): Promise<Request.UploadFileResp> {
131
+ if (ret.length > 0) {
132
+ throw new exceptions.InvalidParamError(`params is too many, as ${ret.length + 2}`)
133
+ }
134
+ if (!data) {
135
+ throw new exceptions.InvalidParamError(`params is null`)
136
+ }
137
+
138
+ // 1. data is filePath, read it from disk, convert it to Steam.
139
+ if (typeof (data) === 'string') {
140
+ if (!fs.existsSync(data)) {
141
+ throw new exceptions.InvalidParamError(`no such file '${data}'`)
142
+ }
143
+ data = fs.createReadStream(data);
144
+ }
145
+
146
+ // 2. data must be Stream at here.
147
+ return await Request.GetInstance().uploadFile(data as Stream, expire);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * OpenSDK 静态资源操作类
153
+ */
154
+ export class _OpenSDKResources {
155
+ file: _IOpenSDKFile;
156
+
157
+ constructor(appCtx: AppCtx) {
158
+ this.file = new _KunlunOpenSDKFile(appCtx);
159
+ }
160
+ }
161
+
162
+ /**
163
+ * 静态资源操作类
164
+ */
165
+ export class _Resources {
166
+
167
+ file: _IKunlunFile;
168
+
169
+ constructor() {
170
+ this.file = new _KunlunFile();
171
+ }
172
+
173
+ }
@@ -0,0 +1,33 @@
1
+ export declare class _Options {
2
+ /**
3
+ * 并发数量,默认值为 5,最大可设置值为 10
4
+ */
5
+ concurrency?: number;
6
+ /**
7
+ * 单个子任务的最大数据量,默认值为 5,最大可设置值为 100
8
+ */
9
+ maxSliceNumber?: number;
10
+ /**
11
+ * 触发进度回调函数的步长,以百分比为单位,每当发生大于等于步长的进度变化时,便触发进度回调函数。默认为每当有进度变化时,便触发进度回调函数(进度变化精度为 1%)
12
+ */
13
+ progressCallbackStep?: number;
14
+ }
15
+ export declare class Tasks<cf> {
16
+ private f;
17
+ constructor(_f?: Function);
18
+ /**
19
+ * 创建异步任务
20
+ * @param apiName 函数的 apiName
21
+ * @param params 参数
22
+ */
23
+ createAsyncTask(apiName: cf, params: object): Promise<void>;
24
+ /**
25
+ * 创建分布式任务
26
+ * @param dataset 待处理数据组成的数组
27
+ * @param handlerFunc 用于处理数据集的全局函数的 API name
28
+ * @param progressCallbackFunc 任务进度发生变化时回调的全局函数的 API name,可通过传入 "" / null / undefined 跳过此步骤
29
+ * @param completedCallbackFunc 任务完成时回调的全局函数的 API name,可通过传入 "" / null / undefined 跳过此步骤
30
+ * @param options 高级配置参数,可选
31
+ */
32
+ createDistributedTask(dataset: any[], handlerFunc: cf, progressCallbackFunc: cf | "" | null | undefined, completedCallbackFunc: cf | "" | null | undefined, options?: _Options): Promise<number>;
33
+ }
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tasks = exports._Options = void 0;
4
+ const common = require("@byted-apaas/server-common-node");
5
+ const Request = require("../../request/interface");
6
+ const utils = common.utils;
7
+ const exceptions = common.exceptions;
8
+ class _Options {
9
+ }
10
+ exports._Options = _Options;
11
+ // export async function asyncTaskV1(apiName: string, params: any, oldFuncName: string, isSync: boolean) {
12
+ // return await invokeFuncSync(apiName, params, oldFuncName, false);
13
+ // }
14
+ class Tasks {
15
+ constructor(_f) {
16
+ this.f = _f;
17
+ }
18
+ /**
19
+ * 创建异步任务
20
+ * @param apiName 函数的 apiName
21
+ * @param params 参数
22
+ */
23
+ async createAsyncTask(apiName, params) {
24
+ if (apiName && params) {
25
+ // low_code 1.0
26
+ if (utils.isOnlineDev()) { // TODO 区分 4.0 vs 5.0
27
+ // 1.debug模式
28
+ if (utils.isDebug()) {
29
+ return await this.f(apiName).invoke(params);
30
+ }
31
+ // 2.运行时
32
+ let newApiName = utils.handleFuncName(null, apiName);
33
+ if (!newApiName) {
34
+ throw new exceptions.InvalidParamError(`The function (${apiName}) does not exist, please confirm ${apiName} exists and has been deployed.`);
35
+ }
36
+ let idOrName = {};
37
+ if (newApiName === apiName) {
38
+ idOrName = {
39
+ APIName: newApiName,
40
+ isInvokeByAPIName: true,
41
+ };
42
+ }
43
+ else if (utils.isMicroservice()) {
44
+ idOrName = {
45
+ APIName: apiName,
46
+ isInvokeByAPIName: true,
47
+ };
48
+ }
49
+ else {
50
+ idOrName = {
51
+ APIId: newApiName,
52
+ isInvokeByAPIName: false,
53
+ };
54
+ }
55
+ return {
56
+ task_id: await Request.GetInstance().createAsyncTaskV1(idOrName, params),
57
+ };
58
+ }
59
+ // low_code 2.0
60
+ // 如果是本地调试模式,则直接异步执行
61
+ if (utils.isLocalDebug()) {
62
+ this.f(apiName).invoke(params);
63
+ return { task_id: 1234567890123456 };
64
+ }
65
+ return {
66
+ task_id: await Request.GetInstance().createAsyncTaskV2(apiName, params),
67
+ };
68
+ }
69
+ else {
70
+ throw new exceptions.InvalidParamError(`context.tasks.createAsyncTask params is error`);
71
+ }
72
+ }
73
+ ;
74
+ /**
75
+ * 创建分布式任务
76
+ * @param dataset 待处理数据组成的数组
77
+ * @param handlerFunc 用于处理数据集的全局函数的 API name
78
+ * @param progressCallbackFunc 任务进度发生变化时回调的全局函数的 API name,可通过传入 "" / null / undefined 跳过此步骤
79
+ * @param completedCallbackFunc 任务完成时回调的全局函数的 API name,可通过传入 "" / null / undefined 跳过此步骤
80
+ * @param options 高级配置参数,可选
81
+ */
82
+ async createDistributedTask(dataset, handlerFunc, progressCallbackFunc, completedCallbackFunc, options) {
83
+ if (utils.isLocalDebug()) {
84
+ throw new exceptions.InvalidParamError("Local debugging isn't supported for distributed tasks. You can only deploy them to the cloud");
85
+ }
86
+ if (utils.getDistributedHandleMask()) {
87
+ throw new exceptions.InvalidParamError("Does not support creating distributed tasks in handler function and progress callback function");
88
+ }
89
+ // dataset
90
+ if (!(dataset instanceof Array)) {
91
+ throw new exceptions.InvalidParamError(`parameter dataset is not list`);
92
+ }
93
+ // handlerFunc
94
+ if (!handlerFunc || typeof handlerFunc !== 'string') {
95
+ throw new exceptions.InvalidParamError(`parameter handlerFunc is not string or handlerFunc is empty`);
96
+ }
97
+ // progressCallbackFunc
98
+ if (progressCallbackFunc === null || progressCallbackFunc === undefined) {
99
+ progressCallbackFunc = "";
100
+ }
101
+ if (typeof progressCallbackFunc !== 'string') {
102
+ throw new exceptions.InvalidParamError(`parameter progressCallbackFunc is not string`);
103
+ }
104
+ // completedCallbackFunc
105
+ if (completedCallbackFunc === null || completedCallbackFunc === undefined) {
106
+ completedCallbackFunc = "";
107
+ }
108
+ if (typeof completedCallbackFunc !== 'string') {
109
+ throw new exceptions.InvalidParamError(`parameter completedCallbackFunc is not string`);
110
+ }
111
+ // option.concurrency
112
+ if (options.concurrency === null || options.concurrency === undefined) {
113
+ options.concurrency = 5;
114
+ }
115
+ if ((typeof options.concurrency !== 'number') || options.concurrency <= 0) {
116
+ throw new exceptions.InvalidParamError(`parameter option.concurrency is not Number or not graterThan 0`);
117
+ }
118
+ // option.maxSliceNumber
119
+ if (options.maxSliceNumber === null || options.maxSliceNumber === undefined) {
120
+ options.maxSliceNumber = 5;
121
+ }
122
+ if ((typeof options.maxSliceNumber !== 'number') || options.maxSliceNumber <= 0) {
123
+ throw new exceptions.InvalidParamError(`parameter option.maxSliceNumber is not Number or not graterThan 0`);
124
+ }
125
+ // option.notifyStep
126
+ if (options.progressCallbackStep === null || options.progressCallbackStep === undefined) {
127
+ options.progressCallbackStep = 1;
128
+ }
129
+ if ((typeof options.progressCallbackStep !== 'number') || options.progressCallbackStep <= 0 || options.progressCallbackStep > 100) {
130
+ throw new exceptions.InvalidParamError(`parameter option.progressCallbackStep is not Number or not between 0 and 100`);
131
+ }
132
+ if (utils.isOnlineDev()) {
133
+ return Request.GetFaaSInfraInstance().createDistributeTaskV1([dataset], handlerFunc, progressCallbackFunc, completedCallbackFunc, options);
134
+ }
135
+ return Request.GetFaaSInfraInstance().createDistributeTaskV2([dataset], handlerFunc, progressCallbackFunc, completedCallbackFunc, options);
136
+ }
137
+ ;
138
+ }
139
+ exports.Tasks = Tasks;
@@ -0,0 +1,159 @@
1
+ import * as common from "@byted-apaas/server-common-node"
2
+ import * as Request from "../../request/interface"
3
+
4
+ const utils = common.utils
5
+ const exceptions = common.exceptions
6
+
7
+ export class _Options {
8
+ /**
9
+ * 并发数量,默认值为 5,最大可设置值为 10
10
+ */
11
+ concurrency?: number;
12
+ /**
13
+ * 单个子任务的最大数据量,默认值为 5,最大可设置值为 100
14
+ */
15
+ maxSliceNumber?: number;
16
+ /**
17
+ * 触发进度回调函数的步长,以百分比为单位,每当发生大于等于步长的进度变化时,便触发进度回调函数。默认为每当有进度变化时,便触发进度回调函数(进度变化精度为 1%)
18
+ */
19
+ progressCallbackStep?: number;
20
+ }
21
+
22
+ // export async function asyncTaskV1(apiName: string, params: any, oldFuncName: string, isSync: boolean) {
23
+ // return await invokeFuncSync(apiName, params, oldFuncName, false);
24
+ // }
25
+
26
+ export class Tasks<cf> {
27
+ private f: Function
28
+
29
+ constructor(_f?: Function) {
30
+ this.f = _f
31
+ }
32
+
33
+ /**
34
+ * 创建异步任务
35
+ * @param apiName 函数的 apiName
36
+ * @param params 参数
37
+ */
38
+ public async createAsyncTask(apiName: cf, params: object): Promise<void> {
39
+ if (apiName && params) {
40
+ // low_code 1.0
41
+ if (utils.isOnlineDev()) {// TODO 区分 4.0 vs 5.0
42
+ // 1.debug模式
43
+ if (utils.isDebug()) {
44
+ return await this.f(apiName).invoke(params);
45
+ }
46
+ // 2.运行时
47
+ let newApiName = utils.handleFuncName(null, apiName as any);
48
+ if (!newApiName) {
49
+ throw new exceptions.InvalidParamError(`The function (${apiName}) does not exist, please confirm ${apiName} exists and has been deployed.`);
50
+ }
51
+ let idOrName: any = {};
52
+ if (newApiName === apiName) {
53
+ idOrName = {
54
+ APIName: newApiName,
55
+ isInvokeByAPIName: true,
56
+ }
57
+ } else if (utils.isMicroservice()) {
58
+ idOrName = {
59
+ APIName: apiName,
60
+ isInvokeByAPIName: true,
61
+ }
62
+ } else {
63
+ idOrName = {
64
+ APIId: newApiName,
65
+ isInvokeByAPIName: false,
66
+ }
67
+ }
68
+ return {
69
+ task_id: await Request.GetInstance().createAsyncTaskV1(idOrName, params),
70
+ } as any
71
+ }
72
+
73
+
74
+ // low_code 2.0
75
+ // 如果是本地调试模式,则直接异步执行
76
+ if (utils.isLocalDebug()) {
77
+ this.f(apiName).invoke(params);
78
+ return {task_id: 1234567890123456} as any;
79
+ }
80
+
81
+ return {
82
+ task_id: await Request.GetInstance().createAsyncTaskV2(apiName as string, params),
83
+ } as any
84
+ } else {
85
+ throw new exceptions.InvalidParamError(`context.tasks.createAsyncTask params is error`);
86
+ }
87
+ };
88
+
89
+ /**
90
+ * 创建分布式任务
91
+ * @param dataset 待处理数据组成的数组
92
+ * @param handlerFunc 用于处理数据集的全局函数的 API name
93
+ * @param progressCallbackFunc 任务进度发生变化时回调的全局函数的 API name,可通过传入 "" / null / undefined 跳过此步骤
94
+ * @param completedCallbackFunc 任务完成时回调的全局函数的 API name,可通过传入 "" / null / undefined 跳过此步骤
95
+ * @param options 高级配置参数,可选
96
+ */
97
+ public async createDistributedTask(dataset: any[], handlerFunc: cf, progressCallbackFunc: cf | "" | null | undefined, completedCallbackFunc: cf | "" | null | undefined, options?: _Options): Promise<number> {
98
+ if (utils.isLocalDebug()) {
99
+ throw new exceptions.InvalidParamError("Local debugging isn't supported for distributed tasks. You can only deploy them to the cloud");
100
+ }
101
+
102
+ if (utils.getDistributedHandleMask()) {
103
+ throw new exceptions.InvalidParamError("Does not support creating distributed tasks in handler function and progress callback function");
104
+ }
105
+
106
+ // dataset
107
+ if (!(dataset instanceof Array)) {
108
+ throw new exceptions.InvalidParamError(`parameter dataset is not list`);
109
+ }
110
+
111
+ // handlerFunc
112
+ if (!handlerFunc || typeof handlerFunc !== 'string') {
113
+ throw new exceptions.InvalidParamError(`parameter handlerFunc is not string or handlerFunc is empty`);
114
+ }
115
+
116
+ // progressCallbackFunc
117
+ if (progressCallbackFunc === null || progressCallbackFunc === undefined) {
118
+ progressCallbackFunc = "";
119
+ }
120
+ if (typeof progressCallbackFunc !== 'string') {
121
+ throw new exceptions.InvalidParamError(`parameter progressCallbackFunc is not string`);
122
+ }
123
+
124
+ // completedCallbackFunc
125
+ if (completedCallbackFunc === null || completedCallbackFunc === undefined) {
126
+ completedCallbackFunc = "";
127
+ }
128
+ if (typeof completedCallbackFunc !== 'string') {
129
+ throw new exceptions.InvalidParamError(`parameter completedCallbackFunc is not string`);
130
+ }
131
+
132
+ // option.concurrency
133
+ if (options.concurrency === null || options.concurrency === undefined) {
134
+ options.concurrency = 5;
135
+ }
136
+ if ((typeof options.concurrency !== 'number') || options.concurrency <= 0) {
137
+ throw new exceptions.InvalidParamError(`parameter option.concurrency is not Number or not graterThan 0`);
138
+ }
139
+ // option.maxSliceNumber
140
+ if (options.maxSliceNumber === null || options.maxSliceNumber === undefined) {
141
+ options.maxSliceNumber = 5;
142
+ }
143
+ if ((typeof options.maxSliceNumber !== 'number') || options.maxSliceNumber <= 0) {
144
+ throw new exceptions.InvalidParamError(`parameter option.maxSliceNumber is not Number or not graterThan 0`);
145
+ }
146
+ // option.notifyStep
147
+ if (options.progressCallbackStep === null || options.progressCallbackStep === undefined) {
148
+ options.progressCallbackStep = 1;
149
+ }
150
+ if ((typeof options.progressCallbackStep !== 'number') || options.progressCallbackStep <= 0 || options.progressCallbackStep > 100) {
151
+ throw new exceptions.InvalidParamError(`parameter option.progressCallbackStep is not Number or not between 0 and 100`);
152
+ }
153
+
154
+ if (utils.isOnlineDev()) {
155
+ return Request.GetFaaSInfraInstance().createDistributeTaskV1([dataset], handlerFunc, progressCallbackFunc, completedCallbackFunc, options);
156
+ }
157
+ return Request.GetFaaSInfraInstance().createDistributeTaskV2([dataset], handlerFunc, progressCallbackFunc, completedCallbackFunc, options);
158
+ };
159
+ }
@@ -0,0 +1,27 @@
1
+ export interface workflowVariables {
2
+ }
3
+ export declare type globalFuncNames = "a" | "b";
4
+ export interface globalVariablesMap {
5
+ a: string;
6
+ b: string;
7
+ }
8
+ export declare type globalVariables = keyof globalVariablesMap;
9
+ export interface metadataMap {
10
+ /**
11
+ * @description 用户
12
+ */
13
+ _user: User;
14
+ _department: Department;
15
+ }
16
+ export declare type currentObjApiName = "_user";
17
+ interface User {
18
+ _name: string;
19
+ _id: number;
20
+ _department: Department;
21
+ }
22
+ interface Department {
23
+ _id: number;
24
+ _name: string;
25
+ _superior: Department;
26
+ }
27
+ export {};