UNPKG

@azurapi/azurapi

Version:

Open Source Azur Lane Local Database

88 lines 3.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AzurAPI = exports.instance = void 0; const events_1 = require("events"); const CacheUpdater_1 = __importDefault(require("./CacheUpdater")); const api_ship_1 = require("./api/api_ship"); const api_equipment_1 = require("./api/api_equipment"); const api_barrage_1 = require("./api/api_barrage"); const api_chapter_1 = require("./api/api_chapter"); const api_voiceline_1 = require("./api/api_voiceline"); /** * The main AzurAPI class */ class AzurAPI extends events_1.EventEmitter { /** * Cache client * @param options options for the cache */ constructor(options) { super(); this.ships = new api_ship_1.Ships(this); this.equipments = new api_equipment_1.Equipments(this); this.chapters = new api_chapter_1.Chapters(this); this.voicelines = new api_voiceline_1.Voicelines(this); this.barrages = new api_barrage_1.Barrages(this); this.apis = { ships: this.ships, equipments: this.equipments, chapters: this.chapters, voicelines: this.voicelines, barrages: this.barrages }; //Make sure people are using Node <=14 if (parseFloat(process.version.replace('v', '')) <= 14) throw new Error('AzurAPI requires Node v14 or above, if you would like to use an older Node version, please use any version of this package below v0.2.13 (Not Recommended)'); this.options = options ? options : { source: 'local', autoupdate: true, rate: 3600000 }; this.source = this.options.source ? this.options.source : 'local'; this.autoupdate = true; if (typeof this.options.autoupdate === 'boolean') { this.autoupdate = this.options.autoupdate; } this.rate = this.options.rate ? this.options.rate : 3600000; this.apis = { ships: this.ships, equipments: this.equipments, chapters: this.chapters, voicelines: this.voicelines, barrages: this.barrages }; this.updater = new CacheUpdater_1.default(this); this.updater.init(); if (this.autoupdate && this.source === 'local') this.updater.start(); this.emit('ready'); exports.instance = this; } /** * Set data in cache * @param type A type of data (ship, equipment, voiceline, chapter, or barrage) * @param raw Raw data in array */ set(type, raw) { if (!raw) return; let api = this.apis[type]; if (api) api.setData(raw); return api; } /** * Bodge until we can rewrite * query string matches a ship's name. */ queryIsShipName(query) { return this.ships.name(query).length !== 0; } /** * Another bodge... */ getShipIdByName(name) { return this.ships.getShipIdByName(name); } } exports.AzurAPI = AzurAPI; //# sourceMappingURL=Client.js.map