rads-db 3.1.13 → 3.1.14

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.
@@ -63,9 +63,6 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
63
63
  const result = [];
64
64
  for (const aggId in docsByAggId) {
65
65
  let events = _lodash.default.orderBy([...docsByAggId[aggId], ...(existingEventsByAggId[aggId] || [])], ["date"], "asc");
66
- if (options.applyEventIf) {
67
- events = events.filter(ev => options.applyEventIf(ev, context, ctx));
68
- }
69
66
  if (events[0].type !== "creation") throw new Error(`First event must have type = "creation". (type: ${events[0].type}, id: ${events[0].id})`);
70
67
  if (events.slice(1).some(ev => ev.type === "creation")) {
71
68
  throw new Error(`Only first event may have type = "creation"`);
@@ -79,6 +76,9 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
79
76
  const originalChange = ev.change;
80
77
  ev.change = (0, _radsDb.diff)(newAggDoc, aggDoc);
81
78
  handleKeepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
79
+ if (options.applyEventIf && !options.applyEventIf(ev, context, ctx)) {
80
+ continue;
81
+ }
82
82
  aggDoc = newAggDoc;
83
83
  if (!context.options.keepNulls) (0, _radsDb.cleanUndefinedAndNull)(aggDoc);
84
84
  }
@@ -53,9 +53,6 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
53
53
  const result = [];
54
54
  for (const aggId in docsByAggId) {
55
55
  let events = _.orderBy([...docsByAggId[aggId], ...existingEventsByAggId[aggId] || []], ["date"], "asc");
56
- if (options.applyEventIf) {
57
- events = events.filter((ev) => options.applyEventIf(ev, context, ctx));
58
- }
59
56
  if (events[0].type !== "creation")
60
57
  throw new Error(`First event must have type = "creation". (type: ${events[0].type}, id: ${events[0].id})`);
61
58
  if (events.slice(1).some((ev) => ev.type === "creation")) {
@@ -68,6 +65,9 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
68
65
  const originalChange = ev.change;
69
66
  ev.change = diff(newAggDoc, aggDoc);
70
67
  handleKeepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
68
+ if (options.applyEventIf && !options.applyEventIf(ev, context, ctx)) {
69
+ continue;
70
+ }
71
71
  aggDoc = newAggDoc;
72
72
  if (!context.options.keepNulls) cleanUndefinedAndNull(aggDoc);
73
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.1.13",
3
+ "version": "3.1.14",
4
4
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
5
5
  "author": "",
6
6
  "license": "ISC",