@microsoft/sp-component-base 1.22.0-beta.2 → 1.22.0-beta.4

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.
Files changed (101) hide show
  1. package/dist/467dc675-7cc5-4709-8aac-78e3b71bd2f6.manifest.json +1 -1
  2. package/lib/BaseComponent.d.ts +115 -0
  3. package/lib/BaseComponent.d.ts.map +1 -0
  4. package/lib/BaseComponent.js +162 -0
  5. package/lib/BaseComponentContext.d.ts +142 -0
  6. package/lib/BaseComponentContext.d.ts.map +1 -0
  7. package/lib/BaseComponentContext.js +221 -0
  8. package/lib/DynamicDataProvider.d.ts +166 -0
  9. package/lib/DynamicDataProvider.d.ts.map +1 -0
  10. package/lib/DynamicDataProvider.js +420 -0
  11. package/lib/DynamicDataSourceManager.d.ts +160 -0
  12. package/lib/DynamicDataSourceManager.d.ts.map +1 -0
  13. package/lib/DynamicDataSourceManager.js +382 -0
  14. package/lib/DynamicProperty.d.ts +204 -0
  15. package/lib/DynamicProperty.d.ts.map +1 -0
  16. package/lib/DynamicProperty.js +390 -0
  17. package/lib/EnsureIsolatedDomainUrl.d.ts +9 -0
  18. package/lib/EnsureIsolatedDomainUrl.d.ts.map +1 -0
  19. package/lib/EnsureIsolatedDomainUrl.js +26 -0
  20. package/lib/IComponentPosition.d.ts +28 -0
  21. package/lib/IComponentPosition.d.ts.map +1 -0
  22. package/lib/IComponentPosition.js +2 -0
  23. package/lib/IComponentPropertyMetadata.d.ts +100 -0
  24. package/lib/IComponentPropertyMetadata.d.ts.map +1 -0
  25. package/lib/IComponentPropertyMetadata.js +2 -0
  26. package/lib/ISerializedServerProcessedData.d.ts +166 -0
  27. package/lib/ISerializedServerProcessedData.d.ts.map +1 -0
  28. package/lib/ISerializedServerProcessedData.js +28 -0
  29. package/lib/LegacyThirdPartyFabricCoreLoader.d.ts +40 -0
  30. package/lib/LegacyThirdPartyFabricCoreLoader.d.ts.map +1 -0
  31. package/lib/LegacyThirdPartyFabricCoreLoader.js +90 -0
  32. package/lib/PropertyMetadataProcessor.d.ts +54 -0
  33. package/lib/PropertyMetadataProcessor.d.ts.map +1 -0
  34. package/lib/PropertyMetadataProcessor.js +297 -0
  35. package/lib/ShimmerFactory.d.ts +17 -0
  36. package/lib/ShimmerFactory.d.ts.map +1 -0
  37. package/lib/ShimmerFactory.js +62 -0
  38. package/lib/chunks/legacy-third-party-fabric-core/FabricLocalFont.d.ts +17 -0
  39. package/lib/chunks/legacy-third-party-fabric-core/FabricLocalFont.d.ts.map +1 -0
  40. package/lib/chunks/legacy-third-party-fabric-core/FabricLocalFont.js +17 -0
  41. package/lib/chunks/legacy-third-party-fabric-core/fabric-core-sass/Fabric.LocalFont.global.scss.css +9247 -0
  42. package/lib/chunks/legacy-third-party-fabric-core/fabric-core-sass/Fabric.LocalFontKillSwitchActivated.scss.css +11165 -0
  43. package/lib/chunks/legacy-third-party-fabric-core/fabric-core-shim.global.scss.css +2063 -0
  44. package/lib/chunks/legacy-third-party-fabric-core/fabric-core-shimKillSwitchActivated.scss.css +2164 -0
  45. package/lib/chunks/legacy-third-party-fabric-core/iconDefinitions.css +6 -0
  46. package/lib/common/Flights.d.ts +3 -0
  47. package/lib/common/Flights.d.ts.map +1 -0
  48. package/lib/common/Flights.js +10 -0
  49. package/lib/common/KillSwitches.d.ts +2 -0
  50. package/lib/common/KillSwitches.d.ts.map +1 -0
  51. package/lib/common/KillSwitches.js +5 -0
  52. package/lib/dataCollector/IWebPartLoadData.d.ts +140 -0
  53. package/lib/dataCollector/IWebPartLoadData.d.ts.map +1 -0
  54. package/lib/dataCollector/IWebPartLoadData.js +40 -0
  55. package/lib/dataCollector/WebPartLoadDataCollector.d.ts +14 -0
  56. package/lib/dataCollector/WebPartLoadDataCollector.d.ts.map +1 -0
  57. package/lib/dataCollector/WebPartLoadDataCollector.js +137 -0
  58. package/lib/index.d.ts +34 -0
  59. package/lib/index.d.ts.map +1 -0
  60. package/lib/index.js +27 -0
  61. package/lib/loc/Strings.resx.d.ts +44 -0
  62. package/lib/loc/Strings.resx.json +1 -0
  63. package/lib/sp-component-base.manifest.json +9 -0
  64. package/lib/styles/shimmer.module.scss.css +11 -0
  65. package/lib/teams/DeferredTeamsAppsClient.d.ts +17 -0
  66. package/lib/teams/DeferredTeamsAppsClient.d.ts.map +1 -0
  67. package/lib/teams/DeferredTeamsAppsClient.js +39 -0
  68. package/lib/teams/ITeamsAppCatalog.d.ts +72 -0
  69. package/lib/teams/ITeamsAppCatalog.d.ts.map +1 -0
  70. package/lib/teams/ITeamsAppCatalog.js +2 -0
  71. package/lib/teams/TeamsAppsClient.d.ts +113 -0
  72. package/lib/teams/TeamsAppsClient.d.ts.map +1 -0
  73. package/lib/teams/TeamsAppsClient.js +440 -0
  74. package/lib/test-api/MockComponent.d.ts +8 -0
  75. package/lib/test-api/MockComponent.d.ts.map +1 -0
  76. package/lib/test-api/MockComponent.js +31 -0
  77. package/lib/test-api/MockComponentContext.d.ts +6 -0
  78. package/lib/test-api/MockComponentContext.d.ts.map +1 -0
  79. package/lib/test-api/MockComponentContext.js +27 -0
  80. package/lib/test-api/index.d.ts +3 -0
  81. package/lib/test-api/index.d.ts.map +1 -0
  82. package/lib/test-api/index.js +3 -0
  83. package/lib/themeProvider/ThemeProvider.d.ts +71 -0
  84. package/lib/themeProvider/ThemeProvider.d.ts.map +1 -0
  85. package/lib/themeProvider/ThemeProvider.js +99 -0
  86. package/lib/themeProvider/themeInterfaces/IFontStyles.d.ts +26 -0
  87. package/lib/themeProvider/themeInterfaces/IFontStyles.d.ts.map +1 -0
  88. package/lib/themeProvider/themeInterfaces/IFontStyles.js +2 -0
  89. package/lib/themeProvider/themeInterfaces/IPalette.d.ts +7 -0
  90. package/lib/themeProvider/themeInterfaces/IPalette.d.ts.map +1 -0
  91. package/lib/themeProvider/themeInterfaces/IPalette.js +2 -0
  92. package/lib/themeProvider/themeInterfaces/ISemanticColors.d.ts +56 -0
  93. package/lib/themeProvider/themeInterfaces/ISemanticColors.d.ts.map +1 -0
  94. package/lib/themeProvider/themeInterfaces/ISemanticColors.js +2 -0
  95. package/lib/themeProvider/themeInterfaces/ISemanticTextColors.d.ts +7 -0
  96. package/lib/themeProvider/themeInterfaces/ISemanticTextColors.d.ts.map +1 -0
  97. package/lib/themeProvider/themeInterfaces/ISemanticTextColors.js +2 -0
  98. package/lib/themeProvider/themeInterfaces/ITheme.d.ts +16 -0
  99. package/lib/themeProvider/themeInterfaces/ITheme.d.ts.map +1 -0
  100. package/lib/themeProvider/themeInterfaces/ITheme.js +2 -0
  101. package/package.json +15 -15
