@hcikn/colibri 1.0.4 → 1.2.0
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/README.md +45 -6
- package/dist/index.cjs +567 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +116 -7
- package/dist/index.d.ts +116 -7
- package/dist/index.js +545 -90
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,41 @@ function _array_like_to_array(arr, len) {
|
|
|
7
7
|
function _array_without_holes(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
9
9
|
}
|
|
10
|
+
function _assert_this_initialized(self) {
|
|
11
|
+
if (self === void 0) {
|
|
12
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
13
|
+
}
|
|
14
|
+
return self;
|
|
15
|
+
}
|
|
16
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
17
|
+
try {
|
|
18
|
+
var info = gen[key](arg);
|
|
19
|
+
var value = info.value;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
reject(error);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (info.done) {
|
|
25
|
+
resolve(value);
|
|
26
|
+
} else {
|
|
27
|
+
Promise.resolve(value).then(_next, _throw);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function _async_to_generator(fn) {
|
|
31
|
+
return function() {
|
|
32
|
+
var self = this, args = arguments;
|
|
33
|
+
return new Promise(function(resolve, reject) {
|
|
34
|
+
var gen = fn.apply(self, args);
|
|
35
|
+
function _next(value) {
|
|
36
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
37
|
+
}
|
|
38
|
+
function _throw(err) {
|
|
39
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
40
|
+
}
|
|
41
|
+
_next(undefined);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
10
45
|
function _class_call_check(instance, Constructor) {
|
|
11
46
|
if (!(instance instanceof Constructor)) {
|
|
12
47
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -26,6 +61,25 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
26
61
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
27
62
|
return Constructor;
|
|
28
63
|
}
|
|
64
|
+
function _get_prototype_of(o) {
|
|
65
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
66
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
67
|
+
};
|
|
68
|
+
return _get_prototype_of(o);
|
|
69
|
+
}
|
|
70
|
+
function _inherits(subClass, superClass) {
|
|
71
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
72
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
73
|
+
}
|
|
74
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
75
|
+
constructor: {
|
|
76
|
+
value: subClass,
|
|
77
|
+
writable: true,
|
|
78
|
+
configurable: true
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
82
|
+
}
|
|
29
83
|
function _instanceof(left, right) {
|
|
30
84
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
31
85
|
return !!right[Symbol.hasInstance](left);
|
|
@@ -39,9 +93,26 @@ function _iterable_to_array(iter) {
|
|
|
39
93
|
function _non_iterable_spread() {
|
|
40
94
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
41
95
|
}
|
|
96
|
+
function _possible_constructor_return(self, call) {
|
|
97
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
98
|
+
return call;
|
|
99
|
+
}
|
|
100
|
+
return _assert_this_initialized(self);
|
|
101
|
+
}
|
|
102
|
+
function _set_prototype_of(o, p) {
|
|
103
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
104
|
+
o.__proto__ = p;
|
|
105
|
+
return o;
|
|
106
|
+
};
|
|
107
|
+
return _set_prototype_of(o, p);
|
|
108
|
+
}
|
|
42
109
|
function _to_consumable_array(arr) {
|
|
43
110
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
44
111
|
}
|
|
112
|
+
function _type_of(obj) {
|
|
113
|
+
"@swc/helpers - typeof";
|
|
114
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
115
|
+
}
|
|
45
116
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
46
117
|
if (!o) return;
|
|
47
118
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -50,11 +121,128 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
50
121
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
51
122
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
52
123
|
}
|
|
53
|
-
|
|
124
|
+
function _is_native_reflect_construct() {
|
|
125
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
126
|
+
if (Reflect.construct.sham) return false;
|
|
127
|
+
if (typeof Proxy === "function") return true;
|
|
128
|
+
try {
|
|
129
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
130
|
+
return true;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function _create_super(Derived) {
|
|
136
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
137
|
+
return function _createSuperInternal() {
|
|
138
|
+
var Super = _get_prototype_of(Derived), result;
|
|
139
|
+
if (hasNativeReflectConstruct) {
|
|
140
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
|
141
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
142
|
+
} else {
|
|
143
|
+
result = Super.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
return _possible_constructor_return(this, result);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function _ts_generator(thisArg, body) {
|
|
149
|
+
var f, y, t, g, _ = {
|
|
150
|
+
label: 0,
|
|
151
|
+
sent: function() {
|
|
152
|
+
if (t[0] & 1) throw t[1];
|
|
153
|
+
return t[1];
|
|
154
|
+
},
|
|
155
|
+
trys: [],
|
|
156
|
+
ops: []
|
|
157
|
+
};
|
|
158
|
+
return g = {
|
|
159
|
+
next: verb(0),
|
|
160
|
+
"throw": verb(1),
|
|
161
|
+
"return": verb(2)
|
|
162
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
163
|
+
return this;
|
|
164
|
+
}), g;
|
|
165
|
+
function verb(n) {
|
|
166
|
+
return function(v) {
|
|
167
|
+
return step([
|
|
168
|
+
n,
|
|
169
|
+
v
|
|
170
|
+
]);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function step(op) {
|
|
174
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
175
|
+
while(_)try {
|
|
176
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
177
|
+
if (y = 0, t) op = [
|
|
178
|
+
op[0] & 2,
|
|
179
|
+
t.value
|
|
180
|
+
];
|
|
181
|
+
switch(op[0]){
|
|
182
|
+
case 0:
|
|
183
|
+
case 1:
|
|
184
|
+
t = op;
|
|
185
|
+
break;
|
|
186
|
+
case 4:
|
|
187
|
+
_.label++;
|
|
188
|
+
return {
|
|
189
|
+
value: op[1],
|
|
190
|
+
done: false
|
|
191
|
+
};
|
|
192
|
+
case 5:
|
|
193
|
+
_.label++;
|
|
194
|
+
y = op[1];
|
|
195
|
+
op = [
|
|
196
|
+
0
|
|
197
|
+
];
|
|
198
|
+
continue;
|
|
199
|
+
case 7:
|
|
200
|
+
op = _.ops.pop();
|
|
201
|
+
_.trys.pop();
|
|
202
|
+
continue;
|
|
203
|
+
default:
|
|
204
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
205
|
+
_ = 0;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
209
|
+
_.label = op[1];
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
213
|
+
_.label = t[1];
|
|
214
|
+
t = op;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (t && _.label < t[2]) {
|
|
218
|
+
_.label = t[2];
|
|
219
|
+
_.ops.push(op);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (t[2]) _.ops.pop();
|
|
223
|
+
_.trys.pop();
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
op = body.call(thisArg, _);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
op = [
|
|
229
|
+
6,
|
|
230
|
+
e
|
|
231
|
+
];
|
|
232
|
+
y = 0;
|
|
233
|
+
} finally{
|
|
234
|
+
f = t = 0;
|
|
235
|
+
}
|
|
236
|
+
if (op[0] & 5) throw op[1];
|
|
237
|
+
return {
|
|
238
|
+
value: op[0] ? op[1] : void 0,
|
|
239
|
+
done: true
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
54
243
|
var __defProp = Object.defineProperty;
|
|
55
244
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
56
245
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
57
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
58
246
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
59
247
|
var __export = function(target, all) {
|
|
60
248
|
for(var name in all)__defProp(target, name, {
|
|
@@ -93,16 +281,6 @@ var __copyProps = function(to, from, except, desc) {
|
|
|
93
281
|
}
|
|
94
282
|
return to;
|
|
95
283
|
};
|
|
96
|
-
var __toESM = function(mod, isNodeMode, target) {
|
|
97
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
98
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
99
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
100
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
101
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
102
|
-
value: mod,
|
|
103
|
-
enumerable: true
|
|
104
|
-
}) : target, mod);
|
|
105
|
-
};
|
|
106
284
|
var __toCommonJS = function(mod) {
|
|
107
285
|
return __copyProps(__defProp({}, "__esModule", {
|
|
108
286
|
value: true
|
|
@@ -114,12 +292,27 @@ __export(src_exports, {
|
|
|
114
292
|
Colibri: function() {
|
|
115
293
|
return Colibri;
|
|
116
294
|
},
|
|
295
|
+
GetRestApi: function() {
|
|
296
|
+
return GetRestApi;
|
|
297
|
+
},
|
|
298
|
+
PutRestApi: function() {
|
|
299
|
+
return PutRestApi;
|
|
300
|
+
},
|
|
301
|
+
RegisterChannel: function() {
|
|
302
|
+
return RegisterChannel;
|
|
303
|
+
},
|
|
117
304
|
RegisterModelSync: function() {
|
|
118
305
|
return RegisterModelSync;
|
|
119
306
|
},
|
|
307
|
+
RegisterOnce: function() {
|
|
308
|
+
return RegisterOnce;
|
|
309
|
+
},
|
|
120
310
|
RemoteLogger: function() {
|
|
121
311
|
return RemoteLogger;
|
|
122
312
|
},
|
|
313
|
+
SendMessage: function() {
|
|
314
|
+
return SendMessage;
|
|
315
|
+
},
|
|
123
316
|
Sync: function() {
|
|
124
317
|
return Sync;
|
|
125
318
|
},
|
|
@@ -128,57 +321,278 @@ __export(src_exports, {
|
|
|
128
321
|
},
|
|
129
322
|
Synced: function() {
|
|
130
323
|
return Synced;
|
|
324
|
+
},
|
|
325
|
+
UnregisterChannel: function() {
|
|
326
|
+
return UnregisterChannel;
|
|
131
327
|
}
|
|
132
328
|
});
|
|
133
329
|
module.exports = __toCommonJS(src_exports);
|
|
134
|
-
// src/
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
var
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
autoConnect: false
|
|
145
|
-
});
|
|
146
|
-
var init = function(app, server) {
|
|
147
|
-
server !== null && server !== void 0 ? server : server = location;
|
|
148
|
-
if (!server.startsWith("http")) {
|
|
149
|
-
server = "http://" + server;
|
|
330
|
+
// src/Colibri.ts
|
|
331
|
+
var import_socket = require("socket.io-client");
|
|
332
|
+
// src/ColibriError.ts
|
|
333
|
+
var import_ts_custom_error = require("ts-custom-error");
|
|
334
|
+
var ColibriError = /*#__PURE__*/ function(_import_ts_custom_error_CustomError) {
|
|
335
|
+
_inherits(ColibriError, _import_ts_custom_error_CustomError);
|
|
336
|
+
var _super = _create_super(ColibriError);
|
|
337
|
+
function ColibriError(message) {
|
|
338
|
+
_class_call_check(this, ColibriError);
|
|
339
|
+
return _super.call(this, message);
|
|
150
340
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
341
|
+
return ColibriError;
|
|
342
|
+
}(import_ts_custom_error.CustomError);
|
|
343
|
+
// src/Colibri.ts
|
|
344
|
+
var import_rxjs = require("rxjs");
|
|
345
|
+
var _window_location_hostname;
|
|
346
|
+
var _Colibri = /*#__PURE__*/ function() {
|
|
347
|
+
function _Colibri(app) {
|
|
348
|
+
var server = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {
|
|
349
|
+
var _window_location, _window;
|
|
350
|
+
return (_window_location_hostname = (_window = window) === null || _window === void 0 ? void 0 : (_window_location = _window.location) === null || _window_location === void 0 ? void 0 : _window_location.hostname) !== null && _window_location_hostname !== void 0 ? _window_location_hostname : "";
|
|
351
|
+
}(), port = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 9011;
|
|
352
|
+
_class_call_check(this, _Colibri);
|
|
353
|
+
this.app = app;
|
|
354
|
+
this.server = server;
|
|
355
|
+
this.port = port;
|
|
356
|
+
this.messageSubject = new import_rxjs.Subject();
|
|
357
|
+
this.messages = this.messageSubject.asObservable();
|
|
358
|
+
if (server.trim().length <= 0) {
|
|
359
|
+
throw new ColibriError("Server Address missing or empty!");
|
|
360
|
+
}
|
|
361
|
+
if (port < 1 || port > 65535) {
|
|
362
|
+
throw new ColibriError("Port out of allowed range (0 - 65535)");
|
|
363
|
+
}
|
|
364
|
+
this.uri = "".concat(server, ":").concat(port);
|
|
365
|
+
if (!new RegExp("wss?://", "i").test(this.uri)) {
|
|
366
|
+
this.uri = "ws://".concat(this.uri);
|
|
367
|
+
}
|
|
368
|
+
this.uriRestApi = "".concat(this.uri, "/api/store/").concat(app, "/");
|
|
369
|
+
if (_Colibri.instance) throw new ColibriError("A Colibri instance already exists!");
|
|
370
|
+
else _Colibri.instance = this;
|
|
371
|
+
this.socket = (0, import_socket.connect)(this.uri, {
|
|
372
|
+
query: {
|
|
373
|
+
app: app,
|
|
374
|
+
version: "1"
|
|
375
|
+
},
|
|
376
|
+
transports: [
|
|
377
|
+
"websocket"
|
|
378
|
+
]
|
|
167
379
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
380
|
+
this.socket.on("connect", this.onSocketConnect.bind(this));
|
|
381
|
+
this.socket.onAny(this.onSocketAny.bind(this));
|
|
382
|
+
this.registerChannel("colibri", function(msg) {
|
|
383
|
+
if (msg.command === "latency") {
|
|
384
|
+
SendMessage("colibri", "latency", msg.payload);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
_create_class(_Colibri, [
|
|
389
|
+
{
|
|
390
|
+
key: "onSocketConnect",
|
|
391
|
+
value: function onSocketConnect() {
|
|
392
|
+
console.debug("Connected to colibri server on ".concat(this.server));
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
397
|
+
key: "onSocketAny",
|
|
398
|
+
value: function onSocketAny(channel, msg) {
|
|
399
|
+
this.messageSubject.next({
|
|
400
|
+
channel: channel,
|
|
401
|
+
command: msg.command,
|
|
402
|
+
payload: msg.payload
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
/**
|
|
408
|
+
* Sends a single message in the given `channel`.
|
|
409
|
+
* @param channel message channel
|
|
410
|
+
* @param command message command
|
|
411
|
+
* @param payload message payload
|
|
412
|
+
*/ key: "sendMessage",
|
|
413
|
+
value: function sendMessage(channel, command) {
|
|
414
|
+
var payload = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
415
|
+
this.socket.emit(channel, {
|
|
416
|
+
command: command,
|
|
417
|
+
payload: payload
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
//#region Socket Events
|
|
423
|
+
/**
|
|
424
|
+
* Adds a `handler` function listening for messages in `channel`.
|
|
425
|
+
* @param channel message channel
|
|
426
|
+
* @param handler handler to be executed when a message is received
|
|
427
|
+
*/ key: "registerChannel",
|
|
428
|
+
value: function registerChannel(channel, handler) {
|
|
429
|
+
this.socket.on(channel, handler);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
/**
|
|
434
|
+
* Removes the `handler` function listening for messages in `channel`.
|
|
435
|
+
* @param channel message channel
|
|
436
|
+
* @param handler handler to be executed when a message is received
|
|
437
|
+
*/ key: "unregisterChannel",
|
|
438
|
+
value: function unregisterChannel(channel, handler) {
|
|
439
|
+
this.socket.off(channel, handler);
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
/**
|
|
444
|
+
* Adds a one-time `handler` function listening for the next message in `channel`.
|
|
445
|
+
* @param channel message channel
|
|
446
|
+
* @param handler handler to be executed when a message is received
|
|
447
|
+
*/ key: "registerOnce",
|
|
448
|
+
value: function registerOnce(channel, handler) {
|
|
449
|
+
this.socket.once(channel, handler);
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region Rest API
|
|
455
|
+
/**
|
|
456
|
+
* Returns the REST API Endpoint for a given `key` or null of the key is empty.
|
|
457
|
+
* @param key REST API storage key
|
|
458
|
+
* @returns
|
|
459
|
+
*/ key: "getRestUri",
|
|
460
|
+
value: function getRestUri(key) {
|
|
461
|
+
key = key.trim();
|
|
462
|
+
while(key.startsWith("/"))key = key.substring(1);
|
|
463
|
+
return key.length === 0 ? null : this.uriRestApi + key;
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
key: "getRestObject",
|
|
468
|
+
value: /**
|
|
469
|
+
* Queries an object from the REST API identified by `key`.
|
|
470
|
+
* @param key REST API storage key
|
|
471
|
+
* @returns JSON object with data or null if object does not exist or any other error occurrs
|
|
472
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
473
|
+
function getRestObject(key) {
|
|
474
|
+
var _this = this;
|
|
475
|
+
return _async_to_generator(function() {
|
|
476
|
+
var uri, response;
|
|
477
|
+
return _ts_generator(this, function(_state) {
|
|
478
|
+
switch(_state.label){
|
|
479
|
+
case 0:
|
|
480
|
+
uri = _this.getRestUri(key);
|
|
481
|
+
if (!uri) return [
|
|
482
|
+
2,
|
|
483
|
+
null
|
|
484
|
+
];
|
|
485
|
+
return [
|
|
486
|
+
4,
|
|
487
|
+
fetch(uri, {
|
|
488
|
+
method: "GET",
|
|
489
|
+
headers: {
|
|
490
|
+
"Content-Type": "application/json"
|
|
491
|
+
}
|
|
492
|
+
})
|
|
493
|
+
];
|
|
494
|
+
case 1:
|
|
495
|
+
response = _state.sent();
|
|
496
|
+
if (response.status >= 400) return [
|
|
497
|
+
2,
|
|
498
|
+
null
|
|
499
|
+
];
|
|
500
|
+
else return [
|
|
501
|
+
2,
|
|
502
|
+
response.json()
|
|
503
|
+
];
|
|
504
|
+
return [
|
|
505
|
+
2
|
|
506
|
+
];
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
})();
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
key: "setRestObject",
|
|
514
|
+
value: /**
|
|
515
|
+
* Sets or updatees an object in the REST API identified by `key`.
|
|
516
|
+
* @param key REST API storage key
|
|
517
|
+
* @param data JSON data to write
|
|
518
|
+
* @returns true if data was written to REST API
|
|
519
|
+
*/ function setRestObject(key, data) {
|
|
520
|
+
var _this = this;
|
|
521
|
+
return _async_to_generator(function() {
|
|
522
|
+
var uri, response;
|
|
523
|
+
return _ts_generator(this, function(_state) {
|
|
524
|
+
switch(_state.label){
|
|
525
|
+
case 0:
|
|
526
|
+
uri = _this.getRestUri(key);
|
|
527
|
+
if (!uri) return [
|
|
528
|
+
2,
|
|
529
|
+
false
|
|
530
|
+
];
|
|
531
|
+
return [
|
|
532
|
+
4,
|
|
533
|
+
fetch(uri, {
|
|
534
|
+
method: "PUT",
|
|
535
|
+
headers: {
|
|
536
|
+
"Content-Type": "application/json"
|
|
537
|
+
},
|
|
538
|
+
body: JSON.stringify(data)
|
|
539
|
+
})
|
|
540
|
+
];
|
|
541
|
+
case 1:
|
|
542
|
+
response = _state.sent();
|
|
543
|
+
return [
|
|
544
|
+
2,
|
|
545
|
+
response.status >= 200 && response.status < 300
|
|
546
|
+
];
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
})();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
], [
|
|
553
|
+
{
|
|
554
|
+
key: "getInstance",
|
|
555
|
+
value: /**
|
|
556
|
+
* Returns the existing Colibri instance or null if there's none yet
|
|
557
|
+
* @param warnIfNotInitialized true => print Log message if Colibri has not been initialized yet
|
|
558
|
+
* @returns
|
|
559
|
+
*/ function getInstance() {
|
|
560
|
+
var warnIfNotInitialized = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
561
|
+
if (warnIfNotInitialized && !_Colibri.instance) {
|
|
562
|
+
console.warn("Colibri not initialized yet! (Instance is null)");
|
|
563
|
+
}
|
|
564
|
+
return _Colibri.instance;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
]);
|
|
568
|
+
return _Colibri;
|
|
569
|
+
}();
|
|
570
|
+
_Colibri.instance = null;
|
|
571
|
+
var Colibri = _Colibri;
|
|
173
572
|
var SendMessage = function(channel, command) {
|
|
174
573
|
var payload = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
payload: payload
|
|
178
|
-
});
|
|
574
|
+
var _Colibri_getInstance;
|
|
575
|
+
return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.sendMessage(channel, command, payload);
|
|
179
576
|
};
|
|
180
577
|
var RegisterChannel = function(channel, handler) {
|
|
181
|
-
|
|
578
|
+
var _Colibri_getInstance;
|
|
579
|
+
return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.registerChannel(channel, handler);
|
|
580
|
+
};
|
|
581
|
+
var UnregisterChannel = function(channel, handler) {
|
|
582
|
+
var _Colibri_getInstance;
|
|
583
|
+
return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.unregisterChannel(channel, handler);
|
|
584
|
+
};
|
|
585
|
+
var RegisterOnce = function(channel, handler) {
|
|
586
|
+
var _Colibri_getInstance;
|
|
587
|
+
return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.registerOnce(channel, handler);
|
|
588
|
+
};
|
|
589
|
+
var GetRestApi = function(key) {
|
|
590
|
+
var _Colibri_getInstance;
|
|
591
|
+
return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.getRestObject(key);
|
|
592
|
+
};
|
|
593
|
+
var PutRestApi = function(key, data) {
|
|
594
|
+
var _Colibri_getInstance;
|
|
595
|
+
return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.setRestObject(key, data);
|
|
182
596
|
};
|
|
183
597
|
// src/Broadcasting.ts
|
|
184
598
|
var sendBool = function(channel, val) {
|
|
@@ -319,58 +733,102 @@ var Sync = {
|
|
|
319
733
|
sendIntArray: sendNumberArray
|
|
320
734
|
};
|
|
321
735
|
// src/RemoteLogger.ts
|
|
322
|
-
var
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
736
|
+
var RemoteLogger = /*#__PURE__*/ function() {
|
|
737
|
+
function _RemoteLogger() {
|
|
738
|
+
var enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
739
|
+
var _this = this;
|
|
740
|
+
_class_call_check(this, _RemoteLogger);
|
|
741
|
+
this.enabled = enabled;
|
|
742
|
+
this.consoleDebug = console.debug;
|
|
743
|
+
this.consoleLog = console.log;
|
|
744
|
+
this.consoleInfo = console.info;
|
|
745
|
+
this.consoleWarn = console.warn;
|
|
746
|
+
this.consoleError = console.error;
|
|
747
|
+
console.debug = function() {
|
|
748
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
749
|
+
args[_key] = arguments[_key];
|
|
750
|
+
}
|
|
751
|
+
_this.consoleDebug.apply(_this, _to_consumable_array(args));
|
|
752
|
+
_this.sendMessage("debug", args);
|
|
753
|
+
};
|
|
754
|
+
console.log = function() {
|
|
755
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
756
|
+
args[_key] = arguments[_key];
|
|
757
|
+
}
|
|
758
|
+
_this.consoleLog.apply(_this, _to_consumable_array(args));
|
|
759
|
+
_this.sendMessage("info", args);
|
|
760
|
+
};
|
|
761
|
+
console.info = function() {
|
|
762
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
763
|
+
args[_key] = arguments[_key];
|
|
764
|
+
}
|
|
765
|
+
_this.consoleInfo.apply(_this, _to_consumable_array(args));
|
|
766
|
+
_this.sendMessage("info", args);
|
|
767
|
+
};
|
|
768
|
+
console.warn = function() {
|
|
769
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
770
|
+
args[_key] = arguments[_key];
|
|
771
|
+
}
|
|
772
|
+
_this.consoleWarn.apply(_this, _to_consumable_array(args));
|
|
773
|
+
_this.sendMessage("warn", args);
|
|
774
|
+
};
|
|
775
|
+
console.error = function() {
|
|
776
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
777
|
+
args[_key] = arguments[_key];
|
|
778
|
+
}
|
|
779
|
+
_this.consoleError.apply(_this, _to_consumable_array(args));
|
|
780
|
+
_this.sendMessage("error", args);
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
_create_class(_RemoteLogger, [
|
|
784
|
+
{
|
|
785
|
+
key: "sendMessage",
|
|
786
|
+
value: function sendMessage(level, args) {
|
|
787
|
+
if (!this.enabled) return;
|
|
788
|
+
SendMessage("log", level, _to_consumable_array(args).map(stringify).join().trim());
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
key: "enable",
|
|
793
|
+
value: function enable() {
|
|
794
|
+
this.enabled = true;
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
key: "disable",
|
|
799
|
+
value: function disable() {
|
|
800
|
+
this.enabled = false;
|
|
338
801
|
}
|
|
339
|
-
return value;
|
|
340
|
-
}, 2);
|
|
341
|
-
return str;
|
|
342
|
-
};
|
|
343
|
-
console.debug = function init2() {
|
|
344
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
345
|
-
args[_key] = arguments[_key];
|
|
346
|
-
}
|
|
347
|
-
consoleDebug.apply(this, Array.prototype.slice.call(args));
|
|
348
|
-
SendMessage("log", "debug", _to_consumable_array(args).map(stringify).join().trim());
|
|
349
|
-
};
|
|
350
|
-
console.log = function() {
|
|
351
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
352
|
-
args[_key] = arguments[_key];
|
|
353
802
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
803
|
+
], [
|
|
804
|
+
{
|
|
805
|
+
key: "init",
|
|
806
|
+
value: /**
|
|
807
|
+
* @deprecated use new class constructor directly
|
|
808
|
+
*/ function init() {
|
|
809
|
+
var enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
810
|
+
return new _RemoteLogger(enabled);
|
|
811
|
+
}
|
|
360
812
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
813
|
+
]);
|
|
814
|
+
return _RemoteLogger;
|
|
815
|
+
}();
|
|
816
|
+
var stringify = function(obj) {
|
|
817
|
+
if (_instanceof(obj, Error)) {
|
|
818
|
+
return obj.message + "\n" + obj.stack;
|
|
819
|
+
}
|
|
820
|
+
if (typeof obj === "string") return obj;
|
|
821
|
+
var cache = [];
|
|
822
|
+
var str = JSON.stringify(obj, function(_, value) {
|
|
823
|
+
if (typeof value === "object" && value !== null) {
|
|
824
|
+
if (cache.indexOf(value) !== -1) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
cache.push(value);
|
|
367
828
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
};
|
|
372
|
-
var RemoteLogger = {
|
|
373
|
-
init: init2
|
|
829
|
+
return value;
|
|
830
|
+
}, 2);
|
|
831
|
+
return str;
|
|
374
832
|
};
|
|
375
833
|
// src/ModelSynchronization.ts
|
|
376
834
|
var import_rxjs2 = require("rxjs");
|
|
@@ -599,10 +1057,16 @@ var Synced = function() {
|
|
|
599
1057
|
// Annotate the CommonJS export names for ESM import in node:
|
|
600
1058
|
0 && (module.exports = {
|
|
601
1059
|
Colibri: Colibri,
|
|
1060
|
+
GetRestApi: GetRestApi,
|
|
1061
|
+
PutRestApi: PutRestApi,
|
|
1062
|
+
RegisterChannel: RegisterChannel,
|
|
602
1063
|
RegisterModelSync: RegisterModelSync,
|
|
1064
|
+
RegisterOnce: RegisterOnce,
|
|
603
1065
|
RemoteLogger: RemoteLogger,
|
|
1066
|
+
SendMessage: SendMessage,
|
|
604
1067
|
Sync: Sync,
|
|
605
1068
|
SyncModel: SyncModel,
|
|
606
|
-
Synced: Synced
|
|
1069
|
+
Synced: Synced,
|
|
1070
|
+
UnregisterChannel: UnregisterChannel
|
|
607
1071
|
});
|
|
608
1072
|
//# sourceMappingURL=index.cjs.map
|