@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
1 lines • 1.73 kB
Source Map (JSON)
{"version":3,"file":"zod.mjs","names":["z"],"sources":["../../src/utils/zod.ts"],"sourcesContent":["import { z } from 'zod'\nimport { ZodValidationError } from '../error'\n\n// biome-ignore lint/suspicious/noExplicitAny: no explanation\nexport type zBaseSchema = z.Schema<any, any, any>\n\nexport function zParseWithErrorHandling<Schema extends zBaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string\n): z.output<Schema> {\n const parseResult = schema.safeParse(data)\n\n if (!parseResult.success) {\n throw new ZodValidationError(\n customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,\n parseResult.error\n )\n }\n\n return parseResult.data\n}\n\nconst zUniqueArray = <const TItem extends zBaseSchema>(item: TItem) =>\n z.array(item).refine((a) => new Set<(typeof a)[number]>(a).size === a.length, 'Array must have unique values')\n\nconst zOptionalToUndefined = <const TItem extends zBaseSchema>(item: TItem) =>\n z.optional(item.transform(() => undefined))\n\nconst zBase64Url = z.string().regex(/[a-zA-Z0-9_-]+/, 'Must be a base64url string')\n\nconst zAnyUint8Array = z.instanceof<{ new (): Uint8Array }>(Uint8Array)\n\nexport { zAnyUint8Array, zBase64Url, zOptionalToUndefined, zUniqueArray }\n"],"mappings":";;;;AAMA,SAAgB,wBACd,QACA,MACA,oBACkB;CAClB,MAAM,cAAc,OAAO,UAAU,IAAI;CAEzC,IAAI,CAAC,YAAY,SACf,MAAM,IAAI,mBACR,sBAAsB,qCAAqC,KAAK,UAAU,IAAI,KAC9E,YAAY,KACd;CAGF,OAAO,YAAY;AACrB;AAEA,MAAM,gBAAiD,SACrDA,IAAE,MAAM,IAAI,CAAC,CAAC,QAAQ,MAAM,IAAI,IAAwB,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,+BAA+B;AAE/G,MAAM,wBAAyD,SAC7DA,IAAE,SAAS,KAAK,gBAAgB,KAAA,CAAS,CAAC;AAE5C,MAAM,aAAaA,IAAE,OAAO,CAAC,CAAC,MAAM,kBAAkB,4BAA4B;AAElF,MAAM,iBAAiBA,IAAE,WAAmC,UAAU"}