@sanity-labs/client-fake-for-test 0.17.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +8 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1381,7 +1381,7 @@ async function applyAction(store, action, hooks) {
|
|
|
1381
1381
|
return store.remove(release._id), { transactionId: cryptoRandomKey() };
|
|
1382
1382
|
}
|
|
1383
1383
|
case "sanity.action.document.version.create": {
|
|
1384
|
-
if ("baseId" in action) return createVersionFromBase(store, action);
|
|
1384
|
+
if ("baseId" in action) return createVersionFromBase(store, action, hooks);
|
|
1385
1385
|
const releaseId = action.releaseId ?? (action.document._id !== void 0 ? parseVersionId(action.document._id).releaseId : void 0);
|
|
1386
1386
|
if (releaseId === void 0)
|
|
1387
1387
|
throw fakeError(
|
|
@@ -1393,7 +1393,7 @@ async function applyAction(store, action, hooks) {
|
|
|
1393
1393
|
...action.document,
|
|
1394
1394
|
_id: vid
|
|
1395
1395
|
}, existing = store.get(vid), promoted = promote(doc);
|
|
1396
|
-
return existing !== void 0 && (promoted._createdAt = existing._createdAt), store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1396
|
+
return existing !== void 0 && (promoted._createdAt = existing._createdAt), await hooks?.gate?.(existing ?? promoted, existing === void 0 ? "create" : "update"), store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1397
1397
|
}
|
|
1398
1398
|
case "sanity.action.document.version.replace": {
|
|
1399
1399
|
const id = action.document._id;
|
|
@@ -1453,7 +1453,7 @@ function requireDraftOf(action) {
|
|
|
1453
1453
|
`${action.actionType}: draftId "${action.draftId}" is not the draft of publishedId "${action.publishedId}" \u2014 expected draftId "drafts.${action.publishedId}".`
|
|
1454
1454
|
);
|
|
1455
1455
|
}
|
|
1456
|
-
function createVersionFromBase(store, action) {
|
|
1456
|
+
async function createVersionFromBase(store, action, hooks) {
|
|
1457
1457
|
const { releaseId, publishedId } = parseVersionId(action.versionId);
|
|
1458
1458
|
if (publishedId !== action.publishedId)
|
|
1459
1459
|
throw fakeError(
|
|
@@ -1466,12 +1466,13 @@ function createVersionFromBase(store, action) {
|
|
|
1466
1466
|
`Cannot create version "${action.versionId}": base document "${action.baseId}" not found. version.create with \`baseId\` copies an existing document; pass \`document\` instead when there is nothing to copy.`
|
|
1467
1467
|
);
|
|
1468
1468
|
requireRevisionMatch(action.baseId, base._rev, action.ifBaseRevisionId);
|
|
1469
|
-
const existing = store.get(action.versionId),
|
|
1469
|
+
const existing = store.get(action.versionId), copy = {
|
|
1470
1470
|
...base,
|
|
1471
1471
|
_id: action.versionId,
|
|
1472
|
-
_createdAt: existing?._createdAt ?? nowIso()
|
|
1473
|
-
|
|
1474
|
-
|
|
1472
|
+
_createdAt: existing?._createdAt ?? nowIso(),
|
|
1473
|
+
_system: { base: { id: base._id, rev: base._rev } }
|
|
1474
|
+
}, promoted = promote(copy);
|
|
1475
|
+
return await hooks?.gate?.(existing ?? promoted, existing === void 0 ? "create" : "update"), store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1475
1476
|
}
|
|
1476
1477
|
function requireRevisionMatch(documentId, actualRev, expectedRev) {
|
|
1477
1478
|
if (!(expectedRev === void 0 || actualRev === expectedRev))
|