Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,39 @@
"license": "MIT",
"dependencies": {
"@fastify/autoload": "^6.3.1",
"@fastify/cors": "^11.1.0",
"@fastify/mongodb": "^9.0.2",
"@fastify/cors": "^11.2.0",
"@fastify/mongodb": "^10.0.0",
"@fastify/sensible": "^6.0.4",
"@fastify/swagger": "^9.6.1",
"@fastify/swagger-ui": "^5.2.3",
"@fastify/type-provider-typebox": "^5.2.0",
"@scalar/fastify-api-reference": "^1.40.0",
"@sinclair/typebox": "^0.34.41",
"fastify": "^5.7.3",
"@fastify/swagger": "^9.7.0",
"@fastify/swagger-ui": "^5.2.5",
"@fastify/type-provider-typebox": "^6.1.0",
"@scalar/fastify-api-reference": "^1.44.15",
"fastify": "^5.7.4",
"fastify-cli": "^7.4.1",
"fastify-plugin": "^5.1.0",
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.2.0",
"openid-client": "^6.8.1"
"jsonwebtoken": "^9.0.3",
"jwks-rsa": "^3.2.2",
"openid-client": "^6.8.2",
"typebox": "^1.0.81"
},
"devDependencies": {
"@commitlint/cli": "^20.1.0",
"@commitlint/config-conventional": "^20.0.0",
"@eslint/js": "^9.39.1",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"@commitlint/cli": "^20.4.1",
"@commitlint/config-conventional": "^20.4.1",
"@eslint/js": "^10.0.1",
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^24.10.1",
"@types/node": "^25.2.2",
"concurrently": "^9.2.1",
"eslint": "^9.39.1",
"eslint": "^10.0.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-prettier": "^5.5.5",
"fastify-tsconfig": "^3.0.0",
"globals": "^16.5.0",
"globals": "^17.3.0",
"husky": "^9.1.7",
"prettier": "^3.7.4",
"prettier-plugin-jsdoc": "^1.7.0",
"prettier": "^3.8.1",
"prettier-plugin-jsdoc": "^1.8.0",
"typescript": "^5.9.3",
"typescript-eslint": "^8.48.1"
"typescript-eslint": "^8.54.0"
},
"packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
}
2 changes: 1 addition & 1 deletion src/plugins/auth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ResponseSchema } from "../utils/schema.js";
import { UnionOneOf } from "../utils/typebox/union-oneof.js";
import { Type } from "@sinclair/typebox";
import { FastifyReply, FastifyRequest } from "fastify";
import fp from "fastify-plugin";
import jwt, { JwtHeader, SigningKeyCallback } from "jsonwebtoken";
import { JwksClient } from "jwks-rsa";
import * as client from "openid-client";
import { skipSubjectCheck, WWWAuthenticateChallengeError } from "openid-client";
import { Type } from "typebox";

export interface AuthPluginOptions {
/** The discovery URL of the OpenID Connect provider. */
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/init-mongo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fp from "fastify-plugin";

// import { Collection } from "mongodb";
// import { Collection, Document } from "mongodb";

export type InitMongoPluginOptions = Record<never, unknown>;

Expand All @@ -18,7 +18,7 @@ export default fp<InitMongoPluginOptions>(async (fastify, opts) => {
// declare module "fastify" {
// export interface FastifyInstance {
// collections: {
// example: Collection<unknown>;
// example: Collection<Document>;
// };
// }
// }
2 changes: 1 addition & 1 deletion src/plugins/sensible.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sensible from "@fastify/sensible";
import { Type } from "@sinclair/typebox";
import fp from "fastify-plugin";
import { Type } from "typebox";

export const HttpError = Type.Ref("HttpError");

Expand Down
2 changes: 1 addition & 1 deletion src/routes/auth-example/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FastifyTypebox } from "../../app.js";
import { AuthResponseSchema } from "../../plugins/auth.js";
import { mergeResponse } from "../../utils/schema.js";
import { Type } from "@sinclair/typebox";
import { FastifyPluginAsync } from "fastify";
import { Type } from "typebox";

const authExample: FastifyPluginAsync = async (
fastify: FastifyTypebox,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/example/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FastifyTypebox } from "../../app.js";
import { HttpError } from "../../plugins/sensible.js";
import { Type } from "@sinclair/typebox";
import { FastifyPluginAsync } from "fastify";
import { Type } from "typebox";

const example: FastifyPluginAsync = async (
fastify: FastifyTypebox,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/root.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyTypebox } from "../app.js";
import { Type } from "@sinclair/typebox";
import { FastifyPluginAsync } from "fastify";
import { Type } from "typebox";

const root: FastifyPluginAsync = async (
fastify: FastifyTypebox,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnionOneOf } from "./typebox/union-oneof.js";
import { TSchema } from "@sinclair/typebox";
import { TSchema } from "typebox";

export type ResponseSchema = Record<number, TSchema>;

Expand Down
22 changes: 12 additions & 10 deletions src/utils/typebox/union-oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,27 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

import { TypeRegistry, Kind, Static, TSchema, SchemaOptions } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'
import { TSchema, TSchemaOptions, Static } from 'typebox'

// -------------------------------------------------------------------------------------
// TUnionOneOf
// -------------------------------------------------------------------------------------
export interface TUnionOneOf<T extends TSchema[]> extends TSchema {
[Kind]: 'UnionOneOf'
'~kind': 'UnionOneOf'
static: { [K in keyof T]: Static<T[K]> }[number]
oneOf: T
}
// -------------------------------------------------------------------------------------
// UnionOneOf
// -------------------------------------------------------------------------------------
/** `[Experimental]` Creates a Union type with a `oneOf` schema representation */
export function UnionOneOf<T extends TSchema[]>(oneOf: [...T], options: SchemaOptions = {}) {
function UnionOneOfCheck(schema: TUnionOneOf<TSchema[]>, value: unknown) {
return 1 === schema.oneOf.reduce((acc: number, schema: any) => (Value.Check(schema, value) ? acc + 1 : acc), 0)
}
if (!TypeRegistry.Has('UnionOneOf')) TypeRegistry.Set('UnionOneOf', UnionOneOfCheck)
return { ...options, [Kind]: 'UnionOneOf', oneOf } as TUnionOneOf<T>
/**
* `[Experimental]` Creates a Union type with a `oneOf` schema representation
*
* Note: Runtime validation of oneOf is handled by the JSON Schema validator (e.g., Ajv)
* which is used by Fastify. The oneOf keyword is a standard JSON Schema keyword that
* ensures exactly one of the schemas matches. This implementation doesn't need custom
* validation logic as the standard validator handles it.
*/
export function UnionOneOf<T extends TSchema[]>(oneOf: [...T], options: TSchemaOptions = {}) {
return { ...options, '~kind': 'UnionOneOf', oneOf } as TUnionOneOf<T>
}
Loading
Loading