idb-bridge: update tests for ava 4.x

This commit is contained in:
Florian Dold 2022-02-10 19:52:45 +01:00
parent 1de423834d
commit 5ff3b44550
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
47 changed files with 2073 additions and 1913 deletions

View File

@ -4,6 +4,7 @@
"description": "IndexedDB implementation that uses SQLite3 as storage", "description": "IndexedDB implementation that uses SQLite3 as storage",
"main": "./dist/idb-bridge.js", "main": "./dist/idb-bridge.js",
"module": "./lib/index.js", "module": "./lib/index.js",
"type": "module",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",
"author": "Florian Dold", "author": "Florian Dold",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
@ -19,13 +20,13 @@
"@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.3", "@rollup/plugin-node-resolve": "^13.1.3",
"@types/node": "^17.0.8", "@types/node": "^17.0.17",
"ava": "^3.15.0", "ava": "^4.0.1",
"esm": "^3.2.25", "esm": "^3.2.25",
"prettier": "^2.2.1", "prettier": "^2.5.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rollup": "^2.63.0", "rollup": "^2.67.2",
"typescript": "^4.5.4" "typescript": "^4.5.5"
}, },
"dependencies": { "dependencies": {
"tslib": "^2.3.1" "tslib": "^2.3.1"

View File

@ -22,14 +22,14 @@ import {
BridgeIDBKeyRange, BridgeIDBKeyRange,
BridgeIDBRequest, BridgeIDBRequest,
BridgeIDBTransaction, BridgeIDBTransaction,
} from "./bridge-idb"; } from "./bridge-idb.js";
import { import {
IDBCursorDirection, IDBCursorDirection,
IDBCursorWithValue, IDBCursorWithValue,
IDBKeyRange, IDBKeyRange,
IDBValidKey, IDBValidKey,
} from "./idbtypes.js"; } from "./idbtypes.js";
import { MemoryBackend } from "./MemoryBackend"; import { MemoryBackend } from "./MemoryBackend.js";
function promiseFromRequest(request: BridgeIDBRequest): Promise<any> { function promiseFromRequest(request: BridgeIDBRequest): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -150,7 +150,7 @@ test("Spec: Example 1 Part 3", async (t) => {
await promiseFromRequest(request3); await promiseFromRequest(request3);
let cursor: BridgeIDBCursorWithValue; let cursor: BridgeIDBCursorWithValue | null;
cursor = request3.result as BridgeIDBCursorWithValue; cursor = request3.result as BridgeIDBCursorWithValue;
t.is(cursor.value.author, "Fred"); t.is(cursor.value.author, "Fred");
t.is(cursor.value.isbn, 123456); t.is(cursor.value.isbn, 123456);
@ -172,6 +172,9 @@ test("Spec: Example 1 Part 3", async (t) => {
await promiseFromRequest(request4); await promiseFromRequest(request4);
cursor = request4.result; cursor = request4.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.isbn, 123456); t.is(cursor.value.isbn, 123456);
cursor.continue(); cursor.continue();
@ -179,6 +182,9 @@ test("Spec: Example 1 Part 3", async (t) => {
await promiseFromRequest(request4); await promiseFromRequest(request4);
cursor = request4.result; cursor = request4.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.isbn, 234567); t.is(cursor.value.isbn, 234567);
cursor.continue(); cursor.continue();
@ -186,6 +192,9 @@ test("Spec: Example 1 Part 3", async (t) => {
await promiseFromRequest(request4); await promiseFromRequest(request4);
cursor = request4.result; cursor = request4.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.isbn, 345678); t.is(cursor.value.isbn, 345678);
cursor.continue(); cursor.continue();
@ -203,16 +212,25 @@ test("Spec: Example 1 Part 3", async (t) => {
await promiseFromRequest(request5); await promiseFromRequest(request5);
cursor = request5.result; cursor = request5.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Barney"); t.is(cursor.value.author, "Barney");
cursor.continue(); cursor.continue();
await promiseFromRequest(request5); await promiseFromRequest(request5);
cursor = request5.result; cursor = request5.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Fred"); t.is(cursor.value.author, "Fred");
cursor.continue(); cursor.continue();
await promiseFromRequest(request5); await promiseFromRequest(request5);
cursor = request5.result; cursor = request5.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Fred"); t.is(cursor.value.author, "Fred");
cursor.continue(); cursor.continue();
@ -224,11 +242,17 @@ test("Spec: Example 1 Part 3", async (t) => {
await promiseFromRequest(request6); await promiseFromRequest(request6);
cursor = request6.result; cursor = request6.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Barney"); t.is(cursor.value.author, "Barney");
cursor.continue(); cursor.continue();
await promiseFromRequest(request6); await promiseFromRequest(request6);
cursor = request6.result; cursor = request6.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Fred"); t.is(cursor.value.author, "Fred");
t.is(cursor.value.isbn, 123456); t.is(cursor.value.isbn, 123456);
cursor.continue(); cursor.continue();
@ -240,12 +264,18 @@ test("Spec: Example 1 Part 3", async (t) => {
const request7 = index5.openCursor(null, "prevunique"); const request7 = index5.openCursor(null, "prevunique");
await promiseFromRequest(request7); await promiseFromRequest(request7);
cursor = request7.result; cursor = request7.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Fred"); t.is(cursor.value.author, "Fred");
t.is(cursor.value.isbn, 123456); t.is(cursor.value.isbn, 123456);
cursor.continue(); cursor.continue();
await promiseFromRequest(request7); await promiseFromRequest(request7);
cursor = request7.result; cursor = request7.result;
if (!cursor) {
throw new Error();
}
t.is(cursor.value.author, "Barney"); t.is(cursor.value.author, "Barney");
cursor.continue(); cursor.continue();

View File

@ -26,20 +26,20 @@ import {
ResultLevel, ResultLevel,
StoreLevel, StoreLevel,
RecordStoreResponse, RecordStoreResponse,
} from "./backend-interface"; } from "./backend-interface.js";
import { import {
structuredClone, structuredClone,
structuredEncapsulate, structuredEncapsulate,
structuredRevive, structuredRevive,
} from "./util/structuredClone"; } from "./util/structuredClone.js";
import { ConstraintError, DataError } from "./util/errors"; import { ConstraintError, DataError } from "./util/errors.js";
import BTree, { ISortedMapF, ISortedSetF } from "./tree/b+tree"; import BTree, { ISortedMapF, ISortedSetF } from "./tree/b+tree.js";
import { compareKeys } from "./util/cmp"; import { compareKeys } from "./util/cmp.js";
import { StoreKeyResult, makeStoreKeyValue } from "./util/makeStoreKeyValue"; import { StoreKeyResult, makeStoreKeyValue } from "./util/makeStoreKeyValue.js";
import { getIndexKeys } from "./util/getIndexKeys"; import { getIndexKeys } from "./util/getIndexKeys.js";
import { openPromise } from "./util/openPromise"; import { openPromise } from "./util/openPromise.js";
import { IDBKeyRange, IDBTransactionMode, IDBValidKey } from "./idbtypes"; import { IDBKeyRange, IDBTransactionMode, IDBValidKey } from "./idbtypes.js";
import { BridgeIDBKeyRange } from "./bridge-idb"; import { BridgeIDBKeyRange } from "./bridge-idb.js";
type Key = IDBValidKey; type Key = IDBValidKey;
type Value = unknown; type Value = unknown;

View File

@ -14,12 +14,12 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { BridgeIDBDatabaseInfo, BridgeIDBKeyRange } from "./bridge-idb"; import { BridgeIDBDatabaseInfo, BridgeIDBKeyRange } from "./bridge-idb.js";
import { import {
IDBCursorDirection, IDBCursorDirection,
IDBTransactionMode, IDBTransactionMode,
IDBValidKey, IDBValidKey,
} from "./idbtypes"; } from "./idbtypes.js";
/** @public */ /** @public */
export interface ObjectStoreProperties { export interface ObjectStoreProperties {

View File

@ -24,7 +24,7 @@ import {
ResultLevel, ResultLevel,
Schema, Schema,
StoreLevel, StoreLevel,
} from "./backend-interface"; } from "./backend-interface.js";
import { import {
DOMException, DOMException,
DOMStringList, DOMStringList,
@ -41,10 +41,10 @@ import {
IDBTransaction, IDBTransaction,
IDBTransactionMode, IDBTransactionMode,
IDBValidKey, IDBValidKey,
} from "./idbtypes"; } from "./idbtypes.js";
import { canInjectKey } from "./util/canInjectKey"; import { canInjectKey } from "./util/canInjectKey.js";
import { compareKeys } from "./util/cmp"; import { compareKeys } from "./util/cmp.js";
import { enforceRange } from "./util/enforceRange"; import { enforceRange } from "./util/enforceRange.js";
import { import {
AbortError, AbortError,
ConstraintError, ConstraintError,
@ -56,20 +56,19 @@ import {
ReadOnlyError, ReadOnlyError,
TransactionInactiveError, TransactionInactiveError,
VersionError, VersionError,
} from "./util/errors"; } from "./util/errors.js";
import { FakeDOMStringList, fakeDOMStringList } from "./util/fakeDOMStringList"; import { FakeDOMStringList, fakeDOMStringList } from "./util/fakeDOMStringList.js";
import FakeEvent from "./util/FakeEvent"; import FakeEvent from "./util/FakeEvent.js";
import FakeEventTarget from "./util/FakeEventTarget"; import FakeEventTarget from "./util/FakeEventTarget.js";
import { makeStoreKeyValue } from "./util/makeStoreKeyValue"; import { makeStoreKeyValue } from "./util/makeStoreKeyValue.js";
import { normalizeKeyPath } from "./util/normalizeKeyPath"; import { normalizeKeyPath } from "./util/normalizeKeyPath.js";
import { openPromise } from "./util/openPromise"; import { openPromise } from "./util/openPromise.js";
import queueTask from "./util/queueTask"; import queueTask from "./util/queueTask.js";
import { import {
checkStructuredCloneOrThrow, checkStructuredCloneOrThrow,
structuredClone, } from "./util/structuredClone.js";
} from "./util/structuredClone"; import { validateKeyPath } from "./util/validateKeyPath.js";
import { validateKeyPath } from "./util/validateKeyPath"; import { valueToKey } from "./util/valueToKey.js";
import { valueToKey } from "./util/valueToKey";
/** @public */ /** @public */
export type CursorSource = BridgeIDBIndex | BridgeIDBObjectStore; export type CursorSource = BridgeIDBIndex | BridgeIDBObjectStore;

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
test("WPT test abort-in-initial-upgradeneeded.htm", async (t) => { test("WPT test abort-in-initial-upgradeneeded.htm", async (t) => {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {

View File

@ -1,44 +1,44 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { createdb } from "./wptsupport.js";
import { BridgeIDBCursorWithValue } from "../bridge-idb";
import { createdb } from "./wptsupport";
// When db.close is called in upgradeneeded, the db is cleaned up on refresh // When db.close is called in upgradeneeded, the db is cleaned up on refresh
test.cb("WPT test close-in-upgradeneeded.htm", (t) => { test("WPT test close-in-upgradeneeded.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
var open_rq = createdb(t); var db: any;
var sawTransactionComplete = false; var open_rq = createdb(t);
var sawTransactionComplete = false;
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
t.deepEqual(db.version, 1); t.deepEqual(db.version, 1);
db.createObjectStore("os"); db.createObjectStore("os");
db.close(); db.close();
e.target.transaction.oncomplete = function () { e.target.transaction.oncomplete = function () {
sawTransactionComplete = true; sawTransactionComplete = true;
};
}; };
};
open_rq.onerror = function (e: any) { open_rq.onerror = function (e: any) {
t.true(sawTransactionComplete, "saw transaction.complete"); t.true(sawTransactionComplete, "saw transaction.complete");
t.deepEqual(e.target.error.name, "AbortError"); t.deepEqual(e.target.error.name, "AbortError");
t.deepEqual(e.result, undefined); t.deepEqual(e.result, undefined);
t.true(!!db); t.true(!!db);
t.deepEqual(db.version, 1); t.deepEqual(db.version, 1);
t.deepEqual(db.objectStoreNames.length, 1); t.deepEqual(db.objectStoreNames.length, 1);
t.throws( t.throws(
() => { () => {
db.transaction("os"); db.transaction("os");
}, },
{ {
name: "InvalidStateError", name: "InvalidStateError",
}, },
); );
t.end(); resolve();
}; };
});
}); });

View File

@ -1,117 +1,130 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor, BridgeIDBKeyRange } from ".."; import { BridgeIDBKeyRange } from "../bridge-idb.js";
import { BridgeIDBCursorWithValue } from "../bridge-idb"; import { IDBRequest } from "../idbtypes.js";
import { IDBRequest } from "../idbtypes"; import { createdb } from "./wptsupport.js";
import { createdb } from "./wptsupport";
const IDBKeyRange = BridgeIDBKeyRange; const IDBKeyRange = BridgeIDBKeyRange;
// Validate the overloads of IDBObjectStore.openCursor(), // Validate the overloads of IDBObjectStore.openCursor(),
// IDBIndex.openCursor() and IDBIndex.openKeyCursor() // IDBIndex.openCursor() and IDBIndex.openKeyCursor()
test.cb("WPT test cursor-overloads.htm", (t) => { test("WPT test cursor-overloads.htm", (t) => {
var db: any, store: any, index: any; return new Promise((resolve, reject) => {
var db: any, store: any, index: any;
var request = createdb(t); var request = createdb(t);
request.onupgradeneeded = function (e: any) { request.onupgradeneeded = function (e: any) {
db = request.result; db = request.result;
store = db.createObjectStore("store"); store = db.createObjectStore("store");
index = store.createIndex("index", "value"); index = store.createIndex("index", "value");
store.put({ value: 0 }, 0); store.put({ value: 0 }, 0);
const trans = request.transaction!; const trans = request.transaction!;
trans.oncomplete = verifyOverloads; trans.oncomplete = verifyOverloads;
}; };
async function verifyOverloads() { async function verifyOverloads() {
const trans = db.transaction("store"); const trans = db.transaction("store");
store = trans.objectStore("store"); store = trans.objectStore("store");
index = store.index("index"); index = store.index("index");
await checkCursorDirection(store.openCursor(), "next"); await checkCursorDirection(store.openCursor(), "next");
await checkCursorDirection(store.openCursor(0), "next"); await checkCursorDirection(store.openCursor(0), "next");
await checkCursorDirection(store.openCursor(0, "next"), "next"); await checkCursorDirection(store.openCursor(0, "next"), "next");
await checkCursorDirection(store.openCursor(0, "nextunique"), "nextunique"); await checkCursorDirection(
await checkCursorDirection(store.openCursor(0, "prev"), "prev"); store.openCursor(0, "nextunique"),
await checkCursorDirection(store.openCursor(0, "prevunique"), "prevunique"); "nextunique",
);
await checkCursorDirection(store.openCursor(0, "prev"), "prev");
await checkCursorDirection(
store.openCursor(0, "prevunique"),
"prevunique",
);
await checkCursorDirection(store.openCursor(IDBKeyRange.only(0)), "next"); await checkCursorDirection(store.openCursor(IDBKeyRange.only(0)), "next");
await checkCursorDirection( await checkCursorDirection(
store.openCursor(BridgeIDBKeyRange.only(0), "next"), store.openCursor(BridgeIDBKeyRange.only(0), "next"),
"next", "next",
); );
await checkCursorDirection( await checkCursorDirection(
store.openCursor(IDBKeyRange.only(0), "nextunique"), store.openCursor(IDBKeyRange.only(0), "nextunique"),
"nextunique", "nextunique",
); );
await checkCursorDirection( await checkCursorDirection(
store.openCursor(IDBKeyRange.only(0), "prev"), store.openCursor(IDBKeyRange.only(0), "prev"),
"prev", "prev",
); );
await checkCursorDirection( await checkCursorDirection(
store.openCursor(IDBKeyRange.only(0), "prevunique"), store.openCursor(IDBKeyRange.only(0), "prevunique"),
"prevunique", "prevunique",
); );
await checkCursorDirection(index.openCursor(), "next"); await checkCursorDirection(index.openCursor(), "next");
await checkCursorDirection(index.openCursor(0), "next"); await checkCursorDirection(index.openCursor(0), "next");
await checkCursorDirection(index.openCursor(0, "next"), "next"); await checkCursorDirection(index.openCursor(0, "next"), "next");
await checkCursorDirection(index.openCursor(0, "nextunique"), "nextunique"); await checkCursorDirection(
await checkCursorDirection(index.openCursor(0, "prev"), "prev"); index.openCursor(0, "nextunique"),
await checkCursorDirection(index.openCursor(0, "prevunique"), "prevunique"); "nextunique",
);
await checkCursorDirection(index.openCursor(0, "prev"), "prev");
await checkCursorDirection(
index.openCursor(0, "prevunique"),
"prevunique",
);
await checkCursorDirection(index.openCursor(IDBKeyRange.only(0)), "next"); await checkCursorDirection(index.openCursor(IDBKeyRange.only(0)), "next");
await checkCursorDirection( await checkCursorDirection(
index.openCursor(IDBKeyRange.only(0), "next"), index.openCursor(IDBKeyRange.only(0), "next"),
"next", "next",
); );
await checkCursorDirection( await checkCursorDirection(
index.openCursor(IDBKeyRange.only(0), "nextunique"), index.openCursor(IDBKeyRange.only(0), "nextunique"),
"nextunique", "nextunique",
); );
await checkCursorDirection( await checkCursorDirection(
index.openCursor(IDBKeyRange.only(0), "prev"), index.openCursor(IDBKeyRange.only(0), "prev"),
"prev", "prev",
); );
await checkCursorDirection( await checkCursorDirection(
index.openCursor(IDBKeyRange.only(0), "prevunique"), index.openCursor(IDBKeyRange.only(0), "prevunique"),
"prevunique", "prevunique",
); );
await checkCursorDirection(index.openKeyCursor(), "next"); await checkCursorDirection(index.openKeyCursor(), "next");
await checkCursorDirection(index.openKeyCursor(0), "next"); await checkCursorDirection(index.openKeyCursor(0), "next");
await checkCursorDirection(index.openKeyCursor(0, "next"), "next"); await checkCursorDirection(index.openKeyCursor(0, "next"), "next");
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(0, "nextunique"), index.openKeyCursor(0, "nextunique"),
"nextunique", "nextunique",
); );
await checkCursorDirection(index.openKeyCursor(0, "prev"), "prev"); await checkCursorDirection(index.openKeyCursor(0, "prev"), "prev");
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(0, "prevunique"), index.openKeyCursor(0, "prevunique"),
"prevunique", "prevunique",
); );
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(IDBKeyRange.only(0)), index.openKeyCursor(IDBKeyRange.only(0)),
"next", "next",
); );
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(IDBKeyRange.only(0), "next"), index.openKeyCursor(IDBKeyRange.only(0), "next"),
"next", "next",
); );
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(IDBKeyRange.only(0), "nextunique"), index.openKeyCursor(IDBKeyRange.only(0), "nextunique"),
"nextunique", "nextunique",
); );
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(IDBKeyRange.only(0), "prev"), index.openKeyCursor(IDBKeyRange.only(0), "prev"),
"prev", "prev",
); );
await checkCursorDirection( await checkCursorDirection(
index.openKeyCursor(IDBKeyRange.only(0), "prevunique"), index.openKeyCursor(IDBKeyRange.only(0), "prevunique"),
"prevunique", "prevunique",
); );
t.end(); resolve();
} }
});
function checkCursorDirection( function checkCursorDirection(
request: IDBRequest, request: IDBRequest,

View File

@ -1,11 +1,10 @@
import test from "ava"; import test from "ava";
import { BridgeIDBRequest } from ".."; import { BridgeIDBRequest } from "../bridge-idb.js";
import { import {
createdb,
indexeddb_test, indexeddb_test,
is_transaction_active, is_transaction_active,
keep_alive, keep_alive,
} from "./wptsupport"; } from "./wptsupport.js";
test("WPT test abort-in-initial-upgradeneeded.htm (subtest 1)", async (t) => { test("WPT test abort-in-initial-upgradeneeded.htm (subtest 1)", async (t) => {
// Transactions are active during success handlers // Transactions are active during success handlers

View File

@ -1,8 +1,6 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { BridgeIDBCursor,BridgeIDBRequest } from "../bridge-idb.js";
import { BridgeIDBRequest } from "../bridge-idb"; import { createdb } from "./wptsupport.js";
import { InvalidStateError } from "../util/errors";
import { createdb } from "./wptsupport";
test("WPT test idbcursor_advance_index.htm", async (t) => { test("WPT test idbcursor_advance_index.htm", async (t) => {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {

View File

@ -1,385 +1,401 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { BridgeIDBCursor, BridgeIDBCursorWithValue } from "../bridge-idb.js";
import { BridgeIDBCursorWithValue } from "../bridge-idb"; import { createdb } from "./wptsupport.js";
import { createdb } from "./wptsupport";
test.cb("WPT test idbcursor_continue_index.htm", (t) => { test("WPT test idbcursor_continue_index.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
let count = 0; var db: any;
const records = [ let count = 0;
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, const records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" }, { pKey: "primaryKey_1", iKey: "indexKey_1" },
]; { pKey: "primaryKey_1-2", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, records.length, "cursor run count");
t.end();
return;
}
var record = cursor.value;
t.deepEqual(record.pKey, records[count].pKey, "primary key");
t.deepEqual(record.iKey, records[count].iKey, "index key");
cursor.continue();
count++;
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, records.length, "cursor run count");
resolve();
return;
}
var record = cursor.value;
t.deepEqual(record.pKey, records[count].pKey, "primary key");
t.deepEqual(record.iKey, records[count].iKey, "index key");
cursor.continue();
count++;
};
};
});
}); });
// IDBCursor.continue() - index - attempt to pass a key parameter that is not a valid key // IDBCursor.continue() - index - attempt to pass a key parameter that is not a valid key
test.cb("WPT idbcursor-continue-index2.htm", (t) => { test("WPT idbcursor-continue-index2.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
let records = [ var db: any;
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, let records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.throws(
() => {
cursor.continue({ foo: "bar" });
},
{ name: "DataError" },
);
t.true(cursor instanceof BridgeIDBCursorWithValue, "cursor");
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.throws(
() => {
cursor.continue({ foo: "bar" });
},
{ name: "DataError" },
);
t.true(cursor instanceof BridgeIDBCursorWithValue, "cursor");
resolve();
};
};
});
}); });
// IDBCursor.continue() - index - attempt to iterate to the previous // IDBCursor.continue() - index - attempt to iterate to the previous
// record when the direction is set for the next record // record when the direction is set for the next record
test.cb("WPT idbcursor-continue-index3.htm", (t) => { test("WPT idbcursor-continue-index3.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [ var db: any;
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, const records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var count = 0;
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "next"); // XXX: Fx has issue with "undefined"
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, 2, "ran number of times");
t.end();
return;
}
// First time checks key equal, second time checks key less than
t.throws(
() => {
cursor.continue(records[0].iKey);
},
{ name: "DataError" },
);
cursor.continue();
count++;
}; };
};
open_rq.onsuccess = function (e: any) {
var count = 0;
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "next"); // XXX: Fx has issue with "undefined"
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, 2, "ran number of times");
resolve();
return;
}
// First time checks key equal, second time checks key less than
t.throws(
() => {
cursor.continue(records[0].iKey);
},
{ name: "DataError" },
);
cursor.continue();
count++;
};
};
});
}); });
// IDBCursor.continue() - index - attempt to iterate to the next // IDBCursor.continue() - index - attempt to iterate to the next
// record when the direction is set for the previous record // record when the direction is set for the previous record
test.cb("WPT idbcursor-continue-index4.htm", (t) => { test("WPT idbcursor-continue-index4.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [ var db: any;
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, const records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" }, { pKey: "primaryKey_1", iKey: "indexKey_1" },
]; { pKey: "primaryKey_2", iKey: "indexKey_2" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "prev"); // XXX Fx issues w undefined
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result,
record = cursor.value;
switch (count) {
case 0:
t.deepEqual(record.pKey, records[2].pKey, "first pKey");
t.deepEqual(record.iKey, records[2].iKey, "first iKey");
cursor.continue();
break;
case 1:
t.deepEqual(record.pKey, records[1].pKey, "second pKey");
t.deepEqual(record.iKey, records[1].iKey, "second iKey");
t.throws(
() => {
cursor.continue("indexKey_2");
},
{ name: "DataError" },
);
t.end();
break;
default:
t.fail("Unexpected count value: " + count);
}
count++;
}; };
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "prev"); // XXX Fx issues w undefined
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result,
record = cursor.value;
switch (count) {
case 0:
t.deepEqual(record.pKey, records[2].pKey, "first pKey");
t.deepEqual(record.iKey, records[2].iKey, "first iKey");
cursor.continue();
break;
case 1:
t.deepEqual(record.pKey, records[1].pKey, "second pKey");
t.deepEqual(record.iKey, records[1].iKey, "second iKey");
t.throws(
() => {
cursor.continue("indexKey_2");
},
{ name: "DataError" },
);
resolve();
break;
default:
t.fail("Unexpected count value: " + count);
}
count++;
};
};
});
}); });
// IDBCursor.continue() - index - iterate using 'prevunique' // IDBCursor.continue() - index - iterate using 'prevunique'
test.cb("WPT idbcursor-continue-index5.htm", (t) => { test("WPT idbcursor-continue-index5.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [ var db: any;
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, const records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" }, { pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" }, { pKey: "primaryKey_1-2", iKey: "indexKey_1" },
]; { pKey: "primaryKey_2", iKey: "indexKey_2" },
const expected = [ ];
{ pKey: "primaryKey_2", iKey: "indexKey_2" }, const expected = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_2", iKey: "indexKey_2" },
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, { pKey: "primaryKey_1", iKey: "indexKey_1" },
]; { pKey: "primaryKey_0", iKey: "indexKey_0" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "prevunique");
cursor_rq.onsuccess = function (e: any) {
if (!e.target.result) {
t.deepEqual(count, expected.length, "count");
t.end();
return;
}
const cursor = e.target.result;
const record = cursor.value;
t.deepEqual(record.pKey, expected[count].pKey, "pKey #" + count);
t.deepEqual(record.iKey, expected[count].iKey, "iKey #" + count);
t.deepEqual(cursor.key, expected[count].iKey, "cursor.key #" + count);
t.deepEqual(
cursor.primaryKey,
expected[count].pKey,
"cursor.primaryKey #" + count,
);
count++;
cursor.continue(expected[count] ? expected[count].iKey : undefined);
}; };
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "prevunique");
cursor_rq.onsuccess = function (e: any) {
if (!e.target.result) {
t.deepEqual(count, expected.length, "count");
resolve();
return;
}
const cursor = e.target.result;
const record = cursor.value;
t.deepEqual(record.pKey, expected[count].pKey, "pKey #" + count);
t.deepEqual(record.iKey, expected[count].iKey, "iKey #" + count);
t.deepEqual(cursor.key, expected[count].iKey, "cursor.key #" + count);
t.deepEqual(
cursor.primaryKey,
expected[count].pKey,
"cursor.primaryKey #" + count,
);
count++;
cursor.continue(expected[count] ? expected[count].iKey : undefined);
};
};
});
}); });
// IDBCursor.continue() - index - iterate using nextunique // IDBCursor.continue() - index - iterate using nextunique
test.cb("WPT idbcursor-continue-index6.htm", (t) => { test("WPT idbcursor-continue-index6.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [ var db: any;
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, const records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" }, { pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" }, { pKey: "primaryKey_1-2", iKey: "indexKey_1" },
]; { pKey: "primaryKey_2", iKey: "indexKey_2" },
const expected = [ ];
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, const expected = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" }, { pKey: "primaryKey_1", iKey: "indexKey_1" },
]; { pKey: "primaryKey_2", iKey: "indexKey_2" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "nextunique");
cursor_rq.onsuccess = function (e: any) {
if (!e.target.result) {
t.deepEqual(count, expected.length, "count");
t.end();
return;
}
var cursor = e.target.result,
record = cursor.value;
t.deepEqual(record.pKey, expected[count].pKey, "pKey #" + count);
t.deepEqual(record.iKey, expected[count].iKey, "iKey #" + count);
t.deepEqual(cursor.key, expected[count].iKey, "cursor.key #" + count);
t.deepEqual(
cursor.primaryKey,
expected[count].pKey,
"cursor.primaryKey #" + count,
);
count++;
cursor.continue(expected[count] ? expected[count].iKey : undefined);
}; };
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "nextunique");
cursor_rq.onsuccess = function (e: any) {
if (!e.target.result) {
t.deepEqual(count, expected.length, "count");
resolve();
return;
}
var cursor = e.target.result,
record = cursor.value;
t.deepEqual(record.pKey, expected[count].pKey, "pKey #" + count);
t.deepEqual(record.iKey, expected[count].iKey, "iKey #" + count);
t.deepEqual(cursor.key, expected[count].iKey, "cursor.key #" + count);
t.deepEqual(
cursor.primaryKey,
expected[count].pKey,
"cursor.primaryKey #" + count,
);
count++;
cursor.continue(expected[count] ? expected[count].iKey : undefined);
};
};
});
}); });
// IDBCursor.continue() - index - throw TransactionInactiveError // IDBCursor.continue() - index - throw TransactionInactiveError
test.cb("WPT idbcursor-continue-index7.htm", (t) => { test("WPT idbcursor-continue-index7.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
var rq = objStore.index("index").openCursor(); var rq = objStore.index("index").openCursor();
rq.onsuccess = function (event: any) { rq.onsuccess = function (event: any) {
var cursor = event.target.result; var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor); t.true(cursor instanceof BridgeIDBCursor);
event.target.transaction.abort(); event.target.transaction.abort();
t.throws( t.throws(
() => { () => {
cursor.continue(); cursor.continue();
}, },
{ name: "TransactionInactiveError" }, { name: "TransactionInactiveError" },
"Calling continue() should throws an exception TransactionInactiveError when the transaction is not active.", "Calling continue() should throws an exception TransactionInactiveError when the transaction is not active.",
); );
t.end(); resolve();
return;
};
}; };
}; });
}); });
// IDBCursor.continue() - index - throw InvalidStateError caused by object store been deleted // IDBCursor.continue() - index - throw InvalidStateError caused by object store been deleted
test.cb("WPT idbcursor-continue-index8.htm", (t) => { test("WPT idbcursor-continue-index8.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
var rq = objStore.index("index").openCursor(); var rq = objStore.index("index").openCursor();
rq.onsuccess = function (event: any) { rq.onsuccess = function (event: any) {
var cursor = event.target.result; var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor); t.true(cursor instanceof BridgeIDBCursor);
db.deleteObjectStore("store"); db.deleteObjectStore("store");
t.throws( t.throws(
() => { () => {
cursor.continue(); cursor.continue();
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
"If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError",
); );
t.end(); resolve();
};
}; };
}; });
}); });

