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');
var Kosmos = function(privateClient/*, publicClient*/) {
var extend = RemoteStorage.util.extend;
const Kosmos = function(privateClient/*, publicClient*/) {
//
// Types/Schemas
//
var baseProperties = {
"id": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
}
};
privateClient.declareType('space', {
privateClient.declareType('chat-account', {
"type": "object",
"properties": extend({
"properties": {
"id": {
"type": "string",
},
"name": {
"type": "string",
},
"protocol": {
"type": "string",
"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": {
"type": "object",
"properties": {
"hostname": {
"type": "string"
"type": [ "string", "null" ]
},
"port": {
"type": "number"
"type": [ "number", "null" ]
},
"secure": {
"type": "boolean"
},
"username": {
"type": "string"
},
"password": {
"type": "string"
},
"nickname": {
"type": "string"
},
}
}
},
"channels": {
"type": "array",
"default": []
},
"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
//
var kosmos = {
const kosmos = {
spaces: {
getAll() {
return privateClient.getAll('spaces/');
accounts: {
getIds() {
return privateClient.getListing('chat/').then(listing => {
return Object.keys(listing).map(id => id.replace(/\/$/, ''));
});
},
store(params) {
if (!params.createdAt) { params.createdAt = new Date().toISOString(); }
return privateClient.storeObject('space', `spaces/${params.id}`, params);
getConfig(id) {
return privateClient.getObject(`chat/${id}/account`);
},
storeConfig(obj) {
return privateClient.storeObject('chat-account', `chat/${obj.id}/account`, obj);
},
// TODO recursively remove all files
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

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",
"dev": "webpack -w",
"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)",
"license": "MIT",