@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50

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 (65) hide show
  1. package/dist/adapters/aws-lambda/index.d.ts +3 -15
  2. package/dist/adapters/aws-lambda/index.js +1 -1
  3. package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
  4. package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
  5. package/dist/adapters/fastify/index.d.ts +2 -1
  6. package/dist/adapters/fastify/index.js +1 -1
  7. package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
  8. package/dist/adapters/fastify/openapi-handler.js +16 -14
  9. package/dist/adapters/fetch/index.d.ts +3 -2
  10. package/dist/adapters/fetch/index.js +2 -2
  11. package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
  12. package/dist/adapters/fetch/openapi-handler.js +16 -14
  13. package/dist/adapters/fetch/openapi-link.d.ts +9 -10
  14. package/dist/adapters/fetch/openapi-link.js +21 -19
  15. package/dist/adapters/node/index.d.ts +2 -1
  16. package/dist/adapters/node/index.js +1 -1
  17. package/dist/adapters/node/openapi-handler.d.ts +8 -9
  18. package/dist/adapters/node/openapi-handler.js +16 -14
  19. package/dist/adapters/standard/index.d.ts +4 -3
  20. package/dist/adapters/standard/index.js +3 -3
  21. package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
  22. package/dist/adapters/standard/openapi-handler-codec.js +143 -205
  23. package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
  24. package/dist/adapters/standard/openapi-link-codec.js +262 -377
  25. package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
  26. package/dist/adapters/standard/openapi-matcher.js +78 -108
  27. package/dist/adapters/standard/utils.js +28 -44
  28. package/dist/bracket-notation.d.ts +22 -22
  29. package/dist/bracket-notation.js +123 -173
  30. package/dist/client-factory.d.ts +12 -12
  31. package/dist/client-factory.js +13 -11
  32. package/dist/constants.d.ts +1 -4
  33. package/dist/constants.js +5 -4
  34. package/dist/extensions/route.d.ts +36 -36
  35. package/dist/extensions/route.js +7 -6
  36. package/dist/helpers/form-data.d.ts +1 -1
  37. package/dist/helpers/form-data.js +74 -86
  38. package/dist/helpers/index.d.ts +2 -1
  39. package/dist/helpers/index.js +1 -1
  40. package/dist/index.d.ts +15 -13
  41. package/dist/index.js +11 -11
  42. package/dist/meta.d.ts +298 -298
  43. package/dist/meta.js +54 -72
  44. package/dist/openapi-generator-components.d.ts +2 -31
  45. package/dist/openapi-generator-components.js +200 -248
  46. package/dist/openapi-generator-operation.d.ts +12 -33
  47. package/dist/openapi-generator-operation.js +369 -437
  48. package/dist/openapi-generator.d.ts +75 -80
  49. package/dist/openapi-generator.js +114 -142
  50. package/dist/openapi-json-serializer.d.ts +65 -65
  51. package/dist/openapi-json-serializer.js +218 -257
  52. package/dist/openapi-serializer.d.ts +31 -32
  53. package/dist/openapi-serializer.js +68 -92
  54. package/dist/plugins/index.d.ts +2 -1
  55. package/dist/plugins/index.js +1 -1
  56. package/dist/plugins/openapi-reference.d.ts +99 -102
  57. package/dist/plugins/openapi-reference.js +109 -132
  58. package/dist/router-utils.d.ts +7 -10
  59. package/dist/router-utils.js +30 -34
  60. package/dist/types.d.ts +8 -12
  61. package/dist/utils.d.ts +5 -10
  62. package/dist/utils.js +39 -42
  63. package/package.json +12 -12
  64. package/dist/adapters/standard/utils.d.ts +0 -4
  65. package/dist/types.js +0 -1
