mol_db 0.0.102 → 0.0.106

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/node.test.js CHANGED
@@ -1258,23 +1258,16 @@ var $;
1258
1258
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
1259
1259
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
1260
1260
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
1261
- },
1262
- 'Number'() {
1263
1261
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
1264
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
1265
1262
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
1266
1263
  },
1267
- 'empty POJOs'() {
1264
+ 'POJO'() {
1268
1265
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
1269
- },
1270
- 'different POJOs'() {
1271
1266
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
1272
- },
1273
- 'different POJOs with same keys but different values'() {
1274
1267
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
1275
- },
1276
- 'different POJOs with different keys but same values'() {
1277
1268
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
1269
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
1270
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
1278
1271
  },
1279
1272
  'Array'() {
1280
1273
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -1282,17 +1275,12 @@ var $;
1282
1275
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
1283
1276
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
1284
1277
  },
1285
- 'same POJO trees'() {
1286
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
1287
- },
1288
- 'different classes with same values'() {
1289
- class Obj {
1290
- foo = 1;
1278
+ 'Non POJO are different'() {
1279
+ class Thing extends Object {
1291
1280
  }
1292
- const a = new Obj;
1293
- const b = new class extends Obj {
1294
- };
1295
- $.$mol_assert_not($.$mol_compare_deep(a, b));
1281
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
1282
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
1283
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
1296
1284
  },
1297
1285
  'same POJOs with cyclic reference'() {
1298
1286
  const a = { foo: {} };
@@ -1301,41 +1289,6 @@ var $;
1301
1289
  b['self'] = b;
1302
1290
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
1303
1291
  },
1304
- 'empty Element'() {
1305
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
1306
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
1307
- },
1308
- 'Element with attributes'() {
1309
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
1310
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
1311
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
1312
- },
1313
- 'Element with styles'() {
1314
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
1315
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
1316
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
1317
- },
1318
- 'Element with content'() {
1319
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
1320
- "foo",
1321
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
1322
- "foo",
1323
- $.$mol_jsx("br", null))));
1324
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
1325
- "foo",
1326
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
1327
- "bar",
1328
- $.$mol_jsx("br", null))));
1329
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
1330
- "foo",
1331
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
1332
- "foo",
1333
- $.$mol_jsx("hr", null))));
1334
- },
1335
- 'Element with handlers'() {
1336
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
1337
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
1338
- },
1339
1292
  'Date'() {
1340
1293
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
1341
1294
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -1347,8 +1300,9 @@ var $;
1347
1300
  },
1348
1301
  'Map'() {
1349
1302
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
1350
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
1303
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
1351
1304
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
1305
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
1352
1306
  },
1353
1307
  'Set'() {
1354
1308
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -1360,6 +1314,21 @@ var $;
1360
1314
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
1361
1315
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
1362
1316
  },
1317
+ 'Custom comparator'() {
1318
+ class User {
1319
+ name;
1320
+ rand;
1321
+ constructor(name, rand = Math.random()) {
1322
+ this.name = name;
1323
+ this.rand = rand;
1324
+ }
1325
+ [Symbol.toPrimitive](mode) {
1326
+ return this.name;
1327
+ }
1328
+ }
1329
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
1330
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
1331
+ },
1363
1332
  });
1364
1333
  })($ || ($ = {}));
1365
1334
  //deep.test.js.map
@@ -1367,97 +1336,123 @@ var $;
1367
1336
  "use strict";
1368
1337
  var $;