View File

@ -1,243 +1,264 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { BridgeIDBCursor } from "../bridge-idb.js";
import { BridgeIDBCursorWithValue } from "../bridge-idb"; import { IDBDatabase } from "../idbtypes.js";
import { IDBDatabase } from "../idbtypes"; import { createdb } from "./wptsupport.js";
import { createdb } from "./wptsupport";
// IDBCursor.continue() - object store - iterate to the next record // IDBCursor.continue() - object store - iterate to the next record
test.cb("WPT test idbcursor_continue_objectstore.htm", (t) => { test("WPT test idbcursor_continue_objectstore.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
let count = 0; var db: any;
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; let count = 0;
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { var objStore = db.createObjectStore("test", {
autoIncrement: true, autoIncrement: true,
keyPath: "pKey", keyPath: "pKey",
}); });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var store = db.transaction("test").objectStore("test");
var cursor_rq = store.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, records.length, "cursor run count");
t.end();
}
var record = cursor.value;
t.deepEqual(record.pKey, records[count].pKey, "primary key");
cursor.continue();
count++;
}; };
};
open_rq.onsuccess = function (e: any) {
var store = db.transaction("test").objectStore("test");
var cursor_rq = store.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, records.length, "cursor run count");
resolve();
return;
}
var record = cursor.value;
t.deepEqual(record.pKey, records[count].pKey, "primary key");
cursor.continue();
count++;
};
};
});
}); });
// IDBCursor.continue() - index - attempt to pass a // IDBCursor.continue() - index - attempt to pass a
// key parameter that is not a valid key // key parameter that is not a valid key
test.cb("WPT test idbcursor_continue_objectstore2.htm", (t) => { test("WPT test idbcursor_continue_objectstore2.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; var db: any;
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
t.throws(
() => {
cursor.continue({ foo: "42" });
},
{ name: "DataError" },
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
t.throws(
() => {
cursor.continue({ foo: "42" });
},
{ name: "DataError" },
);
resolve();
};
};
});
}); });
// IDBCursor.continue() - object store - attempt to iterate to the // IDBCursor.continue() - object store - attempt to iterate to the
// previous record when the direction is set for the next record // previous record when the direction is set for the next record
test.cb("WPT test idbcursor_continue_objectstore3.htm", (t) => { test("WPT test idbcursor_continue_objectstore3.htm", (t) => {
var db: IDBDatabase; return new Promise((resolve, reject) => {
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; var db: IDBDatabase;
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.openCursor(undefined, "next");
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
t.throws(
() => {
cursor.continue(records[0].pKey);
},
{
name: "DataError",
},
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.openCursor(undefined, "next");
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
t.throws(
() => {
cursor.continue(records[0].pKey);
},
{
name: "DataError",
},
);
resolve();
};
};
});
}); });
// IDBCursor.continue() - object store - attempt to iterate to the // IDBCursor.continue() - object store - attempt to iterate to the
// next record when the direction is set for the previous record // next record when the direction is set for the previous record
test.cb("WPT test idbcursor_continue_objectstore4.htm", (t) => { test("WPT test idbcursor_continue_objectstore4.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [ var db: any;
{ pKey: "primaryKey_0" }, const records = [
{ pKey: "primaryKey_1" }, { pKey: "primaryKey_0" },
{ pKey: "primaryKey_2" }, { pKey: "primaryKey_1" },
]; { pKey: "primaryKey_2" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.openCursor(null, "prev");
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
switch (count) {
case 0:
t.deepEqual(cursor.value.pKey, records[2].pKey, "first cursor pkey");
cursor.continue(records[1].pKey);
break;
case 1:
t.deepEqual(cursor.value.pKey, records[1].pKey, "second cursor pkey");
t.throws(
() => {
console.log("**** continuing cursor");
cursor.continue(records[2].pKey);
console.log("**** this should not happen");
},
{
name: "DataError",
},
);
t.end();
break;
default:
t.fail("Unexpected count value: " + count);
}
count++;
}; };
};
open_rq.onsuccess = function (e: any) {
var count = 0,
cursor_rq = db
.transaction("test")
.objectStore("test")
.openCursor(null, "prev");
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
switch (count) {
case 0:
t.deepEqual(
cursor.value.pKey,
records[2].pKey,
"first cursor pkey",
);
cursor.continue(records[1].pKey);
break;
case 1:
t.deepEqual(
cursor.value.pKey,
records[1].pKey,
"second cursor pkey",
);
t.throws(
() => {
console.log("**** continuing cursor");
cursor.continue(records[2].pKey);
console.log("**** this should not happen");
},
{
name: "DataError",
},
);
resolve();
return;
default:
t.fail("Unexpected count value: " + count);
}
count++;
};
};
});
}); });
// IDBCursor.continue() - object store - throw TransactionInactiveError // IDBCursor.continue() - object store - throw TransactionInactiveError
test.cb("WPT test idbcursor_continue_objectstore5.htm", (t) => { test("WPT test idbcursor_continue_objectstore5.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; var db: any;
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
e.target.transaction.abort();
t.throws(
() => {
cursor.continue();
},
{
name: "TransactionInactiveError",
},
"Calling continue() should throw an exception TransactionInactiveError when the transaction is not active.",
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
e.target.transaction.abort();
t.throws(
() => {
cursor.continue();
},
{
name: "TransactionInactiveError",
},
"Calling continue() should throw an exception TransactionInactiveError when the transaction is not active.",
);
resolve();
return;
};
};
});
}); });
// IDBCursor.continue() - object store - throw InvalidStateError caused by object store been deleted // IDBCursor.continue() - object store - throw InvalidStateError caused by object store been deleted
test.cb("WPT test idbcursor_continue_objectstore6.htm", (t) => { test("WPT test idbcursor_continue_objectstore6.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; var db: any;
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
var cursor_rq = objStore.openCursor(); var cursor_rq = objStore.openCursor();
cursor_rq.onsuccess = function (e: any) { cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result; var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists"); t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
db.deleteObjectStore("test"); db.deleteObjectStore("test");
t.throws( t.throws(
() => { () => {
cursor.continue(); cursor.continue();
}, },
{ {
name: "InvalidStateError", name: "InvalidStateError",
}, },
"If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError",
); );
t.end(); resolve();
};
}; };
}; });
}); });

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { createdb, indexeddb_test } from "./wptsupport"; import { indexeddb_test } from "./wptsupport.js";
test("WPT idbcursor-delete-exception-order.htm", async (t) => { test("WPT idbcursor-delete-exception-order.htm", async (t) => {
// 'IDBCursor.delete exception order: TransactionInactiveError vs. ReadOnlyError' // 'IDBCursor.delete exception order: TransactionInactiveError vs. ReadOnlyError'

View File

@ -1,204 +1,214 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { BridgeIDBCursor } from "../bridge-idb.js";
import { IDBCursor } from "../idbtypes"; import { IDBCursor } from "../idbtypes.js";
import { createdb, indexeddb_test } from "./wptsupport"; import { createdb } from "./wptsupport.js";
// IDBCursor.delete() - index - remove a record from the object store // IDBCursor.delete() - index - remove a record from the object store
test.cb("WPT idbcursor-delete-index.htm", (t) => { test("WPT idbcursor-delete-index.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
let count = 0, var db: any;
records = [ let count = 0,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = CursorDeleteRecord;
function CursorDeleteRecord(e: any) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").index("index").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
cursor.delete();
}; };
txn.oncomplete = VerifyRecordWasDeleted; open_rq.onsuccess = CursorDeleteRecord;
}
function VerifyRecordWasDeleted(e: any) { function CursorDeleteRecord(e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor(); var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").index("index").openCursor();
cursor_rq.onsuccess = function (e: any) { cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result; var cursor = e.target.result;
if (!cursor) { t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
t.deepEqual(count, 1, "count"); cursor.delete();
t.end(); };
return;
}
t.deepEqual(cursor.value.pKey, records[1].pKey); txn.oncomplete = VerifyRecordWasDeleted;
t.deepEqual(cursor.value.iKey, records[1].iKey); }
cursor.continue();
count++; function VerifyRecordWasDeleted(e: any) {
}; var cursor_rq = db.transaction("test").objectStore("test").openCursor();
}
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, 1, "count");
resolve();
return;
}
t.deepEqual(cursor.value.pKey, records[1].pKey);
t.deepEqual(cursor.value.iKey, records[1].iKey);
cursor.continue();
count++;
};
}
});
}); });
// IDBCursor.delete() - object store - attempt to remove a record in a read-only transaction // IDBCursor.delete() - object store - attempt to remove a record in a read-only transaction
test.cb("WPT idbcursor-delete-index2.htm", (t) => { test("WPT idbcursor-delete-index2.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
t.throws(
() => {
cursor.delete();
},
{
name: "ReadOnlyError",
},
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
t.throws(
() => {
cursor.delete();
},
{
name: "ReadOnlyError",
},
);
resolve();
};
};
});
}); });
// IDBCursor.delete() - index - attempt to remove a record in an inactive transaction // IDBCursor.delete() - index - attempt to remove a record in an inactive transaction
test.cb("WPT idbcursor-delete-index3.htm", (t) => { test("WPT idbcursor-delete-index3.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
var index = objStore.createIndex("index", "iKey"); var index = objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
var cursor_rq = index.openCursor(); var cursor_rq = index.openCursor();
let myCursor: IDBCursor | undefined; let myCursor: IDBCursor | undefined;
cursor_rq.onsuccess = function (e: any) { cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result; var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
myCursor = cursor; myCursor = cursor;
};
e.target.transaction.oncomplete = function (e: any) {
t.throws(
() => {
myCursor!.delete();
},
{ name: "TransactionInactiveError" },
);
resolve();
};
}; };
});
e.target.transaction.oncomplete = function (e: any) {
t.throws(
() => {
myCursor!.delete();
},
{ name: "TransactionInactiveError" },
);
t.end();
};
};
}); });
// IDBCursor.delete() - index - throw InvalidStateError caused by object store been deleted // IDBCursor.delete() - index - throw InvalidStateError caused by object store been deleted
test.cb("WPT idbcursor-delete-index4.htm", (t) => { test("WPT idbcursor-delete-index4.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
var rq = objStore.index("index").openCursor(); var rq = objStore.index("index").openCursor();
rq.onsuccess = function (event: any) { rq.onsuccess = function (event: any) {
var cursor = event.target.result; var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
db.deleteObjectStore("store"); db.deleteObjectStore("store");
t.throws( t.throws(
function () { function () {
cursor.delete(); cursor.delete();
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
"If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError",
); );
t.end(); resolve();
};
}; };
}; });
}); });
// IDBCursor.delete() - index - throw InvalidStateError when the cursor is being iterated // IDBCursor.delete() - index - throw InvalidStateError when the cursor is being iterated
test.cb("WPT idbcursor-delete-index5.htm", (t) => { test("WPT idbcursor-delete-index5.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
var rq = objStore.index("index").openCursor(); var rq = objStore.index("index").openCursor();
rq.onsuccess = function (event: any) { rq.onsuccess = function (event: any) {
var cursor = event.target.result; var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
cursor.continue(); cursor.continue();
t.throws( t.throws(
function () { function () {
cursor.delete(); cursor.delete();
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
); );
t.end(); resolve();
};
}; };
}; });
}); });

