mol_db 0.0.101 → 0.0.105

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mol_db",
3
- "version": "0.0.101",
3
+ "version": "0.0.105",
4
4
  "main": "node.js",
5
5
  "module": "node.esm.js",
6
6
  "browser": "web.js",
package/web.test.js CHANGED
@@ -346,23 +346,16 @@ var $;
346
346
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
347
347
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
348
348
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
349
- },
350
- 'Number'() {
351
349
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
352
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
353
350
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
354
351
  },
355
- 'empty POJOs'() {
352
+ 'POJO'() {
356
353
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
357
- },
358
- 'different POJOs'() {
359
354
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
360
- },
361
- 'different POJOs with same keys but different values'() {
362
355
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
363
- },
364
- 'different POJOs with different keys but same values'() {
365
356
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
357
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
358
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
366
359
  },
367
360
  'Array'() {
368
361
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -370,17 +363,12 @@ var $;
370
363
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
371
364
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
372
365
  },
373
- 'same POJO trees'() {
374
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
375
- },
376
- 'different classes with same values'() {
377
- class Obj {
378
- foo = 1;
366
+ 'Non POJO are different'() {
367
+ class Thing extends Object {
379
368
  }
380
- const a = new Obj;
381
- const b = new class extends Obj {
382
- };
383
- $.$mol_assert_not($.$mol_compare_deep(a, b));
369
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
370
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
371
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
384
372
  },
385
373
  'same POJOs with cyclic reference'() {
386
374
  const a = { foo: {} };
@@ -389,41 +377,6 @@ var $;
389
377
  b['self'] = b;
390
378
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
391
379
  },
392
- 'empty Element'() {
393
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
394
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
395
- },
396
- 'Element with attributes'() {
397
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
398
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
399
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
400
- },
401
- 'Element with styles'() {
402
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
403
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
404
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
405
- },
406
- 'Element with content'() {
407
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
408
- "foo",
409
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
410
- "foo",
411
- $.$mol_jsx("br", null))));
412
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
413
- "foo",
414
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
415
- "bar",
416
- $.$mol_jsx("br", null))));
417
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
418
- "foo",
419
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
420
- "foo",
421
- $.$mol_jsx("hr", null))));
422
- },
423
- 'Element with handlers'() {
424
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
425
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
426
- },
427
380
  'Date'() {
428
381
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
429
382
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -435,8 +388,9 @@ var $;
435
388
  },
436
389
  'Map'() {
437
390
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
438
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
391
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
439
392
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
393
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
440
394
  },
441
395
  'Set'() {
442
396
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -448,6 +402,21 @@ var $;
448
402
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
449
403
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
450
404
  },
405
+ 'Custom comparator'() {
406
+ class User {
407
+ name;
408
+ rand;
409
+ constructor(name, rand = Math.random()) {
410
+ this.name = name;
411
+ this.rand = rand;
412
+ }
413
+ [Symbol.toPrimitive](mode) {
414
+ return this.name;
415
+ }
416
+ }
417
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
418
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
419
+ },
451
420
  });
452
421
  })($ || ($ = {}));
453
422
  //deep.test.js.map
@@ -455,97 +424,123 @@ var $;
455
424
  "use strict";
456
425
  var $;
