@microsoft/1ds-core-js 3.2.12 → 4.0.1
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/README.md +1 -1
- package/bundle/es5/ms.core-4.0.1.gbl.js +6321 -0
- package/bundle/es5/ms.core-4.0.1.gbl.js.map +1 -0
- package/bundle/es5/ms.core-4.0.1.gbl.min.js +7 -0
- package/bundle/es5/ms.core-4.0.1.gbl.min.js.map +1 -0
- package/bundle/es5/ms.core-4.0.1.integrity.json +46 -0
- package/bundle/es5/ms.core-4.0.1.js +6325 -0
- package/bundle/es5/ms.core-4.0.1.js.map +1 -0
- package/bundle/es5/ms.core-4.0.1.min.js +7 -0
- package/bundle/es5/ms.core-4.0.1.min.js.map +1 -0
- package/bundle/es5/ms.core.gbl.js +6321 -0
- package/bundle/es5/ms.core.gbl.js.map +1 -0
- package/bundle/es5/ms.core.gbl.min.js +7 -0
- package/bundle/es5/ms.core.gbl.min.js.map +1 -0
- package/bundle/es5/ms.core.integrity.json +46 -0
- package/bundle/es5/ms.core.js +6325 -0
- package/bundle/es5/ms.core.js.map +1 -0
- package/bundle/es5/ms.core.min.js +7 -0
- package/bundle/es5/ms.core.min.js.map +1 -0
- package/{bundle → dist/es5}/ms.core.js +3945 -3022
- package/dist/es5/ms.core.js.map +1 -0
- package/dist/es5/ms.core.min.js +7 -0
- package/dist/es5/ms.core.min.js.map +1 -0
- package/dist-es5/AppInsightsCore.js +91 -0
- package/dist-es5/AppInsightsCore.js.map +1 -0
- package/{dist-esm/src → dist-es5}/BaseCore.js +18 -11
- package/dist-es5/BaseCore.js.map +1 -0
- package/{dist-esm/src → dist-es5}/DataModels.js +1 -1
- package/{dist-esm/src → dist-es5}/Enums.js +3 -26
- package/dist-es5/Enums.js.map +1 -0
- package/{dist-esm/src → dist-es5}/Index.js +9 -14
- package/dist-es5/Index.js.map +1 -0
- package/{dist-esm/src → dist-es5}/InternalConstants.js +1 -3
- package/{dist-esm/src → dist-es5}/InternalConstants.js.map +1 -1
- package/{dist-esm/src → dist-es5}/Utils.js +19 -144
- package/dist-es5/Utils.js.map +1 -0
- package/{dist-esm/src → dist-es5}/ValueSanitizer.js +42 -3
- package/dist-es5/ValueSanitizer.js.map +1 -0
- package/package.json +16 -9
- package/tsconfig.json +5 -3
- package/types/1ds-core-js.d.ts +1110 -0
- package/types/1ds-core-js.namespaced.d.ts +1106 -0
- package/bundle/ms.core-3.2.12.gbl.js +0 -5378
- package/bundle/ms.core-3.2.12.gbl.js.map +0 -1
- package/bundle/ms.core-3.2.12.gbl.min.js +0 -7
- package/bundle/ms.core-3.2.12.gbl.min.js.map +0 -1
- package/bundle/ms.core-3.2.12.integrity.json +0 -46
- package/bundle/ms.core-3.2.12.js +0 -5381
- package/bundle/ms.core-3.2.12.js.map +0 -1
- package/bundle/ms.core-3.2.12.min.js +0 -7
- package/bundle/ms.core-3.2.12.min.js.map +0 -1
- package/bundle/ms.core.gbl.js +0 -5378
- package/bundle/ms.core.gbl.js.map +0 -1
- package/bundle/ms.core.gbl.min.js +0 -7
- package/bundle/ms.core.gbl.min.js.map +0 -1
- package/bundle/ms.core.integrity.json +0 -46
- package/bundle/ms.core.js.map +0 -1
- package/bundle/ms.core.min.js +0 -7
- package/bundle/ms.core.min.js.map +0 -1
- package/dist/ms.core.js +0 -1305
- package/dist/ms.core.js.map +0 -1
- package/dist/ms.core.min.js +0 -7
- package/dist/ms.core.min.js.map +0 -1
- package/dist-esm/src/AppInsightsCore.d.ts +0 -15
- package/dist-esm/src/AppInsightsCore.js +0 -114
- package/dist-esm/src/AppInsightsCore.js.map +0 -1
- package/dist-esm/src/BaseCore.d.ts +0 -13
- package/dist-esm/src/BaseCore.js.map +0 -1
- package/dist-esm/src/DataModels.d.ts +0 -273
- package/dist-esm/src/ESPromise.d.ts +0 -110
- package/dist-esm/src/ESPromise.js +0 -286
- package/dist-esm/src/ESPromise.js.map +0 -1
- package/dist-esm/src/ESPromiseScheduler.d.ts +0 -36
- package/dist-esm/src/ESPromiseScheduler.js +0 -274
- package/dist-esm/src/ESPromiseScheduler.js.map +0 -1
- package/dist-esm/src/Enums.d.ts +0 -356
- package/dist-esm/src/Enums.js.map +0 -1
- package/dist-esm/src/Index.d.ts +0 -19
- package/dist-esm/src/Index.js.map +0 -1
- package/dist-esm/src/InternalConstants.d.ts +0 -6
- package/dist-esm/src/Utils.d.ts +0 -190
- package/dist-esm/src/Utils.js.map +0 -1
- package/dist-esm/src/ValueSanitizer.d.ts +0 -40
- package/dist-esm/src/ValueSanitizer.js.map +0 -1
- package/src/AppInsightsCore.ts +0 -135
- package/src/BaseCore.ts +0 -72
- package/src/DataModels.ts +0 -297
- package/src/ESPromise.ts +0 -365
- package/src/ESPromiseScheduler.ts +0 -328
- package/src/Enums.ts +0 -386
- package/src/Index.ts +0 -81
- package/src/InternalConstants.ts +0 -16
- package/src/Utils.ts +0 -565
- package/src/ValueSanitizer.ts +0 -285
- /package/{dist-esm/src → dist-es5}/DataModels.js.map +0 -0
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataModels.ts
|
|
3
|
-
* @author Abhilash Panwar (abpanwar) Hector Hernandez (hectorh)
|
|
4
|
-
* @copyright Microsoft 2018
|
|
5
|
-
* File containing the interfaces for Web JS SDK.
|
|
6
|
-
*/
|
|
7
|
-
import { ITelemetryItem, IConfiguration, IAppInsightsCore } from "@microsoft/applicationinsights-core-js";
|
|
8
|
-
import { EventLatencyValue, EventPersistenceValue, EventSendType, FieldValueSanitizerType } from "./Enums";
|
|
9
|
-
/**
|
|
10
|
-
* An interface used to create an event property value along with tagging it as PII, or customer content.
|
|
11
|
-
* <b>Caution:</b> Customer content and PII are mutually exclusive. You can use only one of them at a time.
|
|
12
|
-
* If you use both, then the property will be considered invalid, and therefore won't be sent.
|
|
13
|
-
*/
|
|
14
|
-
export interface IEventProperty {
|
|
15
|
-
/**
|
|
16
|
-
* The value for the property.
|
|
17
|
-
*/
|
|
18
|
-
value: string | number | boolean | string[] | number[] | boolean[];
|
|
19
|
-
/**
|
|
20
|
-
* [Optional] The value kind associated with property value. The constant enum ValueKind should be used to specify the
|
|
21
|
-
* different kinds.
|
|
22
|
-
*/
|
|
23
|
-
kind?: number;
|
|
24
|
-
/**
|
|
25
|
-
* [Optional] The data type for the property. Valid values accepted by onecollector are
|
|
26
|
-
* "string", "bool", "double", "int64", "datetime", "guid".
|
|
27
|
-
* The EventPropertyType constant enum should be used to specify the different property type values.
|
|
28
|
-
*/
|
|
29
|
-
propertyType?: number;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* An interface used to create an event, along with its name, properties, type, timestamp, and priority.
|
|
33
|
-
*/
|
|
34
|
-
export interface IExtendedTelemetryItem extends ITelemetryItem {
|
|
35
|
-
/**
|
|
36
|
-
* Properties to be captured about the telemetry item.
|
|
37
|
-
* Custom properties (alternatively referred to as Part C properties for a Common Schema event) can be
|
|
38
|
-
* directly added under data.
|
|
39
|
-
*/
|
|
40
|
-
data?: {
|
|
41
|
-
[key: string]: string | number | boolean | string[] | number[] | boolean[] | IEventProperty | object;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Telemetry properties pertaining to domain about which data is being captured. Example, duration, referrerUri for browser page.
|
|
45
|
-
* These are alternatively referred to as Part B properties for a Common Schema event.
|
|
46
|
-
*/
|
|
47
|
-
baseData?: {
|
|
48
|
-
[key: string]: string | number | boolean | string[] | number[] | boolean[] | IEventProperty | object;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* An EventLatency value, that specifies the latency for the event.The EventLatency constant should be
|
|
52
|
-
* used to specify the different latency values.
|
|
53
|
-
*/
|
|
54
|
-
latency?: number | EventLatencyValue;
|
|
55
|
-
/**
|
|
56
|
-
* [Optional] An EventPersistence value, that specifies the persistence for the event. The EventPersistence constant
|
|
57
|
-
* should be used to specify the different persistence values.
|
|
58
|
-
*/
|
|
59
|
-
persistence?: number | EventPersistenceValue;
|
|
60
|
-
/**
|
|
61
|
-
* [Optional] A boolean that specifies whether the event should be sent as a sync request.
|
|
62
|
-
*/
|
|
63
|
-
sync?: boolean | EventSendType;
|
|
64
|
-
/**
|
|
65
|
-
* [Optional] A timings object.
|
|
66
|
-
*/
|
|
67
|
-
timings?: IEventTiming;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* The IExtendedConfiguration interface holds the configuration details passed to core during initialize.
|
|
71
|
-
*/
|
|
72
|
-
export interface IExtendedConfiguration extends IConfiguration {
|
|
73
|
-
/**
|
|
74
|
-
* [Optional] The property storage override that should be used to store
|
|
75
|
-
* internal SDK properties, otherwise stored as cookies. It is needed where cookies are not available.
|
|
76
|
-
*/
|
|
77
|
-
propertyStorageOverride?: IPropertyStorageOverride;
|
|
78
|
-
/**
|
|
79
|
-
* [Optional] A boolean that indicated whether to disable the use of cookies by the 1DS Web SDK. The cookies added by the SDK are
|
|
80
|
-
* MicrosoftApplicationsTelemetryDeviceId. If cookies are disabled, then session events are not sent unless propertyStorageOverride
|
|
81
|
-
* is provided to store the values elsewhere.
|
|
82
|
-
*/
|
|
83
|
-
disableCookiesUsage?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* [Optional] Name of the Anon cookie. The value will be set in the qsp header to collector requests. Collector will use this value to look for specific cookie to use for anid property.
|
|
86
|
-
*/
|
|
87
|
-
anonCookieName?: string;
|
|
88
|
-
/**
|
|
89
|
-
* [Optional] Disables additional internal event timings that are added during processing of events, the timings are not sent as part telemetry items to the server
|
|
90
|
-
*/
|
|
91
|
-
disableEventTimings?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* event: { "somedata.embeddedvalue": 123 }
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
enableCompoundKey?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload
|
|
102
|
-
* event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
|
|
103
|
-
* Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
|
|
104
|
-
*/
|
|
105
|
-
disablePageUnloadEvents?: string[];
|
|
106
|
-
/**
|
|
107
|
-
* [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event
|
|
108
|
-
* hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
|
|
109
|
-
* Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
|
|
110
|
-
*/
|
|
111
|
-
disablePageShowEvents?: string[];
|
|
112
|
-
/**
|
|
113
|
-
* Add "&w=0" parameter to support UA Parsing when web-workers don't have access to Document.
|
|
114
|
-
* Default is false
|
|
115
|
-
*/
|
|
116
|
-
enableWParam?: boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* An interface used for telemetry event timings.
|
|
120
|
-
*/
|
|
121
|
-
export interface IEventTiming {
|
|
122
|
-
/**
|
|
123
|
-
* Time when 1DS Core calls track
|
|
124
|
-
*/
|
|
125
|
-
trackStart?: number;
|
|
126
|
-
/**
|
|
127
|
-
* Array of times when each plugin configured in 1DS calls processTelemetry method
|
|
128
|
-
*/
|
|
129
|
-
processTelemetryStart?: {
|
|
130
|
-
[key: string]: number;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Array of times when a specific channel tried to send the telemetry to configured endpoint
|
|
134
|
-
*/
|
|
135
|
-
sendEventStart?: {
|
|
136
|
-
[key: string]: number;
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* Array of times when a specific channel received a response from endpoint or request timed out
|
|
140
|
-
*/
|
|
141
|
-
sendEventCompleted?: {
|
|
142
|
-
[key: string]: number;
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Array of times when a specific channel started serialization of the telemetry event
|
|
146
|
-
*/
|
|
147
|
-
serializationStart?: {
|
|
148
|
-
[key: string]: number;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Array of times when a specific channel completed serialization of the telemetry event
|
|
152
|
-
*/
|
|
153
|
-
serializationCompleted?: {
|
|
154
|
-
[key: string]: number;
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* The IPropertyStorageOverride interface provides a custom interface for storing internal SDK properties - otherwise they are
|
|
159
|
-
* stored as cookies.
|
|
160
|
-
* You need this interface when you intend to run auto collection for common properties, or when you log a session in
|
|
161
|
-
* a non browser environment.
|
|
162
|
-
*/
|
|
163
|
-
export interface IPropertyStorageOverride {
|
|
164
|
-
/**
|
|
165
|
-
* A function for passing key value pairs to be stored.
|
|
166
|
-
* @param key - The key for the key value pair.
|
|
167
|
-
* @param value - The value for the key value pair.
|
|
168
|
-
*/
|
|
169
|
-
setProperty: (key: string, value: string) => void;
|
|
170
|
-
/**
|
|
171
|
-
* A function that gets a value for a given key.
|
|
172
|
-
* @param key - The key for which the value must be fetched.
|
|
173
|
-
*/
|
|
174
|
-
getProperty: (key: string) => string;
|
|
175
|
-
}
|
|
176
|
-
export interface IExtendedAppInsightsCore extends IAppInsightsCore {
|
|
177
|
-
/**
|
|
178
|
-
* [Optional] Get method to retrieve w parameter
|
|
179
|
-
*/
|
|
180
|
-
getWParam?: () => number;
|
|
181
|
-
}
|
|
182
|
-
export type FieldValueSanitizerFunc = (details: IFieldSanitizerDetails) => IEventProperty | null;
|
|
183
|
-
export type FieldValueSanitizerTypes = string | number | boolean | object | string[] | number[] | boolean[] | IEventProperty;
|
|
184
|
-
/**
|
|
185
|
-
* This interface defines the object that is passed to any provided FieldValueSanitizerFunc, it provides not only the value to be sanitized but also
|
|
186
|
-
* some context about the value like it's location within the envelope (serialized object), the format is defined via the
|
|
187
|
-
* [Common Schema 4.0](https://1dsdocs.azurewebsites.net/schema/README.html) specification.
|
|
188
|
-
*/
|
|
189
|
-
export interface IFieldSanitizerDetails {
|
|
190
|
-
/**
|
|
191
|
-
* The path within the event where the value is stored
|
|
192
|
-
*/
|
|
193
|
-
path: string;
|
|
194
|
-
/**
|
|
195
|
-
* The name of the field with the event path that will store the value
|
|
196
|
-
*/
|
|
197
|
-
name: string;
|
|
198
|
-
/**
|
|
199
|
-
* Identifies the type of the property value
|
|
200
|
-
*/
|
|
201
|
-
type: FieldValueSanitizerType;
|
|
202
|
-
/**
|
|
203
|
-
* The value for the property.
|
|
204
|
-
*/
|
|
205
|
-
prop: IEventProperty;
|
|
206
|
-
/**
|
|
207
|
-
* A reference to the value sanitizer that created the details
|
|
208
|
-
*/
|
|
209
|
-
sanitizer: IValueSanitizer;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* This interface is used during the serialization of individual fields when converting the events into envelope (serialized object) which is sent to the services,
|
|
213
|
-
* the format is defined via the [Common Schema 4.0](https://1dsdocs.azurewebsites.net/schema/README.html) specification. The path and field names used are based
|
|
214
|
-
* on how the data is serialized to the service (CS 4.0 location) and not specifically the location on the event object you pass into the track methods (unless they are the same).
|
|
215
|
-
*/
|
|
216
|
-
export interface IFieldValueSanitizerProvider {
|
|
217
|
-
/**
|
|
218
|
-
* Does this field value sanitizer handle this path / field combination
|
|
219
|
-
* @param path - The field path
|
|
220
|
-
* @param name - The name of the field
|
|
221
|
-
*/
|
|
222
|
-
handleField(path: string, name: string): boolean;
|
|
223
|
-
/**
|
|
224
|
-
* Get the field sanitizer for this type of field based on the field type, value kind and/or event property type
|
|
225
|
-
* @param path - The field path
|
|
226
|
-
* @param name - The name of the field
|
|
227
|
-
* @param theType - The type of field
|
|
228
|
-
* @param theKind - The value kind of the field
|
|
229
|
-
* @param propType - The property type of the field
|
|
230
|
-
*/
|
|
231
|
-
getSanitizer(path: string, name: string, theType: FieldValueSanitizerType, theKind?: number, propType?: number): FieldValueSanitizerFunc | null | undefined;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* This interface is used during the serialization of events into envelope (serialized object) which is sent to the services, the format is defined via the
|
|
235
|
-
* [Common Schema 4.0](https://1dsdocs.azurewebsites.net/schema/README.html) specification. The path and field names used are based on how the data is serialized
|
|
236
|
-
* to the service (CS 4.0 location) and not specifically the location on the event object you pass into the track methods (unless they are the same).
|
|
237
|
-
*/
|
|
238
|
-
export interface IValueSanitizer {
|
|
239
|
-
/**
|
|
240
|
-
* Add a value sanitizer as a fallback sanitizer if this sanitizer can't handle the path/name.
|
|
241
|
-
*/
|
|
242
|
-
addSanitizer: (sanitizer: IValueSanitizer) => void;
|
|
243
|
-
/**
|
|
244
|
-
* Adds a field sanitizer to the evaluation list
|
|
245
|
-
*/
|
|
246
|
-
addFieldSanitizer: (fieldSanitizer: IFieldValueSanitizerProvider) => void;
|
|
247
|
-
/**
|
|
248
|
-
* Does this field value sanitizer handle this path / field combination
|
|
249
|
-
* @param path - The field path
|
|
250
|
-
* @param name - The name of the field
|
|
251
|
-
*/
|
|
252
|
-
handleField: (path: string, name: string) => boolean;
|
|
253
|
-
/**
|
|
254
|
-
* Sanitizes the value. It checks the that the property name and value are valid. It also
|
|
255
|
-
* checks/populates the correct type and pii of the property value.
|
|
256
|
-
* @param path - The root path of the property
|
|
257
|
-
* @param name - The property name.
|
|
258
|
-
* @param value - The property value or an IEventProperty containing value, type ,pii and customer content.
|
|
259
|
-
* @param stringifyObjects - If supplied tells the sanitizer that it should JSON stringify() objects
|
|
260
|
-
* @returns IEventProperty containing valid name, value, pii and type or null if invalid.
|
|
261
|
-
*/
|
|
262
|
-
value: (path: string, name: string, value: FieldValueSanitizerTypes, stringifyObjects?: boolean) => IEventProperty | null;
|
|
263
|
-
/**
|
|
264
|
-
* Sanitizes the Property. It checks the that the property name and value are valid. It also
|
|
265
|
-
* checks/populates the correct type and pii of the property value.
|
|
266
|
-
* @param path - The root path of the property
|
|
267
|
-
* @param name - The property name.
|
|
268
|
-
* @param property - The property value or an IEventProperty containing value, type ,pii and customer content.
|
|
269
|
-
* @param stringifyObjects - If supplied tells the sanitizer that it should JSON stringify() objects
|
|
270
|
-
* @returns IEventProperty containing valid name, value, pii and type or null if invalid.
|
|
271
|
-
*/
|
|
272
|
-
property: (path: string, name: string, property: IEventProperty, stringifyObjects?: boolean) => IEventProperty | null;
|
|
273
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESPromise.ts
|
|
3
|
-
* @author Nev Wylie (newylie))
|
|
4
|
-
* @copyright Microsoft 2019
|
|
5
|
-
* Simplified wrapper to provide ES6 style Promise callback handling for older browsers
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* This defines the handler function for when a promise is resolved.
|
|
9
|
-
* @param value This is the value passed as part of resolving the Promise
|
|
10
|
-
* @return This may return a value, another Promise or void. See [[then]] for how the value is handled.
|
|
11
|
-
*/
|
|
12
|
-
export type ESPromiseOnResolvedFunc<T> = (value: T) => T | ESPromise<T | any> | void;
|
|
13
|
-
/**
|
|
14
|
-
* This defines the handler function for when a promise is rejected.
|
|
15
|
-
* @param value This is the value passed as part of resolving the Promise
|
|
16
|
-
* @return This may return a value, another Promise or void. @see then for how the value is handled.
|
|
17
|
-
*/
|
|
18
|
-
export type ESPromiseOnRejectedFunc<T> = (reason: any) => T | ESPromise<T | any> | void;
|
|
19
|
-
/**
|
|
20
|
-
* Defines the signature of the resolve function passed to the resolverFunc (in the Promise constructor)
|
|
21
|
-
* @param value The value to resolve the Promise with
|
|
22
|
-
* @returns Nothing
|
|
23
|
-
*/
|
|
24
|
-
export type ResolverResolveFunc<T> = (value?: T | void) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Defines the signature of the reject function passed to the resolverFunc (in the Promise constructor)
|
|
27
|
-
* @param value The value to reject the Promise with
|
|
28
|
-
* @returns Nothing
|
|
29
|
-
*/
|
|
30
|
-
export type ResolverRejectFunc<T> = (reason?: T | Error | void) => void;
|
|
31
|
-
/**
|
|
32
|
-
* Simplified wrapper to provide ES6 style Promise callback handling for older browsers
|
|
33
|
-
*/
|
|
34
|
-
export default class ESPromise<T> {
|
|
35
|
-
/**
|
|
36
|
-
* The Promise.resolve() method returns a Promise object that is resolved with a given value. If the value is a promise, that promise is returned;
|
|
37
|
-
* if the value is a thenable (i.e. has a "then" method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise
|
|
38
|
-
* the returned promise will be fulfilled with the value. This function flattens nested layers of promise-like objects (e.g. a promise that resolves
|
|
39
|
-
* to a promise that resolves to something) into a single layer.
|
|
40
|
-
* @param value Argument to be resolved by this Promise. Can also be a Promise or a thenable to resolve.
|
|
41
|
-
*/
|
|
42
|
-
static resolve<T>(value?: any): ESPromise<any>;
|
|
43
|
-
/**
|
|
44
|
-
* The Promise.reject() method returns a Promise object that is rejected with a given reason.
|
|
45
|
-
* @param reason The reason why this Promise rejected.
|
|
46
|
-
*/
|
|
47
|
-
static reject<T>(reason?: T | Error | void): ESPromise<T>;
|
|
48
|
-
/**
|
|
49
|
-
* The Promise.all() method returns a single Promise that resolves when all of the promises passed as an iterable
|
|
50
|
-
* have resolved or when the iterable contains no promises. It rejects with the reason of the first promise that
|
|
51
|
-
* rejects. There is no implied ordering in the execution of the array of Promises given. On some computers, they
|
|
52
|
-
* may be executed in parallel, or in some sense concurrently, while on others they may be executed serially. For
|
|
53
|
-
* this reason, there must be no dependency in any Promise on the order of execution of the Promises.
|
|
54
|
-
* This method can be useful for aggregating the results of multiple promises.
|
|
55
|
-
* FulfillmentSection - The returned promise is fulfilled with an array containing all the values of the iterable
|
|
56
|
-
* passed as argument (also non-promise values).
|
|
57
|
-
* If an empty iterable is passed, then this method returns (synchronously) an already resolved promise.
|
|
58
|
-
* If all of the passed-in promises fulfill, or are not promises, the promise returned by Promise.all is fulfilled
|
|
59
|
-
* asynchronously.
|
|
60
|
-
* RejectionSection - If any of the passed-in promises reject, Promise.all asynchronously rejects with the value of
|
|
61
|
-
* the promise that rejected, whether or not the other promises have resolved.
|
|
62
|
-
* @param iterable
|
|
63
|
-
*/
|
|
64
|
-
static all<T>(iterable: any[]): ESPromise<T>;
|
|
65
|
-
/**
|
|
66
|
-
* The race function returns a Promise that is settled the same way (and takes the same value) as the first promise
|
|
67
|
-
* that settles amongst the promises of the iterable passed as an argument.
|
|
68
|
-
* If the iterable passed is empty, the promise returned will be forever pending.
|
|
69
|
-
* If the iterable contains one or more non-promise value and/or an already settled promise, then Promise.race will
|
|
70
|
-
* resolve to the first of these values found in the iterable.
|
|
71
|
-
* @param iterable
|
|
72
|
-
*/
|
|
73
|
-
static race<T>(iterable: any[]): ESPromise<T>;
|
|
74
|
-
/**
|
|
75
|
-
* The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.
|
|
76
|
-
* @param resolverFunc A function that is passed with the arguments resolve and reject. The executor function is executed
|
|
77
|
-
* immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise
|
|
78
|
-
* constructor even returns the created object). The resolve and reject functions, when called, resolve or reject the promise,
|
|
79
|
-
* respectively. The executor normally initiates some asynchronous work, and then, once that completes, either calls the resolve
|
|
80
|
-
* function to resolve the promise or else rejects it if an error occurred. If an error is thrown in the executor function, the
|
|
81
|
-
* promise is rejected. The return value of the executor is ignored.
|
|
82
|
-
*/
|
|
83
|
-
constructor(resolverFunc: (resolve: ResolverResolveFunc<T>, reject: ResolverRejectFunc<T>) => void);
|
|
84
|
-
/**
|
|
85
|
-
* The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.
|
|
86
|
-
* @param onResolved A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value. If it is not a
|
|
87
|
-
* function, it is internally replaced with an "Identity" function (it returns the received argument).
|
|
88
|
-
* @param onRejected A Function called if the Promise is rejected. This function has one argument, the rejection reason. If it is not a
|
|
89
|
-
* function, it is internally replaced with a "Thrower" function (it throws an error it received as argument).
|
|
90
|
-
* @returns Once a Promise is fulfilled or rejected, the respective handler function (onFulfilled or onRejected) will be called asynchronously
|
|
91
|
-
* (scheduled in the current thread loop). The behavior of the handler function follows a specific set of rules. If a handler function:
|
|
92
|
-
* - returns a value, the promise returned by then gets resolved with the returned value as its value;
|
|
93
|
-
* - doesn't return anything, the promise returned by then gets resolved with an undefined value;
|
|
94
|
-
* - throws an error, the promise returned by then gets rejected with the thrown error as its value;
|
|
95
|
-
* - returns an already fulfilled promise, the promise returned by then gets fulfilled with that promise's value as its value;
|
|
96
|
-
* - returns an already rejected promise, the promise returned by then gets rejected with that promise's value as its value;
|
|
97
|
-
* - returns another pending promise object, the resolution/rejection of the promise returned by then will be subsequent to the
|
|
98
|
-
* resolution/rejection of the promise returned by the handler. Also, the value of the promise returned by then will be the same as the value of the promise returned by the handler.
|
|
99
|
-
*/
|
|
100
|
-
then(onResolved: ESPromiseOnResolvedFunc<T>, onRejected?: ESPromiseOnRejectedFunc<T>): ESPromise<T>;
|
|
101
|
-
/**
|
|
102
|
-
* The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling Promise.prototype.then(undefined, onRejected)
|
|
103
|
-
* (in fact, calling obj.catch(onRejected) internally calls obj.then(undefined, onRejected)). This means that you have to provide an onRejected function
|
|
104
|
-
* even if you want to fall back to an undefined result value - for example obj.catch(() => {}).
|
|
105
|
-
* @param onRejected A Function called when the Promise is rejected. This function has one argument: reason The rejection reason.
|
|
106
|
-
* @returns Internally calls Promise.prototype.then on the object upon which it was called, passing the parameters undefined and the received
|
|
107
|
-
* onRejected handler. Returns the value of that call, which is a Promise.
|
|
108
|
-
*/
|
|
109
|
-
catch(onRejected: ESPromiseOnRejectedFunc<T>): ESPromise<T>;
|
|
110
|
-
}
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* 1DS JS SDK Core, 3.2.12
|
|
3
|
-
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
-
* (Microsoft Internal Only)
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* ESPromise.ts
|
|
8
|
-
* @author Nev Wylie (newylie))
|
|
9
|
-
* @copyright Microsoft 2019
|
|
10
|
-
* Simplified wrapper to provide ES6 style Promise callback handling for older browsers
|
|
11
|
-
*/
|
|
12
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
13
|
-
import { isFunction } from "@microsoft/applicationinsights-core-js";
|
|
14
|
-
/**
|
|
15
|
-
* @ignore -- Don't include in the generated documentation
|
|
16
|
-
* Using a local variable to assist with minfication
|
|
17
|
-
*/
|
|
18
|
-
var _isFunction = isFunction;
|
|
19
|
-
/**
|
|
20
|
-
* @ignore -- Don't include in the generated documentation
|
|
21
|
-
* This function will be used as onFulfilled handler for any Promise found in the iterable passed to Promise.all.
|
|
22
|
-
* The goal here is to capture in a closure the index of the current item from the iterable. If we did not create
|
|
23
|
-
* this closure, the captured index variable would be the same one that the for loop updates and thus would always
|
|
24
|
-
* be pointing to the last index in the iterable by the time that the onFulfilled handler is called.
|
|
25
|
-
* However, note that for the resolvedCallback callback we want the opposite. For this one we do want to capture
|
|
26
|
-
* the same variable that the for loop updates so that we have the full count of pending promises by the time
|
|
27
|
-
* the onFulfilled handlers start getting called.
|
|
28
|
-
* @param values The resolving promise values
|
|
29
|
-
* @param index The index of this callback function
|
|
30
|
-
* @param resolvedCallback THe callback function used to check if the "all" promise is complete
|
|
31
|
-
*/
|
|
32
|
-
function _createPromiseAllOnResolvedFunction(values, index, resolvedCallback) {
|
|
33
|
-
return function (value) {
|
|
34
|
-
values[index] = value;
|
|
35
|
-
resolvedCallback();
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Simplified wrapper to provide ES6 style Promise callback handling for older browsers
|
|
40
|
-
*/
|
|
41
|
-
var ESPromise = /** @class */ (function () {
|
|
42
|
-
/**
|
|
43
|
-
* The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.
|
|
44
|
-
* @param resolverFunc A function that is passed with the arguments resolve and reject. The executor function is executed
|
|
45
|
-
* immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise
|
|
46
|
-
* constructor even returns the created object). The resolve and reject functions, when called, resolve or reject the promise,
|
|
47
|
-
* respectively. The executor normally initiates some asynchronous work, and then, once that completes, either calls the resolve
|
|
48
|
-
* function to resolve the promise or else rejects it if an error occurred. If an error is thrown in the executor function, the
|
|
49
|
-
* promise is rejected. The return value of the executor is ignored.
|
|
50
|
-
*/
|
|
51
|
-
function ESPromise(resolverFunc) {
|
|
52
|
-
var _state = 0 /* PromiseState.Pending */;
|
|
53
|
-
var _settledValue = null;
|
|
54
|
-
var _queue = [];
|
|
55
|
-
dynamicProto(ESPromise, this, function (_this) {
|
|
56
|
-
_this.then = function (onResolved, onRejected) {
|
|
57
|
-
return new ESPromise(function (resolve, reject) {
|
|
58
|
-
// Queue the new promise returned to be resolved or rejected
|
|
59
|
-
// when this promise settles.
|
|
60
|
-
_enqueue(onResolved, onRejected, resolve, reject);
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
_this["catch"] = function (onRejected) {
|
|
64
|
-
return _this.then(null, onRejected);
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
function _enqueue(onResolved, onRejected, resolve, reject) {
|
|
68
|
-
_queue.push(function () {
|
|
69
|
-
var value;
|
|
70
|
-
try {
|
|
71
|
-
// First call the onFulfilled or onRejected handler, on the settled value
|
|
72
|
-
// of this promise. If the corresponding handler does not exist, simply
|
|
73
|
-
// pass through the settled value.
|
|
74
|
-
if (_state === 1 /* PromiseState.Resolved */) {
|
|
75
|
-
value = _isFunction(onResolved) ? onResolved(_settledValue) : _settledValue;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
value = _isFunction(onRejected) ? onRejected(_settledValue) : _settledValue;
|
|
79
|
-
}
|
|
80
|
-
if (value instanceof ESPromise) {
|
|
81
|
-
// The called handlers returned a new promise, so the chained promise
|
|
82
|
-
// will follow the state of this promise.
|
|
83
|
-
value.then(resolve, reject);
|
|
84
|
-
}
|
|
85
|
-
else if (_state === 2 /* PromiseState.Rejected */ && !_isFunction(onRejected)) {
|
|
86
|
-
// If there wasn't an onRejected handler and this promise is rejected, then
|
|
87
|
-
// the chained promise also rejects with the same reason.
|
|
88
|
-
reject(value);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
// If this promise is fulfilled, then the chained promise is also fulfilled
|
|
92
|
-
// with either the settled value of this promise (if no onFulfilled handler
|
|
93
|
-
// was available) or the return value of the handler. If this promise is
|
|
94
|
-
// rejected and there was an onRejected handler, then the chained promise is
|
|
95
|
-
// fulfilled with the return value of the handler.
|
|
96
|
-
resolve(value);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
// The chained promise will reject if there is any exception thrown while
|
|
101
|
-
// calling the onFulfilled or onRejected handlers.
|
|
102
|
-
reject(error);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
// If this promise is already settled, then immediately process the callback we
|
|
107
|
-
// just added to the queue.
|
|
108
|
-
if (_state !== 0 /* PromiseState.Pending */) {
|
|
109
|
-
_processQueue();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function _processQueue() {
|
|
113
|
-
if (_queue.length > 0) {
|
|
114
|
-
// The onFulfilled and onRejected handlers must be called asynchronously. Thus,
|
|
115
|
-
// we make a copy of the queue and work on it once the current call stack unwinds.
|
|
116
|
-
var pending_1 = _queue.slice();
|
|
117
|
-
_queue = [];
|
|
118
|
-
setTimeout(function () {
|
|
119
|
-
for (var i = 0, len = pending_1.length; i < len; ++i) {
|
|
120
|
-
try {
|
|
121
|
-
pending_1[i]();
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
// Don't let 1 failing handler break all others
|
|
125
|
-
// TODO (newylie): Add some form of error reporting (i.e. Call any registered JS error handler so the error is reported)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}, 0);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function _resolve(value) {
|
|
132
|
-
if (_state === 0 /* PromiseState.Pending */) {
|
|
133
|
-
_settledValue = value;
|
|
134
|
-
_state = 1 /* PromiseState.Resolved */;
|
|
135
|
-
_processQueue();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function _reject(reason) {
|
|
139
|
-
if (_state === 0 /* PromiseState.Pending */) {
|
|
140
|
-
_settledValue = reason;
|
|
141
|
-
_state = 2 /* PromiseState.Rejected */;
|
|
142
|
-
_processQueue();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
(function _initialize() {
|
|
146
|
-
if (!_isFunction(resolverFunc)) {
|
|
147
|
-
throw new TypeError("ESPromise: resolvedFunc argument is not a Function");
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
resolverFunc(_resolve, _reject);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
// This promise will immediately reject if any exception is thrown
|
|
154
|
-
// from within the executor function.
|
|
155
|
-
_reject(error);
|
|
156
|
-
}
|
|
157
|
-
})();
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* The Promise.resolve() method returns a Promise object that is resolved with a given value. If the value is a promise, that promise is returned;
|
|
161
|
-
* if the value is a thenable (i.e. has a "then" method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise
|
|
162
|
-
* the returned promise will be fulfilled with the value. This function flattens nested layers of promise-like objects (e.g. a promise that resolves
|
|
163
|
-
* to a promise that resolves to something) into a single layer.
|
|
164
|
-
* @param value Argument to be resolved by this Promise. Can also be a Promise or a thenable to resolve.
|
|
165
|
-
*/
|
|
166
|
-
ESPromise.resolve = function (value) {
|
|
167
|
-
if (value instanceof ESPromise) {
|
|
168
|
-
// Value is a Promise so just return it
|
|
169
|
-
return value;
|
|
170
|
-
}
|
|
171
|
-
else if (value && _isFunction(value.then)) {
|
|
172
|
-
// Value looks like a promise or thenable (has a then function)
|
|
173
|
-
return new ESPromise(function (resolve, reject) {
|
|
174
|
-
try {
|
|
175
|
-
value.then(resolve, reject);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
reject(error);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
return new ESPromise(function (resolve) {
|
|
183
|
-
resolve(value);
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* The Promise.reject() method returns a Promise object that is rejected with a given reason.
|
|
188
|
-
* @param reason The reason why this Promise rejected.
|
|
189
|
-
*/
|
|
190
|
-
ESPromise.reject = function (reason) {
|
|
191
|
-
return new ESPromise(function (resolve, reject) {
|
|
192
|
-
reject(reason);
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* The Promise.all() method returns a single Promise that resolves when all of the promises passed as an iterable
|
|
197
|
-
* have resolved or when the iterable contains no promises. It rejects with the reason of the first promise that
|
|
198
|
-
* rejects. There is no implied ordering in the execution of the array of Promises given. On some computers, they
|
|
199
|
-
* may be executed in parallel, or in some sense concurrently, while on others they may be executed serially. For
|
|
200
|
-
* this reason, there must be no dependency in any Promise on the order of execution of the Promises.
|
|
201
|
-
* This method can be useful for aggregating the results of multiple promises.
|
|
202
|
-
* FulfillmentSection - The returned promise is fulfilled with an array containing all the values of the iterable
|
|
203
|
-
* passed as argument (also non-promise values).
|
|
204
|
-
* If an empty iterable is passed, then this method returns (synchronously) an already resolved promise.
|
|
205
|
-
* If all of the passed-in promises fulfill, or are not promises, the promise returned by Promise.all is fulfilled
|
|
206
|
-
* asynchronously.
|
|
207
|
-
* RejectionSection - If any of the passed-in promises reject, Promise.all asynchronously rejects with the value of
|
|
208
|
-
* the promise that rejected, whether or not the other promises have resolved.
|
|
209
|
-
* @param iterable
|
|
210
|
-
*/
|
|
211
|
-
ESPromise.all = function (iterable) {
|
|
212
|
-
if (!iterable || !iterable.length) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
return new ESPromise(function (resolve, reject) {
|
|
216
|
-
try {
|
|
217
|
-
var values_1 = [];
|
|
218
|
-
var pending_2 = 0;
|
|
219
|
-
for (var lp = 0; lp < iterable.length; lp++) {
|
|
220
|
-
var item = iterable[lp];
|
|
221
|
-
// Quick and direct check for a Promise (will also catch a thenable)
|
|
222
|
-
if (item && _isFunction(item.then)) {
|
|
223
|
-
pending_2++;
|
|
224
|
-
item.then(_createPromiseAllOnResolvedFunction(values_1, lp, function () {
|
|
225
|
-
if (--pending_2 === 0) {
|
|
226
|
-
resolve(values_1);
|
|
227
|
-
}
|
|
228
|
-
}), reject);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
values_1[lp] = item;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (pending_2 === 0) {
|
|
235
|
-
// All promises were either resolved or where not a promise
|
|
236
|
-
setTimeout(function () {
|
|
237
|
-
resolve(values_1);
|
|
238
|
-
}, 0);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
reject(error);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
|
-
/**
|
|
247
|
-
* The race function returns a Promise that is settled the same way (and takes the same value) as the first promise
|
|
248
|
-
* that settles amongst the promises of the iterable passed as an argument.
|
|
249
|
-
* If the iterable passed is empty, the promise returned will be forever pending.
|
|
250
|
-
* If the iterable contains one or more non-promise value and/or an already settled promise, then Promise.race will
|
|
251
|
-
* resolve to the first of these values found in the iterable.
|
|
252
|
-
* @param iterable
|
|
253
|
-
*/
|
|
254
|
-
ESPromise.race = function (iterable) {
|
|
255
|
-
return new ESPromise(function (resolve, reject) {
|
|
256
|
-
if (!iterable || !iterable.length) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
try {
|
|
260
|
-
var _loop_1 = function (lp) {
|
|
261
|
-
var item = iterable[lp];
|
|
262
|
-
// Quick and direct check for a Promise (will also catch a thenable)
|
|
263
|
-
if (item && _isFunction(item.then)) {
|
|
264
|
-
item.then(resolve, reject);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
setTimeout(function () {
|
|
268
|
-
resolve(item);
|
|
269
|
-
}, 0);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
for (var lp = 0; lp < iterable.length; lp++) {
|
|
273
|
-
_loop_1(lp);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
catch (error) {
|
|
277
|
-
reject(error);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
};
|
|
281
|
-
// Removed Stub for ESPromise.prototype.then.
|
|
282
|
-
// Removed Stub for ESPromise.prototype["catch"].
|
|
283
|
-
return ESPromise;
|
|
284
|
-
}());
|
|
285
|
-
export default ESPromise;
|
|
286
|
-
//# sourceMappingURL=ESPromise.js.map
|