@itwin/core-bentley 4.0.0-dev.7 → 4.0.0-dev.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -12
- 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 +8 -8
package/lib/esm/Tracing.d.ts
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Logging
|
|
3
|
+
*/
|
|
4
|
+
import type { SpanAttributes, SpanContext, SpanOptions, Tracer } from "@opentelemetry/api";
|
|
5
|
+
/**
|
|
6
|
+
* Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare enum SpanKind {
|
|
10
|
+
INTERNAL = 0,
|
|
11
|
+
SERVER = 1,
|
|
12
|
+
CLIENT = 2,
|
|
13
|
+
PRODUCER = 3,
|
|
14
|
+
CONSUMER = 4
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Enables OpenTelemetry tracing in addition to traditional logging.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare class Tracing {
|
|
21
|
+
private static _tracer?;
|
|
22
|
+
private static _openTelemetry?;
|
|
23
|
+
/**
|
|
24
|
+
* If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.
|
|
25
|
+
* If OpenTelemetry tracing is _not_ enabled, runs the provided function.
|
|
26
|
+
* @param name name of the new span
|
|
27
|
+
* @param fn function to run inside the new span
|
|
28
|
+
* @param options span options
|
|
29
|
+
* @param parentContext optional context used to retrieve parent span id
|
|
30
|
+
*/
|
|
31
|
+
static withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.
|
|
34
|
+
* [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.
|
|
35
|
+
* @note Node.js OpenTelemetry SDK should be initialized by the user.
|
|
36
|
+
*/
|
|
37
|
+
static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry): void;
|
|
38
|
+
private static withOpenTelemetry;
|
|
39
|
+
/** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.
|
|
40
|
+
* @param attributes The attributes to set
|
|
41
|
+
*/
|
|
42
|
+
static setAttributes(attributes: SpanAttributes): void;
|
|
43
|
+
}
|
|
41
44
|
//# sourceMappingURL=Tracing.d.ts.map
|
package/lib/esm/Tracing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tracing.d.ts","sourceRoot":"","sources":["../../src/Tracing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,cAAc,EAAsB,WAAW,EAAE,WAAW,EAAY,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAIrI;;;GAGG;AACH,oBAAY,QAAQ;IAClB,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,MAAM,IAAI;IACV,QAAQ,IAAI;IACZ,QAAQ,IAAI;CACb;AA2DD;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAoH;IAElJ;;;;;;;OAOG;WACiB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IA4BnI;;;;OAIG;WACW,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,OAAO,CAAC,cAAc;IASpF,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAShC;;OAEG;WACW,aAAa,CAAC,UAAU,EAAE,cAAc;CAGvD"}
|
|
1
|
+
{"version":3,"file":"Tracing.d.ts","sourceRoot":"","sources":["../../src/Tracing.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,EAAc,cAAc,EAAsB,WAAW,EAAE,WAAW,EAAY,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAIrI;;;GAGG;AACH,oBAAY,QAAQ;IAClB,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,MAAM,IAAI;IACV,QAAQ,IAAI;IACZ,QAAQ,IAAI;CACb;AA2DD;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAS;I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|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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 Logging
|
|
7
|
+
*/
|
|
8
|
+
import { Logger } from "./Logger";
|
|
9
|
+
// re-export so that consumers can construct full SpanOptions object without external dependencies
|
|
10
|
+
/**
|
|
11
|
+
* Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export var SpanKind;
|
|
15
|
+
(function (SpanKind) {
|
|
16
|
+
SpanKind[SpanKind["INTERNAL"] = 0] = "INTERNAL";
|
|
17
|
+
SpanKind[SpanKind["SERVER"] = 1] = "SERVER";
|
|
18
|
+
SpanKind[SpanKind["CLIENT"] = 2] = "CLIENT";
|
|
19
|
+
SpanKind[SpanKind["PRODUCER"] = 3] = "PRODUCER";
|
|
20
|
+
SpanKind[SpanKind["CONSUMER"] = 4] = "CONSUMER";
|
|
21
|
+
})(SpanKind || (SpanKind = {}));
|
|
22
|
+
function isValidPrimitive(val) {
|
|
23
|
+
return typeof val === "string" || typeof val === "number" || typeof val === "boolean";
|
|
24
|
+
}
|
|
25
|
+
// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.
|
|
26
|
+
// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.
|
|
27
|
+
function isValidPrimitiveArray(val) {
|
|
28
|
+
if (!Array.isArray(val))
|
|
29
|
+
return false;
|
|
30
|
+
let itemType;
|
|
31
|
+
for (const x of val) {
|
|
32
|
+
if (x === undefined || x === null)
|
|
33
|
+
continue;
|
|
34
|
+
if (!itemType) {
|
|
35
|
+
itemType = typeof x;
|
|
36
|
+
if (!isValidPrimitive(x))
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (typeof x !== itemType)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function isPlainObject(obj) {
|
|
45
|
+
return typeof obj === "object" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
|
|
46
|
+
}
|
|
47
|
+
function* getFlatEntries(obj, path = "") {
|
|
48
|
+
if (isValidPrimitiveArray(obj)) {
|
|
49
|
+
yield [path, obj];
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Prefer JSON serialization over flattening for any non-POJO types.
|
|
53
|
+
// There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)
|
|
54
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) {
|
|
55
|
+
yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// Always serialize empty objects/arrays as empty array values
|
|
59
|
+
const entries = Object.entries(obj);
|
|
60
|
+
if (entries.length === 0)
|
|
61
|
+
yield [path, []];
|
|
62
|
+
for (const [key, val] of entries)
|
|
63
|
+
yield* getFlatEntries(val, (path === "") ? key : `${path}.${key}`);
|
|
64
|
+
}
|
|
65
|
+
function flattenObject(obj) {
|
|
66
|
+
return Object.fromEntries(getFlatEntries(obj));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Enables OpenTelemetry tracing in addition to traditional logging.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export class Tracing {
|
|
73
|
+
/**
|
|
74
|
+
* If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.
|
|
75
|
+
* If OpenTelemetry tracing is _not_ enabled, runs the provided function.
|
|
76
|
+
* @param name name of the new span
|
|
77
|
+
* @param fn function to run inside the new span
|
|
78
|
+
* @param options span options
|
|
79
|
+
* @param parentContext optional context used to retrieve parent span id
|
|
80
|
+
*/
|
|
81
|
+
static async withSpan(name, fn, options, parentContext) {
|
|
82
|
+
if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)
|
|
83
|
+
return fn();
|
|
84
|
+
// this case is for context propagation - parentContext is typically constructed from HTTP headers
|
|
85
|
+
const parent = parentContext === undefined
|
|
86
|
+
? Tracing._openTelemetry.context.active()
|
|
87
|
+
: Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);
|
|
88
|
+
return Tracing._openTelemetry.context.with(Tracing._openTelemetry.trace.setSpan(parent, Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())), async () => {
|
|
89
|
+
try {
|
|
90
|
+
return await fn();
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse
|
|
94
|
+
Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute("error", true);
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.
|
|
104
|
+
* [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.
|
|
105
|
+
* @note Node.js OpenTelemetry SDK should be initialized by the user.
|
|
106
|
+
*/
|
|
107
|
+
static enableOpenTelemetry(tracer, api) {
|
|
108
|
+
Tracing._tracer = tracer;
|
|
109
|
+
Tracing._openTelemetry = api;
|
|
110
|
+
Logger.logTrace = Tracing.withOpenTelemetry(Logger.logTrace);
|
|
111
|
+
Logger.logInfo = Tracing.withOpenTelemetry(Logger.logInfo);
|
|
112
|
+
Logger.logWarning = Tracing.withOpenTelemetry(Logger.logWarning);
|
|
113
|
+
Logger.logError = Tracing.withOpenTelemetry(Logger.logError);
|
|
114
|
+
}
|
|
115
|
+
static withOpenTelemetry(base, isError = false) {
|
|
116
|
+
return (category, message, metaData) => {
|
|
117
|
+
try {
|
|
118
|
+
Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });
|
|
119
|
+
}
|
|
120
|
+
catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work
|
|
121
|
+
base(category, message, metaData);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.
|
|
125
|
+
* @param attributes The attributes to set
|
|
126
|
+
*/
|
|
127
|
+
static setAttributes(attributes) {
|
|
128
|
+
Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
127
131
|
//# sourceMappingURL=Tracing.js.map
|
package/lib/esm/Tracing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tracing.js","sourceRoot":"","sources":["../../src/Tracing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,MAAM,EAAE,MAAM,UAAU,CAAC;AAE/C,kGAAkG;AAClG;;;GAGG;AACH,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,+CAAY,CAAA;IACZ,2CAAU,CAAA;IACV,2CAAU,CAAA;IACV,+CAAY,CAAA;IACZ,+CAAY,CAAA;AACd,CAAC,EANW,QAAQ,KAAR,QAAQ,QAMnB;AAED,SAAS,gBAAgB,CAAC,GAAY;IACpC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,SAAS,CAAC;AACxF,CAAC;AAED,6GAA6G;AAC7G,iJAAiJ;AACjJ,SAAS,qBAAqB,CAAC,GAAY;IACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACrB,OAAO,KAAK,CAAC;IAEf,IAAI,QAAQ,CAAC;IACb,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACnB,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;YAC/B,SAAS;QAEX,IAAI,CAAC,QAAQ,EAAE;YACb,QAAQ,GAAG,OAAO,CAAC,CAAC;YACpB,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;gBACtB,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,OAAO,CAAC,KAAK,QAAQ;YACvB,OAAO,KA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C,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,0CAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5G,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport type { ContextAPI, SpanAttributes, SpanAttributeValue, SpanContext, SpanOptions, TraceAPI, Tracer } from \"@opentelemetry/api\";\r\nimport { LogFunction, Logger } from \"./Logger\";\r\n\r\n// re-export so that consumers can construct full SpanOptions object without external dependencies\r\n/**\r\n * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js-api/enums/spankind)\r\n * @alpha\r\n */\r\nexport enum SpanKind {\r\n INTERNAL = 0,\r\n SERVER = 1,\r\n CLIENT = 2,\r\n PRODUCER = 3,\r\n CONSUMER = 4\r\n}\r\n\r\nfunction isValidPrimitive(val: unknown): val is SpanAttributeValue {\r\n return typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\";\r\n}\r\n\r\n// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.\r\n// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.\r\nfunction isValidPrimitiveArray(val: unknown): val is SpanAttributeValue {\r\n if (!Array.isArray(val))\r\n return false;\r\n\r\n let itemType;\r\n for (const x of val) {\r\n if (x === undefined || x === null)\r\n continue;\r\n\r\n if (!itemType) {\r\n itemType = typeof x;\r\n if (!isValidPrimitive(x))\r\n return false;\r\n }\r\n\r\n if (typeof x !== itemType)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction isPlainObject(obj: unknown): obj is object {\r\n return typeof obj === \"object\" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\r\n}\r\n\r\nfunction* getFlatEntries(obj: unknown, path = \"\"): Iterable<[string, SpanAttributeValue]> {\r\n if (isValidPrimitiveArray(obj)) {\r\n yield [path, obj];\r\n return;\r\n }\r\n\r\n // Prefer JSON serialization over flattening for any non-POJO types.\r\n // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)\r\n if (!isPlainObject(obj) && !Array.isArray(obj)) {\r\n yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];\r\n return;\r\n }\r\n\r\n // Always serialize empty objects/arrays as empty array values\r\n const entries = Object.entries(obj);\r\n if (entries.length === 0)\r\n yield [path, []];\r\n\r\n for (const [key, val] of entries)\r\n yield* getFlatEntries(val, (path === \"\") ? key : `${path}.${key}`);\r\n}\r\n\r\nfunction flattenObject(obj: object): SpanAttributes {\r\n return Object.fromEntries(getFlatEntries(obj));\r\n}\r\n\r\n/**\r\n * Enables OpenTelemetry tracing in addition to traditional logging.\r\n * @alpha\r\n */\r\nexport class Tracing {\r\n private static _tracer?: Tracer;\r\n private static _openTelemetry?: { trace: Pick<TraceAPI, \"setSpan\" | \"setSpanContext\" | \"getSpan\">, context: Pick<ContextAPI, \"active\" | \"with\"> };\r\n\r\n /**\r\n * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.\r\n * If OpenTelemetry tracing is _not_ enabled, runs the provided function.\r\n * @param name name of the new span\r\n * @param fn function to run inside the new span\r\n * @param options span options\r\n * @param parentContext optional context used to retrieve parent span id\r\n */\r\n public static async withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T> {\r\n if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)\r\n return fn();\r\n\r\n // this case is for context propagation - parentContext is typically constructed from HTTP headers\r\n const parent = parentContext === undefined\r\n ? Tracing._openTelemetry.context.active()\r\n : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);\r\n\r\n return Tracing._openTelemetry.context.with(\r\n Tracing._openTelemetry.trace.setSpan(\r\n parent,\r\n Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())\r\n ),\r\n async () => {\r\n try {\r\n return await fn();\r\n } catch (err) {\r\n if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute(\"error\", true);\r\n throw err;\r\n } finally {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();\r\n }\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.\r\n * [[IModelHost.startup]] will call this automatically if it succeeds in requiring `@opentelemetry/api`.\r\n * @note Node.js OpenTelemetry SDK should be initialized by the user.\r\n */\r\n public static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry) {\r\n Tracing._tracer = tracer;\r\n Tracing._openTelemetry = api;\r\n Logger.logTrace = Tracing.withOpenTelemetry(Logger.logTrace);\r\n Logger.logInfo = Tracing.withOpenTelemetry(Logger.logInfo);\r\n Logger.logWarning = Tracing.withOpenTelemetry(Logger.logWarning);\r\n Logger.logError = Tracing.withOpenTelemetry(Logger.logError);\r\n }\r\n\r\n private static withOpenTelemetry(base: LogFunction, isError: boolean = false): LogFunction {\r\n return (category, message, metaData) => {\r\n try {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });\r\n } catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work\r\n base(category, message, metaData);\r\n };\r\n }\r\n\r\n /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.\r\n * @param attributes The attributes to set\r\n */\r\n public static setAttributes(attributes: SpanAttributes) {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Tracing.js","sourceRoot":"","sources":["../../src/T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BAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAAC,IAAiB,EAAE,UAAmB,KAAK;QAC1E,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;YACrC,IAAI;gBACF,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;aACvK;YAAC,OAAO,EAAE,EAAE,GAAG,CAAC,mHAAmH;YACpI,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,aAAa,CAAC,UAA0B;QACpD,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5G,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Logging\r\n */\r\n\r\nimport type { ContextAPI, SpanAttributes, SpanAttributeValue, SpanContext, SpanOptions, TraceAPI, Tracer } from \"@opentelemetry/api\";\r\nimport { LogFunction, Logger } from \"./Logger\";\r\n\r\n// re-export so that consumers can construct full SpanOptions object without external dependencies\r\n/**\r\n * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js/enums/_opentelemetry_api.SpanKind.html)\r\n * @public\r\n */\r\nexport enum SpanKind {\r\n INTERNAL = 0,\r\n SERVER = 1,\r\n CLIENT = 2,\r\n PRODUCER = 3,\r\n CONSUMER = 4\r\n}\r\n\r\nfunction isValidPrimitive(val: unknown): val is SpanAttributeValue {\r\n return typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\";\r\n}\r\n\r\n// Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.\r\n// Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.\r\nfunction isValidPrimitiveArray(val: unknown): val is SpanAttributeValue {\r\n if (!Array.isArray(val))\r\n return false;\r\n\r\n let itemType;\r\n for (const x of val) {\r\n if (x === undefined || x === null)\r\n continue;\r\n\r\n if (!itemType) {\r\n itemType = typeof x;\r\n if (!isValidPrimitive(x))\r\n return false;\r\n }\r\n\r\n if (typeof x !== itemType)\r\n return false;\r\n }\r\n return true;\r\n}\r\n\r\nfunction isPlainObject(obj: unknown): obj is object {\r\n return typeof obj === \"object\" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\r\n}\r\n\r\nfunction* getFlatEntries(obj: unknown, path = \"\"): Iterable<[string, SpanAttributeValue]> {\r\n if (isValidPrimitiveArray(obj)) {\r\n yield [path, obj];\r\n return;\r\n }\r\n\r\n // Prefer JSON serialization over flattening for any non-POJO types.\r\n // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)\r\n if (!isPlainObject(obj) && !Array.isArray(obj)) {\r\n yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];\r\n return;\r\n }\r\n\r\n // Always serialize empty objects/arrays as empty array values\r\n const entries = Object.entries(obj);\r\n if (entries.length === 0)\r\n yield [path, []];\r\n\r\n for (const [key, val] of entries)\r\n yield* getFlatEntries(val, (path === \"\") ? key : `${path}.${key}`);\r\n}\r\n\r\nfunction flattenObject(obj: object): SpanAttributes {\r\n return Object.fromEntries(getFlatEntries(obj));\r\n}\r\n\r\n/**\r\n * Enables OpenTelemetry tracing in addition to traditional logging.\r\n * @public\r\n */\r\nexport class Tracing {\r\n private static _tracer?: Tracer;\r\n private static _openTelemetry?: { trace: Pick<TraceAPI, \"setSpan\" | \"setSpanContext\" | \"getSpan\">, context: Pick<ContextAPI, \"active\" | \"with\"> };\r\n\r\n /**\r\n * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.\r\n * If OpenTelemetry tracing is _not_ enabled, runs the provided function.\r\n * @param name name of the new span\r\n * @param fn function to run inside the new span\r\n * @param options span options\r\n * @param parentContext optional context used to retrieve parent span id\r\n */\r\n public static async withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T> {\r\n if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)\r\n return fn();\r\n\r\n // this case is for context propagation - parentContext is typically constructed from HTTP headers\r\n const parent = parentContext === undefined\r\n ? Tracing._openTelemetry.context.active()\r\n : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);\r\n\r\n return Tracing._openTelemetry.context.with(\r\n Tracing._openTelemetry.trace.setSpan(\r\n parent,\r\n Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())\r\n ),\r\n async () => {\r\n try {\r\n return await fn();\r\n } catch (err) {\r\n if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute(\"error\", true);\r\n throw err;\r\n } finally {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();\r\n }\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.\r\n * [IModelHost.startup]($backend) will call this automatically if the `enableOpenTelemetry` option is enabled and it succeeds in requiring `@opentelemetry/api`.\r\n * @note Node.js OpenTelemetry SDK should be initialized by the user.\r\n */\r\n public static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry) {\r\n Tracing._tracer = tracer;\r\n Tracing._openTelemetry = api;\r\n Logger.logTrace = Tracing.withOpenTelemetry(Logger.logTrace);\r\n Logger.logInfo = Tracing.withOpenTelemetry(Logger.logInfo);\r\n Logger.logWarning = Tracing.withOpenTelemetry(Logger.logWarning);\r\n Logger.logError = Tracing.withOpenTelemetry(Logger.logError);\r\n }\r\n\r\n private static withOpenTelemetry(base: LogFunction, isError: boolean = false): LogFunction {\r\n return (category, message, metaData) => {\r\n try {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger.getMetaData(metaData)), error: isError });\r\n } catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work\r\n base(category, message, metaData);\r\n };\r\n }\r\n\r\n /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.\r\n * @param attributes The attributes to set\r\n */\r\n public static setAttributes(attributes: SpanAttributes) {\r\n Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);\r\n }\r\n}\r\n"]}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Collections
|
|
3
|
-
*/
|
|
4
|
-
/** A map similar to the standard JavaScript Map collection except that the keys must be a tuple
|
|
5
|
-
* (javascript array), and two keys are considered equal if their elements in order are strict-equal,
|
|
6
|
-
* and the tuples have the same amount of elements
|
|
7
|
-
*
|
|
8
|
-
* This means you can use array literals to key data in Maps that would otherwise be reference-compared
|
|
9
|
-
* if using JavaScript's built in Map
|
|
10
|
-
*
|
|
11
|
-
* Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead
|
|
12
|
-
* SameValueZero equality comparison
|
|
13
|
-
* @see https://262.ecma-international.org/6.0/#sec-samevaluezero
|
|
14
|
-
*
|
|
15
|
-
* ```js
|
|
16
|
-
* const map = new TupleKeyedMap([[1,"y"], "value"]);
|
|
17
|
-
* const value = map.get([1, "y"]); // a normal map would identify these keys as different because they are independent objects
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* It is implemented by each index of the tuple key being used as a singular key into a submap
|
|
21
|
-
* @note this only implements a subset of the Map interface
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export declare class TupleKeyedMap<K extends readonly any[], V> {
|
|
25
|
-
private _map;
|
|
26
|
-
constructor(entries?: readonly (readonly [K, V])[] | null);
|
|
27
|
-
clear(): void;
|
|
28
|
-
private makeKeyError;
|
|
29
|
-
get(key: K): V | undefined;
|
|
30
|
-
has(key: K): boolean;
|
|
31
|
-
set(key: K, value: V): this;
|
|
32
|
-
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
33
|
-
private _size;
|
|
34
|
-
get size(): number;
|
|
35
|
-
get [Symbol.toStringTag](): string;
|
|
36
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Collections
|
|
3
|
+
*/
|
|
4
|
+
/** A map similar to the standard JavaScript Map collection except that the keys must be a tuple
|
|
5
|
+
* (javascript array), and two keys are considered equal if their elements in order are strict-equal,
|
|
6
|
+
* and the tuples have the same amount of elements
|
|
7
|
+
*
|
|
8
|
+
* This means you can use array literals to key data in Maps that would otherwise be reference-compared
|
|
9
|
+
* if using JavaScript's built in Map
|
|
10
|
+
*
|
|
11
|
+
* Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead
|
|
12
|
+
* SameValueZero equality comparison
|
|
13
|
+
* @see https://262.ecma-international.org/6.0/#sec-samevaluezero
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* const map = new TupleKeyedMap([[1,"y"], "value"]);
|
|
17
|
+
* const value = map.get([1, "y"]); // a normal map would identify these keys as different because they are independent objects
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* It is implemented by each index of the tuple key being used as a singular key into a submap
|
|
21
|
+
* @note this only implements a subset of the Map interface
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare class TupleKeyedMap<K extends readonly any[], V> {
|
|
25
|
+
private _map;
|
|
26
|
+
constructor(entries?: readonly (readonly [K, V])[] | null);
|
|
27
|
+
clear(): void;
|
|
28
|
+
private makeKeyError;
|
|
29
|
+
get(key: K): V | undefined;
|
|
30
|
+
has(key: K): boolean;
|
|
31
|
+
set(key: K, value: V): this;
|
|
32
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
33
|
+
private _size;
|
|
34
|
+
get size(): number;
|
|
35
|
+
get [Symbol.toStringTag](): string;
|
|
36
|
+
}
|
|
37
37
|
//# sourceMappingURL=TupleKeyedMap.d.ts.map
|