goodeggs-json-schema-validator
Advanced tools
Comparing version 5.3.0 to 6.0.6
@@ -0,1 +1,8 @@ | ||
# [6.0.0](https://github.com/goodeggs/goodeggs-json-schema-validator/compare/v5.0.0...v6.0.0) | ||
### BREAKING CHANGES | ||
- Upgrade to goodeggs-toolkit. | ||
- Port to TypeScript. | ||
# [5.0.0](https://github.com/goodeggs/goodeggs-json-schema-validator/compare/v4.0.0...v5.0.0) | ||
@@ -5,2 +12,2 @@ | ||
* Dropped support for Node 6 | ||
- Dropped support for Node 6 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _tv = _interopRequireDefault(require("tv4")); | ||
var _assert = _interopRequireDefault(require("assert")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var clonedTv4 = _tv["default"].freshApi(); | ||
var allowNull = function allowNull(data, schema) { | ||
return data === null && (schema.type === 'null' || schema.type.includes('null')); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// @CamillaTeodoro we are adding the assertValid function in the end of the file. | ||
// At this point Typescript doesn't know that assertValid exists | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const clonedTv4 = _tv.default.freshApi(); | ||
const allowNull = (data, schema) => { | ||
var _schema$type; | ||
return data === null && (schema.type === 'null' || ((_schema$type = schema.type) === null || _schema$type === void 0 ? void 0 : _schema$type.includes('null')) === true); | ||
}; | ||
clonedTv4.addFormat('objectid', function (data, schema) { | ||
clonedTv4.addFormat('objectid', (data, schema) => { | ||
if (allowNull(data, schema)) return null; | ||
@@ -22,10 +24,10 @@ if (typeof data === 'string' && /^[a-f\d]{24}$/i.test(data)) return null; | ||
}); | ||
clonedTv4.addFormat('date-time', function (data, schema) { | ||
if (allowNull(data, schema)) return null; // Source: http://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime | ||
var dateTimeRegex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/; | ||
clonedTv4.addFormat('date-time', (data, schema) => { | ||
if (allowNull(data, schema)) return null; | ||
// Source: http://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime | ||
const dateTimeRegex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/; | ||
if (typeof data === 'string' && dateTimeRegex.test(data)) return null; | ||
return 'date-time, ISOString format, expected'; | ||
}); | ||
clonedTv4.addFormat('date', function (data, schema) { | ||
clonedTv4.addFormat('date', (data, schema) => { | ||
if (allowNull(data, schema)) return null; | ||
@@ -35,3 +37,3 @@ if (typeof data === 'string' && /\d{4}-[01]\d-[0-3]\d/.test(data)) return null; | ||
}); | ||
clonedTv4.addFormat('time', function (data, schema) { | ||
clonedTv4.addFormat('time', (data, schema) => { | ||
if (allowNull(data, schema)) return null; | ||
@@ -41,10 +43,10 @@ if (typeof data === 'string' && /^[0-2][0-9]:[0-5][0-9](:[0-5][0-9])?$/.test(data)) return null; | ||
}); | ||
clonedTv4.addFormat('email', function (data, schema) { | ||
if (allowNull(data, schema)) return null; // Source: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript | ||
var emailRegex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; | ||
clonedTv4.addFormat('email', (data, schema) => { | ||
if (allowNull(data, schema)) return null; | ||
// Source: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript | ||
const emailRegex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; | ||
if (typeof data === 'string' && emailRegex.test(data)) return null; | ||
return 'email expected'; | ||
}); | ||
clonedTv4.addFormat('non-negative-integer', function (data, schema) { | ||
clonedTv4.addFormat('non-negative-integer', (data, schema) => { | ||
if (allowNull(data, schema)) return null; | ||
@@ -54,30 +56,25 @@ if (typeof data === 'string' && /^[0-9]+$/.test(data)) return null; | ||
}); | ||
module.exports = clonedTv4; | ||
module.exports.assertValid = function (data, schema, errorMessage) { | ||
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { | ||
banUnknownProperties: true | ||
}, | ||
banUnknownProperties = _ref.banUnknownProperties; | ||
(0, _assert["default"])(_typeof(schema) === 'object', 'schema must be an object'); | ||
if (errorMessage != null) (0, _assert["default"])(typeof errorMessage === 'string', 'errorMessage must be a string'); | ||
var _clonedTv4$validateRe = clonedTv4.validateResult(data, schema, null, banUnknownProperties), | ||
valid = _clonedTv4$validateRe.valid, | ||
error = _clonedTv4$validateRe.error; | ||
clonedTv4.assertValid = function (data, schema, errorMessage, { | ||
banUnknownProperties | ||
} = { | ||
banUnknownProperties: true | ||
}) { | ||
(0, _assert.default)(typeof schema === 'object', 'schema must be an object'); | ||
if (errorMessage != null) (0, _assert.default)(typeof errorMessage === 'string', 'errorMessage must be a string'); | ||
const { | ||
valid, | ||
error | ||
} = clonedTv4.validateResult(data, schema, false, banUnknownProperties ?? true); | ||
if (!valid) { | ||
var message = function () { | ||
var result = ''; | ||
if (errorMessage) result += "".concat(errorMessage, "; "); | ||
const message = (() => { | ||
let result = ''; | ||
if (errorMessage) result += `${errorMessage}; `; | ||
result += 'failed'; | ||
if (schema.title) result += " \"".concat(schema.title, "\""); | ||
if (schema.title) result += ` "${String(schema.title)}"`; | ||
result += ' schema validation'; | ||
if (error.schemaPath.length) result += " at schema path ".concat(error.schemaPath); | ||
if (error.dataPath.length) result += " for data path ".concat(error.dataPath); | ||
result += "; ".concat(error.message.toLowerCase()); | ||
if (error.schemaPath) result += ` at schema path ${String(error.schemaPath)}`; | ||
if (error.dataPath) result += ` for data path ${String(error.dataPath)}`; | ||
result += `; ${String(error.message).toLowerCase()}`; | ||
return result; | ||
}(); | ||
})(); | ||
error.name = 'SchemaValidationError'; | ||
@@ -87,4 +84,8 @@ error.message = message; | ||
error.schema = schema; | ||
// @CamillaTeodoro this error is from the tv4 library | ||
// eslint-disable-next-line @typescript-eslint/no-throw-literal | ||
throw error; | ||
} | ||
}; | ||
}; | ||
var _default = clonedTv4; | ||
exports.default = _default; |
{ | ||
"name": "goodeggs-json-schema-validator", | ||
"version": "5.3.0", | ||
"version": "6.0.6", | ||
"description": "Good Eggs JSON Schema Validator", | ||
@@ -17,48 +17,30 @@ "author": "Good Eggs <open-source@goodeggs.com>", | ||
"dependencies": { | ||
"tv4": "^1.2.7" | ||
"tv4": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.0", | ||
"@babel/core": "^7.5.0", | ||
"@babel/node": "^7.5.0", | ||
"@babel/preset-env": "^7.5.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/register": "^7.4.4", | ||
"babel-eslint": "^10.0.2", | ||
"eslint": "^5.5.0", | ||
"eslint-plugin-goodeggs": "^7.3.1", | ||
"flow-bin": "^0.105.2", | ||
"goodeggs-test-helpers": "^6.0.1", | ||
"mocha": "^5.0.5" | ||
"@babel/cli": "^7.21.5", | ||
"@babel/core": "^7.22.1", | ||
"@babel/node": "^7.22.1", | ||
"@babel/polyfill": "^7.12.1", | ||
"@babel/preset-env": "^7.22.4", | ||
"@babel/preset-typescript": "^7.21.5", | ||
"@babel/register": "^7.21.0", | ||
"@goodeggs/toolkit": "^7.0.1", | ||
"@goodeggs/tsconfig": "^2.0.2", | ||
"@types/mocha": "^10.0.1", | ||
"@types/tv4": "^1.2.31", | ||
"goodeggs-test-helpers": "^8.3.3", | ||
"mocha": "6.2.3", | ||
"typescript": "^4.9.5" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-flow" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"parser": "babel-eslint", | ||
"plugins": [ | ||
"goodeggs" | ||
], | ||
"extends": [ | ||
"plugin:goodeggs/goodeggs" | ||
], | ||
"rules": { | ||
"goodeggs/lodash-prefer-lodash-typecheck": "off", | ||
"goodeggs/import-no-commonjs": "off", | ||
"no-eq-null": "off" | ||
}, | ||
"env": { | ||
"node": true | ||
} | ||
}, | ||
"scripts": { | ||
"build": "rm -rf lib && babel src -d lib && cp src/index.js.flow lib", | ||
"build": "yarn run build:clean && babel --extensions=.ts,.js,.jsx,.tsx src -d lib && yarn run build:types", | ||
"build:clean": "rm -rf lib", | ||
"build:types": "tsc --project tsconfig.declarations.json", | ||
"prepublishOnly": "yarn run build", | ||
"lint": "eslint 'src/**/*.js' --ignore-path .gitignore", | ||
"test:mocha": "NODE_ENV=test mocha --require @babel/register", | ||
"test": "yarn run lint && yarn run flow && yarn run test:mocha" | ||
"lint": "getk run lint-es '**/*.{js,jsx,ts,tsx}' --ignore-path .gitignore", | ||
"lint:fix": "getk run fix-es --ignore-path .gitignore", | ||
"test:mocha": "NODE_ENV=test mocha --opts mocha.opts --extension ts,js,jsx,tsx", | ||
"test": "yarn run typecheck && yarn run lint && yarn run test:mocha", | ||
"typecheck": "tsc" | ||
}, | ||
@@ -68,4 +50,5 @@ "homepage": "https://github.com/goodeggs/goodeggs-json-schema-validator", | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/" | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
} | ||
} |
@@ -49,1 +49,12 @@ # Good Eggs JSON Schema Validator | ||
[hiring-link]: http://goodeggs.jobscore.com/?detail=Open+Source&sid=161 | ||
## Releasing | ||
To release a new version of this module, use yarn to bump the version | ||
in `package.json` and create a git tag, then push. This will automatically | ||
get published to the NPM registry via CI. | ||
```sh | ||
yarn version --new-version=<major|minor|patch|premajor|preminor|prepatch> | ||
git push --follow-tags | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9984
7
97
60
14
1
Updatedtv4@^1.3.0