Skip to content

storeWorkflow ​

Overview ​

A pinia store for the workflow transitions a user may run on each model and the workflow state history of each object. It also executes transitions.

An object's current state and the transitions available on it are fields of the object itself: workflow_state_code, workflow_state_name, and valid_transitions.

Signature ​

storeWorkflow(pinia, hot)

Parameters ​

NameTypeRequiredDescription
piniaPinianoPinia instance to retrieve the store
hotStoreGenericnodev only hot module replacement

Returns ​

Store

Examples ​

js
    import { computed, ref } from "vue";
    import { storeWorkflow } from "@vueda/stores/storeWorkflow.js";
    import { getAppModelDotName } from "@vueda/utils/case.js";
    const workflowStore = storeWorkflow();

    const app = ref("myApp");
    const model = ref("myModel");
    const objectPk = ref("myObjectPk");

    // the transitions the user may run on the model, and one object's state history
    await workflowStore.fetchWorkflowTransition(app.value, model.value);
    const history = await workflowStore.fetchObjectHistory(app.value, model.value, objectPk.value);

    // the same history, read reactively from the cache
    const cachedHistory = computed(
        () => workflowStore.objectHistories[getAppModelDotName({ app: app.value, model: model.value })]?.[objectPk.value],
    );

    await workflowStore.executeTransition(app.value, model.value, objectPk.value, "approve");

Properties ​

$id ​

Id of the store. Used by map helpers.

Type: "workflow"

Source: node_modules/.pnpm/pinia@3.0.4_typescript@5.9.3_vue@3.5.43_typescript@5.9.3_/node_modules/pinia/dist/pinia.d.ts:654

authScopeGeneration ​

Incremented by clearAuthScoped. Fetches capture it before issuing and discard their response if it changed while the request was in flight.

Type: number

Source: client/lib/stores/storeWorkflow.js:294

errors ​

The error from each failed fetch, in one bucket per cache. Later calls for the same key reject with this error instead of asking the server again.

Type: object

Source: client/lib/stores/storeWorkflow.js:262

objectHistories ​

The recorded workflow states of each fetched object, oldest first, keyed by app and model dot name, then by object primary key.

Type: object

Source: client/lib/stores/storeWorkflow.js:280

promises ​

The in-flight fetches, in one bucket per cache. Each object bucket is keyed by app and model dot name, then by object primary key. Each model bucket is keyed by app and model dot name. A fetch removes its entry when it settles.

Type: object

Source: client/lib/stores/storeWorkflow.js:273

workflowTransitions ​

The transitions the authenticated user is permitted to run on each fetched model, keyed by app and model dot name. The server does not check any particular object for this list.

Type: object

Source: client/lib/stores/storeWorkflow.js:287

Methods ​

  • clearAuthScoped - Drops every cached workflow response, because permitted transitions and state histories are both filtered for the authenticated user.
  • executeTransition - Runs a workflow transition on one object or on several objects in one request.
  • fetchObjectHistory - Fetches the recorded workflow states of one object and caches them in objectHistories.
  • fetchWorkflowTransition - Fetches the transitions the authenticated user is permitted to run on a model and caches them in workflowTransitions.

Source ​

client/lib/stores/storeWorkflow.js:245