1369
1338
  (function ($) {
1370
- const a_stack = [];
1371
- const b_stack = [];
1372
- let cache = null;
1373
- function $mol_compare_deep(a, b) {
1374
- if (Object.is(a, b))
1339
+ let cache = new WeakMap();
1340
+ function $mol_compare_deep(left, right) {
1341
+ if (Object.is(left, right))
1375
1342
  return true;
1376
- const a_type = typeof a;
1377
- const b_type = typeof b;
1378
- if (a_type !== b_type)
1343
+ if (left === null)
1379
1344
  return false;
1380
- if (a_type === 'function')
1381
- return a['toString']() === b['toString']();
1382
- if (a_type !== 'object')
1345
+ if (right === null)
1383
1346
  return false;
1384
- if (!a || !b)
1347
+ if (typeof left !== 'object')
1385
1348
  return false;
1386
- if (a instanceof Error)
1349
+ if (typeof right !== 'object')
1387
1350
  return false;
1388
- if (a['constructor'] !== b['constructor'])
1351
+ const left_proto = Reflect.getPrototypeOf(left);
1352
+ const right_proto = Reflect.getPrototypeOf(right);
1353
+ if (left_proto !== right_proto)
1389
1354
  return false;
1390
- if (a instanceof RegExp)
1391
- return a.toString() === b['toString']();
1392
- const ref = a_stack.indexOf(a);
1393
- if (ref >= 0) {
1394
- return Object.is(b_stack[ref], b);
1395
- }
1396
- if (!cache)
1397
- cache = new WeakMap;
1398
- let a_cache = cache.get(a);
1399
- if (a_cache) {
1400
- const b_cache = a_cache.get(b);
1401
- if (typeof b_cache === 'boolean')
1402
- return b_cache;
1355
+ if (left instanceof Boolean)
1356
+ return Object.is(left.valueOf(), right['valueOf']());
1357
+ if (left instanceof Number)
1358
+ return Object.is(left.valueOf(), right['valueOf']());
1359
+ if (left instanceof String)
1360
+ return Object.is(left.valueOf(), right['valueOf']());
1361
+ if (left instanceof Date)
1362
+ return Object.is(left.valueOf(), right['valueOf']());
1363
+ if (left instanceof RegExp)
1364
+ return left.source === right['source'] && left.flags === right['flags'];
1365
+ let left_cache = cache.get(left);
1366
+ if (left_cache) {
1367
+ const right_cache = left_cache.get(right);
1368
+ if (typeof right_cache === 'boolean')
1369
+ return right_cache;
1403
1370
  }
1404
1371
  else {
1405
- a_cache = new WeakMap();
1406
- cache.set(a, a_cache);
1372
+ left_cache = new WeakMap([[right, true]]);
1373
+ cache.set(left, left_cache);
1407
1374
  }
1408
- a_stack.push(a);
1409
- b_stack.push(b);
1410
1375
  let result;
1411
1376
  try {
1412
- if (Symbol.iterator in a) {
1413
- const a_iter = a[Symbol.iterator]();
1414
- const b_iter = b[Symbol.iterator]();
1415
- while (true) {
1416
- const a_next = a_iter.next();
1417
- const b_next = b_iter.next();
1418
- if (a_next.done !== b_next.done)
1419
- return result = false;
1420
- if (a_next.done)
1421
- break;
1422
- if (!$mol_compare_deep(a_next.value, b_next.value))
1423
- return result = false;
1424
- }
1425
- return result = true;
1426
- }
1427
- let count = 0;
1428
- for (let key in a) {
1429
- try {
1430
- if (!$mol_compare_deep(a[key], b[key]))
1431
- return result = false;
1432
- }
1433
- catch (error) {
1434
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
1435
- }
1436
- ++count;
1437
- }
1438
- for (let key in b) {
1439
- --count;
1440
- if (count < 0)
1441
- return result = false;
1442
- }
1443
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
1444
- if (!Object.is(a['valueOf'](), b['valueOf']()))
1445
- return result = false;
1446
- }
1447
- return result = true;
1377
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
1378
+ result = compare_pojo(left, right);
1379
+ else if (Array.isArray(left))
1380
+ result = compare_array(left, right);
1381
+ else if (left instanceof Set)
1382
+ result = compare_set(left, right);
1383
+ else if (left instanceof Map)
1384
+ result = compare_map(left, right);
1385
+ else if (ArrayBuffer.isView(left))
1386
+ result = compare_buffer(left, right);
1387
+ else if (Symbol.toPrimitive in left)
1388
+ result = compare_primitive(left, right);
1389
+ else
1390
+ result = false;
1448
1391
  }
1449
1392
  finally {
1450
- a_stack.pop();
1451
- b_stack.pop();
1452
- if (a_stack.length === 0) {
1453
- cache = null;
1454
- }
1455
- else {
1456
- a_cache.set(b, result);
1457
- }
1393
+ left_cache.set(right, result);
1458
1394
  }
1395
+ return result;
1459
1396
  }
1460
1397
  $.$mol_compare_deep = $mol_compare_deep;
1398
+ function compare_array(left, right) {
1399
+ const len = left.length;
1400
+ if (len !== right.length)
1401
+ return false;
1402
+ for (let i = 0; i < len; ++i) {
1403
+ if (!$mol_compare_deep(left[i], right[i]))
1404
+ return false;
1405
+ }
1406
+ return true;
1407
+ }
1408
+ function compare_buffer(left, right) {
1409
+ const len = left.byteLength;
1410
+ if (len !== right.byteLength)
1411
+ return false;
1412
+ for (let i = 0; i < len; ++i) {
1413
+ if (left[i] !== right[i])
1414
+ return false;
1415
+ }
1416
+ return true;
1417
+ }
1418
+ function compare_iterator(left, right, compare) {
1419
+ while (true) {
1420
+ const left_next = left.next();
1421
+ const right_next = right.next();
1422
+ if (left_next.done !== right_next.done)
1423
+ return false;
1424
+ if (left_next.done)
1425
+ break;
1426
+ if (!compare(left_next.value, right_next.value))
1427
+ return false;
1428
+ }
1429
+ return true;
1430
+ }
1431
+ function compare_set(left, right) {
1432
+ if (left.size !== right.size)
1433
+ return false;
1434
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
1435
+ }
1436
+ function compare_map(left, right) {
1437
+ if (left.size !== right.size)
1438
+ return false;
1439
+ return compare_iterator(left.keys(), right.keys(), Object.is)
1440
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
1441
+ }
1442
+ function compare_pojo(left, right) {
1443
+ const left_keys = Object.getOwnPropertyNames(left);
1444
+ const right_keys = Object.getOwnPropertyNames(right);
1445
+ if (left_keys.length !== right_keys.length)
1446
+ return false;
1447
+ for (let key of left_keys) {
1448
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
1449
+ return false;
1450
+ }
1451
+ return true;
1452
+ }
1453
+ function compare_primitive(left, right) {
1454
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1455
+ }
1461
1456
  })($ || ($ = {}));
1462
1457
  //deep.js.map
1463
1458
  ;
@@ -1810,92 +1805,6 @@ var $;
1810
1805
  ;
1811
1806
  "use strict";
1812
1807
  var $;
1813
- (function ($) {
1814
- $.$mol_test({
1815
- 'equal paths'() {
1816
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
1817
- $.$mol_assert_like(diff, {
1818
- prefix: [1, 2, 3, 4],
1819
- suffix: [[], [], []],
1820
- });
1821
- },
1822
- 'different suffix'() {
1823
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
1824
- $.$mol_assert_like(diff, {
1825
- prefix: [1, 2],
1826
- suffix: [[3, 4], [3, 5], [5, 4]],
1827
- });
1828
- },
1829
- 'one contains other'() {
1830
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
1831
- $.$mol_assert_like(diff, {
1832
- prefix: [1, 2],
1833
- suffix: [[3, 4], [], [3]],
1834
- });
1835
- },
1836
- 'fully different'() {
1837
- const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
1838
- $.$mol_assert_like(diff, {
1839
- prefix: [],
1840
- suffix: [[1, 2], [3, 4], [5, 6]],
1841
- });
1842
- },
1843
- });
1844
- })($ || ($ = {}));
1845
- //path.test.js.map
1846
- ;
1847
- "use strict";
1848
- var $;
1849
- (function ($) {
1850
- function $mol_diff_path(...paths) {
1851
- const limit = Math.min(...paths.map(path => path.length));
1852
- lookup: for (var i = 0; i < limit; ++i) {
1853
- const first = paths[0][i];
1854
- for (let j = 1; j < paths.length; ++j) {
1855
- if (paths[j][i] !== first)
1856
- break lookup;
1857
- }
1858
- }
1859
- return {
1860
- prefix: paths[0].slice(0, i),
1861
- suffix: paths.map(path => path.slice(i)),
1862
- };
1863
- }
1864
- $.$mol_diff_path = $mol_diff_path;
1865
- })($ || ($ = {}));
1866
- //path.js.map
1867
- ;
1868
- "use strict";
1869
- var $;
1870
- (function ($) {
1871
- class $mol_error_mix extends Error {
1872
- errors;
1873
- constructor(message, ...errors) {
1874
- super(message);
1875
- this.errors = errors;
1876
- if (errors.length) {
1877
- const stacks = [...errors.map(error => error.stack), this.stack];
1878
- const diff = $.$mol_diff_path(...stacks.map(stack => {
1879
- if (!stack)
1880
- return [];
1881
- return stack.split('\n').reverse();
1882
- }));
1883
- const head = diff.prefix.reverse().join('\n');
1884
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
1885
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
1886
- this.message += errors.map(error => '\n' + error.message).join('');
1887
- }
1888
- }
1889
- toJSON() {
1890
- return this.message;
1891
- }
1892
- }
1893
- $.$mol_error_mix = $mol_error_mix;
1894
- })($ || ($ = {}));
1895
- //mix.js.map
1896
- ;
1897
- "use strict";
1898
- var $;
1899
1808
  (function ($) {
1900
1809
  $.$mol_test({
1901
1810
  async 'unique index'() {