rads-db 3.1.5 → 3.1.6

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/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { g as RadsConfig, T as TypeDefinition } from './types-7e792d1f.js';
1
+ import { g as RadsConfig, T as TypeDefinition } from './types-1bda441b.js';
2
2
  import '_rads-db';
3
3
 
4
4
  declare function defineRadsConfig(config: RadsConfig): RadsConfig;
package/dist/index.cjs CHANGED
@@ -387,8 +387,8 @@ async function handlePrecomputed(context, docs, ctx) {
387
387
  if (!handler)
388
388
  throw new Error(`Computed handler for ${typeName}.${fieldName} was not found`);
389
389
  }
390
- const precomputedResults = docs.map(async ({ doc, oldDoc, events }) => {
391
- doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, db, ctx });
390
+ const precomputedResults = docs.map(async ({ doc, oldDoc, events, updatedEvents }) => {
391
+ doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, updatedEvents, db, ctx });
392
392
  });
393
393
  await Promise.all(precomputedResults);
394
394
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as EntityDecoratorArgs, U as UiDecoratorArgs, a as UiFieldDecoratorArgs, V as ValidateEntityDecoratorArgs, b as ValidateFieldDecoratorArgs, F as FieldDecoratorArgs, C as ComputedDecoratorArgs, S as Schema, D as DriverConstructor, c as Driver, d as ComputedContext, R as RadsRequestContext, e as CreateRadsDbArgs, f as CreateRadsDbClientArgs } from './types-7e792d1f.js';
2
- export { N as Change, x as ComputedContextGlobal, k as CreateRadsArgsDrivers, m as CreateRadsDbArgsNormalized, aj as DeepKeys, ae as DeepPartial, ac as DeepPartialWithNulls, ad as DeepPartialWithNullsItem, ak as EntityMethods, w as EnumDefinition, v as FieldDefinition, I as FileSystemNode, u as FileUploadArgs, q as FileUploadDriver, p as FileUploadResult, B as GenerateClientNormalizedOptions, A as GenerateClientOptions, a8 as Get, _ as GetAggArgs, $ as GetAggArgsAgg, a2 as GetAggArgsAny, a5 as GetAggResponse, Z as GetArgs, a1 as GetArgsAny, a4 as GetArgsInclude, O as GetManyArgs, a0 as GetManyArgsAny, a6 as GetManyResponse, a7 as GetResponse, a9 as GetResponseInclude, aa as GetResponseIncludeSelect, ab as GetResponseNoInclude, s as GetRestRoutesArgs, G as GetRestRoutesOptions, t as GetRestRoutesResponse, ag as InverseRelation, M as MinimalDriver, ai as Put, ah as PutArgs, P as PutEffect, g as RadsConfig, h as RadsConfigDataSource, r as RadsDbInstance, L as RadsFeature, y as RadsHookDoc, K as RadsUiSlotDefinition, J as RadsUiSlotName, H as RadsVitePluginOptions, af as Relation, i as RequiredFields, l as RestDriverOptions, z as RestFileUploadDriverOptions, n as SchemaLoadResult, o as SchemaValidators, T as TypeDefinition, j as ValidateStringDecoratorArgs, Q as VerifyManyArgs, a3 as VerifyManyArgsAny, X as VerifyManyResponse, Y as Where, W as WhereJsonContains } from './types-7e792d1f.js';
1
+ import { E as EntityDecoratorArgs, U as UiDecoratorArgs, a as UiFieldDecoratorArgs, V as ValidateEntityDecoratorArgs, b as ValidateFieldDecoratorArgs, F as FieldDecoratorArgs, C as ComputedDecoratorArgs, S as Schema, D as DriverConstructor, c as Driver, d as ComputedContext, R as RadsRequestContext, e as CreateRadsDbArgs, f as CreateRadsDbClientArgs } from './types-1bda441b.js';
2
+ export { N as Change, x as ComputedContextGlobal, k as CreateRadsArgsDrivers, m as CreateRadsDbArgsNormalized, aj as DeepKeys, ae as DeepPartial, ac as DeepPartialWithNulls, ad as DeepPartialWithNullsItem, ak as EntityMethods, w as EnumDefinition, v as FieldDefinition, I as FileSystemNode, u as FileUploadArgs, q as FileUploadDriver, p as FileUploadResult, B as GenerateClientNormalizedOptions, A as GenerateClientOptions, a8 as Get, _ as GetAggArgs, $ as GetAggArgsAgg, a2 as GetAggArgsAny, a5 as GetAggResponse, Z as GetArgs, a1 as GetArgsAny, a4 as GetArgsInclude, O as GetManyArgs, a0 as GetManyArgsAny, a6 as GetManyResponse, a7 as GetResponse, a9 as GetResponseInclude, aa as GetResponseIncludeSelect, ab as GetResponseNoInclude, s as GetRestRoutesArgs, G as GetRestRoutesOptions, t as GetRestRoutesResponse, ag as InverseRelation, M as MinimalDriver, ai as Put, ah as PutArgs, P as PutEffect, g as RadsConfig, h as RadsConfigDataSource, r as RadsDbInstance, L as RadsFeature, y as RadsHookDoc, K as RadsUiSlotDefinition, J as RadsUiSlotName, H as RadsVitePluginOptions, af as Relation, i as RequiredFields, l as RestDriverOptions, z as RestFileUploadDriverOptions, n as SchemaLoadResult, o as SchemaValidators, T as TypeDefinition, j as ValidateStringDecoratorArgs, Q as VerifyManyArgs, a3 as VerifyManyArgsAny, X as VerifyManyResponse, Y as Where, W as WhereJsonContains } from './types-1bda441b.js';
3
3
  import { RadsDb } from '_rads-db';
