@sanity-labs/client-fake-for-test 0.7.0 → 0.8.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/dist/index.cjs +227 -164
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -11
- package/dist/index.d.ts +43 -11
- package/dist/index.js +227 -164
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type Action = ReleaseAction | VersionAction;
|
|
1
|
+
export declare type Action = ReleaseAction | VersionAction | DocumentAction;
|
|
2
2
|
|
|
3
3
|
/** Options for `action()`. Only `tag` is meaningful to the fake. */
|
|
4
4
|
export declare interface ActionOptions {
|
|
@@ -202,6 +202,26 @@ export declare function defaultAclPath(
|
|
|
202
202
|
dataset: string,
|
|
203
203
|
): string;
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Draft↔published document actions — `sanity.action.document.publish`
|
|
207
|
+
* promotes the draft onto the published id (and deletes the draft);
|
|
208
|
+
* `sanity.action.document.unpublish` retracts the published document into a
|
|
209
|
+
* draft (keeping an existing draft untouched) and deletes the published one.
|
|
210
|
+
*/
|
|
211
|
+
export declare type DocumentAction =
|
|
212
|
+
| {
|
|
213
|
+
actionType: "sanity.action.document.publish";
|
|
214
|
+
draftId: string;
|
|
215
|
+
publishedId: string;
|
|
216
|
+
ifDraftRevisionId?: string;
|
|
217
|
+
ifPublishedRevisionId?: string;
|
|
218
|
+
}
|
|
219
|
+
| {
|
|
220
|
+
actionType: "sanity.action.document.unpublish";
|
|
221
|
+
draftId: string;
|
|
222
|
+
publishedId: string;
|
|
223
|
+
};
|
|
224
|
+
|
|
205
225
|
/**
|
|
206
226
|
* Document body accepted by `version.create` / `createVersion`. The id
|
|
207
227
|
* is derived from `releaseId + publishedId` so callers may omit `_id`
|
|
@@ -387,11 +407,13 @@ export declare interface MultipleMutationResult {
|
|
|
387
407
|
* A pluggable write interceptor, configured via
|
|
388
408
|
* `createTestClient({ mutationGuard })`. It runs on each write through the
|
|
389
409
|
* document mutation API — `create` / `createOrReplace` / `createIfNotExists` /
|
|
390
|
-
* `patch` / `delete` and the equivalent `transaction()` operations —
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
410
|
+
* `patch` / `delete` and the equivalent `transaction()` operations — and on the
|
|
411
|
+
* document publish/unpublish actions (`sanity.action.document.publish` /
|
|
412
|
+
* `.unpublish` via `client.action`) — before the store changes; **throw to
|
|
413
|
+
* reject the write** (the throw propagates out of the client call, exactly as
|
|
414
|
+
* a real lake rejection would). The release/version action API
|
|
415
|
+
* (`client.releases.*`, `createVersion`, the `sanity.action.release.*` and
|
|
416
|
+
* `*.version.*` action types) is **not** intercepted.
|
|
395
417
|
*
|
|
396
418
|
* The client itself has no opinion about *what* a guard is — it only provides
|
|
397
419
|
* the seam and the before/after/identity context. Callers (e.g. a workflow test
|
|
@@ -404,13 +426,21 @@ export declare type MutationGuard = (
|
|
|
404
426
|
) => void | Promise<void>;
|
|
405
427
|
|
|
406
428
|
/** The kind of write a {@link MutationGuard} is asked to vet. */
|
|
407
|
-
export declare type MutationGuardAction =
|
|
429
|
+
export declare type MutationGuardAction =
|
|
430
|
+
| "create"
|
|
431
|
+
| "update"
|
|
432
|
+
| "delete"
|
|
433
|
+
| "publish"
|
|
434
|
+
| "unpublish";
|
|
408
435
|
|
|
409
436
|
/**
|
|
410
437
|
* The before/after image of a single document write, handed to a
|
|
411
438
|
* {@link MutationGuard} before it is applied.
|
|
412
439
|
*
|
|
413
|
-
* - `before` is null on create
|
|
440
|
+
* - `before` is null on create and on a publish with no live published
|
|
441
|
+
* document; `after` is null on delete and unpublish.
|
|
442
|
+
* - On publish/unpublish both images are of the *published* document —
|
|
443
|
+
* `after` on publish is the draft's content promoted onto the published id.
|
|
414
444
|
* - `identity` is the acting user — the id bound to the client's token
|
|
415
445
|
* (its `accessControl.currentUser`), or undefined when the client has no
|
|
416
446
|
* identity configured.
|
|
@@ -789,9 +819,11 @@ export declare interface TestClient {
|
|
|
789
819
|
options?: TxnCommitOptions,
|
|
790
820
|
) => Promise<TxnCommitResult>;
|
|
791
821
|
/**
|
|
792
|
-
* Dispatch one or more release / version actions against the
|
|
793
|
-
* Returns a synthetic `transactionId`. Multi-action arrays are
|
|
794
|
-
* atomically — any failure rolls back the batch.
|
|
822
|
+
* Dispatch one or more release / version / document actions against the
|
|
823
|
+
* store. Returns a synthetic `transactionId`. Multi-action arrays are
|
|
824
|
+
* applied atomically — any failure rolls back the batch. The document
|
|
825
|
+
* publish/unpublish actions run through the access gate and the
|
|
826
|
+
* `mutationGuard` seam; release/version actions apply unhooked.
|
|
795
827
|
*/
|
|
796
828
|
action: (
|
|
797
829
|
action: Action | Action[],
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type Action = ReleaseAction | VersionAction;
|
|
1
|
+
export declare type Action = ReleaseAction | VersionAction | DocumentAction;
|
|
2
2
|
|
|
3
3
|
/** Options for `action()`. Only `tag` is meaningful to the fake. */
|
|
4
4
|
export declare interface ActionOptions {
|
|
@@ -202,6 +202,26 @@ export declare function defaultAclPath(
|
|
|
202
202
|
dataset: string,
|
|
203
203
|
): string;
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Draft↔published document actions — `sanity.action.document.publish`
|
|
207
|
+
* promotes the draft onto the published id (and deletes the draft);
|
|
208
|
+
* `sanity.action.document.unpublish` retracts the published document into a
|
|
209
|
+
* draft (keeping an existing draft untouched) and deletes the published one.
|
|
210
|
+
*/
|
|
211
|
+
export declare type DocumentAction =
|
|
212
|
+
| {
|
|
213
|
+
actionType: "sanity.action.document.publish";
|
|
214
|
+
draftId: string;
|
|
215
|
+
publishedId: string;
|
|
216
|
+
ifDraftRevisionId?: string;
|
|
217
|
+
ifPublishedRevisionId?: string;
|
|
218
|
+
}
|
|
219
|
+
| {
|
|
220
|
+
actionType: "sanity.action.document.unpublish";
|
|
221
|
+
draftId: string;
|
|
222
|
+
publishedId: string;
|
|
223
|
+
};
|
|
224
|
+
|
|
205
225
|
/**
|
|
206
226
|
* Document body accepted by `version.create` / `createVersion`. The id
|
|
207
227
|
* is derived from `releaseId + publishedId` so callers may omit `_id`
|
|
@@ -387,11 +407,13 @@ export declare interface MultipleMutationResult {
|
|
|
387
407
|
* A pluggable write interceptor, configured via
|
|
388
408
|
* `createTestClient({ mutationGuard })`. It runs on each write through the
|
|
389
409
|
* document mutation API — `create` / `createOrReplace` / `createIfNotExists` /
|
|
390
|
-
* `patch` / `delete` and the equivalent `transaction()` operations —
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
410
|
+
* `patch` / `delete` and the equivalent `transaction()` operations — and on the
|
|
411
|
+
* document publish/unpublish actions (`sanity.action.document.publish` /
|
|
412
|
+
* `.unpublish` via `client.action`) — before the store changes; **throw to
|
|
413
|
+
* reject the write** (the throw propagates out of the client call, exactly as
|
|
414
|
+
* a real lake rejection would). The release/version action API
|
|
415
|
+
* (`client.releases.*`, `createVersion`, the `sanity.action.release.*` and
|
|
416
|
+
* `*.version.*` action types) is **not** intercepted.
|
|
395
417
|
*
|
|
396
418
|
* The client itself has no opinion about *what* a guard is — it only provides
|
|
397
419
|
* the seam and the before/after/identity context. Callers (e.g. a workflow test
|
|
@@ -404,13 +426,21 @@ export declare type MutationGuard = (
|
|
|
404
426
|
) => void | Promise<void>;
|
|
405
427
|
|
|
406
428
|
/** The kind of write a {@link MutationGuard} is asked to vet. */
|
|
407
|
-
export declare type MutationGuardAction =
|
|
429
|
+
export declare type MutationGuardAction =
|
|
430
|
+
| "create"
|
|
431
|
+
| "update"
|
|
432
|
+
| "delete"
|
|
433
|
+
| "publish"
|
|
434
|
+
| "unpublish";
|
|
408
435
|
|
|
409
436
|
/**
|
|
410
437
|
* The before/after image of a single document write, handed to a
|
|
411
438
|
* {@link MutationGuard} before it is applied.
|
|
412
439
|
*
|
|
413
|
-
* - `before` is null on create
|
|
440
|
+
* - `before` is null on create and on a publish with no live published
|
|
441
|
+
* document; `after` is null on delete and unpublish.
|
|
442
|
+
* - On publish/unpublish both images are of the *published* document —
|
|
443
|
+
* `after` on publish is the draft's content promoted onto the published id.
|
|
414
444
|
* - `identity` is the acting user — the id bound to the client's token
|
|
415
445
|
* (its `accessControl.currentUser`), or undefined when the client has no
|
|
416
446
|
* identity configured.
|
|
@@ -789,9 +819,11 @@ export declare interface TestClient {
|
|
|
789
819
|
options?: TxnCommitOptions,
|
|
790
820
|
) => Promise<TxnCommitResult>;
|
|
791
821
|
/**
|
|
792
|
-
* Dispatch one or more release / version actions against the
|
|
793
|
-
* Returns a synthetic `transactionId`. Multi-action arrays are
|
|
794
|
-
* atomically — any failure rolls back the batch.
|
|
822
|
+
* Dispatch one or more release / version / document actions against the
|
|
823
|
+
* store. Returns a synthetic `transactionId`. Multi-action arrays are
|
|
824
|
+
* applied atomically — any failure rolls back the batch. The document
|
|
825
|
+
* publish/unpublish actions run through the access gate and the
|
|
826
|
+
* `mutationGuard` seam; release/version actions apply unhooked.
|
|
795
827
|
*/
|
|
796
828
|
action: (
|
|
797
829
|
action: Action | Action[],
|