@sanity/client 7.1.0-views.0 → 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.
- package/README.md +810 -40
- package/dist/_chunks-cjs/config.cjs +14 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-cjs/dataMethods.cjs +197 -32
- package/dist/_chunks-cjs/dataMethods.cjs.map +1 -1
- package/dist/_chunks-cjs/isRecord.cjs +6 -0
- package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +4 -0
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/config.js +15 -1
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/_chunks-es/dataMethods.js +200 -33
- package/dist/_chunks-es/dataMethods.js.map +1 -1
- package/dist/_chunks-es/isRecord.js +7 -0
- package/dist/_chunks-es/isRecord.js.map +1 -0
- package/dist/_chunks-es/resolveEditInfo.js +1 -3
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +4 -0
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +1019 -59
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1950 -149
- package/dist/index.browser.d.ts +1950 -149
- package/dist/index.browser.js +1021 -60
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +825 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1950 -149
- package/dist/index.d.ts +1950 -149
- package/dist/index.js +826 -31
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1950 -149
- package/dist/stega.browser.d.ts +1950 -149
- package/dist/stega.d.cts +1950 -149
- package/dist/stega.d.ts +1950 -149
- package/dist/views.cjs +21 -5
- package/dist/views.cjs.map +1 -1
- package/dist/views.d.cts +54 -36
- package/dist/views.d.ts +54 -36
- package/dist/views.js +22 -5
- package/dist/views.js.map +1 -1
- package/package.json +2 -1
- package/src/SanityClient.ts +652 -12
- package/src/agent/actions/AgentActionsClient.ts +29 -2
- package/src/agent/actions/commonTypes.ts +57 -17
- package/src/agent/actions/generate.ts +36 -2
- package/src/agent/actions/patch.ts +136 -0
- package/src/agent/actions/prompt.ts +145 -0
- package/src/agent/actions/transform.ts +105 -7
- package/src/agent/actions/translate.ts +5 -2
- package/src/config.ts +3 -1
- package/src/csm/walkMap.ts +1 -1
- package/src/data/dataMethods.ts +170 -12
- package/src/data/encodeQueryString.ts +1 -1
- package/src/data/eventsource.ts +16 -7
- package/src/data/listen.ts +10 -4
- package/src/data/live.ts +13 -5
- package/src/datasets/DatasetsClient.ts +4 -1
- package/src/defineCreateClient.ts +7 -1
- package/src/http/errors.ts +92 -27
- package/src/http/request.ts +3 -3
- package/src/http/requestOptions.ts +4 -0
- package/src/projects/ProjectsClient.ts +6 -2
- package/src/releases/ReleasesClient.ts +693 -0
- package/src/releases/createRelease.ts +53 -0
- package/src/types.ts +293 -10
- package/src/users/UsersClient.ts +7 -3
- package/src/util/codeFrame.ts +174 -0
- package/src/util/createVersionId.ts +79 -0
- package/src/{csm → util}/isRecord.ts +1 -1
- package/src/validators.ts +23 -1
- package/src/views/index.ts +65 -15
- package/umd/sanityClient.js +1067 -61
- 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) {
|
package/src/views/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
Any,
|
|
17
|
+
RawQueryResponse,
|
|
18
|
+
ViewQueryOptions,
|
|
10
19
|
} from '../types'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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.resourceId === 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
|
|
17
|
-
|
|
36
|
+
export interface ViewClientConfig
|
|
37
|
+
extends Omit<ClientConfig, 'dataset' | 'projectId' | 'useCdn' | 'useProjectHostname'> {
|
|
38
|
+
viewOverrides?: ViewOverride[]
|
|
39
|
+
apiVersion: string
|
|
18
40
|
}
|
|
19
41
|
|
|
20
42
|
/**
|
|
@@ -24,6 +46,16 @@ export interface ViewClientConfig extends Omit<ClientConfig, 'dataset' | 'projec
|
|
|
24
46
|
* @public
|
|
25
47
|
*/
|
|
26
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
|
+
|
|
27
59
|
const clientRequester = defineHttpRequest([])
|
|
28
60
|
return new ViewClient(
|
|
29
61
|
(options, requester) =>
|
|
@@ -37,9 +69,6 @@ export function createViewClient(config: ViewClientConfig): ViewClient {
|
|
|
37
69
|
)
|
|
38
70
|
}
|
|
39
71
|
|
|
40
|
-
/** @public */
|
|
41
|
-
export type ViewQueryOptions = Pick<QueryOptions, 'perspective' | 'resultSourceMap' | 'filterResponse'>
|
|
42
|
-
|
|
43
72
|
/** @public */
|
|
44
73
|
export class ViewClient {
|
|
45
74
|
#config: ViewClientConfig
|
|
@@ -104,6 +133,15 @@ export class ViewClient {
|
|
|
104
133
|
params?: Q,
|
|
105
134
|
options?: ViewQueryOptions,
|
|
106
135
|
): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {
|
|
136
|
+
// Check if this view has dataset connections
|
|
137
|
+
const useEmulate = hasDatasetConnections(viewId, this.#config.viewOverrides)
|
|
138
|
+
|
|
139
|
+
// Get connections for this view if using emulate endpoint
|
|
140
|
+
const viewOverride = this.#config.viewOverrides?.find(
|
|
141
|
+
(override) => override.resourceId === viewId,
|
|
142
|
+
)
|
|
143
|
+
const connections = useEmulate ? viewOverride?.connections || [] : undefined
|
|
144
|
+
|
|
107
145
|
const cfg = initConfig(
|
|
108
146
|
{
|
|
109
147
|
'~experimental_resource': {
|
|
@@ -117,6 +155,8 @@ export class ViewClient {
|
|
|
117
155
|
returnQuery: false,
|
|
118
156
|
...options,
|
|
119
157
|
useCdn: true,
|
|
158
|
+
useEmulate,
|
|
159
|
+
connections,
|
|
120
160
|
}
|
|
121
161
|
|
|
122
162
|
return lastValueFrom(_fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts))
|
|
@@ -172,6 +212,15 @@ export class ObservableViewClient {
|
|
|
172
212
|
params?: Q,
|
|
173
213
|
options?: ViewQueryOptions,
|
|
174
214
|
): Observable<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {
|
|
215
|
+
// Check if this view has dataset connections
|
|
216
|
+
const useEmulateEndpoint = hasDatasetConnections(viewId, this.#config.viewOverrides)
|
|
217
|
+
|
|
218
|
+
// Get connections for this view if using emulate endpoint
|
|
219
|
+
const viewOverride = this.#config.viewOverrides?.find(
|
|
220
|
+
(override) => override.resourceId === viewId,
|
|
221
|
+
)
|
|
222
|
+
const connections = useEmulateEndpoint ? viewOverride?.connections || [] : undefined
|
|
223
|
+
|
|
175
224
|
const cfg = initConfig(
|
|
176
225
|
{
|
|
177
226
|
'~experimental_resource': {
|
|
@@ -181,11 +230,12 @@ export class ObservableViewClient {
|
|
|
181
230
|
},
|
|
182
231
|
this.#config,
|
|
183
232
|
)
|
|
184
|
-
const opts
|
|
233
|
+
const opts = {
|
|
185
234
|
returnQuery: false,
|
|
186
235
|
...options,
|
|
187
236
|
useCdn: true,
|
|
188
|
-
|
|
237
|
+
useEmulate: useEmulateEndpoint,
|
|
238
|
+
connections,
|
|
189
239
|
}
|
|
190
240
|
|
|
191
241
|
return _fetch(cfg, this.#httpRequest, {enabled: false}, query, params, opts)
|