hyoo_sync_client 0.0.352 → 0.0.354

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,28 +347,15 @@ var $;
347
347
  var $;
348
348
  (function ($) {
349
349
  class $mol_error_mix extends AggregateError {
350
- name = $$.$mol_func_name(this.constructor);
351
- constructor(message, ...errors) {
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));
356
- }
357
- toJSON() {
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;
350
+ cause;
351
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
352
+ constructor(message, cause, ...errors) {
353
+ super(errors, message, { cause });
354
+ this.cause = cause;
355
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
356
+ Object.defineProperty(this, 'stack', {
357
+ get: () => stack_get.call(this) + '\n' + this.errors.map(e => e.stack.trim().replace(/at /gm, ' at ').replace(/^(?! )(.*)/gm, ' at [$1] (#)')).join('\n')
358
+ });
372
359
  }
373
360
  }
374
361
  $.$mol_error_mix = $mol_error_mix;
@@ -379,7 +366,6 @@ var $;
379
366
  var $;
380
367
  (function ($) {
381
368
  class $mol_data_error extends $mol_error_mix {
382
- name = '$mol_data_error';
383
369
  }
384
370
  $.$mol_data_error = $mol_data_error;
385
371
  })($ || ($ = {}));
package/web.test.js CHANGED
@@ -853,39 +853,29 @@ var $;
853
853
  (function ($) {
854
854
  $mol_test({
855
855
  'auto name'() {
856
- class TestError extends $mol_error_mix {
856
+ class Invalid extends $mol_error_mix {
857
857
  }
858
- const mix = new TestError('foo');
859
- $mol_assert_equal(mix.name, 'TestError');
858
+ const mix = new Invalid('foo');
859
+ $mol_assert_equal(mix.name, 'Invalid_Error');
860
860
  },
861
- 'empty mix'() {
862
- const mix = new $mol_error_mix('foo');
861
+ 'simpe mix'() {
862
+ const mix = new $mol_error_mix('foo', null, new Error('bar'), new Error('lol'));
863
863
  $mol_assert_equal(mix.message, 'foo');
864
- $mol_assert_equal(mix.cause, []);
864
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
865
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');
866
+ 'provide additional info'() {
867
+ class Invalid extends $mol_error_mix {
868
+ }
869
+ const mix = new $mol_error_mix('Wrong password', null, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
870
+ const hints = [];
871
+ if (mix instanceof $mol_error_mix) {
872
+ for (const er of mix.errors) {
873
+ if (er instanceof Invalid) {
874
+ hints.push(er.cause?.hint ?? '');
875
+ }
876
+ }
877
+ }
878
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
889
879
  },
890
880
  });
891
881
  })($ || ($ = {}));