@sdxc/validate 2026.9.16 → 2026.9.29
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 +1 -1
- package/dist/index.js +12 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ Normalizes `input`, runs it through `schema`, and resolves to a `Result` carryin
|
|
|
85
85
|
`input` is any of:
|
|
86
86
|
|
|
87
87
|
- `FormData` or `URLSearchParams` — entries flatten to an object, a repeated name becoming an array.
|
|
88
|
-
- `Request` — the body is read by content type: `application/json`, `multipart/form-data`, or `application/x-www-form-urlencoded`. Any other type refuses with `Unsupported content-type: …`, and a body that is not valid JSON refuses with `Invalid JSON in request body`.
|
|
88
|
+
- `Request` — the body is read by content type: `application/json` or any `+json` media type (`application/merge-patch+json`, `application/problem+json`), `multipart/form-data`, or `application/x-www-form-urlencoded`. Any other type refuses with `Unsupported content-type: …`, and a body that is not valid JSON refuses with `Invalid JSON in request body`.
|
|
89
89
|
- A plain object, or any JSON value — handed to the schema as it stands.
|
|
90
90
|
|
|
91
91
|
Some schemas validate the raw source rather than a flattened object — `remix/data-schema/form-data`'s `object()` is one, and it rejects the flattened object with `Expected FormData or URLSearchParams`. That rejection is retried against the original `FormData` or `URLSearchParams`, so those schemas pass through the same call as any other.
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,17 @@ function urlSearchParamsToObject(params) {
|
|
|
19
19
|
}
|
|
20
20
|
return Object.fromEntries(data.entries());
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether a `Content-Type` names a JSON body: `application/json` itself or any media type
|
|
24
|
+
* with the RFC 6839 `+json` structured-syntax suffix (`application/merge-patch+json`,
|
|
25
|
+
* `application/problem+json`), compared case-insensitively with parameters ignored.
|
|
26
|
+
*/
|
|
27
|
+
function isJsonMediaType(contentType) {
|
|
28
|
+
if (contentType === null)
|
|
29
|
+
return false;
|
|
30
|
+
let essence = (contentType.split(";")[0] ?? "").trim().toLowerCase();
|
|
31
|
+
return (essence === "application/json" || /^[a-z0-9!#$&^_.-]+\/[a-z0-9!#$&^_.+-]+\+json$/.test(essence));
|
|
32
|
+
}
|
|
22
33
|
/**
|
|
23
34
|
* Some schemas (e.g. `remix/data-schema/form-data`'s `object()`) validate
|
|
24
35
|
* the raw `FormData`/`URLSearchParams` source instead of a flattened plain
|
|
@@ -27,7 +38,7 @@ function urlSearchParamsToObject(params) {
|
|
|
27
38
|
export async function validate(input, schema) {
|
|
28
39
|
if (input instanceof Request) {
|
|
29
40
|
let contentType = input.headers.get("content-type");
|
|
30
|
-
if (contentType
|
|
41
|
+
if (isJsonMediaType(contentType)) {
|
|
31
42
|
try {
|
|
32
43
|
let data = (await input.json());
|
|
33
44
|
return validate(data, schema);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/validate",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.29",
|
|
4
4
|
"description": "Standard Schema validation utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@sdxc/types": "2026.9.15",
|
|
13
13
|
"@standard-schema/spec": "^1.1.0"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "c17409b830b01b93514feb67818e3b1dcf654f5a",
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|