import { Schema } from '../schema'; import { Model, SearchConsistency } from '..'; import { ModelOptions } from '../model/interfaces/create-model.interface'; import { ModelMetadata } from '../model/interfaces/model-metadata.interface'; import { CastOptions } from '../utils/cast-strategy'; import { Document } from '../model/document'; export interface ConnectOptions { connectionString: string; username: string; password: string; bucketName: string; authenticator?: CertificateAuthenticator; trustStorePath?: string; transcoder?: unknown; logFunc?: unknown; } interface OttomanConfig { collectionName?: string; scopeName?: string; idKey?: string; modelKey?: string; populateMaxDeep?: number; searchConsistency?: SearchConsistency; maxExpiry?: number; keyGenerator?: (params: { metadata: ModelMetadata; }) => string; keyGeneratorDelimiter?: string; } /** * CertificateAuthenticator provides an authenticator implementation * which uses TLS Certificate Authentication. */ export declare class CertificateAuthenticator { certificatePath: any; keyPath: any; /** * * @param {string} certificatePath * @param {string} keyPath */ constructor(certificatePath: any, keyPath: any); } /** * Store default connection */ export declare let __ottoman: Ottoman; export declare const __ottomanInstances: Ottoman[]; export declare class Ottoman { private n1qlIndexes; private viewIndexes; private refdocIndexes; /** * @ignore */ getRefdocIndexByKey: (key: any) => { fields: string[]; }[]; /** * @ignore */ registerIndex: (indexName: string, fields: any, modelName: any) => void; /** * @ignore */ registerViewIndex: (designDocName: string, indexName: string, fields: any, metadata: any) => void; /** * @ignore */ registerRefdocIndex: (fields: string[], prefix: string) => void; config: OttomanConfig; /** * Bucket represents a storage grouping of data within a Couchbase Server cluster. */ bucket: any; /** * CollectionManager allows the management of collections within a Bucket. * * Check the * [Collection Manager Couchbase SDK API](https://docs.couchbase.com/sdk-api/couchbase-node-client/CollectionManager.html) * documentation for more details. */ get collectionManager(): any; /** * Gets a bucket manager for this cluster * * Check the * [Bucket Manager Couchbase SDK API](https://docs.couchbase.com/sdk-api/couchbase-node-client/BucketManager.html) * documentation for more details. */ get bucketManager(): any; /** * QueryIndexManager provides an interface for managing the query indexes on the cluster. * * Check the * [Query Index Manager Couchbase SDK API](https://docs.couchbase.com/sdk-api/couchbase-node-client/QueryIndexManager.html) * documentation for more details. */ get queryIndexManager(): any; /** * ViewIndexManager is an interface which enables the management of view indexes on the cluster. * * Check the * [View Index Manager Couchbase SDK API](https://docs.couchbase.com/sdk-api/couchbase-node-client/ViewIndexManager.html) * documentation for more details. */ get viewIndexManager(): any; /** * Dictionary for all models registered on this connection. */ models: {}; private _cluster; /** * Cluster represents an entire Couchbase Server cluster. */ get cluster(): any; /** * Contains the name of the current bucket. */ bucketName: string; /** * Stores a reference to couchbase instance. */ couchbase: any; constructor(config?: OttomanConfig); /** * Connect to Couchbase server * @example * ```javascript * import { connect } from "ottoman"; * const connection = connect("couchbase://localhost/travel-sample@admin:password"); * ``` */ connect: (connectOptions: ConnectOptions | string) => Ottoman; /** * Creates a Model on this connection. * * @example * ```javascript * const User = connection.model('User', { name: String }, {collectionName: 'users'}); * ``` */ model(name: string, schema: Schema | Record, options?: ModelOptions): import("..").ModelTypes; /** * dropCollection drops a collection from a scope in a bucket. * @param collectionName * @param scopeName * @param options */ dropCollection(collectionName: string, scopeName: string, options?: { timeout?: number; }): Promise; /** * dropScope drops a scope from a bucket. * @param scopeName * @param options */ dropScope(scopeName: string, options?: { timeout?: number; }): Promise; /** * dropBucket drops a bucket from the cluster. * @param bucketName * @param options */ dropBucket(bucketName: string, options?: { timeout?: number; }): Promise; /** * Returns a Model constructor from the given name * * @example * ```javascript * const User = connection.getModel('User'); * ``` */ getModel(name: string): Model & { new (data: T, options?: CastOptions): Document & T; }; /** * Return a collection from the given collectionName in this bucket * Or default collection if collectionName is missing */ getCollection(collectionName?: string, scopeName?: string): any; /** * Closes the current connection * * @example * ```javascript * connection.close().then(() => console.log('connection closed')); * ``` */ close(): void; /** * Executes N1QL Queries. * * Ottoman provides a powerful [Query Builder](/guides/query-builder) system to create valid N1QL queries in a easier way. * See the example below: * * @example * ```javascript * const expr_where = {$or: [{ address: { $like: '%57-59%' } }, { free_breakfast: true }]}; * const query = new Query({}, 'travel-sample'); * const n1qlQuery = query.select([{$field: 'address'}]).where(expr_where).build() * * connection.query(n1qlQuery).then(result => console.log(result)) * ``` * The above example will run this query: * > `SELECT address FROM travel-sample WHERE (address LIKE '%57-59%' OR free_breakfast = true)` */ query(query: string): Promise; /** * `ensureCollections` will attempt to create scopes and collection to map your models into Couchbase Server. */ ensureCollections(): Promise; /** * `ensureIndexes` will attempt to create indexes defined in your schemas */ ensureIndexes(): Promise; /** * `start` method is just a shortcut to run `ensureCollections` and `ensureIndexes`. * Notice: It's not required to execute the `start` method to Ottoman work. */ start(): Promise; } export declare const getDefaultInstance: () => Ottoman; export declare const getOttomanInstances: () => Ottoman[]; export declare const connect: (connectOptions: ConnectOptions | string) => void; export declare const close: () => void; export declare const start: () => Promise; export declare const getModel: (name: string) => Model & (new (data: any, options?: CastOptions | undefined) => any); export declare const getCollection: (collectionName?: string, scopeName?: string) => any; export declare const model: (name: string, schema: Schema | Record, options?: any) => import("..").ModelTypes; export {};