@contractspec/example.analytics-dashboard 1.57.0 → 1.59.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
@@ -1,254 +1,290 @@
1
- //#region src/datasource/posthog-datasource.ts
2
- var PosthogQueryEngine = class {
3
- reader;
4
- defaultLimit;
5
- constructor(reader, options = {}) {
6
- this.reader = reader;
7
- this.defaultLimit = options.defaultLimit ?? 100;
8
- }
9
- async execute(definition, params) {
10
- const startTime = Date.now();
11
- const validation = this.validateQuery(definition);
12
- if (!validation.valid) return {
13
- data: [],
14
- columns: [],
15
- rowCount: 0,
16
- executionTimeMs: Date.now() - startTime,
17
- cached: false,
18
- error: validation.errors.join(", ")
19
- };
20
- if (!this.reader.queryHogQL) return {
21
- data: [],
22
- columns: [],
23
- rowCount: 0,
24
- executionTimeMs: Date.now() - startTime,
25
- cached: false,
26
- error: "Analytics reader does not support HogQL queries."
27
- };
28
- try {
29
- const result = await this.executeHogQL(definition, params);
30
- return {
31
- data: result.data,
32
- columns: result.columns,
33
- rowCount: result.rowCount,
34
- executionTimeMs: Date.now() - startTime,
35
- cached: false
36
- };
37
- } catch (error) {
38
- return {
39
- data: [],
40
- columns: [],
41
- rowCount: 0,
42
- executionTimeMs: Date.now() - startTime,
43
- cached: false,
44
- error: error instanceof Error ? error.message : "Unknown error"
45
- };
46
- }
47
- }
48
- validateQuery(definition) {
49
- const errors = [];
50
- if (definition.type === "SQL" && !definition.sql) errors.push("SQL query is missing.");
51
- if (definition.type === "AGGREGATION" && !definition.aggregation) errors.push("Aggregation definition is missing.");
52
- if (definition.type === "METRIC" && !definition.metricIds?.length) errors.push("Metric IDs are missing.");
53
- if (definition.type === "CUSTOM" && !definition.custom?.handler) errors.push("Custom handler is missing.");
54
- return {
55
- valid: errors.length === 0,
56
- errors
57
- };
58
- }
59
- async executeHogQL(definition, params) {
60
- if (!this.reader.queryHogQL) throw new Error("Analytics reader does not support HogQL queries.");
61
- if (definition.type === "SQL") return mapHogqlResult(await this.reader.queryHogQL({
62
- query: definition.sql ?? "",
63
- values: params.parameters ?? {}
64
- }));
65
- if (definition.type === "AGGREGATION" && definition.aggregation) {
66
- const { query, values } = buildAggregationQuery(definition.aggregation, params);
67
- return mapHogqlResult(await this.reader.queryHogQL({
68
- query,
69
- values
70
- }));
71
- }
72
- if (definition.type === "METRIC" && definition.metricIds) {
73
- const { query, values } = buildMetricQuery(definition.metricIds, params);
74
- return mapHogqlResult(await this.reader.queryHogQL({
75
- query,
76
- values
77
- }));
78
- }
79
- throw new Error("Unsupported query type for PostHog datasource.");
80
- }
81
- };
1
+ // @bun
2
+ // src/datasource/posthog-datasource.ts
3
+ class PosthogQueryEngine {
4
+ reader;
5
+ defaultLimit;
6
+ constructor(reader, options = {}) {
7
+ this.reader = reader;
8
+ this.defaultLimit = options.defaultLimit ?? 100;
9
+ }
10
+ async execute(definition, params) {
11
+ const startTime = Date.now();
12
+ const validation = this.validateQuery(definition);
13
+ if (!validation.valid) {
14
+ return {
15
+ data: [],
16
+ columns: [],
17
+ rowCount: 0,
18
+ executionTimeMs: Date.now() - startTime,
19
+ cached: false,
20
+ error: validation.errors.join(", ")
21
+ };
22
+ }
23
+ if (!this.reader.queryHogQL) {
24
+ return {
25
+ data: [],
26
+ columns: [],
27
+ rowCount: 0,
28
+ executionTimeMs: Date.now() - startTime,
29
+ cached: false,
30
+ error: "Analytics reader does not support HogQL queries."
31
+ };
32
+ }
33
+ try {
34
+ const result = await this.executeHogQL(definition, params);
35
+ return {
36
+ data: result.data,
37
+ columns: result.columns,
38
+ rowCount: result.rowCount,
39
+ executionTimeMs: Date.now() - startTime,
40
+ cached: false
41
+ };
42
+ } catch (error) {
43
+ return {
44
+ data: [],
45
+ columns: [],
46
+ rowCount: 0,
47
+ executionTimeMs: Date.now() - startTime,
48
+ cached: false,
49
+ error: error instanceof Error ? error.message : "Unknown error"
50
+ };
51
+ }
52
+ }
53
+ validateQuery(definition) {
54
+ const errors = [];
55
+ if (definition.type === "SQL" && !definition.sql) {
56
+ errors.push("SQL query is missing.");
57
+ }
58
+ if (definition.type === "AGGREGATION" && !definition.aggregation) {
59
+ errors.push("Aggregation definition is missing.");
60
+ }
61
+ if (definition.type === "METRIC" && !definition.metricIds?.length) {
62
+ errors.push("Metric IDs are missing.");
63
+ }
64
+ if (definition.type === "CUSTOM" && !definition.custom?.handler) {
65
+ errors.push("Custom handler is missing.");
66
+ }
67
+ return { valid: errors.length === 0, errors };
68
+ }
69
+ async executeHogQL(definition, params) {
70
+ if (!this.reader.queryHogQL) {
71
+ throw new Error("Analytics reader does not support HogQL queries.");
72
+ }
73
+ if (definition.type === "SQL") {
74
+ const result = await this.reader.queryHogQL({
75
+ query: definition.sql ?? "",
76
+ values: params.parameters ?? {}
77
+ });
78
+ return mapHogqlResult(result);
79
+ }
80
+ if (definition.type === "AGGREGATION" && definition.aggregation) {
81
+ const { query, values } = buildAggregationQuery(definition.aggregation, params);
82
+ const result = await this.reader.queryHogQL({ query, values });
83
+ return mapHogqlResult(result);
84
+ }
85
+ if (definition.type === "METRIC" && definition.metricIds) {
86
+ const { query, values } = buildMetricQuery(definition.metricIds, params);
87
+ const result = await this.reader.queryHogQL({ query, values });
88
+ return mapHogqlResult(result);
89
+ }
90
+ throw new Error("Unsupported query type for PostHog datasource.");
91
+ }
92
+ }
82
93
  function createPosthogQueryEngine(reader, options) {
83
- return new PosthogQueryEngine(reader, options);
94
+ return new PosthogQueryEngine(reader, options);
84
95
  }
