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

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 (127) hide show
  1. package/README.md +4 -4
  2. package/dist/adapters/aws-lambda/index.d.ts +15 -0
  3. package/dist/adapters/aws-lambda/index.js +1 -0
  4. package/dist/adapters/aws-lambda/openapi-handler.d.ts +18 -0
  5. package/dist/adapters/aws-lambda/openapi-handler.js +18 -0
  6. package/dist/adapters/fastify/index.d.ts +1 -0
  7. package/dist/adapters/fastify/index.js +1 -0
  8. package/dist/adapters/fastify/openapi-handler.d.ts +15 -0
  9. package/dist/adapters/fastify/openapi-handler.js +15 -0
  10. package/dist/adapters/fetch/index.d.ts +2 -0
  11. package/dist/adapters/fetch/index.js +2 -0
  12. package/dist/adapters/fetch/openapi-handler.d.ts +15 -0
  13. package/dist/adapters/fetch/openapi-handler.js +15 -0
  14. package/dist/adapters/fetch/openapi-link.d.ts +21 -0
  15. package/dist/adapters/fetch/openapi-link.js +20 -0
  16. package/dist/adapters/node/index.d.ts +1 -0
  17. package/dist/adapters/node/index.js +1 -0
  18. package/dist/adapters/node/openapi-handler.d.ts +15 -0
  19. package/dist/adapters/node/openapi-handler.js +15 -0
  20. package/dist/adapters/standard/index.d.ts +3 -0
  21. package/dist/adapters/standard/index.js +3 -0
  22. package/dist/adapters/standard/openapi-handler-codec.d.ts +62 -0
  23. package/dist/adapters/standard/openapi-handler-codec.js +220 -0
  24. package/dist/adapters/standard/openapi-link-codec.d.ts +62 -0
  25. package/dist/adapters/standard/openapi-link-codec.js +405 -0
  26. package/dist/adapters/standard/openapi-matcher.d.ts +29 -0
  27. package/dist/adapters/standard/openapi-matcher.js +108 -0
  28. package/dist/adapters/standard/utils.d.ts +4 -0
  29. package/dist/adapters/standard/utils.js +47 -0
  30. package/dist/bracket-notation.d.ts +26 -0
  31. package/dist/bracket-notation.js +185 -0
  32. package/dist/client-factory.d.ts +24 -0
  33. package/dist/client-factory.js +13 -0
  34. package/dist/constants.js +4 -0
  35. package/dist/extensions/route.d.ts +37 -0
  36. package/dist/extensions/route.js +12 -0
  37. package/dist/helpers/form-data.d.ts +57 -0
  38. package/dist/helpers/form-data.js +90 -0
  39. package/dist/helpers/index.d.ts +1 -0
  40. package/dist/helpers/index.js +1 -0
  41. package/dist/index.d.ts +13 -0
  42. package/dist/index.js +11 -0
  43. package/dist/meta.d.ts +325 -0
  44. package/dist/meta.js +84 -0
  45. package/dist/openapi-generator-components.d.ts +31 -0
  46. package/dist/openapi-generator-components.js +275 -0
  47. package/dist/openapi-generator-operation.d.ts +34 -0
  48. package/dist/openapi-generator-operation.js +469 -0
  49. package/dist/openapi-generator.d.ts +92 -0
  50. package/dist/openapi-generator.js +147 -0
  51. package/dist/openapi-json-serializer.d.ts +79 -0
  52. package/dist/openapi-json-serializer.js +260 -0
  53. package/dist/openapi-serializer.d.ts +43 -0
  54. package/dist/openapi-serializer.js +93 -0
  55. package/dist/plugins/index.d.ts +1 -0
  56. package/dist/plugins/index.js +1 -0
  57. package/dist/plugins/openapi-reference.d.ts +115 -0
  58. package/dist/plugins/openapi-reference.js +187 -0
  59. package/dist/router-utils.d.ts +20 -0
  60. package/dist/router-utils.js +36 -0
  61. package/dist/{types.d.mts → types.d.ts} +23 -19
  62. package/dist/utils.d.ts +14 -0
  63. package/dist/utils.js +47 -0
  64. package/package.json +69 -71
  65. package/dist/adapters/aws-lambda/index.d.mts +0 -15
  66. package/dist/adapters/aws-lambda/index.mjs +0 -1
  67. package/dist/adapters/aws-lambda/openapi-handler.d.mts +0 -17
  68. package/dist/adapters/aws-lambda/openapi-handler.mjs +0 -11
  69. package/dist/adapters/fastify/index.d.mts +0 -1
  70. package/dist/adapters/fastify/index.mjs +0 -1
  71. package/dist/adapters/fastify/openapi-handler.d.mts +0 -14
  72. package/dist/adapters/fastify/openapi-handler.mjs +0 -11
  73. package/dist/adapters/fetch/index.d.mts +0 -2
  74. package/dist/adapters/fetch/index.mjs +0 -2
  75. package/dist/adapters/fetch/openapi-handler.d.mts +0 -14
  76. package/dist/adapters/fetch/openapi-handler.mjs +0 -11
  77. package/dist/adapters/fetch/openapi-link.d.mts +0 -15
  78. package/dist/adapters/fetch/openapi-link.mjs +0 -11
  79. package/dist/adapters/node/index.d.mts +0 -1
  80. package/dist/adapters/node/index.mjs +0 -1
  81. package/dist/adapters/node/openapi-handler.d.mts +0 -14
  82. package/dist/adapters/node/openapi-handler.mjs +0 -11
  83. package/dist/adapters/standard/index.d.mts +0 -3
  84. package/dist/adapters/standard/index.mjs +0 -3
  85. package/dist/adapters/standard/openapi-handler-codec.d.mts +0 -61
  86. package/dist/adapters/standard/openapi-handler-codec.mjs +0 -203
  87. package/dist/adapters/standard/openapi-link-codec.d.mts +0 -53
  88. package/dist/adapters/standard/openapi-link-codec.mjs +0 -356
  89. package/dist/adapters/standard/openapi-matcher.d.mts +0 -29
  90. package/dist/adapters/standard/openapi-matcher.mjs +0 -105
  91. package/dist/adapters/standard/utils.d.mts +0 -4
  92. package/dist/adapters/standard/utils.mjs +0 -36
  93. package/dist/bracket-notation.d.mts +0 -26
  94. package/dist/bracket-notation.mjs +0 -156
  95. package/dist/client-factory.d.mts +0 -24
  96. package/dist/client-factory.mjs +0 -5
  97. package/dist/constants.mjs +0 -4
  98. package/dist/extensions/route.d.mts +0 -76
  99. package/dist/extensions/route.mjs +0 -12
  100. package/dist/helpers/form-data.d.mts +0 -57
  101. package/dist/helpers/form-data.mjs +0 -36
  102. package/dist/helpers/index.d.mts +0 -1
  103. package/dist/helpers/index.mjs +0 -1
  104. package/dist/index.d.mts +0 -13
  105. package/dist/index.mjs +0 -11
  106. package/dist/meta.d.mts +0 -345
  107. package/dist/meta.mjs +0 -56
  108. package/dist/openapi-generator-components.d.mts +0 -24
  109. package/dist/openapi-generator-components.mjs +0 -227
  110. package/dist/openapi-generator-operation.d.mts +0 -29
  111. package/dist/openapi-generator-operation.mjs +0 -447
  112. package/dist/openapi-generator.d.mts +0 -87
  113. package/dist/openapi-generator.mjs +0 -115
  114. package/dist/openapi-json-serializer.d.mts +0 -86
  115. package/dist/openapi-json-serializer.mjs +0 -229
  116. package/dist/openapi-serializer.d.mts +0 -43
  117. package/dist/openapi-serializer.mjs +0 -87
  118. package/dist/plugins/index.d.mts +0 -1
  119. package/dist/plugins/index.mjs +0 -1
  120. package/dist/plugins/openapi-reference.d.mts +0 -118
  121. package/dist/plugins/openapi-reference.mjs +0 -157
  122. package/dist/router-utils.d.mts +0 -18
  123. package/dist/router-utils.mjs +0 -29
  124. package/dist/utils.d.mts +0 -14
  125. package/dist/utils.mjs +0 -40
  126. /package/dist/{constants.d.mts → constants.d.ts} +0 -0
  127. /package/dist/{types.mjs → types.js} +0 -0
