@orpc/openapi 0.0.0-next.f22c7ec → 0.0.0-next.f47352c
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 +104 -0
- package/dist/adapters/fetch/index.d.mts +11 -0
- package/dist/adapters/fetch/index.d.ts +11 -0
- package/dist/adapters/fetch/index.mjs +10 -0
- package/dist/adapters/hono/index.d.mts +6 -0
- package/dist/adapters/hono/index.d.ts +6 -0
- package/dist/adapters/hono/index.mjs +10 -0
- package/dist/adapters/next/index.d.mts +6 -0
- package/dist/adapters/next/index.d.ts +6 -0
- package/dist/adapters/next/index.mjs +10 -0
- package/dist/adapters/node/index.d.mts +11 -0
- package/dist/adapters/node/index.d.ts +11 -0
- package/dist/adapters/node/index.mjs +22 -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 +7 -0
- package/dist/index.d.mts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.mjs +536 -0
- package/dist/shared/openapi.CGZ7t-VN.mjs +17 -0
- package/dist/shared/openapi.IfmmOyba.d.mts +8 -0
- package/dist/shared/openapi.IfmmOyba.d.ts +8 -0
- package/dist/shared/openapi.sdeu0I7N.mjs +146 -0
- package/package.json +31 -35
- package/dist/chunk-N7JLIFHD.js +0 -25
- package/dist/chunk-TW72MGM2.js +0 -651
- package/dist/chunk-V4HFPIEN.js +0 -107
- package/dist/fetch.js +0 -34
- package/dist/hono.js +0 -34
- package/dist/index.js +0 -550
- package/dist/next.js +0 -34
- package/dist/node.js +0 -46
- package/dist/src/adapters/fetch/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/fetch/index.d.ts +0 -10
- 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-handler.d.ts +0 -32
- 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/fetch/schema-coercer.d.ts +0 -10
- 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 -5
- 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/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -2
- package/dist/src/index.d.ts +0 -12
- package/dist/src/json-serializer.d.ts +0 -5
- 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-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 -18
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { fallbackContractConfig } from '@orpc/contract';
|
|
2
|
+
import { isObject } from '@orpc/shared';
|
|
3
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
4
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
5
|
+
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
6
|
+
import { standardizeHTTPPath } from '@orpc/openapi-client/standard';
|
|
7
|
+
|
|
8
|
+
class StandardOpenAPICodec {
|
|
9
|
+
constructor(serializer) {
|
|
10
|
+
this.serializer = serializer;
|
|
11
|
+
}
|
|
12
|
+
async decode(request, params, procedure) {
|
|
13
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
14
|
+
if (inputStructure === "compact") {
|
|
15
|
+
const data = request.method === "GET" ? this.serializer.deserialize(request.url.searchParams) : this.serializer.deserialize(await request.body());
|
|
16
|
+
if (data === void 0) {
|
|
17
|
+
return params;
|
|
18
|
+
}
|
|
19
|
+
if (isObject(data)) {
|
|
20
|
+
return {
|
|
21
|
+
...params,
|
|
22
|
+
...data
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
const deserializeSearchParams = () => {
|
|
28
|
+
return this.serializer.deserialize(request.url.searchParams);
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
params,
|
|
32
|
+
get query() {
|
|
33
|
+
const value = deserializeSearchParams();
|
|
34
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
35
|
+
return value;
|
|
36
|
+
},
|
|
37
|
+
set query(value) {
|
|
38
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
39
|
+
},
|
|
40
|
+
headers: request.headers,
|
|
41
|
+
body: this.serializer.deserialize(await request.body())
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
encode(output, procedure) {
|
|
45
|
+
const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
|
|
46
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
47
|
+
if (outputStructure === "compact") {
|
|
48
|
+
return {
|
|
49
|
+
status: successStatus,
|
|
50
|
+
headers: {},
|
|
51
|
+
body: this.serializer.serialize(output)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (!isObject(output)) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
status: successStatus,
|
|
61
|
+
headers: output.headers ?? {},
|
|
62
|
+
body: this.serializer.serialize(output.body)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
encodeError(error) {
|
|
66
|
+
return {
|
|
67
|
+
status: error.status,
|
|
68
|
+
headers: {},
|
|
69
|
+
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function toRou3Pattern(path) {
|
|
75
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
76
|
+
}
|
|
77
|
+
function decodeParams(params) {
|
|
78
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
class StandardOpenAPIMatcher {
|
|
82
|
+
tree = createRouter();
|
|
83
|
+
pendingRouters = [];
|
|
84
|
+
init(router, path = []) {
|
|
85
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
|
86
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
87
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
88
|
+
if (isProcedure(contract)) {
|
|
89
|
+
addRoute(this.tree, method, httpPath, {
|
|
90
|
+
path: path2,
|
|
91
|
+
contract,
|
|
92
|
+
procedure: contract,
|
|
93
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
|
94
|
+
router
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
addRoute(this.tree, method, httpPath, {
|
|
98
|
+
path: path2,
|
|
99
|
+
contract,
|
|
100
|
+
procedure: void 0,
|
|
101
|
+
router
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
106
|
+
...option,
|
|
107
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
108
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
109
|
+
})));
|
|
110
|
+
}
|
|
111
|
+
async match(method, pathname) {
|
|
112
|
+
if (this.pendingRouters.length) {
|
|
113
|
+
const newPendingRouters = [];
|
|
114
|
+
for (const pendingRouter of this.pendingRouters) {
|
|
115
|
+
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
116
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
|
117
|
+
this.init(router, pendingRouter.path);
|
|
118
|
+
} else {
|
|
119
|
+
newPendingRouters.push(pendingRouter);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
this.pendingRouters = newPendingRouters;
|
|
123
|
+
}
|
|
124
|
+
const match = findRoute(this.tree, method, pathname);
|
|
125
|
+
if (!match) {
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
if (!match.data.procedure) {
|
|
129
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
130
|
+
if (!isProcedure(maybeProcedure)) {
|
|
131
|
+
throw new Error(`
|
|
132
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
|
133
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
path: match.data.path,
|
|
140
|
+
procedure: match.data.procedure,
|
|
141
|
+
params: match.params ? decodeParams(match.params) : void 0
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIMatcher as a, 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.f47352c",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,59 +15,55 @@
|
|
|
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
|
+
},
|
|
22
|
+
"./standard": {
|
|
23
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
24
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
25
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
21
26
|
},
|
|
22
27
|
"./fetch": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/fetch.
|
|
25
|
-
"default": "./dist/fetch.
|
|
28
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
26
31
|
},
|
|
27
32
|
"./hono": {
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/hono.
|
|
30
|
-
"default": "./dist/hono.
|
|
33
|
+
"types": "./dist/adapters/hono/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/hono/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/hono/index.mjs"
|
|
31
36
|
},
|
|
32
37
|
"./next": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/next.
|
|
35
|
-
"default": "./dist/next.
|
|
38
|
+
"types": "./dist/adapters/next/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/next/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/next/index.mjs"
|
|
36
41
|
},
|
|
37
42
|
"./node": {
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"import": "./dist/node.
|
|
40
|
-
"default": "./dist/node.
|
|
41
|
-
},
|
|
42
|
-
"./🔒/*": {
|
|
43
|
-
"types": "./dist/src/*.d.ts"
|
|
43
|
+
"types": "./dist/adapters/node/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/node/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/node/index.mjs"
|
|
44
46
|
}
|
|
45
47
|
},
|
|
46
48
|
"files": [
|
|
47
|
-
"!**/*.map",
|
|
48
|
-
"!**/*.tsbuildinfo",
|
|
49
49
|
"dist"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@standard-schema/spec": "1.0.0-beta.4",
|
|
53
|
-
"@types/content-disposition": "^0.5.8",
|
|
54
|
-
"content-disposition": "^0.5.4",
|
|
55
|
-
"escape-string-regexp": "^5.0.0",
|
|
56
|
-
"fast-content-type-parse": "^2.0.0",
|
|
57
|
-
"hono": "^4.6.12",
|
|
58
52
|
"json-schema-typed": "^8.0.1",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"@orpc/
|
|
62
|
-
"@orpc/
|
|
63
|
-
"@orpc/
|
|
53
|
+
"openapi-types": "^12.1.3",
|
|
54
|
+
"rou3": "^0.5.1",
|
|
55
|
+
"@orpc/client": "0.0.0-next.f47352c",
|
|
56
|
+
"@orpc/server": "0.0.0-next.f47352c",
|
|
57
|
+
"@orpc/contract": "0.0.0-next.f47352c",
|
|
58
|
+
"@orpc/shared": "0.0.0-next.f47352c",
|
|
59
|
+
"@orpc/standard-server": "0.0.0-next.f47352c",
|
|
60
|
+
"@orpc/openapi-client": "0.0.0-next.f47352c"
|
|
64
61
|
},
|
|
65
62
|
"devDependencies": {
|
|
66
|
-
"
|
|
67
|
-
"zod": "^3.24.1"
|
|
63
|
+
"zod": "^3.24.2"
|
|
68
64
|
},
|
|
69
65
|
"scripts": {
|
|
70
|
-
"build": "
|
|
66
|
+
"build": "unbuild",
|
|
71
67
|
"build:watch": "pnpm run build --watch",
|
|
72
68
|
"type:check": "tsc -b"
|
|
73
69
|
}
|
package/dist/chunk-N7JLIFHD.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OpenAPIHandler
|
|
3
|
-
} from "./chunk-TW72MGM2.js";
|
|
4
|
-
|
|
5
|
-
// src/adapters/fetch/openapi-handler-server.ts
|
|
6
|
-
import { TrieRouter } from "hono/router/trie-router";
|
|
7
|
-
var OpenAPIServerHandler = class extends OpenAPIHandler {
|
|
8
|
-
constructor(router, options) {
|
|
9
|
-
super(new TrieRouter(), router, options);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// src/adapters/fetch/openapi-handler-serverless.ts
|
|
14
|
-
import { LinearRouter } from "hono/router/linear-router";
|
|
15
|
-
var OpenAPIServerlessHandler = class extends OpenAPIHandler {
|
|
16
|
-
constructor(router, options) {
|
|
17
|
-
super(new LinearRouter(), router, options);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
OpenAPIServerHandler,
|
|
23
|
-
OpenAPIServerlessHandler
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=chunk-N7JLIFHD.js.map
|