@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/src/validators.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {Any, InitializedClientConfig} from './types'
1
+ import type {Any, InitializedClientConfig, SanityDocumentStub} from './types'
2
2
 
3
3
  const VALID_ASSET_TYPES = ['image', 'file']
4
4
  const VALID_INSERT_LOCATIONS = ['before', 'after', 'replace']
@@ -43,6 +43,28 @@ export const requireDocumentId = (op: string, doc: Record<string, Any>) => {
43
43
  validateDocumentId(op, doc._id)
44
44
  }
45
45
 
46
+ export const validateDocumentType = (op: string, type: string) => {
47
+ if (typeof type !== 'string') {
48
+ throw new Error(`\`${op}()\`: \`${type}\` is not a valid document type`)
49
+ }
50
+ }
51
+
52
+ export const requireDocumentType = (op: string, doc: Record<string, Any>) => {
53
+ if (!doc._type) {
54
+ throw new Error(`\`${op}()\` requires that the document contains a type (\`_type\` property)`)
55
+ }
56
+
57
+ validateDocumentType(op, doc._type)
58
+ }
59
+
60
+ export const validateVersionIdMatch = (builtVersionId: string, document: SanityDocumentStub) => {
61
+ if (document._id && document._id !== builtVersionId) {
62
+ throw new Error(
63
+ `The provided document ID (\`${document._id}\`) does not match the generated version ID (\`${builtVersionId}\`)`,
64
+ )
65
+ }
66
+ }
67
+
46
68
  export const validateInsert = (at: string, selector: string, items: Any[]) => {
47
69
  const signature = 'insert(at, selector, items)'
48
70
  if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
@@ -1,20 +1,42 @@
1
+ import {
2
+ type QueryParams,
3
+ type QueryWithoutParams,
4
+ type ViewOverride,
5
+ ViewResourceType,
6
+ } from '@sanity/client'
1
7
  import {lastValueFrom, Observable} from 'rxjs'
2
- import {type QueryParams, type QueryWithoutParams} from '@sanity/client'
8
+
9
+ import {initConfig} from '../config'
10
+ import {_fetch} from '../data/dataMethods'
11
+ import {defineHttpRequest} from '../http/request'
3
12
  import type {
13
+ Any,
14
+ ClientConfig,
4
15
  ClientReturn,
5
- RawQueryResponse,
6
16
  HttpRequest,
7
- QueryOptions,
8
- ClientConfig,
9
- Any,
17
+ RawQueryResponse,
18
+ ViewQueryOptions,
10
19
  } from '../types'
11
- import {_fetch} from '../data/dataMethods'
12
- import {initConfig} from '../config'
13
- import {defineHttpRequest} from '../http/request'
20
+
21
+ /**
22
+ * Helper function to check if a view has any dataset connections
23
+ * @internal
24
+ */
25
+ function hasDatasetConnections(viewId: string, viewOverrides?: ViewOverride[]): boolean {
26
+ if (!viewOverrides) return false
27
+
28
+ const viewOverride = viewOverrides.find((override) => override.id === viewId)
29
+ if (!viewOverride || !viewOverride.connections.length) return false
30
+
31
+ // Check if any connection has dataset resourceType
32
+ return viewOverride.connections.some((conn) => conn.resourceType === ViewResourceType.Dataset)
33
+ }
14
34
 
15
35
  /** @public */
16
- export interface ViewClientConfig extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {
17
- // TODO: Add our own config options
36
+ export interface ViewClientConfig
37
+ extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {
38
+ viewOverrides?: ViewOverride[]
39
+ apiVersion: string
18
40
  }
19
41
 
20
42
  /**
@@ -37,9 +59,6 @@ export function createViewClient(config: ViewClientConfig): ViewClient {
37
59
  )
38
60
  }
39
61
 
40
- /** @public */
41
- export type ViewQueryOptions = Pick<QueryOptions, 'perspective' | 'resultSourceMap' | 'filterResponse'>
42
-
43
62
  /** @public */
44
63
  export class ViewClient {
45
64
  #config: ViewClientConfig
@@ -104,6 +123,13 @@ export class ViewClient {
104
123
  params?: Q,
105
124
  options?: ViewQueryOptions,
106
125
  ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {
126
+ // Check if this view has dataset connections
127
+ const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides)
128
+
129
+ // Get connections for this view if using emulate endpoint
130
+ const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)
131
+ const connections = useEmulate ? viewOverride?.connections || [] : undefined
132
+
107
133
  const cfg = initConfig(
108
134
  {
109
135
  '~experimental_resource': {
@@ -117,6 +143,8 @@ export class ViewClient {
117
143
  returnQuery: false,
118
144
  ...options,
119
145
  useCdn: true,
146
+ useEmulate,
147
+ connections,
120
148
  }
121
149
 
122
150
  return lastValueFrom(_fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts))
@@ -172,6 +200,13 @@ export class ObservableViewClient {
172
200
  params?: Q,
173
201
  options?: ViewQueryOptions,
174
202
  ): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {
203
+ // Check if this view has dataset connections
204
+ const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides)
205
+
206
+ // Get connections for this view if using emulate endpoint
207
+ const viewOverride = this.#config.viewOverrides?.find((override) => override.id === viewId)
208
+ const connections = useEmulateEndpoint ? viewOverride?.connections || [] : undefined
209
+
175
210
  const cfg = initConfig(
176
211
  {
177
212
  '~experimental_resource': {
@@ -181,11 +216,12 @@ export class ObservableViewClient {
181
216
  },
182
217
  this.#config,
183
218
  )
184
- const opts: QueryOptions = {
219
+ const opts = {
185
220
  returnQuery: false,
186
221
  ...options,
187
222
  useCdn: true,
188
- perspective: 'published',
223
+ useEmulate: useEmulateEndpoint,
224
+ connections,
189
225
  }
190
226
 
191
227
  return _fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts)