mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Remove Joi and celebrate
GitOrigin-RevId: 12cf2e0266a2e57d674d13a2e6fe8368c980d2a1
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -53178,7 +53178,6 @@
|
|||||||
"bull": "^3.18.0",
|
"bull": "^3.18.0",
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
"cache-flow": "^1.9.0",
|
"cache-flow": "^1.9.0",
|
||||||
"celebrate": "^15.0.3",
|
|
||||||
"connect-redis": "^6.1.3",
|
"connect-redis": "^6.1.3",
|
||||||
"content-disposition": "^0.5.0",
|
"content-disposition": "^0.5.0",
|
||||||
"contentful": "^10.8.5",
|
"contentful": "^10.8.5",
|
||||||
@@ -53201,7 +53200,6 @@
|
|||||||
"i18next": "^23.10.0",
|
"i18next": "^23.10.0",
|
||||||
"i18next-fs-backend": "^2.3.1",
|
"i18next-fs-backend": "^2.3.1",
|
||||||
"i18next-http-middleware": "^3.5.0",
|
"i18next-http-middleware": "^3.5.0",
|
||||||
"joi": "^17.12.0",
|
|
||||||
"jose": "^4.3.8",
|
"jose": "^4.3.8",
|
||||||
"json2csv": "^4.3.3",
|
"json2csv": "^4.3.3",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const { Joi: CelebrateJoi, celebrate, errors } = require('celebrate')
|
|
||||||
const { ObjectId } = require('mongodb-legacy')
|
|
||||||
const { NotFoundError } = require('../Features/Errors/Errors')
|
const { NotFoundError } = require('../Features/Errors/Errors')
|
||||||
const {
|
const {
|
||||||
validateReq,
|
validateReq,
|
||||||
@@ -15,29 +13,7 @@ const { isZodErrorLike, fromError } = require('zod-validation-error')
|
|||||||
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
|
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const objectIdValidator = {
|
|
||||||
type: 'objectId',
|
|
||||||
base: CelebrateJoi.any(),
|
|
||||||
messages: {
|
|
||||||
'objectId.invalid': 'needs to be a valid ObjectId',
|
|
||||||
},
|
|
||||||
coerce(value) {
|
|
||||||
return {
|
|
||||||
value: typeof value === typeof ObjectId ? value : new ObjectId(value),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prepare(value, helpers) {
|
|
||||||
if (!ObjectId.isValid(value)) {
|
|
||||||
return {
|
|
||||||
errors: helpers.error('objectId.invalid'),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const Joi = CelebrateJoi.extend(objectIdValidator)
|
|
||||||
const errorMiddleware = [
|
const errorMiddleware = [
|
||||||
errors(),
|
|
||||||
/** @type {ErrorRequestHandler} */
|
/** @type {ErrorRequestHandler} */
|
||||||
(err, req, res, next) => {
|
(err, req, res, next) => {
|
||||||
if (!isZodErrorLike(err)) {
|
if (!isZodErrorLike(err)) {
|
||||||
@@ -48,14 +24,6 @@ const errorMiddleware = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
/**
|
|
||||||
* Validation middleware
|
|
||||||
* @deprecated Please use Zod schemas and `validateReq` instead
|
|
||||||
*/
|
|
||||||
function validate(schema) {
|
|
||||||
return celebrate(schema, { allowUnknown: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
const validateReqWeb = (req, schema) => {
|
const validateReqWeb = (req, schema) => {
|
||||||
try {
|
try {
|
||||||
return validateReq(req, schema)
|
return validateReq(req, schema)
|
||||||
@@ -69,8 +37,6 @@ const validateReqWeb = (req, schema) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Joi,
|
|
||||||
validate,
|
|
||||||
errorMiddleware,
|
errorMiddleware,
|
||||||
validateReq: validateReqWeb,
|
validateReq: validateReqWeb,
|
||||||
z,
|
z,
|
||||||
|
|||||||
@@ -116,7 +116,6 @@
|
|||||||
"bull": "^3.18.0",
|
"bull": "^3.18.0",
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
"cache-flow": "^1.9.0",
|
"cache-flow": "^1.9.0",
|
||||||
"celebrate": "^15.0.3",
|
|
||||||
"connect-redis": "^6.1.3",
|
"connect-redis": "^6.1.3",
|
||||||
"content-disposition": "^0.5.0",
|
"content-disposition": "^0.5.0",
|
||||||
"contentful": "^10.8.5",
|
"contentful": "^10.8.5",
|
||||||
@@ -139,7 +138,6 @@
|
|||||||
"i18next": "^23.10.0",
|
"i18next": "^23.10.0",
|
||||||
"i18next-fs-backend": "^2.3.1",
|
"i18next-fs-backend": "^2.3.1",
|
||||||
"i18next-http-middleware": "^3.5.0",
|
"i18next-http-middleware": "^3.5.0",
|
||||||
"joi": "^17.12.0",
|
|
||||||
"jose": "^4.3.8",
|
"jose": "^4.3.8",
|
||||||
"json2csv": "^4.3.3",
|
"json2csv": "^4.3.3",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
const { Joi } = require('../../../../app/src/infrastructure/Validation')
|
|
||||||
const { ObjectId } = require('mongodb-legacy')
|
|
||||||
const { expect } = require('chai')
|
|
||||||
const { ValidationError } = require('joi')
|
|
||||||
|
|
||||||
describe('Validation', function () {
|
|
||||||
const validObjectId = '123456781234567812345678'
|
|
||||||
const invalidObjectId = '12345678-1234-1234-12345678'
|
|
||||||
|
|
||||||
it('accepts valid ObjectId strings', async function () {
|
|
||||||
const schema = Joi.object({
|
|
||||||
test: Joi.objectId(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const value = await schema.validateAsync({
|
|
||||||
test: validObjectId,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(value.test).to.be.instanceof(ObjectId)
|
|
||||||
expect(value.test.toHexString()).to.equal(validObjectId)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('rejects invalid ObjectId strings', async function () {
|
|
||||||
const schema = Joi.object({
|
|
||||||
test: Joi.objectId(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const promise = schema.validateAsync({
|
|
||||||
test: invalidObjectId,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(promise).to.be.rejectedWith(ValidationError)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('accepts valid ObjectId objects', async function () {
|
|
||||||
const schema = Joi.object({
|
|
||||||
test: Joi.objectId(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const value = await schema.validateAsync({
|
|
||||||
test: new ObjectId(validObjectId),
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(value.test).to.be.instanceof(ObjectId)
|
|
||||||
expect(value.test.toHexString()).to.equal(validObjectId)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user