rads-db 3.0.62 → 3.0.66

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);
@@ -139,7 +139,7 @@ ${whereFields.join("\n")}
139
139
  }
140
140
  `.trim()).join("\n");
141
141
  return `
142
- import type { EntityMethods, FileUploadArgs, RadsRequestContext, WhereJsonContains } from 'rads-db'
142
+ import type { EntityMethods, FileUploadArgs, RadsRequestContext, WhereJsonContains, Relation, Change } from 'rads-db'
143
143
  ${imports.join("\n")}
144
144
  ${schemaTypesStr}
145
145
 
@@ -175,7 +175,7 @@ function getEntityTypesStrFromSchema(schema) {
175
175
  if (f.isChange) fieldTypeStr = `Change<${fieldTypeStr}>`;
176
176
  if (f.isRelation) fieldTypeStr = `Relation<${fieldTypeStr}>`;
177
177
  if (f.isArray) fieldTypeStr = `${fieldTypeStr}[]`;
178
- const fieldStr = ` ${f.name}${f.isRequired ? "!" : "?"}: ${fieldTypeStr}`;
178
+ const fieldStr = ` ${f.name}${f.isRequired ? "" : "?"}: ${fieldTypeStr}`;
179
179
  const commentStr2 = f.comment ? ` /** ${f.comment} */` : "";
180
180
  return [fieldStr, commentStr2].filter(x => x).join("\n");
181
181
  }).filter(x => x).join("\n");
@@ -139,7 +139,7 @@ ${whereFields.join("\n")}
139
139
  `.trim()
140
140
  ).join("\n");
141
141
  return `
142
- import type { EntityMethods, FileUploadArgs, RadsRequestContext, WhereJsonContains } from 'rads-db'
142
+ import type { EntityMethods, FileUploadArgs, RadsRequestContext, WhereJsonContains, Relation, Change } from 'rads-db'
143
143
  ${imports.join("\n")}
144
144
  ${schemaTypesStr}
145
145
 
@@ -181,7 +181,7 @@ export function getEntityTypesStrFromSchema(schema) {
181
181
  fieldTypeStr = `Relation<${fieldTypeStr}>`;
182
182
  if (f.isArray)
183
183
  fieldTypeStr = `${fieldTypeStr}[]`;
184
- const fieldStr = ` ${f.name}${f.isRequired ? "!" : "?"}: ${fieldTypeStr}`;
184
+ const fieldStr = ` ${f.name}${f.isRequired ? "" : "?"}: ${fieldTypeStr}`;
185
185
  const commentStr2 = f.comment ? ` /** ${f.comment} */` : "";
186
186
  return [fieldStr, commentStr2].filter((x) => x).join("\n");
187
187
  }).filter((x) => x).join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.62",
3
+ "version": "3.0.66",
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": "",