View File

@ -1,194 +1,204 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { BridgeIDBCursor } from "../bridge-idb.js";
import { IDBCursor } from "../idbtypes"; import { createdb } from "./wptsupport.js";
import { createdb, indexeddb_test } from "./wptsupport";
// IDBCursor.delete() - object store - remove a record from the object store // IDBCursor.delete() - object store - remove a record from the object store
test.cb("WPT idbcursor-delete-objectstore.htm", (t) => { test("WPT idbcursor-delete-objectstore.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
count = 0, var db: any,
records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; count = 0,
records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = CursorDeleteRecord;
function CursorDeleteRecord(e: any) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
cursor.delete();
}; };
txn.oncomplete = VerifyRecordWasDeleted; open_rq.onsuccess = CursorDeleteRecord;
}
function VerifyRecordWasDeleted(e: any) { function CursorDeleteRecord(e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor(); var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) { cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result; var cursor = e.target.result;
if (!cursor) { t.true(cursor != null, "cursor exist");
t.deepEqual(count, 1, "count"); cursor.delete();
t.end(); };
}
t.deepEqual(cursor.value.pKey, records[1].pKey); txn.oncomplete = VerifyRecordWasDeleted;
count++; }
cursor.continue();
}; function VerifyRecordWasDeleted(e: any) {
} var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (!cursor) {
t.deepEqual(count, 1, "count");
resolve();
return;
}
t.deepEqual(cursor.value.pKey, records[1].pKey);
count++;
cursor.continue();
};
}
});
}); });
// IDBCursor.delete() - object store - attempt to remove a record in a read-only transaction // IDBCursor.delete() - object store - attempt to remove a record in a read-only transaction
test.cb("WPT idbcursor-delete-objectstore2.htm", (t) => { test("WPT idbcursor-delete-objectstore2.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
t.throws(
function () {
cursor.delete();
},
{ name: "ReadOnlyError" },
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor != null, "cursor exist");
t.throws(
function () {
cursor.delete();
},
{ name: "ReadOnlyError" },
);
resolve();
};
};
});
}); });
// IDBCursor.delete() - index - attempt to remove a record in an inactive transaction // IDBCursor.delete() - index - attempt to remove a record in an inactive transaction
test.cb("WPT idbcursor-delete-objectstore3.htm", (t) => { test("WPT idbcursor-delete-objectstore3.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
var cursor_rq = objStore.openCursor(); var cursor_rq = objStore.openCursor();
const window: any = {}; const window: any = {};
cursor_rq.onsuccess = function (e: any) { cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result; var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
window.cursor = cursor; window.cursor = cursor;
};
e.target.transaction.oncomplete = function (e: any) {
t.throws(
function () {
window.cursor.delete();
},
{
name: "TransactionInactiveError",
},
);
resolve();
};
}; };
});
e.target.transaction.oncomplete = function (e: any) {
t.throws(
function () {
window.cursor.delete();
},
{
name: "TransactionInactiveError",
},
);
t.end();
};
};
}); });
// IDBCursor.delete() - object store - throw InvalidStateError caused by object store been deleted // IDBCursor.delete() - object store - throw InvalidStateError caused by object store been deleted
test.cb("WPT idbcursor-delete-objectstore4.htm", (t) => { test("WPT idbcursor-delete-objectstore4.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; var db: any,
records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
var rq = objStore.openCursor(); var rq = objStore.openCursor();
rq.onsuccess = function (event: any) { rq.onsuccess = function (event: any) {
var cursor = event.target.result; var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
db.deleteObjectStore("store"); db.deleteObjectStore("store");
t.throws( t.throws(
function () { function () {
cursor.delete(); cursor.delete();
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
"If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError",
); );
t.end(); resolve();
};
}; };
}; });
}); });
// IDBCursor.delete() - object store - throw InvalidStateError when the cursor is being iterated // IDBCursor.delete() - object store - throw InvalidStateError when the cursor is being iterated
test.cb("WPT idbcursor-delete-objectstore5.htm", (t) => { test("WPT idbcursor-delete-objectstore5.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; var db: any,
records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
};
open_rq.onsuccess = function (event: any) {
var txn = db.transaction("store", "readwrite");
var rq = txn.objectStore("store").openCursor();
rq.onsuccess = function (event: any) {
var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
cursor.continue();
t.throws(
function () {
cursor.delete();
},
{
name: "InvalidStateError",
},
);
t.end();
}; };
};
open_rq.onsuccess = function (event: any) {
var txn = db.transaction("store", "readwrite");
var rq = txn.objectStore("store").openCursor();
rq.onsuccess = function (event: any) {
var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
cursor.continue();
t.throws(
function () {
cursor.delete();
},
{
name: "InvalidStateError",
},
);
resolve();
};
};
});
}); });

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
test("WPT idbcursor-reused.htm", async (t) => { test("WPT idbcursor-reused.htm", async (t) => {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {

View File

@ -1,340 +1,356 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor, BridgeIDBKeyRange } from ".."; import { BridgeIDBCursor, BridgeIDBKeyRange } from "../bridge-idb.js";
import { import {
createDatabase, createDatabase,
createdb, createdb,
promiseForRequest, promiseForRequest,
promiseForTransaction, promiseForTransaction,
} from "./wptsupport"; } from "./wptsupport.js";
// IDBCursor.update() - index - modify a record in the object store // IDBCursor.update() - index - modify a record in the object store
test.cb("WPT test idbcursor_update_index.htm", (t) => { test("WPT test idbcursor_update_index.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
// XXX: Gecko doesn't like this // XXX: Gecko doesn't like this
//e.target.transaction.oncomplete = t.step_func(CursorUpdateRecord); //e.target.transaction.oncomplete = t.step_func(CursorUpdateRecord);
};
open_rq.onsuccess = CursorUpdateRecord;
function CursorUpdateRecord(e: any) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").index("index").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
cursor.value.iKey += "_updated";
cursor.update(cursor.value);
}; };
txn.oncomplete = VerifyRecordWasUpdated; open_rq.onsuccess = CursorUpdateRecord;
}
function VerifyRecordWasUpdated(e: any) { function CursorUpdateRecord(e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor(); var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").index("index").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
cursor_rq.onsuccess = function (e: any) { cursor.value.iKey += "_updated";
var cursor = e.target.result; cursor.update(cursor.value);
};
t.deepEqual(cursor.value.iKey, records[0].iKey + "_updated"); txn.oncomplete = VerifyRecordWasUpdated;
t.end(); }
};
} function VerifyRecordWasUpdated(e: any) {
var cursor_rq = db.transaction("test").objectStore("test").openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.deepEqual(cursor.value.iKey, records[0].iKey + "_updated");
resolve();
};
}
});
}); });
// IDBCursor.update() - index - attempt to modify a record in a read-only transaction // IDBCursor.update() - index - attempt to modify a record in a read-only transaction
test.cb("WPT test idbcursor_update_index2.htm", (t) => { test("WPT test idbcursor_update_index2.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.throws(
function () {
cursor.update(cursor.value);
},
{ name: "ReadOnlyError" },
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.throws(
function () {
cursor.update(cursor.value);
},
{ name: "ReadOnlyError" },
);
resolve();
};
};
});
}); });
//IDBCursor.update() - index - attempt to modify a record in an inactive transaction //IDBCursor.update() - index - attempt to modify a record in an inactive transaction
test.cb("WPT test idbcursor_update_index3.htm", (t) => { test("WPT test idbcursor_update_index3.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
var index = objStore.createIndex("index", "iKey"); var index = objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
var cursor_rq = index.openCursor(); var cursor_rq = index.openCursor();
const window: any = {}; const window: any = {};
cursor_rq.onsuccess = function (e: any) { cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result; var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exist"); t.true(cursor instanceof BridgeIDBCursor, "cursor exist");
window.cursor = cursor; window.cursor = cursor;
window.record = cursor.value; window.record = cursor.value;
};
e.target.transaction.oncomplete = function (e: any) {
t.throws(
function () {
window.cursor.update(window.record);
},
{ name: "TransactionInactiveError" },
);
resolve();
};
}; };
});
e.target.transaction.oncomplete = function (e: any) {
t.throws(
function () {
window.cursor.update(window.record);
},
{ name: "TransactionInactiveError" },
);
t.end();
};
};
}); });
// IDBCursor.update() - index - attempt to modify a record when object store been deleted // IDBCursor.update() - index - attempt to modify a record when object store been deleted
test.cb("WPT test idbcursor_update_index4.htm", (t) => { test("WPT test idbcursor_update_index4.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) { for (var i = 0; i < records.length; i++) {
objStore.add(records[i]); objStore.add(records[i]);
} }
var rq = objStore.index("index").openCursor(); var rq = objStore.index("index").openCursor();
rq.onsuccess = function (event: any) { rq.onsuccess = function (event: any) {
var cursor = event.target.result; var cursor = event.target.result;
t.true(cursor instanceof BridgeIDBCursor); t.true(cursor instanceof BridgeIDBCursor);
db.deleteObjectStore("store"); db.deleteObjectStore("store");
cursor.value.iKey += "_updated"; cursor.value.iKey += "_updated";
t.throws( t.throws(
function () { function () {
cursor.update(cursor.value); cursor.update(cursor.value);
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
"If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError", "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError",
); );
t.end(); resolve();
};
}; };
}; });
}); });
// IDBCursor.update() - index - throw DataCloneError // IDBCursor.update() - index - throw DataCloneError
test.cb("WPT test idbcursor_update_index5.htm", (t) => { test("WPT test idbcursor_update_index5.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor);
var record = cursor.value;
// Original test uses different uncloneable value
record.data = { foo: () => {} };
t.throws(
function () {
cursor.update(record);
},
{ name: "DataCloneError" },
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor);
var record = cursor.value;
// Original test uses different uncloneable value
record.data = { foo: () => {} };
t.throws(
function () {
cursor.update(record);
},
{ name: "DataCloneError" },
);
resolve();
};
};
});
}); });
// IDBCursor.update() - index - no argument // IDBCursor.update() - index - no argument
test.cb("WPT test idbcursor_update_index6.htm", (t) => { test("WPT test idbcursor_update_index6.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor);
t.throws(
function () {
cursor.update();
},
{
instanceOf: TypeError,
},
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor);
t.throws(
function () {
cursor.update();
},
{
instanceOf: TypeError,
},
);
resolve();
};
};
});
}); });
// IDBCursor.update() - index - throw DataError // IDBCursor.update() - index - throw DataError
test.cb("WPT test idbcursor_update_index7.htm", (t) => { test("WPT test idbcursor_update_index7.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor);
t.throws(
function () {
cursor.update(null);
},
{ name: "DataError" },
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor);
t.throws(
function () {
cursor.update(null);
},
{ name: "DataError" },
);
resolve();
};
};
});
}); });
// IDBCursor.update() - index - throw InvalidStateError when the cursor is being iterated // IDBCursor.update() - index - throw InvalidStateError when the cursor is being iterated
test.cb("WPT test idbcursor_update_index8.htm", (t) => { test("WPT test idbcursor_update_index8.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
records = [ var db: any,
{ pKey: "primaryKey_0", iKey: "indexKey_0" }, records = [
{ pKey: "primaryKey_1", iKey: "indexKey_1" }, { pKey: "primaryKey_0", iKey: "indexKey_0" },
]; { pKey: "primaryKey_1", iKey: "indexKey_1" },
];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" }); var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey"); objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) objStore.add(records[i]); for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("store", "readwrite")
.objectStore("store")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
cursor.continue();
t.throws(
function () {
cursor.update({ pKey: "primaryKey_0", iKey: "indexKey_0_updated" });
},
{
name: "InvalidStateError",
},
);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var cursor_rq = db
.transaction("store", "readwrite")
.objectStore("store")
.index("index")
.openCursor();
cursor_rq.onsuccess = function (e: any) {
var cursor = e.target.result;
t.true(cursor instanceof BridgeIDBCursor, "cursor exists");
cursor.continue();
t.throws(
function () {
cursor.update({ pKey: "primaryKey_0", iKey: "indexKey_0_updated" });
},
{
name: "InvalidStateError",
},
);
resolve();
};
};
});
}); });
// Index cursor - indexed values updated during iteration // Index cursor - indexed values updated during iteration

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { createdb, idbFactory } from "./wptsupport"; import { idbFactory } from "./wptsupport.js";
test("WPT idbfactory-cmp*.html", async (t) => { test("WPT idbfactory-cmp*.html", async (t) => {
const indexedDB = idbFactory; const indexedDB = idbFactory;

View File

@ -1,7 +1,7 @@
import test from "ava"; import test from "ava";
import { BridgeIDBVersionChangeEvent } from "../bridge-idb"; import { BridgeIDBVersionChangeEvent } from "../bridge-idb.js";
import FakeEvent from "../util/FakeEvent"; import FakeEvent from "../util/FakeEvent.js";
import { createdb, format_value, idbFactory } from "./wptsupport"; import { createdb, format_value, idbFactory } from "./wptsupport.js";
// IDBFactory.open() - request has no source // IDBFactory.open() - request has no source
test("WPT idbfactory-open.htm", async (t) => { test("WPT idbfactory-open.htm", async (t) => {

View File

@ -1,7 +1,7 @@
import test from "ava"; import test from "ava";
import { BridgeIDBKeyRange, BridgeIDBRequest } from ".."; import { BridgeIDBKeyRange } from "../bridge-idb.js";
import { IDBDatabase } from "../idbtypes"; import { IDBDatabase } from "../idbtypes.js";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
// IDBIndex.get() - returns the record // IDBIndex.get() - returns the record
test("WPT idbindex_get.htm", async (t) => { test("WPT idbindex_get.htm", async (t) => {

View File

@ -1,82 +1,85 @@
import test from "ava"; import test from "ava";
import { BridgeIDBCursor } from ".."; import { createdb } from "./wptsupport.js";
import { BridgeIDBCursorWithValue } from "../bridge-idb";
import { IDBDatabase } from "../idbtypes";
import { createdb } from "./wptsupport";
// IDBIndex.openCursor() - throw InvalidStateError when the index is deleted // IDBIndex.openCursor() - throw InvalidStateError when the index is deleted
test.cb("WPT test idbindex-openCursor.htm", (t) => { test("WPT test idbindex-openCursor.htm", (t) => {
var db; return new Promise((resolve, reject) => {
var db;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var store = db.createObjectStore("store", { keyPath: "key" }); var store = db.createObjectStore("store", { keyPath: "key" });
var index = store.createIndex("index", "indexedProperty"); var index = store.createIndex("index", "indexedProperty");
store.add({ key: 1, indexedProperty: "data" }); store.add({ key: 1, indexedProperty: "data" });
store.deleteIndex("index"); store.deleteIndex("index");
t.throws( t.throws(
() => { () => {
index.openCursor(); index.openCursor();
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
); );
t.end(); resolve();
}; };
});
}); });
// IDBIndex.openCursor() - throw TransactionInactiveError on aborted transaction // IDBIndex.openCursor() - throw TransactionInactiveError on aborted transaction
test.cb("WPT test idbindex-openCursor2.htm", (t) => { test("WPT test idbindex-openCursor2.htm", (t) => {
var db; return new Promise((resolve, reject) => {
var db;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var store = db.createObjectStore("store", { keyPath: "key" }); var store = db.createObjectStore("store", { keyPath: "key" });
var index = store.createIndex("index", "indexedProperty"); var index = store.createIndex("index", "indexedProperty");
store.add({ key: 1, indexedProperty: "data" }); store.add({ key: 1, indexedProperty: "data" });
}; };
open_rq.onsuccess = function (e: any) { open_rq.onsuccess = function (e: any) {
db = e.target.result; db = e.target.result;
var tx = db.transaction("store"); var tx = db.transaction("store");
var index = tx.objectStore("store").index("index"); var index = tx.objectStore("store").index("index");
tx.abort(); tx.abort();
t.throws( t.throws(
() => { () => {
index.openCursor(); index.openCursor();
}, },
{ name: "TransactionInactiveError" }, { name: "TransactionInactiveError" },
); );
t.end(); resolve();
}; };
});
}); });
// IDBIndex.openCursor() - throw InvalidStateError on index deleted by aborted upgrade // IDBIndex.openCursor() - throw InvalidStateError on index deleted by aborted upgrade
test.cb("WPT test idbindex-openCursor3.htm", (t) => { test("WPT test idbindex-openCursor3.htm", (t) => {
var db; return new Promise((resolve, reject) => {
var db;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var store = db.createObjectStore("store", { keyPath: "key" }); var store = db.createObjectStore("store", { keyPath: "key" });
var index = store.createIndex("index", "indexedProperty"); var index = store.createIndex("index", "indexedProperty");
store.add({ key: 1, indexedProperty: "data" }); store.add({ key: 1, indexedProperty: "data" });
e.target.transaction.abort(); e.target.transaction.abort();
t.throws( t.throws(
() => { () => {
console.log("index before openCursor", index); console.log("index before openCursor", index);
index.openCursor(); index.openCursor();
}, },
{ name: "InvalidStateError" }, { name: "InvalidStateError" },
); );
t.end(); resolve();
}; };
});
}); });

View File

@ -1,8 +1,5 @@
import test, { ExecutionContext } from "ava"; import test, { ExecutionContext } from "ava";
import { BridgeIDBCursor } from ".."; import { indexeddb_test } from "./wptsupport.js";
import { BridgeIDBRequest } from "../bridge-idb";
import { InvalidStateError } from "../util/errors";
import { createdb, indexeddb_test } from "./wptsupport";
async function t1(t: ExecutionContext, method: string): Promise<void> { async function t1(t: ExecutionContext, method: string): Promise<void> {
await indexeddb_test( await indexeddb_test(

View File

@ -1,7 +1,7 @@
import test from "ava"; import test from "ava";
import { BridgeIDBRequest } from ".."; import { BridgeIDBRequest } from "../bridge-idb.js";
import { IDBDatabase } from "../idbtypes"; import { IDBDatabase } from "../idbtypes.js";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
// IDBObjectStore.add() - add with an inline key // IDBObjectStore.add() - add with an inline key
test("WPT idbobjectstore_add.htm", async (t) => { test("WPT idbobjectstore_add.htm", async (t) => {

View File

@ -1,159 +1,172 @@
import test from "ava"; import test from "ava";
import { BridgeIDBKeyRange, BridgeIDBRequest } from ".."; import { BridgeIDBKeyRange } from "../bridge-idb.js";
import { IDBDatabase } from "../idbtypes"; import { createdb } from "./wptsupport.js";
import { createdb } from "./wptsupport";
// IDBObjectStore.get() - key is a number // IDBObjectStore.get() - key is a number
test.cb("WPT idbobjectstore_get.htm", (t) => { test("WPT idbobjectstore_get.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { key: 3.14159265, property: "data" }; var db: any,
record = { key: 3.14159265, property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
db.createObjectStore("store", { keyPath: "key" }).add(record); db.createObjectStore("store", { keyPath: "key" }).add(record);
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.key, record.key);
t.deepEqual(e.target.result.property, record.property);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.key, record.key);
t.deepEqual(e.target.result.property, record.property);
resolve();
};
};
});
}); });
// IDBObjectStore.get() - key is a string // IDBObjectStore.get() - key is a string
test.cb("WPT idbobjectstore_get2.htm", (t) => { test("WPT idbobjectstore_get2.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { key: "this is a key that's a string", property: "data" }; var db: any,
record = { key: "this is a key that's a string", property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
db.createObjectStore("store", { keyPath: "key" }).add(record); db.createObjectStore("store", { keyPath: "key" }).add(record);
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.key, record.key);
t.deepEqual(e.target.result.property, record.property);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.key, record.key);
t.deepEqual(e.target.result.property, record.property);
resolve();
};
};
});
}); });
// IDBObjectStore.get() - key is a date // IDBObjectStore.get() - key is a date
test.cb("WPT idbobjectstore_get3.htm", (t) => { test("WPT idbobjectstore_get3.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
const record = { key: new Date(), property: "data" }; var db: any;
const record = { key: new Date(), property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
db.createObjectStore("store", { keyPath: "key" }).add(record); db.createObjectStore("store", { keyPath: "key" }).add(record);
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.key.valueOf(), record.key.valueOf());
t.deepEqual(e.target.result.property, record.property);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.key.valueOf(), record.key.valueOf());
t.deepEqual(e.target.result.property, record.property);
resolve();
};
};
});
}); });
// IDBObjectStore.get() - attempt to retrieve a record that doesn't exist // IDBObjectStore.get() - attempt to retrieve a record that doesn't exist
test.cb("WPT idbobjectstore_get4.htm", (t) => { test("WPT idbobjectstore_get4.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
var db: any;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var rq = db.createObjectStore("store", { keyPath: "key" }).get(1); var rq = db.createObjectStore("store", { keyPath: "key" }).get(1);
rq.onsuccess = function (e: any) { rq.onsuccess = function (e: any) {
t.deepEqual(e.target.results, undefined); t.deepEqual(e.target.results, undefined);
setTimeout(function () { setTimeout(function () {
t.end(); resolve();
}, 10); }, 10);
};
}; };
};
open_rq.onsuccess = function () {}; open_rq.onsuccess = function () {};
});
}); });
// IDBObjectStore.get() - returns the record with the first key in the range // IDBObjectStore.get() - returns the record with the first key in the range
test.cb("WPT idbobjectstore_get5.htm", (t) => { test("WPT idbobjectstore_get5.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
var open_rq = createdb(t); var db: any;
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var os = db.createObjectStore("store"); var os = db.createObjectStore("store");
for (var i = 0; i < 10; i++) os.add("data" + i, i); for (var i = 0; i < 10; i++) os.add("data" + i, i);
};
open_rq.onsuccess = function (e: any) {
db
.transaction("store")
.objectStore("store")
.get(BridgeIDBKeyRange.bound(3, 6)).onsuccess = function (e: any) {
t.deepEqual(e.target.result, "data3", "get(3-6)");
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
db
.transaction("store")
.objectStore("store")
.get(BridgeIDBKeyRange.bound(3, 6)).onsuccess = function (e: any) {
t.deepEqual(e.target.result, "data3", "get(3-6)");
resolve();
};
};
});
}); });
// IDBObjectStore.get() - throw TransactionInactiveError on aborted transaction // IDBObjectStore.get() - throw TransactionInactiveError on aborted transaction
test.cb("WPT idbobjectstore_get6.htm", (t) => { test("WPT idbobjectstore_get6.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
var db: any;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
db.createObjectStore("store", { keyPath: "key" }); db.createObjectStore("store", { keyPath: "key" });
}; };
open_rq.onsuccess = function (e: any) { open_rq.onsuccess = function (e: any) {
var store = db.transaction("store").objectStore("store"); var store = db.transaction("store").objectStore("store");
store.transaction.abort(); store.transaction.abort();
t.throws( t.throws(
function () { function () {
store.get(1); store.get(1);
}, },
{ name: "TransactionInactiveError" }, { name: "TransactionInactiveError" },
"throw TransactionInactiveError on aborted transaction.", "throw TransactionInactiveError on aborted transaction.",
); );
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.get() - throw DataError when using invalid key // IDBObjectStore.get() - throw DataError when using invalid key
test.cb("WPT idbobjectstore_get7.htm", (t) => { test("WPT idbobjectstore_get7.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
var db: any;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
db.createObjectStore("store", { keyPath: "key" }); db.createObjectStore("store", { keyPath: "key" });
}; };
open_rq.onsuccess = function (e: any) { open_rq.onsuccess = function (e: any) {
var store = db.transaction("store").objectStore("store"); var store = db.transaction("store").objectStore("store");
t.throws( t.throws(
function () { function () {
store.get(null); store.get(null);
}, },
{ name: "DataError" }, { name: "DataError" },
"throw DataError when using invalid key.", "throw DataError when using invalid key.",
); );
t.end(); resolve();
}; };
});
}); });

