@punks/backend-entity-manager 0.0.144 → 0.0.146

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.
@@ -4,7 +4,6 @@ export type FacetValueType<T> = {
4
4
  };
5
5
  export type FacetType<T> = {
6
6
  values: FacetValueType<T>[];
7
- field: string;
8
7
  };
9
8
  export type StringFacetsType = FacetType<string>;
10
9
  export type NumberFacetsType = FacetType<number>;
@@ -15,6 +15,7 @@ export declare class PipelineInstance<TPipelineInput, TPipelineOutput, TContext>
15
15
  private validateStepPrecondition;
16
16
  private executeStep;
17
17
  private executeOperation;
18
+ private shouldSkipOperation;
18
19
  private rollbackOperations;
19
20
  private rollbackOperation;
20
21
  }
@@ -0,0 +1,4 @@
1
+ import { PipelineOperationResultType, PipelineOperationRollbackResultType, PipelineStepResultType } from "../../../types";
2
+ export declare const isOperationSuccessStatus: (type: PipelineOperationResultType) => boolean;
3
+ export declare const isOperationRollbackErrorStatus: (type: PipelineOperationRollbackResultType) => boolean;
4
+ export declare const isStepSuccessStatus: (type: PipelineStepResultType) => boolean;
@@ -12,6 +12,7 @@ export type OperationDefinition<TOperationInput, TOperationOutput, TCurrentStepI
12
12
  name: string;
13
13
  action: (input: TOperationInput, state: PipelineCurrentStepState<TPipelineInput, TContext, TCurrentStepInput>) => Promise<TOperationOutput> | TOperationOutput;
14
14
  precondition?: (input: TOperationInput, state: PipelineCurrentStepState<TPipelineInput, TContext, TCurrentStepInput>) => Promise<boolean> | boolean;
15
+ skipIf?: (input: TOperationInput, state: PipelineCurrentStepState<TPipelineInput, TContext, TCurrentStepInput>) => Promise<boolean> | boolean;
15
16
  };
16
17
  export type RollbackOperationDefinition<TOperationInput, TOperationOutput, TCurrentStepInput, TPipelineInput, TContext> = {
17
18
  name: string;
@@ -39,6 +40,8 @@ export type PipelineOperationResult<TOperationInput, TOperationOutput> = {
39
40
  } & ({
40
41
  type: "success";
41
42
  output: TOperationOutput;
43
+ } | {
44
+ type: "skipped";
42
45
  } | {
43
46
  type: "preconditionFailed";
44
47
  } | {
package/dist/esm/index.js CHANGED
@@ -21158,6 +21158,11 @@ const mapPipelineErrorType = (stepError) => {
21158
21158
  }
21159
21159
  };
21160
21160
 
21161
+ const isOperationSuccessStatus = (type) => {
21162
+ return ["success", "skipped"].includes(type);
21163
+ };
21164
+ const isOperationRollbackErrorStatus = (type) => ["error"].includes(type);
21165
+
21161
21166
  class PipelineInstance {
21162
21167
  constructor(definition, input, context) {
21163
21168
  this.definition = definition;
@@ -21234,10 +21239,9 @@ class PipelineInstance {
21234
21239
  result: x,
21235
21240
  operation: step.operations[i],
21236
21241
  }));
21237
- // .filter((x) => x.result.type === "success")
21238
21242
  const rollbackOperations = completedOperations.map((x) => this.rollbackOperations(x.operation, x.result.input, getOperationOutput(x.result), state));
21239
21243
  const rollbackResults = await Promise.all(rollbackOperations);
21240
- const isRollbackError = rollbackResults.some((x) => x.type === "error");
21244
+ const isRollbackError = rollbackResults.some((x) => isOperationRollbackErrorStatus(x.type));
21241
21245
  if (isRollbackError) {
21242
21246
  return {
21243
21247
  type: "error",
@@ -21268,7 +21272,7 @@ class PipelineInstance {
21268
21272
  }
21269
21273
  const stepOperations = step.operations.map((x) => this.executeOperation(x, input, state));
21270
21274
  const operationResults = await Promise.all(stepOperations);
21271
- const isSuccess = operationResults.every((x) => x.type === "success");
21275
+ const isSuccess = operationResults.every((x) => isOperationSuccessStatus(x.type));
21272
21276
  if (isSuccess) {
21273
21277
  const output = step.outputsReducer
21274
21278
  ? step.outputsReducer(operationResults.map((x) => getOperationOutput(x)))
@@ -21289,6 +21293,16 @@ class PipelineInstance {
21289
21293
  }
21290
21294
  async executeOperation(operation, input, state) {
21291
21295
  try {
21296
+ const shouldSkip = await this.shouldSkipOperation(operation, input, state);
21297
+ if (shouldSkip) {
21298
+ this.logger.info(`Pipeline operation skipped -> operation:${operation.name}`, {
21299
+ input,
21300
+ });
21301
+ return {
21302
+ type: "skipped",
21303
+ input,
21304
+ };
21305
+ }
21292
21306
  const operationResult = await operation.operation.action(input, state);
21293
21307
  return {
21294
21308
  type: "success",
@@ -21307,6 +21321,12 @@ class PipelineInstance {
21307
21321
  };
21308
21322
  }
21309
21323
  }
21324
+ async shouldSkipOperation({ operation, }, input, state) {
21325
+ if (!operation.skipIf) {
21326
+ return false;
21327
+ }
21328
+ return await operation.skipIf(input, state);
21329
+ }
21310
21330
  async rollbackOperations(operation, operationInput, operationOutput, state) {
21311
21331
  if (!operation.rollbackOperations?.length) {
21312
21332
  return {
@@ -22239,8 +22259,10 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
22239
22259
  .orderBy(field)
22240
22260
  .getRawMany();
22241
22261
  return {
22242
- field: field,
22243
- values: results,
22262
+ values: results.map((x) => ({
22263
+ value: x.value,
22264
+ count: Number(x.count),
22265
+ })),
22244
22266
  };
22245
22267
  }
22246
22268
  async calculateStringFieldFacets(field, request, context) {