@splitsoftware/splitio-commons 1.12.1-rc.3 → 1.12.1-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGES.txt +1 -1
  2. package/cjs/logger/constants.js +3 -3
  3. package/cjs/logger/messages/warn.js +2 -2
  4. package/cjs/sdkClient/client.js +27 -21
  5. package/cjs/sdkClient/clientInputValidation.js +21 -21
  6. package/cjs/sdkManager/index.js +13 -15
  7. package/cjs/storages/KeyBuilder.js +13 -1
  8. package/cjs/storages/KeyBuilderCS.js +1 -4
  9. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -16
  10. package/cjs/storages/inLocalStorage/index.js +1 -1
  11. package/cjs/storages/inRedis/SplitsCacheInRedis.js +2 -2
  12. package/cjs/storages/inRedis/index.js +1 -1
  13. package/cjs/storages/pluggable/SplitsCachePluggable.js +2 -2
  14. package/cjs/storages/pluggable/index.js +14 -3
  15. package/cjs/trackers/eventTracker.js +4 -4
  16. package/cjs/utils/constants/index.js +16 -2
  17. package/cjs/utils/lang/sets.js +3 -3
  18. package/cjs/utils/settingsValidation/index.js +1 -1
  19. package/cjs/utils/settingsValidation/mode.js +10 -3
  20. package/cjs/utils/settingsValidation/splitFilters.js +20 -19
  21. package/esm/logger/constants.js +2 -2
  22. package/esm/logger/messages/warn.js +2 -2
  23. package/esm/sdkClient/client.js +28 -22
  24. package/esm/sdkClient/clientInputValidation.js +23 -23
  25. package/esm/sdkManager/index.js +7 -9
  26. package/esm/storages/KeyBuilder.js +11 -0
  27. package/esm/storages/KeyBuilderCS.js +1 -4
  28. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +12 -16
  29. package/esm/storages/inLocalStorage/index.js +1 -1
  30. package/esm/storages/inRedis/SplitsCacheInRedis.js +3 -3
  31. package/esm/storages/inRedis/index.js +1 -1
  32. package/esm/storages/pluggable/SplitsCachePluggable.js +3 -3
  33. package/esm/storages/pluggable/index.js +15 -4
  34. package/esm/trackers/eventTracker.js +4 -4
  35. package/esm/utils/constants/index.js +14 -0
  36. package/esm/utils/lang/sets.js +1 -1
  37. package/esm/utils/settingsValidation/index.js +2 -2
  38. package/esm/utils/settingsValidation/mode.js +7 -1
  39. package/esm/utils/settingsValidation/splitFilters.js +11 -10
  40. package/package.json +1 -1
  41. package/src/logger/constants.ts +2 -2
  42. package/src/logger/messages/warn.ts +2 -2
  43. package/src/sdkClient/client.ts +26 -23
  44. package/src/sdkClient/clientInputValidation.ts +23 -23
  45. package/src/sdkManager/index.ts +7 -10
  46. package/src/storages/KeyBuilder.ts +14 -1
  47. package/src/storages/KeyBuilderCS.ts +1 -5
  48. package/src/storages/KeyBuilderSS.ts +4 -4
  49. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +16 -14
  50. package/src/storages/inLocalStorage/index.ts +1 -1
  51. package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -3
  52. package/src/storages/inRedis/index.ts +1 -1
  53. package/src/storages/pluggable/SplitsCachePluggable.ts +3 -3
  54. package/src/storages/pluggable/index.ts +15 -5
  55. package/src/storages/types.ts +3 -3
  56. package/src/trackers/eventTracker.ts +4 -4
  57. package/src/utils/constants/index.ts +16 -0
  58. package/src/utils/lang/sets.ts +1 -1
  59. package/src/utils/murmur3/murmur3.ts +0 -1
  60. package/src/utils/settingsValidation/index.ts +2 -2
  61. package/src/utils/settingsValidation/mode.ts +8 -1
  62. package/src/utils/settingsValidation/splitFilters.ts +11 -10
  63. package/types/logger/constants.d.ts +2 -2
  64. package/types/storages/AbstractSplitsCache.d.ts +46 -0
  65. package/types/storages/KeyBuilder.d.ts +8 -1
  66. package/types/storages/KeyBuilderCS.d.ts +0 -1
  67. package/types/storages/KeyBuilderSS.d.ts +4 -4
  68. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +5 -5
  69. package/types/utils/constants/index.d.ts +12 -0
  70. package/types/utils/lang/sets.d.ts +1 -1
  71. package/types/utils/settingsValidation/mode.d.ts +5 -1
  72. package/types/utils/settingsValidation/splitFilters.d.ts +1 -1
  73. package/cjs/trackers/impressionObserver/utils.js +0 -11
  74. package/cjs/utils/redis/RedisMock.js +0 -31
  75. package/esm/trackers/impressionObserver/utils.js +0 -7
  76. package/esm/utils/redis/RedisMock.js +0 -28
  77. package/src/trackers/impressionObserver/utils.ts +0 -9
  78. package/src/utils/redis/RedisMock.ts +0 -31
