initialize(option, outputPath) {
        return __awaiter(this, void 0, void 0, function* () {
            const entitySet = new Set();
            for (const connectionOption of option.connectionList) {
                for (const entity of connectionOption.entities) {
                    const filePaths = glob_1.glob.sync(entity);
                    filePaths.forEach(filePath => {
                        if (option.needCheckShard === false) {
                            const baseName = LibPath.basename(filePath, '.js');
                            if (baseName.search(/\_\d*\.js/) >= 0) {
                                entitySet.add(baseName);
                            }
                            else {
                                const _ = require(filePath);
                                const args = EntityStorage_1.EntityStorage.instance.shardTableMetadataStorage[baseName];
                                if (args) {
                                    const { shardCount } = args;
                                    const classHash = new HashRing();
                                    for (let i = 0; i < shardCount; i++) {
                                        classHash.add(`${baseName}_${i}`);
                                    }
                                    this.shardHashMap[baseName] = classHash;
                                }
                                else {
                                    entitySet.add(baseName);
                                }
                            }
                            EntityStorage_1.EntityStorage.instance.shardTableFileStorage[baseName] = filePath;
                        }
                        else {
                            const _ = require(filePath);
                        }
                    });
                    if (option.needCheckShard) {
                        yield this._checkShardTable(entity, entitySet);
                    }
                }
            }
            debug('Check ShardTable finish');
            this._connections = yield typeorm_1.createConnections(option.connectionList);
            debug('Create connection finish');
            const connMap = {};
            if (option.shardingStrategies) {
                for (const strategy of option.shardingStrategies) {
                    if (!typeorm_1.getConnectionManager().has(strategy.connctionName)) {
                        throw new Error('There is no such ConnectionName in ShardingStrategy');
                    }
                    for (const entityName of strategy.entities) {
                        if (!entitySet.has(entityName)) {
                            throw new Error('There is no such EntityName in ShardingStrategy');
                        }
                        this.entityToConnection[entityName] = strategy.connctionName;
                    }
                    connMap[strategy.connctionName] = strategy.entities;
                }
                debug('Read custom ShardingStrategy finish');
            }
            else {
                const entitiesClass = [...entitySet];
                for (let i = 0; i < entitiesClass.length; i++) {
                    const index = (i + this._connections.length) % this._connections.length;
                    const connName = this._connections[index].name;
                    const className = entitiesClass[i];
                    this.entityToConnection[className] = connName;
                    if (connMap[connName] === undefined) {
                        connMap[connName] = [];
                    }
                    connMap[connName].push(className);
                }
                debug('Use default ShardingStrategy finish');
            }
            // if given outputPath then will write ConnectionMap to show [ connection => Entity ]
            if (outputPath && LibFs.statSync(outputPath).isDirectory()) {
                LibFs.writeFileSync(LibPath.join(outputPath, 'ConnectionMap.json'), JSON.stringify(connMap, null, 2));
            }
            else {
                debug(`Currect ConnectionMap = ${JSON.stringify(connMap, null, 2)}`);
            }
            return this._connections;
        });
    }
/**
     * Create Database by option
     * @param {DatabaseOptions} option DatabaseOptions
     * @param {ZipkinBase} zipkin optonal ZipkinProxy import by SASDN-Zipkin
     * @param {object} ctx optional koa or grpc context
     * @param {string} outputPath which path to create ConnectionMap.json
     */
Create Database by option
@param {DatabaseOptions} option DatabaseOptions
@param {ZipkinBase} zipkin optonal ZipkinProxy import by SASDN-Zipkin
@param {object} ctx optional koa or grpc context
@param {string} outputPath which path to create ConnectionMap.json
Create Database by option @param { DatabaseOptions } option DatabaseOptions @param { ZipkinBase } zipkin optonal ZipkinProxy import by SASDN - Zipkin @param { object } ctx optional koa or grpc context @param { string } outputPath which path to create ConnectionMap . json
initialize(option, outputPath) {
        return __awaiter(this, void 0, void 0, function* () {
            const entitySet = new Set();
            for (const connectionOption of option.connectionList) {
                for (const entity of connectionOption.entities) {
                    const filePaths = glob_1.glob.sync(entity);
                    filePaths.forEach(filePath => {
                        if (option.needCheckShard === false) {
                            const baseName = LibPath.basename(filePath, '.js');
                            if (baseName.search(/\_\d*\.js/) >= 0) {
                                entitySet.add(baseName);
                            }
                            else {
                                const _ = require(filePath);
                                const args = EntityStorage_1.EntityStorage.instance.shardTableMetadataStorage[baseName];
                                if (args) {
                                    const { shardCount } = args;
                                    const classHash = new HashRing();
                                    for (let i = 0; i < shardCount; i++) {
                                        classHash.add(`${baseName}_${i}`);
                                    }
                                    this.shardHashMap[baseName] = classHash;
                                }
                                else {
                                    entitySet.add(baseName);
                                }
                            }
                            EntityStorage_1.EntityStorage.instance.shardTableFileStorage[baseName] = filePath;
                        }
                        else {
                            const _ = require(filePath);
                        }
                    });
                    if (option.needCheckShard) {
                        yield this._checkShardTable(entity, entitySet);
                    }
                }
            }
            debug('Check ShardTable finish');
            this._connections = yield typeorm_1.createConnections(option.connectionList);
            debug('Create connection finish');
            const connMap = {};
            if (option.shardingStrategies) {
                for (const strategy of option.shardingStrategies) {
                    if (!typeorm_1.getConnectionManager().has(strategy.connctionName)) {
                        throw new Error('There is no such ConnectionName in ShardingStrategy');
                    }
                    for (const entityName of strategy.entities) {
                        if (!entitySet.has(entityName)) {
                            throw new Error('There is no such EntityName in ShardingStrategy');
                        }
                        this.entityToConnection[entityName] = strategy.connctionName;
                    }
                    connMap[strategy.connctionName] = strategy.entities;
                }
                debug('Read custom ShardingStrategy finish');
            }
            else {
                const entitiesClass = [...entitySet];
                for (let i = 0; i < entitiesClass.length; i++) {
                    const index = (i + this._connections.length) % this._connections.length;
                    const connName = this._connections[index].name;
                    const className = entitiesClass[i];
                    this.entityToConnection[className] = connName;
                    if (connMap[connName] === undefined) {
                        connMap[connName] = [];
                    }
                    connMap[connName].push(className);
                }
                debug('Use default ShardingStrategy finish');
            }
            if (outputPath && LibFs.statSync(outputPath).isDirectory()) {
                LibFs.writeFileSync(LibPath.join(outputPath, 'ConnectionMap.json'), JSON.stringify(connMap, null, 2));
            }
            else {
                debug(`Currect ConnectionMap = ${JSON.stringify(connMap, null, 2)}`);
            }
            return this._connections;
        });
    }
