@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.
package/dist/cjs/index.js CHANGED
@@ -21166,6 +21166,11 @@ const mapPipelineErrorType = (stepError) => {
21166
21166
  }
21167
21167
  };
21168
21168
 
21169
+ const isOperationSuccessStatus = (type) => {
21170
+ return ["success", "skipped"].includes(type);
21171
+ };
21172
+ const isOperationRollbackErrorStatus = (type) => ["error"].includes(type);
21173
+
21169
21174
  class PipelineInstance {
21170
21175
  constructor(definition, input, context) {
21171
21176
  this.definition = definition;
@@ -21242,10 +21247,9 @@ class PipelineInstance {
21242
21247
  result: x,
21243
21248
  operation: step.operations[i],
21244
21249
  }));
21245
- // .filter((x) => x.result.type === "success")
21246
21250
  const rollbackOperations = completedOperations.map((x) => this.rollbackOperations(x.operation, x.result.input, getOperationOutput(x.result), state));
21247
21251
  const rollbackResults = await Promise.all(rollbackOperations);
21248
- const isRollbackError = rollbackResults.some((x) => x.type === "error");
21252
+ const isRollbackError = rollbackResults.some((x) => isOperationRollbackErrorStatus(x.type));
21249
21253
  if (isRollbackError) {
21250
21254
  return {
21251
21255
  type: "error",
@@ -21276,7 +21280,7 @@ class PipelineInstance {
21276
21280
  }
21277
21281
  const stepOperations = step.operations.map((x) => this.executeOperation(x, input, state));
21278
21282
  const operationResults = await Promise.all(stepOperations);
21279
- const isSuccess = operationResults.every((x) => x.type === "success");
21283
+ const isSuccess = operationResults.every((x) => isOperationSuccessStatus(x.type));
21280
21284
  if (isSuccess) {
21281
21285
  const output = step.outputsReducer
21282
21286
  ? step.outputsReducer(operationResults.map((x) => getOperationOutput(x)))
@@ -21297,6 +21301,16 @@ class PipelineInstance {
21297
21301
  }
21298
21302
  async executeOperation(operation, input, state) {
21299
21303
  try {
21304
+ const shouldSkip = await this.shouldSkipOperation(operation, input, state);
21305
+ if (shouldSkip) {
21306
+ this.logger.info(`Pipeline operation skipped -> operation:${operation.name}`, {
21307
+ input,
21308
+ });
21309
+ return {
21310
+ type: "skipped",
21311
+ input,
21312
+ };
21313
+ }
21300
21314
  const operationResult = await operation.operation.action(input, state);
21301
21315
  return {
21302
21316
  type: "success",
@@ -21315,6 +21329,12 @@ class PipelineInstance {
21315
21329
  };
21316
21330
  }
21317
21331
  }
21332
+ async shouldSkipOperation({ operation, }, input, state) {
21333
+ if (!operation.skipIf) {
21334
+ return false;
21335
+ }
21336
+ return await operation.skipIf(input, state);
21337
+ }
21318
21338
  async rollbackOperations(operation, operationInput, operationOutput, state) {
21319
21339
  if (!operation.rollbackOperations?.length) {
21320
21340
  return {
@@ -22247,8 +22267,10 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
22247
22267
  .orderBy(field)
22248
22268
  .getRawMany();
22249
22269
  return {
22250
- field: field,
22251
- values: results,
22270
+ values: results.map((x) => ({
22271
+ value: x.value,
22272
+ count: Number(x.count),
22273
+ })),
22252
22274
  };
22253
22275
  }
22254
22276
  async calculateStringFieldFacets(field, request, context) {