@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50
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/aws-lambda/index.d.ts +3 -15
- package/dist/adapters/aws-lambda/index.js +1 -1
- package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
- package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
- package/dist/adapters/fastify/index.d.ts +2 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
- package/dist/adapters/fastify/openapi-handler.js +16 -14
- package/dist/adapters/fetch/index.d.ts +3 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
- package/dist/adapters/fetch/openapi-handler.js +16 -14
- package/dist/adapters/fetch/openapi-link.d.ts +9 -10
- package/dist/adapters/fetch/openapi-link.js +21 -19
- package/dist/adapters/node/index.d.ts +2 -1
- package/dist/adapters/node/index.js +1 -1
- package/dist/adapters/node/openapi-handler.d.ts +8 -9
- package/dist/adapters/node/openapi-handler.js +16 -14
- package/dist/adapters/standard/index.d.ts +4 -3
- package/dist/adapters/standard/index.js +3 -3
- package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
- package/dist/adapters/standard/openapi-handler-codec.js +143 -205
- package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
- package/dist/adapters/standard/openapi-link-codec.js +262 -377
- package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
- package/dist/adapters/standard/openapi-matcher.js +78 -108
- package/dist/adapters/standard/utils.js +28 -44
- package/dist/bracket-notation.d.ts +22 -22
- package/dist/bracket-notation.js +123 -173
- package/dist/client-factory.d.ts +12 -12
- package/dist/client-factory.js +13 -11
- package/dist/constants.d.ts +1 -4
- package/dist/constants.js +5 -4
- package/dist/extensions/route.d.ts +36 -36
- package/dist/extensions/route.js +7 -6
- package/dist/helpers/form-data.d.ts +1 -1
- package/dist/helpers/form-data.js +74 -86
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.js +1 -1
- package/dist/index.d.ts +15 -13
- package/dist/index.js +11 -11
- package/dist/meta.d.ts +298 -298
- package/dist/meta.js +54 -72
- package/dist/openapi-generator-components.d.ts +2 -31
- package/dist/openapi-generator-components.js +200 -248
- package/dist/openapi-generator-operation.d.ts +12 -33
- package/dist/openapi-generator-operation.js +369 -437
- package/dist/openapi-generator.d.ts +75 -80
- package/dist/openapi-generator.js +114 -142
- package/dist/openapi-json-serializer.d.ts +65 -65
- package/dist/openapi-json-serializer.js +218 -257
- package/dist/openapi-serializer.d.ts +31 -32
- package/dist/openapi-serializer.js +68 -92
- package/dist/plugins/index.d.ts +2 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/openapi-reference.d.ts +99 -102
- package/dist/plugins/openapi-reference.js +109 -132
- package/dist/router-utils.d.ts +7 -10
- package/dist/router-utils.js +30 -34
- package/dist/types.d.ts +8 -12
- package/dist/utils.d.ts +5 -10
- package/dist/utils.js +39 -42
- package/package.json +12 -12
- package/dist/adapters/standard/utils.d.ts +0 -4
- package/dist/types.js +0 -1
|
@@ -1,90 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isNonPrimitive } from
|
|
3
|
-
import {
|
|
1
|
+
import { BracketNotationSerializer } from "../bracket-notation.js";
|
|
2
|
+
import { NON_NEGATIVE_INTEGER_REGEX, isNonPrimitive } from "@orpc/shared";
|
|
3
|
+
import { isSchemaIssue } from "@orpc/contract";
|
|
4
|
+
// src/helpers/form-data.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return serializer.deserialize(Array.from(form.entries()));
|
|
6
|
+
* Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const form = new FormData()
|
|
11
|
+
* form.append('a', '1')
|
|
12
|
+
* form.append('user[name]', 'John')
|
|
13
|
+
* form.append('user[age]', '20')
|
|
14
|
+
* form.append('user[friends][]', 'Bob')
|
|
15
|
+
* form.append('user[friends][]', 'Alice')
|
|
16
|
+
* form.append('user[friends][]', 'Charlie')
|
|
17
|
+
* form.append('thumb', new Blob(['hello']), 'thumb.png')
|
|
18
|
+
*
|
|
19
|
+
* parseFormData(form)
|
|
20
|
+
* // {
|
|
21
|
+
* // a: '1',
|
|
22
|
+
* // user: {
|
|
23
|
+
* // name: 'John',
|
|
24
|
+
* // age: '20',
|
|
25
|
+
* // friends: ['Bob', 'Alice', 'Charlie'],
|
|
26
|
+
* // },
|
|
27
|
+
* // thumb: form.get('thumb'),
|
|
28
|
+
* // }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
|
|
32
|
+
*/
|
|
33
|
+
function parseFormData(form) {
|
|
34
|
+
return new BracketNotationSerializer().deserialize(Array.from(form.entries()));
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
const issuePath = serializer.stringifyPath(issue.path.map((segment) => typeof segment === 'object' ? segment.key.toString() : segment.toString()));
|
|
79
|
-
if (issuePath === path) {
|
|
80
|
-
return issue.message;
|
|
81
|
-
}
|
|
82
|
-
if (path.endsWith('[]') && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, '[]') === path) {
|
|
83
|
-
return issue.message;
|
|
84
|
-
}
|
|
85
|
-
if (path === '' && /^(?:0|[1-9]\d*)$/.test(issuePath)) {
|
|
86
|
-
return issue.message;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return undefined;
|
|
37
|
+
* Gets the issue message from the error for a given field path.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* **Note**: Requires validation errors to follow the standard schema issue format, stored under `data.issues` — customized validation errors may not be found.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const { error, data, execute } = useServerAction(someAction)
|
|
45
|
+
*
|
|
46
|
+
* return <form action={(form) => execute(parseFormData(form))}>
|
|
47
|
+
* <input name="user[name]" type="text" />
|
|
48
|
+
* <p>{getIssueMessage(error, 'user[name]')}</p>
|
|
49
|
+
*
|
|
50
|
+
* <input name="user[age]" type="number" />
|
|
51
|
+
* <p>{getIssueMessage(error, 'user[age]')}</p>
|
|
52
|
+
*
|
|
53
|
+
* <input name="images[]" type="file" />
|
|
54
|
+
* <p>{getIssueMessage(error, 'images[]')}</p>
|
|
55
|
+
* </form>
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
|
|
59
|
+
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
|
|
62
|
+
*/
|
|
63
|
+
function getIssueMessage(error, path) {
|
|
64
|
+
if (!isNonPrimitive(error) || !isNonPrimitive(error.data) || !Array.isArray(error.data.issues)) return;
|
|
65
|
+
const serializer = new BracketNotationSerializer();
|
|
66
|
+
for (const issue of error.data.issues) {
|
|
67
|
+
if (!isSchemaIssue(issue)) continue;
|
|
68
|
+
if (issue.path === void 0) {
|
|
69
|
+
if (path === "") return issue.message;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const issuePath = serializer.stringifyPath(issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString()));
|
|
73
|
+
if (issuePath === path) return issue.message;
|
|
74
|
+
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) return issue.message;
|
|
75
|
+
if (path === "" && NON_NEGATIVE_INTEGER_REGEX.test(issuePath)) return issue.message;
|
|
76
|
+
}
|
|
90
77
|
}
|
|
78
|
+
export { getIssueMessage, parseFormData };
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { getIssueMessage, parseFormData } from "./form-data.js";
|
|
2
|
+
export { getIssueMessage, parseFormData };
|
package/dist/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { getIssueMessage, parseFormData } from "./form-data.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { BracketNotationSerializeResult, BracketNotationSerializer, BracketNotationSerializerOptions } from "./bracket-notation.js";
|
|
2
|
+
import { ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, createContractJsonifiedClientFactory } from "./client-factory.js";
|
|
3
|
+
import { DEFAULT_OPENAPI_METHOD } from "./constants.js";
|
|
4
|
+
import { OpenAPIFunction, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugin, OpenAPIPathMetaPlugin, OpenAPIPrefixMetaPlugin, OpenAPISpecMetaPlugin, getOpenAPIMeta, openapi } from "./meta.js";
|
|
5
|
+
import { OpenAPIGenerator, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions } from "./openapi-generator.js";
|
|
6
|
+
import { OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions } from "./openapi-json-serializer.js";
|
|
7
|
+
import { OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions } from "./openapi-serializer.js";
|
|
8
|
+
import { PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths, populateRouterContractOpenAPIPaths } from "./router-utils.js";
|
|
9
|
+
import { OpenAPIErrorBodyDefinition, OpenAPIGeneratorError } from "./openapi-generator-operation.js";
|
|
10
|
+
import { JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIV3_0, OpenAPIV3_1, OpenAPIV3_2, OpenAPIVersion } from "./types.js";
|
|
11
|
+
import { getDynamicPathParams } from "./utils.js";
|
|
12
|
+
import { COMMON_ERROR_STATUS_MAP } from "@orpc/client";
|
|
13
|
+
import { JsonSchema } from "@orpc/json-schema";
|
|
14
|
+
import { StandardBodyHint } from "@standard-server/core";
|
|
15
|
+
export { BracketNotationSerializeResult, BracketNotationSerializer, BracketNotationSerializerOptions, COMMON_ERROR_STATUS_MAP, ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, DEFAULT_OPENAPI_METHOD, type JsonSchema, JsonifiedArray, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, type OpenAPIErrorBodyDefinition, OpenAPIFunction, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OpenAPIJsonSerialization, OpenAPIJsonSerializer, OpenAPIJsonSerializerHandler, OpenAPIJsonSerializerOptions, OpenAPIMeta, OpenAPIMetaPlugin, OpenAPIMethodMetaPlugin, OpenAPIPathMetaPlugin, OpenAPIPrefixMetaPlugin, OpenAPISerializer, OpenAPISerializerOptions, OpenAPISerializerSerializeOptions, OpenAPISpecMetaPlugin, type OpenAPIV3_0, type OpenAPIV3_1, type OpenAPIV3_2, OpenAPIVersion, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths, type StandardBodyHint, createContractJsonifiedClientFactory, getDynamicPathParams, getOpenAPIMeta, openapi, populateRouterContractOpenAPIPaths };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export { DEFAULT_OPENAPI_METHOD } from
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export { getDynamicPathParams } from
|
|
11
|
-
export { COMMON_ERROR_STATUS_MAP } from
|
|
1
|
+
export { BracketNotationSerializer } from "./bracket-notation.js";
|
|
2
|
+
export { createContractJsonifiedClientFactory } from "./client-factory.js";
|
|
3
|
+
export { DEFAULT_OPENAPI_METHOD } from "./constants.js";
|
|
4
|
+
export { getOpenAPIMeta, openapi } from "./meta.js";
|
|
5
|
+
export { OpenAPIGenerator } from "./openapi-generator.js";
|
|
6
|
+
export { OpenAPIGeneratorError } from "./openapi-generator-operation.js";
|
|
7
|
+
export { OpenAPIJsonSerializer } from "./openapi-json-serializer.js";
|
|
8
|
+
export { OpenAPISerializer } from "./openapi-serializer.js";
|
|
9
|
+
export { populateRouterContractOpenAPIPaths } from "./router-utils.js";
|
|
10
|
+
export { getDynamicPathParams } from "./utils.js";
|
|
11
|
+
export { COMMON_ERROR_STATUS_MAP } from "@orpc/client";
|