realm
Version:
Realm is a mobile database: an alternative to SQLite and key-value stores
856 lines (848 loc) • 208 kB
TypeScript
import * as bson from 'bson';
import { Timestamp, Long } from 'bson';
declare const flags: {
/**
* When enabled, objects can be created by providing an array of values (in the order that they were declared in the object schema) in addition to of an object of property values.
*/
ALLOW_VALUES_ARRAYS: boolean;
/**
* When enabled, accessing the `Realm` without first importing it from the Realm package, will throw.
* Helps finding places where the app is depending on the now deprecated way of using the package.
*/
THROW_ON_GLOBAL_REALM: boolean;
/**
* Enables calling internal, test-only functions like `Realm.clearTestState`.
* This is disabled by default, mainly because the data-structures needed to support this, introduce minor memory leaks if clearTestState() is not called regularly and are not intended for production use.
*/
ALLOW_CLEAR_TEST_STATE: boolean;
};
/**
* Re-export a subset 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.
*/
declare namespace BSON {
const ObjectId: typeof bson.ObjectID;
type ObjectId = bson.ObjectId;
const ObjectID: typeof bson.ObjectID;
type ObjectID = bson.ObjectID;
const Decimal128: typeof bson.Decimal128;
type Decimal128 = bson.Decimal128;
const UUID: typeof bson.UUID;
type UUID = bson.UUID;
const Binary: typeof bson.Binary;
type Binary = bson.Binary;
const EJSON: typeof bson.EJSON;
type EJSON = typeof bson.EJSON;
}
declare class AssertionError extends Error {
}
declare class TypeAssertionError extends AssertionError {
}
declare class SchemaParseError extends Error {
}
declare class ObjectSchemaParseError extends SchemaParseError {
objectName: string;
}
declare class PropertySchemaParseError extends SchemaParseError {
objectName: string;
propertyName: string;
}
/**
* An class describing a sync error.
*/
declare class SyncError extends Error {
name: string;
isOk: boolean;
/**
* The error code that represents this error.
*/
code?: number;
/**
* The category of this error.
* @deprecated
*/
category: string;
reason?: string;
/**
* The URL to the associated server log, if available. The string will be empty
* if the sync error is not initiated by the server.
*/
logUrl: string;
/**
* A record of extra user information associated with this error.
*/
userInfo: Record<string, string>;
/**
* @deprecated Check the error message instead.
*/
isFatal: boolean;
}
/**
* @deprecated Use the another {@link ClientResetMode} than {@link ClientResetMode.Manual}.
* @see https://github.com/realm/realm-js/blob/main/CHANGELOG.md#1110-2022-11-01
* @see https://github.com/realm/realm-js/issues/4135
*/
declare class ClientResetError extends SyncError {
name: string;
config: Configuration;
}
/**
* An error class that 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.
*/
declare class CompensatingWriteError extends SyncError {
/**
* The array of information about each object that caused the compensating write.
*/
writes: CompensatingWriteInfo[];
}
/**
* The details of a compensating write performed by the server.
*/
type CompensatingWriteInfo = {
/**
* The type of the object that caused the compensating write.
*/
objectName: string;
/**
* The reason for the compensating write.
*/
reason: string;
/**
* The primary key of the object that caused the compensating write.
*/
primaryKey: PrimaryKey;
};
type IndexDecorator = (target: unknown, memberName: string) => void;
/**
* Specify that the decorated field should be indexed by Realm.
* See: [documentation](https://www.mongodb.com/docs/realm/sdk/react-native/examples/define-a-realm-object-model/#index-a-property)
*/
declare const index: IndexDecorator;
type MapToDecorator = (propertyName: string) => (target: unknown, memberName: string) => void;
/**
* Specify that the decorated field should be remapped to a different property name in the Realm database.
* See: [documentation](https://www.mongodb.com/docs/realm/sdk/react-native/examples/define-a-realm-object-model/#remap-a-property)
* @param propertyName The name of the property in the Realm database
*/
declare const mapTo: MapToDecorator;
/**
* The update mode to use when creating an object that already exists.
*/
declare enum UpdateMode {
/**
* Objects are only created. If an existing object exists, an exception is thrown.
*/
Never = "never",
/**
* 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 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.
*/
Modified = "modified",
/**
* If an existing object is found, all properties provided will be updated,
* any other properties will remain unchanged.
*/
All = "all"
}
type AnyRealmObject = RealmObject<any>;
/**
* Base class for a Realm Object.
* @example
* To define a class `Person` with required `name` and `age`
* properties, define a `static schema`:
* ```
* class Person extends Realm.Object<Person> {
* _id!: Realm.BSON.ObjectId;
* name!: string;
* age!: number;
* static schema: Realm.ObjectSchema = {
* name: "Person",
* primaryKey: "_id",
* properties: {
* _id: "objectId",
* name: "string",
* age: "int",
* },
* };
* }
* ```
* @example
* If using the [@realm/babel-plugin](https://www.npmjs.com/package/@realm/babel-plugin):
* To define a class `Person` with required `name` and `age` properties, they would
* need to be specified in the type argument when it is being constructed to allow
* Typescript-only model definitions:
* ```
* class Person extends Realm.Object<Person, "name" | "age"> {
* _id = new Realm.Types.ObjectId();
* name: Realm.Types.String;
* age: Realm.Types.Int;
* static primaryKey = "_id";
* }
* ```
* @see {@link ObjectSchema}
* @typeParam `T` - The type of this class (e.g. if your class is `Person`,
* `T` should also be `Person` - this duplication is required due to how
* TypeScript works)
* @typeParam `RequiredProperties` - The names of any properties of this
* class which are required when an instance is constructed with `new`. Any
* properties not specified will be optional, and will default to a sensible
* null value if no default is specified elsewhere.
*/
declare class RealmObject<T = DefaultObject, RequiredProperties extends keyof OmittedRealmTypes<T> = never> {
static allowValuesArrays: boolean;
/**
* Optionally specify the primary key of the schema when using [@realm/babel-plugin](https://www.npmjs.com/package/@realm/babel-plugin).
*/
static primaryKey?: string;
/**
* Optionally specify that the schema is an embedded schema when using [@realm/babel-plugin](https://www.npmjs.com/package/@realm/babel-plugin).
*/
static embedded?: boolean;
/**
* Optionally specify that the schema should sync unidirectionally if using flexible sync when using [@realm/babel-plugin](https://www.npmjs.com/package/@realm/babel-plugin).
*/
static asymmetric?: boolean;
/**
* Create a `RealmObject` wrapping an `Obj` from the binding.
* @param realm - The Realm managing the object.
* @param values - The values of the object's properties at creation.
*/
constructor(realm: Realm, values: Unmanaged<T, RequiredProperties>);
/**
* @returns An array of the names of the object's properties.
* @deprecated Please use {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys | Object.keys()}
*/
keys(): string[];
/**
* @returns An array of key/value pairs of the object's properties.
* @deprecated Please use {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries | Object.entries()}
*/
entries(): [string, unknown][];
/**
* 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;
/**
* Checks if this object has not been deleted and is part of a valid Realm.
* @returns `true` if the object can be safely accessed, `false` if not.
*/
isValid(): boolean;
/**
* The schema for the type this object belongs to.
* @returns The {@link CanonicalObjectSchema} that describes this object.
*/
objectSchema(): CanonicalObjectSchema<T>;
/**
* Returns all the objects that link to this object in the specified relationship.
* @param objectType - The type of the objects that link to this object's type.
* @param propertyName - The name of the property that references objects of this object's type.
* @throws An {@link AssertionError} if the relationship is not valid.
* @returns The {@link Results} that link to this object.
*/
linkingObjects<T = DefaultObject>(objectType: string, propertyName: string): Results<RealmObject<T> & T>;
linkingObjects<T extends AnyRealmObject>(objectType: Constructor<T>, propertyName: string): Results<T>;
/**
* Returns the total count of incoming links to this object
* @returns The number of links to this object.
*/
linkingObjectsCount(): number;
/**
* @deprecated
* TODO: Remove completely once the type tests are abandoned.
*/
_objectId(): string;
/**
* A string uniquely identifying the object across all objects of the same type.
*/
_objectKey(): string;
/**
* Add a listener `callback` which will be called when a **live** object instance changes.
* @param callback - A function to be called when changes occur.
* @param callback.obj - The object that changed.
* @param callback.changes - A dictionary with information about the changes.
* @param callback.changes.deleted - Is `true` if the object has been deleted.
* @param callback.changes.changedProperties - An array of properties that have changed their value.
* @throws A {@link TypeAssertionError} if `callback` is not a function.
* @example
* wine.addListener((obj, changes) => {
* // obj === wine
* console.log(`object is deleted: ${changes.deleted}`);
* console.log(`${changes.changedProperties.length} properties have been changed:`);
* changes.changedProperties.forEach(prop => {
* console.log(` ${prop}`);
* });
* })
* @note Adding the listener is an asynchronous operation, so the callback is invoked the first time to notify the caller when the listener has been added.
* Thus, when the callback is invoked the first time it will contain empty array for `changes.changedProperties`.
*/
addListener(callback: ObjectChangeCallback<T>): void;
/**
* Remove the listener `callback` from this object.
* @throws A {@link TypeAssertionError} if `callback` is not a function.
* @param callback A function previously added as listener
*/
removeListener(callback: ObjectChangeCallback<T>): void;
/**
* Remove all listeners from this object.
*/
removeAllListeners(): void;
/**
* Get underlying type of a property value.
* @param propertyName - The name of the property to retrieve the type of.
* @throws An {@link Error} if property does not exist.
* @returns Underlying type of the property value.
*/
getPropertyType(propertyName: string): string;
}
type ObjectChangeSet<T> = {
deleted: boolean;
changedProperties: (keyof T)[];
};
type ObjectChangeCallback<T> = (object: RealmObject<T> & T, changes: ObjectChangeSet<T>) => void;
/**
* Abstract base class containing methods shared by Realm {@link List}, {@link Dictionary} and {@link Results}.
*
* A {@link Collection} always reflect the current state of the Realm. The one exception to this is
* when using `for...in` or `for...of` enumeration, which will always enumerate over the
* objects which matched the query when the enumeration is begun, even if some of them are
* deleted or modified to be excluded by the filter during the enumeration.
* @since 0.11.0
*/
declare abstract class Collection<KeyType = unknown, ValueType = unknown, EntryType = [KeyType, ValueType], T = ValueType, ChangeCallbackType = unknown> implements Iterable<T> {
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys Array.prototype.keys}
* @returns An iterator with all keys in the collection.
* @since 0.11.0
*/
abstract keys(): Iterable<KeyType>;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys Array.prototype.keys}
* @returns An iterator with all values in the collection.
* @since 0.11.0
*/
abstract values(): Iterable<ValueType>;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries Array.prototype.keys}
* @returns An iterator with all key/value pairs in the collection.
* @since 0.11.0
*/
abstract entries(): Iterable<EntryType>;
/**
* This is the same method as the {@link Collection.values} method.
* Its presence makes collections _iterable_, thus able to be used with ES6
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of `for-of`}
* loops,
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator `...`}
* spread operators, and more.
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator Symbol.iterator}
* and the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable iterable protocol}
* @returns An iterable of each value in the collection.
* @example
* for (let object of collection) {
* // do something with each object
* }
* @since 0.11.0
*/
abstract [Symbol.iterator](): Iterator<T>;
/**
* Checks if this collection has not been deleted and is part of a valid Realm.
* @returns `true` if the collection can be safely accessed.
* @since 0.14.0
*/
abstract isValid(): boolean;
/**
* Add a listener `callback` which will be called when a **live** collection instance changes.
* @param callback - A function to be called when changes occur.
* @param callback.collection - The collection instance that changed,
* @param callback.changes - An object with information about the changes.
* @param callback.changes.insertions - The indices in the collection where objects were inserted.
* @param callback.changes.newModifications - The indices in the collection where objects were modified.
* @param callback.changes.oldModifications - The indices in the collection where objects were modified.
* @param callback.changes.deletions - The indices in the collection where objects were deleted.
* @note `deletions and `oldModifications` report the indices in the collection before the change happened,
* while `insertions` and `newModifications` report the indices into the new version of the collection.
* @throws A {@link TypeAssertionError} if `callback` is not a function.
* @example
* wines.addListener((collection, changes) => {
* // collection === wines
* console.log(`${changes.insertions.length} insertions`);
* console.log(`${changes.oldModifications.length} oldModifications`);
* console.log(`${changes.newModifications.length} newModifications`);
* console.log(`${changes.deletions.length} deletions`);
* console.log(`new size of collection: ${collection.length}`);
* });
* @note Adding the listener is an asynchronous operation, so the callback is invoked the first time to notify the caller when the listener has been added.
* Thus, when the callback is invoked the first time it will contain empty arrays for each property in the `changes` object.
*/
addListener(callback: ChangeCallbackType): void;
/**
* Remove the listener `callback` from the collection instance.
* @param callback - Callback function that was previously
* added as a listener through the {@link Collection.addListener} method.
* @throws a {@link TypeAssertionError} If `callback` is not a function.
*/
removeListener(callback: ChangeCallbackType): void;
/**
* Remove all `callback` listeners from the collection instance.
*/
removeAllListeners(): void;
}
type PropertyType = string;
/**
* A sort descriptor is either a string containing one or more property names
* separate by dots or an array with two items: `[propertyName, reverse]`.
*/
type SortDescriptor = string | [string, boolean];
type CollectionChangeSet = {
insertions: number[];
deletions: number[];
newModifications: number[];
oldModifications: number[];
};
type CollectionChangeCallback<T = unknown, EntryType extends [unknown, unknown] = [unknown, unknown]> = (collection: OrderedCollection<T, EntryType>, changes: CollectionChangeSet) => void;
/**
* An {@link OrderedCollection} is a homogenous sequence of values of any of the types
* that can be stored as properties of Realm objects. It can be
* accessed in any of the ways that a normal JavaScript Array can, including
* subscripting, enumerating with `for-of` and so on.
* @see {@link https://mdn.io/Array | Array}
*/
declare abstract class OrderedCollection<T = unknown, EntryType extends [unknown, unknown] = [number, T]> extends Collection<number, T, EntryType, T, CollectionChangeCallback<T, EntryType>> implements Omit<ReadonlyArray<T>, "entries"> {
private mixedToBinding;
/**
* 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(): Array<DefaultObject>;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys | Array.prototype.keys()}
* @returns An iterator with all keys in the collection.
*/
keys(): Generator<number>;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values} | Array.prototype.values()}
* @returns An iterator with all values in the collection.
*/
values(): Generator<T>;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries | Array.prototype.entries()}
* @returns An iterator with all key/value pairs in the collection.
*/
entries(): Generator<EntryType>;
[n: number]: T;
/**
* @returns The number of values.
*/
get length(): number;
/**
* @throws An {@link Error} as the length property cannot be assigned.
*/
set length(value: number);
/**
* Name of the type of items.
* @returns The name of the type of values.
*/
get type(): PropertyType;
/**
* Whether `null` is a valid value for the collection.
* @returns Whether `null` is a valid value for the collection.
* @readonly
*/
get optional(): boolean;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString | Array.prototype.toString()}
* @returns A string representation of the collection.
*/
toString(): string;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString | Array.prototype.toLocaleString()}
* @returns A localized string representation of the collection.
*/
toLocaleString(): string;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat | Array.prototype.concat()}
* @param items - Arrays and/or values to concatenate into a new array.
* @returns A new array with the results of calling a provided function on every element in this array.
*/
concat(...items: ConcatArray<T>[]): T[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat | Array.prototype.concat()}
* @param items - Arrays and/or values to concatenate into a new array.
* @returns A new array with the results of calling a provided function on every element in this array.
*/
concat(...items: (T | ConcatArray<T>)[]): T[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join | Array.prototype.join()}
* @params separator - A string used to separate one element of the collection from the next in the resulting String.
* @returns A string representing the elements of the collection.
*/
join(separator?: string): string;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.slice()}
* @params start - Zero-based index at which to begin extraction.
* @params end - Zero-based index at which to end extraction. It extracts up to but not including `end`.
* @returns A new array containing the elements between the start and end indices.
*/
slice(start?: number, end?: number): T[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf | Array.prototype.indexOf()}
* @params searchElement - Element to locate in the collection.
* @params fromIndex - The collection index at which to begin the search. If omitted, the search starts at index 0.
* @note `fromIndex` is currently not supported. So all searches start at index 0.
* @returns The first index at which a given element can be found in the collection, or -1 if it is not present.
*/
indexOf(searchElement: T, fromIndex?: number): number;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf | Array.prototype.lastIndexOf()}
* @params searchElement - Element to locate in the collection.
* @params fromIndex - The collection index at which to begin the search. If omitted, the search starts at the last index.
* @returns The last index at which a given element can be found in the collection, or -1 if it is not present. The collection is searched backwards, starting at `fromIndex`.
*/
lastIndexOf(searchElement: T, fromIndex?: number): number;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.prototype.every()}
* @params predicate - A function to test for each element.
* @params predicate.value - The current element being processed in the collection.
* @params predicate.index - The index of the current element being processed in the collection.
* @params predicate.array - The collection `every` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the predicate function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns `true` if the callback function returns a truthy value for every collection element; otherwise, `false`.
*/
every<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): this is readonly S[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.prototype.every()}
* @params predicate - A function to test for each element.
* @params predicate.value - The current element being processed in the collection.
* @params predicate.index - The index of the current element being processed in the collection.
* @params predicate.array - The collection `every` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the predicate function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns `true` if the callback function returns a truthy value for every collection element; otherwise, `false`.
*/
every(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.prototype.some()}
* @params predicate - A function to test for each element.
* @params predicate.value - The current element being processed in the collection.
* @params predicate.index - The index of the current element being processed in the collection.
* @params predicate.array - The collection `every` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the predicate function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns `true` if the callback function returns a truthy value for any collection element; otherwise, `false`.
*/
some(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach | Array.prototype.forEach()}
* @params callbackfn - A function that accepts up to three arguments. `forEach` calls the callbackfn function one time for each element in the collection.
* @params callbackfn.value - The current element being processed in the collection.
* @params callbackfn.index - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `forEach` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the `callbackfn` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
*/
forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.prototype.map()}
* @params callbackfn - A function that accepts up to three arguments. The `map` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.value - The current element being processed in the collection.
* @params callbackfn.index - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `map` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the `callbackfn` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns A new array containing the results of calling the `callbackfn` function on each element in the collection.
*/
map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.prototype.filter()}
* @params predicate - A function that accepts up to three arguments. The `filter` method calls the `predicate` function one time for each element in the collection.
* @params predicate.value - The current element being processed in the collection.
* @params predicate.index - The index of the current element being processed in the collection.
* @params predicate.array - The collection `filter` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the `predicate` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns A new array containing the elements of the collection for which the `predicate` function returned `true`.
*/
filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.prototype.filter()}
* @params predicate - A function that accepts up to three arguments. The `filter` method calls the `predicate` function one time for each element in the collection.
* @params predicate.value - The current element being processed in the collection.
* @params predicate.index - The index of the current element being processed in the collection.
* @params predicate.array - The collection `filter` was called upon.
* @params thisArg - An object to which the `this` keyword can refer in the `predicate` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns A new array containing the elements of the collection for which the `predicate` function returned `true`.
*/
filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.prototype.reduce()}
* @params callbackfn - A function that accepts up to four arguments. The `reduce` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.previousValue - The value previously returned in the last invocation of the `callbackfn` function, or `initialValue`, if supplied. (See below.)
* @params callbackfn.currentValue - The current element being processed in the collection.
* @params callbackfn.currentIndex - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `reduce` was called upon.
* @params initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an element value.
* @returns The value that results from the reduction.
*/
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.prototype.reduce()}
* @params callbackfn - A function that accepts up to four arguments. The `reduce` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.previousValue - The value previously returned in the last invocation of the `callbackfn` function, or `initialValue`, if supplied. (See below.)
* @params callbackfn.currentValue - The current element being processed in the collection.
* @params callbackfn.currentIndex - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `reduce` was called upon.
* @params initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an element value.
* @returns The value that results from the reduction.
*/
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.prototype.reduce()}
* @params callbackfn - A function that accepts up to four arguments. The `reduce` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.previousValue - The value previously returned in the last invocation of the `callbackfn` function, or `initialValue`, if supplied. (See below.)
* @params callbackfn.currentValue - The current element being processed in the collection.
* @params callbackfn.currentIndex - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `reduce` was called upon.
* @params initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an element value.
* @returns The value that results from the reduction.
*/
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.prototype.reduceRight()}
* @params callbackfn - A function that accepts up to four arguments. The `reduceRight` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.previousValue - The value previously returned in the last invocation of the `callbackfn` function, or `initialValue`, if supplied. (See below.)
* @params callbackfn.currentValue - The current element being processed in the collection.
* @params callbackfn.currentIndex - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `reduceRight` was called upon.
* @params initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an element value.
* @returns The value that results from the reduction.
*/
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.prototype.reduceRight()}
* @params callbackfn - A function that accepts up to four arguments. The `reduceRight` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.previousValue - The value previously returned in the last invocation of the `callbackfn` function, or `initialValue`, if supplied. (See below.)
* @params callbackfn.currentValue - The current element being processed in the collection.
* @params callbackfn.currentIndex - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `reduceRight` was called upon.
* @params initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an element value.
* @returns The value that results from the reduction.
*/
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight | Array.prototype.reduceRight()}
* @params callbackfn - A function that accepts up to four arguments. The `reduceRight` method calls the `callbackfn` function one time for each element in the collection.
* @params callbackfn.previousValue - The value previously returned in the last invocation of the `callbackfn` function, or `initialValue`, if supplied. (See below.)
* @params callbackfn.currentValue - The current element being processed in the collection.
* @params callbackfn.currentIndex - The index of the current element being processed in the collection.
* @params callbackfn.array - The collection `reduceRight` was called upon.
* @params initialValue - If `initialValue` is specified, it is used as the initial value to start the accumulation. The first call to the `callbackfn` function provides this value as an argument instead of an element value.
* @returns The value that results from the reduction.
*/
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.prototype.find()}
* @params predicate - A function that accepts up to three arguments. The `find` method calls the `predicate` function one time for each element in the collection.
* @params predicate.value - The value of the element.
* @params predicate.index - The index of the element.
* @params predicate.obj - The object being traversed.
* @params thisArg - An object to which the `this` keyword can refer in the `predicate` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns The value of the first element in the array that satisfies the provided testing function. Otherwise, `undefined` is returned.
*/
find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.prototype.find()}
* @params predicate - A function that accepts up to three arguments. The `find` method calls the `predicate` function one time for each element in the collection.
* @params predicate.value - The value of the element.
* @params predicate.index - The index of the element.
* @params predicate.obj - The object being traversed.
* @params thisArg - An object to which the `this` keyword can refer in the `predicate` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns The value of the first element in the array that satisfies the provided testing function. Otherwise, `undefined` is returned.
*/
find<T>(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.prototype.findIndex()}
* @params predicate - A function that accepts up to three arguments. The `findIndex` method calls the `predicate` function one time for each element in the collection.
* @params predicate.value - The value of the element.
* @params predicate.index - The index of the element.
* @params predicate.obj - The object being traversed.
* @params thisArg - An object to which the `this` keyword can refer in the `predicate` function. If `thisArg` is omitted, `undefined` is used as the `this` value.
* @returns The index of the first element in the array that satisfies the provided testing function. Otherwise, -1 is returned.
*/
findIndex(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): number;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes | Array.prototype.includes()}
* @params searchElement - The element to search for.
* @params fromIndex - The position in this array at which to begin searching for `searchElement`. A negative value searches from the index of array.length + fromIndex by asc.
* @note `fromIndex` is currently not supported. So all searches start at index 0.
* @returns `true` if the `searchElement` is found in the array; otherwise, `false`.
*/
includes(searchElement: T, fromIndex?: number): boolean;
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.prototype.flatMap()}
* @params callback - Function that produces an element of the new Array, taking three arguments:
* @params callback.currentValue - The current element being processed in the array.
* @params callback.index - The index of the current element being processed in the array.
* @params callback.array - The array `flatMap` was called upon.
* @params thisArg - Value to use as this when executing callback.
* @returns A new array with each element being the result of the callback function and flattened to a depth of 1.
*/
flatMap<U, This = undefined>(callback: (this: This, value: T, index: number, array: T[]) => U | readonly U[], thisArg?: This): U[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat | Array.prototype.flat()}
* @params depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
* @returns A new array with the sub-array elements concatenated into it.
*/
flat<A, D extends number = 1>(this: A, depth?: D): FlatArray<A, D>[];
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.prototype.at()}
* @params index - The index of the element to return from the array. If the index is a negative number, the element at `array.length + index` is returned.
* @returns The element at the given index in the array; `undefined` if there is no element at the given index.
*/
at(index: number): T | undefined;
/**
* @returns An iterator that iterates over all the values in the collection.
*/
[Symbol.iterator](): IterableIterator<T>;
/**
* @returns A string describing the filters applied to this collection.
*/
description(): string;
/**
* Checks if this collection is empty.
* @returns `true` if the collection is empty, `false` if not.
*/
isEmpty(): boolean;
/**
* Returns the minimum value of the values in the collection or of the
* given property among all the objects in the collection, or `undefined`
* if the collection is empty.
*
* Only supported for int, float, double and date properties. `null` values
* are ignored entirely by this method and will not be returned.
* @param property - For a collection of objects, the property to take the minimum of.
* @throws A {@link TypeAssertionError} if no property with the name exists or if property is not numeric/date.
* @returns The minimum value.
*/
min(property?: string): number | Date | undefined;
/**
* Returns the maximum value of the values in the collection or of the
* given property among all the objects in the collection, or `undefined`
* if the collection is empty.
*
* Only supported for int, float, double and date properties. `null` values
* are ignored entirely by this method and will not be returned.
* @param property - For a collection of objects, the property to take the maximum of.
* @throws An {@link Error} if no property with the name exists or if property is not numeric/date.
* @returns The maximum value.
*/
max(property?: string): number | Date | undefined;
/**
* Computes the sum of the values in the collection or of the given
* property among all the objects in the collection, or 0 if the collection
* is empty.
*
* Only supported for int, float and double properties. `null` values are
* ignored entirely by this method.
* @param property - For a collection of objects, the property to take the sum of.
* @throws An {@link Error} if no property with the name exists or if property is not numeric.
* @returns The sum.
*/
sum(property?: string): number;
/**
* Computes the average of the values in the collection or of the given
* property among all the objects in the collection, or `undefined` if the collection
* is empty.
*
* Only supported for int, float and double properties. `null` values are
* ignored entirely by this method and will not be factored into the average.
* @param property - For a collection of objects, the property to take the average of.
* @throws An {@link Error} if no property with the name exists or if property is not numeric.
* @returns The sum.
*/
avg(property?: string): number | undefined;
/**
* Returns new {@link Results} that represent this collection being filtered by the provided query.
* @param queryString - Query used to filter objects from the collection.
* @param args - Each subsequent argument is used by the placeholders
* (e.g. `$0`, `$1`, `$2`, …) in the query.
* @throws An {@link Error} if the query or any other argument passed into this method is invalid.
* @returns Results filtered according to the provided query.
* @note This is currently only supported for collections of Realm Objects.
* @example
* let merlots = wines.filtered('variety == "Merlot" && vintage <= $0', maxYear);
*/
filtered(queryString: string, ...args: unknown[]): Results<T>;
/**
* Returns new _Results_ that represent a sorted view of this collection.
*
* A collection of Realm Objects can be sorted on one or more properties of
* those objects, or of properties of objects linked to by those objects.
* To sort by a single property, simply pass the name of that property to
* `sorted()`, optionally followed by a boolean indicating if the sort should be reversed.
* For more than one property, you must pass an array of
* **sort descriptors** which list
* which properties to sort on.
*
* Collections of other types sort on the values themselves rather than
* properties of the values, and so no property name or sort descriptors
* should be supplied.
* @param reverse - Sort in descending order rather than ascended.
* It may not be applied if `descriptor` is an array of sort descriptors.
* @throws An {@link Error} if a specified property does not exist.
* @returns Results sorted according to the arguments passed in.
*/
sorted(reverse?: boolean): Results<T>;
/**
* Returns new _Results_ that represent a sorted view of this collection.
*
* A collection of Realm Objects can be sorted on one or more properties of
* those objects, or of properties of objects linked to by those objects.
* To sort by a single property, simply pass the name of that property to
* `sorted()`, optionally followed by a boolean indicating if the sort should be reversed.
* For more than one property, you must pass an array of
* **sort descriptors** which list
* which properties to sort on.
*
* Collections of other types sort on the values themselves rather than
* properties of the values, and so no property name or sort descriptors
* should be supplied.
* @param descriptor - The property name(s) to sort the collection on.
* @throws An {@link Error} if a specified property does not exist.
* @returns Results sorted according to the arguments passed in.
*/
sorted(descriptor: SortDescriptor[]): Results<T>;
/**
* Returns new _Results_ that represent a sorted view of this collection.
*
* A collection of Realm Objects can be sorted on one or more properties of
* those objects, or of properties of objects linked to by those objects.
* To sort by a single property, simply pass the name of that property to
* `sorted()`, optionally followed by a boolean indicating if the sort should be reversed.
* For more than one property, you must pass an array of
* **sort descriptors** which list
* which properties to sort on.
*
* Collections of other types sort on the values themselves rather than
* properties of the values, and so no property name or sort descriptors
* should be supplied.
* @param descriptor - The property name(s) to sort the collection on.
* @throws An {@link Error} if a specified property does not exist.
* @returns Results sorted according to the arguments passed in.
*/
sorted(descriptor: string, reverse?: boolean): Results<T>;
/**
* Create a frozen snapshot of the collection.
*
* Values added to and removed from the original collection will not be
* reflected in the _Results_ returned by this method, including if the
* values of properties are changed to make them match or not match any
* filters applied.
*
* This is **not** a _deep_ snapshot. Realm objects contained in this
* snapshot