assignment-user-matcher 1.8.0 → 1.10.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/README.md +240 -12
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/matcher.class.d.ts +44 -2
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +393 -4
- package/dist/queries/pagination.d.ts +5 -1
- package/dist/queries/pagination.d.ts.map +1 -1
- package/dist/queries/pagination.js +14 -3
- package/dist/schedule/policy.d.ts +35 -0
- package/dist/schedule/policy.d.ts.map +1 -0
- package/dist/schedule/policy.js +62 -0
- package/dist/scheduling/constraints/availability.d.ts +44 -0
- package/dist/scheduling/constraints/availability.d.ts.map +1 -0
- package/dist/scheduling/constraints/availability.js +142 -0
- package/dist/scheduling/constraints/consecutive.d.ts +25 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -0
- package/dist/scheduling/constraints/consecutive.js +215 -0
- package/dist/scheduling/constraints/constraint.d.ts +35 -0
- package/dist/scheduling/constraints/constraint.d.ts.map +1 -0
- package/dist/scheduling/constraints/constraint.js +97 -0
- package/dist/scheduling/constraints/contract.d.ts +21 -0
- package/dist/scheduling/constraints/contract.d.ts.map +1 -0
- package/dist/scheduling/constraints/contract.js +106 -0
- package/dist/scheduling/constraints/cost.d.ts +18 -0
- package/dist/scheduling/constraints/cost.d.ts.map +1 -0
- package/dist/scheduling/constraints/cost.js +65 -0
- package/dist/scheduling/constraints/daily-rest.d.ts +22 -0
- package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/daily-rest.js +118 -0
- package/dist/scheduling/constraints/duty-quota.d.ts +20 -0
- package/dist/scheduling/constraints/duty-quota.d.ts.map +1 -0
- package/dist/scheduling/constraints/duty-quota.js +95 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts +28 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts.map +1 -0
- package/dist/scheduling/constraints/engagement-floor.js +79 -0
- package/dist/scheduling/constraints/fairness.d.ts +34 -0
- package/dist/scheduling/constraints/fairness.d.ts.map +1 -0
- package/dist/scheduling/constraints/fairness.js +149 -0
- package/dist/scheduling/constraints/group-composition.d.ts +19 -0
- package/dist/scheduling/constraints/group-composition.d.ts.map +1 -0
- package/dist/scheduling/constraints/group-composition.js +92 -0
- package/dist/scheduling/constraints/hour-budget.d.ts +13 -0
- package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -0
- package/dist/scheduling/constraints/hour-budget.js +59 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts +24 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -0
- package/dist/scheduling/constraints/in-shift-breaks.js +97 -0
- package/dist/scheduling/constraints/intervals.d.ts +5 -0
- package/dist/scheduling/constraints/intervals.d.ts.map +1 -0
- package/dist/scheduling/constraints/intervals.js +17 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts +7 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts.map +1 -0
- package/dist/scheduling/constraints/max-shift-duration.js +38 -0
- package/dist/scheduling/constraints/min-rest.d.ts +22 -0
- package/dist/scheduling/constraints/min-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-rest.js +60 -0
- package/dist/scheduling/constraints/min-staffing.d.ts +14 -0
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-staffing.js +59 -0
- package/dist/scheduling/constraints/night-work.d.ts +24 -0
- package/dist/scheduling/constraints/night-work.d.ts.map +1 -0
- package/dist/scheduling/constraints/night-work.js +163 -0
- package/dist/scheduling/constraints/no-overlap.d.ts +7 -0
- package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
- package/dist/scheduling/constraints/no-overlap.js +36 -0
- package/dist/scheduling/constraints/notice.d.ts +44 -0
- package/dist/scheduling/constraints/notice.d.ts.map +1 -0
- package/dist/scheduling/constraints/notice.js +140 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts +7 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts.map +1 -0
- package/dist/scheduling/constraints/one-shift-per-day.js +35 -0
- package/dist/scheduling/constraints/overtime.d.ts +47 -0
- package/dist/scheduling/constraints/overtime.d.ts.map +1 -0
- package/dist/scheduling/constraints/overtime.js +149 -0
- package/dist/scheduling/constraints/protections.d.ts +21 -0
- package/dist/scheduling/constraints/protections.d.ts.map +1 -0
- package/dist/scheduling/constraints/protections.js +93 -0
- package/dist/scheduling/constraints/qualification.d.ts +18 -0
- package/dist/scheduling/constraints/qualification.d.ts.map +1 -0
- package/dist/scheduling/constraints/qualification.js +78 -0
- package/dist/scheduling/constraints/rest-days.d.ts +30 -0
- package/dist/scheduling/constraints/rest-days.d.ts.map +1 -0
- package/dist/scheduling/constraints/rest-days.js +133 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts +24 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -0
- package/dist/scheduling/constraints/rolling-hours.js +147 -0
- package/dist/scheduling/constraints/start-interval.d.ts +20 -0
- package/dist/scheduling/constraints/start-interval.d.ts.map +1 -0
- package/dist/scheduling/constraints/start-interval.js +53 -0
- package/dist/scheduling/constraints/support.d.ts +48 -0
- package/dist/scheduling/constraints/support.d.ts.map +1 -0
- package/dist/scheduling/constraints/support.js +97 -0
- package/dist/scheduling/constraints/time-off.d.ts +7 -0
- package/dist/scheduling/constraints/time-off.d.ts.map +1 -0
- package/dist/scheduling/constraints/time-off.js +42 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts +22 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/weekly-rest.js +92 -0
- package/dist/scheduling/cost.d.ts +56 -0
- package/dist/scheduling/cost.d.ts.map +1 -0
- package/dist/scheduling/cost.js +120 -0
- package/dist/scheduling/engine/construction.d.ts +22 -0
- package/dist/scheduling/engine/construction.d.ts.map +1 -0
- package/dist/scheduling/engine/construction.js +97 -0
- package/dist/scheduling/engine/explain.d.ts +12 -0
- package/dist/scheduling/engine/explain.d.ts.map +1 -0
- package/dist/scheduling/engine/explain.js +24 -0
- package/dist/scheduling/engine/objective.d.ts +73 -0
- package/dist/scheduling/engine/objective.d.ts.map +1 -0
- package/dist/scheduling/engine/objective.js +164 -0
- package/dist/scheduling/engine/prng.d.ts +5 -0
- package/dist/scheduling/engine/prng.d.ts.map +1 -0
- package/dist/scheduling/engine/prng.js +24 -0
- package/dist/scheduling/engine/propagation.d.ts +19 -0
- package/dist/scheduling/engine/propagation.d.ts.map +1 -0
- package/dist/scheduling/engine/propagation.js +40 -0
- package/dist/scheduling/engine/search.d.ts +50 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -0
- package/dist/scheduling/engine/search.js +127 -0
- package/dist/scheduling/engine/state.d.ts +28 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -0
- package/dist/scheduling/engine/state.js +96 -0
- package/dist/scheduling/engine/timeline.d.ts +179 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -0
- package/dist/scheduling/engine/timeline.js +416 -0
- package/dist/scheduling/engine/verdicts.d.ts +18 -0
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -0
- package/dist/scheduling/engine/verdicts.js +74 -0
- package/dist/scheduling/index.d.ts +10 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +29 -0
- package/dist/scheduling/model.d.ts +53 -0
- package/dist/scheduling/model.d.ts.map +1 -0
- package/dist/scheduling/model.js +379 -0
- package/dist/scheduling/operations.d.ts +134 -0
- package/dist/scheduling/operations.d.ts.map +1 -0
- package/dist/scheduling/operations.js +376 -0
- package/dist/scheduling/provenance.d.ts +33 -0
- package/dist/scheduling/provenance.d.ts.map +1 -0
- package/dist/scheduling/provenance.js +70 -0
- package/dist/scheduling/rules.d.ts +23 -0
- package/dist/scheduling/rules.d.ts.map +1 -0
- package/dist/scheduling/rules.js +37 -0
- package/dist/scheduling/scheduler.class.d.ts +24 -0
- package/dist/scheduling/scheduler.class.d.ts.map +1 -0
- package/dist/scheduling/scheduler.class.js +150 -0
- package/dist/scheduling/time.d.ts +132 -0
- package/dist/scheduling/time.d.ts.map +1 -0
- package/dist/scheduling/time.js +256 -0
- package/dist/scheduling/types.d.ts +932 -0
- package/dist/scheduling/types.d.ts.map +1 -0
- package/dist/scheduling/types.js +19 -0
- package/dist/scoring/match-score.d.ts.map +1 -1
- package/dist/scoring/match-score.js +1 -3
- package/dist/types/matcher.d.ts +195 -1
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/utils/keys.d.ts +3 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +15 -0
- package/dist/validation/assignment-lint.d.ts +24 -0
- package/dist/validation/assignment-lint.d.ts.map +1 -0
- package/dist/validation/assignment-lint.js +132 -0
- package/package.json +4 -2
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Assignment pre-flight lint — pure logic.
|
|
4
|
+
*
|
|
5
|
+
* Detects declarations that the runtime would otherwise handle silently:
|
|
6
|
+
* policies that normalize away to nothing, schedule windows that cannot be
|
|
7
|
+
* satisfied, and clock combinations where one policy shadows another.
|
|
8
|
+
* Everything here is deliberately side-effect free and Redis-free;
|
|
9
|
+
* `AssignmentMatcher.checkAssignmentReadiness()` layers the live checks
|
|
10
|
+
* (tag coverage, duplicate ids, eligible users) on top.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.lintAssignment = exports.userCoversTag = void 0;
|
|
14
|
+
const policy_1 = require("../schedule/policy");
|
|
15
|
+
const policy_2 = require("../sla/policy");
|
|
16
|
+
const policy_3 = require("../escalation/policy");
|
|
17
|
+
const match_score_1 = require("../scoring/match-score");
|
|
18
|
+
function epochMs(value) {
|
|
19
|
+
const n = Number(value);
|
|
20
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether a user can currently serve a tag, mirroring the matching
|
|
24
|
+
* semantics: positive routing weights (wildcards honored, weight 0 vetoes)
|
|
25
|
+
* when the user has any, tag membership (user-side patterns) otherwise.
|
|
26
|
+
*/
|
|
27
|
+
function userCoversTag(user, tag) {
|
|
28
|
+
const weights = user.routingWeights;
|
|
29
|
+
if (weights && Object.keys(weights).length > 0) {
|
|
30
|
+
return (0, match_score_1.getEffectiveWeight)(weights, tag) > 0;
|
|
31
|
+
}
|
|
32
|
+
return (user.tags ?? []).some((userTag) => (0, match_score_1.matchesPattern)(userTag, tag));
|
|
33
|
+
}
|
|
34
|
+
exports.userCoversTag = userCoversTag;
|
|
35
|
+
/**
|
|
36
|
+
* Static pre-flight checks for an assignment declaration. Returns an empty
|
|
37
|
+
* array when nothing is worth flagging. Purely structural — pair with
|
|
38
|
+
* `checkAssignmentReadiness()` for checks against the live user pool.
|
|
39
|
+
*/
|
|
40
|
+
function lintAssignment(assignment, context = {}) {
|
|
41
|
+
const now = context.now ?? Date.now();
|
|
42
|
+
const issues = [];
|
|
43
|
+
if (!assignment.tags || assignment.tags.length === 0) {
|
|
44
|
+
issues.push(context.enableDefaultMatching
|
|
45
|
+
? {
|
|
46
|
+
severity: 'info',
|
|
47
|
+
code: 'no-tags',
|
|
48
|
+
message: 'Assignment has no tags; it will match through the injected default tag only.',
|
|
49
|
+
}
|
|
50
|
+
: {
|
|
51
|
+
severity: 'error',
|
|
52
|
+
code: 'no-tags',
|
|
53
|
+
message: 'Assignment has no tags and default matching is off — no user can ever receive it.',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const schedule = (0, policy_1.normalizeSchedulePolicy)(assignment.schedule);
|
|
57
|
+
if (assignment.schedule && !schedule) {
|
|
58
|
+
const rawNotBefore = epochMs(assignment.schedule.notBefore);
|
|
59
|
+
const rawNotAfter = epochMs(assignment.schedule.notAfter);
|
|
60
|
+
if (rawNotBefore !== undefined && rawNotAfter !== undefined && rawNotAfter <= rawNotBefore) {
|
|
61
|
+
issues.push({
|
|
62
|
+
severity: 'error',
|
|
63
|
+
code: 'schedule-window-inverted',
|
|
64
|
+
message: `schedule.notAfter (${rawNotAfter}) is not after notBefore (${rawNotBefore}); the whole schedule policy is ignored.`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
issues.push({
|
|
69
|
+
severity: 'error',
|
|
70
|
+
code: 'schedule-ignored',
|
|
71
|
+
message: 'schedule declares no usable timestamps; the whole schedule policy is ignored.',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (schedule) {
|
|
76
|
+
// Where the clocks would start: a future notBefore anchors at
|
|
77
|
+
// activation, everything else anchors at enqueue (now).
|
|
78
|
+
const activation = schedule.notBefore !== undefined ? Math.max(schedule.notBefore, now) : now;
|
|
79
|
+
if (schedule.notAfter !== undefined && schedule.notAfter <= now) {
|
|
80
|
+
issues.push({
|
|
81
|
+
severity: 'warning',
|
|
82
|
+
code: 'schedule-window-elapsed',
|
|
83
|
+
message: 'schedule.notAfter is already in the past; the assignment will miss on the first sweep.',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (schedule.notBefore !== undefined && schedule.notBefore <= now) {
|
|
88
|
+
issues.push({
|
|
89
|
+
severity: 'info',
|
|
90
|
+
code: 'schedule-notbefore-past',
|
|
91
|
+
message: 'schedule.notBefore is already in the past; the assignment enqueues immediately.',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (schedule.notAfter !== undefined) {
|
|
95
|
+
const windowMs = schedule.notAfter - activation;
|
|
96
|
+
const escalation = (0, policy_3.normalizeEscalationPolicy)(assignment.escalation);
|
|
97
|
+
const respondWithinMs = escalation?.respondWithinMs ?? context.matchExpirationMs;
|
|
98
|
+
if (respondWithinMs !== undefined && respondWithinMs > 0 && windowMs < respondWithinMs) {
|
|
99
|
+
issues.push({
|
|
100
|
+
severity: 'warning',
|
|
101
|
+
code: 'offer-window-tight',
|
|
102
|
+
message: `The offer window (${windowMs}ms from activation) is shorter than one response deadline (${respondWithinMs}ms) — a single unanswered offer consumes the whole window.`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const sla = (0, policy_2.normalizeSlaPolicy)(assignment.sla);
|
|
106
|
+
if (sla?.expireAfterMs !== undefined && activation + sla.expireAfterMs <= schedule.notAfter) {
|
|
107
|
+
issues.push({
|
|
108
|
+
severity: 'warning',
|
|
109
|
+
code: 'schedule-notafter-shadowed-by-sla-ttl',
|
|
110
|
+
message: `sla.expireAfterMs (${sla.expireAfterMs}ms from activation) elapses before schedule.notAfter — the TTL's onExpire acts first and notAfter never fires.`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (assignment.sla && !(0, policy_2.normalizeSlaPolicy)(assignment.sla)) {
|
|
117
|
+
issues.push({
|
|
118
|
+
severity: 'warning',
|
|
119
|
+
code: 'sla-ignored',
|
|
120
|
+
message: 'sla declares no usable values; the whole SLA policy is ignored.',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (assignment.escalation && !(0, policy_3.normalizeEscalationPolicy)(assignment.escalation)) {
|
|
124
|
+
issues.push({
|
|
125
|
+
severity: 'warning',
|
|
126
|
+
code: 'escalation-ignored',
|
|
127
|
+
message: 'escalation declares no usable respondWithinMs; the whole escalation policy is ignored.',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return issues;
|
|
131
|
+
}
|
|
132
|
+
exports.lintAssignment = lintAssignment;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assignment-user-matcher",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/ViljarVoidula/assignment-user-matcher"
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"test": "nyc mocha tests/ --recursive --extension .ts --exit",
|
|
30
30
|
"benchmark:learning": "ts-node benchmark-learning.ts",
|
|
31
31
|
"benchmark:weights": "ts-node benchmark-weights.ts",
|
|
32
|
+
"benchmark:scheduling": "ts-node benchmark-scheduling.ts",
|
|
32
33
|
"build:docs": "npx typedoc --plugin typedoc-plugin-markdown",
|
|
33
34
|
"prettier": "prettier --write .",
|
|
34
35
|
"build": "rimraf dist && tsc && mkdir -p dist/lua && cp src/lua/*.lua dist/lua/",
|
|
@@ -57,5 +58,6 @@
|
|
|
57
58
|
"typedoc": "^0.25.0",
|
|
58
59
|
"typedoc-plugin-markdown": "3.17.1",
|
|
59
60
|
"typescript": "4.9.5"
|
|
60
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
|
|
61
63
|
}
|