View File

@ -1,449 +1,483 @@
import test from "ava"; import test from "ava";
import { BridgeIDBKeyRange, BridgeIDBRequest } from ".."; import { BridgeIDBRequest } from "../bridge-idb.js";
import { IDBDatabase } from "../idbtypes"; import { createdb } from "./wptsupport.js";
import { createdb } from "./wptsupport";
// IDBObjectStore.put() - put with an inline key // IDBObjectStore.put() - put with an inline key
test.cb("WPT idbobjectstore_put.htm", (t) => { test("WPT idbobjectstore_put.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { key: 1, property: "data" }; var db: any,
record = { key: 1, property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { keyPath: "key" }); var objStore = db.createObjectStore("store", { keyPath: "key" });
objStore.put(record); objStore.put(record);
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.property, record.property);
t.deepEqual(e.target.result.key, record.key);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(record.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.property, record.property);
t.deepEqual(e.target.result.key, record.key);
resolve();
};
};
});
}); });
// IDBObjectStore.put() - put with an out-of-line key // IDBObjectStore.put() - put with an out-of-line key
test.cb("WPT idbobjectstore_put2.htm", (t) => { test("WPT idbobjectstore_put2.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
key = 1, var db: any,
record = { property: "data" }; key = 1,
record = { property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store"); var objStore = db.createObjectStore("store");
objStore.put(record, key); objStore.put(record, key);
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.property, record.property);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var rq = db.transaction("store").objectStore("store").get(key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.property, record.property);
resolve();
};
};
});
}); });
// IDBObjectStore.put() - put with an out-of-line key // IDBObjectStore.put() - put with an out-of-line key
test.cb("WPT idbobjectstore_put3.htm", (t) => { test("WPT idbobjectstore_put3.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
success_event: any, var db: any,
record = { key: 1, property: "data" }, success_event: any,
record_put = { key: 1, property: "changed", more: ["stuff", 2] }; record = { key: 1, property: "data" },
record_put = { key: 1, property: "changed", more: ["stuff", 2] };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { keyPath: "key" }); var objStore = db.createObjectStore("store", { keyPath: "key" });
objStore.put(record); objStore.put(record);
var rq = objStore.put(record_put); var rq = objStore.put(record_put);
rq.onerror = () => t.fail("error on put"); rq.onerror = () => t.fail("error on put");
rq.onsuccess = function (e: any) { rq.onsuccess = function (e: any) {
success_event = true; success_event = true;
};
}; };
};
open_rq.onsuccess = function (e: any) { open_rq.onsuccess = function (e: any) {
t.true(success_event); t.true(success_event);
var rq = db.transaction("store").objectStore("store").get(1); var rq = db.transaction("store").objectStore("store").get(1);
rq.onsuccess = function (e: any) { rq.onsuccess = function (e: any) {
var rec = e.target.result; var rec = e.target.result;
t.deepEqual(rec.key, record_put.key); t.deepEqual(rec.key, record_put.key);
t.deepEqual(rec.property, record_put.property); t.deepEqual(rec.property, record_put.property);
t.deepEqual(rec.more, record_put.more); t.deepEqual(rec.more, record_put.more);
t.end(); resolve();
};
}; };
}; });
}); });
// IDBObjectStore.put() - put where an index has unique:true specified // IDBObjectStore.put() - put where an index has unique:true specified
test.cb("WPT idbobjectstore_put4.htm", (t) => { test("WPT idbobjectstore_put4.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { key: 1, property: "data" }; var db: any,
record = { key: 1, property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { autoIncrement: true }); var objStore = db.createObjectStore("store", { autoIncrement: true });
objStore.createIndex("i1", "property", { unique: true }); objStore.createIndex("i1", "property", { unique: true });
objStore.put(record); objStore.put(record);
var rq = objStore.put(record); var rq = objStore.put(record);
rq.onsuccess = () => t.fail("success on putting duplicate indexed record"); rq.onsuccess = () =>
t.fail("success on putting duplicate indexed record");
rq.onerror = function (e: any) { rq.onerror = function (e: any) {
t.deepEqual(rq.error.name, "ConstraintError"); t.deepEqual(rq.error.name, "ConstraintError");
t.deepEqual(e.target.error.name, "ConstraintError"); t.deepEqual(e.target.error.name, "ConstraintError");
t.deepEqual(e.type, "error"); t.deepEqual(e.type, "error");
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
};
}; };
};
// Defer done, giving a spurious rq.onsuccess a chance to run // Defer done, giving a spurious rq.onsuccess a chance to run
open_rq.onsuccess = function (e: any) { open_rq.onsuccess = function (e: any) {
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.put() - object store's key path is an object attribute // IDBObjectStore.put() - object store's key path is an object attribute
test.cb("WPT idbobjectstore_put5.htm", (t) => { test("WPT idbobjectstore_put5.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { test: { obj: { key: 1 } }, property: "data" }; var db: any,
record = { test: { obj: { key: 1 } }, property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { keyPath: "test.obj.key" }); var objStore = db.createObjectStore("store", { keyPath: "test.obj.key" });
objStore.put(record); objStore.put(record);
};
open_rq.onsuccess = function (e: any) {
var rq = db
.transaction("store")
.objectStore("store")
.get(record.test.obj.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.property, record.property);
t.end();
}; };
};
open_rq.onsuccess = function (e: any) {
var rq = db
.transaction("store")
.objectStore("store")
.get(record.test.obj.key);
rq.onsuccess = function (e: any) {
t.deepEqual(e.target.result.property, record.property);
resolve();
};
};
});
}); });
// IDBObjectStore.put() - autoIncrement and inline keys // IDBObjectStore.put() - autoIncrement and inline keys
test.cb("WPT idbobjectstore_put6.htm", (t) => { test("WPT idbobjectstore_put6.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { property: "data" }, var db: any,
expected_keys = [1, 2, 3, 4]; record = { property: "data" },
expected_keys = [1, 2, 3, 4];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { var objStore = db.createObjectStore("store", {
keyPath: "key", keyPath: "key",
autoIncrement: true, autoIncrement: true,
}); });
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
};
open_rq.onsuccess = function (e: any) {
var actual_keys: any[] = [],
rq = db.transaction("store").objectStore("store").openCursor();
rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (cursor) {
actual_keys.push(cursor.value.key);
cursor.continue();
} else {
t.deepEqual(actual_keys, expected_keys);
t.end();
}
}; };
};
open_rq.onsuccess = function (e: any) {
var actual_keys: any[] = [],
rq = db.transaction("store").objectStore("store").openCursor();
rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (cursor) {
actual_keys.push(cursor.value.key);
cursor.continue();
} else {
t.deepEqual(actual_keys, expected_keys);
resolve();
return;
}
};
};
});
}); });
// IDBObjectStore.put() - autoIncrement and out-of-line keys // IDBObjectStore.put() - autoIncrement and out-of-line keys
test.cb("WPT idbobjectstore_put7.htm", (t) => { test("WPT idbobjectstore_put7.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { property: "data" }, var db: any,
expected_keys = [1, 2, 3, 4]; record = { property: "data" },
expected_keys = [1, 2, 3, 4];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { autoIncrement: true }); var objStore = db.createObjectStore("store", { autoIncrement: true });
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
};
open_rq.onsuccess = function (e) {
var actual_keys: any[] = [],
rq = db.transaction("store").objectStore("store").openCursor();
rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (cursor) {
actual_keys.push(cursor.key);
cursor.continue();
} else {
t.deepEqual(actual_keys, expected_keys);
t.end();
}
}; };
};
open_rq.onsuccess = function (e) {
var actual_keys: any[] = [],
rq = db.transaction("store").objectStore("store").openCursor();
rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (cursor) {
actual_keys.push(cursor.key);
cursor.continue();
} else {
t.deepEqual(actual_keys, expected_keys);
resolve();
}
};
};
});
}); });
// IDBObjectStore.put() - object store has autoIncrement:true and the key path is an object attribute // IDBObjectStore.put() - object store has autoIncrement:true and the key path is an object attribute
test.cb("WPT idbobjectstore_put8.htm", (t) => { test("WPT idbobjectstore_put8.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { property: "data" }, var db: any,
expected_keys = [1, 2, 3, 4]; record = { property: "data" },
expected_keys = [1, 2, 3, 4];
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var objStore = db.createObjectStore("store", { var objStore = db.createObjectStore("store", {
keyPath: "test.obj.key", keyPath: "test.obj.key",
autoIncrement: true, autoIncrement: true,
}); });
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
objStore.put(record); objStore.put(record);
};
open_rq.onsuccess = function (e: any) {
var actual_keys: any[] = [],
rq = db.transaction("store").objectStore("store").openCursor();
rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (cursor) {
actual_keys.push(cursor.value.test.obj.key);
cursor.continue();
} else {
t.deepEqual(actual_keys, expected_keys);
t.end();
}
}; };
};
open_rq.onsuccess = function (e: any) {
var actual_keys: any[] = [],
rq = db.transaction("store").objectStore("store").openCursor();
rq.onsuccess = function (e: any) {
var cursor = e.target.result;
if (cursor) {
actual_keys.push(cursor.value.test.obj.key);
cursor.continue();
} else {
t.deepEqual(actual_keys, expected_keys);
resolve();
return;
}
};
};
});
}); });
//IDBObjectStore.put() - Attempt to put a record that does not meet the constraints of an object store's inline key requirements //IDBObjectStore.put() - Attempt to put a record that does not meet the constraints of an object store's inline key requirements
test.cb("WPT idbobjectstore_put9.htm", (t) => { test("WPT idbobjectstore_put9.htm", (t) => {
var record = { key: 1, property: "data" }; return new Promise((resolve, reject) => {
var record = { key: 1, property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
var rq, var rq,
db = e.target.result, db = e.target.result,
objStore = db.createObjectStore("store", { keyPath: "key" }); objStore = db.createObjectStore("store", { keyPath: "key" });
t.throws( t.throws(
function () { function () {
rq = objStore.put(record, 1); rq = objStore.put(record, 1);
}, },
{ name: "DataError" }, { name: "DataError" },
); );
t.deepEqual(rq, undefined); t.deepEqual(rq, undefined);
t.end(); resolve();
}; };
});
}); });
//IDBObjectStore.put() - Attempt to call 'put' without an key parameter when the object store uses out-of-line keys //IDBObjectStore.put() - Attempt to call 'put' without an key parameter when the object store uses out-of-line keys
test.cb("WPT idbobjectstore_put10.htm", (t) => { test("WPT idbobjectstore_put10.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { property: "data" }; var db: any,
record = { property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var rq, var rq,
objStore = db.createObjectStore("store", { keyPath: "key" }); objStore = db.createObjectStore("store", { keyPath: "key" });
t.throws( t.throws(
function () { function () {
rq = objStore.put(record); rq = objStore.put(record);
}, },
{ name: "DataError" }, { name: "DataError" },
); );
t.deepEqual(rq, undefined); t.deepEqual(rq, undefined);
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.put() - Attempt to put a record where the record's key does not meet the constraints of a valid key // IDBObjectStore.put() - Attempt to put a record where the record's key does not meet the constraints of a valid key
test.cb("WPT idbobjectstore_put11.htm", (t) => { test("WPT idbobjectstore_put11.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { key: { value: 1 }, property: "data" }; var db: any,
record = { key: { value: 1 }, property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var rq, var rq,
objStore = db.createObjectStore("store", { keyPath: "key" }); objStore = db.createObjectStore("store", { keyPath: "key" });
t.throws( t.throws(
function () { function () {
rq = objStore.put(record); rq = objStore.put(record);
}, },
{ name: "DataError" }, { name: "DataError" },
); );
t.deepEqual(rq, undefined); t.deepEqual(rq, undefined);
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.put() - Attempt to put a record where the record's in-line key is not defined // IDBObjectStore.put() - Attempt to put a record where the record's in-line key is not defined
test.cb("WPT idbobjectstore_put12.htm", (t) => { test("WPT idbobjectstore_put12.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { property: "data" }; var db: any,
record = { property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var rq, var rq,
objStore = db.createObjectStore("store", { keyPath: "key" }); objStore = db.createObjectStore("store", { keyPath: "key" });
t.throws( t.throws(
function () { function () {
rq = objStore.put(record); rq = objStore.put(record);
}, },
{ name: "DataError" }, { name: "DataError" },
); );
t.deepEqual(rq, undefined); t.deepEqual(rq, undefined);
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.put() - Attempt to put a record where the out of line key provided does not meet the constraints of a valid key // IDBObjectStore.put() - Attempt to put a record where the out of line key provided does not meet the constraints of a valid key
test.cb("WPT idbobjectstore_put13.htm", (t) => { test("WPT idbobjectstore_put13.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { property: "data" }; var db: any,
record = { property: "data" };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var rq, var rq,
objStore = db.createObjectStore("store"); objStore = db.createObjectStore("store");
t.throws( t.throws(
function () { function () {
rq = objStore.put(record, { value: 1 }); rq = objStore.put(record, { value: 1 });
}, },
{ {
name: "DataError", name: "DataError",
}, },
); );
t.deepEqual(rq, undefined); t.deepEqual(rq, undefined);
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.put() - Put a record where a value being indexed does not meet the constraints of a valid key // IDBObjectStore.put() - Put a record where a value being indexed does not meet the constraints of a valid key
test.cb("WPT idbobjectstore_put14.htm", (t) => { test("WPT idbobjectstore_put14.htm", (t) => {
var db: any, return new Promise((resolve, reject) => {
record = { key: 1, indexedProperty: { property: "data" } }; var db: any,
record = { key: 1, indexedProperty: { property: "data" } };
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (e: any) { open_rq.onupgradeneeded = function (e: any) {
db = e.target.result; db = e.target.result;
var rq, var rq,
objStore = db.createObjectStore("store", { keyPath: "key" }); objStore = db.createObjectStore("store", { keyPath: "key" });
objStore.createIndex("index", "indexedProperty"); objStore.createIndex("index", "indexedProperty");
rq = objStore.put(record); rq = objStore.put(record);
t.true(rq instanceof BridgeIDBRequest); t.true(rq instanceof BridgeIDBRequest);
rq.onsuccess = function () { rq.onsuccess = function () {
t.end(); resolve();
};
}; };
}; });
}); });
// IDBObjectStore.put() - If the transaction this IDBObjectStore belongs to has its mode set to readonly, throw ReadOnlyError // IDBObjectStore.put() - If the transaction this IDBObjectStore belongs to has its mode set to readonly, throw ReadOnlyError
test.cb("WPT idbobjectstore_put15.htm", (t) => { test("WPT idbobjectstore_put15.htm", (t) => {
var db: any; return new Promise((resolve, reject) => {
var db: any;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
db.createObjectStore("store", { keyPath: "pKey" }); db.createObjectStore("store", { keyPath: "pKey" });
}; };
open_rq.onsuccess = function (event: any) { open_rq.onsuccess = function (event: any) {
var txn = db.transaction("store"); var txn = db.transaction("store");
var ostore = txn.objectStore("store"); var ostore = txn.objectStore("store");
t.throws( t.throws(
function () { function () {
ostore.put({ pKey: "primaryKey_0" }); ostore.put({ pKey: "primaryKey_0" });
}, },
{ {
name: "ReadOnlyError", name: "ReadOnlyError",
}, },
); );
t.end(); resolve();
}; };
});
}); });
// IDBObjectStore.put() - If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError // IDBObjectStore.put() - If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError
test.cb("WPT idbobjectstore_put16.htm", (t) => { test("WPT idbobjectstore_put16.htm", (t) => {
var db: any, ostore: any; return new Promise((resolve, reject) => {
var db: any, ostore: any;
var open_rq = createdb(t); var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event: any) { open_rq.onupgradeneeded = function (event: any) {
db = event.target.result; db = event.target.result;
ostore = db.createObjectStore("store", { keyPath: "pKey" }); ostore = db.createObjectStore("store", { keyPath: "pKey" });
db.deleteObjectStore("store"); db.deleteObjectStore("store");
t.throws( t.throws(
function () { function () {
ostore.put({ pKey: "primaryKey_0" }); ostore.put({ pKey: "primaryKey_0" });
}, },
{ {
name: "InvalidStateError", name: "InvalidStateError",
}, },
); );
t.end(); resolve();
}; };
});
}); });

View File

@ -7,7 +7,7 @@ import {
createDatabase, createDatabase,
createNotBooksStore, createNotBooksStore,
migrateDatabase, migrateDatabase,
} from "./wptsupport"; } from "./wptsupport.js";
// IndexedDB: object store renaming support // IndexedDB: object store renaming support
// IndexedDB object store rename in new transaction // IndexedDB object store rename in new transaction

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
// IDBTransaction - complete event // IDBTransaction - complete event
test("WPT idbtransaction-oncomplete.htm", async (t) => { test("WPT idbtransaction-oncomplete.htm", async (t) => {

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { assert_key_equals, createdb } from "./wptsupport"; import { assert_key_equals, createdb } from "./wptsupport.js";
test("WPT test keypath.htm", async (t) => { test("WPT test keypath.htm", async (t) => {
function keypath( function keypath(

View File

@ -1,7 +1,6 @@
import test from "ava"; import test from "ava";
import { BridgeIDBRequest } from ".."; import { EventTarget } from "../idbtypes.js";
import { EventTarget, IDBDatabase } from "../idbtypes"; import { createdb } from "./wptsupport.js";
import { createdb } from "./wptsupport";
// Bubbling and capturing of request events // Bubbling and capturing of request events
test("WPT request_bubble-and-capture.htm", async (t) => { test("WPT request_bubble-and-capture.htm", async (t) => {

View File

@ -1,5 +1,5 @@
import test from "ava"; import test from "ava";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
// Transactions have a request queue // Transactions have a request queue
test("transaction-requestqueue.htm", async (t) => { test("transaction-requestqueue.htm", async (t) => {
@ -72,7 +72,7 @@ test("transaction-requestqueue.htm", async (t) => {
"os2: 1", "os2: 1",
"os2: 1", "os2: 1",
"os1: 2", "os1: 2",
], ] as any,
"transaction keys", "transaction keys",
); );
@ -93,7 +93,7 @@ test("transaction-requestqueue.htm", async (t) => {
"os3: 1", "os3: 1",
"os1: 2", "os1: 2",
"os4: 5", "os4: 5",
], ] as any,
"transaction 2 keys", "transaction 2 keys",
); );

View File

@ -1,47 +1,51 @@
import test from "ava"; import test from "ava";
import { IDBVersionChangeEvent } from "../idbtypes"; import { IDBVersionChangeEvent } from "../idbtypes.js";
import { createdb } from "./wptsupport"; import { createdb } from "./wptsupport.js";
test.cb("WPT test value.htm, array", (t) => { test("WPT test value.htm, array", (t) => {
const value = new Array(); return new Promise((resolve, reject) => {
const _instanceof = Array; const value = new Array();
const _instanceof = Array;
t.plan(1); t.plan(1);
createdb(t).onupgradeneeded = function (e: IDBVersionChangeEvent) { createdb(t).onupgradeneeded = function (e: IDBVersionChangeEvent) {
(e.target as any).result.createObjectStore("store").add(value, 1); (e.target as any).result.createObjectStore("store").add(value, 1);
(e.target as any).onsuccess = (e: any) => { (e.target as any).onsuccess = (e: any) => {
console.log("in first onsuccess"); console.log("in first onsuccess");
e.target.result e.target.result
.transaction("store") .transaction("store")
.objectStore("store") .objectStore("store")
.get(1).onsuccess = (e: any) => { .get(1).onsuccess = (e: any) => {
t.assert(e.target.result instanceof _instanceof, "instanceof"); t.assert(e.target.result instanceof _instanceof, "instanceof");
t.end(); resolve();
};
}; };
}; };
}; });
}); });
test.cb("WPT test value.htm, date", (t) => { test("WPT test value.htm, date", (t) => {
const value = new Date(); return new Promise((resolve, reject) => {
const _instanceof = Date; const value = new Date();
const _instanceof = Date;
t.plan(1); t.plan(1);
createdb(t).onupgradeneeded = function (e: IDBVersionChangeEvent) { createdb(t).onupgradeneeded = function (e: IDBVersionChangeEvent) {
(e.target as any).result.createObjectStore("store").add(value, 1); (e.target as any).result.createObjectStore("store").add(value, 1);
(e.target as any).onsuccess = (e: any) => { (e.target as any).onsuccess = (e: any) => {
console.log("in first onsuccess"); console.log("in first onsuccess");
e.target.result e.target.result
.transaction("store") .transaction("store")
.objectStore("store") .objectStore("store")
.get(1).onsuccess = (e: any) => { .get(1).onsuccess = (e: any) => {
console.log("target", e.target); console.log("target", e.target);
console.log("result", e.target.result); console.log("result", e.target.result);
t.assert(e.target.result instanceof _instanceof, "instanceof"); t.assert(e.target.result instanceof _instanceof, "instanceof");
t.end(); resolve();
};
}; };
}; };
}; });
}); });

View File

@ -1,5 +1,5 @@
import test, { ExecutionContext } from "ava"; import { ExecutionContext } from "ava";
import { BridgeIDBFactory, BridgeIDBRequest } from ".."; import { BridgeIDBFactory, BridgeIDBRequest } from "../bridge-idb.js";
import { import {
IDBDatabase, IDBDatabase,
IDBIndex, IDBIndex,
@ -7,10 +7,9 @@ import {
IDBOpenDBRequest, IDBOpenDBRequest,
IDBRequest, IDBRequest,
IDBTransaction, IDBTransaction,
IDBTransactionMode, } from "../idbtypes.js";
} from "../idbtypes"; import { MemoryBackend } from "../MemoryBackend.js";
import { MemoryBackend } from "../MemoryBackend"; import { compareKeys } from "../util/cmp.js";
import { compareKeys } from "../util/cmp";
BridgeIDBFactory.enableTracing = true; BridgeIDBFactory.enableTracing = true;
const backend = new MemoryBackend(); const backend = new MemoryBackend();

View File

@ -14,8 +14,8 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import FakeEventTarget from "./FakeEventTarget"; import FakeEventTarget from "./FakeEventTarget.js";
import { Event, EventTarget } from "../idbtypes"; import { Event, EventTarget } from "../idbtypes.js";
/** @public */ /** @public */
export type EventType = export type EventType =

View File

@ -14,8 +14,8 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { InvalidStateError } from "./errors"; import { InvalidStateError } from "./errors.js";
import FakeEvent, { EventType } from "./FakeEvent"; import FakeEvent, { EventType } from "./FakeEvent.js";
import { import {
EventTarget, EventTarget,
Event, Event,

View File

@ -16,7 +16,7 @@
*/ */
import test from "ava"; import test from "ava";
import { canInjectKey } from "./canInjectKey"; import { canInjectKey } from "./canInjectKey.js";
test("canInjectKey", (t) => { test("canInjectKey", (t) => {
t.false(canInjectKey("foo", null)); t.false(canInjectKey("foo", null));

View File

@ -15,7 +15,7 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { IDBKeyPath } from "../idbtypes"; import { IDBKeyPath } from "../idbtypes.js";
/** /**
* Check that a key could be injected into a value. * Check that a key could be injected into a value.

View File

@ -14,8 +14,8 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { DataError } from "./errors"; import { DataError } from "./errors.js";
import { valueToKey } from "./valueToKey"; import { valueToKey } from "./valueToKey.js";
const getType = (x: any) => { const getType = (x: any) => {
if (typeof x === "number") { if (typeof x === "number") {

View File

@ -15,8 +15,8 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { IDBKeyPath, IDBValidKey } from "../idbtypes"; import { IDBKeyPath, IDBValidKey } from "../idbtypes.js";
import { valueToKey } from "./valueToKey"; import { valueToKey } from "./valueToKey.js";
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-extracting-a-key-from-a-value-using-a-key-path // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-extracting-a-key-from-a-value-using-a-key-path
export const extractKey = (keyPath: IDBKeyPath | IDBKeyPath[], value: any) => { export const extractKey = (keyPath: IDBKeyPath | IDBKeyPath[], value: any) => {

View File

@ -14,7 +14,6 @@
* permissions and limitations under the License. * permissions and limitations under the License.
*/ */
import { DOMStringList } from "../idbtypes";
/** @public */ /** @public */
export interface FakeDOMStringList extends Array<string> { export interface FakeDOMStringList extends Array<string> {

View File

@ -16,7 +16,7 @@
*/ */
import test from "ava"; import test from "ava";
import { getIndexKeys } from "./getIndexKeys"; import { getIndexKeys } from "./getIndexKeys.js";
test("basics", (t) => { test("basics", (t) => {
t.deepEqual(getIndexKeys({ foo: 42 }, "foo", false), [42]); t.deepEqual(getIndexKeys({ foo: 42 }, "foo", false), [42]);
@ -31,10 +31,10 @@ test("basics", (t) => {
}); });
t.deepEqual(getIndexKeys({ foo: 42 }, "foo", true), [42]); t.deepEqual(getIndexKeys({ foo: 42 }, "foo", true), [42]);
t.deepEqual(getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar"], true), [ t.deepEqual(
42, getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar"], true),
10, [42, 10],
]); );
t.deepEqual(getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar"], false), [ t.deepEqual(getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar"], false), [
[42, 10], [42, 10],
]); ]);

View File

@ -15,9 +15,9 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { IDBKeyPath, IDBValidKey } from "../idbtypes"; import { IDBKeyPath, IDBValidKey } from "../idbtypes.js";
import { extractKey } from "./extractKey"; import { extractKey } from "./extractKey.js";
import { valueToKey } from "./valueToKey"; import { valueToKey } from "./valueToKey.js";
export function getIndexKeys( export function getIndexKeys(
value: any, value: any,

View File

@ -15,7 +15,7 @@
*/ */
import test from "ava"; import test from "ava";
import { makeStoreKeyValue } from "./makeStoreKeyValue"; import { makeStoreKeyValue } from "./makeStoreKeyValue.js";
test("basics", (t) => { test("basics", (t) => {
let result; let result;

View File

@ -14,11 +14,11 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { extractKey } from "./extractKey"; import { extractKey } from "./extractKey.js";
import { DataCloneError, DataError } from "./errors"; import { DataCloneError, DataError } from "./errors.js";
import { valueToKey } from "./valueToKey"; import { valueToKey } from "./valueToKey.js";
import { structuredClone } from "./structuredClone"; import { structuredClone } from "./structuredClone.js";
import { IDBKeyPath, IDBValidKey } from "../idbtypes"; import { IDBKeyPath, IDBValidKey } from "../idbtypes.js";
export interface StoreKeyResult { export interface StoreKeyResult {
updatedKeyGenerator: number; updatedKeyGenerator: number;

View File

@ -15,7 +15,7 @@
*/ */
import test, { ExecutionContext } from "ava"; import test, { ExecutionContext } from "ava";
import { structuredClone } from "./structuredClone"; import { structuredClone } from "./structuredClone.js";
function checkClone(t: ExecutionContext, x: any): void { function checkClone(t: ExecutionContext, x: any): void {
t.deepEqual(structuredClone(x), x); t.deepEqual(structuredClone(x), x);

View File

@ -14,7 +14,7 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { IDBKeyPath } from "../idbtypes"; import { IDBKeyPath } from "../idbtypes.js";
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-valid-key-path // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-valid-key-path
export const validateKeyPath = ( export const validateKeyPath = (

View File

@ -14,8 +14,8 @@
permissions and limitations under the License. permissions and limitations under the License.
*/ */
import { IDBValidKey } from ".."; import { IDBValidKey } from "../idbtypes.js";
import { DataError } from "./errors"; import { DataError } from "./errors.js";
// https://www.w3.org/TR/IndexedDB-2/#convert-a-value-to-a-key // https://www.w3.org/TR/IndexedDB-2/#convert-a-value-to-a-key
export function valueToKey( export function valueToKey(

View File

@ -125,27 +125,27 @@ importers:
'@rollup/plugin-commonjs': ^21.0.1 '@rollup/plugin-commonjs': ^21.0.1
'@rollup/plugin-json': ^4.1.0 '@rollup/plugin-json': ^4.1.0
'@rollup/plugin-node-resolve': ^13.1.3 '@rollup/plugin-node-resolve': ^13.1.3
'@types/node': ^17.0.8 '@types/node': ^17.0.17
ava: ^3.15.0 ava: ^4.0.1
esm: ^3.2.25 esm: ^3.2.25
prettier: ^2.2.1 prettier: ^2.5.1
rimraf: ^3.0.2 rimraf: ^3.0.2
rollup: ^2.63.0 rollup: ^2.67.2
tslib: ^2.3.1 tslib: ^2.3.1
typescript: ^4.5.4 typescript: ^4.5.5
dependencies: dependencies:
tslib: 2.3.1 tslib: 2.3.1
devDependencies: devDependencies:
'@rollup/plugin-commonjs': 21.0.1_rollup@2.63.0 '@rollup/plugin-commonjs': 21.0.1_rollup@2.67.2
'@rollup/plugin-json': 4.1.0_rollup@2.63.0 '@rollup/plugin-json': 4.1.0_rollup@2.67.2
'@rollup/plugin-node-resolve': 13.1.3_rollup@2.63.0 '@rollup/plugin-node-resolve': 13.1.3_rollup@2.67.2
'@types/node': 17.0.8 '@types/node': 17.0.17
ava: 3.15.0 ava: 4.0.1
esm: 3.2.25 esm: 3.2.25
prettier: 2.2.1 prettier: 2.5.1
rimraf: 3.0.2 rimraf: 3.0.2
rollup: 2.63.0 rollup: 2.67.2
typescript: 4.5.4 typescript: 4.5.5
packages/pogen: packages/pogen:
specifiers: specifiers:
@ -10125,7 +10125,6 @@ packages:
/@types/node/17.0.17: /@types/node/17.0.17:
resolution: {integrity: sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw==} resolution: {integrity: sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw==}
dev: false
/@types/node/17.0.8: /@types/node/17.0.8:
resolution: {integrity: sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==} resolution: {integrity: sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==}
@ -10189,7 +10188,7 @@ packages:
/@types/resolve/1.17.1: /@types/resolve/1.17.1:
resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==}
dependencies: dependencies:
'@types/node': 17.0.8 '@types/node': 17.0.17
dev: true dev: true
/@types/scheduler/0.16.2: /@types/scheduler/0.16.2: