@lssm/lib.workflow-composer 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406
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/composer.js +28 -1
- package/dist/index.js +7 -1
- package/dist/injector.js +72 -1
- package/dist/merger.js +7 -1
- package/dist/templates.js +17 -1
- package/dist/validator.js +36 -1
- package/package.json +4 -4
package/dist/composer.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
import{applyWorkflowExtension
|
|
1
|
+
import { applyWorkflowExtension } from "./injector.js";
|
|
2
|
+
|
|
3
|
+
//#region src/composer.ts
|
|
4
|
+
var WorkflowComposer = class {
|
|
5
|
+
extensions = [];
|
|
6
|
+
register(extension) {
|
|
7
|
+
this.extensions.push(extension);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
registerMany(extensions) {
|
|
11
|
+
extensions.forEach((extension) => this.register(extension));
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
compose(params) {
|
|
15
|
+
return this.extensions.filter((extension) => matches(params, extension)).sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0)).reduce((acc, extension) => applyWorkflowExtension(acc, extension), params.base);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function matches(params, extension) {
|
|
19
|
+
if (extension.workflow !== params.base.meta.name) return false;
|
|
20
|
+
if (extension.baseVersion && extension.baseVersion !== params.base.meta.version) return false;
|
|
21
|
+
if (extension.tenantId && extension.tenantId !== params.tenantId) return false;
|
|
22
|
+
if (extension.role && extension.role !== params.role) return false;
|
|
23
|
+
if (extension.device && extension.device !== params.device) return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { WorkflowComposer };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { approvalStepTemplate } from "./templates.js";
|
|
2
|
+
import { validateExtension } from "./validator.js";
|
|
3
|
+
import { applyWorkflowExtension } from "./injector.js";
|
|
4
|
+
import { WorkflowComposer } from "./composer.js";
|
|
5
|
+
import { mergeExtensions } from "./merger.js";
|
|
6
|
+
|
|
7
|
+
export { WorkflowComposer, applyWorkflowExtension, approvalStepTemplate, mergeExtensions, validateExtension };
|
package/dist/injector.js
CHANGED
|
@@ -1 +1,72 @@
|
|
|
1
|
-
import{validateExtension
|
|
1
|
+
import { validateExtension } from "./validator.js";
|
|
2
|
+
|
|
3
|
+
//#region src/injector.ts
|
|
4
|
+
function applyWorkflowExtension(base, extension) {
|
|
5
|
+
validateExtension(extension, base);
|
|
6
|
+
const spec = cloneWorkflowSpec(base);
|
|
7
|
+
const steps = [...spec.definition.steps];
|
|
8
|
+
let transitions = [...spec.definition.transitions];
|
|
9
|
+
const hiddenSet = new Set(extension.hiddenSteps ?? []);
|
|
10
|
+
hiddenSet.forEach((stepId) => {
|
|
11
|
+
const idx = steps.findIndex((step) => step.id === stepId);
|
|
12
|
+
if (idx !== -1) steps.splice(idx, 1);
|
|
13
|
+
});
|
|
14
|
+
if (hiddenSet.size) transitions = transitions.filter((transition) => !hiddenSet.has(transition.from) && !hiddenSet.has(transition.to));
|
|
15
|
+
extension.customSteps?.forEach((injection) => {
|
|
16
|
+
insertStep(steps, injection);
|
|
17
|
+
wireTransitions(transitions, injection);
|
|
18
|
+
});
|
|
19
|
+
spec.definition.steps = steps;
|
|
20
|
+
spec.definition.transitions = dedupeTransitions(transitions);
|
|
21
|
+
spec.meta = {
|
|
22
|
+
...spec.meta,
|
|
23
|
+
version: spec.meta.version
|
|
24
|
+
};
|
|
25
|
+
return spec;
|
|
26
|
+
}
|
|
27
|
+
function insertStep(steps, injection) {
|
|
28
|
+
const anchorIndex = resolveAnchorIndex(steps, injection);
|
|
29
|
+
if (anchorIndex === -1) throw new Error(`Unable to place injected step "${injection.inject.id}"`);
|
|
30
|
+
steps.splice(anchorIndex, 0, { ...injection.inject });
|
|
31
|
+
}
|
|
32
|
+
function resolveAnchorIndex(steps, injection) {
|
|
33
|
+
if (injection.after) {
|
|
34
|
+
const idx = steps.findIndex((step) => step.id === injection.after);
|
|
35
|
+
return idx === -1 ? -1 : idx + 1;
|
|
36
|
+
}
|
|
37
|
+
if (injection.before) {
|
|
38
|
+
const idx = steps.findIndex((step) => step.id === injection.before);
|
|
39
|
+
return idx === -1 ? -1 : idx;
|
|
40
|
+
}
|
|
41
|
+
return steps.length;
|
|
42
|
+
}
|
|
43
|
+
function wireTransitions(transitions, injection) {
|
|
44
|
+
if (!injection.inject.id) return;
|
|
45
|
+
if (injection.transitionFrom) transitions.push({
|
|
46
|
+
from: injection.transitionFrom,
|
|
47
|
+
to: injection.inject.id,
|
|
48
|
+
condition: injection.when
|
|
49
|
+
});
|
|
50
|
+
if (injection.transitionTo) transitions.push({
|
|
51
|
+
from: injection.inject.id,
|
|
52
|
+
to: injection.transitionTo,
|
|
53
|
+
condition: injection.when
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function dedupeTransitions(transitions) {
|
|
57
|
+
const seen = /* @__PURE__ */ new Set();
|
|
58
|
+
const result = [];
|
|
59
|
+
transitions.forEach((transition) => {
|
|
60
|
+
const key = `${transition.from}->${transition.to}:${transition.condition ?? ""}`;
|
|
61
|
+
if (seen.has(key)) return;
|
|
62
|
+
seen.add(key);
|
|
63
|
+
result.push(transition);
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function cloneWorkflowSpec(spec) {
|
|
68
|
+
return JSON.parse(JSON.stringify(spec));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { applyWorkflowExtension };
|
package/dist/merger.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/merger.ts
|
|
2
|
+
function mergeExtensions(extensions) {
|
|
3
|
+
return extensions.sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { mergeExtensions };
|
package/dist/templates.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/templates.ts
|
|
2
|
+
function approvalStepTemplate(options) {
|
|
3
|
+
return {
|
|
4
|
+
id: options.id,
|
|
5
|
+
label: options.label,
|
|
6
|
+
type: options.type ?? "human",
|
|
7
|
+
description: options.description ?? "Tenant-specific approval",
|
|
8
|
+
action: options.action,
|
|
9
|
+
guard: options.guardExpression ? {
|
|
10
|
+
type: "expression",
|
|
11
|
+
value: options.guardExpression
|
|
12
|
+
} : void 0
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { approvalStepTemplate };
|
package/dist/validator.js
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/validator.ts
|
|
2
|
+
function validateExtension(extension, base) {
|
|
3
|
+
const issues = [];
|
|
4
|
+
const stepIds = new Set(base.definition.steps.map((step) => step.id));
|
|
5
|
+
extension.customSteps?.forEach((injection, idx) => {
|
|
6
|
+
if (!injection.inject.id) issues.push({
|
|
7
|
+
code: "workflow.extension.step.id",
|
|
8
|
+
message: `customSteps[${idx}] is missing an id`
|
|
9
|
+
});
|
|
10
|
+
if (!injection.after && !injection.before) issues.push({
|
|
11
|
+
code: "workflow.extension.step.anchor",
|
|
12
|
+
message: `customSteps[${idx}] must set after or before`
|
|
13
|
+
});
|
|
14
|
+
if (injection.after && !stepIds.has(injection.after)) issues.push({
|
|
15
|
+
code: "workflow.extension.step.after",
|
|
16
|
+
message: `customSteps[${idx}] references unknown step "${injection.after}"`
|
|
17
|
+
});
|
|
18
|
+
if (injection.before && !stepIds.has(injection.before)) issues.push({
|
|
19
|
+
code: "workflow.extension.step.before",
|
|
20
|
+
message: `customSteps[${idx}] references unknown step "${injection.before}"`
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
extension.hiddenSteps?.forEach((stepId) => {
|
|
24
|
+
if (!stepIds.has(stepId)) issues.push({
|
|
25
|
+
code: "workflow.extension.hidden-step",
|
|
26
|
+
message: `hidden step "${stepId}" does not exist`
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
if (issues.length) {
|
|
30
|
+
const reason = issues.map((issue) => `${issue.code}: ${issue.message}`).join("; ");
|
|
31
|
+
throw new Error(`Invalid workflow extension for ${extension.workflow}: ${reason}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { validateExtension };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.workflow-composer",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251217072406",
|
|
4
4
|
"description": "Tenant-aware workflow composition helpers for ContractSpec.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"test": "bun run"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lssm/lib.contracts": "0.0.0-canary-
|
|
27
|
+
"@lssm/lib.contracts": "0.0.0-canary-20251217072406"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@lssm/tool.tsdown": "0.0.0-canary-
|
|
31
|
-
"@lssm/tool.typescript": "0.0.0-canary-
|
|
30
|
+
"@lssm/tool.tsdown": "0.0.0-canary-20251217072406",
|
|
31
|
+
"@lssm/tool.typescript": "0.0.0-canary-20251217072406",
|
|
32
32
|
"tsdown": "^0.17.4",
|
|
33
33
|
"typescript": "^5.9.3"
|
|
34
34
|
},
|