@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.
Files changed (87) hide show
  1. package/.turbo/turbo-build.log +59 -56
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +30 -0
  4. package/dist/browser/docs/index.js +43 -0
  5. package/dist/browser/docs/kb-update-pipeline.docblock.js +43 -0
  6. package/dist/browser/entities/index.js +56 -0
  7. package/dist/browser/entities/models.js +56 -0
  8. package/dist/browser/events.js +132 -0
  9. package/dist/browser/example.js +35 -0
  10. package/dist/browser/handlers/index.js +109 -0
  11. package/dist/browser/handlers/memory.handlers.js +109 -0
  12. package/dist/browser/index.js +646 -0
  13. package/dist/browser/kb-update-pipeline.feature.js +61 -0
  14. package/dist/browser/operations/index.js +199 -0
  15. package/dist/browser/operations/pipeline.js +199 -0
  16. package/dist/browser/presentations.js +120 -0
  17. package/dist/browser/tests/operations.test-spec.js +85 -0
  18. package/dist/docs/index.d.ts +2 -1
  19. package/dist/docs/index.d.ts.map +1 -0
  20. package/dist/docs/index.js +44 -1
  21. package/dist/docs/kb-update-pipeline.docblock.d.ts +2 -1
  22. package/dist/docs/kb-update-pipeline.docblock.d.ts.map +1 -0
  23. package/dist/docs/kb-update-pipeline.docblock.js +41 -28
  24. package/dist/entities/index.d.ts +2 -2
  25. package/dist/entities/index.d.ts.map +1 -0
  26. package/dist/entities/index.js +57 -3
  27. package/dist/entities/models.d.ts +53 -58
  28. package/dist/entities/models.d.ts.map +1 -1
  29. package/dist/entities/models.js +54 -71
  30. package/dist/events.d.ts +62 -68
  31. package/dist/events.d.ts.map +1 -1
  32. package/dist/events.js +122 -139
  33. package/dist/example.d.ts +2 -6
  34. package/dist/example.d.ts.map +1 -1
  35. package/dist/example.js +33 -47
  36. package/dist/handlers/index.d.ts +2 -2
  37. package/dist/handlers/index.d.ts.map +1 -0
  38. package/dist/handlers/index.js +110 -3
  39. package/dist/handlers/memory.handlers.d.ts +58 -60
  40. package/dist/handlers/memory.handlers.d.ts.map +1 -1
  41. package/dist/handlers/memory.handlers.js +104 -87
  42. package/dist/handlers/memory.handlers.test.d.ts +2 -0
  43. package/dist/handlers/memory.handlers.test.d.ts.map +1 -0
  44. package/dist/index.d.ts +14 -10
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +647 -12
  47. package/dist/kb-update-pipeline.feature.d.ts +1 -6
  48. package/dist/kb-update-pipeline.feature.d.ts.map +1 -1
  49. package/dist/kb-update-pipeline.feature.js +60 -140
  50. package/dist/node/docs/index.js +43 -0
  51. package/dist/node/docs/kb-update-pipeline.docblock.js +43 -0
  52. package/dist/node/entities/index.js +56 -0
  53. package/dist/node/entities/models.js +56 -0
  54. package/dist/node/events.js +132 -0
  55. package/dist/node/example.js +35 -0
  56. package/dist/node/handlers/index.js +109 -0
  57. package/dist/node/handlers/memory.handlers.js +109 -0
  58. package/dist/node/index.js +646 -0
  59. package/dist/node/kb-update-pipeline.feature.js +61 -0
  60. package/dist/node/operations/index.js +199 -0
  61. package/dist/node/operations/pipeline.js +199 -0
  62. package/dist/node/presentations.js +120 -0
  63. package/dist/node/tests/operations.test-spec.js +85 -0
  64. package/dist/operations/index.d.ts +2 -2
  65. package/dist/operations/index.d.ts.map +1 -0
  66. package/dist/operations/index.js +199 -2
  67. package/dist/operations/pipeline.d.ts +126 -132
  68. package/dist/operations/pipeline.d.ts.map +1 -1
  69. package/dist/operations/pipeline.js +189 -172
  70. package/dist/presentations.d.ts +3 -8
  71. package/dist/presentations.d.ts.map +1 -1
  72. package/dist/presentations.js +117 -67
  73. package/dist/tests/operations.test-spec.d.ts +3 -8
  74. package/dist/tests/operations.test-spec.d.ts.map +1 -1
  75. package/dist/tests/operations.test-spec.js +82 -90
  76. package/package.json +157 -41
  77. package/tsdown.config.js +1 -2
  78. package/.turbo/turbo-build$colon$bundle.log +0 -55
  79. package/dist/docs/kb-update-pipeline.docblock.js.map +0 -1
  80. package/dist/entities/models.js.map +0 -1
  81. package/dist/events.js.map +0 -1
  82. package/dist/example.js.map +0 -1
  83. package/dist/handlers/memory.handlers.js.map +0 -1
  84. package/dist/kb-update-pipeline.feature.js.map +0 -1
  85. package/dist/operations/pipeline.js.map +0 -1
  86. package/dist/presentations.js.map +0 -1
  87. 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
+ };