@orpc/openapi-client 0.0.0-next.7c4acaa → 0.0.0-next.7ccd703
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 +7 -7
- package/dist/adapters/fetch/index.d.mts +1 -1
- package/dist/adapters/fetch/index.d.ts +1 -1
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/standard/index.d.mts +55 -2
- package/dist/adapters/standard/index.d.ts +55 -2
- package/dist/adapters/standard/index.mjs +40 -3
- package/dist/shared/{openapi-client.D89vdV2Y.mjs → openapi-client.D3eD5ojB.mjs} +40 -15
- package/dist/shared/{openapi-client.D_hC2pAM.d.mts → openapi-client.f2unmElJ.d.mts} +23 -5
- package/dist/shared/{openapi-client.D_hC2pAM.d.ts → openapi-client.f2unmElJ.d.ts} +23 -5
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
42
|
|
|
43
43
|
## Documentation
|
|
44
44
|
|
|
@@ -49,13 +49,13 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
54
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
52
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
53
|
-
- [@orpc/
|
|
54
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
55
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
56
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
56
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
57
57
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
58
|
-
- [@orpc/
|
|
58
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
59
59
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
60
60
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
61
61
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
3
3
|
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
-
import {
|
|
4
|
+
import { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.f2unmElJ.mjs';
|
|
5
5
|
import '@orpc/client/standard';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@orpc/standard-server';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { LinkFetchClientOptions } from '@orpc/client/fetch';
|
|
3
3
|
import { AnyContractRouter } from '@orpc/contract';
|
|
4
|
-
import {
|
|
4
|
+
import { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.f2unmElJ.js';
|
|
5
5
|
import '@orpc/client/standard';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@orpc/standard-server';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { LinkFetchClient } from '@orpc/client/fetch';
|
|
2
2
|
import '@orpc/shared';
|
|
3
|
-
import
|
|
3
|
+
import '@orpc/contract';
|
|
4
|
+
import { b as StandardOpenAPILink } from '../../shared/openapi-client.D3eD5ojB.mjs';
|
|
4
5
|
import '@orpc/client';
|
|
5
6
|
import '@orpc/client/standard';
|
|
6
|
-
import '@orpc/contract';
|
|
7
7
|
import '@orpc/standard-server';
|
|
8
8
|
|
|
9
9
|
class OpenAPILink extends StandardOpenAPILink {
|
|
@@ -1,10 +1,63 @@
|
|
|
1
|
-
export { S as StandardBracketNotationSerialized,
|
|
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.f2unmElJ.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,
|
|
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.f2unmElJ.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
|
-
|
|
1
|
+
import { S as StandardBracketNotationSerializer } from '../../shared/openapi-client.D3eD5ojB.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.D3eD5ojB.mjs';
|
|
3
|
+
import { isSchemaIssue } from '@orpc/contract';
|
|
4
|
+
import { isTypescriptObject } from '@orpc/shared';
|
|
2
5
|
import '@orpc/client/standard';
|
|
3
|
-
import '@orpc/shared';
|
|
4
6
|
import '@orpc/client';
|
|
5
|
-
import '@orpc/contract';
|
|
6
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 };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { toHttpPath, getMalformedResponseErrorCode, StandardLink } from '@orpc/client/standard';
|
|
2
|
-
import { isObject, value, get, isAsyncIteratorObject } from '@orpc/shared';
|
|
2
|
+
import { isObject, NullProtoObj, value, get, isAsyncIteratorObject } from '@orpc/shared';
|
|
3
3
|
import { isORPCErrorStatus, isORPCErrorJson, createORPCErrorFromJson, mapEventIterator, toORPCError } from '@orpc/client';
|
|
4
4
|
import { isContractProcedure, fallbackContractConfig, ORPCError } from '@orpc/contract';
|
|
5
5
|
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
6
6
|
|
|
7
7
|
class StandardBracketNotationSerializer {
|
|
8
|
+
maxArrayIndex;
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.maxArrayIndex = options.maxBracketNotationArrayIndex ?? 9999;
|
|
11
|
+
}
|
|
8
12
|
serialize(data, segments = [], result = []) {
|
|
9
13
|
if (Array.isArray(data)) {
|
|
10
14
|
data.forEach((item, i) => {
|
|
@@ -34,20 +38,26 @@ class StandardBracketNotationSerializer {
|
|
|
34
38
|
currentRef[nextSegment] = [];
|
|
35
39
|
}
|
|
36
40
|
if (i !== segments.length - 1) {
|
|
37
|
-
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
|
|
38
|
-
currentRef[nextSegment]
|
|
41
|
+
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
42
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
43
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
44
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
45
|
+
} else {
|
|
46
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
49
|
} else {
|
|
41
50
|
if (Array.isArray(currentRef[nextSegment])) {
|
|
42
51
|
if (segment === "") {
|
|
43
52
|
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
44
|
-
currentRef[nextSegment] =
|
|
53
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
45
54
|
}
|
|
46
55
|
} else {
|
|
47
56
|
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
48
|
-
currentRef[nextSegment]
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
58
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
59
|
+
} else if (!isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
60
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
}
|
|
@@ -55,12 +65,14 @@ class StandardBracketNotationSerializer {
|
|
|
55
65
|
currentRef = currentRef[nextSegment];
|
|
56
66
|
nextSegment = segment;
|
|
57
67
|
});
|
|
58
|
-
if (Array.isArray(currentRef)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
if (Array.isArray(currentRef) && nextSegment === "") {
|
|
69
|
+
arrayPushStyles.add(currentRef);
|
|
70
|
+
currentRef.push(value);
|
|
71
|
+
} else if (nextSegment in currentRef) {
|
|
72
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
73
|
+
currentRef[nextSegment].push(value);
|
|
62
74
|
} else {
|
|
63
|
-
currentRef[
|
|
75
|
+
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
64
76
|
}
|
|
65
77
|
} else {
|
|
66
78
|
currentRef[nextSegment] = value;
|
|
@@ -119,8 +131,20 @@ class StandardBracketNotationSerializer {
|
|
|
119
131
|
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
120
132
|
}
|
|
121
133
|
}
|
|
122
|
-
function isValidArrayIndex(value) {
|
|
123
|
-
return /^0$|^[1-9]\d*$/.test(value);
|
|
134
|
+
function isValidArrayIndex(value, maxIndex) {
|
|
135
|
+
return /^0$|^[1-9]\d*$/.test(value) && Number(value) <= maxIndex;
|
|
136
|
+
}
|
|
137
|
+
function arrayToObject(array) {
|
|
138
|
+
const obj = new NullProtoObj();
|
|
139
|
+
array.forEach((item, i) => {
|
|
140
|
+
obj[i] = item;
|
|
141
|
+
});
|
|
142
|
+
return obj;
|
|
143
|
+
}
|
|
144
|
+
function pushStyleArrayToObject(array) {
|
|
145
|
+
const obj = new NullProtoObj();
|
|
146
|
+
obj[""] = array.length === 1 ? array[0] : array;
|
|
147
|
+
return obj;
|
|
124
148
|
}
|
|
125
149
|
|
|
126
150
|
class StandardOpenAPIJsonSerializer {
|
|
@@ -329,6 +353,7 @@ class StandardOpenapiLinkCodec {
|
|
|
329
353
|
return deserialized;
|
|
330
354
|
}
|
|
331
355
|
return {
|
|
356
|
+
status: response.status,
|
|
332
357
|
headers: response.headers,
|
|
333
358
|
body: deserialized
|
|
334
359
|
};
|
|
@@ -403,7 +428,7 @@ class StandardOpenAPISerializer {
|
|
|
403
428
|
class StandardOpenAPILink extends StandardLink {
|
|
404
429
|
constructor(contract, linkClient, options) {
|
|
405
430
|
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
406
|
-
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
431
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer({ maxBracketNotationArrayIndex: 4294967294 });
|
|
407
432
|
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
408
433
|
const linkCodec = new StandardOpenapiLinkCodec(contract, serializer, options);
|
|
409
434
|
super(linkCodec, linkClient, options);
|
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { ClientContext, ClientOptions } from '@orpc/client';
|
|
2
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][];
|
|
8
|
+
interface StandardBracketNotationSerializerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Maximum allowed array index for bracket notation deserialization.
|
|
11
|
+
*
|
|
12
|
+
* This helps protect against memory exhaustion attacks where malicious input
|
|
13
|
+
* uses extremely large array indices (e.g., `?arr[4294967296]=value`).
|
|
14
|
+
*
|
|
15
|
+
* While bracket notation creates sparse arrays that handle large indices efficiently,
|
|
16
|
+
* downstream code might inadvertently convert these sparse arrays to dense arrays,
|
|
17
|
+
* potentially creating millions of undefined elements and causing memory issues.
|
|
18
|
+
*
|
|
19
|
+
* @note Only applies to deserialization.
|
|
20
|
+
* @default 9_999 (array with 10,000 elements)
|
|
21
|
+
*/
|
|
22
|
+
maxBracketNotationArrayIndex?: number;
|
|
23
|
+
}
|
|
8
24
|
declare class StandardBracketNotationSerializer {
|
|
25
|
+
private readonly maxArrayIndex;
|
|
26
|
+
constructor(options?: StandardBracketNotationSerializerOptions);
|
|
9
27
|
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
|
|
10
28
|
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
|
|
11
29
|
stringifyPath(segments: readonly Segment[]): string;
|
|
@@ -44,7 +62,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
44
62
|
/**
|
|
45
63
|
* Base url for all requests.
|
|
46
64
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
65
|
+
url: Value<Promisable<string | URL>, [
|
|
48
66
|
options: ClientOptions<T>,
|
|
49
67
|
path: readonly string[],
|
|
50
68
|
input: unknown
|
|
@@ -52,7 +70,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
52
70
|
/**
|
|
53
71
|
* Inject headers to the request.
|
|
54
72
|
*/
|
|
55
|
-
headers?: Value<StandardHeaders
|
|
73
|
+
headers?: Value<Promisable<StandardHeaders>, [
|
|
56
74
|
options: ClientOptions<T>,
|
|
57
75
|
path: readonly string[],
|
|
58
76
|
input: unknown
|
|
@@ -75,5 +93,5 @@ declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<
|
|
|
75
93
|
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
|
|
76
94
|
}
|
|
77
95
|
|
|
78
|
-
export { StandardBracketNotationSerializer as
|
|
79
|
-
export type { StandardBracketNotationSerialized as S, StandardOpenAPIJsonSerialized as
|
|
96
|
+
export { StandardBracketNotationSerializer as b, StandardOpenAPIJsonSerializer as f, StandardOpenAPILink as h, StandardOpenapiLinkCodec as j, StandardOpenAPISerializer as l };
|
|
97
|
+
export type { StandardBracketNotationSerialized as S, StandardBracketNotationSerializerOptions as a, StandardOpenAPIJsonSerialized as c, StandardOpenAPICustomJsonSerializer as d, StandardOpenAPIJsonSerializerOptions as e, StandardOpenAPILinkOptions as g, StandardOpenapiLinkCodecOptions as i, StandardOpenAPISerializeOptions as k };
|
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { ClientContext, ClientOptions } from '@orpc/client';
|
|
2
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][];
|
|
8
|
+
interface StandardBracketNotationSerializerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Maximum allowed array index for bracket notation deserialization.
|
|
11
|
+
*
|
|
12
|
+
* This helps protect against memory exhaustion attacks where malicious input
|
|
13
|
+
* uses extremely large array indices (e.g., `?arr[4294967296]=value`).
|
|
14
|
+
*
|
|
15
|
+
* While bracket notation creates sparse arrays that handle large indices efficiently,
|
|
16
|
+
* downstream code might inadvertently convert these sparse arrays to dense arrays,
|
|
17
|
+
* potentially creating millions of undefined elements and causing memory issues.
|
|
18
|
+
*
|
|
19
|
+
* @note Only applies to deserialization.
|
|
20
|
+
* @default 9_999 (array with 10,000 elements)
|
|
21
|
+
*/
|
|
22
|
+
maxBracketNotationArrayIndex?: number;
|
|
23
|
+
}
|
|
8
24
|
declare class StandardBracketNotationSerializer {
|
|
25
|
+
private readonly maxArrayIndex;
|
|
26
|
+
constructor(options?: StandardBracketNotationSerializerOptions);
|
|
9
27
|
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
|
|
10
28
|
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
|
|
11
29
|
stringifyPath(segments: readonly Segment[]): string;
|
|
@@ -44,7 +62,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
44
62
|
/**
|
|
45
63
|
* Base url for all requests.
|
|
46
64
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
65
|
+
url: Value<Promisable<string | URL>, [
|
|
48
66
|
options: ClientOptions<T>,
|
|
49
67
|
path: readonly string[],
|
|
50
68
|
input: unknown
|
|
@@ -52,7 +70,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
52
70
|
/**
|
|
53
71
|
* Inject headers to the request.
|
|
54
72
|
*/
|
|
55
|
-
headers?: Value<StandardHeaders
|
|
73
|
+
headers?: Value<Promisable<StandardHeaders>, [
|
|
56
74
|
options: ClientOptions<T>,
|
|
57
75
|
path: readonly string[],
|
|
58
76
|
input: unknown
|
|
@@ -75,5 +93,5 @@ declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<
|
|
|
75
93
|
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
|
|
76
94
|
}
|
|
77
95
|
|
|
78
|
-
export { StandardBracketNotationSerializer as
|
|
79
|
-
export type { StandardBracketNotationSerialized as S, StandardOpenAPIJsonSerialized as
|
|
96
|
+
export { StandardBracketNotationSerializer as b, StandardOpenAPIJsonSerializer as f, StandardOpenAPILink as h, StandardOpenapiLinkCodec as j, StandardOpenAPISerializer as l };
|
|
97
|
+
export type { StandardBracketNotationSerialized as S, StandardBracketNotationSerializerOptions as a, StandardOpenAPIJsonSerialized as c, StandardOpenAPICustomJsonSerializer as d, StandardOpenAPIJsonSerializerOptions as e, StandardOpenAPILinkOptions as g, StandardOpenapiLinkCodecOptions as i, StandardOpenAPISerializeOptions as k };
|
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.7ccd703",
|
|
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/contract": "0.0.0-next.
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
37
|
+
"@orpc/client": "0.0.0-next.7ccd703",
|
|
38
|
+
"@orpc/contract": "0.0.0-next.7ccd703",
|
|
39
|
+
"@orpc/standard-server": "0.0.0-next.7ccd703",
|
|
40
|
+
"@orpc/shared": "0.0.0-next.7ccd703"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@orpc/server": "0.0.0-next.
|
|
43
|
+
"@orpc/server": "0.0.0-next.7ccd703"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "unbuild",
|