@sanity/client 7.1.0-views.0 → 7.1.0-views.1

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.
Files changed (80) hide show
  1. package/README.md +668 -40
  2. package/dist/_chunks-cjs/config.cjs +14 -0
  3. package/dist/_chunks-cjs/config.cjs.map +1 -1
  4. package/dist/_chunks-cjs/dataMethods.cjs +197 -32
  5. package/dist/_chunks-cjs/dataMethods.cjs.map +1 -1
  6. package/dist/_chunks-cjs/isRecord.cjs +6 -0
  7. package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
  8. package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
  9. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
  10. package/dist/_chunks-cjs/stegaClean.cjs +4 -0
  11. package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
  12. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
  13. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
  14. package/dist/_chunks-es/config.js +15 -1
  15. package/dist/_chunks-es/config.js.map +1 -1
  16. package/dist/_chunks-es/dataMethods.js +200 -33
  17. package/dist/_chunks-es/dataMethods.js.map +1 -1
  18. package/dist/_chunks-es/isRecord.js +7 -0
  19. package/dist/_chunks-es/isRecord.js.map +1 -0
  20. package/dist/_chunks-es/resolveEditInfo.js +1 -3
  21. package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
  22. package/dist/_chunks-es/stegaClean.js +4 -0
  23. package/dist/_chunks-es/stegaClean.js.map +1 -1
  24. package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
  25. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
  26. package/dist/index.browser.cjs +1019 -59
  27. package/dist/index.browser.cjs.map +1 -1
  28. package/dist/index.browser.d.cts +1948 -149
  29. package/dist/index.browser.d.ts +1948 -149
  30. package/dist/index.browser.js +1021 -60
  31. package/dist/index.browser.js.map +1 -1
  32. package/dist/index.cjs +825 -29
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +1948 -149
  35. package/dist/index.d.ts +1948 -149
  36. package/dist/index.js +826 -31
  37. package/dist/index.js.map +1 -1
  38. package/dist/stega.browser.d.cts +1948 -149
  39. package/dist/stega.browser.d.ts +1948 -149
  40. package/dist/stega.d.cts +1948 -149
  41. package/dist/stega.d.ts +1948 -149
  42. package/dist/views.cjs +13 -5
  43. package/dist/views.cjs.map +1 -1
  44. package/dist/views.d.cts +51 -36
  45. package/dist/views.d.ts +51 -36
  46. package/dist/views.js +14 -5
  47. package/dist/views.js.map +1 -1
  48. package/package.json +2 -1
  49. package/src/SanityClient.ts +652 -12
  50. package/src/agent/actions/AgentActionsClient.ts +29 -2
  51. package/src/agent/actions/commonTypes.ts +57 -17
  52. package/src/agent/actions/generate.ts +36 -2
  53. package/src/agent/actions/patch.ts +136 -0
  54. package/src/agent/actions/prompt.ts +145 -0
  55. package/src/agent/actions/transform.ts +105 -7
  56. package/src/agent/actions/translate.ts +5 -2
  57. package/src/config.ts +3 -1
  58. package/src/csm/walkMap.ts +1 -1
  59. package/src/data/dataMethods.ts +170 -12
  60. package/src/data/encodeQueryString.ts +1 -1
  61. package/src/data/eventsource.ts +16 -7
  62. package/src/data/listen.ts +10 -4
  63. package/src/data/live.ts +13 -5
  64. package/src/datasets/DatasetsClient.ts +4 -1
  65. package/src/defineCreateClient.ts +7 -1
  66. package/src/http/errors.ts +92 -27
  67. package/src/http/request.ts +3 -3
  68. package/src/http/requestOptions.ts +4 -0
  69. package/src/projects/ProjectsClient.ts +6 -2
  70. package/src/releases/ReleasesClient.ts +693 -0
  71. package/src/releases/createRelease.ts +53 -0
  72. package/src/types.ts +291 -10
  73. package/src/users/UsersClient.ts +7 -3
  74. package/src/util/codeFrame.ts +174 -0
  75. package/src/util/createVersionId.ts +79 -0
  76. package/src/{csm → util}/isRecord.ts +1 -1
  77. package/src/validators.ts +23 -1
  78. package/src/views/index.ts +51 -15
  79. package/umd/sanityClient.js +1067 -61
  80. package/umd/sanityClient.min.js +2 -2
