diff --git a/types/orientjs/index.d.ts b/types/orientjs/index.d.ts index e460074336..3eef7ace34 100644 --- a/types/orientjs/index.d.ts +++ b/types/orientjs/index.d.ts @@ -1,14 +1,17 @@ -// Type definitions for orientjs v3.0.0 +// Type definitions for orientjs 3.0 // Project: https://github.com/orientechnologies/orientjs // Definitions by: [Saeed Tabrizi] // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last Update : 19-7-2017 +// Last Update : 19-7-2017 // Compatible with Orientdb >= 2.2.15 and orientjs >= 2.2.x features . // Developed with love in www.nowcando.com -// +// /// +import events = require('events'); +import Promise = require('bluebird'); + /* =================== USAGE =================== import orientjs = require('orientjs'); let dbserver = orientjs({ @@ -25,22 +28,23 @@ =============================================== */ /** A lightweight definiton for orientjs module, Official node.js driver for OrientDB. - * + * * @description Official node.js driver for OrientDB. Fast, lightweight, uses the binary protocol. - * - * @author Saeed Tabrizi (saeed a_t nowcando.com) + * + * @author Saeed Tabrizi (saeed a_t nowcando.com) * @version 3.0.0 - * -*/ -declare module "orientjs" { - import events = require('events'); - import Promise = require('bluebird'); + * + */ +declare namespace orientjs { function ojs(config: ojs.ServerConfig): ojs.OrientJs; - module ojs { - + namespace ojs { type Version = number | string; - type PropertyType = "Boolean" | "Integer" | "Short" | "Long" | "Float" | "Double" | "DateTime" | "String" | "Binary" | "Embedded" | "EmbeddedList" | "EmbeddedSet" | "EmbeddedMap" | "Link" | "LinkList" | "LinkSet" | "LinkMap" | "Byte" | "Transient" | "Date" | "Custom" | "Decimal" | "LinkBag"; + type PropertyType = "Boolean" | "Integer" | "Short" | "Long" | + "Float" | "Double" | "DateTime" | "string" | "Binary" | + "Embedded" | "EmbeddedList" | "EmbeddedSet" | "EmbeddedMap" | + "Link" | "LinkList" | "LinkSet" | "LinkMap" | "Byte" | + "Transient" | "Date" | "Custom" | "Decimal" | "LinkBag"; enum DataTypes { Boolean = 0, Integer = 1, @@ -49,7 +53,7 @@ declare module "orientjs" { Float = 4, Double = 5, Datetime = 6, - String = 7, + string = 7, Binary = 8, Embedded = 9, EmbeddedList = 10, @@ -67,37 +71,36 @@ declare module "orientjs" { LinkBag = 22 } - module errors { - interface BaseError { + namespace errors { + class BaseError { name: string; init(name: string): void; } - interface OperationError extends BaseError { + class OperationError extends BaseError { message: string; date: any; } - interface RequestError extends OperationError { } + class RequestError extends OperationError { + } } - module Migration { - type MigrationManagerConfig = { - name?: string, - db?: Db, - dir?: string, - className?: string - }; - + namespace Migration { + interface MigrationManagerConfig { + name?: string; + db?: Db; + dir?: string; + className?: string; + } class Manager extends MigrationManager { constructor(config: MigrationManagerConfig); } - interface Migration { + class Migration { name: string; server: Server; db: Db; configure(config?: any): void; up(): Promise; down(): Promise; - } class MigrationManager { @@ -115,132 +118,119 @@ declare module "orientjs" { className: string; /** - * Create a new migration. - * - * @param {String|Object} config The name or configuration for the new migration. - * @promise {String} The full path to the created migration. - */ + * Create a new migration. + * + * @param {string|Object} config The name or configuration for the new migration. + * @promise {string} The full path to the created migration. + */ create(param: string): Promise; /** - * Generate the content for a migration. - * @param {Object} config The configuration object. - * @return {String} The generated JavaScript source code. - */ + * Generate the content for a migration. + * @param {Object} config The configuration object. + * @return {string} The generated JavaScript source code. + */ generateMigration(config: any): string; /** - * List the migrations that have not yet been applied. - * - * @promise {String[]} An array of migration names - */ + * List the migrations that have not yet been applied. + * + * @promise {string[]} An array of migration names + */ list(): Promise; /** - * List all the available migrations. - * - * @promise {String[]} The names of the available migrations. - */ + * List all the available migrations. + * + * @promise {string[]} The names of the available migrations. + */ listAvailable(): Promise; /** - * Ensure the migration class exists. - * - * @promise {MigrationManager} The manager instance with intact structure. - */ + * Ensure the migration class exists. + * + * @promise {MigrationManager} The manager instance with intact structure. + */ ensureStructure: Promise; /** - * Retrieve a list of applied migrations. - * - * @promise {Object[]} The applied migrations. - */ + * Retrieve a list of applied migrations. + * + * @promise {Object[]} The applied migrations. + */ listApplied(): Promise; /** - * Perform the migration. - * - * @param {Integer} limit The maximum number of migrations to apply, if any. - * @promise {Mixed} The result of the migration. - */ + * Perform the migration. + * + * @param {Integer} limit The maximum number of migrations to apply, if any. + * @promise {Mixed} The result of the migration. + */ up(limit?: number): Promise; /** - * Revert the migration. - * - * @param {Integer} limit The maximum number of migrations to revert, if any. - * @promise {Mixed} The result of the migration. - */ + * Revert the migration. + * + * @param {Integer} limit The maximum number of migrations to revert, if any. + * @promise {Mixed} The result of the migration. + */ down(limit?: number): Promise; /** - * Load the migration with the given name. - * - * @param {String} name The name of the migation. - * @return {Migration} The loaded migration instance. - */ + * Load the migration with the given name. + * + * @param {string} name The name of the migation. + * @return {Migration} The loaded migration instance. + */ loadMigration(name: string): Migration; /** - * Apply the migration with the given name. - * - * @param {String} name The name of the migation. - * @promise {Mixed} The result of the migration. - */ + * Apply the migration with the given name. + * + * @param {string} name The name of the migation. + * @promise {Mixed} The result of the migration. + */ applyMigration(name: string): Promise; /** - * Revert the migration with the given name. - * - * @param {String} name The name of the migation. - * @promise {Mixed} The result of the migration. - */ + * Revert the migration with the given name. + * + * @param {string} name The name of the migation. + * @promise {Mixed} The result of the migration. + */ revertMigration(name: string): Promise; } } interface Logger { - error?: Function; - log?: Function; - debug?: Function; + error(...args: any[]): void; + log(...args: any[]): void; + debug(...args: any[]): void; } - interface RID extends String { + class RID extends String { cluster?: number; position?: number; valueOf(): string; - isValid?(): boolean; - equals?(rid: string) - : boolean; - equals?(rid: RID) - : boolean; - parse?(input: string) - : boolean; - parse?(input: string) - : RID; - parse?(input: string) - : RID[]; - isValid?(input: string) - : boolean; - isValid?(input: RID) - : boolean; - isValid?(input: any) - : boolean; - toRid?(cluster: number, position: number) - : any; + isValid?(input?: string | RID | any): boolean; + equals?(rid: string | RID): boolean; + parse?(input: string): boolean; + parse?(input: string): RID; + parse?(input: string): RID[]; + toRid?(cluster: number, position: number): any; } interface CustomField { /** * Get the value of the given custom field. * - * @param {String} key The name of the field to get. + * @param {string} key The name of the field to get. * @return {Mixed} The field value, or undefined if it doesn't exist. */ get(key: string): CustomField; /** * Set a custom field. * - * @param {String|Object} key The key to set, or map of keys to values. - * @param {String} value The value to set, if `key` is not an object. + * @param {string|Object} key The key to set, or map of keys to values. + * @param {string} value The value to set, if `key` is not an object. * @promise {Object|null} The new set of custom fields, or null if none are present. */ set(key: string, value: any): CustomField; /** * Unset the custom field with the given name, * - * @param {String} key The name of the custom field to remove. + * @param {string} key The name of the custom field to remove. * @promise {Object|null} The new set of custom fields, or null if none are present. */ unset(key: string): CustomField; @@ -263,7 +253,7 @@ declare module "orientjs" { max?: number; custom?: { fields?: CustomField[] - } + }; } interface PropertyUpdateConfig { @@ -281,11 +271,10 @@ declare module "orientjs" { max?: number; custom?: { fields?: CustomField[] - } + }; } - interface Property { - + class Property { class?: Class; name?: string; originalName?: string; @@ -301,50 +290,48 @@ declare module "orientjs" { max?: number; custom?: { fields?: CustomField[] - } + }; configure(config?: any): void; reload(): Promise; - rename(newName: string): Promise; list(): Promise; /** * Create a new property. * - * @param {String|Object} config The property name or configuration. + * @param {string|Object} config The property name or configuration. * @param {Boolean} reload Whether to reload the property, default to true. * @promise {Object} The created property. */ create(config?: PropertyCreateConfig | string, reload?: boolean): Promise; create(config: PropertyCreateConfig[], reload?: boolean): Promise; /** - * Get the property with the given name. - * - * @param {String} name The property to get. - * @promise {Object|null} The retrieved property. - */ + * Get the property with the given name. + * + * @param {string} name The property to get. + * @promise {Object|null} The retrieved property. + */ get(name: string): Promise; /** - * Update the given property. - * - * @param {Object} property The property settings. - * @param {Boolean} reload Whether to reload the property, default to true. - * @promise {Object} The updated property. - */ + * Update the given property. + * + * @param {Object} property The property settings. + * @param {Boolean} reload Whether to reload the property, default to true. + * @promise {Object} The updated property. + */ update(config: PropertyUpdateConfig, reload?: boolean): Promise; drop(name: string, config?: { ifexist?: boolean, force?: boolean }): Promise; alter(name: string, setting?: any): Promise; - rename(oldName: string, newName: string): Promise; + rename(oldName: string, newName?: string): Promise; } /** - * The class constructor. - * @param {Object} config The configuration for the class - */ - interface Class { - + * The class constructor. + * @param {Object} config The configuration for the class + */ + class Class { db?: Db; name?: string; shortName?: string; @@ -353,64 +340,62 @@ declare module "orientjs" { originalName?: string; clusterIds?: number[]; /** - * Configure the class instance. - * @param {Object} config The configuration object. - */ + * Configure the class instance. + * @param {Object} config The configuration object. + */ configure(config?: any): void; /** - * Retreive a list of classes from the database. - * - * @param {Boolean} refresh Whether to refresh the list or not. - * @promise {Object[]} An array of class objects. - */ - list(limit: number, offset: number): Promise; - list(config: any): Promise; - list(refresh: boolean): Promise; + * Retreive a list of classes from the database. + * + * @param {Boolean} refresh Whether to refresh the list or not. + * @promise {Object[]} An array of class objects. + */ + list(limit: number | boolean | any, offset?: number): Promise; /** - * Find a list of records in the class. - * - * @param {Object} attributes The attributes to search with. - * @param {Integer} limit The maximum number of records to return - * @param {Integer} offset The offset to start returning records from. - * @promise {Object[]} An array of records in the class. - */ + * Find a list of records in the class. + * + * @param {Object} attributes The attributes to search with. + * @param {Integer} limit The maximum number of records to return + * @param {Integer} offset The offset to start returning records from. + * @promise {Object[]} An array of records in the class. + */ find(attributes: any, limit?: number, offset?: number): Promise; /** - * Create a record for this class. - * - * @param {Object} record The record to create. - * @promise {Object} The created record. - */ + * Create a record for this class. + * + * @param {Object} record The record to create. + * @promise {Object} The created record. + */ create(record: Record): Promise; /** - * Create a new class. - * - * @param {String} name The name of the class to create. - * @param {String} parentName The name of the parent to extend, if any. - * @param {String|Integer} cluster The cluster name or id. - * @param {Boolean} isAbstract The flag for the abstract class - * @param {Boolean} ifnotexist The flag for the if not exist class - * @promise {Object} The created class object - */ + * Create a new class. + * + * @param {string} name The name of the class to create. + * @param {string} parentName The name of the parent to extend, if any. + * @param {string|Integer} cluster The cluster name or id. + * @param {Boolean} isAbstract The flag for the abstract class + * @param {Boolean} ifnotexist The flag for the if not exist class + * @promise {Object} The created class object + */ create(name: string, parentName?: string, cluster?: string, isAbstract?: boolean, ifnotexist?: boolean): Promise; /** - * Update the given class. - * - * @param {Object} class The class settings. - * @param {Boolean} reload Whether to reload the class, default to true. - * @promise {Object} The updated class. - */ + * Update the given class. + * + * @param {Object} class The class settings. + * @param {Boolean} reload Whether to reload the class, default to true. + * @promise {Object} The updated class. + */ update(cls: any, reload: boolean): Promise; /** - * Reload the class instance. - * - * @promise {Class} The class instance. - */ + * Reload the class instance. + * + * @promise {Class} The class instance. + */ reload(): Promise; /** * Delete a class. * - * @param {String} name The name of the class to delete. + * @param {string} name The name of the class to delete. * @param {Object} config The config. * @promise {Db} The database instance. */ @@ -421,7 +406,7 @@ declare module "orientjs" { /** * Get a class by name. * - * @param {Integer|String} name The name of the class. + * @param {Integer|string} name The name of the class. * @param {Boolean} refresh Whether to refresh the data, defaults to false. * @promise {Object} The class object if it exists. */ @@ -434,31 +419,27 @@ declare module "orientjs" { */ cacheData(classes: Class[]): Db; property: Property; - } - interface Cluster { + class Cluster { name?: string; location?: string; list(refresh?: boolean): Promise; create(name: string, location?: string): Promise & Promise; get(nameOrId: string, refresh?: boolean): Promise & Promise; - get(nameOrId: number, refresh?: boolean): Promise & Promise; getByName(name: string, refresh?: boolean): Promise & Promise; getById(id: string, refresh?: boolean): Promise & Promise; drop(name: string): Promise; - count(name: string): Promise; + count(name: string): Promise; range(name: string): Promise; cacheData(clusters: Cluster[] & any[]): Db; - } /** * The sequence constructor. * @param {Object} config The configuration for the sequence */ - interface Sequence { - + class Sequence { db?: Db; name?: string; type?: string; @@ -467,62 +448,62 @@ declare module "orientjs" { start?: number; cache?: number; /** - * Configure the sequence instance. - * @param {Object} config The configuration object. - */ + * Configure the sequence instance. + * @param {Object} config The configuration object. + */ configure(config?: any): void; /** - * Retreive a list of sequences from the database. - * - * @param {Boolean} refresh Whether to refresh the list or not. - * @promise {Object[]} An array of class objects. - */ + * Retreive a list of sequences from the database. + * + * @param {Boolean} refresh Whether to refresh the list or not. + * @promise {Object[]} An array of class objects. + */ list(refresh: boolean): Promise; /** - * Create a new sequence. - * - * @param {String} name The name of the sequence to create. - * @param {String} type The type of sequence. - * @param {Integer} start The start number. - * @param {Integer} incerement The increment number. - * @param {Integer} cache The cache number - * @promise {Object} The created sequence object - */ + * Create a new sequence. + * + * @param {string} name The name of the sequence to create. + * @param {string} type The type of sequence. + * @param {Integer} start The start number. + * @param {Integer} incerement The increment number. + * @param {Integer} cache The cache number + * @promise {Object} The created sequence object + */ create(name: string, type: "ORDERED" | "CACHED", start?: number, incerement?: number, cache?: number): Promise; /** - * update a sequence. - * - * @param {String} name The name of the sequence to create. - * @param {Integer} incerement The increment number. - * @param {Integer} cache The cache number - * @param {Integer} start The start number. - * @promise {Object} The created sequence object - */ + * update a sequence. + * + * @param {string} name The name of the sequence to create. + * @param {Integer} incerement The increment number. + * @param {Integer} cache The cache number + * @param {Integer} start The start number. + * @promise {Object} The created sequence object + */ update(name: string, start?: number, incerement?: number, cache?: number): Promise; /** - * Reload the sequence instance. - * - * @promise {Sequence} The class instance. - */ + * Reload the sequence instance. + * + * @promise {Sequence} The class instance. + */ reload(): Promise; /** - * Delete a sequence. - * - * @param {String} name The name of the sequence to delete. - * @param {Object} config The config. - * @promise {Db} The database instance. - */ + * Delete a sequence. + * + * @param {string} name The name of the sequence to delete. + * @param {Object} config The config. + * @promise {Db} The database instance. + */ drop(name: string, config?: { }): Promise; /** - * Get a sequence by name. - * - * @param {Integer|String} name The name of the sequence. - * @param {Boolean} refresh Whether to refresh the data, defaults to false. - * @promise {Object} The sequence object if it exists. - */ + * Get a sequence by name. + * + * @param {Integer|string} name The name of the sequence. + * @param {Boolean} refresh Whether to refresh the data, defaults to false. + * @promise {Object} The sequence object if it exists. + */ get(name: string, refresh?: boolean): Promise; /** * Cache the given class data for fast lookup later. @@ -531,116 +512,111 @@ declare module "orientjs" { * @return {Db} The db instance. */ cacheData(sequences: Sequence[]): Db; - } interface RecordMeta { "@rid": RID; "@version": Version; - } type ODocument = Record; type BinaryRecord = Record & Buffer; - - - interface Record extends Object { + class Record extends Object { '@rid'?: RID; '@type'?: 'd' | 'b'; - '@class'?: string, + '@class'?: string; '@version'?: Version; rid?: RID; /** - * Insert the given record into the database. - * - * @param {Object} record The record to insert. - * @param {Object} options The command options. - * @promise {Object} The inserted record. - */ + * Insert the given record into the database. + * + * @param {Object} record The record to insert. + * @param {Object} options The command options. + * @promise {Object} The inserted record. + */ create(record: ODocument | Record | BinaryRecord, options?: any): Promise; /** - * Insert the given record into the database. - * - * @param {Object} record The record to insert. - * @param {Object} options The command options. - * @promise {Object} The inserted record. - */ + * Insert the given record into the database. + * + * @param {Object} record The record to insert. + * @param {Object} options The command options. + * @promise {Object} The inserted record. + */ create(records: ODocument[] | Record[] | BinaryRecord[], options?: any): Promise; /** - * Read the given record. - * - * @param {Object} record The record to load. - * @param {Object} options The query options. - * @promise {Object} The loaded record. - */ + * Read the given record. + * + * @param {Object} record The record to load. + * @param {Object} options The query options. + * @promise {Object} The loaded record. + */ get(record: Record | RID, options?: any): Promise; /** - * Read the given record. - * - * @param {Object} records The record to load. - * @param {Object} options The query options. - * @promise {Object[]} The loaded record. - */ + * Read the given record. + * + * @param {Object} records The record to load. + * @param {Object} options The query options. + * @promise {Object[]} The loaded record. + */ get(records: Record[] | RID[], options?: any): Promise; /** - * Resolve all references within the given collection of records. - * - * @param {Object[]} records The records to resolve. - * @return {Object} The records with references replaced. - */ + * Resolve all references within the given collection of records. + * + * @param {Object[]} records The records to resolve. + * @return {Object} The records with references replaced. + */ resolveReferences(records: Record[]): Record[]; /** - * Read the metadata for the given record. - * - * @param {Object} record The record to load. - * @param {Object} options The query options. - * @promise {Object} The record object with loaded meta data. - */ + * Read the metadata for the given record. + * + * @param {Object} record The record to load. + * @param {Object} options The query options. + * @promise {Object} The record object with loaded meta data. + */ meta(record: Record | RID | string, options?: any): Promise; /** - * Read the metadata for the given record. - * - * @param {Object} record The record to load. - * @param {Object} options The query options. - * @promise {Object} The record object with loaded meta data. - */ + * Read the metadata for the given record. + * + * @param {Object} record The record to load. + * @param {Object} options The query options. + * @promise {Object} The record object with loaded meta data. + */ meta(records: Record[] | RID[], options?: any): Promise; - update(): Promise; /** - * Update the given record. - * - * @param {Object} record The record to update. - * @param {Object} options The query options. - * @promise {Object} The updated record. - */ - update(record: Record | RID, options?: any): Promise; + * Update the given record. + * + * @param {Object} record The record to update. + * @param {Object} options The query options. + * @promise {Object} The updated record. + */ + update(record?: Record | RID, options?: any): Promise; delete(): Promise & Promise; /** - * Delete the given record. - * - * @param {String|RID|Object} record The record or record id to delete. - * @param {Object} options The query options. - * @promise {Object} The deleted record object. - */ + * Delete the given record. + * + * @param {string|RID|Object} record The record or record id to delete. + * @param {Object} options The query options. + * @promise {Object} The deleted record object. + */ delete(record: Record | RID, options?: any): Promise; } interface IndexConfig { - name: string, - class?: string, - properties?: string[], - type: "UNIQUE" | "NOTUNIQUE" | "FULLTEXT" | "DICTIONARY" | "UNIQUE_HASH_INDEX" | "NOTUNIQUE_HASH_INDEX" | "FULLTEXT_HASH_INDEX" | "DICTIONARY_HASH_INDEX" | "SPATIAL", - keyType?: string, - metadata?: any, - engine?: "LUCENE" | "COLA" | string + name: string; + class?: string; + properties?: string[]; + type: "UNIQUE" | "NOTUNIQUE" | "FULLTEXT" | "DICTIONARY" | "UNIQUE_HASH_INDEX" | "NOTUNIQUE_HASH_INDEX" | "FULLTEXT_HASH_INDEX" | "DICTIONARY_HASH_INDEX" | "SPATIAL"; + keyType?: string; + metadata?: any; + engine?: "LUCENE" | "COLA" | string; } interface IndexEntry { - key: string, - value: String | RID + key: string; + value: string | RID; } interface Index { cached: boolean; @@ -650,16 +626,12 @@ declare module "orientjs" { clusters: Cluster[]; type: string; configure(config: any): void; - add(idx: IndexEntry): Promise; - add(idx: IndexEntry[]): Promise; - get(key: string): Promise; - set(key: string, value: string): Promise; - set(key: string, value: RID): Promise; + add(idx: IndexEntry | IndexEntry[]): Promise; + set(key: string, value: string | RID): Promise; delete(name: string): Promise; select(): Statement; list(refresh?: boolean): Promise; - create(config: IndexConfig): Promise; - create(configs: IndexConfig[]): Promise; + create(config: IndexConfig | IndexConfig[]): Promise; drop(name: string): Promise; get(name: string, refresh?: boolean): Promise; cacheData(indices: any[]): Promise; @@ -674,8 +646,7 @@ declare module "orientjs" { delete(param?: string | string[]): Statement; into(param?: string): Statement; create(paramtype?: string, paramname?: string): Statement; - from(param?: string): Statement; - from(param?: any): Statement; + from(param?: string | any): Statement; to(param?: any): Statement; set(param?: any): Statement; content(param?: any): Statement; @@ -695,8 +666,7 @@ declare module "orientjs" { offset(value?: number): Statement; limit(value: number): Statement; fetch(param?: any): Statement; - let(name: string, value: string): Statement; - let(name: string, value: Statement): Statement; + let(name: string, value: string | Statement): Statement; lock(param: any): Statement; if(condition: SqlExpression, statements: Statement[]): Statement; @@ -708,20 +678,16 @@ declare module "orientjs" { retry(retryLimit?: number): Statement; wait(waitLimit: number): Statement; return(value: SqlExpression): Statement; - lucene(property: string, luceneQuery: string): Statement; - lucene(property: any, luceneQuery: string): Statement; - near(latitudeProperty: string, longitudeProperty: string, longitude: number, latitude: number, maxDistanceInKms: number): Statement; - near(prop: any, maxDistanceInKms: number, longitude: number, latitude: number): Statement; - within(latitudeProperty: string, longitudeProperty: string, box: Array): Statement; + lucene(property: string | any, luceneQuery: string): Statement; + near(latitudeProperty: string | any, longitudeProperty: string | number, longitude: number, latitude?: number, maxDistanceInKms?: number): Statement; + within(latitudeProperty: string, longitudeProperty: string, box: number[]): Statement; addParams(key: string, value: any): Statement; addParams(value: any): Statement; token(value: any): Statement; buildStatement(): string; - } interface Query { - transform(transformer: (item: Record) => T): Query; column(name: string): Query; defaults(defaults: any): Query; @@ -729,10 +695,6 @@ declare module "orientjs" { all(params?: any): Promise; scalar(params?: any): Promise; exec(params?: any): Promise; - one(params?: any): Promise; - all(params?: any): Promise; - scalar(params?: any): Promise; - exec(params?: any): Promise; } interface Transaction { @@ -743,11 +705,9 @@ declare module "orientjs" { create(record: Record): Transaction; update(record: Record): Transaction; delete(record: Record): Transaction; - } interface DbConnectionConfig { - useToken?: boolean; name?: string; username?: string; @@ -758,7 +718,7 @@ declare module "orientjs" { type?: string; storage?: string; token?: any; - transformers?: ((item: Record) => any)[]; + transformers?: Array<((item: Record) => any)>; } interface RawExpression { @@ -766,16 +726,14 @@ declare module "orientjs" { value: string; as(alias: string): RawExpression; } - - - interface AbsSqlFunction { - new(field: number | string): AbsSqlFunction; + class AbsSqlFunction { + constructor(field: number | string); } - interface AvgSqlFunction { - new(field: string): AvgSqlFunction; + class AvgSqlFunction { + constructor(field: string); } - interface SequenceSqlFunction { - new(name: string): SequenceSqlFunction; + class SequenceSqlFunction { + constructor(name: string); next(): number; current(): number; reset(): number; @@ -795,10 +753,10 @@ declare module "orientjs" { limit?: number; token?: any; class?: string; - language?: "SQL" | "Javascript" + language?: "SQL" | "Javascript"; } - interface Db extends events.EventEmitter { + class Db extends events.EventEmitter { sessionId: number; forcePrepare: boolean; name: string; @@ -825,94 +783,94 @@ declare module "orientjs" { */ configure(config: DbConfig): Db; /** - * Initialize the database instance. - */ + * Initialize the database instance. + */ init(): void; /** - * Open the database. - * - * @promise {Db} The open db instance. - */ + * Open the database. + * + * @promise {Db} The open db instance. + */ open(): Promise; /** - * Close the database. - * - * @promise {Db} The now closed db instance. - */ + * Close the database. + * + * @promise {Db} The now closed db instance. + */ close(): Promise; /** - * Send the given operation to the server, ensuring the - * database is open first. - * - * @param {Integer} operation The operation to send. - * @param {Object} data The data for the operation. - * @promise {Mixed} The result of the operation. - */ + * Send the given operation to the server, ensuring the + * database is open first. + * + * @param {Integer} operation The operation to send. + * @param {Object} data The data for the operation. + * @promise {Mixed} The result of the operation. + */ send(operation: number, data: any): Promise; /** - * Reload the configuration for the database. - * - * @promise {Db} The database with reloaded configuration. - */ + * Reload the configuration for the database. + * + * @promise {Db} The database with reloaded configuration. + */ reload(): Promise; /** - * Begin a new transaction. - * - * @return {Transaction} The transaction instance. - */ + * Begin a new transaction. + * + * @return {Transaction} The transaction instance. + */ begin(): Transaction; /** - * Execute an SQL query against the database and retreive the raw, parsed response. - * - * @param {String} query The query or command to execute. - * @param {Object} options The options for the query / command. - * @promise {Mixed} The results of the query / command. - */ + * Execute an SQL query against the database and retreive the raw, parsed response. + * + * @param {string} query The query or command to execute. + * @param {Object} options The options for the query / command. + * @promise {Mixed} The results of the query / command. + */ exec(query: string, options?: QueryOptions): Promise; /** * Execute an SQL query against the database and retreive the results * - * @param {String} query The query or command to execute. + * @param {string} query The query or command to execute. * @param {Object} options The options for the query / command. * @promise {Mixed} The results of the query / command. */ query(command: string, options?: QueryOptions): Promise; /** - * Execute a live query against the database - * - * @param {String} query The query or command to execute. - * @param {Object} options The options for the query / command. - * @promise {Mixed} The token of the live query. - */ + * Execute a live query against the database + * + * @param {string} query The query or command to execute. + * @param {Object} options The options for the query / command. + * @promise {Mixed} The token of the live query. + */ liveQuery(command: string, options?: QueryOptions): Promise; /** - * Normalize a result, where possible. - * @param {Object} result The result to normalize. - * @return {Object} The normalized result. - */ + * Normalize a result, where possible. + * @param {Object} result The result to normalize. + * @return {Object} The normalized result. + */ normalizeResult(result: any): any; /** - * Normalize the content for a result. - * @param {Mixed} content The content to normalize. - * @return {Mixed} The normalized content. - */ + * Normalize the content for a result. + * @param {Mixed} content The content to normalize. + * @return {Mixed} The normalized content. + */ normalizeResultContent(content: any): any; /** - * Register a transformer function for documents of the given class. - * This function will be invoked for each document of the specified class - * in all future result sets. - * - * @param {String} className The name of the document class. - * @param {Function} transformer The transformer function. - * @return {Db} The database instance. - */ + * Register a transformer function for documents of the given class. + * This function will be invoked for each document of the specified class + * in all future result sets. + * + * @param {string} className The name of the document class. + * @param {Function} transformer The transformer function. + * @return {Db} The database instance. + */ registerTransformer(className: string, transformer: (item: Record) => T): Db; /** - * Transform a document according to its `@class` property, using the registered transformers. - * @param {Object} document The document to transform. - * @return {Mixed} The transformed document. - */ + * Transform a document according to its `@class` property, using the registered transformers. + * @param {Object} document The document to transform. + * @return {Mixed} The transformed document. + */ transformDocument(document: ODocument): any; /** @@ -922,10 +880,10 @@ declare module "orientjs" { */ createQuery(): Statement; /** - * Create a raw expression. - * - * @return {RawExpression} The raw expression instance. - */ + * Create a raw expression. + * + * @return {RawExpression} The raw expression instance. + */ rawExpression(param: string): RawExpression; /** Create a sql Function. @@ -935,50 +893,47 @@ declare module "orientjs" { sqlFunction(options?: any): SqlFunction; /** - * Create a create query. - * - * @return {Query} The query instance. - */ + * Create a create query. + * + * @return {Query} The query instance. + */ create(params?: any): Statement; create(paramtype: string, paramname: string): Statement; /** - * Create a select query. - * - * @return {Query} The query instance. - */ + * Create a select query. + * + * @return {Query} The query instance. + */ select(params?: any): Statement; /** - * Create a traverse query. - * - * @return {Query} The query instance. - */ + * Create a traverse query. + * + * @return {Query} The query instance. + */ traverse(params?: any): Statement; /** - * Create an insert query. - * - * @return {Query} The query instance. - */ + * Create an insert query. + * + * @return {Query} The query instance. + */ insert(params?: any): Statement; /** - * Create an update query. - * - * @return {Query} The query instance. - */ + * Create an update query. + * + * @return {Query} The query instance. + */ update(params?: any): Statement; /** - * Create a delete query. - * - * @return {Query} The query instance. - */ + * Create a delete query. + * + * @return {Query} The query instance. + */ delete(params?: any): Statement; - insert(param: string | string[]): Statement; - update(param: string | string[]): Statement; - delete(param: string | string[]): Statement; /** - * Create a transactional query. - * - * @return {Query} The query instance. - */ + * Create a transactional query. + * + * @return {Query} The query instance. + */ let(params?: any): Statement; let(name: string, value: string | Statement): Statement; /** Create a transactional query with if. @@ -987,42 +942,40 @@ declare module "orientjs" { */ if(condition: SqlExpression, statements: Statement[]): Statement; /** Create a transactional query with if. - * - * @return {Query} The query instance. - */ + * + * @return {Query} The query instance. + */ if(condition: SqlExpression, ...statements: Statement[]): Statement; /** - * Escape the given input. - * - * @param {String} input The input to escape. - * @return {String} The escaped input. - */ + * Escape the given input. + * + * @param {string} input The input to escape. + * @return {string} The escaped input. + */ escape(input: string): string; /** - * Create a context for a user, using their authentication token. - * The context includes the query builder methods, which will be executed - * on behalf of the user. - * - * @param {Buffer|String} token The authentication token. - * @return {Object} The object containing the query builder methods. - */ + * Create a context for a user, using their authentication token. + * The context includes the query builder methods, which will be executed + * on behalf of the user. + * + * @param {Buffer|string} token The authentication token. + * @return {Object} The object containing the query builder methods. + */ createUserContext(token: any): any; /** * Create a orient function from a plain Javascript function * - * @param {String} name The name of the function + * @param {string} name The name of the function * @param {Object} fn Plain Javascript function to stringify * @param {Object} options Not currently used but will be used for 'IDEMPOTENT' arg * @promise {Mixed} The results of the query / command. */ - createFn(name: string, fn: Function, options?: any): Promise; - createFn(fn: Function, options?: any): Promise; - + createFn(name: string, fn: (...args: any[]) => any, options?: any): Promise; + createFn(fn: (...args: any[]) => any, options?: any): Promise; } interface ServerConfiguration { - get(name: string): string; set(key: string, value: string): string; list(): any; @@ -1032,10 +985,10 @@ declare module "orientjs" { * # Server * Represents a connection to an orientdb server. * - * @param {String|Object} options The server URL, or configuration object + * @param {string|Object} options The server URL, or configuration object */ - interface Server { - new(options?: ServerConfig): Server; + class Server { + constructor(options?: ServerConfig); config: ServerConfiguration; logger: Logger; @@ -1044,11 +997,11 @@ declare module "orientjs" { */ init(): void; /** - * Configure the server instance. - * - * @param {Object} config The configuration for the server. - * @return {Server} The configured server object. - */ + * Configure the server instance. + * + * @param {Object} config The configuration for the server. + * @return {Server} The configured server object. + */ configure(config: ServerConfig): Server; /** * Configure the transport for the server. @@ -1073,106 +1026,83 @@ declare module "orientjs" { */ send(operation: number, options: any): any; /** - * Close the connection to the server. - * - * @return {Server} the disconnected server instance - */ + * Close the connection to the server. + * + * @return {Server} the disconnected server instance + */ close(): Server; /** - * Use the database with the given name / config. - * - * @param {String|Object} config The database name, or configuration object. - * @return {Db} The database instance. - */ - use(name?: string): Db; + * Use the database with the given name / config. + * + * @param {string|Object} config The database name, or configuration object. + * @return {Db} The database instance. + */ + use(name?: string | DbConfig): Db; /** - * Use the database with the given name / config. - * - * @param {String|Object} config The database name, or configuration object. - * @return {Db} The database instance. - */ - use(config?: DbConfig): Db; + * Create a database with the given name / config. + * + * @param {string|Object} config The database name or configuration object. + * @promise {Db} The database instance + */ + create(name: string | DbConfig): Promise; /** - * Create a database with the given name / config. - * - * @param {String|Object} config The database name or configuration object. - * @promise {Db} The database instance - */ - create(name: string): Promise; + * Destroy a database with the given name / config. + * + * @param {string|Object} config The database name or configuration object. + * @promise {Mixed} The server response. + */ + drop(name: string | DbConfig): Promise; /** -* Create a database with the given name / config. -* -* @param {String|Object} config The database name or configuration object. -* @promise {Db} The database instance -*/ - create(config: DbConfig): Promise; - /** - * Destroy a database with the given name / config. - * - * @param {String|Object} config The database name or configuration object. - * @promise {Mixed} The server response. - */ - drop(name: string): Promise; - /** - * Destroy a database with the given name / config. - * - * @param {String|Object} config The database name or configuration object. - * @promise {Mixed} The server response. - */ - drop(config: DbConfig): Promise; - /** - * List all the databases on the server. - * - * @return {Db[]} An array of databases. - */ + * List all the databases on the server. + * + * @return {Db[]} An array of databases. + */ list(): Promise; /** - * Determine whether a database exists with the given name. - * - * @param {String} name The database name. - * @param {String} storageType The storage type, defaults to `plocal`. - * @promise {Boolean} true if the database exists. - */ + * Determine whether a database exists with the given name. + * + * @param {string} name The database name. + * @param {string} storageType The storage type, defaults to `plocal`. + * @promise {Boolean} true if the database exists. + */ exists(name: string, storageType?: string): Promise; /** - * Freeze the database with the given name. - * - * @param {String} name The database name. - * @param {String} storageType The storage type, defaults to `plocal`. - * @return {Object} The response from the server. - */ + * Freeze the database with the given name. + * + * @param {string} name The database name. + * @param {string} storageType The storage type, defaults to `plocal`. + * @return {Object} The response from the server. + */ freeze(name: string, storageType?: string): any; /** - * Release the database with the given name. - * - * @param {String} name The database name. - * @param {String} storageType The storage type, defaults to `plocal`. - * @return {Object} The response from the server. - */ + * Release the database with the given name. + * + * @param {string} name The database name. + * @param {string} storageType The storage type, defaults to `plocal`. + * @return {Object} The response from the server. + */ release(name: string, storageType?: string): any; shutdown(): Promise; } - interface ODatabase extends Db { - new(config?: { + class ODatabase extends Db { + constructor(config?: { host: string, port?: number, username?: string, password?: string, name: string - }): ODatabase; - + }); } interface ServerConfig { - useToken?: boolean; host: string; port?: number; username?: string; password?: string; - servers?: ServerConfig[] + servers?: ServerConfig[]; } interface DbConfig { @@ -1182,8 +1112,9 @@ declare module "orientjs" { username?: string; password?: string; } - - interface OrientJs extends Server { } + interface OrientJs extends Server { + name: string; + } } - export = ojs; -} \ No newline at end of file +} +export = orientjs.ojs; diff --git a/types/orientjs/orientjs-tests.ts b/types/orientjs/orientjs-tests.ts index 464d416122..06a16480bb 100644 --- a/types/orientjs/orientjs-tests.ts +++ b/types/orientjs/orientjs-tests.ts @@ -11,4 +11,3 @@ let db = dbserver.use({ username: 'root', password: 'root' }); -