@orpc/openapi-client 0.0.0-next.bec9f4e → 0.0.0-next.bf3438f
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 +18 -22
- package/dist/adapters/fetch/index.d.mts +12 -5
- package/dist/adapters/fetch/index.d.ts +12 -5
- package/dist/adapters/fetch/index.mjs +5 -9
- package/dist/adapters/standard/index.d.mts +55 -2
- package/dist/adapters/standard/index.d.ts +55 -2
- package/dist/adapters/standard/index.mjs +41 -4
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/shared/{openapi-client.N18yafE2.d.mts → openapi-client.Bc2pHPqD.d.mts} +9 -5
- package/dist/shared/{openapi-client.N18yafE2.d.ts → openapi-client.Bc2pHPqD.d.ts} +9 -5
- package/dist/shared/{openapi-client.xWSf16XH.mjs → openapi-client.Bix5hHnT.mjs} +56 -23
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -21,28 +21,24 @@
|
|
|
21
21
|
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
23
|
|
|
24
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Highlights
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,12 +49,12 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
-
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
59
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
60
|
-
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
61
52
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
56
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
62
58
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
63
59
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
64
60
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
|
-
import { AnyContractRouter } from '@orpc/contract';
|
|
3
2
|
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
4
|
-
import {
|
|
5
|
-
import { f as StandardOpenAPILinkOptions } from '../../shared/openapi-client.
|
|
3
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
+
import { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.Bc2pHPqD.mjs';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@orpc/standard-server';
|
|
8
8
|
|
|
9
9
|
interface OpenAPILinkOptions<T extends ClientContext> extends StandardOpenAPILinkOptions<T>, LinkFetchClientOptions<T> {
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The OpenAPI Link for fetch runtime communicates with the server that follow the OpenAPI specification.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
15
|
+
* @see {@link https://swagger.io/specification/ OpenAPI Specification}
|
|
16
|
+
*/
|
|
17
|
+
declare class OpenAPILink<T extends ClientContext> extends StandardOpenAPILink<T> {
|
|
12
18
|
constructor(contract: AnyContractRouter, options: OpenAPILinkOptions<T>);
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
export { OpenAPILink
|
|
21
|
+
export { OpenAPILink };
|
|
22
|
+
export type { OpenAPILinkOptions };
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
|
-
import { AnyContractRouter } from '@orpc/contract';
|
|
3
2
|
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
4
|
-
import {
|
|
5
|
-
import { f as StandardOpenAPILinkOptions } from '../../shared/openapi-client.
|
|
3
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
+
import { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.Bc2pHPqD.js';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@orpc/standard-server';
|
|
8
8
|
|
|
9
9
|
interface OpenAPILinkOptions<T extends ClientContext> extends StandardOpenAPILinkOptions<T>, LinkFetchClientOptions<T> {
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The OpenAPI Link for fetch runtime communicates with the server that follow the OpenAPI specification.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
15
|
+
* @see {@link https://swagger.io/specification/ OpenAPI Specification}
|
|
16
|
+
*/
|
|
17
|
+
declare class OpenAPILink<T extends ClientContext> extends StandardOpenAPILink<T> {
|
|
12
18
|
constructor(contract: AnyContractRouter, options: OpenAPILinkOptions<T>);
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
export { OpenAPILink
|
|
21
|
+
export { OpenAPILink };
|
|
22
|
+
export type { OpenAPILinkOptions };
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { LinkFetchClient } from '@orpc/client/fetch';
|
|
2
|
-
import { StandardLink } from '@orpc/client/standard';
|
|
3
|
-
import { a as StandardOpenAPIJsonSerializer, b as StandardOpenapiLinkCodec, c as StandardOpenAPISerializer, S as StandardBracketNotationSerializer } from '../../shared/openapi-client.xWSf16XH.mjs';
|
|
4
2
|
import '@orpc/shared';
|
|
5
3
|
import '@orpc/contract';
|
|
6
|
-
import '
|
|
4
|
+
import { b as StandardOpenAPILink } from '../../shared/openapi-client.Bix5hHnT.mjs';
|
|
7
5
|
import '@orpc/client';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/standard-server';
|
|
8
8
|
|
|
9
|
-
class OpenAPILink extends
|
|
9
|
+
class OpenAPILink extends StandardOpenAPILink {
|
|
10
10
|
constructor(contract, options) {
|
|
11
|
-
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
12
|
-
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
13
|
-
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
14
|
-
const linkCodec = new StandardOpenapiLinkCodec(contract, serializer, options);
|
|
15
11
|
const linkClient = new LinkFetchClient(options);
|
|
16
|
-
super(
|
|
12
|
+
super(contract, linkClient, options);
|
|
17
13
|
}
|
|
18
14
|
}
|
|
19
15
|
|
|
@@ -1,10 +1,63 @@
|
|
|
1
|
-
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, f as StandardOpenAPILinkOptions,
|
|
1
|
+
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.Bc2pHPqD.mjs';
|
|
2
2
|
import { HTTPPath } from '@orpc/client';
|
|
3
3
|
import '@orpc/client/standard';
|
|
4
4
|
import '@orpc/contract';
|
|
5
5
|
import '@orpc/shared';
|
|
6
6
|
import '@orpc/standard-server';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* parse a form data with bracket notation
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const form = new FormData()
|
|
14
|
+
* form.append('a', '1')
|
|
15
|
+
* form.append('user[name]', 'John')
|
|
16
|
+
* form.append('user[age]', '20')
|
|
17
|
+
* form.append('user[friends][]', 'Bob')
|
|
18
|
+
* form.append('user[friends][]', 'Alice')
|
|
19
|
+
* form.append('user[friends][]', 'Charlie')
|
|
20
|
+
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
21
|
+
*
|
|
22
|
+
* parseFormData(form)
|
|
23
|
+
* // {
|
|
24
|
+
* // a: '1',
|
|
25
|
+
* // user: {
|
|
26
|
+
* // name: 'John',
|
|
27
|
+
* // age: '20',
|
|
28
|
+
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
29
|
+
* // },
|
|
30
|
+
* // thumb: form.get('thumb'),
|
|
31
|
+
* // }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
|
|
35
|
+
*/
|
|
36
|
+
declare function parseFormData(form: FormData): any;
|
|
37
|
+
/**
|
|
38
|
+
* Get the issue message from the error.
|
|
39
|
+
*
|
|
40
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
41
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.unnoq.com/docs/openapi/bracket-notation)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
46
|
+
*
|
|
47
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
48
|
+
* <input name="user[name]" type="text" />
|
|
49
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
50
|
+
*
|
|
51
|
+
* <input name="user[age]" type="number" />
|
|
52
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
53
|
+
*
|
|
54
|
+
* <input name="images[]" type="file" />
|
|
55
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
56
|
+
* </form>
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
60
|
+
|
|
8
61
|
/**
|
|
9
62
|
* @internal
|
|
10
63
|
*/
|
|
@@ -17,4 +70,4 @@ declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
|
17
70
|
name: string;
|
|
18
71
|
}[] | undefined;
|
|
19
72
|
|
|
20
|
-
export { getDynamicParams, standardizeHTTPPath };
|
|
73
|
+
export { getDynamicParams, getIssueMessage, parseFormData, standardizeHTTPPath };
|
|
@@ -1,10 +1,63 @@
|
|
|
1
|
-
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, f as StandardOpenAPILinkOptions,
|
|
1
|
+
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.Bc2pHPqD.js';
|
|
2
2
|
import { HTTPPath } from '@orpc/client';
|
|
3
3
|
import '@orpc/client/standard';
|
|
4
4
|
import '@orpc/contract';
|
|
5
5
|
import '@orpc/shared';
|
|
6
6
|
import '@orpc/standard-server';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* parse a form data with bracket notation
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const form = new FormData()
|
|
14
|
+
* form.append('a', '1')
|
|
15
|
+
* form.append('user[name]', 'John')
|
|
16
|
+
* form.append('user[age]', '20')
|
|
17
|
+
* form.append('user[friends][]', 'Bob')
|
|
18
|
+
* form.append('user[friends][]', 'Alice')
|
|
19
|
+
* form.append('user[friends][]', 'Charlie')
|
|
20
|
+
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
21
|
+
*
|
|
22
|
+
* parseFormData(form)
|
|
23
|
+
* // {
|
|
24
|
+
* // a: '1',
|
|
25
|
+
* // user: {
|
|
26
|
+
* // name: 'John',
|
|
27
|
+
* // age: '20',
|
|
28
|
+
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
29
|
+
* // },
|
|
30
|
+
* // thumb: form.get('thumb'),
|
|
31
|
+
* // }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
|
|
35
|
+
*/
|
|
36
|
+
declare function parseFormData(form: FormData): any;
|
|
37
|
+
/**
|
|
38
|
+
* Get the issue message from the error.
|
|
39
|
+
*
|
|
40
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
41
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.unnoq.com/docs/openapi/bracket-notation)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
46
|
+
*
|
|
47
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
48
|
+
* <input name="user[name]" type="text" />
|
|
49
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
50
|
+
*
|
|
51
|
+
* <input name="user[age]" type="number" />
|
|
52
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
53
|
+
*
|
|
54
|
+
* <input name="images[]" type="file" />
|
|
55
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
56
|
+
* </form>
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
60
|
+
|
|
8
61
|
/**
|
|
9
62
|
* @internal
|
|
10
63
|
*/
|
|
@@ -17,4 +70,4 @@ declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
|
17
70
|
name: string;
|
|
18
71
|
}[] | undefined;
|
|
19
72
|
|
|
20
|
-
export { getDynamicParams, standardizeHTTPPath };
|
|
73
|
+
export { getDynamicParams, getIssueMessage, parseFormData, standardizeHTTPPath };
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { S as StandardBracketNotationSerializer } from '../../shared/openapi-client.Bix5hHnT.mjs';
|
|
2
|
+
export { a as StandardOpenAPIJsonSerializer, b as StandardOpenAPILink, d as StandardOpenAPISerializer, c as StandardOpenapiLinkCodec, g as getDynamicParams, s as standardizeHTTPPath } from '../../shared/openapi-client.Bix5hHnT.mjs';
|
|
3
|
+
import { isSchemaIssue } from '@orpc/contract';
|
|
4
|
+
import { isTypescriptObject } from '@orpc/shared';
|
|
3
5
|
import '@orpc/client/standard';
|
|
4
|
-
import '@orpc/contract';
|
|
5
|
-
import '@orpc/standard-server';
|
|
6
6
|
import '@orpc/client';
|
|
7
|
+
import '@orpc/standard-server';
|
|
8
|
+
|
|
9
|
+
function parseFormData(form) {
|
|
10
|
+
const serializer = new StandardBracketNotationSerializer();
|
|
11
|
+
return serializer.deserialize(Array.from(form.entries()));
|
|
12
|
+
}
|
|
13
|
+
function getIssueMessage(error, path) {
|
|
14
|
+
if (!isTypescriptObject(error) || !isTypescriptObject(error.data) || !Array.isArray(error.data.issues)) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const serializer = new StandardBracketNotationSerializer();
|
|
18
|
+
for (const issue of error.data.issues) {
|
|
19
|
+
if (!isSchemaIssue(issue)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (issue.path === void 0) {
|
|
23
|
+
if (path === "") {
|
|
24
|
+
return issue.message;
|
|
25
|
+
}
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const issuePath = serializer.stringifyPath(
|
|
29
|
+
issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString())
|
|
30
|
+
);
|
|
31
|
+
if (issuePath === path) {
|
|
32
|
+
return issue.message;
|
|
33
|
+
}
|
|
34
|
+
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) {
|
|
35
|
+
return issue.message;
|
|
36
|
+
}
|
|
37
|
+
if (path === "" && issuePath.match(/(?:0|[1-9]\d*)$/)) {
|
|
38
|
+
return issue.message;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { StandardBracketNotationSerializer, getIssueMessage, parseFormData };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,11 @@ type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends
|
|
|
4
4
|
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
5
5
|
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
6
6
|
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
7
|
+
/**
|
|
8
|
+
* Convert types that JSON not support to corresponding json types
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
11
|
+
*/
|
|
7
12
|
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
|
|
8
13
|
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
9
14
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends
|
|
|
4
4
|
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
5
5
|
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
6
6
|
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
7
|
+
/**
|
|
8
|
+
* Convert types that JSON not support to corresponding json types
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
11
|
+
*/
|
|
7
12
|
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
|
|
8
13
|
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
9
14
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClientContext, ClientOptions } from '@orpc/client';
|
|
2
|
-
import { StandardLinkCodec, StandardLinkOptions } from '@orpc/client/standard';
|
|
2
|
+
import { StandardLinkCodec, StandardLinkOptions, StandardLink, StandardLinkClient } from '@orpc/client/standard';
|
|
3
3
|
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
-
import { Segment, Value } from '@orpc/shared';
|
|
4
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
5
5
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
6
6
|
|
|
7
7
|
type StandardBracketNotationSerialized = [string, unknown][];
|
|
@@ -44,7 +44,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [
|
|
48
48
|
options: ClientOptions<T>,
|
|
49
49
|
path: readonly string[],
|
|
50
50
|
input: unknown
|
|
@@ -52,7 +52,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
52
52
|
/**
|
|
53
53
|
* Inject headers to the request.
|
|
54
54
|
*/
|
|
55
|
-
headers?: Value<StandardHeaders
|
|
55
|
+
headers?: Value<Promisable<StandardHeaders>, [
|
|
56
56
|
options: ClientOptions<T>,
|
|
57
57
|
path: readonly string[],
|
|
58
58
|
input: unknown
|
|
@@ -71,5 +71,9 @@ declare class StandardOpenapiLinkCodec<T extends ClientContext> implements Stand
|
|
|
71
71
|
|
|
72
72
|
interface StandardOpenAPILinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardOpenapiLinkCodecOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
73
73
|
}
|
|
74
|
+
declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<T> {
|
|
75
|
+
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
|
|
76
|
+
}
|
|
74
77
|
|
|
75
|
-
export {
|
|
78
|
+
export { StandardBracketNotationSerializer as a, StandardOpenAPIJsonSerializer as e, StandardOpenAPILink as g, StandardOpenapiLinkCodec as i, StandardOpenAPISerializer as k };
|
|
79
|
+
export type { StandardBracketNotationSerialized as S, StandardOpenAPIJsonSerialized as b, StandardOpenAPICustomJsonSerializer as c, StandardOpenAPIJsonSerializerOptions as d, StandardOpenAPILinkOptions as f, StandardOpenapiLinkCodecOptions as h, StandardOpenAPISerializeOptions as j };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClientContext, ClientOptions } from '@orpc/client';
|
|
2
|
-
import { StandardLinkCodec, StandardLinkOptions } from '@orpc/client/standard';
|
|
2
|
+
import { StandardLinkCodec, StandardLinkOptions, StandardLink, StandardLinkClient } from '@orpc/client/standard';
|
|
3
3
|
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
-
import { Segment, Value } from '@orpc/shared';
|
|
4
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
5
5
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
6
6
|
|
|
7
7
|
type StandardBracketNotationSerialized = [string, unknown][];
|
|
@@ -44,7 +44,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [
|
|
48
48
|
options: ClientOptions<T>,
|
|
49
49
|
path: readonly string[],
|
|
50
50
|
input: unknown
|
|
@@ -52,7 +52,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
52
52
|
/**
|
|
53
53
|
* Inject headers to the request.
|
|
54
54
|
*/
|
|
55
|
-
headers?: Value<StandardHeaders
|
|
55
|
+
headers?: Value<Promisable<StandardHeaders>, [
|
|
56
56
|
options: ClientOptions<T>,
|
|
57
57
|
path: readonly string[],
|
|
58
58
|
input: unknown
|
|
@@ -71,5 +71,9 @@ declare class StandardOpenapiLinkCodec<T extends ClientContext> implements Stand
|
|
|
71
71
|
|
|
72
72
|
interface StandardOpenAPILinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardOpenapiLinkCodecOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
73
73
|
}
|
|
74
|
+
declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<T> {
|
|
75
|
+
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
|
|
76
|
+
}
|
|
74
77
|
|
|
75
|
-
export {
|
|
78
|
+
export { StandardBracketNotationSerializer as a, StandardOpenAPIJsonSerializer as e, StandardOpenAPILink as g, StandardOpenapiLinkCodec as i, StandardOpenAPISerializer as k };
|
|
79
|
+
export type { StandardBracketNotationSerialized as S, StandardOpenAPIJsonSerialized as b, StandardOpenAPICustomJsonSerializer as c, StandardOpenAPIJsonSerializerOptions as d, StandardOpenAPILinkOptions as f, StandardOpenapiLinkCodecOptions as h, StandardOpenAPISerializeOptions as j };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { toHttpPath, getMalformedResponseErrorCode, StandardLink } from '@orpc/client/standard';
|
|
2
|
+
import { isObject, NullProtoObj, value, get, isAsyncIteratorObject } from '@orpc/shared';
|
|
3
|
+
import { isORPCErrorStatus, isORPCErrorJson, createORPCErrorFromJson, mapEventIterator, toORPCError } from '@orpc/client';
|
|
3
4
|
import { isContractProcedure, fallbackContractConfig, ORPCError } from '@orpc/contract';
|
|
4
5
|
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
5
|
-
import { mapEventIterator, toORPCError, ORPCError as ORPCError$1 } from '@orpc/client';
|
|
6
6
|
|
|
7
7
|
class StandardBracketNotationSerializer {
|
|
8
8
|
serialize(data, segments = [], result = []) {
|
|
@@ -35,19 +35,25 @@ class StandardBracketNotationSerializer {
|
|
|
35
35
|
}
|
|
36
36
|
if (i !== segments.length - 1) {
|
|
37
37
|
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
|
|
38
|
-
currentRef[nextSegment]
|
|
38
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
39
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
40
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
41
|
+
} else {
|
|
42
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
} else {
|
|
41
46
|
if (Array.isArray(currentRef[nextSegment])) {
|
|
42
47
|
if (segment === "") {
|
|
43
48
|
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
44
|
-
currentRef[nextSegment] =
|
|
49
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
45
50
|
}
|
|
46
51
|
} else {
|
|
47
52
|
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
48
|
-
currentRef[nextSegment]
|
|
53
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
54
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
49
55
|
} else if (!isValidArrayIndex(segment)) {
|
|
50
|
-
currentRef[nextSegment] =
|
|
56
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -55,12 +61,14 @@ class StandardBracketNotationSerializer {
|
|
|
55
61
|
currentRef = currentRef[nextSegment];
|
|
56
62
|
nextSegment = segment;
|
|
57
63
|
});
|
|
58
|
-
if (Array.isArray(currentRef)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
if (Array.isArray(currentRef) && nextSegment === "") {
|
|
65
|
+
arrayPushStyles.add(currentRef);
|
|
66
|
+
currentRef.push(value);
|
|
67
|
+
} else if (nextSegment in currentRef) {
|
|
68
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
69
|
+
currentRef[nextSegment].push(value);
|
|
62
70
|
} else {
|
|
63
|
-
currentRef[
|
|
71
|
+
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
64
72
|
}
|
|
65
73
|
} else {
|
|
66
74
|
currentRef[nextSegment] = value;
|
|
@@ -122,6 +130,18 @@ class StandardBracketNotationSerializer {
|
|
|
122
130
|
function isValidArrayIndex(value) {
|
|
123
131
|
return /^0$|^[1-9]\d*$/.test(value);
|
|
124
132
|
}
|
|
133
|
+
function arrayToObject(array) {
|
|
134
|
+
const obj = new NullProtoObj();
|
|
135
|
+
array.forEach((item, i) => {
|
|
136
|
+
obj[i] = item;
|
|
137
|
+
});
|
|
138
|
+
return obj;
|
|
139
|
+
}
|
|
140
|
+
function pushStyleArrayToObject(array) {
|
|
141
|
+
const obj = new NullProtoObj();
|
|
142
|
+
obj[""] = array.length === 1 ? array[0] : array;
|
|
143
|
+
return obj;
|
|
144
|
+
}
|
|
125
145
|
|
|
126
146
|
class StandardOpenAPIJsonSerializer {
|
|
127
147
|
customSerializers;
|
|
@@ -202,7 +222,7 @@ class StandardOpenapiLinkCodec {
|
|
|
202
222
|
throw new Error(`[StandardOpenapiLinkCodec] expect a contract procedure at ${path.join(".")}`);
|
|
203
223
|
}
|
|
204
224
|
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
205
|
-
return inputStructure === "compact" ? this.#encodeCompact(procedure, path, input, options, baseUrl
|
|
225
|
+
return inputStructure === "compact" ? this.#encodeCompact(procedure, path, input, options, baseUrl, headers) : this.#encodeDetailed(procedure, path, input, options, baseUrl, headers);
|
|
206
226
|
}
|
|
207
227
|
#encodeCompact(procedure, path, input, options, baseUrl, headers) {
|
|
208
228
|
let httpPath = standardizeHTTPPath(procedure["~orpc"].route.path ?? toHttpPath(path));
|
|
@@ -221,7 +241,8 @@ class StandardOpenapiLinkCodec {
|
|
|
221
241
|
httpBody = Object.keys(body).length ? body : void 0;
|
|
222
242
|
}
|
|
223
243
|
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
224
|
-
const url = new URL(
|
|
244
|
+
const url = new URL(baseUrl);
|
|
245
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${httpPath}`;
|
|
225
246
|
if (method === "GET") {
|
|
226
247
|
const serialized = this.serializer.serialize(httpBody, { outputFormat: "URLSearchParams" });
|
|
227
248
|
for (const [key, value2] of serialized) {
|
|
@@ -266,7 +287,8 @@ class StandardOpenapiLinkCodec {
|
|
|
266
287
|
mergedHeaders = mergeStandardHeaders(input.headers, headers);
|
|
267
288
|
}
|
|
268
289
|
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
269
|
-
const url = new URL(
|
|
290
|
+
const url = new URL(baseUrl);
|
|
291
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${httpPath}`;
|
|
270
292
|
if (input?.query !== void 0) {
|
|
271
293
|
const query = this.serializer.serialize(input.query, { outputFormat: "URLSearchParams" });
|
|
272
294
|
for (const [key, value2] of query) {
|
|
@@ -291,7 +313,7 @@ class StandardOpenapiLinkCodec {
|
|
|
291
313
|
};
|
|
292
314
|
}
|
|
293
315
|
async decode(response, _options, path) {
|
|
294
|
-
const isOk = response.status
|
|
316
|
+
const isOk = !isORPCErrorStatus(response.status);
|
|
295
317
|
const deserialized = await (async () => {
|
|
296
318
|
let isBodyOk = false;
|
|
297
319
|
try {
|
|
@@ -310,12 +332,12 @@ class StandardOpenapiLinkCodec {
|
|
|
310
332
|
}
|
|
311
333
|
})();
|
|
312
334
|
if (!isOk) {
|
|
313
|
-
if (
|
|
314
|
-
throw
|
|
335
|
+
if (isORPCErrorJson(deserialized)) {
|
|
336
|
+
throw createORPCErrorFromJson(deserialized);
|
|
315
337
|
}
|
|
316
|
-
throw new ORPCError(
|
|
338
|
+
throw new ORPCError(getMalformedResponseErrorCode(response.status), {
|
|
317
339
|
status: response.status,
|
|
318
|
-
data: deserialized
|
|
340
|
+
data: { ...response, body: deserialized }
|
|
319
341
|
});
|
|
320
342
|
}
|
|
321
343
|
const procedure = get(this.contract, path);
|
|
@@ -327,6 +349,7 @@ class StandardOpenapiLinkCodec {
|
|
|
327
349
|
return deserialized;
|
|
328
350
|
}
|
|
329
351
|
return {
|
|
352
|
+
status: response.status,
|
|
330
353
|
headers: response.headers,
|
|
331
354
|
body: deserialized
|
|
332
355
|
};
|
|
@@ -387,8 +410,8 @@ class StandardOpenAPISerializer {
|
|
|
387
410
|
return mapEventIterator(data, {
|
|
388
411
|
value: async (value) => value,
|
|
389
412
|
error: async (e) => {
|
|
390
|
-
if (e instanceof ErrorEvent &&
|
|
391
|
-
return
|
|
413
|
+
if (e instanceof ErrorEvent && isORPCErrorJson(e.data)) {
|
|
414
|
+
return createORPCErrorFromJson(e.data, { cause: e });
|
|
392
415
|
}
|
|
393
416
|
return e;
|
|
394
417
|
}
|
|
@@ -398,4 +421,14 @@ class StandardOpenAPISerializer {
|
|
|
398
421
|
}
|
|
399
422
|
}
|
|
400
423
|
|
|
401
|
-
|
|
424
|
+
class StandardOpenAPILink extends StandardLink {
|
|
425
|
+
constructor(contract, linkClient, options) {
|
|
426
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
427
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
428
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
429
|
+
const linkCodec = new StandardOpenapiLinkCodec(contract, serializer, options);
|
|
430
|
+
super(linkCodec, linkClient, options);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export { StandardBracketNotationSerializer as S, StandardOpenAPIJsonSerializer as a, StandardOpenAPILink as b, StandardOpenapiLinkCodec as c, StandardOpenAPISerializer as d, getDynamicParams as g, standardizeHTTPPath as s };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi-client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.bf3438f",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@orpc/client": "0.0.0-next.
|
|
38
|
-
"@orpc/
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
37
|
+
"@orpc/client": "0.0.0-next.bf3438f",
|
|
38
|
+
"@orpc/standard-server": "0.0.0-next.bf3438f",
|
|
39
|
+
"@orpc/shared": "0.0.0-next.bf3438f",
|
|
40
|
+
"@orpc/contract": "0.0.0-next.bf3438f"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@orpc/server": "0.0.0-next.
|
|
43
|
+
"@orpc/server": "0.0.0-next.bf3438f"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "unbuild",
|