@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.
@@ -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
  }
@@ -13,4 +13,5 @@ export declare class Application implements IApplication {
13
13
  cloudfunction(funcName: string): IFunction;
14
14
  env(platformEnvType: PlatformEnvType): IApplication;
15
15
  localDebugMode(): IApplication;
16
+ setLaneName(laneName: string): IApplication;
16
17
  }
@@ -35,5 +35,9 @@ class Application {
35
35
  this.appCtx.debugType = "2";
36
36
  return this;
37
37
  }
38
+ setLaneName(laneName) {
39
+ this.appCtx.x_tt_env = laneName;
40
+ return this;
41
+ }
38
42
  }
39
43
  exports.Application = Application;
@@ -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
- queryBuilder.setLimit(limit);
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
- queryBuilder.setOffset(offset);
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
  ;
@@ -1,6 +1,7 @@
1
1
  import { Order, OrderType } from './order';
2
2
  import { Logic } from '../../../kunlun/operator/impl/logic';
3
3
  export declare const maxLimit = 200;
4
+ export declare const maxLimitV2 = 10000;
4
5
  /**
5
6
  * 查询构造器,在 DB 中被初始化,用于构建一次查询
6
7
  */
@@ -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.maxLimit) {
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: null,
84
- logicalExpressions: null,
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 > 200) {
125
- throw new Error("limit must be greater than 0 and less than or equal to 200");
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.2",
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.1",
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",
@@ -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 > 1000) {
333
- limit = 1000;
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 > 200) {
944
- param.limit = 200;
943
+ if (param.limit <= 0 || param.limit > 10000) {
944
+ param.limit = 10000;
945
945
  }
946
946
  let req;
947
947
  req.ObjectAPIAlias = objectApiName;
@@ -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 > 1000) {
217
- limit = 1000;
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 > 200) {
615
- param.limit = 200;
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 JSON.parse(data.records);
621
+ return data.total;
622
622
  }
623
623
  else {
624
- return data.total;
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.写入文件