@rpcbase/db 0.103.0 → 0.104.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,33 @@
1
1
  import { z as z$1 } from "zod";
2
+ const E164_PHONE_REGEX = /^\+[1-9]\d{1,14}$/;
3
+ const E164_PHONE_OR_EMPTY_REGEX = /^(?:\+[1-9]\d{1,14})?$/;
4
+ const makeZE164Phone = (zod, options) => {
5
+ const allowEmpty = options?.allowEmpty ?? false;
6
+ return zod.string().trim().regex(allowEmpty ? E164_PHONE_OR_EMPTY_REGEX : E164_PHONE_REGEX, {
7
+ message: allowEmpty ? "Expected an empty string or a phone number in E.164 format (e.g. +33608707197)." : "Expected a phone number in E.164 format (e.g. +33608707197)."
8
+ });
9
+ };
10
+ const zE164Phone = (options) => makeZE164Phone(z$1, options);
11
+ let zodPrototypesExtended = false;
12
+ function extendZod(zod) {
13
+ const zodWithExtension = zod;
14
+ if (Object.isExtensible(zodWithExtension) && typeof zodWithExtension.e164Phone !== "function") {
15
+ zodWithExtension.e164Phone = (options) => makeZE164Phone(zod, options);
16
+ }
17
+ if (zodPrototypesExtended) return;
18
+ zodPrototypesExtended = true;
19
+ const supported = [zod.ZodString, zod.ZodNumber, zod.ZodDate];
20
+ for (const type of supported) {
21
+ const proto = type?.prototype;
22
+ if (!proto) continue;
23
+ proto.unique = function unique(_flag = true) {
24
+ return this;
25
+ };
26
+ proto.sparse = function sparse(_flag = true) {
27
+ return this;
28
+ };
29
+ }
30
+ }
2
31
  const LANGUAGE_CODE_REGEX = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
3
32
  const LOCALIZED_STRING_PROXY_CACHE = /* @__PURE__ */ new WeakMap();
