@sanity/workflow-engine-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.d.cts CHANGED
@@ -400,14 +400,12 @@ declare type GuardHelpers = {
400
400
  * `as` routes the write through a token-scoped sibling so `identity()`
401
401
  * resolves to that actor.
402
402
  */
403
- editDocument: (
404
- documentId: string,
405
- patch: Record<string, unknown>,
406
- options?: {
407
- action?: MutationGuardAction;
408
- as?: Actor;
409
- },
410
- ) => Promise<StoreDocument>;
403
+ editDocument: (opts: {
404
+ documentId: string;
405
+ patch: Record<string, unknown>;
406
+ action?: MutationGuardAction;
407
+ as?: Actor;
408
+ }) => Promise<StoreDocument>;
411
409
  };
412
410
 
413
411
  /** Result of a mutation when ids are requested for all affected documents. */
@@ -533,11 +531,15 @@ declare type QueryHelpers = {
533
531
  * workflow?" — useful for filter debugging, UIs that mirror engine
534
532
  * state, etc.
535
533
  */
536
- queryInScope: <T = unknown>(
537
- instanceId: string,
538
- groq: string,
539
- params?: Record<string, unknown>,
540
- ) => Promise<T>;
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>;
541
543
  };
542
544
 
543
545
  declare type ReadHelpers = {
@@ -584,13 +586,11 @@ declare type ReadHelpers = {
584
586
  * completed instances (`completedAt != null`) by default; set
585
587
  * `{ openOnly: true }` to filter to in-flight only.
586
588
  */
587
- instancesByStage: (
588
- workflowName: string,
589
- stage: string,
590
- options?: {
591
- openOnly?: boolean;
592
- },
593
- ) => Promise<WorkflowInstance[]>;
589
+ instancesByStage: (options: {
590
+ workflowName: string;
591
+ stage: string;
592
+ openOnly?: boolean;
593
+ }) => Promise<WorkflowInstance[]>;
594
594
  /**
595
595
  * Every in-flight instance whose reactive watch-set includes `document`
596
596
  * (a resource-qualified GDR URI) — the reverse of the forward watch-set.
package/dist/index.d.ts CHANGED
@@ -400,14 +400,12 @@ declare type GuardHelpers = {
400
400
  * `as` routes the write through a token-scoped sibling so `identity()`
401
401
  * resolves to that actor.
402
402
  */
403
- editDocument: (
404
- documentId: string,
405
- patch: Record<string, unknown>,
406
- options?: {
407
- action?: MutationGuardAction;
408
- as?: Actor;
409
- },
410
- ) => Promise<StoreDocument>;
403
+ editDocument: (opts: {
404
+ documentId: string;
405
+ patch: Record<string, unknown>;
406
+ action?: MutationGuardAction;
407
+ as?: Actor;
408
+ }) => Promise<StoreDocument>;
411
409
  };
412
410
 
413
411
  /** Result of a mutation when ids are requested for all affected documents. */
@@ -533,11 +531,15 @@ declare type QueryHelpers = {
533
531
  * workflow?" — useful for filter debugging, UIs that mirror engine
534
532
  * state, etc.
535
533
  */
536
- queryInScope: <T = unknown>(
537
- instanceId: string,
538
- groq: string,
539
- params?: Record<string, unknown>,
540
- ) => Promise<T>;
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>;
541
543
  };
542
544
 
543
545
  declare type ReadHelpers = {
@@ -584,13 +586,11 @@ declare type ReadHelpers = {
584
586
  * completed instances (`completedAt != null`) by default; set
585
587
  * `{ openOnly: true }` to filter to in-flight only.
586
588
  */
587
- instancesByStage: (
588
- workflowName: string,
589
- stage: string,
590
- options?: {
591
- openOnly?: boolean;
592
- },
593
- ) => Promise<WorkflowInstance[]>;
589
+ instancesByStage: (options: {
590
+ workflowName: string;
591
+ stage: string;
592
+ openOnly?: boolean;
593
+ }) => Promise<WorkflowInstance[]>;
594
594
  /**
595
595
  * Every in-flight instance whose reactive watch-set includes `document`
596
596
  * (a resource-qualified GDR URI) — the reverse of the forward watch-set.
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(access, args, canTokenResolve) {
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(scope, access, clock) {
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, editOptions) => {
5121
- const action = editOptions?.action ?? "update", as = editOptions?.as, writer = as ? client.withConfig({
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: (instanceId, groq, params) => workflow.queryInScope({ ...scope, instanceId, groq, ...withParams(params) })
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) {
@@ -5168,8 +5180,8 @@ function createReadHelpers(scope) {
5168
5180
  { ref: subjectRef, entry: entryName, tag }
5169
5181
  )
5170
5182
  ),
5171
- instancesByStage: async (workflowName, stage, queryOptions) => {
5172
- const filter = queryOptions?.openOnly ? " && completedAt == null" : "";
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)`,
@@ -5183,7 +5195,11 @@ function createReadHelpers(scope) {
5183
5195
  function createBench(options = {}) {
5184
5196
  const tag = options.tag ?? "bench";
5185
5197
  validateTag(tag);
5186
- const workflowResource = options.workflowResource ?? DEFAULT_WORKFLOW_RESOURCE, client = resolveBenchClient(options), scope = { client, tag, workflowResource }, access = resolveBenchAccess(options);
5198
+ const workflowResource = options.workflowResource ?? DEFAULT_WORKFLOW_RESOURCE, client = resolveBenchClient(options), scope = {
5199
+ client,
5200
+ tag,
5201
+ workflowResource
5202
+ }, access = resolveBenchAccess(options);
5187
5203
  let frozenNow = options.now !== void 0 ? assertIsoInstant(options.now) : void 0;
5188
5204
  const clock = () => frozenNow ?? (/* @__PURE__ */ new Date()).toISOString();
5189
5205
  return {
@@ -5201,7 +5217,7 @@ function createBench(options = {}) {
5201
5217
  throw new Error(`bench.advance: ms must be a finite number, got ${ms2}`);
5202
5218
  frozenNow = new Date(Date.parse(frozenNow ?? (/* @__PURE__ */ new Date()).toISOString()) + ms2).toISOString();
5203
5219
  },
5204
- ...createEngineWrappers(scope, access, clock),
5220
+ ...createEngineWrappers({ scope, access, clock }),
5205
5221
  ...createReadHelpers(scope),
5206
5222
  ...createGuardHelpers(client),
5207
5223
  ...createQueryHelpers(scope)