@itwin/core-i18n 5.15.0-dev.13 → 5.15.0-dev.14
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/lib/cjs/test/webpack/bundled-tests.instrumented.js +243 -155
- package/lib/cjs/test/webpack/bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/bundled-tests.js +121 -33
- package/lib/cjs/test/webpack/bundled-tests.js.map +1 -1
- package/lib/cjs/test/webpack/vendors-common_temp_node_modules_pnpm_cross-fetch_4_1_0_node_modules_cross-fetch_dist_browser-44272f.bundled-tests.instrumented.js.map +1 -1
- package/lib/cjs/test/webpack/vendors-common_temp_node_modules_pnpm_cross-fetch_4_1_0_node_modules_cross-fetch_dist_browser-44272f.bundled-tests.js.map +1 -1
- package/package.json +6 -6
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
/** @packageDocumentation
|
|
18
18
|
* @module Localization
|
|
19
19
|
*/
|
|
20
|
-
function
|
|
21
|
-
var path = "C:\\agent\\_work\\
|
|
22
|
-
var hash = "
|
|
20
|
+
function cov_ogldeftyv() {
|
|
21
|
+
var path = "C:\\agent\\_work\\1\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js";
|
|
22
|
+
var hash = "8de28e753813d64322bcaeb99c8c8dfad2c2faad";
|
|
23
23
|
var global = new Function("return this")();
|
|
24
24
|
var gcv = "__coverage__";
|
|
25
25
|
var coverageData = {
|
|
26
|
-
path: "C:\\agent\\_work\\
|
|
26
|
+
path: "C:\\agent\\_work\\1\\s\\core\\i18n\\lib\\cjs\\ITwinLocalization.js",
|
|
27
27
|
statementMap: {
|
|
28
28
|
"0": {
|
|
29
29
|
start: {
|
|
@@ -1995,13 +1995,13 @@ function cov_1wctd2lw3r() {
|
|
|
1995
1995
|
inputSourceMap: {
|
|
1996
1996
|
version: 3,
|
|
1997
1997
|
file: "ITwinLocalization.js",
|
|
1998
|
-
sources: ["C:\\agent\\_work\\
|
|
1998
|
+
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CAAC,CAAC,CAAC;IAC5E,IAAI,CAAC,IAAc,IAAI,qBAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,KAAK,CAAC,IAAc,IAAI,qBAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,gBAAgB,CAAC,IAAc;QACrC,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACrC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAC7B,OAAO,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAChC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC",
|
|
2001
2001
|
sourcesContent: ["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Localization\r\n */\r\n\r\nimport i18next, { i18n, InitOptions, Module, TOptionsBase } from \"i18next\";\r\nimport i18nextBrowserLanguageDetector, { DetectorOptions } from \"i18next-browser-languagedetector\";\r\nimport Backend, { HttpBackendOptions as BackendOptions } from \"i18next-http-backend\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport type { Localization } from \"@itwin/core-common\";\r\n\r\nconst DEFAULT_MAX_RETRIES: number = 1; // a low number prevents wasted time and potential timeouts when requesting localization files throws an error\r\n\r\n/** Options for ITwinLocalization\r\n * @public\r\n */\r\nexport interface LocalizationOptions {\r\n urlTemplate?: string;\r\n backendPlugin?: Module;\r\n detectorPlugin?: Module;\r\n initOptions?: InitOptions;\r\n backendHttpOptions?: BackendOptions;\r\n detectorOptions?: DetectorOptions;\r\n}\r\n\r\n/** Supplies localizations for iTwin.js\r\n * @note this class uses the [i18next](https://www.i18next.com/) package.\r\n * @public\r\n */\r\nexport class ITwinLocalization implements Localization {\r\n public i18next: i18n;\r\n private readonly _initOptions: InitOptions;\r\n private readonly _backendOptions: BackendOptions;\r\n private readonly _detectionOptions: DetectorOptions;\r\n private readonly _namespaces = new Map<string, Promise<void>>();\r\n\r\n public constructor(options?: LocalizationOptions) {\r\n this.i18next = i18next.createInstance();\r\n\r\n this._backendOptions = {\r\n loadPath: options?.urlTemplate ?? \"locales/{{lng}}/{{ns}}.json\",\r\n crossDomain: true,\r\n ...options?.backendHttpOptions,\r\n };\r\n\r\n this._detectionOptions = {\r\n order: [\"querystring\", \"navigator\", \"htmlTag\"],\r\n lookupQuerystring: \"lng\",\r\n caches: [],\r\n ...options?.detectorOptions,\r\n };\r\n\r\n this._initOptions = {\r\n interpolation: { escapeValue: true },\r\n fallbackLng: \"en\",\r\n maxRetries: DEFAULT_MAX_RETRIES,\r\n backend: this._backendOptions,\r\n detection: this._detectionOptions,\r\n ...options?.initOptions,\r\n };\r\n\r\n this.i18next\r\n .use(options?.detectorPlugin ?? i18nextBrowserLanguageDetector)\r\n .use(options?.backendPlugin ?? Backend)\r\n .use(TranslationLogger);\r\n }\r\n\r\n public async initialize(namespaces: string[]): Promise<void> {\r\n\r\n // Also consider namespaces passed into constructor\r\n const initNamespaces: string[] = [this._initOptions.ns || []].flat();\r\n const combinedNamespaces: Set<string> = new Set([...namespaces, ...initNamespaces]); // without duplicates\r\n\r\n const defaultNamespace: string | false | readonly string[] = this._initOptions.defaultNS ?? namespaces[0];\r\n if (defaultNamespace)\r\n combinedNamespaces.add(defaultNamespace as string); // Make sure default namespace is in namespaces list\r\n\r\n const initOptions: InitOptions = {\r\n ...this._initOptions,\r\n defaultNS: defaultNamespace,\r\n ns: [...combinedNamespaces],\r\n };\r\n\r\n // if in a development environment, set debugging\r\n if (process.env.NODE_ENV === \"development\")\r\n initOptions.debug = true;\r\n\r\n const initPromise = this.i18next.init(initOptions) as unknown as Promise<void>;\r\n\r\n for (const ns of namespaces)\r\n this._namespaces.set(ns, initPromise);\r\n\r\n return initPromise;\r\n }\r\n\r\n /** Replace all instances of `%{key}` within a string with the translations of those keys.\r\n * For example:\r\n * ``` ts\r\n * \"MyKeys\": {\r\n * \"Key1\": \"First value\",\r\n * \"Key2\": \"Second value\"\r\n * }\r\n * ```\r\n *\r\n * ``` ts\r\n * i18.translateKeys(\"string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!\"\") // returns \"string with First Value followed by Second Value!\"\r\n * ```\r\n * @param line The input line, potentially containing %{keys}.\r\n * @returns The line with all %{keys} translated\r\n * @public\r\n */\r\n public getLocalizedKeys(line: string): string {\r\n return line.replace(/\\%\\{(.+?)\\}/g, (_match, tag) => this.getLocalizedString(tag));\r\n }\r\n\r\n /** Return the translated value of a key.\r\n * @param key - the key that matches a property in the JSON localization file.\r\n * @note The key includes the namespace, which identifies the particular localization file that contains the property,\r\n * followed by a colon, followed by the property in the JSON file.\r\n * For example:\r\n * ``` ts\r\n * const dataString: string = IModelApp.localization.getLocalizedString(\"iModelJs:BackgroundMap.BingDataAttribution\");\r\n * ```\r\n * assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file.\r\n * @returns The string corresponding to the first key that resolves.\r\n * @throws Error if no keys resolve to a string.\r\n * @public\r\n */\r\n public getLocalizedString(key: string | string[], options?: TOptionsBase): string {\r\n if (options?.returnDetails || options?.returnObjects) {\r\n throw new Error(\"Translation key must map to a string, but the given options will result in an object\");\r\n }\r\n\r\n const value = this.i18next.t(key, options);\r\n\r\n if (typeof value !== \"string\") {\r\n throw new Error(\"Translation key(s) string not found\");\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /** Gets the English translation.\r\n * @param namespace - the namespace that identifies the particular localization file that contains the property.\r\n * @param key - the key that matches a property in the JSON localization file.\r\n * @returns The string corresponding to the first key that resolves.\r\n * @throws Error if no keys resolve to a string.\r\n * @internal\r\n */\r\n public getEnglishString(namespace: string, key: string | string[], options?: TOptionsBase): string {\r\n if (options?.returnDetails || options?.returnObjects) {\r\n throw new Error(\"Translation key must map to a string, but the given options will result in an object\");\r\n }\r\n\r\n options = {\r\n ...options,\r\n ns: namespace, // ensure namespace argument is used\r\n };\r\n\r\n const en = this.i18next.getFixedT(\"en\", namespace);\r\n const str = en(key, options);\r\n if (typeof str !== \"string\")\r\n throw new Error(\"Translation key(s) not found\");\r\n\r\n return str;\r\n }\r\n\r\n /** Get the promise for an already registered Namespace.\r\n * @param name - the name of the namespace\r\n * @public\r\n */\r\n public getNamespacePromise(name: string): Promise<void> | undefined {\r\n return this._namespaces.get(name);\r\n }\r\n\r\n /** @internal */\r\n public getLanguageList(): readonly string[] {\r\n return this.i18next.languages;\r\n }\r\n\r\n /** override the language detected in the browser */\r\n public async changeLanguage(language: string) {\r\n return this.i18next.changeLanguage(language) as unknown as Promise<void>;\r\n }\r\n\r\n /** Register a new Namespace and return it. If the namespace is already registered, it will be returned.\r\n * @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties.\r\n * @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server,\r\n * based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await\r\n * fulfillment of the readPromise Promise property of the returned LocalizationNamespace.\r\n * @see [Localization in iTwin.js]($docs/learning/frontend/Localization.md)\r\n * @public\r\n */\r\n public async registerNamespace(name: string): Promise<void> {\r\n const existing = this._namespaces.get(name);\r\n if (existing !== undefined)\r\n return existing;\r\n\r\n const theReadPromise = new Promise<void>((resolve) => {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this.i18next.loadNamespaces(name, (err) => {\r\n if (!err)\r\n return resolve();\r\n\r\n // i18next can return errors from other concurrent namespace loads in this callback.\r\n const wasLoaded = this.getLanguageList().some((language) => this.i18next.hasResourceBundle(language, name));\r\n if (!wasLoaded)\r\n Logger.logError(\"i18n\", `No resources for namespace ${name} could be loaded`);\r\n\r\n resolve();\r\n });\r\n });\r\n this._namespaces.set(name, theReadPromise);\r\n return theReadPromise;\r\n }\r\n\r\n /** @internal */\r\n public unregisterNamespace(name: string): void {\r\n this._namespaces.delete(name);\r\n }\r\n}\r\n\r\nclass TranslationLogger {\r\n public static readonly type = \"logger\";\r\n public log(args: string[]) { Logger.logInfo(\"i18n\", this.createLogMessage(args)); }\r\n public warn(args: string[]) { Logger.logWarning(\"i18n\", this.createLogMessage(args)); }\r\n public error(args: string[]) { Logger.logError(\"i18n\", this.createLogMessage(args)); }\r\n private createLogMessage(args: string[]) {\r\n let message = args[0];\r\n for (let i = 1; i < args.length; ++i) {\r\n if (typeof args[i] === \"string\")\r\n message += `\\n ${args[i]}`;\r\n }\r\n return message;\r\n }\r\n}\r\n"]
|
|
2002
2002
|
},
|
|
2003
2003
|
_coverageSchema: "1a1c01bbd47fc00a2c39e90264f33305004495a9",
|
|
2004
|
-
hash: "
|
|
2004
|
+
hash: "8de28e753813d64322bcaeb99c8c8dfad2c2faad"
|
|
2005
2005
|
};
|
|
2006
2006
|
var coverage = global[gcv] || (global[gcv] = {});
|
|
2007
2007
|
if (!coverage[path] || coverage[path].hash !== hash) {
|
|
@@ -2010,31 +2010,31 @@ function cov_1wctd2lw3r() {
|
|
|
2010
2010
|
var actualCoverage = coverage[path];
|
|
2011
2011
|
{
|
|
2012
2012
|
// @ts-ignore
|
|
2013
|
-
|
|
2013
|
+
cov_ogldeftyv = function () {
|
|
2014
2014
|
return actualCoverage;
|
|
2015
2015
|
};
|
|
2016
2016
|
}
|
|
2017
2017
|
return actualCoverage;
|
|
2018
2018
|
}
|
|
2019
|
-
|
|
2020
|
-
var __importDefault = (
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
return (
|
|
2019
|
+
cov_ogldeftyv();
|
|
2020
|
+
var __importDefault = (cov_ogldeftyv().s[0]++, (cov_ogldeftyv().b[0][0]++, this) && (cov_ogldeftyv().b[0][1]++, this.__importDefault) || (cov_ogldeftyv().b[0][2]++, function (mod) {
|
|
2021
|
+
cov_ogldeftyv().f[0]++;
|
|
2022
|
+
cov_ogldeftyv().s[1]++;
|
|
2023
|
+
return (cov_ogldeftyv().b[2][0]++, mod) && (cov_ogldeftyv().b[2][1]++, mod.__esModule) ? (cov_ogldeftyv().b[1][0]++, mod) : (cov_ogldeftyv().b[1][1]++, {
|
|
2024
2024
|
"default": mod
|
|
2025
2025
|
});
|
|
2026
2026
|
}));
|
|
2027
|
-
|
|
2027
|
+
cov_ogldeftyv().s[2]++;
|
|
2028
2028
|
Object.defineProperty(exports, "__esModule", ({
|
|
2029
2029
|
value: true
|
|
2030
2030
|
}));
|
|
2031
|
-
|
|
2031
|
+
cov_ogldeftyv().s[3]++;
|
|
2032
2032
|
exports.ITwinLocalization = void 0;
|
|
2033
|
-
const i18next_1 = (
|
|
2034
|
-
const i18next_browser_languagedetector_1 = (
|
|
2035
|
-
const i18next_http_backend_1 = (
|
|
2036
|
-
const core_bentley_1 = (
|
|
2037
|
-
const DEFAULT_MAX_RETRIES = (
|
|
2033
|
+
const i18next_1 = (cov_ogldeftyv().s[4]++, __importDefault(__webpack_require__(/*! i18next */ "../../common/temp/node_modules/.pnpm/i18next@21.10.0/node_modules/i18next/dist/cjs/i18next.js")));
|
|
2034
|
+
const i18next_browser_languagedetector_1 = (cov_ogldeftyv().s[5]++, __importDefault(__webpack_require__(/*! i18next-browser-languagedetector */ "../../common/temp/node_modules/.pnpm/i18next-browser-languagedetector@6.1.8/node_modules/i18next-browser-languagedetector/dist/cjs/i18nextBrowserLanguageDetector.js")));
|
|
2035
|
+
const i18next_http_backend_1 = (cov_ogldeftyv().s[6]++, __importDefault(__webpack_require__(/*! i18next-http-backend */ "../../common/temp/node_modules/.pnpm/i18next-http-backend@3.0.6/node_modules/i18next-http-backend/esm/index.js")));
|
|
2036
|
+
const core_bentley_1 = (cov_ogldeftyv().s[7]++, __webpack_require__(/*! @itwin/core-bentley */ "../bentley/lib/esm/core-bentley.js"));
|
|
2037
|
+
const DEFAULT_MAX_RETRIES = (cov_ogldeftyv().s[8]++, 1); // a low number prevents wasted time and potential timeouts when requesting localization files throws an error
|
|
2038
2038
|
/** Supplies localizations for iTwin.js
|
|
2039
2039
|
* @note this class uses the [i18next](https://www.i18next.com/) package.
|
|
2040
2040
|
* @public
|
|
@@ -2044,25 +2044,25 @@ class ITwinLocalization {
|
|
|
2044
2044
|
_initOptions;
|
|
2045
2045
|
_backendOptions;
|
|
2046
2046
|
_detectionOptions;
|
|
2047
|
-
_namespaces = (
|
|
2047
|
+
_namespaces = (cov_ogldeftyv().s[9]++, new Map());
|
|
2048
2048
|
constructor(options) {
|
|
2049
|
-
|
|
2050
|
-
|
|
2049
|
+
cov_ogldeftyv().f[1]++;
|
|
2050
|
+
cov_ogldeftyv().s[10]++;
|
|
2051
2051
|
this.i18next = i18next_1.default.createInstance();
|
|
2052
|
-
|
|
2052
|
+
cov_ogldeftyv().s[11]++;
|
|
2053
2053
|
this._backendOptions = {
|
|
2054
|
-
loadPath: (
|
|
2054
|
+
loadPath: (cov_ogldeftyv().b[3][0]++, options?.urlTemplate) ?? (cov_ogldeftyv().b[3][1]++, "locales/{{lng}}/{{ns}}.json"),
|
|
2055
2055
|
crossDomain: true,
|
|
2056
2056
|
...options?.backendHttpOptions
|
|
2057
2057
|
};
|
|
2058
|
-
|
|
2058
|
+
cov_ogldeftyv().s[12]++;
|
|
2059
2059
|
this._detectionOptions = {
|
|
2060
2060
|
order: ["querystring", "navigator", "htmlTag"],
|
|
2061
2061
|
lookupQuerystring: "lng",
|
|
2062
2062
|
caches: [],
|
|
2063
2063
|
...options?.detectorOptions
|
|
2064
2064
|
};
|
|
2065
|
-
|
|
2065
|
+
cov_ogldeftyv().s[13]++;
|
|
2066
2066
|
this._initOptions = {
|
|
2067
2067
|
interpolation: {
|
|
2068
2068
|
escapeValue: true
|
|
@@ -2073,41 +2073,41 @@ class ITwinLocalization {
|
|
|
2073
2073
|
detection: this._detectionOptions,
|
|
2074
2074
|
...options?.initOptions
|
|
2075
2075
|
};
|
|
2076
|
-
|
|
2077
|
-
this.i18next.use((
|
|
2076
|
+
cov_ogldeftyv().s[14]++;
|
|
2077
|
+
this.i18next.use((cov_ogldeftyv().b[4][0]++, options?.detectorPlugin) ?? (cov_ogldeftyv().b[4][1]++, i18next_browser_languagedetector_1.default)).use((cov_ogldeftyv().b[5][0]++, options?.backendPlugin) ?? (cov_ogldeftyv().b[5][1]++, i18next_http_backend_1.default)).use(TranslationLogger);
|
|
2078
2078
|
}
|
|
2079
2079
|
async initialize(namespaces) {
|
|
2080
|
-
|
|
2080
|
+
cov_ogldeftyv().f[2]++;
|
|
2081
2081
|
// Also consider namespaces passed into constructor
|
|
2082
|
-
const initNamespaces = (
|
|
2083
|
-
const combinedNamespaces = (
|
|
2084
|
-
const defaultNamespace = (
|
|
2085
|
-
|
|
2082
|
+
const initNamespaces = (cov_ogldeftyv().s[15]++, [(cov_ogldeftyv().b[6][0]++, this._initOptions.ns) || (cov_ogldeftyv().b[6][1]++, [])].flat());
|
|
2083
|
+
const combinedNamespaces = (cov_ogldeftyv().s[16]++, new Set([...namespaces, ...initNamespaces])); // without duplicates
|
|
2084
|
+
const defaultNamespace = (cov_ogldeftyv().s[17]++, (cov_ogldeftyv().b[7][0]++, this._initOptions.defaultNS) ?? (cov_ogldeftyv().b[7][1]++, namespaces[0]));
|
|
2085
|
+
cov_ogldeftyv().s[18]++;
|
|
2086
2086
|
if (defaultNamespace) {
|
|
2087
|
-
|
|
2088
|
-
|
|
2087
|
+
cov_ogldeftyv().b[8][0]++;
|
|
2088
|
+
cov_ogldeftyv().s[19]++;
|
|
2089
2089
|
combinedNamespaces.add(defaultNamespace);
|
|
2090
2090
|
} else {
|
|
2091
|
-
|
|
2091
|
+
cov_ogldeftyv().b[8][1]++;
|
|
2092
2092
|
} // Make sure default namespace is in namespaces list
|
|
2093
|
-
const initOptions = (
|
|
2093
|
+
const initOptions = (cov_ogldeftyv().s[20]++, {
|
|
2094
2094
|
...this._initOptions,
|
|
2095
2095
|
defaultNS: defaultNamespace,
|
|
2096
2096
|
ns: [...combinedNamespaces]
|
|
2097
2097
|
});
|
|
2098
2098
|
// if in a development environment, set debugging
|
|
2099
|
-
|
|
2099
|
+
cov_ogldeftyv().s[21]++;
|
|
2100
2100
|
if (false) // removed by dead control flow
|
|
2101
2101
|
{} else {
|
|
2102
|
-
|
|
2102
|
+
cov_ogldeftyv().b[9][1]++;
|
|
2103
2103
|
}
|
|
2104
|
-
const initPromise = (
|
|
2105
|
-
|
|
2104
|
+
const initPromise = (cov_ogldeftyv().s[23]++, this.i18next.init(initOptions));
|
|
2105
|
+
cov_ogldeftyv().s[24]++;
|
|
2106
2106
|
for (const ns of namespaces) {
|
|
2107
|
-
|
|
2107
|
+
cov_ogldeftyv().s[25]++;
|
|
2108
2108
|
this._namespaces.set(ns, initPromise);
|
|
2109
2109
|
}
|
|
2110
|
-
|
|
2110
|
+
cov_ogldeftyv().s[26]++;
|
|
2111
2111
|
return initPromise;
|
|
2112
2112
|
}
|
|
2113
2113
|
/** Replace all instances of `%{key}` within a string with the translations of those keys.
|
|
@@ -2127,11 +2127,11 @@ class ITwinLocalization {
|
|
|
2127
2127
|
* @public
|
|
2128
2128
|
*/
|
|
2129
2129
|
getLocalizedKeys(line) {
|
|
2130
|
-
|
|
2131
|
-
|
|
2130
|
+
cov_ogldeftyv().f[3]++;
|
|
2131
|
+
cov_ogldeftyv().s[27]++;
|
|
2132
2132
|
return line.replace(/\%\{(.+?)\}/g, (_match, tag) => {
|
|
2133
|
-
|
|
2134
|
-
|
|
2133
|
+
cov_ogldeftyv().f[4]++;
|
|
2134
|
+
cov_ogldeftyv().s[28]++;
|
|
2135
2135
|
return this.getLocalizedString(tag);
|
|
2136
2136
|
});
|
|
2137
2137
|
}
|
|
@@ -2149,25 +2149,25 @@ class ITwinLocalization {
|
|
|
2149
2149
|
* @public
|
|
2150
2150
|
*/
|
|
2151
2151
|
getLocalizedString(key, options) {
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
if ((
|
|
2155
|
-
|
|
2156
|
-
|
|
2152
|
+
cov_ogldeftyv().f[5]++;
|
|
2153
|
+
cov_ogldeftyv().s[29]++;
|
|
2154
|
+
if ((cov_ogldeftyv().b[11][0]++, options?.returnDetails) || (cov_ogldeftyv().b[11][1]++, options?.returnObjects)) {
|
|
2155
|
+
cov_ogldeftyv().b[10][0]++;
|
|
2156
|
+
cov_ogldeftyv().s[30]++;
|
|
2157
2157
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
2158
2158
|
} else {
|
|
2159
|
-
|
|
2159
|
+
cov_ogldeftyv().b[10][1]++;
|
|
2160
2160
|
}
|
|
2161
|
-
const value = (
|
|
2162
|
-
|
|
2161
|
+
const value = (cov_ogldeftyv().s[31]++, this.i18next.t(key, options));
|
|
2162
|
+
cov_ogldeftyv().s[32]++;
|
|
2163
2163
|
if (typeof value !== "string") {
|
|
2164
|
-
|
|
2165
|
-
|
|
2164
|
+
cov_ogldeftyv().b[12][0]++;
|
|
2165
|
+
cov_ogldeftyv().s[33]++;
|
|
2166
2166
|
throw new Error("Translation key(s) string not found");
|
|
2167
2167
|
} else {
|
|
2168
|
-
|
|
2168
|
+
cov_ogldeftyv().b[12][1]++;
|
|
2169
2169
|
}
|
|
2170
|
-
|
|
2170
|
+
cov_ogldeftyv().s[34]++;
|
|
2171
2171
|
return value;
|
|
2172
2172
|
}
|
|
2173
2173
|
/** Gets the English translation.
|
|
@@ -2178,31 +2178,31 @@ class ITwinLocalization {
|
|
|
2178
2178
|
* @internal
|
|
2179
2179
|
*/
|
|
2180
2180
|
getEnglishString(namespace, key, options) {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
if ((
|
|
2184
|
-
|
|
2185
|
-
|
|
2181
|
+
cov_ogldeftyv().f[6]++;
|
|
2182
|
+
cov_ogldeftyv().s[35]++;
|
|
2183
|
+
if ((cov_ogldeftyv().b[14][0]++, options?.returnDetails) || (cov_ogldeftyv().b[14][1]++, options?.returnObjects)) {
|
|
2184
|
+
cov_ogldeftyv().b[13][0]++;
|
|
2185
|
+
cov_ogldeftyv().s[36]++;
|
|
2186
2186
|
throw new Error("Translation key must map to a string, but the given options will result in an object");
|
|
2187
2187
|
} else {
|
|
2188
|
-
|
|
2188
|
+
cov_ogldeftyv().b[13][1]++;
|
|
2189
2189
|
}
|
|
2190
|
-
|
|
2190
|
+
cov_ogldeftyv().s[37]++;
|
|
2191
2191
|
options = {
|
|
2192
2192
|
...options,
|
|
2193
2193
|
ns: namespace // ensure namespace argument is used
|
|
2194
2194
|
};
|
|
2195
|
-
const en = (
|
|
2196
|
-
const str = (
|
|
2197
|
-
|
|
2195
|
+
const en = (cov_ogldeftyv().s[38]++, this.i18next.getFixedT("en", namespace));
|
|
2196
|
+
const str = (cov_ogldeftyv().s[39]++, en(key, options));
|
|
2197
|
+
cov_ogldeftyv().s[40]++;
|
|
2198
2198
|
if (typeof str !== "string") {
|
|
2199
|
-
|
|
2200
|
-
|
|
2199
|
+
cov_ogldeftyv().b[15][0]++;
|
|
2200
|
+
cov_ogldeftyv().s[41]++;
|
|
2201
2201
|
throw new Error("Translation key(s) not found");
|
|
2202
2202
|
} else {
|
|
2203
|
-
|
|
2203
|
+
cov_ogldeftyv().b[15][1]++;
|
|
2204
2204
|
}
|
|
2205
|
-
|
|
2205
|
+
cov_ogldeftyv().s[42]++;
|
|
2206
2206
|
return str;
|
|
2207
2207
|
}
|
|
2208
2208
|
/** Get the promise for an already registered Namespace.
|
|
@@ -2210,20 +2210,20 @@ class ITwinLocalization {
|
|
|
2210
2210
|
* @public
|
|
2211
2211
|
*/
|
|
2212
2212
|
getNamespacePromise(name) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2213
|
+
cov_ogldeftyv().f[7]++;
|
|
2214
|
+
cov_ogldeftyv().s[43]++;
|
|
2215
2215
|
return this._namespaces.get(name);
|
|
2216
2216
|
}
|
|
2217
2217
|
/** @internal */
|
|
2218
2218
|
getLanguageList() {
|
|
2219
|
-
|
|
2220
|
-
|
|
2219
|
+
cov_ogldeftyv().f[8]++;
|
|
2220
|
+
cov_ogldeftyv().s[44]++;
|
|
2221
2221
|
return this.i18next.languages;
|
|
2222
2222
|
}
|
|
2223
2223
|
/** override the language detected in the browser */
|
|
2224
2224
|
async changeLanguage(language) {
|
|
2225
|
-
|
|
2226
|
-
|
|
2225
|
+
cov_ogldeftyv().f[9]++;
|
|
2226
|
+
cov_ogldeftyv().s[45]++;
|
|
2227
2227
|
return this.i18next.changeLanguage(language);
|
|
2228
2228
|
}
|
|
2229
2229
|
/** Register a new Namespace and return it. If the namespace is already registered, it will be returned.
|
|
@@ -2235,94 +2235,94 @@ class ITwinLocalization {
|
|
|
2235
2235
|
* @public
|
|
2236
2236
|
*/
|
|
2237
2237
|
async registerNamespace(name) {
|
|
2238
|
-
|
|
2239
|
-
const existing = (
|
|
2240
|
-
|
|
2238
|
+
cov_ogldeftyv().f[10]++;
|
|
2239
|
+
const existing = (cov_ogldeftyv().s[46]++, this._namespaces.get(name));
|
|
2240
|
+
cov_ogldeftyv().s[47]++;
|
|
2241
2241
|
if (existing !== undefined) {
|
|
2242
|
-
|
|
2243
|
-
|
|
2242
|
+
cov_ogldeftyv().b[16][0]++;
|
|
2243
|
+
cov_ogldeftyv().s[48]++;
|
|
2244
2244
|
return existing;
|
|
2245
2245
|
} else {
|
|
2246
|
-
|
|
2246
|
+
cov_ogldeftyv().b[16][1]++;
|
|
2247
2247
|
}
|
|
2248
|
-
const theReadPromise = (
|
|
2249
|
-
|
|
2250
|
-
|
|
2248
|
+
const theReadPromise = (cov_ogldeftyv().s[49]++, new Promise(resolve => {
|
|
2249
|
+
cov_ogldeftyv().f[11]++;
|
|
2250
|
+
cov_ogldeftyv().s[50]++;
|
|
2251
2251
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
2252
2252
|
this.i18next.loadNamespaces(name, err => {
|
|
2253
|
-
|
|
2254
|
-
|
|
2253
|
+
cov_ogldeftyv().f[12]++;
|
|
2254
|
+
cov_ogldeftyv().s[51]++;
|
|
2255
2255
|
if (!err) {
|
|
2256
|
-
|
|
2257
|
-
|
|
2256
|
+
cov_ogldeftyv().b[17][0]++;
|
|
2257
|
+
cov_ogldeftyv().s[52]++;
|
|
2258
2258
|
return resolve();
|
|
2259
2259
|
} else {
|
|
2260
|
-
|
|
2260
|
+
cov_ogldeftyv().b[17][1]++;
|
|
2261
2261
|
}
|
|
2262
2262
|
// i18next can return errors from other concurrent namespace loads in this callback.
|
|
2263
|
-
const wasLoaded = (
|
|
2264
|
-
|
|
2265
|
-
|
|
2263
|
+
const wasLoaded = (cov_ogldeftyv().s[53]++, this.getLanguageList().some(language => {
|
|
2264
|
+
cov_ogldeftyv().f[13]++;
|
|
2265
|
+
cov_ogldeftyv().s[54]++;
|
|
2266
2266
|
return this.i18next.hasResourceBundle(language, name);
|
|
2267
2267
|
}));
|
|
2268
|
-
|
|
2268
|
+
cov_ogldeftyv().s[55]++;
|
|
2269
2269
|
if (!wasLoaded) {
|
|
2270
|
-
|
|
2271
|
-
|
|
2270
|
+
cov_ogldeftyv().b[18][0]++;
|
|
2271
|
+
cov_ogldeftyv().s[56]++;
|
|
2272
2272
|
core_bentley_1.Logger.logError("i18n", `No resources for namespace ${name} could be loaded`);
|
|
2273
2273
|
} else {
|
|
2274
|
-
|
|
2274
|
+
cov_ogldeftyv().b[18][1]++;
|
|
2275
2275
|
}
|
|
2276
|
-
|
|
2276
|
+
cov_ogldeftyv().s[57]++;
|
|
2277
2277
|
resolve();
|
|
2278
2278
|
});
|
|
2279
2279
|
}));
|
|
2280
|
-
|
|
2280
|
+
cov_ogldeftyv().s[58]++;
|
|
2281
2281
|
this._namespaces.set(name, theReadPromise);
|
|
2282
|
-
|
|
2282
|
+
cov_ogldeftyv().s[59]++;
|
|
2283
2283
|
return theReadPromise;
|
|
2284
2284
|
}
|
|
2285
2285
|
/** @internal */
|
|
2286
2286
|
unregisterNamespace(name) {
|
|
2287
|
-
|
|
2288
|
-
|
|
2287
|
+
cov_ogldeftyv().f[14]++;
|
|
2288
|
+
cov_ogldeftyv().s[60]++;
|
|
2289
2289
|
this._namespaces.delete(name);
|
|
2290
2290
|
}
|
|
2291
2291
|
}
|
|
2292
|
-
|
|
2292
|
+
cov_ogldeftyv().s[61]++;
|
|
2293
2293
|
exports.ITwinLocalization = ITwinLocalization;
|
|
2294
2294
|
class TranslationLogger {
|
|
2295
|
-
static type = (
|
|
2295
|
+
static type = (cov_ogldeftyv().s[62]++, "logger");
|
|
2296
2296
|
log(args) {
|
|
2297
|
-
|
|
2298
|
-
|
|
2297
|
+
cov_ogldeftyv().f[15]++;
|
|
2298
|
+
cov_ogldeftyv().s[63]++;
|
|
2299
2299
|
core_bentley_1.Logger.logInfo("i18n", this.createLogMessage(args));
|
|
2300
2300
|
}
|
|
2301
2301
|
warn(args) {
|
|
2302
|
-
|
|
2303
|
-
|
|
2302
|
+
cov_ogldeftyv().f[16]++;
|
|
2303
|
+
cov_ogldeftyv().s[64]++;
|
|
2304
2304
|
core_bentley_1.Logger.logWarning("i18n", this.createLogMessage(args));
|
|
2305
2305
|
}
|
|
2306
2306
|
error(args) {
|
|
2307
|
-
|
|
2308
|
-
|
|
2307
|
+
cov_ogldeftyv().f[17]++;
|
|
2308
|
+
cov_ogldeftyv().s[65]++;
|
|
2309
2309
|
core_bentley_1.Logger.logError("i18n", this.createLogMessage(args));
|
|
2310
2310
|
}
|
|
2311
2311
|
createLogMessage(args) {
|
|
2312
|
-
|
|
2313
|
-
let message = (
|
|
2314
|
-
|
|
2315
|
-
for (let i = (
|
|
2316
|
-
|
|
2312
|
+
cov_ogldeftyv().f[18]++;
|
|
2313
|
+
let message = (cov_ogldeftyv().s[66]++, args[0]);
|
|
2314
|
+
cov_ogldeftyv().s[67]++;
|
|
2315
|
+
for (let i = (cov_ogldeftyv().s[68]++, 1); i < args.length; ++i) {
|
|
2316
|
+
cov_ogldeftyv().s[69]++;
|
|
2317
2317
|
if (typeof args[i] === "string") {
|
|
2318
|
-
|
|
2319
|
-
|
|
2318
|
+
cov_ogldeftyv().b[19][0]++;
|
|
2319
|
+
cov_ogldeftyv().s[70]++;
|
|
2320
2320
|
message += `\n ${args[i]}`;
|
|
2321
2321
|
} else {
|
|
2322
|
-
|
|
2322
|
+
cov_ogldeftyv().b[19][1]++;
|
|
2323
2323
|
}
|
|
2324
2324
|
}
|
|
2325
|
-
|
|
2325
|
+
cov_ogldeftyv().s[71]++;
|
|
2326
2326
|
return message;
|
|
2327
2327
|
}
|
|
2328
2328
|
}
|
|
@@ -17339,6 +17339,7 @@ function assert(condition, message) {
|
|
|
17339
17339
|
"use strict";
|
|
17340
17340
|
__webpack_require__.r(__webpack_exports__);
|
|
17341
17341
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
17342
|
+
/* harmony export */ BeAsyncEvent: () => (/* binding */ BeAsyncEvent),
|
|
17342
17343
|
/* harmony export */ BeEvent: () => (/* binding */ BeEvent),
|
|
17343
17344
|
/* harmony export */ BeEventList: () => (/* binding */ BeEventList),
|
|
17344
17345
|
/* harmony export */ BeUiEvent: () => (/* binding */ BeUiEvent),
|
|
@@ -17426,8 +17427,13 @@ class BeEvent {
|
|
|
17426
17427
|
dropped = true;
|
|
17427
17428
|
}
|
|
17428
17429
|
else {
|
|
17430
|
+
const listener = context.listener;
|
|
17431
|
+
if (context.once) {
|
|
17432
|
+
context.listener = undefined;
|
|
17433
|
+
dropped = true;
|
|
17434
|
+
}
|
|
17429
17435
|
try {
|
|
17430
|
-
|
|
17436
|
+
listener.apply(context.scope, args);
|
|
17431
17437
|
}
|
|
17432
17438
|
catch (e) {
|
|
17433
17439
|
_UnexpectedErrors__WEBPACK_IMPORTED_MODULE_0__.UnexpectedErrors.handle(e);
|
|
@@ -17436,10 +17442,6 @@ class BeEvent {
|
|
|
17436
17442
|
// listener was removed during its own callback
|
|
17437
17443
|
dropped = true;
|
|
17438
17444
|
}
|
|
17439
|
-
else if (context.once) {
|
|
17440
|
-
context.listener = undefined;
|
|
17441
|
-
dropped = true;
|
|
17442
|
-
}
|
|
17443
17445
|
}
|
|
17444
17446
|
}
|
|
17445
17447
|
this._emitDepth--;
|
|
@@ -17483,8 +17485,6 @@ class BeUiEvent extends BeEvent {
|
|
|
17483
17485
|
*/
|
|
17484
17486
|
class BeUnorderedEvent {
|
|
17485
17487
|
_listeners = new Set();
|
|
17486
|
-
_emitDepth = 0;
|
|
17487
|
-
_hasTombstones = false;
|
|
17488
17488
|
/** The number of listeners currently subscribed to the event.
|
|
17489
17489
|
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
17490
17490
|
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
@@ -17514,43 +17514,26 @@ class BeUnorderedEvent {
|
|
|
17514
17514
|
}
|
|
17515
17515
|
/** Remove a specific context entry, deferring during emit. */
|
|
17516
17516
|
_removeCtx(ctx) {
|
|
17517
|
-
|
|
17518
|
-
ctx.listener = undefined; // tombstone for deferred cleanup
|
|
17519
|
-
this._hasTombstones = true;
|
|
17520
|
-
}
|
|
17521
|
-
else {
|
|
17522
|
-
this._listeners.delete(ctx);
|
|
17523
|
-
}
|
|
17517
|
+
this._listeners.delete(ctx);
|
|
17524
17518
|
}
|
|
17525
17519
|
/**
|
|
17526
17520
|
* Raises the event by calling each registered listener with the supplied arguments.
|
|
17527
17521
|
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
17528
17522
|
*/
|
|
17529
17523
|
raiseEvent(...args) {
|
|
17530
|
-
this._emitDepth++;
|
|
17531
17524
|
for (const ctx of this._listeners) {
|
|
17532
17525
|
if (!ctx.listener) {
|
|
17533
17526
|
continue;
|
|
17534
17527
|
}
|
|
17528
|
+
if (ctx.once) {
|
|
17529
|
+
this._listeners.delete(ctx);
|
|
17530
|
+
}
|
|
17535
17531
|
try {
|
|
17536
17532
|
ctx.listener.apply(ctx.scope, args);
|
|
17537
17533
|
}
|
|
17538
17534
|
catch (e) {
|
|
17539
17535
|
_UnexpectedErrors__WEBPACK_IMPORTED_MODULE_0__.UnexpectedErrors.handle(e);
|
|
17540
17536
|
}
|
|
17541
|
-
if (ctx.listener && ctx.once) {
|
|
17542
|
-
ctx.listener = undefined;
|
|
17543
|
-
this._hasTombstones = true;
|
|
17544
|
-
}
|
|
17545
|
-
}
|
|
17546
|
-
this._emitDepth--;
|
|
17547
|
-
// Only clean up tombstoned entries when we're back at the outermost emit
|
|
17548
|
-
if (this._hasTombstones && this._emitDepth === 0) {
|
|
17549
|
-
this._hasTombstones = false;
|
|
17550
|
-
for (const ctx of this._listeners) {
|
|
17551
|
-
if (ctx.listener === undefined)
|
|
17552
|
-
this._listeners.delete(ctx);
|
|
17553
|
-
}
|
|
17554
17537
|
}
|
|
17555
17538
|
}
|
|
17556
17539
|
/** Clear all listeners from this BeUnorderedEvent.
|
|
@@ -17566,6 +17549,108 @@ class BeUnorderedUiEvent extends BeUnorderedEvent {
|
|
|
17566
17549
|
/** Raises event with single strongly typed argument. */
|
|
17567
17550
|
emit(args) { this.raiseEvent(args); }
|
|
17568
17551
|
}
|
|
17552
|
+
/**
|
|
17553
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
17554
|
+
* Each listener is async (return a Promise<void>). The listeners may be invoked in series
|
|
17555
|
+
* or concurrently depending on the configuration of the instance.
|
|
17556
|
+
*
|
|
17557
|
+
* Like [[BeUnorderedEvent]], this class uses a `Set` internally to support more performant removal
|
|
17558
|
+
* of old listeners. When a listener is removed during emit, it is marked for deferred removal instead
|
|
17559
|
+
* of mutating the set immediately. Despite the "unordered" implication, items in a `Set` are enumerated
|
|
17560
|
+
* in insertion order, which means that this class invokes the listeners in insertion order.
|
|
17561
|
+
*
|
|
17562
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
17563
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
17564
|
+
* closure to unsubscribe.
|
|
17565
|
+
* @beta
|
|
17566
|
+
*/
|
|
17567
|
+
class BeAsyncEvent {
|
|
17568
|
+
_listeners = new Set();
|
|
17569
|
+
_concurrent = false;
|
|
17570
|
+
_promiseRejectionIsUnexpected = false;
|
|
17571
|
+
constructor(options) {
|
|
17572
|
+
if (options?.concurrent)
|
|
17573
|
+
this._concurrent = true;
|
|
17574
|
+
if (options?.promiseRejectionIsUnexpected)
|
|
17575
|
+
this._promiseRejectionIsUnexpected = true;
|
|
17576
|
+
}
|
|
17577
|
+
/** The number of listeners currently subscribed to the event.
|
|
17578
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
17579
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
17580
|
+
*/
|
|
17581
|
+
get numberOfListeners() { return this._listeners.size; }
|
|
17582
|
+
/**
|
|
17583
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
17584
|
+
* @param listener The function to be executed when the event is raised.
|
|
17585
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
17586
|
+
* @returns A function that will remove this event listener in O(1).
|
|
17587
|
+
*/
|
|
17588
|
+
addListener(listener, scope) {
|
|
17589
|
+
const ctx = { listener, scope, once: false };
|
|
17590
|
+
this._listeners.add(ctx);
|
|
17591
|
+
return () => this._removeCtx(ctx);
|
|
17592
|
+
}
|
|
17593
|
+
/**
|
|
17594
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
17595
|
+
* @param listener The function to be executed once when the event is raised.
|
|
17596
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
17597
|
+
* @returns A function that will remove this event listener in O(1).
|
|
17598
|
+
*/
|
|
17599
|
+
addOnce(listener, scope) {
|
|
17600
|
+
const ctx = { listener, scope, once: true };
|
|
17601
|
+
this._listeners.add(ctx);
|
|
17602
|
+
return () => this._removeCtx(ctx);
|
|
17603
|
+
}
|
|
17604
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
17605
|
+
_removeCtx(ctx) {
|
|
17606
|
+
this._listeners.delete(ctx);
|
|
17607
|
+
}
|
|
17608
|
+
/**
|
|
17609
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
17610
|
+
*
|
|
17611
|
+
* See [[BeAsyncEventOptions]] for options that control the behavior of this method.
|
|
17612
|
+
*
|
|
17613
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
17614
|
+
* @returns A Promise that settles when the event invocation is complete.
|
|
17615
|
+
*/
|
|
17616
|
+
async raiseEvent(...args) {
|
|
17617
|
+
const promises = [];
|
|
17618
|
+
// Wrapper to ensure that an exception thrown immediately by a listener is captured as a rejected promise rather than
|
|
17619
|
+
// allowed to propagate as an exception. A well-behaved Promise-returning function should never throw, but
|
|
17620
|
+
// this defends against the poorly-behaved ones. In Node 23+ we could use `Promise.try` instead.
|
|
17621
|
+
const invoke = async (ctx, args) => {
|
|
17622
|
+
if (!ctx.listener)
|
|
17623
|
+
return;
|
|
17624
|
+
await ctx.listener.apply(ctx.scope, args);
|
|
17625
|
+
};
|
|
17626
|
+
for (const ctx of this._listeners) {
|
|
17627
|
+
if (!ctx.listener)
|
|
17628
|
+
continue;
|
|
17629
|
+
if (ctx.once) {
|
|
17630
|
+
// Set guarantees this is safe during iteration.
|
|
17631
|
+
this._listeners.delete(ctx);
|
|
17632
|
+
}
|
|
17633
|
+
let promise = invoke(ctx, args);
|
|
17634
|
+
if (this._promiseRejectionIsUnexpected)
|
|
17635
|
+
promise = promise.catch(reason => _UnexpectedErrors__WEBPACK_IMPORTED_MODULE_0__.UnexpectedErrors.handle(reason));
|
|
17636
|
+
if (this._concurrent)
|
|
17637
|
+
promises.push(promise);
|
|
17638
|
+
else
|
|
17639
|
+
await promise;
|
|
17640
|
+
}
|
|
17641
|
+
if (this._concurrent) {
|
|
17642
|
+
const result = await Promise.allSettled(promises);
|
|
17643
|
+
const firstRejection = result.find(r => r.status === "rejected");
|
|
17644
|
+
if (firstRejection)
|
|
17645
|
+
throw firstRejection.reason;
|
|
17646
|
+
}
|
|
17647
|
+
}
|
|
17648
|
+
/** Clear all listeners from this BeAsyncEvent.
|
|
17649
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
17650
|
+
* immediately rather than being tombstoned.
|
|
17651
|
+
*/
|
|
17652
|
+
clear() { this._listeners.clear(); }
|
|
17653
|
+
}
|
|
17569
17654
|
/**
|
|
17570
17655
|
* A list of BeEvent objects, accessible by an event name.
|
|
17571
17656
|
* This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.
|
|
@@ -20122,16 +20207,18 @@ var Id64;
|
|
|
20122
20207
|
Id64.getFirst = getFirst;
|
|
20123
20208
|
/** Return the number of [[Id64String]]s represented by an [[Id64Arg]]. */
|
|
20124
20209
|
function sizeOf(arg) {
|
|
20125
|
-
return typeof arg === "string" ? 1 :
|
|
20210
|
+
return typeof arg === "string" ? 1 : "size" in arg ? arg.size : arg.length;
|
|
20126
20211
|
}
|
|
20127
20212
|
Id64.sizeOf = sizeOf;
|
|
20128
20213
|
/** Returns true if the [[Id64Arg]] contains the specified Id. */
|
|
20129
20214
|
function has(arg, id) {
|
|
20130
|
-
if (typeof arg === "string")
|
|
20215
|
+
if (typeof arg === "string") {
|
|
20131
20216
|
return arg === id;
|
|
20132
|
-
|
|
20133
|
-
|
|
20134
|
-
|
|
20217
|
+
}
|
|
20218
|
+
if ("has" in arg) {
|
|
20219
|
+
return arg.has(id);
|
|
20220
|
+
}
|
|
20221
|
+
return -1 !== arg.indexOf(id);
|
|
20135
20222
|
}
|
|
20136
20223
|
Id64.has = has;
|
|
20137
20224
|
/** The string representation of an invalid Id. */
|
|
@@ -24201,6 +24288,7 @@ class YieldManager {
|
|
|
24201
24288
|
__webpack_require__.r(__webpack_exports__);
|
|
24202
24289
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
24203
24290
|
/* harmony export */ AbandonedError: () => (/* reexport safe */ _OneAtATimeAction__WEBPACK_IMPORTED_MODULE_22__.AbandonedError),
|
|
24291
|
+
/* harmony export */ BeAsyncEvent: () => (/* reexport safe */ _BeEvent__WEBPACK_IMPORTED_MODULE_2__.BeAsyncEvent),
|
|
24204
24292
|
/* harmony export */ BeDuration: () => (/* reexport safe */ _Time__WEBPACK_IMPORTED_MODULE_30__.BeDuration),
|
|
24205
24293
|
/* harmony export */ BeEvent: () => (/* reexport safe */ _BeEvent__WEBPACK_IMPORTED_MODULE_2__.BeEvent),
|
|
24206
24294
|
/* harmony export */ BeEventList: () => (/* reexport safe */ _BeEvent__WEBPACK_IMPORTED_MODULE_2__.BeEventList),
|