dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
22 lines (21 loc) • 723 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Deduper = void 0;
const JSONSerializer = (value) => JSON.stringify(value, (_, val) => (typeof val === 'bigint' ? val.toString() : val));
class Deduper {
constructor({ serializer = JSONSerializer } = {}) {
this.values = [];
this.serializedValues = new Set();
this.serializer = serializer;
}
push(value) {
const serializedValue = this.serializer(value);
const hit = this.serializedValues.has(serializedValue);
if (!hit) {
this.values.push(value);
this.serializedValues.add(serializedValue);
}
return hit;
}
}
exports.Deduper = Deduper;