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/web.mjs CHANGED
@@ -347,12 +347,28 @@ var $;
347
347
  var $;
348
348
  (function ($) {
349
349
  class $mol_error_mix extends AggregateError {
350
- name = '$mol_error_mix';
350
+ name = $$.$mol_func_name(this.constructor);
351
351
  constructor(message, ...errors) {
352
- super(errors, [message, ...errors.map(e => ' ' + e.message)].join('\n'));
352
+ super(errors, [message, ...errors.map(e => e.message.replace(/^/gm, ' '))].join('\n'));
353
+ }
354
+ get cause() {
355
+ return [].concat(...this.errors.map(e => e.cause).filter(Boolean));
353
356
  }
354
357
  toJSON() {
355
- return this.message;
358
+ return this.errors.map(e => e.message);
359
+ }
360
+ pick(Class) {
361
+ if (this instanceof Class)
362
+ return this;
363
+ for (const e of this.errors) {
364
+ if (e instanceof Class)
365
+ return e;
366
+ }
367
+ for (const e of this.cause) {
368
+ if (e && e instanceof Class)
369
+ return e;
370
+ }
371
+ return null;
356
372
  }
357
373
  }
358
374
  $.$mol_error_mix = $mol_error_mix;
package/web.test.js CHANGED
@@ -847,6 +847,49 @@ var $;
847
847
  });
848
848
  })($ || ($ = {}));
849
849
 
850
+ ;
851
+ "use strict";
852
+ var $;
853
+ (function ($) {
854
+ $mol_test({
855
+ 'auto name'() {
856
+ class TestError extends $mol_error_mix {
857
+ }
858
+ const mix = new TestError('foo');
859
+ $mol_assert_equal(mix.name, 'TestError');
860
+ },
861
+ 'empty mix'() {
862
+ const mix = new $mol_error_mix('foo');
863
+ $mol_assert_equal(mix.message, 'foo');
864
+ $mol_assert_equal(mix.cause, []);
865
+ },
866
+ 'simpe mix'() {
867
+ const mix = new $mol_error_mix('foo', new Error('bar', { cause: 'xxx' }), new Error('lol', { cause: 'yyy' }));
868
+ $mol_assert_equal(mix.message, 'foo\n bar\n lol');
869
+ $mol_assert_equal(mix.cause, ['xxx', 'yyy']);
870
+ },
871
+ 'mix of mixes'() {
872
+ 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' })));
873
+ $mol_assert_equal(mix.message, 'mix\n foo1\n bar1\n lol1\n foo2\n bar2\n lol2');
874
+ $mol_assert_equal(mix.cause, ['xxx1', 'yyy1', 'xxx2', 'yyy2']);
875
+ },
876
+ 'pick by class'() {
877
+ const mix = new $mol_error_mix('foo', new RangeError('bar', {
878
+ cause: [
879
+ new SyntaxError('xxx1'),
880
+ new SyntaxError('xxx2'),
881
+ new TypeError('lol0'),
882
+ ],
883
+ }), new TypeError('lol1', {
884
+ cause: new TypeError('xxx3'),
885
+ }), new TypeError('lol2'));
886
+ $mol_assert_equal(mix.pick(RangeError).message, 'bar');
887
+ $mol_assert_equal(mix.pick(SyntaxError).message, 'xxx1');
888
+ $mol_assert_equal(mix.pick(TypeError).message, 'lol1');
889
+ },
890
+ });
891
+ })($ || ($ = {}));
892
+
850
893
  ;
851
894
  "use strict";
852
895
  var $;