@bitblit/ratchet-aws
Version:
Common tools for use with AWS browser and node
27 lines • 1.15 kB
JavaScript
import { RequireRatchet } from '@bitblit/ratchet-common/lang/require-ratchet';
export class S3PrototypeDaoProvider {
s3CacheRatchet;
keyName;
constructor(s3CacheRatchet, keyName) {
this.s3CacheRatchet = s3CacheRatchet;
this.keyName = keyName;
RequireRatchet.notNullOrUndefined(s3CacheRatchet, 's3CacheRatchet');
RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(s3CacheRatchet.getDefaultBucket(), 's3CacheRatchet.defaultBucket');
RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(keyName, 'keyName');
}
async storeDatabase(inDb) {
const toSave = inDb || { items: [], lastModifiedEpochMS: null };
toSave.lastModifiedEpochMS = Date.now();
const put = await this.s3CacheRatchet.writeObjectToCacheFile(this.keyName, toSave);
const rval = !!put;
return rval;
}
async loadDatabase() {
const rval = (await this.s3CacheRatchet.fetchCacheFileAsObject(this.keyName)) || {
items: [],
lastModifiedEpochMS: Date.now(),
};
return rval;
}
}
//# sourceMappingURL=s3-prototype-dao-provider.js.map