@orpc/openapi 0.16.0 → 0.18.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.
- package/dist/chunk-UPDKQRQG.js +665 -0
- package/dist/fetch.js +27 -704
- package/dist/index.js +51 -27
- package/dist/src/fetch/bracket-notation.d.ts +84 -0
- package/dist/src/fetch/index.d.ts +9 -3
- package/dist/src/fetch/input-builder-full.d.ts +11 -0
- package/dist/src/fetch/input-builder-simple.d.ts +6 -0
- package/dist/src/fetch/openapi-handler-server.d.ts +7 -0
- package/dist/src/fetch/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/fetch/openapi-handler.d.ts +28 -0
- package/dist/src/fetch/openapi-payload-codec.d.ts +13 -0
- package/dist/src/fetch/openapi-procedure-matcher.d.ts +19 -0
- package/dist/src/fetch/schema-coercer.d.ts +10 -0
- package/dist/src/generator.d.ts +4 -2
- package/dist/src/utils.d.ts +6 -5
- package/package.json +9 -7
- package/dist/chunk-KZIT2WCV.js +0 -49
- package/dist/src/fetch/base-handler.d.ts +0 -15
- package/dist/src/fetch/server-handler.d.ts +0 -3
- package/dist/src/fetch/serverless-handler.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
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 {
|
|
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/
|
|
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",
|
|
@@ -4358,6 +4381,7 @@ function extractJSONSchema(schema, check, matches = []) {
|
|
|
4358
4381
|
async function generateOpenAPI(opts, options) {
|
|
4359
4382
|
const throwOnMissingTagDefinition = options?.throwOnMissingTagDefinition ?? false;
|
|
4360
4383
|
const ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
4384
|
+
const payloadCodec = options?.payloadCodec ?? new OpenAPIPayloadCodec();
|
|
4361
4385
|
const builder = new OpenApiBuilder({
|
|
4362
4386
|
...omit(opts, ["router"]),
|
|
4363
4387
|
openapi: "3.1.0"
|
|
@@ -4368,16 +4392,16 @@ async function generateOpenAPI(opts, options) {
|
|
|
4368
4392
|
router: opts.router
|
|
4369
4393
|
}];
|
|
4370
4394
|
for (const item of pending) {
|
|
4371
|
-
const lazies =
|
|
4395
|
+
const lazies = forEachContractProcedure(item, ({ contract, path }) => {
|
|
4372
4396
|
if (!isContractProcedure(contract)) {
|
|
4373
4397
|
return;
|
|
4374
4398
|
}
|
|
4375
|
-
const internal = contract
|
|
4376
|
-
if (ignoreUndefinedPathProcedures && internal.path === void 0) {
|
|
4399
|
+
const internal = contract["~orpc"];
|
|
4400
|
+
if (ignoreUndefinedPathProcedures && internal.route?.path === void 0) {
|
|
4377
4401
|
return;
|
|
4378
4402
|
}
|
|
4379
|
-
const httpPath = internal.path
|
|
4380
|
-
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";
|
|
4381
4405
|
let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
|
|
4382
4406
|
const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
|
|
4383
4407
|
const params = (() => {
|
|
@@ -4539,8 +4563,8 @@ async function generateOpenAPI(opts, options) {
|
|
|
4539
4563
|
content
|
|
4540
4564
|
};
|
|
4541
4565
|
})();
|
|
4542
|
-
if (throwOnMissingTagDefinition && internal.tags) {
|
|
4543
|
-
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));
|
|
4544
4568
|
if (missingTag !== void 0) {
|
|
4545
4569
|
throw new Error(
|
|
4546
4570
|
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
|
|
@@ -4548,10 +4572,10 @@ async function generateOpenAPI(opts, options) {
|
|
|
4548
4572
|
}
|
|
4549
4573
|
}
|
|
4550
4574
|
const operation = {
|
|
4551
|
-
summary: internal.summary,
|
|
4552
|
-
description: internal.description,
|
|
4553
|
-
deprecated: internal.deprecated,
|
|
4554
|
-
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,
|
|
4555
4579
|
operationId: path.join("."),
|
|
4556
4580
|
parameters: parameters.length ? parameters : void 0,
|
|
4557
4581
|
requestBody,
|
|
@@ -4564,14 +4588,14 @@ async function generateOpenAPI(opts, options) {
|
|
|
4564
4588
|
});
|
|
4565
4589
|
});
|
|
4566
4590
|
for (const lazy of lazies) {
|
|
4567
|
-
const router =
|
|
4591
|
+
const { default: router } = await unlazy(lazy.router);
|
|
4568
4592
|
pending.push({
|
|
4569
4593
|
path: lazy.path,
|
|
4570
4594
|
router
|
|
4571
4595
|
});
|
|
4572
4596
|
}
|
|
4573
4597
|
}
|
|
4574
|
-
return
|
|
4598
|
+
return payloadCodec.serialize(builder.getSpec());
|
|
4575
4599
|
}
|
|
4576
4600
|
function isFileSchema(schema) {
|
|
4577
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 './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
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
|
package/dist/src/generator.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { PublicOpenAPIPayloadCodec } from './fetch';
|
|
1
2
|
import { type ContractRouter } from '@orpc/contract';
|
|
2
|
-
import { type
|
|
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 |
|
|
24
|
+
router: ContractRouter | ANY_ROUTER;
|
|
23
25
|
} & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): Promise<OpenAPIObject>;
|
|
24
26
|
//# sourceMappingURL=generator.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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:
|
|
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
|
-
|
|
12
|
+
router: Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER> | ANY_PROCEDURE>;
|
|
13
13
|
path: string[];
|
|
14
14
|
}
|
|
15
|
-
export declare function
|
|
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
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -35,18 +35,20 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@standard-schema/spec": "1.0.0-beta.4",
|
|
38
|
+
"@types/content-disposition": "^0.5.8",
|
|
39
|
+
"content-disposition": "^0.5.4",
|
|
38
40
|
"escape-string-regexp": "^5.0.0",
|
|
41
|
+
"fast-content-type-parse": "^2.0.0",
|
|
42
|
+
"hono": "^4.6.12",
|
|
39
43
|
"json-schema-typed": "^8.0.1",
|
|
40
44
|
"openapi3-ts": "^4.4.0",
|
|
41
|
-
"
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/
|
|
45
|
-
"@orpc/zod": "0.16.0"
|
|
45
|
+
"wildcard-match": "^5.1.3",
|
|
46
|
+
"@orpc/shared": "0.18.0",
|
|
47
|
+
"@orpc/contract": "0.18.0",
|
|
48
|
+
"@orpc/server": "0.18.0"
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
51
|
"@readme/openapi-parser": "^2.6.0",
|
|
49
|
-
"hono": "^4.6.12",
|
|
50
52
|
"zod": "^3.24.1"
|
|
51
53
|
},
|
|
52
54
|
"scripts": {
|
package/dist/chunk-KZIT2WCV.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
|
2
|
-
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Router } from '@orpc/server';
|
|
3
|
-
import type { FetchHandler } from '@orpc/server/fetch';
|
|
4
|
-
import type { Router as HonoRouter } from 'hono/router';
|
|
5
|
-
export type ResolveRouter = (router: Router<any>, method: string, pathname: string) => Promise<{
|
|
6
|
-
path: string[];
|
|
7
|
-
procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE;
|
|
8
|
-
params: Record<string, string>;
|
|
9
|
-
} | undefined>;
|
|
10
|
-
type Routing = HonoRouter<string[]>;
|
|
11
|
-
export declare function createOpenAPIHandler(createHonoRouter: () => Routing): FetchHandler;
|
|
12
|
-
export declare function createResolveRouter(createHonoRouter: () => Routing): ResolveRouter;
|
|
13
|
-
export declare function openAPIPathToRouterPath(path: HTTPPath): string;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=base-handler.d.ts.map
|