@itwin/core-i18n 5.7.0-dev.8 → 5.7.0

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.
@@ -21352,30 +21352,58 @@ class Logger {
21352
21352
  const minLevel = Logger.getLevel(category);
21353
21353
  return (minLevel !== undefined) && (level >= minLevel);
21354
21354
  }
21355
- /** Log the specified message to the **error** stream.
21356
- * @param category The category of the message.
21357
- * @param message The message.
21358
- * @param metaData Optional data for the message
21359
- */
21360
- static logError(category, message, metaData) {
21361
- if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))
21362
- Logger._logError(category, message, metaData);
21355
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
21356
+ static logError(category, messageOrError, metaData) {
21357
+ if (Logger._logError && Logger.isEnabled(category, LogLevel.Error)) {
21358
+ if (typeof messageOrError === "string") {
21359
+ Logger._logError(category, messageOrError, metaData);
21360
+ }
21361
+ else if (_BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.isError(messageOrError)) {
21362
+ // For backwards compatibility, log BentleyError old way
21363
+ Logger._logError(category, Logger.getExceptionMessage(messageOrError), () => ({ ..._BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorMetadata(messageOrError), exceptionType: messageOrError?.constructor?.name ?? "<Unknown>", ..._BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getMetaData(metaData) }));
21364
+ }
21365
+ else {
21366
+ // Else, return a copy of the error, with non-enumerable members `message` and `stack` removed, as "metadata" for log.
21367
+ Logger._logError(category, Logger.getExceptionMessage(messageOrError), Logger.getExceptionMetaData(messageOrError, metaData));
21368
+ }
21369
+ }
21363
21370
  }