85
96
  function buildMetricQuery(metricIds, params) {
86
- const range = resolveDateRange(params);
87
- const values = {
88
- dateFrom: range?.from.toISOString(),
89
- dateTo: range?.to.toISOString()
90
- };
91
- const metricClauses = metricIds.map((metricId, index) => {
92
- values[`metric${index}`] = metricId;
93
- return `event = {metric${index}}`;
94
- });
95
- const whereClauses = [metricClauses.length ? `(${metricClauses.join(" or ")})` : "", range ? "timestamp >= {dateFrom} and timestamp < {dateTo}" : ""].filter(Boolean).join(" and ");
96
- return {
97
- query: [
98
- "select",
99
- " event as metric,",
100
- " count() as total",
101
- "from events",
102
- whereClauses ? `where ${whereClauses}` : "",
103
- "group by metric"
104
- ].filter(Boolean).join("\n"),
105
- values
106
- };
97
+ const range = resolveDateRange(params);
98
+ const values = {
99
+ dateFrom: range?.from.toISOString(),
100
+ dateTo: range?.to.toISOString()
101
+ };
102
+ const metricClauses = metricIds.map((metricId, index) => {
103
+ values[`metric${index}`] = metricId;
104
+ return `event = {metric${index}}`;
105
+ });
106
+ const whereClauses = [
107
+ metricClauses.length ? `(${metricClauses.join(" or ")})` : "",
108
+ range ? "timestamp >= {dateFrom} and timestamp < {dateTo}" : ""
109
+ ].filter(Boolean).join(" and ");
110
+ return {
111
+ query: [
112
+ "select",
113
+ " event as metric,",
114
+ " count() as total",
115
+ "from events",
116
+ whereClauses ? `where ${whereClauses}` : "",
117
+ "group by metric"
118
+ ].filter(Boolean).join(`
119
+ `),
120
+ values
121
+ };
107
122
  }
