@orpc/openapi 0.0.0-next.7e55b05 → 0.0.0-next.7ea4bbf
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/dist/{chunk-WNX6GP4X.js → chunk-XYIZDXKB.js} +13 -13
- package/dist/chunk-YOKECDND.js +25 -0
- package/dist/fetch.js +5 -17
- package/dist/hono.js +34 -0
- package/dist/next.js +34 -0
- package/dist/node.js +10 -10
- package/dist/src/adapters/fetch/openapi-handler.d.ts +4 -5
- package/dist/src/adapters/hono/index.d.ts +2 -0
- package/dist/src/adapters/next/index.d.ts +2 -0
- package/dist/src/adapters/node/openapi-handler.d.ts +3 -4
- package/package.json +15 -6
|
@@ -486,7 +486,7 @@ var CompositeSchemaCoercer = class {
|
|
|
486
486
|
|
|
487
487
|
// src/adapters/fetch/openapi-handler.ts
|
|
488
488
|
import { createProcedureClient, fallbackToGlobalConfig as fallbackToGlobalConfig2, ORPCError as ORPCError2 } from "@orpc/server";
|
|
489
|
-
import { executeWithHooks, isPlainObject as isPlainObject3,
|
|
489
|
+
import { executeWithHooks, isPlainObject as isPlainObject3, trim } from "@orpc/shared";
|
|
490
490
|
var OpenAPIHandler = class {
|
|
491
491
|
constructor(hono, router, options) {
|
|
492
492
|
this.options = options;
|
|
@@ -502,13 +502,10 @@ var OpenAPIHandler = class {
|
|
|
502
502
|
inputStructureCompact;
|
|
503
503
|
inputStructureDetailed;
|
|
504
504
|
compositeSchemaCoercer;
|
|
505
|
-
|
|
506
|
-
return request.headers.get(ORPC_HANDLER_HEADER) === null;
|
|
507
|
-
}
|
|
508
|
-
async fetch(request, ...[options]) {
|
|
505
|
+
async handle(request, ...[options]) {
|
|
509
506
|
const context = options?.context;
|
|
510
507
|
const headers = request.headers;
|
|
511
|
-
const accept = headers.get("
|
|
508
|
+
const accept = headers.get("accept") || void 0;
|
|
512
509
|
const execute = async () => {
|
|
513
510
|
const url = new URL(request.url);
|
|
514
511
|
const pathname = `/${trim(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
|
|
@@ -517,7 +514,7 @@ var OpenAPIHandler = class {
|
|
|
517
514
|
const matchedMethod = customMethod || request.method;
|
|
518
515
|
const matched = await this.procedureMatcher.match(matchedMethod, pathname);
|
|
519
516
|
if (!matched) {
|
|
520
|
-
|
|
517
|
+
return { matched: false, response: void 0 };
|
|
521
518
|
}
|
|
522
519
|
const contractDef = matched.procedure["~orpc"].contract["~orpc"];
|
|
523
520
|
const input = await this.decodeInput(matched.procedure, matched.params, request);
|
|
@@ -527,12 +524,13 @@ var OpenAPIHandler = class {
|
|
|
527
524
|
procedure: matched.procedure,
|
|
528
525
|
path: matched.path
|
|
529
526
|
});
|
|
530
|
-
const output = await client(coercedInput, { signal:
|
|
527
|
+
const output = await client(coercedInput, { signal: request.signal });
|
|
531
528
|
const { body, headers: resHeaders } = this.encodeOutput(matched.procedure, output, accept);
|
|
532
|
-
|
|
529
|
+
const response = new Response(body, {
|
|
533
530
|
headers: resHeaders,
|
|
534
531
|
status: fallbackToGlobalConfig2("defaultSuccessStatus", contractDef.route?.successStatus)
|
|
535
532
|
});
|
|
533
|
+
return { matched: true, response };
|
|
536
534
|
};
|
|
537
535
|
try {
|
|
538
536
|
return await executeWithHooks({
|
|
@@ -541,24 +539,26 @@ var OpenAPIHandler = class {
|
|
|
541
539
|
input: request,
|
|
542
540
|
hooks: this.options,
|
|
543
541
|
meta: {
|
|
544
|
-
signal:
|
|
542
|
+
signal: request.signal
|
|
545
543
|
}
|
|
546
544
|
});
|
|
547
545
|
} catch (e) {
|
|
548
546
|
const error = this.convertToORPCError(e);
|
|
549
547
|
try {
|
|
550
548
|
const { body, headers: headers2 } = this.payloadCodec.encode(error.toJSON(), accept);
|
|
551
|
-
|
|
549
|
+
const response = new Response(body, {
|
|
552
550
|
status: error.status,
|
|
553
551
|
headers: headers2
|
|
554
552
|
});
|
|
553
|
+
return { matched: true, response };
|
|
555
554
|
} catch (e2) {
|
|
556
555
|
const error2 = this.convertToORPCError(e2);
|
|
557
556
|
const { body, headers: headers2 } = this.payloadCodec.encode(error2.toJSON(), void 0);
|
|
558
|
-
|
|
557
|
+
const response = new Response(body, {
|
|
559
558
|
status: error2.status,
|
|
560
559
|
headers: headers2
|
|
561
560
|
});
|
|
561
|
+
return { matched: true, response };
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
}
|
|
@@ -649,4 +649,4 @@ export {
|
|
|
649
649
|
CompositeSchemaCoercer,
|
|
650
650
|
OpenAPIHandler
|
|
651
651
|
};
|
|
652
|
-
//# sourceMappingURL=chunk-
|
|
652
|
+
//# sourceMappingURL=chunk-XYIZDXKB.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-XYIZDXKB.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/fetch/openapi-handler-server.ts
|
|
6
|
+
import { TrieRouter } from "hono/router/trie-router";
|
|
7
|
+
var OpenAPIServerHandler = class extends OpenAPIHandler {
|
|
8
|
+
constructor(router, options) {
|
|
9
|
+
super(new TrieRouter(), router, options);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/adapters/fetch/openapi-handler-serverless.ts
|
|
14
|
+
import { LinearRouter } from "hono/router/linear-router";
|
|
15
|
+
var OpenAPIServerlessHandler = class extends OpenAPIHandler {
|
|
16
|
+
constructor(router, options) {
|
|
17
|
+
super(new LinearRouter(), router, options);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
OpenAPIServerHandler,
|
|
23
|
+
OpenAPIServerlessHandler
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-YOKECDND.js.map
|
package/dist/fetch.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIServerHandler,
|
|
3
|
+
OpenAPIServerlessHandler
|
|
4
|
+
} from "./chunk-YOKECDND.js";
|
|
1
5
|
import {
|
|
2
6
|
CompositeSchemaCoercer,
|
|
3
7
|
InputStructureCompact,
|
|
@@ -10,24 +14,8 @@ import {
|
|
|
10
14
|
parsePath,
|
|
11
15
|
serialize,
|
|
12
16
|
stringifyPath
|
|
13
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-XYIZDXKB.js";
|
|
14
18
|
import "./chunk-KNYXLM77.js";
|
|
15
|
-
|
|
16
|
-
// src/adapters/fetch/openapi-handler-server.ts
|
|
17
|
-
import { TrieRouter } from "hono/router/trie-router";
|
|
18
|
-
var OpenAPIServerHandler = class extends OpenAPIHandler {
|
|
19
|
-
constructor(router, options) {
|
|
20
|
-
super(new TrieRouter(), router, options);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// src/adapters/fetch/openapi-handler-serverless.ts
|
|
25
|
-
import { LinearRouter } from "hono/router/linear-router";
|
|
26
|
-
var OpenAPIServerlessHandler = class extends OpenAPIHandler {
|
|
27
|
-
constructor(router, options) {
|
|
28
|
-
super(new LinearRouter(), router, options);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
19
|
export {
|
|
32
20
|
CompositeSchemaCoercer,
|
|
33
21
|
InputStructureCompact,
|
package/dist/hono.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIServerHandler,
|
|
3
|
+
OpenAPIServerlessHandler
|
|
4
|
+
} from "./chunk-YOKECDND.js";
|
|
5
|
+
import {
|
|
6
|
+
CompositeSchemaCoercer,
|
|
7
|
+
InputStructureCompact,
|
|
8
|
+
InputStructureDetailed,
|
|
9
|
+
OpenAPIHandler,
|
|
10
|
+
OpenAPIPayloadCodec,
|
|
11
|
+
OpenAPIProcedureMatcher,
|
|
12
|
+
deserialize,
|
|
13
|
+
escapeSegment,
|
|
14
|
+
parsePath,
|
|
15
|
+
serialize,
|
|
16
|
+
stringifyPath
|
|
17
|
+
} from "./chunk-XYIZDXKB.js";
|
|
18
|
+
import "./chunk-KNYXLM77.js";
|
|
19
|
+
export {
|
|
20
|
+
CompositeSchemaCoercer,
|
|
21
|
+
InputStructureCompact,
|
|
22
|
+
InputStructureDetailed,
|
|
23
|
+
OpenAPIHandler,
|
|
24
|
+
OpenAPIPayloadCodec,
|
|
25
|
+
OpenAPIProcedureMatcher,
|
|
26
|
+
OpenAPIServerHandler,
|
|
27
|
+
OpenAPIServerlessHandler,
|
|
28
|
+
deserialize,
|
|
29
|
+
escapeSegment,
|
|
30
|
+
parsePath,
|
|
31
|
+
serialize,
|
|
32
|
+
stringifyPath
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIServerHandler,
|
|
3
|
+
OpenAPIServerlessHandler
|
|
4
|
+
} from "./chunk-YOKECDND.js";
|
|
5
|
+
import {
|
|
6
|
+
CompositeSchemaCoercer,
|
|
7
|
+
InputStructureCompact,
|
|
8
|
+
InputStructureDetailed,
|
|
9
|
+
OpenAPIHandler,
|
|
10
|
+
OpenAPIPayloadCodec,
|
|
11
|
+
OpenAPIProcedureMatcher,
|
|
12
|
+
deserialize,
|
|
13
|
+
escapeSegment,
|
|
14
|
+
parsePath,
|
|
15
|
+
serialize,
|
|
16
|
+
stringifyPath
|
|
17
|
+
} from "./chunk-XYIZDXKB.js";
|
|
18
|
+
import "./chunk-KNYXLM77.js";
|
|
19
|
+
export {
|
|
20
|
+
CompositeSchemaCoercer,
|
|
21
|
+
InputStructureCompact,
|
|
22
|
+
InputStructureDetailed,
|
|
23
|
+
OpenAPIHandler,
|
|
24
|
+
OpenAPIPayloadCodec,
|
|
25
|
+
OpenAPIProcedureMatcher,
|
|
26
|
+
OpenAPIServerHandler,
|
|
27
|
+
OpenAPIServerlessHandler,
|
|
28
|
+
deserialize,
|
|
29
|
+
escapeSegment,
|
|
30
|
+
parsePath,
|
|
31
|
+
serialize,
|
|
32
|
+
stringifyPath
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenAPIHandler
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XYIZDXKB.js";
|
|
4
4
|
import "./chunk-KNYXLM77.js";
|
|
5
5
|
|
|
6
6
|
// src/adapters/node/openapi-handler.ts
|
|
7
|
-
import { createRequest, sendResponse } from "@
|
|
8
|
-
import { ORPC_HANDLER_HEADER } from "@orpc/shared";
|
|
7
|
+
import { createRequest, sendResponse } from "@orpc/server/node";
|
|
9
8
|
var OpenAPIHandler2 = class {
|
|
10
9
|
openapiFetchHandler;
|
|
11
10
|
constructor(hono, router, options) {
|
|
12
11
|
this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
|
|
13
12
|
}
|
|
14
|
-
condition(request) {
|
|
15
|
-
return request.headers[ORPC_HANDLER_HEADER] === void 0;
|
|
16
|
-
}
|
|
17
13
|
async handle(req, res, ...[options]) {
|
|
18
|
-
const request = createRequest(req, res
|
|
14
|
+
const request = createRequest(req, res);
|
|
19
15
|
const castedOptions = options ?? {};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const result = await this.openapiFetchHandler.handle(request, castedOptions);
|
|
17
|
+
if (result.matched === false) {
|
|
18
|
+
return { matched: false };
|
|
19
|
+
}
|
|
20
|
+
await options?.beforeSend?.(result.response, castedOptions.context);
|
|
21
|
+
await sendResponse(res, result.response);
|
|
22
|
+
return { matched: true };
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context, Router, WithSignal } from '@orpc/server';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from '@orpc/server/fetch';
|
|
3
3
|
import type { PublicInputStructureCompact } from './input-structure-compact';
|
|
4
4
|
import { type Hooks } from '@orpc/shared';
|
|
5
5
|
import { type PublicJSONSerializer } from '../../json-serializer';
|
|
@@ -7,7 +7,7 @@ import { type PublicInputStructureDetailed } from './input-structure-detailed';
|
|
|
7
7
|
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
8
8
|
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
9
9
|
import { type SchemaCoercer } from './schema-coercer';
|
|
10
|
-
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request,
|
|
10
|
+
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, WithSignal> & {
|
|
11
11
|
jsonSerializer?: PublicJSONSerializer;
|
|
12
12
|
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
13
|
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
@@ -15,7 +15,7 @@ export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response,
|
|
|
15
15
|
inputBuilderFull?: PublicInputStructureDetailed;
|
|
16
16
|
schemaCoercers?: SchemaCoercer[];
|
|
17
17
|
};
|
|
18
|
-
export declare class OpenAPIHandler<T extends Context> implements
|
|
18
|
+
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
|
19
19
|
private readonly options?;
|
|
20
20
|
private readonly procedureMatcher;
|
|
21
21
|
private readonly payloadCodec;
|
|
@@ -23,8 +23,7 @@ export declare class OpenAPIHandler<T extends Context> implements ConditionalFet
|
|
|
23
23
|
private readonly inputStructureDetailed;
|
|
24
24
|
private readonly compositeSchemaCoercer;
|
|
25
25
|
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
|
|
26
|
-
|
|
27
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
|
26
|
+
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
|
28
27
|
private decodeInput;
|
|
29
28
|
private encodeOutput;
|
|
30
29
|
private assertDetailedOutput;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type { ConditionalRequestHandler, RequestOptions } from '@orpc/server/node';
|
|
3
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
3
|
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
5
4
|
import type { Hono } from '../fetch/openapi-procedure-matcher';
|
|
6
|
-
|
|
5
|
+
import { type RequestHandler, type RequestHandleRest, type RequestHandleResult } from '@orpc/server/node';
|
|
6
|
+
export declare class OpenAPIHandler<T extends Context> implements RequestHandler<T> {
|
|
7
7
|
private readonly openapiFetchHandler;
|
|
8
8
|
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
-
|
|
10
|
-
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
|
9
|
+
handle(req: IncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
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.
|
|
4
|
+
"version": "0.0.0-next.7ea4bbf",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -24,6 +24,16 @@
|
|
|
24
24
|
"import": "./dist/fetch.js",
|
|
25
25
|
"default": "./dist/fetch.js"
|
|
26
26
|
},
|
|
27
|
+
"./hono": {
|
|
28
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
|
29
|
+
"import": "./dist/hono.js",
|
|
30
|
+
"default": "./dist/hono.js"
|
|
31
|
+
},
|
|
32
|
+
"./next": {
|
|
33
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
|
34
|
+
"import": "./dist/next.js",
|
|
35
|
+
"default": "./dist/next.js"
|
|
36
|
+
},
|
|
27
37
|
"./node": {
|
|
28
38
|
"types": "./dist/src/adapters/node/index.d.ts",
|
|
29
39
|
"import": "./dist/node.js",
|
|
@@ -39,7 +49,6 @@
|
|
|
39
49
|
"dist"
|
|
40
50
|
],
|
|
41
51
|
"dependencies": {
|
|
42
|
-
"@mjackson/node-fetch-server": "^0.5.0",
|
|
43
52
|
"@standard-schema/spec": "1.0.0-beta.4",
|
|
44
53
|
"@types/content-disposition": "^0.5.8",
|
|
45
54
|
"content-disposition": "^0.5.4",
|
|
@@ -49,16 +58,16 @@
|
|
|
49
58
|
"json-schema-typed": "^8.0.1",
|
|
50
59
|
"openapi3-ts": "^4.4.0",
|
|
51
60
|
"wildcard-match": "^5.1.3",
|
|
52
|
-
"@orpc/
|
|
53
|
-
"@orpc/
|
|
54
|
-
"@orpc/
|
|
61
|
+
"@orpc/contract": "0.0.0-next.7ea4bbf",
|
|
62
|
+
"@orpc/server": "0.0.0-next.7ea4bbf",
|
|
63
|
+
"@orpc/shared": "0.0.0-next.7ea4bbf"
|
|
55
64
|
},
|
|
56
65
|
"devDependencies": {
|
|
57
66
|
"@readme/openapi-parser": "^2.6.0",
|
|
58
67
|
"zod": "^3.24.1"
|
|
59
68
|
},
|
|
60
69
|
"scripts": {
|
|
61
|
-
"build": "tsup --
|
|
70
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
|
62
71
|
"build:watch": "pnpm run build --watch",
|
|
63
72
|
"type:check": "tsc -b"
|
|
64
73
|
}
|