Skip to content

Commit

Permalink
Merge branch 'main' into fp/core-logging
Browse files Browse the repository at this point in the history
* main:
  Update core to v13.9.1 (#5739)
  Implement `User.state` (#5712)
  Rename `local-mongodb` to enable app replacements (#5734)
  Update return type of 'assert.never'. (#5718)
  Run tests after builds are done, regardless of they failed or succeeded (#5729)
  • Loading branch information
papafe committed Apr 17, 2023
2 parents 8924bb3 + a956a74 commit c670167
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ jobs:
ios-xcframework:
name: Generate Info.plist with all frameworks in place
needs: [build]
if: ${{ success() || failure() }}
runs-on: macos-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -234,6 +235,7 @@ jobs:
integration-tests:
name: Integration tests (${{matrix.variant.target}}) for ${{ matrix.variant.environment }} on ${{ matrix.variant.os }}
needs: [bundle, build, ios-xcframework]
if: ${{ success() || failure() }}
env:
REALM_DISABLE_ANALYTICS: 1
MOCHA_REMOTE_TIMEOUT: 60000
Expand Down
16 changes: 9 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
* None

### Enhancements
* None
* Enable multiple processes to operate on an encrypted Realm simultaneously. ([realm/realm-core#1845](https://github.com/realm/realm-core/issues/1845))

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None
* Fix a stack overflow crash when using the query parser with long chains of AND/OR conditions. ([realm/realm-core#6428](https://github.com/realm/realm-core/pull/6428), since v10.11.0)
* Fixed an issue that could have resulted in a client reset action being reported as successful when it actually failed on windows if the `Realm` was still open ([realm/realm-core#6050](https://github.com/realm/realm-core/issues/6050)).
* Fix a data race that could cause a reading thread to read from a no-longer-valid memory mapping ([realm/realm-core#6411](https://github.com/realm/realm-core/pull/6411), since v11.3.0-rc.0).
* Fixed an issue that could cause a crash when performing count() on an undefined query. ([realm/realm-core#6443](https://github.com/realm/realm-core/issues/6443), since v12.0.0-alpha.2)
* Added missing implementation of `User.state` and changed the `UserState` enum values to use pascal case to conform to the v11 implementation (except for `UserState.Active` that we now deprecate in favor of `UserState.LoggedIn`). [#5686](https://github.com/realm/realm-js/issues/5686)

### Compatibility
* React Native >= v0.71.0
* Realm Studio v13.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).
* Lock file format: New format introduced for multiprocess encryption. All processes accessing the file must be upgraded to the new format.

### 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.8.0 to v13.9.1. ([#5739](https://github.com/realm/realm-js/pull/5739))

## 12.0.0-alpha.2 (2023-04-05)

Expand All @@ -29,7 +31,7 @@ Nikolai Samorodov / [@zabutok](https://github.com/zabutok) for contributing the
* Added a new error class `CompensatingWriteError` which indicates that one or more object changes have been reverted by the server.
This can happen when the client creates/updates objects that do not match any subscription, or performs writes on an object it didn't have permission to access. ([#5599](https://github.com/realm/realm-js/pull/5599))
* Performance improvement for the following queries ([realm/realm-core#6376](https://github.com/realm/realm-core/issues/6376)):
* Significant (~75%) improvement when counting (`Realm.Results#length`) the number of exact matches (with no other query conditions) on a `string`/`int`/`uuid`/`objectId` property that has an index. This improvement will be especially noticiable if there are a large number of results returned (duplicate values).
* Significant (~75%) improvement when counting (`Realm.Results#length`) the number of exact matches (with no other query conditions) on a `string`/`int`/`uuid`/`objectId` property that has an index. This improvement will be especially noticeable if there are a large number of results returned (duplicate values).
* Significant (~99%) improvement when querying for an exact match on a `date` property that has an index.
* Significant (~99%) improvement when querying for a case insensitive match on a `mixed` property that has an index.
* Moderate (~25%) improvement when querying for an exact match on a `bool` property that has an index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

exports = async function (loginPayload) {
// Get a handle for the app.users collection
const users = context.services.get("local-mongodb").db("app").collection("users");
const users = context.services.get("mongodb").db("app").collection("users");

// Parse out custom data from the FunctionCredential

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "local-mongodb",
"name": "mongodb",
"type": "mongodb",
"config": {},
"secret_config": {
"uri": "local-mongodb-uri"
}
},
"version": 1
}
21 changes: 21 additions & 0 deletions integration-tests/tests/src/tests/sync/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
randomVerifiableEmail,
} from "../../utils/generators";
import { KJUR } from "jsrsasign";
import { UserState } from "realm";

function expectIsUSer(user: Realm.User) {
expect(user).to.not.be.undefined;
Expand Down Expand Up @@ -320,6 +321,26 @@ describe.skipIf(environment.missingServer, "User", () => {
expect(user2).to.be.undefined;
expect(didFail).to.be.true;
});

describe("state", () => {
it("can fetch state when logged in with email password", async function (this: AppContext & RealmContext) {
expect(this.app.currentUser).to.be.null;
const user = await registerAndLogInEmailUser(this.app);
expect(user.state).to.equal(UserState.LoggedIn);
});

it("can fetch state when logged out with email password", async function (this: AppContext & RealmContext) {
const user = await registerAndLogInEmailUser(this.app);
await user.logOut();
expect(user.state).to.equal(UserState.LoggedOut);
});

it("can fetch state when removed with email password", async function (this: AppContext & RealmContext) {
const user = await registerAndLogInEmailUser(this.app);
await this.app.removeUser(user);
expect(user.state).to.equal(UserState.Removed);
});
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/realm/src/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export class RealmObject<T = DefaultObject> {
} else if (value instanceof BSON.UUID) {
return "uuid";
} else {
throw assert.never(value, "value");
assert.never(value, "value");
}
} else {
return typeName;
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/src/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ export class Realm {
} else if (eventName === RealmEvent.BeforeNotify) {
this.beforeNotifyListeners.remove(callback);
} else {
throw assert.never(eventName, "eventName");
assert.never(eventName, "eventName");
}
}

Expand All @@ -1089,7 +1089,7 @@ export class Realm {
} else if (eventName === RealmEvent.BeforeNotify) {
this.beforeNotifyListeners.removeAll();
} else {
throw assert.never(eventName, "eventName");
assert.never(eventName, "eventName");
}
}
}
Expand Down
23 changes: 19 additions & 4 deletions packages/realm/src/app-services/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ export type UserChangeCallback = () => void;
* The state of a user.
*/
export enum UserState {
/** Authenticated and available to communicate with services. */
/**
* Authenticated and available to communicate with services.
* @deprecated Will be removed in v13. Please use {@link LoggedIn}
*/
Active = "active",
/** Authenticated and available to communicate with services. */
LoggedIn = "LoggedIn",
/** Logged out, but ready to be logged in. */
LoggedOut = "logged-out",
LoggedOut = "LoggedOut",
/** Removed from the app entirely. */
Removed = "removed",
Removed = "Removed",
}

/**
Expand Down Expand Up @@ -141,7 +146,17 @@ export class User<
* The state of the user.
*/
get state(): UserState {
throw new Error("Not yet implemented");
const state = this.internal.state;
switch (state) {
case binding.SyncUserState.LoggedIn:
return UserState.LoggedIn;
case binding.SyncUserState.LoggedOut:
return UserState.LoggedOut;
case binding.SyncUserState.Removed:
return UserState.Removed;
default:
throw new Error(`Unsupported SyncUserState value: ${state}`);
}
}

/**
Expand Down
29 changes: 17 additions & 12 deletions packages/realm/src/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ assert.symbol = (value: unknown, target?: string): asserts value is symbol => {
assert(typeof value === "symbol", () => new TypeAssertionError("a symbol", value, target));
};

assert.primaryKey = (value: unknown, target?: string): asserts value is PrimaryKey => {
assert(
value === null ||
typeof value === "number" ||
typeof value === "string" ||
value instanceof BSON.UUID ||
value instanceof BSON.ObjectId,
() => new TypeAssertionError("a primary key", value, target),
);
};

assert.object = <K extends string | number | symbol = string, V = unknown>(
value: unknown,
target?: string,
Expand Down Expand Up @@ -133,12 +122,28 @@ assert.iterable = (value: unknown, target?: string): asserts value is Iterable<u
assert(Symbol.iterator in value, () => new TypeAssertionError("iterable", value, target));
};

assert.never = (value: never, target?: string): asserts value is never => {
// * Use arg type `value: never` rather than `value: unknown` to get a compile time
// error when e.g. not including if-checks for all enum values.
// * Use return type `never` rather than `asserts value is never` to remove the
// need for callers to explicitly throw (i.e. `throw assert.never()`) as a way
// for TS to detect unreachable code.
assert.never = (value: never, target?: string): never => {
throw new TypeAssertionError("never", value, target);
};

// SDK specific

assert.primaryKey = (value: unknown, target?: string): asserts value is PrimaryKey => {
assert(
value === null ||
typeof value === "number" ||
typeof value === "string" ||
value instanceof BSON.UUID ||
value instanceof BSON.ObjectId,
() => new TypeAssertionError("a primary key", value, target),
);
};

assert.open = (realm: Realm) => {
assert(!realm.isClosed, "Cannot access realm that has been closed.");
};
Expand Down

0 comments on commit c670167

Please sign in to comment.