@technicity/data-service-generator 0.8.3 → 0.9.0

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { generate } from "./generation/generate";
2
2
  export { SDKNotFoundError } from "./runtime/lib/SDKNotFoundError";
3
+ export { SDKBadWhereError } from "./runtime/lib/SDKBadWhereError";
3
4
  export { traverseFieldArgs } from "./traverseFieldArgs";
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseFieldArgs = exports.SDKNotFoundError = exports.generate = void 0;
3
+ exports.traverseFieldArgs = exports.SDKBadWhereError = exports.SDKNotFoundError = exports.generate = void 0;
4
4
  var generate_1 = require("./generation/generate");
5
5
  Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
6
6
  var SDKNotFoundError_1 = require("./runtime/lib/SDKNotFoundError");
7
7
  Object.defineProperty(exports, "SDKNotFoundError", { enumerable: true, get: function () { return SDKNotFoundError_1.SDKNotFoundError; } });
8
+ var SDKBadWhereError_1 = require("./runtime/lib/SDKBadWhereError");
9
+ Object.defineProperty(exports, "SDKBadWhereError", { enumerable: true, get: function () { return SDKBadWhereError_1.SDKBadWhereError; } });
8
10
  var traverseFieldArgs_1 = require("./traverseFieldArgs");
9
11
  Object.defineProperty(exports, "traverseFieldArgs", { enumerable: true, get: function () { return traverseFieldArgs_1.traverseFieldArgs; } });
@@ -0,0 +1,4 @@
1
+ import { CustomError } from "../../lib/CustomError";
2
+ export declare class SDKBadWhereError extends CustomError {
3
+ constructor(message?: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDKBadWhereError = void 0;
4
+ const CustomError_1 = require("../../lib/CustomError");
5
+ class SDKBadWhereError extends CustomError_1.CustomError {
6
+ constructor(message) {
7
+ super(message || "Invalid $where");
8
+ }
9
+ }
10
+ exports.SDKBadWhereError = SDKBadWhereError;
@@ -19,6 +19,7 @@ const cursor_1 = require("./cursor");
19
19
  const runTransforms_1 = require("./runTransforms");
20
20
  const addNullFallbacks_1 = require("./addNullFallbacks");
21
21
  const SDKNotFoundError_1 = require("./SDKNotFoundError");
22
+ const SDKBadWhereError_1 = require("./SDKBadWhereError");
22
23
  const stringifyWhere_1 = require("./stringifyWhere");
23
24
  const getOrderBy_1 = require("./getOrderBy");
24
25
  async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, middlewareHandler, context) {
@@ -776,7 +777,14 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
776
777
  v,
777
778
  ])).then((xs) => xs[0]?.[mappedField.referencedKey])));
778
779
  if (newVal.some((x) => x == null)) {
779
- throw new SDKNotFoundError_1.SDKNotFoundError();
780
+ const index = newVal.findIndex((x) => x == null);
781
+ if (index === -1) {
782
+ throw new SDKBadWhereError_1.SDKBadWhereError();
783
+ }
784
+ else {
785
+ const v = where[index];
786
+ throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, v));
787
+ }
780
788
  }
781
789
  out = _.set(newPath, newVal, out);
782
790
  }
@@ -788,7 +796,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
788
796
  where,
789
797
  ])).then((xs) => xs[0]?.[mappedField.referencedKey]);
790
798
  if (newVal == null) {
791
- throw new SDKNotFoundError_1.SDKNotFoundError();
799
+ throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
792
800
  }
793
801
  out = _.set(newPath, newVal, out);
794
802
  }
@@ -811,7 +819,14 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
811
819
  v,
812
820
  ])).then((xs) => xs[0]?.[mappedField.referencedKey])));
813
821
  if (newVal.some((x) => x == null)) {
814
- throw new SDKNotFoundError_1.SDKNotFoundError();
822
+ const index = newVal.findIndex((x) => x == null);
823
+ if (index === -1) {
824
+ throw new SDKBadWhereError_1.SDKBadWhereError();
825
+ }
826
+ else {
827
+ const v = where[index];
828
+ throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, v));
829
+ }
815
830
  }
816
831
  out = _.set(newPath, newVal, out);
817
832
  }
@@ -823,7 +838,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
823
838
  where,
824
839
  ])).then((xs) => xs[0]?.[mappedField.referencedKey]);
825
840
  if (newVal == null) {
826
- throw new SDKNotFoundError_1.SDKNotFoundError();
841
+ throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
827
842
  }
828
843
  out = _.set(newPath, newVal, out);
829
844
  }
@@ -837,6 +852,9 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
837
852
  return out;
838
853
  }
839
854
  exports._prepareWhere = _prepareWhere;
855
+ function getPrepareWhereNotFoundMessage(mappedField, value) {
856
+ return `Not found: unable to map \`${mappedField.referencedTable}\`.\`${mappedField.name}\` to \`${mappedField.referencedTable}\`.\`${mappedField.referencedKey}\` for the value \`${value}\`.`;
857
+ }
840
858
  const ops = [
841
859
  "$eq",
842
860
  "$neq",
@@ -19,7 +19,10 @@ function stringifyWhere(input) {
19
19
  rowWithMatchingCursor,
20
20
  });
21
21
  if (paginationWhere) {
22
- result = result + " AND " + paginationWhere;
22
+ result =
23
+ result.length === 0
24
+ ? paginationWhere
25
+ : result + " AND " + paginationWhere;
23
26
  }
24
27
  return result;
25
28
  }
@@ -162,7 +165,7 @@ function getOperatorNeq(value) {
162
165
  // return { k, v };
163
166
  // }
164
167
  function stringifyPaginationWhere(input) {
165
- const { table, args, orderBy, escapeId, escape, rowWithMatchingCursor, } = input;
168
+ const { table, args, orderBy, escapeId, escape, rowWithMatchingCursor } = input;
166
169
  if (args?.$paginate?.after == null && args?.$paginate?.before == null) {
167
170
  return "";
168
171
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -40,6 +40,6 @@
40
40
  "env-cmd": "^10.1.0",
41
41
  "mocha": "9.1.3",
42
42
  "sinon": "12.0.1",
43
- "typescript": "^4.0.5"
43
+ "typescript": "4.6.4"
44
44
  }
45
45
  }