owservable 0.8.40 → 0.8.41
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/lib/_enums/store.type.enum.d.ts +6 -6
- package/lib/_enums/store.type.enum.js +9 -9
- package/lib/_types/connection.manager.refresh.type.d.ts +9 -9
- package/lib/_types/connection.manager.refresh.type.js +2 -2
- package/lib/_types/cronjob.type.d.ts +7 -7
- package/lib/_types/cronjob.type.js +2 -2
- package/lib/_types/store.scope.type.d.ts +2 -2
- package/lib/_types/store.scope.type.js +2 -2
- package/lib/_types/store.subscription.config.type.d.ts +15 -15
- package/lib/_types/store.subscription.config.type.js +2 -2
- package/lib/_types/store.subscription.update.type.d.ts +9 -9
- package/lib/_types/store.subscription.update.type.js +2 -2
- package/lib/_types/subscription.methods.type.d.ts +6 -6
- package/lib/_types/subscription.methods.type.js +2 -2
- package/lib/_types/watcher.type.d.ts +6 -5
- package/lib/_types/watcher.type.js +2 -2
- package/lib/_types/worker.type.d.ts +5 -5
- package/lib/_types/worker.type.js +2 -2
- package/lib/auth/i.connection.manager.d.ts +9 -9
- package/lib/auth/i.connection.manager.js +2 -2
- package/lib/functions/action/add.action.cronjobs.d.ts +1 -1
- package/lib/functions/action/add.action.cronjobs.js +25 -25
- package/lib/functions/action/add.action.watchers.d.ts +1 -1
- package/lib/functions/action/add.action.watchers.js +22 -22
- package/lib/functions/action/add.action.workers.d.ts +1 -1
- package/lib/functions/action/add.action.workers.js +22 -22
- package/lib/functions/execute/execute.cronjob.d.ts +3 -3
- package/lib/functions/execute/execute.cronjob.js +12 -12
- package/lib/functions/execute/execute.on.files.recursively.d.ts +2 -2
- package/lib/functions/execute/execute.on.files.recursively.js +17 -17
- package/lib/functions/execute/execute.processes.in.folder.d.ts +2 -2
- package/lib/functions/execute/execute.processes.in.folder.js +10 -10
- package/lib/functions/execute/execute.watcher.d.ts +3 -3
- package/lib/functions/execute/execute.watcher.js +16 -11
- package/lib/functions/execute/execute.watcher.js.map +1 -1
- package/lib/functions/execute/execute.worker.d.ts +3 -3
- package/lib/functions/execute/execute.worker.js +11 -11
- package/lib/functions/initiate.cronjobs.d.ts +2 -2
- package/lib/functions/initiate.cronjobs.js +8 -8
- package/lib/functions/initiate.watchers.d.ts +2 -2
- package/lib/functions/initiate.watchers.js +8 -8
- package/lib/functions/initiate.workers.d.ts +2 -2
- package/lib/functions/initiate.workers.js +8 -8
- package/lib/middleware/data.middleware.map.d.ts +7 -7
- package/lib/middleware/data.middleware.map.js +18 -18
- package/lib/middleware/data.middleware.map.js.map +1 -1
- package/lib/mongodb/collections.models.map.d.ts +8 -8
- package/lib/mongodb/collections.models.map.js +22 -22
- package/lib/mongodb/collections.models.map.js.map +1 -1
- package/lib/mongodb/functions/index/add.both.indices.to.attributes.d.ts +3 -3
- package/lib/mongodb/functions/index/add.both.indices.to.attributes.js +8 -8
- package/lib/mongodb/functions/index/add.down.indices.to.attributes.d.ts +3 -3
- package/lib/mongodb/functions/index/add.down.indices.to.attributes.js +5 -5
- package/lib/mongodb/functions/index/add.index.to.attributes.d.ts +3 -3
- package/lib/mongodb/functions/index/add.index.to.attributes.js +11 -11
- package/lib/mongodb/functions/index/add.up.and.down.indices.to.attributes.d.ts +3 -3
- package/lib/mongodb/functions/index/add.up.and.down.indices.to.attributes.js +9 -9
- package/lib/mongodb/functions/index/add.up.indices.to.attributes.d.ts +3 -3
- package/lib/mongodb/functions/index/add.up.indices.to.attributes.js +5 -5
- package/lib/mongodb/functions/observable.database.d.ts +3 -3
- package/lib/mongodb/functions/observable.database.js +22 -22
- package/lib/mongodb/functions/observable.model.d.ts +4 -4
- package/lib/mongodb/functions/observable.model.js +41 -41
- package/lib/mongodb/functions/process.models.d.ts +2 -2
- package/lib/mongodb/functions/process.models.js +40 -40
- package/lib/mongodb/mongodb.connector.d.ts +7 -7
- package/lib/mongodb/mongodb.connector.js +51 -51
- package/lib/owservable.client.d.ts +23 -23
- package/lib/owservable.client.js +162 -162
- package/lib/owservable.d.ts +41 -41
- package/lib/owservable.js +63 -63
- package/lib/store/a.store.d.ts +37 -37
- package/lib/store/a.store.js +126 -126
- package/lib/store/collection.store.d.ts +8 -8
- package/lib/store/collection.store.js +111 -111
- package/lib/store/count.store.d.ts +7 -7
- package/lib/store/count.store.js +46 -46
- package/lib/store/document.store.d.ts +12 -12
- package/lib/store/document.store.js +134 -134
- package/lib/store/factories/store.factory.d.ts +4 -4
- package/lib/store/factories/store.factory.js +15 -15
- package/package.json +8 -8
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const mongoose = require("mongoose");
|
|
13
|
-
class MongoDBConnector {
|
|
14
|
-
static init(mongoDbUri) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
if (!this._connection) {
|
|
17
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
console.log('');
|
|
19
|
-
mongoose
|
|
20
|
-
.connect(mongoDbUri, {
|
|
21
|
-
poolSize: 10,
|
|
22
|
-
useNewUrlParser: true,
|
|
23
|
-
useUnifiedTopology: true,
|
|
24
|
-
keepAlive: true,
|
|
25
|
-
keepAliveInitialDelay: 100000
|
|
26
|
-
})
|
|
27
|
-
.then(() => {
|
|
28
|
-
this._connection = mongoose.connection;
|
|
29
|
-
resolve(this._connection);
|
|
30
|
-
})
|
|
31
|
-
.catch(reject);
|
|
32
|
-
mongoose.connection.on('connecting', () => console.log('ows -> MongoDB connecting to', mongoDbUri, '...'));
|
|
33
|
-
mongoose.connection.on('connected', () => console.log('ows -> MongoDB connected to', mongoDbUri));
|
|
34
|
-
mongoose.connection.on('open', () => console.log('ows -> MongoDB opened connection to', mongoDbUri));
|
|
35
|
-
mongoose.connection.on('error', console.error.bind(console, 'ows -> MongoDB connection error:'));
|
|
36
|
-
mongoose.connection.on('disconnecting', () => console.error('ows -> MongoDB disconnecting from', mongoDbUri, '...'));
|
|
37
|
-
mongoose.connection.on('disconnected', () => console.error('ows -> MongoDB disconnected from', mongoDbUri));
|
|
38
|
-
mongoose.connection.on('close', () => console.error('ows -> MongoDB closed connection to', mongoDbUri));
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return this._connection;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
static get connection() {
|
|
47
|
-
return this._connection;
|
|
48
|
-
}
|
|
49
|
-
constructor() { }
|
|
50
|
-
}
|
|
51
|
-
exports.default = MongoDBConnector;
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const mongoose = require("mongoose");
|
|
13
|
+
class MongoDBConnector {
|
|
14
|
+
static init(mongoDbUri) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
if (!this._connection) {
|
|
17
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
console.log('');
|
|
19
|
+
mongoose
|
|
20
|
+
.connect(mongoDbUri, {
|
|
21
|
+
poolSize: 10,
|
|
22
|
+
useNewUrlParser: true,
|
|
23
|
+
useUnifiedTopology: true,
|
|
24
|
+
keepAlive: true,
|
|
25
|
+
keepAliveInitialDelay: 100000
|
|
26
|
+
})
|
|
27
|
+
.then(() => {
|
|
28
|
+
this._connection = mongoose.connection;
|
|
29
|
+
resolve(this._connection);
|
|
30
|
+
})
|
|
31
|
+
.catch(reject);
|
|
32
|
+
mongoose.connection.on('connecting', () => console.log('ows -> MongoDB connecting to', mongoDbUri, '...'));
|
|
33
|
+
mongoose.connection.on('connected', () => console.log('ows -> MongoDB connected to', mongoDbUri));
|
|
34
|
+
mongoose.connection.on('open', () => console.log('ows -> MongoDB opened connection to', mongoDbUri));
|
|
35
|
+
mongoose.connection.on('error', console.error.bind(console, 'ows -> MongoDB connection error:'));
|
|
36
|
+
mongoose.connection.on('disconnecting', () => console.error('ows -> MongoDB disconnecting from', mongoDbUri, '...'));
|
|
37
|
+
mongoose.connection.on('disconnected', () => console.error('ows -> MongoDB disconnected from', mongoDbUri));
|
|
38
|
+
mongoose.connection.on('close', () => console.error('ows -> MongoDB closed connection to', mongoDbUri));
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return this._connection;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static get connection() {
|
|
47
|
+
return this._connection;
|
|
48
|
+
}
|
|
49
|
+
constructor() { }
|
|
50
|
+
}
|
|
51
|
+
exports.default = MongoDBConnector;
|
|
52
52
|
//# sourceMappingURL=mongodb.connector.js.map
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
|
-
import IConnectionManager from './auth/i.connection.manager';
|
|
3
|
-
export default class OwservableClient extends Subject<any> {
|
|
4
|
-
private _connectionManager;
|
|
5
|
-
private _ping;
|
|
6
|
-
private _location;
|
|
7
|
-
private _stores;
|
|
8
|
-
private _subscriptions;
|
|
9
|
-
private _timeout;
|
|
10
|
-
constructor(connectionManager: IConnectionManager);
|
|
11
|
-
disconnected(): void;
|
|
12
|
-
private set location(value);
|
|
13
|
-
consume(message: any): Promise<void>;
|
|
14
|
-
ping(): void;
|
|
15
|
-
private _processPong;
|
|
16
|
-
private _checkSession;
|
|
17
|
-
private removeSubscription;
|
|
18
|
-
private reloadData;
|
|
19
|
-
private updateSubscription;
|
|
20
|
-
private isValidTarget;
|
|
21
|
-
private sendDebugTargets;
|
|
22
|
-
private clearSubscriptions;
|
|
23
|
-
}
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
import IConnectionManager from './auth/i.connection.manager';
|
|
3
|
+
export default class OwservableClient extends Subject<any> {
|
|
4
|
+
private _connectionManager;
|
|
5
|
+
private _ping;
|
|
6
|
+
private _location;
|
|
7
|
+
private _stores;
|
|
8
|
+
private _subscriptions;
|
|
9
|
+
private _timeout;
|
|
10
|
+
constructor(connectionManager: IConnectionManager);
|
|
11
|
+
disconnected(): void;
|
|
12
|
+
private set location(value);
|
|
13
|
+
consume(message: any): Promise<void>;
|
|
14
|
+
ping(): void;
|
|
15
|
+
private _processPong;
|
|
16
|
+
private _checkSession;
|
|
17
|
+
private removeSubscription;
|
|
18
|
+
private reloadData;
|
|
19
|
+
private updateSubscription;
|
|
20
|
+
private isValidTarget;
|
|
21
|
+
private sendDebugTargets;
|
|
22
|
+
private clearSubscriptions;
|
|
23
|
+
}
|
package/lib/owservable.client.js
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const lodash_1 = require("lodash");
|
|
13
|
-
const rxjs_1 = require("rxjs");
|
|
14
|
-
const store_factory_1 = require("./store/factories/store.factory");
|
|
15
|
-
const data_middleware_map_1 = require("./middleware/data.middleware.map");
|
|
16
|
-
class OwservableClient extends rxjs_1.Subject {
|
|
17
|
-
constructor(connectionManager) {
|
|
18
|
-
super();
|
|
19
|
-
this._ping = 0;
|
|
20
|
-
this._connectionManager = connectionManager;
|
|
21
|
-
this._stores = new Map();
|
|
22
|
-
this._subscriptions = new Map();
|
|
23
|
-
}
|
|
24
|
-
disconnected() {
|
|
25
|
-
this.clearSubscriptions();
|
|
26
|
-
this._connectionManager.disconnected();
|
|
27
|
-
clearTimeout(this._timeout);
|
|
28
|
-
}
|
|
29
|
-
set location(location) {
|
|
30
|
-
if (location === this._location)
|
|
31
|
-
return;
|
|
32
|
-
this._location = location;
|
|
33
|
-
this._connectionManager.location(location);
|
|
34
|
-
}
|
|
35
|
-
consume(message) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
switch (message.type) {
|
|
38
|
-
case 'pong':
|
|
39
|
-
this._processPong(message);
|
|
40
|
-
return;
|
|
41
|
-
case 'authenticate':
|
|
42
|
-
this._connectionManager.connected(message.jwt);
|
|
43
|
-
this._checkSession();
|
|
44
|
-
return;
|
|
45
|
-
case 'location':
|
|
46
|
-
const { path } = message;
|
|
47
|
-
this.location = path;
|
|
48
|
-
return;
|
|
49
|
-
case 'subscribe':
|
|
50
|
-
this.updateSubscription(message);
|
|
51
|
-
return;
|
|
52
|
-
case 'unsubscribe':
|
|
53
|
-
this.removeSubscription(message.target);
|
|
54
|
-
return;
|
|
55
|
-
case 'reload':
|
|
56
|
-
this.reloadData(message.target);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
ping() {
|
|
62
|
-
this.next({ type: 'ping', id: new Date().getTime() });
|
|
63
|
-
setTimeout(() => this.ping(), 60000);
|
|
64
|
-
}
|
|
65
|
-
_processPong(message) {
|
|
66
|
-
const response = new Date().getTime();
|
|
67
|
-
this._ping = response - message.id;
|
|
68
|
-
this._connectionManager.ping(this._ping);
|
|
69
|
-
}
|
|
70
|
-
_checkSession() {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const check = yield this._connectionManager.checkSession();
|
|
73
|
-
if (check)
|
|
74
|
-
this.next(check);
|
|
75
|
-
let refreshIn = (0, lodash_1.get)(check, 'refresh_in', 300000);
|
|
76
|
-
refreshIn = Math.round((refreshIn * 95) / 100);
|
|
77
|
-
clearTimeout(this._timeout);
|
|
78
|
-
this._timeout = setTimeout(() => this._checkSession(), refreshIn);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
removeSubscription(target) {
|
|
82
|
-
var _a, _b;
|
|
83
|
-
(_a = this._subscriptions.get(target)) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
84
|
-
this._subscriptions.delete(target);
|
|
85
|
-
(_b = this._stores.get(target)) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
86
|
-
this._stores.delete(target);
|
|
87
|
-
this.sendDebugTargets('removeSubscription', target);
|
|
88
|
-
}
|
|
89
|
-
reloadData(target) {
|
|
90
|
-
const store = this._stores.get(target);
|
|
91
|
-
store.restartSubscription();
|
|
92
|
-
}
|
|
93
|
-
updateSubscription(subscriptionConfig) {
|
|
94
|
-
const { target, scope, observe, config } = subscriptionConfig;
|
|
95
|
-
let store = this._stores.get(target);
|
|
96
|
-
if (store) {
|
|
97
|
-
store.config = config;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
store = (0, store_factory_1.default)(scope, observe, target);
|
|
101
|
-
this._stores.set(target, store);
|
|
102
|
-
const subscription = store.subscribe({
|
|
103
|
-
next: (m) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
if (data_middleware_map_1.default.hasMiddleware(observe)) {
|
|
105
|
-
const process = data_middleware_map_1.default.getMiddleware(observe);
|
|
106
|
-
m = yield process(m, this._connectionManager.user);
|
|
107
|
-
}
|
|
108
|
-
if (this.isValidTarget(target))
|
|
109
|
-
this.next(m);
|
|
110
|
-
}),
|
|
111
|
-
error: (e) => this.error(e),
|
|
112
|
-
complete: () => this.complete()
|
|
113
|
-
});
|
|
114
|
-
this._subscriptions.set(target, subscription);
|
|
115
|
-
store.config = config;
|
|
116
|
-
}
|
|
117
|
-
this.sendDebugTargets('updateSubscription', target);
|
|
118
|
-
}
|
|
119
|
-
isValidTarget(target) {
|
|
120
|
-
if (!this._stores)
|
|
121
|
-
return false;
|
|
122
|
-
const targets = Array.from(this._stores.keys());
|
|
123
|
-
return (0, lodash_1.includes)(targets, target);
|
|
124
|
-
}
|
|
125
|
-
sendDebugTargets(event, target) {
|
|
126
|
-
if (!this._stores)
|
|
127
|
-
return false;
|
|
128
|
-
const targets = Array.from(this._stores.keys());
|
|
129
|
-
this.next({
|
|
130
|
-
type: 'debug',
|
|
131
|
-
id: new Date().getTime(),
|
|
132
|
-
payload: {
|
|
133
|
-
event,
|
|
134
|
-
target,
|
|
135
|
-
availableTargets: (0, lodash_1.join)(targets, ', ')
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
clearSubscriptions() {
|
|
140
|
-
var _a, _b;
|
|
141
|
-
if (this._subscriptions) {
|
|
142
|
-
const subscriptionsKeys = this._subscriptions.keys();
|
|
143
|
-
console.log(' -- OwservableClient clearSubscriptions subscriptionsKeys:', subscriptionsKeys);
|
|
144
|
-
for (const subscriptionKey of subscriptionsKeys) {
|
|
145
|
-
(_a = this._subscriptions.get(subscriptionKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
146
|
-
}
|
|
147
|
-
this._subscriptions.clear();
|
|
148
|
-
}
|
|
149
|
-
this._subscriptions = null;
|
|
150
|
-
if (this._stores) {
|
|
151
|
-
const storesKeys = this._stores.keys();
|
|
152
|
-
console.log(' -- OwservableClient clearSubscriptions storesKeys:', storesKeys);
|
|
153
|
-
for (const storeKey of storesKeys) {
|
|
154
|
-
(_b = this._stores.get(storeKey)) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
155
|
-
}
|
|
156
|
-
this._stores.clear();
|
|
157
|
-
}
|
|
158
|
-
this._stores = null;
|
|
159
|
-
this.sendDebugTargets('clearSubscriptions', '*');
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.default = OwservableClient;
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const lodash_1 = require("lodash");
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const store_factory_1 = require("./store/factories/store.factory");
|
|
15
|
+
const data_middleware_map_1 = require("./middleware/data.middleware.map");
|
|
16
|
+
class OwservableClient extends rxjs_1.Subject {
|
|
17
|
+
constructor(connectionManager) {
|
|
18
|
+
super();
|
|
19
|
+
this._ping = 0;
|
|
20
|
+
this._connectionManager = connectionManager;
|
|
21
|
+
this._stores = new Map();
|
|
22
|
+
this._subscriptions = new Map();
|
|
23
|
+
}
|
|
24
|
+
disconnected() {
|
|
25
|
+
this.clearSubscriptions();
|
|
26
|
+
this._connectionManager.disconnected();
|
|
27
|
+
clearTimeout(this._timeout);
|
|
28
|
+
}
|
|
29
|
+
set location(location) {
|
|
30
|
+
if (location === this._location)
|
|
31
|
+
return;
|
|
32
|
+
this._location = location;
|
|
33
|
+
this._connectionManager.location(location);
|
|
34
|
+
}
|
|
35
|
+
consume(message) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
switch (message.type) {
|
|
38
|
+
case 'pong':
|
|
39
|
+
this._processPong(message);
|
|
40
|
+
return;
|
|
41
|
+
case 'authenticate':
|
|
42
|
+
this._connectionManager.connected(message.jwt);
|
|
43
|
+
this._checkSession();
|
|
44
|
+
return;
|
|
45
|
+
case 'location':
|
|
46
|
+
const { path } = message;
|
|
47
|
+
this.location = path;
|
|
48
|
+
return;
|
|
49
|
+
case 'subscribe':
|
|
50
|
+
this.updateSubscription(message);
|
|
51
|
+
return;
|
|
52
|
+
case 'unsubscribe':
|
|
53
|
+
this.removeSubscription(message.target);
|
|
54
|
+
return;
|
|
55
|
+
case 'reload':
|
|
56
|
+
this.reloadData(message.target);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
ping() {
|
|
62
|
+
this.next({ type: 'ping', id: new Date().getTime() });
|
|
63
|
+
setTimeout(() => this.ping(), 60000);
|
|
64
|
+
}
|
|
65
|
+
_processPong(message) {
|
|
66
|
+
const response = new Date().getTime();
|
|
67
|
+
this._ping = response - message.id;
|
|
68
|
+
this._connectionManager.ping(this._ping);
|
|
69
|
+
}
|
|
70
|
+
_checkSession() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const check = yield this._connectionManager.checkSession();
|
|
73
|
+
if (check)
|
|
74
|
+
this.next(check);
|
|
75
|
+
let refreshIn = (0, lodash_1.get)(check, 'refresh_in', 300000);
|
|
76
|
+
refreshIn = Math.round((refreshIn * 95) / 100);
|
|
77
|
+
clearTimeout(this._timeout);
|
|
78
|
+
this._timeout = setTimeout(() => this._checkSession(), refreshIn);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
removeSubscription(target) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
(_a = this._subscriptions.get(target)) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
84
|
+
this._subscriptions.delete(target);
|
|
85
|
+
(_b = this._stores.get(target)) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
86
|
+
this._stores.delete(target);
|
|
87
|
+
this.sendDebugTargets('removeSubscription', target);
|
|
88
|
+
}
|
|
89
|
+
reloadData(target) {
|
|
90
|
+
const store = this._stores.get(target);
|
|
91
|
+
store.restartSubscription();
|
|
92
|
+
}
|
|
93
|
+
updateSubscription(subscriptionConfig) {
|
|
94
|
+
const { target, scope, observe, config } = subscriptionConfig;
|
|
95
|
+
let store = this._stores.get(target);
|
|
96
|
+
if (store) {
|
|
97
|
+
store.config = config;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
store = (0, store_factory_1.default)(scope, observe, target);
|
|
101
|
+
this._stores.set(target, store);
|
|
102
|
+
const subscription = store.subscribe({
|
|
103
|
+
next: (m) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (data_middleware_map_1.default.hasMiddleware(observe)) {
|
|
105
|
+
const process = data_middleware_map_1.default.getMiddleware(observe);
|
|
106
|
+
m = yield process(m, this._connectionManager.user);
|
|
107
|
+
}
|
|
108
|
+
if (this.isValidTarget(target))
|
|
109
|
+
this.next(m);
|
|
110
|
+
}),
|
|
111
|
+
error: (e) => this.error(e),
|
|
112
|
+
complete: () => this.complete()
|
|
113
|
+
});
|
|
114
|
+
this._subscriptions.set(target, subscription);
|
|
115
|
+
store.config = config;
|
|
116
|
+
}
|
|
117
|
+
this.sendDebugTargets('updateSubscription', target);
|
|
118
|
+
}
|
|
119
|
+
isValidTarget(target) {
|
|
120
|
+
if (!this._stores)
|
|
121
|
+
return false;
|
|
122
|
+
const targets = Array.from(this._stores.keys());
|
|
123
|
+
return (0, lodash_1.includes)(targets, target);
|
|
124
|
+
}
|
|
125
|
+
sendDebugTargets(event, target) {
|
|
126
|
+
if (!this._stores)
|
|
127
|
+
return false;
|
|
128
|
+
const targets = Array.from(this._stores.keys());
|
|
129
|
+
this.next({
|
|
130
|
+
type: 'debug',
|
|
131
|
+
id: new Date().getTime(),
|
|
132
|
+
payload: {
|
|
133
|
+
event,
|
|
134
|
+
target,
|
|
135
|
+
availableTargets: (0, lodash_1.join)(targets, ', ')
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
clearSubscriptions() {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
if (this._subscriptions) {
|
|
142
|
+
const subscriptionsKeys = this._subscriptions.keys();
|
|
143
|
+
console.log(' -- OwservableClient clearSubscriptions subscriptionsKeys:', subscriptionsKeys);
|
|
144
|
+
for (const subscriptionKey of subscriptionsKeys) {
|
|
145
|
+
(_a = this._subscriptions.get(subscriptionKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
146
|
+
}
|
|
147
|
+
this._subscriptions.clear();
|
|
148
|
+
}
|
|
149
|
+
this._subscriptions = null;
|
|
150
|
+
if (this._stores) {
|
|
151
|
+
const storesKeys = this._stores.keys();
|
|
152
|
+
console.log(' -- OwservableClient clearSubscriptions storesKeys:', storesKeys);
|
|
153
|
+
for (const storeKey of storesKeys) {
|
|
154
|
+
(_b = this._stores.get(storeKey)) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
155
|
+
}
|
|
156
|
+
this._stores.clear();
|
|
157
|
+
}
|
|
158
|
+
this._stores = null;
|
|
159
|
+
this.sendDebugTargets('clearSubscriptions', '*');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.default = OwservableClient;
|
|
163
163
|
//# sourceMappingURL=owservable.client.js.map
|
package/lib/owservable.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import OwservableClient from './owservable.client';
|
|
2
|
-
import EStoreType from './_enums/store.type.enum';
|
|
3
|
-
import ConnectionManagerRefreshType from './_types/connection.manager.refresh.type';
|
|
4
|
-
import CronJobType from './_types/cronjob.type';
|
|
5
|
-
import StoreScopeType from './_types/store.scope.type';
|
|
6
|
-
import StoreSubscriptionConfigType from './_types/store.subscription.config.type';
|
|
7
|
-
import StoreSubscriptionUpdateType from './_types/store.subscription.update.type';
|
|
8
|
-
import SubscriptionMethodsType from './_types/subscription.methods.type';
|
|
9
|
-
import WatcherType from './_types/watcher.type';
|
|
10
|
-
import WorkerType from './_types/worker.type';
|
|
11
|
-
import IConnectionManager from './auth/i.connection.manager';
|
|
12
|
-
import initiateWorkers from './functions/initiate.workers';
|
|
13
|
-
import initiateCronjobs from './functions/initiate.cronjobs';
|
|
14
|
-
import initiateWatchers from './functions/initiate.watchers';
|
|
15
|
-
import addActionCronjobs from './functions/action/add.action.cronjobs';
|
|
16
|
-
import addActionWatchers from './functions/action/add.action.watchers';
|
|
17
|
-
import addActionWorkers from './functions/action/add.action.workers';
|
|
18
|
-
import executeCronjob from './functions/execute/execute.cronjob';
|
|
19
|
-
import executeWatcher from './functions/execute/execute.watcher';
|
|
20
|
-
import executeWorker from './functions/execute/execute.worker';
|
|
21
|
-
import executeProcessesInFolder from './functions/execute/execute.processes.in.folder';
|
|
22
|
-
import executeOnFilesRecursively from './functions/execute/execute.on.files.recursively';
|
|
23
|
-
import DataMiddlewareMap from './middleware/data.middleware.map';
|
|
24
|
-
import MongoDBConnector from './mongodb/mongodb.connector';
|
|
25
|
-
import CollectionsModelsMap from './mongodb/collections.models.map';
|
|
26
|
-
import processModels from './mongodb/functions/process.models';
|
|
27
|
-
import observableModel from './mongodb/functions/observable.model';
|
|
28
|
-
import observableDatabase from './mongodb/functions/observable.database';
|
|
29
|
-
import addIndexToAttributes from './mongodb/functions/index/add.index.to.attributes';
|
|
30
|
-
import addUpIndicesToAttributes from './mongodb/functions/index/add.up.indices.to.attributes';
|
|
31
|
-
import addDownIndicesToAttributes from './mongodb/functions/index/add.down.indices.to.attributes';
|
|
32
|
-
import addBothIndicesToAttributes from './mongodb/functions/index/add.both.indices.to.attributes';
|
|
33
|
-
import addUpAndDownIndicesToAttributes from './mongodb/functions/index/add.up.and.down.indices.to.attributes';
|
|
34
|
-
import AStore from './store/a.store';
|
|
35
|
-
import CountStore from './store/count.store';
|
|
36
|
-
import DocumentStore from './store/document.store';
|
|
37
|
-
import CollectionStore from './store/collection.store';
|
|
38
|
-
import storeFactory from './store/factories/store.factory';
|
|
39
|
-
export { OwservableClient, EStoreType, ConnectionManagerRefreshType, CronJobType, StoreScopeType, StoreSubscriptionConfigType, StoreSubscriptionUpdateType, SubscriptionMethodsType, WatcherType, WorkerType, IConnectionManager, initiateCronjobs, initiateWatchers, initiateWorkers, addActionCronjobs, addActionWatchers, addActionWorkers, executeCronjob, executeWatcher, executeWorker, executeProcessesInFolder, executeOnFilesRecursively, DataMiddlewareMap, MongoDBConnector, CollectionsModelsMap, processModels, observableModel, observableDatabase, addIndexToAttributes, addUpIndicesToAttributes, addDownIndicesToAttributes, addBothIndicesToAttributes, addUpAndDownIndicesToAttributes, AStore, CountStore, DocumentStore, CollectionStore, storeFactory };
|
|
40
|
-
declare const Owservable: {};
|
|
41
|
-
export default Owservable;
|
|
1
|
+
import OwservableClient from './owservable.client';
|
|
2
|
+
import EStoreType from './_enums/store.type.enum';
|
|
3
|
+
import ConnectionManagerRefreshType from './_types/connection.manager.refresh.type';
|
|
4
|
+
import CronJobType from './_types/cronjob.type';
|
|
5
|
+
import StoreScopeType from './_types/store.scope.type';
|
|
6
|
+
import StoreSubscriptionConfigType from './_types/store.subscription.config.type';
|
|
7
|
+
import StoreSubscriptionUpdateType from './_types/store.subscription.update.type';
|
|
8
|
+
import SubscriptionMethodsType from './_types/subscription.methods.type';
|
|
9
|
+
import WatcherType from './_types/watcher.type';
|
|
10
|
+
import WorkerType from './_types/worker.type';
|
|
11
|
+
import IConnectionManager from './auth/i.connection.manager';
|
|
12
|
+
import initiateWorkers from './functions/initiate.workers';
|
|
13
|
+
import initiateCronjobs from './functions/initiate.cronjobs';
|
|
14
|
+
import initiateWatchers from './functions/initiate.watchers';
|
|
15
|
+
import addActionCronjobs from './functions/action/add.action.cronjobs';
|
|
16
|
+
import addActionWatchers from './functions/action/add.action.watchers';
|
|
17
|
+
import addActionWorkers from './functions/action/add.action.workers';
|
|
18
|
+
import executeCronjob from './functions/execute/execute.cronjob';
|
|
19
|
+
import executeWatcher from './functions/execute/execute.watcher';
|
|
20
|
+
import executeWorker from './functions/execute/execute.worker';
|
|
21
|
+
import executeProcessesInFolder from './functions/execute/execute.processes.in.folder';
|
|
22
|
+
import executeOnFilesRecursively from './functions/execute/execute.on.files.recursively';
|
|
23
|
+
import DataMiddlewareMap from './middleware/data.middleware.map';
|
|
24
|
+
import MongoDBConnector from './mongodb/mongodb.connector';
|
|
25
|
+
import CollectionsModelsMap from './mongodb/collections.models.map';
|
|
26
|
+
import processModels from './mongodb/functions/process.models';
|
|
27
|
+
import observableModel from './mongodb/functions/observable.model';
|
|
28
|
+
import observableDatabase from './mongodb/functions/observable.database';
|
|
29
|
+
import addIndexToAttributes from './mongodb/functions/index/add.index.to.attributes';
|
|
30
|
+
import addUpIndicesToAttributes from './mongodb/functions/index/add.up.indices.to.attributes';
|
|
31
|
+
import addDownIndicesToAttributes from './mongodb/functions/index/add.down.indices.to.attributes';
|
|
32
|
+
import addBothIndicesToAttributes from './mongodb/functions/index/add.both.indices.to.attributes';
|
|
33
|
+
import addUpAndDownIndicesToAttributes from './mongodb/functions/index/add.up.and.down.indices.to.attributes';
|
|
34
|
+
import AStore from './store/a.store';
|
|
35
|
+
import CountStore from './store/count.store';
|
|
36
|
+
import DocumentStore from './store/document.store';
|
|
37
|
+
import CollectionStore from './store/collection.store';
|
|
38
|
+
import storeFactory from './store/factories/store.factory';
|
|
39
|
+
export { OwservableClient, EStoreType, ConnectionManagerRefreshType, CronJobType, StoreScopeType, StoreSubscriptionConfigType, StoreSubscriptionUpdateType, SubscriptionMethodsType, WatcherType, WorkerType, IConnectionManager, initiateCronjobs, initiateWatchers, initiateWorkers, addActionCronjobs, addActionWatchers, addActionWorkers, executeCronjob, executeWatcher, executeWorker, executeProcessesInFolder, executeOnFilesRecursively, DataMiddlewareMap, MongoDBConnector, CollectionsModelsMap, processModels, observableModel, observableDatabase, addIndexToAttributes, addUpIndicesToAttributes, addDownIndicesToAttributes, addBothIndicesToAttributes, addUpAndDownIndicesToAttributes, AStore, CountStore, DocumentStore, CollectionStore, storeFactory };
|
|
40
|
+
declare const Owservable: {};
|
|
41
|
+
export default Owservable;
|