{"version":3,"file":"replaceLeaves.cjs","sources":["../../../src/lib/replaceLeaves.ts"],"sourcesContent":["const isPlainObject = <Value>(\n\tvalue: unknown,\n): value is Record<PropertyKey, Value> => {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\n\tconst prototype = Object.getPrototypeOf(value);\n\n\treturn (\n\t\t(prototype === null ||\n\t\t\tprototype === Object.prototype ||\n\t\t\tObject.getPrototypeOf(prototype) === null) &&\n\t\t!(Symbol.toStringTag in value) &&\n\t\t!(Symbol.iterator in value)\n\t);\n};\n\ntype Replacer = (value: unknown) => unknown | Promise<unknown>;\n\ntype ReplaceLeavesReturnValue<TInput> =\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTInput extends any[]\n\t\t? unknown[]\n\t\t: // eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tTInput extends Record<PropertyKey, any>\n\t\t\t? { [P in keyof TInput]: unknown }\n\t\t\t: unknown;\n\nexport const replaceLeaves = async <TInput>(\n\tinput: TInput,\n\treplacer: Replacer,\n): Promise<ReplaceLeavesReturnValue<TInput>> => {\n\tif (Array.isArray(input)) {\n\t\tconst preparedProcedureArgs: unknown[] = [];\n\n\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\tpreparedProcedureArgs[i] = await replaceLeaves(input[i], replacer);\n\t\t}\n\n\t\treturn preparedProcedureArgs as ReplaceLeavesReturnValue<TInput>;\n\t}\n\n\tif (isPlainObject(input)) {\n\t\tconst preparedProcedureArgs: Record<PropertyKey, unknown> = {};\n\n\t\tfor (const key in input) {\n\t\t\tpreparedProcedureArgs[key] = await replaceLeaves(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\treplacer,\n\t\t\t);\n\t\t}\n\n\t\treturn preparedProcedureArgs as ReplaceLeavesReturnValue<TInput>;\n\t}\n\n\treturn (await replacer(input)) as ReplaceLeavesReturnValue<TInput>;\n};\n"],"names":[],"mappings":";;AAAA,MAAM,gBAAgB,CACrB,UACwC;AACxC,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AACzC,WAAA;AAAA,EACP;AAEK,QAAA,YAAY,OAAO,eAAe,KAAK;AAE7C,UACE,cAAc,QACd,cAAc,OAAO,aACrB,OAAO,eAAe,SAAS,MAAM,SACtC,EAAE,OAAO,eAAe,UACxB,EAAE,OAAO,YAAY;AAEvB;AAaa,MAAA,gBAAgB,OAC5B,OACA,aAC8C;AAC1C,MAAA,MAAM,QAAQ,KAAK,GAAG;AACzB,UAAM,wBAAmC,CAAA;AAEzC,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,4BAAsB,CAAC,IAAI,MAAM,cAAc,MAAM,CAAC,GAAG,QAAQ;AAAA,IACjE;AAEM,WAAA;AAAA,EACP;AAEG,MAAA,cAAc,KAAK,GAAG;AACzB,UAAM,wBAAsD,CAAA;AAE5D,eAAW,OAAO,OAAO;AACxB,4BAAsB,GAAG,IAAI,MAAM,cAClC,MAAM,GAAyB,GAC/B,QAAQ;AAAA,IAET;AAEM,WAAA;AAAA,EACP;AAEO,SAAA,MAAM,SAAS,KAAK;AAC7B;;"}