@orpc/openapi 0.0.0-next.73eb96a → 0.0.0-next.748dfd9

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 (27) hide show
  1. package/dist/chunk-XYIZDXKB.js +652 -0
  2. package/dist/chunk-YOKECDND.js +25 -0
  3. package/dist/fetch.js +17 -644
  4. package/dist/hono.js +34 -0
  5. package/dist/index.js +12 -6
  6. package/dist/next.js +34 -0
  7. package/dist/node.js +46 -0
  8. package/dist/src/{fetch → adapters/fetch}/openapi-handler.d.ts +5 -6
  9. package/dist/src/{fetch → adapters/fetch}/openapi-payload-codec.d.ts +1 -1
  10. package/dist/src/adapters/hono/index.d.ts +2 -0
  11. package/dist/src/adapters/next/index.d.ts +2 -0
  12. package/dist/src/adapters/node/index.d.ts +5 -0
  13. package/dist/src/adapters/node/openapi-handler-server.d.ts +7 -0
  14. package/dist/src/adapters/node/openapi-handler-serverless.d.ts +7 -0
  15. package/dist/src/adapters/node/openapi-handler.d.ts +11 -0
  16. package/dist/src/adapters/node/types.d.ts +2 -0
  17. package/dist/src/openapi-generator.d.ts +1 -1
  18. package/dist/src/openapi-input-structure-parser.d.ts +1 -1
  19. package/package.json +21 -6
  20. /package/dist/src/{fetch → adapters/fetch}/bracket-notation.d.ts +0 -0
  21. /package/dist/src/{fetch → adapters/fetch}/index.d.ts +0 -0
  22. /package/dist/src/{fetch → adapters/fetch}/input-structure-compact.d.ts +0 -0
  23. /package/dist/src/{fetch → adapters/fetch}/input-structure-detailed.d.ts +0 -0
  24. /package/dist/src/{fetch → adapters/fetch}/openapi-handler-server.d.ts +0 -0
  25. /package/dist/src/{fetch → adapters/fetch}/openapi-handler-serverless.d.ts +0 -0
  26. /package/dist/src/{fetch → adapters/fetch}/openapi-procedure-matcher.d.ts +0 -0
  27. /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 ?? "POST";
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 ?? "POST";
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 { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, def.route?.inputStructure ?? "compact");
411
- const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, def.route?.outputStructure ?? "compact");
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: "OK",
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 ?? 200]: successResponse
454
+ [fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
449
455
  }
450
456
  };
451
457
  builder.addPath(httpPath, {
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 ADDED
@@ -0,0 +1,46 @@
1
+ import {
2
+ OpenAPIHandler
3
+ } from "./chunk-XYIZDXKB.js";
4
+ import "./chunk-KNYXLM77.js";
5
+
6
+ // src/adapters/node/openapi-handler.ts
7
+ import { createRequest, sendResponse } from "@orpc/server/node";
8
+ var OpenAPIHandler2 = class {
9
+ openapiFetchHandler;
10
+ constructor(hono, router, options) {
11
+ this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
12
+ }
13
+ async handle(req, res, ...[options]) {
14
+ const request = createRequest(req, res);
15
+ const castedOptions = options ?? {};
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
+ }
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
@@ -1,13 +1,13 @@
1
1
  import type { Context, Router, WithSignal } from '@orpc/server';
2
- import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
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
- import { type PublicJSONSerializer } from '../json-serializer';
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';
9
9
  import { type SchemaCoercer } from './schema-coercer';
10
- export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
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 ConditionalFetchHandler<T> {
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
- condition(request: Request): boolean;
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,4 +1,4 @@
1
- import type { PublicJSONSerializer } from '../json-serializer';
1
+ import type { PublicJSONSerializer } from '../../json-serializer';
2
2
  export declare class OpenAPIPayloadCodec {
3
3
  private readonly jsonSerializer;
4
4
  constructor(jsonSerializer: PublicJSONSerializer);
@@ -0,0 +1,2 @@
1
+ export * from '../fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from '../fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from './openapi-handler';
2
+ export * from './openapi-handler-server';
3
+ export * from './openapi-handler-serverless';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.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 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,11 @@
1
+ import type { Context, Router } from '@orpc/server';
2
+ import type { IncomingMessage, ServerResponse } from 'node:http';
3
+ import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
4
+ import type { Hono } from '../fetch/openapi-procedure-matcher';
5
+ import { type RequestHandler, type RequestHandleRest, type RequestHandleResult } from '@orpc/server/node';
6
+ export declare class OpenAPIHandler<T extends Context> implements RequestHandler<T> {
7
+ private readonly openapiFetchHandler;
8
+ constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
+ handle(req: IncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
10
+ }
11
+ //# sourceMappingURL=openapi-handler.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.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.73eb96a",
4
+ "version": "0.0.0-next.748dfd9",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -20,10 +20,25 @@
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
+ "./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
+ },
37
+ "./node": {
38
+ "types": "./dist/src/adapters/node/index.d.ts",
39
+ "import": "./dist/node.js",
40
+ "default": "./dist/node.js"
41
+ },
27
42
  "./🔒/*": {
28
43
  "types": "./dist/src/*.d.ts"
29
44
  }
@@ -43,16 +58,16 @@
43
58
  "json-schema-typed": "^8.0.1",
44
59
  "openapi3-ts": "^4.4.0",
45
60
  "wildcard-match": "^5.1.3",
46
- "@orpc/server": "0.0.0-next.73eb96a",
47
- "@orpc/shared": "0.0.0-next.73eb96a",
48
- "@orpc/contract": "0.0.0-next.73eb96a"
61
+ "@orpc/shared": "0.0.0-next.748dfd9",
62
+ "@orpc/contract": "0.0.0-next.748dfd9",
63
+ "@orpc/server": "0.0.0-next.748dfd9"
49
64
  },
50
65
  "devDependencies": {
51
66
  "@readme/openapi-parser": "^2.6.0",
52
67
  "zod": "^3.24.1"
53
68
  },
54
69
  "scripts": {
55
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
70
+ "build": "tsup --onSuccess='tsc -b --noCheck'",
56
71
  "build:watch": "pnpm run build --watch",
57
72
  "type:check": "tsc -b"
58
73
  }
File without changes