mongofire 6.5.5 → 6.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +288 -334
- package/bin/mongofire.cjs +1237 -0
- package/dist/bin/mongofire.cjs +1 -1
- package/dist/src/changetrack.js +1 -1
- package/dist/src/compactor.js +1 -1
- package/dist/src/connection.js +1 -1
- package/dist/src/device.js +1 -1
- package/dist/src/diff.js +1 -1
- package/dist/src/field-merge.js +1 -1
- package/dist/src/index.cjs +1 -1
- package/dist/src/local-manager.js +1 -0
- package/dist/src/plugin.js +1 -1
- package/dist/src/rate-limiter.js +1 -1
- package/dist/src/reconcile.js +1 -1
- package/dist/src/schema-manager.js +1 -1
- package/dist/src/state.js +1 -1
- package/dist/src/sync.js +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/types/index.d.ts +140 -1
- package/index.cjs +17 -1
- package/index.mjs +7 -1
- package/package.json +11 -10
- package/types/index.d.ts +317 -0
package/dist/bin/mongofire.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";process.on("uncaughtException",e=>{console.error("\n\u2716 MongoFire error:",e.message||e),process.env.MONGOFIRE_DEBUG&&console.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{console.error("\n\u2716 MongoFire error:",e?.message||e),process.env.MONGOFIRE_DEBUG&&console.error(e?.stack||e),process.exit(1)});const fs=require("fs"),path=require("path"),{pathToFileURL:pathToFileURL}=require("url"),args=process.argv.slice(2),command=args[0],flags=new Set(args.slice(1));flags.has("--esm")&&flags.has("--cjs")&&(console.error("\u2716 Use only one: --esm OR --cjs"),process.exit(1)),function(){const e=path.join(process.cwd(),".env");if(fs.existsSync(e))try{require("dotenv").config({path:e})}catch(e){}}();const IS_TTY=!!process.stdin.isTTY;function showHelp(){const e=_getVersion();console.log(`\n \x1b[33m\ud83d\udd25 MongoFire\x1b[0m \x1b[2mv${e}\x1b[0m\n\n \x1b[1mUsage\x1b[0m\n\n \x1b[36mnpx mongofire\x1b[0m \x1b[2m<command> [flags]\x1b[0m\n\n \x1b[1mCommands\x1b[0m\n\n \x1b[36minit\x1b[0m Interactive setup wizard\n \x1b[36mconfig\x1b[0m Update an existing configuration \x1b[2m(TTY only)\x1b[0m\n \x1b[36mstatus\x1b[0m Show pending sync counts\n \x1b[36mclean\x1b[0m Delete old sync records\n \x1b[36mconflicts\x1b[0m View and resolve conflicts \x1b[2m(TTY only)\x1b[0m\n \x1b[36mreconcile\x1b[0m Recover writes lost from crashes\n \x1b[36mreset-local\x1b[0m Safely wipe local DB + all MongoFire state \x1b[2m(TTY only)\x1b[0m\n\n \x1b[1mFlags for \x1b[36minit\x1b[0m\n\n \x1b[2m--esm\x1b[0m Force ESM module format\n \x1b[2m--cjs\x1b[0m Force CommonJS module format\n \x1b[2m--force, -f\x1b[0m Overwrite existing config files\n\n \x1b[1mFlags for \x1b[36mclean\x1b[0m\n\n \x1b[2m--days=N\x1b[0m Delete records older than N days (1\u20133650, default 7)\n\n \x1b[1mFlags for \x1b[36mreconcile\x1b[0m\n\n \x1b[2m--no-full-scan\x1b[0m Skip Phase 2 (only check orphaned docmeta)\n \x1b[2m--collection=NAME\x1b[0m Scan a single collection instead of all\n\n \x1b[2mTip: set MONGOFIRE_DEBUG=1 for full error stack traces\x1b[0m\n`)}function _getVersion(){try{return require(path.join(__dirname,"..","package.json")).version}catch{return"?"}}async function loadClack(){try{return await import("@clack/prompts")}catch{return buildFallbackClack()}}(async()=>{if("init"===command){const e=flags.has("--esm")||flags.has("--cjs")||flags.has("--force")||flags.has("-f");!e&&IS_TTY?await doInitWizard():(e||process.stdout.write("\u2139 Non-interactive mode \u2014 use --cjs, --esm, --force for control\n\n"),doInitDirect({force:flags.has("--force")||flags.has("-f"),moduleSystem:flags.has("--esm")?"esm":flags.has("--cjs")?"cjs":null,flagForced:flags.has("--esm")||flags.has("--cjs")}))}else if("config"===command)IS_TTY?await doConfigWizard():(console.log("\u2139 config requires an interactive terminal."),process.exit(0));else if("status"===command)await doStatus();else if("clean"===command){![...flags].some(e=>e.startsWith("--days="))&&IS_TTY?await doCleanWizard():await doClean()}else if("conflicts"===command)IS_TTY?await doConflictsWizard():(console.log("\u2139 conflicts requires an interactive terminal."),process.exit(0));else if("reconcile"===command){const e=flags.has("--no-full-scan"),n=[...flags].find(e=>e.startsWith("--collection=")),o=n?n.split("=")[1]:null;await doReconcile({fullScan:!e,collection:o})}else"reset-local"===command?IS_TTY?await doResetLocal():(console.log("\u2139 reset-local requires an interactive terminal (safety guard)."),process.exit(0)):showHelp()})().catch(e=>{console.error("\n\u2716 MongoFire error:",e.message||e),process.env.MONGOFIRE_DEBUG&&console.error(e.stack),process.exit(1)});const DEFAULT_COLLECTIONS="orders, products, users";function _info(e,n,o){const t=e=>e.length>58?e.slice(0,57)+"...":e;process.stdout.write("|\n"),process.stdout.write("\x1b[2m| +- \x1b[0m\x1b[1m"+e+"\x1b[0m\n");for(const e of n)""===e?process.stdout.write("\x1b[2m| |\x1b[0m\n"):e.startsWith("\u2713")?process.stdout.write("\x1b[2m| | \x1b[32m"+t(e)+"\x1b[0m\n"):e.startsWith("\u2715")?process.stdout.write("\x1b[2m| | \x1b[2m"+t(e)+"\x1b[0m\n"):e.startsWith("\u2192")?process.stdout.write("\x1b[2m| | \x1b[36m"+t(e)+"\x1b[0m\n"):process.stdout.write("\x1b[2m| | "+t(e)+"\x1b[0m\n");o?process.stdout.write("\x1b[2m| +- \ud83d\udca1 "+t(o)+"\x1b[0m\n"):process.stdout.write("\x1b[2m| +-\x1b[0m\n")}async function doInitWizard(){const e=await loadClack(),n=process.cwd();e.intro(`\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m v${_getVersion()} \x1b[0m`);const o=path.join(n,"mongofire.config.js"),t=path.join(n,"mongofire.js"),s=fs.existsSync(o),i=fs.existsSync(t);if(s){const n=[s&&"mongofire.config.js",i&&"mongofire.js"].filter(Boolean).join(", ");e.note(`\x1b[33m${n}\x1b[0m \x1b[2m\u2014 already exists in this directory\x1b[0m`,"Existing setup found");const o=await e.select({message:"What would you like to do?",options:[{value:"overwrite",label:"Overwrite",hint:"replace with fresh config \u2014 start from scratch"},{value:"config",label:"Update config",hint:"change collections, interval, or toggle options"},{value:"cancel",label:"Cancel",hint:"keep existing files unchanged"}],initialValue:"overwrite"});if(e.isCancel(o)||"cancel"===o)return void e.cancel("Cancelled \u2014 existing files kept.");if("config"===o)return e.outro("\x1b[2mOpening config wizard...\x1b[0m"),doConfigWizard()}_info("Module System",["How your project loads and shares code between files.","","\u2192 Auto-detect reads package.json + scans your source files","\u2192 CommonJS you write require() / module.exports","\u2192 ESM you write import / export"],"Not sure? Pick Auto-detect \u2014 correct for most projects.");const a=await e.select({message:"Module system",options:[{value:"auto",label:"Auto-detect",hint:"recommended \u2014 reads your project automatically"},{value:"cjs",label:"CommonJS",hint:"require() / module.exports"},{value:"esm",label:"ESM",hint:"import / export"}],initialValue:"auto"});if(e.isCancel(a))return _cancelled(e);_info("Real-Time Sync",["Controls how fast changes appear across all connected devices.","","\u2713 Enabled Atlas Change Streams \u2014 changes push within milliseconds","\u2715 Disabled Polling only \u2014 devices check every syncInterval","","If Change Streams are unavailable, falls back to polling silently."],"Recommended ON for most apps.");const r=await e.confirm({message:"Enable real-time sync?",hint:"ON = instant push OFF = polling only",initialValue:!0});if(e.isCancel(r))return _cancelled(e);_info("Multi-Tenant Mode",["Controls whether each user syncs only their own private data.","","\u2715 OFF Cafe system, team app, single business"," All users share the same data \u2014 simple and fast","","\u2713 ON SaaS platform, per-user notes, multi-business app"," Each user sees only their own documents"],"Keep OFF unless users must have isolated private data.");const l=await e.confirm({message:"Enable multi-tenant mode?",hint:"OFF = shared data (default) ON = per-user isolation",initialValue:!1});if(e.isCancel(l))return _cancelled(e);_info("TypeScript Hints",["Adds @ts-check + JSDoc types to mongofire.config.js.","","\u2713 Enabled VS Code shows autocomplete and catches typos"," Works perfectly in plain JavaScript projects"," No TypeScript compiler or tsconfig needed","","\u2715 Disabled Plain config file, no type annotations"],"Recommended ON \u2014 free autocomplete, zero setup cost.");const c=await e.confirm({message:"Add TypeScript hints?",hint:"ON = smart autocomplete in VS Code OFF = plain JS",initialValue:!0});if(e.isCancel(c))return _cancelled(e);_info("Verbose Logging",["Controls how much MongoFire prints to your console.","","\u2715 OFF Logs only when real changes happen (uploads/downloads)"," Clean output \u2014 good for production","","\u2713 ON Logs every sync cycle even when nothing changed"," Useful when debugging sync issues during development"],"Keep OFF in production. Enable temporarily to debug.");const m=await e.confirm({message:"Enable verbose logging?",hint:"OFF = clean logs (recommended) ON = log every cycle",initialValue:!1});if(e.isCancel(m))return _cancelled(e);const d=new Set([r&&"realtime",l&&"multitenant",c&&"typescript",m&&"verbose"].filter(Boolean));_info("Collections to Sync",["MongoDB collection names MongoFire will keep in sync.","","\u2192 Enter your actual collection names, comma-separated","\u2192 Must match exactly what your Mongoose models use","\u2192 Example: orders, products, users, categories"],"Press Enter to accept defaults \u2014 edit in mongofire.config.js anytime.");const u=await e.text({message:"Collections to sync",placeholder:DEFAULT_COLLECTIONS,defaultValue:DEFAULT_COLLECTIONS,validate:()=>{}});if(e.isCancel(u))return _cancelled(e);const f=((u||"").trim()||DEFAULT_COLLECTIONS).split(",").map(e=>e.trim()).filter(Boolean),g=d.has("realtime");_info("Sync Interval",["How often MongoFire polls Atlas for new changes.","","\u2192 Lower changes appear faster, more bandwidth used","\u2192 Higher less resource usage, slight delay in updates","",g?"\u2713 Realtime is ON \u2014 polling is just a safety net. 5s is ideal.":"\u2192 No realtime \u2014 30s is the sweet spot for most apps."],"You can change this in mongofire.config.js at any time.");const p=g?[{value:2e3,label:"2s",hint:"aggressive \u2014 high bandwidth usage"},{value:5e3,label:"5s",hint:"recommended with Change Streams"},{value:15e3,label:"15s",hint:"light fallback polling"}]:[{value:5e3,label:"5s",hint:"fast \u2014 great for dev and testing"},{value:15e3,label:"15s",hint:"balanced \u2014 low traffic apps"},{value:3e4,label:"30s",hint:"recommended for most apps"},{value:6e4,label:"60s",hint:"conservative \u2014 minimal DB load"}],h=await e.select({message:"Sync interval",options:p,initialValue:g?5e3:3e4});if(e.isCancel(h))return _cancelled(e);let y="*";if(d.has("multitenant")){_info("Owner Field",["The document field that identifies who owns each record.","","\u2192 Must exist on EVERY document in every synced collection","\u2192 MongoFire only syncs docs where this field = current user","\u2192 You must set this field when creating documents in your app","","Common names: userId, ownerId, createdBy, accountId"],"Set req.user._id into this field on every document you create.");const n=await e.text({message:"Owner field name",placeholder:"userId",defaultValue:"userId",hint:"must exist on every synced document"});if(e.isCancel(n))return _cancelled(e);y=(n||"").trim()||"userId"}const w=e=>e?"\x1b[32m\u25cf Enabled\x1b[0m":"\x1b[2m\u25cb Disabled\x1b[0m",v=[`Module system ${"auto"===a?"Auto-detect":a.toUpperCase()}`,`Real-time sync ${w(r)}`,`Multi-tenant ${w(l)}`,`TypeScript hints ${w(c)}`,`Verbose logging ${w(m)}`,`Sync interval ${h}ms`,`Collections ${f.join(", ")}`];d.has("multitenant")&&v.push(`Owner field ${y}`),e.note(v.join("\n"),"Configuration Summary");const C=await e.confirm({message:"Looks good \u2014 create these files?",initialValue:!0});if(e.isCancel(C)||!C)return void e.cancel("Cancelled \u2014 no files changed.");const $="auto"===a,S=$?detectModuleSystem(n,null):a,_={collections:f,realtime:r,syncInterval:h,ownerField:y,verbose:m,typescript:c},b=ensureEnvFile(path.join(n,".env")),F=writeFileIfNeeded(path.join(n,"mongofire.config.js"),buildConfigTemplate(S,_),!0),j=writeFileIfNeeded(path.join(n,"mongofire.js"),buildEntryTemplate(S,_),!0),x=collectPackageHints(n),E=["failed"===F.action&&{file:"mongofire.config.js",error:F.error},"failed"===j.action&&{file:"mongofire.js",error:j.error}].filter(Boolean);if(E.length>0){const n=E.map(e=>"\x1b[31m\u2715\x1b[0m "+e.file.padEnd(24)+"\x1b[2m"+e.error+"\x1b[0m");return n.push(""),n.push("\x1b[2mTip: close the file in VS Code or any editor, then run init again.\x1b[0m"),e.note(n.join("\n"),"\x1b[31mCould not write files\x1b[0m"),void e.cancel("Setup incomplete \u2014 some files could not be written.")}const M=[_fileRow(".env",b.action),_fileRow("mongofire.config.js",F.action),_fileRow("mongofire.js",j.action)];x.length&&M.push("",...x.map(e=>"\x1b[33m\u26a0\x1b[0m "+e)),e.note(M.join("\n"),"Files created");e.note(["Fill in \x1b[36mATLAS_URI\x1b[0m inside \x1b[2m.env\x1b[0m","esm"===S?"Add \x1b[2mimport './mongofire.js'\x1b[0m to your app entry point":"Add \x1b[2mrequire('./mongofire')\x1b[0m to your app entry point","Add \x1b[2mSchema.plugin(mongofire.plugin('name'))\x1b[0m to each model"].map((e,n)=>`${n+1}. ${e}`).join("\n"),"Next steps"),e.outro(`\x1b[32m\u2713 Setup complete!\x1b[0m \x1b[2m${S.toUpperCase()} \xb7 ${$?"auto-detected":"manual"}\x1b[0m`)}async function doConfigWizard(){const e=await loadClack(),n=process.cwd(),o=path.join(n,"mongofire.config.js");fs.existsSync(o)||(console.log("\n\u2716 No mongofire.config.js found \u2014 run npx mongofire init first.\n"),process.exit(1)),e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m config \x1b[0m");const t=await e.select({message:"What do you want to change?",options:[{value:"collections",label:"Collections to sync"},{value:"interval",label:"Sync interval"},{value:"realtime",label:"Real-time sync toggle"},{value:"multitenant",label:"Multi-tenant owner field"},{value:"regenerate",label:"Regenerate all files",hint:"runs full wizard"}]});if(e.isCancel(t))return _cancelled(e);if("regenerate"===t)return e.outro(""),doInitWizard();let s="";try{s=fs.readFileSync(o,"utf8")}catch(e){}if("collections"===t){const n=s.match(/collections:\s*\[([\s\S]*?)\]/),t=n?n[1].replace(/['"\s]/g,"").split(",").filter(Boolean).join(", "):"users, products",i=await e.text({message:"Collections to sync",defaultValue:t,placeholder:t});if(e.isCancel(i))return _cancelled(e);const a=i.split(",").map(e=>e.trim()).filter(Boolean),r=a.map(e=>` '${e}',`).join("\n");fs.writeFileSync(o,s.replace(/collections:\s*\[([\s\S]*?)\]/,`collections: [\n${r}\n ]`),"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m collections \u2192 ${a.join(", ")}`)}else if("interval"===t){const n=await e.select({message:"New sync interval",options:[{value:5e3,label:"5s",hint:"dev"},{value:15e3,label:"15s",hint:"balanced"},{value:3e4,label:"30s",hint:"recommended"},{value:6e4,label:"60s",hint:"conservative"}],initialValue:3e4});if(e.isCancel(n))return _cancelled(e);const t=s.replace(/syncInterval:\s*\d+/,`syncInterval: ${n}`);if(t===s)return void e.cancel("\u2716 Could not find syncInterval in config \u2014 edit manually.");fs.writeFileSync(o,t,"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m syncInterval \u2192 ${n}ms`)}else if("realtime"===t){const n=/realtime:\s*true/.test(s),t=await e.confirm({message:"Enable real-time sync?",initialValue:!n});if(e.isCancel(t))return _cancelled(e);const i=s.replace(/realtime:\s*(true|false)/,`realtime: ${t}`);if(i===s)return void e.cancel("\u2716 Could not find realtime field in config \u2014 edit manually.");fs.writeFileSync(o,i,"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m realtime \u2192 ${t}`)}else if("multitenant"===t){const n=await e.text({message:"Owner field path (use '*' to disable)",defaultValue:"userId",placeholder:"userId"});if(e.isCancel(n))return _cancelled(e);const t=s.replace(/syncOwner:\s*['"][^'"]*['"]/,`syncOwner: '${n}'`);if(t===s)return void e.cancel("\u2716 Could not find syncOwner in config \u2014 edit manually.");fs.writeFileSync(o,t,"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m syncOwner \u2192 ${n}`)}}function doInitDirect(e){const n=process.cwd(),o=detectModuleSystem(n,e.moduleSystem),t=e.flagForced?`--${o}`:"auto-detected",s=ensureEnvFile(path.join(n,".env")),i=writeFileIfNeeded(path.join(n,"mongofire.config.js"),buildConfigTemplate(o,{collections:["users","products"],realtime:!1,syncInterval:3e4,ownerField:"*"}),!!e.force),a=writeFileIfNeeded(path.join(n,"mongofire.js"),buildEntryTemplate(o,{}),!!e.force),r=collectPackageHints(n);console.log(`\x1b[33m \ud83d\udd25 MongoFire\x1b[0m \x1b[2mv${_getVersion()}\x1b[0m\n`),console.log(_fileRow(".env",s.action)),console.log(_fileRow("mongofire.config.js",i.action)),console.log(_fileRow("mongofire.js",a.action)),e.force||"skipped"!==i.action&&"skipped"!==a.action||console.log("\n\x1b[2m Existing files kept \u2014 use --force to regenerate.\x1b[0m"),r.length&&(console.log(""),r.forEach(e=>console.log(`\x1b[33m \u26a0\x1b[0m ${e}`))),console.log(`\n\x1b[32m Done!\x1b[0m \x1b[2m${o.toUpperCase()} \xb7 ${t}\x1b[0m\n`)}async function doStatus(){const e=await loadClack(),n=process.cwd(),o=resolveConfigPath(n);if(!o)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m status \x1b[0m");const t=e.spinner();t.start("Connecting\u2026");const s=await loadConfig(o,n),i=requireMongofire();await i.start(s);const a=await i.status();t.stop("Connected");e.note([`Atlas ${a.online?"\x1b[32m\u25cf online\x1b[0m":"\x1b[31m\u25cf offline\x1b[0m"}`,"",`Pending \x1b[1m${a.pending}\x1b[0m \x1b[2munsynced operations\x1b[0m`,` Creates ${a.creates}`,` Updates ${a.updates}`,` Deletes ${a.deletes}`].join("\n"),"Sync state"),e.outro(0===a.pending?"\x1b[32mAll caught up\x1b[0m":`\x1b[33m${a.pending} operation(s) pending\x1b[0m`),await i.stop(),process.exit(0)}async function doCleanWizard(){const e=await loadClack();e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m clean \x1b[0m");const n=await e.select({message:"Delete records synced longer than",options:[{value:1,label:"1 day",hint:"aggressive"},{value:3,label:"3 days"},{value:7,label:"7 days",hint:"recommended"},{value:14,label:"14 days"},{value:30,label:"30 days",hint:"conservative"}],initialValue:7});if(e.isCancel(n))return _cancelled(e);const o=await e.confirm({message:`Delete records older than ${n} day(s) \u2014 this cannot be undone`,initialValue:!1});!e.isCancel(o)&&o?await _runClean(e,n):e.cancel("Cancelled \u2014 nothing deleted.")}async function doClean(){const e=await loadClack();e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m clean \x1b[0m");const n=[...flags].find(e=>e.startsWith("--days=")),o=n?parseInt(n.split("=")[1],10):7;await _runClean(e,o)}async function _runClean(e,n){(!Number.isInteger(n)||n<1||n>3650)&&(console.error("\u2716 Invalid --days value (must be 1\u20133650)"),process.exit(1));const o=process.cwd(),t=resolveConfigPath(o);if(!t)return _noConfig(e);const s=e.spinner();s.start(`Deleting records older than ${n} day(s)\u2026`);const i=await loadConfig(t,o),a=requireMongofire();await a.start(i);const r=await a.clean(n);s.stop(`Deleted ${r} record(s)`),e.outro(r>0?`\x1b[32m${r} record(s) removed\x1b[0m`:"\x1b[2mNothing to clean\x1b[0m"),await a.stop(),process.exit(0)}async function doConflictsWizard(){const e=await loadClack(),n=process.cwd(),o=resolveConfigPath(n);if(!o)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m conflicts \x1b[0m");const t=e.spinner();t.start("Loading conflicts\u2026");const s=await loadConfig(o,n),i=requireMongofire();await i.start(s);const a=await i.conflicts();t.stop(`${a.length} conflict(s) found`),a.length||(e.outro("\x1b[32mNo unresolved conflicts\x1b[0m"),await i.stop(),process.exit(0));const r=a.map(e=>[`\x1b[1m${e.collection}/${e.docId}\x1b[0m \x1b[2mop:${e.type} v${e.version}\x1b[0m`,e.lastError?` \x1b[31m${e.lastError}\x1b[0m`:""].filter(Boolean).join("\n")).join("\n\n");e.note(r,`${a.length} unresolved conflict(s)`);const l=await e.select({message:"How do you want to resolve?",options:[{value:"retry_all",label:"Retry all",hint:"reset to pending, sync re-attempts"},{value:"dismiss_all",label:"Dismiss all",hint:"discard \u2014 keep local state"},{value:"pick_retry",label:"Pick one to retry"},{value:"pick_dismiss",label:"Pick one to dismiss"},{value:"nothing",label:"Do nothing"}]});if(e.isCancel(l))return _cancelled(e);if("nothing"===l)e.outro("\x1b[2mNo changes made\x1b[0m");else if("retry_all"===l){const n=e.spinner();n.start("Retrying\u2026");for(const e of a)await i.retryConflict(e.opId);n.stop(`Retried ${a.length} conflict(s)`),e.outro("\x1b[32mAll conflicts reset to pending\x1b[0m")}else if("dismiss_all"===l){const n=e.spinner();n.start("Dismissing\u2026");for(const e of a)await i.dismissConflict(e.opId);n.stop(`Dismissed ${a.length} conflict(s)`),e.outro("\x1b[32mAll conflicts dismissed\x1b[0m")}else{const n=await e.select({message:"Select conflict",options:a.map(e=>({value:e.opId,label:`${e.collection}/${e.docId}`,hint:`${e.type} v${e.version}`}))});if(e.isCancel(n))return _cancelled(e);"pick_retry"===l?(await i.retryConflict(n),e.outro("\x1b[32mConflict reset to pending\x1b[0m")):(await i.dismissConflict(n),e.outro("\x1b[32mConflict dismissed\x1b[0m"))}await i.stop(),process.exit(0)}async function doReconcile(e={}){const n=await loadClack(),o=process.cwd(),t=resolveConfigPath(o);if(!t)return _noConfig(n);n.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m reconcile \x1b[0m");const s=!1!==e.fullScan,i=s?"full scan":"Phase 1 only (--no-full-scan)",a=n.spinner();a.start(`Scanning for lost writes\u2026 \x1b[2m(${i})\x1b[0m`);const r=await loadConfig(t,o),l=requireMongofire();await l.start(r);const c=e.collection?e.collection:{fullScan:s,verbose:!0},m=await l.reconcile(c,{fullScan:s,verbose:!0}),d=m.reduce((e,n)=>e+(n.totalQueued||0),0);a.stop("Scan complete");const u=m.map(e=>{if(e.error)return`\x1b[31m\u2716\x1b[0m ${e.collection} \x1b[2m${e.error}\x1b[0m`;return`${(e.phase1?.queued||0)+(e.phase2?.queued||0)>0?"\x1b[33m\u21bb\x1b[0m":"\x1b[32m\u2713\x1b[0m"} \x1b[1m${e.collection}\x1b[0m \x1b[2mP1:${e.phase1?.queued||0} P2:${e.phase2?.queued||0} re-queued\x1b[0m`}).join("\n");n.note(u,"Results"),n.outro(d>0?`\x1b[33m${d} lost write(s) recovered\x1b[0m`:"\x1b[32mNo untracked operations found\x1b[0m"),await l.stop(),process.exit(0)}function buildConfigTemplate(e,n={}){const o=(n.collections?.length?n.collections:["orders","products","users"]).map(e=>` '${e}',`).join("\n"),t=n.ownerField&&"*"!==n.ownerField?n.ownerField:"*",s=n.typescript?'\n// @ts-check\n/** @type {import("mongofire").SyncConfig} */':"",i=[" localUri: process.env.LOCAL_URI || 'mongodb://127.0.0.1:27017',"," atlasUri: process.env.ATLAS_URI,"," dbName: process.env.DB_NAME || 'myapp',",""," collections: [",o," ],","",` syncInterval: ${n.syncInterval||3e4},`," batchSize: 200,",` syncOwner: '${t}', // '*' = sync all data (default \u2014 recommended for most apps)`,"*"===t?" // syncOwner: 'userId', // Uncomment for multi-tenant \u2014 see README":` // Multi-tenant ON: only syncs docs where document.${t} matches syncOwner value`,` realtime: ${!!n.realtime},`,""," onSync(result) {",n.verbose?" console.log(`[MongoFire] \u2191${result.uploaded} \u2193${result.downloaded} DEL:${result.deleted}`);":" if (result.deleted + result.downloaded + result.uploaded > 0) {\n console.log(`[MongoFire] Synced: \u2191${result.uploaded} \u2193${result.downloaded} DEL:${result.deleted}`);\n }"," },"," onError(err) {"," console.error('[MongoFire] Sync error:', err.message);"," },"].join("\n");return"esm"===e?`${s}\nimport 'dotenv/config';\n\n// MongoFire configuration (ESM)\nexport default {\n${i}\n};\n`:`${s}\n'use strict';\ntry { require('dotenv').config(); } catch (_) {}\n\n// MongoFire configuration (CommonJS)\nmodule.exports = {\n${i}\n};\n`}function buildEntryTemplate(e,n={}){const o=n.verbose?"mongofire.on('sync', (r) => console.log(`[MongoFire] \u2191${r.uploaded} \u2193${r.downloaded} DEL:${r.deleted}`));":"mongofire.on('sync', (r) => {\n if (r.deleted + r.downloaded + r.uploaded > 0) {\n console.log(`[MongoFire] Synced: \u2191${r.uploaded} \u2193${r.downloaded} DEL:${r.deleted}`);\n }\n});";return"esm"===e?`import 'dotenv/config';\nimport mongofire from 'mongofire';\nimport config from './mongofire.config.js';\n\nexport const ready = mongofire.start(config);\n\nmongofire.on('online', () => console.log('[MongoFire] Online'));\nmongofire.on('offline', () => console.log('[MongoFire] Offline \u2014 working locally'));\n${o}\n\nexport { mongofire };\n`:`'use strict';\nconst mongofire = require('mongofire');\nconst config = require('./mongofire.config');\n\nconst ready = mongofire.start(config);\n\nmongofire.on('online', () => console.log('[MongoFire] Online'));\nmongofire.on('offline', () => console.log('[MongoFire] Offline \u2014 working locally'));\n${o}\n\nmodule.exports = { mongofire, ready };\n`}function ensureEnvFile(e){const n=[["ATLAS_URI","mongodb+srv://USERNAME:PASSWORD@cluster0.xxxxx.mongodb.net/"],["LOCAL_URI","mongodb://127.0.0.1:27017"],["DB_NAME","myapp"]];if(!fs.existsSync(e))return fs.writeFileSync(e,"# MongoFire\n"+n.map(([e,n])=>`${e}=${n}`).join("\n")+"\n","utf8"),{action:"created"};const o=fs.readFileSync(e,"utf8"),t=n.filter(([e])=>!new RegExp(`^\\s*${escapeRE(e)}\\s*=`,"m").test(o));return t.length?(fs.appendFileSync(e,"\n# MongoFire\n"+t.map(([e,n])=>`${e}=${n}`).join("\n")+"\n","utf8"),{action:"updated"}):{action:"unchanged"}}function writeFileIfNeeded(e,n,o){const t=fs.existsSync(e);if(t&&!o)return{action:"skipped"};const s=e+".mftmp";try{if(fs.writeFileSync(s,n,"utf8"),t)try{fs.unlinkSync(e)}catch(e){}fs.renameSync(s,e)}catch(o){try{fs.unlinkSync(s)}catch(e){}fs.writeFileSync(e,n,{encoding:"utf8",flag:"w"})}return{action:t?"overwritten":"created"}}function collectPackageHints(e){const n=readPackageJson(e),o=Object.assign({},n?.dependencies,n?.devDependencies,n?.peerDependencies),t=[];return o.mongoose||t.push("mongoose not installed \u2014 npm i mongoose"),o.dotenv||t.push("dotenv not installed \u2014 npm i dotenv"),t}function _fileRow(e,n){return` ${{created:"\x1b[32m+\x1b[0m",overwritten:"\x1b[33m~\x1b[0m",skipped:"\x1b[2m\u2013\x1b[0m",unchanged:"\x1b[2m\u2013\x1b[0m",updated:"\x1b[32m+\x1b[0m"}[n]||" "} ${e.padEnd(24)}${{created:"\x1b[2mcreated\x1b[0m",overwritten:"\x1b[33mupdated\x1b[0m",skipped:"\x1b[2mexists\x1b[0m",unchanged:"\x1b[2munchanged\x1b[0m",updated:"\x1b[2mupdated\x1b[0m"}[n]||n}`}async function doResetLocal(){const e=await loadClack(),n=process.cwd(),o=resolveConfigPath(n);if(!o)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m reset-local \x1b[0m"),e.note(["\x1b[1mThis will permanently delete:\x1b[0m"," \u2022 All MongoFire internal collections (_mf_changetrack, _mf_docmeta,"," _mf_sync_state, _mf_ops)"," \u2022 All configured data collections listed in mongofire.config.js","","The next startup will re-bootstrap from Atlas.","\x1b[31mAny unsynced local changes will be lost.\x1b[0m"].join("\n"),"WARNING");const t=await e.confirm({message:"Are you sure you want to reset the entire local database?",initialValue:!1});if(e.isCancel(t)||!t)return void e.cancel("Cancelled \u2014 nothing was deleted.");const s=e.spinner();let i;s.start("Connecting to local MongoDB\u2026");try{i=await loadConfig(o,n)}catch(n){s.stop("Failed to load config"),e.cancel(`Config error: ${n.message}`),process.exit(1)}const a=requireMongofire();await a.start(i);const r=a._conn?.local||a.conn?.local,l=Array.isArray(i.collections)?i.collections:[],c=[...new Set(["_mf_changetrack","_mf_docmeta","_mf_sync_state","_mf_ops","_mf_devices",...l])];s.start(`Dropping ${c.length} collection(s)\u2026`);let m=0,d=0;for(const e of c)try{await r.collection(e).drop(),m++}catch(n){n.message?.includes("ns not found")||n.codeName?.includes("NamespaceNotFound")||(d++,console.error(`\n\u2716 Failed to drop "${e}":`,n.message))}s.stop(`Dropped ${m} collection(s)${d?`, ${d} error(s)`:""}`),e.outro(0===d?"\x1b[32mLocal database reset complete.\x1b[0m Start your app to re-bootstrap from Atlas.":`\x1b[33mReset finished with ${d} error(s).\x1b[0m Check logs above.`),await a.stop(),process.exit(0)}function _cancelled(e){e.cancel("Cancelled."),process.exit(0)}function _noConfig(e){e.cancel("No mongofire.config.js found \u2014 run npx mongofire init first."),process.exit(1)}function detectModuleSystem(e,n){if(n&&"auto"!==n)return n;const o=readPackageJson(e);if("module"===o?.type)return"esm";if("commonjs"===o?.type)return"cjs";const t=["index.js","app.js","server.js","main.js",path.join("src","index.js"),path.join("src","main.js")];for(const n of t){const o=path.join(e,n);if(!fs.existsSync(o))continue;const t=fs.readFileSync(o,"utf8");if(/\bimport\s.+from\s+['"]/.test(t)||/\bexport\s+default\b/.test(t))return"esm";if(/\brequire\(/.test(t)||/\bmodule\.exports\b/.test(t))return"cjs"}return"cjs"}function requireMongofire(){try{return require(path.join(__dirname,"..","dist","src","index.cjs"))}catch(e){}try{return require(path.join(__dirname,"..","src","index.cjs"))}catch(e){console.error("\u2716 MongoFire core load failed:",e.message),process.exit(1)}}function resolveConfigPath(e){for(const n of["mongofire.config.js","mongofire.config.mjs","mongofire.config.cjs"]){const o=path.join(e,n);if(fs.existsSync(o))return o}return null}async function loadConfig(e,n){const o=path.extname(e).toLowerCase();if(".mjs"===o)return loadESM(e);if(".cjs"===o)return require(e);if("module"===readPackageJson(n)?.type)return loadESM(e);try{return require(e)}catch(n){if("ERR_REQUIRE_ESM"===n?.code)return loadESM(e);throw n}}async function loadESM(e){const n=await import(pathToFileURL(e).href);return n.default||n}function readPackageJson(e){const n=path.join(e,"package.json");if(!fs.existsSync(n))return null;try{return JSON.parse(fs.readFileSync(n,"utf8"))}catch{return null}}function escapeRE(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function buildFallbackClack(){const e=require("readline");let n;function o(o){return new Promise(t=>{const s=(n||(process.stdin.resume(),n=e.createInterface({input:process.stdin,output:process.stdout,terminal:IS_TTY}),n.on("error",()=>{})),n);s.once("close",()=>t("")),s.question(o,e=>t(e.trim()))})}return{isCancel:()=>!1,intro:e=>console.log(`\n\u250c ${e}\n\u2502`),outro:e=>{console.log(`\u2502\n\u2514 ${e}\n`),n&&n.close()},cancel:e=>{console.log(`\u2502\n\u2514 ${e}\n`),n&&n.close()},note:(e,n)=>{n&&console.log(`\u2502\n\u2502 ${n}`),e.split("\n").forEach(e=>console.log(`\u2502 ${e}`))},spinner:()=>({start:e=>process.stdout.write(`\u2502\n\u2502 ${e} `),stop:e=>console.log(`\u2192 ${e}`)}),async select({message:e,options:n,initialValue:t}){console.log(`\u2502\n\u25c7 ${e}`),n.forEach((e,n)=>{console.log(`\u2502 ${n+1}. ${e.label}${e.value===t?" \x1b[33m(default)\x1b[0m":""}${e.hint?`\x1b[2m \u2014 ${e.hint}\x1b[0m`:""}`)});const s=n.findIndex(e=>e.value===t),i=await o(`\u2502 Enter number [${s>=0?s+1:1}]: `),a=i?Math.max(0,parseInt(i,10)-1):s>=0?s:0;return n[a]?.value??n[0]?.value},async multiselect({message:e,options:n}){console.log(`\u2502\n\u25c7 ${e} (comma-separated numbers, blank = none)`),n.forEach((e,n)=>console.log(`\u2502 ${n+1}. ${e.label}${e.hint?" ("+e.hint+")":""}`));const t=await o("\u2502 Numbers: ");return t.trim()?t.split(",").map(e=>n[parseInt(e.trim(),10)-1]?.value).filter(Boolean):[]},async text({message:e,defaultValue:n,placeholder:t}){const s=n?` (default: ${n})`:t?` e.g. ${t}`:"";return(await o(`\u2502\n\u25c7 ${e}${s}\n\u2502 `)||"").trim()||n||""},async confirm({message:e,initialValue:n,hint:t}){const s=!1!==n;t&&console.log(`\u2502 \x1b[2m${t}\x1b[0m`);const i=(await o(`\u2502\n\u25c7 ${e} (${s?"Y/n":"y/N"}) `)||"").trim().toLowerCase();return""===i?s:"y"===i||"yes"===i}}}
|
|
2
|
+
"use strict";process.env.MONGOFIRE_CLI="1",process.on("uncaughtException",e=>{console.error("\n\u2716 MongoFire error:",e.message||e),process.env.MONGOFIRE_DEBUG&&console.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{console.error("\n\u2716 MongoFire error:",e?.message||e),process.env.MONGOFIRE_DEBUG&&console.error(e?.stack||e),process.exit(1)});const fs=require("fs"),path=require("path"),{pathToFileURL:pathToFileURL}=require("url"),args=process.argv.slice(2),command=args[0],flags=new Set(args.slice(1));flags.has("--esm")&&flags.has("--cjs")&&(console.error("\u2716 Use only one: --esm OR --cjs"),process.exit(1)),function(){const e=path.join(process.cwd(),".env");if(fs.existsSync(e))try{require("dotenv").config({path:e})}catch(e){}}();const IS_TTY=!!process.stdin.isTTY;function showHelp(){const e=_getVersion();console.log(`\n \x1b[33m\ud83d\udd25 MongoFire\x1b[0m \x1b[2mv${e}\x1b[0m\n\n \x1b[1mUsage\x1b[0m\n\n \x1b[36mnpx mongofire\x1b[0m \x1b[2m<command> [flags]\x1b[0m\n\n \x1b[1mCommands\x1b[0m\n\n \x1b[36minit\x1b[0m Interactive setup wizard\n \x1b[36mconfig\x1b[0m Update an existing configuration \x1b[2m(TTY only)\x1b[0m\n \x1b[36mstatus\x1b[0m Show pending sync counts\n \x1b[36mclean\x1b[0m Delete old sync records\n \x1b[36mconflicts\x1b[0m View and resolve conflicts \x1b[2m(TTY only)\x1b[0m\n \x1b[36mreconcile\x1b[0m Recover writes lost from crashes\n \x1b[36mcompact\x1b[0m Compact the sync changelog (60\u201380% size reduction)\n \x1b[36mreset-local\x1b[0m Safely wipe local DB + all MongoFire state \x1b[2m(TTY only)\x1b[0m\n\n \x1b[1mFlags for \x1b[36minit\x1b[0m\n\n \x1b[2m--esm\x1b[0m Force ESM module format\n \x1b[2m--cjs\x1b[0m Force CommonJS module format\n \x1b[2m--force, -f\x1b[0m Overwrite existing config files\n\n \x1b[1mFlags for \x1b[36mclean\x1b[0m\n\n \x1b[2m--days=N\x1b[0m Delete records older than N days (1\u20133650, default 7)\n\n \x1b[1mFlags for \x1b[36mreconcile\x1b[0m\n\n \x1b[2m--no-full-scan\x1b[0m Skip Phase 2 (only check orphaned docmeta)\n \x1b[2m--collection=NAME\x1b[0m Scan a single collection instead of all\n\n \x1b[2mTip: set MONGOFIRE_DEBUG=1 for full error stack traces\x1b[0m\n`)}function _getVersion(){try{return require(path.join(__dirname,"..","package.json")).version}catch{return"?"}}async function loadClack(){try{return await import("@clack/prompts")}catch{return buildFallbackClack()}}(async()=>{if("init"===command){const e=flags.has("--esm")||flags.has("--cjs")||flags.has("--force")||flags.has("-f");!e&&IS_TTY?await doInitWizard():(e||process.stdout.write("\u2139 Non-interactive mode \u2014 use --cjs, --esm, --force for control\n\n"),doInitDirect({force:flags.has("--force")||flags.has("-f"),moduleSystem:flags.has("--esm")?"esm":flags.has("--cjs")?"cjs":null,flagForced:flags.has("--esm")||flags.has("--cjs")}))}else if("config"===command)IS_TTY?await doConfigWizard():(console.log("\u2139 config requires an interactive terminal."),process.exit(0));else if("status"===command)await doStatus();else if("clean"===command){![...flags].some(e=>e.startsWith("--days="))&&IS_TTY?await doCleanWizard():await doClean()}else if("conflicts"===command)IS_TTY?await doConflictsWizard():(console.log("\u2139 conflicts requires an interactive terminal."),process.exit(0));else if("reconcile"===command){const e=flags.has("--no-full-scan"),o=[...flags].find(e=>e.startsWith("--collection=")),n=o?o.split("=")[1]:null;await doReconcile({fullScan:!e,collection:n})}else"compact"===command?await doCompact():"reset-local"===command?IS_TTY?await doResetLocal():(console.log("\u2139 reset-local requires an interactive terminal (safety guard)."),process.exit(0)):showHelp()})().catch(e=>{console.error("\n\u2716 MongoFire error:",e.message||e),process.env.MONGOFIRE_DEBUG&&console.error(e.stack),process.exit(1)});const DEFAULT_COLLECTIONS="orders, products, users";function _info(e,o,n){const t=e=>e.length>58?e.slice(0,57)+"...":e;process.stdout.write("|\n"),process.stdout.write("\x1b[2m| +- \x1b[0m\x1b[1m"+e+"\x1b[0m\n");for(const e of o)""===e?process.stdout.write("\x1b[2m| |\x1b[0m\n"):e.startsWith("\u2713")?process.stdout.write("\x1b[2m| | \x1b[32m"+t(e)+"\x1b[0m\n"):e.startsWith("\u2715")?process.stdout.write("\x1b[2m| | \x1b[2m"+t(e)+"\x1b[0m\n"):e.startsWith("\u2192")?process.stdout.write("\x1b[2m| | \x1b[36m"+t(e)+"\x1b[0m\n"):process.stdout.write("\x1b[2m| | "+t(e)+"\x1b[0m\n");n?process.stdout.write("\x1b[2m| +- \ud83d\udca1 "+t(n)+"\x1b[0m\n"):process.stdout.write("\x1b[2m| +-\x1b[0m\n")}async function doInitWizard(){const e=await loadClack(),o=process.cwd();e.intro(`\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m v${_getVersion()} \x1b[0m`);const n=path.join(o,"mongofire.config.js"),t=path.join(o,"mongofire.js"),s=fs.existsSync(n),r=fs.existsSync(t);if(s){const o=[s&&"mongofire.config.js",r&&"mongofire.js"].filter(Boolean).join(", ");e.note(`\x1b[33m${o}\x1b[0m \x1b[2m\u2014 already exists in this directory\x1b[0m`,"Existing setup found");const n=await e.select({message:"What would you like to do?",options:[{value:"overwrite",label:"Overwrite",hint:"replace with fresh config \u2014 start from scratch"},{value:"config",label:"Update config",hint:"change collections, interval, or toggle options"},{value:"cancel",label:"Cancel",hint:"keep existing files unchanged"}],initialValue:"overwrite"});if(e.isCancel(n)||"cancel"===n)return void e.cancel("Cancelled \u2014 existing files kept.");if("config"===n)return e.outro("\x1b[2mOpening config wizard...\x1b[0m"),doConfigWizard()}_info("Module System",["How your project loads and shares code between files.","","\u2192 Auto-detect reads package.json + scans your source files","\u2192 CommonJS you write require() / module.exports","\u2192 ESM you write import / export"],"Not sure? Pick Auto-detect \u2014 correct for most projects.");const i=await e.select({message:"Module system",options:[{value:"auto",label:"Auto-detect",hint:"recommended \u2014 reads your project automatically"},{value:"cjs",label:"CommonJS",hint:"require() / module.exports"},{value:"esm",label:"ESM",hint:"import / export"}],initialValue:"auto"});if(e.isCancel(i))return _cancelled(e);_info("Real-Time Sync",["Controls how fast changes appear across all connected devices.","","\u2713 Enabled Atlas Change Streams \u2014 changes push within milliseconds","\u2715 Disabled Polling only \u2014 devices check every syncInterval","","If Change Streams are unavailable, falls back to polling silently."],"Recommended ON for most apps.");const a=await e.confirm({message:"Enable real-time sync?",hint:"ON = instant push OFF = polling only",initialValue:!0});if(e.isCancel(a))return _cancelled(e);_info("Multi-Tenant Mode",["Controls whether each user syncs only their own private data.","","\u2715 OFF Cafe system, team app, single business"," All users share the same data \u2014 simple and fast","","\u2713 ON SaaS platform, per-user notes, multi-business app"," Each user sees only their own documents"],"Keep OFF unless users must have isolated private data.");const l=await e.confirm({message:"Enable multi-tenant mode?",hint:"OFF = shared data (default) ON = per-user isolation",initialValue:!1});if(e.isCancel(l))return _cancelled(e);_info("TypeScript Hints",["Adds @ts-check + JSDoc types to mongofire.config.js.","","\u2713 Enabled VS Code shows autocomplete and catches typos"," Works perfectly in plain JavaScript projects"," No TypeScript compiler or tsconfig needed","","\u2715 Disabled Plain config file, no type annotations"],"Recommended ON \u2014 free autocomplete, zero setup cost.");const c=await e.confirm({message:"Add TypeScript hints?",hint:"ON = smart autocomplete in VS Code OFF = plain JS",initialValue:!0});if(e.isCancel(c))return _cancelled(e);_info("Verbose Logging",["Controls how much MongoFire prints to your console.","","\u2715 OFF Logs only when real changes happen (uploads/downloads)"," Clean output \u2014 good for production","","\u2713 ON Logs every sync cycle even when nothing changed"," Useful when debugging sync issues during development"],"Keep OFF in production. Enable temporarily to debug.");const m=await e.confirm({message:"Enable verbose logging?",hint:"OFF = clean logs (recommended) ON = log every cycle",initialValue:!1});if(e.isCancel(m))return _cancelled(e);const d=new Set([a&&"realtime",l&&"multitenant",c&&"typescript",m&&"verbose"].filter(Boolean));_info("Collections to Sync",["MongoDB collection names MongoFire will keep in sync.","","\u2192 Enter your actual collection names, comma-separated","\u2192 Must match exactly what your Mongoose models use","\u2192 Example: orders, products, users, categories"],"Press Enter to accept defaults \u2014 edit in mongofire.config.js anytime.");const u=await e.text({message:"Collections to sync",placeholder:DEFAULT_COLLECTIONS,defaultValue:DEFAULT_COLLECTIONS,validate:()=>{}});if(e.isCancel(u))return _cancelled(e);const f=((u||"").trim()||DEFAULT_COLLECTIONS).split(",").map(e=>e.trim()).filter(Boolean),p=d.has("realtime");_info("Sync Interval",["How often MongoFire polls Atlas for new changes.","","\u2192 Lower changes appear faster, more bandwidth used","\u2192 Higher less resource usage, slight delay in updates","",p?"\u2713 Realtime is ON \u2014 polling is just a safety net. 5s is ideal.":"\u2192 No realtime \u2014 30s is the sweet spot for most apps."],"You can change this in mongofire.config.js at any time.");const g=p?[{value:2e3,label:"2s",hint:"aggressive \u2014 high bandwidth usage"},{value:5e3,label:"5s",hint:"recommended with Change Streams"},{value:15e3,label:"15s",hint:"light fallback polling"}]:[{value:5e3,label:"5s",hint:"fast \u2014 great for dev and testing"},{value:15e3,label:"15s",hint:"balanced \u2014 low traffic apps"},{value:3e4,label:"30s",hint:"recommended for most apps"},{value:6e4,label:"60s",hint:"conservative \u2014 minimal DB load"}],h=await e.select({message:"Sync interval",options:g,initialValue:p?5e3:3e4});if(e.isCancel(h))return _cancelled(e);let y="*";if(d.has("multitenant")){_info("Owner Field",["The document field that identifies who owns each record.","","\u2192 Must exist on EVERY document in every synced collection","\u2192 MongoFire only syncs docs where this field = current user","\u2192 You must set this field when creating documents in your app","","Common names: userId, ownerId, createdBy, accountId"],"Set req.user._id into this field on every document you create.");const o=await e.text({message:"Owner field name",placeholder:"userId",defaultValue:"userId",hint:"must exist on every synced document"});if(e.isCancel(o))return _cancelled(e);y=(o||"").trim()||"userId"}const w=e=>e?"\x1b[32m\u25cf Enabled\x1b[0m":"\x1b[2m\u25cb Disabled\x1b[0m",v=[`Module system ${"auto"===i?"Auto-detect":i.toUpperCase()}`,`Real-time sync ${w(a)}`,`Multi-tenant ${w(l)}`,`TypeScript hints ${w(c)}`,`Verbose logging ${w(m)}`,`Sync interval ${h}ms`,`Collections ${f.join(", ")}`];d.has("multitenant")&&v.push(`Owner field ${y}`),e.note(v.join("\n"),"Configuration Summary");const _=await e.confirm({message:"Looks good \u2014 create these files?",initialValue:!0});if(e.isCancel(_)||!_)return void e.cancel("Cancelled \u2014 no files changed.");const C="auto"===i,$=C?detectModuleSystem(o,null):i,S={collections:f,realtime:a,syncInterval:h,ownerField:y,verbose:m,typescript:c},b=ensureEnvFile(path.join(o,".env")),F=writeFileIfNeeded(path.join(o,"mongofire.config.js"),buildConfigTemplate($,S),!0),j=writeFileIfNeeded(path.join(o,"mongofire.js"),buildEntryTemplate($,S),!0),x=collectPackageHints(o),M=["failed"===F.action&&{file:"mongofire.config.js",error:F.error},"failed"===j.action&&{file:"mongofire.js",error:j.error}].filter(Boolean);if(M.length>0){const o=M.map(e=>"\x1b[31m\u2715\x1b[0m "+e.file.padEnd(24)+"\x1b[2m"+e.error+"\x1b[0m");return o.push(""),o.push("\x1b[2mTip: close the file in VS Code or any editor, then run init again.\x1b[0m"),e.note(o.join("\n"),"\x1b[31mCould not write files\x1b[0m"),void e.cancel("Setup incomplete \u2014 some files could not be written.")}const E=[_fileRow(".env",b.action),_fileRow("mongofire.config.js",F.action),_fileRow("mongofire.js",j.action)];x.length&&E.push("",...x.map(e=>"\x1b[33m\u26a0\x1b[0m "+e)),e.note(E.join("\n"),"Files created");e.note(["Fill in \x1b[36mATLAS_URI\x1b[0m inside \x1b[2m.env\x1b[0m","esm"===$?"Add \x1b[2mimport './mongofire.js'\x1b[0m to your app entry point":"Add \x1b[2mrequire('./mongofire')\x1b[0m to your app entry point",`Replace \x1b[2mapp.listen()\x1b[0m with \x1b[32mstartApp(app, port)\x1b[0m:\n \x1b[2m${"esm"===$?"import { startApp } from './mongofire.js'; startApp(app, process.env.PORT || 3000);":"const { startApp } = require('./mongofire'); startApp(app, process.env.PORT || 3000);"}\x1b[0m`,"Add \x1b[2mSchema.plugin(plugin('name'))\x1b[0m to each model \u2014 import plugin from mongofire.js","\x1b[31mDO NOT\x1b[0m call \x1b[2mmongoose.connect()\x1b[0m \u2014 MongoFire owns the local connection"].map((e,o)=>`${o+1}. ${e}`).join("\n"),"Next steps"),e.outro(`\x1b[32m\u2713 Setup complete!\x1b[0m \x1b[2m${$.toUpperCase()} \xb7 ${C?"auto-detected":"manual"}\x1b[0m`)}async function doConfigWizard(){const e=await loadClack(),o=process.cwd(),n=path.join(o,"mongofire.config.js");fs.existsSync(n)||(console.log("\n\u2716 No mongofire.config.js found \u2014 run npx mongofire init first.\n"),process.exit(1)),e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m config \x1b[0m");const t=await e.select({message:"What do you want to change?",options:[{value:"collections",label:"Collections to sync"},{value:"interval",label:"Sync interval"},{value:"realtime",label:"Real-time sync toggle"},{value:"multitenant",label:"Multi-tenant owner field"},{value:"regenerate",label:"Regenerate all files",hint:"runs full wizard"}]});if(e.isCancel(t))return _cancelled(e);if("regenerate"===t)return e.outro(""),doInitWizard();let s="";try{s=fs.readFileSync(n,"utf8")}catch(e){}if("collections"===t){const o=s.match(/collections:\s*\[([\s\S]*?)\]/),t=o?o[1].replace(/['"\s]/g,"").split(",").filter(Boolean).join(", "):"users, products",r=await e.text({message:"Collections to sync",defaultValue:t,placeholder:t});if(e.isCancel(r))return _cancelled(e);const i=r.split(",").map(e=>e.trim()).filter(Boolean),a=i.map(e=>` '${e}',`).join("\n");fs.writeFileSync(n,s.replace(/collections:\s*\[([\s\S]*?)\]/,`collections: [\n${a}\n ]`),"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m collections \u2192 ${i.join(", ")}`)}else if("interval"===t){const o=await e.select({message:"New sync interval",options:[{value:5e3,label:"5s",hint:"dev"},{value:15e3,label:"15s",hint:"balanced"},{value:3e4,label:"30s",hint:"recommended"},{value:6e4,label:"60s",hint:"conservative"}],initialValue:3e4});if(e.isCancel(o))return _cancelled(e);const t=s.replace(/syncInterval:\s*\d+/,`syncInterval: ${o}`);if(t===s)return void e.cancel("\u2716 Could not find syncInterval in config \u2014 edit manually.");fs.writeFileSync(n,t,"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m syncInterval \u2192 ${o}ms`)}else if("realtime"===t){const o=/realtime:\s*true/.test(s),t=await e.confirm({message:"Enable real-time sync?",initialValue:!o});if(e.isCancel(t))return _cancelled(e);const r=s.replace(/realtime:\s*(true|false)/,`realtime: ${t}`);if(r===s)return void e.cancel("\u2716 Could not find realtime field in config \u2014 edit manually.");fs.writeFileSync(n,r,"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m realtime \u2192 ${t}`)}else if("multitenant"===t){const o=await e.text({message:"Owner field path (use '*' to disable)",defaultValue:"userId",placeholder:"userId"});if(e.isCancel(o))return _cancelled(e);const t=s.replace(/syncOwner:\s*['"][^'"]*['"]/,`syncOwner: '${o}'`);if(t===s)return void e.cancel("\u2716 Could not find syncOwner in config \u2014 edit manually.");fs.writeFileSync(n,t,"utf8"),e.outro(`\x1b[32mUpdated\x1b[0m syncOwner \u2192 ${o}`)}}function doInitDirect(e){const o=process.cwd(),n=detectModuleSystem(o,e.moduleSystem),t=e.flagForced?`--${n}`:"auto-detected",s=ensureEnvFile(path.join(o,".env")),r=writeFileIfNeeded(path.join(o,"mongofire.config.js"),buildConfigTemplate(n,{collections:["users","products"],realtime:!1,syncInterval:3e4,ownerField:"*"}),!!e.force),i=writeFileIfNeeded(path.join(o,"mongofire.js"),buildEntryTemplate(n,{}),!!e.force),a=collectPackageHints(o);console.log(`\x1b[33m \ud83d\udd25 MongoFire\x1b[0m \x1b[2mv${_getVersion()}\x1b[0m\n`),console.log(_fileRow(".env",s.action)),console.log(_fileRow("mongofire.config.js",r.action)),console.log(_fileRow("mongofire.js",i.action)),e.force||"skipped"!==r.action&&"skipped"!==i.action||console.log("\n\x1b[2m Existing files kept \u2014 use --force to regenerate.\x1b[0m"),a.length&&(console.log(""),a.forEach(e=>console.log(`\x1b[33m \u26a0\x1b[0m ${e}`))),console.log(`\n\x1b[32m Done!\x1b[0m \x1b[2m${n.toUpperCase()} \xb7 ${t}\x1b[0m\n`)}async function doStatus(){const e=await loadClack(),o=process.cwd(),n=resolveConfigPath(o);if(!n)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m status \x1b[0m");const t=e.spinner();t.start("Connecting\u2026");const s=await loadConfig(n,o),r=requireMongofire();await r.start(s);const i=await r.status();t.stop("Connected");e.note([`Atlas ${i.online?"\x1b[32m\u25cf online\x1b[0m":"\x1b[31m\u25cf offline\x1b[0m"}`,"",`Pending \x1b[1m${i.pending}\x1b[0m \x1b[2munsynced operations\x1b[0m`,` Creates ${i.creates}`,` Updates ${i.updates}`,` Deletes ${i.deletes}`].join("\n"),"Sync state"),e.outro(0===i.pending?"\x1b[32mAll caught up\x1b[0m":`\x1b[33m${i.pending} operation(s) pending\x1b[0m`),await r.stop(),process.exit(0)}async function doCleanWizard(){const e=await loadClack();e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m clean \x1b[0m");const o=await e.select({message:"Delete records synced longer than",options:[{value:1,label:"1 day",hint:"aggressive"},{value:3,label:"3 days"},{value:7,label:"7 days",hint:"recommended"},{value:14,label:"14 days"},{value:30,label:"30 days",hint:"conservative"}],initialValue:7});if(e.isCancel(o))return _cancelled(e);const n=await e.confirm({message:`Delete records older than ${o} day(s) \u2014 this cannot be undone`,initialValue:!1});!e.isCancel(n)&&n?await _runClean(e,o):e.cancel("Cancelled \u2014 nothing deleted.")}async function doClean(){const e=await loadClack();e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m clean \x1b[0m");const o=[...flags].find(e=>e.startsWith("--days=")),n=o?parseInt(o.split("=")[1],10):7;await _runClean(e,n)}async function _runClean(e,o){(!Number.isInteger(o)||o<1||o>3650)&&(console.error("\u2716 Invalid --days value (must be 1\u20133650)"),process.exit(1));const n=process.cwd(),t=resolveConfigPath(n);if(!t)return _noConfig(e);const s=e.spinner();s.start(`Deleting records older than ${o} day(s)\u2026`);const r=await loadConfig(t,n),i=requireMongofire();await i.start(r);const a=await i.clean(o);s.stop(`Deleted ${a} record(s)`),e.outro(a>0?`\x1b[32m${a} record(s) removed\x1b[0m`:"\x1b[2mNothing to clean\x1b[0m"),await i.stop(),process.exit(0)}async function doConflictsWizard(){const e=await loadClack(),o=process.cwd(),n=resolveConfigPath(o);if(!n)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m conflicts \x1b[0m");const t=e.spinner();t.start("Loading conflicts\u2026");const s=await loadConfig(n,o),r=requireMongofire();await r.start(s);const i=await r.conflicts();t.stop(`${i.length} conflict(s) found`),i.length||(e.outro("\x1b[32mNo unresolved conflicts\x1b[0m"),await r.stop(),process.exit(0));const a=i.map(e=>[`\x1b[1m${e.collection}/${e.docId}\x1b[0m \x1b[2mop:${e.type} v${e.version}\x1b[0m`,e.lastError?` \x1b[31m${e.lastError}\x1b[0m`:""].filter(Boolean).join("\n")).join("\n\n");e.note(a,`${i.length} unresolved conflict(s)`);const l=await e.select({message:"How do you want to resolve?",options:[{value:"retry_all",label:"Retry all",hint:"reset to pending, sync re-attempts"},{value:"dismiss_all",label:"Dismiss all",hint:"discard \u2014 keep local state"},{value:"pick_retry",label:"Pick one to retry"},{value:"pick_dismiss",label:"Pick one to dismiss"},{value:"nothing",label:"Do nothing"}]});if(e.isCancel(l))return _cancelled(e);if("nothing"===l)e.outro("\x1b[2mNo changes made\x1b[0m");else if("retry_all"===l){const o=e.spinner();o.start("Retrying\u2026");for(const e of i)await r.retryConflict(e.opId);o.stop(`Retried ${i.length} conflict(s)`),e.outro("\x1b[32mAll conflicts reset to pending\x1b[0m")}else if("dismiss_all"===l){const o=e.spinner();o.start("Dismissing\u2026");for(const e of i)await r.dismissConflict(e.opId);o.stop(`Dismissed ${i.length} conflict(s)`),e.outro("\x1b[32mAll conflicts dismissed\x1b[0m")}else{const o=await e.select({message:"Select conflict",options:i.map(e=>({value:e.opId,label:`${e.collection}/${e.docId}`,hint:`${e.type} v${e.version}`}))});if(e.isCancel(o))return _cancelled(e);"pick_retry"===l?(await r.retryConflict(o),e.outro("\x1b[32mConflict reset to pending\x1b[0m")):(await r.dismissConflict(o),e.outro("\x1b[32mConflict dismissed\x1b[0m"))}await r.stop(),process.exit(0)}async function doCompact(){const e=await loadClack(),o=process.cwd(),n=resolveConfigPath(o);if(!n)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m compact \x1b[0m");const t=[...flags].find(e=>e.startsWith("--days=")),s=t?parseInt(t.split("=")[1],10):7,r=[...flags].find(e=>e.startsWith("--collection=")),i=r?r.split("=")[1]:null;(!Number.isInteger(s)||s<1||s>3650)&&(console.error("\u2716 Invalid --days value (must be 1\u20133650)"),process.exit(1));const a=e.spinner();a.start(`Compacting changelog (retention: ${s} day(s)${i?`, collection: ${i}`:""})\u2026`);const l=await loadConfig(n,o),c=requireMongofire();await c.start(l);const m=await c.compact({retentionDays:s,collection:i||void 0,verbose:!1});a.stop(`Done \u2014 scanned ${m.scanned}, deleted ${m.deleted}, kept ${m.kept} (${m.durationMs}ms)`),e.outro(m.deleted>0?`\x1b[32m${m.deleted} superseded row(s) removed\x1b[0m`:"\x1b[2mNothing to compact \u2014 changelog is already lean\x1b[0m"),await c.stop(),process.exit(0)}async function doReconcile(e={}){const o=await loadClack(),n=process.cwd(),t=resolveConfigPath(n);if(!t)return _noConfig(o);o.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m reconcile \x1b[0m");const s=!1!==e.fullScan,r=s?"full scan":"Phase 1 only (--no-full-scan)",i=o.spinner();i.start(`Scanning for lost writes\u2026 \x1b[2m(${r})\x1b[0m`);const a=await loadConfig(t,n),l=requireMongofire();await l.start(a);const c=e.collection?e.collection:{fullScan:s,verbose:!0},m=await l.reconcile(c,{fullScan:s,verbose:!0}),d=m.reduce((e,o)=>e+(o.totalQueued||0),0);i.stop("Scan complete");const u=m.map(e=>{if(e.error)return`\x1b[31m\u2716\x1b[0m ${e.collection} \x1b[2m${e.error}\x1b[0m`;return`${(e.phase1?.queued||0)+(e.phase2?.queued||0)>0?"\x1b[33m\u21bb\x1b[0m":"\x1b[32m\u2713\x1b[0m"} \x1b[1m${e.collection}\x1b[0m \x1b[2mP1:${e.phase1?.queued||0} P2:${e.phase2?.queued||0} re-queued\x1b[0m`}).join("\n");o.note(u,"Results"),o.outro(d>0?`\x1b[33m${d} lost write(s) recovered\x1b[0m`:"\x1b[32mNo untracked operations found\x1b[0m"),await l.stop(),process.exit(0)}function buildConfigTemplate(e,o={}){const n=(o.collections?.length?o.collections:["orders","products","users"]).map(e=>` '${e}',`).join("\n"),t=o.ownerField&&"*"!==o.ownerField?o.ownerField:"*",s=o.typescript?'\n// @ts-check\n/** @type {import("mongofire").SyncConfig} */':"",r=!!o.verbose,i=r?" console.log(`[MongoFire] \u2191${result.uploaded} \u2193${result.downloaded} DEL:${result.deleted}`);":" if (result.deleted + result.downloaded + result.uploaded > 0) {\n console.log(`[MongoFire] Synced: \u2191${result.uploaded} \u2193${result.downloaded} DEL:${result.deleted}`);\n }",a=[" // \u2500\u2500 Required \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"," localUri: process.env.LOCAL_URI || 'mongodb://127.0.0.1:27017',"," atlasUri: process.env.ATLAS_URI,"," dbName: process.env.DB_NAME || 'myapp',",""," collections: [",n," ],",""," // \u2500\u2500 Sync behaviour \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",` syncInterval: ${o.syncInterval||3e4}, // ms \u2014 minimum 500`," batchSize: 200, // docs per upload batch (1\u201310000)",` realtime: ${!!o.realtime}, // Atlas Change Streams \u2014 instant push`,` syncOwner: '${t}', // '*' = all data \xb7 'userId' = per-user isolation`,""," // \u2500\u2500 Maintenance (safe defaults \u2014 change when needed) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"," cleanDays: 7, // auto-delete synced records older than N days"," reconcileOnStart: true, // repair writes lost to crashes on startup",` verbose: ${String(r).padEnd(5)}, // log every sync cycle (useful for debugging)`,""," // \u2500\u2500 Advanced (disabled by default \u2014 uncomment to enable) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"," // autoCompact: true, // compact changelog (60\u201380% size reduction)"," // compactEvery: 100, // run compaction every N sync cycles"," // compactRetentionDays: 7, // keep rows newer than this after compaction"," // rateLimiter: { // protect Atlas from sync storms"," // tokenBucket: { capacity: 100, refillRate: 50 },"," // circuitBreaker: { failureThreshold: 5, timeout: 30000 },"," // },","*"===t?" // syncOwner: 'userId', // uncomment for multi-tenant (per-user sync)":` // multi-tenant ON: only syncs docs where document.${t} === syncOwner value`,""," // \u2500\u2500 Callbacks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"," onSync(result) {",i," },"," onError(err) {"," console.error('[MongoFire] Sync error:', err.message);"," },"].join("\n");return"esm"===e?`${s}\nimport 'dotenv/config';\n\n// MongoFire configuration (ESM)\nexport default {\n${a}\n};\n`:`${s}\n'use strict';\ntry { require('dotenv').config(); } catch (_) {}\n\n// MongoFire configuration (CommonJS)\nmodule.exports = {\n${a}\n};\n`}function buildEntryTemplate(e,o={}){const n=o.verbose?"_mongofire.on('sync', (r) => console.log(`\ud83d\udd04 [MongoFire] Synced: \u2191${r.uploaded} \u2193${r.downloaded} DEL:${r.deleted}`));":"_mongofire.on('sync', (r) => {\n if (r.uploaded + r.downloaded + r.deleted > 0) {\n console.log(`\ud83d\udd04 [MongoFire] Sync complete \u2014 \u2191${r.uploaded} uploaded \u2193${r.downloaded} downloaded \ud83d\uddd1 ${r.deleted} deleted`);\n }\n});";return"esm"===e?["// mongofire.js \u2014 ESM production entry point","//","// \u26a0\ufe0f DO NOT call mongoose.connect() \u2014 MongoFire handles this automatically.","//","// server.js usage:","// import { startApp } from './mongofire.js';","// startApp(app, process.env.PORT || 3000);","//","// model.js usage:","// import { plugin } from './mongofire.js';","// UserSchema.plugin(plugin('users'));","","import { createRequire } from 'module';","import { fileURLToPath, pathToFileURL } from 'url';","import path from 'path';","import fs from 'fs';","","const require = createRequire(import.meta.url);","const __dirname = path.dirname(fileURLToPath(import.meta.url));","","// Load .env synchronously \u2014 dotenv is CJS, always safe to require()","try {"," const e = [path.join(process.cwd(),'.env'), path.join(__dirname,'.env')].find(p => fs.existsSync(p));"," if (e) require('dotenv').config({ path: e });","} catch (_) {}","","const _mongofire = require('mongofire');","","_mongofire.on('localReady', () => console.log('\u2705 [MongoFire] Local MongoDB connected'));","_mongofire.on('online', () => console.log('\ud83c\udf10 [MongoFire] Atlas connected \u2014 sync active'));","_mongofire.on('offline', () => console.log('\ud83d\udcf4 [MongoFire] Atlas offline \u2014 changes queued locally'));",n,"_mongofire.on('error', (err) => console.error('\u274c [MongoFire] Error:', err?.message || err));","","// loadConfigFile() auto-detects CJS/ESM \u2014 safe on Node 22+ (no ERR_INTERNAL_ASSERTION)","async function _loadAndStart() {"," const result = await _mongofire.loadConfigFile([process.cwd(), __dirname]);"," if (!result) { console.error('\\n\u274c mongofire.config.js not found. Run: npx mongofire init\\n'); process.exit(1); }"," if (!result.config?.collections?.length) { console.error('\\n\u274c mongofire.config.js has no collections.\\n'); process.exit(1); }"," return _mongofire.start(result.config);","}","const _startPromise = _loadAndStart();","","export async function startApp(app, port = 3000) {"," await _startPromise.catch(() => {});"," try {"," await _mongofire.localReady;"," } catch (err) {"," console.error('\\n\u274c [MongoFire] Local MongoDB failed to connect.\\n' +"," ` Reason: ${err?.message || err}\\n` +"," ' Server will NOT start in a broken state.\\n');"," process.exit(1);"," }"," return new Promise((resolve, reject) => {"," const server = app.listen(Number(port) || 3000, (err) => {"," if (err) { console.error('\u274c Server listen failed:', err.message); reject(err); process.exit(1); }"," console.log(`\ud83d\ude80 [MongoFire] Server ready on port ${port}`);"," resolve(server);"," });"," server.on('error', (err) => { console.error('\u274c Server error:', err.message); reject(err); process.exit(1); });"," });","}","","export function plugin(collectionName, options = {}) {"," return _mongofire.plugin(collectionName, options);","}","","export const localReady = _mongofire.localReady;","export const ready = _startPromise;","export { _mongofire as mongofire };","export default _mongofire;",""].join("\n"):["// mongofire.js \u2014 CJS production entry point","//","// \u26a0\ufe0f DO NOT call mongoose.connect() \u2014 MongoFire handles this automatically.","//","// server.js usage:","// const { startApp } = require('./mongofire');","// startApp(app, process.env.PORT || 3000);","//","// model.js usage:","// const { plugin } = require('./mongofire');","// UserSchema.plugin(plugin('users'));","","'use strict';","const _mongofire = require('mongofire');","const _config = require('./mongofire.config');","","_mongofire.on('localReady', () => console.log('\u2705 [MongoFire] Local MongoDB connected'));","_mongofire.on('online', () => console.log('\ud83c\udf10 [MongoFire] Atlas connected \u2014 sync active'));","_mongofire.on('offline', () => console.log('\ud83d\udcf4 [MongoFire] Atlas offline \u2014 changes queued locally'));",n,"_mongofire.on('error', (err) => console.error('\u274c [MongoFire] Error:', err?.message || err));","","const _startPromise = _mongofire.start(_config);","","async function startApp(app, port = 3000) {"," try {"," await _mongofire.localReady;"," } catch (err) {"," console.error('\\n\u274c [MongoFire] Local MongoDB failed to connect.\\n' +"," ` Reason: ${err?.message || err}\\n` +"," ' Server will NOT start in a broken state.\\n');"," process.exit(1);"," }"," return new Promise((resolve, reject) => {"," const server = app.listen(Number(port) || 3000, (err) => {"," if (err) { console.error('\u274c Server listen failed:', err.message); reject(err); process.exit(1); }"," console.log(`\ud83d\ude80 [MongoFire] Server ready on port ${port}`);"," resolve(server);"," });"," server.on('error', (err) => { console.error('\u274c Server error:', err.message); reject(err); process.exit(1); });"," });","}","","function plugin(collectionName, options = {}) {"," return _mongofire.plugin(collectionName, options);","}","","module.exports = { startApp, plugin, mongofire: _mongofire, ready: _startPromise, localReady: _mongofire.localReady };",""].join("\n")}function ensureEnvFile(e){const o=[["ATLAS_URI","mongodb+srv://USERNAME:PASSWORD@cluster0.xxxxx.mongodb.net/"],["LOCAL_URI","mongodb://127.0.0.1:27017"],["DB_NAME","myapp"]];if(!fs.existsSync(e))return fs.writeFileSync(e,"# MongoFire\n"+o.map(([e,o])=>`${e}=${o}`).join("\n")+"\n","utf8"),{action:"created"};const n=fs.readFileSync(e,"utf8"),t=o.filter(([e])=>!new RegExp(`^\\s*${escapeRE(e)}\\s*=`,"m").test(n));return t.length?(fs.appendFileSync(e,"\n# MongoFire\n"+t.map(([e,o])=>`${e}=${o}`).join("\n")+"\n","utf8"),{action:"updated"}):{action:"unchanged"}}function writeFileIfNeeded(e,o,n){const t=fs.existsSync(e);if(t&&!n)return{action:"skipped"};const s=e+".mftmp";try{if(fs.writeFileSync(s,o,"utf8"),t)try{fs.unlinkSync(e)}catch(e){}fs.renameSync(s,e)}catch(n){try{fs.unlinkSync(s)}catch(e){}fs.writeFileSync(e,o,{encoding:"utf8",flag:"w"})}return{action:t?"overwritten":"created"}}function collectPackageHints(e){const o=readPackageJson(e),n=Object.assign({},o?.dependencies,o?.devDependencies,o?.peerDependencies),t=[];return n.mongoose||t.push("mongoose not installed \u2014 npm i mongoose"),n.dotenv||t.push("dotenv not installed \u2014 npm i dotenv"),t}function _fileRow(e,o){return` ${{created:"\x1b[32m+\x1b[0m",overwritten:"\x1b[33m~\x1b[0m",skipped:"\x1b[2m\u2013\x1b[0m",unchanged:"\x1b[2m\u2013\x1b[0m",updated:"\x1b[32m+\x1b[0m"}[o]||" "} ${e.padEnd(24)}${{created:"\x1b[2mcreated\x1b[0m",overwritten:"\x1b[33mupdated\x1b[0m",skipped:"\x1b[2mexists\x1b[0m",unchanged:"\x1b[2munchanged\x1b[0m",updated:"\x1b[2mupdated\x1b[0m"}[o]||o}`}async function doResetLocal(){const e=await loadClack(),o=process.cwd(),n=resolveConfigPath(o);if(!n)return _noConfig(e);e.intro("\x1b[33m \ud83d\udd25 MongoFire \x1b[0m\x1b[2m reset-local \x1b[0m"),e.note(["\x1b[1mThis will permanently delete:\x1b[0m"," \u2022 All MongoFire internal collections (_mf_changetrack, _mf_docmeta,"," _mf_sync_state, _mf_ops)"," \u2022 All configured data collections listed in mongofire.config.js","","The next startup will re-bootstrap from Atlas.","\x1b[31mAny unsynced local changes will be lost.\x1b[0m"].join("\n"),"WARNING");const t=await e.confirm({message:"Are you sure you want to reset the entire local database?",initialValue:!1});if(e.isCancel(t)||!t)return void e.cancel("Cancelled \u2014 nothing was deleted.");const s=e.spinner();let r;s.start("Connecting to local MongoDB\u2026");try{r=await loadConfig(n,o)}catch(o){s.stop("Failed to load config"),e.cancel(`Config error: ${o.message}`),process.exit(1)}const i=requireMongofire();await i.start(r);const a=i._conn?.local||i.conn?.local,l=Array.isArray(r.collections)?r.collections:[],c=[...new Set(["_mf_changetrack","_mf_docmeta","_mf_sync_state","_mf_ops","_mf_devices",...l])];s.start(`Dropping ${c.length} collection(s)\u2026`);let m=0,d=0;for(const e of c)try{await a.collection(e).drop(),m++}catch(o){o.message?.includes("ns not found")||o.codeName?.includes("NamespaceNotFound")||(d++,console.error(`\n\u2716 Failed to drop "${e}":`,o.message))}s.stop(`Dropped ${m} collection(s)${d?`, ${d} error(s)`:""}`),e.outro(0===d?"\x1b[32mLocal database reset complete.\x1b[0m Start your app to re-bootstrap from Atlas.":`\x1b[33mReset finished with ${d} error(s).\x1b[0m Check logs above.`),await i.stop(),process.exit(0)}function _cancelled(e){e.cancel("Cancelled."),process.exit(0)}function _noConfig(e){e.cancel("No mongofire.config.js found \u2014 run npx mongofire init first."),process.exit(1)}function detectModuleSystem(e,o){if(o&&"auto"!==o)return o;const n=readPackageJson(e);if("module"===n?.type)return"esm";if("commonjs"===n?.type)return"cjs";const t=["index.js","app.js","server.js","main.js",path.join("src","index.js"),path.join("src","main.js")];for(const o of t){const n=path.join(e,o);if(!fs.existsSync(n))continue;const t=fs.readFileSync(n,"utf8");if(/\bimport\s.+from\s+['"]/.test(t)||/\bexport\s+default\b/.test(t))return"esm";if(/\brequire\(/.test(t)||/\bmodule\.exports\b/.test(t))return"cjs"}return"cjs"}function requireMongofire(){try{return require(path.join(__dirname,"..","dist","src","index.cjs"))}catch(e){}try{return require(path.join(__dirname,"..","src","index.cjs"))}catch(e){console.error("\u2716 MongoFire core load failed:",e.message),process.exit(1)}}function resolveConfigPath(e){for(const o of["mongofire.config.js","mongofire.config.mjs","mongofire.config.cjs"]){const n=path.join(e,o);if(fs.existsSync(n))return n}return null}async function loadConfig(e){const o=await import(pathToFileURL(e).href);return void 0!==o.default?o.default:o}async function loadESM(e){return loadConfig(e)}function readPackageJson(e){const o=path.join(e,"package.json");if(!fs.existsSync(o))return null;try{return JSON.parse(fs.readFileSync(o,"utf8"))}catch{return null}}function escapeRE(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function buildFallbackClack(){const e=require("readline");let o;function n(n){return new Promise(t=>{const s=(o||(process.stdin.resume(),o=e.createInterface({input:process.stdin,output:process.stdout,terminal:IS_TTY}),o.on("error",()=>{})),o);s.once("close",()=>t("")),s.question(n,e=>t(e.trim()))})}return{isCancel:()=>!1,intro:e=>console.log(`\n\u250c ${e}\n\u2502`),outro:e=>{console.log(`\u2502\n\u2514 ${e}\n`),o&&o.close()},cancel:e=>{console.log(`\u2502\n\u2514 ${e}\n`),o&&o.close()},note:(e,o)=>{o&&console.log(`\u2502\n\u2502 ${o}`),e.split("\n").forEach(e=>console.log(`\u2502 ${e}`))},spinner:()=>({start:e=>process.stdout.write(`\u2502\n\u2502 ${e} `),stop:e=>console.log(`\u2192 ${e}`)}),async select({message:e,options:o,initialValue:t}){console.log(`\u2502\n\u25c7 ${e}`),o.forEach((e,o)=>{console.log(`\u2502 ${o+1}. ${e.label}${e.value===t?" \x1b[33m(default)\x1b[0m":""}${e.hint?`\x1b[2m \u2014 ${e.hint}\x1b[0m`:""}`)});const s=o.findIndex(e=>e.value===t),r=await n(`\u2502 Enter number [${s>=0?s+1:1}]: `),i=r?Math.max(0,parseInt(r,10)-1):s>=0?s:0;return o[i]?.value??o[0]?.value},async multiselect({message:e,options:o}){console.log(`\u2502\n\u25c7 ${e} (comma-separated numbers, blank = none)`),o.forEach((e,o)=>console.log(`\u2502 ${o+1}. ${e.label}${e.hint?" ("+e.hint+")":""}`));const t=await n("\u2502 Numbers: ");return t.trim()?t.split(",").map(e=>o[parseInt(e.trim(),10)-1]?.value).filter(Boolean):[]},async text({message:e,defaultValue:o,placeholder:t}){const s=o?` (default: ${o})`:t?` e.g. ${t}`:"";return(await n(`\u2502\n\u25c7 ${e}${s}\n\u2502 `)||"").trim()||o||""},async confirm({message:e,initialValue:o,hint:t}){const s=!1!==o;t&&console.log(`\u2502 \x1b[2m${t}\x1b[0m`);const r=(await n(`\u2502\n\u25c7 ${e} (${s?"Y/n":"y/N"}) `)||"").trim().toLowerCase();return""===r?s:"y"===r||"yes"===r}}}
|
package/dist/src/changetrack.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';(function(_0x5ca374,_0x27184e){const _0x4e35c0={_0x2574c5:0x462,_0x1d1189:0x432,_0x3066eb:0x47c,_0x5ba565:0x432,_0x29a95c:0x44d,_0x5e66bf:0x404,_0x5d922b:0x426,_0x54704a:0x45f,_0x4a8e77:0x429,_0x51763c:0x46c,_0x586d07:0x461,_0x900557:0x44c,_0x4d45a7:0x456},_0x12cf97=_0x5ca374();function _0x4f66a8(_0x24253f,_0x5e763e){return _0x4840(_0x5e763e-0x3ae,_0x24253f);}while(!![]){try{const _0x4c8971=-parseInt(_0x4f66a8(0x466,_0x4e35c0._0x2574c5))/0x1*(-parseInt(_0x4f66a8(_0x4e35c0._0x1d1189,0x454))/0x2)+-parseInt(_0x4f66a8(_0x4e35c0._0x3066eb,0x466))/0x3*(-parseInt(_0x4f66a8(0x40a,_0x4e35c0._0x5ba565))/0x4)+-parseInt(_0x4f66a8(0x427,_0x4e35c0._0x29a95c))/0x5+parseInt(_0x4f66a8(0x42e,0x445))/0x6*(-parseInt(_0x4f66a8(_0x4e35c0._0x5e66bf,_0x4e35c0._0x5d922b))/0x7)+parseInt(_0x4f66a8(0x454,_0x4e35c0._0x54704a))/0x8*(-parseInt(_0x4f66a8(_0x4e35c0._0x4a8e77,0x41f))/0x9)+-parseInt(_0x4f66a8(0x454,_0x4e35c0._0x51763c))/0xa*(parseInt(_0x4f66a8(0x44a,_0x4e35c0._0x586d07))/0xb)+parseInt(_0x4f66a8(_0x4e35c0._0x900557,_0x4e35c0._0x4d45a7))/0xc;if(_0x4c8971===_0x27184e)break;else _0x12cf97['push'](_0x12cf97['shift']());}catch(_0x147b94){_0x12cf97['push'](_0x12cf97['shift']());}}}(_0x54fc,0x2d66f));const crypto=require('crypto'),defaultConn=require(_0x354435(-0x13e,-0x132)),{getDeviceId:getDeviceId}=require(_0x354435(-0x15c,-0x15b)),{asDate:asDate,asInt:asInt,metaId:metaId,safeDoc:safeDoc,payloadChecksum:payloadChecksum,resolveOwnerKey:resolveOwnerKey,getReturnBeforeOpt:getReturnBeforeOpt,markReturnDocFallback:markReturnDocFallback}=require(_0x354435(-0x11e,-0x124)),MAX_RETRY_COUNT=0xa;let _conn=defaultConn;const MAX_PAYLOAD_BYTES=0xf00000;function _checkPayloadSize(_0x4ded6c,_0x453cc7){const _0x5d35ad={_0x1aeb31:0x266,_0x48d739:0x246,_0x1ab9cb:0x26c,_0x4b48af:0x272,_0x11ff02:0x277,_0x22d8c2:0x28a,_0x16af69:0x286,_0xaec877:0x293,_0x10990b:0x277,_0x4048f1:0x294};function _0x16129a(_0x1a06df,_0x1afd6a){return _0x354435(_0x1a06df- -0x13d,_0x1afd6a);}if(_0x4ded6c)try{const _0x5340e5=Buffer[_0x16129a(-_0x5d35ad._0x1aeb31,-_0x5d35ad._0x48d739)](JSON[_0x16129a(-_0x5d35ad._0x1ab9cb,-_0x5d35ad._0x4b48af)](_0x4ded6c),_0x16129a(-0x24f,-0x244));if(_0x5340e5>0xf00000)throw new Error(_0x16129a(-0x295,-_0x5d35ad._0x11ff02)+Math[_0x16129a(-0x265,-0x248)](_0x5340e5/0x400/0x400)+_0x16129a(-0x297,-0x2a6)+_0x453cc7+_0x16129a(-_0x5d35ad._0x22d8c2,-0x282));}catch(_0xc82585){if(_0xc82585[_0x16129a(-_0x5d35ad._0x16af69,-_0x5d35ad._0xaec877)][_0x16129a(-_0x5d35ad._0x10990b,-0x29f)](_0x16129a(-_0x5d35ad._0x4048f1,-0x26d)))throw _0xc82585;}}function _buildDoc({opId:_0x3c8d7c,op:_0x49edc5,collection:_0x1c94c4,docId:_0x1fad52,payload:_0x21e117,owner:_0x207163,deviceId:_0x223a2c,eventTime:_0x43db4e,baseVersion:_0x2cbf53,now:_0x307a51}){const _0x127ae2={_0x19f731:0x12d};function _0x1a1bf1(_0x2bc9cd,_0x52aa01){return _0x354435(_0x52aa01-0xe,_0x2bc9cd);}return{'opId':_0x3c8d7c,'type':_0x49edc5,'collection':_0x1c94c4,'docId':_0x1fad52,'payload':_0x21e117,'ownerKey':_0x207163,'deviceId':_0x223a2c,'timestamp':_0x43db4e,'updatedAt':_0x43db4e,'baseVersion':_0x2cbf53,'version':_0x2cbf53+0x1,'lastWriterDeviceId':_0x223a2c,'payloadChecksum':payloadChecksum(_0x21e117,!0x0),'synced':!0x1,'ackState':_0x1a1bf1(-0x13e,-_0x127ae2._0x19f731),'retryCount':0x0,'createdAt':_0x307a51||new Date(),'syncedAt':null,'remoteAckAt':null,'checksumVerifiedAt':null,'lastError':null};}async function recordChange(_0x15c233,_0x12419e,_0x2b8d28,_0x452622,_0x19e19f,_0x3b7b5f='global',_0x20a0c6={},_0x45a174){const _0xbcdd2b={_0x2af1ce:0x120,_0x1bd9ed:0x144,_0x206cf7:0x140,_0x4baaaa:0x11b,_0x288316:0x13b,_0x37e3ec:0xf3},_0x3b9d89={_0x2bfc12:0x257},_0x3f7ce9=_0x45a174||_conn,_0x43caf7=_0x3f7ce9[_0x2eb6b0(0x122,_0xbcdd2b._0x2af1ce)];if(!_0x43caf7)throw new Error(_0x2eb6b0(_0xbcdd2b._0x1bd9ed,_0xbcdd2b._0x206cf7));const _0x1c5887=_0x20a0c6?.['session']||null,_0x32f101=_normalizeDocId(_0x12419e),_0x32e4b5='delete'===_0x2b8d28?null:safeDoc(_0x452622);_checkPayloadSize(_0x32e4b5,_0x15c233+'/'+_0x32f101+'\x20('+_0x2b8d28+')');const _0x394a62=resolveOwnerKey({'ownerKey':_0x3b7b5f}),_0x5b5d59=asDate(_0x19e19f)||new Date(),_0x2f76ba=getDeviceId(),_0x2f0a70=crypto[_0x2eb6b0(0x140,_0xbcdd2b._0x4baaaa)](),_0x33a9cd=metaId(_0x15c233,_0x32f101),_0x748767=new Date();if(_0x3f7ce9[_0x2eb6b0(0x146,0x129)]&&!_0x1c5887){const _0x63174e=_0x3f7ce9[_0x2eb6b0(_0xbcdd2b._0x288316,0x113)][_0x2eb6b0(0x159,0x142)]();try{await _0x63174e[_0x2eb6b0(_0xbcdd2b._0x37e3ec,0x106)](()=>_doChangetrackWrite(_0x43caf7,_0x63174e,{'opId':_0x2f0a70,'op':_0x2b8d28,'collection':_0x15c233,'docId':_0x32f101,'payload':_0x32e4b5,'owner':_0x394a62,'deviceId':_0x2f76ba,'eventTime':_0x5b5d59,'mid':_0x33a9cd,'now':_0x748767}));}finally{await _0x63174e[_0x2eb6b0(0xf1,0x101)]();}return;}function _0x2eb6b0(_0x1c2583,_0x59ea12){return _0x354435(_0x59ea12-_0x3b9d89._0x2bfc12,_0x1c2583);}await _doChangetrackWrite(_0x43caf7,_0x1c5887,{'opId':_0x2f0a70,'op':_0x2b8d28,'collection':_0x15c233,'docId':_0x32f101,'payload':_0x32e4b5,'owner':_0x394a62,'deviceId':_0x2f76ba,'eventTime':_0x5b5d59,'mid':_0x33a9cd,'now':_0x748767});}async function _doChangetrackWrite(_0x38fcf0,_0x4d4a8e,{opId:_0x28a56c,op:_0xc5cd2c,collection:_0x3d9a1a,docId:_0x3d72db,payload:_0x439c53,owner:_0x2b4ed3,deviceId:_0x2a76b5,eventTime:_0x5de98f,mid:_0x230fa4,now:_0x408254}){const _0x15a8d8={_0x1eb9bd:0x1be,_0xde889f:0x1c3,_0x4e954f:0x20b},_0x15b0c9={_0x325ceb:0x31b},_0x20e8bd=_0x4d4a8e?{'session':_0x4d4a8e}:{},_0x4233ac=await _bumpLocalDocVersion(_0x38fcf0,{'metaId':_0x230fa4,'collection':_0x3d9a1a,'docId':_0x3d72db,'op':_0xc5cd2c,'ownerKey':_0x2b4ed3,'deviceId':_0x2a76b5,'updatedAt':_0x5de98f,'opId':_0x28a56c},_0x4d4a8e);function _0x22ed6f(_0x3b7f99,_0xbddd1a){return _0x354435(_0x3b7f99-_0x15b0c9._0x325ceb,_0xbddd1a);}await _0x38fcf0[_0x22ed6f(_0x15a8d8._0x1eb9bd,_0x15a8d8._0xde889f)](_0x22ed6f(_0x15a8d8._0x4e954f,0x1ec))['updateOne']({'opId':_0x28a56c},{'$setOnInsert':_buildDoc({'opId':_0x28a56c,'op':_0xc5cd2c,'collection':_0x3d9a1a,'docId':_0x3d72db,'payload':_0x439c53,'owner':_0x2b4ed3,'deviceId':_0x2a76b5,'eventTime':_0x5de98f,'baseVersion':_0x4233ac,'now':_0x408254})},{'upsert':!0x0,..._0x20e8bd});}async function recordChangeBulk(_0x2d0ed1,_0x163d4b=null,_0xed049d=0x8,_0x40cd98){const _0x12d9dd={_0x1e5eb4:0x94,_0x1f64d0:0x76,_0x487e6f:0x8b,_0x323be5:0x6f,_0x4b1a3a:0x96,_0x447182:0xae,_0x43e2a8:0xb3,_0x46b6eb:0xd9};function _0x10d57c(_0x32d85c,_0x1a047b){return _0x354435(_0x32d85c-0xa3,_0x1a047b);}const _0x4e418b=_0x40cd98||_conn,_0x5958e4=_0x4e418b[_0x10d57c(-_0x12d9dd._0x1e5eb4,-_0x12d9dd._0x1f64d0)];if(!_0x5958e4)throw new Error(_0x10d57c(-0x74,-0x7b));if(_0x2d0ed1?.[_0x10d57c(-0xa8,-0xcb)]){if(_0x4e418b[_0x10d57c(-_0x12d9dd._0x487e6f,-_0x12d9dd._0x323be5)]&&!_0x163d4b){const _0x2c1f3e=_0x4e418b['localClient'][_0x10d57c(-0x72,-_0x12d9dd._0x4b1a3a)]();try{await _0x2c1f3e[_0x10d57c(-_0x12d9dd._0x447182,-0xa4)](()=>_doRecordChangeBulk(_0x5958e4,_0x2d0ed1,_0x2c1f3e,_0xed049d));}finally{await _0x2c1f3e[_0x10d57c(-_0x12d9dd._0x43e2a8,-_0x12d9dd._0x46b6eb)]();}return;}await _doRecordChangeBulk(_0x5958e4,_0x2d0ed1,_0x163d4b,_0xed049d);}}async function _doRecordChangeBulk(_0x388e1e,_0x451903,_0x170525,_0x2e359d){const _0x489241={_0x2ac8b2:0xff,_0x576966:0x113,_0x121563:0x12a,_0x353428:0x10b,_0x2c6696:0x13d,_0xceace2:0x13f,_0x21e303:0x121,_0x540b87:0x13a,_0x57d8b6:0x13b,_0x2a4025:0x128,_0x48c770:0x15b,_0x11fb00:0x127,_0x3dc753:0x11b},_0xeddbb8={_0x5a4912:0x2c,_0x28cdfe:0x16,_0x4ea952:0x29,_0x47828a:0xc,_0x361eb0:0x6,_0x419864:0x13},_0x201f92=getDeviceId(),_0x4126c0=new Date(),_0x1f2ee9=Math[_0x4a5f10(-0x149,-0x132)](0x1,Math[_0x4a5f10(-_0x489241._0x2ac8b2,-0x102)](Number(_0x2e359d)||0x8,0x20)),_0x250872=new Map();for(const _0x5a7d8f of _0x451903){const _0x279936=_normalizeDocId(_0x5a7d8f['docId']);_0x250872[_0x4a5f10(-_0x489241._0x576966,-0x134)](_0x279936)||_0x250872[_0x4a5f10(-_0x489241._0x121563,-0x144)](_0x279936,[]),_0x250872[_0x4a5f10(-_0x489241._0x353428,-0x131)](_0x279936)[_0x4a5f10(-_0x489241._0x2c6696,-_0x489241._0xceace2)](_0x5a7d8f);}function _0x4a5f10(_0x2192f6,_0x4c8963){return _0x354435(_0x4c8963-0x11,_0x2192f6);}const _0x1b2d10=[..._0x250872[_0x4a5f10(-_0x489241._0x21e303,-0x13b)]()],_0x1b9374=[];for(let _0xc254ec=0x0;_0xc254ec<_0x1b2d10[_0x4a5f10(-0x11d,-_0x489241._0x540b87)];_0xc254ec+=_0x1f2ee9){const _0x51428f=_0x1b2d10[_0x4a5f10(-_0x489241._0x57d8b6,-0x142)](_0xc254ec,_0xc254ec+_0x1f2ee9),_0x72f282=await Promise['all'](_0x51428f[_0x4a5f10(-0x129,-_0x489241._0x2a4025)](async _0x1dbca7=>{const _0x5d88c0={_0x386b39:0x12c},_0x37163e=_0x250872[_0x1991a4(-0x5,0x5)](_0x1dbca7),_0x15da26=[];for(const _0x488f7d of _0x37163e){const {collection:_0x4be196,op:_0x301827,doc:_0x476936,updatedAt:_0x1db859,ownerKey:_0x522b47}=_0x488f7d,_0x188070='delete'===_0x301827?null:safeDoc(_0x476936);try{_checkPayloadSize(_0x188070,_0x4be196+'/'+_0x1dbca7+_0x1991a4(_0xeddbb8._0x5a4912,0x4e)+_0x301827+')');}catch(_0x2d2538){console[_0x1991a4(_0xeddbb8._0x28cdfe,_0xeddbb8._0x4ea952)]('[MongoFire]\x20recordChangeBulk:\x20skipping\x20oversized\x20doc\x20—',_0x2d2538[_0x1991a4(-_0xeddbb8._0x47828a,_0xeddbb8._0x361eb0)]);continue;}const _0x5c3f8a=resolveOwnerKey({'ownerKey':_0x522b47}),_0x4a1f7a=asDate(_0x1db859)||_0x4126c0,_0x20bffa=crypto['randomUUID'](),_0xecc8e1=metaId(_0x4be196,_0x1dbca7),_0x157817=await _bumpLocalDocVersion(_0x388e1e,{'metaId':_0xecc8e1,'collection':_0x4be196,'docId':_0x1dbca7,'op':_0x301827,'ownerKey':_0x5c3f8a,'deviceId':_0x201f92,'updatedAt':_0x4a1f7a,'opId':_0x20bffa},_0x170525);_0x15da26[_0x1991a4(-_0xeddbb8._0x419864,-0x2e)]({'updateOne':{'filter':{'opId':_0x20bffa},'update':{'$setOnInsert':_buildDoc({'opId':_0x20bffa,'op':_0x301827,'collection':_0x4be196,'docId':_0x1dbca7,'payload':_0x188070,'owner':_0x5c3f8a,'deviceId':_0x201f92,'eventTime':_0x4a1f7a,'baseVersion':_0x157817,'now':_0x4126c0})},'upsert':!0x0}});}function _0x1991a4(_0x3374dd,_0x26a90a){return _0x4a5f10(_0x26a90a,_0x3374dd-_0x5d88c0._0x386b39);}return _0x15da26;}));for(const _0x20dfef of _0x72f282)_0x1b9374[_0x4a5f10(-0x11c,-0x13f)](..._0x20dfef);}if(!_0x1b9374[_0x4a5f10(-0x150,-_0x489241._0x540b87)])return;const _0xc1ff07=_0x170525?{'session':_0x170525,'ordered':!0x1}:{'ordered':!0x1};await _0x388e1e[_0x4a5f10(-_0x489241._0x48c770,-0x14c)](_0x4a5f10(-_0x489241._0x11fb00,-0xff))[_0x4a5f10(-0x11b,-_0x489241._0x3dc753)](_0x1b9374,_0xc1ff07);}async function getPending(_0x491300,_0x3f28ec=0x1f4,_0x10d362=null,_0x39545e){const _0x490fb7={_0x5f135b:0x379,_0x1609cc:0x37e,_0x113666:0x384,_0x2d60cc:0x382,_0x518fbe:0x3aa,_0x523b2d:0x382,_0x694bf1:0x37a,_0x3d007b:0x3b6},_0x3d9b64={_0x13cee9:0x4c3};function _0x57ff43(_0x1de0ac,_0x4b66e3){return _0x354435(_0x1de0ac-_0x3d9b64._0x13cee9,_0x4b66e3);}const _0x51e550=_0x39545e||_conn,_0xa4b4c3={'synced':!0x1,'ackState':{'$nin':[_0x57ff43(_0x490fb7._0x5f135b,_0x490fb7._0x1609cc),_0x57ff43(0x39e,0x3c5),'superseded']},'$or':[{'ackState':{'$ne':_0x57ff43(0x39c,_0x490fb7._0x113666)}},{'retryCount':{'$lt':0xa}}]};return _0x491300&&(_0xa4b4c3['collection']=_0x491300),_0x10d362&&(_0xa4b4c3[_0x57ff43(0x37d,_0x490fb7._0x2d60cc)]={'$gt':_0x10d362}),_0x51e550[_0x57ff43(0x38c,_0x490fb7._0x518fbe)][_0x57ff43(0x366,_0x490fb7._0x523b2d)]('_mf_changetrack')['find'](_0xa4b4c3)[_0x57ff43(0x383,_0x490fb7._0x694bf1)]({'_id':0x1})[_0x57ff43(0x374,0x367)](_0x3f28ec)[_0x57ff43(0x3ad,_0x490fb7._0x3d007b)]();}async function markSynced(_0x2133eb,_0x45a09d={},_0x31e2f9){const _0x1542ca={_0x108dcc:0x13b,_0x5065a4:0x11c,_0x5b39f9:0x142},_0x13e1d7={_0x1ffa3f:0x10};if(!_0x2133eb?.[_0x120b71(-_0x1542ca._0x108dcc,-0x15d)])return;function _0x120b71(_0x307b1f,_0x314353){return _0x354435(_0x307b1f-_0x13e1d7._0x1ffa3f,_0x314353);}const _0x4d98c6=_0x31e2f9||_conn,_0x4ffff0=new Date();await _0x4d98c6['local']['collection'](_0x120b71(-0x100,-0x102))[_0x120b71(-0x126,-0x100)]({'_id':{'$in':_0x2133eb}},{'$set':{'synced':!0x0,'ackState':_0x45a09d[_0x120b71(-0x13e,-0x155)]||_0x120b71(-0xff,-_0x1542ca._0x5065a4),'syncedAt':_0x4ffff0,'remoteAckAt':_0x45a09d[_0x120b71(-_0x1542ca._0x5b39f9,-0x160)]||_0x4ffff0,'checksumVerifiedAt':_0x45a09d['checksumVerifiedAt']||null,'lastError':null}});}async function markFailed(_0x5bebac,_0x33f11d,_0x119b23='error',_0x360598){const _0x50a253={_0x3d9388:0x302,_0x561daa:0x2e3},_0x5a2212={_0x364023:0x1b1};if(!_0x5bebac)return;const _0x245b04=_0x360598||_conn;function _0x49178c(_0x2d75ba,_0x31b27d){return _0x354435(_0x2d75ba- -_0x5a2212._0x364023,_0x31b27d);}await _0x245b04['local'][_0x49178c(-0x30e,-_0x50a253._0x3d9388)]('_mf_changetrack')['updateOne']({'_id':_0x5bebac},{'$set':{'synced':!0x1,'ackState':_0x119b23,'lastError':_0x33f11d||_0x49178c(-0x2db,-_0x50a253._0x561daa)},'$inc':{'retryCount':0x1}});}async function cleanSynced(_0x1e38cc,_0x18fee5){if(!_0x1e38cc?.['length'])return;function _0x4ece99(_0x7404e8,_0x193728){return _0x354435(_0x193728-0x579,_0x7404e8);}const _0x5c7aac=_0x18fee5||_conn;await _0x5c7aac['local'][_0x4ece99(0x425,0x41c)](_0x4ece99(0x455,0x469))['deleteMany']({'_id':{'$in':_0x1e38cc},'synced':!0x0});}async function countPending(_0x5e6726){const _0x5e7cb2={_0x489cce:0x34c,_0x2d6a2b:0x326},_0x4c5fac={_0x16105e:0x46c};function _0x481a1e(_0x3f3c91,_0x5d49c3){return _0x354435(_0x3f3c91-_0x4c5fac._0x16105e,_0x5d49c3);}return(_0x5e6726||_conn)['local']['collection'](_0x481a1e(0x35c,0x349))[_0x481a1e(_0x5e7cb2._0x489cce,_0x5e7cb2._0x2d6a2b)]({'synced':!0x1});}async function getConflicts(_0x3f5060=null,_0x428dc8){const _0x56a115={_0x18ecf5:0x78,_0x400d05:0x57,_0xc23325:0x9e,_0x387b3c:0x73},_0x2319f5=_0x428dc8||_conn,_0x45d172={'ackState':'conflict','synced':!0x1};function _0x4dc3de(_0x15d00a,_0x445298){return _0x354435(_0x15d00a-0xbf,_0x445298);}return _0x3f5060&&(_0x45d172['collection']=_0x3f5060),_0x2319f5[_0x4dc3de(-_0x56a115._0x18ecf5,-_0x56a115._0x400d05)][_0x4dc3de(-_0x56a115._0xc23325,-0x78)]('_mf_changetrack')[_0x4dc3de(-_0x56a115._0x387b3c,-0x70)](_0x45d172)['sort']({'timestamp':0x1})[_0x4dc3de(-0x57,-0x6b)]();}async function retryConflict(_0xd8133c,_0x13cf6a){const _0x2244d6={_0x57a8eb:0x3f0,_0x3e7263:0x3b2,_0x3b8c70:0x3f0,_0x337669:0x3b8,_0xda0d1a:0x3e1,_0x48e0cb:0x3ed};function _0x13d8d0(_0x20089c,_0x313ea5){return _0x354435(_0x313ea5-0x50f,_0x20089c);}if(!_0xd8133c)throw new Error('[MongoFire]\x20retryConflict:\x20opId\x20is\x20required');const _0xe768dc=_0x13cf6a||_conn;if(0x0===(await _0xe768dc[_0x13d8d0(_0x2244d6._0x57a8eb,0x3d8)][_0x13d8d0(0x3bb,_0x2244d6._0x3e7263)]('_mf_changetrack')[_0x13d8d0(_0x2244d6._0x3b8c70,0x3f2)]({'opId':_0xd8133c,'ackState':_0x13d8d0(0x3e1,0x3c5)},{'$set':{'ackState':_0x13d8d0(_0x2244d6._0x337669,0x3d4),'lastError':null,'retryCount':0x0}}))[_0x13d8d0(_0x2244d6._0xda0d1a,_0x2244d6._0x48e0cb)])throw new Error(_0x13d8d0(0x3e4,0x3f5)+_0xd8133c);}async function dismissConflict(_0x1ba3d2,_0x1d7555){const _0x24f7cf={_0x1a786c:0x40,_0x5a77f3:0x6d,_0x5f0ab3:0x33,_0x56c549:0x2e,_0x518b38:0x2d,_0x257d2b:0x79,_0x36b175:0x5a,_0xe1ff67:0x44,_0x558925:0x49,_0x4e2b1c:0x32,_0xdea749:0x46},_0x5803c9={_0x222708:0xf0};if(!_0x1ba3d2)throw new Error(_0x29d7d6(-0x29,-_0x24f7cf._0x1a786c));function _0x29d7d6(_0x11e23a,_0x240678){return _0x354435(_0x240678-_0x5803c9._0x222708,_0x11e23a);}const _0x33c56d=_0x1d7555||_conn,_0x539a43=new Date();if(0x0===(await _0x33c56d['local'][_0x29d7d6(-0x85,-_0x24f7cf._0x5a77f3)](_0x29d7d6(-_0x24f7cf._0x5f0ab3,-0x20))[_0x29d7d6(-_0x24f7cf._0x56c549,-_0x24f7cf._0x518b38)]({'opId':_0x1ba3d2,'ackState':_0x29d7d6(-_0x24f7cf._0x257d2b,-0x5a)},{'$set':{'ackState':_0x29d7d6(-_0x24f7cf._0x36b175,-_0x24f7cf._0xe1ff67),'synced':!0x0,'syncedAt':_0x539a43}}))[_0x29d7d6(-_0x24f7cf._0x558925,-_0x24f7cf._0x4e2b1c)])throw new Error(_0x29d7d6(-_0x24f7cf._0xdea749,-0x31)+_0x1ba3d2);}function _0x54fc(){const _0x1ba92d=['ywnRzwq','mZyYody5mejdq1z3Dq','y29SBgvJDgLVBG','lI9KzxzPy2u','mJmZnZn0uLbkAhe','tuiPigzVCIa','B3DUzxjlzxK','w01VBMDVrMLYzv0Gugf5Bg9Hzcb0B28GBgfYz2uGkh4','ugf5Bg9Hzcb0B28GBgfYz2u','zw5Ku2vZC2LVBG','C2v0','mtK5nZaZA3jpthnU','C2XPy2u','CMvTB3rLqwnRqxq','D2L0AfrYyw5Zywn0Aw9U','ChvZAa','BgLTAxq','ywnRu3rHDgu','lIbnyxHPBxvTigLZide1tuiGCgvYigrVy3vTzw50lIbdB25ZAwrLCIbYzw1VDMLUzYbSyxjNzsbIAw5HCNKGzMLLBgrZigzYB20GDgHLihn5BMnLzcbZy2HLBweU','A2v5CW','BgvUz3rO','y29UzMXPy3q','BwvZC2fNzq','ofzqr1vMAa','AxnjBNrLz2vY','x2LK','AgfZ','Bg9JywXdBgLLBNq','Bwf4','z2v0','zgvSzxrL','C29YDa','x21Mx2rVy21LDge','lI9JB25Uzwn0Aw9U','DxbKyxrLzej5t3bjza','CMfUzg9Tvvvjra','CgvUzgLUzW','Aw5JBhvKzxm','BwfW','CMv0DxjUt3jPz2LUywW','Bg9JywW','DxbKyxrLtwfUEq','mtHiEhfQtvK','zgLZBwLZC2vK','DMvYC2LVBG','zMLUza','zMLUze9UzufUzfvWzgf0zq','w01VBMDVrMLYzv0GzgLZBwLZC0nVBMzSAwn0oIbVCeLKigLZihjLCxvPCMvK','C3rYAw5NAwz5','AxnmB2nHBfjLCgXPy2ftzxq','mtC0odq4mhvfwLDHBa','yNvSA1DYAxrL','zxHWB3j0CW','Dw5RBM93BIbZEw5JigvYCM9Y','yNL0zuXLBMD0Aa','CM91BMq','zxjYB3i','nteXoejcAeznzq','y29TChjLC3nLza','mtaWmZeWndb4rgTQq3i','DMfSDwu','Bwf0y2HLzenVDw50','w01VBMDVrMLYzv0GzgLZBwLZC0nVBMzSAwn0oIbUBYbJB25MBgLJDcbMB3vUzcbMB3iGB3bjzca','y291BNreB2n1BwvUDhm','CMv0DxjUrg9JDw1LBNq','lI91DgLSCW','DxbKyxrLt25L','z2XVyMfS','mtyWuu9Mt0Lo','w01VBMDVrMLYzv0GCMv0CNLdB25MBgLJDdOGBM8Gy29UzMXPy3qGzM91BMqGzM9Yig9WswqG','mtfztu1Sv1K','ndnmwurYzw8','w01VBMDVrMLYzv0Gtg9JywWGreiGBM90ignVBM5Ly3rLza','Dg9bCNjHEq','C3rHCNrtzxnZAw9U','mtm1mtuZsNDKzujI','BwLU','DxrMoa','icHIDwXRia','x21Mx2nOyw5NzxrYywnR'];_0x54fc=function(){return _0x1ba92d;};return _0x54fc();}async function _bumpLocalDocVersion(_0x219bf5,_0x557797,_0x534552=null){const _0x1ebf48={_0x5132af:0x245,_0x375a37:0x21f,_0x15a535:0x23b,_0xf0ce5:0x246,_0x14a39d:0x249,_0x12e65a:0x230,_0x3fbec9:0x21b,_0x2bbf97:0x255,_0x1a45cb:0x251,_0x2eaa3b:0x23a,_0x3687fa:0x211,_0x39ce9f:0x22d,_0x3e6283:0x240,_0x4d798f:0x244,_0x37c48d:0x239,_0x11b575:0x24a,_0x1e6f7d:0x22b,_0x47f857:0x266},{metaId:_0x5aebda,collection:_0x246e3b,docId:_0x13fb2f,op:_0x1dedf4,ownerKey:_0x412a18,deviceId:_0x96fc3b,updatedAt:_0x167d5b,opId:_0x35ff78}=_0x557797,_0x50dbca=_0x219bf5['collection'](_0x36d2df(-0x247,-0x268)),_0x5ad7e0=_0x167d5b||new Date(),_0x3f4157=_0x534552?{'session':_0x534552}:{},_0x381291=await _0x50dbca['findOne']({'_id':_0x5aebda},{..._0x3f4157,'projection':{'version':0x1,'updatedByOpId':0x1}});if(_0x381291?.[_0x36d2df(-_0x1ebf48._0x5132af,-_0x1ebf48._0x375a37)]===_0x35ff78)return Math['max'](asInt(_0x381291[_0x36d2df(-_0x1ebf48._0x15a535,-_0x1ebf48._0xf0ce5)],0x1)-0x1,0x0);const _0x175dfa={'$set':{'collection':_0x246e3b,'docId':_0x13fb2f,'updatedAt':_0x5ad7e0,'lastWriterDeviceId':_0x96fc3b,'deleted':_0x36d2df(-_0x1ebf48._0x14a39d,-_0x1ebf48._0x12e65a)===_0x1dedf4,'ownerKey':_0x412a18||_0x36d2df(-0x224,-_0x1ebf48._0x3fbec9),'updatedByOpId':_0x35ff78},'$setOnInsert':{'createdAt':_0x5ad7e0},'$inc':{'version':0x1}},_0xc83ed4=_0x534552?{'upsert':!0x0,'session':_0x534552}:{'upsert':!0x0};function _0x36d2df(_0x4a1270,_0x2523d7){return _0x354435(_0x4a1270- -0x108,_0x2523d7);}let _0x1ac225;try{_0x1ac225=await _0x50dbca[_0x36d2df(-0x239,-_0x1ebf48._0x2bbf97)]({'_id':_0x5aebda},_0x175dfa,{..._0xc83ed4,...getReturnBeforeOpt()});}catch(_0x2a2c1c){if(!_0x2a2c1c?.[_0x36d2df(-_0x1ebf48._0x1a45cb,-0x25d)]?.[_0x36d2df(-0x242,-_0x1ebf48._0x2eaa3b)](_0x36d2df(-0x227,-_0x1ebf48._0x3687fa))&&!_0x2a2c1c?.['message']?.[_0x36d2df(-0x242,-_0x1ebf48._0x39ce9f)](_0x36d2df(-_0x1ebf48._0x3e6283,-_0x1ebf48._0x4d798f)))throw _0x2a2c1c;markReturnDocFallback(),_0x1ac225=await _0x50dbca[_0x36d2df(-_0x1ebf48._0x37c48d,-_0x1ebf48._0x11b575)]({'_id':_0x5aebda},_0x175dfa,{..._0xc83ed4,'returnOriginal':!0x0});}const _0x386b7e=_0x1ac225?.[_0x36d2df(-_0x1ebf48._0x1e6f7d,-_0x1ebf48._0x1e6f7d)]??_0x1ac225,_0x27a488=_0x386b7e?.['version'];return null!=_0x27a488&&Number[_0x36d2df(-0x24f,-_0x1ebf48._0x47f857)](Number(_0x27a488))?Number(_0x27a488):0x0;}function _0x354435(_0x3f05d1,_0x193c63){return _0x4840(_0x3f05d1- -0x1cc,_0x193c63);}async function requeueOrphanedOp(_0x3af79e,_0x292a84,_0x301c29,_0x1c67a7,_0x40e9dd,_0x20a41a){const _0x1c5189={_0x484e30:0x23d,_0x2d273c:0x214,_0x2e74e8:0x207,_0x46fa9a:0x1d4,_0xede416:0x20d,_0x264d28:0x1f8,_0x5e3ffa:0x224,_0x324c8d:0x238,_0x434847:0x216,_0xa54cb3:0x1ff,_0x535de1:0x237},_0x3a6e60=(_0x20a41a||_conn)['local'];function _0x160aa9(_0x19cbf9,_0x44712a){return _0x354435(_0x44712a-0x355,_0x19cbf9);}if(!_0x3a6e60)throw new Error(_0x160aa9(_0x1c5189._0x484e30,0x23e));const _0xc00fc6=_0x160aa9(0x21d,_0x1c5189._0x2d273c)===_0x301c29?null:safeDoc(_0x1c67a7);_checkPayloadSize(_0xc00fc6,_0x3af79e+'/'+_0x292a84+'\x20(reconcile-requeue\x20'+_0x301c29+')');const _0x34e8b7=getDeviceId(),_0x30fcf7=new Date(),_0x4bf4c0=crypto['randomUUID'](),_0x2677d1=asInt(_0x40e9dd[_0x160aa9(_0x1c5189._0x2e74e8,0x222)],0x1),_0x9f3da8=Math[_0x160aa9(0x22c,0x212)](_0x2677d1-0x1,0x0),_0xf717d5=resolveOwnerKey({'ownerKey':_0x40e9dd[_0x160aa9(_0x1c5189._0x46fa9a,0x1fc)]});await _0x3a6e60[_0x160aa9(_0x1c5189._0xede416,_0x1c5189._0x264d28)](_0x160aa9(_0x1c5189._0x5e3ffa,0x245))[_0x160aa9(0x25e,_0x1c5189._0x324c8d)]({'opId':_0x4bf4c0},{'$setOnInsert':{'opId':_0x4bf4c0,'type':_0x301c29,'collection':_0x3af79e,'docId':_0x292a84,'payload':_0xc00fc6,'ownerKey':_0xf717d5,'deviceId':_0x34e8b7,'timestamp':_0x30fcf7,'updatedAt':_0x30fcf7,'baseVersion':_0x9f3da8,'version':_0x2677d1,'lastWriterDeviceId':_0x34e8b7,'payloadChecksum':payloadChecksum(_0xc00fc6,!0x0),'synced':!0x1,'ackState':_0x160aa9(_0x1c5189._0x434847,0x21a),'retryCount':0x0,'createdAt':_0x30fcf7,'syncedAt':null,'remoteAckAt':null,'checksumVerifiedAt':null,'lastError':null,'_reconciled':!0x0}},{'upsert':!0x0}),await _0x3a6e60[_0x160aa9(_0x1c5189._0xa54cb3,_0x1c5189._0x264d28)](_0x160aa9(_0x1c5189._0x535de1,_0x1c5189._0x434847))['updateOne']({'_id':metaId(_0x3af79e,_0x292a84)},{'$set':{'updatedByOpId':_0x4bf4c0,'lastOpId':_0x4bf4c0}});}function _0x4840(_0x293bf2,_0x3f3d19){_0x293bf2=_0x293bf2-0x6f;const _0x54fc26=_0x54fc();let _0x4840e4=_0x54fc26[_0x293bf2];if(_0x4840['AOPNes']===undefined){var _0x1afb6d=function(_0x8d3590){const _0x1bb315='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x4ded6c='',_0x453cc7='';for(let _0x5340e5=0x0,_0xc82585,_0x3c8d7c,_0x49edc5=0x0;_0x3c8d7c=_0x8d3590['charAt'](_0x49edc5++);~_0x3c8d7c&&(_0xc82585=_0x5340e5%0x4?_0xc82585*0x40+_0x3c8d7c:_0x3c8d7c,_0x5340e5++%0x4)?_0x4ded6c+=String['fromCharCode'](0xff&_0xc82585>>(-0x2*_0x5340e5&0x6)):0x0){_0x3c8d7c=_0x1bb315['indexOf'](_0x3c8d7c);}for(let _0x1c94c4=0x0,_0x1fad52=_0x4ded6c['length'];_0x1c94c4<_0x1fad52;_0x1c94c4++){_0x453cc7+='%'+('00'+_0x4ded6c['charCodeAt'](_0x1c94c4)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x453cc7);};_0x4840['ATtORm']=_0x1afb6d,_0x4840['ZmXJiI']={},_0x4840['AOPNes']=!![];}const _0x45e1e4=_0x54fc26[0x0],_0x1a6477=_0x293bf2+_0x45e1e4,_0x57c20e=_0x4840['ZmXJiI'][_0x1a6477];return!_0x57c20e?(_0x4840e4=_0x4840['ATtORm'](_0x4840e4),_0x4840['ZmXJiI'][_0x1a6477]=_0x4840e4):_0x4840e4=_0x57c20e,_0x4840e4;}function _normalizeDocId(_0x139199){return null==_0x139199?'':_0x139199['toString']();}module[_0x354435(-0x12b,-0x123)]={'recordChange':recordChange,'recordChangeBulk':recordChangeBulk,'getPending':getPending,'markSynced':markSynced,'markFailed':markFailed,'cleanSynced':cleanSynced,'countPending':countPending,'requeueOrphanedOp':requeueOrphanedOp,'getConflicts':getConflicts,'retryConflict':retryConflict,'dismissConflict':dismissConflict};
|
|
1
|
+
'use strict';(function(_0x5305ea,_0x2e452e){const _0x238401={_0x34088b:0x16d,_0x3b61f9:0x17b,_0x396f64:0x1a6,_0x17a8bd:0x17e,_0x3ad5f8:0x184,_0x47f21c:0x18b,_0x49565f:0x179,_0xe74f02:0x180,_0x2feb92:0x180,_0x31c7c3:0x19a,_0x573f4a:0x1b9,_0x5b319a:0x191,_0x4f6b30:0x1b3},_0x3fce2d=_0x5305ea();function _0x2a03ac(_0x457aef,_0x87aa77){return _0x91a0(_0x87aa77- -0x18,_0x457aef);}while(!![]){try{const _0xeca6df=-parseInt(_0x2a03ac(_0x238401._0x34088b,0x188))/0x1*(-parseInt(_0x2a03ac(0x179,_0x238401._0x3b61f9))/0x2)+parseInt(_0x2a03ac(_0x238401._0x396f64,0x199))/0x3+parseInt(_0x2a03ac(0x175,_0x238401._0x17a8bd))/0x4+-parseInt(_0x2a03ac(0x193,_0x238401._0x3ad5f8))/0x5+-parseInt(_0x2a03ac(_0x238401._0x47f21c,_0x238401._0x49565f))/0x6*(-parseInt(_0x2a03ac(_0x238401._0xe74f02,_0x238401._0x2feb92))/0x7)+-parseInt(_0x2a03ac(_0x238401._0x31c7c3,_0x238401._0x573f4a))/0x8*(parseInt(_0x2a03ac(_0x238401._0x5b319a,0x194))/0x9)+-parseInt(_0x2a03ac(0x1d9,_0x238401._0x4f6b30))/0xa;if(_0xeca6df===_0x2e452e)break;else _0x3fce2d['push'](_0x3fce2d['shift']());}catch(_0x1eab77){_0x3fce2d['push'](_0x3fce2d['shift']());}}}(_0x27c7,0xea02c));function _0x91a0(_0x3472a3,_0x3e6230){_0x3472a3=_0x3472a3-0x182;const _0x27c7d2=_0x27c7();let _0x91a000=_0x27c7d2[_0x3472a3];if(_0x91a0['DvlDaN']===undefined){var _0x2bff93=function(_0xfedf3c){const _0x1ca443='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x144765='',_0x5b0d68='';for(let _0x5028da=0x0,_0x97d80b,_0x28b105,_0x1f41d1=0x0;_0x28b105=_0xfedf3c['charAt'](_0x1f41d1++);~_0x28b105&&(_0x97d80b=_0x5028da%0x4?_0x97d80b*0x40+_0x28b105:_0x28b105,_0x5028da++%0x4)?_0x144765+=String['fromCharCode'](0xff&_0x97d80b>>(-0x2*_0x5028da&0x6)):0x0){_0x28b105=_0x1ca443['indexOf'](_0x28b105);}for(let _0x13501e=0x0,_0x12d1c0=_0x144765['length'];_0x13501e<_0x12d1c0;_0x13501e++){_0x5b0d68+='%'+('00'+_0x144765['charCodeAt'](_0x13501e)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x5b0d68);};_0x91a0['HOjSHK']=_0x2bff93,_0x91a0['OHtpAe']={},_0x91a0['DvlDaN']=!![];}const _0x253565=_0x27c7d2[0x0],_0x4cbd55=_0x3472a3+_0x253565,_0x318946=_0x91a0['OHtpAe'][_0x4cbd55];return!_0x318946?(_0x91a000=_0x91a0['HOjSHK'](_0x91a000),_0x91a0['OHtpAe'][_0x4cbd55]=_0x91a000):_0x91a000=_0x318946,_0x91a000;}const crypto=require('crypto'),defaultConn=require(_0x58a3bd(0x14b,0x147)),{getDeviceId:getDeviceId}=require('./device'),{asDate:asDate,asInt:asInt,metaId:metaId,safeDoc:safeDoc,payloadChecksum:payloadChecksum,resolveOwnerKey:resolveOwnerKey,getReturnBeforeOpt:getReturnBeforeOpt,markReturnDocFallback:markReturnDocFallback}=require(_0x58a3bd(0x11c,0x115)),MAX_RETRY_COUNT=0xa;let _conn=defaultConn;const MAX_PAYLOAD_BYTES=0xf00000;function _checkPayloadSize(_0x144765,_0x5b0d68){const _0x2e5ba0={_0x3bc0c0:0x104,_0x36887a:0xfe,_0xc89ff6:0x110,_0x2b3341:0xd4,_0x1ba00c:0x111,_0x428988:0xe8},_0x17e754={_0x1c675c:0x44};function _0x434bb3(_0x4c4762,_0x11bd66){return _0x58a3bd(_0x4c4762- -_0x17e754._0x1c675c,_0x11bd66);}if(_0x144765)try{const _0x5028da=Buffer[_0x434bb3(0x106,_0x2e5ba0._0x3bc0c0)](JSON[_0x434bb3(_0x2e5ba0._0x36887a,_0x2e5ba0._0xc89ff6)](_0x144765),_0x434bb3(_0x2e5ba0._0x2b3341,0xe1));if(_0x5028da>0xf00000)throw new Error(_0x434bb3(_0x2e5ba0._0x1ba00c,0xf3)+Math[_0x434bb3(0xc6,_0x2e5ba0._0x428988)](_0x5028da/0x400/0x400)+'MB)\x20for\x20'+_0x5b0d68+_0x434bb3(0xd0,0xb9));}catch(_0x97d80b){if(_0x97d80b['message'][_0x434bb3(0x103,0x129)](_0x434bb3(0xe5,0xbe)))throw _0x97d80b;}}function _buildDoc({opId:_0x28b105,op:_0x1f41d1,collection:_0x13501e,docId:_0x12d1c0,payload:_0x316789,owner:_0x505a05,deviceId:_0xb43dd0,eventTime:_0x52503c,baseVersion:_0x3e0694,now:_0x171e63}){function _0x4ac644(_0x300fb4,_0x223e61){return _0x58a3bd(_0x223e61- -0x186,_0x300fb4);}return{'opId':_0x28b105,'type':_0x1f41d1,'collection':_0x13501e,'docId':_0x12d1c0,'payload':_0x316789,'ownerKey':_0x505a05,'deviceId':_0xb43dd0,'timestamp':_0x52503c,'updatedAt':_0x52503c,'baseVersion':_0x3e0694,'version':_0x3e0694+0x1,'lastWriterDeviceId':_0xb43dd0,'payloadChecksum':payloadChecksum(_0x316789,!0x0),'synced':!0x1,'ackState':_0x4ac644(-0x71,-0x54),'retryCount':0x0,'createdAt':_0x171e63||new Date(),'syncedAt':null,'remoteAckAt':null,'checksumVerifiedAt':null,'lastError':null};}async function recordChange(_0x59b30d,_0x1a68fc,_0xb6d73c,_0x1a8a37,_0x452b86,_0xb2c9aa=_0x58a3bd(0x111,0x138),_0x5ca692={},_0x584ee7){const _0x425ce1={_0x2378b9:0x74,_0x463588:0x85,_0x362146:0x87,_0x326f01:0x90,_0x43e40f:0x70,_0x1d7579:0x94,_0x525e3a:0xab,_0xa02294:0xa6},_0xdcf584={_0x4d1493:0x1bb},_0x434c7d=_0x584ee7||_conn,_0x3d7746=_0x434c7d['local'];if(!_0x3d7746)throw new Error(_0x25f510(-_0x425ce1._0x2378b9,-_0x425ce1._0x463588));const _0x41649a=_0x5ca692?.[_0x25f510(-0x66,-0x61)]||null,_0x1812ce=_normalizeDocId(_0x1a68fc),_0x5b6eda='delete'===_0xb6d73c?null:safeDoc(_0x1a8a37);function _0x25f510(_0x31702c,_0x5875f6){return _0x58a3bd(_0x5875f6- -_0xdcf584._0x4d1493,_0x31702c);}_checkPayloadSize(_0x5b6eda,_0x59b30d+'/'+_0x1812ce+'\x20('+_0xb6d73c+')');const _0x5beff0=resolveOwnerKey({'ownerKey':_0xb2c9aa}),_0x5e01a5=asDate(_0x452b86)||new Date(),_0x5a13f4=getDeviceId(),_0x49ead0=crypto[_0x25f510(-_0x425ce1._0x362146,-_0x425ce1._0x326f01)](),_0x4ac647=metaId(_0x59b30d,_0x1812ce),_0x17997c=new Date();if(_0x434c7d[_0x25f510(-_0x425ce1._0x43e40f,-0x6b)]&&!_0x41649a){const _0x93ee9e=_0x434c7d[_0x25f510(-0x7b,-_0x425ce1._0x1d7579)][_0x25f510(-_0x425ce1._0x525e3a,-_0x425ce1._0xa02294)]();try{await _0x93ee9e[_0x25f510(-0x8c,-0x80)](()=>_doChangetrackWrite(_0x3d7746,_0x93ee9e,{'opId':_0x49ead0,'op':_0xb6d73c,'collection':_0x59b30d,'docId':_0x1812ce,'payload':_0x5b6eda,'owner':_0x5beff0,'deviceId':_0x5a13f4,'eventTime':_0x5e01a5,'mid':_0x4ac647,'now':_0x17997c}));}finally{await _0x93ee9e[_0x25f510(-0x86,-0x7d)]();}return;}await _doChangetrackWrite(_0x3d7746,_0x41649a,{'opId':_0x49ead0,'op':_0xb6d73c,'collection':_0x59b30d,'docId':_0x1812ce,'payload':_0x5b6eda,'owner':_0x5beff0,'deviceId':_0x5a13f4,'eventTime':_0x5e01a5,'mid':_0x4ac647,'now':_0x17997c});}async function _doChangetrackWrite(_0x317ae4,_0x3589a4,{opId:_0x1004e1,op:_0x1e8716,collection:_0x2655c4,docId:_0x2da6dc,payload:_0x34eccf,owner:_0x55b463,deviceId:_0x34fbc8,eventTime:_0x5af6a4,mid:_0xe99df0,now:_0x564685}){const _0x4b7322={_0x2130bb:0x2af},_0x2fe3ec=_0x3589a4?{'session':_0x3589a4}:{},_0x26dc8d=await _bumpLocalDocVersion(_0x317ae4,{'metaId':_0xe99df0,'collection':_0x2655c4,'docId':_0x2da6dc,'op':_0x1e8716,'ownerKey':_0x55b463,'deviceId':_0x34fbc8,'updatedAt':_0x5af6a4,'opId':_0x1004e1},_0x3589a4);function _0xe9f98d(_0x533969,_0x182e1b){return _0x58a3bd(_0x182e1b-0x172,_0x533969);}await _0x317ae4[_0xe9f98d(0x2d3,_0x4b7322._0x2130bb)]('_mf_changetrack')['updateOne']({'opId':_0x1004e1},{'$setOnInsert':_buildDoc({'opId':_0x1004e1,'op':_0x1e8716,'collection':_0x2655c4,'docId':_0x2da6dc,'payload':_0x34eccf,'owner':_0x55b463,'deviceId':_0x34fbc8,'eventTime':_0x5af6a4,'baseVersion':_0x26dc8d,'now':_0x564685})},{'upsert':!0x0,..._0x2fe3ec});}async function recordChangeBulk(_0x14554a,_0x2afba6=null,_0x1f0f28=0x8,_0x2cea87){const _0x683ded={_0x348f98:0x1ec,_0x2d20ef:0x1f1,_0xe12779:0x206,_0x1a39c9:0x1cb},_0x53dca9={_0x56b528:0xb6},_0x18260c=_0x2cea87||_conn,_0x418056=_0x18260c['local'];if(!_0x418056)throw new Error(_0x1a231a(_0x683ded._0x348f98,_0x683ded._0x2d20ef));function _0x1a231a(_0x11f386,_0x201a55){return _0x58a3bd(_0x11f386-_0x53dca9._0x56b528,_0x201a55);}if(_0x14554a?.[_0x1a231a(0x1d9,0x1d4)]){if(_0x18260c[_0x1a231a(_0x683ded._0xe12779,0x21a)]&&!_0x2afba6){const _0x2a15f1=_0x18260c[_0x1a231a(0x1dd,0x1b8)][_0x1a231a(_0x683ded._0x1a39c9,0x1a6)]();try{await _0x2a15f1['withTransaction'](()=>_doRecordChangeBulk(_0x418056,_0x14554a,_0x2a15f1,_0x1f0f28));}finally{await _0x2a15f1['endSession']();}return;}await _doRecordChangeBulk(_0x418056,_0x14554a,_0x2afba6,_0x1f0f28);}}function _0x27c7(){const _0x158125=['Bwf0y2HLzenVDw50','w01VBMDVrMLYzv0Gtg9JywWGreiGBM90ignVBM5Ly3rLza','Bg9JywW','BwvZC2fNzq','ndm4otq4nK55qLbYvq','Dg9bCNjHEq','D2L0AfrYyw5Zywn0Aw9U','DxbKyxrLt25L','y29SBgvJDgLVBG','zw5Ku2vZC2LVBG','z2v0','w01VBMDVrMLYzv0GzgLZBwLZC0nVBMzSAwn0oIbUBYbJB25MBgLJDcbMB3vUzcbMB3iGB3bjzca','Dw5RBM93BIbZEw5JigvYCM9Y','C3rYAw5NAwz5','x21Mx2nOyw5NzxrYywnR','CMv0DxjUt3jPz2LUywW','DMvYC2LVBG','zgvSzxrL','Aw5JBhvKzxm','icHYzwnVBMnPBguTCMvXDwv1zsa','yNvSA1DYAxrL','yNL0zuXLBMD0Aa','lI9JB25Uzwn0Aw9U','x2LK','B3DUzxjlzxK','zgvSzxrLtwfUEq','w01VBMDVrMLYzv0GCMvJB3jKq2HHBMDLqNvSAZOGC2TPChbPBMCGB3zLCNnPEMvKigrVyYdIGjq','AxnmB2nHBfjLCgXPy2ftzxq','CMvTB3rLqwnRqxq','ChvZAa','mZyZotyZntb2wMHPzfu','DxbKyxrLtwfUEq','w01VBMDVrMLYzv0Gugf5Bg9Hzcb0B28GBgfYz2uGkh4','C29YDa','C3vWzxjZzwrLza','BwLU','ntC4odqWog1Hrxj5tq','C2vZC2LVBG','A2v5CW','CM91BMq','ywnRu3rHDgu','AxnjBNrLz2vY','zMLUza','ywXS','zgLZBwLZC2vK','Bwf4','z2XVyMfS','zxjYB3i','AgfZ','lIbnyxHPBxvTigLZide1tuiGCgvYigrVy3vTzw50lIbdB25ZAwrLCIbYzw1VDMLUzYbSyxjNzsbIAw5HCNKGzMLLBgrZigzYB20GDgHLihn5BMnLzcbZy2HLBweU','C3rHCNrtzxnZAw9U','CMv0DxjUrg9JDw1LBNq','zg9Jswq','DxrMoa','mZe5ntq3nhPPvNPowa','ywnRzwq','mKvrqKfJza','lI91DgLSCW','Dg9tDhjPBMC','nJm3mtG2me1zCxnhvq','zMLUze9UzufUzfvWzgf0zq','mJfLvMnIBMG','BgLTAxq','y29UzMXPy3q','BgvUz3rO','mJKYnZu3me51zhjLsW','icHIDwXRia','DxbKyxrLzej5t3bjza','Bg9JywXdBgLLBNq','mti1mZm0nhvlBw9pCW','ugf5Bg9Hzcb0B28GBgfYz2u','zMLUze9Uzq','CMfUzg9Tvvvjra','x21Mx2rVy21LDge','w01VBMDVrMLYzv0GCMv0CNLdB25MBgLJDdOGB3bjzcbPCYbYzxf1AxjLza','C2v0','BwfW','DMfSDwu','w01VBMDVrMLYzv0GzgLZBwLZC0nVBMzSAwn0oIbVCeLKigLZihjLCxvPCMvK','CgvUzgLUzW','w01VBMDVrMLYzv0GCMv0CNLdB25MBgLJDdOGBM8Gy29UzMXPy3qGzM91BMqGzM9Yig9WswqG','ow91Eg52BW'];_0x27c7=function(){return _0x158125;};return _0x27c7();}async function _doRecordChangeBulk(_0x43d3d3,_0x54198d,_0x498636,_0x151606){const _0x28b5b1={_0x15cb26:0x1ea,_0x4a5991:0x23e,_0x4a227a:0x21f,_0x438de0:0x22f,_0x726ccb:0x227,_0x3b5aac:0x216,_0x30d868:0x1f4,_0x348f10:0x203,_0x47a51e:0x1e1,_0x11378c:0x211,_0x5efb89:0x247,_0x599531:0x202,_0x411fb3:0x218,_0x2bb261:0x212},_0xc5f3d5={_0x2c3617:0x355},_0x40db2c={_0x46e5de:0x123,_0x55f163:0x141,_0x412eb3:0x155,_0x4c2f7a:0x113,_0x2ffb70:0x137,_0xb9b20b:0x110},_0x5e9163=getDeviceId(),_0x590cae=new Date(),_0x57a262=Math['max'](0x1,Math[_0x174379(-0x1fd,-_0x28b5b1._0x15cb26)](Number(_0x151606)||0x8,0x20)),_0x58330d=new Map();for(const _0x1d2f6f of _0x54198d){const _0x4acd28=_normalizeDocId(_0x1d2f6f[_0x174379(-_0x28b5b1._0x4a5991,-_0x28b5b1._0x4a227a)]);_0x58330d[_0x174379(-0x242,-_0x28b5b1._0x438de0)](_0x4acd28)||_0x58330d[_0x174379(-_0x28b5b1._0x726ccb,-0x215)](_0x4acd28,[]),_0x58330d[_0x174379(-_0x28b5b1._0x3b5aac,-_0x28b5b1._0x30d868)](_0x4acd28)[_0x174379(-_0x28b5b1._0x348f10,-_0x28b5b1._0x47a51e)](_0x1d2f6f);}const _0x32f534=[..._0x58330d[_0x174379(-0x1fa,-_0x28b5b1._0x11378c)]()],_0x12466a=[];for(let _0x396893=0x0;_0x396893<_0x32f534[_0x174379(-0x232,-0x249)];_0x396893+=_0x57a262){const _0x25f64e=_0x32f534['slice'](_0x396893,_0x396893+_0x57a262),_0x34c865=await Promise[_0x174379(-_0x28b5b1._0x5efb89,-0x25f)](_0x25f64e[_0x174379(-0x226,-_0x28b5b1._0x599531)](async _0x565612=>{const _0x316aed=_0x58330d[_0x3d364e(-0x139,-_0x40db2c._0x46e5de)](_0x565612),_0x5e5fe9=[];for(const _0x5c16c2 of _0x316aed){const {collection:_0x29da6a,op:_0x39a3b2,doc:_0x4f1a95,updatedAt:_0x44fbad,ownerKey:_0x585e9e}=_0x5c16c2,_0x3e4ff6=_0x3d364e(-_0x40db2c._0x55f163,-0x11c)===_0x39a3b2?null:safeDoc(_0x4f1a95);try{_checkPayloadSize(_0x3e4ff6,_0x29da6a+'/'+_0x565612+_0x3d364e(-_0x40db2c._0x412eb3,-0x13d)+_0x39a3b2+')');}catch(_0x48d798){console[_0x3d364e(-0x13c,-0x150)](_0x3d364e(-0x122,-_0x40db2c._0x4c2f7a),_0x48d798[_0x3d364e(-0x128,-0x12a)]);continue;}const _0x3c8f6f=resolveOwnerKey({'ownerKey':_0x585e9e}),_0x330ff0=asDate(_0x44fbad)||_0x590cae,_0x3266d2=crypto[_0x3d364e(-0x132,-_0x40db2c._0x2ffb70)](),_0x23b993=metaId(_0x29da6a,_0x565612),_0x294de5=await _bumpLocalDocVersion(_0x43d3d3,{'metaId':_0x23b993,'collection':_0x29da6a,'docId':_0x565612,'op':_0x39a3b2,'ownerKey':_0x3c8f6f,'deviceId':_0x5e9163,'updatedAt':_0x330ff0,'opId':_0x3266d2},_0x498636);_0x5e5fe9[_0x3d364e(-0x101,-_0x40db2c._0xb9b20b)]({'updateOne':{'filter':{'opId':_0x3266d2},'update':{'$setOnInsert':_buildDoc({'opId':_0x3266d2,'op':_0x39a3b2,'collection':_0x29da6a,'docId':_0x565612,'payload':_0x3e4ff6,'owner':_0x3c8f6f,'deviceId':_0x5e9163,'eventTime':_0x330ff0,'baseVersion':_0x294de5,'now':_0x590cae})},'upsert':!0x0}});}function _0x3d364e(_0x428cef,_0x4eeb96){return _0x174379(_0x4eeb96-0xf3,_0x428cef);}return _0x5e5fe9;}));for(const _0x47a99d of _0x34c865)_0x12466a[_0x174379(-0x203,-0x210)](..._0x47a99d);}function _0x174379(_0x5d525e,_0xd49f88){return _0x58a3bd(_0x5d525e- -_0xc5f3d5._0x2c3617,_0xd49f88);}if(!_0x12466a[_0x174379(-0x232,-0x242)])return;const _0x2a3dcc=_0x498636?{'session':_0x498636,'ordered':!0x1}:{'ordered':!0x1};await _0x43d3d3[_0x174379(-_0x28b5b1._0x411fb3,-0x232)](_0x174379(-_0x28b5b1._0x2bb261,-0x1f4))[_0x174379(-0x20c,-0x215)](_0x12466a,_0x2a3dcc);}async function getPending(_0x3c8004,_0xa0e108=0x1f4,_0x505625=null,_0x38a367){const _0x9cb274={_0x2752a8:0x131,_0x30c698:0x141,_0x4bde59:0x110,_0x3d7474:0x12e,_0x5295d6:0x111,_0x5b5861:0x134,_0x5c8030:0x134,_0x5607fd:0x105,_0x5581d5:0x12d};function _0x2fb31b(_0x4a26b7,_0x4b23a3){return _0x58a3bd(_0x4a26b7- -0x26,_0x4b23a3);}const _0x30678d=_0x38a367||_conn,_0x248822={'synced':!0x1,'ackState':{'$nin':[_0x2fb31b(0xfc,0xdd),'compressed',_0x2fb31b(_0x9cb274._0x2752a8,_0x9cb274._0x30c698)]},'$or':[{'ackState':{'$ne':'error'}},{'retryCount':{'$lt':0xa}}]};return _0x3c8004&&(_0x248822[_0x2fb31b(0x117,_0x9cb274._0x4bde59)]=_0x3c8004),_0x505625&&(_0x248822[_0x2fb31b(0x126,_0x9cb274._0x3d7474)]={'$gt':_0x505625}),_0x30678d[_0x2fb31b(_0x9cb274._0x5295d6,_0x9cb274._0x5b5861)][_0x2fb31b(0x117,_0x9cb274._0x5c8030)]('_mf_changetrack')['find'](_0x248822)['sort']({'_id':0x1})[_0x2fb31b(0xfb,_0x9cb274._0x5607fd)](_0xa0e108)[_0x2fb31b(0x114,_0x9cb274._0x5581d5)]();}async function markSynced(_0x2617b9,_0x308f6b={},_0x4856cc){const _0x381879={_0x408c50:0x47a,_0x1ab4d7:0x4af,_0x3bb211:0x495,_0x2afcea:0x46e,_0x2bfb33:0x4b6},_0x3631ee={_0x13cc77:0x357};function _0x15d22d(_0x1f4e04,_0x59ab2b){return _0x58a3bd(_0x1f4e04-_0x3631ee._0x13cc77,_0x59ab2b);}if(!_0x2617b9?.[_0x15d22d(_0x381879._0x408c50,0x492)])return;const _0x382ed5=_0x4856cc||_conn,_0x1cdf2a=new Date();await _0x382ed5[_0x15d22d(0x48e,0x4b4)][_0x15d22d(0x494,_0x381879._0x1ab4d7)](_0x15d22d(0x49a,_0x381879._0x408c50))[_0x15d22d(0x4ab,_0x381879._0x3bb211)]({'_id':{'$in':_0x2617b9}},{'$set':{'synced':!0x0,'ackState':_0x308f6b[_0x15d22d(0x462,_0x381879._0x2afcea)]||_0x15d22d(0x471,0x44e),'syncedAt':_0x1cdf2a,'remoteAckAt':_0x308f6b[_0x15d22d(0x4a8,_0x381879._0x2bfb33)]||_0x1cdf2a,'checksumVerifiedAt':_0x308f6b['checksumVerifiedAt']||null,'lastError':null}});}async function markFailed(_0x4a69c3,_0x72b528,_0x23ba5f=_0x58a3bd(0x112,0x131),_0x33330f){const _0x3ffeb1={_0x444e8d:0x22d,_0x38dafc:0x239,_0x657aa7:0x25a,_0x3ea4e4:0x237,_0x58fb50:0x24a},_0x103f91={_0x3824f7:0xf6};if(!_0x4a69c3)return;function _0x1647bd(_0x41d0d6,_0x23fe47){return _0x58a3bd(_0x41d0d6-_0x103f91._0x3824f7,_0x23fe47);}const _0x828c3=_0x33330f||_conn;await _0x828c3[_0x1647bd(_0x3ffeb1._0x444e8d,0x207)][_0x1647bd(0x233,0x22a)](_0x1647bd(_0x3ffeb1._0x38dafc,_0x3ffeb1._0x657aa7))[_0x1647bd(0x232,0x23c)]({'_id':_0x4a69c3},{'$set':{'synced':!0x1,'ackState':_0x23ba5f,'lastError':_0x72b528||_0x1647bd(_0x3ffeb1._0x3ea4e4,_0x3ffeb1._0x58fb50)},'$inc':{'retryCount':0x1}});}async function cleanSynced(_0xffa347,_0x550f11){const _0x216e0d={_0x23720e:0x1a2,_0x58735a:0x1bb},_0x18f715={_0x2deb76:0x7a};if(!_0xffa347?.[_0x46570c(_0x216e0d._0x23720e,0x19d)])return;const _0x49324f=_0x550f11||_conn;function _0x46570c(_0x2adfdd,_0x448aa0){return _0x58a3bd(_0x448aa0-_0x18f715._0x2deb76,_0x2adfdd);}await _0x49324f[_0x46570c(0x1b8,0x1b1)]['collection']('_mf_changetrack')[_0x46570c(_0x216e0d._0x58735a,0x1c8)]({'_id':{'$in':_0xffa347},'synced':!0x0});}async function countPending(_0x486dd8){const _0x57c34d={_0x485447:0xe3,_0x3bc4dc:0x104},_0x447220={_0x1dd4a5:0x241};function _0x4a6c5a(_0x1089d6,_0x9143cd){return _0x58a3bd(_0x9143cd- -_0x447220._0x1dd4a5,_0x1089d6);}return(_0x486dd8||_conn)[_0x4a6c5a(-0x11b,-0x10a)][_0x4a6c5a(-_0x57c34d._0x485447,-_0x57c34d._0x3bc4dc)](_0x4a6c5a(-0xd5,-0xfe))['countDocuments']({'synced':!0x1});}async function getConflicts(_0x5eff21=null,_0x2ac8a3){const _0x54c28a={_0x3dae4d:0x52f,_0xa13bbf:0x599},_0x4692ae={_0x28c2be:0x429},_0x1db19a=_0x2ac8a3||_conn,_0x378a08={'ackState':'conflict','synced':!0x1};function _0x2dd5d5(_0x3f2456,_0x1cdf92){return _0x58a3bd(_0x3f2456-_0x4692ae._0x28c2be,_0x1cdf92);}return _0x5eff21&&(_0x378a08[_0x2dd5d5(0x566,0x54e)]=_0x5eff21),_0x1db19a['local'][_0x2dd5d5(0x566,0x57f)](_0x2dd5d5(0x56c,0x545))[_0x2dd5d5(0x536,_0x54c28a._0x3dae4d)](_0x378a08)[_0x2dd5d5(0x57f,_0x54c28a._0xa13bbf)]({'timestamp':0x1})['toArray']();}async function retryConflict(_0xbc9a58,_0x37ff63){const _0x35a86c={_0x40a209:0x97,_0x37a99a:0x79,_0x1b5731:0xa7,_0xa60e2a:0xad,_0x66976e:0x8a,_0x244948:0xa6,_0x37aab8:0x94,_0x24138b:0x9f},_0x48737d={_0x15090a:0x96};if(!_0xbc9a58)throw new Error(_0xc6b3a3(_0x35a86c._0x40a209,0xbe));const _0x36fc5f=_0x37ff63||_conn;function _0xc6b3a3(_0x2ebc70,_0x2e531c){return _0x58a3bd(_0x2ebc70- -_0x48737d._0x15090a,_0x2e531c);}if(0x0===(await _0x36fc5f[_0xc6b3a3(0xa1,_0x35a86c._0x37a99a)][_0xc6b3a3(_0x35a86c._0x1b5731,0xb6)](_0xc6b3a3(_0x35a86c._0xa60e2a,_0x35a86c._0x66976e))[_0xc6b3a3(_0x35a86c._0x244948,0xcf)]({'opId':_0xbc9a58,'ackState':_0xc6b3a3(0x8c,0x96)},{'$set':{'ackState':_0xc6b3a3(0x9c,_0x35a86c._0x37aab8),'lastError':null,'retryCount':0x0}}))[_0xc6b3a3(_0x35a86c._0x24138b,0xae)])throw new Error(_0xc6b3a3(0x9d,_0x35a86c._0x37a99a)+_0xbc9a58);}async function dismissConflict(_0x4e7fa5,_0x3179ba){const _0x4aba25={_0x5a9f43:0x3f9,_0x523386:0x412,_0x253ac0:0x41a,_0xeb577b:0x3d1,_0x177d02:0x3ef,_0x3dc636:0x402,_0x4a712f:0x40f};if(!_0x4e7fa5)throw new Error(_0x1cb40c(0x3f3,0x3eb));function _0x1cb40c(_0x456c3e,_0x64d74){return _0x58a3bd(_0x456c3e-0x2c2,_0x64d74);}const _0x1bdac9=_0x3179ba||_conn,_0x150b44=new Date();if(0x0===(await _0x1bdac9[_0x1cb40c(_0x4aba25._0x5a9f43,0x3dc)][_0x1cb40c(0x3ff,_0x4aba25._0x523386)](_0x1cb40c(0x405,_0x4aba25._0x253ac0))[_0x1cb40c(0x3fe,_0x4aba25._0x523386)]({'opId':_0x4e7fa5,'ackState':'conflict'},{'$set':{'ackState':_0x1cb40c(_0x4aba25._0xeb577b,_0x4aba25._0x177d02),'synced':!0x0,'syncedAt':_0x150b44}}))['matchedCount'])throw new Error(_0x1cb40c(_0x4aba25._0x3dc636,_0x4aba25._0x4a712f)+_0x4e7fa5);}async function _bumpLocalDocVersion(_0x3a9131,_0x2e7677,_0x3d5029=null){const _0x20573b={_0xdedfd9:0x564,_0x4adbfc:0x560,_0x71ee36:0x54f,_0x3506ae:0x52e,_0x5ed5f3:0x531,_0x367940:0x541,_0x172002:0x533,_0x16c791:0x568,_0x5745da:0x580,_0x3be790:0x569,_0x448f6b:0x511,_0x52ccdf:0x534,_0x1e6e47:0x569,_0x23d538:0x58a,_0x726d3f:0x56a,_0x1c537b:0x55b,_0x2d3aed:0x578,_0x5a1cff:0x572},_0x22035c={_0x2dc36d:0x423},{metaId:_0x584771,collection:_0x9fed1a,docId:_0x2817ea,op:_0x44b8bf,ownerKey:_0xd9eec4,deviceId:_0x5ab4b0,updatedAt:_0x5617a7,opId:_0x1481b6}=_0x2e7677,_0x4f2032=_0x3a9131[_0x1abb07(_0x20573b._0xdedfd9,_0x20573b._0x4adbfc)](_0x1abb07(0x55a,_0x20573b._0x71ee36)),_0x41a74d=_0x5617a7||new Date(),_0x520c8e=_0x3d5029?{'session':_0x3d5029}:{},_0x40df1d=await _0x4f2032[_0x1abb07(_0x20573b._0x3506ae,0x54d)]({'_id':_0x584771},{..._0x520c8e,'projection':{'version':0x1,'updatedByOpId':0x1}});function _0x1abb07(_0x696e0c,_0x549e6f){return _0x58a3bd(_0x549e6f-_0x22035c._0x2dc36d,_0x696e0c);}if(_0x40df1d?.[_0x1abb07(_0x20573b._0x5ed5f3,0x549)]===_0x1481b6)return Math[_0x1abb07(_0x20573b._0x367940,_0x20573b._0x172002)](asInt(_0x40df1d[_0x1abb07(0x581,_0x20573b._0x16c791)],0x1)-0x1,0x0);const _0x428e37={'$set':{'collection':_0x9fed1a,'docId':_0x2817ea,'updatedAt':_0x41a74d,'lastWriterDeviceId':_0x5ab4b0,'deleted':_0x1abb07(_0x20573b._0x5745da,_0x20573b._0x3be790)===_0x44b8bf,'ownerKey':_0xd9eec4||_0x1abb07(_0x20573b._0x448f6b,_0x20573b._0x52ccdf),'updatedByOpId':_0x1481b6},'$setOnInsert':{'createdAt':_0x41a74d},'$inc':{'version':0x1}},_0xb9aa0c=_0x3d5029?{'upsert':!0x0,'session':_0x3d5029}:{'upsert':!0x0};let _0x444f7c;try{_0x444f7c=await _0x4f2032[_0x1abb07(_0x20573b._0x1e6e47,0x542)]({'_id':_0x584771},_0x428e37,{..._0xb9aa0c,...getReturnBeforeOpt()});}catch(_0x3c4528){if(!_0x3c4528?.['message']?.[_0x1abb07(_0x20573b._0x23d538,_0x20573b._0x726d3f)](_0x1abb07(0x562,0x539))&&!_0x3c4528?.[_0x1abb07(0x564,_0x20573b._0x1c537b)]?.['includes'](_0x1abb07(_0x20573b._0x2d3aed,0x567)))throw _0x3c4528;markReturnDocFallback(),_0x444f7c=await _0x4f2032[_0x1abb07(0x53c,0x542)]({'_id':_0x584771},_0x428e37,{..._0xb9aa0c,'returnOriginal':!0x0});}const _0x3a3ca2=_0x444f7c?.[_0x1abb07(0x535,0x553)]??_0x444f7c,_0x4c2ff9=_0x3a3ca2?.[_0x1abb07(_0x20573b._0x5a1cff,_0x20573b._0x16c791)];return null!=_0x4c2ff9&&Number[_0x1abb07(0x507,0x52f)](Number(_0x4c2ff9))?Number(_0x4c2ff9):0x0;}async function requeueOrphanedOp(_0x43ad5c,_0x2c70a3,_0x56c8e0,_0xf0bd2d,_0x279e9e,_0x23ad02){const _0x2e86b8={_0x367c8c:0x48f,_0x4a5581:0x480,_0x750d05:0x480,_0x1e52cc:0x459,_0x2ccdf6:0x43e,_0x5b0525:0x47b,_0x5a0d9c:0x45a,_0x494e57:0x47d},_0x267d24={_0x5043e8:0x32e},_0x1e024d=(_0x23ad02||_conn)['local'];if(!_0x1e024d)throw new Error(_0x5c6108(0x475,0x464));const _0x1c1653=_0x5c6108(_0x2e86b8._0x367c8c,0x474)===_0x56c8e0?null:safeDoc(_0xf0bd2d);_checkPayloadSize(_0x1c1653,_0x43ad5c+'/'+_0x2c70a3+_0x5c6108(_0x2e86b8._0x4a5581,0x476)+_0x56c8e0+')');const _0x2529d3=getDeviceId(),_0x2ba76e=new Date(),_0x198f9c=crypto[_0x5c6108(_0x2e86b8._0x750d05,_0x2e86b8._0x1e52cc)](),_0x78cda5=asInt(_0x279e9e['version'],0x1),_0x39642d=Math[_0x5c6108(0x430,_0x2e86b8._0x2ccdf6)](_0x78cda5-0x1,0x0),_0x396464=resolveOwnerKey({'ownerKey':_0x279e9e[_0x5c6108(0x48f,_0x2e86b8._0x5b0525)]});function _0x5c6108(_0x3e7e60,_0x93d358){return _0x58a3bd(_0x93d358-_0x267d24._0x5043e8,_0x3e7e60);}await _0x1e024d['collection'](_0x5c6108(0x473,0x471))[_0x5c6108(0x47b,0x46a)]({'opId':_0x198f9c},{'$setOnInsert':{'opId':_0x198f9c,'type':_0x56c8e0,'collection':_0x43ad5c,'docId':_0x2c70a3,'payload':_0x1c1653,'ownerKey':_0x396464,'deviceId':_0x2529d3,'timestamp':_0x2ba76e,'updatedAt':_0x2ba76e,'baseVersion':_0x39642d,'version':_0x78cda5,'lastWriterDeviceId':_0x2529d3,'payloadChecksum':payloadChecksum(_0x1c1653,!0x0),'synced':!0x1,'ackState':_0x5c6108(0x44a,0x460),'retryCount':0x0,'createdAt':_0x2ba76e,'syncedAt':null,'remoteAckAt':null,'checksumVerifiedAt':null,'lastError':null,'_reconciled':!0x0}},{'upsert':!0x0}),await _0x1e024d['collection'](_0x5c6108(0x466,_0x2e86b8._0x5a0d9c))[_0x5c6108(_0x2e86b8._0x494e57,0x46a)]({'_id':metaId(_0x43ad5c,_0x2c70a3)},{'$set':{'updatedByOpId':_0x198f9c,'lastOpId':_0x198f9c}});}function _0x58a3bd(_0x43c3d5,_0x568564){return _0x91a0(_0x43c3d5- -0x78,_0x568564);}function _normalizeDocId(_0x189d4d){const _0x2da0ba={_0x2216e4:0xb8};function _0x540286(_0x29b31a,_0x3ea457){return _0x58a3bd(_0x29b31a- -0x1d5,_0x3ea457);}return null==_0x189d4d?'':_0x189d4d[_0x540286(-_0x2da0ba._0x2216e4,-0xb2)]();}module['exports']={'recordChange':recordChange,'recordChangeBulk':recordChangeBulk,'getPending':getPending,'markSynced':markSynced,'markFailed':markFailed,'cleanSynced':cleanSynced,'countPending':countPending,'requeueOrphanedOp':requeueOrphanedOp,'getConflicts':getConflicts,'retryConflict':retryConflict,'dismissConflict':dismissConflict};
|
package/dist/src/compactor.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function _0x4028aa(_0x51cd91,_0x47f929){const _0x3e6967={_0x5b2711:0x25f};return _0x4cdd(_0x47f929-_0x3e6967._0x5b2711,_0x51cd91);}(function(_0xee6566,_0x33e46d){const _0x284f6c={_0x2c9f07:0x1b1,_0x56fe87:0x1b0,_0x5b05ba:0x1d7,_0x481972:0x1d1,_0x42a437:0x1cf,_0x5384f7:0x1c5,_0x3af7f0:0x1ca,_0x55d86b:0x1de,_0x8731e8:0x1ed,_0x4888cc:0x1da,_0x7b8536:0x1bb};function _0x49da74(_0x35ace6,_0x216d19){return _0x4cdd(_0x35ace6- -0x30d,_0x216d19);}const _0x1ba4ec=_0xee6566();while(!![]){try{const _0x3faf15=-parseInt(_0x49da74(-_0x284f6c._0x2c9f07,-0x1bd))/0x1*(parseInt(_0x49da74(-0x1d5,-0x1d3))/0x2)+-parseInt(_0x49da74(-0x1bc,-_0x284f6c._0x56fe87))/0x3*(-parseInt(_0x49da74(-_0x284f6c._0x5b05ba,-_0x284f6c._0x481972))/0x4)+-parseInt(_0x49da74(-_0x284f6c._0x42a437,-_0x284f6c._0x5384f7))/0x5+parseInt(_0x49da74(-0x1cb,-_0x284f6c._0x3af7f0))/0x6+-parseInt(_0x49da74(-_0x284f6c._0x3af7f0,-0x1b3))/0x7+-parseInt(_0x49da74(-_0x284f6c._0x55d86b,-_0x284f6c._0x8731e8))/0x8*(-parseInt(_0x49da74(-_0x284f6c._0x4888cc,-0x1c7))/0x9)+parseInt(_0x49da74(-0x1bb,-_0x284f6c._0x7b8536))/0xa;if(_0x3faf15===_0x33e46d)break;else _0x1ba4ec['push'](_0x1ba4ec['shift']());}catch(_0x238de2){_0x1ba4ec['push'](_0x1ba4ec['shift']());}}}(_0x492a,0xb5f85));const defaultConn=require(_0x4028aa(0x38f,0x398)),DEFAULT_RETENTION_DAYS=0x7,DEFAULT_BATCH_SIZE=0x3e8,DEFAULT_PAGE_SIZE=0xc8;async function compactChangelog(_0x1e366c={}){const _0x640d6d={_0x2b1b47:0x2f,_0x33e53a:0x54,_0x582972:0x3b,_0x2c1e08:0x5e,_0x1e205a:0x4b,_0x1a89d5:0x32,_0x32473a:0x47,_0x588958:0x4c,_0x3a910c:0x53,_0x244c1e:0x46,_0x2a8275:0x61,_0x29f20a:0x65,_0x40f9a1:0x50,_0x40110c:0x63,_0x291fcd:0x4e,_0x19cd55:0x42,_0x52ed02:0x58,_0x4ac8cd:0x66,_0x24bb5a:0x39,_0x35ac20:0x3a,_0x540a4f:0x2b,_0x2a07ad:0x40,_0xf11097:0x60,_0x2a7488:0x5c,_0x2a06c5:0x41,_0x2ade24:0x3b,_0x3ddc91:0x7e,_0x48db1a:0x3e,_0x1b799d:0x37,_0x2db416:0x45,_0x435896:0x2c,_0x8bbe7:0x51,_0x5a997f:0x48,_0x15c6f4:0x45,_0x23440a:0x34,_0x3a6f03:0x3a,_0x18804a:0x40,_0x43ab77:0x2e,_0x49a98d:0x65,_0x541ebd:0x61,_0x11c0f6:0x5a,_0x3b46d4:0x4d,_0x377a89:0x43,_0x425b02:0x55,_0x40b264:0x48,_0x590010:0x56,_0x104e90:0x3a,_0x289c84:0x36,_0x562f49:0x2e,_0x3faf7a:0x65,_0x25cced:0x7f,_0xab591c:0x4d,_0x5863bf:0x66,_0x1b80d7:0x45,_0x4229f2:0x4f,_0x430543:0x4d,_0x5ec4b5:0x4d,_0x14b23b:0x63,_0x30403f:0x6b},_0x19b0a3=Date[_0x5befeb(-0x4f,-0x40)](),_0xd9a604=(_0x1e366c['conn']||defaultConn)['local'];if(!_0xd9a604)throw new Error(_0x5befeb(-0x49,-_0x640d6d._0x2b1b47));const _0x4c76f4=_0x1e366c[_0x5befeb(-0x54,-_0x640d6d._0x33e53a)]??0x7,_0xc306e2=_0x1e366c['batchSize']??0x3e8,_0x4f6cb8=!0x1!==_0x1e366c[_0x5befeb(-0x3d,-_0x640d6d._0x582972)],_0x41ef34=_0x1e366c['collection']||null,_0x43439d=new Date(Date[_0x5befeb(-0x4f,-0x62)]()-0x18*_0x4c76f4*0x3c*0x3c*0x3e8);let _0x3eb7c4=0x0,_0x199b5a=0x0,_0x49bf42=0x0,_0x10fd91=_0xc306e2;function _0x5befeb(_0x4e63ba,_0x461a6c){return _0x4028aa(_0x461a6c,_0x4e63ba- -0x3f4);}_0x4f6cb8&&console[_0x5befeb(-0x4d,-0x4c)](_0x5befeb(-_0x640d6d._0x2c1e08,-_0x640d6d._0x1e205a)+_0x4c76f4+_0x5befeb(-0x41,-_0x640d6d._0x1a89d5)+_0x43439d[_0x5befeb(-_0x640d6d._0x32473a,-_0x640d6d._0x588958)]()+_0x5befeb(-0x4b,-_0x640d6d._0x3a910c)+_0xc306e2);const _0xe65855={'synced':!0x0,'syncedAt':{'$lt':_0x43439d},'ackState':{'$in':['acked',_0x5befeb(-_0x640d6d._0x244c1e,-0x3e),'superseded',_0x5befeb(-_0x640d6d._0x2a8275,-0x47)]}};_0x41ef34&&(_0xe65855[_0x5befeb(-_0x640d6d._0x29f20a,-0x72)]=_0x41ef34);let _0x419a14=null,_0x367e77=!0x0;for(;_0x367e77&&_0x10fd91>0x0;){const _0x25aa5e={..._0xe65855};_0x419a14&&(_0x25aa5e[_0x5befeb(-_0x640d6d._0x40f9a1,-0x69)]={'$gt':_0x419a14});const _0x2d0f6d=await _0xd9a604[_0x5befeb(-_0x640d6d._0x29f20a,-_0x640d6d._0x40110c)](_0x5befeb(-0x3e,-_0x640d6d._0x291fcd))[_0x5befeb(-_0x640d6d._0x19cd55,-0x44)]([{'$match':_0x25aa5e},{'$sort':{'_id':0x1}},{'$limit':0x7d0},{'$group':{'_id':{'collection':'$collection','docId':_0x5befeb(-_0x640d6d._0x52ed02,-_0x640d6d._0x4ac8cd)},'rowIds':{'$push':_0x5befeb(-0x4a,-0x64)},'count':{'$sum':0x1},'latestId':{'$last':_0x5befeb(-0x4a,-_0x640d6d._0x24bb5a)},'latestAt':{'$last':_0x5befeb(-0x4c,-0x5c)}}},{'$match':{'count':{'$gt':0x1}}},{'$limit':0xc8}])['toArray']();if(!_0x2d0f6d[_0x5befeb(-_0x640d6d._0x35ac20,-_0x640d6d._0x540a4f)]){_0x367e77=!0x1;break;}const _0x50f366=[];for(const _0x2cfa50 of _0x2d0f6d){_0x3eb7c4+=_0x2cfa50['count'];const _0x4c26a5=_0x2cfa50[_0x5befeb(-_0x640d6d._0x2a07ad,-0x48)][_0x5befeb(-_0x640d6d._0xf11097,-_0x640d6d._0x2a7488)](_0x1c1c1a=>String(_0x1c1c1a)!==String(_0x2cfa50['latestId']));_0x50f366['push'](..._0x4c26a5),_0x49bf42++;}if(_0x50f366[_0x5befeb(-0x3a,-_0x640d6d._0x2a06c5)]>0x0){const _0x47bdd4=Math[_0x5befeb(-_0x640d6d._0x2ade24,-0x44)](_0x50f366['length'],_0x10fd91),_0x219465=_0x50f366['slice'](0x0,_0x47bdd4),_0x4c7451=await _0xd9a604[_0x5befeb(-_0x640d6d._0x29f20a,-_0x640d6d._0x3ddc91)](_0x5befeb(-_0x640d6d._0x48db1a,-_0x640d6d._0x19cd55))['deleteMany']({'_id':{'$in':_0x219465},'synced':!0x0});_0x199b5a+=_0x4c7451[_0x5befeb(-0x45,-_0x640d6d._0x1b799d)],_0x10fd91-=_0x4c7451[_0x5befeb(-_0x640d6d._0x2db416,-0x3d)],_0x4f6cb8&&_0x4c7451[_0x5befeb(-0x45,-_0x640d6d._0x435896)]>0x0&&console[_0x5befeb(-0x4d,-_0x640d6d._0x8bbe7)](_0x5befeb(-_0x640d6d._0x5a997f,-0x44)+_0x4c7451[_0x5befeb(-_0x640d6d._0x15c6f4,-0x4c)]+_0x5befeb(-_0x640d6d._0x23440a,-0x4e));}_0x419a14=_0x2d0f6d[_0x2d0f6d[_0x5befeb(-_0x640d6d._0x3a6f03,-0x50)]-0x1][_0x5befeb(-_0x640d6d._0x2a07ad,-_0x640d6d._0x18804a)][_0x2d0f6d[_0x2d0f6d[_0x5befeb(-0x3a,-_0x640d6d._0x43ab77)]-0x1][_0x5befeb(-_0x640d6d._0x18804a,-0x5a)][_0x5befeb(-0x3a,-0x40)]-0x1];}if(_0x10fd91>0x0){const _0x58982e=await _0xd9a604[_0x5befeb(-_0x640d6d._0x49a98d,-0x58)]('_mf_changetrack')['deleteMany']({'synced':!0x0,'ackState':_0x5befeb(-_0x640d6d._0x541ebd,-0x5a),'syncedAt':{'$lt':_0x43439d},..._0x41ef34?{'collection':_0x41ef34}:{}});_0x58982e[_0x5befeb(-0x45,-0x42)]>0x0&&(_0x199b5a+=_0x58982e[_0x5befeb(-_0x640d6d._0x2db416,-_0x640d6d._0x5a997f)],_0x10fd91-=_0x58982e['deletedCount'],_0x4f6cb8&&console[_0x5befeb(-0x4d,-_0x640d6d._0x11c0f6)](_0x5befeb(-0x51,-_0x640d6d._0x3b46d4)+_0x58982e[_0x5befeb(-_0x640d6d._0x2db416,-_0x640d6d._0x377a89)]+'\x20compressed\x20(create+delete)\x20rows'));}if(_0x10fd91>0x0){const _0x5b85c5=await _0xd9a604[_0x5befeb(-0x65,-_0x640d6d._0x425b02)](_0x5befeb(-0x3e,-_0x640d6d._0x40b264))[_0x5befeb(-0x3f,-0x37)]({'synced':!0x0,'syncedAt':{'$lt':new Date(Date[_0x5befeb(-0x4f,-0x48)]()-0x18*(_0x4c76f4+0x7)*0x3c*0x3c*0x3e8)},'ackState':{'$in':[_0x5befeb(-0x4e,-0x45),_0x5befeb(-0x46,-_0x640d6d._0x590010)]},..._0x41ef34?{'collection':_0x41ef34}:{}})[_0x5befeb(-0x35,-0x35)]({'_id':0x1})['limit'](_0x10fd91)[_0x5befeb(-0x55,-_0x640d6d._0x33e53a)]();if(_0x5b85c5[_0x5befeb(-_0x640d6d._0x104e90,-0x2e)]>0x0){const _0x255210=_0x5b85c5[_0x5befeb(-_0x640d6d._0x289c84,-_0x640d6d._0x562f49)](_0x131a51=>_0x131a51['_id']),_0x2aa965=await _0xd9a604[_0x5befeb(-_0x640d6d._0x3faf7a,-_0x640d6d._0x25cced)](_0x5befeb(-0x3e,-_0x640d6d._0xab591c))[_0x5befeb(-_0x640d6d._0x40110c,-_0x640d6d._0x5863bf)]({'_id':{'$in':_0x255210},'synced':!0x0});_0x199b5a+=_0x2aa965[_0x5befeb(-_0x640d6d._0x1b80d7,-0x37)],_0x4f6cb8&&_0x2aa965[_0x5befeb(-0x45,-_0x640d6d._0x4229f2)]>0x0&&console[_0x5befeb(-_0x640d6d._0x430543,-0x44)](_0x5befeb(-0x37,-0x4b)+_0x2aa965[_0x5befeb(-0x45,-0x5a)]+_0x5befeb(-0x3c,-0x31));}}const _0x2c7b83=Date[_0x5befeb(-0x4f,-0x4b)]()-_0x19b0a3;return _0x4f6cb8&&console[_0x5befeb(-_0x640d6d._0x5ec4b5,-_0x640d6d._0x14b23b)](_0x5befeb(-0x64,-_0x640d6d._0x30403f)+_0x3eb7c4+',\x20deleted:\x20'+_0x199b5a+_0x5befeb(-0x38,-0x26)+_0x49bf42+_0x5befeb(-_0x640d6d._0x1a89d5,-0x3b)+_0x2c7b83+'ms'),{'scanned':_0x3eb7c4,'deleted':_0x199b5a,'kept':_0x49bf42,'durationMs':_0x2c7b83};}async function getCompactionStats(_0x25db20={}){const _0x9c808={_0x3a690b:0x18e,_0x52f0d9:0x162,_0xfd44d7:0x16d,_0x341046:0x168,_0x1a4325:0x17e,_0xb7a735:0x157,_0x5d4cf0:0x141,_0x119d61:0x17e,_0x573e42:0x166,_0x1d3c92:0x158,_0x1cefa3:0x14b,_0x2f353c:0x18a,_0xd4b571:0x17a,_0x26a676:0x16a,_0x50a1ea:0x167,_0x2c55f2:0x15d,_0x5663a2:0x186},_0x47a152={_0x361eb1:0x238},_0x44ba13=(_0x25db20[_0x37ee89(0x189,_0x9c808._0x3a690b)]||defaultConn)[_0x37ee89(_0x9c808._0x52f0d9,_0x9c808._0xfd44d7)];function _0x37ee89(_0x281334,_0x4ce29f){return _0x4028aa(_0x4ce29f,_0x281334- -_0x47a152._0x361eb1);}if(!_0x44ba13)throw new Error('[MongoFire/compactor]\x20Local\x20DB\x20not\x20connected');const _0x1f1331=_0x25db20[_0x37ee89(_0x9c808._0x341046,0x174)]??0x7,_0x341028=new Date(Date['now']()-0x18*_0x1f1331*0x3c*0x3c*0x3e8),[_0x105165,_0x247037,_0x2cef0c]=await Promise['all']([_0x44ba13[_0x37ee89(0x157,0x167)](_0x37ee89(_0x9c808._0x1a4325,0x18e))[_0x37ee89(0x166,0x14d)]({'synced':!0x0}),_0x44ba13[_0x37ee89(_0x9c808._0xb7a735,_0x9c808._0x5d4cf0)](_0x37ee89(_0x9c808._0x119d61,0x169))[_0x37ee89(_0x9c808._0x573e42,_0x9c808._0x1d3c92)]({'synced':!0x0,'syncedAt':{'$lt':_0x341028}}),_0x44ba13[_0x37ee89(0x157,_0x9c808._0x1cefa3)](_0x37ee89(0x17e,_0x9c808._0x2f353c))[_0x37ee89(_0x9c808._0xd4b571,_0x9c808._0x26a676)]([{'$match':{'synced':!0x0}},{'$group':{'_id':'$collection','count':{'$sum':0x1}}},{'$sort':{'count':-0x1}}])[_0x37ee89(_0x9c808._0x50a1ea,_0x9c808._0x2c55f2)]()]);return{'totalSynced':_0x105165,'oldSynced':_0x247037,'retentionDays':_0x1f1331,'cutoffDate':_0x341028,'collections':_0x2cef0c[_0x37ee89(_0x9c808._0x5663a2,0x190)](_0x5c783c=>({'collection':_0x5c783c[_0x37ee89(0x16c,0x181)],'count':_0x5c783c[_0x37ee89(0x161,0x150)]})),'estimatedDeletable':Math['round'](0.65*_0x247037)};}function _0x492a(){const _0x1892df=['lcb0Aw1LoIa','mtzQvgPzBeG','y29SBgvJDgLVBG','w01VBMDVrMLYzs9JB21Wywn0B3jDierVBMuG4OcuihnJyw5Uzwq6ia','zgvSzxrLtwfUEq','mZqZnJm2mLjzvMryqG','y29TChjLC3nLza','zMLSDgvY','mtiYmduYoevUAwTLta','w01VBMDVrMLYzs9JB21Wywn0B3jDifn0yxj0Aw5NiokaLcbYzxrLBNrPB246ia','mtaYnty3ogD4zgPKAq','lI9JB25Uzwn0Aw9U','y291BNq','Bg9JywW','zxHWB3j0CW','jgrVy0LK','mZG5otaZnwXqwwrdCG','y291BNreB2n1BwvUDhm','Dg9bCNjHEq','CMv0zw50Aw9Urgf5CW','ndu2ntiXnhb3z21UEa','nJKYmda4muvtqvfnvW','w01VBMDVrMLYzs9JB21Wywn0B3jDifbOyxnLidi6igrLBgv0zwqG','x2LK','BM93','ywnRzwq','Bg9N','jhn5BMnLzef0','lcbIDwrNzxq6ia','jf9Pza','w01VBMDVrMLYzs9JB21Wywn0B3jDieXVy2fSiercig5VDcbJB25Uzwn0zwq','w01VBMDVrMLYzs9JB21Wywn0B3jDifbOyxnLide6igrLBgv0zwqG','Dg9ju09tDhjPBMC','DMvYAwzPzwq','zgvSzxrLzenVDw50','mtjVwMvqzum','mJGXntq1mgzzAezyzG','ywDNCMvNyxrL','zcWGy3v0B2zMoIa','CM93swrZ','zMLUza','x21Mx2nOyw5NzxrYywnR','DMvYyM9Zzq','ig9SzcbHy2TLzcbYB3DZ','BwLU','BgvUz3rO','mvvdChjPyG','lcbRzxb0oIa','w01VBMDVrMLYzs9JB21Wywn0B3jDifbOyxnLidm6ihbYDw5Lzca','BwfW','ChjVAMvJDa','ihn1CgvYC2vKzwqGCM93CW','y29UBG'];_0x492a=function(){return _0x1892df;};return _0x492a();}function _0x4cdd(_0x7ca126,_0x11ca06){_0x7ca126=_0x7ca126-0x12f;const _0x492a2b=_0x492a();let _0x4cddc7=_0x492a2b[_0x7ca126];if(_0x4cdd['jaWMIB']===undefined){var _0x5dcc06=function(_0xb11f68){const _0x5331af='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1e366c='',_0x19b0a3='';for(let _0xd9a604=0x0,_0x4c76f4,_0xc306e2,_0x4f6cb8=0x0;_0xc306e2=_0xb11f68['charAt'](_0x4f6cb8++);~_0xc306e2&&(_0x4c76f4=_0xd9a604%0x4?_0x4c76f4*0x40+_0xc306e2:_0xc306e2,_0xd9a604++%0x4)?_0x1e366c+=String['fromCharCode'](0xff&_0x4c76f4>>(-0x2*_0xd9a604&0x6)):0x0){_0xc306e2=_0x5331af['indexOf'](_0xc306e2);}for(let _0x41ef34=0x0,_0x43439d=_0x1e366c['length'];_0x41ef34<_0x43439d;_0x41ef34++){_0x19b0a3+='%'+('00'+_0x1e366c['charCodeAt'](_0x41ef34)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x19b0a3);};_0x4cdd['kcPCBn']=_0x5dcc06,_0x4cdd['DTvskA']={},_0x4cdd['jaWMIB']=!![];}const _0x488bd5=_0x492a2b[0x0],_0x4e976e=_0x7ca126+_0x488bd5,_0x27b2e1=_0x4cdd['DTvskA'][_0x4e976e];return!_0x27b2e1?(_0x4cddc7=_0x4cdd['kcPCBn'](_0x4cddc7),_0x4cdd['DTvskA'][_0x4e976e]=_0x4cddc7):_0x4cddc7=_0x27b2e1,_0x4cddc7;}module[_0x4028aa(0x385,0x39b)]={'compactChangelog':compactChangelog,'getCompactionStats':getCompactionStats};
|
|
1
|
+
'use strict';(function(_0x189dad,_0xc70b07){const _0xee6756={_0x252b97:0xb5,_0x1a5ced:0xc1,_0x2efe5e:0xad,_0x155515:0x96,_0x59b9df:0x94,_0x4ead74:0x97,_0x11a69c:0xb4,_0x329ada:0xa8},_0x3e9461=_0x189dad();function _0x4332c6(_0x5b235d,_0x4cf59b){return _0x3070(_0x4cf59b- -0x1ba,_0x5b235d);}while(!![]){try{const _0x4e9524=-parseInt(_0x4332c6(-0xd3,-0xca))/0x1*(parseInt(_0x4332c6(-_0xee6756._0x252b97,-_0xee6756._0x1a5ced))/0x2)+-parseInt(_0x4332c6(-0xbc,-0xc2))/0x3+parseInt(_0x4332c6(-_0xee6756._0x2efe5e,-_0xee6756._0x155515))/0x4*(-parseInt(_0x4332c6(-0xd3,-0xbe))/0x5)+parseInt(_0x4332c6(-_0xee6756._0x59b9df,-0xa3))/0x6+parseInt(_0x4332c6(-_0xee6756._0x4ead74,-0x9a))/0x7+parseInt(_0x4332c6(-0xae,-0xbb))/0x8*(parseInt(_0x4332c6(-0x9b,-0xa8))/0x9)+-parseInt(_0x4332c6(-_0xee6756._0x11a69c,-0xae))/0xa*(-parseInt(_0x4332c6(-_0xee6756._0x329ada,-0xb6))/0xb);if(_0x4e9524===_0xc70b07)break;else _0x3e9461['push'](_0x3e9461['shift']());}catch(_0x25d40f){_0x3e9461['push'](_0x3e9461['shift']());}}}(_0x3275,0xded0b));function _0x3070(_0x293c19,_0x180370){_0x293c19=_0x293c19-0xef;const _0x32750a=_0x3275();let _0x3070bc=_0x32750a[_0x293c19];if(_0x3070['ltjvAl']===undefined){var _0x5b5bf2=function(_0x10aebe){const _0x2e127c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1e0fbe='',_0x583700='';for(let _0x4275ea=0x0,_0x3a14e5,_0x248bb0,_0xc689e6=0x0;_0x248bb0=_0x10aebe['charAt'](_0xc689e6++);~_0x248bb0&&(_0x3a14e5=_0x4275ea%0x4?_0x3a14e5*0x40+_0x248bb0:_0x248bb0,_0x4275ea++%0x4)?_0x1e0fbe+=String['fromCharCode'](0xff&_0x3a14e5>>(-0x2*_0x4275ea&0x6)):0x0){_0x248bb0=_0x2e127c['indexOf'](_0x248bb0);}for(let _0x22a1be=0x0,_0x1c5abb=_0x1e0fbe['length'];_0x22a1be<_0x1c5abb;_0x22a1be++){_0x583700+='%'+('00'+_0x1e0fbe['charCodeAt'](_0x22a1be)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x583700);};_0x3070['pvVRJT']=_0x5b5bf2,_0x3070['BRHJdT']={},_0x3070['ltjvAl']=!![];}const _0x2bea3c=_0x32750a[0x0],_0x2e959d=_0x293c19+_0x2bea3c,_0x42f639=_0x3070['BRHJdT'][_0x2e959d];return!_0x42f639?(_0x3070bc=_0x3070['pvVRJT'](_0x3070bc),_0x3070['BRHJdT'][_0x2e959d]=_0x3070bc):_0x3070bc=_0x42f639,_0x3070bc;}const defaultConn=require('./connection'),DEFAULT_RETENTION_DAYS=0x7,DEFAULT_BATCH_SIZE=0x3e8,DEFAULT_PAGE_SIZE=0xc8;async function compactChangelog(_0x1e0fbe={}){const _0x296bb4={_0xf38e7f:0x3d7,_0x1255eb:0x3cc,_0x5d7a4f:0x3b2,_0xfb9fdf:0x3c6,_0x25cb23:0x3b7,_0x253f06:0x3d3,_0xbf82e0:0x3d7,_0x5b2bc9:0x3f1,_0x13b09d:0x3df,_0x2986f6:0x3d5,_0x1be4f6:0x3ec,_0x3bc0cb:0x3ed,_0x40100c:0x3d7,_0x2f2e31:0x3d0,_0x100c2e:0x3ca,_0x3efeff:0x3e4,_0x3192a2:0x3df,_0xfb0472:0x3e2,_0x273126:0x3ee,_0x2a6103:0x3e9,_0x36a30b:0x3f5,_0x55f1f2:0x3dd,_0x181279:0x3c4,_0x2b856d:0x3dc,_0x5990f7:0x3c0,_0x40a7be:0x3cd,_0x604684:0x3e7,_0x30cb42:0x3af,_0x5d72f7:0x3f3,_0x4d5daf:0x3dd,_0x3dad60:0x3c8,_0x22bcfd:0x3de,_0x394b3f:0x3c1,_0x590796:0x403,_0x371221:0x3eb,_0x2dbcee:0x402,_0x5a8bed:0x3d6,_0x412681:0x3e5,_0x4359d7:0x3b2,_0x126d78:0x3c0,_0x12c787:0x3d9,_0x2accb6:0x3e3,_0x596329:0x3da,_0x49858e:0x3ea,_0x43f049:0x3d4,_0x15655b:0x3be},_0x583700=Date[_0x2c6082(0x3eb,_0x296bb4._0xf38e7f)](),_0x4275ea=(_0x1e0fbe[_0x2c6082(_0x296bb4._0x1255eb,_0x296bb4._0x5d7a4f)]||defaultConn)[_0x2c6082(0x3d2,0x3c7)];if(!_0x4275ea)throw new Error(_0x2c6082(0x3c9,0x3e4));const _0x3a14e5=_0x1e0fbe[_0x2c6082(_0x296bb4._0xfb9fdf,_0x296bb4._0x25cb23)]??0x7,_0x248bb0=_0x1e0fbe[_0x2c6082(0x3d9,0x3ee)]??0x3e8,_0xc689e6=!0x1!==_0x1e0fbe[_0x2c6082(0x3cf,_0x296bb4._0x253f06)],_0x22a1be=_0x1e0fbe[_0x2c6082(_0x296bb4._0xbf82e0,0x3d6)]||null,_0x1c5abb=new Date(Date[_0x2c6082(0x3eb,_0x296bb4._0x5b2bc9)]()-0x18*_0x3a14e5*0x3c*0x3c*0x3e8);let _0x409d2c=0x0,_0x8f4a5e=0x0,_0xbf514b=0x0,_0x29e0f9=_0x248bb0;_0xc689e6&&console[_0x2c6082(0x3cd,0x3b7)](_0x2c6082(0x3e8,_0x296bb4._0x13b09d)+_0x3a14e5+_0x2c6082(_0x296bb4._0x2986f6,0x3c3)+_0x1c5abb['toISOString']()+',\x20budget:\x20'+_0x248bb0);const _0x1635ed={'synced':!0x0,'syncedAt':{'$lt':_0x1c5abb},'ackState':{'$in':[_0x2c6082(_0x296bb4._0x1be4f6,0x3e9),'verified','superseded',_0x2c6082(_0x296bb4._0x3bc0cb,_0x296bb4._0x40100c)]}};_0x22a1be&&(_0x1635ed[_0x2c6082(0x3d7,0x3d8)]=_0x22a1be);let _0x5d6a41=null,_0x3d7156=!0x0;for(;_0x3d7156&&_0x29e0f9>0x0;){const _0x55bf34={..._0x1635ed};_0x5d6a41&&(_0x55bf34[_0x2c6082(0x3c1,0x3c6)]={'$gt':_0x5d6a41});const _0x2de375=await _0x4275ea['collection'](_0x2c6082(_0x296bb4._0x2f2e31,_0x296bb4._0x100c2e))[_0x2c6082(_0x296bb4._0x3efeff,_0x296bb4._0x3192a2)]([{'$match':_0x55bf34},{'$sort':{'_id':0x1}},{'$limit':0x7d0},{'$group':{'_id':{'collection':_0x2c6082(_0x296bb4._0xfb0472,_0x296bb4._0x273126),'docId':'$docId'},'rowIds':{'$push':'$_id'},'count':{'$sum':0x1},'latestId':{'$last':'$_id'},'latestAt':{'$last':'$syncedAt'}}},{'$match':{'count':{'$gt':0x1}}},{'$limit':0xc8}])[_0x2c6082(0x3e0,0x3f3)]();if(!_0x2de375[_0x2c6082(_0x296bb4._0x2a6103,0x3d8)]){_0x3d7156=!0x1;break;}const _0x7e21f1=[];for(const _0x2ca7f5 of _0x2de375){_0x409d2c+=_0x2ca7f5[_0x2c6082(0x3f0,_0x296bb4._0x36a30b)];const _0x29cbda=_0x2ca7f5['rowIds'][_0x2c6082(_0x296bb4._0x55f1f2,_0x296bb4._0x181279)](_0xe51339=>String(_0xe51339)!==String(_0x2ca7f5['latestId']));_0x7e21f1[_0x2c6082(0x3d1,0x3de)](..._0x29cbda),_0xbf514b++;}if(_0x7e21f1[_0x2c6082(0x3e9,0x3de)]>0x0){const _0x27cfde=Math[_0x2c6082(_0x296bb4._0x2b856d,0x3d7)](_0x7e21f1[_0x2c6082(0x3e9,0x3ec)],_0x29e0f9),_0x7ea3ce=_0x7e21f1[_0x2c6082(0x3de,0x3d7)](0x0,_0x27cfde),_0x2594d1=await _0x4275ea['collection'](_0x2c6082(_0x296bb4._0x2f2e31,0x3e8))['deleteMany']({'_id':{'$in':_0x7ea3ce},'synced':!0x0});_0x8f4a5e+=_0x2594d1[_0x2c6082(_0x296bb4._0x5990f7,0x3da)],_0x29e0f9-=_0x2594d1['deletedCount'],_0xc689e6&&_0x2594d1['deletedCount']>0x0&&console[_0x2c6082(_0x296bb4._0x40a7be,0x3da)](_0x2c6082(0x3da,_0x296bb4._0x604684)+_0x2594d1[_0x2c6082(0x3c0,_0x296bb4._0x30cb42)]+_0x2c6082(_0x296bb4._0x181279,0x3d7));}_0x5d6a41=_0x2de375[_0x2de375[_0x2c6082(_0x296bb4._0x2a6103,_0x296bb4._0x5d72f7)]-0x1][_0x2c6082(_0x296bb4._0x5b2bc9,0x3f8)][_0x2de375[_0x2de375[_0x2c6082(0x3e9,_0x296bb4._0x4d5daf)]-0x1]['rowIds']['length']-0x1];}function _0x2c6082(_0x55f6b1,_0x3b0bdd){return _0x3070(_0x55f6b1-0x2cf,_0x3b0bdd);}if(_0x29e0f9>0x0){const _0x1e09aa=await _0x4275ea[_0x2c6082(0x3d7,_0x296bb4._0x3dad60)](_0x2c6082(0x3d0,_0x296bb4._0x22bcfd))['deleteMany']({'synced':!0x0,'ackState':_0x2c6082(0x3ed,0x3dd),'syncedAt':{'$lt':_0x1c5abb},..._0x22a1be?{'collection':_0x22a1be}:{}});_0x1e09aa[_0x2c6082(0x3c0,0x3b6)]>0x0&&(_0x8f4a5e+=_0x1e09aa[_0x2c6082(_0x296bb4._0x5990f7,0x3c3)],_0x29e0f9-=_0x1e09aa[_0x2c6082(_0x296bb4._0x5990f7,_0x296bb4._0x394b3f)],_0xc689e6&&console[_0x2c6082(_0x296bb4._0x40a7be,0x3c9)](_0x2c6082(0x3c2,0x3a9)+_0x1e09aa[_0x2c6082(_0x296bb4._0x5990f7,0x3d4)]+_0x2c6082(_0x296bb4._0x273126,_0x296bb4._0x590796)));}if(_0x29e0f9>0x0){const _0x4b1016=await _0x4275ea[_0x2c6082(0x3d7,0x3ca)]('_mf_changetrack')[_0x2c6082(0x3e7,0x3f8)]({'synced':!0x0,'syncedAt':{'$lt':new Date(Date[_0x2c6082(_0x296bb4._0x371221,_0x296bb4._0x2dbcee)]()-0x18*(_0x3a14e5+0x7)*0x3c*0x3c*0x3e8)},'ackState':{'$in':[_0x2c6082(_0x296bb4._0x1be4f6,0x3e2),_0x2c6082(_0x296bb4._0x5a8bed,0x3d4)]},..._0x22a1be?{'collection':_0x22a1be}:{}})[_0x2c6082(_0x296bb4._0x412681,0x3ea)]({'_id':0x1})[_0x2c6082(0x3c5,0x3d8)](_0x29e0f9)[_0x2c6082(0x3e0,_0x296bb4._0x1be4f6)]();if(_0x4b1016[_0x2c6082(0x3e9,0x3f1)]>0x0){const _0x490cd5=_0x4b1016[_0x2c6082(0x3c3,_0x296bb4._0x4359d7)](_0x540eb4=>_0x540eb4[_0x2c6082(0x3c1,0x3cd)]),_0x10f9b5=await _0x4275ea[_0x2c6082(0x3d7,_0x296bb4._0xfb0472)](_0x2c6082(_0x296bb4._0x2f2e31,0x3ce))[_0x2c6082(0x3d8,_0x296bb4._0x394b3f)]({'_id':{'$in':_0x490cd5},'synced':!0x0});_0x8f4a5e+=_0x10f9b5[_0x2c6082(_0x296bb4._0x126d78,_0x296bb4._0x12c787)],_0xc689e6&&_0x10f9b5['deletedCount']>0x0&&console[_0x2c6082(0x3cd,0x3bc)](_0x2c6082(_0x296bb4._0x2accb6,0x3fc)+_0x10f9b5[_0x2c6082(_0x296bb4._0x5990f7,_0x296bb4._0x596329)]+'\x20old\x20acked\x20rows');}}const _0x41950c=Date[_0x2c6082(0x3eb,0x3eb)]()-_0x583700;return _0xc689e6&&console['log'](_0x2c6082(_0x296bb4._0x49858e,0x3f0)+_0x409d2c+_0x2c6082(_0x296bb4._0x43f049,0x3cf)+_0x8f4a5e+_0x2c6082(_0x296bb4._0x15655b,0x3cc)+_0xbf514b+',\x20time:\x20'+_0x41950c+'ms'),{'scanned':_0x409d2c,'deleted':_0x8f4a5e,'kept':_0xbf514b,'durationMs':_0x41950c};}async function getCompactionStats(_0x4f6498={}){const _0x3a23d5={_0x312076:0x205,_0x5077cf:0x20e,_0x1d45f3:0x20f,_0x40d074:0x211,_0xe725e5:0x1f8,_0x241bd4:0x1ec,_0x3d652c:0x207,_0x474e58:0x1f1,_0x239cff:0x1d3,_0x5e5eb8:0x200,_0x58dd03:0x1f8,_0x12a4e5:0x1e6,_0x31dd83:0x1f3,_0x27e4bd:0x1ff,_0x30eee6:0x226,_0xf5fc0:0x214,_0x58882d:0x20d},_0x7c742f=(_0x4f6498['conn']||defaultConn)[_0x4a8053(-0x208,-_0x3a23d5._0x312076)];if(!_0x7c742f)throw new Error(_0x4a8053(-0x21f,-_0x3a23d5._0x5077cf));function _0x4a8053(_0x73e5b5,_0x7eb133){return _0x3070(_0x7eb133- -0x308,_0x73e5b5);}const _0x15d9ec=_0x4f6498[_0x4a8053(-_0x3a23d5._0x1d45f3,-_0x3a23d5._0x40d074)]??0x7,_0x59ff00=new Date(Date[_0x4a8053(-_0x3a23d5._0xe725e5,-_0x3a23d5._0x241bd4)]()-0x18*_0x15d9ec*0x3c*0x3c*0x3e8),[_0xee693d,_0x30c0c5,_0x8a1e96]=await Promise[_0x4a8053(-0x20c,-0x1f8)]([_0x7c742f[_0x4a8053(-0x213,-0x200)](_0x4a8053(-0x1f0,-_0x3a23d5._0x3d652c))[_0x4a8053(-_0x3a23d5._0x474e58,-0x1e5)]({'synced':!0x0}),_0x7c742f[_0x4a8053(-0x214,-0x200)]('_mf_changetrack')[_0x4a8053(-_0x3a23d5._0x239cff,-0x1e5)]({'synced':!0x0,'syncedAt':{'$lt':_0x59ff00}}),_0x7c742f[_0x4a8053(-0x207,-_0x3a23d5._0x5e5eb8)](_0x4a8053(-_0x3a23d5._0x58dd03,-0x207))[_0x4a8053(-_0x3a23d5._0x12a4e5,-_0x3a23d5._0x31dd83)]([{'$match':{'synced':!0x0}},{'$group':{'_id':_0x4a8053(-_0x3a23d5._0x27e4bd,-0x1f5),'count':{'$sum':0x1}}},{'$sort':{'count':-0x1}}])[_0x4a8053(-0x210,-0x1f7)]()]);return{'totalSynced':_0xee693d,'oldSynced':_0x30c0c5,'retentionDays':_0x15d9ec,'cutoffDate':_0x59ff00,'collections':_0x8a1e96[_0x4a8053(-_0x3a23d5._0x30eee6,-_0x3a23d5._0xf5fc0)](_0x47761a=>({'collection':_0x47761a[_0x4a8053(-0x21c,-0x216)],'count':_0x47761a[_0x4a8053(-0x1f9,-0x1e7)]})),'estimatedDeletable':Math[_0x4a8053(-0x226,-_0x3a23d5._0x58882d)](0.65*_0x30c0c5)};}module['exports']={'compactChangelog':compactChangelog,'getCompactionStats':getCompactionStats};function _0x3275(){const _0x50136f=['mtbUA29IEw4','y29UBG','Bg9N','mtGWmtqZmKvgCerKBa','DMvYyM9Zzq','x21Mx2nOyw5NzxrYywnR','ChvZAa','Bg9JywW','nJC3ndaYB25dC1Lb','lcbKzwXLDgvKoIa','zcWGy3v0B2zMoIa','DMvYAwzPzwq','y29SBgvJDgLVBG','zgvSzxrLtwfUEq','yMf0y2HtAxPL','w01VBMDVrMLYzs9JB21Wywn0B3jDifbOyxnLide6igrLBgv0zwqG','mZmWB3LsrK9U','BwLU','zMLSDgvY','C2XPy2u','ywXS','Dg9bCNjHEq','owHIqKfjBa','jgnVBgXLy3rPB24','w01VBMDVrMLYzs9JB21Wywn0B3jDifbOyxnLidm6ihbYDw5Lzca','ywDNCMvNyxrL','ChjVAMvJDa','nti0odK4senHteXr','zMLUza','w01VBMDVrMLYzs9JB21Wywn0B3jDifn0yxj0Aw5NiokaLcbYzxrLBNrPB246ia','BgvUz3rO','w01VBMDVrMLYzs9JB21Wywn0B3jDierVBMuG4OcuihnJyw5Uzwq6ia','BM93','ywnRzwq','y29TChjLC3nLza','ignVBxbYzxnZzwqGkgnYzwf0zsTKzwXLDguPihjVD3m','mtiWnJu3otv5Dhrct1y','y291BNq','CM93swrZ','y291BNreB2n1BwvUDhm','mZK3mZCYvenPwLHd','lcbRzxb0oIa','nNrzrwjXAW','zgvSzxrLzenVDw50','x2LK','w01VBMDVrMLYzs9JB21Wywn0B3jDifbOyxnLidi6igrLBgv0zwqG','BwfW','ihn1CgvYC2vKzwqGCM93CW','BgLTAxq','CMv0zw50Aw9Urgf5CW','ntqXnZKZnevPuMfHCW','mZGZnZq2ENnztND3','w01VBMDVrMLYzs9JB21Wywn0B3jDieXVy2fSiercig5VDcbJB25Uzwn0zwq','CM91BMq'];_0x3275=function(){return _0x50136f;};return _0x3275();}
|
package/dist/src/connection.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';(function(_0xe1600f,_0x485f99){const _0x2e169d={_0x2c44a8:0x27e,_0x3fcbfb:0x29e,_0x38b202:0x2b2,_0x3d06bd:0x28a,_0x2ee814:0x2ad,_0x30a52b:0x280,_0xb400ab:0x2b0,_0x2a6a8a:0x266,_0x3f1829:0x2cd,_0x303b38:0x2a6,_0x1a343c:0x283};function _0x50de13(_0x277121,_0x2360e4){return _0x22f1(_0x277121-0xdc,_0x2360e4);}const _0x4c9181=_0xe1600f();while(!![]){try{const _0x46b62b=-parseInt(_0x50de13(_0x2e169d._0x2c44a8,0x292))/0x1+-parseInt(_0x50de13(_0x2e169d._0x3fcbfb,_0x2e169d._0x38b202))/0x2*(-parseInt(_0x50de13(0x26d,0x255))/0x3)+parseInt(_0x50de13(_0x2e169d._0x3d06bd,0x29f))/0x4*(parseInt(_0x50de13(_0x2e169d._0x2ee814,0x2c8))/0x5)+parseInt(_0x50de13(_0x2e169d._0x30a52b,_0x2e169d._0x3fcbfb))/0x6+-parseInt(_0x50de13(_0x2e169d._0xb400ab,0x283))/0x7*(-parseInt(_0x50de13(0x28c,_0x2e169d._0x2a6a8a))/0x8)+-parseInt(_0x50de13(0x2b6,_0x2e169d._0x3f1829))/0x9*(-parseInt(_0x50de13(0x298,0x2b4))/0xa)+parseInt(_0x50de13(_0x2e169d._0x303b38,_0x2e169d._0x1a343c))/0xb*(-parseInt(_0x50de13(0x288,0x290))/0xc);if(_0x46b62b===_0x485f99)break;else _0x4c9181['push'](_0x4c9181['shift']());}catch(_0x550060){_0x4c9181['push'](_0x4c9181['shift']());}}}(_0x4836,0xc2a3f));const {MongoClient:MongoClient}=require(_0x489fad(0x1fa,0x1df));class Connection{constructor(){const _0x22f14b={_0x5cea4e:0x59d,_0x4d8e1c:0x576,_0x4644be:0x54a,_0x113664:0x55a,_0x1384d4:0x57e,_0x5ab66c:0x5b0,_0x14a94a:0x5a4},_0x3d9d74={_0x10c6df:0x3a6};function _0x5693fa(_0x58ac4b,_0x160998){return _0x489fad(_0x58ac4b,_0x160998-_0x3d9d74._0x10c6df);}this[_0x5693fa(0x552,0x54d)]=null,this[_0x5693fa(_0x22f14b._0x5cea4e,_0x22f14b._0x4d8e1c)]=null,this['_localDB']=null,this[_0x5693fa(0x566,_0x22f14b._0x4644be)]=null,this[_0x5693fa(_0x22f14b._0x113664,_0x22f14b._0x1384d4)]=!0x1,this[_0x5693fa(0x58f,0x579)]=null,this[_0x5693fa(_0x22f14b._0x5ab66c,_0x22f14b._0x14a94a)]=!0x1,this[_0x5693fa(0x596,0x5a2)]=!0x1;}async['connectLocal'](_0x2e839c,_0x53413f){const _0x448b4f={_0x327615:0x34,_0xa04f3b:0x6,_0x2b038e:0x33,_0x2ca76f:0x44,_0x50e482:0x34,_0x239f2d:0x1b,_0x5e2469:0x9,_0x39ddd0:0x36,_0xeab4fc:0xc,_0xad487d:0x23,_0x5bfa8e:0x10,_0x521d3e:0xf,_0x766b74:0x15,_0x55c8ea:0x12,_0x2b3a53:0x7,_0x4b4bae:0x30,_0x1ba450:0x1b,_0x1b4c93:0x46,_0x3c10a9:0xf,_0x36b37d:0x21,_0x54c6be:0x14,_0x3cb6dd:0x28},_0x538c25={_0x37fc26:0x42a,_0x2af86e:0x400},_0x1682bb={_0x4f4d9c:0x1db};this[_0x3d35af(-0x34,-0x58)]=new MongoClient(_0x2e839c,{'maxPoolSize':0x14,'minPoolSize':0x2,'serverSelectionTimeoutMS':0x1388,'socketTimeoutMS':0x7530}),await this[_0x3d35af(-_0x448b4f._0x327615,-0x38)][_0x3d35af(-0x2a,-_0x448b4f._0xa04f3b)](),this[_0x3d35af(-_0x448b4f._0x2b038e,-_0x448b4f._0x2ca76f)]=this[_0x3d35af(-_0x448b4f._0x50e482,-0x1c)]['db'](_0x53413f),this[_0x3d35af(0x23,-0xb)]=!0x1;function _0x3d35af(_0x35d9ba,_0x1d0dfc){return _0x489fad(_0x1d0dfc,_0x35d9ba- -_0x1682bb._0x4f4d9c);}try{const _0x306ea5=this[_0x3d35af(-0x34,-0x59)]['db'](_0x3d35af(_0x448b4f._0xa04f3b,-_0x448b4f._0x239f2d));let _0x37aecf;try{_0x37aecf=await _0x306ea5[_0x3d35af(-_0x448b4f._0x5e2469,-_0x448b4f._0x39ddd0)]({'hello':0x1});}catch(_0x263722){_0x37aecf=await _0x306ea5[_0x3d35af(-0x9,_0x448b4f._0xeab4fc)]({'isMaster':0x1});}this[_0x3d35af(_0x448b4f._0xad487d,0x1e)]=!!(_0x37aecf?.['setName']||_0x37aecf?.[_0x3d35af(-_0x448b4f._0x5bfa8e,-0xe)]||Array[_0x3d35af(0x1d,0x9)](_0x37aecf?.[_0x3d35af(0x25,0x29)])&&_0x37aecf['hosts'][_0x3d35af(-0x21,-_0x448b4f._0xeab4fc)]>0x0),this[_0x3d35af(0x23,0x3c)]&&console[_0x3d35af(-_0x448b4f._0x521d3e,_0x448b4f._0x766b74)](_0x3d35af(-_0x448b4f._0xa04f3b,-0xa));}catch(_0x237213){console['warn'](_0x3d35af(_0x448b4f._0x55c8ea,_0x448b4f._0xeab4fc),_0x237213?.[_0x3d35af(_0x448b4f._0x2b3a53,0xe)]);}return await this[_0x3d35af(0xf,-0x11)](this[_0x3d35af(-_0x448b4f._0x2b038e,-_0x448b4f._0x4b4bae)])[_0x3d35af(-_0x448b4f._0x1ba450,-_0x448b4f._0x1b4c93)](_0x46db4d=>{function _0x375a21(_0x141b73,_0x1f8e31){return _0x3d35af(_0x141b73-0x413,_0x1f8e31);}console['error'](_0x375a21(_0x538c25._0x37fc26,_0x538c25._0x2af86e),_0x46db4d?.[_0x375a21(0x3f9,0x41b)]||_0x46db4d);}),console[_0x3d35af(-_0x448b4f._0x3c10a9,-_0x448b4f._0x36b37d)](_0x3d35af(_0x448b4f._0x54c6be,0x18)),this[_0x3d35af(-0x33,-_0x448b4f._0x3cb6dd)];}async['connectAtlas'](_0x165557,_0x5e3766){const _0x2fea14={_0x57f811:0x1e0,_0x2601a2:0x1f5,_0xdaf983:0x1e6,_0x3db836:0x1c9,_0xefb937:0x1c1,_0x158271:0x1ba,_0xbe4f24:0x1a8,_0x2f8a92:0x1b4,_0x210603:0x1d0,_0xb7fe9:0x20c,_0x2c3b94:0x1af,_0x56d690:0x1b4,_0x4d9960:0x211,_0x60b92:0x1ed,_0x27893c:0x1e3,_0x28d3fb:0x1dc,_0x5dd230:0x1e8,_0x3e0cbd:0x1e3,_0x190ffb:0x1cb,_0x57c1d3:0x1db,_0x2838ee:0x203,_0x4b463a:0x19e,_0x3a39d9:0x1e8,_0x2b3d4a:0x1bc},_0x4a3141={_0x1f3b74:0xba,_0x2eb966:0xa0};function _0x4a9d8b(_0x4a6ac7,_0x1e54cc){return _0x489fad(_0x4a6ac7,_0x1e54cc-0x10);}if(!_0x165557)return this['_lastAtlasError']='atlasUri\x20is\x20missing',!0x1;try{if(this[_0x4a9d8b(0x1bf,_0x2fea14._0x57f811)]){try{await this['_atlasClient']['close']();}catch(_0x3052b9){}this['_atlasClient']=null,this[_0x4a9d8b(0x198,0x1b4)]=null,this[_0x4a9d8b(0x1d3,0x1e8)]=!0x1;}this[_0x4a9d8b(_0x2fea14._0x2601a2,_0x2fea14._0x57f811)]=new MongoClient(_0x165557,{'maxPoolSize':0x64,'minPoolSize':0x5,'serverSelectionTimeoutMS':0x1f40,'socketTimeoutMS':0xafc8,'retryWrites':!0x0,'retryReads':!0x0,'w':'majority'}),await this[_0x4a9d8b(_0x2fea14._0xdaf983,0x1e0)][_0x4a9d8b(_0x2fea14._0x3db836,_0x2fea14._0xefb937)](),this['_atlasDB']=this[_0x4a9d8b(0x1e4,_0x2fea14._0x57f811)]['db'](_0x5e3766),this[_0x4a9d8b(0x205,0x20c)]||(await this[_0x4a9d8b(0x19b,_0x2fea14._0x158271)](this[_0x4a9d8b(_0x2fea14._0xbe4f24,_0x2fea14._0x2f8a92)])[_0x4a9d8b(0x1bf,_0x2fea14._0x210603)](_0x2d0c9a=>{function _0x15f1ce(_0x4dd553,_0x138ec8){return _0x4a9d8b(_0x138ec8,_0x4dd553- -0x2a3);}console['error'](_0x15f1ce(-_0x4a3141._0x1f3b74,-_0x4a3141._0x2eb966),_0x2d0c9a?.['stack']||_0x2d0c9a);}),this[_0x4a9d8b(0x225,_0x2fea14._0xb7fe9)]=!0x0);try{return await this[_0x4a9d8b(_0x2fea14._0x2c3b94,_0x2fea14._0x56d690)][_0x4a9d8b(_0x2fea14._0x4d9960,0x1e2)]({'ping':0x1}),this['_online']=!0x0,this[_0x4a9d8b(_0x2fea14._0x60b92,_0x2fea14._0x27893c)]=null,console[_0x4a9d8b(0x1ee,_0x2fea14._0x28d3fb)]('✅\x20[MongoFire]\x20Atlas\x20connected\x20and\x20healthy'),!0x0;}catch(_0xe01983){return this[_0x4a9d8b(0x1e3,_0x2fea14._0x5dd230)]=!0x1,this[_0x4a9d8b(0x1bb,_0x2fea14._0x3e0cbd)]=this[_0x4a9d8b(_0x2fea14._0x190ffb,0x1bc)](_0xe01983),console[_0x4a9d8b(_0x2fea14._0x57c1d3,0x1f5)](_0x4a9d8b(0x217,_0x2fea14._0x2838ee),this[_0x4a9d8b(0x1fa,_0x2fea14._0x3e0cbd)]),!0x1;}}catch(_0x396fc9){return this[_0x4a9d8b(_0x2fea14._0x4b463a,0x1b4)]=null,this[_0x4a9d8b(0x1c3,_0x2fea14._0x3a39d9)]=!0x1,this['_lastAtlasError']=this[_0x4a9d8b(_0x2fea14._0x3a39d9,_0x2fea14._0x2b3d4a)](_0x396fc9),!0x1;}}async[_0x489fad(0x1c2,0x1c7)](){const _0x7a360={_0x202477:0xa8,_0x5bb21b:0xaa,_0x18a2a4:0x61,_0x46336a:0x76,_0x2d539b:0xa3,_0x443eb7:0xaa,_0x47ec51:0x7e,_0x4cd3fa:0x7e,_0x271615:0xa7};if(!this['_atlasDB']||!this[_0x284796(-0x7e,-_0x7a360._0x202477)])return this['_online']=!0x1,!0x1;function _0x284796(_0x10c261,_0x1995a1){return _0x489fad(_0x1995a1,_0x10c261- -0x24e);}try{return await this[_0x284796(-_0x7a360._0x5bb21b,-0xb6)][_0x284796(-0x7c,-_0x7a360._0x18a2a4)]({'ping':0x1}),this[_0x284796(-_0x7a360._0x46336a,-0x71)]=!0x0,this[_0x284796(-0x7b,-0x82)]=null,!0x0;}catch(_0x2b7161){this[_0x284796(-_0x7a360._0x46336a,-_0x7a360._0x2d539b)]=!0x1,this['_lastAtlasError']=this[_0x284796(-0xa2,-0x9c)](_0x2b7161),this[_0x284796(-_0x7a360._0x443eb7,-0xab)]=null;try{this[_0x284796(-_0x7a360._0x47ec51,-0x5b)]&&await this[_0x284796(-_0x7a360._0x4cd3fa,-_0x7a360._0x271615)]['close']();}catch(_0x46fc6c){}return this[_0x284796(-_0x7a360._0x4cd3fa,-0x97)]=null,!0x1;}}async['closeAll'](){const _0x2ad9a8={_0x373c3d:0x16b,_0x5c5898:0x142,_0x2bfb30:0x144,_0xff3074:0x12a,_0x3e028b:0x175,_0x3eb5fc:0x158,_0x324fc6:0x16d,_0x4bc166:0x147,_0x2ebb5e:0x12b,_0x19500b:0x181,_0x285f6e:0x17a,_0x15e003:0x180,_0x26827e:0x184,_0x132384:0x150},_0x381449={_0x54fc1a:0x328};try{this['_localClient']&&await this[_0x1d8782(-0x181,-_0x2ad9a8._0x373c3d)]['close']();}catch(_0x18d8cc){console['warn'](_0x1d8782(-_0x2ad9a8._0x5c5898,-_0x2ad9a8._0x2bfb30),_0x18d8cc?.[_0x1d8782(-0x146,-_0x2ad9a8._0xff3074)]||_0x18d8cc);}function _0x1d8782(_0xcd26d2,_0x426c42){return _0x489fad(_0x426c42,_0xcd26d2- -_0x381449._0x54fc1a);}try{this[_0x1d8782(-0x158,-_0x2ad9a8._0x3e028b)]&&await this[_0x1d8782(-_0x2ad9a8._0x3eb5fc,-0x157)][_0x1d8782(-_0x2ad9a8._0x324fc6,-_0x2ad9a8._0x4bc166)]();}catch(_0x543c62){console['warn'](_0x1d8782(-_0x2ad9a8._0x2ebb5e,-0x140),_0x543c62?.[_0x1d8782(-0x146,-0x132)]||_0x543c62);}this[_0x1d8782(-_0x2ad9a8._0x19500b,-0x18a)]=this[_0x1d8782(-0x158,-_0x2ad9a8._0x285f6e)]=this[_0x1d8782(-_0x2ad9a8._0x15e003,-0x1a0)]=this[_0x1d8782(-_0x2ad9a8._0x26827e,-0x179)]=null,this[_0x1d8782(-_0x2ad9a8._0x132384,-0x14e)]=!0x1;}[_0x489fad(0x1b6,0x1b5)](){const _0x5e71e9={_0x5a6f76:0x1a4,_0x44b7a7:0x1a5,_0x3f5afd:0x1c3};function _0x4ede56(_0x4d6f51,_0x477c84){return _0x489fad(_0x4d6f51,_0x477c84- -0x37d);}return{'localConnected':!!this['_localDB'],'atlasConnected':!!this[_0x4ede56(-0x1ac,-0x1d9)]&&this['_online'],'online':this[_0x4ede56(-_0x5e71e9._0x5a6f76,-_0x5e71e9._0x44b7a7)],'lastAtlasError':this[_0x4ede56(-_0x5e71e9._0x3f5afd,-0x1aa)]};}get[_0x489fad(0x1dd,0x1f6)](){const _0x70a448={_0x19c60a:0x20d},_0x3914af={_0x3d83f2:0x66};function _0x107dfc(_0x7676d7,_0x5e1a04){return _0x489fad(_0x5e1a04,_0x7676d7-_0x3914af._0x3d83f2);}return this[_0x107dfc(_0x70a448._0x19c60a,0x229)];}get[_0x489fad(0x1d3,0x1a6)](){const _0xd5ff24={_0x107c40:0x21a},_0x553b14={_0x45a667:0x6b};function _0x35444a(_0x349bf9,_0x3f75b6){return _0x489fad(_0x349bf9,_0x3f75b6-_0x553b14._0x45a667);}return this[_0x35444a(_0xd5ff24._0x107c40,0x23b)];}get['local'](){return this['_localDB'];}get[_0x489fad(0x199,0x1af)](){const _0x340bb7={_0x4f8d18:0x34d},_0x3fafba={_0x2ac8d6:0x1ce};function _0x2da358(_0x391b2f,_0x228b4f){return _0x489fad(_0x391b2f,_0x228b4f-_0x3fafba._0x2ac8d6);}return this[_0x2da358(_0x340bb7._0x4f8d18,0x372)];}get['online'](){return this['_online'];}set['online'](_0x544504){const _0x4dc4c1={_0x3e7c7c:0x3a0};function _0xf2b1c8(_0x998bec,_0x16373d){return _0x489fad(_0x998bec,_0x16373d- -_0x4dc4c1._0x3e7c7c);}this[_0xf2b1c8(-0x1a0,-0x1c8)]=!!_0x544504;}get[_0x489fad(0x1b3,0x1c2)](){const _0x1bb72b={_0x6d4af2:0x59,_0x35ccb3:0x47};function _0x572149(_0x30258d,_0x5d50b6){return _0x489fad(_0x5d50b6,_0x30258d- -0x17a);}return this[_0x572149(_0x1bb72b._0x6d4af2,_0x1bb72b._0x35ccb3)];}get[_0x489fad(0x219,0x1f7)](){const _0x286031={_0x28d5af:0xde,_0x9b730c:0xd7};function _0xe84a97(_0x2bceb8,_0x250136){return _0x489fad(_0x2bceb8,_0x250136- -0x127);}return this[_0xe84a97(_0x286031._0x28d5af,_0x286031._0x9b730c)];}async[_0x489fad(0x1e1,0x1ea)](_0x5cc7ad){const _0x5ae708={_0x106c2a:0x116,_0x25134a:0xc8,_0x344490:0x11c,_0xdb4618:0x109,_0x353462:0xe3,_0x577d4b:0xe2,_0x1a838a:0x117,_0x381f8a:0x118,_0x377f45:0x113,_0x328781:0x11f,_0x4c70d0:0x110,_0x3d59e9:0xfa,_0x3de85b:0xe1,_0x4e46ee:0x12b,_0x56a601:0xf9,_0x2b9fc2:0x105,_0x5779b4:0xf3,_0x3e5f22:0xeb,_0x239da9:0xd3,_0x49060f:0xfb,_0xf2673d:0xde,_0xe2f794:0x128,_0x906ab8:0xff},_0x48746c={_0x58ded6:0xd2},_0x58453d={_0xb2a868:0x34a},_0x310371=async(_0xb3709c,_0x4350bd,_0x4b0081={})=>{function _0x4074a7(_0xea184a,_0x5e63a6){return _0x22f1(_0x5e63a6-0x181,_0xea184a);}try{await _0x5cc7ad['collection'](_0xb3709c)[_0x4074a7(0x36c,0x34e)](_0x4350bd,_0x4b0081);}catch(_0xfdf665){console['warn'](_0x4074a7(0x33d,_0x58453d._0xb2a868)+_0xb3709c+')\x20warning:',_0xfdf665?.['message']||_0xfdf665);}};await _0x5cc7ad[_0x14442d(0x144,_0x5ae708._0x106c2a)](_0x14442d(0xf2,0x109))[_0x14442d(_0x5ae708._0x25134a,0xee)](()=>{});try{await _0x5cc7ad['collection'](_0x14442d(_0x5ae708._0x344490,_0x5ae708._0xdb4618))[_0x14442d(0xd3,0xde)]([{'key':{'opId':0x1},'unique':!0x0,'sparse':!0x0,'name':_0x14442d(0x136,0x10e)},{'key':{'synced':0x1,'timestamp':0x1},'name':_0x14442d(0x102,0x12d)},{'key':{'collection':0x1,'type':0x1,'timestamp':0x1},'name':_0x14442d(_0x5ae708._0x353462,_0x5ae708._0x577d4b)},{'key':{'collection':0x1,'ownerKey':0x1,'timestamp':0x1},'name':'idx_track_owner_ts'},{'key':{'synced':0x1,'ackState':0x1,'retryCount':0x1,'timestamp':0x1},'name':'idx_track_retry'},{'key':{'collection':0x1,'synced':0x1,'ackState':0x1},'name':_0x14442d(0xf6,_0x5ae708._0x1a838a)},{'key':{'collection':0x1,'synced':0x1,'ackState':0x1,'_id':0x1},'name':'idx_track_upload_cursor'}]);}catch(_0x4fce4d){console[_0x14442d(_0x5ae708._0x381f8a,_0x5ae708._0x377f45)](_0x14442d(_0x5ae708._0x328781,0xf2),_0x4fce4d?.[_0x14442d(0xe4,_0x5ae708._0x4c70d0)]||_0x4fce4d);}await _0x310371(_0x14442d(_0x5ae708._0x577d4b,0x109),{'syncedAt':0x1},{'expireAfterSeconds':0x93a80,'name':_0x14442d(_0x5ae708._0x3d59e9,_0x5ae708._0x3de85b),'background':!0x0}),await this['_runMigrations'](_0x5cc7ad),await _0x5cc7ad[_0x14442d(_0x5ae708._0x4e46ee,0x116)]('_mf_devices')['catch'](()=>{}),await _0x310371('_mf_devices',{'deviceId':0x1},{'unique':!0x0,'name':_0x14442d(0xc3,0xdc)}),await _0x5cc7ad[_0x14442d(_0x5ae708._0x56a601,_0x5ae708._0x106c2a)](_0x14442d(0x102,_0x5ae708._0x2b9fc2))[_0x14442d(0x116,0xee)](()=>{});try{await _0x5cc7ad[_0x14442d(0x102,0xfb)](_0x14442d(_0x5ae708._0x5779b4,0x105))[_0x14442d(0xd6,0xde)]([{'key':{'collection':0x1,'docId':0x1},'unique':!0x0,'name':_0x14442d(0x113,_0x5ae708._0x3e5f22)},{'key':{'collection':0x1,'updatedByOpId':0x1},'sparse':!0x0,'name':_0x14442d(0xc3,0xe6)}]);}catch(_0x3fe07f){console['warn'](_0x14442d(0x11e,0x102),_0x3fe07f?.['message']||_0x3fe07f);}await _0x5cc7ad['createCollection']('_mf_sync_state')[_0x14442d(0x105,0xee)](()=>{});function _0x14442d(_0x1ed3b4,_0x1b3afe){return _0x489fad(_0x1ed3b4,_0x1b3afe- -_0x48746c._0x58ded6);}try{await _0x5cc7ad[_0x14442d(_0x5ae708._0x239da9,_0x5ae708._0x49060f)]('_mf_sync_state')[_0x14442d(0xd5,_0x5ae708._0xf2673d)]([{'key':{'ownerKey':0x1,'collection':0x1,'kind':0x1},'name':_0x14442d(_0x5ae708._0xe2f794,_0x5ae708._0x906ab8)}]);}catch(_0x330f9b){console['warn'](_0x14442d(0x137,_0x5ae708._0xe2f794),_0x330f9b?.['message']||_0x330f9b);}}async[_0x489fad(0x1b8,0x1aa)](_0x29876a){const _0x54e355={_0x164b61:0x108,_0x7ba411:0xe7,_0x2a981b:0xda,_0x28ecf5:0xc7,_0x295746:0xa0,_0x1811fd:0xfa,_0x164b6e:0xd9,_0x38c45b:0xd5,_0x393f77:0xac,_0x4f5ba4:0xf1,_0x20a603:0xc0,_0x32a01c:0xe7,_0x324c12:0xe1,_0x358555:0xf9,_0x3afd5f:0xf7,_0x5e290b:0xec,_0x2068ac:0xef,_0x1cf1f8:0xbb,_0xc40509:0xb6,_0x3ecab6:0xee,_0x2ca998:0xc5};await _0x29876a['createCollection'](_0x51bfa3(-0xe7,-0xcc))[_0x51bfa3(-_0x54e355._0x164b61,-_0x54e355._0x7ba411)](()=>{});try{await _0x29876a[_0x51bfa3(-0xf1,-_0x54e355._0x2a981b)](_0x51bfa3(-0xe5,-0xcc))[_0x51bfa3(-0xf6,-0xf7)]([{'key':{'opId':0x1},'unique':!0x0,'sparse':!0x0,'name':_0x51bfa3(-0xd4,-_0x54e355._0x28ecf5)},{'key':{'synced':0x1,'timestamp':0x1},'name':_0x51bfa3(-_0x54e355._0x295746,-0xa8)},{'key':{'collection':0x1,'type':0x1,'timestamp':0x1},'name':'idx_track_changed'},{'key':{'collection':0x1,'ownerKey':0x1,'timestamp':0x1},'name':'idx_track_owner_ts'},{'key':{'synced':0x1,'ackState':0x1,'retryCount':0x1,'timestamp':0x1},'name':_0x51bfa3(-_0x54e355._0x1811fd,-0xfa)},{'key':{'collection':0x1,'ownerKey':0x1,'applyStatus':0x1,'timestamp':0x1},'name':_0x51bfa3(-0xe4,-_0x54e355._0x164b6e)},{'key':{'collection':0x1,'synced':0x1,'ackState':0x1},'name':_0x51bfa3(-_0x54e355._0x38c45b,-0xbe)}]);}catch(_0x4dd634){console['warn'](_0x51bfa3(-0x84,-_0x54e355._0x393f77),_0x4dd634?.['message']||_0x4dd634);}await _0x29876a[_0x51bfa3(-_0x54e355._0x4f5ba4,-_0x54e355._0x2a981b)](_0x51bfa3(-0xe2,-0xcc))[_0x51bfa3(-0x96,-_0x54e355._0x20a603)]({'syncedAt':0x1},{'expireAfterSeconds':0x93a80,'name':'ttl_synced_ops','background':!0x0})[_0x51bfa3(-0xf2,-_0x54e355._0x7ba411)](()=>{}),await _0x29876a[_0x51bfa3(-0xfe,-0xda)]('_mf_changetrack')[_0x51bfa3(-0xcf,-0xc0)]({'remoteAckAt':0x1,'syncedAt':0x1},{'expireAfterSeconds':0x93a80,'name':'ttl_remote_acked_ops','partialFilterExpression':{'syncedAt':{'$exists':!0x1}},'background':!0x0})[_0x51bfa3(-0xf1,-_0x54e355._0x32a01c)](()=>{}),await _0x29876a['createCollection'](_0x51bfa3(-_0x54e355._0x324c12,-0xd0))['catch'](()=>{});function _0x51bfa3(_0x3a9e55,_0x369fc9){return _0x489fad(_0x3a9e55,_0x369fc9- -0x2a7);}try{await _0x29876a[_0x51bfa3(-_0x54e355._0x358555,-_0x54e355._0x2a981b)](_0x51bfa3(-0xb5,-0xd0))[_0x51bfa3(-0x105,-_0x54e355._0x3afd5f)]([{'key':{'collection':0x1,'docId':0x1},'unique':!0x0,'name':'uniq_docmeta_collection_docid'},{'key':{'collection':0x1,'updatedByOpId':0x1},'sparse':!0x0,'name':_0x51bfa3(-_0x54e355._0x5e290b,-_0x54e355._0x2068ac)}]);}catch(_0x5b623b){console[_0x51bfa3(-_0x54e355._0x1cf1f8,-0xc2)](_0x51bfa3(-_0x54e355._0xc40509,-0xe2),_0x5b623b?.[_0x51bfa3(-_0x54e355._0x3ecab6,-_0x54e355._0x2ca998)]||_0x5b623b);}}async[_0x489fad(0x1d7,0x1b9)](_0x1a24c2){const _0x4d6fad={_0x1d64af:0x273,_0x257e4b:0x23e,_0x29b797:0x25c,_0x323fcf:0x265,_0xb52569:0x23e,_0x48b436:0x245,_0x40286d:0x284,_0x25ae79:0x23b,_0x1ddc24:0x265,_0x464a46:0x26a,_0x2e0a80:0x217,_0x5f51c3:0x23e,_0x432196:0x24b,_0x4cbfc9:0x2a0,_0x5e7ea2:0x22c,_0x5827e2:0x26e,_0x4ec015:0x244,_0x11f011:0x28a,_0x2298c5:0x230,_0x3d8185:0x24d,_0x1d8a4c:0x20a,_0x33ee46:0x277},_0x4d4eb9={_0xdb6807:0x7e},_0x4b4e26=_0x1a24c2[_0x4a58ea(0x24b,_0x4d6fad._0x1d64af)]('_mf_changetrack');await _0x4b4e26['updateMany']({'type':{'$exists':!0x1},'op':{'$exists':!0x0}},[{'$set':{'type':_0x4a58ea(0x23d,0x235)}}])[_0x4a58ea(_0x4d6fad._0x257e4b,0x211)](()=>{}),await _0x4b4e26[_0x4a58ea(_0x4d6fad._0x29b797,0x28b)]({'payload':{'$exists':!0x1},'doc':{'$exists':!0x0}},[{'$set':{'payload':_0x4a58ea(0x25b,_0x4d6fad._0x323fcf)}}])[_0x4a58ea(_0x4d6fad._0xb52569,_0x4d6fad._0x48b436)](()=>{}),await _0x4b4e26[_0x4a58ea(0x25c,_0x4d6fad._0x40286d)]({'ownerKey':{'$exists':!0x1},'ownerId':{'$exists':!0x0}},[{'$set':{'ownerKey':_0x4a58ea(0x24d,0x25a)}}])[_0x4a58ea(0x23e,_0x4d6fad._0x25ae79)](()=>{}),await _0x4b4e26[_0x4a58ea(_0x4d6fad._0x29b797,_0x4d6fad._0x1ddc24)]({'timestamp':{'$exists':!0x1}},[{'$set':{'timestamp':{'$ifNull':[_0x4a58ea(0x234,0x23b),{'$ifNull':[_0x4a58ea(_0x4d6fad._0x464a46,0x24e),_0x4a58ea(0x227,_0x4d6fad._0x2e0a80)]}]}}}])[_0x4a58ea(_0x4d6fad._0xb52569,0x214)](()=>{}),await _0x4b4e26[_0x4a58ea(_0x4d6fad._0x29b797,0x232)]({'opId':{'$exists':!0x1}},[{'$set':{'opId':{'$concat':['legacy-',{'$toString':'$_id'}]}}}])[_0x4a58ea(_0x4d6fad._0x5f51c3,0x264)](()=>{}),await _0x4b4e26[_0x4a58ea(0x25c,_0x4d6fad._0x432196)]({'ackState':{'$exists':!0x1}},[{'$set':{'ackState':{'$cond':[{'$eq':[_0x4a58ea(0x273,_0x4d6fad._0x4cbfc9),!0x0]},_0x4a58ea(0x241,_0x4d6fad._0x5e7ea2),_0x4a58ea(_0x4d6fad._0x5827e2,_0x4d6fad._0x4ec015)]}}}])[_0x4a58ea(_0x4d6fad._0x5f51c3,_0x4d6fad._0x29b797)](()=>{}),await _0x4b4e26[_0x4a58ea(0x25c,0x284)]({'retryCount':{'$exists':!0x1}},{'$set':{'retryCount':0x0}})['catch'](()=>{});function _0x4a58ea(_0x1c1b97,_0x2e4fd9){return _0x489fad(_0x2e4fd9,_0x1c1b97-_0x4d4eb9._0xdb6807);}try{const _0x5c68ba=await _0x4b4e26[_0x4a58ea(_0x4d6fad._0x29b797,_0x4d6fad._0x11f011)]({'$or':[{'op':{'$exists':!0x0}},{'doc':{'$exists':!0x0}},{'ownerId':{'$exists':!0x0}},{'changedAt':{'$exists':!0x0}}]},{'$unset':{'op':'','doc':'','ownerId':'','changedAt':''}});_0x5c68ba[_0x4a58ea(_0x4d6fad._0x2298c5,_0x4d6fad._0x3d8185)]>0x0&&console['log']('[MongoFire]\x20Dedup\x20migration:\x20cleaned\x20'+_0x5c68ba[_0x4a58ea(0x230,_0x4d6fad._0x1d8a4c)]+_0x4a58ea(_0x4d6fad._0x33ee46,0x255));}catch(_0x3571de){console[_0x4a58ea(0x263,0x248)](_0x4a58ea(0x26f,0x255),_0x3571de?.['message']||_0x3571de);}}[_0x489fad(0x194,0x1ac)](_0x1d317a){const _0x2fd147={_0x2448d4:0x17e,_0x849695:0x15c,_0x5091c7:0x153,_0x51b043:0x194},_0x5b263f={_0x24ddce:0x64};function _0x5c41a2(_0x384eba,_0x46c782){return _0x489fad(_0x384eba,_0x46c782- -_0x5b263f._0x24ddce);}return _0x1d317a?_0x1d317a[_0x5c41a2(0x199,_0x2fd147._0x2448d4)]?_0x1d317a['message']+(_0x1d317a[_0x5c41a2(_0x2fd147._0x849695,0x15d)]?_0x5c41a2(0x14a,_0x2fd147._0x5091c7)+(_0x1d317a['stack'][_0x5c41a2(_0x2fd147._0x51b043,0x176)]('\x0a')[0x1]||''):''):String(_0x1d317a):_0x5c41a2(0x15c,0x165);}}function _0x489fad(_0x4f1bcf,_0x24cb52){const _0x5f1f5b={_0x559c03:0x1a};return _0x22f1(_0x24cb52-_0x5f1f5b._0x559c03,_0x4f1bcf);}const _singleton=new Connection();module[_0x489fad(0x1b8,0x1a5)]=_singleton,module[_0x489fad(0x1c5,0x1a5)]['Connection']=Connection;function _0x22f1(_0x4d0ff9,_0xffba44){_0x4d0ff9=_0x4d0ff9-0x18a;const _0x4836d0=_0x4836();let _0x22f1e1=_0x4836d0[_0x4d0ff9];if(_0x22f1['pMpIrv']===undefined){var _0x52d965=function(_0xf0230a){const _0x49c83c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2e839c='',_0x53413f='';for(let _0x306ea5=0x0,_0x37aecf,_0x263722,_0x237213=0x0;_0x263722=_0xf0230a['charAt'](_0x237213++);~_0x263722&&(_0x37aecf=_0x306ea5%0x4?_0x37aecf*0x40+_0x263722:_0x263722,_0x306ea5++%0x4)?_0x2e839c+=String['fromCharCode'](0xff&_0x37aecf>>(-0x2*_0x306ea5&0x6)):0x0){_0x263722=_0x49c83c['indexOf'](_0x263722);}for(let _0x46db4d=0x0,_0x165557=_0x2e839c['length'];_0x46db4d<_0x165557;_0x46db4d++){_0x53413f+='%'+('00'+_0x2e839c['charCodeAt'](_0x46db4d)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x53413f);};_0x22f1['HFcEcm']=_0x52d965,_0x22f1['NKWFWU']={},_0x22f1['pMpIrv']=!![];}const _0x2f7612=_0x4836d0[0x0],_0x4b4aa4=_0x4d0ff9+_0x2f7612,_0x4c609e=_0x22f1['NKWFWU'][_0x4b4aa4];return!_0x4c609e?(_0x22f1e1=_0x22f1['HFcEcm'](_0x22f1e1),_0x22f1['NKWFWU'][_0x4b4aa4]=_0x22f1e1):_0x22f1e1=_0x4c609e,_0x22f1e1;}function _0x4836(){const _0x5bbb7a=['oda4wMPyuuPe','AxnYzxbSAwnHC2v0','Bg9N','y29SBgvJDgLVBG','Awr4x3rYywnRx3rLBMfUDf9KBa','jg93BMvYswq','x2f0BgfZq2XPzw50','Awr4x3n5BMnFC3rHDgvFA2v5','y29TBwfUza','x2XHC3rbDgXHC0vYCM9Y','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFzg9JBwv0ys9SB2nHBcK6','4Os577IpicbBtw9Uz29gAxjLxsbmB2nHBcbYzxbSAwnHihnLDcbKzxrLy3rLzcdIGjqGyxrVBwLJignOyw5Nzs10CMfJA2LUzYbLBMfIBgvK','mJaYmhnvA25jyG','x21Mx2rVy21LDge','x29UBgLUzq','w01VBMDVrMLYzv0Gx3nLDhvWqxrSyxndB2XSzwn0Aw9UCYbMywLSzwq6','C3bSAxq','x21Mx2nOyw5NzxrYywnR','odrZrwXwtey','jgrVyW','DxbKyxrLtwfUEq','Bw9Uz29KyG','Dw5PCv90CMfJA19VCgLK','ywrTAw4','BwvZC2fNzq','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxGO','mtfQBMDSCem','D2fYBG','w01VBMDVrMLYzv0GzxjYB3iGy2XVC2LUzYbSB2nHBcbJBgLLBNq6','y3jLyxrLsw5KzxG','y3jLyxrLq29SBgvJDgLVBG','Awr4x3rYywnRx2nVBxbYzxnZ','x3nLDhvWtg9JywXdB2XSzwn0Aw9UCW','nJmXntG1s1fgAuDc','jhvWzgf0zwrbDa','w01VBMDVrMLYzv0Gvg9WB2XVz3KGChjVyMuGzMfPBgvKicHUB24TzMf0ywWPoG','nJu2nJDMrgDorwK','4PYfifTnB25NB0zPCMvDieXVy2fSie1VBMDVreiGCMvHzhK','CgvUzgLUzW','w01VBMDVrMLYzv0GrgvKDxaGBwLNCMf0Aw9UicHUB24TzMf0ywWPoG','w01VBMDVrMLYzv0Gx3nLDhvWtg9JywXdB2XSzwn0Aw9UCYbMywLSzwq6','w01VBMDVrMLYzv0Gq29UBMvJDgvKihrVief0BgfZigj1DcbWAw5NigzHAwXLzdO','nJKZnZjns0D1yKq','jhn5BMnLza','Bg9JywXdBgLLBNq','AxnmB2nHBfjLCgXPy2ftzxq','AxnbCNjHEq','igXLz2fJEsbMAwvSzcHZkq','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFC3LUy19ZDgf0zsK6','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFy2HHBMDLDhjHy2SVyxrSyxmPoG','x2f0BgfZu2v0DxbeB25L','w01VBMDVrMLYzv0GzxjYB3iGy2XVC2LUzYbbDgXHCYbJBgLLBNq6','x2LZtg9JywXszxbSAwnHu2v0','Awr4x3rYywnRx3bLBMrPBMC','Ag9ZDhm','x2f0BgfZrei','zxHWB3j0CW','yxrSyxndBgLLBNq','x2XVy2fSq2XPzw50','x2XVy2fSrei','jgnYzwf0zwrbDa','x3nLDhvWqxrSyxndB2XSzwn0Aw9UCW','odC4odHUBhHbuLG','x2zVCM1HDevYCM9Y','Awr4x3rYywnRx3jLDhj5','Awr4x2rLDMLJzv9Pza','yxrSyxm','y3jLyxrLsw5KzxHLCW','y29UBMvJDa','Bw9KAwzPzwrdB3vUDa','DhrSx3n5BMnLzf9VChm','Awr4x3rYywnRx2nOyw5Nzwq','z2v0u3rHDhvZ','jgnOyw5NzwrbDa','iokaLca','Awr4x2rVy21LDgfFCMvJB25JAwXLx3aX','x3j1BK1Pz3jHDgLVBNm','BgvUz3rO','y2XVC2u','mtu4otKXn090qMHIuW','Dw5PCv9KB2nTzxrHx2nVBgXLy3rPB25Fzg9JAwq','nda0mdi0nhfrq0HwEa','jg9W','y2f0y2G','C3rHy2S','BgfZDef0BgfZrxjYB3i','ywnRzwq','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFy2HHBMDLDhjHy2SVBg9JywWPoG','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFzg9JBwv0ys9HDgXHCYK6','mZyZodaXmdbHzu5YuNu','CgLUz0f0BgfZ','mZjesKX2BxC','Dw5RBM93BIbLCNjVCG'];_0x4836=function(){return _0x5bbb7a;};return _0x4836();}
|
|
1
|
+
'use strict';function _0x4185c1(_0x1064b9,_0x140f98){const _0x4e1585={_0x177f04:0x3ae};return _0x355f(_0x1064b9- -_0x4e1585._0x177f04,_0x140f98);}(function(_0x18303d,_0xa13310){const _0xc85a0c={_0xd4abec:0x1c1,_0x16cf87:0x1a3,_0xfd70d1:0x1f2,_0x1d48ff:0x1d1,_0x2acb72:0x18d,_0x32dadf:0x1a0,_0x23b082:0x18a,_0x7b5858:0x1b2,_0x24ff90:0x1e9,_0x544ea4:0x1cf,_0x292a56:0x17a,_0xf4fe46:0x1b0};function _0x59d5c7(_0x2e189e,_0x53a97e){return _0x355f(_0x53a97e- -0x398,_0x2e189e);}const _0x44a177=_0x18303d();while(!![]){try{const _0x2811ea=parseInt(_0x59d5c7(-_0xc85a0c._0xd4abec,-_0xc85a0c._0x16cf87))/0x1*(parseInt(_0x59d5c7(-0x1ac,-0x1a2))/0x2)+-parseInt(_0x59d5c7(-_0xc85a0c._0xfd70d1,-_0xc85a0c._0x1d48ff))/0x3*(parseInt(_0x59d5c7(-_0xc85a0c._0x2acb72,-_0xc85a0c._0x32dadf))/0x4)+parseInt(_0x59d5c7(-_0xc85a0c._0x23b082,-0x1ae))/0x5+parseInt(_0x59d5c7(-_0xc85a0c._0x7b5858,-0x18e))/0x6+parseInt(_0x59d5c7(-0x17a,-0x171))/0x7+-parseInt(_0x59d5c7(-_0xc85a0c._0x24ff90,-_0xc85a0c._0x544ea4))/0x8*(-parseInt(_0x59d5c7(-_0xc85a0c._0x292a56,-0x17e))/0x9)+-parseInt(_0x59d5c7(-_0xc85a0c._0xf4fe46,-0x17f))/0xa;if(_0x2811ea===_0xa13310)break;else _0x44a177['push'](_0x44a177['shift']());}catch(_0x250c6a){_0x44a177['push'](_0x44a177['shift']());}}}(_0x3c02,0x5583e));function _0x3c02(){const _0x3046f0=['x3nLDhvWqxrSyxndB2XSzwn0Aw9UCW','zxHWB3j0CW','C2v0tMfTzq','Bg9N','C3rHy2S','Awr4x3rYywnRx3rLBMfUDf9KBa','x29UBgLUzq','BwfPBG','x21Mx3n5BMnFC3rHDgu','Bw9Uz29KyG','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFzg9JBwv0ys9SB2nHBcK6','Dw5PCv90CMfJA19VCgLK','ywrTAw4','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxGO','z2v0u3rHDhvZ','mJuXndC2nuLIt1fWCG','4Os577IpicbBtw9Uz29gAxjLxsbmB2nHBcbYzxbSAwnHihnLDcbKzxrLy3rLzcdIGjqGyxrVBwLJignOyw5Nzs10CMfJA2LUzYbLBMfIBgvK','x2f0BgfZq2XPzw50','y2XVC2u','y29SBgvJDgLVBG','zxjYB3i','4PYfifTnB25NB0zPCMvDieXVy2fSie1VBMDVreiGCMvHzhKG4Ocuia','x3nLDhvWtg9JywXdB2XSzwn0Aw9UCW','Awr4x2rVy21LDgfFCMvJB25JAwXLx3aX','y3jLyxrLq29SBgvJDgLVBG','AxnYzxbSAwnHC2v0','mZKZmdK0u05NwfnL','mLnfy1bNsW','Dw5PCv9KB2nTzxrHx2nVBgXLy3rPB25Fzg9JAwq','mJm1oty5mNfLDNH0rG','x2XHC3rbDgXHC0vYCM9Y','x2XVy2fSq2XPzw50','DxbKyxrLtwfUEq','y3DK','Bg9JywXdBgLLBNq','iokaLca','yxrSyxm','BwvZC2fNzq','D2fYBG','y3jLyxrLsw5KzxHLCW','w01VBMDVrMLYzv0Gq29UBMvJDgvKihrVief0BgfZigj1DcbWAw5NigzHAwXLzdO','4PYfifTnB25NB0zPCMvDief0BgfZignVBM5Ly3rLzcbHBMqGAgvHBhrOEq','Awr4x3rYywnRx293BMvYx3rZ','BgfZDef0BgfZrxjYB3i','Cg9YDa','y29UBMvJDgLVBG','Dw5RBM93BIbLCNjVCG','mJu3ntu5mgvYzuXryq','Awr4x3rYywnRx2nVBxbYzxnZ','Ag9ZDa','jhvWzgf0zwrbDa','x2f0BgfZu2v0DxbeB25L','BgvUz3rO','CgvUzgLUzW','Awr4x3n5BMnFC3rHDgvFA2v5','w01VBMDVrMLYzv0Gx3nLDhvWqxrSyxndB2XSzwn0Aw9UCYbMywLSzwq6','y29UBMvJDa','y3jLyxrLsw5KzxG','zw52','jf9Pza','x2LZtg9JywXszxbSAwnHu2v0','x21Mx2rLDMLJzxm','mta0odKXotbWC3HozLy','owzwv0HPvq','CgLUz0f0BgfZ','w01VBMDVrMLYzv0GrxjYB3iGy2XVC2LUzYbbDgXHCYbJBgLLBNq6','x21Mx2nOyw5NzxrYywnR','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFy2HHBMDLDhjHy2SVyxrSyxmPoG','z2v0q2XPzw50','y29UBMvJDeXVy2fS','Awr4x3rYywnRx3vWBg9Hzf9JDxjZB3i','jg9W','x2f0BgfZrei','ywnRzwq','igXLz2fJEsbMAwvSzcHZkq','Awr4x3rYywnRx3bLBMrPBMC','mtK2nduWohvjr25fBq','y2f0y2G','x2XVy2fSrei','jg93BMvYswq','m1H1B0TnBq','DhrSx3jLBw90zv9Hy2TLzf9VChm','mZa2nti0oe5fv29Jwq','jhn5BMnLza','w01VBMDVrMLYzv0Gvg9WB2XVz3KGChjVyMuGzMfPBgvKicHUB24TzMf0ywWPoG','w01VBMDVrMLYzv0Gy3jLyxrLsw5KzxHLCYHFBwzFC3LUy19ZDgf0zsK6','Awr4x3rYywnRx2nOyw5Nzwq','AxnmB2nHBfjLCgXPy2ftzxq','x21Mx2rVy21LDge','y29UBMvJDef0BgfZ','x2zVCM1HDevYCM9Y','AxnbCNjHEq','Awr4x3rYywnRx3jLDhj5','zgLZy29UBMvJDa','BxLHCha','y29TBwfUza','Ag9ZDhm','q29UBMvJDgLVBG','x3j1BK1Pz3jHDgLVBNm','BgvNywn5lq'];_0x3c02=function(){return _0x3046f0;};return _0x3c02();}function _0x355f(_0x220f90,_0x3d4313){_0x220f90=_0x220f90-0x1c7;const _0x3c02ab=_0x3c02();let _0x355fa9=_0x3c02ab[_0x220f90];if(_0x355f['tzOeOS']===undefined){var _0x30b470=function(_0x495032){const _0xc56245='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x41dacc='',_0x2a1f58='';for(let _0x1282b9=0x0,_0x53a3b6,_0xdbcbe7,_0x3e6a9a=0x0;_0xdbcbe7=_0x495032['charAt'](_0x3e6a9a++);~_0xdbcbe7&&(_0x53a3b6=_0x1282b9%0x4?_0x53a3b6*0x40+_0xdbcbe7:_0xdbcbe7,_0x1282b9++%0x4)?_0x41dacc+=String['fromCharCode'](0xff&_0x53a3b6>>(-0x2*_0x1282b9&0x6)):0x0){_0xdbcbe7=_0xc56245['indexOf'](_0xdbcbe7);}for(let _0x1bcf77=0x0,_0x5187e0=_0x41dacc['length'];_0x1bcf77<_0x5187e0;_0x1bcf77++){_0x2a1f58+='%'+('00'+_0x41dacc['charCodeAt'](_0x1bcf77)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x2a1f58);};_0x355f['WvhpRB']=_0x30b470,_0x355f['RTCPOO']={},_0x355f['tzOeOS']=!![];}const _0x22aa97=_0x3c02ab[0x0],_0x156f53=_0x220f90+_0x22aa97,_0x108563=_0x355f['RTCPOO'][_0x156f53];return!_0x108563?(_0x355fa9=_0x355f['WvhpRB'](_0x355fa9),_0x355f['RTCPOO'][_0x156f53]=_0x355fa9):_0x355fa9=_0x108563,_0x355fa9;}const {MongoClient:MongoClient}=require(_0x4185c1(-0x1ca,-0x1a8)),localManager=require('./local-manager');class Connection{constructor(){const _0x24cc11={_0x1c3ffc:0x3b0,_0x5b5188:0x3a2,_0x4aa9eb:0x3d8,_0x1847f3:0x3cf},_0x227ace={_0x2cfe3e:0x56f};function _0x59bb18(_0x42ed1b,_0x1a736e){return _0x4185c1(_0x1a736e-_0x227ace._0x2cfe3e,_0x42ed1b);}this['_localClient']=null,this['_atlasClient']=null,this['_localDB']=null,this['_atlasDB']=null,this[_0x59bb18(_0x24cc11._0x1c3ffc,_0x24cc11._0x5b5188)]=!0x1,this['_lastAtlasError']=null,this[_0x59bb18(0x3eb,_0x24cc11._0x4aa9eb)]=!0x1,this[_0x59bb18(0x3ec,_0x24cc11._0x1847f3)]=!0x1;}async[_0x4185c1(-0x18e,-0x176)](_0x41dacc,_0x2a1f58){const _0x412ed3={_0x4c6650:0x23c,_0x1262db:0x261,_0x5c94f9:0x25f,_0x519800:0x248,_0x356d99:0x23e,_0x2967a5:0x22e,_0x226711:0x254,_0xe95721:0x268,_0x514126:0x26b,_0x5a7b3a:0x256,_0x292281:0x246,_0xf941fd:0x20f,_0x437081:0x233,_0x598a6c:0x241,_0x4f655f:0x23c,_0x87201d:0x263,_0x2978f4:0x229,_0x1b147f:0x240,_0x3ba988:0x21e,_0x9e4144:0x223,_0x5e3533:0x25b,_0xc7369f:0x256,_0x113581:0x237,_0x57caad:0x24c,_0x568a37:0x23d,_0x3f0cf7:0x270,_0x41d5cf:0x275,_0x1984b1:0x230,_0x880f9a:0x23c,_0xdd7300:0x281,_0x3f9630:0x258,_0x42d307:0x254,_0x5acd97:0x253,_0x53a14d:0x275},_0x590db5={_0x5009cc:0x565,_0x4781bb:0x541},_0x1282b9=_0x2a1f58||process[_0x4e8639(_0x412ed3._0x4c6650,_0x412ed3._0x1262db)]['DB_NAME']||_0x4e8639(0x220,0x221);await localManager[_0x4e8639(0x28b,_0x412ed3._0x5c94f9)](_0x41dacc,_0x2a1f58);const _0x53a3b6=require['resolve']('mongoose',{'paths':[process[_0x4e8639(0x226,_0x412ed3._0x519800)](),...require[_0x4e8639(_0x412ed3._0x356d99,_0x412ed3._0x2967a5)]?.['paths']??[]]}),_0xdbcbe7=require(_0x53a3b6);this['_localClient']=_0xdbcbe7[_0x4e8639(0x247,_0x412ed3._0x226711)][_0x4e8639(_0x412ed3._0xe95721,_0x412ed3._0x514126)](),this[_0x4e8639(0x29d,0x275)]=_0xdbcbe7[_0x4e8639(0x233,_0x412ed3._0x226711)]['db'],this['_isLocalReplicaSet']=!0x1;function _0x4e8639(_0x45cc9a,_0x580fd9){return _0x4185c1(_0x580fd9-0x3fa,_0x45cc9a);}try{const _0x3e6a9a=this[_0x4e8639(_0x412ed3._0x5a7b3a,_0x412ed3._0x292281)]['db'](_0x4e8639(_0x412ed3._0xf941fd,_0x412ed3._0x437081));let _0x1bcf77;try{_0x1bcf77=await _0x3e6a9a[_0x4e8639(0x20a,0x222)]({'hello':0x1});}catch(_0x5187e0){_0x1bcf77=await _0x3e6a9a[_0x4e8639(_0x412ed3._0x598a6c,0x222)]({'isMaster':0x1});}this[_0x4e8639(_0x412ed3._0x4f655f,_0x412ed3._0x87201d)]=!!(_0x1bcf77?.[_0x4e8639(0x21d,0x229)]||_0x1bcf77?.[_0x4e8639(_0x412ed3._0x2978f4,_0x412ed3._0x1b147f)]||Array[_0x4e8639(0x1fe,_0x412ed3._0x3ba988)](_0x1bcf77?.[_0x4e8639(0x1fe,0x223)])&&_0x1bcf77[_0x4e8639(0x21b,_0x412ed3._0x9e4144)][_0x4e8639(0x28c,_0x412ed3._0x5e3533)]>0x0),this['_isLocalReplicaSet']&&console[_0x4e8639(_0x412ed3._0xc7369f,0x22a)](_0x4e8639(0x20b,_0x412ed3._0x113581));}catch(_0x2e9156){console['warn'](_0x4e8639(0x20f,0x217),_0x2e9156?.[_0x4e8639(0x26d,_0x412ed3._0x57caad)]);}return await this[_0x4e8639(0x23c,_0x412ed3._0x568a37)](this[_0x4e8639(_0x412ed3._0x3f0cf7,_0x412ed3._0x41d5cf)])[_0x4e8639(0x26a,0x274)](_0x30f69c=>{function _0x4cfd86(_0x4bfd55,_0x3aad9b){return _0x4e8639(_0x4bfd55,_0x3aad9b-0x306);}console[_0x4cfd86(_0x590db5._0x5009cc,_0x590db5._0x4781bb)]('[MongoFire]\x20_setupLocalCollections\x20failed:',_0x30f69c?.['stack']||_0x30f69c);}),console[_0x4e8639(_0x412ed3._0x1984b1,0x22a)](_0x4e8639(_0x412ed3._0x2978f4,_0x412ed3._0x880f9a)+_0xdbcbe7['connection'][_0x4e8639(_0x412ed3._0xdd7300,_0x412ed3._0x3f9630)]+':'+(_0xdbcbe7[_0x4e8639(0x247,_0x412ed3._0x42d307)][_0x4e8639(0x234,_0x412ed3._0x5acd97)]||0x6989)+'/'+_0x1282b9),this[_0x4e8639(0x296,_0x412ed3._0x53a14d)];}async[_0x4185c1(-0x1de,-0x1d9)](_0x2cc595,_0x47ddf5){const _0x231a9c={_0x286170:0x5b3,_0x3b55ac:0x5b4,_0x2a7588:0x5f7,_0x1c8b83:0x5a8,_0x17be93:0x5ac,_0x5b69e5:0x5b3,_0x5005c8:0x5e6,_0x1c4845:0x5d5,_0x1cc1a4:0x58d,_0x578584:0x5a2,_0x217c36:0x5a5,_0xa4f7d8:0x5e7,_0x573e59:0x5a8,_0x442c92:0x598,_0xe5a718:0x59b,_0xf73f6b:0x59e,_0x4de6a9:0x5ca},_0x2f2d21={_0xc8c38e:0x2f7,_0x9d6477:0x2fc},_0x204acb={_0x1656f2:0x775};if(!_0x2cc595)return this['_lastAtlasError']='atlasUri\x20is\x20missing',!0x1;function _0x47602d(_0x2921fc,_0x390687){return _0x4185c1(_0x390687-_0x204acb._0x1656f2,_0x2921fc);}try{if(this[_0x47602d(0x5cc,_0x231a9c._0x286170)]){try{await this[_0x47602d(0x5c4,0x5b3)][_0x47602d(0x5dd,_0x231a9c._0x3b55ac)]();}catch(_0x2c7382){}this[_0x47602d(0x5d5,0x5b3)]=null,this[_0x47602d(_0x231a9c._0x2a7588,0x5ea)]=null,this[_0x47602d(0x5bf,_0x231a9c._0x1c8b83)]=!0x1;}this[_0x47602d(_0x231a9c._0x17be93,_0x231a9c._0x286170)]=new MongoClient(_0x2cc595,{'maxPoolSize':0x64,'minPoolSize':0x5,'serverSelectionTimeoutMS':0x1f40,'socketTimeoutMS':0xafc8,'retryWrites':!0x0,'retryReads':!0x0,'w':'majority'}),await this[_0x47602d(0x5da,_0x231a9c._0x5b69e5)]['connect'](),this[_0x47602d(0x5c9,0x5ea)]=this[_0x47602d(0x5ae,_0x231a9c._0x5b69e5)]['db'](_0x47ddf5),this[_0x47602d(_0x231a9c._0x5005c8,_0x231a9c._0x1c4845)]||(await this[_0x47602d(_0x231a9c._0x1cc1a4,_0x231a9c._0x578584)](this['_atlasDB'])['catch'](_0x525897=>{const _0x30e42d={_0x5288db:0x2af};function _0x1802b1(_0x4d8730,_0x246ad8){return _0x47602d(_0x246ad8,_0x4d8730- -_0x30e42d._0x5288db);}console['error'](_0x1802b1(0x32a,0x333),_0x525897?.[_0x1802b1(_0x2f2d21._0xc8c38e,_0x2f2d21._0x9d6477)]||_0x525897);}),this[_0x47602d(_0x231a9c._0x1c4845,_0x231a9c._0x1c4845)]=!0x0);try{return await this[_0x47602d(0x5da,0x5ea)]['command']({'ping':0x1}),this[_0x47602d(0x5b7,_0x231a9c._0x1c8b83)]=!0x0,this['_lastAtlasError']=null,console[_0x47602d(0x5be,_0x231a9c._0x217c36)](_0x47602d(_0x231a9c._0xa4f7d8,0x5cb)),!0x0;}catch(_0x1e950b){return this[_0x47602d(0x5a1,_0x231a9c._0x573e59)]=!0x1,this['_lastAtlasError']=this[_0x47602d(0x58d,_0x231a9c._0x442c92)](_0x1e950b),console[_0x47602d(_0x231a9c._0xe5a718,0x5c8)](_0x47602d(_0x231a9c._0xf73f6b,_0x231a9c._0x4de6a9),this['_lastAtlasError']),!0x1;}}catch(_0x54c5b2){return this['_atlasDB']=null,this[_0x47602d(0x58d,_0x231a9c._0x573e59)]=!0x1,this['_lastAtlasError']=this[_0x47602d(0x5b6,0x598)](_0x54c5b2),!0x1;}}async[_0x4185c1(-0x193,-0x193)](){const _0x52f596={_0x304e4c:0x5bf,_0x65d7a1:0x599,_0x40e4b9:0x5ab,_0x4576a0:0x5a4};if(!this[_0x128e02(0x5c5,0x5db)]||!this[_0x128e02(0x5c5,0x5a4)])return this['_online']=!0x1,!0x1;function _0x128e02(_0x2bded2,_0xda3c36){return _0x4185c1(_0xda3c36-0x766,_0x2bded2);}try{return await this[_0x128e02(0x5ac,0x5db)][_0x128e02(0x58c,0x58e)]({'ping':0x1}),this[_0x128e02(_0x52f596._0x304e4c,0x599)]=!0x0,this['_lastAtlasError']=null,!0x0;}catch(_0x15d088){this[_0x128e02(0x579,_0x52f596._0x65d7a1)]=!0x1,this[_0x128e02(0x595,0x5b1)]=this[_0x128e02(_0x52f596._0x40e4b9,0x589)](_0x15d088),this[_0x128e02(0x5cc,0x5db)]=null;try{this['_atlasClient']&&await this['_atlasClient']['close']();}catch(_0x29c638){}return this[_0x128e02(0x5a8,_0x52f596._0x4576a0)]=null,!0x1;}}async['closeAll'](){const _0x484b7e={_0x30ca9d:0x12a,_0x4c49ef:0x129,_0x27f404:0x106,_0x1d8409:0xfa,_0xe332e4:0x116,_0x4e317d:0x114,_0x11618a:0xed,_0x3dd545:0xd8,_0x3ebe07:0x135,_0x430cff:0x15d},_0x2f603b={_0x250f49:0x98};try{this[_0x2d6391(-0x12a,-0x113)]&&await this[_0x2d6391(-_0x484b7e._0x30ca9d,-0x115)][_0x2d6391(-_0x484b7e._0x4c49ef,-0x142)]();}catch(_0x1060d5){console[_0x2d6391(-0x115,-_0x484b7e._0x27f404)](_0x2d6391(-_0x484b7e._0x1d8409,-0xf6),_0x1060d5?.[_0x2d6391(-_0x484b7e._0xe332e4,-0x112)]);}function _0x2d6391(_0x3595b8,_0x16473b){return _0x4185c1(_0x3595b8-_0x2f603b._0x250f49,_0x16473b);}await localManager[_0x2d6391(-0x142,-0x147)](),this[_0x2d6391(-0x11c,-_0x484b7e._0x4e317d)]=this['_atlasClient']=this[_0x2d6391(-_0x484b7e._0x11618a,-_0x484b7e._0x3dd545)]=this['_atlasDB']=null,this[_0x2d6391(-_0x484b7e._0x3ebe07,-_0x484b7e._0x430cff)]=!0x1;}[_0x4185c1(-0x1c5,-0x1f4)](){const _0x5eab35={_0x682230:0x100,_0xb2ecd5:0x132};function _0x4ba512(_0x1a10f5,_0x95fba){return _0x4185c1(_0x1a10f5-0x85,_0x95fba);}return{'localConnected':!!this[_0x4ba512(-_0x5eab35._0x682230,-_0x5eab35._0xb2ecd5)],'atlasConnected':!!this[_0x4ba512(-0x106,-0x11a)]&&this['_online'],'online':this[_0x4ba512(-0x148,-0x162)],'lastAtlasError':this['_lastAtlasError']};}get[_0x4185c1(-0x1b1,-0x1a2)](){function _0x998136(_0x460cb6,_0x1515a9){return _0x4185c1(_0x460cb6-0x161,_0x1515a9);}return this[_0x998136(-0x53,-0x2d)];}get['atlasClient'](){return this['_atlasClient'];}get['local'](){const _0x428e8a={_0x118a3f:0x17b},_0x3523f9={_0x23906a:0x2d};function _0x201c24(_0xbf130d,_0x217806){return _0x4185c1(_0x217806-_0x3523f9._0x23906a,_0xbf130d);}return this[_0x201c24(-_0x428e8a._0x118a3f,-0x158)];}get[_0x4185c1(-0x1af,-0x1c2)](){const _0x2f49ad={_0x4a8c59:0x6ad};function _0x833815(_0x5115ee,_0x5ee615){return _0x4185c1(_0x5115ee-_0x2f49ad._0x4a8c59,_0x5ee615);}return this[_0x833815(0x522,0x50d)];}get['online'](){const _0x2f12f7={_0x119ce5:0xdb},_0x374468={_0x88c21:0xfa};function _0x4deebc(_0x2b6293,_0x3deec1){return _0x4185c1(_0x3deec1-_0x374468._0x88c21,_0x2b6293);}return this[_0x4deebc(-_0x2f12f7._0x119ce5,-0xd3)];}set['online'](_0x4fcf8b){const _0x30f309={_0x33b13a:0xdd,_0x1ba708:0xac};function _0x2927fc(_0x874728,_0x1f34c7){return _0x4185c1(_0x1f34c7-0x121,_0x874728);}this[_0x2927fc(-_0x30f309._0x33b13a,-_0x30f309._0x1ba708)]=!!_0x4fcf8b;}get[_0x4185c1(-0x1a8,-0x1b6)](){return this['_lastAtlasError'];}get[_0x4185c1(-0x1e0,-0x1dc)](){const _0x3d05f2={_0x251281:0x4e8},_0x219e27={_0x43fa61:0x68c};function _0x15b751(_0x124631,_0x10882c){return _0x4185c1(_0x124631-_0x219e27._0x43fa61,_0x10882c);}return this[_0x15b751(0x4f5,_0x3d05f2._0x251281)];}async[_0x4185c1(-0x1bd,-0x1d4)](_0x1d00b3){const _0x1eab60={_0x420f06:0x233,_0x444497:0x223,_0x2d2107:0x23e,_0x3c9996:0x21a,_0x5c6763:0x23c,_0x106461:0x21b,_0x119d11:0x1e9,_0x5424cc:0x200,_0x3e88fa:0x221,_0x237472:0x237,_0x153bd9:0x1fa,_0x1607c3:0x1e5,_0x5009f0:0x216,_0x3b4746:0x232,_0xbb04ca:0x24c,_0x1a2906:0x22e,_0x27d69a:0x215,_0x39ed60:0x25a,_0x45c134:0x209,_0x37e355:0x1b5,_0x531c46:0x244,_0x5733dc:0x219,_0xb28cc6:0x1e8,_0x11c826:0x1e5,_0x19094e:0x218,_0x30699d:0x20d,_0x508f57:0x1fb,_0x414da8:0x1fe,_0xd45051:0x216,_0x2149b3:0x236,_0x543d5e:0x209,_0x321bdd:0x1ce,_0x2b3fce:0x204,_0x75af45:0x1f9,_0x117d41:0x218,_0x2ff871:0x1f6,_0xf04479:0x227,_0x25c7eb:0x1f0,_0x371a74:0x217},_0x3407dc={_0xbfe822:0x3c4},_0x18679c={_0x5c240f:0x70,_0xdeb9b2:0x29,_0x2480df:0x3d,_0x5d85f7:0x41,_0x412fb0:0x55},_0x21000f=async(_0x503e73,_0x5a21b1,_0x11fe4c={})=>{function _0x162bb7(_0x4a9c0a,_0xffa77e){return _0x355f(_0xffa77e- -0x1ab,_0x4a9c0a);}try{await _0x1d00b3[_0x162bb7(0x17,0x43)](_0x503e73)[_0x162bb7(_0x18679c._0x5c240f,0x69)](_0x5a21b1,_0x11fe4c);}catch(_0x3f2d05){console['warn'](_0x162bb7(_0x18679c._0xdeb9b2,_0x18679c._0x2480df)+_0x503e73+')\x20warning:',_0x3f2d05?.[_0x162bb7(_0x18679c._0x5d85f7,_0x18679c._0x412fb0)]||_0x3f2d05);}};function _0x41d674(_0x27cf4e,_0x5584f9){return _0x4185c1(_0x5584f9-_0x3407dc._0xbfe822,_0x27cf4e);}await _0x1d00b3['createCollection'](_0x41d674(0x210,_0x1eab60._0x420f06))[_0x41d674(_0x1eab60._0x444497,_0x1eab60._0x2d2107)](()=>{});try{await _0x1d00b3[_0x41d674(_0x1eab60._0x3c9996,0x204)](_0x41d674(0x21d,0x233))['createIndexes']([{'key':{'opId':0x1},'unique':!0x0,'sparse':!0x0,'name':_0x41d674(0x1e8,0x1fc)},{'key':{'synced':0x1,'timestamp':0x1},'name':_0x41d674(0x259,_0x1eab60._0x5c6763)},{'key':{'collection':0x1,'type':0x1,'timestamp':0x1},'name':'idx_track_changed'},{'key':{'collection':0x1,'ownerKey':0x1,'timestamp':0x1},'name':_0x41d674(_0x1eab60._0x5c6763,_0x1eab60._0x106461)},{'key':{'synced':0x1,'ackState':0x1,'retryCount':0x1,'timestamp':0x1},'name':_0x41d674(0x1c6,_0x1eab60._0x119d11)},{'key':{'collection':0x1,'synced':0x1,'ackState':0x1},'name':_0x41d674(_0x1eab60._0x5424cc,_0x1eab60._0x3e88fa)},{'key':{'collection':0x1,'synced':0x1,'ackState':0x1,'_id':0x1},'name':_0x41d674(0x240,_0x1eab60._0x237472)}]);}catch(_0x329f05){console[_0x41d674(_0x1eab60._0x153bd9,0x217)]('[MongoFire]\x20createIndexes(_mf_changetrack/local):',_0x329f05?.[_0x41d674(_0x1eab60._0x1607c3,_0x1eab60._0x5009f0)]||_0x329f05);}await _0x21000f('_mf_changetrack',{'syncedAt':0x1},{'expireAfterSeconds':0x93a80,'name':'ttl_synced_ops','background':!0x0}),await this[_0x41d674(0x1c2,0x1ef)](_0x1d00b3),await _0x1d00b3[_0x41d674(_0x1eab60._0x3b4746,0x209)](_0x41d674(_0x1eab60._0xbb04ca,_0x1eab60._0x1a2906))[_0x41d674(_0x1eab60._0x27d69a,_0x1eab60._0x2d2107)](()=>{}),await _0x21000f(_0x41d674(_0x1eab60._0x39ed60,0x22e),{'deviceId':0x1},{'unique':!0x0,'name':'idx_device_id'}),await _0x1d00b3[_0x41d674(0x207,_0x1eab60._0x45c134)](_0x41d674(_0x1eab60._0x37e355,0x1e5))[_0x41d674(_0x1eab60._0x531c46,_0x1eab60._0x2d2107)](()=>{});try{await _0x1d00b3[_0x41d674(_0x1eab60._0x5733dc,0x204)](_0x41d674(_0x1eab60._0xb28cc6,_0x1eab60._0x11c826))[_0x41d674(0x20b,_0x1eab60._0x19094e)]([{'key':{'collection':0x1,'docId':0x1},'unique':!0x0,'name':_0x41d674(0x204,_0x1eab60._0x30699d)},{'key':{'collection':0x1,'updatedByOpId':0x1},'sparse':!0x0,'name':_0x41d674(0x1f1,0x208)}]);}catch(_0x30d721){console['warn'](_0x41d674(_0x1eab60._0x5009f0,_0x1eab60._0x508f57),_0x30d721?.[_0x41d674(_0x1eab60._0x414da8,_0x1eab60._0xd45051)]||_0x30d721);}await _0x1d00b3[_0x41d674(_0x1eab60._0x2149b3,_0x1eab60._0x543d5e)](_0x41d674(_0x1eab60._0x321bdd,0x1f9))[_0x41d674(_0x1eab60._0x237472,0x23e)](()=>{});try{await _0x1d00b3[_0x41d674(0x1e8,_0x1eab60._0x2b3fce)](_0x41d674(0x1d2,_0x1eab60._0x75af45))[_0x41d674(0x227,_0x1eab60._0x117d41)]([{'key':{'ownerKey':0x1,'collection':0x1,'kind':0x1},'name':_0x41d674(_0x1eab60._0x2ff871,_0x1eab60._0xf04479)}]);}catch(_0x3a8a47){console[_0x41d674(_0x1eab60._0x25c7eb,_0x1eab60._0x371a74)](_0x41d674(0x1eb,0x1e2),_0x3a8a47?.[_0x41d674(_0x1eab60._0x75af45,0x216)]||_0x3a8a47);}}async[_0x4185c1(-0x1d3,-0x1f6)](_0x768661){const _0x4fa8ea={_0x5cb099:0x290,_0x44a0b7:0x2d9,_0x59c627:0x28b,_0x52277a:0x2ba,_0x596172:0x2c3,_0x356b41:0x2c2,_0x2bd3e2:0x2a8,_0x1b228e:0x27e,_0x512d80:0x2bb,_0x25a025:0x2c3,_0x29f8e0:0x2b1,_0x7992c9:0x2a9,_0x1eb69f:0x2c5,_0x1fca8e:0x29c,_0x5473dd:0x265,_0x5872e5:0x2d4,_0x53a156:0x26c,_0x31e045:0x29d,_0x3e0a9c:0x28f,_0x5be61e:0x293,_0x1d5f2f:0x29e},_0x579c6e={_0x515674:0x44b};await _0x768661[_0x395a21(_0x4fa8ea._0x5cb099,0x2bd)]('_mf_changetrack')[_0x395a21(0x2c5,_0x4fa8ea._0x44a0b7)](()=>{});try{await _0x768661[_0x395a21(_0x4fa8ea._0x59c627,0x2ac)](_0x395a21(_0x4fa8ea._0x52277a,0x289))[_0x395a21(0x29f,0x2c4)]([{'key':{'opId':0x1},'unique':!0x0,'sparse':!0x0,'name':_0x395a21(0x283,0x253)},{'key':{'synced':0x1,'timestamp':0x1},'name':_0x395a21(_0x4fa8ea._0x596172,_0x4fa8ea._0x356b41)},{'key':{'collection':0x1,'type':0x1,'timestamp':0x1},'name':_0x395a21(0x26a,0x283)},{'key':{'collection':0x1,'ownerKey':0x1,'timestamp':0x1},'name':_0x395a21(0x2a2,0x29b)},{'key':{'synced':0x1,'ackState':0x1,'retryCount':0x1,'timestamp':0x1},'name':'idx_track_retry'},{'key':{'collection':0x1,'ownerKey':0x1,'applyStatus':0x1,'timestamp':0x1},'name':_0x395a21(0x27d,0x27b)},{'key':{'collection':0x1,'synced':0x1,'ackState':0x1},'name':_0x395a21(_0x4fa8ea._0x2bd3e2,_0x4fa8ea._0x1b228e)}]);}catch(_0x172487){console['warn'](_0x395a21(_0x4fa8ea._0x512d80,_0x4fa8ea._0x25a025),_0x172487?.[_0x395a21(0x29d,0x2bc)]||_0x172487);}function _0x395a21(_0x4692aa,_0x2b7c75){return _0x4185c1(_0x4692aa-_0x579c6e._0x515674,_0x2b7c75);}await _0x768661['collection'](_0x395a21(_0x4fa8ea._0x52277a,0x2d5))[_0x395a21(_0x4fa8ea._0x29f8e0,_0x4fa8ea._0x7992c9)]({'syncedAt':0x1},{'expireAfterSeconds':0x93a80,'name':'ttl_synced_ops','background':!0x0})[_0x395a21(_0x4fa8ea._0x1eb69f,0x2b7)](()=>{}),await _0x768661['collection'](_0x395a21(_0x4fa8ea._0x52277a,0x2ea))[_0x395a21(0x2b1,_0x4fa8ea._0x1fca8e)]({'remoteAckAt':0x1,'syncedAt':0x1},{'expireAfterSeconds':0x93a80,'name':_0x395a21(_0x4fa8ea._0x5473dd,0x288),'partialFilterExpression':{'syncedAt':{'$exists':!0x1}},'background':!0x0})[_0x395a21(0x2c5,_0x4fa8ea._0x5872e5)](()=>{}),await _0x768661['createCollection'](_0x395a21(_0x4fa8ea._0x53a156,0x24e))[_0x395a21(0x2c5,0x2db)](()=>{});try{await _0x768661[_0x395a21(0x28b,0x279)](_0x395a21(0x26c,0x29a))['createIndexes']([{'key':{'collection':0x1,'docId':0x1},'unique':!0x0,'name':_0x395a21(0x294,_0x4fa8ea._0x31e045)},{'key':{'collection':0x1,'updatedByOpId':0x1},'sparse':!0x0,'name':_0x395a21(_0x4fa8ea._0x3e0a9c,_0x4fa8ea._0x5be61e)}]);}catch(_0x2d519f){console[_0x395a21(_0x4fa8ea._0x1d5f2f,0x2bb)]('[MongoFire]\x20createIndexes(_mf_docmeta/atlas):',_0x2d519f?.['message']||_0x2d519f);}}async[_0x4185c1(-0x1d5,-0x1fe)](_0x1d6bbf){const _0x1893b7={_0x3b0b2f:0x429,_0x216ec7:0x407,_0x3a3824:0x436,_0x70b4dc:0x434,_0x1bc502:0x421,_0x232f5e:0x3e2,_0x468db8:0x444,_0x5a9718:0x407,_0x3dfadc:0x419,_0x571431:0x453,_0x179ff6:0x3ed,_0x88653b:0x434,_0x529053:0x3e9,_0xde32a2:0x3d6,_0xd2c880:0x3af,_0x3faaa2:0x430,_0x45f4d4:0x407,_0x56f953:0x431,_0xc4823f:0x440},_0x5a61e9={_0x4807c1:0x5ba};function _0x3d1255(_0x385c55,_0x57cd60){return _0x4185c1(_0x385c55-_0x5a61e9._0x4807c1,_0x57cd60);}const _0x50b2f7=_0x1d6bbf[_0x3d1255(0x3fa,0x3e5)](_0x3d1255(_0x1893b7._0x3b0b2f,0x422));await _0x50b2f7[_0x3d1255(_0x1893b7._0x216ec7,0x3ef)]({'type':{'$exists':!0x1},'op':{'$exists':!0x0}},[{'$set':{'type':_0x3d1255(0x42e,_0x1893b7._0x3a3824)}}])[_0x3d1255(_0x1893b7._0x70b4dc,_0x1893b7._0x1bc502)](()=>{}),await _0x50b2f7[_0x3d1255(0x407,_0x1893b7._0x232f5e)]({'payload':{'$exists':!0x1},'doc':{'$exists':!0x0}},[{'$set':{'payload':'$doc'}}])[_0x3d1255(0x434,0x427)](()=>{}),await _0x50b2f7['updateMany']({'ownerKey':{'$exists':!0x1},'ownerId':{'$exists':!0x0}},[{'$set':{'ownerKey':_0x3d1255(0x436,_0x1893b7._0x468db8)}}])[_0x3d1255(_0x1893b7._0x70b4dc,0x440)](()=>{}),await _0x50b2f7[_0x3d1255(_0x1893b7._0x5a9718,0x3de)]({'timestamp':{'$exists':!0x1}},[{'$set':{'timestamp':{'$ifNull':['$changedAt',{'$ifNull':[_0x3d1255(_0x1893b7._0x3dfadc,0x44b),'$createdAt']}]}}}])[_0x3d1255(0x434,_0x1893b7._0x571431)](()=>{}),await _0x50b2f7[_0x3d1255(0x407,_0x1893b7._0x179ff6)]({'opId':{'$exists':!0x1}},[{'$set':{'opId':{'$concat':[_0x3d1255(0x3e6,0x3cb),{'$toString':_0x3d1255(0x422,0x3fc)}]}}}])[_0x3d1255(_0x1893b7._0x88653b,0x421)](()=>{}),await _0x50b2f7[_0x3d1255(_0x1893b7._0x216ec7,_0x1893b7._0x529053)]({'ackState':{'$exists':!0x1}},[{'$set':{'ackState':{'$cond':[{'$eq':[_0x3d1255(_0x1893b7._0xde32a2,_0x1893b7._0xd2c880),!0x0]},_0x3d1255(_0x1893b7._0x3faaa2,0x3ff),_0x3d1255(0x41c,0x41c)]}}}])['catch'](()=>{}),await _0x50b2f7[_0x3d1255(_0x1893b7._0x5a9718,0x42b)]({'retryCount':{'$exists':!0x1}},{'$set':{'retryCount':0x0}})['catch'](()=>{});try{const _0x23e56e=await _0x50b2f7[_0x3d1255(_0x1893b7._0x45f4d4,0x3fc)]({'$or':[{'op':{'$exists':!0x0}},{'doc':{'$exists':!0x0}},{'ownerId':{'$exists':!0x0}},{'changedAt':{'$exists':!0x0}}]},{'$unset':{'op':'','doc':'','ownerId':'','changedAt':''}});_0x23e56e['modifiedCount']>0x0&&console['log']('[MongoFire]\x20Dedup\x20migration:\x20cleaned\x20'+_0x23e56e['modifiedCount']+_0x3d1255(_0x1893b7._0x56f953,_0x1893b7._0xc4823f));}catch(_0x4fe3f5){console[_0x3d1255(0x40d,0x3df)]('[MongoFire]\x20Dedup\x20migration\x20(non-fatal):',_0x4fe3f5?.[_0x3d1255(0x40c,0x3eb)]||_0x4fe3f5);}}[_0x4185c1(-0x1dd,-0x206)](_0x58cfb2){const _0x3cbd3a={_0x195fd2:0x177,_0x312f66:0x177,_0x2e2fe6:0x166,_0x2c36db:0x175,_0x109f2e:0x156,_0xd79f41:0x180};function _0x4a9433(_0x17ccf5,_0x3b6fba){return _0x4185c1(_0x17ccf5-0x325,_0x3b6fba);}return _0x58cfb2?_0x58cfb2[_0x4a9433(_0x3cbd3a._0x195fd2,0x17e)]?_0x58cfb2[_0x4a9433(_0x3cbd3a._0x312f66,_0x3cbd3a._0x2e2fe6)]+(_0x58cfb2[_0x4a9433(0x156,0x150)]?_0x4a9433(_0x3cbd3a._0x2c36db,_0x3cbd3a._0x109f2e)+(_0x58cfb2[_0x4a9433(0x156,0x183)]['split']('\x0a')[0x1]||''):''):String(_0x58cfb2):_0x4a9433(_0x3cbd3a._0xd79f41,0x194);}}const _singleton=new Connection();module[_0x4185c1(-0x1d2,-0x1c1)]=_singleton,module[_0x4185c1(-0x1d2,-0x1d7)][_0x4185c1(-0x1d6,-0x1b9)]=Connection;
|