@aws-amplify/datastore
Version:
AppSyncLocal support for aws-amplify
46 lines (44 loc) • 1.48 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryStore = void 0;
exports.createInMemoryStore = createInMemoryStore;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
class InMemoryStore {
constructor() {
this.db = new Map();
this.getAllKeys = async () => {
return Array.from(this.db.keys());
};
this.multiGet = async (keys) => {
return keys.reduce((res, k) => {
res.push([k, this.db.get(k)]);
return res;
}, []);
};
this.multiRemove = async (keys, callback) => {
keys.forEach(k => this.db.delete(k));
typeof callback === 'function' && callback();
};
this.multiSet = async (entries, callback) => {
entries.forEach(([key, value]) => {
this.setItem(key, value);
});
typeof callback === 'function' && callback();
};
this.setItem = async (key, value) => {
return this.db.set(key, value);
};
this.removeItem = async (key) => {
return this.db.delete(key);
};
this.getItem = async (key) => {
return this.db.get(key);
};
}
}
exports.InMemoryStore = InMemoryStore;
function createInMemoryStore() {
return new InMemoryStore();
}
//# sourceMappingURL=InMemoryStore.js.map