@microsoft/applicationinsights-core-js 3.0.0-beta.2303-06 → 3.0.0-beta.2303-10
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 +115 -98
- 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 +170 -4
- package/dist/applicationinsights-core-js.api.md +10 -2
- package/dist/applicationinsights-core-js.d.ts +54 -3
- package/dist/applicationinsights-core-js.js +115 -98
- 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 +54 -3
- package/dist-esm/Config/ConfigDefaultHelpers.js +1 -1
- package/dist-esm/Config/ConfigDefaults.js +1 -1
- package/dist-esm/Config/DynamicConfig.js +13 -13
- package/dist-esm/Config/DynamicConfig.js.map +1 -1
- package/dist-esm/Config/DynamicProperty.js +14 -19
- package/dist-esm/Config/DynamicProperty.js.map +1 -1
- package/dist-esm/Config/DynamicState.js +1 -1
- package/dist-esm/Config/DynamicSupport.js +114 -1
- package/dist-esm/Config/DynamicSupport.js.map +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 +42 -34
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +23 -19
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +8 -28
- 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 +10 -12
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +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 +11 -9
- package/dist-esm/JavaScriptSDK/PerfManager.js.map +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/IChannelControlsHost.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControlsHost.js.map +1 -0
- 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 +4 -6
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/applicationinsights-core-js.js +2 -2
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +1 -1
- package/types/Config/DynamicProperty.d.ts +1 -1
- package/types/Config/DynamicSupport.d.ts +67 -0
- package/types/JavaScriptSDK.Interfaces/IChannelControlsHost.d.ts +9 -0
- package/types/JavaScriptSDK.Interfaces/IConfiguration.d.ts +2 -2
- package/types/__DynamicConstants.d.ts +0 -2
- package/types/applicationinsights-core-js.d.ts +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Microsoft Application Insights Core Javascript SDK, 3.0.0-beta.2303-
|
|
2
|
+
* Microsoft Application Insights Core Javascript SDK, 3.0.0-beta.2303-10
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* Microsoft Application Insights Team
|
|
@@ -395,6 +395,49 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
395
395
|
protected _addHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Mark the provided value so that if it's included into the configuration it will NOT have
|
|
400
|
+
* its properties converted into a dynamic (reactive) object. If the object is not a plain object
|
|
401
|
+
* or an array (ie. a class) this function has not affect as only Objects and Arrays are converted
|
|
402
|
+
* into dynamic objects in the dynamic configuration.
|
|
403
|
+
*
|
|
404
|
+
* When you have tagged a value as both {@link forceDynamicConversion} and blocked force will take precedence.
|
|
405
|
+
*
|
|
406
|
+
* You should only need to use this function, if you are creating dynamic "classes" from objects
|
|
407
|
+
* which confirm to the require interface. A common case for this is during unit testing where it's
|
|
408
|
+
* easier to create mock extensions.
|
|
409
|
+
*
|
|
410
|
+
* If `value` is falsy (null / undefined / 0 / empty string etc) it will not be tagged and
|
|
411
|
+
* if there is an exception adding the property to the value (because its frozen etc) the
|
|
412
|
+
* exception will be swallowed
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```ts
|
|
416
|
+
* // This is a valid "extension", but it is technically an object
|
|
417
|
+
* // So when included in the config.extensions it WILL be cloned and then
|
|
418
|
+
* // converted into a dynamic object, where all of its properties will become
|
|
419
|
+
* // get/set object properties and will be tracked. While this WILL still
|
|
420
|
+
* // function, when attempt to use a mocking framework on top of this the
|
|
421
|
+
* // functions are now technically get accessors which return a function
|
|
422
|
+
* // and this can cause some mocking frameworks to fail.
|
|
423
|
+
* let mockChannel = {
|
|
424
|
+
* pause: () => { },
|
|
425
|
+
* resume: () => { },
|
|
426
|
+
* teardown: () => { },
|
|
427
|
+
* flush: (async: any, callBack: any) => { },
|
|
428
|
+
* processTelemetry: (env: any) => { },
|
|
429
|
+
* setNextPlugin: (next: any) => { },
|
|
430
|
+
* initialize: (config: any, core: any, extensions: any) => { },
|
|
431
|
+
* identifier: "testChannel",
|
|
432
|
+
* priority: 1003
|
|
433
|
+
* };
|
|
434
|
+
* ```
|
|
435
|
+
* @param value - The object that you want to block from being converted into a
|
|
436
|
+
* trackable dynamic object
|
|
437
|
+
* @returns The original value
|
|
438
|
+
*/
|
|
439
|
+
export declare function blockDynamicConversion<T>(value: T): T;
|
|
440
|
+
|
|
398
441
|
/**
|
|
399
442
|
* Helper which returns an IConfigDefaultCheck instance that will validate and convert the user
|
|
400
443
|
* provided value to a boolean from a string or boolean value
|
|
@@ -1134,6 +1177,14 @@ export declare interface IChannelControls extends ITelemetryPlugin {
|
|
|
1134
1177
|
flush?(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
|
|
1135
1178
|
}
|
|
1136
1179
|
|
|
1180
|
+
export declare interface IChannelControlsHost extends IChannelControls {
|
|
1181
|
+
/**
|
|
1182
|
+
* Get and return the named channel instance (if present) from the queues
|
|
1183
|
+
* @param pluginIdentifier - The identifier name of the plugin
|
|
1184
|
+
*/
|
|
1185
|
+
getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1137
1188
|
/**
|
|
1138
1189
|
* The type to identify whether the default value should be applied in preference to the provided value.
|
|
1139
1190
|
*/
|
|
@@ -1261,12 +1312,12 @@ export declare interface IConfiguration {
|
|
|
1261
1312
|
/**
|
|
1262
1313
|
* Additional plugins that should be loaded by core at runtime
|
|
1263
1314
|
*/
|
|
1264
|
-
extensions?: ITelemetryPlugin[];
|
|
1315
|
+
readonly extensions?: ITelemetryPlugin[];
|
|
1265
1316
|
/**
|
|
1266
1317
|
* Channel queues that is setup by caller in desired order.
|
|
1267
1318
|
* If channels are provided here, core will ignore any channels that are already setup, example if there is a SKU with an initialized channel
|
|
1268
1319
|
*/
|
|
1269
|
-
channels?: IChannelControls[][];
|
|
1320
|
+
readonly channels?: IChannelControls[][];
|
|
1270
1321
|
/**
|
|
1271
1322
|
* @type {boolean}
|
|
1272
1323
|
* Flag that disables the Instrumentation Key validation.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2303-
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2303-10
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
import { dumpObj,
|
|
7
|
+
import { dumpObj, objDefine, objForEachKey } from "@nevware21/ts-utils";
|
|
8
8
|
import { createUniqueNamespace } from "../JavaScriptSDK/DataCacheHelper";
|
|
9
9
|
import { STR_NOT_DYNAMIC_ERROR, STR_WARN_TO_CONSOLE } from "../JavaScriptSDK/InternalConstants";
|
|
10
|
-
import {
|
|
10
|
+
import { _DYN_LOGGER, _DYN_NOTIFY, _DYN_RD_ONLY, _DYN_SET_DF, _DYN_THROW_INTERNAL, _DYN_WATCH } from "../__DynamicConstants";
|
|
11
11
|
import { _applyDefaultValue } from "./ConfigDefaults";
|
|
12
12
|
import { _makeDynamicObject, _setDynamicProperty } from "./DynamicProperty";
|
|
13
13
|
import { _createState } from "./DynamicState";
|
|
@@ -39,7 +39,7 @@ function _createAndUseHandler(state, configHandler) {
|
|
|
39
39
|
* @returns The existing dynamic handler or a new instance with the provided config values
|
|
40
40
|
*/
|
|
41
41
|
function _createDynamicHandler(logger, target, inPlace) {
|
|
42
|
-
var _a
|
|
42
|
+
var _a;
|
|
43
43
|
var dynamicHandler = getDynamicConfigHandler(target);
|
|
44
44
|
if (dynamicHandler) {
|
|
45
45
|
// The passed config is already dynamic so return it's tracker
|
|
@@ -52,7 +52,7 @@ function _createDynamicHandler(logger, target, inPlace) {
|
|
|
52
52
|
theState[_DYN_NOTIFY /* @min:%2enotify */]();
|
|
53
53
|
}
|
|
54
54
|
function _setValue(target, name, value) {
|
|
55
|
-
return _setDynamicProperty(theState, target, name, value);
|
|
55
|
+
return _setDynamicProperty(theState, target, name, value)[name];
|
|
56
56
|
}
|
|
57
57
|
function _watch(configHandler) {
|
|
58
58
|
return _createAndUseHandler(theState, configHandler);
|
|
@@ -62,11 +62,11 @@ function _createDynamicHandler(logger, target, inPlace) {
|
|
|
62
62
|
}
|
|
63
63
|
function _ref(target, name) {
|
|
64
64
|
// Make sure it's dynamic and mark as referenced with it's current value
|
|
65
|
-
return _setDynamicProperty(theState, target, name, target[name], true);
|
|
65
|
+
return _setDynamicProperty(theState, target, name, target[name], true)[name];
|
|
66
66
|
}
|
|
67
67
|
function _rdOnly(target, name) {
|
|
68
68
|
// Make sure it's dynamic and mark as readonly with it's current value
|
|
69
|
-
return _setDynamicProperty(theState, target, name, target[name], false, true);
|
|
69
|
+
return _setDynamicProperty(theState, target, name, target[name], false, true)[name];
|
|
70
70
|
}
|
|
71
71
|
function _applyDefaults(theConfig, defaultValues) {
|
|
72
72
|
if (defaultValues) {
|
|
@@ -91,12 +91,12 @@ function _createDynamicHandler(logger, target, inPlace) {
|
|
|
91
91
|
_a[_DYN_RD_ONLY /* @min:rdOnly */] = _rdOnly,
|
|
92
92
|
_a._block = _block,
|
|
93
93
|
_a);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
objDefine(cfgHandler, "uid", {
|
|
95
|
+
c: false,
|
|
96
|
+
e: false,
|
|
97
|
+
w: false,
|
|
98
|
+
v: uid
|
|
99
|
+
});
|
|
100
100
|
theState = _createState(cfgHandler);
|
|
101
101
|
// Setup tracking for all defined default keys
|
|
102
102
|
_makeDynamicObject(theState, newTarget);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicConfig.js.map","sources":["DynamicConfig.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { dumpObj,
|
|
1
|
+
{"version":3,"file":"DynamicConfig.js.map","sources":["DynamicConfig.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { dumpObj, objDefine, objForEachKey } from \"@nevware21/ts-utils\";\r\nimport { createUniqueNamespace } from \"../JavaScriptSDK/DataCacheHelper\";\r\nimport { STR_NOT_DYNAMIC_ERROR, STR_WARN_TO_CONSOLE } from \"../JavaScriptSDK/InternalConstants\";\r\nimport { _DYN_LOGGER, _DYN_NOTIFY, _DYN_RD_ONLY, _DYN_SET_DF, _DYN_THROW_INTERNAL, _DYN_WATCH } from \"../__DynamicConstants\";\r\nimport { _applyDefaultValue } from \"./ConfigDefaults\";\r\nimport { _makeDynamicObject, _setDynamicProperty } from \"./DynamicProperty\";\r\nimport { _createState } from \"./DynamicState\";\r\nimport { CFG_HANDLER_LINK, _cfgDeepCopy, getDynamicConfigHandler, throwInvalidAccess } from \"./DynamicSupport\";\r\n/**\r\n * Identifies a function which will be re-called whenever any of it's accessed configuration values\r\n * change.\r\n * @param configHandler - The callback that will be called for the initial request and then whenever any\r\n * accessed configuration changes are identified.\r\n */\r\nfunction _createAndUseHandler(state, configHandler) {\r\n var handler = {\r\n fn: configHandler,\r\n rm: function () {\r\n // Clear all references to the handler so it can be garbage collected\r\n // This will also cause this handler to never get called and eventually removed\r\n handler.fn = null;\r\n state = null;\r\n configHandler = null;\r\n }\r\n };\r\n state.use(handler, configHandler);\r\n return handler;\r\n}\r\n/**\r\n * Creates the dynamic config handler and associates with the target config as the root object\r\n * @param target - The config that you want to be root of the dynamic config\r\n * @param inPlace - Should the passed config be converted in-place or a new proxy returned\r\n * @returns The existing dynamic handler or a new instance with the provided config values\r\n */\r\nfunction _createDynamicHandler(logger, target, inPlace) {\r\n var _a;\r\n var dynamicHandler = getDynamicConfigHandler(target);\r\n if (dynamicHandler) {\r\n // The passed config is already dynamic so return it's tracker\r\n return dynamicHandler;\r\n }\r\n var uid = createUniqueNamespace(\"dyncfg\", true);\r\n var newTarget = (target && inPlace !== false) ? target : _cfgDeepCopy(target);\r\n var theState;\r\n function _notifyWatchers() {\r\n theState[_DYN_NOTIFY /* @min:%2enotify */]();\r\n }\r\n function _setValue(target, name, value) {\r\n return _setDynamicProperty(theState, target, name, value)[name];\r\n }\r\n function _watch(configHandler) {\r\n return _createAndUseHandler(theState, configHandler);\r\n }\r\n function _block(configHandler) {\r\n theState.use(null, configHandler);\r\n }\r\n function _ref(target, name) {\r\n // Make sure it's dynamic and mark as referenced with it's current value\r\n return _setDynamicProperty(theState, target, name, target[name], true)[name];\r\n }\r\n function _rdOnly(target, name) {\r\n // Make sure it's dynamic and mark as readonly with it's current value\r\n return _setDynamicProperty(theState, target, name, target[name], false, true)[name];\r\n }\r\n function _applyDefaults(theConfig, defaultValues) {\r\n if (defaultValues) {\r\n // Resolve/apply the defaults\r\n objForEachKey(defaultValues, function (name, value) {\r\n // Sets the value and makes it dynamic (if it doesn't already exist)\r\n _applyDefaultValue(cfgHandler, theConfig, name, value);\r\n });\r\n }\r\n return theConfig;\r\n }\r\n var cfgHandler = (_a = {\r\n uid: null,\r\n cfg: newTarget\r\n },\r\n _a[_DYN_LOGGER /* @min:logger */] = logger,\r\n _a[_DYN_NOTIFY /* @min:notify */] = _notifyWatchers,\r\n _a.set = _setValue,\r\n _a[_DYN_SET_DF /* @min:setDf */] = _applyDefaults,\r\n _a[_DYN_WATCH /* @min:watch */] = _watch,\r\n _a.ref = _ref,\r\n _a[_DYN_RD_ONLY /* @min:rdOnly */] = _rdOnly,\r\n _a._block = _block,\r\n _a);\r\n objDefine(cfgHandler, \"uid\", {\r\n c: false,\r\n e: false,\r\n w: false,\r\n v: uid\r\n });\r\n theState = _createState(cfgHandler);\r\n // Setup tracking for all defined default keys\r\n _makeDynamicObject(theState, newTarget);\r\n return cfgHandler;\r\n}\r\n/**\r\n * Log an invalid access message to the console\r\n * @param message\r\n */\r\nfunction _logInvalidAccess(logger, message) {\r\n if (logger) {\r\n logger[STR_WARN_TO_CONSOLE /* @min:%2ewarnToConsole */](message);\r\n logger[_DYN_THROW_INTERNAL /* @min:%2ethrowInternal */](2 /* eLoggingSeverity.WARNING */, 108 /* _eInternalMessageId.DynamicConfigException */, message);\r\n }\r\n else {\r\n // We don't have a logger so just throw an exception\r\n throwInvalidAccess(message);\r\n }\r\n}\r\n/**\r\n * Create or return a dynamic version of the passed config, if it is not already dynamic\r\n * @param config - The config to be converted into a dynamic config\r\n * @param defaultConfig - The default values to apply on the config if the properties don't already exist\r\n * @param inPlace - Should the config be converted in-place into a dynamic config or a new instance returned, defaults to true\r\n * @returns The dynamic config handler for the config (whether new or existing)\r\n */\r\nexport function createDynamicConfig(config, defaultConfig, logger, inPlace) {\r\n var dynamicHandler = _createDynamicHandler(logger, config || {}, inPlace);\r\n if (defaultConfig) {\r\n dynamicHandler[_DYN_SET_DF /* @min:%2esetDf */](dynamicHandler.cfg, defaultConfig);\r\n }\r\n return dynamicHandler;\r\n}\r\n/**\r\n * Watch and track changes for accesses to the current config, the provided config MUST already be\r\n * a dynamic config or a child accessed via the dynamic config\r\n * @param config\r\n * @param configHandler\r\n * @param logger - The logger instance to use if there is no existing handler\r\n * @returns A watcher handler instance that can be used to remove itself when being unloaded\r\n * @throws TypeError if the provided config is not a dynamic config instance\r\n */\r\nexport function onConfigChange(config, configHandler, logger) {\r\n var handler = config[CFG_HANDLER_LINK] || config;\r\n if (handler.cfg && (handler.cfg === config || handler.cfg[CFG_HANDLER_LINK] === handler)) {\r\n return handler[_DYN_WATCH /* @min:%2ewatch */](configHandler);\r\n }\r\n _logInvalidAccess(logger, STR_NOT_DYNAMIC_ERROR + dumpObj(config));\r\n createDynamicConfig(config, null, logger)[_DYN_WATCH /* @min:%2ewatch */](configHandler);\r\n}\r\n//# sourceMappingURL=DynamicConfig.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2303-
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2303-10
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
import { arrForEach, arrIndexOf, dumpObj, isArray,
|
|
7
|
+
import { arrForEach, arrIndexOf, dumpObj, isArray, objDefine, objDefineProp, objForEachKey, objGetOwnPropertyDescriptor } from "@nevware21/ts-utils";
|
|
8
8
|
import { UNDEFINED_VALUE } from "../JavaScriptSDK/InternalConstants";
|
|
9
|
-
import { _DYN_APPLY,
|
|
10
|
-
import { CFG_HANDLER_LINK, throwInvalidAccess } from "./DynamicSupport";
|
|
9
|
+
import { _DYN_APPLY, _DYN_PUSH, _DYN_SPLICE } from "../__DynamicConstants";
|
|
10
|
+
import { CFG_HANDLER_LINK, _canMakeDynamic, throwInvalidAccess } from "./DynamicSupport";
|
|
11
11
|
var arrayMethodsToPatch = [
|
|
12
12
|
"push",
|
|
13
13
|
"pop",
|
|
@@ -63,7 +63,7 @@ function _makeDynamicProperty(state, theConfig, name, value) {
|
|
|
63
63
|
var isObjectOrArray = false;
|
|
64
64
|
function _getProperty() {
|
|
65
65
|
if (checkDynamic) {
|
|
66
|
-
isObjectOrArray = isObjectOrArray || (value
|
|
66
|
+
isObjectOrArray = isObjectOrArray || _canMakeDynamic(value);
|
|
67
67
|
// Make sure that if it's an object that we make it dynamic
|
|
68
68
|
if (value && !value[CFG_HANDLER_LINK] && isObjectOrArray) {
|
|
69
69
|
// It doesn't look like it's already dynamic so lets make sure it's converted the object into a dynamic Config as well
|
|
@@ -92,7 +92,7 @@ function _makeDynamicProperty(state, theConfig, name, value) {
|
|
|
92
92
|
throwInvalidAccess("[" + name + "] is read-only:" + dumpObj(theConfig));
|
|
93
93
|
}
|
|
94
94
|
if (checkDynamic) {
|
|
95
|
-
isObjectOrArray = isObjectOrArray || (value
|
|
95
|
+
isObjectOrArray = isObjectOrArray || _canMakeDynamic(value);
|
|
96
96
|
checkDynamic = false;
|
|
97
97
|
}
|
|
98
98
|
// The value must be a plain object or an array to enforce the reference (in-place updates)
|
|
@@ -127,7 +127,7 @@ function _makeDynamicProperty(state, theConfig, name, value) {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
if (newValue !== value) {
|
|
130
|
-
var newIsObjectOrArray = newValue && (
|
|
130
|
+
var newIsObjectOrArray = newValue && _canMakeDynamic(newValue);
|
|
131
131
|
if (!isReferenced && newIsObjectOrArray) {
|
|
132
132
|
// As the newValue is an object/array lets preemptively make it dynamic
|
|
133
133
|
_makeDynamicObject(state, newValue);
|
|
@@ -140,9 +140,7 @@ function _makeDynamicProperty(state, theConfig, name, value) {
|
|
|
140
140
|
state.add(detail);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
|
|
144
|
-
// Return the dynamic reference
|
|
145
|
-
return _getProperty();
|
|
143
|
+
objDefine(theConfig, detail.n, { g: _getProperty, s: _setProperty });
|
|
146
144
|
}
|
|
147
145
|
export function _setDynamicProperty(state, target, name, value, inPlace, rdOnly) {
|
|
148
146
|
if (target) {
|
|
@@ -150,7 +148,7 @@ export function _setDynamicProperty(state, target, name, value, inPlace, rdOnly)
|
|
|
150
148
|
var getter = _getOwnPropGetter(target, name);
|
|
151
149
|
var isDynamic = getter && !!getter[state.prop];
|
|
152
150
|
if (!isDynamic) {
|
|
153
|
-
|
|
151
|
+
_makeDynamicProperty(state, target, name, value);
|
|
154
152
|
if (inPlace || rdOnly) {
|
|
155
153
|
getter = _getOwnPropGetter(target, name);
|
|
156
154
|
}
|
|
@@ -167,10 +165,9 @@ export function _setDynamicProperty(state, target, name, value, inPlace, rdOnly)
|
|
|
167
165
|
getter[state.ro] = rdOnly;
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
|
-
return
|
|
168
|
+
return target;
|
|
171
169
|
}
|
|
172
170
|
export function _makeDynamicObject(state, target) {
|
|
173
|
-
var _a;
|
|
174
171
|
// Assign target with new value properties (converting into dynamic properties in the process)
|
|
175
172
|
objForEachKey(target, function (key, value) {
|
|
176
173
|
// Assign and/or make the property dynamic
|
|
@@ -178,13 +175,11 @@ export function _makeDynamicObject(state, target) {
|
|
|
178
175
|
});
|
|
179
176
|
if (!target[CFG_HANDLER_LINK]) {
|
|
180
177
|
// Link the config back to the dynamic config details
|
|
181
|
-
objDefineProp(target, CFG_HANDLER_LINK,
|
|
182
|
-
|
|
183
|
-
_a[_DYN_ENUMERABLE /* @min:enumerable */] = false,
|
|
184
|
-
_a.get = function () {
|
|
178
|
+
objDefineProp(target, CFG_HANDLER_LINK, {
|
|
179
|
+
get: function () {
|
|
185
180
|
return state.hdlr;
|
|
186
|
-
}
|
|
187
|
-
|
|
181
|
+
}
|
|
182
|
+
});
|
|
188
183
|
_patchArray(state, target);
|
|
189
184
|
}
|
|
190
185
|
return target;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicProperty.js.map","sources":["DynamicProperty.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { arrForEach, arrIndexOf, dumpObj, isArray,
|
|
1
|
+
{"version":3,"file":"DynamicProperty.js.map","sources":["DynamicProperty.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { arrForEach, arrIndexOf, dumpObj, isArray, objDefine, objDefineProp, objForEachKey, objGetOwnPropertyDescriptor } from \"@nevware21/ts-utils\";\r\nimport { UNDEFINED_VALUE } from \"../JavaScriptSDK/InternalConstants\";\r\nimport { _DYN_APPLY, _DYN_PUSH, _DYN_SPLICE } from \"../__DynamicConstants\";\r\nimport { CFG_HANDLER_LINK, _canMakeDynamic, throwInvalidAccess } from \"./DynamicSupport\";\r\nvar arrayMethodsToPatch = [\r\n \"push\",\r\n \"pop\",\r\n \"shift\",\r\n \"unshift\",\r\n \"splice\"\r\n];\r\nfunction _patchArray(state, target) {\r\n if (isArray(target)) {\r\n // Monkey Patch the methods that might change the array\r\n arrForEach(arrayMethodsToPatch, function (method) {\r\n var orgMethod = target[method];\r\n target[method] = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n var result = orgMethod[_DYN_APPLY /* @min:%2eapply */](this, args);\r\n // items may be added, removed or moved so need to make some new dynamic properties\r\n _makeDynamicObject(state, target);\r\n return result;\r\n };\r\n });\r\n }\r\n}\r\nfunction _getOwnPropGetter(target, name) {\r\n var propDesc = objGetOwnPropertyDescriptor(target, name);\r\n return propDesc && propDesc.get;\r\n}\r\nfunction _makeDynamicProperty(state, theConfig, name, value) {\r\n // Does not appear to be dynamic so lets make it so\r\n var detail = {\r\n n: name,\r\n h: [],\r\n trk: function (handler) {\r\n if (handler && handler.fn) {\r\n if (arrIndexOf(detail.h, handler) === -1) {\r\n // Add this handler to the collection that should be notified when the value changes\r\n detail.h[_DYN_PUSH /* @min:%2epush */](handler);\r\n }\r\n state.trk(handler, detail);\r\n }\r\n },\r\n clr: function (handler) {\r\n var idx = arrIndexOf(detail.h, handler);\r\n if (idx !== -1) {\r\n detail.h[_DYN_SPLICE /* @min:%2esplice */](idx, 1);\r\n }\r\n }\r\n };\r\n // Flag to optimize lookup response time by avoiding additional function calls\r\n var checkDynamic = true;\r\n var isObjectOrArray = false;\r\n function _getProperty() {\r\n if (checkDynamic) {\r\n isObjectOrArray = isObjectOrArray || _canMakeDynamic(value);\r\n // Make sure that if it's an object that we make it dynamic\r\n if (value && !value[CFG_HANDLER_LINK] && isObjectOrArray) {\r\n // It doesn't look like it's already dynamic so lets make sure it's converted the object into a dynamic Config as well\r\n value = _makeDynamicObject(state, value);\r\n }\r\n // If it needed to be converted it now has been\r\n checkDynamic = false;\r\n }\r\n // If there is an active handler then add it to the tracking set of handlers\r\n var activeHandler = state.act;\r\n if (activeHandler) {\r\n detail.trk(activeHandler);\r\n }\r\n return value;\r\n }\r\n // Tag this getter as our dynamic property and provide shortcut for notifying a change\r\n _getProperty[state.prop] = {\r\n chng: function () {\r\n state.add(detail);\r\n }\r\n };\r\n function _setProperty(newValue) {\r\n if (value !== newValue) {\r\n if (!!_getProperty[state.ro] && !state.upd) {\r\n // field is marked as readonly so return false\r\n throwInvalidAccess(\"[\" + name + \"] is read-only:\" + dumpObj(theConfig));\r\n }\r\n if (checkDynamic) {\r\n isObjectOrArray = isObjectOrArray || _canMakeDynamic(value);\r\n checkDynamic = false;\r\n }\r\n // The value must be a plain object or an array to enforce the reference (in-place updates)\r\n var isReferenced = isObjectOrArray && _getProperty[state.rf];\r\n if (isObjectOrArray) {\r\n // We are about to replace a plain object or an array\r\n if (isReferenced) {\r\n // Reassign the properties from the current value to the same properties from the newValue\r\n // This will set properties not in the newValue to undefined\r\n objForEachKey(value, function (key) {\r\n value[key] = newValue ? newValue[key] : UNDEFINED_VALUE;\r\n });\r\n // Now assign / re-assign value with all of the keys from newValue\r\n objForEachKey(newValue, function (key, theValue) {\r\n _setDynamicProperty(state, value, key, theValue);\r\n });\r\n // Now drop newValue so when we assign value later it keeps the existing reference\r\n newValue = value;\r\n }\r\n else if (value && value[CFG_HANDLER_LINK]) {\r\n // As we are replacing the value, if it's already dynamic then we need to notify the listeners\r\n // for every property it has already\r\n objForEachKey(value, function (key) {\r\n // Check if the value is dynamic\r\n var getter = _getOwnPropGetter(value, key);\r\n if (getter) {\r\n // And if it is tell it's listeners that the value has changed\r\n var valueState = getter[state.prop];\r\n valueState && valueState.chng();\r\n }\r\n });\r\n }\r\n }\r\n if (newValue !== value) {\r\n var newIsObjectOrArray = newValue && _canMakeDynamic(newValue);\r\n if (!isReferenced && newIsObjectOrArray) {\r\n // As the newValue is an object/array lets preemptively make it dynamic\r\n _makeDynamicObject(state, newValue);\r\n }\r\n // Now assign the internal \"value\" to the newValue\r\n value = newValue;\r\n isObjectOrArray = newIsObjectOrArray;\r\n }\r\n // Cause any listeners to be scheduled for notification\r\n state.add(detail);\r\n }\r\n }\r\n objDefine(theConfig, detail.n, { g: _getProperty, s: _setProperty });\r\n}\r\nexport function _setDynamicProperty(state, target, name, value, inPlace, rdOnly) {\r\n if (target) {\r\n // To be a dynamic property it needs to have a get function\r\n var getter = _getOwnPropGetter(target, name);\r\n var isDynamic = getter && !!getter[state.prop];\r\n if (!isDynamic) {\r\n _makeDynamicProperty(state, target, name, value);\r\n if (inPlace || rdOnly) {\r\n getter = _getOwnPropGetter(target, name);\r\n }\r\n }\r\n else {\r\n // Looks like it's already dynamic just assign the new value\r\n target[name] = value;\r\n }\r\n // Assign the optional flags if true\r\n if (inPlace) {\r\n getter[state.rf] = inPlace;\r\n }\r\n if (rdOnly) {\r\n getter[state.ro] = rdOnly;\r\n }\r\n }\r\n return target;\r\n}\r\nexport function _makeDynamicObject(state, target) {\r\n // Assign target with new value properties (converting into dynamic properties in the process)\r\n objForEachKey(target, function (key, value) {\r\n // Assign and/or make the property dynamic\r\n _setDynamicProperty(state, target, key, value);\r\n });\r\n if (!target[CFG_HANDLER_LINK]) {\r\n // Link the config back to the dynamic config details\r\n objDefineProp(target, CFG_HANDLER_LINK, {\r\n get: function () {\r\n return state.hdlr;\r\n }\r\n });\r\n _patchArray(state, target);\r\n }\r\n return target;\r\n}\r\n//# sourceMappingURL=DynamicProperty.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2303-
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2303-10
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -10,6 +10,19 @@ import { _DYN_LENGTH } from "../__DynamicConstants";
|
|
|
10
10
|
// To handle multiple instances using potentially different versions we are not using
|
|
11
11
|
// createUniqueNamespace()
|
|
12
12
|
export var CFG_HANDLER_LINK = symbolFor("[[ai_dynCfg_1]]");
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
* @ignore
|
|
16
|
+
* The symbol to tag objects / arrays with if they should not be converted
|
|
17
|
+
*/
|
|
18
|
+
var BLOCK_DYNAMIC = symbolFor("[[ai_blkDynCfg_1]]");
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
* @ignore
|
|
22
|
+
* The symbol to tag objects to indicate that when included into the configuration that
|
|
23
|
+
* they should be converted into a trackable dynamic object.
|
|
24
|
+
*/
|
|
25
|
+
var FORCE_DYNAMIC = symbolFor("[[ai_frcDynCfg_1]]");
|
|
13
26
|
export function _cfgDeepCopy(source) {
|
|
14
27
|
if (source) {
|
|
15
28
|
var target_1;
|
|
@@ -46,6 +59,106 @@ export function getDynamicConfigHandler(value) {
|
|
|
46
59
|
}
|
|
47
60
|
return null;
|
|
48
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Mark the provided value so that if it's included into the configuration it will NOT have
|
|
64
|
+
* its properties converted into a dynamic (reactive) object. If the object is not a plain object
|
|
65
|
+
* or an array (ie. a class) this function has not affect as only Objects and Arrays are converted
|
|
66
|
+
* into dynamic objects in the dynamic configuration.
|
|
67
|
+
*
|
|
68
|
+
* When you have tagged a value as both {@link forceDynamicConversion} and blocked force will take precedence.
|
|
69
|
+
*
|
|
70
|
+
* You should only need to use this function, if you are creating dynamic "classes" from objects
|
|
71
|
+
* which confirm to the require interface. A common case for this is during unit testing where it's
|
|
72
|
+
* easier to create mock extensions.
|
|
73
|
+
*
|
|
74
|
+
* If `value` is falsy (null / undefined / 0 / empty string etc) it will not be tagged and
|
|
75
|
+
* if there is an exception adding the property to the value (because its frozen etc) the
|
|
76
|
+
* exception will be swallowed
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* // This is a valid "extension", but it is technically an object
|
|
81
|
+
* // So when included in the config.extensions it WILL be cloned and then
|
|
82
|
+
* // converted into a dynamic object, where all of its properties will become
|
|
83
|
+
* // get/set object properties and will be tracked. While this WILL still
|
|
84
|
+
* // function, when attempt to use a mocking framework on top of this the
|
|
85
|
+
* // functions are now technically get accessors which return a function
|
|
86
|
+
* // and this can cause some mocking frameworks to fail.
|
|
87
|
+
* let mockChannel = {
|
|
88
|
+
* pause: () => { },
|
|
89
|
+
* resume: () => { },
|
|
90
|
+
* teardown: () => { },
|
|
91
|
+
* flush: (async: any, callBack: any) => { },
|
|
92
|
+
* processTelemetry: (env: any) => { },
|
|
93
|
+
* setNextPlugin: (next: any) => { },
|
|
94
|
+
* initialize: (config: any, core: any, extensions: any) => { },
|
|
95
|
+
* identifier: "testChannel",
|
|
96
|
+
* priority: 1003
|
|
97
|
+
* };
|
|
98
|
+
* ```
|
|
99
|
+
* @param value - The object that you want to block from being converted into a
|
|
100
|
+
* trackable dynamic object
|
|
101
|
+
* @returns The original value
|
|
102
|
+
*/
|
|
103
|
+
export function blockDynamicConversion(value) {
|
|
104
|
+
if (value && (isPlainObject(value) || isArray(value))) {
|
|
105
|
+
try {
|
|
106
|
+
value[BLOCK_DYNAMIC] = true;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
// Don't throw for this case as it's an ask only
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* This is the reverse case of {@link blockDynamicConversion} in that this will tag an
|
|
116
|
+
* object to indicate that it should always be converted into a dynamic trackable object
|
|
117
|
+
* even when not an object or array. So all properties of this object will become
|
|
118
|
+
* get / set accessor functions.
|
|
119
|
+
*
|
|
120
|
+
* When you have tagged a value as both {@link forceDynamicConversion} and blocked force will take precedence.
|
|
121
|
+
*
|
|
122
|
+
* If `value` is falsy (null / undefined / 0 / empty string etc) it will not be tagged and
|
|
123
|
+
* if there is an exception adding the property to the value (because its frozen etc) the
|
|
124
|
+
* exception will be swallowed.
|
|
125
|
+
* @param value - The object that should be tagged and converted if included into a dynamic
|
|
126
|
+
* configuration.
|
|
127
|
+
* @returns The original value
|
|
128
|
+
*/
|
|
129
|
+
export function forceDynamicConversion(value) {
|
|
130
|
+
if (value) {
|
|
131
|
+
try {
|
|
132
|
+
value[FORCE_DYNAMIC] = true;
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
// Don't throw for this case as it's an ask only
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @internal
|
|
142
|
+
* @ignore
|
|
143
|
+
* Helper function to check whether an object can or should be converted into a dynamic
|
|
144
|
+
* object.
|
|
145
|
+
* @param value - The object to check whether it should be converted
|
|
146
|
+
* @returns `true` if the value should be converted otherwise `false`.
|
|
147
|
+
*/
|
|
148
|
+
export function _canMakeDynamic(value) {
|
|
149
|
+
var result = false;
|
|
150
|
+
// Object must be exist and be truthy
|
|
151
|
+
if (value) {
|
|
152
|
+
// Tagged as always convert
|
|
153
|
+
result = value[FORCE_DYNAMIC];
|
|
154
|
+
// Check that it's not explicitly tagged as blocked
|
|
155
|
+
if (!result && !value[BLOCK_DYNAMIC]) {
|
|
156
|
+
// Only convert plain objects or arrays by default
|
|
157
|
+
result = isPlainObject(value) || isArray(value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
49
162
|
/**
|
|
50
163
|
* Throws an invalid access exception
|
|
51
164
|
* @param message - The message to include in the exception
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicSupport.js.map","sources":["DynamicSupport.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { isArray, isPlainObject, objForEachKey, symbolFor, throwTypeError } from \"@nevware21/ts-utils\";\r\nimport { _DYN_LENGTH } from \"../__DynamicConstants\";\r\n// Using Symbol.for so that if the same symbol was already created it would be returned\r\n// To handle multiple instances using potentially different versions we are not using\r\n// createUniqueNamespace()\r\nexport var CFG_HANDLER_LINK = symbolFor(\"[[ai_dynCfg_1]]\");\r\nexport function _cfgDeepCopy(source) {\r\n if (source) {\r\n var target_1;\r\n if (isArray(source)) {\r\n target_1 = [];\r\n target_1[_DYN_LENGTH /* @min:%2elength */] = source[_DYN_LENGTH /* @min:%2elength */];\r\n }\r\n else if (isPlainObject(source)) {\r\n target_1 = {};\r\n }\r\n if (target_1) {\r\n // Copying index values by property name as the extensionConfig can be an array or object\r\n objForEachKey(source, function (key, value) {\r\n // Perform a deep copy of the object\r\n target_1[key] = _cfgDeepCopy(value);\r\n });\r\n return target_1;\r\n }\r\n }\r\n return source;\r\n}\r\n/**\r\n * @internal\r\n * Get the dynamic config handler if the value is already dynamic\r\n * @param value\r\n * @returns\r\n */\r\nexport function getDynamicConfigHandler(value) {\r\n if (value) {\r\n var handler = value[CFG_HANDLER_LINK] || value;\r\n if (handler.cfg && (handler.cfg === value || handler.cfg[CFG_HANDLER_LINK] === handler)) {\r\n return handler;\r\n }\r\n }\r\n return null;\r\n}\r\n/**\r\n * Throws an invalid access exception\r\n * @param message - The message to include in the exception\r\n */\r\nexport function throwInvalidAccess(message) {\r\n throwTypeError(\"InvalidAccess:\" + message);\r\n}\r\n//# sourceMappingURL=DynamicSupport.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"DynamicSupport.js.map","sources":["DynamicSupport.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { isArray, isPlainObject, objForEachKey, symbolFor, throwTypeError } from \"@nevware21/ts-utils\";\r\nimport { _DYN_LENGTH } from \"../__DynamicConstants\";\r\n// Using Symbol.for so that if the same symbol was already created it would be returned\r\n// To handle multiple instances using potentially different versions we are not using\r\n// createUniqueNamespace()\r\nexport var CFG_HANDLER_LINK = symbolFor(\"[[ai_dynCfg_1]]\");\r\n/**\r\n * @internal\r\n * @ignore\r\n * The symbol to tag objects / arrays with if they should not be converted\r\n */\r\nvar BLOCK_DYNAMIC = symbolFor(\"[[ai_blkDynCfg_1]]\");\r\n/**\r\n * @internal\r\n * @ignore\r\n * The symbol to tag objects to indicate that when included into the configuration that\r\n * they should be converted into a trackable dynamic object.\r\n */\r\nvar FORCE_DYNAMIC = symbolFor(\"[[ai_frcDynCfg_1]]\");\r\nexport function _cfgDeepCopy(source) {\r\n if (source) {\r\n var target_1;\r\n if (isArray(source)) {\r\n target_1 = [];\r\n target_1[_DYN_LENGTH /* @min:%2elength */] = source[_DYN_LENGTH /* @min:%2elength */];\r\n }\r\n else if (isPlainObject(source)) {\r\n target_1 = {};\r\n }\r\n if (target_1) {\r\n // Copying index values by property name as the extensionConfig can be an array or object\r\n objForEachKey(source, function (key, value) {\r\n // Perform a deep copy of the object\r\n target_1[key] = _cfgDeepCopy(value);\r\n });\r\n return target_1;\r\n }\r\n }\r\n return source;\r\n}\r\n/**\r\n * @internal\r\n * Get the dynamic config handler if the value is already dynamic\r\n * @param value\r\n * @returns\r\n */\r\nexport function getDynamicConfigHandler(value) {\r\n if (value) {\r\n var handler = value[CFG_HANDLER_LINK] || value;\r\n if (handler.cfg && (handler.cfg === value || handler.cfg[CFG_HANDLER_LINK] === handler)) {\r\n return handler;\r\n }\r\n }\r\n return null;\r\n}\r\n/**\r\n * Mark the provided value so that if it's included into the configuration it will NOT have\r\n * its properties converted into a dynamic (reactive) object. If the object is not a plain object\r\n * or an array (ie. a class) this function has not affect as only Objects and Arrays are converted\r\n * into dynamic objects in the dynamic configuration.\r\n *\r\n * When you have tagged a value as both {@link forceDynamicConversion} and blocked force will take precedence.\r\n *\r\n * You should only need to use this function, if you are creating dynamic \"classes\" from objects\r\n * which confirm to the require interface. A common case for this is during unit testing where it's\r\n * easier to create mock extensions.\r\n *\r\n * If `value` is falsy (null / undefined / 0 / empty string etc) it will not be tagged and\r\n * if there is an exception adding the property to the value (because its frozen etc) the\r\n * exception will be swallowed\r\n *\r\n * @example\r\n * ```ts\r\n * // This is a valid \"extension\", but it is technically an object\r\n * // So when included in the config.extensions it WILL be cloned and then\r\n * // converted into a dynamic object, where all of its properties will become\r\n * // get/set object properties and will be tracked. While this WILL still\r\n * // function, when attempt to use a mocking framework on top of this the\r\n * // functions are now technically get accessors which return a function\r\n * // and this can cause some mocking frameworks to fail.\r\n * let mockChannel = {\r\n * pause: () => { },\r\n* resume: () => { },\r\n* teardown: () => { },\r\n* flush: (async: any, callBack: any) => { },\r\n* processTelemetry: (env: any) => { },\r\n* setNextPlugin: (next: any) => { },\r\n* initialize: (config: any, core: any, extensions: any) => { },\r\n* identifier: \"testChannel\",\r\n* priority: 1003\r\n* };\r\n * ```\r\n * @param value - The object that you want to block from being converted into a\r\n * trackable dynamic object\r\n * @returns The original value\r\n */\r\nexport function blockDynamicConversion(value) {\r\n if (value && (isPlainObject(value) || isArray(value))) {\r\n try {\r\n value[BLOCK_DYNAMIC] = true;\r\n }\r\n catch (e) {\r\n // Don't throw for this case as it's an ask only\r\n }\r\n }\r\n return value;\r\n}\r\n/**\r\n * This is the reverse case of {@link blockDynamicConversion} in that this will tag an\r\n * object to indicate that it should always be converted into a dynamic trackable object\r\n * even when not an object or array. So all properties of this object will become\r\n * get / set accessor functions.\r\n *\r\n * When you have tagged a value as both {@link forceDynamicConversion} and blocked force will take precedence.\r\n *\r\n * If `value` is falsy (null / undefined / 0 / empty string etc) it will not be tagged and\r\n * if there is an exception adding the property to the value (because its frozen etc) the\r\n * exception will be swallowed.\r\n * @param value - The object that should be tagged and converted if included into a dynamic\r\n * configuration.\r\n * @returns The original value\r\n */\r\nexport function forceDynamicConversion(value) {\r\n if (value) {\r\n try {\r\n value[FORCE_DYNAMIC] = true;\r\n }\r\n catch (e) {\r\n // Don't throw for this case as it's an ask only\r\n }\r\n }\r\n return value;\r\n}\r\n/**\r\n * @internal\r\n * @ignore\r\n * Helper function to check whether an object can or should be converted into a dynamic\r\n * object.\r\n * @param value - The object to check whether it should be converted\r\n * @returns `true` if the value should be converted otherwise `false`.\r\n */\r\nexport function _canMakeDynamic(value) {\r\n var result = false;\r\n // Object must be exist and be truthy\r\n if (value) {\r\n // Tagged as always convert\r\n result = value[FORCE_DYNAMIC];\r\n // Check that it's not explicitly tagged as blocked\r\n if (!result && !value[BLOCK_DYNAMIC]) {\r\n // Only convert plain objects or arrays by default\r\n result = isPlainObject(value) || isArray(value);\r\n }\r\n }\r\n return result;\r\n}\r\n/**\r\n * Throws an invalid access exception\r\n * @param message - The message to include in the exception\r\n */\r\nexport function throwInvalidAccess(message) {\r\n throwTypeError(\"InvalidAccess:\" + message);\r\n}\r\n//# sourceMappingURL=DynamicSupport.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|