@splitsoftware/splitio-commons 1.4.1-rc.1 → 1.4.1-rc.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.
- package/cjs/storages/inMemory/EventsCacheInMemory.js +2 -2
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +10 -1
- package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +2 -2
- package/cjs/sync/submitters/submitter.js +3 -7
- package/esm/storages/inMemory/EventsCacheInMemory.js +2 -2
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +10 -1
- package/esm/storages/inMemory/ImpressionsCacheInMemory.js +2 -2
- package/esm/sync/submitters/submitter.js +3 -7
- package/package.json +1 -1
- package/src/listeners/browser.ts +1 -1
- package/src/storages/inMemory/EventsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +8 -1
- package/src/storages/inMemory/ImpressionsCacheInMemory.ts +2 -2
- package/src/storages/types.ts +2 -2
- package/src/sync/submitters/submitter.ts +6 -10
- package/types/storages/inMemory/EventsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +1 -1
- package/types/storages/types.d.ts +2 -2
- package/types/sync/submitters/submitter.d.ts +1 -1
|
@@ -37,10 +37,10 @@ var EventsCacheInMemory = /** @class */ (function () {
|
|
|
37
37
|
/**
|
|
38
38
|
* Pop the collected data, used as payload for posting.
|
|
39
39
|
*/
|
|
40
|
-
EventsCacheInMemory.prototype.pop = function () {
|
|
40
|
+
EventsCacheInMemory.prototype.pop = function (toMerge) {
|
|
41
41
|
var data = this.queue;
|
|
42
42
|
this.clear();
|
|
43
|
-
return data;
|
|
43
|
+
return toMerge ? toMerge.concat(data) : data;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* Check if the cache is empty.
|
|
@@ -23,9 +23,18 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
23
23
|
/**
|
|
24
24
|
* Pop the collected data, used as payload for posting.
|
|
25
25
|
*/
|
|
26
|
-
ImpressionCountsCacheInMemory.prototype.pop = function () {
|
|
26
|
+
ImpressionCountsCacheInMemory.prototype.pop = function (toMerge) {
|
|
27
27
|
var data = this.cache;
|
|
28
28
|
this.clear();
|
|
29
|
+
if (toMerge) {
|
|
30
|
+
Object.keys(data).forEach(function (key) {
|
|
31
|
+
if (toMerge[key])
|
|
32
|
+
toMerge[key] += data[key];
|
|
33
|
+
else
|
|
34
|
+
toMerge[key] = data[key];
|
|
35
|
+
});
|
|
36
|
+
return toMerge;
|
|
37
|
+
}
|
|
29
38
|
return data;
|
|
30
39
|
};
|
|
31
40
|
/**
|
|
@@ -35,10 +35,10 @@ var ImpressionsCacheInMemory = /** @class */ (function () {
|
|
|
35
35
|
/**
|
|
36
36
|
* Pop the collected data, used as payload for posting.
|
|
37
37
|
*/
|
|
38
|
-
ImpressionsCacheInMemory.prototype.pop = function () {
|
|
38
|
+
ImpressionsCacheInMemory.prototype.pop = function (toMerge) {
|
|
39
39
|
var data = this.queue;
|
|
40
40
|
this.clear();
|
|
41
|
-
return data;
|
|
41
|
+
return toMerge ? toMerge.concat(data) : data;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Check if the cache is empty.
|
|
@@ -12,13 +12,9 @@ function submitterFactory(log, postClient, sourceCache, postRate, dataName, from
|
|
|
12
12
|
var retries = 0;
|
|
13
13
|
var data;
|
|
14
14
|
function postData() {
|
|
15
|
-
if (!data)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// we clear the cache to track new items, while `data` is used for retries
|
|
19
|
-
data = sourceCache.pop();
|
|
20
|
-
}
|
|
21
|
-
// @ts-ignore
|
|
15
|
+
if (sourceCache.isEmpty() && !data)
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
data = sourceCache.pop(data);
|
|
22
18
|
var dataCountMessage = typeof data.length === 'number' ? data.length + " " + dataName : dataName;
|
|
23
19
|
log[debugLogs ? 'debug' : 'info'](constants_1.SUBMITTERS_PUSH, [dataCountMessage]);
|
|
24
20
|
var jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
|
|
@@ -34,10 +34,10 @@ var EventsCacheInMemory = /** @class */ (function () {
|
|
|
34
34
|
/**
|
|
35
35
|
* Pop the collected data, used as payload for posting.
|
|
36
36
|
*/
|
|
37
|
-
EventsCacheInMemory.prototype.pop = function () {
|
|
37
|
+
EventsCacheInMemory.prototype.pop = function (toMerge) {
|
|
38
38
|
var data = this.queue;
|
|
39
39
|
this.clear();
|
|
40
|
-
return data;
|
|
40
|
+
return toMerge ? toMerge.concat(data) : data;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
43
|
* Check if the cache is empty.
|
|
@@ -20,9 +20,18 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
20
20
|
/**
|
|
21
21
|
* Pop the collected data, used as payload for posting.
|
|
22
22
|
*/
|
|
23
|
-
ImpressionCountsCacheInMemory.prototype.pop = function () {
|
|
23
|
+
ImpressionCountsCacheInMemory.prototype.pop = function (toMerge) {
|
|
24
24
|
var data = this.cache;
|
|
25
25
|
this.clear();
|
|
26
|
+
if (toMerge) {
|
|
27
|
+
Object.keys(data).forEach(function (key) {
|
|
28
|
+
if (toMerge[key])
|
|
29
|
+
toMerge[key] += data[key];
|
|
30
|
+
else
|
|
31
|
+
toMerge[key] = data[key];
|
|
32
|
+
});
|
|
33
|
+
return toMerge;
|
|
34
|
+
}
|
|
26
35
|
return data;
|
|
27
36
|
};
|
|
28
37
|
/**
|
|
@@ -32,10 +32,10 @@ var ImpressionsCacheInMemory = /** @class */ (function () {
|
|
|
32
32
|
/**
|
|
33
33
|
* Pop the collected data, used as payload for posting.
|
|
34
34
|
*/
|
|
35
|
-
ImpressionsCacheInMemory.prototype.pop = function () {
|
|
35
|
+
ImpressionsCacheInMemory.prototype.pop = function (toMerge) {
|
|
36
36
|
var data = this.queue;
|
|
37
37
|
this.clear();
|
|
38
|
-
return data;
|
|
38
|
+
return toMerge ? toMerge.concat(data) : data;
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
* Check if the cache is empty.
|
|
@@ -9,13 +9,9 @@ export function submitterFactory(log, postClient, sourceCache, postRate, dataNam
|
|
|
9
9
|
var retries = 0;
|
|
10
10
|
var data;
|
|
11
11
|
function postData() {
|
|
12
|
-
if (!data)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// we clear the cache to track new items, while `data` is used for retries
|
|
16
|
-
data = sourceCache.pop();
|
|
17
|
-
}
|
|
18
|
-
// @ts-ignore
|
|
12
|
+
if (sourceCache.isEmpty() && !data)
|
|
13
|
+
return Promise.resolve();
|
|
14
|
+
data = sourceCache.pop(data);
|
|
19
15
|
var dataCountMessage = typeof data.length === 'number' ? data.length + " " + dataName : dataName;
|
|
20
16
|
log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCountMessage]);
|
|
21
17
|
var jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
|
package/package.json
CHANGED
package/src/listeners/browser.ts
CHANGED
|
@@ -89,7 +89,7 @@ export class BrowserSignalListener implements ISignalListener {
|
|
|
89
89
|
if (this.syncManager.pushManager) this.syncManager.pushManager.stop();
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
private _flushData<
|
|
92
|
+
private _flushData<T>(url: string, cache: IRecorderCacheProducerSync<T>, postService: (body: string) => Promise<IResponse>, fromCacheToPayload?: (cacheData: T) => any, extraMetadata?: {}) {
|
|
93
93
|
// if there is data in cache, send it to backend
|
|
94
94
|
if (!cache.isEmpty()) {
|
|
95
95
|
const dataPayload = fromCacheToPayload ? fromCacheToPayload(cache.pop()) : cache.pop();
|
|
@@ -48,10 +48,10 @@ export class EventsCacheInMemory implements IEventsCacheSync {
|
|
|
48
48
|
/**
|
|
49
49
|
* Pop the collected data, used as payload for posting.
|
|
50
50
|
*/
|
|
51
|
-
pop() {
|
|
51
|
+
pop(toMerge?: SplitIO.EventData[]) {
|
|
52
52
|
const data = this.queue;
|
|
53
53
|
this.clear();
|
|
54
|
-
return data;
|
|
54
|
+
return toMerge ? toMerge.concat(data) : data;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -25,9 +25,16 @@ export class ImpressionCountsCacheInMemory implements IImpressionCountsCacheSync
|
|
|
25
25
|
/**
|
|
26
26
|
* Pop the collected data, used as payload for posting.
|
|
27
27
|
*/
|
|
28
|
-
pop() {
|
|
28
|
+
pop(toMerge?: Record<string, number>) {
|
|
29
29
|
const data = this.cache;
|
|
30
30
|
this.clear();
|
|
31
|
+
if (toMerge) {
|
|
32
|
+
Object.keys(data).forEach((key) => {
|
|
33
|
+
if (toMerge[key]) toMerge[key] += data[key];
|
|
34
|
+
else toMerge[key] = data[key];
|
|
35
|
+
});
|
|
36
|
+
return toMerge;
|
|
37
|
+
}
|
|
31
38
|
return data;
|
|
32
39
|
}
|
|
33
40
|
|
|
@@ -43,10 +43,10 @@ export class ImpressionsCacheInMemory implements IImpressionsCacheSync {
|
|
|
43
43
|
/**
|
|
44
44
|
* Pop the collected data, used as payload for posting.
|
|
45
45
|
*/
|
|
46
|
-
pop() {
|
|
46
|
+
pop(toMerge?: ImpressionDTO[]) {
|
|
47
47
|
const data = this.queue;
|
|
48
48
|
this.clear();
|
|
49
|
-
return data;
|
|
49
|
+
return toMerge ? toMerge.concat(data) : data;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
package/src/storages/types.ts
CHANGED
|
@@ -302,7 +302,7 @@ export interface IRecorderCacheProducerSync<T> {
|
|
|
302
302
|
/* Clears cache data */
|
|
303
303
|
clear(): void
|
|
304
304
|
/* Pops cache data */
|
|
305
|
-
pop(): T
|
|
305
|
+
pop(toMerge?: T): T
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
|
|
@@ -352,7 +352,7 @@ export interface IImpressionCountsCacheSync extends IRecorderCacheProducerSync<R
|
|
|
352
352
|
|
|
353
353
|
// Used by impressions count submitter in standalone and producer mode
|
|
354
354
|
isEmpty(): boolean // check if cache is empty. Return true if the cache was just created or cleared.
|
|
355
|
-
pop(): Record<string, number> // pop cache data
|
|
355
|
+
pop(toMerge?: Record<string, number> ): Record<string, number> // pop cache data
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
|
|
@@ -8,28 +8,24 @@ import { IResponse } from '../../services/types';
|
|
|
8
8
|
/**
|
|
9
9
|
* Base function to create submitters, such as ImpressionsSubmitter and EventsSubmitter
|
|
10
10
|
*/
|
|
11
|
-
export function submitterFactory<
|
|
11
|
+
export function submitterFactory<T>(
|
|
12
12
|
log: ILogger,
|
|
13
13
|
postClient: (body: string) => Promise<IResponse>,
|
|
14
|
-
sourceCache: IRecorderCacheProducerSync<
|
|
14
|
+
sourceCache: IRecorderCacheProducerSync<T>,
|
|
15
15
|
postRate: number,
|
|
16
16
|
dataName: string,
|
|
17
|
-
fromCacheToPayload?: (cacheData:
|
|
17
|
+
fromCacheToPayload?: (cacheData: T) => any,
|
|
18
18
|
maxRetries: number = 0,
|
|
19
19
|
debugLogs?: boolean // true for telemetry submitters
|
|
20
20
|
): ISyncTask<[], void> {
|
|
21
21
|
|
|
22
22
|
let retries = 0;
|
|
23
|
-
let data:
|
|
23
|
+
let data: any;
|
|
24
24
|
|
|
25
25
|
function postData(): Promise<any> {
|
|
26
|
-
if (!data)
|
|
27
|
-
|
|
28
|
-
// we clear the cache to track new items, while `data` is used for retries
|
|
29
|
-
data = sourceCache.pop();
|
|
30
|
-
}
|
|
26
|
+
if (sourceCache.isEmpty() && !data) return Promise.resolve();
|
|
27
|
+
data = sourceCache.pop(data);
|
|
31
28
|
|
|
32
|
-
// @ts-ignore
|
|
33
29
|
const dataCountMessage = typeof data.length === 'number' ? `${data.length} ${dataName}` : dataName;
|
|
34
30
|
log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCountMessage]);
|
|
35
31
|
|
|
@@ -23,7 +23,7 @@ export declare class EventsCacheInMemory implements IEventsCacheSync {
|
|
|
23
23
|
/**
|
|
24
24
|
* Pop the collected data, used as payload for posting.
|
|
25
25
|
*/
|
|
26
|
-
pop(): SplitIO.EventData[];
|
|
26
|
+
pop(toMerge?: SplitIO.EventData[]): SplitIO.EventData[];
|
|
27
27
|
/**
|
|
28
28
|
* Check if the cache is empty.
|
|
29
29
|
*/
|
|
@@ -12,7 +12,7 @@ export declare class ImpressionCountsCacheInMemory implements IImpressionCountsC
|
|
|
12
12
|
/**
|
|
13
13
|
* Pop the collected data, used as payload for posting.
|
|
14
14
|
*/
|
|
15
|
-
pop(): Record<string, number>;
|
|
15
|
+
pop(toMerge?: Record<string, number>): Record<string, number>;
|
|
16
16
|
/**
|
|
17
17
|
* Clear the data stored on the cache.
|
|
18
18
|
*/
|
|
@@ -22,7 +22,7 @@ export declare class ImpressionsCacheInMemory implements IImpressionsCacheSync {
|
|
|
22
22
|
/**
|
|
23
23
|
* Pop the collected data, used as payload for posting.
|
|
24
24
|
*/
|
|
25
|
-
pop(): ImpressionDTO[];
|
|
25
|
+
pop(toMerge?: ImpressionDTO[]): ImpressionDTO[];
|
|
26
26
|
/**
|
|
27
27
|
* Check if the cache is empty.
|
|
28
28
|
*/
|
|
@@ -266,7 +266,7 @@ export interface IEventsCacheBase {
|
|
|
266
266
|
export interface IRecorderCacheProducerSync<T> {
|
|
267
267
|
isEmpty(): boolean;
|
|
268
268
|
clear(): void;
|
|
269
|
-
pop(): T;
|
|
269
|
+
pop(toMerge?: T): T;
|
|
270
270
|
}
|
|
271
271
|
export interface IImpressionsCacheSync extends IImpressionsCacheBase, IRecorderCacheProducerSync<ImpressionDTO[]> {
|
|
272
272
|
track(data: ImpressionDTO[]): void;
|
|
@@ -295,7 +295,7 @@ export interface IEventsCacheAsync extends IEventsCacheBase, IRecorderCacheProdu
|
|
|
295
295
|
export interface IImpressionCountsCacheSync extends IRecorderCacheProducerSync<Record<string, number>> {
|
|
296
296
|
track(featureName: string, timeFrame: number, amount: number): void;
|
|
297
297
|
isEmpty(): boolean;
|
|
298
|
-
pop(): Record<string, number>;
|
|
298
|
+
pop(toMerge?: Record<string, number>): Record<string, number>;
|
|
299
299
|
}
|
|
300
300
|
/**
|
|
301
301
|
* Telemetry storage interface for standalone and partial consumer modes.
|
|
@@ -5,7 +5,7 @@ import { IResponse } from '../../services/types';
|
|
|
5
5
|
/**
|
|
6
6
|
* Base function to create submitters, such as ImpressionsSubmitter and EventsSubmitter
|
|
7
7
|
*/
|
|
8
|
-
export declare function submitterFactory<
|
|
8
|
+
export declare function submitterFactory<T>(log: ILogger, postClient: (body: string) => Promise<IResponse>, sourceCache: IRecorderCacheProducerSync<T>, postRate: number, dataName: string, fromCacheToPayload?: (cacheData: T) => any, maxRetries?: number, debugLogs?: boolean): ISyncTask<[], void>;
|
|
9
9
|
/**
|
|
10
10
|
* Decorates a provided submitter with a first execution window
|
|
11
11
|
*/
|