4
33
  function normalizeLocale(locale) {
@@ -94,35 +123,6 @@ const zLocalizedString = () => {
94
123
  return schema;
95
124
  };
96
125
  const zI18nString = zLocalizedString;
97
- const E164_PHONE_REGEX = /^\+[1-9]\d{1,14}$/;
98
- const E164_PHONE_OR_EMPTY_REGEX = /^(?:\+[1-9]\d{1,14})?$/;
99
- const makeZE164Phone = (zod, options) => {
100
- const allowEmpty = options?.allowEmpty ?? false;
101
- return zod.string().trim().regex(allowEmpty ? E164_PHONE_OR_EMPTY_REGEX : E164_PHONE_REGEX, {
102
- message: allowEmpty ? "Expected an empty string or a phone number in E.164 format (e.g. +33608707197)." : "Expected a phone number in E.164 format (e.g. +33608707197)."
103
- });
104
- };
105
- const zE164Phone = (options) => makeZE164Phone(z$1, options);
106
- let zodPrototypesExtended = false;
107
- function extendZod(zod) {
108
- const zodWithExtension = zod;
109
- if (Object.isExtensible(zodWithExtension) && typeof zodWithExtension.e164Phone !== "function") {
110
- zodWithExtension.e164Phone = (options) => makeZE164Phone(zod, options);
111
- }
112
- if (zodPrototypesExtended) return;
113
- zodPrototypesExtended = true;
114
- const supported = [zod.ZodString, zod.ZodNumber, zod.ZodDate];
115
- for (const type of supported) {
116
- const proto = type?.prototype;
117
- if (!proto) continue;
118
- proto.unique = function unique(_flag = true) {
119
- return this;
120
- };
121
- proto.sparse = function sparse(_flag = true) {
122
- return this;
123
- };
124
- }
125
- }
126
126
  const z = Object.create(z$1);
127
127
  extendZod(z);
128
128
  export {
@@ -139,4 +139,4 @@ export {
139
139
  withLocalizedStringFallback as w,
140
140
  z
141
141
  };
142
- //# sourceMappingURL=index-BNcI2Uw0.js.map
142
+ //# sourceMappingURL=index-DrIoUXc2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-DrIoUXc2.js","sources":["../src/zod/e164Phone.ts","../src/zod/extension.ts","../src/zod/localizedString.ts","../src/zod/index.ts"],"sourcesContent":["import { z } from \"zod\"\n\n\nexport const E164_PHONE_REGEX = /^\\+[1-9]\\d{1,14}$/\nexport const E164_PHONE_OR_EMPTY_REGEX = /^(?:\\+[1-9]\\d{1,14})?$/\n\nexport type E164PhoneOptions = {\n allowEmpty?: boolean\n}\n\nexport const makeZE164Phone = (zod: typeof z, options?: E164PhoneOptions) => {\n const allowEmpty = options?.allowEmpty ?? false\n return zod.string().trim().regex(allowEmpty ? E164_PHONE_OR_EMPTY_REGEX : E164_PHONE_REGEX, {\n message: allowEmpty\n ? \"Expected an empty string or a phone number in E.164 format (e.g. +33608707197).\"\n : \"Expected a phone number in E.164 format (e.g. +33608707197).\",\n })\n}\n\nexport const zE164Phone = (options?: E164PhoneOptions) => makeZE164Phone(z, options)\n","import { z } from \"zod\"\n\nimport { type E164PhoneOptions, makeZE164Phone } from \"./e164Phone\"\n\n\ntype RpcbaseZodExtension = typeof z & {\n e164Phone?: (options?: E164PhoneOptions) => z.ZodString\n}\n\ntype ExtendableZodPrototype = {\n unique?: (this: unknown, arg?: boolean) => unknown\n sparse?: (this: unknown, arg?: boolean) => unknown\n}\n\ndeclare module \"zod\" {\n interface ZodString {\n unique(arg?: boolean): this\n sparse(arg?: boolean): this\n }\n\n interface ZodNumber {\n unique(arg?: boolean): this\n sparse(arg?: boolean): this\n }\n\n interface ZodDate {\n unique(arg?: boolean): this\n sparse(arg?: boolean): this\n }\n\n}\n\nlet zodPrototypesExtended = false\n\nexport function extendZod(zod: typeof z) {\n const zodWithExtension = zod as RpcbaseZodExtension\n if (Object.isExtensible(zodWithExtension) && typeof zodWithExtension.e164Phone !== \"function\") {\n zodWithExtension.e164Phone = (options?: E164PhoneOptions) => makeZE164Phone(zod, options)\n }\n\n if (zodPrototypesExtended) return\n zodPrototypesExtended = true\n\n const supported = [zod.ZodString, zod.ZodNumber, zod.ZodDate] as const\n for (const type of supported) {\n const proto = type?.prototype as ExtendableZodPrototype | undefined\n if (!proto) continue\n\n proto.unique = function unique(this: unknown, _flag = true) {\n return this\n }\n\n proto.sparse = function sparse(this: unknown, _flag = true) {\n return this\n }\n }\n}\n","import { z } from \"zod\"\n\n\nexport type LanguageCode = string\n\nexport type LocalizedStringEntry<TExtra extends Record<string, unknown> = Record<string, unknown>> = {\n value: string\n updatedAt: Date\n autoTranslated?: boolean\n} & TExtra\n\nexport type LocalizedString<TExtra extends Record<string, unknown> = Record<string, unknown>> = Record<\n LanguageCode,\n LocalizedStringEntry<TExtra>\n>\n\nexport type I18nStringRecord = LocalizedString\n\nexport type I18nString = LocalizedString\n\nexport type LocalizedStringWithFallback = LocalizedString & {\n get: (key: string) => LocalizedStringEntry | undefined\n getExact: (key: string) => LocalizedStringEntry | undefined\n hasExact: (key: string) => boolean\n}\n\nexport const LANGUAGE_CODE_REGEX = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/\n\nconst LOCALIZED_STRING_PROXY_CACHE = new WeakMap<object, unknown>()\n\nfunction normalizeLocale(locale: string): string {\n const trimmed = locale.trim()\n if (!trimmed) return \"\"\n const getCanonicalLocales = (Intl as typeof Intl & {\n getCanonicalLocales?: (locales: string | readonly string[]) => string[]\n }).getCanonicalLocales\n if (typeof getCanonicalLocales !== \"function\") return trimmed\n try {\n return getCanonicalLocales(trimmed)[0] ?? trimmed\n } catch {\n return trimmed\n }\n}\n\nexport function buildLocaleFallbackChain(locale: string, fallbacks?: string | string[]): string[] {\n const base = locale.trim()\n const canonical = normalizeLocale(base)\n const extra = typeof fallbacks === \"string\" ? [fallbacks] : (fallbacks ?? [])\n\n const output: string[] = []\n const seen = new Set<string>()\n\n const push = (value: string) => {\n if (!value) return\n if (seen.has(value)) return\n seen.add(value)\n output.push(value)\n }\n\n const addChain = (value: string) => {\n if (!value) return\n const parts = value.split(\"-\").filter(Boolean)\n while (parts.length > 0) {\n push(parts.join(\"-\"))\n parts.pop()\n }\n }\n\n addChain(base)\n addChain(canonical)\n for (const fallback of extra) addChain(normalizeLocale(fallback))\n\n return output\n}\n\nexport function resolveLocalizedString(\n value: LocalizedString | null | undefined,\n locale: string,\n options?: { fallbacks?: string | string[] }\n): string | undefined {\n return resolveLocalizedStringEntry(value, locale, options)?.value\n}\n\nfunction resolveLocalizedStringEntry(\n value: LocalizedString | null | undefined,\n locale: string,\n options?: { fallbacks?: string | string[] }\n): LocalizedStringEntry | undefined {\n if (!value) return undefined\n const chain = buildLocaleFallbackChain(locale, options?.fallbacks)\n if (chain.length === 0) return undefined\n\n const record = value\n for (const key of chain) {\n if (!Object.prototype.hasOwnProperty.call(record, key)) continue\n return record[key] as LocalizedStringEntry\n }\n return undefined\n}\n\nexport function withLocalizedStringFallback<T>(value: T): T {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return value\n if (value instanceof Map) return value\n const cached = LOCALIZED_STRING_PROXY_CACHE.get(value)\n if (cached) return cached as T\n\n const proxy = withFallbackRecord(value as Record<string, unknown>)\n LOCALIZED_STRING_PROXY_CACHE.set(value, proxy)\n return proxy as T\n}\n\nfunction withFallbackRecord(record: Record<string, unknown>): LocalizedStringWithFallback {\n const getExact = (key: string): LocalizedStringEntry | undefined => {\n if (!hasExact(key)) return undefined\n return record[key] as LocalizedStringEntry\n }\n const hasExact = (key: string) => Object.prototype.hasOwnProperty.call(record, key)\n\n return new Proxy(record, {\n get(target, prop) {\n if (prop === \"getExact\") return getExact\n if (prop === \"hasExact\") return hasExact\n if (prop === \"get\") return (key: string) => resolveLocalizedStringEntry(target as LocalizedString, key)\n if (typeof prop === \"string\" && !(prop in target)) {\n return resolveLocalizedStringEntry(target as LocalizedString, prop)\n }\n\n return Reflect.get(target, prop)\n },\n set(target, prop, next) {\n return Reflect.set(target, prop, next)\n },\n }) as LocalizedStringWithFallback\n}\n\nexport const zLocalizedString = () => {\n const languageCodeSchema = z\n .string()\n .regex(LANGUAGE_CODE_REGEX, { message: \"Expected a language code (BCP 47, e.g. en or fr-FR).\" })\n const entrySchema = z.object({\n value: z.string(),\n updatedAt: z.date(),\n autoTranslated: z.boolean().optional(),\n }).passthrough()\n const schema = z.record(\n languageCodeSchema,\n entrySchema,\n )\n\n return schema\n}\n\nexport const zI18nString = zLocalizedString\n","import { z as baseZ, type ZodError, type ZodString, type ZodType } from \"zod\"\n\nimport { extendZod } from \"./extension\"\n\n\nexport * from \"./e164Phone\"\nexport * from \"./localizedString\"\n\nexport type RpcbaseZod = typeof baseZ & {\n e164Phone: (options?: import(\"./e164Phone\").E164PhoneOptions) => ZodString\n}\n\nexport const z = Object.create(baseZ) as RpcbaseZod\nextendZod(z)\n\nexport namespace z {\n export type infer<T> = import(\"zod\").infer<T>\n export type input<T> = import(\"zod\").input<T>\n export type output<T> = import(\"zod\").output<T>\n export type TypeOf<T> = import(\"zod\").TypeOf<T>\n export type Infer<T> = import(\"zod\").Infer<T>\n}\n\nexport { extendZod, ZodError, ZodType }\n"],"names":["E164_PHONE_REGEX","E164_PHONE_OR_EMPTY_REGEX","makeZE164Phone","zod","options","allowEmpty","string","trim","regex","message","zE164Phone","z","zodPrototypesExtended","extendZod","zodWithExtension","Object","isExtensible","e164Phone","supported","ZodString","ZodNumber","ZodDate","type","proto","prototype","unique","_flag","sparse","LANGUAGE_CODE_REGEX","LOCALIZED_STRING_PROXY_CACHE","WeakMap","normalizeLocale","locale","trimmed","getCanonicalLocales","Intl","buildLocaleFallbackChain","fallbacks","base","canonical","extra","output","seen","Set","push","value","has","add","addChain","parts","split","filter","Boolean","length","join","pop","fallback","resolveLocalizedString","resolveLocalizedStringEntry","undefined","chain","record","key","hasOwnProperty","call","withLocalizedStringFallback","Array","isArray","Map","cached","get","proxy","withFallbackRecord","set","getExact","hasExact","Proxy","target","prop","Reflect","next","zLocalizedString","languageCodeSchema","entrySchema","object","updatedAt","date","autoTranslated","boolean","optional","passthrough","schema","zI18nString","create","baseZ"],"mappings":";AAGO,MAAMA,mBAAmB;AACzB,MAAMC,4BAA4B;AAMlC,MAAMC,iBAAiBA,CAACC,KAAeC,YAA+B;AAC3E,QAAMC,aAAaD,SAASC,cAAc;AAC1C,SAAOF,IAAIG,SAASC,KAAAA,EAAOC,MAAMH,aAAaJ,4BAA4BD,kBAAkB;AAAA,IAC1FS,SAASJ,aACL,oFACA;AAAA,EAAA,CACL;AACH;AAEO,MAAMK,aAAaA,CAACN,YAA+BF,eAAeS,KAAGP,OAAO;ACanF,IAAIQ,wBAAwB;AAErB,S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c, d, f } from "./index-DrIoUXc2.js";
2
2
  export {
3
3
  E as E164_PHONE_OR_EMPTY_REGEX,
4
4
  a as E164_PHONE_REGEX,
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ import mongoose, { Schema as Schema$1, Types } from "mongoose";
4
4
  import { default as default2 } from "mongoose";
5
5
  import { z } from "zod";
6
6
  import { timingSafeEqual, createHmac } from "node:crypto";
7
- import { w as withLocalizedStringFallback } from "./index-BNcI2Uw0.js";
8
- import { E, a as a2, L, b as b2, e as e2, m, r, z as z2, c as c2, d as d2, f as f2 } from "./index-BNcI2Uw0.js";
7
+ import { w as withLocalizedStringFallback } from "./index-DrIoUXc2.js";
8
+ import { E, a as a2, L, b as b2, e as e2, m, r, z as z2, c as c2, d as d2, f as f2 } from "./index-DrIoUXc2.js";
9
9
  import assert from "assert";
10
10
  import { getMongoUrl, getMongoDirectConnection } from "./mongo.js";
11
11
  import { accessibleBy, accessibleRecordsPlugin } from "@casl/mongoose";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/db",
3
- "version": "0.103.0",
3
+ "version": "0.104.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-BNcI2Uw0.js","sources":["../src/zod/localizedString.ts","../src/zod/e164Phone.ts","../src/zod/extension.ts","../src/zod/index.ts"],"sourcesContent":["import { z } from \"zod\"\n\n\nexport type LanguageCode = string\n\nexport type LocalizedStringEntry<TExtra extends Record<string, unknown> = Record<string, unknown>> = {\n value: string\n updatedAt: Date\n autoTranslated?: boolean\n} & TExtra\n\nexport type LocalizedString<TExtra extends Record<string, unknown> = Record<string, unknown>> = Record<\n LanguageCode,\n LocalizedStringEntry<TExtra>\n>\n\nexport type I18nStringRecord = LocalizedString\n\nexport type I18nString = LocalizedString\n\nexport type LocalizedStringWithFallback = LocalizedString & {\n get: (key: string) => LocalizedStringEntry | undefined\n getExact: (key: string) => LocalizedStringEntry | undefined\n hasExact: (key: string) => boolean\n}\n\nexport const LANGUAGE_CODE_REGEX = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/\n\nconst LOCALIZED_STRING_PROXY_CACHE = new WeakMap<object, unknown>()\n\nfunction normalizeLocale(locale: string): string {\n const trimmed = locale.trim()\n if (!trimmed) return \"\"\n const getCanonicalLocales = (Intl as typeof Intl & {\n getCanonicalLocales?: (locales: string | readonly string[]) => string[]\n }).getCanonicalLocales\n if (typeof getCanonicalLocales !== \"function\") return trimmed\n try {\n return getCanonicalLocales(trimmed)[0] ?? trimmed\n } catch {\n return trimmed\n }\n}\n\nexport function buildLocaleFallbackChain(locale: string, fallbacks?: string | string[]): string[] {\n const base = locale.trim()\n const canonical = normalizeLocale(base)\n const extra = typeof fallbacks === \"string\" ? [fallbacks] : (fallbacks ?? [])\n\n const output: string[] = []\n const seen = new Set<string>()\n\n const push = (value: string) => {\n if (!value) return\n if (seen.has(value)) return\n seen.add(value)\n output.push(value)\n }\n\n const addChain = (value: string) => {\n if (!value) return\n const parts = value.split(\"-\").filter(Boolean)\n while (parts.length > 0) {\n push(parts.join(\"-\"))\n parts.pop()\n }\n }\n\n addChain(base)\n addChain(canonical)\n for (const fallback of extra) addChain(normalizeLocale(fallback))\n\n return output\n}\n\nexport function resolveLocalizedString(\n value: LocalizedString | null | undefined,\n locale: string,\n options?: { fallbacks?: string | string[] }\n): string | undefined {\n return resolveLocalizedStringEntry(value, locale, options)?.value\n}\n\nfunction resolveLocalizedStringEntry(\n value: LocalizedString | null | undefined,\n locale: string,\n options?: { fallbacks?: string | string[] }\n): LocalizedStringEntry | undefined {\n if (!value) return undefined\n const chain = buildLocaleFallbackChain(locale, options?.fallbacks)\n if (chain.length === 0) return undefined\n\n const record = value\n for (const key of chain) {\n if (!Object.prototype.hasOwnProperty.call(record, key)) continue\n return record[key] as LocalizedStringEntry\n }\n return undefined\n}\n\nexport function withLocalizedStringFallback<T>(value: T): T {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return value\n if (value instanceof Map) return value\n const cached = LOCALIZED_STRING_PROXY_CACHE.get(value)\n if (cached) return cached as T\n\n const proxy = withFallbackRecord(value as Record<string, unknown>)\n LOCALIZED_STRING_PROXY_CACHE.set(value, proxy)\n return proxy as T\n}\n\nfunction withFallbackRecord(record: Record<string, unknown>): LocalizedStringWithFallback {\n const getExact = (key: string): LocalizedStringEntry | undefined => {\n if (!hasExact(key)) return undefined\n return record[key] as LocalizedStringEntry\n }\n const hasExact = (key: string) => Object.prototype.hasOwnProperty.call(record, key)\n\n return new Proxy(record, {\n get(target, prop) {\n if (prop === \"getExact\") return getExact\n if (prop === \"hasExact\") return hasExact\n if (prop === \"get\") return (key: string) => resolveLocalizedStringEntry(target as LocalizedString, key)\n if (typeof prop === \"string\" && !(prop in target)) {\n return resolveLocalizedStringEntry(target as LocalizedString, prop)\n }\n\n return Reflect.get(target, prop)\n },\n set(target, prop, next) {\n return Reflect.set(target, prop, next)\n },\n }) as LocalizedStringWithFallback\n}\n\nexport const zLocalizedString = () => {\n const languageCodeSchema = z\n .string()\n .regex(LANGUAGE_CODE_REGEX, { message: \"Expected a language code (BCP 47, e.g. en or fr-FR).\" })\n const entrySchema = z.object({\n value: z.string(),\n updatedAt: z.date(),\n autoTranslated: z.boolean().optional(),\n }).passthrough()\n const schema = z.record(\n languageCodeSchema,\n entrySchema,\n )\n\n return schema\n}\n\nexport const zI18nString = zLocalizedString\n","import { z } from \"zod\"\n\n\nexport const E164_PHONE_REGEX = /^\\+[1-9]\\d{1,14}$/\nexport const E164_PHONE_OR_EMPTY_REGEX = /^(?:\\+[1-9]\\d{1,14})?$/\n\nexport type E164PhoneOptions = {\n allowEmpty?: boolean\n}\n\nexport const makeZE164Phone = (zod: typeof z, options?: E164PhoneOptions) => {\n const allowEmpty = options?.allowEmpty ?? false\n return zod.string().trim().regex(allowEmpty ? E164_PHONE_OR_EMPTY_REGEX : E164_PHONE_REGEX, {\n message: allowEmpty\n ? \"Expected an empty string or a phone number in E.164 format (e.g. +33608707197).\"\n : \"Expected a phone number in E.164 format (e.g. +33608707197).\",\n })\n}\n\nexport const zE164Phone = (options?: E164PhoneOptions) => makeZE164Phone(z, options)\n","import { z } from \"zod\"\n\nimport { type E164PhoneOptions, makeZE164Phone } from \"./e164Phone\"\n\n\ntype RpcbaseZodExtension = typeof z & {\n e164Phone?: (options?: E164PhoneOptions) => z.ZodString\n}\n\ntype ExtendableZodPrototype = {\n unique?: (this: unknown, arg?: boolean) => unknown\n sparse?: (this: unknown, arg?: boolean) => unknown\n}\n\ndeclare module \"zod\" {\n interface ZodString {\n unique(arg?: boolean): this\n sparse(arg?: boolean): this\n }\n\n interface ZodNumber {\n unique(arg?: boolean): this\n sparse(arg?: boolean): this\n }\n\n interface ZodDate {\n unique(arg?: boolean): this\n sparse(arg?: boolean): this\n }\n\n}\n\nlet zodPrototypesExtended = false\n\nexport function extendZod(zod: typeof z) {\n const zodWithExtension = zod as RpcbaseZodExtension\n if (Object.isExtensible(zodWithExtension) && typeof zodWithExtension.e164Phone !== \"function\") {\n zodWithExtension.e164Phone = (options?: E164PhoneOptions) => makeZE164Phone(zod, options)\n }\n\n if (zodPrototypesExtended) return\n zodPrototypesExtended = true\n\n const supported = [zod.ZodString, zod.ZodNumber, zod.ZodDate] as const\n for (const type of supported) {\n const proto = type?.prototype as ExtendableZodPrototype | undefined\n if (!proto) continue\n\n proto.unique = function unique(this: unknown, _flag = true) {\n return this\n }\n\n proto.sparse = function sparse(this: unknown, _flag = true) {\n return this\n }\n }\n}\n","import { z as baseZ, type ZodError, type ZodString, type ZodType } from \"zod\"\n\nimport { extendZod } from \"./extension\"\n\n\nexport * from \"./e164Phone\"\nexport * from \"./localizedString\"\n\nexport type RpcbaseZod = typeof baseZ & {\n e164Phone: (options?: import(\"./e164Phone\").E164PhoneOptions) => ZodString\n}\n\nexport const z = Object.create(baseZ) as RpcbaseZod\nextendZod(z)\n\nexport namespace z {\n export type infer<T> = import(\"zod\").infer<T>\n export type input<T> = import(\"zod\").input<T>\n export type output<T> = import(\"zod\").output<T>\n export type TypeOf<T> = import(\"zod\").TypeOf<T>\n export type Infer<T> = import(\"zod\").Infer<T>\n}\n\nexport { extendZod, ZodError, ZodType }\n"],"names":["LANGUAGE_CODE_REGEX","LOCALIZED_STRING_PROXY_CACHE","WeakMap","normalizeLocale","locale","trimmed","trim","getCanonicalLocales","Intl","buildLocaleFallbackChain","fallbacks","base","canonical","extra","output","seen","Set","push","value","has","add","addChain","parts","split","filter","Boolean","length","join","pop","fallback","resolveLocalizedString","options","resolveLocalizedStringEntry","undefined","chain","record","key","Object","prototype","hasOwnProperty","call","withLocalizedStringFallback","Array","isArray","Map","cached","get","proxy","withFallbackRecord","set","getExact","hasExact","Proxy","target","prop","Reflect","next","zLocalizedString","languageCodeSchema","z","string","regex","message","entrySchema","object","updatedAt","date","autoTranslated","boolean","optional","passthrough","schema","zI18nString","E164_PHONE_REGEX","E164_PHONE_OR_EMPTY_REGEX","makeZE164Phone","zod","allowEmpty","zE164Phone","zodPrototypesExtended","extendZod","zodWithExtension","isExtensible","e164Phone","supported","ZodString","ZodNumber","ZodDate","type","proto","unique","_flag","sparse","create","baseZ"],"mappings":";AA0BO,MAAMA,sBAAsB;AAEnC,MAAMC,mDAAmCC,QAAAA;AAEzC,SAASC,gBAAgBC,QAAwB;AAC/C,QAAMC,UAAUD,OAAOE,KAAAA;AACvB,MAAI,CAACD,QAAS,QAAO;AACrB,QAAME,sBAAuBC,KAE1BD;AACH,MAAI,OAAOA,wBAAwB,WAAY,QAAOF;AACtD,MAAI;AACF,WAAOE,oBAAoBF,OAAO,EAAE,CAAC,KAAKA;AAAAA,EAC5C,QAAQ;AACN,WAAOA;AAAAA,EACT;AACF;AAEO,SAASI,yBAAyBL,QAAgBM,WAAyC;AAChG,QAAMC,OAAOP,OAAOE,KAAAA;AACpB,QAAMM,YAAYT,gBAAgBQ,IAAI;AACtC,QAAME,QAAQ,OAAOH,cAAc,WAAW,CAACA,SAAS,IA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