+ static loadByNpmName (npmName: string): Bluebird<MPlugin> {
+ const name = this.normalizePluginName(npmName)
+ const type = this.getTypeFromNpmName(npmName)
+
+ const query = {
+ where: {
+ name,
+ type
+ }
+ }
+
+ return PluginModel.findOne(query)
+ }
+
+ static getSetting (pluginName: string, pluginType: PluginType, settingName: string, registeredSettings: RegisterServerSettingOptions[]) {
+ const query = {
+ attributes: [ 'settings' ],
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ return PluginModel.findOne(query)
+ .then(p => {
+ if (!p || !p.settings || p.settings === undefined) {
+ const registered = registeredSettings.find(s => s.name === settingName)
+ if (!registered || registered.default === undefined) return undefined
+
+ return registered.default
+ }
+
+ return p.settings[settingName]
+ })
+ }
+
+ static getSettings (
+ pluginName: string,
+ pluginType: PluginType,
+ settingNames: string[],
+ registeredSettings: RegisterServerSettingOptions[]
+ ) {
+ const query = {
+ attributes: [ 'settings' ],
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ return PluginModel.findOne(query)
+ .then(p => {
+ const result: { [settingName: string ]: string | boolean } = {}
+
+ for (const name of settingNames) {
+ if (!p || !p.settings || p.settings[name] === undefined) {
+ const registered = registeredSettings.find(s => s.name === name)
+
+ if (registered?.default !== undefined) {
+ result[name] = registered.default
+ }
+ } else {
+ result[name] = p.settings[name]
+ }
+ }
+
+ return result
+ })
+ }
+
+ static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: string) {
+ const query = {
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ const toSave = {
+ [`settings.${settingName}`]: settingValue
+ }
+
+ return PluginModel.update(toSave, query)
+ .then(() => undefined)
+ }
+
+ static getData (pluginName: string, pluginType: PluginType, key: string) {