/* * 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 { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { PartitionLimits, PartitionLimits$inboundSchema, PartitionLimits$Outbound, PartitionLimits$outboundSchema, } from "./partitionlimits.js"; export type MetadataSchema = string | number | boolean | Array | { [k: string]: any; }; export type Partition = { name: string; isDefault: boolean; /** * Timestamp when the partition exceeded its limits, if applicable. */ limitExceededAt?: Date | null | undefined; description: string | null; contextAware: boolean; metadataSchema: { [k: string]: string | number | boolean | Array | { [k: string]: any; }; } | null; limits: PartitionLimits; }; /** @internal */ export const MetadataSchema$inboundSchema: z.ZodType< MetadataSchema, z.ZodTypeDef, unknown > = z.union([ z.string(), z.number().int(), z.boolean(), z.array(z.string()), z.record(z.any()), ]); /** @internal */ export type MetadataSchema$Outbound = | string | number | boolean | Array | { [k: string]: any }; /** @internal */ export const MetadataSchema$outboundSchema: z.ZodType< MetadataSchema$Outbound, z.ZodTypeDef, MetadataSchema > = z.union([ z.string(), z.number().int(), z.boolean(), z.array(z.string()), z.record(z.any()), ]); export function metadataSchemaToJSON(metadataSchema: MetadataSchema): string { return JSON.stringify(MetadataSchema$outboundSchema.parse(metadataSchema)); } export function metadataSchemaFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => MetadataSchema$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'MetadataSchema' from JSON`, ); } /** @internal */ export const Partition$inboundSchema: z.ZodType< Partition, z.ZodTypeDef, unknown > = z.object({ name: z.string(), is_default: z.boolean(), limit_exceeded_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), description: z.nullable(z.string()), context_aware: z.boolean(), metadata_schema: z.nullable( z.record( z.union([ z.string(), z.number().int(), z.boolean(), z.array(z.string()), z.record(z.any()), ]), ), ), limits: PartitionLimits$inboundSchema, }).transform((v) => { return remap$(v, { "is_default": "isDefault", "limit_exceeded_at": "limitExceededAt", "context_aware": "contextAware", "metadata_schema": "metadataSchema", }); }); /** @internal */ export type Partition$Outbound = { name: string; is_default: boolean; limit_exceeded_at?: string | null | undefined; description: string | null; context_aware: boolean; metadata_schema: { [k: string]: string | number | boolean | Array | { [k: string]: any; }; } | null; limits: PartitionLimits$Outbound; }; /** @internal */ export const Partition$outboundSchema: z.ZodType< Partition$Outbound, z.ZodTypeDef, Partition > = z.object({ name: z.string(), isDefault: z.boolean(), limitExceededAt: z.nullable(z.date().transform(v => v.toISOString())) .optional(), description: z.nullable(z.string()), contextAware: z.boolean(), metadataSchema: z.nullable( z.record( z.union([ z.string(), z.number().int(), z.boolean(), z.array(z.string()), z.record(z.any()), ]), ), ), limits: PartitionLimits$outboundSchema, }).transform((v) => { return remap$(v, { isDefault: "is_default", limitExceededAt: "limit_exceeded_at", contextAware: "context_aware", metadataSchema: "metadata_schema", }); }); export function partitionToJSON(partition: Partition): string { return JSON.stringify(Partition$outboundSchema.parse(partition)); } export function partitionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Partition$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Partition' from JSON`, ); }