Merge pull request #1 from 67P/feature/spaces_to_accounts

Refactor spaces to accounts, add separate channel documents
This commit is contained in:
Basti 2021-08-25 17:29:23 +02:00 committed by GitHub
commit a273db8839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 539 additions and 500 deletions

2
dist/build.js vendored
View File

@ -1 +1 @@
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("remotestoragejs"));else if("function"==typeof define&&define.amd)define(["remotestoragejs"],t);else{var r=t("object"==typeof exports?require("remotestoragejs"):e.RemoteStorage);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,function(e){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=r(1),n=function(e){var t=o.util.extend,r={id:{type:"string"},createdAt:{type:"string",format:"date-time"},updatedAt:{type:"string",format:"date-time"}};e.declareType("space",{type:"object",properties:t({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:[]},botkaURL:{type:"string"}},r),required:["id","name","protocol","server"]});var n={spaces:{getAll:function(){return e.getAll("spaces/")},store:function(t){return t.createdAt||(t.createdAt=(new Date).toISOString()),e.storeObject("space","spaces/"+t.id,t)},remove:function(t){return e.remove("spaces/"+t)}},client:e};return{exports:n}};t.default={name:"kosmos",builder:n}},function(t,r){t.exports=e}])}); !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(e){e.declareType("chat-account",{type:"object",properties:{id:{type:"string"},protocol:{type:"string",default:"IRC",enum:["IRC","XMPP"]},username:{type:["string","null"]},password:{type:["string","null"]},nickname:{type:["string","null"]},server:{type:"object",properties:{hostname:{type:["string","null"]},port:{type:["number","null"]},secure:{type:"boolean"}}},botkaURL:{type:["string","null"]}},required:["id","protocol"]}),e.declareType("chat-channel",{type:"object",properties:{id:{type:"string"},accountId:{type:"string"},displayName:{type:["string","null"]},userNickname:{type:["string","null"]},topic:{type:["string","null"]}},required:["id","accountId"]});var t={accounts:{getIds:function(){return e.getListing("chat/").then(function(e){return Object.keys(e).map(function(e){return e.replace(/\/$/,"")})})},getConfig:function(t){return e.getObject("chat/"+t+"/account")},storeConfig:function(t){return e.storeObject("chat-account","chat/"+t.id+"/account",t)},remove:function(t){return e.remove("chat/"+t+"/account")}},channels:{getAll:function(t){return e.getAll("chat/"+t+"/channels/")},store:function(t){return e.storeObject("chat-channel","chat/"+t.accountId+"/channels/"+t.id,t)},remove:function(t,n){return e.remove("chat/"+t+"/channels/"+n)}},client:e};return{exports:t}};t.default={name:"kosmos",builder:n}}])});

128
index.js
View File

@ -1,97 +1,117 @@
var RemoteStorage = require('remotestoragejs'); const Kosmos = function(privateClient/*, publicClient*/) {
var Kosmos = function(privateClient/*, publicClient*/) {
var extend = RemoteStorage.util.extend;
// //
// Types/Schemas // Types/Schemas
// //
var baseProperties = { privateClient.declareType('chat-account', {
"id": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
}
};
privateClient.declareType('space', {
"type": "object", "type": "object",
"properties": extend({ "properties": {
"id": { "id": {
"type": "string", "type": "string",
}, },
"name": {
"type": "string",
},
"protocol": { "protocol": {
"type": "string", "type": "string",
"default": "IRC", "default": "IRC",
"enum": ["IRC", "XMPP", "Mattermost", "Slack"] "enum": ["IRC", "XMPP"] // Mattermost, Slack, ...
},
"username": {
"type": [ "string", "null" ]
},
"password": {
"type": [ "string", "null" ]
},
"nickname": {
"type": [ "string", "null" ]
}, },
"server": { "server": {
"type": "object", "type": "object",
"properties": { "properties": {
"hostname": { "hostname": {
"type": "string" "type": [ "string", "null" ]
}, },
"port": { "port": {
"type": "number" "type": [ "number", "null" ]
}, },
"secure": { "secure": {
"type": "boolean" "type": "boolean"
}, }
"username": {
"type": "string"
},
"password": {
"type": "string"
},
"nickname": {
"type": "string"
},
} }
}, },
"channels": {
"type": "array",
"default": []
},
"botkaURL": { "botkaURL": {
"type": "string" "type": [ "string", "null" ]
} }
}, baseProperties), },
"required": ["id", "name", "protocol", "server"] "required": [
"id",
"protocol"
]
});
privateClient.declareType('chat-channel', {
"type": "object",
"properties": {
"id": {
"type": "string",
},
"accountId": {
"type": "string"
},
"displayName": {
"type": [ "string", "null" ]
},
"userNickname": {
"type": [ "string", "null" ]
},
"topic": {
"type": [ "string", "null" ]
}
},
"required": [
"id",
"accountId"
]
}); });
// //
// Public functions // Public functions
// //
var kosmos = { const kosmos = {
spaces: { accounts: {
getIds() {
getAll() { return privateClient.getListing('chat/').then(listing => {
return privateClient.getAll('spaces/'); return Object.keys(listing).map(id => id.replace(/\/$/, ''));
});
}, },
store(params) { getConfig(id) {
if (!params.createdAt) { params.createdAt = new Date().toISOString(); } return privateClient.getObject(`chat/${id}/account`);
return privateClient.storeObject('space', `spaces/${params.id}`, params);
}, },
storeConfig(obj) {
return privateClient.storeObject('chat-account', `chat/${obj.id}/account`, obj);
},
// TODO recursively remove all files
remove(id) { remove(id) {
return privateClient.remove(`spaces/${id}`); return privateClient.remove(`chat/${id}/account`);
} }
},
channels: {
getAll(accountId) {
return privateClient.getAll(`chat/${accountId}/channels/`);
},
store(obj) {
return privateClient.storeObject('chat-channel', `chat/${obj.accountId}/channels/${obj.id}`, obj);
},
remove(accountId, id) {
return privateClient.remove(`chat/${accountId}/channels/${id}`);
}
}, },
// TODO remove // TODO remove

907
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack -w", "dev": "webpack -w",
"build": "NODE_ENV=production webpack", "build": "NODE_ENV=production webpack",
"prepublish": "npm run build && git add dist" "version": "npm run build && git add dist"
}, },
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)", "author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)",
"license": "MIT", "license": "MIT",