@orpc/openapi 0.0.0-next.9306271 → 0.0.0-next.93e7a4c

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/dist/index.js CHANGED
@@ -1,26 +1,19 @@
1
1
  import {
2
- eachContractProcedureLeaf
3
- } from "./chunk-KZIT2WCV.js";
2
+ OpenAPIPayloadCodec,
3
+ forEachContractProcedure,
4
+ standardizeHTTPPath
5
+ } from "./chunk-UPDKQRQG.js";
4
6
 
5
7
  // src/generator.ts
6
8
  import { isContractProcedure } from "@orpc/contract";
7
- import { LAZY_LOADER_SYMBOL } from "@orpc/server";
9
+ import { unlazy } from "@orpc/server";
8
10
  import { findDeepMatches, isPlainObject, omit } from "@orpc/shared";
9
- import { preSerialize } from "@orpc/transformer";
10
11
  import {
11
12
  OpenApiBuilder
12
13
  } from "openapi3-ts/oas31";
13
14
 
14
- // src/zod-to-json-schema.ts
15
- import {
16
- getCustomJSONSchema,
17
- getCustomZodFileMimeType,
18
- getCustomZodType
19
- } from "@orpc/zod";
20
- import escapeStringRegexp from "escape-string-regexp";
21
- import {
22
- Format
23
- } from "json-schema-typed/draft-2020-12";
15
+ // ../zod/src/coercer.ts
16
+ import { guard } from "@orpc/shared";
24
17
 
25
18
  // ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
26
19
  var util;
@@ -3912,7 +3905,37 @@ var nullableType = ZodNullable.create;
3912
3905
  var preprocessType = ZodEffects.createWithPreprocess;
3913
3906
  var pipelineType = ZodPipeline.create;
3914
3907
 
3908
+ // ../zod/src/schemas.ts
3909
+ import wcmatch from "wildcard-match";
3910
+ var customZodTypeSymbol = Symbol("customZodTypeSymbol");
3911
+ var customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
3912
+ var CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
3913
+ var CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
3914
+ var CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
3915
+ function getCustomZodType(def) {
3916
+ return customZodTypeSymbol in def ? def[customZodTypeSymbol] : void 0;
3917
+ }
3918
+ function getCustomZodFileMimeType(def) {
3919
+ return customZodFileMimeTypeSymbol in def ? def[customZodFileMimeTypeSymbol] : void 0;
3920
+ }
3921
+ function getCustomJSONSchema(def, options) {
3922
+ if (options?.mode === "input" && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {
3923
+ return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL];
3924
+ }
3925
+ if (options?.mode === "output" && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {
3926
+ return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL];
3927
+ }
3928
+ if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {
3929
+ return def[CUSTOM_JSON_SCHEMA_SYMBOL];
3930
+ }
3931
+ return void 0;
3932
+ }
3933
+
3915
3934
  // src/zod-to-json-schema.ts
