{"version":3,"sources":["eternals.ts"],"sourcesContent":["import { NOT_EXISTING } from \"../runtime/constants.ts\";\nimport { Storage } from \"../storage/storage.ts\";\nimport { getCallerInfo } from \"./caller_metadata.ts\";\nimport { logger } from \"./global_values.ts\";\n\nexport let eternals:Map<string,unknown>;\nexport const waitingEternals = new Map<string,string>();\nexport const waitingLazyEternals = new Map<string,string>();\n\nexport async function loadEternalValues(){\n    eternals = await Storage.loadOrCreate(\"eternals\", ()=>new Map<string,unknown>());\n    // console.log(\"eternal\",eternals,Pointer.getByValue(eternals)?.idString())\n}\n\nexport async function clearEternalValues() {\n    eternals.clear();\n    await Storage.clearAll();\n}\n\n\n// get a stored eternal value from a caller location\nexport function getEternal(info?:ReturnType<typeof getCallerInfo>, customIdentifier?:string, return_not_existing = false) {\n    info ??= getCallerInfo();\n    if (!info) throw new Error(\"eternal values are not supported in this runtime environment\");\n    const line = info[0]\n\n    if (!line.file) logger.error(\"eternal values are only supported inside module files\");\n\n    const unique_row = `${line.file}:${line.row}`;\n    const key = customIdentifier!=undefined ? `${line.file}#${customIdentifier}` : `${unique_row}:${line.col}`; // use file location or customIdentifier as key\n\n    if (!eternals.has(key)) {\n        waitingEternals.set(unique_row, key); // assign next pointer to this eternal\n        setTimeout(()=>{\n            if (waitingEternals.has(unique_row)) logger.error(`uncaptured eternal value at ${unique_row}: please surround the value with $(), otherwise it cannot be restored correctly`)\n        }, 6000)\n        if (return_not_existing) return NOT_EXISTING\n    }\n    else return eternals.get(key)\n}\n\nexport async function getLazyEternal(info?:ReturnType<typeof getCallerInfo>, customIdentifier?:string, return_not_existing = false) {\n    info ??= getCallerInfo();\n    if (!info) throw new Error(\"eternal values are not supported in this runtime environment\");\n    const line = info[0]\n\n    if (!line.file) logger.error(\"eternal values are only supported inside module files\");\n\n    const unique_row = `${line.file}:${line.row}`;\n    const key = customIdentifier!=undefined ? `${line.file}#${customIdentifier}` : `${unique_row}:${line.col}`; // use file location or customIdentifier as key\n    \n    if (!await Storage.hasItem(key)) {\n        waitingLazyEternals.set(unique_row, key); // assign next pointer to this eternal\n        setTimeout(()=>{\n            if (waitingLazyEternals.has(unique_row)) logger.error(`uncaptured lazy_eternal value at ${unique_row}: please surround the value with $(), otherwise it cannot be restored correctly`)\n        }, 6000)\n        if (return_not_existing) return NOT_EXISTING\n    }\n    else return Storage.getItem(key);\n}\n\n\n// TODO: remove eternal\nObject.defineProperty(globalThis, 'eternal', {get:getEternal, configurable:false})\n\nObject.defineProperty(globalThis, 'lazyEternal', {get:getLazyEternal, configurable:false})\n\nObject.defineProperty(globalThis, 'eternalVar', {value:(customIdentifier:string)=>getEternal(getCallerInfo(), customIdentifier), configurable:false})\nObject.defineProperty(globalThis, 'lazyEternalVar', {value:(customIdentifier:string)=>getLazyEternal(getCallerInfo(), customIdentifier), configurable:false})"],"names":["NOT_EXISTING","Storage","getCallerInfo","logger","eternals","waitingEternals","Map","waitingLazyEternals","loadEternalValues","loadOrCreate","clearEternalValues","clear","clearAll","getEternal","info","customIdentifier","return_not_existing","Error","line","file","error","unique_row","row","key","undefined","col","has","get","set","setTimeout","getLazyEternal","hasItem","getItem","Object","defineProperty","globalThis","configurable","value"],"mappings":"AAAA,SAASA,YAAY,QAAQ,0BAA0B;AACvD,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,MAAM,QAAQ,qBAAqB;AAE5C,OAAO,IAAIC,SAA6B;AACxC,OAAO,MAAMC,kBAAkB,IAAIC,MAAqB;AACxD,OAAO,MAAMC,sBAAsB,IAAID,MAAqB;AAE5D,OAAO,eAAeE;IAClBJ,WAAW,MAAMH,QAAQQ,YAAY,CAAC,YAAY,IAAI,IAAIH;AAE9D;AAEA,OAAO,eAAeI;IAClBN,SAASO,KAAK,IACd,MAAMV,QAAQW,QAAQ;AAC1B;AAIA,OAAO,SAASC,WAAWC,IAAsC,EAAEC,gBAAwB,EAAEC,sBAAsB,CAAA,CAAK;IAEpH,IAAI,CADJF,CAA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