Skip to content

Commit

Permalink
Corrected spelling mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Jan 20, 2023
1 parent 8ab4df0 commit 789a688
Show file tree
Hide file tree
Showing 31 changed files with 133 additions and 137 deletions.
8 changes: 4 additions & 4 deletions packages/realm/src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down Expand Up @@ -46,13 +46,13 @@ export abstract class Collection<
private listeners: Listeners<ChangeCallbackType, binding.NotificationToken>;

/** @internal */
constructor(registerListener: CallbackRegistrator<ChangeCallbackType, binding.NotificationToken>) {
constructor(addListener: CallbackAdder<ChangeCallbackType, binding.NotificationToken>) {
if (arguments.length === 0) {
throw new IllegalConstructorError("Collection");
}
this.listeners = new Listeners<ChangeCallbackType, binding.NotificationToken>({
register: registerListener,
unregister(token) {
add: addListener,
remove(token) {
token.unregister();
},
});
Expand Down
13 changes: 6 additions & 7 deletions packages/realm/src/Dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ const PROXY_HANDLER: ProxyHandler<Dictionary> = {
}
},
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;
Expand All @@ -74,7 +74,6 @@ const PROXY_HANDLER: ProxyHandler<Dictionary> = {
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);
Expand Down Expand Up @@ -134,7 +133,7 @@ export class Dictionary<T = unknown> extends Collection<string, T, [string, T],
});
} catch (err) {
// Scheduling a throw on the event loop,
// since throwing synchroniously here would result in an abort in the calling C++
// since throwing synchronously here would result in an abort in the calling C++
setImmediate(() => {
throw err;
});
Expand Down Expand Up @@ -269,9 +268,9 @@ export class Dictionary<T = unknown> extends Collection<string, T, [string, T],
}

/**
* The plain object representation of the Dictionary 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.
**/
// @ts-expect-error We're exposing methods in the users value namespace
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/src/InsertionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ExtractPropertyNamesOfType<T, PropType> = {
}[keyof T];

