@karmaniverous/jsonmap
Version:
A hyper-generic JSON mapping library.
74 lines (70 loc) • 1.94 kB
text/typescript
import { z } from 'zod';
interface JsonMapOptions {
ignore?: string | RegExp;
}
declare const JsonMapDynamic: z.ZodObject<{
$: z.ZodUnion<[z.ZodObject<{
method: z.ZodString;
params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
}, "strip", z.ZodTypeAny, {
method: string;
params: string | string[];
}, {
method: string;
params: string | string[];
}>, z.ZodArray<z.ZodObject<{
method: z.ZodString;
params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
}, "strip", z.ZodTypeAny, {
method: string;
params: string | string[];
}, {
method: string;
params: string | string[];
}>, "many">]>;
}, "strip", z.ZodTypeAny, {
$: {
method: string;
params: string | string[];
} | {
method: string;
params: string | string[];
}[];
}, {
$: {
method: string;
params: string | string[];
} | {
method: string;
params: string | string[];
}[];
}>;
type JsonMapDynamic = z.infer<typeof JsonMapDynamic>;
declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
type Literal = z.infer<typeof literalSchema>;
type Json = Literal | {
[key: string]: Json;
} | Json[];
type JsonMapLib = {
[key: string]: JsonMapLib | ((x: any) => any);
} | JsonMapLib[];
type JsonMapMap = Literal | {
[key: string]: JsonMapMap | JsonMapDynamic;
} | JsonMapMap[];
/**
* JsonMap class to apply transformations to a JSON object
*/
declare class JsonMap {
#private;
private map;
private lib;
private ignore;
private input;
private output;
constructor(map?: JsonMapMap, lib?: JsonMapLib, { ignore }?: JsonMapOptions);
/**
* Transforms the input data according to the map configuration.
*/
transform(input: Json): Promise<Json>;
}
export { JsonMap };