annotations

This commit is contained in:
2024-11-27 12:46:03 +02:00
parent 54b8941f3c
commit ad4eef17f5
12 changed files with 514 additions and 36 deletions
+116 -1
View File
@@ -2,7 +2,7 @@ import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
/**
* Main backend application
* Main backend application class
*/
class App{
constructor(){
@@ -73,4 +73,119 @@ class App{
}
}
/* The following are pseudo in order to keep documentation aligned to the code */
/**
* The core application plugins
*/
class AppCore{
/**
* The configuration plugin instance
* @type Config
*/
config = undefined;
/**
* The database plugin instance
* @type Db
*/
db = undefined;
/**
* The web server plugin instance
* @type WebServer
*/
webServer = undefined;
}
/**
* The main logical part application plugins
*/
class AppManagement {
/**
* Game objects manager plugin instance
* @type GameObjectsManager
*/
gameObject = undefined;
/**
* Games manager plugin instance
* @type GamesManager
*/
games = undefined;
/**
* Rules manager plugin instance
* @type RulesManager
*/
rules = undefined;
/**
* Scenarios manager plugin instance
* @type ScenariosManager
*/
scenarios = undefined;
}
/**
* The main application controller plugin instances
*/
class AppControllerApi {
/**
* Game objects controller plugin instance
* @type GameObjectsController
*/
gameObjectsApi = undefined;
/**
* Games controller plugin instance
* @type GamesController
*/
gamesApi = undefined;
/**
* Rules controller plugin instance
* @type RulesController
*/
rulesApi = undefined;
/**
* Scenarios controller plugin instance
* @type ScenariosController
*/
scenariosApi = undefined;
/**
* Asset controller plugin instance
* @type AssetController
*/
assetApi = undefined;
}
class AppConcrete {
/**
* Application core plugins
* @type AppCore
* @memberof App
*/
core = undefined;
/**
* Application management plugins
* @type AppManagement
* @memberof App
*/
management = undefined;
/**
* Application controller API plugins
* @type AppControllerApi
* @memberof App
*/
controller = undefined
}
export default App;
+86 -3
View File
@@ -6,16 +6,40 @@ import path from 'path'
class Config{
name = 'config';
/**
* @class File system options , repository setup
* @alias FileSystemOptions
* @memberof Config
*/
fs = {
/** Repository path
* @type {string}
* @memberof FileSystemOptions
*/
repo: null
}
/**
* @class Database options
* @alias DatabaseOptions
* @memberof Config
*/
db = {
/** Database name
* @type {string}
* @memberof DatabaseOptions
*/
name:'pronature',
/** Database connection string
* @type {string}
* @memberof DatabaseOptions
*/
url: "mongodb://127.0.0.1:27017/pronature"
}
/**
* @class web site options
* @class Web site endpoint options
* @alias SiteOptions
* @memberof Config
*/
@@ -25,38 +49,97 @@ class Config{
* @memberof SiteOptions
*/
host:'https://localhost:5173',
/** Whether to use SSL
* @type {boolean}
* @memberof SiteOptions
*/
ssl: true,
/** Port to use
* @type {Number}
* @memberof SiteOptions
*/
port: 3000,
/**
* @class certificate data
* @class Certificate data
* @alias CertificateOptions
* @memberof SiteOptions
*/
certificate: {
/**
* Certificate key
* Certificate private key
* @type {string}
* @memberof CertificateOptions
*/
key: './.cert/dev-key.pem',
/**
* Certificate public key
* @type {string}
* @memberof CertificateOptions
*/
cert: './.cert/dev-cert.pem',
/**
* PK Passphrase
* @type {string}
* @memberof CertificateOptions
*/
passphrase: 'parola'
},
}
/**
* @class Access management options
* @alias AccessManagementOptions
* @memberof Config
*/
am = {
/**
* Salt, a string to be used in order to make a more complex password hash
* @type {string}
* @memberof AccessManagementOptions
*/
salt : 'P@ssSal7y!!',
/**
* @class Cookie options
* @alias CookieOptions
* @memberof AccessManagementOptions
*/
cookie: {
/**
* Cookie secret
* @type {string}
* @memberof CookieOptions
*/
secret: 'S3cret4C00k!ie$',
/**
* Cookie max age (in seconds)
* @type {Number}
* @memberof CookieOptions
*/
maxAge: 1000 * 60 * 60 * 24 * 7
}
}
/**
* Initializes the configuration
* @param {App} app The application
*/
async init(app){
if (!this.fs.repo){
this.fs.repo = path.resolve(`${app.root}/repo`) + '/';
}
}
/**
* Starts the configuration plugin
* @param {App} app the application instance
*/
async start(app){
}
+63 -21
View File
@@ -8,10 +8,19 @@ let dbo;
*/
class Db {
name = 'db';
/**
* Initializes the database plugin
* @param {App} app The application instance
*/
init(app){
}
/**
* Starts the database plugin
* @param {App} app The application instance
*/
async start(app){
db = await MongoClient.connect(app.config.db.url, {maxPoolSize: 256});
try {
@@ -74,6 +83,12 @@ class Db {
}
}
/**
* Performs a database aggregation according to a given pipeline
* @param {string} collection Database collection name
* @param {Object} specs aggregation definition (the pipeline)
* @returns {Object[]} Array of records
*/
async aggregate(collection, specs){
try {
let cursor = dbo.collection(collection);
@@ -84,6 +99,13 @@ class Db {
}
}
/**
* Finds the distinct values for a specified field across a single collection
* @param {string} collection Database collection name
* @param {Object} key The target field for the distinction
* @param {Object} query filter to be applied
* @returns {Object[]}
*/
async distinct(collection, key, query){
try {
return await dbo.collection(collection).distinct(key, query);
@@ -91,6 +113,13 @@ class Db {
}
}
/**
* Updates a record in database by given key and value
* @param {Object} collection DB collection
* @param {Object} key The key/query which identifies the record to be updated
* @param {Object} value The new value for the record
* @returns {Object} The result from the update operation
*/
async update(collection, key, value){
let r;
try {
@@ -101,6 +130,13 @@ class Db {
}
}
/**
* Performs partial update on a record by given key and partial value
* @param {Object} collection Database collection
* @param {Object} key The key/query which identifies the record to be updated
* @param {Object} value The partial value to be updated
* @returns {Object} The result from the update operation
*/
async updateSet(collection, key, value){
let r;
try {
@@ -110,6 +146,11 @@ class Db {
}
}
/**
* Removes a record from the database by given key
* @param {Object} collection Database collection
* @param {Object} key The key/query which identifies the record to be updated
*/
async remove(collection, key){
try {
await dbo.collection(collection).deleteMany(key);
@@ -117,27 +158,28 @@ class Db {
}
}
convertToObjectId(object, key, recursive, result){
if (object && object[key]){
if (Array.isArray(object[key])){
object[key].forEach((v, i, a)=>{
a[i] = this.ObjectId(v);
result && result.push(a[i]);
})
}else{
let oid = this.ObjectId(object[key])
object[key] = oid;
result && result.push(oid);
}
}
if (recursive){
for (var k in object){
if (typeof(object[k]) == 'object'){
this.convertToObjectId(object[k], key, recursive, result);
}
}
}
}
// convertToObjectId(object, key, recursive, result){
// if (object && object[key]){
// if (Array.isArray(object[key])){
// object[key].forEach((v, i, a)=>{
// a[i] = this.ObjectId(v);
// result && result.push(a[i]);
// })
// }else{
// let oid = this.ObjectId(object[key])
// object[key] = oid;
// result && result.push(oid);
// }
// }
// if (recursive){
// for (var k in object){
// if (typeof(object[k]) == 'object'){
// this.convertToObjectId(object[k], key, recursive, result);
// }
// }
// }
// }
sanitizeQuery(q){
if (!q) return;
+11
View File
@@ -8,9 +8,16 @@ import cookieParser from 'cookie-parser';
import helmet from 'helmet';
import { v4 as uuidv4 } from 'uuid';
/**
* The Web Server class, manages all request from the web pllatform, manages the APIs
*/
class WebServer {
name = 'webServer';
/**
* Initializes the web server plugin
* @param {App} app The application instance
*/
async init(app) {
const xapp = express();
this.xapp = xapp;
@@ -61,6 +68,10 @@ class WebServer {
app.config.am.helmet && xapp.use(helmet(app.config.am.helmet));
}
/**
* Starts the web server plugin
* @param {App} app The application instance
*/
async start(app) {
let indexFile = app.root + '/index.html';
+10 -3
View File
@@ -8,7 +8,7 @@ import path from 'path';
const collection = 'assets';
/**
* Application layer manager
* Game objects manager
*/
class GameObjectsManager{
name = 'gameObject';
@@ -157,7 +157,7 @@ class GameObjectsManager{
}
/**
* GameObject entity
* GameObject entity, can be: panorama picture, 3d environment, 3d object, 2d object (picture), a player (3d), audio or video asset
*/
class GameObject {
/**
@@ -166,9 +166,16 @@ class GameObject {
*/
name = null;
/**
* Game object type
* @type string
*/
type = null;
/**
* Associated file
* @type File
*/
file = null;
}
+6
View File
@@ -77,6 +77,12 @@ class Rule {
*/
name = null;
/**
* Rule definition
* @type Object
*/
name = null;
}
export { RulesManager }