@bitblit/ratchet-aws
Version:
Common tools for use with AWS browser and node
25 lines • 919 B
JavaScript
export class DynamoExpiringCodeProvider {
tableName;
dynamoRatchet;
constructor(tableName, dynamoRatchet) {
this.tableName = tableName;
this.dynamoRatchet = dynamoRatchet;
}
async checkCode(code, context, deleteOnMatch) {
const keys = { code: code, context: context };
const expCode = await this.dynamoRatchet.simpleGet(this.tableName, keys);
const rval = expCode && expCode.expiresEpochMS > Date.now();
if (rval && deleteOnMatch) {
await this.dynamoRatchet.simpleDelete(this.tableName, keys);
}
return rval;
}
async storeCode(code) {
const output = await this.dynamoRatchet.simplePut(this.tableName, code);
return output && output.ConsumedCapacity.CapacityUnits > 0;
}
async createTableIfMissing(_dtr) {
return null;
}
}
//# sourceMappingURL=dynamo-expiring-code-provider.js.map