/// import type { AstJson, TypeDescription } from "@sdkgen/parser"; import { Decimal } from "decimal.js"; import type { DeepReadonly } from "./utils"; type TypeTable = AstJson["typeTable"]; type ExpandRecursively = T extends object ? (T extends infer O ? { [K in keyof O]: ExpandRecursively; } : never) : T; type JsonType = number | string | boolean | null | JsonType[] | { [Key in string]: JsonType; }; type AnyDecodedType = number | string | boolean | null | bigint | Decimal | Buffer | Date | AnyDecodedType[] | { [Key in string]: AnyDecodedType; }; export type DecodedType = TypeDescription extends Type ? AnyDecodedType : Type extends "string" | "email" | "html" | "xml" | "url" | "hex" | "uuid" | "base64" | "cpf" | "cnpj" ? string : Type extends "json" ? JsonType : Type extends "bool" ? boolean : Type extends "void" ? null : Type extends "int" | "uint" | "float" | "money" ? number : Type extends "bigint" ? bigint : Type extends "bytes" ? Buffer : Type extends "decimal" ? Decimal : Type extends "date" | "datetime" ? Date : Type extends `${infer X}?` ? DecodedType | null : Type extends `${infer X}[]` ? Array> : Type extends Array ? DecodedEnumType : Type extends ReadonlyArray ? DecodedEnumType : Type extends object ? { -readonly [Key in keyof Type]: DecodedType; } : object extends Table ? never : Type extends keyof Table ? DecodedType : never; type DecodedEnumType | ReadonlyArray, Table extends object> = Type[number] extends string ? Type[number] : DecodeTaggedEnumValueType; type DecodeTaggedEnumValueType = ValueType extends string ? { tag: ValueType; } : ValueType extends [infer Tag, infer Struct] ? ExpandRecursively<{ tag: Tag; } & DecodedType> : ValueType extends readonly [infer Tag, infer Struct] ? ExpandRecursively<{ tag: Tag; } & DecodedType> : never; export type EncodedType = TypeDescription extends Type ? JsonType : Type extends "string" | "email" | "html" | "xml" | "url" | "hex" | "uuid" | "base64" | "cpf" | "cnpj" ? string : Type extends "json" ? JsonType : Type extends "bool" ? boolean : Type extends "void" ? null : Type extends "int" | "uint" | "float" | "money" ? number : Type extends "bigint" | "bytes" | "date" | "datetime" | "decimal" ? string : Type extends `${infer X}?` ? EncodedType | null : Type extends `${infer X}[]` ? Array> : Type extends Array ? EnumEncodedValueType : Type extends ReadonlyArray ? EnumEncodedValueType : Type extends object ? { -readonly [Key in keyof Type]: EncodedType; } : object extends Table ? never : Type extends keyof Table ? EncodedType : never; type EnumEncodedValueType = ValueType extends string ? ValueType : ValueType extends [infer Tag, infer Struct] ? [Tag, EncodedType] : ValueType extends readonly [infer Tag, infer Struct] ? [Tag, EncodedType] : never; export declare function encode, Type extends DeepReadonly>(typeTable: Table, path: string, type: Type, value: unknown): EncodedType; export declare function decode
, Type extends DeepReadonly>(typeTable: Table, path: string, type: Type, value: unknown): DecodedType; export {};