@orpc/openapi 0.0.0-next.62795ca → 0.0.0-next.62f2eae

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 (39) hide show
  1. package/README.md +31 -30
  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 +17 -9
  9. package/dist/adapters/fetch/index.d.ts +17 -9
  10. package/dist/adapters/fetch/index.mjs +14 -7
  11. package/dist/adapters/node/index.d.mts +17 -9
  12. package/dist/adapters/node/index.d.ts +17 -9
  13. package/dist/adapters/node/index.mjs +9 -26
  14. package/dist/adapters/standard/index.d.mts +8 -23
  15. package/dist/adapters/standard/index.d.ts +8 -23
  16. package/dist/adapters/standard/index.mjs +5 -3
  17. package/dist/index.d.mts +42 -46
  18. package/dist/index.d.ts +42 -46
  19. package/dist/index.mjs +30 -292
  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.BGy4N6eR.d.mts +120 -0
  24. package/dist/shared/openapi.BGy4N6eR.d.ts +120 -0
  25. package/dist/shared/openapi.CoREqFh3.mjs +853 -0
  26. package/dist/shared/{openapi.BNHmrMe2.mjs → openapi.DIt-Z9W1.mjs} +58 -13
  27. package/dist/shared/openapi.DwaweYRb.d.mts +54 -0
  28. package/dist/shared/openapi.DwaweYRb.d.ts +54 -0
  29. package/package.json +29 -26
  30. package/dist/adapters/hono/index.d.mts +0 -8
  31. package/dist/adapters/hono/index.d.ts +0 -8
  32. package/dist/adapters/hono/index.mjs +0 -11
  33. package/dist/adapters/next/index.d.mts +0 -8
  34. package/dist/adapters/next/index.d.ts +0 -8
  35. package/dist/adapters/next/index.mjs +0 -11
  36. package/dist/shared/openapi.DZzpQAb-.mjs +0 -231
  37. package/dist/shared/openapi.Dv-KT_Bx.mjs +0 -33
  38. package/dist/shared/openapi.IfmmOyba.d.mts +0 -8
  39. package/dist/shared/openapi.IfmmOyba.d.ts +0 -8
