@orpc/openapi 2.0.0-beta.5 → 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 (90) hide show
  1. package/README.md +137 -102
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -0
  3. package/dist/adapters/aws-lambda/index.js +1 -0
  4. package/dist/adapters/aws-lambda/openapi-handler.d.ts +17 -0
  5. package/dist/adapters/aws-lambda/openapi-handler.js +20 -0
  6. package/dist/adapters/fastify/index.d.ts +2 -0
  7. package/dist/adapters/fastify/index.js +1 -0
  8. package/dist/adapters/fastify/openapi-handler.d.ts +14 -0
  9. package/dist/adapters/fastify/openapi-handler.js +17 -0
  10. package/dist/adapters/fetch/index.d.ts +3 -27
  11. package/dist/adapters/fetch/index.js +2 -0
  12. package/dist/adapters/fetch/openapi-handler.d.ts +14 -0
  13. package/dist/adapters/fetch/openapi-handler.js +17 -0
  14. package/dist/adapters/fetch/openapi-link.d.ts +20 -0
  15. package/dist/adapters/fetch/openapi-link.js +22 -0
  16. package/dist/adapters/node/index.d.ts +2 -18
  17. package/dist/adapters/node/index.js +1 -0
  18. package/dist/adapters/node/openapi-handler.d.ts +14 -0
  19. package/dist/adapters/node/openapi-handler.js +17 -0
  20. package/dist/adapters/standard/index.d.ts +4 -50
  21. package/dist/adapters/standard/index.js +3 -0
  22. package/dist/adapters/standard/openapi-handler-codec.d.ts +61 -0
  23. package/dist/adapters/standard/openapi-handler-codec.js +158 -0
  24. package/dist/adapters/standard/openapi-link-codec.d.ts +58 -0
  25. package/dist/adapters/standard/openapi-link-codec.js +290 -0
  26. package/dist/adapters/standard/openapi-matcher.d.ts +29 -0
  27. package/dist/adapters/standard/openapi-matcher.js +78 -0
  28. package/dist/adapters/standard/utils.js +31 -0
  29. package/dist/bracket-notation.d.ts +26 -0
  30. package/dist/bracket-notation.js +135 -0
  31. package/dist/client-factory.d.ts +24 -0
  32. package/dist/client-factory.js +15 -0
  33. package/dist/constants.d.ts +1 -0
  34. package/dist/constants.js +5 -0
  35. package/dist/extensions/route.d.ts +36 -42
  36. package/dist/extensions/route.js +13 -0
  37. package/dist/helpers/{index.d.mts → form-data.d.ts} +11 -5
  38. package/dist/helpers/form-data.js +78 -0
  39. package/dist/helpers/index.d.ts +2 -51
  40. package/dist/helpers/index.js +1 -0
  41. package/dist/index.d.ts +15 -120
  42. package/dist/index.js +11 -0
  43. package/dist/meta.d.ts +325 -0
  44. package/dist/meta.js +66 -0
  45. package/dist/openapi-generator-components.d.ts +2 -0
  46. package/dist/openapi-generator-components.js +227 -0
  47. package/dist/openapi-generator-operation.d.ts +13 -0
  48. package/dist/openapi-generator-operation.js +401 -0
  49. package/dist/openapi-generator.d.ts +87 -0
  50. package/dist/openapi-generator.js +119 -0
  51. package/dist/openapi-json-serializer.d.ts +79 -0
  52. package/dist/openapi-json-serializer.js +221 -0
  53. package/dist/openapi-serializer.d.ts +42 -0
  54. package/dist/openapi-serializer.js +69 -0
  55. package/dist/plugins/index.d.ts +2 -90
  56. package/dist/plugins/index.js +1 -0
  57. package/dist/plugins/openapi-reference.d.ts +112 -0
  58. package/dist/plugins/openapi-reference.js +164 -0
  59. package/dist/router-utils.d.ts +17 -0
  60. package/dist/router-utils.js +32 -0
  61. package/dist/types.d.ts +27 -0
  62. package/dist/utils.d.ts +9 -0
  63. package/dist/utils.js +44 -0
  64. package/package.json +87 -49
  65. package/dist/adapters/fetch/index.d.mts +0 -27
  66. package/dist/adapters/fetch/index.mjs +0 -34
  67. package/dist/adapters/node/index.d.mts +0 -18
  68. package/dist/adapters/node/index.mjs +0 -21
  69. package/dist/adapters/standard/index.d.mts +0 -50
  70. package/dist/adapters/standard/index.mjs +0 -12
  71. package/dist/extensions/route.d.mts +0 -43
  72. package/dist/extensions/route.mjs +0 -14
  73. package/dist/helpers/index.mjs +0 -39
  74. package/dist/index.d.mts +0 -120
  75. package/dist/index.mjs +0 -930
  76. package/dist/plugins/index.d.mts +0 -90
  77. package/dist/plugins/index.mjs +0 -162
  78. package/dist/shared/openapi.7vgmPxca.d.ts +0 -82
  79. package/dist/shared/openapi.B2SK0ZAr.mjs +0 -359
  80. package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
  81. package/dist/shared/openapi.BQzzr4-4.d.ts +0 -299
  82. package/dist/shared/openapi.BcEtAxQj.d.mts +0 -299
  83. package/dist/shared/openapi.Bt87OzTt.mjs +0 -131
  84. package/dist/shared/openapi.C7m7NAmH.d.mts +0 -142
  85. package/dist/shared/openapi.C7m7NAmH.d.ts +0 -142
  86. package/dist/shared/openapi.CTlpLuKN.mjs +0 -318
  87. package/dist/shared/openapi.CX6Ri5dP.d.mts +0 -82
  88. package/dist/shared/openapi.CYgMBSUF.d.mts +0 -18
  89. package/dist/shared/openapi.CYgMBSUF.d.ts +0 -18
  90. package/dist/shared/openapi.DmAa7YPO.mjs +0 -275
