hyoo_sync_client 0.0.342 → 0.0.344

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.mjs CHANGED
@@ -996,12 +996,28 @@ var $;
996
996
  var $;
997
997
  (function ($) {
998
998
  class $mol_error_mix extends AggregateError {
999
- name = '$mol_error_mix';
999
+ name = $$.$mol_func_name(this.constructor);
1000
1000
  constructor(message, ...errors) {
1001
- super(errors, [message, ...errors.map(e => ' ' + e.message)].join('\n'));
1001
+ super(errors, [message, ...errors.map(e => e.message.replace(/^/gm, ' '))].join('\n'));
1002
+ }
1003
+ get cause() {
1004
+ return [].concat(...this.errors.map(e => e.cause).filter(Boolean));
1002
1005
  }
1003
1006
  toJSON() {
1004
- return this.message;
1007
+ return this.errors.map(e => e.message);
1008
+ }
1009
+ pick(Class) {
1010
+ if (this instanceof Class)
1011
+ return this;
1012
+ for (const e of this.errors) {
1013
+ if (e instanceof Class)
1014
+ return e;
1015
+ }
1016
+ for (const e of this.cause) {
1017
+ if (e && e instanceof Class)
1018
+ return e;
1019
+ }
1020
+ return null;
1005
1021
  }
1006
1022
  }
1007
1023
  $.$mol_error_mix = $mol_error_mix;
package/node.test.js CHANGED
@@ -987,12 +987,28 @@ var $;
987
987
  var $;
988
988
  (function ($) {
989
989
  class $mol_error_mix extends AggregateError {
990
- name = '$mol_error_mix';
990
+ name = $$.$mol_func_name(this.constructor);
991
991
  constructor(message, ...errors) {
992
- super(errors, [message, ...errors.map(e => ' ' + e.message)].join('\n'));
992
+ super(errors, [message, ...errors.map(e => e.message.replace(/^/gm, ' '))].join('\n'));
993
+ }
994
+ get cause() {
995
+ return [].concat(...this.errors.map(e => e.cause).filter(Boolean));
993
996
  }
994
997
  toJSON() {
995
- return this.message;
998
+ return this.errors.map(e => e.message);
999
+ }
1000
+ pick(Class) {
1001
+ if (this instanceof Class)
1002
+ return this;
1003
+ for (const e of this.errors) {
1004
+ if (e instanceof Class)
1005
+ return e;
1006
+ }
1007
+ for (const e of this.cause) {
1008
+ if (e && e instanceof Class)
1009
+ return e;
1010
+ }
1011
+ return null;
996
1012
  }
997
1013
  }
998
1014
  $.$mol_error_mix = $mol_error_mix;
@@ -5635,6 +5651,49 @@ var $;
5635
5651
  });
5636
5652
  })($ || ($ = {}));
5637
5653
 
5654
+ ;
5655
+ "use strict";
5656
+ var $;
5657
+ (function ($) {
5658
+ $mol_test({
5659
+ 'auto name'() {
5660
+ class TestError extends $mol_error_mix {
5661
+ }
5662
+ const mix = new TestError('foo');
5663
+ $mol_assert_equal(mix.name, 'TestError');
5664
+ },
5665
+ 'empty mix'() {
5666
+ const mix = new $mol_error_mix('foo');
5667
+ $mol_assert_equal(mix.message, 'foo');
5668
+ $mol_assert_equal(mix.cause, []);
5669
+ },
5670
+ 'simpe mix'() {
5671
+ const mix = new $mol_error_mix('foo', new Error('bar', { cause: 'xxx' }), new Error('lol', { cause: 'yyy' }));
5672
+ $mol_assert_equal(mix.message, 'foo\n bar\n lol');
5673
+ $mol_assert_equal(mix.cause, ['xxx', 'yyy']);
5674
+ },
5675
+ 'mix of mixes'() {
5676
+ const mix = new $mol_error_mix('mix', new $mol_error_mix('foo1', new Error('bar1', { cause: 'xxx1' }), new Error('lol1', { cause: 'yyy1' })), new $mol_error_mix('foo2', new Error('bar2', { cause: 'xxx2' }), new Error('lol2', { cause: 'yyy2' })));
5677
+ $mol_assert_equal(mix.message, 'mix\n foo1\n bar1\n lol1\n foo2\n bar2\n lol2');
5678
+ $mol_assert_equal(mix.cause, ['xxx1', 'yyy1', 'xxx2', 'yyy2']);
5679
+ },
5680
+ 'pick by class'() {
5681
+ const mix = new $mol_error_mix('foo', new RangeError('bar', {
5682
+ cause: [
5683
+ new SyntaxError('xxx1'),
5684
+ new SyntaxError('xxx2'),
5685
+ new TypeError('lol0'),
5686
+ ],
5687
+ }), new TypeError('lol1', {
5688
+ cause: new TypeError('xxx3'),
5689
+ }), new TypeError('lol2'));
5690
+ $mol_assert_equal(mix.pick(RangeError).message, 'bar');
5691
+ $mol_assert_equal(mix.pick(SyntaxError).message, 'xxx1');
5692
+ $mol_assert_equal(mix.pick(TypeError).message, 'lol1');
5693
+ },
5694
+ });
5695
+ })($ || ($ = {}));
5696
+
5638
5697
  ;
5639
5698
  "use strict";
5640
5699
  var $;