/** * Enumerated set of HTTP Patch operations */ export abstract class PatchOpType { public static readonly ADD: 'add' = 'add'; public static readonly REMOVE: 'remove' = 'remove'; public static readonly REPLACE: 'replace' = 'replace'; public static readonly COPY: 'copy' = 'copy'; public static readonly MOVE: 'move' = 'move'; public static readonly TEST: 'test' = 'test'; } type PatchOpTypes = 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test'; /** * HTTP Patch operations */ export type PatchOp = { op: T; path: string; } & ( T extends 'move' ? { from: string } : T extends 'copy' ? { from: string } : { } ) & ( T extends 'add' ? { value: any } : T extends 'replace' ? { value: any } : T extends 'test' ? { value: string } : { } ); /** * Expected payload for an HTTP Patch request */ export type PatchPayload = ( PatchOp<'add'> | PatchOp<'replace'> | PatchOp<'remove'> | PatchOp<'copy'> | PatchOp<'move'> | PatchOp<'test'> )[];