diff --git a/src/backend/src/modules/external-extras/ExternalExtrasModule.js b/src/backend/src/modules/external-extras/ExternalExtrasModule.js index 6e837ca64..00d6fea62 100644 --- a/src/backend/src/modules/external-extras/ExternalExtrasModule.js +++ b/src/backend/src/modules/external-extras/ExternalExtrasModule.js @@ -5,9 +5,9 @@ class ExternalExtrasModule extends AdvancedBase { async install (context) { const services = context.get('services'); - if ( !! config?.services?.['ip-geo'] ) { + if ( !! config?.services?.ipgeo ) { const { IPGeoService } = require('./IPGeoService'); - services.registerService('ip-geo', IPGeoService); + services.registerService('ipgeo', IPGeoService); } } } diff --git a/src/backend/src/modules/external-extras/IPGeoService.js b/src/backend/src/modules/external-extras/IPGeoService.js index fd84d592b..024528a60 100644 --- a/src/backend/src/modules/external-extras/IPGeoService.js +++ b/src/backend/src/modules/external-extras/IPGeoService.js @@ -6,7 +6,7 @@ class IPGeoService extends BaseService { const svc_registry = this.services.get('registry'); const col_interfaces = svc_registry.get('interfaces'); - col_interfaces.set('ip-geo', { + col_interfaces.set('ipgeo', { description: 'IP Geolocation', methods: { ipgeo: { @@ -25,7 +25,7 @@ class IPGeoService extends BaseService { } static IMPLEMENTS = { - ['ip-geo']: { + ipgeo: { async ipgeo ({ ip }) { // doing this makes vscode recognize what's being required const require = this.require; diff --git a/src/puter-js/src/modules/Drivers.js b/src/puter-js/src/modules/Drivers.js index 1d37b4b40..7e63875b0 100644 --- a/src/puter-js/src/modules/Drivers.js +++ b/src/puter-js/src/modules/Drivers.js @@ -144,6 +144,7 @@ class Drivers { } async get (iface_name, service_name) { + if ( ! service_name ) service_name = iface_name; const key = `${iface_name}:${service_name}`; if ( this.drivers_[key] ) return this.drivers_[key]; @@ -162,7 +163,41 @@ class Drivers { }); } - async call (iface_name, service_name, method_name, parameters) { + async call (...a) { + let iface_name, service_name, method_name, parameters; + + // Services with the same name as an interface they implement + // are considered the default implementation for that interface. + // + // A method with the same name as the interface and service it is + // called on can be left unspecified in a driver call through puter.js. + // + // For example: + // puter.drivers.call('ipgeo', { ip: '1.2.3.4' }); + // + // Is the same as: + // puter.drivers.call('ipgeo', 'ipgeo', 'ipgeo', { ip: '1.2.3.4' }) + // + // This is commonly the case when an interface only exists to + // connect a particular service to the drivers API. In this case, + // the interface might not specify the structure of the response + // because it is only intended for that specific integration + // (and that integration alone is responsible for avoiding regressions) + + // interface name, service name, method name, parameters + if ( a.length === 4 ) { + ([iface_name, service_name, method_name, parameters] = a); + } + // interface name, method name, parameters + else if ( a.length === 3 ) { + ([iface_name, method_name, parameters] = a); + } + // interface name, parameters + else if ( a.length === 2 ) { + ([iface_name, parameters] = a); + method_name = iface_name; + } + const driver = await this.get(iface_name, service_name); return await driver.call(method_name, parameters); }