@orpc/openapi-client 0.0.0-next.01f89f6 → 0.0.0-next.0240b0d
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 -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.D_hC2pAM.d.mts → openapi-client.Bc2pHPqD.d.mts} +3 -3
- package/dist/shared/{openapi-client.D_hC2pAM.d.ts → openapi-client.Bc2pHPqD.d.ts} +3 -3
- package/dist/shared/{openapi-client.D89vdV2Y.mjs → openapi-client.BwEwVdZl.mjs} +1 -0
- package/package.json +6 -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 { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.
|
|
4
|
+
import { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.Bc2pHPqD.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 { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.
|
|
4
|
+
import { f as StandardOpenAPILinkOptions, g as StandardOpenAPILink } from '../../shared/openapi-client.Bc2pHPqD.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.BwEwVdZl.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, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.
|
|
1
|
+
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.Bc2pHPqD.mjs';
|
|
2
2
|
import { HTTPPath } from '@orpc/client';
|
|
3
3
|
import '@orpc/client/standard';
|
|
4
4
|
import '@orpc/contract';
|
|
5
5
|
import '@orpc/shared';
|
|
6
6
|
import '@orpc/standard-server';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* parse a form data with bracket notation
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const form = new FormData()
|
|
14
|
+
* form.append('a', '1')
|
|
15
|
+
* form.append('user[name]', 'John')
|
|
16
|
+
* form.append('user[age]', '20')
|
|
17
|
+
* form.append('user[friends][]', 'Bob')
|
|
18
|
+
* form.append('user[friends][]', 'Alice')
|
|
19
|
+
* form.append('user[friends][]', 'Charlie')
|
|
20
|
+
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
21
|
+
*
|
|
22
|
+
* parseFormData(form)
|
|
23
|
+
* // {
|
|
24
|
+
* // a: '1',
|
|
25
|
+
* // user: {
|
|
26
|
+
* // name: 'John',
|
|
27
|
+
* // age: '20',
|
|
28
|
+
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
29
|
+
* // },
|
|
30
|
+
* // thumb: form.get('thumb'),
|
|
31
|
+
* // }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
|
|
35
|
+
*/
|
|
36
|
+
declare function parseFormData(form: FormData): any;
|
|
37
|
+
/**
|
|
38
|
+
* Get the issue message from the error.
|
|
39
|
+
*
|
|
40
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
41
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.unnoq.com/docs/openapi/bracket-notation)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
46
|
+
*
|
|
47
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
48
|
+
* <input name="user[name]" type="text" />
|
|
49
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
50
|
+
*
|
|
51
|
+
* <input name="user[age]" type="number" />
|
|
52
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
53
|
+
*
|
|
54
|
+
* <input name="images[]" type="file" />
|
|
55
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
56
|
+
* </form>
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
60
|
+
|
|
8
61
|
/**
|
|
9
62
|
* @internal
|
|
10
63
|
*/
|
|
@@ -17,4 +70,4 @@ declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
|
17
70
|
name: string;
|
|
18
71
|
}[] | undefined;
|
|
19
72
|
|
|
20
|
-
export { getDynamicParams, standardizeHTTPPath };
|
|
73
|
+
export { getDynamicParams, getIssueMessage, parseFormData, standardizeHTTPPath };
|
|
@@ -1,10 +1,63 @@
|
|
|
1
|
-
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.
|
|
1
|
+
export { S as StandardBracketNotationSerialized, a as StandardBracketNotationSerializer, c as StandardOpenAPICustomJsonSerializer, b as StandardOpenAPIJsonSerialized, e as StandardOpenAPIJsonSerializer, d as StandardOpenAPIJsonSerializerOptions, g as StandardOpenAPILink, f as StandardOpenAPILinkOptions, j as StandardOpenAPISerializeOptions, k as StandardOpenAPISerializer, i as StandardOpenapiLinkCodec, h as StandardOpenapiLinkCodecOptions } from '../../shared/openapi-client.Bc2pHPqD.js';
|
|
2
2
|
import { HTTPPath } from '@orpc/client';
|
|
3
3
|
import '@orpc/client/standard';
|
|
4
4
|
import '@orpc/contract';
|
|
5
5
|
import '@orpc/shared';
|
|
6
6
|
import '@orpc/standard-server';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* parse a form data with bracket notation
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const form = new FormData()
|
|
14
|
+
* form.append('a', '1')
|
|
15
|
+
* form.append('user[name]', 'John')
|
|
16
|
+
* form.append('user[age]', '20')
|
|
17
|
+
* form.append('user[friends][]', 'Bob')
|
|
18
|
+
* form.append('user[friends][]', 'Alice')
|
|
19
|
+
* form.append('user[friends][]', 'Charlie')
|
|
20
|
+
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
21
|
+
*
|
|
22
|
+
* parseFormData(form)
|
|
23
|
+
* // {
|
|
24
|
+
* // a: '1',
|
|
25
|
+
* // user: {
|
|
26
|
+
* // name: 'John',
|
|
27
|
+
* // age: '20',
|
|
28
|
+
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
29
|
+
* // },
|
|
30
|
+
* // thumb: form.get('thumb'),
|
|
31
|
+
* // }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
|
|
35
|
+
*/
|
|
36
|
+
declare function parseFormData(form: FormData): any;
|
|
37
|
+
/**
|
|
38
|
+
* Get the issue message from the error.
|
|
39
|
+
*
|
|
40
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
41
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.unnoq.com/docs/openapi/bracket-notation)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
46
|
+
*
|
|
47
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
48
|
+
* <input name="user[name]" type="text" />
|
|
49
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
50
|
+
*
|
|
51
|
+
* <input name="user[age]" type="number" />
|
|
52
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
53
|
+
*
|
|
54
|
+
* <input name="images[]" type="file" />
|
|
55
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
56
|
+
* </form>
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
declare function getIssueMessage(error: unknown, path: string): string | undefined;
|
|
60
|
+
|
|
8
61
|
/**
|
|
9
62
|
* @internal
|
|
10
63
|
*/
|
|
@@ -17,4 +70,4 @@ declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
|
17
70
|
name: string;
|
|
18
71
|
}[] | undefined;
|
|
19
72
|
|
|
20
|
-
export { getDynamicParams, standardizeHTTPPath };
|
|
73
|
+
export { getDynamicParams, getIssueMessage, parseFormData, standardizeHTTPPath };
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import { S as StandardBracketNotationSerializer } from '../../shared/openapi-client.BwEwVdZl.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.BwEwVdZl.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,7 +1,7 @@
|
|
|
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][];
|
|
@@ -44,7 +44,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [
|
|
48
48
|
options: ClientOptions<T>,
|
|
49
49
|
path: readonly string[],
|
|
50
50
|
input: unknown
|
|
@@ -52,7 +52,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
52
52
|
/**
|
|
53
53
|
* Inject headers to the request.
|
|
54
54
|
*/
|
|
55
|
-
headers?: Value<StandardHeaders
|
|
55
|
+
headers?: Value<Promisable<StandardHeaders>, [
|
|
56
56
|
options: ClientOptions<T>,
|
|
57
57
|
path: readonly string[],
|
|
58
58
|
input: unknown
|
|
@@ -1,7 +1,7 @@
|
|
|
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][];
|
|
@@ -44,7 +44,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [
|
|
48
48
|
options: ClientOptions<T>,
|
|
49
49
|
path: readonly string[],
|
|
50
50
|
input: unknown
|
|
@@ -52,7 +52,7 @@ interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
|
|
|
52
52
|
/**
|
|
53
53
|
* Inject headers to the request.
|
|
54
54
|
*/
|
|
55
|
-
headers?: Value<StandardHeaders
|
|
55
|
+
headers?: Value<Promisable<StandardHeaders>, [
|
|
56
56
|
options: ClientOptions<T>,
|
|
57
57
|
path: readonly string[],
|
|
58
58
|
input: unknown
|
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.0240b0d",
|
|
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/standard-server": "0.0.0-next.
|
|
40
|
-
"@orpc/shared": "0.0.0-next.
|
|
37
|
+
"@orpc/client": "0.0.0-next.0240b0d",
|
|
38
|
+
"@orpc/contract": "0.0.0-next.0240b0d",
|
|
39
|
+
"@orpc/standard-server": "0.0.0-next.0240b0d",
|
|
40
|
+
"@orpc/shared": "0.0.0-next.0240b0d"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@orpc/server": "0.0.0-next.
|
|
43
|
+
"@orpc/server": "0.0.0-next.0240b0d"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "unbuild",
|