rads-db 3.0.62 → 3.0.63

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
@@ -748,7 +748,8 @@ async function downloadRelatedDocuments(args) {
748
748
 
749
749
  function getRadsDbMethods(key, computedContext, driverInstance) {
750
750
  const { schema, options, validators } = computedContext;
751
- const { precomputedFields } = schema[key];
751
+ const entitySchema = schema[key];
752
+ const { precomputedFields } = entitySchema;
752
753
  async function getMany(args, ctx) {
753
754
  args = { ...args, where: { ...args?.where } };
754
755
  ctx = { ...options.context, ...ctx, method: "getMany" };
@@ -824,8 +825,19 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
824
825
  }
825
826
  if (!options.keepNulls)
826
827
  cleanUndefinedAndNull(doc);
827
- return { oldDoc, doc };
828
+ return { oldDoc, doc, events: [] };
828
829
  });
830
+ if (entitySchema.decorators.precomputed?.preset === "eventSourcing") {
831
+ const eventEntity = `${key}Event`;
832
+ const aggregateRelationField = ___default.lowerFirst(key);
833
+ const eventDriver = computedContext.drivers[eventEntity];
834
+ for (const d of docArgsToSave) {
835
+ d.events = await eventDriver.getAll(
836
+ { where: { [aggregateRelationField]: { id: d.doc.id } }, orderBy: "date_asc" },
837
+ ctx
838
+ );
839
+ }
840
+ }
829
841
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
830
842
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
831
843
  await beforePut(docArgsToSave, ctx, computedContext);
package/dist/index.mjs CHANGED
@@ -741,7 +741,8 @@ async function downloadRelatedDocuments(args) {
741
741
 
742
742
  function getRadsDbMethods(key, computedContext, driverInstance) {
743
743
  const { schema, options, validators } = computedContext;
744
- const { precomputedFields } = schema[key];
744
+ const entitySchema = schema[key];
745
+ const { precomputedFields } = entitySchema;
745
746
  async function getMany(args, ctx) {
746
747
  args = { ...args, where: { ...args?.where } };
747
748
  ctx = { ...options.context, ...ctx, method: "getMany" };
@@ -817,8 +818,19 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
817
818
  }
818
819
  if (!options.keepNulls)
819
820
  cleanUndefinedAndNull(doc);
820
- return { oldDoc, doc };
821
+ return { oldDoc, doc, events: [] };
821
822
  });
823
+ if (entitySchema.decorators.precomputed?.preset === "eventSourcing") {
824
+ const eventEntity = `${key}Event`;
825
+ const aggregateRelationField = _.lowerFirst(key);
826
+ const eventDriver = computedContext.drivers[eventEntity];
827
+ for (const d of docArgsToSave) {
828
+ d.events = await eventDriver.getAll(
829
+ { where: { [aggregateRelationField]: { id: d.doc.id } }, orderBy: "date_asc" },
830
+ ctx
831
+ );
832
+ }
833
+ }
822
834
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
823
835
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
824
836
  await beforePut(docArgsToSave, ctx, computedContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.62",
3
+ "version": "3.0.63",
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": "",