From ecd0dcc76164a94da78a400bf1d000d4ef03ef2b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 30 Aug 2021 13:13:37 +0200 Subject: [PATCH] Network Workspace --- MultiProject.js | 15 +++++++++++++++ .../.vscode/Superalgos Network.code-workspace | 11 +++++++++++ Network/Queries/BotProfileStats.js | 4 ++-- Network/Queries/Events.js | 4 ++-- Network/Queries/UserProfileStats.js | 4 ++-- Network/SocialGraphNetwokNode.js | 15 --------------- Network/Utilities/QueriesValidations.js | 2 +- Network/clientsInterface.js | 6 +++--- Network/post.js | 2 +- Projects/Network/NT/Globals/Memory.js | 18 ++++++++++++++++++ .../Network/NT/Modules/Event.js | 6 +++--- Projects/ProjectsSchema.json | 14 ++++++++++++++ 12 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 Network/.vscode/Superalgos Network.code-workspace create mode 100644 Projects/Network/NT/Globals/Memory.js rename Network/event.js => Projects/Network/NT/Modules/Event.js (98%) diff --git a/MultiProject.js b/MultiProject.js index 4ed6f29d2..0bbe713cd 100644 --- a/MultiProject.js +++ b/MultiProject.js @@ -63,6 +63,21 @@ exports.newMultiProject = function () { } } + /* + From here we will require and get the modules, but without instantiation thisObject. + */ + + /* Set up Modules for this Project */ + if (projectDefinition[rootObjectName].modules !== undefined) { + for (let j = 0; j < projectDefinition[rootObjectName].modules.length; j++) { + let taskModuleDefinition = projectDefinition[rootObjectName].modules[j] + let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Modules' + '/' + taskModuleDefinition.fileName + + let requiredObject = require(path) + projectInstance.modules[taskModuleDefinition.propertyName] = requiredObject + } + } + /* Set up Task Modules for this Project */ if (projectDefinition[rootObjectName].taskModules !== undefined) { for (let j = 0; j < projectDefinition[rootObjectName].taskModules.length; j++) { diff --git a/Network/.vscode/Superalgos Network.code-workspace b/Network/.vscode/Superalgos Network.code-workspace new file mode 100644 index 000000000..757812e5e --- /dev/null +++ b/Network/.vscode/Superalgos Network.code-workspace @@ -0,0 +1,11 @@ +{ + "folders": [ + { + "path": "C:\\Superalgos\\Network" + }, + { + "path": "C:\\Superalgos\\Projects\\Network" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/Network/Queries/BotProfileStats.js b/Network/Queries/BotProfileStats.js index 510f1ebb3..9e157202f 100644 --- a/Network/Queries/BotProfileStats.js +++ b/Network/Queries/BotProfileStats.js @@ -19,9 +19,9 @@ exports.newBotProfileStats = function newBotProfileStats() { */ let userProfile if (queryReceived.targetUserProfileId !== undefined) { - userProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + userProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + userProfile = NT.globals.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (userProfile === undefined) { diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index d32f756d7..79fbb6bba 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -59,8 +59,8 @@ exports.newEvents = function newEvents() { Any of the above happening, means that indeed it is related. */ - let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) - let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) + let emitterUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) + let targetUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) let emitterBotProfile = emitterUserProfile.bots.get(eventReceived.emitterBotProfileId) let targetBotProfile = targetUserProfile.bots.get(eventReceived.targetBotProfileId) let emitterPost = emitterUserProfile.posts.get(eventReceived.emitterPostHash) diff --git a/Network/Queries/UserProfileStats.js b/Network/Queries/UserProfileStats.js index a7fd8580b..b79deba1e 100644 --- a/Network/Queries/UserProfileStats.js +++ b/Network/Queries/UserProfileStats.js @@ -18,9 +18,9 @@ exports.newUserProfileStats = function newUserProfileStats() { Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = NT.globals.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + thisObject.profile = NT.globals.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (thisObject.profile === undefined) { diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index b3120696c..d35c0d9bd 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -13,7 +13,6 @@ or relationships between User and Bot profiles and also between their posts. global.NT = { modules: { BOOTSTRAP: require('./Bootstrap.js'), - EVENT: require('./Event.js'), USER_PROFILE: require('./UserProfile.js'), BOT_PROFILE: require('./BotProfile.js'), POST: require('./Post.js'), @@ -51,20 +50,6 @@ let MULTI_PROJECT = require('../MultiProject.js'); let MULTI_PROJECT_MODULE = MULTI_PROJECT.newMultiProject() MULTI_PROJECT_MODULE.initialize(CL, 'CL') MULTI_PROJECT_MODULE.initialize(SA, 'SA') -/* -Here is the Data we are going to keep in memory. -*/ -NT.memory = { - maps: { - USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id. - USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle. - EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once. - }, - arrays: { - NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node ordered by Ranking. - NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node ordered by Ranking. - } -} let bootstrapProcess = NT.modules.BOOTSTRAP.newBootstrap() bootstrapProcess.initialize() \ No newline at end of file diff --git a/Network/Utilities/QueriesValidations.js b/Network/Utilities/QueriesValidations.js index 640665fcd..11ac407a7 100644 --- a/Network/Utilities/QueriesValidations.js +++ b/Network/Utilities/QueriesValidations.js @@ -15,7 +15,7 @@ exports.newQueriesValidations = function newQueriesValidations() { Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = NT.globals.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } if (thisObject.profile === undefined) { diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 2f48f80df..482da953f 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -45,13 +45,13 @@ exports.newClientInterface = function newClientInterface() { */ let eventReceived = JSON.parse(eventMessage) - if (NT.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) { + if (NT.globals.memory.EVENTS.get(eventReceived.eventId) !== undefined) { throw ('Event Already Exists.') } - let event = NT.modules.EVENT.newEvent() + let event = NT.modules.event.newNetworkModulesEvent() event.initialize(eventReceived) - NT.memory.maps.EVENTS.set(eventReceived.eventId, event) + NT.globals.memory.EVENTS.set(eventReceived.eventId, event) } function queryReceived(queryMessage) { diff --git a/Network/post.js b/Network/post.js index efe1f33f0..985bdd4a9 100644 --- a/Network/post.js +++ b/Network/post.js @@ -97,7 +97,7 @@ exports.newPost = function newPost() { /* Validate Target User Profile. */ - let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + let targetUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } diff --git a/Projects/Network/NT/Globals/Memory.js b/Projects/Network/NT/Globals/Memory.js new file mode 100644 index 000000000..3248bd2ca --- /dev/null +++ b/Projects/Network/NT/Globals/Memory.js @@ -0,0 +1,18 @@ +exports.newNetworkGlobalsMemory = function () { + /* + Here is the Data we are going to keep in memory. + */ + let thisObject = { + maps: { + USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id. + USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle. + EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once. + }, + arrays: { + NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node ordered by Ranking. + NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node ordered by Ranking. + } + } + + return thisObject +} \ No newline at end of file diff --git a/Network/event.js b/Projects/Network/NT/Modules/Event.js similarity index 98% rename from Network/event.js rename to Projects/Network/NT/Modules/Event.js index b586d9077..a7feafb07 100644 --- a/Network/event.js +++ b/Projects/Network/NT/Modules/Event.js @@ -1,4 +1,4 @@ -exports.newEvent = function newEvent() { +exports.newNetworkModulesEvent = function newNetworkModulesEvent() { /* An Event is anything that happens system wide that needs to be delivered to relevant entities via @@ -104,7 +104,7 @@ exports.newEvent = function newEvent() { if (emitterUserProfileId === undefined) { throw ('Emitter User Profile Id Not Provided.') } - emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) + emitterUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) if (emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } @@ -112,7 +112,7 @@ exports.newEvent = function newEvent() { Validate Target User Profile. */ if (thisObject.targetUserProfileId !== undefined) { - targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + targetUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 800979e73..b9a782d5f 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1278,6 +1278,20 @@ "propertyName": "queryConstants", "functionName": "newNetworkGlobalsQueryConstants", "fileName": "QueryConstants.js" + }, + { + "name": "Memory", + "propertyName": "memory", + "functionName": "newNetworkGlobalsMemory", + "fileName": "Memory.js" + } + ], + "modules": [ + { + "name": "Event", + "propertyName": "event", + "functionName": "newNetworkModulesEvent", + "fileName": "Event.js" } ] }