@gudhub/core 1.0.64 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUDHUB/DocumentManager/DocumentManager.js +6 -1
- package/GUDHUB/FileManager/FileManager.js +1 -1
- package/GUDHUB/PipeService/PipeService.js +36 -3
- package/GUDHUB/PipeService/PipeService.test.js +13 -0
- package/GUDHUB/Utils/get_date/get_date.js +4 -14
- package/GUDHUB/WebSocket/WebsocketHandler.js +58 -0
- package/GUDHUB/config.js +2 -2
- package/GUDHUB/gudhub.js +4 -57
- package/package.json +1 -1
- package/umd/library.min.js +16 -10
- package/umd/library.min.js.map +1 -1
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export class DocumentManager {
|
|
13
|
-
constructor(req) {
|
|
13
|
+
constructor(req, pipeService) {
|
|
14
14
|
this.req = req;
|
|
15
|
+
this.pipeService = pipeService;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
createDocument(documentObject) {
|
|
@@ -22,6 +23,10 @@ export class DocumentManager {
|
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
emitDocumentInsert(data) {
|
|
27
|
+
this.pipeService.emit("gh_document_insert_one", { app_id: data.app_id, item_id: data.item_id, element_id: data.element_id });
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
getDocument(documentAddress) {
|
|
26
31
|
return this.req.post({
|
|
27
32
|
url: "/api/new/document/find-one",
|
|
@@ -54,6 +54,7 @@ import { checkParams, createId } from "./utils.js";
|
|
|
54
54
|
export class PipeService {
|
|
55
55
|
constructor() {
|
|
56
56
|
this.subscribers = {};
|
|
57
|
+
this.messageBox = {};
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
//============================== ON PIPE ====================================//
|
|
@@ -84,6 +85,9 @@ export class PipeService {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
this.subscribers[typeWithId].add(fn);
|
|
88
|
+
|
|
89
|
+
//checking for messeges those were sent before subscription created
|
|
90
|
+
this.checkMessageBox(typeWithId);
|
|
87
91
|
});
|
|
88
92
|
}
|
|
89
93
|
return this;
|
|
@@ -103,14 +107,26 @@ export class PipeService {
|
|
|
103
107
|
| 'value' - Any (require). Emiter value to subscribers
|
|
104
108
|
|-------------------------------------------------------------------------------*/
|
|
105
109
|
|
|
106
|
-
emit(types, destination,
|
|
110
|
+
emit(types, destination, value, params) {
|
|
107
111
|
types.split(" ").forEach((type) => {
|
|
108
112
|
const listenerName = type + ":" + createId(destination);
|
|
109
113
|
|
|
110
114
|
if (this.subscribers[listenerName]) {
|
|
115
|
+
|
|
116
|
+
// if subscribers list is empty we put message to messageBox
|
|
117
|
+
if (this.subscribers[listenerName].size == 0){
|
|
118
|
+
this.messageBox[listenerName] = [types, destination, value, params];
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// sending messege to subscribers
|
|
111
123
|
this.subscribers[listenerName].forEach(function (fn) {
|
|
112
|
-
fn(null,
|
|
124
|
+
fn(null, value, params);
|
|
113
125
|
});
|
|
126
|
+
|
|
127
|
+
}else {
|
|
128
|
+
// if there no subscribers list we put message to messageBox
|
|
129
|
+
this.messageBox[listenerName] = [types, destination, value, params];
|
|
114
130
|
}
|
|
115
131
|
});
|
|
116
132
|
return this;
|
|
@@ -158,10 +174,27 @@ export class PipeService {
|
|
|
158
174
|
|
|
159
175
|
//if we are not passing a function then we remove a subscriber property
|
|
160
176
|
if (this.subscribers[listenerName] && !func) {
|
|
161
|
-
delete this.subscribers[listenerName]
|
|
177
|
+
delete this.subscribers[listenerName];
|
|
162
178
|
}
|
|
163
179
|
});
|
|
164
180
|
|
|
165
181
|
return this;
|
|
166
182
|
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
//============================== MESSAGE BOX ====================================//
|
|
186
|
+
/*---------------------------------------------------------------------------------
|
|
187
|
+
| If emitting event started erlier then subscriber apears then we save it to the MessageBox
|
|
188
|
+
| After subscriber is created we update check MessageBox for encomming messendges
|
|
189
|
+
|
|
|
190
|
+
|---------------------------------------------------------------------------------*/
|
|
191
|
+
|
|
192
|
+
checkMessageBox(listenerName) {
|
|
193
|
+
if (this.messageBox[listenerName]) {
|
|
194
|
+
this.emit(...this.messageBox[listenerName]);
|
|
195
|
+
|
|
196
|
+
//we delete message after it was readed
|
|
197
|
+
delete this.messageBox[listenerName];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
167
200
|
}
|
|
@@ -61,4 +61,17 @@ describe("PipeService", () => {
|
|
|
61
61
|
gudhub.pipeService.subscribers.should.not.have.property("gh_model_update:22.333");
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
|
|
65
|
+
it("Emitting event and then adding new subscriber", () => {
|
|
66
|
+
let incomeData = null;
|
|
67
|
+
|
|
68
|
+
gudhub
|
|
69
|
+
.emit("test", { app_id: 4, item_id: 3, field_id: 2 }, {"message" : "this is the data"})
|
|
70
|
+
.on("test", { app_id: 4, item_id: 3, field_id: 2 }, (event, data) => {
|
|
71
|
+
incomeData = data.message;
|
|
72
|
+
});
|
|
73
|
+
incomeData.should.equal("this is the data");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
64
77
|
});
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import add from "date-fns/add/index.js";
|
|
14
14
|
import setDay from "date-fns/setDay/index.js";
|
|
15
|
+
import isSameWeek from "date-fns/isSameWeek/index.js";
|
|
15
16
|
|
|
16
17
|
//********************** POPULATE WITH DATE ************************//
|
|
17
18
|
export function populateWithDate(items, model) {
|
|
@@ -105,11 +106,9 @@ export function checkRecurringDate(date, option) {
|
|
|
105
106
|
return false;
|
|
106
107
|
}
|
|
107
108
|
case 'week':
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
109
|
+
let currentYear = new Date().getFullYear();
|
|
110
|
+
let shiftedYearDate = new Date(currentYear, date.getMonth(), date.getDate());
|
|
111
|
+
return isSameWeek(shiftedYearDate, currentDate);
|
|
113
112
|
case 'month':
|
|
114
113
|
if(date.getMonth() === currentDate.getMonth()) {
|
|
115
114
|
return true;
|
|
@@ -120,13 +119,4 @@ export function checkRecurringDate(date, option) {
|
|
|
120
119
|
return true;
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
function getWeek(date) {
|
|
124
|
-
let d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
125
|
-
let dayNumber = d.getDay();
|
|
126
|
-
d.setDate(d.getDate() + 4 - dayNumber);
|
|
127
|
-
let firstJanuary = new Date(date.getFullYear(), 0, 1);
|
|
128
|
-
let weekNumber = Math.ceil((((d- firstJanuary) / 86400000) + 1) / 7);
|
|
129
|
-
return weekNumber;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
122
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function WebsocketHandler(gudhub, message) {
|
|
2
|
+
switch (message.api) {
|
|
3
|
+
case "/items/update":
|
|
4
|
+
console.log("/items/update - ", message);
|
|
5
|
+
gudhub.itemProcessor.updateItemsInStorage(
|
|
6
|
+
message.app_id,
|
|
7
|
+
message.response
|
|
8
|
+
);
|
|
9
|
+
break;
|
|
10
|
+
case "/items/add":
|
|
11
|
+
console.log("/items/add - ", message);
|
|
12
|
+
gudhub.itemProcessor.addItemsToStorage(message.app_id, message.response);
|
|
13
|
+
break;
|
|
14
|
+
case "/items/delete":
|
|
15
|
+
console.log("/items/delete - ", message);
|
|
16
|
+
gudhub.itemProcessor.deleteItemsFromStorage(
|
|
17
|
+
message.app_id,
|
|
18
|
+
message.response
|
|
19
|
+
);
|
|
20
|
+
break;
|
|
21
|
+
case "/app/update":
|
|
22
|
+
console.log("/app/update - ", message);
|
|
23
|
+
gudhub.appProcessor.updatingAppInStorage(message.response);
|
|
24
|
+
break;
|
|
25
|
+
case "/file/delete":
|
|
26
|
+
console.log("file/delete - ", message);
|
|
27
|
+
gudhub.fileManager.deleteFileFromStorage(
|
|
28
|
+
message.response.file_id,
|
|
29
|
+
message.app_id
|
|
30
|
+
);
|
|
31
|
+
break;
|
|
32
|
+
case "/file/upload":
|
|
33
|
+
console.log("file/upload - ", message);
|
|
34
|
+
gudhub.fileManager.addFileToStorage(message.app_id, message.response);
|
|
35
|
+
break;
|
|
36
|
+
case "/file/formupload": //I'm not shure if we are using it (probably in contact form)
|
|
37
|
+
console.log("file/formupload - ", message);
|
|
38
|
+
break;
|
|
39
|
+
case "/file/update": //I'm not shure if we are using it (probably in contact form)
|
|
40
|
+
gudhub.fileManager.updateFileInStorage(
|
|
41
|
+
message.response.file_id,
|
|
42
|
+
message.response.app_id,
|
|
43
|
+
message.response
|
|
44
|
+
);
|
|
45
|
+
console.log("file/update - ", message);
|
|
46
|
+
break;
|
|
47
|
+
case "/new/file/duplicate": //I'm not shure if we are using it (probably in contact form)
|
|
48
|
+
gudhub.fileManager.addFilesToStorage(message.app_id, message.response);
|
|
49
|
+
console.log("new/file/duplicate - ", message);
|
|
50
|
+
break;
|
|
51
|
+
case '/api/new/document/insert-one':
|
|
52
|
+
gudhub.documentManager.emitDocumentInsert(message.response);
|
|
53
|
+
console.log('/api/new/document/insert-one - ', message);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
console.warn("WEBSOCKETS is not process this API:", message.api);
|
|
57
|
+
}
|
|
58
|
+
}
|
package/GUDHUB/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const server_url = "https://gudhub.com/GudHub";
|
|
1
|
+
//export const server_url = "https://gudhub.com/GudHub";
|
|
2
2
|
//export const server_url = "https://gudhub.com/GudHub_Temp";
|
|
3
3
|
//export const server_url = "https://integration.gudhub.com/GudHub_Test";
|
|
4
|
-
|
|
4
|
+
export const server_url = "http://localhost:9000";
|
|
5
5
|
export const wss_url = "wss://gudhub.com/GudHub/ws/app/";
|
|
6
6
|
|
|
7
7
|
// FOR TESTS
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -14,6 +14,7 @@ import { ChunksManager } from "./ChunksManager/ChunksManager.js";
|
|
|
14
14
|
import { DocumentManager } from "./DocumentManager/DocumentManager.js";
|
|
15
15
|
import { Interpritate } from './GHConstructor/interpritate.js'
|
|
16
16
|
import { IS_WEB } from "./consts.js";
|
|
17
|
+
import { WebsocketHandler } from './WebSocket/WebsocketHandler.js';
|
|
17
18
|
|
|
18
19
|
export class GudHub {
|
|
19
20
|
constructor(
|
|
@@ -69,11 +70,12 @@ export class GudHub {
|
|
|
69
70
|
this.pipeService
|
|
70
71
|
);
|
|
71
72
|
this.fileManager = new FileManager(this.storage, this.pipeService, this.req, this.appProcessor);
|
|
72
|
-
this.documentManager = new DocumentManager(this.req);
|
|
73
|
+
this.documentManager = new DocumentManager(this.req, this.pipeService);
|
|
73
74
|
|
|
74
75
|
if (options.initWebsocket) {
|
|
76
|
+
const gudhub = this;
|
|
75
77
|
this.ws.initWebSocket(
|
|
76
|
-
|
|
78
|
+
WebsocketHandler.bind(this, gudhub),
|
|
77
79
|
this.appProcessor.refreshApps.bind(this.appProcessor)
|
|
78
80
|
);
|
|
79
81
|
}
|
|
@@ -456,59 +458,4 @@ export class GudHub {
|
|
|
456
458
|
updateAvatar(imageData) {
|
|
457
459
|
return this.auth.updateAvatar(imageData);
|
|
458
460
|
}
|
|
459
|
-
|
|
460
|
-
websocketHandler(message) {
|
|
461
|
-
switch (message.api) {
|
|
462
|
-
case "/items/update":
|
|
463
|
-
console.log("/items/update - ", message);
|
|
464
|
-
this.itemProcessor.updateItemsInStorage(
|
|
465
|
-
message.app_id,
|
|
466
|
-
message.response
|
|
467
|
-
);
|
|
468
|
-
break;
|
|
469
|
-
case "/items/add":
|
|
470
|
-
console.log("/items/add - ", message);
|
|
471
|
-
this.itemProcessor.addItemsToStorage(message.app_id, message.response);
|
|
472
|
-
break;
|
|
473
|
-
case "/items/delete":
|
|
474
|
-
console.log("/items/delete - ", message);
|
|
475
|
-
this.itemProcessor.deleteItemsFromStorage(
|
|
476
|
-
message.app_id,
|
|
477
|
-
message.response
|
|
478
|
-
);
|
|
479
|
-
break;
|
|
480
|
-
case "/app/update":
|
|
481
|
-
console.log("/app/update - ", message);
|
|
482
|
-
this.appProcessor.updatingAppInStorage(message.response);
|
|
483
|
-
break;
|
|
484
|
-
case "/file/delete":
|
|
485
|
-
console.log("file/delete - ", message);
|
|
486
|
-
this.fileManager.deleteFileFromStorage(
|
|
487
|
-
message.response.file_id,
|
|
488
|
-
message.app_id
|
|
489
|
-
);
|
|
490
|
-
break;
|
|
491
|
-
case "/file/upload":
|
|
492
|
-
console.log("file/upload - ", message);
|
|
493
|
-
this.fileManager.addFileToStorage(message.app_id, message.response);
|
|
494
|
-
break;
|
|
495
|
-
case "/file/formupload": //I'm not shure if we are using it (probably in contact form)
|
|
496
|
-
console.log("file/formupload - ", message);
|
|
497
|
-
break;
|
|
498
|
-
case "/file/update": //I'm not shure if we are using it (probably in contact form)
|
|
499
|
-
this.fileManager.updateFileInStorage(
|
|
500
|
-
message.response.file_id,
|
|
501
|
-
message.response.app_id,
|
|
502
|
-
message.response
|
|
503
|
-
);
|
|
504
|
-
console.log("file/update - ", message);
|
|
505
|
-
break;
|
|
506
|
-
case "/new/file/duplicate": //I'm not shure if we are using it (probably in contact form)
|
|
507
|
-
this.fileManager.addFilesToStorage(message.app_id, message.response);
|
|
508
|
-
console.log("new/file/duplicate - ", message);
|
|
509
|
-
break;
|
|
510
|
-
default:
|
|
511
|
-
console.warn("WEBSOCKETS is not process this API:", message.api);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
461
|
}
|