108
123
  function buildAggregationQuery(aggregation, params) {
109
- const measures = aggregation.measures.map((measure) => ({
110
- ...measure,
111
- expression: buildMeasureExpression(measure.field, measure.aggregation)
112
- }));
113
- const dimensions = aggregation.dimensions.map((dimension) => ({
114
- ...dimension,
115
- expression: buildDimensionExpression(dimension.field, dimension.type, dimension.granularity)
116
- }));
117
- const selections = [...dimensions.map((dimension) => `${dimension.expression} as ${dimension.name}`), ...measures.map((measure) => `${measure.expression} as ${measure.name}`)];
118
- const values = {};
119
- const filters = buildFilterClauses(aggregation, params, values);
120
- const limit = aggregation.limit ?? 100;
121
- const orderBy = aggregation.orderBy?.length ? `order by ${aggregation.orderBy.map((order) => `${order.field} ${order.direction}`).join(", ")}` : "";
122
- return {
123
- query: [
124
- "select",
125
- ` ${selections.join(",\n ")}`,
126
- `from ${aggregation.source}`,
127
- filters.length ? `where ${filters.join(" and ")}` : "",
128
- dimensions.length ? `group by ${dimensions.map((d) => d.name).join(", ")}` : "",
129
- orderBy,
130
- `limit ${limit}`
131
- ].filter(Boolean).join("\n"),
132
- values
133
- };
124
+ const measures = aggregation.measures.map((measure) => ({
125
+ ...measure,
126
+ expression: buildMeasureExpression(measure.field, measure.aggregation)
127
+ }));
128
+ const dimensions = aggregation.dimensions.map((dimension) => ({
129
+ ...dimension,
130
+ expression: buildDimensionExpression(dimension.field, dimension.type, dimension.granularity)
131
+ }));
132
+ const selections = [
133
+ ...dimensions.map((dimension) => `${dimension.expression} as ${dimension.name}`),
134
+ ...measures.map((measure) => `${measure.expression} as ${measure.name}`)
135
+ ];
136
+ const values = {};
137
+ const filters = buildFilterClauses(aggregation, params, values);
138
+ const limit = aggregation.limit ?? 100;
139
+ const orderBy = aggregation.orderBy?.length ? `order by ${aggregation.orderBy.map((order) => `${order.field} ${order.direction}`).join(", ")}` : "";
140
+ return {
141
+ query: [
142
+ "select",
143
+ ` ${selections.join(`,
144
+ `)}`,
145
+ `from ${aggregation.source}`,
146
+ filters.length ? `where ${filters.join(" and ")}` : "",
147
+ dimensions.length ? `group by ${dimensions.map((d) => d.name).join(", ")}` : "",
148
+ orderBy,
149
+ `limit ${limit}`
150
+ ].filter(Boolean).join(`
151
+ `),
152
+ values
153
+ };
134
154
  }
135
155
  function buildMeasureExpression(field, aggregation) {
136
- switch (aggregation) {
137
- case "COUNT": return field === "*" ? "count()" : `count(${field})`;
138
- case "COUNT_DISTINCT": return `countDistinct(${field})`;
139
- case "SUM": return `sum(${field})`;
140
- case "AVG": return `avg(${field})`;
141
- case "MIN": return `min(${field})`;
142
- case "MAX": return `max(${field})`;
143
- default: return `count(${field})`;
144
- }
156
+ switch (aggregation) {
157
+ case "COUNT":
158
+ return field === "*" ? "count()" : `count(${field})`;
159
+ case "COUNT_DISTINCT":
160
+ return `countDistinct(${field})`;
161
+ case "SUM":
162
+ return `sum(${field})`;
163
+ case "AVG":
164
+ return `avg(${field})`;
165
+ case "MIN":
166
+ return `min(${field})`;
167
+ case "MAX":
168
+ return `max(${field})`;
169
+ default:
170
+ return `count(${field})`;
171
+ }
145
172
  }
