import {z} from 'zod' export type MetricItemV3QuerySchema = {projectId?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}) | undefined, primaryEntityId?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}) | undefined, primaryEntityType?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, name?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, aggregationTemporality?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, metricPointType?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, time?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThan', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}) | undefined, startTime?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThan', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}) | undefined, timeUnixNano?: (number | string | {_type: 'NotEqual', value: number | string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number | string} | {_type: 'GreaterThanOrEqual', value: number | string} | {_type: 'LessThan', value: number | string} | {_type: 'LessThanOrEqual', value: number | string} | {_type: 'InBetween', startValue: number | string, endValue: number | string}) | undefined, startTimeUnixNano?: (number | string | {_type: 'NotEqual', value: number | string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number | string} | {_type: 'GreaterThanOrEqual', value: number | string} | {_type: 'LessThan', value: number | string} | {_type: 'LessThanOrEqual', value: number | string} | {_type: 'InBetween', startValue: number | string, endValue: number | string}) | undefined, attributes?: ({[key: string]: string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Search', value: string}}) | undefined, attributeKeys?: ({_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'Search', value: string}) | undefined, entityKeys?: ({_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'Search', value: string}) | undefined, serviceEntityKey?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, hostEntityKey?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, k8sPodEntityKey?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, k8sNodeEntityKey?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, k8sClusterEntityKey?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, containerEntityKey?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, isMonotonic?: (boolean | {_type: 'NotEqual', value: boolean} | {_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, count?: (number | string | {_type: 'NotEqual', value: number | string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number | string} | {_type: 'GreaterThanOrEqual', value: number | string} | {_type: 'LessThan', value: number | string} | {_type: 'LessThanOrEqual', value: number | string} | {_type: 'InBetween', startValue: number | string, endValue: number | string}) | undefined, sum?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, value?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, min?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, max?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, bucketCounts?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, explicitBounds?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, scale?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, zeroCount?: (number | string | {_type: 'NotEqual', value: number | string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number | string} | {_type: 'GreaterThanOrEqual', value: number | string} | {_type: 'LessThan', value: number | string} | {_type: 'LessThanOrEqual', value: number | string} | {_type: 'InBetween', startValue: number | string, endValue: number | string}) | undefined, positiveOffset?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, positiveBucketCounts?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, negativeOffset?: (number | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThan', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}) | undefined, negativeBucketCounts?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, summaryQuantiles?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, summaryValues?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, traceId?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, spanId?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string}) | undefined, _id?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}) | undefined, createdAt?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThan', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}) | undefined}; export type MetricItemV3SelectSchema = {projectId?: boolean | undefined, primaryEntityId?: boolean | undefined, primaryEntityType?: boolean | undefined, name?: boolean | undefined, aggregationTemporality?: boolean | undefined, metricPointType?: boolean | undefined, time?: boolean | undefined, startTime?: boolean | undefined, timeUnixNano?: boolean | undefined, startTimeUnixNano?: boolean | undefined, attributes?: boolean | undefined, attributeKeys?: boolean | undefined, entityKeys?: boolean | undefined, serviceEntityKey?: boolean | undefined, hostEntityKey?: boolean | undefined, k8sPodEntityKey?: boolean | undefined, k8sNodeEntityKey?: boolean | undefined, k8sClusterEntityKey?: boolean | undefined, containerEntityKey?: boolean | undefined, isMonotonic?: boolean | undefined, count?: boolean | undefined, sum?: boolean | undefined, value?: boolean | undefined, min?: boolean | undefined, max?: boolean | undefined, bucketCounts?: boolean | undefined, explicitBounds?: boolean | undefined, scale?: boolean | undefined, zeroCount?: boolean | undefined, positiveOffset?: boolean | undefined, positiveBucketCounts?: boolean | undefined, negativeOffset?: boolean | undefined, negativeBucketCounts?: boolean | undefined, summaryQuantiles?: boolean | undefined, summaryValues?: boolean | undefined, traceId?: boolean | undefined, spanId?: boolean | undefined, _id?: boolean | undefined, createdAt?: boolean | undefined}; export type MetricItemV3SortSchema = {projectId?: ('ASC' | 'DESC') | undefined, primaryEntityId?: ('ASC' | 'DESC') | undefined, primaryEntityType?: ('ASC' | 'DESC') | undefined, name?: ('ASC' | 'DESC') | undefined, aggregationTemporality?: ('ASC' | 'DESC') | undefined, metricPointType?: ('ASC' | 'DESC') | undefined, time?: ('ASC' | 'DESC') | undefined, startTime?: ('ASC' | 'DESC') | undefined, timeUnixNano?: ('ASC' | 'DESC') | undefined, startTimeUnixNano?: ('ASC' | 'DESC') | undefined, serviceEntityKey?: ('ASC' | 'DESC') | undefined, hostEntityKey?: ('ASC' | 'DESC') | undefined, k8sPodEntityKey?: ('ASC' | 'DESC') | undefined, k8sNodeEntityKey?: ('ASC' | 'DESC') | undefined, k8sClusterEntityKey?: ('ASC' | 'DESC') | undefined, containerEntityKey?: ('ASC' | 'DESC') | undefined, isMonotonic?: ('ASC' | 'DESC') | undefined, count?: ('ASC' | 'DESC') | undefined, sum?: ('ASC' | 'DESC') | undefined, value?: ('ASC' | 'DESC') | undefined, min?: ('ASC' | 'DESC') | undefined, max?: ('ASC' | 'DESC') | undefined, scale?: ('ASC' | 'DESC') | undefined, zeroCount?: ('ASC' | 'DESC') | undefined, positiveOffset?: ('ASC' | 'DESC') | undefined, negativeOffset?: ('ASC' | 'DESC') | undefined, traceId?: ('ASC' | 'DESC') | undefined, spanId?: ('ASC' | 'DESC') | undefined, retentionDate?: ('ASC' | 'DESC') | undefined, _id?: ('ASC' | 'DESC') | undefined, createdAt?: ('ASC' | 'DESC') | undefined}; export type MetricItemV3GroupBySchema = {projectId?: boolean | undefined, primaryEntityId?: boolean | undefined, primaryEntityType?: boolean | undefined, name?: boolean | undefined, aggregationTemporality?: boolean | undefined, metricPointType?: boolean | undefined, serviceEntityKey?: boolean | undefined, hostEntityKey?: boolean | undefined, k8sPodEntityKey?: boolean | undefined, k8sNodeEntityKey?: boolean | undefined, k8sClusterEntityKey?: boolean | undefined, containerEntityKey?: boolean | undefined, isMonotonic?: boolean | undefined, scale?: boolean | undefined, positiveOffset?: boolean | undefined, negativeOffset?: boolean | undefined, traceId?: boolean | undefined, spanId?: boolean | undefined, _id?: boolean | undefined, createdAt?: boolean | undefined}; export type CreateApiMetricsGetListArgs = {body: {query?: MetricItemV3QuerySchema | undefined, select?: MetricItemV3SelectSchema | undefined, sort?: MetricItemV3SortSchema | undefined, groupBy?: MetricItemV3GroupBySchema | undefined, limit?: number | undefined, skip?: number | undefined}}; export type CreateApiMetricsGetListOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const metricItemV3 = z.object({projectId: z.string(), primaryEntityId: z.string(), primaryEntityType: z.string().optional(), name: z.string(), aggregationTemporality: z.string().optional(), metricPointType: z.string().optional(), time: z.string().optional(), startTime: z.string().optional(), timeUnixNano: z.string().optional(), startTimeUnixNano: z.string().optional(), attributes: z.string().optional(), attributeKeys: z.array(z.string()).optional(), entityKeys: z.array(z.string()).optional(), serviceEntityKey: z.string().optional(), hostEntityKey: z.string().optional(), k8sPodEntityKey: z.string().optional(), k8sNodeEntityKey: z.string().optional(), k8sClusterEntityKey: z.string().optional(), containerEntityKey: z.string().optional(), isMonotonic: z.boolean().optional(), count: z.string().optional(), sum: z.number().optional(), value: z.number().optional(), min: z.number().optional(), max: z.number().optional(), bucketCounts: z.string().optional(), explicitBounds: z.string().optional(), scale: z.number().optional(), zeroCount: z.string().optional(), positiveOffset: z.number().optional(), positiveBucketCounts: z.string().optional(), negativeOffset: z.number().optional(), negativeBucketCounts: z.string().optional(), summaryQuantiles: z.string().optional(), summaryValues: z.string().optional(), traceId: z.string().optional(), spanId: z.string().optional()}); export const createApiMetricsGetListResponse = z.object({data: z.array(metricItemV3).optional(), count: z.number().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List Metric * * POST /metrics/get-list */ export const createApiMetricsGetList = async (args: CreateApiMetricsGetListArgs, options?: CreateApiMetricsGetListOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/metrics/get-list${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiMetricsGetListResponse, await res.json()) };