target.ts•2.13 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";
export type Target = {
/**
* A list of the keys for targets that will receive this variation because of individual targeting
*/
values: Array<string>;
/**
* The index, from the array of variations for this flag, of the variation to serve this list of targets
*/
variation: number;
/**
* The context kind of the individual target
*/
contextKind?: string | undefined;
};
/** @internal */
export const Target$inboundSchema: z.ZodType<Target, z.ZodTypeDef, unknown> = z
.object({
values: z.array(z.string()),
variation: z.number().int(),
contextKind: z.string().optional(),
});
/** @internal */
export type Target$Outbound = {
values: Array<string>;
variation: number;
contextKind?: string | undefined;
};
/** @internal */
export const Target$outboundSchema: z.ZodType<
Target$Outbound,
z.ZodTypeDef,
Target
> = z.object({
values: z.array(z.string()),
variation: z.number().int(),
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 Target$ {
/** @deprecated use `Target$inboundSchema` instead. */
export const inboundSchema = Target$inboundSchema;
/** @deprecated use `Target$outboundSchema` instead. */
export const outboundSchema = Target$outboundSchema;
/** @deprecated use `Target$Outbound` instead. */
export type Outbound = Target$Outbound;
}
export function targetToJSON(target: Target): string {
return JSON.stringify(Target$outboundSchema.parse(target));
}
export function targetFromJSON(
jsonString: string,
): SafeParseResult<Target, SDKValidationError> {
return safeParse(
jsonString,
(x) => Target$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Target' from JSON`,
);
}