Skip to content

Releases: dexie/Dexie.js

Dexie v4.2.1

13 Oct 12:20

Choose a tag to compare

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

y-dexie

  • Updated README

Full Changelog: v4.2.0...v4.2.1

Dexie v4.2.0

18 Aug 08:32

Choose a tag to compare

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

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:

  1. npm install y-dexie
  2. Instead of import { DexieYProvider } from 'dexie' --> import { DexieYProvider } from 'y-dexie'
  3. Instead of DexieyYProvider<Y.Doc> --> DexieYProvider.
  4. No need to pass Y to Dexie constructor, but instead, pass the yDexie addon:
    import yDexie from 'y-dexie';
    ...
    const db = new Dexie('foo', { addons: [yDexie] });
    With dexieCloud addon, make sure to pass yDexie first: { addons: [yDexie, dexieCloud] }
  5. Declare Y.Doc properties as prop:Y.Doc instead of just prop:Y
    db.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

06 Aug 07:43

Choose a tag to compare

Dexie v4.2.0-rc.1 Pre-release
Pre-release

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:

  1. npm install y-dexie
  2. Instead of import { DexieYProvider } from 'dexie' --> import { DexieYProvider } from 'y-dexie'
  3. Instead of DexieyYProvider<Y.Doc> --> DexieYProvider.
  4. No need to pass Y to Dexie constructor, but instead, pass the yDexie addon:
    import yDexie from 'y-dexie';
    ...
    const db = new Dexie('foo', { addons: [yDexie] });
    With dexieCloud addon, make sure to pass yDexie first: { addons: [yDexie, dexieCloud] }
  5. Declare Y.Doc properties as prop:Y.Doc instead of just prop:Y
    db.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

Full Changelog: 19a1778...a572b57

Dexie v4.1.0-beta.43

14 Feb 15:07

Choose a tag to compare

Dexie v4.1.0-beta.43 Pre-release
Pre-release

This release contains experimental support for integration with the Y.js library.

[email protected]

  • New constructor option Y provides 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

15 Jan 17:44

Choose a tag to compare

Fixes issues #2103 and #2113

Make sure to upgrade both dexie and dexie-cloud-addon:

npm install dexie@latest
npm install dexie-cloud-addon@latest

v4.0.10

15 Nov 21:00

Choose a tag to compare

[email protected]

  • #2096 Resolve #1946 again (bug in previous fix)
  • #1909 Allow setting chunk size per table

[email protected]

  • #2094 Fix Multiple Image Blob Export (Also fixes #1297)
  • #1973 Allow import with custom name

Dexie v4.0.9

21 Oct 15:29

Choose a tag to compare

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

10 Jul 15:34

Choose a tag to compare

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

26 May 13:48

Choose a tag to compare

  • Tighten non-idempotent operations (PR #2000 - mathematical addition or subtraction)
  • Align dexie and dexie-cloud-addon versions: 4.0.7

Dexie v4.0.5

24 May 22:49

Choose a tag to compare

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

Bug fixes

  • export ./dist/dexie.mjs (#1997)
  • Fix missing idbtrans in transaction (#1985)

[email protected]