@sanity/workflow-engine-test 0.2.0 → 0.3.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 CHANGED
@@ -5051,11 +5051,7 @@ function benchMutationGuard(getClient) {
5051
5051
  ...identity !== void 0 ? { identity } : {}
5052
5052
  });
5053
5053
  if (denied.length > 0)
5054
- throw new workflowEngine.MutationGuardDeniedError({
5055
- documentId: id,
5056
- action,
5057
- denied: denied.map((g) => ({ guardId: g._id, ...g.name ? { name: g.name } : {} }))
5058
- });
5054
+ throw workflowEngine.MutationGuardDeniedError.fromGuards({ documentId: id, action, guards: denied });
5059
5055
  };
5060
5056
  }
5061
5057
  function resolveBenchClient(options) {
@@ -5104,7 +5100,8 @@ function createEngineWrappers(scope, access, clock) {
5104
5100
  completeEffect: (args) => workflowEngine.workflow.completeEffect(withAccess(args)),
5105
5101
  tick: (args) => workflowEngine.workflow.tick(withAccess(args)),
5106
5102
  evaluate: (args) => workflowEngine.workflow.evaluate(withAccess(args)),
5107
- guardsForInstance: (instanceId) => workflowEngine.workflow.guardsForInstance({ ...scope, instanceId })
5103
+ guardsForInstance: (instanceId) => workflowEngine.workflow.guardsForInstance({ ...scope, instanceId }),
5104
+ guardsForDefinition: (definition) => workflowEngine.workflow.guardsForDefinition({ ...scope, definition })
5108
5105
  };
5109
5106
  }
5110
5107
  function createGuardHelpers(client) {
@@ -5148,42 +5145,38 @@ function createReadHelpers(scope) {
5148
5145
  };
5149
5146
  return {
5150
5147
  getInstance,
5151
- currentStage: async (instanceId) => (await getInstance(instanceId)).currentStageId,
5148
+ currentStage: async (instanceId) => (await getInstance(instanceId)).currentStage,
5152
5149
  pendingEffects: async (instanceId) => (await getInstance(instanceId)).pendingEffects,
5153
- taskStatus: async (instanceId, taskId) => {
5150
+ taskStatus: async (instanceId, task) => {
5154
5151
  const instance = await getInstance(instanceId);
5155
5152
  return instance.stages.find(
5156
- (s) => s.id === instance.currentStageId && s.exitedAt === void 0
5157
- )?.tasks.find((t) => t.id === taskId)?.status;
5158
- },
5159
- effectsContextMap: async (instanceId) => {
5160
- const instance = await getInstance(instanceId), map2 = {};
5161
- for (const entry of instance.effectsContext) map2[entry.id] = entry.value;
5162
- return map2;
5153
+ (s) => s.name === instance.currentStage && s.exitedAt === void 0
5154
+ )?.tasks.find((t) => t.name === task)?.status;
5163
5155
  },
5164
- children: async (parentInstanceId, taskId) => workflowEngine.workflow.children({
5156
+ effectsContextMap: async (instanceId) => workflowEngine.effectsContextMap(await getInstance(instanceId)),
5157
+ children: async (parentInstanceId, task) => workflowEngine.workflow.children({
5165
5158
  ...scope,
5166
5159
  instanceId: parentInstanceId,
5167
- ...taskId !== void 0 ? { taskId } : {}
5160
+ ...task !== void 0 ? { task } : {}
5168
5161
  }),
5169
- instancesForSubject: async (subjectRef, slotId = "subject") => (
5170
- // Subjects live on a workflow-scope `state[id == $slot]` doc.ref
5171
- // slot. Match instances whose slot's value.id equals the supplied
5172
- // ref. The slot id is conventionally "subject" but workflows may
5173
- // name it otherwise.
5162
+ instancesForSubject: async (subjectRef, entryName = "subject") => (
5163
+ // Subjects live on a workflow-scope `doc.ref` state entry. Match
5164
+ // instances whose entry's value.id equals the supplied ref. The
5165
+ // entry name is conventionally "subject" but workflows may name
5166
+ // it otherwise.
5174
5167
  client.fetch(
5175
- `*[_type == "workflow.instance"
5176
- && state[_type == "workflow.state.doc.ref" && id == $slot][0].value.id == $ref
5177
- && count(tags[@ in $engineTags]) > 0] | order(startedAt asc)`,
5178
- { ref: subjectRef, slot: slotId, engineTags: tags }
5168
+ `*[_type == "${workflowEngine.WORKFLOW_INSTANCE_TYPE}"
5169
+ && state[_type == "doc.ref" && name == $entry][0].value.id == $ref
5170
+ && ${workflowEngine.tagScopeFilter()}] | order(startedAt asc)`,
5171
+ { ref: subjectRef, entry: entryName, engineTags: tags }
5179
5172
  )
5180
5173
  ),
5181
- instancesByStage: async (workflowId, stageId, queryOptions) => {
5174
+ instancesByStage: async (workflowName, stage, queryOptions) => {
5182
5175
  const filter = queryOptions?.openOnly ? " && completedAt == null" : "";
5183
5176
  return client.fetch(
5184
- `*[_type == "workflow.instance" && workflowId == $wf && currentStageId == $stage && count(tags[@ in $engineTags]) > 0${filter}]
5177
+ `*[_type == "${workflowEngine.WORKFLOW_INSTANCE_TYPE}" && definition == $wf && currentStage == $stage && ${workflowEngine.tagScopeFilter()}${filter}]
5185
5178
  | order(startedAt asc)`,
5186
- { wf: workflowId, stage: stageId, engineTags: tags }
5179
+ { wf: workflowName, stage, engineTags: tags }
5187
5180
  );
5188
5181
  },
5189
5182
  snapshot: () => client.snapshot()