@omniconvert/server-side-testing-sdk
Version:
TypeScript SDK for server-side A/B testing and experimentation
84 lines • 1.78 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bucket = void 0;
/**
* Bucket class for storing user assignments to experiments and variations
* Maintains consistent user bucketing across sessions
*/
class Bucket {
constructor() {
this.data = new Map();
}
/**
* Add an item to the bucket
*/
add(key, value) {
this.data.set(key, value);
}
/**
* Get an item from the bucket
*/
get(key) {
return this.data.get(key);
}
/**
* Check if the bucket contains a key
*/
has(key) {
return this.data.has(key);
}
/**
* Remove an item from the bucket
*/
remove(key) {
return this.data.delete(key);
}
/**
* Clear all items from the bucket
*/
clear() {
this.data.clear();
}
/**
* Get all keys in the bucket
*/
keys() {
return Array.from(this.data.keys());
}
/**
* Get all values in the bucket
*/
values() {
return Array.from(this.data.values());
}
/**
* Get the size of the bucket
*/
size() {
return this.data.size;
}
/**
* Convert bucket to plain object for serialization
*/
toObject() {
return Object.fromEntries(this.data);
}
/**
* Create bucket from plain object (for deserialization)
*/
static fromObject(obj) {
const bucket = new Bucket();
Object.entries(obj).forEach(([key, value]) => {
bucket.add(key, value);
});
return bucket;
}
/**
* Convert bucket to JSON string
*/
toJSON() {
return this.toObject();
}
}
exports.Bucket = Bucket;
//# sourceMappingURL=Bucket.js.map
;