initialize ( option , outputPath ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { const entitySet = new Set ( ) ; for ( const connectionOption of option . connectionList ) { for ( const entity of connectionOption . entities ) { const filePaths = glob_1 . glob . sync ( entity ) ; filePaths . forEach ( filePath => { if ( option . needCheckShard === false ) { const baseName = LibPath . basename ( filePath , '.js' ) ; if ( baseName . search ( / \_\d*\.js / ) >= 0 ) { entitySet . add ( baseName ) ; } else { const _ = require ( filePath ) ; const args = EntityStorage_1 . EntityStorage . instance . shardTableMetadataStorage [ baseName ] ; if ( args ) { const { shardCount } = args ; const classHash = new HashRing ( ) ; for ( let i = 0 ; i < shardCount ; i ++ ) { classHash . add ( ` ${ baseName } ${ i } ` ) ; } this . shardHashMap [ baseName ] = classHash ; } else { entitySet . add ( baseName ) ; } } EntityStorage_1 . EntityStorage . instance . shardTableFileStorage [ baseName ] = filePath ; } else { const _ = require ( filePath ) ; } } ) ; if ( option . needCheckShard ) { yield this . _checkShardTable ( entity , entitySet ) ; } } } debug ( 'Check ShardTable finish' ) ; this . _connections = yield typeorm_1 . createConnections ( option . connectionList ) ; debug ( 'Create connection finish' ) ; const connMap = { } ; if ( option . shardingStrategies ) { for ( const strategy of option . shardingStrategies ) { if ( ! typeorm_1 . getConnectionManager ( ) . has ( strategy . connctionName ) ) { throw new Error ( 'There is no such ConnectionName in ShardingStrategy' ) ; } for ( const entityName of strategy . entities ) { if ( ! entitySet . has ( entityName ) ) { throw new Error ( 'There is no such EntityName in ShardingStrategy' ) ; } this . entityToConnection [ entityName ] = strategy . connctionName ; } connMap [ strategy . connctionName ] = strategy . entities ; } debug ( 'Read custom ShardingStrategy finish' ) ; } else { const entitiesClass = [ ... entitySet ] ; for ( let i = 0 ; i < entitiesClass . length ; i ++ ) { const index = ( i + this . _connections . length ) % this . _connections . length ; const connName = this . _connections [ index ] . name ; const className = entitiesClass [ i ] ; this . entityToConnection [ className ] = connName ; if ( connMap [ connName ] === undefined ) { connMap [ connName ] = [ ] ; } connMap [ connName ] . push ( className ) ; } debug ( 'Use default ShardingStrategy finish' ) ; } if ( outputPath && LibFs . statSync ( outputPath ) . isDirectory ( ) ) { LibFs . writeFileSync ( LibPath . join ( outputPath , 'ConnectionMap.json' ) , JSON . stringify ( connMap , null , 2 ) ) ; } else { debug ( ` ${ JSON . stringify ( connMap , null , 2 ) } ` ) ; } return this . _connections ; } ) ; }
Create Database by option
 @param {DatabaseOptions} option DatabaseOptions
 @param {ZipkinBase} zipkin optonal ZipkinProxy import by SASDN-Zipkin
 @param {object} ctx optional koa or grpc context
 @param {string} outputPath which path to create ConnectionMap.json
Create Database by option @param { DatabaseOptions } option DatabaseOptions @param { ZipkinBase } zipkin optonal ZipkinProxy import by SASDN - Zipkin @param { object } ctx optional koa or grpc context @param { string } outputPath which path to create ConnectionMap . json
// if given outputPath then will write ConnectionMap to show [ connection => Entity ]