@contractspec/lib.contracts 0.0.0-canary-20260119225944 → 0.0.0-canary-20260202053150

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 (166) hide show
  1. package/dist/app-config/{contracts.d.ts → app-config.contracts.d.ts} +52 -52
  2. package/dist/app-config/{contracts.js → app-config.contracts.js} +1 -1
  3. package/dist/app-config/lifecycle-contracts.d.ts +55 -55
  4. package/dist/app-config/runtime.d.ts +4 -4
  5. package/dist/app-config/spec.d.ts +2 -2
  6. package/dist/capabilities/capabilities.d.ts +64 -5
  7. package/dist/capabilities/capabilities.js +125 -0
  8. package/dist/capabilities/context.d.ts +88 -0
  9. package/dist/capabilities/context.js +87 -0
  10. package/dist/capabilities/docs/capabilities.docblock.js +191 -2
  11. package/dist/capabilities/guards.d.ts +110 -0
  12. package/dist/capabilities/guards.js +146 -0
  13. package/dist/capabilities/index.d.ts +4 -1
  14. package/dist/capabilities/index.js +4 -1
  15. package/dist/capabilities/validation.d.ts +76 -0
  16. package/dist/capabilities/validation.js +141 -0
  17. package/dist/client/react/feature-render.d.ts +2 -2
  18. package/dist/data-views/data-views.d.ts +2 -1
  19. package/dist/data-views/index.d.ts +2 -1
  20. package/dist/data-views/registry.d.ts +1 -1
  21. package/dist/data-views/report/contractVerificationTable.d.ts +10 -0
  22. package/dist/data-views/report/contractVerificationTable.js +95 -0
  23. package/dist/data-views/runtime.d.ts +2 -2
  24. package/dist/data-views/spec.d.ts +2 -8
  25. package/dist/data-views/types.d.ts +1 -1
  26. package/dist/docs/capabilities/documentationSystem.capability.d.ts +7 -0
  27. package/dist/docs/capabilities/documentationSystem.capability.js +71 -0
  28. package/dist/docs/capabilities/index.d.ts +2 -0
  29. package/dist/docs/capabilities/index.js +3 -0
  30. package/dist/docs/commands/docsGenerate.command.d.ts +95 -0
  31. package/dist/docs/commands/docsGenerate.command.js +142 -0
  32. package/dist/docs/commands/docsPublish.command.d.ts +64 -0
  33. package/dist/docs/commands/docsPublish.command.js +107 -0
  34. package/dist/docs/commands/index.d.ts +3 -0
  35. package/dist/docs/commands/index.js +4 -0
  36. package/dist/docs/constants.d.ts +7 -0
  37. package/dist/docs/constants.js +10 -0
  38. package/dist/docs/contracts.d.ts +442 -0
  39. package/dist/docs/contracts.js +58 -0
  40. package/dist/docs/ensure-docblocks.d.ts +1 -0
  41. package/dist/docs/ensure-docblocks.js +1 -0
  42. package/dist/docs/events/docsGenerated.event.d.ts +62 -0
  43. package/dist/docs/events/docsGenerated.event.js +53 -0
  44. package/dist/docs/events/docsPublished.event.d.ts +70 -0
  45. package/dist/docs/events/docsPublished.event.js +57 -0
  46. package/dist/docs/events/index.d.ts +3 -0
  47. package/dist/docs/events/index.js +4 -0
  48. package/dist/docs/forms/docsSearch.form.d.ts +22 -0
  49. package/dist/docs/forms/docsSearch.form.js +113 -0
  50. package/dist/docs/forms/index.d.ts +2 -0
  51. package/dist/docs/forms/index.js +3 -0
  52. package/dist/docs/index.d.ts +23 -2
  53. package/dist/docs/index.js +25 -1
  54. package/dist/docs/presentations/docsLayout.presentation.d.ts +7 -0
  55. package/dist/docs/presentations/docsLayout.presentation.js +35 -0
  56. package/dist/docs/presentations/docsReferencePage.presentation.d.ts +7 -0
  57. package/dist/docs/presentations/docsReferencePage.presentation.js +35 -0
  58. package/dist/docs/presentations/index.d.ts +3 -0
  59. package/dist/docs/presentations/index.js +4 -0
  60. package/dist/docs/queries/contractReference.query.d.ts +217 -0
  61. package/dist/docs/queries/contractReference.query.js +125 -0
  62. package/dist/docs/queries/docsIndex.query.d.ts +272 -0
  63. package/dist/docs/queries/docsIndex.query.js +133 -0
  64. package/dist/docs/queries/index.d.ts +3 -0
  65. package/dist/docs/queries/index.js +4 -0
  66. package/dist/docs/tech/cli.docblock.js +10 -0
  67. package/dist/docs/tech/docs-system.docblock.d.ts +1 -0
  68. package/dist/docs/tech/docs-system.docblock.js +128 -0
  69. package/dist/docs/tech/report-verification-table.docblock.d.ts +1 -0
  70. package/dist/docs/tech/report-verification-table.docblock.js +50 -0
  71. package/dist/docs/views/contractReference.dataView.d.ts +7 -0
  72. package/dist/docs/views/contractReference.dataView.js +80 -0
  73. package/dist/docs/views/docsIndex.dataView.d.ts +7 -0
  74. package/dist/docs/views/docsIndex.dataView.js +136 -0
  75. package/dist/docs/views/exampleCatalog.dataView.d.ts +7 -0
  76. package/dist/docs/views/exampleCatalog.dataView.js +91 -0
  77. package/dist/docs/views/index.d.ts +4 -0
  78. package/dist/docs/views/index.js +5 -0
  79. package/dist/events.d.ts +80 -14
  80. package/dist/events.js +33 -3
  81. package/dist/examples/schema.d.ts +12 -12
  82. package/dist/examples/types.d.ts +1 -1
  83. package/dist/experiments/spec.d.ts +9 -6
  84. package/dist/features/index.d.ts +2 -2
  85. package/dist/features/install.d.ts +4 -4
  86. package/dist/features/types.d.ts +28 -32
  87. package/dist/forms/forms.d.ts +1 -1
  88. package/dist/index.d.ts +60 -31
  89. package/dist/index.js +32 -4
  90. package/dist/install.d.ts +1 -1
  91. package/dist/integrations/openbanking/contracts/accounts.d.ts +67 -67
  92. package/dist/integrations/openbanking/contracts/balances.d.ts +35 -35
  93. package/dist/integrations/openbanking/contracts/transactions.d.ts +49 -49
  94. package/dist/integrations/openbanking/models.d.ts +55 -55
  95. package/dist/integrations/operations.d.ts +103 -103
  96. package/dist/integrations/spec.d.ts +2 -2
  97. package/dist/jsonschema.d.ts +1 -1
  98. package/dist/knowledge/operations.d.ts +67 -67
  99. package/dist/knowledge/spec.d.ts +1 -1
  100. package/dist/llm/exporters.d.ts +4 -4
  101. package/dist/llm/types.d.ts +1 -1
  102. package/dist/markdown.d.ts +2 -2
  103. package/dist/operations/index.d.ts +4 -1
  104. package/dist/operations/index.js +4 -1
  105. package/dist/operations/operation.d.ts +8 -2
  106. package/dist/operations/registry.d.ts +1 -1
  107. package/dist/operations/report/getContractVerificationStatus.d.ts +75 -0
  108. package/dist/operations/report/getContractVerificationStatus.js +96 -0
  109. package/dist/operations/report/index.d.ts +13 -0
  110. package/dist/operations/report/index.js +45 -0
  111. package/dist/ownership.d.ts +133 -8
  112. package/dist/ownership.js +25 -0
  113. package/dist/policy/context.d.ts +237 -0
  114. package/dist/policy/context.js +227 -0
  115. package/dist/policy/guards.d.ts +145 -0
  116. package/dist/policy/guards.js +254 -0
  117. package/dist/policy/index.d.ts +12 -1
  118. package/dist/policy/index.js +11 -1
  119. package/dist/policy/spec.d.ts +7 -4
  120. package/dist/policy/validation.d.ts +67 -0
  121. package/dist/policy/validation.js +307 -0
  122. package/dist/presentations/presentations.d.ts +6 -0
  123. package/dist/presentations/registry.d.ts +1 -1
  124. package/dist/registry.d.ts +1 -1
  125. package/dist/serialization/index.d.ts +3 -0
  126. package/dist/serialization/index.js +3 -0
  127. package/dist/serialization/serializers.d.ts +40 -0
  128. package/dist/serialization/serializers.js +148 -0
  129. package/dist/serialization/types.d.ts +103 -0
  130. package/dist/serialization/types.js +0 -0
  131. package/dist/server/rest-elysia.d.ts +1 -1
  132. package/dist/server/rest-express.d.ts +1 -1
  133. package/dist/server/rest-generic.d.ts +1 -1
  134. package/dist/server/rest-next-app.d.ts +1 -1
  135. package/dist/server/rest-next-mcp.d.ts +1 -1
  136. package/dist/server/rest-next-pages.d.ts +1 -1
  137. package/dist/telemetry/spec.d.ts +1 -1
  138. package/dist/telemetry/tracker.d.ts +3 -2
  139. package/dist/tests/runner.d.ts +1 -1
  140. package/dist/tests/spec.d.ts +17 -12
  141. package/dist/themes.d.ts +8 -5
  142. package/dist/translations/index.d.ts +6 -0
  143. package/dist/translations/index.js +5 -0
  144. package/dist/translations/registry.d.ts +144 -0
  145. package/dist/translations/registry.js +223 -0
  146. package/dist/translations/spec.d.ts +126 -0
  147. package/dist/translations/spec.js +31 -0
  148. package/dist/translations/validation.d.ts +85 -0
  149. package/dist/translations/validation.js +328 -0
  150. package/dist/types.d.ts +142 -16
  151. package/dist/versioning/index.d.ts +2 -1
  152. package/dist/versioning/index.js +2 -1
  153. package/dist/versioning/refs.d.ts +179 -0
  154. package/dist/versioning/refs.js +161 -0
  155. package/dist/workflow/context.d.ts +191 -0
  156. package/dist/workflow/context.js +227 -0
  157. package/dist/workflow/index.d.ts +6 -3
  158. package/dist/workflow/index.js +4 -2
  159. package/dist/workflow/spec.d.ts +4 -11
  160. package/dist/workflow/validation.d.ts +64 -2
  161. package/dist/workflow/validation.js +194 -1
  162. package/dist/workspace-config/contractsrc-schema.d.ts +3 -3
  163. package/dist/workspace-config/contractsrc-schema.js +1 -0
  164. package/dist/workspace-config/contractsrc-types.d.ts +7 -8
  165. package/dist/workspace-config/index.d.ts +2 -2
  166. package/package.json +52 -9
