@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.
- package/README.md +668 -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 +1948 -149
- package/dist/index.browser.d.ts +1948 -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 +1948 -149
- package/dist/index.d.ts +1948 -149
- package/dist/index.js +826 -31
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1948 -149
- package/dist/stega.browser.d.ts +1948 -149
- package/dist/stega.d.cts +1948 -149
- package/dist/stega.d.ts +1948 -149
- package/dist/views.cjs +13 -5
- package/dist/views.cjs.map +1 -1
- package/dist/views.d.cts +51 -36
- package/dist/views.d.ts +51 -36
- package/dist/views.js +14 -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 +291 -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 +51 -15
- package/umd/sanityClient.js +1067 -61
- package/umd/sanityClient.min.js +2 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { _request, _requestObservable, encodeQueryString, _getDataUrl, CorsOriginError,
|
|
1
|
+
import { formatQueryParseError, isQueryParseError, _request, _requestObservable, encodeQueryString, _getDataUrl, CorsOriginError, _getDocument, _action, _getReleaseDocuments, _fetch, _getDocuments, _create, _createIfNotExists, _createOrReplace, _createVersion, _delete, _discardVersion, _replaceVersion, _unpublishVersion, _mutate, Patch, Transaction, _dataRequest, _getUrl, ObservablePatch, ObservableTransaction, defineHttpRequest } from "./_chunks-es/dataMethods.js";
|
|
2
2
|
import { BasePatch, BaseTransaction, ClientError, ServerError } from "./_chunks-es/dataMethods.js";
|
|
3
3
|
import "./_chunks-es/stegaClean.js";
|
|
4
|
-
import { defer, of, isObservable, mergeMap, Observable, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY } from "rxjs";
|
|
4
|
+
import { defer, of, isObservable, mergeMap, Observable, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY, map as map$1, firstValueFrom } from "rxjs";
|
|
5
5
|
import { filter, map, finalize as finalize$1 } from "rxjs/operators";
|
|
6
|
-
import { hasDataset, validateAssetType, resourceGuard, dataset, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
|
|
6
|
+
import { hasDataset, validateAssetType, resourceGuard, dataset, validateVersionIdMatch, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
|
|
7
7
|
import { validateApiPerspective } from "./_chunks-es/config.js";
|
|
8
8
|
import { debug, headers, agent } from "get-it/middleware";
|
|
9
|
+
import { getVersionId, getDraftId, isDraftId, isVersionId, getVersionFromId, getPublishedId } from "@sanity/client/csm";
|
|
10
|
+
import crypto from "crypto";
|
|
9
11
|
import { adapter, environment } from "get-it";
|
|
12
|
+
var ViewResourceType = /* @__PURE__ */ ((ViewResourceType2) => (ViewResourceType2.Dataset = "dataset", ViewResourceType2))(ViewResourceType || {});
|
|
10
13
|
class ConnectionFailedError extends Error {
|
|
11
14
|
name = "ConnectionFailedError";
|
|
12
15
|
}
|
|
@@ -66,7 +69,8 @@ function connectWithESInstance(es, events) {
|
|
|
66
69
|
return;
|
|
67
70
|
}
|
|
68
71
|
if (message.type === "channelError") {
|
|
69
|
-
|
|
72
|
+
const tag = new URL(es.url).searchParams.get("tag");
|
|
73
|
+
observer.error(new ChannelError(extractErrorMessage(event?.data, tag), event.data));
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
76
|
if (message.type === "disconnect") {
|
|
@@ -105,8 +109,9 @@ function parseEvent(message) {
|
|
|
105
109
|
return [err, null];
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
|
-
function extractErrorMessage(err) {
|
|
109
|
-
|
|
112
|
+
function extractErrorMessage(err, tag) {
|
|
113
|
+
const error = err.error;
|
|
114
|
+
return error ? isQueryParseError(error) ? formatQueryParseError(error, tag) : error.description ? error.description : typeof error == "string" ? error : JSON.stringify(error, null, 2) : err.message || "Unknown listener error";
|
|
110
115
|
}
|
|
111
116
|
function isEmptyObject(data) {
|
|
112
117
|
for (const _ in data)
|
|
@@ -121,6 +126,22 @@ function _generate(client, httpRequest, request) {
|
|
|
121
126
|
body: request
|
|
122
127
|
});
|
|
123
128
|
}
|
|
129
|
+
function _patch(client, httpRequest, request) {
|
|
130
|
+
const dataset2 = hasDataset(client.config());
|
|
131
|
+
return _request(client.config(), httpRequest, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
uri: `/agent/action/patch/${dataset2}`,
|
|
134
|
+
body: request
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function _prompt(client, httpRequest, request) {
|
|
138
|
+
const dataset2 = hasDataset(client.config());
|
|
139
|
+
return _request(client.config(), httpRequest, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
uri: `/agent/action/prompt/${dataset2}`,
|
|
142
|
+
body: request
|
|
143
|
+
});
|
|
144
|
+
}
|
|
124
145
|
function _transform(client, httpRequest, request) {
|
|
125
146
|
const dataset2 = hasDataset(client.config());
|
|
126
147
|
return _request(client.config(), httpRequest, {
|
|
@@ -192,6 +213,21 @@ class AgentActionsClient {
|
|
|
192
213
|
translate(request) {
|
|
193
214
|
return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
194
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Run a raw instruction and return the result either as text or json
|
|
218
|
+
* @param request - prompt request
|
|
219
|
+
*/
|
|
220
|
+
prompt(request) {
|
|
221
|
+
return lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Patch a document using a schema aware API.
|
|
225
|
+
* Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
|
|
226
|
+
* @param request - instruction request
|
|
227
|
+
*/
|
|
228
|
+
patch(request) {
|
|
229
|
+
return lastValueFrom(_patch(this.#client, this.#httpRequest, request));
|
|
230
|
+
}
|
|
195
231
|
}
|
|
196
232
|
class ObservableAssetsClient {
|
|
197
233
|
#client;
|
|
@@ -300,13 +336,11 @@ const MAX_URL_LENGTH = 14800, possibleOptions = [
|
|
|
300
336
|
includeResult: !0
|
|
301
337
|
};
|
|
302
338
|
function _listen(query, params, opts = {}) {
|
|
303
|
-
const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this.config(), "listen", qs)}`;
|
|
339
|
+
const { url, token, withCredentials, requestTagPrefix, headers: configHeaders } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this.config(), "listen", qs)}`;
|
|
304
340
|
if (uri.length > MAX_URL_LENGTH)
|
|
305
341
|
return throwError(() => new Error("Query too large for listener"));
|
|
306
342
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
307
|
-
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
308
|
-
Authorization: `Bearer ${token}`
|
|
309
|
-
}), connectEventSource(() => (
|
|
343
|
+
return withCredentials && (esOptions.withCredentials = !0), (token || configHeaders) && (esOptions.headers = {}, token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders)), connectEventSource(() => (
|
|
310
344
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
311
345
|
(typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : of(EventSource)).pipe(map((EventSource2) => new EventSource2(uri, esOptions)))
|
|
312
346
|
), listenFor).pipe(
|
|
@@ -364,7 +398,8 @@ class LiveClient {
|
|
|
364
398
|
apiVersion: _apiVersion,
|
|
365
399
|
token,
|
|
366
400
|
withCredentials,
|
|
367
|
-
requestTagPrefix
|
|
401
|
+
requestTagPrefix,
|
|
402
|
+
headers: configHeaders
|
|
368
403
|
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
369
404
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
370
405
|
throw new Error(
|
|
@@ -377,9 +412,7 @@ class LiveClient {
|
|
|
377
412
|
const path = _getDataUrl(this.#client.config(), "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
378
413
|
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
379
414
|
const esOptions = {};
|
|
380
|
-
includeDrafts && token && (esOptions.headers = {
|
|
381
|
-
Authorization: `Bearer ${token}`
|
|
382
|
-
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
|
|
415
|
+
includeDrafts && withCredentials && (esOptions.withCredentials = !0), (includeDrafts && token || configHeaders) && (esOptions.headers = {}, includeDrafts && token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders));
|
|
383
416
|
const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
|
|
384
417
|
if (existing)
|
|
385
418
|
return existing;
|
|
@@ -517,7 +550,10 @@ class DatasetsClient {
|
|
|
517
550
|
*/
|
|
518
551
|
list() {
|
|
519
552
|
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
520
|
-
_request(this.#client.config(), this.#httpRequest, {
|
|
553
|
+
_request(this.#client.config(), this.#httpRequest, {
|
|
554
|
+
uri: "/datasets",
|
|
555
|
+
tag: null
|
|
556
|
+
})
|
|
521
557
|
);
|
|
522
558
|
}
|
|
523
559
|
}
|
|
@@ -546,7 +582,9 @@ class ObservableProjectsClient {
|
|
|
546
582
|
* @param projectId - ID of the project to fetch
|
|
547
583
|
*/
|
|
548
584
|
getById(projectId) {
|
|
549
|
-
return resourceGuard("projects", this.#client.config()), _request(this.#client.config(), this.#httpRequest, {
|
|
585
|
+
return resourceGuard("projects", this.#client.config()), _request(this.#client.config(), this.#httpRequest, {
|
|
586
|
+
uri: `/projects/${projectId}`
|
|
587
|
+
});
|
|
550
588
|
}
|
|
551
589
|
}
|
|
552
590
|
class ProjectsClient {
|
|
@@ -567,7 +605,521 @@ class ProjectsClient {
|
|
|
567
605
|
*/
|
|
568
606
|
getById(projectId) {
|
|
569
607
|
return resourceGuard("projects", this.#client.config()), lastValueFrom(
|
|
570
|
-
_request(this.#client.config(), this.#httpRequest, {
|
|
608
|
+
_request(this.#client.config(), this.#httpRequest, {
|
|
609
|
+
uri: `/projects/${projectId}`
|
|
610
|
+
})
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const POOL_SIZE_MULTIPLIER = 128;
|
|
615
|
+
let pool, poolOffset, fillPool = (bytes) => {
|
|
616
|
+
!pool || pool.length < bytes ? (pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER), crypto.randomFillSync(pool), poolOffset = 0) : poolOffset + bytes > pool.length && (crypto.randomFillSync(pool), poolOffset = 0), poolOffset += bytes;
|
|
617
|
+
}, random = (bytes) => (fillPool(bytes |= 0), pool.subarray(poolOffset - bytes, poolOffset)), customRandom = (alphabet, defaultSize, getRandom) => {
|
|
618
|
+
let mask = (2 << 31 - Math.clz32(alphabet.length - 1 | 1)) - 1, step = Math.ceil(1.6 * mask * defaultSize / alphabet.length);
|
|
619
|
+
return (size = defaultSize) => {
|
|
620
|
+
let id = "";
|
|
621
|
+
for (; ; ) {
|
|
622
|
+
let bytes = getRandom(step), i = step;
|
|
623
|
+
for (; i--; )
|
|
624
|
+
if (id += alphabet[bytes[i] & mask] || "", id.length === size) return id;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}, customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size, random);
|
|
628
|
+
const generateReleaseId = customAlphabet(
|
|
629
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
630
|
+
8
|
|
631
|
+
), getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
|
|
632
|
+
function deriveDocumentVersionId(op, {
|
|
633
|
+
releaseId,
|
|
634
|
+
publishedId,
|
|
635
|
+
document
|
|
636
|
+
}) {
|
|
637
|
+
if (publishedId && document._id) {
|
|
638
|
+
const versionId = getDocumentVersionId(publishedId, releaseId);
|
|
639
|
+
return validateVersionIdMatch(versionId, document), versionId;
|
|
640
|
+
}
|
|
641
|
+
if (document._id) {
|
|
642
|
+
const isDraft = isDraftId(document._id), isVersion = isVersionId(document._id);
|
|
643
|
+
if (!isDraft && !isVersion)
|
|
644
|
+
throw new Error(
|
|
645
|
+
`\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
|
|
646
|
+
);
|
|
647
|
+
if (releaseId) {
|
|
648
|
+
if (isDraft)
|
|
649
|
+
throw new Error(
|
|
650
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
|
|
651
|
+
);
|
|
652
|
+
const builtVersionId = getVersionFromId(document._id);
|
|
653
|
+
if (builtVersionId !== releaseId)
|
|
654
|
+
throw new Error(
|
|
655
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a version ID, but the release ID (\`${releaseId}\`) does not match the document's version ID (\`${builtVersionId}\`).`
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
return document._id;
|
|
659
|
+
}
|
|
660
|
+
if (publishedId)
|
|
661
|
+
return getDocumentVersionId(publishedId, releaseId);
|
|
662
|
+
throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
|
|
663
|
+
}
|
|
664
|
+
const getArgs = (releaseOrOptions, maybeOptions) => {
|
|
665
|
+
if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
|
|
666
|
+
const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
|
|
667
|
+
return [releaseId, metadata, maybeOptions];
|
|
668
|
+
}
|
|
669
|
+
return [generateReleaseId(), {}, releaseOrOptions];
|
|
670
|
+
}, createRelease = (releaseOrOptions, maybeOptions) => {
|
|
671
|
+
const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
|
|
672
|
+
...metadata,
|
|
673
|
+
releaseType: metadata.releaseType || "undecided"
|
|
674
|
+
};
|
|
675
|
+
return { action: {
|
|
676
|
+
actionType: "sanity.action.release.create",
|
|
677
|
+
releaseId,
|
|
678
|
+
metadata: finalMetadata
|
|
679
|
+
}, options };
|
|
680
|
+
};
|
|
681
|
+
class ObservableReleasesClient {
|
|
682
|
+
#client;
|
|
683
|
+
#httpRequest;
|
|
684
|
+
constructor(client, httpRequest) {
|
|
685
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* @public
|
|
689
|
+
*
|
|
690
|
+
* Retrieve a release by id.
|
|
691
|
+
*
|
|
692
|
+
* @category Releases
|
|
693
|
+
*
|
|
694
|
+
* @param params - Release action parameters:
|
|
695
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
696
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
697
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
698
|
+
*
|
|
699
|
+
* @example Retrieving a release by id
|
|
700
|
+
* ```ts
|
|
701
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
702
|
+
* tap((release) => console.log(release)),
|
|
703
|
+
* // {
|
|
704
|
+
* // _id: '_.releases.my-release',
|
|
705
|
+
* // name: 'my-release'
|
|
706
|
+
* // _type: 'system.release',
|
|
707
|
+
* // metadata: {releaseType: 'asap'},
|
|
708
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
709
|
+
* // ...
|
|
710
|
+
* // }
|
|
711
|
+
* ).subscribe()
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
get({ releaseId }, options) {
|
|
715
|
+
return _getDocument(
|
|
716
|
+
this.#client.config(),
|
|
717
|
+
this.#httpRequest,
|
|
718
|
+
`_.releases.${releaseId}`,
|
|
719
|
+
options
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
create(releaseOrOptions, maybeOptions) {
|
|
723
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
724
|
+
return _action(this.#client.config(), this.#httpRequest, action, options).pipe(
|
|
725
|
+
map$1((actionResult) => ({
|
|
726
|
+
...actionResult,
|
|
727
|
+
releaseId,
|
|
728
|
+
metadata
|
|
729
|
+
}))
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* @public
|
|
734
|
+
*
|
|
735
|
+
* Edits an existing release, updating the metadata.
|
|
736
|
+
*
|
|
737
|
+
* @category Releases
|
|
738
|
+
*
|
|
739
|
+
* @param params - Release action parameters:
|
|
740
|
+
* - `releaseId` - The id of the release to edit.
|
|
741
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
742
|
+
* @param options - Additional action options.
|
|
743
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
744
|
+
*/
|
|
745
|
+
edit({ releaseId, patch }, options) {
|
|
746
|
+
const editAction = {
|
|
747
|
+
actionType: "sanity.action.release.edit",
|
|
748
|
+
releaseId,
|
|
749
|
+
patch
|
|
750
|
+
};
|
|
751
|
+
return _action(this.#client.config(), this.#httpRequest, editAction, options);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* @public
|
|
755
|
+
*
|
|
756
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
757
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
758
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
759
|
+
* take some time.
|
|
760
|
+
*
|
|
761
|
+
* During this period both the source and target documents are locked and cannot be
|
|
762
|
+
* modified through any other means.
|
|
763
|
+
*
|
|
764
|
+
* @category Releases
|
|
765
|
+
*
|
|
766
|
+
* @param params - Release action parameters:
|
|
767
|
+
* - `releaseId` - The id of the release to publish.
|
|
768
|
+
* @param options - Additional action options.
|
|
769
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
770
|
+
*/
|
|
771
|
+
publish({ releaseId }, options) {
|
|
772
|
+
const publishAction = {
|
|
773
|
+
actionType: "sanity.action.release.publish",
|
|
774
|
+
releaseId
|
|
775
|
+
};
|
|
776
|
+
return _action(this.#client.config(), this.#httpRequest, publishAction, options);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* @public
|
|
780
|
+
*
|
|
781
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
782
|
+
* are deleted and therefore no longer queryable.
|
|
783
|
+
*
|
|
784
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
785
|
+
*
|
|
786
|
+
* @category Releases
|
|
787
|
+
*
|
|
788
|
+
* @param params - Release action parameters:
|
|
789
|
+
* - `releaseId` - The id of the release to archive.
|
|
790
|
+
* @param options - Additional action options.
|
|
791
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
792
|
+
*/
|
|
793
|
+
archive({ releaseId }, options) {
|
|
794
|
+
const archiveAction = {
|
|
795
|
+
actionType: "sanity.action.release.archive",
|
|
796
|
+
releaseId
|
|
797
|
+
};
|
|
798
|
+
return _action(this.#client.config(), this.#httpRequest, archiveAction, options);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* @public
|
|
802
|
+
*
|
|
803
|
+
* An unarchive action restores an archived release and all documents
|
|
804
|
+
* with the content they had just prior to archiving.
|
|
805
|
+
*
|
|
806
|
+
* @category Releases
|
|
807
|
+
*
|
|
808
|
+
* @param params - Release action parameters:
|
|
809
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
810
|
+
* @param options - Additional action options.
|
|
811
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
812
|
+
*/
|
|
813
|
+
unarchive({ releaseId }, options) {
|
|
814
|
+
const unarchiveAction = {
|
|
815
|
+
actionType: "sanity.action.release.unarchive",
|
|
816
|
+
releaseId
|
|
817
|
+
};
|
|
818
|
+
return _action(this.#client.config(), this.#httpRequest, unarchiveAction, options);
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* @public
|
|
822
|
+
*
|
|
823
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
824
|
+
* The release is locked such that no documents in the release can be modified and
|
|
825
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
826
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
827
|
+
*
|
|
828
|
+
* @category Releases
|
|
829
|
+
*
|
|
830
|
+
* @param params - Release action parameters:
|
|
831
|
+
* - `releaseId` - The id of the release to schedule.
|
|
832
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
833
|
+
* @param options - Additional action options.
|
|
834
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
835
|
+
*/
|
|
836
|
+
schedule({ releaseId, publishAt }, options) {
|
|
837
|
+
const scheduleAction = {
|
|
838
|
+
actionType: "sanity.action.release.schedule",
|
|
839
|
+
releaseId,
|
|
840
|
+
publishAt
|
|
841
|
+
};
|
|
842
|
+
return _action(this.#client.config(), this.#httpRequest, scheduleAction, options);
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* @public
|
|
846
|
+
*
|
|
847
|
+
* An unschedule action stops a release from being published.
|
|
848
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
849
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
850
|
+
* has a reference to a document created by this one.
|
|
851
|
+
*
|
|
852
|
+
* @category Releases
|
|
853
|
+
*
|
|
854
|
+
* @param params - Release action parameters:
|
|
855
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
856
|
+
* @param options - Additional action options.
|
|
857
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
858
|
+
*/
|
|
859
|
+
unschedule({ releaseId }, options) {
|
|
860
|
+
const unscheduleAction = {
|
|
861
|
+
actionType: "sanity.action.release.unschedule",
|
|
862
|
+
releaseId
|
|
863
|
+
};
|
|
864
|
+
return _action(this.#client.config(), this.#httpRequest, unscheduleAction, options);
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* @public
|
|
868
|
+
*
|
|
869
|
+
* A delete action removes a published or archived release.
|
|
870
|
+
* The backing system document will be removed from the dataset.
|
|
871
|
+
*
|
|
872
|
+
* @category Releases
|
|
873
|
+
*
|
|
874
|
+
* @param params - Release action parameters:
|
|
875
|
+
* - `releaseId` - The id of the release to delete.
|
|
876
|
+
* @param options - Additional action options.
|
|
877
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
878
|
+
*/
|
|
879
|
+
delete({ releaseId }, options) {
|
|
880
|
+
const deleteAction = {
|
|
881
|
+
actionType: "sanity.action.release.delete",
|
|
882
|
+
releaseId
|
|
883
|
+
};
|
|
884
|
+
return _action(this.#client.config(), this.#httpRequest, deleteAction, options);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* @public
|
|
888
|
+
*
|
|
889
|
+
* Fetch the documents in a release by release id.
|
|
890
|
+
*
|
|
891
|
+
* @category Releases
|
|
892
|
+
*
|
|
893
|
+
* @param params - Release action parameters:
|
|
894
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
895
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
896
|
+
* @returns An observable that resolves to the documents in the release.
|
|
897
|
+
*/
|
|
898
|
+
fetchDocuments({ releaseId }, options) {
|
|
899
|
+
return _getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
class ReleasesClient {
|
|
903
|
+
#client;
|
|
904
|
+
#httpRequest;
|
|
905
|
+
constructor(client, httpRequest) {
|
|
906
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* @public
|
|
910
|
+
*
|
|
911
|
+
* Retrieve a release by id.
|
|
912
|
+
*
|
|
913
|
+
* @category Releases
|
|
914
|
+
*
|
|
915
|
+
* @param params - Release action parameters:
|
|
916
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
917
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
918
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
919
|
+
*
|
|
920
|
+
* @example Retrieving a release by id
|
|
921
|
+
* ```ts
|
|
922
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
923
|
+
* console.log(release)
|
|
924
|
+
* // {
|
|
925
|
+
* // _id: '_.releases.my-release',
|
|
926
|
+
* // name: 'my-release'
|
|
927
|
+
* // _type: 'system.release',
|
|
928
|
+
* // metadata: {releaseType: 'asap'},
|
|
929
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
930
|
+
* // ...
|
|
931
|
+
* // }
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
get({ releaseId }, options) {
|
|
935
|
+
return lastValueFrom(
|
|
936
|
+
_getDocument(
|
|
937
|
+
this.#client.config(),
|
|
938
|
+
this.#httpRequest,
|
|
939
|
+
`_.releases.${releaseId}`,
|
|
940
|
+
options
|
|
941
|
+
)
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
async create(releaseOrOptions, maybeOptions) {
|
|
945
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
946
|
+
return { ...await lastValueFrom(
|
|
947
|
+
_action(this.#client.config(), this.#httpRequest, action, options)
|
|
948
|
+
), releaseId, metadata };
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* @public
|
|
952
|
+
*
|
|
953
|
+
* Edits an existing release, updating the metadata.
|
|
954
|
+
*
|
|
955
|
+
* @category Releases
|
|
956
|
+
*
|
|
957
|
+
* @param params - Release action parameters:
|
|
958
|
+
* - `releaseId` - The id of the release to edit.
|
|
959
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
960
|
+
* @param options - Additional action options.
|
|
961
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
962
|
+
*/
|
|
963
|
+
edit({ releaseId, patch }, options) {
|
|
964
|
+
const editAction = {
|
|
965
|
+
actionType: "sanity.action.release.edit",
|
|
966
|
+
releaseId,
|
|
967
|
+
patch
|
|
968
|
+
};
|
|
969
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, editAction, options));
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* @public
|
|
973
|
+
*
|
|
974
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
975
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
976
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
977
|
+
* take some time.
|
|
978
|
+
*
|
|
979
|
+
* During this period both the source and target documents are locked and cannot be
|
|
980
|
+
* modified through any other means.
|
|
981
|
+
*
|
|
982
|
+
* @category Releases
|
|
983
|
+
*
|
|
984
|
+
* @param params - Release action parameters:
|
|
985
|
+
* - `releaseId` - The id of the release to publish.
|
|
986
|
+
* @param options - Additional action options.
|
|
987
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
988
|
+
*/
|
|
989
|
+
publish({ releaseId }, options) {
|
|
990
|
+
const publishAction = {
|
|
991
|
+
actionType: "sanity.action.release.publish",
|
|
992
|
+
releaseId
|
|
993
|
+
};
|
|
994
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, publishAction, options));
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* @public
|
|
998
|
+
*
|
|
999
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
1000
|
+
* are deleted and therefore no longer queryable.
|
|
1001
|
+
*
|
|
1002
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
1003
|
+
*
|
|
1004
|
+
* @category Releases
|
|
1005
|
+
*
|
|
1006
|
+
* @param params - Release action parameters:
|
|
1007
|
+
* - `releaseId` - The id of the release to archive.
|
|
1008
|
+
* @param options - Additional action options.
|
|
1009
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1010
|
+
*/
|
|
1011
|
+
archive({ releaseId }, options) {
|
|
1012
|
+
const archiveAction = {
|
|
1013
|
+
actionType: "sanity.action.release.archive",
|
|
1014
|
+
releaseId
|
|
1015
|
+
};
|
|
1016
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, archiveAction, options));
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* @public
|
|
1020
|
+
*
|
|
1021
|
+
* An unarchive action restores an archived release and all documents
|
|
1022
|
+
* with the content they had just prior to archiving.
|
|
1023
|
+
*
|
|
1024
|
+
* @category Releases
|
|
1025
|
+
*
|
|
1026
|
+
* @param params - Release action parameters:
|
|
1027
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
1028
|
+
* @param options - Additional action options.
|
|
1029
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1030
|
+
*/
|
|
1031
|
+
unarchive({ releaseId }, options) {
|
|
1032
|
+
const unarchiveAction = {
|
|
1033
|
+
actionType: "sanity.action.release.unarchive",
|
|
1034
|
+
releaseId
|
|
1035
|
+
};
|
|
1036
|
+
return lastValueFrom(
|
|
1037
|
+
_action(this.#client.config(), this.#httpRequest, unarchiveAction, options)
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* @public
|
|
1042
|
+
*
|
|
1043
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
1044
|
+
* The release is locked such that no documents in the release can be modified and
|
|
1045
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
1046
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
1047
|
+
*
|
|
1048
|
+
* @category Releases
|
|
1049
|
+
*
|
|
1050
|
+
* @param params - Release action parameters:
|
|
1051
|
+
* - `releaseId` - The id of the release to schedule.
|
|
1052
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
1053
|
+
* @param options - Additional action options.
|
|
1054
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1055
|
+
*/
|
|
1056
|
+
schedule({ releaseId, publishAt }, options) {
|
|
1057
|
+
const scheduleAction = {
|
|
1058
|
+
actionType: "sanity.action.release.schedule",
|
|
1059
|
+
releaseId,
|
|
1060
|
+
publishAt
|
|
1061
|
+
};
|
|
1062
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, scheduleAction, options));
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* @public
|
|
1066
|
+
*
|
|
1067
|
+
* An unschedule action stops a release from being published.
|
|
1068
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
1069
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
1070
|
+
* has a reference to a document created by this one.
|
|
1071
|
+
*
|
|
1072
|
+
* @category Releases
|
|
1073
|
+
*
|
|
1074
|
+
* @param params - Release action parameters:
|
|
1075
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
1076
|
+
* @param options - Additional action options.
|
|
1077
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1078
|
+
*/
|
|
1079
|
+
unschedule({ releaseId }, options) {
|
|
1080
|
+
const unscheduleAction = {
|
|
1081
|
+
actionType: "sanity.action.release.unschedule",
|
|
1082
|
+
releaseId
|
|
1083
|
+
};
|
|
1084
|
+
return lastValueFrom(
|
|
1085
|
+
_action(this.#client.config(), this.#httpRequest, unscheduleAction, options)
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* @public
|
|
1090
|
+
*
|
|
1091
|
+
* A delete action removes a published or archived release.
|
|
1092
|
+
* The backing system document will be removed from the dataset.
|
|
1093
|
+
*
|
|
1094
|
+
* @category Releases
|
|
1095
|
+
*
|
|
1096
|
+
* @param params - Release action parameters:
|
|
1097
|
+
* - `releaseId` - The id of the release to delete.
|
|
1098
|
+
* @param options - Additional action options.
|
|
1099
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1100
|
+
*/
|
|
1101
|
+
delete({ releaseId }, options) {
|
|
1102
|
+
const deleteAction = {
|
|
1103
|
+
actionType: "sanity.action.release.delete",
|
|
1104
|
+
releaseId
|
|
1105
|
+
};
|
|
1106
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, deleteAction, options));
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* @public
|
|
1110
|
+
*
|
|
1111
|
+
* Fetch the documents in a release by release id.
|
|
1112
|
+
*
|
|
1113
|
+
* @category Releases
|
|
1114
|
+
*
|
|
1115
|
+
* @param params - Release action parameters:
|
|
1116
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
1117
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
1118
|
+
* @returns A promise that resolves to the documents in the release.
|
|
1119
|
+
*/
|
|
1120
|
+
fetchDocuments({ releaseId }, options) {
|
|
1121
|
+
return lastValueFrom(
|
|
1122
|
+
_getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options)
|
|
571
1123
|
);
|
|
572
1124
|
}
|
|
573
1125
|
}
|
|
@@ -603,9 +1155,13 @@ class UsersClient {
|
|
|
603
1155
|
*/
|
|
604
1156
|
getById(id) {
|
|
605
1157
|
return lastValueFrom(
|
|
606
|
-
_request(
|
|
607
|
-
|
|
608
|
-
|
|
1158
|
+
_request(
|
|
1159
|
+
this.#client.config(),
|
|
1160
|
+
this.#httpRequest,
|
|
1161
|
+
{
|
|
1162
|
+
uri: `/users/${id}`
|
|
1163
|
+
}
|
|
1164
|
+
)
|
|
609
1165
|
);
|
|
610
1166
|
}
|
|
611
1167
|
}
|
|
@@ -616,6 +1172,7 @@ class ObservableSanityClient {
|
|
|
616
1172
|
projects;
|
|
617
1173
|
users;
|
|
618
1174
|
agent;
|
|
1175
|
+
releases;
|
|
619
1176
|
/**
|
|
620
1177
|
* Private properties
|
|
621
1178
|
*/
|
|
@@ -628,7 +1185,7 @@ class ObservableSanityClient {
|
|
|
628
1185
|
constructor(httpRequest, config = defaultConfig) {
|
|
629
1186
|
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
|
|
630
1187
|
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
631
|
-
};
|
|
1188
|
+
}, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
632
1189
|
}
|
|
633
1190
|
/**
|
|
634
1191
|
* Clone the client - returns a new instance
|
|
@@ -693,17 +1250,132 @@ class ObservableSanityClient {
|
|
|
693
1250
|
return _getDocuments(this.#clientConfig, this.#httpRequest, ids, options);
|
|
694
1251
|
}
|
|
695
1252
|
create(document, options) {
|
|
696
|
-
return _create(
|
|
1253
|
+
return _create(
|
|
1254
|
+
this.#clientConfig,
|
|
1255
|
+
this.#httpRequest,
|
|
1256
|
+
document,
|
|
1257
|
+
"create",
|
|
1258
|
+
options
|
|
1259
|
+
);
|
|
697
1260
|
}
|
|
698
1261
|
createIfNotExists(document, options) {
|
|
699
|
-
return _createIfNotExists(
|
|
1262
|
+
return _createIfNotExists(
|
|
1263
|
+
this.#clientConfig,
|
|
1264
|
+
this.#httpRequest,
|
|
1265
|
+
document,
|
|
1266
|
+
options
|
|
1267
|
+
);
|
|
700
1268
|
}
|
|
701
1269
|
createOrReplace(document, options) {
|
|
702
1270
|
return _createOrReplace(this.#clientConfig, this.#httpRequest, document, options);
|
|
703
1271
|
}
|
|
1272
|
+
createVersion({
|
|
1273
|
+
document,
|
|
1274
|
+
publishedId,
|
|
1275
|
+
releaseId
|
|
1276
|
+
}, options) {
|
|
1277
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
1278
|
+
document,
|
|
1279
|
+
publishedId,
|
|
1280
|
+
releaseId
|
|
1281
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId(document._id);
|
|
1282
|
+
return _createVersion(
|
|
1283
|
+
this.config(),
|
|
1284
|
+
this.#httpRequest,
|
|
1285
|
+
documentVersion,
|
|
1286
|
+
versionPublishedId,
|
|
1287
|
+
options
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
704
1290
|
delete(selection, options) {
|
|
705
1291
|
return _delete(this.#clientConfig, this.#httpRequest, selection, options);
|
|
706
1292
|
}
|
|
1293
|
+
/**
|
|
1294
|
+
* @public
|
|
1295
|
+
*
|
|
1296
|
+
* Deletes the draft or release version of a document.
|
|
1297
|
+
*
|
|
1298
|
+
* @remarks
|
|
1299
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1300
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1301
|
+
*
|
|
1302
|
+
* @param params - Version action parameters:
|
|
1303
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1304
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1305
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1306
|
+
* @param options - Additional action options.
|
|
1307
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
1308
|
+
*
|
|
1309
|
+
* @example Discarding a release version of a document
|
|
1310
|
+
* ```ts
|
|
1311
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1312
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
1313
|
+
* ```
|
|
1314
|
+
*
|
|
1315
|
+
* @example Discarding a draft version of a document
|
|
1316
|
+
* ```ts
|
|
1317
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
1318
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
1319
|
+
* ```
|
|
1320
|
+
*/
|
|
1321
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
1322
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
1323
|
+
return _discardVersion(
|
|
1324
|
+
this.config(),
|
|
1325
|
+
this.#httpRequest,
|
|
1326
|
+
documentVersionId,
|
|
1327
|
+
purge,
|
|
1328
|
+
options
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
replaceVersion({
|
|
1332
|
+
document,
|
|
1333
|
+
publishedId,
|
|
1334
|
+
releaseId
|
|
1335
|
+
}, options) {
|
|
1336
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
1337
|
+
document,
|
|
1338
|
+
publishedId,
|
|
1339
|
+
releaseId
|
|
1340
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
1341
|
+
return _replaceVersion(
|
|
1342
|
+
this.config(),
|
|
1343
|
+
this.#httpRequest,
|
|
1344
|
+
documentVersion,
|
|
1345
|
+
options
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* @public
|
|
1350
|
+
*
|
|
1351
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
1352
|
+
* the release is run.
|
|
1353
|
+
*
|
|
1354
|
+
* @remarks
|
|
1355
|
+
* * If the published document does not exist, an error will be thrown.
|
|
1356
|
+
*
|
|
1357
|
+
* @param params - Version action parameters:
|
|
1358
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
1359
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
1360
|
+
* @param options - Additional action options.
|
|
1361
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
1362
|
+
*
|
|
1363
|
+
* @example Unpublishing a release version of a published document
|
|
1364
|
+
* ```ts
|
|
1365
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1366
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
1367
|
+
* ```
|
|
1368
|
+
*/
|
|
1369
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
1370
|
+
const versionId = getVersionId(publishedId, releaseId);
|
|
1371
|
+
return _unpublishVersion(
|
|
1372
|
+
this.config(),
|
|
1373
|
+
this.#httpRequest,
|
|
1374
|
+
versionId,
|
|
1375
|
+
publishedId,
|
|
1376
|
+
options
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
707
1379
|
mutate(operations, options) {
|
|
708
1380
|
return _mutate(this.#clientConfig, this.#httpRequest, operations, options);
|
|
709
1381
|
}
|
|
@@ -768,6 +1440,7 @@ class SanityClient {
|
|
|
768
1440
|
projects;
|
|
769
1441
|
users;
|
|
770
1442
|
agent;
|
|
1443
|
+
releases;
|
|
771
1444
|
/**
|
|
772
1445
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
773
1446
|
*/
|
|
@@ -784,7 +1457,7 @@ class SanityClient {
|
|
|
784
1457
|
constructor(httpRequest, config = defaultConfig) {
|
|
785
1458
|
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
|
|
786
1459
|
action: new AgentActionsClient(this, this.#httpRequest)
|
|
787
|
-
}, this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1460
|
+
}, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
788
1461
|
}
|
|
789
1462
|
/**
|
|
790
1463
|
* Clone the client - returns a new instance
|
|
@@ -836,7 +1509,9 @@ class SanityClient {
|
|
|
836
1509
|
* @param options - Request options
|
|
837
1510
|
*/
|
|
838
1511
|
getDocument(id, options) {
|
|
839
|
-
return lastValueFrom(
|
|
1512
|
+
return lastValueFrom(
|
|
1513
|
+
_getDocument(this.#clientConfig, this.#httpRequest, id, options)
|
|
1514
|
+
);
|
|
840
1515
|
}
|
|
841
1516
|
/**
|
|
842
1517
|
* Fetch multiple documents in one request.
|
|
@@ -848,7 +1523,9 @@ class SanityClient {
|
|
|
848
1523
|
* @param options - Request options
|
|
849
1524
|
*/
|
|
850
1525
|
getDocuments(ids, options) {
|
|
851
|
-
return lastValueFrom(
|
|
1526
|
+
return lastValueFrom(
|
|
1527
|
+
_getDocuments(this.#clientConfig, this.#httpRequest, ids, options)
|
|
1528
|
+
);
|
|
852
1529
|
}
|
|
853
1530
|
create(document, options) {
|
|
854
1531
|
return lastValueFrom(
|
|
@@ -865,11 +1542,122 @@ class SanityClient {
|
|
|
865
1542
|
_createOrReplace(this.#clientConfig, this.#httpRequest, document, options)
|
|
866
1543
|
);
|
|
867
1544
|
}
|
|
1545
|
+
createVersion({
|
|
1546
|
+
document,
|
|
1547
|
+
publishedId,
|
|
1548
|
+
releaseId
|
|
1549
|
+
}, options) {
|
|
1550
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
1551
|
+
document,
|
|
1552
|
+
publishedId,
|
|
1553
|
+
releaseId
|
|
1554
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId(document._id);
|
|
1555
|
+
return firstValueFrom(
|
|
1556
|
+
_createVersion(
|
|
1557
|
+
this.config(),
|
|
1558
|
+
this.#httpRequest,
|
|
1559
|
+
documentVersion,
|
|
1560
|
+
versionPublishedId,
|
|
1561
|
+
options
|
|
1562
|
+
)
|
|
1563
|
+
);
|
|
1564
|
+
}
|
|
868
1565
|
delete(selection, options) {
|
|
869
|
-
return lastValueFrom(
|
|
1566
|
+
return lastValueFrom(
|
|
1567
|
+
_delete(this.#clientConfig, this.#httpRequest, selection, options)
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* @public
|
|
1572
|
+
*
|
|
1573
|
+
* Deletes the draft or release version of a document.
|
|
1574
|
+
*
|
|
1575
|
+
* @remarks
|
|
1576
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1577
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1578
|
+
*
|
|
1579
|
+
* @param params - Version action parameters:
|
|
1580
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1581
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1582
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1583
|
+
* @param options - Additional action options.
|
|
1584
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1585
|
+
*
|
|
1586
|
+
* @example Discarding a release version of a document
|
|
1587
|
+
* ```ts
|
|
1588
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1589
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
1590
|
+
* ```
|
|
1591
|
+
*
|
|
1592
|
+
* @example Discarding a draft version of a document
|
|
1593
|
+
* ```ts
|
|
1594
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
1595
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
1596
|
+
* ```
|
|
1597
|
+
*/
|
|
1598
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
1599
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
1600
|
+
return lastValueFrom(
|
|
1601
|
+
_discardVersion(
|
|
1602
|
+
this.config(),
|
|
1603
|
+
this.#httpRequest,
|
|
1604
|
+
documentVersionId,
|
|
1605
|
+
purge,
|
|
1606
|
+
options
|
|
1607
|
+
)
|
|
1608
|
+
);
|
|
1609
|
+
}
|
|
1610
|
+
replaceVersion({
|
|
1611
|
+
document,
|
|
1612
|
+
publishedId,
|
|
1613
|
+
releaseId
|
|
1614
|
+
}, options) {
|
|
1615
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
1616
|
+
document,
|
|
1617
|
+
publishedId,
|
|
1618
|
+
releaseId
|
|
1619
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
1620
|
+
return firstValueFrom(
|
|
1621
|
+
_replaceVersion(this.config(), this.#httpRequest, documentVersion, options)
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* @public
|
|
1626
|
+
*
|
|
1627
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
1628
|
+
* the release is run.
|
|
1629
|
+
*
|
|
1630
|
+
* @remarks
|
|
1631
|
+
* * If the published document does not exist, an error will be thrown.
|
|
1632
|
+
*
|
|
1633
|
+
* @param params - Version action parameters:
|
|
1634
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
1635
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
1636
|
+
* @param options - Additional action options.
|
|
1637
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1638
|
+
*
|
|
1639
|
+
* @example Unpublishing a release version of a published document
|
|
1640
|
+
* ```ts
|
|
1641
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1642
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
1643
|
+
* ```
|
|
1644
|
+
*/
|
|
1645
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
1646
|
+
const versionId = getVersionId(publishedId, releaseId);
|
|
1647
|
+
return lastValueFrom(
|
|
1648
|
+
_unpublishVersion(
|
|
1649
|
+
this.config(),
|
|
1650
|
+
this.#httpRequest,
|
|
1651
|
+
versionId,
|
|
1652
|
+
publishedId,
|
|
1653
|
+
options
|
|
1654
|
+
)
|
|
1655
|
+
);
|
|
870
1656
|
}
|
|
871
1657
|
mutate(operations, options) {
|
|
872
|
-
return lastValueFrom(
|
|
1658
|
+
return lastValueFrom(
|
|
1659
|
+
_mutate(this.#clientConfig, this.#httpRequest, operations, options)
|
|
1660
|
+
);
|
|
873
1661
|
}
|
|
874
1662
|
/**
|
|
875
1663
|
* Create a new buildable patch of operations to perform
|
|
@@ -897,7 +1685,9 @@ class SanityClient {
|
|
|
897
1685
|
* @param options - Action options
|
|
898
1686
|
*/
|
|
899
1687
|
action(operations, options) {
|
|
900
|
-
return lastValueFrom(
|
|
1688
|
+
return lastValueFrom(
|
|
1689
|
+
_action(this.#clientConfig, this.#httpRequest, operations, options)
|
|
1690
|
+
);
|
|
901
1691
|
}
|
|
902
1692
|
/**
|
|
903
1693
|
* Perform a request against the Sanity API
|
|
@@ -920,7 +1710,9 @@ class SanityClient {
|
|
|
920
1710
|
* @internal
|
|
921
1711
|
*/
|
|
922
1712
|
dataRequest(endpoint, body, options) {
|
|
923
|
-
return lastValueFrom(
|
|
1713
|
+
return lastValueFrom(
|
|
1714
|
+
_dataRequest(this.#clientConfig, this.#httpRequest, endpoint, body, options)
|
|
1715
|
+
);
|
|
924
1716
|
}
|
|
925
1717
|
/**
|
|
926
1718
|
* Get a Sanity API URL for the URI provided
|
|
@@ -960,7 +1752,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
960
1752
|
return printNoDefaultExport(), createClient2(config);
|
|
961
1753
|
};
|
|
962
1754
|
}
|
|
963
|
-
var name = "@sanity/client", version = "7.1.0-views.
|
|
1755
|
+
var name = "@sanity/client", version = "7.1.0-views.1";
|
|
964
1756
|
const middleware = [
|
|
965
1757
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
966
1758
|
headers({ "User-Agent": `${name} ${version}` }),
|
|
@@ -995,9 +1787,12 @@ export {
|
|
|
995
1787
|
SanityClient,
|
|
996
1788
|
ServerError,
|
|
997
1789
|
Transaction,
|
|
1790
|
+
ViewResourceType,
|
|
998
1791
|
connectEventSource,
|
|
999
1792
|
createClient,
|
|
1000
1793
|
deprecatedCreateClient as default,
|
|
1794
|
+
formatQueryParseError,
|
|
1795
|
+
isQueryParseError,
|
|
1001
1796
|
requester,
|
|
1002
1797
|
adapter as unstable__adapter,
|
|
1003
1798
|
environment as unstable__environment,
|