@contractspec/example.analytics-dashboard 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/dist/browser/dashboard/dashboard.enum.js +34 -0
  2. package/dist/browser/dashboard/dashboard.operation.js +289 -0
  3. package/dist/browser/dashboard/dashboard.presentation.js +197 -0
  4. package/dist/browser/dashboard/dashboard.schema.js +126 -0
  5. package/dist/browser/dashboard/dashboard.test-spec.js +213 -0
  6. package/dist/browser/dashboard/index.js +299 -0
  7. package/dist/browser/dashboard.feature.js +84 -0
  8. package/dist/browser/datasource/posthog-datasource.js +289 -0
  9. package/dist/browser/docs/analytics-dashboard.docblock.js +103 -0
  10. package/dist/browser/docs/index.js +103 -0
  11. package/dist/browser/events.js +81 -0
  12. package/dist/browser/example.js +42 -0
  13. package/dist/browser/handlers/analytics.handlers.js +278 -0
  14. package/dist/browser/handlers/index.js +571 -0
  15. package/dist/browser/handlers/query.handlers.js +294 -0
  16. package/dist/browser/index.js +1677 -0
  17. package/dist/browser/query/index.js +159 -0
  18. package/dist/browser/query/query.enum.js +11 -0
  19. package/dist/browser/query/query.operation.js +154 -0
  20. package/dist/browser/query/query.presentation.js +119 -0
  21. package/dist/browser/query/query.schema.js +70 -0
  22. package/dist/browser/query/query.test-spec.js +113 -0
  23. package/dist/browser/query-engine/index.js +491 -0
  24. package/dist/browser/seeders/index.js +20 -0
  25. package/dist/browser/ui/AnalyticsDashboard.js +394 -0
  26. package/dist/browser/ui/hooks/index.js +69 -0
  27. package/dist/browser/ui/hooks/useAnalyticsData.js +66 -0
  28. package/dist/browser/ui/index.js +671 -0
  29. package/dist/browser/ui/renderers/analytics.markdown.js +275 -0
  30. package/dist/browser/ui/renderers/index.js +275 -0
  31. package/dist/dashboard/dashboard.enum.d.ts +3 -8
  32. package/dist/dashboard/dashboard.enum.d.ts.map +1 -1
  33. package/dist/dashboard/dashboard.enum.js +31 -39
  34. package/dist/dashboard/dashboard.operation.d.ts +444 -450
  35. package/dist/dashboard/dashboard.operation.d.ts.map +1 -1
  36. package/dist/dashboard/dashboard.operation.js +284 -207
  37. package/dist/dashboard/dashboard.presentation.d.ts +3 -8
  38. package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
  39. package/dist/dashboard/dashboard.presentation.js +193 -85
  40. package/dist/dashboard/dashboard.schema.d.ts +289 -294
  41. package/dist/dashboard/dashboard.schema.d.ts.map +1 -1
  42. package/dist/dashboard/dashboard.schema.js +119 -228
  43. package/dist/dashboard/dashboard.test-spec.d.ts +4 -9
  44. package/dist/dashboard/dashboard.test-spec.d.ts.map +1 -1
  45. package/dist/dashboard/dashboard.test-spec.js +209 -228
  46. package/dist/dashboard/index.d.ts +7 -4
  47. package/dist/dashboard/index.d.ts.map +1 -0
  48. package/dist/dashboard/index.js +299 -4
  49. package/dist/dashboard.feature.d.ts +1 -6
  50. package/dist/dashboard.feature.d.ts.map +1 -1
  51. package/dist/dashboard.feature.js +83 -175
  52. package/dist/datasource/posthog-datasource.d.ts +15 -19
  53. package/dist/datasource/posthog-datasource.d.ts.map +1 -1
  54. package/dist/datasource/posthog-datasource.js +274 -238
  55. package/dist/docs/analytics-dashboard.docblock.d.ts +2 -1
  56. package/dist/docs/analytics-dashboard.docblock.d.ts.map +1 -0
  57. package/dist/docs/analytics-dashboard.docblock.js +45 -56
  58. package/dist/docs/index.d.ts +2 -1
  59. package/dist/docs/index.d.ts.map +1 -0
  60. package/dist/docs/index.js +104 -1
  61. package/dist/events.d.ts +109 -115
  62. package/dist/events.d.ts.map +1 -1
  63. package/dist/events.js +74 -120
  64. package/dist/example.d.ts +2 -6
  65. package/dist/example.d.ts.map +1 -1
  66. package/dist/example.js +41 -55
  67. package/dist/handlers/analytics.handlers.d.ts +110 -109
  68. package/dist/handlers/analytics.handlers.d.ts.map +1 -1
  69. package/dist/handlers/analytics.handlers.js +267 -298
  70. package/dist/handlers/index.d.ts +3 -3
  71. package/dist/handlers/index.d.ts.map +1 -0
  72. package/dist/handlers/index.js +571 -3
  73. package/dist/handlers/query.handlers.d.ts +7 -11
  74. package/dist/handlers/query.handlers.d.ts.map +1 -1
  75. package/dist/handlers/query.handlers.js +292 -7
  76. package/dist/index.d.ts +12 -13
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +1678 -14
  79. package/dist/node/dashboard/dashboard.enum.js +34 -0
  80. package/dist/node/dashboard/dashboard.operation.js +289 -0
  81. package/dist/node/dashboard/dashboard.presentation.js +197 -0
  82. package/dist/node/dashboard/dashboard.schema.js +126 -0
  83. package/dist/node/dashboard/dashboard.test-spec.js +213 -0
  84. package/dist/node/dashboard/index.js +299 -0
  85. package/dist/node/dashboard.feature.js +84 -0
  86. package/dist/node/datasource/posthog-datasource.js +289 -0
  87. package/dist/node/docs/analytics-dashboard.docblock.js +103 -0
  88. package/dist/node/docs/index.js +103 -0
  89. package/dist/node/events.js +81 -0
  90. package/dist/node/example.js +42 -0
  91. package/dist/node/handlers/analytics.handlers.js +278 -0
  92. package/dist/node/handlers/index.js +571 -0
  93. package/dist/node/handlers/query.handlers.js +294 -0
  94. package/dist/node/index.js +1677 -0
  95. package/dist/node/query/index.js +159 -0
  96. package/dist/node/query/query.enum.js +11 -0
  97. package/dist/node/query/query.operation.js +154 -0
  98. package/dist/node/query/query.presentation.js +119 -0
  99. package/dist/node/query/query.schema.js +70 -0
  100. package/dist/node/query/query.test-spec.js +113 -0
  101. package/dist/node/query-engine/index.js +491 -0
  102. package/dist/node/seeders/index.js +20 -0
  103. package/dist/node/ui/AnalyticsDashboard.js +394 -0
  104. package/dist/node/ui/hooks/index.js +69 -0
  105. package/dist/node/ui/hooks/useAnalyticsData.js +66 -0
  106. package/dist/node/ui/index.js +671 -0
  107. package/dist/node/ui/renderers/analytics.markdown.js +275 -0
  108. package/dist/node/ui/renderers/index.js +275 -0
  109. package/dist/query/index.d.ts +7 -4
  110. package/dist/query/index.d.ts.map +1 -0
  111. package/dist/query/index.js +159 -4
  112. package/dist/query/query.enum.d.ts +1 -6
  113. package/dist/query/query.enum.d.ts.map +1 -1
  114. package/dist/query/query.enum.js +10 -14
  115. package/dist/query/query.operation.d.ts +148 -154
  116. package/dist/query/query.operation.d.ts.map +1 -1
  117. package/dist/query/query.operation.js +151 -109
  118. package/dist/query/query.presentation.d.ts +2 -7
  119. package/dist/query/query.presentation.d.ts.map +1 -1
  120. package/dist/query/query.presentation.js +116 -56
  121. package/dist/query/query.schema.d.ts +121 -126
  122. package/dist/query/query.schema.d.ts.map +1 -1
  123. package/dist/query/query.schema.js +66 -152
  124. package/dist/query/query.test-spec.d.ts +2 -7
  125. package/dist/query/query.test-spec.d.ts.map +1 -1
  126. package/dist/query/query.test-spec.js +111 -121
  127. package/dist/query-engine/index.d.ts +84 -88
  128. package/dist/query-engine/index.d.ts.map +1 -1
  129. package/dist/query-engine/index.js +489 -188
  130. package/dist/seeders/index.d.ts +4 -8
  131. package/dist/seeders/index.d.ts.map +1 -1
  132. package/dist/seeders/index.js +18 -16
  133. package/dist/ui/AnalyticsDashboard.d.ts +1 -6
  134. package/dist/ui/AnalyticsDashboard.d.ts.map +1 -1
  135. package/dist/ui/AnalyticsDashboard.js +389 -259
  136. package/dist/ui/hooks/index.d.ts +2 -2
  137. package/dist/ui/hooks/index.d.ts.map +1 -0
  138. package/dist/ui/hooks/index.js +69 -4
  139. package/dist/ui/hooks/useAnalyticsData.d.ts +16 -20
  140. package/dist/ui/hooks/useAnalyticsData.d.ts.map +1 -1
  141. package/dist/ui/hooks/useAnalyticsData.js +63 -69
  142. package/dist/ui/index.d.ts +7 -6
  143. package/dist/ui/index.d.ts.map +1 -0
  144. package/dist/ui/index.js +671 -5
  145. package/dist/ui/renderers/analytics.markdown.d.ts +13 -14
  146. package/dist/ui/renderers/analytics.markdown.d.ts.map +1 -1
  147. package/dist/ui/renderers/analytics.markdown.js +266 -254
  148. package/dist/ui/renderers/index.d.ts +2 -2
  149. package/dist/ui/renderers/index.d.ts.map +1 -0
  150. package/dist/ui/renderers/index.js +275 -2
  151. package/package.json +328 -67
  152. package/dist/dashboard/dashboard.enum.js.map +0 -1
  153. package/dist/dashboard/dashboard.operation.js.map +0 -1
  154. package/dist/dashboard/dashboard.presentation.js.map +0 -1
  155. package/dist/dashboard/dashboard.schema.js.map +0 -1
  156. package/dist/dashboard/dashboard.test-spec.js.map +0 -1
  157. package/dist/dashboard.feature.js.map +0 -1
  158. package/dist/datasource/posthog-datasource.js.map +0 -1
  159. package/dist/docs/analytics-dashboard.docblock.js.map +0 -1
  160. package/dist/events.js.map +0 -1
  161. package/dist/example.js.map +0 -1
  162. package/dist/handlers/analytics.handlers.js.map +0 -1
  163. package/dist/handlers/query.handlers.js.map +0 -1
  164. package/dist/query/query.enum.js.map +0 -1
  165. package/dist/query/query.operation.js.map +0 -1
  166. package/dist/query/query.presentation.js.map +0 -1
  167. package/dist/query/query.schema.js.map +0 -1
  168. package/dist/query/query.test-spec.js.map +0 -1
  169. package/dist/query-engine/index.js.map +0 -1
  170. package/dist/seeders/index.js.map +0 -1
  171. package/dist/ui/AnalyticsDashboard.js.map +0 -1
  172. package/dist/ui/hooks/useAnalyticsData.js.map +0 -1
  173. package/dist/ui/renderers/analytics.markdown.js.map +0 -1
