From 8bf14fc21f3bafd0aa9fade2b06a50f9f028747d Mon Sep 17 00:00:00 2001 From: Saeed Tabrizi Date: Wed, 19 Jul 2017 18:36:11 +0430 Subject: [PATCH 1/4] orientjs d.ts update to support version 3.0.0 --- types/orientjs/index.d.ts | 1142 ++++++++++++++++++++++++++++------ types/orientjs/tsconfig.json | 2 +- types/orientjs/tslint.json | 1 + 3 files changed, 951 insertions(+), 194 deletions(-) create mode 100644 types/orientjs/tslint.json diff --git a/types/orientjs/index.d.ts b/types/orientjs/index.d.ts index 679fc7c70a..4fc16bffe3 100644 --- a/types/orientjs/index.d.ts +++ b/types/orientjs/index.d.ts @@ -1,83 +1,46 @@ -// Type definitions for orientjs v2.1.0 +// Type definitions for orientjs v3.0.0 // Project: https://github.com/orientechnologies/orientjs -// Definitions by: Saeed Tabrizi -// Definitions: https://github.com/borisyankov/DefinitelyTyped -// TypeScript Version: 2.3 - +// Definitions by: [Saeed Tabrizi] +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Last Update : 19-7-2017 +// Compatible with Orientdb >= 2.2.15 and orientjs >= 2.2.x features . // Developed with love in www.nowcando.com +// /// /* =================== USAGE =================== - import orientjs = require('orientjs'); - var dbserver = orientjs({ + let dbserver = orientjs({ host: 'localhost', port: 2424, username: 'root', password: 'root' }); - var db = dbserver.use({ + let db = dbserver.use({ name: 'mytestdb', username: 'root', password: 'root' }); - =============================================== */ +/** 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) + * @version 3.0.0 + * +*/ declare module "orientjs" { import events = require('events'); - import Promise = require('bluebird'); - function ojs(config: any): ojs.OrientJs; + import Promise = require('bluebird'); + function ojs(config: ojs.ServerConfig): ojs.OrientJs; module ojs { - module errors { - interface BaseError { - name: string; - init(name: string): void; - } - interface OperationError extends BaseError { - message: string; - date: any; - } - interface RequestError extends OperationError { } - } - - module Migration { - interface Migration { - name: string; - server: Server; - db: Db; - configure(config?: any): void; - up(): Promise; - down(): Promise; - - - } - - class Manager { - - constructor(config?: any); - name: string; - server: Server; - db: Db; - dir: string; - className: string; - create(param: string): Promise; - generateMigration(config: any): string; - list(): Promise; - listAvailable(): Promise; - ensureStructure: Promise; - listApplied(): Promise; - up(limit?: number): Promise; - down(limit?: number): Promise; - loadMigration(name: string): Migration; - applyMigration(name: string): Promise; - revertMigration(name: string): Promise; - } - } - + 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"; enum DataTypes { Boolean = 0, Integer = 1, @@ -101,8 +64,129 @@ declare module "orientjs" { Date = 19, Custom = 20, Decimal = 21, - LinkBag = 22, + LinkBag = 22 + } + module errors { + interface BaseError { + name: string; + init(name: string): void; + } + interface OperationError extends BaseError { + message: string; + date: any; + } + interface RequestError extends OperationError { } + } + + module Migration { + type MigrationManagerConfig = { + name?: string, + db?: Db, + dir?: string, + className?: string + }; + + class Manager extends MigrationManager{ + constructor (config: MigrationManagerConfig); + } + interface Migration { + name: string; + server: Server; + db: Db; + configure(config?: any): void; + up(): Promise; + down(): Promise; + + } + + class MigrationManager { + /** + * # Migration Manager + * + * @param {Object} config The configuration for the migration manager. + */ + constructor(config?: MigrationManagerConfig); + + name: string; + server: Server; + db: Db; + dir: string; + 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(param: string): Promise; + /** + * 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(): Promise; + /** + * 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. + */ + ensureStructure: Promise; + /** + * 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + revertMigration(name: string): Promise; + } } interface Logger { @@ -117,75 +201,245 @@ declare module "orientjs" { 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; + 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; + } + + interface CustomField { + /** + * Get the value of the given custom field. + * + * @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. + * @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. + * @promise {Object|null} The new set of custom fields, or null if none are present. + */ + unset(key: string): CustomField; + } + + interface PropertyCreateConfig { + name: string; + type: PropertyType; + default?: any; + ifnotexist?: boolean; + unsafe?: boolean; + mandatory?: boolean; + readonly?: boolean; + notNull?: boolean; + collate?: string; + linkedClass?: string; + linkedType?: string; + regexp?: RegExp | string; + min?: number; + max?: number; + custom?: { + fields?: CustomField[] + } + } + + interface PropertyUpdateConfig { + name: string; + type: PropertyType; + default?: any; + mandatory?: boolean; + readonly?: boolean; + notNull?: boolean; + collate?: string; + linkedClass?: string; + linkedType?: string; + regexp?: RegExp | string; + min?: number; + max?: number; + custom?: { + fields?: CustomField[] + } } interface Property { - class: Class; - name: string; - originalName: string; - type: any; - mandatory: boolean; - readonly: boolean; - notNull: boolean; - collate: string; - linkedClass: Class; - regexp: RegExp; - min: any; - max: any; + class?: Class; + name?: string; + originalName?: string; + type?: PropertyType; + mandatory?: boolean; + readonly?: boolean; + notNull?: boolean; + collate?: string; + linkedClass?: string; + linkedType?: PropertyType; + regexp?: RegExp | string; + min?: number; + max?: number; + custom?: { + fields?: CustomField[] + } configure(config?: any): void; reload(): Promise; rename(newName: string): Promise; - list(): Promise & Promise; - create(config: string, reload?: boolean): Promise & Promise; - create(config?: any, reload?: boolean): Promise & Promise; - create(...config: any[]): Promise & Promise; - get(name: string): Promise & Promise; - update(config: any, reload?: boolean): Promise & Promise; - drop(name: string): Promise; - alter(name: string, setting?: any): Promise & Promise; - rename(oldName: string, newName: string): Promise; + list(): Promise; + /** + * Create a new property. + * + * @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(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(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; } + /** + * The class constructor. + * @param {Object} config The configuration for the class + */ interface Class { - db: Db; - name: string; - shortName: string; - defaultClusterId: any; - superClass: string; - originalName: string; - clusterIds: number[]; - + db?: Db; + name?: string; + shortName?: string; + defaultClusterId?: any; + superClass?: string; + originalName?: string; + clusterIds?: number[]; + /** + * Configure the class instance. + * @param {Object} config The configuration object. + */ configure(config?: any): void; - list(limit: number, offset: number): Promise & Promise & Promise; - list(config: any): Promise & Promise & Promise; - list(refresh: boolean): Promise & Promise & Promise; - find(attributes: any, limit: number, offset: number): Promise; - create(record: Record): Promise & Promise; - create(name: string, parentName?: string, cluster?: string, isAbstract?: boolean): Promise & Promise; - update(cls: any, reload: boolean): Promise & 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, offset: number): Promise; + list(config: any): Promise; + list(refresh: boolean): 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(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(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(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(cls: any, reload: boolean): Promise; + /** + * Reload the class instance. + * + * @promise {Class} The class instance. + */ reload(): Promise; - drop(name: string): Promise; - get(name: string, refresh?: boolean): Promise & Promise; - cacheData(classes: Class[] & any[]): Db; + /** + * Delete a class. + * + * @param {String} name The name of the class to delete. + * @param {Object} config The config. + * @promise {Db} The database instance. + */ + drop(name: string, config?: { + ifexist?: boolean, + force?: boolean + }): Promise; + /** + * Get a class by name. + * + * @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. + */ + get(name: string, refresh?: boolean): Promise; + /** + * Cache the given class data for fast lookup later. + * + * @param {Object[]} classes The class objects to cache. + * @return {Db} The db instance. + */ + cacheData(classes: Class[]): Db; property: Property; } interface Cluster { - name: string; - location: string; + name?: string; + location?: string; list(refresh?: boolean): Promise; create(name: string, location?: string): Promise & Promise; get(nameOrId: string, refresh?: boolean): Promise & Promise; @@ -199,24 +453,195 @@ declare module "orientjs" { } + /** + * The sequence constructor. + * @param {Object} config The configuration for the sequence + */ + interface Sequence { + + db?: Db; + name?: string; + type?: string; + value?: number; + incr?: number; + start?: number; + cache?: number; + /** + * 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. + */ + + 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(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(name: string, start?: number, incerement?: number, cache?: number): Promise; + /** + * 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. + */ + 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(name: string, refresh?: boolean): Promise; + /** + * Cache the given class data for fast lookup later. + * + * @param {Object[]} sequences The sequence objects to cache. + * @return {Db} The db instance. + */ + cacheData(sequences: Sequence[]): Db; + + } + interface RecordMeta { - "@rid": string|RID; - "@version": string|number; + "@rid": RID; + "@version": Version; } - interface Record { - rid: RID; - create(record: any, options?: any): Promise ; - get(record: Record | RID | string, options?: any): Promise; - resolveReferences(records: Record[] & any[]): any; - meta(record: Record | RID | string, options?: any): Promise ; - update(): Promise & Promise; - update(record: Record | RID | string, options?: any): Promise ; - delete(): Promise & Promise; - delete(record: Record | RID | string, options?: any): Promise ; + type ODocument = Record; + type BinaryRecord = Record & Buffer; + + + interface Record extends Object { + '@rid'?: RID; + '@type'?: 'd' | 'b'; + '@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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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; + + 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(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 } + interface IndexEntry { + key: string, + value: String | RID + } interface Index { cached: boolean; db: Db; @@ -225,35 +650,36 @@ declare module "orientjs" { clusters: Cluster[]; type: string; configure(config: any): void; - add(args: any): Promise; - add(args: any[]): Promise; + add(idx: IndexEntry): Promise; + add(idx: IndexEntry[]): Promise; get(key: string): Promise; set(key: string, value: string): Promise; set(key: string, value: RID): Promise; delete(name: string): Promise; select(): Statement; list(refresh?: boolean): Promise; - create(config: any): Promise; + create(config: IndexConfig): Promise; + create(configs: IndexConfig[]): Promise; drop(name: string): Promise; get(name: string, refresh?: boolean): Promise; cacheData(indices: any[]): Promise; } - + type SqlExpression = string | RawExpression | SqlFunction; interface Statement extends Query { - select(param: string | string[]): Statement; - traverse(param: string | string[]): Statement; - strategy(param: string): Statement; - insert(param: string | string[]): Statement; - update(param: string | string[]): Statement; - delete(param: string | string[]): Statement; - into(param: string): Statement; - create(paramtype: string, paramname: string): Statement; - from(param: string): Statement; - from(param: any): Statement; - to(param: any): Statement; - set(param: any): Statement; - content(param: any): Statement; - increment(property: string, value: any): Statement; + select(param?: string | string[]): Statement; + traverse(param?: string | string[]): Statement; + strategy(param?: string): Statement; + insert(param?: string | string[]): Statement; + update(param?: string | string[]): Statement; + delete(param?: string | string[]): Statement; + into(param?: string): Statement; + create(paramtype?: string, paramname?: string): Statement; + from(param?: string): Statement; + from(param?: any): Statement; + to(param?: any): Statement; + set(param?: any): Statement; + content(param?: any): Statement; + increment(property?: string, value?: any): Statement; add(property: string, value: any): Statement; remove(property: string, value: any): Statement; put(property: string, keysValues: any): Statement; @@ -266,16 +692,22 @@ declare module "orientjs" { group(param: any): Statement; order(param: any): Statement; skip(value: number): Statement; - offset(value: number): Statement; + offset(value?: number): Statement; limit(value: number): Statement; - fetch(param: any): Statement; + fetch(param?: any): Statement; let(name: string, value: string): Statement; let(name: string, value: Statement): Statement; lock(param: any): Statement; + + if(condition: SqlExpression, statements: Statement[]): Statement; + if(condition: SqlExpression, ...statements: Statement[]): Statement; + rollback(param?: any): Statement; + sleep(ms?: number): Statement; + commit(retryLimit?: number): Statement; retry(retryLimit?: number): Statement; wait(waitLimit: number): Statement; - return(value: string): 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; @@ -290,11 +722,11 @@ declare module "orientjs" { interface Query { - transform(transformer: any): Query; + transform(transformer: (item: Record) => T): Query; column(name: string): Query; defaults(defaults: any): Query; - one(params?: any): Promise ; - all(params?: any): Promise ; + one(params?: any): Promise; + all(params?: any): Promise; scalar(params?: any): Promise; exec(params?: any): Promise; one(params?: any): Promise; @@ -308,31 +740,62 @@ declare module "orientjs" { id: number; commit(): Promise; - create(record: any): Transaction; - update(record: any): Transaction; - delete(record: any): Transaction; + create(record: Record): Transaction; + update(record: Record): Transaction; + delete(record: Record): Transaction; } interface DbConnectionConfig { - useToken: boolean; - name: string; - username: string; - password: string; - sessionId: number; - forcePrepare: boolean; - server: Server; - type: string; - storage: string; - token: any; - transformers: any; + useToken?: boolean; + name?: string; + username?: string; + password?: string; + sessionId?: number; + forcePrepare?: boolean; + server?: Server; + type?: string; + storage?: string; + token?: any; + transformers?: ((item: Record) => any)[]; } - interface DbConfig { - name: string; - type: string; - storage: string; + interface RawExpression { + db: Db; + value: string; + as(alias:string): RawExpression; + } + + + interface AbsSqlFunction { + new (field: number | string): AbsSqlFunction; + } + interface AvgSqlFunction { + new (field: string): AvgSqlFunction; + } + interface SequenceSqlFunction { + new (name: string): SequenceSqlFunction; + next(): number; + current(): number; + reset(): number; + } + + interface SqlFunction { + db: Db; + abs: AbsSqlFunction; + avg: AbsSqlFunction; + sequence: SequenceSqlFunction; + } + + interface QueryOptions { + params?:any; + mode?: "s" | "a" | "l"; + fetchPlan?: any; + limit?: number; + token?:any; + class?:string; + language?: "SQL" | "Javascript" } interface Db extends events.EventEmitter { @@ -340,8 +803,10 @@ declare module "orientjs" { forcePrepare: boolean; name: string; server: Server; - type: string; - storage: string; + type: "graph" | "document"; + storage: "plocal" | "memory"; + username: string; + password: string; token: any; dataSegments: any[]; transactionId: number; @@ -352,51 +817,210 @@ declare module "orientjs" { cluster: Cluster; record: Record; index: Index; - - + sequence: Sequence; + /** + * Configure the database instance. + * @param {Object} config The configuration for the database. + * @return {Db} The configured database object. + */ configure(config: DbConfig): Db; + /** + * Initialize the database instance. + */ init(): void; + /** + * Open the database. + * + * @promise {Db} The open db instance. + */ open(): Promise; + /** + * 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(operation: number, data: any): Promise; + /** + * 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(): Transaction; - exec(query: string, options?: any): Promise; - query(command: string, options?: any): Promise; - liveQuery(command: string, options?: any): Promise; + /** + * 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 {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. + */ + liveQuery(command: string, options?: QueryOptions): Promise; + /** + * 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. + */ normalizeResultContent(content: any): any; - registerTransformer(className: string, transformer: Function): Db; - transformDocument(document: 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. + */ + 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. + */ + transformDocument(document: ODocument): any; + + /** + * Create a query instance for this database. + * + * @return {Query} The query instance. + */ createQuery(): Statement; + /** + * Create a raw expression. + * + * @return {RawExpression} The raw expression instance. + */ + rawExpression(param: string): RawExpression; + + /** Create a sql Function. + * + * @return {SqlFunction} The sql function instance. + */ + sqlFunction(options?: any): SqlFunction; + + /** + * 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. + */ select(params?: any): Statement; + /** + * Create a traverse query. + * + * @return {Query} The query instance. + */ traverse(params?: any): Statement; + /** + * Create an insert query. + * + * @return {Query} The query instance. + */ insert(params?: any): Statement; + /** + * Create an update query. + * + * @return {Query} The query instance. + */ update(params?: any): Statement; + /** + * 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. + */ let(params?: any): Statement; - insert(param: string|string[]): Statement; - update(param: string|string[]): Statement; - delete(param: string|string[]): Statement; - let(name: string, value: string|Statement): Statement; + let(name: string, value: string | Statement): Statement; +/** Create a transactional query with if. + * + * @return {Query} The query instance. + */ + if(condition: SqlExpression, statements: Statement[]): Statement; + /** Create a transactional query with if. + * + * @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(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. + */ createUserContext(token: any): any; + + /** + * Create a orient function from a plain Javascript 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; } - interface ServerConfig { - constructor(config?: any):ServerConfig; - useToken: boolean; - host: string; - port: number; - username: string; - password: string; - } - interface ServerConfiguration { get(name: string): string; @@ -404,30 +1028,162 @@ declare module "orientjs" { list(): any; } + /** + * # Server + * Represents a connection to an orientdb server. + * + * @param {String|Object} options The server URL, or configuration object + */ interface Server { - + new (options?: ServerConfig): Server; config: ServerConfiguration; logger: Logger; + + /** + * Initialize the server instance. + */ init(): void; - configure(): Server; + /** + * 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. + * + * @param {Object} config The server config. + * @return {Server} The configured server object. + */ + configureTransport(config: any): Server; + /** + * Configure the logger for the server. + * + * @param {Object} config The logger config + * @return {Server} The server instance with the configured logger. + */ configureLogger(logger: Logger): Server; + /** + * Send an operation to the server, + * + * @param {Integer} operation The id of the operation to send. + * @param {Object} options The options for the operation. + * @promise {Mixed} The result of the operation. + */ send(operation: number, options: any): any; + /** + * Close the connection to the server. + * + * @return {Server} the disconnected server instance + */ close(): Server; - use(config: string): Db; - use(config?: any): Db; - create(config: string): Promise; + /** + * 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(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): 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; - create(config: any): Promise; - drop(config: 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): 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(): 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. + */ 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(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(name: string, storageType?: string): any; + + shutdown(): Promise; } - interface OrientJs extends Server { + + interface ODatabase extends Db { + new (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[] + } + + interface DbConfig { + name: string; + type?: string; + storage?: string; + username?: string; + password?: string; + } + + interface OrientJs extends Server { } } export = ojs; -} +} \ No newline at end of file diff --git a/types/orientjs/tsconfig.json b/types/orientjs/tsconfig.json index f0aee4d991..7c730bcc51 100644 --- a/types/orientjs/tsconfig.json +++ b/types/orientjs/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/orientjs/tslint.json b/types/orientjs/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/orientjs/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b9f2a3e762933e54fee991fbd63c3d0f55ecaffa Mon Sep 17 00:00:00 2001 From: Saeed Tabrizi Date: Wed, 19 Jul 2017 19:06:21 +0430 Subject: [PATCH 2/4] a fix for tslint. --- types/orientjs/index.d.ts | 32 ++++++++++++++++---------------- types/orientjs/orientjs-tests.ts | 22 +++++----------------- 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/types/orientjs/index.d.ts b/types/orientjs/index.d.ts index 4fc16bffe3..e460074336 100644 --- a/types/orientjs/index.d.ts +++ b/types/orientjs/index.d.ts @@ -87,8 +87,8 @@ declare module "orientjs" { className?: string }; - class Manager extends MigrationManager{ - constructor (config: MigrationManagerConfig); + class Manager extends MigrationManager { + constructor(config: MigrationManagerConfig); } interface Migration { name: string; @@ -374,7 +374,7 @@ declare module "orientjs" { * @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; + find(attributes: any, limit?: number, offset?: number): Promise; /** * Create a record for this class. * @@ -764,18 +764,18 @@ declare module "orientjs" { interface RawExpression { db: Db; value: string; - as(alias:string): RawExpression; + as(alias: string): RawExpression; } interface AbsSqlFunction { - new (field: number | string): AbsSqlFunction; + new(field: number | string): AbsSqlFunction; } interface AvgSqlFunction { - new (field: string): AvgSqlFunction; + new(field: string): AvgSqlFunction; } interface SequenceSqlFunction { - new (name: string): SequenceSqlFunction; + new(name: string): SequenceSqlFunction; next(): number; current(): number; reset(): number; @@ -789,12 +789,12 @@ declare module "orientjs" { } interface QueryOptions { - params?:any; + params?: any; mode?: "s" | "a" | "l"; fetchPlan?: any; limit?: number; - token?:any; - class?:string; + token?: any; + class?: string; language?: "SQL" | "Javascript" } @@ -981,10 +981,10 @@ declare module "orientjs" { */ let(params?: any): Statement; let(name: string, value: string | Statement): Statement; -/** Create a transactional query with if. - * - * @return {Query} The query instance. - */ + /** Create a transactional query with if. + * + * @return {Query} The query instance. + */ if(condition: SqlExpression, statements: Statement[]): Statement; /** Create a transactional query with if. * @@ -1035,7 +1035,7 @@ declare module "orientjs" { * @param {String|Object} options The server URL, or configuration object */ interface Server { - new (options?: ServerConfig): Server; + new(options?: ServerConfig): Server; config: ServerConfiguration; logger: Logger; @@ -1155,7 +1155,7 @@ declare module "orientjs" { } interface ODatabase extends Db { - new (config?: { + new(config?: { host: string, port?: number, username?: string, diff --git a/types/orientjs/orientjs-tests.ts b/types/orientjs/orientjs-tests.ts index 82504077ed..464d416122 100644 --- a/types/orientjs/orientjs-tests.ts +++ b/types/orientjs/orientjs-tests.ts @@ -5,22 +5,10 @@ let dbserver = orientjs({ port: 2424, username: 'root', password: 'root' - }); +}); let db = dbserver.use({ - name: 'mytestdb', - username: 'root', - password: 'root' - }); + name: 'mytestdb', + username: 'root', + password: 'root' +}); - -{ - var manager = new orientjs.Migration.Manager({ - db: db, - dir: __dirname + '/migrations' - }); - - manager.up(1) - .then(function () { - console.log('migrated up by one!') - }); -} From 0072c8b729fee124408fc4a42275627b9dc2b16f Mon Sep 17 00:00:00 2001 From: Saeed Tabrizi Date: Wed, 19 Jul 2017 20:29:38 +0430 Subject: [PATCH 3/4] fix all lint errors and replacments . --- types/orientjs/index.d.ts | 977 ++++++++++++++----------------- types/orientjs/orientjs-tests.ts | 1 - 2 files changed, 454 insertions(+), 524 deletions(-) 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' }); - From 57efa884551cf33fcdbc45134c3f95c810e20efa Mon Sep 17 00:00:00 2001 From: Saeed Tabrizi Date: Wed, 19 Jul 2017 21:09:43 +0430 Subject: [PATCH 4/4] some enhancment in namespace and default function declare . --- types/orientjs/index.d.ts | 2149 ++++++++++++++++++------------------- 1 file changed, 1074 insertions(+), 1075 deletions(-) diff --git a/types/orientjs/index.d.ts b/types/orientjs/index.d.ts index 3eef7ace34..9be45a4fea 100644 --- a/types/orientjs/index.d.ts +++ b/types/orientjs/index.d.ts @@ -35,1086 +35,1085 @@ import Promise = require('bluebird'); * @version 3.0.0 * */ + +/** + * Make a orientdb server client in binary protocol . + * @param {orientjs.ServerConfig} config The configuration for server connection. + */ +declare function orientjs(config: orientjs.ServerConfig): orientjs.Server; declare namespace orientjs { - function ojs(config: ojs.ServerConfig): ojs.OrientJs; + 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"; + enum DataTypes { + Boolean = 0, + Integer = 1, + Short = 2, + Long = 3, + Float = 4, + Double = 5, + Datetime = 6, + string = 7, + Binary = 8, + Embedded = 9, + EmbeddedList = 10, + EmbeddedSet = 11, + EmbeddedMap = 12, + Link = 13, + LinkList = 14, + LinkSet = 15, + LinkMap = 16, + Byte = 17, + Transient = 18, + Date = 19, + Custom = 20, + Decimal = 21, + LinkBag = 22 + } - 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"; - enum DataTypes { - Boolean = 0, - Integer = 1, - Short = 2, - Long = 3, - Float = 4, - Double = 5, - Datetime = 6, - string = 7, - Binary = 8, - Embedded = 9, - EmbeddedList = 10, - EmbeddedSet = 11, - EmbeddedMap = 12, - Link = 13, - LinkList = 14, - LinkSet = 15, - LinkMap = 16, - Byte = 17, - Transient = 18, - Date = 19, - Custom = 20, - Decimal = 21, - LinkBag = 22 - } - - namespace errors { - class BaseError { - name: string; - init(name: string): void; - } - class OperationError extends BaseError { - message: string; - date: any; - } - class RequestError extends OperationError { - } - } - - namespace Migration { - interface MigrationManagerConfig { - name?: string; - db?: Db; - dir?: string; - className?: string; - } - class Manager extends MigrationManager { - constructor(config: MigrationManagerConfig); - } - class Migration { - name: string; - server: Server; - db: Db; - configure(config?: any): void; - up(): Promise; - down(): Promise; - } - - class MigrationManager { - /** - * # Migration Manager - * - * @param {Object} config The configuration for the migration manager. - */ - constructor(config?: MigrationManagerConfig); - - name: string; - server: Server; - db: Db; - dir: string; - 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(param: string): Promise; - /** - * 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(): Promise; - /** - * 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. - */ - ensureStructure: Promise; - /** - * 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. - */ - 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. - */ - 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. - */ - 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. - */ - 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. - */ - revertMigration(name: string): Promise; - } - } - - interface Logger { - error(...args: any[]): void; - log(...args: any[]): void; - debug(...args: any[]): void; - } - - class RID extends String { - cluster?: number; - position?: number; - - valueOf(): string; - 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. - * @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. - * @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. - * @promise {Object|null} The new set of custom fields, or null if none are present. - */ - unset(key: string): CustomField; - } - - interface PropertyCreateConfig { + namespace errors { + class BaseError { name: string; - type: PropertyType; - default?: any; - ifnotexist?: boolean; - unsafe?: boolean; - mandatory?: boolean; - readonly?: boolean; - notNull?: boolean; - collate?: string; - linkedClass?: string; - linkedType?: string; - regexp?: RegExp | string; - min?: number; - max?: number; - custom?: { - fields?: CustomField[] - }; + init(name: string): void; } - - interface PropertyUpdateConfig { - name: string; - type: PropertyType; - default?: any; - mandatory?: boolean; - readonly?: boolean; - notNull?: boolean; - collate?: string; - linkedClass?: string; - linkedType?: string; - regexp?: RegExp | string; - min?: number; - max?: number; - custom?: { - fields?: CustomField[] - }; + class OperationError extends BaseError { + message: string; + date: any; } - - class Property { - class?: Class; - name?: string; - originalName?: string; - type?: PropertyType; - mandatory?: boolean; - readonly?: boolean; - notNull?: boolean; - collate?: string; - linkedClass?: string; - linkedType?: PropertyType; - regexp?: RegExp | string; - min?: number; - max?: number; - custom?: { - fields?: CustomField[] - }; - - configure(config?: any): void; - reload(): Promise; - list(): Promise; - /** - * Create a new property. - * - * @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(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(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; - } - - /** - * The class constructor. - * @param {Object} config The configuration for the class - */ - class Class { - db?: Db; - name?: string; - shortName?: string; - defaultClusterId?: any; - superClass?: string; - originalName?: string; - clusterIds?: number[]; - /** - * 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 | 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(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(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(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(cls: any, reload: boolean): Promise; - /** - * 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 {Object} config The config. - * @promise {Db} The database instance. - */ - drop(name: string, config?: { - ifexist?: boolean, - force?: boolean - }): Promise; - /** - * Get a class by name. - * - * @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. - */ - get(name: string, refresh?: boolean): Promise; - /** - * Cache the given class data for fast lookup later. - * - * @param {Object[]} classes The class objects to cache. - * @return {Db} The db instance. - */ - cacheData(classes: Class[]): Db; - property: Property; - } - - class Cluster { - name?: string; - location?: string; - list(refresh?: boolean): Promise; - create(name: string, location?: string): Promise & Promise; - get(nameOrId: string, 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; - range(name: string): Promise; - cacheData(clusters: Cluster[] & any[]): Db; - } - - /** - * The sequence constructor. - * @param {Object} config The configuration for the sequence - */ - class Sequence { - db?: Db; - name?: string; - type?: string; - value?: number; - incr?: number; - start?: number; - cache?: number; - /** - * 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. - */ - - 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(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(name: string, start?: number, incerement?: number, cache?: number): Promise; - /** - * 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. - */ - 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(name: string, refresh?: boolean): Promise; - /** - * Cache the given class data for fast lookup later. - * - * @param {Object[]} sequences The sequence objects to cache. - * @return {Db} The db instance. - */ - cacheData(sequences: Sequence[]): Db; - } - - interface RecordMeta { - "@rid": RID; - "@version": Version; - } - - type ODocument = Record; - type BinaryRecord = Record & Buffer; - class Record extends Object { - '@rid'?: RID; - '@type'?: 'd' | 'b'; - '@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. - */ - 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. - */ - 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. - */ - 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. - */ - 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. - */ - 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. - */ - 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. - */ - meta(records: 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(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; - } - - interface IndexEntry { - key: string; - value: string | RID; - } - interface Index { - cached: boolean; - db: Db; - name: string; - algorithm: string; - clusters: Cluster[]; - type: string; - configure(config: any): void; - 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 | IndexConfig[]): Promise; - drop(name: string): Promise; - get(name: string, refresh?: boolean): Promise; - cacheData(indices: any[]): Promise; - } - type SqlExpression = string | RawExpression | SqlFunction; - interface Statement extends Query { - select(param?: string | string[]): Statement; - traverse(param?: string | string[]): Statement; - strategy(param?: string): Statement; - insert(param?: string | string[]): Statement; - update(param?: string | string[]): Statement; - delete(param?: string | string[]): Statement; - into(param?: string): Statement; - create(paramtype?: string, paramname?: string): Statement; - from(param?: string | any): Statement; - to(param?: any): Statement; - set(param?: any): Statement; - content(param?: any): Statement; - increment(property?: string, value?: any): Statement; - add(property: string, value: any): Statement; - remove(property: string, value: any): Statement; - put(property: string, keysValues: any): Statement; - upsert(condition?: any, params?: any, comparisonOperator?: string): Statement; - where(params: any): Statement; - while(param: any): Statement; - containsText(param: any): Statement; - and(param: any): Statement; - or(param: any): Statement; - group(param: any): Statement; - order(param: any): Statement; - skip(value: number): Statement; - offset(value?: number): Statement; - limit(value: number): Statement; - fetch(param?: any): Statement; - let(name: string, value: string | Statement): Statement; - lock(param: any): Statement; - - if(condition: SqlExpression, statements: Statement[]): Statement; - if(condition: SqlExpression, ...statements: Statement[]): Statement; - rollback(param?: any): Statement; - sleep(ms?: number): Statement; - - commit(retryLimit?: number): Statement; - retry(retryLimit?: number): Statement; - wait(waitLimit: number): Statement; - return(value: SqlExpression): 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; - one(params?: any): Promise; - all(params?: any): Promise; - scalar(params?: any): Promise; - exec(params?: any): Promise; - } - - interface Transaction { - db: Db; - id: number; - - commit(): Promise; - create(record: Record): Transaction; - update(record: Record): Transaction; - delete(record: Record): Transaction; - } - - interface DbConnectionConfig { - useToken?: boolean; - name?: string; - username?: string; - password?: string; - sessionId?: number; - forcePrepare?: boolean; - server?: Server; - type?: string; - storage?: string; - token?: any; - transformers?: Array<((item: Record) => any)>; - } - - interface RawExpression { - db: Db; - value: string; - as(alias: string): RawExpression; - } - class AbsSqlFunction { - constructor(field: number | string); - } - class AvgSqlFunction { - constructor(field: string); - } - class SequenceSqlFunction { - constructor(name: string); - next(): number; - current(): number; - reset(): number; - } - - interface SqlFunction { - db: Db; - abs: AbsSqlFunction; - avg: AbsSqlFunction; - sequence: SequenceSqlFunction; - } - - interface QueryOptions { - params?: any; - mode?: "s" | "a" | "l"; - fetchPlan?: any; - limit?: number; - token?: any; - class?: string; - language?: "SQL" | "Javascript"; - } - - class Db extends events.EventEmitter { - sessionId: number; - forcePrepare: boolean; - name: string; - server: Server; - type: "graph" | "document"; - storage: "plocal" | "memory"; - username: string; - password: string; - token: any; - dataSegments: any[]; - transactionId: number; - transformers: any; - transformerFunctions: any; - - class: Class; - cluster: Cluster; - record: Record; - index: Index; - sequence: Sequence; - /** - * Configure the database instance. - * @param {Object} config The configuration for the database. - * @return {Db} The configured database object. - */ - configure(config: DbConfig): Db; - /** - * Initialize the database instance. - */ - init(): void; - /** - * Open the database. - * - * @promise {Db} The open db instance. - */ - open(): Promise; - /** - * 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(operation: number, data: any): Promise; - /** - * 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(): 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. - */ - 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 {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. - */ - liveQuery(command: string, options?: QueryOptions): Promise; - /** - * 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. - */ - 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. - */ - 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. - */ - transformDocument(document: ODocument): any; - - /** - * Create a query instance for this database. - * - * @return {Query} The query instance. - */ - createQuery(): Statement; - /** - * Create a raw expression. - * - * @return {RawExpression} The raw expression instance. - */ - rawExpression(param: string): RawExpression; - - /** Create a sql Function. - * - * @return {SqlFunction} The sql function instance. - */ - sqlFunction(options?: any): SqlFunction; - - /** - * 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. - */ - select(params?: any): Statement; - /** - * Create a traverse query. - * - * @return {Query} The query instance. - */ - traverse(params?: any): Statement; - /** - * Create an insert query. - * - * @return {Query} The query instance. - */ - insert(params?: any): Statement; - /** - * Create an update query. - * - * @return {Query} The query instance. - */ - update(params?: any): Statement; - /** - * Create a delete query. - * - * @return {Query} The query instance. - */ - delete(params?: any): Statement; - /** - * 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. - * - * @return {Query} The query instance. - */ - if(condition: SqlExpression, statements: Statement[]): Statement; - /** Create a transactional query with if. - * - * @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(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. - */ - createUserContext(token: any): any; - - /** - * Create a orient function from a plain Javascript 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: (...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; - } - - /** - * # Server - * Represents a connection to an orientdb server. - * - * @param {string|Object} options The server URL, or configuration object - */ - class Server { - constructor(options?: ServerConfig); - config: ServerConfiguration; - logger: Logger; - - /** - * Initialize the server instance. - */ - init(): void; - /** - * 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. - * - * @param {Object} config The server config. - * @return {Server} The configured server object. - */ - configureTransport(config: any): Server; - /** - * Configure the logger for the server. - * - * @param {Object} config The logger config - * @return {Server} The server instance with the configured logger. - */ - configureLogger(logger: Logger): Server; - /** - * Send an operation to the server, - * - * @param {Integer} operation The id of the operation to send. - * @param {Object} options The options for the operation. - * @promise {Mixed} The result of the operation. - */ - send(operation: number, options: any): any; - /** - * 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 | 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; - /** - * 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; - /** - * 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. - */ - 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(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(name: string, storageType?: string): any; - - shutdown(): Promise; - } - - class ODatabase extends Db { - constructor(config?: { - host: string, - port?: number, - username?: string, - password?: string, - name: string - }); - } - - interface ServerConfig { - useToken?: boolean; - host: string; - port?: number; - username?: string; - password?: string; - servers?: ServerConfig[]; - } - - interface DbConfig { - name: string; - type?: string; - storage?: string; - username?: string; - password?: string; - } - interface OrientJs extends Server { - name: string; + class RequestError extends OperationError { } } + + namespace Migration { + interface MigrationManagerConfig { + name?: string; + db?: Db; + dir?: string; + className?: string; + } + class Manager extends MigrationManager { + constructor(config: MigrationManagerConfig); + } + class Migration { + name: string; + server: Server; + db: Db; + configure(config?: any): void; + up(): Promise; + down(): Promise; + } + + class MigrationManager { + /** + * # Migration Manager + * + * @param {Object} config The configuration for the migration manager. + */ + constructor(config?: MigrationManagerConfig); + + name: string; + server: Server; + db: Db; + dir: string; + 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(param: string): Promise; + /** + * 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(): Promise; + /** + * 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. + */ + ensureStructure: Promise; + /** + * 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + revertMigration(name: string): Promise; + } + } + + interface Logger { + error(...args: any[]): void; + log(...args: any[]): void; + debug(...args: any[]): void; + } + + class RID extends String { + cluster?: number; + position?: number; + + valueOf(): string; + 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. + * @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. + * @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. + * @promise {Object|null} The new set of custom fields, or null if none are present. + */ + unset(key: string): CustomField; + } + + interface PropertyCreateConfig { + name: string; + type: PropertyType; + default?: any; + ifnotexist?: boolean; + unsafe?: boolean; + mandatory?: boolean; + readonly?: boolean; + notNull?: boolean; + collate?: string; + linkedClass?: string; + linkedType?: string; + regexp?: RegExp | string; + min?: number; + max?: number; + custom?: { + fields?: CustomField[] + }; + } + + interface PropertyUpdateConfig { + name: string; + type: PropertyType; + default?: any; + mandatory?: boolean; + readonly?: boolean; + notNull?: boolean; + collate?: string; + linkedClass?: string; + linkedType?: string; + regexp?: RegExp | string; + min?: number; + max?: number; + custom?: { + fields?: CustomField[] + }; + } + + class Property { + class?: Class; + name?: string; + originalName?: string; + type?: PropertyType; + mandatory?: boolean; + readonly?: boolean; + notNull?: boolean; + collate?: string; + linkedClass?: string; + linkedType?: PropertyType; + regexp?: RegExp | string; + min?: number; + max?: number; + custom?: { + fields?: CustomField[] + }; + + configure(config?: any): void; + reload(): Promise; + list(): Promise; + /** + * Create a new property. + * + * @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(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(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; + } + + /** + * The class constructor. + * @param {Object} config The configuration for the class + */ + class Class { + db?: Db; + name?: string; + shortName?: string; + defaultClusterId?: any; + superClass?: string; + originalName?: string; + clusterIds?: number[]; + /** + * 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 | 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(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(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(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(cls: any, reload: boolean): Promise; + /** + * 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 {Object} config The config. + * @promise {Db} The database instance. + */ + drop(name: string, config?: { + ifexist?: boolean, + force?: boolean + }): Promise; + /** + * Get a class by name. + * + * @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. + */ + get(name: string, refresh?: boolean): Promise; + /** + * Cache the given class data for fast lookup later. + * + * @param {Object[]} classes The class objects to cache. + * @return {Db} The db instance. + */ + cacheData(classes: Class[]): Db; + property: Property; + } + + class Cluster { + name?: string; + location?: string; + list(refresh?: boolean): Promise; + create(name: string, location?: string): Promise & Promise; + get(nameOrId: string, 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; + range(name: string): Promise; + cacheData(clusters: Cluster[] & any[]): Db; + } + + /** + * The sequence constructor. + * @param {Object} config The configuration for the sequence + */ + class Sequence { + db?: Db; + name?: string; + type?: string; + value?: number; + incr?: number; + start?: number; + cache?: number; + /** + * 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. + */ + + 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(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(name: string, start?: number, incerement?: number, cache?: number): Promise; + /** + * 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. + */ + 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(name: string, refresh?: boolean): Promise; + /** + * Cache the given class data for fast lookup later. + * + * @param {Object[]} sequences The sequence objects to cache. + * @return {Db} The db instance. + */ + cacheData(sequences: Sequence[]): Db; + } + + interface RecordMeta { + "@rid": RID; + "@version": Version; + } + + type ODocument = Record; + type BinaryRecord = Record & Buffer; + class Record extends Object { + '@rid'?: RID; + '@type'?: 'd' | 'b'; + '@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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + meta(records: 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(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; + } + + interface IndexEntry { + key: string; + value: string | RID; + } + interface Index { + cached: boolean; + db: Db; + name: string; + algorithm: string; + clusters: Cluster[]; + type: string; + configure(config: any): void; + 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 | IndexConfig[]): Promise; + drop(name: string): Promise; + get(name: string, refresh?: boolean): Promise; + cacheData(indices: any[]): Promise; + } + type SqlExpression = string | RawExpression | SqlFunction; + interface Statement extends Query { + select(param?: string | string[]): Statement; + traverse(param?: string | string[]): Statement; + strategy(param?: string): Statement; + insert(param?: string | string[]): Statement; + update(param?: string | string[]): Statement; + delete(param?: string | string[]): Statement; + into(param?: string): Statement; + create(paramtype?: string, paramname?: string): Statement; + from(param?: string | any): Statement; + to(param?: any): Statement; + set(param?: any): Statement; + content(param?: any): Statement; + increment(property?: string, value?: any): Statement; + add(property: string, value: any): Statement; + remove(property: string, value: any): Statement; + put(property: string, keysValues: any): Statement; + upsert(condition?: any, params?: any, comparisonOperator?: string): Statement; + where(params: any): Statement; + while(param: any): Statement; + containsText(param: any): Statement; + and(param: any): Statement; + or(param: any): Statement; + group(param: any): Statement; + order(param: any): Statement; + skip(value: number): Statement; + offset(value?: number): Statement; + limit(value: number): Statement; + fetch(param?: any): Statement; + let(name: string, value: string | Statement): Statement; + lock(param: any): Statement; + + if(condition: SqlExpression, statements: Statement[]): Statement; + if(condition: SqlExpression, ...statements: Statement[]): Statement; + rollback(param?: any): Statement; + sleep(ms?: number): Statement; + + commit(retryLimit?: number): Statement; + retry(retryLimit?: number): Statement; + wait(waitLimit: number): Statement; + return(value: SqlExpression): 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; + one(params?: any): Promise; + all(params?: any): Promise; + scalar(params?: any): Promise; + exec(params?: any): Promise; + } + + class Transaction { + db: Db; + id: number; + + commit(): Promise; + create(record: Record): Transaction; + update(record: Record): Transaction; + delete(record: Record): Transaction; + } + + interface DbConnectionConfig { + useToken?: boolean; + name?: string; + username?: string; + password?: string; + sessionId?: number; + forcePrepare?: boolean; + server?: Server; + type?: string; + storage?: string; + token?: any; + transformers?: Array<((item: Record) => any)>; + } + + interface RawExpression { + db: Db; + value: string; + as(alias: string): RawExpression; + } + class AbsSqlFunction { + constructor(field: number | string); + } + class AvgSqlFunction { + constructor(field: string); + } + class SequenceSqlFunction { + constructor(name: string); + next(): number; + current(): number; + reset(): number; + } + + interface SqlFunction { + db: Db; + abs: AbsSqlFunction; + avg: AbsSqlFunction; + sequence: SequenceSqlFunction; + } + + interface QueryOptions { + params?: any; + mode?: "s" | "a" | "l"; + fetchPlan?: any; + limit?: number; + token?: any; + class?: string; + language?: "SQL" | "Javascript"; + } + + class Db extends events.EventEmitter { + sessionId: number; + forcePrepare: boolean; + name: string; + server: Server; + type: "graph" | "document"; + storage: "plocal" | "memory"; + username: string; + password: string; + token: any; + dataSegments: any[]; + transactionId: number; + transformers: any; + transformerFunctions: any; + + class: Class; + cluster: Cluster; + record: Record; + index: Index; + sequence: Sequence; + /** + * Configure the database instance. + * @param {Object} config The configuration for the database. + * @return {Db} The configured database object. + */ + configure(config: DbConfig): Db; + /** + * Initialize the database instance. + */ + init(): void; + /** + * Open the database. + * + * @promise {Db} The open db instance. + */ + open(): Promise; + /** + * 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(operation: number, data: any): Promise; + /** + * 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(): 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. + */ + 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 {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. + */ + liveQuery(command: string, options?: QueryOptions): Promise; + /** + * 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. + */ + 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. + */ + 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. + */ + transformDocument(document: ODocument): any; + + /** + * Create a query instance for this database. + * + * @return {Query} The query instance. + */ + createQuery(): Statement; + /** + * Create a raw expression. + * + * @return {RawExpression} The raw expression instance. + */ + rawExpression(param: string): RawExpression; + + /** Create a sql Function. + * + * @return {SqlFunction} The sql function instance. + */ + sqlFunction(options?: any): SqlFunction; + + /** + * 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. + */ + select(params?: any): Statement; + /** + * Create a traverse query. + * + * @return {Query} The query instance. + */ + traverse(params?: any): Statement; + /** + * Create an insert query. + * + * @return {Query} The query instance. + */ + insert(params?: any): Statement; + /** + * Create an update query. + * + * @return {Query} The query instance. + */ + update(params?: any): Statement; + /** + * Create a delete query. + * + * @return {Query} The query instance. + */ + delete(params?: any): Statement; + /** + * 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. + * + * @return {Query} The query instance. + */ + if(condition: SqlExpression, statements: Statement[]): Statement; + /** Create a transactional query with if. + * + * @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(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. + */ + createUserContext(token: any): any; + + /** + * Create a orient function from a plain Javascript 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: (...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; + } + + /** + * # Server + * Represents a connection to an orientdb server. + * + * @param {string|Object} options The server URL, or configuration object + */ + class Server { + constructor(options?: ServerConfig); + config: ServerConfiguration; + logger: Logger; + + /** + * Initialize the server instance. + */ + init(): void; + /** + * 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. + * + * @param {Object} config The server config. + * @return {Server} The configured server object. + */ + configureTransport(config: any): Server; + /** + * Configure the logger for the server. + * + * @param {Object} config The logger config + * @return {Server} The server instance with the configured logger. + */ + configureLogger(logger: Logger): Server; + /** + * Send an operation to the server, + * + * @param {Integer} operation The id of the operation to send. + * @param {Object} options The options for the operation. + * @promise {Mixed} The result of the operation. + */ + send(operation: number, options: any): any; + /** + * Close the connection to the server. + * + * @return {Server} the disconnected server instance + */ + close(): Server; + /** + * Use the database with the given name / config. + * + * @param {string | DbConfig} config The database name, or configuration object. + * @return {Db} The database instance. + */ + use(name: string | DbConfig): Db; + /** + * Create a database with the given name / config. + * + * @param {string | DbConfig} config The database name or configuration object. + * @promise {Db} The database instance + */ + create(name: string | DbConfig): Promise; + /** + * Destroy a database with the given name / config. + * + * @param {string | DbConfig} config The database name or configuration object. + * @promise {Mixed} The server response. + */ + drop(name: string | DbConfig): Promise; + /** + * 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. + */ + 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(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(name: string, storageType?: string): any; + + shutdown(): Promise; + } + + class ODatabase extends Db { + constructor(config?: { + host: string, + port?: number, + username?: string, + password?: string, + name: string + }); + } + + interface ServerConfig { + useToken?: boolean; + host: string; + port?: number; + username?: string; + password?: string; + servers?: ServerConfig[]; + } + + interface DbConfig { + name: string; + type?: string; + storage?: string; + username?: string; + password?: string; + } } -export = orientjs.ojs; +export = orientjs;