@@ -1,11 +1,11 @@
1
- import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../constants';
2
1
  import { validateSplits } from '../inputValidation/splits';
3
2
  import { ISplitFiltersValidation } from '../../dtos/types';
4
3
  import { SplitIO } from '../../types';
5
4
  import { ILogger } from '../../logger/types';
6
- import { WARN_SPLITS_FILTER_IGNORED, WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS, ERROR_SETS_FILTER_EXCLUSIVE, WARN_SPLITS_FILTER_LOWERCASE_SET, WARN_SPLITS_FILTER_INVALID_SET, WARN_FLAGSET_NOT_CONFIGURED } from '../../logger/constants';
5
+ import { WARN_SPLITS_FILTER_IGNORED, WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS, ERROR_SETS_FILTER_EXCLUSIVE, WARN_LOWERCASE_FLAGSET, WARN_INVALID_FLAGSET, WARN_FLAGSET_NOT_CONFIGURED } from '../../logger/constants';
7
6
  import { objectAssign } from '../lang/objectAssign';
8
7
  import { find, uniq } from '../lang';
8
+ import { isConsumerMode } from './mode';
9
9
 
10
10
  // Split filters metadata.
11
11
  // Ordered according to their precedency when forming the filter query string: `&names=<values>&prefixes=<values>`
