@orpc/openapi 0.0.0-next.427bff4 → 0.0.0-next.42e1669
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 +18 -22
- package/dist/adapters/aws-lambda/index.d.mts +19 -0
- package/dist/adapters/aws-lambda/index.d.ts +19 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fetch/index.d.mts +9 -1
- package/dist/adapters/fetch/index.d.ts +9 -1
- package/dist/adapters/fetch/index.mjs +14 -7
- package/dist/adapters/node/index.d.mts +9 -1
- package/dist/adapters/node/index.d.ts +9 -1
- package/dist/adapters/node/index.mjs +7 -12
- package/dist/adapters/standard/index.d.mts +7 -13
- package/dist/adapters/standard/index.d.ts +7 -13
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/index.d.mts +37 -47
- package/dist/index.d.ts +37 -47
- package/dist/index.mjs +30 -292
- package/dist/plugins/index.d.mts +69 -0
- package/dist/plugins/index.d.ts +69 -0
- package/dist/plugins/index.mjs +108 -0
- package/dist/shared/{openapi.BNHmrMe2.mjs → openapi.BVXcB0u4.mjs} +54 -12
- package/dist/shared/openapi.BtoY8ZFF.mjs +742 -0
- package/dist/shared/openapi.CQmjvnb0.d.mts +31 -0
- package/dist/shared/openapi.CQmjvnb0.d.ts +31 -0
- package/dist/shared/openapi.DPAN3GVs.d.mts +108 -0
- package/dist/shared/openapi.DPAN3GVs.d.ts +108 -0
- package/package.json +19 -20
- 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 -11
- 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 -11
- package/dist/shared/openapi.DZzpQAb-.mjs +0 -231
- package/dist/shared/openapi.G9ZZkQ6q.mjs +0 -19
- package/dist/shared/openapi.IfmmOyba.d.mts +0 -8
- package/dist/shared/openapi.IfmmOyba.d.ts +0 -8
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
+
import { isORPCErrorStatus } from '@orpc/client';
|
|
1
4
|
import { fallbackContractConfig } from '@orpc/contract';
|
|
2
|
-
import { isObject } from '@orpc/shared';
|
|
3
|
-
import {
|
|
5
|
+
import { isObject, stringifyJSON, tryDecodeURIComponent, value } from '@orpc/shared';
|
|
6
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
7
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
4
8
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
5
|
-
import { s as standardizeHTTPPath } from './openapi.DZzpQAb-.mjs';
|
|
6
9
|
|
|
7
10
|
class StandardOpenAPICodec {
|
|
8
11
|
constructor(serializer) {
|
|
@@ -50,13 +53,21 @@ class StandardOpenAPICodec {
|
|
|
50
53
|
body: this.serializer.serialize(output)
|
|
51
54
|
};
|
|
52
55
|
}
|
|
53
|
-
if (!
|
|
54
|
-
throw new Error(
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if (!this.#isDetailedOutput(output)) {
|
|
57
|
+
throw new Error(`
|
|
58
|
+
Invalid "detailed" output structure:
|
|
59
|
+
\u2022 Expected an object with optional properties:
|
|
60
|
+
- status (number 200-399)
|
|
61
|
+
- headers (Record<string, string | string[]>)
|
|
62
|
+
- body (any)
|
|
63
|
+
\u2022 No extra keys allowed.
|
|
64
|
+
|
|
65
|
+
Actual value:
|
|
66
|
+
${stringifyJSON(output)}
|
|
67
|
+
`);
|
|
57
68
|
}
|
|
58
69
|
return {
|
|
59
|
-
status: successStatus,
|
|
70
|
+
status: output.status ?? successStatus,
|
|
60
71
|
headers: output.headers ?? {},
|
|
61
72
|
body: this.serializer.serialize(output.body)
|
|
62
73
|
};
|
|
@@ -65,23 +76,43 @@ class StandardOpenAPICodec {
|
|
|
65
76
|
return {
|
|
66
77
|
status: error.status,
|
|
67
78
|
headers: {},
|
|
68
|
-
body: this.serializer.serialize(error.toJSON())
|
|
79
|
+
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
|
69
80
|
};
|
|
70
81
|
}
|
|
82
|
+
#isDetailedOutput(output) {
|
|
83
|
+
if (!isObject(output)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (output.headers && !isObject(output.headers)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
71
94
|
}
|
|
72
95
|
|
|
73
96
|
function toRou3Pattern(path) {
|
|
74
97
|
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
75
98
|
}
|
|
76
99
|
function decodeParams(params) {
|
|
77
|
-
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key,
|
|
100
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)]));
|
|
78
101
|
}
|
|
79
102
|
|
|
80
103
|
class StandardOpenAPIMatcher {
|
|
104
|
+
filter;
|
|
81
105
|
tree = createRouter();
|
|
82
106
|
pendingRouters = [];
|
|
107
|
+
constructor(options = {}) {
|
|
108
|
+
this.filter = options.filter ?? true;
|
|
109
|
+
}
|
|
83
110
|
init(router, path = []) {
|
|
84
|
-
const laziedOptions = traverseContractProcedures({ router, path }, (
|
|
111
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
|
112
|
+
if (!value(this.filter, traverseOptions)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const { path: path2, contract } = traverseOptions;
|
|
85
116
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
86
117
|
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
87
118
|
if (isProcedure(contract)) {
|
|
@@ -142,4 +173,15 @@ class StandardOpenAPIMatcher {
|
|
|
142
173
|
}
|
|
143
174
|
}
|
|
144
175
|
|
|
145
|
-
|
|
176
|
+
class StandardOpenAPIHandler extends StandardHandler {
|
|
177
|
+
constructor(router, options) {
|
|
178
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
179
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer(options);
|
|
180
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
181
|
+
const matcher = new StandardOpenAPIMatcher(options);
|
|
182
|
+
const codec = new StandardOpenAPICodec(serializer);
|
|
183
|
+
super(router, matcher, codec, options);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIHandler as a, StandardOpenAPIMatcher as b, decodeParams as d, toRou3Pattern as t };
|