{ "version": 3, "sources": ["../../../../../../owl-nest/common/validators/numberWithComma.ts", "../../../../../../owl-nest/common/validators/locale.ts", "../../../../../../owl-nest/common/validators/index.ts", "../../../../../../owl-nest/common/validators/email.ts", "../../../../../../owl-nest/common/validators/file.ts", "../../../../../../owl-nest/common/validators/phone.ts", "../../../../../../owl-nest/common/validators/url.ts"], "sourcesContent": ["import * as yup from 'yup'\nimport { locales } from './locale'\n\nexport function numberWithComma() {\n return new NumberWithCommaSchema()\n}\n\nexport class NumberWithCommaSchema extends yup.NumberSchema {\n constructor() {\n super()\n\n // HACK: schema.type is supposed to be read-only, but who cares, right ?\n //@ts-ignore\n this.type = 'numberWithComma'\n\n this.withMutation((schema) => {\n this.transform(function (value, originalValue) {\n if (!isNaN(value)) {\n return value\n }\n return Number(String(originalValue).replace(/,/g, '.'))\n })\n\n schema.typeError(() => locales.numberWithComma.type())\n return schema\n })\n }\n}\n", "import { setLocale } from 'yup'\n\nimport { t } from '@owl-nest/localize'\n\nlet wasSet = false\n\nif (!wasSet) {\n wasSet = true\n setLocale({\n mixed: {\n default: () => t('This field is invalid'),\n required: () => t('This field is required'),\n },\n number: {\n integer: () => t('This field must an integer'),\n max: ({ max }) => t('This field must be lower than or equal to %(max)d').replace('%(max)d', max),\n min: ({ min }) => t('This field must be greater than or equal to %(min)d').replace('%(min)d', min),\n positive: () => t('This field must be superior to 0'),\n },\n string: {\n email: () => t('Please enter a valid e-mail address'),\n max: ({ max }) => t('This field must contain a maximum of %(max)d characters').replace('%(max)d', max),\n min: ({ min }) => t('This field must contain at least %(min)d characters').replace('%(min)d', min),\n url: () => t('Please enter a valid URL address'),\n },\n })\n}\n\nfunction humanFileSize(size: number) {\n if (size < 1000) return size + ' B'\n const i = Math.floor(Math.log(size) / Math.log(1000))\n const num = size / Math.pow(1000, i)\n const round = Math.round(num)\n const formattedNum = round < 100 ? num.toFixed(1) : round\n return `${formattedNum} ${'KMGTPEZY'[i - 1]}B`\n}\n\nexport const locales = {\n file: {\n max: (params: { max: number }) =>\n t('The file is too big. We allow files that are under %(maxSize)s', {\n maxSize: humanFileSize(params.max),\n }),\n formats: (params: { formats: string[] }) =>\n t('This type of file is not supported. We only support: %(supportedFiles)s.', {\n supportedFiles: params.formats.join(', '),\n }),\n },\n numberWithComma: {\n type: () => t('This field must be a number'),\n },\n phone: {\n format: () => t('Phone number is invalid'),\n max: (params: { max: number }) =>\n t('Your phone number cannot be more than %(length)d digits', {\n length: params.max,\n }),\n },\n}\n\nexport const strings = {\n slug: {\n formats: (params: { formats: string[] }) => t('Please enter a valid link. For example: my-project-link'),\n },\n}\n", "import './locale'\n\nexport * from './email'\nexport * from './file'\nexport * from './phone'\nexport * from './url'\nexport * from './numberWithComma'\n\nexport * from 'yup'\n", "import * as yup from 'yup'\n\nexport function email() {\n return new EmailSchema()\n}\n\nexport class EmailSchema extends yup.StringSchema {\n constructor() {\n super()\n\n // HACK\n // @ts-expect-error: schema.type is supposed to be read-only, but who cares, right ?\n this.type = 'email'\n\n this.withMutation((schema) => {\n return schema.email()\n })\n }\n}\n", "import * as yup from 'yup'\nimport { locales } from './locale'\n\nexport function file(): FileSchema {\n return new FileSchema()\n}\n\nexport class FileSchema extends yup.Schema {\n constructor() {\n super({\n type: 'file',\n check: (value: unknown): value is File => {\n return value instanceof File\n },\n })\n\n this.withMutation(() => {\n this.transform(function (value) {\n if (this.isType(value)) {\n // we have a valid value\n return value\n }\n throw 'error'\n })\n })\n }\n\n formats(formats: string[], message: yup.Message<{ formats: string[] }> = locales.file.formats): FileSchema {\n return this.test({\n message,\n name: 'formats',\n exclusive: true,\n params: { formats },\n test(value) {\n if (value === undefined) {\n return true\n }\n return formats.includes(value.type)\n },\n })\n }\n\n max(max: number, message: yup.Message<{ max: number }> = locales.file.max): FileSchema {\n return this.test({\n message,\n name: 'max',\n exclusive: true,\n params: { max },\n test(value) {\n if (value === undefined) {\n return true\n }\n return value.size <= max\n },\n })\n }\n}\n", "import * as yup from 'yup'\nimport * as libphone from 'libphonenumber-js/max'\n\nimport { locales } from './locale'\n\nexport function phone() {\n return new PhoneSchema()\n}\n\nexport class PhoneSchema extends yup.StringSchema {\n constructor() {\n super()\n\n // HACK\n // @ts-expect-error: schema.type is supposed to be read-only, but who cares, right ?\n this.type = 'phone'\n\n this.withMutation((schema) => {\n return schema.test('phone-number', locales.phone.format, (value) => {\n if (value === undefined) {\n return true\n }\n\n try {\n const number = libphone.parsePhoneNumber(value)\n return number.isValid()\n } catch (error) {\n return false\n }\n })\n })\n }\n\n size(max = 15, message: yup.Message<{ max: number }> = locales.phone.max) {\n return super.max(max, message)\n }\n}\n", "import * as yup from 'yup'\n\nexport function url(strict = false) {\n return new UrlSchema(strict)\n}\n\nexport class UrlSchema extends yup.StringSchema {\n constructor(strict?: boolean) {\n super()\n\n // HACK: schema.type is supposed to be read-only, but who cares, right ?\n //@ts-ignore\n this.type = 'url'\n\n this.withMutation((schema) => {\n this.transform(function (value) {\n // HACK: yup `url` validation doesn't understand URLs where origin has no TLD\n // Workaround for `localhost`, where we add a `.invalid` TLD (should not\n // be risky since `.invalid` is guaranteed to never exist)\n if (value.startsWith('http://localhost')) {\n return value.replace('http://localhost', 'http://localhost.invalid')\n }\n if (value && !strict && !value.match(/^((https?):)\\/\\//)) {\n return `https://${value}`\n }\n return value\n })\n return schema.url()\n })\n }\n}\n"], "mappings": "iLAAAA,IAAAC,ICAAC,IAAAC,IAIA,IAAIC,EAAS,GAERA,IACHA,EAAS,GACTC,EAAU,CACR,MAAO,CACL,QAAS,OAAM,KAAE,uBAAuB,EACxC,SAAU,OAAM,KAAE,wBAAwB,CAC5C,EACA,OAAQ,CACN,QAAS,OAAM,KAAE,4BAA4B,EAC7C,IAAK,CAAC,CAAE,IAAAC,CAAI,OAAM,KAAE,mDAAmD,EAAE,QAAQ,UAAWA,CAAG,EAC/F,IAAK,CAAC,CAAE,IAAAC,CAAI,OAAM,KAAE,qDAAqD,EAAE,QAAQ,UAAWA,CAAG,EACjG,SAAU,OAAM,KAAE,kC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QAEZ,KAAK,aAAcC,GACVA,EAAO,KAAK,eAAgBC,EAAQ,MAAM,OAASC,GAAU,CAClE,GAAIA,IAAU,OACZ,MAAO,GAGT,GAAI,CAEF,OADwBC,EAAiBD,CAAK,EAChC,QAAQ,CACxB,OAASE,EAAO,CACd,MAAO,EACT,CACF,CAAC,CACF,CACH,CAEA,KAAKC,EAAM,GAAIC,EAAwCL,EAAQ,MAAM,IAAK,CACxE,OAAO,MAAM,IAAII,EAAKC,CAAO,CAC/B,CACF,ECpCAC,IAAAC,IAEO,SAASC,EAAIC,EAAS,GAAO,CAClC,OAAO,IAAIC,EAAUD,CAAM,CAC7B,CAEO,IAAMC,EAAN,cAA4BC,CAAa,CAC9C,YAAYF,EAAkB,CAC5B,MAAM,EAIN,KAAK,KAAO,MAEZ,KAAK,aAAcG,IACjB,KAAK,UAAU,SAAUC,EAAO,CAI9B,OAAIA,EAAM,WAAW,kBAAkB,EAC9BA,EAAM,QAAQ,mBAAoB,0BAA0B,EAEjEA,GAAS,CAACJ,GAAU,CAACI,EAAM,MAAM,kBAAkB,EAC9C,WAAW,OAAAA,GAEbA,CACT,CAAC,EACMD,EAAO,IAAI,EACnB,CACH,CACF", "names": ["init_define_process_env", "init_sentry_release_injection_stub", "init_define_process_env", "init_sentry_release_injection_stub", "wasSet", "setLocale", "max", "min", "humanFileSize", "size", "i", "num", "round", "formattedNum", "locales", "params", "numberWithComma", "NumberWithCommaSchema", "NumberSchema", "schema", "value", "originalValue", "locales", "init_define_process_env", "init_sentry_release_injection_stub", "init_define_process_env", "init_sentry_release_injection_stub", "email", "EmailSchema", "StringSchema", "schema", "init_define_process_env", "init_sentry_release_injection_stub", "file", "FileSchema", "Schema", "value", "formats", "message", "locales", "max", "init_define_process_env", "init_sentry_release_injection_stub", "phone", "PhoneSchema", "StringSchema", "schema", "locales", "value", "parsePhoneNumberWithError", "error", "max", "message", "init_define_process_env", "init_sentry_release_injection_stub", "url", "strict", "UrlSchema", "StringSchema", "schema", "value"] }