@futdevpro/fsm-dynamo 1.11.23 → 1.11.25
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/.github/workflows/main.yml +1 -1
- package/build/_collections/utils/array.util.d.ts +23 -0
- package/build/_collections/utils/array.util.d.ts.map +1 -1
- package/build/_collections/utils/array.util.js +32 -0
- package/build/_collections/utils/array.util.js.map +1 -1
- package/build/_collections/utils/array.util.spec.js +3 -3
- package/build/_collections/utils/array.util.spec.js.map +1 -1
- package/build/_collections/utils/async.util.d.ts +33 -0
- package/build/_collections/utils/async.util.d.ts.map +1 -0
- package/build/_collections/utils/async.util.js +75 -0
- package/build/_collections/utils/async.util.js.map +1 -0
- package/build/_collections/utils/json-error-helper.util.d.ts +55 -0
- package/build/_collections/utils/json-error-helper.util.d.ts.map +1 -0
- package/build/_collections/utils/json-error-helper.util.js +139 -0
- package/build/_collections/utils/json-error-helper.util.js.map +1 -0
- package/build/_collections/utils/{shared.util.d.ts → object.util.d.ts} +69 -4
- package/build/_collections/utils/object.util.d.ts.map +1 -0
- package/build/_collections/utils/{shared.util.js → object.util.js} +205 -14
- package/build/_collections/utils/object.util.js.map +1 -0
- package/build/_collections/utils/object.util.spec.d.ts +2 -0
- package/build/_collections/utils/object.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/{shared.util.spec.js → object.util.spec.js} +13 -13
- package/build/_collections/utils/{shared.util.spec.js.map → object.util.spec.js.map} +1 -1
- package/build/_collections/utils/utilities.util.d.ts +0 -117
- package/build/_collections/utils/utilities.util.d.ts.map +1 -1
- package/build/_collections/utils/utilities.util.js +0 -307
- package/build/_collections/utils/utilities.util.js.map +1 -1
- package/build/_models/control-models/error.control-model.js +2 -2
- package/build/_models/control-models/poll.control-model.js +2 -2
- package/build/_models/control-models/poll.control-model.js.map +1 -1
- package/build/_modules/location/_collections/loc-regions.util.js +4 -4
- package/build/_modules/location/_collections/loc-regions.util.js.map +1 -1
- package/build/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.js +2 -2
- package/build/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.js.map +1 -1
- package/build/_modules/socket/_services/sck-client.service-base.js +3 -3
- package/build/_modules/socket/_services/sck-client.service-base.js.map +1 -1
- package/build/_modules/socket/_services/sck-client.service-base.spec.js +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/futdevpro-fsm-dynamo-01.11.25.tgz +0 -0
- package/package.json +1 -1
- package/src/_collections/utils/array.util.spec.ts +3 -3
- package/src/_collections/utils/array.util.ts +44 -0
- package/src/_collections/utils/async.util.ts +91 -0
- package/src/_collections/utils/json-error-helper.util.ts +172 -0
- package/src/_collections/utils/{shared.util.spec.ts → object.util.spec.ts} +12 -12
- package/src/_collections/utils/{shared.util.ts → object.util.ts} +269 -14
- package/src/_collections/utils/utilities.util.ts +0 -374
- package/src/_models/control-models/error.control-model.ts +2 -2
- package/src/_models/control-models/poll.control-model.ts +2 -2
- package/src/_modules/location/_collections/loc-regions.util.ts +4 -4
- package/src/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.ts +2 -2
- package/src/_modules/socket/_services/sck-client.service-base.spec.ts +1 -1
- package/src/_modules/socket/_services/sck-client.service-base.ts +3 -3
- package/src/index.ts +2 -1
- package/build/_collections/utils/shared.util.d.ts.map +0 -1
- package/build/_collections/utils/shared.util.js.map +0 -1
- package/build/_collections/utils/shared.util.spec.d.ts +0 -2
- package/build/_collections/utils/shared.util.spec.d.ts.map +0 -1
- package/build/_collections/utils/utilities.util.spec.d.ts +0 -2
- package/build/_collections/utils/utilities.util.spec.d.ts.map +0 -1
- package/build/_collections/utils/utilities.util.spec.js +0 -145
- package/build/_collections/utils/utilities.util.spec.js.map +0 -1
- package/futdevpro-fsm-dynamo-01.11.23.tgz +0 -0
- package/src/_collections/utils/utilities.util.spec.ts +0 -166
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
import { DyFM_Log } from './log.util';
|
|
3
|
-
import {
|
|
3
|
+
import { DyFM_JsonErrorHelper } from './json-error-helper.util';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class DyFM_Object {
|
|
6
|
+
|
|
7
|
+
static readonly defaultErrorMsg =
|
|
8
|
+
' failed. ' +
|
|
9
|
+
'\nThis might be happening because the object you trying to clone, ' +
|
|
10
|
+
'contains object hooks for its own objects, therefore its creating an object loop. ' +
|
|
11
|
+
'See further information in the detailed error:\n\n';
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* returns remapped object list by path list
|
|
@@ -55,7 +61,7 @@ export class DyFM_Shared {
|
|
|
55
61
|
* @returns data from object by path
|
|
56
62
|
*/
|
|
57
63
|
static getNestedData(parentObj: object, nestedDataKeys: string[]): any {
|
|
58
|
-
let newData: any =
|
|
64
|
+
let newData: any = this.clone(parentObj); // {...parentObj};
|
|
59
65
|
|
|
60
66
|
nestedDataKeys.forEach((dk: string): void => {
|
|
61
67
|
if (newData) {
|
|
@@ -74,7 +80,7 @@ export class DyFM_Shared {
|
|
|
74
80
|
* @returns modified data
|
|
75
81
|
*/
|
|
76
82
|
static nestData(parentObj: object, nestKeys: string[], dataToSet: any): object {
|
|
77
|
-
const newData: any =
|
|
83
|
+
const newData: any = this.clone(parentObj); // {...parentObj};
|
|
78
84
|
|
|
79
85
|
if (nestKeys.length > 1) {
|
|
80
86
|
const keys: string[] = [ ...nestKeys ];
|
|
@@ -96,7 +102,7 @@ export class DyFM_Shared {
|
|
|
96
102
|
* @returns modified data
|
|
97
103
|
*/
|
|
98
104
|
static addToNestedData(parentObj: object, nestKeys: string[], dataToAdd: any): object {
|
|
99
|
-
const newData: any =
|
|
105
|
+
const newData: any = this.clone(parentObj); // {...parentObj};
|
|
100
106
|
|
|
101
107
|
if (nestKeys.length > 1) {
|
|
102
108
|
const keys: string[] = [ ...nestKeys ];
|
|
@@ -118,7 +124,7 @@ export class DyFM_Shared {
|
|
|
118
124
|
* @returns modified data
|
|
119
125
|
*/
|
|
120
126
|
static pushToNestedData(parentObj: object, nestKeys: string[], dataToPush: any): object {
|
|
121
|
-
const newData: any =
|
|
127
|
+
const newData: any = this.clone(parentObj); // {...parentObj};
|
|
122
128
|
|
|
123
129
|
if (nestKeys.length > 1) {
|
|
124
130
|
const keys: string[] = [ ...nestKeys ];
|
|
@@ -150,7 +156,7 @@ export class DyFM_Shared {
|
|
|
150
156
|
nestIndexes: number[],
|
|
151
157
|
dataToSet: any
|
|
152
158
|
): T {
|
|
153
|
-
const newData: any =
|
|
159
|
+
const newData: any = this.clone(parentObj); // parentObj; // {...parentObj};
|
|
154
160
|
|
|
155
161
|
if (nestIndexes.length > 1) {
|
|
156
162
|
const indexes: number[] = [ ...nestIndexes ];
|
|
@@ -292,7 +298,7 @@ export class DyFM_Shared {
|
|
|
292
298
|
source[key].forEach(item => {
|
|
293
299
|
if (
|
|
294
300
|
!target[key].includes(item) &&
|
|
295
|
-
!target[key].some(targetItem =>
|
|
301
|
+
!target[key].some(targetItem => this.sameObjects(item, targetItem))
|
|
296
302
|
) {
|
|
297
303
|
target[key].push(item);
|
|
298
304
|
}
|
|
@@ -375,6 +381,7 @@ export class DyFM_Shared {
|
|
|
375
381
|
/**
|
|
376
382
|
* parses the JSON, if it fails, it throws an error
|
|
377
383
|
* (also will extract the JSON from "```json ... ```" wrapper)
|
|
384
|
+
* Uses enhanced error reporting with line context
|
|
378
385
|
*/
|
|
379
386
|
static failableSafeParseJSON<T = any>(textedJSON: string): T {
|
|
380
387
|
if (!textedJSON) {
|
|
@@ -382,16 +389,264 @@ export class DyFM_Shared {
|
|
|
382
389
|
}
|
|
383
390
|
|
|
384
391
|
const match = textedJSON.match(/```json(.*)```/s);
|
|
385
|
-
|
|
392
|
+
const cleanedTextedJSON = textedJSON.replaceAll('\n', '');
|
|
386
393
|
|
|
387
394
|
if (match) {
|
|
388
|
-
return
|
|
395
|
+
return DyFM_JsonErrorHelper.parseJsonWithEnhancedError(match[1].replaceAll('\n', ''));
|
|
389
396
|
} else {
|
|
390
|
-
return
|
|
391
|
-
|
|
397
|
+
return DyFM_JsonErrorHelper.parseJsonWithEnhancedError(
|
|
398
|
+
cleanedTextedJSON.replaceAll('```json', '').replaceAll('```', '')
|
|
392
399
|
);
|
|
393
400
|
}
|
|
394
401
|
}
|
|
395
|
-
}
|
|
396
402
|
|
|
397
|
-
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Clone an object
|
|
418
|
+
* @param object - The object to clone
|
|
419
|
+
* @returns The cloned object
|
|
420
|
+
*/
|
|
421
|
+
static clone<T>(object: T): T {
|
|
422
|
+
try {
|
|
423
|
+
return object ? JSON.parse(JSON.stringify(object)) as T : object;
|
|
424
|
+
} catch (error) {
|
|
425
|
+
DyFM_Log.error(
|
|
426
|
+
'clone()' + this.defaultErrorMsg,
|
|
427
|
+
error
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
static readonly copy: typeof this.clone = this.clone;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Surface clone an object
|
|
437
|
+
* @param object - The object to surface clone
|
|
438
|
+
* @returns The surface cloned object
|
|
439
|
+
*/
|
|
440
|
+
static surfaceClone<T extends Record<string, any>>(object: T): T {
|
|
441
|
+
try {
|
|
442
|
+
const result: Record<string, any> = {};
|
|
443
|
+
|
|
444
|
+
Object.keys(object).forEach((key: string): void => {
|
|
445
|
+
result[key] = object[key];
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
return result as T;
|
|
449
|
+
} catch (error) {
|
|
450
|
+
DyFM_Log.error(
|
|
451
|
+
'surfaceClone()' + this.defaultErrorMsg,
|
|
452
|
+
error
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
throw error;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
static readonly surfaceCopy: typeof this.surfaceClone = this.surfaceClone;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Deep clone an object
|
|
462
|
+
* @param object - The object to deep clone
|
|
463
|
+
* @returns The deep cloned object
|
|
464
|
+
*/
|
|
465
|
+
static deepClone<T extends Record<string, any>>(object: T): T {
|
|
466
|
+
try {
|
|
467
|
+
const result: Record<string, any> = {};
|
|
468
|
+
|
|
469
|
+
Object.keys(object).forEach((key: string): void => {
|
|
470
|
+
if (typeof object[key] === 'object') {
|
|
471
|
+
result[key] = this.deepClone(object[key]);
|
|
472
|
+
} else if (Array.isArray(object[key])) {
|
|
473
|
+
result[key] = object[key].map((item: any): any => this.deepClone(item));
|
|
474
|
+
} else {
|
|
475
|
+
result[key] = object[key];
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
return result as T;
|
|
480
|
+
} catch (error) {
|
|
481
|
+
DyFM_Log.error(
|
|
482
|
+
'deepClone()' + this.defaultErrorMsg,
|
|
483
|
+
error
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* A simple object comparison function that uses JSON.stringify() to compare objects.
|
|
492
|
+
*
|
|
493
|
+
* We experienced that sameObjects() function is not working properly for cases when
|
|
494
|
+
* deleting a key from the objects (to prevent strict results).
|
|
495
|
+
* So, we created orderedSameObject() function to prevent that issue.
|
|
496
|
+
* But be aware that, that function is not as fast as sameObjects() function.
|
|
497
|
+
*/
|
|
498
|
+
static sameObjects<T>(objA: T, objB: T): boolean {
|
|
499
|
+
try {
|
|
500
|
+
return JSON.stringify(objA) === JSON.stringify(objB);
|
|
501
|
+
} catch (error) {
|
|
502
|
+
DyFM_Log.error(
|
|
503
|
+
'sameObjects()' + this.defaultErrorMsg,
|
|
504
|
+
error
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
throw error;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* We experienced that sameObjects() function is not working properly for cases when
|
|
513
|
+
* deleting a key from the objects (to prevent strict results).
|
|
514
|
+
*
|
|
515
|
+
* This function is created to prevent that issue.
|
|
516
|
+
* But be aware that this function is not as fast as sameObjects() function.
|
|
517
|
+
*/
|
|
518
|
+
static orderedSameObject<T>(objA: T, objB: T): boolean {
|
|
519
|
+
try {
|
|
520
|
+
if (
|
|
521
|
+
typeof objA !== 'object' ||
|
|
522
|
+
typeof objB !== 'object' ||
|
|
523
|
+
Array.isArray(objA) ||
|
|
524
|
+
Array.isArray(objB) ||
|
|
525
|
+
objA === null ||
|
|
526
|
+
objB === null ||
|
|
527
|
+
objA === undefined ||
|
|
528
|
+
objB === undefined
|
|
529
|
+
) {
|
|
530
|
+
return JSON.stringify(objA) === JSON.stringify(objB);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const keysA = Object.keys(objA);
|
|
534
|
+
const keysB = Object.keys(objB);
|
|
535
|
+
|
|
536
|
+
if (keysA.length !== keysB.length) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
keysA.sort();
|
|
541
|
+
keysB.sort();
|
|
542
|
+
|
|
543
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
544
|
+
if (JSON.stringify(keysA[i]) !== JSON.stringify(keysB[i])) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return true;
|
|
550
|
+
} catch (error) {
|
|
551
|
+
/* try {
|
|
552
|
+
return DyFM_Object.orderedSameObject2(objA, objB);
|
|
553
|
+
} catch (error) { */
|
|
554
|
+
DyFM_Log.error(
|
|
555
|
+
'orderedSameObject()' + this.defaultErrorMsg,
|
|
556
|
+
error
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
throw error;
|
|
560
|
+
/* } */
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* We experienced that sameObjects() function is not working properly for cases when
|
|
566
|
+
* deleting a key from the objects (to prevent strict results).
|
|
567
|
+
*
|
|
568
|
+
* This function is created to prevent that issue.
|
|
569
|
+
* But be aware that this function is not as fast as sameObjects() function.
|
|
570
|
+
*/
|
|
571
|
+
static orderedSameObject2<T>(objA: T, objB: T): boolean {
|
|
572
|
+
try {
|
|
573
|
+
console.log('using orderedSameObject2');
|
|
574
|
+
|
|
575
|
+
if (
|
|
576
|
+
typeof objA !== 'object' ||
|
|
577
|
+
typeof objB !== 'object' ||
|
|
578
|
+
Array.isArray(objA) ||
|
|
579
|
+
Array.isArray(objB) ||
|
|
580
|
+
objA === null ||
|
|
581
|
+
objB === null ||
|
|
582
|
+
objA === undefined ||
|
|
583
|
+
objB === undefined
|
|
584
|
+
) {
|
|
585
|
+
return JSON.stringify(objA) === JSON.stringify(objB);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return JSON.stringify(
|
|
589
|
+
objA,
|
|
590
|
+
Object.keys(objA).sort()
|
|
591
|
+
) === JSON.stringify(
|
|
592
|
+
objB,
|
|
593
|
+
Object.keys(objB).sort()
|
|
594
|
+
);
|
|
595
|
+
} catch (error) {
|
|
596
|
+
DyFM_Log.error(
|
|
597
|
+
'sameObjects()' + this.defaultErrorMsg,
|
|
598
|
+
error
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
throw error;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* compares the surface of two objects
|
|
607
|
+
* @param objA
|
|
608
|
+
* @param objB
|
|
609
|
+
* @returns
|
|
610
|
+
*/
|
|
611
|
+
static sameObjectSurface<T>(objA: T, objB: T): boolean {
|
|
612
|
+
let result = true;
|
|
613
|
+
|
|
614
|
+
for (const key in objA) {
|
|
615
|
+
if (objA[key] !== objB[key]) {
|
|
616
|
+
result = false;
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return result;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* sets values if its existing on To, even if its null (but if undefined)
|
|
626
|
+
* @param setOn
|
|
627
|
+
* @param setTo
|
|
628
|
+
*/
|
|
629
|
+
static setExistingValuesOnly(setOn: any, setTo: any): void {
|
|
630
|
+
for (const key in setTo) {
|
|
631
|
+
if (setTo[key] != undefined) {
|
|
632
|
+
setOn[key] = setTo[key];
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* converts a JSONList to an array
|
|
639
|
+
* @param JSONList
|
|
640
|
+
* @returns
|
|
641
|
+
*/
|
|
642
|
+
static JSONListify<T>(JSONList: any): T[] {
|
|
643
|
+
const result: T[] = [];
|
|
644
|
+
|
|
645
|
+
for (let i = 0; JSONList[i]; i++) {
|
|
646
|
+
result.push(JSONList[i]);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
return result;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
}
|
|
@@ -1,377 +1,3 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { DyFM_Log } from './log.util';
|
|
4
|
-
|
|
5
|
-
const defaultErrorMsg =
|
|
6
|
-
' failed. ' +
|
|
7
|
-
'\nThis might be happening because the object you trying to clone, ' +
|
|
8
|
-
'contains object hooks for its own objects, therefore its creating an object loop. ' +
|
|
9
|
-
'See further information in the detailed error:\n\n';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Clone an object
|
|
13
|
-
* @param object - The object to clone
|
|
14
|
-
* @returns The cloned object
|
|
15
|
-
*/
|
|
16
|
-
export function DyFM_clone<T>(object: T): T {
|
|
17
|
-
try {
|
|
18
|
-
return object ? JSON.parse(JSON.stringify(object)) as T : object;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
DyFM_Log.error(
|
|
21
|
-
'clone()' + defaultErrorMsg,
|
|
22
|
-
error
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export const DyFM_copy = DyFM_clone;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Surface clone an object
|
|
32
|
-
* @param object - The object to surface clone
|
|
33
|
-
* @returns The surface cloned object
|
|
34
|
-
*/
|
|
35
|
-
export function DyFM_surfaceClone<T extends Record<string, any>>(object: T): T {
|
|
36
|
-
try {
|
|
37
|
-
const result: Record<string, any> = {};
|
|
38
|
-
|
|
39
|
-
Object.keys(object).forEach((key: string): void => {
|
|
40
|
-
result[key] = object[key];
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return result as T;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
DyFM_Log.error(
|
|
46
|
-
'surfaceClone()' + defaultErrorMsg,
|
|
47
|
-
error
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export const DyFM_surfaceCopy = DyFM_surfaceClone;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Deep clone an object
|
|
57
|
-
* @param object - The object to deep clone
|
|
58
|
-
* @returns The deep cloned object
|
|
59
|
-
*/
|
|
60
|
-
export function DyFM_deepClone<T extends Record<string, any>>(object: T): T {
|
|
61
|
-
try {
|
|
62
|
-
const result: Record<string, any> = {};
|
|
63
|
-
|
|
64
|
-
Object.keys(object).forEach((key: string): void => {
|
|
65
|
-
if (typeof object[key] === 'object') {
|
|
66
|
-
result[key] = DyFM_deepClone(object[key]);
|
|
67
|
-
} else if (Array.isArray(object[key])) {
|
|
68
|
-
result[key] = object[key].map((item: any): any => DyFM_deepClone(item));
|
|
69
|
-
} else {
|
|
70
|
-
result[key] = object[key];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return result as T;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
DyFM_Log.error(
|
|
77
|
-
'deepClone()' + defaultErrorMsg,
|
|
78
|
-
error
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* A simple object comparison function that uses JSON.stringify() to compare objects.
|
|
87
|
-
*
|
|
88
|
-
* We experienced that sameObjects() function is not working properly for cases when
|
|
89
|
-
* deleting a key from the objects (to prevent strict results).
|
|
90
|
-
* So, we created orderedSameObject() function to prevent that issue.
|
|
91
|
-
* But be aware that, that function is not as fast as sameObjects() function.
|
|
92
|
-
*/
|
|
93
|
-
export function DyFM_sameObjects<T>(objA: T, objB: T): boolean {
|
|
94
|
-
try {
|
|
95
|
-
return JSON.stringify(objA) === JSON.stringify(objB);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
DyFM_Log.error(
|
|
98
|
-
'sameObjects()' + defaultErrorMsg,
|
|
99
|
-
error
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* We experienced that sameObjects() function is not working properly for cases when
|
|
108
|
-
* deleting a key from the objects (to prevent strict results).
|
|
109
|
-
*
|
|
110
|
-
* This function is created to prevent that issue.
|
|
111
|
-
* But be aware that this function is not as fast as sameObjects() function.
|
|
112
|
-
*/
|
|
113
|
-
export function DyFM_orderedSameObject<T>(objA: T, objB: T): boolean {
|
|
114
|
-
try {
|
|
115
|
-
if (
|
|
116
|
-
typeof objA !== 'object' ||
|
|
117
|
-
typeof objB !== 'object' ||
|
|
118
|
-
Array.isArray(objA) ||
|
|
119
|
-
Array.isArray(objB) ||
|
|
120
|
-
objA === null ||
|
|
121
|
-
objB === null ||
|
|
122
|
-
objA === undefined ||
|
|
123
|
-
objB === undefined
|
|
124
|
-
) {
|
|
125
|
-
return JSON.stringify(objA) === JSON.stringify(objB);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const keysA = Object.keys(objA);
|
|
129
|
-
const keysB = Object.keys(objB);
|
|
130
|
-
|
|
131
|
-
if (keysA.length !== keysB.length) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
keysA.sort();
|
|
136
|
-
keysB.sort();
|
|
137
|
-
|
|
138
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
139
|
-
if (JSON.stringify(keysA[i]) !== JSON.stringify(keysB[i])) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return true;
|
|
145
|
-
} catch (error) {
|
|
146
|
-
/* try {
|
|
147
|
-
return DyFM_orderedSameObject2(objA, objB);
|
|
148
|
-
} catch (error) { */
|
|
149
|
-
DyFM_Log.error(
|
|
150
|
-
'orderedSameObject()' + defaultErrorMsg,
|
|
151
|
-
error
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
throw error;
|
|
155
|
-
/* } */
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* We experienced that sameObjects() function is not working properly for cases when
|
|
161
|
-
* deleting a key from the objects (to prevent strict results).
|
|
162
|
-
*
|
|
163
|
-
* This function is created to prevent that issue.
|
|
164
|
-
* But be aware that this function is not as fast as sameObjects() function.
|
|
165
|
-
*/
|
|
166
|
-
export function DyFM_orderedSameObject2<T>(objA: T, objB: T): boolean {
|
|
167
|
-
try {
|
|
168
|
-
console.log('using orderedSameObject2');
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
typeof objA !== 'object' ||
|
|
172
|
-
typeof objB !== 'object' ||
|
|
173
|
-
Array.isArray(objA) ||
|
|
174
|
-
Array.isArray(objB) ||
|
|
175
|
-
objA === null ||
|
|
176
|
-
objB === null ||
|
|
177
|
-
objA === undefined ||
|
|
178
|
-
objB === undefined
|
|
179
|
-
) {
|
|
180
|
-
return JSON.stringify(objA) === JSON.stringify(objB);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return JSON.stringify(
|
|
184
|
-
objA,
|
|
185
|
-
Object.keys(objA).sort()
|
|
186
|
-
) === JSON.stringify(
|
|
187
|
-
objB,
|
|
188
|
-
Object.keys(objB).sort()
|
|
189
|
-
);
|
|
190
|
-
} catch (error) {
|
|
191
|
-
DyFM_Log.error(
|
|
192
|
-
'sameObjects()' + defaultErrorMsg,
|
|
193
|
-
error
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* compares the surface of two objects
|
|
202
|
-
* @param objA
|
|
203
|
-
* @param objB
|
|
204
|
-
* @returns
|
|
205
|
-
*/
|
|
206
|
-
export function DyFM_sameObjectSurface<T>(objA: T, objB: T): boolean {
|
|
207
|
-
let result = true;
|
|
208
|
-
|
|
209
|
-
for (const key in objA) {
|
|
210
|
-
if (objA[key] !== objB[key]) {
|
|
211
|
-
result = false;
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* sets values if its existing on To, even if its null (but if undefined)
|
|
221
|
-
* @param setOn
|
|
222
|
-
* @param setTo
|
|
223
|
-
*/
|
|
224
|
-
export function DyFM_setExistingValuesOnly(setOn: any, setTo: any): void {
|
|
225
|
-
for (const key in setTo) {
|
|
226
|
-
if (setTo[key] != undefined) {
|
|
227
|
-
setOn[key] = setTo[key];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* delays the execution of a function
|
|
234
|
-
* @param ms
|
|
235
|
-
* @returns
|
|
236
|
-
*/
|
|
237
|
-
export function DyFM_delay(ms: number): Promise<void> {
|
|
238
|
-
return new Promise((resolve): any => setTimeout(resolve, ms));
|
|
239
|
-
}
|
|
240
|
-
export const DyFM_sleep = DyFM_delay;
|
|
241
|
-
export const DyFM_wait = DyFM_delay;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* WARNING: This function is recommended to use ONLY for limited instances,
|
|
245
|
-
* because it can cause performance issues.
|
|
246
|
-
*/
|
|
247
|
-
export function DyFM_waitUntil(
|
|
248
|
-
check: () => boolean,
|
|
249
|
-
interval: number = 100,
|
|
250
|
-
timeout: number = 10000
|
|
251
|
-
): Promise<void> {
|
|
252
|
-
return new Promise((resolve, reject): void => {
|
|
253
|
-
const startTime = Date.now();
|
|
254
|
-
|
|
255
|
-
const intervalId = setInterval((): void => {
|
|
256
|
-
if (check()) {
|
|
257
|
-
clearInterval(intervalId);
|
|
258
|
-
resolve();
|
|
259
|
-
} else if (Date.now() - startTime > timeout) {
|
|
260
|
-
clearInterval(intervalId);
|
|
261
|
-
reject('timeout');
|
|
262
|
-
}
|
|
263
|
-
}, interval);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* WARNING: This function is recommended to use ONLY for limited instances,
|
|
269
|
-
* because it can cause performance issues.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* const result = await DyFM_waitUntilAsync(
|
|
273
|
-
* () => check(),
|
|
274
|
-
* 30 * second,
|
|
275
|
-
* 5 * minute,
|
|
276
|
-
* );
|
|
277
|
-
*/
|
|
278
|
-
export function DyFM_waitUntilAsync(
|
|
279
|
-
check: () => Promise<boolean>,
|
|
280
|
-
interval: number = 100,
|
|
281
|
-
timeout: number = 10000
|
|
282
|
-
): Promise<void> {
|
|
283
|
-
return new Promise((resolve, reject): void => {
|
|
284
|
-
const startTime = Date.now();
|
|
285
|
-
|
|
286
|
-
const intervalId = setInterval(async (): Promise<void> => {
|
|
287
|
-
if (await check()) {
|
|
288
|
-
clearInterval(intervalId);
|
|
289
|
-
resolve();
|
|
290
|
-
} else if (Date.now() - startTime > timeout) {
|
|
291
|
-
clearInterval(intervalId);
|
|
292
|
-
reject('timeout');
|
|
293
|
-
}
|
|
294
|
-
}, interval);
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Creates a promise that resolves when the observable emits a value that passes the check function
|
|
300
|
-
*/
|
|
301
|
-
export function DyFM_takeUntil<T>(
|
|
302
|
-
observable: Observable<T>,
|
|
303
|
-
check: (value?: T) => boolean
|
|
304
|
-
): Promise<T> {
|
|
305
|
-
return new Promise((resolve): void => {
|
|
306
|
-
const sub = observable.subscribe(
|
|
307
|
-
(value?: T): void => {
|
|
308
|
-
if (check(value)) {
|
|
309
|
-
sub.unsubscribe();
|
|
310
|
-
resolve(value as T);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* the return type of the sortForTrue function
|
|
319
|
-
*/
|
|
320
|
-
export type DyFM_SortDirection = 0 | 1 | -1
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* You might be use getSortForTrueFn instead for a shorter expression
|
|
324
|
-
*
|
|
325
|
-
* @param a
|
|
326
|
-
* @param b
|
|
327
|
-
* @param check
|
|
328
|
-
* @returns
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* codes.sort((a,b) => sortForTrue(a,b,(c: Code) => c.haveImg));
|
|
332
|
-
*/
|
|
333
|
-
export function DyFM_sortForTrue<T>(
|
|
334
|
-
a: T,
|
|
335
|
-
b: T,
|
|
336
|
-
check: (a: T) => boolean
|
|
337
|
-
): DyFM_SortDirection {
|
|
338
|
-
const isA = check(a);
|
|
339
|
-
|
|
340
|
-
if (isA === check(b)) {
|
|
341
|
-
return 0;
|
|
342
|
-
} else if (isA) {
|
|
343
|
-
return -1;
|
|
344
|
-
} else {
|
|
345
|
-
return 1;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* returns a function that can be used to sort an array of objects
|
|
351
|
-
* sorts so that the objects that have the value true for the checkFor function are at the beginning of the array
|
|
352
|
-
* @param checkFor
|
|
353
|
-
* @returns
|
|
354
|
-
*/
|
|
355
|
-
export function DyFM_getSortForTrueFn<T>(
|
|
356
|
-
checkFor: (a: T) => boolean
|
|
357
|
-
): (a: T, b: T) => DyFM_SortDirection {
|
|
358
|
-
return (a: T, b: T): DyFM_SortDirection => DyFM_sortForTrue<T>(a, b, checkFor);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* converts a JSONList to an array
|
|
363
|
-
* @param JSONList
|
|
364
|
-
* @returns
|
|
365
|
-
*/
|
|
366
|
-
export function DyFM_JSONListify<T>(JSONList: any): T[] {
|
|
367
|
-
const result: T[] = [];
|
|
368
|
-
|
|
369
|
-
for (let i = 0; JSONList[i]; i++) {
|
|
370
|
-
result.push(JSONList[i]);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return result;
|
|
374
|
-
}
|
|
375
1
|
|
|
376
2
|
/**
|
|
377
3
|
* checks if the value is not null or undefined
|