Skip to content

Releases: dexie/Dexie.js

Dexie v4.0.1-alpha.17

01 Jun 18:31
Compare
Choose a tag to compare
Dexie v4.0.1-alpha.17 Pre-release
Pre-release

This release replaces 4.0.1-alpha.12, 4.0.1-alpha.13 and 4.0.1-alpha.14 due to issues #1730, #1731 and a few other issues fixed in PR #1733

Cache and Optimistic Updates (v0.1)

The biggest news with this release is the initial support for common cache for live queries that enables multiple liveQuery observables targeting the same set of queries to reuse a single request towards indexedDB and to be immediately triggered as soon as data is being mutated. In practice, this will become a big game changer for large apps that has many ongoing liveQueries going on targeting large amount of data and possibly targeting the same data from different components.

Before the flow was pretty simple but could take some time from a mutation until a change was visible in the app if the app had many components using liveQuery and where the results of the queries were large.

Flow prior to this relase:

  1. All live queries for the app is run initially (and the components are rendered).
  2. User does som action so that data is being updated (such as db.friends.update(1, {age: 23}).
  3. Write-transaction is committed --> onstoragemutated event is broadcasted to all tabs and workers
  4. liveQueries that has touched the affected ranges are re-executed. If we have 10 components with affected liveQueries, all 10 of them will simultanously query IndexedDB for their data again.

Flow with this release:

  1. All live queries for the app is run initially their promises are immediately cached in memory so that several liveQueries requesting the same data will await the same single promise instead of each one of them requesting indexedDB. When result arrives, the result is kept in the cache as long as there are components subscribing to the query.
  2. User does som action so that data is being updated (such as db.friends.update(1, {age: 23}). The cache is immediately recomputed by applying the mutation to the previous result and triggering subscribers immediately to rerender.
  3. Mutation promise resolves or reject. If it rejects, the optimistic update is rolled back and components rerender.
  4. Transaction commits or rejects. If it rejects, the optimistic updates are rolled back and components rerender. If it was successful, components doesn't need to requery indexedDB because they already have the changes in the cache.
  5. All mutations are still broadcasted to other tabs and workers. When a mutation comes from another tab or worker, it will not be optimistic but require a re-execution of the query.

So basically, liveQueries will only request IndexedDB at startup and two identical queries will only result in a single query towards IndexedDB.

Now this is the initial version of this and only certain queries can utilize this:

  • If your liveQuery callback explicitely does db.transaction('r', ...), the user expects isolation, so optimistic updates won't be used.
  • Only simple range queries are supported in this initial version: equals, above, aboveOrEqual, below, belowOrEqual, between, startsWith.
  • Only tables with inbound keys are supported.
  • Only toArray() queries (not .keys(), .primaryKeys() or .count())
  • Not offset based queries.
  • Not ignoreCase queries
  • Not anyOf or inAnyRange

Example of optimised queries:

  • db.friends.toArray()
  • db.friends.where('age').between(18,65, true, true).limit(10).toArray()

Example of non-optimized queries in this initial version:

  • db.friends.primaryKeys()
  • db.friends.count()
  • db.friends.offset(25).toArray()
  • db.transaction('r', db.friends, () => db.friends.toArray())

PRs:

  • #1718 Optimistic updates
  • #1727 Fix optimistic updates

Other changes:

  • Dexie will throw if trying to mutate data from a liveQuery callback ( liveQuery(()=>db.friends.add({...})) )
  • A new constructor option to Dexie is {cache: 'immutable' | 'cloned' | 'disabled'}. The default is 'cloned' but 'immutable' would give better performance because the cached results can be returned directly to the caller without having to deep clone it. However, the data will be frozen so if the liveQuery callback would try to set properties or call mutating array operations on the results, it will fail to do so if having { cache: 'immutable' }. array.sort() is one example of a commonly used mutable operation. Workaround is to use array.slice().sort() instead.

Other PRs in this release

  • #1711 Add .d.mts files to support import types properly.
  • #1716 Remove custom unhandledrejection event propagation

Dexie v4.0.1-alpha.14

31 May 13:57
Compare
Choose a tag to compare
Dexie v4.0.1-alpha.14 Pre-release
Pre-release

This release is replaced by 4.0.1-alpha.17

Dexie v4.0.1-alpha.12

30 May 22:15
Compare
Choose a tag to compare
Dexie v4.0.1-alpha.12 Pre-release
Pre-release

This release is replaced by 4.0.1-alpha.17

Dexie v3.2.4

30 May 21:07
Compare
Choose a tag to compare

Fixes in this maintenance release:

  • #1728 Make the optimisation in [email protected] work with [email protected]. In the latest version of dexie-react-hooks (version 1.1.5), live queries are optimised to not fire of unnecessary on render. However, this optimisation is dependant on that the observable returned from liveQuery has a method revealing whether it may be resolved synchronously or not (hasValue()). The optimisation requires dexie@>=3.2.4 or [email protected] together with [email protected].
  • #1677 Add //# sourceMappingUrl= to minified files. Fixes #326.
  • #1712 Add .d.mts files to support import types properly in preparation for future typescript release where this might be needed.

Dexie v4.0.1-alpha.10

28 Mar 22:47
Compare
Choose a tag to compare
Dexie v4.0.1-alpha.10 Pre-release
Pre-release

Better SSR support for NextJS and SvelteKit

This release (and related dexie-react-hooks release) comes with better behavior of liveQuery(). useLiveQuery() and useObservable() in SSR environments, as it makes sure that calling these from a node runtime without any indexedDB envirnomnent will result in a no-op. The result: Use these tools the same in Next.js as in vanilla React and in SvelteKIT as in vanilla Svelte - no need to check for SSR in application code anymore and no need to dynamically imported components doing dexie queries.

We also fixed the typings of our Observables returned from liveQuery() to be type-compatible with Svelte Readables (this was an issue when consuming liveQuery() results in Svelte using typescript).

Svelte users should install this prerelase of dexie instead of the stable version, but NextJS users may stay on the stable version of dexie if they prefer, and just upgrade dexie-react-hooks.

Full Next.js Support

  • Fixed more node errors that prevented nextjs SSR 19cdf0b
  • Better nextjs support for useLiveQuery(): 39484a3
  • Allow normal import of dexie-cloud-addon in nextjs: e18ee07

Full SvelteKit Support

Other fixes

  • Fix transaction typings #1685

We've also released...

[email protected]

  • Better nextjs support for useLiveQuery(): 39484a3

[email protected]

  • move rxjs deps out from peerDependencies and into ordinary dependencies
  • #1675 Dexie Cloud and NextJS improvements
  • #1691 Sveltekit fixes

[email protected]

  • progressCallback Problem? #1678

Dexie v4.0.1-alpha.8

17 Feb 08:42
Compare
Choose a tag to compare
Dexie v4.0.1-alpha.8 Pre-release
Pre-release

Minor fix

Append sourceMappingUrl in minified files

This fix makes the all JS files in the dist folder have the source mapping file pointed out so that bundlers can generate a correct final map file for the application or library that bundles dexie into it.

If dexie was used without bundling it into the app, this change will have no benefit as chrome devtools is still able to locate the map files without the mapfile comment-line.

Dexie v4.0.1-alpha.7

25 Jan 20:26
Compare
Choose a tag to compare
Dexie v4.0.1-alpha.7 Pre-release
Pre-release

Typings fix for Table.update(), Table.bulkUpdate() and Collection.modify()

In Dexie 4.0.1-alpha.6, Table.bulkUpdate() was introduced as well as improving the typings of Table.update(), Collection.modify() to using typescript template literals that would correcltly type the changes argument and provide a nice code completion. However, there was a typings bug in this release that made the typings unusable for updating nested properties.

This version fixes the typings of Table.update(), Table.bulkUpdate() and Collection.modify() so that they work according to the expected format.

Requires Typescript 4.8 or later

The typings in this release requires Typescript 4.8 or later in order to accept numeric keypaths and allow updating individual array items.

The UpdateSpec type

A new type UpdateSpec<T> is expected as the second argument to Table.update(). This type can also be imported from dexie when the library user need to build the updateSpec using custom code before finally send along to Table.update() or in an array keysAndChanges to Table.bulkUpdate().

import type { UpdateSpec } from 'dexie';

interface Contact {
  name: string;
  address: Address;
}

interface Address {
  city: string;
  street: string;
  streetNo: number;
}

let updateSpec: UpdateSpec<Contact> = {};

updateSpec["address.streetNo"] = 44;

db.contacts.update(1, updateSpec);

Dexie v3.2.3

23 Jan 13:15
Compare
Choose a tag to compare

Bugfixes:

This was fixed for 4.x but with this release it is also fixed in the official latest stable version of dexie.

Dexie v4.0.1-alpha.6

Dexie v4.0.0-alpha.4

30 May 22:30
Compare
Choose a tag to compare
Dexie v4.0.0-alpha.4 Pre-release
Pre-release
  • Fix for #1576 Node.js process not exiting when Dexie.js is imported
  • PR #1559 Support for FileSystemDirectoryHandle when cloning