Преглед изворни кода

Remove Joi and celebrate

GitOrigin-RevId: 12cf2e0266a2e57d674d13a2e6fe8368c980d2a1
Andrew Rumble пре 10 месеци
родитељ
комит
19f1f6f702

+ 0 - 2
package-lock.json

@@ -53178,7 +53178,6 @@
         "bull": "^3.18.0",
         "bunyan": "^1.8.15",
         "cache-flow": "^1.9.0",
-        "celebrate": "^15.0.3",
         "connect-redis": "^6.1.3",
         "content-disposition": "^0.5.0",
         "contentful": "^10.8.5",
@@ -53201,7 +53200,6 @@
         "i18next": "^23.10.0",
         "i18next-fs-backend": "^2.3.1",
         "i18next-http-middleware": "^3.5.0",
-        "joi": "^17.12.0",
         "jose": "^4.3.8",
         "json2csv": "^4.3.3",
         "jsonwebtoken": "^9.0.0",

+ 0 - 34
services/web/app/src/infrastructure/Validation.js

@@ -1,7 +1,5 @@
 // @ts-check
 
-const { Joi: CelebrateJoi, celebrate, errors } = require('celebrate')
-const { ObjectId } = require('mongodb-legacy')
 const { NotFoundError } = require('../Features/Errors/Errors')
 const {
   validateReq,
@@ -15,29 +13,7 @@ const { isZodErrorLike, fromError } = require('zod-validation-error')
  * @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 = [
-  errors(),
   /** @type {ErrorRequestHandler} */
   (err, req, res, next) => {
     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) => {
   try {
     return validateReq(req, schema)
@@ -69,8 +37,6 @@ const validateReqWeb = (req, schema) => {
 }
 
 module.exports = {
-  Joi,
-  validate,
   errorMiddleware,
   validateReq: validateReqWeb,
   z,

+ 0 - 2
services/web/package.json

@@ -116,7 +116,6 @@
     "bull": "^3.18.0",
     "bunyan": "^1.8.15",
     "cache-flow": "^1.9.0",
-    "celebrate": "^15.0.3",
     "connect-redis": "^6.1.3",
     "content-disposition": "^0.5.0",
     "contentful": "^10.8.5",
@@ -139,7 +138,6 @@
     "i18next": "^23.10.0",
     "i18next-fs-backend": "^2.3.1",
     "i18next-http-middleware": "^3.5.0",
-    "joi": "^17.12.0",
     "jose": "^4.3.8",
     "json2csv": "^4.3.3",
     "jsonwebtoken": "^9.0.0",

+ 0 - 47
services/web/test/unit/src/infrastructure/ValidationTests.js

@@ -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)
-  })
-})