@itwin/core-bentley 4.1.0-dev.7 → 4.1.0-dev.70
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/CHANGELOG.md +71 -1
- package/lib/cjs/ClassUtils.d.ts +9 -4
- package/lib/cjs/ClassUtils.d.ts.map +1 -1
- package/lib/cjs/ClassUtils.js +9 -4
- package/lib/cjs/ClassUtils.js.map +1 -1
- package/lib/cjs/Logger.d.ts.map +1 -1
- package/lib/cjs/Logger.js +1 -1
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/Tracing.js +4 -4
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.js.map +1 -1
- package/lib/cjs/YieldManager.d.ts +23 -8
- package/lib/cjs/YieldManager.d.ts.map +1 -1
- package/lib/cjs/YieldManager.js +15 -7
- package/lib/cjs/YieldManager.js.map +1 -1
- package/lib/esm/ClassUtils.d.ts +9 -4
- package/lib/esm/ClassUtils.d.ts.map +1 -1
- package/lib/esm/ClassUtils.js +9 -4
- package/lib/esm/ClassUtils.js.map +1 -1
- package/lib/esm/Logger.d.ts.map +1 -1
- package/lib/esm/Logger.js +1 -1
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/Tracing.js +4 -4
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.js.map +1 -1
- package/lib/esm/YieldManager.d.ts +23 -8
- package/lib/esm/YieldManager.d.ts.map +1 -1
- package/lib/esm/YieldManager.js +15 -7
- package/lib/esm/YieldManager.js.map +1 -1
- package/package.json +5 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
# Change Log - @itwin/core-bentley
|
|
2
2
|
|
|
3
|
-
This log was last generated on Tue,
|
|
3
|
+
This log was last generated on Tue, 18 Jul 2023 13:47:06 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.0.5
|
|
6
|
+
Tue, 18 Jul 2023 12:21:56 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.0.4
|
|
11
|
+
Wed, 12 Jul 2023 15:50:01 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 4.0.3
|
|
16
|
+
Mon, 03 Jul 2023 15:28:41 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 4.0.2
|
|
21
|
+
Wed, 21 Jun 2023 22:04:43 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 4.0.1
|
|
26
|
+
Wed, 21 Jun 2023 20:29:13 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 4.0.0
|
|
31
|
+
Mon, 22 May 2023 15:34:14 GMT
|
|
32
|
+
|
|
33
|
+
### Updates
|
|
34
|
+
|
|
35
|
+
- added PickMethods utility type
|
|
36
|
+
- Update to eslint@8
|
|
37
|
+
- Added DataTransformRequired flag to DbResult enum.
|
|
38
|
+
- Add RequireAtLeastOne utility type.
|
|
39
|
+
|
|
40
|
+
## 3.7.11
|
|
41
|
+
Tue, 11 Jul 2023 17:17:21 GMT
|
|
42
|
+
|
|
43
|
+
_Version update only_
|
|
44
|
+
|
|
45
|
+
## 3.7.10
|
|
46
|
+
Wed, 05 Jul 2023 13:41:21 GMT
|
|
47
|
+
|
|
48
|
+
_Version update only_
|
|
49
|
+
|
|
50
|
+
## 3.7.9
|
|
51
|
+
Tue, 20 Jun 2023 12:51:02 GMT
|
|
52
|
+
|
|
53
|
+
_Version update only_
|
|
54
|
+
|
|
55
|
+
## 3.7.8
|
|
56
|
+
Thu, 01 Jun 2023 17:00:39 GMT
|
|
57
|
+
|
|
58
|
+
_Version update only_
|
|
59
|
+
|
|
60
|
+
## 3.7.7
|
|
61
|
+
Wed, 24 May 2023 17:27:09 GMT
|
|
62
|
+
|
|
63
|
+
_Version update only_
|
|
64
|
+
|
|
65
|
+
## 3.7.6
|
|
66
|
+
Mon, 15 May 2023 18:23:40 GMT
|
|
67
|
+
|
|
68
|
+
_Version update only_
|
|
69
|
+
|
|
70
|
+
## 3.7.5
|
|
71
|
+
Thu, 04 May 2023 19:43:18 GMT
|
|
72
|
+
|
|
73
|
+
_Version update only_
|
|
4
74
|
|
|
5
75
|
## 3.7.4
|
|
6
76
|
Tue, 25 Apr 2023 17:50:35 GMT
|
package/lib/cjs/ClassUtils.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
1
4
|
/** Check if class `subclass` is a different class from `superclass` but extends from `superclass`
|
|
2
|
-
* @internal
|
|
3
5
|
* @param subclass the class that may be a subclass of `superclass`
|
|
4
6
|
* @param superclass the class that may be a base class of `subclass`
|
|
7
|
+
* @note The constructors of all types must be `public`.
|
|
5
8
|
* @returns whether `subclass` is a proper subclass of `superclass`
|
|
9
|
+
* @public
|
|
6
10
|
*/
|
|
7
11
|
export declare function isProperSubclassOf<SuperClass extends new (..._: any[]) => any, NonSubClass extends new (..._: any[]) => any, SubClass extends new (..._: any[]) => InstanceType<SuperClass>>(subclass: SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass;
|
|
8
12
|
/** Check if class `subclass` is `superclass` or extends from `superclass`
|
|
9
|
-
* @
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
13
|
+
* @param subclass the class that may be a subclass of `superclass`.
|
|
14
|
+
* @param superclass the class that may be a base class of `subclass`.
|
|
15
|
+
* @note The constructors of all types must be `public`.
|
|
12
16
|
* @returns whether `subclass` is a subclass of `superclass`
|
|
17
|
+
* @public
|
|
13
18
|
*/
|
|
14
19
|
export declare function isSubclassOf<SuperClass extends new (..._: any[]) => any, NonSubClass extends new (..._: any[]) => any, SubClass extends new (..._: any[]) => InstanceType<SuperClass>>(subclass: SuperClass | SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass | SuperClass;
|
|
15
20
|
//# sourceMappingURL=ClassUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassUtils.d.ts","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClassUtils.d.ts","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3C,WAAW,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC5C,QAAQ,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,YAAY,CAAC,UAAU,CAAC,EAC9D,QAAQ,EAAE,QAAQ,GAAG,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,QAAQ,IAAI,QAAQ,CAEhF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,UAAU,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3C,WAAW,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC5C,QAAQ,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,YAAY,CAAC,UAAU,CAAC,EAC9D,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,QAAQ,IAAI,QAAQ,GAAG,UAAU,CAE1G"}
|
package/lib/cjs/ClassUtils.js
CHANGED
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Utils
|
|
8
|
+
*/
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
exports.isSubclassOf = exports.isProperSubclassOf = void 0;
|
|
8
11
|
/** Check if class `subclass` is a different class from `superclass` but extends from `superclass`
|
|
9
|
-
* @internal
|
|
10
12
|
* @param subclass the class that may be a subclass of `superclass`
|
|
11
13
|
* @param superclass the class that may be a base class of `subclass`
|
|
14
|
+
* @note The constructors of all types must be `public`.
|
|
12
15
|
* @returns whether `subclass` is a proper subclass of `superclass`
|
|
16
|
+
* @public
|
|
13
17
|
*/
|
|
14
18
|
function isProperSubclassOf(subclass, superclass) {
|
|
15
19
|
return subclass.prototype instanceof superclass;
|
|
16
20
|
}
|
|
17
21
|
exports.isProperSubclassOf = isProperSubclassOf;
|
|
18
22
|
/** Check if class `subclass` is `superclass` or extends from `superclass`
|
|
19
|
-
* @
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
23
|
+
* @param subclass the class that may be a subclass of `superclass`.
|
|
24
|
+
* @param superclass the class that may be a base class of `subclass`.
|
|
25
|
+
* @note The constructors of all types must be `public`.
|
|
22
26
|
* @returns whether `subclass` is a subclass of `superclass`
|
|
27
|
+
* @public
|
|
23
28
|
*/
|
|
24
29
|
function isSubclassOf(subclass, superclass) {
|
|
25
30
|
return subclass === superclass || isProperSubclassOf(subclass, superclass);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassUtils.js","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F
|
|
1
|
+
{"version":3,"file":"ClassUtils.js","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAIhC,QAAgC,EAAE,UAAsB;IACxD,OAAO,QAAQ,CAAC,SAAS,YAAY,UAAU,CAAC;AAClD,CAAC;AAND,gDAMC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAI1B,QAA6C,EAAE,UAAsB;IACrE,OAAO,QAAQ,KAAK,UAAU,IAAI,kBAAkB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC7E,CAAC;AAND,oCAMC","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 Utils\r\n */\r\n\r\n/** Check if class `subclass` is a different class from `superclass` but extends from `superclass`\r\n * @param subclass the class that may be a subclass of `superclass`\r\n * @param superclass the class that may be a base class of `subclass`\r\n * @note The constructors of all types must be `public`.\r\n * @returns whether `subclass` is a proper subclass of `superclass`\r\n * @public\r\n */\r\nexport function isProperSubclassOf<\r\n SuperClass extends new (..._: any[]) => any,\r\n NonSubClass extends new (..._: any[]) => any,\r\n SubClass extends new (..._: any[]) => InstanceType<SuperClass>,\r\n>(subclass: SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass {\r\n return subclass.prototype instanceof superclass;\r\n}\r\n\r\n/** Check if class `subclass` is `superclass` or extends from `superclass`\r\n * @param subclass the class that may be a subclass of `superclass`.\r\n * @param superclass the class that may be a base class of `subclass`.\r\n * @note The constructors of all types must be `public`.\r\n * @returns whether `subclass` is a subclass of `superclass`\r\n * @public\r\n */\r\nexport function isSubclassOf<\r\n SuperClass extends new (..._: any[]) => any,\r\n NonSubClass extends new (..._: any[]) => any,\r\n SubClass extends new (..._: any[]) => InstanceType<SuperClass>,\r\n>(subclass: SuperClass | SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass | SuperClass {\r\n return subclass === superclass || isProperSubclassOf(subclass, superclass);\r\n}\r\n"]}
|
package/lib/cjs/Logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[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AAG,GAAE,WAAyE,GAAG,IAAI;IAM5I;;;;OAIG;WACW,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;IAK7F;;;;OAIG;WACW,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;IAK1F;;;;OAIG;WACW,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;CAI5F;AAED;;;;;;;;GAQG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IAEnD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAC,CAAkB;IACpC,OAAO,CAAC,eAAe,CAAS;gBAEb,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe;IAahE,OAAO,CAAC,UAAU;IAaX,OAAO,IAAI,IAAI;CAGvB"}
|
package/lib/cjs/Logger.js
CHANGED
|
@@ -174,7 +174,7 @@ class Logger {
|
|
|
174
174
|
* @param log The logger output function to use - defaults to Logger.logError
|
|
175
175
|
* @param metaData Optional data for the message
|
|
176
176
|
*/
|
|
177
|
-
static logException(category, err, log = Logger.logError) {
|
|
177
|
+
static logException(category, err, log = (_category, message) => Logger.logError(_category, message)) {
|
|
178
178
|
log(category, Logger.getExceptionMessage(err), () => {
|
|
179
179
|
return { ...BentleyError_1.BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };
|
|
180
180
|
});
|
package/lib/cjs/Logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,iDAA6E;AAC7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CAAC,eAAe,EAAE,2DAA2D;aACxH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;;AAlCc,oBAAS,GAAa,QAAQ,CAAC,IAAI,CAAC;AADxC,gCAAU","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 Logging\r\n */\r\n\r\nimport { BentleyError, IModelStatus, LoggingMetaData } from \"./BentleyError\";\r\nimport { BentleyLoggerCategory } from \"./BentleyLoggerCategory\";\r\nimport { IDisposable } from \"./Disposable\";\r\n\r\n/** Defines the *signature* for a log function.\r\n * @public\r\n */\r\nexport type LogFunction = (category: string, message: string, metaData: LoggingMetaData) => void;\r\n\r\n/** Use to categorize logging messages by severity.\r\n * @public\r\n */\r\nexport enum LogLevel {\r\n /** Tracing and debugging - low level */\r\n Trace,\r\n /** Information - mid level */\r\n Info,\r\n /** Warnings - high level */\r\n Warning,\r\n /** Errors - highest level */\r\n Error,\r\n /** Higher than any real logging level. This is used to turn a category off. */\r\n None,\r\n}\r\n\r\n/** Identifies a logging category and the LogLevel that should be used for it. The LogLevel is specified by its string name.\r\n * @public\r\n */\r\nexport interface LoggerCategoryAndLevel {\r\n category: string;\r\n logLevel: string;\r\n}\r\n\r\n/** Specifies logging levels, including the default logging level and a set of categories and levels for them.\r\n * @public\r\n */\r\nexport interface LoggerLevelsConfig {\r\n defaultLevel?: string;\r\n categoryLevels?: LoggerCategoryAndLevel[];\r\n}\r\n\r\n/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control\r\n * how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).\r\n * @public\r\n */\r\nexport class Logger {\r\n protected static _logError: LogFunction | undefined;\r\n protected static _logWarning: LogFunction | undefined;\r\n protected static _logInfo: LogFunction | undefined;\r\n protected static _logTrace: LogFunction | undefined;\r\n /** @internal */\r\n public static logLevelChangedFn?: VoidFunction;\r\n private static _categoryFilter = new Map<string, LogLevel>(); // do not change the name of this member, it is referenced directly from node addon\r\n private static _minLevel: LogLevel | undefined = undefined; // do not change the name of this member, it is referenced directly from node addon\r\n\r\n /** Should the call stack be included when an exception is logged? */\r\n public static logExceptionCallstacks = false;\r\n\r\n /** All static metadata is combined with per-call metadata and stringified in every log message.\r\n * Static metadata can either be an object or a function that returns an object.\r\n * Use a key to identify entries in the map so the can be removed individually.\r\n * @internal */\r\n public static staticMetaData = new Map<string, LoggingMetaData>();\r\n\r\n /** Initialize the logger streams. Should be called at application initialization time. */\r\n public static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void {\r\n Logger._logError = logError;\r\n Logger._logWarning = logWarning;\r\n Logger._logInfo = logInfo;\r\n Logger._logTrace = logTrace;\r\n Logger.turnOffLevelDefault();\r\n Logger.turnOffCategories();\r\n }\r\n\r\n /** Initialize the logger to output to the console. */\r\n public static initializeToConsole(): void {\r\n const logConsole = (level: string) => (category: string, message: string, metaData: LoggingMetaData) =>\r\n console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console\r\n\r\n Logger.initialize(logConsole(\"Error\"), logConsole(\"Warning\"), logConsole(\"Info\"), logConsole(\"Trace\"));\r\n }\r\n\r\n /** merge the supplied metadata with all static metadata into one object */\r\n public static getMetaData(metaData?: LoggingMetaData): object {\r\n const metaObj = {};\r\n for (const meta of Logger.staticMetaData) {\r\n const val = BentleyError.getMetaData(meta[1]);\r\n if (val)\r\n Object.assign(metaObj, val);\r\n }\r\n Object.assign(metaObj, BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence\r\n return metaObj;\r\n }\r\n\r\n /** stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then `JSON.stringify`ed. */\r\n public static stringifyMetaData(metaData?: LoggingMetaData): string {\r\n const metaObj = this.getMetaData(metaData);\r\n return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : \"\";\r\n }\r\n\r\n /** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */\r\n public static setLevelDefault(minLevel: LogLevel): void {\r\n this._minLevel = minLevel;\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the\r\n * specified category should be displayed.\r\n */\r\n public static setLevel(category: string, minLevel: LogLevel) {\r\n Logger._categoryFilter.set(category, minLevel);\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Interpret a string as the name of a LogLevel */\r\n public static parseLogLevel(str: string): LogLevel {\r\n switch (str.toUpperCase()) {\r\n case \"EXCEPTION\": return LogLevel.Error;\r\n case \"FATAL\": return LogLevel.Error;\r\n case \"ERROR\": return LogLevel.Error;\r\n case \"WARNING\": return LogLevel.Warning;\r\n case \"INFO\": return LogLevel.Info;\r\n case \"TRACE\": return LogLevel.Trace;\r\n case \"DEBUG\": return LogLevel.Trace;\r\n }\r\n return LogLevel.None;\r\n }\r\n\r\n /** Set the log level for multiple categories at once. Also see [[validateProps]] */\r\n public static configureLevels(cfg: LoggerLevelsConfig) {\r\n Logger.validateProps(cfg);\r\n if (cfg.defaultLevel !== undefined) {\r\n this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));\r\n }\r\n if (cfg.categoryLevels !== undefined) {\r\n for (const cl of cfg.categoryLevels) {\r\n this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));\r\n }\r\n }\r\n }\r\n\r\n private static isLogLevel(v: string) {\r\n return LogLevel.hasOwnProperty(v);\r\n }\r\n\r\n /** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */\r\n public static validateProps(config: any) {\r\n const validProps = [\"defaultLevel\", \"categoryLevels\"];\r\n for (const prop of Object.keys(config)) {\r\n if (!validProps.includes(prop))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);\r\n if (prop === \"defaultLevel\") {\r\n if (!Logger.isLogLevel(config.defaultLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);\r\n } else if (prop === \"categoryLevels\") {\r\n const value = config[prop];\r\n if (!Array.isArray(value))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);\r\n for (const item of config[prop]) {\r\n if (!item.hasOwnProperty(\"category\") || !item.hasOwnProperty(\"logLevel\"))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);\r\n if (!Logger.isLogLevel(item.logLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Get the minimum logging level for the specified category. */\r\n public static getLevel(category: string): LogLevel | undefined {\r\n // Prefer the level set for this category specifically\r\n const minLevelForThisCategory = Logger._categoryFilter.get(category);\r\n if (minLevelForThisCategory !== undefined)\r\n return minLevelForThisCategory;\r\n\r\n // Fall back on the level set for the parent of this category.\r\n const parent = category.lastIndexOf(\".\");\r\n if (parent !== -1)\r\n return Logger.getLevel(category.slice(0, parent));\r\n\r\n // Fall back on the default level.\r\n return Logger._minLevel;\r\n }\r\n\r\n /** Turns off the least severe level at which messages should be displayed by default.\r\n * This turns off logging for all messages for which no category minimum level is defined.\r\n */\r\n public static turnOffLevelDefault(): void {\r\n Logger._minLevel = undefined;\r\n }\r\n\r\n /** Turns off all category level filters previously defined with [[Logger.setLevel]].\r\n */\r\n public static turnOffCategories(): void {\r\n Logger._categoryFilter.clear();\r\n }\r\n\r\n /** Check if messages in the specified category should be displayed at this level of severity. */\r\n public static isEnabled(category: string, level: LogLevel): boolean {\r\n const minLevel = Logger.getLevel(category);\r\n return (minLevel !== undefined) && (level >= minLevel);\r\n }\r\n\r\n /** Log the specified message to the **error** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logError(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))\r\n Logger._logError(category, message, metaData);\r\n }\r\n\r\n private static getExceptionMessage(err: unknown): string {\r\n const stack = Logger.logExceptionCallstacks ? `\\n${BentleyError.getErrorStack(err)}` : \"\";\r\n return BentleyError.getErrorMessage(err) + stack;\r\n }\r\n\r\n /** Log the specified exception. The special \"ExceptionType\" property will be added as metadata,\r\n * in addition to any other metadata that may be supplied by the caller, unless the\r\n * metadata supplied by the caller already includes this property.\r\n * @param category The category of the message.\r\n * @param err The exception object.\r\n * @param log The logger output function to use - defaults to Logger.logError\r\n * @param metaData Optional data for the message\r\n */\r\n public static logException(category: string, err: any, log: LogFunction = Logger.logError): void {\r\n log(category, Logger.getExceptionMessage(err), () => {\r\n return { ...BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };\r\n });\r\n }\r\n\r\n /** Log the specified message to the **warning** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logWarning(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))\r\n Logger._logWarning(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **info** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logInfo(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))\r\n Logger._logInfo(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **trace** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logTrace(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))\r\n Logger._logTrace(category, message, metaData);\r\n }\r\n}\r\n\r\n/** Simple performance diagnostics utility.\r\n * It measures the time from construction to disposal. On disposal it logs the routine name along with\r\n * the duration in milliseconds.\r\n * It also logs the routine name at construction time so that nested calls can be disambiguated.\r\n *\r\n * The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].\r\n * Enable those, if you want to capture timings.\r\n * @public\r\n */\r\nexport class PerfLogger implements IDisposable {\r\n private static _severity: LogLevel = LogLevel.Info;\r\n\r\n private _operation: string;\r\n private _metaData?: LoggingMetaData;\r\n private _startTimeStamp: number;\r\n\r\n public constructor(operation: string, metaData?: LoggingMetaData) {\r\n this._operation = operation;\r\n this._metaData = metaData;\r\n\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity)) {\r\n this._startTimeStamp = 0;\r\n return;\r\n }\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);\r\n this._startTimeStamp = new Date().getTime(); // take timestamp\r\n }\r\n\r\n private logMessage(): void {\r\n const endTimeStamp: number = new Date().getTime();\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity))\r\n return;\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},END`, () => {\r\n const mdata = this._metaData ? BentleyError.getMetaData(this._metaData) : {};\r\n return {\r\n ...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n });\r\n }\r\n\r\n public dispose(): void {\r\n this.logMessage();\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F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AAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7E,OAAO;gBACL,GAAG,KAAK,EAAE,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,2DAA2D;aACxH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;;AAlCc,oBAAS,GAAa,QAAQ,CAAC,IAAI,CAAC;AADxC,gCAAU","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 Logging\r\n */\r\n\r\nimport { BentleyError, IModelStatus, LoggingMetaData } from \"./BentleyError\";\r\nimport { BentleyLoggerCategory } from \"./BentleyLoggerCategory\";\r\nimport { IDisposable } from \"./Disposable\";\r\n\r\n/** Defines the *signature* for a log function.\r\n * @public\r\n */\r\nexport type LogFunction = (category: string, message: string, metaData: LoggingMetaData) => void;\r\n\r\n/** Use to categorize logging messages by severity.\r\n * @public\r\n */\r\nexport enum LogLevel {\r\n /** Tracing and debugging - low level */\r\n Trace,\r\n /** Information - mid level */\r\n Info,\r\n /** Warnings - high level */\r\n Warning,\r\n /** Errors - highest level */\r\n Error,\r\n /** Higher than any real logging level. This is used to turn a category off. */\r\n None,\r\n}\r\n\r\n/** Identifies a logging category and the LogLevel that should be used for it. The LogLevel is specified by its string name.\r\n * @public\r\n */\r\nexport interface LoggerCategoryAndLevel {\r\n category: string;\r\n logLevel: string;\r\n}\r\n\r\n/** Specifies logging levels, including the default logging level and a set of categories and levels for them.\r\n * @public\r\n */\r\nexport interface LoggerLevelsConfig {\r\n defaultLevel?: string;\r\n categoryLevels?: LoggerCategoryAndLevel[];\r\n}\r\n\r\n/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control\r\n * how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).\r\n * @public\r\n */\r\nexport class Logger {\r\n protected static _logError: LogFunction | undefined;\r\n protected static _logWarning: LogFunction | undefined;\r\n protected static _logInfo: LogFunction | undefined;\r\n protected static _logTrace: LogFunction | undefined;\r\n /** @internal */\r\n public static logLevelChangedFn?: VoidFunction;\r\n private static _categoryFilter = new Map<string, LogLevel>(); // do not change the name of this member, it is referenced directly from node addon\r\n private static _minLevel: LogLevel | undefined = undefined; // do not change the name of this member, it is referenced directly from node addon\r\n\r\n /** Should the call stack be included when an exception is logged? */\r\n public static logExceptionCallstacks = false;\r\n\r\n /** All static metadata is combined with per-call metadata and stringified in every log message.\r\n * Static metadata can either be an object or a function that returns an object.\r\n * Use a key to identify entries in the map so the can be removed individually.\r\n * @internal */\r\n public static staticMetaData = new Map<string, LoggingMetaData>();\r\n\r\n /** Initialize the logger streams. Should be called at application initialization time. */\r\n public static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void {\r\n Logger._logError = logError;\r\n Logger._logWarning = logWarning;\r\n Logger._logInfo = logInfo;\r\n Logger._logTrace = logTrace;\r\n Logger.turnOffLevelDefault();\r\n Logger.turnOffCategories();\r\n }\r\n\r\n /** Initialize the logger to output to the console. */\r\n public static initializeToConsole(): void {\r\n const logConsole = (level: string) => (category: string, message: string, metaData: LoggingMetaData) =>\r\n console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console\r\n\r\n Logger.initialize(logConsole(\"Error\"), logConsole(\"Warning\"), logConsole(\"Info\"), logConsole(\"Trace\"));\r\n }\r\n\r\n /** merge the supplied metadata with all static metadata into one object */\r\n public static getMetaData(metaData?: LoggingMetaData): object {\r\n const metaObj = {};\r\n for (const meta of Logger.staticMetaData) {\r\n const val = BentleyError.getMetaData(meta[1]);\r\n if (val)\r\n Object.assign(metaObj, val);\r\n }\r\n Object.assign(metaObj, BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence\r\n return metaObj;\r\n }\r\n\r\n /** stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then `JSON.stringify`ed. */\r\n public static stringifyMetaData(metaData?: LoggingMetaData): string {\r\n const metaObj = this.getMetaData(metaData);\r\n return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : \"\";\r\n }\r\n\r\n /** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */\r\n public static setLevelDefault(minLevel: LogLevel): void {\r\n this._minLevel = minLevel;\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the\r\n * specified category should be displayed.\r\n */\r\n public static setLevel(category: string, minLevel: LogLevel) {\r\n Logger._categoryFilter.set(category, minLevel);\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Interpret a string as the name of a LogLevel */\r\n public static parseLogLevel(str: string): LogLevel {\r\n switch (str.toUpperCase()) {\r\n case \"EXCEPTION\": return LogLevel.Error;\r\n case \"FATAL\": return LogLevel.Error;\r\n case \"ERROR\": return LogLevel.Error;\r\n case \"WARNING\": return LogLevel.Warning;\r\n case \"INFO\": return LogLevel.Info;\r\n case \"TRACE\": return LogLevel.Trace;\r\n case \"DEBUG\": return LogLevel.Trace;\r\n }\r\n return LogLevel.None;\r\n }\r\n\r\n /** Set the log level for multiple categories at once. Also see [[validateProps]] */\r\n public static configureLevels(cfg: LoggerLevelsConfig) {\r\n Logger.validateProps(cfg);\r\n if (cfg.defaultLevel !== undefined) {\r\n this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));\r\n }\r\n if (cfg.categoryLevels !== undefined) {\r\n for (const cl of cfg.categoryLevels) {\r\n this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));\r\n }\r\n }\r\n }\r\n\r\n private static isLogLevel(v: string) {\r\n return LogLevel.hasOwnProperty(v);\r\n }\r\n\r\n /** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */\r\n public static validateProps(config: any) {\r\n const validProps = [\"defaultLevel\", \"categoryLevels\"];\r\n for (const prop of Object.keys(config)) {\r\n if (!validProps.includes(prop))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);\r\n if (prop === \"defaultLevel\") {\r\n if (!Logger.isLogLevel(config.defaultLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);\r\n } else if (prop === \"categoryLevels\") {\r\n const value = config[prop];\r\n if (!Array.isArray(value))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);\r\n for (const item of config[prop]) {\r\n if (!item.hasOwnProperty(\"category\") || !item.hasOwnProperty(\"logLevel\"))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);\r\n if (!Logger.isLogLevel(item.logLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Get the minimum logging level for the specified category. */\r\n public static getLevel(category: string): LogLevel | undefined {\r\n // Prefer the level set for this category specifically\r\n const minLevelForThisCategory = Logger._categoryFilter.get(category);\r\n if (minLevelForThisCategory !== undefined)\r\n return minLevelForThisCategory;\r\n\r\n // Fall back on the level set for the parent of this category.\r\n const parent = category.lastIndexOf(\".\");\r\n if (parent !== -1)\r\n return Logger.getLevel(category.slice(0, parent));\r\n\r\n // Fall back on the default level.\r\n return Logger._minLevel;\r\n }\r\n\r\n /** Turns off the least severe level at which messages should be displayed by default.\r\n * This turns off logging for all messages for which no category minimum level is defined.\r\n */\r\n public static turnOffLevelDefault(): void {\r\n Logger._minLevel = undefined;\r\n }\r\n\r\n /** Turns off all category level filters previously defined with [[Logger.setLevel]].\r\n */\r\n public static turnOffCategories(): void {\r\n Logger._categoryFilter.clear();\r\n }\r\n\r\n /** Check if messages in the specified category should be displayed at this level of severity. */\r\n public static isEnabled(category: string, level: LogLevel): boolean {\r\n const minLevel = Logger.getLevel(category);\r\n return (minLevel !== undefined) && (level >= minLevel);\r\n }\r\n\r\n /** Log the specified message to the **error** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logError(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))\r\n Logger._logError(category, message, metaData);\r\n }\r\n\r\n private static getExceptionMessage(err: unknown): string {\r\n const stack = Logger.logExceptionCallstacks ? `\\n${BentleyError.getErrorStack(err)}` : \"\";\r\n return BentleyError.getErrorMessage(err) + stack;\r\n }\r\n\r\n /** Log the specified exception. The special \"ExceptionType\" property will be added as metadata,\r\n * in addition to any other metadata that may be supplied by the caller, unless the\r\n * metadata supplied by the caller already includes this property.\r\n * @param category The category of the message.\r\n * @param err The exception object.\r\n * @param log The logger output function to use - defaults to Logger.logError\r\n * @param metaData Optional data for the message\r\n */\r\n public static logException(category: string, err: any, log: LogFunction = (_category, message) => Logger.logError(_category, message)): void {\r\n log(category, Logger.getExceptionMessage(err), () => {\r\n return { ...BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };\r\n });\r\n }\r\n\r\n /** Log the specified message to the **warning** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logWarning(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))\r\n Logger._logWarning(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **info** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logInfo(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))\r\n Logger._logInfo(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **trace** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logTrace(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))\r\n Logger._logTrace(category, message, metaData);\r\n }\r\n}\r\n\r\n/** Simple performance diagnostics utility.\r\n * It measures the time from construction to disposal. On disposal it logs the routine name along with\r\n * the duration in milliseconds.\r\n * It also logs the routine name at construction time so that nested calls can be disambiguated.\r\n *\r\n * The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].\r\n * Enable those, if you want to capture timings.\r\n * @public\r\n */\r\nexport class PerfLogger implements IDisposable {\r\n private static _severity: LogLevel = LogLevel.Info;\r\n\r\n private _operation: string;\r\n private _metaData?: LoggingMetaData;\r\n private _startTimeStamp: number;\r\n\r\n public constructor(operation: string, metaData?: LoggingMetaData) {\r\n this._operation = operation;\r\n this._metaData = metaData;\r\n\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity)) {\r\n this._startTimeStamp = 0;\r\n return;\r\n }\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);\r\n this._startTimeStamp = new Date().getTime(); // take timestamp\r\n }\r\n\r\n private logMessage(): void {\r\n const endTimeStamp: number = new Date().getTime();\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity))\r\n return;\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},END`, () => {\r\n const mdata = this._metaData ? BentleyError.getMetaData(this._metaData) : {};\r\n return {\r\n ...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n });\r\n }\r\n\r\n public dispose(): void {\r\n this.logMessage();\r\n }\r\n}\r\n\r\n"]}
|
package/lib/cjs/Tracing.js
CHANGED
|
@@ -110,10 +110,10 @@ class Tracing {
|
|
|
110
110
|
static enableOpenTelemetry(tracer, api) {
|
|
111
111
|
Tracing._tracer = tracer;
|
|
112
112
|
Tracing._openTelemetry = api;
|
|
113
|
-
Logger_1.Logger.logTrace = Tracing.withOpenTelemetry(Logger_1.Logger.logTrace);
|
|
114
|
-
Logger_1.Logger.logInfo = Tracing.withOpenTelemetry(Logger_1.Logger.logInfo);
|
|
115
|
-
Logger_1.Logger.logWarning = Tracing.withOpenTelemetry(Logger_1.Logger.logWarning);
|
|
116
|
-
Logger_1.Logger.logError = Tracing.withOpenTelemetry(Logger_1.Logger.logError);
|
|
113
|
+
Logger_1.Logger.logTrace = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger_1.Logger.logTrace(category, message, metaData));
|
|
114
|
+
Logger_1.Logger.logInfo = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger_1.Logger.logInfo(category, message, metaData));
|
|
115
|
+
Logger_1.Logger.logWarning = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger_1.Logger.logWarning(category, message, metaData));
|
|
116
|
+
Logger_1.Logger.logError = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger_1.Logger.logError(category, message, metaData));
|
|
117
117
|
}
|
|
118
118
|
static withOpenTelemetry(base, isError = false) {
|
|
119
119
|
return (category, message, metaData) => {
|
package/lib/cjs/Tracing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tracing.js","sourceRoot":"","sources":["../../src/Tracing.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,qCAA+C;AAE/C,kGAAkG;AAClG;;;GAGG;AACH,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,+CAAY,CAAA;IACZ,2CAAU,CAAA;IACV,2CAAU,CAAA;IACV,+CAAY,CAAA;IACZ,+CAAY,CAAA;AACd,CAAC,EANW,Q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UAAmB,KAAK;QAC1E,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;YACrC,IAAI;gBACF,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,CAAC,eAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;aACvK;YAAC,OAAO,EAAE,EAAE,GAAG,CAAC,mHAAmH;YACpI,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,aAAa,CAAC,UAA0B;QACpD,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5G,CAAC;CACF;AArED,0BAqEC","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 Logging\r\n */\r\n\r\nimport type { ContextAPI, SpanAttributes, SpanAttributeValue, SpanContext, SpanOptions, TraceAPI, Tracer } from \"@opentelemetry/api\";\r\nimport { LogFunction, Logger } from \"./Logger\";\r\n\r\n// re-export so that consumers can construct full SpanOptions object without external dependencies\r\n/**\r\n * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)\r\n * @public\r\n */\r\nexport enum SpanKind {\r\n INTERNAL = 0,\r\n SERVER = 1,\r\n CLIENT = 2,\r\n PRODUCER = 3,\r\n CONSUMER = 4\r\n}\r\n\r\nfunction isValidPrimitive(val: unknown): val is SpanAttributeValue {\r\n return typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\";\r\n}\r\n\r\n// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.\r\n// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.\r\nfunction isValidPrimitiveArray(val: unknown): val is SpanAttributeValue {\r\n if (!Array.isArray(val))\r\n return false;\r\n\r\n let itemType;\r\n for (const x of val) {\r\n if (x === undefined || x === null)\r\n continue;\r\n\r\n if (!itemType) {\r\n itemType = typeof x;\r\n if (!isValidPrimitive(x))\r\n return false;\r\n }\r\n\r\n if (typeof x !== itemType)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction isPlainObject(obj: unknown): obj is object {\r\n return typeof obj === \"object\" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\r\n}\r\n\r\nfunction* getFlatEntries(obj: unknown, path = \"\"): Iterable<[string, SpanAttributeValue]> {\r\n if (isValidPrimitiveArray(obj)) {\r\n yield [path, obj];\r\n return;\r\n }\r\n\r\n // Prefer JSON serialization over flattening for any non-POJO types.\r\n // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)\r\n if (!isPlainObject(obj) && !Array.isArray(obj)) {\r\n yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];\r\n return;\r\n }\r\n\r\n // Always serialize empty objects/arrays as empty array values\r\n const entries = Object.entries(obj);\r\n if (entries.length === 0)\r\n yield [path, []];\r\n\r\n for (const [key, val] of entries)\r\n yield* getFlatEntries(val, (path === \"\") ? key : `${path}.${key}`);\r\n}\r\n\r\nfunction flattenObject(obj: object): SpanAttributes {\r\n return Object.fromEntries(getFlatEntries(obj));\r\n}\r\n\r\n/**\r\n * Enables OpenTelemetry tracing in addition to traditional logging.\r\n * @public\r\n */\r\nexport class Tracing {\r\n private static _tracer?: Tracer;\r\n private static _openTelemetry?: { trace: Pick<TraceAPI, \"setSpan\" | \"setSpanContext\" | \"getSpan\">, context: Pick<ContextAPI, \"active\" | \"with\"> };\r\n\r\n /**\r\n * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.\r\n * If OpenTelemetry tracing is _not_ enabled, runs the provided function.\r\n * @param name name of the new span\r\n * @param fn function to run inside the new span\r\n * @param options span options\r\n * @param parentContext optional context used to retrieve parent span id\r\n */\r\n public static async withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T> {\r\n if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)\r\n return fn();\r\n\r\n // this case is for context propagation - parentContext is typically constructed from HTTP headers\r\n const parent = parentContext === undefined\r\n ? Tracing._openTelemetry.context.active()\r\n : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);\r\n\r\n return Tracing._openTelemetry.context.with(\r\n Tracing._openTelemetry.trace.setSpan(\r\n parent,\r\n Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())\r\n ),\r\n async () => {\r\n try {\r\n return await fn();\r\n } catch (err) {\r\n if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute(\"error\", true);\r\n throw err;\r\n } finally {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();\r\n }\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.\r\n * [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.\r\n * @note Node.js OpenTelemetry SDK should be initialized by the user.\r\n */\r\n public static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry) {\r\n Tracing._tracer = tracer;\r\n Tracing._openTelemetry = api;\r\n Logger.logTrace = Tracing.withOpenTelemetry(Logger.logTrace);\r\n Logger.logInfo = Tracing.withOpenTelemetry(Logger.logInfo);\r\n Logger.logWarning = Tracing.withOpenTelemetry(Logger.logWarning);\r\n Logger.logError = Tracing.withOpenTelemetry(Logger.logError);\r\n }\r\n\r\n private static withOpenTelemetry(base: LogFunction, isError: boolean = false): LogFunction {\r\n return (category, message, metaData) => {\r\n try {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });\r\n } catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work\r\n base(category, message, metaData);\r\n };\r\n }\r\n\r\n /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.\r\n * @param attributes The attributes to set\r\n */\r\n public static setAttributes(attributes: SpanAttributes) {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Tracing.js","sourceRoot":"","sources":["../../src/Tracing.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,qCAA+C;AAE/C,kGAAkG;AAClG;;;GAGG;AACH,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,+CAAY,CAAA;IACZ,2CAAU,CAAA;IACV,2CAAU,CAAA;IACV,+CAAY,CAAA;IACZ,+CAAY,CAAA;AACd,CAAC,EANW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAMnB;AAED,SAAS,gBAAgB,CAAC,GAAY;IACpC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,SAAS,CAAC;AACxF,CAAC;AAED,6GAA6G;AAC7G,iJAAiJ;AACjJ,SAAS,qBAAqB,CAAC,GAAY;IACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC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,iBAAiB,CAAC,GAAG,EAAE,CAAC,eAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IACnI,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAAC,IAAiB,EAAE,UAAmB,KAAK;QAC1E,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;YACrC,IAAI;gBACF,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,CAAC,eAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;aACvK;YAAC,OAAO,EAAE,EAAE,GAAG,CAAC,mHAAmH;YACpI,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,aAAa,CAAC,UAA0B;QACpD,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5G,CAAC;CACF;AArED,0BAqEC","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 Logging\r\n */\r\n\r\nimport type { ContextAPI, SpanAttributes, SpanAttributeValue, SpanContext, SpanOptions, TraceAPI, Tracer } from \"@opentelemetry/api\";\r\nimport { LogFunction, Logger } from \"./Logger\";\r\n\r\n// re-export so that consumers can construct full SpanOptions object without external dependencies\r\n/**\r\n * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)\r\n * @public\r\n */\r\nexport enum SpanKind {\r\n INTERNAL = 0,\r\n SERVER = 1,\r\n CLIENT = 2,\r\n PRODUCER = 3,\r\n CONSUMER = 4\r\n}\r\n\r\nfunction isValidPrimitive(val: unknown): val is SpanAttributeValue {\r\n return typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\";\r\n}\r\n\r\n// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.\r\n// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.\r\nfunction isValidPrimitiveArray(val: unknown): val is SpanAttributeValue {\r\n if (!Array.isArray(val))\r\n return false;\r\n\r\n let itemType;\r\n for (const x of val) {\r\n if (x === undefined || x === null)\r\n continue;\r\n\r\n if (!itemType) {\r\n itemType = typeof x;\r\n if (!isValidPrimitive(x))\r\n return false;\r\n }\r\n\r\n if (typeof x !== itemType)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction isPlainObject(obj: unknown): obj is object {\r\n return typeof obj === \"object\" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\r\n}\r\n\r\nfunction* getFlatEntries(obj: unknown, path = \"\"): Iterable<[string, SpanAttributeValue]> {\r\n if (isValidPrimitiveArray(obj)) {\r\n yield [path, obj];\r\n return;\r\n }\r\n\r\n // Prefer JSON serialization over flattening for any non-POJO types.\r\n // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)\r\n if (!isPlainObject(obj) && !Array.isArray(obj)) {\r\n yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];\r\n return;\r\n }\r\n\r\n // Always serialize empty objects/arrays as empty array values\r\n const entries = Object.entries(obj);\r\n if (entries.length === 0)\r\n yield [path, []];\r\n\r\n for (const [key, val] of entries)\r\n yield* getFlatEntries(val, (path === \"\") ? key : `${path}.${key}`);\r\n}\r\n\r\nfunction flattenObject(obj: object): SpanAttributes {\r\n return Object.fromEntries(getFlatEntries(obj));\r\n}\r\n\r\n/**\r\n * Enables OpenTelemetry tracing in addition to traditional logging.\r\n * @public\r\n */\r\nexport class Tracing {\r\n private static _tracer?: Tracer;\r\n private static _openTelemetry?: { trace: Pick<TraceAPI, \"setSpan\" | \"setSpanContext\" | \"getSpan\">, context: Pick<ContextAPI, \"active\" | \"with\"> };\r\n\r\n /**\r\n * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.\r\n * If OpenTelemetry tracing is _not_ enabled, runs the provided function.\r\n * @param name name of the new span\r\n * @param fn function to run inside the new span\r\n * @param options span options\r\n * @param parentContext optional context used to retrieve parent span id\r\n */\r\n public static async withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T> {\r\n if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)\r\n return fn();\r\n\r\n // this case is for context propagation - parentContext is typically constructed from HTTP headers\r\n const parent = parentContext === undefined\r\n ? Tracing._openTelemetry.context.active()\r\n : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);\r\n\r\n return Tracing._openTelemetry.context.with(\r\n Tracing._openTelemetry.trace.setSpan(\r\n parent,\r\n Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active()),\r\n ),\r\n async () => {\r\n try {\r\n return await fn();\r\n } catch (err) {\r\n if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute(\"error\", true);\r\n throw err;\r\n } finally {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();\r\n }\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.\r\n * [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.\r\n * @note Node.js OpenTelemetry SDK should be initialized by the user.\r\n */\r\n public static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry) {\r\n Tracing._tracer = tracer;\r\n Tracing._openTelemetry = api;\r\n Logger.logTrace = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logTrace(category, message, metaData));\r\n Logger.logInfo = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logInfo(category, message, metaData));\r\n Logger.logWarning = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logWarning(category, message, metaData));\r\n Logger.logError = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logError(category, message, metaData));\r\n }\r\n\r\n private static withOpenTelemetry(base: LogFunction, isError: boolean = false): LogFunction {\r\n return (category, message, metaData) => {\r\n try {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });\r\n } catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work\r\n base(category, message, metaData);\r\n };\r\n }\r\n\r\n /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.\r\n * @param attributes The attributes to set\r\n */\r\n public static setAttributes(attributes: SpanAttributes) {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TupleKeyedMap.js","sourceRoot":"","sources":["../../src/TupleKeyedMap.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,aAAa;IAGxB,oCAAoC;IACpC,YAAmB,OAA6C;QAHxD,SAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;QAuExC,UAAK,GAAW,CAAC,CAAC;QAnExB,IAAI,OAAO;YACT,KAAK,MAAM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AAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;aAC1B;YACD,MAAM,GAAG,IAAI,CAAC;SACf;QACD,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,CAAC,MAAM,YAAY,GAAG,CAAC;YAC1B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvB,QAAS,CAAC,CAAA,IAAI,CAAC,GAAkB,EAAE,SAAyB;YAC1D,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,EAAE;gBACxB,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC;gBAClC,IAAI,CAAC,YAAY,GAAG,EAAE;oBACpB,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;iBACzB;qBAAM;oBACL,MAAM,CAAC,OAAmB,EAAE,CAAC,CAAC,CAAC;iBAChC;aACF;QACH,CAAC;QACD,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAGD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;CACF;AAhFD,sCAgFC","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 Collections\r\n */\r\n\r\n/** A map similar to the standard JavaScript Map collection except that the keys must be a tuple\r\n * (javascript array), and two keys are considered equal if their elements in order are strict-equal,\r\n * and the tuples have the same amount of elements\r\n *\r\n * This means you can use array literals to key data in Maps that would otherwise be reference-compared\r\n * if using JavaScript's built in Map\r\n *\r\n * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead\r\n * SameValueZero equality comparison\r\n * @see https://262.ecma-international.org/6.0/#sec-samevaluezero\r\n *\r\n * ```js\r\n * const map = new TupleKeyedMap([[1,\"y\"], \"value\"]);\r\n * const value = map.get([1, \"y\"]); // a normal map would identify these keys as different because they are independent objects\r\n * ```\r\n *\r\n * It is implemented by each index of the tuple key being used as a singular key into a submap\r\n * @note this only implements a subset of the Map interface\r\n * @public\r\n */\r\nexport class TupleKeyedMap<K extends readonly any[], V> {\r\n private _map = new Map<K[0], Map<any, V> | V>();\r\n\r\n // argument types match those of Map\r\n public constructor(entries?: readonly (readonly [K, V])[] | null) {\r\n if (entries)\r\n for (const [k, v] of entries) {\r\n this.set(k, v);\r\n }\r\n }\r\n\r\n public clear(): void {\r\n return this._map.clear();\r\n }\r\n\r\n private makeKeyError() {\r\n return Error(\r\n \"A Bad key was used, it didn't match the key type of the the map.\"
|
|
1
|
+
{"version":3,"file":"TupleKeyedMap.js","sourceRoot":"","sources":["../../src/TupleKeyedMap.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,aAAa;IAGxB,oCAAoC;IACpC,YAAmB,OAA6C;QAHxD,SAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;QAuExC,UAAK,GAAW,CAAC,CAAC;QAnExB,IAAI,OAAO;YACT,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,EAAE;gBAC5B,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aAChB;IACL,C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AAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,CAAC,MAAM,YAAY,GAAG,CAAC;YAC1B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvB,QAAS,CAAC,CAAA,IAAI,CAAC,GAAkB,EAAE,SAAyB;YAC1D,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,EAAE;gBACxB,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC;gBAClC,IAAI,CAAC,YAAY,GAAG,EAAE;oBACpB,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;iBACzB;qBAAM;oBACL,MAAM,CAAC,OAAmB,EAAE,CAAC,CAAC,CAAC;iBAChC;aACF;QACH,CAAC;QACD,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAGD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;CACF;AAhFD,sCAgFC","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 Collections\r\n */\r\n\r\n/** A map similar to the standard JavaScript Map collection except that the keys must be a tuple\r\n * (javascript array), and two keys are considered equal if their elements in order are strict-equal,\r\n * and the tuples have the same amount of elements\r\n *\r\n * This means you can use array literals to key data in Maps that would otherwise be reference-compared\r\n * if using JavaScript's built in Map\r\n *\r\n * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead\r\n * SameValueZero equality comparison\r\n * @see https://262.ecma-international.org/6.0/#sec-samevaluezero\r\n *\r\n * ```js\r\n * const map = new TupleKeyedMap([[1,\"y\"], \"value\"]);\r\n * const value = map.get([1, \"y\"]); // a normal map would identify these keys as different because they are independent objects\r\n * ```\r\n *\r\n * It is implemented by each index of the tuple key being used as a singular key into a submap\r\n * @note this only implements a subset of the Map interface\r\n * @public\r\n */\r\nexport class TupleKeyedMap<K extends readonly any[], V> {\r\n private _map = new Map<K[0], Map<any, V> | V>();\r\n\r\n // argument types match those of Map\r\n public constructor(entries?: readonly (readonly [K, V])[] | null) {\r\n if (entries)\r\n for (const [k, v] of entries) {\r\n this.set(k, v);\r\n }\r\n }\r\n\r\n public clear(): void {\r\n return this._map.clear();\r\n }\r\n\r\n private makeKeyError() {\r\n return Error(\r\n \"A Bad key was used, it didn't match the key type of the the map.\",\r\n );\r\n }\r\n\r\n public get(key: K): V | undefined {\r\n let cursor: Map<any, any> | V = this._map;\r\n for (const subkey of key) {\r\n if (!(cursor instanceof Map))\r\n throw this.makeKeyError();\r\n cursor = cursor.get(subkey);\r\n if (cursor === undefined)\r\n return undefined;\r\n }\r\n if (cursor instanceof Map)\r\n throw this.makeKeyError();\r\n return cursor;\r\n }\r\n\r\n public has(key: K): boolean {\r\n return this.get(key) !== undefined;\r\n }\r\n\r\n public set(key: K, value: V): this {\r\n let cursor: Map<any, any> = this._map;\r\n for (let i = 0; i < key.length - 1; ++i) {\r\n const subkey = key[i];\r\n let next = cursor.get(subkey);\r\n if (next === undefined) {\r\n next = new Map();\r\n cursor.set(subkey, next);\r\n }\r\n cursor = next;\r\n }\r\n const finalSubkey = key[key.length - 1];\r\n if (!(cursor instanceof Map))\r\n throw this.makeKeyError();\r\n cursor.set(finalSubkey, value);\r\n this._size++;\r\n return this;\r\n }\r\n\r\n public *[Symbol.iterator](): IterableIterator<[K, V]> {\r\n function *impl(map: Map<any, any>, keyPrefix: readonly any[]): IterableIterator<[K, V]> {\r\n for (const [k, v] of map) {\r\n const nextKey = [...keyPrefix, k];\r\n if (v instanceof Map) {\r\n yield* impl(v, nextKey);\r\n } else {\r\n yield [nextKey as any as K, v];\r\n }\r\n }\r\n }\r\n yield* impl(this._map, []);\r\n }\r\n\r\n private _size: number = 0;\r\n public get size(): number {\r\n return this._size;\r\n }\r\n\r\n public get [Symbol.toStringTag](): string {\r\n return this.constructor.name;\r\n }\r\n}\r\n"]}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
/** Options supplied to a [[YieldManager]].
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
2
7
|
export interface YieldManagerOptions {
|
|
8
|
+
/** The number of times [[YieldManager.allowYield]] must be called to trigger an actual yield.
|
|
9
|
+
* Default: 1000.
|
|
10
|
+
*/
|
|
3
11
|
iterationsBeforeYield?: number;
|
|
4
12
|
}
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
/** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.
|
|
14
|
+
* This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).
|
|
15
|
+
* It maintains a count of the number of iterations that have occurred since the last yield.
|
|
16
|
+
* The constructor specifies how many iterations of the loop are permitted before yielding.
|
|
17
|
+
* The loop should `await` [[allowYield]] on each iteration.
|
|
18
|
+
* [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.
|
|
19
|
+
* @public
|
|
11
20
|
*/
|
|
12
21
|
export declare class YieldManager {
|
|
13
|
-
|
|
22
|
+
/** Options controlling the yield behavior. */
|
|
23
|
+
readonly options: Readonly<Required<YieldManagerOptions>>;
|
|
14
24
|
private _counter;
|
|
25
|
+
/** Constructor.
|
|
26
|
+
* @param options Options customizing the yield behavior. Omitted properties are assigned their default values.
|
|
27
|
+
*/
|
|
15
28
|
constructor(options?: YieldManagerOptions);
|
|
29
|
+
/** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */
|
|
16
30
|
allowYield(): Promise<void>;
|
|
31
|
+
/** @internal */
|
|
17
32
|
protected actualYield(): Promise<void>;
|
|
18
33
|
}
|
|
19
34
|
//# sourceMappingURL=YieldManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YieldManager.d.ts","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"YieldManager.d.ts","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAMD;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB,8CAA8C;IAC9C,SAAgB,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,CAAK;IAErB;;OAEG;gBACgB,OAAO,GAAE,mBAAwB;IAIpD,oIAAoI;IACvH,UAAU;IAOvB,gBAAgB;cACA,WAAW;CAG5B"}
|
package/lib/cjs/YieldManager.js
CHANGED
|
@@ -3,30 +3,38 @@
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Utils
|
|
8
|
+
*/
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
exports.YieldManager = void 0;
|
|
8
|
-
/** @internal the default options when constructing yield managers */
|
|
9
11
|
const defaultYieldManagerOptions = {
|
|
10
12
|
iterationsBeforeYield: 1000,
|
|
11
13
|
};
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
/** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.
|
|
15
|
+
* This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).
|
|
16
|
+
* It maintains a count of the number of iterations that have occurred since the last yield.
|
|
17
|
+
* The constructor specifies how many iterations of the loop are permitted before yielding.
|
|
18
|
+
* The loop should `await` [[allowYield]] on each iteration.
|
|
19
|
+
* [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.
|
|
20
|
+
* @public
|
|
18
21
|
*/
|
|
19
22
|
class YieldManager {
|
|
23
|
+
/** Constructor.
|
|
24
|
+
* @param options Options customizing the yield behavior. Omitted properties are assigned their default values.
|
|
25
|
+
*/
|
|
20
26
|
constructor(options = {}) {
|
|
21
27
|
this._counter = 0;
|
|
22
28
|
this.options = { ...defaultYieldManagerOptions, ...options };
|
|
23
29
|
}
|
|
30
|
+
/** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */
|
|
24
31
|
async allowYield() {
|
|
25
32
|
this._counter = (this._counter + 1) % this.options.iterationsBeforeYield;
|
|
26
33
|
if (this._counter === 0) {
|
|
27
34
|
await this.actualYield();
|
|
28
35
|
}
|
|
29
36
|
}
|
|
37
|
+
/** @internal */
|
|
30
38
|
async actualYield() {
|
|
31
39
|
await new Promise((r) => setTimeout(r, 0));
|
|
32
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YieldManager.js","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F
|
|
1
|
+
{"version":3,"file":"YieldManager.js","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAYH,MAAM,0BAA0B,GAAkC;IAChE,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAa,YAAY;IAKvB;;OAEG;IACH,YAAmB,UAA+B,EAAE;QAL5C,aAAQ,GAAG,CAAC,CAAC;QAMnB,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,0BAA0B,EAAE,GAAG,OAAO,EAAE,CAAC;IAC/D,CAAC;IAED,oIAAoI;IAC7H,KAAK,CAAC,UAAU;QACrB,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC;QACzE,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC,EAAE;YACvB,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;SAC1B;IACH,CAAC;IAED,gBAAgB;IACN,KAAK,CAAC,WAAW;QACzB,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAxBD,oCAwBC","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 Utils\r\n */\r\n\r\n/** Options supplied to a [[YieldManager]].\r\n * @public\r\n */\r\nexport interface YieldManagerOptions {\r\n /** The number of times [[YieldManager.allowYield]] must be called to trigger an actual yield.\r\n * Default: 1000.\r\n */\r\n iterationsBeforeYield?: number;\r\n}\r\n\r\nconst defaultYieldManagerOptions: Required<YieldManagerOptions> = {\r\n iterationsBeforeYield: 1000,\r\n};\r\n\r\n/** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.\r\n * This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).\r\n * It maintains a count of the number of iterations that have occurred since the last yield.\r\n * The constructor specifies how many iterations of the loop are permitted before yielding.\r\n * The loop should `await` [[allowYield]] on each iteration.\r\n * [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.\r\n * @public\r\n */\r\nexport class YieldManager {\r\n /** Options controlling the yield behavior. */\r\n public readonly options: Readonly<Required<YieldManagerOptions>>;\r\n private _counter = 0;\r\n\r\n /** Constructor.\r\n * @param options Options customizing the yield behavior. Omitted properties are assigned their default values.\r\n */\r\n public constructor(options: YieldManagerOptions = {}) {\r\n this.options = { ...defaultYieldManagerOptions, ...options };\r\n }\r\n\r\n /** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */\r\n public async allowYield() {\r\n this._counter = (this._counter + 1) % this.options.iterationsBeforeYield;\r\n if (this._counter === 0) {\r\n await this.actualYield();\r\n }\r\n }\r\n\r\n /** @internal */\r\n protected async actualYield() {\r\n await new Promise((r) => setTimeout(r, 0));\r\n }\r\n}\r\n"]}
|
package/lib/esm/ClassUtils.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
1
4
|
/** Check if class `subclass` is a different class from `superclass` but extends from `superclass`
|
|
2
|
-
* @internal
|
|
3
5
|
* @param subclass the class that may be a subclass of `superclass`
|
|
4
6
|
* @param superclass the class that may be a base class of `subclass`
|
|
7
|
+
* @note The constructors of all types must be `public`.
|
|
5
8
|
* @returns whether `subclass` is a proper subclass of `superclass`
|
|
9
|
+
* @public
|
|
6
10
|
*/
|
|
7
11
|
export declare function isProperSubclassOf<SuperClass extends new (..._: any[]) => any, NonSubClass extends new (..._: any[]) => any, SubClass extends new (..._: any[]) => InstanceType<SuperClass>>(subclass: SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass;
|
|
8
12
|
/** Check if class `subclass` is `superclass` or extends from `superclass`
|
|
9
|
-
* @
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
13
|
+
* @param subclass the class that may be a subclass of `superclass`.
|
|
14
|
+
* @param superclass the class that may be a base class of `subclass`.
|
|
15
|
+
* @note The constructors of all types must be `public`.
|
|
12
16
|
* @returns whether `subclass` is a subclass of `superclass`
|
|
17
|
+
* @public
|
|
13
18
|
*/
|
|
14
19
|
export declare function isSubclassOf<SuperClass extends new (..._: any[]) => any, NonSubClass extends new (..._: any[]) => any, SubClass extends new (..._: any[]) => InstanceType<SuperClass>>(subclass: SuperClass | SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass | SuperClass;
|
|
15
20
|
//# sourceMappingURL=ClassUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassUtils.d.ts","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClassUtils.d.ts","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3C,WAAW,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC5C,QAAQ,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,YAAY,CAAC,UAAU,CAAC,EAC9D,QAAQ,EAAE,QAAQ,GAAG,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,QAAQ,IAAI,QAAQ,CAEhF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,UAAU,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3C,WAAW,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,EAC5C,QAAQ,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,YAAY,CAAC,UAAU,CAAC,EAC9D,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,QAAQ,IAAI,QAAQ,GAAG,UAAU,CAE1G"}
|
package/lib/esm/ClassUtils.js
CHANGED
|
@@ -2,20 +2,25 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Utils
|
|
7
|
+
*/
|
|
5
8
|
/** Check if class `subclass` is a different class from `superclass` but extends from `superclass`
|
|
6
|
-
* @internal
|
|
7
9
|
* @param subclass the class that may be a subclass of `superclass`
|
|
8
10
|
* @param superclass the class that may be a base class of `subclass`
|
|
11
|
+
* @note The constructors of all types must be `public`.
|
|
9
12
|
* @returns whether `subclass` is a proper subclass of `superclass`
|
|
13
|
+
* @public
|
|
10
14
|
*/
|
|
11
15
|
export function isProperSubclassOf(subclass, superclass) {
|
|
12
16
|
return subclass.prototype instanceof superclass;
|
|
13
17
|
}
|
|
14
18
|
/** Check if class `subclass` is `superclass` or extends from `superclass`
|
|
15
|
-
* @
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
19
|
+
* @param subclass the class that may be a subclass of `superclass`.
|
|
20
|
+
* @param superclass the class that may be a base class of `subclass`.
|
|
21
|
+
* @note The constructors of all types must be `public`.
|
|
18
22
|
* @returns whether `subclass` is a subclass of `superclass`
|
|
23
|
+
* @public
|
|
19
24
|
*/
|
|
20
25
|
export function isSubclassOf(subclass, superclass) {
|
|
21
26
|
return subclass === superclass || isProperSubclassOf(subclass, superclass);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassUtils.js","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;
|
|
1
|
+
{"version":3,"file":"ClassUtils.js","sourceRoot":"","sources":["../../src/ClassUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAIhC,QAAgC,EAAE,UAAsB;IACxD,OAAO,QAAQ,CAAC,SAAS,YAAY,UAAU,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAI1B,QAA6C,EAAE,UAAsB;IACrE,OAAO,QAAQ,KAAK,UAAU,IAAI,kBAAkB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC7E,CAAC","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 Utils\r\n */\r\n\r\n/** Check if class `subclass` is a different class from `superclass` but extends from `superclass`\r\n * @param subclass the class that may be a subclass of `superclass`\r\n * @param superclass the class that may be a base class of `subclass`\r\n * @note The constructors of all types must be `public`.\r\n * @returns whether `subclass` is a proper subclass of `superclass`\r\n * @public\r\n */\r\nexport function isProperSubclassOf<\r\n SuperClass extends new (..._: any[]) => any,\r\n NonSubClass extends new (..._: any[]) => any,\r\n SubClass extends new (..._: any[]) => InstanceType<SuperClass>,\r\n>(subclass: SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass {\r\n return subclass.prototype instanceof superclass;\r\n}\r\n\r\n/** Check if class `subclass` is `superclass` or extends from `superclass`\r\n * @param subclass the class that may be a subclass of `superclass`.\r\n * @param superclass the class that may be a base class of `subclass`.\r\n * @note The constructors of all types must be `public`.\r\n * @returns whether `subclass` is a subclass of `superclass`\r\n * @public\r\n */\r\nexport function isSubclassOf<\r\n SuperClass extends new (..._: any[]) => any,\r\n NonSubClass extends new (..._: any[]) => any,\r\n SubClass extends new (..._: any[]) => InstanceType<SuperClass>,\r\n>(subclass: SuperClass | SubClass | NonSubClass, superclass: SuperClass): subclass is SubClass | SuperClass {\r\n return subclass === superclass || isProperSubclassOf(subclass, superclass);\r\n}\r\n"]}
|
package/lib/esm/Logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAA8B,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;AAEjG;;GAEG;AACH,oBAAY,QAAQ;IAClB,wCAAwC;IACxC,KAAK,IAAA;IACL,8BAA8B;IAC9B,IAAI,IAAA;IACJ,4BAA4B;IAC5B,OAAO,IAAA;IACP,6BAA6B;IAC7B,KAAK,IAAA;IACL,+EAA+E;IAC/E,IAAI,IAAA;CACL;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;CAC3C;AAED;;;GAGG;AACH,qBAAa,MAAM;IACjB,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IACtD,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC;IACnD,SAAS,CAAC,MAAM,CAAC,SA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K,EAAE,QAAQ,GAAG,OAAO;IAKnE;;;;OAIG;WACW,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;IAK3F,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAKlC;;;;;;;OAOG;WACW,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,WAAyE,GAAG,IAAI;IAM5I;;;;OAIG;WACW,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;IAK7F;;;;OAIG;WACW,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;IAK1F;;;;OAIG;WACW,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;CAI5F;AAED;;;;;;;;GAQG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IAEnD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAC,CAAkB;IACpC,OAAO,CAAC,eAAe,CAAS;gBAEb,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe;IAahE,OAAO,CAAC,UAAU;IAaX,OAAO,IAAI,IAAI;CAGvB"}
|
package/lib/esm/Logger.js
CHANGED
|
@@ -171,7 +171,7 @@ class Logger {
|
|
|
171
171
|
* @param log The logger output function to use - defaults to Logger.logError
|
|
172
172
|
* @param metaData Optional data for the message
|
|
173
173
|
*/
|
|
174
|
-
static logException(category, err, log = Logger.logError) {
|
|
174
|
+
static logException(category, err, log = (_category, message) => Logger.logError(_category, message)) {
|
|
175
175
|
log(category, Logger.getExceptionMessage(err), () => {
|
|
176
176
|
return { ...BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };
|
|
177
177
|
});
|
package/lib/esm/Logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAQhE;;GAEG;AACH,MAAM,CAAN,IAAY,QAWX;AAXD,WAAY,QAAQ;IAClB,wCAAwC;IACxC,yCAAK,CAAA;IACL,8BAA8B;IAC9B,uCAAI,CAAA;IACJ,4BAA4B;IAC5B,6CAAO,CAAA;IACP,6BAA6B;IAC7B,yCAAK,CAAA;IACL,+EAA+E;IAC/E,uCAAI,CAAA;AACN,CAAC,EAXW,QAAQ,KAAR,QAAQ,QAWnB;AAkBD;;;GAGG;AACH,MAAa,MAAM;IAmBjB,0FAA0F;IACnF,MAAM,CAAC,UAAU,CAAC,QAAsB,EAAE,UAAwB,EAAE,OAAqB,EAAE,QAAsB;QACtH,MAAM,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC5B,MAAM,CAAC,WAAW,GAAG,UAAU,CAAC;QAChC,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC1B,MAAM,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC5B,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC7B,MAAM,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAED,sDAAsD;IAC/C,MAAM,CAAC,mBAAmB;QAC/B,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,OAAe,EAAE,QAAyB,EAAE,EAAE,CACrG,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,MAAM,QAAQ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C;YAC5E,OAAO;QAET,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,UAAU,MAAM,EAAE,GAAG,EAAE;YAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7E,OAAO;gBACL,GAAG,KAAK,EAAE,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,2DAA2D;aACxH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;;AAlCc,oBAAS,GAAa,QAAQ,CAAC,IAAI,CAAC;SADxC,UAAU","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 Logging\r\n */\r\n\r\nimport { BentleyError, IModelStatus, LoggingMetaData } from \"./BentleyError\";\r\nimport { BentleyLoggerCategory } from \"./BentleyLoggerCategory\";\r\nimport { IDisposable } from \"./Disposable\";\r\n\r\n/** Defines the *signature* for a log function.\r\n * @public\r\n */\r\nexport type LogFunction = (category: string, message: string, metaData: LoggingMetaData) => void;\r\n\r\n/** Use to categorize logging messages by severity.\r\n * @public\r\n */\r\nexport enum LogLevel {\r\n /** Tracing and debugging - low level */\r\n Trace,\r\n /** Information - mid level */\r\n Info,\r\n /** Warnings - high level */\r\n Warning,\r\n /** Errors - highest level */\r\n Error,\r\n /** Higher than any real logging level. This is used to turn a category off. */\r\n None,\r\n}\r\n\r\n/** Identifies a logging category and the LogLevel that should be used for it. The LogLevel is specified by its string name.\r\n * @public\r\n */\r\nexport interface LoggerCategoryAndLevel {\r\n category: string;\r\n logLevel: string;\r\n}\r\n\r\n/** Specifies logging levels, including the default logging level and a set of categories and levels for them.\r\n * @public\r\n */\r\nexport interface LoggerLevelsConfig {\r\n defaultLevel?: string;\r\n categoryLevels?: LoggerCategoryAndLevel[];\r\n}\r\n\r\n/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control\r\n * how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).\r\n * @public\r\n */\r\nexport class Logger {\r\n protected static _logError: LogFunction | undefined;\r\n protected static _logWarning: LogFunction | undefined;\r\n protected static _logInfo: LogFunction | undefined;\r\n protected static _logTrace: LogFunction | undefined;\r\n /** @internal */\r\n public static logLevelChangedFn?: VoidFunction;\r\n private static _categoryFilter = new Map<string, LogLevel>(); // do not change the name of this member, it is referenced directly from node addon\r\n private static _minLevel: LogLevel | undefined = undefined; // do not change the name of this member, it is referenced directly from node addon\r\n\r\n /** Should the call stack be included when an exception is logged? */\r\n public static logExceptionCallstacks = false;\r\n\r\n /** All static metadata is combined with per-call metadata and stringified in every log message.\r\n * Static metadata can either be an object or a function that returns an object.\r\n * Use a key to identify entries in the map so the can be removed individually.\r\n * @internal */\r\n public static staticMetaData = new Map<string, LoggingMetaData>();\r\n\r\n /** Initialize the logger streams. Should be called at application initialization time. */\r\n public static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void {\r\n Logger._logError = logError;\r\n Logger._logWarning = logWarning;\r\n Logger._logInfo = logInfo;\r\n Logger._logTrace = logTrace;\r\n Logger.turnOffLevelDefault();\r\n Logger.turnOffCategories();\r\n }\r\n\r\n /** Initialize the logger to output to the console. */\r\n public static initializeToConsole(): void {\r\n const logConsole = (level: string) => (category: string, message: string, metaData: LoggingMetaData) =>\r\n console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console\r\n\r\n Logger.initialize(logConsole(\"Error\"), logConsole(\"Warning\"), logConsole(\"Info\"), logConsole(\"Trace\"));\r\n }\r\n\r\n /** merge the supplied metadata with all static metadata into one object */\r\n public static getMetaData(metaData?: LoggingMetaData): object {\r\n const metaObj = {};\r\n for (const meta of Logger.staticMetaData) {\r\n const val = BentleyError.getMetaData(meta[1]);\r\n if (val)\r\n Object.assign(metaObj, val);\r\n }\r\n Object.assign(metaObj, BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence\r\n return metaObj;\r\n }\r\n\r\n /** stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then `JSON.stringify`ed. */\r\n public static stringifyMetaData(metaData?: LoggingMetaData): string {\r\n const metaObj = this.getMetaData(metaData);\r\n return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : \"\";\r\n }\r\n\r\n /** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */\r\n public static setLevelDefault(minLevel: LogLevel): void {\r\n this._minLevel = minLevel;\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the\r\n * specified category should be displayed.\r\n */\r\n public static setLevel(category: string, minLevel: LogLevel) {\r\n Logger._categoryFilter.set(category, minLevel);\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Interpret a string as the name of a LogLevel */\r\n public static parseLogLevel(str: string): LogLevel {\r\n switch (str.toUpperCase()) {\r\n case \"EXCEPTION\": return LogLevel.Error;\r\n case \"FATAL\": return LogLevel.Error;\r\n case \"ERROR\": return LogLevel.Error;\r\n case \"WARNING\": return LogLevel.Warning;\r\n case \"INFO\": return LogLevel.Info;\r\n case \"TRACE\": return LogLevel.Trace;\r\n case \"DEBUG\": return LogLevel.Trace;\r\n }\r\n return LogLevel.None;\r\n }\r\n\r\n /** Set the log level for multiple categories at once. Also see [[validateProps]] */\r\n public static configureLevels(cfg: LoggerLevelsConfig) {\r\n Logger.validateProps(cfg);\r\n if (cfg.defaultLevel !== undefined) {\r\n this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));\r\n }\r\n if (cfg.categoryLevels !== undefined) {\r\n for (const cl of cfg.categoryLevels) {\r\n this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));\r\n }\r\n }\r\n }\r\n\r\n private static isLogLevel(v: string) {\r\n return LogLevel.hasOwnProperty(v);\r\n }\r\n\r\n /** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */\r\n public static validateProps(config: any) {\r\n const validProps = [\"defaultLevel\", \"categoryLevels\"];\r\n for (const prop of Object.keys(config)) {\r\n if (!validProps.includes(prop))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);\r\n if (prop === \"defaultLevel\") {\r\n if (!Logger.isLogLevel(config.defaultLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);\r\n } else if (prop === \"categoryLevels\") {\r\n const value = config[prop];\r\n if (!Array.isArray(value))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);\r\n for (const item of config[prop]) {\r\n if (!item.hasOwnProperty(\"category\") || !item.hasOwnProperty(\"logLevel\"))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);\r\n if (!Logger.isLogLevel(item.logLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Get the minimum logging level for the specified category. */\r\n public static getLevel(category: string): LogLevel | undefined {\r\n // Prefer the level set for this category specifically\r\n const minLevelForThisCategory = Logger._categoryFilter.get(category);\r\n if (minLevelForThisCategory !== undefined)\r\n return minLevelForThisCategory;\r\n\r\n // Fall back on the level set for the parent of this category.\r\n const parent = category.lastIndexOf(\".\");\r\n if (parent !== -1)\r\n return Logger.getLevel(category.slice(0, parent));\r\n\r\n // Fall back on the default level.\r\n return Logger._minLevel;\r\n }\r\n\r\n /** Turns off the least severe level at which messages should be displayed by default.\r\n * This turns off logging for all messages for which no category minimum level is defined.\r\n */\r\n public static turnOffLevelDefault(): void {\r\n Logger._minLevel = undefined;\r\n }\r\n\r\n /** Turns off all category level filters previously defined with [[Logger.setLevel]].\r\n */\r\n public static turnOffCategories(): void {\r\n Logger._categoryFilter.clear();\r\n }\r\n\r\n /** Check if messages in the specified category should be displayed at this level of severity. */\r\n public static isEnabled(category: string, level: LogLevel): boolean {\r\n const minLevel = Logger.getLevel(category);\r\n return (minLevel !== undefined) && (level >= minLevel);\r\n }\r\n\r\n /** Log the specified message to the **error** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logError(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))\r\n Logger._logError(category, message, metaData);\r\n }\r\n\r\n private static getExceptionMessage(err: unknown): string {\r\n const stack = Logger.logExceptionCallstacks ? `\\n${BentleyError.getErrorStack(err)}` : \"\";\r\n return BentleyError.getErrorMessage(err) + stack;\r\n }\r\n\r\n /** Log the specified exception. The special \"ExceptionType\" property will be added as metadata,\r\n * in addition to any other metadata that may be supplied by the caller, unless the\r\n * metadata supplied by the caller already includes this property.\r\n * @param category The category of the message.\r\n * @param err The exception object.\r\n * @param log The logger output function to use - defaults to Logger.logError\r\n * @param metaData Optional data for the message\r\n */\r\n public static logException(category: string, err: any, log: LogFunction = Logger.logError): void {\r\n log(category, Logger.getExceptionMessage(err), () => {\r\n return { ...BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };\r\n });\r\n }\r\n\r\n /** Log the specified message to the **warning** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logWarning(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))\r\n Logger._logWarning(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **info** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logInfo(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))\r\n Logger._logInfo(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **trace** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logTrace(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))\r\n Logger._logTrace(category, message, metaData);\r\n }\r\n}\r\n\r\n/** Simple performance diagnostics utility.\r\n * It measures the time from construction to disposal. On disposal it logs the routine name along with\r\n * the duration in milliseconds.\r\n * It also logs the routine name at construction time so that nested calls can be disambiguated.\r\n *\r\n * The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].\r\n * Enable those, if you want to capture timings.\r\n * @public\r\n */\r\nexport class PerfLogger implements IDisposable {\r\n private static _severity: LogLevel = LogLevel.Info;\r\n\r\n private _operation: string;\r\n private _metaData?: LoggingMetaData;\r\n private _startTimeStamp: number;\r\n\r\n public constructor(operation: string, metaData?: LoggingMetaData) {\r\n this._operation = operation;\r\n this._metaData = metaData;\r\n\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity)) {\r\n this._startTimeStamp = 0;\r\n return;\r\n }\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);\r\n this._startTimeStamp = new Date().getTime(); // take timestamp\r\n }\r\n\r\n private logMessage(): void {\r\n const endTimeStamp: number = new Date().getTime();\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity))\r\n return;\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},END`, () => {\r\n const mdata = this._metaData ? BentleyError.getMetaData(this._metaData) : {};\r\n return {\r\n ...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n });\r\n }\r\n\r\n public dispose(): void {\r\n this.logMessage();\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAQhE;;GAEG;AACH,MAAM,CAAN,IAAY,QAWX;AAXD,WAAY,QAAQ;IAClB,wCAAwC;IACxC,yCAAK,CAAA;IACL,8BAA8B;IAC9B,uCAAI,CAAA;IACJ,4BAA4B;IAC5B,6CAAO,CAAA;IACP,6BAA6B;IAC7B,yCAAK,CAAA;IACL,+EAA+E;IAC/E,uCAAI,CAAA;AACN,CAAC,EAXW,QAAQ,KAAR,QAAQ,QAWnB;AAkBD;;;GAGG;AACH,MAAa,MAAM;IAmBjB,0FAA0F;IACnF,MAAM,CAAC,UAAU,CAAC,QAAsB,EAAE,UAAwB,EAAE,OAAqB,EAAE,QAAsB;QACtH,MAAM,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC5B,MAAM,CAAC,WAAW,GAAG,UAAU,CAAC;QAChC,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC1B,MAAM,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC5B,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC7B,MAAM,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAED,sDAAsD;IAC/C,MAAM,CAAC,mBAAmB;QAC/B,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAgB,E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UAAU;QAChB,MAAM,YAAY,GAAW,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC;YAC5E,OAAO;QAET,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,UAAU,MAAM,EAAE,GAAG,EAAE;YAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7E,OAAO;gBACL,GAAG,KAAK,EAAE,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,2DAA2D;aACxH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;;AAlCc,oBAAS,GAAa,QAAQ,CAAC,IAAI,CAAC;SADxC,UAAU","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 Logging\r\n */\r\n\r\nimport { BentleyError, IModelStatus, LoggingMetaData } from \"./BentleyError\";\r\nimport { BentleyLoggerCategory } from \"./BentleyLoggerCategory\";\r\nimport { IDisposable } from \"./Disposable\";\r\n\r\n/** Defines the *signature* for a log function.\r\n * @public\r\n */\r\nexport type LogFunction = (category: string, message: string, metaData: LoggingMetaData) => void;\r\n\r\n/** Use to categorize logging messages by severity.\r\n * @public\r\n */\r\nexport enum LogLevel {\r\n /** Tracing and debugging - low level */\r\n Trace,\r\n /** Information - mid level */\r\n Info,\r\n /** Warnings - high level */\r\n Warning,\r\n /** Errors - highest level */\r\n Error,\r\n /** Higher than any real logging level. This is used to turn a category off. */\r\n None,\r\n}\r\n\r\n/** Identifies a logging category and the LogLevel that should be used for it. The LogLevel is specified by its string name.\r\n * @public\r\n */\r\nexport interface LoggerCategoryAndLevel {\r\n category: string;\r\n logLevel: string;\r\n}\r\n\r\n/** Specifies logging levels, including the default logging level and a set of categories and levels for them.\r\n * @public\r\n */\r\nexport interface LoggerLevelsConfig {\r\n defaultLevel?: string;\r\n categoryLevels?: LoggerCategoryAndLevel[];\r\n}\r\n\r\n/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control\r\n * how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).\r\n * @public\r\n */\r\nexport class Logger {\r\n protected static _logError: LogFunction | undefined;\r\n protected static _logWarning: LogFunction | undefined;\r\n protected static _logInfo: LogFunction | undefined;\r\n protected static _logTrace: LogFunction | undefined;\r\n /** @internal */\r\n public static logLevelChangedFn?: VoidFunction;\r\n private static _categoryFilter = new Map<string, LogLevel>(); // do not change the name of this member, it is referenced directly from node addon\r\n private static _minLevel: LogLevel | undefined = undefined; // do not change the name of this member, it is referenced directly from node addon\r\n\r\n /** Should the call stack be included when an exception is logged? */\r\n public static logExceptionCallstacks = false;\r\n\r\n /** All static metadata is combined with per-call metadata and stringified in every log message.\r\n * Static metadata can either be an object or a function that returns an object.\r\n * Use a key to identify entries in the map so the can be removed individually.\r\n * @internal */\r\n public static staticMetaData = new Map<string, LoggingMetaData>();\r\n\r\n /** Initialize the logger streams. Should be called at application initialization time. */\r\n public static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void {\r\n Logger._logError = logError;\r\n Logger._logWarning = logWarning;\r\n Logger._logInfo = logInfo;\r\n Logger._logTrace = logTrace;\r\n Logger.turnOffLevelDefault();\r\n Logger.turnOffCategories();\r\n }\r\n\r\n /** Initialize the logger to output to the console. */\r\n public static initializeToConsole(): void {\r\n const logConsole = (level: string) => (category: string, message: string, metaData: LoggingMetaData) =>\r\n console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console\r\n\r\n Logger.initialize(logConsole(\"Error\"), logConsole(\"Warning\"), logConsole(\"Info\"), logConsole(\"Trace\"));\r\n }\r\n\r\n /** merge the supplied metadata with all static metadata into one object */\r\n public static getMetaData(metaData?: LoggingMetaData): object {\r\n const metaObj = {};\r\n for (const meta of Logger.staticMetaData) {\r\n const val = BentleyError.getMetaData(meta[1]);\r\n if (val)\r\n Object.assign(metaObj, val);\r\n }\r\n Object.assign(metaObj, BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence\r\n return metaObj;\r\n }\r\n\r\n /** stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then `JSON.stringify`ed. */\r\n public static stringifyMetaData(metaData?: LoggingMetaData): string {\r\n const metaObj = this.getMetaData(metaData);\r\n return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : \"\";\r\n }\r\n\r\n /** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */\r\n public static setLevelDefault(minLevel: LogLevel): void {\r\n this._minLevel = minLevel;\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the\r\n * specified category should be displayed.\r\n */\r\n public static setLevel(category: string, minLevel: LogLevel) {\r\n Logger._categoryFilter.set(category, minLevel);\r\n this.logLevelChangedFn?.();\r\n }\r\n\r\n /** Interpret a string as the name of a LogLevel */\r\n public static parseLogLevel(str: string): LogLevel {\r\n switch (str.toUpperCase()) {\r\n case \"EXCEPTION\": return LogLevel.Error;\r\n case \"FATAL\": return LogLevel.Error;\r\n case \"ERROR\": return LogLevel.Error;\r\n case \"WARNING\": return LogLevel.Warning;\r\n case \"INFO\": return LogLevel.Info;\r\n case \"TRACE\": return LogLevel.Trace;\r\n case \"DEBUG\": return LogLevel.Trace;\r\n }\r\n return LogLevel.None;\r\n }\r\n\r\n /** Set the log level for multiple categories at once. Also see [[validateProps]] */\r\n public static configureLevels(cfg: LoggerLevelsConfig) {\r\n Logger.validateProps(cfg);\r\n if (cfg.defaultLevel !== undefined) {\r\n this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));\r\n }\r\n if (cfg.categoryLevels !== undefined) {\r\n for (const cl of cfg.categoryLevels) {\r\n this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));\r\n }\r\n }\r\n }\r\n\r\n private static isLogLevel(v: string) {\r\n return LogLevel.hasOwnProperty(v);\r\n }\r\n\r\n /** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */\r\n public static validateProps(config: any) {\r\n const validProps = [\"defaultLevel\", \"categoryLevels\"];\r\n for (const prop of Object.keys(config)) {\r\n if (!validProps.includes(prop))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);\r\n if (prop === \"defaultLevel\") {\r\n if (!Logger.isLogLevel(config.defaultLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);\r\n } else if (prop === \"categoryLevels\") {\r\n const value = config[prop];\r\n if (!Array.isArray(value))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);\r\n for (const item of config[prop]) {\r\n if (!item.hasOwnProperty(\"category\") || !item.hasOwnProperty(\"logLevel\"))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);\r\n if (!Logger.isLogLevel(item.logLevel))\r\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Get the minimum logging level for the specified category. */\r\n public static getLevel(category: string): LogLevel | undefined {\r\n // Prefer the level set for this category specifically\r\n const minLevelForThisCategory = Logger._categoryFilter.get(category);\r\n if (minLevelForThisCategory !== undefined)\r\n return minLevelForThisCategory;\r\n\r\n // Fall back on the level set for the parent of this category.\r\n const parent = category.lastIndexOf(\".\");\r\n if (parent !== -1)\r\n return Logger.getLevel(category.slice(0, parent));\r\n\r\n // Fall back on the default level.\r\n return Logger._minLevel;\r\n }\r\n\r\n /** Turns off the least severe level at which messages should be displayed by default.\r\n * This turns off logging for all messages for which no category minimum level is defined.\r\n */\r\n public static turnOffLevelDefault(): void {\r\n Logger._minLevel = undefined;\r\n }\r\n\r\n /** Turns off all category level filters previously defined with [[Logger.setLevel]].\r\n */\r\n public static turnOffCategories(): void {\r\n Logger._categoryFilter.clear();\r\n }\r\n\r\n /** Check if messages in the specified category should be displayed at this level of severity. */\r\n public static isEnabled(category: string, level: LogLevel): boolean {\r\n const minLevel = Logger.getLevel(category);\r\n return (minLevel !== undefined) && (level >= minLevel);\r\n }\r\n\r\n /** Log the specified message to the **error** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logError(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))\r\n Logger._logError(category, message, metaData);\r\n }\r\n\r\n private static getExceptionMessage(err: unknown): string {\r\n const stack = Logger.logExceptionCallstacks ? `\\n${BentleyError.getErrorStack(err)}` : \"\";\r\n return BentleyError.getErrorMessage(err) + stack;\r\n }\r\n\r\n /** Log the specified exception. The special \"ExceptionType\" property will be added as metadata,\r\n * in addition to any other metadata that may be supplied by the caller, unless the\r\n * metadata supplied by the caller already includes this property.\r\n * @param category The category of the message.\r\n * @param err The exception object.\r\n * @param log The logger output function to use - defaults to Logger.logError\r\n * @param metaData Optional data for the message\r\n */\r\n public static logException(category: string, err: any, log: LogFunction = (_category, message) => Logger.logError(_category, message)): void {\r\n log(category, Logger.getExceptionMessage(err), () => {\r\n return { ...BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };\r\n });\r\n }\r\n\r\n /** Log the specified message to the **warning** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logWarning(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))\r\n Logger._logWarning(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **info** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logInfo(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))\r\n Logger._logInfo(category, message, metaData);\r\n }\r\n\r\n /** Log the specified message to the **trace** stream.\r\n * @param category The category of the message.\r\n * @param message The message.\r\n * @param metaData Optional data for the message\r\n */\r\n public static logTrace(category: string, message: string, metaData?: LoggingMetaData): void {\r\n if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))\r\n Logger._logTrace(category, message, metaData);\r\n }\r\n}\r\n\r\n/** Simple performance diagnostics utility.\r\n * It measures the time from construction to disposal. On disposal it logs the routine name along with\r\n * the duration in milliseconds.\r\n * It also logs the routine name at construction time so that nested calls can be disambiguated.\r\n *\r\n * The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].\r\n * Enable those, if you want to capture timings.\r\n * @public\r\n */\r\nexport class PerfLogger implements IDisposable {\r\n private static _severity: LogLevel = LogLevel.Info;\r\n\r\n private _operation: string;\r\n private _metaData?: LoggingMetaData;\r\n private _startTimeStamp: number;\r\n\r\n public constructor(operation: string, metaData?: LoggingMetaData) {\r\n this._operation = operation;\r\n this._metaData = metaData;\r\n\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity)) {\r\n this._startTimeStamp = 0;\r\n return;\r\n }\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);\r\n this._startTimeStamp = new Date().getTime(); // take timestamp\r\n }\r\n\r\n private logMessage(): void {\r\n const endTimeStamp: number = new Date().getTime();\r\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity))\r\n return;\r\n\r\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},END`, () => {\r\n const mdata = this._metaData ? BentleyError.getMetaData(this._metaData) : {};\r\n return {\r\n ...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n });\r\n }\r\n\r\n public dispose(): void {\r\n this.logMessage();\r\n }\r\n}\r\n\r\n"]}
|
package/lib/esm/Tracing.js
CHANGED
|
@@ -107,10 +107,10 @@ export class Tracing {
|
|
|
107
107
|
static enableOpenTelemetry(tracer, api) {
|
|
108
108
|
Tracing._tracer = tracer;
|
|
109
109
|
Tracing._openTelemetry = api;
|
|
110
|
-
Logger.logTrace = Tracing.withOpenTelemetry(Logger.logTrace);
|
|
111
|
-
Logger.logInfo = Tracing.withOpenTelemetry(Logger.logInfo);
|
|
112
|
-
Logger.logWarning = Tracing.withOpenTelemetry(Logger.logWarning);
|
|
113
|
-
Logger.logError = Tracing.withOpenTelemetry(Logger.logError);
|
|
110
|
+
Logger.logTrace = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logTrace(category, message, metaData));
|
|
111
|
+
Logger.logInfo = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logInfo(category, message, metaData));
|
|
112
|
+
Logger.logWarning = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logWarning(category, message, metaData));
|
|
113
|
+
Logger.logError = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logError(category, message, metaData));
|
|
114
114
|
}
|
|
115
115
|
static withOpenTelemetry(base, isError = false) {
|
|
116
116
|
return (category, message, metaData) => {
|
package/lib/esm/Tracing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tracing.js","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AO,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAAC,IAAiB,EAAE,UAAmB,KAAK;QAC1E,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;YACrC,IAAI;gBACF,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;aACvK;YAAC,OAAO,EAAE,EAAE,GAAG,CAAC,mHAAmH;YACpI,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,aAAa,CAAC,UAA0B;QACpD,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5G,CAAC;CACF","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 Logging\r\n */\r\n\r\nimport type { ContextAPI, SpanAttributes, SpanAttributeValue, SpanContext, SpanOptions, TraceAPI, Tracer } from \"@opentelemetry/api\";\r\nimport { LogFunction, Logger } from \"./Logger\";\r\n\r\n// re-export so that consumers can construct full SpanOptions object without external dependencies\r\n/**\r\n * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)\r\n * @public\r\n */\r\nexport enum SpanKind {\r\n INTERNAL = 0,\r\n SERVER = 1,\r\n CLIENT = 2,\r\n PRODUCER = 3,\r\n CONSUMER = 4\r\n}\r\n\r\nfunction isValidPrimitive(val: unknown): val is SpanAttributeValue {\r\n return typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\";\r\n}\r\n\r\n// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.\r\n// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.\r\nfunction isValidPrimitiveArray(val: unknown): val is SpanAttributeValue {\r\n if (!Array.isArray(val))\r\n return false;\r\n\r\n let itemType;\r\n for (const x of val) {\r\n if (x === undefined || x === null)\r\n continue;\r\n\r\n if (!itemType) {\r\n itemType = typeof x;\r\n if (!isValidPrimitive(x))\r\n return false;\r\n }\r\n\r\n if (typeof x !== itemType)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction isPlainObject(obj: unknown): obj is object {\r\n return typeof obj === \"object\" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\r\n}\r\n\r\nfunction* getFlatEntries(obj: unknown, path = \"\"): Iterable<[string, SpanAttributeValue]> {\r\n if (isValidPrimitiveArray(obj)) {\r\n yield [path, obj];\r\n return;\r\n }\r\n\r\n // Prefer JSON serialization over flattening for any non-POJO types.\r\n // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)\r\n if (!isPlainObject(obj) && !Array.isArray(obj)) {\r\n yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];\r\n return;\r\n }\r\n\r\n // Always serialize empty objects/arrays as empty array values\r\n const entries = Object.entries(obj);\r\n if (entries.length === 0)\r\n yield [path, []];\r\n\r\n for (const [key, val] of entries)\r\n yield* getFlatEntries(val, (path === \"\") ? key : `${path}.${key}`);\r\n}\r\n\r\nfunction flattenObject(obj: object): SpanAttributes {\r\n return Object.fromEntries(getFlatEntries(obj));\r\n}\r\n\r\n/**\r\n * Enables OpenTelemetry tracing in addition to traditional logging.\r\n * @public\r\n */\r\nexport class Tracing {\r\n private static _tracer?: Tracer;\r\n private static _openTelemetry?: { trace: Pick<TraceAPI, \"setSpan\" | \"setSpanContext\" | \"getSpan\">, context: Pick<ContextAPI, \"active\" | \"with\"> };\r\n\r\n /**\r\n * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.\r\n * If OpenTelemetry tracing is _not_ enabled, runs the provided function.\r\n * @param name name of the new span\r\n * @param fn function to run inside the new span\r\n * @param options span options\r\n * @param parentContext optional context used to retrieve parent span id\r\n */\r\n public static async withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T> {\r\n if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)\r\n return fn();\r\n\r\n // this case is for context propagation - parentContext is typically constructed from HTTP headers\r\n const parent = parentContext === undefined\r\n ? Tracing._openTelemetry.context.active()\r\n : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);\r\n\r\n return Tracing._openTelemetry.context.with(\r\n Tracing._openTelemetry.trace.setSpan(\r\n parent,\r\n Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())\r\n ),\r\n async () => {\r\n try {\r\n return await fn();\r\n } catch (err) {\r\n if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute(\"error\", true);\r\n throw err;\r\n } finally {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();\r\n }\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.\r\n * [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.\r\n * @note Node.js OpenTelemetry SDK should be initialized by the user.\r\n */\r\n public static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry) {\r\n Tracing._tracer = tracer;\r\n Tracing._openTelemetry = api;\r\n Logger.logTrace = Tracing.withOpenTelemetry(Logger.logTrace);\r\n Logger.logInfo = Tracing.withOpenTelemetry(Logger.logInfo);\r\n Logger.logWarning = Tracing.withOpenTelemetry(Logger.logWarning);\r\n Logger.logError = Tracing.withOpenTelemetry(Logger.logError);\r\n }\r\n\r\n private static withOpenTelemetry(base: LogFunction, isError: boolean = false): LogFunction {\r\n return (category, message, metaData) => {\r\n try {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });\r\n } catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work\r\n base(category, message, metaData);\r\n };\r\n }\r\n\r\n /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.\r\n * @param attributes The attributes to set\r\n */\r\n public static setAttributes(attributes: SpanAttributes) {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Tracing.js","sourceRoot":"","sources":["../../src/Tracing.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAe,MAAM,EAAE,MAAM,UAAU,CAAC;AAE/C,kGAAkG;AAClG;;;GAGG;AACH,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,+CAAY,CAAA;IACZ,2CAAU,CAAA;IACV,2CAAU,CAAA;IACV,+CAAY,CAAA;IACZ,+CAA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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 Logging\r\n */\r\n\r\nimport type { ContextAPI, SpanAttributes, SpanAttributeValue, SpanContext, SpanOptions, TraceAPI, Tracer } from \"@opentelemetry/api\";\r\nimport { LogFunction, Logger } from \"./Logger\";\r\n\r\n// re-export so that consumers can construct full SpanOptions object without external dependencies\r\n/**\r\n * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)\r\n * @public\r\n */\r\nexport enum SpanKind {\r\n INTERNAL = 0,\r\n SERVER = 1,\r\n CLIENT = 2,\r\n PRODUCER = 3,\r\n CONSUMER = 4\r\n}\r\n\r\nfunction isValidPrimitive(val: unknown): val is SpanAttributeValue {\r\n return typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\";\r\n}\r\n\r\n// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.\r\n// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.\r\nfunction isValidPrimitiveArray(val: unknown): val is SpanAttributeValue {\r\n if (!Array.isArray(val))\r\n return false;\r\n\r\n let itemType;\r\n for (const x of val) {\r\n if (x === undefined || x === null)\r\n continue;\r\n\r\n if (!itemType) {\r\n itemType = typeof x;\r\n if (!isValidPrimitive(x))\r\n return false;\r\n }\r\n\r\n if (typeof x !== itemType)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction isPlainObject(obj: unknown): obj is object {\r\n return typeof obj === \"object\" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\r\n}\r\n\r\nfunction* getFlatEntries(obj: unknown, path = \"\"): Iterable<[string, SpanAttributeValue]> {\r\n if (isValidPrimitiveArray(obj)) {\r\n yield [path, obj];\r\n return;\r\n }\r\n\r\n // Prefer JSON serialization over flattening for any non-POJO types.\r\n // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)\r\n if (!isPlainObject(obj) && !Array.isArray(obj)) {\r\n yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];\r\n return;\r\n }\r\n\r\n // Always serialize empty objects/arrays as empty array values\r\n const entries = Object.entries(obj);\r\n if (entries.length === 0)\r\n yield [path, []];\r\n\r\n for (const [key, val] of entries)\r\n yield* getFlatEntries(val, (path === \"\") ? key : `${path}.${key}`);\r\n}\r\n\r\nfunction flattenObject(obj: object): SpanAttributes {\r\n return Object.fromEntries(getFlatEntries(obj));\r\n}\r\n\r\n/**\r\n * Enables OpenTelemetry tracing in addition to traditional logging.\r\n * @public\r\n */\r\nexport class Tracing {\r\n private static _tracer?: Tracer;\r\n private static _openTelemetry?: { trace: Pick<TraceAPI, \"setSpan\" | \"setSpanContext\" | \"getSpan\">, context: Pick<ContextAPI, \"active\" | \"with\"> };\r\n\r\n /**\r\n * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.\r\n * If OpenTelemetry tracing is _not_ enabled, runs the provided function.\r\n * @param name name of the new span\r\n * @param fn function to run inside the new span\r\n * @param options span options\r\n * @param parentContext optional context used to retrieve parent span id\r\n */\r\n public static async withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T> {\r\n if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)\r\n return fn();\r\n\r\n // this case is for context propagation - parentContext is typically constructed from HTTP headers\r\n const parent = parentContext === undefined\r\n ? Tracing._openTelemetry.context.active()\r\n : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);\r\n\r\n return Tracing._openTelemetry.context.with(\r\n Tracing._openTelemetry.trace.setSpan(\r\n parent,\r\n Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active()),\r\n ),\r\n async () => {\r\n try {\r\n return await fn();\r\n } catch (err) {\r\n if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute(\"error\", true);\r\n throw err;\r\n } finally {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();\r\n }\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.\r\n * [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.\r\n * @note Node.js OpenTelemetry SDK should be initialized by the user.\r\n */\r\n public static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry) {\r\n Tracing._tracer = tracer;\r\n Tracing._openTelemetry = api;\r\n Logger.logTrace = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logTrace(category, message, metaData));\r\n Logger.logInfo = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logInfo(category, message, metaData));\r\n Logger.logWarning = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logWarning(category, message, metaData));\r\n Logger.logError = (category, message, metaData) => Tracing.withOpenTelemetry(() => Logger.logError(category, message, metaData));\r\n }\r\n\r\n private static withOpenTelemetry(base: LogFunction, isError: boolean = false): LogFunction {\r\n return (category, message, metaData) => {\r\n try {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });\r\n } catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work\r\n base(category, message, metaData);\r\n };\r\n }\r\n\r\n /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.\r\n * @param attributes The attributes to set\r\n */\r\n public static setAttributes(attributes: SpanAttributes) {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
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b,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;CACF","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 Collections\r\n */\r\n\r\n/** A map similar to the standard JavaScript Map collection except that the keys must be a tuple\r\n * (javascript array), and two keys are considered equal if their elements in order are strict-equal,\r\n * and the tuples have the same amount of elements\r\n *\r\n * This means you can use array literals to key data in Maps that would otherwise be reference-compared\r\n * if using JavaScript's built in Map\r\n *\r\n * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead\r\n * SameValueZero equality comparison\r\n * @see https://262.ecma-international.org/6.0/#sec-samevaluezero\r\n *\r\n * ```js\r\n * const map = new TupleKeyedMap([[1,\"y\"], \"value\"]);\r\n * const value = map.get([1, \"y\"]); // a normal map would identify these keys as different because they are independent objects\r\n * ```\r\n *\r\n * It is implemented by each index of the tuple key being used as a singular key into a submap\r\n * @note this only implements a subset of the Map interface\r\n * @public\r\n */\r\nexport class TupleKeyedMap<K extends readonly any[], V> {\r\n private _map = new Map<K[0], Map<any, V> | V>();\r\n\r\n // argument types match those of Map\r\n public constructor(entries?: readonly (readonly [K, V])[] | null) {\r\n if (entries)\r\n for (const [k, v] of entries) {\r\n this.set(k, v);\r\n }\r\n }\r\n\r\n public clear(): void {\r\n return this._map.clear();\r\n }\r\n\r\n private makeKeyError() {\r\n return Error(\r\n \"A Bad key was used, it didn't match the key type of the the map.\"
|
|
1
|
+
{"version":3,"file":"TupleKeyedMap.js","sourceRoot":"","sources":["../../src/TupleKeyedMap.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;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AC/B,CAAC;CACF","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 Collections\r\n */\r\n\r\n/** A map similar to the standard JavaScript Map collection except that the keys must be a tuple\r\n * (javascript array), and two keys are considered equal if their elements in order are strict-equal,\r\n * and the tuples have the same amount of elements\r\n *\r\n * This means you can use array literals to key data in Maps that would otherwise be reference-compared\r\n * if using JavaScript's built in Map\r\n *\r\n * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead\r\n * SameValueZero equality comparison\r\n * @see https://262.ecma-international.org/6.0/#sec-samevaluezero\r\n *\r\n * ```js\r\n * const map = new TupleKeyedMap([[1,\"y\"], \"value\"]);\r\n * const value = map.get([1, \"y\"]); // a normal map would identify these keys as different because they are independent objects\r\n * ```\r\n *\r\n * It is implemented by each index of the tuple key being used as a singular key into a submap\r\n * @note this only implements a subset of the Map interface\r\n * @public\r\n */\r\nexport class TupleKeyedMap<K extends readonly any[], V> {\r\n private _map = new Map<K[0], Map<any, V> | V>();\r\n\r\n // argument types match those of Map\r\n public constructor(entries?: readonly (readonly [K, V])[] | null) {\r\n if (entries)\r\n for (const [k, v] of entries) {\r\n this.set(k, v);\r\n }\r\n }\r\n\r\n public clear(): void {\r\n return this._map.clear();\r\n }\r\n\r\n private makeKeyError() {\r\n return Error(\r\n \"A Bad key was used, it didn't match the key type of the the map.\",\r\n );\r\n }\r\n\r\n public get(key: K): V | undefined {\r\n let cursor: Map<any, any> | V = this._map;\r\n for (const subkey of key) {\r\n if (!(cursor instanceof Map))\r\n throw this.makeKeyError();\r\n cursor = cursor.get(subkey);\r\n if (cursor === undefined)\r\n return undefined;\r\n }\r\n if (cursor instanceof Map)\r\n throw this.makeKeyError();\r\n return cursor;\r\n }\r\n\r\n public has(key: K): boolean {\r\n return this.get(key) !== undefined;\r\n }\r\n\r\n public set(key: K, value: V): this {\r\n let cursor: Map<any, any> = this._map;\r\n for (let i = 0; i < key.length - 1; ++i) {\r\n const subkey = key[i];\r\n let next = cursor.get(subkey);\r\n if (next === undefined) {\r\n next = new Map();\r\n cursor.set(subkey, next);\r\n }\r\n cursor = next;\r\n }\r\n const finalSubkey = key[key.length - 1];\r\n if (!(cursor instanceof Map))\r\n throw this.makeKeyError();\r\n cursor.set(finalSubkey, value);\r\n this._size++;\r\n return this;\r\n }\r\n\r\n public *[Symbol.iterator](): IterableIterator<[K, V]> {\r\n function *impl(map: Map<any, any>, keyPrefix: readonly any[]): IterableIterator<[K, V]> {\r\n for (const [k, v] of map) {\r\n const nextKey = [...keyPrefix, k];\r\n if (v instanceof Map) {\r\n yield* impl(v, nextKey);\r\n } else {\r\n yield [nextKey as any as K, v];\r\n }\r\n }\r\n }\r\n yield* impl(this._map, []);\r\n }\r\n\r\n private _size: number = 0;\r\n public get size(): number {\r\n return this._size;\r\n }\r\n\r\n public get [Symbol.toStringTag](): string {\r\n return this.constructor.name;\r\n }\r\n}\r\n"]}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
/** Options supplied to a [[YieldManager]].
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
2
7
|
export interface YieldManagerOptions {
|
|
8
|
+
/** The number of times [[YieldManager.allowYield]] must be called to trigger an actual yield.
|
|
9
|
+
* Default: 1000.
|
|
10
|
+
*/
|
|
3
11
|
iterationsBeforeYield?: number;
|
|
4
12
|
}
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
/** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.
|
|
14
|
+
* This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).
|
|
15
|
+
* It maintains a count of the number of iterations that have occurred since the last yield.
|
|
16
|
+
* The constructor specifies how many iterations of the loop are permitted before yielding.
|
|
17
|
+
* The loop should `await` [[allowYield]] on each iteration.
|
|
18
|
+
* [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.
|
|
19
|
+
* @public
|
|
11
20
|
*/
|
|
12
21
|
export declare class YieldManager {
|
|
13
|
-
|
|
22
|
+
/** Options controlling the yield behavior. */
|
|
23
|
+
readonly options: Readonly<Required<YieldManagerOptions>>;
|
|
14
24
|
private _counter;
|
|
25
|
+
/** Constructor.
|
|
26
|
+
* @param options Options customizing the yield behavior. Omitted properties are assigned their default values.
|
|
27
|
+
*/
|
|
15
28
|
constructor(options?: YieldManagerOptions);
|
|
29
|
+
/** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */
|
|
16
30
|
allowYield(): Promise<void>;
|
|
31
|
+
/** @internal */
|
|
17
32
|
protected actualYield(): Promise<void>;
|
|
18
33
|
}
|
|
19
34
|
//# sourceMappingURL=YieldManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YieldManager.d.ts","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"YieldManager.d.ts","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAMD;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB,8CAA8C;IAC9C,SAAgB,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,CAAK;IAErB;;OAEG;gBACgB,OAAO,GAAE,mBAAwB;IAIpD,oIAAoI;IACvH,UAAU;IAOvB,gBAAgB;cACA,WAAW;CAG5B"}
|
package/lib/esm/YieldManager.js
CHANGED
|
@@ -2,28 +2,36 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Utils
|
|
7
|
+
*/
|
|
6
8
|
const defaultYieldManagerOptions = {
|
|
7
9
|
iterationsBeforeYield: 1000,
|
|
8
10
|
};
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
/** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.
|
|
12
|
+
* This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).
|
|
13
|
+
* It maintains a count of the number of iterations that have occurred since the last yield.
|
|
14
|
+
* The constructor specifies how many iterations of the loop are permitted before yielding.
|
|
15
|
+
* The loop should `await` [[allowYield]] on each iteration.
|
|
16
|
+
* [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.
|
|
17
|
+
* @public
|
|
15
18
|
*/
|
|
16
19
|
export class YieldManager {
|
|
20
|
+
/** Constructor.
|
|
21
|
+
* @param options Options customizing the yield behavior. Omitted properties are assigned their default values.
|
|
22
|
+
*/
|
|
17
23
|
constructor(options = {}) {
|
|
18
24
|
this._counter = 0;
|
|
19
25
|
this.options = { ...defaultYieldManagerOptions, ...options };
|
|
20
26
|
}
|
|
27
|
+
/** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */
|
|
21
28
|
async allowYield() {
|
|
22
29
|
this._counter = (this._counter + 1) % this.options.iterationsBeforeYield;
|
|
23
30
|
if (this._counter === 0) {
|
|
24
31
|
await this.actualYield();
|
|
25
32
|
}
|
|
26
33
|
}
|
|
34
|
+
/** @internal */
|
|
27
35
|
async actualYield() {
|
|
28
36
|
await new Promise((r) => setTimeout(r, 0));
|
|
29
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YieldManager.js","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;
|
|
1
|
+
{"version":3,"file":"YieldManager.js","sourceRoot":"","sources":["../../src/YieldManager.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAYH,MAAM,0BAA0B,GAAkC;IAChE,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,YAAY;IAKvB;;OAEG;IACH,YAAmB,UAA+B,EAAE;QAL5C,aAAQ,GAAG,CAAC,CAAC;QAMnB,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,0BAA0B,EAAE,GAAG,OAAO,EAAE,CAAC;IAC/D,CAAC;IAED,oIAAoI;IAC7H,KAAK,CAAC,UAAU;QACrB,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC;QACzE,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC,EAAE;YACvB,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;SAC1B;IACH,CAAC;IAED,gBAAgB;IACN,KAAK,CAAC,WAAW;QACzB,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF","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 Utils\r\n */\r\n\r\n/** Options supplied to a [[YieldManager]].\r\n * @public\r\n */\r\nexport interface YieldManagerOptions {\r\n /** The number of times [[YieldManager.allowYield]] must be called to trigger an actual yield.\r\n * Default: 1000.\r\n */\r\n iterationsBeforeYield?: number;\r\n}\r\n\r\nconst defaultYieldManagerOptions: Required<YieldManagerOptions> = {\r\n iterationsBeforeYield: 1000,\r\n};\r\n\r\n/** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.\r\n * This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).\r\n * It maintains a count of the number of iterations that have occurred since the last yield.\r\n * The constructor specifies how many iterations of the loop are permitted before yielding.\r\n * The loop should `await` [[allowYield]] on each iteration.\r\n * [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.\r\n * @public\r\n */\r\nexport class YieldManager {\r\n /** Options controlling the yield behavior. */\r\n public readonly options: Readonly<Required<YieldManagerOptions>>;\r\n private _counter = 0;\r\n\r\n /** Constructor.\r\n * @param options Options customizing the yield behavior. Omitted properties are assigned their default values.\r\n */\r\n public constructor(options: YieldManagerOptions = {}) {\r\n this.options = { ...defaultYieldManagerOptions, ...options };\r\n }\r\n\r\n /** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */\r\n public async allowYield() {\r\n this._counter = (this._counter + 1) % this.options.iterationsBeforeYield;\r\n if (this._counter === 0) {\r\n await this.actualYield();\r\n }\r\n }\r\n\r\n /** @internal */\r\n protected async actualYield() {\r\n await new Promise((r) => setTimeout(r, 0));\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-bentley",
|
|
3
|
-
"version": "4.1.0-dev.
|
|
3
|
+
"version": "4.1.0-dev.70",
|
|
4
4
|
"description": "Bentley JavaScript core components",
|
|
5
5
|
"main": "lib/cjs/core-bentley.js",
|
|
6
6
|
"module": "lib/esm/core-bentley.js",
|
|
@@ -22,30 +22,24 @@
|
|
|
22
22
|
"url": "http://www.bentley.com"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@itwin/eslint-plugin": "
|
|
25
|
+
"@itwin/eslint-plugin": "4.0.0-dev.44",
|
|
26
26
|
"@opentelemetry/api": "1.0.4",
|
|
27
27
|
"@types/chai": "4.3.1",
|
|
28
28
|
"@types/chai-as-promised": "^7",
|
|
29
29
|
"@types/mocha": "^8.2.2",
|
|
30
|
-
"@types/node": "
|
|
30
|
+
"@types/node": "18.16.1",
|
|
31
31
|
"chai": "^4.1.2",
|
|
32
32
|
"chai-as-promised": "^7",
|
|
33
|
-
"eslint": "^8.
|
|
33
|
+
"eslint": "^8.44.0",
|
|
34
34
|
"mocha": "^10.0.0",
|
|
35
35
|
"nyc": "^15.1.0",
|
|
36
36
|
"rimraf": "^3.0.2",
|
|
37
37
|
"typescript": "~5.0.2",
|
|
38
|
-
"@itwin/build-tools": "4.1.0-dev.
|
|
38
|
+
"@itwin/build-tools": "4.1.0-dev.70"
|
|
39
39
|
},
|
|
40
40
|
"nyc": {
|
|
41
41
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|
|
42
42
|
},
|
|
43
|
-
"eslintConfig": {
|
|
44
|
-
"plugins": [
|
|
45
|
-
"@itwin"
|
|
46
|
-
],
|
|
47
|
-
"extends": "plugin:@itwin/itwinjs-recommended"
|
|
48
|
-
},
|
|
49
43
|
"scripts": {
|
|
50
44
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|
|
51
45
|
"build:cjs": "tsc 1>&2 --outDir lib/cjs",
|