146
173
  function buildDimensionExpression(field, type, granularity) {
147
- if (type === "TIME") switch (granularity) {
148
- case "HOUR": return `toStartOfHour(${field})`;
149
- case "WEEK": return `toStartOfWeek(${field})`;
150
- case "MONTH": return `toStartOfMonth(${field})`;
151
- case "YEAR": return `toStartOfYear(${field})`;
152
- default: return `toStartOfDay(${field})`;
153
- }
154
- return field;
174
+ if (type === "TIME") {
175
+ switch (granularity) {
176
+ case "HOUR":
177
+ return `toStartOfHour(${field})`;
178
+ case "WEEK":
179
+ return `toStartOfWeek(${field})`;
180
+ case "MONTH":
181
+ return `toStartOfMonth(${field})`;
182
+ case "YEAR":
183
+ return `toStartOfYear(${field})`;
184
+ case "DAY":
185
+ default:
186
+ return `toStartOfDay(${field})`;
187
+ }
188
+ }
189
+ return field;
155
190
  }
156
191
  function buildFilterClauses(aggregation, params, values) {
157
- const clauses = [];
158
- const range = resolveDateRange(params);
159
- if (range) {
160
- values.dateFrom = range.from.toISOString();
161
- values.dateTo = range.to.toISOString();
162
- clauses.push(`timestamp >= {dateFrom} and timestamp < {dateTo}`);
163
- }
164
- aggregation.filters?.forEach((filter, index) => {
165
- const key = `filter${index}`;
166
- switch (filter.operator) {
167
- case "eq":
168
- values[key] = filter.value;
169
- clauses.push(`${filter.field} = {${key}}`);
170
- break;
171
- case "neq":
172
- values[key] = filter.value;
173
- clauses.push(`${filter.field} != {${key}}`);
174
- break;
175
- case "gt":
176
- values[key] = filter.value;
177
- clauses.push(`${filter.field} > {${key}}`);
178
- break;
179
- case "gte":
180
- values[key] = filter.value;
181
- clauses.push(`${filter.field} >= {${key}}`);
182
- break;
183
- case "lt":
184
- values[key] = filter.value;
185
- clauses.push(`${filter.field} < {${key}}`);
186
- break;
187
- case "lte":
188
- values[key] = filter.value;
189
- clauses.push(`${filter.field} <= {${key}}`);
190
- break;
191
- case "contains":
192
- values[key] = filter.value;
193
- clauses.push(`${filter.field} LIKE '%' || {${key}} || '%'`);
194
- break;
195
- case "between":
196
- if (Array.isArray(filter.value) && filter.value.length >= 2) {
197
- values[`${key}Start`] = filter.value[0];
198
- values[`${key}End`] = filter.value[1];
199
- clauses.push(`${filter.field} BETWEEN {${key}Start} AND {${key}End}`);
200
- }
201
- break;
202
- case "in":
203
- case "nin":
204
- if (Array.isArray(filter.value)) {
205
- const placeholders = [];
206
- filter.value.forEach((value, valueIndex) => {
207
- const valueKey = `${key}_${valueIndex}`;
208
- values[valueKey] = value;
209
- placeholders.push(`{${valueKey}}`);
210
- });
211
- if (placeholders.length) clauses.push(`${filter.field} ${filter.operator === "in" ? "IN" : "NOT IN"} (${placeholders.join(", ")})`);
212
- }
213
- break;
214
- default: break;
215
- }
216
- });
217
- return clauses;
192
+ const clauses = [];
193
+ const range = resolveDateRange(params);
194
+ if (range) {
195
+ values.dateFrom = range.from.toISOString();
196
+ values.dateTo = range.to.toISOString();
197
+ clauses.push(`timestamp >= {dateFrom} and timestamp < {dateTo}`);
198
+ }
199
+ aggregation.filters?.forEach((filter, index) => {
200
+ const key = `filter${index}`;
201
+ switch (filter.operator) {
202
+ case "eq":
203
+ values[key] = filter.value;
204
+ clauses.push(`${filter.field} = {${key}}`);
205
+ break;
206
+ case "neq":
207
+ values[key] = filter.value;
208
+ clauses.push(`${filter.field} != {${key}}`);
209
+ break;
210
+ case "gt":
211
+ values[key] = filter.value;
212
+ clauses.push(`${filter.field} > {${key}}`);
213
+ break;
214
+ case "gte":
215
+ values[key] = filter.value;
216
+ clauses.push(`${filter.field} >= {${key}}`);
217
+ break;
218
+ case "lt":
219
+ values[key] = filter.value;
220
+ clauses.push(`${filter.field} < {${key}}`);
221
+ break;
222
+ case "lte":
223
+ values[key] = filter.value;
224
+ clauses.push(`${filter.field} <= {${key}}`);
225
+ break;
226
+ case "contains":
227
+ values[key] = filter.value;
228
+ clauses.push(`${filter.field} LIKE '%' || {${key}} || '%'`);
229
+ break;
230
+ case "between": {
231
+ if (Array.isArray(filter.value) && filter.value.length >= 2) {
232
+ values[`${key}Start`] = filter.value[0];
233
+ values[`${key}End`] = filter.value[1];
234
+ clauses.push(`${filter.field} BETWEEN {${key}Start} AND {${key}End}`);
235
+ }
236
+ break;
237
+ }
238
+ case "in":
239
+ case "nin":
240
+ if (Array.isArray(filter.value)) {
241
+ const placeholders = [];
242
+ filter.value.forEach((value, valueIndex) => {
243
+ const valueKey = `${key}_${valueIndex}`;
244
+ values[valueKey] = value;
245
+ placeholders.push(`{${valueKey}}`);
246
+ });
247
+ if (placeholders.length) {
248
+ clauses.push(`${filter.field} ${filter.operator === "in" ? "IN" : "NOT IN"} (${placeholders.join(", ")})`);
249
+ }
250
+ }
251
+ break;
252
+ default:
253
+ break;
254
+ }
255
+ });
256
+ return clauses;
218
257
  }
