@orpc/openapi 1.14.11 → 1.14.12
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 +71 -52
- package/dist/adapters/aws-lambda/index.d.mts +20 -0
- package/dist/adapters/aws-lambda/index.d.ts +20 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fastify/index.d.mts +23 -0
- package/dist/adapters/fastify/index.d.ts +23 -0
- package/dist/adapters/fastify/index.mjs +18 -0
- package/dist/adapters/fetch/index.d.mts +16 -20
- package/dist/adapters/fetch/index.d.ts +16 -20
- package/dist/adapters/fetch/index.mjs +8 -24
- package/dist/adapters/node/index.d.mts +13 -8
- package/dist/adapters/node/index.d.ts +13 -8
- package/dist/adapters/node/index.mjs +7 -10
- package/dist/adapters/standard/index.d.mts +16 -46
- package/dist/adapters/standard/index.d.ts +16 -46
- package/dist/adapters/standard/index.mjs +6 -9
- package/dist/index.d.mts +105 -117
- package/dist/index.d.ts +105 -117
- package/dist/index.mjs +32 -850
- package/dist/plugins/index.d.mts +51 -55
- package/dist/plugins/index.d.ts +51 -55
- package/dist/plugins/index.mjs +142 -147
- package/dist/shared/openapi.BGy4N6eR.d.mts +120 -0
- package/dist/shared/openapi.BGy4N6eR.d.ts +120 -0
- package/dist/shared/openapi.BwdtJjDu.mjs +878 -0
- package/dist/shared/openapi.CdeSk3f7.d.mts +54 -0
- package/dist/shared/openapi.CdeSk3f7.d.ts +54 -0
- package/dist/shared/openapi.DPiCV5hl.mjs +208 -0
- package/package.json +24 -46
- package/dist/extensions/route.d.mts +0 -43
- package/dist/extensions/route.d.ts +0 -43
- package/dist/extensions/route.mjs +0 -14
- package/dist/helpers/index.d.mts +0 -51
- package/dist/helpers/index.d.ts +0 -51
- package/dist/helpers/index.mjs +0 -39
- package/dist/shared/openapi.B6hEbRyF.d.ts +0 -83
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.BOOA-bde.d.mts +0 -142
- package/dist/shared/openapi.BOOA-bde.d.ts +0 -142
- package/dist/shared/openapi.BafbB3uM.d.mts +0 -83
- package/dist/shared/openapi.Bt87OzTt.mjs +0 -131
- package/dist/shared/openapi.ByT4oUeY.d.mts +0 -18
- package/dist/shared/openapi.ByT4oUeY.d.ts +0 -18
- package/dist/shared/openapi.C-p_Q2lb.mjs +0 -359
- package/dist/shared/openapi.CVgUshDP.mjs +0 -318
- package/dist/shared/openapi.DNNo0V-l.d.ts +0 -313
- package/dist/shared/openapi.hg_rhZ4x.d.mts +0 -313
- package/dist/shared/openapi.zZH_UksW.mjs +0 -278
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { StandardOpenAPISerializer, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult, StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
|
+
import { Value } from '@orpc/shared';
|
|
7
|
+
|
|
8
|
+
interface StandardOpenAPICodecOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Customize how an ORPC error is encoded into a response body.
|
|
11
|
+
* Use this if your API needs a different error output structure.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* - Return `null | undefined` to fallback to default behavior
|
|
15
|
+
*
|
|
16
|
+
* @default ((e) => e.toJSON())
|
|
17
|
+
*/
|
|
18
|
+
customErrorResponseBodyEncoder?: (error: ORPCError<any, any>) => unknown;
|
|
19
|
+
}
|
|
20
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
|
21
|
+
#private;
|
|
22
|
+
private readonly serializer;
|
|
23
|
+
private readonly customErrorResponseBodyEncoder;
|
|
24
|
+
constructor(serializer: StandardOpenAPISerializer, options?: StandardOpenAPICodecOptions);
|
|
25
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
26
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
27
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface StandardOpenAPIMatcherOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
37
|
+
}
|
|
38
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
39
|
+
private readonly filter;
|
|
40
|
+
private readonly tree;
|
|
41
|
+
private readonly pendingRouters;
|
|
42
|
+
constructor(options?: StandardOpenAPIMatcherOptions);
|
|
43
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
|
44
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions, StandardOpenAPIMatcherOptions, StandardOpenAPICodecOptions {
|
|
48
|
+
}
|
|
49
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
50
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { StandardOpenAPICodec as a, StandardOpenAPIHandler as c, StandardOpenAPIMatcher as e };
|
|
54
|
+
export type { StandardOpenAPICodecOptions as S, StandardOpenAPIHandlerOptions as b, StandardOpenAPIMatcherOptions as d };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { StandardOpenAPISerializer, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult, StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
|
5
|
+
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
|
+
import { Value } from '@orpc/shared';
|
|
7
|
+
|
|
8
|
+
interface StandardOpenAPICodecOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Customize how an ORPC error is encoded into a response body.
|
|
11
|
+
* Use this if your API needs a different error output structure.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* - Return `null | undefined` to fallback to default behavior
|
|
15
|
+
*
|
|
16
|
+
* @default ((e) => e.toJSON())
|
|
17
|
+
*/
|
|
18
|
+
customErrorResponseBodyEncoder?: (error: ORPCError<any, any>) => unknown;
|
|
19
|
+
}
|
|
20
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
|
21
|
+
#private;
|
|
22
|
+
private readonly serializer;
|
|
23
|
+
private readonly customErrorResponseBodyEncoder;
|
|
24
|
+
constructor(serializer: StandardOpenAPISerializer, options?: StandardOpenAPICodecOptions);
|
|
25
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
26
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
27
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface StandardOpenAPIMatcherOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
37
|
+
}
|
|
38
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
39
|
+
private readonly filter;
|
|
40
|
+
private readonly tree;
|
|
41
|
+
private readonly pendingRouters;
|
|
42
|
+
constructor(options?: StandardOpenAPIMatcherOptions);
|
|
43
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
|
44
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions, StandardOpenAPIMatcherOptions, StandardOpenAPICodecOptions {
|
|
48
|
+
}
|
|
49
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
50
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { StandardOpenAPICodec as a, StandardOpenAPIHandler as c, StandardOpenAPIMatcher as e };
|
|
54
|
+
export type { StandardOpenAPICodecOptions as S, StandardOpenAPIHandlerOptions as b, StandardOpenAPIMatcherOptions as d };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
+
import { isORPCErrorStatus } from '@orpc/client';
|
|
4
|
+
import { fallbackContractConfig } from '@orpc/contract';
|
|
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';
|
|
8
|
+
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
9
|
+
|
|
10
|
+
class StandardOpenAPICodec {
|
|
11
|
+
constructor(serializer, options = {}) {
|
|
12
|
+
this.serializer = serializer;
|
|
13
|
+
this.customErrorResponseBodyEncoder = options.customErrorResponseBodyEncoder;
|
|
14
|
+
}
|
|
15
|
+
customErrorResponseBodyEncoder;
|
|
16
|
+
async decode(request, params, procedure) {
|
|
17
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
18
|
+
if (inputStructure === "compact") {
|
|
19
|
+
const data = request.method === "GET" ? this.serializer.deserialize(request.url.searchParams) : this.serializer.deserialize(await request.body());
|
|
20
|
+
if (data === void 0) {
|
|
21
|
+
return params;
|
|
22
|
+
}
|
|
23
|
+
if (isObject(data)) {
|
|
24
|
+
return {
|
|
25
|
+
...params,
|
|
26
|
+
...data
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
const deserializeSearchParams = () => {
|
|
32
|
+
return this.serializer.deserialize(request.url.searchParams);
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
params,
|
|
36
|
+
get query() {
|
|
37
|
+
const value = deserializeSearchParams();
|
|
38
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
39
|
+
return value;
|
|
40
|
+
},
|
|
41
|
+
set query(value) {
|
|
42
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
43
|
+
},
|
|
44
|
+
headers: request.headers,
|
|
45
|
+
body: this.serializer.deserialize(await request.body())
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
encode(output, procedure) {
|
|
49
|
+
const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
|
|
50
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
51
|
+
if (outputStructure === "compact") {
|
|
52
|
+
if (output instanceof ReadableStream) {
|
|
53
|
+
return {
|
|
54
|
+
status: successStatus,
|
|
55
|
+
headers: {},
|
|
56
|
+
body: output
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
status: successStatus,
|
|
61
|
+
headers: {},
|
|
62
|
+
body: this.serializer.serialize(output)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (!this.#isDetailedOutput(output)) {
|
|
66
|
+
throw new Error(`
|
|
67
|
+
Invalid "detailed" output structure:
|
|
68
|
+
\u2022 Expected an object with optional properties:
|
|
69
|
+
- status (number 200-399)
|
|
70
|
+
- headers (Record<string, string | string[]>)
|
|
71
|
+
- body (any)
|
|
72
|
+
\u2022 No extra keys allowed.
|
|
73
|
+
|
|
74
|
+
Actual value:
|
|
75
|
+
${stringifyJSON(output)}
|
|
76
|
+
`);
|
|
77
|
+
}
|
|
78
|
+
if (output.body instanceof ReadableStream) {
|
|
79
|
+
return {
|
|
80
|
+
status: output.status ?? successStatus,
|
|
81
|
+
headers: output.headers ?? {},
|
|
82
|
+
body: output.body
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
status: output.status ?? successStatus,
|
|
87
|
+
headers: output.headers ?? {},
|
|
88
|
+
body: this.serializer.serialize(output.body)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
encodeError(error) {
|
|
92
|
+
const body = this.customErrorResponseBodyEncoder?.(error) ?? error.toJSON();
|
|
93
|
+
return {
|
|
94
|
+
status: error.status,
|
|
95
|
+
headers: {},
|
|
96
|
+
body: this.serializer.serialize(body, { outputFormat: "plain" })
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
#isDetailedOutput(output) {
|
|
100
|
+
if (!isObject(output)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (output.headers && !isObject(output.headers)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function toRou3Pattern(path) {
|
|
114
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
115
|
+
}
|
|
116
|
+
function decodeParams(params) {
|
|
117
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)]));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
class StandardOpenAPIMatcher {
|
|
121
|
+
filter;
|
|
122
|
+
tree = createRouter();
|
|
123
|
+
pendingRouters = [];
|
|
124
|
+
constructor(options = {}) {
|
|
125
|
+
this.filter = options.filter ?? true;
|
|
126
|
+
}
|
|
127
|
+
init(router, path = []) {
|
|
128
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
|
129
|
+
if (!value(this.filter, traverseOptions)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const { path: path2, contract } = traverseOptions;
|
|
133
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
134
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
135
|
+
if (isProcedure(contract)) {
|
|
136
|
+
addRoute(this.tree, method, httpPath, {
|
|
137
|
+
path: path2,
|
|
138
|
+
contract,
|
|
139
|
+
procedure: contract,
|
|
140
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
|
141
|
+
router
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
addRoute(this.tree, method, httpPath, {
|
|
145
|
+
path: path2,
|
|
146
|
+
contract,
|
|
147
|
+
procedure: void 0,
|
|
148
|
+
router
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
153
|
+
...option,
|
|
154
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
155
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
156
|
+
})));
|
|
157
|
+
}
|
|
158
|
+
async match(method, pathname) {
|
|
159
|
+
while (true) {
|
|
160
|
+
const pendingRouter = this.pendingRouters.find(
|
|
161
|
+
(pendingRouter2) => !pendingRouter2.laziedPrefix || pathname.startsWith(pendingRouter2.laziedPrefix) || pathname.startsWith(pendingRouter2.httpPathPrefix)
|
|
162
|
+
);
|
|
163
|
+
if (!pendingRouter) {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
pendingRouter.initPromise ??= unlazy(pendingRouter.router).then(({ default: router }) => {
|
|
167
|
+
this.init(router, pendingRouter.path);
|
|
168
|
+
this.pendingRouters.splice(this.pendingRouters.indexOf(pendingRouter), 1);
|
|
169
|
+
}).catch((error) => {
|
|
170
|
+
pendingRouter.initPromise = void 0;
|
|
171
|
+
throw error;
|
|
172
|
+
});
|
|
173
|
+
await pendingRouter.initPromise;
|
|
174
|
+
}
|
|
175
|
+
const match = findRoute(this.tree, method, pathname);
|
|
176
|
+
if (!match) {
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
if (!match.data.procedure) {
|
|
180
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
181
|
+
if (!isProcedure(maybeProcedure)) {
|
|
182
|
+
throw new Error(`
|
|
183
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
|
184
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
185
|
+
`);
|
|
186
|
+
}
|
|
187
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
path: match.data.path,
|
|
191
|
+
procedure: match.data.procedure,
|
|
192
|
+
params: match.params ? decodeParams(match.params) : void 0
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class StandardOpenAPIHandler extends StandardHandler {
|
|
198
|
+
constructor(router, options) {
|
|
199
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
200
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer(options);
|
|
201
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
202
|
+
const matcher = new StandardOpenAPIMatcher(options);
|
|
203
|
+
const codec = new StandardOpenAPICodec(serializer, options);
|
|
204
|
+
super(router, matcher, codec, options);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
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": "1.14.
|
|
4
|
+
"version": "1.14.12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -10,24 +10,15 @@
|
|
|
10
10
|
"directory": "packages/openapi"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
|
-
"orpc"
|
|
14
|
-
"openapi"
|
|
15
|
-
],
|
|
16
|
-
"sideEffects": [
|
|
17
|
-
"./dist/extensions/route.mjs"
|
|
13
|
+
"orpc"
|
|
18
14
|
],
|
|
15
|
+
"sideEffects": false,
|
|
19
16
|
"exports": {
|
|
20
|
-
"./package.json": "./package.json",
|
|
21
17
|
".": {
|
|
22
18
|
"types": "./dist/index.d.mts",
|
|
23
19
|
"import": "./dist/index.mjs",
|
|
24
20
|
"default": "./dist/index.mjs"
|
|
25
21
|
},
|
|
26
|
-
"./helpers": {
|
|
27
|
-
"types": "./dist/helpers/index.d.mts",
|
|
28
|
-
"import": "./dist/helpers/index.mjs",
|
|
29
|
-
"default": "./dist/helpers/index.mjs"
|
|
30
|
-
},
|
|
31
22
|
"./plugins": {
|
|
32
23
|
"types": "./dist/plugins/index.d.mts",
|
|
33
24
|
"import": "./dist/plugins/index.mjs",
|
|
@@ -48,51 +39,38 @@
|
|
|
48
39
|
"import": "./dist/adapters/node/index.mjs",
|
|
49
40
|
"default": "./dist/adapters/node/index.mjs"
|
|
50
41
|
},
|
|
51
|
-
"./
|
|
52
|
-
"types": "./dist/
|
|
53
|
-
"import": "./dist/
|
|
54
|
-
"default": "./dist/
|
|
42
|
+
"./fastify": {
|
|
43
|
+
"types": "./dist/adapters/fastify/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/fastify/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/fastify/index.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./aws-lambda": {
|
|
48
|
+
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
49
|
+
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
50
|
+
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
55
51
|
}
|
|
56
52
|
},
|
|
57
53
|
"files": [
|
|
58
54
|
"dist"
|
|
59
55
|
],
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"@scalar/api-reference": ">=1.57.2",
|
|
62
|
-
"@types/swagger-ui": ">=5.32.0",
|
|
63
|
-
"swagger-ui": ">=5.32.6"
|
|
64
|
-
},
|
|
65
|
-
"peerDependenciesMeta": {
|
|
66
|
-
"@scalar/api-reference": {
|
|
67
|
-
"optional": true
|
|
68
|
-
},
|
|
69
|
-
"@types/swagger-ui": {
|
|
70
|
-
"optional": true
|
|
71
|
-
},
|
|
72
|
-
"swagger-ui": {
|
|
73
|
-
"optional": true
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
56
|
"dependencies": {
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"@
|
|
80
|
-
"
|
|
81
|
-
"@orpc/
|
|
82
|
-
"@orpc/
|
|
83
|
-
"@orpc/
|
|
84
|
-
"@orpc/
|
|
85
|
-
"@orpc/
|
|
57
|
+
"json-schema-typed": "^8.0.2",
|
|
58
|
+
"rou3": "^0.7.12",
|
|
59
|
+
"@orpc/contract": "1.14.12",
|
|
60
|
+
"@orpc/openapi-client": "1.14.12",
|
|
61
|
+
"@orpc/interop": "1.14.12",
|
|
62
|
+
"@orpc/shared": "1.14.12",
|
|
63
|
+
"@orpc/server": "1.14.12",
|
|
64
|
+
"@orpc/client": "1.14.12",
|
|
65
|
+
"@orpc/standard-server": "1.14.12"
|
|
86
66
|
},
|
|
87
67
|
"devDependencies": {
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"fastify": "^5.8.5",
|
|
91
|
-
"swagger-ui": "^5.32.11",
|
|
92
|
-
"zod": "^4.4.3"
|
|
68
|
+
"fastify": "^5.8.3",
|
|
69
|
+
"zod": "^4.3.6"
|
|
93
70
|
},
|
|
94
71
|
"scripts": {
|
|
95
72
|
"build": "unbuild",
|
|
73
|
+
"build:watch": "pnpm run build --watch",
|
|
96
74
|
"type:check": "tsc -b"
|
|
97
75
|
}
|
|
98
76
|
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { ErrorMap, AnySchema } from '@orpc/contract';
|
|
3
|
-
import { Context } from '@orpc/server';
|
|
4
|
-
import { O as OpenAPIMeta } from '../shared/openapi.hg_rhZ4x.mjs';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import '@standardserver/core';
|
|
7
|
-
import '../shared/openapi.ByT4oUeY.mjs';
|
|
8
|
-
import '@hey-api/spec-types';
|
|
9
|
-
|
|
10
|
-
declare module '@orpc/contract' {
|
|
11
|
-
interface ContractBuilder<TErrorMap extends ErrorMap> {
|
|
12
|
-
route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
|
|
13
|
-
}
|
|
14
|
-
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
15
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
16
|
-
}
|
|
17
|
-
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
18
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
19
|
-
}
|
|
20
|
-
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
21
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
declare module '@orpc/server' {
|
|
25
|
-
interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
|
|
26
|
-
route(meta: OpenAPIMeta): Builder<TInitialContext, TErrorMap>;
|
|
27
|
-
}
|
|
28
|
-
interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
|
|
29
|
-
route(meta: OpenAPIMeta): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
|
|
30
|
-
}
|
|
31
|
-
interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
32
|
-
route(meta: OpenAPIMeta): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
|
|
33
|
-
}
|
|
34
|
-
interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
35
|
-
route(meta: OpenAPIMeta): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
|
|
36
|
-
}
|
|
37
|
-
interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
38
|
-
route(meta: OpenAPIMeta): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
39
|
-
}
|
|
40
|
-
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
41
|
-
route(meta: OpenAPIMeta): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { ErrorMap, AnySchema } from '@orpc/contract';
|
|
3
|
-
import { Context } from '@orpc/server';
|
|
4
|
-
import { O as OpenAPIMeta } from '../shared/openapi.DNNo0V-l.js';
|
|
5
|
-
import '@orpc/shared';
|
|
6
|
-
import '@standardserver/core';
|
|
7
|
-
import '../shared/openapi.ByT4oUeY.js';
|
|
8
|
-
import '@hey-api/spec-types';
|
|
9
|
-
|
|
10
|
-
declare module '@orpc/contract' {
|
|
11
|
-
interface ContractBuilder<TErrorMap extends ErrorMap> {
|
|
12
|
-
route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
|
|
13
|
-
}
|
|
14
|
-
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
15
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
16
|
-
}
|
|
17
|
-
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
18
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
19
|
-
}
|
|
20
|
-
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
21
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
declare module '@orpc/server' {
|
|
25
|
-
interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
|
|
26
|
-
route(meta: OpenAPIMeta): Builder<TInitialContext, TErrorMap>;
|
|
27
|
-
}
|
|
28
|
-
interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
|
|
29
|
-
route(meta: OpenAPIMeta): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
|
|
30
|
-
}
|
|
31
|
-
interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
32
|
-
route(meta: OpenAPIMeta): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
|
|
33
|
-
}
|
|
34
|
-
interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
35
|
-
route(meta: OpenAPIMeta): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
|
|
36
|
-
}
|
|
37
|
-
interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
38
|
-
route(meta: OpenAPIMeta): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
39
|
-
}
|
|
40
|
-
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
41
|
-
route(meta: OpenAPIMeta): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ContractBuilder } from '@orpc/contract';
|
|
2
|
-
import { Builder, DecoratedProcedure } from '@orpc/server';
|
|
3
|
-
import { o as openapi } from '../shared/openapi.B9PQzqBn.mjs';
|
|
4
|
-
import '@orpc/shared';
|
|
5
|
-
|
|
6
|
-
ContractBuilder.prototype.route = function route(meta) {
|
|
7
|
-
return this.meta(openapi(meta));
|
|
8
|
-
};
|
|
9
|
-
Builder.prototype.route = function route2(meta) {
|
|
10
|
-
return this.meta(openapi(meta));
|
|
11
|
-
};
|
|
12
|
-
DecoratedProcedure.prototype.route = function route3(meta) {
|
|
13
|
-
return this.meta(openapi(meta));
|
|
14
|
-
};
|
package/dist/helpers/index.d.mts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const form = new FormData()
|
|
7
|
-
* form.append('a', '1')
|
|
8
|
-
* form.append('user[name]', 'John')
|
|
9
|
-
* form.append('user[age]', '20')
|
|
10
|
-
* form.append('user[friends][]', 'Bob')
|
|
11
|
-
* form.append('user[friends][]', 'Alice')
|
|
12
|
-
* form.append('user[friends][]', 'Charlie')
|
|
13
|
-
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
14
|
-
*
|
|
15
|
-
* parseFormData(form)
|
|
16
|
-
* // {
|
|
17
|
-
* // a: '1',
|
|
18
|
-
* // user: {
|
|
19
|
-
* // name: 'John',
|
|
20
|
-
* // age: '20',
|
|
21
|
-
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
22
|
-
* // },
|
|
23
|
-
* // thumb: form.get('thumb'),
|
|
24
|
-
* // }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
declare function parseFormData(form: FormData): any;
|
|
28
|
-
/**
|
|
29
|
-
* Get the issue message from the error.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const { error, data, execute } = useServerAction(someAction)
|
|
34
|
-
*
|
|
35
|
-
* return <form action={(form) => execute(parseFormData(form))}>
|
|
36
|
-
* <input name="user[name]" type="text" />
|
|
37
|
-
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
38
|
-
*
|
|
39
|
-
* <input name="user[age]" type="number" />
|
|
40
|
-
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
41
|
-
*
|
|
42
|
-
* <input name="images[]" type="file" />
|
|
43
|
-
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
44
|
-
* </form>
|
|
45
|
-
*
|
|
46
|
-
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
47
|
-
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
|
|
48
|
-
*/
|
|
49
|
-
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
50
|
-
|
|
51
|
-
export { getIssueMessage, parseFormData };
|
package/dist/helpers/index.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const form = new FormData()
|
|
7
|
-
* form.append('a', '1')
|
|
8
|
-
* form.append('user[name]', 'John')
|
|
9
|
-
* form.append('user[age]', '20')
|
|
10
|
-
* form.append('user[friends][]', 'Bob')
|
|
11
|
-
* form.append('user[friends][]', 'Alice')
|
|
12
|
-
* form.append('user[friends][]', 'Charlie')
|
|
13
|
-
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
14
|
-
*
|
|
15
|
-
* parseFormData(form)
|
|
16
|
-
* // {
|
|
17
|
-
* // a: '1',
|
|
18
|
-
* // user: {
|
|
19
|
-
* // name: 'John',
|
|
20
|
-
* // age: '20',
|
|
21
|
-
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
22
|
-
* // },
|
|
23
|
-
* // thumb: form.get('thumb'),
|
|
24
|
-
* // }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
declare function parseFormData(form: FormData): any;
|
|
28
|
-
/**
|
|
29
|
-
* Get the issue message from the error.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const { error, data, execute } = useServerAction(someAction)
|
|
34
|
-
*
|
|
35
|
-
* return <form action={(form) => execute(parseFormData(form))}>
|
|
36
|
-
* <input name="user[name]" type="text" />
|
|
37
|
-
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
38
|
-
*
|
|
39
|
-
* <input name="user[age]" type="number" />
|
|
40
|
-
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
41
|
-
*
|
|
42
|
-
* <input name="images[]" type="file" />
|
|
43
|
-
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
44
|
-
* </form>
|
|
45
|
-
*
|
|
46
|
-
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
47
|
-
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
|
|
48
|
-
*/
|
|
49
|
-
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
50
|
-
|
|
51
|
-
export { getIssueMessage, parseFormData };
|
package/dist/helpers/index.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { isSchemaIssue } from '@orpc/contract';
|
|
2
|
-
import { isTypescriptObject } from '@orpc/shared';
|
|
3
|
-
import { B as BracketNotationSerializer } from '../shared/openapi.Bt87OzTt.mjs';
|
|
4
|
-
|
|
5
|
-
function parseFormData(form) {
|
|
6
|
-
const serializer = new BracketNotationSerializer();
|
|
7
|
-
return serializer.deserialize(Array.from(form.entries()));
|
|
8
|
-
}
|
|
9
|
-
function getIssueMessage(error, path) {
|
|
10
|
-
if (!isTypescriptObject(error) || !isTypescriptObject(error.data) || !Array.isArray(error.data.issues)) {
|
|
11
|
-
return void 0;
|
|
12
|
-
}
|
|
13
|
-
const serializer = new BracketNotationSerializer();
|
|
14
|
-
for (const issue of error.data.issues) {
|
|
15
|
-
if (!isSchemaIssue(issue)) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (issue.path === void 0) {
|
|
19
|
-
if (path === "") {
|
|
20
|
-
return issue.message;
|
|
21
|
-
}
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const issuePath = serializer.stringifyPath(
|
|
25
|
-
issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString())
|
|
26
|
-
);
|
|
27
|
-
if (issuePath === path) {
|
|
28
|
-
return issue.message;
|
|
29
|
-
}
|
|
30
|
-
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) {
|
|
31
|
-
return issue.message;
|
|
32
|
-
}
|
|
33
|
-
if (path === "" && /(?:0|[1-9]\d*)$/.test(issuePath)) {
|
|
34
|
-
return issue.message;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { getIssueMessage, parseFormData };
|