/**
* Exchanges properties defined as Realm.List<Model> with an optional Array<Model | RealmInsertionModel<Model>>.
* Exchanges properties defined as {@link List<T>} with an optional {@link Array<T | RealmInsertionModel<T>>}.
*/
type RealmListsRemappedModelPart<T> = {
[K in ExtractPropertyNamesOfType<T, List>]?: T[K] extends List<infer GT>
Expand All @@ -32,7 +32,7 @@ type RealmListsRemappedModelPart<T> = {
};

/**
* Exchanges properties defined as Realm.Dicionary<Model> with an optional key to mixed value object.
* Exchanges properties defined as {@link Dictionary<T>} with an optional key to mixed value object.
*/
type RealmDictionaryRemappedModelPart<T> = {
[K in ExtractPropertyNamesOfType<T, Dictionary>]?: T[K] extends Dictionary<infer ValueType>
Expand Down
14 changes: 7 additions & 7 deletions packages/realm/src/Listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
////////////////////////////////////////////////////////////////////////////

/** @internal */
export type CallbackRegistrator<CallbackType, TokenType, Args extends unknown[] = []> = (
export type CallbackAdder<CallbackType, TokenType, Args extends unknown[] = []> = (
callback: CallbackType,
...args: Args
) => TokenType;
/** @internal */
export type CallbackUnregistrator<TokenType> = (token: TokenType) => void;
export type CallbackRemover<TokenType> = (token: TokenType) => void;

export type ListenersOptions<CallbackType, TokenType, Args extends unknown[]> = {
register: CallbackRegistrator<CallbackType, TokenType, Args>;
unregister: CallbackUnregistrator<TokenType>;
add: CallbackAdder<CallbackType, TokenType, Args>;
remove: CallbackRemover<TokenType>;
throwOnReAdd?: boolean;
};

Expand All @@ -46,22 +46,22 @@ export class Listeners<CallbackType, TokenType, Args extends unknown[] = []> {
}
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);
}

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();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/realm/src/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ export class RealmObject<T = DefaultObject> {
}

/**
* 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;
Expand Down Expand Up @@ -366,7 +366,7 @@ export class RealmObject<T = DefaultObject> {

/**
* @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!");
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/src/ObjectListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ObjectListeners<T> {
private properties: PropertyMap;

private listeners = new Listeners<ObjectChangeCallback<T>, binding.NotificationToken>({
register: (callback) => {
add: (callback) => {
const token = this.notifier.addCallback((changes) => {
try {
callback(this.object as RealmObject<T> & T, {
Expand All @@ -53,7 +53,7 @@ export class ObjectListeners<T> {
// Get an actual NotificationToken for the bigint value
return binding.NotificationToken.forObject(this.notifier, token);
},
unregister(token) {
remove(token) {
token.unregister();
},
});
Expand Down
17 changes: 9 additions & 8 deletions packages/realm/src/OrderedCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export abstract class OrderedCollection<T = unknown, EntryType extends [unknown,
});
} catch (err) {
// Scheduling a throw on the event loop,
// since throwing synchroniously here would result in an abort in the calling C++
// since throwing synchronously here would result in an abort in the calling C++
setImmediate(() => {
throw err;
});
Expand Down Expand Up @@ -191,14 +191,15 @@ export abstract class OrderedCollection<T = unknown, EntryType extends [unknown,
* @param value The value
* @internal
*/
public set(index: number, value: unknown) {
public set(index: number, value: T): void;
public set() {
throw new Error(`Assigning into a ${this.constructor.name} is not support`);
}

/**
* The plain array representation of the collection 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 An array of plain objects.
**/
toJSON(_?: string, cache?: unknown): Array<DefaultObject>;
Expand Down Expand Up @@ -356,7 +357,7 @@ export abstract class OrderedCollection<T = unknown, EntryType extends [unknown,
return [...this].flatMap(callback, thisArg);
}
flat<A, D extends number = 1>(this: A, depth?: D): FlatArray<A, D>[];
flat<D extends number = 1>(depth?: D): FlatArray<this, D>[] {
flat<D extends number = 1>(): FlatArray<this, D>[] {
throw new Error("Method not implemented.");
}
at(index: number) {
Expand Down Expand Up @@ -588,11 +589,11 @@ export abstract class OrderedCollection<T = unknown, EntryType extends [unknown,
if (Array.isArray(arg0)) {
assert(typeof arg1 === "undefined", "Second argument is not allowed if passed an array of sort descriptors");
const { results: parent, realm, helpers } = this;
// Map optional "reversed" to "accending" (expected by the binding)
// Map optional "reversed" to "ascending" (expected by the binding)
const descriptors = arg0.map<[string, boolean]>((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") {
Expand Down
27 changes: 13 additions & 14 deletions packages/realm/src/ProgressRealmPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//
////////////////////////////////////////////////////////////////////////////

import { Helpers } from "./binding";
import {
Configuration,
OpenRealmBehaviorType,
Expand All @@ -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
}
}
}
Expand All @@ -70,11 +69,11 @@ export class ProgressRealmPromise implements Promise<Realm> {
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
Expand Down Expand Up @@ -123,7 +122,7 @@ export class ProgressRealmPromise implements Promise<Realm> {
}
}
} else {
throw new Error(`Unexpected open behaviour '${openBehaviour}'`);
throw new Error(`Unexpected open behavior '${openBehavior}'`);
}
} catch (err) {
this.handle.reject(err);
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/src/PromiseHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PromiseHandle<T> {
};
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");
}
}
7 changes: 3 additions & 4 deletions packages/realm/src/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/realm/src/TypeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/src/app-services/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppChangeCallback, AppListenerToken>({
register: (callback: () => void): AppListenerToken => {
add: (callback: () => void): AppListenerToken => {
return this.internal.subscribe(callback);
},
unregister: (token) => {
remove: (token) => {
this.internal.unsubscribe(token);
},
});
Expand Down
Loading

0 comments on commit 789a688

Please sign in to comment.