Skip to content

Commit

Permalink
Fixed extending types from extends plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yanickrochon committed Dec 17, 2018
1 parent 17207cf commit dc59342
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
],
"no-confusing-arrow": "off",
"no-continue": "error",
"no-console": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perfect-schema/base",
"version": "2.4.1",
"version": "2.4.2",
"description": "Model and schema validation done perfectly.",
"author": "Yanick Rochon <yanick.rochon@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -31,19 +31,19 @@
"var-validator": "0.0.3"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"eslint": "^5.4.0",
"eslint-config-standard": "^11.0.0",
"eslint": "^5.10.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^3.1.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
"jest": "^23.5.0"
"jest": "^23.6.0"
},
"babel": {
"presets": [
Expand Down
8 changes: 4 additions & 4 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ function normalizeField(field, fieldName) {

if (field.type instanceof PerfectSchema) {
field.type = field.type._type;
} else {
} else if (!types.isType(field.type)) {
field.type = types.getType(field.type);
}

if (!field.type) {
throw new TypeError('Invalid field specification' + (fieldName ? (' for ' + fieldName) : ''));
}
if (!field.type) {
throw new TypeError('Invalid field specification' + (fieldName ? (' for ' + fieldName) : ''));
}

return field;
Expand Down
9 changes: 7 additions & 2 deletions src/types/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default Object.freeze({
getType(type) {
if (this.isPrimitive(type)) {
return primitiveTypes[type];
} else if (this.isUserType(type)) {
} else if (this.isType(type)) {
return type;
} else {
return undefined;
Expand All @@ -54,8 +54,13 @@ export default Object.freeze({
@param type {mixed}
@return {Boolean}
*/
isType(type) {
return type && type.$$type && (typeof type.validatorFactory === 'function') && !Array.isArray(type.$$type) || false;
},

isUserType(type) {
return type && type.$$type && (typeof type.validatorFactory === 'function') && !Array.isArray(type.$$type);
console.warn("Deprecated! Use isType() instead!");
return this.isType(type);
}

});
Expand Down
20 changes: 19 additions & 1 deletion test/types/types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Testing type registry map', () => {
validatorFactory: () => {}
};

assert.ok( types.isUserType(type) );
assert.ok( types.isType(type) );
assert.ok( types.getType(type) === type );
});

Expand All @@ -57,7 +57,25 @@ describe('Testing type registry map', () => {
{ $$type: 'test' },
{ validatorFactory: () => {} }
].forEach(type => assert.ok( types.getType(type) === undefined ));
});


it('should warn about deprecation (2.4.2)', () => {
const type = {
$$type: 'test',
validatorFactory: () => {}
};
const warn = console.warn;
let warned = false;

console.warn = () => warned = true;

assert.strictEqual( types.isUserType(type), true );
assert.strictEqual( types.isUserType(null), false );
assert.ok( warned );

console.warn = warn;
});


});

0 comments on commit dc59342

Please sign in to comment.