@twin.org/core 0.0.2-next.4 → 0.0.2-next.5

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.
Files changed (36) hide show
  1. package/dist/cjs/index.cjs +76 -46
  2. package/dist/esm/index.mjs +76 -46
  3. package/dist/types/errors/alreadyExistsError.d.ts +2 -2
  4. package/dist/types/errors/baseError.d.ts +18 -5
  5. package/dist/types/errors/conflictError.d.ts +2 -2
  6. package/dist/types/errors/generalError.d.ts +2 -2
  7. package/dist/types/errors/notFoundError.d.ts +2 -2
  8. package/dist/types/errors/notSupportedError.d.ts +2 -2
  9. package/dist/types/errors/unauthorizedError.d.ts +2 -2
  10. package/dist/types/errors/unprocessableError.d.ts +2 -2
  11. package/dist/types/factories/factory.d.ts +1 -1
  12. package/dist/types/helpers/errorHelper.d.ts +3 -3
  13. package/dist/types/models/IComponent.d.ts +6 -15
  14. package/dist/types/models/IError.d.ts +2 -2
  15. package/docs/changelog.md +17 -0
  16. package/docs/reference/classes/AlreadyExistsError.md +66 -8
  17. package/docs/reference/classes/BaseError.md +62 -8
  18. package/docs/reference/classes/ConflictError.md +66 -8
  19. package/docs/reference/classes/EnvHelper.md +1 -1
  20. package/docs/reference/classes/ErrorHelper.md +3 -3
  21. package/docs/reference/classes/Factory.md +2 -2
  22. package/docs/reference/classes/GeneralError.md +66 -8
  23. package/docs/reference/classes/GuardError.md +63 -5
  24. package/docs/reference/classes/Guards.md +2 -2
  25. package/docs/reference/classes/I18n.md +2 -2
  26. package/docs/reference/classes/Is.md +2 -2
  27. package/docs/reference/classes/NotFoundError.md +66 -8
  28. package/docs/reference/classes/NotImplementedError.md +63 -5
  29. package/docs/reference/classes/NotSupportedError.md +66 -8
  30. package/docs/reference/classes/UnauthorizedError.md +66 -8
  31. package/docs/reference/classes/UnprocessableError.md +66 -8
  32. package/docs/reference/classes/Validation.md +1 -1
  33. package/docs/reference/classes/ValidationError.md +63 -5
  34. package/docs/reference/interfaces/IComponent.md +9 -21
  35. package/docs/reference/interfaces/IError.md +3 -3
  36. package/package.json +2 -2
