@orpc/openapi-client 1.8.5 → 1.8.7
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/dist/adapters/fetch/index.d.mts +1 -1
- package/dist/adapters/fetch/index.d.ts +1 -1
- package/dist/adapters/fetch/index.mjs +2 -1
- package/dist/adapters/standard/index.d.mts +3 -55
- package/dist/adapters/standard/index.d.ts +3 -55
- package/dist/adapters/standard/index.mjs +5 -40
- 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/shared/{openapi-client.f2unmElJ.d.mts → openapi-client.Cv0hBP4Y.d.mts} +1 -1
- package/dist/shared/{openapi-client.f2unmElJ.d.ts → openapi-client.Cv0hBP4Y.d.ts} +1 -1
- package/dist/shared/openapi-client.Dgl8z2tb.mjs +39 -0
- package/dist/shared/{openapi-client.D3eD5ojB.mjs → openapi-client.InKGcjFv.mjs} +6 -148
- package/dist/shared/openapi-client.t9fCAe3x.mjs +146 -0
- package/package.json +11 -6
|
@@ -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 { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.
|
|
4
|
+
import { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.Cv0hBP4Y.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 { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.
|
|
4
|
+
import { g as StandardOpenAPILinkOptions, h as StandardOpenAPILink } from '../../shared/openapi-client.Cv0hBP4Y.js';
|
|
5
5
|
import '@orpc/client/standard';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
import '@orpc/standard-server';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { LinkFetchClient } from '@orpc/client/fetch';
|
|
2
2
|
import '@orpc/shared';
|
|
3
3
|
import '@orpc/contract';
|
|
4
|
-
import {
|
|
4
|
+
import { a as StandardOpenAPILink } from '../../shared/openapi-client.InKGcjFv.mjs';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/client/standard';
|
|
7
7
|
import '@orpc/standard-server';
|
|
8
|
+
import '../../shared/openapi-client.t9fCAe3x.mjs';
|
|
8
9
|
|
|
9
10
|
class OpenAPILink extends StandardOpenAPILink {
|
|
10
11
|
constructor(contract, options) {
|
|
@@ -1,63 +1,11 @@
|
|
|
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.
|
|
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';
|
|
2
3
|
import { HTTPPath } from '@orpc/client';
|
|
3
4
|
import '@orpc/client/standard';
|
|
4
5
|
import '@orpc/contract';
|
|
5
6
|
import '@orpc/shared';
|
|
6
7
|
import '@orpc/standard-server';
|
|
7
8
|
|
|
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
|
-
|
|
61
9
|
/**
|
|
62
10
|
* @internal
|
|
63
11
|
*/
|
|
@@ -70,4 +18,4 @@ declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
|
70
18
|
name: string;
|
|
71
19
|
}[] | undefined;
|
|
72
20
|
|
|
73
|
-
export { getDynamicParams,
|
|
21
|
+
export { getDynamicParams, standardizeHTTPPath };
|
|
@@ -1,63 +1,11 @@
|
|
|
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.
|
|
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';
|
|
2
3
|
import { HTTPPath } from '@orpc/client';
|
|
3
4
|
import '@orpc/client/standard';
|
|
4
5
|
import '@orpc/contract';
|
|
5
6
|
import '@orpc/shared';
|
|
6
7
|
import '@orpc/standard-server';
|
|
7
8
|
|
|
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
|
-
|
|
61
9
|
/**
|
|
62
10
|
* @internal
|
|
63
11
|
*/
|
|
@@ -70,4 +18,4 @@ declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
|
70
18
|
name: string;
|
|
71
19
|
}[] | undefined;
|
|
72
20
|
|
|
73
|
-
export { getDynamicParams,
|
|
21
|
+
export { getDynamicParams, standardizeHTTPPath };
|
|
@@ -1,43 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
import
|
|
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';
|
|
5
6
|
import '@orpc/client/standard';
|
|
6
7
|
import '@orpc/client';
|
|
7
8
|
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 };
|
|
@@ -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';
|
|
@@ -70,7 +70,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
70
70
|
/**
|
|
71
71
|
* Inject headers to the request.
|
|
72
72
|
*/
|
|
73
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
73
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [
|
|
74
74
|
options: ClientOptions<T>,
|
|
75
75
|
path: readonly string[],
|
|
76
76
|
input: unknown
|
|
@@ -70,7 +70,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
70
70
|
/**
|
|
71
71
|
* Inject headers to the request.
|
|
72
72
|
*/
|
|
73
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
73
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [
|
|
74
74
|
options: ClientOptions<T>,
|
|
75
75
|
path: readonly string[],
|
|
76
76
|
input: unknown
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isSchemaIssue } from '@orpc/contract';
|
|
2
|
+
import { isTypescriptObject } from '@orpc/shared';
|
|
3
|
+
import { S as StandardBracketNotationSerializer } from './openapi-client.t9fCAe3x.mjs';
|
|
4
|
+
|
|
5
|
+
function parseFormData(form) {
|
|
6
|
+
const serializer = new StandardBracketNotationSerializer();
|
|
7
|
+
return serializer.deserialize(Array.from(form.entries()));
|
|
8
|
+
}
|
|
9
|
+
function getIssueMessage(error, path) {
|
|
10
|
+
if (!isTypescriptObject(error) || !isTypescriptObject(error.data) || !Array.isArray(error.data.issues)) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
const serializer = new StandardBracketNotationSerializer();
|
|
14
|
+
for (const issue of error.data.issues) {
|
|
15
|
+
if (!isSchemaIssue(issue)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (issue.path === void 0) {
|
|
19
|
+
if (path === "") {
|
|
20
|
+
return issue.message;
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const issuePath = serializer.stringifyPath(
|
|
25
|
+
issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString())
|
|
26
|
+
);
|
|
27
|
+
if (issuePath === path) {
|
|
28
|
+
return issue.message;
|
|
29
|
+
}
|
|
30
|
+
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) {
|
|
31
|
+
return issue.message;
|
|
32
|
+
}
|
|
33
|
+
if (path === "" && issuePath.match(/(?:0|[1-9]\d*)$/)) {
|
|
34
|
+
return issue.message;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { getIssueMessage as g, parseFormData as p };
|
|
@@ -1,152 +1,10 @@
|
|
|
1
|
-
import { toHttpPath, getMalformedResponseErrorCode, StandardLink } from '@orpc/client/standard';
|
|
2
|
-
import {
|
|
1
|
+
import { toStandardHeaders, toHttpPath, getMalformedResponseErrorCode, StandardLink } from '@orpc/client/standard';
|
|
2
|
+
import { S as StandardBracketNotationSerializer } from './openapi-client.t9fCAe3x.mjs';
|
|
3
|
+
import { isObject, value, get, isAsyncIteratorObject } from '@orpc/shared';
|
|
3
4
|
import { isORPCErrorStatus, isORPCErrorJson, createORPCErrorFromJson, mapEventIterator, toORPCError } from '@orpc/client';
|
|
4
5
|
import { isContractProcedure, fallbackContractConfig, ORPCError } from '@orpc/contract';
|
|
5
6
|
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
6
7
|
|
|
7
|
-
class StandardBracketNotationSerializer {
|
|
8
|
-
maxArrayIndex;
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
this.maxArrayIndex = options.maxBracketNotationArrayIndex ?? 9999;
|
|
11
|
-
}
|
|
12
|
-
serialize(data, segments = [], result = []) {
|
|
13
|
-
if (Array.isArray(data)) {
|
|
14
|
-
data.forEach((item, i) => {
|
|
15
|
-
this.serialize(item, [...segments, i], result);
|
|
16
|
-
});
|
|
17
|
-
} else if (isObject(data)) {
|
|
18
|
-
for (const key in data) {
|
|
19
|
-
this.serialize(data[key], [...segments, key], result);
|
|
20
|
-
}
|
|
21
|
-
} else {
|
|
22
|
-
result.push([this.stringifyPath(segments), data]);
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
deserialize(serialized) {
|
|
27
|
-
if (serialized.length === 0) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
31
|
-
const ref = { value: [] };
|
|
32
|
-
for (const [path, value] of serialized) {
|
|
33
|
-
const segments = this.parsePath(path);
|
|
34
|
-
let currentRef = ref;
|
|
35
|
-
let nextSegment = "value";
|
|
36
|
-
segments.forEach((segment, i) => {
|
|
37
|
-
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
38
|
-
currentRef[nextSegment] = [];
|
|
39
|
-
}
|
|
40
|
-
if (i !== segments.length - 1) {
|
|
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
|
-
}
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
if (Array.isArray(currentRef[nextSegment])) {
|
|
51
|
-
if (segment === "") {
|
|
52
|
-
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
53
|
-
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
57
|
-
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
58
|
-
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
59
|
-
} else if (!isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
60
|
-
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
currentRef = currentRef[nextSegment];
|
|
66
|
-
nextSegment = segment;
|
|
67
|
-
});
|
|
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);
|
|
74
|
-
} else {
|
|
75
|
-
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
currentRef[nextSegment] = value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return ref.value;
|
|
82
|
-
}
|
|
83
|
-
stringifyPath(segments) {
|
|
84
|
-
return segments.map((segment) => {
|
|
85
|
-
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
86
|
-
switch (match) {
|
|
87
|
-
case "\\":
|
|
88
|
-
return "\\\\";
|
|
89
|
-
case "[":
|
|
90
|
-
return "\\[";
|
|
91
|
-
case "]":
|
|
92
|
-
return "\\]";
|
|
93
|
-
/* v8 ignore next 2 */
|
|
94
|
-
default:
|
|
95
|
-
return match;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}).reduce((result, segment, i) => {
|
|
99
|
-
if (i === 0) {
|
|
100
|
-
return segment;
|
|
101
|
-
}
|
|
102
|
-
return `${result}[${segment}]`;
|
|
103
|
-
}, "");
|
|
104
|
-
}
|
|
105
|
-
parsePath(path) {
|
|
106
|
-
const segments = [];
|
|
107
|
-
let inBrackets = false;
|
|
108
|
-
let currentSegment = "";
|
|
109
|
-
let backslashCount = 0;
|
|
110
|
-
for (let i = 0; i < path.length; i++) {
|
|
111
|
-
const char = path[i];
|
|
112
|
-
const nextChar = path[i + 1];
|
|
113
|
-
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
114
|
-
if (nextChar === void 0) {
|
|
115
|
-
inBrackets = false;
|
|
116
|
-
}
|
|
117
|
-
segments.push(currentSegment);
|
|
118
|
-
currentSegment = "";
|
|
119
|
-
i++;
|
|
120
|
-
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
121
|
-
inBrackets = true;
|
|
122
|
-
segments.push(currentSegment);
|
|
123
|
-
currentSegment = "";
|
|
124
|
-
} else if (char === "\\") {
|
|
125
|
-
backslashCount++;
|
|
126
|
-
} else {
|
|
127
|
-
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
128
|
-
backslashCount = 0;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
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;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
8
|
class StandardOpenAPIJsonSerializer {
|
|
151
9
|
customSerializers;
|
|
152
10
|
constructor(options = {}) {
|
|
@@ -216,11 +74,11 @@ class StandardOpenapiLinkCodec {
|
|
|
216
74
|
baseUrl;
|
|
217
75
|
headers;
|
|
218
76
|
async encode(path, input, options) {
|
|
219
|
-
|
|
220
|
-
let headers = await value(this.headers, options, path, input);
|
|
77
|
+
let headers = toStandardHeaders(await value(this.headers, options, path, input));
|
|
221
78
|
if (options.lastEventId !== void 0) {
|
|
222
79
|
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
223
80
|
}
|
|
81
|
+
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
224
82
|
const procedure = get(this.contract, path);
|
|
225
83
|
if (!isContractProcedure(procedure)) {
|
|
226
84
|
throw new Error(`[StandardOpenapiLinkCodec] expect a contract procedure at ${path.join(".")}`);
|
|
@@ -435,4 +293,4 @@ class StandardOpenAPILink extends StandardLink {
|
|
|
435
293
|
}
|
|
436
294
|
}
|
|
437
295
|
|
|
438
|
-
export {
|
|
296
|
+
export { StandardOpenAPIJsonSerializer as S, StandardOpenAPILink as a, StandardOpenapiLinkCodec as b, StandardOpenAPISerializer as c, getDynamicParams as g, standardizeHTTPPath as s };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { isObject, NullProtoObj } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
class StandardBracketNotationSerializer {
|
|
4
|
+
maxArrayIndex;
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.maxArrayIndex = options.maxBracketNotationArrayIndex ?? 9999;
|
|
7
|
+
}
|
|
8
|
+
serialize(data, segments = [], result = []) {
|
|
9
|
+
if (Array.isArray(data)) {
|
|
10
|
+
data.forEach((item, i) => {
|
|
11
|
+
this.serialize(item, [...segments, i], result);
|
|
12
|
+
});
|
|
13
|
+
} else if (isObject(data)) {
|
|
14
|
+
for (const key in data) {
|
|
15
|
+
this.serialize(data[key], [...segments, key], result);
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
result.push([this.stringifyPath(segments), data]);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
deserialize(serialized) {
|
|
23
|
+
if (serialized.length === 0) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
27
|
+
const ref = { value: [] };
|
|
28
|
+
for (const [path, value] of serialized) {
|
|
29
|
+
const segments = this.parsePath(path);
|
|
30
|
+
let currentRef = ref;
|
|
31
|
+
let nextSegment = "value";
|
|
32
|
+
segments.forEach((segment, i) => {
|
|
33
|
+
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
34
|
+
currentRef[nextSegment] = [];
|
|
35
|
+
}
|
|
36
|
+
if (i !== segments.length - 1) {
|
|
37
|
+
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
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
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
47
|
+
if (segment === "") {
|
|
48
|
+
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
49
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
53
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
54
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
55
|
+
} else if (!isValidArrayIndex(segment, this.maxArrayIndex)) {
|
|
56
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
currentRef = currentRef[nextSegment];
|
|
62
|
+
nextSegment = segment;
|
|
63
|
+
});
|
|
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);
|
|
70
|
+
} else {
|
|
71
|
+
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
currentRef[nextSegment] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return ref.value;
|
|
78
|
+
}
|
|
79
|
+
stringifyPath(segments) {
|
|
80
|
+
return segments.map((segment) => {
|
|
81
|
+
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
82
|
+
switch (match) {
|
|
83
|
+
case "\\":
|
|
84
|
+
return "\\\\";
|
|
85
|
+
case "[":
|
|
86
|
+
return "\\[";
|
|
87
|
+
case "]":
|
|
88
|
+
return "\\]";
|
|
89
|
+
/* v8 ignore next 2 */
|
|
90
|
+
default:
|
|
91
|
+
return match;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}).reduce((result, segment, i) => {
|
|
95
|
+
if (i === 0) {
|
|
96
|
+
return segment;
|
|
97
|
+
}
|
|
98
|
+
return `${result}[${segment}]`;
|
|
99
|
+
}, "");
|
|
100
|
+
}
|
|
101
|
+
parsePath(path) {
|
|
102
|
+
const segments = [];
|
|
103
|
+
let inBrackets = false;
|
|
104
|
+
let currentSegment = "";
|
|
105
|
+
let backslashCount = 0;
|
|
106
|
+
for (let i = 0; i < path.length; i++) {
|
|
107
|
+
const char = path[i];
|
|
108
|
+
const nextChar = path[i + 1];
|
|
109
|
+
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
110
|
+
if (nextChar === void 0) {
|
|
111
|
+
inBrackets = false;
|
|
112
|
+
}
|
|
113
|
+
segments.push(currentSegment);
|
|
114
|
+
currentSegment = "";
|
|
115
|
+
i++;
|
|
116
|
+
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
117
|
+
inBrackets = true;
|
|
118
|
+
segments.push(currentSegment);
|
|
119
|
+
currentSegment = "";
|
|
120
|
+
} else if (char === "\\") {
|
|
121
|
+
backslashCount++;
|
|
122
|
+
} else {
|
|
123
|
+
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
124
|
+
backslashCount = 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isValidArrayIndex(value, maxIndex) {
|
|
131
|
+
return /^0$|^[1-9]\d*$/.test(value) && Number(value) <= maxIndex;
|
|
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
|
+
}
|
|
145
|
+
|
|
146
|
+
export { StandardBracketNotationSerializer as S };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi-client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./helpers": {
|
|
23
|
+
"types": "./dist/helpers/index.d.mts",
|
|
24
|
+
"import": "./dist/helpers/index.mjs",
|
|
25
|
+
"default": "./dist/helpers/index.mjs"
|
|
26
|
+
},
|
|
22
27
|
"./standard": {
|
|
23
28
|
"types": "./dist/adapters/standard/index.d.mts",
|
|
24
29
|
"import": "./dist/adapters/standard/index.mjs",
|
|
@@ -34,13 +39,13 @@
|
|
|
34
39
|
"dist"
|
|
35
40
|
],
|
|
36
41
|
"dependencies": {
|
|
37
|
-
"@orpc/
|
|
38
|
-
"@orpc/
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
42
|
+
"@orpc/client": "1.8.7",
|
|
43
|
+
"@orpc/standard-server": "1.8.7",
|
|
44
|
+
"@orpc/shared": "1.8.7",
|
|
45
|
+
"@orpc/contract": "1.8.7"
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {
|
|
43
|
-
"@orpc/server": "1.8.
|
|
48
|
+
"@orpc/server": "1.8.7"
|
|
44
49
|
},
|
|
45
50
|
"scripts": {
|
|
46
51
|
"build": "unbuild",
|