clause.ts•2.29 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";
export type Clause = {
id?: string | undefined;
attribute: string;
op: string;
values: Array<any>;
contextKind?: string | undefined;
negate: boolean;
};
/** @internal */
export const Clause$inboundSchema: z.ZodType<Clause, z.ZodTypeDef, unknown> = z
.object({
_id: z.string().optional(),
attribute: z.string(),
op: z.string(),
values: z.array(z.any()),
contextKind: z.string().optional(),
negate: z.boolean(),
}).transform((v) => {
return remap$(v, {
"_id": "id",
});
});
/** @internal */
export type Clause$Outbound = {
_id?: string | undefined;
attribute: string;
op: string;
values: Array<any>;
contextKind?: string | undefined;
negate: boolean;
};
/** @internal */
export const Clause$outboundSchema: z.ZodType<
Clause$Outbound,
z.ZodTypeDef,
Clause
> = z.object({
id: z.string().optional(),
attribute: z.string(),
op: z.string(),
values: z.array(z.any()),
contextKind: z.string().optional(),
negate: z.boolean(),
}).transform((v) => {
return remap$(v, {
id: "_id",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Clause$ {
/** @deprecated use `Clause$inboundSchema` instead. */
export const inboundSchema = Clause$inboundSchema;
/** @deprecated use `Clause$outboundSchema` instead. */
export const outboundSchema = Clause$outboundSchema;
/** @deprecated use `Clause$Outbound` instead. */
export type Outbound = Clause$Outbound;
}
export function clauseToJSON(clause: Clause): string {
return JSON.stringify(Clause$outboundSchema.parse(clause));
}
export function clauseFromJSON(
jsonString: string,
): SafeParseResult<Clause, SDKValidationError> {
return safeParse(
jsonString,
(x) => Clause$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Clause' from JSON`,
);
}