@@ -631,31 +631,33 @@ class BaseError extends Error {
631
631
  */
632
632
  properties;
633
633
  /**
634
- * The inner error if there was one.
634
+ * The cause of the error.
635
635
  */
636
- inner;
636
+ cause;
637
637
  /**
638
638
  * Create a new instance of BaseError.
639
639
  * @param name The name of the error.
640
640
  * @param source The source of the error.
641
641
  * @param message The message as a code.
642
642
  * @param properties Any additional information for the error.
643
- * @param inner The inner error if we have wrapped another error.
643
+ * @param cause The cause of error if we have wrapped another error.
644
644
  */
645
- constructor(name, source, message, properties, inner) {
645
+ constructor(name, source, message, properties, cause) {
646
646
  super(message);
647
647
  this.name = name;
648
648
  this.source = source;
649
+ this.cause = Is.notEmpty(cause) ? BaseError.fromError(cause).toJsonObject(true) : undefined;
650
+ this.properties = properties;
649
651
  // If the message is camel case but has no namespace then prefix it
650
- // with the source name in camel case
652
+ // with the source name in camel case.
651
653
  if (Is.stringValue(source) &&
652
654
  Is.stringValue(message) &&
653
655
  !message.includes(".") &&
656
+ // This comparison checks that it is most likely a camel case name
657
+ // and not a free text error with a dot in it
654
658
  StringHelper.camelCase(message) === message) {
655
659
  this.message = `${StringHelper.camelCase(source)}.${message}`;
656
660
  }
657
- this.properties = properties;
658
- this.inner = inner ? BaseError.fromError(inner).toJsonObject() : undefined;
659
661
  }
660
662
  /**
661
663
  * Construct an error from an existing one.
@@ -667,7 +669,7 @@ class BaseError extends Error {
667
669
  let message;
668
670
  let source;
669
671
  let properties;
670
- let inner;
672
+ let cause;
671
673
  let stack;
672
674
  if (Is.object(err) && Is.stringValue(err.error)) {
673
675
  message = err.error;
@@ -685,8 +687,12 @@ class BaseError extends Error {
685
687
  if (Is.notEmpty(err.properties)) {
686
688
  properties = err.properties;
687
689
  }
688
- if (Is.notEmpty(err.inner)) {
689
- inner = err.inner;
690
+ if (BaseError.isAggregateError(err)) {
691
+ properties ??= {};
692
+ properties.errors = err.errors;
693
+ }
694
+ if (Is.notEmpty(err.cause)) {
695
+ cause = err.cause;
690
696
  }
691
697
  if (Is.notEmpty(err.stack)) {
692
698
  stack = err.stack;
@@ -698,7 +704,7 @@ class BaseError extends Error {
698
704
  else {
699
705
  message = JSON.stringify(err);
700
706
  }
701
- const baseError = new BaseError(name, source ?? "", message ?? "", properties, inner);
707
+ const baseError = new BaseError(name, source ?? "", message ?? "", properties, cause);
702
708
  baseError.stack = stack;
703
709
  return baseError;
704
710
  }
@@ -711,10 +717,10 @@ class BaseError extends Error {
711
717
  const flattened = [];
712
718
  let e = BaseError.fromError(err).toJsonObject(true);
713
719
  while (e) {
714
- const inner = e.inner;
715
- e.inner = undefined;
720
+ const cause = e.cause;
721
+ e.cause = undefined;
716
722
  flattened.push(e);
717
- e = inner;
723
+ e = cause;
718
724
  }
719
725
  return flattened;
720
726
  }
@@ -729,8 +735,8 @@ class BaseError extends Error {
729
735
  first = errors[0];
730
736
  let current = first;
731
737
  for (let i = 1; i < errors.length; i++) {
732
- current.inner = errors[i];
733
- current = current.inner;
738
+ current.cause = errors[i];
739
+ current = current.cause;
734
740
  }
735
741
  }
736
742
  return first;
@@ -804,7 +810,7 @@ class BaseError extends Error {
804
810
  return BaseError.flatten(error).some(e => BaseError.isErrorCode(e, code));
805
811
  }
806
812
  /**
807
- * Is the error empty.
813
+ * Is the error empty, i.e. does it have no message, source, properties, or cause?
808
814
  * @param err The error to check for being empty.
809
815
  * @returns True if the error is empty.
810
816
  */
@@ -812,7 +818,27 @@ class BaseError extends Error {
812
818
  return (!Is.stringValue(err.message) &&
813
819
  !Is.stringValue(err.source) &&
814
820
  !Is.objectValue(err.properties) &&
815
- Is.empty(err.inner));
821
+ Is.empty(err.cause));
822
+ }
823
+ /**
824
+ * Is the error an aggregate error.
825
+ * @param err The error to check for being an aggregate error.
826
+ * @returns True if the error is an aggregate error.
827
+ */
828
+ static isAggregateError(err) {
829
+ return err instanceof AggregateError;
830
+ }
831
+ /**
832
+ * Convert the aggregate error to an array of errors.
833
+ * @param err The error to convert.
834
+ * @param includeStackTrace Whether to include the error stack in the model, defaults to false.
835
+ * @returns The array of errors.
836
+ */
837
+ static fromAggregate(err, includeStackTrace) {
838
+ if (BaseError.isAggregateError(err)) {
839
+ return err.errors.map(e => BaseError.fromError(e).toJsonObject(includeStackTrace));
840
+ }
841
+ return [BaseError.fromError(err).toJsonObject(includeStackTrace)];
816
842
  }
817
843
  /**
818
844
  * Serialize the error to the error model.
@@ -836,8 +862,8 @@ class BaseError extends Error {
836
862
  if ((includeStackTrace ?? false) && Is.stringValue(this.stack)) {
837
863
  err.stack = this.stack;
838
864
  }
839
- if (Is.notEmpty(this.inner)) {
840
- err.inner = BaseError.fromError(this.inner).toJsonObject(includeStackTrace);
865
+ if (Is.notEmpty(this.cause)) {
866
+ err.cause = BaseError.fromError(this.cause).toJsonObject(includeStackTrace);
841
867
  }
842
868
  return err;
843
869
  }
@@ -856,10 +882,10 @@ class GeneralError extends BaseError {
856
882
  * @param source The source of the error.
857
883
  * @param message The message as a code.
858
884
  * @param properties Any additional information for the error.
859
- * @param inner The inner error if we have wrapped another error.
885
+ * @param cause The cause of the error if we have wrapped another error.
860
886
  */
861
- constructor(source, message, properties, inner) {
862
- super(GeneralError.CLASS_NAME, source, message, properties, inner);
887
+ constructor(source, message, properties, cause) {
888
+ super(GeneralError.CLASS_NAME, source, message, properties, cause);
863
889
  }
864
890
  }
865
891
 
@@ -1778,10 +1804,10 @@ class AlreadyExistsError extends BaseError {
1778
1804
  * @param source The source of the error.
1779
1805
  * @param message The message as a code.
1780
1806
  * @param existingId The id for the item.
1781
- * @param inner The inner error if we have wrapped another error.
1807
+ * @param cause The cause of the error if we have wrapped another error.
1782
1808
  */
1783
- constructor(source, message, existingId, inner) {
1784
- super(AlreadyExistsError.CLASS_NAME, source, message, { existingId }, inner);
1809
+ constructor(source, message, existingId, cause) {
1810
+ super(AlreadyExistsError.CLASS_NAME, source, message, { existingId });
1785
1811
  }
1786
1812
  }
1787
1813
 
@@ -1799,10 +1825,10 @@ class ConflictError extends BaseError {
1799
1825
  * @param message The message as a code.
1800
1826
  * @param conflictId The id that has conflicts.
1801
1827
  * @param conflicts The conflicts that occurred.
1802
- * @param inner The inner error if we have wrapped another error.
1828
+ * @param cause The cause or the error if we have wrapped another error.
1803
1829
  */
1804
- constructor(source, message, conflictId, conflicts, inner) {
1805
- super(ConflictError.CLASS_NAME, source, message, { conflictId, conflicts }, inner);
1830
+ constructor(source, message, conflictId, conflicts, cause) {
1831
+ super(ConflictError.CLASS_NAME, source, message, { conflictId, conflicts }, cause);
1806
1832
  }
1807
1833
  }
1808
1834
 
@@ -1819,10 +1845,10 @@ class NotFoundError extends BaseError {
1819
1845
  * @param source The source of the error.
1820
1846
  * @param message The message as a code.
1821
1847
  * @param notFoundId The id for the item.
1822
- * @param inner The inner error if we have wrapped another error.
1848
+ * @param cause The cause of the error if we have wrapped another error.
1823
1849
  */
1824
- constructor(source, message, notFoundId, inner) {
1825
- super(NotFoundError.CLASS_NAME, source, message, { notFoundId }, inner);
1850
+ constructor(source, message, notFoundId, cause) {
1851
+ super(NotFoundError.CLASS_NAME, source, message, { notFoundId }, cause);
1826
1852
  }
1827
1853
  }
1828
1854
 
@@ -1858,10 +1884,10 @@ class NotSupportedError extends BaseError {
1858
1884
  * Create a new instance of NotSupportedError.
1859
1885
  * @param source The source of the error.
1860
1886
  * @param message The message as a code.
1861
- * @param inner The inner error if we have wrapped another error.
1887
+ * @param cause The cause of the error if we have wrapped another error.
1862
1888
  */
1863
- constructor(source, message, inner) {
1864
- super(NotSupportedError.CLASS_NAME, source, message, undefined, inner);
1889
+ constructor(source, message, cause) {
1890
+ super(NotSupportedError.CLASS_NAME, source, message, undefined, cause);
1865
1891
  }
1866
1892
  }
1867
1893
 
@@ -1877,10 +1903,10 @@ class UnauthorizedError extends BaseError {
1877
1903
  * Create a new instance of UnauthorizedError.
1878
1904
  * @param source The source of the error.
1879
1905
  * @param message The message as a code.
1880
- * @param inner The inner error if we have wrapped another error.
1906
+ * @param cause The cause of the error if we have wrapped another error.
1881
1907
  */
1882
- constructor(source, message, inner) {
1883
- super(UnauthorizedError.CLASS_NAME, source, message, undefined, inner);
1908
+ constructor(source, message, cause) {
1909
+ super(UnauthorizedError.CLASS_NAME, source, message, undefined, cause);
1884
1910
  }
1885
1911
  }
1886
1912
 
@@ -1897,10 +1923,10 @@ class UnprocessableError extends BaseError {
1897
1923
  * @param source The source of the error.
1898
1924
  * @param message The message as a code.
1899
1925
  * @param properties Any additional information for the error.
1900
- * @param inner The inner error if we have wrapped another error.
1926
+ * @param cause The cause of the error if we have wrapped another error.
1901
1927
  */
1902
- constructor(source, message, properties, inner) {
1903
- super(UnprocessableError.CLASS_NAME, source, message, properties, inner);
1928
+ constructor(source, message, properties, cause) {
1929
+ super(UnprocessableError.CLASS_NAME, source, message, properties, cause);
1904
1930
  }
1905
1931
  }
1906
1932
 
@@ -2115,6 +2141,7 @@ class Factory {
2115
2141
  * @throws GeneralError if no item exists to get.
2116
2142
  */
2117
2143
  get(name) {
2144
+ Guards.stringValue(Factory._CLASS_NAME, "name", name);
2118
2145
  const instance = this.getIfExists(name);
2119
2146
  if (!instance) {
2120
2147
  throw new GeneralError(Factory._CLASS_NAME, "noGet", {
@@ -2130,6 +2157,9 @@ class Factory {
2130
2157
  * @returns An instance of the item or undefined if it does not exist.
2131
2158
  */
2132
2159
  getIfExists(name) {
2160
+ if (Is.empty(name)) {
2161
+ return;
2162
+ }
2133
2163
  Guards.stringValue(Factory._CLASS_NAME, "name", name);
2134
2164
  const matchName = this._matcher(Object.keys(this._generators), name);
2135
2165
  if (Is.stringValue(matchName) && this._generators[matchName]) {
@@ -3158,7 +3188,7 @@ class ErrorHelper {
3158
3188
  * Format Errors and returns just their messages.
3159
3189
  * @param error The error to format.
3160
3190
  * @param includeDetails Whether to include error details, defaults to false.
3161
- * @returns The error formatted including any inner errors.
3191
+ * @returns The error formatted including any causes errors.
3162
3192
  */
3163
3193
  static formatErrors(error, includeDetails) {
3164
3194
  const localizedErrors = ErrorHelper.localizeErrors(error);
@@ -3176,7 +3206,7 @@ class ErrorHelper {
3176
3206
  return localizedErrors.map(e => e.message);
3177
3207
  }
3178
3208
  /**
3179
- * Localize the content of an error and any inner errors.
3209
+ * Localize the content of an error and any causes.
3180
3210
  * @param error The error to format.
3181
3211
  * @returns The localized version of the errors flattened.
3182
3212
  */
@@ -3217,7 +3247,7 @@ class ErrorHelper {
3217
3247
  return formattedErrors;
3218
3248
  }
3219
3249
  /**
3220
- * Localize the content of an error and any inner errors.
3250
+ * Localize the content of an error and any causes.
3221
3251
  * @param error The error to format.
3222
3252
  * @returns The localized version of the errors flattened.
3223
3253
  */
@@ -4285,7 +4315,7 @@ class Compression {
4285
4315
  static async compress(bytes, type) {
4286
4316
  Guards.uint8Array(Compression._CLASS_NAME, "bytes", bytes);
4287
4317
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
4288
- const blob = new Blob([bytes]);
4318
+ const blob = new Blob([new Uint8Array(bytes)]);
4289
4319
  const compressionStream = new CompressionStream(type);
4290
4320
  const compressionPipe = blob.stream().pipeThrough(compressionStream);
4291
4321
  const compressedBlob = await new Response(compressionPipe).blob();
@@ -4307,7 +4337,7 @@ class Compression {
4307
4337
  static async decompress(compressedBytes, type) {
4308
4338
  Guards.uint8Array(Compression._CLASS_NAME, "compressedBytes", compressedBytes);
4309
4339
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
4310
- const blob = new Blob([compressedBytes]);
4340
+ const blob = new Blob([new Uint8Array(compressedBytes)]);
4311
4341
  const decompressionStream = new DecompressionStream(type);
4312
4342
  const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
4313
4343
  const decompressedBlob = await new Response(decompressionPipe).blob();
@@ -629,31 +629,33 @@ class BaseError extends Error {
629
629
  */
630
630
  properties;
631
631
  /**
632
- * The inner error if there was one.
632
+ * The cause of the error.
633
633
  */
634
- inner;
634
+ cause;
635
635
  /**
636
636
  * Create a new instance of BaseError.
637
637
  * @param name The name of the error.
638
638
  * @param source The source of the error.
639
639
  * @param message The message as a code.
640
640
  * @param properties Any additional information for the error.
641
- * @param inner The inner error if we have wrapped another error.
641
+ * @param cause The cause of error if we have wrapped another error.
642
642
  */
643
- constructor(name, source, message, properties, inner) {
643
+ constructor(name, source, message, properties, cause) {
644
644
  super(message);
645
645
  this.name = name;
646
646
  this.source = source;
647
+ this.cause = Is.notEmpty(cause) ? BaseError.fromError(cause).toJsonObject(true) : undefined;
648
+ this.properties = properties;
647
649
  // If the message is camel case but has no namespace then prefix it
648
- // with the source name in camel case
650
+ // with the source name in camel case.
649
651
  if (Is.stringValue(source) &&
650
652
  Is.stringValue(message) &&
651
653
  !message.includes(".") &&
654
+ // This comparison checks that it is most likely a camel case name
655
+ // and not a free text error with a dot in it
652
656
  StringHelper.camelCase(message) === message) {
653
657
  this.message = `${StringHelper.camelCase(source)}.${message}`;
654
658
  }
655
- this.properties = properties;
656
- this.inner = inner ? BaseError.fromError(inner).toJsonObject() : undefined;
657
659
  }
658
660
  /**
659
661
  * Construct an error from an existing one.
@@ -665,7 +667,7 @@ class BaseError extends Error {
665
667
  let message;
666
668
  let source;
667
669
  let properties;
668
- let inner;
670
+ let cause;
669
671
  let stack;
670
672
  if (Is.object(err) && Is.stringValue(err.error)) {
671
673
  message = err.error;
@@ -683,8 +685,12 @@ class BaseError extends Error {
683
685
  if (Is.notEmpty(err.properties)) {
684
686
  properties = err.properties;
685
687
  }
686
- if (Is.notEmpty(err.inner)) {
687
- inner = err.inner;
688
+ if (BaseError.isAggregateError(err)) {
689
+ properties ??= {};
690
+ properties.errors = err.errors;
691
+ }
692
+ if (Is.notEmpty(err.cause)) {
693
+ cause = err.cause;
688
694
  }
689
695
  if (Is.notEmpty(err.stack)) {
690
696
  stack = err.stack;
@@ -696,7 +702,7 @@ class BaseError extends Error {
696
702
  else {
697
703
  message = JSON.stringify(err);
698
704
  }
699
- const baseError = new BaseError(name, source ?? "", message ?? "", properties, inner);
705
+ const baseError = new BaseError(name, source ?? "", message ?? "", properties, cause);
700
706
  baseError.stack = stack;
701
707
  return baseError;
702
708
  }
@@ -709,10 +715,10 @@ class BaseError extends Error {
709
715
  const flattened = [];
710
716
  let e = BaseError.fromError(err).toJsonObject(true);
711
717
  while (e) {
712
- const inner = e.inner;
713
- e.inner = undefined;
718
+ const cause = e.cause;
719
+ e.cause = undefined;
714
720
  flattened.push(e);
715
- e = inner;
721
+ e = cause;
716
722
  }
717
723
  return flattened;
718
724
  }
@@ -727,8 +733,8 @@ class BaseError extends Error {
727
733
  first = errors[0];
728
734
  let current = first;
729
735
  for (let i = 1; i < errors.length; i++) {
730
- current.inner = errors[i];
731
- current = current.inner;
736
+ current.cause = errors[i];
737
+ current = current.cause;
732
738
  }
733
739
  }
734
740
  return first;
@@ -802,7 +808,7 @@ class BaseError extends Error {
802
808
  return BaseError.flatten(error).some(e => BaseError.isErrorCode(e, code));
803
809
  }
804
810
  /**
805
- * Is the error empty.
811
+ * Is the error empty, i.e. does it have no message, source, properties, or cause?
806
812
  * @param err The error to check for being empty.
807
813
  * @returns True if the error is empty.
808
814
  */
@@ -810,7 +816,27 @@ class BaseError extends Error {
810
816
  return (!Is.stringValue(err.message) &&
811
817
  !Is.stringValue(err.source) &&
812
818
  !Is.objectValue(err.properties) &&
813
- Is.empty(err.inner));
819
+ Is.empty(err.cause));
820
+ }
821
+ /**
822
+ * Is the error an aggregate error.
823
+ * @param err The error to check for being an aggregate error.
824
+ * @returns True if the error is an aggregate error.
825
+ */
826
+ static isAggregateError(err) {
827
+ return err instanceof AggregateError;
828
+ }
829
+ /**
830
+ * Convert the aggregate error to an array of errors.
831
+ * @param err The error to convert.
832
+ * @param includeStackTrace Whether to include the error stack in the model, defaults to false.
833
+ * @returns The array of errors.
834
+ */
835
+ static fromAggregate(err, includeStackTrace) {
836
+ if (BaseError.isAggregateError(err)) {
837
+ return err.errors.map(e => BaseError.fromError(e).toJsonObject(includeStackTrace));
838
+ }
839
+ return [BaseError.fromError(err).toJsonObject(includeStackTrace)];
814
840
  }
815
841
  /**
816
842
  * Serialize the error to the error model.
@@ -834,8 +860,8 @@ class BaseError extends Error {
834
860
  if ((includeStackTrace ?? false) && Is.stringValue(this.stack)) {
835
861
  err.stack = this.stack;
836
862
  }
837
- if (Is.notEmpty(this.inner)) {
838
- err.inner = BaseError.fromError(this.inner).toJsonObject(includeStackTrace);
863
+ if (Is.notEmpty(this.cause)) {
864
+ err.cause = BaseError.fromError(this.cause).toJsonObject(includeStackTrace);
839
865
  }
840
866
  return err;
841
867
  }
@@ -854,10 +880,10 @@ class GeneralError extends BaseError {
854
880
  * @param source The source of the error.
855
881
  * @param message The message as a code.
856
882
  * @param properties Any additional information for the error.
857
- * @param inner The inner error if we have wrapped another error.
883
+ * @param cause The cause of the error if we have wrapped another error.
858
884
  */
859
- constructor(source, message, properties, inner) {
860
- super(GeneralError.CLASS_NAME, source, message, properties, inner);
885
+ constructor(source, message, properties, cause) {
886
+ super(GeneralError.CLASS_NAME, source, message, properties, cause);
861
887
  }
862
888
  }
863
889
 
@@ -1776,10 +1802,10 @@ class AlreadyExistsError extends BaseError {
1776
1802
  * @param source The source of the error.
1777
1803
  * @param message The message as a code.
1778
1804
  * @param existingId The id for the item.
1779
- * @param inner The inner error if we have wrapped another error.
1805
+ * @param cause The cause of the error if we have wrapped another error.
1780
1806
  */
1781
- constructor(source, message, existingId, inner) {
1782
- super(AlreadyExistsError.CLASS_NAME, source, message, { existingId }, inner);
1807
+ constructor(source, message, existingId, cause) {
1808
+ super(AlreadyExistsError.CLASS_NAME, source, message, { existingId });
1783
1809
  }
1784
1810
  }
1785
1811
 
@@ -1797,10 +1823,10 @@ class ConflictError extends BaseError {
1797
1823
  * @param message The message as a code.
1798
1824
  * @param conflictId The id that has conflicts.
1799
1825
  * @param conflicts The conflicts that occurred.
1800
- * @param inner The inner error if we have wrapped another error.
1826
+ * @param cause The cause or the error if we have wrapped another error.
1801
1827
  */
1802
- constructor(source, message, conflictId, conflicts, inner) {
1803
- super(ConflictError.CLASS_NAME, source, message, { conflictId, conflicts }, inner);
1828
+ constructor(source, message, conflictId, conflicts, cause) {
1829
+ super(ConflictError.CLASS_NAME, source, message, { conflictId, conflicts }, cause);
1804
1830
  }
1805
1831
  }
1806
1832
 
@@ -1817,10 +1843,10 @@ class NotFoundError extends BaseError {
1817
1843
  * @param source The source of the error.
1818
1844
  * @param message The message as a code.
1819
1845
  * @param notFoundId The id for the item.
1820
- * @param inner The inner error if we have wrapped another error.
1846
+ * @param cause The cause of the error if we have wrapped another error.
1821
1847
  */
1822
- constructor(source, message, notFoundId, inner) {
1823
- super(NotFoundError.CLASS_NAME, source, message, { notFoundId }, inner);
1848
+ constructor(source, message, notFoundId, cause) {
1849
+ super(NotFoundError.CLASS_NAME, source, message, { notFoundId }, cause);
1824
1850
  }
1825
1851
  }
1826
1852
 
@@ -1856,10 +1882,10 @@ class NotSupportedError extends BaseError {
1856
1882
  * Create a new instance of NotSupportedError.
1857
1883
  * @param source The source of the error.
1858
1884
  * @param message The message as a code.
1859
- * @param inner The inner error if we have wrapped another error.
1885
+ * @param cause The cause of the error if we have wrapped another error.
1860
1886
  */
1861
- constructor(source, message, inner) {
1862
- super(NotSupportedError.CLASS_NAME, source, message, undefined, inner);
1887
+ constructor(source, message, cause) {
1888
+ super(NotSupportedError.CLASS_NAME, source, message, undefined, cause);
1863
1889
  }
1864
1890
  }
1865
1891
 
@@ -1875,10 +1901,10 @@ class UnauthorizedError extends BaseError {
1875
1901
  * Create a new instance of UnauthorizedError.
1876
1902
  * @param source The source of the error.
1877
1903
  * @param message The message as a code.
1878
- * @param inner The inner error if we have wrapped another error.
1904
+ * @param cause The cause of the error if we have wrapped another error.
1879
1905
  */
1880
- constructor(source, message, inner) {
1881
- super(UnauthorizedError.CLASS_NAME, source, message, undefined, inner);
1906
+ constructor(source, message, cause) {
1907
+ super(UnauthorizedError.CLASS_NAME, source, message, undefined, cause);
1882
1908
  }
1883
1909
  }
1884
1910
 
@@ -1895,10 +1921,10 @@ class UnprocessableError extends BaseError {
1895
1921
  * @param source The source of the error.
1896
1922
  * @param message The message as a code.
1897
1923
  * @param properties Any additional information for the error.
1898
- * @param inner The inner error if we have wrapped another error.
1924
+ * @param cause The cause of the error if we have wrapped another error.
1899
1925
  */
1900
- constructor(source, message, properties, inner) {
1901
- super(UnprocessableError.CLASS_NAME, source, message, properties, inner);
1926
+ constructor(source, message, properties, cause) {
1927
+ super(UnprocessableError.CLASS_NAME, source, message, properties, cause);
1902
1928
  }
1903
1929
  }
1904
1930
 
@@ -2113,6 +2139,7 @@ class Factory {
2113
2139
  * @throws GeneralError if no item exists to get.
2114
2140
  */
2115
2141
  get(name) {
2142
+ Guards.stringValue(Factory._CLASS_NAME, "name", name);
2116
2143
  const instance = this.getIfExists(name);
2117
2144
  if (!instance) {
2118
2145
  throw new GeneralError(Factory._CLASS_NAME, "noGet", {
@@ -2128,6 +2155,9 @@ class Factory {
2128
2155
  * @returns An instance of the item or undefined if it does not exist.
2129
2156
  */
2130
2157
  getIfExists(name) {
2158
+ if (Is.empty(name)) {
2159
+ return;
2160
+ }
2131
2161
  Guards.stringValue(Factory._CLASS_NAME, "name", name);
2132
2162
  const matchName = this._matcher(Object.keys(this._generators), name);
2133
2163
  if (Is.stringValue(matchName) && this._generators[matchName]) {
@@ -3156,7 +3186,7 @@ class ErrorHelper {
3156
3186
  * Format Errors and returns just their messages.
3157
3187
  * @param error The error to format.
3158
3188
  * @param includeDetails Whether to include error details, defaults to false.
3159
- * @returns The error formatted including any inner errors.
3189
+ * @returns The error formatted including any causes errors.
3160
3190
  */
3161
3191
  static formatErrors(error, includeDetails) {
3162
3192
  const localizedErrors = ErrorHelper.localizeErrors(error);
@@ -3174,7 +3204,7 @@ class ErrorHelper {
3174
3204
  return localizedErrors.map(e => e.message);
3175
3205
  }
3176
3206
  /**
3177
- * Localize the content of an error and any inner errors.
3207
+ * Localize the content of an error and any causes.
3178
3208
  * @param error The error to format.
3179
3209
  * @returns The localized version of the errors flattened.
3180
3210
  */
@@ -3215,7 +3245,7 @@ class ErrorHelper {
3215
3245
  return formattedErrors;
3216
3246
  }
3217
3247
  /**
3218
- * Localize the content of an error and any inner errors.
3248
+ * Localize the content of an error and any causes.
3219
3249
  * @param error The error to format.
3220
3250
  * @returns The localized version of the errors flattened.
3221
3251
  */
@@ -4283,7 +4313,7 @@ class Compression {
4283
4313
  static async compress(bytes, type) {
4284
4314
  Guards.uint8Array(Compression._CLASS_NAME, "bytes", bytes);
4285
4315
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
4286
- const blob = new Blob([bytes]);
4316
+ const blob = new Blob([new Uint8Array(bytes)]);
4287
4317
  const compressionStream = new CompressionStream(type);
4288
4318
  const compressionPipe = blob.stream().pipeThrough(compressionStream);
4289
4319
  const compressedBlob = await new Response(compressionPipe).blob();
@@ -4305,7 +4335,7 @@ class Compression {
4305
4335
  static async decompress(compressedBytes, type) {
4306
4336
  Guards.uint8Array(Compression._CLASS_NAME, "compressedBytes", compressedBytes);
4307
4337
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
4308
- const blob = new Blob([compressedBytes]);
4338
+ const blob = new Blob([new Uint8Array(compressedBytes)]);
4309
4339
  const decompressionStream = new DecompressionStream(type);
4310
4340
  const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
4311
4341
  const decompressedBlob = await new Response(decompressionPipe).blob();
@@ -12,7 +12,7 @@ export declare class AlreadyExistsError extends BaseError {
12
12
  * @param source The source of the error.
13
13
  * @param message The message as a code.
14
14
  * @param existingId The id for the item.
15
- * @param inner The inner error if we have wrapped another error.
15
+ * @param cause The cause of the error if we have wrapped another error.
16
16
  */
17
- constructor(source: string, message: string, existingId?: string, inner?: unknown);
17
+ constructor(source: string, message: string, existingId?: string, cause?: unknown);
18
18
  }
@@ -14,20 +14,20 @@ export declare class BaseError extends Error implements IError {
14
14
  [id: string]: unknown;
15
15
  };
16
16
  /**
17
- * The inner error if there was one.
17
+ * The cause of the error.
18
18
  */
19
- inner?: IError;
19
+ cause?: IError;
20
20
  /**
21
21
  * Create a new instance of BaseError.
22
22
  * @param name The name of the error.
23
23
  * @param source The source of the error.
24
24
  * @param message The message as a code.
25
25
  * @param properties Any additional information for the error.
26
- * @param inner The inner error if we have wrapped another error.
26
+ * @param cause The cause of error if we have wrapped another error.
27
27
  */
28
28
  constructor(name: string, source: string, message: string, properties?: {
29
29
  [id: string]: unknown;
30
- }, inner?: unknown);
30
+ }, cause?: unknown);
31
31
  /**
32
32
  * Construct an error from an existing one.
33
33
  * @param err The existing error.
@@ -96,11 +96,24 @@ export declare class BaseError extends Error implements IError {
96
96
  */
97
97
  static someErrorCode(error: unknown, code: string | RegExp): error is BaseError;
98
98
  /**
99
- * Is the error empty.
99
+ * Is the error empty, i.e. does it have no message, source, properties, or cause?
100
100
  * @param err The error to check for being empty.
101
101
  * @returns True if the error is empty.
102
102
  */
103
103
  static isEmpty(err: IError): boolean;
104
+ /**
105
+ * Is the error an aggregate error.
106
+ * @param err The error to check for being an aggregate error.
107
+ * @returns True if the error is an aggregate error.
108
+ */
109
+ static isAggregateError(err: unknown): err is AggregateError;
110
+ /**
111
+ * Convert the aggregate error to an array of errors.
112
+ * @param err The error to convert.
113
+ * @param includeStackTrace Whether to include the error stack in the model, defaults to false.
114
+ * @returns The array of errors.
115
+ */
116
+ static fromAggregate(err: unknown, includeStackTrace?: boolean): IError[];
104
117
  /**
105
118
  * Serialize the error to the error model.
106
119
  * @param includeStackTrace Whether to include the error stack in the model, defaults to false.