@trap_stevo/filetide
Version:
Revolutionizing real-time file transfer with seamless, instant communication across any device. Deliver files instantly, regardless of platform, and experience unparalleled speed and control in managing transfers. Elevate your file-sharing capabilities wi
69 lines (68 loc) • 1.61 kB
JavaScript
const MetricTide = require("@trap_stevo/metrictide");
class TidalyticsInstanceManager {
constructor() {
this.instances = new Map();
}
createInstance(name = "default", config = {}) {
if (this.instances.has(name)) {
return this.instances.get(name);
}
const defaultConfig = {
dbPath: "./filetide_core/.tidalytics",
persistence: {
alwaysOn: true
},
loadMetricsOnLaunch: false,
onTrack: record => {
console.log("[Tidalytics] Tracked:", record.name, record.value);
}
};
const mergedConfig = {
...defaultConfig,
...config,
persistence: {
...defaultConfig.persistence,
...(config.persistence || {})
}
};
const instance = new MetricTide(mergedConfig);
this.instances.set(name, instance);
return instance;
}
getInstance(name = "default", configurations = {}) {
if (!this.instances.has(name)) {
if (configurations) {
return this.createInstance(name, configurations);
}
return null;
}
return this.instances.get(name);
}
containsInstance(name = "default") {
return this.instances.has(name);
}
clearInstance(name = "default") {
this.instances.delete(name);
}
listInstances() {
return Array.from(this.instances.entries());
}
clearAll() {
this.instances.clear();
}
}
;
let singleton = null;
const Tidalytics = {
get() {
if (!singleton) {
singleton = new TidalyticsInstanceManager();
}
return singleton;
}
};
module.exports = {
TidalyticsInstanceManager,
Tidalytics
};
;