diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..2906c52 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,35 @@ +{ + "predef": [ + "global", + "Promise", + "require", + "process", + "module", + "exports" + ], + "browser": false, + "boss": true, + "curly": true, + "debug": false, + "devel": true, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true, + "unused": true +} diff --git a/dist/build.js b/dist/build.js new file mode 100644 index 0000000..bae2cbd --- /dev/null +++ b/dist/build.js @@ -0,0 +1,180 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(require("remotestoragejs")); + else if(typeof define === 'function' && define.amd) + define(["remotestoragejs"], factory); + else { + var a = typeof exports === 'object' ? factory(require("remotestoragejs")) : factory(root["RemoteStorage"]); + for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; + } +})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + /** + * File: Kosmos + * + * Maintainer: - Sebastian Kippe + * Version: - 0.1.0 + * + * This module manages data related to the Kosmos group communication suite + */ + + var RemoteStorage = __webpack_require__(1); + + RemoteStorage.defineModule('kosmos', function (privateClient /*, publicClient*/) { + + var extend = RemoteStorage.util.extend; + + // + // Types/Schemas + // + + var baseProperties = { + "id": { + "type": "string" + }, + "createdAt": { + "type": "string", + "format": "date-time" + }, + "updatedAt": { + "type": "string", + "format": "date-time" + } + }; + + privateClient.declareType('space', { + "type": "object", + "properties": extend({ + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "protocol": { + "type": "string", + "default": "IRC", + "enum": ["IRC", "XMPP", "Mattermost", "Slack"] + }, + "server": { + "type": "object", + "properties": { + "hostname": { + "type": "string" + }, + "port": { + "type": "number" + }, + "secure": { + "type": "boolean" + }, + "username": { + "type": "string" + }, + "password": { + "type": "string" + }, + "nickname": { + "type": "string" + } + } + }, + "channels": { + "type": "array", + "default": [] + } + }, baseProperties), + "required": ["id", "name", "protocol", "server"] + }); + + // + // Public functions + // + + var kosmos = { + + spaces: { + getAll: function getAll() { + return privateClient.getAll('spaces/'); + }, + store: function store(params) { + if (!params.createdAt) { + params.createdAt = new Date().toISOString(); + } + + return privateClient.storeObject('space', 'spaces/' + params.id, params); + }, + remove: function remove(id) { + return privateClient.remove('spaces/' + id); + } + }, + + // TODO remove + client: privateClient + }; + + // + // Return public functions + // + + return { exports: kosmos }; + }); + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + module.exports = __WEBPACK_EXTERNAL_MODULE_1__; + +/***/ } +/******/ ]) +}); +; +//# sourceMappingURL=build.js.map \ No newline at end of file diff --git a/dist/build.js.map b/dist/build.js.map new file mode 100644 index 0000000..248d6d9 --- /dev/null +++ b/dist/build.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 911743eea92345b1a49e","webpack:///./index.js","webpack:///external {\"root\":\"RemoteStorage\",\"commonjs2\":\"remotestoragejs\",\"commonjs\":\"remotestoragejs\",\"amd\":\"remotestoragejs\"}"],"names":["RemoteStorage","require","defineModule","privateClient","extend","util","baseProperties","declareType","kosmos","spaces","getAll","store","params","createdAt","Date","toISOString","storeObject","id","remove","client","exports"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;ACtCA;;;;;;;;;AASA,KAAIA,gBAAgB,mBAAAC,CAAQ,CAAR,CAApB;;AAEAD,eAAcE,YAAd,CAA2B,QAA3B,EAAqC,UAASC,aAAT,CAAsB,kBAAtB,EAA0C;;AAE7E,OAAIC,SAASJ,cAAcK,IAAd,CAAmBD,MAAhC;;AAEA;AACA;AACA;;AAEA,OAAIE,iBAAiB;AACnB,WAAM;AACJ,eAAQ;AADJ,MADa;AAInB,kBAAa;AACX,eAAQ,QADG;AAEX,iBAAU;AAFC,MAJM;AAQnB,kBAAa;AACX,eAAQ,QADG;AAEX,iBAAU;AAFC;AARM,IAArB;;AAcAH,iBAAcI,WAAd,CAA0B,OAA1B,EAAmC;AACjC,aAAQ,QADyB;AAEjC,mBAAcH,OAAO;AACnB,aAAM;AACJ,iBAAQ;AADJ,QADa;AAInB,eAAQ;AACN,iBAAQ;AADF,QAJW;AAOnB,mB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(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"remotestoragejs\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"remotestoragejs\"], factory);\n\telse {\n\t\tvar a = typeof exports === 'object' ? factory(require(\"remotestoragejs\")) : factory(root[\"RemoteStorage\"]);\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 911743eea92345b1a49e","/**\n * File: Kosmos\n *\n * Maintainer: - Sebastian Kippe \n * Version: - 0.1.0\n *\n * This module manages data related to the Kosmos group communication suite\n */\n\nvar RemoteStorage = require('remotestoragejs');\n\nRemoteStorage.defineModule('kosmos', function(privateClient/*, publicClient*/) {\n\n var extend = RemoteStorage.util.extend;\n\n //\n // Types/Schemas\n //\n\n var baseProperties = {\n \"id\": {\n \"type\": \"string\"\n },\n \"createdAt\": {\n \"type\": \"string\",\n \"format\": \"date-time\"\n },\n \"updatedAt\": {\n \"type\": \"string\",\n \"format\": \"date-time\"\n }\n };\n\n privateClient.declareType('space', {\n \"type\": \"object\",\n \"properties\": extend({\n \"id\": {\n \"type\": \"string\",\n },\n \"name\": {\n \"type\": \"string\",\n },\n \"protocol\": {\n \"type\": \"string\",\n \"default\": \"IRC\",\n \"enum\": [\"IRC\", \"XMPP\", \"Mattermost\", \"Slack\"]\n },\n \"server\": {\n \"type\": \"object\",\n \"properties\": {\n \"hostname\": {\n \"type\": \"string\"\n },\n \"port\": {\n \"type\": \"number\"\n },\n \"secure\": {\n \"type\": \"boolean\"\n },\n \"username\": {\n \"type\": \"string\"\n },\n \"password\": {\n \"type\": \"string\"\n },\n \"nickname\": {\n \"type\": \"string\"\n },\n }\n },\n \"channels\": {\n \"type\": \"array\",\n \"default\": []\n },\n }, baseProperties),\n \"required\": [\"id\", \"name\", \"protocol\", \"server\"]\n });\n\n //\n // Public functions\n //\n\n var kosmos = {\n\n spaces: {\n\n getAll() {\n return privateClient.getAll('spaces/');\n },\n\n store(params) {\n if (!params.createdAt) { params.createdAt = new Date().toISOString(); }\n\n return privateClient.storeObject('space', `spaces/${params.id}`, params);\n },\n\n remove(id) {\n return privateClient.remove(`spaces/${id}`);\n }\n\n },\n\n // TODO remove\n client: privateClient\n };\n\n //\n // Return public functions\n //\n\n return { exports: kosmos };\n\n});\n\n\n\n// WEBPACK FOOTER //\n// ./index.js","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"root\":\"RemoteStorage\",\"commonjs2\":\"remotestoragejs\",\"commonjs\":\"remotestoragejs\",\"amd\":\"remotestoragejs\"}\n// module id = 1\n// module chunks = 0"],"sourceRoot":""} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..99d53c5 --- /dev/null +++ b/index.js @@ -0,0 +1,113 @@ +/** + * File: Kosmos + * + * Maintainer: - Sebastian Kippe + * Version: - 0.1.0 + * + * This module manages data related to the Kosmos group communication suite + */ + +var RemoteStorage = require('remotestoragejs'); + +RemoteStorage.defineModule('kosmos', function(privateClient/*, publicClient*/) { + + var extend = RemoteStorage.util.extend; + + // + // Types/Schemas + // + + var baseProperties = { + "id": { + "type": "string" + }, + "createdAt": { + "type": "string", + "format": "date-time" + }, + "updatedAt": { + "type": "string", + "format": "date-time" + } + }; + + privateClient.declareType('space', { + "type": "object", + "properties": extend({ + "id": { + "type": "string", + }, + "name": { + "type": "string", + }, + "protocol": { + "type": "string", + "default": "IRC", + "enum": ["IRC", "XMPP", "Mattermost", "Slack"] + }, + "server": { + "type": "object", + "properties": { + "hostname": { + "type": "string" + }, + "port": { + "type": "number" + }, + "secure": { + "type": "boolean" + }, + "username": { + "type": "string" + }, + "password": { + "type": "string" + }, + "nickname": { + "type": "string" + }, + } + }, + "channels": { + "type": "array", + "default": [] + }, + }, baseProperties), + "required": ["id", "name", "protocol", "server"] + }); + + // + // Public functions + // + + var kosmos = { + + spaces: { + + getAll() { + return privateClient.getAll('spaces/'); + }, + + store(params) { + if (!params.createdAt) { params.createdAt = new Date().toISOString(); } + + return privateClient.storeObject('space', `spaces/${params.id}`, params); + }, + + remove(id) { + return privateClient.remove(`spaces/${id}`); + } + + }, + + // TODO remove + client: privateClient + }; + + // + // Return public functions + // + + return { exports: kosmos }; + +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..4edcc7d --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "remotestorage-module-kosmos", + "version": "0.1.0", + "description": "remoteStorage module for Kosmos clients", + "main": "./dist/build.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "dev": "webpack -w", + "build": "NODE_ENV=production webpack" + }, + "author": "Kosmos Developers (https://kosmos.org)", + "license": "MIT", + "devDependencies": { + "babel-core": "^6.18.2", + "babel-loader": "^6.2.7", + "babel-preset-es2015": "^6.18.0", + "webpack": "^1.13.2" + } +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..7cc83aa --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,32 @@ +var webpack = require('webpack'); +var isProd = (process.env.NODE_ENV === 'production'); + +// minimize only in production +var plugins = isProd ? [new webpack.optimize.UglifyJsPlugin({minimize: true })] : [] + +module.exports = { + entry: './index.js', + // source map not in production + devtool: !isProd && 'source-map', + output: { + filename: __dirname + '/dist/build.js', + libraryTarget: 'umd' + }, + externals: { + "remotestoragejs": { + root: "RemoteStorage", //