Skip to content

Commit

Permalink
Upgrade to Realm Core v13.20.0 (#6121)
Browse files Browse the repository at this point in the history
* Upgrade to Realm Core v13.20.0
---------
Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com>
  • Loading branch information
kneth committed Sep 20, 2023
1 parent f3fe1d4 commit 6d2d3c9
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 30 deletions.
18 changes: 10 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
## vNext (TBD)

### Deprecations
* `Realm.Sync.reconnect(app)` has been deprecated and will be removed in the next major version. You can use `Realm.Sync.Session.reconnect()` instead.
* `Realm.App.Sync.reconnect(app)` has been deprecated and will be removed in the next major version. You can use `Realm.App.Sync.Session.reconnect()` instead.

### Enhancements
* Added `Realm.Sync.Session.reconnect()` to help force a reconnection to Atlas Device Sync. ([#6123](https://github.com/realm/realm-js/issues/6123))

### Fixed
* Fixed values of properties being replaced by default value when updating. ([#6129](https://github.com/realm/realm-js/issues/6129), since v12.0.0)
* Fixed that value for `Realm.schemaVersion` wasn't propagated correctly for non-existing files. ([#6119](https://github.com/realm/realm-js/issues/6119), since v12.0.0)
* Full text search supports searching for prefix only e.g., `description TEXT 'alex*'`. ([realm/realm-core#6860](https://github.com/realm/realm-core/issues/6860))
* Unknown protocol errors received from the Altas Device Sync server will no longer cause the app to crash if a valid error action is also received. Unknown error actions will cause device sync to fail with an error via the sync error handler. ([realm/realm-core#6885](https://github.com/realm/realm-core/pull/6885))
* Allow arguments to Realm Query Language to be a string representation of a geospatial object for `GEOWITHIN` queries. ([realm/realm-core#6934](https://github.com/realm/realm-core/issues/6934))
* Crash when querying the size of a Object property through a link chain. ([realm/realm-core#6915](https://github.com/realm/realm-core/issues/6915), since v12.0.0)

### Compatibility
* React Native >= v0.71.4
* Realm Studio v14.0.0.
* File format: generates Realms with format v23 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms).

### Internal
<!-- * Either mention core version or upgrade -->
<!-- * Using Realm Core vX.Y.Z -->
<!-- * Upgraded Realm Core from vX.Y.Z to vA.B.C -->
* Upgraded Realm Core from v13.17.2 to v13.20.0. ([#6077](https://github.com/realm/realm-js/issues/6077)
* Sync protocol version bumped to 10. ([realm/realm-core#6902](https://github.com/realm/realm-core/pull/6902))
* Error code reported in the sync error handling for compensating writes is reported as 1033 (previously 231). ([#6077](https://github.com/realm/realm-js/issues/6077)

## 12.1.0 (2023-08-30)

Expand All @@ -35,9 +39,7 @@
* File format: generates Realms with format v23 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms).

### Internal
<!-- * Either mention core version or upgrade -->
<!-- * Using Realm Core vX.Y.Z -->
<!-- * Upgraded Realm Core from vX.Y.Z to vA.B.C -->
* Using Realm Core v13.17.2.
* Removed pre-v12 source code.
* Added API documentation for `Realm.Configuration`. ([#6081](https://github.com/realm/realm-js/issues/6081), since v12.0.0)
* Added [typedoc-plugin-missing-exports](https://www.npmjs.com/package/typedoc-plugin-missing-exports) to resolved missing exports.
Expand Down Expand Up @@ -92,7 +94,7 @@ const TaskSchema = {
```

* To prevent modifying end-users' class-based model classes, we’re now creating and injecting a class in front of the class provided by the user. Objects will still pass `instanceof SomeClass` checks, however, code which is directly using prototype or constructor comparisons will fail:

```javascript
Object.getPrototypeOf(object) == CustomObject.prototype // No longer works
object.constructor == CustomObject // No longer works
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/src/tests/sync/client-reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function getSchema(useFlexibleSync: boolean) {
(error: SyncError) => {
expect(error.name).to.equal("ClientReset");
expect(error.message).to.equal("Simulate Client Reset");
expect(error.code).to.equal(211);
expect(error.code).to.equal(1032); // diverging client will cause a client reset (error code 1032)
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/src/tests/sync/flexible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
const callbackHandle = createPromiseHandle();

const errorCallback: ErrorCallback = (_, error) => {
expect(error.code).to.equal(231);
expect(error.code).to.equal(1033);
expect(error.logUrl).to.not.be.empty;
expect(error.message).to.contain(
"Client attempted a write that is outside of permissions or query filters; it has been reverted",
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/src/tests/sync/sync-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe("SessionTest", () => {
config.sync!.onError = (_, error: any) => {
try {
expect(error.message).equals("simulated error");
expect(error.code).equals(123);
expect(error.code).equals(1032);
resolve();
} catch (e) {
_reject(e);
Expand All @@ -278,7 +278,7 @@ describe("SessionTest", () => {
const realm = new Realm(config);
const session = realm.syncSession;
//@ts-expect-error using internal method.
session._simulateError(123, "simulated error", "realm::sync::ProtocolError", false);
session._simulateError(1032, "simulated error", "realm::sync::ProtocolError", false); // this will lead to error code 1032
});
});
});
Expand Down
4 changes: 1 addition & 3 deletions packages/realm/bindgen/js_opt_in_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ records:

SyncError:
fields:
- system_error
- status
- is_fatal
- simple_message
- logURL
Expand Down Expand Up @@ -165,8 +165,6 @@ records:
- app_id
- transport
- base_url
- local_app_name
- local_app_version
- default_request_timeout_ms
- device_info

Expand Down
6 changes: 5 additions & 1 deletion packages/realm/bindgen/src/templates/jsi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ function convertPrimToJsi(addon: JsiAddon, type: string, expr: string): string {
if (status.is_ok()) {
return jsi::Value::undefined();
} else {
return jsi::JSError(_env, status.reason()).value().getObject(_env);
auto jsObj = jsi::Object(_env);
jsObj.setProperty(_env, "isOk", status.is_ok());
jsObj.setProperty(_env, "code", static_cast<int32_t>(status.code()));
jsObj.setProperty(_env, "reason", status.reason());
return jsObj;
}
}(${expr}))`;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/realm/bindgen/src/templates/node-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function generate({ rawSpec, spec: boundSpec, file }: TemplateContext): v

both(`
import { Long, ObjectId, UUID, Decimal128, EJSON } from "bson";
import { Float } from "./core";
import { Float, Status } from "./core";
export * from "./core";
Expand Down Expand Up @@ -134,6 +134,7 @@ export function generate({ rawSpec, spec: boundSpec, file }: TemplateContext): v
"Long",
"ArrayBuffer",
"Float",
"Status",
"ObjectId",
"UUID",
"Decimal128",
Expand Down
9 changes: 7 additions & 2 deletions packages/realm/bindgen/src/templates/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,13 @@ function convertPrimToNode(addon: NodeAddon, type: string, expr: string): string
return `([&] (const Status& status) -> Napi::Value {
if (status.is_ok()) {
return ${env}.Undefined();
} else {
return Napi::Error::New(${env}, status.reason()).Value();
}
else {
auto jsObj = Napi::Object::New(${env});
jsObj.Set("isOk", status.is_ok());
jsObj.Set("code", static_cast<int32_t>(status.code()));
jsObj.Set("reason", status.reason());
return jsObj.As<Napi::Value>();
}
}(${expr}))`;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/realm/bindgen/src/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const PRIMITIVES_MAPPING: Record<string, string> = {
AppError: "AppError",
"std::exception_ptr": "Error",
"std::error_code": "CppErrorCode",
Status: "Error", // We don't currently expose the code.
Status: "Status",
EJson: "EJson",
EJsonArray: "EJson[]",
EJsonObj: "Record<string, EJson>",
Expand Down Expand Up @@ -166,6 +166,12 @@ export function generate({ rawSpec, spec: boundSpec, file }: TemplateContext): v
constructor(public value: number) {}
valueOf() { return this.value; }
}
export class Status {
public isOk: boolean;
public code?: number;
public reason?: string;
constructor(isOk: boolean) { this.isOk = isOk; }
}
`);

const out = file("native.d.mts", eslint);
Expand All @@ -174,7 +180,7 @@ export function generate({ rawSpec, spec: boundSpec, file }: TemplateContext): v
out("declare module 'realm/binding' {");

out('import { ObjectId, UUID, Decimal128 } from "bson";');
out("import { Float, ", spec.enums.map((e) => e.name).join(", "), '} from "realm/binding/core";');
out("import { Float, Status, ", spec.enums.map((e) => e.name).join(", "), '} from "realm/binding/core";');
out('export * from "realm/binding/core";');

out("// Utilities");
Expand Down
2 changes: 1 addition & 1 deletion packages/realm/bindgen/vendor/realm-core
Submodule realm-core updated 155 files
2 changes: 1 addition & 1 deletion packages/realm/dependencies.list
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REALM_CORE_VERSION=13.17.2
REALM_CORE_VERSION=13.20.0
2 changes: 0 additions & 2 deletions packages/realm/src/app-services/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ export class App<
appId: id,
deviceInfo: App.deviceInfo,
transport: createNetworkTransport(),
localAppName: app?.name,
localAppVersion: app?.version,
baseUrl,
defaultRequestTimeoutMs: timeout ? binding.Int64.numToInt(timeout) : undefined,
},
Expand Down
19 changes: 14 additions & 5 deletions packages/realm/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class PropertySchemaParseError extends SchemaParseError {

/** @internal */
export function fromBindingSyncError(error: binding.SyncError) {
if (error.systemError.code === 231) {
if (error.compensatingWritesInfo.length > 0) {
return new CompensatingWriteError(error);
} else if (error.isClientResetRequested) {
return new ClientResetError(error);
Expand All @@ -136,16 +136,21 @@ export function fromBindingSyncError(error: binding.SyncError) {
export class SyncError extends Error {
public name = "SyncError";

public isOk: boolean;

/**
* The error code that represents this error.
*/
public code: number;
public code?: number;

/**
* The category of this error.
* @deprecated
*/
public category: string;

public reason?: string;

/**
* The URL to the associated server log, if available. The string will be empty
* if the sync error is not initiated by the server.
Expand All @@ -165,9 +170,13 @@ export class SyncError extends Error {
/** @internal */
constructor(error: binding.SyncError) {
super(error.simpleMessage);
const { systemError } = error;
this.code = systemError.code;
this.category = systemError.category;
this.message = error.simpleMessage;
this.isOk = error.status.isOk;
if (!error.status.isOk) {
this.reason = error.status.reason;
this.code = error.status.code;
}
this.category = "UNKNOWN";
this.logUrl = error.logUrl;
this.userInfo = error.userInfo;
this.isFatal = error.isFatal;
Expand Down

0 comments on commit 6d2d3c9

Please sign in to comment.