@orpc/openapi 0.0.0-next.ee0aeaf → 0.0.0-next.f99e554
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-KNYXLM77.js +107 -0
- package/dist/chunk-YXHH6XHB.js +642 -0
- package/dist/fetch.js +37 -698
- package/dist/index.js +391 -4486
- package/dist/node.js +46 -0
- package/dist/src/adapters/fetch/bracket-notation.d.ts +84 -0
- package/dist/src/adapters/fetch/index.d.ts +10 -0
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +6 -0
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +11 -0
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +7 -0
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/adapters/fetch/openapi-handler.d.ts +33 -0
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +15 -0
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +19 -0
- package/dist/src/adapters/fetch/schema-coercer.d.ts +10 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/openapi-handler-server.d.ts +7 -0
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/adapters/node/openapi-handler.d.ts +12 -0
- package/dist/src/adapters/node/types.d.ts +2 -0
- package/dist/src/index.d.ts +10 -1
- package/dist/src/json-serializer.d.ts +5 -0
- package/dist/src/openapi-content-builder.d.ts +10 -0
- package/dist/src/openapi-error.d.ts +3 -0
- package/dist/src/openapi-generator.d.ts +60 -0
- package/dist/src/openapi-input-structure-parser.d.ts +22 -0
- package/dist/src/openapi-output-structure-parser.d.ts +18 -0
- package/dist/src/openapi-parameters-builder.d.ts +12 -0
- package/dist/src/openapi-path-parser.d.ts +8 -0
- package/dist/src/openapi.d.ts +3 -0
- package/dist/src/schema-converter.d.ts +16 -0
- package/dist/src/schema-utils.d.ts +11 -0
- package/dist/src/schema.d.ts +12 -0
- package/dist/src/utils.d.ts +6 -5
- package/package.json +17 -9
- package/dist/chunk-7HD5IZWG.js +0 -53
- package/dist/src/fetch/base-handler.d.ts +0 -13
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/server-handler.d.ts +0 -3
- package/dist/src/fetch/serverless-handler.d.ts +0 -3
- package/dist/src/generator.d.ts +0 -24
- package/dist/src/zod-to-json-schema.d.ts +0 -43
package/dist/node.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-YXHH6XHB.js";
|
|
4
|
+
import "./chunk-KNYXLM77.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/node/openapi-handler.ts
|
|
7
|
+
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
8
|
+
import { ORPC_HANDLER_HEADER } from "@orpc/shared";
|
|
9
|
+
var OpenAPIHandler2 = class {
|
|
10
|
+
openapiFetchHandler;
|
|
11
|
+
constructor(hono, router, options) {
|
|
12
|
+
this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
|
|
13
|
+
}
|
|
14
|
+
condition(request) {
|
|
15
|
+
return request.headers[ORPC_HANDLER_HEADER] === void 0;
|
|
16
|
+
}
|
|
17
|
+
async handle(req, res, ...[options]) {
|
|
18
|
+
const request = createRequest(req, res, options);
|
|
19
|
+
const castedOptions = options ?? {};
|
|
20
|
+
const response = await this.openapiFetchHandler.fetch(request, castedOptions);
|
|
21
|
+
await options?.beforeSend?.(response, castedOptions.context);
|
|
22
|
+
return await sendResponse(res, response);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/adapters/node/openapi-handler-server.ts
|
|
27
|
+
import { TrieRouter } from "hono/router/trie-router";
|
|
28
|
+
var OpenAPIServerHandler = class extends OpenAPIHandler2 {
|
|
29
|
+
constructor(router, options) {
|
|
30
|
+
super(new TrieRouter(), router, options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/adapters/node/openapi-handler-serverless.ts
|
|
35
|
+
import { LinearRouter } from "hono/router/linear-router";
|
|
36
|
+
var OpenAPIServerlessHandler = class extends OpenAPIHandler2 {
|
|
37
|
+
constructor(router, options) {
|
|
38
|
+
super(new LinearRouter(), router, options);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
OpenAPIHandler2 as OpenAPIHandler,
|
|
43
|
+
OpenAPIServerHandler,
|
|
44
|
+
OpenAPIServerlessHandler
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './bracket-notation';
|
|
2
|
+
export * from './input-structure-compact';
|
|
3
|
+
export * from './input-structure-detailed';
|
|
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';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Params } from 'hono/router';
|
|
2
|
+
export declare class InputStructureCompact {
|
|
3
|
+
build(params: Params, payload: unknown): unknown;
|
|
4
|
+
}
|
|
5
|
+
export type PublicInputStructureCompact = Pick<InputStructureCompact, keyof InputStructureCompact>;
|
|
6
|
+
//# sourceMappingURL=input-structure-compact.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Params } from 'hono/router';
|
|
2
|
+
export declare class InputStructureDetailed {
|
|
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 PublicInputStructureDetailed = Pick<InputStructureDetailed, keyof InputStructureDetailed>;
|
|
11
|
+
//# sourceMappingURL=input-structure-detailed.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,33 @@
|
|
|
1
|
+
import type { Context, Router, WithSignal } from '@orpc/server';
|
|
2
|
+
import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
|
|
3
|
+
import type { PublicInputStructureCompact } from './input-structure-compact';
|
|
4
|
+
import { type Hooks } from '@orpc/shared';
|
|
5
|
+
import { type PublicJSONSerializer } from '../../json-serializer';
|
|
6
|
+
import { type PublicInputStructureDetailed } from './input-structure-detailed';
|
|
7
|
+
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
8
|
+
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
9
|
+
import { type SchemaCoercer } from './schema-coercer';
|
|
10
|
+
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
|
|
11
|
+
jsonSerializer?: PublicJSONSerializer;
|
|
12
|
+
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
|
+
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
14
|
+
inputBuilderSimple?: PublicInputStructureCompact;
|
|
15
|
+
inputBuilderFull?: PublicInputStructureDetailed;
|
|
16
|
+
schemaCoercers?: SchemaCoercer[];
|
|
17
|
+
};
|
|
18
|
+
export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<T> {
|
|
19
|
+
private readonly options?;
|
|
20
|
+
private readonly procedureMatcher;
|
|
21
|
+
private readonly payloadCodec;
|
|
22
|
+
private readonly inputStructureCompact;
|
|
23
|
+
private readonly inputStructureDetailed;
|
|
24
|
+
private readonly compositeSchemaCoercer;
|
|
25
|
+
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
|
|
26
|
+
condition(request: Request): boolean;
|
|
27
|
+
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
|
28
|
+
private decodeInput;
|
|
29
|
+
private encodeOutput;
|
|
30
|
+
private assertDetailedOutput;
|
|
31
|
+
private convertToORPCError;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PublicJSONSerializer } from '../../json-serializer';
|
|
2
|
+
export declare class OpenAPIPayloadCodec {
|
|
3
|
+
private readonly jsonSerializer;
|
|
4
|
+
constructor(jsonSerializer: PublicJSONSerializer);
|
|
5
|
+
encode(payload: unknown, accept: string | undefined): {
|
|
6
|
+
body: FormData | Blob | string | undefined;
|
|
7
|
+
headers?: Headers;
|
|
8
|
+
};
|
|
9
|
+
private encodeAsJSON;
|
|
10
|
+
private encodeAsFormData;
|
|
11
|
+
private encodeAsURLSearchParams;
|
|
12
|
+
decode(re: Request | Response | Headers | URLSearchParams | FormData): Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
export type PublicOpenAPIPayloadCodec = Pick<OpenAPIPayloadCodec, keyof OpenAPIPayloadCodec>;
|
|
15
|
+
//# 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
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { OpenAPIHandlerOptions } from '../fetch/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 '../fetch/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,12 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { ConditionalRequestHandler, RequestOptions } from '@orpc/server/node';
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
5
|
+
import type { Hono } from '../fetch/openapi-procedure-matcher';
|
|
6
|
+
export declare class OpenAPIHandler<T extends Context> implements ConditionalRequestHandler<T> {
|
|
7
|
+
private readonly openapiFetchHandler;
|
|
8
|
+
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
condition(request: IncomingMessage): boolean;
|
|
10
|
+
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './json-serializer';
|
|
3
|
+
export * from './openapi';
|
|
4
|
+
export * from './openapi-content-builder';
|
|
5
|
+
export * from './openapi-generator';
|
|
6
|
+
export * from './openapi-parameters-builder';
|
|
7
|
+
export * from './openapi-path-parser';
|
|
8
|
+
export * from './schema';
|
|
9
|
+
export * from './schema-converter';
|
|
10
|
+
export * from './schema-utils';
|
|
11
|
+
export * from './utils';
|
|
3
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OpenAPI } from './openapi';
|
|
2
|
+
import type { JSONSchema } from './schema';
|
|
3
|
+
import type { PublicSchemaUtils } from './schema-utils';
|
|
4
|
+
export declare class OpenAPIContentBuilder {
|
|
5
|
+
private readonly schemaUtils;
|
|
6
|
+
constructor(schemaUtils: PublicSchemaUtils);
|
|
7
|
+
build(jsonSchema: JSONSchema.JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
|
|
8
|
+
}
|
|
9
|
+
export type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
|
|
10
|
+
//# sourceMappingURL=openapi-content-builder.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ContractRouter } from '@orpc/contract';
|
|
2
|
+
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
|
+
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
4
|
+
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
5
|
+
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
6
|
+
import type { SchemaConverter } from './schema-converter';
|
|
7
|
+
import { type PublicJSONSerializer } from './json-serializer';
|
|
8
|
+
import { type OpenAPI } from './openapi';
|
|
9
|
+
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
10
|
+
import { type PublicOpenAPIParametersBuilder } from './openapi-parameters-builder';
|
|
11
|
+
import { type PublicSchemaUtils } from './schema-utils';
|
|
12
|
+
type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
|
|
13
|
+
export interface OpenAPIGeneratorOptions {
|
|
14
|
+
contentBuilder?: PublicOpenAPIContentBuilder;
|
|
15
|
+
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
|
16
|
+
schemaConverters?: SchemaConverter[];
|
|
17
|
+
schemaUtils?: PublicSchemaUtils;
|
|
18
|
+
jsonSerializer?: PublicJSONSerializer;
|
|
19
|
+
pathParser?: PublicOpenAPIPathParser;
|
|
20
|
+
inputStructureParser?: PublicOpenAPIInputStructureParser;
|
|
21
|
+
outputStructureParser?: PublicOpenAPIOutputStructureParser;
|
|
22
|
+
/**
|
|
23
|
+
* Throw error when you missing define tag definition on OpenAPI root tags
|
|
24
|
+
*
|
|
25
|
+
* Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
|
|
26
|
+
* Because OpenAPI root tags is missing 'bar' tag
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
considerMissingTagDefinitionAsError?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Weather ignore procedures that has no path defined.
|
|
33
|
+
*
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
ignoreUndefinedPathProcedures?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* What to do when we found an error with our router
|
|
39
|
+
*
|
|
40
|
+
* @default 'throw'
|
|
41
|
+
*/
|
|
42
|
+
errorHandlerStrategy?: ErrorHandlerStrategy;
|
|
43
|
+
}
|
|
44
|
+
export declare class OpenAPIGenerator {
|
|
45
|
+
private readonly contentBuilder;
|
|
46
|
+
private readonly parametersBuilder;
|
|
47
|
+
private readonly schemaConverter;
|
|
48
|
+
private readonly schemaUtils;
|
|
49
|
+
private readonly jsonSerializer;
|
|
50
|
+
private readonly pathParser;
|
|
51
|
+
private readonly inputStructureParser;
|
|
52
|
+
private readonly outputStructureParser;
|
|
53
|
+
private readonly errorHandlerStrategy;
|
|
54
|
+
private readonly ignoreUndefinedPathProcedures;
|
|
55
|
+
private readonly considerMissingTagDefinitionAsError;
|
|
56
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
57
|
+
generate(router: ContractRouter | ANY_ROUTER, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=openapi-generator.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
|
+
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
3
|
+
import type { JSONSchema, ObjectSchema } from './schema';
|
|
4
|
+
import type { SchemaConverter } from './schema-converter';
|
|
5
|
+
import type { PublicSchemaUtils } from './schema-utils';
|
|
6
|
+
export interface OpenAPIInputStructureParseResult {
|
|
7
|
+
paramsSchema: ObjectSchema | undefined;
|
|
8
|
+
querySchema: ObjectSchema | undefined;
|
|
9
|
+
headersSchema: ObjectSchema | undefined;
|
|
10
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare class OpenAPIInputStructureParser {
|
|
13
|
+
private readonly schemaConverter;
|
|
14
|
+
private readonly schemaUtils;
|
|
15
|
+
private readonly pathParser;
|
|
16
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
|
|
17
|
+
parse(contract: ANY_CONTRACT_PROCEDURE, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
|
|
18
|
+
private parseDetailedSchema;
|
|
19
|
+
private parseCompactSchema;
|
|
20
|
+
}
|
|
21
|
+
export type PublicOpenAPIInputStructureParser = Pick<OpenAPIInputStructureParser, keyof OpenAPIInputStructureParser>;
|
|
22
|
+
//# sourceMappingURL=openapi-input-structure-parser.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
|
+
import type { JSONSchema, ObjectSchema } from './schema';
|
|
3
|
+
import type { SchemaConverter } from './schema-converter';
|
|
4
|
+
import type { PublicSchemaUtils } from './schema-utils';
|
|
5
|
+
export interface OpenAPIOutputStructureParseResult {
|
|
6
|
+
headersSchema: ObjectSchema | undefined;
|
|
7
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare class OpenAPIOutputStructureParser {
|
|
10
|
+
private readonly schemaConverter;
|
|
11
|
+
private readonly schemaUtils;
|
|
12
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
|
|
13
|
+
parse(contract: ANY_CONTRACT_PROCEDURE, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
|
|
14
|
+
private parseDetailedSchema;
|
|
15
|
+
private parseCompactSchema;
|
|
16
|
+
}
|
|
17
|
+
export type PublicOpenAPIOutputStructureParser = Pick<OpenAPIOutputStructureParser, keyof OpenAPIOutputStructureParser>;
|
|
18
|
+
//# sourceMappingURL=openapi-output-structure-parser.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OpenAPI } from './openapi';
|
|
2
|
+
import type { JSONSchema } from './schema';
|
|
3
|
+
export declare class OpenAPIParametersBuilder {
|
|
4
|
+
build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema.JSONSchema & {
|
|
5
|
+
type: 'object';
|
|
6
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
|
|
7
|
+
buildHeadersObject(jsonSchema: JSONSchema.JSONSchema & {
|
|
8
|
+
type: 'object';
|
|
9
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.HeadersObject;
|
|
10
|
+
}
|
|
11
|
+
export type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
|
|
12
|
+
//# sourceMappingURL=openapi-parameters-builder.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Schema } from '@orpc/contract';
|
|
2
|
+
import type { JSONSchema } from './schema';
|
|
3
|
+
export interface SchemaConvertOptions {
|
|
4
|
+
strategy: 'input' | 'output';
|
|
5
|
+
}
|
|
6
|
+
export interface SchemaConverter {
|
|
7
|
+
condition: (schema: Schema, options: SchemaConvertOptions) => boolean;
|
|
8
|
+
convert: (schema: Schema, options: SchemaConvertOptions) => JSONSchema.JSONSchema;
|
|
9
|
+
}
|
|
10
|
+
export declare class CompositeSchemaConverter implements SchemaConverter {
|
|
11
|
+
private readonly converters;
|
|
12
|
+
constructor(converters: SchemaConverter[]);
|
|
13
|
+
condition(): boolean;
|
|
14
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=schema-converter.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FileSchema, type JSONSchema, type ObjectSchema } from './schema';
|
|
2
|
+
export declare class SchemaUtils {
|
|
3
|
+
isFileSchema(schema: JSONSchema.JSONSchema): schema is FileSchema;
|
|
4
|
+
isObjectSchema(schema: JSONSchema.JSONSchema): schema is ObjectSchema;
|
|
5
|
+
isAnySchema(schema: JSONSchema.JSONSchema): boolean;
|
|
6
|
+
isUndefinableSchema(schema: JSONSchema.JSONSchema): boolean;
|
|
7
|
+
separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
8
|
+
filterSchemaBranches(schema: JSONSchema.JSONSchema, check: (schema: JSONSchema.JSONSchema) => boolean, matches?: JSONSchema.JSONSchema[]): [matches: JSONSchema.JSONSchema[], rest: JSONSchema.JSONSchema | undefined];
|
|
9
|
+
}
|
|
10
|
+
export type PublicSchemaUtils = Pick<SchemaUtils, keyof SchemaUtils>;
|
|
11
|
+
//# sourceMappingURL=schema-utils.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as JSONSchema from 'json-schema-typed/draft-2020-12';
|
|
2
|
+
export { Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
3
|
+
export { JSONSchema };
|
|
4
|
+
export type ObjectSchema = JSONSchema.JSONSchema & {
|
|
5
|
+
type: 'object';
|
|
6
|
+
} & object;
|
|
7
|
+
export type FileSchema = JSONSchema.JSONSchema & {
|
|
8
|
+
type: 'string';
|
|
9
|
+
contentMediaType: string;
|
|
10
|
+
} & object;
|
|
11
|
+
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")[];
|
|
12
|
+
//# sourceMappingURL=schema.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,9 +9,10 @@ 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 forEachAllContractProcedure(router: ContractRouter | ANY_ROUTER, callback: (options: EachLeafCallbackOptions) => void): Promise<void>;
|
|
16
17
|
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
17
18
|
//# 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.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f99e554",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -20,10 +20,15 @@
|
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
},
|
|
22
22
|
"./fetch": {
|
|
23
|
-
"types": "./dist/src/fetch/index.d.ts",
|
|
23
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
|
24
24
|
"import": "./dist/fetch.js",
|
|
25
25
|
"default": "./dist/fetch.js"
|
|
26
26
|
},
|
|
27
|
+
"./node": {
|
|
28
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
|
29
|
+
"import": "./dist/node.js",
|
|
30
|
+
"default": "./dist/node.js"
|
|
31
|
+
},
|
|
27
32
|
"./🔒/*": {
|
|
28
33
|
"types": "./dist/src/*.d.ts"
|
|
29
34
|
}
|
|
@@ -34,23 +39,26 @@
|
|
|
34
39
|
"dist"
|
|
35
40
|
],
|
|
36
41
|
"dependencies": {
|
|
42
|
+
"@mjackson/node-fetch-server": "^0.5.0",
|
|
37
43
|
"@standard-schema/spec": "1.0.0-beta.4",
|
|
44
|
+
"@types/content-disposition": "^0.5.8",
|
|
45
|
+
"content-disposition": "^0.5.4",
|
|
38
46
|
"escape-string-regexp": "^5.0.0",
|
|
47
|
+
"fast-content-type-parse": "^2.0.0",
|
|
48
|
+
"hono": "^4.6.12",
|
|
39
49
|
"json-schema-typed": "^8.0.1",
|
|
40
50
|
"openapi3-ts": "^4.4.0",
|
|
41
|
-
"
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/
|
|
45
|
-
"@orpc/shared": "0.0.0-next.ee0aeaf"
|
|
51
|
+
"wildcard-match": "^5.1.3",
|
|
52
|
+
"@orpc/contract": "0.0.0-next.f99e554",
|
|
53
|
+
"@orpc/shared": "0.0.0-next.f99e554",
|
|
54
|
+
"@orpc/server": "0.0.0-next.f99e554"
|
|
46
55
|
},
|
|
47
56
|
"devDependencies": {
|
|
48
57
|
"@readme/openapi-parser": "^2.6.0",
|
|
49
|
-
"hono": "^4.6.12",
|
|
50
58
|
"zod": "^3.24.1"
|
|
51
59
|
},
|
|
52
60
|
"scripts": {
|
|
53
|
-
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
61
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --entry.node=src/adapters/node/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
54
62
|
"build:watch": "pnpm run build --watch",
|
|
55
63
|
"type:check": "tsc -b"
|
|
56
64
|
}
|