From b245ee0d1d16f45c44ea75c08ad93682ed2e0c8b Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Thu, 25 Jul 2024 15:15:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Apply=20changes=20from?= =?UTF-8?q?=20external=20libraries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app/helper/alchemy_helper.js | 2 +- lib/app/helper/router_helper.js | 27 ++++++++++++------- .../schema_operational_context.js | 4 +-- lib/app/helper_model/document.js | 9 +++---- lib/class/router.js | 4 +-- lib/class/schema_client.js | 1 + lib/core/middleware.js | 4 +++ lib/stages/50-routes.js | 2 ++ 8 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lib/app/helper/alchemy_helper.js b/lib/app/helper/alchemy_helper.js index fe85edd2..7859767d 100644 --- a/lib/app/helper/alchemy_helper.js +++ b/lib/app/helper/alchemy_helper.js @@ -328,7 +328,7 @@ Alchemy.setMethod(function segment(options, data) { route; if (Blast.isNode) { - conduit = that.view.server_var('conduit'); + conduit = that.view.serverVar('conduit'); if (!conduit) { return next(null, ''); diff --git a/lib/app/helper/router_helper.js b/lib/app/helper/router_helper.js index 60f6aab4..68d3ab88 100644 --- a/lib/app/helper/router_helper.js +++ b/lib/app/helper/router_helper.js @@ -51,13 +51,19 @@ Router.setProperty(function current_url() { * * @author Jelle De Loecker * @since 1.3.10 - * @version 1.3.10 + * @version 1.4.0 * * @type {Object} */ Router.setProperty(function current_route() { - let route_name = this.view_render?.variables?.__route; + const variables = this.view_render?.variables; + + if (!variables) { + return; + } + + let route_name = variables.get('__route'); if (!route_name) { return; @@ -157,7 +163,7 @@ Router.setMethod(function applyDirective(element, name, options) { let variables = element[Hawkejs.VARIABLES]; if (variables) { - val = variables[key]; + val = variables.get(key); } } @@ -215,7 +221,7 @@ Router.setMethod(function applyDirective(element, name, options) { element.setAttribute('hreflang', url._chosen_prefix); } - if (config && this.renderer.variables.__route) { + if (config && this.renderer.variables.get('__route')) { let route = this.current_route; if (route && route.section != config.section) { @@ -792,20 +798,21 @@ Router.setMethod(function getAnchor(name, parameters, options) { * * @author Jelle De Loecker * @since 1.2.5 - * @version 1.2.5 + * @version 1.4.0 * * @return {Object} */ Router.setMethod(function getRouteVariables() { + const variables = this.view_render?.variables; + let params, - route, + route = variables?.get?.('__route'), url; - if (this.view_render?.variables?.__route) { - route = this.view_render.variables.__route; - params = this.view_render.variables.__urlparams; - url = this.view_render.variables.__url; + if (route) { + params = variables.get('__urlparams'); + url = variables.get('__url'); } else if (Blast.isBrowser) { route = alchemy.current_route; params = alchemy.current_url_params; diff --git a/lib/app/helper_datasource/schema_operational_context.js b/lib/app/helper_datasource/schema_operational_context.js index e7cf6159..d8a77133 100644 --- a/lib/app/helper_datasource/schema_operational_context.js +++ b/lib/app/helper_datasource/schema_operational_context.js @@ -16,7 +16,7 @@ const SchemaContext = Function.inherits('Alchemy.OperationalContext.DatasourceOp * @since 1.4.0 * @version 1.4.0 * - * @param {Object} string + * @param {string} sub_schema_path */ SchemaContext.setContextProperty('sub_schema_path'); @@ -49,7 +49,7 @@ SchemaContext.setContextProperty('value_property_name'); * @since 1.4.0 * @version 1.4.0 * - * @param {string} value_property_name + * @param {string} local_value */ SchemaContext.setContextProperty('local_value'); diff --git a/lib/app/helper_model/document.js b/lib/app/helper_model/document.js index c96a4507..a0180514 100644 --- a/lib/app/helper_model/document.js +++ b/lib/app/helper_model/document.js @@ -297,14 +297,14 @@ Document.setStatic(function getDocumentClass(model_param) { let model = Blast.Classes.Alchemy.Client.Model.Model.getClass(model_name); if (model && model.super) { - parent = model.super.name; + parent = model.super.model_name; } } else if (Blast.isNode) { config = alchemy.getModel(model_name, false); if (config && config.super) { config = { - parent : config.super.name + parent : config.super.model_name }; } } @@ -317,9 +317,8 @@ Document.setStatic(function getDocumentClass(model_param) { if (parent && parent != 'Model') { // Make sure the parent class exists - getDocumentClass(parent); - - parent_path += '.' + parent; + let parent_constructor = getDocumentClass(parent); + parent_path = parent_constructor.namespace + '.' + parent_constructor.name; } DocClass = Function.inherits(parent_path, target_ns, doc_constructor); diff --git a/lib/class/router.js b/lib/class/router.js index 55af55c5..913a846a 100644 --- a/lib/class/router.js +++ b/lib/class/router.js @@ -701,7 +701,7 @@ RouterClass.setMethod(function use(_paths, _fnc, _options) { * * @author Jelle De Loecker * @since 1.1.0 - * @version 1.3.0 + * @version 1.4.0 * * @param {string} module_name The name of the dependency * @param {Object} options The options or single string @@ -744,7 +744,7 @@ RouterClass.setMethod(function serveDependencyFile(module_name, options) { // Cache this file so earlier middleware can handle this from now on alchemy.getCache('files.assets').set(req.url, {path: options.path}); - req.conduit.serveFile(options.path); + req.conduit.serveFile(options.path, options?.serve_options); }); }); diff --git a/lib/class/schema_client.js b/lib/class/schema_client.js index 491e6f2e..e94c82e1 100644 --- a/lib/class/schema_client.js +++ b/lib/class/schema_client.js @@ -1111,6 +1111,7 @@ Schema.setMethod(function addIndex(_field, _options) { // Set the default options options = Object.assign({}, this.indexOptions, options); + // @TODO: Set the `this.indexes` properly, even when a name is given const setIndexName = () => { if (options.name) { diff --git a/lib/core/middleware.js b/lib/core/middleware.js index ee4a26ce..babefead 100644 --- a/lib/core/middleware.js +++ b/lib/core/middleware.js @@ -537,6 +537,10 @@ Alchemy.setMethod(function minifyScript(path, options, callback) { mangle: { keep_fnames : true, keep_classnames : true, + + // We have to prevent `Blast` variable names from being + // mangled, or our replacement trickery will break things + reserved : ['Blast'], }, output: { // Do not wrap functions that are arguments in parenthesis diff --git a/lib/stages/50-routes.js b/lib/stages/50-routes.js index 1d93d0dc..7e040e15 100644 --- a/lib/stages/50-routes.js +++ b/lib/stages/50-routes.js @@ -38,6 +38,7 @@ const hawkejs = routes.createStage('hawkejs', () => { create_source_map : alchemy.getSetting('debugging.create_source_map'), enable_coverage : !!global.__coverage__, debug : alchemy.getSetting('debugging.debug'), + environment : alchemy.environment, }).done(gotClientFile); function gotClientFile(err, path) { @@ -81,6 +82,7 @@ const hawkejs = routes.createStage('hawkejs', () => { ua : req.conduit.headers.useragent, create_source_map : alchemy.getSetting('debugging.create_source_map'), debug : alchemy.getSetting('debugging.debug'), + environment : alchemy.environment, }).done(gotClientFile); } });