@naturalcycles/abba 1.15.2 → 1.15.3
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/dist/types.d.ts +15 -5
- package/dist/types.js +13 -3
- package/dist/util.js +28 -5
- package/package.json +1 -1
- package/src/types.ts +15 -5
- package/src/util.ts +27 -8
package/dist/types.d.ts
CHANGED
|
@@ -50,16 +50,26 @@ export declare enum AssignmentStatus {
|
|
|
50
50
|
export interface SegmentationRule {
|
|
51
51
|
key: string;
|
|
52
52
|
operator: SegmentationRuleOperator;
|
|
53
|
-
value: string
|
|
53
|
+
value: string;
|
|
54
54
|
}
|
|
55
55
|
export declare enum SegmentationRuleOperator {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
IsSet = "isSet",
|
|
57
|
+
IsNotSet = "isNotSet",
|
|
58
|
+
EqualsText = "equalsText",
|
|
59
|
+
NotEqualsText = "notEqualsText",
|
|
58
60
|
Semver = "semver",
|
|
59
61
|
Regex = "regex",
|
|
60
|
-
Boolean = "boolean"
|
|
62
|
+
Boolean = "boolean",
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated
|
|
65
|
+
*/
|
|
66
|
+
Equals = "==",
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated
|
|
69
|
+
*/
|
|
70
|
+
NotEquals = "!="
|
|
61
71
|
}
|
|
62
|
-
export type SegmentationRuleFn = (segmentationProp: string | boolean | number, ruleValue: SegmentationRule['value']) => boolean;
|
|
72
|
+
export type SegmentationRuleFn = (segmentationProp: string | boolean | number | null | undefined, ruleValue: SegmentationRule['value']) => boolean;
|
|
63
73
|
export interface AssignmentStatistics {
|
|
64
74
|
sampled: number;
|
|
65
75
|
buckets: {
|
package/dist/types.js
CHANGED
|
@@ -18,10 +18,20 @@ var AssignmentStatus;
|
|
|
18
18
|
})(AssignmentStatus = exports.AssignmentStatus || (exports.AssignmentStatus = {}));
|
|
19
19
|
var SegmentationRuleOperator;
|
|
20
20
|
(function (SegmentationRuleOperator) {
|
|
21
|
-
SegmentationRuleOperator["
|
|
22
|
-
SegmentationRuleOperator["
|
|
21
|
+
SegmentationRuleOperator["IsSet"] = "isSet";
|
|
22
|
+
SegmentationRuleOperator["IsNotSet"] = "isNotSet";
|
|
23
|
+
SegmentationRuleOperator["EqualsText"] = "equalsText";
|
|
24
|
+
SegmentationRuleOperator["NotEqualsText"] = "notEqualsText";
|
|
23
25
|
SegmentationRuleOperator["Semver"] = "semver";
|
|
24
26
|
SegmentationRuleOperator["Regex"] = "regex";
|
|
25
|
-
/* eslint-disable id-blacklist
|
|
27
|
+
/* eslint-disable id-blacklist*/
|
|
26
28
|
SegmentationRuleOperator["Boolean"] = "boolean";
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated
|
|
31
|
+
*/
|
|
32
|
+
SegmentationRuleOperator["Equals"] = "==";
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated
|
|
35
|
+
*/
|
|
36
|
+
SegmentationRuleOperator["NotEquals"] = "!=";
|
|
27
37
|
})(SegmentationRuleOperator = exports.SegmentationRuleOperator || (exports.SegmentationRuleOperator = {}));
|
package/dist/util.js
CHANGED
|
@@ -92,11 +92,34 @@ exports.validateSegmentationRules = validateSegmentationRules;
|
|
|
92
92
|
* Map of segmentation rule validators
|
|
93
93
|
*/
|
|
94
94
|
exports.segmentationRuleMap = {
|
|
95
|
-
[types_1.SegmentationRuleOperator.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
[types_1.SegmentationRuleOperator.
|
|
99
|
-
|
|
95
|
+
[types_1.SegmentationRuleOperator.IsSet](keyValue) {
|
|
96
|
+
return !!keyValue;
|
|
97
|
+
},
|
|
98
|
+
[types_1.SegmentationRuleOperator.IsNotSet](keyValue) {
|
|
99
|
+
return !keyValue;
|
|
100
|
+
},
|
|
101
|
+
[types_1.SegmentationRuleOperator.EqualsText](keyValue, ruleValue) {
|
|
102
|
+
return keyValue?.toString() === ruleValue.toString();
|
|
103
|
+
},
|
|
104
|
+
[types_1.SegmentationRuleOperator.NotEqualsText](keyValue, ruleValue) {
|
|
105
|
+
return keyValue?.toString() !== ruleValue.toString();
|
|
106
|
+
},
|
|
107
|
+
[types_1.SegmentationRuleOperator.Semver](keyValue, ruleValue) {
|
|
108
|
+
return (0, semver_1.satisfies)(keyValue?.toString() || '', ruleValue.toString());
|
|
109
|
+
},
|
|
110
|
+
[types_1.SegmentationRuleOperator.Regex](keyValue, ruleValue) {
|
|
111
|
+
return new RegExp(`${ruleValue}`).test(keyValue?.toString() || '');
|
|
112
|
+
},
|
|
113
|
+
[types_1.SegmentationRuleOperator.Boolean](keyValue, ruleValue) {
|
|
114
|
+
// If it's true, then must be true
|
|
115
|
+
if (ruleValue === 'true')
|
|
116
|
+
return keyValue === 'true';
|
|
117
|
+
// Anything else cannot be true
|
|
118
|
+
return keyValue !== 'true';
|
|
119
|
+
},
|
|
120
|
+
// Deprecated
|
|
121
|
+
[types_1.SegmentationRuleOperator.Equals]: (keyValue, ruleValue) => keyValue === ruleValue,
|
|
122
|
+
[types_1.SegmentationRuleOperator.NotEquals]: (keyValue, ruleValue) => keyValue !== ruleValue,
|
|
100
123
|
};
|
|
101
124
|
/**
|
|
102
125
|
* Returns true if an experiment is able to generate new assignments based on status and start/end dates
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -61,20 +61,30 @@ export enum AssignmentStatus {
|
|
|
61
61
|
export interface SegmentationRule {
|
|
62
62
|
key: string
|
|
63
63
|
operator: SegmentationRuleOperator
|
|
64
|
-
value: string
|
|
64
|
+
value: string
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export enum SegmentationRuleOperator {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
IsSet = 'isSet',
|
|
69
|
+
IsNotSet = 'isNotSet',
|
|
70
|
+
EqualsText = 'equalsText',
|
|
71
|
+
NotEqualsText = 'notEqualsText',
|
|
70
72
|
Semver = 'semver',
|
|
71
73
|
Regex = 'regex',
|
|
72
|
-
/* eslint-disable id-blacklist
|
|
74
|
+
/* eslint-disable id-blacklist*/
|
|
73
75
|
Boolean = 'boolean',
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated
|
|
78
|
+
*/
|
|
79
|
+
Equals = '==',
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated
|
|
82
|
+
*/
|
|
83
|
+
NotEquals = '!=',
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
export type SegmentationRuleFn = (
|
|
77
|
-
segmentationProp: string | boolean | number,
|
|
87
|
+
segmentationProp: string | boolean | number | null | undefined,
|
|
78
88
|
ruleValue: SegmentationRule['value'],
|
|
79
89
|
) => boolean
|
|
80
90
|
|
package/src/util.ts
CHANGED
|
@@ -111,14 +111,33 @@ export const validateSegmentationRules = (
|
|
|
111
111
|
* Map of segmentation rule validators
|
|
112
112
|
*/
|
|
113
113
|
export const segmentationRuleMap: Record<SegmentationRuleOperator, SegmentationRuleFn> = {
|
|
114
|
-
[SegmentationRuleOperator.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
[SegmentationRuleOperator.
|
|
121
|
-
|
|
114
|
+
[SegmentationRuleOperator.IsSet](keyValue) {
|
|
115
|
+
return !!keyValue
|
|
116
|
+
},
|
|
117
|
+
[SegmentationRuleOperator.IsNotSet](keyValue) {
|
|
118
|
+
return !keyValue
|
|
119
|
+
},
|
|
120
|
+
[SegmentationRuleOperator.EqualsText](keyValue, ruleValue) {
|
|
121
|
+
return keyValue?.toString() === ruleValue.toString()
|
|
122
|
+
},
|
|
123
|
+
[SegmentationRuleOperator.NotEqualsText](keyValue, ruleValue) {
|
|
124
|
+
return keyValue?.toString() !== ruleValue.toString()
|
|
125
|
+
},
|
|
126
|
+
[SegmentationRuleOperator.Semver](keyValue, ruleValue) {
|
|
127
|
+
return satisfies(keyValue?.toString() || '', ruleValue.toString())
|
|
128
|
+
},
|
|
129
|
+
[SegmentationRuleOperator.Regex](keyValue, ruleValue) {
|
|
130
|
+
return new RegExp(`${ruleValue}`).test(keyValue?.toString() || '')
|
|
131
|
+
},
|
|
132
|
+
[SegmentationRuleOperator.Boolean](keyValue, ruleValue) {
|
|
133
|
+
// If it's true, then must be true
|
|
134
|
+
if (ruleValue === 'true') return keyValue === 'true'
|
|
135
|
+
// Anything else cannot be true
|
|
136
|
+
return keyValue !== 'true'
|
|
137
|
+
},
|
|
138
|
+
// Deprecated
|
|
139
|
+
[SegmentationRuleOperator.Equals]: (keyValue, ruleValue) => keyValue === ruleValue,
|
|
140
|
+
[SegmentationRuleOperator.NotEquals]: (keyValue, ruleValue) => keyValue !== ruleValue,
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
/**
|