@aklinker1/zeta 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aklinker1/zeta",
3
3
  "description": "Composable, testable, OpenAPI-first backend framework with validation built-in",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "packageManager": "bun@1.2.17",
@@ -11,6 +11,7 @@ import {
11
11
  validateOutputSchema,
12
12
  } from "./utils";
13
13
  import { smartDeserialize, smartSerialize } from "./serialization";
14
+ import { getMeta } from "../meta";
14
15
 
15
16
  export async function callHandler(
16
17
  ctx: any,
@@ -92,7 +93,7 @@ export async function callHandler(
92
93
  route.data.def.responses,
93
94
  ctx.response,
94
95
  );
95
- responseMeta = schemaAdapter?.getMeta(route.data.def.responses);
96
+ responseMeta = getMeta(schemaAdapter, route.data.def.responses);
96
97
  } else {
97
98
  if (!ctx.response || !isStatusResult(ctx.response)) {
98
99
  throw new Error(
@@ -107,7 +108,7 @@ export async function callHandler(
107
108
  }
108
109
  ctx.set.status = status;
109
110
  ctx.response = validateOutputSchema(schema, body);
110
- responseMeta = schemaAdapter?.getMeta(schema);
111
+ responseMeta = getMeta(schemaAdapter, schema);
111
112
  }
112
113
  }
113
114
  }
package/src/meta.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import type { SchemaAdapter } from "./types";
3
+ import type { ZetaSchema } from "./custom-responses";
4
+
5
+ /** Get metadata for either a ZetaSchema or a StandardSchemaV1. */
6
+ export function getMeta(
7
+ adapter: SchemaAdapter | undefined,
8
+ schema: StandardSchemaV1 | ZetaSchema,
9
+ ): Record<string, any> {
10
+ if ("~zeta" in schema) return schema.meta;
11
+
12
+ if (!adapter) return {};
13
+ return adapter.getMeta(schema) ?? {};
14
+ }
package/src/open-api.ts CHANGED
@@ -4,6 +4,7 @@ import type { CreateAppOptions } from "./app";
4
4
  import type { StandardSchemaV1 } from "@standard-schema/spec";
5
5
  import { getHttpStatusName } from "./status";
6
6
  import { ErrorResponseJsonSchema, type ZetaSchema } from "./custom-responses";
7
+ import { getMeta } from "./meta";
7
8
 
8
9
  export function buildOpenApiDocs(
9
10
  options: CreateAppOptions<any> | undefined,
@@ -45,7 +46,7 @@ export function buildOpenApiDocs(
45
46
  requestBody: body
46
47
  ? {
47
48
  content: {
48
- [adapter.getMeta(body)?.contentType ?? "application/json"]: {
49
+ [getMeta(adapter, body)?.contentType ?? "application/json"]: {
49
50
  schema: adapter.toJsonSchema(body),
50
51
  },
51
52
  },
@@ -151,16 +152,18 @@ function buildResponse(
151
152
  schema: StandardSchemaV1 | ZetaSchema,
152
153
  adapter: SchemaAdapter,
153
154
  ): NonNullable<OpenAPI.Operation["responses"]>[string] {
155
+ const meta = getMeta(adapter, schema);
156
+
154
157
  if ("~zeta" in schema) {
155
158
  const description =
156
- schema["~zeta"].meta?.responseDescription ??
157
- getHttpStatusName(status) ??
158
- "";
159
+ meta?.responseDescription ?? getHttpStatusName(status) ?? "";
160
+
159
161
  if (schema["~zeta"].type === "NoResponse") {
160
162
  return {
161
163
  description,
162
164
  };
163
165
  }
166
+
164
167
  if (schema["~zeta"].type === "ErrorResponse") {
165
168
  return {
166
169
  description,
@@ -175,7 +178,6 @@ function buildResponse(
175
178
  }
176
179
  }
177
180
 
178
- const meta = adapter.getMeta(schema);
179
181
  return {
180
182
  description: meta?.responseDescription ?? getHttpStatusName(status),
181
183
  content: {