@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.
- package/README.md +137 -102
- package/dist/adapters/aws-lambda/index.d.ts +3 -0
- package/dist/adapters/aws-lambda/index.js +1 -0
- package/dist/adapters/aws-lambda/openapi-handler.d.ts +17 -0
- package/dist/adapters/aws-lambda/openapi-handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +2 -0
- package/dist/adapters/fastify/index.js +1 -0
- package/dist/adapters/fastify/openapi-handler.d.ts +14 -0
- package/dist/adapters/fastify/openapi-handler.js +17 -0
- package/dist/adapters/fetch/index.d.ts +3 -27
- package/dist/adapters/fetch/index.js +2 -0
- package/dist/adapters/fetch/openapi-handler.d.ts +14 -0
- package/dist/adapters/fetch/openapi-handler.js +17 -0
- package/dist/adapters/fetch/openapi-link.d.ts +20 -0
- package/dist/adapters/fetch/openapi-link.js +22 -0
- package/dist/adapters/node/index.d.ts +2 -18
- package/dist/adapters/node/index.js +1 -0
- package/dist/adapters/node/openapi-handler.d.ts +14 -0
- package/dist/adapters/node/openapi-handler.js +17 -0
- package/dist/adapters/standard/index.d.ts +4 -50
- package/dist/adapters/standard/index.js +3 -0
- package/dist/adapters/standard/openapi-handler-codec.d.ts +61 -0
- package/dist/adapters/standard/openapi-handler-codec.js +158 -0
- package/dist/adapters/standard/openapi-link-codec.d.ts +58 -0
- package/dist/adapters/standard/openapi-link-codec.js +290 -0
- package/dist/adapters/standard/openapi-matcher.d.ts +29 -0
- package/dist/adapters/standard/openapi-matcher.js +78 -0
- package/dist/adapters/standard/utils.js +31 -0
- package/dist/bracket-notation.d.ts +26 -0
- package/dist/bracket-notation.js +135 -0
- package/dist/client-factory.d.ts +24 -0
- package/dist/client-factory.js +15 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +5 -0
- package/dist/extensions/route.d.ts +36 -42
- package/dist/extensions/route.js +13 -0
- package/dist/helpers/{index.d.mts → form-data.d.ts} +11 -5
- package/dist/helpers/form-data.js +78 -0
- package/dist/helpers/index.d.ts +2 -51
- package/dist/helpers/index.js +1 -0
- package/dist/index.d.ts +15 -120
- package/dist/index.js +11 -0
- package/dist/meta.d.ts +325 -0
- package/dist/meta.js +66 -0
- package/dist/openapi-generator-components.d.ts +2 -0
- package/dist/openapi-generator-components.js +227 -0
- package/dist/openapi-generator-operation.d.ts +13 -0
- package/dist/openapi-generator-operation.js +401 -0
- package/dist/openapi-generator.d.ts +87 -0
- package/dist/openapi-generator.js +119 -0
- package/dist/openapi-json-serializer.d.ts +79 -0
- package/dist/openapi-json-serializer.js +221 -0
- package/dist/openapi-serializer.d.ts +42 -0
- package/dist/openapi-serializer.js +69 -0
- package/dist/plugins/index.d.ts +2 -90
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/openapi-reference.d.ts +112 -0
- package/dist/plugins/openapi-reference.js +164 -0
- package/dist/router-utils.d.ts +17 -0
- package/dist/router-utils.js +32 -0
- package/dist/types.d.ts +27 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +44 -0
- package/package.json +87 -49
- package/dist/adapters/fetch/index.d.mts +0 -27
- package/dist/adapters/fetch/index.mjs +0 -34
- package/dist/adapters/node/index.d.mts +0 -18
- package/dist/adapters/node/index.mjs +0 -21
- package/dist/adapters/standard/index.d.mts +0 -50
- package/dist/adapters/standard/index.mjs +0 -12
- package/dist/extensions/route.d.mts +0 -43
- package/dist/extensions/route.mjs +0 -14
- package/dist/helpers/index.mjs +0 -39
- package/dist/index.d.mts +0 -120
- package/dist/index.mjs +0 -930
- package/dist/plugins/index.d.mts +0 -90
- package/dist/plugins/index.mjs +0 -162
- package/dist/shared/openapi.7vgmPxca.d.ts +0 -82
- package/dist/shared/openapi.B2SK0ZAr.mjs +0 -359
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.BQzzr4-4.d.ts +0 -299
- package/dist/shared/openapi.BcEtAxQj.d.mts +0 -299
- package/dist/shared/openapi.Bt87OzTt.mjs +0 -131
- package/dist/shared/openapi.C7m7NAmH.d.mts +0 -142
- package/dist/shared/openapi.C7m7NAmH.d.ts +0 -142
- package/dist/shared/openapi.CTlpLuKN.mjs +0 -318
- package/dist/shared/openapi.CX6Ri5dP.d.mts +0 -82
- package/dist/shared/openapi.CYgMBSUF.d.mts +0 -18
- package/dist/shared/openapi.CYgMBSUF.d.ts +0 -18
- package/dist/shared/openapi.DmAa7YPO.mjs +0 -275
|
@@ -1,43 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Context } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
18
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
19
|
-
}
|
|
20
|
-
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
21
|
-
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
declare module '@orpc/server' {
|
|
25
|
-
interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
|
|
26
|
-
route(meta: OpenAPIMeta): Builder<TInitialContext, TErrorMap>;
|
|
27
|
-
}
|
|
28
|
-
interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
|
|
29
|
-
route(meta: OpenAPIMeta): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
|
|
30
|
-
}
|
|
31
|
-
interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
32
|
-
route(meta: OpenAPIMeta): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
|
|
33
|
-
}
|
|
34
|
-
interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
35
|
-
route(meta: OpenAPIMeta): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
|
|
36
|
-
}
|
|
37
|
-
interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
38
|
-
route(meta: OpenAPIMeta): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
39
|
-
}
|
|
40
|
-
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
41
|
-
route(meta: OpenAPIMeta): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
42
|
-
}
|
|
1
|
+
import { OpenAPIMeta } from "../meta.js";
|
|
2
|
+
import { AnySchema, ErrorMap } from "@orpc/contract";
|
|
3
|
+
import { Context } from "@orpc/server";
|
|
4
|
+
declare module "@orpc/contract" {
|
|
5
|
+
interface ContractBuilder<TErrorMap extends ErrorMap> {
|
|
6
|
+
route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
|
|
7
|
+
}
|
|
8
|
+
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
9
|
+
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
10
|
+
}
|
|
11
|
+
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
12
|
+
route(meta: OpenAPIMeta): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
13
|
+
}
|
|
14
|
+
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
15
|
+
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
16
|
+
}
|
|
43
17
|
}
|
|
18
|
+
declare module "@orpc/server" {
|
|
19
|
+
interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
|
|
20
|
+
route(meta: OpenAPIMeta): Builder<TInitialContext, TErrorMap>;
|
|
21
|
+
}
|
|
22
|
+
interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
|
|
23
|
+
route(meta: OpenAPIMeta): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
|
|
24
|
+
}
|
|
25
|
+
interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
26
|
+
route(meta: OpenAPIMeta): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
|
|
27
|
+
}
|
|
28
|
+
interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
29
|
+
route(meta: OpenAPIMeta): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
|
|
30
|
+
}
|
|
31
|
+
interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
32
|
+
route(meta: OpenAPIMeta): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
33
|
+
}
|
|
34
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
35
|
+
route(meta: OpenAPIMeta): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { openapi } from "../meta.js";
|
|
2
|
+
import { ContractBuilder } from "@orpc/contract";
|
|
3
|
+
import { Builder, DecoratedProcedure } from "@orpc/server";
|
|
4
|
+
// src/extensions/route.ts
|
|
5
|
+
ContractBuilder.prototype.route = function route(meta) {
|
|
6
|
+
return this.meta(openapi(meta));
|
|
7
|
+
};
|
|
8
|
+
Builder.prototype.route = function route(meta) {
|
|
9
|
+
return this.meta(openapi(meta));
|
|
10
|
+
};
|
|
11
|
+
DecoratedProcedure.prototype.route = function route(meta) {
|
|
12
|
+
return this.meta(openapi(meta));
|
|
13
|
+
};
|
|
@@ -23,10 +23,15 @@
|
|
|
23
23
|
* // thumb: form.get('thumb'),
|
|
24
24
|
* // }
|
|
25
25
|
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
|
|
26
28
|
*/
|
|
27
|
-
declare function parseFormData(form: FormData): any;
|
|
29
|
+
export declare function parseFormData(form: FormData): any;
|
|
28
30
|
/**
|
|
29
|
-
*
|
|
31
|
+
* Gets the issue message from the error for a given field path.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* **Note**: Requires validation errors to follow the standard schema issue format, stored under `data.issues` — customized validation errors may not be found.
|
|
30
35
|
*
|
|
31
36
|
* @example
|
|
32
37
|
* ```tsx
|
|
@@ -42,10 +47,11 @@ declare function parseFormData(form: FormData): any;
|
|
|
42
47
|
* <input name="images[]" type="file" />
|
|
43
48
|
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
44
49
|
* </form>
|
|
50
|
+
* ```
|
|
45
51
|
*
|
|
46
52
|
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
47
53
|
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
|
|
48
56
|
*/
|
|
49
|
-
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
50
|
-
|
|
51
|
-
export { getIssueMessage, parseFormData };
|
|
57
|
+
export declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BracketNotationSerializer } from "../bracket-notation.js";
|
|
2
|
+
import { NON_NEGATIVE_INTEGER_REGEX, isNonPrimitive } from "@orpc/shared";
|
|
3
|
+
import { isSchemaIssue } from "@orpc/contract";
|
|
4
|
+
// src/helpers/form-data.ts
|
|
5
|
+
/**
|
|
6
|
+
* Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const form = new FormData()
|
|
11
|
+
* form.append('a', '1')
|
|
12
|
+
* form.append('user[name]', 'John')
|
|
13
|
+
* form.append('user[age]', '20')
|
|
14
|
+
* form.append('user[friends][]', 'Bob')
|
|
15
|
+
* form.append('user[friends][]', 'Alice')
|
|
16
|
+
* form.append('user[friends][]', 'Charlie')
|
|
17
|
+
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
18
|
+
*
|
|
19
|
+
* parseFormData(form)
|
|
20
|
+
* // {
|
|
21
|
+
* // a: '1',
|
|
22
|
+
* // user: {
|
|
23
|
+
* // name: 'John',
|
|
24
|
+
* // age: '20',
|
|
25
|
+
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
26
|
+
* // },
|
|
27
|
+
* // thumb: form.get('thumb'),
|
|
28
|
+
* // }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
|
|
32
|
+
*/
|
|
33
|
+
function parseFormData(form) {
|
|
34
|
+
return new BracketNotationSerializer().deserialize(Array.from(form.entries()));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the issue message from the error for a given field path.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* **Note**: Requires validation errors to follow the standard schema issue format, stored under `data.issues` — customized validation errors may not be found.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
45
|
+
*
|
|
46
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
47
|
+
* <input name="user[name]" type="text" />
|
|
48
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
49
|
+
*
|
|
50
|
+
* <input name="user[age]" type="number" />
|
|
51
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
52
|
+
*
|
|
53
|
+
* <input name="images[]" type="file" />
|
|
54
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
55
|
+
* </form>
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
59
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
|
|
62
|
+
*/
|
|
63
|
+
function getIssueMessage(error, path) {
|
|
64
|
+
if (!isNonPrimitive(error) || !isNonPrimitive(error.data) || !Array.isArray(error.data.issues)) return;
|
|
65
|
+
const serializer = new BracketNotationSerializer();
|
|
66
|
+
for (const issue of error.data.issues) {
|
|
67
|
+
if (!isSchemaIssue(issue)) continue;
|
|
68
|
+
if (issue.path === void 0) {
|
|
69
|
+
if (path === "") return issue.message;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const issuePath = serializer.stringifyPath(issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString()));
|
|
73
|
+
if (issuePath === path) return issue.message;
|
|
74
|
+
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) return issue.message;
|
|
75
|
+
if (path === "" && NON_NEGATIVE_INTEGER_REGEX.test(issuePath)) return issue.message;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export { getIssueMessage, parseFormData };
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const form = new FormData()
|
|
7
|
-
* form.append('a', '1')
|
|
8
|
-
* form.append('user[name]', 'John')
|
|
9
|
-
* form.append('user[age]', '20')
|
|
10
|
-
* form.append('user[friends][]', 'Bob')
|
|
11
|
-
* form.append('user[friends][]', 'Alice')
|
|
12
|
-
* form.append('user[friends][]', 'Charlie')
|
|
13
|
-
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
14
|
-
*
|
|
15
|
-
* parseFormData(form)
|
|
16
|
-
* // {
|
|
17
|
-
* // a: '1',
|
|
18
|
-
* // user: {
|
|
19
|
-
* // name: 'John',
|
|
20
|
-
* // age: '20',
|
|
21
|
-
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
22
|
-
* // },
|
|
23
|
-
* // thumb: form.get('thumb'),
|
|
24
|
-
* // }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
declare function parseFormData(form: FormData): any;
|
|
28
|
-
/**
|
|
29
|
-
* Get the issue message from the error.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const { error, data, execute } = useServerAction(someAction)
|
|
34
|
-
*
|
|
35
|
-
* return <form action={(form) => execute(parseFormData(form))}>
|
|
36
|
-
* <input name="user[name]" type="text" />
|
|
37
|
-
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
38
|
-
*
|
|
39
|
-
* <input name="user[age]" type="number" />
|
|
40
|
-
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
41
|
-
*
|
|
42
|
-
* <input name="images[]" type="file" />
|
|
43
|
-
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
44
|
-
* </form>
|
|
45
|
-
*
|
|
46
|
-
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
47
|
-
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
|
|
48
|
-
*/
|
|
49
|
-
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
50
|
-
|
|
51
|
-
export { getIssueMessage, parseFormData };
|
|
1
|
+
import { getIssueMessage, parseFormData } from "./form-data.js";
|
|
2
|
+
export { getIssueMessage, parseFormData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getIssueMessage, parseFormData } from "./form-data.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,120 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>, ...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>): PromiseWithError<JsonifiedValue<InferSchemaOutput<TOutputSchema>>, JsonifiedClientError<ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
|
|
17
|
-
}
|
|
18
|
-
interface ContractJsonifiedCallerOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
|
|
19
|
-
/**
|
|
20
|
-
* An optional reference to the root router-contract.
|
|
21
|
-
* When provided, the caller will automatically register the called procedure-contract
|
|
22
|
-
* into the router at the path defined by `meta.path`.
|
|
23
|
-
*/
|
|
24
|
-
contractRef?: undefined | RouterContract;
|
|
25
|
-
}
|
|
26
|
-
declare function createContractJsonifiedCaller<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedCallerOptions<TClientContext>): ContractJsonifiedCaller<TClientContext>;
|
|
27
|
-
|
|
28
|
-
declare const DEFAULT_OPENAPI_METHOD = "POST";
|
|
29
|
-
declare const DEFAULT_OPENAPI_SUCCESS_DESCRIPTION = "OK";
|
|
30
|
-
declare const DEFAULT_OPENAPI_INPUT_STRUCTURE = "compact";
|
|
31
|
-
declare const DEFAULT_OPENAPI_OUTPUT_STRUCTURE = "compact";
|
|
32
|
-
|
|
33
|
-
declare class OpenAPIGeneratorError extends TypeError {
|
|
34
|
-
}
|
|
35
|
-
interface OpenAPIGeneratorOptions {
|
|
36
|
-
converters?: JsonSchemaConverter[] | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* The serializer used to serialize the generated OpenAPI documentation
|
|
39
|
-
*/
|
|
40
|
-
serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer> | undefined;
|
|
41
|
-
}
|
|
42
|
-
interface OpenAPIGeneratorGenerateOptions {
|
|
43
|
-
base?: Partial<OpenAPIDocument> | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Controls whether a generated json schema `$defs` at root-level should be moved into `components.schemas`.
|
|
46
|
-
*
|
|
47
|
-
* @default true
|
|
48
|
-
*/
|
|
49
|
-
shouldHoistDef?: Value<boolean, [defName: string, defSchema: JsonSchema]>;
|
|
50
|
-
/**
|
|
51
|
-
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
52
|
-
*
|
|
53
|
-
* @default true
|
|
54
|
-
*/
|
|
55
|
-
filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]>;
|
|
56
|
-
/**
|
|
57
|
-
* Define a custom JSON schema for the error response body when using
|
|
58
|
-
* type-safe errors. Helps align ORPC error formatting with existing API
|
|
59
|
-
* response standards or conventions.
|
|
60
|
-
*
|
|
61
|
-
* @remarks
|
|
62
|
-
* - Return `null | undefined` to use the default error response body shaper.
|
|
63
|
-
*/
|
|
64
|
-
customErrorResponseBodySchema?: Value<JsonSchema | undefined | null, [
|
|
65
|
-
definedErrors: {
|
|
66
|
-
code: string;
|
|
67
|
-
defaultMessage: string | undefined;
|
|
68
|
-
dataOptional: boolean;
|
|
69
|
-
dataJsonSchema: JsonSchema;
|
|
70
|
-
}[],
|
|
71
|
-
status: number
|
|
72
|
-
]>;
|
|
73
|
-
/**
|
|
74
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
75
|
-
*
|
|
76
|
-
* @default COMMON_ERROR_STATUS_MAP, DEFAULT_ERROR_STATUS
|
|
77
|
-
*/
|
|
78
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
79
|
-
}
|
|
80
|
-
declare class OpenAPIGenerator {
|
|
81
|
-
private readonly serializer;
|
|
82
|
-
private readonly converter;
|
|
83
|
-
constructor(options?: OpenAPIGeneratorOptions);
|
|
84
|
-
generate(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIDocument>;
|
|
85
|
-
private convertSchema;
|
|
86
|
-
private convertSchemas;
|
|
87
|
-
private request;
|
|
88
|
-
private successResponse;
|
|
89
|
-
private errorResponse;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
|
|
93
|
-
[K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
|
|
94
|
-
};
|
|
95
|
-
interface PopulateRouterContractOpenAPIPathsOptions {
|
|
96
|
-
/**
|
|
97
|
-
* Base path segments.
|
|
98
|
-
*/
|
|
99
|
-
path?: undefined | string[];
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Automatically populates missing openapi.path using router structure.
|
|
103
|
-
*
|
|
104
|
-
* Builds paths by joining router keys with `/`.
|
|
105
|
-
* Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
|
|
106
|
-
*/
|
|
107
|
-
declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Dynamic parameters are always returned in path order.
|
|
111
|
-
*/
|
|
112
|
-
declare function getDynamicPathParams(path: `/${string}`): {
|
|
113
|
-
segment: string;
|
|
114
|
-
startIndex: number;
|
|
115
|
-
parameterName: string;
|
|
116
|
-
allowsSlash: boolean;
|
|
117
|
-
}[] | undefined;
|
|
118
|
-
|
|
119
|
-
export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams, populateRouterContractOpenAPIPaths };
|
|
120
|
-
export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };
|
|
1
|
+
import { BracketNotationSerializeResult, BracketNotationSerializer, BracketNotationSerializerOptions } from "./bracket-notation.js";
|
|
2
|
+
import { ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, createContractJsonifiedClientFactory } from "./client-factory.js";
|
|
3
|
+
import { DEFAULT_OPENAPI_METHOD } from "./constants.js";
|
|
4
|
+
import { OpenAPIFunction, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugin, OpenAPIPathMetaPlugin, OpenAPIPrefixMetaPlugin, OpenAPISpecMetaPlugin, getOpenAPIMeta, openapi } from "./meta.js";
|
|
5
|
+
import { OpenAPIGenerator, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions } from "./openapi-generator.js";
|
|
6
|
+
import { OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions } from "./openapi-json-serializer.js";
|
|
7
|
+
import { OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions } from "./openapi-serializer.js";
|
|
8
|
+
import { PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths, populateRouterContractOpenAPIPaths } from "./router-utils.js";
|
|
9
|
+
import { OpenAPIErrorBodyDefinition, OpenAPIGeneratorError } from "./openapi-generator-operation.js";
|
|
10
|
+
import { JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIV3_0, OpenAPIV3_1, OpenAPIV3_2, OpenAPIVersion } from "./types.js";
|
|
11
|
+
import { getDynamicPathParams } from "./utils.js";
|
|
12
|
+
import { COMMON_ERROR_STATUS_MAP } from "@orpc/client";
|
|
13
|
+
import { JsonSchema } from "@orpc/json-schema";
|
|
14
|
+
import { StandardBodyHint } from "@standard-server/core";
|
|
15
|
+
export { BracketNotationSerializeResult, BracketNotationSerializer, BracketNotationSerializerOptions, COMMON_ERROR_STATUS_MAP, ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, DEFAULT_OPENAPI_METHOD, type JsonSchema, JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, type OpenAPIErrorBodyDefinition, OpenAPIFunction, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugin, OpenAPIPathMetaPlugin, OpenAPIPrefixMetaPlugin, OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions, OpenAPISpecMetaPlugin, type OpenAPIV3_0, type OpenAPIV3_1, type OpenAPIV3_2, OpenAPIVersion, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths, type StandardBodyHint, createContractJsonifiedClientFactory, getDynamicPathParams, getOpenAPIMeta, openapi, populateRouterContractOpenAPIPaths };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { BracketNotationSerializer } from "./bracket-notation.js";
|
|
2
|
+
export { createContractJsonifiedClientFactory } from "./client-factory.js";
|
|
3
|
+
export { DEFAULT_OPENAPI_METHOD } from "./constants.js";
|
|
4
|
+
export { getOpenAPIMeta, openapi } from "./meta.js";
|
|
5
|
+
export { OpenAPIGenerator } from "./openapi-generator.js";
|
|
6
|
+
export { OpenAPIGeneratorError } from "./openapi-generator-operation.js";
|
|
7
|
+
export { OpenAPIJsonSerializer } from "./openapi-json-serializer.js";
|
|
8
|
+
export { OpenAPISerializer } from "./openapi-serializer.js";
|
|
9
|
+
export { populateRouterContractOpenAPIPaths } from "./router-utils.js";
|
|
10
|
+
export { getDynamicPathParams } from "./utils.js";
|
|
11
|
+
export { COMMON_ERROR_STATUS_MAP } from "@orpc/client";
|