@sanity/client 7.1.0-views.1 → 7.1.0-views.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.
@@ -6347,7 +6347,8 @@ export declare type ViewConnectionOverride = {
6347
6347
 
6348
6348
  /** @public */
6349
6349
  export declare type ViewOverride = {
6350
- id: string
6350
+ resourceType: ViewResourceType.View
6351
+ resourceId: string
6351
6352
  connections: ViewConnectionOverride[]
6352
6353
  }
6353
6354
 
@@ -6360,6 +6361,7 @@ export declare type ViewQueryOptions = Pick<
6360
6361
  /** @public */
6361
6362
  export declare enum ViewResourceType {
6362
6363
  Dataset = 'dataset',
6364
+ View = 'view',
6363
6365
  }
6364
6366
 
6365
6367
  /**
@@ -6347,7 +6347,8 @@ export declare type ViewConnectionOverride = {
6347
6347
 
6348
6348
  /** @public */
6349
6349
  export declare type ViewOverride = {
6350
- id: string
6350
+ resourceType: ViewResourceType.View
6351
+ resourceId: string
6351
6352
  connections: ViewConnectionOverride[]
6352
6353
  }
6353
6354
 
@@ -6360,6 +6361,7 @@ export declare type ViewQueryOptions = Pick<
6360
6361
  /** @public */
6361
6362
  export declare enum ViewResourceType {
6362
6363
  Dataset = 'dataset',
6364
+ View = 'view',
6363
6365
  }
6364
6366
 
6365
6367
  /**
package/dist/stega.d.cts CHANGED
@@ -6347,7 +6347,8 @@ export declare type ViewConnectionOverride = {
6347
6347
 
6348
6348
  /** @public */
6349
6349
  export declare type ViewOverride = {
6350
- id: string
6350
+ resourceType: ViewResourceType.View
6351
+ resourceId: string
6351
6352
  connections: ViewConnectionOverride[]
6352
6353
  }
6353
6354
 
@@ -6360,6 +6361,7 @@ export declare type ViewQueryOptions = Pick<
6360
6361
  /** @public */
6361
6362
  export declare enum ViewResourceType {
6362
6363
  Dataset = 'dataset',
6364
+ View = 'view',
6363
6365
  }
6364
6366
 
6365
6367
  /**
package/dist/stega.d.ts CHANGED
@@ -6347,7 +6347,8 @@ export declare type ViewConnectionOverride = {
6347
6347
 
6348
6348
  /** @public */
6349
6349
  export declare type ViewOverride = {
6350
- id: string
6350
+ resourceType: ViewResourceType.View
6351
+ resourceId: string
6351
6352
  connections: ViewConnectionOverride[]
6352
6353
  }
6353
6354
 
@@ -6360,6 +6361,7 @@ export declare type ViewQueryOptions = Pick<
6360
6361
  /** @public */
6361
6362
  export declare enum ViewResourceType {
6362
6363
  Dataset = 'dataset',
6364
+ View = 'view',
6363
6365
  }
6364
6366
 
6365
6367
  /**
package/dist/views.cjs CHANGED
@@ -3,10 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: !0 });
3
3
  var client = require("@sanity/client"), rxjs = require("rxjs"), config = require("./_chunks-cjs/config.cjs"), dataMethods = require("./_chunks-cjs/dataMethods.cjs");
4
4
  function hasDatasetConnections(viewId, viewOverrides) {
5
5
  if (!viewOverrides) return !1;
6
- const viewOverride = viewOverrides.find((override) => override.id === viewId);
6
+ const viewOverride = viewOverrides.find((override) => override.resourceId === viewId);
7
7
  return !viewOverride || !viewOverride.connections.length ? !1 : viewOverride.connections.some((conn) => conn.resourceType === client.ViewResourceType.Dataset);
8
8
  }
9
9
  function createViewClient(config2) {
10
+ config2.viewOverrides && config2.viewOverrides.forEach((override) => {
11
+ if (override.resourceType !== client.ViewResourceType.View)
12
+ throw new Error('View overrides only support resource type "view"');
13
+ });
10
14
  const clientRequester = dataMethods.defineHttpRequest([]);
11
15
  return new ViewClient(
12
16
  (options, requester) => (requester || clientRequester)({
@@ -48,7 +52,9 @@ class ViewClient {
48
52
  * @param options - Request options
49
53
  */
50
54
  fetch(viewId, query, params, options) {
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(
55
+ const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find(
56
+ (override) => override.resourceId === viewId
57
+ ), connections = useEmulate ? viewOverride?.connections || [] : void 0, cfg = config.initConfig(
52
58
  {
53
59
  "~experimental_resource": {
54
60
  id: viewId,
@@ -84,7 +90,9 @@ class ObservableViewClient {
84
90
  });
85
91
  }
86
92
  fetch(viewId, query, params, options) {
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(
93
+ const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find(
94
+ (override) => override.resourceId === viewId
95
+ ), connections = useEmulateEndpoint ? viewOverride?.connections || [] : void 0, cfg = config.initConfig(
88
96
  {
89
97
  "~experimental_resource": {
90
98
  id: viewId,
@@ -1 +1 @@
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,aAAa,YAAY,KAAK,CAAC,SAAS,KAAK,iBAAiBA,wBAAiB,OAAO;AAC/F;AAeO,SAAS,iBAAiBC,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;AAGO,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;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;AA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b,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;;;;"}
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.resourceId === 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 // Validate we have the correct view resourceType\n // Fail early if we don't.\n if (config.viewOverrides) {\n config.viewOverrides.forEach((override: ViewOverride) => {\n if (override.resourceType !== ViewResourceType.View) {\n throw new Error('View overrides only support resource type \"view\"')\n }\n })\n }\n\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(\n (override) => override.resourceId === viewId,\n )\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(\n (override) => override.resourceId === viewId,\n )\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,eAAe,MAAM;AACpF,SAAI,CAAC,gBAAgB,CAAC,aAAa,YAAY,SAAe,KAGvD,aAAa,YAAY,KAAK,CAAC,SAAS,KAAK,iBAAiBA,wBAAiB,OAAO;AAC/F;AAeO,SAAS,iBAAiBC,SAAsC;AAGjE,EAAAA,QAAO,iBACTA,QAAO,cAAc,QAAQ,CAAC,aAA2B;AACnD,QAAA,SAAS,iBAAiBD,OAAAA,iBAAiB;AACvC,YAAA,IAAI,MAAM,kDAAkD;AAAA,EAAA,CAErE;AAGG,QAAA,kBAAkBE,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;AAGO,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;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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AA,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
@@ -557,7 +557,8 @@ declare type ViewConnectionOverride_2 = {
557
557
 
558
558
  /** @public */
559
559
  declare type ViewOverride = {
560
- id: string
560
+ resourceType: ViewResourceType.View
561
+ resourceId: string
561
562
  connections: ViewConnectionOverride[]
562
563
  }
563
564
 
@@ -570,11 +571,13 @@ declare type ViewQueryOptions = Pick<
570
571
  /** @public */
571
572
  declare enum ViewResourceType {
572
573
  Dataset = 'dataset',
574
+ View = 'view',
573
575
  }
574
576
 
575
577
  /** @public */
576
578
  declare enum ViewResourceType_2 {
577
579
  Dataset = 'dataset',
580
+ View = 'view',
578
581
  }
579
582
 
580
583
  export {}
package/dist/views.d.ts CHANGED
@@ -557,7 +557,8 @@ declare type ViewConnectionOverride_2 = {
557
557
 
558
558
  /** @public */
559
559
  declare type ViewOverride = {
560
- id: string
560
+ resourceType: ViewResourceType.View
561
+ resourceId: string
561
562
  connections: ViewConnectionOverride[]
562
563
  }
563
564
 
@@ -570,11 +571,13 @@ declare type ViewQueryOptions = Pick<
570
571
  /** @public */
571
572
  declare enum ViewResourceType {
572
573
  Dataset = 'dataset',
574
+ View = 'view',
573
575
  }
574
576
 
575
577
  /** @public */
576
578
  declare enum ViewResourceType_2 {
577
579
  Dataset = 'dataset',
580
+ View = 'view',
578
581
  }
579
582
 
580
583
  export {}
package/dist/views.js CHANGED
@@ -4,10 +4,14 @@ import { initConfig } from "./_chunks-es/config.js";
4
4
  import { defineHttpRequest, _fetch } from "./_chunks-es/dataMethods.js";
5
5
  function hasDatasetConnections(viewId, viewOverrides) {
6
6
  if (!viewOverrides) return !1;
7
- const viewOverride = viewOverrides.find((override) => override.id === viewId);
7
+ const viewOverride = viewOverrides.find((override) => override.resourceId === viewId);
8
8
  return !viewOverride || !viewOverride.connections.length ? !1 : viewOverride.connections.some((conn) => conn.resourceType === ViewResourceType.Dataset);
9
9
  }
10
10
  function createViewClient(config) {
11
+ config.viewOverrides && config.viewOverrides.forEach((override) => {
12
+ if (override.resourceType !== ViewResourceType.View)
13
+ throw new Error('View overrides only support resource type "view"');
14
+ });
11
15
  const clientRequester = defineHttpRequest([]);
12
16
  return new ViewClient(
13
17
  (options, requester) => (requester || clientRequester)({
@@ -49,7 +53,9 @@ class ViewClient {
49
53
  * @param options - Request options
50
54
  */
51
55
  fetch(viewId, query, params, options) {
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(
56
+ const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find(
57
+ (override) => override.resourceId === viewId
58
+ ), connections = useEmulate ? viewOverride?.connections || [] : void 0, cfg = initConfig(
53
59
  {
54
60
  "~experimental_resource": {
55
61
  id: viewId,
@@ -85,7 +91,9 @@ class ObservableViewClient {
85
91
  });
86
92
  }
87
93
  fetch(viewId, query, params, options) {
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(
94
+ const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides), viewOverride = this.#config.viewOverrides?.find(
95
+ (override) => override.resourceId === viewId
96
+ ), connections = useEmulateEndpoint ? viewOverride?.connections || [] : void 0, cfg = initConfig(
89
97
  {
90
98
  "~experimental_resource": {
91
99
  id: viewId,
package/dist/views.js.map CHANGED
@@ -1 +1 @@
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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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,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;"}
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.resourceId === 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 // Validate we have the correct view resourceType\n // Fail early if we don't.\n if (config.viewOverrides) {\n config.viewOverrides.forEach((override: ViewOverride) => {\n if (override.resourceType !== ViewResourceType.View) {\n throw new Error('View overrides only support resource type \"view\"')\n }\n })\n }\n\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(\n (override) => override.resourceId === viewId,\n )\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(\n (override) => override.resourceId === viewId,\n )\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,eAAe,MAAM;AACpF,SAAI,CAAC,gBAAgB,CAAC,aAAa,YAAY,SAAe,KAGvD,aAAa,YAAY,KAAK,CAAC,SAAS,KAAK,iBAAiB,iBAAiB,OAAO;AAC/F;AAeO,SAAS,iBAAiB,QAAsC;AAGjE,SAAO,iBACT,OAAO,cAAc,QAAQ,CAAC,aAA2B;AACnD,QAAA,SAAS,iBAAiB,iBAAiB;AACvC,YAAA,IAAI,MAAM,kDAAkD;AAAA,EAAA,CAErE;AAGG,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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,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;AAAA,MAC/C,CAAC,aAAa,SAAS,eAAe;AAAA,IAAA,GAElC,cAAc,qBAAqB,cAAc,eAAe,KAAK,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.1",
3
+ "version": "7.1.0-views.2",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
package/src/types.ts CHANGED
@@ -1232,11 +1232,13 @@ export interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
1232
1232
  /** @public */
1233
1233
  export enum ViewResourceType {
1234
1234
  Dataset = 'dataset',
1235
+ View = 'view',
1235
1236
  }
1236
1237
 
1237
1238
  /** @public */
1238
1239
  export type ViewOverride = {
1239
- id: string
1240
+ resourceType: ViewResourceType.View
1241
+ resourceId: string
1240
1242
  connections: ViewConnectionOverride[]
1241
1243
  }
1242
1244
 
@@ -25,7 +25,7 @@ import type {
25
25
  function hasDatasetConnections(viewId: string, viewOverrides?: ViewOverride[]): boolean {
26
26
  if (!viewOverrides) return false
27
27
 
28
- const viewOverride = viewOverrides.find((override) => override.id === viewId)
28
+ const viewOverride = viewOverrides.find((override) => override.resourceId === viewId)
29
29
  if (!viewOverride || !viewOverride.connections.length) return false
30
30
 
31
31
  // Check if any connection has dataset resourceType
@@ -46,6 +46,16 @@ export interface ViewClientConfig
46
46
  * @public
47
47
  */
48
48
  export function createViewClient(config: ViewClientConfig): ViewClient {
49
+ // Validate we have the correct view resourceType
50
+ // Fail early if we don't.
51
+ if (config.viewOverrides) {
52
+ config.viewOverrides.forEach((override: ViewOverride) => {
53
+ if (override.resourceType !== ViewResourceType.View) {
54
+ throw new Error('View overrides only support resource type "view"')
55
+ }
56
+ })
57
+ }
58
+
49
59
  const clientRequester = defineHttpRequest([])
50
60
  return new ViewClient(
51
61
  (options, requester) =>
@@ -127,7 +137,9 @@ export class ViewClient {
127
137
  const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides)
128
138
 
129
139
  // Get connections for this view if using emulate endpoint
130
- const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)
140
+ const viewOverride = this.#config.viewOverrides?.find(
141
+ (override) => override.resourceId === viewId,
142
+ )
131
143
  const connections = useEmulate ? viewOverride?.connections || [] : undefined
132
144
 
133
145
  const cfg = initConfig(
@@ -204,7 +216,9 @@ export class ObservableViewClient {
204
216
  const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides)
205
217
 
206
218
  // Get connections for this view if using emulate endpoint
207
- const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)
219
+ const viewOverride = this.#config.viewOverrides?.find(
220
+ (override) => override.resourceId === viewId,
221
+ )
208
222
  const connections = useEmulateEndpoint ? viewOverride?.connections || [] : undefined
209
223
 
210
224
  const cfg = initConfig(
@@ -2237,7 +2237,7 @@ ${codeFrame(query, { start, end }, description)}${withTag}`;
2237
2237
  if (config["~experimental_resource"])
2238
2238
  throw new Error(`\`${service}\` does not support resource-based operations`);
2239
2239
  };
2240
- var ViewResourceType = /* @__PURE__ */ ((ViewResourceType2) => (ViewResourceType2.Dataset = "dataset", ViewResourceType2))(ViewResourceType || {});
2240
+ var ViewResourceType = /* @__PURE__ */ ((ViewResourceType2) => (ViewResourceType2.Dataset = "dataset", ViewResourceType2.View = "view", ViewResourceType2))(ViewResourceType || {});
2241
2241
  function once(fn) {
2242
2242
  let didCall = false, returnValue;
2243
2243
  return (...args) => (didCall || (returnValue = fn(...args), didCall = true), returnValue);