rads-db 0.1.76 → 0.1.78

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
@@ -684,14 +684,20 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
684
684
  doc = merge(oldDoc, doc);
685
685
  if (mustCleanNulls)
686
686
  cleanUndefinedAndNull(doc);
687
- doc = validators[key](doc);
688
687
  return { oldDoc, doc };
689
688
  });
690
- const docsToSave = docArgsToSave.map((x) => x.doc);
691
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
692
689
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
693
690
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
694
691
  await beforePut(docArgsToSave, ctx, computedContext);
692
+ for (const d of docArgsToSave) {
693
+ const validatedDoc = validators[key](d.doc);
694
+ for (const f of precomputedFields || []) {
695
+ ___default.set(validatedDoc, f, ___default.get(d.doc, f));
696
+ }
697
+ d.doc = validatedDoc;
698
+ }
699
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
700
+ const docsToSave = docArgsToSave.map((x) => x.doc);
695
701
  await driverInstance.putMany(docsToSave, ctx);
696
702
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
697
703
  await afterPut(docArgsToSave, ctx, computedContext);
@@ -745,17 +751,19 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
745
751
  doc = merge(oldDoc, doc);
746
752
  if (mustCleanNulls)
747
753
  cleanUndefinedAndNull(doc);
748
- doc = validators[key](doc);
749
- if (oldDoc && precomputedFields) {
750
- for (const f of precomputedFields) {
751
- ___default.set(doc, f, ___default.get(oldDoc, f));
752
- }
753
- }
754
754
  const docArgsToSave = [{ doc, oldDoc }];
755
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
756
755
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
757
756
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
758
757
  await beforePut(docArgsToSave, ctx, computedContext);
758
+ const validatedDoc = validators[key](doc);
759
+ docArgsToSave[0].doc = validatedDoc;
760
+ if (precomputedFields) {
761
+ for (const f of precomputedFields) {
762
+ ___default.set(validatedDoc, f, ___default.get(doc, f));
763
+ }
764
+ }
765
+ doc = validatedDoc;
766
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
759
767
  await driverInstance.put(doc, ctx);
760
768
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
761
769
  await afterPut(docArgsToSave, ctx, computedContext);
@@ -777,7 +785,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
777
785
  const incorrectDocs = [];
778
786
  const oldDocs = nodes;
779
787
  const docArgsToSave = oldDocs.map((oldDoc) => {
780
- let doc = merge(oldDoc, {});
788
+ const doc = merge(oldDoc, {});
781
789
  if (args?.recompute) {
782
790
  for (const p of args.recompute) {
783
791
  delete doc[p];
@@ -785,13 +793,19 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
785
793
  }
786
794
  if (mustCleanNulls)
787
795
  cleanUndefinedAndNull(doc);
788
- doc = validators[key](doc);
789
796
  return { oldDoc, doc };
790
797
  });
791
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
792
798
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
793
799
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
794
800
  await beforePut(docArgsToSave, ctx, computedContext);
801
+ for (const d of docArgsToSave) {
802
+ const validatedDoc = validators[key](d.doc);
803
+ for (const f of precomputedFields || []) {
804
+ ___default.set(validatedDoc, f, ___default.get(d.doc, f));
805
+ }
806
+ d.doc = validatedDoc;
807
+ }
808
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
795
809
  for (const { oldDoc, doc } of docArgsToSave) {
796
810
  const d = diff(doc, oldDoc);
797
811
  if (___default.isEmpty(d))
package/dist/index.mjs CHANGED
@@ -677,14 +677,20 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
677
677
  doc = merge(oldDoc, doc);
678
678
  if (mustCleanNulls)
679
679
  cleanUndefinedAndNull(doc);
680
- doc = validators[key](doc);
681
680
  return { oldDoc, doc };
682
681
  });
683
- const docsToSave = docArgsToSave.map((x) => x.doc);
684
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
685
682
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
686
683
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
687
684
  await beforePut(docArgsToSave, ctx, computedContext);
685
+ for (const d of docArgsToSave) {
686
+ const validatedDoc = validators[key](d.doc);
687
+ for (const f of precomputedFields || []) {
688
+ _.set(validatedDoc, f, _.get(d.doc, f));
689
+ }
690
+ d.doc = validatedDoc;
691
+ }
692
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
693
+ const docsToSave = docArgsToSave.map((x) => x.doc);
688
694
  await driverInstance.putMany(docsToSave, ctx);
689
695
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
690
696
  await afterPut(docArgsToSave, ctx, computedContext);
@@ -738,17 +744,19 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
738
744
  doc = merge(oldDoc, doc);
739
745
  if (mustCleanNulls)
740
746
  cleanUndefinedAndNull(doc);
741
- doc = validators[key](doc);
742
- if (oldDoc && precomputedFields) {
743
- for (const f of precomputedFields) {
744
- _.set(doc, f, _.get(oldDoc, f));
745
- }
746
- }
747
747
  const docArgsToSave = [{ doc, oldDoc }];
748
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
749
748
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
750
749
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
751
750
  await beforePut(docArgsToSave, ctx, computedContext);
751
+ const validatedDoc = validators[key](doc);
752
+ docArgsToSave[0].doc = validatedDoc;
753
+ if (precomputedFields) {
754
+ for (const f of precomputedFields) {
755
+ _.set(validatedDoc, f, _.get(doc, f));
756
+ }
757
+ }
758
+ doc = validatedDoc;
759
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
752
760
  await driverInstance.put(doc, ctx);
