@orpc/openapi 0.0.0-next.00a3135 → 0.0.0-next.0361c32
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-HC5PVG4R.js +52 -0
- package/dist/chunk-ICLAXOVR.js +32 -0
- package/dist/chunk-PWOV66X6.js +421 -0
- package/dist/fetch.js +5 -42
- package/dist/hono.js +9 -0
- package/dist/index.js +82 -32
- package/dist/next.js +9 -0
- package/dist/node.js +20 -36
- package/dist/src/adapters/fetch/index.d.ts +0 -8
- package/dist/src/adapters/fetch/openapi-handler.d.ts +8 -31
- package/dist/src/adapters/hono/index.d.ts +2 -0
- package/dist/src/adapters/next/index.d.ts +2 -0
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/openapi-handler.d.ts +7 -9
- 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/openapi-generator.d.ts +9 -2
- package/dist/src/openapi-input-structure-parser.d.ts +2 -2
- package/dist/src/openapi-output-structure-parser.d.ts +2 -2
- package/dist/src/schema-converter.d.ts +2 -2
- package/dist/src/schema.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -16
- package/dist/standard.js +14 -0
- package/package.json +21 -10
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/chunk-WNX6GP4X.js +0 -652
- 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,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONSerializer,
|
|
3
|
-
forEachAllContractProcedure,
|
|
4
|
-
forEachContractProcedure,
|
|
5
3
|
standardizeHTTPPath
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HC5PVG4R.js";
|
|
7
5
|
|
|
8
6
|
// src/openapi.ts
|
|
9
7
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
@@ -36,14 +34,16 @@ var OpenAPIContentBuilder = class {
|
|
|
36
34
|
};
|
|
37
35
|
|
|
38
36
|
// src/openapi-generator.ts
|
|
39
|
-
import {
|
|
37
|
+
import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus } from "@orpc/contract";
|
|
38
|
+
import { eachAllContractProcedure } from "@orpc/server";
|
|
39
|
+
import { group } from "@orpc/shared";
|
|
40
40
|
|
|
41
41
|
// src/openapi-error.ts
|
|
42
42
|
var OpenAPIError = class extends Error {
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
// src/openapi-input-structure-parser.ts
|
|
46
|
-
import {
|
|
46
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
47
47
|
var OpenAPIInputStructureParser = class {
|
|
48
48
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
49
49
|
this.schemaConverter = schemaConverter;
|
|
@@ -51,8 +51,8 @@ var OpenAPIInputStructureParser = class {
|
|
|
51
51
|
this.pathParser = pathParser;
|
|
52
52
|
}
|
|
53
53
|
parse(contract, structure) {
|
|
54
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
55
|
-
const method =
|
|
54
|
+
const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
|
|
55
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
56
56
|
const httpPath = contract["~orpc"].route?.path;
|
|
57
57
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
58
58
|
return {
|
|
@@ -144,7 +144,7 @@ var OpenAPIOutputStructureParser = class {
|
|
|
144
144
|
this.schemaUtils = schemaUtils;
|
|
145
145
|
}
|
|
146
146
|
parse(contract, structure) {
|
|
147
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
147
|
+
const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
|
|
148
148
|
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
149
149
|
return {
|
|
150
150
|
headersSchema: void 0,
|
|
@@ -183,14 +183,14 @@ var OpenAPIOutputStructureParser = class {
|
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
// src/openapi-parameters-builder.ts
|
|
186
|
-
import { get,
|
|
186
|
+
import { get, isObject, omit } from "@orpc/shared";
|
|
187
187
|
var OpenAPIParametersBuilder = class {
|
|
188
188
|
build(paramIn, jsonSchema, options) {
|
|
189
189
|
const parameters = [];
|
|
190
190
|
for (const name in jsonSchema.properties) {
|
|
191
191
|
const schema = jsonSchema.properties[name];
|
|
192
192
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
193
|
-
return
|
|
193
|
+
return isObject(example) && name in example;
|
|
194
194
|
}).map((example) => {
|
|
195
195
|
return example[name];
|
|
196
196
|
});
|
|
@@ -251,7 +251,7 @@ var CompositeSchemaConverter = class {
|
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
// src/schema-utils.ts
|
|
254
|
-
import {
|
|
254
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
255
255
|
|
|
256
256
|
// src/schema.ts
|
|
257
257
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
@@ -293,14 +293,14 @@ var SchemaUtils = class {
|
|
|
293
293
|
return typeof schema === "object" && schema.type === "object";
|
|
294
294
|
}
|
|
295
295
|
isAnySchema(schema) {
|
|
296
|
-
return schema === true || Object.keys(schema).length === 0;
|
|
296
|
+
return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
297
297
|
}
|
|
298
298
|
isUndefinableSchema(schema) {
|
|
299
299
|
const [matches] = this.filterSchemaBranches(schema, (schema2) => {
|
|
300
300
|
if (typeof schema2 === "boolean") {
|
|
301
301
|
return schema2;
|
|
302
302
|
}
|
|
303
|
-
return Object.keys(schema2).length === 0;
|
|
303
|
+
return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
304
304
|
});
|
|
305
305
|
return matches.length > 0;
|
|
306
306
|
}
|
|
@@ -313,7 +313,7 @@ var SchemaUtils = class {
|
|
|
313
313
|
}, {});
|
|
314
314
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
315
315
|
matched.examples = schema.examples?.map((example) => {
|
|
316
|
-
if (!
|
|
316
|
+
if (!isObject2(example)) {
|
|
317
317
|
return example;
|
|
318
318
|
}
|
|
319
319
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -329,7 +329,7 @@ var SchemaUtils = class {
|
|
|
329
329
|
}, {});
|
|
330
330
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
331
331
|
rest.examples = schema.examples?.map((example) => {
|
|
332
|
-
if (!
|
|
332
|
+
if (!isObject2(example)) {
|
|
333
333
|
return example;
|
|
334
334
|
}
|
|
335
335
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -384,6 +384,7 @@ var OpenAPIGenerator = class {
|
|
|
384
384
|
errorHandlerStrategy;
|
|
385
385
|
ignoreUndefinedPathProcedures;
|
|
386
386
|
considerMissingTagDefinitionAsError;
|
|
387
|
+
strictErrorResponses;
|
|
387
388
|
constructor(options) {
|
|
388
389
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
389
390
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
@@ -396,6 +397,7 @@ var OpenAPIGenerator = class {
|
|
|
396
397
|
this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
|
|
397
398
|
this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
398
399
|
this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
|
|
400
|
+
this.strictErrorResponses = options?.strictErrorResponses ?? true;
|
|
399
401
|
}
|
|
400
402
|
async generate(router, doc) {
|
|
401
403
|
const builder = new OpenApiBuilder({
|
|
@@ -403,16 +405,19 @@ var OpenAPIGenerator = class {
|
|
|
403
405
|
openapi: "3.1.1"
|
|
404
406
|
});
|
|
405
407
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
406
|
-
await
|
|
408
|
+
await eachAllContractProcedure({
|
|
409
|
+
path: [],
|
|
410
|
+
router
|
|
411
|
+
}, ({ contract, path }) => {
|
|
407
412
|
try {
|
|
408
413
|
const def = contract["~orpc"];
|
|
409
414
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
410
415
|
return;
|
|
411
416
|
}
|
|
412
|
-
const method =
|
|
417
|
+
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
|
413
418
|
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
414
|
-
const inputStructure =
|
|
415
|
-
const outputStructure =
|
|
419
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
420
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
416
421
|
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
417
422
|
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
418
423
|
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
@@ -425,15 +430,64 @@ var OpenAPIGenerator = class {
|
|
|
425
430
|
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
426
431
|
content: this.contentBuilder.build(bodySchema)
|
|
427
432
|
} : void 0;
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
|
|
434
|
-
example: def.outputExample
|
|
435
|
-
}) : void 0
|
|
433
|
+
const responses = {};
|
|
434
|
+
responses[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
435
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
436
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
437
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
436
438
|
};
|
|
439
|
+
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
440
|
+
...config,
|
|
441
|
+
code,
|
|
442
|
+
status: fallbackORPCErrorStatus(code, config?.status)
|
|
443
|
+
})), (error) => error.status);
|
|
444
|
+
for (const status in errors) {
|
|
445
|
+
const configs = errors[status];
|
|
446
|
+
if (!configs || configs.length === 0) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const schemas = configs.map(({ data, code, message }) => {
|
|
450
|
+
const json = {
|
|
451
|
+
type: "object",
|
|
452
|
+
properties: {
|
|
453
|
+
defined: { const: true },
|
|
454
|
+
code: { const: code },
|
|
455
|
+
status: { const: Number(status) },
|
|
456
|
+
message: { type: "string", default: message },
|
|
457
|
+
data: {}
|
|
458
|
+
},
|
|
459
|
+
required: ["defined", "code", "status", "message"]
|
|
460
|
+
};
|
|
461
|
+
if (data) {
|
|
462
|
+
const dataJson = this.schemaConverter.convert(data, { strategy: "output" });
|
|
463
|
+
json.properties.data = dataJson;
|
|
464
|
+
if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
|
|
465
|
+
json.required.push("data");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return json;
|
|
469
|
+
});
|
|
470
|
+
if (this.strictErrorResponses) {
|
|
471
|
+
schemas.push({
|
|
472
|
+
type: "object",
|
|
473
|
+
properties: {
|
|
474
|
+
defined: { const: false },
|
|
475
|
+
code: { type: "string" },
|
|
476
|
+
status: { type: "number" },
|
|
477
|
+
message: { type: "string" },
|
|
478
|
+
data: {}
|
|
479
|
+
},
|
|
480
|
+
required: ["defined", "code", "status", "message"]
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
const contentSchema = schemas.length === 1 ? schemas[0] : {
|
|
484
|
+
oneOf: schemas
|
|
485
|
+
};
|
|
486
|
+
responses[status] = {
|
|
487
|
+
description: status,
|
|
488
|
+
content: this.contentBuilder.build(contentSchema)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
437
491
|
if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
|
|
438
492
|
const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
439
493
|
if (missingTag !== void 0) {
|
|
@@ -450,9 +504,7 @@ var OpenAPIGenerator = class {
|
|
|
450
504
|
operationId: path.join("."),
|
|
451
505
|
parameters: parameters.length ? parameters : void 0,
|
|
452
506
|
requestBody,
|
|
453
|
-
responses
|
|
454
|
-
[fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
|
|
455
|
-
}
|
|
507
|
+
responses
|
|
456
508
|
};
|
|
457
509
|
builder.addPath(httpPath, {
|
|
458
510
|
[method.toLocaleLowerCase()]: operation
|
|
@@ -489,8 +541,6 @@ export {
|
|
|
489
541
|
OpenAPIPathParser,
|
|
490
542
|
OpenApiBuilder,
|
|
491
543
|
SchemaUtils,
|
|
492
|
-
forEachAllContractProcedure,
|
|
493
|
-
forEachContractProcedure,
|
|
494
544
|
standardizeHTTPPath
|
|
495
545
|
};
|
|
496
546
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
ADDED
package/dist/node.js
CHANGED
|
@@ -1,46 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher
|
|
4
|
+
} from "./chunk-PWOV66X6.js";
|
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
|
5
6
|
|
|
6
7
|
// src/adapters/node/openapi-handler.ts
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
constructor(hono, router, options) {
|
|
12
|
-
this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
|
|
13
|
-
}
|
|
14
|
-
condition(request) {
|
|
15
|
-
return request.headers[ORPC_HANDLER_HEADER] === void 0;
|
|
16
|
-
}
|
|
17
|
-
async handle(req, res, ...[options]) {
|
|
18
|
-
const request = createRequest(req, res, options);
|
|
19
|
-
const castedOptions = options ?? {};
|
|
20
|
-
const response = await this.openapiFetchHandler.fetch(request, castedOptions);
|
|
21
|
-
await options?.beforeSend?.(response, castedOptions.context);
|
|
22
|
-
return await sendResponse(res, response);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/adapters/node/openapi-handler-server.ts
|
|
27
|
-
import { TrieRouter } from "hono/router/trie-router";
|
|
28
|
-
var OpenAPIServerHandler = class extends OpenAPIHandler2 {
|
|
8
|
+
import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
|
|
9
|
+
import { StandardHandler } from "@orpc/server/standard";
|
|
10
|
+
var OpenAPIHandler = class {
|
|
11
|
+
standardHandler;
|
|
29
12
|
constructor(router, options) {
|
|
30
|
-
|
|
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 });
|
|
31
16
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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) {
|
|
21
|
+
return { matched: false };
|
|
22
|
+
}
|
|
23
|
+
await nodeHttpResponseSendStandardResponse(res, result.response);
|
|
24
|
+
return { matched: true };
|
|
39
25
|
}
|
|
40
26
|
};
|
|
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,33 +1,10 @@
|
|
|
1
|
-
import type { Context, Router
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { type SchemaCoercer } from './schema-coercer';
|
|
10
|
-
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
|
|
11
|
-
jsonSerializer?: PublicJSONSerializer;
|
|
12
|
-
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
|
-
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
14
|
-
inputBuilderSimple?: PublicInputStructureCompact;
|
|
15
|
-
inputBuilderFull?: PublicInputStructureDetailed;
|
|
16
|
-
schemaCoercers?: SchemaCoercer[];
|
|
17
|
-
};
|
|
18
|
-
export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<T> {
|
|
19
|
-
private readonly options?;
|
|
20
|
-
private readonly procedureMatcher;
|
|
21
|
-
private readonly payloadCodec;
|
|
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
|
-
condition(request: Request): boolean;
|
|
27
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
|
28
|
-
private decodeInput;
|
|
29
|
-
private encodeOutput;
|
|
30
|
-
private assertDetailedOutput;
|
|
31
|
-
private convertToORPCError;
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
|
3
|
+
import type { StandardHandleRest } from '@orpc/server/standard';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
5
|
+
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
|
6
|
+
private readonly standardHandler;
|
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
8
|
+
handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
|
|
32
9
|
}
|
|
33
10
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { OpenAPIHandlerOptions } from '../
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
condition(request: IncomingMessage): boolean;
|
|
10
|
-
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
|
2
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
|
|
3
|
+
import type { StandardHandleRest } from '@orpc/server/standard';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
5
|
+
export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
6
|
+
private readonly standardHandler;
|
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
8
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
|
|
11
9
|
}
|
|
12
10
|
//# 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
|
|
@@ -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';
|
|
@@ -40,6 +40,12 @@ export interface OpenAPIGeneratorOptions {
|
|
|
40
40
|
* @default 'throw'
|
|
41
41
|
*/
|
|
42
42
|
errorHandlerStrategy?: ErrorHandlerStrategy;
|
|
43
|
+
/**
|
|
44
|
+
* Strict error response
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
strictErrorResponses?: boolean;
|
|
43
49
|
}
|
|
44
50
|
export declare class OpenAPIGenerator {
|
|
45
51
|
private readonly contentBuilder;
|
|
@@ -53,8 +59,9 @@ export declare class OpenAPIGenerator {
|
|
|
53
59
|
private readonly errorHandlerStrategy;
|
|
54
60
|
private readonly ignoreUndefinedPathProcedures;
|
|
55
61
|
private readonly considerMissingTagDefinitionAsError;
|
|
62
|
+
private readonly strictErrorResponses;
|
|
56
63
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
57
|
-
generate(router: ContractRouter |
|
|
64
|
+
generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
58
65
|
}
|
|
59
66
|
export {};
|
|
60
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
|
}
|
|
@@ -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/schema.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export type FileSchema = JSONSchema.JSONSchema & {
|
|
|
8
8
|
type: 'string';
|
|
9
9
|
contentMediaType: string;
|
|
10
10
|
} & object;
|
|
11
|
-
export declare const NON_LOGIC_KEYWORDS:
|
|
11
|
+
export declare const NON_LOGIC_KEYWORDS: string[];
|
|
12
12
|
//# sourceMappingURL=schema.d.ts.map
|
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-PWOV66X6.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
|