@orpc/openapi 0.0.0-next.1431467 → 0.0.0-next.16739f4
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/README.md +26 -17
- package/dist/adapters/fetch/index.d.mts +12 -8
- package/dist/adapters/fetch/index.d.ts +12 -8
- package/dist/adapters/fetch/index.mjs +13 -6
- package/dist/adapters/node/index.d.mts +12 -8
- package/dist/adapters/node/index.d.ts +12 -8
- package/dist/adapters/node/index.mjs +7 -22
- package/dist/adapters/standard/index.d.mts +19 -8
- package/dist/adapters/standard/index.d.ts +19 -8
- package/dist/adapters/standard/index.mjs +4 -2
- package/dist/index.d.mts +99 -135
- package/dist/index.d.ts +99 -135
- package/dist/index.mjs +448 -559
- package/dist/shared/openapi.D3j94c9n.d.mts +12 -0
- package/dist/shared/openapi.D3j94c9n.d.ts +12 -0
- package/dist/shared/{openapi.C_biOx82.mjs → openapi.p5tsmBXx.mjs} +33 -22
- package/package.json +9 -21
- package/dist/adapters/hono/index.d.mts +0 -6
- package/dist/adapters/hono/index.d.ts +0 -6
- package/dist/adapters/hono/index.mjs +0 -10
- package/dist/adapters/next/index.d.mts +0 -6
- package/dist/adapters/next/index.d.ts +0 -6
- package/dist/adapters/next/index.mjs +0 -10
- package/dist/shared/openapi.B6uueFtN.mjs +0 -29
- package/dist/shared/openapi.BHG_gu5Z.mjs +0 -8
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
|
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
6
|
+
}
|
|
7
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { StandardOpenAPIHandler as a };
|
|
12
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
|
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
6
|
+
}
|
|
7
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { StandardOpenAPIHandler as a };
|
|
12
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
1
3
|
import { fallbackContractConfig } from '@orpc/contract';
|
|
2
4
|
import { isObject } from '@orpc/shared';
|
|
3
|
-
import {
|
|
5
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
6
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
4
7
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
5
|
-
import { s as standardizeHTTPPath } from './openapi.BHG_gu5Z.mjs';
|
|
6
8
|
|
|
7
|
-
class
|
|
9
|
+
class StandardOpenAPICodec {
|
|
8
10
|
constructor(serializer) {
|
|
9
11
|
this.serializer = serializer;
|
|
10
12
|
}
|
|
@@ -65,21 +67,25 @@ class OpenAPICodec {
|
|
|
65
67
|
return {
|
|
66
68
|
status: error.status,
|
|
67
69
|
headers: {},
|
|
68
|
-
body: this.serializer.serialize(error.toJSON())
|
|
70
|
+
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
function toRou3Pattern(path) {
|
|
76
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
77
|
+
}
|
|
78
|
+
function decodeParams(params) {
|
|
79
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class StandardOpenAPIMatcher {
|
|
74
83
|
tree = createRouter();
|
|
75
84
|
pendingRouters = [];
|
|
76
85
|
init(router, path = []) {
|
|
77
|
-
const laziedOptions =
|
|
78
|
-
router,
|
|
79
|
-
path
|
|
80
|
-
}, ({ path: path2, contract }) => {
|
|
86
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
|
81
87
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
82
|
-
const httpPath =
|
|
88
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
83
89
|
if (isProcedure(contract)) {
|
|
84
90
|
addRoute(this.tree, method, httpPath, {
|
|
85
91
|
path: path2,
|
|
@@ -99,8 +105,8 @@ class OpenAPIMatcher {
|
|
|
99
105
|
});
|
|
100
106
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
101
107
|
...option,
|
|
102
|
-
httpPathPrefix:
|
|
103
|
-
laziedPrefix:
|
|
108
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
109
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
104
110
|
})));
|
|
105
111
|
}
|
|
106
112
|
async match(method, pathname) {
|
|
@@ -108,7 +114,7 @@ class OpenAPIMatcher {
|
|
|
108
114
|
const newPendingRouters = [];
|
|
109
115
|
for (const pendingRouter of this.pendingRouters) {
|
|
110
116
|
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
111
|
-
const { default: router } = await unlazy(pendingRouter.
|
|
117
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
|
112
118
|
this.init(router, pendingRouter.path);
|
|
113
119
|
} else {
|
|
114
120
|
newPendingRouters.push(pendingRouter);
|
|
@@ -121,14 +127,14 @@ class OpenAPIMatcher {
|
|
|
121
127
|
return void 0;
|
|
122
128
|
}
|
|
123
129
|
if (!match.data.procedure) {
|
|
124
|
-
const { default: maybeProcedure } = await unlazy(
|
|
130
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
125
131
|
if (!isProcedure(maybeProcedure)) {
|
|
126
132
|
throw new Error(`
|
|
127
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
|
133
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
|
128
134
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
129
135
|
`);
|
|
130
136
|
}
|
|
131
|
-
match.data.procedure = createContractedProcedure(match.data.contract
|
|
137
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
132
138
|
}
|
|
133
139
|
return {
|
|
134
140
|
path: match.data.path,
|
|
@@ -137,11 +143,16 @@ class OpenAPIMatcher {
|
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
|
|
147
|
+
class StandardOpenAPIHandler extends StandardHandler {
|
|
148
|
+
constructor(router, options) {
|
|
149
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
150
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
151
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
152
|
+
const matcher = new StandardOpenAPIMatcher();
|
|
153
|
+
const codec = new StandardOpenAPICodec(serializer);
|
|
154
|
+
super(router, matcher, codec, options);
|
|
155
|
+
}
|
|
145
156
|
}
|
|
146
157
|
|
|
147
|
-
export {
|
|
158
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIHandler as a, StandardOpenAPIMatcher as b, decodeParams as d, toRou3Pattern as t };
|
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.16739f4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,16 +29,6 @@
|
|
|
29
29
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
30
30
|
"default": "./dist/adapters/fetch/index.mjs"
|
|
31
31
|
},
|
|
32
|
-
"./hono": {
|
|
33
|
-
"types": "./dist/adapters/hono/index.d.mts",
|
|
34
|
-
"import": "./dist/adapters/hono/index.mjs",
|
|
35
|
-
"default": "./dist/adapters/hono/index.mjs"
|
|
36
|
-
},
|
|
37
|
-
"./next": {
|
|
38
|
-
"types": "./dist/adapters/next/index.d.mts",
|
|
39
|
-
"import": "./dist/adapters/next/index.mjs",
|
|
40
|
-
"default": "./dist/adapters/next/index.mjs"
|
|
41
|
-
},
|
|
42
32
|
"./node": {
|
|
43
33
|
"types": "./dist/adapters/node/index.d.mts",
|
|
44
34
|
"import": "./dist/adapters/node/index.mjs",
|
|
@@ -50,16 +40,14 @@
|
|
|
50
40
|
],
|
|
51
41
|
"dependencies": {
|
|
52
42
|
"json-schema-typed": "^8.0.1",
|
|
53
|
-
"
|
|
54
|
-
"rou3": "^0.
|
|
55
|
-
"@orpc/client": "0.0.0-next.
|
|
56
|
-
"@orpc/
|
|
57
|
-
"@orpc/
|
|
58
|
-
"@orpc/
|
|
59
|
-
"@orpc/server": "0.0.0-next.
|
|
60
|
-
"@orpc/
|
|
61
|
-
"@orpc/standard-server-fetch": "0.0.0-next.1431467",
|
|
62
|
-
"@orpc/standard-server-node": "0.0.0-next.1431467"
|
|
43
|
+
"openapi-types": "^12.1.3",
|
|
44
|
+
"rou3": "^0.6.0",
|
|
45
|
+
"@orpc/client": "0.0.0-next.16739f4",
|
|
46
|
+
"@orpc/contract": "0.0.0-next.16739f4",
|
|
47
|
+
"@orpc/openapi-client": "0.0.0-next.16739f4",
|
|
48
|
+
"@orpc/server": "0.0.0-next.16739f4",
|
|
49
|
+
"@orpc/standard-server": "0.0.0-next.16739f4",
|
|
50
|
+
"@orpc/shared": "0.0.0-next.16739f4"
|
|
63
51
|
},
|
|
64
52
|
"devDependencies": {
|
|
65
53
|
"zod": "^3.24.2"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.B6uueFtN.mjs';
|
|
2
|
-
import '@orpc/openapi-client/standard';
|
|
3
|
-
import '@orpc/server/standard';
|
|
4
|
-
import '@orpc/standard-server-fetch';
|
|
5
|
-
import '../../shared/openapi.C_biOx82.mjs';
|
|
6
|
-
import '@orpc/contract';
|
|
7
|
-
import '@orpc/shared';
|
|
8
|
-
import '@orpc/server';
|
|
9
|
-
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.BHG_gu5Z.mjs';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.B6uueFtN.mjs';
|
|
2
|
-
import '@orpc/openapi-client/standard';
|
|
3
|
-
import '@orpc/server/standard';
|
|
4
|
-
import '@orpc/standard-server-fetch';
|
|
5
|
-
import '../../shared/openapi.C_biOx82.mjs';
|
|
6
|
-
import '@orpc/contract';
|
|
7
|
-
import '@orpc/shared';
|
|
8
|
-
import '@orpc/server';
|
|
9
|
-
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.BHG_gu5Z.mjs';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { OpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
-
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
|
4
|
-
import { a as OpenAPIMatcher, O as OpenAPICodec } from './openapi.C_biOx82.mjs';
|
|
5
|
-
|
|
6
|
-
class OpenAPIHandler {
|
|
7
|
-
standardHandler;
|
|
8
|
-
constructor(router, options = {}) {
|
|
9
|
-
const serializer = new OpenAPISerializer();
|
|
10
|
-
const matcher = new OpenAPIMatcher();
|
|
11
|
-
const codec = new OpenAPICodec(serializer);
|
|
12
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
13
|
-
}
|
|
14
|
-
async handle(request, ...[
|
|
15
|
-
options = {}
|
|
16
|
-
]) {
|
|
17
|
-
const standardRequest = toStandardLazyRequest(request);
|
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
|
19
|
-
if (!result.matched) {
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
matched: true,
|
|
24
|
-
response: toFetchResponse(result.response, options)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { OpenAPIHandler as O };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
function standardizeHTTPPath(path) {
|
|
2
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
3
|
-
}
|
|
4
|
-
function toOpenAPI31RoutePattern(path) {
|
|
5
|
-
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { standardizeHTTPPath as s, toOpenAPI31RoutePattern as t };
|