[{"data":1,"prerenderedAt":2606},["ShallowReactive",2],{"navigation_docs":3,"-docs-core-working-with-content-hooks":478,"-docs-core-working-with-content-hooks-surround":2601},[4,352,446],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Docs",false,"\u002Fdocs\u002Fcore","docs\u002F1.core",[10,35,141,174,195,212,242,318],{"title":11,"icon":6,"path":12,"stem":13,"children":14,"page":6},"Getting Started","\u002Fdocs\u002Fcore\u002Fgetting-started","docs\u002F1.core\u002F1.getting-started",[15,19,23,27,31],{"title":16,"path":17,"stem":18},"Introduction","\u002Fdocs\u002Fcore\u002Fgetting-started\u002Fintroduction","docs\u002F1.core\u002F1.getting-started\u002F1.introduction",{"title":20,"path":21,"stem":22},"Quick Start","\u002Fdocs\u002Fcore\u002Fgetting-started\u002Fquick-start","docs\u002F1.core\u002F1.getting-started\u002F2.quick-start",{"title":24,"path":25,"stem":26},"Add to an Existing Site","\u002Fdocs\u002Fcore\u002Fgetting-started\u002Fexisting-site","docs\u002F1.core\u002F1.getting-started\u002F3.existing-site",{"title":28,"path":29,"stem":30},"Configuration","\u002Fdocs\u002Fcore\u002Fgetting-started\u002Fconfiguration","docs\u002F1.core\u002F1.getting-started\u002F4.configuration",{"title":32,"path":33,"stem":34},"How Tenon works","\u002Fdocs\u002Fcore\u002Fgetting-started\u002Fhow-tenon-works","docs\u002F1.core\u002F1.getting-started\u002F5.how-tenon-works",{"title":36,"icon":6,"path":37,"stem":38,"children":39,"page":6},"Content Modeling","\u002Fdocs\u002Fcore\u002Fcontent-modeling","docs\u002F1.core\u002F2.content-modeling",[40,44,111,115,119],{"title":41,"path":42,"stem":43},"Collections and Globals","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fcollections-and-globals","docs\u002F1.core\u002F2.content-modeling\u002F1.collections-and-globals",{"title":45,"icon":6,"path":46,"stem":47,"children":48},"Fields","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002Findex",[49,51,55,59,63,67,71,75,79,83,87,91,95,99,103,107],{"title":50,"path":46,"stem":47},"Overview",{"title":52,"path":53,"stem":54},"Array","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Farray","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F01.array",{"title":56,"path":57,"stem":58},"Blocks","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fblocks","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F02.blocks",{"title":60,"path":61,"stem":62},"Boolean","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fboolean","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F03.boolean",{"title":64,"path":65,"stem":66},"Date","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fdate","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F04.date",{"title":68,"path":69,"stem":70},"File","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Ffile","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F05.file",{"title":72,"path":73,"stem":74},"Group","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fgroup","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F06.group",{"title":76,"path":77,"stem":78},"Image","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fimage","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F07.image",{"title":80,"path":81,"stem":82},"Link","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Flink","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F08.link",{"title":84,"path":85,"stem":86},"Number","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fnumber","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F09.number",{"title":88,"path":89,"stem":90},"Relation","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Frelation","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F10.relation",{"title":92,"path":93,"stem":94},"Rich text","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Frich-text","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F11.rich-text",{"title":96,"path":97,"stem":98},"Select","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fselect","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F12.select",{"title":100,"path":101,"stem":102},"Size","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fsize","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F13.size",{"title":104,"path":105,"stem":106},"Slug","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Fslug","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F14.slug",{"title":108,"path":109,"stem":110},"Text","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Ffields\u002Ftext","docs\u002F1.core\u002F2.content-modeling\u002F2.fields\u002F15.text",{"title":112,"path":113,"stem":114},"Relations","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Frelations","docs\u002F1.core\u002F2.content-modeling\u002F3.relations",{"title":116,"path":117,"stem":118},"Media","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fmedia","docs\u002F1.core\u002F2.content-modeling\u002F4.media",{"title":120,"icon":6,"path":121,"stem":122,"children":123},"Presets","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fpresets","docs\u002F1.core\u002F2.content-modeling\u002F5.presets\u002Findex",[124,125,129,133,137],{"title":50,"path":121,"stem":122},{"title":126,"path":127,"stem":128},"Menu","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fpresets\u002Fmenu","docs\u002F1.core\u002F2.content-modeling\u002F5.presets\u002F1.menu",{"title":130,"path":131,"stem":132},"Pages","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fpresets\u002Fpages","docs\u002F1.core\u002F2.content-modeling\u002F5.presets\u002F2.pages",{"title":134,"path":135,"stem":136},"Settings","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fpresets\u002Fsettings","docs\u002F1.core\u002F2.content-modeling\u002F5.presets\u002F3.settings",{"title":138,"path":139,"stem":140},"Strings","\u002Fdocs\u002Fcore\u002Fcontent-modeling\u002Fpresets\u002Fstrings","docs\u002F1.core\u002F2.content-modeling\u002F5.presets\u002F4.strings",{"title":142,"icon":6,"path":143,"stem":144,"children":145,"page":6},"Working with Content","\u002Fdocs\u002Fcore\u002Fworking-with-content","docs\u002F1.core\u002F3.working-with-content",[146,150,154,158,162,166,170],{"title":147,"path":148,"stem":149},"Reading","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Freading","docs\u002F1.core\u002F3.working-with-content\u002F1.reading",{"title":151,"path":152,"stem":153},"Writing and Drafts","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fwriting","docs\u002F1.core\u002F3.working-with-content\u002F2.writing",{"title":155,"path":156,"stem":157},"Scheduled publishing","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fscheduled-publishing","docs\u002F1.core\u002F3.working-with-content\u002F3.scheduled-publishing",{"title":159,"path":160,"stem":161},"HTTP API and Client","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fhttp-api-and-client","docs\u002F1.core\u002F3.working-with-content\u002F4.http-api-and-client",{"title":163,"path":164,"stem":165},"Headless","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fheadless","docs\u002F1.core\u002F3.working-with-content\u002F5.headless",{"title":167,"path":168,"stem":169},"Localization","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Flocalization","docs\u002F1.core\u002F3.working-with-content\u002F6.localization",{"title":171,"path":172,"stem":173},"Hooks","\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fhooks","docs\u002F1.core\u002F3.working-with-content\u002F7.hooks",{"title":175,"icon":6,"path":176,"stem":177,"children":178,"page":6},"Building Your Site","\u002Fdocs\u002Fcore\u002Fbuilding-your-site","docs\u002F1.core\u002F4.building-your-site",[179,183,187,191],{"title":180,"path":181,"stem":182},"Pages and SEO","\u002Fdocs\u002Fcore\u002Fbuilding-your-site\u002Fpages-and-seo","docs\u002F1.core\u002F4.building-your-site\u002F1.pages-and-seo",{"title":184,"path":185,"stem":186},"Components","\u002Fdocs\u002Fcore\u002Fbuilding-your-site\u002Fcomponents","docs\u002F1.core\u002F4.building-your-site\u002F2.components",{"title":188,"path":189,"stem":190},"Menus","\u002Fdocs\u002Fcore\u002Fbuilding-your-site\u002Fmenus","docs\u002F1.core\u002F4.building-your-site\u002F3.menus",{"title":192,"path":193,"stem":194},"Live Preview","\u002Fdocs\u002Fcore\u002Fbuilding-your-site\u002Flive-preview","docs\u002F1.core\u002F4.building-your-site\u002F4.live-preview",{"title":196,"icon":6,"path":197,"stem":198,"children":199,"page":6},"Users and Access","\u002Fdocs\u002Fcore\u002Fusers-and-access","docs\u002F1.core\u002F5.users-and-access",[200,204,208],{"title":201,"path":202,"stem":203},"Authentication","\u002Fdocs\u002Fcore\u002Fusers-and-access\u002Fauthentication","docs\u002F1.core\u002F5.users-and-access\u002F1.authentication",{"title":205,"path":206,"stem":207},"Access Control","\u002Fdocs\u002Fcore\u002Fusers-and-access\u002Faccess-control","docs\u002F1.core\u002F5.users-and-access\u002F2.access-control",{"title":209,"path":210,"stem":211},"API Keys","\u002Fdocs\u002Fcore\u002Fusers-and-access\u002Fapi-keys","docs\u002F1.core\u002F5.users-and-access\u002F3.api-keys",{"title":213,"icon":6,"path":214,"stem":215,"children":216},"Customization","\u002Fdocs\u002Fcore\u002Fcustomization","docs\u002F1.core\u002F6.customization\u002Findex",[217,218,222,226,230,234,238],{"title":50,"path":214,"stem":215},{"title":219,"path":220,"stem":221},"Admin","\u002Fdocs\u002Fcore\u002Fcustomization\u002Fadmin","docs\u002F1.core\u002F6.customization\u002F1.admin",{"title":223,"path":224,"stem":225},"Custom Fields","\u002Fdocs\u002Fcore\u002Fcustomization\u002Fcustom-fields","docs\u002F1.core\u002F6.customization\u002F2.custom-fields",{"title":227,"path":228,"stem":229},"Custom Pages and Actions","\u002Fdocs\u002Fcore\u002Fcustomization\u002Fcustom-pages-and-actions","docs\u002F1.core\u002F6.customization\u002F3.custom-pages-and-actions",{"title":231,"path":232,"stem":233},"Styles and UI Libraries","\u002Fdocs\u002Fcore\u002Fcustomization\u002Fstyles-and-ui-libraries","docs\u002F1.core\u002F6.customization\u002F4.styles-and-ui-libraries",{"title":235,"path":236,"stem":237},"Rich Text Extensions","\u002Fdocs\u002Fcore\u002Fcustomization\u002Frich-text-extensions","docs\u002F1.core\u002F6.customization\u002F5.rich-text-extensions",{"title":239,"path":240,"stem":241},"Plugins","\u002Fdocs\u002Fcore\u002Fcustomization\u002Fplugins","docs\u002F1.core\u002F6.customization\u002F6.plugins",{"title":243,"icon":6,"path":244,"stem":245,"children":246},"Operations","\u002Fdocs\u002Fcore\u002Foperations","docs\u002F1.core\u002F7.operations\u002Findex",[247,248,266,288,306,310,314],{"title":50,"path":244,"stem":245},{"title":249,"icon":6,"path":250,"stem":251,"children":252},"Email","\u002Fdocs\u002Fcore\u002Foperations\u002Femail","docs\u002F1.core\u002F7.operations\u002F1.email\u002Findex",[253,254,258,262],{"title":50,"path":250,"stem":251},{"title":255,"path":256,"stem":257},"SMTP","\u002Fdocs\u002Fcore\u002Foperations\u002Femail\u002Fsmtp","docs\u002F1.core\u002F7.operations\u002F1.email\u002F1.smtp",{"title":259,"path":260,"stem":261},"Cloudflare","\u002Fdocs\u002Fcore\u002Foperations\u002Femail\u002Fcloudflare","docs\u002F1.core\u002F7.operations\u002F1.email\u002F2.cloudflare",{"title":263,"path":264,"stem":265},"Custom adapter","\u002Fdocs\u002Fcore\u002Foperations\u002Femail\u002Fcustom-adapter","docs\u002F1.core\u002F7.operations\u002F1.email\u002F3.custom-adapter",{"title":267,"icon":6,"path":268,"stem":269,"children":270},"Jobs","\u002Fdocs\u002Fcore\u002Foperations\u002Fjobs","docs\u002F1.core\u002F7.operations\u002F2.jobs\u002Findex",[271,272,276,280,284],{"title":50,"path":268,"stem":269},{"title":273,"path":274,"stem":275},"Queue jobs","\u002Fdocs\u002Fcore\u002Foperations\u002Fjobs\u002Fqueue-jobs","docs\u002F1.core\u002F7.operations\u002F2.jobs\u002F1.queue-jobs",{"title":277,"path":278,"stem":279},"Recurring jobs","\u002Fdocs\u002Fcore\u002Foperations\u002Fjobs\u002Frecurring-jobs","docs\u002F1.core\u002F7.operations\u002F2.jobs\u002F2.recurring-jobs",{"title":281,"path":282,"stem":283},"The clock","\u002Fdocs\u002Fcore\u002Foperations\u002Fjobs\u002Fclock","docs\u002F1.core\u002F7.operations\u002F2.jobs\u002F3.clock",{"title":285,"path":286,"stem":287},"Manage jobs","\u002Fdocs\u002Fcore\u002Foperations\u002Fjobs\u002Fmanage-jobs","docs\u002F1.core\u002F7.operations\u002F2.jobs\u002F4.manage-jobs",{"title":289,"icon":6,"path":290,"stem":291,"children":292},"Webhooks","\u002Fdocs\u002Fcore\u002Foperations\u002Fwebhooks","docs\u002F1.core\u002F7.operations\u002F3.webhooks\u002Findex",[293,294,298,302],{"title":50,"path":290,"stem":291},{"title":295,"path":296,"stem":297},"Send webhooks","\u002Fdocs\u002Fcore\u002Foperations\u002Fwebhooks\u002Fsend-webhooks","docs\u002F1.core\u002F7.operations\u002F3.webhooks\u002F1.send-webhooks",{"title":299,"path":300,"stem":301},"Receive webhooks","\u002Fdocs\u002Fcore\u002Foperations\u002Fwebhooks\u002Freceive-webhooks","docs\u002F1.core\u002F7.operations\u002F3.webhooks\u002F2.receive-webhooks",{"title":303,"path":304,"stem":305},"Rebuild on publish","\u002Fdocs\u002Fcore\u002Foperations\u002Fwebhooks\u002Frebuild-on-publish","docs\u002F1.core\u002F7.operations\u002F3.webhooks\u002F3.rebuild-on-publish",{"title":307,"path":308,"stem":309},"Backup and Restore","\u002Fdocs\u002Fcore\u002Foperations\u002Fbackup-and-restore","docs\u002F1.core\u002F7.operations\u002F4.backup-and-restore",{"title":311,"path":312,"stem":313},"Lifecycle Hooks","\u002Fdocs\u002Fcore\u002Foperations\u002Flifecycle-hooks","docs\u002F1.core\u002F7.operations\u002F5.lifecycle-hooks",{"title":315,"path":316,"stem":317},"Upgrades and Schema Changes","\u002Fdocs\u002Fcore\u002Foperations\u002Fupgrades-and-schema-changes","docs\u002F1.core\u002F7.operations\u002F6.upgrades-and-schema-changes",{"title":319,"icon":6,"path":320,"stem":321,"children":322,"page":6},"Reference","\u002Fdocs\u002Fcore\u002Freference","docs\u002F1.core\u002F8.reference",[323,326,344,348],{"title":28,"path":324,"stem":325},"\u002Fdocs\u002Fcore\u002Freference\u002Fconfiguration","docs\u002F1.core\u002F8.reference\u002F1.configuration",{"title":327,"icon":6,"path":328,"stem":329,"children":330},"API","\u002Fdocs\u002Fcore\u002Freference\u002Fapi","docs\u002F1.core\u002F8.reference\u002F2.api\u002Findex",[331,332,336,340],{"title":50,"path":328,"stem":329},{"title":333,"path":334,"stem":335},"Local API","\u002Fdocs\u002Fcore\u002Freference\u002Fapi\u002Flocal-api","docs\u002F1.core\u002F8.reference\u002F2.api\u002F1.local-api",{"title":337,"path":338,"stem":339},"Client","\u002Fdocs\u002Fcore\u002Freference\u002Fapi\u002Fclient","docs\u002F1.core\u002F8.reference\u002F2.api\u002F2.client",{"title":341,"path":342,"stem":343},"HTTP routes","\u002Fdocs\u002Fcore\u002Freference\u002Fapi\u002Fhttp-routes","docs\u002F1.core\u002F8.reference\u002F2.api\u002F3.http-routes",{"title":345,"path":346,"stem":347},"Errors and types","\u002Fdocs\u002Fcore\u002Freference\u002Ferrors-and-types","docs\u002F1.core\u002F8.reference\u002F3.errors-and-types",{"title":349,"path":350,"stem":351},"Package exports","\u002Fdocs\u002Fcore\u002Freference\u002Fpackage-exports","docs\u002F1.core\u002F8.reference\u002F4.package-exports",{"title":353,"icon":6,"path":354,"stem":355,"children":356,"page":6},"Guide","\u002Fdocs\u002Fguide","docs\u002F2.guide",[357,383,400,417],{"title":358,"icon":6,"path":359,"stem":360,"children":361},"Frameworks","\u002Fdocs\u002Fguide\u002Fframeworks","docs\u002F2.guide\u002F1.frameworks\u002Findex",[362,363,367,371,375,379],{"title":50,"path":359,"stem":360},{"title":364,"path":365,"stem":366},"Astro","\u002Fdocs\u002Fguide\u002Fframeworks\u002Fastro","docs\u002F2.guide\u002F1.frameworks\u002F1.astro",{"title":368,"path":369,"stem":370},"Nuxt","\u002Fdocs\u002Fguide\u002Fframeworks\u002Fnuxt","docs\u002F2.guide\u002F1.frameworks\u002F2.nuxt",{"title":372,"path":373,"stem":374},"TanStack Start","\u002Fdocs\u002Fguide\u002Fframeworks\u002Ftanstack-start","docs\u002F2.guide\u002F1.frameworks\u002F3.tanstack-start",{"title":376,"path":377,"stem":378},"Standalone","\u002Fdocs\u002Fguide\u002Fframeworks\u002Fstandalone","docs\u002F2.guide\u002F1.frameworks\u002F4.standalone",{"title":380,"path":381,"stem":382},"Other Frameworks","\u002Fdocs\u002Fguide\u002Fframeworks\u002Fother-frameworks","docs\u002F2.guide\u002F1.frameworks\u002F5.other-frameworks",{"title":384,"icon":6,"path":385,"stem":386,"children":387},"Deployment","\u002Fdocs\u002Fguide\u002Fdeployment","docs\u002F2.guide\u002F2.deployment\u002Findex",[388,389,393,397],{"title":50,"path":385,"stem":386},{"title":390,"path":391,"stem":392},"Node","\u002Fdocs\u002Fguide\u002Fdeployment\u002Fnode","docs\u002F2.guide\u002F2.deployment\u002F1.node",{"title":394,"path":395,"stem":396},"Vercel","\u002Fdocs\u002Fguide\u002Fdeployment\u002Fvercel","docs\u002F2.guide\u002F2.deployment\u002F2.vercel",{"title":259,"path":398,"stem":399},"\u002Fdocs\u002Fguide\u002Fdeployment\u002Fcloudflare","docs\u002F2.guide\u002F2.deployment\u002F3.cloudflare",{"title":401,"icon":6,"path":402,"stem":403,"children":404,"page":6},"Databases and Storage","\u002Fdocs\u002Fguide\u002Fdatabases-and-storage","docs\u002F2.guide\u002F3.databases-and-storage",[405,409,413],{"title":406,"path":407,"stem":408},"Databases","\u002Fdocs\u002Fguide\u002Fdatabases-and-storage\u002Fdatabases","docs\u002F2.guide\u002F3.databases-and-storage\u002F1.databases",{"title":410,"path":411,"stem":412},"Media Storage","\u002Fdocs\u002Fguide\u002Fdatabases-and-storage\u002Fmedia-storage","docs\u002F2.guide\u002F3.databases-and-storage\u002F2.media-storage",{"title":414,"path":415,"stem":416},"Image Providers","\u002Fdocs\u002Fguide\u002Fdatabases-and-storage\u002Fimage-providers","docs\u002F2.guide\u002F3.databases-and-storage\u002F3.image-providers",{"title":418,"icon":6,"path":419,"stem":420,"children":421,"page":6},"Recipes","\u002Fdocs\u002Fguide\u002Frecipes","docs\u002F2.guide\u002F4.recipes",[422,426,430,434,438,442],{"title":423,"path":424,"stem":425},"Seed Content","\u002Fdocs\u002Fguide\u002Frecipes\u002Fseed-content","docs\u002F2.guide\u002F4.recipes\u002F1.seed-content",{"title":427,"path":428,"stem":429},"Tracking and Consent","\u002Fdocs\u002Fguide\u002Frecipes\u002Ftracking-and-consent","docs\u002F2.guide\u002F4.recipes\u002F2.tracking-and-consent",{"title":431,"path":432,"stem":433},"Build a Custom Field","\u002Fdocs\u002Fguide\u002Frecipes\u002Fbuild-a-custom-field","docs\u002F2.guide\u002F4.recipes\u002F3.build-a-custom-field",{"title":435,"path":436,"stem":437},"Write a Plugin","\u002Fdocs\u002Fguide\u002Frecipes\u002Fwrite-a-plugin","docs\u002F2.guide\u002F4.recipes\u002F4.write-a-plugin",{"title":439,"path":440,"stem":441},"Build a Headless Site with Next.js","\u002Fdocs\u002Fguide\u002Frecipes\u002Fbuild-a-headless-site-with-nextjs","docs\u002F2.guide\u002F4.recipes\u002F5.build-a-headless-site-with-nextjs",{"title":443,"path":444,"stem":445},"Troubleshooting","\u002Fdocs\u002Fguide\u002Frecipes\u002Ftroubleshooting","docs\u002F2.guide\u002F4.recipes\u002F6.troubleshooting",{"title":447,"icon":6,"path":448,"stem":449,"children":450,"page":6},"CLI","\u002Fdocs\u002Fcli","docs\u002F3.cli",[451,454,458,462,466,470,474],{"title":50,"path":452,"stem":453},"\u002Fdocs\u002Fcli\u002Foverview","docs\u002F3.cli\u002F1.overview",{"title":455,"path":456,"stem":457},"create-tenoncms","\u002Fdocs\u002Fcli\u002Fcreate-tenoncms","docs\u002F3.cli\u002F2.create-tenoncms",{"title":459,"path":460,"stem":461},"tenon backup","\u002Fdocs\u002Fcli\u002Fbackup","docs\u002F3.cli\u002F3.backup",{"title":463,"path":464,"stem":465},"tenon users","\u002Fdocs\u002Fcli\u002Fusers","docs\u002F3.cli\u002F4.users",{"title":467,"path":468,"stem":469},"tenon media","\u002Fdocs\u002Fcli\u002Fmedia","docs\u002F3.cli\u002F5.media",{"title":471,"path":472,"stem":473},"tenon upgrade","\u002Fdocs\u002Fcli\u002Fupgrade","docs\u002F3.cli\u002F6.upgrade",{"title":475,"path":476,"stem":477},"tenon login","\u002Fdocs\u002Fcli\u002Flogin","docs\u002F3.cli\u002F7.login",{"id":479,"title":171,"body":480,"description":2595,"extension":2596,"links":2597,"meta":2598,"navigation":545,"path":172,"seo":2599,"stem":173,"__hash__":2600},"docs\u002Fdocs\u002F1.core\u002F3.working-with-content\u002F7.hooks.md",{"type":481,"value":482,"toc":2569},"minimark",[483,487,1038,1041,1051,1056,1070,1073,1117,1232,1237,1240,1344,1348,1351,1413,1434,1437,1470,1491,1495,1503,1728,1731,1767,1770,1778,1782,1796,1831,1834,1838,1853,1907,1921,1925,1931,1972,1976,1979,2000,2008,2012,2015,2020,2026,2046,2054,2060,2066,2216,2223,2241,2245,2251,2262,2301,2319,2323,2331,2418,2448,2458,2468,2472,2477,2527,2532,2536,2565],[484,485,486],"p",{},"A hook is a function that Tenon calls at a fixed point of a read, write or delete. Use hooks to change data before it is stored, to check it against other documents, and to react to changes. This collection does all three:",[488,489,495],"pre",{"className":490,"code":491,"filename":492,"language":493,"meta":494,"style":494},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import { defineCollection, ValidationError } from \"tenoncms\";\n\nexport const posts = defineCollection({\n  fields: {\n    title: {\n      type: \"text\",\n      required: true,\n      \u002F\u002F Change data: store the title without spaces at the ends\n      hooks: { beforeChange: [({ value }) => value?.trim()] },\n    },\n    featured: { type: \"boolean\" },\n  },\n  hooks: {\n    beforeChange: {\n      \u002F\u002F Check across documents: only one post can be featured\n      oneFeatured: async ({ data, id, cms }) => {\n        if (!data.featured) return;\n        const other = await cms.findOne(\"posts\", { where: { featured: true } });\n        if (other && other.id !== id) {\n          throw new ValidationError({ featured: \"Another post is already featured\" });\n        }\n      },\n    },\n    afterChange: [\n      \u002F\u002F React to changes\n      ({ doc, operation }) => console.log(`${operation}: ${doc.title}`),\n    ],\n  },\n});\n","cms\u002Fcollections\u002Fposts.ts","ts","",[496,497,498,540,547,572,585,595,613,627,634,679,685,710,716,726,736,742,775,804,862,891,924,930,936,941,952,958,1016,1024,1029],"code",{"__ignoreMap":494},[499,500,503,507,511,515,518,521,524,527,530,534,537],"span",{"class":501,"line":502},"line",1,[499,504,506],{"class":505},"s7zQu","import",[499,508,510],{"class":509},"sMK4o"," {",[499,512,514],{"class":513},"sTEyZ"," defineCollection",[499,516,517],{"class":509},",",[499,519,520],{"class":513}," ValidationError",[499,522,523],{"class":509}," }",[499,525,526],{"class":505}," from",[499,528,529],{"class":509}," \"",[499,531,533],{"class":532},"sfazB","tenoncms",[499,535,536],{"class":509},"\"",[499,538,539],{"class":509},";\n",[499,541,543],{"class":501,"line":542},2,[499,544,546],{"emptyLinePlaceholder":545},true,"\n",[499,548,550,553,557,560,563,566,569],{"class":501,"line":549},3,[499,551,552],{"class":505},"export",[499,554,556],{"class":555},"spNyl"," const",[499,558,559],{"class":513}," posts ",[499,561,562],{"class":509},"=",[499,564,514],{"class":565},"s2Zo4",[499,567,568],{"class":513},"(",[499,570,571],{"class":509},"{\n",[499,573,575,579,582],{"class":501,"line":574},4,[499,576,578],{"class":577},"swJcz","  fields",[499,580,581],{"class":509},":",[499,583,584],{"class":509}," {\n",[499,586,588,591,593],{"class":501,"line":587},5,[499,589,590],{"class":577},"    title",[499,592,581],{"class":509},[499,594,584],{"class":509},[499,596,598,601,603,605,608,610],{"class":501,"line":597},6,[499,599,600],{"class":577},"      type",[499,602,581],{"class":509},[499,604,529],{"class":509},[499,606,607],{"class":532},"text",[499,609,536],{"class":509},[499,611,612],{"class":509},",\n",[499,614,616,619,621,625],{"class":501,"line":615},7,[499,617,618],{"class":577},"      required",[499,620,581],{"class":509},[499,622,624],{"class":623},"sfNiH"," true",[499,626,612],{"class":509},[499,628,630],{"class":501,"line":629},8,[499,631,633],{"class":632},"sHwdD","      \u002F\u002F Change data: store the title without spaces at the ends\n",[499,635,637,640,642,644,647,649,652,655,659,662,665,667,670,673,676],{"class":501,"line":636},9,[499,638,639],{"class":577},"      hooks",[499,641,581],{"class":509},[499,643,510],{"class":509},[499,645,646],{"class":577}," beforeChange",[499,648,581],{"class":509},[499,650,651],{"class":513}," [",[499,653,654],{"class":509},"({",[499,656,658],{"class":657},"sHdIc"," value",[499,660,661],{"class":509}," })",[499,663,664],{"class":555}," =>",[499,666,658],{"class":513},[499,668,669],{"class":509},"?.",[499,671,672],{"class":565},"trim",[499,674,675],{"class":513},"()] ",[499,677,678],{"class":509},"},\n",[499,680,682],{"class":501,"line":681},10,[499,683,684],{"class":509},"    },\n",[499,686,688,691,693,695,698,700,702,705,707],{"class":501,"line":687},11,[499,689,690],{"class":577},"    featured",[499,692,581],{"class":509},[499,694,510],{"class":509},[499,696,697],{"class":577}," type",[499,699,581],{"class":509},[499,701,529],{"class":509},[499,703,704],{"class":532},"boolean",[499,706,536],{"class":509},[499,708,709],{"class":509}," },\n",[499,711,713],{"class":501,"line":712},12,[499,714,715],{"class":509},"  },\n",[499,717,719,722,724],{"class":501,"line":718},13,[499,720,721],{"class":577},"  hooks",[499,723,581],{"class":509},[499,725,584],{"class":509},[499,727,729,732,734],{"class":501,"line":728},14,[499,730,731],{"class":577},"    beforeChange",[499,733,581],{"class":509},[499,735,584],{"class":509},[499,737,739],{"class":501,"line":738},15,[499,740,741],{"class":632},"      \u002F\u002F Check across documents: only one post can be featured\n",[499,743,745,748,750,753,756,759,761,764,766,769,771,773],{"class":501,"line":744},16,[499,746,747],{"class":565},"      oneFeatured",[499,749,581],{"class":509},[499,751,752],{"class":555}," async",[499,754,755],{"class":509}," ({",[499,757,758],{"class":657}," data",[499,760,517],{"class":509},[499,762,763],{"class":657}," id",[499,765,517],{"class":509},[499,767,768],{"class":657}," cms",[499,770,661],{"class":509},[499,772,664],{"class":555},[499,774,584],{"class":509},[499,776,778,781,784,787,790,793,796,799,802],{"class":501,"line":777},17,[499,779,780],{"class":505},"        if",[499,782,783],{"class":577}," (",[499,785,786],{"class":509},"!",[499,788,789],{"class":513},"data",[499,791,792],{"class":509},".",[499,794,795],{"class":513},"featured",[499,797,798],{"class":577},") ",[499,800,801],{"class":505},"return",[499,803,539],{"class":509},[499,805,807,810,813,816,819,821,823,826,828,830,833,835,837,839,842,844,846,849,851,853,855,857,860],{"class":501,"line":806},18,[499,808,809],{"class":555},"        const",[499,811,812],{"class":513}," other",[499,814,815],{"class":509}," =",[499,817,818],{"class":505}," await",[499,820,768],{"class":513},[499,822,792],{"class":509},[499,824,825],{"class":565},"findOne",[499,827,568],{"class":577},[499,829,536],{"class":509},[499,831,832],{"class":532},"posts",[499,834,536],{"class":509},[499,836,517],{"class":509},[499,838,510],{"class":509},[499,840,841],{"class":577}," where",[499,843,581],{"class":509},[499,845,510],{"class":509},[499,847,848],{"class":577}," featured",[499,850,581],{"class":509},[499,852,624],{"class":623},[499,854,523],{"class":509},[499,856,523],{"class":509},[499,858,859],{"class":577},")",[499,861,539],{"class":509},[499,863,865,867,869,872,875,877,879,882,885,887,889],{"class":501,"line":864},19,[499,866,780],{"class":505},[499,868,783],{"class":577},[499,870,871],{"class":513},"other",[499,873,874],{"class":509}," &&",[499,876,812],{"class":513},[499,878,792],{"class":509},[499,880,881],{"class":513},"id",[499,883,884],{"class":509}," !==",[499,886,763],{"class":513},[499,888,798],{"class":577},[499,890,571],{"class":509},[499,892,894,897,900,902,904,907,909,911,913,916,918,920,922],{"class":501,"line":893},20,[499,895,896],{"class":505},"          throw",[499,898,899],{"class":509}," new",[499,901,520],{"class":565},[499,903,568],{"class":577},[499,905,906],{"class":509},"{",[499,908,848],{"class":577},[499,910,581],{"class":509},[499,912,529],{"class":509},[499,914,915],{"class":532},"Another post is already featured",[499,917,536],{"class":509},[499,919,523],{"class":509},[499,921,859],{"class":577},[499,923,539],{"class":509},[499,925,927],{"class":501,"line":926},21,[499,928,929],{"class":509},"        }\n",[499,931,933],{"class":501,"line":932},22,[499,934,935],{"class":509},"      },\n",[499,937,939],{"class":501,"line":938},23,[499,940,684],{"class":509},[499,942,944,947,949],{"class":501,"line":943},24,[499,945,946],{"class":577},"    afterChange",[499,948,581],{"class":509},[499,950,951],{"class":513}," [\n",[499,953,955],{"class":501,"line":954},25,[499,956,957],{"class":632},"      \u002F\u002F React to changes\n",[499,959,961,964,967,969,972,974,976,979,981,984,986,989,992,995,998,1001,1004,1006,1009,1012,1014],{"class":501,"line":960},26,[499,962,963],{"class":509},"      ({",[499,965,966],{"class":657}," doc",[499,968,517],{"class":509},[499,970,971],{"class":657}," operation",[499,973,661],{"class":509},[499,975,664],{"class":555},[499,977,978],{"class":513}," console",[499,980,792],{"class":509},[499,982,983],{"class":565},"log",[499,985,568],{"class":513},[499,987,988],{"class":509},"`${",[499,990,991],{"class":513},"operation",[499,993,994],{"class":509},"}",[499,996,997],{"class":532},": ",[499,999,1000],{"class":509},"${",[499,1002,1003],{"class":513},"doc",[499,1005,792],{"class":509},[499,1007,1008],{"class":513},"title",[499,1010,1011],{"class":509},"}`",[499,1013,859],{"class":513},[499,1015,612],{"class":509},[499,1017,1019,1022],{"class":501,"line":1018},27,[499,1020,1021],{"class":513},"    ]",[499,1023,612],{"class":509},[499,1025,1027],{"class":501,"line":1026},28,[499,1028,715],{"class":509},[499,1030,1032,1034,1036],{"class":501,"line":1031},29,[499,1033,994],{"class":509},[499,1035,859],{"class":513},[499,1037,539],{"class":509},[484,1039,1040],{},"Hooks run for every call of the local API. The HTTP API and the admin use the local API, so hooks run there too.",[484,1042,1043,1044,1047,1048,792],{},"For checks of a single value, a field's ",[496,1045,1046],{},"validate"," is simpler. See ",[1049,1050,45],"a",{"href":46},[1052,1053,1055],"h2",{"id":1054},"write-a-hook","Write a hook",[484,1057,1058,1059,1062,1063,1065,1066,1069],{},"A hook gets one object and MAY be async. It MAY return a new value for its main argument, like ",[496,1060,1061],{},"value",", ",[496,1064,789],{}," or ",[496,1067,1068],{},"docs",". Returning nothing keeps the value.",[484,1071,1072],{},"You can set hooks in three places:",[1074,1075,1076,1090,1098],"ul",{},[1077,1078,1079,1083,1084,1087,1088,792],"li",{},[1080,1081,1082],"strong",{},"On a field",", in the field's ",[496,1085,1086],{},"hooks",". The hook gets the field's ",[496,1089,1061],{},[1077,1091,1092,1095,1096,792],{},[1080,1093,1094],{},"On a collection or global",", in its ",[496,1097,1086],{},[1077,1099,1100,1106,1107,1109,1110,1065,1113,1116],{},[1080,1101,1102,1103],{},"On ",[496,1104,1105],{},"defineCms()",", in ",[496,1108,1086],{},". These hooks run for every collection and global. ",[496,1111,1112],{},"collection",[496,1114,1115],{},"global"," names the target.",[488,1118,1121],{"className":490,"code":1119,"filename":1120,"language":493,"meta":494,"style":494},"export default defineCms({\n  \u002F\u002F ...\n  hooks: {\n    afterChange: [\n      ({ collection, global, doc }) => console.log(\"changed\", collection ?? global, doc.id),\n    ],\n  },\n});\n","tenon.config.ts",[496,1122,1123,1137,1142,1150,1158,1214,1220,1224],{"__ignoreMap":494},[499,1124,1125,1127,1130,1133,1135],{"class":501,"line":502},[499,1126,552],{"class":505},[499,1128,1129],{"class":505}," default",[499,1131,1132],{"class":565}," defineCms",[499,1134,568],{"class":513},[499,1136,571],{"class":509},[499,1138,1139],{"class":501,"line":542},[499,1140,1141],{"class":632},"  \u002F\u002F ...\n",[499,1143,1144,1146,1148],{"class":501,"line":549},[499,1145,721],{"class":577},[499,1147,581],{"class":509},[499,1149,584],{"class":509},[499,1151,1152,1154,1156],{"class":501,"line":574},[499,1153,946],{"class":577},[499,1155,581],{"class":509},[499,1157,951],{"class":513},[499,1159,1160,1162,1165,1167,1170,1172,1174,1176,1178,1180,1182,1184,1186,1188,1191,1193,1195,1198,1201,1203,1205,1207,1209,1212],{"class":501,"line":587},[499,1161,963],{"class":509},[499,1163,1164],{"class":657}," collection",[499,1166,517],{"class":509},[499,1168,1169],{"class":657}," global",[499,1171,517],{"class":509},[499,1173,966],{"class":657},[499,1175,661],{"class":509},[499,1177,664],{"class":555},[499,1179,978],{"class":513},[499,1181,792],{"class":509},[499,1183,983],{"class":565},[499,1185,568],{"class":513},[499,1187,536],{"class":509},[499,1189,1190],{"class":532},"changed",[499,1192,536],{"class":509},[499,1194,517],{"class":509},[499,1196,1197],{"class":513}," collection ",[499,1199,1200],{"class":509},"??",[499,1202,1169],{"class":513},[499,1204,517],{"class":509},[499,1206,966],{"class":513},[499,1208,792],{"class":509},[499,1210,1211],{"class":513},"id)",[499,1213,612],{"class":509},[499,1215,1216,1218],{"class":501,"line":597},[499,1217,1021],{"class":513},[499,1219,612],{"class":509},[499,1221,1222],{"class":501,"line":615},[499,1223,715],{"class":509},[499,1225,1226,1228,1230],{"class":501,"line":629},[499,1227,994],{"class":509},[499,1229,859],{"class":513},[499,1231,539],{"class":509},[1233,1234,1236],"h3",{"id":1235},"lists-and-records","Lists and records",[484,1238,1239],{},"Each stage takes a list or a record of hooks, and runs them in order. In a record, the keys name the hooks. Code that reuses a collection, like a preset or a plugin, can then leave out one hook and keep the rest:",[488,1241,1243],{"className":490,"code":1242,"language":493,"meta":494,"style":494},"const { oneFeatured, ...rest } = posts.hooks.beforeChange;\n\nconst archive = defineCollection({\n  ...posts,\n  hooks: { ...posts.hooks, beforeChange: rest },\n});\n",[496,1244,1245,1281,1285,1300,1309,1336],{"__ignoreMap":494},[499,1246,1247,1250,1252,1255,1257,1260,1263,1265,1267,1270,1272,1274,1276,1279],{"class":501,"line":502},[499,1248,1249],{"class":555},"const",[499,1251,510],{"class":509},[499,1253,1254],{"class":513}," oneFeatured",[499,1256,517],{"class":509},[499,1258,1259],{"class":509}," ...",[499,1261,1262],{"class":513},"rest ",[499,1264,994],{"class":509},[499,1266,815],{"class":509},[499,1268,1269],{"class":513}," posts",[499,1271,792],{"class":509},[499,1273,1086],{"class":513},[499,1275,792],{"class":509},[499,1277,1278],{"class":513},"beforeChange",[499,1280,539],{"class":509},[499,1282,1283],{"class":501,"line":542},[499,1284,546],{"emptyLinePlaceholder":545},[499,1286,1287,1289,1292,1294,1296,1298],{"class":501,"line":549},[499,1288,1249],{"class":555},[499,1290,1291],{"class":513}," archive ",[499,1293,562],{"class":509},[499,1295,514],{"class":565},[499,1297,568],{"class":513},[499,1299,571],{"class":509},[499,1301,1302,1305,1307],{"class":501,"line":574},[499,1303,1304],{"class":509},"  ...",[499,1306,832],{"class":513},[499,1308,612],{"class":509},[499,1310,1311,1313,1315,1317,1319,1321,1323,1325,1327,1329,1331,1334],{"class":501,"line":587},[499,1312,721],{"class":577},[499,1314,581],{"class":509},[499,1316,510],{"class":509},[499,1318,1259],{"class":509},[499,1320,832],{"class":513},[499,1322,792],{"class":509},[499,1324,1086],{"class":513},[499,1326,517],{"class":509},[499,1328,646],{"class":577},[499,1330,581],{"class":509},[499,1332,1333],{"class":513}," rest ",[499,1335,678],{"class":509},[499,1337,1338,1340,1342],{"class":501,"line":597},[499,1339,994],{"class":509},[499,1341,859],{"class":513},[499,1343,539],{"class":509},[1233,1345,1347],{"id":1346},"arguments","Arguments",[484,1349,1350],{},"Every hook gets:",[1074,1352,1353,1366,1376,1382,1388,1395,1404],{},[1077,1354,1355,1358,1359,792],{},[496,1356,1357],{},"cms",": the local API. See ",[1049,1360,1362,1363,1365],{"href":1361},"#use-the-cms-you-receive","Use the ",[496,1364,1357],{}," you receive",[1077,1367,1368,1371,1372,1375],{},[496,1369,1370],{},"user",": the signed-in user of the request, or ",[496,1373,1374],{},"null"," for server code.",[1077,1377,1378,1381],{},[496,1379,1380],{},"apiKey",": the API key of the request, if it has one.",[1077,1383,1384,1387],{},[496,1385,1386],{},"context",": one object that all hooks of an operation share.",[1077,1389,1390,1065,1392,1394],{},[496,1391,1112],{},[496,1393,1115],{},": the name of the target.",[1077,1396,1397,997,1400,1403],{},[496,1398,1399],{},"draft",[496,1401,1402],{},"true"," on a draft save.",[1077,1405,1406,1409,1410,792],{},[496,1407,1408],{},"locale",": the language of the operation, with ",[1049,1411,1412],{"href":168},"localization",[484,1414,1415,1416,1418,1419,1422,1423,1426,1427,1430,1431,792],{},"Field hooks also get ",[496,1417,789],{}," (the whole document), ",[496,1420,1421],{},"siblingData"," (the object that holds the field, like a group), ",[496,1424,1425],{},"originalDoc"," and ",[496,1428,1429],{},"path",", like ",[496,1432,1433],{},"seo.title",[484,1435,1436],{},"The arguments are typed from your fields in these places:",[1074,1438,1439,1456,1461],{},[1077,1440,1441,1426,1444,1447,1448,1062,1450,1062,1452,1426,1454,792],{},[496,1442,1443],{},"defineCollection()",[496,1445,1446],{},"defineGlobal()"," type ",[496,1449,789],{},[496,1451,1003],{},[496,1453,1068],{},[496,1455,1425],{},[1077,1457,1458,1459,792],{},"Field hooks type only ",[496,1460,1061],{},[1077,1462,1463,1464,1466,1467,1469],{},"Hooks on ",[496,1465,1105],{},", and the hooks of a collection written straight into ",[496,1468,1105],{},", are untyped.",[1471,1472,1473,1474,1477,1478,1062,1480,1477,1483,1485,1486,1477,1489,792],"tip",{},"Coming from Payload? The hook names are the same. ",[496,1475,1476],{},"req.user"," is ",[496,1479,1370],{},[496,1481,1482],{},"req.context",[496,1484,1386],{},", and ",[496,1487,1488],{},"req.payload",[496,1490,1357],{},[1052,1492,1494],{"id":1493},"stages-content","Stages (Content)",[484,1496,1497,1498,1502],{},"Each stage runs at one point of an operation. ",[1049,1499,1501],{"href":1500},"#when-hooks-run","When hooks run"," shows the order.",[1504,1505,1506,1525],"table",{},[1507,1508,1509],"thead",{},[1510,1511,1512,1516,1519,1522],"tr",{},[1513,1514,1515],"th",{},"Hook",[1513,1517,1518],{},"Runs",[1513,1520,1521],{},"Main value",[1513,1523,1524],{},"Also gets",[1526,1527,1528,1548,1570,1591,1612,1630,1648,1666,1688,1709],"tbody",{},[1510,1529,1530,1536,1539,1544],{},[1531,1532,1533],"td",{},[496,1534,1535],{},"beforeOperation",[1531,1537,1538],{},"First, in every operation of a collection",[1531,1540,1541],{},[496,1542,1543],{},"args",[1531,1545,1546],{},[496,1547,991],{},[1510,1549,1550,1555,1558,1562],{},[1531,1551,1552],{},[496,1553,1554],{},"beforeValidate",[1531,1556,1557],{},"On a create or update, before validation",[1531,1559,1560],{},[496,1561,789],{},[1531,1563,1564,1062,1566,1062,1568],{},[496,1565,991],{},[496,1567,881],{},[496,1569,1425],{},[1510,1571,1572,1576,1579,1583],{},[1531,1573,1574],{},[496,1575,1278],{},[1531,1577,1578],{},"After validation, before the write",[1531,1580,1581],{},[496,1582,789],{},[1531,1584,1585,1062,1587,1062,1589],{},[496,1586,991],{},[496,1588,881],{},[496,1590,1425],{},[1510,1592,1593,1598,1601,1605],{},[1531,1594,1595],{},[496,1596,1597],{},"afterChange",[1531,1599,1600],{},"After the write. Not on a draft save",[1531,1602,1603],{},[496,1604,1003],{},[1531,1606,1607,1062,1609],{},[496,1608,991],{},[496,1610,1611],{},"previousDoc",[1510,1613,1614,1619,1622,1626],{},[1531,1615,1616],{},[496,1617,1618],{},"beforeRead",[1531,1620,1621],{},"Once per read, before relations load",[1531,1623,1624],{},[496,1625,1068],{},[1531,1627,1628],{},[496,1629,991],{},[1510,1631,1632,1637,1640,1644],{},[1531,1633,1634],{},[496,1635,1636],{},"afterRead",[1531,1638,1639],{},"Once per read, and after each write",[1531,1641,1642],{},[496,1643,1068],{},[1531,1645,1646],{},[496,1647,991],{},[1510,1649,1650,1655,1658,1660],{},[1531,1651,1652],{},[496,1653,1654],{},"beforeDelete",[1531,1656,1657],{},"Before a document is deleted",[1531,1659],{},[1531,1661,1662,1062,1664],{},[496,1663,881],{},[496,1665,1003],{},[1510,1667,1668,1673,1680,1682],{},[1531,1669,1670],{},[496,1671,1672],{},"afterDelete",[1531,1674,1675,1676,1679],{},"After the delete and its ",[496,1677,1678],{},"onDelete"," effects",[1531,1681],{},[1531,1683,1684,1062,1686],{},[496,1685,881],{},[496,1687,1003],{},[1510,1689,1690,1695,1698,1703],{},[1531,1691,1692],{},[496,1693,1694],{},"afterOperation",[1531,1696,1697],{},"Last, in every operation of a collection",[1531,1699,1700],{},[496,1701,1702],{},"result",[1531,1704,1705,1062,1707],{},[496,1706,991],{},[496,1708,1543],{},[1510,1710,1711,1716,1719,1721],{},[1531,1712,1713],{},[496,1714,1715],{},"afterError",[1531,1717,1718],{},"After an unexpected error. A write rolls back first",[1531,1720],{},[1531,1722,1723,1062,1726],{},[496,1724,1725],{},"error",[496,1727,991],{},[484,1729,1730],{},"Not every stage exists everywhere:",[1074,1732,1733,1739,1755],{},[1077,1734,1735,1738],{},[1080,1736,1737],{},"Collections"," take every stage.",[1077,1740,1741,1744,1745,1062,1747,1062,1749,1062,1751,1426,1753,792],{},[1080,1742,1743],{},"Globals"," take ",[496,1746,1554],{},[496,1748,1278],{},[496,1750,1597],{},[496,1752,1618],{},[496,1754,1636],{},[1077,1756,1757,1744,1759,1062,1761,1062,1763,1426,1765,792],{},[1080,1758,45],{},[496,1760,1554],{},[496,1762,1278],{},[496,1764,1597],{},[496,1766,1636],{},[1052,1768,1501],{"id":1769},"when-hooks-run",[484,1771,1772,1773,1426,1775,1777],{},"Every operation runs its steps in a fixed order. Globals have no ",[496,1774,1535],{},[496,1776,1694],{},", so they skip the first and the last step.",[1233,1779,1781],{"id":1780},"a-read","A read",[484,1783,1784,1062,1787,1062,1789,1426,1792,1795],{},[496,1785,1786],{},"find",[496,1788,825],{},[496,1790,1791],{},"findById",[496,1793,1794],{},"getGlobal"," run these steps:",[1797,1798,1799,1803,1806,1809,1813,1816,1820,1827],"ol",{},[1077,1800,1801],{},[496,1802,1535],{},[1077,1804,1805],{},"The access rules. A read rule can narrow the query to what the user may see.",[1077,1807,1808],{},"The query",[1077,1810,1811],{},[496,1812,1618],{},[1077,1814,1815],{},"Loading the relations. Each related document runs the read hooks of its own collection.",[1077,1817,1818],{},[496,1819,1636],{},[1077,1821,1822,1823,1826],{},"Removing the fields that the user may not read, then the ",[496,1824,1825],{},"select"," of the read",[1077,1828,1829],{},[496,1830,1694],{},[484,1832,1833],{},"A read opens no transaction.",[1233,1835,1837],{"id":1836},"a-write","A write",[484,1839,1840,1062,1843,1062,1846,1426,1849,1852],{},[496,1841,1842],{},"create",[496,1844,1845],{},"update",[496,1847,1848],{},"setGlobal",[496,1850,1851],{},"publish"," run these steps in one transaction:",[1797,1854,1855,1859,1871,1874,1878,1884,1889,1892,1895,1899,1903],{},[1077,1856,1857],{},[496,1858,1535],{},[1077,1860,1861,1862,1865,1866,1870],{},"The access rules, and the ",[496,1863,1864],{},"updatedAt"," check for ",[1049,1867,1869],{"href":1868},"\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fwriting#edit-conflicts","edit conflicts",". Fields that the user may not change are dropped.",[1077,1872,1873],{},"Default values on create, then slugs",[1077,1875,1876],{},[496,1877,1554],{},[1077,1879,1880,1881,1883],{},"Validation, then the ",[496,1882,1046],{}," functions of the fields",[1077,1885,1886,1888],{},[496,1887,1278],{},", then validation again, so a hook cannot store invalid data",[1077,1890,1891],{},"The checks for unique values and references",[1077,1893,1894],{},"The write",[1077,1896,1897],{},[496,1898,1597],{},[1077,1900,1901],{},[496,1902,1636],{},[1077,1904,1905],{},[496,1906,1694],{},[1908,1909,1910,1911,1913,1914,1917,1918,792],"note",{},"A draft save checks only the value types in steps 5 and 6, and skips step 7 and ",[496,1912,1597],{},". Its hooks get ",[496,1915,1916],{},"draft: true",". The publish later runs every step on the draft, with ",[496,1919,1920],{},"draft: false",[1233,1922,1924],{"id":1923},"a-delete","A delete",[484,1926,1927,1930],{},[496,1928,1929],{},"delete"," runs these steps in one transaction:",[1797,1932,1933,1937,1940,1944,1955,1958,1964,1968],{},[1077,1934,1935],{},[496,1936,1535],{},[1077,1938,1939],{},"The access rules",[1077,1941,1942],{},[496,1943,1654],{},[1077,1945,1946,1947,1950,1951,792],{},"The check for links in rich text and ",[496,1948,1949],{},"link"," fields. See ",[1049,1952,1954],{"href":1953},"\u002Fdocs\u002Fcore\u002Fworking-with-content\u002Fwriting#deletes-and-references","Deletes and references",[1077,1956,1957],{},"The delete",[1077,1959,1960,1961,1963],{},"The ",[496,1962,1678],{}," rule of every relation that points to the document",[1077,1965,1966],{},[496,1967,1672],{},[1077,1969,1970],{},[496,1971,1694],{},[1233,1973,1975],{"id":1974},"several-hooks-at-one-stage","Several hooks at one stage",[484,1977,1978],{},"At each stage, the hooks run in this order:",[1797,1980,1981,1984,1987,1996],{},[1077,1982,1983],{},"The field hooks, in field order. A group's hooks run before the hooks of its fields.",[1077,1985,1986],{},"The hooks of the collection or global.",[1077,1988,1989,1990,1993,1994,792],{},"The hooks of ",[1049,1991,1992],{"href":240},"plugins",", in the order of ",[496,1995,1992],{},[1077,1997,1989,1998,792],{},[496,1999,1105],{},[484,2001,2002,2003,1426,2005,2007],{},"Webhooks are queued after the last ",[496,2004,1597],{},[496,2006,1672],{}," hook, so they see the final document.",[1052,2009,2011],{"id":2010},"inside-the-transaction","Inside the transaction",[484,2013,2014],{},"The hooks of a write or delete run inside its transaction. The operation commits after its last hook.",[1233,2016,1362,2018,1365],{"id":2017},"use-the-cms-you-receive",[496,2019,1357],{},[484,2021,2022,2023,2025],{},"Inside a hook, call other content through the ",[496,2024,1357],{}," argument, not the instance you import:",[1074,2027,2028,2031,2040,2043],{},[1077,2029,2030],{},"It runs in the transaction of the operation. If the operation fails, its changes roll back too.",[1077,2032,2033,2034,2036,2037,2039],{},"It inherits the ",[496,2035,1408],{},", the ",[496,2038,1386],{}," and the drafts or published view of the operation.",[1077,2041,2042],{},"It skips the access rules, like the instance you import.",[1077,2044,2045],{},"It is untyped: names and data are plain strings and records.",[2047,2048,2049,2050,2053],"warning",{},"On a database with one connection, like ",[496,2051,2052],{},":memory:"," libsql, PGlite or a Cloudflare Durable Object, the imported instance waits for the open transaction forever. The request never finishes.",[1233,2055,2057,2058],{"id":2056},"stop-loops-with-context","Stop loops with ",[496,2059,1386],{},[484,2061,2062,2063,2065],{},"A hook that writes to its own collection runs the hooks again. ",[496,2064,1386],{}," is shared by every hook of the operation and every nested call, so it can stop the loop:",[488,2067,2069],{"className":490,"code":2068,"language":493,"meta":494,"style":494},"afterChange: [\n  async ({ doc, cms, context }) => {\n    if (context.counted) return;\n    context.counted = true;\n    await cms.update(\"posts\", doc.id, { views: (doc.views ?? 0) + 1 });\n  },\n],\n",[496,2070,2071,2080,2104,2124,2139,2205,2209],{"__ignoreMap":494},[499,2072,2073,2076,2078],{"class":501,"line":502},[499,2074,1597],{"class":2075},"sBMFI",[499,2077,581],{"class":509},[499,2079,951],{"class":513},[499,2081,2082,2085,2087,2089,2091,2093,2095,2098,2100,2102],{"class":501,"line":542},[499,2083,2084],{"class":555},"  async",[499,2086,755],{"class":509},[499,2088,966],{"class":657},[499,2090,517],{"class":509},[499,2092,768],{"class":657},[499,2094,517],{"class":509},[499,2096,2097],{"class":657}," context",[499,2099,661],{"class":509},[499,2101,664],{"class":555},[499,2103,584],{"class":509},[499,2105,2106,2109,2111,2113,2115,2118,2120,2122],{"class":501,"line":549},[499,2107,2108],{"class":505},"    if",[499,2110,783],{"class":577},[499,2112,1386],{"class":513},[499,2114,792],{"class":509},[499,2116,2117],{"class":513},"counted",[499,2119,798],{"class":577},[499,2121,801],{"class":505},[499,2123,539],{"class":509},[499,2125,2126,2129,2131,2133,2135,2137],{"class":501,"line":574},[499,2127,2128],{"class":513},"    context",[499,2130,792],{"class":509},[499,2132,2117],{"class":513},[499,2134,815],{"class":509},[499,2136,624],{"class":623},[499,2138,539],{"class":509},[499,2140,2141,2144,2146,2148,2150,2152,2154,2156,2158,2160,2162,2164,2166,2168,2170,2173,2175,2177,2179,2181,2184,2187,2191,2193,2196,2199,2201,2203],{"class":501,"line":587},[499,2142,2143],{"class":505},"    await",[499,2145,768],{"class":513},[499,2147,792],{"class":509},[499,2149,1845],{"class":565},[499,2151,568],{"class":577},[499,2153,536],{"class":509},[499,2155,832],{"class":532},[499,2157,536],{"class":509},[499,2159,517],{"class":509},[499,2161,966],{"class":513},[499,2163,792],{"class":509},[499,2165,881],{"class":513},[499,2167,517],{"class":509},[499,2169,510],{"class":509},[499,2171,2172],{"class":577}," views",[499,2174,581],{"class":509},[499,2176,783],{"class":577},[499,2178,1003],{"class":513},[499,2180,792],{"class":509},[499,2182,2183],{"class":513},"views",[499,2185,2186],{"class":509}," ??",[499,2188,2190],{"class":2189},"sbssI"," 0",[499,2192,798],{"class":577},[499,2194,2195],{"class":509},"+",[499,2197,2198],{"class":2189}," 1",[499,2200,523],{"class":509},[499,2202,859],{"class":577},[499,2204,539],{"class":509},[499,2206,2207],{"class":501,"line":597},[499,2208,715],{"class":509},[499,2210,2211,2214],{"class":501,"line":615},[499,2212,2213],{"class":513},"]",[499,2215,612],{"class":509},[1233,2217,2219,2220,2222],{"id":2218},"keep-afterchange-fast","Keep ",[496,2221,1597],{}," fast",[484,2224,2225,2226,2228,2229,2232,2233,2236,2237,2240],{},"A slow ",[496,2227,1597],{}," hook delays the commit. Send calls to other services from a ",[1049,2230,2231],{"href":268},"job"," or a ",[1049,2234,2235],{"href":290},"webhook",". A job that a hook queues with ",[496,2238,2239],{},"cms.jobs.queue()"," joins the transaction, so a rollback removes it too.",[1052,2242,2244],{"id":2243},"errors","Errors",[484,2246,2247,2248,2250],{},"A hook that throws stops the operation. A write rolls back every change, including the changes of nested ",[496,2249,1357],{}," calls.",[484,2252,2253,2254,2257,2258,2261],{},"Throw a ",[496,2255,2256],{},"ValidationError"," for invalid input. Its keys are field paths, and the admin shows each message next to its field. The key ",[496,2259,2260],{},"\"\""," holds a message for the whole document:",[488,2263,2265],{"className":490,"code":2264,"language":493,"meta":494,"style":494},"throw new ValidationError({ \"seo.title\": \"Too long\" });\n",[496,2266,2267],{"__ignoreMap":494},[499,2268,2269,2272,2274,2276,2278,2280,2282,2284,2286,2288,2290,2293,2295,2297,2299],{"class":501,"line":502},[499,2270,2271],{"class":505},"throw",[499,2273,899],{"class":509},[499,2275,520],{"class":565},[499,2277,568],{"class":513},[499,2279,906],{"class":509},[499,2281,529],{"class":509},[499,2283,1433],{"class":577},[499,2285,536],{"class":509},[499,2287,581],{"class":509},[499,2289,529],{"class":509},[499,2291,2292],{"class":532},"Too long",[499,2294,536],{"class":509},[499,2296,523],{"class":509},[499,2298,859],{"class":513},[499,2300,539],{"class":509},[484,2302,2303,2304,2306,2307,2310,2311,2314,2315,2318],{},"Over HTTP, a ",[496,2305,2256],{}," answers ",[496,2308,2309],{},"400"," with ",[496,2312,2313],{},"{ message, errors }",". Any other error answers ",[496,2316,2317],{},"500",", without its message.",[1233,2320,2322],{"id":2321},"unexpected-errors","Unexpected errors",[484,2324,2325,2326,2328,2329,581],{},"An unexpected error runs the ",[496,2327,1715],{}," hooks, after the rollback. The hooks of the collection run first, then the ones of ",[496,2330,1105],{},[488,2332,2334],{"className":490,"code":2333,"filename":1120,"language":493,"meta":494,"style":494},"export default defineCms({\n  \u002F\u002F ...\n  hooks: {\n    afterError: [({ error, operation, collection }) => console.error(operation, collection, error)],\n  },\n});\n",[496,2335,2336,2348,2352,2360,2406,2410],{"__ignoreMap":494},[499,2337,2338,2340,2342,2344,2346],{"class":501,"line":502},[499,2339,552],{"class":505},[499,2341,1129],{"class":505},[499,2343,1132],{"class":565},[499,2345,568],{"class":513},[499,2347,571],{"class":509},[499,2349,2350],{"class":501,"line":542},[499,2351,1141],{"class":632},[499,2353,2354,2356,2358],{"class":501,"line":549},[499,2355,721],{"class":577},[499,2357,581],{"class":509},[499,2359,584],{"class":509},[499,2361,2362,2365,2367,2369,2371,2374,2376,2378,2380,2382,2384,2386,2388,2390,2392,2395,2397,2399,2401,2404],{"class":501,"line":574},[499,2363,2364],{"class":577},"    afterError",[499,2366,581],{"class":509},[499,2368,651],{"class":513},[499,2370,654],{"class":509},[499,2372,2373],{"class":657}," error",[499,2375,517],{"class":509},[499,2377,971],{"class":657},[499,2379,517],{"class":509},[499,2381,1164],{"class":657},[499,2383,661],{"class":509},[499,2385,664],{"class":555},[499,2387,978],{"class":513},[499,2389,792],{"class":509},[499,2391,1725],{"class":565},[499,2393,2394],{"class":513},"(operation",[499,2396,517],{"class":509},[499,2398,1164],{"class":513},[499,2400,517],{"class":509},[499,2402,2403],{"class":513}," error)]",[499,2405,612],{"class":509},[499,2407,2408],{"class":501,"line":587},[499,2409,715],{"class":509},[499,2411,2412,2414,2416],{"class":501,"line":597},[499,2413,994],{"class":509},[499,2415,859],{"class":513},[499,2417,539],{"class":509},[1074,2419,2420,2433,2442],{},[1077,2421,2422,1062,2424,1426,2427,2430,2431,792],{},[496,2423,2256],{},[496,2425,2426],{},"ConflictError",[496,2428,2429],{},"ForbiddenError"," are expected, so they run no ",[496,2432,1715],{},[1077,2434,2435,2436,2438,2439,2441],{},"Only the outer operation runs ",[496,2437,1715],{},". A nested ",[496,2440,1357],{}," call that fails runs none of its own.",[1077,2443,2444,2445,2447],{},"An error inside ",[496,2446,1715],{}," is logged and does not replace the first one.",[484,2449,2450,2451,2457],{},"To report errors to a service like Sentry, use the ",[1049,2452,2454,2455],{"href":2453},"\u002Fdocs\u002Fcore\u002Foperations\u002Flifecycle-hooks#aftererror","lifecycle ",[496,2456,1715],{}," instead. It also sees failed jobs and requests.",[1908,2459,2460,2463,2464,2467],{},[496,2461,2462],{},"cms.import()"," and restoring a backup skip the content hooks. The lifecycle hook ",[496,2465,2466],{},"afterImport"," runs after them.",[1052,2469,2471],{"id":2470},"lifecycle-hooks","Lifecycle hooks",[484,2473,2474,2475,581],{},"The hooks on this page run for content. The CMS itself has four more, set directly on ",[496,2476,1105],{},[1504,2478,2479,2487],{},[1507,2480,2481],{},[1510,2482,2483,2485],{},[1513,2484,1515],{},[1513,2486,1518],{},[1526,2488,2489,2499,2509,2518],{},[1510,2490,2491,2496],{},[1531,2492,2493],{},[496,2494,2495],{},"seed",[1531,2497,2498],{},"Once per database, to fill a new database",[1510,2500,2501,2506],{},[1531,2502,2503],{},[496,2504,2505],{},"onInit",[1531,2507,2508],{},"On every start",[1510,2510,2511,2515],{},[1531,2512,2513],{},[496,2514,2466],{},[1531,2516,2517],{},"After an import or a restore",[1510,2519,2520,2524],{},[1531,2521,2522],{},[496,2523,1715],{},[1531,2525,2526],{},"On every unexpected error",[484,2528,2529,2530,792],{},"See ",[1049,2531,2471],{"href":312},[1052,2533,2535],{"id":2534},"related-resources","Related resources",[1074,2537,2538,2543,2549,2555,2560],{},[1077,2539,2540,2542],{},[1049,2541,2471],{"href":312},": code on start, after imports and on errors.",[1077,2544,2545,2548],{},[1049,2546,2547],{"href":152},"Writing and drafts",": the writes that run these hooks.",[1077,2550,2551,2554],{},[1049,2552,2553],{"href":206},"Access control",": who may read and write, without a hook.",[1077,2556,2557,2559],{},[1049,2558,267],{"href":268},": slow work after a write.",[1077,2561,2562,2564],{},[1049,2563,289],{"href":290},": tell other services about changes.",[2566,2567,2568],"style",{},"html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}",{"title":494,"searchDepth":542,"depth":542,"links":2570},[2571,2575,2576,2582,2590,2593,2594],{"id":1054,"depth":542,"text":1055,"children":2572},[2573,2574],{"id":1235,"depth":549,"text":1236},{"id":1346,"depth":549,"text":1347},{"id":1493,"depth":542,"text":1494},{"id":1769,"depth":542,"text":1501,"children":2577},[2578,2579,2580,2581],{"id":1780,"depth":549,"text":1781},{"id":1836,"depth":549,"text":1837},{"id":1923,"depth":549,"text":1924},{"id":1974,"depth":549,"text":1975},{"id":2010,"depth":542,"text":2011,"children":2583},[2584,2586,2588],{"id":2017,"depth":549,"text":2585},"Use the cms you receive",{"id":2056,"depth":549,"text":2587},"Stop loops with context",{"id":2218,"depth":549,"text":2589},"Keep afterChange fast",{"id":2243,"depth":542,"text":2244,"children":2591},[2592],{"id":2321,"depth":549,"text":2322},{"id":2470,"depth":542,"text":2471},{"id":2534,"depth":542,"text":2535},"Run code when content is read, written or deleted.","md",null,{},{"title":171,"description":2595},"eRkUwyn4gjfxvVGJ8XqcYn-yXYChnDQR97NHYXL0IsE",[2602,2604],{"title":167,"path":168,"stem":169,"description":2603,"children":-1},"Content in several languages, with URLs and fallbacks.",{"title":180,"path":181,"stem":182,"description":2605,"children":-1},"Pages with (nested) URLs, head tags, sitemap and robots.txt.",1795884678199]