4
4
  export { RadsDb } from '_rads-db';
5
5
 
package/dist/index.mjs CHANGED
@@ -380,8 +380,8 @@ async function handlePrecomputed(context, docs, ctx) {
380
380
  if (!handler)
381
381
  throw new Error(`Computed handler for ${typeName}.${fieldName} was not found`);
382
382
  }
383
- const precomputedResults = docs.map(async ({ doc, oldDoc, events }) => {
384
- doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, db, ctx });
383
+ const precomputedResults = docs.map(async ({ doc, oldDoc, events, updatedEvents }) => {
384
+ doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, updatedEvents, db, ctx });
385
385
  });
386
386
  await Promise.all(precomputedResults);
387
387
  }
@@ -355,7 +355,8 @@ interface RadsHookDoc {
355
355
  /** Previous version of document - i.e. one that is currently in the database (before saving) */
356
356
  oldDoc: any;
357
357
  /** If current entity is event sourcing aggregate, you can access all events in the chronological order */
358
- events?: any;
358
+ events?: any[];
359
+ updatedEvents?: any[];
359
360
  }
360
361
  interface PutEffect {
361
362
  beforePut?: (computedContext: ComputedContext, docs: RadsHookDoc[], ctx: RadsRequestContext) => MaybePromise<any>;
@@ -82,6 +82,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
82
82
  result.push({
83
83
  aggDoc,
84
84
  events,
85
+ updatedEvents: events.filter(ev => docsById[ev.id]),
85
86
  oldAggDoc: existingAggregatesById[aggDoc.id]
86
87
  });
87
88
  }
@@ -93,6 +94,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
93
94
  }, result.map(v => ({
94
95
  doc: v.aggDoc,
95
96
  events: v.events,
97
+ updatedEvents: v.updatedEvents,
96
98
  oldDoc: v.oldAggDoc
97
99
  })), ctx);
98
100
  return result;
@@ -102,6 +104,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
102
104
  const hookItems = beforePutResult.map(v => ({
103
105
  doc: v.aggDoc,
104
106
  events: v.events,
107
+ updatedEvents: v.updatedEvents,
105
108
  oldDoc: v.oldAggDoc
106
109
  }));
107
110
  const aggregateEffectContext = {
@@ -74,19 +74,29 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
74
74
  if (!context.options.keepNulls)
75
75
  cleanUndefinedAndNull(aggDoc);
76
76
  }
77
- result.push({ aggDoc, events, oldAggDoc: existingAggregatesById[aggDoc.id] });
77
+ result.push({
78
+ aggDoc,
79
+ events,
80
+ updatedEvents: events.filter((ev) => docsById[ev.id]),
81
+ oldAggDoc: existingAggregatesById[aggDoc.id]
82
+ });
78
83
  }
79
84
  await handlePrecomputed(
80
85
  // @ts-expect-error TODO wrong types
81
86
  { ...context, typeName: entityName },
82
- result.map((v) => ({ doc: v.aggDoc, events: v.events, oldDoc: v.oldAggDoc })),
87
+ result.map((v) => ({ doc: v.aggDoc, events: v.events, updatedEvents: v.updatedEvents, oldDoc: v.oldAggDoc })),
83
88
  ctx
84
89
  );
85
90
  return result;
86
91
  },
87
92
  async afterPut(context, docs, beforePutResult, ctx) {
88
93
  const aggs = beforePutResult.map((d) => d.aggDoc);
89
- const hookItems = beforePutResult.map((v) => ({ doc: v.aggDoc, events: v.events, oldDoc: v.oldAggDoc }));
94
+ const hookItems = beforePutResult.map((v) => ({
95
+ doc: v.aggDoc,
96
+ events: v.events,
97
+ updatedEvents: v.updatedEvents,
98
+ oldDoc: v.oldAggDoc
99
+ }));
90
100
  const aggregateEffectContext = { ...context, typeName: entityName, handle: schema[entityName].handle };
91
101
  await beforePut(hookItems, ctx, aggregateEffectContext);
92
102
  await context.drivers[entityName].putMany(aggs, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "packageManager": "pnpm@8.6.1",
5
5
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
6
6
  "author": "",