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