@coderich/autograph 0.10.19 → 0.10.20

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderich/autograph",
3
3
  "author": "Richard Livolsi (coderich)",
4
- "version": "0.10.19",
4
+ "version": "0.10.20",
5
5
  "description": "AutoGraph",
6
6
  "keywords": [
7
7
  "graphql",
@@ -129,24 +129,24 @@ module.exports = class Pipeline {
129
129
 
130
130
  // A field cannot hold a reference to itself
131
131
  Pipeline.define('selfless', ({ model, field, parent, parentPath, value }) => {
132
- if (`${value}` === `${parentPath('id')}`) throw Boom.badRequest(`${model}.${field} cannot hold a reference to itself`);
132
+ if (`${value}` === `${parentPath('id')}`) throw Boom.badData(`${model}.${field} cannot hold a reference to itself`);
133
133
  });
134
134
 
135
135
  // Once set it cannot be changed
136
136
  Pipeline.define('immutable', ({ model, field, docPath, parentPath, path, value }) => {
137
137
  const hint = { id: parentPath('id') };
138
138
  const oldVal = docPath(path, hint);
139
- if (oldVal !== undefined && value !== undefined && `${hashObject(oldVal)}` !== `${hashObject(value)}`) throw Boom.badRequest(`${model}.${field} is immutable; cannot be changed once set ${oldVal} -> ${value}`);
139
+ if (oldVal !== undefined && value !== undefined && `${hashObject(oldVal)}` !== `${hashObject(value)}`) throw Boom.badData(`${model}.${field} is immutable; cannot be changed once set ${oldVal} -> ${value}`);
140
140
  });
141
141
 
142
142
  // List of allowed values
143
143
  Pipeline.factory('Allow', (...args) => function allow({ model, field, value }) {
144
- if (args.indexOf(value) === -1) throw Boom.badRequest(`${model}.${field} allows ${args}; found '${value}'`);
144
+ if (args.indexOf(value) === -1) throw Boom.badData(`${model}.${field} allows ${args}; found '${value}'`);
145
145
  });
146
146
 
147
147
  // List of disallowed values
148
148
  Pipeline.factory('Deny', (...args) => function deny({ model, field, value }) {
149
- if (args.indexOf(value) > -1) throw Boom.badRequest(`${model}.${field} denys ${args}; found '${value}'`);
149
+ if (args.indexOf(value) > -1) throw Boom.badData(`${model}.${field} denys ${args}; found '${value}'`);
150
150
  });
151
151
 
152
152
  // Min/Max range
@@ -157,7 +157,7 @@ module.exports = class Pipeline {
157
157
  return function range({ model, field, value }) {
158
158
  const num = +value; // Coerce to number if possible
159
159
  const test = Number.isNaN(num) ? value.length : num;
160
- if (test < min || test > max) throw Boom.badRequest(`${model}.${field} must satisfy range ${min}:${max}; found '${value}'`);
160
+ if (test < min || test > max) throw Boom.badData(`${model}.${field} must satisfy range ${min}:${max}; found '${value}'`);
161
161
  };
162
162
  }, { itemize: false });
163
163
  }
@@ -1,5 +1,3 @@
1
- const Boom = require('../core/Boom');
2
-
3
1
  module.exports = class Query {
4
2
  constructor(props = {}) {
5
3
  this.props = {};
@@ -21,7 +19,7 @@ module.exports = class Query {
21
19
 
22
20
  propCheck(prop, ...checks) {
23
21
  checks.forEach((check) => {
24
- if (this.props[check]) throw Boom.badRequest(`Cannot use "${prop}" while using "${check}"`);
22
+ if (this.props[check]) throw new Error(`Cannot use "${prop}" while using "${check}"`);
25
23
  });
26
24
  }
27
25
 
@@ -98,7 +96,7 @@ module.exports = class Query {
98
96
 
99
97
  skip(skip) {
100
98
  this.propCheck('skip', 'id');
101
- if (this.isCursorPaging) throw Boom.badRequest('Cannot use "skip" while using Cursor-Style Pagination');
99
+ if (this.isCursorPaging) throw new Error('Cannot use "skip" while using Cursor-Style Pagination');
102
100
  this.isClassicPaging = true;
103
101
  this.props.skip = skip;
104
102
  return this;
@@ -106,7 +104,7 @@ module.exports = class Query {
106
104
 
107
105
  limit(limit) {
108
106
  this.propCheck('limit', 'id');
109
- if (this.isCursorPaging) throw Boom.badRequest('Cannot use "limit" while using Cursor-Style Pagination');
107
+ if (this.isCursorPaging) throw new Error('Cannot use "limit" while using Cursor-Style Pagination');
110
108
  this.isClassicPaging = true;
111
109
  this.props.limit = limit;
112
110
  return this;
@@ -114,7 +112,7 @@ module.exports = class Query {
114
112
 
115
113
  first(first) {
116
114
  this.propCheck('first', 'id', 'last');
117
- if (this.isClassicPaging) throw Boom.badRequest('Cannot use "first" while using Classic-Style Pagination');
115
+ if (this.isClassicPaging) throw new Error('Cannot use "first" while using Classic-Style Pagination');
118
116
  this.isCursorPaging = true;
119
117
  this.props.first = first + 2; // Adding 2 for pagination meta info (hasNext hasPrev)
120
118
  return this;
@@ -122,7 +120,7 @@ module.exports = class Query {
122
120
 
123
121
  last(last) {
124
122
  this.propCheck('last', 'id', 'first');
125
- if (this.isClassicPaging) throw Boom.badRequest('Cannot use "last" while using Classic-Style Pagination');
123
+ if (this.isClassicPaging) throw new Error('Cannot use "last" while using Classic-Style Pagination');
126
124
  this.isCursorPaging = true;
127
125
  this.props.last = last + 2; // Adding 2 for pagination meta info (hasNext hasPrev)
128
126
  return this;
@@ -130,7 +128,7 @@ module.exports = class Query {
130
128
 
131
129
  before(before) {
132
130
  this.propCheck('before', 'id');
133
- if (this.isClassicPaging) throw Boom.badRequest('Cannot use "before" while using Classic-Style Pagination');
131
+ if (this.isClassicPaging) throw new Error('Cannot use "before" while using Classic-Style Pagination');
134
132
  this.isCursorPaging = true;
135
133
  this.props.before = before;
136
134
  return this;
@@ -138,7 +136,7 @@ module.exports = class Query {
138
136
 
139
137
  after(after) {
140
138
  this.propCheck('after', 'id');
141
- if (this.isClassicPaging) throw Boom.badRequest('Cannot use "after" while using Classic-Style Pagination');
139
+ if (this.isClassicPaging) throw new Error('Cannot use "after" while using Classic-Style Pagination');
142
140
  this.isCursorPaging = true;
143
141
  this.props.after = after;
144
142
  return this;