@coderich/autograph 0.10.18 → 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 +1 -1
- package/src/data/Pipeline.js +5 -5
- package/src/data/Type.js +1 -1
- package/src/query/Query.js +7 -9
package/package.json
CHANGED
package/src/data/Pipeline.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
package/src/data/Type.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = class extends Type {
|
|
|
30
30
|
structures.defaultValue = Pipeline.defaultValue;
|
|
31
31
|
structures.ensureArrayValue = Pipeline.ensureArrayValue;
|
|
32
32
|
|
|
33
|
-
if (enumType) structures.validators.push(Pipeline.define(`allow
|
|
33
|
+
if (enumType) structures.validators.push(Pipeline.define(`allow${type}`, Pipeline.Allow(...enumType.getValue()), { configurable: true }));
|
|
34
34
|
if (!scalarType) return structures;
|
|
35
35
|
|
|
36
36
|
return Object.entries(scalarType.getDirectiveArgs('field', {})).reduce((prev, [key, value]) => {
|
package/src/query/Query.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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;
|