@orpc/openapi 0.0.0-next.73eb96a → 0.0.0-next.7e55b05
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 +652 -0
- package/dist/fetch.js +15 -630
- package/dist/index.js +12 -6
- package/dist/node.js +46 -0
- package/dist/src/{fetch → adapters/fetch}/openapi-handler.d.ts +1 -1
- package/dist/src/{fetch → adapters/fetch}/openapi-payload-codec.d.ts +1 -1
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/openapi-handler-server.d.ts +7 -0
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/adapters/node/openapi-handler.d.ts +12 -0
- package/dist/src/adapters/node/types.d.ts +2 -0
- package/dist/src/openapi-generator.d.ts +1 -1
- package/dist/src/openapi-input-structure-parser.d.ts +1 -1
- package/package.json +12 -6
- /package/dist/src/{fetch → adapters/fetch}/bracket-notation.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/index.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/input-structure-compact.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/input-structure-detailed.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/openapi-handler-server.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/openapi-handler-serverless.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/openapi-procedure-matcher.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/schema-coercer.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -35,11 +35,15 @@ var OpenAPIContentBuilder = class {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// src/openapi-generator.ts
|
|
39
|
+
import { fallbackToGlobalConfig as fallbackToGlobalConfig2 } from "@orpc/contract";
|
|
40
|
+
|
|
38
41
|
// src/openapi-error.ts
|
|
39
42
|
var OpenAPIError = class extends Error {
|
|
40
43
|
};
|
|
41
44
|
|
|
42
45
|
// src/openapi-input-structure-parser.ts
|
|
46
|
+
import { fallbackToGlobalConfig } from "@orpc/contract";
|
|
43
47
|
var OpenAPIInputStructureParser = class {
|
|
44
48
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
45
49
|
this.schemaConverter = schemaConverter;
|
|
@@ -48,7 +52,7 @@ var OpenAPIInputStructureParser = class {
|
|
|
48
52
|
}
|
|
49
53
|
parse(contract, structure) {
|
|
50
54
|
const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
|
|
51
|
-
const method = contract["~orpc"].route?.method
|
|
55
|
+
const method = fallbackToGlobalConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
52
56
|
const httpPath = contract["~orpc"].route?.path;
|
|
53
57
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
54
58
|
return {
|
|
@@ -405,10 +409,12 @@ var OpenAPIGenerator = class {
|
|
|
405
409
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
406
410
|
return;
|
|
407
411
|
}
|
|
408
|
-
const method = def.route?.method
|
|
412
|
+
const method = fallbackToGlobalConfig2("defaultMethod", def.route?.method);
|
|
409
413
|
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
410
|
-
const
|
|
411
|
-
const
|
|
414
|
+
const inputStructure = fallbackToGlobalConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
415
|
+
const outputStructure = fallbackToGlobalConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
416
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
417
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
412
418
|
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
413
419
|
required: true
|
|
414
420
|
}) : [];
|
|
@@ -420,7 +426,7 @@ var OpenAPIGenerator = class {
|
|
|
420
426
|
content: this.contentBuilder.build(bodySchema)
|
|
421
427
|
} : void 0;
|
|
422
428
|
const successResponse = {
|
|
423
|
-
description: "
|
|
429
|
+
description: fallbackToGlobalConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
424
430
|
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema, {
|
|
425
431
|
example: def.outputExample
|
|
426
432
|
}) : void 0,
|
|
@@ -445,7 +451,7 @@ var OpenAPIGenerator = class {
|
|
|
445
451
|
parameters: parameters.length ? parameters : void 0,
|
|
446
452
|
requestBody,
|
|
447
453
|
responses: {
|
|
448
|
-
[def.route?.successStatus
|
|
454
|
+
[fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
|
|
449
455
|
}
|
|
450
456
|
};
|
|
451
457
|
builder.addPath(httpPath, {
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-WNX6GP4X.js";
|
|
4
|
+
import "./chunk-KNYXLM77.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/node/openapi-handler.ts
|
|
7
|
+
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
8
|
+
import { ORPC_HANDLER_HEADER } from "@orpc/shared";
|
|
9
|
+
var OpenAPIHandler2 = class {
|
|
10
|
+
openapiFetchHandler;
|
|
11
|
+
constructor(hono, router, options) {
|
|
12
|
+
this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
|
|
13
|
+
}
|
|
14
|
+
condition(request) {
|
|
15
|
+
return request.headers[ORPC_HANDLER_HEADER] === void 0;
|
|
16
|
+
}
|
|
17
|
+
async handle(req, res, ...[options]) {
|
|
18
|
+
const request = createRequest(req, res, options);
|
|
19
|
+
const castedOptions = options ?? {};
|
|
20
|
+
const response = await this.openapiFetchHandler.fetch(request, castedOptions);
|
|
21
|
+
await options?.beforeSend?.(response, castedOptions.context);
|
|
22
|
+
return await sendResponse(res, response);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/adapters/node/openapi-handler-server.ts
|
|
27
|
+
import { TrieRouter } from "hono/router/trie-router";
|
|
28
|
+
var OpenAPIServerHandler = class extends OpenAPIHandler2 {
|
|
29
|
+
constructor(router, options) {
|
|
30
|
+
super(new TrieRouter(), router, options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/adapters/node/openapi-handler-serverless.ts
|
|
35
|
+
import { LinearRouter } from "hono/router/linear-router";
|
|
36
|
+
var OpenAPIServerlessHandler = class extends OpenAPIHandler2 {
|
|
37
|
+
constructor(router, options) {
|
|
38
|
+
super(new LinearRouter(), router, options);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
OpenAPIHandler2 as OpenAPIHandler,
|
|
43
|
+
OpenAPIServerHandler,
|
|
44
|
+
OpenAPIServerlessHandler
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -2,7 +2,7 @@ import type { Context, Router, WithSignal } from '@orpc/server';
|
|
|
2
2
|
import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
|
|
3
3
|
import type { PublicInputStructureCompact } from './input-structure-compact';
|
|
4
4
|
import { type Hooks } from '@orpc/shared';
|
|
5
|
-
import { type PublicJSONSerializer } from '
|
|
5
|
+
import { type PublicJSONSerializer } from '../../json-serializer';
|
|
6
6
|
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';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
3
|
+
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
+
export declare class OpenAPIServerHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=openapi-handler-server.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
3
|
+
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
+
export declare class OpenAPIServerlessHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=openapi-handler-serverless.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { ConditionalRequestHandler, RequestOptions } from '@orpc/server/node';
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
5
|
+
import type { Hono } from '../fetch/openapi-procedure-matcher';
|
|
6
|
+
export declare class OpenAPIHandler<T extends Context> implements ConditionalRequestHandler<T> {
|
|
7
|
+
private readonly openapiFetchHandler;
|
|
8
|
+
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
condition(request: IncomingMessage): boolean;
|
|
10
|
+
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract';
|
|
2
1
|
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
2
|
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
4
3
|
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
5
4
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
6
5
|
import type { SchemaConverter } from './schema-converter';
|
|
6
|
+
import { type ContractRouter } from '@orpc/contract';
|
|
7
7
|
import { type PublicJSONSerializer } from './json-serializer';
|
|
8
8
|
import { type OpenAPI } from './openapi';
|
|
9
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
1
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
3
2
|
import type { JSONSchema, ObjectSchema } from './schema';
|
|
4
3
|
import type { SchemaConverter } from './schema-converter';
|
|
5
4
|
import type { PublicSchemaUtils } from './schema-utils';
|
|
5
|
+
import { type ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
6
6
|
export interface OpenAPIInputStructureParseResult {
|
|
7
7
|
paramsSchema: ObjectSchema | undefined;
|
|
8
8
|
querySchema: ObjectSchema | undefined;
|
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.7e55b05",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -20,10 +20,15 @@
|
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
},
|
|
22
22
|
"./fetch": {
|
|
23
|
-
"types": "./dist/src/fetch/index.d.ts",
|
|
23
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
|
24
24
|
"import": "./dist/fetch.js",
|
|
25
25
|
"default": "./dist/fetch.js"
|
|
26
26
|
},
|
|
27
|
+
"./node": {
|
|
28
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
|
29
|
+
"import": "./dist/node.js",
|
|
30
|
+
"default": "./dist/node.js"
|
|
31
|
+
},
|
|
27
32
|
"./🔒/*": {
|
|
28
33
|
"types": "./dist/src/*.d.ts"
|
|
29
34
|
}
|
|
@@ -34,6 +39,7 @@
|
|
|
34
39
|
"dist"
|
|
35
40
|
],
|
|
36
41
|
"dependencies": {
|
|
42
|
+
"@mjackson/node-fetch-server": "^0.5.0",
|
|
37
43
|
"@standard-schema/spec": "1.0.0-beta.4",
|
|
38
44
|
"@types/content-disposition": "^0.5.8",
|
|
39
45
|
"content-disposition": "^0.5.4",
|
|
@@ -43,16 +49,16 @@
|
|
|
43
49
|
"json-schema-typed": "^8.0.1",
|
|
44
50
|
"openapi3-ts": "^4.4.0",
|
|
45
51
|
"wildcard-match": "^5.1.3",
|
|
46
|
-
"@orpc/server": "0.0.0-next.
|
|
47
|
-
"@orpc/shared": "0.0.0-next.
|
|
48
|
-
"@orpc/contract": "0.0.0-next.
|
|
52
|
+
"@orpc/server": "0.0.0-next.7e55b05",
|
|
53
|
+
"@orpc/shared": "0.0.0-next.7e55b05",
|
|
54
|
+
"@orpc/contract": "0.0.0-next.7e55b05"
|
|
49
55
|
},
|
|
50
56
|
"devDependencies": {
|
|
51
57
|
"@readme/openapi-parser": "^2.6.0",
|
|
52
58
|
"zod": "^3.24.1"
|
|
53
59
|
},
|
|
54
60
|
"scripts": {
|
|
55
|
-
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
61
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --entry.node=src/adapters/node/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
56
62
|
"build:watch": "pnpm run build --watch",
|
|
57
63
|
"type:check": "tsc -b"
|
|
58
64
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|