@rpcbase/db 0.41.0 → 0.43.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.
@@ -85,15 +85,18 @@ const zLocalizedString = () => {
85
85
  };
86
86
  const zI18nString = zLocalizedString;
87
87
  const E164_PHONE_REGEX = /^\+[1-9]\d{1,14}$/;
88
- const zE164Phone = () => z$1.string().trim().regex(E164_PHONE_REGEX, {
89
- message: "Expected a phone number in E.164 format (e.g. +33608707197)."
90
- });
88
+ const E164_PHONE_OR_EMPTY_REGEX = /^(?:\+[1-9]\d{1,14})?$/;
89
+ const makeZE164Phone = (zod, options) => {
90
+ const allowEmpty = options?.allowEmpty ?? false;
91
+ return zod.string().trim().regex(allowEmpty ? E164_PHONE_OR_EMPTY_REGEX : E164_PHONE_REGEX, {
92
+ 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)."
93
+ });
94
+ };
95
+ const zE164Phone = (options) => makeZE164Phone(z$1, options);
91
96
  let zodPrototypesExtended = false;
92
97
  function extendZod(zod) {
93
98
  if (Object.isExtensible(zod) && typeof zod.e164Phone !== "function") {
94
- zod.e164Phone = () => zod.string().trim().regex(E164_PHONE_REGEX, {
95
- message: "Expected a phone number in E.164 format (e.g. +33608707197)."
96
- });
99
+ zod.e164Phone = (options) => makeZE164Phone(zod, options);
97
100
  }
98
101
  if (zodPrototypesExtended) return;
99
102
  zodPrototypesExtended = true;
@@ -114,13 +117,15 @@ extendZod(z);
114
117
  export {
115
118
  E164_PHONE_REGEX as E,
116
119
  LANGUAGE_CODE_REGEX as L,
117
- zE164Phone as a,
118
- buildLocaleFallbackChain as b,
119
- zLocalizedString as c,
120
- zI18nString as d,
120
+ E164_PHONE_OR_EMPTY_REGEX as a,
121
+ zE164Phone as b,
122
+ buildLocaleFallbackChain as c,
123
+ zLocalizedString as d,
121
124
  extendZod as e,
125
+ zI18nString as f,
126
+ makeZE164Phone as m,
122
127
  resolveLocalizedString as r,
123
128
  withLocalizedStringFallback as w,
124
129
  z
125
130
  };
126
- //# sourceMappingURL=index-SiSvd0kf.js.map
131
+ //# sourceMappingURL=index-Bj25CvzZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-Bj25CvzZ.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 LocalizedString = Record<LanguageCode, string>\n\nexport type I18nStringRecord = LocalizedString\n\nexport type I18nString = LocalizedString\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 any)?.getCanonicalLocales as ((locales: string | string[]) => string[]) | undefined\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 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]\n }\n return undefined\n}\n\nexport function withLocalizedStringFallback<T extends object>(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 any)\n LOCALIZED_STRING_PROXY_CACHE.set(value, proxy)\n return proxy as T\n}\n\nfunction withFallbackRecord(record: LocalizedString) {\n const getExact = (key: string) => record[key]\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) => resolveLocalizedString(record, key)\n if (typeof prop === \"string\" && !(prop in target)) {\n return resolveLocalizedString(record, prop)\n }\n\n return (target as any)[prop]\n },\n set(target, prop, next) {\n ;(target as any)[prop] = next\n return true\n },\n })\n}\n\nexport const zLocalizedString = () => {\n const schema = z.record(\n z\n .string()\n .regex(LANGUAGE_CODE_REGEX, { message: \"Expected a language code (BCP 47, e.g. en or fr-FR).\" }),\n z.string()\n ) as z.ZodRecord<z.ZodString, z.ZodString>\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\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 if (Object.isExtensible(zod) && typeof (zod as any).e164Phone !== \"function\") {\n ;(zod as any).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: any = type?.prototype\n if (!proto) continue\n\n proto.unique = function unique(this: any, _flag = true) {\n return this\n }\n\n proto.sparse = function sparse(this: any, _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":["z","baseZ"],"mappings":";AAWO,MAAM,sBAAsB;AAEnC,MAAM,mDAAmC,QAAA;AAEzC,SAA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1F,SAAS,aACL,oFACA;AAAA,EAAA,CACL;AACH;AAEO,MAAM,aAAa,CAAC,YAA+B,eAAeA,KAAG,OAAO;ACInF,IAAI,wBAAwB;AAErB,SAAS,UAAU,KAAe;AACvC,MAAI,OAAO,aAAa,GAAG,KAAK,OAAQ,IAAY,cAAc,YAAY;AAC1E,QAAY,YAAY,CAAC,YAA+B,eAAe,KAAK,OAAO;AAAA,EACvF;AAEA,MAAI,sBAAuB;AAC3B,0BAAwB;AAExB,QAAM,YAAY,CAAC,IAAI,WAAW,IAAI,WAAW,IAAI,OAAO;AAC5D,aAAW,QAAQ,WAAW;AAC5B,UAAM,QAAa,MAAM;AACzB,QAAI,CAAC,MAAO;AAEZ,UAAM,SAAS,SAAS,OAAkB,QAAQ,MAAM;AACtD,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,OAAkB,QAAQ,MAAM;AACtD,aAAO;AAAA,IACT;AAAA,EACF;AACF;AClCO,MAAM,IAAI,OAAO,OAAOC,GAAK;AACpC,UAAU,CAAC;"}
@@ -1,14 +1,16 @@
1
- import { E, L, b, e, r, w, z, a, d, c } from "./index-SiSvd0kf.js";
1
+ import { a, E, L, c, e, m, r, w, z, b, f, d } from "./index-Bj25CvzZ.js";
2
2
  export {
3
+ a as E164_PHONE_OR_EMPTY_REGEX,
3
4
  E as E164_PHONE_REGEX,
4
5
  L as LANGUAGE_CODE_REGEX,
5
- b as buildLocaleFallbackChain,
6
+ c as buildLocaleFallbackChain,
6
7
  e as extendZod,
8
+ m as makeZE164Phone,
7
9
  r as resolveLocalizedString,
8
10
  w as withLocalizedStringFallback,
9
11
  z,
10
- a as zE164Phone,
11
- d as zI18nString,
12
- c as zLocalizedString
12
+ b as zE164Phone,
13
+ f as zI18nString,
14
+ d as zLocalizedString
13
15
  };
14
16
  //# sourceMappingURL=index.browser.js.map
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-SiSvd0kf.js";
8
- import { E, L, b as b2, e as e2, r as r2, z as z2, a, d as d2, c as c2 } from "./index-SiSvd0kf.js";
7
+ import { w as withLocalizedStringFallback } from "./index-Bj25CvzZ.js";
8
+ import { a, E, L, c as c2, e as e2, m, r as r2, z as z2, b as b2, f as f2, d as d2 } from "./index-Bj25CvzZ.js";
9
9
  import assert from "assert";
10
10
  import { accessibleBy, accessibleRecordsPlugin } from "@casl/mongoose";
11
11
  import "@casl/ability";
@@ -1214,6 +1214,7 @@ const getTenantFilesystemDbFromCtx = async (ctx) => {
1214
1214
  return getTenantFilesystemDb(tenantId);
1215
1215
  };
1216
1216
  export {
1217
+ a as E164_PHONE_OR_EMPTY_REGEX,
1217
1218
  E as E164_PHONE_REGEX,
1218
1219
  L as LANGUAGE_CODE_REGEX,
1219
1220
  PaginationValidationError,
@@ -1253,7 +1254,7 @@ export {
1253
1254
  ZRBUser,
1254
1255
  b as buildAbility,
1255
1256
  d as buildAbilityFromSession,
1256
- b2 as buildLocaleFallbackChain,
1257
+ c2 as buildLocaleFallbackChain,
1257
1258
  f as can,
1258
1259
  createModels,
1259
1260
  extendMongooseSchema,
@@ -1266,6 +1267,7 @@ export {
1266
1267
  c as getTenantRolesFromSessionUser,
1267
1268
  isPaginationValidationError,
1268
1269
  localizedStringField,
1270
+ m as makeZE164Phone,
1269
1271
  model,
1270
1272
  models,
1271
1273
  mongoPaginationPlugin,
@@ -1276,8 +1278,8 @@ export {
1276
1278
  r2 as resolveLocalizedString,
1277
1279
  withLocalizedStringFallback,
1278
1280
  z2 as z,
1279
- a as zE164Phone,
1280
- d2 as zI18nString,
1281
- c2 as zLocalizedString
1281
+ b2 as zE164Phone,
1282
+ f2 as zI18nString,
1283
+ d2 as zLocalizedString
1282
1284
  };
1283
1285
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  export declare const E164_PHONE_REGEX: RegExp;
3
- export declare const zE164Phone: () => z.ZodString;
3
+ export declare const E164_PHONE_OR_EMPTY_REGEX: RegExp;
4
+ export type E164PhoneOptions = {
5
+ allowEmpty?: boolean;
6
+ };
7
+ export declare const makeZE164Phone: (zod: typeof z, options?: E164PhoneOptions) => z.ZodString;
8
+ export declare const zE164Phone: (options?: E164PhoneOptions) => z.ZodString;
4
9
  //# sourceMappingURL=e164Phone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"e164Phone.d.ts","sourceRoot":"","sources":["../../src/zod/e164Phone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,gBAAgB,QAAsB,CAAA;AAEnD,eAAO,MAAM,UAAU,mBAGnB,CAAA"}
1
+ {"version":3,"file":"e164Phone.d.ts","sourceRoot":"","sources":["../../src/zod/e164Phone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,gBAAgB,QAAsB,CAAA;AACnD,eAAO,MAAM,yBAAyB,QAA2B,CAAA;AAEjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,OAAO,CAAC,EAAE,UAAU,gBAAgB,gBAOvE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,UAAU,gBAAgB,gBAA+B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../src/zod/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,OAAO,QAAQ,KAAK,CAAC;IACnB,UAAU,SAAS;QACjB,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC3B,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAC5B;IAED,UAAU,SAAS;QACjB,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC3B,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAC5B;IAED,UAAU,OAAO;QACf,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC3B,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAC5B;CAEF;AAID,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,QAwBtC"}
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../src/zod/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,OAAO,QAAQ,KAAK,CAAC;IACnB,UAAU,SAAS;QACjB,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC3B,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAC5B;IAED,UAAU,SAAS;QACjB,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC3B,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAC5B;IAED,UAAU,OAAO;QACf,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC3B,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAC5B;CAEF;AAID,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,QAqBtC"}
@@ -1,9 +1,9 @@
1
- import { z as baseZ, ZodError, ZodString } from 'zod';
1
+ import { z as baseZ, ZodError, ZodString, ZodType } from 'zod';
2
2
  import { extendZod } from './extension';
3
3
  export * from './e164Phone';
4
4
  export * from './localizedString';
5
5
  export type RpcbaseZod = typeof baseZ & {
6
- e164Phone: () => ZodString;
6
+ e164Phone: (options?: import('./e164Phone').E164PhoneOptions) => ZodString;
7
7
  };
8
8
  export declare const z: RpcbaseZod;
9
9
  export declare namespace z {
@@ -13,5 +13,5 @@ export declare namespace z {
13
13
  type TypeOf<T> = import("zod").TypeOf<T>;
14
14
  type Infer<T> = import("zod").Infer<T>;
15
15
  }
16
- export { extendZod, ZodError };
16
+ export { extendZod, ZodError, ZodType };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,IAAI,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,KAAK,CAAA;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AAEjC,MAAM,MAAM,UAAU,GAAG,OAAO,KAAK,GAAG;IACtC,SAAS,EAAE,MAAM,SAAS,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,CAAC,EAA2B,UAAU,CAAA;AAGnD,yBAAiB,CAAC,CAAC;IACjB,KAAY,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7C,KAAY,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7C,KAAY,MAAM,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAC/C,KAAY,MAAM,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAC/C,KAAY,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAC9C;AAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,IAAI,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAA;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AAEjC,MAAM,MAAM,UAAU,GAAG,OAAO,KAAK,GAAG;IACtC,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,aAAa,EAAE,gBAAgB,KAAK,SAAS,CAAA;CAC3E,CAAA;AAED,eAAO,MAAM,CAAC,EAA2B,UAAU,CAAA;AAGnD,yBAAiB,CAAC,CAAC;IACjB,KAAY,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7C,KAAY,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7C,KAAY,MAAM,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAC/C,KAAY,MAAM,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAC/C,KAAY,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAC9C;AAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/db",
3
- "version": "0.41.0",
3
+ "version": "0.43.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-SiSvd0kf.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 LocalizedString = Record<LanguageCode, string>\n\nexport type I18nStringRecord = LocalizedString\n\nexport type I18nString = LocalizedString\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 any)?.getCanonicalLocales as ((locales: string | string[]) => string[]) | undefined\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 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]\n }\n return undefined\n}\n\nexport function withLocalizedStringFallback<T extends object>(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 any)\n LOCALIZED_STRING_PROXY_CACHE.set(value, proxy)\n return proxy as T\n}\n\nfunction withFallbackRecord(record: LocalizedString) {\n const getExact = (key: string) => record[key]\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) => resolveLocalizedString(record, key)\n if (typeof prop === \"string\" && !(prop in target)) {\n return resolveLocalizedString(record, prop)\n }\n\n return (target as any)[prop]\n },\n set(target, prop, next) {\n ;(target as any)[prop] = next\n return true\n },\n })\n}\n\nexport const zLocalizedString = () => {\n const schema = z.record(\n z\n .string()\n .regex(LANGUAGE_CODE_REGEX, { message: \"Expected a language code (BCP 47, e.g. en or fr-FR).\" }),\n z.string()\n ) as z.ZodRecord<z.ZodString, z.ZodString>\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}$/\n\nexport const zE164Phone = () =>\n z.string().trim().regex(E164_PHONE_REGEX, {\n message: \"Expected a phone number in E.164 format (e.g. +33608707197).\",\n })\n\n","import { z } from \"zod\"\n\nimport { E164_PHONE_REGEX } from \"./e164Phone\"\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 if (Object.isExtensible(zod) && typeof (zod as any).e164Phone !== \"function\") {\n ;(zod as any).e164Phone = () =>\n zod.string().trim().regex(E164_PHONE_REGEX, {\n message: \"Expected a phone number in E.164 format (e.g. +33608707197).\",\n })\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: any = type?.prototype\n if (!proto) continue\n\n proto.unique = function unique(this: any, _flag = true) {\n return this\n }\n\n proto.sparse = function sparse(this: any, _flag = true) {\n return this\n }\n }\n}\n","import { z as baseZ, type ZodError, type ZodString } from \"zod\"\n\nimport { extendZod } from \"./extension\"\n\n\nexport * from \"./e164Phone\"\nexport * from \"./localizedString\"\n\nexport type RpcbaseZod = typeof baseZ & {\n e164Phone: () => 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 }\n"],"names":["z","baseZ"],"mappings":";AAWO,MAAM,sBAAsB;AAEnC,MAAM,mDAAmC,QAAA;AAEzC,SAAS,gBAAgB,QAAwB;AAC/C,QAAM,UAAU,OAAO,KAAA;AACvB,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,sBAAuB,MAAc;AAC3C,MAAI,OAAO,wBAAwB,WAAY,QAAO;AACtD,MAAI;AACF,WAAO,oBAAoB,OAAO,EAAE,CAAC,KAAK;AAAA,EAC5C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,yBAAyB,QAAgB,WAAyC;AAChG,QAAM,OAAO,OAAO,KAAA;AACpB,QAAM,YAAY,gBAAgB,IAAI;AACtC,QAAM,QAAQ,OAAO,cAAc,WAAW,CAAC,SAAS,IAAK,aAAa,CAAA;AAE1E,QAAM,SAAmB,CAAA;AACzB,QAAM,2BAAW,IAAA;AAEjB,QAAM,OAAO,CAAC,UAAkB;AAC9B,QAAI,CAAC,MAAO;AACZ,QA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