rollout.ts•2.76 kB
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
ExperimentAllocationRep,
ExperimentAllocationRep$inboundSchema,
ExperimentAllocationRep$Outbound,
ExperimentAllocationRep$outboundSchema,
} from "./experimentallocationrep.js";
import {
WeightedVariation,
WeightedVariation$inboundSchema,
WeightedVariation$Outbound,
WeightedVariation$outboundSchema,
} from "./weightedvariation.js";
export type Rollout = {
variations: Array<WeightedVariation>;
experimentAllocation?: ExperimentAllocationRep | undefined;
seed?: number | undefined;
bucketBy?: string | undefined;
contextKind?: string | undefined;
};
/** @internal */
export const Rollout$inboundSchema: z.ZodType<Rollout, z.ZodTypeDef, unknown> =
z.object({
variations: z.array(WeightedVariation$inboundSchema),
experimentAllocation: ExperimentAllocationRep$inboundSchema.optional(),
seed: z.number().int().optional(),
bucketBy: z.string().optional(),
contextKind: z.string().optional(),
});
/** @internal */
export type Rollout$Outbound = {
variations: Array<WeightedVariation$Outbound>;
experimentAllocation?: ExperimentAllocationRep$Outbound | undefined;
seed?: number | undefined;
bucketBy?: string | undefined;
contextKind?: string | undefined;
};
/** @internal */
export const Rollout$outboundSchema: z.ZodType<
Rollout$Outbound,
z.ZodTypeDef,
Rollout
> = z.object({
variations: z.array(WeightedVariation$outboundSchema),
experimentAllocation: ExperimentAllocationRep$outboundSchema.optional(),
seed: z.number().int().optional(),
bucketBy: z.string().optional(),
contextKind: z.string().optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Rollout$ {
/** @deprecated use `Rollout$inboundSchema` instead. */
export const inboundSchema = Rollout$inboundSchema;
/** @deprecated use `Rollout$outboundSchema` instead. */
export const outboundSchema = Rollout$outboundSchema;
/** @deprecated use `Rollout$Outbound` instead. */
export type Outbound = Rollout$Outbound;
}
export function rolloutToJSON(rollout: Rollout): string {
return JSON.stringify(Rollout$outboundSchema.parse(rollout));
}
export function rolloutFromJSON(
jsonString: string,
): SafeParseResult<Rollout, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rollout$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rollout' from JSON`,
);
}