@standards/schema 1.0.0-alpha.419 → 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 +15312 -1880
- package/dist/api/index.d.ts +15312 -1880
- 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-C3d0YoMy.d.mts → exceptions-DtcTc7fk.d.mts} +11 -0
- package/dist/{exceptions-DzEpWPJ7.d.ts → exceptions-EheEZJ0K.d.ts} +11 -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-YUFgn36U.d.ts → utils-CzDInA43.d.ts} +1 -1
- package/dist/{utils-Bl7NhRVP.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 +58903 -12561
- package/package.json +2 -2
- package/dist/all-BFZvSwku.mjs +0 -4
- package/dist/all-CcI67hiC.d.mts +0 -4305
- package/dist/all-cpt9cxka.d.ts +0 -4306
- package/dist/all-kYfkyIit.js +0 -4
- package/dist/index-D59FeAd4.d.mts +0 -18609
- package/dist/index-DhzoMOYA.d.ts +0 -18609
- package/dist/primitives-B-h9MEQ4.mjs +0 -11
- package/dist/primitives-CvuPz5hX.js +0 -11
- package/dist/record-operation-BYjGrZ1R.js +0 -2
- package/dist/record-operation-q6w-3EDJ.mjs +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standards/schema",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.421",
|
|
4
4
|
"description": "Standard schema definitions and utilities",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"README.md"
|
|
81
81
|
],
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@standards/constants": "1.0.0-alpha.
|
|
83
|
+
"@standards/constants": "1.0.0-alpha.421",
|
|
84
84
|
"@standard-schema/spec": "^1.1.0",
|
|
85
85
|
"libphonenumber-js": "^1.12.31",
|
|
86
86
|
"zod": "^4.6.6"
|
package/dist/all-BFZvSwku.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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{AGGREGATE_MEASURES as e,ATTRIBUTE_NAME_SCHEMA as t,DECISION_KINDS as n,HIERARCHY_ATTRIBUTE_NAMES as r,LIST_VIEW_TAB_VISIBILITIES as i,SCHEMA_LIMITS as a,colorIdSchema as o,getObjectSystemAttributes as s,iconNameSchema as c,isHierarchyAttribute as l,isManagedSystemAttribute as u,isPlainRecord as d}from"./primitives-B-h9MEQ4.mjs";import{DuplicateError as f,SchemaError as ee,ValidationError as p}from"./exceptions.mjs";import*as m from"zod";import{getCountryByIso3 as h,isValidIso3 as te,stripTrunkPrefix as g}from"@standards/constants";import{parsePhoneNumberFromString as _}from"libphonenumber-js";const ne=[`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`ends_with`,`is_empty`,`is_not_empty`],v=[`is`,`is_not`,`less_than`,`greater_than`,`less_or_equal`,`greater_or_equal`,`is_empty`,`is_not_empty`],y=[`is`],b=[`is`,`is_not`,`less_than`,`greater_than`,`less_or_equal`,`greater_or_equal`,`is_within`,`on_day_month`,`is_empty`,`is_not_empty`],x=[`is`,`is_not`,`any_of`,`none_of`,`is_empty`,`is_not_empty`],S=[`any_of`,`none_of`,`is_empty`,`is_not_empty`],re=[`is`,`is_not`,`any_of`,`none_of`,`is_empty`,`is_not_empty`],ie=[`is_empty`,`is_not_empty`],ae=[`is`,`is_not`,`less_than`,`greater_than`,`less_or_equal`,`greater_or_equal`,`contains`,`not_contains`,`is_empty`,`is_not_empty`],C=[`city`,`postalCode`,`country`];function isLocationFilterProperty(e){return C.includes(e)}const w={text:ne,richtext:[],number:v,checkbox:y,date:b,phone:[`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`is_empty`,`is_not_empty`],currency:v,status:x,select:x,multiselect:S,location:[],user:re,relation:re,formula:ae,document:ie},T={text:{value:`plain`,traits:[`placeholder`,`searchable`,`sortable`]},richtext:{value:`plain`,traits:[`searchable`,`content`]},number:{value:`plain`,traits:[`placeholder`,`sortable`]},checkbox:{value:`boolean`,traits:[`sortable`]},date:{value:`plain`,traits:[`placeholder`,`sortable`]},phone:{value:`plain`,traits:[`placeholder`,`searchable`,`sortable`]},currency:{value:`plain`,traits:[`placeholder`,`sortable`,`groupable`]},status:{value:`options`,traits:[`searchable`,`sortable`,`groupable`]},location:{value:`plain`,traits:[]},select:{value:`options`,traits:[`placeholder`,`searchable`,`sortable`]},multiselect:{value:`options`,traits:[`placeholder`,`searchable`]},user:{value:`reference`,traits:[]},relation:{value:`reference`,traits:[`qualified`]},formula:{value:`computed`,traits:[]},rollup:{value:`computed`,traits:[]},document:{value:`reference`,traits:[`content`,`qualified`]}};function descriptorOf(e){return Object.prototype.hasOwnProperty.call(T,e)?T[e]:void 0}function isValueKindType(e,t){return descriptorOf(e)?.value===t}function hasValueKind(e,t){return isValueKindType(e.type,t)}function hasTypeTrait(e,t){return descriptorOf(e)?.traits.includes(t)??!1}const oe={plain:`static`,boolean:`automatic`,options:`static`,reference:`static`,computed:`forbidden`};function getAttributeCapabilities(e){let t=!!(e.hidden||e.archived),n=!e.archived,r=descriptorOf(e.type)?.value,i=r===`computed`,a=e.type===`document`,o=r===`reference`&&!l(e),s=getAttributeCardinality(e),c=t?[]:getRawFilterOperators(e),d=c.length>0&&!t,f=!t&&hasTypeTrait(e.type,`searchable`),ee=!t&&hasTypeTrait(e.type,`sortable`),p=!t&&hasTypeTrait(e.type,`groupable`),m=!t&&(e.type===`status`||e.type===`select`),h=u(e),te=i||a||h,g=!(t||te),_=r===void 0?`forbidden`:oe[r],ne=r===`boolean`||i?`forbidden`:`allowed`,v=supportsMaxItems(e),y=hasTypeTrait(e.type,`placeholder`),b=hasTypeTrait(e.type,`content`),x=!(!e.deprecated||t),S=resolveEditMode(e);return{lifecycle:{active:n,deprecated:!!e.deprecated,visibleInArchitect:!0,visibleInRuntime:!t,warningWhenDeprecated:x},storage:{mode:i?`computed`:o?`edge`:`value`,cardinality:s,edgeBacked:o,preservesExistingValues:!!e.archived,qualifiedProperties:hasTypeTrait(e.type,`qualified`),polymorphic:getPolymorphicCapability(e),maxItems:v},authoring:{editable:g,readOnly:te,directEdit:g&&S===`inline`,required:ne,defaultValue:_,placeholder:y,maxItems:v},presentation:{formField:!t&&e.type!==`richtext`,tableCell:!(t||b),defaultColumn:!(t||b),compactDisplay:!t,popoverEditor:!t&&S===`popover`,placeholder:y,warningWhenDeprecated:x},query:{filterable:d,searchable:f,sortable:ee,groupable:p,kanbanGroupable:m,operators:c},agent:{readable:!t,writable:g&&!a,compactReadable:!t,contentReadable:!t&&b,requiresDedicatedTool:a},exchange:{importable:!t,exportable:!t,schemaExportable:!0,metadataExportable:!1}}}function getAttributeFilterOperators(e){return getAttributeCapabilities(e).query.operators}function isAttributeFilterable(e){return getAttributeCapabilities(e).query.filterable}function isAttributeSearchable(e){return getAttributeCapabilities(e).query.searchable}function isAttributeSortable$1(e){return getAttributeCapabilities(e).query.sortable}function isAttributeGroupable(e){return getAttributeCapabilities(e).query.groupable}function isAttributeKanbanGroupable(e){return getAttributeCapabilities(e).query.kanbanGroupable}function resolveEffectiveFilterType(e){if(e.type!==`rollup`)return e.type;let t=e;if(t.function===`earliest`||t.function===`latest`)return`date`;if(t.function===`original`){let e=t.targetAttributeType;if(e&&hasFilterOperatorEntry(e))return e}return`number`}function getRollupFilterOperators$1(e){let t=resolveEffectiveFilterType(e);return hasFilterOperatorEntry(t)?w[t]:w.number}function getRawFilterOperators(e){return e.type===`rollup`?getRollupFilterOperators$1(e):w[e.type]??[]}function getAttributeCardinality(e){return e.type===`multiselect`||e.type===`document`||e.type===`user`&&e.multiple===!0||e.type===`relation`&&e.cardinality===`many`?`many`:`one`}function getPolymorphicCapability(e){if(e.type!==`relation`)return`none`;let t=e.targets??[];return t.length===1&&t[0]?.object===`*`?`internal`:t.length>1?`code-only`:`none`}function supportsMaxItems(e){return e.type===`multiselect`||e.type===`relation`&&e.cardinality===`many`}function resolveEditMode(e){switch(e.type){case`checkbox`:return`inline`;case`number`:return e.renderAs===`rating`?`inline`:`default`;case`select`:case`multiselect`:return e.renderAs===`badges`?`inline`:`popover`;case`status`:case`relation`:case`user`:case`date`:return`popover`;default:return`default`}}function hasFilterOperatorEntry(e){return Object.prototype.hasOwnProperty.call(w,e)}const se=[`text`,`richtext`,`number`,`checkbox`,`date`,`phone`,`currency`,`status`,`location`,`select`,`multiselect`,`user`,`relation`,`formula`,`rollup`,`document`],ce=`*`;function relationTargetsOf(e){return e.type!==`relation`||!Array.isArray(e.targets)?[]:e.targets.map(e=>e.object).filter(e=>e!==`*`)}function isUniversalRelation(e){return e.targets.length===1&&e.targets[0].object===`*`}function isBilateralRelation(e){return e.bilateral!==void 0}function inferInverseCardinality(e){return`many`}function isAttributeSortable(e){return isAttributeSortable$1(e)}const le=w,ue=[`is_empty`,`is_not_empty`];function isNoValueOperator(e){return ue.includes(e)}function getRollupFilterOperators(e){return getRollupFilterOperators$1(e)}const de=[`text`,`number`,`boolean`,`date`,`select`,`multiselect`];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 fe={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 m.preprocess(e=>isEmptyValue(e,t)?null:e,e.nullish())}const pe={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?pe[e.format]:void 0}const me=`__`;function parseQualifiedAttribute(e){let t=e.indexOf(`__`);return t<=0||t+2>=e.length?{kind:`scalar`,attribute:e}:{kind:`qualified`,root:e.slice(0,t),property:e.slice(t+2)}}function buildQualifiedAttribute(e,t){return`${e}__${t}`}const E={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 he=createRegexCache();function createTextValidator(e,t=E){let n=m.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(he,r),t.invalidPattern(e))),n}function createNumberValidator(e,t=E){let n=m.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=E){return m.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=E){let n=t.invalidDate(e),r=floorToPrecision(resolveBound(e.minDate),e.precision),i=resolveBound(e.maxDate),a=m.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=m.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 m.preprocess(e=>typeof e==`string`?{start:e,end:null}:e,o)}const D=m.object({placeholder:m.string().optional(),description:m.string().optional(),defaultValue:m.unknown().optional(),icon:m.string().optional(),order:m.number().int().optional(),hidden:m.boolean().optional(),archived:m.boolean().optional(),deprecated:m.boolean().optional(),metadata:m.record(m.string(),m.unknown()).optional()}),O=[`placeholder`,`description`,`defaultValue`,`icon`,`order`,`hidden`,`archived`,`deprecated`,`metadata`],ge={icon:c.optional().describe(`Field icon from search_icons`)},_e={date:[`precision`],user:[`notifiesOnAssign`,`actors`]};function wireOmittedConfigKeysFor(e){return[...O,..._e[e]??[]]}function wireHiddenTypeConfigMask(e){return Object.fromEntries((_e[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 k=m.object({value:m.string().min(1).describe(`Stored value`),label:m.string().min(1).describe(`Label people see`),description:m.string().describe(`Extra context`).optional(),inverse:m.string().describe(`Paired option's value (symmetric)`).optional(),archived:m.boolean().describe(`Hides without deleting`).optional()}),A=m.enum([`idle`,`in_progress`,`finished`]).describe(`Workflow stage`),j=k.extend({color:o}).strict(),ve=k.extend({color:o,group:A}).strict(),M=k.extend({color:m.string().optional().describe(`A color id`),group:A.optional()}).strict(),ye=new Set(M.keyof().options),be=[`options`,`targetAttributeOptions`];function withoutUnknownOptionKeys(e){let t=e;for(let n of be){let r=e[n];if(!Array.isArray(r))continue;let i=!1,a=r.map(e=>!d(e)||Object.keys(e).every(e=>ye.has(e))?e:(i=!0,Object.fromEntries(Object.entries(e).filter(([e])=>ye.has(e)))));i&&(t={...t,[n]:a})}let n=e.properties;if(d(n)&&Array.isArray(n.definitions)){let e=n.definitions,r=e.map(e=>d(e)?withoutUnknownOptionKeys(e):e);r.some((t,n)=>t!==e[n])&&(t={...t,properties:{...n,definitions:r}})}return t}const N=m.array(M).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 m.array(e).min(1).max(a.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 xe=writeOptionsArraySchema(j),Se=writeOptionsArraySchema(j),Ce=writeOptionsArraySchema(ve),we=m.object({object:m.string().min(1).describe(`Target object`),displayTemplate:m.string().optional().describe(`Linked record label template`),filter:m.record(m.string(),m.unknown()).optional().describe(`Restricts linkable records`)}),Te=m.object({object:m.string().min(1).describe(`Other side's object`),attribute:m.string().min(1).describe(`Other side's attribute`),cardinality:m.enum([`one`,`many`]).optional().describe(`Other side's cardinality`),label:m.string().min(1).optional().describe(`Other side's label`),storageOwner:m.boolean().optional().describe(`Owns the join storage`)}),Ee=m.object({objectName:m.string().min(1).describe(`API name of the object whose options are mirrored`),attributeName:m.string().min(1).describe(`API name of the select/status attribute to mirror options from`),attributeId:m.string().optional().describe(`Id of the source attribute, resolved by the server`)}),De=D.extend({multiline:m.boolean().describe(`Renders as a multi-line textarea`).optional(),minLength:m.number().int().min(0).describe(`Minimum character count`).optional(),maxLength:m.number().int().min(1).describe(`Maximum character count`).optional(),pattern:m.string().describe(`Regular expression the value must match`).optional(),format:m.enum([`email`,`url`,`slug`]).describe(`Validates and renders as this format`).optional()}),Oe=D,ke=D.extend({renderAs:m.enum([`number`,`rating`]).describe(`Plain number or a star rating`).optional(),min:m.number().describe(`Minimum allowed value`).optional(),max:m.number().describe(`Maximum allowed value`).optional(),unit:m.enum([`integer`,`decimal`,`percentage`]).describe(`How the value is stored and rendered`).optional(),decimals:m.number().int().min(0).max(10).describe(`Decimal places shown`).optional()}),Ae=D,je=D.extend({dateFormat:m.enum([`short`,`long`,`full`,`relative`]).describe(`How the date is rendered`).optional(),precision:m.enum([`day`,`month`,`year`]).describe(`Whether the value records a day, a month or a year`).optional(),minDate:m.string().describe(`Earliest allowed date (ISO)`).optional(),maxDate:m.string().describe(`Latest allowed date (ISO)`).optional(),includeTime:m.boolean().describe(`Also captures a time of day`).optional(),endDate:m.boolean().describe(`Paired with another date attribute as a range's end`).optional(),timeFormat:m.enum([`12h`,`24h`]).describe(`Clock format when a time is included`).optional()}),Me=D.extend({defaultCountryCode:m.string().length(3).describe(`ISO country code preselected in the dialer`).optional()}),Ne=D.extend({defaultCurrency:m.string().length(3).describe(`ISO currency code preselected for new values`).optional(),allowedCurrencies:m.array(m.string().length(3)).describe(`ISO currency codes a value may use; any currency when omitted`).optional(),allowNegative:m.boolean().describe(`Whether a negative amount is accepted`).optional()}),P=D.extend({options:N.describe(`The workflow statuses, in order`)}),Pe=D.extend({granularity:m.enum([`full`,`address`,`city`,`state`,`country`,`coordinates`]).describe(`How precise a location must be captured`).optional(),defaultCountry:m.string().length(3).describe(`ISO country code preselected for new values`).optional(),allowedCountries:m.array(m.string().length(3)).describe(`ISO country codes a value may use; any country when omitted`).optional()}),F=D.extend({options:N.describe(`Options`),renderAs:m.literal(`badges`).optional().describe(`Renders the chosen option as a colored badge`)}),I=D.extend({options:N.describe(`Options`),renderAs:m.literal(`badges`).optional().describe(`Renders the chosen options as colored badges`)}),Fe=D.extend({types:m.array(m.enum([`user`,`agent`])).min(1).optional().describe(`Which kinds of actor can be picked; both when omitted`),multiple:m.boolean().optional().describe(`Whether more than one actor can be picked`),notifiesOnAssign:m.boolean().optional().describe(`Whether each person added to the value is notified`),actors:m.boolean().optional().describe(`Whether the value holds actor ids, named by each actor's current name`)}),L={name:t.describe(`Property API name`),label:m.string().min(1).describe(`Label people see`),required:m.boolean().describe(`Required on every edge`).optional()},Ie={id:m.string().optional(),objectId:m.string().optional(),system:m.boolean().optional(),unique:m.boolean().optional()},Le=Object.fromEntries(O.map(e=>[e,!0])),R=[`text`,`number`,`checkbox`,`date`,`phone`,`currency`,`location`],Re=[...R,`select`,`multiselect`,`status`],ze={text:De,number:ke,checkbox:Ae,date:je,phone:Me,currency:Ne,location:Pe,select:F,multiselect:I,status:P},Be={...ze,select:F.extend({options:xe.describe(`Options`)}),multiselect:I.extend({options:Se.describe(`Options`)}),status:P.extend({options:Ce.describe(`Statuses`)})},propertyWireConfigShapeFor=e=>Be[e].omit(Le).omit(wireHiddenTypeConfigMask(e)).shape,storedPropertyMember=e=>m.object({...L,...Ie,type:m.literal(e).describe(`Property type`),...ze[e].shape}).strip(),Ve=m.discriminatedUnion(`type`,Re.map(storedPropertyMember)),z=m.object({definitions:m.array(Ve).min(1).max(a.optionsPerAttribute).describe(`Edge properties`)}).strip().describe(`Properties carried by the edge itself (role, share, since…), never a third object`),He=refuseForeignKeys(Object.fromEntries(Re.map(e=>[e,new Set(Object.keys(propertyWireConfigShapeFor(e)))])),`property key`,[...Object.keys(L),`type`]);function refuseForeignPropertyKeys(e,t){He(e.type,e,t)}const Ue=R.reduce((e,t)=>(Object.assign(e,propertyWireConfigShapeFor(t)),e),{}),optionPropertyWireMember=e=>m.object({...L,type:e.length===1?m.literal(e[0]).describe(`Property type`):m.enum(e).describe(`Property type`),...propertyWireConfigShapeFor(e[0])}).strict(),We=m.discriminatedUnion(`type`,[optionPropertyWireMember([`select`,`multiselect`]),optionPropertyWireMember([`status`]),m.object({...L,type:m.enum(R).describe(`Property type`),...Ue}).strict().superRefine(refuseForeignPropertyKeys)]),Ge=m.object({definitions:m.array(We).min(1).max(a.optionsPerAttribute).describe(`Edge properties`)}).strict().describe(`Properties carried by the edge itself (role, share, since…), never a third object`),Ke=D.extend({targets:m.array(we).min(1).describe(`Target object(s)`),cardinality:m.enum([`one`,`many`]).describe(`one or many`),maxItems:m.number().int().min(1).optional().describe(`Max linked records`),bilateral:Te.optional().describe(`Syncs the other side's attribute`),properties:z.optional()}),qe=D.extend({expression:m.string().min(1).describe(`The formula expression, compiled against this object's attributes`),returnType:m.enum(de).describe(`The formula's result type`),decimals:m.number().int().min(0).max(10).optional().describe(`Decimal places shown for a number result`),currencyCode:m.string().length(3).optional().describe(`ISO 4217 code a number result renders with; presentation only`),allowRelations:m.boolean().optional().describe(`Whether the expression may read across a relation`),optionsSource:Ee.optional().describe(`Mirrors an option set`)}),Je=D.extend({relationAttribute:m.string().min(1).optional().describe(`API name of the relation this rollup aggregates through`),relationPath:m.string().optional().describe(`Not supported yet — single-hop only`),targetAttribute:m.string().min(1).optional().describe(`API name of the attribute aggregated on the relation's target object; not read by count`),function:m.enum([`sum`,`avg`,`earliest`,`latest`,`count`,`countValues`,`countUniqueValues`,`countEmpty`,`percentEmpty`,`percentNotEmpty`,`original`]).describe(`The aggregation applied across the linked records`),decimals:m.number().int().min(0).max(10).optional().describe(`Decimal places shown for a numeric result`),targetAttributeType:m.string().optional().describe(`Server-set`),targetAttributeOptions:m.array(M).optional().describe(`Server-set`),targetCurrencyCode:m.string().length(3).optional().describe(`Server-set`),optionsSource:Ee.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=[],i=t.precision;if(e===`date`&&i!==void 0&&i!==`day`)for(let e of[`includeTime`,`endDate`])t[e]===!0&&r.push({path:[...n,`precision`],message:`A "${String(i)}" precision cannot be combined with ${e}`});let a=t.properties;return d(a)&&Array.isArray(a.definitions)&&a.definitions.forEach((e,t)=>{d(e)&&r.push(...datePrecisionIssues(String(e.type),e,[...n,`properties`,`definitions`,t]))}),r}const Ye={text:De,richtext:Oe,number:ke,checkbox:Ae,date:je,phone:Me,currency:Ne,status:P,location:Pe,select:F,multiselect:I,user:Fe,relation:Ke,formula:qe,rollup:Je,document:D.extend({properties:z.optional(),accepts:m.array(m.string().min(1)).optional().describe("MIME prefixes or globs a file must match (e.g. `image/*`, `*.pdf`)"),maxFileSize:m.number().int().min(1).optional().describe(`Maximum file size in bytes`)})};function getAttributeConfigSchema(e){let t=Ye[e];if(!t)throw new p(`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:c.optional()});switch(e){case`select`:return t.extend({options:xe.describe(`Options`)});case`multiselect`:return t.extend({options:Se.describe(`Options`)});case`status`:return t.extend({options:Ce.describe(`Statuses`)});default:return t}}function validationErrorFromIssues(e){return p.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=c.optional().safeParse(e.icon);if(!t.success)throw p.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 a=e.options;isValueKindType(e.type,`options`)&&(i.options=[{value:`__legacy__`,label:`__legacy__`}]);let o=getAttributeConfigSchema(e.type).strip().safeParse(i);if(!o.success)throw validationErrorFromIssues(o.error.issues);let s=o.data,c=datePrecisionIssues(e.type,s);if(c.length>0)throw validationErrorFromIssues(c);return isValueKindType(e.type,`options`)&&(s.options=a),s}function createCurrencyValidator(e,t=E){let n=e.allowNegative?m.number():m.number().min(0);return m.object({code:m.string().length(3),value:n},{message:t.invalidCurrency(e)})}function createLocationValidator(e,t=E){return m.object({address:m.string().optional(),address2:m.string().optional(),city:m.string().optional(),state:m.string().optional(),postalCode:m.string().optional(),country:m.string().length(3).optional(),latitude:m.number().min(-90).max(90).optional(),longitude:m.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 h(e)?.iso2}function normalizePhoneNumber(e,t){if(!e)return``;let n=getIso2(t);if(!n)return digitsOnly(e);let r=_(e,n);if(r)return absorbDoubledCallingCode(r.nationalNumber,r.isValid(),t,n);let i=h(t),a=digitsOnly(e);if(i){let e=i.phoneCode.replace(`+`,``),t=a.startsWith(e)?a.slice(e.length):a;return g(t,i.phoneTrunkPrefix??``)}return a}function absorbDoubledCallingCode(e,t,n,r){if(t)return e;let i=h(n)?.phoneCode.replace(`+`,``);if(i===void 0||!e.startsWith(i))return e;let a=e.slice(i.length),o=_(`+${i}${a}`,r);return o?.isValid()?o.nationalNumber:e}function formatPhoneForDisplay(e){if(!e.phoneNumber)return``;let t=getIso2(e.countryCode),n=h(e.countryCode)?.phoneCode??``;if(!t)return`${n} ${e.phoneNumber}`.trim();let r=`${n}${digitsOnly(e.phoneNumber)}`,i=_(r);return i?i.formatInternational():`${n} ${e.phoneNumber}`.trim()}function createPhoneValidator(e,t=E){return m.object({countryCode:m.string().length(3),phoneNumber:m.string().min(1,{message:t.required(e)})},{message:t.invalidPhone(e)}).refine(e=>te(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=E){let n=m.guid({message:t.invalidId(e)}),r=m.union([n,m.null()]);return m.union([r,m.object({id:n,props:m.record(m.string(),m.unknown()).optional()}).passthrough()])}function createMultiRelationValidator(e,t=E){let n=m.guid({message:t.invalidId(e)}),r=m.union([n,m.object({id:n,props:m.record(m.string(),m.unknown()).optional()}).passthrough()]),i=m.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=E){return e.cardinality===`many`?createMultiRelationValidator(e,t):createSingleRelationValidator(e,t)}function createRichtextValidator(e,t=E){return m.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=E){let n=e.options.map(e=>e.value);return n.length===0?m.never():m.enum(n,{message:t.invalidOption(e,describeOptions(e.options))})}function createMultiselectValidator(e,t=E){let n=e.options.map(e=>e.value);return n.length===0?m.never():m.array(m.enum(n,{message:t.invalidOption(e,describeOptions(e.options))}))}function createStatusValidator(e,t=E){let n=e.options.map(e=>e.value);return n.length===0?m.never():m.enum(n,{message:t.invalidOption(e,describeOptions(e.options))})}function createUserValidator(e,t=E){let n=m.guid({message:t.invalidId(e)});return e.multiple?m.array(n):n}function createFormulaValidator(e,t=E){return m.unknown()}function createRollupValidator(e,t=E){return m.unknown()}function createAttributeValidator(e,t=E){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 m.unknown()}}function createFormAttributeValidator(e,t=E){let n=createAttributeValidator(e,t);return e.required?n:withEmptyToNull(n,fe[e.type])}const Xe=/* @__PURE__ */ new WeakMap,Ze=/* @__PURE__ */ new WeakMap;function createObjectValidator(e){let t=Xe.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:E.required(t)}):n[t.name]=withEmptyToNull(e,fe[t.type])}let r=m.object(n).passthrough();return Xe.set(e,r),r}function createDraftValidator(e){let t=Ze.get(e);if(t)return t;let n={};for(let t of e.attributes){let e=createAttributeValidator(t);n[t.name]=withEmptyToNull(e,fe[t.type])}let r=m.object(n).passthrough();return Ze.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 p(`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 p(`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 p(`Unknown attribute${r.length>1?`s`:``} for ${e.label}: ${r.join(`, `)}`,r.map(e=>({path:[e],message:`Unknown attribute`})))}const B=[`page`,`record`,`display`];function defineBlock(e){let t=Object.fromEntries(Object.entries(e.inputs).map(([e,t])=>[e,t.isOptional?t.schema.optional():t.schema]));return Object.freeze({name:e.name,label:e.label,icon:e.icon,family:e.family,contexts:Object.freeze([...e.contexts]),inputs:Object.freeze({...e.inputs}),...e.layout===void 0?{}:{layout:Object.freeze({...e.layout})},parameters:m.object(t).strict().superRefine((t,n)=>{let r=e.refine?.(t);r&&n.addIssue({code:`custom`,path:[r.input],message:r.message})}),...e.refine===void 0?{}:{refine:(t,n)=>e.refine?.(t,n)}})}function parseBlockParameters(e,t,n){let r=e.parameters.safeParse(structuredClone(t??{}));if(!r.success)throw p.fromZodErrors(r.error.issues.map(e=>({path:[...n,...e.path.map(String)],message:e.message})));return r.data}function blockObjectInputs(e,t,n){return Object.entries(e.inputs).flatMap(([e,r])=>{let i=t[e];if(r.kind===`object`&&typeof i==`string`)return[i];if(r.kind===`query`&&typeof i==`object`&&i){let e=i.source;if(!e)return[];if(`object`in e&&typeof e.object==`string`)return[e.object];let t=n?.attributes.find(t=>t.name===e.relation);return t?relationTargetsOf(t):[]}return[]})}const Qe=/^\d{4}-\d{2}-\d{2}$/u;function isCalendarDay(e){if(!Qe.test(e))return!1;let t=/* @__PURE__ */ new Date(`${e}T00:00:00Z`);return!Number.isNaN(t.getTime())&&t.toISOString().slice(0,10)===e}function isDynamicValue(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&`dynamic`in e}function currentActor(){return{dynamic:`actor`,ref:`current`}}function today(){return{dynamic:`date`,anchor:`today`}}function now(){return{dynamic:`date`,anchor:`now`}}function toAmount(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:null}return null}function extractCurrencyFilterValue(e){return typeof e==`object`&&e?`value`in e?toAmount(e.value):null:toAmount(e)}function extractFilterValue(e){return e==null?null:typeof e==`object`&&`value`in e?e.value??null:e}const $e=/* @__PURE__ */ new Set([`is_not`,`not_contains`,`none_of`,`is_empty`]),et={is_not:`is`,not_contains:`contains`,none_of:`any_of`,is_empty:`is_not_empty`};function getOperatorPolarity(e){return $e.has(e)?`none`:`any`}function normalizeForEdgeRpc(e){return et[e]??e}const tt={is:`any_of`,is_not:`none_of`};function toMultiValueOperator(e){return tt[e]??e}const nt=new Set(Object.values(tt).filter(e=>e!==void 0));function isSetMembershipOperator(e){return nt.has(e)}function canonicalizeFilterValue(e,t){let n=e.value;if(isNoValueOperator(e.operator)||n==null||isDynamicValue(n))return;if(isSetMembershipOperator(e.operator)){Array.isArray(n)||(e.value=[n]);return}if(t!==`currency`)return;let r=extractCurrencyFilterValue(n);if(r!==null){e.value=r;return}if(!hasCurrencyAmount(n))return;let i=`Filter on a currency attribute expected a numeric amount, received ${JSON.stringify(n)}`;throw new p(i,[{path:[`value`],message:i}])}function hasCurrencyAmount(e){return typeof e!=`object`||`value`in e&&e.value!=null}const V=w.text,rt=[`is`,`is_not`,`is_empty`,`is_not_empty`],H=[`is`,`is_not`,`any_of`,`none_of`,`is_empty`,`is_not_empty`],U={id:H,objectId:H,tenantId:H,label:w.text,createdAt:w.date,updatedAt:w.date,deletedAt:w.date,createdBy:w.user,lastUpdatedBy:w.user,parentId:H,childIds:[`is_empty`,`is_not_empty`]},it=/* @__PURE__ */ new Set([`createdAt`,`updatedAt`,`deletedAt`]);function offeredOn(e,t){return it.has(e)?t.filter(e=>e!==`on_day_month`):t}function fullyOffered(e,t,n,r){return{target:e,attribute:t,...r?{property:r}:{},operators:n,offered:n}}function attributeFilterTarget(e){let t=l(e)?systemColumnFilterTarget(e.name):void 0;if(t)return t;let n=getAttributeFilterOperators(e);return{target:e.name,attribute:e.name,operators:n,offered:offeredOn(e.name,n)}}function locationPartFilterTarget(e,t){return{target:buildQualifiedAttribute(e,t),attribute:e,property:t,operators:V,offered:t===`country`?rt:V}}function edgePropertyFilterTarget(e,t){let n=hasOperatorEntry(t.type)?w[t.type]:[];return fullyOffered(buildQualifiedAttribute(e,t.name),e,n,t.name)}function hasOperatorEntry(e){return Object.prototype.hasOwnProperty.call(w,e)}function systemColumnFilterTarget(e){let t=Object.prototype.hasOwnProperty.call(U,e)?U[e]:void 0;return t?{target:e,attribute:e,operators:t,offered:offeredOn(e,t)}:void 0}function filterOperatorsOfType(e){return isAttributeType(e)?getAttributeFilterOperators({type:e}):[]}function isAttributeType(e){return se.includes(e)}function isLocationPartOperator(e){return V.includes(e)}function carriesEdgeProperties(e){return hasTypeTrait(e.type,`qualified`)}function filterTargetsOf(e){let t=[];for(let n of e){if(n.type===`location`){for(let e of C)t.push(locationPartFilterTarget(n.name,e));continue}if(t.push(attributeFilterTarget(n)),!carriesEdgeProperties(n))continue;let e=n.properties?.definitions;for(let r of e??[])t.push(edgePropertyFilterTarget(n.name,r))}let n=new Set(e.map(e=>e.name));for(let e of Object.keys(U)){if(n.has(e))continue;let r=systemColumnFilterTarget(e);r&&t.push(r)}return t.filter(e=>e.operators.length>0)}const at={eq:`is`,equals:`is`,equal:`is`,"==":`is`,"=":`is`,neq:`is_not`,notEqual:`is_not`,isNot:`is_not`,"!=":`is_not`,"<>":`is_not`,lt:`less_than`,"<":`less_than`,gt:`greater_than`,">":`greater_than`,lte:`less_or_equal`,"<=":`less_or_equal`,gte:`greater_or_equal`,">=":`greater_or_equal`,in:`any_of`,isAnyOf:`any_of`,anyOf:`any_of`,oneOf:`any_of`,notIn:`none_of`,not_in:`none_of`,isNoneOf:`none_of`,noneOf:`none_of`,notOneOf:`none_of`,startsWith:`starts_with`,beginsWith:`starts_with`,endsWith:`ends_with`,doesNotContain:`not_contains`,notContain:`not_contains`,isEmpty:`is_empty`,isNotEmpty:`is_not_empty`};function normalizeOperator(e){return at[e]??e}function normalizeFilterRule(e){let t=normalizeOperator(e.operator);return t===e.operator?e:{...e,operator:t}}const W=864e5,ot=/* @__PURE__ */ new Set([`days`,`weeks`,`months`,`years`]),st=/* @__PURE__ */ new Set([`past`,`future`]);function isRelativeDateValue(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.amount==`number`&&Number.isFinite(t.amount)&&t.amount>0&&typeof t.unit==`string`&&ot.has(t.unit)&&typeof t.direction==`string`&&st.has(t.direction)}function utcDayStart(e){return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function shiftUtcDay(e,t,n){if(n===`days`)return e+t*W;if(n===`weeks`)return e+t*7*W;let r=new Date(e),i=r.getUTCFullYear()+(n===`years`?t:0),a=r.getUTCMonth()+(n===`months`?t:0),o=new Date(Date.UTC(i,a+1,0)).getUTCDate();return Date.UTC(i,a,Math.min(r.getUTCDate(),o))}function resolveIsWithinBounds(e,t=/* @__PURE__ */ new Date){if(!isRelativeDateValue(e))return null;let n=utcDayStart(t),r=Math.trunc(e.amount),i=e.direction===`past`?{startMs:shiftUtcDay(n,-r,e.unit),endMs:n+W}:{startMs:n,endMs:shiftUtcDay(n,r,e.unit)+W};return Number.isFinite(i.startMs)&&Number.isFinite(i.endMs)?i:null}function resolveUtcDayBounds(e){if(!Number.isFinite(e))return null;let t=utcDayStart(new Date(e));return Number.isFinite(t)?{startMs:t,endMs:t+W}:null}function toUtcDayString(e){return new Date(e).toISOString().slice(0,10)}const ct=/* @__PURE__ */ new Set([`relation`,`document`,`user`]),lt={id:`text`,objectId:`text`,objectName:`text`,tenantId:`text`,label:`text`,createdAt:`date`,updatedAt:`date`,deletedAt:`date`,deletedBy:`user`,createdBy:`user`,lastUpdatedBy:`user`,visibility:`select`,ownedBy:`user`,parentId:`text`,childIds:`relation`},G={before:`"less_than"`,after:`"greater_than"`,on_or_before:`"less_or_equal"`,on_or_after:`"greater_or_equal"`,is_checked:`"is" with value true`,is_not_checked:`"is" with value false`,day_month_eq:`"on_day_month"`},ut=new Set(Object.entries(w).filter(([,e])=>e.includes(`any_of`)&&!e.includes(`contains`)).map(([e])=>e)),dt={contains:`any_of`,not_contains:`none_of`};function resolveCanonicalOperator(e,t){let n=G[e];if(n){let t=`Unknown filter operator "${e}" — use ${n}`;throw new p(t,[{path:[`operator`],message:t}])}let r=normalizeOperator(e),i=dt[r];if(i&&ut.has(t)){let e=`Operator "${r}" is not valid for type "${t}" — use "${i}"`;throw new p(e,[{path:[`operator`],message:e}])}return r}function assertPropertyOperator(e,t,n){let r=resolveCanonicalOperator(e,t);if(!n.includes(r)){let r=`Operator "${e}" is not valid for property type "${t}". Valid operators: ${n.length?n.join(`, `):`(no operators registered for this type)`}.`;throw new p(r,[{path:[`operator`],message:r}])}return r}function assertRelativeDateValue(e){if(e.operator===`is_within`&&!isRelativeDateValue(e.value)){let e=`Operator "is_within" requires a relative-date value { amount: positive number, unit: days|weeks|months|years, direction: past|future }`;throw new p(e,[{path:[`value`],message:e}])}}const ft=/^(\d{4}-\d{2}-\d{2})(?:[T ](?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z|[+-](?:(?:0\d|1[0-3])(?::[0-5]\d)?|14(?::00)?))?)?$/,pt=/* @__PURE__ */ new Set([`is`,`is_not`,`less_than`,`less_or_equal`,`greater_than`,`greater_or_equal`]);function assertAbsoluteDateValue(e,t){if(t!==`date`||!pt.has(e.operator))return;let n=e.value;if(n==null||isDynamicValue(n)||typeof n==`string`&&isCastableDay(n))return;let r=`Filter on a date attribute expected a YYYY-MM-DD day, optionally followed by a time, received ${JSON.stringify(n)}`;throw new p(r,[{path:[`value`],message:r}])}function isCastableDay(e){let t=ft.exec(e)?.[1];return!t||t.startsWith(`0000-`)?!1:isCalendarDay(t)}function resolveComparandType(e){return e.type===`formula`&&e.returnType===`date`?`date`:resolveEffectiveFilterType(e)}function applyCanonicalForm(e,t,n){e.operator=t,canonicalizeFilterValue(e,n),assertRelativeDateValue(e),assertAbsoluteDateValue(e,n)}function assertDynamicValueForAttribute(e,t){if(!isDynamicValue(e.value))return;let n=e.value;if(n.dynamic===`actor`&&t!==`user`){let e=`actor token (@me) is only valid on user attributes, not "${t}"`;throw new p(e,[{path:[`value`],message:e}])}if(n.dynamic===`date`&&t!==`date`){let e=`date token (@today/@now) is only valid on date attributes, not "${t}"`;throw new p(e,[{path:[`value`],message:e}])}}const mt=C.map(e=>`"${e}"`).join(`, `);function operatorList(e){return e.length?e.join(`, `):`(not filterable)`}function qualifyWithSchema(e){if(ct.has(e.type))return e.properties}function locationPartsHint(e){return e===`location`?` A location is filtered on one of its parts: set "property" to one of ${mt} and use a text operator (e.g. contains).`:``}function dottedPathHint(e,t,n){let r=` Dotted paths are not supported — `;if(n.type===`location`)return`${r}set "attribute" to "${e}" and "property" to ${isLocationFilterProperty(t)?`"${t}"`:`one of ${mt}`}.`;let i=qualifyWithSchema(n);if(i){let n=i.definitions.map(e=>`"${e.name}"`).join(`, `);return`${r}set "attribute" to "${e}" and "property" to ${i.definitions.some(e=>e.name===t)?`"${t}"`:`one of ${n}`} to filter on the edge property.`}let a=attributeFilterTarget(n).operators;return`${r}${a.length?`set "attribute" to "${e}" and use one of ${a.join(`, `)}`:`"${e}" is not filterable`}; the full-text "query" parameter matches tokens by relevance, not values.`}function collectQualifiedRuleIssues(e,t){try{return validateQualifiedRule({...e},t),[]}catch(e){if(!(e instanceof p))throw e;return e.errors.map(e=>({...e,path:[...e.path]}))}}function validateQualifiedRule(e,t){if(typeof e.attribute!=`string`){let e=`A filter rule needs an attribute: filters are one combinator and a flat list of rules`;throw new p(e,[{path:[`attribute`],message:e}])}let n=t.attributes.find(t=>t.name===e.attribute),r=n?[]:systemColumnFilterTarget(e.attribute)?.operators??[];if(!n&&r.length===0){let[n,...r]=e.attribute.split(`.`),i=r.length>0?t.attributes.find(e=>e.name===n):void 0,a=i?dottedPathHint(n??``,r[0]??``,i):e.attribute.includes(`.`)?` Dotted paths are not supported — filter on the attribute name alone with a structured operator (contains, any_of, …); the full-text "query" parameter matches tokens by relevance, not values.`:``,o=`Unknown attribute: ${e.attribute}${a}`;throw new p(o,[{path:[`attribute`],message:o}])}if(e.quantifier!==void 0&&!e.property){let e=`quantifier is only valid on qualified edge rules (set "property")`;throw new p(e,[{path:[`quantifier`],message:e}])}if(!n){if(e.property)throw new p(`Cannot qualify system attribute "${e.attribute}"`,[{path:[`property`],message:`"${e.attribute}" is a system column, not a reference`}]);let t=lt[e.attribute]??`text`,n=resolveCanonicalOperator(e.operator,t);if(!r.includes(n)){let t=`Operator "${e.operator}" is not valid for system attribute "${e.attribute}". Valid operators: ${r.join(`, `)}.`;throw new p(t,[{path:[`operator`],message:t}])}applyCanonicalForm(e,n,t);return}if(!e.property){assertDynamicValueForAttribute(e,n.type);let t=attributeFilterTarget(n).operators,r=resolveCanonicalOperator(e.operator,n.type);if(!t.includes(r)){let r=`Operator "${e.operator}" is not valid for attribute "${n.name}". Valid operators: ${operatorList(t)}.${locationPartsHint(n.type)}`;throw new p(r,[{path:[`operator`],message:r}])}applyCanonicalForm(e,r,resolveComparandType(n));return}if(n.type===`location`){if(e.quantifier!==void 0){let e=`quantifier is not valid on a location part — a location is one value, not a set of edges`;throw new p(e,[{path:[`quantifier`],message:e}])}if(!isLocationFilterProperty(e.property)){let t=`Property "${e.property}" is not a part of location "${e.attribute}". Valid parts: ${mt}.`;throw new p(t,[{path:[`property`],message:t}])}assertDynamicValueForAttribute(e,`text`);let{operators:t}=locationPartFilterTarget(n.name,e.property);applyCanonicalForm(e,assertPropertyOperator(e.operator,`text`,t),`text`);return}if(!ct.has(n.type))throw new p(`Cannot qualify ${n.type} attribute "${e.attribute}"`,[{path:[`property`],message:`Attribute "${e.attribute}" is not a reference type`}]);let i=n.properties;if(!i)throw new p(`Attribute "${e.attribute}" has no qualifyWith schema`,[{path:[`property`],message:`"${e.attribute}" has no qualifyWith`}]);let a=i.definitions.find(t=>t.name===e.property);if(!a)throw new p(`Property "${e.property}" not defined on "${e.attribute}".qualifyWith()`,[{path:[`property`],message:`Unknown property: ${e.property}`}]);let{operators:o}=edgePropertyFilterTarget(n.name,a);applyCanonicalForm(e,assertPropertyOperator(e.operator,a.type,o),a.type)}const ht=m.array(m.string()).max(a.columnsPerTab),gt=m.array(m.string().min(1)).max(a.columnsPerTab).refine(e=>new Set(e).size===e.length,{message:`Displayed attribute names must be unique`}),_t=m.object({attribute:m.string().describe(`Attribute to sort by`),direction:m.enum([`asc`,`desc`]).describe(`asc or desc`)}).strict(),vt=m.array(_t).max(a.sortsPerTab),yt=m.object({amount:m.number().describe(`Count`),unit:m.enum([`days`,`weeks`,`months`,`years`]).describe(`Unit`),direction:m.enum([`past`,`future`]).describe(`Past or future`)}).strict(),bt=m.object({value:m.number().nullable().describe(`Amount`),code:m.array(m.string()).optional().describe(`Currency codes`)}).strict(),xt=m.object({phoneNumber:m.string().nullable().describe(`Number`),countryCode:m.string().optional().describe(`ISO country code`)}).strict(),St=m.discriminatedUnion(`dynamic`,[m.object({dynamic:m.literal(`actor`).describe(`Resolved at filter time`),ref:m.literal(`current`).describe(`The current actor`)}).strict(),m.object({dynamic:m.literal(`date`).describe(`Resolved at filter time`),anchor:m.enum([`today`,`now`]).describe(`Anchor`)}).strict()]),Ct=m.object({month:m.number().describe(`1-12`),day:m.number().describe(`Day`)}).strict(),wt=m.union([m.string(),m.number(),m.boolean(),m.array(m.string()),yt,bt,xt,Ct,St,m.null()]),Tt=m.enum([`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`ends_with`,`is_empty`,`is_not_empty`,`less_than`,`greater_than`,`less_or_equal`,`greater_or_equal`,`is_within`,`on_day_month`,`any_of`,`none_of`],{error:e=>{let t=e.input,n=typeof t==`string`?G[t]:void 0;return n?`Unknown filter operator "${t}" — use ${n}`:void 0}}),Et=m.object({attribute:m.string().describe(`Attribute to filter on`),property:m.string().optional().describe(`Qualified edge property`),quantifier:m.enum([`any`,`none`]).optional().describe(`For a multi-value attribute`),operator:Tt.describe(`Comparison`),value:wt.describe(`Comparison value, by attribute type`)}).strict(),Dt=m.array(Et).max(a.filterRulesPerTab),Ot=m.object({combinator:m.enum([`and`,`or`]).describe(`Match every rule or any rule`),rules:Dt.describe(`The rules`)}).strict(),kt=m.object({object:m.string().optional().describe(`Every record of this object`),relation:m.string().optional().describe(`Records linked through this relation`)}).strict().superRefine((e,t)=>{e.object===void 0&&e.relation===void 0&&t.addIssue({code:`custom`,message:`Collection source must define an object, a relation, or both`})}).transform(e=>e.relation===void 0?{object:e.object}:e.object===void 0?{relation:e.relation}:{object:e.object,relation:e.relation}),At=m.object({source:kt,filters:Ot.optional(),sorts:vt.optional(),limit:m.number().int().nonnegative().optional()}).strict();var RecordQuery=class{constructor(e){this.state=e}with(e){return new this.constructor({...this.state,...e})}rule(e,t,n){return this.with({rules:[...this.state.rules,{attribute:e,operator:t,value:n}]})}eq(e,t){return this.rule(e,`is`,t)}neq(e,t){return this.rule(e,`is_not`,t)}gt(e,t){return this.rule(e,`greater_than`,t)}gte(e,t){return this.rule(e,`greater_or_equal`,t)}lt(e,t){return this.rule(e,`less_than`,t)}lte(e,t){return this.rule(e,`less_or_equal`,t)}contains(e,t){return this.rule(e,`contains`,t)}notContains(e,t){return this.rule(e,`not_contains`,t)}startsWith(e,t){return this.rule(e,`starts_with`,t)}endsWith(e,t){return this.rule(e,`ends_with`,t)}in(e,t){return this.rule(e,`any_of`,t)}notIn(e,t){return this.rule(e,`none_of`,t)}isEmpty(e){return this.rule(e,`is_empty`,null)}isNotEmpty(e){return this.rule(e,`is_not_empty`,null)}where(...e){return this.with({rules:[...this.state.rules,...e.map(e=>({...e}))]})}or(){return this.with({combinator:`or`})}orderBy(e,t=`asc`){return this.with({sorts:[...this.state.sorts,{attribute:e,direction:t}]})}limit(e){return this.with({limit:e})}offset(e){return this.with({offset:e})}search(e){return this.with({search:e})}related(e){return this.with({scope:{kind:`related`,relation:e}})}relatedFrom(e){return this.with({scope:{kind:`relatedFrom`,relation:e}})}toDefinition(){let{object:e,scope:t,rules:n,combinator:r,sorts:i,limit:a}=this.state;return{source:t?.kind===`related`?{relation:t.relation}:t?.kind===`relatedFrom`?{object:e,relation:t.relation}:{object:e},...n.length>0?{filters:{combinator:r,rules:n.map(e=>({...e}))}}:{},...i.length>0?{sorts:i.map(e=>({...e}))}:{},...a===void 0?{}:{limit:a}}}};function query(e){return new RecordQuery({object:typeof e==`string`?e:e.build().name,combinator:`and`,rules:[],sorts:[]})}const K=[`day`,`week`,`month`,`quarter`,`year`],q=`$query`,jt=`$record`;function createInput(e){return Object.freeze({...e,optional:()=>createInput({...e,isOptional:!0}),inSection:t=>createInput({...e,section:t}),showWhen:(t,n)=>createInput({...e,when:{key:t,...n}}),many:()=>createInput({...e,isMany:!0,schema:m.array(e.schema).min(1)})})}function objectNameOf(e){return e===void 0||typeof e==`string`?e:e.build().name}function scalar(e,t,n){return createInput({kind:e,of:objectNameOf(n),isOptional:!1,isMany:!1,schema:t})}function name(){return m.string().min(1)}const J={object:e=>scalar(`object`,name(),e),attribute:(e,t)=>createInput({kind:`attribute`,of:objectNameOf(e),options:t,isOptional:!1,isMany:!1,schema:name()}),query:e=>scalar(`query`,At,e),record:e=>scalar(`record`,name(),e),agent:()=>scalar(`agent`,name()),routine:()=>scalar(`routine`,name()),view:()=>scalar(`view`,name()),url:()=>scalar(`url`,m.url().refine(e=>/^https?:\/\//.test(e),`Only http(s) links`)),emailCategory:()=>scalar(`emailCategory`,name()),enum:e=>createInput({kind:`enum`,isOptional:!1,isMany:!1,schema:m.enum(e)}),text:()=>scalar(`text`,name()),number:()=>scalar(`number`,m.number()),boolean:()=>scalar(`boolean`,m.boolean()),period:()=>scalar(`period`,m.enum(K))},Y={size:{w:4,h:4},minWidth:3,height:`flexible`,minHeight:3,maxHeight:10},Mt=defineBlock({name:`artifact_preview`,label:`Preview`,icon:`eye`,family:`context`,contexts:[`record`],layout:{size:{w:6,h:8},minWidth:4,height:`flexible`,minHeight:4,maxHeight:20},inputs:{}}),Nt=[`number`,`currency`],Pt=[`status`,`select`,`user`,`relation`,`date`],Ft=[`bar`,`horizontal_bar`,`line`,`area`,`donut`,`funnel`,`treemap`,`calendar`];function measureIssue({measure:e,attribute:t}){return e===`count`?t===void 0?void 0:{input:`attribute`,message:`count measures records; it takes no attribute`}:t===void 0?{input:`attribute`,message:`${String(e)} needs a number or currency attribute`}:void 0}function requires(e,t,n){return e[t]!==void 0&&e[n]===void 0?{input:t,message:`${t} needs ${n}`}:void 0}function together(e,t,n){return requires(e,t,n)??requires(e,n,t)}function kindIssue(e){let{kind:t,by:n,byBucket:r,by2:i,measure:a}=e;if(i!==void 0&&i===n)return{input:`by2`,message:`by2 must differ from by`};if((t===`donut`||t===`funnel`)&&i!==void 0)return{input:`kind`,message:`a ${String(t)} splits one grouping (by), and no second`};if(t===`funnel`&&a!==`count`&&a!==`sum`)return{input:`kind`,message:`a funnel adds stages up: its measure is count or sum`};if(t===`area`&&i===void 0)return{input:`kind`,message:`an area stacks a second grouping (by2); one series is a line`};if(t===`treemap`&&(n===void 0||i!==void 0))return{input:`kind`,message:`a treemap needs one grouping (by), and no second`};if(t===`calendar`&&(r!==`day`||i!==void 0))return{input:`kind`,message:`a calendar needs a date grouping by day, and no second`}}function measuredInputs(){return{query:J.query(),measure:J.enum(e).inSection(`data`),attribute:J.attribute(q,{types:Nt}).optional().showWhen(`measure`,{not:[`count`]}),label:J.text().optional()}}function metricComparePeriod(e){if(e.period)return e.period;if(!e.trendBucket)return`month`;let t=K.indexOf(e.trendBucket);return K[Math.min(t+1,K.length-1)]??`month`}function comparedSpanIssue(e){let{trendBucket:t,compare:n}=e;if(n===void 0||typeof t!=`string`)return;let r=t;if(r===K.at(-1))return{input:`compare`,message:`compare needs a trendBucket finer than year`};let i=metricComparePeriod({trendBucket:r,period:e.period});return K.indexOf(i)>K.indexOf(r)?void 0:{input:`period`,message:`period must be wider than trendBucket (unset, it is one step above)`}}const It=defineBlock({name:`metric`,label:`Indicateur`,icon:`trending-up`,family:`data`,contexts:[`page`,`record`,`display`],layout:{size:{w:3,h:2},minWidth:3,height:`fit`,maxHeight:4,figure:!0},inputs:{...measuredInputs(),trend:J.attribute(q,{types:[`date`]}).optional().inSection(`display`),trendBucket:J.period().optional().showWhen(`trend`),compare:J.enum([`previous_period`]).optional(),period:J.period().optional().showWhen(`compare`),target:J.number().optional()},refine:e=>measureIssue(e)??together(e,`trend`,`trendBucket`)??requires(e,`period`,`compare`)??comparedSpanIssue(e)??(e.target!==void 0&&e.target<=0?{input:`target`,message:`target must be above zero`}:void 0)}),Lt=defineBlock({name:`chart`,label:`Graphique`,icon:`chart-bar`,family:`data`,contexts:[`page`,`record`,`display`],layout:{size:{w:4,h:6},minWidth:4,height:`flexible`,minHeight:4,maxHeight:12},inputs:{...measuredInputs(),kind:J.enum(Ft),by:J.attribute(q,{types:Pt}).optional(),byBucket:J.period().optional().inSection(`data`).showWhen(`by`),by2:J.attribute(q,{types:Pt}).optional().showWhen(`by`),by2Bucket:J.period().optional().inSection(`data`).showWhen(`by2`)},refine:e=>measureIssue(e)??requires(e,`byBucket`,`by`)??requires(e,`by2`,`by`)??requires(e,`by2Bucket`,`by2`)??kindIssue(e)}),Rt=defineBlock({name:`agenda`,label:`Agenda`,icon:`calendar`,family:`data`,contexts:[`page`,`record`,`display`],layout:Y,inputs:{query:J.query(),attribute:J.attribute(q,{types:[`date`]}),next:J.number().optional(),yearly:J.boolean().optional(),label:J.text().optional()}}),zt=defineBlock({name:`card`,label:`Fiche`,icon:`user-square`,family:`data`,contexts:[`page`,`record`,`display`],layout:{size:{w:4,h:4},minWidth:3,height:`fit`,maxHeight:10},inputs:{object:J.object().optional(),record:J.record().optional(),fields:J.attribute(jt).many().optional()},refine:(e,t)=>requires(e,`record`,`object`)??(t===`page`&&e.record===void 0?{input:`record`,message:`A card outside a record shows a chosen record: content.card(object).record(id)`}:void 0)}),Bt=defineBlock({name:`text_block`,label:`Texte`,icon:`type-text`,family:`layout`,contexts:[`page`,`record`,`display`],layout:{size:{w:12,h:2},minWidth:3,height:`fit`,maxHeight:16},inputs:{markdown:J.text()}}),Vt=defineBlock({name:`heading`,label:`Titre`,icon:`type-text`,family:`layout`,contexts:[`page`,`record`],layout:{size:{w:12,h:1},minWidth:6,height:`fit`,maxHeight:3},inputs:{title:J.text(),description:J.text().optional(),icon:J.text().optional()}}),Ht=defineBlock({name:`decisions`,label:`Décisions`,icon:`inbox`,family:`people`,contexts:[`page`],layout:Y,inputs:{kinds:J.enum(n).inSection(`data`).many().optional(),limit:J.number().optional()}}),Ut=defineBlock({name:`meetings_upcoming`,label:`Réunions à venir`,icon:`video`,family:`people`,contexts:[`page`],layout:Y,inputs:{limit:J.number().optional()},refine:({limit:e})=>e===void 0||Number.isInteger(e)&&e>=1&&e<=50?void 0:{input:`limit`,message:`limit is a whole number from 1 to 50`}}),Wt=defineBlock({name:`mailbox`,label:`E-mails`,icon:`envelope`,family:`people`,contexts:[`page`],layout:Y,inputs:{category:J.emailCategory().optional(),important:J.boolean().optional().inSection(`data`),unread:J.boolean().optional().inSection(`data`),limit:J.number().optional(),label:J.text().optional()},refine:({limit:e})=>e===void 0||Number.isInteger(e)&&e>=1&&e<=50?void 0:{input:`limit`,message:`limit is a whole number from 1 to 50`}}),X=defineBlock({name:`record_links`,label:`Bubble`,icon:`share`,family:`context`,contexts:[`record`,`page`],layout:{size:{w:6,h:8},minWidth:6,height:`flexible`,minHeight:6,maxHeight:16},inputs:{center:J.enum([`record`,`me`]).optional().inSection(`data`),object:J.object().optional(),record:J.record().optional(),depth:J.enum([`1`,`2`,`3`,`4`,`5`]).optional()},refine:(e,t)=>requires(e,`record`,`object`)??(t===`page`&&e.center!==`me`&&e.record===void 0?{input:`record`,message:`Links outside a record centre on a chosen record or on the viewer: { object, record } or { center: "me" }`}:void 0)}),Gt={name:`bubble`,type:`custom`,extension:X.name,placement:`main`,label:X.label,icon:X.icon,parameters:{}},Kt=[Mt,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,X],qt=/* @__PURE__ */ new Set([`name`,`label`,`icon`,`family`,`contexts`,`inputs`,`parameters`,`layout`,`refine`]),Jt=Kt;var ContentExtensionRegistry=class{constructor(){this.extensions=/* @__PURE__ */ new Map,this.seed()}register(e){let t=Array.isArray(e)?e:[e],n=/* @__PURE__ */ new Set;t.forEach((e,t)=>{if(this.prepare(e,t),n.has(e.name))throw new f(`content extension`,e.name);n.add(e.name)});for(let e of t)this.extensions.set(e.name,e);return this}prepare(e,t){let n=[`extensions`,String(t)],reject=e=>{throw new p(e,[{path:n,message:e}])};if((typeof e!=`object`||!e||Array.isArray(e))&&reject(`Expected a content extension declaration`),Object.keys(e).some(e=>!qt.has(e))&&reject(`Expected only ${[...qt].join(`, `)}`),(typeof e.name!=`string`||e.name.trim().length===0)&&reject(`API name must not be empty`),(!Array.isArray(e.contexts)||e.contexts.length===0||e.contexts.some(e=>!B.includes(e)))&&reject(`contexts must be a non-empty list of ${B.join(`, `)}`),typeof e.parameters?.safeParse!=`function`&&reject(`parameters must be a Zod schema`),this.extensions.has(e.name))throw new f(`content extension`,e.name)}get(e){return this.extensions.get(e)}has(e){return this.extensions.has(e)}getAll(){return[...this.extensions.values()]}get size(){return this.extensions.size}clear(){this.extensions.clear(),this.seed()}seed(){for(let e of Jt)this.extensions.set(e.name,e)}};const Yt=new ContentExtensionRegistry,Xt=12,Z=[3,4,6,8,9,12];function overlaps(e,t){return e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h}function findGridViolation(e,t={}){let n=Object.entries(e);for(let[e,{x:t,y:r,w:i,h:a}]of n){if(![t,r,i,a].every(Number.isInteger))return{path:[e],message:`Block "${e}" needs integer grid coordinates`};if(t<0||r<0||i<1||a<1)return{path:[e],message:`Block "${e}" needs x >= 0, y >= 0, w >= 1 and h >= 1`};if(t+i>12)return{path:[e],message:`Block "${e}" overflows the 12-column grid (x + w = ${t+i})`}}let r=n.filter(([e])=>t.exempt?.has(e)!==!0);for(let[e,[t,n]]of r.entries())for(let[i,a]of r.slice(e+1))if(overlaps(n,a))return{path:[i],message:`Blocks "${t}" and "${i}" overlap`}}function groupedMembers(e){let t=new Set(e.filter(e=>e.type!==`group`).map(e=>e.name)),n=/* @__PURE__ */ new Set;for(let r of e)if(r.type===`group`)for(let e of r.members)t.has(e)&&n.add(e);return n}function memberlessGroups(e){let t=new Set(e.filter(e=>e.type!==`group`).map(e=>e.name));return new Set(e.flatMap(e=>e.type===`group`&&!e.members.some(e=>t.has(e))?[e.name]:[]))}function groupSizeMessage(e){return e>=2&&e<=a.membersPerGroup?void 0:`A group holds 2 to ${a.membersPerGroup} blocks, not ${e}`}function findGroupViolation(e){let t=new Map(e.map(e=>[e.name,e])),n=/* @__PURE__ */ new Map;for(let r of e)if(r.type===`group`)for(let e of r.members){let i=t.get(e);if(i===void 0)return{path:[r.name],message:`Group "${r.name}" names "${e}", which is not a content of this page`};if(i.type===`group`)return{path:[r.name],message:`Group "${r.name}" cannot hold the group "${e}"`};let a=n.get(e);if(a!==void 0)return{path:[r.name],message:a===r.name?`Group "${r.name}" names "${e}" twice`:`"${e}" already belongs to the group "${a}"`};n.set(e,r.name)}}function boundsOf(e){let{minHeight:t,maxHeight:n}=e;return t!==void 0&&n!==void 0?`${t} to ${n} rows`:t===void 0?`at most ${String(n)} rows`:`at least ${t} rows`}function findRowLimitViolation(e){let t=Object.entries(e).find(([,e])=>e.y+e.h>a.pageRows);if(t===void 0)return;let[n,r]=t;return{path:[n],message:`Block "${n}" ends at row ${r.y+r.h}, past the page's ${a.pageRows} rows`}}function cellViolation(e,t,n){if(!Z.includes(t.w))return{path:[e],message:`Block "${e}" width ${t.w} is not one of ${Z.join(`, `)}`};if(t.w<n.minWidth)return{path:[e],message:`Block "${e}" width ${t.w} is below its minimum width ${n.minWidth}`};if(n.height===`flexible`&&(n.minHeight!==void 0&&t.h<n.minHeight||n.maxHeight!==void 0&&t.h>n.maxHeight))return{path:[e],message:`Block "${e}" height ${t.h} is outside its bounds (${boundsOf(n)})`}}function sharesRows(e,t){return e.y<t.y+t.h&&t.y<e.y+e.h}function findLayoutRuleViolation(e,t,n,r=/* @__PURE__ */ new Set){let i=findRowLimitViolation(e);if(i!==void 0)return i;let a=groupedMembers(t),o=Object.entries(e).filter(([e])=>!a.has(e));for(let[e,t]of o){if(r.has(e))continue;let i=cellViolation(e,t,n(e));if(i!==void 0)return i}let[s,c]=o.filter(([e])=>!r.has(e)&&n(e).height===`fill`);if(s!==void 0&&c!==void 0)return{path:[c[0]],message:`Only one block may fill the page: "${s[0]}" and "${c[0]}" both do`};if(s===void 0)return;let[l,u]=s,d=o.find(([e,t])=>e!==l&&sharesRows(t,u));if(d!==void 0)return{path:[l],message:`Block "${l}" fills the page and must be alone in its rows; "${d[0]}" shares them`}}function findRelationAttribute(e,t){return e.attributes.find(e=>e.name===t&&e.type===`relation`)}function relationAcceptsObject(e,t){return e.targets.some(e=>e.object===t||e.object===`*`)}function singleRelationTarget(e){let[t,...n]=e.targets;return t&&n.length===0&&t.object!==`*`?t.object:void 0}function requireSingleRelationTarget(e,t=[e.name,`targets`]){let n=singleRelationTarget(e);if(n===void 0){let n=`Relation "${e.name}" requires one concrete collection target`;throw new p(n,[{path:t,message:n}])}return n}function isCollectionContent(e){return e.type===`collection`}function collectionSourceAddress(e){return e.relation===void 0?{kind:`object`,object:e.object}:e.object===void 0?{kind:`related`,relation:e.relation}:{kind:`relatedFrom`,object:e.object,relation:e.relation}}function collectionSourceAddressOf(e){if(!e||typeof e!=`object`)return;let t=`object`in e?e.object:void 0,n=`relation`in e?e.relation:void 0;if(typeof t==`string`&&typeof n==`string`)return{kind:`relatedFrom`,object:t,relation:n};if(typeof t==`string`&&n===void 0)return{kind:`object`,object:t};if(typeof n==`string`&&t===void 0)return{kind:`related`,relation:n}}function sourcedAttributeOf(e,t){if(t.type===`richtext`)return typeof t.attribute==`string`&&e!==void 0?{object:e,attribute:t.attribute}:void 0;if(t.type!==`collection`)return;let n=collectionSourceAddressOf(t.source);if(n?.kind===`related`)return e===void 0?void 0:{object:e,attribute:n.relation};if(n?.kind===`relatedFrom`)return{object:n.object,attribute:n.relation}}function requireRecordContentContext(e,t,n){if(t!==`record`){let r=`Content "${e}" requires record context. In ${t===`page`?`a standalone page`:`a collection view`} only a collection that lists a whole object, or a custom content that does not require a record, is allowed.`;throw new p(r,[{path:n,message:r}])}}function resolveContentNavigation(e){let t=e.openMode??`page`;return{openMode:t,createMode:e.createMode??t}}function resolveCollectionActions(e,t){return[...new Set(t)].filter(t=>e.actions===void 0||e.actions.includes(t))}const Zt={collection:[`page`,`record`,`display`],group:[`page`,`record`],form:[`record`],activity:[`record`],richtext:[`record`],documents:[`record`],forms:[`record`],emails:[`record`],meetings:[`record`]},Qt={collection:{size:{w:12,h:8},minWidth:6,height:`flexible`,minHeight:4,maxHeight:20},activity:{size:{w:12,h:8},minWidth:6,height:`flexible`},page:{size:{w:12,h:8},minWidth:6,height:`flexible`},group:{size:{w:6,h:4},minWidth:6,height:`flexible`}};function contentReadObjects(e,t,n){if(e.type!==`group`)return[...n(e)];let r=/* @__PURE__ */ new Set;for(let i of e.members){let e=t.get(i);if(e!==void 0&&e.type!==`group`)for(let t of n(e))r.add(t)}return[...r]}function contentPlacementContexts(e,t){return e.type===`custom`?t?.contexts:e.type===`page`||e.type===`collection`&&collectionSourceAddress(e.source).kind!==`object`?[`record`]:Zt[e.type]}function requireContentPlacement(e,t,n,r,i){let a=contentPlacementContexts(e,t);a&&!a.includes(hostPlacementContext(r))&&(requireRecordContentContext(n,r,i),reject(i,`Content "${n}" cannot be placed in a record view or a record page`))}function hostPlacementContext(e){return e===`record`?`record`:`page`}function contentContextOf(e){return e.context===`page`&&e.object!==void 0?`record`:e.context}const $t=/* @__PURE__ */ new WeakSet;function violationOf(e,t,n,r){if(!(e instanceof ee))throw e;let i=e instanceof p?e.errors[0]:void 0;return{key:JSON.stringify([t,n,e.code,$t.has(e)?`Invalid content view`:e.message]),contentName:n,path:i?.path??r,message:e.message,code:e.code,error:e}}const en=systemAttributeMap({name:``});function systemAttributeMap(e){return new Map(s(e).map(e=>[e.name,e]))}function reject(e,t){throw new p(t,[{path:e,message:t}])}function requireName(e,t){e.trim().length===0&&reject(t,`API name must not be empty`)}function indexUnique(e,t,n){let r=/* @__PURE__ */ new Map;return e.forEach((e,i)=>{if(requireName(e.name,[...n,String(i),`name`]),r.has(e.name))throw new f(t,e.name);r.set(e.name,e)}),r}const tn=30;function capped(e,t){let n=e.slice(0,t).join(`, `);return e.length>t?`${n} … and ${e.length-t} more`:n}function attributeInventory(e,t){return t.length===0?`Object "${e}" has no attributes yet.`:`Attributes of "${e}": ${capped(t,30)}`}function requireAttribute(e,t,n,i,a){if(requireName(t,n),!e)return;let o=e.attributes?.get(t)??(e.system??en).get(t);if(!o){if(!e.attributes||r.has(t))return;let i=attributeInventory(e.name,[...e.attributes.keys()]);reject(n,`Unknown attribute "${e.name}.${t}". ${i}${a?.()??``}`)}let s=i===void 0?[]:[i].flat();return s.length>0&&!s.includes(o.type)&&reject(n,`Attribute "${e.name}.${t}" must have type ${s.join(` or `)}`),o}function collectContentViewCatalogue(e,t=`authoring`){let n=e.mode??`published`,r=/* @__PURE__ */ new Map;e.objects.forEach((e,t)=>{if(requireName(e.name,[`objects`,String(t),`name`]),r.has(e.name))throw new f(`object`,e.name);r.set(e.name,{name:e.name,system:systemAttributeMap(e),attributes:indexUnique(e.attributes,`attribute`,[`objects`,String(t),`attributes`])})});let i=/* @__PURE__ */ new Set;(e.reservedObjects??[]).forEach((e,t)=>{let a=[`reservedObjects`,String(t)];requireName(e,a),r.has(e)||(n!==`draft`&&reject(a,`Unresolved reserved object "${e}"`),i.add(e),r.set(e,{name:e}))});let a=indexUnique(e.extensions??[],`extension`,[`extensions`]);function resolveObject(e,t){requireName(e,t);let n=r.get(e);return n||reject(t,`Unknown object "${e}"`),n}function inverseAddresses(e){let t=[];for(let[n,i]of r)if(n!==e)for(let r of i.attributes?.values()??[])r.type===`relation`&&relationAcceptsObject(r,e)&&t.push(`relatedFrom("${n}", "${r.name}")`);return t.sort().slice(0,3)}let authoringSchemaWith=r=>n===`draft`?draftContentViewDefinitionSchemaFor():contentViewDefinitionSchemaFor({traits:t===`structural`?null:(e,t)=>layoutTraitsOf(e,a,t),viewerFiltered:e.viewerFiltered,...r===void 0?{}:{statics:r}}),o=authoringSchemaWith(),s=n===`draft`||t===`structural`?o:contentViewDefinitionSchemaFor({traits:null,viewerFiltered:e.viewerFiltered}),schemaFor=t=>{if(e.authoringViews!==void 0&&!e.authoringViews.has(t))return s;let n=e.staticsOf?.(t);return n===void 0||n.size===0?o:authoringSchemaWith(n)},c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u=[],d=[];function parseView(e,t,n){let r=schemaFor(n).safeParse(e);if(!r.success){let n=new p(invalidViewMessage(e,r.error.issues[0]),r.error.issues.map(e=>({path:[...t,...e.path.map(String)],message:e.message,code:e.code})));throw $t.add(n),n}let i=r.data;requireName(i.name,[...t,`name`]);let a=i.object??``,o=c.get(a)??/* @__PURE__ */ new Set;if(o.has(i.name))throw new f(`view`,`${a}.${i.name}`);if(o.add(i.name),c.set(a,o),i.context!==`page`&&i.default){let e=l.get(i.object)??/* @__PURE__ */ new Set;if(e.has(i.context))throw new f(`default view`,`${i.object}.${i.context}`);e.add(i.context),l.set(i.object,e)}return i}return e.views.forEach((t,n)=>{let r=[`views`,String(n)],i=t,o=`${String(i?.object??`?`)}.${String(i?.name??n)}`,s,c;try{s=parseView(t,r,n),c=s.object===void 0?void 0:resolveObject(s.object,[...r,`object`])}catch(e){u.push(violationOf(e,o,null,r));return}s.contents.forEach((t,i)=>{let l=[...r,`contents`,String(i)];try{requireName(t.name,[...l,`name`]),validateContent(t,l,c,contentContextOf(s),a,resolveObject,inverseAddresses,e.authoringViews?.has(n)===!0)}catch(e){u.push(violationOf(e,o,t.name,l))}}),d.push(s)}),d.forEach((t,n)=>{t.contents.forEach((r,i)=>{if(r.type!==`page`)return;let a=[`views`,String(n),`contents`,String(i),`page`],o=d.find(e=>e.context===`page`&&e.object===r.page.object&&e.name===r.page.name),s=t.context===`page`?`Content "${r.name}" cannot reference a page from a page`:t.object===r.page.object?o||e.complete!==!0?void 0:`Unknown page "${r.page.object}.${r.page.name}"`:`Content "${r.name}" must reference a page of "${String(t.object)}", not of "${r.page.object}"`;s!==void 0&&u.push(violationOf(new p(s,[{path:a,message:s}]),`${String(t.object)}.${t.name}`,r.name,a))})}),{views:d,unresolvedObjects:[...i].sort(),violations:u}}function validateStoredViews(e){let t=collectContentViewCatalogue(e,`structural`).violations[0];if(t)throw t.error}function describeViewIssue(e){let t=e.path.length>0?` (${e.path.map(String).join(`.`)})`:``;return`${e.message}${t}`}function invalidViewMessage(e,t){let n=typeof e==`object`&&e?e:{},r=typeof n.name==`string`?` "${n.name}"`:``,i=typeof n.object==`string`?` of "${n.object}"`:``;return t?`Invalid content view${r}${i}: ${describeViewIssue(t)}`:`Invalid content view${r}${i}`}function validateContentViewCatalogue(e){let{views:t,unresolvedObjects:n,violations:r}=collectContentViewCatalogue(e),i=r[0];if(i)throw i.error;return{views:t,unresolvedObjects:n}}function resolveStoredQuery(e,t,n,{owner:r,requireRecord:i,resolveObject:a,inverseAddresses:o}){let s=collectionSourceAddress(e.source),c,l;if(s.kind===`object`)c=a(s.object,[...t,`source`,`object`]);else if(s.kind===`related`){i();let e=[...t,`source`,`relation`],hint=()=>{if(!r)return``;let e=o(r.name);return e.length===0?``:`. Records pointing at "${r.name}" are addressed from the other side: ${e.join(`, `)}`},n=requireAttribute(r,s.relation,e,`relation`,hint);n?.type===`relation`&&(l=n,c=a(requireSingleRelationTarget(n,e),e))}else{i(),c=a(s.object,[...t,`source`,`object`]);let o=[...t,`source`,`relation`],l=requireAttribute(c,s.relation,o,`relation`);if(l?.type===`relation`&&r&&!relationAcceptsObject(l,r.name)){let e=l.targets.map(e=>`"${e.object}"`).join(`, `);reject(o,`Relation "${s.object}.${s.relation}" targets ${e}, not "${r.name}"`)}e.filters?.combinator===`or`&&reject([...t,`filters`,`combinator`],`${n} addresses "${s.object}" from the far side, so its filters must use the "and" combinator`)}return e.sorts?.forEach((e,n)=>requireAttribute(c,e.attribute,[...t,`sorts`,String(n),`attribute`])),e.filters?.rules.forEach((e,n)=>requireAttribute(c,e.attribute,[...t,`filters`,`rules`,String(n),`attribute`])),{target:c,relationAttribute:l}}function validateBlockReferences(e,t,n,r){let i=Object.entries(e.inputs),a;for(let[o,s]of i){let i=t[o];s.kind===`query`&&i!==void 0&&(a=resolveStoredQuery(i,[...n,o],`Block "${e.name}"`,r).target)}function attributeScope(o){if(o===void 0)return;if(o===`$query`)return a;if(o!==`$record`)return r.resolveObject(o,n);let s=i.find(([,e])=>e.kind===`object`)?.[0],c=s===void 0?void 0:t[s];return typeof c==`string`?r.resolveObject(c,[...n,s??`object`]):(r.owner||reject(n,`Block "${e.name}" names attributes, so it needs an object or a record host`),r.owner)}for(let[e,r]of i){let i=t[e];if(r.kind!==`attribute`||i===void 0)continue;let a=attributeScope(r.of);(Array.isArray(i)?i:[i]).forEach((t,o)=>{if(typeof t!=`string`)return;let s=Array.isArray(i)?[...n,e,String(o)]:[...n,e];requireAttribute(a,t,s,r.options?.types)})}for(let[r,a]of i){let i=a.when?.key,o=i===void 0?void 0:e.inputs[i],s=i===void 0?void 0:t[i];a.kind===`period`&&t[r]!==void 0&&o?.kind===`attribute`&&typeof s==`string`&&requireAttribute(attributeScope(o.of),s,[...n,i??r],[`date`])}}function isBoardGrouping(e){return(e?.type===`status`||e?.type===`select`)&&!e.hidden}function requireBoardGrouping(e,t,n){let r=t.type===`status`||t.type===`select`?`is hidden`:`is a ${t.type}`;isBoardGrouping(t)||reject(n,`A board groups by a visible status or select attribute: "${e}.${t.name}" ${r}`)}function validateContent(e,t,n,r,i,a,o,s){function requireRecord(){requireRecordContentContext(e.name,r,t)}let c={owner:n,requireRecord,resolveObject:a,inverseAddresses:o},l=hostPlacementContext(r);if(e.type===`custom`){let n=i.get(e.extension);n||reject([...t,`extension`],`Unknown extension "${e.extension}"`),contentPlacementContexts(e,n)?.includes(l)||reject([...t,`extension`],`${e.extension} cannot be placed here`);let r=n.parameters.safeParse(structuredClone(e.parameters??{}));if(!r.success)throw new p(`Invalid extension parameters`,r.error.issues.map(e=>({path:[...t,`parameters`,...e.path.map(String)],message:e.message,code:e.code})));let a=r.data,o=n.refine?.(a,l);o&&reject([...t,`parameters`,o.input],o.message),validateBlockReferences(n,a,[...t,`parameters`],c)}else if(requireContentPlacement(e,void 0,e.name,r,t),e.type!==`page`&&e.type!==`group`){if(e.type===`collection`){let{target:n,relationAttribute:r}=resolveStoredQuery(e,t,`Collection "${e.name}"`,c);if(e.columns?.forEach((e,i)=>{let a=[...t,`columns`,String(i)];if(typeof e==`string`){requireAttribute(n,e,a);return}let o=[...a,`relationProperty`];r||reject(o,`Relation property columns require a relation source`),r.properties?.definitions.some(t=>t.name===e.relationProperty)||reject(o,`Unknown relation property "${e.relationProperty}"`)}),e.displayAttributes?.forEach((e,r)=>requireAttribute(n,e,[...t,`displayAttributes`,String(r)])),e.descriptionAttribute!==void 0&&requireAttribute(n,e.descriptionAttribute,[...t,`descriptionAttribute`]),e.layout===`kanban`&&e.groupByAttribute!==void 0){let r=[...t,`groupByAttribute`],i=requireAttribute(n,e.groupByAttribute,r);s&&i&&n&&requireBoardGrouping(n.name,i,r)}}else switch(e.type){case`form`:e.groups.forEach((e,r)=>{let i=[...t,`groups`,String(r)];requireName(e.name,[...i,`name`]),e.fields.forEach((e,t)=>requireAttribute(n,e.attribute,[...i,`fields`,String(t),`attribute`]))});break;case`richtext`:requireAttribute(n,e.attribute,[...t,`attribute`],`richtext`),e.titleAttribute!==void 0&&requireAttribute(n,e.titleAttribute,[...t,`titleAttribute`],`text`);break;case`emails`:case`meetings`:e.emailAttributes.forEach((e,r)=>requireAttribute(n,e,[...t,`emailAttributes`,String(r)],`text`));break;case`documents`:e.relations?.forEach((e,r)=>requireAttribute(n,e,[...t,`relations`,String(r)],`relation`));break;case`forms`:e.objectName!==void 0&&a(e.objectName,[...t,`objectName`]);break;case`activity`:break;default:reject(t,`Unknown content type: ${String(e)}`)}}}const Q=Object.freeze({size:Object.freeze({w:4,h:4}),minWidth:3,height:`flexible`,minHeight:2,figure:!1});function resolveLayout(e){return e===void 0?Q:{size:e.size??Q.size,minWidth:e.minWidth??Q.minWidth,height:e.height??Q.height,...e.minHeight===void 0?{}:{minHeight:e.minHeight},...e.maxHeight===void 0?{}:{maxHeight:e.maxHeight},figure:e.figure??!1}}function baseTraitsOf(e,t){return e.type===`custom`?resolveLayout(t.get(e.extension)?.layout):e.type in Qt?resolveLayout(Qt[e.type]):Q}function widthCovering(e){return Z.find(t=>t>=e)??12}function boundOf(e,t){let n=e.filter(e=>e!==void 0);return n.length===0?void 0:t(...n)}function groupTraitsOf(e){if(e.length===0)return resolveLayout(Qt.group);let sum=t=>e.reduce((e,n)=>e+t(n),0),t={w:widthCovering(sum(e=>e.size.w)),h:Math.max(...e.map(e=>e.size.h))},n=widthCovering(sum(e=>e.minWidth)),r=e.every(e=>e.figure);if(e.every(e=>e.height===`fit`)){let i=boundOf(e.map(e=>e.maxHeight),Math.max);return{size:t,minWidth:n,height:`fit`,...i===void 0?{}:{maxHeight:i},figure:r}}let i=e.filter(e=>e.height!==`fit`),a=boundOf(i.map(e=>e.minHeight),Math.max),o=boundOf(i.map(e=>e.maxHeight),Math.min),s=o===void 0?void 0:Math.max(o,a??o);return{size:t,minWidth:n,height:`flexible`,...a===void 0?{}:{minHeight:a},...s===void 0?{}:{maxHeight:s},figure:r}}function layoutTraitsOf(e,t,n){let r=e.type===`group`?groupTraitsOf(e.members.flatMap(e=>{let r=n?.get(e);return r===void 0||r.type===`group`?[]:[layoutTraitsOf(r,t)]})):baseTraitsOf(e,t);return e.height===void 0?r:{...r,height:e.height}}function pageTraitsOf(e,t){return n=>{let r=e.get(n);return r?layoutTraitsOf(r,t,e):Q}}const nn=1e4;function isPlainJsonObject(e){let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null&&t.constructor?.name===`Object`}function addJsonIssue(e,t,n=[]){e.addIssue({code:`custom`,message:t,path:n})}function pushJsonArrayChildren(e,t,n,r){for(let n of Reflect.ownKeys(e))n!==`length`&&(n===`__proto__`?addJsonIssue(r,`The __proto__ key is not allowed in custom props`,[...t.path,n]):typeof n!=`symbol`&&/^(0|[1-9]\d*)$/.test(n)||addJsonIssue(r,`Arrays cannot contain non-index JSON properties`,[...t.path,n]));for(let i=e.length-1;i>=0;i--){let a=Object.getOwnPropertyDescriptor(e,String(i)),o=[...t.path,i];a&&`value`in a?n.push({kind:`enter`,value:a.value,path:o,depth:t.depth+1}):addJsonIssue(r,`Sparse arrays are not valid JSON values`,o)}}function pushJsonObjectChildren(e,t,n,r){let i=Reflect.ownKeys(e);for(let a=i.length-1;a>=0;a--){let o=i[a],s=[...t.path,o];if(o===`__proto__`){addJsonIssue(r,`The __proto__ key is not allowed in custom props`,s);continue}if(typeof o==`symbol`){addJsonIssue(r,`Symbol keys are not valid JSON keys`,s);continue}let c=Object.getOwnPropertyDescriptor(e,o);c?.enumerable&&`value`in c?n.push({kind:`enter`,value:c.value,path:s,depth:t.depth+1}):addJsonIssue(r,`Custom props must contain enumerable data properties only`,s)}}function validateJsonProps(e,t){if(typeof e!=`object`||!e){addJsonIssue(t,`Expected a plain JSON object`);return}try{if(Array.isArray(e)||!isPlainJsonObject(e)){addJsonIssue(t,`Expected a plain JSON object`);return}}catch{addJsonIssue(t,`Custom props contain an object that cannot be safely inspected`);return}let n=/* @__PURE__ */ new WeakSet,r=[{kind:`enter`,value:e,path:[],depth:0}],i=0;for(;r.length>0;){let e=r.pop();if(!e)break;if(e.kind===`exit`){n.delete(e.value);continue}if(i++,i>nn){addJsonIssue(t,`Custom props cannot exceed ${nn.toLocaleString(`en-US`)} total JSON nodes`,e.path);return}if(e.depth>64){addJsonIssue(t,`Custom props cannot exceed depth 64`,e.path);continue}let a=e.value;if(!(a===null||typeof a==`string`||typeof a==`boolean`||typeof a==`number`&&Number.isFinite(a))){if(typeof a!=`object`)addJsonIssue(t,`Expected a JSON value`,e.path);else if(n.has(a))addJsonIssue(t,`Custom props cannot contain circular references`,e.path);else try{if(Array.isArray(a)){n.add(a),r.push({kind:`exit`,value:a}),pushJsonArrayChildren(a,e,r,t);continue}if(!isPlainJsonObject(a)){addJsonIssue(t,`Expected an array or plain JSON object`,e.path);continue}n.add(a),r.push({kind:`exit`,value:a}),pushJsonObjectChildren(a,e,r,t)}catch{addJsonIssue(t,`Custom props contain an object that cannot be safely inspected`,e.path)}}}}const rn=m.unknown().superRefine(validateJsonProps).transform(e=>e),an={span:m.union([m.literal(1),m.literal(2),m.literal(3),m.literal(4),m.literal(5),m.literal(6),m.literal(7),m.literal(8),m.literal(9),m.literal(10),m.literal(11),m.literal(12)]).optional().describe(`Columns of 12 this field occupies`),label:m.string().optional().describe(`Overrides the attribute's label`),readOnly:m.boolean().optional().describe(`Shows the value, not editable`)},on=m.object({attribute:m.string().describe(`Attribute API name shown by this field`),...an}).strict(),sn=m.object({name:m.string().describe(`Group API name, unique in the form`),label:m.string().describe(`Label people see`),description:m.string().optional().describe(`Extra context under the label`),collapsible:m.boolean().optional().describe(`Whether the group can be collapsed`),collapsed:m.boolean().optional().describe(`Whether the group starts collapsed`),fields:m.array(on).max(a.fieldsPerGroup).describe(`Fields in this group, in order`)}).strict();function refineFormContent(e,t){e.groups.reduce((e,t)=>e+t.fields.length,0)>a.fieldsPerFormTab&&t.addIssue({code:`too_big`,origin:`array`,maximum:a.fieldsPerFormTab,inclusive:!0,message:`A form content can contain at most ${a.fieldsPerFormTab} fields`,path:[`groups`]});let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set;e.groups.forEach((e,i)=>{n.has(e.name)&&t.addIssue({code:`custom`,message:`Duplicate group name "${e.name}"`,path:[`groups`,i,`name`]}),n.add(e.name),e.fields.forEach((e,n)=>{r.has(e.attribute)&&t.addIssue({code:`custom`,message:`Duplicate field attribute "${e.attribute}"`,path:[`groups`,i,`fields`,n,`attribute`]}),r.add(e.attribute)})})}const $={name:m.string().describe(`Content API name, unique in the view`),label:m.string().optional().describe(`Label people see`),icon:c.optional().describe(`Icon name`),placement:m.enum([`main`,`aside`,`grid`]).describe(`main: the tab strip. aside: the side panel. grid: a page block`),height:m.enum([`fit`,`flexible`,`fill`]).optional().describe(`Page block height: fit (content), flexible (between bounds) or fill (whole page, one per page)`)},cn={...$,type:m.literal(`collection`),source:kt.describe(`object: every record; relation: records linked to this record; both: records of object whose relation points at this record`),visibility:m.enum(i).optional().describe(`all: no scope; workspace: every member; private: viewer's own; shared: private records other members shared with the viewer`),columns:m.array(m.union([m.string(),m.object({relationProperty:m.string().refine(e=>e.trim().length>0).describe(`Qualified edge property shown as a column`)}).strict()])).max(a.columnsPerTab).optional().describe(`Table columns, in order`),descriptionAttribute:m.string().optional().describe(`Secondary line under each row's title (list layout)`),displayAttributes:gt.optional().describe(`Attributes shown on each card`),filters:Ot.optional().describe(`Restricts which records show`),sorts:vt.optional().describe(`Sort order`),actions:m.enum([`create`,`update`,`delete`,`attach`,`detach`]).array().optional().describe(`Offered actions; absent = every action, [] = none`),openMode:m.enum([`page`,`peek`]).optional().describe(`page or peek (the record panel)`),createMode:m.enum([`page`,`peek`,`inline`]).optional().describe(`page, peek, or inline (creates without opening)`)},ln=m.object({...cn,layout:m.enum([`table`,`list`,`kanban`]).describe(`table columns, list cards, kanban board grouped by a select/status attribute`),columnSizing:m.record(m.string(),m.number()).optional().describe(`Column widths in pixels, by attribute name`),groupByAttribute:m.string().optional().describe(`Kanban only: the select or status attribute that names the columns`),kanbanColumnOrder:m.array(m.string()).optional().describe(`Kanban: column order by option value`),kanbanColumnVisibility:m.record(m.string(),m.boolean()).optional().describe(`Kanban: which columns are shown`),kanbanPinnedColumns:m.array(m.string()).optional().describe(`Kanban: columns pinned first`)}).strict().superRefine((e,t)=>{let n=[`groupByAttribute`,`kanbanColumnOrder`,`kanbanColumnVisibility`,`kanbanPinnedColumns`];if(e.layout===`kanban`)e.groupByAttribute===void 0&&t.addIssue({code:`custom`,path:[`groupByAttribute`],message:`A kanban layout requires groupByAttribute`});else for(let r of n)e[r]!==void 0&&t.addIssue({code:`custom`,path:[r],message:`Only a kanban layout groups by an attribute`})}),un={...$,type:m.literal(`form`),groups:m.array(sn).max(a.groupsPerFormTab).describe(`Field groups, in order`),formColumns:m.union([m.literal(1),m.literal(2),m.literal(3)]).optional().describe(`Grid columns, 1-3`),density:m.enum([`compact`,`comfortable`,`spacious`]).optional().describe(`Vertical spacing between fields`)},dn=m.object(un).strict().superRefine(refineFormContent),fn=m.object({...un,groups:un.groups.min(1,`A published form content requires at least one group`)}).strict().superRefine(refineFormContent),pn=[ln,m.object({...$,type:m.literal(`group`),placement:m.literal(`grid`).describe(`Always grid`),members:m.array(m.string()).min(1).max(a.membersPerGroup).describe(`Contents side by side`)}).strict(),m.object({...$,type:m.literal(`custom`),extension:m.string().describe(`Name of a registered extension`),parameters:m.lazy(()=>rn).optional().describe(`Extension parameters`)}).strict(),m.object({...$,type:m.literal(`activity`)}).strict(),m.object({...$,type:m.literal(`richtext`),attribute:m.string().describe(`Richtext attribute edited in place`),titleAttribute:m.string().optional().describe(`Text attribute shown as the title`)}).strict(),m.object({...$,type:m.literal(`documents`),allowUpload:m.boolean().optional().describe(`Lets people add files here`),allowRemove:m.boolean().optional().describe(`Lets people remove files here`),hideAttachments:m.boolean().optional().describe(`Hides files attached elsewhere (e.g. emails)`),relations:m.array(m.string()).optional().describe(`Document relations shown; the record's own files if absent`)}).strict(),m.object({...$,type:m.literal(`forms`),objectName:m.string().optional().describe(`Limits to this object's published forms`)}).strict(),m.object({...$,type:m.literal(`emails`),emailAttributes:m.array(m.string()).max(a.emailAttributesPerTab).describe(`Addresses`)}).strict(),m.object({...$,type:m.literal(`meetings`),emailAttributes:m.array(m.string()).max(a.emailAttributesPerTab).describe(`Addresses`)}).strict(),m.object({...$,type:m.literal(`page`),page:m.object({object:m.string().describe(`Its object`),name:m.string().describe(`Its name`)}).strict().describe(`The record page this tab renders`)}).strict()],mn=m.discriminatedUnion(`type`,[dn,...pn]),hn=m.discriminatedUnion(`type`,[fn,...pn]),gn={name:m.string(),label:m.string(),description:m.string().optional(),icon:c.optional()},_n=m.object({x:m.number().describe(`Column`),y:m.number().describe(`Row`),w:m.number().describe(`Width: 3, 4, 6, 8, 9 or 12; x + w ≤ 12`),h:m.number().describe(`Height`)}).strict();function contentViewBaseSchemaFor(e){let t=m.array(e).max(a.tabsPerView);return m.discriminatedUnion(`context`,[m.object({...gn,object:m.string(),context:m.enum([`collection`,`record`]),default:m.boolean().optional(),anchors:m.record(m.string(),m.object({after:m.string()}).strict()).optional(),contents:t}).strict(),m.object({...gn,object:m.string().optional(),context:m.literal(`page`),home:m.boolean().optional(),grid:m.record(m.string(),_n).refine(e=>Object.keys(e).length<=a.tabsPerView,{message:`A page holds at most ${a.tabsPerView} blocks`}),contents:t}).strict()])}const vn=contentViewBaseSchemaFor(mn),yn=contentViewBaseSchemaFor(hn);function registryTraits(e,t){return layoutTraitsOf(e,Yt,t)}function addGroupSizeIssues(e,t){for(let n of e.contents){let e=n.type===`group`?groupSizeMessage(n.members.length):void 0;e&&t.addIssue({code:`custom`,message:e,path:[`contents`]})}}function addDuplicateContentNameIssues(e,t){let n=/* @__PURE__ */ new Set;e.contents.forEach((e,r)=>{n.has(e.name)&&t.addIssue({code:`custom`,message:`Duplicate content name "${e.name}"`,path:[`contents`,r,`name`]}),n.add(e.name)})}function addPlacementIssues(e,t){e.contents.forEach((n,r)=>{let i=n.placement===`grid`;e.context===`page`&&!i&&t.addIssue({code:`custom`,message:`Content "${n.name}" of a page must be placed on the grid`,path:[`contents`,r,`placement`]}),e.context!==`page`&&i&&t.addIssue({code:`custom`,message:`Content "${n.name}" cannot be placed on a grid outside a page`,path:[`contents`,r,`placement`]})})}function addIssue(e,t){e.addIssue({code:`custom`,message:t.message,path:[`grid`,...t.path]})}function addGridIssues(e,t,n,r){if(e.context!==`page`||!e.grid)return;let i=new Set(e.contents.map(e=>e.name)),a=groupedMembers(e.contents);for(let n of i)a.has(n)||Object.hasOwn(e.grid,n)||t.addIssue({code:`custom`,message:`Content "${n}" has no grid position`,path:[`grid`]});let o=Object.keys(e.grid).filter(e=>!i.has(e));for(let e of o)t.addIssue({code:`custom`,message:`Grid position "${e}" matches no content`,path:[`grid`,e]});if(e.home&&e.object!==void 0&&t.addIssue({code:`custom`,message:`Only a standalone page can be the home`,path:[`home`]}),o.length>0)return;let s=findGridViolation(e.grid,{exempt:a});if(s){addIssue(t,s);return}if(n===null)return;let c=findGroupViolation(e.contents);if(c){t.addIssue({code:`custom`,message:c.message,path:[`contents`]});return}let l=new Map(e.contents.map(e=>[e.name,e])),u=findLayoutRuleViolation(e.grid,e.contents,e=>n(l.get(e),l),r);u&&addIssue(t,u)}function draftContentViewDefinitionSchemaFor(){return vn.superRefine((e,t)=>{let n=e;addDuplicateContentNameIssues(n,t),addPlacementIssues(n,t),addGridIssues(n,t,null)})}function contentViewDefinitionSchemaFor(e={}){let t=e.traits===void 0?registryTraits:e.traits;return yn.superRefine((n,r)=>{let i=n;addDuplicateContentNameIssues(i,r),addPlacementIssues(i,r),addGridIssues(i,r,t,e.statics),e.viewerFiltered||addGroupSizeIssues(i,r),n.context!==`page`&&!n.contents.some(e=>e.placement===`main`)&&r.addIssue({code:`custom`,message:`A published view requires at least one main content`,path:[`contents`]})})}const bn=draftContentViewDefinitionSchemaFor(),xn=contentViewDefinitionSchemaFor();export{Rt as AGENDA_BLOCK,Mt as ARTIFACT_PREVIEW_EXTENSION,w as ATTRIBUTE_FILTER_OPERATORS,se as ATTRIBUTE_TYPES,T as ATTRIBUTE_TYPE_DESCRIPTORS,B as BLOCK_CONTEXTS,K as BLOCK_PERIODS,Z as BLOCK_WIDTHS,zt as CARD_BLOCK,Lt as CHART_BLOCK,Ft as CHART_KINDS,de as COMPUTED_RETURN_TYPES,Zt as CONTENT_PLACEMENT_CONTEXTS,Ht as DECISIONS_BLOCK,Q as DEFAULT_LAYOUT_TRAITS,E as DEFAULT_VALIDATION_MESSAGES,Pt as GROUPABLE_ATTRIBUTE_TYPES,Vt as HEADING_BLOCK,tn as INVENTORY_LIMIT,C as LOCATION_FILTER_PROPERTIES,Wt as MAILBOX_BLOCK,Nt as MEASURABLE_ATTRIBUTE_TYPES,Ut as MEETINGS_UPCOMING_BLOCK,It as METRIC_BLOCK,Kt as NATIVE_BLOCKS,ue as NO_VALUE_OPERATORS,le as OPERATORS_BY_TYPE,Xt as PAGE_GRID_COLUMNS,me as QUALIFIED_SEPARATOR,q as QUERY_OBJECT,X as RECORD_LINKS_BLOCK,Gt as RECORD_LINKS_CONTENT,jt as RECORD_OBJECT,ce as RELATION_TARGET_ANY,G as REMOVED_OPERATOR_REPLACEMENTS,RecordQuery,R as SIMPLE_PROPERTY_TYPES,at as SYNONYM_ALIASES,lt as SYSTEM_FILTER_ATTRIBUTE_TYPES,Bt as TEXT_BLOCK,pe as TEXT_FORMAT_PATTERNS,ge as WIRE_OFFERED_BASE_CONFIG,O as WIRE_OMITTED_CONFIG_KEYS,Ye as attributeConfigSchemas,attributeFilterTarget,attributeInventory,blockObjectInputs,buildQualifiedAttribute,canonicalizeFilterValue,capped,collectContentViewCatalogue,collectQualifiedRuleIssues,kt as collectionContentSourceSchema,collectionSourceAddress,collectionSourceAddressOf,ht as columnsSchema,Yt as contentExtensionRegistry,contentReadObjects,xn as contentViewDefinitionSchema,contentViewDefinitionSchemaFor,createAttributeValidator,createFormAttributeValidator,createObjectValidator,currentActor,datePrecisionIssues,defineBlock,describeViewIssue,gt as displayAttributesSchema,bn as draftContentViewDefinitionSchema,draftContentViewDefinitionSchemaFor,edgePropertyFilterTarget,extractCurrencyFilterValue,extractFilterValue,filterOperatorsOfType,Ot as filterStateSchema,filterTargetsOf,findGridViolation,findGroupViolation,findLayoutRuleViolation,findRelationAttribute,findRowLimitViolation,formatPhoneForDisplay,formatZodErrors,getAttributeCapabilities,getAttributeConfigSchema,getAttributeConfigWriteSchema,getAttributeFilterOperators,getIso2,getOperatorPolarity,getRollupFilterOperators,_n as gridPositionSchema,groupSizeMessage,groupedMembers,hasTypeTrait,hasValueKind,inferInverseCardinality,J as input,invalidViewMessage,isAttributeFilterable,isAttributeGroupable,isAttributeKanbanGroupable,isAttributeSearchable,isAttributeSortable,isBilateralRelation,isBoardGrouping,isCalendarDay,isCollectionContent,isDynamicValue,isEmptyValue,isLocationFilterProperty,isLocationPartOperator,isNoValueOperator,isNullishOrEmptyString,isRelativeDateValue,isSetMembershipOperator,isUniversalRelation,isValueKindType,isValuePresent,layoutTraitsOf,locationPartFilterTarget,memberlessGroups,metricComparePeriod,normalizeCountrylessPhoneNumber,normalizeFilterRule,normalizeForEdgeRpc,normalizeOperator,normalizePhoneNumber,now,overlaps,pageTraitsOf,parseAttributeConfig,parseAttributeConfigForCreate,parseAttributeConfigForUpdate,parseBlockParameters,parseQualifiedAttribute,Ve as propertyAttributeSchema,We as propertyAttributeWireSchema,z as propertySchemaSchema,Ge as propertySchemaWireSchema,hn as publishedViewContentDefinitionSchema,query,At as recordQueryDefinitionSchema,refuseForeignKeys,rejectUnknownAttributesOrThrow,relationAcceptsObject,relationTargetsOf,requireContentPlacement,requireRecordContentContext,requireSingleRelationTarget,resolveCollectionActions,resolveContentNavigation,resolveEffectiveFilterType,resolveIsWithinBounds,resolveTextPattern,resolveUtcDayBounds,j as selectOptionWriteSchema,singleRelationTarget,vt as sortsSchema,sourcedAttributeOf,A as statusGroupSchema,ve as statusOptionWriteSchema,systemColumnFilterTarget,toMultiValueOperator,toUtcDayString,today,validateAttribute,validateContentViewCatalogue,validateDraft,validateDraftOrThrow,validateObject,validateObjectOrThrow,validateQualifiedRule,validateStoredViews,wireHiddenTypeConfigMask,wireOmittedConfigKeysFor,withoutUnknownOptionKeys};
|