typeorm 0.3.18-dev.7adbc9b → 0.3.18-dev.c6f608d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/browser/driver/DriverUtils.js +2 -5
  2. package/browser/driver/DriverUtils.js.map +1 -1
  3. package/browser/driver/sqlserver/SqlServerConnectionCredentialsOptions.d.ts +2 -1
  4. package/browser/driver/sqlserver/SqlServerConnectionCredentialsOptions.js.map +1 -1
  5. package/browser/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.d.ts +12 -0
  6. package/browser/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js +3 -0
  7. package/browser/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js.map +1 -0
  8. package/browser/error/QueryFailedError.d.ts +3 -3
  9. package/browser/error/QueryFailedError.js.map +1 -1
  10. package/browser/find-options/FindOptionsUtils.js +1 -1
  11. package/browser/find-options/FindOptionsUtils.js.map +1 -1
  12. package/browser/naming-strategy/DefaultNamingStrategy.d.ts +0 -1
  13. package/browser/naming-strategy/DefaultNamingStrategy.js +0 -3
  14. package/browser/naming-strategy/DefaultNamingStrategy.js.map +1 -1
  15. package/browser/naming-strategy/NamingStrategyInterface.d.ts +0 -4
  16. package/browser/naming-strategy/NamingStrategyInterface.js.map +1 -1
  17. package/browser/persistence/Subject.js +2 -1
  18. package/browser/persistence/Subject.js.map +1 -1
  19. package/browser/query-builder/QueryBuilder.js +1 -1
  20. package/browser/query-builder/QueryBuilder.js.map +1 -1
  21. package/browser/repository/Repository.d.ts +1 -1
  22. package/browser/repository/Repository.js +9 -5
  23. package/browser/repository/Repository.js.map +1 -1
  24. package/commands/CommandUtils.js +6 -1
  25. package/commands/CommandUtils.js.map +1 -1
  26. package/commands/EntityCreateCommand.d.ts +3 -0
  27. package/commands/EntityCreateCommand.js +7 -0
  28. package/commands/EntityCreateCommand.js.map +1 -1
  29. package/commands/MigrationCreateCommand.d.ts +5 -1
  30. package/commands/MigrationCreateCommand.js +6 -1
  31. package/commands/MigrationCreateCommand.js.map +1 -1
  32. package/commands/MigrationGenerateCommand.d.ts +5 -1
  33. package/commands/MigrationGenerateCommand.js +5 -0
  34. package/commands/MigrationGenerateCommand.js.map +1 -1
  35. package/commands/SubscriberCreateCommand.d.ts +3 -0
  36. package/commands/SubscriberCreateCommand.js +7 -0
  37. package/commands/SubscriberCreateCommand.js.map +1 -1
  38. package/driver/DriverUtils.js +2 -5
  39. package/driver/DriverUtils.js.map +1 -1
  40. package/driver/sqlserver/SqlServerConnectionCredentialsOptions.d.ts +2 -1
  41. package/driver/sqlserver/SqlServerConnectionCredentialsOptions.js.map +1 -1
  42. package/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.d.ts +12 -0
  43. package/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js +4 -0
  44. package/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js.map +1 -0
  45. package/error/QueryFailedError.d.ts +3 -3
  46. package/error/QueryFailedError.js.map +1 -1
  47. package/find-options/FindOptionsUtils.js +1 -1
  48. package/find-options/FindOptionsUtils.js.map +1 -1
  49. package/naming-strategy/DefaultNamingStrategy.d.ts +0 -1
  50. package/naming-strategy/DefaultNamingStrategy.js +0 -3
  51. package/naming-strategy/DefaultNamingStrategy.js.map +1 -1
  52. package/naming-strategy/NamingStrategyInterface.d.ts +0 -4
  53. package/naming-strategy/NamingStrategyInterface.js.map +1 -1
  54. package/package.json +1 -1
  55. package/persistence/Subject.js +2 -1
  56. package/persistence/Subject.js.map +1 -1
  57. package/query-builder/QueryBuilder.js +1 -1
  58. package/query-builder/QueryBuilder.js.map +1 -1
  59. package/repository/Repository.d.ts +1 -1
  60. package/repository/Repository.js +9 -5
  61. package/repository/Repository.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,OAAO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AAA;IAChD,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,SAAS,CACL,UAAoC,EACpC,YAAoB,EACpB,KAAsB;QAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,SAAS,CACL,UAAoC,EACpC,YAAoB,EACpB,KAAsB;QAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CACF,MAA4D;QAE5D,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,KAAK;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAkD,CAAA;QACxE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAM,SAAQ,QAAQ;SAAG,CAAC,CACvC,MAAM,EACN,OAAO,EACP,WAAW,CACd,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC1B,OAAO,GAAU,CAAA;IACrB,CAAC;CACJ","file":"Repository.js","sourcesContent":["import { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { ObjectId } from \"../driver/mongodb/typings\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\n\n/**\n * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.\n */\nexport class Repository<Entity extends ObjectLiteral> {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity target that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n readonly target: EntityTarget<Entity>\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n get metadata() {\n return this.manager.connection.getMetadata(this.target)\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n this.target = target\n this.manager = manager\n this.queryRunner = queryRunner\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(\n this.metadata.target as any,\n alias || this.metadata.targetName,\n queryRunner || this.queryRunner,\n )\n }\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(entity: Entity): boolean {\n return this.manager.hasId(this.metadata.target, entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n getId(entity: Entity): any {\n return this.manager.getId(this.metadata.target, entity)\n }\n\n /**\n * Creates a new entity instance.\n */\n create(): Entity\n\n /**\n * Creates new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLikeArray: DeepPartial<Entity>[]): Entity[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLike: DeepPartial<Entity>): Entity\n\n /**\n * Creates a new entity instance or instances.\n * Can copy properties from the given object into new entities.\n */\n create(\n plainEntityLikeOrPlainEntityLikes?:\n | DeepPartial<Entity>\n | DeepPartial<Entity>[],\n ): Entity | Entity[] {\n return this.manager.create<any>(\n this.metadata.target as any,\n plainEntityLikeOrPlainEntityLikes as any,\n )\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(\n mergeIntoEntity: Entity,\n ...entityLikes: DeepPartial<Entity>[]\n ): Entity {\n return this.manager.merge(\n this.metadata.target as any,\n mergeIntoEntity,\n ...entityLikes,\n )\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n preload(entityLike: DeepPartial<Entity>): Promise<Entity | undefined> {\n return this.manager.preload(this.metadata.target as any, entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.save<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Removes a given entities from the database.\n */\n remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>\n\n /**\n * Removes a given entity from the database.\n */\n remove(entity: Entity, options?: RemoveOptions): Promise<Entity>\n\n /**\n * Removes one or many given entities.\n */\n remove(\n entityOrEntities: Entity | Entity[],\n options?: RemoveOptions,\n ): Promise<Entity | Entity[]> {\n return this.manager.remove(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.softRemove<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.recover<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n insert(\n entity:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n ): Promise<InsertResult> {\n return this.manager.insert(this.metadata.target as any, entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n update(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n partialEntity: QueryDeepPartialEntity<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.update(\n this.metadata.target as any,\n criteria as any,\n partialEntity,\n )\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n upsert(\n entityOrEntities:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>,\n ): Promise<InsertResult> {\n return this.manager.upsert(\n this.metadata.target as any,\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n delete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<DeleteResult> {\n return this.manager.delete(this.metadata.target as any, criteria as any)\n }\n\n /**\n * Records the delete date of entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n softDelete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.softDelete(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Restores entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n restore(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.restore(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Checks whether any entity exists that match given options.\n */\n exist(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given options.\n * Useful for pagination.\n */\n count(options?: FindManyOptions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given conditions.\n * Useful for pagination.\n */\n countBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number> {\n return this.manager.countBy(this.metadata.target, where)\n }\n\n /**\n * Return the SUM of a column\n */\n sum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.sum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n average(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.average(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n minimum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.minimum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n maximum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.maximum(this.metadata.target, columnName, where)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async findBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity[]> {\n return this.manager.findBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(\n options?: FindManyOptions<Entity>,\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCount(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCountBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCountBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities with ids.\n * Optionally find options or conditions can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n async findByIds(ids: any[]): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target, ids)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - returns null.\n */\n async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {\n return this.manager.findOne(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - returns null.\n */\n async findOneBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity | null> {\n return this.manager.findOneBy(this.metadata.target, where)\n }\n\n /**\n * Finds first entity that matches given id.\n * If entity was not found in the database - returns null.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n async findOneById(\n id: number | string | Date | ObjectId,\n ): Promise<Entity | null> {\n return this.manager.findOneById(this.metadata.target, id)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - rejects with error.\n */\n async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - rejects with error.\n */\n async findOneByOrFail(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity> {\n return this.manager.findOneByOrFail(this.metadata.target, where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n query(query: string, parameters?: any[]): Promise<any> {\n return this.manager.query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n *\n * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.\n * @see https://stackoverflow.com/a/5972738/925151\n */\n clear(): Promise<void> {\n return this.manager.clear(this.metadata.target)\n }\n\n /**\n * Increments some column by provided value of the entities matched given conditions.\n */\n increment(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.increment(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.decrement(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Extends repository with provided functions.\n */\n extend<CustomRepository>(\n custom: CustomRepository & ThisType<this & CustomRepository>,\n ): this & CustomRepository {\n // return {\n // ...this,\n // ...custom\n // };\n const thisRepo = this.constructor as new (...args: any[]) => typeof this\n const { target, manager, queryRunner } = this\n const cls = new (class extends thisRepo {})(\n target,\n manager,\n queryRunner,\n )\n Object.assign(cls, custom)\n return cls as any\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,OAAO,UAAU;IAsBnB,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;QAEzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,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,UAAoC,EACpC,YAAoB,EACpB,KAAsB;QAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CACF,OAA6D;QAE7D,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,KAAK;QACL,MAAM,QAAQ,GAAQ,IAAI,CAAC,WAAW,CAAA;QACtC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAC7C,MAAM,UAAU,GAAG,KAAM,SAAQ,QAAQ;YACrC,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;gBAEzB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;YACvC,CAAC;SACJ,CAAA;QACD,KAAK,MAAM,MAAM,IAAI,OAAO;YACxB,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;QAClD,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAQ,CAAA;IAC9D,CAAC;CACJ","file":"Repository.js","sourcesContent":["import { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { ObjectId } from \"../driver/mongodb/typings\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\n\n/**\n * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.\n */\nexport class Repository<Entity extends ObjectLiteral> {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity target that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n readonly target: EntityTarget<Entity>\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n get metadata() {\n return this.manager.connection.getMetadata(this.target)\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n this.target = target\n this.manager = manager\n this.queryRunner = queryRunner\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(\n this.metadata.target as any,\n alias || this.metadata.targetName,\n queryRunner || this.queryRunner,\n )\n }\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(entity: Entity): boolean {\n return this.manager.hasId(this.metadata.target, entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n getId(entity: Entity): any {\n return this.manager.getId(this.metadata.target, entity)\n }\n\n /**\n * Creates a new entity instance.\n */\n create(): Entity\n\n /**\n * Creates new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLikeArray: DeepPartial<Entity>[]): Entity[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLike: DeepPartial<Entity>): Entity\n\n /**\n * Creates a new entity instance or instances.\n * Can copy properties from the given object into new entities.\n */\n create(\n plainEntityLikeOrPlainEntityLikes?:\n | DeepPartial<Entity>\n | DeepPartial<Entity>[],\n ): Entity | Entity[] {\n return this.manager.create<any>(\n this.metadata.target as any,\n plainEntityLikeOrPlainEntityLikes as any,\n )\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(\n mergeIntoEntity: Entity,\n ...entityLikes: DeepPartial<Entity>[]\n ): Entity {\n return this.manager.merge(\n this.metadata.target as any,\n mergeIntoEntity,\n ...entityLikes,\n )\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n preload(entityLike: DeepPartial<Entity>): Promise<Entity | undefined> {\n return this.manager.preload(this.metadata.target as any, entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.save<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Removes a given entities from the database.\n */\n remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>\n\n /**\n * Removes a given entity from the database.\n */\n remove(entity: Entity, options?: RemoveOptions): Promise<Entity>\n\n /**\n * Removes one or many given entities.\n */\n remove(\n entityOrEntities: Entity | Entity[],\n options?: RemoveOptions,\n ): Promise<Entity | Entity[]> {\n return this.manager.remove(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.softRemove<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.recover<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n insert(\n entity:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n ): Promise<InsertResult> {\n return this.manager.insert(this.metadata.target as any, entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n update(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n partialEntity: QueryDeepPartialEntity<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.update(\n this.metadata.target as any,\n criteria as any,\n partialEntity,\n )\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n upsert(\n entityOrEntities:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>,\n ): Promise<InsertResult> {\n return this.manager.upsert(\n this.metadata.target as any,\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n delete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<DeleteResult> {\n return this.manager.delete(this.metadata.target as any, criteria as any)\n }\n\n /**\n * Records the delete date of entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n softDelete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.softDelete(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Restores entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n restore(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.restore(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Checks whether any entity exists that match given options.\n */\n exist(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given options.\n * Useful for pagination.\n */\n count(options?: FindManyOptions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given conditions.\n * Useful for pagination.\n */\n countBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number> {\n return this.manager.countBy(this.metadata.target, where)\n }\n\n /**\n * Return the SUM of a column\n */\n sum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.sum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n average(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.average(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n minimum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.minimum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n maximum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.maximum(this.metadata.target, columnName, where)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async findBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity[]> {\n return this.manager.findBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(\n options?: FindManyOptions<Entity>,\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCount(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCountBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCountBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities with ids.\n * Optionally find options or conditions can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n async findByIds(ids: any[]): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target, ids)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - returns null.\n */\n async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {\n return this.manager.findOne(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - returns null.\n */\n async findOneBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity | null> {\n return this.manager.findOneBy(this.metadata.target, where)\n }\n\n /**\n * Finds first entity that matches given id.\n * If entity was not found in the database - returns null.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n async findOneById(\n id: number | string | Date | ObjectId,\n ): Promise<Entity | null> {\n return this.manager.findOneById(this.metadata.target, id)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - rejects with error.\n */\n async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - rejects with error.\n */\n async findOneByOrFail(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity> {\n return this.manager.findOneByOrFail(this.metadata.target, where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n query(query: string, parameters?: any[]): Promise<any> {\n return this.manager.query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n *\n * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.\n * @see https://stackoverflow.com/a/5972738/925151\n */\n clear(): Promise<void> {\n return this.manager.clear(this.metadata.target)\n }\n\n /**\n * Increments some column by provided value of the entities matched given conditions.\n */\n increment(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.increment(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.decrement(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Extends repository with provided functions.\n */\n extend<CustomRepository>(\n customs: CustomRepository & ThisType<this & CustomRepository>,\n ): this & CustomRepository {\n // return {\n // ...this,\n // ...custom\n // };\n const thisRepo: any = this.constructor\n const { target, manager, queryRunner } = this\n const ChildClass = class extends thisRepo {\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n super(target, manager, queryRunner)\n }\n }\n for (const custom in customs)\n ChildClass.prototype[custom] = customs[custom]\n return new ChildClass(target, manager, queryRunner) as any\n }\n}\n"],"sourceRoot":".."}
