@contractspec/example.kb-update-pipeline 1.57.0 → 1.59.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 (88) hide show
  1. package/.turbo/turbo-build.log +58 -60
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +25 -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 +34 -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 -60
  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
  88. package/tsconfig.tsbuildinfo +0 -1
@@ -1,93 +1,110 @@
1
- //#region src/handlers/memory.handlers.ts
1
+ // @bun
2
+ // src/handlers/memory.handlers.ts
2
3
  function createPipelineMemoryStore() {
3
- return {
4
- candidates: /* @__PURE__ */ new Map(),
5
- reviewTasks: /* @__PURE__ */ new Map(),
6
- proposedRuleVersionIdsByCandidate: /* @__PURE__ */ new Map(),
7
- approvedRuleVersionIds: /* @__PURE__ */ new Set(),
8
- notifications: []
9
- };
4
+ return {
5
+ candidates: new Map,
6
+ reviewTasks: new Map,
7
+ proposedRuleVersionIdsByCandidate: new Map,
8
+ approvedRuleVersionIds: new Set,
9
+ notifications: []
10
+ };
10
11
  }
11
12
  function stableId(prefix, value) {
12
- return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
13
+ return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
13
14
  }
14
15
  function createPipelineMemoryHandlers(store) {
15
- async function runWatch(input) {
16
- return { candidates: [...store.candidates.values()].filter((c) => c.sourceDocumentId.startsWith(`${input.jurisdiction}_`) || true) };
17
- }
18
- async function createReviewTask(input) {
19
- const candidate = store.candidates.get(input.changeCandidateId);
20
- if (!candidate) throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
21
- const assignedRole = candidate.riskLevel === "high" ? "expert" : "curator";
22
- const id = stableId("review", input.changeCandidateId);
23
- const task = {
24
- id,
25
- changeCandidateId: input.changeCandidateId,
26
- status: "open",
27
- assignedRole,
28
- decision: void 0,
29
- decidedAt: void 0,
30
- decidedBy: void 0
31
- };
32
- store.reviewTasks.set(id, task);
33
- store.notifications.push({
34
- kind: "kb.review.requested",
35
- reviewTaskId: id,
36
- changeCandidateId: input.changeCandidateId,
37
- assignedRole,
38
- createdAt: /* @__PURE__ */ new Date()
39
- });
40
- return task;
41
- }
42
- async function proposeRulePatch(input) {
43
- if (!store.candidates.has(input.changeCandidateId)) throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
44
- store.proposedRuleVersionIdsByCandidate.set(input.changeCandidateId, [...input.proposedRuleVersionIds]);
45
- return { proposedRuleVersionIds: [...input.proposedRuleVersionIds] };
46
- }
47
- async function markRuleVersionApproved(input) {
48
- store.approvedRuleVersionIds.add(input.ruleVersionId);
49
- return { ruleVersionId: input.ruleVersionId };
50
- }
51
- async function submitDecision(input) {
52
- const task = store.reviewTasks.get(input.reviewTaskId);
53
- if (!task) throw new Error("REVIEW_TASK_NOT_FOUND");
54
- const candidate = store.candidates.get(task.changeCandidateId);
55
- if (!candidate) throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
56
- if (candidate.riskLevel === "high" && input.decision === "approve") {
57
- if (input.decidedByRole !== "expert") throw new Error("FORBIDDEN_ROLE");
58
- }
59
- const decided = {
60
- ...task,
61
- status: "decided",
62
- decision: input.decision,
63
- decidedAt: /* @__PURE__ */ new Date(),
64
- decidedBy: input.decidedBy
65
- };
66
- store.reviewTasks.set(decided.id, decided);
67
- return decided;
68
- }
69
- async function publishIfReady(_input) {
70
- if ([...store.reviewTasks.values()].filter((t) => t.status !== "decided").length) throw new Error("NOT_READY");
71
- if ([...store.reviewTasks.values()].some((t) => t.decision === "reject")) return {
72
- published: false,
73
- reason: "REJECTED"
74
- };
75
- for (const task of store.reviewTasks.values()) {
76
- if (task.decision !== "approve") continue;
77
- if ((store.proposedRuleVersionIdsByCandidate.get(task.changeCandidateId) ?? []).filter((id) => !store.approvedRuleVersionIds.has(id)).length) throw new Error("NOT_READY");
78
- }
79
- return { published: true };
80
- }
81
- return {
82
- runWatch,
83
- createReviewTask,
84
- proposeRulePatch,
85
- markRuleVersionApproved,
86
- submitDecision,
87
- publishIfReady
88
- };
16
+ async function runWatch(input) {
17
+ const candidates = [...store.candidates.values()].filter((c) => c.sourceDocumentId.startsWith(`${input.jurisdiction}_`) || true);
18
+ return { candidates };
19
+ }
20
+ async function createReviewTask(input) {
21
+ const candidate = store.candidates.get(input.changeCandidateId);
22
+ if (!candidate)
23
+ throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
24
+ const assignedRole = candidate.riskLevel === "high" ? "expert" : "curator";
25
+ const id = stableId("review", input.changeCandidateId);
26
+ const task = {
27
+ id,
28
+ changeCandidateId: input.changeCandidateId,
29
+ status: "open",
30
+ assignedRole,
31
+ decision: undefined,
32
+ decidedAt: undefined,
33
+ decidedBy: undefined
34
+ };
35
+ store.reviewTasks.set(id, task);
36
+ store.notifications.push({
37
+ kind: "kb.review.requested",
38
+ reviewTaskId: id,
39
+ changeCandidateId: input.changeCandidateId,
40
+ assignedRole,
41
+ createdAt: new Date
42
+ });
43
+ return task;
44
+ }
45
+ async function proposeRulePatch(input) {
46
+ if (!store.candidates.has(input.changeCandidateId)) {
47
+ throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
48
+ }
49
+ store.proposedRuleVersionIdsByCandidate.set(input.changeCandidateId, [
50
+ ...input.proposedRuleVersionIds
51
+ ]);
52
+ return { proposedRuleVersionIds: [...input.proposedRuleVersionIds] };
53
+ }
54
+ async function markRuleVersionApproved(input) {
55
+ store.approvedRuleVersionIds.add(input.ruleVersionId);
56
+ return { ruleVersionId: input.ruleVersionId };
57
+ }
58
+ async function submitDecision(input) {
59
+ const task = store.reviewTasks.get(input.reviewTaskId);
60
+ if (!task)
61
+ throw new Error("REVIEW_TASK_NOT_FOUND");
62
+ const candidate = store.candidates.get(task.changeCandidateId);
63
+ if (!candidate)
64
+ throw new Error("CHANGE_CANDIDATE_NOT_FOUND");
65
+ if (candidate.riskLevel === "high" && input.decision === "approve") {
66
+ if (input.decidedByRole !== "expert")
67
+ throw new Error("FORBIDDEN_ROLE");
68
+ }
69
+ const decided = {
70
+ ...task,
71
+ status: "decided",
72
+ decision: input.decision,
73
+ decidedAt: new Date,
74
+ decidedBy: input.decidedBy
75
+ };
76
+ store.reviewTasks.set(decided.id, decided);
77
+ return decided;
78
+ }
79
+ async function publishIfReady(_input) {
80
+ const openTasks = [...store.reviewTasks.values()].filter((t) => t.status !== "decided");
81
+ if (openTasks.length) {
82
+ throw new Error("NOT_READY");
83
+ }
84
+ const rejected = [...store.reviewTasks.values()].some((t) => t.decision === "reject");
85
+ if (rejected)
86
+ return { published: false, reason: "REJECTED" };
87
+ for (const task of store.reviewTasks.values()) {
88
+ if (task.decision !== "approve")
89
+ continue;
90
+ const proposed = store.proposedRuleVersionIdsByCandidate.get(task.changeCandidateId) ?? [];
91
+ const unapproved = proposed.filter((id) => !store.approvedRuleVersionIds.has(id));
92
+ if (unapproved.length) {
93
+ throw new Error("NOT_READY");
94
+ }
95
+ }
96
+ return { published: true };
97
+ }
98
+ return {
99
+ runWatch,
100
+ createReviewTask,
101
+ proposeRulePatch,
102
+ markRuleVersionApproved,
103
+ submitDecision,
104
+ publishIfReady
105
+ };
89
106
  }
