From 876871e6304c490f7e991e625b4ad7dccb125eed Mon Sep 17 00:00:00 2001 From: Etienne Donneger Date: Fri, 21 Jun 2024 11:02:24 -0400 Subject: [PATCH] Apply `MAX_LIMIT` configuration option to `limit` --- index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index a26a371..0c42e8c 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,7 @@ import openapi from "./tsp-output/@typespec/openapi3/openapi.json"; import { Hono } from "hono"; import { ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodNumber, ZodOptional, ZodTypeAny, ZodUndefined, ZodUnion, z } from "zod"; import { EndpointByMethod } from './src/types/zod.gen.js'; -import { APP_VERSION } from "./src/config.js"; +import { APP_VERSION, config } from "./src/config.js"; import { logger } from './src/logger.js'; import * as prometheus from './src/prometheus.js'; import { makeUsageQuery } from "./src/usage.js"; @@ -96,6 +96,8 @@ function AntelopeTokenAPI() { // Query and path user input parameters come as strings and we need to coerce them to the right type using Zod if (underlying_zod_type instanceof ZodNumber) { p[key] = z.coerce.number(); + if (key === "limit") + p[key] = p[key].max(config.maxLimit); } else if (underlying_zod_type instanceof ZodBoolean) { p[key] = z.coerce.boolean(); } else if (underlying_zod_type instanceof ZodBigInt) {