@@ -0,0 +1,221 @@
1
+ import { NullProtoObj, copyOnWrite, isPlainObject } from "@orpc/shared";
2
+ // src/openapi-json-serializer.ts
3
+ const DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS = {
4
+ undefined: {
5
+ condition(data) {
6
+ return data === void 0;
7
+ },
8
+ serialize() {
9
+ return null;
10
+ },
11
+ isTerminal: true
12
+ },
13
+ bigint: {
14
+ condition(data) {
15
+ return typeof data === "bigint";
16
+ },
17
+ serialize(data) {
18
+ return data.toString();
19
+ },
20
+ isTerminal: true
21
+ },
22
+ date: {
23
+ condition(data) {
24
+ return data instanceof Date;
25
+ },
26
+ serialize(data) {
27
+ if (Number.isNaN(data.getTime())) return null;
28
+ return data.toISOString();
29
+ },
30
+ isTerminal: true
31
+ },
32
+ nan: {
33
+ condition(data) {
34
+ return typeof data === "number" && Number.isNaN(data);
35
+ },
36
+ serialize() {
37
+ return null;
38
+ },
39
+ isTerminal: true
40
+ },
41
+ infinity: {
42
+ condition(data) {
43
+ return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
44
+ },
45
+ serialize() {
46
+ return null;
47
+ },
48
+ isTerminal: true
49
+ },
50
+ url: {
51
+ condition(data) {
52
+ return data instanceof URL;
53
+ },
54
+ serialize(data) {
55
+ return data.toString();
56
+ },
57
+ isTerminal: true
58
+ },
59
+ set: {
60
+ condition(data) {
61
+ return data instanceof Set;
62
+ },
63
+ serialize(data) {
64
+ return Array.from(data);
65
+ }
66
+ },
67
+ map: {
68
+ condition(data) {
69
+ return data instanceof Map;
70
+ },
71
+ serialize(data) {
72
+ return Array.from(data.entries());
73
+ }
74
+ }
75
+ };
76
+ /**
77
+ * The JSON layer behind `OpenAPISerializer`: one-way serialization of types like `Date`, `BigInt`,
78
+ * and `Set` into JSON-friendly values, for places that only accept JSON.
79
+ *
80
+ * @see {@link https://orpc.dev/docs/openapi/serializer#openapi-json-serializer | OpenAPI Serializer - OpenAPI JSON Serializer}
81
+ */
82
+ var OpenAPIJsonSerializer = class {
83
+ inlineBuiltInHandlers;
84
+ handlerEntries;
85
+ constructor(options = {}) {
86
+ const customHandlers = options.handlers;
87
+ if (customHandlers === void 0) {
88
+ this.inlineBuiltInHandlers = true;
89
+ return;
90
+ }
91
+ let inlineBuiltInHandlers = true;
92
+ let handlerEntries = [];
93
+ for (const key of Object.keys(customHandlers)) {
94
+ const handler = customHandlers[key];
95
+ if (inlineBuiltInHandlers && key in DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS) {
96
+ inlineBuiltInHandlers = false;
97
+ break;
98
+ }
99
+ if (handler !== void 0) handlerEntries.push(handler);
100
+ }
101
+ if (!inlineBuiltInHandlers) {
102
+ handlerEntries = [];
103
+ for (const handler of Object.values({
104
+ ...DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS,
105
+ ...customHandlers
106
+ })) if (handler !== void 0) handlerEntries.push(handler);
107
+ }
108
+ this.inlineBuiltInHandlers = inlineBuiltInHandlers;
109
+ this.handlerEntries = handlerEntries.length === 0 ? void 0 : handlerEntries;
110
+ }
111
+ serializeJson(data) {
112
+ const maps = [];
113
+ const blobs = [];
114
+ return {
115
+ json: this.serializeValue(data, [], maps, blobs),
116
+ maps,
117
+ blobs
118
+ };
119
+ }
120
+ /**
121
+ * `segments` is a shared mutable stack (push/pop while walking),
122
+ * so it must be copied before being stored in `maps`.
123
+ */
124
+ serializeValue(data, segments, maps, blobs) {
125
+ const handlerEntries = this.handlerEntries;
126
+ /**
127
+ * Inlined version of DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS: primitives
128
+ * are dispatched on typeof and skip every handler condition check.
129
+ * Must match the built-in handlers exactly.
130
+ * Primitives without a built-in handler return early unless custom handlers must see them.
131
+ */
132
+ if (this.inlineBuiltInHandlers) switch (typeof data) {
133
+ case "string":
134
+ case "boolean":
135
+ if (handlerEntries === void 0) return data;
136
+ break;
137
+ case "number":
138
+ if (!Number.isFinite(data)) return null;
139
+ if (handlerEntries === void 0) return data;
140
+ break;
141
+ case "undefined": return null;
142
+ case "bigint": return data.toString();
143
+ case "object":
144
+ if (data === null) {
145
+ if (handlerEntries === void 0) return data;
146
+ break;
147
+ }
148
+ if (data instanceof Date) return Number.isNaN(data.getTime()) ? null : data.toISOString();
149
+ if (data instanceof URL) return data.toString();
150
+ if (data instanceof Set) return this.serializeValue(Array.from(data), segments, maps, blobs);
151
+ if (data instanceof Map) return this.serializeValue(Array.from(data.entries()), segments, maps, blobs);
152
+ }
153
+ if (handlerEntries) for (let i = 0; i < handlerEntries.length; i++) {
154
+ const handler = handlerEntries[i];
155
+ if (handler.condition(data)) {
156
+ const serialized = handler.serialize(data);
157
+ if (handler.isTerminal) {
158
+ if (serialized instanceof Blob) {
159
+ maps.push(segments.slice());
160
+ blobs.push(serialized);
161
+ }
162
+ return serialized;
163
+ }
164
+ return this.serializeValue(serialized, segments, maps, blobs);
165
+ }
166
+ }
167
+ if (typeof data !== "object" || data === null) return data;
168
+ if (data instanceof Blob) {
169
+ maps.push(segments.slice());
170
+ blobs.push(data);
171
+ return data;
172
+ }
173
+ if (Array.isArray(data)) {
174
+ const json = [];
175
+ for (let i = 0; i < data.length; i++) {
176
+ segments.push(i);
177
+ json.push(this.serializeValue(data[i], segments, maps, blobs));
178
+ segments.pop();
179
+ }
180
+ return json;
181
+ }
182
+ if (isPlainObject(data)) {
183
+ const json = new NullProtoObj();
184
+ for (const k of Object.keys(data)) {
185
+ const v = data[k];
186
+ /**
187
+ * Skip custom toJSON methods to avoid JSON.stringify invoking them,
188
+ * which could cause meta and serialized data mismatches during deserialization.
189
+ * Instead, rely on custom handlers.
190
+ */
191
+ if (k === "toJSON" && typeof v === "function") continue;
192
+ if (v === void 0) continue;
193
+ segments.push(k);
194
+ json[k] = this.serializeValue(v, segments, maps, blobs);
195
+ segments.pop();
196
+ }
197
+ return json;
198
+ }
199
+ return data;
200
+ }
201
+ deserializeJson(serialized) {
202
+ const ref = { json: serialized.json };
203
+ if (serialized.blobs?.length) for (let i = 0; i < serialized.maps.length; i++) {
204
+ const blob = serialized.blobs[i];
205
+ if (!(blob instanceof Blob)) throw new TypeError(`Invalid OpenAPI serialized data: blob ${i} is not a Blob.`);
206
+ const segments = serialized.maps[i];
207
+ let original = serialized;
208
+ let currentRef = ref;
209
+ let preSegment = "json";
210
+ for (let j = 0; j < segments.length; j++) {
211
+ original = original[preSegment];
212
+ currentRef = copyOnWrite(currentRef, preSegment, original);
213
+ preSegment = segments[j];
214
+ if (!Object.hasOwn(currentRef, preSegment)) throw new TypeError(`Invalid OpenAPI serialized data: segment "${preSegment}" does not exist.`);
215
+ }
216
+ currentRef[preSegment] = blob;
217
+ }
218
+ return ref.json;
219
+ }
220
+ };
221
+ export { OpenAPIJsonSerializer };
@@ -0,0 +1,42 @@
1
+ import { BracketNotationSerializerOptions } from "./bracket-notation.js";
2
+ import { OpenAPIJsonSerializer, OpenAPIJsonSerializerOptions } from "./openapi-json-serializer.js";
3
+ import { StandardBody } from "@standard-server/core";
4
+ export interface OpenAPISerializerSerializeOptions {
5
+ /**
6
+ * Use FormData for serialization when nested blobs are present.
7
+ * Does not apply to root-level Blob values.
8
+ *
9
+ * @default true
10
+ */
11
+ useFormDataForBlobFields?: boolean | undefined;
12
+ /**
13
+ * When enabled, the serialized output is always returned as a FormData instance using bracket notation.
14
+ *
15
+ * @default false
16
+ */
17
+ asFormData?: boolean | undefined;
18
+ }
19
+ export interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
20
+ /**
21
+ * Options for bracket notation serializer, like maxDeserializingEmptySlots
22
+ */
23
+ bracketNotation?: BracketNotationSerializerOptions | undefined;
24
+ /**
25
+ * Default options for serialize method
26
+ */
27
+ serialize?: OpenAPISerializerSerializeOptions | undefined;
28
+ }
29
+ /**
30
+ * Handles one-way serialization of oRPC payloads into JSON-friendly formats,
31
+ * partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
32
+ *
33
+ * @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
34
+ */
35
+ export declare class OpenAPISerializer extends OpenAPIJsonSerializer {
36
+ private readonly bracketNotation;
37
+ private readonly defaultSerializeOptions;
38
+ constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
39
+ serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
40
+ private serializePayload;
41
+ deserialize(data: StandardBody): unknown;
42
+ }
@@ -0,0 +1,69 @@
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
7
+ /**
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,90 +1,2 @@
1
- import { Context } from '@orpc/server';
2
- import { StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions, StandardHandlerOptions } from '@orpc/server/standard';
3
- import { Value, Promisable } from '@orpc/shared';
4
- import { ApiReferenceConfiguration } from '@scalar/api-reference';
5
- import { StandardUrl } from '@standardserver/core';
6
- import { SwaggerUIOptions } from 'swagger-ui';
7
- import { a as OpenAPIDocument } from '../shared/openapi.CYgMBSUF.js';
8
- import '@hey-api/spec-types';
9
- import '@orpc/client';
10
-
11
- type OpenAPIReferenceHandlerPluginProvider = 'scalar' | 'swagger';
12
- interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReferenceConfiguration> {
13
- }
14
- interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
15
- dom_id?: undefined | never;
16
- presets?: undefined | `SwaggerUIBundle.${string}`[];
17
- plugins?: undefined | `SwaggerUIBundle.${string}`[];
18
- }
19
- interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
20
- /**
21
- * A static or dynamic OpenAPI document to serve.
22
- * Receives routing interceptor options when provided as a function.
23
- */
24
- spec: Value<Promisable<OpenAPIDocument>, [StandardHandlerRoutingInterceptorOptions<T>]>;
25
- /**
26
- * The URL path at which to serve the OpenAPI JSON.
27
- *
28
- * @default '/spec.json'
29
- */
30
- specPath?: StandardUrl;
31
- /**
32
- * The UI provider to use for rendering the API reference.
33
- *
34
- * @default 'scalar'
35
- */
36
- provider?: TProvider;
37
- /**
38
- * Provider-specific configuration passed directly to the chosen UI library.
39
- * Options differ depending on `provider`.
40
- */
41
- providerConfig?: undefined | (TProvider extends 'swagger' ? OpenAPIReferenceHandlerPluginSwaggerConfig : OpenAPIReferenceHandlerPluginScalarConfig);
42
- /**
43
- * URL for the provider's main script bundle.
44
- *
45
- * @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference' | 'https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js'
46
- */
47
- providerScriptUrl?: undefined | string;
48
- /**
49
- * URL for the provider's stylesheet.
50
- *
51
- * @default undefined | 'https://unpkg.com/swagger-ui-dist/swagger-ui.css'
52
- */
53
- providerCssUrl?: undefined | string;
54
- /**
55
- * The URL path at which to serve the API reference UI.
56
- *
57
- * @default '/'
58
- */
59
- docsPath?: StandardUrl;
60
- /**
61
- * The document title for the API reference UI.
62
- *
63
- * @default spec.info.title
64
- */
65
- docsTitle?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]>;
66
- /**
67
- * Raw HTML to inject into the `<head>` of the API reference page.
68
- * Useful for custom stylesheets, meta tags, or scripts.
69
- *
70
- * @default ''
71
- */
72
- docsHead?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]>;
73
- }
74
- declare class OpenAPIReferenceHandlerPlugin<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> implements StandardHandlerPlugin<T> {
75
- name: string;
76
- private readonly spec;
77
- private readonly specPath;
78
- private readonly provider;
79
- private readonly providerConfig;
80
- private readonly providerScriptUrl;
81
- private readonly providerCssUrl;
82
- private readonly docsPath;
83
- private readonly docsTitle;
84
- private readonly docsHead;
85
- constructor(options: OpenAPIReferenceHandlerPluginOptions<T, TProvider>);
86
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
87
- }
88
-
89
- export { OpenAPIReferenceHandlerPlugin };
90
- export type { OpenAPIReferenceHandlerPluginOptions, OpenAPIReferenceHandlerPluginProvider, OpenAPIReferenceHandlerPluginScalarConfig, OpenAPIReferenceHandlerPluginSwaggerConfig };
1
+ import { OpenAPIReferenceHandlerPlugin, OpenAPIReferenceHandlerPluginOptions, OpenAPIReferenceHandlerPluginProvider, OpenAPIReferenceHandlerPluginScalarConfig, OpenAPIReferenceHandlerPluginSwaggerConfig } from "./openapi-reference.js";
2
+ export { OpenAPIReferenceHandlerPlugin, OpenAPIReferenceHandlerPluginOptions, OpenAPIReferenceHandlerPluginProvider, OpenAPIReferenceHandlerPluginScalarConfig, OpenAPIReferenceHandlerPluginSwaggerConfig };
@@ -0,0 +1 @@
1
+ export { OpenAPIReferenceHandlerPlugin } from "./openapi-reference.js";
@@ -0,0 +1,112 @@
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;
26
+ }
27
+ export interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
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;
88
+ }
89
+ /**
90
+ * Serves API reference documentation powered by Scalar or Swagger UI,
91
+ * and exposes the OpenAPI specification as JSON.
92
+ *
93
+ * @remarks
94
+ * **Note**: By default, the API reference UI is served from `/` and the OpenAPI specification from `/spec.json`.
95
+ *
96
+ * @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
97
+ */
98
+ export declare class OpenAPIReferenceHandlerPlugin<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> implements StandardHandlerPlugin<T> {
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
+ }