@sanity/schema 6.10.1 → 6.10.2-next.18
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/lib/_internal.d.ts +5 -2
- package/lib/_internal.js +25 -14
- package/lib/_internal.js.map +1 -1
- package/package.json +8 -5
package/lib/_internal.d.ts
CHANGED
|
@@ -56,8 +56,11 @@ type DescriptorRequestOptions = RequestOptions;
|
|
|
56
56
|
/**
|
|
57
57
|
* The transport seam. The client calls this for every request; the return value
|
|
58
58
|
* is the parsed response body. Any requester with the shape
|
|
59
|
-
* `<B>(options): Promise<B>`
|
|
60
|
-
*
|
|
59
|
+
* `<B>(options): Promise<B>` is structurally assignable, so callers can bring
|
|
60
|
+
* their own transport. Note that a configured get-it v9 instance does NOT
|
|
61
|
+
* qualify on its own — it resolves with the full response object, not the
|
|
62
|
+
* parsed body — so it must be wrapped the way {@link createGetItRequester}
|
|
63
|
+
* wraps it.
|
|
61
64
|
*
|
|
62
65
|
* @internal
|
|
63
66
|
*/
|
package/lib/_internal.js
CHANGED
|
@@ -4,8 +4,8 @@ import { isSpanSchemaType } from "@sanity/types";
|
|
|
4
4
|
import isEqual from "lodash-es/isEqual.js";
|
|
5
5
|
import isObject from "lodash-es/isObject.js";
|
|
6
6
|
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { HttpError, createRequester } from "get-it";
|
|
8
|
+
import { retry } from "get-it/middleware";
|
|
9
9
|
import "@sanity/generate-help-url";
|
|
10
10
|
import difference from "lodash-es/difference.js";
|
|
11
11
|
import startCase from "lodash-es/startCase.js";
|
|
@@ -632,13 +632,26 @@ function processSchemaSynchronization(sync, response) {
|
|
|
632
632
|
return processSetSynchronization(sync, response);
|
|
633
633
|
}
|
|
634
634
|
/**
|
|
635
|
-
* Retry on rate-limit (429) and server (5xx) responses.
|
|
635
|
+
* Retry on rate-limit (429) and server (5xx) responses. get-it v9 throws a
|
|
636
|
+
* `HttpError` (with the status on `err.status`) for non-2xx responses; network
|
|
637
|
+
* and timeout failures are not `HttpError`s and are not retried, matching the
|
|
638
|
+
* v8 behavior of reading `err.response.statusCode`.
|
|
636
639
|
*
|
|
637
640
|
* @internal
|
|
638
641
|
*/
|
|
639
642
|
function defaultShouldRetry(err) {
|
|
640
|
-
|
|
641
|
-
|
|
643
|
+
return err instanceof HttpError ? err.status === 429 || err.status >= 500 : !1;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Parse a response body the way get-it v8's `jsonResponse()` middleware did:
|
|
647
|
+
* JSON only when the body is non-empty and the content type says so, the raw
|
|
648
|
+
* text otherwise, `undefined` for empty bodies. get-it v9's `as: 'json'`
|
|
649
|
+
* parses unconditionally and throws on empty bodies, which an endpoint
|
|
650
|
+
* answering e.g. `204 No Content` would trip on.
|
|
651
|
+
*/
|
|
652
|
+
function parseBody(res) {
|
|
653
|
+
let text = res.text();
|
|
654
|
+
if (text) return (res.headers.get("content-type") ?? "").toLowerCase().includes("application/json") ? res.json() : text;
|
|
642
655
|
}
|
|
643
656
|
/**
|
|
644
657
|
* Build the default get-it requester. Auth and headers are NOT applied here —
|
|
@@ -648,15 +661,13 @@ function defaultShouldRetry(err) {
|
|
|
648
661
|
* @internal
|
|
649
662
|
*/
|
|
650
663
|
function createGetItRequester(options) {
|
|
651
|
-
let requester =
|
|
652
|
-
base
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
]);
|
|
659
|
-
return (opts) => requester(opts);
|
|
664
|
+
let requester = createRequester({
|
|
665
|
+
base: options.baseUrl,
|
|
666
|
+
headers: { Accept: "application/json" },
|
|
667
|
+
fetch: options.fetch,
|
|
668
|
+
middleware: [retry({ shouldRetry: defaultShouldRetry })]
|
|
669
|
+
});
|
|
670
|
+
return async (opts) => parseBody(await requester(opts));
|
|
660
671
|
}
|
|
661
672
|
const sharedConverter = new DescriptorConverter();
|
|
662
673
|
/**
|