@sanity/schema 6.10.2-next.5 → 6.11.0-next.32

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.
@@ -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>` such as a configured `get-it` instance — is
60
- * structurally assignable, so callers can bring their own transport.
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;
387
- fieldset?: undefined;
388
390
  validation?: undefined;
389
391
  hidden?: undefined;
392
+ fieldset?: undefined;
390
393
  } | {
391
394
  name: string;
392
395
  type: string;
393
396
  title: string;
394
- fieldset?: undefined;
395
- readOnly?: undefined;
396
397
  validation?: undefined;
397
398
  hidden?: undefined;
399
+ readOnly?: undefined;
400
+ fieldset?: 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
- title?: undefined;
413
415
  validation?: undefined;
416
+ title?: 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;
466
- fieldset?: undefined;
467
469
  validation?: undefined;
468
470
  hidden?: undefined;
471
+ fieldset?: undefined;
469
472
  } | {
470
473
  name: string;
471
474
  type: string;
472
475
  title: string;
473
- fieldset?: undefined;
474
- readOnly?: undefined;
475
476
  validation?: undefined;
476
477
  hidden?: undefined;
478
+ readOnly?: undefined;
479
+ fieldset?: 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
  } | {
489
+ validation?: undefined;
486
490
  name: string;
487
491
  type: string;
488
492
  readOnly: boolean;
489
493
  hidden: boolean;
490
494
  fieldset: string;
491
495
  title?: undefined;
492
- validation?: undefined;
493
496
  } | {
497
+ validation?: undefined;
498
+ hidden?: undefined;
494
499
  name: string;
495
500
  type: string;
496
501
  title: string;
497
502
  readOnly: boolean;
498
503
  fieldset: string;
499
- validation?: undefined;
500
- hidden?: undefined;
501
504
  })[];
502
505
  preview: {
503
506
  select: {
@@ -547,17 +550,17 @@ declare const builtinTypes: ({
547
550
  };
548
551
  }[];
549
552
  fields: ({
550
- name: string;
551
- type: string;
552
- fieldset?: undefined;
553
553
  title?: undefined;
554
554
  readOnly?: undefined;
555
+ fieldset?: undefined;
556
+ name: string;
557
+ type: string;
555
558
  } | {
559
+ readOnly?: undefined;
556
560
  name: string;
557
561
  title: string;
558
562
  type: string;
559
563
  fieldset: string;
560
- readOnly?: undefined;
561
564
  } | {
562
565
  fieldset?: undefined;
563
566
  name: string;
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 { getIt } from "get-it";
8
- import { base, httpErrors, jsonRequest, jsonResponse, promise, retry } from "get-it/middleware";
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
- let statusCode = err?.response?.statusCode;
641
- return statusCode === 429 || typeof statusCode == "number" && statusCode >= 500;
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 = getIt([
652
- base(options.baseUrl),
653
- jsonResponse(),
654
- jsonRequest(),
655
- httpErrors(),
656
- retry({ shouldRetry: defaultShouldRetry }),
657
- promise({ onlyBody: !0 })
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
  /**