@sanity/workflow-engine-test 0.1.0 → 0.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 +39 -0
- package/dist/index.cjs +5091 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +711 -6
- package/dist/index.d.ts +711 -6
- package/dist/index.js +5089 -45
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -13,6 +13,45 @@ boilerplate.
|
|
|
13
13
|
npm install -D @sanity/workflow-engine-test
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
## Mutation guards
|
|
17
|
+
|
|
18
|
+
A workflow stage can deploy **mutation guards** — `temp.system.guard` documents
|
|
19
|
+
that lock the documents it governs while the stage is active, and lift when it
|
|
20
|
+
exits. There are two distinct things you test, and the bench gives you a helper
|
|
21
|
+
for each:
|
|
22
|
+
|
|
23
|
+
- **Write-time enforcement** — `bench.editDocument(id, patch)` writes through the
|
|
24
|
+
bench client, which **simulates the lake's server-side guard rejection**: a
|
|
25
|
+
write a deployed guard denies throws `MutationGuardDeniedError`. In production
|
|
26
|
+
the lake enforces this for _any_ client; the bench reproduces it on the
|
|
27
|
+
client it mints.
|
|
28
|
+
- **Read-time preflight** — `bench.activeGuardsForDocument(id)` answers "_would_
|
|
29
|
+
a write be denied right now?" _without_ writing. This is the check a UI uses
|
|
30
|
+
to disable a button or show a lock ahead of time. It's a pure read over the
|
|
31
|
+
same evaluation path as enforcement, so its verdict matches what a write would
|
|
32
|
+
actually do — and it works against any client.
|
|
33
|
+
|
|
34
|
+
`bench.listGuards()` returns the deployed guard docs for inspection.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const bench = createBench({documents: [{_id: 'doc-1', _type: 'article', body: 'b'}]})
|
|
38
|
+
// …deploy a definition whose current stage locks `doc-1`, start an instance…
|
|
39
|
+
|
|
40
|
+
// Preflight: is the doc locked for this user right now?
|
|
41
|
+
const active = await bench.activeGuardsForDocument('doc-1')
|
|
42
|
+
|
|
43
|
+
// Enforcement: a guard-violating write is rejected.
|
|
44
|
+
await expect(bench.editDocument('doc-1', {body: 'edited'})).rejects.toThrow(
|
|
45
|
+
MutationGuardDeniedError,
|
|
46
|
+
)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> To share one store across benches with enforcement intact, pass another
|
|
50
|
+
> bench's already-wired client: `createBench({client: other.client, tags})`. The
|
|
51
|
+
> `mutationGuard` rides along, so the second bench enforces the same locks. Only
|
|
52
|
+
> a bare hand-built `createTestClient()` opts out of write rejection — the
|
|
53
|
+
> read-time preflight needs no wiring either way.
|
|
54
|
+
|
|
16
55
|
## License
|
|
17
56
|
|
|
18
57
|
[MIT](./LICENSE)
|