/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { AggregationType, AggregationType$inboundSchema, AggregationType$outboundSchema, } from "./aggregation-type.js"; import { SDKValidationError } from "./sdk-validation-error.js"; import { WindowSize, WindowSize$inboundSchema, WindowSize$outboundSchema, } from "./window-size.js"; export type MeterAggregation = { bucketSize?: WindowSize | undefined; /** * Expression is an optional CEL expression to compute per-event quantity from event.properties. * * @remarks * When set, it replaces Field-based extraction. Property names are used directly (e.g., token * duration * pixel). */ expression?: string | undefined; /** * Field is the key in $event.properties on which the aggregation is to be applied * * @remarks * For ex if the aggregation type is sum for API usage, the field could be "duration_ms" * Ignored when Expression is set. */ field?: string | undefined; /** * GroupBy is the property name in event.properties to group by before aggregating. * * @remarks * Currently only supported for MAX aggregation with bucket_size. * When set, aggregation is applied per unique value of this property within each bucket, * then the per-group results are summed to produce the bucket total. */ groupBy?: string | undefined; /** * Multiplier is the multiplier for the aggregation * * @remarks * For ex if the aggregation type is sum_with_multiplier for API usage, the multiplier could be 1000 * to scale up by a factor of 1000. If not provided, it will be null. */ multiplier?: string | undefined; type?: AggregationType | undefined; }; /** @internal */ export const MeterAggregation$inboundSchema: z.ZodMiniType< MeterAggregation, unknown > = z.pipe( z.object({ bucket_size: types.optional(WindowSize$inboundSchema), expression: types.optional(types.string()), field: types.optional(types.string()), group_by: types.optional(types.string()), multiplier: types.optional(types.string()), type: types.optional(AggregationType$inboundSchema), }), z.transform((v) => { return remap$(v, { "bucket_size": "bucketSize", "group_by": "groupBy", }); }), ); /** @internal */ export type MeterAggregation$Outbound = { bucket_size?: string | undefined; expression?: string | undefined; field?: string | undefined; group_by?: string | undefined; multiplier?: string | undefined; type?: string | undefined; }; /** @internal */ export const MeterAggregation$outboundSchema: z.ZodMiniType< MeterAggregation$Outbound, MeterAggregation > = z.pipe( z.object({ bucketSize: z.optional(WindowSize$outboundSchema), expression: z.optional(z.string()), field: z.optional(z.string()), groupBy: z.optional(z.string()), multiplier: z.optional(z.string()), type: z.optional(AggregationType$outboundSchema), }), z.transform((v) => { return remap$(v, { bucketSize: "bucket_size", groupBy: "group_by", }); }), ); export function meterAggregationToJSON( meterAggregation: MeterAggregation, ): string { return JSON.stringify( MeterAggregation$outboundSchema.parse(meterAggregation), ); } export function meterAggregationFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => MeterAggregation$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'MeterAggregation' from JSON`, ); }