@contractspec/example.kb-update-pipeline 1.56.1 → 1.58.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/.turbo/turbo-build.log +59 -56
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +30 -0
- package/dist/browser/docs/index.js +43 -0
- package/dist/browser/docs/kb-update-pipeline.docblock.js +43 -0
- package/dist/browser/entities/index.js +56 -0
- package/dist/browser/entities/models.js +56 -0
- package/dist/browser/events.js +132 -0
- package/dist/browser/example.js +35 -0
- package/dist/browser/handlers/index.js +109 -0
- package/dist/browser/handlers/memory.handlers.js +109 -0
- package/dist/browser/index.js +646 -0
- package/dist/browser/kb-update-pipeline.feature.js +61 -0
- package/dist/browser/operations/index.js +199 -0
- package/dist/browser/operations/pipeline.js +199 -0
- package/dist/browser/presentations.js +120 -0
- package/dist/browser/tests/operations.test-spec.js +85 -0
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +44 -1
- package/dist/docs/kb-update-pipeline.docblock.d.ts +2 -1
- package/dist/docs/kb-update-pipeline.docblock.d.ts.map +1 -0
- package/dist/docs/kb-update-pipeline.docblock.js +41 -28
- package/dist/entities/index.d.ts +2 -2
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +57 -3
- package/dist/entities/models.d.ts +53 -58
- package/dist/entities/models.d.ts.map +1 -1
- package/dist/entities/models.js +54 -71
- package/dist/events.d.ts +62 -68
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +122 -139
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +33 -47
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +110 -3
- package/dist/handlers/memory.handlers.d.ts +58 -60
- package/dist/handlers/memory.handlers.d.ts.map +1 -1
- package/dist/handlers/memory.handlers.js +104 -87
- package/dist/handlers/memory.handlers.test.d.ts +2 -0
- package/dist/handlers/memory.handlers.test.d.ts.map +1 -0
- package/dist/index.d.ts +14 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +647 -12
- package/dist/kb-update-pipeline.feature.d.ts +1 -6
- package/dist/kb-update-pipeline.feature.d.ts.map +1 -1
- package/dist/kb-update-pipeline.feature.js +60 -140
- package/dist/node/docs/index.js +43 -0
- package/dist/node/docs/kb-update-pipeline.docblock.js +43 -0
- package/dist/node/entities/index.js +56 -0
- package/dist/node/entities/models.js +56 -0
- package/dist/node/events.js +132 -0
- package/dist/node/example.js +35 -0
- package/dist/node/handlers/index.js +109 -0
- package/dist/node/handlers/memory.handlers.js +109 -0
- package/dist/node/index.js +646 -0
- package/dist/node/kb-update-pipeline.feature.js +61 -0
- package/dist/node/operations/index.js +199 -0
- package/dist/node/operations/pipeline.js +199 -0
- package/dist/node/presentations.js +120 -0
- package/dist/node/tests/operations.test-spec.js +85 -0
- package/dist/operations/index.d.ts +2 -2
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +199 -2
- package/dist/operations/pipeline.d.ts +126 -132
- package/dist/operations/pipeline.d.ts.map +1 -1
- package/dist/operations/pipeline.js +189 -172
- package/dist/presentations.d.ts +3 -8
- package/dist/presentations.d.ts.map +1 -1
- package/dist/presentations.js +117 -67
- package/dist/tests/operations.test-spec.d.ts +3 -8
- package/dist/tests/operations.test-spec.d.ts.map +1 -1
- package/dist/tests/operations.test-spec.js +82 -90
- package/package.json +157 -41
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -55
- package/dist/docs/kb-update-pipeline.docblock.js.map +0 -1
- package/dist/entities/models.js.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/memory.handlers.js.map +0 -1
- package/dist/kb-update-pipeline.feature.js.map +0 -1
- package/dist/operations/pipeline.js.map +0 -1
- package/dist/presentations.js.map +0 -1
- package/dist/tests/operations.test-spec.js.map +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/handlers/memory.handlers.ts
|
|
2
|
+
function createPipelineMemoryStore() {
|
|
3
|
+
return {
|
|
4
|
+
candidates: new Map,
|
|
5
|
+
reviewTasks: new Map,
|
|
6
|
+
proposedRuleVersionIdsByCandidate: new Map,
|
|
7
|
+
approvedRuleVersionIds: new Set,
|
|
8
|
+
notifications: []
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function stableId(prefix, value) {
|
|
12
|
+
return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
13
|
+
}
|
|
14
|
+
function createPipelineMemoryHandlers(store) {
|
|
15
|
+
async function runWatch(input) {
|
|
16
|
+
const candidates = [...store.candidates.values()].filter((c) => c.sourceDocumentId.startsWith(`${input.jurisdiction}_`) || true);
|
|
17
|
+
return { candidates };
|
|
18
|
+
}
|
|
19
|
+
async function createReviewTask(input) {
|
|
20
|
+
const candidate = store.candidates.get(input.changeCandidateId);
|
|
21
|
+
if (!candidate)
|
|
22
|
+
throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
|
|
23
|
+
const assignedRole = candidate.riskLevel === "high" ? "expert" : "curator";
|
|
24
|
+
const id = stableId("review", input.changeCandidateId);
|
|
25
|
+
const task = {
|
|
26
|
+
id,
|
|
27
|
+
changeCandidateId: input.changeCandidateId,
|
|
28
|
+
status: "open",
|
|
29
|
+
assignedRole,
|
|
30
|
+
decision: undefined,
|
|
31
|
+
decidedAt: undefined,
|
|
32
|
+
decidedBy: undefined
|
|
33
|
+
};
|
|
34
|
+
store.reviewTasks.set(id, task);
|
|
35
|
+
store.notifications.push({
|
|
36
|
+
kind: "kb.review.requested",
|
|
37
|
+
reviewTaskId: id,
|
|
38
|
+
changeCandidateId: input.changeCandidateId,
|
|
39
|
+
assignedRole,
|
|
40
|
+
createdAt: new Date
|
|
41
|
+
});
|
|
42
|
+
return task;
|
|
43
|
+
}
|
|
44
|
+
async function proposeRulePatch(input) {
|
|
45
|
+
if (!store.candidates.has(input.changeCandidateId)) {
|
|
46
|
+
throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
|
|
47
|
+
}
|
|
48
|
+
store.proposedRuleVersionIdsByCandidate.set(input.changeCandidateId, [
|
|
49
|
+
...input.proposedRuleVersionIds
|
|
50
|
+
]);
|
|
51
|
+
return { proposedRuleVersionIds: [...input.proposedRuleVersionIds] };
|
|
52
|
+
}
|
|
53
|
+
async function markRuleVersionApproved(input) {
|
|
54
|
+
store.approvedRuleVersionIds.add(input.ruleVersionId);
|
|
55
|
+
return { ruleVersionId: input.ruleVersionId };
|
|
56
|
+
}
|
|
57
|
+
async function submitDecision(input) {
|
|
58
|
+
const task = store.reviewTasks.get(input.reviewTaskId);
|
|
59
|
+
if (!task)
|
|
60
|
+
throw new Error("REVIEW_TASK_NOT_FOUND");
|
|
61
|
+
const candidate = store.candidates.get(task.changeCandidateId);
|
|
62
|
+
if (!candidate)
|
|
63
|
+
throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
|
|
64
|
+
if (candidate.riskLevel === "high" && input.decision === "approve") {
|
|
65
|
+
if (input.decidedByRole !== "expert")
|
|
66
|
+
throw new Error("FORBIDDEN_ROLE");
|
|
67
|
+
}
|
|
68
|
+
const decided = {
|
|
69
|
+
...task,
|
|
70
|
+
status: "decided",
|
|
71
|
+
decision: input.decision,
|
|
72
|
+
decidedAt: new Date,
|
|
73
|
+
decidedBy: input.decidedBy
|
|
74
|
+
};
|
|
75
|
+
store.reviewTasks.set(decided.id, decided);
|
|
76
|
+
return decided;
|
|
77
|
+
}
|
|
78
|
+
async function publishIfReady(_input) {
|
|
79
|
+
const openTasks = [...store.reviewTasks.values()].filter((t) => t.status !== "decided");
|
|
80
|
+
if (openTasks.length) {
|
|
81
|
+
throw new Error("NOT_READY");
|
|
82
|
+
}
|
|
83
|
+
const rejected = [...store.reviewTasks.values()].some((t) => t.decision === "reject");
|
|
84
|
+
if (rejected)
|
|
85
|
+
return { published: false, reason: "REJECTED" };
|
|
86
|
+
for (const task of store.reviewTasks.values()) {
|
|
87
|
+
if (task.decision !== "approve")
|
|
88
|
+
continue;
|
|
89
|
+
const proposed = store.proposedRuleVersionIdsByCandidate.get(task.changeCandidateId) ?? [];
|
|
90
|
+
const unapproved = proposed.filter((id) => !store.approvedRuleVersionIds.has(id));
|
|
91
|
+
if (unapproved.length) {
|
|
92
|
+
throw new Error("NOT_READY");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { published: true };
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
runWatch,
|
|
99
|
+
createReviewTask,
|
|
100
|
+
proposeRulePatch,
|
|
101
|
+
markRuleVersionApproved,
|
|
102
|
+
submitDecision,
|
|
103
|
+
publishIfReady
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
createPipelineMemoryStore,
|
|
108
|
+
createPipelineMemoryHandlers
|
|
109
|
+
};
|