@orpc/openapi 0.12.0 → 0.13.0

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.
@@ -0,0 +1,49 @@
1
+ // src/utils.ts
2
+ import { isContractProcedure } from "@orpc/contract";
3
+ import { isLazy, isProcedure, ROUTER_CONTRACT_SYMBOL } from "@orpc/server";
4
+ function eachContractProcedureLeaf(options, callback, result = [], isCurrentRouterContract = false) {
5
+ if (!isCurrentRouterContract && ROUTER_CONTRACT_SYMBOL in options.router && options.router[ROUTER_CONTRACT_SYMBOL]) {
6
+ return eachContractProcedureLeaf(
7
+ {
8
+ path: options.path,
9
+ router: options.router[ROUTER_CONTRACT_SYMBOL]
10
+ },
11
+ callback,
12
+ result,
13
+ true
14
+ );
15
+ }
16
+ if (isLazy(options.router)) {
17
+ result.push({
18
+ lazy: options.router,
19
+ path: options.path
20
+ });
21
+ } else if (isProcedure(options.router)) {
22
+ callback({
23
+ contract: options.router.zz$p.contract,
24
+ path: options.path
25
+ });
26
+ } else if (isContractProcedure(options.router)) {
27
+ callback({
28
+ contract: options.router,
29
+ path: options.path
30
+ });
31
+ } else {
32
+ for (const key in options.router) {
33
+ eachContractProcedureLeaf(
34
+ {
35
+ router: options.router[key],
36
+ path: [...options.path, key]
37
+ },
38
+ callback,
39
+ result
40
+ );
41
+ }
42
+ }
43
+ return result;
44
+ }
45
+
46
+ export {
47
+ eachContractProcedureLeaf
48
+ };
49
+ //# sourceMappingURL=chunk-KZIT2WCV.js.map
package/dist/fetch.js CHANGED
@@ -1,6 +1,10 @@
1
+ import {
2
+ eachContractProcedureLeaf
3
+ } from "./chunk-KZIT2WCV.js";
4
+
1
5
  // src/fetch/base-handler.ts
2
6
  import { ORPC_HEADER, standardizeHTTPPath } from "@orpc/contract";
3
- import { createProcedureCaller, isProcedure, ORPCError } from "@orpc/server";
7
+ import { createProcedureCaller, isLazy, isProcedure, LAZY_LOADER_SYMBOL, LAZY_ROUTER_PREFIX_SYMBOL, ORPCError } from "@orpc/server";
4
8
  import { isPlainObject, mapValues, trim, value } from "@orpc/shared";
5
9
  import { OpenAPIDeserializer, OpenAPISerializer, zodCoerce } from "@orpc/transformer";