@@ -0,0 +1,159 @@
1
+ // src/query/query.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var QueryTypeEnum = defineEnum("QueryType", [
4
+ "SQL",
5
+ "METRIC",
6
+ "AGGREGATION",
7
+ "CUSTOM"
8
+ ]);
9
+
10
+ // src/query/query.schema.ts
11
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
12
+ var QueryModel = defineSchemaModel({
13
+ name: "QueryModel",
14
+ fields: {
15
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
16
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
18
+ type: { type: QueryTypeEnum, isOptional: false },
19
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
20
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
21
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
22
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
23
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
24
+ }
25
+ });
26
+ var QueryResultModel = defineSchemaModel({
27
+ name: "QueryResultModel",
28
+ fields: {
29
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
+ data: { type: ScalarTypeEnum.JSON(), isOptional: false },
31
+ columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
+ rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
33
+ executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
+ cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
35
+ error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
36
+ }
37
+ });
38
+ var CreateQueryInputModel = defineSchemaModel({
39
+ name: "CreateQueryInput",
40
+ fields: {
41
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
42
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
+ type: { type: QueryTypeEnum, isOptional: false },
44
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
45
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
46
+ metricIds: {
47
+ type: ScalarTypeEnum.String_unsecure(),
48
+ isArray: true,
49
+ isOptional: true
50
+ },
51
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
52
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
53
+ }
54
+ });
55
+ var ExecuteQueryInputModel = defineSchemaModel({
56
+ name: "ExecuteQueryInput",
57
+ fields: {
58
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
60
+ dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
+ filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
+ forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
63
+ }
64
+ });
65
+
66
+ // src/query/query.operation.ts
67
+ import {
68
+ defineCommand,
69
+ defineQuery
70
+ } from "@contractspec/lib.contracts/operations";
71
+ var OWNERS = ["@example.analytics-dashboard"];
72
+ var CreateQueryContract = defineCommand({
73
+ meta: {
74
+ key: "analytics.query.create",
75
+ version: "1.0.0",
76
+ stability: "stable",
77
+ owners: [...OWNERS],
78
+ tags: ["analytics", "query", "create"],
79
+ description: "Create a data query.",
80
+ goal: "Define reusable data queries.",
81
+ context: "Query builder."
82
+ },
83
+ io: { input: CreateQueryInputModel, output: QueryModel },
84
+ policy: { auth: "user" },
85
+ sideEffects: {
86
+ emits: [
87
+ {
88
+ key: "analytics.query.created",
89
+ version: "1.0.0",
90
+ stability: "stable",
91
+ owners: [...OWNERS],
92
+ tags: ["analytics", "query", "created"],
93
+ when: "Query created",
94
+ payload: QueryModel
95
+ }
96
+ ],
97
+ audit: ["analytics.query.created"]
98
+ },
99
+ acceptance: {
100
+ scenarios: [
101
+ {
102
+ key: "create-query-happy-path",
103
+ given: ["User is authenticated"],
104
+ when: ["User submits valid query definition"],
105
+ then: ["Query is created", "QueryCreated event is emitted"]
106
+ }
107
+ ],
108
+ examples: [
109
+ {
110
+ key: "create-sql-query",
111
+ input: {
112
+ name: "Monthly Revenue",
113
+ sql: "SELECT SUM(amount) FROM orders WHERE date >= :startDate"
114
+ },
115
+ output: { id: "query-123", name: "Monthly Revenue", type: "sql" }
116
+ }
117
+ ]
118
+ }
119
+ });
120
+ var ExecuteQueryContract = defineQuery({
121
+ meta: {
122
+ key: "analytics.query.execute",
123
+ version: "1.0.0",
124
+ stability: "stable",
125
+ owners: [...OWNERS],
126
+ tags: ["analytics", "query", "execute"],
127
+ description: "Execute a data query.",
128
+ goal: "Fetch data for visualizations.",
129
+ context: "Dashboard rendering."
130
+ },
131
+ io: { input: ExecuteQueryInputModel, output: QueryResultModel },
132
+ policy: { auth: "user" },
133
+ acceptance: {
134
+ scenarios: [
135
+ {
136
+ key: "execute-query-happy-path",
137
+ given: ["Query exists"],
138
+ when: ["User executes query with parameters"],
139
+ then: ["Query results are returned"]
140
+ }
141
+ ],
142
+ examples: [
143
+ {
144
+ key: "execute-with-params",
145
+ input: { queryId: "query-123", params: { startDate: "2025-01-01" } },
146
+ output: { columns: ["total"], rows: [{ total: 50000 }], rowCount: 1 }
147
+ }
148
+ ]
149
+ }
150
+ });
151
+ export {
152
+ QueryTypeEnum,
153
+ QueryResultModel,
154
+ QueryModel,
155
+ ExecuteQueryInputModel,
156
+ ExecuteQueryContract,
157
+ CreateQueryInputModel,
158
+ CreateQueryContract
159
+ };
@@ -0,0 +1,11 @@
1
+ // src/query/query.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var QueryTypeEnum = defineEnum("QueryType", [
4
+ "SQL",
5
+ "METRIC",
6
+ "AGGREGATION",
7
+ "CUSTOM"
8
+ ]);
9
+ export {
10
+ QueryTypeEnum
11
+ };
@@ -0,0 +1,154 @@
1
+ // src/query/query.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var QueryTypeEnum = defineEnum("QueryType", [
4
+ "SQL",
5
+ "METRIC",
6
+ "AGGREGATION",
7
+ "CUSTOM"
8
+ ]);
9
+
10
+ // src/query/query.schema.ts
11
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
12
+ var QueryModel = defineSchemaModel({
13
+ name: "QueryModel",
14
+ fields: {
15
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
16
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
18
+ type: { type: QueryTypeEnum, isOptional: false },
19
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
20
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
21
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
22
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
23
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
24
+ }
25
+ });
26
+ var QueryResultModel = defineSchemaModel({
27
+ name: "QueryResultModel",
28
+ fields: {
29
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
+ data: { type: ScalarTypeEnum.JSON(), isOptional: false },
31
+ columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
+ rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
33
+ executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
+ cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
35
+ error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
36
+ }
37
+ });
38
+ var CreateQueryInputModel = defineSchemaModel({
39
+ name: "CreateQueryInput",
40
+ fields: {
41
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
42
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
+ type: { type: QueryTypeEnum, isOptional: false },
44
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
45
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
46
+ metricIds: {
47
+ type: ScalarTypeEnum.String_unsecure(),
48
+ isArray: true,
49
+ isOptional: true
50
+ },
51
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
52
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
53
+ }
54
+ });
55
+ var ExecuteQueryInputModel = defineSchemaModel({
56
+ name: "ExecuteQueryInput",
57
+ fields: {
58
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
60
+ dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
+ filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
+ forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
63
+ }
64
+ });
65
+
66
+ // src/query/query.operation.ts
67
+ import {
68
+ defineCommand,
69
+ defineQuery
70
+ } from "@contractspec/lib.contracts/operations";
71
+ var OWNERS = ["@example.analytics-dashboard"];
72
+ var CreateQueryContract = defineCommand({
73
+ meta: {
74
+ key: "analytics.query.create",
75
+ version: "1.0.0",
76
+ stability: "stable",
77
+ owners: [...OWNERS],
78
+ tags: ["analytics", "query", "create"],
79
+ description: "Create a data query.",
80
+ goal: "Define reusable data queries.",
81
+ context: "Query builder."
82
+ },
83
+ io: { input: CreateQueryInputModel, output: QueryModel },
84
+ policy: { auth: "user" },
85
+ sideEffects: {
86
+ emits: [
87
+ {
88
+ key: "analytics.query.created",
89
+ version: "1.0.0",
90
+ stability: "stable",
91
+ owners: [...OWNERS],
92
+ tags: ["analytics", "query", "created"],
93
+ when: "Query created",
94
+ payload: QueryModel
95
+ }
96
+ ],
97
+ audit: ["analytics.query.created"]
98
+ },
99
+ acceptance: {
100
+ scenarios: [
101
+ {
102
+ key: "create-query-happy-path",
103
+ given: ["User is authenticated"],
104
+ when: ["User submits valid query definition"],
105
+ then: ["Query is created", "QueryCreated event is emitted"]
106
+ }
107
+ ],
108
+ examples: [
109
+ {
110
+ key: "create-sql-query",
111
+ input: {
112
+ name: "Monthly Revenue",
113
+ sql: "SELECT SUM(amount) FROM orders WHERE date >= :startDate"
114
+ },
115
+ output: { id: "query-123", name: "Monthly Revenue", type: "sql" }
116
+ }
117
+ ]
118
+ }
119
+ });
120
+ var ExecuteQueryContract = defineQuery({
121
+ meta: {
122
+ key: "analytics.query.execute",
123
+ version: "1.0.0",
124
+ stability: "stable",
125
+ owners: [...OWNERS],
126
+ tags: ["analytics", "query", "execute"],
127
+ description: "Execute a data query.",
128
+ goal: "Fetch data for visualizations.",
129
+ context: "Dashboard rendering."
130
+ },
131
+ io: { input: ExecuteQueryInputModel, output: QueryResultModel },
132
+ policy: { auth: "user" },
133
+ acceptance: {
134
+ scenarios: [
135
+ {
136
+ key: "execute-query-happy-path",
137
+ given: ["Query exists"],
138
+ when: ["User executes query with parameters"],
139
+ then: ["Query results are returned"]
140
+ }
141
+ ],
142
+ examples: [
143
+ {
144
+ key: "execute-with-params",
145
+ input: { queryId: "query-123", params: { startDate: "2025-01-01" } },
146
+ output: { columns: ["total"], rows: [{ total: 50000 }], rowCount: 1 }
147
+ }
148
+ ]
149
+ }
150
+ });
151
+ export {
152
+ ExecuteQueryContract,
153
+ CreateQueryContract
154
+ };
@@ -0,0 +1,119 @@
1
+ // src/query/query.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var QueryTypeEnum = defineEnum("QueryType", [
4
+ "SQL",
5
+ "METRIC",
6
+ "AGGREGATION",
7
+ "CUSTOM"
8
+ ]);
9
+
10
+ // src/query/query.schema.ts
11
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
12
+ var QueryModel = defineSchemaModel({
13
+ name: "QueryModel",
14
+ fields: {
15
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
16
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
18
+ type: { type: QueryTypeEnum, isOptional: false },
19
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
20
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
21
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
22
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
23
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
24
+ }
25
+ });
26
+ var QueryResultModel = defineSchemaModel({
27
+ name: "QueryResultModel",
28
+ fields: {
29
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
+ data: { type: ScalarTypeEnum.JSON(), isOptional: false },
31
+ columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
+ rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
33
+ executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
+ cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
35
+ error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
36
+ }
37
+ });
38
+ var CreateQueryInputModel = defineSchemaModel({
39
+ name: "CreateQueryInput",
40
+ fields: {
41
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
42
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
+ type: { type: QueryTypeEnum, isOptional: false },
44
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
45
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
46
+ metricIds: {
47
+ type: ScalarTypeEnum.String_unsecure(),
48
+ isArray: true,
49
+ isOptional: true
50
+ },
51
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
52
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
53
+ }
54
+ });
55
+ var ExecuteQueryInputModel = defineSchemaModel({
56
+ name: "ExecuteQueryInput",
57
+ fields: {
58
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
60
+ dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
+ filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
+ forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
63
+ }
64
+ });
65
+
66
+ // src/query/query.presentation.ts
67
+ import { definePresentation, StabilityEnum } from "@contractspec/lib.contracts";
68
+ var QueriesListPresentation = definePresentation({
69
+ meta: {
70
+ key: "analytics.query.list",
71
+ version: "1.0.0",
72
+ title: "Queries List",
73
+ description: "List of saved queries",
74
+ domain: "analytics",
75
+ owners: ["@analytics-dashboard"],
76
+ tags: ["analytics", "queries", "list"],
77
+ stability: StabilityEnum.Experimental,
78
+ goal: "Browse and manage saved data queries.",
79
+ context: "The library of reusable data definitions."
80
+ },
81
+ source: {
82
+ type: "component",
83
+ framework: "react",
84
+ componentKey: "QueriesList",
85
+ props: QueryModel
86
+ },
87
+ targets: ["react", "markdown"],
88
+ policy: {
89
+ flags: ["analytics.queries.enabled"]
90
+ }
91
+ });
92
+ var QueryBuilderPresentation = definePresentation({
93
+ meta: {
94
+ key: "analytics.query.builder",
95
+ version: "1.0.0",
96
+ title: "Query Builder",
97
+ description: "Visual query builder interface",
98
+ domain: "analytics",
99
+ owners: ["@analytics-dashboard"],
100
+ tags: ["analytics", "query", "builder"],
101
+ stability: StabilityEnum.Experimental,
102
+ goal: "Visually construct data queries and transformations.",
103
+ context: "Developer tool for data analysis."
104
+ },
105
+ source: {
106
+ type: "component",
107
+ framework: "react",
108
+ componentKey: "QueryBuilder",
109
+ props: QueryModel
110
+ },
111
+ targets: ["react"],
112
+ policy: {
113
+ flags: ["analytics.queries.enabled"]
114
+ }
115
+ });
116
+ export {
117
+ QueryBuilderPresentation,
118
+ QueriesListPresentation
119
+ };
@@ -0,0 +1,70 @@
1
+ // src/query/query.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var QueryTypeEnum = defineEnum("QueryType", [
4
+ "SQL",
5
+ "METRIC",
6
+ "AGGREGATION",
7
+ "CUSTOM"
8
+ ]);
9
+
10
+ // src/query/query.schema.ts
11
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
12
+ var QueryModel = defineSchemaModel({
13
+ name: "QueryModel",
14
+ fields: {
15
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
16
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
18
+ type: { type: QueryTypeEnum, isOptional: false },
19
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
20
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
21
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
22
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: false },
23
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
24
+ }
25
+ });
26
+ var QueryResultModel = defineSchemaModel({
27
+ name: "QueryResultModel",
28
+ fields: {
29
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
+ data: { type: ScalarTypeEnum.JSON(), isOptional: false },
31
+ columns: { type: ScalarTypeEnum.JSON(), isOptional: false },
32
+ rowCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
33
+ executionTimeMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
34
+ cachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
35
+ error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
36
+ }
37
+ });
38
+ var CreateQueryInputModel = defineSchemaModel({
39
+ name: "CreateQueryInput",
40
+ fields: {
41
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
42
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
+ type: { type: QueryTypeEnum, isOptional: false },
44
+ definition: { type: ScalarTypeEnum.JSON(), isOptional: false },
45
+ sql: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
46
+ metricIds: {
47
+ type: ScalarTypeEnum.String_unsecure(),
48
+ isArray: true,
49
+ isOptional: true
50
+ },
51
+ cacheTtlSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
52
+ isShared: { type: ScalarTypeEnum.Boolean(), isOptional: true }
53
+ }
54
+ });
55
+ var ExecuteQueryInputModel = defineSchemaModel({
56
+ name: "ExecuteQueryInput",
57
+ fields: {
58
+ queryId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ parameters: { type: ScalarTypeEnum.JSON(), isOptional: true },
60
+ dateRange: { type: ScalarTypeEnum.JSON(), isOptional: true },
61
+ filters: { type: ScalarTypeEnum.JSON(), isOptional: true },
62
+ forceRefresh: { type: ScalarTypeEnum.Boolean(), isOptional: true }
63
+ }
64
+ });
65
+ export {
66
+ QueryResultModel,
67
+ QueryModel,
68
+ ExecuteQueryInputModel,
69
+ CreateQueryInputModel
70
+ };
@@ -0,0 +1,113 @@
1
+ // src/query/query.test-spec.ts
2
+ import { defineTestSpec } from "@contractspec/lib.contracts";
3
+ var CreateQueryTest = defineTestSpec({
4
+ meta: {
5
+ key: "analytics.query.create.test",
6
+ version: "1.0.0",
7
+ title: "Create Query Test",
8
+ description: "Verifies query creation flow",
9
+ owners: ["@example.analytics-dashboard"],
10
+ tags: ["analytics", "query", "test"],
11
+ stability: "stable"
12
+ },
13
+ target: {
14
+ type: "operation",
15
+ operation: { key: "analytics.query.create", version: "1.0.0" }
16
+ },
17
+ scenarios: [
18
+ {
19
+ key: "success",
20
+ description: "Successfully create a query",
21
+ when: {
22
+ operation: { key: "analytics.query.create", version: "1.0.0" },
23
+ input: {
24
+ name: "Revenue Query",
25
+ sql: "SELECT * FROM revenue"
26
+ }
27
+ },
28
+ then: [
29
+ {
30
+ type: "expectOutput",
31
+ match: {
32
+ name: "Revenue Query",
33
+ type: "sql"
34
+ }
35
+ }
36
+ ]
37
+ },
38
+ {
39
+ key: "error-invalid-sql",
40
+ description: "Fail with invalid SQL",
41
+ when: {
42
+ operation: { key: "analytics.query.create", version: "1.0.0" },
43
+ input: {
44
+ name: "Bad Query",
45
+ sql: ""
46
+ }
47
+ },
48
+ then: [
49
+ {
50
+ type: "expectError",
51
+ messageIncludes: "VALIDATION_ERROR"
52
+ }
53
+ ]
54
+ }
55
+ ]
56
+ });
57
+ var ExecuteQueryTest = defineTestSpec({
58
+ meta: {
59
+ key: "analytics.query.execute.test",
60
+ version: "1.0.0",
61
+ title: "Execute Query Test",
62
+ description: "Verifies query execution",
63
+ owners: ["@example.analytics-dashboard"],
64
+ tags: ["analytics", "query", "test"],
65
+ stability: "stable"
66
+ },
67
+ target: {
68
+ type: "operation",
69
+ operation: { key: "analytics.query.execute", version: "1.0.0" }
70
+ },
71
+ scenarios: [
72
+ {
73
+ key: "success",
74
+ description: "Successfully execute query",
75
+ when: {
76
+ operation: { key: "analytics.query.execute", version: "1.0.0" },
77
+ input: {
78
+ queryId: "q-123",
79
+ params: { limit: 10 }
80
+ }
81
+ },
82
+ then: [
83
+ {
84
+ type: "expectOutput",
85
+ match: {
86
+ rowCount: 1
87
+ }
88
+ }
89
+ ]
90
+ },
91
+ {
92
+ key: "error-query-not-found",
93
+ description: "Fail when query not found",
94
+ when: {
95
+ operation: { key: "analytics.query.execute", version: "1.0.0" },
96
+ input: {
97
+ queryId: "q-999",
98
+ params: {}
99
+ }
100
+ },
101
+ then: [
102
+ {
103
+ type: "expectError",
104
+ messageIncludes: "NOT_FOUND"
105
+ }
106
+ ]
107
+ }
108
+ ]
109
+ });
110
+ export {
111
+ ExecuteQueryTest,
112
+ CreateQueryTest
113
+ };