/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@content-collections/core@0.15.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import path,{basename,dirname,extname,join,resolve}from"node:path";import{createHash}from"node:crypto";import{existsSync}from"node:fs";import fs,{mkdir,readFile,unlink,writeFile}from"node:fs/promises";import{readFile as readFile$1}from"fs/promises";import{glob}from"tinyglobby";import fs2 from"fs";import path2 from"path";import{build}from"esbuild";import{createRequire}from"module";import{fileURLToPath}from"node:url";import matter from"gray-matter";import{parse,stringify}from"yaml";import camelcase from"camelcase";import pluralize from"pluralize";import picomatch from"picomatch";import os from"node:os";import pLimit from"p-limit";import serializeJs from"serialize-javascript";import{EventEmitter}from"node:events";import chokidar from"chokidar";function createKey(e,t,n){return createHash("sha256").update(e).update(JSON.stringify(t)).update(n).digest("hex")}async function createCacheDirectory(e){existsSync(e)||await mkdir(e,{recursive:!0})}function fileName(e){const t=e.replace(/[^a-z0-9]/gi,"_").toLowerCase(),n=createHash("sha1").update(e).digest("hex").slice(0,12);return`${t.slice(0,24)}_${n}`.replace(/^_([a-f0-9]{12})$/,"$1")}async function readMapping(e){if(existsSync(e))try{return JSON.parse(await readFile(e,"utf-8"))}catch(e){console.error("Failed to parse the cache mapping. We will recreate the cache.")}return{}}async function createCacheManager(e,t){await createCacheDirectory(e);const n=join(e,"mapping.json"),r=await readMapping(n);return{cache:function(n,o){const i=join(e,fileName(n),fileName(o));let s=r[n];s||(s={},r[n]=s);let a=s[o];a||(a=[],s[o]=a);let c=[];return{cacheFn:async(e,n,r)=>{const o=createKey(t,e,r?.key||"");c.push(o);const s=join(i,`${o}.cache`);if((a?.includes(o)||c.includes(o))&&existsSync(s))try{return JSON.parse(await readFile(s,"utf-8"))}catch(e){console.error("Failed to parse the cache file. We will recompute the value.")}const u=await n(e);return existsSync(i)||await mkdir(i,{recursive:!0}),await writeFile(s,JSON.stringify(u)),u},tidyUp:async()=>{const e=a?.filter((e=>!c.includes(e)))||[];for(const t of e){const e=join(i,`${t}.cache`);existsSync(e)&&await unlink(e)}s&&(s[o]=c)}}},flush:async function(){await writeFile(n,JSON.stringify(r))}}}var singleComment=Symbol("singleComment"),multiComment=Symbol("multiComment"),stripWithoutWhitespace=()=>"",stripWithWhitespace=(e,t,n)=>e.slice(t,n).replace(/\S/g," "),isEscaped=(e,t)=>{let n=t-1,r=0;for(;"\\"===e[n];)n-=1,r+=1;return Boolean(r%2)};function stripJsonComments(e,{whitespace:t=!0,trailingCommas:n=!1}={}){if("string"!=typeof e)throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);const r=t?stripWithWhitespace:stripWithoutWhitespace;let o=!1,i=!1,s=0,a="",c="",u=-1;for(let t=0;t<e.length;t++){const l=e[t],d=e[t+1];if(i||'"'!==l||isEscaped(e,t)||(o=!o),!o)if(i||l+d!=="//"){if(i===singleComment&&l+d==="\r\n"){t++,i=!1,a+=r(e,s,t),s=t;continue}if(i===singleComment&&"\n"===l)i=!1,a+=r(e,s,t),s=t;else{if(!i&&l+d==="/*"){a+=e.slice(s,t),s=t,i=multiComment,t++;continue}if(i===multiComment&&l+d==="*/"){t++,i=!1,a+=r(e,s,t+1),s=t+1;continue}n&&!i&&(-1!==u?"}"===l||"]"===l?(a+=e.slice(s,t),c+=r(a,0,1)+a.slice(1),a="",s=t,u=-1):" "!==l&&"\t"!==l&&"\r"!==l&&"\n"!==l&&(a+=e.slice(s,t),s=t,u=-1):","===l&&(c+=a+e.slice(s,t),a="",s=t,u=t))}}else a+=e.slice(s,t),s=t,i=singleComment,t++}return c+a+(i?r(e.slice(s)):e.slice(s))}function jsoncParse(e){try{return new Function("return "+stripJsonComments(e).trim())()}catch(e){return{}}}var req=createRequire(import.meta.url),findUp=(e,t,n=path2.parse(t).root)=>{let r=t;for(;r!==n;){const t=path2.join(r,e);if(fs2.existsSync(t))return t;if(!t.endsWith(".json")){const e=t+".json";if(fs2.existsSync(e))return e}r=path2.dirname(r)}return null},resolveTsConfigFromFile=(e,t)=>path2.isAbsolute(t)?fs2.existsSync(t)?t:null:findUp(t,e),resolveTsConfigFromExtends=(e,t)=>path2.isAbsolute(t)?fs2.existsSync(t)?t:null:t.startsWith(".")?findUp(t,e):req.resolve(t,{paths:[e]}),loadTsConfigInternal=(e=process.cwd(),t="tsconfig.json",n=!1)=>{var r,o;e=path2.resolve(e);const i=n?resolveTsConfigFromExtends(e,t):resolveTsConfigFromFile(e,t);if(!i)return null;const s=jsoncParse(fs2.readFileSync(i,"utf-8")),a=path2.dirname(i);(null==(r=s.compilerOptions)?void 0:r.baseUrl)&&(s.compilerOptions.baseUrl=path2.join(a,s.compilerOptions.baseUrl));let c=[];if(s.extends){const e=Array.isArray(s.extends)?s.extends:[s.extends],t={};for(const n of e){const e=loadTsConfigInternal(a,n,!0);e&&(Object.assign(t,{...null==e?void 0:e.data,compilerOptions:{...t.compilerOptions,...null==(o=null==e?void 0:e.data)?void 0:o.compilerOptions}}),c.push(...e.files))}Object.assign(s,{...t,...s,compilerOptions:{...t.compilerOptions,...s.compilerOptions}})}return delete s.extends,{path:i,data:s,files:[...c,i]}},loadTsConfig=(e,t)=>loadTsConfigInternal(e,t),tsconfigPathsToRegExp=e=>Object.keys(e||{}).map((e=>new RegExp(`^${e.replace(/\*/,".*")}$`))),match=(e,t)=>!!t&&t.some((t=>t instanceof RegExp?t.test(e):e===t||e.startsWith(t+"/")));function tsconfigResolvePaths(e){let t=loadTsConfig(dirname(e));return t||(t=loadTsConfig()),t?.data?.compilerOptions?.paths||{}}const NON_NODE_MODULE_RE=/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;function isCoreImport(e,t){return"@content-collections/core"===e&&"import-statement"===t}function resolveDirname(){return dirname(fileURLToPath(import.meta.url))}function isInternalTest(){return"__yes"===process.env.CC_TEST_INDICATOR}function createExternalsPlugin(e){const t=tsconfigPathsToRegExp(tsconfigResolvePaths(e)),n=resolveDirname();return{name:"external-packages",setup:e=>{e.onResolve({filter:/.*/},(({path:e,kind:r})=>isInternalTest()&&isCoreImport(e,r)?{path:join(n,"index.ts"),external:!0}:match(e,t)?"dynamic-import"===r?{path:e,external:!0}:void 0:NON_NODE_MODULE_RE.test(e)?void 0:{path:e,external:!0}))}}}async function compile(e,t){const n=await build({entryPoints:[e],packages:"external",bundle:!0,platform:"node",format:"esm",plugins:[createExternalsPlugin(e)],outfile:t,metafile:!0});return Object.keys(n.metafile.inputs)}const deprecations={implicitContentProperty:"The implicit addition of a content property to schemas is deprecated.\nPlease add an explicit content property to your schema.\nFor more information, see:\nhttps://content-collections.dev/docs/deprecations/implicit-content-property",collectionsConfigProperty:'The configuration property "collections" is deprecated.\nPlease use "content" instead.\nFor more information, see:\nhttps://content-collections.dev/docs/deprecations/config-collections-property'},_suppressDeprecatedWarnings=[];function suppressDeprecatedWarnings(...e){for(const t of e){if("all"===t)return void _suppressDeprecatedWarnings.push(...Object.keys(deprecations));_suppressDeprecatedWarnings.push(t)}}function deprecated(e,t=console.warn){_suppressDeprecatedWarnings.includes(e)||t(`[CC DEPRECATED]: ${deprecations[e]}`)}const retiredFeatures={legacySchema:"The use of a function as a schema is retired.\nPlease use a StandardSchema compliant library directly.\nFor more information, see:\nhttps://content-collections.dev/docs/deprecations/schema-as-function"};var RetiredFeatureError=class e extends Error{feature;constructor(t){super(`This feature has been removed:\n${retiredFeatures[t]}`),this.feature=t,this.name="RetiredFeatureError",Object.setPrototypeOf(this,e.prototype)}};function retired(e){throw new RetiredFeatureError(e)}var ConfigurationError=class extends Error{type;constructor(e,t){super(t),this.type=e}};const defaultConfigName="content-collection-config.mjs";function resolveCacheDir$1(e,t){return t.cacheDir?t.cacheDir:path.join(path.dirname(e),".content-collections","cache")}function createConfigurationReader(){return async(e,t={configName:defaultConfigName})=>{if(!existsSync(e))throw new ConfigurationError("Read",`configuration file ${e} does not exist`);const n=resolveCacheDir$1(e,t);await fs.mkdir(n,{recursive:!0});const r=path.join(n,t.configName);try{const t=await compile(e,r),{content:n,collections:o,hooks:i,...s}=(await import(`file://${path.resolve(r)}?x=${Date.now()}`)).default;!n&&o&&deprecated("collectionsConfigProperty");const a=createHash("sha256");a.update(await fs.readFile(r,"utf-8"));const c=a.digest("hex");return{...s,collections:n??o??[],hooks:i??{},path:e,inputPaths:t.map((e=>path.resolve(e))),generateTypes:!0,checksum:c}}catch(t){throw new ConfigurationError("Compile",`configuration file ${e} is invalid: ${t}`)}}}function parseYaml(e){return parse(e.trim())}function frontmatter(e){return matter(e,{engines:{yaml:{parse:parseYaml,stringify:stringify}}})}function frontmatterParser(e){const{data:t,content:n}=frontmatter(e);return{...t,content:n.trim()}}function frontmatterOnlyParser(e){const{data:t}=frontmatter(e);return t}const parsers={frontmatter:{hasContent:!0,parse:frontmatterParser},"frontmatter-only":{hasContent:!1,parse:frontmatterOnlyParser},json:{hasContent:!1,parse:JSON.parse},yaml:{hasContent:!1,parse:parseYaml}};function getParser(e){return"string"==typeof e?parsers[e]:e}function defineParser(e){return"function"==typeof e?{hasContent:!1,parse:e}:e}function isValidParser(e){return"string"==typeof e?e in parsers:"hasContent"in e&&"function"==typeof e.parse}function generateTypeName(e){return camelcase(pluralize.singular(e),{pascalCase:!0})}function generateArrayConstName(e){return"all"+pluralize(e.charAt(0).toUpperCase()+e.slice(1))}function generateSingletonConstName(e){return camelcase(e,{pascalCase:!1})}function isDefined(e){return null!=e}function orderByPath(e,t){return e.path.localeCompare(t.path)}function removeChildPaths(e){return Array.from(new Set(e.filter((t=>!e.some((e=>t!==e&&t.startsWith(e)))))))}function posixToNativePath(e){return path.sep!==path.posix.sep?e.replaceAll(path.posix.sep,path.sep):e}function toError(e){return e instanceof Error?e:new Error(String(e))}const skippedSymbol=Symbol("skipped");function isSingleton(e){return"singleton"===e.type}function defineCollection(e){let t=e.typeName;t||(t=generateTypeName(e.name));let n=e.parser;if(n){if(!isValidParser(n))throw new ConfigurationError("Read",`Parser ${n} is not a valid parser`)}else n="frontmatter";let r=e.schema;return r["~standard"]||retired("legacySchema"),{...e,type:"collection",typeName:t,parser:n,schema:r}}function defineSingleton(e){let t=e.typeName;t||(t=generateTypeName(e.name));let n=e.parser;if(n){if(!isValidParser(n))throw new ConfigurationError("Read",`Parser ${n} is not a valid parser`)}else n="frontmatter";let r=e.schema;return r["~standard"]||retired("legacySchema"),{...e,type:"singleton",typeName:t,parser:n,schema:r}}function defineConfig(e){return e}var CollectError=class extends Error{type;constructor(e,t){super(t),this.type=e}};function createCollector(e,t="."){async function n(t){try{return await readFile$1(t,"utf-8")}catch(n){return e.emit("collector:read-error",{filePath:t,error:new CollectError("Read",String(n))}),null}}async function r(r,o){const i=await n(path.join(t,r.directory,o));if(!i)return null;try{return{data:await getParser(r.parser).parse(i),path:o}}catch(t){return e.emit("collector:parse-error",{filePath:path.join(r.directory,o),error:new CollectError("Parse",String(t))}),null}}async function o(r){const o=await n(path.join(t,r.filePath));if(!o){if(r.optional)return null;throw new CollectError("Read",`Singleton file not found at path: ${r.filePath}`)}try{return{data:await getParser(r.parser).parse(o),path:path.basename(r.filePath)}}catch(t){return e.emit("collector:parse-error",{filePath:r.filePath,error:new CollectError("Parse",String(t))}),null}}function i(e){if(e.exclude)return Array.isArray(e.exclude)?e.exclude:[e.exclude]}return{collect:async function(e){const n=e.map((e=>isSingleton(e)?async function(e){const t=await o(e);return{...e,files:t?[t]:[]}}(e):async function(e){const n=path.join(t,e.directory),o=(await glob(Array.isArray(e.include)?e.include:[e.include],{cwd:n,onlyFiles:!0,absolute:!1,ignore:i(e)})).map((t=>r(e,posixToNativePath(t)))),s=await Promise.all(o);return{...e,files:s.filter(isDefined).sort(orderByPath)}}(e)));return await Promise.all(n)},collectFile:async function(e,t){return isSingleton(e)?o(e):r(e,t)}}}function createSynchronizer(e,t,n="."){function r(e,t){const r=path.resolve(n,e);let o=path.resolve(t).slice(r.length);return o.startsWith(path.sep)&&(o=o.slice(path.sep.length)),o}function o(e){return function(e){const r=path.resolve(e);return t.filter((e=>isSingleton(e)?r===path.resolve(n,e.filePath):r.startsWith(path.resolve(n,e.directory))))}(e).map((t=>({collection:t,relativePath:isSingleton(t)?path.basename(t.filePath):r(t.directory,e)}))).filter((({collection:e,relativePath:t})=>!!isSingleton(e)||picomatch.isMatch(t,e.include,{windows:"win32"===process.platform,ignore:e.exclude})))}return{deleted:function(e){const t=o(e);if(0===t.length)return!1;let n=!1;for(const{collection:e,relativePath:r}of t){if(isSingleton(e)){e.files.length>0&&(e.files=[],n=!0);continue}const t=e.files.findIndex((e=>e.path===r));e.files.splice(t,1).length>0&&(n=!0)}return n},changed:async function(t){const n=o(t);if(0===n.length)return!1;let r=!1;for(const{collection:t,relativePath:o}of n){const n=t.files.findIndex((e=>e.path===o)),i=await e(t,o);i&&(r=!0,isSingleton(t)?t.files=[i]:-1===n?(t.files.push(i),t.files.sort(orderByPath)):t.files[n]=i)}return r}}}const NEVER=Object.freeze({status:"aborted"});function $constructor(e,t,n){function r(n,r){var o;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(o=n._zod).traits??(o.traits=new Set),n._zod.traits.add(e),t(n,r);for(const e in s.prototype)e in n||Object.defineProperty(n,e,{value:s.prototype[e].bind(n)});n._zod.constr=s,n._zod.def=r}const o=n?.Parent??Object;class i extends o{}function s(e){var t;const o=n?.Parent?new i:this;r(o,e),(t=o._zod).deferred??(t.deferred=[]);for(const e of o._zod.deferred)e();return o}return Object.defineProperty(i,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}const $brand=Symbol("zod_brand");var $ZodAsyncError=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};const globalConfig={};function config(e){return e&&Object.assign(globalConfig,e),globalConfig}function jsonStringifyReplacer(e,t){return"bigint"==typeof t?t.toString():t}function cached(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function cleanRegex(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const EVALUATING=Symbol("evaluating");function defineLazy(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==EVALUATING)return void 0===r&&(r=EVALUATING,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}const captureStackTrace="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function isObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const allowsEval=cached((()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}}));function isPlainObject(e){if(!1===isObject(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!1!==isObject(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}const propertyKeyTypes=new Set(["string","number","symbol"]);function escapeRegex(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function clone(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function normalizeParams(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}function optionalKeys(e){return Object.keys(e).filter((t=>"optional"===e[t]._zod.optin&&"optional"===e[t]._zod.optout))}const NUMBER_FORMAT_RANGES={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function aborted(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function prefixIssues(e,t){return t.map((t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t}))}function unwrapMessage(e){return"string"==typeof e?e:e?.message}function finalizeIssue(e,t,n){const r={...e,path:e.path??[]};return e.message||(r.message=unwrapMessage(e.inst?._zod.def?.error?.(e))??unwrapMessage(t?.error?.(e))??unwrapMessage(n.customError?.(e))??unwrapMessage(n.localeError?.(e))??"Invalid input"),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}const initializer=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,jsonStringifyReplacer,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},$ZodError=$constructor("$ZodError",initializer),$ZodRealError=$constructor("$ZodError",initializer,{Parent:Error}),_parse=e=>(t,n,r,o)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new $ZodAsyncError;if(s.issues.length){const t=new(o?.Err??e)(s.issues.map((e=>finalizeIssue(e,i,config()))));throw captureStackTrace(t,o?.callee),t}return s.value},parse$1=_parse($ZodRealError),_parseAsync=e=>async(t,n,r,o)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(o?.Err??e)(s.issues.map((e=>finalizeIssue(e,i,config()))));throw captureStackTrace(t,o?.callee),t}return s.value},parseAsync=_parseAsync($ZodRealError),_safeParse=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new $ZodAsyncError;return i.issues.length?{success:!1,error:new(e??$ZodError)(i.issues.map((e=>finalizeIssue(e,o,config()))))}:{success:!0,data:i.value}},safeParse=_safeParse($ZodRealError),_safeParseAsync=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map((e=>finalizeIssue(e,o,config()))))}:{success:!0,data:i.value}},safeParseAsync=_safeParseAsync($ZodRealError),_encode=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return _parse(e)(t,n,o)},encode=_encode($ZodRealError),_decode=e=>(t,n,r)=>_parse(e)(t,n,r),decode=_decode($ZodRealError),_encodeAsync=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return _parseAsync(e)(t,n,o)},encodeAsync=_encodeAsync($ZodRealError),_decodeAsync=e=>async(t,n,r)=>_parseAsync(e)(t,n,r),decodeAsync=_decodeAsync($ZodRealError),_safeEncode=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return _safeParse(e)(t,n,o)},safeEncode=_safeEncode($ZodRealError),_safeDecode=e=>(t,n,r)=>_safeParse(e)(t,n,r),safeDecode=_safeDecode($ZodRealError),_safeEncodeAsync=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return _safeParseAsync(e)(t,n,o)},safeEncodeAsync=_safeEncodeAsync($ZodRealError),_safeDecodeAsync=e=>async(t,n,r)=>_safeParseAsync(e)(t,n,r),safeDecodeAsync=_safeDecodeAsync($ZodRealError),dateSource="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",date$1=new RegExp(`^${dateSource}$`),string$1=e=>new RegExp(`^${e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*"}$`),bigint$1=/^-?\d+n?$/,number$1=/^-?\d+(?:\.\d+)?/,boolean$1=/^(?:true|false)$/i,_null$2=/^null$/i,_undefined$2=/^undefined$/i,version={major:4,minor:1,patch:11},$ZodType=$constructor("$ZodType",((e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=version;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push((()=>{e._zod.run=e._zod.parse}));else{const t=(e,t,n)=>{let r,o=aborted(e);for(const i of t){if(i._zod.def.when){if(!i._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,s=i._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new $ZodAsyncError;if(r||s instanceof Promise)r=(r??Promise.resolve()).then((async()=>{await s,e.issues.length!==t&&(o||(o=aborted(e,t)))}));else{if(e.issues.length===t)continue;o||(o=aborted(e,t))}}return r?r.then((()=>e)):e},n=(n,o,i)=>{if(aborted(n))return n.aborted=!0,n;const s=t(o,r,i);if(s instanceof Promise){if(!1===i.async)throw new $ZodAsyncError;return s.then((t=>e._zod.parse(t,i)))}return e._zod.parse(s,i)};e._zod.run=(o,i)=>{if(i.skipChecks)return e._zod.parse(o,i);if("backward"===i.direction){const t=e._zod.parse({value:o.value,issues:[]},{...i,skipChecks:!0});return t instanceof Promise?t.then((e=>n(e,o,i))):n(t,o,i)}const s=e._zod.parse(o,i);if(s instanceof Promise){if(!1===i.async)throw new $ZodAsyncError;return s.then((e=>t(e,r,i)))}return t(s,r,i)}}e["~standard"]={validate:t=>{try{const n=safeParse(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return safeParseAsync(e,t).then((e=>e.success?{value:e.data}:{issues:e.error?.issues}))}},vendor:"zod",version:1}})),$ZodString=$constructor("$ZodString",((e,t)=>{$ZodType.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??string$1(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(e){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}})),$ZodNumber=$constructor("$ZodNumber",((e,t)=>{$ZodType.init(e,t),e._zod.pattern=e._zod.bag.pattern??number$1,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const o=n.value;if("number"==typeof o&&!Number.isNaN(o)&&Number.isFinite(o))return n;const i="number"==typeof o?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),n}})),$ZodBoolean=$constructor("$ZodBoolean",((e,t)=>{$ZodType.init(e,t),e._zod.pattern=boolean$1,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const o=n.value;return"boolean"==typeof o||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}})),$ZodBigInt=$constructor("$ZodBigInt",((e,t)=>{$ZodType.init(e,t),e._zod.pattern=bigint$1,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}})),$ZodUndefined=$constructor("$ZodUndefined",((e,t)=>{$ZodType.init(e,t),e._zod.pattern=_undefined$2,e._zod.values=new Set([void 0]),e._zod.optin="optional",e._zod.optout="optional",e._zod.parse=(t,n)=>{const r=t.value;return void 0===r||t.issues.push({expected:"undefined",code:"invalid_type",input:r,inst:e}),t}})),$ZodNull=$constructor("$ZodNull",((e,t)=>{$ZodType.init(e,t),e._zod.pattern=_null$2,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}})),$ZodUnknown=$constructor("$ZodUnknown",((e,t)=>{$ZodType.init(e,t),e._zod.parse=e=>e})),$ZodDate=$constructor("$ZodDate",((e,t)=>{$ZodType.init(e,t),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=new Date(n.value)}catch(e){}const o=n.value,i=o instanceof Date;return i&&!Number.isNaN(o.getTime())||n.issues.push({expected:"date",code:"invalid_type",input:o,...i?{received:"Invalid Date"}:{},inst:e}),n}}));function handleArrayResult(e,t,n){e.issues.length&&t.issues.push(...prefixIssues(n,e.issues)),t.value[n]=e.value}const $ZodArray=$constructor("$ZodArray",((e,t)=>{$ZodType.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let e=0;e<o.length;e++){const s=o[e],a=t.element._zod.run({value:s,issues:[]},r);a instanceof Promise?i.push(a.then((t=>handleArrayResult(t,n,e)))):handleArrayResult(a,n,e)}return i.length?Promise.all(i).then((()=>n)):n}}));function handlePropertyResult(e,t,n,r){e.issues.length&&t.issues.push(...prefixIssues(n,e.issues)),void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function normalizeDef(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=optionalKeys(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function handleCatchall(e,t,n,r,o,i){const s=[],a=o.keySet,c=o.catchall._zod,u=c.def.type;for(const o of Object.keys(t)){if(a.has(o))continue;if("never"===u){s.push(o);continue}const i=c.run({value:t[o],issues:[]},r);i instanceof Promise?e.push(i.then((e=>handlePropertyResult(e,n,o,t)))):handlePropertyResult(i,n,o,t)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i}),e.length?Promise.all(e).then((()=>n)):n}const $ZodObject=$constructor("$ZodObject",((e,t)=>{if($ZodType.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const n=cached((()=>normalizeDef(t)));defineLazy(e._zod,"propValues",(()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n}));const r=isObject,o=t.catchall;let i;e._zod.parse=(t,s)=>{i??(i=n.value);const a=t.value;if(!r(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=i.shape;for(const e of i.keys){const n=u[e]._zod.run({value:a[e],issues:[]},s);n instanceof Promise?c.push(n.then((n=>handlePropertyResult(n,t,e,a)))):handlePropertyResult(n,t,e,a)}return o?handleCatchall(c,a,t,s,n.value,e):c.length?Promise.all(c).then((()=>t)):t}}));function handleUnionResults(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const o=e.filter((e=>!aborted(e)));return 1===o.length?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map((e=>e.issues.map((e=>finalizeIssue(e,r,config())))))}),t)}const $ZodUnion=$constructor("$ZodUnion",((e,t)=>{$ZodType.init(e,t),defineLazy(e._zod,"optin",(()=>t.options.some((e=>"optional"===e._zod.optin))?"optional":void 0)),defineLazy(e._zod,"optout",(()=>t.options.some((e=>"optional"===e._zod.optout))?"optional":void 0)),defineLazy(e._zod,"values",(()=>{if(t.options.every((e=>e._zod.values)))return new Set(t.options.flatMap((e=>Array.from(e._zod.values))))})),defineLazy(e._zod,"pattern",(()=>{if(t.options.every((e=>e._zod.pattern))){const e=t.options.map((e=>e._zod.pattern));return new RegExp(`^(${e.map((e=>cleanRegex(e.source))).join("|")})$`)}}));const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(o,i)=>{if(n)return r(o,i);let s=!1;const a=[];for(const e of t.options){const t=e._zod.run({value:o.value,issues:[]},i);if(t instanceof Promise)a.push(t),s=!0;else{if(0===t.issues.length)return t;a.push(t)}}return s?Promise.all(a).then((t=>handleUnionResults(t,o,e,i))):handleUnionResults(a,o,e,i)}})),$ZodRecord=$constructor("$ZodRecord",((e,t)=>{$ZodType.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!isPlainObject(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const i=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){const s=t.valueType._zod.run({value:o[e],issues:[]},r);s instanceof Promise?i.push(s.then((t=>{t.issues.length&&n.issues.push(...prefixIssues(e,t.issues)),n.value[e]=t.value}))):(s.issues.length&&n.issues.push(...prefixIssues(e,s.issues)),n.value[e]=s.value)}let a;for(const e in o)s.has(e)||(a=a??[],a.push(e));a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:a})}else{n.value={};for(const s of Reflect.ownKeys(o)){if("__proto__"===s)continue;const a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(a.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map((e=>finalizeIssue(e,r,config()))),input:s,path:[s],inst:e}),n.value[a.value]=a.value;continue}const c=t.valueType._zod.run({value:o[s],issues:[]},r);c instanceof Promise?i.push(c.then((e=>{e.issues.length&&n.issues.push(...prefixIssues(s,e.issues)),n.value[a.value]=e.value}))):(c.issues.length&&n.issues.push(...prefixIssues(s,c.issues)),n.value[a.value]=c.value)}}return i.length?Promise.all(i).then((()=>n)):n}})),$ZodMap=$constructor("$ZodMap",((e,t)=>{$ZodType.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!(o instanceof Map))return n.issues.push({expected:"map",code:"invalid_type",input:o,inst:e}),n;const i=[];n.value=new Map;for(const[s,a]of o){const c=t.keyType._zod.run({value:s,issues:[]},r),u=t.valueType._zod.run({value:a,issues:[]},r);c instanceof Promise||u instanceof Promise?i.push(Promise.all([c,u]).then((([t,i])=>{handleMapResult(t,i,n,s,o,e,r)}))):handleMapResult(c,u,n,s,o,e,r)}return i.length?Promise.all(i).then((()=>n)):n}}));function handleMapResult(e,t,n,r,o,i,s){e.issues.length&&(propertyKeyTypes.has(typeof r)?n.issues.push(...prefixIssues(r,e.issues)):n.issues.push({code:"invalid_key",origin:"map",input:o,inst:i,issues:e.issues.map((e=>finalizeIssue(e,s,config())))})),t.issues.length&&(propertyKeyTypes.has(typeof r)?n.issues.push(...prefixIssues(r,t.issues)):n.issues.push({origin:"map",code:"invalid_element",input:o,inst:i,key:r,issues:t.issues.map((e=>finalizeIssue(e,s,config())))})),n.value.set(e.value,t.value)}const $ZodSet=$constructor("$ZodSet",((e,t)=>{$ZodType.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!(o instanceof Set))return n.issues.push({input:o,inst:e,expected:"set",code:"invalid_type"}),n;const i=[];n.value=new Set;for(const e of o){const o=t.valueType._zod.run({value:e,issues:[]},r);o instanceof Promise?i.push(o.then((e=>handleSetResult(e,n)))):handleSetResult(o,n)}return i.length?Promise.all(i).then((()=>n)):n}}));function handleSetResult(e,t){e.issues.length&&t.issues.push(...e.issues),t.value.add(e.value)}const $ZodLiteral=$constructor("$ZodLiteral",((e,t)=>{if($ZodType.init(e,t),0===t.values.length)throw new Error("Cannot create literal schema with no valid values");e._zod.values=new Set(t.values),e._zod.pattern=new RegExp(`^(${t.values.map((e=>"string"==typeof e?escapeRegex(e):e?escapeRegex(e.toString()):String(e))).join("|")})$`),e._zod.parse=(n,r)=>{const o=n.value;return e._zod.values.has(o)||n.issues.push({code:"invalid_value",values:t.values,input:o,inst:e}),n}}));function handleOptionalResult(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const $ZodOptional=$constructor("$ZodOptional",((e,t)=>{$ZodType.init(e,t),e._zod.optin="optional",e._zod.optout="optional",defineLazy(e._zod,"values",(()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0)),defineLazy(e._zod,"pattern",(()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${cleanRegex(e.source)})?$`):void 0})),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then((t=>handleOptionalResult(t,e.value))):handleOptionalResult(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}})),$ZodLazy=$constructor("$ZodLazy",((e,t)=>{$ZodType.init(e,t),defineLazy(e._zod,"innerType",(()=>t.getter())),defineLazy(e._zod,"pattern",(()=>e._zod.innerType._zod.pattern)),defineLazy(e._zod,"propValues",(()=>e._zod.innerType._zod.propValues)),defineLazy(e._zod,"optin",(()=>e._zod.innerType._zod.optin??void 0)),defineLazy(e._zod,"optout",(()=>e._zod.innerType._zod.optout??void 0)),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}));function _string(e,t){return new e({type:"string",...normalizeParams(t)})}function _number(e,t){return new e({type:"number",checks:[],...normalizeParams(t)})}function _boolean(e,t){return new e({type:"boolean",...normalizeParams(t)})}function _bigint(e,t){return new e({type:"bigint",...normalizeParams(t)})}function _undefined$1(e,t){return new e({type:"undefined",...normalizeParams(t)})}function _null$1(e,t){return new e({type:"null",...normalizeParams(t)})}function _unknown(e){return new e({type:"unknown"})}function _date(e,t){return new e({type:"date",...normalizeParams(t)})}const ZodMiniType=$constructor("ZodMiniType",((e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");$ZodType.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>parse$1(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>safeParse(e,t,n),e.parseAsync=async(t,n)=>parseAsync(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>safeParseAsync(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map((e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e))]}),e.clone=(t,n)=>clone(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e)})),ZodMiniString=$constructor("ZodMiniString",((e,t)=>{$ZodString.init(e,t),ZodMiniType.init(e,t)}));function string(e){return _string(ZodMiniString,e)}const ZodMiniNumber=$constructor("ZodMiniNumber",((e,t)=>{$ZodNumber.init(e,t),ZodMiniType.init(e,t)}));function number(e){return _number(ZodMiniNumber,e)}const ZodMiniBoolean=$constructor("ZodMiniBoolean",((e,t)=>{$ZodBoolean.init(e,t),ZodMiniType.init(e,t)}));function boolean(e){return _boolean(ZodMiniBoolean,e)}const ZodMiniBigInt=$constructor("ZodMiniBigInt",((e,t)=>{$ZodBigInt.init(e,t),ZodMiniType.init(e,t)}));function bigint(e){return _bigint(ZodMiniBigInt,e)}const ZodMiniUndefined=$constructor("ZodMiniUndefined",((e,t)=>{$ZodUndefined.init(e,t),ZodMiniType.init(e,t)}));function _undefined(e){return _undefined$1(ZodMiniUndefined,e)}const ZodMiniNull=$constructor("ZodMiniNull",((e,t)=>{$ZodNull.init(e,t),ZodMiniType.init(e,t)}));function _null(e){return _null$1(ZodMiniNull,e)}const ZodMiniUnknown=$constructor("ZodMiniUnknown",((e,t)=>{$ZodUnknown.init(e,t),ZodMiniType.init(e,t)}));function unknown(){return _unknown(ZodMiniUnknown)}const ZodMiniDate=$constructor("ZodMiniDate",((e,t)=>{$ZodDate.init(e,t),ZodMiniType.init(e,t)}));function date(e){return _date(ZodMiniDate,e)}const ZodMiniArray=$constructor("ZodMiniArray",((e,t)=>{$ZodArray.init(e,t),ZodMiniType.init(e,t)}));function array(e,t){return new ZodMiniArray({type:"array",element:e,...normalizeParams(t)})}const ZodMiniObject=$constructor("ZodMiniObject",((e,t)=>{$ZodObject.init(e,t),ZodMiniType.init(e,t),defineLazy(e,"shape",(()=>t.shape))}));function object(e,t){return new ZodMiniObject({type:"object",shape:e??{},...normalizeParams(t)})}const ZodMiniUnion=$constructor("ZodMiniUnion",((e,t)=>{$ZodUnion.init(e,t),ZodMiniType.init(e,t)}));function union(e,t){return new ZodMiniUnion({type:"union",options:e,...normalizeParams(t)})}const ZodMiniRecord=$constructor("ZodMiniRecord",((e,t)=>{$ZodRecord.init(e,t),ZodMiniType.init(e,t)}));function record(e,t,n){return new ZodMiniRecord({type:"record",keyType:e,valueType:t,...normalizeParams(n)})}const ZodMiniMap=$constructor("ZodMiniMap",((e,t)=>{$ZodMap.init(e,t),ZodMiniType.init(e,t)}));function map(e,t,n){return new ZodMiniMap({type:"map",keyType:e,valueType:t,...normalizeParams(n)})}const ZodMiniSet=$constructor("ZodMiniSet",((e,t)=>{$ZodSet.init(e,t),ZodMiniType.init(e,t)}));function set(e,t){return new ZodMiniSet({type:"set",valueType:e,...normalizeParams(t)})}const ZodMiniLiteral=$constructor("ZodMiniLiteral",((e,t)=>{$ZodLiteral.init(e,t),ZodMiniType.init(e,t)}));function literal(e,t){return new ZodMiniLiteral({type:"literal",values:Array.isArray(e)?e:[e],...normalizeParams(t)})}const ZodMiniOptional=$constructor("ZodMiniOptional",((e,t)=>{$ZodOptional.init(e,t),ZodMiniType.init(e,t)}));function optional(e){return new ZodMiniOptional({type:"optional",innerType:e})}const ZodMiniLazy=$constructor("ZodMiniLazy",((e,t)=>{$ZodLazy.init(e,t),ZodMiniType.init(e,t)}));function _lazy(e){return new ZodMiniLazy({type:"lazy",getter:e})}const importSchema=object({__cc_import:literal(!0),path:string(),name:optional(string())});function isImport(e){return e&&e.__cc_import}function createDefaultImport(e){return{__cc_import:!0,path:e.replace(/\\/g,"/")}}function createNamedImport(e,t){return{__cc_import:!0,path:t.replace(/\\/g,"/"),name:e}}const literalSchema=union([string(),number(),boolean(),_null(),_undefined(),date(),map(unknown(),unknown()),set(unknown()),bigint(),importSchema]),schema=_lazy((()=>union([literalSchema,array(schema),record(string(),schema)]))),extension="js",serializableSchema=record(string(),schema);function createImport(e,t){return`import ${e.name?`{ ${e.name} as ${t} }`:t} from "${e.path}";\n`}function serialize(e){let t="",n=0;!function e(r,o,i){if(r&&"object"==typeof r){if(isImport(r)){n++;const e=`__v_${n}`;return t+=createImport(r,e),void(void 0!==o&&void 0!==i&&(o[i]=e))}Array.isArray(r)?r.forEach(((t,n)=>e(t,r,n))):Object.entries(r).forEach((([t,n])=>{e(n,r,t)}))}}(e),t+="\n";const r=serializeJs(e,{space:2,unsafe:!0,ignoreFunction:!0}).replace(/"__v_(\d+)"/g,((e,t)=>`__v_${t}`));return t+="export default "+r,t}var TransformError=class extends Error{type;constructor(e,t){super(t),this.type=e}};function isSkippedSignal(e){return!0===e[skippedSymbol]}function createPath(e,t){let n=e.slice(0,-t.length);return n.endsWith("/index")&&(n=n.slice(0,-6)),n}function isContentDefined(e){return null!==e&&"object"==typeof e&&"content"in e}function formatValidationErrorMessage(e){return e.map((e=>`- ${e.path}: ${e.message}`)).join("\n")}function createTransformer(e,t){const n=new Set;async function r(t,r){const{data:o,path:i}=r,s=await t.schema["~standard"].validate(o);if(s.issues)return e.emit("transformer:validation-error",{collection:t,file:r,error:new TransformError("Validation",formatValidationErrorMessage(s.issues))}),null;let a=s.value;if(getParser(t.parser).hasContent&&!isContentDefined(a)){if(function(e){const t=`implicitContentProperty:${e.name}`;n.has(t)||(n.add(t),deprecated("implicitContentProperty"))}(t),"string"!=typeof o.content)return e.emit("transformer:validation-error",{collection:t,file:r,error:new TransformError("Validation","The content property is not a string")}),null;a={...a,content:o.content}}const c=extname(i);let u=c;return u.startsWith(".")&&(u=u.slice(1)),{document:{...a,_meta:{filePath:i,fileName:basename(i),directory:dirname(i),extension:u,path:createPath(i,c)}}}}async function o(n,r,o,i){const s=t.cache(r.name,i.document._meta.path),a=function(e,t,n){const r=isSingleton(t)?dirname(t.filePath):t.directory,o={documents:t=>{const n=e.find((e=>e.name===t.name));if(!n)throw new TransformError("Configuration",`Collection ${t.name} not found, do you have registered it in your configuration?`);return n.documents.map((e=>e.document))},cache:n.cacheFn,collection:{name:t.name,directory:r,documents:async()=>t.documents.map((e=>e.document))},skip:e=>({[skippedSymbol]:!0,reason:e})};return isSingleton(t)?{...o,singleton:{name:t.name,filePath:t.filePath,directory:r,document:async()=>t.documents[0]?.document}}:o}(n,r,s);try{const t=(isSingleton(r),await o(i.document,a));if(await s.tidyUp(),!isSkippedSignal(t))return{...i,document:t};e.emit("transformer:document-skipped",{collection:r,filePath:join(isSingleton(r)?dirname(r.filePath):r.directory,i.document._meta.filePath),reason:t.reason})}catch(t){t instanceof TransformError?e.emit("transformer:error",{collection:r,error:t}):e.emit("transformer:error",{collection:r,error:new TransformError("Transform",String(t))})}}async function i(e,n){const r=n.transform;if(r){const i=pLimit(os.cpus().length),s=r,a=n.documents.map((t=>i((()=>o(e,n,s,t))))),c=await Promise.all(a);return await t.flush(),c.filter(isDefined)}return n.documents}async function s(t,n){const r=[];for(const o of n){let n=await serializableSchema.safeParseAsync(o.document);n.success?r.push(o):e.emit("transformer:result-error",{collection:t,document:o.document,error:new TransformError("Result",n.error.message)})}return r}return async t=>{const n=t.map((e=>async function(e){const t=e.files.map((t=>r(e,t)));return{...e,documents:(await Promise.all(t)).filter(isDefined)}}(e))),o=await Promise.all(n);for(const t of o)t.documents=await s(t,await i(o,t)),isSingleton(t)&&0===t.documents.length&&e.emit("transformer:singleton-warning",{collection:t});return o}}async function createDataFile(e,t,n){const r=isSingleton(t)?generateSingletonConstName(t.typeName):generateArrayConstName(t.name),o=path.join(e,`${r}.js`);let i=serialize(isSingleton(t)?t.documents[0]?.document:t.documents.map((e=>e.document)));for(const e of n)i=(await e({fileType:"data",content:i,filePath:o})).content;await fs.writeFile(o,i)}function createDataFiles(e,t,n){return Promise.all(t.map((t=>createDataFile(e,t,n))))}async function createJavaScriptFile(e,t,n){const r=t.collections.map((e=>isSingleton(e)?generateSingletonConstName(e.typeName):generateArrayConstName(e.name)));let o=`// generated by content-collections at ${new Date}\n\n`;for(const e of r)o+=`import ${e} from "./${e}.js";\n`;o+="\n",o+="export { "+r.join(", ")+" };\n";const i=path.join(e,"index.js");for(const e of n)o=(await e({fileType:"javascript",content:o,filePath:i})).content;await fs.writeFile(i,o,"utf-8")}function createImportPath(e,t){let n=path.posix.join(...path.relative(e,t).split(path.sep));return n.startsWith(".")||(n="./"+n),n}async function createTypeDefinitionFile(e,t,n){if(!t.generateTypes)return;let r=`import configuration from "${createImportPath(e,t.path)}";\nimport { GetTypeByName } from "@content-collections/core";\n`;const o=t.collections;for(const e of o)r+="\n",r+=`export type ${e.typeName} = GetTypeByName<typeof configuration, "${e.name}">;\n`,isSingleton(e)?r+=`export declare const ${generateSingletonConstName(e.typeName)}: ${e.typeName}${e.optional?" | undefined":""};\n`:r+=`export declare const ${generateArrayConstName(e.name)}: Array<${e.typeName}>;\n`;r+="\n",r+="export {};\n";const i=path.join(e,"index.d.ts");for(const e of n)r=(await e({fileType:"typeDefinition",content:r,filePath:i})).content;await fs.writeFile(i,r,"utf-8")}async function createWriter(e,t){return await fs.mkdir(e,{recursive:!0}),{createJavaScriptFile:n=>createJavaScriptFile(e,n,t),createTypeDefinitionFile:n=>createTypeDefinitionFile(e,n,t),createDataFiles:n=>createDataFiles(e,n,t)}}async function createBuildContext({emitter:e,outputDirectory:t,cacheDirectory:n,baseDirectory:r,configuration:o}){const i=createCollector(e,r),[s,a,c]=await Promise.all([createWriter(t,o.hooks?.writer??[]),i.collect(o.collections),createCacheManager(n,o.checksum)]);return{resolved:a,writer:s,synchronizer:createSynchronizer(i.collectFile,a,r),transform:createTransformer(e,c),emitter:e,cacheManager:c,configuration:o}}async function build$1({emitter:e,transform:t,resolved:n,writer:r,configuration:o}){const i=Date.now();e.emit("builder:start",{startedAt:i});const s=await t(n);await Promise.all([r.createDataFiles(s),r.createTypeDefinitionFile(o),r.createJavaScriptFile(o)]);const a=s.filter((e=>Boolean(e.onSuccess))).map((e=>isSingleton(e)?e.onSuccess?.(e.documents[0]?.document):e.onSuccess?.(e.documents.map((e=>e.document)))));await Promise.all(a.filter(isDefined));const c=s.reduce(((e,t)=>(e.collections++,e.documents+=t.documents.length,e)),{collections:0,documents:0});e.emit("builder:end",{startedAt:i,endedAt:Date.now(),stats:c})}function isEventWithError(e){return"object"==typeof e&&null!==e&&"error"in e}function createEmitter(){const e=new EventEmitter;return{on:function(t,n){e.on(t,n)},emit:function(t,n){e.emit(t,n),isEventWithError(n)&&e.emit("_error",{...n,_event:t}),e.emit("_all",{...n,_event:t})}}}async function createWatcher(e,t,n,r){const o=removeChildPaths([...n.collections.map((e=>{const n=isSingleton(e)?path.dirname(e.filePath):e.directory;return path.join(t,n)})).map((e=>resolve(e))),...n.inputPaths.map((e=>dirname(e)))]),i=chokidar.watch(o,{ignored:[/(^|[\/\\])\../,/(^|[\/\\])node_modules([\/\\]|$)/],persistent:!0,ignoreInitial:!0}),s=async(t,n)=>{try{await r(t,n)}catch(t){e.emit("watcher:subscribe-error",{paths:o,error:toError(t)})}};return i.on("add",(e=>s("create",e))),i.on("change",(e=>s("update",e))),i.on("unlink",(e=>s("delete",e))),i.on("error",(t=>{e.emit("watcher:subscribe-error",{paths:o,error:toError(t)})})),await new Promise(((t,n)=>{i.on("ready",(()=>{e.emit("watcher:subscribed",{paths:o}),t()})),i.on("error",n)})),{unsubscribe:async()=>{await i.close(),e.emit("watcher:unsubscribed",{paths:o})}}}function resolveOutputDir(e,t){return t.outputDir?t.outputDir:path.join(e,".content-collections","generated")}function resolveCacheDir(e,t){return t.cacheDir?t.cacheDir:path.join(e,".content-collections","cache")}var ConfigurationReloadError=class extends Error{constructor(e){super(e)}};async function createBuilder(e,t={configName:defaultConfigName},n=createEmitter()){const r=createConfigurationReader(),o=path.dirname(e);return createInternalBuilder(await r(e,t),o,t,n)}async function createInternalBuilder(e,t,n,r){const o=createConfigurationReader(),i=e.path,s=resolveOutputDir(t,n),a=resolveCacheDir(t,n);r.emit("builder:created",{createdAt:Date.now(),configurationPath:i,outputDirectory:s});let c=e,u=null,l=await createBuildContext({emitter:r,baseDirectory:t,outputDirectory:s,cacheDirectory:a,configuration:c});async function d(e,p){if(c.inputPaths.includes(p)){if(await async function(){try{c=await o(i,n)}catch(e){return r.emit("watcher:config-reload-error",{error:new ConfigurationReloadError(`Failed to reload configuration: ${e}`),configurationPath:i}),!1}u&&await u.unsubscribe();l=await createBuildContext({emitter:r,baseDirectory:t,outputDirectory:s,cacheDirectory:a,configuration:c}),u&&(u=await createWatcher(r,t,c,d));return!0}())return r.emit("watcher:config-changed",{filePath:p,modification:e}),await build$1(l),!0}else if(await async function(e,t){const{synchronizer:n}=l;return"delete"===e?n.deleted(t):n.changed(t)}(e,p))return r.emit("watcher:file-changed",{filePath:p,modification:e}),await build$1(l),!0;return!1}return{build:()=>build$1(l),sync:d,watch:async function(){return u=await createWatcher(r,t,c,d),{unsubscribe:async()=>{u&&await u.unsubscribe()}}},on:r.on}}export{CollectError,ConfigurationError,ConfigurationReloadError,TransformError,createBuilder,createDefaultImport,createInternalBuilder,createNamedImport,defineCollection,defineConfig,defineParser,defineSingleton,isSingleton,skippedSymbol,suppressDeprecatedWarnings};
//# sourceMappingURL=/sm/5a0ebc2984dd6dcc2e53fa57f30bd4fd2b6c1135c501e22097afb104a4050bf6.map