@sanity/client 5.2.0 → 5.2.2

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.
@@ -2,11 +2,11 @@ import {getIt, type Middlewares} from 'get-it'
2
2
  import {jsonRequest, jsonResponse, observable, progress} from 'get-it/middleware'
3
3
  import {Observable} from 'rxjs'
4
4
 
5
- import type {FIXME, HttpRequest, RequestOptions} from '../types'
5
+ import type {Any, HttpRequest, RequestOptions} from '../types'
6
6
  import {ClientError, ServerError} from './errors'
7
7
 
8
8
  const httpError = {
9
- onResponse: (res: FIXME) => {
9
+ onResponse: (res: Any) => {
10
10
  if (res.statusCode >= 500) {
11
11
  throw new ServerError(res)
12
12
  } else if (res.statusCode >= 400) {
@@ -18,7 +18,7 @@ const httpError = {
18
18
  }
19
19
 
20
20
  const printWarnings = {
21
- onResponse: (res: FIXME) => {
21
+ onResponse: (res: Any) => {
22
22
  const warn = res.headers['x-sanity-warning']
23
23
  const warnings = Array.isArray(warn) ? warn : [warn]
24
24
  warnings.filter(Boolean).forEach((msg) => console.warn(msg)) // eslint-disable-line no-console
@@ -39,7 +39,7 @@ export function defineHttpRequest(envMiddleware: Middlewares): HttpRequest {
39
39
  ])
40
40
 
41
41
  function httpRequest(options: RequestOptions, requester = request) {
42
- return requester({maxRedirects: 0, ...options} as FIXME)
42
+ return requester({maxRedirects: 0, ...options} as Any)
43
43
  }
44
44
 
45
45
  httpRequest.defaultRequester = request
@@ -1,11 +1,11 @@
1
1
  import type {RequestOptions} from 'get-it'
2
2
 
3
- import type {FIXME} from '../types'
3
+ import type {Any} from '../types'
4
4
 
5
5
  const projectHeader = 'X-Sanity-Project-ID'
6
6
 
7
- export default (config: FIXME, overrides: FIXME = {}): Omit<RequestOptions, 'url'> => {
8
- const headers: FIXME = {}
7
+ export function requestOptions(config: Any, overrides: Any = {}): Omit<RequestOptions, 'url'> {
8
+ const headers: Any = {}
9
9
 
10
10
  const token = overrides.token || config.token
11
11
  if (token) {
@@ -2,6 +2,7 @@ import envMiddleware from './http/browserMiddleware'
2
2
  import {defineHttpRequest} from './http/request'
3
3
  import {SanityClient} from './SanityClient'
4
4
  import type {ClientConfig} from './types'
5
+ import {printNoDefaultExport} from './warnings'
5
6
 
6
7
  export * from './data/patch'
7
8
  export * from './data/transaction'
@@ -17,4 +18,11 @@ export const requester = httpRequest.defaultRequester
17
18
  /** @public */
18
19
  export const createClient = (config: ClientConfig) => new SanityClient(httpRequest, config)
19
20
 
20
- export {migrationNotice as default} from './migrationNotice'
21
+ /**
22
+ * @public
23
+ * @deprecated Use the named export `createClient` instead of the `default` export
24
+ */
25
+ export default function deprecatedCreateClient(config: ClientConfig) {
26
+ printNoDefaultExport()
27
+ return new SanityClient(httpRequest, config)
28
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import envMiddleware from './http/nodeMiddleware'
2
2
  import {defineHttpRequest} from './http/request'
3
3
  import {SanityClient} from './SanityClient'
4
4
  import type {ClientConfig} from './types'
5
+ import {printNoDefaultExport} from './warnings'
5
6
 
6
7
  export * from './data/patch'
7
8
  export * from './data/transaction'
@@ -17,4 +18,11 @@ export const requester = httpRequest.defaultRequester
17
18
  /** @public */
18
19
  export const createClient = (config: ClientConfig) => new SanityClient(httpRequest, config)
19
20
 
20
- export {migrationNotice as default} from './migrationNotice'
21
+ /**
22
+ * @public
23
+ * @deprecated Use the named export `createClient` instead of the `default` export
24
+ */
25
+ export default function deprecatedCreateClient(config: ClientConfig) {
26
+ printNoDefaultExport()
27
+ return new SanityClient(httpRequest, config)
28
+ }
package/src/types.ts CHANGED
@@ -4,7 +4,7 @@ import type {Requester} from 'get-it'
4
4
  * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
5
5
  * @internal
6
6
  */
7
- export type FIXME = any // eslint-disable-line @typescript-eslint/no-explicit-any
7
+ export type Any = any // eslint-disable-line @typescript-eslint/no-explicit-any
8
8
 
9
9
  /** @public */
10
10
  export interface RequestOptions {
@@ -13,8 +13,8 @@ export interface RequestOptions {
13
13
  tag?: string
14
14
  headers?: Record<string, string>
15
15
  method?: string
16
- query?: FIXME
17
- body?: FIXME
16
+ query?: Any
17
+ body?: Any
18
18
  signal?: AbortSignal
19
19
  }
20
20
 
@@ -155,7 +155,7 @@ export interface SanityReference {
155
155
  }
156
156
 
157
157
  /** @internal */
158
- export type SanityDocument<T extends Record<string, FIXME> = Record<string, FIXME>> = {
158
+ export type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = {
159
159
  [P in keyof T]: T[P]
160
160
  } & {
161
161
  _id: string
@@ -212,11 +212,11 @@ export interface SanityImageAssetDocument extends SanityAssetDocument {
212
212
  }
213
213
  image?: {
214
214
  _type: 'sanity.imageExifTags'
215
- [key: string]: FIXME
215
+ [key: string]: Any
216
216
  }
217
217
  exif?: {
218
218
  _type: 'sanity.imageExifMetadata'
219
- [key: string]: FIXME
219
+ [key: string]: Any
220
220
  }
221
221
  }
222
222
  }
@@ -224,10 +224,10 @@ export interface SanityImageAssetDocument extends SanityAssetDocument {
224
224
  /** @public */
225
225
  export interface ErrorProps {
226
226
  message: string
227
- response: FIXME
227
+ response: Any
228
228
  statusCode: number
229
- responseBody: FIXME
230
- details: FIXME
229
+ responseBody: Any
230
+ details: Any
231
231
  }
232
232
 
233
233
  /** @public */
@@ -337,32 +337,31 @@ export interface CurrentSanityUser {
337
337
  }
338
338
 
339
339
  /** @public */
340
- export type SanityDocumentStub<T extends Record<string, FIXME> = Record<string, FIXME>> = {
340
+ export type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
341
341
  [P in keyof T]: T[P]
342
342
  } & {
343
343
  _type: string
344
344
  }
345
345
 
346
346
  /** @public */
347
- export type IdentifiedSanityDocumentStub<T extends Record<string, FIXME> = Record<string, FIXME>> =
348
- {
349
- [P in keyof T]: T[P]
350
- } & {
351
- _id: string
352
- } & SanityDocumentStub
347
+ export type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
348
+ [P in keyof T]: T[P]
349
+ } & {
350
+ _id: string
351
+ } & SanityDocumentStub
353
352
 
354
353
  /** @internal */
355
354
  export type InsertPatch =
356
- | {before: string; items: FIXME[]}
357
- | {after: string; items: FIXME[]}
358
- | {replace: string; items: FIXME[]}
355
+ | {before: string; items: Any[]}
356
+ | {after: string; items: Any[]}
357
+ | {replace: string; items: Any[]}
359
358
 
360
359
  // Note: this is actually incorrect/invalid, but implemented as-is for backwards compatibility
361
360
  /** @internal */
362
361
  export interface PatchOperations {
363
- set?: {[key: string]: FIXME}
364
- setIfMissing?: {[key: string]: FIXME}
365
- diffMatchPatch?: {[key: string]: FIXME}
362
+ set?: {[key: string]: Any}
363
+ setIfMissing?: {[key: string]: Any}
364
+ diffMatchPatch?: {[key: string]: Any}
366
365
  unset?: string[]
367
366
  inc?: {[key: string]: number}
368
367
  dec?: {[key: string]: number}
@@ -371,7 +370,7 @@ export interface PatchOperations {
371
370
  }
372
371
 
373
372
  /** @public */
374
- export type QueryParams = {[key: string]: FIXME}
373
+ export type QueryParams = {[key: string]: Any}
375
374
  /** @internal */
376
375
  export type MutationSelection = {query: string; params?: QueryParams} | {id: string | string[]}
377
376
  /** @internal */
@@ -380,7 +379,7 @@ export type PatchSelection = string | string[] | MutationSelection
380
379
  export type PatchMutationOperation = PatchOperations & MutationSelection
381
380
 
382
381
  /** @public */
383
- export type Mutation<R extends Record<string, FIXME> = Record<string, FIXME>> =
382
+ export type Mutation<R extends Record<string, Any> = Record<string, Any>> =
384
383
  | {create: SanityDocumentStub<R>}
385
384
  | {createOrReplace: IdentifiedSanityDocumentStub<R>}
386
385
  | {createIfNotExists: IdentifiedSanityDocumentStub<R>}
@@ -388,7 +387,7 @@ export type Mutation<R extends Record<string, FIXME> = Record<string, FIXME>> =
388
387
  | {patch: PatchMutationOperation}
389
388
 
390
389
  /** @public */
391
- export type MutationEvent<R extends Record<string, FIXME> = Record<string, FIXME>> = {
390
+ export type MutationEvent<R extends Record<string, Any> = Record<string, Any>> = {
392
391
  type: 'mutation'
393
392
  documentId: string
394
393
  eventId: string
@@ -428,7 +427,7 @@ export type WelcomeEvent = {
428
427
  }
429
428
 
430
429
  /** @public */
431
- export type ListenEvent<R extends Record<string, FIXME>> =
430
+ export type ListenEvent<R extends Record<string, Any>> =
432
431
  | MutationEvent<R>
433
432
  | ChannelErrorEvent
434
433
  | DisconnectEvent
@@ -517,7 +516,7 @@ export type AllDocumentIdsMutationOptions = BaseMutationOptions & {
517
516
  }
518
517
 
519
518
  /** @internal */
520
- export type AttributeSet = {[key: string]: FIXME}
519
+ export type AttributeSet = {[key: string]: Any}
521
520
 
522
521
  /** @internal */
523
522
  export type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
@@ -564,6 +563,6 @@ export interface RawRequestOptions {
564
563
  headers?: {[key: string]: string}
565
564
  timeout?: number
566
565
  proxy?: string
567
- body?: FIXME
566
+ body?: Any
568
567
  maxRedirects?: number
569
568
  }
@@ -1,10 +1,10 @@
1
- import type {FIXME} from '../types'
1
+ import type {Any} from '../types'
2
2
 
3
- export default (obj: FIXME, defaults: FIXME) =>
3
+ export default (obj: Any, defaults: Any) =>
4
4
  Object.keys(defaults)
5
5
  .concat(Object.keys(obj))
6
6
  .reduce((target, prop) => {
7
7
  target[prop] = typeof obj[prop] === 'undefined' ? defaults[prop] : obj[prop]
8
8
 
9
9
  return target
10
- }, {} as FIXME)
10
+ }, {} as Any)
@@ -1,6 +1,6 @@
1
1
  import type {MutationSelection} from '../types'
2
2
 
3
- export default function getSelection(sel: unknown): MutationSelection {
3
+ export function getSelection(sel: unknown): MutationSelection {
4
4
  if (typeof sel === 'string' || Array.isArray(sel)) {
5
5
  return {id: sel}
6
6
  }
package/src/util/once.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type {FIXME} from '../types'
1
+ import type {Any} from '../types'
2
2
 
3
- export default (fn: FIXME) => {
3
+ export function once(fn: Any) {
4
4
  let didCall = false
5
- let returnValue: FIXME
6
- return (...args: FIXME[]) => {
5
+ let returnValue: Any
6
+ return (...args: Any[]) => {
7
7
  if (didCall) {
8
8
  return returnValue
9
9
  }
package/src/util/pick.ts CHANGED
@@ -1,7 +1,7 @@
1
- import {FIXME} from '../types'
1
+ import {Any} from '../types'
2
2
 
3
- export default (obj: FIXME, props: FIXME) =>
4
- props.reduce((selection: FIXME, prop: FIXME) => {
3
+ export const pick = (obj: Any, props: Any) =>
4
+ props.reduce((selection: Any, prop: Any) => {
5
5
  if (typeof obj[prop] === 'undefined') {
6
6
  return selection
7
7
  }
package/src/validators.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {FIXME, InitializedClientConfig} from './types'
1
+ import type {Any, InitializedClientConfig} from './types'
2
2
 
3
3
  const VALID_ASSET_TYPES = ['image', 'file']
4
4
  const VALID_INSERT_LOCATIONS = ['before', 'after', 'replace']
@@ -23,7 +23,7 @@ export const validateAssetType = (type: string) => {
23
23
  }
24
24
  }
25
25
 
26
- export const validateObject = (op: string, val: FIXME) => {
26
+ export const validateObject = (op: string, val: Any) => {
27
27
  if (val === null || typeof val !== 'object' || Array.isArray(val)) {
28
28
  throw new Error(`${op}() takes an object of properties`)
29
29
  }
@@ -35,7 +35,7 @@ export const validateDocumentId = (op: string, id: string) => {
35
35
  }
36
36
  }
37
37
 
38
- export const requireDocumentId = (op: string, doc: Record<string, FIXME>) => {
38
+ export const requireDocumentId = (op: string, doc: Record<string, Any>) => {
39
39
  if (!doc._id) {
40
40
  throw new Error(`${op}() requires that the document contains an ID ("_id" property)`)
41
41
  }
@@ -43,7 +43,7 @@ export const requireDocumentId = (op: string, doc: Record<string, FIXME>) => {
43
43
  validateDocumentId(op, doc._id)
44
44
  }
45
45
 
46
- export const validateInsert = (at: string, selector: string, items: FIXME[]) => {
46
+ export const validateInsert = (at: string, selector: string, items: Any[]) => {
47
47
  const signature = 'insert(at, selector, items)'
48
48
  if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
49
49
  const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(', ')
package/src/warnings.ts CHANGED
@@ -1,10 +1,10 @@
1
- import generateHelpUrl from './generateHelpUrl'
2
- import {FIXME} from './types'
3
- import once from './util/once'
1
+ import {generateHelpUrl} from './generateHelpUrl'
2
+ import {Any} from './types'
3
+ import {once} from './util/once'
4
4
 
5
5
  const createWarningPrinter = (message: string[]) =>
6
6
  // eslint-disable-next-line no-console
7
- once((...args: FIXME[]) => console.warn(message.join(' '), ...args))
7
+ once((...args: Any[]) => console.warn(message.join(' '), ...args))
8
8
 
9
9
  export const printCdnWarning = createWarningPrinter([
10
10
  'You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and',
@@ -24,3 +24,7 @@ export const printNoApiVersionSpecifiedWarning = createWarningPrinter([
24
24
  'Using the Sanity client without specifying an API version is deprecated.',
25
25
  `See ${generateHelpUrl('js-client-api-version')}`,
26
26
  ])
27
+
28
+ export const printNoDefaultExport = createWarningPrinter([
29
+ 'The default export of @sanity/client has been deprecated. Use the named export `createClient` instead',
30
+ ])
@@ -1631,23 +1631,8 @@
1631
1631
 
1632
1632
  function noop() { }
1633
1633
 
1634
- var context = null;
1635
1634
  function errorContext(cb) {
1636
- if (config.useDeprecatedSynchronousErrorHandling) {
1637
- var isRoot = !context;
1638
- if (isRoot) {
1639
- context = { errorThrown: false, error: null };
1640
- }
1641
- cb();
1642
- if (isRoot) {
1643
- var _a = context, errorThrown = _a.errorThrown, error = _a.error;
1644
- context = null;
1645
- if (errorThrown) {
1646
- throw error;
1647
- }
1648
- }
1649
- }
1650
- else {
1635
+ {
1651
1636
  cb();
1652
1637
  }
1653
1638
  }
@@ -3185,7 +3170,7 @@
3185
3170
  return httpRequest;
3186
3171
  }
3187
3172
  const projectHeader = "X-Sanity-Project-ID";
3188
- var getRequestOptions = function (config) {
3173
+ function requestOptions(config) {
3189
3174
  let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3190
3175
  const headers = {};
3191
3176
  const token = overrides.token || config.token;
@@ -3204,7 +3189,7 @@
3204
3189
  json: true,
3205
3190
  withCredentials
3206
3191
  });
3207
- };
3192
+ }
3208
3193
  function getSelection(sel) {
3209
3194
  if (typeof sel === "string" || Array.isArray(sel)) {
3210
3195
  return {
@@ -3280,7 +3265,7 @@
3280
3265
  }
3281
3266
  return tag;
3282
3267
  };
3283
- var encodeQueryString = _ref => {
3268
+ const encodeQueryString = _ref => {
3284
3269
  let {
3285
3270
  query,
3286
3271
  params = {},
@@ -3885,7 +3870,7 @@
3885
3870
  ...options.query
3886
3871
  };
3887
3872
  }
3888
- const reqOptions = getRequestOptions(config, Object.assign({}, options, {
3873
+ const reqOptions = requestOptions(config, Object.assign({}, options, {
3889
3874
  url: _getUrl(client, uri, useCdn)
3890
3875
  }));
3891
3876
  const request = new Observable(subscriber =>
@@ -4041,7 +4026,7 @@
4041
4026
  function generateHelpUrl(slug) {
4042
4027
  return BASE_URL + slug;
4043
4028
  }
4044
- var once = fn => {
4029
+ function once(fn) {
4045
4030
  let didCall = false;
4046
4031
  let returnValue;
4047
4032
  return function () {
@@ -4052,7 +4037,7 @@
4052
4037
  didCall = true;
4053
4038
  return returnValue;
4054
4039
  };
4055
- };
4040
+ }
4056
4041
  const createWarningPrinter = message =>
4057
4042
  // eslint-disable-next-line no-console
4058
4043
  once(function () {
@@ -4064,6 +4049,7 @@
4064
4049
  const printCdnWarning = createWarningPrinter(["You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and", "cheaper. Think about it! For more info, see ".concat(generateHelpUrl("js-client-cdn-configuration"), " "), "To hide this warning, please set the `useCdn` option to either `true` or `false` when creating", "the client."]);
4065
4050
  const printBrowserTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.", "See ".concat(generateHelpUrl("js-client-browser-token"), " for more information and how to hide this warning.")]);
4066
4051
  const printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", "See ".concat(generateHelpUrl("js-client-api-version"))]);
4052
+ const printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead"]);
4067
4053
  const defaultCdnHost = "apicdn.sanity.io";
4068
4054
  const defaultConfig = {
4069
4055
  apiHost: "https://api.sanity.io",
@@ -4133,7 +4119,7 @@
4133
4119
  target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
4134
4120
  return target;
4135
4121
  }, {});
4136
- var pick = (obj, props) => props.reduce((selection, prop) => {
4122
+ const pick = (obj, props) => props.reduce((selection, prop) => {
4137
4123
  if (typeof obj[prop] === "undefined") {
4138
4124
  return selection;
4139
4125
  }
@@ -4818,12 +4804,13 @@
4818
4804
  let SanityClient = _SanityClient;
4819
4805
  _clientConfig2 = new WeakMap();
4820
4806
  _httpRequest2 = new WeakMap();
4821
- function migrationNotice() {
4822
- throw new TypeError("The default export of @sanity/client has been deprecated. Use the named export `createClient` instead");
4823
- }
4824
4807
  const httpRequest = defineHttpRequest(envMiddleware);
4825
4808
  const requester = httpRequest.defaultRequester;
4826
4809
  const createClient = config => new SanityClient(httpRequest, config);
4810
+ function deprecatedCreateClient(config) {
4811
+ printNoDefaultExport();
4812
+ return new SanityClient(httpRequest, config);
4813
+ }
4827
4814
 
4828
4815
  exports.BasePatch = BasePatch;
4829
4816
  exports.BaseTransaction = BaseTransaction;
@@ -4836,7 +4823,7 @@
4836
4823
  exports.ServerError = ServerError;
4837
4824
  exports.Transaction = Transaction;
4838
4825
  exports.createClient = createClient;
4839
- exports.default = migrationNotice;
4826
+ exports.default = deprecatedCreateClient;
4840
4827
  exports.requester = requester;
4841
4828
 
4842
4829
  Object.defineProperty(exports, '__esModule', { value: true });