@byted-apaas/server-sdk-node 1.0.15 → 1.0.16

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.
@@ -249,6 +249,16 @@ export interface _IKQuery<T> {
249
249
  * 设置查询条件
250
250
  */
251
251
  where(): Omit<_IKQuery<T>, 'findAll'>;
252
+ /**
253
+ * 模糊查询:与 where 之间是与关系
254
+ * @param keyword 模糊查询的关键字,必填且不可以为空串
255
+ * @param fieldAPINames 『可搜索字段』的字段列表,不可为空
256
+ * @example
257
+ * ```
258
+ * context.db.object("_user").fuzzySearch("张三", ["_name"]).find()
259
+ * ```
260
+ */
261
+ fuzzySearch(keyword: string, fieldAPINames: string[]): Omit<_IKQuery<T>, 'findAll'>;
252
262
  /**
253
263
  * 指定分页查询的数量
254
264
  * @param limit 分页查询的数量
@@ -72,6 +72,7 @@ declare class _KObjectQuery<T> implements _IKQuery<T> {
72
72
  select<K extends keyof T>(...fieldApiNames: K[]): _KQuery<T>;
73
73
  where(conditionMap: _WhereCond<T>): _KQuery<T>;
74
74
  where(): _KQuery<T>;
75
+ fuzzySearch(keyword: string, fieldAPINames: string[]): _KQuery<T>;
75
76
  limit(limit: number): _KQuery<T>;
76
77
  offset(offset: number): _KQuery<T>;
77
78
  count(): Promise<number>;
@@ -102,6 +103,7 @@ declare class _KQuery<T> implements _IKQuery<T> {
102
103
  select<K extends keyof T>(...fieldApiNames: K[]): this;
103
104
  where(conditionMap: _WhereCond<T>): this;
104
105
  where(): this;
106
+ fuzzySearch(keyword: string, fieldAPINames: string[]): this;
105
107
  limit(limit: number): this;
106
108
  offset(offset: number): this;
107
109
  count(): Promise<number>;
@@ -339,6 +339,9 @@ class _KObjectQuery {
339
339
  }
340
340
  return new _KQuery(this.apiName, this.appCtx, this.authType).where(conditionMap);
341
341
  }
342
+ fuzzySearch(keyword, fieldAPINames) {
343
+ return new _KQuery(this.apiName, this.appCtx).fuzzySearch(keyword, fieldAPINames);
344
+ }
342
345
  // limit, offset, count
343
346
  limit(limit) {
344
347
  return new _KQuery(this.apiName, this.appCtx, this.authType).limit(limit);
@@ -397,7 +400,7 @@ class _KQuery {
397
400
  }
398
401
  else {
399
402
  const criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
400
- return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false, this.authType);
403
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false, this.authType);
401
404
  }
402
405
  }
403
406
  ;
@@ -482,7 +485,7 @@ class _KQuery {
482
485
  }
483
486
  else {
484
487
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
485
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
488
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
486
489
  }
487
490
  queryCount += rs.length;
488
491
  rs.forEach((r) => {
@@ -552,7 +555,7 @@ class _KQuery {
552
555
  }
553
556
  else {
554
557
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
555
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), orders, false, selectFields, i, newLimit, false, this.authType);
558
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, orders, false, selectFields, i, newLimit, false, this.authType);
556
559
  }
557
560
  queryCount += rs.length;
558
561
  try {
@@ -590,7 +593,8 @@ class _KQuery {
590
593
  }
591
594
  else {
592
595
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
593
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
596
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), null, // FindAll 不再迭代
597
+ [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
594
598
  }
595
599
  rs.forEach((r) => {
596
600
  maxId = r._id > maxId ? r._id : maxId;
@@ -660,6 +664,26 @@ class _KQuery {
660
664
  }
661
665
  return this;
662
666
  }
667
+ fuzzySearch(keyword, fieldAPINames) {
668
+ const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
669
+ if (queryV2) {
670
+ throw new server_common_node_1.exceptions.InvalidParamError(`OpenSDK does not implement FuzzySearch`);
671
+ }
672
+ if (queryBuilder.fuzzySearch) {
673
+ throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch can only be called once`);
674
+ }
675
+ if (!keyword) {
676
+ throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch's keyword can not be empty`);
677
+ }
678
+ if (!fieldAPINames || fieldAPINames.length === 0) {
679
+ throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch's fieldAPINames can not be empty`);
680
+ }
681
+ queryBuilder.fuzzySearch = {
682
+ keyword: keyword,
683
+ fieldAPINames: fieldAPINames,
684
+ };
685
+ return this;
686
+ }
663
687
  limit(limit) {
664
688
  const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
665
689
  limit = Number(limit);
@@ -702,7 +726,7 @@ class _KQuery {
702
726
  }
703
727
  else {
704
728
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
705
- return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true, this.authType);
729
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true, this.authType);
706
730
  }
707
731
  }
708
732
  ;
@@ -14,6 +14,7 @@ export declare class QueryBuilder {
14
14
  offset: number;
15
15
  order: Order[];
16
16
  logic: Logic;
17
+ fuzzySearch: object;
17
18
  constructor(objectApiName: string);
18
19
  addLogic(logic: Logic): void;
19
20
  getLogic(): Logic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -12,7 +12,7 @@
12
12
  "pre-build": "rm -rf build && tsc"
13
13
  },
14
14
  "dependencies": {
15
- "@byted-apaas/server-common-node": "^1.0.13",
15
+ "@byted-apaas/server-common-node": "^1.0.14",
16
16
  "@jorgeferrero/stream-to-buffer": "^2.0.6",
17
17
  "dayjs": "^1.9.6",
18
18
  "form-data": "^3.0.0",
@@ -17,7 +17,7 @@ export declare class RequestRpc implements IInnerAPIRequest {
17
17
  createRecordsBySync(objectApiName: string, records: object[], authType: string): any;
18
18
  updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
19
19
  deleteRecordsBySync(objectApiName: string, recordIDs: number[], authType: string): any;
20
- getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
20
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, fuzzySearch: any, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
21
21
  updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): Promise<void>;
22
22
  uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
23
23
  downloadFileByID(fileID: string, filePath?: string): Promise<Buffer | void>;
@@ -331,10 +331,7 @@ async function deleteRecordsBySync(objectApiName, recordIDs, authType) {
331
331
  });
332
332
  return { err_map: errMap };
333
333
  }
334
- async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
335
- if (limit > 10000) {
336
- limit = 10000;
337
- }
334
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
338
335
  // 1.check
339
336
  if (!objectApiName) {
340
337
  throw new exceptions.InvalidParamError("objectApiName is empty");
@@ -361,6 +358,7 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ign
361
358
  param.FieldAPIAPIAliases = fieldApiNames;
362
359
  param.NeedFilterUserPermission = false;
363
360
  param.NeedTotalCount = needCount;
361
+ param.FuzzySearch = fuzzySearch;
364
362
  // 4.发起请求
365
363
  let resp;
366
364
  try {
@@ -1114,7 +1112,7 @@ class RequestRpc {
1114
1112
  }
1115
1113
  deleteRecordsBySync(objectApiName, recordIDs, authType) {
1116
1114
  }
1117
- getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
1115
+ getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
1118
1116
  }
1119
1117
  async updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1120
1118
  }
@@ -41,7 +41,7 @@ export interface IInnerAPIBaseRequest {
41
41
  createRecordsBySync(objectApiName: string, records: object[], authType: string): any;
42
42
  updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
43
43
  deleteRecordsBySync(objectApiName: string, recordIDs: number[], authType: string): any;
44
- getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
44
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, fuzzySearch: any, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
45
45
  updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): Promise<void>;
46
46
  uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
47
47
  downloadFileByID(fileID: string, filePath?: string): Promise<Buffer | void>;
@@ -19,7 +19,7 @@ export declare class RequestHttp implements IInnerAPIRequest {
19
19
  createRecordsBySync(objectApiName: string, records: object[], authType: string): any;
20
20
  updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
21
21
  deleteRecordsBySync(objectApiName: string, recordIDs: number[], authType: string): any;
22
- getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
22
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], fuzzySearch: any, ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
23
23
  uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
24
24
  downloadFileByID(fileID: string, filePath?: string): Promise<void | Buffer>;
25
25
  downloadFileByToken(fileToken: string, filePath?: string): Promise<Buffer | void>;
@@ -261,10 +261,7 @@ function handleResponse(data, needCount) {
261
261
  return [];
262
262
  }
263
263
  }
264
- async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
265
- if (limit > 10000) {
266
- limit = 10000;
267
- }
264
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
268
265
  // 1.check
269
266
  if (!objectApiName) {
270
267
  throw new exceptions.InternalError("objectApiName is empty");
@@ -283,6 +280,7 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ign
283
280
  "limit": limit,
284
281
  "need_filter_user_permission": false,
285
282
  "need_total_count": needCount,
283
+ "fuzzySearch": fuzzySearch,
286
284
  };
287
285
  authType = (0, utils_1.formatAuthType)(authType);
288
286
  options.headers["User"] = utils.getUserIDFromCtx() + "";
@@ -793,7 +791,7 @@ class RequestHttp {
793
791
  }
794
792
  deleteRecordsBySync(objectApiName, recordIDs, authType) {
795
793
  }
796
- getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
794
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, fuzzySearch, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
797
795
  }
798
796
  uploadFile(data, expire) {
799
797
  return null;