@orpc/openapi 0.34.0 → 0.35.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-BHJYKXQL.js +52 -0
- package/dist/chunk-HQ34JZI7.js +32 -0
- package/dist/chunk-M5HOHBLW.js +432 -0
- package/dist/fetch.js +5 -30
- package/dist/hono.js +5 -30
- package/dist/index.js +6 -6
- package/dist/next.js +5 -30
- package/dist/node.js +18 -34
- package/dist/src/adapters/fetch/index.d.ts +0 -8
- package/dist/src/adapters/fetch/openapi-handler.d.ts +6 -28
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/openapi-handler.d.ts +7 -8
- package/dist/src/adapters/standard/index.d.ts +7 -0
- package/dist/src/adapters/standard/openapi-codec.d.ts +18 -0
- package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
- package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
- package/dist/src/adapters/standard/openapi-serializer.d.ts +11 -0
- package/dist/src/openapi-generator.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -16
- package/dist/standard.js +16 -0
- package/package.json +10 -5
- package/dist/chunk-Q2LSK6YZ.js +0 -102
- package/dist/chunk-SOVQ5ARD.js +0 -650
- package/dist/chunk-VFGNQS5W.js +0 -25
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/types.d.ts +0 -2
- /package/dist/src/adapters/{fetch → standard}/bracket-notation.d.ts +0 -0
- /package/dist/src/adapters/{fetch → standard}/schema-coercer.d.ts +0 -0
package/dist/node.js
CHANGED
@@ -1,46 +1,30 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
OpenAPICodec,
|
3
|
+
OpenAPIMatcher
|
4
|
+
} from "./chunk-M5HOHBLW.js";
|
5
|
+
import "./chunk-BHJYKXQL.js";
|
5
6
|
|
6
7
|
// src/adapters/node/openapi-handler.ts
|
7
|
-
import {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
|
9
|
+
import { StandardHandler } from "@orpc/server/standard";
|
10
|
+
var OpenAPIHandler = class {
|
11
|
+
standardHandler;
|
12
|
+
constructor(router, options) {
|
13
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher(options);
|
14
|
+
const codec = options?.codec ?? new OpenAPICodec(options);
|
15
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
|
12
16
|
}
|
13
|
-
async handle(req, res, ...
|
14
|
-
const
|
15
|
-
const
|
16
|
-
|
17
|
-
if (result.matched === false) {
|
17
|
+
async handle(req, res, ...rest) {
|
18
|
+
const standardRequest = nodeHttpToStandardRequest(req, res);
|
19
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
20
|
+
if (!result.matched) {
|
18
21
|
return { matched: false };
|
19
22
|
}
|
20
|
-
await
|
21
|
-
await sendResponse(res, result.response);
|
23
|
+
await nodeHttpResponseSendStandardResponse(res, result.response);
|
22
24
|
return { matched: true };
|
23
25
|
}
|
24
26
|
};
|
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
27
|
export {
|
42
|
-
|
43
|
-
OpenAPIServerHandler,
|
44
|
-
OpenAPIServerlessHandler
|
28
|
+
OpenAPIHandler
|
45
29
|
};
|
46
30
|
//# sourceMappingURL=node.js.map
|
@@ -1,10 +1,2 @@
|
|
1
|
-
export * from './bracket-notation';
|
2
|
-
export * from './input-structure-compact';
|
3
|
-
export * from './input-structure-detailed';
|
4
1
|
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
2
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,32 +1,10 @@
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
2
|
-
import type { FetchHandler,
|
3
|
-
import type {
|
4
|
-
import {
|
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, FetchHandleResult, T, any> & {
|
11
|
-
jsonSerializer?: PublicJSONSerializer;
|
12
|
-
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
13
|
-
payloadCodec?: PublicOpenAPIPayloadCodec;
|
14
|
-
inputBuilderSimple?: PublicInputStructureCompact;
|
15
|
-
inputBuilderFull?: PublicInputStructureDetailed;
|
16
|
-
schemaCoercers?: SchemaCoercer[];
|
17
|
-
};
|
2
|
+
import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
3
|
+
import type { StandardHandleRest } from '@orpc/server/standard';
|
4
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
18
5
|
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
19
|
-
private readonly
|
20
|
-
|
21
|
-
|
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
|
-
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
27
|
-
private decodeInput;
|
28
|
-
private encodeOutput;
|
29
|
-
private assertDetailedOutput;
|
30
|
-
private convertToORPCError;
|
6
|
+
private readonly standardHandler;
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
8
|
+
handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
|
31
9
|
}
|
32
10
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
handle(req: IncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
2
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
|
3
|
+
import type { StandardHandleRest } from '@orpc/server/standard';
|
4
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
5
|
+
export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
6
|
+
private readonly standardHandler;
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
8
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
|
10
9
|
}
|
11
10
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export * as BracketNotation from './bracket-notation';
|
2
|
+
export * from './openapi-codec';
|
3
|
+
export * from './openapi-handler';
|
4
|
+
export * from './openapi-matcher';
|
5
|
+
export * from './openapi-serializer';
|
6
|
+
export * from './schema-coercer';
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { AnyProcedure } from '@orpc/server';
|
2
|
+
import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from '@orpc/server/standard';
|
3
|
+
import { type ORPCError } from '@orpc/contract';
|
4
|
+
import { OpenAPISerializer } from './openapi-serializer';
|
5
|
+
import { type SchemaCoercer } from './schema-coercer';
|
6
|
+
export interface OpenAPICodecOptions {
|
7
|
+
serializer?: OpenAPISerializer;
|
8
|
+
schemaCoercers?: SchemaCoercer[];
|
9
|
+
}
|
10
|
+
export declare class OpenAPICodec implements StandardCodec {
|
11
|
+
private readonly serializer;
|
12
|
+
private readonly compositeSchemaCoercer;
|
13
|
+
constructor(options?: OpenAPICodecOptions);
|
14
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
15
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
16
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=openapi-codec.d.ts.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { Context } from '@orpc/server';
|
2
|
+
import type { RPCHandlerOptions } from '@orpc/server/standard';
|
3
|
+
import type { OpenAPICodecOptions } from './openapi-codec';
|
4
|
+
import type { OpenAPIMatcherOptions } from './openapi-matcher';
|
5
|
+
export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T>, OpenAPIMatcherOptions, OpenAPICodecOptions {
|
6
|
+
}
|
7
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { AnyRouter } from '@orpc/server';
|
2
|
+
import type { StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
3
|
+
import { type HTTPPath } from '@orpc/contract';
|
4
|
+
export interface OpenAPIMatcherOptions {
|
5
|
+
/**
|
6
|
+
* Ignore procedure that does not have a method defined in the contract.
|
7
|
+
*
|
8
|
+
* @default false
|
9
|
+
*/
|
10
|
+
ignoreUndefinedMethod?: boolean;
|
11
|
+
}
|
12
|
+
export declare class OpenAPIMatcher implements StandardMatcher {
|
13
|
+
private readonly tree;
|
14
|
+
private readonly ignoreUndefinedMethod;
|
15
|
+
constructor(options?: OpenAPIMatcherOptions);
|
16
|
+
private pendingRouters;
|
17
|
+
init(router: AnyRouter, path?: string[]): void;
|
18
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=openapi-matcher.d.ts.map
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { PublicJSONSerializer } from '../../json-serializer';
|
2
|
+
export interface OpenAPISerializerOptions {
|
3
|
+
jsonSerializer?: PublicJSONSerializer;
|
4
|
+
}
|
5
|
+
export declare class OpenAPISerializer {
|
6
|
+
private readonly jsonSerializer;
|
7
|
+
constructor(options?: OpenAPISerializerOptions);
|
8
|
+
serialize(data: unknown): unknown;
|
9
|
+
deserialize(serialized: unknown): unknown;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=openapi-serializer.d.ts.map
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { AnyRouter } from '@orpc/server';
|
2
1
|
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
3
2
|
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
4
3
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
5
4
|
import type { SchemaConverter } from './schema-converter';
|
6
5
|
import { type ContractRouter } from '@orpc/contract';
|
6
|
+
import { type AnyRouter } from '@orpc/server';
|
7
7
|
import { type PublicJSONSerializer } from './json-serializer';
|
8
8
|
import { type OpenAPI } from './openapi';
|
9
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
package/dist/src/utils.d.ts
CHANGED
@@ -1,18 +1,3 @@
|
|
1
|
-
import type {
|
2
|
-
import type { AnyProcedure, AnyRouter, Lazy } from '@orpc/server';
|
3
|
-
export interface EachLeafOptions {
|
4
|
-
router: AnyContractRouter | AnyRouter;
|
5
|
-
path: string[];
|
6
|
-
}
|
7
|
-
export interface EachLeafCallbackOptions {
|
8
|
-
contract: AnyContractProcedure;
|
9
|
-
path: string[];
|
10
|
-
}
|
11
|
-
export interface EachContractLeafResultItem {
|
12
|
-
router: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
|
13
|
-
path: string[];
|
14
|
-
}
|
15
|
-
export declare function forEachContractProcedure(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
|
16
|
-
export declare function forEachAllContractProcedure(router: AnyContractRouter | AnyRouter, callback: (options: EachLeafCallbackOptions) => void): Promise<void>;
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
17
2
|
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
18
3
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/standard.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import {
|
2
|
+
CompositeSchemaCoercer,
|
3
|
+
OpenAPICodec,
|
4
|
+
OpenAPIMatcher,
|
5
|
+
OpenAPISerializer,
|
6
|
+
bracket_notation_exports
|
7
|
+
} from "./chunk-M5HOHBLW.js";
|
8
|
+
import "./chunk-BHJYKXQL.js";
|
9
|
+
export {
|
10
|
+
bracket_notation_exports as BracketNotation,
|
11
|
+
CompositeSchemaCoercer,
|
12
|
+
OpenAPICodec,
|
13
|
+
OpenAPIMatcher,
|
14
|
+
OpenAPISerializer
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=standard.js.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.35.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -19,6 +19,11 @@
|
|
19
19
|
"import": "./dist/index.js",
|
20
20
|
"default": "./dist/index.js"
|
21
21
|
},
|
22
|
+
"./standard": {
|
23
|
+
"types": "./dist/src/adapters/standard/index.d.ts",
|
24
|
+
"import": "./dist/standard.js",
|
25
|
+
"default": "./dist/standard.js"
|
26
|
+
},
|
22
27
|
"./fetch": {
|
23
28
|
"types": "./dist/src/adapters/fetch/index.d.ts",
|
24
29
|
"import": "./dist/fetch.js",
|
@@ -54,13 +59,13 @@
|
|
54
59
|
"content-disposition": "^0.5.4",
|
55
60
|
"escape-string-regexp": "^5.0.0",
|
56
61
|
"fast-content-type-parse": "^2.0.0",
|
57
|
-
"hono": "^4.6.12",
|
58
62
|
"json-schema-typed": "^8.0.1",
|
59
63
|
"openapi3-ts": "^4.4.0",
|
64
|
+
"rou3": "^0.5.1",
|
60
65
|
"wildcard-match": "^5.1.3",
|
61
|
-
"@orpc/contract": "0.
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/
|
66
|
+
"@orpc/contract": "0.35.0",
|
67
|
+
"@orpc/shared": "0.35.0",
|
68
|
+
"@orpc/server": "0.35.0"
|
64
69
|
},
|
65
70
|
"devDependencies": {
|
66
71
|
"@readme/openapi-parser": "^2.6.0",
|
package/dist/chunk-Q2LSK6YZ.js
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
// src/json-serializer.ts
|
2
|
-
import { isPlainObject } from "@orpc/shared";
|
3
|
-
var JSONSerializer = class {
|
4
|
-
serialize(payload) {
|
5
|
-
if (payload instanceof Set)
|
6
|
-
return this.serialize([...payload]);
|
7
|
-
if (payload instanceof Map)
|
8
|
-
return this.serialize([...payload.entries()]);
|
9
|
-
if (Array.isArray(payload)) {
|
10
|
-
return payload.map((v) => v === void 0 ? "undefined" : this.serialize(v));
|
11
|
-
}
|
12
|
-
if (Number.isNaN(payload))
|
13
|
-
return "NaN";
|
14
|
-
if (typeof payload === "bigint")
|
15
|
-
return payload.toString();
|
16
|
-
if (payload instanceof Date && Number.isNaN(payload.getTime())) {
|
17
|
-
return "Invalid Date";
|
18
|
-
}
|
19
|
-
if (payload instanceof RegExp)
|
20
|
-
return payload.toString();
|
21
|
-
if (payload instanceof URL)
|
22
|
-
return payload.toString();
|
23
|
-
if (!isPlainObject(payload))
|
24
|
-
return payload;
|
25
|
-
return Object.keys(payload).reduce(
|
26
|
-
(carry, key) => {
|
27
|
-
const val = payload[key];
|
28
|
-
carry[key] = this.serialize(val);
|
29
|
-
return carry;
|
30
|
-
},
|
31
|
-
{}
|
32
|
-
);
|
33
|
-
}
|
34
|
-
};
|
35
|
-
|
36
|
-
// src/utils.ts
|
37
|
-
import { isContractProcedure } from "@orpc/contract";
|
38
|
-
import { getRouterContract, isLazy, unlazy } from "@orpc/server";
|
39
|
-
function forEachContractProcedure(options, callback, result = [], isCurrentRouterContract = false) {
|
40
|
-
const hiddenContract = getRouterContract(options.router);
|
41
|
-
if (!isCurrentRouterContract && hiddenContract) {
|
42
|
-
return forEachContractProcedure(
|
43
|
-
{
|
44
|
-
path: options.path,
|
45
|
-
router: hiddenContract
|
46
|
-
},
|
47
|
-
callback,
|
48
|
-
result,
|
49
|
-
true
|
50
|
-
);
|
51
|
-
}
|
52
|
-
if (isLazy(options.router)) {
|
53
|
-
result.push({
|
54
|
-
router: options.router,
|
55
|
-
path: options.path
|
56
|
-
});
|
57
|
-
} else if (isContractProcedure(options.router)) {
|
58
|
-
callback({
|
59
|
-
contract: options.router,
|
60
|
-
path: options.path
|
61
|
-
});
|
62
|
-
} else {
|
63
|
-
for (const key in options.router) {
|
64
|
-
forEachContractProcedure(
|
65
|
-
{
|
66
|
-
router: options.router[key],
|
67
|
-
path: [...options.path, key]
|
68
|
-
},
|
69
|
-
callback,
|
70
|
-
result
|
71
|
-
);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
return result;
|
75
|
-
}
|
76
|
-
async function forEachAllContractProcedure(router, callback) {
|
77
|
-
const pending = [{
|
78
|
-
path: [],
|
79
|
-
router
|
80
|
-
}];
|
81
|
-
for (const item of pending) {
|
82
|
-
const lazies = forEachContractProcedure(item, callback);
|
83
|
-
for (const lazy of lazies) {
|
84
|
-
const { default: router2 } = await unlazy(lazy.router);
|
85
|
-
pending.push({
|
86
|
-
path: lazy.path,
|
87
|
-
router: router2
|
88
|
-
});
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
function standardizeHTTPPath(path) {
|
93
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
94
|
-
}
|
95
|
-
|
96
|
-
export {
|
97
|
-
JSONSerializer,
|
98
|
-
forEachContractProcedure,
|
99
|
-
forEachAllContractProcedure,
|
100
|
-
standardizeHTTPPath
|
101
|
-
};
|
102
|
-
//# sourceMappingURL=chunk-Q2LSK6YZ.js.map
|