Releases: dexie/Dexie.js
Dexie v4.2.1
New package versions
dexie
- Resolve issue #2186 by letting an external closure of the DB make it behave identical to explicit closing the database, except that we still respect autoOpen option by @dfahlander in #2187
- Feature: Table.upsert() by @dfahlander in #2203
dexie-cloud-addon
- Optimize sync updates by @dfahlander in #2201
- Fix styling of default login dialog by @dfahlander in #2204
- propagate Table.upsert() intention to server (part of #2203)
y-dexie
- Updated README
Full Changelog: v4.2.0...v4.2.1
Dexie v4.2.0
New Stable Packages
What's Changed since Latest Stable ([email protected])
- New add-on "y-dexie" that integrates the powerful Y.js library with dexie.
- Support "y-dexie" and Y.js in dexie-cloud-addon
- New hook
useDocument()in dexie-react-hooks for Y.js integration. - Fix Named Export 'Dexie' Not Found in Production with Vite/Vinxi by @thijssmudde in #2155
- fix: 'Dexie' Not Found in Production with Vite/Vinxi dexie-react-hooks by @Contraboi in #2162
New Contributors
- @thijssmudde made their first contribution in #2155
- @davbl made their first contribution in #2165
- @Contraboi made their first contribution in #2162
Migration from 4.1.x-beta
Dexie 4.1.x has been tagged @next and contained experimental Y.js support. The Y.js support has since been moved into its own add-on 'y-dexie'.
If the built-in Y.js support in [email protected] has been used, a migration is needed:
npm install y-dexie- Instead of
import { DexieYProvider } from 'dexie'-->import { DexieYProvider } from 'y-dexie' - Instead of
DexieyYProvider<Y.Doc>-->DexieYProvider. - No need to pass
Yto Dexie constructor, but instead, pass theyDexieaddon:With dexieCloud addon, make sure to pass yDexie first:import yDexie from 'y-dexie'; ... const db = new Dexie('foo', { addons: [yDexie] });
{ addons: [yDexie, dexieCloud] } - Declare Y.Doc properties as
prop:Y.Docinstead of justprop:Ydb.version(1).stores({ friends: ` ++id, name, age, friendNotes: Y.Doc` // where friendNotes holds the Y.Doc instance });
If you need a sample PR of these changes, have a look at dexie/dexie-cloud-starter#8
Full Changelog: b415d92...a978fc0
Dexie v4.2.0-rc.1
Release Candidate of [email protected]
In contrast to previous 4.1.x betas, we've extracted the Y.js support from the "dexie" package into "y-dexie".
Migration from 4.1.x-beta
Only if the experimental Y.js support from 4.1.x beta was used, a migration is needed:
npm install y-dexie- Instead of
import { DexieYProvider } from 'dexie'-->import { DexieYProvider } from 'y-dexie' - Instead of
DexieyYProvider<Y.Doc>-->DexieYProvider. - No need to pass
Yto Dexie constructor, but instead, pass theyDexieaddon:With dexieCloud addon, make sure to pass yDexie first:import yDexie from 'y-dexie'; ... const db = new Dexie('foo', { addons: [yDexie] });
{ addons: [yDexie, dexieCloud] } - Declare Y.Doc properties as
prop:Y.Docinstead of justprop:Ydb.version(1).stores({ friends: ` ++id, name, age, friendNotes: Y.Doc` // where friendNotes holds the Y.Doc instance });
If you need a sample PR of these changes, have a look at dexie/dexie-cloud-starter#8
What's Changed since 4.1.0-beta.43
- New npm package "y-dexie" and removed the Y.js code from the "dexie" library. #2180
- Fix Named Export 'Dexie' Not Found in Production with Vite/Vinxi by @thijssmudde in #2155
- fix: 'Dexie' Not Found in Production with Vite/Vinxi dexie-react-hooks by @Contraboi in #2162
New Contributors
- @thijssmudde made their first contribution in #2155
- @davbl made their first contribution in #2165
- @Contraboi made their first contribution in #2162
Full Changelog: 19a1778...a572b57
Dexie v4.1.0-beta.43
This release contains experimental support for integration with the Y.js library.
[email protected]
- New constructor option
Yprovides the Y.js library to Dexie.import * as Y from 'yjs'; import Dexie from "dexie"; const db = new Dexie("dbname", { Y });
- New schema feature:
<propertyName>:Y- declares virtual property (not an index) holding the Y.Doc instance.db.version(1).stores({ comments: 'id, title, contentDoc:Y' });
- New Y.js provider for Dexie: DexieYProvider.
const comment = await db.comments.get(commentId); try { DexieYProvider.load(comment.contentDoc); await comment.contentDoc.whenLoaded; // waits until loaded. // At this point the doc is loaded, observed and you // can invoke anything from the Y.js ecosystem, such // as a Tiptap or Prosemirror editor. } finally { DexieYProvider.release(comment.contentDoc); }
When using these options, every object retrieved from table containing :Y specifications, will contain an instance of a Y.Doc no matter if that property has been created or not. The property is neither enumerable nor own so JSON.stringify(obj) won't reveleal it. Accessing the Y.Doc will retrieve an empty, unloaded Y.Doc instance.
Rules for Y properties on objects
- Y properties are never nullish. If declared in the dexie schema, they'll exist on all objects from all queries (toArray(), get() etc).
- Y properties are not
own properties. They are set on the prototype of the returned object. - Y properties are readonly, except when adding new objects to a table (using table.add() or bulkAdd())
- If providing a custom Y.Doc to add() or bulkAdd() its udates will be cloned when added.
- If not providing the Y.Doc or setting the Y property to null when adding objects, there will still be an Y.Doc property on query results of the object, since Y props are defined by the schema and cannot be null or undefined.
- Y properties on dexie objects are readonly. You can not replace them with another document or update them using table.update() or collection.modify(). The only way to update Y.Docs is via the Y.js library methods on the document instance.
- Y properties are not loaded until using DexieYProvider.load() or the new react hook
useDocument() - Y.Doc instances are kept in a global cache integrated with FinalizationRegistry. First time you access the getter, it will be created, and will stay in cache until it's garbage collected. This means that you'll always get the same Y.Doc instance when querying the same Y property of a the same object. This holds true even if the there are multiple obj instances representing the same ID in the database. All of these will hold one single instance of the Y.Doc because the cache is connected to the primary key of the parent object.
How it works
Internally, every declared Y property generates a dedicated table for Y.js updates tied to the parent table and the property name. Whenever a document is updated, a new entry in this table is added.
DexieYProvider is responsible of loading and observing updates in both directions.
Integrations
Y.js allows multiple providers on the same document. It is possible to combine DexieYProvider with other providers, but it is also possible for dexie addons to extend the provider behavior - such as adding awareness and sync.
[email protected]
This is the next verison of dexie-cloud-addon that extends the behavior of DexieYProvider to also support awareness and sync over websockets with Dexie Cloud Server.
Bugfixes
No double initial sync
Earlier versions of dexie-cloud-addon performed two initial sync phases also when requireAuth was specified. This is now optimized to only be done in a single authenticated initial sync.
Better migration from vanilla dexie to dexie-cloud
A vanilla Dexie app with multiple versions and upgraders could not make it to the cloud earlier because we previously disallowed using upgraders between versions when using dexie-cloud-addon. With this version, we allow that but make sure that the change tracking and sync is disabled during upgrade transactions. This allows vanilla dexie apps for easier migrating to cloud by allowing them to run the upgraders needed and then activate dexie-cloud and sync.
New Example App
The Dexie Cloud Starter is a new nextjs app that make full use of online text editing, full-text search and dexie cloud authentication, Github SSO and data sharing in realms.
[email protected]
New hook useDocument() makes use of DexieYProvider as a hook rather than loading and releasing imperatively.
function MyComponent(commentId: string) {
// Query comment object:
const comment = useLiveQuery(() => db.comments.get(comentId));
// Use it's document property (might be nullish):
const provider = useDocument(comment?.contentDoc);
// Pass provider and document to some Y.js compliant code in the ecosystem of such (unless nullish)...
return provider
? <CommentEditor doc={comment.contentDoc} provider={provider} />
: null;
}Dexie v4.0.11
v4.0.10
Dexie v4.0.9
Bugfixes
#2011: Dexie returns duplicated object after manually deleting the database and re-populate it
#2064 Failed to execute 'cmp' on 'IDBFactory': The parameter is not a valid key.
#2073 Uses cmp for sortBy
#2078 DexiePromise does not have withResolvers
#2067 useLiveQuery does not update when multiple items are deleted
Note: The Y.js support is released in 4.1.0 in alpha and possible to test but there is still no official release published for it. Also, the API might change from how it is right now. Will need some more testing and documentation before publishing it with release notes
Dexie v4.0.8
Here's a maintainance release with small things so far.
NOTE: We're also working to release a 4.1 later this summer with CRDT support for rich text editing by providing explicit support for Y.js documents into both Dexie.js and Dexie Cloud (#1926)
Solved issues
- #2001 Typings: circular reference on update
- #2004 Add complete ./dist/* to package.json exports
- #2026 Typings error with Table.update()
- #2011 and #2012: bulkPut() of multiple objects with same primary key would result i liveQueries showing multiple results instead of the last entry only (which is the correct result).
PRs:
- #2006 requireAuth with options. Now possible to provide requireAuth: {email, otp, otpId} instead of just requireAuth: true. Useful when implementing magic link authentication.
[email protected]:
- Fix the 10-seconds pause issue: fdd9844
Dexie v4.0.7
- Tighten non-idempotent operations (PR #2000 - mathematical addition or subtraction)
- Align dexie and dexie-cloud-addon versions: 4.0.7
Dexie v4.0.5
Features
New CRDT operations: add() and remove() (#1936)
New operations that works consistently across sync: Mathematical addition/subtraction as well as adding or removing string or numbers from array properties.
Add to set
It is now possible to add items to an array property using a sync consistent operation "add":
import { add } from "dexie";
db.friends.update(friend.id, {
hobbies: add([
"skating",
"football"
])
});Remove from set
import { remove } from "dexie";
db.friends.update(friend.id, {
hobbies: remove([
"curling"
])
});Mathematical addition and subtraction (number)
import { add, remove } from "dexie";
await db.transaction('rw', db.accounts, () => {
db.accounts.update(accountId1, { balance: remove(100) });
db.accounts.update(accountId2, { balance: add(100) });
});Mathematical addition and subtraction (bigint)
import { add, remove } from "dexie";
await db.transaction('rw', db.accounts, () => {
db.accounts.update(accountId1, { balance: remove(100n) });
db.accounts.update(accountId2, { balance: add(100n) });
});Typings
- #1998 TInsertType in table methods on Dexie and Transaction