@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.
Files changed (60) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +47 -0
  2. package/.turbo/turbo-build.log +48 -0
  3. package/CHANGELOG.md +302 -0
  4. package/LICENSE +21 -0
  5. package/README.md +35 -0
  6. package/dist/docs/index.d.ts +1 -0
  7. package/dist/docs/index.js +1 -0
  8. package/dist/docs/versioned-knowledge-base.docblock.d.ts +1 -0
  9. package/dist/docs/versioned-knowledge-base.docblock.js +31 -0
  10. package/dist/docs/versioned-knowledge-base.docblock.js.map +1 -0
  11. package/dist/entities/index.d.ts +2 -0
  12. package/dist/entities/index.js +3 -0
  13. package/dist/entities/models.d.ts +139 -0
  14. package/dist/entities/models.d.ts.map +1 -0
  15. package/dist/entities/models.js +151 -0
  16. package/dist/entities/models.js.map +1 -0
  17. package/dist/events.d.ts +63 -0
  18. package/dist/events.d.ts.map +1 -0
  19. package/dist/events.js +124 -0
  20. package/dist/events.js.map +1 -0
  21. package/dist/example.d.ts +7 -0
  22. package/dist/example.d.ts.map +1 -0
  23. package/dist/example.js +49 -0
  24. package/dist/example.js.map +1 -0
  25. package/dist/handlers/index.d.ts +2 -0
  26. package/dist/handlers/index.js +3 -0
  27. package/dist/handlers/memory.handlers.d.ts +78 -0
  28. package/dist/handlers/memory.handlers.d.ts.map +1 -0
  29. package/dist/handlers/memory.handlers.js +103 -0
  30. package/dist/handlers/memory.handlers.js.map +1 -0
  31. package/dist/index.d.ts +9 -0
  32. package/dist/index.js +11 -0
  33. package/dist/operations/index.d.ts +2 -0
  34. package/dist/operations/index.js +3 -0
  35. package/dist/operations/kb.d.ts +267 -0
  36. package/dist/operations/kb.d.ts.map +1 -0
  37. package/dist/operations/kb.js +256 -0
  38. package/dist/operations/kb.js.map +1 -0
  39. package/dist/versioned-knowledge-base.feature.d.ts +7 -0
  40. package/dist/versioned-knowledge-base.feature.d.ts.map +1 -0
  41. package/dist/versioned-knowledge-base.feature.js +70 -0
  42. package/dist/versioned-knowledge-base.feature.js.map +1 -0
  43. package/example.ts +1 -0
  44. package/package.json +71 -0
  45. package/src/docs/index.ts +1 -0
  46. package/src/docs/versioned-knowledge-base.docblock.ts +29 -0
  47. package/src/entities/index.ts +1 -0
  48. package/src/entities/models.ts +75 -0
  49. package/src/events.ts +102 -0
  50. package/src/example.ts +34 -0
  51. package/src/handlers/index.ts +1 -0
  52. package/src/handlers/memory.handlers.test.ts +81 -0
  53. package/src/handlers/memory.handlers.ts +216 -0
  54. package/src/index.ts +13 -0
  55. package/src/operations/index.ts +1 -0
  56. package/src/operations/kb.ts +201 -0
  57. package/src/versioned-knowledge-base.feature.ts +34 -0
  58. package/tsconfig.json +19 -0
  59. package/tsconfig.tsbuildinfo +1 -0
  60. package/tsdown.config.js +17 -0
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { KbRuleVersionApprovedEvent, KbRuleVersionCreatedEvent, KbSnapshotPublishedEvent, KbSourceIngestedEvent } from "./events.js";
2
+ import example_default from "./example.js";
3
+ import { KBSnapshotModel, RuleModel, RuleVersionModel, SourceDocumentModel, SourceRefModel } from "./entities/models.js";
4
+ import "./entities/index.js";
5
+ import { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract } from "./operations/kb.js";
6
+ import "./operations/index.js";
7
+ import { createMemoryKbHandlers, createMemoryKbStore } from "./handlers/memory.handlers.js";
8
+ import { VersionedKnowledgeBaseFeature } from "./versioned-knowledge-base.feature.js";
9
+ import "./docs/index.js";
10
+
11
+ export { KBSnapshotModel, KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbRuleVersionApprovedEvent, KbRuleVersionCreatedEvent, KbSearchContract, KbSnapshotPublishedEvent, KbSourceIngestedEvent, KbUpsertRuleVersionContract, RuleModel, RuleVersionModel, SourceDocumentModel, SourceRefModel, VersionedKnowledgeBaseFeature, createMemoryKbHandlers, createMemoryKbStore, example_default as example };
@@ -0,0 +1,2 @@
1
+ import { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract } from "./kb.js";
2
+ export { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract };
@@ -0,0 +1,3 @@
1
+ import { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract } from "./kb.js";
2
+
3
+ export { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract };
@@ -0,0 +1,267 @@
1
+ import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
2
+ import * as _contractspec_lib_schema0 from "@contractspec/lib.schema";
3
+
4
+ //#region src/operations/kb.d.ts
5
+ declare const KbIngestSourceContract: _contractspec_lib_contracts0.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
6
+ jurisdiction: {
7
+ type: _contractspec_lib_schema0.FieldType<string, string>;
8
+ isOptional: false;
9
+ };
10
+ authority: {
11
+ type: _contractspec_lib_schema0.FieldType<string, string>;
12
+ isOptional: false;
13
+ };
14
+ title: {
15
+ type: _contractspec_lib_schema0.FieldType<string, string>;
16
+ isOptional: false;
17
+ };
18
+ fetchedAt: {
19
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
20
+ isOptional: false;
21
+ };
22
+ hash: {
23
+ type: _contractspec_lib_schema0.FieldType<string, string>;
24
+ isOptional: false;
25
+ };
26
+ fileId: {
27
+ type: _contractspec_lib_schema0.FieldType<string, string>;
28
+ isOptional: false;
29
+ };
30
+ }>, _contractspec_lib_schema0.SchemaModel<{
31
+ id: {
32
+ type: _contractspec_lib_schema0.FieldType<string, string>;
33
+ isOptional: false;
34
+ };
35
+ jurisdiction: {
36
+ type: _contractspec_lib_schema0.FieldType<string, string>;
37
+ isOptional: false;
38
+ };
39
+ authority: {
40
+ type: _contractspec_lib_schema0.FieldType<string, string>;
41
+ isOptional: false;
42
+ };
43
+ title: {
44
+ type: _contractspec_lib_schema0.FieldType<string, string>;
45
+ isOptional: false;
46
+ };
47
+ fetchedAt: {
48
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
49
+ isOptional: false;
50
+ };
51
+ hash: {
52
+ type: _contractspec_lib_schema0.FieldType<string, string>;
53
+ isOptional: false;
54
+ };
55
+ fileId: {
56
+ type: _contractspec_lib_schema0.FieldType<string, string>;
57
+ isOptional: false;
58
+ };
59
+ }>, undefined>;
60
+ declare const KbUpsertRuleVersionContract: _contractspec_lib_contracts0.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
61
+ ruleId: {
62
+ type: _contractspec_lib_schema0.FieldType<string, string>;
63
+ isOptional: false;
64
+ };
65
+ content: {
66
+ type: _contractspec_lib_schema0.FieldType<string, string>;
67
+ isOptional: false;
68
+ };
69
+ sourceRefs: {
70
+ type: _contractspec_lib_schema0.SchemaModel<{
71
+ sourceDocumentId: {
72
+ type: _contractspec_lib_schema0.FieldType<string, string>;
73
+ isOptional: false;
74
+ };
75
+ excerpt: {
76
+ type: _contractspec_lib_schema0.FieldType<string, string>;
77
+ isOptional: true;
78
+ };
79
+ }>;
80
+ isArray: true;
81
+ isOptional: false;
82
+ };
83
+ }>, _contractspec_lib_schema0.SchemaModel<{
84
+ id: {
85
+ type: _contractspec_lib_schema0.FieldType<string, string>;
86
+ isOptional: false;
87
+ };
88
+ ruleId: {
89
+ type: _contractspec_lib_schema0.FieldType<string, string>;
90
+ isOptional: false;
91
+ };
92
+ jurisdiction: {
93
+ type: _contractspec_lib_schema0.FieldType<string, string>;
94
+ isOptional: false;
95
+ };
96
+ topicKey: {
97
+ type: _contractspec_lib_schema0.FieldType<string, string>;
98
+ isOptional: false;
99
+ };
100
+ version: {
101
+ type: _contractspec_lib_schema0.FieldType<string, string>;
102
+ isOptional: false;
103
+ };
104
+ content: {
105
+ type: _contractspec_lib_schema0.FieldType<string, string>;
106
+ isOptional: false;
107
+ };
108
+ sourceRefs: {
109
+ type: _contractspec_lib_schema0.SchemaModel<{
110
+ sourceDocumentId: {
111
+ type: _contractspec_lib_schema0.FieldType<string, string>;
112
+ isOptional: false;
113
+ };
114
+ excerpt: {
115
+ type: _contractspec_lib_schema0.FieldType<string, string>;
116
+ isOptional: true;
117
+ };
118
+ }>;
119
+ isArray: true;
120
+ isOptional: false;
121
+ };
122
+ status: {
123
+ type: _contractspec_lib_schema0.FieldType<string, string>;
124
+ isOptional: false;
125
+ };
126
+ approvedBy: {
127
+ type: _contractspec_lib_schema0.FieldType<string, string>;
128
+ isOptional: true;
129
+ };
130
+ approvedAt: {
131
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
132
+ isOptional: true;
133
+ };
134
+ createdAt: {
135
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
136
+ isOptional: false;
137
+ };
138
+ }>, undefined>;
139
+ declare const KbApproveRuleVersionContract: _contractspec_lib_contracts0.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
140
+ ruleVersionId: {
141
+ type: _contractspec_lib_schema0.FieldType<string, string>;
142
+ isOptional: false;
143
+ };
144
+ approver: {
145
+ type: _contractspec_lib_schema0.FieldType<string, string>;
146
+ isOptional: false;
147
+ };
148
+ }>, _contractspec_lib_schema0.SchemaModel<{
149
+ id: {
150
+ type: _contractspec_lib_schema0.FieldType<string, string>;
151
+ isOptional: false;
152
+ };
153
+ ruleId: {
154
+ type: _contractspec_lib_schema0.FieldType<string, string>;
155
+ isOptional: false;
156
+ };
157
+ jurisdiction: {
158
+ type: _contractspec_lib_schema0.FieldType<string, string>;
159
+ isOptional: false;
160
+ };
161
+ topicKey: {
162
+ type: _contractspec_lib_schema0.FieldType<string, string>;
163
+ isOptional: false;
164
+ };
165
+ version: {
166
+ type: _contractspec_lib_schema0.FieldType<string, string>;
167
+ isOptional: false;
168
+ };
169
+ content: {
170
+ type: _contractspec_lib_schema0.FieldType<string, string>;
171
+ isOptional: false;
172
+ };
173
+ sourceRefs: {
174
+ type: _contractspec_lib_schema0.SchemaModel<{
175
+ sourceDocumentId: {
176
+ type: _contractspec_lib_schema0.FieldType<string, string>;
177
+ isOptional: false;
178
+ };
179
+ excerpt: {
180
+ type: _contractspec_lib_schema0.FieldType<string, string>;
181
+ isOptional: true;
182
+ };
183
+ }>;
184
+ isArray: true;
185
+ isOptional: false;
186
+ };
187
+ status: {
188
+ type: _contractspec_lib_schema0.FieldType<string, string>;
189
+ isOptional: false;
190
+ };
191
+ approvedBy: {
192
+ type: _contractspec_lib_schema0.FieldType<string, string>;
193
+ isOptional: true;
194
+ };
195
+ approvedAt: {
196
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
197
+ isOptional: true;
198
+ };
199
+ createdAt: {
200
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
201
+ isOptional: false;
202
+ };
203
+ }>, undefined>;
204
+ declare const KbPublishSnapshotContract: _contractspec_lib_contracts0.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
205
+ jurisdiction: {
206
+ type: _contractspec_lib_schema0.FieldType<string, string>;
207
+ isOptional: false;
208
+ };
209
+ asOfDate: {
210
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
211
+ isOptional: false;
212
+ };
213
+ }>, _contractspec_lib_schema0.SchemaModel<{
214
+ id: {
215
+ type: _contractspec_lib_schema0.FieldType<string, string>;
216
+ isOptional: false;
217
+ };
218
+ jurisdiction: {
219
+ type: _contractspec_lib_schema0.FieldType<string, string>;
220
+ isOptional: false;
221
+ };
222
+ asOfDate: {
223
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
224
+ isOptional: false;
225
+ };
226
+ includedRuleVersionIds: {
227
+ type: _contractspec_lib_schema0.FieldType<string, string>;
228
+ isArray: true;
229
+ isOptional: false;
230
+ };
231
+ publishedAt: {
232
+ type: _contractspec_lib_schema0.FieldType<Date, string>;
233
+ isOptional: false;
234
+ };
235
+ }>, undefined>;
236
+ declare const KbSearchContract: _contractspec_lib_contracts0.OperationSpec<_contractspec_lib_schema0.SchemaModel<{
237
+ snapshotId: {
238
+ type: _contractspec_lib_schema0.FieldType<string, string>;
239
+ isOptional: false;
240
+ };
241
+ jurisdiction: {
242
+ type: _contractspec_lib_schema0.FieldType<string, string>;
243
+ isOptional: false;
244
+ };
245
+ query: {
246
+ type: _contractspec_lib_schema0.FieldType<string, string>;
247
+ isOptional: false;
248
+ };
249
+ }>, _contractspec_lib_schema0.SchemaModel<{
250
+ items: {
251
+ type: _contractspec_lib_schema0.SchemaModel<{
252
+ ruleVersionId: {
253
+ type: _contractspec_lib_schema0.FieldType<string, string>;
254
+ isOptional: false;
255
+ };
256
+ excerpt: {
257
+ type: _contractspec_lib_schema0.FieldType<string, string>;
258
+ isOptional: true;
259
+ };
260
+ }>;
261
+ isArray: true;
262
+ isOptional: false;
263
+ };
264
+ }>, undefined>;
265
+ //#endregion
266
+ export { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract };
267
+ //# sourceMappingURL=kb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kb.d.ts","names":[],"sources":["../../src/operations/kb.ts"],"sourcesContent":[],"mappings":";;;;cAoFa,qDAAsB,wCAAA;;UAiBjC,yBAAA,CAAA;;EAjBW,CAAA;EAiBX,SAAA,EAAA;;;;;;;;EAjBiC,SAAA,EAAA;;;;;;;;;6CAAA,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EAmBtB,CAAA;CA+BX,CAAA,uCAAA,CAAA;;UAlDiC,yBAAA,CAAA;;;;IAmBK,IAAA,qCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;;;;;;;;;6CAAA,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EAiC3B,CAAA;EAiBX,MAAA,EAAA;;;EAjBuC,CAAA;;cAjC5B,0DAA2B,wCAAA;;UA+BtC,yBAAA,CAAA;;;;;;;;;;;;;MAEuC,OAAA,EAAA;QAmB5B,IAAA,qCA0BX,CAAA,MAAA,EAAA,MAAA,CAAA;QAAA,UAAA,EAAA,IAAA;;;;IA1BoC,UAAA,EAAA,KAAA;;;;UApDE,yBAAA,CAAA;;;;6CAoDF,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EA4BzB,CAAA;EAiBX,YAAA,EAAA;;;;EAjB2B,QAAA,EAAA;;;;;IAAA,IAAA,qCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA/ChB,2DAA4B,wCAAA;;UAiBvC,yBAAA,CAAA;;;;;;;;;UAjBuC,yBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmB5B,wDAAyB,wCAAA;;UA0BpC,yBAAA,CAAA;;;;;;;;;UA1BoC,yBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;cA4BzB,+CAAgB,wCAAA;;UAiB3B,yBAAA,CAAA;;;;;;;;;;;;;;;cAjB2B,yBAAA,CAAA"}
@@ -0,0 +1,256 @@
1
+ import { KBSnapshotModel, RuleVersionModel, SourceDocumentModel, SourceRefModel } from "../entities/models.js";
2
+ import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
3
+ import { ScalarTypeEnum, defineSchemaModel as defineSchemaModel$1 } from "@contractspec/lib.schema";
4
+
5
+ //#region src/operations/kb.ts
6
+ const IngestSourceInput = defineSchemaModel$1({
7
+ name: "KbIngestSourceInput",
8
+ description: "Ingest immutable source metadata referencing a stored file.",
9
+ fields: {
10
+ jurisdiction: {
11
+ type: ScalarTypeEnum.String_unsecure(),
12
+ isOptional: false
13
+ },
14
+ authority: {
15
+ type: ScalarTypeEnum.String_unsecure(),
16
+ isOptional: false
17
+ },
18
+ title: {
19
+ type: ScalarTypeEnum.String_unsecure(),
20
+ isOptional: false
21
+ },
22
+ fetchedAt: {
23
+ type: ScalarTypeEnum.DateTime(),
24
+ isOptional: false
25
+ },
26
+ hash: {
27
+ type: ScalarTypeEnum.String_unsecure(),
28
+ isOptional: false
29
+ },
30
+ fileId: {
31
+ type: ScalarTypeEnum.String_unsecure(),
32
+ isOptional: false
33
+ }
34
+ }
35
+ });
36
+ const UpsertRuleVersionInput = defineSchemaModel$1({
37
+ name: "KbUpsertRuleVersionInput",
38
+ description: "Create a new draft rule version (immutable history).",
39
+ fields: {
40
+ ruleId: {
41
+ type: ScalarTypeEnum.String_unsecure(),
42
+ isOptional: false
43
+ },
44
+ content: {
45
+ type: ScalarTypeEnum.String_unsecure(),
46
+ isOptional: false
47
+ },
48
+ sourceRefs: {
49
+ type: SourceRefModel,
50
+ isArray: true,
51
+ isOptional: false
52
+ }
53
+ }
54
+ });
55
+ const ApproveRuleVersionInput = defineSchemaModel$1({
56
+ name: "KbApproveRuleVersionInput",
57
+ description: "Approve a rule version (human verification).",
58
+ fields: {
59
+ ruleVersionId: {
60
+ type: ScalarTypeEnum.String_unsecure(),
61
+ isOptional: false
62
+ },
63
+ approver: {
64
+ type: ScalarTypeEnum.String_unsecure(),
65
+ isOptional: false
66
+ }
67
+ }
68
+ });
69
+ const PublishSnapshotInput = defineSchemaModel$1({
70
+ name: "KbPublishSnapshotInput",
71
+ description: "Publish a snapshot for a jurisdiction as-of a date.",
72
+ fields: {
73
+ jurisdiction: {
74
+ type: ScalarTypeEnum.String_unsecure(),
75
+ isOptional: false
76
+ },
77
+ asOfDate: {
78
+ type: ScalarTypeEnum.DateTime(),
79
+ isOptional: false
80
+ }
81
+ }
82
+ });
83
+ const SearchKbInput = defineSchemaModel$1({
84
+ name: "KbSearchInput",
85
+ description: "Search within a published snapshot.",
86
+ fields: {
87
+ snapshotId: {
88
+ type: ScalarTypeEnum.String_unsecure(),
89
+ isOptional: false
90
+ },
91
+ jurisdiction: {
92
+ type: ScalarTypeEnum.String_unsecure(),
93
+ isOptional: false
94
+ },
95
+ query: {
96
+ type: ScalarTypeEnum.String_unsecure(),
97
+ isOptional: false
98
+ }
99
+ }
100
+ });
101
+ const SearchKbOutput = defineSchemaModel$1({
102
+ name: "KbSearchOutput",
103
+ description: "Search results constrained to snapshot + jurisdiction.",
104
+ fields: { items: {
105
+ type: defineSchemaModel$1({
106
+ name: "KbSearchResultItem",
107
+ description: "Search result referencing a specific rule version.",
108
+ fields: {
109
+ ruleVersionId: {
110
+ type: ScalarTypeEnum.String_unsecure(),
111
+ isOptional: false
112
+ },
113
+ excerpt: {
114
+ type: ScalarTypeEnum.String_unsecure(),
115
+ isOptional: true
116
+ }
117
+ }
118
+ }),
119
+ isArray: true,
120
+ isOptional: false
121
+ } }
122
+ });
123
+ const KbIngestSourceContract = defineCommand({
124
+ meta: {
125
+ key: "kb.ingestSource",
126
+ title: "Ingest Source",
127
+ version: "1.0.0",
128
+ stability: "experimental",
129
+ owners: ["@examples"],
130
+ tags: [
131
+ "knowledge",
132
+ "sources",
133
+ "ingestion"
134
+ ],
135
+ description: "Ingest immutable source document metadata.",
136
+ goal: "Store traceable source documents for curated KB.",
137
+ context: "Called when an admin uploads/records authoritative sources."
138
+ },
139
+ io: {
140
+ input: IngestSourceInput,
141
+ output: SourceDocumentModel
142
+ },
143
+ policy: { auth: "user" }
144
+ });
145
+ const KbUpsertRuleVersionContract = defineCommand({
146
+ meta: {
147
+ key: "kb.upsertRuleVersion",
148
+ title: "Upsert Rule Version",
149
+ version: "1.0.0",
150
+ stability: "experimental",
151
+ owners: ["@examples"],
152
+ tags: [
153
+ "knowledge",
154
+ "rules",
155
+ "versioning"
156
+ ],
157
+ description: "Create a new draft rule version with source references.",
158
+ goal: "Propose curated knowledge updates with traceability.",
159
+ context: "Automation or curators propose draft rule versions."
160
+ },
161
+ io: {
162
+ input: UpsertRuleVersionInput,
163
+ output: RuleVersionModel,
164
+ errors: {
165
+ SOURCE_REFS_REQUIRED: {
166
+ description: "Rule version must cite at least one sourceRef",
167
+ http: 400,
168
+ gqlCode: "SOURCE_REFS_REQUIRED",
169
+ when: "sourceRefs is empty"
170
+ },
171
+ RULE_NOT_FOUND: {
172
+ description: "Rule does not exist",
173
+ http: 404,
174
+ gqlCode: "RULE_NOT_FOUND",
175
+ when: "ruleId is unknown"
176
+ }
177
+ }
178
+ },
179
+ policy: { auth: "user" }
180
+ });
181
+ const KbApproveRuleVersionContract = defineCommand({
182
+ meta: {
183
+ key: "kb.approveRuleVersion",
184
+ title: "Approve Rule Version",
185
+ version: "1.0.0",
186
+ stability: "experimental",
187
+ owners: ["@examples"],
188
+ tags: [
189
+ "knowledge",
190
+ "rules",
191
+ "approval"
192
+ ],
193
+ description: "Approve a draft rule version.",
194
+ goal: "Human verification step before publishing snapshots.",
195
+ context: "Curators/experts approve proposed KB changes."
196
+ },
197
+ io: {
198
+ input: ApproveRuleVersionInput,
199
+ output: RuleVersionModel
200
+ },
201
+ policy: { auth: "user" }
202
+ });
203
+ const KbPublishSnapshotContract = defineCommand({
204
+ meta: {
205
+ key: "kb.publishSnapshot",
206
+ title: "Publish Snapshot",
207
+ version: "1.0.0",
208
+ stability: "experimental",
209
+ owners: ["@examples"],
210
+ tags: [
211
+ "knowledge",
212
+ "snapshots",
213
+ "publishing"
214
+ ],
215
+ description: "Publish a KB snapshot for a jurisdiction.",
216
+ goal: "Create a stable snapshot that assistant answers can cite.",
217
+ context: "Publishing happens after approvals; snapshot is referenced by answers."
218
+ },
219
+ io: {
220
+ input: PublishSnapshotInput,
221
+ output: KBSnapshotModel,
222
+ errors: { NO_APPROVED_RULES: {
223
+ description: "No approved rule versions available to publish",
224
+ http: 409,
225
+ gqlCode: "NO_APPROVED_RULES",
226
+ when: "jurisdiction has zero approved rule versions"
227
+ } }
228
+ },
229
+ policy: { auth: "user" }
230
+ });
231
+ const KbSearchContract = defineQuery({
232
+ meta: {
233
+ key: "kb.search",
234
+ title: "Search KB",
235
+ version: "1.0.0",
236
+ stability: "experimental",
237
+ owners: ["@examples"],
238
+ tags: [
239
+ "knowledge",
240
+ "search",
241
+ "snapshots"
242
+ ],
243
+ description: "Search within a published KB snapshot.",
244
+ goal: "Provide scoped retrieval for assistant answers.",
245
+ context: "Assistant queries curated rules from a specific snapshot."
246
+ },
247
+ io: {
248
+ input: SearchKbInput,
249
+ output: SearchKbOutput
250
+ },
251
+ policy: { auth: "user" }
252
+ });
253
+
254
+ //#endregion
255
+ export { KbApproveRuleVersionContract, KbIngestSourceContract, KbPublishSnapshotContract, KbSearchContract, KbUpsertRuleVersionContract };
256
+ //# sourceMappingURL=kb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kb.js","names":["defineSchemaModel"],"sources":["../../src/operations/kb.ts"],"sourcesContent":["import { defineCommand, defineQuery } from '@contractspec/lib.contracts';\nimport { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';\n\nimport {\n KBSnapshotModel,\n RuleVersionModel,\n SourceDocumentModel,\n SourceRefModel,\n} from '../entities/models';\n\nconst IngestSourceInput = defineSchemaModel({\n name: 'KbIngestSourceInput',\n description: 'Ingest immutable source metadata referencing a stored file.',\n fields: {\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\nconst UpsertRuleVersionInput = defineSchemaModel({\n name: 'KbUpsertRuleVersionInput',\n description: 'Create a new draft rule version (immutable history).',\n fields: {\n ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n sourceRefs: { type: SourceRefModel, isArray: true, isOptional: false },\n },\n});\n\nconst ApproveRuleVersionInput = defineSchemaModel({\n name: 'KbApproveRuleVersionInput',\n description: 'Approve a rule version (human verification).',\n fields: {\n ruleVersionId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nconst PublishSnapshotInput = defineSchemaModel({\n name: 'KbPublishSnapshotInput',\n description: 'Publish a snapshot for a jurisdiction as-of a date.',\n fields: {\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\nconst SearchKbInput = defineSchemaModel({\n name: 'KbSearchInput',\n description: 'Search within a published snapshot.',\n fields: {\n snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n query: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nconst SearchKbResultItem = defineSchemaModel({\n name: 'KbSearchResultItem',\n description: 'Search result referencing a specific rule version.',\n fields: {\n ruleVersionId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\nconst SearchKbOutput = defineSchemaModel({\n name: 'KbSearchOutput',\n description: 'Search results constrained to snapshot + jurisdiction.',\n fields: {\n items: { type: SearchKbResultItem, isArray: true, isOptional: false },\n },\n});\n\nexport const KbIngestSourceContract = defineCommand({\n meta: {\n key: 'kb.ingestSource',\n title: 'Ingest Source',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge', 'sources', 'ingestion'],\n description: 'Ingest immutable source document metadata.',\n goal: 'Store traceable source documents for curated KB.',\n context: 'Called when an admin uploads/records authoritative sources.',\n },\n io: {\n input: IngestSourceInput,\n output: SourceDocumentModel,\n },\n policy: { auth: 'user' },\n});\n\nexport const KbUpsertRuleVersionContract = defineCommand({\n meta: {\n key: 'kb.upsertRuleVersion',\n title: 'Upsert Rule Version',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge', 'rules', 'versioning'],\n description: 'Create a new draft rule version with source references.',\n goal: 'Propose curated knowledge updates with traceability.',\n context: 'Automation or curators propose draft rule versions.',\n },\n io: {\n input: UpsertRuleVersionInput,\n output: RuleVersionModel,\n errors: {\n SOURCE_REFS_REQUIRED: {\n description: 'Rule version must cite at least one sourceRef',\n http: 400,\n gqlCode: 'SOURCE_REFS_REQUIRED',\n when: 'sourceRefs is empty',\n },\n RULE_NOT_FOUND: {\n description: 'Rule does not exist',\n http: 404,\n gqlCode: 'RULE_NOT_FOUND',\n when: 'ruleId is unknown',\n },\n },\n },\n policy: { auth: 'user' },\n});\n\nexport const KbApproveRuleVersionContract = defineCommand({\n meta: {\n key: 'kb.approveRuleVersion',\n title: 'Approve Rule Version',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge', 'rules', 'approval'],\n description: 'Approve a draft rule version.',\n goal: 'Human verification step before publishing snapshots.',\n context: 'Curators/experts approve proposed KB changes.',\n },\n io: {\n input: ApproveRuleVersionInput,\n output: RuleVersionModel,\n },\n policy: { auth: 'user' },\n});\n\nexport const KbPublishSnapshotContract = defineCommand({\n meta: {\n key: 'kb.publishSnapshot',\n title: 'Publish Snapshot',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge', 'snapshots', 'publishing'],\n description: 'Publish a KB snapshot for a jurisdiction.',\n goal: 'Create a stable snapshot that assistant answers can cite.',\n context:\n 'Publishing happens after approvals; snapshot is referenced by answers.',\n },\n io: {\n input: PublishSnapshotInput,\n output: KBSnapshotModel,\n errors: {\n NO_APPROVED_RULES: {\n description: 'No approved rule versions available to publish',\n http: 409,\n gqlCode: 'NO_APPROVED_RULES',\n when: 'jurisdiction has zero approved rule versions',\n },\n },\n },\n policy: { auth: 'user' },\n});\n\nexport const KbSearchContract = defineQuery({\n meta: {\n key: 'kb.search',\n title: 'Search KB',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['knowledge', 'search', 'snapshots'],\n description: 'Search within a published KB snapshot.',\n goal: 'Provide scoped retrieval for assistant answers.',\n context: 'Assistant queries curated rules from a specific snapshot.',\n },\n io: {\n input: SearchKbInput,\n output: SearchKbOutput,\n },\n policy: { auth: 'user' },\n});\n"],"mappings":"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"}
@@ -0,0 +1,7 @@
1
+ import * as _contractspec_lib_contracts9 from "@contractspec/lib.contracts";
2
+
3
+ //#region src/versioned-knowledge-base.feature.d.ts
4
+ declare const VersionedKnowledgeBaseFeature: _contractspec_lib_contracts9.FeatureModuleSpec;
5
+ //#endregion
6
+ export { VersionedKnowledgeBaseFeature };
7
+ //# sourceMappingURL=versioned-knowledge-base.feature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versioned-knowledge-base.feature.d.ts","names":[],"sources":["../src/versioned-knowledge-base.feature.ts"],"sourcesContent":[],"mappings":";;;cAEa,+BA+BX,4BAAA,CA/BwC"}
@@ -0,0 +1,70 @@
1
+ import { defineFeature } from "@contractspec/lib.contracts";
2
+
3
+ //#region src/versioned-knowledge-base.feature.ts
4
+ const VersionedKnowledgeBaseFeature = defineFeature({
5
+ meta: {
6
+ key: "versioned-knowledge-base",
7
+ version: "1.0.0",
8
+ title: "Versioned Knowledge Base",
9
+ description: "Curated KB with immutable sources, rule versions, and published snapshots.",
10
+ domain: "knowledge",
11
+ owners: ["@examples"],
12
+ tags: [
13
+ "knowledge",
14
+ "versioning",
15
+ "snapshots"
16
+ ],
17
+ stability: "experimental"
18
+ },
19
+ operations: [
20
+ {
21
+ key: "kb.ingestSource",
22
+ version: "1.0.0"
23
+ },
24
+ {
25
+ key: "kb.upsertRuleVersion",
26
+ version: "1.0.0"
27
+ },
28
+ {
29
+ key: "kb.approveRuleVersion",
30
+ version: "1.0.0"
31
+ },
32
+ {
33
+ key: "kb.publishSnapshot",
34
+ version: "1.0.0"
35
+ },
36
+ {
37
+ key: "kb.search",
38
+ version: "1.0.0"
39
+ }
40
+ ],
41
+ events: [
42
+ {
43
+ key: "kb.source.ingested",
44
+ version: "1.0.0"
45
+ },
46
+ {
47
+ key: "kb.ruleVersion.created",
48
+ version: "1.0.0"
49
+ },
50
+ {
51
+ key: "kb.ruleVersion.approved",
52
+ version: "1.0.0"
53
+ },
54
+ {
55
+ key: "kb.snapshot.published",
56
+ version: "1.0.0"
57
+ }
58
+ ],
59
+ presentations: [],
60
+ opToPresentation: [],
61
+ presentationsTargets: [],
62
+ capabilities: { requires: [{
63
+ key: "knowledge",
64
+ version: "1.0.0"
65
+ }] }
66
+ });
67
+
68
+ //#endregion
69
+ export { VersionedKnowledgeBaseFeature };
70
+ //# sourceMappingURL=versioned-knowledge-base.feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versioned-knowledge-base.feature.js","names":[],"sources":["../src/versioned-knowledge-base.feature.ts"],"sourcesContent":["import { defineFeature } from '@contractspec/lib.contracts';\n\nexport const VersionedKnowledgeBaseFeature = defineFeature({\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, rule versions, and published snapshots.',\n domain: 'knowledge',\n owners: ['@examples'],\n tags: ['knowledge', 'versioning', 'snapshots'],\n stability: 'experimental',\n },\n operations: [\n { key: 'kb.ingestSource', version: '1.0.0' },\n { key: 'kb.upsertRuleVersion', version: '1.0.0' },\n { key: 'kb.approveRuleVersion', version: '1.0.0' },\n { key: 'kb.publishSnapshot', version: '1.0.0' },\n { key: 'kb.search', version: '1.0.0' },\n ],\n events: [\n { key: 'kb.source.ingested', version: '1.0.0' },\n { key: 'kb.ruleVersion.created', version: '1.0.0' },\n { key: 'kb.ruleVersion.approved', version: '1.0.0' },\n { key: 'kb.snapshot.published', version: '1.0.0' },\n ],\n presentations: [],\n opToPresentation: [],\n presentationsTargets: [],\n capabilities: {\n requires: [{ key: 'knowledge', version: '1.0.0' }],\n },\n});\n"],"mappings":";;;AAEA,MAAa,gCAAgC,cAAc;CACzD,MAAM;EACJ,KAAK;EACL,SAAS;EACT,OAAO;EACP,aACE;EACF,QAAQ;EACR,QAAQ,CAAC,YAAY;EACrB,MAAM;GAAC;GAAa;GAAc;GAAY;EAC9C,WAAW;EACZ;CACD,YAAY;EACV;GAAE,KAAK;GAAmB,SAAS;GAAS;EAC5C;GAAE,KAAK;GAAwB,SAAS;GAAS;EACjD;GAAE,KAAK;GAAyB,SAAS;GAAS;EAClD;GAAE,KAAK;GAAsB,SAAS;GAAS;EAC/C;GAAE,KAAK;GAAa,SAAS;GAAS;EACvC;CACD,QAAQ;EACN;GAAE,KAAK;GAAsB,SAAS;GAAS;EAC/C;GAAE,KAAK;GAA0B,SAAS;GAAS;EACnD;GAAE,KAAK;GAA2B,SAAS;GAAS;EACpD;GAAE,KAAK;GAAyB,SAAS;GAAS;EACnD;CACD,eAAe,EAAE;CACjB,kBAAkB,EAAE;CACpB,sBAAsB,EAAE;CACxB,cAAc,EACZ,UAAU,CAAC;EAAE,KAAK;EAAa,SAAS;EAAS,CAAC,EACnD;CACF,CAAC"}
package/example.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './src/example';