js-node-arango
Version:
NodeJS ArangoDB Provider
131 lines (130 loc) • 6.24 kB
TypeScript
import ApiError from 'js-node-errors';
import { Config as LoggerConfig } from 'js-node-logger';
import { Database } from 'arangojs';
import { AqlQuery } from 'arangojs/aql';
import { ArrayCursor } from 'arangojs/cursor';
import { QueryOptions } from 'arangojs/database';
import { DocumentMetadata as DocumentMetadataImported, EdgeMetadata as EdgeMetadataImported } from 'arangojs/documents';
import ArangoConfig from './types/arango-config.interface';
import { ArangoDocumentQueryOptions, ArangoEdgeQueryOptions } from './types/arango-query-options.interface';
import { WithCount } from './types/with-count.type';
import { WithRelatedWithCount } from './types/with-related-with-count.type';
import { WithRelated } from './types/with-related.type';
export declare class ArangoError extends ApiError {
constructor(error: Error);
}
export declare class RevisionNotMatchingError extends ApiError {
constructor(id: string, error: Error);
}
export type DocumentMetadata = DocumentMetadataImported;
export type EdgeMetadata = EdgeMetadataImported;
export declare class ArangoDBProvider {
private db;
private logger?;
private config;
private shouldWaitForViewUpdate;
constructor(config: ArangoConfig, loggerConfig?: LoggerConfig);
initializeDBConnection(username: string, password: string, dbName?: string): Promise<void>;
disconnectDB(cb?: Function): void;
removeDB(databaseName?: string): Promise<void>;
addDB(databaseName?: string): Promise<Database>;
switchDB(database: string | Database, username?: string, password?: string): Promise<void>;
createCollection(collectionName: string): Promise<void>;
createEdgeCollection(collectionName: string): Promise<void>;
createView(viewName: string, collectionName: string): Promise<void>;
cleanCollection(collectionName: string): Promise<void>;
addToCollection(collectionName: string, item: any): Promise<DocumentMetadata>;
updateDocumentInCollection(collectionName: string, id: string, docPatch: any, rev?: string): Promise<DocumentMetadata & {
new?: any;
}>;
deleteDocumentInCollection(collectionName: string, id: string): Promise<DocumentMetadata>;
getByIdFromCollection<T = any>(collectionName: string, id: string): Promise<DocumentMetadata & T>;
getLinksFromViewForId(edgeCollectionViewName: string, linkedCollectionName: string, id: string): Promise<any>;
getLinksFromViewForToId(edgeCollectionViewName: string, linkedCollectionName: string, id: string): Promise<any>;
getOutBoundDocumentsForEntityId(edgeCollectionViewName: string, entityName: string, entityId: any, collectionName: string): Promise<Array<any>>;
/**
* @deprecated Please use getDocuments method instead of getFromCollection
*/
getFromCollection(collectionName: string, sortField: string, sortOrder: string, limit: number, offset: number, filter?: any): Promise<ArrayCursor<any>>;
getByFieldNameFromCollection(collectionName: string, fieldName: string, value: any): Promise<ArrayCursor<any>>;
executeRawQuery<T = any>(aqlQuery: AqlQuery, options?: QueryOptions): Promise<T[]>;
/**
* Just a shortcut method for returning the first result from the query result set
* ```js
* const resultSet = await this.executeRawQuery<T>(query, options);
* return resultSet[0];
* ```
*/
executeRawQueryReturnFirst<T = any>(aqlQuery: AqlQuery, options?: QueryOptions): Promise<T>;
addToCollectionWithRelatedDocument<T = any, R = any>(inputArgs: {
rootDocCollectionName: string;
rootDoc: object;
edgeCollectionName: string;
relatedCollectionName: string;
relatedDoc: object;
additionalLinkData?: object;
}): Promise<{
rootDoc: T & DocumentMetadata;
related: R & DocumentMetadata;
}>;
addRelatedDocument<T = any>(inputArgs: {
rootDocCollectionName: string;
rootDocId: string;
edgeCollectionName: string;
relatedCollectionName: string;
relatedDoc: object;
additionalLinkData?: object;
}): Promise<T & DocumentMetadataImported>;
/**
* Basic query with options.
*
* @example
* ```js
* // This query will return all documents matches the given example
* const results = await this.db.getDocuments('manifest', {
* filterBy: {
* filter: {
* gitRepoInfo: {
* owner: 'Tospaa',
* },
* },
* },
* });
* return results;
*
* // This query will return the first document matches the given example
* const results = await this.db.getDocuments('git_account', {
* limitBy: {
* offset: 0,
* limit: 1,
* },
* sortBy: {
* field: 'dateTs',
* order: 'DESC',
* },
* filterBy: {
* filter: {
* cognitoUsername: '26fcf457-e31a-4219-91e0-878ed039024c',
* status: 'active',
* },
* },
* });
* return results[0];
*
* // This query will return all the documents in the given collection
* const results = await this.db.getDocuments('git_repo');
* return results;
* ```
* @param collectionName The name of the collection
* @param options Arango Query Options
* @returns All results matching the given criteria
*/
getDocuments<T = any>(options: ArangoDocumentQueryOptions): Promise<(T & DocumentMetadataImported)[]>;
getDocumentsWithCount<T = any>(options: ArangoDocumentQueryOptions): Promise<WithCount<T & DocumentMetadataImported>>;
getDocumentWithRelatedDocuments<T = any, R = any>(collectionName: string, rootDocId: string, options: ArangoEdgeQueryOptions): Promise<WithRelated<T & DocumentMetadataImported, R & DocumentMetadataImported>>;
getDocumentWithRelatedDocumentsWithCount<T = any, R = any>(collectionName: string, rootDocId: string, options: ArangoEdgeQueryOptions): Promise<WithRelatedWithCount<T & DocumentMetadataImported, R & DocumentMetadataImported>>;
registerFunction: (name: string, code: string) => Promise<import("arangojs/connection").ArangoResponseMetadata & {
isNewlyCreated: boolean;
}>;
}
export default ArangoDBProvider;