@orpc/openapi 0.0.0-next.df024bb → 0.0.0-next.e0f01a5

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.
@@ -0,0 +1,12 @@
1
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
+ import { Context, Router } from '@orpc/server';
3
+ import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
4
+
5
+ interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
+ }
7
+ declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
8
+ constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
9
+ }
10
+
11
+ export { StandardOpenAPIHandler as a };
12
+ export type { StandardOpenAPIHandlerOptions as S };
@@ -0,0 +1,12 @@
1
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
+ import { Context, Router } from '@orpc/server';
3
+ import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
4
+
5
+ interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
+ }
7
+ declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
8
+ constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
9
+ }
10
+
11
+ export { StandardOpenAPIHandler as a };
12
+ export type { StandardOpenAPIHandlerOptions as S };
@@ -1,12 +1,13 @@
1
+ import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
+ import { StandardHandler } from '@orpc/server/standard';
1
3
  import { fallbackContractConfig } from '@orpc/contract';
2
- import { OpenAPISerializer } from '@orpc/openapi-client/standard';
3
4
  import { isObject } from '@orpc/shared';
4
- import { eachContractProcedure, convertPathToHttpPath, isProcedure, getLazyRouterPrefix, unlazy, getRouterChild, createContractedProcedure } from '@orpc/server';
5
+ import { toHttpPath } from '@orpc/client/standard';
6
+ import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
5
7
  import { createRouter, addRoute, findRoute } from 'rou3';
6
- import { s as standardizeHTTPPath } from './openapi.BHG_gu5Z.mjs';
7
8
 
