/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { collectExtraKeys as collectExtraKeys$, safeParse, } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { ResourceOriginEnum, ResourceOriginEnum$inboundSchema, } from "./resourceoriginenum.js"; import { StepIssuesDto, StepIssuesDto$inboundSchema } from "./stepissuesdto.js"; import { ThrottleControlsMetadataResponseDto, ThrottleControlsMetadataResponseDto$inboundSchema, } from "./throttlecontrolsmetadataresponsedto.js"; /** * The type of throttle window. */ export const ThrottleStepResponseDtoType = { Fixed: "fixed", Dynamic: "dynamic", } as const; /** * The type of throttle window. */ export type ThrottleStepResponseDtoType = ClosedEnum< typeof ThrottleStepResponseDtoType >; /** * The unit of time for the throttle window (required for fixed type). */ export const ThrottleStepResponseDtoUnit = { Minutes: "minutes", Hours: "hours", Days: "days", } as const; /** * The unit of time for the throttle window (required for fixed type). */ export type ThrottleStepResponseDtoUnit = ClosedEnum< typeof ThrottleStepResponseDtoUnit >; /** * Control values for the throttle step */ export type ThrottleStepResponseDtoControlValues = { /** * JSONLogic filter conditions for conditionally skipping the step execution. Supports complex logical operations with AND, OR, and comparison operators. See https://jsonlogic.com/ for full typing reference. */ skip?: { [k: string]: any } | undefined; /** * The type of throttle window. */ type: ThrottleStepResponseDtoType; /** * The amount of time for the throttle window (required for fixed type). */ amount?: number | undefined; /** * The unit of time for the throttle window (required for fixed type). */ unit?: ThrottleStepResponseDtoUnit | undefined; /** * Key path to retrieve dynamic window value (required for dynamic type). */ dynamicKey?: string | undefined; /** * The maximum number of executions allowed within the window. Defaults to 1. */ threshold: number; /** * Optional key for grouping throttle rules. If not provided, defaults to workflow and subscriber combination. */ throttleKey?: string | undefined; additionalProperties?: { [k: string]: any } | undefined; }; export type ThrottleStepResponseDto = { /** * Controls metadata for the throttle step */ controls: ThrottleControlsMetadataResponseDto; /** * Control values for the throttle step */ controlValues?: ThrottleStepResponseDtoControlValues | undefined; /** * JSON Schema for variables, follows the JSON Schema standard */ variables: { [k: string]: any }; /** * Unique identifier of the step */ stepId: string; /** * Database identifier of the step */ id: string; /** * Name of the step */ name: string; /** * Slug of the step */ slug: string; /** * Type of the step */ type: "throttle"; /** * Origin of the layout */ origin: ResourceOriginEnum; /** * Workflow identifier */ workflowId: string; /** * Workflow database identifier */ workflowDatabaseId: string; /** * Issues associated with the step */ issues?: StepIssuesDto | undefined; /** * Hash identifying the deployed Cloudflare Worker for this step */ stepResolverHash?: string | undefined; }; /** @internal */ export const ThrottleStepResponseDtoType$inboundSchema: z.ZodNativeEnum< typeof ThrottleStepResponseDtoType > = z.nativeEnum(ThrottleStepResponseDtoType); /** @internal */ export const ThrottleStepResponseDtoUnit$inboundSchema: z.ZodNativeEnum< typeof ThrottleStepResponseDtoUnit > = z.nativeEnum(ThrottleStepResponseDtoUnit); /** @internal */ export const ThrottleStepResponseDtoControlValues$inboundSchema: z.ZodType< ThrottleStepResponseDtoControlValues, z.ZodTypeDef, unknown > = collectExtraKeys$( z.object({ skip: z.record(z.any()).optional(), type: ThrottleStepResponseDtoType$inboundSchema.default("fixed"), amount: z.number().optional(), unit: ThrottleStepResponseDtoUnit$inboundSchema.optional(), dynamicKey: z.string().optional(), threshold: z.number().default(1), throttleKey: z.string().optional(), }).catchall(z.any()), "additionalProperties", true, ); export function throttleStepResponseDtoControlValuesFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ThrottleStepResponseDtoControlValues$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ThrottleStepResponseDtoControlValues' from JSON`, ); } /** @internal */ export const ThrottleStepResponseDto$inboundSchema: z.ZodType< ThrottleStepResponseDto, z.ZodTypeDef, unknown > = z.object({ controls: ThrottleControlsMetadataResponseDto$inboundSchema, controlValues: z.lazy(() => ThrottleStepResponseDtoControlValues$inboundSchema ).optional(), variables: z.record(z.any()), stepId: z.string(), _id: z.string(), name: z.string(), slug: z.string(), type: z.literal("throttle"), origin: ResourceOriginEnum$inboundSchema, workflowId: z.string(), workflowDatabaseId: z.string(), issues: StepIssuesDto$inboundSchema.optional(), stepResolverHash: z.string().optional(), }).transform((v) => { return remap$(v, { "_id": "id", }); }); export function throttleStepResponseDtoFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ThrottleStepResponseDto$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ThrottleStepResponseDto' from JSON`, ); }