@sanity/workflow-engine-test 0.8.0 → 0.9.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 +18 -13
- package/dist/index.cjs +40 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -37
- package/dist/index.d.ts +61 -37
- package/dist/index.js +42 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -3,15 +3,16 @@ import { Actor } from "@sanity/workflow-engine";
|
|
|
3
3
|
import type { CompleteEffectArgs } from "@sanity/workflow-engine";
|
|
4
4
|
import { DeployDefinitionsArgs } from "@sanity/workflow-engine";
|
|
5
5
|
import { DeployDefinitionsResult } from "@sanity/workflow-engine";
|
|
6
|
-
import { DispatchResult } from "@sanity/workflow-engine";
|
|
7
6
|
import type { EditFieldArgs } from "@sanity/workflow-engine";
|
|
8
7
|
import type { EvaluateArgs } from "@sanity/workflow-engine";
|
|
9
8
|
import type { FireActionArgs } from "@sanity/workflow-engine";
|
|
10
9
|
import { GdrUri } from "@sanity/workflow-engine";
|
|
11
10
|
import type { Grant } from "@sanity/workflow-engine";
|
|
11
|
+
import { InitialFieldValue } from "@sanity/workflow-engine";
|
|
12
12
|
import { MutationGuardAction } from "@sanity/workflow-engine";
|
|
13
13
|
import { MutationGuardDoc } from "@sanity/workflow-engine";
|
|
14
14
|
import type { OperationArgs } from "@sanity/workflow-engine";
|
|
15
|
+
import { OperationResult } from "@sanity/workflow-engine";
|
|
15
16
|
import { PendingEffect } from "@sanity/workflow-engine";
|
|
16
17
|
import type { StartInstanceArgs } from "@sanity/workflow-engine";
|
|
17
18
|
import type { WorkflowAccess } from "@sanity/workflow-engine";
|
|
@@ -51,21 +52,16 @@ export declare type Bench = BenchState &
|
|
|
51
52
|
EngineWrappers &
|
|
52
53
|
ReadHelpers &
|
|
53
54
|
GuardHelpers &
|
|
54
|
-
QueryHelpers
|
|
55
|
+
QueryHelpers &
|
|
56
|
+
ComposedHelpers;
|
|
55
57
|
|
|
56
|
-
declare type BenchCompleteEffectArgs = Omit<
|
|
57
|
-
CompleteEffectArgs,
|
|
58
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
59
|
-
> & {
|
|
58
|
+
declare type BenchCompleteEffectArgs = Omit<CompleteEffectArgs, "access"> & {
|
|
60
59
|
access?: WorkflowAccess;
|
|
61
60
|
/** Shortcut for `access.actor`. */
|
|
62
61
|
actor?: Actor;
|
|
63
62
|
};
|
|
64
63
|
|
|
65
|
-
declare type BenchEditFieldArgs = Omit<
|
|
66
|
-
EditFieldArgs,
|
|
67
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
68
|
-
> & {
|
|
64
|
+
declare type BenchEditFieldArgs = Omit<EditFieldArgs, "access"> & {
|
|
69
65
|
access?: WorkflowAccess;
|
|
70
66
|
/** Shortcut for `access.actor`. */
|
|
71
67
|
actor?: Actor;
|
|
@@ -73,10 +69,7 @@ declare type BenchEditFieldArgs = Omit<
|
|
|
73
69
|
grants?: Grant[];
|
|
74
70
|
};
|
|
75
71
|
|
|
76
|
-
declare type BenchEvaluateArgs = Omit<
|
|
77
|
-
EvaluateArgs,
|
|
78
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
79
|
-
> & {
|
|
72
|
+
declare type BenchEvaluateArgs = Omit<EvaluateArgs, "access"> & {
|
|
80
73
|
access?: WorkflowAccess;
|
|
81
74
|
/** Shortcut for `access.actor`. */
|
|
82
75
|
actor?: Actor;
|
|
@@ -84,10 +77,7 @@ declare type BenchEvaluateArgs = Omit<
|
|
|
84
77
|
grants?: Grant[];
|
|
85
78
|
};
|
|
86
79
|
|
|
87
|
-
declare type BenchFireActionArgs = Omit<
|
|
88
|
-
FireActionArgs,
|
|
89
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
90
|
-
> & {
|
|
80
|
+
declare type BenchFireActionArgs = Omit<FireActionArgs, "access"> & {
|
|
91
81
|
access?: WorkflowAccess;
|
|
92
82
|
/** Shortcut for `access.actor`. */
|
|
93
83
|
actor?: Actor;
|
|
@@ -95,10 +85,7 @@ declare type BenchFireActionArgs = Omit<
|
|
|
95
85
|
grants?: Grant[];
|
|
96
86
|
};
|
|
97
87
|
|
|
98
|
-
declare type BenchStartInstanceArgs = Omit<
|
|
99
|
-
StartInstanceArgs,
|
|
100
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
101
|
-
> & {
|
|
88
|
+
declare type BenchStartInstanceArgs = Omit<StartInstanceArgs, "access"> & {
|
|
102
89
|
access?: WorkflowAccess;
|
|
103
90
|
/** Shortcut for `access.actor`. */
|
|
104
91
|
actor?: Actor;
|
|
@@ -142,10 +129,7 @@ declare interface BenchState {
|
|
|
142
129
|
advance: (ms: number) => void;
|
|
143
130
|
}
|
|
144
131
|
|
|
145
|
-
declare type BenchTickArgs = Omit<
|
|
146
|
-
OperationArgs,
|
|
147
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
148
|
-
> & {
|
|
132
|
+
declare type BenchTickArgs = Omit<OperationArgs, "access"> & {
|
|
149
133
|
access?: WorkflowAccess;
|
|
150
134
|
/** Shortcut for `access.actor`. */
|
|
151
135
|
actor?: Actor;
|
|
@@ -171,6 +155,21 @@ declare interface CallRecord {
|
|
|
171
155
|
dataset: string;
|
|
172
156
|
}
|
|
173
157
|
|
|
158
|
+
/** Helpers composed across the wrapper + read groups at bench assembly. */
|
|
159
|
+
declare interface ComposedHelpers {
|
|
160
|
+
/**
|
|
161
|
+
* Complete the pending effect named `effect` — {@link EngineWrappers.completeEffect}
|
|
162
|
+
* with the `effectKey` looked up by name, throwing loud when no such effect
|
|
163
|
+
* is pending. The idiomatic way to play an external handler reporting its
|
|
164
|
+
* result; pass `ops` to write outcome fields in the same commit.
|
|
165
|
+
*/
|
|
166
|
+
completePendingEffect: (
|
|
167
|
+
args: Omit<BenchCompleteEffectArgs, "effectKey"> & {
|
|
168
|
+
effect: string;
|
|
169
|
+
},
|
|
170
|
+
) => Promise<OperationResult>;
|
|
171
|
+
}
|
|
172
|
+
|
|
174
173
|
/**
|
|
175
174
|
* Create a fresh bench. By default the bench is fully isolated — two
|
|
176
175
|
* `createBench()` calls have no shared state. Pass `client` + `tag`
|
|
@@ -282,13 +281,13 @@ declare type DocumentValuePermission = "create" | "read" | "update";
|
|
|
282
281
|
/** Engine-call wrappers that inject the bench-owned client + tag + access. */
|
|
283
282
|
declare type EngineWrappers = {
|
|
284
283
|
deployDefinitions: (
|
|
285
|
-
args:
|
|
284
|
+
args: DeployDefinitionsArgs,
|
|
286
285
|
) => Promise<DeployDefinitionsResult>;
|
|
287
|
-
startInstance: (args: BenchStartInstanceArgs) => Promise<
|
|
288
|
-
fireAction: (args: BenchFireActionArgs) => Promise<
|
|
289
|
-
editField: (args: BenchEditFieldArgs) => Promise<
|
|
290
|
-
completeEffect: (args: BenchCompleteEffectArgs) => Promise<
|
|
291
|
-
tick: (args: BenchTickArgs) => Promise<
|
|
286
|
+
startInstance: (args: BenchStartInstanceArgs) => Promise<OperationResult>;
|
|
287
|
+
fireAction: (args: BenchFireActionArgs) => Promise<OperationResult>;
|
|
288
|
+
editField: (args: BenchEditFieldArgs) => Promise<OperationResult>;
|
|
289
|
+
completeEffect: (args: BenchCompleteEffectArgs) => Promise<OperationResult>;
|
|
290
|
+
tick: (args: BenchTickArgs) => Promise<OperationResult>;
|
|
292
291
|
evaluate: (args: BenchEvaluateArgs) => Promise<WorkflowEvaluation>;
|
|
293
292
|
guardsForInstance: (instanceId: string) => Promise<MutationGuardDoc[]>;
|
|
294
293
|
guardsForDefinition: (definition: string) => Promise<MutationGuardDoc[]>;
|
|
@@ -382,7 +381,7 @@ declare interface Grant_2 {
|
|
|
382
381
|
}
|
|
383
382
|
|
|
384
383
|
declare type GuardHelpers = {
|
|
385
|
-
/** All deployed
|
|
384
|
+
/** All deployed guard docs ({@link MutationGuardDoc}) in the store. */
|
|
386
385
|
listGuards: () => Promise<MutationGuardDoc[]>;
|
|
387
386
|
/**
|
|
388
387
|
* Guards that would deny an arbitrary edit to `documentId` right now (i.e.
|
|
@@ -394,11 +393,11 @@ declare type GuardHelpers = {
|
|
|
394
393
|
as?: Actor,
|
|
395
394
|
) => Promise<MutationGuardDoc[]>;
|
|
396
395
|
/**
|
|
397
|
-
* Write to a document through the client's
|
|
396
|
+
* Write to a document through the client's guarded write seam — the bench
|
|
398
397
|
* client gates the write against deployed guards (incl. `identity()`) and
|
|
399
|
-
* throws `MutationGuardDeniedError` on denial
|
|
400
|
-
* `as` routes the write through a
|
|
401
|
-
* resolves to that actor.
|
|
398
|
+
* throws `MutationGuardDeniedError` on denial — the lake's intended
|
|
399
|
+
* rejection, simulated by the bench. `as` routes the write through a
|
|
400
|
+
* token-scoped sibling so `identity()` resolves to that actor.
|
|
402
401
|
*/
|
|
403
402
|
editDocument: (opts: {
|
|
404
403
|
documentId: string;
|
|
@@ -650,6 +649,18 @@ declare interface ReleaseDocument extends SanityDocument {
|
|
|
650
649
|
publishAt?: string;
|
|
651
650
|
}
|
|
652
651
|
|
|
652
|
+
/**
|
|
653
|
+
* A `release.ref` entry pointing at `_.releases.<releaseName>` in the bench's
|
|
654
|
+
* default resource — what a release-targeting workflow's `release` field
|
|
655
|
+
* expects at start.
|
|
656
|
+
*/
|
|
657
|
+
export declare function releaseField(
|
|
658
|
+
releaseName: string,
|
|
659
|
+
opts?: {
|
|
660
|
+
name?: string;
|
|
661
|
+
},
|
|
662
|
+
): InitialFieldValue;
|
|
663
|
+
|
|
653
664
|
declare interface ReleaseMetadata {
|
|
654
665
|
title?: string;
|
|
655
666
|
description?: string;
|
|
@@ -737,6 +748,19 @@ declare type StoreDocument = {
|
|
|
737
748
|
[key: string]: unknown;
|
|
738
749
|
};
|
|
739
750
|
|
|
751
|
+
/**
|
|
752
|
+
* The conventional workflow-scope `subject` doc.ref entry, keyed by a bare
|
|
753
|
+
* doc id in the bench's default resource. `type` defaults to `'document'`;
|
|
754
|
+
* pass the subject's schema type when a filter or projection reads it.
|
|
755
|
+
*/
|
|
756
|
+
export declare function subjectField(
|
|
757
|
+
documentId: string,
|
|
758
|
+
opts?: {
|
|
759
|
+
name?: string;
|
|
760
|
+
type?: string;
|
|
761
|
+
},
|
|
762
|
+
): InitialFieldValue;
|
|
763
|
+
|
|
740
764
|
declare interface SystemFields {
|
|
741
765
|
_rev: string;
|
|
742
766
|
_createdAt: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,16 @@ import { Actor } from "@sanity/workflow-engine";
|
|
|
3
3
|
import type { CompleteEffectArgs } from "@sanity/workflow-engine";
|
|
4
4
|
import { DeployDefinitionsArgs } from "@sanity/workflow-engine";
|
|
5
5
|
import { DeployDefinitionsResult } from "@sanity/workflow-engine";
|
|
6
|
-
import { DispatchResult } from "@sanity/workflow-engine";
|
|
7
6
|
import type { EditFieldArgs } from "@sanity/workflow-engine";
|
|
8
7
|
import type { EvaluateArgs } from "@sanity/workflow-engine";
|
|
9
8
|
import type { FireActionArgs } from "@sanity/workflow-engine";
|
|
10
9
|
import { GdrUri } from "@sanity/workflow-engine";
|
|
11
10
|
import type { Grant } from "@sanity/workflow-engine";
|
|
11
|
+
import { InitialFieldValue } from "@sanity/workflow-engine";
|
|
12
12
|
import { MutationGuardAction } from "@sanity/workflow-engine";
|
|
13
13
|
import { MutationGuardDoc } from "@sanity/workflow-engine";
|
|
14
14
|
import type { OperationArgs } from "@sanity/workflow-engine";
|
|
15
|
+
import { OperationResult } from "@sanity/workflow-engine";
|
|
15
16
|
import { PendingEffect } from "@sanity/workflow-engine";
|
|
16
17
|
import type { StartInstanceArgs } from "@sanity/workflow-engine";
|
|
17
18
|
import type { WorkflowAccess } from "@sanity/workflow-engine";
|
|
@@ -51,21 +52,16 @@ export declare type Bench = BenchState &
|
|
|
51
52
|
EngineWrappers &
|
|
52
53
|
ReadHelpers &
|
|
53
54
|
GuardHelpers &
|
|
54
|
-
QueryHelpers
|
|
55
|
+
QueryHelpers &
|
|
56
|
+
ComposedHelpers;
|
|
55
57
|
|
|
56
|
-
declare type BenchCompleteEffectArgs = Omit<
|
|
57
|
-
CompleteEffectArgs,
|
|
58
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
59
|
-
> & {
|
|
58
|
+
declare type BenchCompleteEffectArgs = Omit<CompleteEffectArgs, "access"> & {
|
|
60
59
|
access?: WorkflowAccess;
|
|
61
60
|
/** Shortcut for `access.actor`. */
|
|
62
61
|
actor?: Actor;
|
|
63
62
|
};
|
|
64
63
|
|
|
65
|
-
declare type BenchEditFieldArgs = Omit<
|
|
66
|
-
EditFieldArgs,
|
|
67
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
68
|
-
> & {
|
|
64
|
+
declare type BenchEditFieldArgs = Omit<EditFieldArgs, "access"> & {
|
|
69
65
|
access?: WorkflowAccess;
|
|
70
66
|
/** Shortcut for `access.actor`. */
|
|
71
67
|
actor?: Actor;
|
|
@@ -73,10 +69,7 @@ declare type BenchEditFieldArgs = Omit<
|
|
|
73
69
|
grants?: Grant[];
|
|
74
70
|
};
|
|
75
71
|
|
|
76
|
-
declare type BenchEvaluateArgs = Omit<
|
|
77
|
-
EvaluateArgs,
|
|
78
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
79
|
-
> & {
|
|
72
|
+
declare type BenchEvaluateArgs = Omit<EvaluateArgs, "access"> & {
|
|
80
73
|
access?: WorkflowAccess;
|
|
81
74
|
/** Shortcut for `access.actor`. */
|
|
82
75
|
actor?: Actor;
|
|
@@ -84,10 +77,7 @@ declare type BenchEvaluateArgs = Omit<
|
|
|
84
77
|
grants?: Grant[];
|
|
85
78
|
};
|
|
86
79
|
|
|
87
|
-
declare type BenchFireActionArgs = Omit<
|
|
88
|
-
FireActionArgs,
|
|
89
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
90
|
-
> & {
|
|
80
|
+
declare type BenchFireActionArgs = Omit<FireActionArgs, "access"> & {
|
|
91
81
|
access?: WorkflowAccess;
|
|
92
82
|
/** Shortcut for `access.actor`. */
|
|
93
83
|
actor?: Actor;
|
|
@@ -95,10 +85,7 @@ declare type BenchFireActionArgs = Omit<
|
|
|
95
85
|
grants?: Grant[];
|
|
96
86
|
};
|
|
97
87
|
|
|
98
|
-
declare type BenchStartInstanceArgs = Omit<
|
|
99
|
-
StartInstanceArgs,
|
|
100
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
101
|
-
> & {
|
|
88
|
+
declare type BenchStartInstanceArgs = Omit<StartInstanceArgs, "access"> & {
|
|
102
89
|
access?: WorkflowAccess;
|
|
103
90
|
/** Shortcut for `access.actor`. */
|
|
104
91
|
actor?: Actor;
|
|
@@ -142,10 +129,7 @@ declare interface BenchState {
|
|
|
142
129
|
advance: (ms: number) => void;
|
|
143
130
|
}
|
|
144
131
|
|
|
145
|
-
declare type BenchTickArgs = Omit<
|
|
146
|
-
OperationArgs,
|
|
147
|
-
"client" | "tag" | "workflowResource" | "access"
|
|
148
|
-
> & {
|
|
132
|
+
declare type BenchTickArgs = Omit<OperationArgs, "access"> & {
|
|
149
133
|
access?: WorkflowAccess;
|
|
150
134
|
/** Shortcut for `access.actor`. */
|
|
151
135
|
actor?: Actor;
|
|
@@ -171,6 +155,21 @@ declare interface CallRecord {
|
|
|
171
155
|
dataset: string;
|
|
172
156
|
}
|
|
173
157
|
|
|
158
|
+
/** Helpers composed across the wrapper + read groups at bench assembly. */
|
|
159
|
+
declare interface ComposedHelpers {
|
|
160
|
+
/**
|
|
161
|
+
* Complete the pending effect named `effect` — {@link EngineWrappers.completeEffect}
|
|
162
|
+
* with the `effectKey` looked up by name, throwing loud when no such effect
|
|
163
|
+
* is pending. The idiomatic way to play an external handler reporting its
|
|
164
|
+
* result; pass `ops` to write outcome fields in the same commit.
|
|
165
|
+
*/
|
|
166
|
+
completePendingEffect: (
|
|
167
|
+
args: Omit<BenchCompleteEffectArgs, "effectKey"> & {
|
|
168
|
+
effect: string;
|
|
169
|
+
},
|
|
170
|
+
) => Promise<OperationResult>;
|
|
171
|
+
}
|
|
172
|
+
|
|
174
173
|
/**
|
|
175
174
|
* Create a fresh bench. By default the bench is fully isolated — two
|
|
176
175
|
* `createBench()` calls have no shared state. Pass `client` + `tag`
|
|
@@ -282,13 +281,13 @@ declare type DocumentValuePermission = "create" | "read" | "update";
|
|
|
282
281
|
/** Engine-call wrappers that inject the bench-owned client + tag + access. */
|
|
283
282
|
declare type EngineWrappers = {
|
|
284
283
|
deployDefinitions: (
|
|
285
|
-
args:
|
|
284
|
+
args: DeployDefinitionsArgs,
|
|
286
285
|
) => Promise<DeployDefinitionsResult>;
|
|
287
|
-
startInstance: (args: BenchStartInstanceArgs) => Promise<
|
|
288
|
-
fireAction: (args: BenchFireActionArgs) => Promise<
|
|
289
|
-
editField: (args: BenchEditFieldArgs) => Promise<
|
|
290
|
-
completeEffect: (args: BenchCompleteEffectArgs) => Promise<
|
|
291
|
-
tick: (args: BenchTickArgs) => Promise<
|
|
286
|
+
startInstance: (args: BenchStartInstanceArgs) => Promise<OperationResult>;
|
|
287
|
+
fireAction: (args: BenchFireActionArgs) => Promise<OperationResult>;
|
|
288
|
+
editField: (args: BenchEditFieldArgs) => Promise<OperationResult>;
|
|
289
|
+
completeEffect: (args: BenchCompleteEffectArgs) => Promise<OperationResult>;
|
|
290
|
+
tick: (args: BenchTickArgs) => Promise<OperationResult>;
|
|
292
291
|
evaluate: (args: BenchEvaluateArgs) => Promise<WorkflowEvaluation>;
|
|
293
292
|
guardsForInstance: (instanceId: string) => Promise<MutationGuardDoc[]>;
|
|
294
293
|
guardsForDefinition: (definition: string) => Promise<MutationGuardDoc[]>;
|
|
@@ -382,7 +381,7 @@ declare interface Grant_2 {
|
|
|
382
381
|
}
|
|
383
382
|
|
|
384
383
|
declare type GuardHelpers = {
|
|
385
|
-
/** All deployed
|
|
384
|
+
/** All deployed guard docs ({@link MutationGuardDoc}) in the store. */
|
|
386
385
|
listGuards: () => Promise<MutationGuardDoc[]>;
|
|
387
386
|
/**
|
|
388
387
|
* Guards that would deny an arbitrary edit to `documentId` right now (i.e.
|
|
@@ -394,11 +393,11 @@ declare type GuardHelpers = {
|
|
|
394
393
|
as?: Actor,
|
|
395
394
|
) => Promise<MutationGuardDoc[]>;
|
|
396
395
|
/**
|
|
397
|
-
* Write to a document through the client's
|
|
396
|
+
* Write to a document through the client's guarded write seam — the bench
|
|
398
397
|
* client gates the write against deployed guards (incl. `identity()`) and
|
|
399
|
-
* throws `MutationGuardDeniedError` on denial
|
|
400
|
-
* `as` routes the write through a
|
|
401
|
-
* resolves to that actor.
|
|
398
|
+
* throws `MutationGuardDeniedError` on denial — the lake's intended
|
|
399
|
+
* rejection, simulated by the bench. `as` routes the write through a
|
|
400
|
+
* token-scoped sibling so `identity()` resolves to that actor.
|
|
402
401
|
*/
|
|
403
402
|
editDocument: (opts: {
|
|
404
403
|
documentId: string;
|
|
@@ -650,6 +649,18 @@ declare interface ReleaseDocument extends SanityDocument {
|
|
|
650
649
|
publishAt?: string;
|
|
651
650
|
}
|
|
652
651
|
|
|
652
|
+
/**
|
|
653
|
+
* A `release.ref` entry pointing at `_.releases.<releaseName>` in the bench's
|
|
654
|
+
* default resource — what a release-targeting workflow's `release` field
|
|
655
|
+
* expects at start.
|
|
656
|
+
*/
|
|
657
|
+
export declare function releaseField(
|
|
658
|
+
releaseName: string,
|
|
659
|
+
opts?: {
|
|
660
|
+
name?: string;
|
|
661
|
+
},
|
|
662
|
+
): InitialFieldValue;
|
|
663
|
+
|
|
653
664
|
declare interface ReleaseMetadata {
|
|
654
665
|
title?: string;
|
|
655
666
|
description?: string;
|
|
@@ -737,6 +748,19 @@ declare type StoreDocument = {
|
|
|
737
748
|
[key: string]: unknown;
|
|
738
749
|
};
|
|
739
750
|
|
|
751
|
+
/**
|
|
752
|
+
* The conventional workflow-scope `subject` doc.ref entry, keyed by a bare
|
|
753
|
+
* doc id in the bench's default resource. `type` defaults to `'document'`;
|
|
754
|
+
* pass the subject's schema type when a filter or projection reads it.
|
|
755
|
+
*/
|
|
756
|
+
export declare function subjectField(
|
|
757
|
+
documentId: string,
|
|
758
|
+
opts?: {
|
|
759
|
+
name?: string;
|
|
760
|
+
type?: string;
|
|
761
|
+
},
|
|
762
|
+
): InitialFieldValue;
|
|
763
|
+
|
|
740
764
|
declare interface SystemFields {
|
|
741
765
|
_rev: string;
|
|
742
766
|
_createdAt: string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { guardsForResource, denyingGuards, MutationGuardDeniedError, workflow, WORKFLOW_INSTANCE_TYPE, tagScopeFilter, effectsContextMap, validateTag } from "@sanity/workflow-engine";
|
|
1
|
+
import { guardsForResource, denyingGuards, MutationGuardDeniedError, workflow, instancesQuery, WORKFLOW_INSTANCE_TYPE, tagScopeFilter, effectsContextMap, gdrFromResource, gdrRef, validateTag } from "@sanity/workflow-engine";
|
|
2
2
|
import require$$0 from "tty";
|
|
3
3
|
import require$$1 from "util";
|
|
4
4
|
function escapeRegExp(string2) {
|
|
@@ -5010,7 +5010,7 @@ const DEFAULT_WORKFLOW_RESOURCE = {
|
|
|
5010
5010
|
type: "dataset",
|
|
5011
5011
|
id: "test.test"
|
|
5012
5012
|
}, ALL_ACCESS_USER = {
|
|
5013
|
-
kind: "
|
|
5013
|
+
kind: "person",
|
|
5014
5014
|
id: "bench-user",
|
|
5015
5015
|
roles: ["*"]
|
|
5016
5016
|
}, WILDCARD_GRANTS = [
|
|
@@ -5181,17 +5181,38 @@ function createReadHelpers(scope) {
|
|
|
5181
5181
|
)
|
|
5182
5182
|
),
|
|
5183
5183
|
instancesByStage: async ({ workflowName, stage, openOnly }) => {
|
|
5184
|
-
const
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
);
|
|
5184
|
+
const { query, params } = instancesQuery({
|
|
5185
|
+
tag,
|
|
5186
|
+
filter: { definition: workflowName, stage, includeCompleted: !openOnly }
|
|
5187
|
+
});
|
|
5188
|
+
return client.fetch(query, params);
|
|
5190
5189
|
},
|
|
5191
5190
|
instancesForDocument: async (document2) => workflow.instancesForDocument({ ...scope, document: document2 }),
|
|
5192
5191
|
snapshot: () => client.snapshot()
|
|
5193
5192
|
};
|
|
5194
5193
|
}
|
|
5194
|
+
function subjectField(documentId, opts) {
|
|
5195
|
+
return {
|
|
5196
|
+
type: "doc.ref",
|
|
5197
|
+
name: opts?.name ?? "subject",
|
|
5198
|
+
value: gdrRef({
|
|
5199
|
+
res: DEFAULT_WORKFLOW_RESOURCE,
|
|
5200
|
+
documentId,
|
|
5201
|
+
type: opts?.type ?? "document"
|
|
5202
|
+
})
|
|
5203
|
+
};
|
|
5204
|
+
}
|
|
5205
|
+
function releaseField(releaseName, opts) {
|
|
5206
|
+
return {
|
|
5207
|
+
type: "release.ref",
|
|
5208
|
+
name: opts?.name ?? "release",
|
|
5209
|
+
value: {
|
|
5210
|
+
id: gdrFromResource(DEFAULT_WORKFLOW_RESOURCE, `_.releases.${releaseName}`),
|
|
5211
|
+
type: "system.release",
|
|
5212
|
+
releaseName
|
|
5213
|
+
}
|
|
5214
|
+
};
|
|
5215
|
+
}
|
|
5195
5216
|
function createBench(options = {}) {
|
|
5196
5217
|
const tag = options.tag ?? "bench";
|
|
5197
5218
|
validateTag(tag);
|
|
@@ -5201,7 +5222,7 @@ function createBench(options = {}) {
|
|
|
5201
5222
|
workflowResource
|
|
5202
5223
|
}, access = resolveBenchAccess(options);
|
|
5203
5224
|
let frozenNow = options.now !== void 0 ? assertIsoInstant(options.now) : void 0;
|
|
5204
|
-
const clock = () => frozenNow ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
5225
|
+
const clock = () => frozenNow ?? (/* @__PURE__ */ new Date()).toISOString(), engine = createEngineWrappers({ scope, access, clock }), reads = createReadHelpers(scope);
|
|
5205
5226
|
return {
|
|
5206
5227
|
client,
|
|
5207
5228
|
access,
|
|
@@ -5217,10 +5238,16 @@ function createBench(options = {}) {
|
|
|
5217
5238
|
throw new Error(`bench.advance: ms must be a finite number, got ${ms2}`);
|
|
5218
5239
|
frozenNow = new Date(Date.parse(frozenNow ?? (/* @__PURE__ */ new Date()).toISOString()) + ms2).toISOString();
|
|
5219
5240
|
},
|
|
5220
|
-
...
|
|
5221
|
-
...
|
|
5241
|
+
...engine,
|
|
5242
|
+
...reads,
|
|
5222
5243
|
...createGuardHelpers(client),
|
|
5223
|
-
...createQueryHelpers(scope)
|
|
5244
|
+
...createQueryHelpers(scope),
|
|
5245
|
+
completePendingEffect: async ({ effect, ...rest }) => {
|
|
5246
|
+
const match = (await reads.pendingEffects(rest.instanceId)).find((e) => e.name === effect);
|
|
5247
|
+
if (match === void 0)
|
|
5248
|
+
throw new Error(`completePendingEffect: no pending effect named "${effect}"`);
|
|
5249
|
+
return engine.completeEffect({ ...rest, effectKey: match._key });
|
|
5250
|
+
}
|
|
5224
5251
|
};
|
|
5225
5252
|
}
|
|
5226
5253
|
function assertIsoInstant(iso) {
|
|
@@ -5234,6 +5261,8 @@ export {
|
|
|
5234
5261
|
ALL_ACCESS_USER,
|
|
5235
5262
|
DEFAULT_WORKFLOW_RESOURCE,
|
|
5236
5263
|
WILDCARD_GRANTS,
|
|
5237
|
-
createBench
|
|
5264
|
+
createBench,
|
|
5265
|
+
releaseField,
|
|
5266
|
+
subjectField
|
|
5238
5267
|
};
|
|
5239
5268
|
//# sourceMappingURL=index.js.map
|