@standards/schema 1.0.0-alpha.418 → 1.0.0-alpha.421
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.
- package/dist/all-BKRTNSnx.mjs +4 -0
- package/dist/all-Bd7AdHPs.js +4 -0
- package/dist/api/index.d.mts +15302 -1123
- package/dist/api/index.d.ts +15302 -1123
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/attribute-validators-CH24eLCk.js +11 -0
- package/dist/attribute-validators-RdwWgLqZ.mjs +11 -0
- package/dist/{exceptions-BQiNZXm5.d.mts → exceptions-DtcTc7fk.d.mts} +19 -0
- package/dist/{exceptions-g7YWWqxM.d.ts → exceptions-EheEZJ0K.d.ts} +19 -0
- package/dist/exceptions.d.mts +2 -2
- package/dist/exceptions.d.ts +2 -2
- package/dist/exceptions.js +1 -1
- package/dist/exceptions.mjs +1 -1
- package/dist/index-Ba3rZe7X.d.ts +29994 -0
- package/dist/index-DY7cHmBV.d.mts +29994 -0
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/record-operation-BxDtJz4E.js +2 -0
- package/dist/record-operation-Ds20ta2l.mjs +2 -0
- package/dist/{utils-zJGDp1O7.d.ts → utils-CzDInA43.d.ts} +1 -1
- package/dist/{utils-Cb1wqWLJ.d.mts → utils-qZ-SCngX.d.mts} +1 -1
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/validation/all.d.mts +1 -1
- package/dist/validation/all.d.ts +1 -1
- package/dist/validation/all.js +1 -1
- package/dist/validation/all.mjs +1 -1
- package/openapi.json +71338 -0
- package/package.json +4 -2
- package/dist/all-1pGx58g6.mjs +0 -4
- package/dist/all-B1SMbpC9.js +0 -4
- package/dist/all-C-tG86Pt.d.mts +0 -4305
- package/dist/all-DxVkjo74.d.ts +0 -4306
- package/dist/index-B_nj48YC.d.mts +0 -18322
- package/dist/index-DsmLdvid.d.ts +0 -18322
- package/dist/primitives-B4ZEOP32.js +0 -11
- package/dist/primitives-CXio5R1q.mjs +0 -11
- package/dist/record-operation-Ce5oJe9K.js +0 -2
- package/dist/record-operation-DszVqr_i.mjs +0 -2
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
|
|
2
|
+
import"./zod-locale.mjs";import{ATTRIBUTE_NAME_SCHEMA as e,SCHEMA_LIMITS as t,colorIdSchema as n,iconNameSchema as r,isPlainRecord as i,isValueKindType as a}from"./attribute-validators-RdwWgLqZ.mjs";import{ValidationError as o}from"./exceptions.mjs";import*as s from"zod";import{getCountryByIso3 as c,isValidIso3 as l,stripTrunkPrefix as u}from"@standards/constants";import{parsePhoneNumberFromString as d}from"libphonenumber-js";const f=[`text`,`number`,`boolean`,`date`,`select`,`multiselect`],p={email:`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`,url:`^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$`,slug:`^[a-z0-9]+(?:-[a-z0-9]+)*$`};function resolveTextPattern(e){return e.pattern?e.pattern:e.format?p[e.format]:void 0}const m={required:e=>`${e.label} is required`,invalidType:(e,t)=>`${e.label} must be a ${t}`,minLength:(e,t)=>`${e.label} must be at least ${t} characters`,maxLength:(e,t)=>`${e.label} must be at most ${t} characters`,invalidPattern:e=>`${e.label} format is invalid`,minValue:(e,t)=>`${e.label} must be at least ${t}`,maxValue:(e,t)=>`${e.label} must be at most ${t}`,mustBeInteger:e=>`${e.label} must be an integer`,invalidDate:e=>`${e.label} must be a valid date`,invalidOption:(e,t)=>`${e.label} must be one of: ${t.join(`, `)}`,invalidId:e=>`${e.label} must be a valid ID`,maxItems:(e,t)=>`${e.label} must have at most ${t} item${t>1?`s`:``}`,invalidRichtext:e=>`${e.label} must be valid rich text content`,invalidPhone:e=>`${e.label} must be a valid phone number`,invalidCurrency:e=>`${e.label} must be a valid currency value`,invalidLocation:e=>`${e.label} must be a valid location`};function formatZodErrors(e){return e.issues.map(e=>({path:e.path.map(String),message:e.message}))}var LRUCache=class{constructor(e){if(!Number.isInteger(e)||e<=0)throw Error(`LRU cache capacity must be greater than 0`);this.capacity=e,this.cache=/* @__PURE__ */ new Map}get(e){if(!this.cache.has(e))return;let t=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,t),t}set(e,t){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){let e=this.cache.keys().next();e.done||this.cache.delete(e.value)}this.cache.set(e,t)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}get size(){return this.cache.size}};function createRegexCache(e=100){return new LRUCache(e)}function getCachedRegex(e,t){let n=e.get(t);return n||(n=new RegExp(t),e.set(t,n)),n}const ee=createRegexCache();function createTextValidator(e,t=m){let n=s.string();e.minLength!==void 0&&(n=n.min(e.minLength,t.minLength(e,e.minLength))),e.maxLength!==void 0&&(n=n.max(e.maxLength,t.maxLength(e,e.maxLength)));let r=resolveTextPattern(e);return r&&(n=n.regex(getCachedRegex(ee,r),t.invalidPattern(e))),n}function createNumberValidator(e,t=m){let n=s.number();return e.min!==void 0&&(n=n.min(e.min,t.minValue(e,e.min))),e.max!==void 0&&(n=n.max(e.max,t.maxValue(e,e.max))),e.renderAs===`rating`&&(n=n.min(e.min??0),n=n.max(e.max??5)),e.unit===`percentage`&&(n=n.min(e.min??0).max(e.max??100)),e.unit===`integer`&&(n=n.int(t.mustBeInteger(e))),n}function createCheckboxValidator(e,t=m){return s.boolean()}function resolveBound(e){if(!e)return null;let t=e===`today`?(/* @__PURE__ */ new Date()).toISOString().slice(0,10):e,n=new Date(t);return Number.isNaN(n.getTime())?null:n}function floorToPrecision(e,t){return e?t===`month`?new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),1)):t===`year`?new Date(Date.UTC(e.getUTCFullYear(),0,1)):e:null}function createDateValidator(e,t=m){let n=t.invalidDate(e),r=floorToPrecision(resolveBound(e.minDate),e.precision),i=resolveBound(e.maxDate),a=s.any().superRefine((e,t)=>{let a=new Date(e);Number.isNaN(a.getTime())?t.addIssue({code:`custom`,message:n}):(r&&a<r&&t.addIssue({code:`custom`,message:n}),i&&a>i&&t.addIssue({code:`custom`,message:n}))});if(!e.endDate)return a;let o=s.object({start:a,end:a.nullable()}).superRefine((e,t)=>{if(e.end===null)return;let r=new Date(e.start),i=new Date(e.end);!(Number.isNaN(r.getTime())||Number.isNaN(i.getTime()))&&i<r&&t.addIssue({code:`custom`,message:n,path:[`end`]})});return s.preprocess(e=>typeof e==`string`?{start:e,end:null}:e,o)}function isNullishOrEmptyString(e){return e==null||e===``}function isValuePresent(e){return e==null?!1:typeof e==`string`?e.trim()!==``:!Array.isArray(e)||e.length>0}const h={phone:[`countryCode`]};function isEmptyValue(e,t=[]){return e==null||typeof e==`string`&&e.trim()===``?!0:e instanceof Date?!1:typeof e==`object`&&!Array.isArray(e)&&Object.entries(e).filter(([e])=>!t.includes(e)).every(([,e])=>e==null||typeof e==`string`&&e.trim()===``)}function withEmptyToNull(e,t){return s.preprocess(e=>isEmptyValue(e,t)?null:e,e.nullish())}const g=s.object({placeholder:s.string().optional(),description:s.string().optional(),defaultValue:s.unknown().optional(),icon:s.string().optional(),order:s.number().int().optional(),hidden:s.boolean().optional(),archived:s.boolean().optional(),deprecated:s.boolean().optional(),metadata:s.record(s.string(),s.unknown()).optional()}),_=[`placeholder`,`description`,`defaultValue`,`icon`,`order`,`hidden`,`archived`,`deprecated`,`metadata`],v={icon:r.optional().describe(`Field icon from search_icons`)},y={date:[`precision`],user:[`notifiesOnAssign`,`actors`]};function wireOmittedConfigKeysFor(e){return[..._,...y[e]??[]]}function wireHiddenTypeConfigMask(e){return Object.fromEntries((y[e]??[]).map(e=>[e,!0]))}function refuseForeignKeys(e,t,n=[]){let r=new Set(n);return function refuse(n,i,a,o=[]){let s=e[n];if(s!==void 0&&i!==void 0)for(let e of Object.keys(i))s.has(e)||r.has(e)||a.addIssue({code:`custom`,path:[...o,e],message:`"${e}" is not a ${n} ${t}; keys of ${n}: ${[...s].join(`, `)}`})}}const b=s.object({value:s.string().min(1).describe(`Stored value`),label:s.string().min(1).describe(`Label people see`),description:s.string().describe(`Extra context`).optional(),inverse:s.string().describe(`Paired option's value (symmetric)`).optional(),archived:s.boolean().describe(`Hides without deleting`).optional()}),x=s.enum([`idle`,`in_progress`,`finished`]).describe(`Workflow stage`),S=b.extend({color:n}).strict(),C=b.extend({color:n,group:x}).strict(),w=b.extend({color:s.string().optional().describe(`A color id`),group:x.optional()}).strict(),T=new Set(w.keyof().options),te=[`options`,`targetAttributeOptions`];function withoutUnknownOptionKeys(e){let t=e;for(let n of te){let r=e[n];if(!Array.isArray(r))continue;let a=!1,o=r.map(e=>!i(e)||Object.keys(e).every(e=>T.has(e))?e:(a=!0,Object.fromEntries(Object.entries(e).filter(([e])=>T.has(e)))));a&&(t={...t,[n]:o})}let n=e.properties;if(i(n)&&Array.isArray(n.definitions)){let e=n.definitions,r=e.map(e=>i(e)?withoutUnknownOptionKeys(e):e);r.some((t,n)=>t!==e[n])&&(t={...t,properties:{...n,definitions:r}})}return t}const E=s.array(w).min(1).refine(e=>{let t=e.map(e=>e.value);return new Set(t).size===t.length},{message:`Duplicate option values are not allowed`});function writeOptionsArraySchema(e){return s.array(e).min(1).max(t.optionsPerAttribute).refine(e=>{let t=e.map(e=>e.value);return new Set(t).size===t.length},{message:`Duplicate option values are not allowed`})}const D=writeOptionsArraySchema(S),O=writeOptionsArraySchema(S),k=writeOptionsArraySchema(C),ne=s.object({object:s.string().min(1).describe(`Target object`),displayTemplate:s.string().optional().describe(`Linked record label template`),filter:s.record(s.string(),s.unknown()).optional().describe(`Restricts linkable records`)}),A=s.object({object:s.string().min(1).describe(`Other side's object`),attribute:s.string().min(1).describe(`Other side's attribute`),cardinality:s.enum([`one`,`many`]).optional().describe(`Other side's cardinality`),label:s.string().min(1).optional().describe(`Other side's label`),storageOwner:s.boolean().optional().describe(`Owns the join storage`)}),j=s.object({objectName:s.string().min(1).describe(`API name of the object whose options are mirrored`),attributeName:s.string().min(1).describe(`API name of the select/status attribute to mirror options from`),attributeId:s.string().optional().describe(`Id of the source attribute, resolved by the server`)}),M=g.extend({multiline:s.boolean().describe(`Renders as a multi-line textarea`).optional(),minLength:s.number().int().min(0).describe(`Minimum character count`).optional(),maxLength:s.number().int().min(1).describe(`Maximum character count`).optional(),pattern:s.string().describe(`Regular expression the value must match`).optional(),format:s.enum([`email`,`url`,`slug`]).describe(`Validates and renders as this format`).optional()}),re=g,N=g.extend({renderAs:s.enum([`number`,`rating`]).describe(`Plain number or a star rating`).optional(),min:s.number().describe(`Minimum allowed value`).optional(),max:s.number().describe(`Maximum allowed value`).optional(),unit:s.enum([`integer`,`decimal`,`percentage`]).describe(`How the value is stored and rendered`).optional(),decimals:s.number().int().min(0).max(10).describe(`Decimal places shown`).optional()}),P=g,F=g.extend({dateFormat:s.enum([`short`,`long`,`full`,`relative`]).describe(`How the date is rendered`).optional(),precision:s.enum([`day`,`month`,`year`]).describe(`Whether the value records a day, a month or a year`).optional(),minDate:s.string().describe(`Earliest allowed date (ISO)`).optional(),maxDate:s.string().describe(`Latest allowed date (ISO)`).optional(),includeTime:s.boolean().describe(`Also captures a time of day`).optional(),endDate:s.boolean().describe(`Paired with another date attribute as a range's end`).optional(),timeFormat:s.enum([`12h`,`24h`]).describe(`Clock format when a time is included`).optional()}),I=g.extend({defaultCountryCode:s.string().length(3).describe(`ISO country code preselected in the dialer`).optional()}),L=g.extend({defaultCurrency:s.string().length(3).describe(`ISO currency code preselected for new values`).optional(),allowedCurrencies:s.array(s.string().length(3)).describe(`ISO currency codes a value may use; any currency when omitted`).optional(),allowNegative:s.boolean().describe(`Whether a negative amount is accepted`).optional()}),R=g.extend({options:E.describe(`The workflow statuses, in order`)}),z=g.extend({granularity:s.enum([`full`,`address`,`city`,`state`,`country`,`coordinates`]).describe(`How precise a location must be captured`).optional(),defaultCountry:s.string().length(3).describe(`ISO country code preselected for new values`).optional(),allowedCountries:s.array(s.string().length(3)).describe(`ISO country codes a value may use; any country when omitted`).optional()}),B=g.extend({options:E.describe(`Options`),renderAs:s.literal(`badges`).optional().describe(`Renders the chosen option as a colored badge`)}),V=g.extend({options:E.describe(`Options`),renderAs:s.literal(`badges`).optional().describe(`Renders the chosen options as colored badges`)}),ie=g.extend({types:s.array(s.enum([`user`,`agent`])).min(1).optional().describe(`Which kinds of actor can be picked; both when omitted`),multiple:s.boolean().optional().describe(`Whether more than one actor can be picked`),notifiesOnAssign:s.boolean().optional().describe(`Whether each person added to the value is notified`),actors:s.boolean().optional().describe(`Whether the value holds actor ids, named by each actor's current name`)}),H={name:e.describe(`Property API name`),label:s.string().min(1).describe(`Label people see`),required:s.boolean().describe(`Required on every edge`).optional()},ae={id:s.string().optional(),objectId:s.string().optional(),system:s.boolean().optional(),unique:s.boolean().optional()},oe=Object.fromEntries(_.map(e=>[e,!0])),U=[`text`,`number`,`checkbox`,`date`,`phone`,`currency`,`location`],W=[...U,`select`,`multiselect`,`status`],G={text:M,number:N,checkbox:P,date:F,phone:I,currency:L,location:z,select:B,multiselect:V,status:R},K={...G,select:B.extend({options:D.describe(`Options`)}),multiselect:V.extend({options:O.describe(`Options`)}),status:R.extend({options:k.describe(`Statuses`)})},propertyWireConfigShapeFor=e=>K[e].omit(oe).omit(wireHiddenTypeConfigMask(e)).shape,storedPropertyMember=e=>s.object({...H,...ae,type:s.literal(e).describe(`Property type`),...G[e].shape}).strip(),q=s.discriminatedUnion(`type`,W.map(storedPropertyMember)),J=s.object({definitions:s.array(q).min(1).max(t.optionsPerAttribute).describe(`Edge properties`)}).strip().describe(`Properties carried by the edge itself (role, share, since…), never a third object`),se=refuseForeignKeys(Object.fromEntries(W.map(e=>[e,new Set(Object.keys(propertyWireConfigShapeFor(e)))])),`property key`,[...Object.keys(H),`type`]);function refuseForeignPropertyKeys(e,t){se(e.type,e,t)}const ce=U.reduce((e,t)=>(Object.assign(e,propertyWireConfigShapeFor(t)),e),{}),optionPropertyWireMember=e=>s.object({...H,type:e.length===1?s.literal(e[0]).describe(`Property type`):s.enum(e).describe(`Property type`),...propertyWireConfigShapeFor(e[0])}).strict(),Y=s.discriminatedUnion(`type`,[optionPropertyWireMember([`select`,`multiselect`]),optionPropertyWireMember([`status`]),s.object({...H,type:s.enum(U).describe(`Property type`),...ce}).strict().superRefine(refuseForeignPropertyKeys)]),le=s.object({definitions:s.array(Y).min(1).max(t.optionsPerAttribute).describe(`Edge properties`)}).strict().describe(`Properties carried by the edge itself (role, share, since…), never a third object`),X=g.extend({targets:s.array(ne).min(1).describe(`Target object(s)`),cardinality:s.enum([`one`,`many`]).describe(`one or many`),maxItems:s.number().int().min(1).optional().describe(`Max linked records`),bilateral:A.optional().describe(`Syncs the other side's attribute`),properties:J.optional()}),ue=g.extend({expression:s.string().min(1).describe(`The formula expression, compiled against this object's attributes`),returnType:s.enum(f).describe(`The formula's result type`),decimals:s.number().int().min(0).max(10).optional().describe(`Decimal places shown for a number result`),currencyCode:s.string().length(3).optional().describe(`ISO 4217 code a number result renders with; presentation only`),allowRelations:s.boolean().optional().describe(`Whether the expression may read across a relation`),optionsSource:j.optional().describe(`Mirrors an option set`)}),de=g.extend({relationAttribute:s.string().min(1).optional().describe(`API name of the relation this rollup aggregates through`),relationPath:s.string().optional().describe(`Not supported yet — single-hop only`),targetAttribute:s.string().min(1).optional().describe(`API name of the attribute aggregated on the relation's target object; not read by count`),function:s.enum([`sum`,`avg`,`earliest`,`latest`,`count`,`countValues`,`countUniqueValues`,`countEmpty`,`percentEmpty`,`percentNotEmpty`,`original`]).describe(`The aggregation applied across the linked records`),decimals:s.number().int().min(0).max(10).optional().describe(`Decimal places shown for a numeric result`),targetAttributeType:s.string().optional().describe(`Server-set`),targetAttributeOptions:s.array(w).optional().describe(`Server-set`),targetCurrencyCode:s.string().length(3).optional().describe(`Server-set`),optionsSource:j.optional().describe(`Mirrors an option set`)});function rollupTargetIssue(e,t){if(e===`rollup`&&t.function!==`count`&&t.targetAttribute===void 0)return{path:[`targetAttribute`],message:`targetAttribute is required for a "${String(t.function)}" rollup`}}function datePrecisionIssues(e,t,n=[]){let r=[],a=t.precision;if(e===`date`&&a!==void 0&&a!==`day`)for(let e of[`includeTime`,`endDate`])t[e]===!0&&r.push({path:[...n,`precision`],message:`A "${String(a)}" precision cannot be combined with ${e}`});let o=t.properties;return i(o)&&Array.isArray(o.definitions)&&o.definitions.forEach((e,t)=>{i(e)&&r.push(...datePrecisionIssues(String(e.type),e,[...n,`properties`,`definitions`,t]))}),r}const Z={text:M,richtext:re,number:N,checkbox:P,date:F,phone:I,currency:L,status:R,location:z,select:B,multiselect:V,user:ie,relation:X,formula:ue,rollup:de,document:g.extend({properties:J.optional(),accepts:s.array(s.string().min(1)).optional().describe("MIME prefixes or globs a file must match (e.g. `image/*`, `*.pdf`)"),maxFileSize:s.number().int().min(1).optional().describe(`Maximum file size in bytes`)})};function getAttributeConfigSchema(e){let t=Z[e];if(!t)throw new o(`Unsupported attribute type: ${e}`,[]);return t}function parseAttributeConfig(e,t){let n=getAttributeConfigSchema(e).strip().parse(t),r=rollupTargetIssue(e,n);if(r)throw validationErrorFromIssues([r]);return n}function getAttributeConfigWriteSchema(e){let t=getAttributeConfigSchema(e).extend({icon:r.optional()});switch(e){case`select`:return t.extend({options:D.describe(`Options`)});case`multiselect`:return t.extend({options:O.describe(`Options`)});case`status`:return t.extend({options:k.describe(`Statuses`)});default:return t}}function validationErrorFromIssues(e){return o.fromZodErrors(e.map(e=>({path:e.path.map(e=>typeof e==`symbol`?String(e):e),message:e.message})))}function parseWriteSchema(e,t){let n=getAttributeConfigWriteSchema(e).strip().safeParse(t);if(!n.success)throw validationErrorFromIssues(n.error.issues);let r=rollupTargetIssue(e,n.data);if(r)throw validationErrorFromIssues([r]);let i=datePrecisionIssues(e,n.data);if(i.length>0)throw validationErrorFromIssues(i);return n.data}function parseAttributeConfigForCreate(e,t){return parseWriteSchema(e,t)}function validatePatchedIcon(e){if(!Object.prototype.hasOwnProperty.call(e,`icon`))return;let t=r.optional().safeParse(e.icon);if(!t.success)throw o.fromZodErrors(t.error.issues.map(e=>({path:[`icon`,...e.path.map(e=>typeof e==`symbol`?String(e):e)],message:e.message})))}function parseAttributeConfigForUpdate(e,t){let n=Object.prototype.hasOwnProperty.call(t,`options`),r=Object.prototype.hasOwnProperty.call(t,`icon`),i={...e,...t};if(validatePatchedIcon(t),n){let{icon:t,...n}=i,a=parseWriteSchema(e.type,r?i:n);return!r&&t!==void 0&&(a.icon=t),a}let o=e.options;a(e.type,`options`)&&(i.options=[{value:`__legacy__`,label:`__legacy__`}]);let s=getAttributeConfigSchema(e.type).strip().safeParse(i);if(!s.success)throw validationErrorFromIssues(s.error.issues);let c=s.data,l=datePrecisionIssues(e.type,c);if(l.length>0)throw validationErrorFromIssues(l);return a(e.type,`options`)&&(c.options=o),c}function createCurrencyValidator(e,t=m){let n=e.allowNegative?s.number():s.number().min(0);return s.object({code:s.string().length(3),value:n},{message:t.invalidCurrency(e)})}function createLocationValidator(e,t=m){return s.object({address:s.string().optional(),address2:s.string().optional(),city:s.string().optional(),state:s.string().optional(),postalCode:s.string().optional(),country:s.string().length(3).optional(),latitude:s.number().min(-90).max(90).optional(),longitude:s.number().min(-180).max(180).optional()},{message:t.invalidLocation(e)})}function digitsOnly(e){return e.replace(/\D/g,``)}function normalizeCountrylessPhoneNumber(e){return digitsOnly(e)}function getIso2(e){return c(e)?.iso2}function normalizePhoneNumber(e,t){if(!e)return``;let n=getIso2(t);if(!n)return digitsOnly(e);let r=d(e,n);if(r)return absorbDoubledCallingCode(r.nationalNumber,r.isValid(),t,n);let i=c(t),a=digitsOnly(e);if(i){let e=i.phoneCode.replace(`+`,``),t=a.startsWith(e)?a.slice(e.length):a;return u(t,i.phoneTrunkPrefix??``)}return a}function absorbDoubledCallingCode(e,t,n,r){if(t)return e;let i=c(n)?.phoneCode.replace(`+`,``);if(i===void 0||!e.startsWith(i))return e;let a=e.slice(i.length),o=d(`+${i}${a}`,r);return o?.isValid()?o.nationalNumber:e}function formatPhoneForDisplay(e){if(!e.phoneNumber)return``;let t=getIso2(e.countryCode),n=c(e.countryCode)?.phoneCode??``;if(!t)return`${n} ${e.phoneNumber}`.trim();let r=`${n}${digitsOnly(e.phoneNumber)}`,i=d(r);return i?i.formatInternational():`${n} ${e.phoneNumber}`.trim()}function createPhoneValidator(e,t=m){return s.object({countryCode:s.string().length(3),phoneNumber:s.string().min(1,{message:t.required(e)})},{message:t.invalidPhone(e)}).refine(e=>l(e.countryCode),{message:`Invalid country code`}).transform(e=>({countryCode:e.countryCode,phoneNumber:normalizePhoneNumber(e.phoneNumber,e.countryCode)}))}function extractRelationId(e){return typeof e==`object`&&e&&`id`in e?e.id:e}function createSingleRelationValidator(e,t=m){let n=s.guid({message:t.invalidId(e)}),r=s.union([n,s.null()]);return s.union([r,s.object({id:n,props:s.record(s.string(),s.unknown()).optional()}).passthrough()])}function createMultiRelationValidator(e,t=m){let n=s.guid({message:t.invalidId(e)}),r=s.union([n,s.object({id:n,props:s.record(s.string(),s.unknown()).optional()}).passthrough()]),i=s.array(r);return e.maxItems!==void 0&&(i=i.max(e.maxItems,t.maxItems(e,e.maxItems))),i.refine(e=>e.every(e=>{let t=extractRelationId(e);return typeof t==`string`&&n.safeParse(t).success}),{message:t.invalidId(e)})}function createRelationValidator(e,t=m){return e.cardinality===`many`?createMultiRelationValidator(e,t):createSingleRelationValidator(e,t)}function createRichtextValidator(e,t=m){return s.string({message:t.invalidRichtext(e)})}function describeOptions(e){return e.map(e=>e.label===e.value?e.value:`${e.value} (${e.label})`)}function createSelectValidator(e,t=m){let n=e.options.map(e=>e.value);return n.length===0?s.never():s.enum(n,{message:t.invalidOption(e,describeOptions(e.options))})}function createMultiselectValidator(e,t=m){let n=e.options.map(e=>e.value);return n.length===0?s.never():s.array(s.enum(n,{message:t.invalidOption(e,describeOptions(e.options))}))}function createStatusValidator(e,t=m){let n=e.options.map(e=>e.value);return n.length===0?s.never():s.enum(n,{message:t.invalidOption(e,describeOptions(e.options))})}function createUserValidator(e,t=m){let n=s.guid({message:t.invalidId(e)});return e.multiple?s.array(n):n}function createFormulaValidator(e,t=m){return s.unknown()}function createRollupValidator(e,t=m){return s.unknown()}function createAttributeValidator(e,t=m){switch(e.type){case`text`:return createTextValidator(e,t);case`richtext`:return createRichtextValidator(e,t);case`number`:return createNumberValidator(e,t);case`checkbox`:return createCheckboxValidator(e,t);case`date`:return createDateValidator(e,t);case`phone`:return createPhoneValidator(e,t);case`currency`:return createCurrencyValidator(e,t);case`status`:return createStatusValidator(e,t);case`location`:return createLocationValidator(e,t);case`select`:return createSelectValidator(e,t);case`multiselect`:return createMultiselectValidator(e,t);case`user`:return createUserValidator(e,t);case`relation`:return createRelationValidator(e,t);case`formula`:return createFormulaValidator(e,t);case`rollup`:return createRollupValidator(e,t);default:return s.unknown()}}function createFormAttributeValidator(e,t=m){let n=createAttributeValidator(e,t);return e.required?n:withEmptyToNull(n,h[e.type])}const Q=/* @__PURE__ */ new WeakMap,$=/* @__PURE__ */ new WeakMap;function createObjectValidator(e){let t=Q.get(e);if(t)return t;let n={};for(let t of e.attributes){let e=createAttributeValidator(t);t.required?n[t.name]=e.refine(isValuePresent,{message:m.required(t)}):n[t.name]=withEmptyToNull(e,h[t.type])}let r=s.object(n).passthrough();return Q.set(e,r),r}function createDraftValidator(e){let t=$.get(e);if(t)return t;let n={};for(let t of e.attributes){let e=createAttributeValidator(t);n[t.name]=withEmptyToNull(e,h[t.type])}let r=s.object(n).passthrough();return $.set(e,r),r}function validateAttribute(e,t){let n=createAttributeValidator(e);if(!e.required&&t==null)return{success:!0,data:{[e.name]:t}};let r=n.safeParse(t);return r.success?{success:!0,data:{[e.name]:r.data}}:{success:!1,errors:formatZodErrors(r.error).map(t=>({path:[e.name,...t.path],message:t.message}))}}function validateObject(e,t){let n=createObjectValidator(e).safeParse(t);return n.success?{success:!0,data:n.data}:{success:!1,errors:formatZodErrors(n.error)}}function validateObjectOrThrow(e,t){let n=validateObject(e,t);if(!n.success){let t=n.errors??[],r=t.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`
|
|
3
|
+
`)||`Unknown validation error`;throw new o(`Validation failed for ${e.label}:\n${r}`,t.map(e=>({path:e.path,message:e.message})))}return n.data}function validateDraft(e,t){let n=createDraftValidator(e).safeParse(t);return n.success?{success:!0,data:n.data}:{success:!1,errors:formatZodErrors(n.error)}}function validateDraftOrThrow(e,t){let n=validateDraft(e,t);if(!n.success){let t=n.errors??[],r=t.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`
|
|
4
|
+
`)||`Unknown validation error`;throw new o(`Draft validation failed for ${e.label}:\n${r}`,t.map(e=>({path:e.path,message:e.message})))}return n.data}function rejectUnknownAttributesOrThrow(e,t){let n=new Set(e.attributes.map(e=>e.name)),r=Object.keys(t).filter(e=>!n.has(e));if(r.length>0)throw new o(`Unknown attribute${r.length>1?`s`:``} for ${e.label}: ${r.join(`, `)}`,r.map(e=>({path:[e],message:`Unknown attribute`})))}export{f as COMPUTED_RETURN_TYPES,m as DEFAULT_VALIDATION_MESSAGES,U as SIMPLE_PROPERTY_TYPES,p as TEXT_FORMAT_PATTERNS,v as WIRE_OFFERED_BASE_CONFIG,_ as WIRE_OMITTED_CONFIG_KEYS,Z as attributeConfigSchemas,createAttributeValidator,createFormAttributeValidator,createObjectValidator,datePrecisionIssues,formatPhoneForDisplay,formatZodErrors,getAttributeConfigSchema,getAttributeConfigWriteSchema,getIso2,isEmptyValue,isNullishOrEmptyString,isValuePresent,normalizeCountrylessPhoneNumber,normalizePhoneNumber,parseAttributeConfig,parseAttributeConfigForCreate,parseAttributeConfigForUpdate,q as propertyAttributeSchema,Y as propertyAttributeWireSchema,J as propertySchemaSchema,le as propertySchemaWireSchema,refuseForeignKeys,rejectUnknownAttributesOrThrow,resolveTextPattern,S as selectOptionWriteSchema,x as statusGroupSchema,C as statusOptionWriteSchema,validateAttribute,validateDraft,validateDraftOrThrow,validateObject,validateObjectOrThrow,wireHiddenTypeConfigMask,wireOmittedConfigKeysFor,withoutUnknownOptionKeys};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
|
|
2
|
+
require("./zod-locale.js");const e=require("./attribute-validators-CH24eLCk.js"),t=require("./exceptions.js");let n=require("zod");n=e.__toESM(n);let r=require("@standards/constants"),i=require("libphonenumber-js");const a=[`text`,`number`,`boolean`,`date`,`select`,`multiselect`],o={email:`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`,url:`^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$`,slug:`^[a-z0-9]+(?:-[a-z0-9]+)*$`};function resolveTextPattern(e){return e.pattern?e.pattern:e.format?o[e.format]:void 0}const s={required:e=>`${e.label} is required`,invalidType:(e,t)=>`${e.label} must be a ${t}`,minLength:(e,t)=>`${e.label} must be at least ${t} characters`,maxLength:(e,t)=>`${e.label} must be at most ${t} characters`,invalidPattern:e=>`${e.label} format is invalid`,minValue:(e,t)=>`${e.label} must be at least ${t}`,maxValue:(e,t)=>`${e.label} must be at most ${t}`,mustBeInteger:e=>`${e.label} must be an integer`,invalidDate:e=>`${e.label} must be a valid date`,invalidOption:(e,t)=>`${e.label} must be one of: ${t.join(`, `)}`,invalidId:e=>`${e.label} must be a valid ID`,maxItems:(e,t)=>`${e.label} must have at most ${t} item${t>1?`s`:``}`,invalidRichtext:e=>`${e.label} must be valid rich text content`,invalidPhone:e=>`${e.label} must be a valid phone number`,invalidCurrency:e=>`${e.label} must be a valid currency value`,invalidLocation:e=>`${e.label} must be a valid location`};function formatZodErrors(e){return e.issues.map(e=>({path:e.path.map(String),message:e.message}))}var LRUCache=class{constructor(e){if(!Number.isInteger(e)||e<=0)throw Error(`LRU cache capacity must be greater than 0`);this.capacity=e,this.cache=/* @__PURE__ */ new Map}get(e){if(!this.cache.has(e))return;let t=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,t),t}set(e,t){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){let e=this.cache.keys().next();e.done||this.cache.delete(e.value)}this.cache.set(e,t)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}get size(){return this.cache.size}};function createRegexCache(e=100){return new LRUCache(e)}function getCachedRegex(e,t){let n=e.get(t);return n||(n=new RegExp(t),e.set(t,n)),n}const c=createRegexCache();function createTextValidator(e,t=s){let r=n.string();e.minLength!==void 0&&(r=r.min(e.minLength,t.minLength(e,e.minLength))),e.maxLength!==void 0&&(r=r.max(e.maxLength,t.maxLength(e,e.maxLength)));let i=resolveTextPattern(e);return i&&(r=r.regex(getCachedRegex(c,i),t.invalidPattern(e))),r}function createNumberValidator(e,t=s){let r=n.number();return e.min!==void 0&&(r=r.min(e.min,t.minValue(e,e.min))),e.max!==void 0&&(r=r.max(e.max,t.maxValue(e,e.max))),e.renderAs===`rating`&&(r=r.min(e.min??0),r=r.max(e.max??5)),e.unit===`percentage`&&(r=r.min(e.min??0).max(e.max??100)),e.unit===`integer`&&(r=r.int(t.mustBeInteger(e))),r}function createCheckboxValidator(e,t=s){return n.boolean()}function resolveBound(e){if(!e)return null;let t=e===`today`?(/* @__PURE__ */ new Date()).toISOString().slice(0,10):e,n=new Date(t);return Number.isNaN(n.getTime())?null:n}function floorToPrecision(e,t){return e?t===`month`?new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),1)):t===`year`?new Date(Date.UTC(e.getUTCFullYear(),0,1)):e:null}function createDateValidator(e,t=s){let r=t.invalidDate(e),i=floorToPrecision(resolveBound(e.minDate),e.precision),a=resolveBound(e.maxDate),o=n.any().superRefine((e,t)=>{let n=new Date(e);Number.isNaN(n.getTime())?t.addIssue({code:`custom`,message:r}):(i&&n<i&&t.addIssue({code:`custom`,message:r}),a&&n>a&&t.addIssue({code:`custom`,message:r}))});if(!e.endDate)return o;let c=n.object({start:o,end:o.nullable()}).superRefine((e,t)=>{if(e.end===null)return;let n=new Date(e.start),i=new Date(e.end);!(Number.isNaN(n.getTime())||Number.isNaN(i.getTime()))&&i<n&&t.addIssue({code:`custom`,message:r,path:[`end`]})});return n.preprocess(e=>typeof e==`string`?{start:e,end:null}:e,c)}function isNullishOrEmptyString(e){return e==null||e===``}function isValuePresent(e){return e==null?!1:typeof e==`string`?e.trim()!==``:!Array.isArray(e)||e.length>0}const l={phone:[`countryCode`]};function isEmptyValue(e,t=[]){return e==null||typeof e==`string`&&e.trim()===``?!0:e instanceof Date?!1:typeof e==`object`&&!Array.isArray(e)&&Object.entries(e).filter(([e])=>!t.includes(e)).every(([,e])=>e==null||typeof e==`string`&&e.trim()===``)}function withEmptyToNull(e,t){return n.preprocess(e=>isEmptyValue(e,t)?null:e,e.nullish())}const u=n.object({placeholder:n.string().optional(),description:n.string().optional(),defaultValue:n.unknown().optional(),icon:n.string().optional(),order:n.number().int().optional(),hidden:n.boolean().optional(),archived:n.boolean().optional(),deprecated:n.boolean().optional(),metadata:n.record(n.string(),n.unknown()).optional()}),d=[`placeholder`,`description`,`defaultValue`,`icon`,`order`,`hidden`,`archived`,`deprecated`,`metadata`],f={icon:e.iconNameSchema.optional().describe(`Field icon from search_icons`)},p={date:[`precision`],user:[`notifiesOnAssign`,`actors`]};function wireOmittedConfigKeysFor(e){return[...d,...p[e]??[]]}function wireHiddenTypeConfigMask(e){return Object.fromEntries((p[e]??[]).map(e=>[e,!0]))}function refuseForeignKeys(e,t,n=[]){let r=new Set(n);return function refuse(n,i,a,o=[]){let s=e[n];if(s!==void 0&&i!==void 0)for(let e of Object.keys(i))s.has(e)||r.has(e)||a.addIssue({code:`custom`,path:[...o,e],message:`"${e}" is not a ${n} ${t}; keys of ${n}: ${[...s].join(`, `)}`})}}const m=n.object({value:n.string().min(1).describe(`Stored value`),label:n.string().min(1).describe(`Label people see`),description:n.string().describe(`Extra context`).optional(),inverse:n.string().describe(`Paired option's value (symmetric)`).optional(),archived:n.boolean().describe(`Hides without deleting`).optional()}),h=n.enum([`idle`,`in_progress`,`finished`]).describe(`Workflow stage`),g=m.extend({color:e.colorIdSchema}).strict(),_=m.extend({color:e.colorIdSchema,group:h}).strict(),v=m.extend({color:n.string().optional().describe(`A color id`),group:h.optional()}).strict(),y=new Set(v.keyof().options),ee=[`options`,`targetAttributeOptions`];function withoutUnknownOptionKeys(t){let n=t;for(let r of ee){let i=t[r];if(!Array.isArray(i))continue;let a=!1,o=i.map(t=>!e.isPlainRecord(t)||Object.keys(t).every(e=>y.has(e))?t:(a=!0,Object.fromEntries(Object.entries(t).filter(([e])=>y.has(e)))));a&&(n={...n,[r]:o})}let r=t.properties;if(e.isPlainRecord(r)&&Array.isArray(r.definitions)){let t=r.definitions,i=t.map(t=>e.isPlainRecord(t)?withoutUnknownOptionKeys(t):t);i.some((e,n)=>e!==t[n])&&(n={...n,properties:{...r,definitions:i}})}return n}const b=n.array(v).min(1).refine(e=>{let t=e.map(e=>e.value);return new Set(t).size===t.length},{message:`Duplicate option values are not allowed`});function writeOptionsArraySchema(t){return n.array(t).min(1).max(e.SCHEMA_LIMITS.optionsPerAttribute).refine(e=>{let t=e.map(e=>e.value);return new Set(t).size===t.length},{message:`Duplicate option values are not allowed`})}const x=writeOptionsArraySchema(g),S=writeOptionsArraySchema(g),C=writeOptionsArraySchema(_),w=n.object({object:n.string().min(1).describe(`Target object`),displayTemplate:n.string().optional().describe(`Linked record label template`),filter:n.record(n.string(),n.unknown()).optional().describe(`Restricts linkable records`)}),te=n.object({object:n.string().min(1).describe(`Other side's object`),attribute:n.string().min(1).describe(`Other side's attribute`),cardinality:n.enum([`one`,`many`]).optional().describe(`Other side's cardinality`),label:n.string().min(1).optional().describe(`Other side's label`),storageOwner:n.boolean().optional().describe(`Owns the join storage`)}),T=n.object({objectName:n.string().min(1).describe(`API name of the object whose options are mirrored`),attributeName:n.string().min(1).describe(`API name of the select/status attribute to mirror options from`),attributeId:n.string().optional().describe(`Id of the source attribute, resolved by the server`)}),E=u.extend({multiline:n.boolean().describe(`Renders as a multi-line textarea`).optional(),minLength:n.number().int().min(0).describe(`Minimum character count`).optional(),maxLength:n.number().int().min(1).describe(`Maximum character count`).optional(),pattern:n.string().describe(`Regular expression the value must match`).optional(),format:n.enum([`email`,`url`,`slug`]).describe(`Validates and renders as this format`).optional()}),ne=u,D=u.extend({renderAs:n.enum([`number`,`rating`]).describe(`Plain number or a star rating`).optional(),min:n.number().describe(`Minimum allowed value`).optional(),max:n.number().describe(`Maximum allowed value`).optional(),unit:n.enum([`integer`,`decimal`,`percentage`]).describe(`How the value is stored and rendered`).optional(),decimals:n.number().int().min(0).max(10).describe(`Decimal places shown`).optional()}),O=u,k=u.extend({dateFormat:n.enum([`short`,`long`,`full`,`relative`]).describe(`How the date is rendered`).optional(),precision:n.enum([`day`,`month`,`year`]).describe(`Whether the value records a day, a month or a year`).optional(),minDate:n.string().describe(`Earliest allowed date (ISO)`).optional(),maxDate:n.string().describe(`Latest allowed date (ISO)`).optional(),includeTime:n.boolean().describe(`Also captures a time of day`).optional(),endDate:n.boolean().describe(`Paired with another date attribute as a range's end`).optional(),timeFormat:n.enum([`12h`,`24h`]).describe(`Clock format when a time is included`).optional()}),A=u.extend({defaultCountryCode:n.string().length(3).describe(`ISO country code preselected in the dialer`).optional()}),j=u.extend({defaultCurrency:n.string().length(3).describe(`ISO currency code preselected for new values`).optional(),allowedCurrencies:n.array(n.string().length(3)).describe(`ISO currency codes a value may use; any currency when omitted`).optional(),allowNegative:n.boolean().describe(`Whether a negative amount is accepted`).optional()}),M=u.extend({options:b.describe(`The workflow statuses, in order`)}),N=u.extend({granularity:n.enum([`full`,`address`,`city`,`state`,`country`,`coordinates`]).describe(`How precise a location must be captured`).optional(),defaultCountry:n.string().length(3).describe(`ISO country code preselected for new values`).optional(),allowedCountries:n.array(n.string().length(3)).describe(`ISO country codes a value may use; any country when omitted`).optional()}),P=u.extend({options:b.describe(`Options`),renderAs:n.literal(`badges`).optional().describe(`Renders the chosen option as a colored badge`)}),F=u.extend({options:b.describe(`Options`),renderAs:n.literal(`badges`).optional().describe(`Renders the chosen options as colored badges`)}),I=u.extend({types:n.array(n.enum([`user`,`agent`])).min(1).optional().describe(`Which kinds of actor can be picked; both when omitted`),multiple:n.boolean().optional().describe(`Whether more than one actor can be picked`),notifiesOnAssign:n.boolean().optional().describe(`Whether each person added to the value is notified`),actors:n.boolean().optional().describe(`Whether the value holds actor ids, named by each actor's current name`)}),L={name:e.ATTRIBUTE_NAME_SCHEMA.describe(`Property API name`),label:n.string().min(1).describe(`Label people see`),required:n.boolean().describe(`Required on every edge`).optional()},R={id:n.string().optional(),objectId:n.string().optional(),system:n.boolean().optional(),unique:n.boolean().optional()},z=Object.fromEntries(d.map(e=>[e,!0])),B=[`text`,`number`,`checkbox`,`date`,`phone`,`currency`,`location`],V=[...B,`select`,`multiselect`,`status`],H={text:E,number:D,checkbox:O,date:k,phone:A,currency:j,location:N,select:P,multiselect:F,status:M},U={...H,select:P.extend({options:x.describe(`Options`)}),multiselect:F.extend({options:S.describe(`Options`)}),status:M.extend({options:C.describe(`Statuses`)})},propertyWireConfigShapeFor=e=>U[e].omit(z).omit(wireHiddenTypeConfigMask(e)).shape,storedPropertyMember=e=>n.object({...L,...R,type:n.literal(e).describe(`Property type`),...H[e].shape}).strip(),W=n.discriminatedUnion(`type`,V.map(storedPropertyMember)),G=n.object({definitions:n.array(W).min(1).max(e.SCHEMA_LIMITS.optionsPerAttribute).describe(`Edge properties`)}).strip().describe(`Properties carried by the edge itself (role, share, since…), never a third object`),K=refuseForeignKeys(Object.fromEntries(V.map(e=>[e,new Set(Object.keys(propertyWireConfigShapeFor(e)))])),`property key`,[...Object.keys(L),`type`]);function refuseForeignPropertyKeys(e,t){K(e.type,e,t)}const q=B.reduce((e,t)=>(Object.assign(e,propertyWireConfigShapeFor(t)),e),{}),optionPropertyWireMember=e=>n.object({...L,type:e.length===1?n.literal(e[0]).describe(`Property type`):n.enum(e).describe(`Property type`),...propertyWireConfigShapeFor(e[0])}).strict(),J=n.discriminatedUnion(`type`,[optionPropertyWireMember([`select`,`multiselect`]),optionPropertyWireMember([`status`]),n.object({...L,type:n.enum(B).describe(`Property type`),...q}).strict().superRefine(refuseForeignPropertyKeys)]),Y=n.object({definitions:n.array(J).min(1).max(e.SCHEMA_LIMITS.optionsPerAttribute).describe(`Edge properties`)}).strict().describe(`Properties carried by the edge itself (role, share, since…), never a third object`),X=u.extend({targets:n.array(w).min(1).describe(`Target object(s)`),cardinality:n.enum([`one`,`many`]).describe(`one or many`),maxItems:n.number().int().min(1).optional().describe(`Max linked records`),bilateral:te.optional().describe(`Syncs the other side's attribute`),properties:G.optional()}),re=u.extend({expression:n.string().min(1).describe(`The formula expression, compiled against this object's attributes`),returnType:n.enum(a).describe(`The formula's result type`),decimals:n.number().int().min(0).max(10).optional().describe(`Decimal places shown for a number result`),currencyCode:n.string().length(3).optional().describe(`ISO 4217 code a number result renders with; presentation only`),allowRelations:n.boolean().optional().describe(`Whether the expression may read across a relation`),optionsSource:T.optional().describe(`Mirrors an option set`)}),ie=u.extend({relationAttribute:n.string().min(1).optional().describe(`API name of the relation this rollup aggregates through`),relationPath:n.string().optional().describe(`Not supported yet — single-hop only`),targetAttribute:n.string().min(1).optional().describe(`API name of the attribute aggregated on the relation's target object; not read by count`),function:n.enum([`sum`,`avg`,`earliest`,`latest`,`count`,`countValues`,`countUniqueValues`,`countEmpty`,`percentEmpty`,`percentNotEmpty`,`original`]).describe(`The aggregation applied across the linked records`),decimals:n.number().int().min(0).max(10).optional().describe(`Decimal places shown for a numeric result`),targetAttributeType:n.string().optional().describe(`Server-set`),targetAttributeOptions:n.array(v).optional().describe(`Server-set`),targetCurrencyCode:n.string().length(3).optional().describe(`Server-set`),optionsSource:T.optional().describe(`Mirrors an option set`)});function rollupTargetIssue(e,t){if(e===`rollup`&&t.function!==`count`&&t.targetAttribute===void 0)return{path:[`targetAttribute`],message:`targetAttribute is required for a "${String(t.function)}" rollup`}}function datePrecisionIssues(t,n,r=[]){let i=[],a=n.precision;if(t===`date`&&a!==void 0&&a!==`day`)for(let e of[`includeTime`,`endDate`])n[e]===!0&&i.push({path:[...r,`precision`],message:`A "${String(a)}" precision cannot be combined with ${e}`});let o=n.properties;return e.isPlainRecord(o)&&Array.isArray(o.definitions)&&o.definitions.forEach((t,n)=>{e.isPlainRecord(t)&&i.push(...datePrecisionIssues(String(t.type),t,[...r,`properties`,`definitions`,n]))}),i}const Z={text:E,richtext:ne,number:D,checkbox:O,date:k,phone:A,currency:j,status:M,location:N,select:P,multiselect:F,user:I,relation:X,formula:re,rollup:ie,document:u.extend({properties:G.optional(),accepts:n.array(n.string().min(1)).optional().describe("MIME prefixes or globs a file must match (e.g. `image/*`, `*.pdf`)"),maxFileSize:n.number().int().min(1).optional().describe(`Maximum file size in bytes`)})};function getAttributeConfigSchema(e){let n=Z[e];if(!n)throw new t.ValidationError(`Unsupported attribute type: ${e}`,[]);return n}function parseAttributeConfig(e,t){let n=getAttributeConfigSchema(e).strip().parse(t),r=rollupTargetIssue(e,n);if(r)throw validationErrorFromIssues([r]);return n}function getAttributeConfigWriteSchema(t){let n=getAttributeConfigSchema(t).extend({icon:e.iconNameSchema.optional()});switch(t){case`select`:return n.extend({options:x.describe(`Options`)});case`multiselect`:return n.extend({options:S.describe(`Options`)});case`status`:return n.extend({options:C.describe(`Statuses`)});default:return n}}function validationErrorFromIssues(e){return t.ValidationError.fromZodErrors(e.map(e=>({path:e.path.map(e=>typeof e==`symbol`?String(e):e),message:e.message})))}function parseWriteSchema(e,t){let n=getAttributeConfigWriteSchema(e).strip().safeParse(t);if(!n.success)throw validationErrorFromIssues(n.error.issues);let r=rollupTargetIssue(e,n.data);if(r)throw validationErrorFromIssues([r]);let i=datePrecisionIssues(e,n.data);if(i.length>0)throw validationErrorFromIssues(i);return n.data}function parseAttributeConfigForCreate(e,t){return parseWriteSchema(e,t)}function validatePatchedIcon(n){if(!Object.prototype.hasOwnProperty.call(n,`icon`))return;let r=e.iconNameSchema.optional().safeParse(n.icon);if(!r.success)throw t.ValidationError.fromZodErrors(r.error.issues.map(e=>({path:[`icon`,...e.path.map(e=>typeof e==`symbol`?String(e):e)],message:e.message})))}function parseAttributeConfigForUpdate(t,n){let r=Object.prototype.hasOwnProperty.call(n,`options`),i=Object.prototype.hasOwnProperty.call(n,`icon`),a={...t,...n};if(validatePatchedIcon(n),r){let{icon:e,...n}=a,r=parseWriteSchema(t.type,i?a:n);return!i&&e!==void 0&&(r.icon=e),r}let o=t.options;e.isValueKindType(t.type,`options`)&&(a.options=[{value:`__legacy__`,label:`__legacy__`}]);let s=getAttributeConfigSchema(t.type).strip().safeParse(a);if(!s.success)throw validationErrorFromIssues(s.error.issues);let c=s.data,l=datePrecisionIssues(t.type,c);if(l.length>0)throw validationErrorFromIssues(l);return e.isValueKindType(t.type,`options`)&&(c.options=o),c}function createCurrencyValidator(e,t=s){let r=e.allowNegative?n.number():n.number().min(0);return n.object({code:n.string().length(3),value:r},{message:t.invalidCurrency(e)})}function createLocationValidator(e,t=s){return n.object({address:n.string().optional(),address2:n.string().optional(),city:n.string().optional(),state:n.string().optional(),postalCode:n.string().optional(),country:n.string().length(3).optional(),latitude:n.number().min(-90).max(90).optional(),longitude:n.number().min(-180).max(180).optional()},{message:t.invalidLocation(e)})}function digitsOnly(e){return e.replace(/\D/g,``)}function normalizeCountrylessPhoneNumber(e){return digitsOnly(e)}function getIso2(e){return(0,r.getCountryByIso3)(e)?.iso2}function normalizePhoneNumber(e,t){if(!e)return``;let n=getIso2(t);if(!n)return digitsOnly(e);let a=(0,i.parsePhoneNumberFromString)(e,n);if(a)return absorbDoubledCallingCode(a.nationalNumber,a.isValid(),t,n);let o=(0,r.getCountryByIso3)(t),s=digitsOnly(e);if(o){let e=o.phoneCode.replace(`+`,``),t=s.startsWith(e)?s.slice(e.length):s;return(0,r.stripTrunkPrefix)(t,o.phoneTrunkPrefix??``)}return s}function absorbDoubledCallingCode(e,t,n,a){if(t)return e;let o=(0,r.getCountryByIso3)(n)?.phoneCode.replace(`+`,``);if(o===void 0||!e.startsWith(o))return e;let s=e.slice(o.length),c=(0,i.parsePhoneNumberFromString)(`+${o}${s}`,a);return c?.isValid()?c.nationalNumber:e}function formatPhoneForDisplay(e){if(!e.phoneNumber)return``;let t=getIso2(e.countryCode),n=(0,r.getCountryByIso3)(e.countryCode)?.phoneCode??``;if(!t)return`${n} ${e.phoneNumber}`.trim();let a=`${n}${digitsOnly(e.phoneNumber)}`,o=(0,i.parsePhoneNumberFromString)(a);return o?o.formatInternational():`${n} ${e.phoneNumber}`.trim()}function createPhoneValidator(e,t=s){return n.object({countryCode:n.string().length(3),phoneNumber:n.string().min(1,{message:t.required(e)})},{message:t.invalidPhone(e)}).refine(e=>(0,r.isValidIso3)(e.countryCode),{message:`Invalid country code`}).transform(e=>({countryCode:e.countryCode,phoneNumber:normalizePhoneNumber(e.phoneNumber,e.countryCode)}))}function extractRelationId(e){return typeof e==`object`&&e&&`id`in e?e.id:e}function createSingleRelationValidator(e,t=s){let r=n.guid({message:t.invalidId(e)}),i=n.union([r,n.null()]);return n.union([i,n.object({id:r,props:n.record(n.string(),n.unknown()).optional()}).passthrough()])}function createMultiRelationValidator(e,t=s){let r=n.guid({message:t.invalidId(e)}),i=n.union([r,n.object({id:r,props:n.record(n.string(),n.unknown()).optional()}).passthrough()]),a=n.array(i);return e.maxItems!==void 0&&(a=a.max(e.maxItems,t.maxItems(e,e.maxItems))),a.refine(e=>e.every(e=>{let t=extractRelationId(e);return typeof t==`string`&&r.safeParse(t).success}),{message:t.invalidId(e)})}function createRelationValidator(e,t=s){return e.cardinality===`many`?createMultiRelationValidator(e,t):createSingleRelationValidator(e,t)}function createRichtextValidator(e,t=s){return n.string({message:t.invalidRichtext(e)})}function describeOptions(e){return e.map(e=>e.label===e.value?e.value:`${e.value} (${e.label})`)}function createSelectValidator(e,t=s){let r=e.options.map(e=>e.value);return r.length===0?n.never():n.enum(r,{message:t.invalidOption(e,describeOptions(e.options))})}function createMultiselectValidator(e,t=s){let r=e.options.map(e=>e.value);return r.length===0?n.never():n.array(n.enum(r,{message:t.invalidOption(e,describeOptions(e.options))}))}function createStatusValidator(e,t=s){let r=e.options.map(e=>e.value);return r.length===0?n.never():n.enum(r,{message:t.invalidOption(e,describeOptions(e.options))})}function createUserValidator(e,t=s){let r=n.guid({message:t.invalidId(e)});return e.multiple?n.array(r):r}function createFormulaValidator(e,t=s){return n.unknown()}function createRollupValidator(e,t=s){return n.unknown()}function createAttributeValidator(e,t=s){switch(e.type){case`text`:return createTextValidator(e,t);case`richtext`:return createRichtextValidator(e,t);case`number`:return createNumberValidator(e,t);case`checkbox`:return createCheckboxValidator(e,t);case`date`:return createDateValidator(e,t);case`phone`:return createPhoneValidator(e,t);case`currency`:return createCurrencyValidator(e,t);case`status`:return createStatusValidator(e,t);case`location`:return createLocationValidator(e,t);case`select`:return createSelectValidator(e,t);case`multiselect`:return createMultiselectValidator(e,t);case`user`:return createUserValidator(e,t);case`relation`:return createRelationValidator(e,t);case`formula`:return createFormulaValidator(e,t);case`rollup`:return createRollupValidator(e,t);default:return n.unknown()}}function createFormAttributeValidator(e,t=s){let n=createAttributeValidator(e,t);return e.required?n:withEmptyToNull(n,l[e.type])}const Q=/* @__PURE__ */ new WeakMap,$=/* @__PURE__ */ new WeakMap;function createObjectValidator(e){let t=Q.get(e);if(t)return t;let r={};for(let t of e.attributes){let e=createAttributeValidator(t);t.required?r[t.name]=e.refine(isValuePresent,{message:s.required(t)}):r[t.name]=withEmptyToNull(e,l[t.type])}let i=n.object(r).passthrough();return Q.set(e,i),i}function createDraftValidator(e){let t=$.get(e);if(t)return t;let r={};for(let t of e.attributes){let e=createAttributeValidator(t);r[t.name]=withEmptyToNull(e,l[t.type])}let i=n.object(r).passthrough();return $.set(e,i),i}function validateAttribute(e,t){let n=createAttributeValidator(e);if(!e.required&&t==null)return{success:!0,data:{[e.name]:t}};let r=n.safeParse(t);return r.success?{success:!0,data:{[e.name]:r.data}}:{success:!1,errors:formatZodErrors(r.error).map(t=>({path:[e.name,...t.path],message:t.message}))}}function validateObject(e,t){let n=createObjectValidator(e).safeParse(t);return n.success?{success:!0,data:n.data}:{success:!1,errors:formatZodErrors(n.error)}}function validateObjectOrThrow(e,n){let r=validateObject(e,n);if(!r.success){let n=r.errors??[],i=n.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`
|
|
3
|
+
`)||`Unknown validation error`;throw new t.ValidationError(`Validation failed for ${e.label}:\n${i}`,n.map(e=>({path:e.path,message:e.message})))}return r.data}function validateDraft(e,t){let n=createDraftValidator(e).safeParse(t);return n.success?{success:!0,data:n.data}:{success:!1,errors:formatZodErrors(n.error)}}function validateDraftOrThrow(e,n){let r=validateDraft(e,n);if(!r.success){let n=r.errors??[],i=n.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`
|
|
4
|
+
`)||`Unknown validation error`;throw new t.ValidationError(`Draft validation failed for ${e.label}:\n${i}`,n.map(e=>({path:e.path,message:e.message})))}return r.data}function rejectUnknownAttributesOrThrow(e,n){let r=new Set(e.attributes.map(e=>e.name)),i=Object.keys(n).filter(e=>!r.has(e));if(i.length>0)throw new t.ValidationError(`Unknown attribute${i.length>1?`s`:``} for ${e.label}: ${i.join(`, `)}`,i.map(e=>({path:[e],message:`Unknown attribute`})))}Object.defineProperty(exports,"COMPUTED_RETURN_TYPES",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"DEFAULT_VALIDATION_MESSAGES",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"SIMPLE_PROPERTY_TYPES",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"TEXT_FORMAT_PATTERNS",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"WIRE_OFFERED_BASE_CONFIG",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"WIRE_OMITTED_CONFIG_KEYS",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"attributeConfigSchemas",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"createAttributeValidator",{enumerable:!0,get:function(){return createAttributeValidator}}),Object.defineProperty(exports,"createFormAttributeValidator",{enumerable:!0,get:function(){return createFormAttributeValidator}}),Object.defineProperty(exports,"createObjectValidator",{enumerable:!0,get:function(){return createObjectValidator}}),Object.defineProperty(exports,"datePrecisionIssues",{enumerable:!0,get:function(){return datePrecisionIssues}}),Object.defineProperty(exports,"formatPhoneForDisplay",{enumerable:!0,get:function(){return formatPhoneForDisplay}}),Object.defineProperty(exports,"formatZodErrors",{enumerable:!0,get:function(){return formatZodErrors}}),Object.defineProperty(exports,"getAttributeConfigSchema",{enumerable:!0,get:function(){return getAttributeConfigSchema}}),Object.defineProperty(exports,"getAttributeConfigWriteSchema",{enumerable:!0,get:function(){return getAttributeConfigWriteSchema}}),Object.defineProperty(exports,"getIso2",{enumerable:!0,get:function(){return getIso2}}),Object.defineProperty(exports,"isEmptyValue",{enumerable:!0,get:function(){return isEmptyValue}}),Object.defineProperty(exports,"isNullishOrEmptyString",{enumerable:!0,get:function(){return isNullishOrEmptyString}}),Object.defineProperty(exports,"isValuePresent",{enumerable:!0,get:function(){return isValuePresent}}),Object.defineProperty(exports,"normalizeCountrylessPhoneNumber",{enumerable:!0,get:function(){return normalizeCountrylessPhoneNumber}}),Object.defineProperty(exports,"normalizePhoneNumber",{enumerable:!0,get:function(){return normalizePhoneNumber}}),Object.defineProperty(exports,"parseAttributeConfig",{enumerable:!0,get:function(){return parseAttributeConfig}}),Object.defineProperty(exports,"parseAttributeConfigForCreate",{enumerable:!0,get:function(){return parseAttributeConfigForCreate}}),Object.defineProperty(exports,"parseAttributeConfigForUpdate",{enumerable:!0,get:function(){return parseAttributeConfigForUpdate}}),Object.defineProperty(exports,"propertyAttributeSchema",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"propertyAttributeWireSchema",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"propertySchemaSchema",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"propertySchemaWireSchema",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"refuseForeignKeys",{enumerable:!0,get:function(){return refuseForeignKeys}}),Object.defineProperty(exports,"rejectUnknownAttributesOrThrow",{enumerable:!0,get:function(){return rejectUnknownAttributesOrThrow}}),Object.defineProperty(exports,"resolveTextPattern",{enumerable:!0,get:function(){return resolveTextPattern}}),Object.defineProperty(exports,"selectOptionWriteSchema",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"statusGroupSchema",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"statusOptionWriteSchema",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"validateAttribute",{enumerable:!0,get:function(){return validateAttribute}}),Object.defineProperty(exports,"validateDraft",{enumerable:!0,get:function(){return validateDraft}}),Object.defineProperty(exports,"validateDraftOrThrow",{enumerable:!0,get:function(){return validateDraftOrThrow}}),Object.defineProperty(exports,"validateObject",{enumerable:!0,get:function(){return validateObject}}),Object.defineProperty(exports,"validateObjectOrThrow",{enumerable:!0,get:function(){return validateObjectOrThrow}}),Object.defineProperty(exports,"wireHiddenTypeConfigMask",{enumerable:!0,get:function(){return wireHiddenTypeConfigMask}}),Object.defineProperty(exports,"wireOmittedConfigKeysFor",{enumerable:!0,get:function(){return wireOmittedConfigKeysFor}}),Object.defineProperty(exports,"withoutUnknownOptionKeys",{enumerable:!0,get:function(){return withoutUnknownOptionKeys}});
|