@@ -1,86 +0,0 @@
1
- import type { Segment } from "@orpc/shared";
2
- export type OpenAPIJsonSerialization = {
3
- json: unknown;
4
- maps?: undefined;
5
- blobs?: undefined;
6
- } | {
7
- json: unknown;
8
- maps: Segment[][];
9
- blobs: Blob[];
10
- };
11
- export interface OpenAPIJsonSerializerHandler {
12
- condition(value: unknown): boolean;
13
- serialize(value: any): unknown;
14
- /**
15
- * If false, the result of this serializer will not be further processed by other serializers,
16
- * even if it matches their conditions and treat it as final serialized value.
17
- * This can be useful for serializers that return primitive values, which should not be further processed.
18
- * to improve performance and avoid potential issues with other serializers.
19
- *
20
- * @default false
21
- */
22
- isTerminal?: boolean | undefined;
23
- }
24
- export interface OpenAPIJsonSerializerOptions {
25
- /**
26
- * Extend or override the built-in type handlers used during serialization.
27
- *
28
- * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
29
- * that defines how to detect and serialize values of that type.
30
- *
31
- * **Extending:** Add new keys to support custom types:
32
- * ```ts
33
- * handlers: {
34
- * buffer: {
35
- * condition: (v) => v instanceof Buffer,
36
- * serialize: (v: Buffer) => v.toString('base64'),
37
- * isTerminal: true,
38
- * }
39
- * }
40
- * ```
41
- *
42
- * **Overriding:** Use an existing key to replace a built-in handler:
43
- * ```ts
44
- * handlers: {
45
- * date: {
46
- * condition: (v) => v instanceof Date,
47
- * serialize: (v: Date) => v.getTime(),
48
- * isTerminal: true,
49
- * }
50
- * }
51
- * ```
52
- *
53
- * **Disabling:** Set a key to `undefined` to remove a built-in handler:
54
- * ```ts
55
- * handlers: { url: undefined }
56
- * ```
57
- *
58
- * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
59
- */
60
- handlers?: Record<string, undefined | OpenAPIJsonSerializerHandler> | undefined;
61
- /**
62
- * If true, properties with undefined values will be omitted during serialization.
63
- *
64
- * @default true
65
- */
66
- omitUndefinedProperties?: boolean | undefined;
67
- }
68
- /**
69
- * The JSON layer behind `OpenAPISerializer`: one-way serialization of types like `Date`, `BigInt`,
70
- * and `Set` into JSON-friendly values, for places that only accept JSON.
71
- *
72
- * @see {@link https://orpc.dev/docs/openapi/serializer#openapi-json-serializer | OpenAPI Serializer - OpenAPI JSON Serializer}
73
- */
74
- export declare class OpenAPIJsonSerializer {
75
- private readonly inlineBuiltInHandlers;
76
- private readonly handlerEntries;
77
- private readonly omitUndefinedProperties;
78
- constructor(options?: OpenAPIJsonSerializerOptions);
79
- serializeJson(data: unknown): OpenAPIJsonSerialization;
80
- /**
81
- * `segments` is a shared mutable stack (push/pop while walking),
82
- * so it must be copied before being stored in `maps`.
83
- */
84
- private serializeValue;
85
- deserializeJson(serialized: OpenAPIJsonSerialization): unknown;
86
- }
@@ -1,229 +0,0 @@
1
- import { copyOnWrite, isPlainObject, NullProtoObj } from "@orpc/shared";
2
- const DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS = {
3
- undefined: {
4
- condition(data) {
5
- return data === undefined;
6
- },
7
- serialize() {
8
- return null;
9
- },
10
- isTerminal: true
11
- },
12
- bigint: {
13
- condition(data) {
14
- return typeof data === "bigint";
15
- },
16
- serialize(data) {
17
- return data.toString();
18
- },
19
- isTerminal: true
20
- },
21
- date: {
22
- condition(data) {
23
- return data instanceof Date;
24
- },
25
- serialize(data) {
26
- if (Number.isNaN(data.getTime())) {
27
- return null;
28
- }
29
- return data.toISOString();
30
- },
31
- isTerminal: true
32
- },
33
- nan: {
34
- condition(data) {
35
- return typeof data === "number" && Number.isNaN(data);
36
- },
37
- serialize() {
38
- return null;
39
- },
40
- isTerminal: true
41
- },
42
- infinity: {
43
- condition(data) {
44
- return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
45
- },
46
- serialize() {
47
- return null;
48
- },
49
- isTerminal: true
50
- },
51
- url: {
52
- condition(data) {
53
- return data instanceof URL;
54
- },
55
- serialize(data) {
56
- return data.toString();
57
- },
58
- isTerminal: true
59
- },
60
- set: {
61
- condition(data) {
62
- return data instanceof Set;
63
- },
64
- serialize(data) {
65
- return Array.from(data);
66
- }
67
- },
68
- map: {
69
- condition(data) {
70
- return data instanceof Map;
71
- },
72
- serialize(data) {
73
- return Array.from(data.entries());
74
- }
75
- }
76
- };
77
-
78
- export class OpenAPIJsonSerializer {
79
- inlineBuiltInHandlers;
80
- handlerEntries;
81
- omitUndefinedProperties;
82
- constructor(options = {}) {
83
- this.omitUndefinedProperties = options.omitUndefinedProperties !== false;
84
- const customHandlers = options.handlers;
85
- if (customHandlers === undefined) {
86
- this.inlineBuiltInHandlers = true;
87
- return;
88
- }
89
- let inlineBuiltInHandlers = true;
90
- let handlerEntries = [];
91
- for (const key of Object.keys(customHandlers)) {
92
- const handler = customHandlers[key];
93
- if (inlineBuiltInHandlers && key in DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS) {
94
- inlineBuiltInHandlers = false;
95
- break;
96
- }
97
- if (handler !== undefined) {
98
- handlerEntries.push(handler);
99
- }
100
- }
101
- if (!inlineBuiltInHandlers) {
102
- handlerEntries = [];
103
- for (const handler of Object.values({
104
- ...DEFAULT_OPEN_API_JSON_SERIALIZER_HANDLERS,
105
- ...customHandlers
106
- })) {
107
- if (handler !== undefined) {
108
- handlerEntries.push(handler);
109
- }
110
- }
111
- }
112
- this.inlineBuiltInHandlers = inlineBuiltInHandlers;
113
- this.handlerEntries = handlerEntries;
114
- }
115
- serializeJson(data) {
116
- const maps = [];
117
- const blobs = [];
118
- const json = this.serializeValue(data, [], maps, blobs);
119
- return {
120
- json,
121
- maps,
122
- blobs
123
- };
124
- }
125
-
126
- serializeValue(data, segments, maps, blobs) {
127
-
128
- if (this.inlineBuiltInHandlers) {
129
- switch (typeof data) {
130
- case "string":
131
- case "boolean": return data;
132
- case "number": return Number.isFinite(data) ? data : null;
133
- case "undefined": return null;
134
- case "bigint": return data.toString();
135
- case "object": {
136
- if (data === null) {
137
- return data;
138
- }
139
- if (data instanceof Date) {
140
- return Number.isNaN(data.getTime()) ? null : data.toISOString();
141
- }
142
- if (data instanceof URL) {
143
- return data.toString();
144
- }
145
- if (data instanceof Set) {
146
- return this.serializeValue(Array.from(data), segments, maps, blobs);
147
- }
148
- if (data instanceof Map) {
149
- return this.serializeValue(Array.from(data.entries()), segments, maps, blobs);
150
- }
151
- }
152
- }
153
- }
154
- const handlerEntries = this.handlerEntries;
155
- if (handlerEntries) {
156
- for (let i = 0; i < handlerEntries.length; i++) {
157
- const handler = handlerEntries[i];
158
- if (handler.condition(data)) {
159
- const serialized = handler.serialize(data);
160
- if (handler.isTerminal) {
161
- if (serialized instanceof Blob) {
162
- maps.push(segments.slice());
163
- blobs.push(serialized);
164
- }
165
- return serialized;
166
- }
167
- return this.serializeValue(serialized, segments, maps, blobs);
168
- }
169
- }
170
- }
171
- if (data instanceof Blob) {
172
- maps.push(segments.slice());
173
- blobs.push(data);
174
- return data;
175
- }
176
- if (Array.isArray(data)) {
177
- const json = [];
178
- for (let i = 0; i < data.length; i++) {
179
- segments.push(i);
180
- json.push(this.serializeValue(data[i], segments, maps, blobs));
181
- segments.pop();
182
- }
183
- return json;
184
- }
185
- if (isPlainObject(data)) {
186
- const json = new NullProtoObj();
187
- for (const k of Object.keys(data)) {
188
- const v = data[k];
189
-
190
- if (k === "toJSON" && typeof v === "function") {
191
- continue;
192
- }
193
- if (v === undefined && this.omitUndefinedProperties) {
194
- continue;
195
- }
196
- segments.push(k);
197
- json[k] = this.serializeValue(v, segments, maps, blobs);
198
- segments.pop();
199
- }
200
- return json;
201
- }
202
- return data;
203
- }
204
- deserializeJson(serialized) {
205
- const ref = { json: serialized.json };
206
- if (serialized.blobs?.length) {
207
- for (let i = 0; i < serialized.maps.length; i++) {
208
- const blob = serialized.blobs[i];
209
- if (!(blob instanceof Blob)) {
210
- throw new TypeError(`Invalid OpenAPI serialized data: blob ${i} is not a Blob.`);
211
- }
212
- const segments = serialized.maps[i];
213
- let original = serialized;
214
- let currentRef = ref;
215
- let preSegment = "json";
216
- for (let j = 0; j < segments.length; j++) {
217
- original = original[preSegment];
218
- currentRef = copyOnWrite(currentRef, preSegment, original);
219
- preSegment = segments[j];
220
- if (!Object.hasOwn(currentRef, preSegment)) {
221
- throw new TypeError(`Invalid OpenAPI serialized data: segment "${preSegment}" does not exist.`);
222
- }
223
- }
224
- currentRef[preSegment] = blob;
225
- }
226
- }
227
- return ref.json;
228
- }
229
- }
@@ -1,43 +0,0 @@
1
- import type { StandardBody } from "@standard-server/core";
2
- import type { BracketNotationSerializerOptions } from "./bracket-notation.mjs";
3
- import type { OpenAPIJsonSerializerOptions } from "./openapi-json-serializer.mjs";
4
- import { OpenAPIJsonSerializer } from "./openapi-json-serializer.mjs";
5
- export interface OpenAPISerializerSerializeOptions {
6
- /**
7
- * Use FormData for serialization when nested blobs are present.
8
- * Does not apply to root-level Blob values.
9
- *
10
- * @default true
11
- */
12
- useFormDataForBlobFields?: boolean | undefined;
13
- /**
14
- * When enabled, the serialized output is always returned as a FormData instance using bracket notation.
15
- *
16
- * @default false
17
- */
18
- asFormData?: boolean | undefined;
19
- }
20
- export interface OpenAPISerializerOptions extends OpenAPIJsonSerializerOptions {
21
- /**
22
- * Options for bracket notation serializer, like maxDeserializingEmptySlots
23
- */
24
- bracketNotation?: BracketNotationSerializerOptions | undefined;
25
- /**
26
- * Default options for serialize method
27
- */
28
- serialize?: OpenAPISerializerSerializeOptions | undefined;
29
- }
30
- /**
31
- * Handles one-way serialization of oRPC payloads into JSON-friendly formats,
32
- * partially supporting complex data types beyond plain JSON such as `Date`, `BigInt`, and `Set`.
33
- *
34
- * @see {@link https://orpc.dev/docs/openapi/serializer | OpenAPI Serializer}
35
- */
36
- export declare class OpenAPISerializer extends OpenAPIJsonSerializer {
37
- private readonly bracketNotation;
38
- private readonly defaultSerializeOptions;
39
- constructor({ bracketNotation, serialize, ...options }?: OpenAPISerializerOptions);
40
- serialize(data: unknown, options?: OpenAPISerializerSerializeOptions): StandardBody;
41
- private serializePayload;
42
- deserialize(data: StandardBody): unknown;
43
- }
@@ -1,87 +0,0 @@
1
- import { createORPCErrorFromJson, isORPCErrorJson, toORPCError, wrapAsyncIteratorPreservingEventMeta } from "@orpc/client";
2
- import { isAsyncIteratorObject } from "@orpc/shared";
3
- import { ErrorEvent } from "@standard-server/core";
4
- import { BracketNotationSerializer } from "./bracket-notation.mjs";
5
- import { OpenAPIJsonSerializer } from "./openapi-json-serializer.mjs";
6
-
7
- export class OpenAPISerializer extends OpenAPIJsonSerializer {
8
- bracketNotation;
9
- defaultSerializeOptions;
10
- constructor({ bracketNotation, serialize, ...options } = {}) {
11
- super(options);
12
- this.bracketNotation = new BracketNotationSerializer(bracketNotation);
13
- this.defaultSerializeOptions = serialize;
14
- }
15
- serialize(data, options = {}) {
16
- if (!options.asFormData) {
17
-
18
- if (data === undefined || data instanceof ReadableStream || data instanceof Blob) {
19
- return data;
20
- }
21
- if (isAsyncIteratorObject(data)) {
22
- return wrapAsyncIteratorPreservingEventMeta(data, {
23
- mapResult: (result) => {
24
-
25
- if (result.value === undefined) {
26
- return result;
27
- }
28
- return {
29
- done: result.done,
30
- value: this.serializePayload(result.value, false, false)
31
- };
32
- },
33
- mapError: (e) => new ErrorEvent(this.serializePayload(toORPCError(e).toJSON(), false, false), { cause: e })
34
- });
35
- }
36
- }
37
- const useFormDataForBlobFields = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
38
- const asFormData = options.asFormData ?? this.defaultSerializeOptions?.asFormData ?? false;
39
- return this.serializePayload(data, useFormDataForBlobFields, asFormData);
40
- }
41
- serializePayload(value, useFormDataForBlobFields, asFormData) {
42
- const { json, blobs } = this.serializeJson(value);
43
- if (!asFormData && (json instanceof Blob || json === undefined || !blobs?.length || !useFormDataForBlobFields)) {
44
- return json;
45
- }
46
- const form = new FormData();
47
- for (const [path, value] of this.bracketNotation.serialize(json)) {
48
- if (value instanceof Blob) {
49
- form.append(path, value);
50
- } else if (value !== undefined && value !== null) {
51
- form.append(path, String(value));
52
- }
53
- }
54
- return form;
55
- }
56
- deserialize(data) {
57
- if (data === undefined || data instanceof ReadableStream || data instanceof Blob) {
58
- return data;
59
- }
60
- if (isAsyncIteratorObject(data)) {
61
- return wrapAsyncIteratorPreservingEventMeta(data, {
62
- mapResult: (result) => {
63
- if (result.value === undefined) {
64
- return result;
65
- }
66
- return {
67
- done: result.done,
68
- value: this.deserializeJson({ json: result.value })
69
- };
70
- },
71
- mapError: (e) => {
72
- if (e instanceof ErrorEvent) {
73
- const deserialized = this.deserializeJson({ json: e.data });
74
- if (isORPCErrorJson(deserialized)) {
75
- return createORPCErrorFromJson(deserialized, { cause: e });
76
- }
77
- }
78
- return e;
79
- }
80
- });
81
- }
82
- if (data instanceof URLSearchParams || data instanceof FormData) {
83
- data = this.bracketNotation.deserialize(Array.from(data.entries()));
84
- }
85
- return this.deserializeJson({ json: data });
86
- }
87
- }
@@ -1 +0,0 @@
1
- export * from "./openapi-reference.mjs";
@@ -1 +0,0 @@
1
- export * from "./openapi-reference.mjs";
@@ -1,118 +0,0 @@
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.mjs";
8
- export type OpenAPIReferenceHandlerPluginProvider = "scalar" | "swagger";
9
- export interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ScalarProviderConfig> {}
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<
28
- T extends Context,
29
- TProvider extends OpenAPIReferenceHandlerPluginProvider
30
- > {
31
- /**
32
- * A static or dynamic OpenAPI document to serve.
33
- * Receives routing interceptor options when provided as a function.
34
- */
35
- spec: Value<Promisable<OpenAPIDocument<OpenAPIVersion>>, [StandardHandlerRoutingInterceptorOptions<T>]>;
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;
91
- }
92
- /**
93
- * Serves API reference documentation powered by Scalar or Swagger UI,
94
- * and exposes the OpenAPI specification as JSON.
95
- *
96
- * @remarks
97
- * **Note**: By default, the API reference UI is served from `/` and the OpenAPI specification from `/spec.json`.
98
- *
99
- * @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
100
- */
101
- export declare class OpenAPIReferenceHandlerPlugin<
102
- T extends Context,
103
- TProvider extends OpenAPIReferenceHandlerPluginProvider
104
- > implements StandardHandlerPlugin<T> {
105
- name: string;
106
- private readonly spec;
107
- private readonly allow;
108
- private readonly specPath;
109
- private readonly provider;
110
- private readonly providerConfig;
111
- private readonly providerScriptUrl;
112
- private readonly providerCssUrl;
113
- private readonly docsPath;
114
- private readonly docsTitle;
115
- private readonly docsHead;
116
- constructor(options: OpenAPIReferenceHandlerPluginOptions<T, TProvider>);
117
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
118
- }