Skip to content

Commit

Permalink
fix(joi)!: switch from @hapi/joi to joi (#284)
Browse files Browse the repository at this point in the history
the `@hapi/joi` package is deprecated, and no longer receiving updates,
switch to the replacement `joi`

ref:
- https://www.npmjs.com/package/@hapi/joi
- https://www.npmjs.com/package/joi

BREAKING CHANGE: `peerDependency` changed to `joi` for users of
`--schema-builder joi`
  • Loading branch information
mnahkies authored Dec 21, 2024
1 parent 7b34fd4 commit 6693e1d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 74 deletions.
3 changes: 1 addition & 2 deletions integration-tests/typescript-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
"validate": "tsc -p ./tsconfig.json"
},
"dependencies": {
"@hapi/joi": "^17.1.1",
"@koa/router": "^13.1.0",
"@nahkies/typescript-koa-runtime": "*",
"@types/hapi__joi": "^17.1.15",
"joi": "^17.13.3",
"koa": "^2.15.3",
"zod": "^3.23.8"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe.each(testVersions)(
// I think it should be possible move loading of joi into the context, such that
// it gets the contexts global RegExp correctly, but I can't figure it out right now.

{joi: require("@hapi/joi"), RegExp},
{joi: require("joi"), RegExp},
)
}

Expand All @@ -44,7 +44,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_SimpleObject = joi
.object()
Expand Down Expand Up @@ -75,7 +75,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AString = joi.string().required().id("s_AString")
Expand Down Expand Up @@ -124,7 +124,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_OneOf = joi
.alternatives()
Expand Down Expand Up @@ -152,7 +152,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AnyOf = joi
.alternatives()
Expand All @@ -172,7 +172,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_Base = joi
.object()
Expand Down Expand Up @@ -205,7 +205,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_Recursive = joi
.object()
Expand All @@ -226,7 +226,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AOrdering = joi
.object()
Expand Down Expand Up @@ -264,7 +264,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_Enums = joi
.object()
Expand All @@ -291,7 +291,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AdditionalPropertiesBool = joi
.object()
Expand All @@ -313,7 +313,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AdditionalPropertiesUnknownEmptySchema = joi
.object()
Expand All @@ -335,7 +335,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AdditionalPropertiesUnknownEmptyObjectSchema = joi
.object()
Expand All @@ -357,7 +357,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_NamedNullableStringEnum = joi
.string()
Expand Down Expand Up @@ -388,7 +388,7 @@ describe.each(testVersions)(
`)

expect(schemas).toMatchInlineSnapshot(`
"import joi from "@hapi/joi"
"import joi from "joi"
export const s_AdditionalPropertiesMixed = joi
.object()
Expand Down Expand Up @@ -449,7 +449,7 @@ describe.each(testVersions)(
)

await expect(execute(5)).rejects.toThrow(
'"value" must be larger than or equal to 10',
'"value" must be greater than or equal to 10',
)
await expect(execute(20)).resolves.toBe(20)
})
Expand Down Expand Up @@ -482,7 +482,7 @@ describe.each(testVersions)(
)

await expect(execute(5)).rejects.toThrow(
'"value" must be larger than or equal to 10',
'"value" must be greater than or equal to 10',
)
await expect(execute(25)).rejects.toThrow(
'"value" must be less than or equal to 24',
Expand Down Expand Up @@ -552,7 +552,7 @@ describe.each(testVersions)(
'"value" must be a multiple of 4',
)
await expect(execute(8)).rejects.toThrow(
'"value" must be larger than or equal to 10',
'"value" must be greater than or equal to 10',
)
await expect(execute(24)).rejects.toThrow(
'"value" must be less than or equal to 20',
Expand All @@ -571,7 +571,7 @@ describe.each(testVersions)(
)

await expect(execute(-1)).rejects.toThrow(
'"value" must be larger than or equal to 0',
'"value" must be greater than or equal to 0',
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class JoiBuilder extends AbstractSchemaBuilder<
}

protected importHelpers(imports: ImportBuilder) {
imports.addModule(joi, "@hapi/joi")
imports.addModule(joi, "joi")
}

public parse(schema: string, value: string): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-fetch-runtime/src/joi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Schema as JoiSchema} from "@hapi/joi"
import type {Schema as JoiSchema} from "joi"
import type {Res, StatusCode} from "./main"

export function responseValidationFactory(
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-koa-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@
"test": "jest"
},
"peerDependencies": {
"@hapi/joi": "^17.1.1",
"@koa/cors": "^5.0.0",
"@koa/router": "^13.0.0",
"joi": "^17.1.1",
"koa": "^2.14.1",
"koa-body": "^6.0.1",
"zod": "^3.20.6"
},
"devDependencies": {
"@hapi/joi": "^17.1.1",
"@koa/cors": "^5.0.0",
"@koa/router": "^13.1.0",
"@types/koa": "^2.15.0",
"@types/koa__cors": "^5.0.0",
"@types/koa__router": "^12.0.4",
"jest": "^30.0.0-alpha.6",
"joi": "^17.1.1",
"koa": "^2.15.3",
"koa-body": "^6.0.1",
"typescript": "~5.7.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-koa-runtime/src/joi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Schema as JoiSchema} from "@hapi/joi"
import type {Schema as JoiSchema} from "joi"
import {KoaRuntimeError, type RequestInputType} from "./errors"

export type Params<Params, Query, Body> = {
Expand Down
90 changes: 41 additions & 49 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6693e1d

Please sign in to comment.