@orpc/openapi 0.0.0-next.ea0903c → 0.0.0-next.ea1d4fd

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.
Files changed (38) hide show
  1. package/README.md +23 -22
  2. package/dist/adapters/aws-lambda/index.d.mts +20 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +20 -0
  4. package/dist/adapters/aws-lambda/index.mjs +18 -0
  5. package/dist/adapters/fastify/index.d.mts +23 -0
  6. package/dist/adapters/fastify/index.d.ts +23 -0
  7. package/dist/adapters/fastify/index.mjs +18 -0
  8. package/dist/adapters/fetch/index.d.mts +15 -3
  9. package/dist/adapters/fetch/index.d.ts +15 -3
  10. package/dist/adapters/fetch/index.mjs +13 -5
  11. package/dist/adapters/node/index.d.mts +15 -3
  12. package/dist/adapters/node/index.d.ts +15 -3
  13. package/dist/adapters/node/index.mjs +5 -9
  14. package/dist/adapters/standard/index.d.mts +8 -22
  15. package/dist/adapters/standard/index.d.ts +8 -22
  16. package/dist/adapters/standard/index.mjs +4 -2
  17. package/dist/index.d.mts +43 -40
  18. package/dist/index.d.ts +43 -40
  19. package/dist/index.mjs +31 -513
  20. package/dist/plugins/index.d.mts +84 -0
  21. package/dist/plugins/index.d.ts +84 -0
  22. package/dist/plugins/index.mjs +148 -0
  23. package/dist/shared/openapi.BfNjg7j9.d.mts +120 -0
  24. package/dist/shared/openapi.BfNjg7j9.d.ts +120 -0
  25. package/dist/shared/openapi.CzHcOMxv.mjs +853 -0
  26. package/dist/shared/{openapi.rzdlmBcy.mjs → openapi.DIt-Z9W1.mjs} +56 -12
  27. package/dist/shared/openapi.DwaweYRb.d.mts +54 -0
  28. package/dist/shared/openapi.DwaweYRb.d.ts +54 -0
  29. package/package.json +26 -21
  30. package/dist/adapters/hono/index.d.mts +0 -6
  31. package/dist/adapters/hono/index.d.ts +0 -6
  32. package/dist/adapters/hono/index.mjs +0 -10
  33. package/dist/adapters/next/index.d.mts +0 -6
  34. package/dist/adapters/next/index.d.ts +0 -6
  35. package/dist/adapters/next/index.mjs +0 -10
  36. package/dist/shared/openapi.By1hOIbk.mjs +0 -17
  37. package/dist/shared/openapi.IfmmOyba.d.mts +0 -8
  38. package/dist/shared/openapi.IfmmOyba.d.ts +0 -8
@@ -1,14 +1,18 @@
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';
5
+ import { isObject, stringifyJSON, tryDecodeURIComponent, value } from '@orpc/shared';
3
6
  import { toHttpPath } from '@orpc/client/standard';
4
7
  import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
5
8
  import { createRouter, addRoute, findRoute } from 'rou3';
6
- import { standardizeHTTPPath } from '@orpc/openapi-client/standard';
7
9
 
8
10
  class StandardOpenAPICodec {
9
- constructor(serializer) {
11
+ constructor(serializer, options = {}) {
10
12
  this.serializer = serializer;
13
+ this.customErrorResponseBodyEncoder = options.customErrorResponseBodyEncoder;
11
14
  }
15
+ customErrorResponseBodyEncoder;
12
16
  async decode(request, params, procedure) {
13
17
  const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
14
18
  if (inputStructure === "compact") {
@@ -51,38 +55,67 @@ class StandardOpenAPICodec {
51
55
  body: this.serializer.serialize(output)
52
56
  };
53
57
  }
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
+ if (!this.#isDetailedOutput(output)) {
59
+ throw new Error(`
60
+ Invalid "detailed" output structure:
61
+ \u2022 Expected an object with optional properties:
62
+ - status (number 200-399)
63
+ - headers (Record<string, string | string[]>)
64
+ - body (any)
65
+ \u2022 No extra keys allowed.
66
+
67
+ Actual value:
68
+ ${stringifyJSON(output)}
69
+ `);
58
70
  }
59
71
  return {
60
- status: successStatus,
72
+ status: output.status ?? successStatus,
61
73
  headers: output.headers ?? {},
62
74
  body: this.serializer.serialize(output.body)
63
75
  };
64
76
  }
65
77
  encodeError(error) {
78
+ const body = this.customErrorResponseBodyEncoder?.(error) ?? error.toJSON();
66
79
  return {
67
80
  status: error.status,
68
81
  headers: {},
69
- body: this.serializer.serialize(error.toJSON())
82
+ body: this.serializer.serialize(body, { outputFormat: "plain" })
70
83
  };
71
84
  }
85
+ #isDetailedOutput(output) {
86
+ if (!isObject(output)) {
87
+ return false;
88
+ }
89
+ if (output.headers && !isObject(output.headers)) {
90
+ return false;
91
+ }
92
+ if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
93
+ return false;
94
+ }
95
+ return true;
96
+ }
72
97
  }
73
98
 
74
99
  function toRou3Pattern(path) {
75
100
  return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
76
101
  }
77
102
  function decodeParams(params) {
78
- return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
103
+ return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)]));
79
104
  }
80
105
 
