@sanity/schema 6.10.2-next.10 → 6.10.2-next.25
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 +15 -12
- package/lib/_internal.js +25 -14
- package/lib/_internal.js.map +1 -1
- package/package.json +7 -4
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
|
*/
|
|
@@ -384,17 +387,17 @@ declare const builtinTypes: ({
|
|
|
384
387
|
type: string;
|
|
385
388
|
title: string;
|
|
386
389
|
readOnly: boolean;
|
|
390
|
+
fieldset?: undefined;
|
|
387
391
|
validation?: undefined;
|
|
388
392
|
hidden?: undefined;
|
|
389
|
-
fieldset?: undefined;
|
|
390
393
|
} | {
|
|
391
394
|
name: string;
|
|
392
395
|
type: string;
|
|
393
396
|
title: string;
|
|
394
|
-
validation?: undefined;
|
|
395
|
-
hidden?: undefined;
|
|
396
397
|
readOnly?: undefined;
|
|
397
398
|
fieldset?: undefined;
|
|
399
|
+
validation?: undefined;
|
|
400
|
+
hidden?: undefined;
|
|
398
401
|
} | {
|
|
399
402
|
name: string;
|
|
400
403
|
type: string;
|
|
@@ -409,8 +412,8 @@ declare const builtinTypes: ({
|
|
|
409
412
|
readOnly: boolean;
|
|
410
413
|
hidden: boolean;
|
|
411
414
|
fieldset: string;
|
|
412
|
-
validation?: undefined;
|
|
413
415
|
title?: undefined;
|
|
416
|
+
validation?: undefined;
|
|
414
417
|
} | {
|
|
415
418
|
name: string;
|
|
416
419
|
type: string;
|
|
@@ -463,17 +466,17 @@ declare const builtinTypes: ({
|
|
|
463
466
|
type: string;
|
|
464
467
|
title: string;
|
|
465
468
|
readOnly: boolean;
|
|
469
|
+
fieldset?: undefined;
|
|
466
470
|
validation?: undefined;
|
|
467
471
|
hidden?: undefined;
|
|
468
|
-
fieldset?: undefined;
|
|
469
472
|
} | {
|
|
470
473
|
name: string;
|
|
471
474
|
type: string;
|
|
472
475
|
title: string;
|
|
473
|
-
validation?: undefined;
|
|
474
|
-
hidden?: undefined;
|
|
475
476
|
readOnly?: undefined;
|
|
476
477
|
fieldset?: undefined;
|
|
478
|
+
validation?: undefined;
|
|
479
|
+
hidden?: undefined;
|
|
477
480
|
} | {
|
|
478
481
|
name: string;
|
|
479
482
|
type: string;
|
|
@@ -483,21 +486,21 @@ declare const builtinTypes: ({
|
|
|
483
486
|
validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
|
|
484
487
|
hidden?: undefined;
|
|
485
488
|
} | {
|
|
486
|
-
validation?: undefined;
|
|
487
489
|
name: string;
|
|
488
490
|
type: string;
|
|
489
491
|
readOnly: boolean;
|
|
490
492
|
hidden: boolean;
|
|
491
493
|
fieldset: string;
|
|
492
494
|
title?: undefined;
|
|
493
|
-
} | {
|
|
494
495
|
validation?: undefined;
|
|
495
|
-
|
|
496
|
+
} | {
|
|
496
497
|
name: string;
|
|
497
498
|
type: string;
|
|
498
499
|
title: string;
|
|
499
500
|
readOnly: boolean;
|
|
500
501
|
fieldset: string;
|
|
502
|
+
validation?: undefined;
|
|
503
|
+
hidden?: undefined;
|
|
501
504
|
})[];
|
|
502
505
|
preview: {
|
|
503
506
|
select: {
|
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
|
/**
|