@adminforth/dashboard 1.6.0 → 1.8.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 (36) hide show
  1. package/custom/model/dashboard.types.ts +25 -10
  2. package/custom/package.json +1 -0
  3. package/custom/pnpm-lock.yaml +31 -0
  4. package/custom/runtime/DashboardRuntime.vue +7 -12
  5. package/custom/runtime/YamlConfigEditor.vue +109 -0
  6. package/custom/skills/adminforth-dashboard/SKILL.md +26 -3
  7. package/dist/custom/model/dashboard.types.d.ts +19 -7
  8. package/dist/custom/model/dashboard.types.ts +25 -10
  9. package/dist/custom/package.json +1 -0
  10. package/dist/custom/pnpm-lock.yaml +31 -0
  11. package/dist/custom/queries/useDashboardConfig.d.ts +322 -4
  12. package/dist/custom/queries/useWidgetData.d.ts +322 -4
  13. package/dist/custom/runtime/DashboardRuntime.vue +7 -12
  14. package/dist/custom/runtime/YamlConfigEditor.vue +109 -0
  15. package/dist/custom/skills/adminforth-dashboard/SKILL.md +26 -3
  16. package/dist/schema/api.d.ts +8099 -1620
  17. package/dist/schema/api.js +2 -2
  18. package/dist/schema/widget.d.ts +622 -33
  19. package/dist/schema/widget.js +1 -1
  20. package/dist/schema/widgets/charts.d.ts +785 -39
  21. package/dist/schema/widgets/charts.js +2 -2
  22. package/dist/schema/widgets/common.d.ts +35 -6
  23. package/dist/schema/widgets/common.js +23 -5
  24. package/dist/schema/widgets/gauge-card.d.ts +56 -2
  25. package/dist/schema/widgets/kpi-card.d.ts +56 -2
  26. package/dist/schema/widgets/pivot-table.d.ts +56 -2
  27. package/dist/schema/widgets/table.d.ts +56 -2
  28. package/dist/services/widgetDataService.js +37 -32
  29. package/package.json +1 -1
  30. package/schema/api.ts +1 -2
  31. package/schema/widget.ts +0 -1
  32. package/schema/widgets/charts.ts +1 -2
  33. package/schema/widgets/common.ts +24 -5
  34. package/services/widgetDataService.ts +62 -50
  35. package/shims-vue.d.ts +11 -0
  36. package/tsconfig.json +3 -1
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ChartFieldRefSchema, FunnelQueryConfigSchema, QueryConfigSchema, WidgetBaseSchema, } from './common.js';
2
+ import { ChartFieldRefSchema, QueryConfigSchema, WidgetBaseSchema, } from './common.js';
3
3
  const ChartBaseSchema = z.object({
4
4
  title: z.string().optional(),
5
5
  }).strict();
