patchoperation.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 PatchOperation = {
/**
* The type of operation to perform
*/
op: string;
/**
* A JSON Pointer string specifying the part of the document to operate on
*/
path: string;
/**
* A JSON value used in "add", "replace", and "test" operations
*/
value?: any | undefined;
};
/** @internal */
export const PatchOperation$inboundSchema: z.ZodType<
PatchOperation,
z.ZodTypeDef,
unknown
> = z.object({
op: z.string(),
path: z.string(),
value: z.any().optional(),
});
/** @internal */
export type PatchOperation$Outbound = {
op: string;
path: string;
value?: any | undefined;
};
/** @internal */
export const PatchOperation$outboundSchema: z.ZodType<
PatchOperation$Outbound,
z.ZodTypeDef,
PatchOperation
> = z.object({
op: z.string(),
path: z.string(),
value: z.any().optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace PatchOperation$ {
/** @deprecated use `PatchOperation$inboundSchema` instead. */
export const inboundSchema = PatchOperation$inboundSchema;
/** @deprecated use `PatchOperation$outboundSchema` instead. */
export const outboundSchema = PatchOperation$outboundSchema;
/** @deprecated use `PatchOperation$Outbound` instead. */
export type Outbound = PatchOperation$Outbound;
}
export function patchOperationToJSON(patchOperation: PatchOperation): string {
return JSON.stringify(PatchOperation$outboundSchema.parse(patchOperation));
}
export function patchOperationFromJSON(
jsonString: string,
): SafeParseResult<PatchOperation, SDKValidationError> {
return safeParse(
jsonString,
(x) => PatchOperation$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'PatchOperation' from JSON`,
);
}