@byted-apaas/server-sdk-node 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/application/application.d.ts +2 -0
- package/application/impl/common.js +1 -0
- package/application/impl/impl.d.ts +1 -0
- package/application/impl/impl.js +4 -0
- package/context/db/impl/object.js +30 -4
- package/context/db/impl/queryBuilder.d.ts +1 -0
- package/context/db/impl/queryBuilder.js +5 -3
- package/kunlun/operator/impl/logicV2.js +5 -4
- package/package.json +5 -2
- package/request/innerapi.js +4 -4
- package/request/openapi.js +7 -6
|
@@ -17,6 +17,7 @@ export interface IApplication {
|
|
|
17
17
|
cloudfunction(funcName: string): IFunction;
|
|
18
18
|
env(platformEnvType: PlatformEnvType): IApplication;
|
|
19
19
|
localDebugMode(): IApplication;
|
|
20
|
+
setLaneName(laneName: string): IApplication;
|
|
20
21
|
}
|
|
21
22
|
export declare type AppMode = 'openSDK' | 'faasSDK';
|
|
22
23
|
export interface AppCtx {
|
|
@@ -24,4 +25,5 @@ export interface AppCtx {
|
|
|
24
25
|
env?: PlatformEnvType;
|
|
25
26
|
credential: AppCredential;
|
|
26
27
|
debugType?: "0" | "2";
|
|
28
|
+
x_tt_env?: string;
|
|
27
29
|
}
|
|
@@ -39,6 +39,7 @@ async function runCtxForOpenSDK(appCtx, promise) {
|
|
|
39
39
|
}
|
|
40
40
|
utils.setInvokeFuncName("openSDK");
|
|
41
41
|
utils.setTenant(await appCtx.credential.getTenantInfo());
|
|
42
|
+
utils.setXTTEnvOnlyDebug(appCtx.x_tt_env);
|
|
42
43
|
if (!utils.getLogID()) {
|
|
43
44
|
utils.setLogID(crypto.randomBytes(16).toString('hex'));
|
|
44
45
|
}
|
package/application/impl/impl.js
CHANGED
|
@@ -348,6 +348,22 @@ class _KQuery {
|
|
|
348
348
|
}
|
|
349
349
|
async find() {
|
|
350
350
|
const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
351
|
+
// 查询非 _id 字段或者关联对象下钻._id, limit 不允许超过 200
|
|
352
|
+
let checkLimit;
|
|
353
|
+
let checkFields;
|
|
354
|
+
if (queryV2) {
|
|
355
|
+
checkLimit = queryV2._limit;
|
|
356
|
+
checkFields = queryV2.fields;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
checkLimit = queryBuilder.getLimit();
|
|
360
|
+
checkFields = queryBuilder.getSelect();
|
|
361
|
+
}
|
|
362
|
+
if (checkFields.length != 1 || !(checkFields[0] == "_id" || checkFields[0].endsWith("._id"))) {
|
|
363
|
+
if (checkLimit > 200) {
|
|
364
|
+
throw new Error(`limit(${checkLimit}) > ${queryBuilder_1.maxLimit}. Limit should be 1~${queryBuilder_1.maxLimitV2} when querying the id field, otherwise it should be 1~${queryBuilder_1.maxLimit}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
351
367
|
if (appCtx) {
|
|
352
368
|
const param = {
|
|
353
369
|
limit: queryV2._limit,
|
|
@@ -478,14 +494,24 @@ class _KQuery {
|
|
|
478
494
|
return this;
|
|
479
495
|
}
|
|
480
496
|
limit(limit) {
|
|
481
|
-
const { queryBuilder } = queryPropertiesStore.get(this);
|
|
482
|
-
|
|
497
|
+
const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
498
|
+
if (queryV2) {
|
|
499
|
+
queryV2.limit(limit);
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
queryBuilder.setLimit(limit);
|
|
503
|
+
}
|
|
483
504
|
return this;
|
|
484
505
|
}
|
|
485
506
|
;
|
|
486
507
|
offset(offset) {
|
|
487
|
-
const { queryBuilder } = queryPropertiesStore.get(this);
|
|
488
|
-
|
|
508
|
+
const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
|
|
509
|
+
if (queryV2) {
|
|
510
|
+
queryV2.offset(offset);
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
queryBuilder.setOffset(offset);
|
|
514
|
+
}
|
|
489
515
|
return this;
|
|
490
516
|
}
|
|
491
517
|
;
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 ByteDance Ltd. and/or its affiliates
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.QueryBuilder = exports.maxLimit = void 0;
|
|
5
|
+
exports.QueryBuilder = exports.maxLimitV2 = exports.maxLimit = void 0;
|
|
6
6
|
const order_1 = require("./order");
|
|
7
7
|
const logic_1 = require("../../../kunlun/operator/impl/logic");
|
|
8
8
|
const server_common_node_1 = require("@byted-apaas/server-common-node");
|
|
9
9
|
exports.maxLimit = 200;
|
|
10
|
+
// 限制开放至 1w,当仅查询 _id 时,最大可返回 1w,其他查询字段时仅返回 200,由底层控制。
|
|
11
|
+
exports.maxLimitV2 = 10000;
|
|
10
12
|
/**
|
|
11
13
|
* 查询构造器,在 DB 中被初始化,用于构建一次查询
|
|
12
14
|
*/
|
|
@@ -62,9 +64,9 @@ class QueryBuilder {
|
|
|
62
64
|
// need import exceptions
|
|
63
65
|
throw new server_common_node_1.exceptions.InvalidParamError(`limit(${limit}) < 1`);
|
|
64
66
|
}
|
|
65
|
-
if (limit > exports.
|
|
67
|
+
if (limit > exports.maxLimitV2) {
|
|
66
68
|
// need import exceptions
|
|
67
|
-
throw new server_common_node_1.exceptions.InvalidParamError(`limit(${limit}) > ${exports.maxLimit}`);
|
|
69
|
+
throw new server_common_node_1.exceptions.InvalidParamError(`limit(${limit}) > ${exports.maxLimitV2}. Limit should be 1~${exports.maxLimitV2} when querying the id field, otherwise it should be 1~${exports.maxLimit}`);
|
|
68
70
|
}
|
|
69
71
|
this.limit = limit;
|
|
70
72
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildCriterionV2 = exports.logical = exports.QueryV2 = exports.LogicalExpression = exports.ArithmeticExpression = exports.NewConstantExpressionField = exports.NewMetadataExpressionField = void 0;
|
|
4
4
|
const operator_1 = require("./operator");
|
|
5
|
+
const queryBuilder_1 = require("../../../context/db/impl/queryBuilder");
|
|
5
6
|
function NewMetadataExpressionField(objectApiName, fieldApiName) {
|
|
6
7
|
return {
|
|
7
8
|
type: "metadataVariable",
|
|
@@ -80,8 +81,8 @@ class QueryV2 {
|
|
|
80
81
|
this._order = [];
|
|
81
82
|
this.filter = {
|
|
82
83
|
type: "and",
|
|
83
|
-
arithmeticExpressions:
|
|
84
|
-
logicalExpressions:
|
|
84
|
+
arithmeticExpressions: [],
|
|
85
|
+
logicalExpressions: [],
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
buildCriterion(filter) {
|
|
@@ -121,8 +122,8 @@ class QueryV2 {
|
|
|
121
122
|
return this;
|
|
122
123
|
}
|
|
123
124
|
limit(limit) {
|
|
124
|
-
if (limit <= 0 || limit >
|
|
125
|
-
throw new Error(
|
|
125
|
+
if (limit <= 0 || limit > 10000) {
|
|
126
|
+
throw new Error(`limit(${limit}) > ${queryBuilder_1.maxLimitV2}. Limit should be 1~${queryBuilder_1.maxLimitV2} when querying the id field, otherwise it should be 1~${queryBuilder_1.maxLimit}`);
|
|
126
127
|
}
|
|
127
128
|
this._limit = limit;
|
|
128
129
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byted-apaas/server-sdk-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "aPaaS Server SDK",
|
|
5
5
|
"author": "zhouwexin <zhouwexin@bytedance.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -12,14 +12,17 @@
|
|
|
12
12
|
"pre-build": "rm -rf build && tsc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@byted-apaas/server-common-node": "1.0.
|
|
15
|
+
"@byted-apaas/server-common-node": "^1.0.4",
|
|
16
16
|
"@jorgeferrero/stream-to-buffer": "^2.0.6",
|
|
17
17
|
"dayjs": "^1.9.6",
|
|
18
18
|
"form-data": "^3.0.0",
|
|
19
|
+
"typescript": "^4.9.3",
|
|
19
20
|
"uuid": "^8.3.2"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
23
|
+
"@types/google-protobuf": "^3.15.6",
|
|
22
24
|
"@types/mocha": "^9.0.0",
|
|
25
|
+
"@types/node-fetch": "^2.6.2",
|
|
23
26
|
"axios": "^0.21.0",
|
|
24
27
|
"madge": "^3.12.0",
|
|
25
28
|
"mocha": "^9.1.3",
|
package/request/innerapi.js
CHANGED
|
@@ -329,8 +329,8 @@ async function deleteRecordsBySync(objectApiName, recordIDs) {
|
|
|
329
329
|
return { err_map: errMap };
|
|
330
330
|
}
|
|
331
331
|
async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
|
|
332
|
-
if (limit >
|
|
333
|
-
limit =
|
|
332
|
+
if (limit > 10000) {
|
|
333
|
+
limit = 10000;
|
|
334
334
|
}
|
|
335
335
|
// 1.check
|
|
336
336
|
if (!objectApiName) {
|
|
@@ -940,8 +940,8 @@ async function openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
|
|
|
940
940
|
}
|
|
941
941
|
async function openSDKGetRecords(objectApiName, param) {
|
|
942
942
|
// 1. prepare args
|
|
943
|
-
if (param.limit <= 0 || param.limit >
|
|
944
|
-
param.limit =
|
|
943
|
+
if (param.limit <= 0 || param.limit > 10000) {
|
|
944
|
+
param.limit = 10000;
|
|
945
945
|
}
|
|
946
946
|
let req;
|
|
947
947
|
req.ObjectAPIAlias = objectApiName;
|
package/request/openapi.js
CHANGED
|
@@ -213,8 +213,8 @@ function handleResponse(data, needCount) {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
|
|
216
|
-
if (limit >
|
|
217
|
-
limit =
|
|
216
|
+
if (limit > 10000) {
|
|
217
|
+
limit = 10000;
|
|
218
218
|
}
|
|
219
219
|
// 1.check
|
|
220
220
|
if (!objectApiName) {
|
|
@@ -611,17 +611,17 @@ async function openSDKGetRecords(objectApiName, param) {
|
|
|
611
611
|
let options = commonHttp.getOptions(null, openapiHttpPath.openSDKGetRecords);
|
|
612
612
|
let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
|
|
613
613
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
614
|
-
if (param.limit <= 0 || param.limit >
|
|
615
|
-
param.limit =
|
|
614
|
+
if (param.limit <= 0 || param.limit > 10000) {
|
|
615
|
+
param.limit = 10000;
|
|
616
616
|
}
|
|
617
617
|
// 2.请求
|
|
618
618
|
options.json = param;
|
|
619
619
|
const data = await openapi.doRequest(null, urlPath, options);
|
|
620
620
|
if (param.count) {
|
|
621
|
-
return
|
|
621
|
+
return data.total;
|
|
622
622
|
}
|
|
623
623
|
else {
|
|
624
|
-
return data.
|
|
624
|
+
return data.records;
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
async function openSDKUploadFile(fileName, data) {
|
|
@@ -661,6 +661,7 @@ async function openSDKDownloadAvatar(imageID) {
|
|
|
661
661
|
let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDownloadAvatar);
|
|
662
662
|
let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
|
|
663
663
|
urlPath = urlPath.replace(replaceKeys.fileID, imageID);
|
|
664
|
+
options.responseType = "buffer";
|
|
664
665
|
// 2.请求
|
|
665
666
|
let data = await openapi.doRequest(null, urlPath, options);
|
|
666
667
|
// 3.写入文件
|