Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Magic.IndexedDb.Cli/Magic.IndexedDb.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>magicdb</ToolCommandName>
<PackageId>Magic.IndexedDb.Cli</PackageId>
<Version>4.1.0</Version>
<Version>4.1.1</Version>
<Authors>Magic Man</Authors>
<Description>Code-first, language-independent migration planning, validation, and static publishing for Magic IndexedDB.</Description>
<PackageProjectUrl>https://github.com/magiccodingman/Magic.IndexedDb</PackageProjectUrl>
Expand Down
4 changes: 2 additions & 2 deletions Magic.IndexedDb/Magic.IndexedDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<FileVersion>4.1.0.0</FileVersion>
<Version>4.1.0</Version>
<FileVersion>4.1.1.0</FileVersion>
<Version>4.1.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 7 additions & 10 deletions Magic.IndexedDb/wwwroot/magicLinqToIndexedDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,15 @@ async function runIndexedQueries(db, table, universalQueries,
return await table.toArray();
}

let queries = [];

for (let query of universalQueries) {
const coverage = coveredIndex(table, query, queryAdditions, projection);
queries.push({ q: runIndexedQuery(table, query, queryAdditions, Boolean(coverage)), coverage });
}

let finalResults = [];
const finalResults = [];

await Promise.all(
queries.map(async ({ q, coverage }) => {
await db.transaction('r', table, async () => {
universalQueries.map(query => {
const coverage = coveredIndex(table, query, queryAdditions, projection);
return db.transaction('r', table, async () => {
// First and Last start their IndexedDB request immediately.
// Create that request in the transaction that awaits it.
const q = runIndexedQuery(table, query, queryAdditions, Boolean(coverage));
if (coverage && !(q instanceof Promise)) {
await q.eachKey((key, cursor) => {
const pk = cursor.primaryKey;
Expand Down
14 changes: 14 additions & 0 deletions tests/migrations/ProtectedWasm/App/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@
"The cross-store batch insert failed.");
Require((await references.ToListAsync()).Single().Target == "document",
"The protected batch failed to persist the typed value.");
foreach (var (id, size) in new[] { (20, 400 * 1024), (21, 400 * 1024), (22, 2800 * 1024) })
{
var secret = new string((char)('a' + id - 20), size);
Require(await table.InsertProtectedIfCurrentAsync(new RotationRow { Id = id, Secret = secret },
table, advancedFence, row => row.Generation) == MagicConditionalMutationResult.Applied,
"The guarded setup for the protected terminal read failed.");
var first = await table.FirstOrDefaultAsync(row => row.Id == id);
var last = await table.LastOrDefaultAsync(row => row.Id == id);
Require(first?.Id == id && first.Secret == secret && last?.Id == id && last.Secret == secret,
"Indexed terminal reads did not round-trip the protected record.");
}
Require(await table.FirstOrDefaultAsync(row => row.Id == -1) is null &&
await table.LastOrDefaultAsync(row => row.Id == -1) is null,
"An absent indexed key did not return the default value.");
await Contexts.DeactivateAsync();
}

Expand Down
52 changes: 51 additions & 1 deletion tests/migrations/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,10 +1759,60 @@ test('rotation checkpoints preserve compound keys across protected and public st
indexedKeys: ids.map(id => ['catalog', id]), publicRow: { id: 1, label: 'Public configuration' }, oldKeyRejected: true });
});

test('indexed first and last start their requests inside the native read transaction', async ({ page }) => {
const result = await page.evaluate(async () => {
const { default: Dexie } = await import('/engine/dexie/dexie.js');
const { magicQueryAsync } = await import('/engine/magicLinqToIndexedDb.js');
const db = new Dexie('indexed-terminal-transaction');
db.version(1).stores({ records: 'id, category' });
await db.open();
try {
const table = db.table('records');
await table.bulkAdd([{ id: 1, category: 7 }, { id: 2, category: 7 }]);
const prototype = Object.getPrototypeOf(table.toCollection());
let terminalCalls = 0;
for (const method of ['first', 'last']) {
const execute = prototype[method];
prototype[method] = function (...args) {
terminalCalls++;
if (!Dexie.currentTransaction) {
// Let a request started prematurely resolve on a later task.
// An unrelated empty read transaction cannot stay alive for it.
return execute.apply(this, args).then(async row => {
await new Promise(resolve => setTimeout(resolve, 20));
return row;
});
}
return execute.apply(this, args);
};
}
const query = async (property, value, additionFunction) => {
const before = terminalCalls;
const rows = await magicQueryAsync(db, table, {
nodeType: 1, condition: { property, operation: 'Equal', value }
}, [{ additionFunction, intValue: 0 }]);
if (terminalCalls === before) throw new Error("The query did not use the indexed terminal path.");
return rows.map(row => row.id);
};
return {
first: await query('category', 7, 'first'),
last: await query('category', 7, 'last'),
present: await query('id', 2, 'first'),
missing: await query('id', 3, 'last')
};
} catch (error) {
throw new Error(`${error.name}: ${error.message}`);
} finally {
db.close();
}
});
assert.deepEqual(result, { first: [1], last: [2], present: [2], missing: [] });
});

registerProtectedEngineTests({ test, schema, bundle, copy, inspect, read, loadPage, recoveryPackage,
appendRevision, jsonAsset, assets, cliFixture, getOrigin: () => origin });
registerProtectedRegistrationTests({ test, schema, bundle, jsonAsset, copy, registrationStore, inspect, appendRevision, assets });
const expectedScenarioCount = (cliFixture ? 143 : 139) + (process.env.MAGIC_ROTATION_BENCHMARK === "1" ? 9 : 0);
const expectedScenarioCount = (cliFixture ? 144 : 140) + (process.env.MAGIC_ROTATION_BENCHMARK === "1" ? 9 : 0);
assert.equal(tests.length, expectedScenarioCount, 'Unexpected migration scenario count.');

if (listOnly) {
Expand Down
Loading