@vercel/sdk
Version:
<p align="center"> <a href="https://vercel.com"> <img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96"> <h3 align="center">Vercel</h3> </a> <p align="center">Develop. Preview. Ship.</p> </p>
1,155 lines (1,020 loc) • 27.8 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
export type Value =
| string
| number
| { [k: string]: any }
| Array<any>
| boolean;
export type Variants = {
description?: string | undefined;
label?: string | undefined;
value: string | number | { [k: string]: any } | Array<any> | boolean | null;
id: string;
};
export type Reuse = {
active: boolean;
environment: string;
};
export type Targets = {
note?: string | undefined;
value: string;
};
export const FlagType = {
Variant: "variant",
} as const;
export type FlagType = ClosedEnum<typeof FlagType>;
export type PausedOutcome = {
type: FlagType;
variantId: string;
};
export type Fallthrough4 = {
type: "experiment";
};
export const FlagFallthroughEnvironments3Type = {
Entity: "entity",
} as const;
export type FlagFallthroughEnvironments3Type = ClosedEnum<
typeof FlagFallthroughEnvironments3Type
>;
export type FallthroughBase = {
type: FlagFallthroughEnvironments3Type;
kind: string;
attribute: string;
};
export type Slots = {
promille: number;
durationMs: number;
};
export type Fallthrough3 = {
type: "rollout";
base: FallthroughBase;
defaultVariantId: string;
startTimestamp: number;
rollFromVariantId: string;
rollToVariantId: string;
slots: Array<Slots>;
};
export const FlagFallthroughEnvironments2Type = {
Entity: "entity",
} as const;
export type FlagFallthroughEnvironments2Type = ClosedEnum<
typeof FlagFallthroughEnvironments2Type
>;
export type Base = {
type: FlagFallthroughEnvironments2Type;
kind: string;
attribute: string;
};
export type Fallthrough2 = {
type: "split";
base: Base;
weights: { [k: string]: number };
defaultVariantId: string;
};
export type Fallthrough1 = {
type: "variant";
variantId: string;
};
export type Fallthrough =
| Fallthrough1
| Fallthrough2
| Fallthrough3
| Fallthrough4;
export type Outcome4 = {
type: "experiment";
};
export const FlagOutcomeEnvironmentsRules3Type = {
Entity: "entity",
} as const;
export type FlagOutcomeEnvironmentsRules3Type = ClosedEnum<
typeof FlagOutcomeEnvironmentsRules3Type
>;
export type FlagOutcomeBase = {
type: FlagOutcomeEnvironmentsRules3Type;
kind: string;
attribute: string;
};
export type OutcomeSlots = {
promille: number;
durationMs: number;
};
export type Outcome3 = {
type: "rollout";
base: FlagOutcomeBase;
defaultVariantId: string;
startTimestamp: number;
rollFromVariantId: string;
rollToVariantId: string;
slots: Array<OutcomeSlots>;
};
export const FlagOutcomeEnvironmentsRules2Type = {
Entity: "entity",
} as const;
export type FlagOutcomeEnvironmentsRules2Type = ClosedEnum<
typeof FlagOutcomeEnvironmentsRules2Type
>;
export type OutcomeBase = {
type: FlagOutcomeEnvironmentsRules2Type;
kind: string;
attribute: string;
};
export type Outcome2 = {
type: "split";
base: OutcomeBase;
weights: { [k: string]: number };
defaultVariantId: string;
};
export type Outcome1 = {
type: "variant";
variantId: string;
};
export type FlagOutcome = Outcome1 | Outcome2 | Outcome3 | Outcome4;
export const FlagRhsType = {
Regex: "regex",
} as const;
export type FlagRhsType = ClosedEnum<typeof FlagRhsType>;
export type Rhs4 = {
type: FlagRhsType;
pattern: string;
flags: string;
};
export const RhsType = {
List: "list",
ListInline: "list/inline",
} as const;
export type RhsType = ClosedEnum<typeof RhsType>;
export type Items2 = {
label?: string | undefined;
note?: string | undefined;
value: string;
};
export type Items1 = {
label?: string | undefined;
note?: string | undefined;
value: number;
};
export type RhsItems = Items1 | Items2;
export type Rhs3 = {
type: RhsType;
items: Array<Items1 | Items2>;
};
export type Rhs = Rhs4 | Rhs3 | string | number | boolean;
export type CmpOptions = {
ignoreCase?: boolean | undefined;
};
export type Lhs2 = {
type: "entity";
kind: string;
attribute: string;
};
export type Lhs1 = {
type: "segment";
};
export type Lhs = Lhs1 | Lhs2;
export const Cmp = {
NotContains: "!contains",
NotEndsWith: "!endsWith",
NotEq: "!eq",
NotEx: "!ex",
NotOneOf: "!oneOf",
NotRegex: "!regex",
NotStartsWith: "!startsWith",
After: "after",
Before: "before",
Contains: "contains",
ContainsAllOf: "containsAllOf",
ContainsAnyOf: "containsAnyOf",
ContainsNoneOf: "containsNoneOf",
EndsWith: "endsWith",
Eq: "eq",
Ex: "ex",
Gt: "gt",
Gte: "gte",
Lt: "lt",
Lte: "lte",
OneOf: "oneOf",
Regex: "regex",
StartsWith: "startsWith",
} as const;
export type Cmp = ClosedEnum<typeof Cmp>;
export type Conditions = {
rhs?: Rhs4 | Rhs3 | string | number | boolean | undefined;
cmpOptions?: CmpOptions | undefined;
lhs: Lhs1 | Lhs2;
cmp: Cmp;
};
export type Rules = {
id: string;
outcome: Outcome1 | Outcome2 | Outcome3 | Outcome4;
conditions: Array<Conditions>;
};
export type FlagEnvironments = {
reuse?: Reuse | undefined;
targets?:
| { [k: string]: { [k: string]: { [k: string]: Array<Targets> } } }
| undefined;
revision?: number | undefined;
pausedOutcome: PausedOutcome;
fallthrough: Fallthrough1 | Fallthrough2 | Fallthrough3 | Fallthrough4;
active: boolean;
rules: Array<Rules>;
};
export const Kind = {
Boolean: "boolean",
Json: "json",
Number: "number",
String: "string",
} as const;
export type Kind = ClosedEnum<typeof Kind>;
export const State = {
Active: "active",
Archived: "archived",
} as const;
export type State = ClosedEnum<typeof State>;
export const TypeName = {
Flag: "flag",
} as const;
export type TypeName = ClosedEnum<typeof TypeName>;
export type Creator = {
id: string;
name: string;
};
export type Metadata = {
creator?: Creator | undefined;
};
export type Flag = {
description?: string | undefined;
variants: Array<Variants>;
id: string;
environments: { [k: string]: FlagEnvironments };
kind: Kind;
revision: number;
seed: number;
state: State;
maintainerIds?: Array<string> | undefined;
permanent?: boolean | undefined;
tags?: Array<string> | undefined;
slug: string;
createdAt: number;
updatedAt: number;
updatedBy?: string | undefined;
createdBy: string;
ownerId: string;
projectId: string;
typeName: TypeName;
metadata?: Metadata | undefined;
};
/** @internal */
export const Value$inboundSchema: z.ZodType<Value, z.ZodTypeDef, unknown> =
smartUnion([
types.string(),
types.number(),
z.record(z.any()),
z.array(z.any()),
types.boolean(),
]);
export function valueFromJSON(
jsonString: string,
): SafeParseResult<Value, SDKValidationError> {
return safeParse(
jsonString,
(x) => Value$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Value' from JSON`,
);
}
/** @internal */
export const Variants$inboundSchema: z.ZodType<
Variants,
z.ZodTypeDef,
unknown
> = z.object({
description: types.optional(types.string()),
label: types.optional(types.string()),
value: types.nullable(
smartUnion([
types.string(),
types.number(),
z.record(z.any()),
z.array(z.any()),
types.boolean(),
]),
),
id: types.string(),
});
export function variantsFromJSON(
jsonString: string,
): SafeParseResult<Variants, SDKValidationError> {
return safeParse(
jsonString,
(x) => Variants$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Variants' from JSON`,
);
}
/** @internal */
export const Reuse$inboundSchema: z.ZodType<Reuse, z.ZodTypeDef, unknown> = z
.object({
active: types.boolean(),
environment: types.string(),
});
export function reuseFromJSON(
jsonString: string,
): SafeParseResult<Reuse, SDKValidationError> {
return safeParse(
jsonString,
(x) => Reuse$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Reuse' from JSON`,
);
}
/** @internal */
export const Targets$inboundSchema: z.ZodType<Targets, z.ZodTypeDef, unknown> =
z.object({
note: types.optional(types.string()),
value: types.string(),
});
export function targetsFromJSON(
jsonString: string,
): SafeParseResult<Targets, SDKValidationError> {
return safeParse(
jsonString,
(x) => Targets$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Targets' from JSON`,
);
}
/** @internal */
export const FlagType$inboundSchema: z.ZodNativeEnum<typeof FlagType> = z
.nativeEnum(FlagType);
/** @internal */
export const PausedOutcome$inboundSchema: z.ZodType<
PausedOutcome,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagType$inboundSchema,
variantId: types.string(),
});
export function pausedOutcomeFromJSON(
jsonString: string,
): SafeParseResult<PausedOutcome, SDKValidationError> {
return safeParse(
jsonString,
(x) => PausedOutcome$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'PausedOutcome' from JSON`,
);
}
/** @internal */
export const Fallthrough4$inboundSchema: z.ZodType<
Fallthrough4,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("experiment"),
});
export function fallthrough4FromJSON(
jsonString: string,
): SafeParseResult<Fallthrough4, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough4$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough4' from JSON`,
);
}
/** @internal */
export const FlagFallthroughEnvironments3Type$inboundSchema: z.ZodNativeEnum<
typeof FlagFallthroughEnvironments3Type
> = z.nativeEnum(FlagFallthroughEnvironments3Type);
/** @internal */
export const FallthroughBase$inboundSchema: z.ZodType<
FallthroughBase,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagFallthroughEnvironments3Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function fallthroughBaseFromJSON(
jsonString: string,
): SafeParseResult<FallthroughBase, SDKValidationError> {
return safeParse(
jsonString,
(x) => FallthroughBase$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FallthroughBase' from JSON`,
);
}
/** @internal */
export const Slots$inboundSchema: z.ZodType<Slots, z.ZodTypeDef, unknown> = z
.object({
promille: types.number(),
durationMs: types.number(),
});
export function slotsFromJSON(
jsonString: string,
): SafeParseResult<Slots, SDKValidationError> {
return safeParse(
jsonString,
(x) => Slots$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Slots' from JSON`,
);
}
/** @internal */
export const Fallthrough3$inboundSchema: z.ZodType<
Fallthrough3,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("rollout"),
base: z.lazy(() => FallthroughBase$inboundSchema),
defaultVariantId: types.string(),
startTimestamp: types.number(),
rollFromVariantId: types.string(),
rollToVariantId: types.string(),
slots: z.array(z.lazy(() => Slots$inboundSchema)),
});
export function fallthrough3FromJSON(
jsonString: string,
): SafeParseResult<Fallthrough3, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough3' from JSON`,
);
}
/** @internal */
export const FlagFallthroughEnvironments2Type$inboundSchema: z.ZodNativeEnum<
typeof FlagFallthroughEnvironments2Type
> = z.nativeEnum(FlagFallthroughEnvironments2Type);
/** @internal */
export const Base$inboundSchema: z.ZodType<Base, z.ZodTypeDef, unknown> = z
.object({
type: FlagFallthroughEnvironments2Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function baseFromJSON(
jsonString: string,
): SafeParseResult<Base, SDKValidationError> {
return safeParse(
jsonString,
(x) => Base$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Base' from JSON`,
);
}
/** @internal */
export const Fallthrough2$inboundSchema: z.ZodType<
Fallthrough2,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("split"),
base: z.lazy(() => Base$inboundSchema),
weights: z.record(types.number()),
defaultVariantId: types.string(),
});
export function fallthrough2FromJSON(
jsonString: string,
): SafeParseResult<Fallthrough2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough2' from JSON`,
);
}
/** @internal */
export const Fallthrough1$inboundSchema: z.ZodType<
Fallthrough1,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("variant"),
variantId: types.string(),
});
export function fallthrough1FromJSON(
jsonString: string,
): SafeParseResult<Fallthrough1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough1' from JSON`,
);
}
/** @internal */
export const Fallthrough$inboundSchema: z.ZodType<
Fallthrough,
z.ZodTypeDef,
unknown
> = z.union([
z.lazy(() => Fallthrough1$inboundSchema),
z.lazy(() => Fallthrough2$inboundSchema),
z.lazy(() => Fallthrough3$inboundSchema),
z.lazy(() => Fallthrough4$inboundSchema),
]);
export function fallthroughFromJSON(
jsonString: string,
): SafeParseResult<Fallthrough, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough' from JSON`,
);
}
/** @internal */
export const Outcome4$inboundSchema: z.ZodType<
Outcome4,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("experiment"),
});
export function outcome4FromJSON(
jsonString: string,
): SafeParseResult<Outcome4, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome4$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome4' from JSON`,
);
}
/** @internal */
export const FlagOutcomeEnvironmentsRules3Type$inboundSchema: z.ZodNativeEnum<
typeof FlagOutcomeEnvironmentsRules3Type
> = z.nativeEnum(FlagOutcomeEnvironmentsRules3Type);
/** @internal */
export const FlagOutcomeBase$inboundSchema: z.ZodType<
FlagOutcomeBase,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagOutcomeEnvironmentsRules3Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function flagOutcomeBaseFromJSON(
jsonString: string,
): SafeParseResult<FlagOutcomeBase, SDKValidationError> {
return safeParse(
jsonString,
(x) => FlagOutcomeBase$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FlagOutcomeBase' from JSON`,
);
}
/** @internal */
export const OutcomeSlots$inboundSchema: z.ZodType<
OutcomeSlots,
z.ZodTypeDef,
unknown
> = z.object({
promille: types.number(),
durationMs: types.number(),
});
export function outcomeSlotsFromJSON(
jsonString: string,
): SafeParseResult<OutcomeSlots, SDKValidationError> {
return safeParse(
jsonString,
(x) => OutcomeSlots$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'OutcomeSlots' from JSON`,
);
}
/** @internal */
export const Outcome3$inboundSchema: z.ZodType<
Outcome3,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("rollout"),
base: z.lazy(() => FlagOutcomeBase$inboundSchema),
defaultVariantId: types.string(),
startTimestamp: types.number(),
rollFromVariantId: types.string(),
rollToVariantId: types.string(),
slots: z.array(z.lazy(() => OutcomeSlots$inboundSchema)),
});
export function outcome3FromJSON(
jsonString: string,
): SafeParseResult<Outcome3, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome3' from JSON`,
);
}
/** @internal */
export const FlagOutcomeEnvironmentsRules2Type$inboundSchema: z.ZodNativeEnum<
typeof FlagOutcomeEnvironmentsRules2Type
> = z.nativeEnum(FlagOutcomeEnvironmentsRules2Type);
/** @internal */
export const OutcomeBase$inboundSchema: z.ZodType<
OutcomeBase,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagOutcomeEnvironmentsRules2Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function outcomeBaseFromJSON(
jsonString: string,
): SafeParseResult<OutcomeBase, SDKValidationError> {
return safeParse(
jsonString,
(x) => OutcomeBase$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'OutcomeBase' from JSON`,
);
}
/** @internal */
export const Outcome2$inboundSchema: z.ZodType<
Outcome2,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("split"),
base: z.lazy(() => OutcomeBase$inboundSchema),
weights: z.record(types.number()),
defaultVariantId: types.string(),
});
export function outcome2FromJSON(
jsonString: string,
): SafeParseResult<Outcome2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome2' from JSON`,
);
}
/** @internal */
export const Outcome1$inboundSchema: z.ZodType<
Outcome1,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("variant"),
variantId: types.string(),
});
export function outcome1FromJSON(
jsonString: string,
): SafeParseResult<Outcome1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome1' from JSON`,
);
}
/** @internal */
export const FlagOutcome$inboundSchema: z.ZodType<
FlagOutcome,
z.ZodTypeDef,
unknown
> = z.union([
z.lazy(() => Outcome1$inboundSchema),
z.lazy(() => Outcome2$inboundSchema),
z.lazy(() => Outcome3$inboundSchema),
z.lazy(() => Outcome4$inboundSchema),
]);
export function flagOutcomeFromJSON(
jsonString: string,
): SafeParseResult<FlagOutcome, SDKValidationError> {
return safeParse(
jsonString,
(x) => FlagOutcome$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FlagOutcome' from JSON`,
);
}
/** @internal */
export const FlagRhsType$inboundSchema: z.ZodNativeEnum<typeof FlagRhsType> = z
.nativeEnum(FlagRhsType);
/** @internal */
export const Rhs4$inboundSchema: z.ZodType<Rhs4, z.ZodTypeDef, unknown> = z
.object({
type: FlagRhsType$inboundSchema,
pattern: types.string(),
flags: types.string(),
});
export function rhs4FromJSON(
jsonString: string,
): SafeParseResult<Rhs4, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rhs4$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rhs4' from JSON`,
);
}
/** @internal */
export const RhsType$inboundSchema: z.ZodNativeEnum<typeof RhsType> = z
.nativeEnum(RhsType);
/** @internal */
export const Items2$inboundSchema: z.ZodType<Items2, z.ZodTypeDef, unknown> = z
.object({
label: types.optional(types.string()),
note: types.optional(types.string()),
value: types.string(),
});
export function items2FromJSON(
jsonString: string,
): SafeParseResult<Items2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Items2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Items2' from JSON`,
);
}
/** @internal */
export const Items1$inboundSchema: z.ZodType<Items1, z.ZodTypeDef, unknown> = z
.object({
label: types.optional(types.string()),
note: types.optional(types.string()),
value: types.number(),
});
export function items1FromJSON(
jsonString: string,
): SafeParseResult<Items1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Items1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Items1' from JSON`,
);
}
/** @internal */
export const RhsItems$inboundSchema: z.ZodType<
RhsItems,
z.ZodTypeDef,
unknown
> = smartUnion([
z.lazy(() => Items1$inboundSchema),
z.lazy(() => Items2$inboundSchema),
]);
export function rhsItemsFromJSON(
jsonString: string,
): SafeParseResult<RhsItems, SDKValidationError> {
return safeParse(
jsonString,
(x) => RhsItems$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'RhsItems' from JSON`,
);
}
/** @internal */
export const Rhs3$inboundSchema: z.ZodType<Rhs3, z.ZodTypeDef, unknown> = z
.object({
type: RhsType$inboundSchema,
items: z.array(
smartUnion([
z.lazy(() => Items1$inboundSchema),
z.lazy(() => Items2$inboundSchema),
]),
),
});
export function rhs3FromJSON(
jsonString: string,
): SafeParseResult<Rhs3, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rhs3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rhs3' from JSON`,
);
}
/** @internal */
export const Rhs$inboundSchema: z.ZodType<Rhs, z.ZodTypeDef, unknown> =
smartUnion([
z.lazy(() => Rhs4$inboundSchema),
z.lazy(() => Rhs3$inboundSchema),
types.string(),
types.number(),
types.boolean(),
]);
export function rhsFromJSON(
jsonString: string,
): SafeParseResult<Rhs, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rhs$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rhs' from JSON`,
);
}
/** @internal */
export const CmpOptions$inboundSchema: z.ZodType<
CmpOptions,
z.ZodTypeDef,
unknown
> = z.object({
ignoreCase: types.optional(types.boolean()),
});
export function cmpOptionsFromJSON(
jsonString: string,
): SafeParseResult<CmpOptions, SDKValidationError> {
return safeParse(
jsonString,
(x) => CmpOptions$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'CmpOptions' from JSON`,
);
}
/** @internal */
export const Lhs2$inboundSchema: z.ZodType<Lhs2, z.ZodTypeDef, unknown> = z
.object({
type: types.literal("entity"),
kind: types.string(),
attribute: types.string(),
});
export function lhs2FromJSON(
jsonString: string,
): SafeParseResult<Lhs2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Lhs2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Lhs2' from JSON`,
);
}
/** @internal */
export const Lhs1$inboundSchema: z.ZodType<Lhs1, z.ZodTypeDef, unknown> = z
.object({
type: types.literal("segment"),
});
export function lhs1FromJSON(
jsonString: string,
): SafeParseResult<Lhs1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Lhs1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Lhs1' from JSON`,
);
}
/** @internal */
export const Lhs$inboundSchema: z.ZodType<Lhs, z.ZodTypeDef, unknown> = z.union(
[z.lazy(() => Lhs1$inboundSchema), z.lazy(() => Lhs2$inboundSchema)],
);
export function lhsFromJSON(
jsonString: string,
): SafeParseResult<Lhs, SDKValidationError> {
return safeParse(
jsonString,
(x) => Lhs$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Lhs' from JSON`,
);
}
/** @internal */
export const Cmp$inboundSchema: z.ZodNativeEnum<typeof Cmp> = z.nativeEnum(Cmp);
/** @internal */
export const Conditions$inboundSchema: z.ZodType<
Conditions,
z.ZodTypeDef,
unknown
> = z.object({
rhs: types.optional(
smartUnion([
z.lazy(() => Rhs4$inboundSchema),
z.lazy(() => Rhs3$inboundSchema),
types.string(),
types.number(),
types.boolean(),
]),
),
cmpOptions: types.optional(z.lazy(() => CmpOptions$inboundSchema)),
lhs: z.union([
z.lazy(() => Lhs1$inboundSchema),
z.lazy(() => Lhs2$inboundSchema),
]),
cmp: Cmp$inboundSchema,
});
export function conditionsFromJSON(
jsonString: string,
): SafeParseResult<Conditions, SDKValidationError> {
return safeParse(
jsonString,
(x) => Conditions$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Conditions' from JSON`,
);
}
/** @internal */
export const Rules$inboundSchema: z.ZodType<Rules, z.ZodTypeDef, unknown> = z
.object({
id: types.string(),
outcome: z.union([
z.lazy(() => Outcome1$inboundSchema),
z.lazy(() => Outcome2$inboundSchema),
z.lazy(() => Outcome3$inboundSchema),
z.lazy(() => Outcome4$inboundSchema),
]),
conditions: z.array(z.lazy(() => Conditions$inboundSchema)),
});
export function rulesFromJSON(
jsonString: string,
): SafeParseResult<Rules, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rules$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rules' from JSON`,
);
}
/** @internal */
export const FlagEnvironments$inboundSchema: z.ZodType<
FlagEnvironments,
z.ZodTypeDef,
unknown
> = z.object({
reuse: types.optional(z.lazy(() => Reuse$inboundSchema)),
targets: types.optional(
z.record(z.record(z.record(z.array(z.lazy(() => Targets$inboundSchema))))),
),
revision: types.optional(types.number()),
pausedOutcome: z.lazy(() => PausedOutcome$inboundSchema),
fallthrough: z.union([
z.lazy(() => Fallthrough1$inboundSchema),
z.lazy(() => Fallthrough2$inboundSchema),
z.lazy(() => Fallthrough3$inboundSchema),
z.lazy(() => Fallthrough4$inboundSchema),
]),
active: types.boolean(),
rules: z.array(z.lazy(() => Rules$inboundSchema)),
});
export function flagEnvironmentsFromJSON(
jsonString: string,
): SafeParseResult<FlagEnvironments, SDKValidationError> {
return safeParse(
jsonString,
(x) => FlagEnvironments$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FlagEnvironments' from JSON`,
);
}
/** @internal */
export const Kind$inboundSchema: z.ZodNativeEnum<typeof Kind> = z.nativeEnum(
Kind,
);
/** @internal */
export const State$inboundSchema: z.ZodNativeEnum<typeof State> = z.nativeEnum(
State,
);
/** @internal */
export const TypeName$inboundSchema: z.ZodNativeEnum<typeof TypeName> = z
.nativeEnum(TypeName);
/** @internal */
export const Creator$inboundSchema: z.ZodType<Creator, z.ZodTypeDef, unknown> =
z.object({
id: types.string(),
name: types.string(),
});
export function creatorFromJSON(
jsonString: string,
): SafeParseResult<Creator, SDKValidationError> {
return safeParse(
jsonString,
(x) => Creator$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Creator' from JSON`,
);
}
/** @internal */
export const Metadata$inboundSchema: z.ZodType<
Metadata,
z.ZodTypeDef,
unknown
> = z.object({
creator: types.optional(z.lazy(() => Creator$inboundSchema)),
});
export function metadataFromJSON(
jsonString: string,
): SafeParseResult<Metadata, SDKValidationError> {
return safeParse(
jsonString,
(x) => Metadata$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Metadata' from JSON`,
);
}
/** @internal */
export const Flag$inboundSchema: z.ZodType<Flag, z.ZodTypeDef, unknown> = z
.object({
description: types.optional(types.string()),
variants: z.array(z.lazy(() => Variants$inboundSchema)),
id: types.string(),
environments: z.record(z.lazy(() => FlagEnvironments$inboundSchema)),
kind: Kind$inboundSchema,
revision: types.number(),
seed: types.number(),
state: State$inboundSchema,
maintainerIds: types.optional(z.array(types.string())),
permanent: types.optional(types.boolean()),
tags: types.optional(z.array(types.string())),
slug: types.string(),
createdAt: types.number(),
updatedAt: types.number(),
updatedBy: types.optional(types.string()),
createdBy: types.string(),
ownerId: types.string(),
projectId: types.string(),
typeName: TypeName$inboundSchema,
metadata: types.optional(z.lazy(() => Metadata$inboundSchema)),
});
export function flagFromJSON(
jsonString: string,
): SafeParseResult<Flag, SDKValidationError> {
return safeParse(
jsonString,
(x) => Flag$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Flag' from JSON`,
);
}