package/dist/views.cjs CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var rxjs = require("rxjs"), dataMethods = require("./_chunks-cjs/dataMethods.cjs"), config = require("./_chunks-cjs/config.cjs");
3
+ var client = require("@sanity/client"), rxjs = require("rxjs"), config = require("./_chunks-cjs/config.cjs"), dataMethods = require("./_chunks-cjs/dataMethods.cjs");
4
+ function hasDatasetConnections(viewId, viewOverrides) {
5
+ if (!viewOverrides) return !1;
6
+ const viewOverride = viewOverrides.find((override) => override.id === viewId);
7
+ return !viewOverride || !viewOverride.connections.length ? !1 : viewOverride.connections.some((conn) => conn.resourceType === client.ViewResourceType.Dataset);
8
+ }
4
9
  function createViewClient(config2) {
5
10
  const clientRequester = dataMethods.defineHttpRequest([]);
6
11
  return new ViewClient(
@@ -43,7 +48,7 @@ class ViewClient {
43
48
  * @param options - Request options
44
49
  */
45
50
  fetch(viewId, query, params, options) {
46
- const cfg = config.initConfig(
51
+ const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId), connections = useEmulate ? viewOverride?.connections || [] : void 0, cfg = config.initConfig(
47
52
  {
48
53
  "~experimental_resource": {
49
54
  id: viewId,
@@ -54,7 +59,9 @@ class ViewClient {
54
59
  ), opts = {
55
60
  returnQuery: !1,
56
61
  ...options,
57
- useCdn: !0
62
+ useCdn: !0,
63
+ useEmulate,
64
+ connections
58
65
  };
59
66
  return rxjs.lastValueFrom(dataMethods._fetch(cfg, this.#httpRequest, { enabled: !1 }, query, params, opts));
60
67
  }
@@ -77,7 +84,7 @@ class ObservableViewClient {
77
84
  });
78
85
  }
79
86
  fetch(viewId, query, params, options) {
80
- const cfg = config.initConfig(
87
+ const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId), connections = useEmulateEndpoint ? viewOverride?.connections || [] : void 0, cfg = config.initConfig(
81
88
  {
82
89
  "~experimental_resource": {
83
90
  id: viewId,
@@ -89,7 +96,8 @@ class ObservableViewClient {
89
96
  returnQuery: !1,
90
97
  ...options,
91
98
  useCdn: !0,
92
- perspective: "published"
99
+ useEmulate: useEmulateEndpoint,
100
+ connections
93
101
  };
94
102
  return dataMethods._fetch(cfg, this.#httpRequest, { enabled: !1 }, query, params, opts);
95
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"views.cjs","sources":["../src/views/index.ts"],"sourcesContent":["import {lastValueFrom, Observable} from 'rxjs'\nimport {type QueryParams, type QueryWithoutParams} from '@sanity/client'\nimport type {\n ClientReturn,\n RawQueryResponse,\n HttpRequest,\n QueryOptions,\n ClientConfig,\n Any,\n} from '../types'\nimport {_fetch} from '../data/dataMethods'\nimport {initConfig} from '../config'\nimport {defineHttpRequest} from '../http/request'\n\n/** @public */\nexport interface ViewClientConfig extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {\n // TODO: Add our own config options\n}\n\n/**\n * Creates a new ViewClient instance with the given configuration\n *\n * @param config - Configuration for the ViewClient\n * @public\n */\nexport function createViewClient(config: ViewClientConfig): ViewClient {\n const clientRequester = defineHttpRequest([])\n return new ViewClient(\n (options, requester) =>\n (requester || clientRequester)({\n maxRedirects: 0,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n ...options,\n } as Any),\n config,\n )\n}\n\n/** @public */\nexport type ViewQueryOptions = Pick<QueryOptions, 'perspective' | 'resultSourceMap' | 'filterResponse'>\n\n/** @public */\nexport class ViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n /**\n * Observable version of the view client, with the same configuration as the promise-based one\n */\n observable: ObservableViewClient\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n\n this.observable = new ObservableViewClient(httpRequest, config)\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ViewClient {\n return new ViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n * @param params - Optional query parameters\n * @param options - Request options\n */\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts = {\n returnQuery: false,\n ...options,\n useCdn: true,\n }\n\n return lastValueFrom(_fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts))\n }\n}\n\n/** @public */\nexport class ObservableViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ObservableViewClient {\n return new ObservableViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts: QueryOptions = {\n returnQuery: false,\n ...options,\n useCdn: true,\n perspective: 'published',\n }\n\n return _fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts)\n }\n}\n"],"names":["config","defineHttpRequest","initConfig","lastValueFrom","_fetch"],"mappings":";;;AAyBO,SAAS,iBAAiBA,SAAsC;AAC/D,QAAA,kBAAkBC,YAAkB,kBAAA,EAAE;AAC5C,SAAO,IAAI;AAAA,IACT,CAAC,SAAS,eACP,aAAa,iBAAiB;AAAA,MAC7B,cAAc;AAAA,MACd,YAAYD,QAAO;AAAA,MACnB,YAAYA,QAAO;AAAA,MACnB,GAAG;AAAA,IAAA,CACG;AAAA,IACVA;AAAA,EACF;AACF;AAMO,MAAM,WAAW;AAAA,EACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,YAAY,aAA0BA,SAA0B;AACzD,SAAA,UAAUA,SACf,KAAK,eAAe,aAEpB,KAAK,aAAa,IAAI,qBAAqB,aAAaA,OAAM;AAAA,EAAA;AAAA;AA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;;;;"}
1
+ {"version":3,"file":"views.cjs","sources":["../src/views/index.ts"],"sourcesContent":["import {\n type QueryParams,\n type QueryWithoutParams,\n type ViewOverride,\n ViewResourceType,\n} from '@sanity/client'\nimport {lastValueFrom, Observable} from 'rxjs'\n\nimport {initConfig} from '../config'\nimport {_fetch} from '../data/dataMethods'\nimport {defineHttpRequest} from '../http/request'\nimport type {\n Any,\n ClientConfig,\n ClientReturn,\n HttpRequest,\n RawQueryResponse,\n ViewQueryOptions,\n} from '../types'\n\n/**\n * Helper function to check if a view has any dataset connections\n * @internal\n */\nfunction hasDatasetConnections(viewId: string, viewOverrides?: ViewOverride[]): boolean {\n if (!viewOverrides) return false\n\n const viewOverride = viewOverrides.find((override) => override.id === viewId)\n if (!viewOverride || !viewOverride.connections.length) return false\n\n // Check if any connection has dataset resourceType\n return viewOverride.connections.some((conn) => conn.resourceType === ViewResourceType.Dataset)\n}\n\n/** @public */\nexport interface ViewClientConfig\n extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {\n viewOverrides?: ViewOverride[]\n apiVersion: string\n}\n\n/**\n * Creates a new ViewClient instance with the given configuration\n *\n * @param config - Configuration for the ViewClient\n * @public\n */\nexport function createViewClient(config: ViewClientConfig): ViewClient {\n const clientRequester = defineHttpRequest([])\n return new ViewClient(\n (options, requester) =>\n (requester || clientRequester)({\n maxRedirects: 0,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n ...options,\n } as Any),\n config,\n )\n}\n\n/** @public */\nexport class ViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n /**\n * Observable version of the view client, with the same configuration as the promise-based one\n */\n observable: ObservableViewClient\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n\n this.observable = new ObservableViewClient(httpRequest, config)\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ViewClient {\n return new ViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n * @param params - Optional query parameters\n * @param options - Request options\n */\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n // Check if this view has dataset connections\n const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides)\n\n // Get connections for this view if using emulate endpoint\n const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)\n const connections = useEmulate ? viewOverride?.connections || [] : undefined\n\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts = {\n returnQuery: false,\n ...options,\n useCdn: true,\n useEmulate,\n connections,\n }\n\n return lastValueFrom(_fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts))\n }\n}\n\n/** @public */\nexport class ObservableViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ObservableViewClient {\n return new ObservableViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n // Check if this view has dataset connections\n const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides)\n\n // Get connections for this view if using emulate endpoint\n const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)\n const connections = useEmulateEndpoint ? viewOverride?.connections || [] : undefined\n\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts = {\n returnQuery: false,\n ...options,\n useCdn: true,\n useEmulate: useEmulateEndpoint,\n connections,\n }\n\n return _fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts)\n }\n}\n"],"names":["ViewResourceType","config","defineHttpRequest","initConfig","lastValueFrom","_fetch"],"mappings":";;;AAwBA,SAAS,sBAAsB,QAAgB,eAAyC;AAClF,MAAA,CAAC,cAAsB,QAAA;AAE3B,QAAM,eAAe,cAAc,KAAK,CAAC,aAAa,SAAS,OAAO,MAAM;AAC5E,SAAI,CAAC,gBAAgB,CAAC,aAAa,YAAY,SAAe,KAGvD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C,SAAS,GAAA,GAAQ,OAAO,QAAQ,IAAI,CAAC;AAAA,EAAA;AAE9F;AAGO,MAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EAEA,YAAY,aAA0BJ,SAA0B;AACzD,SAAA,UAAUA,SACf,KAAK,eAAe;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtB,WAAW,WAA6D;AAC/D,WAAA,IAAI,qBAAqB,KAAK,cAAc;AAAA,MACjD,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IAAA,CACJ;AAAA,EAAA;AAAA,EAwBH,MACE,QACA,OACA,QACA,SACuE;AAEjE,UAAA,qBAAqB,sBAAsB,QAAQ,KAAK,QAAQ,aAAa,GAG7E,eAAe,KAAK,QAAQ,eAAe,KAAK,CAAC,aAAa,SAAS,OAAO,MAAM,GACpF,cAAc,qBAAqB,cAAc,eAAe,CAAA,IAAK,QAErE,MAAME,OAAA;AAAA,MACV;AAAA,QACE,0BAA0B;AAAA,UACxB,IAAI;AAAA,UACJ,MAAM;AAAA,QAAA;AAAA,MAEV;AAAA,MACA,KAAK;AAAA,OAED,OAAO;AAAA,MACX,aAAa;AAAA,MACb,GAAG;AAAA,MACH,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ;AAAA,IACF;AAEO,WAAAE,mBAAO,KAAK,KAAK,cAAc,EAAC,SAAS,MAAQ,OAAO,QAAQ,IAAI;AAAA,EAAA;AAE/E;;;;"}
package/dist/views.d.cts CHANGED
@@ -35,6 +35,12 @@ declare interface ClientConfig {
35
35
  * Optional request tag prefix for all request tags
36
36
  */
37
37
  requestTagPrefix?: string
38
+ /**
39
+ * Optional default headers to include with all requests
40
+ *
41
+ * @remarks request-specific headers will override any default headers with the same name.
42
+ */
43
+ headers?: Record<string, string>
38
44
  ignoreBrowserTokenWarning?: boolean
39
45
  withCredentials?: boolean
40
46
  allowReconfigure?: boolean
@@ -97,6 +103,7 @@ declare type ClientConfigResource =
97
103
  | {
98
104
  type: 'view'
99
105
  id: string
106
+ useEmulate?: boolean
100
107
  }
101
108
 
102
109
  /** @public */
@@ -245,6 +252,14 @@ export declare function createViewClient(config: ViewClientConfig): ViewClient
245
252
  */
246
253
  declare type DeprecatedPreviewDrafts = 'previewDrafts'
247
254
 
255
+ /** @public */
256
+ declare interface EmulatedResponseQueryOptions extends ResponseQueryOptions {
257
+ useEmulate: boolean
258
+ connections?: ViewConnectionOverride_2[] | undefined
259
+ filterResponse?: false
260
+ returnQuery?: false
261
+ }
262
+
248
263
  /** @public */
249
264
  declare type FilterDefault = (props: {
250
265
  /**
@@ -294,11 +309,6 @@ declare type FilterDefault = (props: {
294
309
  filterDefault: FilterDefault
295
310
  }) => boolean
296
311
 
297
- /** @public */
298
- declare interface FilteredResponseQueryOptions extends ResponseQueryOptions {
299
- filterResponse?: true
300
- }
301
-
302
312
  /** @public */
303
313
  declare type HttpRequest = {
304
314
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -344,12 +354,6 @@ export declare class ObservableViewClient {
344
354
  ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>
345
355
  }
346
356
 
347
- /** @public */
348
- declare type QueryOptions =
349
- | FilteredResponseQueryOptions
350
- | UnfilteredResponseQueryOptions
351
- | UnfilteredResponseWithoutQuery
352
-
353
357
  /** @public */
354
358
  declare interface QueryParams {
355
359
  [key: string]: any
@@ -493,28 +497,6 @@ declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
493
497
  /** @public */
494
498
  declare type SyncTag = `s1:${string}`
495
499
 
496
- /** @public */
497
- declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
498
- filterResponse: false
499
- /**
500
- * When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
501
- * backwards compatibility (on the client side, not from the content lake API).
502
- * Can also explicitly be set to `true`.
503
- */
504
- returnQuery?: true
505
- }
506
-
507
- /**
508
- * When using `filterResponse: false`, but you do not wish to receive back the query from
509
- * the content lake API.
510
- *
511
- * @public
512
- */
513
- declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
514
- filterResponse: false
515
- returnQuery: false
516
- }
517
-
518
500
  /** @public */
519
501
  export declare class ViewClient {
520
502
  #private
@@ -554,12 +536,45 @@ export declare class ViewClient {
554
536
 
555
537
  /** @public */
556
538
  export declare interface ViewClientConfig
557
- extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {}
539
+ extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {
540
+ viewOverrides?: ViewOverride[]
541
+ apiVersion: string
542
+ }
543
+
544
+ /** @public */
545
+ declare type ViewConnectionOverride = {
546
+ query: string
547
+ resourceType: ViewResourceType
548
+ resourceId: string
549
+ }
550
+
551
+ /** @public */
552
+ declare type ViewConnectionOverride_2 = {
553
+ query: string
554
+ resourceType: ViewResourceType_2
555
+ resourceId: string
556
+ }
558
557
 
559
558
  /** @public */
560
- export declare type ViewQueryOptions = Pick<
561
- QueryOptions,
559
+ declare type ViewOverride = {
560
+ id: string
561
+ connections: ViewConnectionOverride[]
562
+ }
563
+
564
+ /** @public */
565
+ declare type ViewQueryOptions = Pick<
566
+ EmulatedResponseQueryOptions,
562
567
  'perspective' | 'resultSourceMap' | 'filterResponse'
563
568
  >
564
569
 
570
+ /** @public */
571
+ declare enum ViewResourceType {
572
+ Dataset = 'dataset',
573
+ }
574
+
575
+ /** @public */
576
+ declare enum ViewResourceType_2 {
577
+ Dataset = 'dataset',
578
+ }
579
+
565
580
  export {}
package/dist/views.d.ts CHANGED
@@ -35,6 +35,12 @@ declare interface ClientConfig {
35
35
  * Optional request tag prefix for all request tags
36
36
  */
37
37
  requestTagPrefix?: string
38
+ /**
39
+ * Optional default headers to include with all requests
40
+ *
41
+ * @remarks request-specific headers will override any default headers with the same name.
42
+ */
43
+ headers?: Record<string, string>
38
44
  ignoreBrowserTokenWarning?: boolean
39
45
  withCredentials?: boolean
40
46
  allowReconfigure?: boolean
@@ -97,6 +103,7 @@ declare type ClientConfigResource =
97
103
  | {
98
104
  type: 'view'
99
105
  id: string
106
+ useEmulate?: boolean
100
107
  }
101
108
 
102
109
  /** @public */
@@ -245,6 +252,14 @@ export declare function createViewClient(config: ViewClientConfig): ViewClient
245
252
  */
246
253
  declare type DeprecatedPreviewDrafts = 'previewDrafts'
247
254
 
255
+ /** @public */
256
+ declare interface EmulatedResponseQueryOptions extends ResponseQueryOptions {
257
+ useEmulate: boolean
258
+ connections?: ViewConnectionOverride_2[] | undefined
259
+ filterResponse?: false
260
+ returnQuery?: false
261
+ }
262
+
248
263
  /** @public */
249
264
  declare type FilterDefault = (props: {
250
265
  /**
@@ -294,11 +309,6 @@ declare type FilterDefault = (props: {
294
309
  filterDefault: FilterDefault
295
310
  }) => boolean
296
311
 
297
- /** @public */
298
- declare interface FilteredResponseQueryOptions extends ResponseQueryOptions {
299
- filterResponse?: true
300
- }
301
-
302
312
  /** @public */
303
313
  declare type HttpRequest = {
304
314
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -344,12 +354,6 @@ export declare class ObservableViewClient {
344
354
  ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>
345
355
  }
346
356
 
347
- /** @public */
348
- declare type QueryOptions =
349
- | FilteredResponseQueryOptions
350
- | UnfilteredResponseQueryOptions
351
- | UnfilteredResponseWithoutQuery
352
-
353
357
  /** @public */
354
358
  declare interface QueryParams {
355
359
  [key: string]: any
@@ -493,28 +497,6 @@ declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
493
497
  /** @public */
494
498
  declare type SyncTag = `s1:${string}`
495
499
 
496
- /** @public */
497
- declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
498
- filterResponse: false
499
- /**
500
- * When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
501
- * backwards compatibility (on the client side, not from the content lake API).
502
- * Can also explicitly be set to `true`.
503
- */
504
- returnQuery?: true
505
- }
506
-
507
- /**
508
- * When using `filterResponse: false`, but you do not wish to receive back the query from
509
- * the content lake API.
510
- *
511
- * @public
512
- */
513
- declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
514
- filterResponse: false
515
- returnQuery: false
516
- }
517
-
518
500
  /** @public */
519
501
  export declare class ViewClient {
520
502
  #private
@@ -554,12 +536,45 @@ export declare class ViewClient {
554
536
 
555
537
  /** @public */
556
538
  export declare interface ViewClientConfig
557
- extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {}
539
+ extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {
540
+ viewOverrides?: ViewOverride[]
541
+ apiVersion: string
542
+ }
543
+
544
+ /** @public */
545
+ declare type ViewConnectionOverride = {
546
+ query: string
547
+ resourceType: ViewResourceType
548
+ resourceId: string
549
+ }
550
+
551
+ /** @public */
552
+ declare type ViewConnectionOverride_2 = {
553
+ query: string
554
+ resourceType: ViewResourceType_2
555
+ resourceId: string
556
+ }
558
557
 
559
558
  /** @public */
560
- export declare type ViewQueryOptions = Pick<
561
- QueryOptions,
559
+ declare type ViewOverride = {
560
+ id: string
561
+ connections: ViewConnectionOverride[]
562
+ }
563
+
564
+ /** @public */
565
+ declare type ViewQueryOptions = Pick<
566
+ EmulatedResponseQueryOptions,
562
567
  'perspective' | 'resultSourceMap' | 'filterResponse'
563
568
  >
564
569
 
570
+ /** @public */
571
+ declare enum ViewResourceType {
572
+ Dataset = 'dataset',
573
+ }
574
+
575
+ /** @public */
576
+ declare enum ViewResourceType_2 {
577
+ Dataset = 'dataset',
578
+ }
579
+
565
580
  export {}
package/dist/views.js CHANGED
@@ -1,6 +1,12 @@
1
+ import { ViewResourceType } from "@sanity/client";
1
2
  import { lastValueFrom } from "rxjs";
2
- import { defineHttpRequest, _fetch } from "./_chunks-es/dataMethods.js";
3
3
  import { initConfig } from "./_chunks-es/config.js";
4
+ import { defineHttpRequest, _fetch } from "./_chunks-es/dataMethods.js";
5
+ function hasDatasetConnections(viewId, viewOverrides) {
6
+ if (!viewOverrides) return !1;
7
+ const viewOverride = viewOverrides.find((override) => override.id === viewId);
8
+ return !viewOverride || !viewOverride.connections.length ? !1 : viewOverride.connections.some((conn) => conn.resourceType === ViewResourceType.Dataset);
9
+ }
4
10
  function createViewClient(config) {
5
11
  const clientRequester = defineHttpRequest([]);
6
12
  return new ViewClient(
@@ -43,7 +49,7 @@ class ViewClient {
43
49
  * @param options - Request options
44
50
  */
45
51
  fetch(viewId, query, params, options) {
46
- const cfg = initConfig(
52
+ const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId), connections = useEmulate ? viewOverride?.connections || [] : void 0, cfg = initConfig(
47
53
  {
48
54
  "~experimental_resource": {
49
55
  id: viewId,
@@ -54,7 +60,9 @@ class ViewClient {
54
60
  ), opts = {
55
61
  returnQuery: !1,
56
62
  ...options,
57
- useCdn: !0
63
+ useCdn: !0,
64
+ useEmulate,
65
+ connections
58
66
  };
59
67
  return lastValueFrom(_fetch(cfg, this.#httpRequest, { enabled: !1 }, query, params, opts));
60
68
  }
@@ -77,7 +85,7 @@ class ObservableViewClient {
77
85
  });
78
86
  }
79
87
  fetch(viewId, query, params, options) {
80
- const cfg = initConfig(
88
+ const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId), connections = useEmulateEndpoint ? viewOverride?.connections || [] : void 0, cfg = initConfig(
81
89
  {
82
90
  "~experimental_resource": {
83
91
  id: viewId,
@@ -89,7 +97,8 @@ class ObservableViewClient {
89
97
  returnQuery: !1,
90
98
  ...options,
91
99
  useCdn: !0,
92
- perspective: "published"
100
+ useEmulate: useEmulateEndpoint,
101
+ connections
93
102
  };
94
103
  return _fetch(cfg, this.#httpRequest, { enabled: !1 }, query, params, opts);
95
104
  }
package/dist/views.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"views.js","sources":["../src/views/index.ts"],"sourcesContent":["import {lastValueFrom, Observable} from 'rxjs'\nimport {type QueryParams, type QueryWithoutParams} from '@sanity/client'\nimport type {\n ClientReturn,\n RawQueryResponse,\n HttpRequest,\n QueryOptions,\n ClientConfig,\n Any,\n} from '../types'\nimport {_fetch} from '../data/dataMethods'\nimport {initConfig} from '../config'\nimport {defineHttpRequest} from '../http/request'\n\n/** @public */\nexport interface ViewClientConfig extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {\n // TODO: Add our own config options\n}\n\n/**\n * Creates a new ViewClient instance with the given configuration\n *\n * @param config - Configuration for the ViewClient\n * @public\n */\nexport function createViewClient(config: ViewClientConfig): ViewClient {\n const clientRequester = defineHttpRequest([])\n return new ViewClient(\n (options, requester) =>\n (requester || clientRequester)({\n maxRedirects: 0,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n ...options,\n } as Any),\n config,\n )\n}\n\n/** @public */\nexport type ViewQueryOptions = Pick<QueryOptions, 'perspective' | 'resultSourceMap' | 'filterResponse'>\n\n/** @public */\nexport class ViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n /**\n * Observable version of the view client, with the same configuration as the promise-based one\n */\n observable: ObservableViewClient\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n\n this.observable = new ObservableViewClient(httpRequest, config)\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ViewClient {\n return new ViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n * @param params - Optional query parameters\n * @param options - Request options\n */\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts = {\n returnQuery: false,\n ...options,\n useCdn: true,\n }\n\n return lastValueFrom(_fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts))\n }\n}\n\n/** @public */\nexport class ObservableViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ObservableViewClient {\n return new ObservableViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts: QueryOptions = {\n returnQuery: false,\n ...options,\n useCdn: true,\n perspective: 'published',\n }\n\n return _fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts)\n }\n}\n"],"names":[],"mappings":";;;AAyBO,SAAS,iBAAiB,QAAsC;AAC/D,QAAA,kBAAkB,kBAAkB,EAAE;AAC5C,SAAO,IAAI;AAAA,IACT,CAAC,SAAS,eACP,aAAa,iBAAiB;AAAA,MAC7B,cAAc;AAAA,MACd,YAAY,OAAO;AAAA,MACnB,YAAY,OAAO;AAAA,MACnB,GAAG;AAAA,IAAA,CACG;AAAA,IACV;AAAA,EACF;AACF;AAMO,MAAM,WAAW;AAAA,EACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,YAAY,aAA0B,QAA0B;AACzD,SAAA,UAAU,QACf,KAAK,eAAe,aAEpB,KAAK,aAAa,IAAI,qBAAqB,aAAa,MAAM;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhE,WAAW,WAAmD;AACrD,WAAA,IAAI,WAAW,KAAK,cAAc;AAAA,MACvC,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IAAA,CACJ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgCH,MACE,QACA,OACA,QACA,SACoE;AACpE,UAAM,MAAM;AAAA,MACV;AAAA,QACE,0BAA0B;AAAA,UACxB,IAAI;AAAA,UACJ,MAAM;AAAA,QAAA;AAAA,MAEV;AAAA,MACA,KAAK;AAAA,OAED,OAAO;AAAA,MACX,aAAa;AAAA,MACb,GAAG;AAAA,MACH,QAAQ;AAAA,IACV;AAEA,WAAO,cAAc,OAAO,KAAK,KAAK,cAAc,EAAC,SAAS,GAAA,GAAQ,OAAO,QAAQ,IAAI,CAAC;AAAA,EAAA;AAE9F;AAGO,MAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EAEA,YAAY,aAA0B,QAA0B;AACzD,SAAA,UAAU,QACf,KAAK,eAAe;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtB,WAAW,WAA6D;AAC/D,WAAA,IAAI,qBAAqB,KAAK,cAAc;AAAA,MACjD,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IAAA,CACJ;AAAA,EAAA;AAAA,EAwBH,MACE,QACA,OACA,QACA,SACuE;AACvE,UAAM,MAAM;AAAA,MACV;AAAA,QACE,0BAA0B;AAAA,UACxB,IAAI;AAAA,UACJ,MAAM;AAAA,QAAA;AAAA,MAEV;AAAA,MACA,KAAK;AAAA,OAED,OAAqB;AAAA,MACzB,aAAa;AAAA,MACb,GAAG;AAAA,MACH,QAAQ;AAAA,MACR,aAAa;AAAA,IACf;AAEO,WAAA,OAAO,KAAK,KAAK,cAAc,EAAC,SAAS,MAAQ,OAAO,QAAQ,IAAI;AAAA,EAAA;AAE/E;"}
1
+ {"version":3,"file":"views.js","sources":["../src/views/index.ts"],"sourcesContent":["import {\n type QueryParams,\n type QueryWithoutParams,\n type ViewOverride,\n ViewResourceType,\n} from '@sanity/client'\nimport {lastValueFrom, Observable} from 'rxjs'\n\nimport {initConfig} from '../config'\nimport {_fetch} from '../data/dataMethods'\nimport {defineHttpRequest} from '../http/request'\nimport type {\n Any,\n ClientConfig,\n ClientReturn,\n HttpRequest,\n RawQueryResponse,\n ViewQueryOptions,\n} from '../types'\n\n/**\n * Helper function to check if a view has any dataset connections\n * @internal\n */\nfunction hasDatasetConnections(viewId: string, viewOverrides?: ViewOverride[]): boolean {\n if (!viewOverrides) return false\n\n const viewOverride = viewOverrides.find((override) => override.id === viewId)\n if (!viewOverride || !viewOverride.connections.length) return false\n\n // Check if any connection has dataset resourceType\n return viewOverride.connections.some((conn) => conn.resourceType === ViewResourceType.Dataset)\n}\n\n/** @public */\nexport interface ViewClientConfig\n extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {\n viewOverrides?: ViewOverride[]\n apiVersion: string\n}\n\n/**\n * Creates a new ViewClient instance with the given configuration\n *\n * @param config - Configuration for the ViewClient\n * @public\n */\nexport function createViewClient(config: ViewClientConfig): ViewClient {\n const clientRequester = defineHttpRequest([])\n return new ViewClient(\n (options, requester) =>\n (requester || clientRequester)({\n maxRedirects: 0,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n ...options,\n } as Any),\n config,\n )\n}\n\n/** @public */\nexport class ViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n /**\n * Observable version of the view client, with the same configuration as the promise-based one\n */\n observable: ObservableViewClient\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n\n this.observable = new ObservableViewClient(httpRequest, config)\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ViewClient {\n return new ViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n * @param params - Optional query parameters\n * @param options - Request options\n */\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n // Check if this view has dataset connections\n const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides)\n\n // Get connections for this view if using emulate endpoint\n const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)\n const connections = useEmulate ? viewOverride?.connections || [] : undefined\n\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts = {\n returnQuery: false,\n ...options,\n useCdn: true,\n useEmulate,\n connections,\n }\n\n return lastValueFrom(_fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts))\n }\n}\n\n/** @public */\nexport class ObservableViewClient {\n #config: ViewClientConfig\n #httpRequest: HttpRequest\n\n constructor(httpRequest: HttpRequest, config: ViewClientConfig) {\n this.#config = config\n this.#httpRequest = httpRequest\n }\n\n /**\n * Clone the client with a new (partial) configuration.\n *\n * @param newConfig - New client configuration properties, shallowly merged with existing configuration\n */\n withConfig(newConfig?: Partial<ViewClientConfig>): ObservableViewClient {\n return new ObservableViewClient(this.#httpRequest, {\n ...this.#config,\n ...newConfig,\n })\n }\n\n /**\n * Perform a GROQ-query against the configured view.\n *\n * @param viewId - ID of the view to query\n * @param query - GROQ-query to perform\n */\n fetch<\n R = Any,\n Q extends QueryWithoutParams = QueryWithoutParams,\n const G extends string = string,\n >(viewId: string, query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>\n fetch<\n R = Any,\n Q extends QueryWithoutParams | QueryParams = QueryParams,\n const G extends string = string,\n >(\n viewId: string,\n query: G,\n params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>>\n fetch<R, Q, const G extends string>(\n viewId: string,\n query: G,\n params?: Q,\n options?: ViewQueryOptions,\n ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {\n // Check if this view has dataset connections\n const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides)\n\n // Get connections for this view if using emulate endpoint\n const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)\n const connections = useEmulateEndpoint ? viewOverride?.connections || [] : undefined\n\n const cfg = initConfig(\n {\n '~experimental_resource': {\n id: viewId,\n type: 'view',\n },\n },\n this.#config,\n )\n const opts = {\n returnQuery: false,\n ...options,\n useCdn: true,\n useEmulate: useEmulateEndpoint,\n connections,\n }\n\n return _fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts)\n }\n}\n"],"names":[],"mappings":";;;;AAwBA,SAAS,sBAAsB,QAAgB,eAAyC;AAClF,MAAA,CAAC,cAAsB,QAAA;AAE3B,QAAM,eAAe,cAAc,KAAK,CAAC,aAAa,SAAS,OAAO,MAAM;AAC5E,SAAI,CAAC,gBAAgB,CAAC,aAAa,YAAY,SAAe,KAGvD,aAAa,YAAY,KAAK,CAAC,SAAS,KAAK,iBAAiB,iBAAiB,OAAO;AAC/F;AAeO,SAAS,iBAAiB,QAAsC;AAC/D,QAAA,kBAAkB,kBAAkB,EAAE;AAC5C,SAAO,IAAI;AAAA,IACT,CAAC,SAAS,eACP,aAAa,iBAAiB;AAAA,MAC7B,cAAc;AAAA,MACd,YAAY,OAAO;AAAA,MACnB,YAAY,OAAO;AAAA,MACnB,GAAG;AAAA,IAAA,CACG;AAAA,IACV;AAAA,EACF;AACF;AAGO,MAAM,WAAW;AAAA,EACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,YAAY,aAA0B,QAA0B;AACzD,SAAA,UAAU,QACf,KAAK,eAAe,aAEpB,KAAK,aAAa,IAAI,qBAAqB,aAA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c,qBAAqB,cAAc,eAAe,CAAA,IAAK,QAErE,MAAM;AAAA,MACV;AAAA,QACE,0BAA0B;AAAA,UACxB,IAAI;AAAA,UACJ,MAAM;AAAA,QAAA;AAAA,MAEV;AAAA,MACA,KAAK;AAAA,OAED,OAAO;AAAA,MACX,aAAa;AAAA,MACb,GAAG;AAAA,MACH,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ;AAAA,IACF;AAEO,WAAA,OAAO,KAAK,KAAK,cAAc,EAAC,SAAS,MAAQ,OAAO,QAAQ,IAAI;AAAA,EAAA;AAE/E;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.1.0-views.0",
3
+ "version": "7.1.0-views.1",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -102,6 +102,7 @@
102
102
  "benchmark": "npm test -- bench",
103
103
  "prebuild": "npm run clean",
104
104
  "build": "pkg build --strict && pkg --strict && npm run rollup && npm run minify",
105
+ "check-esm-compatibility": "node scripts/check-esm-compatibility.mjs",
105
106
  "clean": "npx rimraf dist coverage umd/*.js",
106
107
  "coverage": "vitest run --coverage",
107
108
  "lint": "eslint . --max-warnings 0",