Page MenuHomeSealhub

No OneTemporary

Authored By
Unknown
Size
18 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/chip-types/chip-manager.js b/lib/chip-types/chip-manager.js
deleted file mode 100644
index f3c94e72..00000000
--- a/lib/chip-types/chip-manager.js
+++ /dev/null
@@ -1,154 +0,0 @@
-"use strict";
-const locreq = require("locreq")(__dirname);
-const Errors = locreq("lib/response/error.js");
-const Logger = locreq("lib/logger/logger.js");
-
-const Promise = require("bluebird");
-
-const ConfigurationManager = require("../config/config-manager.js");
-
-// const chip_type_functions = {
-// channel: require("./channel.js"),
-// collection: require("./resource-type.js"),
-// field_type: require("./field-type.js"),
-// datastore: require("./datastore.js")
-// };
-
-const chips = {};
-
-const chip_type_start_order = ["access_strategy", "field_type", "collection", "channel"];
-
-const ChipManager = {
- /**
- * Starts chips in proper order.
- * @param {array} chip_types_to_start - array of names of chips we want to start
- * @returns {Promise} - Promise, which will resolve with starting chips or reject with error
- */
- start_chips: function(){
- Logger.info("Starting all chips:");
- const promises = [];
- const datastore = this.get_datastore_chip();
-
- let promise = datastore.start();
- promises.push(promise);
- Logger.info(`\t \u2713 ${datastore.name}`);
-
- for (const i in chip_type_start_order){
- const type = chip_type_start_order[i];
- Logger.info(` ${type}:`);
- for (const name in chips[type]){
- const chip = chips[type][name];
- Logger.info(`\t \u2713 ${name}`);
- try {
- if (chip.start){
- promise = chip.start();
- promises.push(promise);
- }
- } catch (error){
- Logger.error(`\t " + "couldn't start "${name}"`);
- return Promise.reject(error);
- }
- }
- }
- return Promise.all(promises);
- },
- add_chip: function(type, name, chip){
- if (chips[type] === undefined){
- chips[type] = [];
- }
- if(chips[type][name]) throw Error(`Chip '${type}.${name}' already exists!`);
- chips[type][name] = chip;
- },
- /**
- * Gets all resource types
- * @returns {array} Array of names of resource types.
- */
- __get_all_collections: function(chips){
- const names = [];
- for (const collection in chips.collection){
- names.push(collection);
- }
- return names;
- },
- get_all_collections: function(){
- return this.__get_all_collections(chips);
- },
- /**
- * Checks if chip exists
- * @param {string} type - chip type
- * @param {string} name - chip name
- * @returns {boolean} true if exists, otherwise false
- */
- chip_exists: function(type, name){
- if (chips[type] && chips[type][name]){
- return true;
- } else {
- return false;
- }
- },
- __get_chip: function(chips, type, name){
- try {
- const ret = chips[type][name];
- if (ret === undefined){
- throw new Error(`Chip of type ${type} and name ${name} has not yet been registered`);
- }
- return ret;
- } catch (e){
- throw new Errors.ValidationError(`ChipManager was asked to return a chip of type "${type}" and name "${name}", but it was not found`, {}, {short_message: "chip_not_found"});
- }
- },
- get_chip: function(type, name){
- return this.__get_chip(chips, type, name);
- },
- /*
- * Gets chip by long id
- * @param {string} longid - longid is chip_type.chip_name ex. chanell.cli
- * @returns {object} requested chip or throws error
- */
- __get_chip_by_longid: function(chips, longid){
- const type = longid.split(".")[0];
- const name = longid.split(".")[1];
- return this.__get_chip(chips, type, name);
- },
- get_chip_by_longid: function(longid){
- return this.__get_chip_by_longid(chips, longid);
- },
- __get_chip_amount_by_type: function(chips, type){
- if (chips[type]){
- return Object.keys(chips[type]).length;
- } else {
- return 0;
- }
- },
- get_chip_amount_by_type: function(type){
- return this.__get_chip_amount_by_type(chips, type);
- },
- /**
- * Gets proper datastore chip
- * @returns {object} datastore chip for application or throws error if no datastore chip is defined
- */
- get_datastore_chip: function(){
- const datastore_chip_amount = this.get_chip_amount_by_type("datastore");
- if (datastore_chip_amount === 0){
- throw new Errors.Error("Chip manager was requested to return the datastore chip, but no chips of type `datastore` have been registered.");
- } else if (datastore_chip_amount === 1){
- return chips["datastore"][Object.keys(chips["datastore"])[0]];
- } else {
- const datastore_chip_name = ConfigurationManager.get_config().core.datastore;
- if (datastore_chip_name === undefined){
- throw Errors.Error("Chip manager was requested to return a datastore chip. Multiple chips of type `datastore` have been registered, and no default provided in configuration.");
- } else {
- return this.get_chip("datastore", datastore_chip_name);
- }
- }
- },
- __get_chips_by_type: function(chips, chip_type){
- return chips[chip_type];
- },
- get_chips_by_type: function(chip_type){
- return this.__get_chips_by_type(chips, chip_type);
- }
-};
-
-
-module.exports = ChipManager;
diff --git a/lib/config/config-manager.js b/lib/config/config-manager.js
deleted file mode 100644
index 44aaebe3..00000000
--- a/lib/config/config-manager.js
+++ /dev/null
@@ -1,103 +0,0 @@
-"use strict";
-const locreq = require("locreq")(__dirname);
-const merge = require("merge");
-const path = require("path");
-const fs = require("fs");
-const yaml = require("js-yaml");
-const get_main_app_dir = locreq("lib/utils/get-main-app-dir.js");
-
-let default_config = {};
-let config = {};
-
-function modify_config (is_default_config, key, value){
- const key_elements = key.split(".");
- const new_values = {};
- let current_position = new_values;
- for (let i = 0; i < key_elements.length - 1; i++){
- const current_key = key_elements[i];
- current_position[current_key] = {};
- current_position = current_position[current_key];
- }
- current_position[key_elements[key_elements.length - 1]] = value;
- if (is_default_config){
- default_config = merge.recursive(true, default_config, new_values);
- } else {
- config = merge.recursive(true, config, new_values);
- }
-}
-
-const ConfigManager = {
- load_default_config_for_dir: function(dir){
- const default_config_file = path.join(dir, "default_config.yml");
- try {
- const default_config = yaml.safeLoad(fs.readFileSync(default_config_file, "utf8"));
- for (const i in default_config){
- ConfigManager.set_default_config(i, default_config[i]);
- }
- } catch(e){
- // error
- }
- },
- load_custom_config: function(){
- // we're using console.log here because Logger will not be loaded by now, as it needs config to work.
- const log = global.console.log.bind(console);
- const log_error = global.console.error.bind(console);
- const default_file_path = path.resolve(get_main_app_dir(), "./sealious.yml");
- log("Looking for custom config from file in:", default_file_path);
- const custom_config_file = path.resolve(default_file_path);
- try {
- const custom_config = yaml.safeLoad(fs.readFileSync(custom_config_file, "utf8"));
- log("-----");
- log("config:", "\n", yaml.safeDump(custom_config));
- log("-----");
- for (const i in custom_config){
- ConfigManager.set_config(i, custom_config[i]);
- }
- } catch(e){
- if(e.name === "YAMLException"){
- log_error(`Syntax error in sealious.yml:\n#{e.message}`);
- process.exit(1);
- } else if (e.code === "ENOENT"){
- log("\n\n\tNo 'sealious.yml' file detected.\n\tConsider creating it alongside your app's package.json file if you want to configure the app's chips.\n\n");
- } else {
- log_error(e);
- process.exit(1);
- }
- }
- },
- set_config: function(key, new_config){
- if (arguments.length === 1){
- // config = config;
- } else {
- modify_config(false, key, new_config);
- }
- },
- set_default_config: function(key, value){
- if (arguments.length === 1){
- // default_config = default_config;
- } else {
- modify_config(true, key, value);
- }
- },
- get_configuration: function(key){
- let to_merge_left = default_config;
- let to_merge_right = config;
- const key_elements = key === undefined ? [] : key.split(".");
- while (key_elements.length){
- const current_key = key_elements.splice(0, 1);
- to_merge_left = to_merge_left[current_key] === undefined ? {} : to_merge_left[current_key];
- to_merge_right = to_merge_right[current_key] === undefined ? {} : to_merge_right[current_key];
- }
- return merge.recursive(true, to_merge_left, to_merge_right);
- },
- get_chip_config: function(longid){
- return config.chip_config && config.chip_config[longid];
- },
- get_dispatcher_config: function(){
- return config.dispatcher_config || {};
- }
-};
-
-ConfigManager.get_config = ConfigManager.get_configuration;
-
-module.exports = ConfigManager;
diff --git a/lib/core-services/file-manager.js b/lib/core-services/file-manager.js
deleted file mode 100644
index 27ddd35c..00000000
--- a/lib/core-services/file-manager.js
+++ /dev/null
@@ -1,107 +0,0 @@
-"use strict";
-const locreq = require("locreq")(__dirname);
-const Promise = require("bluebird");
-const UUIDGenerator = require("shortid");
-const path = require("path");
-const fse = require("fs-extra");
-const fs = require("fs");
-const get_main_app_dir = locreq("lib/utils/get-main-app-dir.js");
-
-const Logger = locreq("lib/logger/logger.js");
-const File = locreq("lib/data-structures/file.js");
-const ChipManager = locreq("lib/chip-types/chip-manager.js");
-
-/**
- * Manages files
- * @class
- */
-
-const root_path = function(){
- let parent_tmp = module.parent;
- let parent = null;
- while (parent_tmp){
- parent = parent_tmp;
- parent_tmp = parent_tmp.parent;
- }
-
- return parent.filename;
-};
-
-const FileManager = function(upload_path){
- if (upload_path === undefined){
- upload_path = "./uploaded_files/";
- }
- this.upload_path = path.resolve(get_main_app_dir(), "./" + upload_path);
-};
-
-FileManager.prototype.name = "files";
-FileManager.prototype.save_file = function(file){
- // should be passed as an argument
- const Datastore = ChipManager.get_datastore_chip();
-
- if (!fs.existsSync(this.upload_path)){
- fs.mkdirSync(this.upload_path);
- }
-
- const newID = UUIDGenerator();
-
- const upload_path_with_sealious_name = this.upload_path + "/" + newID;
- return Promise.promisify(fs.writeFile)(upload_path_with_sealious_name, file.data)
- .then(function(){
-
- const file_database_entry = {
- original_name: file.filename,
- creation_context: file.context,
- id: newID,
- mime_type: file.mime,
- };
-
- return Datastore.insert("files", file_database_entry, {});
- })
- .then(function(){
- return {
- id: newID,
- filename: file.filename
- };
- });
-
-};
-FileManager.prototype.diff = function(dispatcher, file){
-
-};
-FileManager.prototype.get_list = function(dispatcher, owner){
- const query = {
- "body.owner": owner
- };
- Logger.info("List for owner '" + owner + "' has been created");
- return this.find(dispatcher, query);
-};
-FileManager.prototype.find = function(context, query){
- const Datastore = ChipManager.get_datastore_chip();
- const self = this;
- return Datastore.find("files", query)
- .then(function(documents){
- const parsed_documents = documents.map(function(document){
- const ret = File.from_db_entry(document);
- ret.path_on_hdd = path.resolve(self.upload_path, "./" + ret.id);
- return ret;
- });
- return Promise.resolve(parsed_documents);
- });
-};
-FileManager.prototype.change_name = function(dispatcher, sealious_name, new_name){
- const Datastore = ChipManager.get_datastore_chip();
- return Datastore.update("files", {
- sealious_id: sealious_name
- }, {
- $set: {
- "body.original_name": new_name
- }
- });
-};
-FileManager.prototype.delete = function(dispatcher, query){
-
-};
-// wersjonowanie, historia dostępu, przetrzymywanie poprzednich wersji
-
-module.exports = new FileManager();
diff --git a/lib/logger/logger.js b/lib/logger/logger.js
deleted file mode 100644
index 8432acbd..00000000
--- a/lib/logger/logger.js
+++ /dev/null
@@ -1,126 +0,0 @@
-"use strict";
-const locreq = require("locreq")(__dirname);
-const winston = require("winston");
-const ConfigManager = locreq("lib/config/config-manager.js");
-
-/*
- This is the custom logger level and color configuration.
-
- @levels - default logger levels, 0 being the lowest importance, 4 being the highest:
- * lazyseal - an Easter, or should we say: Sealious egg. Used only for humorous reasons, the lowest level of importance, default color: white,
- * info - used for stating the current status or general information such as starting the server, default color: green,
- * debug - used for debugging, default color: blue,
- * warning - used to display warnings, default color: yellow,
- * error - used to display errors, default color: red
-
-*/
-const custom = {
- levels: {
- lazyseal: 0,
- info: 1,
- debug: 2,
- warning: 3,
- error: 4,
- no_output: 5,
- },
- colors: {
- lazyseal: "white",
- info: "green",
- debug: "blue",
- warning: "yellow",
- error: "red",
- },
-};
-
-/*
- Returns the current date and time, default format: "yyyy-mm-dd hh:mm:ss.mmm", ex. "2000-01-01 20:00:00.000"
-*/
-function getDateTime (with_date){
- const date = new Date();
-
- let hour = date.getHours();
- hour = (hour < 10 ? "0" : "") + hour;
-
- let min = date.getMinutes();
- min = (min < 10 ? "0" : "") + min;
-
- let sec = date.getSeconds();
- sec = (sec < 10 ? "0" : "") + sec;
-
- let milli = date.getMilliseconds();
- milli = (milli < 10 ? "00" : "") + milli;
- milli = (milli < 100 && milli >= 10 ? "0" : "") + milli;
-
- const year = date.getFullYear();
-
- let month = date.getMonth() + 1;
- month = (month < 10 ? "0" : "") + month;
-
- let day = date.getDate();
- day = (day < 10 ? "0" : "") + day;
-
- if (!with_date){
- return hour + ":" + min + ":" + sec + "." + milli;
- } else {
- return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec + "." + milli;
- }
-}
-
-const transports_array = [];
-
-const logger_level = ConfigManager.get_config().logger.level;
-const logger_color = ConfigManager.get_config().logger.color;
-const logger_file = ConfigManager.get_config().logger.file;
-const logger_dirname = ConfigManager.get_config().logger.dirname;
-const logger_to_json = ConfigManager.get_config().logger.to_json;
-const logger_rotation = ConfigManager.get_config().logger.rotation;
-
-
-const winston_level = new(winston.transports.Console)({
- level: logger_level,
- colorize: logger_color,
- timestamp: function(){
- return getDateTime(false);
- },
-});
-transports_array.push(winston_level);
-
-
-if (logger_file){
- const winston_save_to_file = new(winston.transports.File)({
- filename: logger_file,
- colorize: logger_color,
- timestamp: function(){
- return getDateTime(true);
- },
- dirname: logger_dirname,
- json: logger_to_json,
- });
- const winston_daily_rotate = new(winston.transports.DailyRotateFile)({
- filename: logger_file,
- datePattern: logger_rotation,
- });
- transports_array.push(winston_save_to_file);
- transports_array.push(winston_daily_rotate);
-}
-
-
-const logger = new winston.Logger({
- levels: custom.levels,
- colors: custom.colors,
- transports: transports_array,
-});
-
-logger.rewriters.push(function(level, msg, meta){
- if (Object.keys(meta).length){
- let message = "\n";
- for (const prop in meta){
- message += " - " + prop + ": " + JSON.stringify(meta[prop]) + "\n";
- }
- meta = message;
- }
-
- return meta;
-});
-
-module.exports = logger;
diff --git a/lib/plugins/plugin-manager.js b/lib/plugins/plugin-manager.js
deleted file mode 100644
index 989b26cc..00000000
--- a/lib/plugins/plugin-manager.js
+++ /dev/null
@@ -1,82 +0,0 @@
-"use strict";
-const locreq = require("locreq")(__dirname);
-const path = require("path");
-const fs = require("fs");
-const resolve = require("resolve");
-const Core = locreq("lib/core.js");
-const ConfigManager = locreq("lib/config/config-manager.js");
-
-const Logger = locreq("lib/logger/logger.js");
-
-function custom_resolve (plugin_name, root){
- try {
- return resolve.sync(plugin_name, {basedir: root});
- } catch (error){
- return require.resolve(plugin_name);
- }
-}
-
-function get_package_info_path (dir, package_name){
- let package_path = custom_resolve(package_name, dir);
- let package_info_path = null;
- while (package_info_path === null){
- const temp_path = path.resolve(package_path, "../package.json");
- try {
- fs.accessSync(temp_path, fs.F_OK);
- package_info_path = temp_path;
- } catch (e){
- package_path = path.resolve(package_path, "../");
- }
- }
- return package_info_path;
-}
-
-function get_package_info (dir, package_name){
- return require(get_package_info_path(dir, package_name));
-}
-
-function is_sealious_plugin (dir, module_name){
- const plugin_package_info = get_package_info(dir, module_name);
- return plugin_package_info.keywords && plugin_package_info.keywords.indexOf("sealious-plugin") !== -1;
-}
-
-function load_plugins_from_dir (dir){
- const root = path.resolve(dir);
- const pkgfile = require("locreq")(dir).resolve("package.json");
- const pkg = require(pkgfile);
-
- const dependencies = pkg.dependencies || {};
- const required_sealious_plugins = Object.keys(dependencies).filter(is_sealious_plugin.bind({}, root));
-
-
- if (required_sealious_plugins.length){
- Logger.debug(`${pkg.name} (${pkgfile}) requires: ${required_sealious_plugins.join(", ")}`);
- for (const i in required_sealious_plugins){
- const plugin_name = required_sealious_plugins[i];
- const plugin_info_path = get_package_info_path(root, plugin_name);
- const plugin_dir = path.resolve(plugin_info_path, "../");
- ConfigManager.load_default_config_for_dir(plugin_dir);
- load_plugins_from_dir(plugin_dir);
- if(PluginManager.loaded_plugins.indexOf(plugin_name) === -1){
- require(custom_resolve(plugin_name, plugin_dir));
- PluginManager.loaded_plugins.push(plugin_name);
- Logger.info(`\t\u2713 ${plugin_name} (${plugin_dir})`);
- }else{
- Logger.info(`\ ${plugin_name} (already loaded)`);
- }
- }
- }
-}
-const PluginManager = {
- loaded_plugins: [],
- load_plugins: function(){
- Logger.info("Loading plugins...");
- const sealious_dir = path.resolve(module.filename, "../../../");
- if (sealious_dir !== path.resolve("")){
- load_plugins_from_dir(sealious_dir);
- }
- load_plugins_from_dir("");
- }
-};
-
-module.exports = PluginManager;
diff --git a/lib/utils/run-action.js b/lib/utils/run-action.js
deleted file mode 100644
index 05b8a319..00000000
--- a/lib/utils/run-action.js
+++ /dev/null
@@ -1,11 +0,0 @@
-"use strict";
-const locreq = require("locreq")(__dirname);
-
-const RootSubject = locreq("lib/subject/predefined-subjects/root-subject.js");
-
-module.exports = function(context, subject_path, action_name, params){
- return RootSubject.get_subject(subject_path)
- .then(function(subject){
- return subject.perform_action(context, action_name, params);
- });
-};

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 28, 03:15 (23 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1218104
Default Alt Text
(18 KB)

Event Timeline