@splitsoftware/splitio-commons 1.17.0 → 1.17.1-rc.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/CHANGES.txt +8 -0
- package/cjs/evaluator/matchers/index.js +3 -1
- package/cjs/evaluator/matchers/large_segment.js +16 -0
- package/cjs/evaluator/matchers/matcherTypes.js +1 -0
- package/cjs/evaluator/matchersTransform/index.js +4 -1
- package/cjs/evaluator/matchersTransform/segment.js +3 -1
- package/cjs/logger/constants.js +2 -2
- package/cjs/logger/messages/info.js +1 -1
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/readiness/readinessManager.js +5 -6
- package/cjs/readiness/sdkReadinessManager.js +5 -6
- package/cjs/sdkClient/identity.js +7 -0
- package/cjs/sdkClient/sdkClient.js +5 -5
- package/cjs/sdkClient/sdkClientMethod.js +3 -1
- package/cjs/sdkClient/sdkClientMethodCS.js +9 -14
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +9 -14
- package/cjs/sdkFactory/index.js +6 -2
- package/cjs/services/splitApi.js +5 -5
- package/cjs/storages/AbstractSegmentsCacheSync.js +41 -12
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -1
- package/cjs/storages/KeyBuilderCS.js +23 -5
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +29 -52
- package/cjs/storages/inLocalStorage/index.js +6 -2
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -0
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +9 -40
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +8 -8
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +7 -10
- package/cjs/storages/pluggable/inMemoryWrapper.js +1 -1
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +5 -8
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +1 -1
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +15 -21
- package/cjs/sync/streaming/AuthClient/index.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -5
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +107 -48
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/parseUtils.js +14 -9
- package/cjs/sync/streaming/pushManager.js +69 -67
- package/cjs/utils/constants/index.js +5 -4
- package/cjs/utils/settingsValidation/index.js +2 -1
- package/esm/evaluator/matchers/index.js +3 -1
- package/esm/evaluator/matchers/large_segment.js +12 -0
- package/esm/evaluator/matchers/matcherTypes.js +1 -0
- package/esm/evaluator/matchersTransform/index.js +4 -1
- package/esm/evaluator/matchersTransform/segment.js +3 -1
- package/esm/logger/constants.js +1 -1
- package/esm/logger/messages/info.js +1 -1
- package/esm/logger/messages/warn.js +1 -1
- package/esm/readiness/readinessManager.js +5 -6
- package/esm/readiness/sdkReadinessManager.js +5 -6
- package/esm/sdkClient/identity.js +3 -0
- package/esm/sdkClient/sdkClient.js +5 -5
- package/esm/sdkClient/sdkClientMethod.js +3 -1
- package/esm/sdkClient/sdkClientMethodCS.js +7 -12
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +7 -12
- package/esm/sdkFactory/index.js +6 -2
- package/esm/services/splitApi.js +6 -6
- package/esm/storages/AbstractSegmentsCacheSync.js +41 -12
- package/esm/storages/AbstractSplitsCacheSync.js +3 -2
- package/esm/storages/KeyBuilderCS.js +21 -4
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +29 -52
- package/esm/storages/inLocalStorage/index.js +7 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -0
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +9 -40
- package/esm/storages/inMemory/SplitsCacheInMemory.js +8 -8
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +7 -10
- package/esm/storages/pluggable/inMemoryWrapper.js +1 -1
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +5 -8
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/esm/sync/polling/pollingManagerCS.js +1 -1
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +15 -21
- package/esm/sync/streaming/AuthClient/index.js +1 -1
- package/esm/sync/streaming/SSEHandler/index.js +4 -6
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +108 -49
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/parseUtils.js +12 -8
- package/esm/sync/streaming/pushManager.js +72 -70
- package/esm/utils/constants/index.js +3 -2
- package/esm/utils/settingsValidation/index.js +2 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +21 -7
- package/src/evaluator/matchers/index.ts +2 -0
- package/src/evaluator/matchers/large_segment.ts +18 -0
- package/src/evaluator/matchers/matcherTypes.ts +1 -0
- package/src/evaluator/matchersTransform/index.ts +4 -1
- package/src/evaluator/matchersTransform/segment.ts +5 -3
- package/src/logger/constants.ts +1 -1
- package/src/logger/messages/info.ts +1 -1
- package/src/logger/messages/warn.ts +1 -1
- package/src/readiness/readinessManager.ts +7 -5
- package/src/readiness/sdkReadinessManager.ts +7 -7
- package/src/readiness/types.ts +2 -2
- package/src/sdkClient/identity.ts +5 -0
- package/src/sdkClient/sdkClient.ts +5 -5
- package/src/sdkClient/sdkClientMethod.ts +4 -1
- package/src/sdkClient/sdkClientMethodCS.ts +7 -13
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +7 -13
- package/src/sdkFactory/index.ts +8 -4
- package/src/sdkFactory/types.ts +2 -1
- package/src/services/splitApi.ts +7 -7
- package/src/services/splitHttpClient.ts +1 -1
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSegmentsCacheSync.ts +53 -12
- package/src/storages/AbstractSplitsCacheSync.ts +4 -3
- package/src/storages/KeyBuilderCS.ts +34 -5
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +29 -59
- package/src/storages/inLocalStorage/index.ts +8 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +5 -0
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +10 -44
- package/src/storages/inMemory/SplitsCacheInMemory.ts +7 -8
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +7 -11
- package/src/storages/pluggable/inMemoryWrapper.ts +1 -1
- package/src/storages/types.ts +11 -7
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +8 -10
- package/src/sync/polling/fetchers/segmentChangesFetcher.ts +1 -1
- package/src/sync/polling/fetchers/types.ts +3 -2
- package/src/sync/polling/pollingManagerCS.ts +4 -4
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +4 -5
- package/src/sync/polling/types.ts +7 -6
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +19 -22
- package/src/sync/streaming/AuthClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/index.ts +4 -6
- package/src/sync/streaming/SSEHandler/index.ts +5 -8
- package/src/sync/streaming/SSEHandler/types.ts +15 -15
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +116 -49
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/types.ts +2 -2
- package/src/sync/streaming/constants.ts +2 -2
- package/src/sync/streaming/parseUtils.ts +19 -11
- package/src/sync/streaming/pushManager.ts +73 -72
- package/src/sync/streaming/types.ts +10 -10
- package/src/sync/submitters/types.ts +8 -5
- package/src/types.ts +7 -1
- package/src/utils/constants/index.ts +3 -2
- package/src/utils/settingsValidation/index.ts +3 -2
- package/src/utils/settingsValidation/types.ts +1 -1
- package/types/dtos/types.d.ts +18 -7
- package/types/evaluator/matchersTransform/segment.d.ts +2 -2
- package/types/logger/constants.d.ts +1 -1
- package/types/readiness/readinessManager.d.ts +2 -2
- package/types/readiness/sdkReadinessManager.d.ts +2 -3
- package/types/readiness/types.d.ts +2 -2
- package/types/sdkClient/identity.d.ts +0 -4
- package/types/sdkClient/sdkClientMethod.d.ts +1 -1
- package/types/sdkFactory/types.d.ts +2 -1
- package/types/services/splitApi.d.ts +1 -1
- package/types/services/splitHttpClient.d.ts +1 -1
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractMySegmentsCacheSync.d.ts +39 -0
- package/types/storages/AbstractSegmentsCacheSync.d.ts +9 -11
- package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
- package/types/storages/KeyBuilderCS.d.ts +9 -2
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +4 -14
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +3 -9
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +4 -6
- package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -1
- package/types/storages/types.d.ts +7 -5
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +2 -2
- package/types/sync/polling/fetchers/types.d.ts +2 -2
- package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +2 -2
- package/types/sync/polling/types.d.ts +7 -4
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +4 -3
- package/types/sync/streaming/SSEHandler/types.d.ts +16 -14
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +4 -2
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
- package/types/sync/streaming/UpdateWorkers/types.d.ts +2 -2
- package/types/sync/streaming/constants.d.ts +2 -2
- package/types/sync/streaming/parseUtils.d.ts +4 -5
- package/types/sync/streaming/types.d.ts +8 -8
- package/types/sync/submitters/types.d.ts +7 -4
- package/types/types.d.ts +7 -1
- package/types/utils/constants/index.d.ts +3 -2
- package/types/utils/settingsValidation/types.d.ts +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { sdkClientFactory } from './sdkClient';
|
|
2
2
|
import { RETRIEVE_CLIENT_DEFAULT } from '../logger/constants';
|
|
3
3
|
/**
|
|
4
|
-
* Factory of client method for server-side SDKs
|
|
4
|
+
* Factory of client method for server-side SDKs
|
|
5
5
|
*/
|
|
6
6
|
export function sdkClientMethodFactory(params) {
|
|
7
7
|
var log = params.settings.log;
|
|
8
8
|
var clientInstance = sdkClientFactory(params);
|
|
9
|
+
// Only one client in server-side without bound key
|
|
10
|
+
params.clients[''] = clientInstance;
|
|
9
11
|
return function client() {
|
|
10
12
|
if (arguments.length > 0) {
|
|
11
13
|
throw new Error('Shared Client not supported by the storage mechanism. Create isolated instances instead.');
|
|
@@ -5,22 +5,18 @@ import { sdkClientFactory } from './sdkClient';
|
|
|
5
5
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
6
6
|
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING, LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants';
|
|
7
7
|
import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
8
|
-
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
return (key.matchingKey ? key.matchingKey : key) + "-" + (key.bucketingKey ? key.bucketingKey : key) + "-";
|
|
11
|
-
}
|
|
8
|
+
import { buildInstanceId } from './identity';
|
|
12
9
|
/**
|
|
13
10
|
* Factory of client method for the client-side API variant where TT is ignored.
|
|
14
11
|
* Therefore, clients don't have a bound TT for the track method.
|
|
15
12
|
*/
|
|
16
13
|
export function sdkClientMethodCSFactory(params) {
|
|
17
|
-
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key,
|
|
14
|
+
var clients = params.clients, storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, log = _a.log;
|
|
18
15
|
var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), key);
|
|
19
16
|
var parsedDefaultKey = keyParser(key);
|
|
20
17
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey);
|
|
21
18
|
// Cache instances created per factory.
|
|
22
|
-
|
|
23
|
-
clientInstances[defaultInstanceId] = mainClientInstance;
|
|
19
|
+
clients[defaultInstanceId] = mainClientInstance;
|
|
24
20
|
return function client(key) {
|
|
25
21
|
if (key === undefined) {
|
|
26
22
|
log.debug(RETRIEVE_CLIENT_DEFAULT);
|
|
@@ -32,9 +28,9 @@ export function sdkClientMethodCSFactory(params) {
|
|
|
32
28
|
throw new Error('Shared Client needs a valid key.');
|
|
33
29
|
}
|
|
34
30
|
var instanceId = buildInstanceId(validKey);
|
|
35
|
-
if (!
|
|
31
|
+
if (!clients[instanceId]) {
|
|
36
32
|
var matchingKey = getMatching(validKey);
|
|
37
|
-
var sharedSdkReadiness_1 = sdkReadinessManager.shared(
|
|
33
|
+
var sharedSdkReadiness_1 = sdkReadinessManager.shared();
|
|
38
34
|
var sharedStorage = storage.shared && storage.shared(matchingKey, function (err) {
|
|
39
35
|
if (err) {
|
|
40
36
|
sharedSdkReadiness_1.readinessManager.timeout();
|
|
@@ -51,11 +47,10 @@ export function sdkClientMethodCSFactory(params) {
|
|
|
51
47
|
var sharedSyncManager = syncManager && sharedStorage && syncManager.shared(matchingKey, sharedSdkReadiness_1.readinessManager, sharedStorage);
|
|
52
48
|
// As shared clients reuse all the storage information, we don't need to check here if we
|
|
53
49
|
// will use offline or online mode. We should stick with the original decision.
|
|
54
|
-
|
|
50
|
+
clients[instanceId] = clientCSDecorator(log, sdkClientFactory(objectAssign({}, params, {
|
|
55
51
|
sdkReadinessManager: sharedSdkReadiness_1,
|
|
56
52
|
storage: sharedStorage || storage,
|
|
57
53
|
syncManager: sharedSyncManager,
|
|
58
|
-
signalListener: undefined, // only the main client "destroy" method stops the signal listener
|
|
59
54
|
}), true), validKey);
|
|
60
55
|
sharedSyncManager && sharedSyncManager.start();
|
|
61
56
|
log.info(NEW_SHARED_CLIENT);
|
|
@@ -63,6 +58,6 @@ export function sdkClientMethodCSFactory(params) {
|
|
|
63
58
|
else {
|
|
64
59
|
log.debug(RETRIEVE_CLIENT_EXISTING);
|
|
65
60
|
}
|
|
66
|
-
return
|
|
61
|
+
return clients[instanceId];
|
|
67
62
|
};
|
|
68
63
|
}
|
|
@@ -6,23 +6,19 @@ import { sdkClientFactory } from './sdkClient';
|
|
|
6
6
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
7
7
|
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING, LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants';
|
|
8
8
|
import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
9
|
-
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
return (key.matchingKey ? key.matchingKey : key) + "-" + (key.bucketingKey ? key.bucketingKey : key) + "-" + (trafficType !== undefined ? trafficType : '');
|
|
12
|
-
}
|
|
9
|
+
import { buildInstanceId } from './identity';
|
|
13
10
|
/**
|
|
14
11
|
* Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
|
|
15
12
|
* where clients can have a bound TT for the track method, which is provided via the settings
|
|
16
13
|
* (default client) or the client method (shared clients).
|
|
17
14
|
*/
|
|
18
15
|
export function sdkClientMethodCSFactory(params) {
|
|
19
|
-
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType,
|
|
16
|
+
var clients = params.clients, storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, log = _a.log;
|
|
20
17
|
var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), key, trafficType);
|
|
21
18
|
var parsedDefaultKey = keyParser(key);
|
|
22
19
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
|
|
23
20
|
// Cache instances created per factory.
|
|
24
|
-
|
|
25
|
-
clientInstances[defaultInstanceId] = mainClientInstance;
|
|
21
|
+
clients[defaultInstanceId] = mainClientInstance;
|
|
26
22
|
return function client(key, trafficType) {
|
|
27
23
|
if (key === undefined) {
|
|
28
24
|
log.debug(RETRIEVE_CLIENT_DEFAULT);
|
|
@@ -41,9 +37,9 @@ export function sdkClientMethodCSFactory(params) {
|
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
var instanceId = buildInstanceId(validKey, validTrafficType);
|
|
44
|
-
if (!
|
|
40
|
+
if (!clients[instanceId]) {
|
|
45
41
|
var matchingKey = getMatching(validKey);
|
|
46
|
-
var sharedSdkReadiness_1 = sdkReadinessManager.shared(
|
|
42
|
+
var sharedSdkReadiness_1 = sdkReadinessManager.shared();
|
|
47
43
|
var sharedStorage = storage.shared && storage.shared(matchingKey, function (err) {
|
|
48
44
|
if (err) {
|
|
49
45
|
sharedSdkReadiness_1.readinessManager.timeout();
|
|
@@ -60,11 +56,10 @@ export function sdkClientMethodCSFactory(params) {
|
|
|
60
56
|
var sharedSyncManager = syncManager && sharedStorage && syncManager.shared(matchingKey, sharedSdkReadiness_1.readinessManager, sharedStorage);
|
|
61
57
|
// As shared clients reuse all the storage information, we don't need to check here if we
|
|
62
58
|
// will use offline or online mode. We should stick with the original decision.
|
|
63
|
-
|
|
59
|
+
clients[instanceId] = clientCSDecorator(log, sdkClientFactory(objectAssign({}, params, {
|
|
64
60
|
sdkReadinessManager: sharedSdkReadiness_1,
|
|
65
61
|
storage: sharedStorage || storage,
|
|
66
62
|
syncManager: sharedSyncManager,
|
|
67
|
-
signalListener: undefined, // only the main client "destroy" method stops the signal listener
|
|
68
63
|
}), true), validKey, validTrafficType);
|
|
69
64
|
sharedSyncManager && sharedSyncManager.start();
|
|
70
65
|
log.info(NEW_SHARED_CLIENT);
|
|
@@ -72,6 +67,6 @@ export function sdkClientMethodCSFactory(params) {
|
|
|
72
67
|
else {
|
|
73
68
|
log.debug(RETRIEVE_CLIENT_EXISTING);
|
|
74
69
|
}
|
|
75
|
-
return
|
|
70
|
+
return clients[instanceId];
|
|
76
71
|
};
|
|
77
72
|
}
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -22,7 +22,7 @@ export function sdkFactory(params) {
|
|
|
22
22
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
23
23
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
24
24
|
validateAndTrackApiKey(log, settings.core.authorizationKey);
|
|
25
|
-
var sdkReadinessManager = sdkReadinessManagerFactory(
|
|
25
|
+
var sdkReadinessManager = sdkReadinessManagerFactory(platform.EventEmitter, settings);
|
|
26
26
|
var readiness = sdkReadinessManager.readinessManager;
|
|
27
27
|
var storage = storageFactory({
|
|
28
28
|
settings: settings,
|
|
@@ -37,6 +37,7 @@ export function sdkFactory(params) {
|
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
39
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
40
|
+
var clients = {};
|
|
40
41
|
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
41
42
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
42
43
|
var observer = impressionsObserverFactory();
|
|
@@ -56,7 +57,7 @@ export function sdkFactory(params) {
|
|
|
56
57
|
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
57
58
|
// splitApi is used by SyncManager and Browser signal listener
|
|
58
59
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
59
|
-
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
60
|
+
var ctx = { clients: clients, splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
60
61
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
61
62
|
ctx.syncManager = syncManager;
|
|
62
63
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
@@ -79,5 +80,8 @@ export function sdkFactory(params) {
|
|
|
79
80
|
// Logger wrapper API
|
|
80
81
|
Logger: createLoggerAPI(log),
|
|
81
82
|
settings: settings,
|
|
83
|
+
destroy: function () {
|
|
84
|
+
return Promise.all(Object.keys(clients).map(function (key) { return clients[key].destroy(); })).then(function () { });
|
|
85
|
+
}
|
|
82
86
|
}, extraProps && extraProps(ctx));
|
|
83
87
|
}
|
package/esm/services/splitApi.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { splitHttpClientFactory } from './splitHttpClient';
|
|
2
2
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
3
|
-
import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT,
|
|
3
|
+
import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT, MEMBERSHIPS } from '../utils/constants';
|
|
4
4
|
import { ERROR_TOO_MANY_SETS } from '../logger/constants';
|
|
5
5
|
var noCacheHeaderOptions = { headers: { 'Cache-Control': 'no-cache' } };
|
|
6
6
|
function userKeyToQueryParam(userKey) {
|
|
@@ -51,15 +51,15 @@ export function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
51
51
|
var url = urls.sdk + "/segmentChanges/" + segmentName + "?since=" + since + (till ? '&till=' + till : '');
|
|
52
52
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SEGMENT));
|
|
53
53
|
},
|
|
54
|
-
|
|
54
|
+
fetchMemberships: function (userMatchingKey, noCache, till) {
|
|
55
55
|
/**
|
|
56
56
|
* URI encoding of user keys in order to:
|
|
57
|
-
* - avoid 400 responses (due to URI malformed). E.g.: '/api/
|
|
58
|
-
* - avoid 404 responses. E.g.: '/api/
|
|
57
|
+
* - avoid 400 responses (due to URI malformed). E.g.: '/api/memberships/%'
|
|
58
|
+
* - avoid 404 responses. E.g.: '/api/memberships/foo/bar'
|
|
59
59
|
* - match user keys with special characters. E.g.: 'foo%bar', 'foo/bar'
|
|
60
60
|
*/
|
|
61
|
-
var url = urls.sdk + "/
|
|
62
|
-
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(
|
|
61
|
+
var url = urls.sdk + "/memberships/" + encodeURIComponent(userMatchingKey) + (till ? '?till=' + till : '');
|
|
62
|
+
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(MEMBERSHIPS));
|
|
63
63
|
},
|
|
64
64
|
/**
|
|
65
65
|
* Post events.
|
|
@@ -6,25 +6,54 @@ var AbstractSegmentsCacheSync = /** @class */ (function () {
|
|
|
6
6
|
function AbstractSegmentsCacheSync() {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* For client-side synchronizer: the method is not used.
|
|
11
|
-
*/
|
|
12
|
-
AbstractSegmentsCacheSync.prototype.registerSegments = function (names) { return false; };
|
|
13
|
-
/**
|
|
14
|
-
* For server-side synchronizer: set the change number of `name` segment.
|
|
15
|
-
* For client-side synchronizer: the method is not used.
|
|
9
|
+
* clear the cache.
|
|
16
10
|
*/
|
|
17
|
-
AbstractSegmentsCacheSync.prototype.
|
|
11
|
+
AbstractSegmentsCacheSync.prototype.clear = function () {
|
|
12
|
+
this.resetSegments({});
|
|
13
|
+
};
|
|
18
14
|
/**
|
|
19
|
-
* For server-side synchronizer:
|
|
15
|
+
* For server-side synchronizer: add the given list of segments to the cache, with an empty list of keys. The segments that already exist are not modified.
|
|
20
16
|
* For client-side synchronizer: the method is not used.
|
|
21
17
|
*/
|
|
22
|
-
AbstractSegmentsCacheSync.prototype.
|
|
18
|
+
AbstractSegmentsCacheSync.prototype.registerSegments = function (names) { return false; };
|
|
23
19
|
/**
|
|
24
20
|
* For server-side synchronizer: the method is not used.
|
|
25
|
-
* For client-side synchronizer:
|
|
21
|
+
* For client-side synchronizer: it resets or updates the cache.
|
|
26
22
|
*/
|
|
27
|
-
AbstractSegmentsCacheSync.prototype.resetSegments = function (
|
|
23
|
+
AbstractSegmentsCacheSync.prototype.resetSegments = function (segmentsData) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
this.setChangeNumber(undefined, segmentsData.cn);
|
|
26
|
+
var _a = segmentsData, added = _a.added, removed = _a.removed;
|
|
27
|
+
if (added && removed) {
|
|
28
|
+
var isDiff_1 = false;
|
|
29
|
+
added.forEach(function (segment) {
|
|
30
|
+
isDiff_1 = _this.addToSegment(segment) || isDiff_1;
|
|
31
|
+
});
|
|
32
|
+
removed.forEach(function (segment) {
|
|
33
|
+
isDiff_1 = _this.removeFromSegment(segment) || isDiff_1;
|
|
34
|
+
});
|
|
35
|
+
return isDiff_1;
|
|
36
|
+
}
|
|
37
|
+
var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
|
|
38
|
+
var storedSegmentKeys = this.getRegisteredSegments().sort();
|
|
39
|
+
// Extreme fast => everything is empty
|
|
40
|
+
if (!names.length && !storedSegmentKeys.length)
|
|
41
|
+
return false;
|
|
42
|
+
var index = 0;
|
|
43
|
+
while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
|
|
44
|
+
index++;
|
|
45
|
+
// Quick path => no changes
|
|
46
|
+
if (index === names.length && index === storedSegmentKeys.length)
|
|
47
|
+
return false;
|
|
48
|
+
// Slowest path => add and/or remove segments
|
|
49
|
+
for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
|
|
50
|
+
this.removeFromSegment(storedSegmentKeys[removeIndex]);
|
|
51
|
+
}
|
|
52
|
+
for (var addIndex = index; addIndex < names.length; addIndex++) {
|
|
53
|
+
this.addToSegment(names[addIndex]);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
};
|
|
28
57
|
return AbstractSegmentsCacheSync;
|
|
29
58
|
}());
|
|
30
59
|
export { AbstractSegmentsCacheSync };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { IN_SEGMENT } from '../utils/constants';
|
|
2
|
+
import { IN_SEGMENT, IN_LARGE_SEGMENT } from '../utils/constants';
|
|
3
3
|
/**
|
|
4
4
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
5
5
|
* to minimize the effort required to implement this interface.
|
|
@@ -67,7 +67,8 @@ export function usesSegments(split) {
|
|
|
67
67
|
for (var i = 0; i < conditions.length; i++) {
|
|
68
68
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
69
69
|
for (var j = 0; j < matchers.length; j++) {
|
|
70
|
-
|
|
70
|
+
var matcher = matchers[j].matcherType;
|
|
71
|
+
if (matcher === IN_SEGMENT || matcher === IN_LARGE_SEGMENT)
|
|
71
72
|
return true;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -21,10 +21,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
21
21
|
return builtSegmentKeyName.substr(prefix.length);
|
|
22
22
|
};
|
|
23
23
|
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
|
|
24
|
-
KeyBuilderCS.prototype.buildOldSegmentNameKey = function (segmentName) {
|
|
25
|
-
return this.matchingKey + "." + this.prefix + ".segment." + segmentName;
|
|
26
|
-
};
|
|
27
|
-
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
|
|
28
24
|
KeyBuilderCS.prototype.extractOldSegmentKey = function (builtSegmentKeyName) {
|
|
29
25
|
var prefix = this.matchingKey + "." + this.prefix + ".segment.";
|
|
30
26
|
if (startsWith(builtSegmentKeyName, prefix))
|
|
@@ -36,6 +32,27 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
36
32
|
KeyBuilderCS.prototype.isSplitsCacheKey = function (key) {
|
|
37
33
|
return this.regexSplitsCacheKey.test(key);
|
|
38
34
|
};
|
|
35
|
+
KeyBuilderCS.prototype.buildTillKey = function () {
|
|
36
|
+
return this.prefix + "." + this.matchingKey + ".segments.till";
|
|
37
|
+
};
|
|
39
38
|
return KeyBuilderCS;
|
|
40
39
|
}(KeyBuilder));
|
|
41
40
|
export { KeyBuilderCS };
|
|
41
|
+
export function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
|
|
42
|
+
return {
|
|
43
|
+
buildSegmentNameKey: function (segmentName) {
|
|
44
|
+
return prefix + "." + matchingKey + ".largeSegment." + segmentName;
|
|
45
|
+
},
|
|
46
|
+
extractSegmentName: function (builtSegmentKeyName) {
|
|
47
|
+
var p = prefix + "." + matchingKey + ".largeSegment.";
|
|
48
|
+
if (startsWith(builtSegmentKeyName, p))
|
|
49
|
+
return builtSegmentKeyName.substr(p.length);
|
|
50
|
+
},
|
|
51
|
+
extractOldSegmentKey: function () {
|
|
52
|
+
return undefined;
|
|
53
|
+
},
|
|
54
|
+
buildTillKey: function () {
|
|
55
|
+
return prefix + "." + matchingKey + ".largeSegments.till";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -42,6 +42,6 @@ export function dataLoaderFactory(preloadedData) {
|
|
|
42
42
|
return Array.isArray(userIds) && userIds.indexOf(userId) > -1;
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
storage.segments.resetSegments(mySegmentsData);
|
|
45
|
+
storage.segments.resetSegments({ k: mySegmentsData.map(function (s) { return ({ n: s }); }) });
|
|
46
46
|
};
|
|
47
47
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
|
+
import { isNaNNumber } from '../../utils/lang';
|
|
2
3
|
import { AbstractSegmentsCacheSync } from '../AbstractSegmentsCacheSync';
|
|
3
4
|
import { LOG_PREFIX, DEFINED } from './constants';
|
|
4
5
|
var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
@@ -10,19 +11,11 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
10
11
|
return _this;
|
|
11
12
|
// There is not need to flush segments cache like splits cache, since resetSegments receives the up-to-date list of active segments
|
|
12
13
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Removes list of segments from localStorage
|
|
15
|
-
* @NOTE this method is not being used at the moment.
|
|
16
|
-
*/
|
|
17
|
-
MySegmentsCacheInLocal.prototype.clear = function () {
|
|
18
|
-
this.log.info(LOG_PREFIX + 'Flushing MySegments data from localStorage');
|
|
19
|
-
// We cannot simply call `localStorage.clear()` since that implies removing user items from the storage
|
|
20
|
-
// We could optimize next sentence, since it implies iterating over all localStorage items
|
|
21
|
-
this.resetSegments([]);
|
|
22
|
-
};
|
|
23
14
|
MySegmentsCacheInLocal.prototype.addToSegment = function (name) {
|
|
24
15
|
var segmentKey = this.keys.buildSegmentNameKey(name);
|
|
25
16
|
try {
|
|
17
|
+
if (localStorage.getItem(segmentKey) === DEFINED)
|
|
18
|
+
return false;
|
|
26
19
|
localStorage.setItem(segmentKey, DEFINED);
|
|
27
20
|
return true;
|
|
28
21
|
}
|
|
@@ -34,6 +27,8 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
34
27
|
MySegmentsCacheInLocal.prototype.removeFromSegment = function (name) {
|
|
35
28
|
var segmentKey = this.keys.buildSegmentNameKey(name);
|
|
36
29
|
try {
|
|
30
|
+
if (localStorage.getItem(segmentKey) !== DEFINED)
|
|
31
|
+
return false;
|
|
37
32
|
localStorage.removeItem(segmentKey);
|
|
38
33
|
return true;
|
|
39
34
|
}
|
|
@@ -45,30 +40,22 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
45
40
|
MySegmentsCacheInLocal.prototype.isInSegment = function (name) {
|
|
46
41
|
return localStorage.getItem(this.keys.buildSegmentNameKey(name)) === DEFINED;
|
|
47
42
|
};
|
|
48
|
-
|
|
49
|
-
* Reset (update) the cached list of segments with the given list, removing and adding segments if necessary.
|
|
50
|
-
*
|
|
51
|
-
* @param {string[]} segmentNames list of segment names
|
|
52
|
-
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
53
|
-
*/
|
|
54
|
-
MySegmentsCacheInLocal.prototype.resetSegments = function (names) {
|
|
43
|
+
MySegmentsCacheInLocal.prototype.getRegisteredSegments = function () {
|
|
55
44
|
var _this = this;
|
|
56
|
-
var isDiff = false;
|
|
57
|
-
var index;
|
|
58
45
|
// Scan current values from localStorage
|
|
59
|
-
|
|
46
|
+
return Object.keys(localStorage).reduce(function (accum, key) {
|
|
60
47
|
var segmentName = _this.keys.extractSegmentName(key);
|
|
61
48
|
if (segmentName) {
|
|
62
49
|
accum.push(segmentName);
|
|
63
50
|
}
|
|
64
51
|
else {
|
|
65
|
-
// @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
|
|
52
|
+
// @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
|
|
66
53
|
segmentName = _this.keys.extractOldSegmentKey(key);
|
|
67
54
|
if (segmentName) { // this was an old segment key, let's clean up.
|
|
68
55
|
var newSegmentKey = _this.keys.buildSegmentNameKey(segmentName);
|
|
69
56
|
try {
|
|
70
57
|
// If the new format key is not there, create it.
|
|
71
|
-
if (!localStorage.getItem(newSegmentKey)
|
|
58
|
+
if (!localStorage.getItem(newSegmentKey)) {
|
|
72
59
|
localStorage.setItem(newSegmentKey, DEFINED);
|
|
73
60
|
// we are migrating a segment, let's track it.
|
|
74
61
|
accum.push(segmentName);
|
|
@@ -82,40 +69,30 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
82
69
|
}
|
|
83
70
|
return accum;
|
|
84
71
|
}, []);
|
|
85
|
-
// Extreme fast => everything is empty
|
|
86
|
-
if (names.length === 0 && storedSegmentNames.length === names.length)
|
|
87
|
-
return isDiff;
|
|
88
|
-
// Quick path
|
|
89
|
-
if (storedSegmentNames.length !== names.length) {
|
|
90
|
-
isDiff = true;
|
|
91
|
-
storedSegmentNames.forEach(function (name) { return _this.removeFromSegment(name); });
|
|
92
|
-
names.forEach(function (name) { return _this.addToSegment(name); });
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// Slowest path => we need to find at least 1 difference because
|
|
96
|
-
for (index = 0; index < names.length && storedSegmentNames.indexOf(names[index]) !== -1; index++) {
|
|
97
|
-
// TODO: why empty statement?
|
|
98
|
-
}
|
|
99
|
-
if (index < names.length) {
|
|
100
|
-
isDiff = true;
|
|
101
|
-
storedSegmentNames.forEach(function (name) { return _this.removeFromSegment(name); });
|
|
102
|
-
names.forEach(function (name) { return _this.addToSegment(name); });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return isDiff;
|
|
106
|
-
};
|
|
107
|
-
MySegmentsCacheInLocal.prototype.getRegisteredSegments = function () {
|
|
108
|
-
var _this = this;
|
|
109
|
-
return Object.keys(localStorage).reduce(function (accum, key) {
|
|
110
|
-
var segmentName = _this.keys.extractSegmentName(key);
|
|
111
|
-
if (segmentName)
|
|
112
|
-
accum.push(segmentName);
|
|
113
|
-
return accum;
|
|
114
|
-
}, []);
|
|
115
72
|
};
|
|
116
73
|
MySegmentsCacheInLocal.prototype.getKeysCount = function () {
|
|
117
74
|
return 1;
|
|
118
75
|
};
|
|
76
|
+
MySegmentsCacheInLocal.prototype.setChangeNumber = function (name, changeNumber) {
|
|
77
|
+
try {
|
|
78
|
+
if (changeNumber)
|
|
79
|
+
localStorage.setItem(this.keys.buildTillKey(), changeNumber + '');
|
|
80
|
+
else
|
|
81
|
+
localStorage.removeItem(this.keys.buildTillKey());
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
this.log.error(e);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
MySegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
88
|
+
var n = -1;
|
|
89
|
+
var value = localStorage.getItem(this.keys.buildTillKey());
|
|
90
|
+
if (value !== null) {
|
|
91
|
+
value = parseInt(value, 10);
|
|
92
|
+
return isNaNNumber(value) ? n : value;
|
|
93
|
+
}
|
|
94
|
+
return n;
|
|
95
|
+
};
|
|
119
96
|
return MySegmentsCacheInLocal;
|
|
120
97
|
}(AbstractSegmentsCacheSync));
|
|
121
98
|
export { MySegmentsCacheInLocal };
|
|
@@ -2,7 +2,7 @@ import { ImpressionsCacheInMemory } from '../inMemory/ImpressionsCacheInMemory';
|
|
|
2
2
|
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
|
|
3
3
|
import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory';
|
|
4
4
|
import { validatePrefix } from '../KeyBuilder';
|
|
5
|
-
import { KeyBuilderCS } from '../KeyBuilderCS';
|
|
5
|
+
import { KeyBuilderCS, myLargeSegmentsKeyBuilder } from '../KeyBuilderCS';
|
|
6
6
|
import { isLocalStorageAvailable } from '../../utils/env/isLocalStorageAvailable';
|
|
7
7
|
import { SplitsCacheInLocal } from './SplitsCacheInLocal';
|
|
8
8
|
import { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal';
|
|
@@ -33,9 +33,11 @@ export function InLocalStorage(options) {
|
|
|
33
33
|
var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
34
34
|
var splits = new SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
35
35
|
var segments = new MySegmentsCacheInLocal(log, keys);
|
|
36
|
+
var largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey));
|
|
36
37
|
return {
|
|
37
38
|
splits: splits,
|
|
38
39
|
segments: segments,
|
|
40
|
+
largeSegments: largeSegments,
|
|
39
41
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
40
42
|
impressionCounts: impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
41
43
|
events: new EventsCacheInMemory(eventsQueueSize),
|
|
@@ -45,6 +47,7 @@ export function InLocalStorage(options) {
|
|
|
45
47
|
var _a;
|
|
46
48
|
this.splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
47
49
|
this.segments = new MySegmentsCacheInMemory();
|
|
50
|
+
this.largeSegments = new MySegmentsCacheInMemory();
|
|
48
51
|
this.impressions.clear();
|
|
49
52
|
this.impressionCounts && this.impressionCounts.clear();
|
|
50
53
|
this.events.clear();
|
|
@@ -52,10 +55,10 @@ export function InLocalStorage(options) {
|
|
|
52
55
|
},
|
|
53
56
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
54
57
|
shared: function (matchingKey) {
|
|
55
|
-
var childKeysBuilder = new KeyBuilderCS(prefix, matchingKey);
|
|
56
58
|
return {
|
|
57
59
|
splits: this.splits,
|
|
58
|
-
segments: new MySegmentsCacheInLocal(log,
|
|
60
|
+
segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey)),
|
|
61
|
+
largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey)),
|
|
59
62
|
impressions: this.impressions,
|
|
60
63
|
impressionCounts: this.impressionCounts,
|
|
61
64
|
events: this.events,
|
|
@@ -63,6 +66,7 @@ export function InLocalStorage(options) {
|
|
|
63
66
|
destroy: function () {
|
|
64
67
|
this.splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
65
68
|
this.segments = new MySegmentsCacheInMemory();
|
|
69
|
+
this.largeSegments = new MySegmentsCacheInMemory();
|
|
66
70
|
}
|
|
67
71
|
};
|
|
68
72
|
},
|
|
@@ -15,9 +15,11 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
15
15
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
16
16
|
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
17
17
|
var segments = new MySegmentsCacheInMemory();
|
|
18
|
+
var largeSegments = new MySegmentsCacheInMemory();
|
|
18
19
|
var storage = {
|
|
19
20
|
splits: splits,
|
|
20
21
|
segments: segments,
|
|
22
|
+
largeSegments: largeSegments,
|
|
21
23
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
22
24
|
impressionCounts: impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
23
25
|
events: new EventsCacheInMemory(eventsQueueSize),
|
|
@@ -27,6 +29,7 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
27
29
|
destroy: function () {
|
|
28
30
|
this.splits.clear();
|
|
29
31
|
this.segments.clear();
|
|
32
|
+
this.largeSegments.clear();
|
|
30
33
|
this.impressions.clear();
|
|
31
34
|
this.impressionCounts && this.impressionCounts.clear();
|
|
32
35
|
this.events.clear();
|
|
@@ -37,6 +40,7 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
37
40
|
return {
|
|
38
41
|
splits: this.splits,
|
|
39
42
|
segments: new MySegmentsCacheInMemory(),
|
|
43
|
+
largeSegments: new MySegmentsCacheInMemory(),
|
|
40
44
|
impressions: this.impressions,
|
|
41
45
|
impressionCounts: this.impressionCounts,
|
|
42
46
|
events: this.events,
|
|
@@ -45,6 +49,7 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
45
49
|
destroy: function () {
|
|
46
50
|
this.splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
47
51
|
this.segments.clear();
|
|
52
|
+
this.largeSegments.clear();
|
|
48
53
|
}
|
|
49
54
|
};
|
|
50
55
|
},
|
|
@@ -11,57 +11,26 @@ var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
11
11
|
_this.segmentCache = {};
|
|
12
12
|
return _this;
|
|
13
13
|
}
|
|
14
|
-
MySegmentsCacheInMemory.prototype.clear = function () {
|
|
15
|
-
this.segmentCache = {};
|
|
16
|
-
};
|
|
17
14
|
MySegmentsCacheInMemory.prototype.addToSegment = function (name) {
|
|
15
|
+
if (this.segmentCache[name])
|
|
16
|
+
return false;
|
|
18
17
|
this.segmentCache[name] = true;
|
|
19
18
|
return true;
|
|
20
19
|
};
|
|
21
20
|
MySegmentsCacheInMemory.prototype.removeFromSegment = function (name) {
|
|
21
|
+
if (!this.segmentCache[name])
|
|
22
|
+
return false;
|
|
22
23
|
delete this.segmentCache[name];
|
|
23
24
|
return true;
|
|
24
25
|
};
|
|
25
26
|
MySegmentsCacheInMemory.prototype.isInSegment = function (name) {
|
|
26
27
|
return this.segmentCache[name] === true;
|
|
27
28
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
34
|
-
*/
|
|
35
|
-
MySegmentsCacheInMemory.prototype.resetSegments = function (names) {
|
|
36
|
-
var _this = this;
|
|
37
|
-
var isDiff = false;
|
|
38
|
-
var index;
|
|
39
|
-
var storedSegmentKeys = Object.keys(this.segmentCache);
|
|
40
|
-
// Extreme fast => everything is empty
|
|
41
|
-
if (names.length === 0 && storedSegmentKeys.length === names.length)
|
|
42
|
-
return isDiff;
|
|
43
|
-
// Quick path
|
|
44
|
-
if (storedSegmentKeys.length !== names.length) {
|
|
45
|
-
isDiff = true;
|
|
46
|
-
this.segmentCache = {};
|
|
47
|
-
names.forEach(function (s) {
|
|
48
|
-
_this.addToSegment(s);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// Slowest path => we need to find at least 1 difference because
|
|
53
|
-
for (index = 0; index < names.length && this.isInSegment(names[index]); index++) {
|
|
54
|
-
// TODO: why empty statement?
|
|
55
|
-
}
|
|
56
|
-
if (index < names.length) {
|
|
57
|
-
isDiff = true;
|
|
58
|
-
this.segmentCache = {};
|
|
59
|
-
names.forEach(function (s) {
|
|
60
|
-
_this.addToSegment(s);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return isDiff;
|
|
29
|
+
MySegmentsCacheInMemory.prototype.setChangeNumber = function (name, changeNumber) {
|
|
30
|
+
this.cn = changeNumber;
|
|
31
|
+
};
|
|
32
|
+
MySegmentsCacheInMemory.prototype.getChangeNumber = function () {
|
|
33
|
+
return this.cn || -1;
|
|
65
34
|
};
|
|
66
35
|
MySegmentsCacheInMemory.prototype.getRegisteredSegments = function () {
|
|
67
36
|
return Object.keys(this.segmentCache);
|