@orpc/openapi 0.23.0 → 0.24.0

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/index.js CHANGED
@@ -369,8 +369,18 @@ var SchemaUtils = class {
369
369
 
370
370
  // src/openapi-generator.ts
371
371
  var OpenAPIGenerator = class {
372
+ contentBuilder;
373
+ parametersBuilder;
374
+ schemaConverter;
375
+ schemaUtils;
376
+ jsonSerializer;
377
+ pathParser;
378
+ inputStructureParser;
379
+ outputStructureParser;
380
+ errorHandlerStrategy;
381
+ ignoreUndefinedPathProcedures;
382
+ considerMissingTagDefinitionAsError;
372
383
  constructor(options) {
373
- this.options = options;
374
384
  this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
375
385
  this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
376
386
  this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
@@ -379,15 +389,10 @@ var OpenAPIGenerator = class {
379
389
  this.pathParser = new OpenAPIPathParser();
380
390
  this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
381
391
  this.outputStructureParser = options?.outputStructureParser ?? new OpenAPIOutputStructureParser(this.schemaConverter, this.schemaUtils);
392
+ this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
393
+ this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
394
+ this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
382
395
  }
383
- contentBuilder;
384
- parametersBuilder;
385
- schemaConverter;
386
- schemaUtils;
387
- jsonSerializer;
388
- pathParser;
389
- inputStructureParser;
390
- outputStructureParser;
391
396
  async generate(router, doc) {
392
397
  const builder = new OpenApiBuilder({
393
398
  ...doc,
@@ -397,7 +402,7 @@ var OpenAPIGenerator = class {
397
402
  await forEachAllContractProcedure(router, ({ contract, path }) => {
398
403
  try {
399
404
  const def = contract["~orpc"];
400
- if (this.options?.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
405
+ if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
401
406
  return;
402
407
  }
403
408
  const method = def.route?.method ?? "POST";
@@ -423,7 +428,7 @@ var OpenAPIGenerator = class {
423
428
  example: def.outputExample
424
429
  }) : void 0
425
430
  };
426
- if (this.options?.considerMissingTagDefinitionAsError && def.route?.tags) {
431
+ if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
427
432
  const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
428
433
  if (missingTag !== void 0) {
429
434
  throw new OpenAPIError(
@@ -452,10 +457,14 @@ var OpenAPIGenerator = class {
452
457
  Generate OpenAPI Error: ${e.message}
453
458
  Happened at path: ${path.join(".")}
454
459
  `, { cause: e });
455
- if (this.options?.throwOnError) {
460
+ if (this.errorHandlerStrategy === "throw") {
456
461
  throw error;
457
462
  }
458
- console.error(error);
463
+ if (this.errorHandlerStrategy === "log") {
464
+ console.error(error);
465
+ }
466
+ } else {
467
+ throw e;
459
468
  }
460
469
  }
461
470
  });
package/dist/node.js ADDED
@@ -0,0 +1,46 @@
1
+ import {
2
+ OpenAPIHandler
3
+ } from "./chunk-YXHH6XHB.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 '../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';
@@ -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,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,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
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.d.ts.map
@@ -9,6 +9,7 @@ import { type OpenAPI } from './openapi';
9
9
  import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
10
10
  import { type PublicOpenAPIParametersBuilder } from './openapi-parameters-builder';
11
11
  import { type PublicSchemaUtils } from './schema-utils';
12
+ type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
12
13
  export interface OpenAPIGeneratorOptions {
13
14
  contentBuilder?: PublicOpenAPIContentBuilder;
14
15
  parametersBuilder?: PublicOpenAPIParametersBuilder;
@@ -34,14 +35,13 @@ export interface OpenAPIGeneratorOptions {
34
35
  */
35
36
  ignoreUndefinedPathProcedures?: boolean;
36
37
  /**
37
- * Throw error when you have error in OpenAPI generator
38
+ * What to do when we found an error with our router
38
39
  *
39
- * @default false
40
+ * @default 'throw'
40
41
  */
41
- throwOnError?: boolean;
42
+ errorHandlerStrategy?: ErrorHandlerStrategy;
42
43
  }
43
44
  export declare class OpenAPIGenerator {
44
- private readonly options?;
45
45
  private readonly contentBuilder;
46
46
  private readonly parametersBuilder;
47
47
  private readonly schemaConverter;
@@ -50,7 +50,11 @@ export declare class OpenAPIGenerator {
50
50
  private readonly pathParser;
51
51
  private readonly inputStructureParser;
52
52
  private readonly outputStructureParser;
53
- constructor(options?: OpenAPIGeneratorOptions | undefined);
53
+ private readonly errorHandlerStrategy;
54
+ private readonly ignoreUndefinedPathProcedures;
55
+ private readonly considerMissingTagDefinitionAsError;
56
+ constructor(options?: OpenAPIGeneratorOptions);
54
57
  generate(router: ContractRouter | ANY_ROUTER, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
55
58
  }
59
+ export {};
56
60
  //# sourceMappingURL=openapi-generator.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.23.0",
4
+ "version": "0.24.0",
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/contract": "0.23.0",
47
- "@orpc/shared": "0.23.0",
48
- "@orpc/server": "0.23.0"
52
+ "@orpc/contract": "0.24.0",
53
+ "@orpc/server": "0.24.0",
54
+ "@orpc/shared": "0.24.0"
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