@@ -1,13 +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';
3
- import { traverseContractProcedures, toHttpPath, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
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
- constructor(serializer) {
11
+ constructor(serializer, options = {}) {
9
12
  this.serializer = serializer;
13
+ this.customErrorResponseBodyEncoder = options.customErrorResponseBodyEncoder;
10
14
  }
15
+ customErrorResponseBodyEncoder;
11
16
  async decode(request, params, procedure) {
12
17
  const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
13
18
  if (inputStructure === "compact") {
@@ -50,38 +55,67 @@ class StandardOpenAPICodec {
50
55
  body: this.serializer.serialize(output)
51
56
  };
52
57
  }
53
- if (!isObject(output)) {
54
- throw new Error(
55
- 'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
56
- );
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
+ `);
57
70
  }
58
71
  return {
59
- status: successStatus,
72
+ status: output.status ?? successStatus,
60
73
  headers: output.headers ?? {},
61
74
  body: this.serializer.serialize(output.body)
62
75
  };
63
76
  }
64
77
  encodeError(error) {
78
+ const body = this.customErrorResponseBodyEncoder?.(error) ?? error.toJSON();
65
79
  return {
66
80
  status: error.status,
67
81
  headers: {},
68
- body: this.serializer.serialize(error.toJSON())
82
+ body: this.serializer.serialize(body, { outputFormat: "plain" })
69
83
  };
70
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
+ }
71
97
  }
72
98
 
73
99
  function toRou3Pattern(path) {
74
100
  return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
75
101
  }
76
102
  function decodeParams(params) {
77
- 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)]));
78
104
  }
79
105
 
80
106
  class StandardOpenAPIMatcher {
107
+ filter;
81
108
  tree = createRouter();
82
109
  pendingRouters = [];
110
+ constructor(options = {}) {
111
+ this.filter = options.filter ?? true;
112
+ }
83
113
  init(router, path = []) {
84
- 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;
85
119
  const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
86
120
  const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
87
121
  if (isProcedure(contract)) {
@@ -142,4 +176,15 @@ class StandardOpenAPIMatcher {
142
176
  }
143
177
  }
144
178
 
145
- 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,16 +1,15 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.0.0-next.62795ca",
4
+ "version": "0.0.0-next.62f2eae",
5
5
  "license": "MIT",
6
- "homepage": "https://orpc.unnoq.com",
6
+ "homepage": "https://orpc.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/middleapi/orpc.git",
10
10
  "directory": "packages/openapi"
11
11
  },
12
12
  "keywords": [
13
- "unnoq",
14
13
  "orpc"
15
14
  ],
16
15
  "exports": {
@@ -19,6 +18,11 @@
19
18
  "import": "./dist/index.mjs",
20
19
  "default": "./dist/index.mjs"
21
20
  },
21
+ "./plugins": {
22
+ "types": "./dist/plugins/index.d.mts",
23
+ "import": "./dist/plugins/index.mjs",
24
+ "default": "./dist/plugins/index.mjs"
25
+ },
22
26
  "./standard": {
23
27
  "types": "./dist/adapters/standard/index.d.mts",
24
28
  "import": "./dist/adapters/standard/index.mjs",
@@ -29,40 +33,39 @@
29
33
  "import": "./dist/adapters/fetch/index.mjs",
30
34
  "default": "./dist/adapters/fetch/index.mjs"
31
35
  },
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
36
  "./node": {
43
37
  "types": "./dist/adapters/node/index.d.mts",
44
38
  "import": "./dist/adapters/node/index.mjs",
45
39
  "default": "./dist/adapters/node/index.mjs"
40
+ },
41
+ "./fastify": {
42
+ "types": "./dist/adapters/fastify/index.d.mts",
43
+ "import": "./dist/adapters/fastify/index.mjs",
44
+ "default": "./dist/adapters/fastify/index.mjs"
45
+ },
46
+ "./aws-lambda": {
47
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
48
+ "import": "./dist/adapters/aws-lambda/index.mjs",
49
+ "default": "./dist/adapters/aws-lambda/index.mjs"
46
50
  }
47
51
  },
48
52
  "files": [
49
53
  "dist"
50
54
  ],
51
55
  "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.62795ca",
56
- "@orpc/contract": "0.0.0-next.62795ca",
57
- "@orpc/openapi-client": "0.0.0-next.62795ca",
58
- "@orpc/server": "0.0.0-next.62795ca",
59
- "@orpc/standard-server-fetch": "0.0.0-next.62795ca",
60
- "@orpc/shared": "0.0.0-next.62795ca",
61
- "@orpc/standard-server-node": "0.0.0-next.62795ca",
62
- "@orpc/standard-server": "0.0.0-next.62795ca"
56
+ "json-schema-typed": "^8.0.2",
57
+ "rou3": "^0.7.12",
58
+ "@orpc/client": "0.0.0-next.62f2eae",
59
+ "@orpc/contract": "0.0.0-next.62f2eae",
60
+ "@orpc/interop": "0.0.0-next.62f2eae",
61
+ "@orpc/openapi-client": "0.0.0-next.62f2eae",
62
+ "@orpc/server": "0.0.0-next.62f2eae",
63
+ "@orpc/standard-server": "0.0.0-next.62f2eae",
64
+ "@orpc/shared": "0.0.0-next.62f2eae"
63
65
  },
64
66
  "devDependencies": {
65
- "zod": "^3.24.2"
67
+ "fastify": "^5.6.2",
68
+ "zod": "^4.3.2"
66
69
  },
67
70
  "scripts": {
68
71
  "build": "unbuild",
@@ -1,8 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.mjs';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '@orpc/shared';
6
- import '@orpc/standard-server-fetch';
7
- import '../../shared/openapi.IfmmOyba.mjs';
8
- import '@orpc/openapi-client/standard';
@@ -1,8 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.js';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '@orpc/shared';
6
- import '@orpc/standard-server-fetch';
7
- import '../../shared/openapi.IfmmOyba.js';
8
- import '@orpc/openapi-client/standard';
@@ -1,11 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.Dv-KT_Bx.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/standard';
4
- import '@orpc/standard-server-fetch';
5
- import '../../shared/openapi.BNHmrMe2.mjs';
6
- import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/server';
9
- import 'rou3';
10
- import '../../shared/openapi.DZzpQAb-.mjs';
11
- import 'json-schema-typed/draft-2020-12';
@@ -1,8 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.mjs';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '@orpc/shared';
6
- import '@orpc/standard-server-fetch';
7
- import '../../shared/openapi.IfmmOyba.mjs';
8
- import '@orpc/openapi-client/standard';
@@ -1,8 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.js';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '@orpc/shared';
6
- import '@orpc/standard-server-fetch';
7
- import '../../shared/openapi.IfmmOyba.js';
8
- import '@orpc/openapi-client/standard';
@@ -1,11 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.Dv-KT_Bx.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/standard';
4
- import '@orpc/standard-server-fetch';
5
- import '../../shared/openapi.BNHmrMe2.mjs';
6
- import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/server';
9
- import 'rou3';
10
- import '../../shared/openapi.DZzpQAb-.mjs';
11
- import 'json-schema-typed/draft-2020-12';
@@ -1,231 +0,0 @@
1
- import { isObject, findDeepMatches } from '@orpc/shared';
2
- import 'json-schema-typed/draft-2020-12';
3
-
4
- const LOGIC_KEYWORDS = [
5
- "$dynamicRef",
6
- "$ref",
7
- "additionalItems",
8
- "additionalProperties",
9
- "allOf",
10
- "anyOf",
11
- "const",
12
- "contains",
13
- "contentEncoding",
14
- "contentMediaType",
15
- "contentSchema",
16
- "dependencies",
17
- "dependentRequired",
18
- "dependentSchemas",
19
- "else",
20
- "enum",
21
- "exclusiveMaximum",
22
- "exclusiveMinimum",
23
- "format",
24
- "if",
25
- "items",
26
- "maxContains",
27
- "maximum",
28
- "maxItems",
29
- "maxLength",
30
- "maxProperties",
31
- "minContains",
32
- "minimum",
33
- "minItems",
34
- "minLength",
35
- "minProperties",
36
- "multipleOf",
37
- "not",
38
- "oneOf",
39
- "pattern",
40
- "patternProperties",
41
- "prefixItems",
42
- "properties",
43
- "propertyNames",
44
- "required",
45
- "then",
46
- "type",
47
- "unevaluatedItems",
48
- "unevaluatedProperties",
49
- "uniqueItems"
50
- ];
51
-
52
- function isFileSchema(schema) {
53
- return isObject(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
54
- }
55
- function isObjectSchema(schema) {
56
- return isObject(schema) && schema.type === "object";
57
- }
58
- function isAnySchema(schema) {
59
- if (schema === true) {
60
- return true;
61
- }
62
- if (Object.keys(schema).every((k) => !LOGIC_KEYWORDS.includes(k))) {
63
- return true;
64
- }
65
- return false;
66
- }
67
- function separateObjectSchema(schema, separatedProperties) {
68
- if (Object.keys(schema).some((k) => k !== "type" && k !== "properties" && k !== "required" && LOGIC_KEYWORDS.includes(k))) {
69
- return [{ type: "object" }, schema];
70
- }
71
- const matched = { ...schema };
72
- const rest = { ...schema };
73
- matched.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
74
- acc[key] = value;
75
- return acc;
76
- }, {});
77
- matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
78
- matched.examples = schema.examples?.map((example) => {
79
- if (!isObject(example)) {
80
- return example;
81
- }
82
- return Object.entries(example).reduce((acc, [key, value]) => {
83
- if (separatedProperties.includes(key)) {
84
- acc[key] = value;
85
- }
86
- return acc;
87
- }, {});
88
- });
89
- rest.properties = schema.properties && Object.entries(schema.properties).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
90
- acc[key] = value;
91
- return acc;
92
- }, {});
93
- rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
94
- rest.examples = schema.examples?.map((example) => {
95
- if (!isObject(example)) {
96
- return example;
97
- }
98
- return Object.entries(example).reduce((acc, [key, value]) => {
99
- if (!separatedProperties.includes(key)) {
100
- acc[key] = value;
101
- }
102
- return acc;
103
- }, {});
104
- });
105
- return [matched, rest];
106
- }
107
- function filterSchemaBranches(schema, check, matches = []) {
108
- if (check(schema)) {
109
- matches.push(schema);
110
- return [matches, void 0];
111
- }
112
- if (isObject(schema)) {
113
- for (const keyword of ["anyOf", "oneOf"]) {
114
- if (schema[keyword] && Object.keys(schema).every(
115
- (k) => k === keyword || !LOGIC_KEYWORDS.includes(k)
116
- )) {
117
- const rest = schema[keyword].map((s) => filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
118
- if (rest.length === 1 && typeof rest[0] === "object") {
119
- return [matches, { ...schema, [keyword]: void 0, ...rest[0] }];
120
- }
121
- return [matches, { ...schema, [keyword]: rest }];
122
- }
123
- }
124
- }
125
- return [matches, schema];
126
- }
127
-
128
- function standardizeHTTPPath(path) {
129
- return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
130
- }
131
- function toOpenAPIPath(path) {
132
- return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
133
- }
134
- function toOpenAPIMethod(method) {
135
- return method.toLocaleLowerCase();
136
- }
137
- function getDynamicParams(path) {
138
- return path ? standardizeHTTPPath(path).match(/\/\{([^}]+)\}/g)?.map((v) => v.match(/\{\+?([^}]+)\}/)[1]) : void 0;
139
- }
140
- function toOpenAPIContent(schema) {
141
- const content = {};
142
- const [matches, restSchema] = filterSchemaBranches(schema, isFileSchema);
143
- for (const file of matches) {
144
- content[file.contentMediaType] = {
145
- schema: toOpenAPISchema(file)
146
- };
147
- }
148
- if (restSchema !== void 0) {
149
- content["application/json"] = {
150
- schema: toOpenAPISchema(restSchema)
151
- };
152
- const isStillHasFileSchema = findDeepMatches((v) => isObject(v) && isFileSchema(v), restSchema).values.length > 0;
153
- if (isStillHasFileSchema) {
154
- content["multipart/form-data"] = {
155
- schema: toOpenAPISchema(restSchema)
156
- };
157
- }
158
- }
159
- return content;
160
- }
161
- function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema], [returnsRequired, returnsSchema]) {
162
- return {
163
- "text/event-stream": {
164
- schema: toOpenAPISchema({
165
- oneOf: [
166
- {
167
- type: "object",
168
- properties: {
169
- event: { const: "message" },
170
- data: yieldsSchema,
171
- id: { type: "string" },
172
- retry: { type: "number" }
173
- },
174
- required: yieldsRequired ? ["event", "data"] : ["event"]
175
- },
176
- {
177
- type: "object",
178
- properties: {
179
- event: { const: "done" },
180
- data: returnsSchema,
181
- id: { type: "string" },
182
- retry: { type: "number" }
183
- },
184
- required: returnsRequired ? ["event", "data"] : ["event"]
185
- },
186
- {
187
- type: "object",
188
- properties: {
189
- event: { const: "error" },
190
- data: {},
191
- id: { type: "string" },
192
- retry: { type: "number" }
193
- },
194
- required: ["event"]
195
- }
196
- ]
197
- })
198
- }
199
- };
200
- }
201
- function toOpenAPIParameters(schema, parameterIn) {
202
- const parameters = [];
203
- for (const key in schema.properties) {
204
- const keySchema = schema.properties[key];
205
- parameters.push({
206
- name: key,
207
- in: parameterIn,
208
- required: schema.required?.includes(key),
209
- style: parameterIn === "query" ? "deepObject" : void 0,
210
- explode: parameterIn === "query" ? true : void 0,
211
- schema: toOpenAPISchema(keySchema)
212
- });
213
- }
214
- return parameters;
215
- }
216
- function checkParamsSchema(schema, params) {
217
- const properties = Object.keys(schema.properties ?? {});
218
- const required = schema.required ?? [];
219
- if (properties.length !== params.length || properties.some((v) => !params.includes(v))) {
220
- return false;
221
- }
222
- if (required.length !== params.length || required.some((v) => !params.includes(v))) {
223
- return false;
224
- }
225
- return true;
226
- }
227
- function toOpenAPISchema(schema) {
228
- return schema === true ? {} : schema === false ? { not: {} } : schema;
229
- }
230
-
231
- export { LOGIC_KEYWORDS as L, toOpenAPIPath as a, toOpenAPIEventIteratorContent as b, isObjectSchema as c, separateObjectSchema as d, checkParamsSchema as e, toOpenAPIParameters as f, getDynamicParams as g, toOpenAPIContent as h, isAnySchema as i, toOpenAPISchema as j, isFileSchema as k, filterSchemaBranches as l, standardizeHTTPPath as s, toOpenAPIMethod as t };
@@ -1,33 +0,0 @@
1
- import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
- import { StandardHandler } from '@orpc/server/standard';
3
- import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
4
- import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from './openapi.BNHmrMe2.mjs';
5
- import '@orpc/shared';
6
- import 'json-schema-typed/draft-2020-12';
7
-
8
- class OpenAPIHandler {
9
- standardHandler;
10
- constructor(router, options = {}) {
11
- const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
12
- const bracketNotationSerializer = new StandardBracketNotationSerializer();
13
- const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
14
- const matcher = new StandardOpenAPIMatcher();
15
- const codec = new StandardOpenAPICodec(serializer);
16
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
17
- }
18
- async handle(request, ...[
19
- options = {}
20
- ]) {
21
- const standardRequest = toStandardLazyRequest(request);
22
- const result = await this.standardHandler.handle(standardRequest, options);
23
- if (!result.matched) {
24
- return result;
25
- }
26
- return {
27
- matched: true,
28
- response: toFetchResponse(result.response, options)
29
- };
30
- }
31
- }
32
-
33
- 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 };