summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/managers/DataManager.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/discord.js/src/managers/DataManager.js')
-rw-r--r--node_modules/discord.js/src/managers/DataManager.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/managers/DataManager.js b/node_modules/discord.js/src/managers/DataManager.js
new file mode 100644
index 0000000..383844e
--- /dev/null
+++ b/node_modules/discord.js/src/managers/DataManager.js
@@ -0,0 +1,61 @@
+'use strict';
+
+const BaseManager = require('./BaseManager');
+const { DiscordjsError, ErrorCodes } = require('../errors');
+
+/**
+ * Manages the API methods of a data model along with a collection of instances.
+ * @extends {BaseManager}
+ * @abstract
+ */
+class DataManager extends BaseManager {
+ constructor(client, holds) {
+ super(client);
+
+ /**
+ * The data structure belonging to this manager.
+ * @name DataManager#holds
+ * @type {Function}
+ * @private
+ * @readonly
+ */
+ Object.defineProperty(this, 'holds', { value: holds });
+ }
+
+ /**
+ * The cache of items for this manager.
+ * @type {Collection}
+ * @abstract
+ */
+ get cache() {
+ throw new DiscordjsError(ErrorCodes.NotImplemented, 'get cache', this.constructor.name);
+ }
+
+ /**
+ * Resolves a data entry to a data Object.
+ * @param {string|Object} idOrInstance The id or instance of something in this Manager
+ * @returns {?Object} An instance from this Manager
+ */
+ resolve(idOrInstance) {
+ if (idOrInstance instanceof this.holds) return idOrInstance;
+ if (typeof idOrInstance === 'string') return this.cache.get(idOrInstance) ?? null;
+ return null;
+ }
+
+ /**
+ * Resolves a data entry to an instance id.
+ * @param {string|Object} idOrInstance The id or instance of something in this Manager
+ * @returns {?Snowflake}
+ */
+ resolveId(idOrInstance) {
+ if (idOrInstance instanceof this.holds) return idOrInstance.id;
+ if (typeof idOrInstance === 'string') return idOrInstance;
+ return null;
+ }
+
+ valueOf() {
+ return this.cache;
+ }
+}
+
+module.exports = DataManager;