@orpc/openapi 0.0.0-next.fe39bf3 → 0.0.0-next.ff41b3a
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 +100 -0
- package/dist/adapters/fetch/index.d.mts +17 -0
- package/dist/adapters/fetch/index.d.ts +17 -0
- package/dist/adapters/fetch/index.mjs +17 -0
- package/dist/adapters/node/index.d.mts +17 -0
- package/dist/adapters/node/index.d.ts +17 -0
- package/dist/adapters/node/index.mjs +17 -0
- package/dist/adapters/standard/index.d.mts +34 -0
- package/dist/adapters/standard/index.d.ts +34 -0
- package/dist/adapters/standard/index.mjs +8 -0
- package/dist/index.d.mts +131 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.mjs +545 -0
- package/dist/shared/openapi.D3j94c9n.d.mts +12 -0
- package/dist/shared/openapi.D3j94c9n.d.ts +12 -0
- package/dist/{chunk-LPBZEW4B.js → shared/openapi.p5tsmBXx.mjs} +40 -47
- package/package.json +23 -39
- package/dist/chunk-UU2TTVB2.js +0 -32
- package/dist/chunk-XGHV4TH3.js +0 -13
- package/dist/fetch.js +0 -9
- package/dist/hono.js +0 -9
- package/dist/index.js +0 -701
- package/dist/next.js +0 -9
- package/dist/node.js +0 -30
- package/dist/src/adapters/fetch/index.d.ts +0 -2
- package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/hono/index.d.ts +0 -2
- package/dist/src/adapters/next/index.d.ts +0 -2
- package/dist/src/adapters/node/index.d.ts +0 -2
- package/dist/src/adapters/node/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/standard/index.d.ts +0 -4
- package/dist/src/adapters/standard/openapi-codec.d.ts +0 -16
- package/dist/src/adapters/standard/openapi-handler.d.ts +0 -7
- package/dist/src/adapters/standard/openapi-matcher.d.ts +0 -20
- package/dist/src/index.d.ts +0 -16
- package/dist/src/openapi-content-builder.d.ts +0 -10
- package/dist/src/openapi-error.d.ts +0 -3
- package/dist/src/openapi-generator.d.ts +0 -67
- package/dist/src/openapi-input-structure-parser.d.ts +0 -22
- package/dist/src/openapi-operation-extender.d.ts +0 -7
- package/dist/src/openapi-output-structure-parser.d.ts +0 -18
- package/dist/src/openapi-parameters-builder.d.ts +0 -12
- package/dist/src/openapi-path-parser.d.ts +0 -8
- package/dist/src/openapi.d.ts +0 -3
- package/dist/src/schema-converter.d.ts +0 -16
- package/dist/src/schema-utils.d.ts +0 -11
- package/dist/src/schema.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -4
- package/dist/standard.js +0 -10
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
1
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
+
import { fallbackContractConfig } from '@orpc/contract';
|
|
4
|
+
import { isObject } from '@orpc/shared';
|
|
5
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
6
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
7
|
+
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { isObject } from "@orpc/shared";
|
|
9
|
-
var OpenAPICodec = class {
|
|
10
|
-
serializer;
|
|
11
|
-
constructor(options) {
|
|
12
|
-
this.serializer = options?.serializer ?? new OpenAPISerializer();
|
|
9
|
+
class StandardOpenAPICodec {
|
|
10
|
+
constructor(serializer) {
|
|
11
|
+
this.serializer = serializer;
|
|
13
12
|
}
|
|
14
13
|
async decode(request, params, procedure) {
|
|
15
14
|
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
@@ -68,32 +67,25 @@ var OpenAPICodec = class {
|
|
|
68
67
|
return {
|
|
69
68
|
status: error.status,
|
|
70
69
|
headers: {},
|
|
71
|
-
body: this.serializer.serialize(error.toJSON())
|
|
70
|
+
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
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
|
+
}
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
import { fallbackContractConfig as fallbackContractConfig2 } from "@orpc/contract";
|
|
78
|
-
import { convertPathToHttpPath, createContractedProcedure, eachContractProcedure, getLazyRouterPrefix, getRouterChild, isProcedure, unlazy } from "@orpc/server";
|
|
79
|
-
import { addRoute, createRouter, findRoute } from "rou3";
|
|
80
|
-
var OpenAPIMatcher = class {
|
|
82
|
+
class StandardOpenAPIMatcher {
|
|
81
83
|
tree = createRouter();
|
|
82
|
-
ignoreUndefinedMethod;
|
|
83
|
-
constructor(options) {
|
|
84
|
-
this.ignoreUndefinedMethod = options?.ignoreUndefinedMethod ?? false;
|
|
85
|
-
}
|
|
86
84
|
pendingRouters = [];
|
|
87
85
|
init(router, path = []) {
|
|
88
|
-
const laziedOptions =
|
|
89
|
-
|
|
90
|
-
path
|
|
91
|
-
}, ({ path: path2, contract }) => {
|
|
92
|
-
if (!contract["~orpc"].route.method && this.ignoreUndefinedMethod) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const method = fallbackContractConfig2("defaultMethod", contract["~orpc"].route.method);
|
|
96
|
-
const httpPath = contract["~orpc"].route.path ? toRou3Pattern(contract["~orpc"].route.path) : convertPathToHttpPath(path2);
|
|
86
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
|
87
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
88
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
97
89
|
if (isProcedure(contract)) {
|
|
98
90
|
addRoute(this.tree, method, httpPath, {
|
|
99
91
|
path: path2,
|
|
@@ -113,8 +105,8 @@ var OpenAPIMatcher = class {
|
|
|
113
105
|
});
|
|
114
106
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
115
107
|
...option,
|
|
116
|
-
httpPathPrefix:
|
|
117
|
-
laziedPrefix:
|
|
108
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
109
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
118
110
|
})));
|
|
119
111
|
}
|
|
120
112
|
async match(method, pathname) {
|
|
@@ -122,7 +114,7 @@ var OpenAPIMatcher = class {
|
|
|
122
114
|
const newPendingRouters = [];
|
|
123
115
|
for (const pendingRouter of this.pendingRouters) {
|
|
124
116
|
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
125
|
-
const { default: router } = await unlazy(pendingRouter.
|
|
117
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
|
126
118
|
this.init(router, pendingRouter.path);
|
|
127
119
|
} else {
|
|
128
120
|
newPendingRouters.push(pendingRouter);
|
|
@@ -135,14 +127,14 @@ var OpenAPIMatcher = class {
|
|
|
135
127
|
return void 0;
|
|
136
128
|
}
|
|
137
129
|
if (!match.data.procedure) {
|
|
138
|
-
const { default: maybeProcedure } = await unlazy(
|
|
130
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
139
131
|
if (!isProcedure(maybeProcedure)) {
|
|
140
132
|
throw new Error(`
|
|
141
|
-
[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)}.
|
|
142
134
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
143
135
|
`);
|
|
144
136
|
}
|
|
145
|
-
match.data.procedure = createContractedProcedure(match.data.contract
|
|
137
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
146
138
|
}
|
|
147
139
|
return {
|
|
148
140
|
path: match.data.path,
|
|
@@ -150,16 +142,17 @@ var OpenAPIMatcher = class {
|
|
|
150
142
|
params: match.params ? decodeParams(match.params) : void 0
|
|
151
143
|
};
|
|
152
144
|
}
|
|
153
|
-
};
|
|
154
|
-
function toRou3Pattern(path) {
|
|
155
|
-
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "**:$1").replace(/\{([^}]+)\}/g, ":$1");
|
|
156
145
|
}
|
|
157
|
-
|
|
158
|
-
|
|
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
|
+
}
|
|
159
156
|
}
|
|
160
157
|
|
|
161
|
-
export {
|
|
162
|
-
OpenAPICodec,
|
|
163
|
-
OpenAPIMatcher
|
|
164
|
-
};
|
|
165
|
-
//# sourceMappingURL=chunk-LPBZEW4B.js.map
|
|
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.ff41b3a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,61 +15,45 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
22
|
"./standard": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/standard.
|
|
25
|
-
"default": "./dist/standard.
|
|
23
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
24
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
25
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
26
26
|
},
|
|
27
27
|
"./fetch": {
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/fetch.
|
|
30
|
-
"default": "./dist/fetch.
|
|
31
|
-
},
|
|
32
|
-
"./hono": {
|
|
33
|
-
"types": "./dist/src/adapters/hono/index.d.ts",
|
|
34
|
-
"import": "./dist/hono.js",
|
|
35
|
-
"default": "./dist/hono.js"
|
|
36
|
-
},
|
|
37
|
-
"./next": {
|
|
38
|
-
"types": "./dist/src/adapters/next/index.d.ts",
|
|
39
|
-
"import": "./dist/next.js",
|
|
40
|
-
"default": "./dist/next.js"
|
|
28
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
41
31
|
},
|
|
42
32
|
"./node": {
|
|
43
|
-
"types": "./dist/
|
|
44
|
-
"import": "./dist/node.
|
|
45
|
-
"default": "./dist/node.
|
|
46
|
-
},
|
|
47
|
-
"./🔒/*": {
|
|
48
|
-
"types": "./dist/src/*.d.ts"
|
|
33
|
+
"types": "./dist/adapters/node/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/node/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/node/index.mjs"
|
|
49
36
|
}
|
|
50
37
|
},
|
|
51
38
|
"files": [
|
|
52
|
-
"!**/*.map",
|
|
53
|
-
"!**/*.tsbuildinfo",
|
|
54
39
|
"dist"
|
|
55
40
|
],
|
|
56
41
|
"dependencies": {
|
|
57
|
-
"@orpc/server-standard": "^0.4.0",
|
|
58
|
-
"@orpc/server-standard-fetch": "^0.4.0",
|
|
59
|
-
"@orpc/server-standard-node": "^0.4.0",
|
|
60
42
|
"json-schema-typed": "^8.0.1",
|
|
61
|
-
"
|
|
62
|
-
"rou3": "^0.
|
|
63
|
-
"@orpc/client": "0.0.0-next.
|
|
64
|
-
"@orpc/contract": "0.0.0-next.
|
|
65
|
-
"@orpc/
|
|
66
|
-
"@orpc/
|
|
43
|
+
"openapi-types": "^12.1.3",
|
|
44
|
+
"rou3": "^0.6.0",
|
|
45
|
+
"@orpc/client": "0.0.0-next.ff41b3a",
|
|
46
|
+
"@orpc/contract": "0.0.0-next.ff41b3a",
|
|
47
|
+
"@orpc/server": "0.0.0-next.ff41b3a",
|
|
48
|
+
"@orpc/openapi-client": "0.0.0-next.ff41b3a",
|
|
49
|
+
"@orpc/shared": "0.0.0-next.ff41b3a",
|
|
50
|
+
"@orpc/standard-server": "0.0.0-next.ff41b3a"
|
|
67
51
|
},
|
|
68
52
|
"devDependencies": {
|
|
69
|
-
"zod": "^3.24.
|
|
53
|
+
"zod": "^3.24.2"
|
|
70
54
|
},
|
|
71
55
|
"scripts": {
|
|
72
|
-
"build": "
|
|
56
|
+
"build": "unbuild",
|
|
73
57
|
"build:watch": "pnpm run build --watch",
|
|
74
58
|
"type:check": "tsc -b"
|
|
75
59
|
}
|
package/dist/chunk-UU2TTVB2.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OpenAPICodec,
|
|
3
|
-
OpenAPIMatcher
|
|
4
|
-
} from "./chunk-LPBZEW4B.js";
|
|
5
|
-
|
|
6
|
-
// src/adapters/fetch/openapi-handler.ts
|
|
7
|
-
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
|
8
|
-
import { StandardHandler } from "@orpc/server/standard";
|
|
9
|
-
var OpenAPIHandler = class {
|
|
10
|
-
standardHandler;
|
|
11
|
-
constructor(router, options) {
|
|
12
|
-
const matcher = options?.matcher ?? new OpenAPIMatcher(options);
|
|
13
|
-
const codec = options?.codec ?? new OpenAPICodec(options);
|
|
14
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
15
|
-
}
|
|
16
|
-
async handle(request, ...rest) {
|
|
17
|
-
const standardRequest = toStandardRequest(request);
|
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
19
|
-
if (!result.matched) {
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
matched: true,
|
|
24
|
-
response: toFetchResponse(result.response)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
OpenAPIHandler
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=chunk-UU2TTVB2.js.map
|
package/dist/chunk-XGHV4TH3.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
function standardizeHTTPPath(path) {
|
|
3
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
4
|
-
}
|
|
5
|
-
function toOpenAPI31RoutePattern(path) {
|
|
6
|
-
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
standardizeHTTPPath,
|
|
11
|
-
toOpenAPI31RoutePattern
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=chunk-XGHV4TH3.js.map
|
package/dist/fetch.js
DELETED