@sanity/workflow-engine-test 0.6.1 → 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/README.md +2 -2
- package/dist/index.cjs +31 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -30
- package/dist/index.d.ts +38 -30
- package/dist/index.js +31 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ActivityStatus } from "@sanity/workflow-engine";
|
|
1
2
|
import { Actor } from "@sanity/workflow-engine";
|
|
2
3
|
import type { CompleteEffectArgs } from "@sanity/workflow-engine";
|
|
3
4
|
import { DeployDefinitionsArgs } from "@sanity/workflow-engine";
|
|
@@ -6,13 +7,13 @@ import { DispatchResult } from "@sanity/workflow-engine";
|
|
|
6
7
|
import type { EditFieldArgs } from "@sanity/workflow-engine";
|
|
7
8
|
import type { EvaluateArgs } from "@sanity/workflow-engine";
|
|
8
9
|
import type { FireActionArgs } from "@sanity/workflow-engine";
|
|
10
|
+
import { GdrUri } from "@sanity/workflow-engine";
|
|
9
11
|
import type { Grant } from "@sanity/workflow-engine";
|
|
10
12
|
import { MutationGuardAction } from "@sanity/workflow-engine";
|
|
11
13
|
import { MutationGuardDoc } from "@sanity/workflow-engine";
|
|
12
14
|
import type { OperationArgs } from "@sanity/workflow-engine";
|
|
13
15
|
import { PendingEffect } from "@sanity/workflow-engine";
|
|
14
16
|
import type { StartInstanceArgs } from "@sanity/workflow-engine";
|
|
15
|
-
import { TaskStatus } from "@sanity/workflow-engine";
|
|
16
17
|
import type { WorkflowAccess } from "@sanity/workflow-engine";
|
|
17
18
|
import { WorkflowEvaluation } from "@sanity/workflow-engine";
|
|
18
19
|
import { WorkflowInstance } from "@sanity/workflow-engine";
|
|
@@ -399,14 +400,12 @@ declare type GuardHelpers = {
|
|
|
399
400
|
* `as` routes the write through a token-scoped sibling so `identity()`
|
|
400
401
|
* resolves to that actor.
|
|
401
402
|
*/
|
|
402
|
-
editDocument: (
|
|
403
|
-
documentId: string
|
|
404
|
-
patch: Record<string, unknown
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
},
|
|
409
|
-
) => Promise<StoreDocument>;
|
|
403
|
+
editDocument: (opts: {
|
|
404
|
+
documentId: string;
|
|
405
|
+
patch: Record<string, unknown>;
|
|
406
|
+
action?: MutationGuardAction;
|
|
407
|
+
as?: Actor;
|
|
408
|
+
}) => Promise<StoreDocument>;
|
|
410
409
|
};
|
|
411
410
|
|
|
412
411
|
/** Result of a mutation when ids are requested for all affected documents. */
|
|
@@ -532,11 +531,15 @@ declare type QueryHelpers = {
|
|
|
532
531
|
* workflow?" — useful for filter debugging, UIs that mirror engine
|
|
533
532
|
* state, etc.
|
|
534
533
|
*/
|
|
535
|
-
queryInScope: <T = unknown>(
|
|
536
|
-
instanceId
|
|
537
|
-
groq
|
|
538
|
-
params
|
|
539
|
-
|
|
534
|
+
queryInScope: <T = unknown>({
|
|
535
|
+
instanceId,
|
|
536
|
+
groq,
|
|
537
|
+
params,
|
|
538
|
+
}: {
|
|
539
|
+
instanceId: string;
|
|
540
|
+
groq: string;
|
|
541
|
+
params?: Record<string, unknown>;
|
|
542
|
+
}) => Promise<T>;
|
|
540
543
|
};
|
|
541
544
|
|
|
542
545
|
declare type ReadHelpers = {
|
|
@@ -546,27 +549,27 @@ declare type ReadHelpers = {
|
|
|
546
549
|
currentStage: (instanceId: string) => Promise<string>;
|
|
547
550
|
/** Pending effects on an instance. */
|
|
548
551
|
pendingEffects: (instanceId: string) => Promise<PendingEffect[]>;
|
|
549
|
-
/** Status of a single
|
|
550
|
-
|
|
552
|
+
/** Status of a single activity on an instance, or undefined if missing. */
|
|
553
|
+
activityStatus: (
|
|
551
554
|
instanceId: string,
|
|
552
|
-
|
|
553
|
-
) => Promise<
|
|
555
|
+
activity: string,
|
|
556
|
+
) => Promise<ActivityStatus | undefined>;
|
|
554
557
|
/** The rendered `$effects` map — context entries keyed by `name`,
|
|
555
558
|
* completed-effect outputs namespaced under the effect's name. */
|
|
556
559
|
effectsContextMap: (instanceId: string) => Promise<Record<string, unknown>>;
|
|
557
560
|
/**
|
|
558
|
-
* Spawned children of `parentInstanceId`. If `
|
|
559
|
-
* only children spawned by that specific
|
|
561
|
+
* Spawned children of `parentInstanceId`. If `activity` is provided,
|
|
562
|
+
* only children spawned by that specific activity on the parent.
|
|
560
563
|
*
|
|
561
564
|
* Walks `history.spawned` entries on the parent — this is the durable
|
|
562
|
-
* record. (The per-
|
|
563
|
-
* open StageEntry's
|
|
565
|
+
* record. (The per-activity `spawnedInstances` field only lives on the
|
|
566
|
+
* open StageEntry's activities; history survives transitions.)
|
|
564
567
|
*
|
|
565
568
|
* Returns children ordered by `startedAt` ascending.
|
|
566
569
|
*/
|
|
567
570
|
children: (
|
|
568
571
|
parentInstanceId: string,
|
|
569
|
-
|
|
572
|
+
activity?: string,
|
|
570
573
|
) => Promise<WorkflowInstance[]>;
|
|
571
574
|
/**
|
|
572
575
|
* All workflow instances whose `doc.ref` field entry named
|
|
@@ -583,13 +586,18 @@ declare type ReadHelpers = {
|
|
|
583
586
|
* completed instances (`completedAt != null`) by default; set
|
|
584
587
|
* `{ openOnly: true }` to filter to in-flight only.
|
|
585
588
|
*/
|
|
586
|
-
instancesByStage: (
|
|
587
|
-
workflowName: string
|
|
588
|
-
stage: string
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
589
|
+
instancesByStage: (options: {
|
|
590
|
+
workflowName: string;
|
|
591
|
+
stage: string;
|
|
592
|
+
openOnly?: boolean;
|
|
593
|
+
}) => Promise<WorkflowInstance[]>;
|
|
594
|
+
/**
|
|
595
|
+
* Every in-flight instance whose reactive watch-set includes `document`
|
|
596
|
+
* (a resource-qualified GDR URI) — the reverse of the forward watch-set.
|
|
597
|
+
* Answers "which instances should this changed doc `tick`?" the way a
|
|
598
|
+
* non-reactive content forwarder needs. Sorted by `startedAt` ascending.
|
|
599
|
+
*/
|
|
600
|
+
instancesForDocument: (document: GdrUri) => Promise<WorkflowInstance[]>;
|
|
593
601
|
/** Snapshot of all documents in the store — for inspecting the world. */
|
|
594
602
|
snapshot: () => readonly StoreDocument[];
|
|
595
603
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ActivityStatus } from "@sanity/workflow-engine";
|
|
1
2
|
import { Actor } from "@sanity/workflow-engine";
|
|
2
3
|
import type { CompleteEffectArgs } from "@sanity/workflow-engine";
|
|
3
4
|
import { DeployDefinitionsArgs } from "@sanity/workflow-engine";
|
|
@@ -6,13 +7,13 @@ import { DispatchResult } from "@sanity/workflow-engine";
|
|
|
6
7
|
import type { EditFieldArgs } from "@sanity/workflow-engine";
|
|
7
8
|
import type { EvaluateArgs } from "@sanity/workflow-engine";
|
|
8
9
|
import type { FireActionArgs } from "@sanity/workflow-engine";
|
|
10
|
+
import { GdrUri } from "@sanity/workflow-engine";
|
|
9
11
|
import type { Grant } from "@sanity/workflow-engine";
|
|
10
12
|
import { MutationGuardAction } from "@sanity/workflow-engine";
|
|
11
13
|
import { MutationGuardDoc } from "@sanity/workflow-engine";
|
|
12
14
|
import type { OperationArgs } from "@sanity/workflow-engine";
|
|
13
15
|
import { PendingEffect } from "@sanity/workflow-engine";
|
|
14
16
|
import type { StartInstanceArgs } from "@sanity/workflow-engine";
|
|
15
|
-
import { TaskStatus } from "@sanity/workflow-engine";
|
|
16
17
|
import type { WorkflowAccess } from "@sanity/workflow-engine";
|
|
17
18
|
import { WorkflowEvaluation } from "@sanity/workflow-engine";
|
|
18
19
|
import { WorkflowInstance } from "@sanity/workflow-engine";
|
|
@@ -399,14 +400,12 @@ declare type GuardHelpers = {
|
|
|
399
400
|
* `as` routes the write through a token-scoped sibling so `identity()`
|
|
400
401
|
* resolves to that actor.
|
|
401
402
|
*/
|
|
402
|
-
editDocument: (
|
|
403
|
-
documentId: string
|
|
404
|
-
patch: Record<string, unknown
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
},
|
|
409
|
-
) => Promise<StoreDocument>;
|
|
403
|
+
editDocument: (opts: {
|
|
404
|
+
documentId: string;
|
|
405
|
+
patch: Record<string, unknown>;
|
|
406
|
+
action?: MutationGuardAction;
|
|
407
|
+
as?: Actor;
|
|
408
|
+
}) => Promise<StoreDocument>;
|
|
410
409
|
};
|
|
411
410
|
|
|
412
411
|
/** Result of a mutation when ids are requested for all affected documents. */
|
|
@@ -532,11 +531,15 @@ declare type QueryHelpers = {
|
|
|
532
531
|
* workflow?" — useful for filter debugging, UIs that mirror engine
|
|
533
532
|
* state, etc.
|
|
534
533
|
*/
|
|
535
|
-
queryInScope: <T = unknown>(
|
|
536
|
-
instanceId
|
|
537
|
-
groq
|
|
538
|
-
params
|
|
539
|
-
|
|
534
|
+
queryInScope: <T = unknown>({
|
|
535
|
+
instanceId,
|
|
536
|
+
groq,
|
|
537
|
+
params,
|
|
538
|
+
}: {
|
|
539
|
+
instanceId: string;
|
|
540
|
+
groq: string;
|
|
541
|
+
params?: Record<string, unknown>;
|
|
542
|
+
}) => Promise<T>;
|
|
540
543
|
};
|
|
541
544
|
|
|
542
545
|
declare type ReadHelpers = {
|
|
@@ -546,27 +549,27 @@ declare type ReadHelpers = {
|
|
|
546
549
|
currentStage: (instanceId: string) => Promise<string>;
|
|
547
550
|
/** Pending effects on an instance. */
|
|
548
551
|
pendingEffects: (instanceId: string) => Promise<PendingEffect[]>;
|
|
549
|
-
/** Status of a single
|
|
550
|
-
|
|
552
|
+
/** Status of a single activity on an instance, or undefined if missing. */
|
|
553
|
+
activityStatus: (
|
|
551
554
|
instanceId: string,
|
|
552
|
-
|
|
553
|
-
) => Promise<
|
|
555
|
+
activity: string,
|
|
556
|
+
) => Promise<ActivityStatus | undefined>;
|
|
554
557
|
/** The rendered `$effects` map — context entries keyed by `name`,
|
|
555
558
|
* completed-effect outputs namespaced under the effect's name. */
|
|
556
559
|
effectsContextMap: (instanceId: string) => Promise<Record<string, unknown>>;
|
|
557
560
|
/**
|
|
558
|
-
* Spawned children of `parentInstanceId`. If `
|
|
559
|
-
* only children spawned by that specific
|
|
561
|
+
* Spawned children of `parentInstanceId`. If `activity` is provided,
|
|
562
|
+
* only children spawned by that specific activity on the parent.
|
|
560
563
|
*
|
|
561
564
|
* Walks `history.spawned` entries on the parent — this is the durable
|
|
562
|
-
* record. (The per-
|
|
563
|
-
* open StageEntry's
|
|
565
|
+
* record. (The per-activity `spawnedInstances` field only lives on the
|
|
566
|
+
* open StageEntry's activities; history survives transitions.)
|
|
564
567
|
*
|
|
565
568
|
* Returns children ordered by `startedAt` ascending.
|
|
566
569
|
*/
|
|
567
570
|
children: (
|
|
568
571
|
parentInstanceId: string,
|
|
569
|
-
|
|
572
|
+
activity?: string,
|
|
570
573
|
) => Promise<WorkflowInstance[]>;
|
|
571
574
|
/**
|
|
572
575
|
* All workflow instances whose `doc.ref` field entry named
|
|
@@ -583,13 +586,18 @@ declare type ReadHelpers = {
|
|
|
583
586
|
* completed instances (`completedAt != null`) by default; set
|
|
584
587
|
* `{ openOnly: true }` to filter to in-flight only.
|
|
585
588
|
*/
|
|
586
|
-
instancesByStage: (
|
|
587
|
-
workflowName: string
|
|
588
|
-
stage: string
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
589
|
+
instancesByStage: (options: {
|
|
590
|
+
workflowName: string;
|
|
591
|
+
stage: string;
|
|
592
|
+
openOnly?: boolean;
|
|
593
|
+
}) => Promise<WorkflowInstance[]>;
|
|
594
|
+
/**
|
|
595
|
+
* Every in-flight instance whose reactive watch-set includes `document`
|
|
596
|
+
* (a resource-qualified GDR URI) — the reverse of the forward watch-set.
|
|
597
|
+
* Answers "which instances should this changed doc `tick`?" the way a
|
|
598
|
+
* non-reactive content forwarder needs. Sorted by `startedAt` ascending.
|
|
599
|
+
*/
|
|
600
|
+
instancesForDocument: (document: GdrUri) => Promise<WorkflowInstance[]>;
|
|
593
601
|
/** Snapshot of all documents in the store — for inspecting the world. */
|
|
594
602
|
snapshot: () => readonly StoreDocument[];
|
|
595
603
|
};
|
package/dist/index.js
CHANGED
|
@@ -5069,7 +5069,11 @@ function resolveBenchAccess(options) {
|
|
|
5069
5069
|
grants: options.grants ?? WILDCARD_GRANTS
|
|
5070
5070
|
};
|
|
5071
5071
|
}
|
|
5072
|
-
function accessFor(
|
|
5072
|
+
function accessFor({
|
|
5073
|
+
access,
|
|
5074
|
+
args,
|
|
5075
|
+
canTokenResolve
|
|
5076
|
+
}) {
|
|
5073
5077
|
if (args.access !== void 0) return args.access;
|
|
5074
5078
|
if (args.actor === void 0 && args.grants === void 0) return access;
|
|
5075
5079
|
const inheritedGrants = canTokenResolve ? void 0 : access.grants, grants = args.grants ?? inheritedGrants;
|
|
@@ -5082,10 +5086,14 @@ function stripAccessShortcuts(args) {
|
|
|
5082
5086
|
const rest = { ...args };
|
|
5083
5087
|
return delete rest.access, delete rest.actor, delete rest.grants, rest;
|
|
5084
5088
|
}
|
|
5085
|
-
function createEngineWrappers(
|
|
5089
|
+
function createEngineWrappers({
|
|
5090
|
+
scope,
|
|
5091
|
+
access,
|
|
5092
|
+
clock
|
|
5093
|
+
}) {
|
|
5086
5094
|
const canTokenResolve = "request" in scope.client, withAccess = (args) => ({
|
|
5087
5095
|
...scope,
|
|
5088
|
-
access: accessFor(access, args, canTokenResolve),
|
|
5096
|
+
access: accessFor({ access, args, canTokenResolve }),
|
|
5089
5097
|
clock,
|
|
5090
5098
|
...stripAccessShortcuts(args)
|
|
5091
5099
|
});
|
|
@@ -5117,8 +5125,8 @@ function createGuardHelpers(client) {
|
|
|
5117
5125
|
...as ? { identity: as.id } : {}
|
|
5118
5126
|
});
|
|
5119
5127
|
},
|
|
5120
|
-
editDocument: async (documentId, patch,
|
|
5121
|
-
const action =
|
|
5128
|
+
editDocument: async ({ documentId, patch, action: editAction, as }) => {
|
|
5129
|
+
const action = editAction ?? "update", writer = as ? client.withConfig({
|
|
5122
5130
|
accessControl: { currentUser: { id: as.id }, grants: WILDCARD_GRANTS }
|
|
5123
5131
|
}) : client;
|
|
5124
5132
|
return action === "delete" ? await writer.delete(documentId) : await writer.patch(documentId).set(patch).commit(), await client.getDocument(documentId);
|
|
@@ -5129,7 +5137,11 @@ function createQueryHelpers(scope) {
|
|
|
5129
5137
|
const withParams = (params) => params !== void 0 ? { params } : {};
|
|
5130
5138
|
return {
|
|
5131
5139
|
query: (groq, params) => workflow.query({ ...scope, groq, ...withParams(params) }),
|
|
5132
|
-
queryInScope: (
|
|
5140
|
+
queryInScope: ({
|
|
5141
|
+
instanceId,
|
|
5142
|
+
groq,
|
|
5143
|
+
params
|
|
5144
|
+
}) => workflow.queryInScope({ ...scope, instanceId, groq, ...withParams(params) })
|
|
5133
5145
|
};
|
|
5134
5146
|
}
|
|
5135
5147
|
function createReadHelpers(scope) {
|
|
@@ -5144,17 +5156,17 @@ function createReadHelpers(scope) {
|
|
|
5144
5156
|
getInstance,
|
|
5145
5157
|
currentStage: async (instanceId) => (await getInstance(instanceId)).currentStage,
|
|
5146
5158
|
pendingEffects: async (instanceId) => (await getInstance(instanceId)).pendingEffects,
|
|
5147
|
-
|
|
5159
|
+
activityStatus: async (instanceId, activity) => {
|
|
5148
5160
|
const instance = await getInstance(instanceId);
|
|
5149
5161
|
return instance.stages.find(
|
|
5150
5162
|
(s) => s.name === instance.currentStage && s.exitedAt === void 0
|
|
5151
|
-
)?.
|
|
5163
|
+
)?.activities.find((t) => t.name === activity)?.status;
|
|
5152
5164
|
},
|
|
5153
5165
|
effectsContextMap: async (instanceId) => effectsContextMap(await getInstance(instanceId)),
|
|
5154
|
-
children: async (parentInstanceId,
|
|
5166
|
+
children: async (parentInstanceId, activity) => workflow.children({
|
|
5155
5167
|
...scope,
|
|
5156
5168
|
instanceId: parentInstanceId,
|
|
5157
|
-
...
|
|
5169
|
+
...activity !== void 0 ? { activity } : {}
|
|
5158
5170
|
}),
|
|
5159
5171
|
instancesForSubject: async (subjectRef, entryName = "subject") => (
|
|
5160
5172
|
// Subjects live on a workflow-scope `doc.ref` field entry. Match
|
|
@@ -5168,21 +5180,26 @@ function createReadHelpers(scope) {
|
|
|
5168
5180
|
{ ref: subjectRef, entry: entryName, tag }
|
|
5169
5181
|
)
|
|
5170
5182
|
),
|
|
5171
|
-
instancesByStage: async (workflowName, stage,
|
|
5172
|
-
const filter =
|
|
5183
|
+
instancesByStage: async ({ workflowName, stage, openOnly }) => {
|
|
5184
|
+
const filter = openOnly ? " && completedAt == null" : "";
|
|
5173
5185
|
return client.fetch(
|
|
5174
5186
|
`*[_type == "${WORKFLOW_INSTANCE_TYPE}" && definition == $wf && currentStage == $stage && ${tagScopeFilter()}${filter}]
|
|
5175
5187
|
| order(startedAt asc)`,
|
|
5176
5188
|
{ wf: workflowName, stage, tag }
|
|
5177
5189
|
);
|
|
5178
5190
|
},
|
|
5191
|
+
instancesForDocument: async (document2) => workflow.instancesForDocument({ ...scope, document: document2 }),
|
|
5179
5192
|
snapshot: () => client.snapshot()
|
|
5180
5193
|
};
|
|
5181
5194
|
}
|
|
5182
5195
|
function createBench(options = {}) {
|
|
5183
5196
|
const tag = options.tag ?? "bench";
|
|
5184
5197
|
validateTag(tag);
|
|
5185
|
-
const workflowResource = options.workflowResource ?? DEFAULT_WORKFLOW_RESOURCE, client = resolveBenchClient(options), scope = {
|
|
5198
|
+
const workflowResource = options.workflowResource ?? DEFAULT_WORKFLOW_RESOURCE, client = resolveBenchClient(options), scope = {
|
|
5199
|
+
client,
|
|
5200
|
+
tag,
|
|
5201
|
+
workflowResource
|
|
5202
|
+
}, access = resolveBenchAccess(options);
|
|
5186
5203
|
let frozenNow = options.now !== void 0 ? assertIsoInstant(options.now) : void 0;
|
|
5187
5204
|
const clock = () => frozenNow ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
5188
5205
|
return {
|
|
@@ -5200,7 +5217,7 @@ function createBench(options = {}) {
|
|
|
5200
5217
|
throw new Error(`bench.advance: ms must be a finite number, got ${ms2}`);
|
|
5201
5218
|
frozenNow = new Date(Date.parse(frozenNow ?? (/* @__PURE__ */ new Date()).toISOString()) + ms2).toISOString();
|
|
5202
5219
|
},
|
|
5203
|
-
...createEngineWrappers(scope, access, clock),
|
|
5220
|
+
...createEngineWrappers({ scope, access, clock }),
|
|
5204
5221
|
...createReadHelpers(scope),
|
|
5205
5222
|
...createGuardHelpers(client),
|
|
5206
5223
|
...createQueryHelpers(scope)
|