@microsoft/applicationinsights-core-js 3.0.0-beta.2303-02 → 3.0.0-beta.2303-04
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/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +2 -2
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +113 -206
- package/dist/applicationinsights-core-js.api.md +11 -14
- package/dist/applicationinsights-core-js.d.ts +15 -13
- package/dist/applicationinsights-core-js.js +2 -2
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +15 -13
- package/dist-esm/Config/ConfigDefaultHelpers.js +1 -1
- package/dist-esm/Config/ConfigDefaults.js +1 -1
- package/dist-esm/Config/DynamicConfig.js +1 -1
- package/dist-esm/Config/DynamicProperty.js +1 -1
- package/dist-esm/Config/DynamicState.js +1 -1
- package/dist-esm/Config/DynamicSupport.js +1 -1
- package/dist-esm/Config/IConfigDefaults.js +1 -1
- package/dist-esm/Config/IDynamicConfigHandler.js +1 -1
- package/dist-esm/Config/IDynamicPropertyHandler.js +1 -1
- package/dist-esm/Config/IDynamicWatcher.js +1 -1
- package/dist-esm/Config/_IDynamicConfigHandlerState.js +1 -1
- package/dist-esm/JavaScriptSDK/AggregationError.js +1 -1
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHookContainer.js +1 -1
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
- package/dist-esm/__DynamicConstants.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +1 -1
- package/package.json +1 -1
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +5 -6
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +9 -6
- package/src/JavaScriptSDK/AggregationError.ts +0 -36
- package/src/JavaScriptSDK/AppInsightsCore.ts +0 -1322
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +0 -343
- package/src/JavaScriptSDK/Constants.ts +0 -4
- package/src/JavaScriptSDK/CookieMgr.ts +0 -449
- package/src/JavaScriptSDK/CoreUtils.ts +0 -58
- package/src/JavaScriptSDK/DataCacheHelper.ts +0 -107
- package/src/JavaScriptSDK/DbgExtensionUtils.ts +0 -56
- package/src/JavaScriptSDK/DiagnosticLogger.ts +0 -380
- package/src/JavaScriptSDK/EnvUtils.ts +0 -312
- package/src/JavaScriptSDK/EventHelpers.ts +0 -550
- package/src/JavaScriptSDK/HelperFuncs.ts +0 -351
- package/src/JavaScriptSDK/InstrumentHooks.ts +0 -280
- package/src/JavaScriptSDK/InternalConstants.ts +0 -31
- package/src/JavaScriptSDK/NotificationManager.ts +0 -165
- package/src/JavaScriptSDK/PerfManager.ts +0 -288
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +0 -674
- package/src/JavaScriptSDK/RandomHelper.ts +0 -145
- package/src/JavaScriptSDK/TelemetryHelpers.ts +0 -184
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -112
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -45
- package/src/JavaScriptSDK/UnloadHookContainer.ts +0 -52
- package/src/JavaScriptSDK/W3cTraceParent.ts +0 -197
- package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +0 -24
- package/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts +0 -71
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +0 -121
- package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -56
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
- package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +0 -216
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +0 -46
- package/src/JavaScriptSDK.Interfaces/IConfiguration.ts +0 -176
- package/src/JavaScriptSDK.Interfaces/ICookieMgr.ts +0 -116
- package/src/JavaScriptSDK.Interfaces/IDbgExtension.ts +0 -14
- package/src/JavaScriptSDK.Interfaces/IDiagnosticLogger.ts +0 -75
- package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +0 -54
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +0 -100
- package/src/JavaScriptSDK.Interfaces/INotificationListener.ts +0 -39
- package/src/JavaScriptSDK.Interfaces/INotificationManager.ts +0 -52
- package/src/JavaScriptSDK.Interfaces/IPerfEvent.ts +0 -69
- package/src/JavaScriptSDK.Interfaces/IPerfManager.ts +0 -53
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +0 -157
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -17
- package/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +0 -62
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +0 -94
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +0 -30
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
- package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -44
- package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +0 -38
- package/src/JavaScriptSDK.Interfaces/IUnloadHook.ts +0 -22
- package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { ObjAssign, ObjClass } from "@microsoft/applicationinsights-shims";
|
|
4
|
-
import {
|
|
5
|
-
arrForEach, asString as asString21, isArray, isBoolean, isError, isFunction, isNullOrUndefined, isObject, isPlainObject, isString,
|
|
6
|
-
isUndefined, objDeepFreeze, objDefineAccessors, objForEachKey, objHasOwn, strIndexOf
|
|
7
|
-
} from "@nevware21/ts-utils";
|
|
8
|
-
import { STR_EMPTY } from "./InternalConstants";
|
|
9
|
-
|
|
10
|
-
// RESTRICT and AVOID circular dependencies you should not import other contained modules or export the contents of this file directly
|
|
11
|
-
|
|
12
|
-
// Added to help with minification
|
|
13
|
-
const strGetPrototypeOf = "getPrototypeOf";
|
|
14
|
-
|
|
15
|
-
const rCamelCase = /-([a-z])/g;
|
|
16
|
-
const rNormalizeInvalid = /([^\w\d_$])/g;
|
|
17
|
-
const rLeadingNumeric = /^(\d+[\w\d_$])/;
|
|
18
|
-
|
|
19
|
-
export let _getObjProto = Object[strGetPrototypeOf];
|
|
20
|
-
|
|
21
|
-
export function isNotUndefined<T>(value: T): value is T {
|
|
22
|
-
return !isUndefined(value);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function isNotNullOrUndefined<T>(value: T): value is T {
|
|
26
|
-
return !isNullOrUndefined(value);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Validates that the string name conforms to the JS IdentifierName specification and if not
|
|
31
|
-
* normalizes the name so that it would. This method does not identify or change any keywords
|
|
32
|
-
* meaning that if you pass in a known keyword the same value will be returned.
|
|
33
|
-
* This is a simplified version
|
|
34
|
-
* @param name - The name to validate
|
|
35
|
-
*/
|
|
36
|
-
export function normalizeJsName(name: string): string {
|
|
37
|
-
let value = name;
|
|
38
|
-
|
|
39
|
-
if (value && isString(value)) {
|
|
40
|
-
// CamelCase everything after the "-" and remove the dash
|
|
41
|
-
value = value.replace(rCamelCase, function (_all, letter) {
|
|
42
|
-
return letter.toUpperCase();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
value = value.replace(rNormalizeInvalid, "_");
|
|
46
|
-
value = value.replace(rLeadingNumeric, function(_all, match) {
|
|
47
|
-
return "_" + match;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* A simple wrapper (for minification support) to check if the value contains the search string.
|
|
56
|
-
* @param value - The string value to check for the existence of the search value
|
|
57
|
-
* @param search - The value search within the value
|
|
58
|
-
*/
|
|
59
|
-
export function strContains(value: string, search: string): boolean {
|
|
60
|
-
if (value && search) {
|
|
61
|
-
return strIndexOf(value, search) !== -1;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Convert a date to I.S.O. format in IE8
|
|
69
|
-
*/
|
|
70
|
-
export function toISOString(date: Date) {
|
|
71
|
-
return date && date.toISOString() || "";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const deepFreeze: <T>(obj: T) => T = objDeepFreeze;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Returns the name of object if it's an Error. Otherwise, returns empty string.
|
|
78
|
-
*/
|
|
79
|
-
export function getExceptionName(object: any): string {
|
|
80
|
-
if (isError(object)) {
|
|
81
|
-
return object.name;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return STR_EMPTY;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Sets the provided value on the target instance using the field name when the provided chk function returns true, the chk
|
|
89
|
-
* function will only be called if the new value is no equal to the original value.
|
|
90
|
-
* @param target - The target object
|
|
91
|
-
* @param field - The key of the target
|
|
92
|
-
* @param value - The value to set
|
|
93
|
-
* @param valChk - [Optional] Callback to check the value that if supplied will be called check if the new value can be set
|
|
94
|
-
* @param srcChk - [Optional] Callback to check to original value that if supplied will be called if the new value should be set (if allowed)
|
|
95
|
-
* @returns The existing or new value, depending what was set
|
|
96
|
-
*/
|
|
97
|
-
export function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: ((value: T[K]) => boolean) | null, srcChk?: ((value: T[K]) => boolean) | null) {
|
|
98
|
-
let theValue = value;
|
|
99
|
-
if (target) {
|
|
100
|
-
theValue = target[field];
|
|
101
|
-
if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
|
|
102
|
-
theValue = value;
|
|
103
|
-
target[field] = theValue;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return theValue;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Returns the current value from the target object if not null or undefined otherwise sets the new value and returns it
|
|
112
|
-
* @param target - The target object to return or set the default value
|
|
113
|
-
* @param field - The key for the field to set on the target
|
|
114
|
-
* @param defValue - [Optional] The value to set if not already present, when not provided a empty object will be added
|
|
115
|
-
*/
|
|
116
|
-
export function getSetValue<T, K extends keyof T>(target: T, field: K, defValue?: T[K]): T[K] {
|
|
117
|
-
let theValue;
|
|
118
|
-
if (target) {
|
|
119
|
-
theValue = target[field];
|
|
120
|
-
if (!theValue && isNullOrUndefined(theValue)) {
|
|
121
|
-
// Supports having the default as null
|
|
122
|
-
theValue = !isUndefined(defValue) ? defValue : {} as any;
|
|
123
|
-
target[field] = theValue;
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
// Expanded for performance so we only check defValue if required
|
|
127
|
-
theValue = !isUndefined(defValue) ? defValue : {} as any;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return theValue;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function _createProxyFunction<S>(source: S | (() => S), funcName: (keyof S)) {
|
|
134
|
-
let srcFunc: () => S = null;
|
|
135
|
-
let src: S = null;
|
|
136
|
-
if (isFunction (source)) {
|
|
137
|
-
srcFunc = source;
|
|
138
|
-
} else {
|
|
139
|
-
src = source;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return function() {
|
|
143
|
-
// Capture the original arguments passed to the method
|
|
144
|
-
var originalArguments = arguments;
|
|
145
|
-
if (srcFunc) {
|
|
146
|
-
src = srcFunc();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (src) {
|
|
150
|
-
return (src[funcName] as any).apply(src, originalArguments);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Effectively assigns all enumerable properties (not just own properties) and functions (including inherited prototype) from
|
|
157
|
-
* the source object to the target, it attempts to use proxy getters / setters (if possible) and proxy functions to avoid potential
|
|
158
|
-
* implementation issues by assigning prototype functions as instance ones
|
|
159
|
-
*
|
|
160
|
-
* This method is the primary method used to "update" the snippet proxy with the ultimate implementations.
|
|
161
|
-
*
|
|
162
|
-
* Special ES3 Notes:
|
|
163
|
-
* Updates (setting) of direct property values on the target or indirectly on the source object WILL NOT WORK PROPERLY, updates to the
|
|
164
|
-
* properties of "referenced" object will work (target.context.newValue = 10 => will be reflected in the source.context as it's the
|
|
165
|
-
* same object). ES3 Failures: assigning target.myProp = 3 -> Won't change source.myProp = 3, likewise the reverse would also fail.
|
|
166
|
-
* @param target - The target object to be assigned with the source properties and functions
|
|
167
|
-
* @param source - The source object which will be assigned / called by setting / calling the targets proxies
|
|
168
|
-
* @param chkSet - An optional callback to determine whether a specific property/function should be proxied
|
|
169
|
-
*/
|
|
170
|
-
export function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string, isFunc?: boolean, source?: S, target?: T) => boolean) {
|
|
171
|
-
if (target && source && isObject(target) && isObject(source)) {
|
|
172
|
-
// effectively apply/proxy full source to the target instance
|
|
173
|
-
for (const field in source) {
|
|
174
|
-
if (isString(field)) {
|
|
175
|
-
let value = source[field] as any;
|
|
176
|
-
if (isFunction(value)) {
|
|
177
|
-
if (!chkSet || chkSet(field, true, source, target)) {
|
|
178
|
-
// Create a proxy function rather than just copying the (possible) prototype to the new object as an instance function
|
|
179
|
-
target[field as string] = _createProxyFunction(source, field);
|
|
180
|
-
}
|
|
181
|
-
} else if (!chkSet || chkSet(field, false, source, target)) {
|
|
182
|
-
if (objHasOwn(target, field)) {
|
|
183
|
-
// Remove any previous instance property
|
|
184
|
-
delete (target as any)[field];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!objDefineAccessors(target, field, () => {
|
|
188
|
-
return source[field];
|
|
189
|
-
}, (theValue) => {
|
|
190
|
-
source[field] = theValue;
|
|
191
|
-
})) {
|
|
192
|
-
// Unable to create an accessor, so just assign the values as a fallback
|
|
193
|
-
// -- this will (mostly) work for objects
|
|
194
|
-
// -- but will fail for accessing primitives (if the source changes it) and all types of "setters" as the source won't be modified
|
|
195
|
-
target[field as string] = value;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return target;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Creates a proxy function on the target which internally will call the source version with all arguments passed to the target method.
|
|
207
|
-
*
|
|
208
|
-
* @param target - The target object to be assigned with the source properties and functions
|
|
209
|
-
* @param name - The function name that will be added on the target
|
|
210
|
-
* @param source - The source object which will be assigned / called by setting / calling the targets proxies
|
|
211
|
-
* @param theFunc - The function name on the source that will be proxied on the target
|
|
212
|
-
* @param overwriteTarget - If `false` this will not replace any pre-existing name otherwise (the default) it will overwrite any existing name
|
|
213
|
-
*/
|
|
214
|
-
export function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() => S), theFunc: (keyof S), overwriteTarget?: boolean) {
|
|
215
|
-
if (target && name && source) {
|
|
216
|
-
if (overwriteTarget !== false || isUndefined(target[name])) {
|
|
217
|
-
(target as any)[name] = _createProxyFunction(source, theFunc);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
|
|
224
|
-
*
|
|
225
|
-
* @param target - The target object to be assigned with the source properties and functions
|
|
226
|
-
* @param source - The source object which will be assigned / called by setting / calling the targets proxies
|
|
227
|
-
* @param functionsToProxy - An array of function names that will be proxied on the target
|
|
228
|
-
* @param overwriteTarget - If false this will not replace any pre-existing name otherwise (the default) it will overwrite any existing name
|
|
229
|
-
*/
|
|
230
|
-
export function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget?: boolean) {
|
|
231
|
-
if (target && source && isObject(target) && isArray(functionsToProxy)) {
|
|
232
|
-
arrForEach(functionsToProxy, (theFuncName) => {
|
|
233
|
-
if (isString(theFuncName)) {
|
|
234
|
-
proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return target;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Simpler helper to create a dynamic class that implements the interface and populates the values with the defaults.
|
|
244
|
-
* Only instance properties (hasOwnProperty) values are copied from the defaults to the new instance
|
|
245
|
-
* @param defaults - Simple helper
|
|
246
|
-
*/
|
|
247
|
-
export function createClassFromInterface<T>(defaults?: T) {
|
|
248
|
-
return class {
|
|
249
|
-
constructor() {
|
|
250
|
-
if (defaults) {
|
|
251
|
-
objForEachKey(defaults, (field, value) => {
|
|
252
|
-
(this as any)[field] = value;
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
} as new () => T;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* A helper function to assist with JIT performance for objects that have properties added / removed dynamically
|
|
261
|
-
* this is primarily for chromium based browsers and has limited effects on Firefox and none of IE. Only call this
|
|
262
|
-
* function after you have finished "updating" the object, calling this within loops reduces or defeats the benefits.
|
|
263
|
-
* This helps when iterating using for..in, objKeys() and objForEach()
|
|
264
|
-
* @param theObject - The object to be optimized if possible
|
|
265
|
-
*/
|
|
266
|
-
export function optimizeObject<T>(theObject: T): T {
|
|
267
|
-
// V8 Optimization to cause the JIT compiler to create a new optimized object for looking up the own properties
|
|
268
|
-
// primarily for object with <= 19 properties for >= 20 the effect is reduced or non-existent
|
|
269
|
-
if (theObject && ObjAssign) {
|
|
270
|
-
theObject = ObjClass(ObjAssign({}, theObject));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return theObject;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Pass in the objects to merge as arguments, this will only "merge" (extend) properties that are owned by the object.
|
|
278
|
-
* It will NOT merge inherited or non-enumerable properties.
|
|
279
|
-
* @param obj1 - object to merge. Set this argument to 'true' for a deep extend.
|
|
280
|
-
* @param obj2 - object to merge.
|
|
281
|
-
* @param obj3 - object to merge.
|
|
282
|
-
* @param obj4 - object to merge.
|
|
283
|
-
* @param obj5 - object to merge.
|
|
284
|
-
* @returns The extended first object.
|
|
285
|
-
*/
|
|
286
|
-
export function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6
|
|
287
|
-
export function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6
|
|
288
|
-
export function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1 | any, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6 {
|
|
289
|
-
// Variables
|
|
290
|
-
let theArgs = arguments as any;
|
|
291
|
-
let extended: T1 & T2 & T3 & T4 & T5 & T6 = theArgs[0] || {};
|
|
292
|
-
let argLen = theArgs.length;
|
|
293
|
-
let deep = false;
|
|
294
|
-
let idx = 1;
|
|
295
|
-
|
|
296
|
-
// Check for "Deep" flag
|
|
297
|
-
if (argLen > 0 && isBoolean(extended)) {
|
|
298
|
-
deep = extended;
|
|
299
|
-
extended = theArgs[idx] || {};
|
|
300
|
-
idx++;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Handle case when target is a string or something (possible in deep copy)
|
|
304
|
-
if (!isObject(extended)) {
|
|
305
|
-
extended = {} as T1 & T2 & T3 & T4 & T5 & T6;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Loop through each remaining object and conduct a merge
|
|
309
|
-
for (; idx < argLen; idx++ ) {
|
|
310
|
-
let arg = theArgs[idx];
|
|
311
|
-
let isArgArray = isArray(arg);
|
|
312
|
-
let isArgObj = isObject(arg);
|
|
313
|
-
for (let prop in arg) {
|
|
314
|
-
let propOk = (isArgArray && (prop in arg)) || (isArgObj && objHasOwn(arg, prop));
|
|
315
|
-
if (!propOk) {
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
let newValue = arg[prop];
|
|
320
|
-
let isNewArray: boolean;
|
|
321
|
-
|
|
322
|
-
// If deep merge and property is an object, merge properties
|
|
323
|
-
if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
|
|
324
|
-
// Grab the current value of the extended object
|
|
325
|
-
let clone = extended[prop];
|
|
326
|
-
|
|
327
|
-
if (isNewArray) {
|
|
328
|
-
if (!isArray(clone)) {
|
|
329
|
-
// We can't "merge" an array with a non-array so overwrite the original
|
|
330
|
-
clone = [];
|
|
331
|
-
}
|
|
332
|
-
} else if (!isPlainObject(clone)) {
|
|
333
|
-
// We can't "merge" an object with a non-object
|
|
334
|
-
clone = {};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Never move the original objects always clone them
|
|
338
|
-
newValue = objExtend(deep, clone, newValue);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// Assign the new (or previous) value (unless undefined)
|
|
342
|
-
if (newValue !== undefined) {
|
|
343
|
-
extended[prop] = newValue;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return extended;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
export const asString = asString21;
|
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { strShimFunction, strShimPrototype } from "@microsoft/applicationinsights-shims";
|
|
5
|
-
import { getInst, objHasOwnProperty } from "@nevware21/ts-utils";
|
|
6
|
-
import {
|
|
7
|
-
IInstrumentCallDetails, IInstrumentHook, IInstrumentHooks, IInstrumentHooksCallbacks, InstrumentorHooksCallback
|
|
8
|
-
} from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
|
|
9
|
-
import { _getObjProto } from "./HelperFuncs";
|
|
10
|
-
|
|
11
|
-
const aiInstrumentHooks = "_aiHooks";
|
|
12
|
-
|
|
13
|
-
const enum CallbackType {
|
|
14
|
-
Request = 0,
|
|
15
|
-
Response = 1,
|
|
16
|
-
HookError = 2,
|
|
17
|
-
FunctionError = 3
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const cbNames = [
|
|
21
|
-
"req", "rsp", "hkErr", "fnErr"
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
/** @ignore */
|
|
25
|
-
function _arrLoop<T>(arr:T[], fn:(value:T, idx:number) => boolean|number|void) {
|
|
26
|
-
if (arr) {
|
|
27
|
-
for (let lp = 0; lp < arr.length; lp++) {
|
|
28
|
-
if (fn(arr[lp], lp)) {
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** @ignore */
|
|
36
|
-
function _doCallbacks(hooks:IInstrumentHook[], callDetails: IInstrumentCallDetails, cbArgs:any[], hookCtx:any[], type:CallbackType): void {
|
|
37
|
-
if (type >= CallbackType.Request && type <= CallbackType.HookError) {
|
|
38
|
-
_arrLoop(hooks, (hook, idx) => {
|
|
39
|
-
let cbks = hook.cbks;
|
|
40
|
-
let cb:InstrumentorHooksCallback = cbks[cbNames[type]];
|
|
41
|
-
if (cb) {
|
|
42
|
-
|
|
43
|
-
// Set the specific hook context implementation using a lazy creation pattern
|
|
44
|
-
callDetails.ctx = () => {
|
|
45
|
-
let ctx = hookCtx[idx] = (hookCtx[idx] || {});
|
|
46
|
-
return ctx;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
cb.apply(callDetails.inst, cbArgs);
|
|
51
|
-
} catch (err) {
|
|
52
|
-
let orgEx = callDetails.err;
|
|
53
|
-
try {
|
|
54
|
-
// Report Hook error via the callback
|
|
55
|
-
let hookErrorCb:InstrumentorHooksCallback = cbks[cbNames[CallbackType.HookError]];
|
|
56
|
-
if (hookErrorCb) {
|
|
57
|
-
callDetails.err = err;
|
|
58
|
-
hookErrorCb.apply(callDetails.inst, cbArgs);
|
|
59
|
-
}
|
|
60
|
-
} catch(e) {
|
|
61
|
-
// Not much we can do here -- swallowing the exception to avoid crashing the hosting app
|
|
62
|
-
} finally {
|
|
63
|
-
// restore the original exception (if any)
|
|
64
|
-
callDetails.err = orgEx;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @ignore */
|
|
73
|
-
function _createFunctionHook(aiHook:IInstrumentHooks) {
|
|
74
|
-
|
|
75
|
-
// Define a temporary method that queues-up a the real method call
|
|
76
|
-
return function (this: any) {
|
|
77
|
-
let funcThis = this;
|
|
78
|
-
// Capture the original arguments passed to the method
|
|
79
|
-
let orgArgs = arguments as any;
|
|
80
|
-
let hooks = aiHook.h;
|
|
81
|
-
|
|
82
|
-
let funcArgs: IInstrumentCallDetails = {
|
|
83
|
-
name: aiHook.n,
|
|
84
|
-
inst: funcThis,
|
|
85
|
-
ctx: null,
|
|
86
|
-
set: _replaceArg
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
let hookCtx: any[] = [];
|
|
90
|
-
let cbArgs = _createArgs([funcArgs], orgArgs);
|
|
91
|
-
funcArgs.evt = getInst("event");
|
|
92
|
-
|
|
93
|
-
function _createArgs(target:any[], theArgs:any[]): any[] {
|
|
94
|
-
_arrLoop((theArgs as any), (arg) => {
|
|
95
|
-
target.push(arg);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return target;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function _replaceArg(idx:number, value:any) {
|
|
102
|
-
orgArgs = _createArgs([], orgArgs);
|
|
103
|
-
orgArgs[idx] = value;
|
|
104
|
-
cbArgs = _createArgs([funcArgs], orgArgs);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Call the pre-request hooks
|
|
108
|
-
_doCallbacks(hooks, funcArgs, cbArgs, hookCtx, CallbackType.Request);
|
|
109
|
-
|
|
110
|
-
// Call the original function was called
|
|
111
|
-
let theFunc = aiHook.f;
|
|
112
|
-
if (theFunc) {
|
|
113
|
-
try {
|
|
114
|
-
funcArgs.rslt = theFunc.apply(funcThis, orgArgs);
|
|
115
|
-
} catch (err) {
|
|
116
|
-
// Report the request callback
|
|
117
|
-
funcArgs.err = err;
|
|
118
|
-
_doCallbacks(hooks, funcArgs, cbArgs, hookCtx, CallbackType.FunctionError);
|
|
119
|
-
|
|
120
|
-
// rethrow the original exception so anyone listening for it can catch the exception
|
|
121
|
-
throw err;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Call the post-request hooks
|
|
126
|
-
_doCallbacks(hooks, funcArgs, cbArgs, hookCtx, CallbackType.Response);
|
|
127
|
-
|
|
128
|
-
return funcArgs.rslt;
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/** @ignore */
|
|
134
|
-
function _getOwner(target:any, name:string, checkPrototype: boolean, checkParentProto: boolean): any {
|
|
135
|
-
let owner = null;
|
|
136
|
-
if (target) {
|
|
137
|
-
if (objHasOwnProperty(target, name)) {
|
|
138
|
-
owner = target;
|
|
139
|
-
} else if (checkPrototype) {
|
|
140
|
-
owner = _getOwner(_getObjProto(target), name, checkParentProto, false);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return owner;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Intercept the named prototype functions for the target class / object
|
|
149
|
-
* @param target - The target object
|
|
150
|
-
* @param funcName - The function name
|
|
151
|
-
* @param callbacks - The callbacks to configure and call whenever the function is called
|
|
152
|
-
*/
|
|
153
|
-
export function InstrumentProto(target:any, funcName:string, callbacks: IInstrumentHooksCallbacks): IInstrumentHook {
|
|
154
|
-
if (target) {
|
|
155
|
-
return InstrumentFunc(target[strShimPrototype], funcName, callbacks, false);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Intercept the named prototype functions for the target class / object
|
|
163
|
-
* @param target - The target object
|
|
164
|
-
* @param funcNames - The function names to intercept and call
|
|
165
|
-
* @param callbacks - The callbacks to configure and call whenever the function is called
|
|
166
|
-
*/
|
|
167
|
-
export function InstrumentProtos(target:any, funcNames:string[], callbacks: IInstrumentHooksCallbacks): IInstrumentHook[] {
|
|
168
|
-
if (target) {
|
|
169
|
-
return InstrumentFuncs(target[strShimPrototype], funcNames, callbacks, false);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function _createInstrumentHook(owner: any, funcName: string, fn: any, callbacks: IInstrumentHooksCallbacks) {
|
|
176
|
-
let aiHook: IInstrumentHooks = fn && fn[aiInstrumentHooks];
|
|
177
|
-
if (!aiHook) {
|
|
178
|
-
// Only hook the function once
|
|
179
|
-
aiHook = {
|
|
180
|
-
i: 0,
|
|
181
|
-
n: funcName,
|
|
182
|
-
f: fn,
|
|
183
|
-
h: []
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
// Override (hook) the original function
|
|
187
|
-
let newFunc = _createFunctionHook(aiHook);
|
|
188
|
-
newFunc[aiInstrumentHooks] = aiHook; // Tag and store the function hooks
|
|
189
|
-
owner[funcName] = newFunc;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const theHook: IInstrumentHook = {
|
|
193
|
-
// tslint:disable:object-literal-shorthand
|
|
194
|
-
id: aiHook.i,
|
|
195
|
-
cbks: callbacks,
|
|
196
|
-
rm: function () {
|
|
197
|
-
// DO NOT Use () => { shorthand for the function as the this gets replaced
|
|
198
|
-
// with the outer this and not the this for theHook instance.
|
|
199
|
-
let id = this.id;
|
|
200
|
-
_arrLoop(aiHook.h, (hook, idx) => {
|
|
201
|
-
if (hook.id === id) {
|
|
202
|
-
aiHook.h.splice(idx, 1);
|
|
203
|
-
return 1;
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
// tslint:enable:object-literal-shorthand
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
aiHook.i++;
|
|
211
|
-
aiHook.h.push(theHook);
|
|
212
|
-
|
|
213
|
-
return theHook;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Intercept the named prototype functions for the target class / object
|
|
218
|
-
* @param target - The target object
|
|
219
|
-
* @param funcName - The function name
|
|
220
|
-
* @param callbacks - The callbacks to configure and call whenever the function is called
|
|
221
|
-
* @param checkPrototype - If the function doesn't exist on the target should it attempt to hook the prototype function
|
|
222
|
-
* @param checkParentProto - If the function doesn't exist on the target or it's prototype should it attempt to hook the parent's prototype
|
|
223
|
-
*/
|
|
224
|
-
export function InstrumentFunc(target:any, funcName:string, callbacks: IInstrumentHooksCallbacks, checkPrototype: boolean = true, checkParentProto?: boolean): IInstrumentHook {
|
|
225
|
-
if (target && funcName && callbacks) {
|
|
226
|
-
let owner = _getOwner(target, funcName, checkPrototype, checkParentProto);
|
|
227
|
-
if (owner) {
|
|
228
|
-
let fn = owner[funcName]
|
|
229
|
-
if (typeof fn === strShimFunction) {
|
|
230
|
-
return _createInstrumentHook(owner, funcName, fn, callbacks);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Intercept the named functions for the target class / object
|
|
240
|
-
* @param target - The target object
|
|
241
|
-
* @param funcNames - The function names to intercept and call
|
|
242
|
-
* @param callbacks - The callbacks to configure and call whenever the function is called
|
|
243
|
-
* @param checkPrototype - If the function doesn't exist on the target should it attempt to hook the prototype function
|
|
244
|
-
* @param checkParentProto - If the function doesn't exist on the target or it's prototype should it attempt to hook the parent's prototype
|
|
245
|
-
*/
|
|
246
|
-
export function InstrumentFuncs(target:any, funcNames:string[], callbacks: IInstrumentHooksCallbacks, checkPrototype:boolean = true, checkParentProto?: boolean): IInstrumentHook[] {
|
|
247
|
-
let hooks: IInstrumentHook[] = null;
|
|
248
|
-
_arrLoop(funcNames, (funcName) => {
|
|
249
|
-
let hook = InstrumentFunc(target, funcName, callbacks, checkPrototype, checkParentProto);
|
|
250
|
-
if (hook) {
|
|
251
|
-
if (!hooks) {
|
|
252
|
-
hooks = [];
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
hooks.push(hook);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
return hooks;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Add an instrumentation hook to the provided named "event" for the target class / object, this doesn't check whether the
|
|
264
|
-
* named "event" is in fact a function and just assigns the instrumentation hook to the target[evtName]
|
|
265
|
-
* @param target - The target object
|
|
266
|
-
* @param evtName - The name of the event
|
|
267
|
-
* @param callbacks - The callbacks to configure and call whenever the function is called
|
|
268
|
-
* @param checkPrototype - If the function doesn't exist on the target should it attempt to hook the prototype function
|
|
269
|
-
* @param checkParentProto - If the function doesn't exist on the target or it's prototype should it attempt to hook the parent's prototype
|
|
270
|
-
*/
|
|
271
|
-
export function InstrumentEvent(target: any, evtName: string, callbacks: IInstrumentHooksCallbacks, checkPrototype?: boolean, checkParentProto?: boolean): IInstrumentHook {
|
|
272
|
-
if (target && evtName && callbacks) {
|
|
273
|
-
let owner = _getOwner(target, evtName, checkPrototype, checkParentProto) || target;
|
|
274
|
-
if (owner) {
|
|
275
|
-
return _createInstrumentHook(owner, evtName, owner[evtName], callbacks);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
// ###################################################################################################################################################
|
|
5
|
-
// Note: DON'T Export these const from the package as we are still targeting IE/ES5 this will export a mutable variables that someone could change ###
|
|
6
|
-
// ###################################################################################################################################################
|
|
7
|
-
|
|
8
|
-
export const UNDEFINED_VALUE: any = undefined;
|
|
9
|
-
export const STR_EMPTY = "";
|
|
10
|
-
export const STR_CHANNELS = "channels";
|
|
11
|
-
export const STR_CORE = "core";
|
|
12
|
-
export const STR_CREATE_PERF_MGR = "createPerfMgr";
|
|
13
|
-
export const STR_DISABLED = "disabled";
|
|
14
|
-
export const STR_EXTENSION_CONFIG = "extensionConfig";
|
|
15
|
-
export const STR_EXTENSIONS = "extensions";
|
|
16
|
-
export const STR_PROCESS_TELEMETRY = "processTelemetry";
|
|
17
|
-
export const STR_PRIORITY = "priority";
|
|
18
|
-
|
|
19
|
-
export const STR_EVENTS_SENT = "eventsSent";
|
|
20
|
-
export const STR_EVENTS_DISCARDED = "eventsDiscarded";
|
|
21
|
-
export const STR_EVENTS_SEND_REQUEST = "eventsSendRequest";
|
|
22
|
-
export const STR_PERF_EVENT = "perfEvent";
|
|
23
|
-
|
|
24
|
-
export const STR_ERROR_TO_CONSOLE = "errorToConsole";
|
|
25
|
-
export const STR_WARN_TO_CONSOLE = "warnToConsole";
|
|
26
|
-
|
|
27
|
-
export const STR_GET_PERF_MGR = "getPerfMgr";
|
|
28
|
-
export const STR_DOMAIN = "domain";
|
|
29
|
-
export const STR_PATH = "path";
|
|
30
|
-
|
|
31
|
-
export const STR_NOT_DYNAMIC_ERROR = "Not dynamic - ";
|