8
- class OpenAPICodec {
9
- constructor(serializer = new OpenAPISerializer()) {
9
+ class StandardOpenAPICodec {
10
+ constructor(serializer) {
10
11
  this.serializer = serializer;
11
12
  }
12
13
  async decode(request, params, procedure) {
@@ -66,21 +67,25 @@ class OpenAPICodec {
66
67
  return {
67
68
  status: error.status,
68
69
  headers: {},
69
- body: this.serializer.serialize(error.toJSON())
70
+ body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
70
71
  };
71
72
  }
72
73
  }
73
74
 
74
- class OpenAPIMatcher {
75
+ function toRou3Pattern(path) {
76
+ return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
77
+ }
78
+ function decodeParams(params) {
79
+ return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
80
+ }
81
+
82
+ class StandardOpenAPIMatcher {
75
83
  tree = createRouter();
76
84
  pendingRouters = [];
77
85
  init(router, path = []) {
78
- const laziedOptions = eachContractProcedure({
79
- router,
80
- path
81
- }, ({ path: path2, contract }) => {
86
+ const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
82
87
  const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
83
- const httpPath = contract["~orpc"].route.path ? toRou3Pattern(contract["~orpc"].route.path) : convertPathToHttpPath(path2);
88
+ const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
84
89
  if (isProcedure(contract)) {
85
90
  addRoute(this.tree, method, httpPath, {
86
91
  path: path2,
@@ -100,8 +105,8 @@ class OpenAPIMatcher {
100
105
  });
101
106
  this.pendingRouters.push(...laziedOptions.map((option) => ({
102
107
  ...option,
103
- httpPathPrefix: convertPathToHttpPath(option.path),
104
- laziedPrefix: getLazyRouterPrefix(option.lazied)
108
+ httpPathPrefix: toHttpPath(option.path),
109
+ laziedPrefix: getLazyMeta(option.router).prefix
105
110
  })));
106
111
  }
107
112
  async match(method, pathname) {
@@ -109,7 +114,7 @@ class OpenAPIMatcher {
109
114
  const newPendingRouters = [];
110
115
  for (const pendingRouter of this.pendingRouters) {
111
116
  if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
112
- const { default: router } = await unlazy(pendingRouter.lazied);
117
+ const { default: router } = await unlazy(pendingRouter.router);
113
118
  this.init(router, pendingRouter.path);
114
119
  } else {
115
120
  newPendingRouters.push(pendingRouter);
@@ -122,14 +127,14 @@ class OpenAPIMatcher {
122
127
  return void 0;
123
128
  }
124
129
  if (!match.data.procedure) {
125
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.data.router, ...match.data.path));
130
+ const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
126
131
  if (!isProcedure(maybeProcedure)) {
127
132
  throw new Error(`
128
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.data.path)}.
133
+ [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
129
134
  Ensure that the procedure is correctly defined and matches the expected contract.
130
135
  `);
131
136
  }
132
- match.data.procedure = createContractedProcedure(match.data.contract, maybeProcedure);
137
+ match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
133
138
  }
134
139
  return {
135
140
  path: match.data.path,
@@ -138,11 +143,16 @@ class OpenAPIMatcher {
138
143
  };
139
144
  }
140
145
  }
141
- function toRou3Pattern(path) {
142
- return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "**:$1").replace(/\{([^}]+)\}/g, ":$1");
143
- }
144
- function decodeParams(params) {
145
- return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
146
+
147
+ class StandardOpenAPIHandler extends StandardHandler {
148
+ constructor(router, options) {
149
+ const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
150
+ const bracketNotationSerializer = new StandardBracketNotationSerializer();
151
+ const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
152
+ const matcher = new StandardOpenAPIMatcher();
153
+ const codec = new StandardOpenAPICodec(serializer);
154
+ super(router, matcher, codec, options);
155
+ }
146
156
  }
147
157
 
148
- export { OpenAPICodec as O, OpenAPIMatcher as a };
158
+ 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": "0.0.0-next.df024bb",
4
+ "version": "0.0.0-next.e0f01a5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,16 +29,6 @@
29
29
  "import": "./dist/adapters/fetch/index.mjs",
30
30
  "default": "./dist/adapters/fetch/index.mjs"
31
31
  },
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
32
  "./node": {
43
33
  "types": "./dist/adapters/node/index.d.mts",
44
34
  "import": "./dist/adapters/node/index.mjs",
@@ -50,19 +40,17 @@
50
40
  ],
51
41
  "dependencies": {
52
42
  "json-schema-typed": "^8.0.1",
53
- "openapi3-ts": "^4.4.0",
43
+ "openapi-types": "^12.1.3",
54
44
  "rou3": "^0.5.1",
55
- "@orpc/client": "0.0.0-next.df024bb",
56
- "@orpc/openapi-client": "0.0.0-next.df024bb",
57
- "@orpc/contract": "0.0.0-next.df024bb",
58
- "@orpc/shared": "0.0.0-next.df024bb",
59
- "@orpc/server": "0.0.0-next.df024bb",
60
- "@orpc/standard-server": "0.0.0-next.df024bb",
61
- "@orpc/standard-server-fetch": "0.0.0-next.df024bb",
62
- "@orpc/standard-server-node": "0.0.0-next.df024bb"
45
+ "@orpc/client": "0.0.0-next.e0f01a5",
46
+ "@orpc/openapi-client": "0.0.0-next.e0f01a5",
47
+ "@orpc/shared": "0.0.0-next.e0f01a5",
48
+ "@orpc/contract": "0.0.0-next.e0f01a5",
49
+ "@orpc/server": "0.0.0-next.e0f01a5",
50
+ "@orpc/standard-server": "0.0.0-next.e0f01a5"
63
51
  },
64
52
  "devDependencies": {
65
- "zod": "^3.24.1"
53
+ "zod": "^3.24.2"
66
54
  },
67
55
  "scripts": {
68
56
  "build": "unbuild",
@@ -1,7 +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.Dz_6xooR.mjs';
@@ -1,7 +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.Dz_6xooR.js';
@@ -1,10 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.BcJH4F9P.mjs';
2
- import '@orpc/server/standard';
3
- import '@orpc/standard-server-fetch';
4
- import '../../shared/openapi.CDsfPHgw.mjs';
5
- import '@orpc/contract';
6
- import '@orpc/openapi-client/standard';
7
- import '@orpc/shared';
8
- import '@orpc/server';
9
- import 'rou3';
10
- import '../../shared/openapi.BHG_gu5Z.mjs';
@@ -1,7 +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.Dz_6xooR.mjs';
@@ -1,7 +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.Dz_6xooR.js';
@@ -1,10 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.BcJH4F9P.mjs';
2
- import '@orpc/server/standard';
3
- import '@orpc/standard-server-fetch';
4
- import '../../shared/openapi.CDsfPHgw.mjs';
5
- import '@orpc/contract';
6
- import '@orpc/openapi-client/standard';
7
- import '@orpc/shared';
8
- import '@orpc/server';
9
- import 'rou3';
10
- import '../../shared/openapi.BHG_gu5Z.mjs';
@@ -1,8 +0,0 @@
1
- function standardizeHTTPPath(path) {
2
- return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
3
- }
4
- function toOpenAPI31RoutePattern(path) {
5
- return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
6
- }
7
-
8
- export { standardizeHTTPPath as s, toOpenAPI31RoutePattern as t };
@@ -1,27 +0,0 @@
1
- import { StandardHandler } from '@orpc/server/standard';
2
- import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
3
- import { a as OpenAPIMatcher, O as OpenAPICodec } from './openapi.CDsfPHgw.mjs';
4
-
5
- class OpenAPIHandler {
6
- standardHandler;
7
- constructor(router, options) {
8
- const matcher = options?.matcher ?? new OpenAPIMatcher();
9
- const codec = options?.codec ?? new OpenAPICodec();
10
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
11
- }
12
- async handle(request, ...[
13
- options = {}
14
- ]) {
15
- const standardRequest = toStandardLazyRequest(request);
16
- const result = await this.standardHandler.handle(standardRequest, options);
17
- if (!result.matched) {
18
- return result;
19
- }
20
- return {
21
- matched: true,
22
- response: toFetchResponse(result.response, options)
23
- };
24
- }
25
- }
26
-
27
- export { OpenAPIHandler as O };
@@ -1,7 +0,0 @@
1
- import { Context } from '@orpc/server';
2
- import { RPCHandlerOptions } from '@orpc/server/standard';
3
-
4
- interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T> {
5
- }
6
-
7
- export type { OpenAPIHandlerOptions as O };
@@ -1,7 +0,0 @@
1
- import { Context } from '@orpc/server';
2
- import { RPCHandlerOptions } from '@orpc/server/standard';
3
-
4
- interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T> {
5
- }
6
-
7
- export type { OpenAPIHandlerOptions as O };