@qualsoft/workflow-core 0.1.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/action-runner.d.ts +24 -0
- package/dist/action-runner.d.ts.map +1 -0
- package/dist/action-runner.js +16 -0
- package/dist/action-runner.js.map +1 -0
- package/dist/engine.d.ts +27 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +97 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/state-store.d.ts +7 -0
- package/dist/state-store.d.ts.map +1 -0
- package/dist/state-store.js +3 -0
- package/dist/state-store.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +51 -0
- package/dist/utils.js.map +1 -0
- package/package.json +19 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface ActionRunner {
|
|
2
|
+
sendEmail(payload: {
|
|
3
|
+
to: string;
|
|
4
|
+
subject: string;
|
|
5
|
+
body: string;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
httpRequest(payload: {
|
|
8
|
+
method: string;
|
|
9
|
+
url: string;
|
|
10
|
+
body?: unknown;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
scheduleTask(payload: {
|
|
14
|
+
runAt: string;
|
|
15
|
+
taskType: string;
|
|
16
|
+
payload: unknown;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export declare class NoopActionRunner implements ActionRunner {
|
|
20
|
+
sendEmail(): Promise<void>;
|
|
21
|
+
httpRequest(): Promise<void>;
|
|
22
|
+
scheduleTask(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=action-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-runner.d.ts","sourceRoot":"","sources":["../action-runner.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjF,WAAW,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvH,YAAY,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7F;AAED,qBAAa,gBAAiB,YAAW,YAAY;IAC7C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoopActionRunner = void 0;
|
|
4
|
+
class NoopActionRunner {
|
|
5
|
+
async sendEmail() {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
async httpRequest() {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
async scheduleTask() {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NoopActionRunner = NoopActionRunner;
|
|
16
|
+
//# sourceMappingURL=action-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-runner.js","sourceRoot":"","sources":["../action-runner.ts"],"names":[],"mappings":";;;AAMA,MAAa,gBAAgB;IAC3B,KAAK,CAAC,SAAS;QACb,OAAO;IACT,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO;IACT,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO;IACT,CAAC;CACF;AAZD,4CAYC"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ActionRunner } from './action-runner';
|
|
2
|
+
import { WorkflowStateStore } from './state-store';
|
|
3
|
+
import { StepWorkflowDefinition, WorkflowContext, WorkflowRecord } from './types';
|
|
4
|
+
export interface WorkflowEngineOptions {
|
|
5
|
+
stateStore: WorkflowStateStore;
|
|
6
|
+
actionRunner?: ActionRunner;
|
|
7
|
+
}
|
|
8
|
+
export interface WorkflowRunInput {
|
|
9
|
+
formId: string;
|
|
10
|
+
workflowId: string;
|
|
11
|
+
recordId: string;
|
|
12
|
+
actionId: string;
|
|
13
|
+
context?: WorkflowContext;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkflowRunResult {
|
|
16
|
+
updatedRecord: WorkflowRecord;
|
|
17
|
+
definition: StepWorkflowDefinition;
|
|
18
|
+
}
|
|
19
|
+
export declare class WorkflowEngine {
|
|
20
|
+
private options;
|
|
21
|
+
private actionRunner;
|
|
22
|
+
constructor(options: WorkflowEngineOptions);
|
|
23
|
+
run(input: WorkflowRunInput): Promise<WorkflowRunResult>;
|
|
24
|
+
private applyActions;
|
|
25
|
+
private buildWorkflowHistory;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,cAAc,EAEf,MAAM,SAAS,CAAC;AAGjB,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,cAAc,CAAC;IAC9B,UAAU,EAAE,sBAAsB,CAAC;CACpC;AAED,qBAAa,cAAc;IAGb,OAAO,CAAC,OAAO;IAF3B,OAAO,CAAC,YAAY,CAAe;gBAEf,OAAO,EAAE,qBAAqB;IAI5C,GAAG,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAmDhD,YAAY;IAqB1B,OAAO,CAAC,oBAAoB;CAyC7B"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowEngine = void 0;
|
|
4
|
+
const action_runner_1 = require("./action-runner");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
class WorkflowEngine {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
this.actionRunner = options.actionRunner ?? new action_runner_1.NoopActionRunner();
|
|
10
|
+
}
|
|
11
|
+
async run(input) {
|
|
12
|
+
const { formId, workflowId, recordId } = input;
|
|
13
|
+
const definition = await this.options.stateStore.getWorkflowDefinition(formId, workflowId);
|
|
14
|
+
if (!definition) {
|
|
15
|
+
throw new Error('Workflow definition not found.');
|
|
16
|
+
}
|
|
17
|
+
const record = await this.options.stateStore.getRecord(formId, recordId);
|
|
18
|
+
if (!record) {
|
|
19
|
+
throw new Error('Record not found.');
|
|
20
|
+
}
|
|
21
|
+
const steps = (0, utils_1.resolveSteps)(definition);
|
|
22
|
+
const currentStepId = record.statut ?? definition.initialState ?? steps[0]?.id;
|
|
23
|
+
const currentStep = (0, utils_1.findStep)(steps, currentStepId);
|
|
24
|
+
if (!currentStep) {
|
|
25
|
+
throw new Error('Current step not found.');
|
|
26
|
+
}
|
|
27
|
+
const action = currentStep.actions?.find(item => item.id === input.actionId);
|
|
28
|
+
if (!action) {
|
|
29
|
+
throw new Error('Action not allowed for current workflow.');
|
|
30
|
+
}
|
|
31
|
+
const nextStepId = action.defaultNextStepId;
|
|
32
|
+
const timestamp = input.context?.timestamp ?? new Date().toISOString();
|
|
33
|
+
const validatedBy = input.context?.user?.email ?? input.context?.user?.displayName ?? '';
|
|
34
|
+
const workflowHistory = this.buildWorkflowHistory(record.workflowHistory ?? [], currentStepId, nextStepId, action.label, validatedBy, timestamp);
|
|
35
|
+
const updatedRecord = {
|
|
36
|
+
...record,
|
|
37
|
+
statut: nextStepId,
|
|
38
|
+
workflowHistory
|
|
39
|
+
};
|
|
40
|
+
await this.options.stateStore.updateRecord(formId, recordId, {
|
|
41
|
+
statut: nextStepId,
|
|
42
|
+
workflowHistory
|
|
43
|
+
});
|
|
44
|
+
await this.applyActions(definition, currentStepId, action, input.context);
|
|
45
|
+
return { updatedRecord, definition };
|
|
46
|
+
}
|
|
47
|
+
async applyActions(definition, stepId, action, context) {
|
|
48
|
+
if (!context?.actions?.length) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (const item of context.actions) {
|
|
52
|
+
if (item.type === 'email') {
|
|
53
|
+
await this.actionRunner.sendEmail(item.payload);
|
|
54
|
+
}
|
|
55
|
+
else if (item.type === 'http') {
|
|
56
|
+
await this.actionRunner.httpRequest(item.payload);
|
|
57
|
+
}
|
|
58
|
+
else if (item.type === 'schedule') {
|
|
59
|
+
await this.actionRunner.scheduleTask(item.payload);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
buildWorkflowHistory(history, currentStepId, nextStepId, actionLabel, validatedBy, timestamp) {
|
|
64
|
+
const updated = history.map(entry => ({ ...entry }));
|
|
65
|
+
if (currentStepId) {
|
|
66
|
+
const index = [...updated].reverse().findIndex(entry => entry.stepId === currentStepId && !entry.exitedAt);
|
|
67
|
+
if (index >= 0) {
|
|
68
|
+
const targetIndex = updated.length - 1 - index;
|
|
69
|
+
updated[targetIndex] = {
|
|
70
|
+
...updated[targetIndex],
|
|
71
|
+
enteredAt: updated[targetIndex].enteredAt ?? timestamp,
|
|
72
|
+
exitedAt: timestamp,
|
|
73
|
+
validatedBy: validatedBy || updated[targetIndex].validatedBy,
|
|
74
|
+
actionLabel: actionLabel || updated[targetIndex].actionLabel
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
updated.push({
|
|
79
|
+
stepId: currentStepId,
|
|
80
|
+
enteredAt: timestamp,
|
|
81
|
+
exitedAt: timestamp,
|
|
82
|
+
validatedBy: validatedBy || undefined,
|
|
83
|
+
actionLabel: actionLabel || undefined
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (nextStepId) {
|
|
88
|
+
updated.push({
|
|
89
|
+
stepId: nextStepId,
|
|
90
|
+
enteredAt: timestamp
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return updated;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.WorkflowEngine = WorkflowEngine;
|
|
97
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../engine.ts"],"names":[],"mappings":";;;AAAA,mDAAiE;AAQjE,mCAAiD;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CAAC;gBACN,OAAO,CAAC,IAAI,CAAC;oBACX,MAAM,EAAE,aAAa;oBACrB,SAAS,EAAE,SAAS;oBACpB,QAAQ,EAAE,SAAS;oBACnB,WAAW,EAAE,WAAW,IAAI,SAAS;oBACrC,WAAW,EAAE,WAAW,IAAI,SAAS;iBACtC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC;gBACX,MAAM,EAAE,UAAU;gBAClB,SAAS,EAAE,SAAS;aACrB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAxHD,wCAwHC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./action-runner"), exports);
|
|
18
|
+
__exportStar(require("./engine"), exports);
|
|
19
|
+
__exportStar(require("./state-store"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,0CAAwB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StepWorkflowDefinition, WorkflowRecord } from './types';
|
|
2
|
+
export interface WorkflowStateStore {
|
|
3
|
+
getWorkflowDefinition(formId: string, workflowId: string): Promise<StepWorkflowDefinition | null>;
|
|
4
|
+
getRecord(formId: string, recordId: string): Promise<WorkflowRecord | null>;
|
|
5
|
+
updateRecord(formId: string, recordId: string, payload: Partial<WorkflowRecord>): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=state-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,WAAW,kBAAkB;IACjC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAClG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5E,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.js","sourceRoot":"","sources":["../state-store.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export type WorkflowActor = 'anyone' | 'creator' | 'designated' | 'role' | 'designatedField' | 'none';
|
|
2
|
+
export interface WorkflowStepAction {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
defaultNextStepId: string;
|
|
6
|
+
validationCriteria?: string;
|
|
7
|
+
conditionalRoutes: WorkflowConditionalRoute[];
|
|
8
|
+
}
|
|
9
|
+
export interface WorkflowConditionalRoute {
|
|
10
|
+
id: string;
|
|
11
|
+
condition: string;
|
|
12
|
+
nextStepId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkflowStepFieldConfig {
|
|
15
|
+
fieldId: string;
|
|
16
|
+
visible: boolean;
|
|
17
|
+
editable: boolean;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface WorkflowStep {
|
|
21
|
+
id: string;
|
|
22
|
+
label: string;
|
|
23
|
+
actor: WorkflowActor;
|
|
24
|
+
role?: string;
|
|
25
|
+
designatedUsers?: string[];
|
|
26
|
+
designatedFieldId?: string;
|
|
27
|
+
isFinal?: boolean;
|
|
28
|
+
fields: WorkflowStepFieldConfig[];
|
|
29
|
+
actions: WorkflowStepAction[];
|
|
30
|
+
}
|
|
31
|
+
export interface StepWorkflowDefinition {
|
|
32
|
+
id: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
formId?: string;
|
|
35
|
+
version?: string;
|
|
36
|
+
isActive?: boolean;
|
|
37
|
+
initialState?: string;
|
|
38
|
+
diagramSvg?: string;
|
|
39
|
+
states: Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
isFinal?: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
transitions: Array<{
|
|
45
|
+
from: string;
|
|
46
|
+
to: string;
|
|
47
|
+
actor: WorkflowActor;
|
|
48
|
+
role?: string;
|
|
49
|
+
}>;
|
|
50
|
+
steps?: WorkflowStep[];
|
|
51
|
+
}
|
|
52
|
+
export interface WorkflowStepHistoryEntry {
|
|
53
|
+
stepId: string;
|
|
54
|
+
enteredAt?: string;
|
|
55
|
+
exitedAt?: string;
|
|
56
|
+
validatedBy?: string;
|
|
57
|
+
actionLabel?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface WorkflowRecord {
|
|
60
|
+
id?: string;
|
|
61
|
+
statut?: string;
|
|
62
|
+
workflowHistory?: WorkflowStepHistoryEntry[];
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
}
|
|
65
|
+
export interface WorkflowUser {
|
|
66
|
+
id?: string;
|
|
67
|
+
email?: string;
|
|
68
|
+
displayName?: string;
|
|
69
|
+
roles?: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface WorkflowContext {
|
|
72
|
+
formId: string;
|
|
73
|
+
recordId: string;
|
|
74
|
+
workflowId: string;
|
|
75
|
+
user?: WorkflowUser;
|
|
76
|
+
timestamp?: string;
|
|
77
|
+
actions?: Array<{
|
|
78
|
+
type: 'email' | 'http' | 'schedule';
|
|
79
|
+
payload: unknown;
|
|
80
|
+
}>;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACrB,QAAQ,GACR,SAAS,GACT,YAAY,GACZ,MAAM,GACN,iBAAiB,GACjB,MAAM,CAAC;AAEX,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,C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ist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StepWorkflowDefinition, WorkflowStep, WorkflowStepAction } from './types';
|
|
2
|
+
export declare const resolveSteps: (definition: StepWorkflowDefinition) => WorkflowStep[];
|
|
3
|
+
export declare const findAction: (steps: WorkflowStep[], actionId: string) => {
|
|
4
|
+
step: WorkflowStep;
|
|
5
|
+
action: WorkflowStepAction;
|
|
6
|
+
} | null;
|
|
7
|
+
export declare const findStep: (steps: WorkflowStep[], stepId: string | undefined) => WorkflowStep | undefined;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnF,eAAO,MAAM,YAAY,GAAI,YAAY,sBAAsB,KAAG,YAAY,EAoC7E,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,YAAY,EAAE,EAAE,UAAU,MAAM,KAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,GAAG,IAQzH,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,YAAY,EAAE,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,YAAY,GAAG,SACpD,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findStep = exports.findAction = exports.resolveSteps = void 0;
|
|
4
|
+
const resolveSteps = (definition) => {
|
|
5
|
+
if (definition.steps?.length) {
|
|
6
|
+
return definition.steps;
|
|
7
|
+
}
|
|
8
|
+
const transitionsByFrom = new Map();
|
|
9
|
+
definition.transitions?.forEach(transition => {
|
|
10
|
+
const items = transitionsByFrom.get(transition.from) ?? [];
|
|
11
|
+
items.push(transition);
|
|
12
|
+
transitionsByFrom.set(transition.from, items);
|
|
13
|
+
});
|
|
14
|
+
return definition.states.map(state => {
|
|
15
|
+
const transitions = transitionsByFrom.get(state.id) ?? [];
|
|
16
|
+
const actions = state.isFinal
|
|
17
|
+
? []
|
|
18
|
+
: transitions.map((transition, index) => ({
|
|
19
|
+
id: `${state.id}-action-${index + 1}`,
|
|
20
|
+
label: `Vers ${transition.to}`,
|
|
21
|
+
defaultNextStepId: transition.to,
|
|
22
|
+
validationCriteria: '',
|
|
23
|
+
conditionalRoutes: []
|
|
24
|
+
}));
|
|
25
|
+
return {
|
|
26
|
+
id: state.id,
|
|
27
|
+
label: state.label,
|
|
28
|
+
isFinal: state.isFinal,
|
|
29
|
+
actor: transitions[0]?.actor ?? 'anyone',
|
|
30
|
+
role: transitions[0]?.role,
|
|
31
|
+
designatedUsers: [],
|
|
32
|
+
designatedFieldId: undefined,
|
|
33
|
+
fields: [],
|
|
34
|
+
actions
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.resolveSteps = resolveSteps;
|
|
39
|
+
const findAction = (steps, actionId) => {
|
|
40
|
+
for (const step of steps) {
|
|
41
|
+
const action = step.actions?.find(item => item.id === actionId);
|
|
42
|
+
if (action) {
|
|
43
|
+
return { step, action };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
exports.findAction = findAction;
|
|
49
|
+
const findStep = (steps, stepId) => steps.find(step => step.id === stepId);
|
|
50
|
+
exports.findStep = findStep;
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../utils.ts"],"names":[],"mappings":";;;AAEO,MAAM,YAAY,GAAG,CAAC,UAAkC,EAAkB,EAAE;IACjF,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,CAA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YACnB,iBAAiB,EAAE,SAAS;YAC5B,MAAM,EAAE,EAAE;YACV,OAAO;SACR,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AApCW,QAAA,YAAY,gBAoCvB;AAEK,MAAM,UAAU,GAAG,CAAC,KAAqB,EAAE,QAAgB,EAA6D,EAAE;IAC/H,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;QAChE,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AARW,QAAA,UAAU,cAQrB;AAEK,MAAM,QAAQ,GAAG,CAAC,KAAqB,EAAE,MAA0B,EAA4B,EAAE,CACtG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;AAD5B,QAAA,QAAQ,YACoB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qualsoft/workflow-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json",
|
|
14
|
+
"prepare": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^5.9.2"
|
|
18
|
+
}
|
|
19
|
+
}
|