rads-db 3.2.17 → 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.
package/dist/index.cjs CHANGED
@@ -1247,7 +1247,8 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1247
1247
  async put(data, ctx) {
1248
1248
  if (!data)
1249
1249
  throw new Error("Data is required");
1250
- await driverInstance.putMany([data], ctx);
1250
+ const response = await driverInstance.putMany([data], ctx);
1251
+ return response?.[0];
1251
1252
  },
1252
1253
  deleteMany(args, ctx) {
1253
1254
  throw new Error(`"deleteMany" not supported for driver "${driverInstance.driverName}"`);
package/dist/index.mjs CHANGED
@@ -1240,7 +1240,8 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1240
1240
  async put(data, ctx) {
1241
1241
  if (!data)
1242
1242
  throw new Error("Data is required");
1243
- await driverInstance.putMany([data], ctx);
1243
+ const response = await driverInstance.putMany([data], ctx);
1244
+ return response?.[0];
1244
1245
  },
1245
1246
  deleteMany(args, ctx) {
1246
1247
  throw new Error(`"deleteMany" not supported for driver "${driverInstance.driverName}"`);
@@ -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.17",
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",