rads-db 3.2.13 → 3.2.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.
package/dist/index.cjs CHANGED
@@ -1426,6 +1426,8 @@ function createRadsDbClient(dataSourceKey, args) {
1426
1426
  return generateMethods(s, validators, radsDbArgs);
1427
1427
  }
1428
1428
 
1429
+ exports.afterPut = afterPut;
1430
+ exports.beforePut = beforePut;
1429
1431
  exports.cleanEntity = cleanEntity;
1430
1432
  exports.computed = computed;
1431
1433
  exports.createRadsDb = createRadsDb;
package/dist/index.d.ts CHANGED
@@ -16,6 +16,15 @@ declare function getDriverInstance(schema: Schema, key: string, driverConstructo
16
16
 
17
17
  declare function handlePrecomputed(context: ComputedContext, docs: any[], ctx: RadsRequestContext): Promise<void>;
18
18
 
19
+ declare function beforePut(items: {
20
+ oldDoc: any;
21
+ doc: any;
22
+ }[], ctx: RadsRequestContext, computedContext: ComputedContext): Promise<void>;
23
+ declare function afterPut(items: {
24
+ oldDoc: any;
25
+ doc: any;
26
+ }[], ctx: RadsRequestContext, computedContext: ComputedContext): Promise<void>;
27
+
19
28
  /** Performs immutable deep merge */
20
29
  declare function merge<T extends Record<string, any>>(target: T, source: any): T;
21
30
 
@@ -35,4 +44,4 @@ declare function createRadsDb<T extends keyof RadsDb>(dataSourceKey: T, args?: C
35
44
  */
36
45
  declare function createRadsDbClient<T extends keyof RadsDb>(dataSourceKey: T, args?: CreateRadsDbClientArgs): RadsDb[T];
37
46
 
38
- export { ComputedContext, ComputedDecoratorArgs, CreateRadsDbArgs, CreateRadsDbClientArgs, Driver, DriverConstructor, EntityDecoratorArgs, FieldDecoratorArgs, RadsRequestContext, Schema, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
47
+ export { ComputedContext, ComputedDecoratorArgs, CreateRadsDbArgs, CreateRadsDbClientArgs, Driver, DriverConstructor, EntityDecoratorArgs, FieldDecoratorArgs, RadsRequestContext, Schema, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, afterPut, beforePut, cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
package/dist/index.mjs CHANGED
@@ -1419,4 +1419,4 @@ function createRadsDbClient(dataSourceKey, args) {
1419
1419
  return generateMethods(s, validators, radsDbArgs);
1420
1420
  }
1421
1421
 
1422
- export { cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
1422
+ export { afterPut, beforePut, cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
@@ -113,14 +113,15 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
113
113
  updatedEvents: v.updatedEvents,
114
114
  oldDoc: v.oldAggDoc
115
115
  }));
116
+ console.log(ctx);
116
117
  const aggregateEffectContext = {
117
118
  ...context,
118
119
  typeName: entityName,
119
120
  handle: schema[entityName].handle
120
121
  };
121
- await beforePut(hookItems, ctx, aggregateEffectContext);
122
+ await (0, _radsDb.beforePut)(hookItems, ctx, aggregateEffectContext);
122
123
  await context.drivers[entityName].putMany(aggs, ctx);
123
- await afterPut(hookItems, ctx, aggregateEffectContext);
124
+ await (0, _radsDb.afterPut)(hookItems, ctx, aggregateEffectContext);
124
125
  }
125
126
  };
126
127
  }
@@ -189,14 +190,4 @@ function validateSchemaField(fieldName, eventEntityName, expectedFields, schema)
189
190
  const expectedRequired = expectedField.isRequired ? `required` : "optional";
190
191
  throw new Error(`"${eventEntityName}.${fieldName}" must be ${expectedRequired}`);
191
192
  }
192
- }
193
- async function beforePut(items, ctx, computedContext) {
194
- for (const f of computedContext.options.features) {
195
- await f.beforePut?.(items, ctx, computedContext);
196
- }
197
- }
198
- async function afterPut(items, ctx, computedContext) {
199
- for (const f of computedContext.options.features) {
200
- await f.afterPut?.(items, ctx, computedContext);
201
- }
202
193
  }
@@ -1,5 +1,5 @@
1
1
  import _ from "lodash";
2
- import { cleanEntity, diff, handlePrecomputed, merge } from "rads-db";
2
+ import { afterPut, beforePut, cleanEntity, diff, handlePrecomputed, merge } from "rads-db";
3
3
  export default (options) => {
4
4
  return {
5
5
  name: "eventSourcing",
@@ -97,6 +97,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
97
97
  updatedEvents: v.updatedEvents,
98
98
  oldDoc: v.oldAggDoc
99
99
  }));
100
+ console.log(ctx);
100
101
  const aggregateEffectContext = { ...context, typeName: entityName, handle: schema[entityName].handle };
101
102
  await beforePut(hookItems, ctx, aggregateEffectContext);
102
103
  await context.drivers[entityName].putMany(aggs, ctx);
@@ -157,13 +158,3 @@ function validateSchemaField(fieldName, eventEntityName, expectedFields, schema)
157
158
  throw new Error(`"${eventEntityName}.${fieldName}" must be ${expectedRequired}`);
158
159
  }
159
160
  }
160
- async function beforePut(items, ctx, computedContext) {
161
- for (const f of computedContext.options.features) {
162
- await f.beforePut?.(items, ctx, computedContext);
163
- }
164
- }
165
- async function afterPut(items, ctx, computedContext) {
166
- for (const f of computedContext.options.features) {
167
- await f.afterPut?.(items, ctx, computedContext);
168
- }
169
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.2.13",
3
+ "version": "3.2.14",
4
4
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
5
5
  "author": "",
6
6
  "license": "ISC",