Skip to content

Commit a7e4912

Browse files
authored
chore: minor cleanup of some schema definitions (#1723)
1 parent ba5da86 commit a7e4912

4 files changed

Lines changed: 12 additions & 27 deletions

File tree

‎packages/api/openapi.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@
545545
"example": "number"
546546
},
547547
"mantissa": {
548-
"type": "number",
548+
"type": "integer",
549549
"description": "Number of decimal places.",
550550
"example": 2
551551
},

‎packages/api/src/routers/external-api/v2/dashboards.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async function getMissingSources(
7676
* $ref: '#/components/schemas/NumberFormatOutput'
7777
* example: "number"
7878
* mantissa:
79-
* type: number
79+
* type: integer
8080
* description: Number of decimal places.
8181
* example: 2
8282
* thousandSeparated:

‎packages/api/src/utils/zod.ts‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { AggregateFunctionSchema } from '@hyperdx/common-utils/dist/types';
2-
import { MetricsDataType } from '@hyperdx/common-utils/dist/types';
1+
import {
2+
AggregateFunctionSchema,
3+
MetricsDataType,
4+
NumberFormatSchema,
5+
SearchConditionLanguageSchema as whereLanguageSchema,
6+
} from '@hyperdx/common-utils/dist/types';
37
import { Types } from 'mongoose';
48
import { z } from 'zod';
59

@@ -21,27 +25,8 @@ export type SourceTable = z.infer<typeof sourceTableSchema>;
2125
// Charts & Dashboards
2226
// ==============================
2327

24-
const numberFormatSchema = z.object({
25-
output: z.union([
26-
z.literal('currency'),
27-
z.literal('percent'),
28-
z.literal('byte'),
29-
z.literal('time'),
30-
z.literal('number'),
31-
]),
32-
mantissa: z.number().optional(),
33-
thousandSeparated: z.boolean().optional(),
34-
average: z.boolean().optional(),
35-
decimalBytes: z.boolean().optional(),
36-
factor: z.number().optional(),
37-
currencySymbol: z.string().optional(),
38-
unit: z.string().optional(),
39-
});
40-
4128
const percentileLevelSchema = z.number().min(0).max(1).optional();
4229

43-
const whereLanguageSchema = z.enum(['sql', 'lucene']).optional();
44-
4530
const timeChartSeriesSchema = z.object({
4631
type: z.literal('time'),
4732
sourceId: objectIdSchema,
@@ -52,7 +37,7 @@ const timeChartSeriesSchema = z.object({
5237
where: z.string(),
5338
whereLanguage: whereLanguageSchema,
5439
groupBy: z.array(z.string()).max(10),
55-
numberFormat: numberFormatSchema.optional(),
40+
numberFormat: NumberFormatSchema.optional(),
5641
metricDataType: z.optional(z.nativeEnum(MetricsDataType)),
5742
metricName: z.string().optional(),
5843
displayType: z
@@ -73,7 +58,7 @@ const tableChartSeriesSchema = z.object({
7358
whereLanguage: whereLanguageSchema,
7459
groupBy: z.array(z.string()).max(10),
7560
sortOrder: z.union([z.literal('desc'), z.literal('asc')]).optional(),
76-
numberFormat: numberFormatSchema.optional(),
61+
numberFormat: NumberFormatSchema.optional(),
7762
metricDataType: z.nativeEnum(MetricsDataType).optional(),
7863
metricName: z.string().optional(),
7964
});
@@ -89,7 +74,7 @@ const numberChartSeriesSchema = z.object({
8974
alias: z.string().optional(),
9075
where: z.string(),
9176
whereLanguage: whereLanguageSchema,
92-
numberFormat: numberFormatSchema.optional(),
77+
numberFormat: NumberFormatSchema.optional(),
9378
metricDataType: z.nativeEnum(MetricsDataType).optional(),
9479
metricName: z.string().optional(),
9580
});

‎packages/common-utils/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export type SavedSearch = z.infer<typeof SavedSearchSchema>;
374374
// --------------------------
375375
export const NumberFormatSchema = z.object({
376376
output: z.enum(['currency', 'percent', 'byte', 'time', 'number']),
377-
mantissa: z.number().optional(),
377+
mantissa: z.number().int().optional(),
378378
thousandSeparated: z.boolean().optional(),
379379
average: z.boolean().optional(),
380380
decimalBytes: z.boolean().optional(),

0 commit comments

Comments
 (0)