fix more query wrapper bugs
This commit is contained in:
parent
3bf1846ed8
commit
91fc8d56f0
@ -559,7 +559,6 @@ class UInt64 extends PackedArenaObject {
|
|||||||
static fromNumber(n) {
|
static fromNumber(n) {
|
||||||
let x = new UInt64();
|
let x = new UInt64();
|
||||||
x.alloc();
|
x.alloc();
|
||||||
console.log("Creating UINT64 with", n);
|
|
||||||
set64(x.getNative(), n);
|
set64(x.getNative(), n);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -799,7 +799,6 @@ class UInt64 extends PackedArenaObject {
|
|||||||
static fromNumber(n: number): UInt64 {
|
static fromNumber(n: number): UInt64 {
|
||||||
let x = new UInt64();
|
let x = new UInt64();
|
||||||
x.alloc();
|
x.alloc();
|
||||||
console.log("Creating UINT64 with", n);
|
|
||||||
set64(x.getNative(), n);
|
set64(x.getNative(), n);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// FIXME: none of these handlers should pass on the sendResponse.
|
||||||
|
|
||||||
let handlers = {
|
let handlers = {
|
||||||
["balances"]: function(db, detail, sendResponse) {
|
["balances"]: function(db, detail, sendResponse) {
|
||||||
getBalances(db).then(sendResponse);
|
getBalances(db).then(sendResponse);
|
||||||
@ -48,6 +50,12 @@ let handlers = {
|
|||||||
["confirm-reserve"]: function(db, detail, sendResponse) {
|
["confirm-reserve"]: function(db, detail, sendResponse) {
|
||||||
return confirmReserveHandler(db, detail, sendResponse);
|
return confirmReserveHandler(db, detail, sendResponse);
|
||||||
},
|
},
|
||||||
|
["confirm-pay"]: function(db, detail, sendResponse) {
|
||||||
|
return confirmPayHandler(db, detail, sendResponse);
|
||||||
|
},
|
||||||
|
["execute-payment"]: function(db, detail, sendResponse) {
|
||||||
|
return doPaymentHandler(db, detail, sendResponse);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
function Query(db) {
|
function Query(db) {
|
||||||
return new QueryRoot(db);
|
return new QueryRoot(db);
|
||||||
}
|
}
|
||||||
@ -32,6 +33,7 @@ function Query(db) {
|
|||||||
|
|
||||||
abstract class QueryStreamBase {
|
abstract class QueryStreamBase {
|
||||||
abstract subscribe(f: (isDone: boolean, value: any) => void);
|
abstract subscribe(f: (isDone: boolean, value: any) => void);
|
||||||
|
|
||||||
root: QueryRoot;
|
root: QueryRoot;
|
||||||
|
|
||||||
constructor(root: QueryRoot) {
|
constructor(root: QueryRoot) {
|
||||||
@ -41,6 +43,7 @@ abstract class QueryStreamBase {
|
|||||||
indexJoin(storeName: string, indexName: string, key: any): QueryStreamBase {
|
indexJoin(storeName: string, indexName: string, key: any): QueryStreamBase {
|
||||||
// join on the source relation's key, which may be
|
// join on the source relation's key, which may be
|
||||||
// a path or a transformer function
|
// a path or a transformer function
|
||||||
|
this.root.stores.add(storeName);
|
||||||
return new QueryStreamIndexJoin(this, storeName, indexName, key);
|
return new QueryStreamIndexJoin(this, storeName, indexName, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,11 +98,14 @@ class QueryStreamIndexJoin extends QueryStreamBase {
|
|||||||
s: QueryStreamBase;
|
s: QueryStreamBase;
|
||||||
storeName;
|
storeName;
|
||||||
key;
|
key;
|
||||||
|
indexName;
|
||||||
|
|
||||||
constructor(s, storeName: string, indexName: string, key: any) {
|
constructor(s, storeName: string, indexName: string, key: any) {
|
||||||
super(s.root);
|
super(s.root);
|
||||||
this.s = s;
|
this.s = s;
|
||||||
this.storeName = storeName;
|
this.storeName = storeName;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
this.indexName = indexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(f) {
|
subscribe(f) {
|
||||||
@ -108,9 +114,8 @@ class QueryStreamIndexJoin extends QueryStreamBase {
|
|||||||
f(true, undefined);
|
f(true, undefined);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let s = this.root.tx.objectStore(this.storeName).index(this.indexName);
|
||||||
let s = this.root.tx.objectStore(this.storeName);
|
let req = s.openCursor(IDBKeyRange.only(this.key(value)));
|
||||||
let req = s.openCursor(IDBKeyRange.only(value));
|
|
||||||
req.onsuccess = () => {
|
req.onsuccess = () => {
|
||||||
let cursor = req.result;
|
let cursor = req.result;
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
@ -140,7 +145,13 @@ class IterQueryStream extends QueryStreamBase {
|
|||||||
|
|
||||||
subscribe(f) {
|
subscribe(f) {
|
||||||
function doIt() {
|
function doIt() {
|
||||||
let s = this.qr.tx.objectStore(this.storeName);
|
let s;
|
||||||
|
if (this.options && this.options.indexName) {
|
||||||
|
s = this.qr.tx.objectStore(this.storeName)
|
||||||
|
.index(this.options.indexName);
|
||||||
|
} else {
|
||||||
|
s = this.qr.tx.objectStore(this.storeName);
|
||||||
|
}
|
||||||
let kr = undefined;
|
let kr = undefined;
|
||||||
if (this.options && ("only" in this.options)) {
|
if (this.options && ("only" in this.options)) {
|
||||||
kr = IDBKeyRange.only(this.options.only);
|
kr = IDBKeyRange.only(this.options.only);
|
||||||
@ -156,6 +167,7 @@ class IterQueryStream extends QueryStreamBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.qr.work.push(doIt.bind(this));
|
this.qr.work.push(doIt.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,11 +194,17 @@ class QueryRoot {
|
|||||||
return new IterQueryStream(this, storeName, {only: key});
|
return new IterQueryStream(this, storeName, {only: key});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterIndex(storeName, indexName, key) {
|
||||||
|
this.stores.add(storeName);
|
||||||
|
return new IterQueryStream(this, storeName, {indexName: indexName});
|
||||||
|
}
|
||||||
|
|
||||||
put(storeName, val): QueryRoot {
|
put(storeName, val): QueryRoot {
|
||||||
this.stores.add(storeName);
|
this.stores.add(storeName);
|
||||||
function doPut() {
|
function doPut() {
|
||||||
this.tx.objectStore(storeName).put(val);
|
this.tx.objectStore(storeName).put(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.work.push(doPut.bind(this));
|
this.work.push(doPut.bind(this));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -198,6 +216,7 @@ class QueryRoot {
|
|||||||
this.tx.objectStore(storeName).put(obj);
|
this.tx.objectStore(storeName).put(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.work.push(doPutAll.bind(this));
|
this.work.push(doPutAll.bind(this));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -207,6 +226,7 @@ class QueryRoot {
|
|||||||
function doAdd() {
|
function doAdd() {
|
||||||
this.tx.objectStore(storeName).add(val);
|
this.tx.objectStore(storeName).add(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.work.push(doAdd.bind(this));
|
this.work.push(doAdd.bind(this));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -227,6 +247,7 @@ class QueryRoot {
|
|||||||
leakedResolve(req.result);
|
leakedResolve(req.result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.work.push(doGet.bind(this));
|
this.work.push(doGet.bind(this));
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return this.finish().then(() => p);
|
return this.finish().then(() => p);
|
||||||
@ -255,6 +276,7 @@ class QueryRoot {
|
|||||||
function doDelete() {
|
function doDelete() {
|
||||||
this.tx.objectStore(storeName).delete(key);
|
this.tx.objectStore(storeName).delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.work.push(doDelete.bind(this));
|
this.work.push(doDelete.bind(this));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints)
|
|||||||
}
|
}
|
||||||
let ps = allowedMints.map((info) => {
|
let ps = allowedMints.map((info) => {
|
||||||
return Query(db)
|
return Query(db)
|
||||||
.iterOnly("mints", info.master_pub)
|
.iterIndex("mints", "pubKey", info.master_pub)
|
||||||
.indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
|
.indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
|
||||||
.reduce(storeMintCoin);
|
.reduce(storeMintCoin);
|
||||||
});
|
});
|
||||||
|
@ -208,7 +208,7 @@ function getPossibleMintCoins(db: IDBDatabase,
|
|||||||
|
|
||||||
let ps = allowedMints.map((info) => {
|
let ps = allowedMints.map((info) => {
|
||||||
return Query(db)
|
return Query(db)
|
||||||
.iterOnly("mints", info.master_pub)
|
.iterIndex("mints", "pubKey", info.master_pub)
|
||||||
.indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
|
.indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
|
||||||
.reduce(storeMintCoin);
|
.reduce(storeMintCoin);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user