Fix: the signature of putMany is different

This commit is contained in:
eight 2020-02-08 02:08:36 +08:00
parent 733afcbad5
commit e255a4ff2e

View File

@ -14,13 +14,18 @@ function createChromeStorageDB() {
// FIXME: we don't use this method at all. Should we remove this? // FIXME: we don't use this method at all. Should we remove this?
get: id => get(PREFIX + id) get: id => get(PREFIX + id)
.then(result => result[PREFIX + id]), .then(result => result[PREFIX + id]),
put: obj => Promise.resolve(obj && obj.id ? obj.id : prepareInc()) put: obj => Promise.resolve()
.then(() => { .then(() => {
// FIXME: should we clone the object? if (!obj.id) {
obj.id = INC++; return prepareInc()
return set({[PREFIX + obj.id]: obj}) .then(() => {
.then(() => obj.id); // FIXME: should we clone the object?
}), obj.id = INC++;
});
}
})
.then(() => set({[PREFIX + obj.id]: obj}))
.then(() => obj.id),
putMany: items => prepareInc() putMany: items => prepareInc()
.then(() => { .then(() => {
for (const item of items) { for (const item of items) {
@ -52,7 +57,12 @@ function createChromeStorageDB() {
function exec(method, ...args) { function exec(method, ...args) {
if (METHODS[method]) { if (METHODS[method]) {
return METHODS[method](...args) return METHODS[method](...args)
.then(result => ({target: {result}})); .then(result => {
if (method === 'putMany' && result.map) {
return result.map(r => ({target: {result: r}}));
}
return {target: {result}};
});
} }
return Promise.reject(new Error(`unknown DB method ${method}`)); return Promise.reject(new Error(`unknown DB method ${method}`));
} }