assignment-user-matcher 1.2.0 → 1.2.2

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.
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeWorkflowDefinition = exports.validateWorkflowDefinition = void 0;
4
+ function ensureNonEmpty(value, message) {
5
+ if (!value?.trim()) {
6
+ throw new Error(message);
7
+ }
8
+ return value;
9
+ }
10
+ function validateStepBasics(step) {
11
+ ensureNonEmpty(step.id, 'Workflow step ID is required');
12
+ ensureNonEmpty(step.name, `Step "${step.id}" must have a name`);
13
+ if (typeof step.targetUser === 'object' && step.targetUser !== null && 'tag' in step.targetUser) {
14
+ ensureNonEmpty(step.targetUser.tag, `Step "${step.id}" must have a non-empty target tag`);
15
+ }
16
+ const taskType = step.taskType ?? 'assignment';
17
+ if (taskType === 'machine') {
18
+ ensureNonEmpty(step.machineTask?.handler, `Step "${step.id}" has taskType "machine" but no machineTask.handler`);
19
+ return;
20
+ }
21
+ if (!step.assignmentTemplate) {
22
+ throw new Error(`Assignment step "${step.id}" is missing assignmentTemplate`);
23
+ }
24
+ }
25
+ function validateWorkflowDefinition(definition) {
26
+ ensureNonEmpty(definition.id, 'Workflow ID is required');
27
+ ensureNonEmpty(definition.name, 'Workflow name is required');
28
+ if (!definition.steps.length) {
29
+ throw new Error('Workflow must have at least one step');
30
+ }
31
+ const stepIds = new Set();
32
+ for (const step of definition.steps) {
33
+ validateStepBasics(step);
34
+ if (stepIds.has(step.id)) {
35
+ throw new Error(`Duplicate workflow step ID "${step.id}"`);
36
+ }
37
+ stepIds.add(step.id);
38
+ }
39
+ ensureNonEmpty(definition.initialStepId, 'Workflow initial step ID is required');
40
+ if (!stepIds.has(definition.initialStepId)) {
41
+ throw new Error(`Initial step "${definition.initialStepId}" not found`);
42
+ }
43
+ for (const step of definition.steps) {
44
+ if (step.routing) {
45
+ for (const route of step.routing) {
46
+ if (!stepIds.has(route.targetStepId)) {
47
+ throw new Error(`Step "${step.id}" references non-existent step "${route.targetStepId}" in routing`);
48
+ }
49
+ }
50
+ }
51
+ if (step.defaultNextStepId && !stepIds.has(step.defaultNextStepId)) {
52
+ throw new Error(`Step "${step.id}" references non-existent step "${step.defaultNextStepId}" as default next`);
53
+ }
54
+ if (step.parallelStepIds) {
55
+ for (const parallelStepId of step.parallelStepIds) {
56
+ if (!stepIds.has(parallelStepId)) {
57
+ throw new Error(`Step "${step.id}" references non-existent parallel step "${parallelStepId}"`);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return definition;
63
+ }
64
+ exports.validateWorkflowDefinition = validateWorkflowDefinition;
65
+ function normalizeWorkflowDefinition(definition) {
66
+ const steps = [...definition.steps];
67
+ if (!steps.length) {
68
+ throw new Error('Workflow must have at least one step');
69
+ }
70
+ const normalized = {
71
+ id: definition.id,
72
+ name: definition.name,
73
+ version: definition.version ?? 1,
74
+ initialStepId: definition.initialStepId ?? steps[0].id,
75
+ steps,
76
+ };
77
+ if (definition.defaultTimeoutMs !== undefined) {
78
+ normalized.defaultTimeoutMs = definition.defaultTimeoutMs;
79
+ }
80
+ if (definition.metadata !== undefined) {
81
+ normalized.metadata = definition.metadata;
82
+ }
83
+ return validateWorkflowDefinition(normalized);
84
+ }
85
+ exports.normalizeWorkflowDefinition = normalizeWorkflowDefinition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assignment-user-matcher",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ViljarVoidula/assignment-user-matcher"
@@ -50,8 +50,10 @@
50
50
  },
51
51
  "scripts": {
52
52
  "test": "nyc mocha tests/ --recursive --extension .ts --exit",
53
+ "benchmark:learning": "ts-node benchmark-learning.ts",
53
54
  "build:docs": "npx typedoc --plugin typedoc-plugin-markdown",
54
55
  "prettier": "prettier --write .",
55
- "build": "rimraf dist && tsc"
56
+ "build": "rimraf dist && tsc",
57
+ "release:patch": "bash ./scripts/release-patch-local.sh.example"
56
58
  }
57
59
  }