@@ -1,93 +1,69 @@
1
- import { createORPCErrorFromJson, isORPCErrorJson, toORPCError, wrapAsyncIteratorPreservingEventMeta, } from '@orpc/client';
2
- import { isAsyncIteratorObject } from '@orpc/shared';
3
- import { EventStreamErrorEvent } from '@standard-server/core';
4
- import { BracketNotationSerializer } from './bracket-notation.js';
5
- import { OpenAPIJsonSerializer } from './openapi-json-serializer.js';
1
+ import { BracketNotationSerializer } from "./bracket-notation.js";
2
+ import { OpenAPIJsonSerializer } from "./openapi-json-serializer.js";
3
+ import { isAsyncIteratorObject } from "@orpc/shared";
4
+ import { createORPCErrorFromJson, isORPCErrorJson, toORPCError, wrapAsyncIteratorPreservingEventMeta } from "@orpc/client";
5
+ import { EventStreamErrorEvent } from "@standard-server/core";
6
+ // src/openapi-serializer.ts
6
7
  /**
7
- * Handles one-way serialization of oRPC payloads into JSON-friendly formats,
8
- * partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
9
- *
10
- * @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
11
- */
12
- export class OpenAPISerializer extends OpenAPIJsonSerializer {
13
- bracketNotation;
14
- defaultSerializeOptions;
15
- constructor({ bracketNotation, serialize, ...options } = {}) {
16
- super(options);
17
- this.bracketNotation = new BracketNotationSerializer(bracketNotation);
18
- this.defaultSerializeOptions = serialize;
19
- }
20
- serialize(data, options = {}) {
21
- if (!options.asFormData) {
22
- // standard body already supports these types without additional serialization.
23
- if (data === undefined || data instanceof ReadableStream || data instanceof Blob) {
24
- return data;
25
- }
26
- if (isAsyncIteratorObject(data)) {
27
- return wrapAsyncIteratorPreservingEventMeta(data, {
28
- mapResult: (result) => {
29
- // standard event stream data already supports these types without additional serialization.
30
- if (result.value === undefined) {
31
- return result;
32
- }
33
- return { done: result.done, value: this.serializePayload(result.value, false, false) };
34
- },
35
- mapError: (e) => new EventStreamErrorEvent(this.serializePayload(toORPCError(e).toJSON(), false, false), {
36
- cause: e,
37
- }),
38
- });
39
- }
40
- }
41
- const useFormDataForBlobFields = options.useFormDataForBlobFields ??
42
- this.defaultSerializeOptions?.useFormDataForBlobFields ??
43
- true;
44
- const asFormData = options.asFormData ?? this.defaultSerializeOptions?.asFormData ?? false;
45
- return this.serializePayload(data, useFormDataForBlobFields, asFormData);
46
- }
47
- serializePayload(value, useFormDataForBlobFields, asFormData) {
48
- const { json, blobs } = this.serializeJson(value);
49
- if (!asFormData &&
50
- (json instanceof Blob || json === undefined || !blobs?.length || !useFormDataForBlobFields)) {
51
- return json;
52
- }
53
- const form = new FormData();
54
- for (const [path, value] of this.bracketNotation.serialize(json)) {
55
- if (value instanceof Blob) {
56
- form.append(path, value);
57
- }
58
- else if (value !== undefined && value !== null) {
59
- // oxlint-disable-next-line typescript/no-base-to-string
60
- form.append(path, String(value));
61
- }
62
- }
63
- return form;
64
- }
65
- deserialize(data) {
66
- if (data === undefined || data instanceof ReadableStream || data instanceof Blob) {
67
- return data;
68
- }
69
- if (isAsyncIteratorObject(data)) {
70
- return wrapAsyncIteratorPreservingEventMeta(data, {
71
- mapResult: (result) => {
72
- if (result.value === undefined) {
73
- return result;
74
- }
75
- return { done: result.done, value: this.deserializeJson({ json: result.value }) };
76
- },
77
- mapError: (e) => {
78
- if (e instanceof EventStreamErrorEvent) {
79
- const deserialized = this.deserializeJson({ json: e.data });
80
- if (isORPCErrorJson(deserialized)) {
81
- return createORPCErrorFromJson(deserialized, { cause: e });
82
- }
83
- }
84
- return e;
85
- },
86
- });
87
- }
88
- if (data instanceof URLSearchParams || data instanceof FormData) {
89
- data = this.bracketNotation.deserialize(Array.from(data.entries()));
90
- }
91
- return this.deserializeJson({ json: data });
92
- }
93
- }
8
+ * Handles one-way serialization of oRPC payloads into JSON-friendly formats,
9
+ * partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
12
+ */
13
+ var OpenAPISerializer = class extends OpenAPIJsonSerializer {
14
+ bracketNotation;
15
+ defaultSerializeOptions;
16
+ constructor({ bracketNotation, serialize, ...options } = {}) {
17
+ super(options);
18
+ this.bracketNotation = new BracketNotationSerializer(bracketNotation);
19
+ this.defaultSerializeOptions = serialize;
20
+ }
21
+ serialize(data, options = {}) {
22
+ if (!options.asFormData) {
23
+ if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) return data;
24
+ if (isAsyncIteratorObject(data)) return wrapAsyncIteratorPreservingEventMeta(data, {
25
+ mapResult: (result) => {
26
+ if (result.value === void 0) return result;
27
+ return {
28
+ done: result.done,
29
+ value: this.serializePayload(result.value, false, false)
30
+ };
31
+ },
32
+ mapError: (e) => new EventStreamErrorEvent(this.serializePayload(toORPCError(e).toJSON(), false, false), { cause: e })
33
+ });
34
+ }
35
+ const useFormDataForBlobFields = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
36
+ const asFormData = options.asFormData ?? this.defaultSerializeOptions?.asFormData ?? false;
37
+ return this.serializePayload(data, useFormDataForBlobFields, asFormData);
38
+ }
39
+ serializePayload(value, useFormDataForBlobFields, asFormData) {
40
+ const { json, blobs } = this.serializeJson(value);
41
+ if (!asFormData && (json instanceof Blob || json === void 0 || !blobs?.length || !useFormDataForBlobFields)) return json;
42
+ const form = new FormData();
43
+ for (const [path, value] of this.bracketNotation.serialize(json)) if (value instanceof Blob) form.append(path, value);
44
+ else if (value !== void 0 && value !== null) form.append(path, String(value));
45
+ return form;
46
+ }
47
+ deserialize(data) {
48
+ if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) return data;
49
+ if (isAsyncIteratorObject(data)) return wrapAsyncIteratorPreservingEventMeta(data, {
50
+ mapResult: (result) => {
51
+ if (result.value === void 0) return result;
52
+ return {
53
+ done: result.done,
54
+ value: this.deserializeJson({ json: result.value })
55
+ };
56
+ },
57
+ mapError: (e) => {
58
+ if (e instanceof EventStreamErrorEvent) {
59
+ const deserialized = this.deserializeJson({ json: e.data });
60
+ if (isORPCErrorJson(deserialized)) return createORPCErrorFromJson(deserialized, { cause: e });
61
+ }
62
+ return e;
63
+ }
64
+ });
65
+ if (data instanceof URLSearchParams || data instanceof FormData) data = this.bracketNotation.deserialize(Array.from(data.entries()));
66
+ return this.deserializeJson({ json: data });
67
+ }
68
+ };
69
+ export { OpenAPISerializer };
@@ -1 +1,2 @@
1
- export * from './openapi-reference.ts';
1
+ import { OpenAPIReferenceHandlerPlugin, OpenAPIReferenceHandlerPluginOptions, OpenAPIReferenceHandlerPluginProvider, OpenAPIReferenceHandlerPluginScalarConfig, OpenAPIReferenceHandlerPluginSwaggerConfig } from "./openapi-reference.js";
2
+ export { OpenAPIReferenceHandlerPlugin, OpenAPIReferenceHandlerPluginOptions, OpenAPIReferenceHandlerPluginProvider, OpenAPIReferenceHandlerPluginScalarConfig, OpenAPIReferenceHandlerPluginSwaggerConfig };
@@ -1 +1 @@
1
- export * from './openapi-reference.js';
1
+ export { OpenAPIReferenceHandlerPlugin } from "./openapi-reference.js";
@@ -1,93 +1,90 @@
1
- import type { Context } from '@orpc/server';
2
- import type { StandardHandlerOptions, StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions } from '@orpc/server/standard';
3
- import type { Promisable, Value } from '@orpc/shared';
4
- import type { ApiReferenceConfiguration as ScalarProviderConfig } from '@scalar/api-reference';
5
- import type { StandardUrl } from '@standard-server/core';
6
- import type { SwaggerUIOptions } from 'swagger-ui';
7
- import type { OpenAPIDocument, OpenAPIVersion } from '../types.ts';
8
- export type OpenAPIReferenceHandlerPluginProvider = 'scalar' | 'swagger';
9
- export interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ScalarProviderConfig> {
10
- }
11
- export interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
12
- dom_id?: undefined;
13
- /**
14
- * Paths to global variables holding the presets, resolved in the browser,
15
- * e.g. `'SwaggerUIBundle.presets.apis'`. Load custom presets through `docsHead`.
16
- *
17
- * @default ['SwaggerUIBundle.presets.apis']
18
- */
19
- presets?: string[] | undefined;
20
- /**
21
- * Paths to global variables holding the plugins, resolved in the browser,
22
- * e.g. `'SwaggerUIBundle.plugins.DownloadUrl'`. Load custom plugins through `docsHead`.
23
- *
24
- * @default ['SwaggerUIBundle.plugins.DownloadUrl']
25
- */
26
- plugins?: string[] | undefined;
1
+ import { OpenAPIDocument, OpenAPIVersion } from "../types.js";
2
+ import { Promisable, Value } from "@orpc/shared";
3
+ import { Context } from "@orpc/server";
4
+ import { StandardUrl } from "@standard-server/core";
5
+ import { StandardHandlerOptions, StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions } from "@orpc/server/standard";
6
+ import { ApiReferenceConfiguration } from "@scalar/api-reference";
7
+ import { SwaggerUIOptions } from "swagger-ui";
8
+ export type OpenAPIReferenceHandlerPluginProvider = "scalar" | "swagger";
9
+ export interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReferenceConfiguration> {}
10
+ export interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, "dom_id" | "presets" | "plugins">> {
11
+ dom_id?: undefined;
12
+ /**
13
+ * Paths to global variables holding the presets, resolved in the browser,
14
+ * e.g. `'SwaggerUIBundle.presets.apis'`. Load custom presets through `docsHead`.
15
+ *
16
+ * @default ['SwaggerUIBundle.presets.apis']
17
+ */
18
+ presets?: string[] | undefined;
19
+ /**
20
+ * Paths to global variables holding the plugins, resolved in the browser,
21
+ * e.g. `'SwaggerUIBundle.plugins.DownloadUrl'`. Load custom plugins through `docsHead`.
22
+ *
23
+ * @default ['SwaggerUIBundle.plugins.DownloadUrl']
24
+ */
25
+ plugins?: string[] | undefined;
27
26
  }
