rads-db 3.2.18 → 3.2.20

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.
@@ -73,10 +73,12 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
73
73
  const newAggDoc = context.validators[entityName]((0, _radsDb.merge)(aggDoc || {
74
74
  id: aggId
75
75
  }, ev.change));
76
- ev.beforeChange = aggDoc;
77
- const originalChange = ev.change;
78
- ev.change = (0, _radsDb.diff)(newAggDoc, aggDoc);
79
- handleKeepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
76
+ if (!options.freezeEvent?.(ev, context, ctx)) {
77
+ ev.beforeChange = aggDoc;
78
+ const originalChange = ev.change;
79
+ ev.change = (0, _radsDb.diff)(newAggDoc, aggDoc);
80
+ handleKeepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
81
+ }
80
82
  if (options.applyEventIf && !options.applyEventIf(ev, context, ctx)) {
81
83
  continue;
82
84
  }
@@ -1,6 +1,7 @@
1
1
  import type { ComputedContext, RadsFeature, RadsRequestContext } from '@/types';
2
2
  export interface EventSourcingFeatureOptions {
3
3
  applyEventIf?: (event: any, context: ComputedContext, ctx: RadsRequestContext) => boolean;
4
+ freezeEvent?: (event: any, context: ComputedContext, ctx: RadsRequestContext) => boolean;
4
5
  }
5
6
  declare const _default: (options?: EventSourcingFeatureOptions) => RadsFeature;
6
7
  export default _default;
@@ -62,10 +62,12 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
62
62
  let aggDoc;
63
63
  for (const ev of events) {
64
64
  const newAggDoc = context.validators[entityName](merge(aggDoc || { id: aggId }, ev.change));
65
- ev.beforeChange = aggDoc;
66
- const originalChange = ev.change;
67
- ev.change = diff(newAggDoc, aggDoc);
68
- handleKeepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
65
+ if (!options.freezeEvent?.(ev, context, ctx)) {
66
+ ev.beforeChange = aggDoc;
67
+ const originalChange = ev.change;
68
+ ev.change = diff(newAggDoc, aggDoc);
69
+ handleKeepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
70
+ }
69
71
  if (options.applyEventIf && !options.applyEventIf(ev, context, ctx)) {
70
72
  continue;
71
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.2.18",
3
+ "version": "3.2.20",
4
4
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
5
5
  "author": "",
6
6
  "license": "ISC",