@sanity/client 7.1.0 → 7.2.1-agent-actions.0
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 +516 -40
- package/dist/_chunks-cjs/config.cjs +14 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +15 -1
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +765 -5
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1483 -32
- package/dist/index.browser.d.ts +1483 -32
- package/dist/index.browser.js +767 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +754 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1483 -32
- package/dist/index.d.ts +1483 -32
- package/dist/index.js +757 -7
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1483 -32
- package/dist/stega.browser.d.ts +1483 -32
- package/dist/stega.d.cts +1483 -32
- package/dist/stega.d.ts +1483 -32
- package/package.json +3 -1
- package/src/SanityClient.ts +592 -4
- package/src/agent/actions/AgentActionsClient.ts +11 -0
- package/src/agent/actions/commonTypes.ts +26 -16
- package/src/agent/actions/prompt.ts +150 -0
- package/src/data/dataMethods.ts +126 -2
- package/src/releases/ReleasesClient.ts +687 -0
- package/src/releases/createRelease.ts +53 -0
- package/src/types.ts +216 -0
- package/src/util/createVersionId.ts +79 -0
- package/src/validators.ts +23 -1
- package/umd/sanityClient.js +829 -4
- package/umd/sanityClient.min.js +2 -2
package/umd/sanityClient.js
CHANGED
|
@@ -1495,6 +1495,24 @@
|
|
|
1495
1495
|
});
|
|
1496
1496
|
}
|
|
1497
1497
|
|
|
1498
|
+
function firstValueFrom(source, config) {
|
|
1499
|
+
return new Promise(function (resolve, reject) {
|
|
1500
|
+
var subscriber = new SafeSubscriber({
|
|
1501
|
+
next: function (value) {
|
|
1502
|
+
resolve(value);
|
|
1503
|
+
subscriber.unsubscribe();
|
|
1504
|
+
},
|
|
1505
|
+
error: reject,
|
|
1506
|
+
complete: function () {
|
|
1507
|
+
{
|
|
1508
|
+
reject(new EmptyError());
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
});
|
|
1512
|
+
source.subscribe(subscriber);
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1498
1516
|
function isValidDate$1(value) {
|
|
1499
1517
|
return value instanceof Date && !isNaN(value);
|
|
1500
1518
|
}
|
|
@@ -1912,6 +1930,53 @@
|
|
|
1912
1930
|
return O(result);
|
|
1913
1931
|
}
|
|
1914
1932
|
|
|
1933
|
+
const DRAFTS_FOLDER$1 = "drafts", VERSION_FOLDER$1 = "versions", PATH_SEPARATOR$1 = ".", DRAFTS_PREFIX$1 = `${DRAFTS_FOLDER$1}${PATH_SEPARATOR$1}`, VERSION_PREFIX$1 = `${VERSION_FOLDER$1}${PATH_SEPARATOR$1}`;
|
|
1934
|
+
function isDraftId$1(id) {
|
|
1935
|
+
return id.startsWith(DRAFTS_PREFIX$1);
|
|
1936
|
+
}
|
|
1937
|
+
function isVersionId$1(id) {
|
|
1938
|
+
return id.startsWith(VERSION_PREFIX$1);
|
|
1939
|
+
}
|
|
1940
|
+
function getDraftId(id) {
|
|
1941
|
+
if (isVersionId$1(id)) {
|
|
1942
|
+
const publishedId = getPublishedId$1(id);
|
|
1943
|
+
return DRAFTS_PREFIX$1 + publishedId;
|
|
1944
|
+
}
|
|
1945
|
+
return isDraftId$1(id) ? id : DRAFTS_PREFIX$1 + id;
|
|
1946
|
+
}
|
|
1947
|
+
function getVersionId(id, version) {
|
|
1948
|
+
if (version === "drafts" || version === "published")
|
|
1949
|
+
throw new Error('Version can not be "published" or "drafts"');
|
|
1950
|
+
return `${VERSION_PREFIX$1}${version}${PATH_SEPARATOR$1}${getPublishedId$1(id)}`;
|
|
1951
|
+
}
|
|
1952
|
+
function getVersionFromId$1(id) {
|
|
1953
|
+
if (!isVersionId$1(id)) return;
|
|
1954
|
+
const [_versionPrefix, versionId, ..._publishedId] = id.split(PATH_SEPARATOR$1);
|
|
1955
|
+
return versionId;
|
|
1956
|
+
}
|
|
1957
|
+
function getPublishedId$1(id) {
|
|
1958
|
+
return isVersionId$1(id) ? id.split(PATH_SEPARATOR$1).slice(2).join(PATH_SEPARATOR$1) : isDraftId$1(id) ? id.slice(DRAFTS_PREFIX$1.length) : id;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes));
|
|
1962
|
+
let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
1963
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1;
|
|
1964
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length);
|
|
1965
|
+
return (size = defaultSize) => {
|
|
1966
|
+
let id = '';
|
|
1967
|
+
while (true) {
|
|
1968
|
+
let bytes = getRandom(step);
|
|
1969
|
+
let j = step | 0;
|
|
1970
|
+
while (j--) {
|
|
1971
|
+
id += alphabet[bytes[j] & mask] || '';
|
|
1972
|
+
if (id.length === size) return id
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
let customAlphabet = (alphabet, size = 21) =>
|
|
1978
|
+
customRandom(alphabet, size, random);
|
|
1979
|
+
|
|
1915
1980
|
class ClientError extends Error {
|
|
1916
1981
|
response;
|
|
1917
1982
|
statusCode = 400;
|
|
@@ -2043,6 +2108,18 @@
|
|
|
2043
2108
|
if (!doc._id)
|
|
2044
2109
|
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
2045
2110
|
validateDocumentId(op, doc._id);
|
|
2111
|
+
}, validateDocumentType = (op, type) => {
|
|
2112
|
+
if (typeof type != "string")
|
|
2113
|
+
throw new Error(`\`${op}()\`: \`${type}\` is not a valid document type`);
|
|
2114
|
+
}, requireDocumentType = (op, doc) => {
|
|
2115
|
+
if (!doc._type)
|
|
2116
|
+
throw new Error(`\`${op}()\` requires that the document contains a type (\`_type\` property)`);
|
|
2117
|
+
validateDocumentType(op, doc._type);
|
|
2118
|
+
}, validateVersionIdMatch = (builtVersionId, document) => {
|
|
2119
|
+
if (document._id && document._id !== builtVersionId)
|
|
2120
|
+
throw new Error(
|
|
2121
|
+
`The provided document ID (\`${document._id}\`) does not match the generated version ID (\`${builtVersionId}\`)`
|
|
2122
|
+
);
|
|
2046
2123
|
}, validateInsert = (at, selector, items) => {
|
|
2047
2124
|
const signature = "insert(at, selector, items)";
|
|
2048
2125
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
@@ -2684,8 +2761,24 @@ ${selectionOpts}`);
|
|
|
2684
2761
|
) : $request.pipe(map(mapResponse));
|
|
2685
2762
|
}
|
|
2686
2763
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2764
|
+
const docId = (() => {
|
|
2765
|
+
if (!opts.releaseId)
|
|
2766
|
+
return id;
|
|
2767
|
+
const versionId = getVersionFromId$1(id);
|
|
2768
|
+
if (!versionId) {
|
|
2769
|
+
if (isDraftId$1(id))
|
|
2770
|
+
throw new Error(
|
|
2771
|
+
`The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
|
|
2772
|
+
);
|
|
2773
|
+
return getVersionId(id, opts.releaseId);
|
|
2774
|
+
}
|
|
2775
|
+
if (versionId !== opts.releaseId)
|
|
2776
|
+
throw new Error(
|
|
2777
|
+
`The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
|
|
2778
|
+
);
|
|
2779
|
+
return id;
|
|
2780
|
+
})(), options = {
|
|
2781
|
+
uri: _getDataUrl(client, "doc", docId),
|
|
2689
2782
|
json: true,
|
|
2690
2783
|
tag: opts.tag,
|
|
2691
2784
|
signal: opts.signal
|
|
@@ -2710,12 +2803,33 @@ ${selectionOpts}`);
|
|
|
2710
2803
|
})
|
|
2711
2804
|
);
|
|
2712
2805
|
}
|
|
2806
|
+
function _getReleaseDocuments(client, httpRequest, releaseId, opts = {}) {
|
|
2807
|
+
return _dataRequest(
|
|
2808
|
+
client,
|
|
2809
|
+
httpRequest,
|
|
2810
|
+
"query",
|
|
2811
|
+
{
|
|
2812
|
+
query: "*[sanity::partOfRelease($releaseId)]",
|
|
2813
|
+
params: {
|
|
2814
|
+
releaseId
|
|
2815
|
+
}
|
|
2816
|
+
},
|
|
2817
|
+
opts
|
|
2818
|
+
);
|
|
2819
|
+
}
|
|
2713
2820
|
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
2714
2821
|
return requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
2715
2822
|
}
|
|
2716
2823
|
function _createOrReplace(client, httpRequest, doc, options) {
|
|
2717
2824
|
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
2718
2825
|
}
|
|
2826
|
+
function _createVersion(client, httpRequest, doc, publishedId, options) {
|
|
2827
|
+
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(client, httpRequest, {
|
|
2828
|
+
actionType: "sanity.action.document.version.create",
|
|
2829
|
+
publishedId,
|
|
2830
|
+
document: doc
|
|
2831
|
+
}, options);
|
|
2832
|
+
}
|
|
2719
2833
|
function _delete(client, httpRequest, selection, options) {
|
|
2720
2834
|
return _dataRequest(
|
|
2721
2835
|
client,
|
|
@@ -2725,6 +2839,26 @@ ${selectionOpts}`);
|
|
|
2725
2839
|
options
|
|
2726
2840
|
);
|
|
2727
2841
|
}
|
|
2842
|
+
function _discardVersion(client, httpRequest, versionId, purge = false, options) {
|
|
2843
|
+
return _action(client, httpRequest, {
|
|
2844
|
+
actionType: "sanity.action.document.version.discard",
|
|
2845
|
+
versionId,
|
|
2846
|
+
purge
|
|
2847
|
+
}, options);
|
|
2848
|
+
}
|
|
2849
|
+
function _replaceVersion(client, httpRequest, doc, options) {
|
|
2850
|
+
return requireDocumentId("replaceVersion", doc), requireDocumentType("replaceVersion", doc), _action(client, httpRequest, {
|
|
2851
|
+
actionType: "sanity.action.document.version.replace",
|
|
2852
|
+
document: doc
|
|
2853
|
+
}, options);
|
|
2854
|
+
}
|
|
2855
|
+
function _unpublishVersion(client, httpRequest, versionId, publishedId, options) {
|
|
2856
|
+
return _action(client, httpRequest, {
|
|
2857
|
+
actionType: "sanity.action.document.version.unpublish",
|
|
2858
|
+
versionId,
|
|
2859
|
+
publishedId
|
|
2860
|
+
}, options);
|
|
2861
|
+
}
|
|
2728
2862
|
function _mutate(client, httpRequest, mutations, options) {
|
|
2729
2863
|
let mut;
|
|
2730
2864
|
mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
|
|
@@ -2879,6 +3013,14 @@ ${selectionOpts}`);
|
|
|
2879
3013
|
body: request
|
|
2880
3014
|
});
|
|
2881
3015
|
}
|
|
3016
|
+
function _prompt(client, httpRequest, request) {
|
|
3017
|
+
const dataset2 = hasDataset(client.config());
|
|
3018
|
+
return _request(client, httpRequest, {
|
|
3019
|
+
method: "POST",
|
|
3020
|
+
uri: `/agent/action/prompt/${dataset2}`,
|
|
3021
|
+
body: request
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
2882
3024
|
function _transform(client, httpRequest, request) {
|
|
2883
3025
|
const dataset2 = hasDataset(client.config());
|
|
2884
3026
|
return _request(client, httpRequest, {
|
|
@@ -2950,6 +3092,13 @@ ${selectionOpts}`);
|
|
|
2950
3092
|
translate(request) {
|
|
2951
3093
|
return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
2952
3094
|
}
|
|
3095
|
+
/**
|
|
3096
|
+
* Run a raw instruction and return the result either as text or json
|
|
3097
|
+
* @param request - prompt request
|
|
3098
|
+
*/
|
|
3099
|
+
prompt(request) {
|
|
3100
|
+
return lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
|
|
3101
|
+
}
|
|
2953
3102
|
}
|
|
2954
3103
|
class ObservableAssetsClient {
|
|
2955
3104
|
#client;
|
|
@@ -3327,6 +3476,498 @@ ${selectionOpts}`);
|
|
|
3327
3476
|
);
|
|
3328
3477
|
}
|
|
3329
3478
|
}
|
|
3479
|
+
const generateReleaseId = customAlphabet(
|
|
3480
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
3481
|
+
8
|
|
3482
|
+
), getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
|
|
3483
|
+
function deriveDocumentVersionId(op, {
|
|
3484
|
+
releaseId,
|
|
3485
|
+
publishedId,
|
|
3486
|
+
document
|
|
3487
|
+
}) {
|
|
3488
|
+
if (publishedId && document._id) {
|
|
3489
|
+
const versionId = getDocumentVersionId(publishedId, releaseId);
|
|
3490
|
+
return validateVersionIdMatch(versionId, document), versionId;
|
|
3491
|
+
}
|
|
3492
|
+
if (document._id) {
|
|
3493
|
+
const isDraft = isDraftId$1(document._id), isVersion = isVersionId$1(document._id);
|
|
3494
|
+
if (!isDraft && !isVersion)
|
|
3495
|
+
throw new Error(
|
|
3496
|
+
`\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
|
|
3497
|
+
);
|
|
3498
|
+
if (releaseId) {
|
|
3499
|
+
if (isDraft)
|
|
3500
|
+
throw new Error(
|
|
3501
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
|
|
3502
|
+
);
|
|
3503
|
+
const builtVersionId = getVersionFromId$1(document._id);
|
|
3504
|
+
if (builtVersionId !== releaseId)
|
|
3505
|
+
throw new Error(
|
|
3506
|
+
`\`${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}\`).`
|
|
3507
|
+
);
|
|
3508
|
+
}
|
|
3509
|
+
return document._id;
|
|
3510
|
+
}
|
|
3511
|
+
if (publishedId)
|
|
3512
|
+
return getDocumentVersionId(publishedId, releaseId);
|
|
3513
|
+
throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
|
|
3514
|
+
}
|
|
3515
|
+
const getArgs = (releaseOrOptions, maybeOptions) => {
|
|
3516
|
+
if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
|
|
3517
|
+
const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
|
|
3518
|
+
return [releaseId, metadata, maybeOptions];
|
|
3519
|
+
}
|
|
3520
|
+
return [generateReleaseId(), {}, releaseOrOptions];
|
|
3521
|
+
}, createRelease = (releaseOrOptions, maybeOptions) => {
|
|
3522
|
+
const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
|
|
3523
|
+
...metadata,
|
|
3524
|
+
releaseType: metadata.releaseType || "undecided"
|
|
3525
|
+
};
|
|
3526
|
+
return { action: {
|
|
3527
|
+
actionType: "sanity.action.release.create",
|
|
3528
|
+
releaseId,
|
|
3529
|
+
metadata: finalMetadata
|
|
3530
|
+
}, options };
|
|
3531
|
+
};
|
|
3532
|
+
class ObservableReleasesClient {
|
|
3533
|
+
#client;
|
|
3534
|
+
#httpRequest;
|
|
3535
|
+
constructor(client, httpRequest) {
|
|
3536
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
3537
|
+
}
|
|
3538
|
+
/**
|
|
3539
|
+
* @public
|
|
3540
|
+
*
|
|
3541
|
+
* Retrieve a release by id.
|
|
3542
|
+
*
|
|
3543
|
+
* @category Releases
|
|
3544
|
+
*
|
|
3545
|
+
* @param params - Release action parameters:
|
|
3546
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
3547
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
3548
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
3549
|
+
*
|
|
3550
|
+
* @example Retrieving a release by id
|
|
3551
|
+
* ```ts
|
|
3552
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
3553
|
+
* tap((release) => console.log(release)),
|
|
3554
|
+
* // {
|
|
3555
|
+
* // _id: '_.releases.my-release',
|
|
3556
|
+
* // name: 'my-release'
|
|
3557
|
+
* // _type: 'system.release',
|
|
3558
|
+
* // metadata: {releaseType: 'asap'},
|
|
3559
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
3560
|
+
* // ...
|
|
3561
|
+
* // }
|
|
3562
|
+
* ).subscribe()
|
|
3563
|
+
* ```
|
|
3564
|
+
*/
|
|
3565
|
+
get({ releaseId }, options) {
|
|
3566
|
+
return _getDocument(
|
|
3567
|
+
this.#client,
|
|
3568
|
+
this.#httpRequest,
|
|
3569
|
+
`_.releases.${releaseId}`,
|
|
3570
|
+
options
|
|
3571
|
+
);
|
|
3572
|
+
}
|
|
3573
|
+
create(releaseOrOptions, maybeOptions) {
|
|
3574
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
3575
|
+
return _action(this.#client, this.#httpRequest, action, options).pipe(
|
|
3576
|
+
map((actionResult) => ({
|
|
3577
|
+
...actionResult,
|
|
3578
|
+
releaseId,
|
|
3579
|
+
metadata
|
|
3580
|
+
}))
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3583
|
+
/**
|
|
3584
|
+
* @public
|
|
3585
|
+
*
|
|
3586
|
+
* Edits an existing release, updating the metadata.
|
|
3587
|
+
*
|
|
3588
|
+
* @category Releases
|
|
3589
|
+
*
|
|
3590
|
+
* @param params - Release action parameters:
|
|
3591
|
+
* - `releaseId` - The id of the release to edit.
|
|
3592
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
3593
|
+
* @param options - Additional action options.
|
|
3594
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3595
|
+
*/
|
|
3596
|
+
edit({ releaseId, patch }, options) {
|
|
3597
|
+
const editAction = {
|
|
3598
|
+
actionType: "sanity.action.release.edit",
|
|
3599
|
+
releaseId,
|
|
3600
|
+
patch
|
|
3601
|
+
};
|
|
3602
|
+
return _action(this.#client, this.#httpRequest, editAction, options);
|
|
3603
|
+
}
|
|
3604
|
+
/**
|
|
3605
|
+
* @public
|
|
3606
|
+
*
|
|
3607
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
3608
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
3609
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
3610
|
+
* take some time.
|
|
3611
|
+
*
|
|
3612
|
+
* During this period both the source and target documents are locked and cannot be
|
|
3613
|
+
* modified through any other means.
|
|
3614
|
+
*
|
|
3615
|
+
* @category Releases
|
|
3616
|
+
*
|
|
3617
|
+
* @param params - Release action parameters:
|
|
3618
|
+
* - `releaseId` - The id of the release to publish.
|
|
3619
|
+
* @param options - Additional action options.
|
|
3620
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3621
|
+
*/
|
|
3622
|
+
publish({ releaseId }, options) {
|
|
3623
|
+
const publishAction = {
|
|
3624
|
+
actionType: "sanity.action.release.publish",
|
|
3625
|
+
releaseId
|
|
3626
|
+
};
|
|
3627
|
+
return _action(this.#client, this.#httpRequest, publishAction, options);
|
|
3628
|
+
}
|
|
3629
|
+
/**
|
|
3630
|
+
* @public
|
|
3631
|
+
*
|
|
3632
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
3633
|
+
* are deleted and therefore no longer queryable.
|
|
3634
|
+
*
|
|
3635
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
3636
|
+
*
|
|
3637
|
+
* @category Releases
|
|
3638
|
+
*
|
|
3639
|
+
* @param params - Release action parameters:
|
|
3640
|
+
* - `releaseId` - The id of the release to archive.
|
|
3641
|
+
* @param options - Additional action options.
|
|
3642
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3643
|
+
*/
|
|
3644
|
+
archive({ releaseId }, options) {
|
|
3645
|
+
const archiveAction = {
|
|
3646
|
+
actionType: "sanity.action.release.archive",
|
|
3647
|
+
releaseId
|
|
3648
|
+
};
|
|
3649
|
+
return _action(this.#client, this.#httpRequest, archiveAction, options);
|
|
3650
|
+
}
|
|
3651
|
+
/**
|
|
3652
|
+
* @public
|
|
3653
|
+
*
|
|
3654
|
+
* An unarchive action restores an archived release and all documents
|
|
3655
|
+
* with the content they had just prior to archiving.
|
|
3656
|
+
*
|
|
3657
|
+
* @category Releases
|
|
3658
|
+
*
|
|
3659
|
+
* @param params - Release action parameters:
|
|
3660
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
3661
|
+
* @param options - Additional action options.
|
|
3662
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3663
|
+
*/
|
|
3664
|
+
unarchive({ releaseId }, options) {
|
|
3665
|
+
const unarchiveAction = {
|
|
3666
|
+
actionType: "sanity.action.release.unarchive",
|
|
3667
|
+
releaseId
|
|
3668
|
+
};
|
|
3669
|
+
return _action(this.#client, this.#httpRequest, unarchiveAction, options);
|
|
3670
|
+
}
|
|
3671
|
+
/**
|
|
3672
|
+
* @public
|
|
3673
|
+
*
|
|
3674
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
3675
|
+
* The release is locked such that no documents in the release can be modified and
|
|
3676
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
3677
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
3678
|
+
*
|
|
3679
|
+
* @category Releases
|
|
3680
|
+
*
|
|
3681
|
+
* @param params - Release action parameters:
|
|
3682
|
+
* - `releaseId` - The id of the release to schedule.
|
|
3683
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
3684
|
+
* @param options - Additional action options.
|
|
3685
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3686
|
+
*/
|
|
3687
|
+
schedule({ releaseId, publishAt }, options) {
|
|
3688
|
+
const scheduleAction = {
|
|
3689
|
+
actionType: "sanity.action.release.schedule",
|
|
3690
|
+
releaseId,
|
|
3691
|
+
publishAt
|
|
3692
|
+
};
|
|
3693
|
+
return _action(this.#client, this.#httpRequest, scheduleAction, options);
|
|
3694
|
+
}
|
|
3695
|
+
/**
|
|
3696
|
+
* @public
|
|
3697
|
+
*
|
|
3698
|
+
* An unschedule action stops a release from being published.
|
|
3699
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
3700
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
3701
|
+
* has a reference to a document created by this one.
|
|
3702
|
+
*
|
|
3703
|
+
* @category Releases
|
|
3704
|
+
*
|
|
3705
|
+
* @param params - Release action parameters:
|
|
3706
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
3707
|
+
* @param options - Additional action options.
|
|
3708
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3709
|
+
*/
|
|
3710
|
+
unschedule({ releaseId }, options) {
|
|
3711
|
+
const unscheduleAction = {
|
|
3712
|
+
actionType: "sanity.action.release.unschedule",
|
|
3713
|
+
releaseId
|
|
3714
|
+
};
|
|
3715
|
+
return _action(this.#client, this.#httpRequest, unscheduleAction, options);
|
|
3716
|
+
}
|
|
3717
|
+
/**
|
|
3718
|
+
* @public
|
|
3719
|
+
*
|
|
3720
|
+
* A delete action removes a published or archived release.
|
|
3721
|
+
* The backing system document will be removed from the dataset.
|
|
3722
|
+
*
|
|
3723
|
+
* @category Releases
|
|
3724
|
+
*
|
|
3725
|
+
* @param params - Release action parameters:
|
|
3726
|
+
* - `releaseId` - The id of the release to delete.
|
|
3727
|
+
* @param options - Additional action options.
|
|
3728
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
3729
|
+
*/
|
|
3730
|
+
delete({ releaseId }, options) {
|
|
3731
|
+
const deleteAction = {
|
|
3732
|
+
actionType: "sanity.action.release.delete",
|
|
3733
|
+
releaseId
|
|
3734
|
+
};
|
|
3735
|
+
return _action(this.#client, this.#httpRequest, deleteAction, options);
|
|
3736
|
+
}
|
|
3737
|
+
/**
|
|
3738
|
+
* @public
|
|
3739
|
+
*
|
|
3740
|
+
* Fetch the documents in a release by release id.
|
|
3741
|
+
*
|
|
3742
|
+
* @category Releases
|
|
3743
|
+
*
|
|
3744
|
+
* @param params - Release action parameters:
|
|
3745
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
3746
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
3747
|
+
* @returns An observable that resolves to the documents in the release.
|
|
3748
|
+
*/
|
|
3749
|
+
fetchDocuments({ releaseId }, options) {
|
|
3750
|
+
return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
class ReleasesClient {
|
|
3754
|
+
#client;
|
|
3755
|
+
#httpRequest;
|
|
3756
|
+
constructor(client, httpRequest) {
|
|
3757
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
3758
|
+
}
|
|
3759
|
+
/**
|
|
3760
|
+
* @public
|
|
3761
|
+
*
|
|
3762
|
+
* Retrieve a release by id.
|
|
3763
|
+
*
|
|
3764
|
+
* @category Releases
|
|
3765
|
+
*
|
|
3766
|
+
* @param params - Release action parameters:
|
|
3767
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
3768
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
3769
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
3770
|
+
*
|
|
3771
|
+
* @example Retrieving a release by id
|
|
3772
|
+
* ```ts
|
|
3773
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
3774
|
+
* console.log(release)
|
|
3775
|
+
* // {
|
|
3776
|
+
* // _id: '_.releases.my-release',
|
|
3777
|
+
* // name: 'my-release'
|
|
3778
|
+
* // _type: 'system.release',
|
|
3779
|
+
* // metadata: {releaseType: 'asap'},
|
|
3780
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
3781
|
+
* // ...
|
|
3782
|
+
* // }
|
|
3783
|
+
* ```
|
|
3784
|
+
*/
|
|
3785
|
+
get({ releaseId }, options) {
|
|
3786
|
+
return lastValueFrom(
|
|
3787
|
+
_getDocument(
|
|
3788
|
+
this.#client,
|
|
3789
|
+
this.#httpRequest,
|
|
3790
|
+
`_.releases.${releaseId}`,
|
|
3791
|
+
options
|
|
3792
|
+
)
|
|
3793
|
+
);
|
|
3794
|
+
}
|
|
3795
|
+
async create(releaseOrOptions, maybeOptions) {
|
|
3796
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
3797
|
+
return { ...await lastValueFrom(
|
|
3798
|
+
_action(this.#client, this.#httpRequest, action, options)
|
|
3799
|
+
), releaseId, metadata };
|
|
3800
|
+
}
|
|
3801
|
+
/**
|
|
3802
|
+
* @public
|
|
3803
|
+
*
|
|
3804
|
+
* Edits an existing release, updating the metadata.
|
|
3805
|
+
*
|
|
3806
|
+
* @category Releases
|
|
3807
|
+
*
|
|
3808
|
+
* @param params - Release action parameters:
|
|
3809
|
+
* - `releaseId` - The id of the release to edit.
|
|
3810
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
3811
|
+
* @param options - Additional action options.
|
|
3812
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3813
|
+
*/
|
|
3814
|
+
edit({ releaseId, patch }, options) {
|
|
3815
|
+
const editAction = {
|
|
3816
|
+
actionType: "sanity.action.release.edit",
|
|
3817
|
+
releaseId,
|
|
3818
|
+
patch
|
|
3819
|
+
};
|
|
3820
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, editAction, options));
|
|
3821
|
+
}
|
|
3822
|
+
/**
|
|
3823
|
+
* @public
|
|
3824
|
+
*
|
|
3825
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
3826
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
3827
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
3828
|
+
* take some time.
|
|
3829
|
+
*
|
|
3830
|
+
* During this period both the source and target documents are locked and cannot be
|
|
3831
|
+
* modified through any other means.
|
|
3832
|
+
*
|
|
3833
|
+
* @category Releases
|
|
3834
|
+
*
|
|
3835
|
+
* @param params - Release action parameters:
|
|
3836
|
+
* - `releaseId` - The id of the release to publish.
|
|
3837
|
+
* @param options - Additional action options.
|
|
3838
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3839
|
+
*/
|
|
3840
|
+
publish({ releaseId }, options) {
|
|
3841
|
+
const publishAction = {
|
|
3842
|
+
actionType: "sanity.action.release.publish",
|
|
3843
|
+
releaseId
|
|
3844
|
+
};
|
|
3845
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, publishAction, options));
|
|
3846
|
+
}
|
|
3847
|
+
/**
|
|
3848
|
+
* @public
|
|
3849
|
+
*
|
|
3850
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
3851
|
+
* are deleted and therefore no longer queryable.
|
|
3852
|
+
*
|
|
3853
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
3854
|
+
*
|
|
3855
|
+
* @category Releases
|
|
3856
|
+
*
|
|
3857
|
+
* @param params - Release action parameters:
|
|
3858
|
+
* - `releaseId` - The id of the release to archive.
|
|
3859
|
+
* @param options - Additional action options.
|
|
3860
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3861
|
+
*/
|
|
3862
|
+
archive({ releaseId }, options) {
|
|
3863
|
+
const archiveAction = {
|
|
3864
|
+
actionType: "sanity.action.release.archive",
|
|
3865
|
+
releaseId
|
|
3866
|
+
};
|
|
3867
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, archiveAction, options));
|
|
3868
|
+
}
|
|
3869
|
+
/**
|
|
3870
|
+
* @public
|
|
3871
|
+
*
|
|
3872
|
+
* An unarchive action restores an archived release and all documents
|
|
3873
|
+
* with the content they had just prior to archiving.
|
|
3874
|
+
*
|
|
3875
|
+
* @category Releases
|
|
3876
|
+
*
|
|
3877
|
+
* @param params - Release action parameters:
|
|
3878
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
3879
|
+
* @param options - Additional action options.
|
|
3880
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3881
|
+
*/
|
|
3882
|
+
unarchive({ releaseId }, options) {
|
|
3883
|
+
const unarchiveAction = {
|
|
3884
|
+
actionType: "sanity.action.release.unarchive",
|
|
3885
|
+
releaseId
|
|
3886
|
+
};
|
|
3887
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, unarchiveAction, options));
|
|
3888
|
+
}
|
|
3889
|
+
/**
|
|
3890
|
+
* @public
|
|
3891
|
+
*
|
|
3892
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
3893
|
+
* The release is locked such that no documents in the release can be modified and
|
|
3894
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
3895
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
3896
|
+
*
|
|
3897
|
+
* @category Releases
|
|
3898
|
+
*
|
|
3899
|
+
* @param params - Release action parameters:
|
|
3900
|
+
* - `releaseId` - The id of the release to schedule.
|
|
3901
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
3902
|
+
* @param options - Additional action options.
|
|
3903
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3904
|
+
*/
|
|
3905
|
+
schedule({ releaseId, publishAt }, options) {
|
|
3906
|
+
const scheduleAction = {
|
|
3907
|
+
actionType: "sanity.action.release.schedule",
|
|
3908
|
+
releaseId,
|
|
3909
|
+
publishAt
|
|
3910
|
+
};
|
|
3911
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, scheduleAction, options));
|
|
3912
|
+
}
|
|
3913
|
+
/**
|
|
3914
|
+
* @public
|
|
3915
|
+
*
|
|
3916
|
+
* An unschedule action stops a release from being published.
|
|
3917
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
3918
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
3919
|
+
* has a reference to a document created by this one.
|
|
3920
|
+
*
|
|
3921
|
+
* @category Releases
|
|
3922
|
+
*
|
|
3923
|
+
* @param params - Release action parameters:
|
|
3924
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
3925
|
+
* @param options - Additional action options.
|
|
3926
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3927
|
+
*/
|
|
3928
|
+
unschedule({ releaseId }, options) {
|
|
3929
|
+
const unscheduleAction = {
|
|
3930
|
+
actionType: "sanity.action.release.unschedule",
|
|
3931
|
+
releaseId
|
|
3932
|
+
};
|
|
3933
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, unscheduleAction, options));
|
|
3934
|
+
}
|
|
3935
|
+
/**
|
|
3936
|
+
* @public
|
|
3937
|
+
*
|
|
3938
|
+
* A delete action removes a published or archived release.
|
|
3939
|
+
* The backing system document will be removed from the dataset.
|
|
3940
|
+
*
|
|
3941
|
+
* @category Releases
|
|
3942
|
+
*
|
|
3943
|
+
* @param params - Release action parameters:
|
|
3944
|
+
* - `releaseId` - The id of the release to delete.
|
|
3945
|
+
* @param options - Additional action options.
|
|
3946
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
3947
|
+
*/
|
|
3948
|
+
delete({ releaseId }, options) {
|
|
3949
|
+
const deleteAction = {
|
|
3950
|
+
actionType: "sanity.action.release.delete",
|
|
3951
|
+
releaseId
|
|
3952
|
+
};
|
|
3953
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, deleteAction, options));
|
|
3954
|
+
}
|
|
3955
|
+
/**
|
|
3956
|
+
* @public
|
|
3957
|
+
*
|
|
3958
|
+
* Fetch the documents in a release by release id.
|
|
3959
|
+
*
|
|
3960
|
+
* @category Releases
|
|
3961
|
+
*
|
|
3962
|
+
* @param params - Release action parameters:
|
|
3963
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
3964
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
3965
|
+
* @returns A promise that resolves to the documents in the release.
|
|
3966
|
+
*/
|
|
3967
|
+
fetchDocuments({ releaseId }, options) {
|
|
3968
|
+
return lastValueFrom(_getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options));
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3330
3971
|
class ObservableUsersClient {
|
|
3331
3972
|
#client;
|
|
3332
3973
|
#httpRequest;
|
|
@@ -3372,6 +4013,7 @@ ${selectionOpts}`);
|
|
|
3372
4013
|
projects;
|
|
3373
4014
|
users;
|
|
3374
4015
|
agent;
|
|
4016
|
+
releases;
|
|
3375
4017
|
/**
|
|
3376
4018
|
* Private properties
|
|
3377
4019
|
*/
|
|
@@ -3384,7 +4026,7 @@ ${selectionOpts}`);
|
|
|
3384
4026
|
constructor(httpRequest, config = defaultConfig) {
|
|
3385
4027
|
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 = {
|
|
3386
4028
|
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
3387
|
-
};
|
|
4029
|
+
}, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
3388
4030
|
}
|
|
3389
4031
|
/**
|
|
3390
4032
|
* Clone the client - returns a new instance
|
|
@@ -3457,9 +4099,96 @@ ${selectionOpts}`);
|
|
|
3457
4099
|
createOrReplace(document, options) {
|
|
3458
4100
|
return _createOrReplace(this, this.#httpRequest, document, options);
|
|
3459
4101
|
}
|
|
4102
|
+
createVersion({
|
|
4103
|
+
document,
|
|
4104
|
+
publishedId,
|
|
4105
|
+
releaseId
|
|
4106
|
+
}, options) {
|
|
4107
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
4108
|
+
document,
|
|
4109
|
+
publishedId,
|
|
4110
|
+
releaseId
|
|
4111
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId$1(document._id);
|
|
4112
|
+
return _createVersion(
|
|
4113
|
+
this,
|
|
4114
|
+
this.#httpRequest,
|
|
4115
|
+
documentVersion,
|
|
4116
|
+
versionPublishedId,
|
|
4117
|
+
options
|
|
4118
|
+
);
|
|
4119
|
+
}
|
|
3460
4120
|
delete(selection, options) {
|
|
3461
4121
|
return _delete(this, this.#httpRequest, selection, options);
|
|
3462
4122
|
}
|
|
4123
|
+
/**
|
|
4124
|
+
* @public
|
|
4125
|
+
*
|
|
4126
|
+
* Deletes the draft or release version of a document.
|
|
4127
|
+
*
|
|
4128
|
+
* @remarks
|
|
4129
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
4130
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
4131
|
+
*
|
|
4132
|
+
* @param params - Version action parameters:
|
|
4133
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
4134
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
4135
|
+
* @param purge - if `true` the document history is also discarded.
|
|
4136
|
+
* @param options - Additional action options.
|
|
4137
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
4138
|
+
*
|
|
4139
|
+
* @example Discarding a release version of a document
|
|
4140
|
+
* ```ts
|
|
4141
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
4142
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
4143
|
+
* ```
|
|
4144
|
+
*
|
|
4145
|
+
* @example Discarding a draft version of a document
|
|
4146
|
+
* ```ts
|
|
4147
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
4148
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
4149
|
+
* ```
|
|
4150
|
+
*/
|
|
4151
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
4152
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
4153
|
+
return _discardVersion(this, this.#httpRequest, documentVersionId, purge, options);
|
|
4154
|
+
}
|
|
4155
|
+
replaceVersion({
|
|
4156
|
+
document,
|
|
4157
|
+
publishedId,
|
|
4158
|
+
releaseId
|
|
4159
|
+
}, options) {
|
|
4160
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
4161
|
+
document,
|
|
4162
|
+
publishedId,
|
|
4163
|
+
releaseId
|
|
4164
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
4165
|
+
return _replaceVersion(this, this.#httpRequest, documentVersion, options);
|
|
4166
|
+
}
|
|
4167
|
+
/**
|
|
4168
|
+
* @public
|
|
4169
|
+
*
|
|
4170
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
4171
|
+
* the release is run.
|
|
4172
|
+
*
|
|
4173
|
+
* @remarks
|
|
4174
|
+
* * If the published document does not exist, an error will be thrown.
|
|
4175
|
+
*
|
|
4176
|
+
* @param params - Version action parameters:
|
|
4177
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
4178
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
4179
|
+
* @param options - Additional action options.
|
|
4180
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
4181
|
+
*
|
|
4182
|
+
* @example Unpublishing a release version of a published document
|
|
4183
|
+
* ```ts
|
|
4184
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
4185
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
4186
|
+
* ```
|
|
4187
|
+
*/
|
|
4188
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
4189
|
+
const versionId = getVersionId(publishedId, releaseId);
|
|
4190
|
+
return _unpublishVersion(this, this.#httpRequest, versionId, publishedId, options);
|
|
4191
|
+
}
|
|
3463
4192
|
mutate(operations, options) {
|
|
3464
4193
|
return _mutate(this, this.#httpRequest, operations, options);
|
|
3465
4194
|
}
|
|
@@ -3524,6 +4253,7 @@ ${selectionOpts}`);
|
|
|
3524
4253
|
projects;
|
|
3525
4254
|
users;
|
|
3526
4255
|
agent;
|
|
4256
|
+
releases;
|
|
3527
4257
|
/**
|
|
3528
4258
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
3529
4259
|
*/
|
|
@@ -3540,7 +4270,7 @@ ${selectionOpts}`);
|
|
|
3540
4270
|
constructor(httpRequest, config = defaultConfig) {
|
|
3541
4271
|
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 = {
|
|
3542
4272
|
action: new AgentActionsClient(this, this.#httpRequest)
|
|
3543
|
-
}, this.observable = new ObservableSanityClient(httpRequest, config);
|
|
4273
|
+
}, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
3544
4274
|
}
|
|
3545
4275
|
/**
|
|
3546
4276
|
* Clone the client - returns a new instance
|
|
@@ -3621,9 +4351,104 @@ ${selectionOpts}`);
|
|
|
3621
4351
|
_createOrReplace(this, this.#httpRequest, document, options)
|
|
3622
4352
|
);
|
|
3623
4353
|
}
|
|
4354
|
+
createVersion({
|
|
4355
|
+
document,
|
|
4356
|
+
publishedId,
|
|
4357
|
+
releaseId
|
|
4358
|
+
}, options) {
|
|
4359
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
4360
|
+
document,
|
|
4361
|
+
publishedId,
|
|
4362
|
+
releaseId
|
|
4363
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId$1(document._id);
|
|
4364
|
+
return firstValueFrom(
|
|
4365
|
+
_createVersion(
|
|
4366
|
+
this,
|
|
4367
|
+
this.#httpRequest,
|
|
4368
|
+
documentVersion,
|
|
4369
|
+
versionPublishedId,
|
|
4370
|
+
options
|
|
4371
|
+
)
|
|
4372
|
+
);
|
|
4373
|
+
}
|
|
3624
4374
|
delete(selection, options) {
|
|
3625
4375
|
return lastValueFrom(_delete(this, this.#httpRequest, selection, options));
|
|
3626
4376
|
}
|
|
4377
|
+
/**
|
|
4378
|
+
* @public
|
|
4379
|
+
*
|
|
4380
|
+
* Deletes the draft or release version of a document.
|
|
4381
|
+
*
|
|
4382
|
+
* @remarks
|
|
4383
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
4384
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
4385
|
+
*
|
|
4386
|
+
* @param params - Version action parameters:
|
|
4387
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
4388
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
4389
|
+
* @param purge - if `true` the document history is also discarded.
|
|
4390
|
+
* @param options - Additional action options.
|
|
4391
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
4392
|
+
*
|
|
4393
|
+
* @example Discarding a release version of a document
|
|
4394
|
+
* ```ts
|
|
4395
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
4396
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
4397
|
+
* ```
|
|
4398
|
+
*
|
|
4399
|
+
* @example Discarding a draft version of a document
|
|
4400
|
+
* ```ts
|
|
4401
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
4402
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
4403
|
+
* ```
|
|
4404
|
+
*/
|
|
4405
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
4406
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
4407
|
+
return lastValueFrom(
|
|
4408
|
+
_discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
|
|
4409
|
+
);
|
|
4410
|
+
}
|
|
4411
|
+
replaceVersion({
|
|
4412
|
+
document,
|
|
4413
|
+
publishedId,
|
|
4414
|
+
releaseId
|
|
4415
|
+
}, options) {
|
|
4416
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
4417
|
+
document,
|
|
4418
|
+
publishedId,
|
|
4419
|
+
releaseId
|
|
4420
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
4421
|
+
return firstValueFrom(
|
|
4422
|
+
_replaceVersion(this, this.#httpRequest, documentVersion, options)
|
|
4423
|
+
);
|
|
4424
|
+
}
|
|
4425
|
+
/**
|
|
4426
|
+
* @public
|
|
4427
|
+
*
|
|
4428
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
4429
|
+
* the release is run.
|
|
4430
|
+
*
|
|
4431
|
+
* @remarks
|
|
4432
|
+
* * If the published document does not exist, an error will be thrown.
|
|
4433
|
+
*
|
|
4434
|
+
* @param params - Version action parameters:
|
|
4435
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
4436
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
4437
|
+
* @param options - Additional action options.
|
|
4438
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
4439
|
+
*
|
|
4440
|
+
* @example Unpublishing a release version of a published document
|
|
4441
|
+
* ```ts
|
|
4442
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
4443
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
4444
|
+
* ```
|
|
4445
|
+
*/
|
|
4446
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
4447
|
+
const versionId = getVersionId(publishedId, releaseId);
|
|
4448
|
+
return lastValueFrom(
|
|
4449
|
+
_unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
|
|
4450
|
+
);
|
|
4451
|
+
}
|
|
3627
4452
|
mutate(operations, options) {
|
|
3628
4453
|
return lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
|
|
3629
4454
|
}
|