import RedisShim from './redis/redis-shim' ; import Entity from './entity/entity' ; import Repository from './repository/repository' ; import Schema from './schema/schema' ; import RedisError from './errors' ; internal export type HashData = { [ key ] : any ; } ; internal export type JsonData = { [ key ] : any ; } ; /** The type of data structure in Redis to map objects to. */ export type SearchDataStructure = 'HASH' | 'JSON' ; internal export type CreateIndexOptions = { indexName : string ; dataStructure : SearchDataStructure ; prefix : string ; schema : string [ ] ; stopWords ? : string [ ] ; } ; internal export type SearchOptions = { indexName : string ; query : string ; offset : number ; count : number ; } ; /**
 * A Client is the starting point for working with Redis OM. Clients manage the
 * connection to Redis and provide limited functionality for executing Redis commands.
 * Create a client and open it before you use it:
 *
 * ```typescript
 * let client = new Client();
 * await client.open();
 * ```
 *
 * A Client is primarily used by a  Repository which requires a client in
 * its constructor.
  export default class Client { private shim ? : RedisShim ; param url async open ( url = 'redis://localhost:6379' ) { let shim = this . shim ?? new RedisShim ( ) ; await shim . open ( url ) ; this . shim = shim ; } template TResult param command returns async execute < TResult > ( command ) { this . validateShimOpen ( ) ; return await this . shim ! . execute < TResult > ( command . map ( arg => { if ( arg === false ) return '0' ; if ( arg === true ) return '1' ; return arg . toString ( ) ; } ) ) ; } template TEntity The entity type for this {@lin Schema} and  Repository .
     *  param schema returns fetchRepository < TEntity extends Entity > ( schema ) { this . validateShimOpen ( ) ; return new Repository ( schema , this ) ; } /**
     * Close the connection to Redis.
     */ async close ( ) { await this . shim ?. close ( ) ; this . shim = undefined ; } internal async createIndex ( options ) { this . validateShimOpen ( ) ; let { indexName , dataStructure , prefix , schema , stopWords } = options ; let command = [ 'FT.CREATE' , indexName , 'ON' , dataStructure , 'PREFIX' , '1' , `${ prefix }` ] ; if ( stopWords !== undefined ) command . push ( 'STOPWORDS' , `${ stopWords . length }` , ... stopWords ) ; command . push ( 'SCHEMA' , ... schema ) ; await this . shim ! . execute ( command ) ; } internal async dropIndex ( indexName ) { this . validateShimOpen ( ) ; await this . shim ! . execute ( [ 'FT.DROPINDEX' , indexName ] ) ; } internal async search ( options ) { this . validateShimOpen ( ) ; let { indexName , query , offset , count } = options ; return await this . shim ! . execute < any [ ] > ( [ 'FT.SEARCH' , indexName , query , 'LIMIT' , offset . toString ( ) , count . toString ( ) ] ) ; } internal async unlink ( key ) { this . validateShimOpen ( ) ; await this . shim ! . unlink ( key ) ; } internal async hgetall ( key ) { this . validateShimOpen ( ) ; return await this . shim ! . hgetall ( key ) ; } internal async hsetall ( key , data ) { this . validateShimOpen ( ) ; await this . shim ! . hsetall ( key , data ) ; } internal async jsonget ( key ) { this . validateShimOpen ( ) ; let json = await this . shim ! . execute < string > ( [ 'JSON.GET' , key , '.' ] ) ; return JSON . parse ( json ) ; } internal async jsonset ( key , data ) { this . validateShimOpen ( ) ; let json = JSON . stringify ( data ) ; await this . shim ! . execute < string > ( [ 'JSON.SET' , key , '.' , json ] ) ; } returns isOpen ( ) { return ! ! this . shim ; } private validateShimOpen ( ) { if ( ! this . shim ) throw new RedisError ( "Redis connection needs opened." ) ; } }