6
10
  function createOpenAPIHandler(createHonoRouter) {
@@ -17,12 +21,18 @@ function createOpenAPIHandler(createHonoRouter) {
17
21
  const pathname = `/${trim(url.pathname.replace(options.prefix ?? "", ""), "/")}`;
18
22
  const customMethod = options.request.method === "POST" ? url.searchParams.get("method")?.toUpperCase() : void 0;
19
23
  const method = customMethod || options.request.method;
20
- const match = resolveRouter(options.router, method, pathname);
24
+ const match = await resolveRouter(options.router, method, pathname);
21
25
  if (!match) {
22
26
  throw new ORPCError({ code: "NOT_FOUND", message: "Not found" });
23
27
  }
24
- const procedure = match.procedure;
28
+ const procedure = isLazy(match.procedure) ? (await match.procedure[LAZY_LOADER_SYMBOL]()).default : match.procedure;
25
29
  const path = match.path;
30
+ if (!isProcedure(procedure)) {
31
+ throw new ORPCError({
32
+ code: "NOT_FOUND",
33
+ message: "Not found"
34
+ });
35
+ }
26
36
  const params = procedure.zz$p.contract.zz$cp.InputSchema ? zodCoerce(
27
37
  procedure.zz$p.contract.zz$cp.InputSchema,
28
38
  match.params,
@@ -69,27 +79,44 @@ function createOpenAPIHandler(createHonoRouter) {
69
79
  };
70
80
  }
71
81
  var routingCache = /* @__PURE__ */ new Map();
82
+ var pendingCache = /* @__PURE__ */ new Map();
72
83
  function createResolveRouter(createHonoRouter) {
73
- return (router, method, pathname) => {
74
- let routing = routingCache.get(router);
75
- if (!routing) {
76
- routing = createHonoRouter();
77
- const addRouteRecursively = (routing2, router2, basePath) => {
78
- for (const key in router2) {
79
- const currentPath = [...basePath, key];
80
- const item = router2[key];
81
- if (isProcedure(item)) {
82
- const method2 = item.zz$p.contract.zz$cp.method ?? "POST";
83
- const path2 = item.zz$p.contract.zz$cp.path ? openAPIPathToRouterPath(item.zz$p.contract.zz$cp.path) : `/${currentPath.map(encodeURIComponent).join("/")}`;
84
- routing2.add(method2, path2, [currentPath, item]);
85
- } else {
86
- addRouteRecursively(routing2, item, currentPath);
87
- }
88
- }
89
- };
90
- addRouteRecursively(routing, router, []);
91
- routingCache.set(router, routing);
84
+ const addRoutes = (routing, pending, options) => {
85
+ const lazies = eachContractProcedureLeaf(options, ({ path, contract }) => {
86
+ const method = contract.zz$cp.method ?? "POST";
87
+ const httpPath = contract.zz$cp.path ? openAPIPathToRouterPath(contract.zz$cp.path) : `/${path.map(encodeURIComponent).join("/")}`;
88
+ routing.add(method, httpPath, path);
89
+ });
90
+ pending.ref.push(...lazies);
91
+ };
92
+ return async (router, method, pathname) => {
93
+ const pending = (() => {
94
+ let pending2 = pendingCache.get(router);
95
+ if (!pending2) {
96
+ pending2 = { ref: [] };
97
+ pendingCache.set(router, pending2);
98
+ }
99
+ return pending2;
100
+ })();
101
+ const routing = (() => {
102
+ let routing2 = routingCache.get(router);
103
+ if (!routing2) {
104
+ routing2 = createHonoRouter();
105
+ routingCache.set(router, routing2);
106
+ addRoutes(routing2, pending, { router, path: [] });
107
+ }
108
+ return routing2;
109
+ })();
110
+ const newPending = [];
111
+ for (const item of pending.ref) {
112
+ if (LAZY_ROUTER_PREFIX_SYMBOL in item.lazy && item.lazy[LAZY_ROUTER_PREFIX_SYMBOL] && !pathname.startsWith(item.lazy[LAZY_ROUTER_PREFIX_SYMBOL]) && !pathname.startsWith(`/${item.path.map(encodeURIComponent).join("/")}`)) {
113
+ newPending.push(item);
114
+ continue;
115
+ }
116
+ const router2 = (await item.lazy[LAZY_LOADER_SYMBOL]()).default;
117
+ addRoutes(routing, pending, { path: item.path, router: router2 });
92
118
  }
119
+ pending.ref = newPending;
93
120
  const [matches, params_] = routing.match(method, pathname);
94
121
  const [match] = matches.sort((a, b) => {
95
122
  return Object.keys(a[1]).length - Object.keys(b[1]).length;
@@ -97,18 +124,25 @@ function createResolveRouter(createHonoRouter) {
97
124
  if (!match) {
98
125
  return void 0;
99
126
  }
100
- const path = match[0][0];
101
- const procedure = match[0][1];
127
+ const path = match[0];
102
128
  const params = params_ ? mapValues(
103
129
  match[1],
104
130
  (v) => params_[v]
105
131
  ) : match[1];
106
- return {
132
+ let current = router;
133
+ for (const segment of path) {
134
+ if (typeof current !== "object" && typeof current !== "function" || !current) {
135
+ current = void 0;
136
+ break;
137
+ }
138
+ current = current[segment];
139
+ }
140
+ return isProcedure(current) || isLazy(current) ? {
107
141
  path,
108
- procedure,
142
+ procedure: current,
109
143
  params: { ...params }
110
144
  // params from hono not a normal object, so we need spread here
111
- };
145
+ } : void 0;
112
146
  };
113
147
  }
114
148
  function mergeParamsAndInput(coercedParams, input) {
@@ -666,3 +700,4 @@ export {
666
700
  createResolveRouter,
667
701
  openAPIPathToRouterPath
668
702
  };
703
+ //# sourceMappingURL=fetch.js.map
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
+ import {
2
+ eachContractProcedureLeaf
3
+ } from "./chunk-KZIT2WCV.js";
4
+
1
5
  // src/generator.ts
2
- import { eachContractRouterLeaf } from "@orpc/contract";
3
- import { toContractRouter } from "@orpc/server";
6
+ import { isContractProcedure } from "@orpc/contract";
7
+ import { LAZY_LOADER_SYMBOL } from "@orpc/server";
4
8
  import { findDeepMatches, isPlainObject, omit } from "@orpc/shared";
5
9
  import { preSerialize } from "@orpc/transformer";
6
10
  import {
@@ -4210,7 +4214,7 @@ function extractJSONSchema(schema, check, matches = []) {
4210
4214
  }
4211
4215
 
4212
4216
  // src/generator.ts
4213
- function generateOpenAPI(opts, options) {
4217
+ async function generateOpenAPI(opts, options) {
4214
4218
  const throwOnMissingTagDefinition = options?.throwOnMissingTagDefinition ?? false;
4215
4219
  const ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
4216
4220
  const builder = new OpenApiBuilder({
@@ -4218,197 +4222,212 @@ function generateOpenAPI(opts, options) {
4218
4222
  openapi: "3.1.0"
4219
4223
  });
4220
4224
  const rootTags = opts.tags?.map((tag) => tag.name) ?? [];
4221
- const router = toContractRouter(opts.router);
4222
- eachContractRouterLeaf(router, (procedure, path_) => {
4223
- const internal = procedure.zz$cp;
4224
- if (ignoreUndefinedPathProcedures && internal.path === void 0) {
4225
- return;
4226
- }
4227
- const path = internal.path ?? `/${path_.map(encodeURIComponent).join("/")}`;
4228
- const method = internal.method ?? "POST";
4229
- let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
4230
- const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
4231
- const params = (() => {
4232
- const names = path.match(/\{([^}]+)\}/g);
4233
- if (!names || !names.length) {
4234
- return void 0;
4225
+ const pending = [{
4226
+ path: [],
4227
+ router: opts.router
4228
+ }];
4229
+ for (const item of pending) {
4230
+ const lazies = eachContractProcedureLeaf(item, ({ contract, path }) => {
4231
+ if (!isContractProcedure(contract)) {
4232
+ return;
4235
4233
  }
4236
- if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4237
- throw new Error(
4238
- `When path has parameters, input schema must be an object [${path_.join(".")}]`
4239
- );
4234
+ const internal = contract.zz$cp;
4235
+ if (ignoreUndefinedPathProcedures && internal.path === void 0) {
4236
+ return;
4240
4237
  }
4241
- return names.map((raw) => raw.slice(1, -1)).map((name) => {
4242
- let schema = inputSchema.properties?.[name];
4243
- const required = inputSchema.required?.includes(name);
4244
- if (schema === void 0) {
4245
- throw new Error(
4246
- `Parameter ${name} is missing in input schema [${path_.join(".")}]`
4247
- );
4238
+ const httpPath = internal.path ?? `/${path.map(encodeURIComponent).join("/")}`;
4239
+ const method = internal.method ?? "POST";
4240
+ let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
4241
+ const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
4242
+ const params = (() => {
4243
+ const names = httpPath.match(/\{([^}]+)\}/g);
4244
+ if (!names || !names.length) {
4245
+ return void 0;
4248
4246
  }
4249
- if (!required) {
4247
+ if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4250
4248
  throw new Error(
4251
- `Parameter ${name} must be required in input schema [${path_.join(".")}]`
4249
+ `When path has parameters, input schema must be an object [${path.join(".")}]`
4252
4250
  );
4253
4251
  }
4254
- const examples = inputSchema.examples?.filter((example) => {
4255
- return isPlainObject(example) && name in example;
4256
- }).map((example) => {
4257
- return example[name];
4258
- });
4259
- schema = {
4260
- examples: examples?.length ? examples : void 0,
4261
- ...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
4262
- };
4263
- inputSchema = {
4264
- ...inputSchema,
4265
- properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
4266
- (acc, [key, value]) => {
4267
- if (key !== name) {
4268
- acc[key] = value;
4269
- }
4270
- return acc;
4271
- },
4272
- {}
4273
- ) : void 0,
4274
- required: inputSchema.required?.filter((v) => v !== name),
4275
- examples: inputSchema.examples?.map((example) => {
4276
- if (!isPlainObject(example))
4277
- return example;
4278
- return Object.entries(example).reduce(
4279
- (acc, [key, value]) => {
4280
- if (key !== name) {
4281
- acc[key] = value;
4282
- }
4283
- return acc;
4284
- },
4285
- {}
4252
+ return names.map((raw) => raw.slice(1, -1)).map((name) => {
4253
+ let schema = inputSchema.properties?.[name];
4254
+ const required = inputSchema.required?.includes(name);
4255
+ if (schema === void 0) {
4256
+ throw new Error(
4257
+ `Parameter ${name} is missing in input schema [${path.join(".")}]`
4286
4258
  );
4287
- })
4288
- };
4289
- return {
4290
- name,
4291
- in: "path",
4292
- required: true,
4293
- schema,
4294
- example: internal.inputExample?.[name]
4295
- };
4296
- });
4297
- })();
4298
- const query = (() => {
4299
- if (method !== "GET" || Object.keys(inputSchema).length === 0) {
4300
- return void 0;
4301
- }
4302
- if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4303
- throw new Error(
4304
- `When method is GET, input schema must be an object [${path_.join(".")}]`
4305
- );
4306
- }
4307
- return Object.entries(inputSchema.properties ?? {}).map(
4308
- ([name, schema]) => {
4259
+ }
4260
+ if (!required) {
4261
+ throw new Error(
4262
+ `Parameter ${name} must be required in input schema [${path.join(".")}]`
4263
+ );
4264
+ }
4309
4265
  const examples = inputSchema.examples?.filter((example) => {
4310
4266
  return isPlainObject(example) && name in example;
4311
4267
  }).map((example) => {
4312
4268
  return example[name];
4313
4269
  });
4314
- const schema_ = {
4270
+ schema = {
4315
4271
  examples: examples?.length ? examples : void 0,
4316
4272
  ...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
4317
4273
  };
4274
+ inputSchema = {
4275
+ ...inputSchema,
4276
+ properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
4277
+ (acc, [key, value]) => {
4278
+ if (key !== name) {
4279
+ acc[key] = value;
4280
+ }
4281
+ return acc;
4282
+ },
4283
+ {}
4284
+ ) : void 0,
4285
+ required: inputSchema.required?.filter((v) => v !== name),
4286
+ examples: inputSchema.examples?.map((example) => {
4287
+ if (!isPlainObject(example))
4288
+ return example;
4289
+ return Object.entries(example).reduce(
4290
+ (acc, [key, value]) => {
4291
+ if (key !== name) {
4292
+ acc[key] = value;
4293
+ }
4294
+ return acc;
4295
+ },
4296
+ {}
4297
+ );
4298
+ })
4299
+ };
4318
4300
  return {
4319
4301
  name,
4320
- in: "query",
4321
- style: "deepObject",
4322
- required: inputSchema?.required?.includes(name) ?? false,
4323
- schema: schema_,
4302
+ in: "path",
4303
+ required: true,
4304
+ schema,
4324
4305
  example: internal.inputExample?.[name]
4325
4306
  };
4307
+ });
4308
+ })();
4309
+ const query = (() => {
4310
+ if (method !== "GET" || Object.keys(inputSchema).length === 0) {
4311
+ return void 0;
4326
4312
  }
4327
- );
4328
- })();
4329
- const parameters = [...params ?? [], ...query ?? []];
4330
- const requestBody = (() => {
4331
- if (method === "GET") {
4332
- return void 0;
4333
- }
4334
- const { schema, matches } = extractJSONSchema(inputSchema, isFileSchema);
4335
- const files = matches;
4336
- const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4337
- if (files.length) {
4338
- parameters.push({
4339
- name: "content-disposition",
4340
- in: "header",
4341
- required: schema === void 0,
4342
- schema: {
4343
- type: "string",
4344
- pattern: "filename",
4345
- example: 'filename="file.png"',
4346
- description: "To define the file name. Required when the request body is a file."
4313
+ if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
4314
+ throw new Error(
4315
+ `When method is GET, input schema must be an object [${path.join(".")}]`
4316
+ );
4317
+ }
4318
+ return Object.entries(inputSchema.properties ?? {}).map(
4319
+ ([name, schema]) => {
4320
+ const examples = inputSchema.examples?.filter((example) => {
4321
+ return isPlainObject(example) && name in example;
4322
+ }).map((example) => {
4323
+ return example[name];
4324
+ });
4325
+ const schema_ = {
4326
+ examples: examples?.length ? examples : void 0,
4327
+ ...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
4328
+ };
4329
+ return {
4330
+ name,
4331
+ in: "query",
4332
+ style: "deepObject",
4333
+ required: inputSchema?.required?.includes(name) ?? false,
4334
+ schema: schema_,
4335
+ example: internal.inputExample?.[name]
4336
+ };
4347
4337
  }
4348
- });
4349
- }
4350
- const content = {};
4351
- for (const file of files) {
4352
- content[file.contentMediaType] = {
4353
- schema: file
4354
- };
4355
- }
4356
- if (schema !== void 0) {
4357
- content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4358
- schema,
4359
- example: internal.inputExample
4360
- };
4361
- }
4362
- return {
4363
- required: Boolean(internal.InputSchema?.isOptional()),
4364
- content
4365
- };
4366
- })();
4367
- const successResponse = (() => {
4368
- const { schema, matches } = extractJSONSchema(outputSchema, isFileSchema);
4369
- const files = matches;
4370
- const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4371
- const content = {};
4372
- for (const file of files) {
4373
- content[file.contentMediaType] = {
4374
- schema: file
4338
+ );
4339
+ })();
4340
+ const parameters = [...params ?? [], ...query ?? []];
4341
+ const requestBody = (() => {
4342
+ if (method === "GET") {
4343
+ return void 0;
4344
+ }
4345
+ const { schema, matches } = extractJSONSchema(inputSchema, isFileSchema);
4346
+ const files = matches;
4347
+ const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4348
+ if (files.length) {
4349
+ parameters.push({
4350
+ name: "content-disposition",
4351
+ in: "header",
4352
+ required: schema === void 0,
4353
+ schema: {
4354
+ type: "string",
4355
+ pattern: "filename",
4356
+ example: 'filename="file.png"',
4357
+ description: "To define the file name. Required when the request body is a file."
4358
+ }
4359
+ });
4360
+ }
4361
+ const content = {};
4362
+ for (const file of files) {
4363
+ content[file.contentMediaType] = {
4364
+ schema: file
4365
+ };
4366
+ }
4367
+ if (schema !== void 0) {
4368
+ content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4369
+ schema,
4370
+ example: internal.inputExample
4371
+ };
4372
+ }
4373
+ return {
4374
+ required: Boolean(internal.InputSchema?.isOptional()),
4375
+ content
4375
4376
  };
4376
- }
4377
- if (schema !== void 0) {
4378
- content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4379
- schema,
4380
- example: internal.outputExample
4377
+ })();
4378
+ const successResponse = (() => {
4379
+ const { schema, matches } = extractJSONSchema(outputSchema, isFileSchema);
4380
+ const files = matches;
4381
+ const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
4382
+ const content = {};
4383
+ for (const file of files) {
4384
+ content[file.contentMediaType] = {
4385
+ schema: file
4386
+ };
4387
+ }
4388
+ if (schema !== void 0) {
4389
+ content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
4390
+ schema,
4391
+ example: internal.outputExample
4392
+ };
4393
+ }
4394
+ return {
4395
+ description: "OK",
4396
+ content
4381
4397
  };
4398
+ })();
4399
+ if (throwOnMissingTagDefinition && internal.tags) {
4400
+ const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
4401
+ if (missingTag !== void 0) {
4402
+ throw new Error(
4403
+ `Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
4404
+ );
4405
+ }
4382
4406
  }
4383
- return {
4384
- description: "OK",
4385
- content
4407
+ const operation = {
4408
+ summary: internal.summary,
4409
+ description: internal.description,
4410
+ deprecated: internal.deprecated,
4411
+ tags: internal.tags,
4412
+ operationId: path.join("."),
4413
+ parameters: parameters.length ? parameters : void 0,
4414
+ requestBody,
4415
+ responses: {
4416
+ 200: successResponse
4417
+ }
4386
4418
  };
4387
- })();
4388
- if (throwOnMissingTagDefinition && internal.tags) {
4389
- const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
4390
- if (missingTag !== void 0) {
4391
- throw new Error(
4392
- `Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path_.join(".")}]`
4393
- );
4394
- }
4395
- }
4396
- const operation = {
4397
- summary: internal.summary,
4398
- description: internal.description,
4399
- deprecated: internal.deprecated,
4400
- tags: internal.tags,
4401
- operationId: path_.join("."),
4402
- parameters: parameters.length ? parameters : void 0,
4403
- requestBody,
4404
- responses: {
4405
- 200: successResponse
4406
- }
4407
- };
4408
- builder.addPath(path, {
4409
- [method.toLocaleLowerCase()]: operation
4419
+ builder.addPath(httpPath, {
4420
+ [method.toLocaleLowerCase()]: operation
4421
+ });
4410
4422
  });
4411
- });
4423
+ for (const lazy of lazies) {
4424
+ const router = (await lazy.lazy[LAZY_LOADER_SYMBOL]()).default;
4425
+ pending.push({
4426
+ path: lazy.path,
4427
+ router
4428
+ });
4429
+ }
4430
+ }
4412
4431
  return preSerialize(builder.getSpec());
4413
4432
  }
4414
4433
  function isFileSchema(schema) {
@@ -4419,3 +4438,4 @@ function isFileSchema(schema) {
4419
4438
  export {
4420
4439
  generateOpenAPI
4421
4440
  };
4441
+ //# sourceMappingURL=index.js.map
@@ -1,14 +1,15 @@
1
1
  import type { HTTPPath } from '@orpc/contract';
2
+ import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Router } from '@orpc/server';
2
3
  import type { FetchHandler } from '@orpc/server/fetch';
3
4
  import type { Router as HonoRouter } from 'hono/router';
4
- import { type Procedure, type Router } from '@orpc/server';
5
- export type ResolveRouter = (router: Router<any>, method: string, pathname: string) => {
5
+ export type ResolveRouter = (router: Router<any>, method: string, pathname: string) => Promise<{
6
6
  path: string[];
7
- procedure: Procedure<any, any, any, any, any>;
7
+ procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE;
8
8
  params: Record<string, string>;
9
- } | undefined;
10
- type Routing = HonoRouter<[string[], Procedure<any, any, any, any, any>]>;
9
+ } | undefined>;
10
+ type Routing = HonoRouter<string[]>;
11
11
  export declare function createOpenAPIHandler(createHonoRouter: () => Routing): FetchHandler;
12
12
  export declare function createResolveRouter(createHonoRouter: () => Routing): ResolveRouter;
13
13
  export declare function openAPIPathToRouterPath(path: HTTPPath): string;
14
14
  export {};
15
+ //# sourceMappingURL=base-handler.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export * from './base-handler';
2
2
  export * from './server-handler';
3
3
  export * from './serverless-handler';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { FetchHandler } from '@orpc/server/fetch';
2
2
  export declare function createOpenAPIServerHandler(): FetchHandler;
3
+ //# sourceMappingURL=server-handler.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { FetchHandler } from '@orpc/server/fetch';
2
2
  export declare function createOpenAPIServerlessHandler(): FetchHandler;
3
+ //# sourceMappingURL=serverless-handler.d.ts.map
@@ -20,4 +20,5 @@ export interface GenerateOpenAPIOptions {
20
20
  }
21
21
  export declare function generateOpenAPI(opts: {
22
22
  router: ContractRouter | Router<any>;
23
- } & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): OpenAPIObject;
23
+ } & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): Promise<OpenAPIObject>;
24
+ //# sourceMappingURL=generator.d.ts.map
@@ -1,2 +1,3 @@
1
1
  /** unnoq */
2
2
  export * from './generator';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { ContractProcedure, ContractRouter, WELL_CONTRACT_PROCEDURE } from '@orpc/contract';
2
+ import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Lazy, Router } from '@orpc/server';
3
+ export interface EachLeafOptions {
4
+ router: ANY_PROCEDURE | Router<any> | ContractRouter | ContractProcedure<any, any>;
5
+ path: string[];
6
+ }
7
+ export interface EachLeafCallbackOptions {
8
+ contract: WELL_CONTRACT_PROCEDURE;
9
+ path: string[];
10
+ }
11
+ export interface EachContractLeafResultItem {
12
+ lazy: ANY_LAZY_PROCEDURE | Lazy<Router<any>>;
13
+ path: string[];
14
+ }
15
+ export declare function eachContractProcedureLeaf(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
16
+ //# sourceMappingURL=utils.d.ts.map
@@ -40,3 +40,4 @@ export declare function extractJSONSchema(schema: JSONSchema, check: (schema: JS
40
40
  schema: JSONSchema | undefined;
41
41
  matches: JSONSchema[];
42
42
  };
43
+ //# sourceMappingURL=zod-to-json-schema.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.12.0",
4
+ "version": "0.13.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,18 +29,19 @@
29
29
  }
30
30
  },
31
31
  "files": [
32
- "!dist/*.tsbuildinfo",
32
+ "!**/*.map",
33
+ "!**/*.tsbuildinfo",
33
34
  "dist"
34
35
  ],
35
36
  "dependencies": {
36
37
  "escape-string-regexp": "^5.0.0",
37
38
  "json-schema-typed": "^8.0.1",
38
39
  "openapi3-ts": "^4.4.0",
39
- "@orpc/contract": "0.12.0",
40
- "@orpc/transformer": "0.12.0",
41
- "@orpc/server": "0.12.0",
42
- "@orpc/shared": "0.12.0",
43
- "@orpc/zod": "0.12.0"
40
+ "@orpc/contract": "0.13.0",
41
+ "@orpc/shared": "0.13.0",
42
+ "@orpc/server": "0.13.0",
43
+ "@orpc/transformer": "0.13.0",
44
+ "@orpc/zod": "0.13.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@readme/openapi-parser": "^2.6.0",
@@ -48,7 +49,7 @@
48
49
  "zod": "^3.23.8"
49
50
  },
50
51
  "scripts": {
51
- "build": "tsup --clean --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
52
+ "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
52
53
  "build:watch": "pnpm run build --watch",
53
54
  "type:check": "tsc -b"
54
55
  }