3935
+ import escapeStringRegexp from "escape-string-regexp";
3936
+ import {
3937
+ Format
3938
+ } from "json-schema-typed/draft-2020-12";
3916
3939
  var NON_LOGIC_KEYWORDS = [
3917
3940
  // Core Documentation Keywords
3918
3941
  "$anchor",
@@ -3943,10 +3966,15 @@ var NON_LOGIC_KEYWORDS = [
3943
3966
  var UNSUPPORTED_JSON_SCHEMA = { not: {} };
3944
3967
  var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
3945
3968
  function zodToJsonSchema(schema, options) {
3969
+ if (schema["~standard"].vendor !== "zod") {
3970
+ console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
3971
+ return {};
3972
+ }
3973
+ const schema__ = schema;
3946
3974
  if (!options?.isHandledCustomJSONSchema) {
3947
- const customJSONSchema = getCustomJSONSchema(schema._def, options);
3975
+ const customJSONSchema = getCustomJSONSchema(schema__._def, options);
3948
3976
  if (customJSONSchema) {
3949
- const json = zodToJsonSchema(schema, {
3977
+ const json = zodToJsonSchema(schema__, {
3950
3978
  ...options,
3951
3979
  isHandledCustomJSONSchema: true
3952
3980
  });
@@ -3957,13 +3985,13 @@ function zodToJsonSchema(schema, options) {
3957
3985
  }
3958
3986
  }
3959
3987
  const childOptions = { ...options, isHandledCustomJSONSchema: false };
3960
- const customType = getCustomZodType(schema._def);
3988
+ const customType = getCustomZodType(schema__._def);
3961
3989
  switch (customType) {
3962
3990
  case "Blob": {
3963
3991
  return { type: "string", contentMediaType: "*/*" };
3964
3992
  }
3965
3993
  case "File": {
3966
- const mimeType = getCustomZodFileMimeType(schema._def) ?? "*/*";
3994
+ const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
3967
3995
  return { type: "string", contentMediaType: mimeType };
3968
3996
  }
3969
3997
  case "Invalid Date": {
@@ -3980,10 +4008,10 @@ function zodToJsonSchema(schema, options) {
3980
4008
  }
3981
4009
  }
3982
4010
  const _expectedCustomType = customType;
3983
- const typeName = schema._def.typeName;
4011
+ const typeName = schema__._def.typeName;
3984
4012
  switch (typeName) {
3985
4013
  case ZodFirstPartyTypeKind.ZodString: {
3986
- const schema_ = schema;
4014
+ const schema_ = schema__;
3987
4015
  const json = { type: "string" };
3988
4016
  for (const check of schema_._def.checks) {
3989
4017
  switch (check.kind) {
@@ -4065,7 +4093,7 @@ function zodToJsonSchema(schema, options) {
4065
4093
  return json;
4066
4094
  }
4067
4095
  case ZodFirstPartyTypeKind.ZodNumber: {
4068
- const schema_ = schema;
4096
+ const schema_ = schema__;
4069
4097
  const json = { type: "number" };
4070
4098
  for (const check of schema_._def.checks) {
4071
4099
  switch (check.kind) {
@@ -4110,23 +4138,23 @@ function zodToJsonSchema(schema, options) {
4110
4138
  return UNDEFINED_JSON_SCHEMA;
4111
4139
  }
4112
4140
  case ZodFirstPartyTypeKind.ZodLiteral: {
4113
- const schema_ = schema;
4141
+ const schema_ = schema__;
4114
4142
  return { const: schema_._def.value };
4115
4143
  }
4116
4144
  case ZodFirstPartyTypeKind.ZodEnum: {
4117
- const schema_ = schema;
4145
+ const schema_ = schema__;
4118
4146
  return {
4119
4147
  enum: schema_._def.values
4120
4148
  };
4121
4149
  }
4122
4150
  case ZodFirstPartyTypeKind.ZodNativeEnum: {
4123
- const schema_ = schema;
4151
+ const schema_ = schema__;
4124
4152
  return {
4125
4153
  enum: Object.values(schema_._def.values)
4126
4154
  };
4127
4155
  }
4128
4156
  case ZodFirstPartyTypeKind.ZodArray: {
4129
- const schema_ = schema;
4157
+ const schema_ = schema__;
4130
4158
  const def = schema_._def;
4131
4159
  const json = { type: "array" };
4132
4160
  if (def.exactLength) {
@@ -4142,7 +4170,7 @@ function zodToJsonSchema(schema, options) {
4142
4170
  return json;
4143
4171
  }
4144
4172
  case ZodFirstPartyTypeKind.ZodTuple: {
4145
- const schema_ = schema;
4173
+ const schema_ = schema__;
4146
4174
  const prefixItems = [];
4147
4175
  const json = { type: "array" };
4148
4176
  for (const item of schema_._def.items) {
@@ -4160,7 +4188,7 @@ function zodToJsonSchema(schema, options) {
4160
4188
  return json;
4161
4189
  }
4162
4190
  case ZodFirstPartyTypeKind.ZodObject: {
4163
- const schema_ = schema;
4191
+ const schema_ = schema__;
4164
4192
  const json = { type: "object" };
4165
4193
  const properties = {};
4166
4194
  const required = [];
@@ -4196,7 +4224,7 @@ function zodToJsonSchema(schema, options) {
4196
4224
  return json;
4197
4225
  }
4198
4226
  case ZodFirstPartyTypeKind.ZodRecord: {
4199
- const schema_ = schema;
4227
+ const schema_ = schema__;
4200
4228
  const json = { type: "object" };
4201
4229
  json.additionalProperties = zodToJsonSchema(
4202
4230
  schema_._def.valueType,
@@ -4205,14 +4233,14 @@ function zodToJsonSchema(schema, options) {
4205
4233
  return json;
4206
4234
  }
4207
4235
  case ZodFirstPartyTypeKind.ZodSet: {
4208
- const schema_ = schema;
4236
+ const schema_ = schema__;
4209
4237
  return {
4210
4238
  type: "array",
4211
4239
  items: zodToJsonSchema(schema_._def.valueType, childOptions)
4212
4240
  };
4213
4241
  }
4214
4242
  case ZodFirstPartyTypeKind.ZodMap: {
4215
- const schema_ = schema;
4243
+ const schema_ = schema__;
4216
4244
  return {
4217
4245
  type: "array",
4218
4246
  items: {
@@ -4228,7 +4256,7 @@ function zodToJsonSchema(schema, options) {
4228
4256
  }
4229
4257
  case ZodFirstPartyTypeKind.ZodUnion:
4230
4258
  case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
4231
- const schema_ = schema;
4259
+ const schema_ = schema__;
4232
4260
  const anyOf = [];
4233
4261
  for (const s of schema_._def.options) {
4234
4262
  anyOf.push(zodToJsonSchema(s, childOptions));
@@ -4236,7 +4264,7 @@ function zodToJsonSchema(schema, options) {
4236
4264
  return { anyOf };
4237
4265
  }
4238
4266
  case ZodFirstPartyTypeKind.ZodIntersection: {
4239
- const schema_ = schema;
4267
+ const schema_ = schema__;
4240
4268
  const allOf = [];
4241
4269
  for (const s of [schema_._def.left, schema_._def.right]) {
4242
4270
  allOf.push(zodToJsonSchema(s, childOptions));
@@ -4244,7 +4272,7 @@ function zodToJsonSchema(schema, options) {
4244
4272
  return { allOf };
4245
4273
  }
4246
4274
  case ZodFirstPartyTypeKind.ZodLazy: {
4247
- const schema_ = schema;
4275
+ const schema_ = schema__;
4248
4276
  const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
4249
4277
  const lazyDepth = childOptions?.lazyDepth ?? 0;
4250
4278
  if (lazyDepth > maxLazyDepth) {
@@ -4261,44 +4289,44 @@ function zodToJsonSchema(schema, options) {
4261
4289
  return {};
4262
4290
  }
4263
4291
  case ZodFirstPartyTypeKind.ZodOptional: {
4264
- const schema_ = schema;
4292
+ const schema_ = schema__;
4265
4293
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
4266
4294
  return {
4267
4295
  anyOf: [UNDEFINED_JSON_SCHEMA, inner]
4268
4296
  };
4269
4297
  }
4270
4298
  case ZodFirstPartyTypeKind.ZodReadonly: {
4271
- const schema_ = schema;
4299
+ const schema_ = schema__;
4272
4300
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4273
4301
  }
4274
4302
  case ZodFirstPartyTypeKind.ZodDefault: {
4275
- const schema_ = schema;
4303
+ const schema_ = schema__;
4276
4304
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4277
4305
  }
4278
4306
  case ZodFirstPartyTypeKind.ZodEffects: {
4279
- const schema_ = schema;
4307
+ const schema_ = schema__;
4280
4308
  if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
4281
4309
  return {};
4282
4310
  }
4283
4311
  return zodToJsonSchema(schema_._def.schema, childOptions);
4284
4312
  }
4285
4313
  case ZodFirstPartyTypeKind.ZodCatch: {
4286
- const schema_ = schema;
4314
+ const schema_ = schema__;
4287
4315
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4288
4316
  }
4289
4317
  case ZodFirstPartyTypeKind.ZodBranded: {
4290
- const schema_ = schema;
4318
+ const schema_ = schema__;
4291
4319
  return zodToJsonSchema(schema_._def.type, childOptions);
4292
4320
  }
4293
4321
  case ZodFirstPartyTypeKind.ZodPipeline: {
4294
- const schema_ = schema;
4322
+ const schema_ = schema__;
4295
4323
  return zodToJsonSchema(
4296
4324
  childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
4297
4325
  childOptions
4298
4326
  );
4299
4327
  }
4300
4328
  case ZodFirstPartyTypeKind.ZodNullable: {
4301
- const schema_ = schema;
4329
+ const schema_ = schema__;
4302
4330
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
4303
4331
  return {
4304
4332
  anyOf: [{ type: "null" }, inner]
@@ -4353,6 +4381,7 @@ function extractJSONSchema(schema, check, matches = []) {
4353
4381
  async function generateOpenAPI(opts, options) {
4354
4382
  const throwOnMissingTagDefinition = options?.throwOnMissingTagDefinition ?? false;
4355
4383
  const ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
4384
+ const payloadCodec = options?.payloadCodec ?? new OpenAPIPayloadCodec();
4356
4385
  const builder = new OpenApiBuilder({
4357
4386
  ...omit(opts, ["router"]),
4358
4387
  openapi: "3.1.0"
@@ -4363,16 +4392,16 @@ async function generateOpenAPI(opts, options) {
4363
4392
  router: opts.router
4364
4393
  }];
4365
4394
  for (const item of pending) {
4366
- const lazies = eachContractProcedureLeaf(item, ({ contract, path }) => {
4395
+ const lazies = forEachContractProcedure(item, ({ contract, path }) => {
4367
4396
  if (!isContractProcedure(contract)) {
4368
4397
  return;
4369
4398
  }
4370
- const internal = contract.zz$cp;
4371
- if (ignoreUndefinedPathProcedures && internal.path === void 0) {
4399
+ const internal = contract["~orpc"];
4400
+ if (ignoreUndefinedPathProcedures && internal.route?.path === void 0) {
4372
4401
  return;
4373
4402
  }
4374
- const httpPath = internal.path ?? `/${path.map(encodeURIComponent).join("/")}`;
4375
- const method = internal.method ?? "POST";
4403
+ const httpPath = internal.route?.path ? standardizeHTTPPath(internal.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
4404
+ const method = internal.route?.method ?? "POST";
4376
4405
  let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
4377
4406
  const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
4378
4407
  const params = (() => {
@@ -4507,7 +4536,9 @@ async function generateOpenAPI(opts, options) {
4507
4536
  };
4508
4537
  }
4509
4538
  return {
4510
- required: Boolean(internal.InputSchema?.isOptional()),
4539
+ required: Boolean(
4540
+ internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
4541
+ ),
4511
4542
  content
4512
4543
  };
4513
4544
  })();
@@ -4532,8 +4563,8 @@ async function generateOpenAPI(opts, options) {
4532
4563
  content
4533
4564
  };
4534
4565
  })();
4535
- if (throwOnMissingTagDefinition && internal.tags) {
4536
- const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
4566
+ if (throwOnMissingTagDefinition && internal.route?.tags) {
4567
+ const missingTag = internal.route?.tags.find((tag) => !rootTags.includes(tag));
4537
4568
  if (missingTag !== void 0) {
4538
4569
  throw new Error(
4539
4570
  `Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
@@ -4541,10 +4572,10 @@ async function generateOpenAPI(opts, options) {
4541
4572
  }
4542
4573
  }
4543
4574
  const operation = {
4544
- summary: internal.summary,
4545
- description: internal.description,
4546
- deprecated: internal.deprecated,
4547
- tags: internal.tags,
4575
+ summary: internal.route?.summary,
4576
+ description: internal.route?.description,
4577
+ deprecated: internal.route?.deprecated,
4578
+ tags: internal.route?.tags ? [...internal.route.tags] : void 0,
4548
4579
  operationId: path.join("."),
4549
4580
  parameters: parameters.length ? parameters : void 0,
4550
4581
  requestBody,
@@ -4557,14 +4588,14 @@ async function generateOpenAPI(opts, options) {
4557
4588
  });
4558
4589
  });
4559
4590
  for (const lazy of lazies) {
4560
- const router = (await lazy.lazy[LAZY_LOADER_SYMBOL]()).default;
4591
+ const { default: router } = await unlazy(lazy.router);
4561
4592
  pending.push({
4562
4593
  path: lazy.path,
4563
4594
  router
4564
4595
  });
4565
4596
  }
4566
4597
  }
4567
- return preSerialize(builder.getSpec());
4598
+ return payloadCodec.serialize(builder.getSpec());
4568
4599
  }
4569
4600
  function isFileSchema(schema) {
4570
4601
  if (typeof schema !== "object" || schema === null)
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Serialize an object or array into a list of [key, value] pairs.
3
+ * The key will express by using bracket-notation.
4
+ *
5
+ * Notice: This way cannot express the empty object or array.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const payload = {
10
+ * name: 'John Doe',
11
+ * pets: ['dog', 'cat'],
12
+ * }
13
+ *
14
+ * const entities = serialize(payload)
15
+ *
16
+ * expect(entities).toEqual([
17
+ * ['name', 'John Doe'],
18
+ * ['name[pets][0]', 'dog'],
19
+ * ['name[pets][1]', 'cat'],
20
+ * ])
21
+ * ```
22
+ */
23
+ export declare function serialize(payload: unknown, parentKey?: string): [string, unknown][];
24
+ /**
25
+ * Deserialize a list of [key, value] pairs into an object or array.
26
+ * The key is expressed by using bracket-notation.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const entities = [
31
+ * ['name', 'John Doe'],
32
+ * ['name[pets][0]', 'dog'],
33
+ * ['name[pets][1]', 'cat'],
34
+ * ['name[dogs][]', 'hello'],
35
+ * ['name[dogs][]', 'kitty'],
36
+ * ]
37
+ *
38
+ * const payload = deserialize(entities)
39
+ *
40
+ * expect(payload).toEqual({
41
+ * name: 'John Doe',
42
+ * pets: { 0: 'dog', 1: 'cat' },
43
+ * dogs: ['hello', 'kitty'],
44
+ * })
45
+ * ```
46
+ */
47
+ export declare function deserialize(entities: readonly (readonly [string, unknown])[]): Record<string, unknown> | unknown[] | undefined;
48
+ /**
49
+ * Escape the `[`, `]`, and `\` chars in a path segment.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * expect(escapeSegment('name[pets')).toEqual('name\\[pets')
54
+ * ```
55
+ */
56
+ export declare function escapeSegment(segment: string): string;
57
+ /**
58
+ * Convert an array of path segments into a path string using bracket-notation.
59
+ *
60
+ * For the special char `[`, `]`, and `\` will be escaped by adding `\` at start.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * expect(stringifyPath(['name', 'pets', '0'])).toEqual('name[pets][0]')
65
+ * ```
66
+ */
67
+ export declare function stringifyPath(path: readonly [string, ...string[]]): string;
68
+ /**
69
+ * Convert a path string using bracket-notation into an array of path segments.
70
+ *
71
+ * For the special char `[`, `]`, and `\` you should escape by adding `\` at start.
72
+ * It only treats a pair `[${string}]` as a path segment.
73
+ * If missing or escape it will bypass and treat as normal string.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * expect(parsePath('name[pets][0]')).toEqual(['name', 'pets', '0'])
78
+ * expect(parsePath('name[pets][0')).toEqual(['name', 'pets', '[0'])
79
+ * expect(parsePath('name[pets[0]')).toEqual(['name', 'pets[0')
80
+ * expect(parsePath('name\\[pets][0]')).toEqual(['name[pets]', '0'])
81
+ * ```
82
+ */
83
+ export declare function parsePath(path: string): [string, ...string[]];
84
+ //# sourceMappingURL=bracket-notation.d.ts.map
@@ -1,4 +1,10 @@
1
- export * from './base-handler';
2
- export * from './server-handler';
3
- export * from './serverless-handler';
1
+ export * from './bracket-notation';
2
+ export * from './input-builder-full';
3
+ export * from './input-builder-simple';
4
+ export * from './openapi-handler';
5
+ export * from './openapi-handler-server';
6
+ export * from './openapi-handler-serverless';
7
+ export * from './openapi-payload-codec';
8
+ export * from './openapi-procedure-matcher';
9
+ export * from './schema-coercer';
4
10
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Params } from 'hono/router';
2
+ export declare class InputBuilderFull {
3
+ build(params: Params, query: unknown, headers: unknown, body: unknown): {
4
+ params: Params;
5
+ query: unknown;
6
+ headers: unknown;
7
+ body: unknown;
8
+ };
9
+ }
10
+ export type PublicInputBuilderFull = Pick<InputBuilderFull, keyof InputBuilderFull>;
11
+ //# sourceMappingURL=input-builder-full.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { Params } from 'hono/router';
2
+ export declare class InputBuilderSimple {
3
+ build(params: Params, payload: unknown): unknown;
4
+ }
5
+ export type PublicInputBuilderSimple = Pick<InputBuilderSimple, keyof InputBuilderSimple>;
6
+ //# sourceMappingURL=input-builder-simple.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Context, Router } from '@orpc/server';
2
+ import type { OpenAPIHandlerOptions } from './openapi-handler';
3
+ import { OpenAPIHandler } from './openapi-handler';
4
+ export declare class OpenAPIServerHandler<T extends Context> extends OpenAPIHandler<T> {
5
+ constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
6
+ }
7
+ //# sourceMappingURL=openapi-handler-server.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Context, Router } from '@orpc/server';
2
+ import type { OpenAPIHandlerOptions } from './openapi-handler';
3
+ import { OpenAPIHandler } from './openapi-handler';
4
+ export declare class OpenAPIServerlessHandler<T extends Context> extends OpenAPIHandler<T> {
5
+ constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
6
+ }
7
+ //# sourceMappingURL=openapi-handler-serverless.d.ts.map
@@ -0,0 +1,28 @@
1
+ import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
2
+ import type { PublicInputBuilderSimple } from './input-builder-simple';
3
+ import { type Context, type Router, type WithSignal } from '@orpc/server';
4
+ import { type Hooks } from '@orpc/shared';
5
+ import { type PublicInputBuilderFull } from './input-builder-full';
6
+ import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
7
+ import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
8
+ import { type SchemaCoercer } from './schema-coercer';
9
+ export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
10
+ procedureMatcher?: PublicOpenAPIProcedureMatcher;
11
+ payloadCodec?: PublicOpenAPIPayloadCodec;
12
+ inputBuilderSimple?: PublicInputBuilderSimple;
13
+ inputBuilderFull?: PublicInputBuilderFull;
14
+ schemaCoercers?: SchemaCoercer[];
15
+ };
16
+ export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<T> {
17
+ private readonly options?;
18
+ private readonly procedureMatcher;
19
+ private readonly payloadCodec;
20
+ private readonly inputBuilderSimple;
21
+ private readonly inputBuilderFull;
22
+ private readonly compositeSchemaCoercer;
23
+ constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
24
+ condition(request: Request): boolean;
25
+ fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
26
+ private convertToORPCError;
27
+ }
28
+ //# sourceMappingURL=openapi-handler.d.ts.map
@@ -0,0 +1,13 @@
1
+ export declare class OpenAPIPayloadCodec {
2
+ encode(payload: unknown, accept?: string): {
3
+ body: FormData | Blob | string | undefined;
4
+ headers?: Headers;
5
+ };
6
+ private encodeAsJSON;
7
+ private encodeAsFormData;
8
+ private encodeAsURLSearchParams;
9
+ serialize(payload: unknown): unknown;
10
+ decode(re: Request | Response | Headers | URLSearchParams | FormData): Promise<unknown>;
11
+ }
12
+ export type PublicOpenAPIPayloadCodec = Pick<OpenAPIPayloadCodec, keyof OpenAPIPayloadCodec>;
13
+ //# sourceMappingURL=openapi-payload-codec.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { Router as BaseHono, Params } from 'hono/router';
2
+ import { type ANY_PROCEDURE, type ANY_ROUTER } from '@orpc/server';
3
+ export type Hono = BaseHono<[string, string[]]>;
4
+ export declare class OpenAPIProcedureMatcher {
5
+ private readonly hono;
6
+ private readonly router;
7
+ private pendingRouters;
8
+ constructor(hono: Hono, router: ANY_ROUTER);
9
+ match(method: string, pathname: string): Promise<{
10
+ path: string[];
11
+ procedure: ANY_PROCEDURE;
12
+ params: Params;
13
+ } | undefined>;
14
+ private add;
15
+ private handlePendingRouters;
16
+ private convertOpenAPIPathToRouterPath;
17
+ }
18
+ export type PublicOpenAPIProcedureMatcher = Pick<OpenAPIProcedureMatcher, keyof OpenAPIProcedureMatcher>;
19
+ //# sourceMappingURL=openapi-procedure-matcher.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { Schema } from '@orpc/contract';
2
+ export interface SchemaCoercer {
3
+ coerce: (schema: Schema, value: unknown) => unknown;
4
+ }
5
+ export declare class CompositeSchemaCoercer implements SchemaCoercer {
6
+ private readonly coercers;
7
+ constructor(coercers: SchemaCoercer[]);
8
+ coerce(schema: Schema, value: unknown): unknown;
9
+ }
10
+ //# sourceMappingURL=schema-coercer.d.ts.map
@@ -1,5 +1,6 @@
1
+ import type { PublicOpenAPIPayloadCodec } from './fetch';
1
2
  import { type ContractRouter } from '@orpc/contract';
2
- import { type Router } from '@orpc/server';
3
+ import { type ANY_ROUTER } from '@orpc/server';
3
4
  import { type OpenAPIObject } from 'openapi3-ts/oas31';
4
5
  export interface GenerateOpenAPIOptions {
5
6
  /**
@@ -17,8 +18,9 @@ export interface GenerateOpenAPIOptions {
17
18
  * @default false
18
19
  */
19
20
  ignoreUndefinedPathProcedures?: boolean;
21
+ payloadCodec?: PublicOpenAPIPayloadCodec;
20
22
  }
21
23
  export declare function generateOpenAPI(opts: {
22
- router: ContractRouter | Router<any>;
24
+ router: ContractRouter | ANY_ROUTER;
23
25
  } & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): Promise<OpenAPIObject>;
24
26
  //# sourceMappingURL=generator.d.ts.map
@@ -1,7 +1,7 @@
1
- import type { ContractProcedure, ContractRouter, WELL_CONTRACT_PROCEDURE } from '@orpc/contract';
2
- import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Lazy, Router } from '@orpc/server';
1
+ import type { ContractRouter, HTTPPath, WELL_CONTRACT_PROCEDURE } from '@orpc/contract';
2
+ import type { ANY_PROCEDURE, ANY_ROUTER, Lazy } from '@orpc/server';
3
3
  export interface EachLeafOptions {
4
- router: ANY_PROCEDURE | Router<any> | ContractRouter | ContractProcedure<any, any>;
4
+ router: ContractRouter | ANY_ROUTER;
5
5
  path: string[];
6
6
  }
7
7
  export interface EachLeafCallbackOptions {
@@ -9,8 +9,9 @@ export interface EachLeafCallbackOptions {
9
9
  path: string[];
10
10
  }
11
11
  export interface EachContractLeafResultItem {
12
- lazy: ANY_LAZY_PROCEDURE | Lazy<Router<any>>;
12
+ router: Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER> | ANY_PROCEDURE>;
13
13
  path: string[];
14
14
  }
15
- export declare function eachContractProcedureLeaf(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
15
+ export declare function forEachContractProcedure(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
16
+ export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
16
17
  //# sourceMappingURL=utils.d.ts.map
@@ -1,5 +1,5 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
1
2
  import { type JSONSchema } from 'json-schema-typed/draft-2020-12';
2
- import { type ZodTypeAny } from 'zod';
3
3
  export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
4
4
  export declare const UNSUPPORTED_JSON_SCHEMA: {
5
5
  not: {};
@@ -35,7 +35,7 @@ export interface ZodToJsonSchemaOptions {
35
35
  */
36
36
  isHandledCustomJSONSchema?: boolean;
37
37
  }
38
- export declare function zodToJsonSchema(schema: ZodTypeAny, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
38
+ export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
39
39
  export declare function extractJSONSchema(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): {
40
40
  schema: JSONSchema | undefined;
41
41
  matches: JSONSchema[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.0.0-next.9306271",
4
+ "version": "0.0.0-next.93e7a4c",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,18 +34,21 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
+ "@standard-schema/spec": "1.0.0-beta.4",
38
+ "@types/content-disposition": "^0.5.8",
39
+ "content-disposition": "^0.5.4",
37
40
  "escape-string-regexp": "^5.0.0",
41
+ "fast-content-type-parse": "^2.0.0",
42
+ "hono": "^4.6.12",
38
43
  "json-schema-typed": "^8.0.1",
39
44
  "openapi3-ts": "^4.4.0",
40
- "@orpc/contract": "0.0.0-next.9306271",
41
- "@orpc/transformer": "0.0.0-next.9306271",
42
- "@orpc/shared": "0.0.0-next.9306271",
43
- "@orpc/zod": "0.0.0-next.9306271",
44
- "@orpc/server": "0.0.0-next.9306271"
45
+ "wildcard-match": "^5.1.3",
46
+ "@orpc/contract": "0.0.0-next.93e7a4c",
47
+ "@orpc/shared": "0.0.0-next.93e7a4c",
48
+ "@orpc/server": "0.0.0-next.93e7a4c"
45
49
  },
46
50
  "devDependencies": {
47
51
  "@readme/openapi-parser": "^2.6.0",
48
- "hono": "^4.6.12",
49
52
  "zod": "^3.24.1"
50
53
  },
51
54
  "scripts": {