90
-
91
- //#endregion
92
- export { createPipelineMemoryHandlers, createPipelineMemoryStore };
93
- //# sourceMappingURL=memory.handlers.js.map
107
+ export {
108
+ createPipelineMemoryStore,
109
+ createPipelineMemoryHandlers
110
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=memory.handlers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.handlers.test.d.ts","sourceRoot":"","sources":["../../src/handlers/memory.handlers.test.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,14 @@
1
- import { ChangeCandidateModel, ChangeRiskLevelEnum, ReviewAssignedRoleEnum, ReviewDecisionEnum, ReviewTaskModel } from "./entities/models.js";
2
- import "./entities/index.js";
3
- import { KbChangeDetectedEvent, KbChangeSummarizedEvent, KbPatchProposedEvent, KbReviewDecidedEvent, KbReviewRequestedEvent } from "./events.js";
4
- import example from "./example.js";
5
- import { PipelineMemoryHandlers, PipelineMemoryStore, createPipelineMemoryHandlers, createPipelineMemoryStore } from "./handlers/memory.handlers.js";
6
- import { KbPipelineCreateReviewTaskContract, KbPipelinePublishIfReadyContract, KbPipelineRunWatchContract, KbPipelineSubmitDecisionContract } from "./operations/pipeline.js";
7
- import "./operations/index.js";
8
- import { KbUpdatePipelineFeature } from "./kb-update-pipeline.feature.js";
9
- import { KbDashboardPresentation, KbReviewFormPresentation, KbReviewListPresentation } from "./presentations.js";
10
- export { ChangeCandidateModel, ChangeRiskLevelEnum, KbChangeDetectedEvent, KbChangeSummarizedEvent, KbDashboardPresentation, KbPatchProposedEvent, KbPipelineCreateReviewTaskContract, KbPipelinePublishIfReadyContract, KbPipelineRunWatchContract, KbPipelineSubmitDecisionContract, KbReviewDecidedEvent, KbReviewFormPresentation, KbReviewListPresentation, KbReviewRequestedEvent, KbUpdatePipelineFeature, PipelineMemoryHandlers, PipelineMemoryStore, ReviewAssignedRoleEnum, ReviewDecisionEnum, ReviewTaskModel, createPipelineMemoryHandlers, createPipelineMemoryStore, example };
1
+ /**
2
+ * KB Update Pipeline Example
3
+ *
4
+ * Automation proposes KB updates; humans verify; everything audited and notified.
5
+ */
6
+ export * from './entities';
7
+ export * from './operations';
8
+ export * from './events';
9
+ export * from './handlers';
10
+ export * from './kb-update-pipeline.feature';
11
+ export { default as example } from './example';
12
+ export * from './presentations';
13
+ import './docs';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAE/C,cAAc,iBAAiB,CAAC;AAEhC,OAAO,QAAQ,CAAC"}