@@ -25,12 +25,17 @@ class CommandUtils {
25
25
  typeof dataSourceFileExports !== "object") {
26
26
  throw new Error(`Given data source file must contain export of a DataSource instance`);
27
27
  }
28
+ if (InstanceChecker_1.InstanceChecker.isDataSource(dataSourceFileExports)) {
29
+ return dataSourceFileExports;
30
+ }
28
31
  const dataSourceExports = [];
29
32
  for (const fileExportKey in dataSourceFileExports) {
30
33
  const fileExport = dataSourceFileExports[fileExportKey];
31
34
  // It is necessary to await here in case of the exported async value (Promise<DataSource>).
32
35
  // e.g. the DataSource is instantiated with an async factory in the source file
33
- const awaitedFileExport = fileExport instanceof Promise ? await fileExport : fileExport;
36
+ // It is safe to await regardless of the export being async or not due to `awaits` definition:
37
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#return_value
38
+ const awaitedFileExport = await fileExport;
34
39
  if (InstanceChecker_1.InstanceChecker.isDataSource(awaitedFileExport)) {
35
40
  dataSourceExports.push(awaitedFileExport);
36
41
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/CommandUtils.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AACxB,mDAA4B;AAC5B,4DAA2B;AAC3B,oCAAuC;AAEvC,6DAAyD;AACzD,qDAAyD;AAEzD;;GAEG;AACH,MAAa,YAAY;IACrB,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,kBAA0B;QAE1B,IAAI,qBAAqB,CAAA;QACzB,IAAI;YACA,CAAC;YAAA,CAAC,qBAAqB,CAAC,GAAG,MAAM,IAAA,iCAAmB,EAChD,kBAAkB,CACrB,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,KAAK,CACX,yBAAyB,kBAAkB,MAAM,GAAG,CAAC,OAAO,EAAE,CACjE,CAAA;SACJ;QAED,IACI,CAAC,qBAAqB;YACtB,OAAO,qBAAqB,KAAK,QAAQ,EAC3C;YACE,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;SACJ;QAED,MAAM,iBAAiB,GAAG,EAAE,CAAA;QAC5B,KAAK,MAAM,aAAa,IAAI,qBAAqB,EAAE;YAC/C,MAAM,UAAU,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAA;YACvD,2FAA2F;YAC3F,+EAA+E;YAC/E,MAAM,iBAAiB,GACnB,UAAU,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,CAAC,CAAC,UAAU,CAAA;YACjE,IAAI,iCAAe,CAAC,YAAY,CAAC,iBAAiB,CAAC,EAAE;gBACjD,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;aAC5C;SACJ;QAED,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;SACJ;QACD,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9B,MAAM,IAAI,KA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C,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,uBAA4B;QAC5C,IACI,uBAAuB;YACvB,CAAC,KAAK,CAAC,uBAAuB,CAAC,IAAI,uBAAuB,GAAG,CAAC,CAAC,EACjE;YACE,MAAM,IAAI,oBAAY,CAClB,+DAA+D,uBAAuB,EAAE,CAC3F,CAAA;SACJ;QACD,OAAO,uBAAuB;YAC1B,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,OAAO,EAAE;YACrD,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACpB,CAAC;CACJ;AAvGD,oCAuGC","file":"CommandUtils.js","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport mkdirp from \"mkdirp\"\nimport { TypeORMError } from \"../error\"\nimport { DataSource } from \"../data-source\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Command line utils functions.\n */\nexport class CommandUtils {\n static async loadDataSource(\n dataSourceFilePath: string,\n ): Promise<DataSource> {\n let dataSourceFileExports\n try {\n ;[dataSourceFileExports] = await importOrRequireFile(\n dataSourceFilePath,\n )\n } catch (err) {\n throw new Error(\n `Unable to open file: \"${dataSourceFilePath}\". ${err.message}`,\n )\n }\n\n if (\n !dataSourceFileExports ||\n typeof dataSourceFileExports !== \"object\"\n ) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n\n const dataSourceExports = []\n for (const fileExportKey in dataSourceFileExports) {\n const fileExport = dataSourceFileExports[fileExportKey]\n // It is necessary to await here in case of the exported async value (Promise<DataSource>).\n // e.g. the DataSource is instantiated with an async factory in the source file\n const awaitedFileExport =\n fileExport instanceof Promise ? await fileExport : fileExport\n if (InstanceChecker.isDataSource(awaitedFileExport)) {\n dataSourceExports.push(awaitedFileExport)\n }\n }\n\n if (dataSourceExports.length === 0) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n if (dataSourceExports.length > 1) {\n throw new Error(\n `Given data source file must contain only one export of DataSource instance`,\n )\n }\n return dataSourceExports[0]\n }\n\n /**\n * Creates directories recursively.\n */\n static createDirectories(directory: string) {\n return mkdirp(directory)\n }\n\n /**\n * Creates a file with the given content in the given path.\n */\n static async createFile(\n filePath: string,\n content: string,\n override: boolean = true,\n ): Promise<void> {\n await CommandUtils.createDirectories(path.dirname(filePath))\n return new Promise<void>((ok, fail) => {\n if (override === false && fs.existsSync(filePath)) return ok()\n\n fs.writeFile(filePath, content, (err) => (err ? fail(err) : ok()))\n })\n }\n\n /**\n * Reads everything from a given file and returns its content as a string.\n */\n static async readFile(filePath: string): Promise<string> {\n return new Promise<string>((ok, fail) => {\n fs.readFile(filePath, (err, data) =>\n err ? fail(err) : ok(data.toString()),\n )\n })\n }\n\n static async fileExists(filePath: string) {\n return fs.existsSync(filePath)\n }\n\n /**\n * Gets migration timestamp and validates argument (if sent)\n */\n static getTimestamp(timestampOptionArgument: any): number {\n if (\n timestampOptionArgument &&\n (isNaN(timestampOptionArgument) || timestampOptionArgument < 0)\n ) {\n throw new TypeORMError(\n `timestamp option should be a non-negative number. received: ${timestampOptionArgument}`,\n )\n }\n return timestampOptionArgument\n ? new Date(Number(timestampOptionArgument)).getTime()\n : Date.now()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/CommandUtils.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AACxB,mDAA4B;AAC5B,4DAA2B;AAC3B,oCAAuC;AAEvC,6DAAyD;AACzD,qDAAyD;AAEzD;;GAEG;AACH,MAAa,YAAY;IACrB,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,kBAA0B;QAE1B,IAAI,qBAAqB,CAAA;QACzB,IAAI;YACA,CAAC;YAAA,CAAC,qBAAqB,CAAC,GAAG,MAAM,IAAA,iCAAmB,EAChD,kBAAkB,CACrB,CAAA;SACJ;Q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;YACrD,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACpB,CAAC;CACJ;AA5GD,oCA4GC","file":"CommandUtils.js","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport mkdirp from \"mkdirp\"\nimport { TypeORMError } from \"../error\"\nimport { DataSource } from \"../data-source\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Command line utils functions.\n */\nexport class CommandUtils {\n static async loadDataSource(\n dataSourceFilePath: string,\n ): Promise<DataSource> {\n let dataSourceFileExports\n try {\n ;[dataSourceFileExports] = await importOrRequireFile(\n dataSourceFilePath,\n )\n } catch (err) {\n throw new Error(\n `Unable to open file: \"${dataSourceFilePath}\". ${err.message}`,\n )\n }\n\n if (\n !dataSourceFileExports ||\n typeof dataSourceFileExports !== \"object\"\n ) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n\n if (InstanceChecker.isDataSource(dataSourceFileExports)) {\n return dataSourceFileExports\n }\n\n const dataSourceExports = []\n for (const fileExportKey in dataSourceFileExports) {\n const fileExport = dataSourceFileExports[fileExportKey]\n // It is necessary to await here in case of the exported async value (Promise<DataSource>).\n // e.g. the DataSource is instantiated with an async factory in the source file\n // It is safe to await regardless of the export being async or not due to `awaits` definition:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#return_value\n const awaitedFileExport = await fileExport\n if (InstanceChecker.isDataSource(awaitedFileExport)) {\n dataSourceExports.push(awaitedFileExport)\n }\n }\n\n if (dataSourceExports.length === 0) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n if (dataSourceExports.length > 1) {\n throw new Error(\n `Given data source file must contain only one export of DataSource instance`,\n )\n }\n return dataSourceExports[0]\n }\n\n /**\n * Creates directories recursively.\n */\n static createDirectories(directory: string) {\n return mkdirp(directory)\n }\n\n /**\n * Creates a file with the given content in the given path.\n */\n static async createFile(\n filePath: string,\n content: string,\n override: boolean = true,\n ): Promise<void> {\n await CommandUtils.createDirectories(path.dirname(filePath))\n return new Promise<void>((ok, fail) => {\n if (override === false && fs.existsSync(filePath)) return ok()\n\n fs.writeFile(filePath, content, (err) => (err ? fail(err) : ok()))\n })\n }\n\n /**\n * Reads everything from a given file and returns its content as a string.\n */\n static async readFile(filePath: string): Promise<string> {\n return new Promise<string>((ok, fail) => {\n fs.readFile(filePath, (err, data) =>\n err ? fail(err) : ok(data.toString()),\n )\n })\n }\n\n static async fileExists(filePath: string) {\n return fs.existsSync(filePath)\n }\n\n /**\n * Gets migration timestamp and validates argument (if sent)\n */\n static getTimestamp(timestampOptionArgument: any): number {\n if (\n timestampOptionArgument &&\n (isNaN(timestampOptionArgument) || timestampOptionArgument < 0)\n ) {\n throw new TypeORMError(\n `timestamp option should be a non-negative number. received: ${timestampOptionArgument}`,\n )\n }\n return timestampOptionArgument\n ? new Date(Number(timestampOptionArgument)).getTime()\n : Date.now()\n }\n}\n"],"sourceRoot":".."}
@@ -5,6 +5,9 @@ import * as yargs from "yargs";
5
5
  export declare class EntityCreateCommand implements yargs.CommandModule {
6
6
  command: string;
7
7
  describe: string;
8
+ builder(args: yargs.Argv): yargs.Argv<{
9
+ path: string;
10
+ }>;
8
11
  handler(args: yargs.Arguments): Promise<void>;
9
12
  /**
10
13
  * Gets contents of the entity file.
@@ -14,6 +14,13 @@ class EntityCreateCommand {
14
14
  this.command = "entity:create <path>";
15
15
  this.describe = "Generates a new entity.";
16
16
  }
17
+ builder(args) {
18
+ return args.positional("path", {
19
+ type: "string",
20
+ describe: "Path of the entity file",
21
+ demandOption: true,
22
+ });
23
+ }
17
24
  async handler(args) {
18
25
  try {
19
26
  const fullPath = args.path.startsWith("/")
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/EntityCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAE7C,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AAEvB;;GAEG;AACH,MAA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A7CD,kDA6CC","file":"EntityCreateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\n\n/**\n * Generates a new entity.\n */\nexport class EntityCreateCommand implements yargs.CommandModule {\n command = \"entity:create <path>\"\n describe = \"Generates a new entity.\"\n\n async handler(args: yargs.Arguments) {\n try {\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = path.basename(fullPath)\n const fileContent = EntityCreateCommand.getTemplate(filename)\n const fileExists = await CommandUtils.fileExists(fullPath + \".ts\")\n if (fileExists) {\n throw `File ${chalk.blue(fullPath + \".ts\")} already exists`\n }\n await CommandUtils.createFile(fullPath + \".ts\", fileContent)\n console.log(\n chalk.green(\n `Entity ${chalk.blue(\n fullPath + \".ts\",\n )} has been created successfully.`,\n ),\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during entity creation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the entity file.\n */\n protected static getTemplate(name: string): string {\n return `import { Entity } from \"typeorm\"\n\n@Entity()\nexport class ${name} {\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/EntityCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAE7C,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AAEvB;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,sBAAsB,CAAA;QAChC,aAAQ,GAAG,yBAAyB,CAAA;IAmDxC,CAAC;IAjDG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YAC3B,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,yBAAyB;YACnC,YAAY,EAAE,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"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\n\n/**\n * Generates a new entity.\n */\nexport class EntityCreateCommand implements yargs.CommandModule {\n command = \"entity:create <path>\"\n describe = \"Generates a new entity.\"\n\n builder(args: yargs.Argv) {\n return args.positional(\"path\", {\n type: \"string\",\n describe: \"Path of the entity file\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = path.basename(fullPath)\n const fileContent = EntityCreateCommand.getTemplate(filename)\n const fileExists = await CommandUtils.fileExists(fullPath + \".ts\")\n if (fileExists) {\n throw `File ${chalk.blue(fullPath + \".ts\")} already exists`\n }\n await CommandUtils.createFile(fullPath + \".ts\", fileContent)\n console.log(\n chalk.green(\n `Entity ${chalk.blue(\n fullPath + \".ts\",\n )} has been created successfully.`,\n ),\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during entity creation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the entity file.\n */\n protected static getTemplate(name: string): string {\n return `import { Entity } from \"typeorm\"\n\n@Entity()\nexport class ${name} {\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
@@ -6,11 +6,15 @@ export declare class MigrationCreateCommand implements yargs.CommandModule {
6
6
  command: string;
7
7
  describe: string;
8
8
  builder(args: yargs.Argv): yargs.Argv<{
9
+ path: string;
10
+ } & {
9
11
  o: boolean;
10
12
  } & {
11
13
  t: number | boolean;
12
14
  }>;
13
- handler(args: yargs.Arguments): Promise<void>;
15
+ handler(args: yargs.Arguments<any & {
16
+ path: string;
17
+ }>): Promise<void>;
14
18
  /**
15
19
  * Gets contents of the migration file.
16
20
  */
@@ -17,6 +17,11 @@ class MigrationCreateCommand {
17
17
  }
18
18
  builder(args) {
19
19
  return args
20
+ .positional("path", {
21
+ type: "string",
22
+ describe: "Path of the migration file",
23
+ demandOption: true,
24
+ })
20
25
  .option("o", {
21
26
  alias: "outputJs",
22
27
  type: "boolean",
@@ -56,7 +61,7 @@ class MigrationCreateCommand {
56
61
  * Gets contents of the migration file.
57
62
  */
58
63
  static getTemplate(name, timestamp) {
59
- return `import { MigrationInterface, QueryRunner } from "typeorm"
64
+ return `import { MigrationInterface, QueryRunner } from "typeorm";
60
65
 
61
66
  export class ${(0, StringUtils_1.camelCase)(name, true)}${timestamp} implements MigrationInterface {
62
67
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,qDAA+C;AAE/C,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AAEvB;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,yBAAyB,CAAA;QACnC,aAAQ,GAAG,+BAA+B,CAAA;IAgG9C,CAAC;IA9FG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,+DAA+D;SACtE,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,yCAAyC;SACtD,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI;YACA,MAAM,SAAS,GAAG,2BAAY,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC3D,MAAM,SAAS,GAAI,IAAI,CAAC,IAAe,CAAC,UAAU,CAAC,GAAG,CAAC;gBACnD,CAAC,CAAE,IAAI,CAAC,IAAe;gBACvB,CAAC,CAAC,cAA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OAAO;;yBAEU,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS;;;;;;;;;CASzD,CAAA;IACG,CAAC;CACJ;AAlGD,wDAkGC","file":"MigrationCreateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\n\n/**\n * Creates a new migration file.\n */\nexport class MigrationCreateCommand implements yargs.CommandModule {\n command = \"migration:create <path>\"\n describe = \"Creates a new migration file.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const inputPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = path.basename(inputPath)\n const fullPath =\n path.dirname(inputPath) + \"/\" + timestamp + \"-\" + filename\n\n const fileContent = args.outputJs\n ? MigrationCreateCommand.getJavascriptTemplate(\n filename,\n timestamp,\n )\n : MigrationCreateCommand.getTemplate(filename, timestamp)\n\n await CommandUtils.createFile(\n fullPath + (args.outputJs ? \".js\" : \".ts\"),\n fileContent,\n )\n console.log(\n `Migration ${chalk.blue(\n fullPath + (args.outputJs ? \".js\" : \".ts\"),\n )} has been generated successfully.`,\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration creation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number): string {\n return `import { MigrationInterface, QueryRunner } from \"typeorm\"\n\nexport class ${camelCase(\n name,\n true,\n )}${timestamp} implements MigrationInterface {\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n ): string {\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${camelCase(name, true)}${timestamp} {\n\n async up(queryRunner) {\n }\n\n async down(queryRunner) {\n }\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,qDAA+C;AAE/C,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AAEvB;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,yBAAyB,CAAA;QACnC,aAAQ,GAAG,+BAA+B,CAAA;IAqG9C,CAAC;IAnGG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,4BAA4B;YACtC,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,+DAA+D;SACtE,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,yCAAyC;SACtD,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAA6C;QACvD,IAAI;YACA,MAAM,SAAS,GAAG,2BAAY,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC3D,MAAM,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,CACP,GAAG,SAAS;;;;;;;;;CASpB,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,qBAAqB,CAClC,IAAY,EACZ,SAAiB;QAEjB,OAAO;;yBAEU,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS;;;;;;;;;CASzD,CAAA;IACG,CAAC;CACJ;AAvGD,wDAuGC","file":"MigrationCreateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\n\n/**\n * Creates a new migration file.\n */\nexport class MigrationCreateCommand implements yargs.CommandModule {\n command = \"migration:create <path>\"\n describe = \"Creates a new migration file.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"path\", {\n type: \"string\",\n describe: \"Path of the migration file\",\n demandOption: true,\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments<any & { path: string }>) {\n try {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const inputPath = args.path.startsWith(\"/\")\n ? args.path\n : path.resolve(process.cwd(), args.path)\n const filename = path.basename(inputPath)\n const fullPath =\n path.dirname(inputPath) + \"/\" + timestamp + \"-\" + filename\n\n const fileContent = args.outputJs\n ? MigrationCreateCommand.getJavascriptTemplate(\n filename,\n timestamp,\n )\n : MigrationCreateCommand.getTemplate(filename, timestamp)\n\n await CommandUtils.createFile(\n fullPath + (args.outputJs ? \".js\" : \".ts\"),\n fileContent,\n )\n console.log(\n `Migration ${chalk.blue(\n fullPath + (args.outputJs ? \".js\" : \".ts\"),\n )} has been generated successfully.`,\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration creation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number): string {\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${camelCase(\n name,\n true,\n )}${timestamp} implements MigrationInterface {\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n ): string {\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${camelCase(name, true)}${timestamp} {\n\n async up(queryRunner) {\n }\n\n async down(queryRunner) {\n }\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
@@ -6,6 +6,8 @@ export declare class MigrationGenerateCommand implements yargs.CommandModule {
6
6
  command: string;
7
7
  describe: string;
8
8
  builder(args: yargs.Argv): yargs.Argv<{
9
+ path: string;
10
+ } & {
9
11
  dataSource: string;
10
12
  } & {
11
13
  p: boolean;
@@ -18,7 +20,9 @@ export declare class MigrationGenerateCommand implements yargs.CommandModule {
18
20
  } & {
19
21
  t: number | boolean;
20
22
  }>;
21
- handler(args: yargs.Arguments): Promise<void>;
23
+ handler(args: yargs.Arguments<any & {
24
+ path: string;
25
+ }>): Promise<void>;
22
26
  /**
23
27
  * Formats query parameters for migration queries if parameters actually exist
24
28
  */
@@ -19,6 +19,11 @@ class MigrationGenerateCommand {
19
19
  }
20
20
  builder(args) {
21
21
  return args
22
+ .positional("path", {
23
+ type: "string",
24
+ describe: "Path of the migration file",
25
+ demandOption: true,
26
+ })
22
27
  .option("dataSource", {
23
28
  alias: "d",
24
29
  type: "string",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA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EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QACxD,OAAO,CACH,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CACtE,CAAA;IACL,CAAC;CACJ;AApRD,4DAoRC","file":"MigrationGenerateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport * as path from \"path\"\nimport process from \"process\"\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n command = \"migration:generate <path>\"\n describe =\n \"Generates a new migration file with sql needs to be executed to update schema.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n type: \"string\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe:\n \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe:\n \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const extension = args.outputJs ? \".js\" : \".ts\"\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = timestamp + \"-\" + path.basename(fullPath) + extension\n\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const upSqls: string[] = [],\n downSqls: string[] = []\n\n try {\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach((upQuery) => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(\n upQuery.query,\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downQuery.query =\n MigrationGenerateCommand.prettifyQuery(\n downQuery.query,\n )\n })\n }\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n upSqls.push(\n \" await queryRunner.query(`\" +\n upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n upQuery.parameters,\n ) +\n \");\",\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downSqls.push(\n \" await queryRunner.query(`\" +\n downQuery.query.replace(\n new RegExp(\"`\", \"g\"),\n \"\\\\`\",\n ) +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n downQuery.parameters,\n ) +\n \");\",\n )\n })\n } finally {\n await dataSource.destroy()\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(\n chalk.green(`No changes in database schema were found`),\n )\n process.exit(0)\n } else {\n console.log(\n chalk.yellow(\n `No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`,\n ),\n )\n process.exit(1)\n }\n } else if (!args.path) {\n console.log(chalk.yellow(\"Please specify a migration path\"))\n process.exit(1)\n }\n\n const fileContent = args.outputJs\n ? MigrationGenerateCommand.getJavascriptTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n : MigrationGenerateCommand.getTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n\n if (args.check) {\n console.log(\n chalk.yellow(\n `Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(\n fileContent,\n )}`,\n ),\n )\n process.exit(1)\n }\n\n if (args.dryrun) {\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n fullPath + extension,\n )} has content:\\n\\n${chalk.white(fileContent)}`,\n ),\n )\n } else {\n const migrationFileName =\n path.dirname(fullPath) + \"/\" + filename\n await CommandUtils.createFile(migrationFileName, fileContent)\n\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n migrationFileName,\n )} has been generated successfully.`,\n ),\n )\n process.exit(0)\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\"\n }\n\n return `, ${JSON.stringify(parameters)}`\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" })\n return (\n \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \"\n )\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,qDAA+C;AAE/C,0DAAyB;AACzB,uEAA6D;AAC7D,6DAAyD;AAEzD,mDAA4B;AAC5B,8DAA6B;AAE7B;;GAEG;AACH,MAAa,wBAAwB;IAArC;QACI,YAAO,GAAG,2BAA2B,CAAA;QACrC,aAAQ,GACJ,gFAAgF,CAAA;IAsRxF,CAAC;IApRG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,4BAA4B;YACtC,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,QAAQ;YACd,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,4BAA4B;SACzC,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,+DAA+D;SACtE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,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I,CAAC;CACf,CAAC;;;;CAID,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,qBAAqB,CAClC,IAAY,EACZ,SAAiB,EACjB,MAAgB,EAChB,QAAkB;QAElB,MAAM,aAAa,GAAG,GAAG,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,EAAE,CAAA;QAE5D,OAAO;;yBAEU,aAAa;cACxB,aAAa;;;EAGzB,MAAM,CAAC,IAAI,CAAC;CACb,CAAC;;;;EAIA,QAAQ,CAAC,IAAI,CAAC;CACf,CAAC;;;CAGD,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,aAAa,CAAC,KAAa;QACxC,MAAM,cAAc,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QACxD,OAAO,CACH,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CACtE,CAAA;IACL,CAAC;CACJ;AAzRD,4DAyRC","file":"MigrationGenerateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport * as path from \"path\"\nimport process from \"process\"\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n command = \"migration:generate <path>\"\n describe =\n \"Generates a new migration file with sql needs to be executed to update schema.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"path\", {\n type: \"string\",\n describe: \"Path of the migration file\",\n demandOption: true,\n })\n .option(\"dataSource\", {\n alias: \"d\",\n type: \"string\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe:\n \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe:\n \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments<any & { path: string }>) {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const extension = args.outputJs ? \".js\" : \".ts\"\n const fullPath = args.path.startsWith(\"/\")\n ? args.path\n : path.resolve(process.cwd(), args.path)\n const filename = timestamp + \"-\" + path.basename(fullPath) + extension\n\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const upSqls: string[] = [],\n downSqls: string[] = []\n\n try {\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach((upQuery) => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(\n upQuery.query,\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downQuery.query =\n MigrationGenerateCommand.prettifyQuery(\n downQuery.query,\n )\n })\n }\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n upSqls.push(\n \" await queryRunner.query(`\" +\n upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n upQuery.parameters,\n ) +\n \");\",\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downSqls.push(\n \" await queryRunner.query(`\" +\n downQuery.query.replace(\n new RegExp(\"`\", \"g\"),\n \"\\\\`\",\n ) +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n downQuery.parameters,\n ) +\n \");\",\n )\n })\n } finally {\n await dataSource.destroy()\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(\n chalk.green(`No changes in database schema were found`),\n )\n process.exit(0)\n } else {\n console.log(\n chalk.yellow(\n `No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`,\n ),\n )\n process.exit(1)\n }\n } else if (!args.path) {\n console.log(chalk.yellow(\"Please specify a migration path\"))\n process.exit(1)\n }\n\n const fileContent = args.outputJs\n ? MigrationGenerateCommand.getJavascriptTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n : MigrationGenerateCommand.getTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n\n if (args.check) {\n console.log(\n chalk.yellow(\n `Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(\n fileContent,\n )}`,\n ),\n )\n process.exit(1)\n }\n\n if (args.dryrun) {\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n fullPath + extension,\n )} has content:\\n\\n${chalk.white(fileContent)}`,\n ),\n )\n } else {\n const migrationFileName =\n path.dirname(fullPath) + \"/\" + filename\n await CommandUtils.createFile(migrationFileName, fileContent)\n\n console.log(\n chalk.green(\n `Migration ${chalk.blue(\n migrationFileName,\n )} has been generated successfully.`,\n ),\n )\n process.exit(0)\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\"\n }\n\n return `, ${JSON.stringify(parameters)}`\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" })\n return (\n \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \"\n )\n }\n}\n"],"sourceRoot":".."}
@@ -5,6 +5,9 @@ import * as yargs from "yargs";
5
5
  export declare class SubscriberCreateCommand implements yargs.CommandModule {
6
6
  command: string;
7
7
  describe: string;
8
+ builder(args: yargs.Argv): yargs.Argv<{
9
+ path: string;
10
+ }>;
8
11
  handler(args: yargs.Arguments): Promise<void>;
9
12
  /**
10
13
  * Gets contents of the entity file.
@@ -14,6 +14,13 @@ class SubscriberCreateCommand {
14
14
  this.command = "subscriber:create <path>";
15
15
  this.describe = "Generates a new subscriber.";
16
16
  }
17
+ builder(args) {
18
+ return args.positional("path", {
19
+ type: "string",
20
+ describe: "Path of the subscriber file",
21
+ demandOption: true,
22
+ });
23
+ }
17
24
  async handler(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AClB;IACL,CAAC;IAED,4EAA4E;IAC5E,2BAA2B;IAC3B,4EAA4E;IAE5E;;OAEG;IACO,MAAM,CAAC,WAAW,CAAC,IAAY;QACrC,OAAO;;;eAGA,IAAI;;;CAGlB,CAAA;IACG,CAAC;CACJ;AA7CD,0DA6CC","file":"SubscriberCreateCommand.js","sourcesContent":["import * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Generates a new subscriber.\n */\nexport class SubscriberCreateCommand implements yargs.CommandModule {\n command = \"subscriber:create <path>\"\n describe = \"Generates a new subscriber.\"\n\n async handler(args: yargs.Arguments) {\n try {\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = path.basename(fullPath)\n const fileContent = SubscriberCreateCommand.getTemplate(filename)\n const fileExists = await CommandUtils.fileExists(fullPath + \".ts\")\n if (fileExists) {\n throw `File ${chalk.blue(fullPath + \".ts\")} already exists`\n }\n await CommandUtils.createFile(fullPath + \".ts\", fileContent)\n console.log(\n chalk.green(\n `Subscriber ${chalk.blue(\n fullPath,\n )} has been created successfully.`,\n ),\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during subscriber creation:\")\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the entity file.\n */\n protected static getTemplate(name: string): string {\n return `import { EventSubscriber, EntitySubscriberInterface } from \"typeorm\"\n\n@EventSubscriber()\nexport class ${name} implements EntitySubscriberInterface {\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/SubscriberCreateCommand.ts"],"names":[],"mappings":";;;;AACA,0DAAyB;AACzB,wDAAuB;AACvB,6DAAyD;AACzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,uBAAuB;IAApC;QACI,YA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;IAC3B,4EAA4E;IAE5E;;OAEG;IACO,MAAM,CAAC,WAAW,CAAC,IAAY;QACrC,OAAO;;;eAGA,IAAI;;;CAGlB,CAAA;IACG,CAAC;CACJ;AArDD,0DAqDC","file":"SubscriberCreateCommand.js","sourcesContent":["import * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Generates a new subscriber.\n */\nexport class SubscriberCreateCommand implements yargs.CommandModule {\n command = \"subscriber:create <path>\"\n describe = \"Generates a new subscriber.\"\n\n builder(args: yargs.Argv) {\n return args.positional(\"path\", {\n type: \"string\",\n describe: \"Path of the subscriber file\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = path.basename(fullPath)\n const fileContent = SubscriberCreateCommand.getTemplate(filename)\n const fileExists = await CommandUtils.fileExists(fullPath + \".ts\")\n if (fileExists) {\n throw `File ${chalk.blue(fullPath + \".ts\")} already exists`\n }\n await CommandUtils.createFile(fullPath + \".ts\", fileContent)\n console.log(\n chalk.green(\n `Subscriber ${chalk.blue(\n fullPath,\n )} has been created successfully.`,\n ),\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during subscriber creation:\")\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the entity file.\n */\n protected static getTemplate(name: string): string {\n return `import { EventSubscriber, EntitySubscriberInterface } from \"typeorm\"\n\n@EventSubscriber()\nexport class ${name} implements EntitySubscriberInterface {\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
@@ -93,11 +93,8 @@ class DriverUtils {
93
93
  * @return An alias that is no longer than the divers max alias length.
94
94
  */
95
95
  static buildAlias({ maxAliasLength }, buildOptions, ...alias) {
96
- const newAlias = alias.length === 1
97
- ? alias[0]
98
- : alias.join(buildOptions && buildOptions.joiner
99
- ? buildOptions.joiner
100
- : "_");
96
+ const joiner = buildOptions && buildOptions.joiner ? buildOptions.joiner : "_";
97
+ let newAlias = alias.length === 1 ? alias[0] : alias.join(joiner);
101
98
  if (maxAliasLength &&
102
99
  maxAliasLength > 0 &&
103
100
  newAlias.length > maxAliasLength) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/DriverUtils.ts"],"names":[],"mappings":";;;AACA,qDAAmD;AACnD,uDAAmD;AAEnD;;GAEG;AACH,MAAa,WAAW;IACpB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc;QAChC,OAAO;YACH,QAAQ;YACR,SAAS;YACT,cAAc;YACd,cAAc;YACd,OAAO;YACP,MAAM;YACN,gBAAgB;YAChB,WAAW;SACd,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAc;QAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,CAAC,yBAAyB,CAAC,MAAc,EAAE,OAAe;QAC5D,OAAO,CACH,MAAM,CAAC,OAAO,IAAI,IAAI;YACtB,2BAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CACzD,CAAA;IACL,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAc;QAClC,OAAO,CAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC,QAAQ,CAC1D,MAAM,CAAC,OAAO,CAAC,IAAI,CACtB,CAAA;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CACrB,OAAY,EACZ,YAAkC;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CAAC;CACJ;AAvSD,kCAuSC","file":"DriverUtils.js","sourcesContent":["import { Driver } from \"./Driver\"\nimport { hash, shorten } from \"../util/StringUtils\"\nimport { VersionUtils } from \"../util/VersionUtils\"\n\n/**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns true if given driver is SQLite-based driver.\n */\n static isSQLiteFamily(driver: Driver): boolean {\n return [\n \"sqlite\",\n \"cordova\",\n \"react-native\",\n \"nativescript\",\n \"sqljs\",\n \"expo\",\n \"better-sqlite3\",\n \"capacitor\",\n ].includes(driver.options.type)\n }\n\n /**\n * Returns true if given driver is MySQL-based driver.\n */\n static isMySQLFamily(driver: Driver): boolean {\n return [\"mysql\", \"mariadb\"].includes(driver.options.type)\n }\n\n static isReleaseVersionOrGreater(driver: Driver, version: string): boolean {\n return (\n driver.version != null &&\n VersionUtils.isGreaterOrEqual(driver.version, version)\n )\n }\n\n static isPostgresFamily(driver: Driver): boolean {\n return [\"postgres\", \"aurora-postgres\", \"cockroachdb\"].includes(\n driver.options.type,\n )\n }\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseConnectionUrl(options.url) as {\n [key: string]: any\n }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * buildDriverOptions for MongodDB only to support replica set\n */\n static buildMongoDBDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseMongoDBConnectionUrl(\n options.url,\n ) as { [key: string]: any }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * Joins and shortens alias if needed.\n *\n * If the alias length is greater than the limit allowed by the current\n * driver, replaces it with a shortend string, if the shortend string\n * is still too long, it will then hash the alias.\n *\n * @param driver Current `Driver`.\n * @param buildOptions Optional settings.\n * @param alias Alias parts.\n *\n * @return An alias that is no longer than the divers max alias length.\n */\n static buildAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | undefined,\n ...alias: string[]\n ): string {\n const newAlias =\n alias.length === 1\n ? alias[0]\n : alias.join(\n buildOptions && buildOptions.joiner\n ? buildOptions.joiner\n : \"_\",\n )\n if (\n maxAliasLength &&\n maxAliasLength > 0 &&\n newAlias.length > maxAliasLength\n ) {\n if (buildOptions && buildOptions.shorten === true) {\n const shortenedAlias = shorten(newAlias)\n if (shortenedAlias.length < maxAliasLength) {\n return shortenedAlias\n }\n }\n\n return hash(newAlias, { length: maxAliasLength })\n }\n\n return newAlias\n }\n\n /**\n * @deprecated use `buildAlias` instead.\n */\n static buildColumnAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | string,\n ...alias: string[]\n ) {\n if (typeof buildOptions === \"string\") {\n alias.unshift(buildOptions)\n buildOptions = { shorten: false, joiner: \"_\" }\n } else {\n buildOptions = Object.assign(\n { shorten: false, joiner: \"_\" },\n buildOptions,\n )\n }\n return this.buildAlias(\n { maxAliasLength } as Driver,\n buildOptions,\n ...alias,\n )\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n // remove mongodb query params\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n const [host, port] = hostAndPort.split(\":\")\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n }\n\n /**\n * Extracts connection data from the connection url for MongoDB to support replica set.\n */\n private static parseMongoDBConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n let afterQuestionMark = \"\"\n let host = undefined\n let port = undefined\n let hostReplicaSet = undefined\n let replicaSet = undefined\n\n let optionsObject: any = {}\n\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n // split params\n afterQuestionMark = afterBase.substr(\n afterBase.indexOf(\"?\") + 1,\n afterBase.length,\n )\n\n const optionsList = afterQuestionMark.split(\"&\")\n let optionKey: string\n let optionValue: string\n\n // create optionsObject for merge with connectionUrl object before return\n optionsList.forEach((optionItem) => {\n optionKey = optionItem.split(\"=\")[0]\n optionValue = optionItem.split(\"=\")[1]\n optionsObject[optionKey] = optionValue\n })\n\n // specific replicaSet value to set options about hostReplicaSet\n replicaSet = optionsObject[\"replicaSet\"]\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n\n // If replicaSet have value set It as hostlist, If not set like standalone host\n if (replicaSet) {\n hostReplicaSet = hostAndPort\n } else {\n ;[host, port] = hostAndPort.split(\":\")\n }\n\n let connectionUrl: any = {\n type: type,\n host: host,\n hostReplicaSet: hostReplicaSet,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n\n // Loop to set every options in connectionUrl to object\n for (const [key, value] of Object.entries(optionsObject)) {\n connectionUrl[key] = value\n }\n\n return connectionUrl\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/driver/DriverUtils.ts"],"names":[],"mappings":";;;AACA,qDAAmD;AACnD,uDAAmD;AAEnD;;GAEG;AACH,MAAa,WAAW;IACpB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc;QAChC,OAAO;YACH,QAAQ;YACR,SAAS;YACT,cAAc;YACd,cAAc;YACd,OAAO;YACP,MAAM;YACN,gBAAgB;YAChB,WAAW;SACd,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAc;QAC/B,OAAO,CAAC,OAAO,E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AAC,GAAG,CAAC,CAAA;SACzC;QAED,IAAI,aAAa,GAAQ;YACrB,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,IAAI;YACV,cAAc,EAAE,cAAc;YAC9B,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YACvC,QAAQ,EAAE,SAAS,IAAI,SAAS;SACnC,CAAA;QAED,uDAAuD;QACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACtD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SAC7B;QAED,OAAO,aAAa,CAAA;IACxB,CAAC;CACJ;AApSD,kCAoSC","file":"DriverUtils.js","sourcesContent":["import { Driver } from \"./Driver\"\nimport { hash, shorten } from \"../util/StringUtils\"\nimport { VersionUtils } from \"../util/VersionUtils\"\n\n/**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns true if given driver is SQLite-based driver.\n */\n static isSQLiteFamily(driver: Driver): boolean {\n return [\n \"sqlite\",\n \"cordova\",\n \"react-native\",\n \"nativescript\",\n \"sqljs\",\n \"expo\",\n \"better-sqlite3\",\n \"capacitor\",\n ].includes(driver.options.type)\n }\n\n /**\n * Returns true if given driver is MySQL-based driver.\n */\n static isMySQLFamily(driver: Driver): boolean {\n return [\"mysql\", \"mariadb\"].includes(driver.options.type)\n }\n\n static isReleaseVersionOrGreater(driver: Driver, version: string): boolean {\n return (\n driver.version != null &&\n VersionUtils.isGreaterOrEqual(driver.version, version)\n )\n }\n\n static isPostgresFamily(driver: Driver): boolean {\n return [\"postgres\", \"aurora-postgres\", \"cockroachdb\"].includes(\n driver.options.type,\n )\n }\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseConnectionUrl(options.url) as {\n [key: string]: any\n }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * buildDriverOptions for MongodDB only to support replica set\n */\n static buildMongoDBDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseMongoDBConnectionUrl(\n options.url,\n ) as { [key: string]: any }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * Joins and shortens alias if needed.\n *\n * If the alias length is greater than the limit allowed by the current\n * driver, replaces it with a shortend string, if the shortend string\n * is still too long, it will then hash the alias.\n *\n * @param driver Current `Driver`.\n * @param buildOptions Optional settings.\n * @param alias Alias parts.\n *\n * @return An alias that is no longer than the divers max alias length.\n */\n static buildAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | undefined,\n ...alias: string[]\n ): string {\n const joiner =\n buildOptions && buildOptions.joiner ? buildOptions.joiner : \"_\"\n\n let newAlias = alias.length === 1 ? alias[0] : alias.join(joiner)\n\n if (\n maxAliasLength &&\n maxAliasLength > 0 &&\n newAlias.length > maxAliasLength\n ) {\n if (buildOptions && buildOptions.shorten === true) {\n const shortenedAlias = shorten(newAlias)\n if (shortenedAlias.length < maxAliasLength) {\n return shortenedAlias\n }\n }\n\n return hash(newAlias, { length: maxAliasLength })\n }\n\n return newAlias\n }\n\n /**\n * @deprecated use `buildAlias` instead.\n */\n static buildColumnAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | string,\n ...alias: string[]\n ) {\n if (typeof buildOptions === \"string\") {\n alias.unshift(buildOptions)\n buildOptions = { shorten: false, joiner: \"_\" }\n } else {\n buildOptions = Object.assign(\n { shorten: false, joiner: \"_\" },\n buildOptions,\n )\n }\n return this.buildAlias(\n { maxAliasLength } as Driver,\n buildOptions,\n ...alias,\n )\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n // remove mongodb query params\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n const [host, port] = hostAndPort.split(\":\")\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n }\n\n /**\n * Extracts connection data from the connection url for MongoDB to support replica set.\n */\n private static parseMongoDBConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n let afterQuestionMark = \"\"\n let host = undefined\n let port = undefined\n let hostReplicaSet = undefined\n let replicaSet = undefined\n\n let optionsObject: any = {}\n\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n // split params\n afterQuestionMark = afterBase.substr(\n afterBase.indexOf(\"?\") + 1,\n afterBase.length,\n )\n\n const optionsList = afterQuestionMark.split(\"&\")\n let optionKey: string\n let optionValue: string\n\n // create optionsObject for merge with connectionUrl object before return\n optionsList.forEach((optionItem) => {\n optionKey = optionItem.split(\"=\")[0]\n optionValue = optionItem.split(\"=\")[1]\n optionsObject[optionKey] = optionValue\n })\n\n // specific replicaSet value to set options about hostReplicaSet\n replicaSet = optionsObject[\"replicaSet\"]\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n\n // If replicaSet have value set It as hostlist, If not set like standalone host\n if (replicaSet) {\n hostReplicaSet = hostAndPort\n } else {\n ;[host, port] = hostAndPort.split(\":\")\n }\n\n let connectionUrl: any = {\n type: type,\n host: host,\n hostReplicaSet: hostReplicaSet,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n\n // Loop to set every options in connectionUrl to object\n for (const [key, value] of Object.entries(optionsObject)) {\n connectionUrl[key] = value\n }\n\n return connectionUrl\n }\n}\n"],"sourceRoot":".."}
@@ -1,11 +1,12 @@
1
1
  import { DefaultAuthentication } from "./authentication/DefaultAuthentication";
2
2
  import { AzureActiveDirectoryAccessTokenAuthentication } from "./authentication/AzureActiveDirectoryAccessTokenAuthentication";
3
+ import { AzureActiveDirectoryDefaultAuthentication } from "./authentication/AzureActiveDirectoryDefaultAuthentication";
3
4
  import { AzureActiveDirectoryMsiAppServiceAuthentication } from "./authentication/AzureActiveDirectoryMsiAppServiceAuthentication";
4
5
  import { AzureActiveDirectoryMsiVmAuthentication } from "./authentication/AzureActiveDirectoryMsiVmAuthentication";
5
6
  import { AzureActiveDirectoryPasswordAuthentication } from "./authentication/AzureActiveDirectoryPasswordAuthentication";
6
7
  import { AzureActiveDirectoryServicePrincipalSecret } from "./authentication/AzureActiveDirectoryServicePrincipalSecret";
7
8
  import { NtlmAuthentication } from "./authentication/NtlmAuthentication";
8
- export type SqlServerConnectionCredentialsAuthenticationOptions = DefaultAuthentication | NtlmAuthentication | AzureActiveDirectoryAccessTokenAuthentication | AzureActiveDirectoryMsiAppServiceAuthentication | AzureActiveDirectoryMsiVmAuthentication | AzureActiveDirectoryPasswordAuthentication | AzureActiveDirectoryServicePrincipalSecret;
9
+ export type SqlServerConnectionCredentialsAuthenticationOptions = DefaultAuthentication | NtlmAuthentication | AzureActiveDirectoryAccessTokenAuthentication | AzureActiveDirectoryDefaultAuthentication | AzureActiveDirectoryMsiAppServiceAuthentication | AzureActiveDirectoryMsiVmAuthentication | AzureActiveDirectoryPasswordAuthentication | AzureActiveDirectoryServicePrincipalSecret;
9
10
  /**
10
11
  * SqlServer specific connection credential options.
11
12
  */