From 360ad2e25247b37aacfbb76604781b46bf5ef6d7 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Tue, 18 Jun 2024 22:04:56 -0400 Subject: [PATCH] refactor: move FilesystemService to BaseService --- packages/backend/src/CoreModule.js | 18 ++++++++++++------ .../src/filesystem/FilesystemService.js | 14 ++++++-------- .../backend/src/services/ParameterService.js | 13 ++++++++----- .../services/information/InformationService.js | 18 +++++++----------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/packages/backend/src/CoreModule.js b/packages/backend/src/CoreModule.js index 0f57e357..ce9a04ea 100644 --- a/packages/backend/src/CoreModule.js +++ b/packages/backend/src/CoreModule.js @@ -156,6 +156,16 @@ const install = async ({ services, app, useapi }) => { MaxLimitES, { max: 5000 }, ]), }); + + const { ParameterService } = require('./services/ParameterService'); + services.registerService('params', ParameterService); + + const { InformationService } = require('./services/information/InformationService'); + services.registerService('information', InformationService) + + const { FilesystemService } = require('./filesystem/FilesystemService'); + services.registerService('filesystem', FilesystemService); + services.registerService('es:subdomain', EntityStoreService, { entity: 'subdomain', upstream: ESBuilder.create([ @@ -263,9 +273,7 @@ const install = async ({ services, app, useapi }) => { const install_legacy = async ({ services }) => { const { ProcessEventService } = require('./services/runtime-analysis/ProcessEventService'); - const { ParameterService } = require('./services/ParameterService'); - const { InformationService } = require('./services/information/InformationService'); - const { FilesystemService } = require('./filesystem/FilesystemService'); + // const { FilesystemService } = require('./filesystem/FilesystemService'); const PerformanceMonitor = require('./monitor/PerformanceMonitor'); const { OperationTraceService } = require('./services/OperationTraceService'); const { WSPushService } = require('./services/WSPushService'); @@ -277,9 +285,7 @@ const install_legacy = async ({ services }) => { // === Services which do not yet extend BaseService === services.registerService('process-event', ProcessEventService); - services.registerService('params', ParameterService); - services.registerService('information', InformationService) - services.registerService('filesystem', FilesystemService); + // services.registerService('filesystem', FilesystemService); services.registerService('operationTrace', OperationTraceService); services.registerService('__event-push-ws', WSPushService); services.registerService('referral-code', ReferralCodeService); diff --git a/packages/backend/src/filesystem/FilesystemService.js b/packages/backend/src/filesystem/FilesystemService.js index e69dae3a..bfb9d3d6 100644 --- a/packages/backend/src/filesystem/FilesystemService.js +++ b/packages/backend/src/filesystem/FilesystemService.js @@ -38,8 +38,9 @@ const { PermissionUtil, PermissionRewriter, PermissionImplicator, PermissionExpl const { DB_WRITE } = require("../services/database/consts"); const { UserActorType } = require('../services/auth/Actor'); const { get_user } = require('../helpers'); +const BaseService = require('../services/BaseService'); -class FilesystemService extends AdvancedBase { +class FilesystemService extends BaseService { static MODULES = { _path: require('path'), uuidv4: require('uuid').v4, @@ -47,11 +48,11 @@ class FilesystemService extends AdvancedBase { config: require('../config.js'), } - constructor (args) { - super(args); + old_constructor (args) { + // super(args); const { services } = args; - this.services = services; + // this.services = services; services.registerService('resourceService', ResourceService); services.registerService('sizeService', SizeService); @@ -101,13 +102,10 @@ class FilesystemService extends AdvancedBase { return result; } } - - // TODO: eventually FilesystemService will extend BaseService - // and _init() will be called (and awaited) automatically - this._init(); } async _init () { + this.old_constructor({ services: this.services }); const svc_permission = this.services.get('permission'); svc_permission.register_rewriter(PermissionRewriter.create({ matcher: permission => { diff --git a/packages/backend/src/services/ParameterService.js b/packages/backend/src/services/ParameterService.js index 65398d8b..fb17fc5e 100644 --- a/packages/backend/src/services/ParameterService.js +++ b/packages/backend/src/services/ParameterService.js @@ -1,3 +1,5 @@ +const BaseService = require("./BaseService"); + /* * Copyright (C) 2024 Puter Technologies Inc. * @@ -16,12 +18,13 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -class ParameterService { - constructor({ services }) { - this.log = services.get('log-service').create('params'); +class ParameterService extends BaseService { + _construct () { this.parameters_ = []; - - this._registerCommands(services.get('commands')); + } + + _init () { + this._registerCommands(this.services.get('commands')); } createParameters(serviceName, parameters, opt_instance) { diff --git a/packages/backend/src/services/information/InformationService.js b/packages/backend/src/services/information/InformationService.js index db4eda91..7e508cae 100644 --- a/packages/backend/src/services/information/InformationService.js +++ b/packages/backend/src/services/information/InformationService.js @@ -1,3 +1,5 @@ +const BaseService = require("../BaseService"); + /* * Copyright (C) 2024 Puter Technologies Inc. * @@ -77,19 +79,13 @@ class InformationObtainer { * // code to obtain fsentry from path * }); */ -class InformationService { - constructor ({ services }) { +class InformationService extends BaseService { + _construct () { this.providers_ = {}; - this.services = services; + } - this.log = services.get('log-service').create('information-service'); - - (async () => { - await services.ready; - if ( services.has('commands') ) { - this._register_commands(services.get('commands')); - } - })(); + _init () { + this._register_commands(this.services.get('commands')); } given (input) {