@@ -80,7 +80,7 @@ export const HistogramChartWidgetConfigSchema = WidgetBaseSchema.extend({
80
80
  export const FunnelChartWidgetConfigSchema = WidgetBaseSchema.extend({
81
81
  target: z.literal('chart'),
82
82
  chart: FunnelChartSchema,
83
- query: FunnelQueryConfigSchema,
83
+ query: QueryConfigSchema,
84
84
  });
85
85
  export const ChartWidgetTargetConfigSchema = z.union([
86
86
  LineChartWidgetConfigSchema,
@@ -117,7 +117,8 @@ export declare const QueryCalcItemSchema: z.ZodObject<{
117
117
  calc: z.ZodString;
118
118
  as: z.ZodString;
119
119
  }, z.core.$strict>;
120
- export declare const QueryConfigSchema: z.ZodObject<{
120
+ export declare const QueryConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
121
+ source: z.ZodOptional<z.ZodLiteral<"resource">>;
121
122
  resource: z.ZodString;
122
123
  select: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
123
124
  field: z.ZodString;
@@ -190,9 +191,9 @@ export declare const QueryConfigSchema: z.ZodObject<{
190
191
  as: z.ZodString;
191
192
  }, z.core.$strict>>>;
192
193
  formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
193
- }, z.core.$strict>;
194
- export declare const FunnelQueryConfigSchema: z.ZodObject<{
195
- steps: z.ZodArray<z.ZodObject<{
194
+ }, z.core.$strict>, z.ZodObject<{
195
+ source: z.ZodLiteral<"steps">;
196
+ steps: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
196
197
  name: z.ZodString;
197
198
  resource: z.ZodString;
198
199
  metric: z.ZodObject<{
@@ -210,12 +211,40 @@ export declare const FunnelQueryConfigSchema: z.ZodObject<{
210
211
  filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
211
212
  }, z.core.$strict>;
212
213
  filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
213
- }, z.core.$strict>>;
214
+ }, z.core.$strict>, z.ZodObject<{
215
+ name: z.ZodString;
216
+ resource: z.ZodString;
217
+ select: z.ZodArray<z.ZodObject<{
218
+ agg: z.ZodEnum<{
219
+ sum: "sum";
220
+ count: "count";
221
+ count_distinct: "count_distinct";
222
+ avg: "avg";
223
+ min: "min";
224
+ max: "max";
225
+ median: "median";
226
+ }>;
227
+ field: z.ZodOptional<z.ZodString>;
228
+ as: z.ZodString;
229
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
230
+ }, z.core.$strict>>;
231
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
232
+ }, z.core.$strict>]>>;
214
233
  calcs: z.ZodOptional<z.ZodArray<z.ZodObject<{
215
234
  calc: z.ZodString;
216
235
  as: z.ZodString;
217
236
  }, z.core.$strict>>>;
218
- }, z.core.$strict>;
237
+ order_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
238
+ field: z.ZodString;
239
+ direction: z.ZodOptional<z.ZodEnum<{
240
+ asc: "asc";
241
+ desc: "desc";
242
+ }>>;
243
+ }, z.core.$strict>>>;
244
+ limit: z.ZodOptional<z.ZodNumber>;
245
+ offset: z.ZodOptional<z.ZodNumber>;
246
+ formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
247
+ }, z.core.$strict>]>;
219
248
  export declare const WidgetPersistedFieldsSchema: z.ZodObject<{
220
249
  id: z.ZodString;
221
250
  group_id: z.ZodString;
@@ -123,7 +123,8 @@ export const QueryCalcItemSchema = z.object({
123
123
  calc: z.string(),
124
124
  as: z.string(),
125
125
  }).strict();
126
- export const QueryConfigSchema = z.object({
126
+ const ResourceQueryConfigSchema = z.object({
127
+ source: z.literal('resource').optional(),
127
128
  resource: z.string(),
128
129
  select: z.array(QuerySelectItemSchema).optional(),
129
130
  sparkline: z.object({
@@ -141,16 +142,33 @@ export const QueryConfigSchema = z.object({
141
142
  calcs: z.array(QueryCalcItemSchema).optional(),
142
143
  formatting: z.record(z.string(), z.unknown()).optional(),
143
144
  }).strict();
144
- const FunnelQueryStepSchema = z.object({
145
+ const StepsQueryMetricStepSchema = z.object({
145
146
  name: z.string(),
146
147
  resource: z.string(),
147
148
  metric: QueryAggregateSelectItemSchema,
148
149
  filters: FilterExpressionSchema.optional(),
149
150
  }).strict();
150
- export const FunnelQueryConfigSchema = z.object({
151
- steps: z.array(FunnelQueryStepSchema).min(1),
152
- calcs: z.array(QueryCalcItemSchema).optional(),
151
+ const StepsQuerySelectStepSchema = z.object({
152
+ name: z.string(),
153
+ resource: z.string(),
154
+ select: z.array(QueryAggregateSelectItemSchema).min(1),
155
+ filters: FilterExpressionSchema.optional(),
153
156
  }).strict();
157
+ export const QueryConfigSchema = z.union([
158
+ ResourceQueryConfigSchema,
159
+ z.object({
160
+ source: z.literal('steps'),
161
+ steps: z.array(z.union([
162
+ StepsQueryMetricStepSchema,
163
+ StepsQuerySelectStepSchema,
164
+ ])).min(1),
165
+ calcs: z.array(QueryCalcItemSchema).optional(),
166
+ order_by: z.array(QueryOrderByItemSchema).optional(),
167
+ limit: z.number().int().positive().optional(),
168
+ offset: z.number().int().nonnegative().optional(),
169
+ formatting: z.record(z.string(), z.unknown()).optional(),
170
+ }).strict(),
171
+ ]);
154
172
  export const WidgetPersistedFieldsSchema = z.object({
155
173
  id: z.string(),
156
174
  group_id: z.string(),
@@ -95,7 +95,8 @@ export declare const GaugeCardWidgetConfigSchema: z.ZodObject<{
95
95
  }, z.core.$strict>>;
96
96
  color: z.ZodOptional<z.ZodString>;
97
97
  }, z.core.$strict>;
98
- query: z.ZodObject<{
98
+ query: z.ZodUnion<readonly [z.ZodObject<{
99
+ source: z.ZodOptional<z.ZodLiteral<"resource">>;
99
100
  resource: z.ZodString;
100
101
  select: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
101
102
  field: z.ZodString;
@@ -168,5 +169,58 @@ export declare const GaugeCardWidgetConfigSchema: z.ZodObject<{
168
169
  as: z.ZodString;
169
170
  }, z.core.$strict>>>;
170
171
  formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
171
- }, z.core.$strict>;
172
+ }, z.core.$strict>, z.ZodObject<{
173
+ source: z.ZodLiteral<"steps">;
174
+ steps: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
175
+ name: z.ZodString;
176
+ resource: z.ZodString;
177
+ metric: z.ZodObject<{
178
+ agg: z.ZodEnum<{
179
+ sum: "sum";
180
+ count: "count";
181
+ count_distinct: "count_distinct";
182
+ avg: "avg";
183
+ min: "min";
184
+ max: "max";
185
+ median: "median";
186
+ }>;
187
+ field: z.ZodOptional<z.ZodString>;
188
+ as: z.ZodString;
189
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
190
+ }, z.core.$strict>;
191
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
192
+ }, z.core.$strict>, z.ZodObject<{
193
+ name: z.ZodString;
194
+ resource: z.ZodString;
195
+ select: z.ZodArray<z.ZodObject<{
196
+ agg: z.ZodEnum<{
197
+ sum: "sum";
198
+ count: "count";
199
+ count_distinct: "count_distinct";
200
+ avg: "avg";
201
+ min: "min";
202
+ max: "max";
203
+ median: "median";
204
+ }>;
205
+ field: z.ZodOptional<z.ZodString>;
206
+ as: z.ZodString;
207
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
208
+ }, z.core.$strict>>;
209
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
210
+ }, z.core.$strict>]>>;
211
+ calcs: z.ZodOptional<z.ZodArray<z.ZodObject<{
212
+ calc: z.ZodString;
213
+ as: z.ZodString;
214
+ }, z.core.$strict>>>;
215
+ order_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
216
+ field: z.ZodString;
217
+ direction: z.ZodOptional<z.ZodEnum<{
218
+ asc: "asc";
219
+ desc: "desc";
220
+ }>>;
221
+ }, z.core.$strict>>>;
222
+ limit: z.ZodOptional<z.ZodNumber>;
223
+ offset: z.ZodOptional<z.ZodNumber>;
224
+ formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
225
+ }, z.core.$strict>]>;
172
226
  }, z.core.$strict>;
@@ -135,7 +135,8 @@ export declare const KpiCardWidgetConfigSchema: z.ZodObject<{
135
135
  }, z.core.$strict>>;
136
136
  }, z.core.$strict>>;
137
137
  }, z.core.$strict>;
138
- query: z.ZodObject<{
138
+ query: z.ZodUnion<readonly [z.ZodObject<{
139
+ source: z.ZodOptional<z.ZodLiteral<"resource">>;
139
140
  resource: z.ZodString;
140
141
  select: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
141
142
  field: z.ZodString;
@@ -208,5 +209,58 @@ export declare const KpiCardWidgetConfigSchema: z.ZodObject<{
208
209
  as: z.ZodString;
209
210
  }, z.core.$strict>>>;
210
211
  formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
211
- }, z.core.$strict>;
212
+ }, z.core.$strict>, z.ZodObject<{
213
+ source: z.ZodLiteral<"steps">;
214
+ steps: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
215
+ name: z.ZodString;
216
+ resource: z.ZodString;
217
+ metric: z.ZodObject<{
218
+ agg: z.ZodEnum<{
219
+ sum: "sum";
220
+ count: "count";
221
+ count_distinct: "count_distinct";
222
+ avg: "avg";
223
+ min: "min";
224
+ max: "max";
225
+ median: "median";
226
+ }>;
227
+ field: z.ZodOptional<z.ZodString>;
228
+ as: z.ZodString;
229
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
230
+ }, z.core.$strict>;
231
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
232
+ }, z.core.$strict>, z.ZodObject<{
233
+ name: z.ZodString;
234
+ resource: z.ZodString;
235
+ select: z.ZodArray<z.ZodObject<{
236
+ agg: z.ZodEnum<{
237
+ sum: "sum";
238
+ count: "count";
239
+ count_distinct: "count_distinct";
240
+ avg: "avg";
241
+ min: "min";
242
+ max: "max";
243
+ median: "median";
244
+ }>;
245
+ field: z.ZodOptional<z.ZodString>;
246
+ as: z.ZodString;
247
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
248
+ }, z.core.$strict>>;
249
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
250
+ }, z.core.$strict>]>>;
251
+ calcs: z.ZodOptional<z.ZodArray<z.ZodObject<{
252
+ calc: z.ZodString;
253
+ as: z.ZodString;
254
+ }, z.core.$strict>>>;
255
+ order_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
256
+ field: z.ZodString;
257
+ direction: z.ZodOptional<z.ZodEnum<{
258
+ asc: "asc";
259
+ desc: "desc";
260
+ }>>;
261
+ }, z.core.$strict>>>;
262
+ limit: z.ZodOptional<z.ZodNumber>;
263
+ offset: z.ZodOptional<z.ZodNumber>;
264
+ formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
265
+ }, z.core.$strict>]>;
212
266
  }, z.core.$strict>;
@@ -119,7 +119,8 @@ export declare const PivotTableWidgetConfigSchema: z.ZodObject<{
119
119
  }>>;
120
120
  }, z.core.$strict>>;
121
121
  }, z.core.$strict>;
