diff --git a/context.test.ts b/context.test.ts index c94b39c..e6e7ca2 100644 --- a/context.test.ts +++ b/context.test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the oak authors. All rights reserved. -import { assertEquals } from "@std/assert/assert-equals"; +import { assertEquals } from "@std/assert/equals"; import { Schema } from "./schema.ts"; import { MockRequestEvent } from "./testing_utils.ts"; @@ -18,7 +18,7 @@ Deno.test({ }, ); const responseHeaders = new Headers(); - const schema = new Schema(); + const schema = new Schema(undefined, false); const context = new Context( requestEvent, responseHeaders, @@ -26,6 +26,7 @@ Deno.test({ { item: "123" }, schema, undefined, + false, ); assertEquals(context.addr, { hostname: "localhost", diff --git a/request_server_deno.test.ts b/request_server_deno.test.ts index 3f57e9e..337a807 100644 --- a/request_server_deno.test.ts +++ b/request_server_deno.test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the oak authors. All rights reserved. -import { assertEquals } from "@std/assert/assert-equals"; +import { assertEquals } from "@std/assert/equals"; import DenoServer from "./request_server_deno.ts"; Deno.test({ diff --git a/router.ts b/router.ts index 50f1def..05876de 100644 --- a/router.ts +++ b/router.ts @@ -1826,6 +1826,7 @@ export class Router< handler, schemaDescriptor, this.#keys, + this.#expose, ); this.#logger.debug(`adding status route for ${status.join(", ")}`); this.#statusRoutes.add(route); diff --git a/schema.test.ts b/schema.test.ts index c988fac..5323802 100644 --- a/schema.test.ts +++ b/schema.test.ts @@ -2,8 +2,8 @@ import { isHttpError } from "@oak/commons/http_errors"; import { assert } from "@std/assert/assert"; -import { assertEquals } from "@std/assert/assert-equals"; -import { assertRejects } from "@std/assert/assert-rejects"; +import { assertEquals } from "@std/assert/equals"; +import { assertRejects } from "@std/assert/rejects"; import * as v from "@valibot/valibot"; import { MockRequestEvent } from "./testing_utils.ts"; @@ -12,7 +12,7 @@ import { Schema } from "./schema.ts"; Deno.test({ name: "Schema - empty schema should passthrough values for querystring", async fn() { - const schema = new Schema(); + const schema = new Schema(undefined, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1&b=2", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -26,7 +26,7 @@ Deno.test({ Deno.test({ name: "Schema - empty schema should passthrough values for body", async fn() { - const schema = new Schema(); + const schema = new Schema(undefined, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1&b=2", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -40,7 +40,7 @@ Deno.test({ Deno.test({ name: "Schema - empty schema should passthrough values for response", async fn() { - const schema = new Schema(); + const schema = new Schema(undefined, false); const result = await schema.validateResponse({ hello: "world" }); assertEquals(result, { output: { hello: "world" } }); }, @@ -51,7 +51,7 @@ Deno.test({ async fn() { const schema = new Schema({ querystring: v.object({ a: v.string(), b: v.string() }), - }); + }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1&b=2", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -65,7 +65,7 @@ Deno.test({ Deno.test({ name: "Schema - body schema should validate body", async fn() { - const schema = new Schema({ body: v.object({ c: v.number() }) }); + const schema = new Schema({ body: v.object({ c: v.number() }) }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1&b=2", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -79,7 +79,10 @@ Deno.test({ Deno.test({ name: "Schema - response schema should validate response", async fn() { - const schema = new Schema({ response: v.object({ hello: v.string() }) }); + const schema = new Schema( + { response: v.object({ hello: v.string() }) }, + false, + ); const result = await schema.validateResponse({ hello: "world" }); assertEquals(result, { output: { hello: "world" } }); }, @@ -90,7 +93,7 @@ Deno.test({ async fn() { const schema = new Schema({ querystring: v.object({ a: v.string(), b: v.string() }), - }); + }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -107,7 +110,7 @@ Deno.test({ Deno.test({ name: "Schema - invalid body should reject with 400", async fn() { - const schema = new Schema({ body: v.object({ c: v.string() }) }); + const schema = new Schema({ body: v.object({ c: v.string() }) }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1&b=2", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -124,7 +127,10 @@ Deno.test({ Deno.test({ name: "Schema - invalid response should should reject with 500", async fn() { - const schema = new Schema({ response: v.object({ hello: v.number() }) }); + const schema = new Schema( + { response: v.object({ hello: v.number() }) }, + false, + ); const error = await assertRejects(async () => { await schema.validateResponse({ hello: "world" }); }); @@ -143,7 +149,7 @@ Deno.test({ assertEquals(issues.length, 1); return new Response("Invalid querystring", { status: 400 }); }, - }); + }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -165,7 +171,7 @@ Deno.test({ assertEquals(issues.length, 1); return new Response("Invalid querystring", { status: 400 }); }, - }); + }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -187,7 +193,7 @@ Deno.test({ assertEquals(issues.length, 1); return new Response("Invalid querystring", { status: 400 }); }, - }); + }, false); const result = await schema.validateResponse({ hello: "world" }); assert(result.invalidResponse instanceof Response); assertEquals(result.invalidResponse.status, 400); @@ -202,7 +208,7 @@ Deno.test({ invalidHandler() { throw new Error("Boom"); }, - }); + }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -226,7 +232,7 @@ Deno.test({ invalidHandler() { throw new Error("Boom"); }, - }); + }, false); const requestEvent = new MockRequestEvent("http://localhost/?a=1", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -250,7 +256,7 @@ Deno.test({ invalidHandler() { throw new Error("Boom"); }, - }); + }, false); const error = await assertRejects(async () => { await schema.validateResponse({ hello: "world" }); }); diff --git a/status_route.ts b/status_route.ts index c0a43c4..efd470e 100644 --- a/status_route.ts +++ b/status_route.ts @@ -114,6 +114,7 @@ export class StatusRoute< QSSchema extends QueryStringSchema = QueryStringSchema, QueryParams extends InferOutput = InferOutput, > { + #expose: boolean; #handler: StatusHandler; #keys?: KeyRing; #schema: Schema; @@ -130,12 +131,14 @@ export class StatusRoute< status: (Status | StatusRange)[], handler: StatusHandler, schemaDescriptor: SchemaDescriptor, - keys?: KeyRing, + keys: KeyRing | undefined, + expose: boolean, ) { this.#status = status; this.#handler = handler; this.#keys = keys; - this.#schema = new Schema(schemaDescriptor); + this.#expose = expose; + this.#schema = new Schema(schemaDescriptor, expose); } /** @@ -163,6 +166,7 @@ export class StatusRoute< undefined, this.#schema, this.#keys, + this.#expose, ); const result = await this.#handler(context, response.status, response); if (result instanceof Response) {