@cutos/core 0.0.7 → 0.0.9
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/dist/cutos.cjs.js +76 -328
- package/dist/cutos.esm.js +55 -11
- package/package.json +2 -1
package/dist/cutos.cjs.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var crypto = require('crypto');
|
|
5
6
|
var require$$1 = require('mqtt');
|
|
7
|
+
var require$$2 = require('lodash');
|
|
6
8
|
var require$$0$1 = require('qs');
|
|
7
9
|
|
|
8
10
|
function getAugmentedNamespace(n) {
|
|
@@ -32,23 +34,16 @@ function getAugmentedNamespace(n) {
|
|
|
32
34
|
|
|
33
35
|
var cutos = {};
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
37
|
-
// generators (like Math.random()).
|
|
38
|
-
let getRandomValues;
|
|
39
|
-
const rnds8 = new Uint8Array(16);
|
|
40
|
-
function rng() {
|
|
41
|
-
// lazy load so that environments that need to polyfill have a chance to do so
|
|
42
|
-
if (!getRandomValues) {
|
|
43
|
-
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
44
|
-
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
37
|
+
const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
let poolPtr = rnds8Pool.length;
|
|
40
|
+
function rng() {
|
|
41
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
42
|
+
crypto.randomFillSync(rnds8Pool);
|
|
43
|
+
poolPtr = 0;
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
return
|
|
46
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
@@ -276,226 +271,21 @@ function v35(name, version, hashfunc) {
|
|
|
276
271
|
return generateUUID;
|
|
277
272
|
}
|
|
278
273
|
|
|
279
|
-
/*
|
|
280
|
-
* Browser-compatible JavaScript MD5
|
|
281
|
-
*
|
|
282
|
-
* Modification of JavaScript MD5
|
|
283
|
-
* https://github.com/blueimp/JavaScript-MD5
|
|
284
|
-
*
|
|
285
|
-
* Copyright 2011, Sebastian Tschan
|
|
286
|
-
* https://blueimp.net
|
|
287
|
-
*
|
|
288
|
-
* Licensed under the MIT license:
|
|
289
|
-
* https://opensource.org/licenses/MIT
|
|
290
|
-
*
|
|
291
|
-
* Based on
|
|
292
|
-
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
|
293
|
-
* Digest Algorithm, as defined in RFC 1321.
|
|
294
|
-
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
|
295
|
-
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
|
296
|
-
* Distributed under the BSD License
|
|
297
|
-
* See http://pajhome.org.uk/crypt/md5 for more info.
|
|
298
|
-
*/
|
|
299
274
|
function md5(bytes) {
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
bytes =
|
|
304
|
-
|
|
305
|
-
for (let i = 0; i < msg.length; ++i) {
|
|
306
|
-
bytes[i] = msg.charCodeAt(i);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
|
|
311
|
-
}
|
|
312
|
-
/*
|
|
313
|
-
* Convert an array of little-endian words to an array of bytes
|
|
314
|
-
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
function md5ToHexEncodedArray(input) {
|
|
318
|
-
const output = [];
|
|
319
|
-
const length32 = input.length * 32;
|
|
320
|
-
const hexTab = '0123456789abcdef';
|
|
321
|
-
|
|
322
|
-
for (let i = 0; i < length32; i += 8) {
|
|
323
|
-
const x = input[i >> 5] >>> i % 32 & 0xff;
|
|
324
|
-
const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
|
|
325
|
-
output.push(hex);
|
|
275
|
+
if (Array.isArray(bytes)) {
|
|
276
|
+
bytes = Buffer.from(bytes);
|
|
277
|
+
} else if (typeof bytes === 'string') {
|
|
278
|
+
bytes = Buffer.from(bytes, 'utf8');
|
|
326
279
|
}
|
|
327
280
|
|
|
328
|
-
return
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Calculate output length with padding and bit length
|
|
332
|
-
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
function getOutputLength(inputLength8) {
|
|
336
|
-
return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
|
|
337
|
-
}
|
|
338
|
-
/*
|
|
339
|
-
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
function wordsToMd5(x, len) {
|
|
344
|
-
/* append padding */
|
|
345
|
-
x[len >> 5] |= 0x80 << len % 32;
|
|
346
|
-
x[getOutputLength(len) - 1] = len;
|
|
347
|
-
let a = 1732584193;
|
|
348
|
-
let b = -271733879;
|
|
349
|
-
let c = -1732584194;
|
|
350
|
-
let d = 271733878;
|
|
351
|
-
|
|
352
|
-
for (let i = 0; i < x.length; i += 16) {
|
|
353
|
-
const olda = a;
|
|
354
|
-
const oldb = b;
|
|
355
|
-
const oldc = c;
|
|
356
|
-
const oldd = d;
|
|
357
|
-
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
358
|
-
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
359
|
-
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
360
|
-
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
361
|
-
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
362
|
-
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
363
|
-
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
364
|
-
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
365
|
-
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
366
|
-
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
367
|
-
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
368
|
-
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
369
|
-
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
370
|
-
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
371
|
-
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
372
|
-
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
373
|
-
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
374
|
-
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
375
|
-
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
376
|
-
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
377
|
-
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
378
|
-
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
379
|
-
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
380
|
-
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
381
|
-
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
382
|
-
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
383
|
-
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
384
|
-
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
385
|
-
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
386
|
-
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
387
|
-
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
388
|
-
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
389
|
-
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
390
|
-
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
391
|
-
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
392
|
-
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
393
|
-
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
394
|
-
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
395
|
-
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
396
|
-
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
397
|
-
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
398
|
-
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
399
|
-
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
400
|
-
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
401
|
-
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
402
|
-
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
403
|
-
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
404
|
-
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
405
|
-
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
406
|
-
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
407
|
-
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
408
|
-
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
409
|
-
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
410
|
-
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
411
|
-
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
412
|
-
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
413
|
-
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
414
|
-
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
415
|
-
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
416
|
-
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
417
|
-
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
418
|
-
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
419
|
-
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
420
|
-
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
421
|
-
a = safeAdd(a, olda);
|
|
422
|
-
b = safeAdd(b, oldb);
|
|
423
|
-
c = safeAdd(c, oldc);
|
|
424
|
-
d = safeAdd(d, oldd);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return [a, b, c, d];
|
|
428
|
-
}
|
|
429
|
-
/*
|
|
430
|
-
* Convert an array bytes to an array of little-endian words
|
|
431
|
-
* Characters >255 have their high-byte silently ignored.
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
function bytesToWords(input) {
|
|
436
|
-
if (input.length === 0) {
|
|
437
|
-
return [];
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const length8 = input.length * 8;
|
|
441
|
-
const output = new Uint32Array(getOutputLength(length8));
|
|
442
|
-
|
|
443
|
-
for (let i = 0; i < length8; i += 8) {
|
|
444
|
-
output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
return output;
|
|
448
|
-
}
|
|
449
|
-
/*
|
|
450
|
-
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
|
451
|
-
* to work around bugs in some JS interpreters.
|
|
452
|
-
*/
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
function safeAdd(x, y) {
|
|
456
|
-
const lsw = (x & 0xffff) + (y & 0xffff);
|
|
457
|
-
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
458
|
-
return msw << 16 | lsw & 0xffff;
|
|
459
|
-
}
|
|
460
|
-
/*
|
|
461
|
-
* Bitwise rotate a 32-bit number to the left.
|
|
462
|
-
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
function bitRotateLeft(num, cnt) {
|
|
466
|
-
return num << cnt | num >>> 32 - cnt;
|
|
467
|
-
}
|
|
468
|
-
/*
|
|
469
|
-
* These functions implement the four basic operations the algorithm uses.
|
|
470
|
-
*/
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
function md5cmn(q, a, b, x, s, t) {
|
|
474
|
-
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function md5ff(a, b, c, d, x, s, t) {
|
|
478
|
-
return md5cmn(b & c | ~b & d, a, b, x, s, t);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function md5gg(a, b, c, d, x, s, t) {
|
|
482
|
-
return md5cmn(b & d | c & ~d, a, b, x, s, t);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function md5hh(a, b, c, d, x, s, t) {
|
|
486
|
-
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function md5ii(a, b, c, d, x, s, t) {
|
|
490
|
-
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
281
|
+
return crypto.createHash('md5').update(bytes).digest();
|
|
491
282
|
}
|
|
492
283
|
|
|
493
284
|
const v3 = v35('v3', 0x30, md5);
|
|
494
285
|
var v3$1 = v3;
|
|
495
286
|
|
|
496
|
-
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
497
287
|
var native = {
|
|
498
|
-
randomUUID
|
|
288
|
+
randomUUID: crypto.randomUUID
|
|
499
289
|
};
|
|
500
290
|
|
|
501
291
|
function v4(options, buf, offset) {
|
|
@@ -522,99 +312,14 @@ function v4(options, buf, offset) {
|
|
|
522
312
|
return unsafeStringify(rnds);
|
|
523
313
|
}
|
|
524
314
|
|
|
525
|
-
// Adapted from Chris Veness' SHA1 code at
|
|
526
|
-
// http://www.movable-type.co.uk/scripts/sha1.html
|
|
527
|
-
function f(s, x, y, z) {
|
|
528
|
-
switch (s) {
|
|
529
|
-
case 0:
|
|
530
|
-
return x & y ^ ~x & z;
|
|
531
|
-
|
|
532
|
-
case 1:
|
|
533
|
-
return x ^ y ^ z;
|
|
534
|
-
|
|
535
|
-
case 2:
|
|
536
|
-
return x & y ^ x & z ^ y & z;
|
|
537
|
-
|
|
538
|
-
case 3:
|
|
539
|
-
return x ^ y ^ z;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
function ROTL(x, n) {
|
|
544
|
-
return x << n | x >>> 32 - n;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
315
|
function sha1(bytes) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
553
|
-
|
|
554
|
-
bytes = [];
|
|
555
|
-
|
|
556
|
-
for (let i = 0; i < msg.length; ++i) {
|
|
557
|
-
bytes.push(msg.charCodeAt(i));
|
|
558
|
-
}
|
|
559
|
-
} else if (!Array.isArray(bytes)) {
|
|
560
|
-
// Convert Array-like to Array
|
|
561
|
-
bytes = Array.prototype.slice.call(bytes);
|
|
316
|
+
if (Array.isArray(bytes)) {
|
|
317
|
+
bytes = Buffer.from(bytes);
|
|
318
|
+
} else if (typeof bytes === 'string') {
|
|
319
|
+
bytes = Buffer.from(bytes, 'utf8');
|
|
562
320
|
}
|
|
563
321
|
|
|
564
|
-
bytes.
|
|
565
|
-
const l = bytes.length / 4 + 2;
|
|
566
|
-
const N = Math.ceil(l / 16);
|
|
567
|
-
const M = new Array(N);
|
|
568
|
-
|
|
569
|
-
for (let i = 0; i < N; ++i) {
|
|
570
|
-
const arr = new Uint32Array(16);
|
|
571
|
-
|
|
572
|
-
for (let j = 0; j < 16; ++j) {
|
|
573
|
-
arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
M[i] = arr;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
|
|
580
|
-
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
581
|
-
M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
|
|
582
|
-
|
|
583
|
-
for (let i = 0; i < N; ++i) {
|
|
584
|
-
const W = new Uint32Array(80);
|
|
585
|
-
|
|
586
|
-
for (let t = 0; t < 16; ++t) {
|
|
587
|
-
W[t] = M[i][t];
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
for (let t = 16; t < 80; ++t) {
|
|
591
|
-
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
let a = H[0];
|
|
595
|
-
let b = H[1];
|
|
596
|
-
let c = H[2];
|
|
597
|
-
let d = H[3];
|
|
598
|
-
let e = H[4];
|
|
599
|
-
|
|
600
|
-
for (let t = 0; t < 80; ++t) {
|
|
601
|
-
const s = Math.floor(t / 20);
|
|
602
|
-
const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
|
|
603
|
-
e = d;
|
|
604
|
-
d = c;
|
|
605
|
-
c = ROTL(b, 30) >>> 0;
|
|
606
|
-
b = a;
|
|
607
|
-
a = T;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
H[0] = H[0] + a >>> 0;
|
|
611
|
-
H[1] = H[1] + b >>> 0;
|
|
612
|
-
H[2] = H[2] + c >>> 0;
|
|
613
|
-
H[3] = H[3] + d >>> 0;
|
|
614
|
-
H[4] = H[4] + e >>> 0;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
|
|
322
|
+
return crypto.createHash('sha1').update(bytes).digest();
|
|
618
323
|
}
|
|
619
324
|
|
|
620
325
|
const v5 = v35('v5', 0x50, sha1);
|
|
@@ -630,7 +335,7 @@ function version$1(uuid) {
|
|
|
630
335
|
return parseInt(uuid.slice(14, 15), 16);
|
|
631
336
|
}
|
|
632
337
|
|
|
633
|
-
var
|
|
338
|
+
var esmNode = /*#__PURE__*/Object.freeze({
|
|
634
339
|
__proto__: null,
|
|
635
340
|
NIL: nil,
|
|
636
341
|
parse: parse,
|
|
@@ -643,7 +348,7 @@ var esmBrowser = /*#__PURE__*/Object.freeze({
|
|
|
643
348
|
version: version$1
|
|
644
349
|
});
|
|
645
350
|
|
|
646
|
-
var require$$0 = /*@__PURE__*/getAugmentedNamespace(
|
|
351
|
+
var require$$0 = /*@__PURE__*/getAugmentedNamespace(esmNode);
|
|
647
352
|
|
|
648
353
|
/**
|
|
649
354
|
* Copyright (C) 2010-2023 - SipTimes Technologies Corporation - All rights reserved.
|
|
@@ -676,7 +381,7 @@ const DEVICE = Object.freeze({ // core level api
|
|
|
676
381
|
DEFAULT: 'device-default',
|
|
677
382
|
ID_CARD_READER: 'device-id-card-reader',
|
|
678
383
|
NFC: 'device-nfc',
|
|
679
|
-
|
|
384
|
+
FINGERPRINT: 'device-fingerprint',
|
|
680
385
|
QR_CODE_SCANNER: 'device-qr-code-scanner',
|
|
681
386
|
PRINTER: 'device-printer'
|
|
682
387
|
});
|
|
@@ -705,7 +410,7 @@ if(typeof window !== 'undefined') {
|
|
|
705
410
|
var utils = config$1;
|
|
706
411
|
|
|
707
412
|
var name = "@cutos/core";
|
|
708
|
-
var version = "0.0.
|
|
413
|
+
var version = "0.0.9";
|
|
709
414
|
var description = "";
|
|
710
415
|
var main = "dist/cutos.cjs.js";
|
|
711
416
|
var module$1 = "dist/cutos.esm.js";
|
|
@@ -718,6 +423,7 @@ var keywords = [
|
|
|
718
423
|
var author = "";
|
|
719
424
|
var license = "ISC";
|
|
720
425
|
var dependencies = {
|
|
426
|
+
lodash: "4.17.21",
|
|
721
427
|
mqtt: "4.3.7",
|
|
722
428
|
qs: "6.11.2"
|
|
723
429
|
};
|
|
@@ -733,7 +439,7 @@ var files = [
|
|
|
733
439
|
"dist/cutos.esm.js",
|
|
734
440
|
"package.json"
|
|
735
441
|
];
|
|
736
|
-
var require$$
|
|
442
|
+
var require$$5 = {
|
|
737
443
|
name: name,
|
|
738
444
|
version: version,
|
|
739
445
|
description: description,
|
|
@@ -754,11 +460,12 @@ var require$$4 = {
|
|
|
754
460
|
|
|
755
461
|
const {v4: uuidv4} = require$$0;
|
|
756
462
|
const mqtt = require$$1;
|
|
463
|
+
const _ = require$$2;
|
|
757
464
|
const cutosAPI = cutosApi;
|
|
758
465
|
const config = utils;
|
|
759
466
|
const callbackMap = new Map();
|
|
760
467
|
const listenerMap = new Map();
|
|
761
|
-
const packageJson = require$$
|
|
468
|
+
const packageJson = require$$5;
|
|
762
469
|
|
|
763
470
|
const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
764
471
|
|
|
@@ -784,12 +491,21 @@ class Database {
|
|
|
784
491
|
KEY_TYPE_TEXT = "TEXT";
|
|
785
492
|
KEY_TYPE_INTEGER = "INTEGER";
|
|
786
493
|
|
|
787
|
-
constructor(db, callback,
|
|
494
|
+
constructor(db, callback, opts = {
|
|
495
|
+
retentionTime: 48,
|
|
496
|
+
mirror: {
|
|
497
|
+
gwIPC: null,
|
|
498
|
+
lwaName: "lwa-default",
|
|
499
|
+
confirm: false
|
|
500
|
+
}
|
|
501
|
+
}) {
|
|
788
502
|
// sub class
|
|
503
|
+
let database = this;
|
|
789
504
|
this.Table = class {
|
|
790
505
|
constructor(db, name, callback, retentionTime, keyType, keyName) {
|
|
791
506
|
this.db = db;
|
|
792
507
|
this.name = name;
|
|
508
|
+
|
|
793
509
|
let body = {
|
|
794
510
|
db: this.db, cmd: "db.table.create", name: name
|
|
795
511
|
};
|
|
@@ -803,28 +519,28 @@ class Database {
|
|
|
803
519
|
throw new Error("keyType MUST be INTEGER or TEXT");
|
|
804
520
|
|
|
805
521
|
}
|
|
806
|
-
return
|
|
522
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
807
523
|
}
|
|
808
524
|
|
|
809
525
|
insert(value, callback, tid) {
|
|
810
526
|
let body = {
|
|
811
527
|
db: this.db, cmd: "db.table.insert", name: this.name, value: value, tid: tid
|
|
812
528
|
};
|
|
813
|
-
return
|
|
529
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
814
530
|
}
|
|
815
531
|
|
|
816
532
|
insertById(id, value, callback, tid) {
|
|
817
533
|
let body = {
|
|
818
534
|
db: this.db, cmd: "db.table.insertById", name: this.name, id: id, value: value, tid: tid
|
|
819
535
|
};
|
|
820
|
-
return
|
|
536
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
821
537
|
}
|
|
822
538
|
|
|
823
539
|
insertByKey(key, value, callback, tid) {
|
|
824
540
|
let body = {
|
|
825
541
|
db: this.db, cmd: "db.table.insertByKey", name: this.name, key: key, value: value, tid: tid
|
|
826
542
|
};
|
|
827
|
-
return
|
|
543
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
828
544
|
}
|
|
829
545
|
|
|
830
546
|
update(id, value, callback) {
|
|
@@ -889,9 +605,29 @@ class Database {
|
|
|
889
605
|
};
|
|
890
606
|
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
891
607
|
}
|
|
608
|
+
|
|
609
|
+
publishRequestMirror(topic, callback, body) {
|
|
610
|
+
let mirror = database.mirror;
|
|
611
|
+
let cb = callback;
|
|
612
|
+
if (mirror.gwIPC) { // mirror enabled
|
|
613
|
+
cb = (dbResult) => {
|
|
614
|
+
let confirmCallback = !mirror.confirm ? null : (gwResult) => {
|
|
615
|
+
if (gwResult.status === "success") {
|
|
616
|
+
this.sync(dbResult.row);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
if (dbResult.status === true) {
|
|
620
|
+
mirror.gwIPC.mirror(body, confirmCallback, {lwa_name: mirror.lwaName});
|
|
621
|
+
}
|
|
622
|
+
callback && callback(dbResult);
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
return publishRequest(topic, cb, body);
|
|
626
|
+
};
|
|
892
627
|
};
|
|
893
628
|
this.db = db;
|
|
894
|
-
this.retentionTime = retentionTime
|
|
629
|
+
this.retentionTime = opts.retentionTime ? opts.retentionTime : 48;// default 48 hours
|
|
630
|
+
this.mirror = opts.mirror;
|
|
895
631
|
let body = {
|
|
896
632
|
cmd: "db.connect", db: this.db
|
|
897
633
|
};
|
|
@@ -1232,7 +968,19 @@ const CoreAPI = {
|
|
|
1232
968
|
},
|
|
1233
969
|
|
|
1234
970
|
getDatabase(db, callback) {
|
|
1235
|
-
|
|
971
|
+
let opts = {
|
|
972
|
+
retentionTime: 48,
|
|
973
|
+
mirror: {
|
|
974
|
+
gwIPC: null,
|
|
975
|
+
lwaName: "lwa-default",
|
|
976
|
+
confirm: false
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
if (typeof db === 'object') {
|
|
980
|
+
_.merge(opts, db);
|
|
981
|
+
db = opts.db;
|
|
982
|
+
}
|
|
983
|
+
return new Database(db, callback, opts);
|
|
1236
984
|
},
|
|
1237
985
|
|
|
1238
986
|
getVolume(callback) {
|
package/dist/cutos.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import require$$1 from 'mqtt/dist/mqtt';
|
|
2
|
+
import require$$2 from 'lodash';
|
|
2
3
|
import require$$0$1 from 'qs';
|
|
3
4
|
|
|
4
5
|
function getAugmentedNamespace(n) {
|
|
@@ -672,7 +673,7 @@ const DEVICE = Object.freeze({ // core level api
|
|
|
672
673
|
DEFAULT: 'device-default',
|
|
673
674
|
ID_CARD_READER: 'device-id-card-reader',
|
|
674
675
|
NFC: 'device-nfc',
|
|
675
|
-
|
|
676
|
+
FINGERPRINT: 'device-fingerprint',
|
|
676
677
|
QR_CODE_SCANNER: 'device-qr-code-scanner',
|
|
677
678
|
PRINTER: 'device-printer'
|
|
678
679
|
});
|
|
@@ -701,7 +702,7 @@ if(typeof window !== 'undefined') {
|
|
|
701
702
|
var utils = config$1;
|
|
702
703
|
|
|
703
704
|
var name = "@cutos/core";
|
|
704
|
-
var version = "0.0.
|
|
705
|
+
var version = "0.0.9";
|
|
705
706
|
var description = "";
|
|
706
707
|
var main = "dist/cutos.cjs.js";
|
|
707
708
|
var module = "dist/cutos.esm.js";
|
|
@@ -714,6 +715,7 @@ var keywords = [
|
|
|
714
715
|
var author = "";
|
|
715
716
|
var license = "ISC";
|
|
716
717
|
var dependencies = {
|
|
718
|
+
lodash: "4.17.21",
|
|
717
719
|
mqtt: "4.3.7",
|
|
718
720
|
qs: "6.11.2"
|
|
719
721
|
};
|
|
@@ -729,7 +731,7 @@ var files = [
|
|
|
729
731
|
"dist/cutos.esm.js",
|
|
730
732
|
"package.json"
|
|
731
733
|
];
|
|
732
|
-
var require$$
|
|
734
|
+
var require$$5 = {
|
|
733
735
|
name: name,
|
|
734
736
|
version: version,
|
|
735
737
|
description: description,
|
|
@@ -750,11 +752,12 @@ var require$$4 = {
|
|
|
750
752
|
|
|
751
753
|
const {v4: uuidv4} = require$$0;
|
|
752
754
|
const mqtt = require$$1;
|
|
755
|
+
const _ = require$$2;
|
|
753
756
|
const cutosAPI = cutosApi;
|
|
754
757
|
const config = utils;
|
|
755
758
|
const callbackMap = new Map();
|
|
756
759
|
const listenerMap = new Map();
|
|
757
|
-
const packageJson = require$$
|
|
760
|
+
const packageJson = require$$5;
|
|
758
761
|
|
|
759
762
|
const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
760
763
|
|
|
@@ -780,12 +783,21 @@ class Database {
|
|
|
780
783
|
KEY_TYPE_TEXT = "TEXT";
|
|
781
784
|
KEY_TYPE_INTEGER = "INTEGER";
|
|
782
785
|
|
|
783
|
-
constructor(db, callback,
|
|
786
|
+
constructor(db, callback, opts = {
|
|
787
|
+
retentionTime: 48,
|
|
788
|
+
mirror: {
|
|
789
|
+
gwIPC: null,
|
|
790
|
+
lwaName: "lwa-default",
|
|
791
|
+
confirm: false
|
|
792
|
+
}
|
|
793
|
+
}) {
|
|
784
794
|
// sub class
|
|
795
|
+
let database = this;
|
|
785
796
|
this.Table = class {
|
|
786
797
|
constructor(db, name, callback, retentionTime, keyType, keyName) {
|
|
787
798
|
this.db = db;
|
|
788
799
|
this.name = name;
|
|
800
|
+
|
|
789
801
|
let body = {
|
|
790
802
|
db: this.db, cmd: "db.table.create", name: name
|
|
791
803
|
};
|
|
@@ -799,28 +811,28 @@ class Database {
|
|
|
799
811
|
throw new Error("keyType MUST be INTEGER or TEXT");
|
|
800
812
|
|
|
801
813
|
}
|
|
802
|
-
return
|
|
814
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
803
815
|
}
|
|
804
816
|
|
|
805
817
|
insert(value, callback, tid) {
|
|
806
818
|
let body = {
|
|
807
819
|
db: this.db, cmd: "db.table.insert", name: this.name, value: value, tid: tid
|
|
808
820
|
};
|
|
809
|
-
return
|
|
821
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
810
822
|
}
|
|
811
823
|
|
|
812
824
|
insertById(id, value, callback, tid) {
|
|
813
825
|
let body = {
|
|
814
826
|
db: this.db, cmd: "db.table.insertById", name: this.name, id: id, value: value, tid: tid
|
|
815
827
|
};
|
|
816
|
-
return
|
|
828
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
817
829
|
}
|
|
818
830
|
|
|
819
831
|
insertByKey(key, value, callback, tid) {
|
|
820
832
|
let body = {
|
|
821
833
|
db: this.db, cmd: "db.table.insertByKey", name: this.name, key: key, value: value, tid: tid
|
|
822
834
|
};
|
|
823
|
-
return
|
|
835
|
+
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
824
836
|
}
|
|
825
837
|
|
|
826
838
|
update(id, value, callback) {
|
|
@@ -885,9 +897,29 @@ class Database {
|
|
|
885
897
|
};
|
|
886
898
|
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
887
899
|
}
|
|
900
|
+
|
|
901
|
+
publishRequestMirror(topic, callback, body) {
|
|
902
|
+
let mirror = database.mirror;
|
|
903
|
+
let cb = callback;
|
|
904
|
+
if (mirror.gwIPC) { // mirror enabled
|
|
905
|
+
cb = (dbResult) => {
|
|
906
|
+
let confirmCallback = !mirror.confirm ? null : (gwResult) => {
|
|
907
|
+
if (gwResult.status === "success") {
|
|
908
|
+
this.sync(dbResult.row);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
if (dbResult.status === true) {
|
|
912
|
+
mirror.gwIPC.mirror(body, confirmCallback, {lwa_name: mirror.lwaName});
|
|
913
|
+
}
|
|
914
|
+
callback && callback(dbResult);
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return publishRequest(topic, cb, body);
|
|
918
|
+
};
|
|
888
919
|
};
|
|
889
920
|
this.db = db;
|
|
890
|
-
this.retentionTime = retentionTime
|
|
921
|
+
this.retentionTime = opts.retentionTime ? opts.retentionTime : 48;// default 48 hours
|
|
922
|
+
this.mirror = opts.mirror;
|
|
891
923
|
let body = {
|
|
892
924
|
cmd: "db.connect", db: this.db
|
|
893
925
|
};
|
|
@@ -1228,7 +1260,19 @@ const CoreAPI = {
|
|
|
1228
1260
|
},
|
|
1229
1261
|
|
|
1230
1262
|
getDatabase(db, callback) {
|
|
1231
|
-
|
|
1263
|
+
let opts = {
|
|
1264
|
+
retentionTime: 48,
|
|
1265
|
+
mirror: {
|
|
1266
|
+
gwIPC: null,
|
|
1267
|
+
lwaName: "lwa-default",
|
|
1268
|
+
confirm: false
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
if (typeof db === 'object') {
|
|
1272
|
+
_.merge(opts, db);
|
|
1273
|
+
db = opts.db;
|
|
1274
|
+
}
|
|
1275
|
+
return new Database(db, callback, opts);
|
|
1232
1276
|
},
|
|
1233
1277
|
|
|
1234
1278
|
getVolume(callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutos/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cutos.cjs.js",
|
|
6
6
|
"module": "dist/cutos.esm.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"lodash": "4.17.21",
|
|
16
17
|
"mqtt": "4.3.7",
|
|
17
18
|
"qs": "6.11.2"
|
|
18
19
|
},
|