122
- query: z.ZodObject<{
122
+ query: z.ZodUnion<readonly [z.ZodObject<{
123
+ source: z.ZodOptional<z.ZodLiteral<"resource">>;
123
124
  resource: z.ZodString;
124
125
  select: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
125
126
  field: z.ZodString;
@@ -192,5 +193,58 @@ export declare const PivotTableWidgetConfigSchema: z.ZodObject<{
192
193
  as: z.ZodString;
193
194
  }, z.core.$strict>>>;
194
195
  formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
195
- }, z.core.$strict>;
196
+ }, z.core.$strict>, z.ZodObject<{
197
+ source: z.ZodLiteral<"steps">;
198
+ steps: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
199
+ name: z.ZodString;
200
+ resource: z.ZodString;
201
+ metric: z.ZodObject<{
202
+ agg: z.ZodEnum<{
203
+ sum: "sum";
204
+ count: "count";
205
+ count_distinct: "count_distinct";
206
+ avg: "avg";
207
+ min: "min";
208
+ max: "max";
209
+ median: "median";
210
+ }>;
211
+ field: z.ZodOptional<z.ZodString>;
212
+ as: z.ZodString;
213
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
214
+ }, z.core.$strict>;
215
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
216
+ }, z.core.$strict>, z.ZodObject<{
217
+ name: z.ZodString;
218
+ resource: z.ZodString;
219
+ select: z.ZodArray<z.ZodObject<{
220
+ agg: z.ZodEnum<{
221
+ sum: "sum";
222
+ count: "count";
223
+ count_distinct: "count_distinct";
224
+ avg: "avg";
225
+ min: "min";
226
+ max: "max";
227
+ median: "median";
228
+ }>;
229
+ field: z.ZodOptional<z.ZodString>;
230
+ as: z.ZodString;
231
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
232
+ }, z.core.$strict>>;
233
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
234
+ }, z.core.$strict>]>>;
235
+ calcs: z.ZodOptional<z.ZodArray<z.ZodObject<{
236
+ calc: z.ZodString;
237
+ as: z.ZodString;
238
+ }, z.core.$strict>>>;
239
+ order_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
240
+ field: z.ZodString;
241
+ direction: z.ZodOptional<z.ZodEnum<{
242
+ asc: "asc";
243
+ desc: "desc";
244
+ }>>;
245
+ }, z.core.$strict>>>;
246
+ limit: z.ZodOptional<z.ZodNumber>;
247
+ offset: z.ZodOptional<z.ZodNumber>;
248
+ formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
249
+ }, z.core.$strict>]>;
196
250
  }, z.core.$strict>;