28
27
  export interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
29
- /**
30
- * A static or dynamic OpenAPI document to serve.
31
- * Receives routing interceptor options when provided as a function.
32
- */
33
- spec: Value<Promisable<OpenAPIDocument<OpenAPIVersion>>, [
34
- StandardHandlerRoutingInterceptorOptions<T>
35
- ]>;
36
- /**
37
- * Determines whether the docs UI and OpenAPI JSON are allowed to be served for a request.
38
- * When it resolves to `false`, the request falls through as unmatched,
39
- * as if the plugin were not installed. Useful for restricting access
40
- * to authenticated users.
41
- */
42
- allow?: Value<Promisable<boolean>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
43
- /**
44
- * The URL path at which to serve the OpenAPI JSON.
45
- *
46
- * @default '/spec.json'
47
- */
48
- specPath?: StandardUrl | undefined;
49
- /**
50
- * The UI provider to use for rendering the API reference.
51
- *
52
- * @default 'scalar'
53
- */
54
- provider?: TProvider | undefined;
55
- /**
56
- * Provider-specific configuration passed directly to the chosen UI library.
57
- * Options differ depending on `provider`.
58
- */
59
- providerConfig?: (TProvider extends 'swagger' ? OpenAPIReferenceHandlerPluginSwaggerConfig : OpenAPIReferenceHandlerPluginScalarConfig) | undefined;
60
- /**
61
- * URL for the provider's main script bundle.
62
- *
63
- * @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference' | 'https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js'
64
- */
65
- providerScriptUrl?: string | undefined;
66
- /**
67
- * URL for the provider's stylesheet.
68
- *
69
- * @default undefined | 'https://unpkg.com/swagger-ui-dist/swagger-ui.css'
70
- */
71
- providerCssUrl?: string | undefined;
72
- /**
73
- * The URL path at which to serve the API reference UI.
74
- *
75
- * @default '/'
76
- */
77
- docsPath?: StandardUrl | undefined;
78
- /**
79
- * The document title for the API reference UI.
80
- *
81
- * @default spec.info.title
82
- */
83
- docsTitle?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
84
- /**
85
- * Raw HTML to inject into the `<head>` of the API reference page.
86
- * Useful for custom stylesheets, meta tags, or scripts.
87
- *
88
- * @default ''
89
- */
90
- docsHead?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
28
+ /**
29
+ * A static or dynamic OpenAPI document to serve.
30
+ * Receives routing interceptor options when provided as a function.
31
+ */
32
+ spec: Value<Promisable<OpenAPIDocument<OpenAPIVersion>>, [StandardHandlerRoutingInterceptorOptions<T>]>;
33
+ /**
34
+ * Determines whether the docs UI and OpenAPI JSON are allowed to be served for a request.
35
+ * When it resolves to `false`, the request falls through as unmatched,
36
+ * as if the plugin were not installed. Useful for restricting access
37
+ * to authenticated users.
38
+ */
39
+ allow?: Value<Promisable<boolean>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
40
+ /**
41
+ * The URL path at which to serve the OpenAPI JSON.
42
+ *
43
+ * @default '/spec.json'
44
+ */
45
+ specPath?: StandardUrl | undefined;
46
+ /**
47
+ * The UI provider to use for rendering the API reference.
48
+ *
49
+ * @default 'scalar'
50
+ */
51
+ provider?: TProvider | undefined;
52
+ /**
53
+ * Provider-specific configuration passed directly to the chosen UI library.
54
+ * Options differ depending on `provider`.
55
+ */
56
+ providerConfig?: (TProvider extends "swagger" ? OpenAPIReferenceHandlerPluginSwaggerConfig : OpenAPIReferenceHandlerPluginScalarConfig) | undefined;
57
+ /**
58
+ * URL for the provider's main script bundle.
59
+ *
60
+ * @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference' | 'https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js'
61
+ */
62
+ providerScriptUrl?: string | undefined;
63
+ /**
64
+ * URL for the provider's stylesheet.
65
+ *
66
+ * @default undefined | 'https://unpkg.com/swagger-ui-dist/swagger-ui.css'
67
+ */
68
+ providerCssUrl?: string | undefined;
69
+ /**
70
+ * The URL path at which to serve the API reference UI.
71
+ *
72
+ * @default '/'
73
+ */
74
+ docsPath?: StandardUrl | undefined;
75
+ /**
76
+ * The document title for the API reference UI.
77
+ *
78
+ * @default spec.info.title
79
+ */
80
+ docsTitle?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
81
+ /**
82
+ * Raw HTML to inject into the `<head>` of the API reference page.
83
+ * Useful for custom stylesheets, meta tags, or scripts.
84
+ *
85
+ * @default ''
86
+ */
87
+ docsHead?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
91
88
  }
