diff --git a/packages/realm/src/Collection.ts b/packages/realm/src/Collection.ts index aabc2ce7a8..e7b1f36e99 100644 --- a/packages/realm/src/Collection.ts +++ b/packages/realm/src/Collection.ts @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// -import { CallbackRegistrator, IllegalConstructorError, Listeners, assert, binding } from "./internal"; +import { CallbackAdder, IllegalConstructorError, Listeners, assert, binding } from "./internal"; /** * Abstract base class containing methods shared by Realm **List**, **Dictionary**, and **Results**. @@ -46,13 +46,13 @@ export abstract class Collection< private listeners: Listeners; /** @internal */ - constructor(registerListener: CallbackRegistrator) { + constructor(addListener: CallbackAdder) { if (arguments.length === 0) { throw new IllegalConstructorError("Collection"); } this.listeners = new Listeners({ - register: registerListener, - unregister(token) { + add: addListener, + remove(token) { token.unregister(); }, }); diff --git a/packages/realm/src/Dictionary.ts b/packages/realm/src/Dictionary.ts index ab6202bfaa..eded2b2829 100644 --- a/packages/realm/src/Dictionary.ts +++ b/packages/realm/src/Dictionary.ts @@ -61,11 +61,11 @@ const PROXY_HANDLER: ProxyHandler = { } }, deleteProperty(target, prop) { - // We're intentionally not checking !Reflect.has(target, prop) below to allow deletes to propagage for any key + // We're intentionally not checking !Reflect.has(target, prop) below to allow deletes to propagate for any key if (typeof prop === "string") { const internal = target[INTERNAL]; internal.tryErase(prop); - // We consider any key without a value as "deleteable", the same way `const foo = {}; delete foo.bar;` returns true + // We consider any key without a value as "deletable", the same way `const foo = {}; delete foo.bar;` returns true return true; } else { return false; @@ -74,7 +74,6 @@ const PROXY_HANDLER: ProxyHandler = { ownKeys(target) { const internal = target[INTERNAL]; const result: (string | symbol)[] = Reflect.ownKeys(target); - // assert(internal.isValid, "Expected a valid dicitonary"); const keys = internal.keys.snapshot(); for (let i = 0; i < keys.size(); i++) { const key = keys.getAny(i); @@ -134,7 +133,7 @@ export class Dictionary extends Collection { throw err; }); @@ -269,9 +268,9 @@ export class Dictionary extends Collection = { }[keyof T]; /** - * Exchanges properties defined as Realm.List with an optional Array>. + * Exchanges properties defined as {@link List} with an optional {@link Array>}. */ type RealmListsRemappedModelPart = { [K in ExtractPropertyNamesOfType]?: T[K] extends List @@ -32,7 +32,7 @@ type RealmListsRemappedModelPart = { }; /** - * Exchanges properties defined as Realm.Dicionary with an optional key to mixed value object. + * Exchanges properties defined as {@link Dictionary} with an optional key to mixed value object. */ type RealmDictionaryRemappedModelPart = { [K in ExtractPropertyNamesOfType]?: T[K] extends Dictionary diff --git a/packages/realm/src/Listeners.ts b/packages/realm/src/Listeners.ts index e37cf94c0c..8d343e526f 100644 --- a/packages/realm/src/Listeners.ts +++ b/packages/realm/src/Listeners.ts @@ -17,16 +17,16 @@ //////////////////////////////////////////////////////////////////////////// /** @internal */ -export type CallbackRegistrator = ( +export type CallbackAdder = ( callback: CallbackType, ...args: Args ) => TokenType; /** @internal */ -export type CallbackUnregistrator = (token: TokenType) => void; +export type CallbackRemover = (token: TokenType) => void; export type ListenersOptions = { - register: CallbackRegistrator; - unregister: CallbackUnregistrator; + add: CallbackAdder; + remove: CallbackRemover; throwOnReAdd?: boolean; }; @@ -46,7 +46,7 @@ export class Listeners { } return; } - const token = this.options.register(callback, ...args); + const token = this.options.add(callback, ...args); // Store the notification token by the callback to enable later removal. this.listeners.set(callback, token); } @@ -54,14 +54,14 @@ export class Listeners { remove(callback: CallbackType): void { const token = this.listeners.get(callback); if (typeof token !== "undefined") { - this.options.unregister(token); + this.options.remove(token); this.listeners.delete(callback); } } removeAll(): void { for (const [, token] of this.listeners) { - this.options.unregister(token); + this.options.remove(token); } this.listeners.clear(); } diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index e42ae9a3a2..def3c41188 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -271,9 +271,9 @@ export class RealmObject { } /** - * The plain object representation of this object for JSON serialization. - * Use circular JSON serialization libraries such as {@link https://www.npmjs.com/package/@ungap/structured-clone @ungap/structured-clone} - * and {@link https://www.npmjs.com/package/flatted flatted} for stringifying Realm entities that have circular structures. + * The plain object representation for JSON serialization. + * Use circular JSON serialization libraries such as [@ungap/structured-clone](https://www.npmjs.com/package/@ungap/structured-clone) + * and [flatted](https://www.npmjs.com/package/flatted) to stringify Realm entities that have circular structures. * @returns A plain object. **/ toJSON(_?: string, cache?: unknown): DefaultObject; @@ -366,7 +366,7 @@ export class RealmObject { /** * @deprecated - * TODO: Remove completely once the type tests are obandend. + * TODO: Remove completely once the type tests are abandoned. */ _objectId(): string { throw new Error("This is now removed!"); diff --git a/packages/realm/src/ObjectListeners.ts b/packages/realm/src/ObjectListeners.ts index a0b80377c1..7b3cf97c0a 100644 --- a/packages/realm/src/ObjectListeners.ts +++ b/packages/realm/src/ObjectListeners.ts @@ -35,7 +35,7 @@ export class ObjectListeners { private properties: PropertyMap; private listeners = new Listeners, binding.NotificationToken>({ - register: (callback) => { + add: (callback) => { const token = this.notifier.addCallback((changes) => { try { callback(this.object as RealmObject & T, { @@ -53,7 +53,7 @@ export class ObjectListeners { // Get an actual NotificationToken for the bigint value return binding.NotificationToken.forObject(this.notifier, token); }, - unregister(token) { + remove(token) { token.unregister(); }, }); diff --git a/packages/realm/src/OrderedCollection.ts b/packages/realm/src/OrderedCollection.ts index 5cb43b6d80..1576eaa36a 100644 --- a/packages/realm/src/OrderedCollection.ts +++ b/packages/realm/src/OrderedCollection.ts @@ -123,7 +123,7 @@ export abstract class OrderedCollection { throw err; }); @@ -191,14 +191,15 @@ export abstract class OrderedCollection; @@ -356,7 +357,7 @@ export abstract class OrderedCollection(this: A, depth?: D): FlatArray[]; - flat(depth?: D): FlatArray[] { + flat(): FlatArray[] { throw new Error("Method not implemented."); } at(index: number) { @@ -588,11 +589,11 @@ export abstract class OrderedCollection((arg) => typeof arg === "string" ? [arg, true] : [arg[0], !arg[1]], ); - // TODO: Call `parent.sort`, avoiding property name to colkey conversion to speed up performance here. + // TODO: Call `parent.sort`, avoiding property name to column key conversion to speed up performance here. const results = parent.sortByNames(descriptors); return new Results(realm, results, helpers); } else if (typeof arg0 === "string") { diff --git a/packages/realm/src/ProgressRealmPromise.ts b/packages/realm/src/ProgressRealmPromise.ts index 41bc764a75..0795404c7a 100644 --- a/packages/realm/src/ProgressRealmPromise.ts +++ b/packages/realm/src/ProgressRealmPromise.ts @@ -16,7 +16,6 @@ // //////////////////////////////////////////////////////////////////////////// -import { Helpers } from "./binding"; import { Configuration, OpenRealmBehaviorType, @@ -31,27 +30,27 @@ import { validateConfiguration, } from "./internal"; -type OpenBehaviour = { - openBehaviour: OpenRealmBehaviorType; +type OpenBehavior = { + openBehavior: OpenRealmBehaviorType; timeOut?: number; timeOutBehavior?: OpenRealmTimeOutBehavior; }; -function determineBehaviour(config: Configuration): OpenBehaviour { +function determineBehavior(config: Configuration): OpenBehavior { const { sync } = config; if (!sync) { - return { openBehaviour: OpenRealmBehaviorType.OpenImmediately }; + return { openBehavior: OpenRealmBehaviorType.OpenImmediately }; } else { const configProperty = Realm.exists(config) ? "existingRealmFileBehavior" : "newRealmFileBehavior"; - const configBehaviour = sync[configProperty]; - if (configBehaviour) { - const { type, timeOut, timeOutBehavior } = configBehaviour; + const configBehavior = sync[configProperty]; + if (configBehavior) { + const { type, timeOut, timeOutBehavior } = configBehavior; if (typeof timeOut !== "undefined") { assert.number(timeOut, "timeOut"); } - return { openBehaviour: type, timeOut, timeOutBehavior }; + return { openBehavior: type, timeOut, timeOutBehavior }; } else { - return { openBehaviour: OpenRealmBehaviorType.DownloadBeforeOpen }; // Default is downloadBeforeOpen + return { openBehavior: OpenRealmBehaviorType.DownloadBeforeOpen }; // Default is downloadBeforeOpen } } } @@ -70,11 +69,11 @@ export class ProgressRealmPromise implements Promise { constructor(config: Configuration) { try { validateConfiguration(config); - const { openBehaviour, timeOut, timeOutBehavior } = determineBehaviour(config); - if (openBehaviour === OpenRealmBehaviorType.OpenImmediately) { + const { openBehavior: openBehavior, timeOut, timeOutBehavior } = determineBehavior(config); + if (openBehavior === OpenRealmBehaviorType.OpenImmediately) { const realm = new Realm(config); this.handle.resolve(realm); - } else if (openBehaviour === OpenRealmBehaviorType.DownloadBeforeOpen) { + } else if (openBehavior === OpenRealmBehaviorType.DownloadBeforeOpen) { const { bindingConfig } = Realm.transformConfig(config); this.task = binding.Realm.getSynchronizedRealm(bindingConfig); this.task @@ -123,7 +122,7 @@ export class ProgressRealmPromise implements Promise { } } } else { - throw new Error(`Unexpected open behaviour '${openBehaviour}'`); + throw new Error(`Unexpected open behavior '${openBehavior}'`); } } catch (err) { this.handle.reject(err); diff --git a/packages/realm/src/PromiseHandle.ts b/packages/realm/src/PromiseHandle.ts index 39e7a65718..38e28104ba 100644 --- a/packages/realm/src/PromiseHandle.ts +++ b/packages/realm/src/PromiseHandle.ts @@ -33,7 +33,7 @@ export class PromiseHandle { }; this.reject = arg1; }); - assert(this.resolve, "Expected promise executor to be called synchroniously"); - assert(this.reject, "Expected promise executor to be called synchroniously"); + assert(this.resolve, "Expected promise executor to be called synchronously"); + assert(this.reject, "Expected promise executor to be called synchronously"); } } diff --git a/packages/realm/src/Realm.ts b/packages/realm/src/Realm.ts index 60666c3b49..ba6ab77fcc 100644 --- a/packages/realm/src/Realm.ts +++ b/packages/realm/src/Realm.ts @@ -273,7 +273,7 @@ export class Realm { * * This is only implemented for React Native. * - * @throws {@link Error} If an I/O error occured or method is not implemented. + * @throws {@link Error} If an I/O error occurred or method is not implemented. */ public static copyBundledRealmFiles() { fs.copyBundledRealmFiles(); @@ -608,7 +608,7 @@ export class Realm { * remain unchanged. * - UpdateMode.Modified: If an existing object exists, only properties where the value has actually changed will be * updated. This improves notifications and server side performance but also have implications for how changes - * across devices are merged. For most use cases, the behaviour will match the intuitive behaviour of how + * across devices are merged. For most use cases, the behavior will match the intuitive behavior of how * changes should be merged, but if updating an entire object is considered an atomic operation, this mode * should not be used. */ @@ -724,7 +724,6 @@ export class Realm { const value = properties.get(objectSchema.primaryKey).toBinding(primaryKey, undefined); try { const objKey = table.findPrimaryKey(value); - // This relies on the JS represenation of an ObjKey being a bigint if (binding.isEmptyObjKey(objKey)) { return null; } else { @@ -816,7 +815,7 @@ export class Realm { } /** - * Remove the listener {@link callback} for the specfied event {@link eventName}. + * Remove the listener {@link callback} for the specified event {@link eventName}. * @param eventName The event name. * @param callback Function that was previously added as a listener for this event through the {@link addListener} method. * @throws {@link Error} If an invalid event {@link eventName} is supplied, if Realm is closed or if {@link callback} is not a function. diff --git a/packages/realm/src/TypeHelpers.ts b/packages/realm/src/TypeHelpers.ts index 4f7b089487..2ec6464f8c 100644 --- a/packages/realm/src/TypeHelpers.ts +++ b/packages/realm/src/TypeHelpers.ts @@ -75,7 +75,7 @@ export type TypeOptions = { getClassHelpers(nameOrTableKey: string | binding.TableKey): ClassHelpers; }; -// TODO: Consider testing for expected object instance types and throw something simular to the legacy SDK: +// TODO: Consider testing for expected object instance types and throw something similar to the legacy SDK: // "Only Realm instances are supported." (which should probably have been "Realm.Object") // instead of relying on the binding to throw. export function mixedToBinding(realm: binding.Realm, value: unknown): binding.MixedArg { diff --git a/packages/realm/src/app-services/App.ts b/packages/realm/src/app-services/App.ts index af4c247539..a647033833 100644 --- a/packages/realm/src/app-services/App.ts +++ b/packages/realm/src/app-services/App.ts @@ -82,10 +82,10 @@ export class App { public userAgent = `RealmJS/${App.SDK_VERSION} (${App.PLATFORM_CONTEXT}, ${App.PLATFORM_OS}, v${App.PLATFORM_VERSION})`; private listeners = new Listeners({ - register: (callback: () => void): AppListenerToken => { + add: (callback: () => void): AppListenerToken => { return this.internal.subscribe(callback); }, - unregister: (token) => { + remove: (token) => { this.internal.unsubscribe(token); }, }); diff --git a/packages/realm/src/app-services/Credentials.ts b/packages/realm/src/app-services/Credentials.ts index ba8df17b0a..527a49553b 100644 --- a/packages/realm/src/app-services/Credentials.ts +++ b/packages/realm/src/app-services/Credentials.ts @@ -16,9 +16,12 @@ // //////////////////////////////////////////////////////////////////////////// -import { AppCredentials, GoogleIdToken } from "../binding"; -import { assert, binding } from "../internal"; -import { App } from "./App"; +import { + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used by TS docs + App, + assert, + binding, +} from "../internal"; /** * Types of an authentication provider. @@ -50,9 +53,9 @@ export class Credentials { /** * Creates credentials for an anonymous user. These can only be used once - using them a second * time will result in a different user being logged in. If you need to get a user that has already logged - * in with the Anonymous credentials, use {@linkcode App.currentUser} or {@linkcode App.allUsers}. + * in with the Anonymous credentials, use {@link App.currentUser} or {@link App.allUsers}. * @param reuse Reuse any existing anonymous user already logged in. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link App.logIn}. */ static anonymous(reuse = true): Credentials { return new Credentials(binding.AppCredentials.anonymous(reuse)); @@ -60,7 +63,7 @@ export class Credentials { /** * Creates credentials based on a login with an email address and a password. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link App.logIn}. */ static emailPassword(credentials: { email: string; password: string }): Credentials; static emailPassword(email: string, password: string): Credentials; @@ -78,7 +81,7 @@ export class Credentials { /** * Creates credentials from an API key. * @param key A string identifying the API key. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link Realm.App.logIn}. */ static apiKey(key: string): Credentials { return new Credentials(binding.AppCredentials.userApiKey(key)); @@ -87,7 +90,7 @@ export class Credentials { /** * Creates credentials based on an Apple login. * @param token An Apple authentication token, obtained by logging into Apple. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link Realm.App.logIn}. */ static apple(token: string): Credentials { return new Credentials(binding.AppCredentials.apple(token)); @@ -96,7 +99,7 @@ export class Credentials { /** * Creates credentials based on a Facebook login. * @param token A Facebook authentication token, obtained by logging into Facebook. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link Realm.App.logIn}. */ static facebook(token: string): Credentials { return new Credentials(binding.AppCredentials.facebook(token)); @@ -105,7 +108,7 @@ export class Credentials { /** * Creates credentials based on a Google login. * @param authObject An object with either an `authCode` or `idToken` property. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link Realm.App.logIn}. */ static google(authObject: object): Credentials { return new Credentials(binding.AppCredentials.googleAuth(authObject)); @@ -114,7 +117,7 @@ export class Credentials { /** * Creates credentials with a JSON Web Token (JWT) provider and user identifier. * @param token A string identifying the user. Usually an identity token or a username. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link Realm.App.logIn}. */ static jwt(token: string): Credentials { return new Credentials(binding.AppCredentials.custom(token)); @@ -123,7 +126,7 @@ export class Credentials { /** * Creates credentials with an Atlas App Services function and user identifier. * @param payload An object identifying the user. Usually an identity token or a username. - * @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.App.logIn}. + * @return {Credentials} An instance of `Credentials` that can be used in {@link Realm.App.logIn}. */ static function(payload: object): Credentials { return new Credentials(binding.AppCredentials.function(payload as Record)); diff --git a/packages/realm/src/app-services/EmailPasswordAuthClient.ts b/packages/realm/src/app-services/EmailPasswordAuthClient.ts index 24e52d4b6d..c80d8e4fd0 100644 --- a/packages/realm/src/app-services/EmailPasswordAuthClient.ts +++ b/packages/realm/src/app-services/EmailPasswordAuthClient.ts @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// -import { binding, Realm } from "../internal"; +import { binding } from "../internal"; export class EmailPasswordAuthClient { /** @internal */ diff --git a/packages/realm/src/app-services/FunctionsFactory.ts b/packages/realm/src/app-services/FunctionsFactory.ts index 534de2aec0..8b028489d0 100644 --- a/packages/realm/src/app-services/FunctionsFactory.ts +++ b/packages/realm/src/app-services/FunctionsFactory.ts @@ -15,23 +15,6 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2022 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// import { User } from "../internal"; diff --git a/packages/realm/src/app-services/MongoClient.ts b/packages/realm/src/app-services/MongoClient.ts index 7d1bc63c20..21b711aea4 100644 --- a/packages/realm/src/app-services/MongoClient.ts +++ b/packages/realm/src/app-services/MongoClient.ts @@ -16,11 +16,11 @@ // //////////////////////////////////////////////////////////////////////////// -import { Document, EJSON } from "bson"; +import { Document } from "bson"; import { DefaultFunctionsFactory, User, binding, createFactory } from "../internal"; /** - * Options passed when finding a signle document + * Options passed when finding a single document */ type FindOneOptions = { /** @@ -46,7 +46,7 @@ type FindOptions = FindOneOptions & { }; /** - * Options passed when finding and modifying a signle document + * Options passed when finding and modifying a single document */ type FindOneAndModifyOptions = FindOneOptions & { /** diff --git a/packages/realm/src/app-services/PushClient.ts b/packages/realm/src/app-services/PushClient.ts index e1d056ebdc..f8fca39727 100644 --- a/packages/realm/src/app-services/PushClient.ts +++ b/packages/realm/src/app-services/PushClient.ts @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// -import { BSON, assert, binding } from "../internal"; +import { binding } from "../internal"; /** * Authentication provider where users identify using an API-key. */ diff --git a/packages/realm/src/app-services/SyncConfiguration.ts b/packages/realm/src/app-services/SyncConfiguration.ts index 306b1b0430..59b3346722 100644 --- a/packages/realm/src/app-services/SyncConfiguration.ts +++ b/packages/realm/src/app-services/SyncConfiguration.ts @@ -29,11 +29,11 @@ import { binding, toBindingClientResetMode, toBindingErrorHandler, - toBindingStopPolicy, - toBindingNotifyBeforeClientReset, - toBindingNotifyAfterClientReset, - toBindingNotifyAfterClientResetWithfallback, toBindingErrorHandlerWithOnManual, + toBindingNotifyAfterClientReset, + toBindingNotifyAfterClientResetWithFallback, + toBindingNotifyBeforeClientReset, + toBindingStopPolicy, } from "../internal"; export type PartitionValue = string | number | BSON.ObjectId | BSON.UUID | null; @@ -222,7 +222,7 @@ function parseRecoverUnsyncedChanges(clientReset: ClientResetRecoverUnsyncedChan clientResyncMode: toBindingClientResetMode(clientReset.mode), notifyBeforeClientReset: clientReset.onBefore ? toBindingNotifyBeforeClientReset(clientReset.onBefore) : undefined, notifyAfterClientReset: clientReset.onAfter - ? toBindingNotifyAfterClientResetWithfallback(clientReset.onAfter, clientReset.onFallback) + ? toBindingNotifyAfterClientResetWithFallback(clientReset.onAfter, clientReset.onFallback) : undefined, }; } @@ -233,7 +233,7 @@ function parseRecoverOrDiscardUnsyncedChanges(clientReset: ClientResetRecoverOrD clientResyncMode: toBindingClientResetMode(clientReset.mode), notifyBeforeClientReset: clientReset.onBefore ? toBindingNotifyBeforeClientReset(clientReset.onBefore) : undefined, notifyAfterClientReset: clientReset.onAfter - ? toBindingNotifyAfterClientResetWithfallback(clientReset.onAfter, clientReset.onFallback) + ? toBindingNotifyAfterClientResetWithFallback(clientReset.onAfter, clientReset.onFallback) : undefined, }; } diff --git a/packages/realm/src/app-services/SyncSession.ts b/packages/realm/src/app-services/SyncSession.ts index 7ca4f99be7..b201f391d1 100644 --- a/packages/realm/src/app-services/SyncSession.ts +++ b/packages/realm/src/app-services/SyncSession.ts @@ -19,10 +19,15 @@ import { EJSON } from "bson"; import { App, + ClientResetAfterCallback, + ClientResetBeforeCallback, + ClientResetError, + ClientResetFallbackCallback, ClientResetMode, ErrorCallback, Listeners, PartitionValue, + Realm, SessionStopPolicy, SyncConfiguration, TimeoutPromise, @@ -30,11 +35,6 @@ import { assert, binding, fromBindingSyncError, - ClientResetBeforeCallback, - Realm, - ClientResetAfterCallback, - ClientResetFallbackCallback, - ClientResetError, } from "../internal"; export enum ProgressDirection { @@ -85,7 +85,7 @@ function fromBindingConnectionState(state: binding.SyncSessionConnectionState) { } } -// TODO: This mapping is an interpretation of the behaviour of the legacy SDK we might want to revisit +// TODO: This mapping is an interpretation of the behavior of the legacy SDK we might want to revisit function fromBindingSessionState(state: binding.SyncSessionState) { if (state === binding.SyncSessionState.Inactive) { return SessionState.Inactive; @@ -124,10 +124,12 @@ export function toBindingErrorHandlerWithOnManual( } }); } - if (onError) { // onError gets all errors + if (onError) { + // onError gets all errors return toBindingErrorHandler(onError); } - if (onManual) { // onManual only gets ClientResetErrors + if (onManual) { + // onManual only gets ClientResetErrors return toBindingErrorHandler((session, error) => { if (error instanceof ClientResetError) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -152,7 +154,7 @@ export function toBindingNotifyAfterClientReset(onAfter: ClientResetAfterCallbac } /** @internal */ -export function toBindingNotifyAfterClientResetWithfallback( +export function toBindingNotifyAfterClientResetWithFallback( onAfter: ClientResetAfterCallback, onFallback: ClientResetFallbackCallback | undefined, ) { @@ -205,7 +207,7 @@ type ListenerToken = { /** * Progress listeners are shared across instances of the SyncSession, making it possible to deregister a listener on another session - * TODO: Consider adding a check to verify that the callback is removed from the correct SynsSession (although that would break the API) + * TODO: Consider adding a check to verify that the callback is removed from the correct SyncSession (although that would break the API) */ const PROGRESS_LISTENERS = new Listeners< ProgressNotificationCallback, @@ -213,7 +215,7 @@ const PROGRESS_LISTENERS = new Listeners< [binding.SyncSession, ProgressDirection, ProgressMode] >({ throwOnReAdd: true, - register(callback, internal, direction, mode) { + add(callback, internal, direction, mode) { const token = internal.registerProgressNotifier( (transferred, transferable) => callback(Number(transferred), Number(transferable)), toBindingDirection(direction), @@ -221,24 +223,24 @@ const PROGRESS_LISTENERS = new Listeners< ); return { internal, token }; }, - unregister({ internal, token }) { + remove({ internal, token }) { return internal.unregisterProgressNotifier(token); }, }); /** * Connection listeners are shared across instances of the SyncSession, making it possible to deregister a listener on another session - * TODO: Consider adding a check to verify that the callback is removed from the correct SynsSession (although that would break the API) + * TODO: Consider adding a check to verify that the callback is removed from the correct SyncSession (although that would break the API) */ const CONNECTION_LISTENERS = new Listeners({ throwOnReAdd: true, - register(callback, internal) { + add(callback, internal) { const token = internal.registerConnectionChangeCallback((oldState, newState) => callback(fromBindingConnectionState(newState), fromBindingConnectionState(oldState)), ); return { internal, token }; }, - unregister({ internal, token }) { + remove({ internal, token }) { internal.unregisterConnectionChangeCallback(token); }, }); diff --git a/packages/realm/src/app-services/User.ts b/packages/realm/src/app-services/User.ts index 19f1b0d6e8..474e355488 100644 --- a/packages/realm/src/app-services/User.ts +++ b/packages/realm/src/app-services/User.ts @@ -95,10 +95,10 @@ export class User< private cachedProfile: UserProfileDataType | undefined; private listeners = new Listeners({ - register: (callback: () => void): UserListenerToken => { + add: (callback: () => void): UserListenerToken => { return this.internal.subscribe(callback); }, - unregister: (token) => { + remove: (token) => { this.internal.unsubscribe(token); }, }); @@ -236,7 +236,7 @@ export class User< * @param credentials The credentials to use when linking. */ async linkCredentials(credentials: Credentials) { - throw new Error("Not yet implemented"); + await this.app.internal.linkUser(this.internal, credentials.internal); } /** diff --git a/packages/realm/src/binding.ts b/packages/realm/src/binding.ts index e8158cf511..be565168c5 100644 --- a/packages/realm/src/binding.ts +++ b/packages/realm/src/binding.ts @@ -67,5 +67,6 @@ export function stringToObjKey(input: string): ObjKey { } export function isEmptyObjKey(objKey: ObjKey) { + // This relies on the JS representation of an ObjKey being a bigint return (objKey as unknown as bigint) === -1n; } diff --git a/packages/realm/src/bson.ts b/packages/realm/src/bson.ts index 60947d2b84..dfa252587f 100644 --- a/packages/realm/src/bson.ts +++ b/packages/realm/src/bson.ts @@ -20,7 +20,7 @@ import * as bson from "bson"; /** - * A re-export of the "bson" package, enabling access to the BSON types without requiring an explict dependency on the "bson" package. + * A re-export of the "bson" package, enabling access to the BSON types without requiring an explicit dependency on the "bson" package. * * @see {@link https://www.npmjs.com/package/bson#documentation|the BSON documentation} for more information. * @memberof Realm diff --git a/packages/realm/src/internal.ts b/packages/realm/src/internal.ts index cfe07b3536..825d0ac2e2 100644 --- a/packages/realm/src/internal.ts +++ b/packages/realm/src/internal.ts @@ -16,7 +16,10 @@ // //////////////////////////////////////////////////////////////////////////// -// Following [the internal module pattern](https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de) +/** + * @module + * We're following [the internal module pattern](https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de) to control of the order of code when bundled. + */ /** @internal */ export * from "./debug"; diff --git a/packages/realm/src/platform/file-system.ts b/packages/realm/src/platform/file-system.ts index 9da0f7c881..2f97a2474d 100644 --- a/packages/realm/src/platform/file-system.ts +++ b/packages/realm/src/platform/file-system.ts @@ -48,17 +48,17 @@ export const fs: FileSystemType = { throw new Error("Not supported on this platform"); }, exists() { - throw new Error("Not supported on this playform"); + throw new Error("Not supported on this platform"); }, copyBundledRealmFiles() { - throw new Error("Not supported on this playform"); + throw new Error("Not supported on this platform"); }, removeDirectory() { throw new Error("Not supported on this platform"); }, /* readDirectory() { - throw new Error("Not supported on this playform"); + throw new Error("Not supported on this platform"); }, */ removeRealmFilesFromDirectory() { diff --git a/packages/realm/src/schema/from-binding.ts b/packages/realm/src/schema/from-binding.ts index c83e5567de..35624dff49 100644 --- a/packages/realm/src/schema/from-binding.ts +++ b/packages/realm/src/schema/from-binding.ts @@ -169,7 +169,7 @@ function fromBindingPropertyTypeName( if (!objectType) { throw new Error("Expected property with 'object' type to declare an objectType"); } - // TODO: Decide if this change is resonable + // TODO: Decide if this change is reasonable return { type: "object", objectType, optional: true }; // Implicitly nullable } else if (type === PropertyType.LinkingObjects) { if (!objectType) { diff --git a/packages/realm/src/schema/types.ts b/packages/realm/src/schema/types.ts index 1e75f4b10a..f4b15e9624 100644 --- a/packages/realm/src/schema/types.ts +++ b/packages/realm/src/schema/types.ts @@ -17,7 +17,8 @@ //////////////////////////////////////////////////////////////////////////// import { - Realm, // Used by TS docs + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used by TS docs + Realm, RealmObject, } from "../internal"; diff --git a/packages/realm/src/tests/milestone-2.test.ts b/packages/realm/src/tests/milestone-2.test.ts index ed30e744a2..09c75e2b82 100644 --- a/packages/realm/src/tests/milestone-2.test.ts +++ b/packages/realm/src/tests/milestone-2.test.ts @@ -85,9 +85,9 @@ describe("Milestone #2", () => { it("returns a spreadable object", function (this: RealmContext) { const alice = this.realm.objectForPrimaryKey("Person", "Alice"); expect(alice.keys()).deep.equals(["name", "bestFriend"]); - const spreaded = { ...alice }; - expect(Object.keys(spreaded)).deep.equals(alice.keys()); - expect(spreaded.name).deep.equals(alice.name); + const spread = { ...alice }; + expect(Object.keys(spread)).deep.equals(alice.keys()); + expect(spread.name).deep.equals(alice.name); }); }); @@ -260,8 +260,8 @@ describe("Milestone #2", () => { const persons = this.realm.objects("Person"); expect(persons).instanceOf(Results); expect(persons.length).greaterThan(0); - const spreaded = { ...persons }; - expect(Object.keys(spreaded)); + const spread = { ...persons }; + expect(Object.keys(spread)); }); }); }); diff --git a/packages/realm/src/tests/milestone-3.test.ts b/packages/realm/src/tests/milestone-3.test.ts index 9e9a728a79..2c319a0ac6 100644 --- a/packages/realm/src/tests/milestone-3.test.ts +++ b/packages/realm/src/tests/milestone-3.test.ts @@ -18,7 +18,7 @@ import { expect } from "chai"; -import { CollectionChangeSet, ObjectChangeSet, Realm, Results } from "../index"; +import { ObjectChangeSet, Realm, Results } from "../index"; import { RealmContext, closeRealm, generateTempRealmPath } from "./utils"; describe("Milestone #3", () => { @@ -170,14 +170,14 @@ describe("Milestone #3", () => { } alice.addListener(foo); alice.addListener(foo); - // Make a change to fire the listerner + // Make a change to fire the listener realm.write(() => (alice.name = "Alison")); // Begin a new write transaction to ensure the read transaction gets advanced realm.beginTransaction(); realm.cancelTransaction(); // Expect initial event + change expect(fooCalls).equals(2); - // Make another change to fire the listerner + // Make another change to fire the listener realm.write(() => (alice.name = "Alison!")); // Begin a new write transaction to ensure the read transaction gets advanced realm.beginTransaction(); @@ -362,14 +362,14 @@ describe("Milestone #3", () => { } persons.addListener(foo); persons.addListener(foo); - // Make a change to fire the listerner + // Make a change to fire the listener realm.write(() => (alice.name = "Alison")); // Begin a new write transaction to ensure the read transaction gets advanced realm.beginTransaction(); realm.cancelTransaction(); // Expect initial event + change expect(fooCalls).equals(2); - // Make another change to fire the listerner + // Make another change to fire the listener realm.write(() => (alice.name = "Alison!")); // Begin a new write transaction to ensure the read transaction gets advanced realm.beginTransaction(); diff --git a/packages/realm/src/tests/milestone-4.test.ts b/packages/realm/src/tests/milestone-4.test.ts index 2d9e0b478c..c2e5c962d9 100644 --- a/packages/realm/src/tests/milestone-4.test.ts +++ b/packages/realm/src/tests/milestone-4.test.ts @@ -52,7 +52,7 @@ describe("Milestone #4", () => { expect(person.name).equals("Alice"); }); - it("filters on placeholded strings", function (this: RealmContext) { + it("filters on placeholder strings", function (this: RealmContext) { const results = this.realm.objects("Person").filtered("name == $0", "Alice"); expect(results).instanceOf(Realm.Results); expect(results.length).equals(1); @@ -60,7 +60,7 @@ describe("Milestone #4", () => { expect(person.name).equals("Alice"); }); - it("filters on placeholded ints", function (this: RealmContext) { + it("filters on placeholder ints", function (this: RealmContext) { const results = this.realm.objects("Person").filtered("age > $0", 10); expect(results).instanceOf(Realm.Results); expect(results.length).equals(2); diff --git a/packages/realm/src/tests/milestone-5.test.ts b/packages/realm/src/tests/milestone-5.test.ts index ec4ab1053b..5c92a3ccf0 100644 --- a/packages/realm/src/tests/milestone-5.test.ts +++ b/packages/realm/src/tests/milestone-5.test.ts @@ -158,7 +158,8 @@ const TESTS: PropertySuite[] = [ ], ["bool", [true, false]], ["string", ["", "Hello!", "💣💥"]], - [ "data", + [ + "data", [ [createArrayBuffer, testArrayBuffer], [createEmptyArrayBuffer, testArrayBuffer], diff --git a/packages/realm/src/tests/schema-normalization.test.ts b/packages/realm/src/tests/schema-normalization.test.ts index ae97bf5df8..1853d028f3 100644 --- a/packages/realm/src/tests/schema-normalization.test.ts +++ b/packages/realm/src/tests/schema-normalization.test.ts @@ -950,7 +950,9 @@ function itNormalizes( expected: Partial, { isPrimaryKey } = { isPrimaryKey: false }, ): void { - it(`normalizes ${inspect(input, { compact: true, breakLength: Number.MAX_SAFE_INTEGER })} ${isPrimaryKey ? "(primary key)" : ""}`, () => { + it(`normalizes ${inspect(input, { compact: true, breakLength: Number.MAX_SAFE_INTEGER })} ${ + isPrimaryKey ? "(primary key)" : "" + }`, () => { const result = normalizePropertySchema({ objectName: OBJECT_NAME, propertyName: PROPERTY_NAME, @@ -979,7 +981,9 @@ function itThrowsWhenNormalizing( errMessage: string, { isPrimaryKey } = { isPrimaryKey: false }, ): void { - it(`throws when normalizing ${inspect(input, { compact: true, breakLength: Number.MAX_SAFE_INTEGER })} ${isPrimaryKey ? "(primary key)" : ""}`, () => { + it(`throws when normalizing ${inspect(input, { compact: true, breakLength: Number.MAX_SAFE_INTEGER })} ${ + isPrimaryKey ? "(primary key)" : "" + }`, () => { const normalizeFn = () => normalizePropertySchema({ objectName: OBJECT_NAME,