2017-06-20 11:09:01 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2017 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.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// TypeScript Version: 2.3.2
|
|
|
|
// With great contributions to @akim95 on github
|
|
|
|
|
|
|
|
declare namespace Realm {
|
|
|
|
/**
|
|
|
|
* PropertyType
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~PropertyType }
|
|
|
|
*/
|
2017-06-29 09:59:10 +00:00
|
|
|
type PropertyType = string | 'bool' | 'int' | 'float' | 'double' | 'string' | 'data' | 'date' | 'list' | 'linkingObjects';
|
2017-06-20 11:09:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ObjectSchemaProperty
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~ObjectSchemaProperty }
|
|
|
|
*/
|
|
|
|
interface ObjectSchemaProperty {
|
|
|
|
type: PropertyType;
|
|
|
|
objectType?: string;
|
2017-06-29 09:59:10 +00:00
|
|
|
property?: string;
|
2017-06-20 11:09:01 +00:00
|
|
|
default?: any;
|
|
|
|
optional?: boolean;
|
|
|
|
indexed?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
// properties types
|
|
|
|
interface PropertiesTypes {
|
|
|
|
[keys: string]: PropertyType | ObjectSchemaProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ObjectSchema
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~ObjectSchema }
|
|
|
|
*/
|
|
|
|
interface ObjectSchema {
|
|
|
|
name: string;
|
|
|
|
primaryKey?: string;
|
|
|
|
properties: PropertiesTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ObjectClass
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~ObjectClass }
|
|
|
|
*/
|
|
|
|
interface ObjectClass {
|
|
|
|
schema: ObjectSchema;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ObjectType
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~ObjectType }
|
|
|
|
*/
|
|
|
|
interface ObjectType {
|
|
|
|
type: ObjectClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* realm configuration
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~Configuration }
|
|
|
|
*/
|
|
|
|
interface Configuration {
|
|
|
|
encryptionKey?: ArrayBuffer | ArrayBufferView | Int8Array;
|
|
|
|
migration?: (oldRealm: Realm, newRealm: Realm) => void;
|
2017-08-18 12:22:29 +00:00
|
|
|
shouldCompactOnLaunch?: (totalBytes: number, usedBytes: number) => boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
path?: string;
|
|
|
|
readOnly?: boolean;
|
2017-09-13 18:42:23 +00:00
|
|
|
inMemory?: boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
schema?: ObjectClass[] | ObjectSchema[];
|
|
|
|
schemaVersion?: number;
|
|
|
|
sync?: Realm.Sync.SyncConfiguration;
|
2017-10-03 11:37:21 +00:00
|
|
|
deleteRealmIfMigrationNeeded?: boolean;
|
2017-12-14 06:53:03 +00:00
|
|
|
disableFormatUpgrade?: boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// object props type
|
|
|
|
interface ObjectPropsType {
|
|
|
|
[keys: string]: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Object.html }
|
|
|
|
*/
|
|
|
|
interface Object {
|
|
|
|
/**
|
|
|
|
* @returns boolean
|
|
|
|
*/
|
|
|
|
isValid(): boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns ObjectSchema
|
|
|
|
*/
|
|
|
|
objectSchema(): ObjectSchema;
|
2017-06-29 09:59:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns Results<T>
|
|
|
|
*/
|
|
|
|
linkingObjects<T>(objectType: string, property: string): Results<T>;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Object: {
|
|
|
|
readonly prototype: Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SortDescriptor
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Collection.html#~SortDescriptor }
|
|
|
|
*/
|
2017-09-28 22:03:56 +00:00
|
|
|
type SortDescriptor = [string] | [string, boolean];
|
2017-06-20 11:09:01 +00:00
|
|
|
|
|
|
|
interface CollectionChangeSet {
|
|
|
|
insertions: number[];
|
|
|
|
deletions: number[];
|
|
|
|
modifications: number[];
|
|
|
|
}
|
|
|
|
|
|
|
|
type CollectionChangeCallback<T> = (collection: Collection<T>, change: CollectionChangeSet) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collection
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Collection.html }
|
|
|
|
*/
|
|
|
|
interface Collection<T> extends ReadonlyArray<T> {
|
2017-09-28 22:03:56 +00:00
|
|
|
readonly type: PropertyType;
|
|
|
|
readonly optional: boolean;
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* @returns boolean
|
|
|
|
*/
|
|
|
|
isValid(): boolean;
|
|
|
|
|
2018-01-11 13:47:54 +00:00
|
|
|
min(property?: string): number | Date | null;
|
|
|
|
max(property?: string): number | Date | null;
|
|
|
|
sum(property?: string): number | null;
|
2017-10-11 12:54:52 +00:00
|
|
|
avg(property?: string): number;
|
2017-09-29 11:23:37 +00:00
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* @param {string} query
|
|
|
|
* @param {any[]} ...arg
|
|
|
|
* @returns Results
|
|
|
|
*/
|
|
|
|
filtered(query: string, ...arg: any[]): Results<T>;
|
|
|
|
|
2017-09-28 22:03:56 +00:00
|
|
|
sorted(reverse?: boolean): Results<T>;
|
|
|
|
sorted(descriptor: SortDescriptor[]): Results<T>;
|
|
|
|
sorted(descriptor: string, reverse?: boolean): Results<T>;
|
2017-06-20 11:09:01 +00:00
|
|
|
|
2018-02-20 12:40:54 +00:00
|
|
|
/**
|
|
|
|
* @returns Results<T>
|
|
|
|
*/
|
|
|
|
subscribe(subscriptionName?: string): Realm.Sync.Subscription;
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* @returns Results
|
|
|
|
*/
|
|
|
|
snapshot(): Results<T>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {(collection:any,changes:any)=>void} callback
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
addListener(callback: CollectionChangeCallback<T>): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
removeAllListeners(): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {()=>void} callback this is the callback to remove
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
removeListener(callback: CollectionChangeCallback<T>): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Collection: {
|
|
|
|
readonly prototype: Collection<any>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.List.html }
|
|
|
|
*/
|
|
|
|
interface List<T> extends Collection<T> {
|
|
|
|
[n: number]: T;
|
|
|
|
|
|
|
|
pop(): T | null | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {T} object
|
|
|
|
* @returns number
|
|
|
|
*/
|
2017-09-28 22:03:56 +00:00
|
|
|
push(...object: T[]): number;
|
2017-06-20 11:09:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns T
|
|
|
|
*/
|
|
|
|
shift(): T | null | undefined;
|
|
|
|
|
2017-09-28 22:03:56 +00:00
|
|
|
unshift(...object: T[]): number;
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* @param {number} index
|
|
|
|
* @param {number} count?
|
|
|
|
* @param {any} object?
|
|
|
|
* @returns T
|
|
|
|
*/
|
|
|
|
splice(index: number, count?: number, object?: any): T[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const List: {
|
|
|
|
readonly prototype: List<any>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Results
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Results.html }
|
|
|
|
*/
|
|
|
|
interface Results<T> extends Collection<T> {
|
2017-10-10 10:55:47 +00:00
|
|
|
/**
|
|
|
|
* Bulk update objects in the collection.
|
|
|
|
* @param {string} property
|
|
|
|
* @param {any} value
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
update(property: string, value: any): void;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Results: {
|
|
|
|
readonly prototype: Results<any>;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.html }
|
|
|
|
*/
|
|
|
|
declare namespace Realm.Sync {
|
|
|
|
|
2017-07-06 09:33:47 +00:00
|
|
|
interface UserInfo {
|
|
|
|
id: string;
|
|
|
|
isAdmin: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Account {
|
|
|
|
provider_id: string;
|
|
|
|
provider: string;
|
|
|
|
user: UserInfo
|
|
|
|
}
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* User
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.User.html }
|
|
|
|
*/
|
|
|
|
class User {
|
|
|
|
static readonly all: { [identity: string]: User };
|
|
|
|
static readonly current: User;
|
|
|
|
readonly identity: string;
|
|
|
|
readonly isAdmin: boolean;
|
2018-01-11 13:47:54 +00:00
|
|
|
readonly isAdminToken: boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
readonly server: string;
|
|
|
|
readonly token: string;
|
2017-07-10 13:04:55 +00:00
|
|
|
static adminUser(adminToken: string, server?: string): User;
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-09-12 17:38:43 +00:00
|
|
|
/**
|
|
|
|
* @deprecated, to be removed in future versions
|
|
|
|
*/
|
2017-06-20 11:09:01 +00:00
|
|
|
static login(server: string, username: string, password: string, callback: (error: any, user: User) => void): void;
|
2017-09-12 17:38:43 +00:00
|
|
|
static login(server: string, username: string, password: string): Promise<Realm.Sync.User>;
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-09-12 17:38:43 +00:00
|
|
|
/**
|
|
|
|
* @deprecated, to be removed in future versions
|
2017-09-22 10:40:34 +00:00
|
|
|
*/
|
2017-06-20 11:09:01 +00:00
|
|
|
static register(server: string, username: string, password: string, callback: (error: any, user: User) => void): void;
|
2017-09-12 17:38:43 +00:00
|
|
|
static register(server: string, username: string, password: string): Promise<Realm.Sync.User>;
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-09-12 17:38:43 +00:00
|
|
|
/**
|
|
|
|
* @deprecated, to be removed in versions
|
2017-09-22 10:40:34 +00:00
|
|
|
*/
|
2017-06-20 11:09:01 +00:00
|
|
|
static registerWithProvider(server: string, options: { provider: string, providerToken: string, userInfo: any }, callback: (error: Error | null, user: User | null) => void): void;
|
2017-09-12 17:38:43 +00:00
|
|
|
static registerWithProvider(server: string, options: { provider: string, providerToken: string, userInfo: any }): Promise<Realm.Sync.User>;
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2018-01-05 08:38:53 +00:00
|
|
|
authenticate(server: string, provider: string, options: any): Promise<Realm.Sync.User>;
|
2017-06-20 11:09:01 +00:00
|
|
|
logout(): void;
|
|
|
|
openManagementRealm(): Realm;
|
2017-07-06 09:33:47 +00:00
|
|
|
retrieveAccount(provider: string, username: string): Promise<Account>;
|
2017-08-29 13:23:22 +00:00
|
|
|
|
2017-10-01 05:50:31 +00:00
|
|
|
getGrantedPermissions(recipient: 'any' | 'currentUser' | 'otherUser'): Promise<Results<Permission>>;
|
2017-08-29 13:23:22 +00:00
|
|
|
applyPermissions(condition: PermissionCondition, realmUrl: string, accessLevel: AccessLevel): Promise<PermissionChange>;
|
|
|
|
offerPermissions(realmUrl: string, accessLevel: AccessLevel, expiresAt?: Date): Promise<string>;
|
|
|
|
acceptPermissionOffer(token: string): Promise<string>
|
|
|
|
invalidatePermissionOffer(permissionOfferOrToken: PermissionOffer | string): Promise<void>;
|
|
|
|
}
|
|
|
|
|
2018-01-25 14:44:47 +00:00
|
|
|
interface _PermissionConditionUserId {
|
|
|
|
userId: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface _PermissionConditionMetadata {
|
|
|
|
metadataKey: string
|
|
|
|
metadataValue: string
|
|
|
|
}
|
|
|
|
|
|
|
|
type PermissionCondition = _PermissionConditionUserId | _PermissionConditionMetadata
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-09-27 15:53:09 +00:00
|
|
|
type AccessLevel = 'none' | 'read' | 'write' | 'admin';
|
2017-08-29 13:23:22 +00:00
|
|
|
|
2017-09-08 08:19:13 +00:00
|
|
|
class Permission {
|
2017-09-27 15:53:09 +00:00
|
|
|
readonly id: string;
|
|
|
|
readonly updatedAt: Date;
|
|
|
|
readonly userId: string;
|
|
|
|
readonly path: string;
|
|
|
|
readonly mayRead?: boolean;
|
|
|
|
readonly mayWrite?: boolean;
|
|
|
|
readonly mayManage?: boolean;
|
2017-09-22 10:40:34 +00:00
|
|
|
}
|
2017-09-08 08:19:13 +00:00
|
|
|
|
2017-08-29 13:23:22 +00:00
|
|
|
class PermissionChange {
|
2017-09-27 15:53:09 +00:00
|
|
|
id: string;
|
|
|
|
createdAt: Date;
|
|
|
|
updatedAt: Date;
|
|
|
|
statusCode?: number;
|
|
|
|
statusMessage?: string;
|
|
|
|
userId: string;
|
|
|
|
metadataKey?: string;
|
|
|
|
metadataValue?: string;
|
|
|
|
realmUrl: string;
|
|
|
|
mayRead?: boolean;
|
|
|
|
mayWrite?: boolean;
|
|
|
|
mayManage?: boolean;
|
2017-08-29 13:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class PermissionOffer {
|
2017-09-27 15:53:09 +00:00
|
|
|
id: string;
|
|
|
|
createdAt: Date;
|
|
|
|
updatedAt: Date;
|
|
|
|
statusCode?: number;
|
|
|
|
statusMessage?: string;
|
|
|
|
token?: string;
|
|
|
|
realmUrl: string;
|
|
|
|
mayRead?: boolean;
|
|
|
|
mayWrite?: boolean;
|
|
|
|
mayManage?: boolean;
|
|
|
|
expiresAt?: Date;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 09:29:32 +00:00
|
|
|
interface SyncError {
|
2017-11-06 12:51:33 +00:00
|
|
|
name: string;
|
2018-01-11 13:47:54 +00:00
|
|
|
message: string;
|
2017-11-06 12:51:33 +00:00
|
|
|
isFatal: boolean;
|
2018-01-11 13:47:54 +00:00
|
|
|
category?: string;
|
2017-10-04 09:29:32 +00:00
|
|
|
code: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorCallback = (session: Session, error: SyncError) => void;
|
2017-09-22 10:40:34 +00:00
|
|
|
type SSLVerifyCallback = (serverAddress: string, serverPort: number, pemCertificate: string, preverifyOk: number, depth: number) => boolean;
|
2017-09-15 13:22:44 +00:00
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
interface SyncConfiguration {
|
|
|
|
user: User;
|
|
|
|
url: string;
|
2017-06-20 17:13:33 +00:00
|
|
|
validate_ssl?: boolean;
|
|
|
|
ssl_trust_certificate_path?: string;
|
2017-11-03 15:02:34 +00:00
|
|
|
open_ssl_verify_callback?: SSLVerifyCallback;
|
2017-09-15 13:22:44 +00:00
|
|
|
error?: ErrorCallback;
|
2017-10-16 09:48:07 +00:00
|
|
|
partial?: boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 22:59:30 +00:00
|
|
|
type ProgressNotificationCallback = (transferred: number, transferable: number) => void;
|
2017-09-05 14:04:06 +00:00
|
|
|
type ProgressDirection = 'download' | 'upload';
|
|
|
|
type ProgressMode = 'reportIndefinitely' | 'forCurrentlyOutstandingWork';
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* Session
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.Session.html }
|
|
|
|
*/
|
|
|
|
class Session {
|
|
|
|
readonly config: SyncConfiguration;
|
|
|
|
readonly state: 'invalid' | 'active' | 'inactive';
|
|
|
|
readonly url: string;
|
|
|
|
readonly user: User;
|
2017-09-05 14:04:06 +00:00
|
|
|
|
|
|
|
addProgressNotification(direction: ProgressDirection, mode: ProgressMode, progressCallback: ProgressNotificationCallback): void;
|
|
|
|
removeProgressNotification(progressCallback: ProgressNotificationCallback): void;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:40:54 +00:00
|
|
|
type SubscriptionNotificationCallback = (state: number) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscription
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.Subscription.html }
|
|
|
|
*/
|
|
|
|
class Subscription {
|
2018-03-02 23:08:06 +00:00
|
|
|
readonly state: SubscriptionState;
|
2018-02-20 12:40:54 +00:00
|
|
|
readonly error: string;
|
|
|
|
|
|
|
|
unsubscribe(): void;
|
|
|
|
addListener(subscruptionCallback: SubscriptionNotificationCallback): void;
|
|
|
|
removeListener(subscruptionCallback: SubscriptionNotificationCallback): void;
|
|
|
|
}
|
|
|
|
|
2018-03-02 23:08:06 +00:00
|
|
|
enum SubscriptionState {
|
|
|
|
Error,
|
|
|
|
Creating,
|
|
|
|
Pending,
|
|
|
|
Complete,
|
|
|
|
Invalidated,
|
|
|
|
}
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* AuthError
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.AuthError.html }
|
|
|
|
*/
|
|
|
|
class AuthError {
|
|
|
|
readonly code: number;
|
|
|
|
readonly type: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ChangeEvent
|
|
|
|
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.ChangeEvent.html }
|
|
|
|
*/
|
|
|
|
interface ChangeEvent {
|
|
|
|
readonly changes: { [object_type: string]: CollectionChangeSet };
|
|
|
|
readonly oldRealm: Realm;
|
|
|
|
readonly path: string;
|
|
|
|
readonly realm: Realm;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addListener(serverURL: string, adminUser: Realm.Sync.User, regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => void): void;
|
2018-01-18 11:20:17 +00:00
|
|
|
function addListener(serverURL: string, adminUser: Realm.Sync.User, regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => Promise<void>): void;
|
|
|
|
function removeAllListeners(): Promise<void>;
|
2018-02-01 13:38:02 +00:00
|
|
|
function removeListener(regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => void): Promise<void>;
|
2017-08-29 08:37:29 +00:00
|
|
|
function setLogLevel(logLevel: 'all' | 'trace' | 'debug' | 'detail' | 'info' | 'warn' | 'error' | 'fatal' | 'off'): void;
|
2017-10-02 17:44:24 +00:00
|
|
|
function initiateClientReset(path: string): void;
|
2017-09-12 12:28:16 +00:00
|
|
|
function setFeatureToken(token: string): void;
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
type Instruction = {
|
2017-09-13 07:21:26 +00:00
|
|
|
type: 'INSERT' | 'SET' | 'DELETE' | 'CLEAR' | 'LIST_SET' | 'LIST_INSERT' | 'LIST_ERASE' | 'LIST_CLEAR' | 'ADD_TYPE' | 'ADD_PROPERTIES' | 'CHANGE_IDENTITY' | 'SWAP_IDENTITY'
|
2017-06-20 11:09:01 +00:00
|
|
|
object_type: string,
|
|
|
|
identity: string,
|
|
|
|
values: any | undefined
|
|
|
|
list_index: any | undefined
|
|
|
|
object_identity: any | undefined
|
|
|
|
new_identity: any | undefined,
|
|
|
|
property: any | undefined,
|
|
|
|
properties: any | undefined,
|
|
|
|
primary_key: string | undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
class Adapter {
|
|
|
|
constructor(
|
|
|
|
local_path: string,
|
|
|
|
server_url: string,
|
|
|
|
admin_user: User,
|
|
|
|
regex: string,
|
|
|
|
change_callback: Function
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Advance the to the next transaction indicating that you are done processing the current instructions for the given Realm.
|
|
|
|
* @param path the path for the Realm to advance
|
|
|
|
*/
|
|
|
|
advance(path: string): void;
|
|
|
|
close(): void;
|
|
|
|
current(path: string): Array<Instruction>;
|
2017-11-01 13:44:40 +00:00
|
|
|
realmAtPath(path: string, schema?: ObjectSchema[]): Realm
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 14:04:06 +00:00
|
|
|
|
2017-09-27 15:53:09 +00:00
|
|
|
interface ProgressPromise extends Promise<Realm> {
|
|
|
|
progress(callback: Realm.Sync.ProgressNotificationCallback): Promise<Realm>
|
2017-09-05 14:04:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
declare class Realm {
|
|
|
|
static defaultPath: string;
|
|
|
|
|
2017-07-12 11:02:21 +00:00
|
|
|
readonly empty: boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
readonly path: string;
|
|
|
|
readonly readOnly: boolean;
|
|
|
|
readonly schema: Realm.ObjectSchema[];
|
|
|
|
readonly schemaVersion: number;
|
2017-08-21 15:48:53 +00:00
|
|
|
readonly isInTransaction: boolean;
|
2017-12-13 09:09:26 +00:00
|
|
|
readonly isClosed: boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
|
|
|
|
readonly syncSession: Realm.Sync.Session | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current schema version of the Realm at the given path.
|
|
|
|
* @param {string} path
|
|
|
|
* @param {any} encryptionKey?
|
|
|
|
* @returns number
|
|
|
|
*/
|
|
|
|
static schemaVersion(path: string, encryptionKey?: ArrayBuffer | ArrayBufferView): number;
|
|
|
|
|
2017-09-22 10:40:34 +00:00
|
|
|
|
2017-09-05 14:04:06 +00:00
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* Open a realm asynchronously with a promise. If the realm is synced, it will be fully synchronized before it is available.
|
2017-09-22 10:40:34 +00:00
|
|
|
* @param {Configuration} config
|
2017-06-20 11:09:01 +00:00
|
|
|
*/
|
2017-09-05 14:04:06 +00:00
|
|
|
static open(config: Realm.Configuration): ProgressPromise;
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
2017-08-24 18:01:12 +00:00
|
|
|
* @deprecated in favor of `Realm.open`
|
2017-06-20 11:09:01 +00:00
|
|
|
* Open a realm asynchronously with a callback. If the realm is synced, it will be fully synchronized before it is available.
|
2017-09-22 10:40:34 +00:00
|
|
|
* @param {Configuration} config
|
2017-06-20 11:09:01 +00:00
|
|
|
* @param {Function} callback will be called when the realm is ready.
|
2017-09-22 10:40:34 +00:00
|
|
|
* @param {ProgressNotificationCallback} progressCallback? a progress notification callback for 'download' direction and 'forCurrentlyOutstandingWork' mode
|
2017-06-20 11:09:01 +00:00
|
|
|
*/
|
2017-09-13 09:37:44 +00:00
|
|
|
static openAsync(config: Realm.Configuration, callback: (error: any, realm: Realm) => void, progressCallback?: Realm.Sync.ProgressNotificationCallback): void
|
2017-06-20 11:09:01 +00:00
|
|
|
|
2017-08-30 04:55:30 +00:00
|
|
|
/**
|
|
|
|
* Delete the Realm file for the given configuration.
|
|
|
|
* @param {Configuration} config
|
|
|
|
*/
|
|
|
|
static deleteFile(config: Realm.Configuration): void
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* @param {Realm.Configuration} config?
|
|
|
|
*/
|
|
|
|
constructor(config?: Realm.Configuration);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} path
|
|
|
|
*/
|
|
|
|
constructor(path?: string);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
close(): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string|Realm.ObjectClass|Function} type
|
|
|
|
* @param {T&Realm.ObjectPropsType} properties
|
|
|
|
* @param {boolean} update?
|
|
|
|
* @returns T
|
|
|
|
*/
|
|
|
|
create<T>(type: string | Realm.ObjectClass | Function, properties: T & Realm.ObjectPropsType, update?: boolean): T;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Realm.Object|Realm.Object[]|Realm.List<any>|Realm.Results<any>|any} object
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
delete(object: Realm.Object | Realm.Object[] | Realm.List<any> | Realm.Results<any> | any): void;
|
|
|
|
|
2017-09-11 05:45:08 +00:00
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
deleteModel(name: string): void;
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
deleteAll(): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string|Realm.ObjectSchema|Function} type
|
|
|
|
* @param {number|string} key
|
2018-02-16 09:27:30 +00:00
|
|
|
* @returns {T | undefined}
|
2017-06-20 11:09:01 +00:00
|
|
|
*/
|
2018-02-16 09:27:30 +00:00
|
|
|
objectForPrimaryKey<T>(type: string | Realm.ObjectSchema | Function, key: number | string): T | undefined;
|
2017-06-20 11:09:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string|Realm.ObjectType|Function} type
|
|
|
|
* @returns Realm
|
|
|
|
*/
|
|
|
|
objects<T>(type: string | Realm.ObjectSchema | Function): Realm.Results<T>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {()=>void} callback
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
addListener(name: string, callback: (sender: Realm, event: 'change') => void): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {()=>void} callback
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
removeListener(name: string, callback: (sender: Realm, event: 'change') => void): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name?
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
removeAllListeners(name?: string): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {()=>void} callback
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
write(callback: () => void): void;
|
2017-08-18 12:22:29 +00:00
|
|
|
|
2017-08-21 15:48:53 +00:00
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
beginTransaction(): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
commitTransaction(): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
cancelTransaction(): void;
|
|
|
|
|
2017-08-18 12:22:29 +00:00
|
|
|
/**
|
|
|
|
* @returns boolean
|
|
|
|
*/
|
|
|
|
compact(): boolean;
|
2017-06-20 11:09:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 22:56:00 +00:00
|
|
|
declare namespace Realm.Permissions {
|
|
|
|
interface Permission {
|
|
|
|
identity: string;
|
|
|
|
canRead: boolean;
|
|
|
|
canUpdate: boolean;
|
|
|
|
canDelete: boolean;
|
|
|
|
canSetPermissions: boolean;
|
|
|
|
canQuery: boolean;
|
|
|
|
canCreate: boolean;
|
|
|
|
canModifySchema: boolean;
|
|
|
|
}
|
|
|
|
interface User {
|
|
|
|
identity: string;
|
|
|
|
}
|
|
|
|
interface Role {
|
|
|
|
name: string;
|
|
|
|
members: User[];
|
|
|
|
}
|
|
|
|
interface Class {
|
|
|
|
class_name: string;
|
|
|
|
permissions: Permission[];
|
|
|
|
}
|
|
|
|
interface Realm {
|
|
|
|
permissions: Permission[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 11:09:01 +00:00
|
|
|
declare module 'realm' {
|
|
|
|
export = Realm
|
|
|
|
}
|