@@ -53,7 +53,8 @@ export declare const TableWidgetConfigSchema: z.ZodObject<{
53
53
  pagination: z.ZodOptional<z.ZodBoolean>;
54
54
  page_size: z.ZodOptional<z.ZodNumber>;
55
55
  }, z.core.$strict>>;
56
- query: z.ZodObject<{
56
+ query: z.ZodUnion<readonly [z.ZodObject<{
57
+ source: z.ZodOptional<z.ZodLiteral<"resource">>;
57
58
  resource: z.ZodString;
58
59
  select: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
59
60
  field: z.ZodString;
@@ -126,5 +127,58 @@ export declare const TableWidgetConfigSchema: z.ZodObject<{
126
127
  as: z.ZodString;
127
128
  }, z.core.$strict>>>;
128
129
  formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
129
- }, z.core.$strict>;
130
+ }, z.core.$strict>, z.ZodObject<{
131
+ source: z.ZodLiteral<"steps">;
132
+ steps: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
133
+ name: z.ZodString;
134
+ resource: z.ZodString;
135
+ metric: z.ZodObject<{
136
+ agg: z.ZodEnum<{
137
+ sum: "sum";
138
+ count: "count";
139
+ count_distinct: "count_distinct";
140
+ avg: "avg";
141
+ min: "min";
142
+ max: "max";
143
+ median: "median";
144
+ }>;
145
+ field: z.ZodOptional<z.ZodString>;
146
+ as: z.ZodString;
147
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
148
+ }, z.core.$strict>;
149
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
150
+ }, z.core.$strict>, z.ZodObject<{
151
+ name: z.ZodString;
152
+ resource: z.ZodString;
153
+ select: z.ZodArray<z.ZodObject<{
154
+ agg: z.ZodEnum<{
155
+ sum: "sum";
156
+ count: "count";
157
+ count_distinct: "count_distinct";
158
+ avg: "avg";
159
+ min: "min";
160
+ max: "max";
161
+ median: "median";
162
+ }>;
163
+ field: z.ZodOptional<z.ZodString>;
164
+ as: z.ZodString;
165
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
166
+ }, z.core.$strict>>;
167
+ filters: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
168
+ }, z.core.$strict>]>>;
169
+ calcs: z.ZodOptional<z.ZodArray<z.ZodObject<{
170
+ calc: z.ZodString;
171
+ as: z.ZodString;
172
+ }, z.core.$strict>>>;
173
+ order_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
174
+ field: z.ZodString;
175
+ direction: z.ZodOptional<z.ZodEnum<{
176
+ asc: "asc";
177
+ desc: "desc";
178
+ }>>;
179
+ }, z.core.$strict>>>;
180
+ limit: z.ZodOptional<z.ZodNumber>;
181
+ offset: z.ZodOptional<z.ZodNumber>;
182
+ formatting: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
183
+ }, z.core.$strict>]>;
130
184
  }, z.core.$strict>;
