From 32ebcb2a809e13da7750c0550775b09ac4ba6835 Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Tue, 23 Jan 2024 14:47:31 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20More=20settings=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/class/conduit.js | 6 ++--- lib/core/alchemy.js | 4 ---- lib/core/setting.js | 43 +++++++++++++++++++++++++++++++++- lib/scripts/create_settings.js | 4 ++-- lib/stages/20-settings.js | 20 +++++++++++++--- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/lib/class/conduit.js b/lib/class/conduit.js index a3cd0ae4..4422378b 100644 --- a/lib/class/conduit.js +++ b/lib/class/conduit.js @@ -2543,7 +2543,7 @@ Conduit.setMethod(function setRouteParameters(data) { * * @author Jelle De Loecker * @since 0.2.0 - * @version 1.3.18 + * @version 1.4.0 * * @param {string} name * @param {Mixed} value @@ -2582,8 +2582,8 @@ Conduit.setMethod(function cookie(name, value, options) { this.new_cookies[name] = value; // If there is no domain set, see if it is required - if ((options.domain === true || options.domain == null) && alchemy.settings.cookies.domain && this.url) { - let wanted_domain = alchemy.settings.cookies.domain, + if ((options.domain === true || options.domain == null) && alchemy.settings.frontend.cookies.domain && this.url) { + let wanted_domain = alchemy.settings.frontend.cookies.domain, actual_domain = this.url.hostname; if (wanted_domain != actual_domain) { diff --git a/lib/core/alchemy.js b/lib/core/alchemy.js index 7b098a23..8940d14c 100644 --- a/lib/core/alchemy.js +++ b/lib/core/alchemy.js @@ -757,10 +757,6 @@ Alchemy.setMethod(function loadSettings() { let port = this.getSetting('network.port'); - // Create the settings object - this.settings = system.toObject(); - - if (port > 49151) { port_error = 'Could not use port number ' + String(port).bold.red + ' because '; diff --git a/lib/core/setting.js b/lib/core/setting.js index f0f82c38..60cb117e 100644 --- a/lib/core/setting.js +++ b/lib/core/setting.js @@ -164,6 +164,10 @@ Definition.enforceProperty(function schema(new_value, old_value) { type = 'string'; } + if (type == 'function') { + type = 'string'; + } + new_value.addField('value', type, { description: this.description, allowed_values: this.allowed_values, @@ -917,15 +921,33 @@ GroupValue.setProperty(function is_group() { GroupValue.setMethod(function toObject() { let result = {}, + entry, key; for (key in this[VALUE]) { - result[key] = this[VALUE][key].toObject(); + entry = this[VALUE][key]; + + if (!entry) { + continue; + } + + result[key] = entry.toObject(); } return result; }); +/** + * Remove an entry + * + * @author Jelle De Loecker + * @since 1.4.0 + * @version 1.4.0 + */ +GroupValue.setMethod(function remove(name) { + this[VALUE][name] = undefined; +}); + /** * Get the proxy representation of this group value. * @@ -970,6 +992,17 @@ GroupValue.setMethod(function setValueSilently(value) { this.definition.setValueSilently(this, value); }); +/** + * Inject the given group value + * + * @author Jelle De Loecker + * @since 1.4.0 + * @version 1.4.0 + */ +GroupValue.setMethod(function injectSubGroupValue(name, value) { + this[VALUE][name] = value; +}); + /** * Get all the setting values with executable actions in order. * @@ -1011,6 +1044,10 @@ GroupValue.setMethod(function getFlattenedValues() { for (key in this[VALUE]) { entry = this[VALUE][key]; + if (!entry) { + continue; + } + if (entry.is_group) { result.push(...entry.getFlattenedValues()); } else { @@ -1218,6 +1255,10 @@ SettingValue.setMethod(function setDefaultValue(value) { */ SettingValue.setMethod(function setValueSilently(value) { + if (value instanceof Value) { + value = value[VALUE]; + } + // Even though the default value and this new value might be the same, // it is no longer considered to be the "default" value! this.has_default_value = false; diff --git a/lib/scripts/create_settings.js b/lib/scripts/create_settings.js index d74fd6bb..a9df546a 100644 --- a/lib/scripts/create_settings.js +++ b/lib/scripts/create_settings.js @@ -20,8 +20,8 @@ system.addSetting('name', { description : 'The package name', }); -const extensions = system.createGroup('extensions'); -SettingNs.EXTENSIONS = extensions; +const plugins = system.createGroup('plugins'); +SettingNs.PLUGINS = plugins; const network = system.createGroup('network'); diff --git a/lib/stages/20-settings.js b/lib/stages/20-settings.js index c2bb1686..43bb6f2a 100644 --- a/lib/stages/20-settings.js +++ b/lib/stages/20-settings.js @@ -38,10 +38,9 @@ const load = settings.createStage('load', async () => { } }); - /** - * "datasource.connect.load_settings" - * Load any possible settings in the database + * "settings.perform_actions" + * Do all the setting-associated actions. * * @author Jelle De Loecker * @since 1.4.0 @@ -51,4 +50,19 @@ const load = settings.createStage('load', async () => { */ const perform_actions = settings.createStage('perform_actions', async () => { await alchemy.system_settings.performAllActions(); +}); + +/** + * "settings.to_object" + * Convert the `alchemy.settings` property to a simple object + * + * @author Jelle De Loecker + * @since 1.4.0 + * @version 1.4.0 + * + * @type {Alchemy.Stages.Stage} + */ +const to_object = settings.createStage('to_object', async () => { + // Create the settings object + alchemy.settings = alchemy.system_settings.toObject(); }); \ No newline at end of file