From f6181b14f406b3a5d6d80b4b5c194ae37363c69d Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Thu, 25 Jul 2024 23:07:50 -0400 Subject: [PATCH] dev: move driver arg types to a registry --- src/backend/src/services/drivers/DriverService.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/src/services/drivers/DriverService.js b/src/backend/src/services/drivers/DriverService.js index f2f15eac..510b017f 100644 --- a/src/backend/src/services/drivers/DriverService.js +++ b/src/backend/src/services/drivers/DriverService.js @@ -43,18 +43,26 @@ class DriverService extends BaseService { const svc_registry = this.services.get('registry'); svc_registry.register_collection('interfaces'); svc_registry.register_collection('drivers'); + svc_registry.register_collection('types'); } async ['__on_registry.entries'] () { const services = this.services; const svc_registry = services.get('registry'); const col_interfaces = svc_registry.get('interfaces'); const col_drivers = svc_registry.get('drivers'); + const col_types = svc_registry.get('types'); { const default_interfaces = require('./interfaces'); for ( const k in default_interfaces ) { col_interfaces.set(k, default_interfaces[k]); } } + { + const types = this.modules.types; + for ( const k in types ) { + col_types.set(k, types[k]); + } + } await services.emit('driver.register.interfaces', { col_interfaces }); await services.emit('driver.register.drivers', @@ -387,6 +395,7 @@ class DriverService extends BaseService { async _process_args (interface_name, method_name, args) { const svc_registry = this.services.get('registry'); const c_interfaces = svc_registry.get('interfaces'); + const c_types = svc_registry.get('types'); // Note: 'interface' is a strict mode reserved word. const interface_ = c_interfaces.get(interface_name); @@ -399,9 +408,10 @@ class DriverService extends BaseService { if ( ! method ) { throw APIError.create('method_not_found', null, { interface_name, method_name }); } + for ( const [arg_name, arg_descriptor] of Object.entries(method.parameters) ) { const arg_value = args[arg_name]; - const arg_behaviour = this.modules.types[arg_descriptor.type]; + const arg_behaviour = c_types.get(arg_descriptor.type); // TODO: eventually put this in arg behaviour base class. // There's a particular way I want to do this that involves