@@ -27,13 +27,11 @@ const FILTER_OPERATORS = {
27
27
  };
28
28
  export function getWidgetData(adminforth_1, widget_1) {
29
29
  return __awaiter(this, arguments, void 0, function* (adminforth, widget, options = {}) {
30
- var _a, _b;
30
+ var _a;
31
31
  if (!('query' in widget)) {
32
32
  return null;
33
33
  }
34
- const data = 'steps' in widget.query
35
- ? yield getFunnelWidgetData(adminforth, widget.query, (_a = options.variables) !== null && _a !== void 0 ? _a : {})
36
- : yield getQueryWidgetData(adminforth, widget.query, (_b = options.variables) !== null && _b !== void 0 ? _b : {});
34
+ const data = yield getQueryWidgetData(adminforth, widget.query, (_a = options.variables) !== null && _a !== void 0 ? _a : {});
37
35
  if (widget.target !== 'table' || !options.pagination) {
38
36
  return data;
39
37
  }
@@ -48,37 +46,12 @@ export function getWidgetData(adminforth_1, widget_1) {
48
46
  } });
49
47
  });
50
48
  }
51
- function getFunnelWidgetData(adminforth, query, variables) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- var _a;
54
- const rows = yield Promise.all(query.steps.map((step) => __awaiter(this, void 0, void 0, function* () {
55
- var _a, _b;
56
- const valueField = step.metric.as;
57
- const [values = {}] = yield getAggregateRows(adminforth, step.resource, step.filters, [step.metric], []);
58
- const row = {
59
- name: step.name,
60
- resource: step.resource,
61
- [valueField]: (_a = values[valueField]) !== null && _a !== void 0 ? _a : 0,
62
- };
63
- for (const calc of (_b = query.calcs) !== null && _b !== void 0 ? _b : []) {
64
- row[calc.as] = evaluateCalc(calc.calc, row, variables);
65
- }
66
- return row;
67
- })));
68
- return {
69
- kind: 'aggregate',
70
- columns: [
71
- 'name',
72
- ...Array.from(new Set(query.steps.map((step) => step.metric.as))),
73
- ...Array.from(new Set(((_a = query.calcs) !== null && _a !== void 0 ? _a : []).map((calc) => calc.as))),
74
- ],
75
- rows,
76
- };
77
- });
78
- }
79
49
  function getQueryWidgetData(adminforth, query, variables) {
80
50
  return __awaiter(this, void 0, void 0, function* () {
81
51
  var _a, _b, _c;
52
+ if (isStepsQuery(query)) {
53
+ return getStepsQueryData(adminforth, query, variables);
54
+ }
82
55
  const metricSelect = getSingleAggregateMetricSelect(query);
83
56
  if (metricSelect) {
84
57
  return getMetricWidgetData(adminforth, query, metricSelect);
@@ -102,6 +75,32 @@ function getQueryWidgetData(adminforth, query, variables) {
102
75
  };
103
76
  });
104
77
  }
78
+ function getStepsQueryData(adminforth, query, variables) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ var _a, _b, _c, _d;
81
+ const rows = yield Promise.all(query.steps.map((step) => __awaiter(this, void 0, void 0, function* () {
82
+ const select = getStepSelect(step);
83
+ const [values = {}] = yield getAggregateRows(adminforth, step.resource, step.filters, select, []);
84
+ const row = buildCalculatedRow(Object.assign({ name: step.name, resource: step.resource }, values), select, query.calcs, variables);
85
+ return row;
86
+ })));
87
+ const orderedRows = sortRows(rows, query.order_by);
88
+ const slicedRows = typeof query.limit === 'number'
89
+ ? orderedRows.slice((_a = query.offset) !== null && _a !== void 0 ? _a : 0, ((_b = query.offset) !== null && _b !== void 0 ? _b : 0) + query.limit)
90
+ : orderedRows.slice((_c = query.offset) !== null && _c !== void 0 ? _c : 0);
91
+ const columns = Array.from(new Set([
92
+ 'name',
93
+ 'resource',
94
+ ...query.steps.flatMap((step) => getStepSelect(step).map((item) => item.as)),
95
+ ...((_d = query.calcs) !== null && _d !== void 0 ? _d : []).map((item) => item.as),
96
+ ]));
97
+ return {
98
+ kind: 'aggregate',
99
+ columns,
100
+ rows: slicedRows,
101
+ };
102
+ });
103
+ }
105
104
  function getMetricWidgetData(adminforth, query, metric) {
106
105
  return __awaiter(this, void 0, void 0, function* () {
107
106
  var _a;
@@ -292,6 +291,12 @@ function getSingleAggregateMetricSelect(query) {
292
291
  }
293
292
  return aggregateItems[0];
294
293
  }
294
+ function isStepsQuery(query) {
295
+ return query.source === 'steps';
296
+ }
297
+ function getStepSelect(step) {
298
+ return 'select' in step ? step.select : [step.metric];
299
+ }
295
300
  function isFieldSelectItem(item) {
296
301
  return 'field' in item && !('agg' in item);
297
302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/dashboard",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
package/schema/api.ts CHANGED
@@ -2,7 +2,6 @@ import { toJSONSchema, z } from 'zod'
2
2
  import {
3
3
  BarChartSchema,
4
4
  FunnelChartSchema,
5
- FunnelQueryConfigSchema,
6
5
  GaugeCardViewConfigSchema,
7
6
  HistogramChartSchema,
8
7
  KpiCardViewConfigSchema,
@@ -153,7 +152,7 @@ const ConfigurableHistogramChartWidgetConfigSchema = WidgetEditableBaseSchema.ex
153
152
  const ConfigurableFunnelChartWidgetConfigSchema = WidgetEditableBaseSchema.extend({
154
153
  target: z.literal('chart'),
155
154
  chart: FunnelChartSchema,
156
- query: FunnelQueryConfigSchema,
155
+ query: QueryConfigSchema,
157
156
  })
158
157
 
159
158
  const ConfigurablePivotTableWidgetConfigSchema = WidgetEditableBaseSchema.extend({
package/schema/widget.ts CHANGED
@@ -33,7 +33,6 @@ export {
33
33
  } from './widgets/table.js'
34
34
  export {
35
35
  EmptyWidgetConfigSchema,
36
- FunnelQueryConfigSchema,
37
36
  QueryConfigSchema,
38
37
  WidgetEditableBaseSchema,
39
38
  } from './widgets/common.js'
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod'
2
2
  import {
3
3
  ChartFieldRefSchema,
4
- FunnelQueryConfigSchema,
5
4
  QueryConfigSchema,
6
5
  WidgetBaseSchema,
7
6
  } from './common.js'
@@ -100,7 +99,7 @@ export const HistogramChartWidgetConfigSchema = WidgetBaseSchema.extend({
100
99
  export const FunnelChartWidgetConfigSchema = WidgetBaseSchema.extend({
101
100
  target: z.literal('chart'),
102
101
  chart: FunnelChartSchema,
103
- query: FunnelQueryConfigSchema,
102
+ query: QueryConfigSchema,
104
103
  })
105
104
 
106
105
  export const ChartWidgetTargetConfigSchema = z.union([
@@ -140,7 +140,8 @@ export const QueryCalcItemSchema = z.object({
140
140
  as: z.string(),
141
141
  }).strict()
142
142
 
143
- export const QueryConfigSchema = z.object({
143
+ const ResourceQueryConfigSchema = z.object({
144
+ source: z.literal('resource').optional(),
144
145
  resource: z.string(),
145
146
  select: z.array(QuerySelectItemSchema).optional(),
146
147
  sparkline: z.object({
@@ -159,18 +160,36 @@ export const QueryConfigSchema = z.object({
159
160
  formatting: z.record(z.string(), z.unknown()).optional(),
160
161
  }).strict()
161
162
 
162
- const FunnelQueryStepSchema = z.object({
163
+ const StepsQueryMetricStepSchema = z.object({
163
164
  name: z.string(),
164
165
  resource: z.string(),
165
166
  metric: QueryAggregateSelectItemSchema,
166
167
  filters: FilterExpressionSchema.optional(),
167
168
  }).strict()
168
169
 
169
- export const FunnelQueryConfigSchema = z.object({
170
- steps: z.array(FunnelQueryStepSchema).min(1),
171
- calcs: z.array(QueryCalcItemSchema).optional(),
170
+ const StepsQuerySelectStepSchema = z.object({
171
+ name: z.string(),
172
+ resource: z.string(),
173
+ select: z.array(QueryAggregateSelectItemSchema).min(1),
174
+ filters: FilterExpressionSchema.optional(),
172
175
  }).strict()
173
176
 
177
+ export const QueryConfigSchema = z.union([
178
+ ResourceQueryConfigSchema,
179
+ z.object({
180
+ source: z.literal('steps'),
181
+ steps: z.array(z.union([
182
+ StepsQueryMetricStepSchema,
183
+ StepsQuerySelectStepSchema,
184
+ ])).min(1),
185
+ calcs: z.array(QueryCalcItemSchema).optional(),
186
+ order_by: z.array(QueryOrderByItemSchema).optional(),
187
+ limit: z.number().int().positive().optional(),
188
+ offset: z.number().int().nonnegative().optional(),
189
+ formatting: z.record(z.string(), z.unknown()).optional(),
190
+ }).strict(),
191
+ ])
192
+
174
193
  export const WidgetPersistedFieldsSchema = z.object({
175
194
  id: z.string(),
176
195
  group_id: z.string(),