Skip to content

Commit

Permalink
feat: allow ifError to return updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Oct 20, 2018
1 parent cb0bd13 commit 92963a9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 67 deletions.
4 changes: 3 additions & 1 deletion __tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@ test('throws when using ifError', () => {

test('doesn\'t throw on ifError', () => {
validator = new Validation(CORRECT_PATH, null, { removeAdditional: true });
expect(validator.ifError('custom', { string: 'not empty', extra: true })).toBeUndefined();
expect(validator.ifError('custom', { string: 'not empty', extra: true })).toEqual({
string: 'not empty',
});
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"compile": "rimraf lib; tsc -b ./tsconfig.build.json",
"prepublishOnly": "yarn compile",
"test": "yarn lint && jest --collectCoverage && codecov >/dev/null",
"lint": "tslint -c tslint.json ./src/**/*.ts",
"lint": "tslint './src/**/*.ts' -c tslint.json",
"semantic-release": "semantic-release"
},
"repository": {
Expand All @@ -28,14 +28,14 @@
},
"homepage": "https://github.com/microfleet/validation#readme",
"devDependencies": {
"@makeomatic/deploy": "^8.0.1",
"@makeomatic/deploy": "^8.1.1",
"@types/bluebird": "^3.5.24",
"@types/callsite": "^1.0.30",
"@types/common-errors": "^1.0.0",
"@types/debug": "^0.0.31",
"@types/glob": "^7.1.1",
"@types/jest": "^23.3.5",
"@types/node": "^10.11.7",
"@types/node": "^10.12.0",
"codecov": "^3.1.0",
"jest": "^23.6.0",
"ts-jest": "^23.10.4",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export class Validator {
}
throw result.error;
}

return result.doc;
}

/**
Expand Down
116 changes: 53 additions & 63 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@commitlint/cli@^7.1.2":
"@commitlint/cli@^7.2.1":
version "7.2.1"
resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-7.2.1.tgz#dbb9eeb1f5015a129bb0801fbc1115eb1dcd513b"
integrity sha512-PUHWGoQOx8m6ZSpZPSHb+YISFAvW7jiWvCJOQiViKHZC8CLKu4bjyc/AwP8gBte0RsTGAu1ekiitp5Q0NcLGcA==
Expand Down Expand Up @@ -152,27 +152,31 @@
dependencies:
find-up "^2.1.0"

"@makeomatic/deploy@^8.0.1":
version "8.0.1"
resolved "https://registry.yarnpkg.com/@makeomatic/deploy/-/deploy-8.0.1.tgz#2fa0d60aa6012e1daa22e53aec478227f200affc"
integrity sha512-PJDdfFzvEqT2FKFqJppONuyFkMkzWPUNiq7HiwH87XlLc0Z75Z3G2r+B3n2ohTgsh6z9heAnKLFsCvxBSEZW3w==
"@makeomatic/deploy@^8.1.1":
version "8.1.1"
resolved "https://registry.yarnpkg.com/@makeomatic/deploy/-/deploy-8.1.1.tgz#1d3be007d3dd5ec18d93aa2cc395f7a127a62ac4"
integrity sha512-EDQcFeaT4qimPx1PnQi3eXcvzyLXjSnVHi1zmpFDuZsEL8Dh31GyLaffNtTk8FsfusLcXMXmksukmJyxWDnCUQ==
dependencies:
"@commitlint/cli" "^7.1.2"
"@commitlint/cli" "^7.2.1"
bluebird "^3.5.2"
chrome-launcher "^0.10.5"
chrome-remote-interface "^0.26.1"
death "^1.1.0"
find-up "^3.0.0"
glob "^7.1.3"
husky "^1.1.0"
husky "^1.1.2"
hyperid "^1.4.1"
is "^3.2.1"
js-yaml "^3.12.0"
lodash.get "^4.4.2"
lodash.merge "^4.6.1"
lodash.set "^4.3.2"
ms-conf "^3.3.0"
ms-conf "^3.3.1"
npm-path "^2.0.4"
pino "^5.6.3"
pino "^5.8.0"
read-pkg "^4.0.1"
rimraf "^2.6.2"
semantic-release "15.9.17"
semantic-release "15.9.x"
shelljs "^0.8.2"
yargs "^12.0.2"

Expand Down Expand Up @@ -383,11 +387,16 @@
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.3.29.tgz#7f2ad7ec55f914482fc9b1ec4bb1ae6028d46066"
integrity sha1-fyrX7FX5FEgvybHsS7GuYCjUYGY=

"@types/node@*", "@types/node@^10.11.7":
"@types/node@*":
version "10.11.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.11.7.tgz#0e75ca9357d646ca754016ca1d68a127ad7e7300"
integrity sha512-yOxFfkN9xUFLyvWaeYj90mlqTJ41CsQzWKS3gXdOMOyPVacUsymejKxJ4/pMW7exouubuEeZLJawGgcNGYlTeg==

"@types/node@^10.12.0":
version "10.12.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.0.tgz#ea6dcbddbc5b584c83f06c60e82736d8fbb0c235"
integrity sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ==

"@types/node@^9.3.0":
version "9.6.35"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.35.tgz#197dd535c094362a7c95f0b78f07583d6681ed26"
Expand Down Expand Up @@ -1745,14 +1754,14 @@ debug@^3.1.0:
dependencies:
ms "^2.1.1"

debug@^4.0.0, debug@^4.0.1, debug@^4.1.0:
debug@^4.0.0, debug@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.0.tgz#373687bffa678b38b1cd91f861b63850035ddc87"
integrity sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -1914,7 +1923,7 @@ dotenv@^5.0.1:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-5.0.1.tgz#a5317459bd3d79ab88cff6e44057a6a3fbb1fcef"
integrity sha512-4As8uPrjfwb7VXC+WnLCbXK7y+Ueb2B3zgNCePYfhxS1PYeaO1YTeplffTEcbfLhvFNGLAz90VvJs9yomG7bow==

dotenv@^6.0.0:
dotenv@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.1.0.tgz#9853b6ca98292acb7dec67a95018fa40bccff42c"
integrity sha512-/veDn2ztgRlB7gKmE3i9f6CmDIyXAy6d5nBq+whO9SLX+Zs1sXEgFLPi+aSuWqUuusMfbi84fT8j34fs1HaYUw==
Expand Down Expand Up @@ -2851,7 +2860,7 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"

husky@^1.1.0:
husky@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/husky/-/husky-1.1.2.tgz#574c2bb16958db8a8120b63306efaff110525c23"
integrity sha512-9TdkUpBeEOjz0AnFdUN4i3w8kEbOsVs9/WSeJqWLq2OO6bcKQhVW64Zi+pVd/AMRLpN3QTINb6ZXiELczvdmqQ==
Expand All @@ -2867,6 +2876,14 @@ husky@^1.1.0:
run-node "^1.0.0"
slash "^2.0.0"

hyperid@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/hyperid/-/hyperid-1.4.1.tgz#5df41b25a86171661b37534c3404655ae7657d29"
integrity sha512-rtuRoJyEPZZEGN25T1PC2/IYxdApJEYbBB+8e7vZMFnfhZV7HobkpUr7z1gZvcxqleg4OVg0YrMEtfmIoV85gQ==
dependencies:
uuid "^3.2.1"
uuid-parse "^1.0.0"

[email protected], iconv-lite@^0.4.4, iconv-lite@~0.4.13:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down Expand Up @@ -2916,7 +2933,7 @@ import-local@^1.0.0:
pkg-dir "^2.0.0"
resolve-cwd "^2.0.0"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -4037,11 +4054,6 @@ lockfile@^1.0.4:
dependencies:
signal-exit "^3.0.2"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -4050,33 +4062,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=

lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -4157,11 +4147,6 @@ lodash.reduce@^4.6.0:
resolved "https://registry.yarnpkg.com/lodash.reduce/-/lodash.reduce-4.6.0.tgz#f1ab6b839299ad48f784abbf476596f03b914d3b"
integrity sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs=

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down Expand Up @@ -4615,15 +4600,15 @@ move-concurrently@^1.0.1:
rimraf "^2.5.4"
run-queue "^1.0.3"

ms-conf@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/ms-conf/-/ms-conf-3.3.0.tgz#14bc72def20383305505e519780b52228ed6d5d2"
integrity sha512-Ng9RG8ev8cin2r8zOfNgjT82zVcc0yKe/fQhEMtXC/T//UpSIwJXVqAskxKiH2TozNUwNUadozdEqQmHyus47Q==
ms-conf@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/ms-conf/-/ms-conf-3.3.1.tgz#e4a4cf5395cfeb105feb50fe92887ec0f48094ef"
integrity sha512-tqqgrhAE1MZ+3Q/1HECYVM1SrxwoYwatCS5YTjfNpPTV6yE5DEOUwV5hu4VF9Wv7l2wVvSGQk2GV8AT7JMa7Dw==
dependencies:
camelcase "^5.0.0"
confidence "^3.0.2"
debug "^4.0.1"
dotenv "^6.0.0"
debug "^4.1.0"
dotenv "^6.1.0"
eventemitter3 "^3.1.0"
glob "^7.1.3"
lodash.merge "^4.6.1"
Expand Down Expand Up @@ -5476,21 +5461,21 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=

pino-std-serializers@^2.2.1:
pino-std-serializers@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-2.3.0.tgz#34eeaab97c055c28e22c0542ae55978e7e427786"
integrity sha512-klfGoOsP6sJH7ON796G4xoUSx2fkpFgKHO4YVVO2zmz31jR+etzc/QzGJILaOIiCD6HTCFgkPx+XN8nk+ruqPw==

pino@^5.6.3:
version "5.7.0"
resolved "https://registry.yarnpkg.com/pino/-/pino-5.7.0.tgz#9ca520788662646877e050e8d0704f71735e1b12"
integrity sha512-V2ST6/C7KokFH2b94MeN2ItXIu+q948CFAT5JmtbW6H0v3xmZOCJvLyYFWFwrZWgKJd05y/F1EgZcl3clkV/mA==
pino@^5.8.0:
version "5.8.0"
resolved "https://registry.yarnpkg.com/pino/-/pino-5.8.0.tgz#b566f78617c53c2bae91d30ad62d52cd1074df4a"
integrity sha512-L+nysfU1DMoMku+/4DTsBNFl/ajFzPWMGFQ7Gs3Cuo60Iya4ixPzHSxBUT6po2lQRexW9iEj8oCAIGpEXBeIZQ==
dependencies:
fast-json-parse "^1.0.3"
fast-redact "^1.2.0"
fast-safe-stringify "^2.0.6"
flatstr "^1.0.5"
pino-std-serializers "^2.2.1"
pino-std-serializers "^2.3.0"
pump "^3.0.0"
quick-format-unescaped "^3.0.0"
sonic-boom "^0.6.1"
Expand Down Expand Up @@ -5844,7 +5829,7 @@ readable-stream@~1.1.10:
isarray "0.0.1"
string_decoder "~0.10.x"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
integrity sha1-n6+jfShr5dksuuve4DDcm19AZ0c=
Expand Down Expand Up @@ -6138,7 +6123,7 @@ secure-keys@^1.0.0:
resolved "https://registry.yarnpkg.com/secure-keys/-/secure-keys-1.0.0.tgz#f0c82d98a3b139a8776a8808050b824431087fca"
integrity sha1-8MgtmKOxOah3aogIBQuCRDEIf8o=

[email protected].17:
[email protected].x:
version "15.9.17"
resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-15.9.17.tgz#fe3eb554e1e186da167b30c61bb1f9a454ebeabc"
integrity sha512-Z+LAJBuPD2pcPpRdF0zC9bwHeZkNUqgENEkWzuFdcpocA0FmFZVLMPcdZGR1+jVOjD1yiLli3MMCFYrpegIxTg==
Expand Down Expand Up @@ -7054,7 +7039,12 @@ util.promisify@^1.0.0:
define-properties "^1.1.2"
object.getownpropertydescriptors "^2.0.3"

uuid@^3.3.2:
uuid-parse@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/uuid-parse/-/uuid-parse-1.0.0.tgz#f4657717624b0e4b88af36f98d89589a5bbee569"
integrity sha1-9GV3F2JLDkuIrzb5jYlYmlu+5Wk=

uuid@^3.2.1, uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
Expand Down

0 comments on commit 92963a9

Please sign in to comment.