@@ -0,0 +1,160 @@
1
+ import { type IDisposable, type ServiceScope } from '@microsoft/sp-core-library';
2
+ import { type IDynamicDataCallables, type IDynamicDataSource, type IDynamicDataSourceMetadata } from '@microsoft/sp-dynamic-data';
3
+ import type BaseComponent from './BaseComponent';
4
+ /**
5
+ * The Dynamic Data Source Manager is responsible for:
6
+ * - Constructing the dynamic data source
7
+ * - Allowing initialization of the dynamic data source by a component
8
+ * - Allowing data source to update its metadata and notify when data has been updated.
9
+ *
10
+ * @public
11
+ */
12
+ export default class DynamicDataSourceManager implements IDisposable {
13
+ private _dynamicDataManager;
14
+ private _component;
15
+ private _callableFunctions;
16
+ private _src;
17
+ private _isDisposed;
18
+ private _isInitialized;
19
+ private _logSource;
20
+ /**
21
+ * Initializes the Dynamic Data source manager for a specific component.
22
+ *
23
+ * @param component - Component on which the source is being constructed.
24
+ *
25
+ * @internal
26
+ */
27
+ _initialize(component: BaseComponent, serviceScope: ServiceScope): void;
28
+ /**
29
+ * Disposes the resources held by the Dynamic Data source.
30
+ */
31
+ dispose(): void;
32
+ /**
33
+ * Returns true if the DynamicDataSourceManager is disposed.
34
+ */
35
+ get isDisposed(): boolean;
36
+ /**
37
+ * Returns the source of DynamicDataSourceManager.
38
+ * @internal
39
+ */
40
+ get _source(): IDynamicDataSource | undefined;
41
+ /**
42
+ * Initializes the Dynamic Data Source for the component.
43
+ *
44
+ * @param callableFunctions - Set of methods that are exposed through the Dynamic Data Source
45
+ */
46
+ initializeSource(callableFunctions: IDynamicDataCallables): void;
47
+ /**
48
+ * Notifies that this source has updated its properties.
49
+ *
50
+ * When invoked, it enables to broadcast the notification to all the consumers who have
51
+ * registered to this notification from this source.
52
+ */
53
+ notifySourceChanged(): void;
54
+ /**
55
+ * Notifies that this source has updated a specific property.
56
+ *
57
+ * When invoked, it enables to broadcast the notification to all the consumers who have
58
+ * registered to this notification from this source.
59
+ *
60
+ * @param propertyId - Id of the updated property in the source.
61
+ */
62
+ notifyPropertyChanged(propertyId: string): void;
63
+ /**
64
+ * Updates the metadata of the Dynamic Data Source.
65
+ * It allows to update fields like title or description.
66
+ * Auto-generated fields like alias, componentId or instanceId cannot be updated.
67
+ *
68
+ * @param metadata - Partial of the metadata.
69
+ */
70
+ updateMetadata(metadata: Partial<IDynamicDataSourceMetadata>): void;
71
+ /**
72
+ * Returns the Id of the current DataSource.
73
+ * If the component did not initialize as a dynamic data source, then it returns an empty string.
74
+ */
75
+ get sourceId(): string;
76
+ private _buildSource;
77
+ /**
78
+ * This is the allowedEvents() that the DynamicDataSource actually exposes.
79
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
80
+ */
81
+ private _allowedEvents;
82
+ /**
83
+ * This is the sendEvent() that the consumer invokes to send an event to the source, with data.
84
+ * @param eventName - Name of the event
85
+ * @param data - Associated data
86
+ */
87
+ private _sendEvent;
88
+ /**
89
+ * This is the getPropertyDefinitions() that the DynamicDataSource actually exposes.
90
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
91
+ * This assumes that the component has dynamic data and has a controller.
92
+ */
93
+ private _getPropertyDefinitions;
94
+ /**
95
+ * This is the getPropertyValue() that the DynamicDataSource actually exposes.
96
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
97
+ * This assumes that the component has the source initialized.
98
+ * If there is no value returned, it checks whether the propertyId is incorrect or the value is actually undefined.
99
+ *
100
+ * @remarks
101
+ * If the property value associated with the property id, is an array then the
102
+ * propertyId will have [*] notation appended at the end to support valid JSON Path notation.
103
+ * Hence when reading the property id, we account for that and extract the name accordingly.
104
+ */
105
+ private _getPropertyValue;
106
+ /**
107
+ * Returns the real time value of the property.
108
+ */
109
+ private _getPropertyDefinitionsAsync;
110
+ /**
111
+ * Returns the real time value of the property.
112
+ * @param propertyId - property id for which the value is requested.
113
+ */
114
+ private _getPropertyValueAsync;
115
+ /**
116
+ * This is the allowedEvents() that the DynamicDataSource actually exposes.
117
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
118
+ */
119
+ private _allowedEventsAsync;
120
+ /**
121
+ * This is the getPropertyValueSchema() that the DynamicDataSource actually exposes.
122
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
123
+ * If the source doesn't provide the annotated value, then it falls back to whatever
124
+ * 'getPropertyValue' returns as the sample value and metadata would be undefined.
125
+ *
126
+ * @remarks
127
+ * If the property value associated with the property id, is an array then the
128
+ * propertyId will have [*] notation appended at the end to support valid JSON Path notation.
129
+ * Hence when reading the property id, we account for that and extract the name accordingly.
130
+ *
131
+ * @param propertyId - property id for which the schema is requested.
132
+ */
133
+ private _getAnnotatedPropertyValue;
134
+ /**
135
+ * Returns the annotated value of the property.
136
+ * @param propertyId - property id for which the value is requested.
137
+ */
138
+ private _getAnnotatedPropertyValueAsync;
139
+ private _buildMetadata;
140
+ /**
141
+ * Asserts if the event is a valid event on the source.
142
+ *
143
+ * Its an invalid event in two cases:
144
+ * 1. When '_allowedEvent()' api returns undefined
145
+ * 2. When the event name is not one of the allowed events on the source.
146
+ *
147
+ * @param eventName - Name of the event.
148
+ */
149
+ private _assertValidEvent;
150
+ private _assertNotDisposed;
151
+ private _assertInitialized;
152
+ private _assertSourceExists;
153
+ /**
154
+ * Logs a feature event.
155
+ * @param logFeature - Name of the feature to log.
156
+ * @param contextualProps - Contextual log properties of the feature event.
157
+ */
158
+ private _logFeatureEntry;
159
+ }
160
+ //# sourceMappingURL=DynamicDataSourceManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicDataSourceManager.d.ts","sourceRoot":"","sources":["../src/DynamicDataSourceManager.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAkB,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAEL,KAAK,qBAAqB,EAG1B,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAGhC,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AAKjD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,YAAW,WAAW;IAClE,OAAO,CAAC,mBAAmB,CAAmC;IAC9D,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,IAAI,CAA6C;IACzD,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,UAAU,CAA8D;IAEhF;;;;;;OAMG;IACI,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,GAAG,IAAI;IAW9E;;OAEG;IACI,OAAO,IAAI,IAAI;IActB;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED;;;OAGG;IACH,IAAW,OAAO,IAAI,kBAAkB,GAAG,SAAS,CAEnD;IAED;;;;OAIG;IACI,gBAAgB,CAAC,iBAAiB,EAAE,qBAAqB,GAAG,IAAI;IAmBvE;;;;;OAKG;IACI,mBAAmB,IAAI,IAAI;IAOlC;;;;;;;OAOG;IACI,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAQtD;;;;;;OAMG;IACI,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAAG,IAAI;IAc1E;;;OAGG;IACH,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,OAAO,CAAC,YAAY;IA2BpB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAMtB;;;;OAIG;IAEH,OAAO,CAAC,UAAU;IAMlB;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;;;;;;;;;OAUG;IAEH,OAAO,CAAC,iBAAiB;IA2CzB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAIpC;;;OAGG;IAEH,OAAO,CAAC,sBAAsB;IAI9B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,0BAA0B;IA0ClC;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAIvC,OAAO,CAAC,cAAc;IAyBtB;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CAezB"}
@@ -0,0 +1,382 @@
1
+ import { __assign } from "tslib";
2
+ import { _EngagementLogger, _LogEntry, _LogType, _TraceLogger, _LogSource, _QosMonitor } from '@microsoft/sp-diagnostics';
3
+ import { Text, Validate } from '@microsoft/sp-core-library';
4
+ import { _DynamicDataUtilities } from '@microsoft/sp-dynamic-data';
5
+ import * as lodash from '@microsoft/sp-lodash-subset';
6
+ import { cloneDeep, findIndex, merge } from '@microsoft/sp-lodash-subset';
7
+ import DynamicDataProvider from './DynamicDataProvider';
8
+ import strings from './loc/Strings.resx';
9
+ import { isExemptWebPartWithDynamicDataFromLazyLoadKSActivated } from './common/KillSwitches';
10
+ /**
11
+ * The Dynamic Data Source Manager is responsible for:
12
+ * - Constructing the dynamic data source
13
+ * - Allowing initialization of the dynamic data source by a component
14
+ * - Allowing data source to update its metadata and notify when data has been updated.
15
+ *
16
+ * @public
17
+ */
18
+ var DynamicDataSourceManager = /** @class */ (function () {
19
+ function DynamicDataSourceManager() {
20
+ this._src = undefined;
21
+ this._isDisposed = false;
22
+ this._isInitialized = false;
23
+ this._logSource = _LogSource.create('DynamicDataSourceManager');
24
+ }
25
+ /**
26
+ * Initializes the Dynamic Data source manager for a specific component.
27
+ *
28
+ * @param component - Component on which the source is being constructed.
29
+ *
30
+ * @internal
31
+ */
32
+ DynamicDataSourceManager.prototype._initialize = function (component, serviceScope) {
33
+ Validate.isNotNullOrUndefined(component, 'component');
34
+ Validate.isNotNullOrUndefined(serviceScope, 'serviceScope');
35
+ this._component = component;
36
+ this._dynamicDataManager = serviceScope.consume(_DynamicDataUtilities.IDynamicDataManagerServiceKey);
37
+ this._isInitialized = true;
38
+ };
39
+ /**
40
+ * Disposes the resources held by the Dynamic Data source.
41
+ */
42
+ DynamicDataSourceManager.prototype.dispose = function () {
43
+ if (!this._isDisposed) {
44
+ if (this._src) {
45
+ this._dynamicDataManager.removeSource(this._src.id);
46
+ delete this._src;
47
+ }
48
+ delete this._dynamicDataManager;
49
+ delete this._component;
50
+ this._isInitialized = false;
51
+ this._isDisposed = true;
52
+ }
53
+ };
54
+ Object.defineProperty(DynamicDataSourceManager.prototype, "isDisposed", {
55
+ /**
56
+ * Returns true if the DynamicDataSourceManager is disposed.
57
+ */
58
+ get: function () {
59
+ return this._isDisposed;
60
+ },
61
+ enumerable: false,
62
+ configurable: true
63
+ });
64
+ Object.defineProperty(DynamicDataSourceManager.prototype, "_source", {
65
+ /**
66
+ * Returns the source of DynamicDataSourceManager.
67
+ * @internal
68
+ */
69
+ get: function () {
70
+ return this._src;
71
+ },
72
+ enumerable: false,
73
+ configurable: true
74
+ });
75
+ /**
76
+ * Initializes the Dynamic Data Source for the component.
77
+ *
78
+ * @param callableFunctions - Set of methods that are exposed through the Dynamic Data Source
79
+ */
80
+ DynamicDataSourceManager.prototype.initializeSource = function (callableFunctions) {
81
+ this._assertNotDisposed();
82
+ this._assertInitialized();
83
+ if (this._src) {
84
+ throw new Error(strings.SourceAlreadyInitialized);
85
+ }
86
+ this._callableFunctions = callableFunctions;
87
+ this._src = this._buildSource(this._component);
88
+ this._dynamicDataManager.addSource(this._src);
89
+ if (!isExemptWebPartWithDynamicDataFromLazyLoadKSActivated()) {
90
+ this._component._containsDynamicDataSource = true;
91
+ }
92
+ this._logFeatureEntry('DynamicDataSourceInitialized', { sourceId: this._src.id });
93
+ };
94
+ /**
95
+ * Notifies that this source has updated its properties.
96
+ *
97
+ * When invoked, it enables to broadcast the notification to all the consumers who have
98
+ * registered to this notification from this source.
99
+ */
100
+ DynamicDataSourceManager.prototype.notifySourceChanged = function () {
101
+ this._assertNotDisposed();
102
+ this._assertInitialized();
103
+ this._assertSourceExists();
104
+ this._dynamicDataManager.notifySourceChanged(this._src.id);
105
+ };
106
+ /**
107
+ * Notifies that this source has updated a specific property.
108
+ *
109
+ * When invoked, it enables to broadcast the notification to all the consumers who have
110
+ * registered to this notification from this source.
111
+ *
112
+ * @param propertyId - Id of the updated property in the source.
113
+ */
114
+ DynamicDataSourceManager.prototype.notifyPropertyChanged = function (propertyId) {
115
+ Validate.isNonemptyString(propertyId, 'propertyId');
116
+ this._assertNotDisposed();
117
+ this._assertInitialized();
118
+ this._assertSourceExists();
119
+ this._dynamicDataManager.notifyPropertyChanged(this._src.id, propertyId);
120
+ };
121
+ /**
122
+ * Updates the metadata of the Dynamic Data Source.
123
+ * It allows to update fields like title or description.
124
+ * Auto-generated fields like alias, componentId or instanceId cannot be updated.
125
+ *
126
+ * @param metadata - Partial of the metadata.
127
+ */
128
+ DynamicDataSourceManager.prototype.updateMetadata = function (metadata) {
129
+ this._assertNotDisposed();
130
+ this._assertInitialized();
131
+ this._assertSourceExists();
132
+ Validate.isNotNullOrUndefined(metadata, 'metadata');
133
+ // Ensure that auto-generated properties are not updated.
134
+ metadata.alias = undefined;
135
+ metadata.componentId = undefined;
136
+ metadata.instanceId = undefined;
137
+ merge(this._src.metadata, metadata);
138
+ };
139
+ Object.defineProperty(DynamicDataSourceManager.prototype, "sourceId", {
140
+ /**
141
+ * Returns the Id of the current DataSource.
142
+ * If the component did not initialize as a dynamic data source, then it returns an empty string.
143
+ */
144
+ get: function () {
145
+ return this._src ? this._src.id : '';
146
+ },
147
+ enumerable: false,
148
+ configurable: true
149
+ });
150
+ DynamicDataSourceManager.prototype._buildSource = function (component) {
151
+ // If the source is returning non-empty allowed events then, it has to define
152
+ // 'sendEvent' event handler as well.
153
+ if (this._callableFunctions.allowedEvents && this._callableFunctions.allowedEvents.length > 0) {
154
+ if (!this._callableFunctions.sendEvent) {
155
+ throw new Error(strings.NoSendEventWhenAllowedEventsIsNonEmpty);
156
+ }
157
+ }
158
+ return {
159
+ id: this._component._dynamicDataSourceId,
160
+ metadata: this._buildMetadata(component),
161
+ // Return a clone to ensure that the consumer doesn't modify values in the source
162
+ getPropertyDefinitions: this._getPropertyDefinitions.bind(this),
163
+ getPropertyValue: this._getPropertyValue.bind(this),
164
+ getAnnotatedPropertyValue: this._getAnnotatedPropertyValue.bind(this),
165
+ // async callbacks
166
+ getPropertyDefinitionsAsync: this._getPropertyDefinitionsAsync.bind(this),
167
+ getPropertyValueAsync: this._getPropertyValueAsync.bind(this),
168
+ getAnnotatedPropertyValueAsync: this._getAnnotatedPropertyValueAsync.bind(this),
169
+ allowedEventsAsync: this._allowedEventsAsync.bind(this),
170
+ sendEvent: this._sendEvent.bind(this)
171
+ };
172
+ };
173
+ /**
174
+ * This is the allowedEvents() that the DynamicDataSource actually exposes.
175
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
176
+ */
177
+ DynamicDataSourceManager.prototype._allowedEvents = function () {
178
+ return this._callableFunctions.allowedEvents
179
+ ? cloneDeep(this._callableFunctions.allowedEvents())
180
+ : undefined;
181
+ };
182
+ /**
183
+ * This is the sendEvent() that the consumer invokes to send an event to the source, with data.
184
+ * @param eventName - Name of the event
185
+ * @param data - Associated data
186
+ */
187
+ DynamicDataSourceManager.prototype._sendEvent = function (eventName, data) {
188
+ this._assertValidEvent(eventName);
189
+ this._callableFunctions.sendEvent(eventName, data);
190
+ };
191
+ /**
192
+ * This is the getPropertyDefinitions() that the DynamicDataSource actually exposes.
193
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
194
+ * This assumes that the component has dynamic data and has a controller.
195
+ */
196
+ DynamicDataSourceManager.prototype._getPropertyDefinitions = function () {
197
+ return cloneDeep(this._callableFunctions.getPropertyDefinitions());
198
+ };
199
+ /**
200
+ * This is the getPropertyValue() that the DynamicDataSource actually exposes.
201
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
202
+ * This assumes that the component has the source initialized.
203
+ * If there is no value returned, it checks whether the propertyId is incorrect or the value is actually undefined.
204
+ *
205
+ * @remarks
206
+ * If the property value associated with the property id, is an array then the
207
+ * propertyId will have [*] notation appended at the end to support valid JSON Path notation.
208
+ * Hence when reading the property id, we account for that and extract the name accordingly.
209
+ */
210
+ DynamicDataSourceManager.prototype._getPropertyValue = function (propertyId) {
211
+ Validate.isNotNullOrUndefined(propertyId, 'propertyId');
212
+ var qosMonitor = new _QosMonitor('DynamicDataSourceManager._getPropertyValue');
213
+ var paths = propertyId.split(DynamicDataProvider._jsonPathArrayRegex);
214
+ try {
215
+ var propertyValue = this._callableFunctions.getPropertyValue(paths.shift());
216
+ if (paths.length > 0) {
217
+ if (!isNaN(parseInt(paths[0], 10)) && Array.isArray(propertyValue)) {
218
+ propertyValue = propertyValue[paths[0]];
219
+ }
220
+ }
221
+ if (propertyValue === undefined) {
222
+ if (
223
+ // This code can be slow if there is a many property definitions (O(n) for number of properties).
224
+ // It's done this way to prioritize memory consumption instead of CPU cycles as this is an optional feature,
225
+ // so if it's not used there is no memory footprint
226
+ this._callableFunctions.getPropertyDefinitions().filter(function (def) { return def.id === propertyId; }).length ===
227
+ 0 &&
228
+ this._src // Check that the source exists to get its title
229
+ ) {
230
+ throw new Error("Property \"".concat(propertyId, "\" doesn't exist in source \"").concat(this._src.metadata.title, "\""));
231
+ }
232
+ }
233
+ // DO NOT log propertyValue it can contain PII.
234
+ qosMonitor.writeSuccess(__assign(__assign({}, ((this._src && this._src.metadata) || {})), { sourceId: this._src && this._src.id, propertyId: propertyId }));
235
+ return cloneDeep(propertyValue);
236
+ }
237
+ catch (error) {
238
+ qosMonitor.writeUnexpectedFailure('NoPropertyId', error, { propertyId: propertyId });
239
+ _TraceLogger.logErrorData({
240
+ source: this._logSource,
241
+ error: error
242
+ });
243
+ return undefined;
244
+ }
245
+ };
246
+ /**
247
+ * Returns the real time value of the property.
248
+ */
249
+ DynamicDataSourceManager.prototype._getPropertyDefinitionsAsync = function () {
250
+ return Promise.resolve(this._getPropertyDefinitions());
251
+ };
252
+ /**
253
+ * Returns the real time value of the property.
254
+ * @param propertyId - property id for which the value is requested.
255
+ */
256
+ DynamicDataSourceManager.prototype._getPropertyValueAsync = function (propertyId) {
257
+ return Promise.resolve(this._getPropertyValue(propertyId));
258
+ };
259
+ /**
260
+ * This is the allowedEvents() that the DynamicDataSource actually exposes.
261
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
262
+ */
263
+ DynamicDataSourceManager.prototype._allowedEventsAsync = function () {
264
+ return Promise.resolve(this._allowedEvents());
265
+ };
266
+ /**
267
+ * This is the getPropertyValueSchema() that the DynamicDataSource actually exposes.
268
+ * It does a copy of the data to ensure the consumer doesn't modify the source.
269
+ * If the source doesn't provide the annotated value, then it falls back to whatever
270
+ * 'getPropertyValue' returns as the sample value and metadata would be undefined.
271
+ *
272
+ * @remarks
273
+ * If the property value associated with the property id, is an array then the
274
+ * propertyId will have [*] notation appended at the end to support valid JSON Path notation.
275
+ * Hence when reading the property id, we account for that and extract the name accordingly.
276
+ *
277
+ * @param propertyId - property id for which the schema is requested.
278
+ */
279
+ DynamicDataSourceManager.prototype._getAnnotatedPropertyValue = function (propertyId) {
280
+ Validate.isNotNullOrUndefined(propertyId, 'propertyId');
281
+ var qosMonitor = new _QosMonitor('DynamicDataSourceManager._getAnnotatedPropertyValue');
282
+ var annotatedPropertyValue;
283
+ var getAnnotatedPropertyValue = this._callableFunctions.getAnnotatedPropertyValue;
284
+ if (getAnnotatedPropertyValue) {
285
+ var paths = propertyId.split(DynamicDataProvider._jsonPathArrayRegex);
286
+ try {
287
+ annotatedPropertyValue = this._callableFunctions.getAnnotatedPropertyValue(paths.shift());
288
+ if (paths.length > 0) {
289
+ if (!isNaN(parseInt(paths[0], 10)) && Array.isArray(annotatedPropertyValue)) {
290
+ annotatedPropertyValue = annotatedPropertyValue[paths[0]];
291
+ }
292
+ }
293
+ qosMonitor.writeSuccess(__assign(__assign({}, ((this._src && this._src.metadata) || {})), { sourceId: this._src && this._src.id, annotatedPropertyValue: annotatedPropertyValue, propertyId: propertyId }));
294
+ }
295
+ catch (error) {
296
+ qosMonitor.writeExpectedFailure('NoAnnotatedPropertyValue', error, { annotatedPropertyValue: annotatedPropertyValue });
297
+ _TraceLogger.logErrorData({
298
+ source: this._logSource,
299
+ error: error
300
+ });
301
+ annotatedPropertyValue = undefined;
302
+ }
303
+ }
304
+ if (!annotatedPropertyValue) {
305
+ annotatedPropertyValue = {
306
+ sampleValue: this._getPropertyValue(propertyId),
307
+ metadata: undefined
308
+ };
309
+ }
310
+ return annotatedPropertyValue;
311
+ };
312
+ /**
313
+ * Returns the annotated value of the property.
314
+ * @param propertyId - property id for which the value is requested.
315
+ */
316
+ DynamicDataSourceManager.prototype._getAnnotatedPropertyValueAsync = function (propertyId) {
317
+ return Promise.resolve(this._getAnnotatedPropertyValue(propertyId));
318
+ };
319
+ DynamicDataSourceManager.prototype._buildMetadata = function (component) {
320
+ var metadata = {
321
+ title: component.manifest.alias,
322
+ alias: component.manifest.alias,
323
+ componentId: component.componentId,
324
+ instanceId: component.instanceId
325
+ };
326
+ // Web parts have properties "title" and "description" that should go to the source by default.
327
+ var componentWithMetadata = component;
328
+ if (componentWithMetadata.title) {
329
+ metadata.title = componentWithMetadata.title;
330
+ }
331
+ if (componentWithMetadata.description) {
332
+ metadata.description = componentWithMetadata.description;
333
+ }
334
+ return metadata;
335
+ };
336
+ /**
337
+ * Asserts if the event is a valid event on the source.
338
+ *
339
+ * Its an invalid event in two cases:
340
+ * 1. When '_allowedEvent()' api returns undefined
341
+ * 2. When the event name is not one of the allowed events on the source.
342
+ *
343
+ * @param eventName - Name of the event.
344
+ */
345
+ DynamicDataSourceManager.prototype._assertValidEvent = function (eventName) {
346
+ if (!this._allowedEvents() || findIndex(this._allowedEvents(), { name: eventName }) === -1) {
347
+ throw new Error(Text.format(strings.InvalidEvent, eventName, this._src.metadata.title));
348
+ }
349
+ };
350
+ DynamicDataSourceManager.prototype._assertNotDisposed = function () {
351
+ if (this.isDisposed) {
352
+ throw new Error(strings.DynamicDataSourceManagerIsDisposed);
353
+ }
354
+ };
355
+ DynamicDataSourceManager.prototype._assertInitialized = function () {
356
+ if (!this._isInitialized) {
357
+ throw new Error(strings.DynamicDataSourceManagerIsNotInitialized);
358
+ }
359
+ };
360
+ DynamicDataSourceManager.prototype._assertSourceExists = function () {
361
+ if (!this._src) {
362
+ throw new Error(strings.DynamicDataSourceIsNotInitialized);
363
+ }
364
+ };
365
+ /**
366
+ * Logs a feature event.
367
+ * @param logFeature - Name of the feature to log.
368
+ * @param contextualProps - Contextual log properties of the feature event.
369
+ */
370
+ DynamicDataSourceManager.prototype._logFeatureEntry = function (logFeature, contextualProps) {
371
+ var isInternal = this._component.manifest.isInternal || false;
372
+ var logProperties = {
373
+ alias: this._component.manifest.alias,
374
+ isInternal: isInternal.toString()
375
+ };
376
+ var logEntry = new _LogEntry('DynamicDataSourceManager', logFeature, _LogType.Event, lodash.merge(logProperties, contextualProps));
377
+ _EngagementLogger.logEventWithLogEntry(logEntry);
378
+ };
379
+ return DynamicDataSourceManager;
380
+ }());
381
+ export default DynamicDataSourceManager;
382
+ //# sourceMappingURL=DynamicDataSourceManager.js.map