rads-db 3.0.25 → 3.0.27

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
@@ -659,6 +659,59 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
659
659
  await afterPut(docArgsToSave, ctx, computedContext);
660
660
  return docsToSave;
661
661
  }
662
+ async function verifyMany(args, ctx) {
663
+ if (driverInstance.verifyMany) {
664
+ return driverInstance.verifyMany(args, ctx);
665
+ }
666
+ ctx = { ...options.context, ...ctx };
667
+ if (args?.dryRun) {
668
+ ctx._logs = ctx._logs || [];
669
+ ctx.dryRun = true;
670
+ }
671
+ const { _logs } = ctx;
672
+ const { nodes, cursor } = await driverInstance.getMany(args, ctx);
673
+ let correctCount = 0;
674
+ let incorrectCount = 0;
675
+ const incorrectDocs = [];
676
+ const oldDocs = nodes;
677
+ const docArgsToSave = oldDocs.map((oldDoc) => {
678
+ const doc = merge(oldDoc, {});
679
+ if (args?.recompute) {
680
+ for (const p of args.recompute) {
681
+ delete doc[p];
682
+ }
683
+ }
684
+ if (!options.keepNulls)
685
+ cleanUndefinedAndNull(doc);
686
+ return { oldDoc, doc };
687
+ });
688
+ await handlePrecomputed(computedContext, docArgsToSave, ctx);
689
+ const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
690
+ await beforePut(docArgsToSave, ctx, computedContext);
691
+ for (const d of docArgsToSave) {
692
+ const validatedDoc = validators[key](d.doc);
693
+ for (const f of precomputedFields || []) {
694
+ ___default.set(validatedDoc, f, ___default.get(d.doc, f));
695
+ }
696
+ d.doc = validatedDoc;
697
+ }
698
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
699
+ for (const { oldDoc, doc } of docArgsToSave) {
700
+ const d = diff(doc, oldDoc);
701
+ if (___default.isEmpty(d))
702
+ correctCount++;
703
+ else {
704
+ incorrectCount++;
705
+ const objToAdd = { id: doc.id, diff: d };
706
+ incorrectDocs.push(objToAdd);
707
+ }
708
+ }
709
+ const docsToSave = docArgsToSave.map((x) => x.doc);
710
+ await driverInstance.putMany(docsToSave, ctx);
711
+ await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
712
+ await afterPut(docArgsToSave, ctx, computedContext);
713
+ return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
714
+ }
662
715
  const result = {
663
716
  // No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
664
717
  createObject() {
@@ -666,6 +719,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
666
719
  },
667
720
  getMany,
668
721
  putMany,
722
+ verifyMany,
669
723
  driver: driverInstance,
670
724
  getAgg: async (args, ctx) => {
671
725
  args = { ...args, where: { ...args?.where } };
@@ -703,6 +757,17 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
703
757
  await afterGet(result2, args, ctx, computedContext);
704
758
  return result2;
705
759
  },
760
+ verifyAll: async (args, ctx) => {
761
+ let cursor = args?.cursor;
762
+ const result2 = { correctCount: 0, incorrectCount: 0 };
763
+ do {
764
+ const response = await verifyMany({ ...args, cursor }, ctx);
765
+ cursor = response.cursor;
766
+ result2.correctCount += response.correctCount;
767
+ result2.incorrectCount += response.incorrectCount;
768
+ } while (cursor);
769
+ return result2;
770
+ },
706
771
  put: async (doc, ctx) => {
707
772
  const precomputed = schema[key].decorators.precomputed;
708
773
  if (precomputed && ctx?.skipPrecomputedCheckFor !== key) {
@@ -735,59 +800,6 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
735
800
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
736
801
  await afterPut(docArgsToSave, ctx, computedContext);
737
802
  return doc;
738
- },
739
- async verifyMany(args, ctx) {
740
- if (driverInstance.verifyMany) {
741
- return driverInstance.verifyMany(args, ctx);
742
- }
743
- ctx = { ...options.context, ...ctx };
744
- if (args?.dryRun) {
745
- ctx._logs = ctx._logs || [];
746
- ctx.dryRun = true;
747
- }
748
- const { _logs } = ctx;
749
- const { nodes, cursor } = await driverInstance.getMany(args, ctx);
750
- let correctCount = 0;
751
- let incorrectCount = 0;
752
- const incorrectDocs = [];
753
- const oldDocs = nodes;
754
- const docArgsToSave = oldDocs.map((oldDoc) => {
755
- const doc = merge(oldDoc, {});
756
- if (args?.recompute) {
757
- for (const p of args.recompute) {
758
- delete doc[p];
759
- }
760
- }
761
- if (!options.keepNulls)
762
- cleanUndefinedAndNull(doc);
763
- return { oldDoc, doc };
764
- });
765
- await handlePrecomputed(computedContext, docArgsToSave, ctx);
766
- const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
767
- await beforePut(docArgsToSave, ctx, computedContext);
768
- for (const d of docArgsToSave) {
769
- const validatedDoc = validators[key](d.doc);
770
- for (const f of precomputedFields || []) {
771
- ___default.set(validatedDoc, f, ___default.get(d.doc, f));
772
- }
773
- d.doc = validatedDoc;
774
- }
775
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
776
- for (const { oldDoc, doc } of docArgsToSave) {
777
- const d = diff(doc, oldDoc);
778
- if (___default.isEmpty(d))
779
- correctCount++;
780
- else {
781
- incorrectCount++;
782
- const objToAdd = { id: doc.id, diff: d };
783
- incorrectDocs.push(objToAdd);
784
- }
785
- }
786
- const docsToSave = docArgsToSave.map((x) => x.doc);
787
- await driverInstance.putMany(docsToSave, ctx);
788
- await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
789
- await afterPut(docArgsToSave, ctx, computedContext);
790
- return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
791
803
  }
792
804
  };
793
805
  for (const f of options.features) {
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { RadsDb } from '_rads-db';
3
3
 
4
4
  type MaybePromise$1<T> = Promise<T> | T;
5
5
  type Change<T> = {
6
- [K in keyof T]?: Change<T[K]>;
6
+ [K in keyof T]?: T[K] extends any[] ? T[K] : T[K] extends {} ? Change<T[K]> : T[K];
7
7
  };
8
8
  interface GetManyArgs<E, EN extends keyof EntityMeta, W> extends GetArgs<E, EN, W> {
9
9
  cursor?: string | null;
@@ -52,15 +52,16 @@ interface GetManyResponse<E, EN extends keyof EntityMeta, A extends GetArgs<E, E
52
52
  type GetResponse<E, EN extends keyof EntityMeta, A extends GetArgs<E, EN, any>> = A extends {
53
53
  include: any;
54
54
  } ? GetResponseInclude<E, EN, A['include']> : GetResponseNoInclude<E, EN>;
55
+ type RelationData<EN extends keyof EntityMeta, K extends keyof EntityMeta[EN]['relations']> = Pick<EntityMeta[EN]['relations'][K]['entity'], EntityMeta[EN]['relations'][K]['denormFields']>;
55
56
  type GetResponseInclude<E, EN extends keyof EntityMeta, I extends GetArgsInclude<E, EN>> = I extends {
56
57
  _pick: string[];
57
58
  } ? GetResponseIncludeSelect<E, I> : {
58
- [K in keyof E]: K extends keyof EntityMeta[EN]['relations'] ? K extends keyof I ? GetResponseInclude<EntityMeta[EN]['relations'][K]['entity'], EntityMeta[EN]['relations'][K]['entityName'], I[K]> : Pick<EntityMeta[EN]['relations'][K]['entity'], EntityMeta[EN]['relations'][K]['denormFields']> : E[K];
59
+ [K in keyof E]: K extends keyof EntityMeta[EN]['relations'] ? K extends keyof I ? GetResponseInclude<EntityMeta[EN]['relations'][K]['entity'], EntityMeta[EN]['relations'][K]['entityName'], I[K]> : RelationData<EN, K> : E[K];
59
60
  };
60
61
  interface GetResponseIncludeSelect<E, I> {
61
62
  }
62
63
  type GetResponseNoInclude<E, EN extends keyof EntityMeta> = {
63
- [K in keyof E]: K extends keyof EntityMeta[EN]['relations'] ? Pick<EntityMeta[EN]['relations'][K]['entity'], EntityMeta[EN]['relations'][K]['denormFields']> : E[K];
64
+ [K in keyof E]: K extends keyof EntityMeta[EN]['relations'] ? E[K] extends any[] ? RelationData<EN, K>[] : RelationData<EN, K> : E[K];
64
65
  };
65
66
  type DeepPartial<T> = {
66
67
  [K in keyof T]?: NonNullable<T[K]> extends Record<string, any> ? DeepPartial<T[K]> : T[K] | null;
package/dist/index.mjs CHANGED
@@ -651,6 +651,59 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
651
651
  await afterPut(docArgsToSave, ctx, computedContext);
652
652
  return docsToSave;
653
653
  }
654
+ async function verifyMany(args, ctx) {
655
+ if (driverInstance.verifyMany) {
656
+ return driverInstance.verifyMany(args, ctx);
657
+ }
658
+ ctx = { ...options.context, ...ctx };
659
+ if (args?.dryRun) {
660
+ ctx._logs = ctx._logs || [];
661
+ ctx.dryRun = true;
662
+ }
663
+ const { _logs } = ctx;
664
+ const { nodes, cursor } = await driverInstance.getMany(args, ctx);
665
+ let correctCount = 0;
666
+ let incorrectCount = 0;
667
+ const incorrectDocs = [];
668
+ const oldDocs = nodes;
669
+ const docArgsToSave = oldDocs.map((oldDoc) => {
670
+ const doc = merge(oldDoc, {});
671
+ if (args?.recompute) {
672
+ for (const p of args.recompute) {
673
+ delete doc[p];
674
+ }
675
+ }
676
+ if (!options.keepNulls)
677
+ cleanUndefinedAndNull(doc);
678
+ return { oldDoc, doc };
679
+ });
680
+ await handlePrecomputed(computedContext, docArgsToSave, ctx);
681
+ const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
682
+ await beforePut(docArgsToSave, ctx, computedContext);
683
+ for (const d of docArgsToSave) {
684
+ const validatedDoc = validators[key](d.doc);
685
+ for (const f of precomputedFields || []) {
686
+ _.set(validatedDoc, f, _.get(d.doc, f));
687
+ }
688
+ d.doc = validatedDoc;
689
+ }
690
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
691
+ for (const { oldDoc, doc } of docArgsToSave) {
692
+ const d = diff(doc, oldDoc);
693
+ if (_.isEmpty(d))
694
+ correctCount++;
695
+ else {
696
+ incorrectCount++;
697
+ const objToAdd = { id: doc.id, diff: d };
698
+ incorrectDocs.push(objToAdd);
699
+ }
700
+ }
701
+ const docsToSave = docArgsToSave.map((x) => x.doc);
702
+ await driverInstance.putMany(docsToSave, ctx);
703
+ await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
704
+ await afterPut(docArgsToSave, ctx, computedContext);
705
+ return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
706
+ }
654
707
  const result = {
655
708
  // No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
656
709
  createObject() {
@@ -658,6 +711,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
658
711
  },
659
712
  getMany,
660
713
  putMany,
714
+ verifyMany,
661
715
  driver: driverInstance,
662
716
  getAgg: async (args, ctx) => {
663
717
  args = { ...args, where: { ...args?.where } };
@@ -695,6 +749,17 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
695
749
  await afterGet(result2, args, ctx, computedContext);
696
750
  return result2;
697
751
  },
752
+ verifyAll: async (args, ctx) => {
753
+ let cursor = args?.cursor;
754
+ const result2 = { correctCount: 0, incorrectCount: 0 };
755
+ do {
756
+ const response = await verifyMany({ ...args, cursor }, ctx);
757
+ cursor = response.cursor;
758
+ result2.correctCount += response.correctCount;
759
+ result2.incorrectCount += response.incorrectCount;
760
+ } while (cursor);
761
+ return result2;
762
+ },
698
763
  put: async (doc, ctx) => {
699
764
  const precomputed = schema[key].decorators.precomputed;
700
765
  if (precomputed && ctx?.skipPrecomputedCheckFor !== key) {
@@ -727,59 +792,6 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
727
792
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
728
793
  await afterPut(docArgsToSave, ctx, computedContext);
729
794
  return doc;
730
- },
731
- async verifyMany(args, ctx) {
732
- if (driverInstance.verifyMany) {
733
- return driverInstance.verifyMany(args, ctx);
734
- }
735
- ctx = { ...options.context, ...ctx };
736
- if (args?.dryRun) {
737
- ctx._logs = ctx._logs || [];
738
- ctx.dryRun = true;
739
- }
740
- const { _logs } = ctx;
741
- const { nodes, cursor } = await driverInstance.getMany(args, ctx);
742
- let correctCount = 0;
743
- let incorrectCount = 0;
744
- const incorrectDocs = [];
745
- const oldDocs = nodes;
746
- const docArgsToSave = oldDocs.map((oldDoc) => {
747
- const doc = merge(oldDoc, {});
748
- if (args?.recompute) {
749
- for (const p of args.recompute) {
750
- delete doc[p];
751
- }
752
- }
753
- if (!options.keepNulls)
754
- cleanUndefinedAndNull(doc);
755
- return { oldDoc, doc };
756
- });
757
- await handlePrecomputed(computedContext, docArgsToSave, ctx);
758
- const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
759
- await beforePut(docArgsToSave, ctx, computedContext);
760
- for (const d of docArgsToSave) {
761
- const validatedDoc = validators[key](d.doc);
762
- for (const f of precomputedFields || []) {
763
- _.set(validatedDoc, f, _.get(d.doc, f));
764
- }
765
- d.doc = validatedDoc;
766
- }
767
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
768
- for (const { oldDoc, doc } of docArgsToSave) {
769
- const d = diff(doc, oldDoc);
770
- if (_.isEmpty(d))
771
- correctCount++;
772
- else {
773
- incorrectCount++;
774
- const objToAdd = { id: doc.id, diff: d };
775
- incorrectDocs.push(objToAdd);
776
- }
777
- }
778
- const docsToSave = docArgsToSave.map((x) => x.doc);
779
- await driverInstance.putMany(docsToSave, ctx);
780
- await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
781
- await afterPut(docArgsToSave, ctx, computedContext);
782
- return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
783
795
  }
784
796
  };
785
797
  for (const f of options.features) {
@@ -77,7 +77,9 @@ function verifyEventSourcingSetup(schema, effects) {
77
77
  events
78
78
  });
79
79
  }
80
- await (0, _radsDb.handlePrecomputed)({
80
+ await (0, _radsDb.handlePrecomputed)(
81
+ // @ts-expect-error TODO wrong types
82
+ {
81
83
  ...context,
82
84
  typeName: entityName
83
85
  }, result.map(v => ({
@@ -70,6 +70,7 @@ function verifyEventSourcingSetup(schema, effects) {
70
70
  result.push({ aggDoc, events });
71
71
  }
72
72
  await handlePrecomputed(
73
+ // @ts-expect-error TODO wrong types
73
74
  { ...context, typeName: entityName },
74
75
  result.map((v) => ({ doc: v.aggDoc, events: v.events, oldDoc: existingAggregatesById[v.aggDoc.id] })),
75
76
  ctx
@@ -3,23 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.radsDbNuxt = void 0;
7
- var _kit = require("@nuxt/kit");
8
- const radsDbNuxt = (0, _kit.defineNuxtModule)({
9
- meta: {
10
- name: "rads-db",
11
- compatibility: {
12
- nuxt: "^3.0.0"
13
- }
14
- },
15
- defaults: {},
16
- setup(options, nuxt) {
17
- const {
18
- resolve
19
- } = (0, _kit.createResolver)(require('url').pathToFileURL(__filename).toString());
20
- (0, _kit.addServerHandler)({
21
- handler: resolve("./nuxtModuleHandler")
22
- });
23
- }
24
- });
25
- exports.radsDbNuxt = radsDbNuxt;
6
+ module.exports = void 0;
7
+ var _default = {};
8
+ module.exports = _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -1,16 +1 @@
1
- import { addServerHandler, createResolver, defineNuxtModule } from "@nuxt/kit";
2
- export const radsDbNuxt = defineNuxtModule({
3
- meta: {
4
- name: "rads-db",
5
- compatibility: {
6
- nuxt: "^3.0.0"
7
- }
8
- },
9
- defaults: {},
10
- setup(options, nuxt) {
11
- const { resolve } = createResolver(import.meta.url);
12
- addServerHandler({
13
- handler: resolve("./nuxtModuleHandler")
14
- });
15
- }
16
- });
1
+ export default {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.25",
3
+ "version": "3.0.27",
4
4
  "files": [
5
5
  "dist",
6
6
  "drivers",
@@ -94,7 +94,6 @@
94
94
  },
95
95
  "dependencies": {
96
96
  "@fastify/deepmerge": "^1.3.0",
97
- "@nuxt/kit": "^3.5.1",
98
97
  "dataloader": "^2.2.2",
99
98
  "ignore": "^5.2.4",
100
99
  "klaw": "^4.1.0",