@orpc/openapi-client 0.0.0-next.df024bb → 0.0.0-next.df70448
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 +33 -20
- package/dist/adapters/fetch/index.d.mts +22 -0
- package/dist/adapters/fetch/index.d.ts +22 -0
- package/dist/adapters/fetch/index.mjs +17 -0
- package/dist/adapters/standard/index.d.mts +19 -25
- package/dist/adapters/standard/index.d.ts +19 -25
- package/dist/adapters/standard/index.mjs +8 -216
- package/dist/helpers/index.d.mts +54 -0
- package/dist/helpers/index.d.ts +54 -0
- package/dist/helpers/index.mjs +7 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/shared/openapi-client.Cv0hBP4Y.d.mts +97 -0
- package/dist/shared/openapi-client.Cv0hBP4Y.d.ts +97 -0
- package/dist/shared/openapi-client.Dgl8z2tb.mjs +39 -0
- package/dist/shared/openapi-client.InKGcjFv.mjs +296 -0
- package/dist/shared/openapi-client.t9fCAe3x.mjs +146 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -17,32 +17,31 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
26
|
|
|
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
|
|
27
|
+
**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
28
|
|
|
26
29
|
---
|
|
27
30
|
|
|
28
31
|
## Highlights
|
|
29
32
|
|
|
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.
|
|
33
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
34
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
35
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
36
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
38
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
39
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
40
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
41
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
42
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
43
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
44
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
46
45
|
|
|
47
46
|
## Documentation
|
|
48
47
|
|
|
@@ -53,16 +52,30 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
52
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
54
|
- [@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/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
55
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
57
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
58
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
59
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
61
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
62
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
60
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
64
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
65
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
61
66
|
|
|
62
67
|
## `@orpc/openapi-client`
|
|
63
68
|
|
|
64
69
|
Provides core serializer for OpenAPI requests and responses.
|
|
65
70
|
|
|
71
|
+
## Sponsors
|
|
72
|
+
|
|
73
|
+
<p align="center">
|
|
74
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
75
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
76
|
+
</a>
|
|
77
|
+
</p>
|
|
78
|
+
|
|
66
79
|
## License
|
|
67
80
|
|
|
68
81
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClientContext } from '@orpc/client';
|
|
2
|
+
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
3
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
+
import { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.Cv0hBP4Y.mjs';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
|
+
import '@orpc/shared';
|
|
7
|
+
import '@orpc/standard-server';
|
|
8
|
+
|
|
9
|
+
interface OpenAPILinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardOpenAPILinkOptions<T>, 'plugins'> {
|
|
10
|
+
}
|
|
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> {
|
|
18
|
+
constructor(contract: AnyContractRouter, options: OpenAPILinkOptions<T>);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { OpenAPILink };
|
|
22
|
+
export type { OpenAPILinkOptions };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClientContext } from '@orpc/client';
|
|
2
|
+
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
3
|
+
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
+
import { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.Cv0hBP4Y.js';
|
|
5
|
+
import '@orpc/client/standard';
|
|
6
|
+
import '@orpc/shared';
|
|
7
|
+
import '@orpc/standard-server';
|
|
8
|
+
|
|
9
|
+
interface OpenAPILinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardOpenAPILinkOptions<T>, 'plugins'> {
|
|
10
|
+
}
|
|
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> {
|
|
18
|
+
constructor(contract: AnyContractRouter, options: OpenAPILinkOptions<T>);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { OpenAPILink };
|
|
22
|
+
export type { OpenAPILinkOptions };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LinkFetchClient } from '@orpc/client/fetch';
|
|
2
|
+
import '@orpc/shared';
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import { a as StandardOpenAPILink } from '../../shared/openapi-client.InKGcjFv.mjs';
|
|
5
|
+
import '@orpc/client';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/standard-server';
|
|
8
|
+
import '../../shared/openapi-client.t9fCAe3x.mjs';
|
|
9
|
+
|
|
10
|
+
class OpenAPILink extends StandardOpenAPILink {
|
|
11
|
+
constructor(contract, options) {
|
|
12
|
+
const linkClient = new LinkFetchClient(options);
|
|
13
|
+
super(contract, linkClient, options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { OpenAPILink };
|
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
export { S as StandardBracketNotationSerialized, b as StandardBracketNotationSerializer, a as StandardBracketNotationSerializerOptions, d as StandardOpenAPICustomJsonSerializer, c as StandardOpenAPIJsonSerialized, f as StandardOpenAPIJsonSerializer, e as StandardOpenAPIJsonSerializerOptions, h as StandardOpenAPILink, g as StandardOpenAPILinkOptions, k as StandardOpenAPISerializeOptions, l as StandardOpenAPISerializer, j as StandardOpenapiLinkCodec, i as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.Cv0hBP4Y.mjs';
|
|
2
|
+
export { getIssueMessage, parseFormData } from '../../helpers/index.mjs';
|
|
3
|
+
import { HTTPPath } from '@orpc/client';
|
|
4
|
+
import '@orpc/client/standard';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/shared';
|
|
7
|
+
import '@orpc/standard-server';
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
17
|
+
raw: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}[] | undefined;
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
declare class OpenAPIJsonSerializer {
|
|
13
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
14
|
-
value: boolean;
|
|
15
|
-
}): OpenAPIJsonSerialized;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare class OpenAPISerializer {
|
|
19
|
-
#private;
|
|
20
|
-
private readonly jsonSerializer;
|
|
21
|
-
private readonly bracketNotation;
|
|
22
|
-
constructor(jsonSerializer?: OpenAPIJsonSerializer, bracketNotation?: BracketNotationSerializer);
|
|
23
|
-
serialize(data: unknown): unknown;
|
|
24
|
-
deserialize(data: unknown): unknown;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { type BracketNotationSerialized, BracketNotationSerializer, type OpenAPIJsonSerialized, OpenAPIJsonSerializer, OpenAPISerializer };
|
|
21
|
+
export { getDynamicParams, standardizeHTTPPath };
|
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
export { S as StandardBracketNotationSerialized, b as StandardBracketNotationSerializer, a as StandardBracketNotationSerializerOptions, d as StandardOpenAPICustomJsonSerializer, c as StandardOpenAPIJsonSerialized, f as StandardOpenAPIJsonSerializer, e as StandardOpenAPIJsonSerializerOptions, h as StandardOpenAPILink, g as StandardOpenAPILinkOptions, k as StandardOpenAPISerializeOptions, l as StandardOpenAPISerializer, j as StandardOpenapiLinkCodec, i as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.Cv0hBP4Y.js';
|
|
2
|
+
export { getIssueMessage, parseFormData } from '../../helpers/index.js';
|
|
3
|
+
import { HTTPPath } from '@orpc/client';
|
|
4
|
+
import '@orpc/client/standard';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/shared';
|
|
7
|
+
import '@orpc/standard-server';
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
17
|
+
raw: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}[] | undefined;
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
declare class OpenAPIJsonSerializer {
|
|
13
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
14
|
-
value: boolean;
|
|
15
|
-
}): OpenAPIJsonSerialized;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare class OpenAPISerializer {
|
|
19
|
-
#private;
|
|
20
|
-
private readonly jsonSerializer;
|
|
21
|
-
private readonly bracketNotation;
|
|
22
|
-
constructor(jsonSerializer?: OpenAPIJsonSerializer, bracketNotation?: BracketNotationSerializer);
|
|
23
|
-
serialize(data: unknown): unknown;
|
|
24
|
-
deserialize(data: unknown): unknown;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { type BracketNotationSerialized, BracketNotationSerializer, type OpenAPIJsonSerialized, OpenAPIJsonSerializer, OpenAPISerializer };
|
|
21
|
+
export { getDynamicParams, standardizeHTTPPath };
|
|
@@ -1,216 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.serialize(item, [...segments, i], result);
|
|
10
|
-
});
|
|
11
|
-
} else if (isObject(data)) {
|
|
12
|
-
for (const key in data) {
|
|
13
|
-
this.serialize(data[key], [...segments, key], result);
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
result.push([this.stringifyPath(segments), data]);
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
deserialize(serialized) {
|
|
21
|
-
if (serialized.length === 0) {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
24
|
-
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
25
|
-
const ref = { value: [] };
|
|
26
|
-
for (const [path, value] of serialized) {
|
|
27
|
-
const segments = this.parsePath(path);
|
|
28
|
-
let currentRef = ref;
|
|
29
|
-
let nextSegment = "value";
|
|
30
|
-
segments.forEach((segment, i) => {
|
|
31
|
-
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
32
|
-
currentRef[nextSegment] = [];
|
|
33
|
-
}
|
|
34
|
-
if (i !== segments.length - 1) {
|
|
35
|
-
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
|
|
36
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
if (Array.isArray(currentRef[nextSegment])) {
|
|
40
|
-
if (segment === "") {
|
|
41
|
-
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
42
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
46
|
-
currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
|
|
47
|
-
} else if (!isValidArrayIndex(segment)) {
|
|
48
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
currentRef = currentRef[nextSegment];
|
|
54
|
-
nextSegment = segment;
|
|
55
|
-
});
|
|
56
|
-
if (Array.isArray(currentRef)) {
|
|
57
|
-
if (nextSegment === "") {
|
|
58
|
-
arrayPushStyles.add(currentRef);
|
|
59
|
-
currentRef.push(value);
|
|
60
|
-
} else {
|
|
61
|
-
currentRef[Number(nextSegment)] = value;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
currentRef[nextSegment] = value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return ref.value;
|
|
68
|
-
}
|
|
69
|
-
stringifyPath(segments) {
|
|
70
|
-
return segments.map((segment) => {
|
|
71
|
-
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
72
|
-
switch (match) {
|
|
73
|
-
case "\\":
|
|
74
|
-
return "\\\\";
|
|
75
|
-
case "[":
|
|
76
|
-
return "\\[";
|
|
77
|
-
case "]":
|
|
78
|
-
return "\\]";
|
|
79
|
-
/* v8 ignore next 2 */
|
|
80
|
-
default:
|
|
81
|
-
return match;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}).reduce((result, segment, i) => {
|
|
85
|
-
if (i === 0) {
|
|
86
|
-
return segment;
|
|
87
|
-
}
|
|
88
|
-
return `${result}[${segment}]`;
|
|
89
|
-
}, "");
|
|
90
|
-
}
|
|
91
|
-
parsePath(path) {
|
|
92
|
-
const segments = [];
|
|
93
|
-
let inBrackets = false;
|
|
94
|
-
let currentSegment = "";
|
|
95
|
-
let backslashCount = 0;
|
|
96
|
-
for (let i = 0; i < path.length; i++) {
|
|
97
|
-
const char = path[i];
|
|
98
|
-
const nextChar = path[i + 1];
|
|
99
|
-
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
100
|
-
if (nextChar === void 0) {
|
|
101
|
-
inBrackets = false;
|
|
102
|
-
}
|
|
103
|
-
segments.push(currentSegment);
|
|
104
|
-
currentSegment = "";
|
|
105
|
-
i++;
|
|
106
|
-
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
107
|
-
inBrackets = true;
|
|
108
|
-
segments.push(currentSegment);
|
|
109
|
-
currentSegment = "";
|
|
110
|
-
} else if (char === "\\") {
|
|
111
|
-
backslashCount++;
|
|
112
|
-
} else {
|
|
113
|
-
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
114
|
-
backslashCount = 0;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function isValidArrayIndex(value) {
|
|
121
|
-
return /^0$|^[1-9]\d*$/.test(value);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
class OpenAPIJsonSerializer {
|
|
125
|
-
serialize(data, hasBlobRef = { value: false }) {
|
|
126
|
-
if (data instanceof Blob) {
|
|
127
|
-
hasBlobRef.value = true;
|
|
128
|
-
return [data, hasBlobRef.value];
|
|
129
|
-
}
|
|
130
|
-
if (data instanceof Set) {
|
|
131
|
-
return this.serialize(Array.from(data), hasBlobRef);
|
|
132
|
-
}
|
|
133
|
-
if (data instanceof Map) {
|
|
134
|
-
return this.serialize(Array.from(data.entries()), hasBlobRef);
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(data)) {
|
|
137
|
-
const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
|
|
138
|
-
return [json, hasBlobRef.value];
|
|
139
|
-
}
|
|
140
|
-
if (isObject(data)) {
|
|
141
|
-
const json = {};
|
|
142
|
-
for (const k in data) {
|
|
143
|
-
json[k] = this.serialize(data[k], hasBlobRef)[0];
|
|
144
|
-
}
|
|
145
|
-
return [json, hasBlobRef.value];
|
|
146
|
-
}
|
|
147
|
-
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
148
|
-
return [data.toString(), hasBlobRef.value];
|
|
149
|
-
}
|
|
150
|
-
if (data instanceof Date) {
|
|
151
|
-
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
152
|
-
}
|
|
153
|
-
if (Number.isNaN(data)) {
|
|
154
|
-
return [null, hasBlobRef.value];
|
|
155
|
-
}
|
|
156
|
-
return [data, hasBlobRef.value];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
class OpenAPISerializer {
|
|
161
|
-
constructor(jsonSerializer = new OpenAPIJsonSerializer(), bracketNotation = new BracketNotationSerializer()) {
|
|
162
|
-
this.jsonSerializer = jsonSerializer;
|
|
163
|
-
this.bracketNotation = bracketNotation;
|
|
164
|
-
}
|
|
165
|
-
serialize(data) {
|
|
166
|
-
if (isAsyncIteratorObject(data)) {
|
|
167
|
-
return mapEventIterator(data, {
|
|
168
|
-
value: async (value) => this.#serialize(value, false),
|
|
169
|
-
error: async (e) => {
|
|
170
|
-
return new ErrorEvent({
|
|
171
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
|
172
|
-
cause: e
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return this.#serialize(data, true);
|
|
178
|
-
}
|
|
179
|
-
#serialize(data, enableFormData) {
|
|
180
|
-
if (data instanceof Blob || data === void 0) {
|
|
181
|
-
return data;
|
|
182
|
-
}
|
|
183
|
-
const [json, hasBlob] = this.jsonSerializer.serialize(data);
|
|
184
|
-
if (!enableFormData || !hasBlob) {
|
|
185
|
-
return json;
|
|
186
|
-
}
|
|
187
|
-
const form = new FormData();
|
|
188
|
-
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
189
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
190
|
-
form.append(path, value.toString());
|
|
191
|
-
} else if (value instanceof Blob) {
|
|
192
|
-
form.append(path, value);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return form;
|
|
196
|
-
}
|
|
197
|
-
deserialize(data) {
|
|
198
|
-
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
199
|
-
return this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
200
|
-
}
|
|
201
|
-
if (isAsyncIteratorObject(data)) {
|
|
202
|
-
return mapEventIterator(data, {
|
|
203
|
-
value: async (value) => value,
|
|
204
|
-
error: async (e) => {
|
|
205
|
-
if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
|
|
206
|
-
return ORPCError.fromJSON(e.data, { cause: e });
|
|
207
|
-
}
|
|
208
|
-
return e;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
return data;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export { BracketNotationSerializer, OpenAPIJsonSerializer, OpenAPISerializer };
|
|
1
|
+
export { S as StandardBracketNotationSerializer } from '../../shared/openapi-client.t9fCAe3x.mjs';
|
|
2
|
+
export { g as getIssueMessage, p as parseFormData } from '../../shared/openapi-client.Dgl8z2tb.mjs';
|
|
3
|
+
export { S as StandardOpenAPIJsonSerializer, a as StandardOpenAPILink, c as StandardOpenAPISerializer, b as StandardOpenapiLinkCodec, g as getDynamicParams, s as standardizeHTTPPath } from '../../shared/openapi-client.InKGcjFv.mjs';
|
|
4
|
+
import '@orpc/shared';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/client';
|
|
8
|
+
import '@orpc/standard-server';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parse a form data with bracket notation
|
|
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
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
|
|
28
|
+
*/
|
|
29
|
+
declare function parseFormData(form: FormData): any;
|
|
30
|
+
/**
|
|
31
|
+
* Get the issue message from the error.
|
|
32
|
+
*
|
|
33
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
34
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.unnoq.com/docs/openapi/bracket-notation)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
39
|
+
*
|
|
40
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
41
|
+
* <input name="user[name]" type="text" />
|
|
42
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
43
|
+
*
|
|
44
|
+
* <input name="user[age]" type="number" />
|
|
45
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
46
|
+
*
|
|
47
|
+
* <input name="images[]" type="file" />
|
|
48
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
49
|
+
* </form>
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
53
|
+
|
|
54
|
+
export { getIssueMessage, parseFormData };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parse a form data with bracket notation
|
|
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
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
|
|
28
|
+
*/
|
|
29
|
+
declare function parseFormData(form: FormData): any;
|
|
30
|
+
/**
|
|
31
|
+
* Get the issue message from the error.
|
|
32
|
+
*
|
|
33
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
34
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.unnoq.com/docs/openapi/bracket-notation)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
39
|
+
*
|
|
40
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
41
|
+
* <input name="user[name]" type="text" />
|
|
42
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
43
|
+
*
|
|
44
|
+
* <input name="user[age]" type="number" />
|
|
45
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
46
|
+
*
|
|
47
|
+
* <input name="images[]" type="file" />
|
|
48
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
49
|
+
* </form>
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
53
|
+
|
|
54
|
+
export { getIssueMessage, parseFormData };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import '@orpc/shared';
|
|
2
|
+
export { g as getIssueMessage, p as parseFormData } from '../shared/openapi-client.Dgl8z2tb.mjs';
|
|
3
|
+
import '@orpc/client/standard';
|
|
4
|
+
import '@orpc/client';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/standard-server';
|
|
7
|
+
import '../shared/openapi-client.t9fCAe3x.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
import { NestedClient, Client, ORPCError } from '@orpc/client';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
4
|
+
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
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
|
+
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
|
+
*/
|
|
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> : {
|
|
13
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type { JsonifiedArray, JsonifiedClient, JsonifiedValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
import { NestedClient, Client, ORPCError } from '@orpc/client';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
4
|
+
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
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
|
+
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
|
+
*/
|
|
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> : {
|
|
13
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type { JsonifiedArray, JsonifiedClient, JsonifiedValue };
|