API Reference
classes
Shaclflow

@coasys/ad4m / Exports / SHACLFlow

Class: SHACLFlow

SHACL Flow - represents a state machine for AD4M expressions

Flows define:

  • Which expressions can enter the flow (flowable condition)
  • What states exist and how to detect them (via link patterns)
  • How to transition between states (via actions)

Example

const todoFlow = new SHACLFlow('todo://TODO', 'todo://');
 
// Any expression can become a TODO
todoFlow.flowable = 'any';
 
// Define states
todoFlow.addState({
  name: 'ready',
  value: 0,
  stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
});
todoFlow.addState({
  name: 'doing', 
  value: 0.5,
  stateCheck: { predicate: 'todo://state', target: 'todo://doing' }
});
todoFlow.addState({
  name: 'done',
  value: 1,
  stateCheck: { predicate: 'todo://state', target: 'todo://done' }
});
 
// Define start action
todoFlow.startAction = [{
  action: 'addLink',
  source: 'this',
  predicate: 'todo://state',
  target: 'todo://ready'
}];
 
// Define transitions
todoFlow.addTransition({
  actionName: 'Start',
  fromState: 'ready',
  toState: 'doing',
  actions: [
    { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' },
    { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
  ]
});
 
// Store in perspective
await perspective.addFlow('TODO', todoFlow);

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new SHACLFlow(name, namespace)

Create a new SHACL Flow

Parameters

NameTypeDescription
namestringFlow name (e.g., "TODO")
namespacestringNamespace for URIs (e.g., "todo://")

Defined in

shacl/SHACLFlow.ts:135 (opens in a new tab)

Properties

_states

Private _states: FlowState[] = []

States in this flow

Defined in

shacl/SHACLFlow.ts:125 (opens in a new tab)


_transitions

Private _transitions: FlowTransition[] = []

Transitions between states

Defined in

shacl/SHACLFlow.ts:128 (opens in a new tab)


flowable

flowable: FlowableCondition = "any"

Condition for which expressions can start this flow

Defined in

shacl/SHACLFlow.ts:119 (opens in a new tab)


name

name: string

Flow name (e.g., "TODO")

Defined in

shacl/SHACLFlow.ts:113 (opens in a new tab)


namespace

namespace: string

Namespace for generated URIs

Defined in

shacl/SHACLFlow.ts:116 (opens in a new tab)


startAction

startAction: AD4MAction[] = []

Actions to execute when starting the flow

Defined in

shacl/SHACLFlow.ts:122 (opens in a new tab)

Accessors

flowUri

get flowUri(): string

Get the flow shape URI

Returns

string

Defined in

shacl/SHACLFlow.ts:169 (opens in a new tab)


states

get states(): FlowState[]

Get all states

Returns

FlowState[]

Defined in

shacl/SHACLFlow.ts:141 (opens in a new tab)


transitions

get transitions(): FlowTransition[]

Get all transitions

Returns

FlowTransition[]

Defined in

shacl/SHACLFlow.ts:146 (opens in a new tab)

Methods

addState

addState(state): void

Add a state to the flow

Parameters

NameTypeDescription
stateFlowStateState definition

Returns

void

Defined in

shacl/SHACLFlow.ts:154 (opens in a new tab)


addTransition

addTransition(transition): void

Add a transition to the flow

Parameters

NameTypeDescription
transitionFlowTransitionTransition definition

Returns

void

Defined in

shacl/SHACLFlow.ts:162 (opens in a new tab)


stateUri

stateUri(stateName): string

Get a state URI

Parameters

NameType
stateNamestring

Returns

string

Defined in

shacl/SHACLFlow.ts:176 (opens in a new tab)


toJSON

toJSON(): object

Convert to JSON representation

Returns

object

Defined in

shacl/SHACLFlow.ts:477 (opens in a new tab)


toLinks

toLinks(): Link[]

Serialize the flow to AD4M links These links can be stored in a perspective and queried via SurrealDB

Returns

Link[]

Array of Link objects representing the flow

Defined in

shacl/SHACLFlow.ts:193 (opens in a new tab)


transitionUri

transitionUri(fromState, toState): string

Get a transition URI

Parameters

NameType
fromStatestring
toStatestring

Returns

string

Defined in

shacl/SHACLFlow.ts:183 (opens in a new tab)


fromJSON

Static fromJSON(json): SHACLFlow

Create from JSON representation

Parameters

NameType
jsonany

Returns

SHACLFlow

Defined in

shacl/SHACLFlow.ts:491 (opens in a new tab)


fromLinks

Static fromLinks(links, flowUri): SHACLFlow

Reconstruct a SHACLFlow from links

Parameters

NameTypeDescription
linksLink[]Array of links containing the flow definition
flowUristringThe URI of the flow to reconstruct

Returns

SHACLFlow

Reconstructed SHACLFlow

Defined in

shacl/SHACLFlow.ts:334 (opens in a new tab)