Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
kneth committed Jan 30, 2024
1 parent 37ac180 commit 276dc67
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
8 changes: 5 additions & 3 deletions integration-tests/tests/src/tests/shared-realms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
////////////////////////////////////////////////////////////////////////////

import { expect } from "chai";
import Realm, { LogCategory } from "realm";
import Realm, { LogCategory, LogArgs, LoggerCallbackArgs } from "realm";

import { openRealmBefore, openRealmBeforeEach } from "../hooks";
import { createLocalConfig } from "../utils/open-realm";
Expand All @@ -32,10 +32,12 @@ describe("SharedRealm operations", () => {
};
let logs: Log[] = [];

Realm.setLogger(({ category, level, message }) => {
const logger = (args: LoggerCallbackArgs) => {
const { category, level, message } = args;
logs.push({ category, level, message });
});
};

Realm.setLogger(logger);
Realm.setLogLevel({ category: LogCategory.Realm, level: "all" });

const realm = await Realm.open({
Expand Down
8 changes: 5 additions & 3 deletions integration-tests/tests/src/tests/sync/sync-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
////////////////////////////////////////////////////////////////////////////

import { expect } from "chai";
import Realm, { ConnectionState, LogCategory, ObjectSchema, BSON, SyncConfiguration } from "realm";
import Realm, { ConnectionState, LogCategory, LoggerCallbackArgs, ObjectSchema, BSON, SyncConfiguration } from "realm";
import { importAppBefore } from "../../hooks";
import { DogSchema } from "../../schemas/person-and-dog-with-object-ids";
import { getRegisteredEmailPassCredentials } from "../../utils/credentials";
Expand Down Expand Up @@ -361,13 +361,15 @@ describe.skipIf(environment.missingServer, "SessionTest", () => {

const promisedLog = new Promise((resolve) => {
Realm.setLogLevel({ category: LogCategory.Realm, level: logLevelStr });
Realm.setLogger((category, level, message) => {
const logger = (args: LoggerCallbackArgs) => {
const { category, level, message } = args;
if (level == logLevelStr && message.includes("Connection") && message.includes("Session")) {
// we should, at some point, receive a log message that looks like
// Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, client reset = false
resolve(true);
}
});
};
Realm.setLogger(logger);
});

const user = await app.logIn(credentials);
Expand Down
8 changes: 8 additions & 0 deletions packages/realm/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export enum LogCategory {
SDK = "SDK",
}

/**
* Type for `Realm.setLogLevel`
*/
export type LogArgs = {
level: LogLevel;
category?: LogCategory;
};

/**
* A callback passed to `Realm.App.Sync.setLogger` when instrumenting the Atlas Device Sync client with a custom logger.
* @param level - The level of the log entry between 0 and 8 inclusively.
Expand Down
13 changes: 8 additions & 5 deletions packages/realm/src/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ import {
InvalidateEvent,
List,
LocalAppConfiguration,
LogArgs,
LogCategory,
LogLevel,
LoggerCallbackArgs,
LoggerCallback,
LoggerCallback1,
LoggerCallback2,
Expand Down Expand Up @@ -216,11 +218,6 @@ type ObjectSchemaExtra = {

export type RealmEventName = "change" | "schema" | "beforenotify";

export type LogArgs = {
level: LogLevel;
category?: LogCategory;
};

/**
* Asserts the event passed as string is a valid RealmEvent value.
* @throws A {@link TypeAssertionError} if an unexpected name is passed via {@link name}.
Expand Down Expand Up @@ -1421,6 +1418,8 @@ type UserType<
> = User<UserFunctionsType, UserCustomDataType, UserProfileDataType>;

type BaseSubscriptionSetType = BaseSubscriptionSet;
type LogArgsType = LogArgs;
type LoggerCallbackArgsType = LoggerCallbackArgs;
type LogCategoryType = LogCategory;
type LogLevelType = LogLevel;
type NumericLogLevelType = NumericLogLevel;
Expand Down Expand Up @@ -1530,6 +1529,8 @@ export declare namespace Realm {
FlexibleSyncConfiguration,
IndexDecoratorType as IndexDecorator,
ListType as List,
LogArgsType as LogArgs,
LoggerCallbackArgsType as LoggerCallbackArgs,
LogCategoryType as LogCategory,
LocalAppConfiguration,
MapToDecoratorType as MapToDecorator,
Expand Down Expand Up @@ -1758,6 +1759,8 @@ declare global {
IndexDecoratorType as IndexDecorator,
ListType as List,
LocalAppConfiguration,
LogArgsType as LogArgs,
LoggerCallbackArgsType as LoggerCallbackArgs,
LogCategoryType as LogCategory,
MapToDecoratorType as MapToDecorator,
MetadataModeType as MetadataMode,
Expand Down
2 changes: 2 additions & 0 deletions packages/realm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export {
List,
LocalAppConfiguration,
LoggerCallback,
LoggerCallbackArgs,
LogArgs,
LogCategory,
LogLevel,
mapTo,
Expand Down

0 comments on commit 276dc67

Please sign in to comment.