219
258
  function resolveDateRange(params) {
220
- const range = params.dateRange;
221
- if (!range) return null;
222
- return {
223
- from: range.start,
224
- to: range.end
225
- };
259
+ const range = params.dateRange;
260
+ if (!range)
261
+ return null;
262
+ return { from: range.start, to: range.end };
226
263
  }
227
264
  function mapHogqlResult(result) {
228
- if (!Array.isArray(result.results) || !Array.isArray(result.columns)) return {
229
- data: [],
230
- columns: [],
231
- rowCount: 0
232
- };
233
- const columns = result.columns.map((name) => ({
234
- name,
235
- type: "STRING"
236
- }));
237
- const data = result.results.map((row) => {
238
- if (!Array.isArray(row)) return {};
239
- const record = {};
240
- result.columns?.forEach((column, index) => {
241
- record[column] = row[index];
242
- });
243
- return record;
244
- });
245
- return {
246
- data,
247
- columns,
248
- rowCount: data.length
249
- };
265
+ if (!Array.isArray(result.results) || !Array.isArray(result.columns)) {
266
+ return { data: [], columns: [], rowCount: 0 };
267
+ }
268
+ const columns = result.columns.map((name) => ({
269
+ name,
270
+ type: "STRING"
271
+ }));
272
+ const data = result.results.map((row) => {
273
+ if (!Array.isArray(row))
274
+ return {};
275
+ const record = {};
276
+ result.columns?.forEach((column, index) => {
277
+ record[column] = row[index];
278
+ });
279
+ return record;
280
+ });
281
+ return {
282
+ data,
283
+ columns,
284
+ rowCount: data.length
285
+ };
250
286
  }
251
-
252
- //#endregion
253
- export { PosthogQueryEngine, createPosthogQueryEngine };
254
- //# sourceMappingURL=posthog-datasource.js.map
287
+ export {
288
+ createPosthogQueryEngine,
289
+ PosthogQueryEngine
290
+ };
@@ -1 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=analytics-dashboard.docblock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics-dashboard.docblock.d.ts","sourceRoot":"","sources":["../../src/docs/analytics-dashboard.docblock.ts"],"names":[],"mappings":""}