diff --git a/notNeededPackages.json b/notNeededPackages.json index e94e48189c..6e6767c69f 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -504,6 +504,12 @@ "sourceRepoURL": "https://github.com/gpbl/react-day-picker", "asOfVersion": "5.3.0" }, + { + "libraryName": "realm", + "typingsPackageName": "realm", + "sourceRepoURL": "https://github.com/realm/realm-js/blob/master/lib/index.d.ts", + "asOfVersion": "1.0.3" + }, { "libraryName": "Redux", "typingsPackageName": "redux", diff --git a/types/realm/index.d.ts b/types/realm/index.d.ts deleted file mode 100644 index 993f0bcc0f..0000000000 --- a/types/realm/index.d.ts +++ /dev/null @@ -1,456 +0,0 @@ -// Type definitions for realm-js 1.0 -// Project: https://github.com/realm/realm-js -// Definitions by: Akim -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -declare namespace Realm { - /** - * PropertyType - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~PropertyType } - */ - type PropertyType = string | 'bool' | 'int' | 'float' | 'double' | 'string' | 'data' | 'date' | 'list'; - - /** - * ObjectSchemaProperty - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~ObjectSchemaProperty } - */ - interface ObjectSchemaProperty { - type: PropertyType; - objectType?: string; - 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; - } - - interface SyncConfiguration { - user: User; - url: string; - } - - /** - * realm configuration - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~Configuration } - */ - interface Configuration { - encryptionKey?: any; - migration?: any; - path?: string; - readOnly?: boolean; - schema?: ObjectClass[] | ObjectSchema[]; - schemaVersion?: number; - sync?: SyncConfiguration; - } - - // object props type - interface ObjectPropsType { - [keys: string]: any; - } - - /** - * SortDescriptor - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Collection.html#~SortDescriptor } - */ - type SortDescriptor = string | [string, boolean] | any[]; - - /** - * Iterator - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Collection.html#~Iterator } - */ - interface IteratorResult { - done: boolean; - value?: T; - } - - interface Iterator { - next(done: boolean, value?: any): IteratorResult; - [Symbol.iterator](): any; - } - - /** - * Collection - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Collection.html } - */ - interface Collection { - readonly length: number; - - /** - * @returns boolean - */ - isValid(): boolean; - - /** - * @param {string} query - * @param {any[]} ...arg - * @returns Results - */ - filtered(query: string, ...arg: any[]): Results; - - /** - * @param {string|SortDescriptor} descriptor - * @param {boolean} reverse? - * @returns Results - */ - sorted(descriptor: string | SortDescriptor, reverse?: boolean): Results; - - /** - * @returns Iterator - */ - [Symbol.iterator](): Iterator; - - /** - * @returns Results - */ - snapshot(): Results; - - /** - * @returns Iterator - */ - entries(): Iterator; - - /** - * @returns Iterator - */ - keys(): Iterator; - - /** - * @returns Iterator - */ - values(): Iterator; - - /** - * @param {string[]} separator? - * @returns string - */ - join(separator?: string[]): string; - - /** - * @param {number} start? - * @param {number} end? - * @returns T - */ - slice(start?: number, end?: number): T[]; - - /** - * @param {(object:any,index?:any,collection?:any)=>void} callback - * @param {any} thisArg? - * @returns T - */ - find(callback: (object: any, index?: any, collection?: any) => void, thisArg?: any): T | null | undefined; - - /** - * @param {(object:any,index?:number,collection?:any)=>void} callback - * @param {any} thisArg? - * @returns number - */ - findIndex(callback: (object: any, index?: number, collection?: any) => void, thisArg?: any): number; - - /** - * @param {(object:T,index?:number,collection?:any)=>void} callback - * @param {any} thisArg? - * @returns void - */ - forEach(callback: (object: T, index?: number, collection?: any) => void, thisArg?: any): void; - - /** - * @param {(object:T,index?:number,collection?:any)=>void} callback - * @param {any} thisArg? - * @returns boolean - */ - every(callback: (object: T, index?: number, collection?: any) => void, thisArg?: any): boolean; - - /** - * @param {(object:T,index?:number,collection?:any)=>void} callback - * @param {any} thisArg? - * @returns boolean - */ - some(callback: (object: T, index?: number, collection?: any) => void, thisArg?: any): boolean; - - /** - * @param {(object:T,index?:number,collection?:any)=>void} callback - * @param {any} thisArg? - * @returns any - */ - map(callback: (object: T, index?: number, collection?: any) => void, thisArg?: any): any[]; - - /** - * @param {(previousValue:T,object?:T,index?:number,collection?:any)=>void} callback - * @param {any} initialValue? - * @returns any - */ - reduce(callback: (previousValue: T, object?: T, index?: number, collection?: any) => void, initialValue?: any): any; - - /** - * @param {(previousValue:T,object?:T,index?:any,collection?:any)=>void} callback - * @param {any} initialValue? - * @returns any - */ - reduceRight(callback: (previousValue: T, object?: T, index?: any, collection?: any) => void, initialValue?: any): any; - - /** - * @param {(collection:any,changes:any)=>void} callback - * @returns void - */ - addListener(callback: (collection: any, changes: any) => void): void; - - /** - * @returns void - */ - removeAllListeners(): void; - - /** - * @param {()=>void} callback - * @returns void - */ - removeListener(callback: () => void): void; - } - - /** - * Object - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Object.html } - */ - interface Object { - /** - * @returns boolean - */ - isValid(): boolean; - } - - /** - * List - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.List.html } - */ - interface List extends Collection { - /** - * @returns T - */ - pop(): T | null | undefined; - - /** - * @param {T} object - * @returns number - */ - push(object: T): number; - - /** - * @returns T - */ - shift(): T | null | undefined; - - /** - * @param {number} index - * @param {number} count? - * @param {any} object? - * @returns T - */ - splice(index: number, count?: number, object?: any): T[]; - - /** - * @param {T} object - * @returns number - */ - unshift(object: T): number; - } - - /** - * Results - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Results.html } - */ - type Results = Collection; - - /** - * User - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.User.html } - */ - interface User { - all: any; - current: User; - readonly identity: string; - readonly isAdmin: boolean; - readonly server: string; - readonly token: string; - adminUser(adminToken: string): User; - login(server: string, username: string, password: string, callback: (error: any, user: any) => void): void; - loginWithProvider(server: string, provider: string, providerToken: string, callback: (error: any, user: any) => void): void; - register(server: string, username: string, password: string, callback: (error: any, user: any) => void): void; - registerWithProvider(server: string, provider: string, providerToken: string, callback: (error: any, user: any) => void): void; - logout(): void; - openManagementRealm(): Realm; - } - - /** - * Session - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.Session.html } - */ - interface Session { - readonly config: any; - readonly state: string; - readonly url: string; - readonly user: User; - } - - /** - * AuthError - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.AuthError.html } - */ - interface 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: any; - readonly oldRealm: Realm; - readonly path: string; - readonly realm: Realm; - } - - /** - * LogLevel - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.html#~LogLevel } - */ - type LogLevelType = string | 'error' | 'info' | 'defug'; - - /** - * Sync - * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Sync.html } - */ - interface Sync { - User: User; - Session: Session; - AuthError: AuthError; - ChangeEvent: ChangeEvent; - addListener(serverURL: string, adminUser: User, regex: string, name: string, changeCallback: () => void): void; - removeAllListeners(name?: string[]): void; - removeListener(regex: string, name: string, changeCallback: () => void): void; - setLogLevel(logLevel: LogLevelType): void; - } -} - -declare class Realm { - static defaultPath: string; - - readonly path: string; - - readonly readOnly: boolean; - - readonly schema: Realm.ObjectSchema[]; - - readonly schemaVersion: number; - - static Sync: Realm.Sync; - - syncSession: Realm.Session; - - /** - * @param {string} path - * @param {any} encryptionKey? - * @returns number - */ - static schemaVersion(path: string, encryptionKey?: any): number; - - /** - * @param {Realm.Configuration} config? - */ - constructor(config?: Realm.Configuration); - - /** - * @returns void - */ - close(): void; - - /** - * @param {string|Realm.ObjectType} type - * @param {T&Realm.ObjectPropsType} properties - * @param {boolean} update? - * @returns T - */ - create(type: string | Realm.ObjectType, properties: T & Realm.ObjectPropsType, update?: boolean): T; - - /** - * @param {Realm.Object|Realm.Object[]|Realm.List|Realm.Results|any} object - * @returns void - */ - delete(object: Realm.Object | Realm.Object[] | Realm.List | Realm.Results | any): void; - - /** - * @returns void - */ - deleteAll(): void; - - /** - * @param {string|Realm.ObjectType} type - * @param {number|string} key - * @returns T - */ - objectForPrimaryKey(type: string | Realm.ObjectType, key: number | string): T | void; - - /** - * @param {string|Realm.ObjectType} type - * @returns Realm - */ - objects(type: string | Realm.ObjectType): Realm.ObjectType & Realm.Results; - - /** - * @param {string} name - * @param {()=>void} callback - * @returns void - */ - addListener(name: string, callback: () => void): void; - - /** - * @param {string} name - * @param {()=>void} callback - * @returns void - */ - removeListener(name: string, callback: () => void): void; - - /** - * @param {string[]} name? - * @returns void - */ - removeAllListeners(name?: string[]): void; - - /** - * @param {()=>void} callback - * @returns void - */ - write(callback: () => void): void; -} - -export = Realm; diff --git a/types/realm/realm-tests.ts b/types/realm/realm-tests.ts deleted file mode 100644 index 5f171a3287..0000000000 --- a/types/realm/realm-tests.ts +++ /dev/null @@ -1,98 +0,0 @@ -import * as Realm from 'realm'; - -// schema test -const personSchema = { - name: 'Person', - primaryKey: 'id', - properties: { - id: 'int', - name: { type: 'string', default: 'anonymous', indexed: true }, - profilePic: { type: 'string', optional: true } - } -}; - -// encryptionKey -const key = new Int8Array(64); - -// constructor test -const realm = new Realm({ - schema: [personSchema], - encryptionKey: key -}); - -realm.write(() => { - // create test - realm.create('Person', { - id: 1, - name: 'Tony' - }); - - // update test - realm.create('Person', { - id: 1, - name: 'Jack' - }, true); -}); - -// delete all person test -const allPerson = realm.objects('Person'); -realm.delete(allPerson); - -// filtered test -const allJack = allPerson.filtered('name = "Jack"'); - -// sorted test -allJack.sorted('id'); -allJack.sorted('id', true); - -// limiting results test -allJack.slice(0, 2); - -// change events test -realm.addListener('change', () => { - return 'updated'; -}); - -// remove all events -realm.removeAllListeners(); - -allPerson.find((person: any) => { - return person.name === 'Jack'; -}); - -const currentVersion = Realm.schemaVersion(Realm.defaultPath); - -// username/password authentication -Realm.Sync.User.register('http://localhost:9080', 'username@example.com', 'p@s$w0rd', (error, user) => { /* ... */ }); - -Realm.Sync.User.login('http://localhost.com:9080', 'username@example.com', 'p@s$w0rd', (error, user) => { - const todoSchema = { - name: 'Todo', - primaryKey: 'id', - properties: { - id: 'int', - task: 'string', - } - }; - - // sync test - const realm = new Realm({ - schema: [todoSchema], - sync: { user, url: 'realm://localhost:9080/~/todos' } - }); - - // session test - const session = realm.syncSession; - const sessionUrl = session.config.url; -}); - -// facebook authentication -const fbAccessToken = 'acc3ssT0ken...'; -Realm.Sync.User.registerWithProvider('http://localhost:9080', 'facebook', fbAccessToken, (error, user) => { /* ... */ }); - -// user test -const user = Realm.Sync.User.current; -const users = Realm.Sync.User.all; - -// access control test -const managementRealm = user.openManagementRealm(); diff --git a/types/realm/tsconfig.json b/types/realm/tsconfig.json deleted file mode 100644 index 583e188e67..0000000000 --- a/types/realm/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "realm-tests.ts" - ] -} \ No newline at end of file diff --git a/types/realm/tslint.json b/types/realm/tslint.json deleted file mode 100644 index e6dc9b7f2f..0000000000 --- a/types/realm/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - // TODO - "no-any-union": false, - "no-unnecessary-generics": false - } -}