753
761
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
754
762
  await afterPut(docArgsToSave, ctx, computedContext);
@@ -770,7 +778,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
770
778
  const incorrectDocs = [];
771
779
  const oldDocs = nodes;
772
780
  const docArgsToSave = oldDocs.map((oldDoc) => {
773
- let doc = merge(oldDoc, {});
781
+ const doc = merge(oldDoc, {});
774
782
  if (args?.recompute) {
775
783
  for (const p of args.recompute) {
776
784
  delete doc[p];
@@ -778,13 +786,19 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
778
786
  }
779
787
  if (mustCleanNulls)
780
788
  cleanUndefinedAndNull(doc);
781
- doc = validators[key](doc);
782
789
  return { oldDoc, doc };
783
790
  });
784
- await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
785
791
  await handlePrecomputed(computedContext, docArgsToSave, ctx);
786
792
  const beforePutResults = await handleEffectsBeforePut(computedContext, docArgsToSave, ctx);
787
793
  await beforePut(docArgsToSave, ctx, computedContext);
794
+ for (const d of docArgsToSave) {
795
+ const validatedDoc = validators[key](d.doc);
796
+ for (const f of precomputedFields || []) {
797
+ _.set(validatedDoc, f, _.get(d.doc, f));
798
+ }
799
+ d.doc = validatedDoc;
800
+ }
801
+ await fillDenormFieldsBeforePut(computedContext, docArgsToSave, ctx);
788
802
  for (const { oldDoc, doc } of docArgsToSave) {
789
803
  const d = diff(doc, oldDoc);
790
804
  if (_.isEmpty(d))
@@ -17,7 +17,18 @@ var _default = options => (schema, entity) => {
17
17
  ...options
18
18
  };
19
19
  const fetch = opts.fetch || global.fetch;
20
- if (!opts.fetch) throw new Error('Please provide "fetch" argument to rest driver definition');
20
+ async function fetchInner(...args) {
21
+ const [url, fetchOptions] = args;
22
+ const response = await fetch(url, fetchOptions);
23
+ const responseJson = response.status === 204 ? null : await response.json();
24
+ if (!response.ok) {
25
+ const err = new Error(response.statusText);
26
+ if (responseJson?.code) err.code = responseJson?.code;
27
+ err.fetchResponseJson = responseJson;
28
+ throw err;
29
+ }
30
+ return responseJson;
31
+ }
21
32
  const pluralEntityName = _lodash.default.lowerFirst((0, _pluralize.default)(entity));
22
33
  const instance = {
23
34
  driverName: "restApi",
@@ -33,8 +44,7 @@ var _default = options => (schema, entity) => {
33
44
  ...fetchOptions.headers,
34
45
  ...opts.getHeaders(url, fetchOptions)
35
46
  };
36
- const response = await fetch(url, fetchOptions);
37
- return await response?.json();
47
+ return await fetchInner(url, fetchOptions);
38
48
  },
39
49
  async putMany(item) {
40
50
  const url = `${opts.baseUrl}/${pluralEntityName}`;
@@ -49,7 +59,7 @@ var _default = options => (schema, entity) => {
49
59
  ...fetchOptions.headers,
50
60
  ...opts.getHeaders(url, fetchOptions)
51
61
  };
52
- await fetch(url, fetchOptions);
62
+ return await fetchInner(url, fetchOptions);
53
63
  },
54
64
  async verifyMany(args, ctx) {
55
65
  throw new Error('Calling "verifyMany" via rest api is not supported for security reasons.');
@@ -10,8 +10,19 @@ export default (options) => (schema, entity) => {
10
10
  ...options
11
11
  };
12
12
  const fetch = opts.fetch || global.fetch;
13
- if (!opts.fetch)
14
- throw new Error('Please provide "fetch" argument to rest driver definition');
13
+ async function fetchInner(...args) {
14
+ const [url, fetchOptions] = args;
15
+ const response = await fetch(url, fetchOptions);
16
+ const responseJson = response.status === 204 ? null : await response.json();
17
+ if (!response.ok) {
18
+ const err = new Error(response.statusText);
19
+ if (responseJson?.code)
20
+ err.code = responseJson?.code;
21
+ err.fetchResponseJson = responseJson;
22
+ throw err;
23
+ }
24
+ return responseJson;
25
+ }
15
26
  const pluralEntityName = _.lowerFirst(pluralize(entity));
16
27
  const instance = {
17
28
  driverName: "restApi",
@@ -24,8 +35,7 @@ export default (options) => (schema, entity) => {
24
35
  headers: {}
25
36
  };
26
37
  fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(url, fetchOptions) };
27
- const response = await fetch(url, fetchOptions);
28
- return await response?.json();
38
+ return await fetchInner(url, fetchOptions);
29
39
  },
30
40
  async putMany(item) {
31
41
  const url = `${opts.baseUrl}/${pluralEntityName}`;
@@ -35,7 +45,7 @@ export default (options) => (schema, entity) => {
35
45
  headers: {}
36
46
  };
37
47
  fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(url, fetchOptions) };
38
- await fetch(url, fetchOptions);
48
+ return await fetchInner(url, fetchOptions);
39
49
  },
40
50
  async verifyMany(args, ctx) {
41
51
  throw new Error('Calling "verifyMany" via rest api is not supported for security reasons.');
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "require": "./features/*.cjs"
41
41
  }
42
42
  },
43
- "version": "0.1.76",
43
+ "version": "0.1.78",
44
44
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
45
45
  "keywords": [],
46
46
  "author": "",