@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.
- package/dist/browser/dashboard/dashboard.enum.js +34 -0
- package/dist/browser/dashboard/dashboard.operation.js +289 -0
- package/dist/browser/dashboard/dashboard.presentation.js +197 -0
- package/dist/browser/dashboard/dashboard.schema.js +126 -0
- package/dist/browser/dashboard/dashboard.test-spec.js +213 -0
- package/dist/browser/dashboard/index.js +299 -0
- package/dist/browser/dashboard.feature.js +84 -0
- package/dist/browser/datasource/posthog-datasource.js +289 -0
- package/dist/browser/docs/analytics-dashboard.docblock.js +103 -0
- package/dist/browser/docs/index.js +103 -0
- package/dist/browser/events.js +81 -0
- package/dist/browser/example.js +42 -0
- package/dist/browser/handlers/analytics.handlers.js +278 -0
- package/dist/browser/handlers/index.js +571 -0
- package/dist/browser/handlers/query.handlers.js +294 -0
- package/dist/browser/index.js +1677 -0
- package/dist/browser/query/index.js +159 -0
- package/dist/browser/query/query.enum.js +11 -0
- package/dist/browser/query/query.operation.js +154 -0
- package/dist/browser/query/query.presentation.js +119 -0
- package/dist/browser/query/query.schema.js +70 -0
- package/dist/browser/query/query.test-spec.js +113 -0
- package/dist/browser/query-engine/index.js +491 -0
- package/dist/browser/seeders/index.js +20 -0
- package/dist/browser/ui/AnalyticsDashboard.js +394 -0
- package/dist/browser/ui/hooks/index.js +69 -0
- package/dist/browser/ui/hooks/useAnalyticsData.js +66 -0
- package/dist/browser/ui/index.js +671 -0
- package/dist/browser/ui/renderers/analytics.markdown.js +275 -0
- package/dist/browser/ui/renderers/index.js +275 -0
- package/dist/dashboard/dashboard.enum.d.ts +3 -8
- package/dist/dashboard/dashboard.enum.d.ts.map +1 -1
- package/dist/dashboard/dashboard.enum.js +31 -39
- package/dist/dashboard/dashboard.operation.d.ts +444 -450
- package/dist/dashboard/dashboard.operation.d.ts.map +1 -1
- package/dist/dashboard/dashboard.operation.js +284 -207
- package/dist/dashboard/dashboard.presentation.d.ts +3 -8
- package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
- package/dist/dashboard/dashboard.presentation.js +193 -85
- package/dist/dashboard/dashboard.schema.d.ts +289 -294
- package/dist/dashboard/dashboard.schema.d.ts.map +1 -1
- package/dist/dashboard/dashboard.schema.js +119 -228
- package/dist/dashboard/dashboard.test-spec.d.ts +4 -9
- package/dist/dashboard/dashboard.test-spec.d.ts.map +1 -1
- package/dist/dashboard/dashboard.test-spec.js +209 -228
- package/dist/dashboard/index.d.ts +7 -4
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +299 -4
- package/dist/dashboard.feature.d.ts +1 -6
- package/dist/dashboard.feature.d.ts.map +1 -1
- package/dist/dashboard.feature.js +83 -175
- package/dist/datasource/posthog-datasource.d.ts +15 -19
- package/dist/datasource/posthog-datasource.d.ts.map +1 -1
- package/dist/datasource/posthog-datasource.js +274 -238
- package/dist/docs/analytics-dashboard.docblock.d.ts +2 -1
- package/dist/docs/analytics-dashboard.docblock.d.ts.map +1 -0
- package/dist/docs/analytics-dashboard.docblock.js +45 -56
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +104 -1
- package/dist/events.d.ts +109 -115
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +74 -120
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +41 -55
- package/dist/handlers/analytics.handlers.d.ts +110 -109
- package/dist/handlers/analytics.handlers.d.ts.map +1 -1
- package/dist/handlers/analytics.handlers.js +267 -298
- package/dist/handlers/index.d.ts +3 -3
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +571 -3
- package/dist/handlers/query.handlers.d.ts +7 -11
- package/dist/handlers/query.handlers.d.ts.map +1 -1
- package/dist/handlers/query.handlers.js +292 -7
- package/dist/index.d.ts +12 -13
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1678 -14
- package/dist/node/dashboard/dashboard.enum.js +34 -0
- package/dist/node/dashboard/dashboard.operation.js +289 -0
- package/dist/node/dashboard/dashboard.presentation.js +197 -0
- package/dist/node/dashboard/dashboard.schema.js +126 -0
- package/dist/node/dashboard/dashboard.test-spec.js +213 -0
- package/dist/node/dashboard/index.js +299 -0
- package/dist/node/dashboard.feature.js +84 -0
- package/dist/node/datasource/posthog-datasource.js +289 -0
- package/dist/node/docs/analytics-dashboard.docblock.js +103 -0
- package/dist/node/docs/index.js +103 -0
- package/dist/node/events.js +81 -0
- package/dist/node/example.js +42 -0
- package/dist/node/handlers/analytics.handlers.js +278 -0
- package/dist/node/handlers/index.js +571 -0
- package/dist/node/handlers/query.handlers.js +294 -0
- package/dist/node/index.js +1677 -0
- package/dist/node/query/index.js +159 -0
- package/dist/node/query/query.enum.js +11 -0
- package/dist/node/query/query.operation.js +154 -0
- package/dist/node/query/query.presentation.js +119 -0
- package/dist/node/query/query.schema.js +70 -0
- package/dist/node/query/query.test-spec.js +113 -0
- package/dist/node/query-engine/index.js +491 -0
- package/dist/node/seeders/index.js +20 -0
- package/dist/node/ui/AnalyticsDashboard.js +394 -0
- package/dist/node/ui/hooks/index.js +69 -0
- package/dist/node/ui/hooks/useAnalyticsData.js +66 -0
- package/dist/node/ui/index.js +671 -0
- package/dist/node/ui/renderers/analytics.markdown.js +275 -0
- package/dist/node/ui/renderers/index.js +275 -0
- package/dist/query/index.d.ts +7 -4
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +159 -4
- package/dist/query/query.enum.d.ts +1 -6
- package/dist/query/query.enum.d.ts.map +1 -1
- package/dist/query/query.enum.js +10 -14
- package/dist/query/query.operation.d.ts +148 -154
- package/dist/query/query.operation.d.ts.map +1 -1
- package/dist/query/query.operation.js +151 -109
- package/dist/query/query.presentation.d.ts +2 -7
- package/dist/query/query.presentation.d.ts.map +1 -1
- package/dist/query/query.presentation.js +116 -56
- package/dist/query/query.schema.d.ts +121 -126
- package/dist/query/query.schema.d.ts.map +1 -1
- package/dist/query/query.schema.js +66 -152
- package/dist/query/query.test-spec.d.ts +2 -7
- package/dist/query/query.test-spec.d.ts.map +1 -1
- package/dist/query/query.test-spec.js +111 -121
- package/dist/query-engine/index.d.ts +84 -88
- package/dist/query-engine/index.d.ts.map +1 -1
- package/dist/query-engine/index.js +489 -188
- package/dist/seeders/index.d.ts +4 -8
- package/dist/seeders/index.d.ts.map +1 -1
- package/dist/seeders/index.js +18 -16
- package/dist/ui/AnalyticsDashboard.d.ts +1 -6
- package/dist/ui/AnalyticsDashboard.d.ts.map +1 -1
- package/dist/ui/AnalyticsDashboard.js +389 -259
- package/dist/ui/hooks/index.d.ts +2 -2
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +69 -4
- package/dist/ui/hooks/useAnalyticsData.d.ts +16 -20
- package/dist/ui/hooks/useAnalyticsData.d.ts.map +1 -1
- package/dist/ui/hooks/useAnalyticsData.js +63 -69
- package/dist/ui/index.d.ts +7 -6
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +671 -5
- package/dist/ui/renderers/analytics.markdown.d.ts +13 -14
- package/dist/ui/renderers/analytics.markdown.d.ts.map +1 -1
- package/dist/ui/renderers/analytics.markdown.js +266 -254
- package/dist/ui/renderers/index.d.ts +2 -2
- package/dist/ui/renderers/index.d.ts.map +1 -0
- package/dist/ui/renderers/index.js +275 -2
- package/package.json +328 -67
- package/dist/dashboard/dashboard.enum.js.map +0 -1
- package/dist/dashboard/dashboard.operation.js.map +0 -1
- package/dist/dashboard/dashboard.presentation.js.map +0 -1
- package/dist/dashboard/dashboard.schema.js.map +0 -1
- package/dist/dashboard/dashboard.test-spec.js.map +0 -1
- package/dist/dashboard.feature.js.map +0 -1
- package/dist/datasource/posthog-datasource.js.map +0 -1
- package/dist/docs/analytics-dashboard.docblock.js.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/analytics.handlers.js.map +0 -1
- package/dist/handlers/query.handlers.js.map +0 -1
- package/dist/query/query.enum.js.map +0 -1
- package/dist/query/query.operation.js.map +0 -1
- package/dist/query/query.presentation.js.map +0 -1
- package/dist/query/query.schema.js.map +0 -1
- package/dist/query/query.test-spec.js.map +0 -1
- package/dist/query-engine/index.js.map +0 -1
- package/dist/seeders/index.js.map +0 -1
- package/dist/ui/AnalyticsDashboard.js.map +0 -1
- package/dist/ui/hooks/useAnalyticsData.js.map +0 -1
- 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,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
|
+
};
|