@splitsoftware/splitio-commons 1.17.1-rc.3 → 2.0.0-rc.0
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 +7 -3
- package/cjs/evaluator/index.js +2 -2
- package/cjs/evaluator/matchers/semver_inlist.js +1 -2
- package/cjs/evaluator/matchers/whitelist.js +1 -2
- package/cjs/listeners/browser.js +1 -2
- package/cjs/logger/browser/DebugLogger.js +1 -2
- package/cjs/logger/browser/ErrorLogger.js +1 -2
- package/cjs/logger/browser/InfoLogger.js +1 -2
- package/cjs/logger/browser/WarnLogger.js +1 -2
- package/cjs/logger/index.js +1 -2
- package/cjs/readiness/readinessManager.js +5 -7
- package/cjs/sdkClient/clientCS.js +5 -8
- package/cjs/sdkClient/sdkClientMethodCS.js +5 -8
- package/cjs/sdkFactory/index.js +10 -33
- package/cjs/services/decorateHeaders.js +1 -2
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
- package/cjs/storages/AbstractSplitsCacheSync.js +7 -0
- package/cjs/storages/KeyBuilderCS.js +0 -9
- package/cjs/storages/dataLoader.js +32 -64
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
- package/cjs/storages/inLocalStorage/index.js +1 -6
- package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -16
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +3 -4
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -3
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
- package/cjs/storages/inRedis/RedisAdapter.js +3 -4
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +3 -4
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +6 -7
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +7 -8
- package/cjs/storages/pluggable/index.js +32 -37
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
- package/cjs/sync/polling/pollingManagerSS.js +3 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +13 -5
- package/cjs/sync/streaming/parseUtils.js +0 -1
- package/cjs/sync/streaming/pushManager.js +2 -3
- package/cjs/trackers/eventTracker.js +9 -11
- package/cjs/trackers/impressionsTracker.js +13 -15
- package/cjs/trackers/uniqueKeysTracker.js +3 -5
- package/cjs/utils/LRUCache/index.js +1 -2
- package/cjs/utils/constants/browser.js +1 -4
- package/cjs/utils/lang/index.js +6 -9
- package/cjs/utils/lang/objectAssign.js +12 -77
- package/cjs/utils/lang/sets.js +3 -110
- package/cjs/utils/settingsValidation/index.js +0 -9
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +1 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
- package/esm/evaluator/index.js +3 -3
- package/esm/evaluator/matchers/semver_inlist.js +1 -2
- package/esm/evaluator/matchers/whitelist.js +1 -2
- package/esm/listeners/browser.js +1 -2
- package/esm/logger/browser/DebugLogger.js +1 -2
- package/esm/logger/browser/ErrorLogger.js +1 -2
- package/esm/logger/browser/InfoLogger.js +1 -2
- package/esm/logger/browser/WarnLogger.js +1 -2
- package/esm/logger/index.js +1 -2
- package/esm/readiness/readinessManager.js +5 -7
- package/esm/sdkClient/clientCS.js +5 -8
- package/esm/sdkClient/sdkClientMethodCS.js +5 -8
- package/esm/sdkFactory/index.js +11 -34
- package/esm/services/decorateHeaders.js +1 -2
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
- package/esm/storages/AbstractSplitsCacheSync.js +7 -0
- package/esm/storages/KeyBuilderCS.js +0 -9
- package/esm/storages/dataLoader.js +30 -61
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
- package/esm/storages/inLocalStorage/index.js +2 -7
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -16
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +3 -4
- package/esm/storages/inMemory/SplitsCacheInMemory.js +2 -3
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
- package/esm/storages/inRedis/RedisAdapter.js +3 -4
- package/esm/storages/inRedis/SplitsCacheInRedis.js +2 -2
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +3 -4
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
- package/esm/storages/pluggable/TelemetryCachePluggable.js +6 -7
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +7 -8
- package/esm/storages/pluggable/index.js +32 -37
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
- package/esm/sync/polling/pollingManagerSS.js +3 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +14 -6
- package/esm/sync/streaming/parseUtils.js +0 -1
- package/esm/sync/streaming/pushManager.js +2 -3
- package/esm/trackers/eventTracker.js +9 -11
- package/esm/trackers/impressionsTracker.js +13 -15
- package/esm/trackers/uniqueKeysTracker.js +3 -5
- package/esm/utils/LRUCache/index.js +1 -2
- package/esm/utils/constants/browser.js +0 -3
- package/esm/utils/lang/index.js +6 -9
- package/esm/utils/lang/objectAssign.js +12 -77
- package/esm/utils/lang/sets.js +2 -107
- package/esm/utils/settingsValidation/index.js +0 -9
- package/esm/utils/settingsValidation/logger/builtinLogger.js +1 -2
- package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
- package/package.json +2 -2
- package/src/evaluator/index.ts +5 -5
- package/src/evaluator/matchers/semver_inlist.ts +1 -2
- package/src/evaluator/matchers/whitelist.ts +1 -3
- package/src/listeners/browser.ts +1 -2
- package/src/logger/browser/DebugLogger.ts +1 -2
- package/src/logger/browser/ErrorLogger.ts +1 -2
- package/src/logger/browser/InfoLogger.ts +1 -2
- package/src/logger/browser/WarnLogger.ts +1 -2
- package/src/logger/index.ts +3 -4
- package/src/readiness/readinessManager.ts +7 -9
- package/src/readiness/types.ts +0 -1
- package/src/sdkClient/clientCS.ts +5 -8
- package/src/sdkClient/sdkClientMethodCS.ts +3 -6
- package/src/sdkFactory/index.ts +12 -37
- package/src/sdkFactory/types.ts +1 -4
- package/src/services/decorateHeaders.ts +1 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +9 -2
- package/src/storages/AbstractSplitsCacheSync.ts +9 -2
- package/src/storages/KeyBuilderCS.ts +0 -13
- package/src/storages/dataLoader.ts +32 -62
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +1 -21
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +16 -8
- package/src/storages/inLocalStorage/index.ts +2 -8
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -19
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +4 -5
- package/src/storages/inMemory/SplitsCacheInMemory.ts +4 -5
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +4 -5
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +4 -5
- package/src/storages/inRedis/RedisAdapter.ts +4 -5
- package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -3
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -4
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +1 -2
- package/src/storages/pluggable/SegmentsCachePluggable.ts +0 -1
- package/src/storages/pluggable/SplitsCachePluggable.ts +3 -3
- package/src/storages/pluggable/TelemetryCachePluggable.ts +6 -7
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +1 -2
- package/src/storages/pluggable/inMemoryWrapper.ts +8 -9
- package/src/storages/pluggable/index.ts +33 -38
- package/src/storages/types.ts +9 -6
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
- package/src/sync/polling/pollingManagerSS.ts +2 -3
- package/src/sync/polling/updaters/splitChangesUpdater.ts +15 -8
- package/src/sync/streaming/parseUtils.ts +0 -1
- package/src/sync/streaming/pushManager.ts +3 -4
- package/src/sync/submitters/types.ts +3 -4
- package/src/trackers/eventTracker.ts +7 -10
- package/src/trackers/impressionsTracker.ts +9 -12
- package/src/trackers/types.ts +0 -1
- package/src/trackers/uniqueKeysTracker.ts +4 -6
- package/src/types.ts +9 -18
- package/src/utils/LRUCache/index.ts +2 -3
- package/src/utils/constants/browser.ts +0 -4
- package/src/utils/lang/index.ts +6 -7
- package/src/utils/lang/objectAssign.ts +13 -92
- package/src/utils/lang/sets.ts +3 -125
- package/src/utils/settingsValidation/index.ts +0 -10
- package/src/utils/settingsValidation/logger/builtinLogger.ts +1 -2
- package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
- package/src/utils/settingsValidation/types.ts +0 -2
- package/types/logger/index.d.ts +1 -2
- package/types/readiness/types.d.ts +0 -1
- package/types/sdkClient/clientCS.d.ts +2 -3
- package/types/sdkFactory/types.d.ts +1 -3
- package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -2
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -2
- package/types/storages/KeyBuilderCS.d.ts +0 -2
- package/types/storages/dataLoader.d.ts +6 -17
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +7 -2
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -2
- package/types/storages/inMemory/UniqueKeysCacheInMemory.d.ts +2 -3
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +1 -2
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +1 -2
- package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -2
- package/types/storages/types.d.ts +7 -6
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -2
- package/types/sync/submitters/types.d.ts +3 -4
- package/types/trackers/eventTracker.d.ts +1 -1
- package/types/trackers/impressionsTracker.d.ts +1 -1
- package/types/trackers/types.d.ts +0 -1
- package/types/types.d.ts +9 -17
- package/types/utils/LRUCache/index.d.ts +1 -2
- package/types/utils/constants/browser.d.ts +0 -2
- package/types/utils/lang/objectAssign.d.ts +3 -0
- package/types/utils/lang/sets.d.ts +1 -61
- package/types/utils/settingsValidation/index.d.ts +0 -1
- package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
- package/types/utils/settingsValidation/types.d.ts +0 -2
- package/cjs/integrations/browser.js +0 -31
- package/cjs/integrations/ga/GaToSplit.js +0 -257
- package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +0 -14
- package/cjs/integrations/ga/SplitToGa.js +0 -123
- package/cjs/integrations/ga/SplitToGoogleAnalytics.js +0 -14
- package/cjs/integrations/ga/types.js +0 -2
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +0 -79
- package/cjs/utils/lang/maps.js +0 -96
- package/esm/integrations/browser.js +0 -27
- package/esm/integrations/ga/GaToSplit.js +0 -250
- package/esm/integrations/ga/GoogleAnalyticsToSplit.js +0 -10
- package/esm/integrations/ga/SplitToGa.js +0 -120
- package/esm/integrations/ga/SplitToGoogleAnalytics.js +0 -10
- package/esm/integrations/ga/types.js +0 -1
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +0 -75
- package/esm/utils/lang/maps.js +0 -92
- package/src/integrations/browser.ts +0 -35
- package/src/integrations/ga/GaToSplit.ts +0 -299
- package/src/integrations/ga/GoogleAnalyticsToSplit.ts +0 -14
- package/src/integrations/ga/SplitToGa.ts +0 -135
- package/src/integrations/ga/SplitToGoogleAnalytics.ts +0 -14
- package/src/integrations/ga/autoRequire.js +0 -33
- package/src/integrations/ga/types.ts +0 -153
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +0 -101
- package/src/utils/lang/maps.ts +0 -108
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { clientCSDecorator } from './clientCS';
|
|
2
|
-
import { SplitIO } from '../types';
|
|
3
|
-
import { validateKey } from '../utils/inputValidation/key';
|
|
4
|
-
import { validateTrafficType } from '../utils/inputValidation/trafficType';
|
|
5
|
-
import { getMatching, keyParser } from '../utils/key';
|
|
6
|
-
import { sdkClientFactory } from './sdkClient';
|
|
7
|
-
import { ISyncManagerCS } from '../sync/types';
|
|
8
|
-
import { objectAssign } from '../utils/lang/objectAssign';
|
|
9
|
-
import { RETRIEVE_CLIENT_DEFAULT, NEW_SHARED_CLIENT, RETRIEVE_CLIENT_EXISTING, LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants';
|
|
10
|
-
import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
11
|
-
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
12
|
-
import { buildInstanceId } from './identity';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
|
|
16
|
-
* where clients can have a bound TT for the track method, which is provided via the settings
|
|
17
|
-
* (default client) or the client method (shared clients).
|
|
18
|
-
*/
|
|
19
|
-
export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient {
|
|
20
|
-
const { clients, storage, syncManager, sdkReadinessManager, settings: { core: { key, trafficType }, log }, whenInit } = params;
|
|
21
|
-
|
|
22
|
-
const mainClientInstance = clientCSDecorator(
|
|
23
|
-
log,
|
|
24
|
-
sdkClientFactory(params) as SplitIO.IClient,
|
|
25
|
-
key,
|
|
26
|
-
trafficType
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const parsedDefaultKey = keyParser(key);
|
|
30
|
-
const defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
|
|
31
|
-
|
|
32
|
-
// Cache instances created per factory.
|
|
33
|
-
clients[defaultInstanceId] = mainClientInstance;
|
|
34
|
-
|
|
35
|
-
return function client(key?: SplitIO.SplitKey, trafficType?: string) {
|
|
36
|
-
if (key === undefined) {
|
|
37
|
-
log.debug(RETRIEVE_CLIENT_DEFAULT);
|
|
38
|
-
return mainClientInstance;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Validate the key value
|
|
42
|
-
const validKey = validateKey(log, key, LOG_PREFIX_CLIENT_INSTANTIATION);
|
|
43
|
-
if (validKey === false) {
|
|
44
|
-
throw new Error('Shared Client needs a valid key.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let validTrafficType;
|
|
48
|
-
if (trafficType !== undefined) {
|
|
49
|
-
validTrafficType = validateTrafficType(log, trafficType, LOG_PREFIX_CLIENT_INSTANTIATION);
|
|
50
|
-
if (validTrafficType === false) {
|
|
51
|
-
throw new Error('Shared Client needs a valid traffic type or no traffic type at all.');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const instanceId = buildInstanceId(validKey, validTrafficType);
|
|
55
|
-
|
|
56
|
-
if (!clients[instanceId]) {
|
|
57
|
-
const matchingKey = getMatching(validKey);
|
|
58
|
-
|
|
59
|
-
const sharedSdkReadiness = sdkReadinessManager.shared();
|
|
60
|
-
const sharedStorage = storage.shared && storage.shared(matchingKey, (err) => {
|
|
61
|
-
if (err) {
|
|
62
|
-
sharedSdkReadiness.readinessManager.timeout();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// Emit SDK_READY in consumer mode for shared clients
|
|
66
|
-
sharedSdkReadiness.readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// 3 possibilities:
|
|
70
|
-
// - Standalone mode: both syncManager and sharedSyncManager are defined
|
|
71
|
-
// - Consumer mode: both syncManager and sharedSyncManager are undefined
|
|
72
|
-
// - Consumer partial mode: syncManager is defined (only for submitters) but sharedSyncManager is undefined
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
const sharedSyncManager = syncManager && sharedStorage && (syncManager as ISyncManagerCS).shared(matchingKey, sharedSdkReadiness.readinessManager, sharedStorage);
|
|
75
|
-
|
|
76
|
-
// As shared clients reuse all the storage information, we don't need to check here if we
|
|
77
|
-
// will use offline or online mode. We should stick with the original decision.
|
|
78
|
-
clients[instanceId] = clientCSDecorator(
|
|
79
|
-
log,
|
|
80
|
-
sdkClientFactory(objectAssign({}, params, {
|
|
81
|
-
sdkReadinessManager: sharedSdkReadiness,
|
|
82
|
-
storage: sharedStorage || storage,
|
|
83
|
-
syncManager: sharedSyncManager,
|
|
84
|
-
}), true) as SplitIO.IClient,
|
|
85
|
-
validKey,
|
|
86
|
-
validTrafficType
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
whenInit(() => {
|
|
90
|
-
sharedSdkReadiness.readinessManager.init();
|
|
91
|
-
sharedSyncManager && sharedSyncManager.start();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
log.info(NEW_SHARED_CLIENT);
|
|
95
|
-
} else {
|
|
96
|
-
log.debug(RETRIEVE_CLIENT_EXISTING);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return clients[instanceId] as SplitIO.ICsClient;
|
|
100
|
-
};
|
|
101
|
-
}
|
package/src/utils/lang/maps.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map implementation based on es6-map polyfill (https://github.com/medikoo/es6-map/blob/master/polyfill.js),
|
|
3
|
-
* with the minimal features used by the SDK.
|
|
4
|
-
|
|
5
|
-
Copyright (C) 2013 Mariusz Nowak (www.medikoo.com)
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
24
|
-
**/
|
|
25
|
-
|
|
26
|
-
export interface IMap<K, V> {
|
|
27
|
-
clear(): void;
|
|
28
|
-
delete(key: K): boolean;
|
|
29
|
-
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
30
|
-
get(key: K): V | undefined;
|
|
31
|
-
has(key: K): boolean;
|
|
32
|
-
set(key: K, value: V): this;
|
|
33
|
-
readonly size: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class MapPoly<K, V> implements IMap<K, V>{
|
|
37
|
-
private __mapKeysData__: K[] = [];
|
|
38
|
-
private __mapValuesData__: V[] = [];
|
|
39
|
-
|
|
40
|
-
// unlike ES6 `Map`, it only accepts an array as first argument iterable
|
|
41
|
-
constructor(entries?: readonly (readonly [K, V])[] | null) {
|
|
42
|
-
if (Array.isArray(entries)) entries.forEach(entry => { this.set(entry[0], entry[1]); });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
clear() {
|
|
46
|
-
if (!this.__mapKeysData__.length) return;
|
|
47
|
-
this.__mapKeysData__.length = 0;
|
|
48
|
-
this.__mapValuesData__.length = 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
delete(key: K) {
|
|
52
|
-
const index = this.__mapKeysData__.indexOf(key);
|
|
53
|
-
if (index === -1) return false;
|
|
54
|
-
this.__mapKeysData__.splice(index, 1);
|
|
55
|
-
this.__mapValuesData__.splice(index, 1);
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any) {
|
|
60
|
-
for (let i = 0; i < this.__mapKeysData__.length; i++) {
|
|
61
|
-
callbackfn.call(thisArg, this.__mapValuesData__[i], this.__mapKeysData__[i], this as any);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get(key: K) {
|
|
66
|
-
const index = this.__mapKeysData__.indexOf(key);
|
|
67
|
-
if (index === -1) return;
|
|
68
|
-
return this.__mapValuesData__[index];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
has(key: K): boolean {
|
|
72
|
-
return this.__mapKeysData__.indexOf(key) !== -1;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
set(key: K, value: V) {
|
|
76
|
-
let index = this.__mapKeysData__.indexOf(key);
|
|
77
|
-
if (index === -1) index = this.__mapKeysData__.push(key) - 1;
|
|
78
|
-
this.__mapValuesData__[index] = value;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
get size() {
|
|
83
|
-
return this.__mapKeysData__.length;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
interface IMapConstructor {
|
|
89
|
-
new(): IMap<any, any>;
|
|
90
|
-
new <K, V>(entries?: readonly (readonly [K, V])[] | null): IMap<K, V>;
|
|
91
|
-
readonly prototype: IMap<any, any>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
|
|
96
|
-
* a ponyfill with minimal features is returned instead.
|
|
97
|
-
*
|
|
98
|
-
* Exported for testing purposes only.
|
|
99
|
-
*/
|
|
100
|
-
export function __getMapConstructor(): IMapConstructor {
|
|
101
|
-
// eslint-disable-next-line compat/compat
|
|
102
|
-
if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
|
|
103
|
-
return Map;
|
|
104
|
-
}
|
|
105
|
-
return MapPoly;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export const _Map = __getMapConstructor();
|