@orpc/openapi 1.14.6 → 2.0.0-beta.1
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 +74 -109
- package/dist/adapters/fetch/index.d.mts +20 -16
- package/dist/adapters/fetch/index.d.ts +20 -16
- package/dist/adapters/fetch/index.mjs +24 -8
- package/dist/adapters/node/index.d.mts +8 -13
- package/dist/adapters/node/index.d.ts +8 -13
- package/dist/adapters/node/index.mjs +10 -7
- package/dist/adapters/standard/index.d.mts +46 -16
- package/dist/adapters/standard/index.d.ts +46 -16
- package/dist/adapters/standard/index.mjs +9 -6
- package/dist/extensions/route.d.mts +43 -0
- package/dist/extensions/route.d.ts +43 -0
- package/dist/extensions/route.mjs +14 -0
- package/dist/helpers/index.d.mts +51 -0
- package/dist/helpers/index.d.ts +51 -0
- package/dist/helpers/index.mjs +39 -0
- package/dist/index.d.mts +92 -111
- package/dist/index.d.ts +92 -111
- package/dist/index.mjs +894 -34
- package/dist/plugins/index.d.mts +55 -51
- package/dist/plugins/index.d.ts +55 -51
- package/dist/plugins/index.mjs +147 -142
- package/dist/shared/openapi.B2SK0ZAr.mjs +359 -0
- package/dist/shared/openapi.B9PQzqBn.mjs +49 -0
- package/dist/shared/openapi.BQzzr4-4.d.ts +299 -0
- package/dist/shared/openapi.BcEtAxQj.d.mts +299 -0
- package/dist/shared/openapi.Bt87OzTt.mjs +131 -0
- package/dist/shared/openapi.C7m7NAmH.d.mts +142 -0
- package/dist/shared/openapi.C7m7NAmH.d.ts +142 -0
- package/dist/shared/openapi.C9Olbxd5.d.ts +75 -0
- package/dist/shared/openapi.CYgMBSUF.d.mts +18 -0
- package/dist/shared/openapi.CYgMBSUF.d.ts +18 -0
- package/dist/shared/openapi.CcyUEuTs.mjs +313 -0
- package/dist/shared/openapi.DmAa7YPO.mjs +275 -0
- package/dist/shared/openapi.Drd1OtzG.d.mts +75 -0
- package/package.json +29 -23
- package/dist/adapters/aws-lambda/index.d.mts +0 -20
- package/dist/adapters/aws-lambda/index.d.ts +0 -20
- package/dist/adapters/aws-lambda/index.mjs +0 -18
- package/dist/adapters/fastify/index.d.mts +0 -23
- package/dist/adapters/fastify/index.d.ts +0 -23
- package/dist/adapters/fastify/index.mjs +0 -18
- package/dist/shared/openapi.BB-W-NKv.mjs +0 -204
- package/dist/shared/openapi.BGy4N6eR.d.mts +0 -120
- package/dist/shared/openapi.BGy4N6eR.d.ts +0 -120
- package/dist/shared/openapi.BwdtJjDu.mjs +0 -878
- package/dist/shared/openapi.DwaweYRb.d.mts +0 -54
- package/dist/shared/openapi.DwaweYRb.d.ts +0 -54
|
@@ -1,20 +1,50 @@
|
|
|
1
|
-
export { a as
|
|
2
|
-
import {
|
|
3
|
-
import '@orpc/
|
|
1
|
+
export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecError, O as OpenAPIHandlerCodecOptions, c as OpenAPIMatcher, d as OpenAPIMatcherOptions } from '../../shared/openapi.C9Olbxd5.js';
|
|
2
|
+
import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
|
|
3
|
+
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
|
|
4
|
+
import { RouterContract } from '@orpc/contract';
|
|
5
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
6
|
+
import { StandardUrl, StandardHeaders, StandardLazyResponse, StandardRequest } from '@standardserver/core';
|
|
7
|
+
import { O as OpenAPISerializer } from '../../shared/openapi.C7m7NAmH.js';
|
|
4
8
|
import '@orpc/server';
|
|
5
9
|
import '@orpc/server/standard';
|
|
6
|
-
import '@orpc/standard-server';
|
|
7
|
-
import '@orpc/shared';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
declare class OpenAPILinkCodecError extends TypeError {
|
|
12
|
+
}
|
|
13
|
+
interface OpenAPILinkCodecOptions<T extends ClientContext> {
|
|
14
|
+
/**
|
|
15
|
+
* Base URL for all requests, without origin. Should match the OpenAPI handler mount path.
|
|
16
|
+
*
|
|
17
|
+
* @example '/api'
|
|
18
|
+
* @default '/'
|
|
19
|
+
*/
|
|
20
|
+
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
21
|
+
/**
|
|
22
|
+
* Inject headers into the request.
|
|
23
|
+
*/
|
|
24
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
25
|
+
/**
|
|
26
|
+
* Override the default OpenAPI serializer.
|
|
27
|
+
*/
|
|
28
|
+
serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer>;
|
|
29
|
+
/**
|
|
30
|
+
* Customize how an error response body is converted into an ORPC error.
|
|
31
|
+
* Return `null` or `undefined` to fall back to the default decoding behavior.
|
|
32
|
+
*/
|
|
33
|
+
customErrorResponseBodyDecoder?: (deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined;
|
|
34
|
+
}
|
|
35
|
+
declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
36
|
+
private readonly router;
|
|
37
|
+
private readonly baseUrl;
|
|
38
|
+
private readonly headers;
|
|
39
|
+
private readonly serializer;
|
|
40
|
+
private readonly customErrorResponseBodyDecoder;
|
|
41
|
+
constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
|
|
42
|
+
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
43
|
+
private encodePathParam;
|
|
44
|
+
private serializeQueryString;
|
|
45
|
+
decodeResponse(response: StandardLazyResponse, path: string[], _options: ClientOptions<T>): Promise<StandardLinkCodecDecodedResponse>;
|
|
46
|
+
private resolveProcedure;
|
|
47
|
+
}
|
|
19
48
|
|
|
20
|
-
export {
|
|
49
|
+
export { OpenAPILinkCodec, OpenAPILinkCodecError };
|
|
50
|
+
export type { OpenAPILinkCodecOptions };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
import '@orpc/server/standard';
|
|
1
|
+
export { O as OpenAPIHandlerCodec, a as OpenAPIHandlerCodecError, b as OpenAPIMatcher } from '../../shared/openapi.CcyUEuTs.mjs';
|
|
2
|
+
export { O as OpenAPILinkCodec, a as OpenAPILinkCodecError } from '../../shared/openapi.B2SK0ZAr.mjs';
|
|
4
3
|
import '@orpc/client';
|
|
5
|
-
import '@orpc/contract';
|
|
6
|
-
import '@orpc/shared';
|
|
7
|
-
import '@orpc/client/standard';
|
|
8
4
|
import '@orpc/server';
|
|
5
|
+
import '@orpc/shared';
|
|
6
|
+
import '@standardserver/core';
|
|
7
|
+
import '../../shared/openapi.DmAa7YPO.mjs';
|
|
8
|
+
import '../../shared/openapi.Bt87OzTt.mjs';
|
|
9
|
+
import '../../shared/openapi.B9PQzqBn.mjs';
|
|
9
10
|
import 'rou3';
|
|
11
|
+
import '@orpc/contract';
|
|
12
|
+
import '@standardserver/fetch';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AnyORPCError } from '@orpc/client';
|
|
2
|
+
import { ErrorMap, AnySchema } from '@orpc/contract';
|
|
3
|
+
import { Context } from '@orpc/server';
|
|
4
|
+
import { O as OpenAPIMeta } from '../shared/openapi.BcEtAxQj.mjs';
|
|
5
|
+
import '@orpc/shared';
|
|
6
|
+
import '@standardserver/core';
|
|
7
|
+
import '../shared/openapi.CYgMBSUF.mjs';
|
|
8
|
+
import '@hey-api/spec-types';
|
|
9
|
+
|
|
10
|
+
declare module '@orpc/contract' {
|
|
11
|
+
interface ContractBuilder<TErrorMap extends ErrorMap> {
|
|
12
|
+
route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
|
|
13
|
+
}
|
|
14
|
+
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
15
|
+
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
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
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AnyORPCError } from '@orpc/client';
|
|
2
|
+
import { ErrorMap, AnySchema } from '@orpc/contract';
|
|
3
|
+
import { Context } from '@orpc/server';
|
|
4
|
+
import { O as OpenAPIMeta } from '../shared/openapi.BQzzr4-4.js';
|
|
5
|
+
import '@orpc/shared';
|
|
6
|
+
import '@standardserver/core';
|
|
7
|
+
import '../shared/openapi.CYgMBSUF.js';
|
|
8
|
+
import '@hey-api/spec-types';
|
|
9
|
+
|
|
10
|
+
declare module '@orpc/contract' {
|
|
11
|
+
interface ContractBuilder<TErrorMap extends ErrorMap> {
|
|
12
|
+
route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
|
|
13
|
+
}
|
|
14
|
+
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
15
|
+
route(meta: OpenAPIMeta): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
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
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ContractBuilder } from '@orpc/contract';
|
|
2
|
+
import { Builder, DecoratedProcedure } from '@orpc/server';
|
|
3
|
+
import { o as openapi } from '../shared/openapi.B9PQzqBn.mjs';
|
|
4
|
+
import '@orpc/shared';
|
|
5
|
+
|
|
6
|
+
ContractBuilder.prototype.route = function route(meta) {
|
|
7
|
+
return this.meta(openapi(meta));
|
|
8
|
+
};
|
|
9
|
+
Builder.prototype.route = function route2(meta) {
|
|
10
|
+
return this.meta(openapi(meta));
|
|
11
|
+
};
|
|
12
|
+
DecoratedProcedure.prototype.route = function route3(meta) {
|
|
13
|
+
return this.meta(openapi(meta));
|
|
14
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
|
|
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 };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
|
|
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 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isSchemaIssue } from '@orpc/contract';
|
|
2
|
+
import { isTypescriptObject } from '@orpc/shared';
|
|
3
|
+
import { B as BracketNotationSerializer } from '../shared/openapi.Bt87OzTt.mjs';
|
|
4
|
+
|
|
5
|
+
function parseFormData(form) {
|
|
6
|
+
const serializer = new BracketNotationSerializer();
|
|
7
|
+
return serializer.deserialize(Array.from(form.entries()));
|
|
8
|
+
}
|
|
9
|
+
function getIssueMessage(error, path) {
|
|
10
|
+
if (!isTypescriptObject(error) || !isTypescriptObject(error.data) || !Array.isArray(error.data.issues)) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
const serializer = new BracketNotationSerializer();
|
|
14
|
+
for (const issue of error.data.issues) {
|
|
15
|
+
if (!isSchemaIssue(issue)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (issue.path === void 0) {
|
|
19
|
+
if (path === "") {
|
|
20
|
+
return issue.message;
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const issuePath = serializer.stringifyPath(
|
|
25
|
+
issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString())
|
|
26
|
+
);
|
|
27
|
+
if (issuePath === path) {
|
|
28
|
+
return issue.message;
|
|
29
|
+
}
|
|
30
|
+
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) {
|
|
31
|
+
return issue.message;
|
|
32
|
+
}
|
|
33
|
+
if (path === "" && /(?:0|[1-9]\d*)$/.test(issuePath)) {
|
|
34
|
+
return issue.message;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { getIssueMessage, parseFormData };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,117 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { JsonifiedClient } from '
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import '@orpc/
|
|
1
|
+
import { O as OpenAPISerializer } from './shared/openapi.C7m7NAmH.mjs';
|
|
2
|
+
export { B as BracketNotationSerializeResult, a as BracketNotationSerializer, b as BracketNotationSerializerOptions, c as OpenAPIJsonSerialization, d as OpenAPIJsonSerializer, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.C7m7NAmH.mjs';
|
|
3
|
+
import { ClientContext, ClientRest, ThrowableError, ORPCClientOptions, ClientLink } from '@orpc/client';
|
|
4
|
+
export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
5
|
+
import { AnySchema, ErrorMap, ProcedureContract, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, RouterContractClient, RouterContract, AnyProcedureContract } from '@orpc/contract';
|
|
6
|
+
import { PromiseWithError, Value } from '@orpc/shared';
|
|
7
|
+
import { J as JsonifiedValue, b as JsonifiedClientError, c as JsonifiedClient, a as OpenAPIDocument } from './shared/openapi.CYgMBSUF.mjs';
|
|
8
|
+
export { d as JsonifiedArray, O as OpenAPIOperationObject } from './shared/openapi.CYgMBSUF.mjs';
|
|
9
|
+
export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.BcEtAxQj.mjs';
|
|
10
|
+
import { JsonSchemaConverter, JsonSchema } from '@orpc/json-schema';
|
|
11
|
+
import { AnyRouter, AnyProcedure } from '@orpc/server';
|
|
12
|
+
import '@standardserver/core';
|
|
13
|
+
import '@hey-api/spec-types';
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
interface ContractJsonifiedCaller<TClientContext extends ClientContext> {
|
|
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>;
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
declare class OpenAPIGeneratorError extends TypeError {
|
|
29
|
+
}
|
|
30
|
+
interface OpenAPIGeneratorOptions {
|
|
31
|
+
converters?: JsonSchemaConverter[] | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The serializer used to serialize the generated OpenAPI documentation
|
|
34
|
+
*/
|
|
35
|
+
serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer> | undefined;
|
|
36
|
+
}
|
|
37
|
+
interface OpenAPIGeneratorGenerateOptions {
|
|
38
|
+
base?: Partial<OpenAPIDocument> | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Controls whether a generated json schema `$defs` at root-level should be moved into `components.schemas`.
|
|
41
|
+
*
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
shouldHoistDef?: Value<boolean, [defName: string, defSchema: JsonSchema]>;
|
|
45
|
+
/**
|
|
46
|
+
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
47
|
+
*
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]>;
|
|
51
|
+
/**
|
|
52
|
+
* Define a custom JSON schema for the error response body when using
|
|
53
|
+
* type-safe errors. Helps align ORPC error formatting with existing API
|
|
54
|
+
* response standards or conventions.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* - Return `null | undefined` to use the default error response body shaper.
|
|
58
|
+
*/
|
|
59
|
+
customErrorResponseBodySchema?: Value<JsonSchema | undefined | null, [
|
|
60
|
+
definedErrors: {
|
|
61
|
+
code: string;
|
|
62
|
+
defaultMessage: string | undefined;
|
|
63
|
+
dataOptional: boolean;
|
|
64
|
+
dataJsonSchema: JsonSchema;
|
|
65
|
+
}[],
|
|
66
|
+
status: number
|
|
67
|
+
]>;
|
|
68
|
+
/**
|
|
69
|
+
* Mapping ORPCError Code -> HTTP Status Code
|
|
70
|
+
*
|
|
71
|
+
* @default COMMON_ERROR_STATUS_MAP, DEFAULT_ERROR_STATUS
|
|
72
|
+
*/
|
|
73
|
+
errorStatusMap?: Record<string, number> | undefined;
|
|
74
|
+
}
|
|
75
|
+
declare class OpenAPIGenerator {
|
|
76
|
+
private readonly serializer;
|
|
77
|
+
private readonly converter;
|
|
78
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
79
|
+
generate(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIDocument>;
|
|
80
|
+
private convertSchema;
|
|
81
|
+
private convertSchemas;
|
|
82
|
+
private request;
|
|
83
|
+
private successResponse;
|
|
84
|
+
private errorResponse;
|
|
85
|
+
}
|
|
39
86
|
|
|
40
87
|
/**
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
44
|
-
/**
|
|
45
|
-
* @internal
|
|
88
|
+
* Dynamic parameters are always returned in path order.
|
|
46
89
|
*/
|
|
47
|
-
declare function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
56
|
-
/**
|
|
57
|
-
* @internal
|
|
58
|
-
*/
|
|
59
|
-
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
60
|
-
/**
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
68
|
-
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
69
|
-
/**
|
|
70
|
-
* Simplifies composed object JSON Schemas (using anyOf, oneOf, allOf) by flattening nested compositions
|
|
71
|
-
*
|
|
72
|
-
* @warning The result is looser than the original schema and may not fully validate the same data.
|
|
73
|
-
*/
|
|
74
|
-
declare function simplifyComposedObjectJsonSchemasAndRefs(schema: JSONSchema, doc?: OpenAPI.Document): JSONSchema;
|
|
75
|
-
|
|
76
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
*@internal
|
|
80
|
-
*/
|
|
81
|
-
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
82
|
-
/**
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
86
|
-
/**
|
|
87
|
-
* @internal
|
|
88
|
-
*/
|
|
89
|
-
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
90
|
-
declare function isNeverSchema(schema: JSONSchema): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* @internal
|
|
93
|
-
*/
|
|
94
|
-
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
95
|
-
/**
|
|
96
|
-
* @internal
|
|
97
|
-
*/
|
|
98
|
-
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
99
|
-
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
100
|
-
/**
|
|
101
|
-
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
102
|
-
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
103
|
-
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
104
|
-
*/
|
|
105
|
-
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
106
|
-
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
107
|
-
type: 'array';
|
|
108
|
-
items?: JSONSchema;
|
|
109
|
-
}];
|
|
110
|
-
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
111
|
-
|
|
112
|
-
declare const oo: {
|
|
113
|
-
spec: typeof customOpenAPIOperation;
|
|
114
|
-
};
|
|
90
|
+
declare function getDynamicPathParams(path: `/${string}`): {
|
|
91
|
+
segment: string;
|
|
92
|
+
startIndex: number;
|
|
93
|
+
parameterName: string;
|
|
94
|
+
allowsSlash: boolean;
|
|
95
|
+
}[] | undefined;
|
|
115
96
|
|
|
116
|
-
export {
|
|
117
|
-
export type {
|
|
97
|
+
export { JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams };
|
|
98
|
+
export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions };
|