kizunajs 2.0.0-beta.22 → 2.0.0-beta.24

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  A spec-driven framework for building fully typed REST APIs in TypeScript, where your route declarations produce the validation, the documentation, the clients, and the AI tools.
6
6
 
7
- [![npm](https://img.shields.io/npm/v/kizunajs/beta?color=blue&label=npm)](https://www.npmjs.com/package/kizunajs/v/2.0.0-beta.22)
7
+ [![npm](https://img.shields.io/npm/v/kizunajs/beta?color=blue&label=npm)](https://www.npmjs.com/package/kizunajs/v/2.0.0-beta.24)
8
8
  ![license](https://img.shields.io/badge/license-MIT-blue)
9
9
 
10
10
  [Documentation](https://kizunajs.com)
@@ -1,7 +1,7 @@
1
1
  const require_plugin = require("./plugin-Dw-yCjTY.cjs");
2
- const require_error_response = require("./error-response-C9ymqSU4.cjs");
3
- const require_plugin_server = require("./plugin-server-D6-b-Sw8.cjs");
4
- const require_schemas = require("./schemas-DNPVDvkd.cjs");
2
+ const require_error_response = require("./error-response-DN5Dsf8b.cjs");
3
+ const require_plugin_server = require("./plugin-server-7pkhltOp.cjs");
4
+ const require_schemas = require("./schemas-Bre1FVHq.cjs");
5
5
  let zod = require("zod");
6
6
  //#region src/tool-definitions.ts
7
7
  /**
@@ -87,8 +87,9 @@ const toJsonSchema = (route) => {
87
87
  const { $schema: _, ...schema } = zod.z.toJSONSchema(zod.z.object(shape ?? {}), {
88
88
  io: "input",
89
89
  unrepresentable: "any",
90
- override: ({ jsonSchema }) => {
91
- delete jsonSchema.brand;
90
+ override: (context) => {
91
+ require_plugin_server.encodeForWire(context);
92
+ delete context.jsonSchema.brand;
92
93
  }
93
94
  });
94
95
  return schema;
@@ -1,7 +1,7 @@
1
1
  import { g as ROUTES_GROUP, n as PLUGIN_SERVERS_META_KEY, o as pluginRouteTree, p as HANDLER, t as PLUGIN_ROUTES_META_KEY } from "./plugin-xxCxibmu.mjs";
2
- import { D as unwrapOptionalWrappers, E as resolveBaseType, T as readObjectShape, c as isBinarySchema, m as readDef, o as findCoercedSchemaPath, p as isVoidSchema, t as ProblemDetailsSchema, u as isFileSchema } from "./error-response-CNQaKVYd.mjs";
3
- import { F as routeStreams, G as isZodSchema, H as isJsonMediaType, J as resolveResponseBody, L as streamContentType, M as assertValidStreams, N as encodeStreamBody, S as dueSchedules, U as isStreamResponse, W as isSuccessStatus, X as resolveResponseContentType, Y as resolveResponseCache, Z as resolveResponseEtag, _ as jobAt, c as cacheHeaders, ct as allowedMethodsForPath, dt as isRouteDefinition, ft as validateRequest, h as isCompiledJob, j as EVENT_STREAM_MEDIA_TYPE, k as deriveToolNames, lt as flattenRoutes, m as flattenJobs, pt as resolveCoercionPlans, st as parsePath, u as deprecationHeaders, ut as formatValidationError, y as toJobResponse, z as streamSchemas } from "./plugin-server-DZx4-wXx.mjs";
4
- import { l as authenticationChallenge, p as resolveSecurityRequirements } from "./schemas-HW2FDsvz.mjs";
2
+ import { D as resolveBaseType, E as readObjectShape, O as unwrapOptionalWrappers, c as isBinarySchema, m as readDef, o as findCoercedSchemaPath, p as isVoidSchema, t as ProblemDetailsSchema, u as isFileSchema } from "./error-response-D7urgxeq.mjs";
3
+ import { A as deriveToolNames, B as streamSchemas, G as isSuccessStatus, I as routeStreams, K as isZodSchema, M as EVENT_STREAM_MEDIA_TYPE, N as assertValidStreams, P as encodeStreamBody, Q as resolveResponseEtag, R as streamContentType, S as dueSchedules, U as isJsonMediaType, W as isStreamResponse, X as resolveResponseCache, Y as resolveResponseBody, Z as resolveResponseContentType, _ as jobAt, c as cacheHeaders, ct as parsePath, dt as formatValidationError, ft as isRouteDefinition, h as isCompiledJob, k as encodeForWire, lt as allowedMethodsForPath, m as flattenJobs, mt as resolveCoercionPlans, pt as validateRequest, u as deprecationHeaders, ut as flattenRoutes, y as toJobResponse } from "./plugin-server-B-JDZ7GV.mjs";
4
+ import { l as authenticationChallenge, p as resolveSecurityRequirements } from "./schemas-DBX8DwFb.mjs";
5
5
  import { z } from "zod";
6
6
  //#region src/tool-definitions.ts
7
7
  /**
@@ -87,8 +87,9 @@ const toJsonSchema = (route) => {
87
87
  const { $schema: _, ...schema } = z.toJSONSchema(z.object(shape ?? {}), {
88
88
  io: "input",
89
89
  unrepresentable: "any",
90
- override: ({ jsonSchema }) => {
91
- delete jsonSchema.brand;
90
+ override: (context) => {
91
+ encodeForWire(context);
92
+ delete context.jsonSchema.brand;
92
93
  }
93
94
  });
94
95
  return schema;
package/dist/adapter.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_plugin = require("./plugin-Dw-yCjTY.cjs");
3
- const require_plugin_server = require("./plugin-server-D6-b-Sw8.cjs");
4
- const require_schemas = require("./schemas-DNPVDvkd.cjs");
5
- const require_adapter = require("./adapter-D7KXowQc.cjs");
3
+ const require_plugin_server = require("./plugin-server-7pkhltOp.cjs");
4
+ const require_schemas = require("./schemas-Bre1FVHq.cjs");
5
+ const require_adapter = require("./adapter-CWSs910w.cjs");
6
6
  exports.API_META = require_adapter.API_META;
7
7
  exports.AUTO_GUARD_BRAND = require_plugin.AUTO_GUARD_BRAND;
8
8
  exports.AUTO_RESPONSES_BRAND = require_plugin.AUTO_RESPONSES_BRAND;
package/dist/adapter.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as definePlugin, d as AUTO_RESPONSES_BRAND, g as ROUTES_GROUP, l as AUTO_GUARD_BRAND, m as HANDLER_CONTEXT_BRAND, o as pluginRouteTree } from "./plugin-xxCxibmu.mjs";
2
- import { N as encodeStreamBody, U as isStreamResponse, _ as jobAt, a as pluginRoutesOf, ct as allowedMethodsForPath, dt as isRouteDefinition, ft as validateRequest, h as isCompiledJob, i as pluginRouterOf, lt as flattenRoutes, m as flattenJobs, o as resolvePlugins, ot as buildPath, r as pluginExportsOf, st as parsePath, t as createApiReference, ut as formatValidationError } from "./plugin-server-DZx4-wXx.mjs";
3
- import { l as authenticationChallenge, p as resolveSecurityRequirements } from "./schemas-HW2FDsvz.mjs";
4
- import { A as parseFetchBody, B as matchRoute, C as guardDenyFor, Ct as toolRefusal, D as jobRoutes, E as jobRouter, F as warnUnsupportedJobOptions, G as JobDispatchError, H as insufficientScope, I as isRawResponse, J as createJobRunner, K as defineJobTransport, L as rawResponse, M as routerFromRoutes, N as runHandler, O as jobRunnerFrom, P as runRoute, S as getHeaderValue, St as toolOptionsOf, T as isGuardDenial, U as requiresDenial, V as sortFlattenedRoutes, W as withPermissions, X as ResponseError, Y as jobFnAt, _ as defineAdapter, a as HANDLER_ARG_KEYS, b as entriesToObject, bt as describeTool, c as ROUTER_META, d as SCHEMES_META, f as adapterContextOf, g as contractOf, h as boundJobKeys, ht as groupRoutes, i as GUARD_SCHEMA_META, j as renderJsonResult, k as parseBodyText, l as RUN_ROUTE_KEY, m as bearerChallenge, n as DISPATCH_ROUTE_KEY, o as JOBS_META, p as assembleApi, pt as isGroupSet, q as JobInputError, r as GUARDS_META, rt as problemDetails, s as REQUEST_CONTEXT_META, t as API_META, u as ResponseValidationError, v as dispatchHandler, vt as buildToolDefinitions, w as headersToObject, x as extractCredential, xt as selectToolRoutes, y as dispatchRoute, yt as buildToolInputSchema } from "./adapter-_R9w_PZc.mjs";
2
+ import { P as encodeStreamBody, W as isStreamResponse, _ as jobAt, a as pluginRoutesOf, ct as parsePath, dt as formatValidationError, ft as isRouteDefinition, h as isCompiledJob, i as pluginRouterOf, lt as allowedMethodsForPath, m as flattenJobs, o as resolvePlugins, pt as validateRequest, r as pluginExportsOf, st as buildPath, t as createApiReference, ut as flattenRoutes } from "./plugin-server-B-JDZ7GV.mjs";
3
+ import { l as authenticationChallenge, p as resolveSecurityRequirements } from "./schemas-DBX8DwFb.mjs";
4
+ import { A as parseFetchBody, B as matchRoute, C as guardDenyFor, Ct as toolRefusal, D as jobRoutes, E as jobRouter, F as warnUnsupportedJobOptions, G as JobDispatchError, H as insufficientScope, I as isRawResponse, J as createJobRunner, K as defineJobTransport, L as rawResponse, M as routerFromRoutes, N as runHandler, O as jobRunnerFrom, P as runRoute, S as getHeaderValue, St as toolOptionsOf, T as isGuardDenial, U as requiresDenial, V as sortFlattenedRoutes, W as withPermissions, X as ResponseError, Y as jobFnAt, _ as defineAdapter, a as HANDLER_ARG_KEYS, b as entriesToObject, bt as describeTool, c as ROUTER_META, d as SCHEMES_META, f as adapterContextOf, g as contractOf, h as boundJobKeys, ht as groupRoutes, i as GUARD_SCHEMA_META, j as renderJsonResult, k as parseBodyText, l as RUN_ROUTE_KEY, m as bearerChallenge, n as DISPATCH_ROUTE_KEY, o as JOBS_META, p as assembleApi, pt as isGroupSet, q as JobInputError, r as GUARDS_META, rt as problemDetails, s as REQUEST_CONTEXT_META, t as API_META, u as ResponseValidationError, v as dispatchHandler, vt as buildToolDefinitions, w as headersToObject, x as extractCredential, xt as selectToolRoutes, y as dispatchRoute, yt as buildToolInputSchema } from "./adapter-DW1ixy_N.mjs";
5
5
  export { API_META, AUTO_GUARD_BRAND, AUTO_RESPONSES_BRAND, DISPATCH_ROUTE_KEY, GUARDS_META, GUARD_SCHEMA_META, HANDLER_ARG_KEYS, HANDLER_CONTEXT_BRAND, JOBS_META, JobDispatchError, JobInputError, REQUEST_CONTEXT_META, ROUTER_META, ROUTES_GROUP, RUN_ROUTE_KEY, ResponseError, ResponseValidationError, SCHEMES_META, adapterContextOf, allowedMethodsForPath, assembleApi, authenticationChallenge, bearerChallenge, boundJobKeys, buildPath, buildToolDefinitions, buildToolInputSchema, contractOf, createApiReference, createJobRunner, defineAdapter, defineJobTransport, definePlugin, describeTool, dispatchHandler, dispatchRoute, encodeStreamBody, entriesToObject, extractCredential, flattenJobs, flattenRoutes, formatValidationError, getHeaderValue, groupRoutes, guardDenyFor, headersToObject, insufficientScope, isCompiledJob, isGroupSet, isGuardDenial, isRawResponse, isRouteDefinition, isStreamResponse, jobAt, jobFnAt, jobRouter, jobRoutes, jobRunnerFrom, matchRoute, parseBodyText, parseFetchBody, parsePath, pluginExportsOf, pluginRouteTree, pluginRouterOf, pluginRoutesOf, problemDetails, rawResponse, renderJsonResult, requiresDenial, resolvePlugins, resolveSecurityRequirements, routerFromRoutes, runHandler, runRoute, selectToolRoutes, sortFlattenedRoutes, toolOptionsOf, toolRefusal, validateRequest, warnUnsupportedJobOptions, withPermissions };
@@ -193,11 +193,24 @@ const markModelSchema = (schema) => {
193
193
  modelSchemas.add(schema);
194
194
  };
195
195
  /**
196
+ * Returns the `Kizuna.model` a schema is, or was copied from by `.describe()` or `.meta()`.
197
+ */
198
+ const readModelSchema = (schema) => {
199
+ let current = schema;
200
+ while (current !== void 0) {
201
+ if (modelSchemas.has(current)) return current;
202
+ const parent = current._zod.parent;
203
+ if (parent === void 0 || parent._zod.def !== current._zod.def) return void 0;
204
+ current = parent;
205
+ }
206
+ };
207
+ /**
196
208
  * Returns a `Kizuna.model` schema's `id` metadata, or undefined.
197
209
  */
198
210
  const readMetaId = (schema) => {
199
- if (!modelSchemas.has(schema)) return void 0;
200
- const id = readMeta(schema)?.id;
211
+ const model = readModelSchema(schema);
212
+ if (model === void 0) return void 0;
213
+ const id = readMeta(model)?.id;
201
214
  return typeof id === "string" ? id : void 0;
202
215
  };
203
216
  /**
@@ -354,4 +367,4 @@ function isProblemDetails(body) {
354
367
  return typeof candidate.type === "string" && typeof candidate.title === "string" && typeof candidate.status === "number" && typeof candidate.detail === "string";
355
368
  }
356
369
  //#endregion
357
- export { readMetaExamples as C, unwrapOptionalWrappers as D, resolveBaseType as E, readMetaDescription as S, readObjectShape as T, readDiscriminatedUnion as _, WRAPPER_TYPES as a, readMeta as b, isBinarySchema as c, isIntegerSchema as d, isObjectSchema as f, readDeprecation as g, readDefType as h, FILE_PROBE as i, isDiscriminatedUnionSchema as l, readDef as m, isProblemDetails as n, findCoercedSchemaPath as o, isVoidSchema as p, createModel as r, globalRegistrySchemas as s, ProblemDetailsSchema as t, isFileSchema as u, readDiscriminatorLiteral as v, readMetaId as w, readMetaBrand as x, readDiscriminatorStringLiteral as y };
370
+ export { readMetaExamples as C, resolveBaseType as D, readObjectShape as E, unwrapOptionalWrappers as O, readMetaDescription as S, readModelSchema as T, readDiscriminatedUnion as _, WRAPPER_TYPES as a, readMeta as b, isBinarySchema as c, isIntegerSchema as d, isObjectSchema as f, readDeprecation as g, readDefType as h, FILE_PROBE as i, isDiscriminatedUnionSchema as l, readDef as m, isProblemDetails as n, findCoercedSchemaPath as o, isVoidSchema as p, createModel as r, globalRegistrySchemas as s, ProblemDetailsSchema as t, isFileSchema as u, readDiscriminatorLiteral as v, readMetaId as w, readMetaBrand as x, readDiscriminatorStringLiteral as y };
@@ -193,11 +193,24 @@ const markModelSchema = (schema) => {
193
193
  modelSchemas.add(schema);
194
194
  };
195
195
  /**
196
+ * Returns the `Kizuna.model` a schema is, or was copied from by `.describe()` or `.meta()`.
197
+ */
198
+ const readModelSchema = (schema) => {
199
+ let current = schema;
200
+ while (current !== void 0) {
201
+ if (modelSchemas.has(current)) return current;
202
+ const parent = current._zod.parent;
203
+ if (parent === void 0 || parent._zod.def !== current._zod.def) return void 0;
204
+ current = parent;
205
+ }
206
+ };
207
+ /**
196
208
  * Returns a `Kizuna.model` schema's `id` metadata, or undefined.
197
209
  */
198
210
  const readMetaId = (schema) => {
199
- if (!modelSchemas.has(schema)) return void 0;
200
- const id = readMeta(schema)?.id;
211
+ const model = readModelSchema(schema);
212
+ if (model === void 0) return void 0;
213
+ const id = readMeta(model)?.id;
201
214
  return typeof id === "string" ? id : void 0;
202
215
  };
203
216
  /**
@@ -498,6 +511,12 @@ Object.defineProperty(exports, "readMetaId", {
498
511
  return readMetaId;
499
512
  }
500
513
  });
514
+ Object.defineProperty(exports, "readModelSchema", {
515
+ enumerable: true,
516
+ get: function() {
517
+ return readModelSchema;
518
+ }
519
+ });
501
520
  Object.defineProperty(exports, "readObjectShape", {
502
521
  enumerable: true,
503
522
  get: function() {
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_error_response = require("./error-response-C9ymqSU4.cjs");
3
- const require_plugin_server = require("./plugin-server-D6-b-Sw8.cjs");
2
+ const require_error_response = require("./error-response-DN5Dsf8b.cjs");
3
+ const require_plugin_server = require("./plugin-server-7pkhltOp.cjs");
4
4
  //#region src/generator.ts
5
5
  /**
6
6
  * Every route the api serves, the app's and the plugins' under their slugs,
@@ -42,7 +42,8 @@ const reachModels = (value, models, found, seen) => {
42
42
  if (typeof value !== "object" || value === null || seen.has(value)) return;
43
43
  seen.add(value);
44
44
  if (isSchema(value)) {
45
- if (models.has(value)) found.add(value);
45
+ const model = require_error_response.readModelSchema(value);
46
+ if (model !== void 0 && models.has(model)) found.add(model);
46
47
  const def = value._zod.def;
47
48
  for (const [key, child] of Object.entries(def)) {
48
49
  if (key === "checks") continue;
@@ -176,6 +177,7 @@ exports.defineClient = defineClient;
176
177
  exports.defineGenerator = defineGenerator;
177
178
  exports.deprecationHeaders = require_plugin_server.deprecationHeaders;
178
179
  exports.deriveToolNames = require_plugin_server.deriveToolNames;
180
+ exports.encodeForWire = require_plugin_server.encodeForWire;
179
181
  exports.flattenJobs = require_plugin_server.flattenJobs;
180
182
  exports.globalRegistrySchemas = require_error_response.globalRegistrySchemas;
181
183
  exports.isBinarySchema = require_error_response.isBinarySchema;
@@ -207,6 +209,7 @@ exports.readMetaBrand = require_error_response.readMetaBrand;
207
209
  exports.readMetaDescription = require_error_response.readMetaDescription;
208
210
  exports.readMetaExamples = require_error_response.readMetaExamples;
209
211
  exports.readMetaId = require_error_response.readMetaId;
212
+ exports.readModelSchema = require_error_response.readModelSchema;
210
213
  exports.readObjectShape = require_error_response.readObjectShape;
211
214
  exports.resolveResponseBody = require_plugin_server.resolveResponseBody;
212
215
  exports.resolveResponseCache = require_plugin_server.resolveResponseCache;
@@ -107,6 +107,10 @@ declare const isBinarySchema: (schema: z.core.$ZodType) => boolean;
107
107
  * Returns a schema's metadata (set via `.meta()`), or undefined.
108
108
  */
109
109
  declare const readMeta: (schema: z.core.$ZodType) => Record<string, unknown> | undefined;
110
+ /**
111
+ * Returns the `Kizuna.model` a schema is, or was copied from by `.describe()` or `.meta()`.
112
+ */
113
+ declare const readModelSchema: (schema: z.core.$ZodType) => z.core.$ZodType | undefined;
110
114
  /**
111
115
  * Returns a `Kizuna.model` schema's `id` metadata, or undefined.
112
116
  */
@@ -148,6 +152,19 @@ declare const globalRegistrySchemas: () => Map<string, z.core.$ZodType>;
148
152
  */
149
153
  declare const deprecationHeaders: (route: RouteDefinition) => ResponseHeaders;
150
154
  //#endregion
155
+ //#region src/json-encoding.d.ts
156
+ /**
157
+ * An `override` for `z.toJSONSchema` that gives a date or bigint its wire form,
158
+ * where `unrepresentable: 'any'` would otherwise leave an empty schema.
159
+ */
160
+ declare const encodeForWire: ({
161
+ zodSchema,
162
+ jsonSchema
163
+ }: {
164
+ zodSchema: z.core.$ZodType;
165
+ jsonSchema: Record<string, unknown>;
166
+ }) => void;
167
+ //#endregion
151
168
  //#region src/tool-name.d.ts
152
169
  /**
153
170
  * `users.listUsers` becomes `users_list_users`, the shape MCP servers publish
@@ -376,4 +393,4 @@ interface GeneratorDefinition<Schema extends z.ZodType | undefined> {
376
393
  */
377
394
  declare const defineGenerator: <Schema extends z.ZodType | undefined = undefined>(definition: GeneratorDefinition<Schema>) => ((options: OptionsInput<Schema> & GeneratedFileOptions) => GeneratedFile);
378
395
  //#endregion
379
- export { ClientDefinition, type CompiledJob, type DiscriminatedUnion, EVENT_STREAM_MEDIA_TYPE, FILE_PROBE, type FlattenedJob, GenerateContext, type GeneratedFile, GeneratedFileOptions, GeneratorDefinition, GeneratorModelContext, GeneratorPluginInfo, GeneratorRouteContext, GeneratorWalk, type Jobs, type RouteDefinition, type Routes, type StreamMode, type ToolNameEntry, type ToolOrigin, WalkApiOptions, type ZodDef, cacheHeaders, defineClient, defineGenerator, deprecationHeaders, deriveToolNames, flattenJobs, globalRegistrySchemas, isBinarySchema, isCompiledJob, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, isZodSchema, jobAt, listedRoutes, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorLiteral, readDiscriminatorStringLiteral, readMeta, readMetaBrand, readMetaDescription, readMetaExamples, readMetaId, readObjectShape, resolveResponseBody, resolveResponseCache, resolveResponseContentType, resolveResponseEtag, resolveResponseHeaders, resolveResponseStream, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamContentType, streamMode, streamSchemas, streamStatuses, toCamelCase, toPascalCase, toToolName, unwrapOptionalWrappers, walkApi };
396
+ export { ClientDefinition, type CompiledJob, type DiscriminatedUnion, EVENT_STREAM_MEDIA_TYPE, FILE_PROBE, type FlattenedJob, GenerateContext, type GeneratedFile, GeneratedFileOptions, GeneratorDefinition, GeneratorModelContext, GeneratorPluginInfo, GeneratorRouteContext, GeneratorWalk, type Jobs, type RouteDefinition, type Routes, type StreamMode, type ToolNameEntry, type ToolOrigin, WalkApiOptions, type ZodDef, cacheHeaders, defineClient, defineGenerator, deprecationHeaders, deriveToolNames, encodeForWire, flattenJobs, globalRegistrySchemas, isBinarySchema, isCompiledJob, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, isZodSchema, jobAt, listedRoutes, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorLiteral, readDiscriminatorStringLiteral, readMeta, readMetaBrand, readMetaDescription, readMetaExamples, readMetaId, readModelSchema, readObjectShape, resolveResponseBody, resolveResponseCache, resolveResponseContentType, resolveResponseEtag, resolveResponseHeaders, resolveResponseStream, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamContentType, streamMode, streamSchemas, streamStatuses, toCamelCase, toPascalCase, toToolName, unwrapOptionalWrappers, walkApi };
@@ -107,6 +107,10 @@ declare const isBinarySchema: (schema: z.core.$ZodType) => boolean;
107
107
  * Returns a schema's metadata (set via `.meta()`), or undefined.
108
108
  */
109
109
  declare const readMeta: (schema: z.core.$ZodType) => Record<string, unknown> | undefined;
110
+ /**
111
+ * Returns the `Kizuna.model` a schema is, or was copied from by `.describe()` or `.meta()`.
112
+ */
113
+ declare const readModelSchema: (schema: z.core.$ZodType) => z.core.$ZodType | undefined;
110
114
  /**
111
115
  * Returns a `Kizuna.model` schema's `id` metadata, or undefined.
112
116
  */
@@ -148,6 +152,19 @@ declare const globalRegistrySchemas: () => Map<string, z.core.$ZodType>;
148
152
  */
149
153
  declare const deprecationHeaders: (route: RouteDefinition) => ResponseHeaders;
150
154
  //#endregion
155
+ //#region src/json-encoding.d.ts
156
+ /**
157
+ * An `override` for `z.toJSONSchema` that gives a date or bigint its wire form,
158
+ * where `unrepresentable: 'any'` would otherwise leave an empty schema.
159
+ */
160
+ declare const encodeForWire: ({
161
+ zodSchema,
162
+ jsonSchema
163
+ }: {
164
+ zodSchema: z.core.$ZodType;
165
+ jsonSchema: Record<string, unknown>;
166
+ }) => void;
167
+ //#endregion
151
168
  //#region src/tool-name.d.ts
152
169
  /**
153
170
  * `users.listUsers` becomes `users_list_users`, the shape MCP servers publish
@@ -376,4 +393,4 @@ interface GeneratorDefinition<Schema extends z.ZodType | undefined> {
376
393
  */
377
394
  declare const defineGenerator: <Schema extends z.ZodType | undefined = undefined>(definition: GeneratorDefinition<Schema>) => ((options: OptionsInput<Schema> & GeneratedFileOptions) => GeneratedFile);
378
395
  //#endregion
379
- export { ClientDefinition, type CompiledJob, type DiscriminatedUnion, EVENT_STREAM_MEDIA_TYPE, FILE_PROBE, type FlattenedJob, GenerateContext, type GeneratedFile, GeneratedFileOptions, GeneratorDefinition, GeneratorModelContext, GeneratorPluginInfo, GeneratorRouteContext, GeneratorWalk, type Jobs, type RouteDefinition, type Routes, type StreamMode, type ToolNameEntry, type ToolOrigin, WalkApiOptions, type ZodDef, cacheHeaders, defineClient, defineGenerator, deprecationHeaders, deriveToolNames, flattenJobs, globalRegistrySchemas, isBinarySchema, isCompiledJob, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, isZodSchema, jobAt, listedRoutes, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorLiteral, readDiscriminatorStringLiteral, readMeta, readMetaBrand, readMetaDescription, readMetaExamples, readMetaId, readObjectShape, resolveResponseBody, resolveResponseCache, resolveResponseContentType, resolveResponseEtag, resolveResponseHeaders, resolveResponseStream, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamContentType, streamMode, streamSchemas, streamStatuses, toCamelCase, toPascalCase, toToolName, unwrapOptionalWrappers, walkApi };
396
+ export { ClientDefinition, type CompiledJob, type DiscriminatedUnion, EVENT_STREAM_MEDIA_TYPE, FILE_PROBE, type FlattenedJob, GenerateContext, type GeneratedFile, GeneratedFileOptions, GeneratorDefinition, GeneratorModelContext, GeneratorPluginInfo, GeneratorRouteContext, GeneratorWalk, type Jobs, type RouteDefinition, type Routes, type StreamMode, type ToolNameEntry, type ToolOrigin, WalkApiOptions, type ZodDef, cacheHeaders, defineClient, defineGenerator, deprecationHeaders, deriveToolNames, encodeForWire, flattenJobs, globalRegistrySchemas, isBinarySchema, isCompiledJob, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, isZodSchema, jobAt, listedRoutes, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorLiteral, readDiscriminatorStringLiteral, readMeta, readMetaBrand, readMetaDescription, readMetaExamples, readMetaId, readModelSchema, readObjectShape, resolveResponseBody, resolveResponseCache, resolveResponseContentType, resolveResponseEtag, resolveResponseHeaders, resolveResponseStream, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamContentType, streamMode, streamSchemas, streamStatuses, toCamelCase, toPascalCase, toToolName, unwrapOptionalWrappers, walkApi };
@@ -1,5 +1,5 @@
1
- import { C as readMetaExamples, D as unwrapOptionalWrappers, S as readMetaDescription, T as readObjectShape, _ as readDiscriminatedUnion, b as readMeta, c as isBinarySchema, d as isIntegerSchema, f as isObjectSchema, g as readDeprecation, h as readDefType, i as FILE_PROBE, l as isDiscriminatedUnionSchema, m as readDef, p as isVoidSchema, s as globalRegistrySchemas, u as isFileSchema, v as readDiscriminatorLiteral, w as readMetaId, x as readMetaBrand, y as readDiscriminatorStringLiteral } from "./error-response-CNQaKVYd.mjs";
2
- import { $ as resolveResponseStream, A as toToolName, B as streamStatuses, F as routeStreams, G as isZodSchema, H as isJsonMediaType, I as soleStreamResponse, J as resolveResponseBody, K as localTypeName, L as streamContentType, P as isNamedStream, Q as resolveResponseHeaders, R as streamMode, U as isStreamResponse, V as isHintPrefix, W as isSuccessStatus, X as resolveResponseContentType, Y as resolveResponseCache, Z as resolveResponseEtag, _ as jobAt, a as pluginRoutesOf, at as toPascalCase, c as cacheHeaders, dt as isRouteDefinition, et as sanitizeFieldName, h as isCompiledJob, it as toCamelCase, j as EVENT_STREAM_MEDIA_TYPE, k as deriveToolNames, lt as flattenRoutes, m as flattenJobs, n as describeIssue, nt as shortTypeName, q as mergeHeaderFields, rt as statusToCamelCase, st as parsePath, tt as sanitizeIdentifier, u as deprecationHeaders, z as streamSchemas } from "./plugin-server-DZx4-wXx.mjs";
1
+ import { C as readMetaExamples, E as readObjectShape, O as unwrapOptionalWrappers, S as readMetaDescription, T as readModelSchema, _ as readDiscriminatedUnion, b as readMeta, c as isBinarySchema, d as isIntegerSchema, f as isObjectSchema, g as readDeprecation, h as readDefType, i as FILE_PROBE, l as isDiscriminatedUnionSchema, m as readDef, p as isVoidSchema, s as globalRegistrySchemas, u as isFileSchema, v as readDiscriminatorLiteral, w as readMetaId, x as readMetaBrand, y as readDiscriminatorStringLiteral } from "./error-response-D7urgxeq.mjs";
2
+ import { $ as resolveResponseHeaders, A as deriveToolNames, B as streamSchemas, F as isNamedStream, G as isSuccessStatus, H as isHintPrefix, I as routeStreams, J as mergeHeaderFields, K as isZodSchema, L as soleStreamResponse, M as EVENT_STREAM_MEDIA_TYPE, Q as resolveResponseEtag, R as streamContentType, U as isJsonMediaType, V as streamStatuses, W as isStreamResponse, X as resolveResponseCache, Y as resolveResponseBody, Z as resolveResponseContentType, _ as jobAt, a as pluginRoutesOf, at as toCamelCase, c as cacheHeaders, ct as parsePath, et as resolveResponseStream, ft as isRouteDefinition, h as isCompiledJob, it as statusToCamelCase, j as toToolName, k as encodeForWire, m as flattenJobs, n as describeIssue, nt as sanitizeIdentifier, ot as toPascalCase, q as localTypeName, rt as shortTypeName, tt as sanitizeFieldName, u as deprecationHeaders, ut as flattenRoutes, z as streamMode } from "./plugin-server-B-JDZ7GV.mjs";
3
3
  //#region src/generator.ts
4
4
  /**
5
5
  * Every route the api serves, the app's and the plugins' under their slugs,
@@ -41,7 +41,8 @@ const reachModels = (value, models, found, seen) => {
41
41
  if (typeof value !== "object" || value === null || seen.has(value)) return;
42
42
  seen.add(value);
43
43
  if (isSchema(value)) {
44
- if (models.has(value)) found.add(value);
44
+ const model = readModelSchema(value);
45
+ if (model !== void 0 && models.has(model)) found.add(model);
45
46
  const def = value._zod.def;
46
47
  for (const [key, child] of Object.entries(def)) {
47
48
  if (key === "checks") continue;
@@ -168,4 +169,4 @@ const defineGenerator = (definition) => (input) => {
168
169
  };
169
170
  };
170
171
  //#endregion
171
- export { EVENT_STREAM_MEDIA_TYPE, FILE_PROBE, cacheHeaders, defineClient, defineGenerator, deprecationHeaders, deriveToolNames, flattenJobs, globalRegistrySchemas, isBinarySchema, isCompiledJob, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, isZodSchema, jobAt, listedRoutes, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorLiteral, readDiscriminatorStringLiteral, readMeta, readMetaBrand, readMetaDescription, readMetaExamples, readMetaId, readObjectShape, resolveResponseBody, resolveResponseCache, resolveResponseContentType, resolveResponseEtag, resolveResponseHeaders, resolveResponseStream, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamContentType, streamMode, streamSchemas, streamStatuses, toCamelCase, toPascalCase, toToolName, unwrapOptionalWrappers, walkApi };
172
+ export { EVENT_STREAM_MEDIA_TYPE, FILE_PROBE, cacheHeaders, defineClient, defineGenerator, deprecationHeaders, deriveToolNames, encodeForWire, flattenJobs, globalRegistrySchemas, isBinarySchema, isCompiledJob, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, isZodSchema, jobAt, listedRoutes, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorLiteral, readDiscriminatorStringLiteral, readMeta, readMetaBrand, readMetaDescription, readMetaExamples, readMetaId, readModelSchema, readObjectShape, resolveResponseBody, resolveResponseCache, resolveResponseContentType, resolveResponseEtag, resolveResponseHeaders, resolveResponseStream, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamContentType, streamMode, streamSchemas, streamStatuses, toCamelCase, toPascalCase, toToolName, unwrapOptionalWrappers, walkApi };
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_plugin = require("./plugin-Dw-yCjTY.cjs");
3
- const require_error_response = require("./error-response-C9ymqSU4.cjs");
4
- const require_plugin_server = require("./plugin-server-D6-b-Sw8.cjs");
5
- const require_schemas = require("./schemas-DNPVDvkd.cjs");
6
- const require_adapter = require("./adapter-D7KXowQc.cjs");
3
+ const require_error_response = require("./error-response-DN5Dsf8b.cjs");
4
+ const require_plugin_server = require("./plugin-server-7pkhltOp.cjs");
5
+ const require_schemas = require("./schemas-Bre1FVHq.cjs");
6
+ const require_adapter = require("./adapter-CWSs910w.cjs");
7
7
  let zod = require("zod");
8
8
  //#region src/group-routes.ts
9
9
  /**
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as definePlugin, c as createRoute, d as AUTO_RESPONSES_BRAND, f as DECLARATION, g as ROUTES_GROUP, h as METHODS, l as AUTO_GUARD_BRAND, m as HANDLER_CONTEXT_BRAND, o as pluginRouteTree, p as HANDLER, u as AUTO_GUARD_WRITTEN_BRAND } from "./plugin-xxCxibmu.mjs";
2
- import { T as readObjectShape, m as readDef, n as isProblemDetails, r as createModel, t as ProblemDetailsSchema } from "./error-response-CNQaKVYd.mjs";
3
- import { B as streamStatuses, C as firesBetween, D as scheduleExpression, E as parseCron, F as routeStreams, G as isZodSchema, I as soleStreamResponse, J as resolveResponseBody, L as streamContentType, O as scheduleTimezone, P as isNamedStream, R as streamMode, S as dueSchedules, T as nextRuns, U as isStreamResponse, _ as jobAt, b as assertValidSchedule, dt as isRouteDefinition, f as assertJobRunner, g as isJobDefinition, h as isCompiledJob, j as EVENT_STREAM_MEDIA_TYPE, l as assertValidDeprecationDates, lt as flattenRoutes, m as flattenJobs, o as resolvePlugins, ot as buildPath, p as buildJobs, r as pluginExportsOf, s as assertValidCache, st as parsePath, t as createApiReference, v as jobClaims, w as nextRun, x as cron } from "./plugin-server-DZx4-wXx.mjs";
4
- import { a as assertCanonicalResourceUri, c as isValidationError, d as declaredScopes, f as isSecurityScheme, l as authenticationChallenge, o as buildProtectedResourceMetadata, p as resolveSecurityRequirements, u as authorizationServerIssuer } from "./schemas-HW2FDsvz.mjs";
5
- import { $ as dispatchDueJobs, F as warnUnsupportedJobOptions, G as JobDispatchError, J as createJobRunner, K as defineJobTransport, M as routerFromRoutes, Q as DispatchResultSchema, R as assertNoPathCollisions, S as getHeaderValue, X as ResponseError, Y as jobFnAt, Z as DispatchFailedSchema, _t as toolEvents, at as STATUS_TITLES, ct as createRoles, dt as permissionNames, et as dispatchSucceeded, ft as createGroups, gt as expandStreamTools, ht as groupRoutes, it as problemFromBody, lt as isPermissions, mt as assembleRoutes, nt as failedJobs, o as JOBS_META, ot as getStatusText, p as assembleApi, q as JobInputError, rt as problemDetails, st as createPermissions, tt as dueJobs, ut as isRoles, z as routeClaims } from "./adapter-_R9w_PZc.mjs";
2
+ import { E as readObjectShape, m as readDef, n as isProblemDetails, r as createModel, t as ProblemDetailsSchema } from "./error-response-D7urgxeq.mjs";
3
+ import { C as firesBetween, D as scheduleExpression, E as parseCron, F as isNamedStream, I as routeStreams, K as isZodSchema, L as soleStreamResponse, M as EVENT_STREAM_MEDIA_TYPE, O as scheduleTimezone, R as streamContentType, S as dueSchedules, T as nextRuns, V as streamStatuses, W as isStreamResponse, Y as resolveResponseBody, _ as jobAt, b as assertValidSchedule, ct as parsePath, f as assertJobRunner, ft as isRouteDefinition, g as isJobDefinition, h as isCompiledJob, l as assertValidDeprecationDates, m as flattenJobs, o as resolvePlugins, p as buildJobs, r as pluginExportsOf, s as assertValidCache, st as buildPath, t as createApiReference, ut as flattenRoutes, v as jobClaims, w as nextRun, x as cron, z as streamMode } from "./plugin-server-B-JDZ7GV.mjs";
4
+ import { a as assertCanonicalResourceUri, c as isValidationError, d as declaredScopes, f as isSecurityScheme, l as authenticationChallenge, o as buildProtectedResourceMetadata, p as resolveSecurityRequirements, u as authorizationServerIssuer } from "./schemas-DBX8DwFb.mjs";
5
+ import { $ as dispatchDueJobs, F as warnUnsupportedJobOptions, G as JobDispatchError, J as createJobRunner, K as defineJobTransport, M as routerFromRoutes, Q as DispatchResultSchema, R as assertNoPathCollisions, S as getHeaderValue, X as ResponseError, Y as jobFnAt, Z as DispatchFailedSchema, _t as toolEvents, at as STATUS_TITLES, ct as createRoles, dt as permissionNames, et as dispatchSucceeded, ft as createGroups, gt as expandStreamTools, ht as groupRoutes, it as problemFromBody, lt as isPermissions, mt as assembleRoutes, nt as failedJobs, o as JOBS_META, ot as getStatusText, p as assembleApi, q as JobInputError, rt as problemDetails, st as createPermissions, tt as dueJobs, ut as isRoles, z as routeClaims } from "./adapter-DW1ixy_N.mjs";
6
6
  import { z } from "zod";
7
7
  //#region src/group-routes.ts
8
8
  /**
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_plugin_server = require("./plugin-server-D6-b-Sw8.cjs");
3
- const require_adapter = require("./adapter-D7KXowQc.cjs");
2
+ const require_plugin_server = require("./plugin-server-7pkhltOp.cjs");
3
+ const require_adapter = require("./adapter-CWSs910w.cjs");
4
4
  //#region src/start-jobs.ts
5
5
  /**
6
6
  * The dedupe key an occurrence gets. Every instance ticking the same minute
@@ -1,5 +1,5 @@
1
- import { D as scheduleExpression, O as scheduleTimezone, m as flattenJobs, w as nextRun } from "./plugin-server-DZx4-wXx.mjs";
2
- import { O as jobRunnerFrom, Y as jobFnAt, h as boundJobKeys, o as JOBS_META } from "./adapter-_R9w_PZc.mjs";
1
+ import { D as scheduleExpression, O as scheduleTimezone, m as flattenJobs, w as nextRun } from "./plugin-server-B-JDZ7GV.mjs";
2
+ import { O as jobRunnerFrom, Y as jobFnAt, h as boundJobKeys, o as JOBS_META } from "./adapter-DW1ixy_N.mjs";
3
3
  //#region src/start-jobs.ts
4
4
  /**
5
5
  * The dedupe key an occurrence gets. Every instance ticking the same minute
@@ -1,5 +1,5 @@
1
1
  const require_plugin = require("./plugin-Dw-yCjTY.cjs");
2
- const require_error_response = require("./error-response-C9ymqSU4.cjs");
2
+ const require_error_response = require("./error-response-DN5Dsf8b.cjs");
3
3
  let zod = require("zod");
4
4
  //#region src/coercion.ts
5
5
  /**
@@ -554,6 +554,28 @@ const deriveToolNames = (entries) => {
554
554
  return names;
555
555
  };
556
556
  //#endregion
557
+ //#region src/json-encoding.ts
558
+ /**
559
+ * What the wire carries for a type JSON Schema has no keyword for. A route's
560
+ * query, path and headers arrive as text that kizuna coerces, and JSON writes
561
+ * a `Date` as its ISO string.
562
+ */
563
+ const JSON_ENCODING = {
564
+ date: {
565
+ type: "string",
566
+ format: "date-time"
567
+ },
568
+ bigint: { type: "string" }
569
+ };
570
+ /**
571
+ * An `override` for `z.toJSONSchema` that gives a date or bigint its wire form,
572
+ * where `unrepresentable: 'any'` would otherwise leave an empty schema.
573
+ */
574
+ const encodeForWire = ({ zodSchema, jsonSchema }) => {
575
+ const encoding = JSON_ENCODING[require_error_response.readDefType(zodSchema) ?? ""];
576
+ if (encoding && Object.keys(jsonSchema).length === 0) Object.assign(jsonSchema, encoding);
577
+ };
578
+ //#endregion
557
579
  //#region src/schedule.ts
558
580
  /**
559
581
  * The cron expression of a {@link JobSchedule}, whichever form it was written in.
@@ -1415,6 +1437,12 @@ Object.defineProperty(exports, "dueSchedules", {
1415
1437
  return dueSchedules;
1416
1438
  }
1417
1439
  });
1440
+ Object.defineProperty(exports, "encodeForWire", {
1441
+ enumerable: true,
1442
+ get: function() {
1443
+ return encodeForWire;
1444
+ }
1445
+ });
1418
1446
  Object.defineProperty(exports, "encodeStreamBody", {
1419
1447
  enumerable: true,
1420
1448
  get: function() {
@@ -1,5 +1,5 @@
1
1
  import { g as ROUTES_GROUP, n as PLUGIN_SERVERS_META_KEY, t as PLUGIN_ROUTES_META_KEY } from "./plugin-xxCxibmu.mjs";
2
- import { E as resolveBaseType, T as readObjectShape, a as WRAPPER_TYPES, c as isBinarySchema, m as readDef, t as ProblemDetailsSchema } from "./error-response-CNQaKVYd.mjs";
2
+ import { D as resolveBaseType, E as readObjectShape, a as WRAPPER_TYPES, c as isBinarySchema, h as readDefType, m as readDef, t as ProblemDetailsSchema } from "./error-response-D7urgxeq.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/coercion.ts
5
5
  /**
@@ -554,6 +554,28 @@ const deriveToolNames = (entries) => {
554
554
  return names;
555
555
  };
556
556
  //#endregion
557
+ //#region src/json-encoding.ts
558
+ /**
559
+ * What the wire carries for a type JSON Schema has no keyword for. A route's
560
+ * query, path and headers arrive as text that kizuna coerces, and JSON writes
561
+ * a `Date` as its ISO string.
562
+ */
563
+ const JSON_ENCODING = {
564
+ date: {
565
+ type: "string",
566
+ format: "date-time"
567
+ },
568
+ bigint: { type: "string" }
569
+ };
570
+ /**
571
+ * An `override` for `z.toJSONSchema` that gives a date or bigint its wire form,
572
+ * where `unrepresentable: 'any'` would otherwise leave an empty schema.
573
+ */
574
+ const encodeForWire = ({ zodSchema, jsonSchema }) => {
575
+ const encoding = JSON_ENCODING[readDefType(zodSchema) ?? ""];
576
+ if (encoding && Object.keys(jsonSchema).length === 0) Object.assign(jsonSchema, encoding);
577
+ };
578
+ //#endregion
557
579
  //#region src/schedule.ts
558
580
  /**
559
581
  * The cron expression of a {@link JobSchedule}, whichever form it was written in.
@@ -1313,4 +1335,4 @@ const createApiReference = () => {
1313
1335
  };
1314
1336
  };
1315
1337
  //#endregion
1316
- export { resolveResponseStream as $, toToolName as A, streamStatuses as B, firesBetween as C, scheduleExpression as D, parseCron as E, routeStreams as F, isZodSchema as G, isJsonMediaType as H, soleStreamResponse as I, resolveResponseBody as J, localTypeName as K, streamContentType as L, assertValidStreams as M, encodeStreamBody as N, scheduleTimezone as O, isNamedStream as P, resolveResponseHeaders as Q, streamMode as R, dueSchedules as S, nextRuns as T, isStreamResponse as U, isHintPrefix as V, isSuccessStatus as W, resolveResponseContentType as X, resolveResponseCache as Y, resolveResponseEtag as Z, jobAt as _, pluginRoutesOf as a, toPascalCase as at, assertValidSchedule as b, cacheHeaders as c, allowedMethodsForPath as ct, DEFAULT_JOBS_PATH as d, isRouteDefinition as dt, sanitizeFieldName as et, assertJobRunner as f, validateRequest as ft, isJobDefinition as g, isCompiledJob as h, pluginRouterOf as i, toCamelCase as it, EVENT_STREAM_MEDIA_TYPE as j, deriveToolNames as k, assertValidDeprecationDates as l, flattenRoutes as lt, flattenJobs as m, describeIssue as n, shortTypeName as nt, resolvePlugins as o, buildPath as ot, buildJobs as p, resolveCoercionPlans as pt, mergeHeaderFields as q, pluginExportsOf as r, statusToCamelCase as rt, assertValidCache as s, parsePath as st, createApiReference as t, sanitizeIdentifier as tt, deprecationHeaders as u, formatValidationError as ut, jobClaims as v, nextRun as w, cron as x, toJobResponse as y, streamSchemas as z };
1338
+ export { resolveResponseHeaders as $, deriveToolNames as A, streamSchemas as B, firesBetween as C, scheduleExpression as D, parseCron as E, isNamedStream as F, isSuccessStatus as G, isHintPrefix as H, routeStreams as I, mergeHeaderFields as J, isZodSchema as K, soleStreamResponse as L, EVENT_STREAM_MEDIA_TYPE as M, assertValidStreams as N, scheduleTimezone as O, encodeStreamBody as P, resolveResponseEtag as Q, streamContentType as R, dueSchedules as S, nextRuns as T, isJsonMediaType as U, streamStatuses as V, isStreamResponse as W, resolveResponseCache as X, resolveResponseBody as Y, resolveResponseContentType as Z, jobAt as _, pluginRoutesOf as a, toCamelCase as at, assertValidSchedule as b, cacheHeaders as c, parsePath as ct, DEFAULT_JOBS_PATH as d, formatValidationError as dt, resolveResponseStream as et, assertJobRunner as f, isRouteDefinition as ft, isJobDefinition as g, isCompiledJob as h, pluginRouterOf as i, statusToCamelCase as it, toToolName as j, encodeForWire as k, assertValidDeprecationDates as l, allowedMethodsForPath as lt, flattenJobs as m, resolveCoercionPlans as mt, describeIssue as n, sanitizeIdentifier as nt, resolvePlugins as o, toPascalCase as ot, buildJobs as p, validateRequest as pt, localTypeName as q, pluginExportsOf as r, shortTypeName as rt, assertValidCache as s, buildPath as st, createApiReference as t, sanitizeFieldName as tt, deprecationHeaders as u, flattenRoutes as ut, jobClaims as v, nextRun as w, cron as x, toJobResponse as y, streamMode as z };
@@ -1,4 +1,4 @@
1
- const require_error_response = require("./error-response-C9ymqSU4.cjs");
1
+ const require_error_response = require("./error-response-DN5Dsf8b.cjs");
2
2
  let zod = require("zod");
3
3
  //#region src/security-scheme.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as createModel, t as ProblemDetailsSchema } from "./error-response-CNQaKVYd.mjs";
1
+ import { r as createModel, t as ProblemDetailsSchema } from "./error-response-D7urgxeq.mjs";
2
2
  import { z } from "zod";
3
3
  //#region src/security-scheme.ts
4
4
  /**
package/dist/schemas.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_error_response = require("./error-response-C9ymqSU4.cjs");
3
- const require_schemas = require("./schemas-DNPVDvkd.cjs");
2
+ const require_error_response = require("./error-response-DN5Dsf8b.cjs");
3
+ const require_schemas = require("./schemas-Bre1FVHq.cjs");
4
4
  exports.BinarySchema = require_schemas.BinarySchema;
5
5
  exports.FileSchema = require_schemas.FileSchema;
6
6
  exports.ProblemDetailsSchema = require_error_response.ProblemDetailsSchema;
package/dist/schemas.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as ProblemDetailsSchema } from "./error-response-CNQaKVYd.mjs";
2
- import { i as ProtectedResourceMetadataSchema, n as BinarySchema, r as FileSchema, s as ValidationErrorSchema, t as ToolAnswerSchema } from "./schemas-HW2FDsvz.mjs";
1
+ import { t as ProblemDetailsSchema } from "./error-response-D7urgxeq.mjs";
2
+ import { i as ProtectedResourceMetadataSchema, n as BinarySchema, r as FileSchema, s as ValidationErrorSchema, t as ToolAnswerSchema } from "./schemas-DBX8DwFb.mjs";
3
3
  export { BinarySchema, FileSchema, ProblemDetailsSchema, ProtectedResourceMetadataSchema, ToolAnswerSchema, ValidationErrorSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kizunajs",
3
- "version": "2.0.0-beta.22",
3
+ "version": "2.0.0-beta.24",
4
4
  "description": "Route declaration, validation, and the adapter API for Kizuna.js",
5
5
  "keywords": [
6
6
  "kizunajs",
package/src/generator.ts CHANGED
@@ -5,7 +5,7 @@ import type { Routes, RouteDefinition } from './types.js';
5
5
  import type { ApiDefinition } from './api-definition.js';
6
6
  import { isRouteDefinition } from './handler-pipeline.js';
7
7
  import { describeIssue, pluginRoutesOf } from './plugin-server.js';
8
- import { globalRegistrySchemas, readMetaDescription } from './zod-internals.js';
8
+ import { globalRegistrySchemas, readMetaDescription, readModelSchema } from './zod-internals.js';
9
9
  import type { GeneratedFile } from './config.js';
10
10
  import type { z } from 'zod';
11
11
 
@@ -28,6 +28,7 @@ export {
28
28
  readDiscriminatedUnion,
29
29
  readMeta,
30
30
  readMetaId,
31
+ readModelSchema,
31
32
  readMetaDescription,
32
33
  readMetaBrand,
33
34
  readMetaExamples,
@@ -41,6 +42,7 @@ export {
41
42
  } from './zod-internals.js';
42
43
 
43
44
  export { deprecationHeaders } from './deprecation.js';
45
+ export { encodeForWire } from './json-encoding.js';
44
46
  export { toToolName, deriveToolNames, type ToolOrigin, type ToolNameEntry } from './tool-name.js';
45
47
  export {
46
48
  streamMode,
@@ -222,7 +224,8 @@ const reachModels = (value: unknown, models: Map<z.core.$ZodType, string>, found
222
224
  if (typeof value !== 'object' || value === null || seen.has(value)) return;
223
225
  seen.add(value);
224
226
  if (isSchema(value)) {
225
- if (models.has(value)) found.add(value);
227
+ const model = readModelSchema(value);
228
+ if (model !== undefined && models.has(model)) found.add(model);
226
229
  const def = value._zod.def as unknown as Record<string, unknown>;
227
230
  for (const [key, child] of Object.entries(def)) {
228
231
  if (key === 'checks') continue;
@@ -0,0 +1,26 @@
1
+ import type { z } from 'zod';
2
+ import { readDefType } from './zod-internals.js';
3
+
4
+ /**
5
+ * What the wire carries for a type JSON Schema has no keyword for. A route's
6
+ * query, path and headers arrive as text that kizuna coerces, and JSON writes
7
+ * a `Date` as its ISO string.
8
+ */
9
+ const JSON_ENCODING: Record<string, Record<string, unknown>> = {
10
+ date: {
11
+ type: 'string',
12
+ format: 'date-time',
13
+ },
14
+ bigint: {
15
+ type: 'string',
16
+ },
17
+ };
18
+
19
+ /**
20
+ * An `override` for `z.toJSONSchema` that gives a date or bigint its wire form,
21
+ * where `unrepresentable: 'any'` would otherwise leave an empty schema.
22
+ */
23
+ export const encodeForWire = ({ zodSchema, jsonSchema }: { zodSchema: z.core.$ZodType; jsonSchema: Record<string, unknown> }): void => {
24
+ const encoding = JSON_ENCODING[readDefType(zodSchema) ?? ''];
25
+ if (encoding && Object.keys(jsonSchema).length === 0) Object.assign(jsonSchema, encoding);
26
+ };
@@ -6,6 +6,7 @@ import { resolveSecurityRequirements } from './security-scheme.js';
6
6
  import { routeStreams } from './stream.js';
7
7
  import { deriveToolNames } from './tool-name.js';
8
8
  import { isVoidSchema, readObjectShape } from './zod-internals.js';
9
+ import { encodeForWire } from './json-encoding.js';
9
10
 
10
11
  /**
11
12
  * What a route says about publishing itself, or `undefined` when it says
@@ -138,8 +139,9 @@ const toJsonSchema = (route: RouteDefinition): Record<string, unknown> => {
138
139
  const { $schema: _, ...schema } = z.toJSONSchema(z.object(shape ?? {}), {
139
140
  io: 'input',
140
141
  unrepresentable: 'any',
141
- override: ({ jsonSchema }) => {
142
- delete jsonSchema.brand;
142
+ override: (context) => {
143
+ encodeForWire(context);
144
+ delete context.jsonSchema.brand;
143
145
  },
144
146
  }) as Record<string, unknown>;
145
147
  return schema;
@@ -248,12 +248,27 @@ export const markModelSchema = (schema: z.core.$ZodType): void => {
248
248
  modelSchemas.add(schema);
249
249
  };
250
250
 
251
+ /**
252
+ * Returns the `Kizuna.model` a schema is, or was copied from by `.describe()` or `.meta()`.
253
+ */
254
+ export const readModelSchema = (schema: z.core.$ZodType): z.core.$ZodType | undefined => {
255
+ let current: z.core.$ZodType | undefined = schema;
256
+ while (current !== undefined) {
257
+ if (modelSchemas.has(current)) return current;
258
+ const parent: z.core.$ZodType | undefined = current._zod.parent;
259
+ if (parent === undefined || parent._zod.def !== current._zod.def) return undefined;
260
+ current = parent;
261
+ }
262
+ return undefined;
263
+ };
264
+
251
265
  /**
252
266
  * Returns a `Kizuna.model` schema's `id` metadata, or undefined.
253
267
  */
254
268
  export const readMetaId = (schema: z.core.$ZodType): string | undefined => {
255
- if (!modelSchemas.has(schema)) return undefined;
256
- const id = readMeta(schema)?.id;
269
+ const model = readModelSchema(schema);
270
+ if (model === undefined) return undefined;
271
+ const id = readMeta(model)?.id;
257
272
  return typeof id === 'string' ? id : undefined;
258
273
  };
259
274