featureflags.ts•3.04 kB
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
FeatureFlag,
FeatureFlag$inboundSchema,
FeatureFlag$Outbound,
FeatureFlag$outboundSchema,
} from "./featureflag.js";
import {
Link,
Link$inboundSchema,
Link$Outbound,
Link$outboundSchema,
} from "./link.js";
export type FeatureFlags = {
/**
* An array of feature flags
*/
items: Array<FeatureFlag>;
/**
* The location and content type of related resources
*/
links: { [k: string]: Link };
/**
* The total number of flags
*/
totalCount?: number | undefined;
/**
* The number of flags that have differences between environments. Only shown when query parameter <code>compare</code> is <code>true</code>.
*/
totalCountWithDifferences?: number | undefined;
};
/** @internal */
export const FeatureFlags$inboundSchema: z.ZodType<
FeatureFlags,
z.ZodTypeDef,
unknown
> = z.object({
items: z.array(FeatureFlag$inboundSchema),
_links: z.record(Link$inboundSchema),
totalCount: z.number().int().optional(),
totalCountWithDifferences: z.number().int().optional(),
}).transform((v) => {
return remap$(v, {
"_links": "links",
});
});
/** @internal */
export type FeatureFlags$Outbound = {
items: Array<FeatureFlag$Outbound>;
_links: { [k: string]: Link$Outbound };
totalCount?: number | undefined;
totalCountWithDifferences?: number | undefined;
};
/** @internal */
export const FeatureFlags$outboundSchema: z.ZodType<
FeatureFlags$Outbound,
z.ZodTypeDef,
FeatureFlags
> = z.object({
items: z.array(FeatureFlag$outboundSchema),
links: z.record(Link$outboundSchema),
totalCount: z.number().int().optional(),
totalCountWithDifferences: z.number().int().optional(),
}).transform((v) => {
return remap$(v, {
links: "_links",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace FeatureFlags$ {
/** @deprecated use `FeatureFlags$inboundSchema` instead. */
export const inboundSchema = FeatureFlags$inboundSchema;
/** @deprecated use `FeatureFlags$outboundSchema` instead. */
export const outboundSchema = FeatureFlags$outboundSchema;
/** @deprecated use `FeatureFlags$Outbound` instead. */
export type Outbound = FeatureFlags$Outbound;
}
export function featureFlagsToJSON(featureFlags: FeatureFlags): string {
return JSON.stringify(FeatureFlags$outboundSchema.parse(featureFlags));
}
export function featureFlagsFromJSON(
jsonString: string,
): SafeParseResult<FeatureFlags, SDKValidationError> {
return safeParse(
jsonString,
(x) => FeatureFlags$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FeatureFlags' from JSON`,
);
}