@contractspec/example.versioned-knowledge-base 0.0.0-canary-20260113162409
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$colon$bundle.log +47 -0
- package/.turbo/turbo-build.log +48 -0
- package/CHANGELOG.md +302 -0
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/versioned-knowledge-base.docblock.d.ts +1 -0
- package/dist/docs/versioned-knowledge-base.docblock.js +31 -0
- package/dist/docs/versioned-knowledge-base.docblock.js.map +1 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/models.d.ts +139 -0
- package/dist/entities/models.d.ts.map +1 -0
- package/dist/entities/models.js +151 -0
- package/dist/entities/models.js.map +1 -0
- package/dist/events.d.ts +63 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +124 -0
- package/dist/events.js.map +1 -0
- package/dist/example.d.ts +7 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +49 -0
- package/dist/example.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/memory.handlers.d.ts +78 -0
- package/dist/handlers/memory.handlers.d.ts.map +1 -0
- package/dist/handlers/memory.handlers.js +103 -0
- package/dist/handlers/memory.handlers.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/kb.d.ts +267 -0
- package/dist/operations/kb.d.ts.map +1 -0
- package/dist/operations/kb.js +256 -0
- package/dist/operations/kb.js.map +1 -0
- package/dist/versioned-knowledge-base.feature.d.ts +7 -0
- package/dist/versioned-knowledge-base.feature.d.ts.map +1 -0
- package/dist/versioned-knowledge-base.feature.js +70 -0
- package/dist/versioned-knowledge-base.feature.js.map +1 -0
- package/example.ts +1 -0
- package/package.json +71 -0
- package/src/docs/index.ts +1 -0
- package/src/docs/versioned-knowledge-base.docblock.ts +29 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/models.ts +75 -0
- package/src/events.ts +102 -0
- package/src/example.ts +34 -0
- package/src/handlers/index.ts +1 -0
- package/src/handlers/memory.handlers.test.ts +81 -0
- package/src/handlers/memory.handlers.ts +216 -0
- package/src/index.ts +13 -0
- package/src/operations/index.ts +1 -0
- package/src/operations/kb.ts +201 -0
- package/src/versioned-knowledge-base.feature.ts +34 -0
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +17 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
2
|
+
|
|
3
|
+
//#region src/entities/models.ts
|
|
4
|
+
const SourceDocumentModel = defineSchemaModel({
|
|
5
|
+
name: "SourceDocument",
|
|
6
|
+
description: "Immutable raw source document metadata referencing a stored file.",
|
|
7
|
+
fields: {
|
|
8
|
+
id: {
|
|
9
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
10
|
+
isOptional: false
|
|
11
|
+
},
|
|
12
|
+
jurisdiction: {
|
|
13
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
14
|
+
isOptional: false
|
|
15
|
+
},
|
|
16
|
+
authority: {
|
|
17
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
18
|
+
isOptional: false
|
|
19
|
+
},
|
|
20
|
+
title: {
|
|
21
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
22
|
+
isOptional: false
|
|
23
|
+
},
|
|
24
|
+
fetchedAt: {
|
|
25
|
+
type: ScalarTypeEnum.DateTime(),
|
|
26
|
+
isOptional: false
|
|
27
|
+
},
|
|
28
|
+
hash: {
|
|
29
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
30
|
+
isOptional: false
|
|
31
|
+
},
|
|
32
|
+
fileId: {
|
|
33
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
34
|
+
isOptional: false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const SourceRefModel = defineSchemaModel({
|
|
39
|
+
name: "SourceRef",
|
|
40
|
+
description: "Reference to a source document used to justify a rule version.",
|
|
41
|
+
fields: {
|
|
42
|
+
sourceDocumentId: {
|
|
43
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
44
|
+
isOptional: false
|
|
45
|
+
},
|
|
46
|
+
excerpt: {
|
|
47
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
48
|
+
isOptional: true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const RuleModel = defineSchemaModel({
|
|
53
|
+
name: "Rule",
|
|
54
|
+
description: "Curated rule (stable identity) with topic + jurisdiction scope.",
|
|
55
|
+
fields: {
|
|
56
|
+
id: {
|
|
57
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
58
|
+
isOptional: false
|
|
59
|
+
},
|
|
60
|
+
jurisdiction: {
|
|
61
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
62
|
+
isOptional: false
|
|
63
|
+
},
|
|
64
|
+
topicKey: {
|
|
65
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
66
|
+
isOptional: false
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const RuleVersionModel = defineSchemaModel({
|
|
71
|
+
name: "RuleVersion",
|
|
72
|
+
description: "A versioned rule content with source references and approval status.",
|
|
73
|
+
fields: {
|
|
74
|
+
id: {
|
|
75
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
76
|
+
isOptional: false
|
|
77
|
+
},
|
|
78
|
+
ruleId: {
|
|
79
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
80
|
+
isOptional: false
|
|
81
|
+
},
|
|
82
|
+
jurisdiction: {
|
|
83
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
84
|
+
isOptional: false
|
|
85
|
+
},
|
|
86
|
+
topicKey: {
|
|
87
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
88
|
+
isOptional: false
|
|
89
|
+
},
|
|
90
|
+
version: {
|
|
91
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
92
|
+
isOptional: false
|
|
93
|
+
},
|
|
94
|
+
content: {
|
|
95
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
96
|
+
isOptional: false
|
|
97
|
+
},
|
|
98
|
+
sourceRefs: {
|
|
99
|
+
type: SourceRefModel,
|
|
100
|
+
isArray: true,
|
|
101
|
+
isOptional: false
|
|
102
|
+
},
|
|
103
|
+
status: {
|
|
104
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
105
|
+
isOptional: false
|
|
106
|
+
},
|
|
107
|
+
approvedBy: {
|
|
108
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
109
|
+
isOptional: true
|
|
110
|
+
},
|
|
111
|
+
approvedAt: {
|
|
112
|
+
type: ScalarTypeEnum.DateTime(),
|
|
113
|
+
isOptional: true
|
|
114
|
+
},
|
|
115
|
+
createdAt: {
|
|
116
|
+
type: ScalarTypeEnum.DateTime(),
|
|
117
|
+
isOptional: false
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const KBSnapshotModel = defineSchemaModel({
|
|
122
|
+
name: "KBSnapshot",
|
|
123
|
+
description: "Published KB snapshot (as-of) referencing approved rule versions.",
|
|
124
|
+
fields: {
|
|
125
|
+
id: {
|
|
126
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
127
|
+
isOptional: false
|
|
128
|
+
},
|
|
129
|
+
jurisdiction: {
|
|
130
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
131
|
+
isOptional: false
|
|
132
|
+
},
|
|
133
|
+
asOfDate: {
|
|
134
|
+
type: ScalarTypeEnum.DateTime(),
|
|
135
|
+
isOptional: false
|
|
136
|
+
},
|
|
137
|
+
includedRuleVersionIds: {
|
|
138
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
139
|
+
isArray: true,
|
|
140
|
+
isOptional: false
|
|
141
|
+
},
|
|
142
|
+
publishedAt: {
|
|
143
|
+
type: ScalarTypeEnum.DateTime(),
|
|
144
|
+
isOptional: false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
export { KBSnapshotModel, RuleModel, RuleVersionModel, SourceDocumentModel, SourceRefModel };
|
|
151
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","names":[],"sources":["../../src/entities/models.ts"],"sourcesContent":["import { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';\n\nexport const SourceDocumentModel = defineSchemaModel({\n name: 'SourceDocument',\n description:\n 'Immutable raw source document metadata referencing a stored file.',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n authority: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n fetchedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const SourceRefModel = defineSchemaModel({\n name: 'SourceRef',\n description: 'Reference to a source document used to justify a rule version.',\n fields: {\n sourceDocumentId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\nexport const RuleModel = defineSchemaModel({\n name: 'Rule',\n description:\n 'Curated rule (stable identity) with topic + jurisdiction scope.',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n topicKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const RuleVersionModel = defineSchemaModel({\n name: 'RuleVersion',\n description:\n 'A versioned rule content with source references and approval status.',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n topicKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n version: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n sourceRefs: { type: SourceRefModel, isArray: true, isOptional: false },\n status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // draft|approved|rejected\n approvedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n approvedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\nexport const KBSnapshotModel = defineSchemaModel({\n name: 'KBSnapshot',\n description:\n 'Published KB snapshot (as-of) referencing approved rule versions.',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n includedRuleVersionIds: {\n type: ScalarTypeEnum.String_unsecure(),\n isArray: true,\n isOptional: false,\n },\n publishedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n"],"mappings":";;;AAEA,MAAa,sBAAsB,kBAAkB;CACnD,MAAM;CACN,aACE;CACF,QAAQ;EACN,IAAI;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACjE,cAAc;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EAC3E,WAAW;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACxE,OAAO;GAAE,MAAM,eAAe,iBAAiB;GAAE,YA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eAAe,UAAU;GAAE,YAAY;GAAM;EACjE,WAAW;GAAE,MAAM,eAAe,UAAU;GAAE,YAAY;GAAO;EAClE;CACF,CAAC;AAEF,MAAa,kBAAkB,kBAAkB;CAC/C,MAAM;CACN,aACE;CACF,QAAQ;EACN,IAAI;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACjE,cAAc;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EAC3E,UAAU;GAAE,MAAM,eAAe,UAAU;GAAE,YAAY;GAAO;EAChE,wBAAwB;GACtB,MAAM,eAAe,iBAAiB;GACtC,SAAS;GACT,YAAY;GACb;EACD,aAAa;GAAE,MAAM,eAAe,UAAU;GAAE,YAAY;GAAO;EACpE;CACF,CAAC"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as _contractspec_lib_contracts4 from "@contractspec/lib.contracts";
|
|
2
|
+
import * as _contractspec_lib_schema68 from "@contractspec/lib.schema";
|
|
3
|
+
|
|
4
|
+
//#region src/events.d.ts
|
|
5
|
+
declare const KbSourceIngestedEvent: _contractspec_lib_contracts4.EventSpec<_contractspec_lib_schema68.SchemaModel<{
|
|
6
|
+
sourceDocumentId: {
|
|
7
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
8
|
+
isOptional: false;
|
|
9
|
+
};
|
|
10
|
+
jurisdiction: {
|
|
11
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
12
|
+
isOptional: false;
|
|
13
|
+
};
|
|
14
|
+
hash: {
|
|
15
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
16
|
+
isOptional: false;
|
|
17
|
+
};
|
|
18
|
+
}>>;
|
|
19
|
+
declare const KbRuleVersionCreatedEvent: _contractspec_lib_contracts4.EventSpec<_contractspec_lib_schema68.SchemaModel<{
|
|
20
|
+
ruleVersionId: {
|
|
21
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
22
|
+
isOptional: false;
|
|
23
|
+
};
|
|
24
|
+
ruleId: {
|
|
25
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
26
|
+
isOptional: false;
|
|
27
|
+
};
|
|
28
|
+
jurisdiction: {
|
|
29
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
30
|
+
isOptional: false;
|
|
31
|
+
};
|
|
32
|
+
status: {
|
|
33
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
34
|
+
isOptional: false;
|
|
35
|
+
};
|
|
36
|
+
}>>;
|
|
37
|
+
declare const KbRuleVersionApprovedEvent: _contractspec_lib_contracts4.EventSpec<_contractspec_lib_schema68.SchemaModel<{
|
|
38
|
+
ruleVersionId: {
|
|
39
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
40
|
+
isOptional: false;
|
|
41
|
+
};
|
|
42
|
+
approver: {
|
|
43
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
44
|
+
isOptional: false;
|
|
45
|
+
};
|
|
46
|
+
}>>;
|
|
47
|
+
declare const KbSnapshotPublishedEvent: _contractspec_lib_contracts4.EventSpec<_contractspec_lib_schema68.SchemaModel<{
|
|
48
|
+
snapshotId: {
|
|
49
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
50
|
+
isOptional: false;
|
|
51
|
+
};
|
|
52
|
+
jurisdiction: {
|
|
53
|
+
type: _contractspec_lib_schema68.FieldType<string, string>;
|
|
54
|
+
isOptional: false;
|
|
55
|
+
};
|
|
56
|
+
includedRuleVersionsCount: {
|
|
57
|
+
type: _contractspec_lib_schema68.FieldType<number, number>;
|
|
58
|
+
isOptional: false;
|
|
59
|
+
};
|
|
60
|
+
}>>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { KbRuleVersionApprovedEvent, KbRuleVersionCreatedEvent, KbSnapshotPublishedEvent, KbSourceIngestedEvent };
|
|
63
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","names":[],"sources":["../src/events.ts"],"sourcesContent":[],"mappings":";;;;cAgBa,uBAAqB,4BAAA,CAAA,qCAAA;;UAUhC,0BAAA,CAAA;;EAVW,CAAA;EAUX,YAAA,EAAA;;;;EAVgC,IAAA,EAAA;IAAA,IAAA,sCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;IA0BrB,UAAA,EAAA,KAAA;EAUX,CAAA;;cAVW,2BAAyB,4BAAA,CAAA,qCAAA;;UAUpC,0BAAA,CAAA,SAVoC,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EAAA,CAAA;EAwBzB,MAAA,EAAA;IAUX,IAAA,sCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;EAVqC,YAAA,EAAA;IAAA,IAAA,sCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;IAyB1B,UAAA,EAAA,KAAA;EAUX,CAAA;;;;EAVmC,CAAA;CAAA,CAAA,CAAA;cAzBxB,4BAA0B,4BAAA,CAAA,qCAAA;;UAUrC,0BAAA,CAAA;;;;;;;;cAeW,0BAAwB,4BAAA,CAAA,qCAAA;;UAUnC,0BAAA,CAAA"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { defineEvent, defineSchemaModel } from "@contractspec/lib.contracts";
|
|
2
|
+
import { ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
3
|
+
|
|
4
|
+
//#region src/events.ts
|
|
5
|
+
const KbSourceIngestedPayload = defineSchemaModel({
|
|
6
|
+
name: "KbSourceIngestedPayload",
|
|
7
|
+
description: "Emitted when a source document is ingested.",
|
|
8
|
+
fields: {
|
|
9
|
+
sourceDocumentId: {
|
|
10
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
11
|
+
isOptional: false
|
|
12
|
+
},
|
|
13
|
+
jurisdiction: {
|
|
14
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
15
|
+
isOptional: false
|
|
16
|
+
},
|
|
17
|
+
hash: {
|
|
18
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
19
|
+
isOptional: false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const KbSourceIngestedEvent = defineEvent({
|
|
24
|
+
meta: {
|
|
25
|
+
key: "kb.source.ingested",
|
|
26
|
+
version: "1.0.0",
|
|
27
|
+
description: "Source document ingested (immutable).",
|
|
28
|
+
stability: "experimental",
|
|
29
|
+
owners: ["@examples"],
|
|
30
|
+
tags: ["knowledge"]
|
|
31
|
+
},
|
|
32
|
+
payload: KbSourceIngestedPayload
|
|
33
|
+
});
|
|
34
|
+
const KbRuleVersionCreatedPayload = defineSchemaModel({
|
|
35
|
+
name: "KbRuleVersionCreatedPayload",
|
|
36
|
+
description: "Emitted when a rule version draft is created.",
|
|
37
|
+
fields: {
|
|
38
|
+
ruleVersionId: {
|
|
39
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
40
|
+
isOptional: false
|
|
41
|
+
},
|
|
42
|
+
ruleId: {
|
|
43
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
44
|
+
isOptional: false
|
|
45
|
+
},
|
|
46
|
+
jurisdiction: {
|
|
47
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
48
|
+
isOptional: false
|
|
49
|
+
},
|
|
50
|
+
status: {
|
|
51
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
52
|
+
isOptional: false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const KbRuleVersionCreatedEvent = defineEvent({
|
|
57
|
+
meta: {
|
|
58
|
+
key: "kb.ruleVersion.created",
|
|
59
|
+
version: "1.0.0",
|
|
60
|
+
description: "Rule version created (draft).",
|
|
61
|
+
stability: "experimental",
|
|
62
|
+
owners: ["@examples"],
|
|
63
|
+
tags: ["knowledge"]
|
|
64
|
+
},
|
|
65
|
+
payload: KbRuleVersionCreatedPayload
|
|
66
|
+
});
|
|
67
|
+
const KbRuleVersionApprovedPayload = defineSchemaModel({
|
|
68
|
+
name: "KbRuleVersionApprovedPayload",
|
|
69
|
+
description: "Emitted when a rule version is approved.",
|
|
70
|
+
fields: {
|
|
71
|
+
ruleVersionId: {
|
|
72
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
73
|
+
isOptional: false
|
|
74
|
+
},
|
|
75
|
+
approver: {
|
|
76
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
77
|
+
isOptional: false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const KbRuleVersionApprovedEvent = defineEvent({
|
|
82
|
+
meta: {
|
|
83
|
+
key: "kb.ruleVersion.approved",
|
|
84
|
+
version: "1.0.0",
|
|
85
|
+
description: "Rule version approved (human verified).",
|
|
86
|
+
stability: "experimental",
|
|
87
|
+
owners: ["@examples"],
|
|
88
|
+
tags: ["knowledge"]
|
|
89
|
+
},
|
|
90
|
+
payload: KbRuleVersionApprovedPayload
|
|
91
|
+
});
|
|
92
|
+
const KbSnapshotPublishedPayload = defineSchemaModel({
|
|
93
|
+
name: "KbSnapshotPublishedPayload",
|
|
94
|
+
description: "Emitted when a KB snapshot is published.",
|
|
95
|
+
fields: {
|
|
96
|
+
snapshotId: {
|
|
97
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
98
|
+
isOptional: false
|
|
99
|
+
},
|
|
100
|
+
jurisdiction: {
|
|
101
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
102
|
+
isOptional: false
|
|
103
|
+
},
|
|
104
|
+
includedRuleVersionsCount: {
|
|
105
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
106
|
+
isOptional: false
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const KbSnapshotPublishedEvent = defineEvent({
|
|
111
|
+
meta: {
|
|
112
|
+
key: "kb.snapshot.published",
|
|
113
|
+
version: "1.0.0",
|
|
114
|
+
description: "KB snapshot published.",
|
|
115
|
+
stability: "experimental",
|
|
116
|
+
owners: ["@examples"],
|
|
117
|
+
tags: ["knowledge"]
|
|
118
|
+
},
|
|
119
|
+
payload: KbSnapshotPublishedPayload
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
export { KbRuleVersionApprovedEvent, KbRuleVersionCreatedEvent, KbSnapshotPublishedEvent, KbSourceIngestedEvent };
|
|
124
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","names":[],"sources":["../src/events.ts"],"sourcesContent":["import { defineEvent, defineSchemaModel } from '@contractspec/lib.contracts';\nimport { ScalarTypeEnum } from '@contractspec/lib.schema';\n\nconst KbSourceIngestedPayload = defineSchemaModel({\n name: 'KbSourceIngestedPayload',\n description: 'Emitted when a source document is ingested.',\n fields: {\n sourceDocumentId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const KbSourceIngestedEvent = defineEvent({\n meta: {\n key: 'kb.source.ingested',\n version: '1.0.0',\n description: 'Source document ingested (immutable).',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge'],\n },\n payload: KbSourceIngestedPayload,\n});\n\nconst KbRuleVersionCreatedPayload = defineSchemaModel({\n name: 'KbRuleVersionCreatedPayload',\n description: 'Emitted when a rule version draft is created.',\n fields: {\n ruleVersionId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const KbRuleVersionCreatedEvent = defineEvent({\n meta: {\n key: 'kb.ruleVersion.created',\n version: '1.0.0',\n description: 'Rule version created (draft).',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge'],\n },\n payload: KbRuleVersionCreatedPayload,\n});\n\nconst KbRuleVersionApprovedPayload = defineSchemaModel({\n name: 'KbRuleVersionApprovedPayload',\n description: 'Emitted when a rule version is approved.',\n fields: {\n ruleVersionId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const KbRuleVersionApprovedEvent = defineEvent({\n meta: {\n key: 'kb.ruleVersion.approved',\n version: '1.0.0',\n description: 'Rule version approved (human verified).',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge'],\n },\n payload: KbRuleVersionApprovedPayload,\n});\n\nconst KbSnapshotPublishedPayload = defineSchemaModel({\n name: 'KbSnapshotPublishedPayload',\n description: 'Emitted when a KB snapshot is published.',\n fields: {\n snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n includedRuleVersionsCount: {\n type: ScalarTypeEnum.Int_unsecure(),\n isOptional: false,\n },\n },\n});\n\nexport const KbSnapshotPublishedEvent = defineEvent({\n meta: {\n key: 'kb.snapshot.published',\n version: '1.0.0',\n description: 'KB snapshot published.',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge'],\n },\n payload: KbSnapshotPublishedPayload,\n});\n"],"mappings":";;;;AAGA,MAAM,0BAA0B,kBAAkB;CAChD,MAAM;CACN,aAAa;CACb,QAAQ;EACN,kBAAkB;GAChB,MAAM,eAAe,iBAAiB;GACtC,YAAY;GACb;EACD,cAAc;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EAC3E,MAAM;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACpE;CACF,CAAC;AAEF,MAAa,wBAAwB,YAAY;CAC/C,MAAM;EACJ,KAAK;EACL,SAAS;EACT,aAAa;EACb,WAAW;EACX,QAAQ,CAAC,YAAY;E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AC,YAAY;EACpB;CACD,SAAS;CACV,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.d.ts","names":[],"sources":["../src/example.ts"],"sourcesContent":[],"mappings":";;;cAEM,SA6BJ,4BAAA,CA7BW"}
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/example.ts
|
|
4
|
+
const example = defineExample({
|
|
5
|
+
meta: {
|
|
6
|
+
key: "versioned-knowledge-base",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
title: "Versioned Knowledge Base",
|
|
9
|
+
description: "Curated KB with immutable sources, reviewable rule versions, and published snapshots.",
|
|
10
|
+
kind: "knowledge",
|
|
11
|
+
visibility: "public",
|
|
12
|
+
stability: "experimental",
|
|
13
|
+
owners: ["@platform.core"],
|
|
14
|
+
tags: [
|
|
15
|
+
"knowledge",
|
|
16
|
+
"versioning",
|
|
17
|
+
"snapshots"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
docs: { rootDocId: "docs.examples.versioned-knowledge-base" },
|
|
21
|
+
entrypoints: {
|
|
22
|
+
packageName: "@contractspec/example.versioned-knowledge-base",
|
|
23
|
+
feature: "./feature",
|
|
24
|
+
contracts: "./contracts",
|
|
25
|
+
handlers: "./handlers",
|
|
26
|
+
docs: "./docs"
|
|
27
|
+
},
|
|
28
|
+
surfaces: {
|
|
29
|
+
templates: true,
|
|
30
|
+
sandbox: {
|
|
31
|
+
enabled: true,
|
|
32
|
+
modes: [
|
|
33
|
+
"markdown",
|
|
34
|
+
"specs",
|
|
35
|
+
"builder"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
studio: {
|
|
39
|
+
enabled: true,
|
|
40
|
+
installable: true
|
|
41
|
+
},
|
|
42
|
+
mcp: { enabled: true }
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
var example_default = example;
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { example_default as default };
|
|
49
|
+
//# sourceMappingURL=example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.js","names":[],"sources":["../src/example.ts"],"sourcesContent":["import { defineExample } from '@contractspec/lib.contracts';\n\nconst example = defineExample({\n meta: {\n key: 'versioned-knowledge-base',\n version: '1.0.0',\n title: 'Versioned Knowledge Base',\n description:\n 'Curated KB with immutable sources, reviewable rule versions, and published snapshots.',\n kind: 'knowledge',\n visibility: 'public',\n stability: 'experimental',\n owners: ['@platform.core'],\n tags: ['knowledge', 'versioning', 'snapshots'],\n },\n docs: {\n rootDocId: 'docs.examples.versioned-knowledge-base',\n },\n entrypoints: {\n packageName: '@contractspec/example.versioned-knowledge-base',\n feature: './feature',\n contracts: './contracts',\n handlers: './handlers',\n docs: './docs',\n },\n surfaces: {\n templates: true,\n sandbox: { enabled: true, modes: ['markdown', 'specs', 'builder'] },\n studio: { enabled: true, installable: true },\n mcp: { enabled: true },\n },\n});\n\nexport default example;\n"],"mappings":";;;AAEA,MAAM,UAAU,cAAc;CAC5B,MAAM;EACJ,KAAK;EACL,SAAS;EACT,OAAO;EACP,aACE;EACF,MAAM;EACN,YAAY;EACZ,WAAW;EACX,QAAQ,CAAC,iBAAiB;EAC1B,MAAM;GAAC;GAAa;GAAc;GAAY;EAC/C;CACD,MAAM,EACJ,WAAW,0CACZ;CACD,aAAa;EACX,aAAa;EACb,SAAS;EACT,WAAW;EACX,UAAU;EACV,MAAM;EACP;CACD,UAAU;EACR,WAAW;EACX,SAAS;GAAE,SAAS;GAAM,OAAO;IAAC;IAAY;IAAS;IAAU;GAAE;EACnE,QAAQ;GAAE,SAAS;GAAM,aAAa;GAAM;EAC5C,KAAK,EAAE,SAAS,MAAM;EACvB;CACF,CAAC;AAEF,sBAAe"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/handlers/memory.handlers.d.ts
|
|
2
|
+
interface SourceRef {
|
|
3
|
+
sourceDocumentId: string;
|
|
4
|
+
excerpt?: string;
|
|
5
|
+
}
|
|
6
|
+
interface SourceDocument {
|
|
7
|
+
id: string;
|
|
8
|
+
jurisdiction: string;
|
|
9
|
+
authority: string;
|
|
10
|
+
title: string;
|
|
11
|
+
fetchedAt: Date;
|
|
12
|
+
hash: string;
|
|
13
|
+
fileId: string;
|
|
14
|
+
}
|
|
15
|
+
interface Rule {
|
|
16
|
+
id: string;
|
|
17
|
+
jurisdiction: string;
|
|
18
|
+
topicKey: string;
|
|
19
|
+
}
|
|
20
|
+
interface RuleVersion {
|
|
21
|
+
id: string;
|
|
22
|
+
ruleId: string;
|
|
23
|
+
jurisdiction: string;
|
|
24
|
+
topicKey: string;
|
|
25
|
+
version: string;
|
|
26
|
+
content: string;
|
|
27
|
+
sourceRefs: SourceRef[];
|
|
28
|
+
status: 'draft' | 'approved' | 'rejected';
|
|
29
|
+
approvedBy?: string;
|
|
30
|
+
approvedAt?: Date;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
}
|
|
33
|
+
interface KBSnapshot {
|
|
34
|
+
id: string;
|
|
35
|
+
jurisdiction: string;
|
|
36
|
+
asOfDate: Date;
|
|
37
|
+
includedRuleVersionIds: string[];
|
|
38
|
+
publishedAt: Date;
|
|
39
|
+
}
|
|
40
|
+
interface MemoryKbStore {
|
|
41
|
+
sources: Map<string, SourceDocument>;
|
|
42
|
+
rules: Map<string, Rule>;
|
|
43
|
+
ruleVersions: Map<string, RuleVersion>;
|
|
44
|
+
snapshots: Map<string, KBSnapshot>;
|
|
45
|
+
nextRuleVersionNumberByRuleId: Map<string, number>;
|
|
46
|
+
}
|
|
47
|
+
declare function createMemoryKbStore(): MemoryKbStore;
|
|
48
|
+
interface MemoryKbHandlers {
|
|
49
|
+
createRule(rule: Rule): Promise<Rule>;
|
|
50
|
+
ingestSource(input: Omit<SourceDocument, 'id'>): Promise<SourceDocument>;
|
|
51
|
+
upsertRuleVersion(input: {
|
|
52
|
+
ruleId: string;
|
|
53
|
+
content: string;
|
|
54
|
+
sourceRefs: SourceRef[];
|
|
55
|
+
}): Promise<RuleVersion>;
|
|
56
|
+
approveRuleVersion(input: {
|
|
57
|
+
ruleVersionId: string;
|
|
58
|
+
approver: string;
|
|
59
|
+
}): Promise<RuleVersion>;
|
|
60
|
+
publishSnapshot(input: {
|
|
61
|
+
jurisdiction: string;
|
|
62
|
+
asOfDate: Date;
|
|
63
|
+
}): Promise<KBSnapshot>;
|
|
64
|
+
search(input: {
|
|
65
|
+
snapshotId: string;
|
|
66
|
+
jurisdiction: string;
|
|
67
|
+
query: string;
|
|
68
|
+
}): Promise<{
|
|
69
|
+
items: {
|
|
70
|
+
ruleVersionId: string;
|
|
71
|
+
excerpt?: string;
|
|
72
|
+
}[];
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
declare function createMemoryKbHandlers(store: MemoryKbStore): MemoryKbHandlers;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { MemoryKbHandlers, MemoryKbStore, createMemoryKbHandlers, createMemoryKbStore };
|
|
78
|
+
//# sourceMappingURL=memory.handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.handlers.d.ts","names":[],"sources":["../../src/handlers/memory.handlers.ts"],"sourcesContent":[],"mappings":";UAAU,SAAA;EAAA,gBAAS,EAAA,MAAA;EAIT,OAAA,CAAA,EAAA,MAAA;AAKO;AAIH,UATJ,cAAA,CAcW;EAOP,EAAA,EAAA,MAAA;EAGC,YAAA,EAAA,MAAA;EACF,SAAA,EAAA,MAAA;EAAI,KAAA,EAAA,MAAA;EAEP,SAAA,EAtBG,IAsBO;EAQH,IAAA,EAAA,MAAA;EACM,MAAA,EAAA,MAAA;;UA3Bb,IAAA,CA4BW;EAAZ,EAAA,EAAA,MAAA;EACmB,YAAA,EAAA,MAAA;EAAZ,QAAA,EAAA,MAAA;;UAxBN,WAAA,CAyBG;EACoB,EAAA,EAAA,MAAA;EAAG,MAAA,EAAA,MAAA;EAGpB,YAAA,EAAA,MAAA;EAUC,QAAA,EAAA,MAAA;EACE,OAAA,EAAA,MAAA;EAAe,OAAA,EAAA,MAAA;EAAR,UAAA,EAjCZ,SAiCY,EAAA;EACC,MAAA,EAAA,OAAA,GAAA,UAAA,GAAA,UAAA;EAAL,UAAA,CAAA,EAAA,MAAA;EAAqC,UAAA,CAAA,EA/B5C,IA+B4C;EAAR,SAAA,EA9BtC,IA8BsC;;UA5BzC,UAAA,CAiCI;EAAR,EAAA,EAAA,MAAA;EAIQ,YAAA,EAAA,MAAA;EAAR,QAAA,EAlCM,IAkCN;EAGQ,sBAAA,EAAA,MAAA,EAAA;EACA,WAAA,EApCC,IAoCD;;AAKR,UAtCW,aAAA,CAsCX;EAAO,OAAA,EArCF,GAqCE,CAAA,MAAA,EArCU,cAqCV,CAAA;EAOG,KAAA,EA3CP,GA2CO,CAAA,MAAA,EA3CK,IA2CL,CAAA;gBA1CA,YAAY;aACf,YAAY;iCACQ;;iBAGjB,mBAAA,CAAA,GAAuB;UAUtB,gBAAA;mBACE,OAAO,QAAQ;sBACZ,KAAK,wBAAwB,QAAQ;;;;gBAI3C;MACV,QAAQ;;;;MAIR,QAAQ;;;cAGA;MACR,QAAQ;;;;;MAKR;;;;;;;iBAOU,sBAAA,QAA8B,gBAAgB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//#region src/handlers/memory.handlers.ts
|
|
2
|
+
function createMemoryKbStore() {
|
|
3
|
+
return {
|
|
4
|
+
sources: /* @__PURE__ */ new Map(),
|
|
5
|
+
rules: /* @__PURE__ */ new Map(),
|
|
6
|
+
ruleVersions: /* @__PURE__ */ new Map(),
|
|
7
|
+
snapshots: /* @__PURE__ */ new Map(),
|
|
8
|
+
nextRuleVersionNumberByRuleId: /* @__PURE__ */ 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 = {
|
|
22
|
+
id,
|
|
23
|
+
...input
|
|
24
|
+
};
|
|
25
|
+
store.sources.set(id, doc);
|
|
26
|
+
return doc;
|
|
27
|
+
}
|
|
28
|
+
async function upsertRuleVersion(input) {
|
|
29
|
+
if (!input.sourceRefs.length) throw new Error("SOURCE_REFS_REQUIRED");
|
|
30
|
+
const rule = store.rules.get(input.ruleId);
|
|
31
|
+
if (!rule) throw new Error("RULE_NOT_FOUND");
|
|
32
|
+
const next = (store.nextRuleVersionNumberByRuleId.get(input.ruleId) ?? 0) + 1;
|
|
33
|
+
const id = stableId("rv", `${input.ruleId}_${next}`);
|
|
34
|
+
const ruleVersion = {
|
|
35
|
+
id,
|
|
36
|
+
ruleId: input.ruleId,
|
|
37
|
+
jurisdiction: rule.jurisdiction,
|
|
38
|
+
topicKey: rule.topicKey,
|
|
39
|
+
version: next.toString(),
|
|
40
|
+
content: input.content,
|
|
41
|
+
sourceRefs: input.sourceRefs,
|
|
42
|
+
status: "draft",
|
|
43
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
44
|
+
approvedAt: void 0,
|
|
45
|
+
approvedBy: void 0
|
|
46
|
+
};
|
|
47
|
+
store.ruleVersions.set(id, ruleVersion);
|
|
48
|
+
return ruleVersion;
|
|
49
|
+
}
|
|
50
|
+
async function approveRuleVersion(input) {
|
|
51
|
+
const existing = store.ruleVersions.get(input.ruleVersionId);
|
|
52
|
+
if (!existing) throw new Error("RULE_VERSION_NOT_FOUND");
|
|
53
|
+
const approved = {
|
|
54
|
+
...existing,
|
|
55
|
+
status: "approved",
|
|
56
|
+
approvedBy: input.approver,
|
|
57
|
+
approvedAt: /* @__PURE__ */ new Date()
|
|
58
|
+
};
|
|
59
|
+
store.ruleVersions.set(approved.id, approved);
|
|
60
|
+
return approved;
|
|
61
|
+
}
|
|
62
|
+
async function publishSnapshot(input) {
|
|
63
|
+
const approved = [...store.ruleVersions.values()].filter((rv) => rv.status === "approved" && rv.jurisdiction === input.jurisdiction);
|
|
64
|
+
if (approved.length === 0) throw new Error("NO_APPROVED_RULES");
|
|
65
|
+
const includedRuleVersionIds = approved.map((rv) => rv.id).sort();
|
|
66
|
+
const id = stableId("snap", `${input.jurisdiction}_${input.asOfDate.toISOString().slice(0, 10)}_${includedRuleVersionIds.length}`);
|
|
67
|
+
const snapshot = {
|
|
68
|
+
id,
|
|
69
|
+
jurisdiction: input.jurisdiction,
|
|
70
|
+
asOfDate: input.asOfDate,
|
|
71
|
+
includedRuleVersionIds,
|
|
72
|
+
publishedAt: /* @__PURE__ */ new Date()
|
|
73
|
+
};
|
|
74
|
+
store.snapshots.set(id, snapshot);
|
|
75
|
+
return snapshot;
|
|
76
|
+
}
|
|
77
|
+
async function search(input) {
|
|
78
|
+
const snapshot = store.snapshots.get(input.snapshotId);
|
|
79
|
+
if (!snapshot) throw new Error("SNAPSHOT_NOT_FOUND");
|
|
80
|
+
if (snapshot.jurisdiction !== input.jurisdiction) throw new Error("JURISDICTION_MISMATCH");
|
|
81
|
+
const tokens = input.query.toLowerCase().split(/\s+/).map((t) => t.trim()).filter(Boolean);
|
|
82
|
+
return { items: snapshot.includedRuleVersionIds.map((id) => store.ruleVersions.get(id)).filter((rv) => Boolean(rv)).filter((rv) => {
|
|
83
|
+
if (tokens.length === 0) return true;
|
|
84
|
+
const hay = rv.content.toLowerCase();
|
|
85
|
+
return tokens.every((token) => hay.includes(token));
|
|
86
|
+
}).map((rv) => ({
|
|
87
|
+
ruleVersionId: rv.id,
|
|
88
|
+
excerpt: rv.content.slice(0, 120)
|
|
89
|
+
})) };
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
createRule,
|
|
93
|
+
ingestSource,
|
|
94
|
+
upsertRuleVersion,
|
|
95
|
+
approveRuleVersion,
|
|
96
|
+
publishSnapshot,
|
|
97
|
+
search
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
export { createMemoryKbHandlers, createMemoryKbStore };
|
|
103
|
+
//# sourceMappingURL=memory.handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.handlers.js","names":[],"sources":["../../src/handlers/memory.handlers.ts"],"sourcesContent":["interface SourceRef {\n sourceDocumentId: string;\n excerpt?: string;\n}\ninterface SourceDocument {\n id: string;\n jurisdiction: string;\n authority: string;\n title: string;\n fetchedAt: Date;\n hash: string;\n fileId: string;\n}\ninterface Rule {\n id: string;\n jurisdiction: string;\n topicKey: string;\n}\ninterface RuleVersion {\n id: string;\n ruleId: string;\n jurisdiction: string;\n topicKey: string;\n version: string;\n content: string;\n sourceRefs: SourceRef[];\n status: 'draft' | 'approved' | 'rejected';\n approvedBy?: string;\n approvedAt?: Date;\n createdAt: Date;\n}\ninterface KBSnapshot {\n id: string;\n jurisdiction: string;\n asOfDate: Date;\n includedRuleVersionIds: string[];\n publishedAt: Date;\n}\n\nexport interface MemoryKbStore {\n sources: Map<string, SourceDocument>;\n rules: Map<string, Rule>;\n ruleVersions: Map<string, RuleVersion>;\n snapshots: Map<string, KBSnapshot>;\n nextRuleVersionNumberByRuleId: Map<string, number>;\n}\n\nexport function createMemoryKbStore(): MemoryKbStore {\n return {\n sources: new Map(),\n rules: new Map(),\n ruleVersions: new Map(),\n snapshots: new Map(),\n nextRuleVersionNumberByRuleId: new Map(),\n };\n}\n\nexport interface MemoryKbHandlers {\n createRule(rule: Rule): Promise<Rule>;\n ingestSource(input: Omit<SourceDocument, 'id'>): Promise<SourceDocument>;\n upsertRuleVersion(input: {\n ruleId: string;\n content: string;\n sourceRefs: SourceRef[];\n }): Promise<RuleVersion>;\n approveRuleVersion(input: {\n ruleVersionId: string;\n approver: string;\n }): Promise<RuleVersion>;\n publishSnapshot(input: {\n jurisdiction: string;\n asOfDate: Date;\n }): Promise<KBSnapshot>;\n search(input: {\n snapshotId: string;\n jurisdiction: string;\n query: string;\n }): Promise<{ items: { ruleVersionId: string; excerpt?: string }[] }>;\n}\n\nfunction stableId(prefix: string, value: string): string {\n return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, '_')}`;\n}\n\nexport function createMemoryKbHandlers(store: MemoryKbStore): MemoryKbHandlers {\n async function createRule(rule: Rule): Promise<Rule> {\n store.rules.set(rule.id, rule);\n return rule;\n }\n\n async function ingestSource(\n input: Omit<SourceDocument, 'id'>\n ): Promise<SourceDocument> {\n const id = stableId('src', `${input.jurisdiction}_${input.hash}`);\n const doc: SourceDocument = { id, ...input };\n store.sources.set(id, doc);\n return doc;\n }\n\n async function upsertRuleVersion(input: {\n ruleId: string;\n content: string;\n sourceRefs: SourceRef[];\n }): Promise<RuleVersion> {\n if (!input.sourceRefs.length) {\n throw new Error('SOURCE_REFS_REQUIRED');\n }\n const rule = store.rules.get(input.ruleId);\n if (!rule) {\n throw new Error('RULE_NOT_FOUND');\n }\n const next =\n (store.nextRuleVersionNumberByRuleId.get(input.ruleId) ?? 0) + 1;\n const id = stableId('rv', `${input.ruleId}_${next}`);\n const ruleVersion: RuleVersion = {\n id,\n ruleId: input.ruleId,\n jurisdiction: rule.jurisdiction,\n topicKey: rule.topicKey,\n version: next.toString(),\n content: input.content,\n sourceRefs: input.sourceRefs,\n status: 'draft',\n createdAt: new Date(),\n approvedAt: undefined,\n approvedBy: undefined,\n };\n store.ruleVersions.set(id, ruleVersion);\n return ruleVersion;\n }\n\n async function approveRuleVersion(input: {\n ruleVersionId: string;\n approver: string;\n }): Promise<RuleVersion> {\n const existing = store.ruleVersions.get(input.ruleVersionId);\n if (!existing) {\n throw new Error('RULE_VERSION_NOT_FOUND');\n }\n const approved: RuleVersion = {\n ...existing,\n status: 'approved',\n approvedBy: input.approver,\n approvedAt: new Date(),\n };\n store.ruleVersions.set(approved.id, approved);\n return approved;\n }\n\n async function publishSnapshot(input: {\n jurisdiction: string;\n asOfDate: Date;\n }): Promise<KBSnapshot> {\n const approved = [...store.ruleVersions.values()].filter(\n (rv) => rv.status === 'approved' && rv.jurisdiction === input.jurisdiction\n );\n if (approved.length === 0) {\n throw new Error('NO_APPROVED_RULES');\n }\n const includedRuleVersionIds = approved.map((rv) => rv.id).sort();\n const id = stableId(\n 'snap',\n `${input.jurisdiction}_${input.asOfDate.toISOString().slice(0, 10)}_${includedRuleVersionIds.length}`\n );\n const snapshot: KBSnapshot = {\n id,\n jurisdiction: input.jurisdiction,\n asOfDate: input.asOfDate,\n includedRuleVersionIds,\n publishedAt: new Date(),\n };\n store.snapshots.set(id, snapshot);\n return snapshot;\n }\n\n async function search(input: {\n snapshotId: string;\n jurisdiction: string;\n query: string;\n }): Promise<{ items: { ruleVersionId: string; excerpt?: string }[] }> {\n const snapshot = store.snapshots.get(input.snapshotId);\n if (!snapshot) {\n throw new Error('SNAPSHOT_NOT_FOUND');\n }\n if (snapshot.jurisdiction !== input.jurisdiction) {\n throw new Error('JURISDICTION_MISMATCH');\n }\n const q = input.query.toLowerCase();\n const tokens = q\n .split(/\\s+/)\n .map((t) => t.trim())\n .filter(Boolean);\n const items = snapshot.includedRuleVersionIds\n .map((id) => store.ruleVersions.get(id))\n .filter((rv): rv is RuleVersion => Boolean(rv))\n .filter((rv) => {\n if (tokens.length === 0) return true;\n const hay = rv.content.toLowerCase();\n return tokens.every((token) => hay.includes(token));\n })\n .map((rv) => ({\n ruleVersionId: rv.id,\n excerpt: rv.content.slice(0, 120),\n }));\n return { items };\n }\n\n return {\n createRule,\n ingestSource,\n upsertRuleVersion,\n approveRuleVersion,\n publishSnapshot,\n search,\n };\n}\n"],"mappings":";AA+CA,SAAgB,sBAAqC;AACnD,QAAO;EACL,yBAAS,IAAI,KAAK;EAClB,uBAAO,IAAI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,SAAS,GAAG,QAAQ,MAAM,GAAG,IAAI;GAClC,EAAE,EACW;;AAGlB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KBSnapshotModel, RuleModel, RuleVersionModel, SourceDocumentModel, SourceRefModel } from "./entities/models.js";
|
|
2
|
+
import "./entities/index.js";
|
|
3
|
+
import { KbRuleVersionApprovedEvent, KbRuleVersionCreatedEvent, KbSnapshotPublishedEvent, KbSourceIngestedEvent } from "./events.js";
|
|
4
|
+
import example from "./example.js";
|
|
5
|
+
import { MemoryKbHandlers, MemoryKbStore, createMemoryKbHandlers, createMemoryKbStore } from "./handlers/memory.handlers.js";
|
|
6
|
+
import { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract } from "./operations/kb.js";
|
|
7
|
+
import "./operations/index.js";
|
|
8
|
+
import { VersionedKnowledgeBaseFeature } from "./versioned-knowledge-base.feature.js";
|
|
9
|
+
export { KBSnapshotModel, KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbRuleVersionApprovedEvent, KbRuleVersionCreatedEvent, KbSearchContract, KbSnapshotPublishedEvent, KbSourceIngestedEvent, KbUpsertRuleVersionContract, MemoryKbHandlers, MemoryKbStore, RuleModel, RuleVersionModel, SourceDocumentModel, SourceRefModel, VersionedKnowledgeBaseFeature, createMemoryKbHandlers, createMemoryKbStore, example };
|