@microsoft/sp-component-base 1.23.1 → 1.24.0-beta.2

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