Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/zod-4-package-v3-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@hyperdx/api': patch
'@hyperdx/app': patch
'@hyperdx/common-utils': patch
---

chore: move to the zod 4 package (^4.6.6) while keeping the zod 3 API through
`zod/v3` imports. Schemas and validation behavior are unchanged.
11 changes: 11 additions & 0 deletions .yarn/patches/@hookform-resolvers-npm-3.9.0-6238a72f77.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/zod/dist/types.d.ts b/zod/dist/types.d.ts
index 033484e0c93b5d927ad2bb3023b2bffe22a281a9..2994f3b4c2a887fd88ca0bffedd3f9bf1f2a7892 100644
--- a/zod/dist/types.d.ts
+++ b/zod/dist/types.d.ts
@@ -1,5 +1,5 @@
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
-import { z } from 'zod';
+import { z } from 'zod/v3';
export type Resolver = <T extends z.Schema<any, any>>(schema: T, schemaOptions?: Partial<z.ParseParams>, factoryOptions?: {
/**
* @default async
12 changes: 12 additions & 0 deletions .yarn/patches/zod-express-middleware-npm-1.4.0-951b3b605a.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 1f78e88a306195f14fc83bf8801a5f1c299d7193..355a4e40c9d2a17fe06677d1c314497acf1c6a60 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,6 +1,6 @@
import { Request, RequestHandler, Response } from 'express';
import { ParamsDictionary } from 'express-serve-static-core';
-import { z, ZodEffects, ZodError, ZodSchema, ZodType, ZodTypeDef } from 'zod';
+import { z, ZodEffects, ZodError, ZodSchema, ZodType, ZodTypeDef } from 'zod/v3';
declare type NonReadOnly<T> = {
-readonly [P in keyof T]: NonReadOnly<T[P]>;
};
19 changes: 19 additions & 0 deletions packages/api/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@
"jest.setup.ts"
],
"rules": {
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "zod",
"message": "Import from 'zod/v3'. Bare 'zod' is the v4 API; mixing v3 and v4 schemas breaks composition and ZodError checks."
},
{
"name": "zod/v4",
"message": "Import from 'zod/v3' until the codebase migrates to v4."
},
{
"name": "zod/mini",
"message": "Import from 'zod/v3' until the codebase migrates to v4."
}
]
}
],
"typescript/no-empty-object-type": "error",
"typescript/no-floating-promises": "error",
"typescript/no-unsafe-type-assertion": "warn",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"sqlstring": "^2.3.3",
"undici": "^7.29.0",
"uuid": "^11.1.1",
"zod": "3.25",
"zod-express-middleware": "^1.4.0"
"zod": "^4.6.6",
"zod-express-middleware": "patch:zod-express-middleware@npm%3A1.4.0#~/.yarn/patches/zod-express-middleware-npm-1.4.0-951b3b605a.patch"
},
"devDependencies": {
"@opentelemetry/sdk-trace-base": "^2.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/scripts/generate-api-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import swaggerJsdoc from 'swagger-jsdoc';

// eslint-disable-next-line no-restricted-imports -- run via ts-node without tsconfig-paths, so @/ does not resolve here
// Relative import: run via ts-node without tsconfig-paths, so @/ does not resolve here
import { swaggerOptions } from '../src/utils/swagger';

const specs = swaggerJsdoc(swaggerOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import type { LanguageModel } from 'ai';
import * as chrono from 'chrono-node';
import ms from 'ms';
import z from 'zod';
import z from 'zod/v3';

import { ClickhouseClient } from '@/clickhouse';
import * as config from '@/config';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { configUsesReferenceVariable } from '@hyperdx/common-utils/dist/referenc
import { isRangeThresholdType } from '@hyperdx/common-utils/dist/types';
import { groupBy } from 'lodash';
import { type FilterQuery, Types } from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import { recordOnboardingTaskCompletion } from '@/controllers/user';
import type { ObjectId } from '@/models';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/alertsPage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MAX_ALERT_DISPLAY_NAME_LENGTH } from '@hyperdx/common-utils/dist/types';
import { escapeRegExp } from 'lodash';
import type { FilterQuery } from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import { ALERT_PAGE_POPULATE, type AlertPageRefs } from '@/controllers/alerts';
import type { ObjectId } from '@/models';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
walkRawDashboardTileColors,
} from '@hyperdx/common-utils/dist/types';
import { map, partition, uniq } from 'lodash';
import { z } from 'zod';
import { z } from 'zod/v3';

import {
createOrUpdateDashboardAlerts,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/promql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type SQLInterval,
} from '@hyperdx/common-utils/dist/types';
import { trace } from '@opentelemetry/api';
import { z } from 'zod';
import { z } from 'zod/v3';

import { ClickhouseClient } from '@/clickhouse';
import { getConnectionById } from '@/controllers/connection';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/savedSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SavedSearchSchema,
} from '@hyperdx/common-utils/dist/types';
import { groupBy } from 'lodash';
import { z } from 'zod';
import { z } from 'zod/v3';

import { deleteSavedSearchAlerts } from '@/controllers/alerts';
import Alert from '@/models/alert';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/__tests__/mcpUnion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getParseErrorMessage } from '@modelcontextprotocol/sdk/server/zod-compat.js';
import { z } from 'zod';
import { z } from 'zod/v3';

import { mcpSaveAlertSchema } from '@/mcp/tools/alerts/schemas';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/prompts/dashboards/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import type { PromptDefinition } from '@/mcp/tools/types';
import { getMcpConnections } from '@/mcp/utils/connections';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/alerts/deleteWebhook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import { deleteWebhook } from '@/controllers/webhook';
import { IDEMPOTENT_DESTRUCTIVE_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/alerts/getAlert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type AlertInterval } from '@hyperdx/common-utils/dist/types';
import { ObjectId } from 'mongodb';
import mongoose from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import * as config from '@/config';
import { getRecentAlertHistories } from '@/controllers/alertHistory';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/alerts/getWebhook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/alerts/saveWebhook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WebhookService } from '@hyperdx/common-utils/dist/types';
import mongoose from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import { createWebhook, updateWebhook } from '@/controllers/webhook';
import { OPEN_WORLD_UPSERT_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/alerts/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SearchConditionTrimmedLanguageSchema,
tagsSchema,
} from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import {
mcpBarTileSchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/deleteDashboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import { deleteDashboard } from '@/controllers/dashboard';
import { IDEMPOTENT_DESTRUCTIVE_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/getDashboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import * as config from '@/config';
import { getDashboards } from '@/controllers/dashboard';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/queryTile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import { parseTimeRange, runConfigTile } from '@/mcp/tools/query/helpers';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/queryTiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PQueue from '@esm2cjs/p-queue';
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import { parseTimeRange, runConfigTile } from '@/mcp/tools/query/helpers';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/saveDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isPromqlSavedChartConfig } from '@hyperdx/common-utils/dist/guards';
import type { DashboardContainer } from '@hyperdx/common-utils/dist/types';
import { uniq } from 'lodash';
import mongoose from 'mongoose';
import { z } from 'zod';
import { z } from 'zod/v3';

import * as config from '@/config';
import { recordDashboardOnboardingIfHasTiles } from '@/controllers/dashboard';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
SqlQueryDashboardFilterSchema,
StaticListDashboardFilterSchema,
} from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import {
getMetricSelectIssues,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
SourceKind,
} from '@hyperdx/common-utils/dist/types';
import { isFilterSingleSelect } from '@hyperdx/common-utils/dist/variables';
import { z } from 'zod';
import { z } from 'zod/v3';

import type { McpContext } from '@/mcp/tools/types';
import { getMcpConnections } from '@/mcp/utils/connections';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/emergingSignals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/eventDeltas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DisplayType,
SourceKind,
} from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import type { ClickhouseClient } from '@/clickhouse';
import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/eventPatterns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/promql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
PromqlQueryTypeSchema,
SQLIntervalSchema,
} from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { QUERYABLE_METRIC_KINDS } from '@/mcp/tools/sources/metricKinds';
import type { McpErrorResult } from '@/mcp/utils/errors';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/serviceHealth/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ms from 'ms';
import { z } from 'zod';
import { z } from 'zod/v3';

import {
sourceIdSchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/sql.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { trace } from '@opentelemetry/api';
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/sqlBatch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PQueue from '@esm2cjs/p-queue';
import { trace } from '@opentelemetry/api';
import { z } from 'zod';
import { z } from 'zod/v3';

import type { McpContext, ToolResult } from '@/mcp/tools/types';
import { mcpUserError } from '@/mcp/utils/errors';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/query/timeseries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FIXED_TIME_BUCKET_EXPR_ALIAS } from '@hyperdx/common-utils/dist/core/renderChartConfig';
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { ToolRegistrar } from '@/mcp/tools/types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import * as config from '@/config';
import { getSavedSearch } from '@/controllers/savedSearch';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/savedSearches/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { mcpUnion } from '@/mcp/utils/errors';
import { objectIdSchema, tagsSchema } from '@/utils/zod';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/deleteSource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import { deleteSource } from '@/controllers/sources';
import { IDEMPOTENT_DESTRUCTIVE_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/describeMetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@hyperdx/common-utils/dist/clickhouse';
import { getMetadata } from '@hyperdx/common-utils/dist/core/metadata';
import { SourceKind } from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import type { ClickhouseClient } from '@/clickhouse';
import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/describeSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { type MetricTable, SourceKind } from '@hyperdx/common-utils/dist/types';
import { trace } from '@opentelemetry/api';
import SqlString from 'sqlstring';
import { z } from 'zod';
import { z } from 'zod/v3';

import type { ClickhouseClient } from '@/clickhouse';
import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import {
decodeCursor as decodeCursorPayload,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/listMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getMetadata } from '@hyperdx/common-utils/dist/core/metadata';
import { SourceKind } from '@hyperdx/common-utils/dist/types';
import { trace } from '@opentelemetry/api';
import { z } from 'zod';
import { z } from 'zod/v3';

import type { ClickhouseClient } from '@/clickhouse';
import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/listMetricsSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from 'zod/v3';

import {
decodeCursor as decodeCursorPayload,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/listSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
quoteIdentifierIfNeeded,
} from '@hyperdx/common-utils/dist/core/metadata';
import { SourceKind } from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import { READ_ONLY_TOOL } from '@/mcp/tools/annotations';
import type { McpContext, ToolRegistrar } from '@/mcp/tools/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/sources/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
PromqlSourceBackendSchema,
SourceKind,
} from '@hyperdx/common-utils/dist/types';
import { z } from 'zod';
import { z } from 'zod/v3';

import { sanitizeMetricTables } from './metricKinds';

Expand Down
Loading
Loading