@byted-apaas/server-sdk-node 1.1.17-beta.1 → 1.1.17-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.
@@ -411,8 +411,11 @@ class _KQuery {
411
411
  });
412
412
  }
413
413
  else {
414
- const criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
415
- 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);
414
+ let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
415
+ if (queryBuilder.getLogic().logics.length > 0) {
416
+ criterion = await (0, logic_1.handleCriterion)(criterion);
417
+ }
418
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false, this.authType);
416
419
  }
417
420
  }
418
421
  ;
@@ -478,11 +481,12 @@ class _KQuery {
478
481
  let criterion;
479
482
  if (appCtx) {
480
483
  criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
481
- criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
482
484
  }
483
485
  else {
484
- criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
485
- criterion = await (0, logic_1.handleCriterion)(criterion);
486
+ criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
487
+ if (queryBuilder.getLogic().logics.length > 0) { // 有自定义搜索条件时,需要获取 fields
488
+ criterion = await (0, logic_1.handleCriterion)(criterion);
489
+ }
486
490
  }
487
491
  while (true) {
488
492
  let newLimit = pageLimit;
@@ -494,6 +498,7 @@ class _KQuery {
494
498
  }
495
499
  let rs;
496
500
  if (appCtx) {
501
+ criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
497
502
  const param = {
498
503
  limit: newLimit,
499
504
  offset: 0,
@@ -507,6 +512,9 @@ class _KQuery {
507
512
  });
508
513
  }
509
514
  else {
515
+ // 添加 _id>maxId 条件
516
+ criterion = (0, logic_1.addIDCriterion)(criterion, apiName, maxId);
517
+ // 发起请求
510
518
  rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
511
519
  }
512
520
  queryCount += rs.length;
@@ -554,11 +562,12 @@ class _KQuery {
554
562
  let criterion;
555
563
  if (appCtx) {
556
564
  criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
557
- criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
558
565
  }
559
566
  else {
560
- criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
561
- criterion = await (0, logic_1.handleCriterion)(criterion);
567
+ criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
568
+ if (queryBuilder.getLogic().logics.length > 0) {
569
+ criterion = await (0, logic_1.handleCriterion)(criterion);
570
+ }
562
571
  }
563
572
  for (let i = offset; !limit || i < offset + limit; i += pageLimit) {
564
573
  let newLimit = function () {
@@ -575,6 +584,7 @@ class _KQuery {
575
584
  }
576
585
  let rs;
577
586
  if (appCtx) {
587
+ criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
578
588
  const param = {
579
589
  limit: newLimit,
580
590
  offset: i,
@@ -588,6 +598,9 @@ class _KQuery {
588
598
  });
589
599
  }
590
600
  else {
601
+ // 添加 _id>maxId 条件
602
+ criterion = (0, logic_1.addIDCriterion)(criterion, apiName, maxId);
603
+ // 发起请求
591
604
  rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, orders, false, selectFields, i, newLimit, false, this.authType);
592
605
  }
593
606
  queryCount += rs.length;
@@ -625,8 +638,12 @@ class _KQuery {
625
638
  });
626
639
  }
627
640
  else {
628
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
629
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), null, // FindAll 不再迭代
641
+ let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
642
+ if (queryBuilder.getLogic().logics.length > 0) {
643
+ criterion = await (0, logic_1.handleCriterion)(criterion);
644
+ }
645
+ criterion = (0, logic_1.addIDCriterion)(criterion, apiName, maxId);
646
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, null, // FindAll 不再迭代
630
647
  [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
631
648
  }
632
649
  rs.forEach((r) => {
@@ -759,7 +776,10 @@ class _KQuery {
759
776
  }
760
777
  else {
761
778
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
762
- 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);
779
+ if (queryBuilder.getLogic().logics.length > 0) {
780
+ criterion = await (0, logic_1.handleCriterion)(criterion);
781
+ }
782
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true, this.authType);
763
783
  }
764
784
  }
765
785
  ;
@@ -24,8 +24,16 @@ export type Criterion = {
24
24
  * @param objectApiName
25
25
  * @param maxId 添加 _id>maxId 条件,为 -1 表示不使用该参数
26
26
  */
27
- export declare function buildCriterion(logic: Logic, objectApiName: string, maxId?: number): Criterion | string;
27
+ export declare function buildCriterion(logic: Logic, objectApiName: string): Criterion;
28
28
  export declare function buildExpression(objectApiName: string, left: string, right: Condition | UserDataType, index?: number): Expression;
29
+ /**
30
+ * 在 criterion 中添加 _id>maxId 的判断条件
31
+ *
32
+ * @param criterion
33
+ * @param apiName
34
+ * @param maxId 添加 _id>maxId 条件
35
+ */
36
+ export declare function addIDCriterion(criterion: Criterion, apiName: string, maxId: number): Criterion;
29
37
  export declare class Logic {
30
38
  value: string;
31
39
  expressions: {
@@ -47,4 +55,4 @@ export declare class Logic {
47
55
  addLogic(logic: Logic): void;
48
56
  }
49
57
  export declare function buildLogic(param: (Logic | object)[], logicValue?: string): Logic;
50
- export declare function handleCriterion(criterion: string | Criterion): Promise<string | Criterion>;
58
+ export declare function handleCriterion(criterion: Criterion): Promise<Criterion>;
@@ -2,7 +2,7 @@
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.handleCriterion = exports.buildLogic = exports.Logic = exports.buildExpression = exports.buildCriterion = exports.Condition = void 0;
5
+ exports.handleCriterion = exports.buildLogic = exports.Logic = exports.addIDCriterion = exports.buildExpression = exports.buildCriterion = exports.Condition = void 0;
6
6
  const expression_1 = require("./expression");
7
7
  const operator_1 = require("./operator");
8
8
  const server_common_node_1 = require("@byted-apaas/server-common-node");
@@ -59,7 +59,7 @@ function isKunlunTypeOrSerializedObject(obj) {
59
59
  * @param objectApiName
60
60
  * @param maxId 添加 _id>maxId 条件,为 -1 表示不使用该参数
61
61
  */
62
- function buildCriterion(logic, objectApiName, maxId = -1) {
62
+ function buildCriterion(logic, objectApiName) {
63
63
  let index = 0;
64
64
  let logics = [];
65
65
  let expressions = [];
@@ -117,18 +117,10 @@ function buildCriterion(logic, objectApiName, maxId = -1) {
117
117
  f(logic);
118
118
  // 如果未设置filter,默认添加: _isDeleted = false
119
119
  if (expressions.length < 1) {
120
- if (maxId >= 0) {
121
- return `{"conditions":[{"index":1,"left":{"type":"metadataVariable","settings":{"fieldPath":
122
- [{"objectApiName":"${objectApiName}","fieldApiName":"_isDeleted"}]}},"operator":"equals","right":
123
- {"type":"constant","settings":{"data":false}}},{"index":2,"left":{"type":"metadataVariable","settings":
124
- {"fieldPath":[{"objectApiName":"${objectApiName}","fieldApiName":"_id"}]}},"operator":"greaterThan","right":
125
- {"type":"constant","settings":{"data":${maxId}}}}],"logic":"1 and 2"}`;
126
- }
127
- else {
128
- return `{"conditions":[{"index":1,"left":{"type":"metadataVariable","settings":{"fieldPath":
129
- [{"objectApiName":"${objectApiName}","fieldApiName":"_isDeleted"}]}},"operator":"equals","right":
130
- {"type":"constant","settings":{"data":false}}}],"logic":"1"}`;
131
- }
120
+ logics = [];
121
+ expressions.push(buildExpression(objectApiName, '_isDeleted', false, expressions.length + 1));
122
+ logics.push('1');
123
+ return { conditions: expressions, logic: logics.join('') };
132
124
  }
133
125
  let isContainDeleted = false;
134
126
  for (let i = 0; i < expressions.length; i++) {
@@ -148,11 +140,6 @@ function buildCriterion(logic, objectApiName, maxId = -1) {
148
140
  logics.splice(0, 0, '(');
149
141
  logics.push(' and ', `${expressions.length}`, ')');
150
142
  }
151
- if (maxId >= 0) {
152
- expressions.push(buildExpression(objectApiName, '_id', new Condition('_id', maxId, operator_1.operates.GT), expressions.length + 1));
153
- logics.splice(0, 0, '(');
154
- logics.push(' and ', `${expressions.length}`, ')');
155
- }
156
143
  return { conditions: expressions, logic: logics.join('') };
157
144
  }
158
145
  exports.buildCriterion = buildCriterion;
@@ -183,6 +170,22 @@ function buildExpression(objectApiName, left, right, index = 1) {
183
170
  return null;
184
171
  }
185
172
  exports.buildExpression = buildExpression;
173
+ /**
174
+ * 在 criterion 中添加 _id>maxId 的判断条件
175
+ *
176
+ * @param criterion
177
+ * @param apiName
178
+ * @param maxId 添加 _id>maxId 条件
179
+ */
180
+ function addIDCriterion(criterion, apiName, maxId) {
181
+ criterion.conditions.push(buildExpression(apiName, '_id', new Condition('_id', maxId, operator_1.operates.GT), criterion.conditions.length + 1));
182
+ let logics = criterion.logic.split('');
183
+ logics.splice(0, 0, '(');
184
+ logics.push(' and ', `${criterion.conditions.length}`, ')');
185
+ criterion.logic = logics.join('');
186
+ return criterion;
187
+ }
188
+ exports.addIDCriterion = addIDCriterion;
186
189
  // 逻辑操作:and 和 or
187
190
  class Logic {
188
191
  constructor(expressions = null, logicValue = 'and') {
@@ -339,9 +342,6 @@ class Filter {
339
342
  }
340
343
  }
341
344
  async function handleCriterion(criterion) {
342
- if (typeof criterion === 'string') {
343
- return criterion;
344
- }
345
345
  if (!criterion || !criterion.conditions || !(criterion.conditions instanceof Array)) {
346
346
  return criterion;
347
347
  }
@@ -355,7 +355,7 @@ async function handleCriterion(criterion) {
355
355
  }
356
356
  await handleCondition(condition, fieldRes);
357
357
  }
358
- return JSON.stringify(criterion);
358
+ return criterion;
359
359
  }
360
360
  exports.handleCriterion = handleCriterion;
361
361
  async function handleLookupCondition(conditions) {
@@ -376,6 +376,7 @@ async function handleLookupCondition(conditions) {
376
376
  let lookupMap = new Map(), dateSet = new Set();
377
377
  let firstObjApiName = conditions[0].left.settings.fieldPath[0].objectApiName;
378
378
  let fields = [];
379
+ // 获取对象的字段
379
380
  if (queryMap.size === 1) {
380
381
  fields.push(await Request.GetInstance().getField(firstObjApiName, fieldName));
381
382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.1.17-beta.1",
3
+ "version": "1.1.17-beta.3",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -296,9 +296,12 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearc
296
296
  if (needCount) {
297
297
  fieldApiNames = ['_id'];
298
298
  }
299
+ if (typeof criterion === 'string') {
300
+ criterion = JSON.parse(criterion);
301
+ }
299
302
  // 3.请求
300
303
  options.json = {
301
- 'criterion': JSON.parse(criterion),
304
+ 'criterion': criterion,
302
305
  order,
303
306
  'ignore_back_lookup_field': ignoreBackLookupField,
304
307
  'field_api_names': fieldApiNames,