@@ -0,0 +1,50 @@
1
+ import { registerDocBlocks } from "../registry.js";
2
+
3
+ //#region src/docs/tech/report-verification-table.docblock.ts
4
+ registerDocBlocks([{
5
+ id: "docs.tech.report-verification-table",
6
+ title: "Contract Verification Table",
7
+ summary: "How the impact report renders per-contract verification status.",
8
+ kind: "how",
9
+ visibility: "public",
10
+ route: "/docs/tech/report/verification-table",
11
+ tags: [
12
+ "report",
13
+ "drift",
14
+ "verification",
15
+ "impact"
16
+ ],
17
+ owners: ["platform.core"],
18
+ domain: "report",
19
+ body: `# Contract Verification Table
20
+
21
+ The impact report includes an optional per-contract verification table that summarises the health of each contract at a glance.
22
+
23
+ ## Columns
24
+
25
+ | Column | Description |
26
+ |--------|-------------|
27
+ | Contract / Endpoint / Event | Fully qualified contract name (e.g. \`user.create\`) |
28
+ | Drift debt | Number of mismatches currently detected |
29
+ | Time since verified | Human-friendly elapsed time (e.g. "23 days") or "Never" |
30
+ | Surfaces covered | Comma-separated list (API, runtime validation, UI form, docs/examples, permissions) |
31
+ | Last verified commit | Short SHA of the last drift-free commit |
32
+
33
+ ## Data flow
34
+
35
+ 1. The drift detector produces per-contract mismatch counts.
36
+ 2. \`.contractspec/verified.json\` records the last clean commit per contract.
37
+ 3. The report script reads both sources and renders the Markdown table.
38
+
39
+ ## Backward compatibility
40
+
41
+ When \`contracts\` is absent from the report JSON, the table is skipped and the existing report sections render unchanged.
42
+
43
+ ## Contracts
44
+
45
+ - Query: \`report.getContractVerificationStatus\` (v1.0.0)
46
+ - Data view: \`report.contractVerificationTable\` (v1.0.0)
47
+ `
48
+ }]);
49
+
50
+ //#endregion
@@ -0,0 +1,7 @@
1
+ import { DataViewSpec } from "../../data-views/spec.js";
2
+ import "../../index.js";
3
+
4
+ //#region src/docs/views/contractReference.dataView.d.ts
5
+ declare const ContractReferenceDataView: DataViewSpec;
6
+ //#endregion
7
+ export { ContractReferenceDataView };
@@ -0,0 +1,80 @@
1
+ import { defineDataView } from "../../data-views/spec.js";
2
+ import "../../data-views/index.js";
3
+ import { DOCS_DOMAIN, DOCS_OWNERS, DOCS_STABILITY, DOCS_TAGS } from "../constants.js";
4
+ import { docId } from "../registry.js";
5
+ import "../ensure-docblocks.js";
6
+ import { ContractReferenceQuery } from "../queries/contractReference.query.js";
7
+
8
+ //#region src/docs/views/contractReference.dataView.ts
9
+ const ContractReferenceDataView = defineDataView({
10
+ meta: {
11
+ key: "docs.contract.reference.view",
12
+ title: "Contract Reference",
13
+ version: "1.0.0",
14
+ description: "Detail view for a single contract reference.",
15
+ domain: DOCS_DOMAIN,
16
+ owners: DOCS_OWNERS,
17
+ tags: [...DOCS_TAGS, "reference"],
18
+ stability: DOCS_STABILITY,
19
+ entity: "contract-reference",
20
+ docId: [docId("docs.tech.docs-reference")]
21
+ },
22
+ source: { primary: {
23
+ key: ContractReferenceQuery.meta.key,
24
+ version: ContractReferenceQuery.meta.version
25
+ } },
26
+ view: {
27
+ kind: "detail",
28
+ fields: [
29
+ {
30
+ key: "key",
31
+ label: "Key",
32
+ dataPath: "reference.key"
33
+ },
34
+ {
35
+ key: "version",
36
+ label: "Version",
37
+ dataPath: "reference.version"
38
+ },
39
+ {
40
+ key: "type",
41
+ label: "Type",
42
+ dataPath: "reference.type"
43
+ },
44
+ {
45
+ key: "title",
46
+ label: "Title",
47
+ dataPath: "reference.title"
48
+ },
49
+ {
50
+ key: "description",
51
+ label: "Description",
52
+ dataPath: "reference.description"
53
+ },
54
+ {
55
+ key: "tags",
56
+ label: "Tags",
57
+ dataPath: "reference.tags"
58
+ },
59
+ {
60
+ key: "owners",
61
+ label: "Owners",
62
+ dataPath: "reference.owners"
63
+ },
64
+ {
65
+ key: "stability",
66
+ label: "Stability",
67
+ dataPath: "reference.stability"
68
+ }
69
+ ],
70
+ primaryField: "title",
71
+ secondaryFields: ["description"]
72
+ },
73
+ policy: {
74
+ flags: [],
75
+ pii: []
76
+ }
77
+ });
78
+
79
+ //#endregion
80
+ export { ContractReferenceDataView };
@@ -0,0 +1,7 @@
1
+ import { DataViewSpec } from "../../data-views/spec.js";
2
+ import "../../index.js";
3
+
4
+ //#region src/docs/views/docsIndex.dataView.d.ts
5
+ declare const DocsIndexDataView: DataViewSpec;
6
+ //#endregion
7
+ export { DocsIndexDataView };
@@ -0,0 +1,136 @@
1
+ import { defineDataView } from "../../data-views/spec.js";
2
+ import "../../data-views/index.js";
3
+ import { DOCS_DOMAIN, DOCS_OWNERS, DOCS_STABILITY, DOCS_TAGS } from "../constants.js";
4
+ import { docId } from "../registry.js";
5
+ import "../ensure-docblocks.js";
6
+ import { DocsIndexQuery } from "../queries/docsIndex.query.js";
7
+
8
+ //#region src/docs/views/docsIndex.dataView.ts
9
+ const DocsIndexDataView = defineDataView({
10
+ meta: {
11
+ key: "docs.index.view",
12
+ title: "Docs Index",
13
+ version: "1.0.0",
14
+ description: "List and filter documentation entries.",
15
+ domain: DOCS_DOMAIN,
16
+ owners: DOCS_OWNERS,
17
+ tags: [...DOCS_TAGS, "index"],
18
+ stability: DOCS_STABILITY,
19
+ entity: "docs",
20
+ docId: [docId("docs.tech.docs-search")]
21
+ },
22
+ source: { primary: {
23
+ key: DocsIndexQuery.meta.key,
24
+ version: DocsIndexQuery.meta.version
25
+ } },
26
+ view: {
27
+ kind: "list",
28
+ fields: [
29
+ {
30
+ key: "id",
31
+ label: "ID",
32
+ dataPath: "id"
33
+ },
34
+ {
35
+ key: "title",
36
+ label: "Title",
37
+ dataPath: "title"
38
+ },
39
+ {
40
+ key: "summary",
41
+ label: "Summary",
42
+ dataPath: "summary"
43
+ },
44
+ {
45
+ key: "route",
46
+ label: "Route",
47
+ dataPath: "route"
48
+ },
49
+ {
50
+ key: "tags",
51
+ label: "Tags",
52
+ dataPath: "tags",
53
+ format: "badge"
54
+ },
55
+ {
56
+ key: "kind",
57
+ label: "Kind",
58
+ dataPath: "kind"
59
+ },
60
+ {
61
+ key: "visibility",
62
+ label: "Visibility",
63
+ dataPath: "visibility"
64
+ }
65
+ ],
66
+ primaryField: "title",
67
+ secondaryFields: ["summary", "route"],
68
+ filters: [
69
+ {
70
+ key: "query",
71
+ label: "Search",
72
+ field: "query",
73
+ type: "search"
74
+ },
75
+ {
76
+ key: "visibility",
77
+ label: "Visibility",
78
+ field: "visibility",
79
+ type: "enum",
80
+ options: [
81
+ {
82
+ value: "public",
83
+ label: "Public"
84
+ },
85
+ {
86
+ value: "internal",
87
+ label: "Internal"
88
+ },
89
+ {
90
+ value: "mixed",
91
+ label: "Mixed"
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ key: "kind",
97
+ label: "Kind",
98
+ field: "kind",
99
+ type: "enum",
100
+ options: [
101
+ {
102
+ value: "goal",
103
+ label: "Goal"
104
+ },
105
+ {
106
+ value: "how",
107
+ label: "How"
108
+ },
109
+ {
110
+ value: "usage",
111
+ label: "Usage"
112
+ },
113
+ {
114
+ value: "reference",
115
+ label: "Reference"
116
+ },
117
+ {
118
+ value: "faq",
119
+ label: "FAQ"
120
+ },
121
+ {
122
+ value: "changelog",
123
+ label: "Changelog"
124
+ }
125
+ ]
126
+ }
127
+ ]
128
+ },
129
+ policy: {
130
+ flags: [],
131
+ pii: []
132
+ }
133
+ });
134
+
135
+ //#endregion
136
+ export { DocsIndexDataView };
@@ -0,0 +1,7 @@
1
+ import { DataViewSpec } from "../../data-views/spec.js";
2
+ import "../../index.js";
3
+
4
+ //#region src/docs/views/exampleCatalog.dataView.d.ts
5
+ declare const ExampleCatalogDataView: DataViewSpec;
6
+ //#endregion
7
+ export { ExampleCatalogDataView };
@@ -0,0 +1,91 @@
1
+ import { defineDataView } from "../../data-views/spec.js";
2
+ import "../../data-views/index.js";
3
+ import { DOCS_DOMAIN, DOCS_OWNERS, DOCS_STABILITY, DOCS_TAGS } from "../constants.js";
4
+ import { docId } from "../registry.js";
5
+ import "../ensure-docblocks.js";
6
+ import { DocsIndexQuery } from "../queries/docsIndex.query.js";
7
+
8
+ //#region src/docs/views/exampleCatalog.dataView.ts
9
+ const ExampleCatalogDataView = defineDataView({
10
+ meta: {
11
+ key: "docs.examples.catalog.view",
12
+ title: "Examples Catalog",
13
+ version: "1.0.0",
14
+ description: "Catalog view of ContractSpec examples and demos.",
15
+ domain: DOCS_DOMAIN,
16
+ owners: DOCS_OWNERS,
17
+ tags: [...DOCS_TAGS, "examples"],
18
+ stability: DOCS_STABILITY,
19
+ entity: "docs-examples",
20
+ docId: [docId("docs.tech.docs-examples")]
21
+ },
22
+ source: { primary: {
23
+ key: DocsIndexQuery.meta.key,
24
+ version: DocsIndexQuery.meta.version
25
+ } },
26
+ view: {
27
+ kind: "grid",
28
+ fields: [
29
+ {
30
+ key: "id",
31
+ label: "ID",
32
+ dataPath: "id"
33
+ },
34
+ {
35
+ key: "title",
36
+ label: "Title",
37
+ dataPath: "title"
38
+ },
39
+ {
40
+ key: "summary",
41
+ label: "Summary",
42
+ dataPath: "summary"
43
+ },
44
+ {
45
+ key: "route",
46
+ label: "Route",
47
+ dataPath: "route"
48
+ },
49
+ {
50
+ key: "tags",
51
+ label: "Tags",
52
+ dataPath: "tags",
53
+ format: "badge"
54
+ }
55
+ ],
56
+ primaryField: "title",
57
+ secondaryFields: ["summary"],
58
+ filters: [{
59
+ key: "query",
60
+ label: "Search",
61
+ field: "query",
62
+ type: "search"
63
+ }, {
64
+ key: "tags",
65
+ label: "Tags",
66
+ field: "tag",
67
+ type: "enum",
68
+ options: [
69
+ {
70
+ value: "examples",
71
+ label: "Examples"
72
+ },
73
+ {
74
+ value: "templates",
75
+ label: "Templates"
76
+ },
77
+ {
78
+ value: "sandbox",
79
+ label: "Sandbox"
80
+ }
81
+ ]
82
+ }]
83
+ },
84
+ policy: {
85
+ flags: [],
86
+ pii: []
87
+ }
88
+ });
89
+
90
+ //#endregion
91
+ export { ExampleCatalogDataView };
@@ -0,0 +1,4 @@
1
+ import { DocsIndexDataView } from "./docsIndex.dataView.js";
2
+ import { ContractReferenceDataView } from "./contractReference.dataView.js";
3
+ import { ExampleCatalogDataView } from "./exampleCatalog.dataView.js";
4
+ export { ContractReferenceDataView, DocsIndexDataView, ExampleCatalogDataView };
@@ -0,0 +1,5 @@
1
+ import { DocsIndexDataView } from "./docsIndex.dataView.js";
2
+ import { ContractReferenceDataView } from "./contractReference.dataView.js";
3
+ import { ExampleCatalogDataView } from "./exampleCatalog.dataView.js";
4
+
5
+ export { ContractReferenceDataView, DocsIndexDataView, ExampleCatalogDataView };
package/dist/events.d.ts CHANGED
@@ -1,45 +1,111 @@
1
+ import { CapabilityRef } from "./capabilities/capabilities.js";
2
+ import { SpecContractRegistry } from "./registry.js";
1
3
  import { DocId } from "./docs/registry.js";
2
4
  import { OwnerShipMeta } from "./ownership.js";
3
- import { SpecContractRegistry } from "./registry.js";
4
5
  import { AnySchemaModel } from "@contractspec/lib.schema";
5
6
 
6
7
  //#region src/events.d.ts
8
+
9
+ /**
10
+ * Metadata for an event specification.
11
+ * Extends OwnerShipMeta with event-specific documentation.
12
+ */
7
13
  interface EventSpecMeta extends Omit<OwnerShipMeta, 'docId'> {
8
- /** Doc block(s) for this operation. */
14
+ /** Associated DocBlock identifiers for this event. */
9
15
  docId?: DocId[];
10
16
  }
11
17
  /**
12
- * Typed event specification. Declare once, validate payloads at publish time,
13
- * and guard emissions via the contracts runtime.
18
+ * Typed event specification.
19
+ *
20
+ * Declare once, validate payloads at publish time, and guard emissions
21
+ * via the contracts runtime. Events are the backbone of event-driven
22
+ * architectures in ContractSpec.
23
+ *
24
+ * @typeParam T - The SchemaModel type defining the event payload structure
14
25
  */
15
26
  interface EventSpec<T extends AnySchemaModel> {
27
+ /** Event metadata including key, version, and ownership. */
16
28
  meta: EventSpecMeta;
17
- /** JSON-like paths to redact from logs/exports. */
29
+ /**
30
+ * Optional reference to the capability that provides this event.
31
+ * Used for bidirectional linking between capabilities and events.
32
+ */
33
+ capability?: CapabilityRef;
34
+ /**
35
+ * JSON paths to PII fields that should be redacted in logs/exports.
36
+ * @example ['email', 'user.phone', 'billing.address']
37
+ */
18
38
  pii?: string[];
19
39
  /** Event payload schema from @contractspec/lib.schema. */
20
40
  payload: T;
21
41
  }
42
+ /**
43
+ * Type alias for any EventSpec regardless of payload type.
44
+ * Useful for collections and registries.
45
+ */
22
46
  type AnyEventSpec<T extends AnySchemaModel = AnySchemaModel> = EventSpec<T>;
23
- /** Identity function to keep type inference when declaring events. */
47
+ /**
48
+ * Identity function to define an event spec with full type inference.
49
+ *
50
+ * @param e - The event specification
51
+ * @returns The same event specification with preserved types
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const MyEvent = defineEvent({
56
+ * meta: { key: 'my.event', version: '1.0.0', ... },
57
+ * payload: myPayloadSchema,
58
+ * });
59
+ * ```
60
+ */
24
61
  declare function defineEvent<T extends AnySchemaModel>(e: EventSpec<T>): EventSpec<T>;
62
+ /**
63
+ * Wrapper for a published event with metadata.
64
+ *
65
+ * Used when events are serialized for transport or storage.
66
+ * Contains the validated payload plus envelope metadata.
67
+ *
68
+ * @typeParam T - The payload type
69
+ */
25
70
  interface EventEnvelope<T> {
26
- /** Unique identifier for the published event (UUID recommended). */
71
+ /** Unique identifier for this event instance (UUID recommended). */
27
72
  id: string;
28
- /** ISO timestamp when the event occurred. */
73
+ /** ISO 8601 timestamp when the event occurred. */
29
74
  occurredAt: string;
30
- /** Optional trace identifier for correlating across services. */
75
+ /** Trace identifier for correlating across services. */
31
76
  traceId?: string;
32
- /** Event name as published (should match spec.name). */
77
+ /** Event key (should match spec.meta.key). */
33
78
  key: string;
34
- /** Event version as published (should match spec.version). */
79
+ /** Event version (should match spec.meta.version). */
35
80
  version: string;
36
- /** Validated payload. */
81
+ /** Validated event payload. */
37
82
  payload: T;
38
83
  }
84
+ /**
85
+ * Template literal type for event keys.
86
+ * Format: "key.vversion" (e.g., "user.created.v1.0.0")
87
+ */
39
88
  type EventKey = `${string}.v${string}`;
40
- /** Build a stable string key for an event name/version pair. */
89
+ /**
90
+ * Builds a stable string key for an event name/version pair.
91
+ *
92
+ * @param key - The event key (e.g., "user.created")
93
+ * @param version - The event version (e.g., "1.0.0")
94
+ * @returns A string in format "key.vversion"
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const key = eventKey('user.created', '1.0.0');
99
+ * // "user.created.v1.0.0"
100
+ * ```
101
+ */
41
102
  declare const eventKey: (key: string, version: string) => EventKey;
42
- /** In-memory registry for EventSpec. */
103
+ /**
104
+ * In-memory registry for EventSpec instances.
105
+ *
106
+ * Provides registration, lookup, and listing of event specifications.
107
+ * Used by the contracts runtime to validate event emissions.
108
+ */
43
109
  declare class EventRegistry extends SpecContractRegistry<'event', AnyEventSpec> {
44
110
  constructor(items?: AnyEventSpec[]);
45
111
  }
package/dist/events.js CHANGED
@@ -2,13 +2,43 @@ import { SpecContractRegistry } from "./registry.js";
2
2
  import "@contractspec/lib.schema";
3
3
 
4
4
  //#region src/events.ts
5
- /** Identity function to keep type inference when declaring events. */
5
+ /**
6
+ * Identity function to define an event spec with full type inference.
7
+ *
8
+ * @param e - The event specification
9
+ * @returns The same event specification with preserved types
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const MyEvent = defineEvent({
14
+ * meta: { key: 'my.event', version: '1.0.0', ... },
15
+ * payload: myPayloadSchema,
16
+ * });
17
+ * ```
18
+ */
6
19
  function defineEvent(e) {
7
20
  return e;
8
21
  }
9
- /** Build a stable string key for an event name/version pair. */
22
+ /**
23
+ * Builds a stable string key for an event name/version pair.
24
+ *
25
+ * @param key - The event key (e.g., "user.created")
26
+ * @param version - The event version (e.g., "1.0.0")
27
+ * @returns A string in format "key.vversion"
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const key = eventKey('user.created', '1.0.0');
32
+ * // "user.created.v1.0.0"
33
+ * ```
34
+ */
10
35
  const eventKey = (key, version) => `${key}.v${version}`;
11
- /** In-memory registry for EventSpec. */
36
+ /**
37
+ * In-memory registry for EventSpec instances.
38
+ *
39
+ * Provides registration, lookup, and listing of event specifications.
40
+ * Used by the contracts runtime to validate event emissions.
41
+ */
12
42
  var EventRegistry = class extends SpecContractRegistry {
13
43
  constructor(items) {
14
44
  super("event", items);
@@ -3,11 +3,11 @@ import { z as z$1 } from "zod";
3
3
 
4
4
  //#region src/examples/schema.d.ts
5
5
  declare const ExampleKindSchema: z$1.ZodEnum<{
6
+ integration: "integration";
7
+ knowledge: "knowledge";
6
8
  library: "library";
7
9
  workflow: "workflow";
8
- knowledge: "knowledge";
9
10
  template: "template";
10
- integration: "integration";
11
11
  blueprint: "blueprint";
12
12
  ui: "ui";
13
13
  script: "script";
@@ -18,10 +18,10 @@ declare const ExampleVisibilitySchema: z$1.ZodEnum<{
18
18
  internal: "internal";
19
19
  }>;
20
20
  declare const ExampleSandboxModeSchema: z$1.ZodEnum<{
21
+ markdown: "markdown";
21
22
  playground: "playground";
22
23
  specs: "specs";
23
24
  builder: "builder";
24
- markdown: "markdown";
25
25
  evolution: "evolution";
26
26
  }>;
27
27
  declare const StabilitySchema: z$1.ZodEnum<{
@@ -42,10 +42,10 @@ declare const ExampleDocumentationSchema: z$1.ZodObject<{
42
42
  declare const ExampleSandboxSupportSchema: z$1.ZodObject<{
43
43
  enabled: z$1.ZodBoolean;
44
44
  modes: z$1.ZodArray<z$1.ZodEnum<{
45
+ markdown: "markdown";
45
46
  playground: "playground";
46
47
  specs: "specs";
47
48
  builder: "builder";
48
- markdown: "markdown";
49
49
  evolution: "evolution";
50
50
  }>>;
51
51
  }, z$1.core.$strip>;
@@ -61,10 +61,10 @@ declare const ExampleSurfacesSchema: z$1.ZodObject<{
61
61
  sandbox: z$1.ZodObject<{
62
62
  enabled: z$1.ZodBoolean;
63
63
  modes: z$1.ZodArray<z$1.ZodEnum<{
64
+ markdown: "markdown";
64
65
  playground: "playground";
65
66
  specs: "specs";
66
67
  builder: "builder";
67
- markdown: "markdown";
68
68
  evolution: "evolution";
69
69
  }>>;
70
70
  }, z$1.core.$strip>;
@@ -104,11 +104,11 @@ declare const ExampleMetaSchema: z$1.ZodObject<{
104
104
  tags: z$1.ZodArray<z$1.ZodString>;
105
105
  docId: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
106
106
  kind: z$1.ZodEnum<{
107
+ integration: "integration";
108
+ knowledge: "knowledge";
107
109
  library: "library";
108
110
  workflow: "workflow";
109
- knowledge: "knowledge";
110
111
  template: "template";
111
- integration: "integration";
112
112
  blueprint: "blueprint";
113
113
  ui: "ui";
114
114
  script: "script";
@@ -152,11 +152,11 @@ declare const ExampleSpecSchema: z$1.ZodObject<{
152
152
  tags: z$1.ZodArray<z$1.ZodString>;
153
153
  docId: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
154
154
  kind: z$1.ZodEnum<{
155
+ integration: "integration";
156
+ knowledge: "knowledge";
155
157
  library: "library";
156
158
  workflow: "workflow";
157
- knowledge: "knowledge";
158
159
  template: "template";
159
- integration: "integration";
160
160
  blueprint: "blueprint";
161
161
  ui: "ui";
162
162
  script: "script";
@@ -180,10 +180,10 @@ declare const ExampleSpecSchema: z$1.ZodObject<{
180
180
  sandbox: z$1.ZodObject<{
181
181
  enabled: z$1.ZodBoolean;
182
182
  modes: z$1.ZodArray<z$1.ZodEnum<{
183
+ markdown: "markdown";
183
184
  playground: "playground";
184
185
  specs: "specs";
185
186
  builder: "builder";
186
- markdown: "markdown";
187
187
  evolution: "evolution";
188
188
  }>>;
189
189
  }, z$1.core.$strip>;
@@ -224,7 +224,7 @@ declare function safeParseExampleSpec(data: unknown): z$1.ZodSafeParseResult<{
224
224
  stability: "deprecated" | "idea" | "in_creation" | "experimental" | "beta" | "stable";
225
225
  owners: string[];
226
226
  tags: string[];
227
- kind: "library" | "workflow" | "knowledge" | "template" | "integration" | "blueprint" | "ui" | "script";
227
+ kind: "integration" | "knowledge" | "library" | "workflow" | "template" | "blueprint" | "ui" | "script";
228
228
  visibility: "experimental" | "public" | "internal";
229
229
  title?: string | undefined;
230
230
  domain?: string | undefined;
@@ -235,7 +235,7 @@ declare function safeParseExampleSpec(data: unknown): z$1.ZodSafeParseResult<{
235
235
  templates: boolean;
236
236
  sandbox: {
237
237
  enabled: boolean;
238
- modes: ("playground" | "specs" | "builder" | "markdown" | "evolution")[];
238
+ modes: ("markdown" | "playground" | "specs" | "builder" | "evolution")[];
239
239
  };
240
240
  studio: {
241
241
  enabled: boolean;
@@ -1,7 +1,7 @@
1
- import { OwnerShipMeta } from "../ownership.js";
2
1
  import { FeatureModuleSpec, FeatureRef } from "../features/types.js";
3
2
  import "../features/index.js";
4
3
  import { AppBlueprintSpec, SpecPointer } from "../app-config/spec.js";
4
+ import { OwnerShipMeta } from "../ownership.js";
5
5
 
6
6
  //#region src/examples/types.d.ts
7
7
  /** Kind of example - determines how it's presented in catalogs */