@sanity/client 7.0.1-canary.2 → 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 +850 -7
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +2601 -1622
- package/dist/index.browser.d.ts +2601 -1622
- package/dist/index.browser.js +852 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +839 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2601 -1622
- package/dist/index.d.ts +2601 -1622
- package/dist/index.js +842 -9
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +2612 -1633
- package/dist/stega.browser.d.ts +2612 -1633
- package/dist/stega.d.cts +2612 -1633
- package/dist/stega.d.ts +2612 -1633
- package/package.json +3 -1
- package/src/SanityClient.ts +626 -1106
- package/src/agent/actions/AgentActionsClient.ts +111 -0
- package/src/agent/actions/commonTypes.ts +336 -0
- package/src/agent/actions/generate.ts +274 -0
- package/src/agent/actions/transform.ts +215 -0
- package/src/agent/actions/translate.ts +165 -0
- package/src/assets/AssetsClient.ts +2 -86
- package/src/data/dataMethods.ts +127 -3
- package/src/data/transaction.ts +1 -1
- package/src/datasets/DatasetsClient.ts +2 -64
- package/src/projects/ProjectsClient.ts +4 -46
- package/src/releases/ReleasesClient.ts +687 -0
- package/src/releases/createRelease.ts +53 -0
- package/src/types.ts +245 -1
- package/src/users/UsersClient.ts +2 -24
- package/src/util/createVersionId.ts +79 -0
- package/src/validators.ts +23 -1
- package/umd/sanityClient.js +915 -6
- package/umd/sanityClient.min.js +2 -2
package/dist/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
mod
|
|
20
20
|
));
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
|
-
var getIt = require("get-it"), middleware$1 = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators"), config = require("./_chunks-cjs/config.cjs");
|
|
22
|
+
var getIt = require("get-it"), middleware$1 = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators"), csm = require("@sanity/client/csm"), nanoid = require("nanoid"), config = require("./_chunks-cjs/config.cjs");
|
|
23
23
|
class ClientError extends Error {
|
|
24
24
|
response;
|
|
25
25
|
statusCode = 400;
|
|
@@ -636,8 +636,24 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
636
636
|
) : $request.pipe(operators.map(mapResponse));
|
|
637
637
|
}
|
|
638
638
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
639
|
-
const
|
|
640
|
-
|
|
639
|
+
const docId = (() => {
|
|
640
|
+
if (!opts.releaseId)
|
|
641
|
+
return id;
|
|
642
|
+
const versionId = csm.getVersionFromId(id);
|
|
643
|
+
if (!versionId) {
|
|
644
|
+
if (csm.isDraftId(id))
|
|
645
|
+
throw new Error(
|
|
646
|
+
`The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
|
|
647
|
+
);
|
|
648
|
+
return csm.getVersionId(id, opts.releaseId);
|
|
649
|
+
}
|
|
650
|
+
if (versionId !== opts.releaseId)
|
|
651
|
+
throw new Error(
|
|
652
|
+
`The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
|
|
653
|
+
);
|
|
654
|
+
return id;
|
|
655
|
+
})(), options = {
|
|
656
|
+
uri: _getDataUrl(client, "doc", docId),
|
|
641
657
|
json: !0,
|
|
642
658
|
tag: opts.tag,
|
|
643
659
|
signal: opts.signal
|
|
@@ -662,12 +678,33 @@ function _getDocuments(client, httpRequest, ids, opts = {}) {
|
|
|
662
678
|
})
|
|
663
679
|
);
|
|
664
680
|
}
|
|
681
|
+
function _getReleaseDocuments(client, httpRequest, releaseId, opts = {}) {
|
|
682
|
+
return _dataRequest(
|
|
683
|
+
client,
|
|
684
|
+
httpRequest,
|
|
685
|
+
"query",
|
|
686
|
+
{
|
|
687
|
+
query: "*[sanity::partOfRelease($releaseId)]",
|
|
688
|
+
params: {
|
|
689
|
+
releaseId
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
opts
|
|
693
|
+
);
|
|
694
|
+
}
|
|
665
695
|
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
666
696
|
return config.requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
667
697
|
}
|
|
668
698
|
function _createOrReplace(client, httpRequest, doc, options) {
|
|
669
699
|
return config.requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
670
700
|
}
|
|
701
|
+
function _createVersion(client, httpRequest, doc, publishedId, options) {
|
|
702
|
+
return config.requireDocumentId("createVersion", doc), config.requireDocumentType("createVersion", doc), _action(client, httpRequest, {
|
|
703
|
+
actionType: "sanity.action.document.version.create",
|
|
704
|
+
publishedId,
|
|
705
|
+
document: doc
|
|
706
|
+
}, options);
|
|
707
|
+
}
|
|
671
708
|
function _delete(client, httpRequest, selection, options) {
|
|
672
709
|
return _dataRequest(
|
|
673
710
|
client,
|
|
@@ -677,6 +714,26 @@ function _delete(client, httpRequest, selection, options) {
|
|
|
677
714
|
options
|
|
678
715
|
);
|
|
679
716
|
}
|
|
717
|
+
function _discardVersion(client, httpRequest, versionId, purge = !1, options) {
|
|
718
|
+
return _action(client, httpRequest, {
|
|
719
|
+
actionType: "sanity.action.document.version.discard",
|
|
720
|
+
versionId,
|
|
721
|
+
purge
|
|
722
|
+
}, options);
|
|
723
|
+
}
|
|
724
|
+
function _replaceVersion(client, httpRequest, doc, options) {
|
|
725
|
+
return config.requireDocumentId("replaceVersion", doc), config.requireDocumentType("replaceVersion", doc), _action(client, httpRequest, {
|
|
726
|
+
actionType: "sanity.action.document.version.replace",
|
|
727
|
+
document: doc
|
|
728
|
+
}, options);
|
|
729
|
+
}
|
|
730
|
+
function _unpublishVersion(client, httpRequest, versionId, publishedId, options) {
|
|
731
|
+
return _action(client, httpRequest, {
|
|
732
|
+
actionType: "sanity.action.document.version.unpublish",
|
|
733
|
+
versionId,
|
|
734
|
+
publishedId
|
|
735
|
+
}, options);
|
|
736
|
+
}
|
|
680
737
|
function _mutate(client, httpRequest, mutations, options) {
|
|
681
738
|
let mut;
|
|
682
739
|
mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
|
|
@@ -823,6 +880,86 @@ const resourceDataBase = (config2) => {
|
|
|
823
880
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
824
881
|
}
|
|
825
882
|
};
|
|
883
|
+
function _generate(client, httpRequest, request) {
|
|
884
|
+
const dataset = config.hasDataset(client.config());
|
|
885
|
+
return _request(client, httpRequest, {
|
|
886
|
+
method: "POST",
|
|
887
|
+
uri: `/agent/action/generate/${dataset}`,
|
|
888
|
+
body: request
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
function _transform(client, httpRequest, request) {
|
|
892
|
+
const dataset = config.hasDataset(client.config());
|
|
893
|
+
return _request(client, httpRequest, {
|
|
894
|
+
method: "POST",
|
|
895
|
+
uri: `/agent/action/transform/${dataset}`,
|
|
896
|
+
body: request
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
function _translate(client, httpRequest, request) {
|
|
900
|
+
const dataset = config.hasDataset(client.config());
|
|
901
|
+
return _request(client, httpRequest, {
|
|
902
|
+
method: "POST",
|
|
903
|
+
uri: `/agent/action/translate/${dataset}`,
|
|
904
|
+
body: request
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
class ObservableAgentsActionClient {
|
|
908
|
+
#client;
|
|
909
|
+
#httpRequest;
|
|
910
|
+
constructor(client, httpRequest) {
|
|
911
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Run an instruction to generate content in a target document.
|
|
915
|
+
* @param request - instruction request
|
|
916
|
+
*/
|
|
917
|
+
generate(request) {
|
|
918
|
+
return _generate(this.#client, this.#httpRequest, request);
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Transform a target document based on a source.
|
|
922
|
+
* @param request - translation request
|
|
923
|
+
*/
|
|
924
|
+
transform(request) {
|
|
925
|
+
return _transform(this.#client, this.#httpRequest, request);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Translate a target document based on a source.
|
|
929
|
+
* @param request - translation request
|
|
930
|
+
*/
|
|
931
|
+
translate(request) {
|
|
932
|
+
return _translate(this.#client, this.#httpRequest, request);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
class AgentActionsClient {
|
|
936
|
+
#client;
|
|
937
|
+
#httpRequest;
|
|
938
|
+
constructor(client, httpRequest) {
|
|
939
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Run an instruction to generate content in a target document.
|
|
943
|
+
* @param request - instruction request
|
|
944
|
+
*/
|
|
945
|
+
generate(request) {
|
|
946
|
+
return rxjs.lastValueFrom(_generate(this.#client, this.#httpRequest, request));
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Transform a target document based on a source.
|
|
950
|
+
* @param request - translation request
|
|
951
|
+
*/
|
|
952
|
+
transform(request) {
|
|
953
|
+
return rxjs.lastValueFrom(_transform(this.#client, this.#httpRequest, request));
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Translate a target document based on a source.
|
|
957
|
+
* @param request - translation request
|
|
958
|
+
*/
|
|
959
|
+
translate(request) {
|
|
960
|
+
return rxjs.lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
961
|
+
}
|
|
962
|
+
}
|
|
826
963
|
class ObservableAssetsClient {
|
|
827
964
|
#client;
|
|
828
965
|
#httpRequest;
|
|
@@ -1199,6 +1336,498 @@ class ProjectsClient {
|
|
|
1199
1336
|
);
|
|
1200
1337
|
}
|
|
1201
1338
|
}
|
|
1339
|
+
const generateReleaseId = nanoid.customAlphabet(
|
|
1340
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
1341
|
+
8
|
|
1342
|
+
), getDocumentVersionId = (publishedId, releaseId) => releaseId ? csm.getVersionId(publishedId, releaseId) : csm.getDraftId(publishedId);
|
|
1343
|
+
function deriveDocumentVersionId(op, {
|
|
1344
|
+
releaseId,
|
|
1345
|
+
publishedId,
|
|
1346
|
+
document
|
|
1347
|
+
}) {
|
|
1348
|
+
if (publishedId && document._id) {
|
|
1349
|
+
const versionId = getDocumentVersionId(publishedId, releaseId);
|
|
1350
|
+
return config.validateVersionIdMatch(versionId, document), versionId;
|
|
1351
|
+
}
|
|
1352
|
+
if (document._id) {
|
|
1353
|
+
const isDraft = csm.isDraftId(document._id), isVersion = csm.isVersionId(document._id);
|
|
1354
|
+
if (!isDraft && !isVersion)
|
|
1355
|
+
throw new Error(
|
|
1356
|
+
`\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
|
|
1357
|
+
);
|
|
1358
|
+
if (releaseId) {
|
|
1359
|
+
if (isDraft)
|
|
1360
|
+
throw new Error(
|
|
1361
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
|
|
1362
|
+
);
|
|
1363
|
+
const builtVersionId = csm.getVersionFromId(document._id);
|
|
1364
|
+
if (builtVersionId !== releaseId)
|
|
1365
|
+
throw new Error(
|
|
1366
|
+
`\`${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}\`).`
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
return document._id;
|
|
1370
|
+
}
|
|
1371
|
+
if (publishedId)
|
|
1372
|
+
return getDocumentVersionId(publishedId, releaseId);
|
|
1373
|
+
throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
|
|
1374
|
+
}
|
|
1375
|
+
const getArgs = (releaseOrOptions, maybeOptions) => {
|
|
1376
|
+
if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
|
|
1377
|
+
const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
|
|
1378
|
+
return [releaseId, metadata, maybeOptions];
|
|
1379
|
+
}
|
|
1380
|
+
return [generateReleaseId(), {}, releaseOrOptions];
|
|
1381
|
+
}, createRelease = (releaseOrOptions, maybeOptions) => {
|
|
1382
|
+
const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
|
|
1383
|
+
...metadata,
|
|
1384
|
+
releaseType: metadata.releaseType || "undecided"
|
|
1385
|
+
};
|
|
1386
|
+
return { action: {
|
|
1387
|
+
actionType: "sanity.action.release.create",
|
|
1388
|
+
releaseId,
|
|
1389
|
+
metadata: finalMetadata
|
|
1390
|
+
}, options };
|
|
1391
|
+
};
|
|
1392
|
+
class ObservableReleasesClient {
|
|
1393
|
+
#client;
|
|
1394
|
+
#httpRequest;
|
|
1395
|
+
constructor(client, httpRequest) {
|
|
1396
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* @public
|
|
1400
|
+
*
|
|
1401
|
+
* Retrieve a release by id.
|
|
1402
|
+
*
|
|
1403
|
+
* @category Releases
|
|
1404
|
+
*
|
|
1405
|
+
* @param params - Release action parameters:
|
|
1406
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
1407
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
1408
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
1409
|
+
*
|
|
1410
|
+
* @example Retrieving a release by id
|
|
1411
|
+
* ```ts
|
|
1412
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
1413
|
+
* tap((release) => console.log(release)),
|
|
1414
|
+
* // {
|
|
1415
|
+
* // _id: '_.releases.my-release',
|
|
1416
|
+
* // name: 'my-release'
|
|
1417
|
+
* // _type: 'system.release',
|
|
1418
|
+
* // metadata: {releaseType: 'asap'},
|
|
1419
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
1420
|
+
* // ...
|
|
1421
|
+
* // }
|
|
1422
|
+
* ).subscribe()
|
|
1423
|
+
* ```
|
|
1424
|
+
*/
|
|
1425
|
+
get({ releaseId }, options) {
|
|
1426
|
+
return _getDocument(
|
|
1427
|
+
this.#client,
|
|
1428
|
+
this.#httpRequest,
|
|
1429
|
+
`_.releases.${releaseId}`,
|
|
1430
|
+
options
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
create(releaseOrOptions, maybeOptions) {
|
|
1434
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
1435
|
+
return _action(this.#client, this.#httpRequest, action, options).pipe(
|
|
1436
|
+
rxjs.map((actionResult) => ({
|
|
1437
|
+
...actionResult,
|
|
1438
|
+
releaseId,
|
|
1439
|
+
metadata
|
|
1440
|
+
}))
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* @public
|
|
1445
|
+
*
|
|
1446
|
+
* Edits an existing release, updating the metadata.
|
|
1447
|
+
*
|
|
1448
|
+
* @category Releases
|
|
1449
|
+
*
|
|
1450
|
+
* @param params - Release action parameters:
|
|
1451
|
+
* - `releaseId` - The id of the release to edit.
|
|
1452
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
1453
|
+
* @param options - Additional action options.
|
|
1454
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1455
|
+
*/
|
|
1456
|
+
edit({ releaseId, patch }, options) {
|
|
1457
|
+
const editAction = {
|
|
1458
|
+
actionType: "sanity.action.release.edit",
|
|
1459
|
+
releaseId,
|
|
1460
|
+
patch
|
|
1461
|
+
};
|
|
1462
|
+
return _action(this.#client, this.#httpRequest, editAction, options);
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* @public
|
|
1466
|
+
*
|
|
1467
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
1468
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
1469
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
1470
|
+
* take some time.
|
|
1471
|
+
*
|
|
1472
|
+
* During this period both the source and target documents are locked and cannot be
|
|
1473
|
+
* modified through any other means.
|
|
1474
|
+
*
|
|
1475
|
+
* @category Releases
|
|
1476
|
+
*
|
|
1477
|
+
* @param params - Release action parameters:
|
|
1478
|
+
* - `releaseId` - The id of the release to publish.
|
|
1479
|
+
* @param options - Additional action options.
|
|
1480
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1481
|
+
*/
|
|
1482
|
+
publish({ releaseId }, options) {
|
|
1483
|
+
const publishAction = {
|
|
1484
|
+
actionType: "sanity.action.release.publish",
|
|
1485
|
+
releaseId
|
|
1486
|
+
};
|
|
1487
|
+
return _action(this.#client, this.#httpRequest, publishAction, options);
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* @public
|
|
1491
|
+
*
|
|
1492
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
1493
|
+
* are deleted and therefore no longer queryable.
|
|
1494
|
+
*
|
|
1495
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
1496
|
+
*
|
|
1497
|
+
* @category Releases
|
|
1498
|
+
*
|
|
1499
|
+
* @param params - Release action parameters:
|
|
1500
|
+
* - `releaseId` - The id of the release to archive.
|
|
1501
|
+
* @param options - Additional action options.
|
|
1502
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1503
|
+
*/
|
|
1504
|
+
archive({ releaseId }, options) {
|
|
1505
|
+
const archiveAction = {
|
|
1506
|
+
actionType: "sanity.action.release.archive",
|
|
1507
|
+
releaseId
|
|
1508
|
+
};
|
|
1509
|
+
return _action(this.#client, this.#httpRequest, archiveAction, options);
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* @public
|
|
1513
|
+
*
|
|
1514
|
+
* An unarchive action restores an archived release and all documents
|
|
1515
|
+
* with the content they had just prior to archiving.
|
|
1516
|
+
*
|
|
1517
|
+
* @category Releases
|
|
1518
|
+
*
|
|
1519
|
+
* @param params - Release action parameters:
|
|
1520
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
1521
|
+
* @param options - Additional action options.
|
|
1522
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1523
|
+
*/
|
|
1524
|
+
unarchive({ releaseId }, options) {
|
|
1525
|
+
const unarchiveAction = {
|
|
1526
|
+
actionType: "sanity.action.release.unarchive",
|
|
1527
|
+
releaseId
|
|
1528
|
+
};
|
|
1529
|
+
return _action(this.#client, this.#httpRequest, unarchiveAction, options);
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
* @public
|
|
1533
|
+
*
|
|
1534
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
1535
|
+
* The release is locked such that no documents in the release can be modified and
|
|
1536
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
1537
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
1538
|
+
*
|
|
1539
|
+
* @category Releases
|
|
1540
|
+
*
|
|
1541
|
+
* @param params - Release action parameters:
|
|
1542
|
+
* - `releaseId` - The id of the release to schedule.
|
|
1543
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
1544
|
+
* @param options - Additional action options.
|
|
1545
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1546
|
+
*/
|
|
1547
|
+
schedule({ releaseId, publishAt }, options) {
|
|
1548
|
+
const scheduleAction = {
|
|
1549
|
+
actionType: "sanity.action.release.schedule",
|
|
1550
|
+
releaseId,
|
|
1551
|
+
publishAt
|
|
1552
|
+
};
|
|
1553
|
+
return _action(this.#client, this.#httpRequest, scheduleAction, options);
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* @public
|
|
1557
|
+
*
|
|
1558
|
+
* An unschedule action stops a release from being published.
|
|
1559
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
1560
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
1561
|
+
* has a reference to a document created by this one.
|
|
1562
|
+
*
|
|
1563
|
+
* @category Releases
|
|
1564
|
+
*
|
|
1565
|
+
* @param params - Release action parameters:
|
|
1566
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
1567
|
+
* @param options - Additional action options.
|
|
1568
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1569
|
+
*/
|
|
1570
|
+
unschedule({ releaseId }, options) {
|
|
1571
|
+
const unscheduleAction = {
|
|
1572
|
+
actionType: "sanity.action.release.unschedule",
|
|
1573
|
+
releaseId
|
|
1574
|
+
};
|
|
1575
|
+
return _action(this.#client, this.#httpRequest, unscheduleAction, options);
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* @public
|
|
1579
|
+
*
|
|
1580
|
+
* A delete action removes a published or archived release.
|
|
1581
|
+
* The backing system document will be removed from the dataset.
|
|
1582
|
+
*
|
|
1583
|
+
* @category Releases
|
|
1584
|
+
*
|
|
1585
|
+
* @param params - Release action parameters:
|
|
1586
|
+
* - `releaseId` - The id of the release to delete.
|
|
1587
|
+
* @param options - Additional action options.
|
|
1588
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1589
|
+
*/
|
|
1590
|
+
delete({ releaseId }, options) {
|
|
1591
|
+
const deleteAction = {
|
|
1592
|
+
actionType: "sanity.action.release.delete",
|
|
1593
|
+
releaseId
|
|
1594
|
+
};
|
|
1595
|
+
return _action(this.#client, this.#httpRequest, deleteAction, options);
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* @public
|
|
1599
|
+
*
|
|
1600
|
+
* Fetch the documents in a release by release id.
|
|
1601
|
+
*
|
|
1602
|
+
* @category Releases
|
|
1603
|
+
*
|
|
1604
|
+
* @param params - Release action parameters:
|
|
1605
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
1606
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
1607
|
+
* @returns An observable that resolves to the documents in the release.
|
|
1608
|
+
*/
|
|
1609
|
+
fetchDocuments({ releaseId }, options) {
|
|
1610
|
+
return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
class ReleasesClient {
|
|
1614
|
+
#client;
|
|
1615
|
+
#httpRequest;
|
|
1616
|
+
constructor(client, httpRequest) {
|
|
1617
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* @public
|
|
1621
|
+
*
|
|
1622
|
+
* Retrieve a release by id.
|
|
1623
|
+
*
|
|
1624
|
+
* @category Releases
|
|
1625
|
+
*
|
|
1626
|
+
* @param params - Release action parameters:
|
|
1627
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
1628
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
1629
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
1630
|
+
*
|
|
1631
|
+
* @example Retrieving a release by id
|
|
1632
|
+
* ```ts
|
|
1633
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
1634
|
+
* console.log(release)
|
|
1635
|
+
* // {
|
|
1636
|
+
* // _id: '_.releases.my-release',
|
|
1637
|
+
* // name: 'my-release'
|
|
1638
|
+
* // _type: 'system.release',
|
|
1639
|
+
* // metadata: {releaseType: 'asap'},
|
|
1640
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
1641
|
+
* // ...
|
|
1642
|
+
* // }
|
|
1643
|
+
* ```
|
|
1644
|
+
*/
|
|
1645
|
+
get({ releaseId }, options) {
|
|
1646
|
+
return rxjs.lastValueFrom(
|
|
1647
|
+
_getDocument(
|
|
1648
|
+
this.#client,
|
|
1649
|
+
this.#httpRequest,
|
|
1650
|
+
`_.releases.${releaseId}`,
|
|
1651
|
+
options
|
|
1652
|
+
)
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
async create(releaseOrOptions, maybeOptions) {
|
|
1656
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
1657
|
+
return { ...await rxjs.lastValueFrom(
|
|
1658
|
+
_action(this.#client, this.#httpRequest, action, options)
|
|
1659
|
+
), releaseId, metadata };
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* @public
|
|
1663
|
+
*
|
|
1664
|
+
* Edits an existing release, updating the metadata.
|
|
1665
|
+
*
|
|
1666
|
+
* @category Releases
|
|
1667
|
+
*
|
|
1668
|
+
* @param params - Release action parameters:
|
|
1669
|
+
* - `releaseId` - The id of the release to edit.
|
|
1670
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
1671
|
+
* @param options - Additional action options.
|
|
1672
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1673
|
+
*/
|
|
1674
|
+
edit({ releaseId, patch }, options) {
|
|
1675
|
+
const editAction = {
|
|
1676
|
+
actionType: "sanity.action.release.edit",
|
|
1677
|
+
releaseId,
|
|
1678
|
+
patch
|
|
1679
|
+
};
|
|
1680
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, editAction, options));
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* @public
|
|
1684
|
+
*
|
|
1685
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
1686
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
1687
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
1688
|
+
* take some time.
|
|
1689
|
+
*
|
|
1690
|
+
* During this period both the source and target documents are locked and cannot be
|
|
1691
|
+
* modified through any other means.
|
|
1692
|
+
*
|
|
1693
|
+
* @category Releases
|
|
1694
|
+
*
|
|
1695
|
+
* @param params - Release action parameters:
|
|
1696
|
+
* - `releaseId` - The id of the release to publish.
|
|
1697
|
+
* @param options - Additional action options.
|
|
1698
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1699
|
+
*/
|
|
1700
|
+
publish({ releaseId }, options) {
|
|
1701
|
+
const publishAction = {
|
|
1702
|
+
actionType: "sanity.action.release.publish",
|
|
1703
|
+
releaseId
|
|
1704
|
+
};
|
|
1705
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, publishAction, options));
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* @public
|
|
1709
|
+
*
|
|
1710
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
1711
|
+
* are deleted and therefore no longer queryable.
|
|
1712
|
+
*
|
|
1713
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
1714
|
+
*
|
|
1715
|
+
* @category Releases
|
|
1716
|
+
*
|
|
1717
|
+
* @param params - Release action parameters:
|
|
1718
|
+
* - `releaseId` - The id of the release to archive.
|
|
1719
|
+
* @param options - Additional action options.
|
|
1720
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1721
|
+
*/
|
|
1722
|
+
archive({ releaseId }, options) {
|
|
1723
|
+
const archiveAction = {
|
|
1724
|
+
actionType: "sanity.action.release.archive",
|
|
1725
|
+
releaseId
|
|
1726
|
+
};
|
|
1727
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, archiveAction, options));
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* @public
|
|
1731
|
+
*
|
|
1732
|
+
* An unarchive action restores an archived release and all documents
|
|
1733
|
+
* with the content they had just prior to archiving.
|
|
1734
|
+
*
|
|
1735
|
+
* @category Releases
|
|
1736
|
+
*
|
|
1737
|
+
* @param params - Release action parameters:
|
|
1738
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
1739
|
+
* @param options - Additional action options.
|
|
1740
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1741
|
+
*/
|
|
1742
|
+
unarchive({ releaseId }, options) {
|
|
1743
|
+
const unarchiveAction = {
|
|
1744
|
+
actionType: "sanity.action.release.unarchive",
|
|
1745
|
+
releaseId
|
|
1746
|
+
};
|
|
1747
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, unarchiveAction, options));
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* @public
|
|
1751
|
+
*
|
|
1752
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
1753
|
+
* The release is locked such that no documents in the release can be modified and
|
|
1754
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
1755
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
1756
|
+
*
|
|
1757
|
+
* @category Releases
|
|
1758
|
+
*
|
|
1759
|
+
* @param params - Release action parameters:
|
|
1760
|
+
* - `releaseId` - The id of the release to schedule.
|
|
1761
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
1762
|
+
* @param options - Additional action options.
|
|
1763
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1764
|
+
*/
|
|
1765
|
+
schedule({ releaseId, publishAt }, options) {
|
|
1766
|
+
const scheduleAction = {
|
|
1767
|
+
actionType: "sanity.action.release.schedule",
|
|
1768
|
+
releaseId,
|
|
1769
|
+
publishAt
|
|
1770
|
+
};
|
|
1771
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, scheduleAction, options));
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* @public
|
|
1775
|
+
*
|
|
1776
|
+
* An unschedule action stops a release from being published.
|
|
1777
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
1778
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
1779
|
+
* has a reference to a document created by this one.
|
|
1780
|
+
*
|
|
1781
|
+
* @category Releases
|
|
1782
|
+
*
|
|
1783
|
+
* @param params - Release action parameters:
|
|
1784
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
1785
|
+
* @param options - Additional action options.
|
|
1786
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1787
|
+
*/
|
|
1788
|
+
unschedule({ releaseId }, options) {
|
|
1789
|
+
const unscheduleAction = {
|
|
1790
|
+
actionType: "sanity.action.release.unschedule",
|
|
1791
|
+
releaseId
|
|
1792
|
+
};
|
|
1793
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, unscheduleAction, options));
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* @public
|
|
1797
|
+
*
|
|
1798
|
+
* A delete action removes a published or archived release.
|
|
1799
|
+
* The backing system document will be removed from the dataset.
|
|
1800
|
+
*
|
|
1801
|
+
* @category Releases
|
|
1802
|
+
*
|
|
1803
|
+
* @param params - Release action parameters:
|
|
1804
|
+
* - `releaseId` - The id of the release to delete.
|
|
1805
|
+
* @param options - Additional action options.
|
|
1806
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1807
|
+
*/
|
|
1808
|
+
delete({ releaseId }, options) {
|
|
1809
|
+
const deleteAction = {
|
|
1810
|
+
actionType: "sanity.action.release.delete",
|
|
1811
|
+
releaseId
|
|
1812
|
+
};
|
|
1813
|
+
return rxjs.lastValueFrom(_action(this.#client, this.#httpRequest, deleteAction, options));
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* @public
|
|
1817
|
+
*
|
|
1818
|
+
* Fetch the documents in a release by release id.
|
|
1819
|
+
*
|
|
1820
|
+
* @category Releases
|
|
1821
|
+
*
|
|
1822
|
+
* @param params - Release action parameters:
|
|
1823
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
1824
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
1825
|
+
* @returns A promise that resolves to the documents in the release.
|
|
1826
|
+
*/
|
|
1827
|
+
fetchDocuments({ releaseId }, options) {
|
|
1828
|
+
return rxjs.lastValueFrom(_getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options));
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1202
1831
|
class ObservableUsersClient {
|
|
1203
1832
|
#client;
|
|
1204
1833
|
#httpRequest;
|
|
@@ -1243,11 +1872,21 @@ class ObservableSanityClient {
|
|
|
1243
1872
|
live;
|
|
1244
1873
|
projects;
|
|
1245
1874
|
users;
|
|
1875
|
+
agent;
|
|
1876
|
+
releases;
|
|
1877
|
+
/**
|
|
1878
|
+
* Private properties
|
|
1879
|
+
*/
|
|
1246
1880
|
#clientConfig;
|
|
1247
1881
|
#httpRequest;
|
|
1882
|
+
/**
|
|
1883
|
+
* Instance properties
|
|
1884
|
+
*/
|
|
1248
1885
|
listen = _listen;
|
|
1249
1886
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1250
|
-
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)
|
|
1887
|
+
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 = {
|
|
1888
|
+
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
1889
|
+
}, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
1251
1890
|
}
|
|
1252
1891
|
/**
|
|
1253
1892
|
* Clone the client - returns a new instance
|
|
@@ -1320,9 +1959,96 @@ class ObservableSanityClient {
|
|
|
1320
1959
|
createOrReplace(document, options) {
|
|
1321
1960
|
return _createOrReplace(this, this.#httpRequest, document, options);
|
|
1322
1961
|
}
|
|
1962
|
+
createVersion({
|
|
1963
|
+
document,
|
|
1964
|
+
publishedId,
|
|
1965
|
+
releaseId
|
|
1966
|
+
}, options) {
|
|
1967
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
1968
|
+
document,
|
|
1969
|
+
publishedId,
|
|
1970
|
+
releaseId
|
|
1971
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
|
|
1972
|
+
return _createVersion(
|
|
1973
|
+
this,
|
|
1974
|
+
this.#httpRequest,
|
|
1975
|
+
documentVersion,
|
|
1976
|
+
versionPublishedId,
|
|
1977
|
+
options
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1323
1980
|
delete(selection, options) {
|
|
1324
1981
|
return _delete(this, this.#httpRequest, selection, options);
|
|
1325
1982
|
}
|
|
1983
|
+
/**
|
|
1984
|
+
* @public
|
|
1985
|
+
*
|
|
1986
|
+
* Deletes the draft or release version of a document.
|
|
1987
|
+
*
|
|
1988
|
+
* @remarks
|
|
1989
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1990
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1991
|
+
*
|
|
1992
|
+
* @param params - Version action parameters:
|
|
1993
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1994
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1995
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1996
|
+
* @param options - Additional action options.
|
|
1997
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
1998
|
+
*
|
|
1999
|
+
* @example Discarding a release version of a document
|
|
2000
|
+
* ```ts
|
|
2001
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2002
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
2003
|
+
* ```
|
|
2004
|
+
*
|
|
2005
|
+
* @example Discarding a draft version of a document
|
|
2006
|
+
* ```ts
|
|
2007
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
2008
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
2009
|
+
* ```
|
|
2010
|
+
*/
|
|
2011
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
2012
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
2013
|
+
return _discardVersion(this, this.#httpRequest, documentVersionId, purge, options);
|
|
2014
|
+
}
|
|
2015
|
+
replaceVersion({
|
|
2016
|
+
document,
|
|
2017
|
+
publishedId,
|
|
2018
|
+
releaseId
|
|
2019
|
+
}, options) {
|
|
2020
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
2021
|
+
document,
|
|
2022
|
+
publishedId,
|
|
2023
|
+
releaseId
|
|
2024
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
2025
|
+
return _replaceVersion(this, this.#httpRequest, documentVersion, options);
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* @public
|
|
2029
|
+
*
|
|
2030
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
2031
|
+
* the release is run.
|
|
2032
|
+
*
|
|
2033
|
+
* @remarks
|
|
2034
|
+
* * If the published document does not exist, an error will be thrown.
|
|
2035
|
+
*
|
|
2036
|
+
* @param params - Version action parameters:
|
|
2037
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2038
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
2039
|
+
* @param options - Additional action options.
|
|
2040
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
2041
|
+
*
|
|
2042
|
+
* @example Unpublishing a release version of a published document
|
|
2043
|
+
* ```ts
|
|
2044
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2045
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
2046
|
+
* ```
|
|
2047
|
+
*/
|
|
2048
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
2049
|
+
const versionId = csm.getVersionId(publishedId, releaseId);
|
|
2050
|
+
return _unpublishVersion(this, this.#httpRequest, versionId, publishedId, options);
|
|
2051
|
+
}
|
|
1326
2052
|
mutate(operations, options) {
|
|
1327
2053
|
return _mutate(this, this.#httpRequest, operations, options);
|
|
1328
2054
|
}
|
|
@@ -1386,15 +2112,25 @@ class SanityClient {
|
|
|
1386
2112
|
live;
|
|
1387
2113
|
projects;
|
|
1388
2114
|
users;
|
|
2115
|
+
agent;
|
|
2116
|
+
releases;
|
|
1389
2117
|
/**
|
|
1390
2118
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1391
2119
|
*/
|
|
1392
2120
|
observable;
|
|
2121
|
+
/**
|
|
2122
|
+
* Private properties
|
|
2123
|
+
*/
|
|
1393
2124
|
#clientConfig;
|
|
1394
2125
|
#httpRequest;
|
|
2126
|
+
/**
|
|
2127
|
+
* Instance properties
|
|
2128
|
+
*/
|
|
1395
2129
|
listen = _listen;
|
|
1396
2130
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1397
|
-
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.
|
|
2131
|
+
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 = {
|
|
2132
|
+
action: new AgentActionsClient(this, this.#httpRequest)
|
|
2133
|
+
}, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config$1);
|
|
1398
2134
|
}
|
|
1399
2135
|
/**
|
|
1400
2136
|
* Clone the client - returns a new instance
|
|
@@ -1475,9 +2211,104 @@ class SanityClient {
|
|
|
1475
2211
|
_createOrReplace(this, this.#httpRequest, document, options)
|
|
1476
2212
|
);
|
|
1477
2213
|
}
|
|
2214
|
+
createVersion({
|
|
2215
|
+
document,
|
|
2216
|
+
publishedId,
|
|
2217
|
+
releaseId
|
|
2218
|
+
}, options) {
|
|
2219
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2220
|
+
document,
|
|
2221
|
+
publishedId,
|
|
2222
|
+
releaseId
|
|
2223
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
|
|
2224
|
+
return rxjs.firstValueFrom(
|
|
2225
|
+
_createVersion(
|
|
2226
|
+
this,
|
|
2227
|
+
this.#httpRequest,
|
|
2228
|
+
documentVersion,
|
|
2229
|
+
versionPublishedId,
|
|
2230
|
+
options
|
|
2231
|
+
)
|
|
2232
|
+
);
|
|
2233
|
+
}
|
|
1478
2234
|
delete(selection, options) {
|
|
1479
2235
|
return rxjs.lastValueFrom(_delete(this, this.#httpRequest, selection, options));
|
|
1480
2236
|
}
|
|
2237
|
+
/**
|
|
2238
|
+
* @public
|
|
2239
|
+
*
|
|
2240
|
+
* Deletes the draft or release version of a document.
|
|
2241
|
+
*
|
|
2242
|
+
* @remarks
|
|
2243
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
2244
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
2245
|
+
*
|
|
2246
|
+
* @param params - Version action parameters:
|
|
2247
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
2248
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
2249
|
+
* @param purge - if `true` the document history is also discarded.
|
|
2250
|
+
* @param options - Additional action options.
|
|
2251
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
2252
|
+
*
|
|
2253
|
+
* @example Discarding a release version of a document
|
|
2254
|
+
* ```ts
|
|
2255
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2256
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
2257
|
+
* ```
|
|
2258
|
+
*
|
|
2259
|
+
* @example Discarding a draft version of a document
|
|
2260
|
+
* ```ts
|
|
2261
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
2262
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
2263
|
+
* ```
|
|
2264
|
+
*/
|
|
2265
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
2266
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
2267
|
+
return rxjs.lastValueFrom(
|
|
2268
|
+
_discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
replaceVersion({
|
|
2272
|
+
document,
|
|
2273
|
+
publishedId,
|
|
2274
|
+
releaseId
|
|
2275
|
+
}, options) {
|
|
2276
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
2277
|
+
document,
|
|
2278
|
+
publishedId,
|
|
2279
|
+
releaseId
|
|
2280
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
2281
|
+
return rxjs.firstValueFrom(
|
|
2282
|
+
_replaceVersion(this, this.#httpRequest, documentVersion, options)
|
|
2283
|
+
);
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* @public
|
|
2287
|
+
*
|
|
2288
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
2289
|
+
* the release is run.
|
|
2290
|
+
*
|
|
2291
|
+
* @remarks
|
|
2292
|
+
* * If the published document does not exist, an error will be thrown.
|
|
2293
|
+
*
|
|
2294
|
+
* @param params - Version action parameters:
|
|
2295
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2296
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
2297
|
+
* @param options - Additional action options.
|
|
2298
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
2299
|
+
*
|
|
2300
|
+
* @example Unpublishing a release version of a published document
|
|
2301
|
+
* ```ts
|
|
2302
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2303
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
2304
|
+
* ```
|
|
2305
|
+
*/
|
|
2306
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
2307
|
+
const versionId = csm.getVersionId(publishedId, releaseId);
|
|
2308
|
+
return rxjs.lastValueFrom(
|
|
2309
|
+
_unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
|
|
2310
|
+
);
|
|
2311
|
+
}
|
|
1481
2312
|
mutate(operations, options) {
|
|
1482
2313
|
return rxjs.lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
|
|
1483
2314
|
}
|
|
@@ -1488,8 +2319,8 @@ class SanityClient {
|
|
|
1488
2319
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1489
2320
|
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1490
2321
|
*/
|
|
1491
|
-
patch(
|
|
1492
|
-
return new Patch(
|
|
2322
|
+
patch(documentId, operations) {
|
|
2323
|
+
return new Patch(documentId, operations, this);
|
|
1493
2324
|
}
|
|
1494
2325
|
/**
|
|
1495
2326
|
* Create a new transaction of mutations
|
|
@@ -1570,7 +2401,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1570
2401
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
1571
2402
|
};
|
|
1572
2403
|
}
|
|
1573
|
-
var name = "@sanity/client", version = "7.0
|
|
2404
|
+
var name = "@sanity/client", version = "7.2.0";
|
|
1574
2405
|
const middleware = [
|
|
1575
2406
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1576
2407
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|