21364
- static getExceptionMessage(err) {
21365
- if (err === undefined) {
21366
- return "Error: err is undefined.";
21371
+ /**
21372
+ * Get a sting message for a given error.
21373
+ * For legacy [[BentleyError]] exceptions, this will include the error message and, optionally, the call stack.
21374
+ * For other exceptions, this will include the stringified version of the error.
21375
+ * @param error The error to get the message for
21376
+ * @returns A string message for the error
21377
+ */
21378
+ static getExceptionMessage(error) {
21379
+ if (error === undefined) {
21380
+ return "Error: error is undefined.";
21381
+ }
21382
+ if (error === null) {
21383
+ return "Error: error is null.";
21367
21384
  }
21368
- if (err === null) {
21369
- return "Error: err is null.";
21385
+ const stack = Logger.logExceptionCallstacks ? `\n${_BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorStack(error)}` : "";
21386
+ return _BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorMessage(error) + stack;
21387
+ }
21388
+ /**
21389
+ * Merged passed metaData with error properties into one LoggingMetaData, with the passed metaData taking precedence in case of conflict.
21390
+ * @param error The error to be logged as metadata
21391
+ * @param metaData Optional metadata to be merged with the error
21392
+ * @returns A function returning the merged metadata
21393
+ */
21394
+ static getExceptionMetaData(error, metaData) {
21395
+ const exceptionType = error?.constructor?.name ?? "<Unknown>";
21396
+ if (metaData === undefined) {
21397
+ return () => ({ exceptionType, ...error });
21370
21398
  }
21371
- const stack = Logger.logExceptionCallstacks ? `\n${_BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorStack(err)}` : "";
21372
- return _BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorMessage(err) + stack;
21399
+ return () => ({ exceptionType, ...error, ..._BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getMetaData(metaData) });
21373
21400
  }
21374
21401
  /** Log the specified exception.
21375
21402
  * For legacy [[BentleyError]] exceptions, the special "exceptionType" property will be added as metadata. Otherwise, all enumerable members of the exception are logged as metadata.
21376
21403
  * @param category The category of the message.
21377
21404
  * @param err The exception object.
21378
21405
  * @param log The logger output function to use - defaults to Logger.logError
21406
+ * @deprecated in 5.6 - will not be removed until after 2027-03-03. Use logError(category, error, metaData) instead, which will log exceptions in the same way but is more flexible and easier to use.
21379
21407
  */
21380
21408
  static logException(category, err, log = (_category, message, metaData) => Logger.logError(_category, message, metaData)) {
21381
21409
  log(category, Logger.getExceptionMessage(err), () => {
@@ -21491,6 +21519,10 @@ class ObservableSet extends Set {
21491
21519
  onDeleted = new _BeEvent__WEBPACK_IMPORTED_MODULE_0__.BeEvent();
21492
21520
  /** Emitted after this set's contents are cleared. */
21493
21521
  onCleared = new _BeEvent__WEBPACK_IMPORTED_MODULE_0__.BeEvent();
21522
+ /** Emitted after multiple items are added to this set via [[addAll]]. */
21523
+ onBatchAdded = new _BeEvent__WEBPACK_IMPORTED_MODULE_0__.BeEvent();
21524
+ /** Emitted after multiple items are deleted from this set via [[deleteAll]]. */
21525
+ onBatchDeleted = new _BeEvent__WEBPACK_IMPORTED_MODULE_0__.BeEvent();
21494
21526
  /** Construct a new ObservableSet.
21495
21527
  * @param elements Optional elements with which to populate the new set.
21496
21528
  */
@@ -21523,6 +21555,32 @@ class ObservableSet extends Set {
21523
21555
  this.onCleared.raiseEvent();
21524
21556
  }
21525
21557
  }
21558
+ /** Add multiple items to the set, raising [[onBatchAdded]] only once after all items are added.
21559
+ * This is more efficient than calling [[add]] in a loop when listeners need not be notified of each individual addition.
21560
+ * @param items The items to add.
21561
+ * @returns The number of items that were actually added (i.e., were not already present).
21562
+ */
21563
+ addAll(items) {
21564
+ const prevSize = this.size;
21565
+ for (const item of items)
21566
+ super.add(item);
21567
+ if (this.size !== prevSize)
21568
+ this.onBatchAdded.raiseEvent();
21569
+ return this.size - prevSize;
21570
+ }
21571
+ /** Delete multiple items from the set, raising [[onBatchDeleted]] only once after all items are deleted.
21572
+ * This is more efficient than calling [[delete]] in a loop when listeners need not be notified of each individual deletion.
21573
+ * @param items The items to delete.
21574
+ * @returns The number of items that were actually deleted (i.e., were present in the set).
21575
+ */
21576
+ deleteAll(items) {
21577
+ const prevSize = this.size;
21578
+ for (const item of items)
21579
+ super.delete(item);
21580
+ if (this.size !== prevSize)
21581
+ this.onBatchDeleted.raiseEvent();
21582
+ return prevSize - this.size;
21583
+ }
21526
21584
  }
21527
21585
 
21528
21586
 
@@ -21631,11 +21689,15 @@ class OneAtATimeAction {
21631
21689
  return await promise;
21632
21690
  }
21633
21691
  finally {
21634
- // do all of this whether promise was fulfilled or rejected
21635
- this._active = this._pending; // see if there's a pending request waiting
21636
- this._pending = undefined; // clear pending
21637
- if (this._active)
21638
- this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
21692
+ // A replaced pending request can be abandoned before it ever becomes active.
21693
+ // Only the currently active entry is allowed to promote/start the next pending request.
21694
+ if (this._active === entry) {
21695
+ // do all of this whether promise was fulfilled or rejected
21696
+ this._active = this._pending; // see if there's a pending request waiting
21697
+ this._pending = undefined; // clear pending
21698
+ if (this._active)
21699
+ this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
21700
+ }
21639
21701
  }
21640
21702
  }
21641
21703
  }
@@ -23718,7 +23780,7 @@ class UnexpectedErrors {
23718
23780
  /** handler for logging exception to console */
23719
23781
  static consoleLog = (e) => console.error(e); // eslint-disable-line no-console
23720
23782
  /** handler for logging exception with [[Logger]] */
23721
- static errorLog = (e) => _Logger__WEBPACK_IMPORTED_MODULE_0__.Logger.logException("unhandled", e);
23783
+ static errorLog = (e) => _Logger__WEBPACK_IMPORTED_MODULE_0__.Logger.logError("unhandled", e);
23722
23784
  static _telemetry = [];
23723
23785
  static _handler = this.errorLog; // default to error logging
23724
23786
  constructor() { } // this is a singleton
@@ -25629,7 +25691,7 @@ describe("ITwinLocalization", () => {
25629
25691
  // For interpolation options, see: https://www.i18next.com/translation-function/interpolation
25630
25692
  describe("#getLocalizedString", () => {
25631
25693
  before(async () => {
25632
- localization = new ITwinLocalization_1.ITwinLocalization();
25694
+ localization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "en-US" } });
25633
25695
  await localization.initialize(["Default", "Test"]);
25634
25696
  germanLocalization = new ITwinLocalization_1.ITwinLocalization({ initOptions: { lng: "de" } });
25635
25697
  await germanLocalization.initialize(["Default", "Test"]);
@@ -26202,11 +26264,11 @@ describe("ITwinLocalization", () => {
26202
26264
  // On current Linux CI environment, "@POSIX" is appended as a suffix to the locale,
26203
26265
  // which means that the en-US locales do not get loaded.
26204
26266
  if (!navigator.userAgent.toLowerCase().includes("linux")) {
26205
- it("english language list includes en and en-US", async () => {
26267
+ it("default list includes en and the user's language", async () => {
26206
26268
  localization = new ITwinLocalization_1.ITwinLocalization();
26207
26269
  await localization.initialize([]);
26208
26270
  languages = localization.getLanguageList();
26209
- chai_1.assert.isTrue(languages.includes("en-US"));
26271
+ chai_1.assert.isTrue(languages.includes(navigator.language));
26210
26272
  chai_1.assert.isTrue(languages.includes("en"));
26211
26273
  });
26212
26274
  }