rads-db 3.0.38 → 3.0.40

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.d.ts CHANGED
@@ -291,15 +291,17 @@ interface ComputedContext extends ComputedContextGlobal {
291
291
  typeName: string;
292
292
  handle: string;
293
293
  }
294
+ interface RadsHookDoc {
295
+ /** Updated document that will be saved to the database */
296
+ doc: any;
297
+ /** Previous version of document - i.e. one that is currently in the database (before saving) */
298
+ oldDoc: any;
299
+ /** If current entity is event sourcing aggregate, you can access all events in the chronological order */
300
+ events?: any;
301
+ }
294
302
  interface PutEffect {
295
- beforePut?: (computedContext: ComputedContext, docs: {
296
- oldDoc: any;
297
- doc: any;
298
- }[], ctx: RadsRequestContext) => MaybePromise<any>;
299
- afterPut: (computedContext: ComputedContext, docs: {
300
- oldDoc: any;
301
- doc: any;
302
- }[], beforePutResult: any, ctx: RadsRequestContext) => MaybePromise<any>;
303
+ beforePut?: (computedContext: ComputedContext, docs: RadsHookDoc[], ctx: RadsRequestContext) => MaybePromise<any>;
304
+ afterPut: (computedContext: ComputedContext, docs: RadsHookDoc[], beforePutResult: any, ctx: RadsRequestContext) => MaybePromise<any>;
303
305
  }
304
306
  interface RestFileUploadDriverOptions {
305
307
  /** @default '/api' */
@@ -371,14 +373,8 @@ interface RadsFeature {
371
373
  enhanceEntityMethods?: (context: ComputedContext, entityMethodsObj: EntityMethods<any, any, any>) => void;
372
374
  beforeGet?: (args: GetArgsAny, ctx: RadsRequestContext, context: ComputedContext) => MaybePromise<any>;
373
375
  afterGet?: (items: any[], args: GetArgsAny, ctx: RadsRequestContext, context: ComputedContext) => MaybePromise<void>;
374
- beforePut?: (items: {
375
- oldDoc: any;
376
- doc: any;
377
- }[], ctx: RadsRequestContext, computedContext: ComputedContext) => void;
378
- afterPut?: (items: {
379
- oldDoc: any;
380
- doc: any;
381
- }[], ctx: RadsRequestContext, computedContext: ComputedContext) => void;
376
+ beforePut?: (items: RadsHookDoc[], ctx: RadsRequestContext, computedContext: ComputedContext) => void;
377
+ afterPut?: (items: RadsHookDoc[], ctx: RadsRequestContext, computedContext: ComputedContext) => void;
382
378
  beforeUploadFile?: (args: FileUploadArgs) => MaybePromise<any>;
383
379
  afterUploadFile?: (result: FileUploadResult, args: FileUploadArgs) => MaybePromise<void>;
384
380
  }
@@ -414,4 +410,4 @@ declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
414
410
  */
415
411
  declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
416
412
 
417
- export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
413
+ export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsHookDoc, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
@@ -104,9 +104,14 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
104
104
  events: v.events,
105
105
  oldDoc: v.oldAggDoc
106
106
  }));
107
- await beforePut(hookItems, ctx, context);
107
+ const aggregateEffectContext = {
108
+ ...context,
109
+ typeName: entityName,
110
+ handle: schema[entityName].handle
111
+ };
112
+ await beforePut(hookItems, ctx, aggregateEffectContext);
108
113
  await context.drivers[entityName].putMany(aggs, ctx);
109
- await afterPut(hookItems, ctx, context);
114
+ await afterPut(hookItems, ctx, aggregateEffectContext);
110
115
  }
111
116
  };
112
117
  }
@@ -87,9 +87,10 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
87
87
  async afterPut(context, docs, beforePutResult, ctx) {
88
88
  const aggs = beforePutResult.map((d) => d.aggDoc);
89
89
  const hookItems = beforePutResult.map((v) => ({ doc: v.aggDoc, events: v.events, oldDoc: v.oldAggDoc }));
90
- await beforePut(hookItems, ctx, context);
90
+ const aggregateEffectContext = { ...context, typeName: entityName, handle: schema[entityName].handle };
91
+ await beforePut(hookItems, ctx, aggregateEffectContext);
91
92
  await context.drivers[entityName].putMany(aggs, ctx);
92
- await afterPut(hookItems, ctx, context);
93
+ await afterPut(hookItems, ctx, aggregateEffectContext);
93
94
  }
94
95
  };
95
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.38",
3
+ "version": "3.0.40",
4
4
  "files": [
5
5
  "dist",
6
6
  "drivers",