@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.cjs
CHANGED
|
@@ -21,7 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
22
|
var dataMethods = require("./_chunks-cjs/dataMethods.cjs");
|
|
23
23
|
require("./_chunks-cjs/stegaClean.cjs");
|
|
24
|
-
var rxjs = require("rxjs"), operators = require("rxjs/operators"), config = require("./_chunks-cjs/config.cjs"), middleware$1 = require("get-it/middleware"), getIt = require("get-it");
|
|
24
|
+
var rxjs = require("rxjs"), operators = require("rxjs/operators"), config = require("./_chunks-cjs/config.cjs"), middleware$1 = require("get-it/middleware"), csm = require("@sanity/client/csm"), crypto = require("crypto"), getIt = require("get-it");
|
|
25
|
+
function _interopDefaultCompat(e) {
|
|
26
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
27
|
+
}
|
|
28
|
+
var crypto__default = /* @__PURE__ */ _interopDefaultCompat(crypto), ViewResourceType = /* @__PURE__ */ ((ViewResourceType2) => (ViewResourceType2.Dataset = "dataset", ViewResourceType2))(ViewResourceType || {});
|
|
25
29
|
class ConnectionFailedError extends Error {
|
|
26
30
|
name = "ConnectionFailedError";
|
|
27
31
|
}
|
|
@@ -81,7 +85,8 @@ function connectWithESInstance(es, events) {
|
|
|
81
85
|
return;
|
|
82
86
|
}
|
|
83
87
|
if (message.type === "channelError") {
|
|
84
|
-
|
|
88
|
+
const tag = new URL(es.url).searchParams.get("tag");
|
|
89
|
+
observer.error(new ChannelError(extractErrorMessage(event?.data, tag), event.data));
|
|
85
90
|
return;
|
|
86
91
|
}
|
|
87
92
|
if (message.type === "disconnect") {
|
|
@@ -120,8 +125,9 @@ function parseEvent(message) {
|
|
|
120
125
|
return [err, null];
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
|
-
function extractErrorMessage(err) {
|
|
124
|
-
|
|
128
|
+
function extractErrorMessage(err, tag) {
|
|
129
|
+
const error = err.error;
|
|
130
|
+
return error ? dataMethods.isQueryParseError(error) ? dataMethods.formatQueryParseError(error, tag) : error.description ? error.description : typeof error == "string" ? error : JSON.stringify(error, null, 2) : err.message || "Unknown listener error";
|
|
125
131
|
}
|
|
126
132
|
function isEmptyObject(data) {
|
|
127
133
|
for (const _ in data)
|
|
@@ -136,6 +142,22 @@ function _generate(client, httpRequest, request) {
|
|
|
136
142
|
body: request
|
|
137
143
|
});
|
|
138
144
|
}
|
|
145
|
+
function _patch(client, httpRequest, request) {
|
|
146
|
+
const dataset = config.hasDataset(client.config());
|
|
147
|
+
return dataMethods._request(client.config(), httpRequest, {
|
|
148
|
+
method: "POST",
|
|
149
|
+
uri: `/agent/action/patch/${dataset}`,
|
|
150
|
+
body: request
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function _prompt(client, httpRequest, request) {
|
|
154
|
+
const dataset = config.hasDataset(client.config());
|
|
155
|
+
return dataMethods._request(client.config(), httpRequest, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
uri: `/agent/action/prompt/${dataset}`,
|
|
158
|
+
body: request
|
|
159
|
+
});
|
|
160
|
+
}
|
|
139
161
|
function _transform(client, httpRequest, request) {
|
|
140
162
|
const dataset = config.hasDataset(client.config());
|
|
141
163
|
return dataMethods._request(client.config(), httpRequest, {
|
|
@@ -207,6 +229,21 @@ class AgentActionsClient {
|
|
|
207
229
|
translate(request) {
|
|
208
230
|
return rxjs.lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
209
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Run a raw instruction and return the result either as text or json
|
|
234
|
+
* @param request - prompt request
|
|
235
|
+
*/
|
|
236
|
+
prompt(request) {
|
|
237
|
+
return rxjs.lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Patch a document using a schema aware API.
|
|
241
|
+
* Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
|
|
242
|
+
* @param request - instruction request
|
|
243
|
+
*/
|
|
244
|
+
patch(request) {
|
|
245
|
+
return rxjs.lastValueFrom(_patch(this.#client, this.#httpRequest, request));
|
|
246
|
+
}
|
|
210
247
|
}
|
|
211
248
|
class ObservableAssetsClient {
|
|
212
249
|
#client;
|
|
@@ -315,13 +352,11 @@ const MAX_URL_LENGTH = 14800, possibleOptions = [
|
|
|
315
352
|
includeResult: !0
|
|
316
353
|
};
|
|
317
354
|
function _listen(query, params, opts = {}) {
|
|
318
|
-
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 = dataMethods.encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${dataMethods._getDataUrl(this.config(), "listen", qs)}`;
|
|
355
|
+
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 = dataMethods.encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${dataMethods._getDataUrl(this.config(), "listen", qs)}`;
|
|
319
356
|
if (uri.length > MAX_URL_LENGTH)
|
|
320
357
|
return rxjs.throwError(() => new Error("Query too large for listener"));
|
|
321
358
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
322
|
-
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
323
|
-
Authorization: `Bearer ${token}`
|
|
324
|
-
}), connectEventSource(() => (
|
|
359
|
+
return withCredentials && (esOptions.withCredentials = !0), (token || configHeaders) && (esOptions.headers = {}, token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders)), connectEventSource(() => (
|
|
325
360
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
326
361
|
(typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : rxjs.of(EventSource)).pipe(operators.map((EventSource2) => new EventSource2(uri, esOptions)))
|
|
327
362
|
), listenFor).pipe(
|
|
@@ -379,7 +414,8 @@ class LiveClient {
|
|
|
379
414
|
apiVersion: _apiVersion,
|
|
380
415
|
token,
|
|
381
416
|
withCredentials,
|
|
382
|
-
requestTagPrefix
|
|
417
|
+
requestTagPrefix,
|
|
418
|
+
headers: configHeaders
|
|
383
419
|
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
384
420
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
385
421
|
throw new Error(
|
|
@@ -392,9 +428,7 @@ class LiveClient {
|
|
|
392
428
|
const path = dataMethods._getDataUrl(this.#client.config(), "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
393
429
|
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
394
430
|
const esOptions = {};
|
|
395
|
-
includeDrafts && token && (esOptions.headers = {
|
|
396
|
-
Authorization: `Bearer ${token}`
|
|
397
|
-
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
|
|
431
|
+
includeDrafts && withCredentials && (esOptions.withCredentials = !0), (includeDrafts && token || configHeaders) && (esOptions.headers = {}, includeDrafts && token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders));
|
|
398
432
|
const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
|
|
399
433
|
if (existing)
|
|
400
434
|
return existing;
|
|
@@ -532,7 +566,10 @@ class DatasetsClient {
|
|
|
532
566
|
*/
|
|
533
567
|
list() {
|
|
534
568
|
return config.resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
|
|
535
|
-
dataMethods._request(this.#client.config(), this.#httpRequest, {
|
|
569
|
+
dataMethods._request(this.#client.config(), this.#httpRequest, {
|
|
570
|
+
uri: "/datasets",
|
|
571
|
+
tag: null
|
|
572
|
+
})
|
|
536
573
|
);
|
|
537
574
|
}
|
|
538
575
|
}
|
|
@@ -561,7 +598,9 @@ class ObservableProjectsClient {
|
|
|
561
598
|
* @param projectId - ID of the project to fetch
|
|
562
599
|
*/
|
|
563
600
|
getById(projectId) {
|
|
564
|
-
return config.resourceGuard("projects", this.#client.config()), dataMethods._request(this.#client.config(), this.#httpRequest, {
|
|
601
|
+
return config.resourceGuard("projects", this.#client.config()), dataMethods._request(this.#client.config(), this.#httpRequest, {
|
|
602
|
+
uri: `/projects/${projectId}`
|
|
603
|
+
});
|
|
565
604
|
}
|
|
566
605
|
}
|
|
567
606
|
class ProjectsClient {
|
|
@@ -582,7 +621,521 @@ class ProjectsClient {
|
|
|
582
621
|
*/
|
|
583
622
|
getById(projectId) {
|
|
584
623
|
return config.resourceGuard("projects", this.#client.config()), rxjs.lastValueFrom(
|
|
585
|
-
dataMethods._request(this.#client.config(), this.#httpRequest, {
|
|
624
|
+
dataMethods._request(this.#client.config(), this.#httpRequest, {
|
|
625
|
+
uri: `/projects/${projectId}`
|
|
626
|
+
})
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const POOL_SIZE_MULTIPLIER = 128;
|
|
631
|
+
let pool, poolOffset, fillPool = (bytes) => {
|
|
632
|
+
!pool || pool.length < bytes ? (pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER), crypto__default.default.randomFillSync(pool), poolOffset = 0) : poolOffset + bytes > pool.length && (crypto__default.default.randomFillSync(pool), poolOffset = 0), poolOffset += bytes;
|
|
633
|
+
}, random = (bytes) => (fillPool(bytes |= 0), pool.subarray(poolOffset - bytes, poolOffset)), customRandom = (alphabet, defaultSize, getRandom) => {
|
|
634
|
+
let mask = (2 << 31 - Math.clz32(alphabet.length - 1 | 1)) - 1, step = Math.ceil(1.6 * mask * defaultSize / alphabet.length);
|
|
635
|
+
return (size = defaultSize) => {
|
|
636
|
+
let id = "";
|
|
637
|
+
for (; ; ) {
|
|
638
|
+
let bytes = getRandom(step), i = step;
|
|
639
|
+
for (; i--; )
|
|
640
|
+
if (id += alphabet[bytes[i] & mask] || "", id.length === size) return id;
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}, customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size, random);
|
|
644
|
+
const generateReleaseId = customAlphabet(
|
|
645
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
646
|
+
8
|
|
647
|
+
), getDocumentVersionId = (publishedId, releaseId) => releaseId ? csm.getVersionId(publishedId, releaseId) : csm.getDraftId(publishedId);
|
|
648
|
+
function deriveDocumentVersionId(op, {
|
|
649
|
+
releaseId,
|
|
650
|
+
publishedId,
|
|
651
|
+
document
|
|
652
|
+
}) {
|
|
653
|
+
if (publishedId && document._id) {
|
|
654
|
+
const versionId = getDocumentVersionId(publishedId, releaseId);
|
|
655
|
+
return config.validateVersionIdMatch(versionId, document), versionId;
|
|
656
|
+
}
|
|
657
|
+
if (document._id) {
|
|
658
|
+
const isDraft = csm.isDraftId(document._id), isVersion = csm.isVersionId(document._id);
|
|
659
|
+
if (!isDraft && !isVersion)
|
|
660
|
+
throw new Error(
|
|
661
|
+
`\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
|
|
662
|
+
);
|
|
663
|
+
if (releaseId) {
|
|
664
|
+
if (isDraft)
|
|
665
|
+
throw new Error(
|
|
666
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
|
|
667
|
+
);
|
|
668
|
+
const builtVersionId = csm.getVersionFromId(document._id);
|
|
669
|
+
if (builtVersionId !== releaseId)
|
|
670
|
+
throw new Error(
|
|
671
|
+
`\`${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}\`).`
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
return document._id;
|
|
675
|
+
}
|
|
676
|
+
if (publishedId)
|
|
677
|
+
return getDocumentVersionId(publishedId, releaseId);
|
|
678
|
+
throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
|
|
679
|
+
}
|
|
680
|
+
const getArgs = (releaseOrOptions, maybeOptions) => {
|
|
681
|
+
if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
|
|
682
|
+
const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
|
|
683
|
+
return [releaseId, metadata, maybeOptions];
|
|
684
|
+
}
|
|
685
|
+
return [generateReleaseId(), {}, releaseOrOptions];
|
|
686
|
+
}, createRelease = (releaseOrOptions, maybeOptions) => {
|
|
687
|
+
const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
|
|
688
|
+
...metadata,
|
|
689
|
+
releaseType: metadata.releaseType || "undecided"
|
|
690
|
+
};
|
|
691
|
+
return { action: {
|
|
692
|
+
actionType: "sanity.action.release.create",
|
|
693
|
+
releaseId,
|
|
694
|
+
metadata: finalMetadata
|
|
695
|
+
}, options };
|
|
696
|
+
};
|
|
697
|
+
class ObservableReleasesClient {
|
|
698
|
+
#client;
|
|
699
|
+
#httpRequest;
|
|
700
|
+
constructor(client, httpRequest) {
|
|
701
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* @public
|
|
705
|
+
*
|
|
706
|
+
* Retrieve a release by id.
|
|
707
|
+
*
|
|
708
|
+
* @category Releases
|
|
709
|
+
*
|
|
710
|
+
* @param params - Release action parameters:
|
|
711
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
712
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
713
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
714
|
+
*
|
|
715
|
+
* @example Retrieving a release by id
|
|
716
|
+
* ```ts
|
|
717
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
718
|
+
* tap((release) => console.log(release)),
|
|
719
|
+
* // {
|
|
720
|
+
* // _id: '_.releases.my-release',
|
|
721
|
+
* // name: 'my-release'
|
|
722
|
+
* // _type: 'system.release',
|
|
723
|
+
* // metadata: {releaseType: 'asap'},
|
|
724
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
725
|
+
* // ...
|
|
726
|
+
* // }
|
|
727
|
+
* ).subscribe()
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
get({ releaseId }, options) {
|
|
731
|
+
return dataMethods._getDocument(
|
|
732
|
+
this.#client.config(),
|
|
733
|
+
this.#httpRequest,
|
|
734
|
+
`_.releases.${releaseId}`,
|
|
735
|
+
options
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
create(releaseOrOptions, maybeOptions) {
|
|
739
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
740
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, action, options).pipe(
|
|
741
|
+
rxjs.map((actionResult) => ({
|
|
742
|
+
...actionResult,
|
|
743
|
+
releaseId,
|
|
744
|
+
metadata
|
|
745
|
+
}))
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* @public
|
|
750
|
+
*
|
|
751
|
+
* Edits an existing release, updating the metadata.
|
|
752
|
+
*
|
|
753
|
+
* @category Releases
|
|
754
|
+
*
|
|
755
|
+
* @param params - Release action parameters:
|
|
756
|
+
* - `releaseId` - The id of the release to edit.
|
|
757
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
758
|
+
* @param options - Additional action options.
|
|
759
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
760
|
+
*/
|
|
761
|
+
edit({ releaseId, patch }, options) {
|
|
762
|
+
const editAction = {
|
|
763
|
+
actionType: "sanity.action.release.edit",
|
|
764
|
+
releaseId,
|
|
765
|
+
patch
|
|
766
|
+
};
|
|
767
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, editAction, options);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* @public
|
|
771
|
+
*
|
|
772
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
773
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
774
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
775
|
+
* take some time.
|
|
776
|
+
*
|
|
777
|
+
* During this period both the source and target documents are locked and cannot be
|
|
778
|
+
* modified through any other means.
|
|
779
|
+
*
|
|
780
|
+
* @category Releases
|
|
781
|
+
*
|
|
782
|
+
* @param params - Release action parameters:
|
|
783
|
+
* - `releaseId` - The id of the release to publish.
|
|
784
|
+
* @param options - Additional action options.
|
|
785
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
786
|
+
*/
|
|
787
|
+
publish({ releaseId }, options) {
|
|
788
|
+
const publishAction = {
|
|
789
|
+
actionType: "sanity.action.release.publish",
|
|
790
|
+
releaseId
|
|
791
|
+
};
|
|
792
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, publishAction, options);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* @public
|
|
796
|
+
*
|
|
797
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
798
|
+
* are deleted and therefore no longer queryable.
|
|
799
|
+
*
|
|
800
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
801
|
+
*
|
|
802
|
+
* @category Releases
|
|
803
|
+
*
|
|
804
|
+
* @param params - Release action parameters:
|
|
805
|
+
* - `releaseId` - The id of the release to archive.
|
|
806
|
+
* @param options - Additional action options.
|
|
807
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
808
|
+
*/
|
|
809
|
+
archive({ releaseId }, options) {
|
|
810
|
+
const archiveAction = {
|
|
811
|
+
actionType: "sanity.action.release.archive",
|
|
812
|
+
releaseId
|
|
813
|
+
};
|
|
814
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, archiveAction, options);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* @public
|
|
818
|
+
*
|
|
819
|
+
* An unarchive action restores an archived release and all documents
|
|
820
|
+
* with the content they had just prior to archiving.
|
|
821
|
+
*
|
|
822
|
+
* @category Releases
|
|
823
|
+
*
|
|
824
|
+
* @param params - Release action parameters:
|
|
825
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
826
|
+
* @param options - Additional action options.
|
|
827
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
828
|
+
*/
|
|
829
|
+
unarchive({ releaseId }, options) {
|
|
830
|
+
const unarchiveAction = {
|
|
831
|
+
actionType: "sanity.action.release.unarchive",
|
|
832
|
+
releaseId
|
|
833
|
+
};
|
|
834
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, unarchiveAction, options);
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* @public
|
|
838
|
+
*
|
|
839
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
840
|
+
* The release is locked such that no documents in the release can be modified and
|
|
841
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
842
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
843
|
+
*
|
|
844
|
+
* @category Releases
|
|
845
|
+
*
|
|
846
|
+
* @param params - Release action parameters:
|
|
847
|
+
* - `releaseId` - The id of the release to schedule.
|
|
848
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
849
|
+
* @param options - Additional action options.
|
|
850
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
851
|
+
*/
|
|
852
|
+
schedule({ releaseId, publishAt }, options) {
|
|
853
|
+
const scheduleAction = {
|
|
854
|
+
actionType: "sanity.action.release.schedule",
|
|
855
|
+
releaseId,
|
|
856
|
+
publishAt
|
|
857
|
+
};
|
|
858
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, scheduleAction, options);
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* @public
|
|
862
|
+
*
|
|
863
|
+
* An unschedule action stops a release from being published.
|
|
864
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
865
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
866
|
+
* has a reference to a document created by this one.
|
|
867
|
+
*
|
|
868
|
+
* @category Releases
|
|
869
|
+
*
|
|
870
|
+
* @param params - Release action parameters:
|
|
871
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
872
|
+
* @param options - Additional action options.
|
|
873
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
874
|
+
*/
|
|
875
|
+
unschedule({ releaseId }, options) {
|
|
876
|
+
const unscheduleAction = {
|
|
877
|
+
actionType: "sanity.action.release.unschedule",
|
|
878
|
+
releaseId
|
|
879
|
+
};
|
|
880
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, unscheduleAction, options);
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* @public
|
|
884
|
+
*
|
|
885
|
+
* A delete action removes a published or archived release.
|
|
886
|
+
* The backing system document will be removed from the dataset.
|
|
887
|
+
*
|
|
888
|
+
* @category Releases
|
|
889
|
+
*
|
|
890
|
+
* @param params - Release action parameters:
|
|
891
|
+
* - `releaseId` - The id of the release to delete.
|
|
892
|
+
* @param options - Additional action options.
|
|
893
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
894
|
+
*/
|
|
895
|
+
delete({ releaseId }, options) {
|
|
896
|
+
const deleteAction = {
|
|
897
|
+
actionType: "sanity.action.release.delete",
|
|
898
|
+
releaseId
|
|
899
|
+
};
|
|
900
|
+
return dataMethods._action(this.#client.config(), this.#httpRequest, deleteAction, options);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* @public
|
|
904
|
+
*
|
|
905
|
+
* Fetch the documents in a release by release id.
|
|
906
|
+
*
|
|
907
|
+
* @category Releases
|
|
908
|
+
*
|
|
909
|
+
* @param params - Release action parameters:
|
|
910
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
911
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
912
|
+
* @returns An observable that resolves to the documents in the release.
|
|
913
|
+
*/
|
|
914
|
+
fetchDocuments({ releaseId }, options) {
|
|
915
|
+
return dataMethods._getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
class ReleasesClient {
|
|
919
|
+
#client;
|
|
920
|
+
#httpRequest;
|
|
921
|
+
constructor(client, httpRequest) {
|
|
922
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* @public
|
|
926
|
+
*
|
|
927
|
+
* Retrieve a release by id.
|
|
928
|
+
*
|
|
929
|
+
* @category Releases
|
|
930
|
+
*
|
|
931
|
+
* @param params - Release action parameters:
|
|
932
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
933
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
934
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
935
|
+
*
|
|
936
|
+
* @example Retrieving a release by id
|
|
937
|
+
* ```ts
|
|
938
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
939
|
+
* console.log(release)
|
|
940
|
+
* // {
|
|
941
|
+
* // _id: '_.releases.my-release',
|
|
942
|
+
* // name: 'my-release'
|
|
943
|
+
* // _type: 'system.release',
|
|
944
|
+
* // metadata: {releaseType: 'asap'},
|
|
945
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
946
|
+
* // ...
|
|
947
|
+
* // }
|
|
948
|
+
* ```
|
|
949
|
+
*/
|
|
950
|
+
get({ releaseId }, options) {
|
|
951
|
+
return rxjs.lastValueFrom(
|
|
952
|
+
dataMethods._getDocument(
|
|
953
|
+
this.#client.config(),
|
|
954
|
+
this.#httpRequest,
|
|
955
|
+
`_.releases.${releaseId}`,
|
|
956
|
+
options
|
|
957
|
+
)
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
async create(releaseOrOptions, maybeOptions) {
|
|
961
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
962
|
+
return { ...await rxjs.lastValueFrom(
|
|
963
|
+
dataMethods._action(this.#client.config(), this.#httpRequest, action, options)
|
|
964
|
+
), releaseId, metadata };
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* @public
|
|
968
|
+
*
|
|
969
|
+
* Edits an existing release, updating the metadata.
|
|
970
|
+
*
|
|
971
|
+
* @category Releases
|
|
972
|
+
*
|
|
973
|
+
* @param params - Release action parameters:
|
|
974
|
+
* - `releaseId` - The id of the release to edit.
|
|
975
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
976
|
+
* @param options - Additional action options.
|
|
977
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
978
|
+
*/
|
|
979
|
+
edit({ releaseId, patch }, options) {
|
|
980
|
+
const editAction = {
|
|
981
|
+
actionType: "sanity.action.release.edit",
|
|
982
|
+
releaseId,
|
|
983
|
+
patch
|
|
984
|
+
};
|
|
985
|
+
return rxjs.lastValueFrom(dataMethods._action(this.#client.config(), this.#httpRequest, editAction, options));
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* @public
|
|
989
|
+
*
|
|
990
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
991
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
992
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
993
|
+
* take some time.
|
|
994
|
+
*
|
|
995
|
+
* During this period both the source and target documents are locked and cannot be
|
|
996
|
+
* modified through any other means.
|
|
997
|
+
*
|
|
998
|
+
* @category Releases
|
|
999
|
+
*
|
|
1000
|
+
* @param params - Release action parameters:
|
|
1001
|
+
* - `releaseId` - The id of the release to publish.
|
|
1002
|
+
* @param options - Additional action options.
|
|
1003
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1004
|
+
*/
|
|
1005
|
+
publish({ releaseId }, options) {
|
|
1006
|
+
const publishAction = {
|
|
1007
|
+
actionType: "sanity.action.release.publish",
|
|
1008
|
+
releaseId
|
|
1009
|
+
};
|
|
1010
|
+
return rxjs.lastValueFrom(dataMethods._action(this.#client.config(), this.#httpRequest, publishAction, options));
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* @public
|
|
1014
|
+
*
|
|
1015
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
1016
|
+
* are deleted and therefore no longer queryable.
|
|
1017
|
+
*
|
|
1018
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
1019
|
+
*
|
|
1020
|
+
* @category Releases
|
|
1021
|
+
*
|
|
1022
|
+
* @param params - Release action parameters:
|
|
1023
|
+
* - `releaseId` - The id of the release to archive.
|
|
1024
|
+
* @param options - Additional action options.
|
|
1025
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1026
|
+
*/
|
|
1027
|
+
archive({ releaseId }, options) {
|
|
1028
|
+
const archiveAction = {
|
|
1029
|
+
actionType: "sanity.action.release.archive",
|
|
1030
|
+
releaseId
|
|
1031
|
+
};
|
|
1032
|
+
return rxjs.lastValueFrom(dataMethods._action(this.#client.config(), this.#httpRequest, archiveAction, options));
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* @public
|
|
1036
|
+
*
|
|
1037
|
+
* An unarchive action restores an archived release and all documents
|
|
1038
|
+
* with the content they had just prior to archiving.
|
|
1039
|
+
*
|
|
1040
|
+
* @category Releases
|
|
1041
|
+
*
|
|
1042
|
+
* @param params - Release action parameters:
|
|
1043
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
1044
|
+
* @param options - Additional action options.
|
|
1045
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1046
|
+
*/
|
|
1047
|
+
unarchive({ releaseId }, options) {
|
|
1048
|
+
const unarchiveAction = {
|
|
1049
|
+
actionType: "sanity.action.release.unarchive",
|
|
1050
|
+
releaseId
|
|
1051
|
+
};
|
|
1052
|
+
return rxjs.lastValueFrom(
|
|
1053
|
+
dataMethods._action(this.#client.config(), this.#httpRequest, unarchiveAction, options)
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* @public
|
|
1058
|
+
*
|
|
1059
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
1060
|
+
* The release is locked such that no documents in the release can be modified and
|
|
1061
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
1062
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
1063
|
+
*
|
|
1064
|
+
* @category Releases
|
|
1065
|
+
*
|
|
1066
|
+
* @param params - Release action parameters:
|
|
1067
|
+
* - `releaseId` - The id of the release to schedule.
|
|
1068
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
1069
|
+
* @param options - Additional action options.
|
|
1070
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1071
|
+
*/
|
|
1072
|
+
schedule({ releaseId, publishAt }, options) {
|
|
1073
|
+
const scheduleAction = {
|
|
1074
|
+
actionType: "sanity.action.release.schedule",
|
|
1075
|
+
releaseId,
|
|
1076
|
+
publishAt
|
|
1077
|
+
};
|
|
1078
|
+
return rxjs.lastValueFrom(dataMethods._action(this.#client.config(), this.#httpRequest, scheduleAction, options));
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* @public
|
|
1082
|
+
*
|
|
1083
|
+
* An unschedule action stops a release from being published.
|
|
1084
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
1085
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
1086
|
+
* has a reference to a document created by this one.
|
|
1087
|
+
*
|
|
1088
|
+
* @category Releases
|
|
1089
|
+
*
|
|
1090
|
+
* @param params - Release action parameters:
|
|
1091
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
1092
|
+
* @param options - Additional action options.
|
|
1093
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1094
|
+
*/
|
|
1095
|
+
unschedule({ releaseId }, options) {
|
|
1096
|
+
const unscheduleAction = {
|
|
1097
|
+
actionType: "sanity.action.release.unschedule",
|
|
1098
|
+
releaseId
|
|
1099
|
+
};
|
|
1100
|
+
return rxjs.lastValueFrom(
|
|
1101
|
+
dataMethods._action(this.#client.config(), this.#httpRequest, unscheduleAction, options)
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* @public
|
|
1106
|
+
*
|
|
1107
|
+
* A delete action removes a published or archived release.
|
|
1108
|
+
* The backing system document will be removed from the dataset.
|
|
1109
|
+
*
|
|
1110
|
+
* @category Releases
|
|
1111
|
+
*
|
|
1112
|
+
* @param params - Release action parameters:
|
|
1113
|
+
* - `releaseId` - The id of the release to delete.
|
|
1114
|
+
* @param options - Additional action options.
|
|
1115
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1116
|
+
*/
|
|
1117
|
+
delete({ releaseId }, options) {
|
|
1118
|
+
const deleteAction = {
|
|
1119
|
+
actionType: "sanity.action.release.delete",
|
|
1120
|
+
releaseId
|
|
1121
|
+
};
|
|
1122
|
+
return rxjs.lastValueFrom(dataMethods._action(this.#client.config(), this.#httpRequest, deleteAction, options));
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* @public
|
|
1126
|
+
*
|
|
1127
|
+
* Fetch the documents in a release by release id.
|
|
1128
|
+
*
|
|
1129
|
+
* @category Releases
|
|
1130
|
+
*
|
|
1131
|
+
* @param params - Release action parameters:
|
|
1132
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
1133
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
1134
|
+
* @returns A promise that resolves to the documents in the release.
|
|
1135
|
+
*/
|
|
1136
|
+
fetchDocuments({ releaseId }, options) {
|
|
1137
|
+
return rxjs.lastValueFrom(
|
|
1138
|
+
dataMethods._getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options)
|
|
586
1139
|
);
|
|
587
1140
|
}
|
|
588
1141
|
}
|
|
@@ -618,9 +1171,13 @@ class UsersClient {
|
|
|
618
1171
|
*/
|
|
619
1172
|
getById(id) {
|
|
620
1173
|
return rxjs.lastValueFrom(
|
|
621
|
-
dataMethods._request(
|
|
622
|
-
|
|
623
|
-
|
|
1174
|
+
dataMethods._request(
|
|
1175
|
+
this.#client.config(),
|
|
1176
|
+
this.#httpRequest,
|
|
1177
|
+
{
|
|
1178
|
+
uri: `/users/${id}`
|
|
1179
|
+
}
|
|
1180
|
+
)
|
|
624
1181
|
);
|
|
625
1182
|
}
|
|
626
1183
|
}
|
|
@@ -631,6 +1188,7 @@ class ObservableSanityClient {
|
|
|
631
1188
|
projects;
|
|
632
1189
|
users;
|
|
633
1190
|
agent;
|
|
1191
|
+
releases;
|
|
634
1192
|
/**
|
|
635
1193
|
* Private properties
|
|
636
1194
|
*/
|
|
@@ -643,7 +1201,7 @@ class ObservableSanityClient {
|
|
|
643
1201
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
644
1202
|
this.config(config$1), 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 = {
|
|
645
1203
|
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
646
|
-
};
|
|
1204
|
+
}, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
647
1205
|
}
|
|
648
1206
|
/**
|
|
649
1207
|
* Clone the client - returns a new instance
|
|
@@ -708,17 +1266,132 @@ class ObservableSanityClient {
|
|
|
708
1266
|
return dataMethods._getDocuments(this.#clientConfig, this.#httpRequest, ids, options);
|
|
709
1267
|
}
|
|
710
1268
|
create(document, options) {
|
|
711
|
-
return dataMethods._create(
|
|
1269
|
+
return dataMethods._create(
|
|
1270
|
+
this.#clientConfig,
|
|
1271
|
+
this.#httpRequest,
|
|
1272
|
+
document,
|
|
1273
|
+
"create",
|
|
1274
|
+
options
|
|
1275
|
+
);
|
|
712
1276
|
}
|
|
713
1277
|
createIfNotExists(document, options) {
|
|
714
|
-
return dataMethods._createIfNotExists(
|
|
1278
|
+
return dataMethods._createIfNotExists(
|
|
1279
|
+
this.#clientConfig,
|
|
1280
|
+
this.#httpRequest,
|
|
1281
|
+
document,
|
|
1282
|
+
options
|
|
1283
|
+
);
|
|
715
1284
|
}
|
|
716
1285
|
createOrReplace(document, options) {
|
|
717
1286
|
return dataMethods._createOrReplace(this.#clientConfig, this.#httpRequest, document, options);
|
|
718
1287
|
}
|
|
1288
|
+
createVersion({
|
|
1289
|
+
document,
|
|
1290
|
+
publishedId,
|
|
1291
|
+
releaseId
|
|
1292
|
+
}, options) {
|
|
1293
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
1294
|
+
document,
|
|
1295
|
+
publishedId,
|
|
1296
|
+
releaseId
|
|
1297
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
|
|
1298
|
+
return dataMethods._createVersion(
|
|
1299
|
+
this.config(),
|
|
1300
|
+
this.#httpRequest,
|
|
1301
|
+
documentVersion,
|
|
1302
|
+
versionPublishedId,
|
|
1303
|
+
options
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
719
1306
|
delete(selection, options) {
|
|
720
1307
|
return dataMethods._delete(this.#clientConfig, this.#httpRequest, selection, options);
|
|
721
1308
|
}
|
|
1309
|
+
/**
|
|
1310
|
+
* @public
|
|
1311
|
+
*
|
|
1312
|
+
* Deletes the draft or release version of a document.
|
|
1313
|
+
*
|
|
1314
|
+
* @remarks
|
|
1315
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1316
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1317
|
+
*
|
|
1318
|
+
* @param params - Version action parameters:
|
|
1319
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1320
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1321
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1322
|
+
* @param options - Additional action options.
|
|
1323
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
1324
|
+
*
|
|
1325
|
+
* @example Discarding a release version of a document
|
|
1326
|
+
* ```ts
|
|
1327
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1328
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
1329
|
+
* ```
|
|
1330
|
+
*
|
|
1331
|
+
* @example Discarding a draft version of a document
|
|
1332
|
+
* ```ts
|
|
1333
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
1334
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
1335
|
+
* ```
|
|
1336
|
+
*/
|
|
1337
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
1338
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
1339
|
+
return dataMethods._discardVersion(
|
|
1340
|
+
this.config(),
|
|
1341
|
+
this.#httpRequest,
|
|
1342
|
+
documentVersionId,
|
|
1343
|
+
purge,
|
|
1344
|
+
options
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
replaceVersion({
|
|
1348
|
+
document,
|
|
1349
|
+
publishedId,
|
|
1350
|
+
releaseId
|
|
1351
|
+
}, options) {
|
|
1352
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
1353
|
+
document,
|
|
1354
|
+
publishedId,
|
|
1355
|
+
releaseId
|
|
1356
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
1357
|
+
return dataMethods._replaceVersion(
|
|
1358
|
+
this.config(),
|
|
1359
|
+
this.#httpRequest,
|
|
1360
|
+
documentVersion,
|
|
1361
|
+
options
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* @public
|
|
1366
|
+
*
|
|
1367
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
1368
|
+
* the release is run.
|
|
1369
|
+
*
|
|
1370
|
+
* @remarks
|
|
1371
|
+
* * If the published document does not exist, an error will be thrown.
|
|
1372
|
+
*
|
|
1373
|
+
* @param params - Version action parameters:
|
|
1374
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
1375
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
1376
|
+
* @param options - Additional action options.
|
|
1377
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
1378
|
+
*
|
|
1379
|
+
* @example Unpublishing a release version of a published document
|
|
1380
|
+
* ```ts
|
|
1381
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1382
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
1383
|
+
* ```
|
|
1384
|
+
*/
|
|
1385
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
1386
|
+
const versionId = csm.getVersionId(publishedId, releaseId);
|
|
1387
|
+
return dataMethods._unpublishVersion(
|
|
1388
|
+
this.config(),
|
|
1389
|
+
this.#httpRequest,
|
|
1390
|
+
versionId,
|
|
1391
|
+
publishedId,
|
|
1392
|
+
options
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
722
1395
|
mutate(operations, options) {
|
|
723
1396
|
return dataMethods._mutate(this.#clientConfig, this.#httpRequest, operations, options);
|
|
724
1397
|
}
|
|
@@ -783,6 +1456,7 @@ class SanityClient {
|
|
|
783
1456
|
projects;
|
|
784
1457
|
users;
|
|
785
1458
|
agent;
|
|
1459
|
+
releases;
|
|
786
1460
|
/**
|
|
787
1461
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
788
1462
|
*/
|
|
@@ -799,7 +1473,7 @@ class SanityClient {
|
|
|
799
1473
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
800
1474
|
this.config(config$1), 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 = {
|
|
801
1475
|
action: new AgentActionsClient(this, this.#httpRequest)
|
|
802
|
-
}, this.observable = new ObservableSanityClient(httpRequest, config$1);
|
|
1476
|
+
}, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config$1);
|
|
803
1477
|
}
|
|
804
1478
|
/**
|
|
805
1479
|
* Clone the client - returns a new instance
|
|
@@ -851,7 +1525,9 @@ class SanityClient {
|
|
|
851
1525
|
* @param options - Request options
|
|
852
1526
|
*/
|
|
853
1527
|
getDocument(id, options) {
|
|
854
|
-
return rxjs.lastValueFrom(
|
|
1528
|
+
return rxjs.lastValueFrom(
|
|
1529
|
+
dataMethods._getDocument(this.#clientConfig, this.#httpRequest, id, options)
|
|
1530
|
+
);
|
|
855
1531
|
}
|
|
856
1532
|
/**
|
|
857
1533
|
* Fetch multiple documents in one request.
|
|
@@ -863,7 +1539,9 @@ class SanityClient {
|
|
|
863
1539
|
* @param options - Request options
|
|
864
1540
|
*/
|
|
865
1541
|
getDocuments(ids, options) {
|
|
866
|
-
return rxjs.lastValueFrom(
|
|
1542
|
+
return rxjs.lastValueFrom(
|
|
1543
|
+
dataMethods._getDocuments(this.#clientConfig, this.#httpRequest, ids, options)
|
|
1544
|
+
);
|
|
867
1545
|
}
|
|
868
1546
|
create(document, options) {
|
|
869
1547
|
return rxjs.lastValueFrom(
|
|
@@ -880,11 +1558,122 @@ class SanityClient {
|
|
|
880
1558
|
dataMethods._createOrReplace(this.#clientConfig, this.#httpRequest, document, options)
|
|
881
1559
|
);
|
|
882
1560
|
}
|
|
1561
|
+
createVersion({
|
|
1562
|
+
document,
|
|
1563
|
+
publishedId,
|
|
1564
|
+
releaseId
|
|
1565
|
+
}, options) {
|
|
1566
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
1567
|
+
document,
|
|
1568
|
+
publishedId,
|
|
1569
|
+
releaseId
|
|
1570
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
|
|
1571
|
+
return rxjs.firstValueFrom(
|
|
1572
|
+
dataMethods._createVersion(
|
|
1573
|
+
this.config(),
|
|
1574
|
+
this.#httpRequest,
|
|
1575
|
+
documentVersion,
|
|
1576
|
+
versionPublishedId,
|
|
1577
|
+
options
|
|
1578
|
+
)
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
883
1581
|
delete(selection, options) {
|
|
884
|
-
return rxjs.lastValueFrom(
|
|
1582
|
+
return rxjs.lastValueFrom(
|
|
1583
|
+
dataMethods._delete(this.#clientConfig, this.#httpRequest, selection, options)
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* @public
|
|
1588
|
+
*
|
|
1589
|
+
* Deletes the draft or release version of a document.
|
|
1590
|
+
*
|
|
1591
|
+
* @remarks
|
|
1592
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1593
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1594
|
+
*
|
|
1595
|
+
* @param params - Version action parameters:
|
|
1596
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1597
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1598
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1599
|
+
* @param options - Additional action options.
|
|
1600
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1601
|
+
*
|
|
1602
|
+
* @example Discarding a release version of a document
|
|
1603
|
+
* ```ts
|
|
1604
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1605
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
1606
|
+
* ```
|
|
1607
|
+
*
|
|
1608
|
+
* @example Discarding a draft version of a document
|
|
1609
|
+
* ```ts
|
|
1610
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
1611
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
1612
|
+
* ```
|
|
1613
|
+
*/
|
|
1614
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
1615
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
1616
|
+
return rxjs.lastValueFrom(
|
|
1617
|
+
dataMethods._discardVersion(
|
|
1618
|
+
this.config(),
|
|
1619
|
+
this.#httpRequest,
|
|
1620
|
+
documentVersionId,
|
|
1621
|
+
purge,
|
|
1622
|
+
options
|
|
1623
|
+
)
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
replaceVersion({
|
|
1627
|
+
document,
|
|
1628
|
+
publishedId,
|
|
1629
|
+
releaseId
|
|
1630
|
+
}, options) {
|
|
1631
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
1632
|
+
document,
|
|
1633
|
+
publishedId,
|
|
1634
|
+
releaseId
|
|
1635
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
1636
|
+
return rxjs.firstValueFrom(
|
|
1637
|
+
dataMethods._replaceVersion(this.config(), this.#httpRequest, documentVersion, options)
|
|
1638
|
+
);
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* @public
|
|
1642
|
+
*
|
|
1643
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
1644
|
+
* the release is run.
|
|
1645
|
+
*
|
|
1646
|
+
* @remarks
|
|
1647
|
+
* * If the published document does not exist, an error will be thrown.
|
|
1648
|
+
*
|
|
1649
|
+
* @param params - Version action parameters:
|
|
1650
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
1651
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
1652
|
+
* @param options - Additional action options.
|
|
1653
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1654
|
+
*
|
|
1655
|
+
* @example Unpublishing a release version of a published document
|
|
1656
|
+
* ```ts
|
|
1657
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1658
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
1659
|
+
* ```
|
|
1660
|
+
*/
|
|
1661
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
1662
|
+
const versionId = csm.getVersionId(publishedId, releaseId);
|
|
1663
|
+
return rxjs.lastValueFrom(
|
|
1664
|
+
dataMethods._unpublishVersion(
|
|
1665
|
+
this.config(),
|
|
1666
|
+
this.#httpRequest,
|
|
1667
|
+
versionId,
|
|
1668
|
+
publishedId,
|
|
1669
|
+
options
|
|
1670
|
+
)
|
|
1671
|
+
);
|
|
885
1672
|
}
|
|
886
1673
|
mutate(operations, options) {
|
|
887
|
-
return rxjs.lastValueFrom(
|
|
1674
|
+
return rxjs.lastValueFrom(
|
|
1675
|
+
dataMethods._mutate(this.#clientConfig, this.#httpRequest, operations, options)
|
|
1676
|
+
);
|
|
888
1677
|
}
|
|
889
1678
|
/**
|
|
890
1679
|
* Create a new buildable patch of operations to perform
|
|
@@ -912,7 +1701,9 @@ class SanityClient {
|
|
|
912
1701
|
* @param options - Action options
|
|
913
1702
|
*/
|
|
914
1703
|
action(operations, options) {
|
|
915
|
-
return rxjs.lastValueFrom(
|
|
1704
|
+
return rxjs.lastValueFrom(
|
|
1705
|
+
dataMethods._action(this.#clientConfig, this.#httpRequest, operations, options)
|
|
1706
|
+
);
|
|
916
1707
|
}
|
|
917
1708
|
/**
|
|
918
1709
|
* Perform a request against the Sanity API
|
|
@@ -935,7 +1726,9 @@ class SanityClient {
|
|
|
935
1726
|
* @internal
|
|
936
1727
|
*/
|
|
937
1728
|
dataRequest(endpoint, body, options) {
|
|
938
|
-
return rxjs.lastValueFrom(
|
|
1729
|
+
return rxjs.lastValueFrom(
|
|
1730
|
+
dataMethods._dataRequest(this.#clientConfig, this.#httpRequest, endpoint, body, options)
|
|
1731
|
+
);
|
|
939
1732
|
}
|
|
940
1733
|
/**
|
|
941
1734
|
* Get a Sanity API URL for the URI provided
|
|
@@ -975,7 +1768,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
975
1768
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
976
1769
|
};
|
|
977
1770
|
}
|
|
978
|
-
var name = "@sanity/client", version = "7.1.0-views.
|
|
1771
|
+
var name = "@sanity/client", version = "7.1.0-views.1";
|
|
979
1772
|
const middleware = [
|
|
980
1773
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
981
1774
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|
|
@@ -1002,6 +1795,8 @@ exports.ObservableTransaction = dataMethods.ObservableTransaction;
|
|
|
1002
1795
|
exports.Patch = dataMethods.Patch;
|
|
1003
1796
|
exports.ServerError = dataMethods.ServerError;
|
|
1004
1797
|
exports.Transaction = dataMethods.Transaction;
|
|
1798
|
+
exports.formatQueryParseError = dataMethods.formatQueryParseError;
|
|
1799
|
+
exports.isQueryParseError = dataMethods.isQueryParseError;
|
|
1005
1800
|
exports.validateApiPerspective = config.validateApiPerspective;
|
|
1006
1801
|
Object.defineProperty(exports, "unstable__adapter", {
|
|
1007
1802
|
enumerable: !0,
|
|
@@ -1022,6 +1817,7 @@ exports.MessageError = MessageError;
|
|
|
1022
1817
|
exports.MessageParseError = MessageParseError;
|
|
1023
1818
|
exports.ObservableSanityClient = ObservableSanityClient;
|
|
1024
1819
|
exports.SanityClient = SanityClient;
|
|
1820
|
+
exports.ViewResourceType = ViewResourceType;
|
|
1025
1821
|
exports.connectEventSource = connectEventSource;
|
|
1026
1822
|
exports.createClient = createClient;
|
|
1027
1823
|
exports.default = deprecatedCreateClient;
|