Merge pull request #1612 from Luis-Fernando-Molina/develop

Contribution: Superalgos Network: Users Profiles loaded into Memory
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-08-30 11:31:40 -04:00
commit 9fb12699f0
32 files changed
+3435 -177

No files matched your search

+1 -1
View File
@@ -95,7 +95,7 @@ try {
/*
Setting up external dependencies.
*/
CL.nodeModules = {
SA.nodeModules = {
fs: require('fs'),
nodeFetch: require('node-fetch')
}
+22
View File
@@ -0,0 +1,22 @@
exports.newEnvironment = function () {
let thisObject = {
WEB_SERVER_URL: 'localhost',
WEB_SOCKETS_INTERFACE_PORT: 18041,
HTTP_INTERFACE_PORT: 34248,
PATH_TO_TASK_SERVER: '../TaskServer',
PATH_TO_DATA_STORAGE: '../Data-Storage',
PATH_TO_PROJECTS: '../Projects',
PATH_TO_LOG_FILES: '../Log-Files',
PATH_TO_PROJECTS_REQUIRED: './Projects',
PATH_TO_PROJECT_SCHEMA: '../Projects/ProjectsSchema.json',
PATH_TO_UI: '../UI',
PATH_TO_DATA_FILES: '../UI/Data-Files/src',
PATH_TO_CLIENT: '../Client/',
PATH_TO_DEFAULT_WORKSPACE: '../Projects/Foundations/Plugins/Workspaces',
PATH_TO_MY_WORKSPACES: '../My-Workspaces',
PATH_TO_FONTS: '../Client/WebServer/Fonts'
}
return thisObject
}
+16
View File
@@ -21,6 +21,7 @@ exports.newMultiProject = function () {
projectInstance.utilities = {}
projectInstance.globals = {}
projectInstance.functionLibraries = {}
projectInstance.modules = {}
projectInstance.taskModules = {}
projectInstance.processModules = {}
projectInstance.botModules = {}
@@ -63,6 +64,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++) {
+11
View File
@@ -0,0 +1,11 @@
{
"folders": [
{
"path": "C:\\Superalgos\\Network"
},
{
"path": "C:\\Superalgos\\Projects\\Network"
}
],
"settings": {}
}
-24
View File
@@ -1,24 +0,0 @@
exports.newBootstrap = function newBootstrap() {
/*
This module helps the Network Node to bootstrap, by
loading all the services and data that needs to start
operating.
*/
let thisObject = {
/* Framework Functions */
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
}
}
+53
View File
@@ -0,0 +1,53 @@
/*
The Superalgos Network offers 3 types of services:
* Social Graph Service
* Search Index Service
* Private Message Service
Users can decide which services to run at their node.
This module is the starting point of the Network Node.
*/
/*
The NT object is accesible everywhere at the Superalgos Network.
It provides access to all modules built for this Network.
*/
global.NT = {}
/*
The SA object is accesible everywhere at the Superalgos Network.
It provides access to all modules built for Superalgos in general.
*/
global.SA = {}
/* Load Environment Variables */
let ENVIRONMENT = require('../EnvironmentForDebug.js');
let ENVIRONMENT_MODULE = ENVIRONMENT.newEnvironment()
global.env = ENVIRONMENT_MODULE
/*
First thing is to load the project schema file.
*/
global.PROJECTS_SCHEMA = require(global.env.PATH_TO_PROJECT_SCHEMA)
/*
Setting up the modules that will be available for the Servers Running inside this Client
*/
let MULTI_PROJECT = require('../MultiProject.js');
let MULTI_PROJECT_MODULE = MULTI_PROJECT.newMultiProject()
MULTI_PROJECT_MODULE.initialize(NT, 'NT')
MULTI_PROJECT_MODULE.initialize(SA, 'SA')
/*
Setting up external dependencies.
*/
SA.nodeModules = {
fs: require('fs'),
nodeFetch: require('node-fetch'),
web3: require('web3')
}
start()
async function start() {
let socialGraphService = NT.projects.network.modules.socialGraph.newSocialGraph()
await socialGraphService.initialize()
}
-82
View File
@@ -1,82 +0,0 @@
/*
The Superalgos Network have 3 types of nodes:
* Social Graph Nodes
* Search Index Nodes
* Private Message Nodes
This module is the starting point of the Social Graph Network Node.
This type of node is responsible for mantaining the whole Social Graph
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'),
QUERY: require('./Query.js'),
QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'),
QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'),
QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'),
QUERY_PROFILE_FOLLOWERS: require('./Queries/ProfileFollowers.js'),
QUERY_PROFILE_FOLLOWING: require('./Queries/ProfileFollowing.js'),
QUERY_POST_REPLIES: require('./Queries/PostReplies.js'),
QUERY_EVENTS: require('./Queries/Events.js')
},
utilities: {
queriesValidations: require('./Utilities/QueriesValidations.js').newQueriesValidations()
},
globals: {
constants: {
queries: {
INITIAL_INDEX_FIRST: 'First',
INITIAL_INDEX_LAST: 'Last',
MIN_AMOUNT_REQUESTED: 1,
MAX_AMOUNT_REQUESTED: 100,
DIRECTION_FUTURE: 'Future',
DIRECTION_PAST: 'Past'
}
}
}
}
/*
The NT object is accesible everywhere at the Superalgos Network.
It provides access to all modules built for this Network.
*/
global.NT = {}
/*
The SA object is accesible everywhere at the Superalgos Network.
It provides access to all modules built for Superalgos in general.
*/
global.SA = {}
/*
First thing is to load the project schema file.
*/
global.PROJECTS_SCHEMA = require(global.env.PATH_TO_PROJECT_SCHEMA)
/*
Setting up the modules that will be available for the Servers Running inside this Client
*/
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()
+4 -4
View File
@@ -45,13 +45,13 @@ exports.newClientInterface = function newClientInterface() {
*/
let eventReceived = JSON.parse(eventMessage)
if (NT.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) {
if (NT.projects.network.globals.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) {
throw ('Event Already Exists.')
}
let event = NT.modules.EVENT.newEvent()
let event = NT.projects.network.modules.event.newNetworkModulesEvent()
event.initialize(eventReceived)
NT.memory.maps.EVENTS.set(eventReceived.eventId, event)
NT.projects.network.globals.memory.maps.EVENTS.set(eventReceived.eventId, event)
}
function queryReceived(queryMessage) {
@@ -80,7 +80,7 @@ exports.newClientInterface = function newClientInterface() {
*/
let queryReceived = JSON.parse(queryMessage)
let query = NT.modules.QUERY.newQuery()
let query = NT.projects.network.modules.queriesQuery.newNetworkModulesQuery()
query.initialize(queryReceived)
return query.execute()
}
@@ -9,7 +9,7 @@ exports.newFoundationsUtilitiesWebAccess = function () {
async function fetchAPIDataFile(url) {
let promise = new Promise((resolve, reject) => {
const fetch = CL.nodeModules.nodeFetch
const fetch = SA.nodeModules.nodeFetch
/*
This is how we call the API.
*/
+2 -2
View File
@@ -12,7 +12,7 @@ exports.newFoundationsUtilitiesPlugins = function () {
let path = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + folder
CL.nodeModules.fs.readdir(path, (err, files) => {
SA.nodeModules.fs.readdir(path, (err, files) => {
if (err) {
reject()
return
@@ -33,7 +33,7 @@ exports.newFoundationsUtilitiesPlugins = function () {
let path = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + folder + '/' + fileName
CL.nodeModules.fs.readFile(path, onFileRead)
SA.nodeModules.fs.readFile(path, onFileRead)
function onFileRead(err, file) {
if (err) {
@@ -16,7 +16,7 @@ function newWorkspace() {
save: saveWorkspace,
backup: backupWorkspace,
share: shareWorkspace,
getNodesByTypeAndHierarchyHeadsType: getNodesByTypeAndHierarchyHeadsType,
getNodesByTypeAndHierarchyHeadsType: getNodesByTypeAndHierarchyHeadsType,
getProjectsHeads: getProjectsHeads,
getHierarchyHeads: getHierarchyHeads,
getHierarchyHeadsById: getHierarchyHeadsById,
@@ -70,8 +70,12 @@ function newWorkspace() {
/* Set up the action switches map */
for (let i = 0; i < PROJECTS_SCHEMA.length; i++) {
let project = PROJECTS_SCHEMA[i].name
let actionSwitch = eval('new' + project + 'ActionSwitch()')
actionSwitchesByProject.set(project, actionSwitch)
try {
let actionSwitch = eval('new' + project + 'ActionSwitch()')
actionSwitchesByProject.set(project, actionSwitch)
} catch (err) {
console.log('[WARN] Action Switch for project ' + project + ' not found.')
}
}
/* Check which was the last workspace. */
@@ -157,9 +161,9 @@ function newWorkspace() {
let workspace = UI.projects.foundations.spaces.designSpace.workspace.workspaceNode
/* Validation if it is too early to save. */
if (thisObject.isInitialized === false) {
if (thisObject.isInitialized === false) {
console.log('Workspace not saved because it has not been initialized. =')
return
return
}
/* Validation of 2 sessions opened at the same time. */
+18
View File
@@ -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
}
@@ -0,0 +1,13 @@
exports.newNetworkGlobalsQueryConstants = function () {
let thisObject = {
INITIAL_INDEX_FIRST: 'First',
INITIAL_INDEX_LAST: 'Last',
MIN_AMOUNT_REQUESTED: 1,
MAX_AMOUNT_REQUESTED: 100,
DIRECTION_FUTURE: 'Future',
DIRECTION_PAST: 'Past'
}
return thisObject
}
+57
View File
@@ -0,0 +1,57 @@
exports.newBootstrap = function newBootstrap() {
/*
This module helps the Network Node to bootstrap, by
loading all the services and data that needs to start
operating.
*/
let thisObject = {
/* Framework Functions */
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
async function initialize() {
let pluginFileNames = await SA.projects.foundations.utilities.plugins.getPluginFileNames(
'Governance',
'User-Profiles'
)
for (let i = 0; i < pluginFileNames.length; i++) {
let pluginFileName = pluginFileNames[i]
let pluginFileContent = await SA.projects.foundations.utilities.plugins.getPluginFileContent(
'Governance',
'User-Profiles',
pluginFileName
)
let userProfilePlugin = JSON.parse(pluginFileContent)
let config = JSON.parse(userProfilePlugin.config)
let signatureObject = config.signature
let web3 = new SA.nodeModules.web3()
let bloackchainAddress = web3.eth.accounts.recover(signatureObject)
let ranking = 0 // TODO: read the blockchain balance and transactions from the Treasury Account to calculate the profile ranking.
let userProfileId = userProfilePlugin.id
let userHandle = config.signature.message
let userProfile = NT.projects.network.modules.socialGraphUserProfile.newNetworkModulesSocialGraphUserProfile()
userProfile.initialize(
userProfileId,
userHandle,
bloackchainAddress,
ranking
)
NT.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.set(userProfileId, userProfile)
NT.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.set(userHandle, userProfile)
}
}
}
@@ -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.projects.network.globals.memory.maps.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.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId)
if (targetUserProfile === undefined) {
throw ('Target User Profile Not Found.')
}
@@ -1,4 +1,4 @@
exports.newBotProfileStats = function newBotProfileStats() {
exports.newNetworkModulesQueriesBotProfileStats = function newNetworkModulesQueriesBotProfileStats() {
let thisObject = {
profile: undefined,
@@ -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.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
} else {
userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
userProfile = NT.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
}
if (userProfile === undefined) {
@@ -1,4 +1,4 @@
exports.newEvents = function newEvents() {
exports.newNetworkModulesQueriesEvents = function newNetworkModulesQueriesEvents() {
/*
This is the query executed to fill the timeline of a certain User or Bot Profile.
@@ -29,7 +29,7 @@ exports.newEvents = function newEvents() {
function execute() {
let response = []
switch (thisObject.direction) {
case NT.globals.constants.queries.DIRECTION_FUTURE: {
case NT.projects.network.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let event = NT.memory.arrays.EVENTS[i]
if (event === undefined) { break }
@@ -37,7 +37,7 @@ exports.newEvents = function newEvents() {
}
break
}
case NT.globals.constants.queries.DIRECTION_PAST: {
case NT.projects.network.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let event = NT.memory.arrays.EVENTS[i]
if (event === undefined) { break }
@@ -59,12 +59,18 @@ 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.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
let emitterBotProfile = emitterUserProfile.bots.get(eventReceived.emitterBotProfileId)
let targetBotProfile = targetUserProfile.bots.get(eventReceived.targetBotProfileId)
let emitterPost = emitterUserProfile.posts.get(eventReceived.emitterPostHash)
let targetPost = targetUserProfile.posts.get(eventReceived.targetPostHash)
let targetUserProfile = NT.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
let targetBotProfile
let targetPost
if (targetUserProfile !== undefined) {
targetBotProfile = targetUserProfile.bots.get(eventReceived.targetBotProfileId)
targetPost = targetUserProfile.posts.get(eventReceived.targetPostHash)
}
/*
Test #1 : The Emitter or Target profile must be the same as the Context Profile.
*/
@@ -217,28 +223,28 @@ exports.newEvents = function newEvents() {
}
if (emitterUserProfile !== undefined) {
let query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats()
let query = NT.projects.network.modules.queriesUserProfileStats.newNetworkModulesQueriesUserProfileStats()
query.initialize({ targetUserProfileId: event.emitterUserProfileId })
eventResponse.emitterUserProfile = query.execute()
query.finalize()
}
if (targetUserProfile !== undefined) {
let query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats()
let query = NT.projects.network.modules.queriesUserProfileStats.newNetworkModulesQueriesUserProfileStats()
query.initialize({ targetUserProfileId: event.targetUserProfileId })
eventResponse.targetUserProfile = query.execute()
query.finalize()
}
if (emitterBotProfile !== undefined) {
let query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats()
let query = NT.projects.network.modules.queriesBotProfileStats.newNetworkModulesQueriesBotProfileStats()
query.initialize({ targetUserProfileId: event.emitterUserProfileId, targetBotProfileId: emitterBotProfileId })
eventResponse.emitterBotProfile = query.execute()
query.finalize()
}
if (targetBotProfile !== undefined) {
let query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats()
let query = NT.projects.network.modules.queriesBotProfileStats.newNetworkModulesQueriesBotProfileStats()
query.initialize({ targetUserProfileId: event.targetUserProfileId, targetBotProfileId: targetBotProfileId })
eventResponse.targetBotProfile = query.execute()
query.finalize()
@@ -1,4 +1,4 @@
exports.newPostReplies = function newPostReplies() {
exports.newNetworkModulesQueriesPostReplies = function newNetworkModulesQueriesPostReplies() {
/*
Each Post regardless if it is authored by a User or Bot Profile,
can have replies. This query is designed for Network Clients to
@@ -39,7 +39,7 @@ exports.newPostReplies = function newPostReplies() {
let array = Array.from(thisObject.post.replies)
switch (thisObject.direction) {
case NT.globals.constants.queries.DIRECTION_FUTURE: {
case NT.projects.network.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
if (post === undefined) { break }
@@ -47,7 +47,7 @@ exports.newPostReplies = function newPostReplies() {
}
break
}
case NT.globals.constants.queries.DIRECTION_PAST: {
case NT.projects.network.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
if (post === undefined) { break }
@@ -1,4 +1,4 @@
exports.newProfileFollowers = function newProfileFollowers() {
exports.newNetworkModulesQueriesProfileFollowers = function newNetworkModulesQueriesProfileFollowers() {
/*
This module represents the query that allows a Network Client to know
all the User or Bot profiles that are following a certain User or Bot profile.
@@ -32,7 +32,7 @@ exports.newProfileFollowers = function newProfileFollowers() {
let array = Array.from(thisObject.profile.followers)
switch (thisObject.direction) {
case NT.globals.constants.queries.DIRECTION_FUTURE: {
case NT.projects.network.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
@@ -40,7 +40,7 @@ exports.newProfileFollowers = function newProfileFollowers() {
}
break
}
case NT.globals.constants.queries.DIRECTION_PAST: {
case NT.projects.network.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
@@ -1,4 +1,4 @@
exports.newProfileFollowing = function newProfileFollowing() {
exports.newNetworkModulesQueriesProfileFollowing = function newNetworkModulesQueriesProfileFollowing() {
/*
This module represents the query that allows a Network Client to know
all the User or Bot profiles that are being followed by a certain User or Bot profile.
@@ -32,7 +32,7 @@ exports.newProfileFollowing = function newProfileFollowing() {
let array = Array.from(thisObject.profile.following)
switch (thisObject.direction) {
case NT.globals.constants.queries.DIRECTION_FUTURE: {
case NT.projects.network.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
@@ -40,7 +40,7 @@ exports.newProfileFollowing = function newProfileFollowing() {
}
break
}
case NT.globals.constants.queries.DIRECTION_PAST: {
case NT.projects.network.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
@@ -1,4 +1,4 @@
exports.newProfilePosts = function newProfilePosts() {
exports.newNetworkModulesQueriesUserProfileStats = function newNetworkModulesQueriesUserProfileStats() {
/*
Each User or Bot Profile can have posts. This query
is designed for Network Clients to fetch the posts
@@ -35,7 +35,7 @@ exports.newProfilePosts = function newProfilePosts() {
let array = Array.from(thisObject.profile.posts)
switch (thisObject.direction) {
case NT.globals.constants.queries.DIRECTION_FUTURE: {
case NT.projects.network.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
@@ -43,7 +43,7 @@ exports.newProfilePosts = function newProfilePosts() {
}
break
}
case NT.globals.constants.queries.DIRECTION_PAST: {
case NT.projects.network.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
@@ -1,4 +1,4 @@
exports.newUserProfileStats = function newUserProfileStats() {
exports.newNetworkModulesQueriesUserProfileStats = function newNetworkModulesQueriesUserProfileStats() {
let thisObject = {
profile: undefined,
@@ -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.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
} else {
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
thisObject.profile = NT.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
}
if (thisObject.profile === undefined) {
@@ -1,4 +1,4 @@
exports.newQuery = function newQuery() {
exports.newNetworkModulesQuery = function newNetworkModulesQuery() {
/*
A Query is a call from a Network Client to
a Network Node with the purpose to get
@@ -41,49 +41,49 @@ exports.newQuery = function newQuery() {
switch (thisObject.queryType) {
case QUERY_TYPES.USER_PROFILE_STATS: {
thisObject.query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats()
thisObject.query = NT.projects.network.modules.queriesUserProfileStats.newNetworkModulesQueriesUserProfileStats()
query.initialize(queryReceived)
query.finalize()
break
}
case QUERY_TYPES.BOT_PROFILE_STATS: {
thisObject.query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats()
thisObject.query = NT.projects.network.modules.queriesBotProfileStats.newNetworkModulesQueriesBotProfileStats()
query.initialize(queryReceived)
query.finalize()
break
}
case QUERY_TYPES.PROFILE_POSTS: {
thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts()
thisObject.query = NT.projects.network.modules.queriesProfilePosts.newNetworkModulesQueriesProfilePosts()
query.initialize(queryReceived)
query.finalize()
break
}
case QUERY_TYPES.POST_REPLIES: {
thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies()
thisObject.query = NT.projects.network.modules.queriesPostReplies.newNetworkModulesQueriesPostReplies()
query.initialize(queryReceived)
query.finalize()
break
}
case QUERY_TYPES.PROFILE_FOLLOWERS: {
thisObject.query = NT.modules.QUERY_PROFILE_FOLLOWERS.newProfileFollowers()
thisObject.query = NT.projects.network.modules.queriesProfileFollowers.newNetworkModulesQueriesProfileFollowers()
query.initialize(queryReceived)
query.finalize()
break
}
case QUERY_TYPES.PROFILE_FOLLOWING: {
thisObject.query = NT.modules.QUERY_PROFILE_FOLLOWING.newProfileFollowing()
thisObject.query = NT.projects.network.modules.queriesProfileFollowing.newNetworkModulesQueriesProfileFollowing()
query.initialize(queryReceived)
query.finalize()
break
}
case QUERY_TYPES.maps.EVENTS: {
thisObject.query = NT.modules.QUERY_EVENTS.newEvents()
thisObject.query = NT.projects.network.modules.queriesEvents.newNetworkModulesQueriesEvents()
query.initialize(queryReceived)
query.finalize()
break
@@ -1,4 +1,4 @@
exports.newBotProfile = function newBotProfile() {
exports.newNetworkModulesSocialGraphBotProfile = function newNetworkModulesSocialGraphBotProfile() {
/*
Users can have a Profile that can:
* follow other bots profiles.
@@ -80,7 +80,7 @@ exports.newBotProfile = function newBotProfile() {
if (thisObject.posts.get(emitterPostHash) !== undefined) {
throw ('Post Already Exists.')
} else {
let post = NT.modules.POST.newPost()
let post = NT.projects.network.modules.socialGraphPost.newNetworkModulesSocialGraphPost()
post.initialize(
emitterUserProfileId,
targetUserProfileId,
@@ -1,4 +1,4 @@
exports.newPost = function newPost() {
exports.newNetworkModulesSocialGraphPost = function newNetworkModulesSocialGraphPost() {
/*
Posts represent a collection of multimedia content sotored somewhere else
and identified by that content hash. Posts might belong to:
@@ -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.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId)
if (targetUserProfile === undefined) {
throw ('Target User Profile Not Found.')
}
@@ -1,4 +1,4 @@
exports.newUserProfile = function newUserProfile() {
exports.newNetworkModulesSocialGraphUserProfile = function newNetworkModulesSocialGraphUserProfile() {
/*
Users can have a Profile that can:
* follow other user profiles.
@@ -84,7 +84,7 @@ exports.newUserProfile = function newUserProfile() {
if (thisObject.posts.get(emitterPostHash) !== undefined) {
throw ('Post Already Exists.')
} else {
let post = NT.modules.POST.newPost()
let post = NT.projects.network.modules.socialGraphPost.newNetworkModulesSocialGraphPost()
post.initialize(
emitterUserProfileId,
targetUserProfileId,
@@ -159,7 +159,7 @@ exports.newUserProfile = function newUserProfile() {
if (bot !== undefined) {
throw ('Bot Already Exists.')
} else {
let bot = NT.modules.BOTS.newBot()
let bot = NT.projects.network.modules.BOTS.newBot()
bot.initialize(
userProfileId,
botProfileId,
@@ -0,0 +1,27 @@
exports.newSocialGraph = function newSocialGraph() {
/*
This module represents the Social Graph Service that
this deals with the Social Graph this node mantains.
The Social Graph is one of the services the Network Node provides.
This service is responsible for mantaining the whole Social Graph
or relationships between User and Bot profiles and also between
their posts.
*/
let thisObject = {
/* Framework Functions */
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
async function initialize() {
let bootstrapProcess = NT.projects.network.modules.bootstrap.newBootstrap()
await bootstrapProcess.initialize()
}
}
@@ -1,4 +1,4 @@
exports.newQueriesValidations = function newQueriesValidations() {
exports.newNetworkUtilitiesQueriesValidations = function newNetworkUtilitiesQueriesValidations() {
/*
This module have a few funcions that are often needed at Queries Modules.
*/
@@ -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.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
}
if (thisObject.profile === undefined) {
@@ -51,11 +51,11 @@ exports.newQueriesValidations = function newQueriesValidations() {
throw ('Initial Index Undefined.')
}
if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_LAST) {
if (queryReceived.initialIndex === NT.projects.network.globals.queryConstants.INITIAL_INDEX_LAST) {
queryReceived.initialIndex = thisObject.profile.posts.length - 1
}
if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_FIRST) {
if (queryReceived.initialIndex === NT.projects.network.globals.queryConstants.INITIAL_INDEX_FIRST) {
queryReceived.initialIndex = 0
}
@@ -75,11 +75,11 @@ exports.newQueriesValidations = function newQueriesValidations() {
throw ('Amount Requested Is Not a Number.')
}
if (queryReceived.amountRequested < NT.globals.constants.queries.MIN_AMOUNT_REQUESTED) {
if (queryReceived.amountRequested < NT.projects.network.globals.queryConstants.MIN_AMOUNT_REQUESTED) {
throw ('Amount Requested Below Min.')
}
if (queryReceived.amountRequested > NT.globals.constants.queries.MAX_AMOUNT_REQUESTED) {
if (queryReceived.amountRequested > NT.projects.network.globals.queryConstants.MAX_AMOUNT_REQUESTED) {
throw ('Amount Requested Above Max.')
}
/*
@@ -89,7 +89,7 @@ exports.newQueriesValidations = function newQueriesValidations() {
throw ('Direction Undefined.')
}
if (queryReceived.direction !== NT.globals.constants.queries.DIRECTION_FUTURE && queryReceived.direction !== NT.globals.constants.queries.DIRECTION_PAST) {
if (queryReceived.direction !== NT.projects.network.globals.queryConstants.DIRECTION_FUTURE && queryReceived.direction !== NT.projects.network.globals.queryConstants.DIRECTION_PAST) {
throw ('Direction Not Supported.')
}
+114
View File
@@ -1267,5 +1267,119 @@
"Features",
"Positions"
]
},
{
"name": "Network",
"propertyName": "network",
"NT": {
"globals": [
{
"name": "Query Constants",
"propertyName": "queryConstants",
"functionName": "newNetworkGlobalsQueryConstants",
"fileName": "QueryConstants.js"
},
{
"name": "Memory",
"propertyName": "memory",
"functionName": "newNetworkGlobalsMemory",
"fileName": "Memory.js"
}
],
"modules": [
{
"name": "Bot Profile Stats",
"propertyName": "queriesBotProfileStats",
"functionName": "newNetworkModulesQueriesBotProfileStats",
"fileName": "Queries/BotProfileStats.js"
},
{
"name": "User Profile Stats",
"propertyName": "queriesUserProfileStats",
"functionName": "newNetworkModulesQueriesUserProfileStats",
"fileName": "Queries/UserProfileStats.js"
},
{
"name": "Profile Posts",
"propertyName": "queriesProfilePosts",
"functionName": "newNetworkModulesQueriesProfilePosts",
"fileName": "Queries/ProfilePosts.js"
},
{
"name": "Profile Followers",
"propertyName": "queriesProfileFollowers",
"functionName": "newNetworkModulesQueriesProfileFollowers",
"fileName": "Queries/ProfileFollowers.js"
},
{
"name": "Profile Following",
"propertyName": "queriesProfileFollowing",
"functionName": "newNetworkModulesQueriesProfileFollowing",
"fileName": "Queries/ProfileFollowing.js"
},
{
"name": "Post Replies",
"propertyName": "queriesPostReplies",
"functionName": "newNetworkModulesQueriesPostReplies",
"fileName": "Queries/PostReplies.js"
},
{
"name": "Events",
"propertyName": "queriesEvents",
"functionName": "newNetworkModulesQueriesEvents",
"fileName": "Queries/Events.js"
},
{
"name": "User Profile",
"propertyName": "socialGraphUserProfile",
"functionName": "newNetworkModulesSocialGraphUserProfile",
"fileName": "Social-Graph/UserProfile.js"
},
{
"name": "Bot Profile",
"propertyName": "socialGraphBotProfile",
"functionName": "newNetworkModulesSocialGraphBotProfile",
"fileName": "Social-Graph/BotProfile.js"
},
{
"name": "Post",
"propertyName": "socialGraphPost",
"functionName": "newNetworkModulesSocialGraphPost",
"fileName": "Social-Graph/Post.js"
},
{
"name": "Social Graph",
"propertyName": "socialGraph",
"functionName": "newNetworkModulesSocialGraph",
"fileName": "SocialGraph.js"
},
{
"name": "Bootstrap",
"propertyName": "bootstrap",
"functionName": "newNetworkModulesBootstrap",
"fileName": "Bootstrap.js"
},
{
"name": "Query",
"propertyName": "Query",
"functionName": "newNetworkModulesQuery",
"fileName": "Query.js"
},
{
"name": "Event",
"propertyName": "event",
"functionName": "newNetworkModulesEvent",
"fileName": "Event.js"
}
],
"utilities": [
{
"name": "Queries Validations",
"propertyName": "queriesValidations",
"functionName": "newNetworkUtilitiesQueriesValidations",
"fileName": "QueriesValidations.js"
}
]
}
}
]
+10
View File
@@ -121,6 +121,8 @@ function newCanvas() {
let spaceAnimationDrawMap = new Map()
let spaceDefinitionDrawMap = new Map()
if (projectDefinition.UI === undefined) { continue }
/* Set up Globals of this Project */
if (projectDefinition.UI.globals !== undefined) {
for (let j = 0; j < projectDefinition.UI.globals.length; j++) {
@@ -742,6 +744,8 @@ function newCanvas() {
let projectInstance = UI.projects[projectDefinition.propertyName]
if (projectInstance === undefined) { continue }
if (projectDefinition.UI === undefined) { continue }
if (projectDefinition.UI.spaces === undefined) { continue }
for (let j = 0; j < projectDefinition.UI.spaces.length; j++) {
let spaceInstance = projectInstance.events.onMouseDownMap.get(j)
if (spaceInstance === undefined) { continue }
@@ -850,6 +854,8 @@ function newCanvas() {
let projectInstance = UI.projects[projectDefinition.propertyName]
if (projectInstance === undefined) { continue }
if (projectDefinition.UI === undefined) { continue }
if (projectDefinition.UI.spaces === undefined) { continue }
for (let j = 0; j < projectDefinition.UI.spaces.length; j++) {
let spaceInstance = projectInstance.events.onMouseClickMap.get(j)
if (spaceInstance === undefined) { continue }
@@ -966,6 +972,8 @@ function newCanvas() {
let projectInstance = UI.projects[projectDefinition.propertyName]
if (projectInstance === undefined) { continue }
if (projectDefinition.UI === undefined) { continue }
if (projectDefinition.UI.spaces === undefined) { continue }
for (let j = 0; j < projectDefinition.UI.spaces.length; j++) {
let spaceInstance = projectInstance.events.onMouseOverMap.get(j)
if (spaceInstance === undefined) { continue }
@@ -1028,6 +1036,8 @@ function newCanvas() {
let projectInstance = UI.projects[projectDefinition.propertyName]
if (projectInstance === undefined) { continue }
if (projectDefinition.UI === undefined) { continue }
if (projectDefinition.UI.spaces === undefined) { continue }
for (let j = 0; j < projectDefinition.UI.spaces.length; j++) {
let spaceInstance = projectInstance.events.onMouseWheelMap.get(j)
if (spaceInstance === undefined) { continue }
+3011 -3
View File
File diff suppressed because it is too large. Load diff
+6 -1
View File
@@ -1 +1,6 @@
{}
{
"dependencies": {
"node-fetch": "^2.6.1",
"web3": "^1.5.2"
}
}