@byted-apaas/server-sdk-node 1.1.15 → 1.1.17-beta.1

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.
@@ -163,6 +163,21 @@ export interface _IKQuery<T> {
163
163
  * ```
164
164
  */
165
165
  findStream(handler: (records: object[]) => Promise<void>): Promise<void>;
166
+ /**
167
+ * 遍历全部符合条件的记录
168
+ * 注:
169
+ * 如果未设置排序字段,默认以 _id 增序查询;
170
+ * 如果有设置排序字段,必须设置具有唯一属性的字段,否则会有数据重复的风险;
171
+ * @param handler 业务处理函数
172
+ * @param pageLimit 分页查询的数量
173
+ * @example
174
+ * ```
175
+ * await application.data.object('_user').findStream(async (records) => {
176
+ * // doSomething ...
177
+ * }, 300);
178
+ * ```
179
+ */
180
+ findStream(handler: (records: object[]) => Promise<void>, pageLimit: number): Promise<void>;
166
181
  /**
167
182
  * 无需入参,返回符合条件的记录,单次返回 200 条
168
183
  * @example
@@ -437,7 +437,7 @@ class _KQuery {
437
437
  return await this.getRecordsByPage();
438
438
  }
439
439
  ;
440
- async findStream(handler) {
440
+ async findStream(handler, pageLimit) {
441
441
  const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
442
442
  let offset = 0, orders = [];
443
443
  if (queryV2) {
@@ -448,14 +448,17 @@ class _KQuery {
448
448
  offset = queryBuilder.getOffset();
449
449
  orders = queryBuilder.getOrder();
450
450
  }
451
+ if (pageLimit == 0) {
452
+ pageLimit = queryBuilder_1.defaultLimit;
453
+ }
451
454
  if (orders.length === 0 && offset === 0) {
452
455
  // 走主键翻页
453
- return await this.walkRecordsByID(handler);
456
+ return await this.walkRecordsByID(handler, pageLimit);
454
457
  }
455
458
  // 走 limit offset 翻页
456
- return await this.walkRecordsByLimitOffset(handler);
459
+ return await this.walkRecordsByLimitOffset(handler, pageLimit);
457
460
  }
458
- async walkRecordsByID(handler) {
461
+ async walkRecordsByID(handler, pageLimit) {
459
462
  const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
460
463
  let limit = 0, selectFields = [];
461
464
  if (queryV2) {
@@ -471,9 +474,19 @@ class _KQuery {
471
474
  selectFields = queryBuilder.getSelect();
472
475
  }
473
476
  let maxId = 0, queryCount = 0;
477
+ let criterionV2;
478
+ let criterion;
479
+ if (appCtx) {
480
+ criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
481
+ criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
482
+ }
483
+ else {
484
+ criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
485
+ criterion = await (0, logic_1.handleCriterion)(criterion);
486
+ }
474
487
  while (true) {
475
- let newLimit = queryBuilder_1.defaultLimit;
476
- if (limit > 0 && limit - queryCount < queryBuilder_1.defaultLimit) {
488
+ let newLimit = pageLimit;
489
+ if (limit > 0 && limit - queryCount < pageLimit) {
477
490
  newLimit = limit - queryCount;
478
491
  }
479
492
  if (newLimit <= 0) {
@@ -481,23 +494,20 @@ class _KQuery {
481
494
  }
482
495
  let rs;
483
496
  if (appCtx) {
484
- let criterion = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
485
- criterion.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
486
497
  const param = {
487
498
  limit: newLimit,
488
499
  offset: 0,
489
500
  sort: [{ field: '_id', direction: 'asc', type: '' }],
490
501
  fields: selectFields,
491
502
  count: false,
492
- filter: criterion,
503
+ filter: criterionV2,
493
504
  };
494
505
  rs = await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
495
506
  return await Request.GetInstance().openSDKGetRecords(apiName, param);
496
507
  });
497
508
  }
498
509
  else {
499
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
500
- 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);
510
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
501
511
  }
502
512
  queryCount += rs.length;
503
513
  rs.forEach((r) => {
@@ -511,12 +521,12 @@ class _KQuery {
511
521
  catch (err) {
512
522
  throw err;
513
523
  }
514
- if (rs.length < queryBuilder_1.defaultLimit) {
524
+ if (rs.length < pageLimit) {
515
525
  break;
516
526
  }
517
527
  }
518
528
  }
519
- async walkRecordsByLimitOffset(handler) {
529
+ async walkRecordsByLimitOffset(handler, pageLimit) {
520
530
  const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
521
531
  let limit = 0, offset = 0, selectFields = [], orders = [];
522
532
  if (queryV2) {
@@ -540,38 +550,45 @@ class _KQuery {
540
550
  orders = [{ field: '_id', direction: 'asc', type: '' }];
541
551
  }
542
552
  let maxId = 0, queryCount = 0;
543
- for (let i = offset; !limit || i < offset + limit; i += queryBuilder_1.defaultLimit) {
553
+ let criterionV2;
554
+ let criterion;
555
+ if (appCtx) {
556
+ criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
557
+ criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
558
+ }
559
+ else {
560
+ criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
561
+ criterion = await (0, logic_1.handleCriterion)(criterion);
562
+ }
563
+ for (let i = offset; !limit || i < offset + limit; i += pageLimit) {
544
564
  let newLimit = function () {
545
565
  if (limit == 0) {
546
- return queryBuilder_1.defaultLimit;
566
+ return pageLimit;
547
567
  }
548
- if (offset + limit - i < queryBuilder_1.defaultLimit) {
568
+ if (offset + limit - i < pageLimit) {
549
569
  return offset + limit - i;
550
570
  }
551
- return queryBuilder_1.defaultLimit;
571
+ return pageLimit;
552
572
  }();
553
573
  if (newLimit <= 0) {
554
574
  break;
555
575
  }
556
576
  let rs;
557
577
  if (appCtx) {
558
- let criterion = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
559
- criterion.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
560
578
  const param = {
561
579
  limit: newLimit,
562
580
  offset: i,
563
581
  sort: orders,
564
582
  fields: selectFields,
565
583
  count: false,
566
- filter: criterion,
584
+ filter: criterionV2,
567
585
  };
568
586
  rs = await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
569
587
  return await Request.GetInstance().openSDKGetRecords(apiName, param);
570
588
  });
571
589
  }
572
590
  else {
573
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
574
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, orders, false, selectFields, i, newLimit, false, this.authType);
591
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, orders, false, selectFields, i, newLimit, false, this.authType);
575
592
  }
576
593
  queryCount += rs.length;
577
594
  try {
@@ -582,7 +599,7 @@ class _KQuery {
582
599
  catch (err) {
583
600
  throw err;
584
601
  }
585
- if (rs.length < queryBuilder_1.defaultLimit) {
602
+ if (rs.length < pageLimit) {
586
603
  break;
587
604
  }
588
605
  }
@@ -1,5 +1,5 @@
1
1
  import { IApprovalInstance, IApprovalInstanceListOptions, IApprovalInstanceList, IGetApprovalInstanceOptions } from '../../../request/structs';
2
- export declare function NewFlow(): Flow;
2
+ export declare function newFlow(context: any): Flow;
3
3
  export interface Flow {
4
4
  /**
5
5
  * 获取流程实例人工任务详情列表
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NewFlow = void 0;
3
+ exports.newFlow = void 0;
4
4
  const flow_1 = require("./impl/flow");
5
- function NewFlow() {
6
- return new flow_1.Flow();
5
+ function newFlow(context) {
6
+ return new flow_1.Flow(context?.flow);
7
7
  }
8
- exports.NewFlow = NewFlow;
8
+ exports.newFlow = newFlow;
@@ -1,6 +1,16 @@
1
- import { Flow as IFlow, ExecuteOptions, ExecutionResult, ExecutionInfo, FlowTaskInfo, RevokeExecutionOptions } from '../flow';
1
+ import { Flow as IFlow, ExecuteOptions, ExecutionResult, ExecutionInfo, FlowTaskInfo, RevokeExecutionOptions, Execution } from '../flow';
2
2
  import { IApprovalInstance, IApprovalInstanceList, IApprovalInstanceListOptions, IGetApprovalInstanceOptions } from "../../../../request/structs";
3
3
  export declare class Flow implements IFlow {
4
+ execution: Execution;
5
+ /**
6
+ * 工作流的 API name
7
+ */
8
+ apiName: string;
9
+ /**
10
+ * 工作流实例的 ID
11
+ */
12
+ instanceId: number;
13
+ constructor(flowParams: any);
4
14
  execute(APIName: string, options: ExecuteOptions | undefined): Promise<ExecutionResult>;
5
15
  getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
6
16
  getExecutionUserTaskInfo(executionId: number): Promise<FlowTaskInfo[]>;
@@ -5,6 +5,11 @@ const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions")
5
5
  const Request = require("../../../../request/interface");
6
6
  const server_common_node_1 = require("@byted-apaas/server-common-node");
7
7
  class Flow {
8
+ constructor(flowParams) {
9
+ this.execution = flowParams?.execution;
10
+ this.apiName = flowParams?.apiName;
11
+ this.instanceId = flowParams?.instanceId;
12
+ }
8
13
  async execute(APIName, options) {
9
14
  if (!APIName || typeof APIName !== 'string') {
10
15
  throw new exceptions_1.InvalidParamError(`param's type (${APIName}) need string, but is ${typeof APIName}`);
package/hooks/hooks.js CHANGED
@@ -95,7 +95,7 @@ function mountApplication(context) {
95
95
  }
96
96
  global.application.constants.metaType = metadataApi.metaType();
97
97
  // flow
98
- global.application.flow = (0, flow_1.NewFlow)();
98
+ global.application.flow = (0, flow_1.newFlow)(context);
99
99
  // operator
100
100
  global.application.operator = new operator_1.Operator();
101
101
  global.application.integration = new integration_1._Integration();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.1.15",
3
+ "version": "1.1.17-beta.1",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -13,7 +13,7 @@
13
13
  "clean": "tsc --build --clean && rm -rf **/*.js.map"
14
14
  },
15
15
  "dependencies": {
16
- "@byted-apaas/server-common-node": "^2.0.4",
16
+ "@byted-apaas/server-common-node": "^2.0.5",
17
17
  "@jorgeferrero/stream-to-buffer": "^2.0.6",
18
18
  "dayjs": "^1.9.6",
19
19
  "form-data": "^3.0.0",