@contractspec/example.versioned-knowledge-base 3.7.17 → 3.7.18
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 +42 -42
- package/CHANGELOG.md +10 -0
- package/dist/browser/docs/index.js +3 -27
- package/dist/browser/docs/versioned-knowledge-base.docblock.js +3 -27
- package/dist/browser/entities/index.js +1 -74
- package/dist/browser/entities/models.js +1 -74
- package/dist/browser/events.js +1 -101
- package/dist/browser/example.js +1 -35
- package/dist/browser/handlers/index.js +1 -115
- package/dist/browser/handlers/memory.handlers.js +1 -115
- package/dist/browser/index.js +4 -617
- package/dist/browser/knowledge-snapshot-publication.migration.js +2 -44
- package/dist/browser/operations/index.js +1 -257
- package/dist/browser/operations/kb.js +1 -257
- package/dist/browser/versioned-knowledge-base.feature.js +1 -41
- package/dist/docs/index.js +3 -27
- package/dist/docs/versioned-knowledge-base.docblock.js +3 -27
- package/dist/entities/index.js +1 -74
- package/dist/entities/models.js +1 -74
- package/dist/events.js +1 -101
- package/dist/example.js +1 -35
- package/dist/handlers/index.js +1 -115
- package/dist/handlers/memory.handlers.js +1 -115
- package/dist/index.js +4 -617
- package/dist/knowledge-snapshot-publication.migration.js +2 -44
- package/dist/node/docs/index.js +3 -27
- package/dist/node/docs/versioned-knowledge-base.docblock.js +3 -27
- package/dist/node/entities/index.js +1 -74
- package/dist/node/entities/models.js +1 -74
- package/dist/node/events.js +1 -101
- package/dist/node/example.js +1 -35
- package/dist/node/handlers/index.js +1 -115
- package/dist/node/handlers/memory.handlers.js +1 -115
- package/dist/node/index.js +4 -617
- package/dist/node/knowledge-snapshot-publication.migration.js +2 -44
- package/dist/node/operations/index.js +1 -257
- package/dist/node/operations/kb.js +1 -257
- package/dist/node/versioned-knowledge-base.feature.js +1 -41
- package/dist/operations/index.js +1 -257
- package/dist/operations/kb.js +1 -257
- package/dist/versioned-knowledge-base.feature.js +1 -41
- package/package.json +5 -5
|
@@ -1,115 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function createMemoryKbStore() {
|
|
3
|
-
return {
|
|
4
|
-
sources: new Map,
|
|
5
|
-
rules: new Map,
|
|
6
|
-
ruleVersions: new Map,
|
|
7
|
-
snapshots: new Map,
|
|
8
|
-
nextRuleVersionNumberByRuleId: new Map
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function stableId(prefix, value) {
|
|
12
|
-
return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
13
|
-
}
|
|
14
|
-
function createMemoryKbHandlers(store) {
|
|
15
|
-
async function createRule(rule) {
|
|
16
|
-
store.rules.set(rule.id, rule);
|
|
17
|
-
return rule;
|
|
18
|
-
}
|
|
19
|
-
async function ingestSource(input) {
|
|
20
|
-
const id = stableId("src", `${input.jurisdiction}_${input.hash}`);
|
|
21
|
-
const doc = { id, ...input };
|
|
22
|
-
store.sources.set(id, doc);
|
|
23
|
-
return doc;
|
|
24
|
-
}
|
|
25
|
-
async function upsertRuleVersion(input) {
|
|
26
|
-
if (!input.sourceRefs.length) {
|
|
27
|
-
throw new Error("SOURCE_REFS_REQUIRED");
|
|
28
|
-
}
|
|
29
|
-
const rule = store.rules.get(input.ruleId);
|
|
30
|
-
if (!rule) {
|
|
31
|
-
throw new Error("RULE_NOT_FOUND");
|
|
32
|
-
}
|
|
33
|
-
const next = (store.nextRuleVersionNumberByRuleId.get(input.ruleId) ?? 0) + 1;
|
|
34
|
-
const id = stableId("rv", `${input.ruleId}_${next}`);
|
|
35
|
-
const ruleVersion = {
|
|
36
|
-
id,
|
|
37
|
-
ruleId: input.ruleId,
|
|
38
|
-
jurisdiction: rule.jurisdiction,
|
|
39
|
-
topicKey: rule.topicKey,
|
|
40
|
-
version: next.toString(),
|
|
41
|
-
content: input.content,
|
|
42
|
-
sourceRefs: input.sourceRefs,
|
|
43
|
-
status: "draft",
|
|
44
|
-
createdAt: new Date,
|
|
45
|
-
approvedAt: undefined,
|
|
46
|
-
approvedBy: undefined
|
|
47
|
-
};
|
|
48
|
-
store.ruleVersions.set(id, ruleVersion);
|
|
49
|
-
return ruleVersion;
|
|
50
|
-
}
|
|
51
|
-
async function approveRuleVersion(input) {
|
|
52
|
-
const existing = store.ruleVersions.get(input.ruleVersionId);
|
|
53
|
-
if (!existing) {
|
|
54
|
-
throw new Error("RULE_VERSION_NOT_FOUND");
|
|
55
|
-
}
|
|
56
|
-
const approved = {
|
|
57
|
-
...existing,
|
|
58
|
-
status: "approved",
|
|
59
|
-
approvedBy: input.approver,
|
|
60
|
-
approvedAt: new Date
|
|
61
|
-
};
|
|
62
|
-
store.ruleVersions.set(approved.id, approved);
|
|
63
|
-
return approved;
|
|
64
|
-
}
|
|
65
|
-
async function publishSnapshot(input) {
|
|
66
|
-
const approved = [...store.ruleVersions.values()].filter((rv) => rv.status === "approved" && rv.jurisdiction === input.jurisdiction);
|
|
67
|
-
if (approved.length === 0) {
|
|
68
|
-
throw new Error("NO_APPROVED_RULES");
|
|
69
|
-
}
|
|
70
|
-
const includedRuleVersionIds = approved.map((rv) => rv.id).sort();
|
|
71
|
-
const id = stableId("snap", `${input.jurisdiction}_${input.asOfDate.toISOString().slice(0, 10)}_${includedRuleVersionIds.length}`);
|
|
72
|
-
const snapshot = {
|
|
73
|
-
id,
|
|
74
|
-
jurisdiction: input.jurisdiction,
|
|
75
|
-
asOfDate: input.asOfDate,
|
|
76
|
-
includedRuleVersionIds,
|
|
77
|
-
publishedAt: new Date
|
|
78
|
-
};
|
|
79
|
-
store.snapshots.set(id, snapshot);
|
|
80
|
-
return snapshot;
|
|
81
|
-
}
|
|
82
|
-
async function search(input) {
|
|
83
|
-
const snapshot = store.snapshots.get(input.snapshotId);
|
|
84
|
-
if (!snapshot) {
|
|
85
|
-
throw new Error("SNAPSHOT_NOT_FOUND");
|
|
86
|
-
}
|
|
87
|
-
if (snapshot.jurisdiction !== input.jurisdiction) {
|
|
88
|
-
throw new Error("JURISDICTION_MISMATCH");
|
|
89
|
-
}
|
|
90
|
-
const q = input.query.toLowerCase();
|
|
91
|
-
const tokens = q.split(/\s+/).map((t) => t.trim()).filter(Boolean);
|
|
92
|
-
const items = snapshot.includedRuleVersionIds.map((id) => store.ruleVersions.get(id)).filter((rv) => Boolean(rv)).filter((rv) => {
|
|
93
|
-
if (tokens.length === 0)
|
|
94
|
-
return true;
|
|
95
|
-
const hay = rv.content.toLowerCase();
|
|
96
|
-
return tokens.every((token) => hay.includes(token));
|
|
97
|
-
}).map((rv) => ({
|
|
98
|
-
ruleVersionId: rv.id,
|
|
99
|
-
excerpt: rv.content.slice(0, 120)
|
|
100
|
-
}));
|
|
101
|
-
return { items };
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
createRule,
|
|
105
|
-
ingestSource,
|
|
106
|
-
upsertRuleVersion,
|
|
107
|
-
approveRuleVersion,
|
|
108
|
-
publishSnapshot,
|
|
109
|
-
search
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
export {
|
|
113
|
-
createMemoryKbStore,
|
|
114
|
-
createMemoryKbHandlers
|
|
115
|
-
};
|
|
1
|
+
function m(){return{sources:new Map,rules:new Map,ruleVersions:new Map,snapshots:new Map,nextRuleVersionNumberByRuleId:new Map}}function c(t,u){return`${t}_${u.replace(/[^a-zA-Z0-9_-]/g,"_")}`}function h(t){async function u(e){return t.rules.set(e.id,e),e}async function a(e){let r=c("src",`${e.jurisdiction}_${e.hash}`),n={id:r,...e};return t.sources.set(r,n),n}async function d(e){if(!e.sourceRefs.length)throw Error("SOURCE_REFS_REQUIRED");let r=t.rules.get(e.ruleId);if(!r)throw Error("RULE_NOT_FOUND");let n=(t.nextRuleVersionNumberByRuleId.get(e.ruleId)??0)+1,i=c("rv",`${e.ruleId}_${n}`),o={id:i,ruleId:e.ruleId,jurisdiction:r.jurisdiction,topicKey:r.topicKey,version:n.toString(),content:e.content,sourceRefs:e.sourceRefs,status:"draft",createdAt:new Date,approvedAt:void 0,approvedBy:void 0};return t.ruleVersions.set(i,o),o}async function l(e){let r=t.ruleVersions.get(e.ruleVersionId);if(!r)throw Error("RULE_VERSION_NOT_FOUND");let n={...r,status:"approved",approvedBy:e.approver,approvedAt:new Date};return t.ruleVersions.set(n.id,n),n}async function p(e){let r=[...t.ruleVersions.values()].filter((s)=>s.status==="approved"&&s.jurisdiction===e.jurisdiction);if(r.length===0)throw Error("NO_APPROVED_RULES");let n=r.map((s)=>s.id).sort(),i=c("snap",`${e.jurisdiction}_${e.asOfDate.toISOString().slice(0,10)}_${n.length}`),o={id:i,jurisdiction:e.jurisdiction,asOfDate:e.asOfDate,includedRuleVersionIds:n,publishedAt:new Date};return t.snapshots.set(i,o),o}async function g(e){let r=t.snapshots.get(e.snapshotId);if(!r)throw Error("SNAPSHOT_NOT_FOUND");if(r.jurisdiction!==e.jurisdiction)throw Error("JURISDICTION_MISMATCH");let i=e.query.toLowerCase().split(/\s+/).map((s)=>s.trim()).filter(Boolean);return{items:r.includedRuleVersionIds.map((s)=>t.ruleVersions.get(s)).filter((s)=>Boolean(s)).filter((s)=>{if(i.length===0)return!0;let R=s.content.toLowerCase();return i.every((f)=>R.includes(f))}).map((s)=>({ruleVersionId:s.id,excerpt:s.content.slice(0,120)}))}}return{createRule:u,ingestSource:a,upsertRuleVersion:d,approveRuleVersion:l,publishSnapshot:p,search:g}}export{m as createMemoryKbStore,h as createMemoryKbHandlers};
|