457
426
  (function ($) {
458
- const a_stack = [];
459
- const b_stack = [];
460
- let cache = null;
461
- function $mol_compare_deep(a, b) {
462
- if (Object.is(a, b))
427
+ let cache = new WeakMap();
428
+ function $mol_compare_deep(left, right) {
429
+ if (Object.is(left, right))
463
430
  return true;
464
- const a_type = typeof a;
465
- const b_type = typeof b;
466
- if (a_type !== b_type)
431
+ if (left === null)
467
432
  return false;
468
- if (a_type === 'function')
469
- return a['toString']() === b['toString']();
470
- if (a_type !== 'object')
433
+ if (right === null)
471
434
  return false;
472
- if (!a || !b)
435
+ if (typeof left !== 'object')
473
436
  return false;
474
- if (a instanceof Error)
437
+ if (typeof right !== 'object')
475
438
  return false;
476
- if (a['constructor'] !== b['constructor'])
439
+ const left_proto = Reflect.getPrototypeOf(left);
440
+ const right_proto = Reflect.getPrototypeOf(right);
441
+ if (left_proto !== right_proto)
477
442
  return false;
478
- if (a instanceof RegExp)
479
- return a.toString() === b['toString']();
480
- const ref = a_stack.indexOf(a);
481
- if (ref >= 0) {
482
- return Object.is(b_stack[ref], b);
483
- }
484
- if (!cache)
485
- cache = new WeakMap;
486
- let a_cache = cache.get(a);
487
- if (a_cache) {
488
- const b_cache = a_cache.get(b);
489
- if (typeof b_cache === 'boolean')
490
- return b_cache;
443
+ if (left instanceof Boolean)
444
+ return Object.is(left.valueOf(), right['valueOf']());
445
+ if (left instanceof Number)
446
+ return Object.is(left.valueOf(), right['valueOf']());
447
+ if (left instanceof String)
448
+ return Object.is(left.valueOf(), right['valueOf']());
449
+ if (left instanceof Date)
450
+ return Object.is(left.valueOf(), right['valueOf']());
451
+ if (left instanceof RegExp)
452
+ return left.source === right['source'] && left.flags === right['flags'];
453
+ let left_cache = cache.get(left);
454
+ if (left_cache) {
455
+ const right_cache = left_cache.get(right);
456
+ if (typeof right_cache === 'boolean')
457
+ return right_cache;
491
458
  }
492
459
  else {
493
- a_cache = new WeakMap();
494
- cache.set(a, a_cache);
460
+ left_cache = new WeakMap([[right, true]]);
461
+ cache.set(left, left_cache);
495
462
  }
496
- a_stack.push(a);
497
- b_stack.push(b);
498
463
  let result;
499
464
  try {
500
- if (Symbol.iterator in a) {
501
- const a_iter = a[Symbol.iterator]();
502
- const b_iter = b[Symbol.iterator]();
503
- while (true) {
504
- const a_next = a_iter.next();
505
- const b_next = b_iter.next();
506
- if (a_next.done !== b_next.done)
507
- return result = false;
508
- if (a_next.done)
509
- break;
510
- if (!$mol_compare_deep(a_next.value, b_next.value))
511
- return result = false;
512
- }
513
- return result = true;
514
- }
515
- let count = 0;
516
- for (let key in a) {
517
- try {
518
- if (!$mol_compare_deep(a[key], b[key]))
519
- return result = false;
520
- }
521
- catch (error) {
522
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
523
- }
524
- ++count;
525
- }
526
- for (let key in b) {
527
- --count;
528
- if (count < 0)
529
- return result = false;
530
- }
531
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
532
- if (!Object.is(a['valueOf'](), b['valueOf']()))
533
- return result = false;
534
- }
535
- return result = true;
465
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
466
+ result = compare_pojo(left, right);
467
+ else if (Array.isArray(left))
468
+ result = compare_array(left, right);
469
+ else if (left instanceof Set)
470
+ result = compare_set(left, right);
471
+ else if (left instanceof Map)
472
+ result = compare_map(left, right);
473
+ else if (ArrayBuffer.isView(left))
474
+ result = compare_buffer(left, right);
475
+ else if (Symbol.toPrimitive in left)
476
+ result = compare_primitive(left, right);
477
+ else
478
+ result = false;
536
479
  }
537
480
  finally {
538
- a_stack.pop();
539
- b_stack.pop();
540
- if (a_stack.length === 0) {
541
- cache = null;
542
- }
543
- else {
544
- a_cache.set(b, result);
545
- }
481
+ left_cache.set(right, result);
546
482
  }
483
+ return result;
547
484
  }
548
485
  $.$mol_compare_deep = $mol_compare_deep;
486
+ function compare_array(left, right) {
487
+ const len = left.length;
488
+ if (len !== right.length)
489
+ return false;
490
+ for (let i = 0; i < len; ++i) {
491
+ if (!$mol_compare_deep(left[i], right[i]))
492
+ return false;
493
+ }
494
+ return true;
495
+ }
496
+ function compare_buffer(left, right) {
497
+ const len = left.byteLength;
498
+ if (len !== right.byteLength)
499
+ return false;
500
+ for (let i = 0; i < len; ++i) {
501
+ if (left[i] !== right[i])
502
+ return false;
503
+ }
504
+ return true;
505
+ }
506
+ function compare_iterator(left, right, compare) {
507
+ while (true) {
508
+ const left_next = left.next();
509
+ const right_next = right.next();
510
+ if (left_next.done !== right_next.done)
511
+ return false;
512
+ if (left_next.done)
513
+ break;
514
+ if (!compare(left_next.value, right_next.value))
515
+ return false;
516
+ }
517
+ return true;
518
+ }
519
+ function compare_set(left, right) {
520
+ if (left.size !== right.size)
521
+ return false;
522
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
523
+ }
524
+ function compare_map(left, right) {
525
+ if (left.size !== right.size)
526
+ return false;
527
+ return compare_iterator(left.keys(), right.keys(), Object.is)
528
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
529
+ }
530
+ function compare_pojo(left, right) {
531
+ const left_keys = Object.getOwnPropertyNames(left);
532
+ const right_keys = Object.getOwnPropertyNames(right);
533
+ if (left_keys.length !== right_keys.length)
534
+ return false;
535
+ for (let key of left_keys) {
536
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
537
+ return false;
538
+ }
539
+ return true;
540
+ }
541
+ function compare_primitive(left, right) {
542
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
543
+ }
549
544
  })($ || ($ = {}));
550
545
  //deep.js.map
551
546
  ;
@@ -831,92 +826,6 @@ var $;
831
826
  ;
832
827
  "use strict";
833
828
  var $;
834
- (function ($) {
835
- $.$mol_test({
836
- 'equal paths'() {
837
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
838
- $.$mol_assert_like(diff, {
839
- prefix: [1, 2, 3, 4],
840
- suffix: [[], [], []],
841
- });
842
- },
843
- 'different suffix'() {
844
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
845
- $.$mol_assert_like(diff, {
846
- prefix: [1, 2],
847
- suffix: [[3, 4], [3, 5], [5, 4]],
848
- });
849
- },
850
- 'one contains other'() {
851
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
852
- $.$mol_assert_like(diff, {
853
- prefix: [1, 2],
854
- suffix: [[3, 4], [], [3]],
855
- });
856
- },
857
- 'fully different'() {
858
- const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
859
- $.$mol_assert_like(diff, {
860
- prefix: [],
861
- suffix: [[1, 2], [3, 4], [5, 6]],
862
- });
863
- },
864
- });
865
- })($ || ($ = {}));
866
- //path.test.js.map
867
- ;
868
- "use strict";
869
- var $;
870
- (function ($) {
871
- function $mol_diff_path(...paths) {
872
- const limit = Math.min(...paths.map(path => path.length));
873
- lookup: for (var i = 0; i < limit; ++i) {
874
- const first = paths[0][i];
875
- for (let j = 1; j < paths.length; ++j) {
876
- if (paths[j][i] !== first)
877
- break lookup;
878
- }
879
- }
880
- return {
881
- prefix: paths[0].slice(0, i),
882
- suffix: paths.map(path => path.slice(i)),
883
- };
884
- }
885
- $.$mol_diff_path = $mol_diff_path;
886
- })($ || ($ = {}));
887
- //path.js.map
888
- ;
889
- "use strict";
890
- var $;
891
- (function ($) {
892
- class $mol_error_mix extends Error {
893
- errors;
894
- constructor(message, ...errors) {
895
- super(message);
896
- this.errors = errors;
897
- if (errors.length) {
898
- const stacks = [...errors.map(error => error.stack), this.stack];
899
- const diff = $.$mol_diff_path(...stacks.map(stack => {
900
- if (!stack)
901
- return [];
902
- return stack.split('\n').reverse();
903
- }));
904
- const head = diff.prefix.reverse().join('\n');
905
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
906
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
907
- this.message += errors.map(error => '\n' + error.message).join('');
908
- }
909
- }
910
- toJSON() {
911
- return this.message;
912
- }
913
- }
914
- $.$mol_error_mix = $mol_error_mix;
915
- })($ || ($ = {}));
916
- //mix.js.map
917
- ;
918
- "use strict";
919
- var $;
920
829
  (function ($) {
921
830
  $.$mol_test({
922
831
  async 'unique index'() {