@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/README.md
CHANGED
|
@@ -76,7 +76,7 @@ More patterns — passing the fake to code typed against `SanityClient`, asserti
|
|
|
76
76
|
| Patch | `patch(id)` chain → `.commit()` | Ops: `.set`, `.setIfMissing`, `.unset`, `.inc`, `.dec`, `.insert(position, anchor, items)`, `.ifRevisionId` |
|
|
77
77
|
| Transaction | `transaction()` chain → `.commit()` | Mutations: `.create`, `.createOrReplace`, `.createIfNotExists`, `.delete`, `.patch(id, recipe)`. Atomic — any throw rolls back the whole batch. Default result is a `MultipleMutationResult` (`{ transactionId, documentIds, results }`) |
|
|
78
78
|
| Actions | `action(action \| action[])` | Content Lake release / version actions, applied atomically |
|
|
79
|
-
| Releases | `releases.*`, `createVersion`, `unpublishVersion` | Content Releases lifecycle — create / edit / schedule / publish / archive / delete, plus version create / replace / discard / unpublish. `createVersion({ baseId, publishedId, releaseId })` (or `version.create` with `baseId` + `versionId`) copies the base document, `_type` included, into the version; a missing base fails. A failed revision precondition (`ifDraftRevisionId`, `ifPublishedRevisionId`, `ifBaseRevisionId`) carries `statusCode: 409`, as the Actions API answers |
|
|
79
|
+
| Releases | `releases.*`, `createVersion`, `unpublishVersion` | Content Releases lifecycle — create / edit / schedule / publish / archive / delete, plus version create / replace / discard / unpublish. `createVersion({ baseId, publishedId, releaseId })` (or `version.create` with `baseId` + `versionId`) copies the base document, `_type` included, into the version and records it in `_system.base` (`{ id, rev }`); a missing base fails. With access control, `version.create` in either form needs `create` on the resulting version, or `update` on the version it replaces (as `createOrReplace` does), as the Content Lake does; the base is not access-checked. A failed revision precondition (`ifDraftRevisionId`, `ifPublishedRevisionId`, `ifBaseRevisionId`) carries `statusCode: 409`, as the Actions API answers |
|
|
80
80
|
| Config | `config()` | Returns `{ projectId, dataset, resource?, perspective, token?, useProjectHostname }` |
|
|
81
81
|
| Config | `getDataUrl(operation, path?)` | The same URL `@sanity/client` builds: `<resource base>/<operation>/<path>` on a `resource` handle, `/data/<operation>/<dataset>/<path>` otherwise |
|
|
82
82
|
| Config | `withConfig({ projectId?, dataset?, resource?, perspective?, accessControl?, token?, useProjectHostname? })` | Sibling handle into the same multi-resource registry; `resource` points it at a Media Library, Canvas, dashboard or dataset (see [Resource types](#resource-types-media-library-canvas-dashboard)); `token` binds a registered identity (see the token→identity registry below), `accessControl` rebinds it inline — the two are mutually exclusive; `useProjectHostname: false` mints a global-hosted sibling |
|
package/dist/index.cjs
CHANGED
|
@@ -1383,7 +1383,7 @@ async function applyAction(store, action, hooks) {
|
|
|
1383
1383
|
return store.remove(release._id), { transactionId: cryptoRandomKey() };
|
|
1384
1384
|
}
|
|
1385
1385
|
case "sanity.action.document.version.create": {
|
|
1386
|
-
if ("baseId" in action) return createVersionFromBase(store, action);
|
|
1386
|
+
if ("baseId" in action) return createVersionFromBase(store, action, hooks);
|
|
1387
1387
|
const releaseId = action.releaseId ?? (action.document._id !== void 0 ? parseVersionId(action.document._id).releaseId : void 0);
|
|
1388
1388
|
if (releaseId === void 0)
|
|
1389
1389
|
throw fakeError(
|
|
@@ -1395,7 +1395,7 @@ async function applyAction(store, action, hooks) {
|
|
|
1395
1395
|
...action.document,
|
|
1396
1396
|
_id: vid
|
|
1397
1397
|
}, existing = store.get(vid), promoted = promote(doc);
|
|
1398
|
-
return existing !== void 0 && (promoted._createdAt = existing._createdAt), store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1398
|
+
return existing !== void 0 && (promoted._createdAt = existing._createdAt), await hooks?.gate?.(existing ?? promoted, existing === void 0 ? "create" : "update"), store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1399
1399
|
}
|
|
1400
1400
|
case "sanity.action.document.version.replace": {
|
|
1401
1401
|
const id = action.document._id;
|
|
@@ -1455,7 +1455,7 @@ function requireDraftOf(action) {
|
|
|
1455
1455
|
`${action.actionType}: draftId "${action.draftId}" is not the draft of publishedId "${action.publishedId}" \u2014 expected draftId "drafts.${action.publishedId}".`
|
|
1456
1456
|
);
|
|
1457
1457
|
}
|
|
1458
|
-
function createVersionFromBase(store, action) {
|
|
1458
|
+
async function createVersionFromBase(store, action, hooks) {
|
|
1459
1459
|
const { releaseId, publishedId } = parseVersionId(action.versionId);
|
|
1460
1460
|
if (publishedId !== action.publishedId)
|
|
1461
1461
|
throw fakeError(
|
|
@@ -1468,12 +1468,13 @@ function createVersionFromBase(store, action) {
|
|
|
1468
1468
|
`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.`
|
|
1469
1469
|
);
|
|
1470
1470
|
requireRevisionMatch(action.baseId, base._rev, action.ifBaseRevisionId);
|
|
1471
|
-
const existing = store.get(action.versionId),
|
|
1471
|
+
const existing = store.get(action.versionId), copy = {
|
|
1472
1472
|
...base,
|
|
1473
1473
|
_id: action.versionId,
|
|
1474
|
-
_createdAt: existing?._createdAt ?? nowIso()
|
|
1475
|
-
|
|
1476
|
-
|
|
1474
|
+
_createdAt: existing?._createdAt ?? nowIso(),
|
|
1475
|
+
_system: { base: { id: base._id, rev: base._rev } }
|
|
1476
|
+
}, promoted = promote(copy);
|
|
1477
|
+
return await hooks?.gate?.(existing ?? promoted, existing === void 0 ? "create" : "update"), store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1477
1478
|
}
|
|
1478
1479
|
function requireRevisionMatch(documentId, actualRev, expectedRev) {
|
|
1479
1480
|
if (!(expectedRev === void 0 || actualRev === expectedRev))
|