@itwin/core-bentley 5.0.0-dev.1 → 5.0.0-dev.100
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 +74 -1
- package/lib/cjs/BeEvent.js +3 -7
- package/lib/cjs/BeEvent.js.map +1 -1
- package/lib/cjs/BentleyError.d.ts +84 -1
- package/lib/cjs/BentleyError.d.ts.map +1 -1
- package/lib/cjs/BentleyError.js +72 -11
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/ByteStream.d.ts +3 -22
- package/lib/cjs/ByteStream.d.ts.map +1 -1
- package/lib/cjs/ByteStream.js +7 -21
- package/lib/cjs/ByteStream.js.map +1 -1
- package/lib/cjs/Compare.d.ts +15 -0
- package/lib/cjs/Compare.d.ts.map +1 -1
- package/lib/cjs/Compare.js +48 -0
- package/lib/cjs/Compare.js.map +1 -1
- package/lib/cjs/CompressedId64Set.js +6 -3
- package/lib/cjs/CompressedId64Set.js.map +1 -1
- package/lib/cjs/Dictionary.js +8 -3
- package/lib/cjs/Dictionary.js.map +1 -1
- package/lib/cjs/Disposable.d.ts +18 -0
- package/lib/cjs/Disposable.d.ts.map +1 -1
- package/lib/cjs/Disposable.js +25 -25
- package/lib/cjs/Disposable.js.map +1 -1
- package/lib/cjs/Id.d.ts +0 -4
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +9 -11
- package/lib/cjs/Id.js.map +1 -1
- package/lib/cjs/IndexMap.js +6 -1
- package/lib/cjs/IndexMap.js.map +1 -1
- package/lib/cjs/JsonUtils.d.ts +4 -0
- package/lib/cjs/JsonUtils.d.ts.map +1 -1
- package/lib/cjs/JsonUtils.js +6 -1
- package/lib/cjs/JsonUtils.js.map +1 -1
- package/lib/cjs/LRUMap.js +16 -0
- package/lib/cjs/LRUMap.js.map +1 -1
- package/lib/cjs/Logger.d.ts +26 -3
- package/lib/cjs/Logger.d.ts.map +1 -1
- package/lib/cjs/Logger.js +33 -9
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/ObservableSet.js +6 -6
- package/lib/cjs/ObservableSet.js.map +1 -1
- package/lib/cjs/OneAtATimeAction.js +9 -0
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/OrderedSet.js +1 -0
- package/lib/cjs/OrderedSet.js.map +1 -1
- package/lib/cjs/PriorityQueue.js +3 -1
- package/lib/cjs/PriorityQueue.js.map +1 -1
- package/lib/cjs/SortedArray.js +4 -1
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StatusCategory.js +42 -105
- package/lib/cjs/StatusCategory.js.map +1 -1
- package/lib/cjs/Time.js +5 -0
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.js +2 -0
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.js +2 -2
- package/lib/cjs/TupleKeyedMap.js.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js +8 -0
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UnexpectedErrors.js +10 -12
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/YieldManager.js +3 -1
- package/lib/cjs/YieldManager.js.map +1 -1
- package/lib/cjs/internal/cross-package.d.ts +0 -1
- package/lib/cjs/internal/cross-package.d.ts.map +1 -1
- package/lib/cjs/internal/cross-package.js +1 -3
- package/lib/cjs/internal/cross-package.js.map +1 -1
- package/lib/esm/BeEvent.js +3 -7
- package/lib/esm/BeEvent.js.map +1 -1
- package/lib/esm/BentleyError.d.ts +84 -1
- package/lib/esm/BentleyError.d.ts.map +1 -1
- package/lib/esm/BentleyError.js +71 -10
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/ByteStream.d.ts +3 -22
- package/lib/esm/ByteStream.d.ts.map +1 -1
- package/lib/esm/ByteStream.js +7 -21
- package/lib/esm/ByteStream.js.map +1 -1
- package/lib/esm/Compare.d.ts +15 -0
- package/lib/esm/Compare.d.ts.map +1 -1
- package/lib/esm/Compare.js +46 -0
- package/lib/esm/Compare.js.map +1 -1
- package/lib/esm/CompressedId64Set.js +6 -3
- package/lib/esm/CompressedId64Set.js.map +1 -1
- package/lib/esm/Dictionary.js +8 -3
- package/lib/esm/Dictionary.js.map +1 -1
- package/lib/esm/Disposable.d.ts +18 -0
- package/lib/esm/Disposable.d.ts.map +1 -1
- package/lib/esm/Disposable.js +24 -25
- package/lib/esm/Disposable.js.map +1 -1
- package/lib/esm/Id.d.ts +0 -4
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +9 -11
- package/lib/esm/Id.js.map +1 -1
- package/lib/esm/IndexMap.js +6 -1
- package/lib/esm/IndexMap.js.map +1 -1
- package/lib/esm/JsonUtils.d.ts +4 -0
- package/lib/esm/JsonUtils.d.ts.map +1 -1
- package/lib/esm/JsonUtils.js +6 -1
- package/lib/esm/JsonUtils.js.map +1 -1
- package/lib/esm/LRUMap.js +16 -0
- package/lib/esm/LRUMap.js.map +1 -1
- package/lib/esm/Logger.d.ts +26 -3
- package/lib/esm/Logger.d.ts.map +1 -1
- package/lib/esm/Logger.js +33 -9
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/ObservableSet.js +6 -6
- package/lib/esm/ObservableSet.js.map +1 -1
- package/lib/esm/OneAtATimeAction.js +9 -0
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/OrderedSet.js +1 -0
- package/lib/esm/OrderedSet.js.map +1 -1
- package/lib/esm/PriorityQueue.js +3 -1
- package/lib/esm/PriorityQueue.js.map +1 -1
- package/lib/esm/SortedArray.js +4 -1
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StatusCategory.js +42 -105
- package/lib/esm/StatusCategory.js.map +1 -1
- package/lib/esm/Time.js +5 -0
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.js +2 -0
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.js +2 -2
- package/lib/esm/TupleKeyedMap.js.map +1 -1
- package/lib/esm/TypedArrayBuilder.js +8 -0
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UnexpectedErrors.js +10 -12
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/YieldManager.js +3 -1
- package/lib/esm/YieldManager.js.map +1 -1
- package/lib/esm/internal/cross-package.d.ts +0 -1
- package/lib/esm/internal/cross-package.d.ts.map +1 -1
- package/lib/esm/internal/cross-package.js +0 -1
- package/lib/esm/internal/cross-package.js.map +1 -1
- package/package.json +8 -8
- package/lib/cjs/internal/staticLoggerMetadata.d.ts +0 -11
- package/lib/cjs/internal/staticLoggerMetadata.d.ts.map +0 -1
- package/lib/cjs/internal/staticLoggerMetadata.js +0 -17
- package/lib/cjs/internal/staticLoggerMetadata.js.map +0 -1
- package/lib/esm/internal/staticLoggerMetadata.d.ts +0 -11
- package/lib/esm/internal/staticLoggerMetadata.d.ts.map +0 -1
- package/lib/esm/internal/staticLoggerMetadata.js +0 -14
- package/lib/esm/internal/staticLoggerMetadata.js.map +0 -1
package/lib/cjs/Logger.d.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BeEvent } from "./BeEvent";
|
|
5
5
|
import { LoggingMetaData } from "./BentleyError";
|
|
6
|
-
import { IDisposable } from "./Disposable";
|
|
7
6
|
/** Defines the *signature* for a log function.
|
|
8
7
|
* @public
|
|
9
8
|
*/
|
|
@@ -37,6 +36,22 @@ export interface LoggerLevelsConfig {
|
|
|
37
36
|
defaultLevel?: string;
|
|
38
37
|
categoryLevels?: LoggerCategoryAndLevel[];
|
|
39
38
|
}
|
|
39
|
+
/** A global set of metadata that should be included with every log message.
|
|
40
|
+
* You can provide an object representing the metadata, or a function to be invoked to obtain the metadata object each
|
|
41
|
+
* time a message is logged.
|
|
42
|
+
* Each key-value pair of the object will be stringified and combined with the log message's per-call metadata.
|
|
43
|
+
* The keys you provide to each method is used solely to identify your entries so that you can later update or delete them - these keys
|
|
44
|
+
* are **not** included in log messages. Don't modify or remove metadata associated with keys that belong to someone else.
|
|
45
|
+
* @note Each extra bit of metadata adds cost and overhead to the logging system. Avoid adding unnecessary or unnecessarily verbose metadata.
|
|
46
|
+
* @see [[Logger.staticMetaData]] to access the global metadata.
|
|
47
|
+
* @beta
|
|
48
|
+
*/
|
|
49
|
+
export interface StaticLoggerMetaData {
|
|
50
|
+
/** Add or update some metadata to be included with every logged message. */
|
|
51
|
+
set(key: string, metadata: LoggingMetaData): void;
|
|
52
|
+
/** Remove metadata previously [[set]] using the specified `key`, so it will no longer be included with every logged message. */
|
|
53
|
+
delete(key: string): void;
|
|
54
|
+
}
|
|
40
55
|
/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control
|
|
41
56
|
* how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).
|
|
42
57
|
* @public
|
|
@@ -47,6 +62,7 @@ export declare class Logger {
|
|
|
47
62
|
protected static _logInfo: LogFunction | undefined;
|
|
48
63
|
protected static _logTrace: LogFunction | undefined;
|
|
49
64
|
private static _onLogLevelChanged;
|
|
65
|
+
private static _staticMetaData;
|
|
50
66
|
/** An event raised whenever [[setLevel]] or [[setLevelDefault]] is called. */
|
|
51
67
|
static get onLogLevelChanged(): BeEvent<() => void>;
|
|
52
68
|
private static _categoryFilter;
|
|
@@ -65,6 +81,10 @@ export declare class Logger {
|
|
|
65
81
|
static get minLevel(): LogLevel | undefined;
|
|
66
82
|
/** Should the call stack be included when an exception is logged? */
|
|
67
83
|
static logExceptionCallstacks: boolean;
|
|
84
|
+
/** Contains metadata that should be included with every logged message.
|
|
85
|
+
* @beta
|
|
86
|
+
*/
|
|
87
|
+
static get staticMetaData(): StaticLoggerMetaData;
|
|
68
88
|
/** Initialize the logger streams. Should be called at application initialization time. */
|
|
69
89
|
static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void;
|
|
70
90
|
/** Initialize the logger to output to the console. */
|
|
@@ -104,7 +124,8 @@ export declare class Logger {
|
|
|
104
124
|
*/
|
|
105
125
|
static logError(category: string, message: string, metaData?: LoggingMetaData): void;
|
|
106
126
|
private static getExceptionMessage;
|
|
107
|
-
/** Log the specified exception.
|
|
127
|
+
/** Log the specified exception.
|
|
128
|
+
* For legacy [[BentleyError]] exceptions, the special "exceptionType" property will be added as metadata. Otherwise, all enumerable members of the exception are logged as metadata.
|
|
108
129
|
* @param category The category of the message.
|
|
109
130
|
* @param err The exception object.
|
|
110
131
|
* @param log The logger output function to use - defaults to Logger.logError
|
|
@@ -138,13 +159,15 @@ export declare class Logger {
|
|
|
138
159
|
* Enable those, if you want to capture timings.
|
|
139
160
|
* @public
|
|
140
161
|
*/
|
|
141
|
-
export declare class PerfLogger implements
|
|
162
|
+
export declare class PerfLogger implements Disposable {
|
|
142
163
|
private static _severity;
|
|
143
164
|
private _operation;
|
|
144
165
|
private _metaData?;
|
|
145
166
|
private _startTimeStamp;
|
|
146
167
|
constructor(operation: string, metaData?: LoggingMetaData);
|
|
147
168
|
private logMessage;
|
|
169
|
+
[Symbol.dispose](): void;
|
|
170
|
+
/** @deprecated in 5.0 Use [Symbol.dispose] instead. */
|
|
148
171
|
dispose(): void;
|
|
149
172
|
}
|
|
150
173
|
//# sourceMappingURL=Logger.d.ts.map
|
package/lib/cjs/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,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAA8B,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC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@ exports.PerfLogger = exports.Logger = exports.LogLevel = void 0;
|
|
|
11
11
|
const BeEvent_1 = require("./BeEvent");
|
|
12
12
|
const BentleyError_1 = require("./BentleyError");
|
|
13
13
|
const BentleyLoggerCategory_1 = require("./BentleyLoggerCategory");
|
|
14
|
-
const staticLoggerMetadata_1 = require("./internal/staticLoggerMetadata");
|
|
15
14
|
/** Use to categorize logging messages by severity.
|
|
16
15
|
* @public
|
|
17
16
|
*/
|
|
@@ -33,6 +32,12 @@ var LogLevel;
|
|
|
33
32
|
* @public
|
|
34
33
|
*/
|
|
35
34
|
class Logger {
|
|
35
|
+
static _logError;
|
|
36
|
+
static _logWarning;
|
|
37
|
+
static _logInfo;
|
|
38
|
+
static _logTrace;
|
|
39
|
+
static _onLogLevelChanged;
|
|
40
|
+
static _staticMetaData = new Map();
|
|
36
41
|
/** An event raised whenever [[setLevel]] or [[setLevelDefault]] is called. */
|
|
37
42
|
static get onLogLevelChanged() {
|
|
38
43
|
// We have to lazily initialize because it's static and BeEvent imports UnexpectedErrors which imports Logger which wants to instantiate BeEvent.
|
|
@@ -41,6 +46,7 @@ class Logger {
|
|
|
41
46
|
}
|
|
42
47
|
return Logger._onLogLevelChanged;
|
|
43
48
|
}
|
|
49
|
+
static _categoryFilter = {};
|
|
44
50
|
/** Maps category names to the least severe level at which messages in that category should be displayed,
|
|
45
51
|
* or `undefined` if a minimum has not been defined.
|
|
46
52
|
* @see [[setLevel]] to change the minimum logging level for a category.
|
|
@@ -49,6 +55,7 @@ class Logger {
|
|
|
49
55
|
// NOTE: this property is accessed by native code.
|
|
50
56
|
return this._categoryFilter;
|
|
51
57
|
}
|
|
58
|
+
static _minLevel;
|
|
52
59
|
/** The least severe level at which messages should be displayed by default.
|
|
53
60
|
* @see [[setLevelDefault]] to change this default.
|
|
54
61
|
* @see [[setLevel]] to override this default for specific categories.
|
|
@@ -57,6 +64,14 @@ class Logger {
|
|
|
57
64
|
// NOTE: this property is accessed by native code. */
|
|
58
65
|
return this._minLevel;
|
|
59
66
|
}
|
|
67
|
+
/** Should the call stack be included when an exception is logged? */
|
|
68
|
+
static logExceptionCallstacks = false;
|
|
69
|
+
/** Contains metadata that should be included with every logged message.
|
|
70
|
+
* @beta
|
|
71
|
+
*/
|
|
72
|
+
static get staticMetaData() {
|
|
73
|
+
return this._staticMetaData;
|
|
74
|
+
}
|
|
60
75
|
/** Initialize the logger streams. Should be called at application initialization time. */
|
|
61
76
|
static initialize(logError, logWarning, logInfo, logTrace) {
|
|
62
77
|
Logger._logError = logError;
|
|
@@ -74,7 +89,7 @@ class Logger {
|
|
|
74
89
|
/** merge the supplied metadata with all static metadata into one object */
|
|
75
90
|
static getMetaData(metaData) {
|
|
76
91
|
const metaObj = {};
|
|
77
|
-
for (const meta of
|
|
92
|
+
for (const meta of this._staticMetaData) {
|
|
78
93
|
const val = BentleyError_1.BentleyError.getMetaData(meta[1]);
|
|
79
94
|
if (val)
|
|
80
95
|
Object.assign(metaObj, val);
|
|
@@ -198,14 +213,19 @@ class Logger {
|
|
|
198
213
|
const stack = Logger.logExceptionCallstacks ? `\n${BentleyError_1.BentleyError.getErrorStack(err)}` : "";
|
|
199
214
|
return BentleyError_1.BentleyError.getErrorMessage(err) + stack;
|
|
200
215
|
}
|
|
201
|
-
/** Log the specified exception.
|
|
216
|
+
/** Log the specified exception.
|
|
217
|
+
* For legacy [[BentleyError]] exceptions, the special "exceptionType" property will be added as metadata. Otherwise, all enumerable members of the exception are logged as metadata.
|
|
202
218
|
* @param category The category of the message.
|
|
203
219
|
* @param err The exception object.
|
|
204
220
|
* @param log The logger output function to use - defaults to Logger.logError
|
|
205
221
|
*/
|
|
206
222
|
static logException(category, err, log = (_category, message, metaData) => Logger.logError(_category, message, metaData)) {
|
|
207
223
|
log(category, Logger.getExceptionMessage(err), () => {
|
|
208
|
-
|
|
224
|
+
// For backwards compatibility, log BentleyError old way
|
|
225
|
+
if (BentleyError_1.BentleyError.isError(err))
|
|
226
|
+
return { ...BentleyError_1.BentleyError.getErrorMetadata(err), exceptionType: err?.constructor?.name ?? "<Unknown>" };
|
|
227
|
+
// return a copy of the error, with non-enumerable members `message` and `stack` removed, as "metadata" for log.
|
|
228
|
+
return { ...err };
|
|
209
229
|
});
|
|
210
230
|
}
|
|
211
231
|
/** Log the specified message to the **warning** stream.
|
|
@@ -237,9 +257,6 @@ class Logger {
|
|
|
237
257
|
}
|
|
238
258
|
}
|
|
239
259
|
exports.Logger = Logger;
|
|
240
|
-
Logger._categoryFilter = {};
|
|
241
|
-
/** Should the call stack be included when an exception is logged? */
|
|
242
|
-
Logger.logExceptionCallstacks = false;
|
|
243
260
|
/** Simple performance diagnostics utility.
|
|
244
261
|
* It measures the time from construction to disposal. On disposal it logs the routine name along with
|
|
245
262
|
* the duration in milliseconds.
|
|
@@ -250,6 +267,10 @@ Logger.logExceptionCallstacks = false;
|
|
|
250
267
|
* @public
|
|
251
268
|
*/
|
|
252
269
|
class PerfLogger {
|
|
270
|
+
static _severity = LogLevel.Info;
|
|
271
|
+
_operation;
|
|
272
|
+
_metaData;
|
|
273
|
+
_startTimeStamp;
|
|
253
274
|
constructor(operation, metaData) {
|
|
254
275
|
this._operation = operation;
|
|
255
276
|
this._metaData = metaData;
|
|
@@ -271,10 +292,13 @@ class PerfLogger {
|
|
|
271
292
|
};
|
|
272
293
|
});
|
|
273
294
|
}
|
|
274
|
-
dispose() {
|
|
295
|
+
[Symbol.dispose]() {
|
|
275
296
|
this.logMessage();
|
|
276
297
|
}
|
|
298
|
+
/** @deprecated in 5.0 Use [Symbol.dispose] instead. */
|
|
299
|
+
dispose() {
|
|
300
|
+
this[Symbol.dispose]();
|
|
301
|
+
}
|
|
277
302
|
}
|
|
278
303
|
exports.PerfLogger = PerfLogger;
|
|
279
|
-
PerfLogger._severity = LogLevel.Info;
|
|
280
304
|
//# sourceMappingURL=Logger.js.map
|
package/lib/cjs/Logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"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AAe,GAAG,CAAC,CAAC;YACzB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,6CAAqB,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,6CAAqB,CAAC,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC;YAC5E,OAAO;QAET,MAAM,CAAC,OAAO,CAAC,6CAAqB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,UAAU,MAAM,EAAE,GAAG,EAAE;YAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,2BAAY,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;;AAnCH,gCAoCC;AAnCgB,oBAAS,GAAa,QAAQ,CAAC,IAAI,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Logging\n */\n\nimport { BeEvent } from \"./BeEvent\";\nimport { BentleyError, IModelStatus, LoggingMetaData } from \"./BentleyError\";\nimport { BentleyLoggerCategory } from \"./BentleyLoggerCategory\";\nimport { IDisposable } from \"./Disposable\";\nimport { staticLoggerMetadata } from \"./internal/staticLoggerMetadata\";\n\n/** Defines the *signature* for a log function.\n * @public\n */\nexport type LogFunction = (category: string, message: string, metaData: LoggingMetaData) => void;\n\n/** Use to categorize logging messages by severity.\n * @public\n */\nexport enum LogLevel {\n /** Tracing and debugging - low level */\n Trace,\n /** Information - mid level */\n Info,\n /** Warnings - high level */\n Warning,\n /** Errors - highest level */\n Error,\n /** Higher than any real logging level. This is used to turn a category off. */\n None,\n}\n\n/** Identifies a logging category and the LogLevel that should be used for it. The LogLevel is specified by its string name.\n * @public\n */\nexport interface LoggerCategoryAndLevel {\n category: string;\n logLevel: string;\n}\n\n/** Specifies logging levels, including the default logging level and a set of categories and levels for them.\n * @public\n */\nexport interface LoggerLevelsConfig {\n defaultLevel?: string;\n categoryLevels?: LoggerCategoryAndLevel[];\n}\n\n/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control\n * how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).\n * @public\n */\nexport class Logger {\n protected static _logError: LogFunction | undefined;\n protected static _logWarning: LogFunction | undefined;\n protected static _logInfo: LogFunction | undefined;\n protected static _logTrace: LogFunction | undefined;\n\n private static _onLogLevelChanged: BeEvent<() => void> | undefined;\n\n /** An event raised whenever [[setLevel]] or [[setLevelDefault]] is called. */\n public static get onLogLevelChanged(): BeEvent<() => void> {\n // We have to lazily initialize because it's static and BeEvent imports UnexpectedErrors which imports Logger which wants to instantiate BeEvent.\n if (undefined === Logger._onLogLevelChanged) {\n Logger._onLogLevelChanged = new BeEvent<() => void>();\n }\n\n return Logger._onLogLevelChanged;\n }\n\n private static _categoryFilter: {[categoryName: string]: LogLevel | undefined} = {};\n\n /** Maps category names to the least severe level at which messages in that category should be displayed,\n * or `undefined` if a minimum has not been defined.\n * @see [[setLevel]] to change the minimum logging level for a category.\n */\n public static get categoryFilter(): Readonly<{[categoryName: string]: LogLevel | undefined}> {\n // NOTE: this property is accessed by native code.\n return this._categoryFilter;\n }\n\n private static _minLevel: LogLevel | undefined;\n\n /** The least severe level at which messages should be displayed by default.\n * @see [[setLevelDefault]] to change this default.\n * @see [[setLevel]] to override this default for specific categories.\n */\n public static get minLevel(): LogLevel | undefined {\n // NOTE: this property is accessed by native code. */\n return this._minLevel;\n }\n\n /** Should the call stack be included when an exception is logged? */\n public static logExceptionCallstacks = false;\n\n /** Initialize the logger streams. Should be called at application initialization time. */\n public static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void {\n Logger._logError = logError;\n Logger._logWarning = logWarning;\n Logger._logInfo = logInfo;\n Logger._logTrace = logTrace;\n Logger.turnOffLevelDefault();\n Logger.turnOffCategories();\n }\n\n /** Initialize the logger to output to the console. */\n public static initializeToConsole(): void {\n const logConsole = (level: string) => (category: string, message: string, metaData: LoggingMetaData) =>\n console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console\n\n Logger.initialize(logConsole(\"Error\"), logConsole(\"Warning\"), logConsole(\"Info\"), logConsole(\"Trace\"));\n }\n\n /** merge the supplied metadata with all static metadata into one object */\n public static getMetaData(metaData?: LoggingMetaData): object {\n const metaObj = {};\n for (const meta of staticLoggerMetadata) {\n const val = BentleyError.getMetaData(meta[1]);\n if (val)\n Object.assign(metaObj, val);\n }\n Object.assign(metaObj, BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence\n return metaObj;\n }\n\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. */\n public static stringifyMetaData(metaData?: LoggingMetaData): string {\n const metaObj = this.getMetaData(metaData);\n return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : \"\";\n }\n\n /** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */\n public static setLevelDefault(minLevel: LogLevel): void {\n this._minLevel = minLevel;\n this.onLogLevelChanged.raiseEvent();\n }\n\n /** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the\n * specified category should be displayed.\n */\n public static setLevel(category: string, minLevel: LogLevel) {\n Logger._categoryFilter[category] = minLevel;\n this.onLogLevelChanged.raiseEvent();\n }\n\n /** Interpret a string as the name of a LogLevel */\n public static parseLogLevel(str: string): LogLevel {\n switch (str.toUpperCase()) {\n case \"EXCEPTION\": return LogLevel.Error;\n case \"FATAL\": return LogLevel.Error;\n case \"ERROR\": return LogLevel.Error;\n case \"WARNING\": return LogLevel.Warning;\n case \"INFO\": return LogLevel.Info;\n case \"TRACE\": return LogLevel.Trace;\n case \"DEBUG\": return LogLevel.Trace;\n }\n return LogLevel.None;\n }\n\n /** Set the log level for multiple categories at once. Also see [[validateProps]] */\n public static configureLevels(cfg: LoggerLevelsConfig) {\n Logger.validateProps(cfg);\n if (cfg.defaultLevel !== undefined) {\n this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));\n }\n if (cfg.categoryLevels !== undefined) {\n for (const cl of cfg.categoryLevels) {\n this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));\n }\n }\n }\n\n private static isLogLevel(v: string) {\n return LogLevel.hasOwnProperty(v);\n }\n\n /** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */\n public static validateProps(config: any) {\n const validProps = [\"defaultLevel\", \"categoryLevels\"];\n for (const prop of Object.keys(config)) {\n if (!validProps.includes(prop))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);\n if (prop === \"defaultLevel\") {\n if (!Logger.isLogLevel(config.defaultLevel))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);\n } else if (prop === \"categoryLevels\") {\n const value = config[prop];\n if (!Array.isArray(value))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);\n for (const item of config[prop]) {\n if (!item.hasOwnProperty(\"category\") || !item.hasOwnProperty(\"logLevel\"))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);\n if (!Logger.isLogLevel(item.logLevel))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);\n }\n }\n }\n }\n\n /** Get the minimum logging level for the specified category. */\n public static getLevel(category: string): LogLevel | undefined {\n // Prefer the level set for this category specifically\n const minLevelForThisCategory = Logger.categoryFilter[category];\n if (minLevelForThisCategory !== undefined)\n return minLevelForThisCategory;\n\n // Fall back on the level set for the parent of this category.\n const parent = category.lastIndexOf(\".\");\n if (parent !== -1)\n return Logger.getLevel(category.slice(0, parent));\n\n // Fall back on the default level.\n return Logger.minLevel;\n }\n\n /** Turns off the least severe level at which messages should be displayed by default.\n * This turns off logging for all messages for which no category minimum level is defined.\n */\n public static turnOffLevelDefault(): void {\n Logger._minLevel = undefined;\n }\n\n /** Turns off all category level filters previously defined with [[Logger.setLevel]].\n */\n public static turnOffCategories(): void {\n Logger._categoryFilter = {};\n }\n\n /** Check if messages in the specified category should be displayed at this level of severity. */\n public static isEnabled(category: string, level: LogLevel): boolean {\n const minLevel = Logger.getLevel(category);\n return (minLevel !== undefined) && (level >= minLevel);\n }\n\n /** Log the specified message to the **error** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logError(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))\n Logger._logError(category, message, metaData);\n }\n\n private static getExceptionMessage(err: unknown): string {\n if (err === undefined) {\n return \"Error: err is undefined.\";\n }\n if (err === null) {\n return \"Error: err is null.\";\n }\n const stack = Logger.logExceptionCallstacks ? `\\n${BentleyError.getErrorStack(err)}` : \"\";\n return BentleyError.getErrorMessage(err) + stack;\n }\n\n /** Log the specified exception. The special \"ExceptionType\" property will be added as metadata.\n * @param category The category of the message.\n * @param err The exception object.\n * @param log The logger output function to use - defaults to Logger.logError\n */\n public static logException(category: string, err: any, log: LogFunction = (_category, message, metaData) => Logger.logError(_category, message, metaData)): void {\n log(category, Logger.getExceptionMessage(err), () => {\n return { ...BentleyError.getErrorMetadata(err), exceptionType: err?.constructor?.name ?? \"<Unknown>\"};\n });\n }\n\n /** Log the specified message to the **warning** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logWarning(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))\n Logger._logWarning(category, message, metaData);\n }\n\n /** Log the specified message to the **info** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logInfo(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))\n Logger._logInfo(category, message, metaData);\n }\n\n /** Log the specified message to the **trace** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logTrace(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))\n Logger._logTrace(category, message, metaData);\n }\n}\n\n/** Simple performance diagnostics utility.\n * It measures the time from construction to disposal. On disposal it logs the routine name along with\n * the duration in milliseconds.\n * It also logs the routine name at construction time so that nested calls can be disambiguated.\n *\n * The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].\n * Enable those, if you want to capture timings.\n * @public\n */\nexport class PerfLogger implements IDisposable {\n private static _severity: LogLevel = LogLevel.Info;\n\n private _operation: string;\n private _metaData?: LoggingMetaData;\n private _startTimeStamp: number;\n\n public constructor(operation: string, metaData?: LoggingMetaData) {\n this._operation = operation;\n this._metaData = metaData;\n\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity)) {\n this._startTimeStamp = 0;\n return;\n }\n\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);\n this._startTimeStamp = new Date().getTime(); // take timestamp\n }\n\n private logMessage(): void {\n const endTimeStamp: number = new Date().getTime();\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity))\n return;\n\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},END`, () => {\n const mdata = this._metaData ? BentleyError.getMetaData(this._metaData) : {};\n return {\n ...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention\n };\n });\n }\n\n public dispose(): void {\n this.logMessage();\n }\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,uCAAoC;AACpC,iDAA6E;AAC7E,mEAAgE;AAOhE;;GAEG;AACH,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,wBAAR,QAAQ,QAWnB;AAmCD;;;GAGG;AACH,MAAa,MAAM;IACP,MAAM,CAAC,SAAS,CAA0B;IAC1C,MAAM,CAAC,WAAW,CAA0B;IAC5C,MAAM,CAAC,QAAQ,CAA0B;IACzC,MAAM,CAAC,SAAS,CAA0B;IAE5C,MAAM,CAAC,kBAAkB,CAAkC;IAC3D,MAAM,CAAC,eAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEpE,8EAA8E;IACvE,MAAM,KAAK,iBAAiB;QACjC,iJAAiJ;QACjJ,IAAI,SAAS,KAAK,MAAM,CAAC,kBAAkB,EAAE,CAAC;YAC5C,MAAM,CAAC,kBAAkB,GAAG,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e,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,6CAAqB,CAAC,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC;YAC5E,OAAO;QAET,MAAM,CAAC,OAAO,CAAC,6CAAqB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,UAAU,MAAM,EAAE,GAAG,EAAE;YAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,2BAAY,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,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,uDAAuD;IAChD,OAAO;QACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;;AAxCH,gCAyCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Logging\n */\n\nimport { BeEvent } from \"./BeEvent\";\nimport { BentleyError, IModelStatus, LoggingMetaData } from \"./BentleyError\";\nimport { BentleyLoggerCategory } from \"./BentleyLoggerCategory\";\n\n/** Defines the *signature* for a log function.\n * @public\n */\nexport type LogFunction = (category: string, message: string, metaData: LoggingMetaData) => void;\n\n/** Use to categorize logging messages by severity.\n * @public\n */\nexport enum LogLevel {\n /** Tracing and debugging - low level */\n Trace,\n /** Information - mid level */\n Info,\n /** Warnings - high level */\n Warning,\n /** Errors - highest level */\n Error,\n /** Higher than any real logging level. This is used to turn a category off. */\n None,\n}\n\n/** Identifies a logging category and the LogLevel that should be used for it. The LogLevel is specified by its string name.\n * @public\n */\nexport interface LoggerCategoryAndLevel {\n category: string;\n logLevel: string;\n}\n\n/** Specifies logging levels, including the default logging level and a set of categories and levels for them.\n * @public\n */\nexport interface LoggerLevelsConfig {\n defaultLevel?: string;\n categoryLevels?: LoggerCategoryAndLevel[];\n}\n\n/** A global set of metadata that should be included with every log message.\n * You can provide an object representing the metadata, or a function to be invoked to obtain the metadata object each\n * time a message is logged.\n * Each key-value pair of the object will be stringified and combined with the log message's per-call metadata.\n * The keys you provide to each method is used solely to identify your entries so that you can later update or delete them - these keys\n * are **not** included in log messages. Don't modify or remove metadata associated with keys that belong to someone else.\n * @note Each extra bit of metadata adds cost and overhead to the logging system. Avoid adding unnecessary or unnecessarily verbose metadata.\n * @see [[Logger.staticMetaData]] to access the global metadata.\n * @beta\n */\nexport interface StaticLoggerMetaData {\n /** Add or update some metadata to be included with every logged message. */\n set(key: string, metadata: LoggingMetaData): void;\n /** Remove metadata previously [[set]] using the specified `key`, so it will no longer be included with every logged message. */\n delete(key: string): void;\n}\n\n/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control\n * how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).\n * @public\n */\nexport class Logger {\n protected static _logError: LogFunction | undefined;\n protected static _logWarning: LogFunction | undefined;\n protected static _logInfo: LogFunction | undefined;\n protected static _logTrace: LogFunction | undefined;\n\n private static _onLogLevelChanged: BeEvent<() => void> | undefined;\n private static _staticMetaData = new Map<string, LoggingMetaData>();\n\n /** An event raised whenever [[setLevel]] or [[setLevelDefault]] is called. */\n public static get onLogLevelChanged(): BeEvent<() => void> {\n // We have to lazily initialize because it's static and BeEvent imports UnexpectedErrors which imports Logger which wants to instantiate BeEvent.\n if (undefined === Logger._onLogLevelChanged) {\n Logger._onLogLevelChanged = new BeEvent<() => void>();\n }\n\n return Logger._onLogLevelChanged;\n }\n\n private static _categoryFilter: { [categoryName: string]: LogLevel | undefined } = {};\n\n /** Maps category names to the least severe level at which messages in that category should be displayed,\n * or `undefined` if a minimum has not been defined.\n * @see [[setLevel]] to change the minimum logging level for a category.\n */\n public static get categoryFilter(): Readonly<{ [categoryName: string]: LogLevel | undefined }> {\n // NOTE: this property is accessed by native code.\n return this._categoryFilter;\n }\n\n private static _minLevel: LogLevel | undefined;\n\n /** The least severe level at which messages should be displayed by default.\n * @see [[setLevelDefault]] to change this default.\n * @see [[setLevel]] to override this default for specific categories.\n */\n public static get minLevel(): LogLevel | undefined {\n // NOTE: this property is accessed by native code. */\n return this._minLevel;\n }\n\n /** Should the call stack be included when an exception is logged? */\n public static logExceptionCallstacks = false;\n\n /** Contains metadata that should be included with every logged message.\n * @beta\n */\n public static get staticMetaData(): StaticLoggerMetaData {\n return this._staticMetaData;\n }\n\n /** Initialize the logger streams. Should be called at application initialization time. */\n public static initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void {\n Logger._logError = logError;\n Logger._logWarning = logWarning;\n Logger._logInfo = logInfo;\n Logger._logTrace = logTrace;\n Logger.turnOffLevelDefault();\n Logger.turnOffCategories();\n }\n\n /** Initialize the logger to output to the console. */\n public static initializeToConsole(): void {\n const logConsole = (level: string) => (category: string, message: string, metaData: LoggingMetaData) =>\n console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console\n\n Logger.initialize(logConsole(\"Error\"), logConsole(\"Warning\"), logConsole(\"Info\"), logConsole(\"Trace\"));\n }\n\n /** merge the supplied metadata with all static metadata into one object */\n public static getMetaData(metaData?: LoggingMetaData): object {\n const metaObj = {};\n for (const meta of this._staticMetaData) {\n const val = BentleyError.getMetaData(meta[1]);\n if (val)\n Object.assign(metaObj, val);\n }\n Object.assign(metaObj, BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence\n return metaObj;\n }\n\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. */\n public static stringifyMetaData(metaData?: LoggingMetaData): string {\n const metaObj = this.getMetaData(metaData);\n return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : \"\";\n }\n\n /** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */\n public static setLevelDefault(minLevel: LogLevel): void {\n this._minLevel = minLevel;\n this.onLogLevelChanged.raiseEvent();\n }\n\n /** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the\n * specified category should be displayed.\n */\n public static setLevel(category: string, minLevel: LogLevel) {\n Logger._categoryFilter[category] = minLevel;\n this.onLogLevelChanged.raiseEvent();\n }\n\n /** Interpret a string as the name of a LogLevel */\n public static parseLogLevel(str: string): LogLevel {\n switch (str.toUpperCase()) {\n case \"EXCEPTION\": return LogLevel.Error;\n case \"FATAL\": return LogLevel.Error;\n case \"ERROR\": return LogLevel.Error;\n case \"WARNING\": return LogLevel.Warning;\n case \"INFO\": return LogLevel.Info;\n case \"TRACE\": return LogLevel.Trace;\n case \"DEBUG\": return LogLevel.Trace;\n }\n return LogLevel.None;\n }\n\n /** Set the log level for multiple categories at once. Also see [[validateProps]] */\n public static configureLevels(cfg: LoggerLevelsConfig) {\n Logger.validateProps(cfg);\n if (cfg.defaultLevel !== undefined) {\n this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));\n }\n if (cfg.categoryLevels !== undefined) {\n for (const cl of cfg.categoryLevels) {\n this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));\n }\n }\n }\n\n private static isLogLevel(v: string) {\n return LogLevel.hasOwnProperty(v);\n }\n\n /** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */\n public static validateProps(config: any) {\n const validProps = [\"defaultLevel\", \"categoryLevels\"];\n for (const prop of Object.keys(config)) {\n if (!validProps.includes(prop))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);\n if (prop === \"defaultLevel\") {\n if (!Logger.isLogLevel(config.defaultLevel))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);\n } else if (prop === \"categoryLevels\") {\n const value = config[prop];\n if (!Array.isArray(value))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);\n for (const item of config[prop]) {\n if (!item.hasOwnProperty(\"category\") || !item.hasOwnProperty(\"logLevel\"))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);\n if (!Logger.isLogLevel(item.logLevel))\n throw new BentleyError(IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);\n }\n }\n }\n }\n\n /** Get the minimum logging level for the specified category. */\n public static getLevel(category: string): LogLevel | undefined {\n // Prefer the level set for this category specifically\n const minLevelForThisCategory = Logger.categoryFilter[category];\n if (minLevelForThisCategory !== undefined)\n return minLevelForThisCategory;\n\n // Fall back on the level set for the parent of this category.\n const parent = category.lastIndexOf(\".\");\n if (parent !== -1)\n return Logger.getLevel(category.slice(0, parent));\n\n // Fall back on the default level.\n return Logger.minLevel;\n }\n\n /** Turns off the least severe level at which messages should be displayed by default.\n * This turns off logging for all messages for which no category minimum level is defined.\n */\n public static turnOffLevelDefault(): void {\n Logger._minLevel = undefined;\n }\n\n /** Turns off all category level filters previously defined with [[Logger.setLevel]].\n */\n public static turnOffCategories(): void {\n Logger._categoryFilter = {};\n }\n\n /** Check if messages in the specified category should be displayed at this level of severity. */\n public static isEnabled(category: string, level: LogLevel): boolean {\n const minLevel = Logger.getLevel(category);\n return (minLevel !== undefined) && (level >= minLevel);\n }\n\n /** Log the specified message to the **error** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logError(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))\n Logger._logError(category, message, metaData);\n }\n\n private static getExceptionMessage(err: unknown): string {\n if (err === undefined) {\n return \"Error: err is undefined.\";\n }\n if (err === null) {\n return \"Error: err is null.\";\n }\n const stack = Logger.logExceptionCallstacks ? `\\n${BentleyError.getErrorStack(err)}` : \"\";\n return BentleyError.getErrorMessage(err) + stack;\n }\n\n /** Log the specified exception.\n * For legacy [[BentleyError]] exceptions, the special \"exceptionType\" property will be added as metadata. Otherwise, all enumerable members of the exception are logged as metadata.\n * @param category The category of the message.\n * @param err The exception object.\n * @param log The logger output function to use - defaults to Logger.logError\n */\n public static logException(category: string, err: any, log: LogFunction = (_category, message, metaData) => Logger.logError(_category, message, metaData)): void {\n log(category, Logger.getExceptionMessage(err), () => {\n // For backwards compatibility, log BentleyError old way\n if (BentleyError.isError(err))\n return { ...BentleyError.getErrorMetadata(err), exceptionType: err?.constructor?.name ?? \"<Unknown>\" };\n\n // return a copy of the error, with non-enumerable members `message` and `stack` removed, as \"metadata\" for log.\n return { ...err };\n });\n }\n\n /** Log the specified message to the **warning** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logWarning(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))\n Logger._logWarning(category, message, metaData);\n }\n\n /** Log the specified message to the **info** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logInfo(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))\n Logger._logInfo(category, message, metaData);\n }\n\n /** Log the specified message to the **trace** stream.\n * @param category The category of the message.\n * @param message The message.\n * @param metaData Optional data for the message\n */\n public static logTrace(category: string, message: string, metaData?: LoggingMetaData): void {\n if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))\n Logger._logTrace(category, message, metaData);\n }\n}\n\n/** Simple performance diagnostics utility.\n * It measures the time from construction to disposal. On disposal it logs the routine name along with\n * the duration in milliseconds.\n * It also logs the routine name at construction time so that nested calls can be disambiguated.\n *\n * The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].\n * Enable those, if you want to capture timings.\n * @public\n */\nexport class PerfLogger implements Disposable {\n private static _severity: LogLevel = LogLevel.Info;\n\n private _operation: string;\n private _metaData?: LoggingMetaData;\n private _startTimeStamp: number;\n\n public constructor(operation: string, metaData?: LoggingMetaData) {\n this._operation = operation;\n this._metaData = metaData;\n\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity)) {\n this._startTimeStamp = 0;\n return;\n }\n\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);\n this._startTimeStamp = new Date().getTime(); // take timestamp\n }\n\n private logMessage(): void {\n const endTimeStamp: number = new Date().getTime();\n if (!Logger.isEnabled(BentleyLoggerCategory.Performance, PerfLogger._severity))\n return;\n\n Logger.logInfo(BentleyLoggerCategory.Performance, `${this._operation},END`, () => {\n const mdata = this._metaData ? BentleyError.getMetaData(this._metaData) : {};\n return {\n ...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention\n };\n });\n }\n\n public [Symbol.dispose](): void {\n this.logMessage();\n }\n\n /** @deprecated in 5.0 Use [Symbol.dispose] instead. */\n public dispose(): void {\n this[Symbol.dispose]();\n }\n}\n\n"]}
|
package/lib/cjs/ObservableSet.js
CHANGED
|
@@ -13,18 +13,18 @@ const BeEvent_1 = require("./BeEvent");
|
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
15
|
class ObservableSet extends Set {
|
|
16
|
+
/** Emitted after `item` is added to this set. */
|
|
17
|
+
onAdded = new BeEvent_1.BeEvent();
|
|
18
|
+
/** Emitted after `item` is deleted from this set. */
|
|
19
|
+
onDeleted = new BeEvent_1.BeEvent();
|
|
20
|
+
/** Emitted after this set's contents are cleared. */
|
|
21
|
+
onCleared = new BeEvent_1.BeEvent();
|
|
16
22
|
/** Construct a new ObservableSet.
|
|
17
23
|
* @param elements Optional elements with which to populate the new set.
|
|
18
24
|
*/
|
|
19
25
|
constructor(elements) {
|
|
20
26
|
// NB: Set constructor will invoke add(). Do not override until initialized.
|
|
21
27
|
super(elements);
|
|
22
|
-
/** Emitted after `item` is added to this set. */
|
|
23
|
-
this.onAdded = new BeEvent_1.BeEvent();
|
|
24
|
-
/** Emitted after `item` is deleted from this set. */
|
|
25
|
-
this.onDeleted = new BeEvent_1.BeEvent();
|
|
26
|
-
/** Emitted after this set's contents are cleared. */
|
|
27
|
-
this.onCleared = new BeEvent_1.BeEvent();
|
|
28
28
|
this.add = (item) => {
|
|
29
29
|
const prevSize = this.size;
|
|
30
30
|
const ret = super.add(item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableSet.js","sourceRoot":"","sources":["../../src/ObservableSet.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,uCAAoC;AAEpC;;GAEG;AACH,MAAa,aAAiB,SAAQ,GAAM;
|
|
1
|
+
{"version":3,"file":"ObservableSet.js","sourceRoot":"","sources":["../../src/ObservableSet.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,uCAAoC;AAEpC;;GAEG;AACH,MAAa,aAAiB,SAAQ,GAAM;IAC1C,iDAAiD;IACjC,OAAO,GAAG,IAAI,iBAAO,EAAqB,CAAC;IAC3D,qDAAqD;IACrC,SAAS,GAAG,IAAI,iBAAO,EAAqB,CAAC;IAC7D,qDAAqD;IACrC,SAAS,GAAG,IAAI,iBAAO,EAAc,CAAC;IAEtD;;OAEG;IACH,YAAmB,QAAkC;QACnD,4EAA4E;QAC5E,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,IAAI,CAAC,GAAG,GAAG,CAAC,IAAO,EAAE,EAAE;YACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;YAC3B,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;gBACxB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAEhC,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACa,MAAM,CAAC,IAAO;QAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,GAAG;YACL,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAElC,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;OAEG;IACa,KAAK;QACnB,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;CACF;AA7CD,sCA6CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Collections\n */\n\nimport { BeEvent } from \"./BeEvent\";\n\n/** A standard [Set<T>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) that emits events when its contents change.\n * @public\n */\nexport class ObservableSet<T> extends Set<T> {\n /** Emitted after `item` is added to this set. */\n public readonly onAdded = new BeEvent<(item: T) => void>();\n /** Emitted after `item` is deleted from this set. */\n public readonly onDeleted = new BeEvent<(item: T) => void>();\n /** Emitted after this set's contents are cleared. */\n public readonly onCleared = new BeEvent<() => void>();\n\n /** Construct a new ObservableSet.\n * @param elements Optional elements with which to populate the new set.\n */\n public constructor(elements?: Iterable<T> | undefined) {\n // NB: Set constructor will invoke add(). Do not override until initialized.\n super(elements);\n\n this.add = (item: T) => {\n const prevSize = this.size;\n const ret = super.add(item);\n if (this.size !== prevSize)\n this.onAdded.raiseEvent(item);\n\n return ret;\n };\n }\n\n /** Invokes [Set.delete](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete), raising\n * the [[onDeleted]] event if the item was removed from the set.\n */\n public override delete(item: T): boolean {\n const ret = super.delete(item);\n if (ret)\n this.onDeleted.raiseEvent(item);\n\n return ret;\n }\n\n /** If this set is not already empty, invokes [Set.clear](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)\n * and raises the [[onCleared]] event.\n */\n public override clear(): void {\n if (0 !== this.size) {\n super.clear();\n this.onCleared.raiseEvent();\n }\n }\n}\n"]}
|
|
@@ -20,6 +20,11 @@ exports.AbandonedError = AbandonedError;
|
|
|
20
20
|
* Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.
|
|
21
21
|
*/
|
|
22
22
|
class PromiseWithAbandon {
|
|
23
|
+
_run;
|
|
24
|
+
_args;
|
|
25
|
+
/** Method to abandon the Promise created by [[init]] while it is outstanding. The promise will be rejected. */
|
|
26
|
+
abandon;
|
|
27
|
+
_resolve;
|
|
23
28
|
/** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.
|
|
24
29
|
* @param _run The method that creates the underlying Promise.
|
|
25
30
|
* @param _args An array of args to be passed to run when [[start]] is called.
|
|
@@ -57,6 +62,10 @@ class PromiseWithAbandon {
|
|
|
57
62
|
* @beta
|
|
58
63
|
*/
|
|
59
64
|
class OneAtATimeAction {
|
|
65
|
+
_active;
|
|
66
|
+
_pending;
|
|
67
|
+
_run;
|
|
68
|
+
msg;
|
|
60
69
|
/** Ctor for OneAtATimePromise.
|
|
61
70
|
* @param run The method that performs an action that creates the Promise.
|
|
62
71
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneAtATimeAction.js","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,iDAA8C;AAE9C,YAAY;AACZ,MAAa,cAAe,SAAQ,KAAK;CAAI;AAA7C,wCAA6C;AAE7C;;;;;GAKG;AACH,MAAM,kBAAkB;
|
|
1
|
+
{"version":3,"file":"OneAtATimeAction.js","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,iDAA8C;AAE9C,YAAY;AACZ,MAAa,cAAe,SAAQ,KAAK;CAAI;AAA7C,wCAA6C;AAE7C;;;;;GAKG;AACH,MAAM,kBAAkB;IASF;IAA8C;IARlE,+GAA+G;IACxG,OAAO,CAA0B;IAChC,QAAQ,CAAsB;IAEtC;;;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,IAAI,GAAG,CAAC,CAAC,CAAC;YAChF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,oFAAoF;IAC7E,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAChD,CAAC;QA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AC,CAAC,gBAAgB;YAC3C,IAAI,IAAI,CAAC,OAAO;gBACd,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,8DAA8D;QACxF,CAAC;IACH,CAAC;CACF;AAxCD,4CAwCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\nimport { BentleyError } from \"./BentleyError\";\n\n/** @beta */\nexport class AbandonedError extends Error { }\n\n/**\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.\n * When you call abandon, the promise will be rejected. You must supply a [[run]] method to the constructor that\n * creates the real Promise for the underlying action. Notice that to use this class there are really two\n * Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.\n */\nclass PromiseWithAbandon<T> {\n /** Method to abandon the Promise created by [[init]] while it is outstanding. The promise will be rejected. */\n public abandon!: (msg?: string) => void;\n private _resolve!: (val: any) => void;\n\n /** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.\n * @param _run The method that creates the underlying Promise.\n * @param _args An array of args to be passed to run when [[start]] is called.\n */\n constructor(private _run: (...args: any[]) => Promise<T>, private _args: any[]) { }\n\n /** Create a Promise that is chained to the underlying Promise, but is connected to the abandon method. */\n public async init(msg: string): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.abandon = (message?: string) => reject(new AbandonedError(message ?? msg));\n this._resolve = resolve;\n });\n }\n\n /** Call the [[run]] method supplied to the ctor to start the underlying Promise. */\n public async start() {\n try {\n this._resolve(await this._run(...this._args));\n } catch (err) {\n this.abandon(BentleyError.getErrorMessage(err)); // turn all errors from execution into abandoned errors, but keep the message\n }\n }\n}\n\n/**\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\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\n * request queue to grow such that the delay to service new requests is unbounded.\n *\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\n * requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.\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\n * of operation, but the first and last request will always eventually complete.\n * @beta\n */\nexport class OneAtATimeAction<T> {\n private _active?: PromiseWithAbandon<T>;\n private _pending?: PromiseWithAbandon<T>;\n private _run: (...args: any[]) => Promise<T>;\n public msg: string;\n\n /** Ctor for OneAtATimePromise.\n * @param run The method that performs an action that creates the Promise.\n */\n constructor(run: (...args: any[]) => Promise<T>, msg = \"abandoned\") {\n this._run = run;\n this.msg = msg;\n }\n\n /** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.\n * @note Callers of this method *must* handle AbandonedError rejections.\n */\n public async request(...args: any[]): Promise<T> {\n const entry = new PromiseWithAbandon<T>(this._run, args); // create an \"abandon-able promise\" object\n const promise = entry.init(this.msg); // create the Promise from PromiseWithAbandon. Note: this must be called before we call start.\n\n if (this._active !== undefined) { // is there an active request?\n if (this._pending) // yes. If there is also a pending request, this one replaces it and previous one is abandoned\n this._pending.abandon(); // rejects previous call to this method, throwing AbandonedError.\n this._pending = entry;\n } else {\n this._active = entry; // this is the first request, start it.\n entry.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n\n try {\n return await promise;\n } finally {\n // do all of this whether promise was fulfilled or rejected\n this._active = this._pending; // see if there's a pending request waiting\n this._pending = undefined; // clear pending\n if (this._active)\n this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n}\n"]}
|
package/lib/cjs/OrderedSet.js
CHANGED
|
@@ -15,6 +15,7 @@ const SortedArray_1 = require("./SortedArray");
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
class ReadonlyOrderedSet {
|
|
18
|
+
_array;
|
|
18
19
|
/** Construct a new ReadonlyOrderedSet<T>.
|
|
19
20
|
* @param compare The function used to compare elements within the set, determining their ordering.
|
|
20
21
|
* @param clone The function invoked to clone a new element for insertion into the set. The default implementation simply returns its input.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrderedSet.js","sourceRoot":"","sources":["../../src/OrderedSet.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,+CAAyE;AAEzE;;;;GAIG;AACH,MAAa,kBAAkB;
|
|
1
|
+
{"version":3,"file":"OrderedSet.js","sourceRoot":"","sources":["../../src/OrderedSet.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,+CAAyE;AAEzE;;;;GAIG;AACH,MAAa,kBAAkB;IACV,MAAM,CAAiB;IAE1C;;;OAGG;IACH,YAAmB,OAA6B,EAAE,QAA0B,0BAAY;QACtF,IAAI,CAAC,MAAM,GAAG,IAAI,yBAAW,CAAI,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,yCAAyC;IACzC,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,qDAAqD;IAC9C,GAAG,CAAC,KAAQ;QACjB,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,6HAA6H;IACtH,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,CAAC;CACF;AAzBD,gDAyBC;AAED;;GAEG;AACH,MAAa,UAAc,SAAQ,kBAAqB;IACtD;;;OAGG;IACH,YAAmB,OAA6B,EAAE,QAA0B,0BAAY;QACtF,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,wCAAwC;IACjC,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,8DAA8D;IACvD,GAAG,CAAC,KAAQ;QACjB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6FAA6F;IACtF,MAAM,CAAC,KAAQ;QACpB,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF;AAxBD,gCAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Collections\n */\n\nimport { OrderedComparator } from \"./Compare\";\nimport { CloneFunction, shallowClone, SortedArray } from \"./SortedArray\";\n\n/** A read-only equivalent of `Set<T>` that maintains its elements in sorted order as specified by a comparison function.\n * Iteration returns elements in the order specified by the comparison function, as opposed to `Set` which returns elements in insertion order.\n * Implemented in terms of [[SortedArray]].\n * @public\n */\nexport class ReadonlyOrderedSet<T> implements Iterable<T> {\n protected readonly _array: SortedArray<T>;\n\n /** Construct a new ReadonlyOrderedSet<T>.\n * @param compare The function used to compare elements within the set, determining their ordering.\n * @param clone The function invoked to clone a new element for insertion into the set. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, clone: CloneFunction<T> = shallowClone) {\n this._array = new SortedArray<T>(compare, false, clone);\n }\n\n /** The number of elements in the set. */\n public get size(): number {\n return this._array.length;\n }\n\n /** Returns true if `value` is present in the set. */\n public has(value: T): boolean {\n return -1 !== this._array.indexOf(value);\n }\n\n /** Iterate over the elements in sorted order (as opposed to `Set`'s iterator, which returns elements in insertion order). */\n public [Symbol.iterator](): Iterator<T> {\n return this._array[Symbol.iterator]();\n }\n}\n\n/** A mutable [[ReadonlyOrderedSet]].\n * @public\n */\nexport class OrderedSet<T> extends ReadonlyOrderedSet<T> {\n /** Construct a new OrderedSet<T>.\n * @param compare The function used to compare elements within the set, determining their ordering.\n * @param clone The function invoked to clone a new element for insertion into the set. The default implementation simply returns its input.\n */\n public constructor(compare: OrderedComparator<T>, clone: CloneFunction<T> = shallowClone) {\n super(compare, clone);\n }\n\n /** Remove all elements from the set. */\n public clear(): void {\n this._array.clear();\n }\n\n /** Add the specified element to the set. Returns this set. */\n public add(value: T): this {\n this._array.insert(value);\n return this;\n }\n\n /** Removes the specified element from the set. Returns `true` if the element was present. */\n public delete(value: T): boolean {\n return -1 !== this._array.remove(value);\n }\n}\n"]}
|
package/lib/cjs/PriorityQueue.js
CHANGED
|
@@ -15,6 +15,9 @@ const SortedArray_1 = require("./SortedArray");
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
class PriorityQueue {
|
|
18
|
+
_array = [];
|
|
19
|
+
_compare;
|
|
20
|
+
_clone;
|
|
18
21
|
/**
|
|
19
22
|
* Constructor
|
|
20
23
|
* @param compare The function used to compare values in the queue. If `compare(x, y)` returns a negative value, then x is placed before y in the queue.
|
|
@@ -22,7 +25,6 @@ class PriorityQueue {
|
|
|
22
25
|
* @note If the criterion which control the result of the `compare` function changes, then [[PriorityQueue.sort]] should be used to reorder the queue according to the new criterion.
|
|
23
26
|
*/
|
|
24
27
|
constructor(compare, clone = SortedArray_1.shallowClone) {
|
|
25
|
-
this._array = [];
|
|
26
28
|
this._compare = compare;
|
|
27
29
|
this._clone = clone;
|
|
28
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PriorityQueue.js","sourceRoot":"","sources":["../../src/PriorityQueue.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,+CAA4D;AAK5D;;;;GAIG;AACH,MAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"PriorityQueue.js","sourceRoot":"","sources":["../../src/PriorityQueue.ts"],"names":[],"mappings":";AA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AO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF;AA/ID,sCA+IC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Collections\n */\n\nimport { OrderedComparator } from \"./Compare\";\nimport { CloneFunction, shallowClone } from \"./SortedArray\";\n\n/** @public */\nexport type ComputePriorityFunction<T> = (value: T) => number;\n\n/**\n * A [priority queue](https://en.wikipedia.org/wiki/Priority_queue) implemented as a heap array.\n * The queue is ordered by an [[OrderedComparator]] function supplied by the user such that the value in the queue that compares less than all other values is always located at the front of the queue.\n * @public\n */\nexport class PriorityQueue<T> implements Iterable<T> {\n protected _array: T[] = [];\n protected readonly _compare: OrderedComparator<T>;\n protected readonly _clone: CloneFunction<T>;\n\n /**\n * Constructor\n * @param compare The function used to compare values in the queue. If `compare(x, y)` returns a negative value, then x is placed before y in the queue.\n * @param clone The function used to clone a value for insertion onto the queue. The default implementation simply returns its input.\n * @note If the criterion which control the result of the `compare` function changes, then [[PriorityQueue.sort]] should be used to reorder the queue according to the new criterion.\n */\n public constructor(compare: OrderedComparator<T>, clone: CloneFunction<T> = shallowClone) {\n this._compare = compare;\n this._clone = clone;\n }\n\n /** The number of values in the queue. */\n public get length(): number { return this._array.length; }\n\n /** Returns true if the queue contains no values. */\n public get isEmpty(): boolean { return 0 === this.length; }\n\n /** Returns an iterator over the contents of the heap suitable for use in `for-of` loops. */\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\n\n protected _swap(a: number, b: number) {\n const temp = this._array[a];\n this._array[a] = this._array[b];\n this._array[b] = temp;\n }\n\n protected _heapify(index: number): void {\n let candidate = -1;\n while (true) {\n const right = 2 * (index + 1);\n const left = right - 1;\n if (left < this.length && this._compare(this._array[left], this._array[index]) < 0)\n candidate = left;\n else\n candidate = index;\n\n if (right < this.length && this._compare(this._array[right], this._array[candidate]) < 0)\n candidate = right;\n\n if (candidate !== index) {\n this._swap(candidate, index);\n index = candidate;\n } else {\n break;\n }\n }\n }\n\n /**\n * Reorders the queue. This function should only (and *always*) be called when the criteria governing the ordering of items on the queue have changed.\n * For example, a priority queue containing graphics sorted by their distance from the camera would need to be reordered when the position of the camera changes.\n */\n public sort(): void {\n for (let i = Math.ceil(this.length / 2); i >= 0; i--)\n this._heapify(i);\n }\n\n /**\n * Pushes a value onto the queue according to the sorting criterion.\n * @param value The value to insert\n * @returns The inserted value, cloned according to the [[CloneFunction]] supplied to this queue's constructor.\n */\n public push(value: T): T {\n const clone = this._clone(value);\n\n let index = this.length;\n this._array.push(clone);\n\n while (index !== 0) {\n const parent = Math.floor((index - 1) / 2);\n if (this._compare(this._array[index], this._array[parent]) < 0) {\n this._swap(index, parent);\n index = parent;\n } else {\n break;\n }\n }\n\n return clone;\n }\n\n /** Pushes a value onto the back of the queue without making any attempt to enforce ordering.\n * After using this function, you must manually invoke sort() to ensure the queue is sorted again.\n * @param value The value to append\n * @returns The appended value, cloned according to the [[CloneFunction]] supplied to this queue's constructor.\n */\n public append(value: T): T {\n const clone = this._clone(value);\n this._array.push(clone);\n return clone;\n }\n\n /** Returns the element at the front of the queue, or `undefined` if the queue is empty. */\n public get front(): T | undefined {\n return this._peek(0);\n }\n\n /**\n * Removes the front-most element off of the queue and returns it.\n * @returns The front-most element, or undefined if the queue is empty.\n */\n public pop(): T | undefined {\n return this._pop(0);\n }\n\n /** Removes all values from the queue. */\n public clear(): void {\n this._array.length = 0;\n }\n\n /**\n * Removes the value at the specified index from the queue and reorders the queue.\n * @param index The index of the value to remove\n * @returns the value at the specified index, or undefined if the index is out of range.\n */\n protected _pop(index: number): T | undefined {\n if (index < 0 || index >= this.length)\n return undefined;\n\n const root = this._array[index];\n this._swap(index, this.length - 1);\n this._array.length--;\n\n this._heapify(index);\n return root;\n }\n\n /**\n * Returns the value at the specified index in the queue.\n * @param index The index of the value to retrieve\n * @returns the value at the specified index, or undefined if the index is out of range.\n */\n protected _peek(index: number): T | undefined {\n if (index < 0 || index >= this.length)\n return undefined;\n else\n return this._array[index];\n }\n}\n"]}
|
package/lib/cjs/SortedArray.js
CHANGED
|
@@ -85,6 +85,10 @@ var DuplicatePolicy;
|
|
|
85
85
|
* @public
|
|
86
86
|
*/
|
|
87
87
|
class ReadonlySortedArray {
|
|
88
|
+
_array = [];
|
|
89
|
+
_compare;
|
|
90
|
+
_clone;
|
|
91
|
+
_duplicatePolicy;
|
|
88
92
|
/**
|
|
89
93
|
* Construct a new ReadonlySortedArray<T>.
|
|
90
94
|
* @param compare The function used to compare elements within the array.
|
|
@@ -92,7 +96,6 @@ class ReadonlySortedArray {
|
|
|
92
96
|
* @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.
|
|
93
97
|
*/
|
|
94
98
|
constructor(compare, duplicatePolicy = false, clone = shallowClone) {
|
|
95
|
-
this._array = [];
|
|
96
99
|
this._compare = compare;
|
|
97
100
|
this._clone = clone;
|
|
98
101
|
if (typeof duplicatePolicy === "boolean")
|