Realm JavaScript v11.0.0
Notes
Based on Realm JS v10.22.0: See changelog below for details on enhancements and fixes introduced between this and the previous pre release (which was based on Realm JS v10.19.5).
Breaking changes
Removed APIs
- Removed all code related to the legacy Chrome Debugger. Please use Flipper as debugger.
The following deprecated methods have been removed:
Realm#automaticSyncConfiguration
Realm.Credentials#google
withauthCode
parameter (useauthObject
)- The following should be replaced with
Realm.Credentials#apiKey
:Realm.Credentials#serverApiKey
Realm.Credentials#userApiKey
- The overload of
Realm.Auth.EmailPasswordAuth
methods, taking positional arguments instead of object arguments:registerUser
- Removed
Realm.JsonSerializationReplacer
. Use circular JSON serialization libraries such as @ungap/structured-clone and flatted for stringifying Realm entities that have circular structures. The Realm entities'toJSON
method returns plain objects and arrays (with circular references if applicable) which makes them compatible with any serialization library that supports stringifying plain JavaScript types. (#4997)
Now the only supported call signature of Realm.Auth.EmailPasswordAuth
methods is using a single object argument:
registerUser({ email, password });
confirmUser({ token, tokenId });
resendConfirmationEmail({ email });
retryCustomConfirmation({ email });
resetPassword({ token, tokenId, password });
sendResetPasswordEmail({ email });
callResetPasswordFunction({ email, password }, ...args);
Renamed APIs
- Renamed the
RealmInsertionModel<T>
type toUnmanaged<T>
to simplify and highlight its usage.
The following APIs have been renamed on the Realm
:
Before | After |
---|---|
empty |
isEmpty |
readOnly |
isReadOnly |
The following APIs have been renamed on the Realm.Config
:
Before | After |
---|---|
migration |
onMigration |
shouldCompactOnLaunch |
shouldCompact |
The following APIs have been renamed on the Realm.SyncConfiguration
:
Before | After |
---|---|
error |
onError |
clientReset.clientResetBefore |
clientReset.onBefore |
clientReset.clientResetAfter |
clientReset.onAfter |
ssl.validateCallback |
ssl.validateCertificates |
- A typo was fixed in the
SubscriptionsState
enum, in whichSubscriptionsState.Superseded
now returnssuperseded
in place ofSuperseded
Here are examples of the use of the APIs after they've been renamed:
// before
Realm.open({ migration:() => {} })
// after
Realm.open({ onMigration:() => {} })
// before
Realm.open({
sync: {
shouldCompactOnLaunch: /* ... */
error: /* ... */
clientReset: {
clientResetBefore: /* ... */
clientResetAfter: /* ... */
}
ssl:{
validateCallback: /* ... */
}
}
})
// after
Realm.open({
sync: {
shouldCompact: /* ... */
onError: /* ... */
clientReset: {
onBefore: /* ... */
onAfter: /* ... */
}
ssl:{
validateCertificates: /* ... */
}
}
})
Changed APIs
- Model classes passed as schema to the
Realm
constructor must now extendRealm.Object
and will no longer have their constructors called when pulling an object of that type from the database. Existing classes already extendingRealm.Object
now need to call thesuper
constructor passing two arguments:
realm
: The Realm to create the object in.values
: Values to pass to therealm.create
call when creating the object in the database.
Realm#writeCopyTo
now only accepts an output Realm configuration as a parameter.- When no object is found calling
Realm#objectForPrimaryKey
,null
is returned instead ofundefined
, - Removed
Object#_objectId
, which is now replaced byObject#_objectKey
- Unified the call signature of
User#callFunction
(#3733) - Replaced string unions with enums where it made sense:
Realm.App.Sync.Session#state
is nowSessionState
.Realm.App.Sync.Session#addProgressNotification
now takes(direction: ProgressDirection, mode: ProgressMode, progressCallback: ProgressNotificationCallback)
."discardLocal"
is now the default client reset mode. (#4382)
This is an example of calling a function with the new signature of callFunction
:
user.callFunction("sum", 1, 2, 3); // Valid
user.callFunction("sum", [1, 2, 3]); // Invalid
user.functions.sum(1, 2, 3); // Still the recommended
Enhancements
- Adding support for Hermes on iOS & Android.
- Class-based models (i.e. user defined classes extending
Realm.Object
and passed through theschema
when opening a Realm), will now create object when their constructor is called. - Small improvement to performance by caching JSI property String object #4863
- Small improvement to performance for
toJSON
which should make it useful for cases where a plain representations of Realm entities are needed, e.g. when inspecting them for debugging purposes throughconsole.log(realmObj.toJSON())
. (#4997) - Catching missing libjsi.so when loading the librealm.so and rethrowing a more meaningful error, instructing users to upgrade their version of React Native.
Example of declaring a class-based model in TypeScript:
class Person extends Realm.Object<Person> {
name!: string;
static schema = {
name: "Person",
properties: { name: "string" },
};
}
const realm = new Realm({ schema: [Person] });
realm.write(() => {
const alice = new Person(realm, { name: "Alice" });
// A Person { name: "Alice" } is now persisted in the database
console.log("Hello " + alice.name);
});
Compatibility
- React Native >= v0.70.0
- Atlas App Services.
- Realm Studio v12.0.0.
- APIs are backwards compatible with all previous releases of Realm JavaScript in the 10.5.x series.
- File format: generates Realms with format v22 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms).
Internal
- Using Realm Core v12.9.0
- Building from source from a package downloaded via NPM is no longer supported, since we removed
src
andvendor
from the NPM bundle, to reduce size blow-up caused by files recently added to the sub-module. This will force end-users to checkout the Git repository from GitHub when building from source. (#4060) - Renamed the following internal packages:
@realm.io/common
->@realm/common
realm-network-transport
->@realm/network-transport
realm-app-importer
->@realm/app-importer
realm-example
->@realm/example
realm-electron-tests
->@realm/electron-tests
realm-node-tests
->@realm/node-tests
realm-react-native-tests
->@realm/react-native-tests