92
89
  /**
93
90
  * Serves API reference documentation powered by Scalar or Swagger UI,
@@ -99,17 +96,17 @@ export interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvid
99
96
  * @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
100
97
  */
101
98
  export declare class OpenAPIReferenceHandlerPlugin<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> implements StandardHandlerPlugin<T> {
102
- name: string;
103
- private readonly spec;
104
- private readonly allow;
105
- private readonly specPath;
106
- private readonly provider;
107
- private readonly providerConfig;
108
- private readonly providerScriptUrl;
109
- private readonly providerCssUrl;
110
- private readonly docsPath;
111
- private readonly docsTitle;
112
- private readonly docsHead;
113
- constructor(options: OpenAPIReferenceHandlerPluginOptions<T, TProvider>);
114
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
115
- }
99
+ name: string;
100
+ private readonly spec;
101
+ private readonly allow;
102
+ private readonly specPath;
103
+ private readonly provider;
104
+ private readonly providerConfig;
105
+ private readonly providerScriptUrl;
106
+ private readonly providerCssUrl;
107
+ private readonly docsPath;
108
+ private readonly docsTitle;
109
+ private readonly docsHead;
110
+ constructor(options: OpenAPIReferenceHandlerPluginOptions<T, TProvider>);
111
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
112
+ }