@itwin/core-bentley 4.0.0-dev.7 → 4.0.0-dev.72
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 +50 -1
- package/lib/cjs/AccessToken.d.ts +10 -10
- package/lib/cjs/AccessToken.d.ts.map +1 -1
- package/lib/cjs/AccessToken.js +9 -9
- package/lib/cjs/Assert.d.ts +25 -25
- package/lib/cjs/Assert.js +45 -45
- package/lib/cjs/Assert.js.map +1 -1
- package/lib/cjs/BeEvent.d.ts +81 -81
- package/lib/cjs/BeEvent.d.ts.map +1 -1
- package/lib/cjs/BeEvent.js +156 -156
- package/lib/cjs/BeSQLite.d.ts +172 -170
- package/lib/cjs/BeSQLite.d.ts.map +1 -1
- package/lib/cjs/BeSQLite.js +185 -183
- package/lib/cjs/BeSQLite.js.map +1 -1
- package/lib/cjs/BentleyError.d.ts +378 -378
- package/lib/cjs/BentleyError.d.ts.map +1 -1
- package/lib/cjs/BentleyError.js +703 -702
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/BentleyLoggerCategory.d.ts +11 -11
- package/lib/cjs/BentleyLoggerCategory.js +19 -19
- package/lib/cjs/ByteStream.d.ts +110 -110
- package/lib/cjs/ByteStream.js +159 -159
- package/lib/cjs/ClassUtils.d.ts +14 -14
- package/lib/cjs/ClassUtils.js +27 -27
- package/lib/cjs/Compare.d.ts +47 -47
- package/lib/cjs/Compare.d.ts.map +1 -1
- package/lib/cjs/Compare.js +75 -75
- package/lib/cjs/CompressedId64Set.d.ts +134 -134
- package/lib/cjs/CompressedId64Set.d.ts.map +1 -1
- package/lib/cjs/CompressedId64Set.js +428 -428
- package/lib/cjs/CompressedId64Set.js.map +1 -1
- package/lib/cjs/Dictionary.d.ts +125 -125
- package/lib/cjs/Dictionary.js +203 -203
- package/lib/cjs/Disposable.d.ts +80 -80
- package/lib/cjs/Disposable.d.ts.map +1 -1
- package/lib/cjs/Disposable.js +120 -120
- package/lib/cjs/Id.d.ts +285 -285
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +643 -643
- package/lib/cjs/IndexMap.d.ts +65 -65
- package/lib/cjs/IndexMap.js +91 -91
- package/lib/cjs/JsonSchema.d.ts +77 -77
- package/lib/cjs/JsonSchema.d.ts.map +1 -1
- package/lib/cjs/JsonSchema.js +9 -9
- package/lib/cjs/JsonUtils.d.ts +78 -78
- package/lib/cjs/JsonUtils.js +151 -151
- package/lib/cjs/LRUMap.d.ts +129 -129
- package/lib/cjs/LRUMap.js +333 -333
- package/lib/cjs/LRUMap.js.map +1 -1
- package/lib/cjs/Logger.d.ts +143 -143
- package/lib/cjs/Logger.d.ts.map +1 -1
- package/lib/cjs/Logger.js +256 -258
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/ObservableSet.d.ts +23 -23
- package/lib/cjs/ObservableSet.js +51 -51
- package/lib/cjs/OneAtATimeAction.d.ts +31 -31
- package/lib/cjs/OneAtATimeAction.js +94 -94
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
- package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -1
- package/lib/cjs/OrderedId64Iterable.js +235 -235
- package/lib/cjs/OrderedSet.d.ts +40 -40
- package/lib/cjs/OrderedSet.js +64 -64
- package/lib/cjs/PriorityQueue.d.ts +70 -70
- package/lib/cjs/PriorityQueue.d.ts.map +1 -1
- package/lib/cjs/PriorityQueue.js +140 -140
- package/lib/cjs/ProcessDetector.d.ts +59 -59
- package/lib/cjs/ProcessDetector.js +71 -71
- package/lib/cjs/SortedArray.d.ts +236 -232
- package/lib/cjs/SortedArray.d.ts.map +1 -1
- package/lib/cjs/SortedArray.js +315 -303
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StatusCategory.d.ts +30 -30
- package/lib/cjs/StatusCategory.d.ts.map +1 -1
- package/lib/cjs/StatusCategory.js +460 -460
- package/lib/cjs/StatusCategory.js.map +1 -1
- package/lib/cjs/StringUtils.d.ts +22 -22
- package/lib/cjs/StringUtils.js +148 -148
- package/lib/cjs/Time.d.ts +122 -122
- package/lib/cjs/Time.js +152 -152
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.d.ts +43 -40
- package/lib/cjs/Tracing.d.ts.map +1 -1
- package/lib/cjs/Tracing.js +134 -130
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.d.ts +36 -36
- package/lib/cjs/TupleKeyedMap.js +102 -102
- package/lib/cjs/TypedArrayBuilder.d.ts +155 -155
- package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js +206 -208
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UnexpectedErrors.d.ts +43 -43
- package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
- package/lib/cjs/UnexpectedErrors.js +68 -68
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/UtilityTypes.d.ts +112 -96
- package/lib/cjs/UtilityTypes.d.ts.map +1 -1
- package/lib/cjs/UtilityTypes.js +40 -40
- package/lib/cjs/UtilityTypes.js.map +1 -1
- package/lib/cjs/YieldManager.d.ts +18 -18
- package/lib/cjs/YieldManager.js +34 -34
- package/lib/cjs/core-bentley.d.ts +74 -74
- package/lib/cjs/core-bentley.js +94 -90
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/cjs/partitionArray.d.ts +21 -21
- package/lib/cjs/partitionArray.js +43 -43
- package/lib/esm/AccessToken.d.ts +10 -10
- package/lib/esm/AccessToken.d.ts.map +1 -1
- package/lib/esm/AccessToken.js +8 -8
- package/lib/esm/Assert.d.ts +25 -25
- package/lib/esm/Assert.js +41 -41
- package/lib/esm/Assert.js.map +1 -1
- package/lib/esm/BeEvent.d.ts +81 -81
- package/lib/esm/BeEvent.d.ts.map +1 -1
- package/lib/esm/BeEvent.js +150 -150
- package/lib/esm/BeSQLite.d.ts +172 -170
- package/lib/esm/BeSQLite.d.ts.map +1 -1
- package/lib/esm/BeSQLite.js +182 -180
- package/lib/esm/BeSQLite.js.map +1 -1
- package/lib/esm/BentleyError.d.ts +378 -378
- package/lib/esm/BentleyError.d.ts.map +1 -1
- package/lib/esm/BentleyError.js +699 -698
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
- package/lib/esm/BentleyLoggerCategory.js +16 -16
- package/lib/esm/ByteStream.d.ts +110 -110
- package/lib/esm/ByteStream.js +155 -155
- package/lib/esm/ClassUtils.d.ts +14 -14
- package/lib/esm/ClassUtils.js +22 -22
- package/lib/esm/Compare.d.ts +47 -47
- package/lib/esm/Compare.d.ts.map +1 -1
- package/lib/esm/Compare.js +63 -63
- package/lib/esm/CompressedId64Set.d.ts +134 -134
- package/lib/esm/CompressedId64Set.d.ts.map +1 -1
- package/lib/esm/CompressedId64Set.js +423 -423
- package/lib/esm/CompressedId64Set.js.map +1 -1
- package/lib/esm/Dictionary.d.ts +125 -125
- package/lib/esm/Dictionary.js +199 -199
- package/lib/esm/Disposable.d.ts +80 -80
- package/lib/esm/Disposable.d.ts.map +1 -1
- package/lib/esm/Disposable.js +112 -112
- package/lib/esm/Id.d.ts +285 -285
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +639 -639
- package/lib/esm/IndexMap.d.ts +65 -65
- package/lib/esm/IndexMap.js +86 -86
- package/lib/esm/JsonSchema.d.ts +77 -77
- package/lib/esm/JsonSchema.d.ts.map +1 -1
- package/lib/esm/JsonSchema.js +8 -8
- package/lib/esm/JsonUtils.d.ts +78 -78
- package/lib/esm/JsonUtils.js +148 -148
- package/lib/esm/LRUMap.d.ts +129 -129
- package/lib/esm/LRUMap.js +326 -326
- package/lib/esm/LRUMap.js.map +1 -1
- package/lib/esm/Logger.d.ts +143 -143
- package/lib/esm/Logger.d.ts.map +1 -1
- package/lib/esm/Logger.js +253 -253
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/ObservableSet.d.ts +23 -23
- package/lib/esm/ObservableSet.js +47 -47
- package/lib/esm/OneAtATimeAction.d.ts +31 -31
- package/lib/esm/OneAtATimeAction.js +89 -89
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/OrderedId64Iterable.d.ts +74 -74
- package/lib/esm/OrderedId64Iterable.d.ts.map +1 -1
- package/lib/esm/OrderedId64Iterable.js +232 -232
- package/lib/esm/OrderedSet.d.ts +40 -40
- package/lib/esm/OrderedSet.js +59 -59
- package/lib/esm/PriorityQueue.d.ts +70 -70
- package/lib/esm/PriorityQueue.d.ts.map +1 -1
- package/lib/esm/PriorityQueue.js +136 -136
- package/lib/esm/ProcessDetector.d.ts +59 -59
- package/lib/esm/ProcessDetector.js +67 -67
- package/lib/esm/SortedArray.d.ts +236 -232
- package/lib/esm/SortedArray.d.ts.map +1 -1
- package/lib/esm/SortedArray.js +308 -296
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StatusCategory.d.ts +30 -30
- package/lib/esm/StatusCategory.d.ts.map +1 -1
- package/lib/esm/StatusCategory.js +455 -454
- package/lib/esm/StatusCategory.js.map +1 -1
- package/lib/esm/StringUtils.d.ts +22 -22
- package/lib/esm/StringUtils.js +142 -142
- package/lib/esm/Time.d.ts +122 -122
- package/lib/esm/Time.js +146 -146
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.d.ts +43 -40
- package/lib/esm/Tracing.d.ts.map +1 -1
- package/lib/esm/Tracing.js +130 -126
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.d.ts +36 -36
- package/lib/esm/TupleKeyedMap.js +98 -98
- package/lib/esm/TypedArrayBuilder.d.ts +155 -155
- package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/esm/TypedArrayBuilder.js +198 -200
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UnexpectedErrors.d.ts +43 -43
- package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
- package/lib/esm/UnexpectedErrors.js +65 -64
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/UtilityTypes.d.ts +112 -96
- package/lib/esm/UtilityTypes.d.ts.map +1 -1
- package/lib/esm/UtilityTypes.js +34 -34
- package/lib/esm/UtilityTypes.js.map +1 -1
- package/lib/esm/YieldManager.d.ts +18 -18
- package/lib/esm/YieldManager.js +30 -30
- package/lib/esm/core-bentley.d.ts +74 -74
- package/lib/esm/core-bentley.js +78 -78
- package/lib/esm/partitionArray.d.ts +21 -21
- package/lib/esm/partitionArray.js +39 -39
- package/package.json +9 -9
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,MAAM,OAAO,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,M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,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,UAAU,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9F,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,iBAAiB;IAChE,CAAC;IAEO,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","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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,eAAe,GAAG,CAAC,CAAC;YACzB,OAAO;SACR;QAED,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,UAAU,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9F,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,iBAAiB;IAChE,CAAC;IAEO,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 = 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,24 +1,24 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Collections
|
|
3
|
-
*/
|
|
4
|
-
import { BeEvent } from "./BeEvent";
|
|
5
|
-
/** A standard [Set<T>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) that emits events when its contents change.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export declare class ObservableSet<T> extends Set<T> {
|
|
9
|
-
/** Emitted after `item` is added to this set. */
|
|
10
|
-
readonly onAdded: BeEvent<(item: T) => void>;
|
|
11
|
-
/** Emitted after `item` is deleted from this set. */
|
|
12
|
-
readonly onDeleted: BeEvent<(item: T) => void>;
|
|
13
|
-
/** Emitted after this set's contents are cleared. */
|
|
14
|
-
readonly onCleared: BeEvent<() => void>;
|
|
15
|
-
/** Construct a new ObservableSet.
|
|
16
|
-
* @param elements Optional elements with which to populate the new set.
|
|
17
|
-
*/
|
|
18
|
-
constructor(elements?: Iterable<T> | undefined);
|
|
19
|
-
/** @internal */
|
|
20
|
-
delete(item: T): boolean;
|
|
21
|
-
/** @internal */
|
|
22
|
-
clear(): void;
|
|
23
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Collections
|
|
3
|
+
*/
|
|
4
|
+
import { BeEvent } from "./BeEvent";
|
|
5
|
+
/** A standard [Set<T>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) that emits events when its contents change.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class ObservableSet<T> extends Set<T> {
|
|
9
|
+
/** Emitted after `item` is added to this set. */
|
|
10
|
+
readonly onAdded: BeEvent<(item: T) => void>;
|
|
11
|
+
/** Emitted after `item` is deleted from this set. */
|
|
12
|
+
readonly onDeleted: BeEvent<(item: T) => void>;
|
|
13
|
+
/** Emitted after this set's contents are cleared. */
|
|
14
|
+
readonly onCleared: BeEvent<() => void>;
|
|
15
|
+
/** Construct a new ObservableSet.
|
|
16
|
+
* @param elements Optional elements with which to populate the new set.
|
|
17
|
+
*/
|
|
18
|
+
constructor(elements?: Iterable<T> | undefined);
|
|
19
|
+
/** @internal */
|
|
20
|
+
delete(item: T): boolean;
|
|
21
|
+
/** @internal */
|
|
22
|
+
clear(): void;
|
|
23
|
+
}
|
|
24
24
|
//# sourceMappingURL=ObservableSet.d.ts.map
|
package/lib/esm/ObservableSet.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Collections
|
|
7
|
-
*/
|
|
8
|
-
import { BeEvent } from "./BeEvent";
|
|
9
|
-
/** A standard [Set<T>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) that emits events when its contents change.
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export class ObservableSet extends Set {
|
|
13
|
-
/** Construct a new ObservableSet.
|
|
14
|
-
* @param elements Optional elements with which to populate the new set.
|
|
15
|
-
*/
|
|
16
|
-
constructor(elements) {
|
|
17
|
-
// NB: Set constructor will invoke add(). Do not override until initialized.
|
|
18
|
-
super(elements);
|
|
19
|
-
/** Emitted after `item` is added to this set. */
|
|
20
|
-
this.onAdded = new BeEvent();
|
|
21
|
-
/** Emitted after `item` is deleted from this set. */
|
|
22
|
-
this.onDeleted = new BeEvent();
|
|
23
|
-
/** Emitted after this set's contents are cleared. */
|
|
24
|
-
this.onCleared = new BeEvent();
|
|
25
|
-
this.add = (item) => {
|
|
26
|
-
const prevSize = this.size;
|
|
27
|
-
const ret = super.add(item);
|
|
28
|
-
if (this.size !== prevSize)
|
|
29
|
-
this.onAdded.raiseEvent(item);
|
|
30
|
-
return ret;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/** @internal */
|
|
34
|
-
delete(item) {
|
|
35
|
-
const ret = super.delete(item);
|
|
36
|
-
if (ret)
|
|
37
|
-
this.onDeleted.raiseEvent(item);
|
|
38
|
-
return ret;
|
|
39
|
-
}
|
|
40
|
-
/** @internal */
|
|
41
|
-
clear() {
|
|
42
|
-
if (0 !== this.size) {
|
|
43
|
-
super.clear();
|
|
44
|
-
this.onCleared.raiseEvent();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Collections
|
|
7
|
+
*/
|
|
8
|
+
import { BeEvent } from "./BeEvent";
|
|
9
|
+
/** A standard [Set<T>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) that emits events when its contents change.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export class ObservableSet extends Set {
|
|
13
|
+
/** Construct a new ObservableSet.
|
|
14
|
+
* @param elements Optional elements with which to populate the new set.
|
|
15
|
+
*/
|
|
16
|
+
constructor(elements) {
|
|
17
|
+
// NB: Set constructor will invoke add(). Do not override until initialized.
|
|
18
|
+
super(elements);
|
|
19
|
+
/** Emitted after `item` is added to this set. */
|
|
20
|
+
this.onAdded = new BeEvent();
|
|
21
|
+
/** Emitted after `item` is deleted from this set. */
|
|
22
|
+
this.onDeleted = new BeEvent();
|
|
23
|
+
/** Emitted after this set's contents are cleared. */
|
|
24
|
+
this.onCleared = new BeEvent();
|
|
25
|
+
this.add = (item) => {
|
|
26
|
+
const prevSize = this.size;
|
|
27
|
+
const ret = super.add(item);
|
|
28
|
+
if (this.size !== prevSize)
|
|
29
|
+
this.onAdded.raiseEvent(item);
|
|
30
|
+
return ret;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
delete(item) {
|
|
35
|
+
const ret = super.delete(item);
|
|
36
|
+
if (ret)
|
|
37
|
+
this.onDeleted.raiseEvent(item);
|
|
38
|
+
return ret;
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
clear() {
|
|
42
|
+
if (0 !== this.size) {
|
|
43
|
+
super.clear();
|
|
44
|
+
this.onCleared.raiseEvent();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
48
|
//# sourceMappingURL=ObservableSet.js.map
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Utils
|
|
3
|
-
*/
|
|
4
|
-
/** @beta */
|
|
5
|
-
export declare class AbandonedError extends Error {
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate
|
|
9
|
-
* the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP
|
|
10
|
-
* request queue to grow such that the delay to service new requests is unbounded.
|
|
11
|
-
*
|
|
12
|
-
* With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent
|
|
13
|
-
* requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.
|
|
14
|
-
* When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type
|
|
15
|
-
* of operation, but the first and last request will always eventually complete.
|
|
16
|
-
* @beta
|
|
17
|
-
*/
|
|
18
|
-
export declare class OneAtATimeAction<T> {
|
|
19
|
-
private _active?;
|
|
20
|
-
private _pending?;
|
|
21
|
-
private _run;
|
|
22
|
-
msg: string;
|
|
23
|
-
/** Ctor for OneAtATimePromise.
|
|
24
|
-
* @param run The method that performs an action that creates the Promise.
|
|
25
|
-
*/
|
|
26
|
-
constructor(run: (...args: any[]) => Promise<T>, msg?: string);
|
|
27
|
-
/** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.
|
|
28
|
-
* @note Callers of this method *must* handle AbandonedError rejections.
|
|
29
|
-
*/
|
|
30
|
-
request(...args: any[]): Promise<T>;
|
|
31
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
/** @beta */
|
|
5
|
+
export declare class AbandonedError extends Error {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate
|
|
9
|
+
* the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP
|
|
10
|
+
* request queue to grow such that the delay to service new requests is unbounded.
|
|
11
|
+
*
|
|
12
|
+
* With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent
|
|
13
|
+
* requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.
|
|
14
|
+
* When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type
|
|
15
|
+
* of operation, but the first and last request will always eventually complete.
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
export declare class OneAtATimeAction<T> {
|
|
19
|
+
private _active?;
|
|
20
|
+
private _pending?;
|
|
21
|
+
private _run;
|
|
22
|
+
msg: string;
|
|
23
|
+
/** Ctor for OneAtATimePromise.
|
|
24
|
+
* @param run The method that performs an action that creates the Promise.
|
|
25
|
+
*/
|
|
26
|
+
constructor(run: (...args: any[]) => Promise<T>, msg?: string);
|
|
27
|
+
/** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.
|
|
28
|
+
* @note Callers of this method *must* handle AbandonedError rejections.
|
|
29
|
+
*/
|
|
30
|
+
request(...args: any[]): Promise<T>;
|
|
31
|
+
}
|
|
32
32
|
//# sourceMappingURL=OneAtATimeAction.d.ts.map
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Utils
|
|
7
|
-
*/
|
|
8
|
-
import { BentleyError } from "./BentleyError";
|
|
9
|
-
/** @beta */
|
|
10
|
-
export class AbandonedError extends Error {
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* An object that returns a Promise when you call [[init]], but supplies a way to abandon the promise if it is no longer relevant.
|
|
14
|
-
* When you call abandon, the promise will be rejected. You must supply a [[run]] method to the constructor that
|
|
15
|
-
* creates the real Promise for the underlying action. Notice that to use this class there are really two
|
|
16
|
-
* Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.
|
|
17
|
-
*/
|
|
18
|
-
class PromiseWithAbandon {
|
|
19
|
-
/** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.
|
|
20
|
-
* @param _run The method that creates the underlying Promise.
|
|
21
|
-
* @param _args An array of args to be passed to run when [[start]] is called.
|
|
22
|
-
*/
|
|
23
|
-
constructor(_run, _args) {
|
|
24
|
-
this._run = _run;
|
|
25
|
-
this._args = _args;
|
|
26
|
-
}
|
|
27
|
-
/** Create a Promise that is chained to the underlying Promise, but is connected to the abandon method. */
|
|
28
|
-
async init(msg) {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
this.abandon = (message) => reject(new AbandonedError(message
|
|
31
|
-
this._resolve = resolve;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/** Call the [[run]] method supplied to the ctor to start the underlying Promise. */
|
|
35
|
-
async start() {
|
|
36
|
-
try {
|
|
37
|
-
this._resolve(await this._run(...this._args));
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
this.abandon(BentleyError.getErrorMessage(err)); // turn all errors from execution into abandoned errors, but keep the message
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate
|
|
46
|
-
* the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP
|
|
47
|
-
* request queue to grow such that the delay to service new requests is unbounded.
|
|
48
|
-
*
|
|
49
|
-
* With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent
|
|
50
|
-
* requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.
|
|
51
|
-
* When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type
|
|
52
|
-
* of operation, but the first and last request will always eventually complete.
|
|
53
|
-
* @beta
|
|
54
|
-
*/
|
|
55
|
-
export class OneAtATimeAction {
|
|
56
|
-
/** Ctor for OneAtATimePromise.
|
|
57
|
-
* @param run The method that performs an action that creates the Promise.
|
|
58
|
-
*/
|
|
59
|
-
constructor(run, msg = "abandoned") {
|
|
60
|
-
this._run = run;
|
|
61
|
-
this.msg = msg;
|
|
62
|
-
}
|
|
63
|
-
/** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.
|
|
64
|
-
* @note Callers of this method *must* handle AbandonedError rejections.
|
|
65
|
-
*/
|
|
66
|
-
async request(...args) {
|
|
67
|
-
const entry = new PromiseWithAbandon(this._run, args); // create an "abandon-able promise" object
|
|
68
|
-
const promise = entry.init(this.msg); // create the Promise from PromiseWithAbandon. Note: this must be called before we call start.
|
|
69
|
-
if (this._active !== undefined) { // is there an active request?
|
|
70
|
-
if (this._pending) // yes. If there is also a pending request, this one replaces it and previous one is abandoned
|
|
71
|
-
this._pending.abandon(); // rejects previous call to this method, throwing AbandonedError.
|
|
72
|
-
this._pending = entry;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this._active = entry; // this is the first request, start it.
|
|
76
|
-
entry.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
return await promise;
|
|
80
|
-
}
|
|
81
|
-
finally {
|
|
82
|
-
// do all of this whether promise was fulfilled or rejected
|
|
83
|
-
this._active = this._pending; // see if there's a pending request waiting
|
|
84
|
-
this._pending = undefined; // clear pending
|
|
85
|
-
if (this._active)
|
|
86
|
-
this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Utils
|
|
7
|
+
*/
|
|
8
|
+
import { BentleyError } from "./BentleyError";
|
|
9
|
+
/** @beta */
|
|
10
|
+
export class AbandonedError extends Error {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An object that returns a Promise when you call [[init]], but supplies a way to abandon the promise if it is no longer relevant.
|
|
14
|
+
* When you call abandon, the promise will be rejected. You must supply a [[run]] method to the constructor that
|
|
15
|
+
* creates the real Promise for the underlying action. Notice that to use this class there are really two
|
|
16
|
+
* Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.
|
|
17
|
+
*/
|
|
18
|
+
class PromiseWithAbandon {
|
|
19
|
+
/** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.
|
|
20
|
+
* @param _run The method that creates the underlying Promise.
|
|
21
|
+
* @param _args An array of args to be passed to run when [[start]] is called.
|
|
22
|
+
*/
|
|
23
|
+
constructor(_run, _args) {
|
|
24
|
+
this._run = _run;
|
|
25
|
+
this._args = _args;
|
|
26
|
+
}
|
|
27
|
+
/** Create a Promise that is chained to the underlying Promise, but is connected to the abandon method. */
|
|
28
|
+
async init(msg) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
this.abandon = (message) => reject(new AbandonedError(message ?? msg));
|
|
31
|
+
this._resolve = resolve;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Call the [[run]] method supplied to the ctor to start the underlying Promise. */
|
|
35
|
+
async start() {
|
|
36
|
+
try {
|
|
37
|
+
this._resolve(await this._run(...this._args));
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
this.abandon(BentleyError.getErrorMessage(err)); // turn all errors from execution into abandoned errors, but keep the message
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate
|
|
46
|
+
* the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP
|
|
47
|
+
* request queue to grow such that the delay to service new requests is unbounded.
|
|
48
|
+
*
|
|
49
|
+
* With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent
|
|
50
|
+
* requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.
|
|
51
|
+
* When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type
|
|
52
|
+
* of operation, but the first and last request will always eventually complete.
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
export class OneAtATimeAction {
|
|
56
|
+
/** Ctor for OneAtATimePromise.
|
|
57
|
+
* @param run The method that performs an action that creates the Promise.
|
|
58
|
+
*/
|
|
59
|
+
constructor(run, msg = "abandoned") {
|
|
60
|
+
this._run = run;
|
|
61
|
+
this.msg = msg;
|
|
62
|
+
}
|
|
63
|
+
/** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.
|
|
64
|
+
* @note Callers of this method *must* handle AbandonedError rejections.
|
|
65
|
+
*/
|
|
66
|
+
async request(...args) {
|
|
67
|
+
const entry = new PromiseWithAbandon(this._run, args); // create an "abandon-able promise" object
|
|
68
|
+
const promise = entry.init(this.msg); // create the Promise from PromiseWithAbandon. Note: this must be called before we call start.
|
|
69
|
+
if (this._active !== undefined) { // is there an active request?
|
|
70
|
+
if (this._pending) // yes. If there is also a pending request, this one replaces it and previous one is abandoned
|
|
71
|
+
this._pending.abandon(); // rejects previous call to this method, throwing AbandonedError.
|
|
72
|
+
this._pending = entry;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this._active = entry; // this is the first request, start it.
|
|
76
|
+
entry.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return await promise;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
// do all of this whether promise was fulfilled or rejected
|
|
83
|
+
this._active = this._pending; // see if there's a pending request waiting
|
|
84
|
+
this._pending = undefined; // clear pending
|
|
85
|
+
if (this._active)
|
|
86
|
+
this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
90
|
//# sourceMappingURL=OneAtATimeAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneAtATimeAction.js","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,YAAY;AACZ,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAI;AAE7C;;;;;GAKG;AACH,MAAM,kBAAkB;IAKtB;;;OAGG;IACH,YAAoB,IAAoC,EAAU,KAAY;QAA1D,SAAI,GAAJ,IAAI,CAAgC;QAAU,UAAK,GAAL,KAAK,CAAO;IAAI,CAAC;IAEnF,0GAA0G;IACnG,KAAK,CAAC,IAAI,CAAC,GAAW;QAC3B,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,IAAI,CAAC,OAAO,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"OneAtATimeAction.js","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,YAAY;AACZ,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAI;AAE7C;;;;;GAKG;AACH,MAAM,kBAAkB;IAKtB;;;OAGG;IACH,YAAoB,IAAoC,EAAU,KAAY;QAA1D,SAAI,GAAJ,IAAI,CAAg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/G,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,iEAAiE;YAC5F,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACvB;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,uCAAuC;YAC7D,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,8DAA8D;SAC9E;QAED,IAAI;YACF,OAAO,MAAM,OAAO,CAAC;SACtB;gBAAS;YACR,2DAA2D;YAC3D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,2CAA2C;YACzE,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,gBAAgB;YAC3C,IAAI,IAAI,CAAC,OAAO;gBACd,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,8DAA8D;SACvF;IACH,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\nimport { BentleyError } from \"./BentleyError\";\r\n\r\n/** @beta */\r\nexport class AbandonedError extends Error { }\r\n\r\n/**\r\n * An object that returns a Promise when you call [[init]], but supplies a way to abandon the promise if it is no longer relevant.\r\n * When you call abandon, the promise will be rejected. You must supply a [[run]] method to the constructor that\r\n * creates the real Promise for the underlying action. Notice that to use this class there are really two\r\n * Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.\r\n */\r\nclass PromiseWithAbandon<T> {\r\n /** Method to abandon the Promise created by [[init]] while it is outstanding. The promise will be rejected. */\r\n public abandon!: (msg?: string) => void;\r\n private _resolve!: (val: any) => void;\r\n\r\n /** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.\r\n * @param _run The method that creates the underlying Promise.\r\n * @param _args An array of args to be passed to run when [[start]] is called.\r\n */\r\n constructor(private _run: (...args: any[]) => Promise<T>, private _args: any[]) { }\r\n\r\n /** Create a Promise that is chained to the underlying Promise, but is connected to the abandon method. */\r\n public async init(msg: string): Promise<T> {\r\n return new Promise<T>((resolve, reject) => {\r\n this.abandon = (message?: string) => reject(new AbandonedError(message ?? msg));\r\n this._resolve = resolve;\r\n });\r\n }\r\n\r\n /** Call the [[run]] method supplied to the ctor to start the underlying Promise. */\r\n public async start() {\r\n try {\r\n this._resolve(await this._run(...this._args));\r\n } catch (err) {\r\n this.abandon(BentleyError.getErrorMessage(err)); // turn all errors from execution into abandoned errors, but keep the message\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate\r\n * the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP\r\n * request queue to grow such that the delay to service new requests is unbounded.\r\n *\r\n * With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent\r\n * requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.\r\n * When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type\r\n * of operation, but the first and last request will always eventually complete.\r\n * @beta\r\n */\r\nexport class OneAtATimeAction<T> {\r\n private _active?: PromiseWithAbandon<T>;\r\n private _pending?: PromiseWithAbandon<T>;\r\n private _run: (...args: any[]) => Promise<T>;\r\n public msg: string;\r\n\r\n /** Ctor for OneAtATimePromise.\r\n * @param run The method that performs an action that creates the Promise.\r\n */\r\n constructor(run: (...args: any[]) => Promise<T>, msg = \"abandoned\") {\r\n this._run = run;\r\n this.msg = msg;\r\n }\r\n\r\n /** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.\r\n * @note Callers of this method *must* handle AbandonedError rejections.\r\n */\r\n public async request(...args: any[]): Promise<T> {\r\n const entry = new PromiseWithAbandon<T>(this._run, args); // create an \"abandon-able promise\" object\r\n const promise = entry.init(this.msg); // create the Promise from PromiseWithAbandon. Note: this must be called before we call start.\r\n\r\n if (this._active !== undefined) { // is there an active request?\r\n if (this._pending) // yes. If there is also a pending request, this one replaces it and previous one is abandoned\r\n this._pending.abandon(); // rejects previous call to this method, throwing AbandonedError.\r\n this._pending = entry;\r\n } else {\r\n this._active = entry; // this is the first request, start it.\r\n entry.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n try {\r\n return await promise;\r\n } finally {\r\n // do all of this whether promise was fulfilled or rejected\r\n this._active = this._pending; // see if there's a pending request waiting\r\n this._pending = undefined; // clear pending\r\n if (this._active)\r\n this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n}\r\n"]}
|