@@ -54,7 +54,7 @@ function validateSplitFilter(log: ILogger, type: SplitIO.SplitFilterType, values
54
54
  if (result) {
55
55
 
56
56
  if (type === 'bySet') {
57
- result = sanitizeFlagSets(log, result);
57
+ result = sanitizeFlagSets(log, result, LOG_PREFIX_SETTINGS);
58
58
  }
59
59
 
60
60
  // check max length
@@ -88,7 +88,7 @@ function queryStringBuilder(groupedFilters: Record<SplitIO.SplitFilterType, stri
88
88
  }
89
89
 
90
90
  /**
91
- * Sanitizes set names list taking in account:
91
+ * Sanitizes set names list taking into account:
92
92
  * - It should be lowercase
93
93
  * - Must adhere the following regular expression /^[a-z0-9][_a-z0-9]{0,49}$/ that means
94
94
  * - must start with a letter or number
@@ -98,20 +98,21 @@ function queryStringBuilder(groupedFilters: Record<SplitIO.SplitFilterType, stri
98
98
  *
99
99
  * @param {ILogger} log
100
100
  * @param {string[]} flagSets
101
+ * @param {string} method
101
102
  * @returns sanitized list of set names
102
103
  */
103
- function sanitizeFlagSets(log: ILogger, flagSets: string[]) {
104
+ function sanitizeFlagSets(log: ILogger, flagSets: string[], method: string) {
104
105
  let sanitizedSets = flagSets
105
106
  .map(flagSet => {
106
107
  if (CAPITAL_LETTERS_REGEX.test(flagSet)) {
107
- log.warn(WARN_SPLITS_FILTER_LOWERCASE_SET, [flagSet]);
108
+ log.warn(WARN_LOWERCASE_FLAGSET, [method, flagSet]);
108
109
  flagSet = flagSet.toLowerCase();
109
110
  }
110
111
  return flagSet;
111
112
  })
112
113
  .filter(flagSet => {
113
114
  if (!VALID_FLAGSET_REGEX.test(flagSet)) {
114
- log.warn(WARN_SPLITS_FILTER_INVALID_SET, [flagSet, VALID_FLAGSET_REGEX, flagSet]);
115
+ log.warn(WARN_INVALID_FLAGSET, [method, flagSet, VALID_FLAGSET_REGEX, flagSet]);
115
116
  return false;
116
117
  }
117
118
  if (typeof flagSet !== 'string') return false;
@@ -148,7 +149,7 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode:
148
149
  // do nothing if `splitFilters` param is not a non-empty array or mode is not STANDALONE
149
150
  if (!maybeSplitFilters) return res;
150
151
  // Warn depending on the mode
151
- if (mode === CONSUMER_MODE || mode === CONSUMER_PARTIAL_MODE) {
152
+ if (isConsumerMode(mode)) {
152
153
  log.warn(WARN_SPLITS_FILTER_IGNORED);
153
154
  return res;
154
155
  }
@@ -188,9 +189,9 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode:
188
189
  return res;
189
190
  }
190
191
 
191
- export function flagSetsAreValid(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] {
192
+ export function validateFlagSets(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] {
192
193
  const sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
193
- let toReturn = sets ? sanitizeFlagSets(log, sets) : [];
194
+ let toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
194
195
  if (flagSetsInConfig.length > 0) {
195
196
  toReturn = toReturn.filter(flagSet => {
196
197
  if (flagSetsInConfig.indexOf(flagSet) > -1) {
@@ -95,8 +95,8 @@ export declare const WARN_SPLITS_FILTER_EMPTY = 221;
95
95
  export declare const WARN_SDK_KEY = 222;
96
96
  export declare const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
97
97
  export declare const STREAMING_PARSING_SPLIT_UPDATE = 224;
98
- export declare const WARN_SPLITS_FILTER_INVALID_SET = 225;
99
- export declare const WARN_SPLITS_FILTER_LOWERCASE_SET = 226;
98
+ export declare const WARN_INVALID_FLAGSET = 225;
99
+ export declare const WARN_LOWERCASE_FLAGSET = 226;
100
100
  export declare const WARN_FLAGSET_NOT_CONFIGURED = 227;
101
101
  export declare const WARN_FLAGSET_WITHOUT_FLAGS = 228;
102
102
  export declare const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
@@ -0,0 +1,46 @@
1
+ import { ISplit, MaybeThenable } from '../dtos/types';
2
+ /**
3
+ * This class provides a skeletal implementation of the ISplitsCacheAsync interface
4
+ * to minimize the effort required to implement this interface.
5
+ */
6
+ export declare abstract class AbstractSplitsCache {
7
+ /**
8
+ * Check if the splits information is already stored in cache. This data can be preloaded.
9
+ * It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
10
+ */
11
+ checkCache(): boolean;
12
+ protected abstract addSplit(name: string, split: ISplit): MaybeThenable<boolean>;
13
+ /**
14
+ * Add a list of splits.
15
+ * The returned promise is resolved when the operation success or rejected if it fails (e.g., wrapper operation fails).
16
+ */
17
+ protected addSplits(entries: [string, ISplit][]): Promise<boolean[]>;
18
+ protected abstract removeSplit(name: string): MaybeThenable<boolean>;
19
+ /**
20
+ * Remove a list of splits.
21
+ * The returned promise is resolved when the operation success, with a boolean array indicating if the splits existed or not.
22
+ * or rejected if it fails (e.g., wrapper operation fails).
23
+ */
24
+ protected removeSplits(names: string[]): Promise<boolean[]>;
25
+ protected abstract setChangeNumber(changeNumber: number): MaybeThenable<boolean | void>;
26
+ /**
27
+ * Updates the cache with the provided changeNumber, feature flags to add and feature flags to remove.
28
+ *
29
+ * @returns {Promise<boolean>} a promise that resolved once the operation is performed successfully. The fulfillment value is `true` if at least one feature flag was added, modified or removed; or `false` if there was no change.
30
+ * The promise will reject if some storage operation rejects.
31
+ */
32
+ update(changeNumber: number, toAdd: [string, ISplit][], toRemove?: string[]): Promise<boolean>;
33
+ abstract getSplit(name: string): MaybeThenable<ISplit | null>;
34
+ /**
35
+ * Kill `name` split and set `defaultTreatment` and `changeNumber`.
36
+ * Used for SPLIT_KILL push notifications.
37
+ *
38
+ * @param {string} name
39
+ * @param {string} defaultTreatment
40
+ * @param {number} changeNumber
41
+ * @returns {Promise} a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the operation successed updating the split or `false` if no split is updated,
42
+ * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
43
+ * The promise will never be rejected.
44
+ */
45
+ killLocally(name: string, defaultTreatment: string, changeNumber: number): Promise<boolean>;
46
+ }
@@ -1,6 +1,7 @@
1
+ import { ISettings } from '../types';
1
2
  export declare function validatePrefix(prefix: unknown): string;
2
3
  export declare class KeyBuilder {
3
- protected readonly prefix: string;
4
+ readonly prefix: string;
4
5
  constructor(prefix?: string);
5
6
  buildTrafficTypeKey(trafficType: string): string;
6
7
  buildFlagSetKey(flagSet: string): string;
@@ -12,4 +13,10 @@ export declare class KeyBuilder {
12
13
  buildSegmentNameKey(segmentName: string): string;
13
14
  buildSegmentTillKey(segmentName: string): string;
14
15
  extractKey(builtKey: string): string;
16
+ buildHashKey(): string;
15
17
  }
18
+ /**
19
+ * Generates a murmur32 hash based on the authorization key and the feature flags filter query.
20
+ * The hash is in hexadecimal format (8 characters max, 32 bits).
21
+ */
22
+ export declare function getStorageHash(settings: ISettings): string;
@@ -12,5 +12,4 @@ export declare class KeyBuilderCS extends KeyBuilder {
12
12
  extractOldSegmentKey(builtSegmentKeyName: string): string | undefined;
13
13
  buildLastUpdatedKey(): string;
14
14
  isSplitsCacheKey(key: string): boolean;
15
- buildSplitsFilterQueryKey(): string;
16
15
  }
@@ -3,10 +3,10 @@ import { IMetadata } from '../dtos/types';
3
3
  import { Method } from '../sync/submitters/types';
4
4
  export declare const METHOD_NAMES: Record<Method, string>;
5
5
  export declare class KeyBuilderSS extends KeyBuilder {
6
- latencyPrefix: string;
7
- exceptionPrefix: string;
8
- initPrefix: string;
9
- private versionablePrefix;
6
+ readonly latencyPrefix: string;
7
+ readonly exceptionPrefix: string;
8
+ readonly initPrefix: string;
9
+ private readonly versionablePrefix;
10
10
  constructor(prefix: string, metadata: IMetadata);
11
11
  buildRegisteredSegmentsKey(): string;
12
12
  buildImpressionsKey(): string;
@@ -1,15 +1,15 @@
1
- import { ISplit, ISplitFiltersValidation } from '../../dtos/types';
1
+ import { ISplit } from '../../dtos/types';
2
2
  import { AbstractSplitsCacheSync } from '../AbstractSplitsCacheSync';
3
3
  import { KeyBuilderCS } from '../KeyBuilderCS';
4
- import { ILogger } from '../../logger/types';
5
4
  import { ISet } from '../../utils/lang/sets';
5
+ import { ISettings } from '../../types';
6
6
  /**
7
7
  * ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
8
8
  */
9
9
  export declare class SplitsCacheInLocal extends AbstractSplitsCacheSync {
10
- private readonly log;
11
10
  private readonly keys;
12
- private readonly splitFiltersValidation;
11
+ private readonly log;
12
+ private readonly storageHash;
13
13
  private readonly flagSetsFilter;
14
14
  private hasSync?;
15
15
  private updateNewFilter?;
@@ -18,7 +18,7 @@ export declare class SplitsCacheInLocal extends AbstractSplitsCacheSync {
18
18
  * @param {number | undefined} expirationTimestamp
19
19
  * @param {ISplitFiltersValidation} splitFiltersValidation
20
20
  */
21
- constructor(log: ILogger, keys: KeyBuilderCS, expirationTimestamp?: number, splitFiltersValidation?: ISplitFiltersValidation);
21
+ constructor(settings: ISettings, keys: KeyBuilderCS, expirationTimestamp?: number);
22
22
  private _decrementCount;
23
23
  private _decrementCounts;
24
24
  private _incrementCounts;
@@ -24,6 +24,18 @@ export declare const STORAGE_PLUGGABLE: StorageType;
24
24
  export declare const CONSENT_GRANTED = "GRANTED";
25
25
  export declare const CONSENT_DECLINED = "DECLINED";
26
26
  export declare const CONSENT_UNKNOWN = "UNKNOWN";
27
+ export declare const GET_TREATMENT = "getTreatment";
28
+ export declare const GET_TREATMENTS = "getTreatments";
29
+ export declare const GET_TREATMENT_WITH_CONFIG = "getTreatmentWithConfig";
30
+ export declare const GET_TREATMENTS_WITH_CONFIG = "getTreatmentsWithConfig";
31
+ export declare const GET_TREATMENTS_BY_FLAG_SET = "getTreatmentsByFlagSet";
32
+ export declare const GET_TREATMENTS_BY_FLAG_SETS = "getTreatmentsByFlagSets";
33
+ export declare const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = "getTreatmentsWithConfigByFlagSet";
34
+ export declare const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = "getTreatmentsWithConfigByFlagSets";
35
+ export declare const TRACK_FN_LABEL = "track";
36
+ export declare const SPLIT_FN_LABEL = "split";
37
+ export declare const SPLITS_FN_LABEL = "splits";
38
+ export declare const NAMES_FN_LABEL = "names";
27
39
  export declare const QUEUED = 0;
28
40
  export declare const DROPPED = 1;
29
41
  export declare const DEDUPED = 2;
@@ -58,5 +58,5 @@ interface ISetConstructor {
58
58
  export declare function __getSetConstructor(): ISetConstructor;
59
59
  export declare const _Set: ISetConstructor;
60
60
  export declare function returnSetsUnion<T>(set: ISet<T>, set2: ISet<T>): ISet<T>;
61
- export declare function returnListDifference<T>(list?: T[], list2?: T[]): T[];
61
+ export declare function returnDifference<T>(list?: T[], list2?: T[]): T[];
62
62
  export {};
@@ -1 +1,5 @@
1
- export declare function mode(key: string, mode: string): string;
1
+ export declare function validateMode(key: string, mode: string): string;
2
+ /**
3
+ * Storage is async if mode is consumer or partial consumer
4
+ */
5
+ export declare function isConsumerMode(mode: string): boolean;
@@ -14,4 +14,4 @@ import { ILogger } from '../../logger/types';
14
14
  * @throws Error if the some of the grouped list of values per filter exceeds the max allowed length
15
15
  */
16
16
  export declare function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode: string): ISplitFiltersValidation;
17
- export declare function flagSetsAreValid(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[];
17
+ export declare function validateFlagSets(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[];
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStorageSync = void 0;
4
- var constants_1 = require("../../utils/constants");
5
- /**
6
- * Storage is async if mode is consumer or partial consumer
7
- */
8
- function isStorageSync(settings) {
9
- return [constants_1.CONSUMER_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
10
- }
11
- exports.isStorageSync = isStorageSync;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisMock = void 0;
4
- //@ts-nocheck
5
- function identityFunction(data) {
6
- return data;
7
- }
8
- function asyncFunction(data) {
9
- return Promise.resolve(data);
10
- }
11
- var IDENTITY_METHODS = [];
12
- var ASYNC_METHODS = ['rpush', 'hincrby'];
13
- var PIPELINE_METHODS = ['rpush', 'hincrby'];
14
- var RedisMock = /** @class */ (function () {
15
- function RedisMock() {
16
- var _this = this;
17
- this.pipelineMethods = { exec: jest.fn(asyncFunction) };
18
- IDENTITY_METHODS.forEach(function (method) {
19
- _this[method] = jest.fn(identityFunction);
20
- });
21
- ASYNC_METHODS.forEach(function (method) {
22
- _this[method] = jest.fn(asyncFunction);
23
- });
24
- PIPELINE_METHODS.forEach(function (method) {
25
- _this.pipelineMethods[method] = _this[method];
26
- });
27
- this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
28
- }
29
- return RedisMock;
30
- }());
31
- exports.RedisMock = RedisMock;
@@ -1,7 +0,0 @@
1
- import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../../utils/constants';
2
- /**
3
- * Storage is async if mode is consumer or partial consumer
4
- */
5
- export function isStorageSync(settings) {
6
- return [CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
7
- }
@@ -1,28 +0,0 @@
1
- //@ts-nocheck
2
- function identityFunction(data) {
3
- return data;
4
- }
5
- function asyncFunction(data) {
6
- return Promise.resolve(data);
7
- }
8
- var IDENTITY_METHODS = [];
9
- var ASYNC_METHODS = ['rpush', 'hincrby'];
10
- var PIPELINE_METHODS = ['rpush', 'hincrby'];
11
- var RedisMock = /** @class */ (function () {
12
- function RedisMock() {
13
- var _this = this;
14
- this.pipelineMethods = { exec: jest.fn(asyncFunction) };
15
- IDENTITY_METHODS.forEach(function (method) {
16
- _this[method] = jest.fn(identityFunction);
17
- });
18
- ASYNC_METHODS.forEach(function (method) {
19
- _this[method] = jest.fn(asyncFunction);
20
- });
21
- PIPELINE_METHODS.forEach(function (method) {
22
- _this.pipelineMethods[method] = _this[method];
23
- });
24
- this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
25
- }
26
- return RedisMock;
27
- }());
28
- export { RedisMock };
@@ -1,9 +0,0 @@
1
- import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../../utils/constants';
2
- import { ISettings } from '../../types';
3
-
4
- /**
5
- * Storage is async if mode is consumer or partial consumer
6
- */
7
- export function isStorageSync(settings: Pick<ISettings, 'mode'>) {
8
- return [CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
9
- }
@@ -1,31 +0,0 @@
1
- //@ts-nocheck
2
- function identityFunction(data: any): any {
3
- return data;
4
- }
5
-
6
- function asyncFunction(data: any): Promise<any> {
7
- return Promise.resolve(data);
8
- }
9
-
10
- const IDENTITY_METHODS: string[] = [];
11
- const ASYNC_METHODS = ['rpush', 'hincrby'];
12
- const PIPELINE_METHODS = ['rpush', 'hincrby'];
13
-
14
- export class RedisMock {
15
-
16
- private pipelineMethods: any = { exec: jest.fn(asyncFunction) };
17
-
18
- constructor() {
19
- IDENTITY_METHODS.forEach(method => {
20
- this[method] = jest.fn(identityFunction);
21
- });
22
- ASYNC_METHODS.forEach(method => {
23
- this[method] = jest.fn(asyncFunction);
24
- });
25
- PIPELINE_METHODS.forEach(method => {
26
- this.pipelineMethods[method] = this[method];
27
- });
28
-
29
- this.pipeline = jest.fn(() => { return this.pipelineMethods; });
30
- }
31
- }