@sanity/client 6.21.2 → 6.21.3-bundle-perspective
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/dist/_chunks-cjs/resolveEditInfo.cjs +1 -2
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +1 -2
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +1 -2
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +1 -2
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +1 -2
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -2
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/csm.cjs +1 -2
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +1 -2
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +16 -6
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +16 -1
- package/dist/index.browser.d.ts +16 -1
- package/dist/index.browser.js +16 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +17 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +2 -2
- package/src/data/dataMethods.ts +23 -4
- package/src/types.ts +14 -1
- package/umd/sanityClient.js +21 -12
- package/umd/sanityClient.min.js +2 -2
package/package.json
CHANGED
package/src/SanityClient.ts
CHANGED
|
@@ -900,7 +900,7 @@ export class SanityClient {
|
|
|
900
900
|
*/
|
|
901
901
|
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
902
902
|
id: string,
|
|
903
|
-
options?: {tag?: string},
|
|
903
|
+
options?: {signal?: AbortSignal; tag?: string},
|
|
904
904
|
): Promise<SanityDocument<R> | undefined> {
|
|
905
905
|
return lastValueFrom(dataMethods._getDocument<R>(this, this.#httpRequest, id, options))
|
|
906
906
|
}
|
|
@@ -916,7 +916,7 @@ export class SanityClient {
|
|
|
916
916
|
*/
|
|
917
917
|
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
918
918
|
ids: string[],
|
|
919
|
-
options?: {tag?: string},
|
|
919
|
+
options?: {signal?: AbortSignal; tag?: string},
|
|
920
920
|
): Promise<(SanityDocument<R> | null)[]> {
|
|
921
921
|
return lastValueFrom(dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options))
|
|
922
922
|
}
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -129,9 +129,14 @@ export function _getDocument<R extends Record<string, Any>>(
|
|
|
129
129
|
client: ObservableSanityClient | SanityClient,
|
|
130
130
|
httpRequest: HttpRequest,
|
|
131
131
|
id: string,
|
|
132
|
-
opts: {tag?: string} = {},
|
|
132
|
+
opts: {signal?: AbortSignal; tag?: string} = {},
|
|
133
133
|
): Observable<SanityDocument<R> | undefined> {
|
|
134
|
-
const options = {
|
|
134
|
+
const options = {
|
|
135
|
+
uri: _getDataUrl(client, 'doc', id),
|
|
136
|
+
json: true,
|
|
137
|
+
tag: opts.tag,
|
|
138
|
+
signal: opts.signal,
|
|
139
|
+
}
|
|
135
140
|
return _requestObservable<SanityDocument<R> | undefined>(client, httpRequest, options).pipe(
|
|
136
141
|
filter(isResponse),
|
|
137
142
|
map((event) => event.body.documents && event.body.documents[0]),
|
|
@@ -143,9 +148,14 @@ export function _getDocuments<R extends Record<string, Any>>(
|
|
|
143
148
|
client: ObservableSanityClient | SanityClient,
|
|
144
149
|
httpRequest: HttpRequest,
|
|
145
150
|
ids: string[],
|
|
146
|
-
opts: {tag?: string} = {},
|
|
151
|
+
opts: {signal?: AbortSignal; tag?: string} = {},
|
|
147
152
|
): Observable<(SanityDocument<R> | null)[]> {
|
|
148
|
-
const options = {
|
|
153
|
+
const options = {
|
|
154
|
+
uri: _getDataUrl(client, 'doc', ids.join(',')),
|
|
155
|
+
json: true,
|
|
156
|
+
tag: opts.tag,
|
|
157
|
+
signal: opts.signal,
|
|
158
|
+
}
|
|
149
159
|
return _requestObservable<(SanityDocument<R> | null)[]>(client, httpRequest, options).pipe(
|
|
150
160
|
filter(isResponse),
|
|
151
161
|
map((event: Any) => {
|
|
@@ -302,6 +312,7 @@ export function _dataRequest(
|
|
|
302
312
|
tag,
|
|
303
313
|
returnQuery,
|
|
304
314
|
perspective: options.perspective,
|
|
315
|
+
bundlePerspective: options.bundlePerspective,
|
|
305
316
|
resultSourceMap: options.resultSourceMap,
|
|
306
317
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
307
318
|
canUseCdn: isQuery,
|
|
@@ -395,6 +406,7 @@ export function _requestObservable<R>(
|
|
|
395
406
|
options.query = {resultSourceMap, ...options.query}
|
|
396
407
|
}
|
|
397
408
|
const perspective = options.perspective || config.perspective
|
|
409
|
+
const bundlePerspective = options.bundlePerspective || config.bundlePerspective
|
|
398
410
|
if (typeof perspective === 'string' && perspective !== 'raw') {
|
|
399
411
|
validateApiPerspective(perspective)
|
|
400
412
|
options.query = {perspective, ...options.query}
|
|
@@ -405,6 +417,13 @@ export function _requestObservable<R>(
|
|
|
405
417
|
}
|
|
406
418
|
}
|
|
407
419
|
|
|
420
|
+
if (typeof bundlePerspective === 'string') {
|
|
421
|
+
if (perspective) {
|
|
422
|
+
// printWarning()
|
|
423
|
+
}
|
|
424
|
+
options.query = {perspective: undefined, bundlePerspective, ...options.query}
|
|
425
|
+
}
|
|
426
|
+
|
|
408
427
|
if (options.lastLiveEventId) {
|
|
409
428
|
options.query = {...options.query, lastLiveEventId: options.lastLiveEventId}
|
|
410
429
|
}
|
package/src/types.ts
CHANGED
|
@@ -42,6 +42,7 @@ export interface ClientConfig {
|
|
|
42
42
|
token?: string
|
|
43
43
|
/** @defaultValue 'raw' */
|
|
44
44
|
perspective?: ClientPerspective
|
|
45
|
+
bundlePerspective?: string
|
|
45
46
|
apiHost?: string
|
|
46
47
|
apiVersion?: string
|
|
47
48
|
proxy?: string
|
|
@@ -221,7 +222,7 @@ export type SanityDocument<T extends Record<string, Any> = Record<string, Any>>
|
|
|
221
222
|
_createdAt: string
|
|
222
223
|
_updatedAt: string
|
|
223
224
|
/**
|
|
224
|
-
* Present when `perspective` is set to `previewDrafts`
|
|
225
|
+
* Present when `perspective` is set to `previewDrafts` or `bundlePerspective` is specified
|
|
225
226
|
*/
|
|
226
227
|
_originalId?: string
|
|
227
228
|
}
|
|
@@ -306,6 +307,7 @@ export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
|
|
|
306
307
|
returnQuery?: boolean
|
|
307
308
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
308
309
|
perspective?: ClientPerspective
|
|
310
|
+
bundlePerspective?: string
|
|
309
311
|
lastLiveEventId?: string
|
|
310
312
|
}
|
|
311
313
|
|
|
@@ -372,6 +374,10 @@ export interface SanityProjectMember {
|
|
|
372
374
|
export interface SanityProject {
|
|
373
375
|
id: string
|
|
374
376
|
displayName: string
|
|
377
|
+
/**
|
|
378
|
+
* @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
|
|
379
|
+
* @see https://www.sanity.io/help/studio-host-user-applications
|
|
380
|
+
*/
|
|
375
381
|
studioHost: string | null
|
|
376
382
|
organizationId: string | null
|
|
377
383
|
isBlocked: boolean
|
|
@@ -384,6 +390,10 @@ export interface SanityProject {
|
|
|
384
390
|
metadata: {
|
|
385
391
|
cliInitializedAt?: string
|
|
386
392
|
color?: string
|
|
393
|
+
/**
|
|
394
|
+
* @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
|
|
395
|
+
* @see https://www.sanity.io/help/studio-host-user-applications
|
|
396
|
+
*/
|
|
387
397
|
externalStudioHost?: string
|
|
388
398
|
}
|
|
389
399
|
}
|
|
@@ -463,6 +473,8 @@ export interface QueryParams {
|
|
|
463
473
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
464
474
|
perspective?: never
|
|
465
475
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
476
|
+
bundlePerspective?: never
|
|
477
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
466
478
|
query?: never
|
|
467
479
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
468
480
|
resultSourceMap?: never
|
|
@@ -928,6 +940,7 @@ export interface ListenOptions {
|
|
|
928
940
|
/** @public */
|
|
929
941
|
export interface ResponseQueryOptions extends RequestOptions {
|
|
930
942
|
perspective?: ClientPerspective
|
|
943
|
+
bundlePerspective?: string
|
|
931
944
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
932
945
|
returnQuery?: boolean
|
|
933
946
|
useCdn?: boolean
|
package/umd/sanityClient.js
CHANGED
|
@@ -125,8 +125,9 @@
|
|
|
125
125
|
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
126
126
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
127
127
|
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
128
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
129
|
-
function
|
|
128
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
129
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
130
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
130
131
|
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
131
132
|
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
132
133
|
function fulfill(value) { resume("next", value); }
|
|
@@ -1044,8 +1045,7 @@
|
|
|
1044
1045
|
let e = JSON.stringify(t);
|
|
1045
1046
|
return `${u}${Array.from(e).map((r) => {
|
|
1046
1047
|
let n = r.charCodeAt(0);
|
|
1047
|
-
if (n > 255)
|
|
1048
|
-
throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);
|
|
1048
|
+
if (n > 255) throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);
|
|
1049
1049
|
return Array.from(n.toString(4).padStart(4, "0")).map((o) => String.fromCodePoint(c[o])).join("");
|
|
1050
1050
|
}).join("")}`;
|
|
1051
1051
|
}
|
|
@@ -1160,8 +1160,7 @@
|
|
|
1160
1160
|
]);
|
|
1161
1161
|
}
|
|
1162
1162
|
function shouldRetry(err, attempt, options) {
|
|
1163
|
-
if (options.maxRetries === 0)
|
|
1164
|
-
return !1;
|
|
1163
|
+
if (options.maxRetries === 0) return !1;
|
|
1165
1164
|
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
1166
1165
|
return (isSafe || isQuery) && isRetriableResponse ? !0 : _$1.shouldRetry(err, attempt, options);
|
|
1167
1166
|
}
|
|
@@ -1700,14 +1699,24 @@ ${selectionOpts}`);
|
|
|
1700
1699
|
) : $request.pipe(map(mapResponse));
|
|
1701
1700
|
}
|
|
1702
1701
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
1703
|
-
const options = {
|
|
1702
|
+
const options = {
|
|
1703
|
+
uri: _getDataUrl(client, "doc", id),
|
|
1704
|
+
json: !0,
|
|
1705
|
+
tag: opts.tag,
|
|
1706
|
+
signal: opts.signal
|
|
1707
|
+
};
|
|
1704
1708
|
return _requestObservable(client, httpRequest, options).pipe(
|
|
1705
1709
|
filter(isResponse),
|
|
1706
1710
|
map((event) => event.body.documents && event.body.documents[0])
|
|
1707
1711
|
);
|
|
1708
1712
|
}
|
|
1709
1713
|
function _getDocuments(client, httpRequest, ids, opts = {}) {
|
|
1710
|
-
const options = {
|
|
1714
|
+
const options = {
|
|
1715
|
+
uri: _getDataUrl(client, "doc", ids.join(",")),
|
|
1716
|
+
json: !0,
|
|
1717
|
+
tag: opts.tag,
|
|
1718
|
+
signal: opts.signal
|
|
1719
|
+
};
|
|
1711
1720
|
return _requestObservable(client, httpRequest, options).pipe(
|
|
1712
1721
|
filter(isResponse),
|
|
1713
1722
|
map((event) => {
|
|
@@ -1760,6 +1769,7 @@ ${selectionOpts}`);
|
|
|
1760
1769
|
tag,
|
|
1761
1770
|
returnQuery,
|
|
1762
1771
|
perspective: options.perspective,
|
|
1772
|
+
bundlePerspective: options.bundlePerspective,
|
|
1763
1773
|
resultSourceMap: options.resultSourceMap,
|
|
1764
1774
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
1765
1775
|
canUseCdn: isQuery,
|
|
@@ -1797,8 +1807,8 @@ ${selectionOpts}`);
|
|
|
1797
1807
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
1798
1808
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
1799
1809
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
1800
|
-
const perspective = options.perspective || config.perspective;
|
|
1801
|
-
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
1810
|
+
const perspective = options.perspective || config.perspective, bundlePerspective = options.bundlePerspective || config.bundlePerspective;
|
|
1811
|
+
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), typeof bundlePerspective == "string" && (options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
1802
1812
|
}
|
|
1803
1813
|
const reqOptions = requestOptions(
|
|
1804
1814
|
config,
|
|
@@ -2852,8 +2862,7 @@ ${selectionOpts}`);
|
|
|
2852
2862
|
const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
|
|
2853
2863
|
typeof config.studioUrl == "function" ? config.studioUrl(sourceDocument) : config.studioUrl
|
|
2854
2864
|
);
|
|
2855
|
-
if (!baseUrl)
|
|
2856
|
-
return value;
|
|
2865
|
+
if (!baseUrl) return value;
|
|
2857
2866
|
const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
|
|
2858
2867
|
return C(
|
|
2859
2868
|
value,
|