mirror of
https://gitlab.com/upRootNutrition/zookeeper.git
synced 2025-06-16 10:25:12 -05:00
feat: init
This commit is contained in:
parent
8379d09058
commit
2cfa016090
2929 changed files with 299087 additions and 3 deletions
326
node_modules/@sapphire/shapeshift/CHANGELOG.md
generated
vendored
Normal file
326
node_modules/@sapphire/shapeshift/CHANGELOG.md
generated
vendored
Normal file
|
@ -0,0 +1,326 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [3.9.7](https://github.com/sapphiredev/shapeshift/compare/v3.9.6...v3.9.7) - (2024-03-31)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Allow engines.node >= 16 ([a4d8c8d](https://github.com/sapphiredev/shapeshift/commit/a4d8c8d70e414192b61d565f89e51b19a117c8c1))
|
||||
|
||||
# [3.9.6](https://github.com/sapphiredev/shapeshift/compare/v3.9.6...v3.9.6) - (2024-01-19)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Fixed commonjs typings export mapping (#341) ([a5518aa](https://github.com/sapphiredev/shapeshift/commit/a5518aa88350925ad03f612e49f695a296a0d3b3))
|
||||
|
||||
# [3.9.5](https://github.com/sapphiredev/shapeshift/compare/v3.9.5...v3.9.5) - (2023-12-15)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Properly publish all dist files ([8e925fa](https://github.com/sapphiredev/shapeshift/commit/8e925faff5a67ccca84c41473bf77c9e0a01ebc0))
|
||||
|
||||
# [3.9.4](https://github.com/sapphiredev/shapeshift/compare/v3.9.4...v3.9.4) - (2023-12-04)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Properly split CJS and ESM ([9bb1ff9](https://github.com/sapphiredev/shapeshift/commit/9bb1ff95f2852e765a27c7a839ff5145ee6e3a01))
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
- Update path to global file ([d03b19f](https://github.com/sapphiredev/shapeshift/commit/d03b19f20507690869fe6b8f59a2400d95bd02be))
|
||||
|
||||
# [3.9.3](https://github.com/sapphiredev/shapeshift/compare/v3.9.3...v3.9.3) - (2023-10-13)
|
||||
|
||||
## 🏠 Refactor
|
||||
|
||||
- Change email regex (#306) ([c5d49cf](https://github.com/sapphiredev/shapeshift/commit/c5d49cf32931aff24ab74ba87ee8d6d35f7231af))
|
||||
|
||||
# [3.9.2](https://github.com/sapphiredev/shapeshift/compare/v3.9.1...v3.9.2) - (2023-06-04)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **arrayvalidator:** Fixed runaway type instantiation with TypeScript >=5.1 (#275) ([f59d901](https://github.com/sapphiredev/shapeshift/commit/f59d90112181e6625230c28e6a4f0f065ced6344))
|
||||
|
||||
# [3.9.1](https://github.com/sapphiredev/shapeshift/compare/v3.9.0...v3.9.1) - (2023-06-02)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **types:** Move the `types` condition to the front (#273) ([5a3e202](https://github.com/sapphiredev/shapeshift/commit/5a3e202e9ceafb3d330a568e93c060dd5aac1dde))
|
||||
|
||||
# [3.9.0](https://github.com/sapphiredev/shapeshift/compare/v3.8.2...v3.9.0) - (2023-05-09)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Resolve minor grammar mistake (#260) ([62df609](https://github.com/sapphiredev/shapeshift/commit/62df6094845ffa118aa93ea3c5f47f81f1c5d99f))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add BaseValidator.describe (#267) ([d9e1a2d](https://github.com/sapphiredev/shapeshift/commit/d9e1a2d2f3c5e6378f0025becf8497138ee6d97c))
|
||||
|
||||
# [3.8.2](https://github.com/sapphiredev/shapeshift/compare/v3.8.1...v3.8.2) - (2023-04-02)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- ***:** TypeScript 5.x compatibility (#253) ([eba2a88](https://github.com/sapphiredev/shapeshift/commit/eba2a88b91fb6631f431313753299ec7a70cf6ce))
|
||||
- Remove `node:` prefix (#249) ([af766b5](https://github.com/sapphiredev/shapeshift/commit/af766b504c1013f3cd24f7bf803ac9ff7442a8d7))
|
||||
|
||||
# [3.8.1](https://github.com/sapphiredev/shapeshift/compare/v3.8.0...v3.8.1) - (2022-12-15)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Fixed lodash esm import (#230) ([63def7b](https://github.com/sapphiredev/shapeshift/commit/63def7bcec6319b3792093945ba7ba9f871ced6f))
|
||||
|
||||
# [3.8.0](https://github.com/sapphiredev/shapeshift/compare/v3.7.1...v3.8.0) - (2022-12-11)
|
||||
|
||||
## 🏠 Refactor
|
||||
|
||||
- Remove `NonNullObject` (#227) ([04d3934](https://github.com/sapphiredev/shapeshift/commit/04d39343f55a4e1571f54870a84d8b95447bd682))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add `when` constraint (#223) ([8eade90](https://github.com/sapphiredev/shapeshift/commit/8eade90cd4c02b80746ecdcdc612829d7f765178))
|
||||
|
||||
# [3.7.1](https://github.com/sapphiredev/shapeshift/compare/v3.7.0...v3.7.1) - (2022-11-27)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Fixed "jump to definition" for `undefinedToOptional` going to wrong symbol (#226) ([6aab6d0](https://github.com/sapphiredev/shapeshift/commit/6aab6d01450fd7abbeaa95e91fb58568240e02ff))
|
||||
|
||||
## 📝 Documentation
|
||||
|
||||
- Add @legendhimslef as a contributor ([499522a](https://github.com/sapphiredev/shapeshift/commit/499522a782c3ecd4df80978d0811df1a75d08212))
|
||||
|
||||
# [3.7.0](https://github.com/sapphiredev/shapeshift/compare/v3.6.0...v3.7.0) - (2022-10-02)
|
||||
|
||||
## 📝 Documentation
|
||||
|
||||
- Add phone in readme (#203) ([4ec9b7a](https://github.com/sapphiredev/shapeshift/commit/4ec9b7ab85124d84b3404cb548b17b9221a716c5))
|
||||
- Add RealShadowNova as a contributor for tool (#185) ([6dfc442](https://github.com/sapphiredev/shapeshift/commit/6dfc442af6ef26d6bbca39078eca5727257b6dab))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add `s.string.phone` (#202) ([7d122d5](https://github.com/sapphiredev/shapeshift/commit/7d122d5dc0eaa63c639b9cde1514e63566a681bd))
|
||||
|
||||
# [3.6.0](https://github.com/sapphiredev/shapeshift/compare/v3.5.1...v3.6.0) - (2022-08-29)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Typescript 4.8 compatibility (#179) ([2281535](https://github.com/sapphiredev/shapeshift/commit/2281535f7589a987510828e46bf66accc8393c34))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add `Validator#is` (#183) ([5114f95](https://github.com/sapphiredev/shapeshift/commit/5114f9516e5406cd1ca4a7ceb5ea5761158af1c6))
|
||||
|
||||
# [3.5.1](https://github.com/sapphiredev/shapeshift/compare/v3.5.0...v3.5.1) - (2022-07-17)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Fast deep equal import (#155) ([5ce8ff6](https://github.com/sapphiredev/shapeshift/commit/5ce8ff6803b70624af07c3e406bc1cdc9e3cdafe))
|
||||
|
||||
# [3.5.0](https://github.com/sapphiredev/shapeshift/compare/v3.4.1...v3.5.0) - (2022-07-10)
|
||||
|
||||
## 🏠 Refactor
|
||||
|
||||
- Port net module (#149) ([5f26e32](https://github.com/sapphiredev/shapeshift/commit/5f26e32b0f87d2b100ca13471d5835c0067ddee8))
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Ensure browser compatibility (#150) ([92d05d8](https://github.com/sapphiredev/shapeshift/commit/92d05d83c1fbab53f98f61219fb01d49fc031bae))
|
||||
- Fixed `s.array` type inference (#153) ([a5948dc](https://github.com/sapphiredev/shapeshift/commit/a5948dc67ce6a0ea73986d32084898a4ce0b9c3a))
|
||||
- Fixed `shape#array` types (#146) ([43016a0](https://github.com/sapphiredev/shapeshift/commit/43016a025b04a676d906758ed065d26a17231888))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Lazy validator (#147) ([807666e](https://github.com/sapphiredev/shapeshift/commit/807666ef537c84d2e0f8bd9f4ce1a8060bfb3fb5))
|
||||
- Reshape finally (#148) ([d3751f6](https://github.com/sapphiredev/shapeshift/commit/d3751f6d3d99f415d797369f98158f932371e02c))
|
||||
- **arrays:** Add unique (#141) ([ad7af34](https://github.com/sapphiredev/shapeshift/commit/ad7af34eb811541253150b7ff0b58a6bd7200796))
|
||||
|
||||
# [3.4.1](https://github.com/sapphiredev/shapeshift/compare/v3.4.0...v3.4.1) - (2022-07-03)
|
||||
|
||||
## 🏠 Refactor
|
||||
|
||||
- Move all type utilities to one file (#139) ([61cab3d](https://github.com/sapphiredev/shapeshift/commit/61cab3d0e486d9dc74c8f6160ff8c75c91b595b2))
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Return array-validator from length* methods (#140) ([75b1f9a](https://github.com/sapphiredev/shapeshift/commit/75b1f9a6efffb6c27dcfd48eb4ec6269a3614633))
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
- Typechecking for tests (#145) ([273cdc8](https://github.com/sapphiredev/shapeshift/commit/273cdc82c1cf65ba4111ca6e70b050e02cbdf485))
|
||||
|
||||
# [3.4.0](https://github.com/sapphiredev/shapeshift/compare/v3.3.2...v3.4.0) - (2022-06-29)
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add `required` in object validation (#137) ([928f7be](https://github.com/sapphiredev/shapeshift/commit/928f7beb5e727b47868e9e46f2191f2def228080))
|
||||
|
||||
# [3.3.2](https://github.com/sapphiredev/shapeshift/compare/v3.3.1...v3.3.2) - (2022-06-26)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Make keys optional in object parsing (#134) ([57a3719](https://github.com/sapphiredev/shapeshift/commit/57a37193d64399aae1431b041012d582e8defecf))
|
||||
|
||||
# [3.3.1](https://github.com/sapphiredev/shapeshift/compare/v3.3.0...v3.3.1) - (2022-06-22)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Add generic type to parse (#133) ([90c91aa](https://github.com/sapphiredev/shapeshift/commit/90c91aad572d51a2bfbd1ed32a51e1d4201c5d4a))
|
||||
|
||||
# [3.3.0](https://github.com/sapphiredev/shapeshift/compare/v3.2.0...v3.3.0) - (2022-06-19)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Compile for es2020 instead of es2021 (#128) ([051344d](https://github.com/sapphiredev/shapeshift/commit/051344debe1cf423713d7fc64b8908353348f301))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Allow passing functions in `setValidationEnabled` (#131) ([e1991cf](https://github.com/sapphiredev/shapeshift/commit/e1991cfef1ffe92f9167d11d7f2ded65379df8d2))
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
- Migrate to vitest (#126) ([4d80969](https://github.com/sapphiredev/shapeshift/commit/4d80969b714c39768499569456405a73c1444da8))
|
||||
|
||||
# [3.2.0](https://github.com/sapphiredev/shapeshift/compare/v3.1.0...v3.2.0) - (2022-06-11)
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add disabling of validators (#125) ([e17af95](https://github.com/sapphiredev/shapeshift/commit/e17af95d697be62796c57d03385b0c74b9d2d580))
|
||||
|
||||
# [3.1.0](https://github.com/sapphiredev/shapeshift/compare/v3.0.0...v3.1.0) - (2022-06-04)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **ObjectValidator:** Fix #121 (#122) ([ecfad7e](https://github.com/sapphiredev/shapeshift/commit/ecfad7ec2cdd9e0cee0b3e227e55a91b28c29c30))
|
||||
|
||||
## 📝 Documentation
|
||||
|
||||
- **readme:** Clarify the difference between validations and schemas and add table of contents (#108) ([dc492a3](https://github.com/sapphiredev/shapeshift/commit/dc492a395349cc5bc680f313146127ea510b4ada))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- **StringValidator:** Add date string checks (#106) ([1b72907](https://github.com/sapphiredev/shapeshift/commit/1b729078be32a88aeddf574c9cff3098990d4f94))
|
||||
|
||||
# [3.0.0](https://github.com/sapphiredev/shapeshift/compare/v2.2.0...v3.0.0) - (2022-05-06)
|
||||
|
||||
## 🏃 Performance
|
||||
|
||||
- Speed up object validation a LOT (#101) ([817278e](https://github.com/sapphiredev/shapeshift/commit/817278e6a3ac128ca342e5ae1737f40b98788c37))
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Expand method names (#100) ([741490f](https://github.com/sapphiredev/shapeshift/commit/741490fb6907f618fa25fe53808f7dcb5a59a96c))}
|
||||
|
||||
### 💥 Breaking Changes:
|
||||
- `date.eq` has been renamed to `date.equal`
|
||||
- `string.lengthLt` has been renamed to `string.lengthLessThan`
|
||||
- `string.lengthLe` has been renamed to `string.lengthLessThanOrEqual`
|
||||
- `string.lengthGt` has been renamed to `string.lengthGreaterThan`
|
||||
- `string.lengthGe` has been renamed to `string.lengthGreaterThanOrEqual`
|
||||
- `string.lengthEq` has been renamed to `string.lengthEqual`
|
||||
- `string.lengthNe` has been renamed to `string.lengthNotEqual`
|
||||
- `number.gt` has been renamed to `number.greaterThan`
|
||||
- `number.ge` has been renamed to `number.greaterThanOrEqual`
|
||||
- `number.lt` has been renamed to `number.lessThan`
|
||||
- `number.le` has been renamed to `number.lessThanOrEqual`
|
||||
- `number.eq` has been renamed to `number.equal`
|
||||
- `number.ne` has been renamed to `number.notEqual`
|
||||
- `bigint.gt` has been renamed to `bigint.greaterThan`
|
||||
- `bigint.ge` has been renamed to `bigint.greaterThanOrEqual`
|
||||
- `bigint.lt` has been renamed to `bigint.lessThan`
|
||||
- `bigint.le` has been renamed to `bigint.lessThanOrEqual`
|
||||
- `bigint.eq` has been renamed to `bigint.equal`
|
||||
- `bigint.ne` has been renamed to `bigint.notEqual`
|
||||
- `boolean.eq` has been renamed to `boolean.equal`
|
||||
- `boolean.ne` has been renamed to `boolean.notEqual`
|
||||
- `array.lengthLt` has been renamed to `array.lengthLessThan`
|
||||
- `array.lengthLe` has been renamed to `array.lengthLessThanOrEqual`
|
||||
- `array.lengthGt` has been renamed to `array.lengthGreaterThan`
|
||||
- `array.lengthGe` has been renamed to `array.lengthGreaterThanOrEqual`
|
||||
- `array.lengthEq` has been renamed to `array.lengthEqual`
|
||||
- `array.lengthNe` has been renamed to `array.lengthNotEqual`
|
||||
- `typedArray.lengthLt` has been renamed to `typedArray.lengthLessThan`
|
||||
- `typedArray.lengthLe` has been renamed to `typedArray.lengthLessThanOrEqual`
|
||||
- `typedArray.lengthGt` has been renamed to `typedArray.lengthGreaterThan`
|
||||
- `typedArray.lengthGe` has been renamed to `typedArray.lengthGreaterThanOrEqual`
|
||||
- `typedArray.lengthEq` has been renamed to `typedArray.lengthEqual`
|
||||
- `typedArray.lengthNe` has been renamed to `typedArray.lengthNotEqual`
|
||||
- `typedArray.byteLengthLt` has been renamed to `typedArray.byteLengthLessThan`
|
||||
- `typedArray.byteLengthLe` has been renamed to `typedArray.byteLengthLessThanOrEqual`
|
||||
- `typedArray.byteLengthGt` has been renamed to `typedArray.byteLengthGreaterThan`
|
||||
- `typedArray.byteLengthGe` has been renamed to `typedArray.byteLengthGreaterThanOrEqual`
|
||||
- `typedArray.byteLengthEq` has been renamed to `typedArray.byteLengthEqual`
|
||||
- `typedArray.byteLengthNe` has been renamed to `typedArray.byteLengthNotEqual`
|
||||
|
||||
- **ObjectValidator:** Don't run validation on arrays (#99) ([c83b3d0](https://github.com/sapphiredev/shapeshift/commit/c83b3d03a201d38cc230d9c831ca1d9b66ca533b))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add 2 utility types inspired by yup and co (#102) ([2fef902](https://github.com/sapphiredev/shapeshift/commit/2fef9026c30f2f1825aa55511d0ab088a3dd13ab))
|
||||
|
||||
# [2.2.0](https://github.com/sapphiredev/shapeshift/compare/v2.0.0...v2.2.0) - (2022-04-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Ensure `BaseError` is exported as value (#95) ([335d799](https://github.com/sapphiredev/shapeshift/commit/335d799ef7a8c1a19a12e3eeec07e6d210db113d))
|
||||
|
||||
## Documentation
|
||||
|
||||
- **readme:** Add todo notice for `reshape` and `function` validations (#75) ([d5f16f6](https://github.com/sapphiredev/shapeshift/commit/d5f16f615de83503187dc834c6245fafbf138f5e))
|
||||
|
||||
## Features
|
||||
|
||||
- Add Typed Array (#78) ([ca5ea5f](https://github.com/sapphiredev/shapeshift/commit/ca5ea5f568084bd5d3aa004911d4ea64329e1a89))
|
||||
|
||||
## Performance
|
||||
|
||||
- Optimize `NativeEnum` (#79) ([e9ae280](https://github.com/sapphiredev/shapeshift/commit/e9ae280f73e9ea08239bd8bd22165fe0b2178f82))
|
||||
|
||||
# [@sapphire/shapeshift@2.1.0](https://github.com/sapphiredev/shapeshift/compare/v2.0.0...@sapphire/shapeshift@2.1.0) - (2022-04-24)
|
||||
|
||||
## Documentation
|
||||
|
||||
- **readme:** Add todo notice for `reshape` and `function` validations (#75) ([d5f16f6](https://github.com/sapphiredev/shapeshift/commit/d5f16f615de83503187dc834c6245fafbf138f5e))
|
||||
|
||||
## Performance
|
||||
|
||||
- Optimize `NativeEnum` (#79) ([e9ae280](https://github.com/sapphiredev/shapeshift/commit/e9ae280f73e9ea08239bd8bd22165fe0b2178f82))
|
||||
|
||||
## [2.0.0](https://github.com/sapphiredev/shapeshift/compare/v1.0.0...v2.0.0) (2022-03-13)
|
||||
|
||||
### Features
|
||||
|
||||
- add `default` ([#25](https://github.com/sapphiredev/shapeshift/issues/25)) ([378c51f](https://github.com/sapphiredev/shapeshift/commit/378c51fb4ba2c501fd782387169db888d6bfe662))
|
||||
- add bigint methods ([#32](https://github.com/sapphiredev/shapeshift/issues/32)) ([4c444c1](https://github.com/sapphiredev/shapeshift/commit/4c444c15657c4610b99481b6dec9812bd136d72b))
|
||||
- add MapValidator ([#21](https://github.com/sapphiredev/shapeshift/issues/21)) ([c4d1258](https://github.com/sapphiredev/shapeshift/commit/c4d12586762d446b858454077b66635d9d11e2d6))
|
||||
- add NativeEnum validator ([#54](https://github.com/sapphiredev/shapeshift/issues/54)) ([7359042](https://github.com/sapphiredev/shapeshift/commit/7359042843d1119f396ac2c038aaff89dbd90c8e))
|
||||
- add RecordValidator ([#20](https://github.com/sapphiredev/shapeshift/issues/20)) ([8727427](https://github.com/sapphiredev/shapeshift/commit/8727427be4656792eebcdc5bddf6bcd61bc7e846))
|
||||
- add remaining string validations ([#38](https://github.com/sapphiredev/shapeshift/issues/38)) ([1c2fd7b](https://github.com/sapphiredev/shapeshift/commit/1c2fd7bbb20463f09ac461b697c312bec6ae9195))
|
||||
- add tuple ([#39](https://github.com/sapphiredev/shapeshift/issues/39)) ([b7704bf](https://github.com/sapphiredev/shapeshift/commit/b7704bf87cf5225021408cf4a6b9ceff8cba25b3))
|
||||
- added number transformers ([#17](https://github.com/sapphiredev/shapeshift/issues/17)) ([89a8ddd](https://github.com/sapphiredev/shapeshift/commit/89a8ddd8583774e68c43260c28ee1589ef44516c))
|
||||
- allow the use of module: NodeNext ([#55](https://github.com/sapphiredev/shapeshift/issues/55)) ([e6827c5](https://github.com/sapphiredev/shapeshift/commit/e6827c5a12b6a2803a137b71fe4c21bd1c35034b))
|
||||
- **array:** add array length Comparators ([#40](https://github.com/sapphiredev/shapeshift/issues/40)) ([1e564c2](https://github.com/sapphiredev/shapeshift/commit/1e564c204b6c9b0a798b3121d31dd4cc99165f60))
|
||||
- **Array:** generate tuple types with given length ([#52](https://github.com/sapphiredev/shapeshift/issues/52)) ([793648b](https://github.com/sapphiredev/shapeshift/commit/793648b4cde1f72c5b735ceebb0c48272179be06))
|
||||
- **ArrayValidator:** add length ranges ([#53](https://github.com/sapphiredev/shapeshift/issues/53)) ([e431d62](https://github.com/sapphiredev/shapeshift/commit/e431d6218b86fc1480fce14c4466cb36567cad2f))
|
||||
- display the property that errored ([#35](https://github.com/sapphiredev/shapeshift/issues/35)) ([fe188b0](https://github.com/sapphiredev/shapeshift/commit/fe188b0d17eeaa5f73b08085562903e23e91717c))
|
||||
- improve how errors are returned ([#29](https://github.com/sapphiredev/shapeshift/issues/29)) ([8bc7669](https://github.com/sapphiredev/shapeshift/commit/8bc7669a1a66a10449b321cc4447e411383977d9))
|
||||
- **s.object:** add passthrough ([#66](https://github.com/sapphiredev/shapeshift/issues/66)) ([ee9f6f3](https://github.com/sapphiredev/shapeshift/commit/ee9f6f367e513c0120a04cfafe05057c7907c327))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- copy/paste error and `ge` ([#22](https://github.com/sapphiredev/shapeshift/issues/22)) ([fe6505f](https://github.com/sapphiredev/shapeshift/commit/fe6505f8e698bcaf9f8024b2d8f012559827cbb0))
|
||||
- fix union type and add test ([#41](https://github.com/sapphiredev/shapeshift/issues/41)) ([fbcf8a9](https://github.com/sapphiredev/shapeshift/commit/fbcf8a9c617c16b33fdddb0a44aa0fe506164fd3))
|
||||
- **s.union:** fix union overrides ([#62](https://github.com/sapphiredev/shapeshift/issues/62)) ([56e9b19](https://github.com/sapphiredev/shapeshift/commit/56e9b1947d9b2b129dbed374671114b2242e6d35))
|
||||
|
||||
## 1.0.0 (2022-01-16)
|
||||
|
||||
### Features
|
||||
|
||||
- added more primitives ([#2](https://github.com/sapphiredev/shapeshift/issues/2)) ([16af17b](https://github.com/sapphiredev/shapeshift/commit/16af17b5d9ee40dce284ee120e0b099f7b2cc0b8))
|
||||
- added more things ([7c73d82](https://github.com/sapphiredev/shapeshift/commit/7c73d82cf3740d5b2d4eebcac7767da9d3562437))
|
||||
- added ObjectValidator ([#3](https://github.com/sapphiredev/shapeshift/issues/3)) ([abe7ead](https://github.com/sapphiredev/shapeshift/commit/abe7eaddee981ef485713ff5e7b7f32ff97c645b))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- resolved install error ([a5abe13](https://github.com/sapphiredev/shapeshift/commit/a5abe1362bb6d9ce6d6471bffa47fe8983b0d1a4))
|
24
node_modules/@sapphire/shapeshift/LICENSE.md
generated
vendored
Normal file
24
node_modules/@sapphire/shapeshift/LICENSE.md
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
# The MIT License (MIT)
|
||||
|
||||
Copyright © `2021` `The Sapphire Community and its contributors`
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the “Software”), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
934
node_modules/@sapphire/shapeshift/README.md
generated
vendored
Normal file
934
node_modules/@sapphire/shapeshift/README.md
generated
vendored
Normal file
|
@ -0,0 +1,934 @@
|
|||
<div align="center">
|
||||
|
||||

|
||||
|
||||
# @sapphire/shapeshift
|
||||
|
||||
**Shapeshift**
|
||||
|
||||
Blazing fast input validation and transformation ⚡
|
||||
|
||||
[](https://github.com/sapphiredev/shapeshift/blob/main/LICENSE.md)
|
||||
[](https://codecov.io/gh/sapphiredev/shapeshift)
|
||||
[](https://www.npmjs.com/package/@sapphire/shapeshift)
|
||||
|
||||
</div>
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [@sapphire/shapeshift](#sapphireshapeshift)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Description](#description)
|
||||
- [Features](#features)
|
||||
- [Usage](#usage)
|
||||
- [Basic usage](#basic-usage)
|
||||
- [Defining validations](#defining-validations)
|
||||
- [Primitives](#primitives)
|
||||
- [Literals](#literals)
|
||||
- [Strings](#strings)
|
||||
- [Numbers](#numbers)
|
||||
- [BigInts](#bigints)
|
||||
- [Booleans](#booleans)
|
||||
- [Arrays](#arrays)
|
||||
- [Tuples](#tuples)
|
||||
- [Unions](#unions)
|
||||
- [Enums](#enums)
|
||||
- [Maps](#maps)
|
||||
- [Sets](#sets)
|
||||
- [Instances](#instances)
|
||||
- [Records](#records)
|
||||
- [Functions // TODO](#functions--todo)
|
||||
- [TypedArray](#typedarray)
|
||||
- [Defining schemas (objects)](#defining-schemas-objects)
|
||||
- [Utility types for TypeScript](#utility-types-for-typescript)
|
||||
- [Extracting an interface from a schema](#extracting-an-interface-from-a-schema)
|
||||
- [Defining the structure of a schema through an interface](#defining-the-structure-of-a-schema-through-an-interface)
|
||||
- [`.extend`:](#extend)
|
||||
- [`.pick` / `.omit`:](#pick--omit)
|
||||
- [`.partial`](#partial)
|
||||
- [`.required`](#required)
|
||||
- [Handling unrecognized keys](#handling-unrecognized-keys)
|
||||
- [`.strict`](#strict)
|
||||
- [`.ignore`](#ignore)
|
||||
- [`.passthrough`](#passthrough)
|
||||
- [BaseValidator: methods and properties](#basevalidator-methods-and-properties)
|
||||
- [`.run`](#rundata-unknown-resultt-error-given-a-validation-you-can-call-this-method-to-check-whether-or-not-the)
|
||||
- [`.parse`](#parsedata-unknown-t-given-a-validations-you-can-call-this-method-to-check-whether-or-not-the-input-is-valid)
|
||||
- [`.transform`](#transformrvalue-t--r-nopvalidatorr-adds-a-constraint-that-modifies-the-input)
|
||||
- [`.reshape`](#reshapervalue-t--resultr-error--iconstraint-nopvalidatorr-adds-a-constraint-able-to-both-validate)
|
||||
- [`.default`](#defaultvalue-t----t-transform-undefined-into-the-given-value-or-the-callbacks-returned-value)
|
||||
- [`.optional`](#optional-a-convenience-method-that-returns-a-union-of-the-type-with-sundefined)
|
||||
- [`.nullable`](#nullable-a-convenience-method-that-returns-a-union-of-the-type-with-snullable)
|
||||
- [`.nullish`](#nullish-a-convenience-method-that-returns-a-union-of-the-type-with-snullish)
|
||||
- [`.array`](#array-a-convenience-method-that-returns-an-arrayvalidator-with-the-type)
|
||||
- [`.or`](#or-a-convenience-method-that-returns-an-unionvalidator-with-the-type-this-method-is-also-overridden-in)
|
||||
- [`.when`](#when-adjust-the-schema-based-on-a-sibling-or-sinbling-children-fields)
|
||||
- [Available options for providing `is`](#available-options-for-providing-is)
|
||||
- [Resolving of the `key` (first) parameter](#resolving-of-the-key-first-parameter)
|
||||
- [Examples](#examples)
|
||||
- [Enabling and disabling validation](#enabling-and-disabling-validation)
|
||||
- [Buy us some doughnuts](#buy-us-some-doughnuts)
|
||||
- [Contributors](#contributors)
|
||||
|
||||
## Description
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
A very fast and lightweight input validation and transformation library for JavaScript.
|
||||
|
||||
> **Note**: Shapeshift requires Node.js v14.0.0 or higher to work.
|
||||
|
||||
## Features
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
- TypeScript friendly
|
||||
- Offers CJS, ESM and UMD builds
|
||||
- API similar to [`zod`]
|
||||
- Faster than ⚡
|
||||
|
||||
## Usage
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
**_For complete usages, please dive into our [documentation]_**
|
||||
|
||||
### Basic usage
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Creating a simple string validation
|
||||
|
||||
```typescript
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
|
||||
const myStringValidation = s.string;
|
||||
|
||||
// Parse
|
||||
myStringValidation.parse('sapphire'); // => returns 'sapphire'
|
||||
myStringValidation.parse(12); // throws ValidationError
|
||||
```
|
||||
|
||||
Creating an object schema
|
||||
|
||||
```typescript
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
|
||||
const user = s.object({
|
||||
username: s.string
|
||||
});
|
||||
|
||||
user.parse({ username: 'Sapphire' });
|
||||
```
|
||||
|
||||
### Defining validations
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
#### Primitives
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```typescript
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
|
||||
// Primitives
|
||||
s.string;
|
||||
s.number;
|
||||
s.bigint;
|
||||
s.boolean;
|
||||
s.date;
|
||||
|
||||
// Empty Types
|
||||
s.undefined;
|
||||
s.null;
|
||||
s.nullish; // Accepts undefined | null
|
||||
|
||||
// Catch-all Types
|
||||
s.any;
|
||||
s.unknown;
|
||||
|
||||
// Never Type
|
||||
s.never;
|
||||
```
|
||||
|
||||
#### Literals
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```typescript
|
||||
s.literal('sapphire');
|
||||
s.literal(12);
|
||||
s.literal(420n);
|
||||
s.literal(true);
|
||||
s.literal(new Date(1639278160000)); // s.date.equal(1639278160000);
|
||||
```
|
||||
|
||||
#### Strings
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Shapeshift includes a handful of string-specific validations:
|
||||
|
||||
```typescript
|
||||
s.string.lengthLessThan(5);
|
||||
s.string.lengthLessThanOrEqual(5);
|
||||
s.string.lengthGreaterThan(5);
|
||||
s.string.lengthGreaterThanOrEqual(5);
|
||||
s.string.lengthEqual(5);
|
||||
s.string.lengthNotEqual(5);
|
||||
s.string.email;
|
||||
s.string.url();
|
||||
s.string.uuid();
|
||||
s.string.regex(regex);
|
||||
s.string.ip();
|
||||
s.string.ipv4;
|
||||
s.string.ipv6;
|
||||
s.string.phone();
|
||||
```
|
||||
|
||||
#### Numbers
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Shapeshift includes a handful of number-specific validations:
|
||||
|
||||
```typescript
|
||||
s.number.greaterThan(5); // > 5
|
||||
s.number.greaterThanOrEqual(5); // >= 5
|
||||
s.number.lessThan(5); // < 5
|
||||
s.number.lessThanOrEqual(5); // <= 5
|
||||
s.number.equal(5); // === 5
|
||||
s.number.notEqual(5); // !== 5
|
||||
|
||||
s.number.equal(NaN); // special case: Number.isNaN
|
||||
s.number.notEqual(NaN); // special case: !Number.isNaN
|
||||
|
||||
s.number.int; // value must be an integer
|
||||
s.number.safeInt; // value must be a safe integer
|
||||
s.number.finite; // value must be finite
|
||||
|
||||
s.number.positive; // .greaterThanOrEqual(0)
|
||||
s.number.negative; // .lessThan(0)
|
||||
|
||||
s.number.divisibleBy(5); // Divisible by 5
|
||||
```
|
||||
|
||||
And transformations:
|
||||
|
||||
```typescript
|
||||
s.number.abs; // Transforms the number to an absolute number
|
||||
s.number.sign; // Gets the number's sign
|
||||
|
||||
s.number.trunc; // Transforms the number to the result of `Math.trunc`
|
||||
s.number.floor; // Transforms the number to the result of `Math.floor`
|
||||
s.number.fround; // Transforms the number to the result of `Math.fround`
|
||||
s.number.round; // Transforms the number to the result of `Math.round`
|
||||
s.number.ceil; // Transforms the number to the result of `Math.ceil`
|
||||
```
|
||||
|
||||
#### BigInts
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Shapeshift includes a handful of number-specific validations:
|
||||
|
||||
```typescript
|
||||
s.bigint.greaterThan(5n); // > 5n
|
||||
s.bigint.greaterThanOrEqual(5n); // >= 5n
|
||||
s.bigint.lessThan(5n); // < 5n
|
||||
s.bigint.lessThanOrEqual(5n); // <= 5n
|
||||
s.bigint.equal(5n); // === 5n
|
||||
s.bigint.notEqual(5n); // !== 5n
|
||||
|
||||
s.bigint.positive; // .greaterThanOrEqual(0n)
|
||||
s.bigint.negative; // .lessThan(0n)
|
||||
|
||||
s.bigint.divisibleBy(5n); // Divisible by 5n
|
||||
```
|
||||
|
||||
And transformations:
|
||||
|
||||
```typescript
|
||||
s.bigint.abs; // Transforms the bigint to an absolute bigint
|
||||
|
||||
s.bigint.intN(5); // Clamps to a bigint to a signed bigint with 5 digits, see BigInt.asIntN
|
||||
s.bigint.uintN(5); // Clamps to a bigint to an unsigned bigint with 5 digits, see BigInt.asUintN
|
||||
```
|
||||
|
||||
#### Booleans
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Shapeshift includes a few boolean-specific validations:
|
||||
|
||||
```typescript
|
||||
s.boolean.true; // value must be true
|
||||
s.boolean.false; // value must be false
|
||||
|
||||
s.boolean.equal(true); // s.boolean.true
|
||||
s.boolean.equal(false); // s.boolean.false
|
||||
|
||||
s.boolean.notEqual(true); // s.boolean.false
|
||||
s.boolean.notEqual(false); // s.boolean.true
|
||||
```
|
||||
|
||||
#### Arrays
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```typescript
|
||||
const stringArray = s.array(s.string);
|
||||
const stringArray = s.string.array;
|
||||
```
|
||||
|
||||
Shapeshift includes a handful of array-specific validations:
|
||||
|
||||
```typescript
|
||||
s.string.array.lengthLessThan(5); // Must have less than 5 elements
|
||||
s.string.array.lengthLessThanOrEqual(5); // Must have 5 or less elements
|
||||
s.string.array.lengthGreaterThan(5); // Must have more than 5 elements
|
||||
s.string.array.lengthGreaterThanOrEqual(5); // Must have 5 or more elements
|
||||
s.string.array.lengthEqual(5); // Must have exactly 5 elements
|
||||
s.string.array.lengthNotEqual(5); // Must not have exactly 5 elements
|
||||
s.string.array.lengthRange(0, 4); // Must have at least 0 elements and less than 4 elements (in math, that is [0, 4))
|
||||
s.string.array.lengthRangeInclusive(0, 4); // Must have at least 0 elements and at most 4 elements (in math, that is [0, 4])
|
||||
s.string.array.lengthRangeExclusive(0, 4); // Must have more than 0 element and less than 4 elements (in math, that is (0, 4))
|
||||
s.string.array.unique; // All elements must be unique. Deep equality is used to check for uniqueness.
|
||||
```
|
||||
|
||||
> **Note**: All `.length` methods define tuple types with the given amount of elements. For example,
|
||||
> `s.string.array.lengthGreaterThanOrEqual(2)`'s inferred type is `[string, string, ...string[]]`
|
||||
|
||||
#### Tuples
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Unlike arrays, tuples have a fixed number of elements and each element can have a different type:
|
||||
|
||||
```typescript
|
||||
const dish = s.tuple([
|
||||
s.string, // Dish's name
|
||||
s.number.int, // Table's number
|
||||
s.date // Date the dish was ready for delivery
|
||||
]);
|
||||
|
||||
dish.parse(['Iberian ham', 10, new Date()]);
|
||||
```
|
||||
|
||||
#### Unions
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Shapeshift includes a built-in method for composing OR types:
|
||||
|
||||
```typescript
|
||||
const stringOrNumber = s.union(s.string, s.number);
|
||||
|
||||
stringOrNumber.parse('Sapphire'); // => 'Sapphire'
|
||||
stringOrNumber.parse(42); // => 42
|
||||
stringOrNumber.parse({}); // => throws CombinedError
|
||||
```
|
||||
|
||||
#### Enums
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Enums are a convenience method that aliases `s.union(s.literal(a), s.literal(b), ...)`:
|
||||
|
||||
```typescript
|
||||
s.enum('Red', 'Green', 'Blue');
|
||||
// s.union(s.literal('Red'), s.literal('Green'), s.literal('Blue'));
|
||||
```
|
||||
|
||||
#### Maps
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```typescript
|
||||
const map = s.map(s.string, s.number);
|
||||
// Map<string, number>
|
||||
```
|
||||
|
||||
#### Sets
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```typescript
|
||||
const set = s.set(s.number);
|
||||
// Set<number>
|
||||
```
|
||||
|
||||
#### Instances
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can use `s.instance(Class)` to check that the input is an instance of a class. This is useful to validate inputs
|
||||
against classes:
|
||||
|
||||
```typescript
|
||||
class User {
|
||||
public constructor(public name: string) {}
|
||||
}
|
||||
|
||||
const userInstanceValidation = s.instance(User);
|
||||
userInstanceValidation.parse(new User('Sapphire')); // => User { name: 'Sapphire' }
|
||||
userInstanceValidation.parse('oops'); // => throws ValidatorError
|
||||
```
|
||||
|
||||
#### Records
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Record validations are similar to objects, but validate `Record<string, T>` types. Keep in mind this does not check for
|
||||
the keys, and cannot support validation for specific ones:
|
||||
|
||||
```typescript
|
||||
const tags = s.record(s.string);
|
||||
|
||||
tags.parse({ foo: 'bar', hello: 'world' }); // => { foo: 'bar', hello: 'world' }
|
||||
tags.parse({ foo: 42 }); // => throws CombinedError
|
||||
tags.parse('Hello'); // => throws ValidateError
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
_**Function validation is not yet implemented and will be made available starting v2.1.0**_
|
||||
|
||||
#### Functions // TODO
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can define function validations. This checks for whether or not an input is a function:
|
||||
|
||||
```typescript
|
||||
s.function; // () => unknown
|
||||
```
|
||||
|
||||
You can define arguments by passing an array as the first argument, as well as the return type as the second:
|
||||
|
||||
```typescript
|
||||
s.function([s.string]); // (arg0: string) => unknown
|
||||
s.function([s.string, s.number], s.string); // (arg0: string, arg1: number) => string
|
||||
```
|
||||
|
||||
> **Note**: Shapeshift will transform the given function into one with validation on arguments and output. You can
|
||||
> access the `.raw` property of the function to get the unchecked function.
|
||||
|
||||
---
|
||||
|
||||
#### TypedArray
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```ts
|
||||
const typedArray = s.typedArray();
|
||||
const int16Array = s.int16Array;
|
||||
const uint16Array = s.uint16Array;
|
||||
const uint8ClampedArray = s.uint8ClampedArray;
|
||||
const int16Array = s.int16Array;
|
||||
const uint16Array = s.uint16Array;
|
||||
const int32Array = s.int32Array;
|
||||
const uint32Array = s.uint32Array;
|
||||
const float32Array = s.float32Array;
|
||||
const float64Array = s.float64Array;
|
||||
const bigInt64Array = s.bigInt64Array;
|
||||
const bigUint64Array = s.bigUint64Array;
|
||||
```
|
||||
|
||||
Shapeshift includes a handful of validations specific to typed arrays.
|
||||
|
||||
```typescript
|
||||
s.typedArray().lengthLessThan(5); // Length must be less than 5
|
||||
s.typedArray().lengthLessThanOrEqual(5); // Length must be 5 or less
|
||||
s.typedArray().lengthGreaterThan(5); // Length must be more than 5
|
||||
s.typedArray().lengthGreaterThanOrEqual(5); // Length must be 5 or more
|
||||
s.typedArray().lengthEqual(5); // Length must be exactly 5
|
||||
s.typedArray().lengthNotEqual(5); // Length must not be 5
|
||||
s.typedArray().lengthRange(0, 4); // Length L must satisfy 0 <= L < 4
|
||||
s.typedArray().lengthRangeInclusive(0, 4); // Length L must satisfy 0 <= L <= 4
|
||||
s.typedArray().lengthRangeExclusive(0, 4); // Length L must satisfy 0 < L < 4
|
||||
```
|
||||
|
||||
Note that all of these methods have analogous methods for working with the typed array's byte length,
|
||||
`s.typedArray().byteLengthX()` - for instance, `s.typedArray().byteLengthLessThan(5)` is the same as
|
||||
`s.typedArray().lengthLessThan(5)` but for the array's byte length.
|
||||
|
||||
---
|
||||
|
||||
### Defining schemas (objects)
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
```typescript
|
||||
// Properties are required by default:
|
||||
const animal = s.object({
|
||||
name: s.string,
|
||||
age: s.number
|
||||
});
|
||||
```
|
||||
|
||||
#### Utility types for TypeScript
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
For object validation Shapeshift exports 2 utility types that can be used to extract interfaces from schemas and define
|
||||
the structure of a schema as an interface beforehand respectively.
|
||||
|
||||
##### Extracting an interface from a schema
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can use the `InferType` type to extract the interface from a schema, for example:
|
||||
|
||||
```typescript
|
||||
import { InferType, s } from '@sapphire/shapeshift';
|
||||
|
||||
const schema = s.object({
|
||||
foo: s.string,
|
||||
bar: s.number,
|
||||
baz: s.boolean,
|
||||
qux: s.bigint,
|
||||
quux: s.date
|
||||
});
|
||||
|
||||
type Inferredtype = InferType<typeof schema>;
|
||||
|
||||
// Expected type:
|
||||
type Inferredtype = {
|
||||
foo: string;
|
||||
bar: number;
|
||||
baz: boolean;
|
||||
qux: bigint;
|
||||
quux: Date;
|
||||
};
|
||||
```
|
||||
|
||||
##### Defining the structure of a schema through an interface
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can use the `SchemaOf` type to define the structure of a schema before defining the actual schema, for example:
|
||||
|
||||
```typescript
|
||||
import { s, SchemaOf } from '@sapphire/shapeshift';
|
||||
|
||||
interface IIngredient {
|
||||
ingredientId: string | undefined;
|
||||
name: string | undefined;
|
||||
}
|
||||
|
||||
interface IInstruction {
|
||||
instructionId: string | undefined;
|
||||
message: string | undefined;
|
||||
}
|
||||
|
||||
interface IRecipe {
|
||||
recipeId: string | undefined;
|
||||
title: string;
|
||||
description: string;
|
||||
instructions: IInstruction[];
|
||||
ingredients: IIngredient[];
|
||||
}
|
||||
|
||||
type InstructionSchemaType = SchemaOf<IInstruction>;
|
||||
// Expected Type: ObjectValidator<IInstruction>
|
||||
|
||||
type IngredientSchemaType = SchemaOf<IIngredient>;
|
||||
// Expected Type: ObjectValidator<IIngredient>
|
||||
|
||||
type RecipeSchemaType = SchemaOf<IRecipe>;
|
||||
// Expected Type: ObjectValidator<IRecipe>
|
||||
|
||||
const instructionSchema: InstructionSchemaType = s.object({
|
||||
instructionId: s.string.optional,
|
||||
message: s.string
|
||||
});
|
||||
|
||||
const ingredientSchema: IngredientSchemaType = s.object({
|
||||
ingredientId: s.string.optional,
|
||||
name: s.string
|
||||
});
|
||||
|
||||
const recipeSchema: RecipeSchemaType = s.object({
|
||||
recipeId: s.string.optional,
|
||||
title: s.string,
|
||||
description: s.string,
|
||||
instructions: s.array(instructionSchema),
|
||||
ingredients: s.array(ingredientSchema)
|
||||
});
|
||||
```
|
||||
|
||||
#### `.extend`:
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can add additional fields using either an object or an ObjectValidator, in this case, you will get a new object
|
||||
validator with the merged properties:
|
||||
|
||||
```typescript
|
||||
const animal = s.object({
|
||||
name: s.string.optional,
|
||||
age: s.number
|
||||
});
|
||||
|
||||
const pet = animal.extend({
|
||||
owner: s.string.nullish
|
||||
});
|
||||
|
||||
const pet = animal.extend(
|
||||
s.object({
|
||||
owner: s.string.nullish
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
> If both schemas share keys, an error will be thrown. Please use `.omit` on the first object if you desire this
|
||||
> behaviour.
|
||||
|
||||
#### `.pick` / `.omit`:
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Inspired by TypeScript's built-in `Pick` and `Omit` utility types, all object schemas have the aforementioned methods
|
||||
that return a modifier version:
|
||||
|
||||
```typescript
|
||||
const pkg = s.object({
|
||||
name: s.string,
|
||||
description: s.string,
|
||||
dependencies: s.string.array
|
||||
});
|
||||
|
||||
const justTheName = pkg.pick(['name']);
|
||||
// s.object({ name: s.string });
|
||||
|
||||
const noDependencies = pkg.omit(['dependencies']);
|
||||
// s.object({ name: s.string, description: s.string });
|
||||
```
|
||||
|
||||
#### `.partial`
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Inspired by TypeScript's built-in `Partial` utility type, all object schemas have the aforementioned method that makes
|
||||
all properties optional:
|
||||
|
||||
```typescript
|
||||
const user = s.object({
|
||||
username: s.string,
|
||||
password: s.string
|
||||
}).partial;
|
||||
```
|
||||
|
||||
Which is the same as doing:
|
||||
|
||||
```typescript
|
||||
const user = s.object({
|
||||
username: s.string.optional,
|
||||
password: s.string.optional
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### `.required`
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Inspired by TypeScript's built-in `Required` utility type, all object schemas have the aforementioned method that makes
|
||||
all properties required:
|
||||
|
||||
```typescript
|
||||
const user = s.object({
|
||||
username: s.string.optional,
|
||||
password: s.string.optional
|
||||
}).required;
|
||||
```
|
||||
|
||||
Which is the same as doing:
|
||||
|
||||
```typescript
|
||||
const user = s.object({
|
||||
username: s.string,
|
||||
password: s.string
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Handling unrecognized keys
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
By default, Shapeshift will not include keys that are not defined by the schema during parsing:
|
||||
|
||||
```typescript
|
||||
const person = s.object({
|
||||
framework: s.string
|
||||
});
|
||||
|
||||
person.parse({
|
||||
framework: 'Sapphire',
|
||||
awesome: true
|
||||
});
|
||||
// => { name: 'Sapphire' }
|
||||
```
|
||||
|
||||
#### `.strict`
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can disallow unknown keys with `.strict`. If the input includes any unknown keys, an error will be thrown.
|
||||
|
||||
```typescript
|
||||
const person = s.object({
|
||||
framework: s.string
|
||||
}).strict;
|
||||
|
||||
person.parse({
|
||||
framework: 'Sapphire',
|
||||
awesome: true
|
||||
});
|
||||
// => throws ValidationError
|
||||
```
|
||||
|
||||
#### `.ignore`
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can use the `.ignore` getter to reset an object schema to the default behaviour (ignoring unrecognized keys).
|
||||
|
||||
#### `.passthrough`
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
You can use the `.passthrough` getter to make the validator add the unrecognized properties the shape does not have,
|
||||
from the input.
|
||||
|
||||
---
|
||||
|
||||
### BaseValidator: methods and properties
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
All validations in Shapeshift contain certain methods.
|
||||
|
||||
- #### `.run(data: unknown): Result<T, Error>`: given a validation, you can call this method to check whether or not the
|
||||
|
||||
input is valid. If it is, a `Result` with `success: true` and a deep-cloned value will be returned with the given
|
||||
constraints and transformations. Otherwise, a `Result` with `success: false` and an error is returned.
|
||||
|
||||
- #### `.parse(data: unknown): T`: given a validations, you can call this method to check whether or not the input is valid.
|
||||
|
||||
If it is, a deep-cloned value will be returned with the given constraints and transformations. Otherwise, an error is
|
||||
thrown.
|
||||
|
||||
- #### `.transform<R>((value: T) => R): NopValidator<R>`: adds a constraint that modifies the input:
|
||||
|
||||
```typescript
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
|
||||
const getLength = s.string.transform((value) => value.length);
|
||||
getLength.parse('Hello There'); // => 11
|
||||
```
|
||||
|
||||
> :warning: `.transform`'s functions **must not throw**. If a validation error is desired to be thrown, `.reshape`
|
||||
> instead.
|
||||
|
||||
- #### `.reshape<R>((value: T) => Result<R, Error> | IConstraint): NopValidator<R>`: adds a constraint able to both validate
|
||||
and modify the input:
|
||||
|
||||
```typescript
|
||||
import { s, Result } from '@sapphire/shapeshift';
|
||||
|
||||
const getLength = s.string.reshape((value) => Result.ok(value.length));
|
||||
getLength.parse('Hello There'); // => 11
|
||||
```
|
||||
|
||||
> :warning: `.reshape`'s functions **must not throw**. If a validation error is desired to be thrown, use
|
||||
> `Result.err(error)` instead.
|
||||
|
||||
- #### `.default(value: T | (() => T))`: transform `undefined` into the given value or the callback's returned value:
|
||||
|
||||
```typescript
|
||||
const name = s.string.default('Sapphire');
|
||||
name.parse('Hello'); // => 'Hello'
|
||||
name.parse(undefined); // => 'Sapphire'
|
||||
```
|
||||
|
||||
```typescript
|
||||
const number = s.number.default(Math.random);
|
||||
number.parse(12); // => 12
|
||||
number.parse(undefined); // => 0.989911985608602
|
||||
number.parse(undefined); // => 0.3224350185068794
|
||||
```
|
||||
|
||||
> :warning: The default values are not validated.
|
||||
|
||||
- #### `.optional`: a convenience method that returns a union of the type with `s.undefined`.
|
||||
|
||||
```typescript
|
||||
s.string.optional; // s.union(s.string, s.undefined)
|
||||
```
|
||||
|
||||
- #### `.nullable`: a convenience method that returns a union of the type with `s.nullable`.
|
||||
|
||||
```typescript
|
||||
s.string.nullable; // s.union(s.string, s.nullable)
|
||||
```
|
||||
|
||||
- #### `.nullish`: a convenience method that returns a union of the type with `s.nullish`.
|
||||
|
||||
```typescript
|
||||
s.string.nullish; // s.union(s.string, s.nullish)
|
||||
```
|
||||
|
||||
- #### `.array`: a convenience method that returns an ArrayValidator with the type.
|
||||
|
||||
```typescript
|
||||
s.string.array; // s.array(s.string)
|
||||
```
|
||||
|
||||
- #### `.or`: a convenience method that returns an UnionValidator with the type. This method is also overridden in
|
||||
UnionValidator to just append one more entry.
|
||||
|
||||
```typescript
|
||||
s.string.or(s.number);
|
||||
// => s.union(s.string, s.number)
|
||||
|
||||
s.object({ name: s.string }).or(s.string, s.number);
|
||||
// => s.union(s.object({ name: s.string }), s.string, s.number)
|
||||
```
|
||||
|
||||
- #### `.when`: Adjust the schema based on a sibling or sinbling children fields.
|
||||
|
||||
For using when you provide an object literal where the key `is` is undefined, a value, or a matcher function; `then`
|
||||
provides the schema when `is` resolves truthy, and `otherwise` provides the schema when `is` resolves falsey.
|
||||
|
||||
##### Available options for providing `is`
|
||||
|
||||
When `is` is not provided (`=== undefined`) it is strictly resolved as `Boolean(value)` wherein `value` is the current
|
||||
value of the referenced sibling. Note that if multiple siblings are referenced then all the values of the array need to
|
||||
resolve truthy for the `is` to resolve truthy.
|
||||
|
||||
When `is` is a primitive literal it is strictly compared (`===`) to the current value.
|
||||
|
||||
If you want to use a different form of equality you can provide a function like: `is: (value) => value === true`.
|
||||
|
||||
##### Resolving of the `key` (first) parameter
|
||||
|
||||
For resolving the `key` parameter to its respective value we use [lodash/get](https://lodash.com/docs#get). This means
|
||||
that every way that Lodash supports resolving a key to its respective value is also supported by Shapeshift. This
|
||||
includes:
|
||||
|
||||
- Simply providing a string or number like `'name'` or `1`.
|
||||
- Providing a string or number with a dot notation like `'name.first'` (representative of a nested object structure of
|
||||
`{ 'name': { 'first': 'Sapphire' } }` => resolves to `Sapphire`).
|
||||
- Providing a string or number with a bracket notation like `'name[0]'` (representative of an array structure of
|
||||
`{ 'name': ['Sapphire', 'Framework'] }` => resolves to `Sapphire`).
|
||||
- Providing a string or number with a dot and bracket notation like `'name[1].first'` (representative of a nested object
|
||||
structure of `{ 'name': [{ 'first': 'Sapphire' }, { 'first': 'Framework' }] }` => resolves to `Framework`).
|
||||
|
||||
##### Examples
|
||||
|
||||
Let's start with a basic example:
|
||||
|
||||
```typescript
|
||||
const whenPredicate = s.object({
|
||||
booleanLike: s.boolean,
|
||||
numberLike: s.number.when('booleanLike', {
|
||||
then: (schema) => schema.greaterThanOrEqual(5),
|
||||
otherwise: (schema) => schema.lessThanOrEqual(5)
|
||||
})
|
||||
});
|
||||
|
||||
whenPredicate.parse({ booleanLike: true, numberLike: 6 });
|
||||
// => { booleanLike: true, numberLike: 6 }
|
||||
|
||||
whenPredicate.parse({ booleanLike: true, numberLike: 4 });
|
||||
// => ExpectedConstraintError('s.number.greaterThanOrEqual', 'Invalid number value', 4, 'expected >= 5')
|
||||
|
||||
whenPredicate.parse({ booleanLike: false, numberLike: 4 });
|
||||
// => { booleanLike: false, numberLike: 4 }
|
||||
```
|
||||
|
||||
The provided key can also be an array of sibling children:
|
||||
|
||||
```typescript
|
||||
const whenPredicate = s.object({
|
||||
booleanLike: s.boolean,
|
||||
stringLike: s.string,
|
||||
numberLike: s.number.when(['booleanLike', 'stringLike'], {
|
||||
is: ([booleanLikeValue, stringLikeValue]) => booleanLikeValue === true && stringLikeValue === 'foobar',
|
||||
then: (schema) => schema.greaterThanOrEqual(5),
|
||||
otherwise: (schema) => schema.lessThanOrEqual(5)
|
||||
})
|
||||
});
|
||||
|
||||
whenPredicate.parse({ booleanLike: true, stringLike: 'foobar', numberLike: 6 });
|
||||
// => { booleanLike: true, numberLike: 6 }
|
||||
|
||||
whenPredicate.parse({ booleanLike: true, stringLike: 'barfoo', numberLike: 4 });
|
||||
// => ExpectedConstraintError('s.number.greaterThanOrEqual', 'Invalid number value', 4, 'expected >= 5')
|
||||
|
||||
whenPredicate.parse({ booleanLike: false, stringLike: 'foobar' numberLike: 4 });
|
||||
// => ExpectedConstraintError('s.number.greaterThanOrEqual', 'Invalid number value', 4, 'expected >= 5')
|
||||
```
|
||||
|
||||
### Enabling and disabling validation
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
At times, you might want to have a consistent code base with validation, but would like to keep validation to the strict
|
||||
necessities instead of the in-depth constraints available in shapeshift. By calling `setGlobalValidationEnabled` you can
|
||||
disable validation at a global level, and by calling `setValidationEnabled` you can disable validation on a
|
||||
per-validator level.
|
||||
|
||||
> When setting the validation enabled status per-validator, you can also set it to `null` to use the global setting.
|
||||
|
||||
```typescript
|
||||
import { setGlobalValidationEnabled } from '@sapphire/shapeshift';
|
||||
|
||||
setGlobalValidationEnabled(false);
|
||||
```
|
||||
|
||||
```typescript
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
|
||||
const predicate = s.string.lengthGreaterThan(5).setValidationEnabled(false);
|
||||
```
|
||||
|
||||
## Buy us some doughnuts
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are
|
||||
amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
||||
|
||||
We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons
|
||||
below to donate through your method of choice.
|
||||
|
||||
| Donate With | Address |
|
||||
| :-------------: | :-------------------------------------------------: |
|
||||
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|
||||
| Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
|
||||
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
|
||||
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
|
||||
|
||||
## Contributors
|
||||
|
||||
[Back to top][toc]
|
||||
|
||||
Please make sure to read the [Contributing Guide][contributing] before making a pull request.
|
||||
|
||||
Thank you to all the people who already contributed to Sapphire!
|
||||
|
||||
<a href="https://github.com/sapphiredev/shapeshift/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=sapphiredev/shapeshift" />
|
||||
</a>
|
||||
|
||||
[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md
|
||||
[`zod`]: https://github.com/colinhacks/zod
|
||||
[documentation]: https://www.sapphirejs.dev/docs/Documentation/api-shapeshift/
|
||||
[toc]: #table-of-contents
|
3013
node_modules/@sapphire/shapeshift/dist/cjs/index.cjs
generated
vendored
Normal file
3013
node_modules/@sapphire/shapeshift/dist/cjs/index.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@sapphire/shapeshift/dist/cjs/index.cjs.map
generated
vendored
Normal file
1
node_modules/@sapphire/shapeshift/dist/cjs/index.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
715
node_modules/@sapphire/shapeshift/dist/cjs/index.d.cts
generated
vendored
Normal file
715
node_modules/@sapphire/shapeshift/dist/cjs/index.d.cts
generated
vendored
Normal file
|
@ -0,0 +1,715 @@
|
|||
import { InspectOptionsStylized } from 'util';
|
||||
|
||||
declare class Result<T, E extends Error = Error> {
|
||||
readonly success: boolean;
|
||||
readonly value?: T;
|
||||
readonly error?: E;
|
||||
private constructor();
|
||||
isOk(): this is {
|
||||
success: true;
|
||||
value: T;
|
||||
};
|
||||
isErr(): this is {
|
||||
success: false;
|
||||
error: E;
|
||||
};
|
||||
unwrap(): T;
|
||||
static ok<T, E extends Error = Error>(value: T): Result<T, E>;
|
||||
static err<T, E extends Error = Error>(error: E): Result<T, E>;
|
||||
}
|
||||
|
||||
type ArrayConstraintName = `s.array(T).${'unique' | `length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`}`;
|
||||
declare function arrayLengthLessThan<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthLessThanOrEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthGreaterThan<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthGreaterThanOrEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthNotEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthRange<T>(start: number, endBefore: number): IConstraint<T[]>;
|
||||
declare function arrayLengthRangeInclusive<T>(start: number, end: number): IConstraint<T[]>;
|
||||
declare function arrayLengthRangeExclusive<T>(startAfter: number, endBefore: number): IConstraint<T[]>;
|
||||
|
||||
type BigIntConstraintName = `s.bigint.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'divisibleBy'}`;
|
||||
declare function bigintLessThan(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintLessThanOrEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintGreaterThan(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintGreaterThanOrEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintNotEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintDivisibleBy(divider: bigint): IConstraint<bigint>;
|
||||
|
||||
type BooleanConstraintName = `s.boolean.${boolean}`;
|
||||
declare const booleanTrue: IConstraint<boolean, true>;
|
||||
declare const booleanFalse: IConstraint<boolean, false>;
|
||||
|
||||
type DateConstraintName = `s.date.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'valid' | 'invalid'}`;
|
||||
declare function dateLessThan(value: Date): IConstraint<Date>;
|
||||
declare function dateLessThanOrEqual(value: Date): IConstraint<Date>;
|
||||
declare function dateGreaterThan(value: Date): IConstraint<Date>;
|
||||
declare function dateGreaterThanOrEqual(value: Date): IConstraint<Date>;
|
||||
declare function dateEqual(value: Date): IConstraint<Date>;
|
||||
declare function dateNotEqual(value: Date): IConstraint<Date>;
|
||||
declare const dateInvalid: IConstraint<Date>;
|
||||
declare const dateValid: IConstraint<Date>;
|
||||
|
||||
type NumberConstraintName = `s.number.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'equal(NaN)' | 'notEqual' | 'notEqual(NaN)' | 'int' | 'safeInt' | 'finite' | 'divisibleBy'}`;
|
||||
declare function numberLessThan(value: number): IConstraint<number>;
|
||||
declare function numberLessThanOrEqual(value: number): IConstraint<number>;
|
||||
declare function numberGreaterThan(value: number): IConstraint<number>;
|
||||
declare function numberGreaterThanOrEqual(value: number): IConstraint<number>;
|
||||
declare function numberEqual(value: number): IConstraint<number>;
|
||||
declare function numberNotEqual(value: number): IConstraint<number>;
|
||||
declare const numberInt: IConstraint<number>;
|
||||
declare const numberSafeInt: IConstraint<number>;
|
||||
declare const numberFinite: IConstraint<number>;
|
||||
declare const numberNaN: IConstraint<number>;
|
||||
declare const numberNotNaN: IConstraint<number>;
|
||||
declare function numberDivisibleBy(divider: number): IConstraint<number>;
|
||||
|
||||
declare const customInspectSymbol: unique symbol;
|
||||
declare const customInspectSymbolStackLess: unique symbol;
|
||||
declare abstract class BaseError extends Error {
|
||||
protected [customInspectSymbol](depth: number, options: InspectOptionsStylized): string;
|
||||
protected abstract [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class CombinedError extends BaseError {
|
||||
readonly errors: readonly BaseError[];
|
||||
constructor(errors: readonly BaseError[]);
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class ValidationError extends BaseError {
|
||||
readonly validator: string;
|
||||
readonly given: unknown;
|
||||
constructor(validator: string, message: string, given: unknown);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
validator: string;
|
||||
given: unknown;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class ExpectedValidationError<T> extends ValidationError {
|
||||
readonly expected: T;
|
||||
constructor(validator: string, message: string, given: unknown, expected: T);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
validator: string;
|
||||
given: unknown;
|
||||
expected: T;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class MissingPropertyError extends BaseError {
|
||||
readonly property: PropertyKey;
|
||||
constructor(property: PropertyKey);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
property: PropertyKey;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class MultiplePossibilitiesConstraintError<T = unknown> extends BaseConstraintError<T> {
|
||||
readonly expected: readonly string[];
|
||||
constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: readonly string[]);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
constraint: ConstraintErrorNames;
|
||||
given: T;
|
||||
expected: readonly string[];
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class UnknownEnumValueError extends BaseError {
|
||||
readonly value: string | number;
|
||||
readonly enumKeys: string[];
|
||||
readonly enumMappings: Map<string | number, string | number>;
|
||||
constructor(value: string | number, keys: string[], enumMappings: Map<string | number, string | number>);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
value: string | number;
|
||||
enumKeys: string[];
|
||||
enumMappings: [string | number, string | number][];
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class UnknownPropertyError extends BaseError {
|
||||
readonly property: PropertyKey;
|
||||
readonly value: unknown;
|
||||
constructor(property: PropertyKey, value: unknown);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
property: PropertyKey;
|
||||
value: unknown;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class BigIntValidator<T extends bigint> extends BaseValidator<T> {
|
||||
lessThan(number: bigint): this;
|
||||
lessThanOrEqual(number: bigint): this;
|
||||
greaterThan(number: bigint): this;
|
||||
greaterThanOrEqual(number: bigint): this;
|
||||
equal<N extends bigint>(number: N): BigIntValidator<N>;
|
||||
notEqual(number: bigint): this;
|
||||
get positive(): this;
|
||||
get negative(): this;
|
||||
divisibleBy(number: bigint): this;
|
||||
get abs(): this;
|
||||
intN(bits: number): this;
|
||||
uintN(bits: number): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class BooleanValidator<T extends boolean = boolean> extends BaseValidator<T> {
|
||||
get true(): BooleanValidator<true>;
|
||||
get false(): BooleanValidator<false>;
|
||||
equal<R extends true | false>(value: R): BooleanValidator<R>;
|
||||
notEqual<R extends true | false>(value: R): BooleanValidator<R>;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class DateValidator extends BaseValidator<Date> {
|
||||
lessThan(date: Date | number | string): this;
|
||||
lessThanOrEqual(date: Date | number | string): this;
|
||||
greaterThan(date: Date | number | string): this;
|
||||
greaterThanOrEqual(date: Date | number | string): this;
|
||||
equal(date: Date | number | string): this;
|
||||
notEqual(date: Date | number | string): this;
|
||||
get valid(): this;
|
||||
get invalid(): this;
|
||||
protected handle(value: unknown): Result<Date, ValidationError>;
|
||||
}
|
||||
|
||||
declare class DefaultValidator<T> extends BaseValidator<T> {
|
||||
private readonly validator;
|
||||
private defaultValue;
|
||||
constructor(validator: BaseValidator<T>, value: T | (() => T), constraints?: readonly IConstraint<T>[]);
|
||||
default(value: Exclude<T, undefined> | (() => Exclude<T, undefined>)): DefaultValidator<Exclude<T, undefined>>;
|
||||
protected handle(value: unknown): Result<T, ValidatorError>;
|
||||
protected clone(): this;
|
||||
}
|
||||
|
||||
declare class InstanceValidator<T> extends BaseValidator<T> {
|
||||
readonly expected: Constructor<T>;
|
||||
constructor(expected: Constructor<T>, constraints?: readonly IConstraint<T>[]);
|
||||
protected handle(value: unknown): Result<T, ExpectedValidationError<Constructor<T>>>;
|
||||
protected clone(): this;
|
||||
}
|
||||
|
||||
declare class LiteralValidator<T> extends BaseValidator<T> {
|
||||
readonly expected: T;
|
||||
constructor(literal: T, constraints?: readonly IConstraint<T>[]);
|
||||
protected handle(value: unknown): Result<T, ExpectedValidationError<T>>;
|
||||
protected clone(): this;
|
||||
}
|
||||
|
||||
declare class CombinedPropertyError extends BaseError {
|
||||
readonly errors: [PropertyKey, BaseError][];
|
||||
constructor(errors: [PropertyKey, BaseError][]);
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
private static formatProperty;
|
||||
}
|
||||
|
||||
declare class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
|
||||
private readonly keyValidator;
|
||||
private readonly valueValidator;
|
||||
constructor(keyValidator: BaseValidator<K>, valueValidator: BaseValidator<V>, constraints?: readonly IConstraint<Map<K, V>>[]);
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<Map<K, V>, ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
declare class NativeEnumValidator<T extends NativeEnumLike> extends BaseValidator<T[keyof T]> {
|
||||
readonly enumShape: T;
|
||||
readonly hasNumericElements: boolean;
|
||||
private readonly enumKeys;
|
||||
private readonly enumMapping;
|
||||
constructor(enumShape: T);
|
||||
protected handle(value: unknown): Result<T[keyof T], ValidationError | UnknownEnumValueError>;
|
||||
protected clone(): this;
|
||||
}
|
||||
interface NativeEnumLike {
|
||||
[key: string]: string | number;
|
||||
[key: number]: string;
|
||||
}
|
||||
|
||||
declare class NeverValidator extends BaseValidator<never> {
|
||||
protected handle(value: unknown): Result<never, ValidationError>;
|
||||
}
|
||||
|
||||
declare class NullishValidator extends BaseValidator<undefined | null> {
|
||||
protected handle(value: unknown): Result<undefined | null, ValidationError>;
|
||||
}
|
||||
|
||||
declare class NumberValidator<T extends number> extends BaseValidator<T> {
|
||||
lessThan(number: number): this;
|
||||
lessThanOrEqual(number: number): this;
|
||||
greaterThan(number: number): this;
|
||||
greaterThanOrEqual(number: number): this;
|
||||
equal<N extends number>(number: N): NumberValidator<N>;
|
||||
notEqual(number: number): this;
|
||||
get int(): this;
|
||||
get safeInt(): this;
|
||||
get finite(): this;
|
||||
get positive(): this;
|
||||
get negative(): this;
|
||||
divisibleBy(divider: number): this;
|
||||
get abs(): this;
|
||||
get sign(): this;
|
||||
get trunc(): this;
|
||||
get floor(): this;
|
||||
get fround(): this;
|
||||
get round(): this;
|
||||
get ceil(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class ObjectValidator<T extends object, I = UndefinedToOptional<T>> extends BaseValidator<I> {
|
||||
readonly shape: MappedObjectValidator<T>;
|
||||
readonly strategy: ObjectValidatorStrategy;
|
||||
private readonly keys;
|
||||
private readonly handleStrategy;
|
||||
private readonly requiredKeys;
|
||||
private readonly possiblyUndefinedKeys;
|
||||
private readonly possiblyUndefinedKeysWithDefaults;
|
||||
constructor(shape: MappedObjectValidator<T>, strategy?: ObjectValidatorStrategy, constraints?: readonly IConstraint<I>[]);
|
||||
get strict(): this;
|
||||
get ignore(): this;
|
||||
get passthrough(): this;
|
||||
get partial(): ObjectValidator<{
|
||||
[Key in keyof I]?: I[Key];
|
||||
}>;
|
||||
get required(): ObjectValidator<{
|
||||
[Key in keyof I]-?: I[Key];
|
||||
}>;
|
||||
extend<ET extends object>(schema: ObjectValidator<ET> | MappedObjectValidator<ET>): ObjectValidator<T & ET>;
|
||||
pick<K extends keyof I>(keys: readonly K[]): ObjectValidator<{
|
||||
[Key in keyof Pick<I, K>]: I[Key];
|
||||
}>;
|
||||
omit<K extends keyof I>(keys: readonly K[]): ObjectValidator<{
|
||||
[Key in keyof Omit<I, K>]: I[Key];
|
||||
}>;
|
||||
protected handle(value: unknown): Result<I, ValidationError | CombinedPropertyError>;
|
||||
protected clone(): this;
|
||||
private handleIgnoreStrategy;
|
||||
private handleStrictStrategy;
|
||||
private handlePassthroughStrategy;
|
||||
}
|
||||
declare enum ObjectValidatorStrategy {
|
||||
Ignore = 0,
|
||||
Strict = 1,
|
||||
Passthrough = 2
|
||||
}
|
||||
|
||||
declare class PassthroughValidator<T extends any | unknown> extends BaseValidator<T> {
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class RecordValidator<T> extends BaseValidator<Record<string, T>> {
|
||||
private readonly validator;
|
||||
constructor(validator: BaseValidator<T>, constraints?: readonly IConstraint<Record<string, T>>[]);
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<Record<string, T>, ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
declare class SetValidator<T> extends BaseValidator<Set<T>> {
|
||||
private readonly validator;
|
||||
constructor(validator: BaseValidator<T>, constraints?: readonly IConstraint<Set<T>>[]);
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<Set<T>, ValidationError | CombinedError>;
|
||||
}
|
||||
|
||||
type StringConstraintName = `s.string.${`length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual'}` | 'regex' | 'url' | 'uuid' | 'email' | `ip${'v4' | 'v6' | ''}` | 'date' | 'phone'}`;
|
||||
type StringProtocol = `${string}:`;
|
||||
type StringDomain = `${string}.${string}`;
|
||||
interface UrlOptions {
|
||||
allowedProtocols?: StringProtocol[];
|
||||
allowedDomains?: StringDomain[];
|
||||
}
|
||||
type UUIDVersion = 1 | 3 | 4 | 5;
|
||||
interface StringUuidOptions {
|
||||
version?: UUIDVersion | `${UUIDVersion}-${UUIDVersion}` | null;
|
||||
nullable?: boolean;
|
||||
}
|
||||
declare function stringLengthLessThan(length: number): IConstraint<string>;
|
||||
declare function stringLengthLessThanOrEqual(length: number): IConstraint<string>;
|
||||
declare function stringLengthGreaterThan(length: number): IConstraint<string>;
|
||||
declare function stringLengthGreaterThanOrEqual(length: number): IConstraint<string>;
|
||||
declare function stringLengthEqual(length: number): IConstraint<string>;
|
||||
declare function stringLengthNotEqual(length: number): IConstraint<string>;
|
||||
declare function stringEmail(): IConstraint<string>;
|
||||
declare function stringUrl(options?: UrlOptions): IConstraint<string>;
|
||||
declare function stringIp(version?: 4 | 6): IConstraint<string>;
|
||||
declare function stringRegex(regex: RegExp): IConstraint<string, string>;
|
||||
declare function stringUuid({ version, nullable }?: StringUuidOptions): IConstraint<string, string>;
|
||||
|
||||
declare class StringValidator<T extends string> extends BaseValidator<T> {
|
||||
lengthLessThan(length: number): this;
|
||||
lengthLessThanOrEqual(length: number): this;
|
||||
lengthGreaterThan(length: number): this;
|
||||
lengthGreaterThanOrEqual(length: number): this;
|
||||
lengthEqual(length: number): this;
|
||||
lengthNotEqual(length: number): this;
|
||||
get email(): this;
|
||||
url(options?: UrlOptions): this;
|
||||
uuid(options?: StringUuidOptions): this;
|
||||
regex(regex: RegExp): this;
|
||||
get date(): this;
|
||||
get ipv4(): this;
|
||||
get ipv6(): this;
|
||||
ip(version?: 4 | 6): this;
|
||||
phone(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class TupleValidator<T extends any[]> extends BaseValidator<[...T]> {
|
||||
private readonly validators;
|
||||
constructor(validators: BaseValidator<[...T]>[], constraints?: readonly IConstraint<[...T]>[]);
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<[...T], ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
||||
declare const TypedArrays: {
|
||||
readonly Int8Array: (x: unknown) => x is Int8Array;
|
||||
readonly Uint8Array: (x: unknown) => x is Uint8Array;
|
||||
readonly Uint8ClampedArray: (x: unknown) => x is Uint8ClampedArray;
|
||||
readonly Int16Array: (x: unknown) => x is Int16Array;
|
||||
readonly Uint16Array: (x: unknown) => x is Uint16Array;
|
||||
readonly Int32Array: (x: unknown) => x is Int32Array;
|
||||
readonly Uint32Array: (x: unknown) => x is Uint32Array;
|
||||
readonly Float32Array: (x: unknown) => x is Float32Array;
|
||||
readonly Float64Array: (x: unknown) => x is Float64Array;
|
||||
readonly BigInt64Array: (x: unknown) => x is BigInt64Array;
|
||||
readonly BigUint64Array: (x: unknown) => x is BigUint64Array;
|
||||
readonly TypedArray: (x: unknown) => x is TypedArray;
|
||||
};
|
||||
type TypedArrayName = keyof typeof TypedArrays;
|
||||
|
||||
declare class TypedArrayValidator<T extends TypedArray> extends BaseValidator<T> {
|
||||
private readonly type;
|
||||
constructor(type: TypedArrayName, constraints?: readonly IConstraint<T>[]);
|
||||
byteLengthLessThan(length: number): this;
|
||||
byteLengthLessThanOrEqual(length: number): this;
|
||||
byteLengthGreaterThan(length: number): this;
|
||||
byteLengthGreaterThanOrEqual(length: number): this;
|
||||
byteLengthEqual(length: number): this;
|
||||
byteLengthNotEqual(length: number): this;
|
||||
byteLengthRange(start: number, endBefore: number): this;
|
||||
byteLengthRangeInclusive(startAt: number, endAt: number): this;
|
||||
byteLengthRangeExclusive(startAfter: number, endBefore: number): this;
|
||||
lengthLessThan(length: number): this;
|
||||
lengthLessThanOrEqual(length: number): this;
|
||||
lengthGreaterThan(length: number): this;
|
||||
lengthGreaterThanOrEqual(length: number): this;
|
||||
lengthEqual(length: number): this;
|
||||
lengthNotEqual(length: number): this;
|
||||
lengthRange(start: number, endBefore: number): this;
|
||||
lengthRangeInclusive(startAt: number, endAt: number): this;
|
||||
lengthRangeExclusive(startAfter: number, endBefore: number): this;
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class UnionValidator<T> extends BaseValidator<T> {
|
||||
private validators;
|
||||
constructor(validators: readonly BaseValidator<T>[], constraints?: readonly IConstraint<T>[]);
|
||||
get optional(): UnionValidator<T | undefined>;
|
||||
get required(): UnionValidator<Exclude<T, undefined>>;
|
||||
get nullable(): UnionValidator<T | null>;
|
||||
get nullish(): UnionValidator<T | null | undefined>;
|
||||
or<O>(...predicates: readonly BaseValidator<O>[]): UnionValidator<T | O>;
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError | CombinedError>;
|
||||
}
|
||||
|
||||
type ObjectConstraintName = `s.object(T.when)`;
|
||||
type WhenKey = PropertyKey | PropertyKey[];
|
||||
interface WhenOptions<T extends BaseValidator<any>, Key extends WhenKey> {
|
||||
is?: boolean | ((value: Key extends Array<any> ? any[] : any) => boolean);
|
||||
then: (predicate: T) => T;
|
||||
otherwise?: (predicate: T) => T;
|
||||
}
|
||||
|
||||
declare class ExpectedConstraintError<T = unknown> extends BaseConstraintError<T> {
|
||||
readonly expected: string;
|
||||
constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: string);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
constraint: ConstraintErrorNames;
|
||||
given: T;
|
||||
expected: string;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
type TypedArrayConstraintName = `s.typedArray(T).${'byteLength' | 'length'}${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`;
|
||||
declare function typedArrayByteLengthLessThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthLessThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthGreaterThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthGreaterThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthNotEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthRangeInclusive<T extends TypedArray>(start: number, end: number): {
|
||||
run(input: T): Result<T, Error> | Result<unknown, ExpectedConstraintError<T>>;
|
||||
};
|
||||
declare function typedArrayByteLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>;
|
||||
declare function typedArrayLengthLessThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthLessThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthGreaterThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthGreaterThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthNotEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>;
|
||||
declare function typedArrayLengthRangeInclusive<T extends TypedArray>(start: number, end: number): IConstraint<T>;
|
||||
declare function typedArrayLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>;
|
||||
|
||||
type ConstraintErrorNames = TypedArrayConstraintName | ArrayConstraintName | BigIntConstraintName | BooleanConstraintName | DateConstraintName | NumberConstraintName | ObjectConstraintName | StringConstraintName;
|
||||
declare abstract class BaseConstraintError<T = unknown> extends BaseError {
|
||||
readonly constraint: ConstraintErrorNames;
|
||||
readonly given: T;
|
||||
constructor(constraint: ConstraintErrorNames, message: string, given: T);
|
||||
}
|
||||
|
||||
interface IConstraint<Input, Return extends Input = Input> {
|
||||
run(input: Input, parent?: any): Result<Return, BaseConstraintError<Input>>;
|
||||
}
|
||||
|
||||
declare class ArrayValidator<T extends unknown[], I = T[number]> extends BaseValidator<T> {
|
||||
private readonly validator;
|
||||
constructor(validator: BaseValidator<I>, constraints?: readonly IConstraint<T>[]);
|
||||
lengthLessThan<N extends number>(length: N): ArrayValidator<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, N>]>>>;
|
||||
lengthLessThanOrEqual<N extends number>(length: N): ArrayValidator<ExpandSmallerTuples<[...Tuple<I, N>]>>;
|
||||
lengthGreaterThan<N extends number>(length: N): ArrayValidator<[...Tuple<I, N>, I, ...T]>;
|
||||
lengthGreaterThanOrEqual<N extends number>(length: N): ArrayValidator<[...Tuple<I, N>, ...T]>;
|
||||
lengthEqual<N extends number>(length: N): ArrayValidator<[...Tuple<I, N>]>;
|
||||
lengthNotEqual(length: number): ArrayValidator<[...T]>;
|
||||
lengthRange<S extends number, E extends number>(start: S, endBefore: E): ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>>;
|
||||
lengthRangeInclusive<S extends number, E extends number>(startAt: S, endAt: E): ArrayValidator<Exclude<ExpandSmallerTuples<[...Tuple<I, E>]>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>>;
|
||||
lengthRangeExclusive<S extends number, E extends number>(startAfter: S, endBefore: E): ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<[...Tuple<T, S>]>>>;
|
||||
get unique(): this;
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<T, ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
declare abstract class BaseValidator<T> {
|
||||
description?: string;
|
||||
protected parent?: object;
|
||||
protected constraints: readonly IConstraint<T>[];
|
||||
protected isValidationEnabled: boolean | (() => boolean) | null;
|
||||
constructor(constraints?: readonly IConstraint<T>[]);
|
||||
setParent(parent: object): this;
|
||||
get optional(): UnionValidator<T | undefined>;
|
||||
get nullable(): UnionValidator<T | null>;
|
||||
get nullish(): UnionValidator<T | null | undefined>;
|
||||
get array(): ArrayValidator<T[]>;
|
||||
get set(): SetValidator<T>;
|
||||
or<O>(...predicates: readonly BaseValidator<O>[]): UnionValidator<T | O>;
|
||||
transform(cb: (value: T) => T): this;
|
||||
transform<O>(cb: (value: T) => O): BaseValidator<O>;
|
||||
reshape(cb: (input: T) => Result<T>): this;
|
||||
reshape<R extends Result<unknown>, O = InferResultType<R>>(cb: (input: T) => R): BaseValidator<O>;
|
||||
default(value: Exclude<T, undefined> | (() => Exclude<T, undefined>)): DefaultValidator<Exclude<T, undefined>>;
|
||||
when<Key extends WhenKey, This extends BaseValidator<any> = this>(key: Key, options: WhenOptions<This, Key>): this;
|
||||
describe(description: string): this;
|
||||
run(value: unknown): Result<T, BaseError>;
|
||||
parse<R extends T = T>(value: unknown): R;
|
||||
is<R extends T = T>(value: unknown): value is R;
|
||||
/**
|
||||
* Sets if the validator should also run constraints or just do basic checks.
|
||||
* @param isValidationEnabled Whether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing.
|
||||
* Set to `null` to go off of the global configuration.
|
||||
*/
|
||||
setValidationEnabled(isValidationEnabled: boolean | (() => boolean) | null): this;
|
||||
getValidationEnabled(): boolean | null;
|
||||
protected get shouldRunConstraints(): boolean;
|
||||
protected clone(): this;
|
||||
protected abstract handle(value: unknown): Result<T, ValidatorError>;
|
||||
protected addConstraint(constraint: IConstraint<T>): this;
|
||||
}
|
||||
type ValidatorError = ValidationError | CombinedError | CombinedPropertyError | UnknownEnumValueError;
|
||||
|
||||
type Constructor<T> = (new (...args: readonly any[]) => T) | (abstract new (...args: readonly any[]) => T);
|
||||
type Type<V> = V extends BaseValidator<infer T> ? T : never;
|
||||
/**
|
||||
* @deprecated Use `object` instead.
|
||||
*/
|
||||
type NonNullObject = {} & object;
|
||||
/**
|
||||
* @deprecated This type is no longer used and will be removed in the next major version.
|
||||
*/
|
||||
type PickDefined<T> = {
|
||||
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
||||
};
|
||||
/**
|
||||
* @deprecated This type is no longer used and will be removed in the next major version.
|
||||
*/
|
||||
type PickUndefinedMakeOptional<T> = {
|
||||
[K in keyof T as undefined extends T[K] ? K : never]+?: Exclude<T[K], undefined>;
|
||||
};
|
||||
type FilterDefinedKeys<TObj extends object> = Exclude<{
|
||||
[TKey in keyof TObj]: undefined extends TObj[TKey] ? never : TKey;
|
||||
}[keyof TObj], undefined>;
|
||||
type UndefinedToOptional<T extends object> = Pick<T, FilterDefinedKeys<T>> & {
|
||||
[k in keyof Omit<T, FilterDefinedKeys<T>>]?: Exclude<T[k], undefined>;
|
||||
};
|
||||
type MappedObjectValidator<T> = {
|
||||
[key in keyof T]: BaseValidator<T[key]>;
|
||||
};
|
||||
/**
|
||||
* An alias of {@link ObjectValidator} with a name more common among object validation libraries.
|
||||
* This is the type of a schema after using `s.object({ ... })`
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { s, SchemaOf } from '@sapphire/shapeshift';
|
||||
*
|
||||
* interface IIngredient {
|
||||
* ingredientId: string | undefined;
|
||||
* name: string | undefined;
|
||||
* }
|
||||
*
|
||||
* interface IInstruction {
|
||||
* instructionId: string | undefined;
|
||||
* message: string | undefined;
|
||||
* }
|
||||
*
|
||||
* interface IRecipe {
|
||||
* recipeId: string | undefined;
|
||||
* title: string;
|
||||
* description: string;
|
||||
* instructions: IInstruction[];
|
||||
* ingredients: IIngredient[];
|
||||
* }
|
||||
*
|
||||
* type InstructionSchemaType = SchemaOf<IInstruction>;
|
||||
* // Expected Type: ObjectValidator<IInstruction>
|
||||
*
|
||||
* type IngredientSchemaType = SchemaOf<IIngredient>;
|
||||
* // Expected Type: ObjectValidator<IIngredient>
|
||||
*
|
||||
* type RecipeSchemaType = SchemaOf<IRecipe>;
|
||||
* // Expected Type: ObjectValidator<IRecipe>
|
||||
*
|
||||
* const instructionSchema: InstructionSchemaType = s.object({
|
||||
* instructionId: s.string.optional,
|
||||
* message: s.string
|
||||
* });
|
||||
*
|
||||
* const ingredientSchema: IngredientSchemaType = s.object({
|
||||
* ingredientId: s.string.optional,
|
||||
* name: s.string
|
||||
* });
|
||||
*
|
||||
* const recipeSchema: RecipeSchemaType = s.object({
|
||||
* recipeId: s.string.optional,
|
||||
* title: s.string,
|
||||
* description: s.string,
|
||||
* instructions: s.array(instructionSchema),
|
||||
* ingredients: s.array(ingredientSchema)
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
type SchemaOf<T extends object> = ObjectValidator<T>;
|
||||
/**
|
||||
* Infers the type of a schema object given `typeof schema`.
|
||||
* The schema has to extend {@link ObjectValidator}.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { InferType, s } from '@sapphire/shapeshift';
|
||||
*
|
||||
* const schema = s.object({
|
||||
* foo: s.string,
|
||||
* bar: s.number,
|
||||
* baz: s.boolean,
|
||||
* qux: s.bigint,
|
||||
* quux: s.date
|
||||
* });
|
||||
*
|
||||
* type Inferredtype = InferType<typeof schema>;
|
||||
* // Expected type:
|
||||
* // type Inferredtype = {
|
||||
* // foo: string;
|
||||
* // bar: number;
|
||||
* // baz: boolean;
|
||||
* // qux: bigint;
|
||||
* // quux: Date;
|
||||
* // };
|
||||
* ```
|
||||
*/
|
||||
type InferType<T extends ObjectValidator<any>> = T extends ObjectValidator<any, infer U> ? U : never;
|
||||
type InferResultType<T extends Result<any>> = T extends Result<infer U> ? U : never;
|
||||
type UnwrapTuple<T extends [...any[]]> = T extends [infer Head, ...infer Tail] ? [Unwrap<Head>, ...UnwrapTuple<Tail>] : [];
|
||||
type Unwrap<T> = T extends BaseValidator<infer V> ? V : never;
|
||||
type UnshiftTuple<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? Tail : never;
|
||||
type ExpandSmallerTuples<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? T | ExpandSmallerTuples<Tail> : [];
|
||||
type Shift<A extends Array<any>> = ((...args: A) => void) extends (...args: [A[0], ...infer R]) => void ? R : never;
|
||||
type GrowExpRev<A extends Array<any>, N extends number, P extends Array<Array<any>>> = A['length'] extends N ? A : GrowExpRev<[...A, ...P[0]][N] extends undefined ? [...A, ...P[0]] : A, N, Shift<P>>;
|
||||
type GrowExp<A extends Array<any>, N extends number, P extends Array<Array<any>>> = [...A, ...A][N] extends undefined ? GrowExp<[...A, ...A], N, [A, ...P]> : GrowExpRev<A, N, P>;
|
||||
type Tuple<T, N extends number> = N extends number ? number extends N ? Array<T> : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]> : never;
|
||||
|
||||
declare class LazyValidator<T extends BaseValidator<unknown>, R = Unwrap<T>> extends BaseValidator<R> {
|
||||
private readonly validator;
|
||||
constructor(validator: (value: unknown) => T, constraints?: readonly IConstraint<R>[]);
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<R, ValidatorError>;
|
||||
}
|
||||
|
||||
declare class Shapes {
|
||||
get string(): StringValidator<string>;
|
||||
get number(): NumberValidator<number>;
|
||||
get bigint(): BigIntValidator<bigint>;
|
||||
get boolean(): BooleanValidator<boolean>;
|
||||
get date(): DateValidator;
|
||||
object<T extends object>(shape: MappedObjectValidator<T>): ObjectValidator<T, UndefinedToOptional<T>>;
|
||||
get undefined(): BaseValidator<undefined>;
|
||||
get null(): BaseValidator<null>;
|
||||
get nullish(): NullishValidator;
|
||||
get any(): PassthroughValidator<any>;
|
||||
get unknown(): PassthroughValidator<unknown>;
|
||||
get never(): NeverValidator;
|
||||
enum<T>(...values: readonly T[]): UnionValidator<T>;
|
||||
nativeEnum<T extends NativeEnumLike>(enumShape: T): NativeEnumValidator<T>;
|
||||
literal<T>(value: T): BaseValidator<T>;
|
||||
instance<T>(expected: Constructor<T>): InstanceValidator<T>;
|
||||
union<T extends [...BaseValidator<any>[]]>(...validators: [...T]): UnionValidator<Unwrap<T[number]>>;
|
||||
array<T>(validator: BaseValidator<T[][number]>): ArrayValidator<T[], T[][number]>;
|
||||
array<T extends unknown[]>(validator: BaseValidator<T[number]>): ArrayValidator<T, T[number]>;
|
||||
typedArray<T extends TypedArray>(type?: TypedArrayName): TypedArrayValidator<T>;
|
||||
get int8Array(): TypedArrayValidator<Int8Array>;
|
||||
get uint8Array(): TypedArrayValidator<Uint8Array>;
|
||||
get uint8ClampedArray(): TypedArrayValidator<Uint8ClampedArray>;
|
||||
get int16Array(): TypedArrayValidator<Int16Array>;
|
||||
get uint16Array(): TypedArrayValidator<Uint16Array>;
|
||||
get int32Array(): TypedArrayValidator<Int32Array>;
|
||||
get uint32Array(): TypedArrayValidator<Uint32Array>;
|
||||
get float32Array(): TypedArrayValidator<Float32Array>;
|
||||
get float64Array(): TypedArrayValidator<Float64Array>;
|
||||
get bigInt64Array(): TypedArrayValidator<BigInt64Array>;
|
||||
get bigUint64Array(): TypedArrayValidator<BigUint64Array>;
|
||||
tuple<T extends [...BaseValidator<any>[]]>(validators: [...T]): TupleValidator<UnwrapTuple<T>>;
|
||||
set<T>(validator: BaseValidator<T>): SetValidator<T>;
|
||||
record<T>(validator: BaseValidator<T>): RecordValidator<T>;
|
||||
map<T, U>(keyValidator: BaseValidator<T>, valueValidator: BaseValidator<U>): MapValidator<T, U>;
|
||||
lazy<T extends BaseValidator<unknown>>(validator: (value: unknown) => T): LazyValidator<T, Unwrap<T>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether validators should run on the input, or if the input should be passed through.
|
||||
* @param enabled Whether validation should be done on inputs
|
||||
*/
|
||||
declare function setGlobalValidationEnabled(enabled: boolean): void;
|
||||
/**
|
||||
* @returns Whether validation is enabled
|
||||
*/
|
||||
declare function getGlobalValidationEnabled(): boolean;
|
||||
|
||||
declare const s: Shapes;
|
||||
|
||||
export { type ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, type BigIntConstraintName, BigIntValidator, type BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, type ConstraintErrorNames, type Constructor, type DateConstraintName, DateValidator, DefaultValidator, type ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, type GrowExp, type GrowExpRev, type IConstraint, type InferResultType, type InferType, InstanceValidator, LiteralValidator, MapValidator, type MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, type NativeEnumLike, NativeEnumValidator, NeverValidator, type NonNullObject, NullishValidator, type NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, type PickDefined, type PickUndefinedMakeOptional, RecordValidator, Result, type SchemaOf, SetValidator, Shapes, type Shift, type StringConstraintName, type StringDomain, type StringProtocol, type StringUuidOptions, StringValidator, type Tuple, TupleValidator, type Type, type TypedArrayConstraintName, TypedArrayValidator, type UUIDVersion, type UndefinedToOptional, UnionValidator, UnknownEnumValueError, UnknownPropertyError, type UnshiftTuple, type Unwrap, type UnwrapTuple, type UrlOptions, ValidationError, type ValidatorError, arrayLengthEqual, arrayLengthGreaterThan, arrayLengthGreaterThanOrEqual, arrayLengthLessThan, arrayLengthLessThanOrEqual, arrayLengthNotEqual, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEqual, bigintGreaterThan, bigintGreaterThanOrEqual, bigintLessThan, bigintLessThanOrEqual, bigintNotEqual, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEqual, dateGreaterThan, dateGreaterThanOrEqual, dateInvalid, dateLessThan, dateLessThanOrEqual, dateNotEqual, dateValid, getGlobalValidationEnabled, numberDivisibleBy, numberEqual, numberFinite, numberGreaterThan, numberGreaterThanOrEqual, numberInt, numberLessThan, numberLessThanOrEqual, numberNaN, numberNotEqual, numberNotNaN, numberSafeInt, s, setGlobalValidationEnabled, stringEmail, stringIp, stringLengthEqual, stringLengthGreaterThan, stringLengthGreaterThanOrEqual, stringLengthLessThan, stringLengthLessThanOrEqual, stringLengthNotEqual, stringRegex, stringUrl, stringUuid, typedArrayByteLengthEqual, typedArrayByteLengthGreaterThan, typedArrayByteLengthGreaterThanOrEqual, typedArrayByteLengthLessThan, typedArrayByteLengthLessThanOrEqual, typedArrayByteLengthNotEqual, typedArrayByteLengthRange, typedArrayByteLengthRangeExclusive, typedArrayByteLengthRangeInclusive, typedArrayLengthEqual, typedArrayLengthGreaterThan, typedArrayLengthGreaterThanOrEqual, typedArrayLengthLessThan, typedArrayLengthLessThanOrEqual, typedArrayLengthNotEqual, typedArrayLengthRange, typedArrayLengthRangeExclusive, typedArrayLengthRangeInclusive };
|
715
node_modules/@sapphire/shapeshift/dist/esm/index.d.mts
generated
vendored
Normal file
715
node_modules/@sapphire/shapeshift/dist/esm/index.d.mts
generated
vendored
Normal file
|
@ -0,0 +1,715 @@
|
|||
import { InspectOptionsStylized } from 'util';
|
||||
|
||||
declare class Result<T, E extends Error = Error> {
|
||||
readonly success: boolean;
|
||||
readonly value?: T;
|
||||
readonly error?: E;
|
||||
private constructor();
|
||||
isOk(): this is {
|
||||
success: true;
|
||||
value: T;
|
||||
};
|
||||
isErr(): this is {
|
||||
success: false;
|
||||
error: E;
|
||||
};
|
||||
unwrap(): T;
|
||||
static ok<T, E extends Error = Error>(value: T): Result<T, E>;
|
||||
static err<T, E extends Error = Error>(error: E): Result<T, E>;
|
||||
}
|
||||
|
||||
type ArrayConstraintName = `s.array(T).${'unique' | `length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`}`;
|
||||
declare function arrayLengthLessThan<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthLessThanOrEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthGreaterThan<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthGreaterThanOrEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthNotEqual<T>(value: number): IConstraint<T[]>;
|
||||
declare function arrayLengthRange<T>(start: number, endBefore: number): IConstraint<T[]>;
|
||||
declare function arrayLengthRangeInclusive<T>(start: number, end: number): IConstraint<T[]>;
|
||||
declare function arrayLengthRangeExclusive<T>(startAfter: number, endBefore: number): IConstraint<T[]>;
|
||||
|
||||
type BigIntConstraintName = `s.bigint.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'divisibleBy'}`;
|
||||
declare function bigintLessThan(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintLessThanOrEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintGreaterThan(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintGreaterThanOrEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintNotEqual(value: bigint): IConstraint<bigint>;
|
||||
declare function bigintDivisibleBy(divider: bigint): IConstraint<bigint>;
|
||||
|
||||
type BooleanConstraintName = `s.boolean.${boolean}`;
|
||||
declare const booleanTrue: IConstraint<boolean, true>;
|
||||
declare const booleanFalse: IConstraint<boolean, false>;
|
||||
|
||||
type DateConstraintName = `s.date.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'valid' | 'invalid'}`;
|
||||
declare function dateLessThan(value: Date): IConstraint<Date>;
|
||||
declare function dateLessThanOrEqual(value: Date): IConstraint<Date>;
|
||||
declare function dateGreaterThan(value: Date): IConstraint<Date>;
|
||||
declare function dateGreaterThanOrEqual(value: Date): IConstraint<Date>;
|
||||
declare function dateEqual(value: Date): IConstraint<Date>;
|
||||
declare function dateNotEqual(value: Date): IConstraint<Date>;
|
||||
declare const dateInvalid: IConstraint<Date>;
|
||||
declare const dateValid: IConstraint<Date>;
|
||||
|
||||
type NumberConstraintName = `s.number.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'equal(NaN)' | 'notEqual' | 'notEqual(NaN)' | 'int' | 'safeInt' | 'finite' | 'divisibleBy'}`;
|
||||
declare function numberLessThan(value: number): IConstraint<number>;
|
||||
declare function numberLessThanOrEqual(value: number): IConstraint<number>;
|
||||
declare function numberGreaterThan(value: number): IConstraint<number>;
|
||||
declare function numberGreaterThanOrEqual(value: number): IConstraint<number>;
|
||||
declare function numberEqual(value: number): IConstraint<number>;
|
||||
declare function numberNotEqual(value: number): IConstraint<number>;
|
||||
declare const numberInt: IConstraint<number>;
|
||||
declare const numberSafeInt: IConstraint<number>;
|
||||
declare const numberFinite: IConstraint<number>;
|
||||
declare const numberNaN: IConstraint<number>;
|
||||
declare const numberNotNaN: IConstraint<number>;
|
||||
declare function numberDivisibleBy(divider: number): IConstraint<number>;
|
||||
|
||||
declare const customInspectSymbol: unique symbol;
|
||||
declare const customInspectSymbolStackLess: unique symbol;
|
||||
declare abstract class BaseError extends Error {
|
||||
protected [customInspectSymbol](depth: number, options: InspectOptionsStylized): string;
|
||||
protected abstract [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class CombinedError extends BaseError {
|
||||
readonly errors: readonly BaseError[];
|
||||
constructor(errors: readonly BaseError[]);
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class ValidationError extends BaseError {
|
||||
readonly validator: string;
|
||||
readonly given: unknown;
|
||||
constructor(validator: string, message: string, given: unknown);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
validator: string;
|
||||
given: unknown;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class ExpectedValidationError<T> extends ValidationError {
|
||||
readonly expected: T;
|
||||
constructor(validator: string, message: string, given: unknown, expected: T);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
validator: string;
|
||||
given: unknown;
|
||||
expected: T;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class MissingPropertyError extends BaseError {
|
||||
readonly property: PropertyKey;
|
||||
constructor(property: PropertyKey);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
property: PropertyKey;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class MultiplePossibilitiesConstraintError<T = unknown> extends BaseConstraintError<T> {
|
||||
readonly expected: readonly string[];
|
||||
constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: readonly string[]);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
constraint: ConstraintErrorNames;
|
||||
given: T;
|
||||
expected: readonly string[];
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class UnknownEnumValueError extends BaseError {
|
||||
readonly value: string | number;
|
||||
readonly enumKeys: string[];
|
||||
readonly enumMappings: Map<string | number, string | number>;
|
||||
constructor(value: string | number, keys: string[], enumMappings: Map<string | number, string | number>);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
value: string | number;
|
||||
enumKeys: string[];
|
||||
enumMappings: [string | number, string | number][];
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class UnknownPropertyError extends BaseError {
|
||||
readonly property: PropertyKey;
|
||||
readonly value: unknown;
|
||||
constructor(property: PropertyKey, value: unknown);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
property: PropertyKey;
|
||||
value: unknown;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
declare class BigIntValidator<T extends bigint> extends BaseValidator<T> {
|
||||
lessThan(number: bigint): this;
|
||||
lessThanOrEqual(number: bigint): this;
|
||||
greaterThan(number: bigint): this;
|
||||
greaterThanOrEqual(number: bigint): this;
|
||||
equal<N extends bigint>(number: N): BigIntValidator<N>;
|
||||
notEqual(number: bigint): this;
|
||||
get positive(): this;
|
||||
get negative(): this;
|
||||
divisibleBy(number: bigint): this;
|
||||
get abs(): this;
|
||||
intN(bits: number): this;
|
||||
uintN(bits: number): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class BooleanValidator<T extends boolean = boolean> extends BaseValidator<T> {
|
||||
get true(): BooleanValidator<true>;
|
||||
get false(): BooleanValidator<false>;
|
||||
equal<R extends true | false>(value: R): BooleanValidator<R>;
|
||||
notEqual<R extends true | false>(value: R): BooleanValidator<R>;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class DateValidator extends BaseValidator<Date> {
|
||||
lessThan(date: Date | number | string): this;
|
||||
lessThanOrEqual(date: Date | number | string): this;
|
||||
greaterThan(date: Date | number | string): this;
|
||||
greaterThanOrEqual(date: Date | number | string): this;
|
||||
equal(date: Date | number | string): this;
|
||||
notEqual(date: Date | number | string): this;
|
||||
get valid(): this;
|
||||
get invalid(): this;
|
||||
protected handle(value: unknown): Result<Date, ValidationError>;
|
||||
}
|
||||
|
||||
declare class DefaultValidator<T> extends BaseValidator<T> {
|
||||
private readonly validator;
|
||||
private defaultValue;
|
||||
constructor(validator: BaseValidator<T>, value: T | (() => T), constraints?: readonly IConstraint<T>[]);
|
||||
default(value: Exclude<T, undefined> | (() => Exclude<T, undefined>)): DefaultValidator<Exclude<T, undefined>>;
|
||||
protected handle(value: unknown): Result<T, ValidatorError>;
|
||||
protected clone(): this;
|
||||
}
|
||||
|
||||
declare class InstanceValidator<T> extends BaseValidator<T> {
|
||||
readonly expected: Constructor<T>;
|
||||
constructor(expected: Constructor<T>, constraints?: readonly IConstraint<T>[]);
|
||||
protected handle(value: unknown): Result<T, ExpectedValidationError<Constructor<T>>>;
|
||||
protected clone(): this;
|
||||
}
|
||||
|
||||
declare class LiteralValidator<T> extends BaseValidator<T> {
|
||||
readonly expected: T;
|
||||
constructor(literal: T, constraints?: readonly IConstraint<T>[]);
|
||||
protected handle(value: unknown): Result<T, ExpectedValidationError<T>>;
|
||||
protected clone(): this;
|
||||
}
|
||||
|
||||
declare class CombinedPropertyError extends BaseError {
|
||||
readonly errors: [PropertyKey, BaseError][];
|
||||
constructor(errors: [PropertyKey, BaseError][]);
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
private static formatProperty;
|
||||
}
|
||||
|
||||
declare class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
|
||||
private readonly keyValidator;
|
||||
private readonly valueValidator;
|
||||
constructor(keyValidator: BaseValidator<K>, valueValidator: BaseValidator<V>, constraints?: readonly IConstraint<Map<K, V>>[]);
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<Map<K, V>, ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
declare class NativeEnumValidator<T extends NativeEnumLike> extends BaseValidator<T[keyof T]> {
|
||||
readonly enumShape: T;
|
||||
readonly hasNumericElements: boolean;
|
||||
private readonly enumKeys;
|
||||
private readonly enumMapping;
|
||||
constructor(enumShape: T);
|
||||
protected handle(value: unknown): Result<T[keyof T], ValidationError | UnknownEnumValueError>;
|
||||
protected clone(): this;
|
||||
}
|
||||
interface NativeEnumLike {
|
||||
[key: string]: string | number;
|
||||
[key: number]: string;
|
||||
}
|
||||
|
||||
declare class NeverValidator extends BaseValidator<never> {
|
||||
protected handle(value: unknown): Result<never, ValidationError>;
|
||||
}
|
||||
|
||||
declare class NullishValidator extends BaseValidator<undefined | null> {
|
||||
protected handle(value: unknown): Result<undefined | null, ValidationError>;
|
||||
}
|
||||
|
||||
declare class NumberValidator<T extends number> extends BaseValidator<T> {
|
||||
lessThan(number: number): this;
|
||||
lessThanOrEqual(number: number): this;
|
||||
greaterThan(number: number): this;
|
||||
greaterThanOrEqual(number: number): this;
|
||||
equal<N extends number>(number: N): NumberValidator<N>;
|
||||
notEqual(number: number): this;
|
||||
get int(): this;
|
||||
get safeInt(): this;
|
||||
get finite(): this;
|
||||
get positive(): this;
|
||||
get negative(): this;
|
||||
divisibleBy(divider: number): this;
|
||||
get abs(): this;
|
||||
get sign(): this;
|
||||
get trunc(): this;
|
||||
get floor(): this;
|
||||
get fround(): this;
|
||||
get round(): this;
|
||||
get ceil(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class ObjectValidator<T extends object, I = UndefinedToOptional<T>> extends BaseValidator<I> {
|
||||
readonly shape: MappedObjectValidator<T>;
|
||||
readonly strategy: ObjectValidatorStrategy;
|
||||
private readonly keys;
|
||||
private readonly handleStrategy;
|
||||
private readonly requiredKeys;
|
||||
private readonly possiblyUndefinedKeys;
|
||||
private readonly possiblyUndefinedKeysWithDefaults;
|
||||
constructor(shape: MappedObjectValidator<T>, strategy?: ObjectValidatorStrategy, constraints?: readonly IConstraint<I>[]);
|
||||
get strict(): this;
|
||||
get ignore(): this;
|
||||
get passthrough(): this;
|
||||
get partial(): ObjectValidator<{
|
||||
[Key in keyof I]?: I[Key];
|
||||
}>;
|
||||
get required(): ObjectValidator<{
|
||||
[Key in keyof I]-?: I[Key];
|
||||
}>;
|
||||
extend<ET extends object>(schema: ObjectValidator<ET> | MappedObjectValidator<ET>): ObjectValidator<T & ET>;
|
||||
pick<K extends keyof I>(keys: readonly K[]): ObjectValidator<{
|
||||
[Key in keyof Pick<I, K>]: I[Key];
|
||||
}>;
|
||||
omit<K extends keyof I>(keys: readonly K[]): ObjectValidator<{
|
||||
[Key in keyof Omit<I, K>]: I[Key];
|
||||
}>;
|
||||
protected handle(value: unknown): Result<I, ValidationError | CombinedPropertyError>;
|
||||
protected clone(): this;
|
||||
private handleIgnoreStrategy;
|
||||
private handleStrictStrategy;
|
||||
private handlePassthroughStrategy;
|
||||
}
|
||||
declare enum ObjectValidatorStrategy {
|
||||
Ignore = 0,
|
||||
Strict = 1,
|
||||
Passthrough = 2
|
||||
}
|
||||
|
||||
declare class PassthroughValidator<T extends any | unknown> extends BaseValidator<T> {
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class RecordValidator<T> extends BaseValidator<Record<string, T>> {
|
||||
private readonly validator;
|
||||
constructor(validator: BaseValidator<T>, constraints?: readonly IConstraint<Record<string, T>>[]);
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<Record<string, T>, ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
declare class SetValidator<T> extends BaseValidator<Set<T>> {
|
||||
private readonly validator;
|
||||
constructor(validator: BaseValidator<T>, constraints?: readonly IConstraint<Set<T>>[]);
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<Set<T>, ValidationError | CombinedError>;
|
||||
}
|
||||
|
||||
type StringConstraintName = `s.string.${`length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual'}` | 'regex' | 'url' | 'uuid' | 'email' | `ip${'v4' | 'v6' | ''}` | 'date' | 'phone'}`;
|
||||
type StringProtocol = `${string}:`;
|
||||
type StringDomain = `${string}.${string}`;
|
||||
interface UrlOptions {
|
||||
allowedProtocols?: StringProtocol[];
|
||||
allowedDomains?: StringDomain[];
|
||||
}
|
||||
type UUIDVersion = 1 | 3 | 4 | 5;
|
||||
interface StringUuidOptions {
|
||||
version?: UUIDVersion | `${UUIDVersion}-${UUIDVersion}` | null;
|
||||
nullable?: boolean;
|
||||
}
|
||||
declare function stringLengthLessThan(length: number): IConstraint<string>;
|
||||
declare function stringLengthLessThanOrEqual(length: number): IConstraint<string>;
|
||||
declare function stringLengthGreaterThan(length: number): IConstraint<string>;
|
||||
declare function stringLengthGreaterThanOrEqual(length: number): IConstraint<string>;
|
||||
declare function stringLengthEqual(length: number): IConstraint<string>;
|
||||
declare function stringLengthNotEqual(length: number): IConstraint<string>;
|
||||
declare function stringEmail(): IConstraint<string>;
|
||||
declare function stringUrl(options?: UrlOptions): IConstraint<string>;
|
||||
declare function stringIp(version?: 4 | 6): IConstraint<string>;
|
||||
declare function stringRegex(regex: RegExp): IConstraint<string, string>;
|
||||
declare function stringUuid({ version, nullable }?: StringUuidOptions): IConstraint<string, string>;
|
||||
|
||||
declare class StringValidator<T extends string> extends BaseValidator<T> {
|
||||
lengthLessThan(length: number): this;
|
||||
lengthLessThanOrEqual(length: number): this;
|
||||
lengthGreaterThan(length: number): this;
|
||||
lengthGreaterThanOrEqual(length: number): this;
|
||||
lengthEqual(length: number): this;
|
||||
lengthNotEqual(length: number): this;
|
||||
get email(): this;
|
||||
url(options?: UrlOptions): this;
|
||||
uuid(options?: StringUuidOptions): this;
|
||||
regex(regex: RegExp): this;
|
||||
get date(): this;
|
||||
get ipv4(): this;
|
||||
get ipv6(): this;
|
||||
ip(version?: 4 | 6): this;
|
||||
phone(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class TupleValidator<T extends any[]> extends BaseValidator<[...T]> {
|
||||
private readonly validators;
|
||||
constructor(validators: BaseValidator<[...T]>[], constraints?: readonly IConstraint<[...T]>[]);
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<[...T], ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
||||
declare const TypedArrays: {
|
||||
readonly Int8Array: (x: unknown) => x is Int8Array;
|
||||
readonly Uint8Array: (x: unknown) => x is Uint8Array;
|
||||
readonly Uint8ClampedArray: (x: unknown) => x is Uint8ClampedArray;
|
||||
readonly Int16Array: (x: unknown) => x is Int16Array;
|
||||
readonly Uint16Array: (x: unknown) => x is Uint16Array;
|
||||
readonly Int32Array: (x: unknown) => x is Int32Array;
|
||||
readonly Uint32Array: (x: unknown) => x is Uint32Array;
|
||||
readonly Float32Array: (x: unknown) => x is Float32Array;
|
||||
readonly Float64Array: (x: unknown) => x is Float64Array;
|
||||
readonly BigInt64Array: (x: unknown) => x is BigInt64Array;
|
||||
readonly BigUint64Array: (x: unknown) => x is BigUint64Array;
|
||||
readonly TypedArray: (x: unknown) => x is TypedArray;
|
||||
};
|
||||
type TypedArrayName = keyof typeof TypedArrays;
|
||||
|
||||
declare class TypedArrayValidator<T extends TypedArray> extends BaseValidator<T> {
|
||||
private readonly type;
|
||||
constructor(type: TypedArrayName, constraints?: readonly IConstraint<T>[]);
|
||||
byteLengthLessThan(length: number): this;
|
||||
byteLengthLessThanOrEqual(length: number): this;
|
||||
byteLengthGreaterThan(length: number): this;
|
||||
byteLengthGreaterThanOrEqual(length: number): this;
|
||||
byteLengthEqual(length: number): this;
|
||||
byteLengthNotEqual(length: number): this;
|
||||
byteLengthRange(start: number, endBefore: number): this;
|
||||
byteLengthRangeInclusive(startAt: number, endAt: number): this;
|
||||
byteLengthRangeExclusive(startAfter: number, endBefore: number): this;
|
||||
lengthLessThan(length: number): this;
|
||||
lengthLessThanOrEqual(length: number): this;
|
||||
lengthGreaterThan(length: number): this;
|
||||
lengthGreaterThanOrEqual(length: number): this;
|
||||
lengthEqual(length: number): this;
|
||||
lengthNotEqual(length: number): this;
|
||||
lengthRange(start: number, endBefore: number): this;
|
||||
lengthRangeInclusive(startAt: number, endAt: number): this;
|
||||
lengthRangeExclusive(startAfter: number, endBefore: number): this;
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError>;
|
||||
}
|
||||
|
||||
declare class UnionValidator<T> extends BaseValidator<T> {
|
||||
private validators;
|
||||
constructor(validators: readonly BaseValidator<T>[], constraints?: readonly IConstraint<T>[]);
|
||||
get optional(): UnionValidator<T | undefined>;
|
||||
get required(): UnionValidator<Exclude<T, undefined>>;
|
||||
get nullable(): UnionValidator<T | null>;
|
||||
get nullish(): UnionValidator<T | null | undefined>;
|
||||
or<O>(...predicates: readonly BaseValidator<O>[]): UnionValidator<T | O>;
|
||||
protected clone(): this;
|
||||
protected handle(value: unknown): Result<T, ValidationError | CombinedError>;
|
||||
}
|
||||
|
||||
type ObjectConstraintName = `s.object(T.when)`;
|
||||
type WhenKey = PropertyKey | PropertyKey[];
|
||||
interface WhenOptions<T extends BaseValidator<any>, Key extends WhenKey> {
|
||||
is?: boolean | ((value: Key extends Array<any> ? any[] : any) => boolean);
|
||||
then: (predicate: T) => T;
|
||||
otherwise?: (predicate: T) => T;
|
||||
}
|
||||
|
||||
declare class ExpectedConstraintError<T = unknown> extends BaseConstraintError<T> {
|
||||
readonly expected: string;
|
||||
constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: string);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
constraint: ConstraintErrorNames;
|
||||
given: T;
|
||||
expected: string;
|
||||
};
|
||||
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
|
||||
}
|
||||
|
||||
type TypedArrayConstraintName = `s.typedArray(T).${'byteLength' | 'length'}${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`;
|
||||
declare function typedArrayByteLengthLessThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthLessThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthGreaterThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthGreaterThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthNotEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>;
|
||||
declare function typedArrayByteLengthRangeInclusive<T extends TypedArray>(start: number, end: number): {
|
||||
run(input: T): Result<T, Error> | Result<unknown, ExpectedConstraintError<T>>;
|
||||
};
|
||||
declare function typedArrayByteLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>;
|
||||
declare function typedArrayLengthLessThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthLessThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthGreaterThan<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthGreaterThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthNotEqual<T extends TypedArray>(value: number): IConstraint<T>;
|
||||
declare function typedArrayLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>;
|
||||
declare function typedArrayLengthRangeInclusive<T extends TypedArray>(start: number, end: number): IConstraint<T>;
|
||||
declare function typedArrayLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>;
|
||||
|
||||
type ConstraintErrorNames = TypedArrayConstraintName | ArrayConstraintName | BigIntConstraintName | BooleanConstraintName | DateConstraintName | NumberConstraintName | ObjectConstraintName | StringConstraintName;
|
||||
declare abstract class BaseConstraintError<T = unknown> extends BaseError {
|
||||
readonly constraint: ConstraintErrorNames;
|
||||
readonly given: T;
|
||||
constructor(constraint: ConstraintErrorNames, message: string, given: T);
|
||||
}
|
||||
|
||||
interface IConstraint<Input, Return extends Input = Input> {
|
||||
run(input: Input, parent?: any): Result<Return, BaseConstraintError<Input>>;
|
||||
}
|
||||
|
||||
declare class ArrayValidator<T extends unknown[], I = T[number]> extends BaseValidator<T> {
|
||||
private readonly validator;
|
||||
constructor(validator: BaseValidator<I>, constraints?: readonly IConstraint<T>[]);
|
||||
lengthLessThan<N extends number>(length: N): ArrayValidator<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, N>]>>>;
|
||||
lengthLessThanOrEqual<N extends number>(length: N): ArrayValidator<ExpandSmallerTuples<[...Tuple<I, N>]>>;
|
||||
lengthGreaterThan<N extends number>(length: N): ArrayValidator<[...Tuple<I, N>, I, ...T]>;
|
||||
lengthGreaterThanOrEqual<N extends number>(length: N): ArrayValidator<[...Tuple<I, N>, ...T]>;
|
||||
lengthEqual<N extends number>(length: N): ArrayValidator<[...Tuple<I, N>]>;
|
||||
lengthNotEqual(length: number): ArrayValidator<[...T]>;
|
||||
lengthRange<S extends number, E extends number>(start: S, endBefore: E): ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>>;
|
||||
lengthRangeInclusive<S extends number, E extends number>(startAt: S, endAt: E): ArrayValidator<Exclude<ExpandSmallerTuples<[...Tuple<I, E>]>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>>;
|
||||
lengthRangeExclusive<S extends number, E extends number>(startAfter: S, endBefore: E): ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<[...Tuple<T, S>]>>>;
|
||||
get unique(): this;
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<T, ValidationError | CombinedPropertyError>;
|
||||
}
|
||||
|
||||
declare abstract class BaseValidator<T> {
|
||||
description?: string;
|
||||
protected parent?: object;
|
||||
protected constraints: readonly IConstraint<T>[];
|
||||
protected isValidationEnabled: boolean | (() => boolean) | null;
|
||||
constructor(constraints?: readonly IConstraint<T>[]);
|
||||
setParent(parent: object): this;
|
||||
get optional(): UnionValidator<T | undefined>;
|
||||
get nullable(): UnionValidator<T | null>;
|
||||
get nullish(): UnionValidator<T | null | undefined>;
|
||||
get array(): ArrayValidator<T[]>;
|
||||
get set(): SetValidator<T>;
|
||||
or<O>(...predicates: readonly BaseValidator<O>[]): UnionValidator<T | O>;
|
||||
transform(cb: (value: T) => T): this;
|
||||
transform<O>(cb: (value: T) => O): BaseValidator<O>;
|
||||
reshape(cb: (input: T) => Result<T>): this;
|
||||
reshape<R extends Result<unknown>, O = InferResultType<R>>(cb: (input: T) => R): BaseValidator<O>;
|
||||
default(value: Exclude<T, undefined> | (() => Exclude<T, undefined>)): DefaultValidator<Exclude<T, undefined>>;
|
||||
when<Key extends WhenKey, This extends BaseValidator<any> = this>(key: Key, options: WhenOptions<This, Key>): this;
|
||||
describe(description: string): this;
|
||||
run(value: unknown): Result<T, BaseError>;
|
||||
parse<R extends T = T>(value: unknown): R;
|
||||
is<R extends T = T>(value: unknown): value is R;
|
||||
/**
|
||||
* Sets if the validator should also run constraints or just do basic checks.
|
||||
* @param isValidationEnabled Whether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing.
|
||||
* Set to `null` to go off of the global configuration.
|
||||
*/
|
||||
setValidationEnabled(isValidationEnabled: boolean | (() => boolean) | null): this;
|
||||
getValidationEnabled(): boolean | null;
|
||||
protected get shouldRunConstraints(): boolean;
|
||||
protected clone(): this;
|
||||
protected abstract handle(value: unknown): Result<T, ValidatorError>;
|
||||
protected addConstraint(constraint: IConstraint<T>): this;
|
||||
}
|
||||
type ValidatorError = ValidationError | CombinedError | CombinedPropertyError | UnknownEnumValueError;
|
||||
|
||||
type Constructor<T> = (new (...args: readonly any[]) => T) | (abstract new (...args: readonly any[]) => T);
|
||||
type Type<V> = V extends BaseValidator<infer T> ? T : never;
|
||||
/**
|
||||
* @deprecated Use `object` instead.
|
||||
*/
|
||||
type NonNullObject = {} & object;
|
||||
/**
|
||||
* @deprecated This type is no longer used and will be removed in the next major version.
|
||||
*/
|
||||
type PickDefined<T> = {
|
||||
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
||||
};
|
||||
/**
|
||||
* @deprecated This type is no longer used and will be removed in the next major version.
|
||||
*/
|
||||
type PickUndefinedMakeOptional<T> = {
|
||||
[K in keyof T as undefined extends T[K] ? K : never]+?: Exclude<T[K], undefined>;
|
||||
};
|
||||
type FilterDefinedKeys<TObj extends object> = Exclude<{
|
||||
[TKey in keyof TObj]: undefined extends TObj[TKey] ? never : TKey;
|
||||
}[keyof TObj], undefined>;
|
||||
type UndefinedToOptional<T extends object> = Pick<T, FilterDefinedKeys<T>> & {
|
||||
[k in keyof Omit<T, FilterDefinedKeys<T>>]?: Exclude<T[k], undefined>;
|
||||
};
|
||||
type MappedObjectValidator<T> = {
|
||||
[key in keyof T]: BaseValidator<T[key]>;
|
||||
};
|
||||
/**
|
||||
* An alias of {@link ObjectValidator} with a name more common among object validation libraries.
|
||||
* This is the type of a schema after using `s.object({ ... })`
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { s, SchemaOf } from '@sapphire/shapeshift';
|
||||
*
|
||||
* interface IIngredient {
|
||||
* ingredientId: string | undefined;
|
||||
* name: string | undefined;
|
||||
* }
|
||||
*
|
||||
* interface IInstruction {
|
||||
* instructionId: string | undefined;
|
||||
* message: string | undefined;
|
||||
* }
|
||||
*
|
||||
* interface IRecipe {
|
||||
* recipeId: string | undefined;
|
||||
* title: string;
|
||||
* description: string;
|
||||
* instructions: IInstruction[];
|
||||
* ingredients: IIngredient[];
|
||||
* }
|
||||
*
|
||||
* type InstructionSchemaType = SchemaOf<IInstruction>;
|
||||
* // Expected Type: ObjectValidator<IInstruction>
|
||||
*
|
||||
* type IngredientSchemaType = SchemaOf<IIngredient>;
|
||||
* // Expected Type: ObjectValidator<IIngredient>
|
||||
*
|
||||
* type RecipeSchemaType = SchemaOf<IRecipe>;
|
||||
* // Expected Type: ObjectValidator<IRecipe>
|
||||
*
|
||||
* const instructionSchema: InstructionSchemaType = s.object({
|
||||
* instructionId: s.string.optional,
|
||||
* message: s.string
|
||||
* });
|
||||
*
|
||||
* const ingredientSchema: IngredientSchemaType = s.object({
|
||||
* ingredientId: s.string.optional,
|
||||
* name: s.string
|
||||
* });
|
||||
*
|
||||
* const recipeSchema: RecipeSchemaType = s.object({
|
||||
* recipeId: s.string.optional,
|
||||
* title: s.string,
|
||||
* description: s.string,
|
||||
* instructions: s.array(instructionSchema),
|
||||
* ingredients: s.array(ingredientSchema)
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
type SchemaOf<T extends object> = ObjectValidator<T>;
|
||||
/**
|
||||
* Infers the type of a schema object given `typeof schema`.
|
||||
* The schema has to extend {@link ObjectValidator}.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { InferType, s } from '@sapphire/shapeshift';
|
||||
*
|
||||
* const schema = s.object({
|
||||
* foo: s.string,
|
||||
* bar: s.number,
|
||||
* baz: s.boolean,
|
||||
* qux: s.bigint,
|
||||
* quux: s.date
|
||||
* });
|
||||
*
|
||||
* type Inferredtype = InferType<typeof schema>;
|
||||
* // Expected type:
|
||||
* // type Inferredtype = {
|
||||
* // foo: string;
|
||||
* // bar: number;
|
||||
* // baz: boolean;
|
||||
* // qux: bigint;
|
||||
* // quux: Date;
|
||||
* // };
|
||||
* ```
|
||||
*/
|
||||
type InferType<T extends ObjectValidator<any>> = T extends ObjectValidator<any, infer U> ? U : never;
|
||||
type InferResultType<T extends Result<any>> = T extends Result<infer U> ? U : never;
|
||||
type UnwrapTuple<T extends [...any[]]> = T extends [infer Head, ...infer Tail] ? [Unwrap<Head>, ...UnwrapTuple<Tail>] : [];
|
||||
type Unwrap<T> = T extends BaseValidator<infer V> ? V : never;
|
||||
type UnshiftTuple<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? Tail : never;
|
||||
type ExpandSmallerTuples<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? T | ExpandSmallerTuples<Tail> : [];
|
||||
type Shift<A extends Array<any>> = ((...args: A) => void) extends (...args: [A[0], ...infer R]) => void ? R : never;
|
||||
type GrowExpRev<A extends Array<any>, N extends number, P extends Array<Array<any>>> = A['length'] extends N ? A : GrowExpRev<[...A, ...P[0]][N] extends undefined ? [...A, ...P[0]] : A, N, Shift<P>>;
|
||||
type GrowExp<A extends Array<any>, N extends number, P extends Array<Array<any>>> = [...A, ...A][N] extends undefined ? GrowExp<[...A, ...A], N, [A, ...P]> : GrowExpRev<A, N, P>;
|
||||
type Tuple<T, N extends number> = N extends number ? number extends N ? Array<T> : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]> : never;
|
||||
|
||||
declare class LazyValidator<T extends BaseValidator<unknown>, R = Unwrap<T>> extends BaseValidator<R> {
|
||||
private readonly validator;
|
||||
constructor(validator: (value: unknown) => T, constraints?: readonly IConstraint<R>[]);
|
||||
protected clone(): this;
|
||||
protected handle(values: unknown): Result<R, ValidatorError>;
|
||||
}
|
||||
|
||||
declare class Shapes {
|
||||
get string(): StringValidator<string>;
|
||||
get number(): NumberValidator<number>;
|
||||
get bigint(): BigIntValidator<bigint>;
|
||||
get boolean(): BooleanValidator<boolean>;
|
||||
get date(): DateValidator;
|
||||
object<T extends object>(shape: MappedObjectValidator<T>): ObjectValidator<T, UndefinedToOptional<T>>;
|
||||
get undefined(): BaseValidator<undefined>;
|
||||
get null(): BaseValidator<null>;
|
||||
get nullish(): NullishValidator;
|
||||
get any(): PassthroughValidator<any>;
|
||||
get unknown(): PassthroughValidator<unknown>;
|
||||
get never(): NeverValidator;
|
||||
enum<T>(...values: readonly T[]): UnionValidator<T>;
|
||||
nativeEnum<T extends NativeEnumLike>(enumShape: T): NativeEnumValidator<T>;
|
||||
literal<T>(value: T): BaseValidator<T>;
|
||||
instance<T>(expected: Constructor<T>): InstanceValidator<T>;
|
||||
union<T extends [...BaseValidator<any>[]]>(...validators: [...T]): UnionValidator<Unwrap<T[number]>>;
|
||||
array<T>(validator: BaseValidator<T[][number]>): ArrayValidator<T[], T[][number]>;
|
||||
array<T extends unknown[]>(validator: BaseValidator<T[number]>): ArrayValidator<T, T[number]>;
|
||||
typedArray<T extends TypedArray>(type?: TypedArrayName): TypedArrayValidator<T>;
|
||||
get int8Array(): TypedArrayValidator<Int8Array>;
|
||||
get uint8Array(): TypedArrayValidator<Uint8Array>;
|
||||
get uint8ClampedArray(): TypedArrayValidator<Uint8ClampedArray>;
|
||||
get int16Array(): TypedArrayValidator<Int16Array>;
|
||||
get uint16Array(): TypedArrayValidator<Uint16Array>;
|
||||
get int32Array(): TypedArrayValidator<Int32Array>;
|
||||
get uint32Array(): TypedArrayValidator<Uint32Array>;
|
||||
get float32Array(): TypedArrayValidator<Float32Array>;
|
||||
get float64Array(): TypedArrayValidator<Float64Array>;
|
||||
get bigInt64Array(): TypedArrayValidator<BigInt64Array>;
|
||||
get bigUint64Array(): TypedArrayValidator<BigUint64Array>;
|
||||
tuple<T extends [...BaseValidator<any>[]]>(validators: [...T]): TupleValidator<UnwrapTuple<T>>;
|
||||
set<T>(validator: BaseValidator<T>): SetValidator<T>;
|
||||
record<T>(validator: BaseValidator<T>): RecordValidator<T>;
|
||||
map<T, U>(keyValidator: BaseValidator<T>, valueValidator: BaseValidator<U>): MapValidator<T, U>;
|
||||
lazy<T extends BaseValidator<unknown>>(validator: (value: unknown) => T): LazyValidator<T, Unwrap<T>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether validators should run on the input, or if the input should be passed through.
|
||||
* @param enabled Whether validation should be done on inputs
|
||||
*/
|
||||
declare function setGlobalValidationEnabled(enabled: boolean): void;
|
||||
/**
|
||||
* @returns Whether validation is enabled
|
||||
*/
|
||||
declare function getGlobalValidationEnabled(): boolean;
|
||||
|
||||
declare const s: Shapes;
|
||||
|
||||
export { type ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, type BigIntConstraintName, BigIntValidator, type BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, type ConstraintErrorNames, type Constructor, type DateConstraintName, DateValidator, DefaultValidator, type ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, type GrowExp, type GrowExpRev, type IConstraint, type InferResultType, type InferType, InstanceValidator, LiteralValidator, MapValidator, type MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, type NativeEnumLike, NativeEnumValidator, NeverValidator, type NonNullObject, NullishValidator, type NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, type PickDefined, type PickUndefinedMakeOptional, RecordValidator, Result, type SchemaOf, SetValidator, Shapes, type Shift, type StringConstraintName, type StringDomain, type StringProtocol, type StringUuidOptions, StringValidator, type Tuple, TupleValidator, type Type, type TypedArrayConstraintName, TypedArrayValidator, type UUIDVersion, type UndefinedToOptional, UnionValidator, UnknownEnumValueError, UnknownPropertyError, type UnshiftTuple, type Unwrap, type UnwrapTuple, type UrlOptions, ValidationError, type ValidatorError, arrayLengthEqual, arrayLengthGreaterThan, arrayLengthGreaterThanOrEqual, arrayLengthLessThan, arrayLengthLessThanOrEqual, arrayLengthNotEqual, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEqual, bigintGreaterThan, bigintGreaterThanOrEqual, bigintLessThan, bigintLessThanOrEqual, bigintNotEqual, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEqual, dateGreaterThan, dateGreaterThanOrEqual, dateInvalid, dateLessThan, dateLessThanOrEqual, dateNotEqual, dateValid, getGlobalValidationEnabled, numberDivisibleBy, numberEqual, numberFinite, numberGreaterThan, numberGreaterThanOrEqual, numberInt, numberLessThan, numberLessThanOrEqual, numberNaN, numberNotEqual, numberNotNaN, numberSafeInt, s, setGlobalValidationEnabled, stringEmail, stringIp, stringLengthEqual, stringLengthGreaterThan, stringLengthGreaterThanOrEqual, stringLengthLessThan, stringLengthLessThanOrEqual, stringLengthNotEqual, stringRegex, stringUrl, stringUuid, typedArrayByteLengthEqual, typedArrayByteLengthGreaterThan, typedArrayByteLengthGreaterThanOrEqual, typedArrayByteLengthLessThan, typedArrayByteLengthLessThanOrEqual, typedArrayByteLengthNotEqual, typedArrayByteLengthRange, typedArrayByteLengthRangeExclusive, typedArrayByteLengthRangeInclusive, typedArrayLengthEqual, typedArrayLengthGreaterThan, typedArrayLengthGreaterThanOrEqual, typedArrayLengthLessThan, typedArrayLengthLessThanOrEqual, typedArrayLengthNotEqual, typedArrayLengthRange, typedArrayLengthRangeExclusive, typedArrayLengthRangeInclusive };
|
2990
node_modules/@sapphire/shapeshift/dist/esm/index.mjs
generated
vendored
Normal file
2990
node_modules/@sapphire/shapeshift/dist/esm/index.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@sapphire/shapeshift/dist/esm/index.mjs.map
generated
vendored
Normal file
1
node_modules/@sapphire/shapeshift/dist/esm/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
4220
node_modules/@sapphire/shapeshift/dist/iife/index.global.js
generated
vendored
Normal file
4220
node_modules/@sapphire/shapeshift/dist/iife/index.global.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/@sapphire/shapeshift/dist/iife/index.global.js.map
generated
vendored
Normal file
1
node_modules/@sapphire/shapeshift/dist/iife/index.global.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
124
node_modules/@sapphire/shapeshift/package.json
generated
vendored
Normal file
124
node_modules/@sapphire/shapeshift/package.json
generated
vendored
Normal file
|
@ -0,0 +1,124 @@
|
|||
{
|
||||
"name": "@sapphire/shapeshift",
|
||||
"version": "3.9.7",
|
||||
"description": "Blazing fast input validation and transformation ⚡",
|
||||
"author": "@sapphire",
|
||||
"license": "MIT",
|
||||
"main": "dist/cjs/index.cjs",
|
||||
"module": "dist/esm/index.mjs",
|
||||
"browser": "dist/iife/index.global.js",
|
||||
"unpkg": "dist/iife/index.global.js",
|
||||
"types": "dist/cjs/index.d.cts",
|
||||
"exports": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.mts",
|
||||
"default": "./dist/esm/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/index.d.cts",
|
||||
"default": "./dist/cjs/index.cjs"
|
||||
},
|
||||
"browser": "./dist/iife/index.global.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"homepage": "https://www.sapphirejs.dev",
|
||||
"scripts": {
|
||||
"lint": "eslint src tests --ext ts --fix",
|
||||
"format": "prettier --write \"{src,tests}/**/*.ts\"",
|
||||
"docs": "typedoc-json-parser",
|
||||
"test": "vitest run",
|
||||
"build": "tsup && yarn build:rename-cjs-index",
|
||||
"build:rename-cjs-index": "node scripts/rename-cjs-index.mjs",
|
||||
"clean": "rimraf dist",
|
||||
"typecheck": "tsc -p tsconfig.eslint.json",
|
||||
"bump": "cliff-jumper",
|
||||
"check-update": "cliff-jumper --dry-run",
|
||||
"prepack": "yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^19.2.1",
|
||||
"@commitlint/config-conventional": "^19.1.0",
|
||||
"@favware/cliff-jumper": "^3.0.1",
|
||||
"@favware/npm-deprecate": "^1.0.7",
|
||||
"@sapphire/eslint-config": "^5.0.4",
|
||||
"@sapphire/prettier-config": "^2.0.0",
|
||||
"@sapphire/ts-config": "^5.0.1",
|
||||
"@types/jsdom": "^21.1.6",
|
||||
"@types/lodash": "^4.17.0",
|
||||
"@types/node": "^20.11.5",
|
||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||
"@typescript-eslint/parser": "^7.4.0",
|
||||
"@vitest/coverage-v8": "^1.4.0",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"esbuild-plugins-node-modules-polyfill": "^1.6.3",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"jsdom": "^24.0.0",
|
||||
"lint-staged": "^15.2.2",
|
||||
"prettier": "^3.2.5",
|
||||
"rimraf": "^5.0.5",
|
||||
"tsup": "^8.0.2",
|
||||
"typedoc": "^0.25.12",
|
||||
"typedoc-json-parser": "^9.0.1",
|
||||
"typescript": "^5.4.3",
|
||||
"vitest": "^1.4.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sapphiredev/shapeshift.git"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=v16"
|
||||
},
|
||||
"keywords": [
|
||||
"@sapphire/shapeshift",
|
||||
"shapeshift",
|
||||
"bot",
|
||||
"typescript",
|
||||
"ts",
|
||||
"yarn",
|
||||
"sapphire",
|
||||
"schema",
|
||||
"validation",
|
||||
"type-checking",
|
||||
"checking",
|
||||
"input-validation",
|
||||
"runtime-validation",
|
||||
"ow",
|
||||
"type-validation",
|
||||
"zod"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/sapphiredev/shapeshift/issues"
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"*": "prettier --ignore-unknown --write",
|
||||
"*.{mjs,js,ts}": "eslint --fix --ext mjs,js,ts"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"resolutions": {
|
||||
"ansi-regex": "^5.0.1",
|
||||
"minimist": "^1.2.8"
|
||||
},
|
||||
"packageManager": "yarn@4.1.1"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue