Skip to content

Commit

Permalink
Merge branch 'main' into fp/minimal-fts
Browse files Browse the repository at this point in the history
* main:
  Remove incorrect info and adds to return description for compact() (#5798)
  Use `declare prop` rather than `prop!` with Object.declareProperty()
  Use Object.defineProperty rather than Object.defineProperties because it is faster
  Update importAppBefore to take an AppConfiguration (#5838)
  Adding `next` to install test matrix (#5819)
  Default session multiplexing to being disabled (#5831)
  Adding types for some "environment" options
  Exposing a defaultLogLevel context option
  Update pr-realm-js.yml
  Update PR workflow to pin the server version
  Update baas test server install script
  • Loading branch information
papafe committed May 24, 2023
2 parents d0c1c17 + 29486fc commit f2a2fc6
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 167 deletions.
1 change: 1 addition & 0 deletions .github/workflows/install-test-react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
realm-version:
# - v10 # Enable if we feel the need
- latest
- next
react-native-version:
- latest
- next
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ jobs:
MOCHA_REMOTE_REPORTER: mocha-github-actions-reporter
MOCHA_REMOTE_EXIT_ON_ERROR: true
SPAWN_LOGCAT: true
BAAS_TAG: latest
# Pin the Xcode version
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app
runs-on: ${{ matrix.variant.runner }}
Expand Down Expand Up @@ -284,7 +285,7 @@ jobs:
echo "url=https://${subdomain}.ngrok.io" >> $GITHUB_OUTPUT;

- name: Trigger the test server workflow to start the server
run: gh workflow run test-server.yml -f ngrok_subdomain=${{ steps.baas-config.outputs.subdomain }} -f run_id=${{ github.run_id }}
run: gh workflow run test-server.yml -f ngrok_subdomain=${{ steps.baas-config.outputs.subdomain }} -f run_id=${{ github.run_id }} -f server_tag=${{ env.BAAS_TAG }}
env:
GH_TOKEN: ${{ github.token }}

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* Upgraded React Native from 0.71.4 to 0.71.7. ([#5761](https://github.com/realm/realm-js/pull/5761))
* Upgraded Realm Core from v13.10.1 to v13.11.0. ([#5811](https://github.com/realm/realm-js/issues/5811))
* Bump sync protocol to v9 to indicate client has fix for client reset error during async open. ([realm/realm-core#6609](https://github.com/realm/realm-core/issues/6609))
* Sync session multiplexing is enabled by default, and calling `Realm.Sync.Session#enableSessionMultiplexing()` is a no-op.
* Disabling sync session multiplexing by default in the SDK, since Core's default changed to enabled with v13.11.0. ([#5831](https://github.com/realm/realm-js/pull/5831))

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

Expand Down
6 changes: 3 additions & 3 deletions docs/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ class Realm {
cancelTransaction() {}

/**
* Replaces all string columns in this Realm with a string enumeration column and compacts the
* database file.
* Compacts the database file.
*
* Cannot be called from a write transaction.
*
Expand All @@ -292,7 +291,8 @@ class Realm {
* Be warned that resource requirements for compaction is proportional to the amount of live data in
* the database. Compaction works by writing the database contents to a temporary database file and
* then replacing the database with the temporary one.
* @returns {true} if compaction succeeds.
* @returns {boolean} returns `false` if compaction was not allowed, `true` if compaction succeeds.
* An exception is thrown if writing the compacted file fails.
*/
compact() {}

Expand Down
1 change: 1 addition & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Examples of context variables used:
- `performance`: Disabled skipping of the "Performance tests" suite.
- `integration=false`: Skip the integration test (which performance tests are not considered a part of).
- `preserveAppAfterRun`: Skip deleting the Realm app after the test run
- `defaultLogLevel=all`: Set the default log level to help debugging realm core issues.
- `syncLogLevel=all`: Set the sync client log level to help debugging sync client issues.
- `reuseApp=true`: Instructs the app importer to reuse and reconfigure a single app. Defaults to `false`.
- `realmBaseUrl=https://localhost:9090`: Set the base URL used when connecting the the server.
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/baas-test-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import { Socket } from "node:net";

const MONGO_CONTAINER_NAME = "mongo";
const STITCH_SUPPORT_URL =
"https://mciuploads.s3.amazonaws.com/mongodb-mongo-master-nightly/stitch-support/macos-arm64/796351fa200293a91413699c8da073eb314ac2cd/stitch-support-6.1.0-alpha-527-g796351f.tgz";
// This can be updated once https://github.com/10gen/baas/pull/7405 gets merged
"https://stitch-artifacts.s3.amazonaws.com/stitch-support/macos-arm64/stitch-support-6.1.0-alpha-527-g796351f.tgz";
const BAAS_REPO = "[email protected]:10gen/baas.git";
const BAAS_UI_REPO = "[email protected]:10gen/baas-ui.git";
const MONGODB_PORT = 26000;
Expand Down
13 changes: 6 additions & 7 deletions integration-tests/tests/src/hooks/import-app-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
//
////////////////////////////////////////////////////////////////////////////

import { Realm } from "realm";
import { Realm, AppConfiguration } from "realm";

import { importApp } from "../utils/import-app";
import { AppConfig } from "@realm/app-importer";
import { mongodbServiceType } from "../utils/ExtendedAppConfigBuilder";

const REALM_LOG_LEVELS = ["all", "trace", "debug", "detail", "info", "warn", "error", "fatal", "off"];

export function importAppBefore(
config: AppConfig | { config: AppConfig },
logLevel: Realm.App.Sync.LogLevel = (environment.syncLogLevel as Realm.App.Sync.LogLevel) || "warn",
): void {
const { syncLogLevel = "warn" } = environment;

export function importAppBefore(config: AppConfig | { config: AppConfig }, sdkConfig?: AppConfiguration): void {
// Unwrap when passed a builder directly
if ("config" in config) {
return importAppBefore(config.config);
Expand All @@ -40,7 +39,7 @@ export function importAppBefore(
throw new Error("Unexpected app on context, use only one importAppBefore per test");
} else {
const { appId, baseUrl } = await importApp(config);
this.app = new Realm.App({ id: appId, baseUrl });
this.app = new Realm.App({ id: appId, baseUrl, ...sdkConfig });

// Extract the sync database name from the config
const databaseNames: string[] = config.services
Expand All @@ -59,7 +58,7 @@ export function importAppBefore(
throw new Error("Expected at most 1 database name in the config");
}

Realm.App.Sync.setLogLevel(this.app, logLevel);
Realm.App.Sync.setLogLevel(this.app, syncLogLevel);
// Set a default logger as Android does not forward stdout
Realm.App.Sync.setLogger(this.app, (level, message) => {
const time = new Date().toISOString().split("T")[1].replace("Z", "");
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/tests/src/setup-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ describe("Test Harness", function (this: Mocha.Suite) {

import { Realm } from "realm";

//Disable the logger to avoid console flooding
Realm.setLogLevel("off");
// Disable the logger to avoid console flooding
const { defaultLogLevel = "off" } = environment;
Realm.setLogLevel(defaultLogLevel);
5 changes: 4 additions & 1 deletion integration-tests/tests/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//
////////////////////////////////////////////////////////////////////////////

type Realm = import("realm").Realm;
type RealmObject = import("realm").Object;
type App = import("realm").App;
type User = import("realm").User;
Expand Down Expand Up @@ -45,6 +44,10 @@ type KnownEnvironment = {
performance?: true;
/** Disable deletion of the Realm app after the test run. */
preserveAppAfterRun?: true;
/** Instructs the app importer to reuse and reconfigure a single app. */
reuseApp?: true;
/** Set the default log level to help debugging realm core issues */
defaultLogLevel?: Realm.App.Sync.LogLevel;
/** Set the sync client log level to help debugging sync client issues */
syncLogLevel?: Realm.App.Sync.LogLevel;

Expand Down
47 changes: 20 additions & 27 deletions packages/realm/src/ClassMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,46 +79,39 @@ export class ClassMap {
const properties = [...schema.persistedProperties, ...schema.computedProperties];
const propertyNames = properties.map((p) => p.publicName || p.name);

// Build a map of property descriptors from the properties declared in the schema
const descriptors: PropertyDescriptorMap = Object.fromEntries(
properties.map((property) => {
const propertyName = property.publicName || property.name;
const { get, set } = propertyMap.get(propertyName);
return [
propertyName,
{
enumerable: true,
get(this: RealmObject) {
return get(this[INTERNAL]);
},
set(this: RealmObject, value: unknown) {
set(this[INTERNAL], value);
},
},
];
}),
);
// Set up accessors for the properties declared in the schema
for (const property of properties) {
const propertyName = property.publicName || property.name;
const { get, set } = propertyMap.get(propertyName);
Object.defineProperty(constructor.prototype, propertyName, {
enumerable: true,
get(this: RealmObject) {
return get(this[INTERNAL]);
},
set(this: RealmObject, value: unknown) {
set(this[INTERNAL], value);
},
});
}

descriptors[REALM] = {
Object.defineProperty(constructor.prototype, REALM, {
enumerable: false,
configurable: false,
writable: false,
value: realm,
};
descriptors[KEY_ARRAY] = {
});
Object.defineProperty(constructor.prototype, KEY_ARRAY, {
enumerable: false,
configurable: false,
writable: false,
value: propertyNames,
};
descriptors[KEY_SET] = {
});
Object.defineProperty(constructor.prototype, KEY_SET, {
enumerable: false,
configurable: false,
writable: false,
value: new Set(propertyNames),
};

Object.defineProperties(constructor.prototype, descriptors);
});
}

constructor(realm: Realm, realmSchema: readonly BindingObjectSchema[], canonicalRealmSchema: CanonicalRealmSchema) {
Expand Down
10 changes: 4 additions & 6 deletions packages/realm/src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ export abstract class Collection<
},
});
// Make the internal properties non-enumerable
Object.defineProperties(this, {
listeners: {
enumerable: false,
configurable: false,
writable: false,
},
Object.defineProperty(this, "listeners", {
enumerable: false,
configurable: false,
writable: false,
});
}

Expand Down
42 changes: 20 additions & 22 deletions packages/realm/src/Dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,23 @@ export class Dictionary<T = unknown> extends Collection<string, T, [string, T],

const proxied = new Proxy(this, PROXY_HANDLER) as Dictionary<T>;

Object.defineProperties(this, {
[REALM]: {
enumerable: false,
configurable: false,
writable: false,
value: realm,
},
[INTERNAL]: {
enumerable: false,
configurable: false,
writable: false,
value: internal,
},
[HELPERS]: {
enumerable: false,
configurable: false,
writable: false,
value: helpers,
},
Object.defineProperty(this, REALM, {
enumerable: false,
configurable: false,
writable: false,
value: realm,
});
Object.defineProperty(this, INTERNAL, {
enumerable: false,
configurable: false,
writable: false,
value: internal,
});
Object.defineProperty(this, HELPERS, {
enumerable: false,
configurable: false,
writable: false,
value: helpers,
});

return proxied;
Expand All @@ -170,18 +168,18 @@ export class Dictionary<T = unknown> extends Collection<string, T, [string, T],
* The representation in the binding.
* @internal
*/
private [REALM]!: Realm;
private declare [REALM]: Realm;

/**
* The representation in the binding.
* @internal
*/
private [INTERNAL]!: binding.Dictionary;
private declare [INTERNAL]: binding.Dictionary;

/**
* @internal
*/
private [HELPERS]!: TypeHelpers;
private declare [HELPERS]: TypeHelpers;

/** @ts-expect-error We're exposing methods in the end-users namespace of keys */
[key: string]: T;
Expand Down
28 changes: 13 additions & 15 deletions packages/realm/src/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export class List<T = unknown> extends OrderedCollection<T> implements Partially
* The representation in the binding.
* @internal
*/
public internal!: binding.List;
public declare internal: binding.List;

/** @internal */
private isEmbedded!: boolean;
private declare isEmbedded: boolean;

/** @internal */
constructor(realm: Realm, internal: binding.List, helpers: OrderedCollectionHelpers) {
Expand All @@ -57,19 +57,17 @@ export class List<T = unknown> extends OrderedCollection<T> implements Partially
const isEmbedded =
baseType === binding.PropertyType.Object && internal.objectSchema.tableType === binding.TableType.Embedded;

Object.defineProperties(this, {
internal: {
enumerable: false,
configurable: false,
writable: false,
value: internal,
},
isEmbedded: {
enumerable: false,
configurable: false,
writable: false,
value: isEmbedded,
},
Object.defineProperty(this, "internal", {
enumerable: false,
configurable: false,
writable: false,
value: internal,
});
Object.defineProperty(this, "isEmbedded", {
enumerable: false,
configurable: false,
writable: false,
value: isEmbedded,
});
}

Expand Down
Loading

0 comments on commit f2a2fc6

Please sign in to comment.