@@ -5,12 +5,44 @@ import { getMatching } from '../utils/key';
5
5
import { IMembershipsResponse , IMySegmentsResponse , IRBSegment , ISplit } from '../dtos/types' ;
6
6
import { ILogger } from '../logger/types' ;
7
7
8
+ export type RolloutPlan = {
9
+ /**
10
+ * Change number of feature flags.
11
+ */
12
+ since : number ;
13
+ /**
14
+ * List of feature flags.
15
+ */
16
+ flags : ISplit [ ] ;
17
+ /**
18
+ * Change number of rule-based segments.
19
+ */
20
+ rbSince ?: number ;
21
+ /**
22
+ * List of rule-based segments.
23
+ */
24
+ rbSegments ?: IRBSegment [ ] ;
25
+ /**
26
+ * Optional map of user keys to their memberships.
27
+ */
28
+ memberships ?: {
29
+ [ key : string ] : IMembershipsResponse ;
30
+ } ;
31
+ /**
32
+ * Optional map of standard segments to their list of keys.
33
+ * This property is ignored if `memberships` is provided.
34
+ */
35
+ segments ?: {
36
+ [ segmentName : string ] : string [ ] ;
37
+ } ;
38
+ } ;
39
+
8
40
/**
9
41
* Sets the given synchronous storage with the provided rollout plan snapshot.
10
42
* If `matchingKey` is provided, the storage is handled as a client-side storage (segments and largeSegments are instances of MySegmentsCache).
11
43
* Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
12
44
*/
13
- export function setRolloutPlan ( log : ILogger , rolloutPlan : SplitIO . RolloutPlan , storage : { splits ?: ISplitsCacheSync , rbSegments ?: IRBSegmentsCacheSync , segments : ISegmentsCacheSync , largeSegments ?: ISegmentsCacheSync } , matchingKey ?: string ) {
45
+ export function setRolloutPlan ( log : ILogger , rolloutPlan : RolloutPlan , storage : { splits ?: ISplitsCacheSync , rbSegments ?: IRBSegmentsCacheSync , segments : ISegmentsCacheSync , largeSegments ?: ISegmentsCacheSync } , matchingKey ?: string ) {
14
46
// Do not load data if current rollout plan is empty
15
47
if ( Object . keys ( rolloutPlan ) . length === 0 ) return ;
16
48
@@ -20,12 +52,12 @@ export function setRolloutPlan(log: ILogger, rolloutPlan: SplitIO.RolloutPlan, s
20
52
21
53
if ( splits ) {
22
54
splits . clear ( ) ;
23
- splits . update ( rolloutPlan . flags as ISplit [ ] || [ ] , [ ] , rolloutPlan . since || - 1 ) ;
55
+ splits . update ( rolloutPlan . flags || [ ] , [ ] , rolloutPlan . since || - 1 ) ;
24
56
}
25
57
26
58
if ( rbSegments ) {
27
59
rbSegments . clear ( ) ;
28
- rbSegments . update ( rolloutPlan . rbSegments as IRBSegment [ ] || [ ] , [ ] , rolloutPlan . rbSince || - 1 ) ;
60
+ rbSegments . update ( rolloutPlan . rbSegments || [ ] , [ ] , rolloutPlan . rbSince || - 1 ) ;
29
61
}
30
62
31
63
const segmentsData = rolloutPlan . segments || { } ;
@@ -43,8 +75,8 @@ export function setRolloutPlan(log: ILogger, rolloutPlan: SplitIO.RolloutPlan, s
43
75
}
44
76
45
77
if ( memberships ) {
46
- if ( ( memberships as IMembershipsResponse ) . ms ) segments . resetSegments ( ( memberships as IMembershipsResponse ) . ms ! ) ;
47
- if ( ( memberships as IMembershipsResponse ) . ls && largeSegments ) largeSegments . resetSegments ( ( memberships as IMembershipsResponse ) . ls ! ) ;
78
+ if ( memberships . ms ) segments . resetSegments ( memberships . ms ! ) ;
79
+ if ( memberships . ls && largeSegments ) largeSegments . resetSegments ( memberships . ls ! ) ;
48
80
}
49
81
} else { // add segments data (server-side)
50
82
Object . keys ( segmentsData ) . forEach ( segmentName => {
@@ -59,7 +91,7 @@ export function setRolloutPlan(log: ILogger, rolloutPlan: SplitIO.RolloutPlan, s
59
91
* If `keys` are provided, the memberships for those keys is returned, to protect segments data.
60
92
* Otherwise, the segments data is returned.
61
93
*/
62
- export function getRolloutPlan ( log : ILogger , storage : IStorageSync , keys ?: SplitIO . SplitKey [ ] ) : SplitIO . RolloutPlan {
94
+ export function getRolloutPlan ( log : ILogger , storage : IStorageSync , keys ?: SplitIO . SplitKey [ ] ) : RolloutPlan {
63
95
64
96
log . debug ( `storage: get feature flags and segments${ keys ? ` for keys ${ keys } ` : '' } ` ) ;
65
97
0 commit comments