81
106
  class StandardOpenAPIMatcher {
107
+ filter;
82
108
  tree = createRouter();
83
109
  pendingRouters = [];
110
+ constructor(options = {}) {
111
+ this.filter = options.filter ?? true;
112
+ }
84
113
  init(router, path = []) {
85
- const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
114
+ const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
115
+ if (!value(this.filter, traverseOptions)) {
116
+ return;
117
+ }
118
+ const { path: path2, contract } = traverseOptions;
86
119
  const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
87
120
  const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
88
121
  if (isProcedure(contract)) {
@@ -143,4 +176,15 @@ class StandardOpenAPIMatcher {
143
176
  }
144
177
  }
145
178
 
146
- export { StandardOpenAPICodec as S, StandardOpenAPIMatcher as a, decodeParams as d, toRou3Pattern as t };
179
+ class StandardOpenAPIHandler extends StandardHandler {
180
+ constructor(router, options) {
181
+ const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
182
+ const bracketNotationSerializer = new StandardBracketNotationSerializer(options);
183
+ const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
184
+ const matcher = new StandardOpenAPIMatcher(options);
185
+ const codec = new StandardOpenAPICodec(serializer, options);
186
+ super(router, matcher, codec, options);
187
+ }
188
+ }
189
+
190
+ export { StandardOpenAPICodec as S, StandardOpenAPIHandler as a, StandardOpenAPIMatcher as b, decodeParams as d, toRou3Pattern as t };
@@ -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 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 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 };
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.ea0903c",
4
+ "version": "0.0.0-next.ea1d4fd",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,6 +19,11 @@
19
19
  "import": "./dist/index.mjs",
20
20
  "default": "./dist/index.mjs"
21
21
  },
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
26
+ },
22
27
  "./standard": {
23
28
  "types": "./dist/adapters/standard/index.d.mts",
24
29
  "import": "./dist/adapters/standard/index.mjs",
@@ -29,38 +34,38 @@
29
34
  "import": "./dist/adapters/fetch/index.mjs",
30
35
  "default": "./dist/adapters/fetch/index.mjs"
31
36
  },
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
37
  "./node": {
43
38
  "types": "./dist/adapters/node/index.d.mts",
44
39
  "import": "./dist/adapters/node/index.mjs",
45
40
  "default": "./dist/adapters/node/index.mjs"
41
+ },
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"
46
51
  }
47
52
  },
48
53
  "files": [
49
54
  "dist"
50
55
  ],
51
56
  "dependencies": {
52
- "json-schema-typed": "^8.0.1",
53
- "openapi-types": "^12.1.3",
54
- "rou3": "^0.5.1",
55
- "@orpc/client": "0.0.0-next.ea0903c",
56
- "@orpc/openapi-client": "0.0.0-next.ea0903c",
57
- "@orpc/server": "0.0.0-next.ea0903c",
58
- "@orpc/shared": "0.0.0-next.ea0903c",
59
- "@orpc/contract": "0.0.0-next.ea0903c",
60
- "@orpc/standard-server": "0.0.0-next.ea0903c"
57
+ "rou3": "^0.7.10",
58
+ "@orpc/client": "0.0.0-next.ea1d4fd",
59
+ "@orpc/contract": "0.0.0-next.ea1d4fd",
60
+ "@orpc/interop": "0.0.0-next.ea1d4fd",
61
+ "@orpc/openapi-client": "0.0.0-next.ea1d4fd",
62
+ "@orpc/shared": "0.0.0-next.ea1d4fd",
63
+ "@orpc/server": "0.0.0-next.ea1d4fd",
64
+ "@orpc/standard-server": "0.0.0-next.ea1d4fd"
61
65
  },
62
66
  "devDependencies": {
63
- "zod": "^3.24.2"
67
+ "fastify": "^5.6.2",
68
+ "zod": "^4.1.12"
64
69
  },
65
70
  "scripts": {
66
71
  "build": "unbuild",
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.mjs';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.mjs';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.js';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.js';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,10 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.By1hOIbk.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '../../shared/openapi.rzdlmBcy.mjs';
6
- import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/client/standard';
9
- import '@orpc/server';
10
- import 'rou3';
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.mjs';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.mjs';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.js';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.js';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,10 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.By1hOIbk.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '../../shared/openapi.rzdlmBcy.mjs';
6
- import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/client/standard';
9
- import '@orpc/server';
10
- import 'rou3';
@@ -1,17 +0,0 @@
1
- import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
- import { FetchHandler } from '@orpc/server/fetch';
3
- import { StandardHandler } from '@orpc/server/standard';
4
- import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from './openapi.rzdlmBcy.mjs';
5
-
6
- class OpenAPIHandler extends FetchHandler {
7
- constructor(router, options = {}) {
8
- const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
9
- const bracketNotationSerializer = new StandardBracketNotationSerializer();
10
- const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
11
- const matcher = new StandardOpenAPIMatcher();
12
- const codec = new StandardOpenAPICodec(serializer);
13
- super(new StandardHandler(router, matcher, codec, options), options);
14
- }
15
- }
16
-
17
- export { OpenAPIHandler as O };
@@ -1,8 +0,0 @@
1
- import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
- import { Context } from '@orpc/server';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
-
5
- interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardOpenAPIHandlerOptions as S };
@@ -1,8 +0,0 @@
1
- import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
- import { Context } from '@orpc/server';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
-
5
- interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardOpenAPIHandlerOptions as S };