@orpc/openapi 0.0.0-next.da84cda → 0.0.0-next.da8ae32
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/chunk-DRV7KYES.js +420 -0
- package/dist/chunk-HC5PVG4R.js +52 -0
- package/dist/chunk-NHYWV7BW.js +32 -0
- package/dist/fetch.js +5 -30
- package/dist/hono.js +5 -30
- package/dist/index.js +80 -28
- package/dist/next.js +5 -30
- package/dist/node.js +18 -34
- package/dist/src/adapters/fetch/index.d.ts +0 -8
- package/dist/src/adapters/fetch/openapi-handler.d.ts +8 -29
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/openapi-handler.d.ts +8 -8
- package/dist/src/adapters/standard/index.d.ts +6 -0
- package/dist/src/adapters/standard/openapi-codec.d.ts +15 -0
- package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
- package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
- package/dist/src/adapters/standard/openapi-serializer.d.ts +11 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/openapi-generator.d.ts +2 -2
- package/dist/src/openapi-input-structure-parser.d.ts +2 -2
- package/dist/src/openapi-operation-extender.d.ts +7 -0
- package/dist/src/openapi-output-structure-parser.d.ts +2 -2
- package/dist/src/schema-converter.d.ts +2 -2
- package/dist/src/utils.d.ts +1 -16
- package/dist/standard.js +14 -0
- package/package.json +10 -8
- package/dist/chunk-EVWWILO6.js +0 -25
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/chunk-X2HG5K4J.js +0 -651
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/types.d.ts +0 -2
- /package/dist/src/adapters/{fetch → standard}/bracket-notation.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONSerializer,
|
|
3
|
-
forEachAllContractProcedure,
|
|
4
|
-
forEachContractProcedure,
|
|
5
3
|
standardizeHTTPPath
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HC5PVG4R.js";
|
|
5
|
+
|
|
6
|
+
// src/openapi-operation-extender.ts
|
|
7
|
+
import { isProcedure } from "@orpc/server";
|
|
8
|
+
var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
9
|
+
function setOperationExtender(o, extend) {
|
|
10
|
+
return new Proxy(o, {
|
|
11
|
+
get(target, prop, receiver) {
|
|
12
|
+
if (prop === OPERATION_EXTENDER_SYMBOL) {
|
|
13
|
+
return extend;
|
|
14
|
+
}
|
|
15
|
+
return Reflect.get(target, prop, receiver);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function getOperationExtender(o) {
|
|
20
|
+
return o[OPERATION_EXTENDER_SYMBOL];
|
|
21
|
+
}
|
|
22
|
+
function extendOperation(operation, procedure) {
|
|
23
|
+
const operationExtenders = [];
|
|
24
|
+
for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
|
|
25
|
+
const maybeExtender = getOperationExtender(errorItem);
|
|
26
|
+
if (maybeExtender) {
|
|
27
|
+
operationExtenders.push(maybeExtender);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (isProcedure(procedure)) {
|
|
31
|
+
for (const middleware of procedure["~orpc"].middlewares) {
|
|
32
|
+
const maybeExtender = getOperationExtender(middleware);
|
|
33
|
+
if (maybeExtender) {
|
|
34
|
+
operationExtenders.push(maybeExtender);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let currentOperation = operation;
|
|
39
|
+
for (const extender of operationExtenders) {
|
|
40
|
+
if (typeof extender === "function") {
|
|
41
|
+
currentOperation = extender(currentOperation, procedure);
|
|
42
|
+
} else {
|
|
43
|
+
currentOperation = {
|
|
44
|
+
...currentOperation,
|
|
45
|
+
...extender
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return currentOperation;
|
|
50
|
+
}
|
|
7
51
|
|
|
8
52
|
// src/openapi.ts
|
|
9
53
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
@@ -36,7 +80,8 @@ var OpenAPIContentBuilder = class {
|
|
|
36
80
|
};
|
|
37
81
|
|
|
38
82
|
// src/openapi-generator.ts
|
|
39
|
-
import {
|
|
83
|
+
import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus } from "@orpc/contract";
|
|
84
|
+
import { eachAllContractProcedure } from "@orpc/server";
|
|
40
85
|
import { group } from "@orpc/shared";
|
|
41
86
|
|
|
42
87
|
// src/openapi-error.ts
|
|
@@ -44,7 +89,7 @@ var OpenAPIError = class extends Error {
|
|
|
44
89
|
};
|
|
45
90
|
|
|
46
91
|
// src/openapi-input-structure-parser.ts
|
|
47
|
-
import {
|
|
92
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
48
93
|
var OpenAPIInputStructureParser = class {
|
|
49
94
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
50
95
|
this.schemaConverter = schemaConverter;
|
|
@@ -52,8 +97,8 @@ var OpenAPIInputStructureParser = class {
|
|
|
52
97
|
this.pathParser = pathParser;
|
|
53
98
|
}
|
|
54
99
|
parse(contract, structure) {
|
|
55
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
56
|
-
const method =
|
|
100
|
+
const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
|
|
101
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
57
102
|
const httpPath = contract["~orpc"].route?.path;
|
|
58
103
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
59
104
|
return {
|
|
@@ -145,7 +190,7 @@ var OpenAPIOutputStructureParser = class {
|
|
|
145
190
|
this.schemaUtils = schemaUtils;
|
|
146
191
|
}
|
|
147
192
|
parse(contract, structure) {
|
|
148
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
193
|
+
const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
|
|
149
194
|
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
150
195
|
return {
|
|
151
196
|
headersSchema: void 0,
|
|
@@ -184,14 +229,14 @@ var OpenAPIOutputStructureParser = class {
|
|
|
184
229
|
};
|
|
185
230
|
|
|
186
231
|
// src/openapi-parameters-builder.ts
|
|
187
|
-
import { get,
|
|
232
|
+
import { get, isObject, omit } from "@orpc/shared";
|
|
188
233
|
var OpenAPIParametersBuilder = class {
|
|
189
234
|
build(paramIn, jsonSchema, options) {
|
|
190
235
|
const parameters = [];
|
|
191
236
|
for (const name in jsonSchema.properties) {
|
|
192
237
|
const schema = jsonSchema.properties[name];
|
|
193
238
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
194
|
-
return
|
|
239
|
+
return isObject(example) && name in example;
|
|
195
240
|
}).map((example) => {
|
|
196
241
|
return example[name];
|
|
197
242
|
});
|
|
@@ -252,7 +297,7 @@ var CompositeSchemaConverter = class {
|
|
|
252
297
|
};
|
|
253
298
|
|
|
254
299
|
// src/schema-utils.ts
|
|
255
|
-
import {
|
|
300
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
256
301
|
|
|
257
302
|
// src/schema.ts
|
|
258
303
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
@@ -314,7 +359,7 @@ var SchemaUtils = class {
|
|
|
314
359
|
}, {});
|
|
315
360
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
316
361
|
matched.examples = schema.examples?.map((example) => {
|
|
317
|
-
if (!
|
|
362
|
+
if (!isObject2(example)) {
|
|
318
363
|
return example;
|
|
319
364
|
}
|
|
320
365
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -330,7 +375,7 @@ var SchemaUtils = class {
|
|
|
330
375
|
}, {});
|
|
331
376
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
332
377
|
rest.examples = schema.examples?.map((example) => {
|
|
333
|
-
if (!
|
|
378
|
+
if (!isObject2(example)) {
|
|
334
379
|
return example;
|
|
335
380
|
}
|
|
336
381
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -406,16 +451,19 @@ var OpenAPIGenerator = class {
|
|
|
406
451
|
openapi: "3.1.1"
|
|
407
452
|
});
|
|
408
453
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
409
|
-
await
|
|
454
|
+
await eachAllContractProcedure({
|
|
455
|
+
path: [],
|
|
456
|
+
router
|
|
457
|
+
}, ({ contract, path }) => {
|
|
410
458
|
try {
|
|
411
459
|
const def = contract["~orpc"];
|
|
412
460
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
413
461
|
return;
|
|
414
462
|
}
|
|
415
|
-
const method =
|
|
463
|
+
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
|
416
464
|
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
417
|
-
const inputStructure =
|
|
418
|
-
const outputStructure =
|
|
465
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
466
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
419
467
|
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
420
468
|
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
421
469
|
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
@@ -429,14 +477,10 @@ var OpenAPIGenerator = class {
|
|
|
429
477
|
content: this.contentBuilder.build(bodySchema)
|
|
430
478
|
} : void 0;
|
|
431
479
|
const responses = {};
|
|
432
|
-
responses[
|
|
433
|
-
description:
|
|
434
|
-
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema,
|
|
435
|
-
|
|
436
|
-
}) : void 0,
|
|
437
|
-
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
|
|
438
|
-
example: def.outputExample
|
|
439
|
-
}) : void 0
|
|
480
|
+
responses[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
481
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
482
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
483
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
440
484
|
};
|
|
441
485
|
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
442
486
|
...config,
|
|
@@ -508,8 +552,9 @@ var OpenAPIGenerator = class {
|
|
|
508
552
|
requestBody,
|
|
509
553
|
responses
|
|
510
554
|
};
|
|
555
|
+
const extendedOperation = extendOperation(operation, contract);
|
|
511
556
|
builder.addPath(httpPath, {
|
|
512
|
-
[method.toLocaleLowerCase()]:
|
|
557
|
+
[method.toLocaleLowerCase()]: extendedOperation
|
|
513
558
|
});
|
|
514
559
|
} catch (e) {
|
|
515
560
|
if (e instanceof OpenAPIError) {
|
|
@@ -531,6 +576,11 @@ var OpenAPIGenerator = class {
|
|
|
531
576
|
return this.jsonSerializer.serialize(builder.getSpec());
|
|
532
577
|
}
|
|
533
578
|
};
|
|
579
|
+
|
|
580
|
+
// src/index.ts
|
|
581
|
+
var oo = {
|
|
582
|
+
spec: setOperationExtender
|
|
583
|
+
};
|
|
534
584
|
export {
|
|
535
585
|
CompositeSchemaConverter,
|
|
536
586
|
JSONSchema,
|
|
@@ -543,8 +593,10 @@ export {
|
|
|
543
593
|
OpenAPIPathParser,
|
|
544
594
|
OpenApiBuilder,
|
|
545
595
|
SchemaUtils,
|
|
546
|
-
|
|
547
|
-
|
|
596
|
+
extendOperation,
|
|
597
|
+
getOperationExtender,
|
|
598
|
+
oo,
|
|
599
|
+
setOperationExtender,
|
|
548
600
|
standardizeHTTPPath
|
|
549
601
|
};
|
|
550
602
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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-X2HG5K4J.js";
|
|
18
|
-
import "./chunk-KNYXLM77.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-NHYWV7BW.js";
|
|
4
|
+
import "./chunk-DRV7KYES.js";
|
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
|
@@ -1,46 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher
|
|
4
|
+
} from "./chunk-DRV7KYES.js";
|
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
|
5
6
|
|
|
6
7
|
// src/adapters/node/openapi-handler.ts
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
|
|
9
|
+
import { StandardHandler } from "@orpc/server/standard";
|
|
10
|
+
var OpenAPIHandler = class {
|
|
11
|
+
standardHandler;
|
|
12
|
+
constructor(router, options) {
|
|
13
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher(options);
|
|
14
|
+
const codec = options?.codec ?? new OpenAPICodec(options);
|
|
15
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
|
|
12
16
|
}
|
|
13
|
-
async handle(req, res, ...
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
if (result.matched === false) {
|
|
17
|
+
async handle(req, res, ...rest) {
|
|
18
|
+
const standardRequest = nodeHttpToStandardRequest(req, res);
|
|
19
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
20
|
+
if (!result.matched) {
|
|
18
21
|
return { matched: false };
|
|
19
22
|
}
|
|
20
|
-
await
|
|
21
|
-
await sendResponse(res, result.response);
|
|
23
|
+
await nodeHttpResponseSendStandardResponse(res, result.response);
|
|
22
24
|
return { matched: true };
|
|
23
25
|
}
|
|
24
26
|
};
|
|
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
27
|
export {
|
|
42
|
-
|
|
43
|
-
OpenAPIServerHandler,
|
|
44
|
-
OpenAPIServerlessHandler
|
|
28
|
+
OpenAPIHandler
|
|
45
29
|
};
|
|
46
30
|
//# sourceMappingURL=node.js.map
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
export * from './bracket-notation';
|
|
2
|
-
export * from './input-structure-compact';
|
|
3
|
-
export * from './input-structure-detailed';
|
|
4
1
|
export * from './openapi-handler';
|
|
5
|
-
export * from './openapi-handler-server';
|
|
6
|
-
export * from './openapi-handler-serverless';
|
|
7
|
-
export * from './openapi-payload-codec';
|
|
8
|
-
export * from './openapi-procedure-matcher';
|
|
9
|
-
export * from './schema-coercer';
|
|
10
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,32 +1,11 @@
|
|
|
1
|
-
import type { Context, Router
|
|
2
|
-
import type { FetchHandler,
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { type PublicInputStructureDetailed } from './input-structure-detailed';
|
|
7
|
-
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
8
|
-
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
9
|
-
import { type SchemaCoercer } from './schema-coercer';
|
|
10
|
-
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, WithSignal> & {
|
|
11
|
-
jsonSerializer?: PublicJSONSerializer;
|
|
12
|
-
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
|
-
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
14
|
-
inputBuilderSimple?: PublicInputStructureCompact;
|
|
15
|
-
inputBuilderFull?: PublicInputStructureDetailed;
|
|
16
|
-
schemaCoercers?: SchemaCoercer[];
|
|
17
|
-
};
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
|
3
|
+
import type { StandardHandleOptions } from '@orpc/server/standard';
|
|
4
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
5
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
18
6
|
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
|
19
|
-
private readonly
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private readonly inputStructureCompact;
|
|
23
|
-
private readonly inputStructureDetailed;
|
|
24
|
-
private readonly compositeSchemaCoercer;
|
|
25
|
-
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
|
|
26
|
-
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
|
27
|
-
private decodeInput;
|
|
28
|
-
private encodeOutput;
|
|
29
|
-
private assertDetailedOutput;
|
|
30
|
-
private convertToORPCError;
|
|
7
|
+
private readonly standardHandler;
|
|
8
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
|
31
10
|
}
|
|
32
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
export declare class OpenAPIHandler<T extends Context> implements
|
|
7
|
-
private readonly
|
|
8
|
-
constructor(
|
|
9
|
-
handle(req:
|
|
2
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
|
|
3
|
+
import type { StandardHandleOptions } from '@orpc/server/standard';
|
|
4
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
5
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
6
|
+
export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
7
|
+
private readonly standardHandler;
|
|
8
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyProcedure } from '@orpc/server';
|
|
2
|
+
import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from '@orpc/server/standard';
|
|
3
|
+
import { type ORPCError } from '@orpc/contract';
|
|
4
|
+
import { OpenAPISerializer } from './openapi-serializer';
|
|
5
|
+
export interface OpenAPICodecOptions {
|
|
6
|
+
serializer?: OpenAPISerializer;
|
|
7
|
+
}
|
|
8
|
+
export declare class OpenAPICodec implements StandardCodec {
|
|
9
|
+
private readonly serializer;
|
|
10
|
+
constructor(options?: OpenAPICodecOptions);
|
|
11
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
12
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
13
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=openapi-codec.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context } from '@orpc/server';
|
|
2
|
+
import type { RPCHandlerOptions } from '@orpc/server/standard';
|
|
3
|
+
import type { OpenAPICodecOptions } from './openapi-codec';
|
|
4
|
+
import type { OpenAPIMatcherOptions } from './openapi-matcher';
|
|
5
|
+
export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T>, OpenAPIMatcherOptions, OpenAPICodecOptions {
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnyRouter } from '@orpc/server';
|
|
2
|
+
import type { StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
3
|
+
import { type HTTPPath } from '@orpc/contract';
|
|
4
|
+
export interface OpenAPIMatcherOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Ignore procedure that does not have a method defined in the contract.
|
|
7
|
+
*
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
ignoreUndefinedMethod?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class OpenAPIMatcher implements StandardMatcher {
|
|
13
|
+
private readonly tree;
|
|
14
|
+
private readonly ignoreUndefinedMethod;
|
|
15
|
+
constructor(options?: OpenAPIMatcherOptions);
|
|
16
|
+
private pendingRouters;
|
|
17
|
+
init(router: AnyRouter, path?: string[]): void;
|
|
18
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=openapi-matcher.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PublicJSONSerializer } from '../../json-serializer';
|
|
2
|
+
export interface OpenAPISerializerOptions {
|
|
3
|
+
jsonSerializer?: PublicJSONSerializer;
|
|
4
|
+
}
|
|
5
|
+
export declare class OpenAPISerializer {
|
|
6
|
+
private readonly jsonSerializer;
|
|
7
|
+
constructor(options?: OpenAPISerializerOptions);
|
|
8
|
+
serialize(data: unknown): unknown;
|
|
9
|
+
deserialize(serialized: unknown): unknown;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=openapi-serializer.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
|
+
import { setOperationExtender } from './openapi-operation-extender';
|
|
2
3
|
export * from './json-serializer';
|
|
3
4
|
export * from './openapi';
|
|
4
5
|
export * from './openapi-content-builder';
|
|
5
6
|
export * from './openapi-generator';
|
|
7
|
+
export * from './openapi-operation-extender';
|
|
6
8
|
export * from './openapi-parameters-builder';
|
|
7
9
|
export * from './openapi-path-parser';
|
|
8
10
|
export * from './schema';
|
|
9
11
|
export * from './schema-converter';
|
|
10
12
|
export * from './schema-utils';
|
|
11
13
|
export * from './utils';
|
|
14
|
+
export declare const oo: {
|
|
15
|
+
spec: typeof setOperationExtender;
|
|
16
|
+
};
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ANY_ROUTER } from '@orpc/server';
|
|
2
1
|
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
3
2
|
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
4
3
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
5
4
|
import type { SchemaConverter } from './schema-converter';
|
|
6
5
|
import { type ContractRouter } from '@orpc/contract';
|
|
6
|
+
import { type AnyRouter } from '@orpc/server';
|
|
7
7
|
import { type PublicJSONSerializer } from './json-serializer';
|
|
8
8
|
import { type OpenAPI } from './openapi';
|
|
9
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
@@ -61,7 +61,7 @@ export declare class OpenAPIGenerator {
|
|
|
61
61
|
private readonly considerMissingTagDefinitionAsError;
|
|
62
62
|
private readonly strictErrorResponses;
|
|
63
63
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
64
|
-
generate(router: ContractRouter |
|
|
64
|
+
generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
65
65
|
}
|
|
66
66
|
export {};
|
|
67
67
|
//# sourceMappingURL=openapi-generator.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { AnyContractProcedure } from '@orpc/contract';
|
|
1
2
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
2
3
|
import type { JSONSchema, ObjectSchema } from './schema';
|
|
3
4
|
import type { SchemaConverter } from './schema-converter';
|
|
4
5
|
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;
|
|
@@ -14,7 +14,7 @@ export declare class OpenAPIInputStructureParser {
|
|
|
14
14
|
private readonly schemaUtils;
|
|
15
15
|
private readonly pathParser;
|
|
16
16
|
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
|
|
17
|
-
parse(contract:
|
|
17
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
|
|
18
18
|
private parseDetailedSchema;
|
|
19
19
|
private parseCompactSchema;
|
|
20
20
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyContractProcedure } from '@orpc/contract';
|
|
2
|
+
import type { OpenAPI } from './openapi';
|
|
3
|
+
export type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
4
|
+
export declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
5
|
+
export declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
|
|
6
|
+
export declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
|
|
7
|
+
//# sourceMappingURL=openapi-operation-extender.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyContractProcedure } from '@orpc/contract';
|
|
2
2
|
import type { JSONSchema, ObjectSchema } from './schema';
|
|
3
3
|
import type { SchemaConverter } from './schema-converter';
|
|
4
4
|
import type { PublicSchemaUtils } from './schema-utils';
|
|
@@ -10,7 +10,7 @@ export declare class OpenAPIOutputStructureParser {
|
|
|
10
10
|
private readonly schemaConverter;
|
|
11
11
|
private readonly schemaUtils;
|
|
12
12
|
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
|
|
13
|
-
parse(contract:
|
|
13
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
|
|
14
14
|
private parseDetailedSchema;
|
|
15
15
|
private parseCompactSchema;
|
|
16
16
|
}
|
|
@@ -4,8 +4,8 @@ export interface SchemaConvertOptions {
|
|
|
4
4
|
strategy: 'input' | 'output';
|
|
5
5
|
}
|
|
6
6
|
export interface SchemaConverter {
|
|
7
|
-
condition
|
|
8
|
-
convert
|
|
7
|
+
condition(schema: Schema, options: SchemaConvertOptions): boolean;
|
|
8
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
|
9
9
|
}
|
|
10
10
|
export declare class CompositeSchemaConverter implements SchemaConverter {
|
|
11
11
|
private readonly converters;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ANY_PROCEDURE, ANY_ROUTER, Lazy } from '@orpc/server';
|
|
3
|
-
export interface EachLeafOptions {
|
|
4
|
-
router: ContractRouter | ANY_ROUTER;
|
|
5
|
-
path: string[];
|
|
6
|
-
}
|
|
7
|
-
export interface EachLeafCallbackOptions {
|
|
8
|
-
contract: WELL_CONTRACT_PROCEDURE;
|
|
9
|
-
path: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface EachContractLeafResultItem {
|
|
12
|
-
router: Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER> | ANY_PROCEDURE>;
|
|
13
|
-
path: string[];
|
|
14
|
-
}
|
|
15
|
-
export declare function forEachContractProcedure(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
|
|
16
|
-
export declare function forEachAllContractProcedure(router: ContractRouter | ANY_ROUTER, callback: (options: EachLeafCallbackOptions) => void): Promise<void>;
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
|
17
2
|
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
18
3
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/standard.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher,
|
|
4
|
+
OpenAPISerializer,
|
|
5
|
+
bracket_notation_exports
|
|
6
|
+
} from "./chunk-DRV7KYES.js";
|
|
7
|
+
import "./chunk-HC5PVG4R.js";
|
|
8
|
+
export {
|
|
9
|
+
bracket_notation_exports as BracketNotation,
|
|
10
|
+
OpenAPICodec,
|
|
11
|
+
OpenAPIMatcher,
|
|
12
|
+
OpenAPISerializer
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=standard.js.map
|
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.
|
|
4
|
+
"version": "0.0.0-next.da8ae32",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./standard": {
|
|
23
|
+
"types": "./dist/src/adapters/standard/index.d.ts",
|
|
24
|
+
"import": "./dist/standard.js",
|
|
25
|
+
"default": "./dist/standard.js"
|
|
26
|
+
},
|
|
22
27
|
"./fetch": {
|
|
23
28
|
"types": "./dist/src/adapters/fetch/index.d.ts",
|
|
24
29
|
"import": "./dist/fetch.js",
|
|
@@ -49,18 +54,15 @@
|
|
|
49
54
|
"dist"
|
|
50
55
|
],
|
|
51
56
|
"dependencies": {
|
|
52
|
-
"@standard-schema/spec": "1.0.0-beta.4",
|
|
53
|
-
"@types/content-disposition": "^0.5.8",
|
|
54
|
-
"content-disposition": "^0.5.4",
|
|
55
57
|
"escape-string-regexp": "^5.0.0",
|
|
56
58
|
"fast-content-type-parse": "^2.0.0",
|
|
57
|
-
"hono": "^4.6.12",
|
|
58
59
|
"json-schema-typed": "^8.0.1",
|
|
59
60
|
"openapi3-ts": "^4.4.0",
|
|
61
|
+
"rou3": "^0.5.1",
|
|
60
62
|
"wildcard-match": "^5.1.3",
|
|
61
|
-
"@orpc/contract": "0.0.0-next.
|
|
62
|
-
"@orpc/
|
|
63
|
-
"@orpc/
|
|
63
|
+
"@orpc/contract": "0.0.0-next.da8ae32",
|
|
64
|
+
"@orpc/server": "0.0.0-next.da8ae32",
|
|
65
|
+
"@orpc/shared": "0.0.0-next.da8ae32"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
68
|
"@readme/openapi-parser": "^2.6.0",
|