typeorm 0.3.9 → 0.3.10-dev.749809a
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.
- package/browser/cli-ts-node-commonjs.js +0 -0
- package/browser/cli-ts-node-esm.js +0 -0
- package/browser/data-source/BaseDataSourceOptions.d.ts +4 -0
- package/browser/data-source/BaseDataSourceOptions.js.map +1 -1
- package/browser/data-source/DataSource.d.ts +1 -1
- package/browser/data-source/DataSource.js.map +1 -1
- package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
- package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
- package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/browser/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
- package/browser/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachDriver.js +1 -0
- package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/browser/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
- package/browser/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/browser/driver/expo/ExpoConnectionOptions.d.ts +1 -0
- package/browser/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
- package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/typings.d.ts +2 -0
- package/browser/driver/mysql/MysqlDriver.js +1 -1
- package/browser/driver/mysql/MysqlDriver.js.map +1 -1
- package/browser/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
- package/browser/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/browser/driver/oracle/OracleDriver.js +2 -0
- package/browser/driver/oracle/OracleDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.js +1 -0
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
- package/browser/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/browser/driver/sap/SapConnectionOptions.d.ts +1 -0
- package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
- package/browser/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
- package/browser/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
- package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +2 -0
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/browser/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
- package/browser/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/browser/driver/sqljs/SqljsDriver.d.ts +1 -0
- package/browser/driver/sqljs/SqljsDriver.js +3 -1
- package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js +3 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
- package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/browser/entity-manager/EntityManager.d.ts +20 -20
- package/browser/entity-manager/EntityManager.js.map +1 -1
- package/browser/entity-schema/EntitySchemaColumnOptions.d.ts +4 -0
- package/browser/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaTransformer.js +1 -0
- package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/browser/find-options/FindOptionsUtils.d.ts +2 -1
- package/browser/find-options/FindOptionsUtils.js.map +1 -1
- package/browser/query-builder/DeleteQueryBuilder.d.ts +2 -2
- package/browser/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/browser/query-builder/InsertQueryBuilder.d.ts +2 -2
- package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
- package/browser/query-builder/QueryBuilder.d.ts +3 -3
- package/browser/query-builder/QueryBuilder.js.map +1 -1
- package/browser/query-builder/QueryPartialEntity.d.ts +5 -2
- package/browser/query-builder/QueryPartialEntity.js.map +1 -1
- package/browser/query-builder/RelationIdLoader.js +15 -14
- package/browser/query-builder/RelationIdLoader.js.map +1 -1
- package/browser/query-builder/RelationQueryBuilder.d.ts +2 -1
- package/browser/query-builder/RelationQueryBuilder.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.d.ts +5 -5
- package/browser/query-builder/SelectQueryBuilder.js +1 -1
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/repository/BaseEntity.js.map +1 -1
- package/browser/util/OrmUtils.js +2 -0
- package/browser/util/OrmUtils.js.map +1 -1
- package/cli-ts-node-commonjs.js +0 -0
- package/cli-ts-node-esm.js +0 -0
- package/cli.js +0 -0
- package/commands/InitCommand.js +5 -5
- package/commands/InitCommand.js.map +1 -1
- package/data-source/BaseDataSourceOptions.d.ts +4 -0
- package/data-source/BaseDataSourceOptions.js.map +1 -1
- package/data-source/DataSource.d.ts +1 -1
- package/data-source/DataSource.js.map +1 -1
- package/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
- package/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
- package/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
- package/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/driver/cockroachdb/CockroachDriver.js +1 -0
- package/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
- package/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/driver/expo/ExpoConnectionOptions.d.ts +1 -0
- package/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
- package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/driver/mongodb/typings.d.ts +2 -0
- package/driver/mysql/MysqlDriver.js +1 -1
- package/driver/mysql/MysqlDriver.js.map +1 -1
- package/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
- package/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/driver/oracle/OracleDriver.js +2 -0
- package/driver/oracle/OracleDriver.js.map +1 -1
- package/driver/postgres/PostgresDriver.js +1 -0
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
- package/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/driver/sap/SapConnectionOptions.d.ts +1 -0
- package/driver/sap/SapConnectionOptions.js.map +1 -1
- package/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
- package/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
- package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +2 -0
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
- package/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/driver/sqljs/SqljsDriver.d.ts +1 -0
- package/driver/sqljs/SqljsDriver.js +3 -1
- package/driver/sqljs/SqljsDriver.js.map +1 -1
- package/driver/sqljs/SqljsQueryRunner.js +3 -1
- package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
- package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/entity-manager/EntityManager.d.ts +20 -20
- package/entity-manager/EntityManager.js.map +1 -1
- package/entity-schema/EntitySchemaColumnOptions.d.ts +4 -0
- package/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/entity-schema/EntitySchemaTransformer.js +1 -0
- package/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/find-options/FindOptionsUtils.d.ts +2 -1
- package/find-options/FindOptionsUtils.js.map +1 -1
- package/package.json +1 -274
- package/query-builder/DeleteQueryBuilder.d.ts +2 -2
- package/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/query-builder/InsertQueryBuilder.d.ts +2 -2
- package/query-builder/InsertQueryBuilder.js.map +1 -1
- package/query-builder/QueryBuilder.d.ts +3 -3
- package/query-builder/QueryBuilder.js.map +1 -1
- package/query-builder/QueryPartialEntity.d.ts +5 -2
- package/query-builder/QueryPartialEntity.js.map +1 -1
- package/query-builder/RelationIdLoader.js +15 -14
- package/query-builder/RelationIdLoader.js.map +1 -1
- package/query-builder/RelationQueryBuilder.d.ts +2 -1
- package/query-builder/RelationQueryBuilder.js.map +1 -1
- package/query-builder/SelectQueryBuilder.d.ts +5 -5
- package/query-builder/SelectQueryBuilder.js +1 -1
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/repository/BaseEntity.js.map +1 -1
- package/util/OrmUtils.js +2 -0
- package/util/OrmUtils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACx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QG;IACH,MAAM,CAAC,WAAW,CAEd,EAAqC;QAErC,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAEhB,OAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAElB,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAER,KAAa,EACb,UAAkB;QAElB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const id = baseEntity.getRepository().metadata.getEntityIdMap(this)\n if (!id) {\n throw new Error(\n `Entity doesn't have id-s set, cannot reload entity`,\n )\n }\n const reloadedEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneByOrFail(id)\n\n ObjectUtils.assign(this, reloadedEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object 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 static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\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 present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\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 present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\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 static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository() as Repository<T>\n return thisRepository.preload(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 static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\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 static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\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 static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(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 static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\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 static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove 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 static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(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 static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(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 static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options 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 static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\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 static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(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 static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAuB;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAkB,CAAA;IAC5E,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAqB;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED;;OAE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IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const id = baseEntity.getRepository().metadata.getEntityIdMap(this)\n if (!id) {\n throw new Error(\n `Entity doesn't have id-s set, cannot reload entity`,\n )\n }\n const reloadedEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneByOrFail(id)\n\n ObjectUtils.assign(this, reloadedEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object 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 static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\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 present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\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 present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\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 static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository<T>()\n return thisRepository.preload(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 static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\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 static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\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 static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(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 static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\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 static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove 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 static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(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 static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(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 static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options 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 static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\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 static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(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 static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
|
package/browser/util/OrmUtils.js
CHANGED
|
@@ -105,6 +105,8 @@ export class OrmUtils {
|
|
|
105
105
|
static merge(target, source, memo = new Map()) {
|
|
106
106
|
if (this.isPlainObject(target) && this.isPlainObject(source)) {
|
|
107
107
|
for (const key of Object.keys(source)) {
|
|
108
|
+
if (key === "__proto__")
|
|
109
|
+
continue;
|
|
108
110
|
this.mergeObjectKey(target, key, source[key], memo);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["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AA;aACf;YAED,QAAQ,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBACjB,KAAK,QAAQ,CAAC;gBACd,KAAK,UAAU;oBACX,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;oBACjB,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;oBAElB,IACI,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1D;wBACE,OAAO,KAAK,CAAA;qBACf;oBAED,SAAS,CAAC,GAAG,EAAE,CAAA;oBACf,UAAU,CAAC,GAAG,EAAE,CAAA;oBAChB,MAAK;gBAET;oBACI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;wBACf,OAAO,KAAK,CAAA;qBACf;oBACD,MAAK;aACZ;SACJ;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ","file":"OrmUtils.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\n\nexport class OrmUtils {\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n /**\n * Chunks array into pieces.\n */\n static chunk<T>(array: T[], size: number): T[][] {\n return Array.from(Array(Math.ceil(array.length / size)), (_, i) => {\n return array.slice(i * size, i * size + size)\n })\n }\n\n static splitClassesAndStrings<T>(\n classesAndStrings: (string | T)[],\n ): [T[], string[]] {\n return [\n classesAndStrings.filter(\n (cls): cls is T => typeof cls !== \"string\",\n ),\n classesAndStrings.filter(\n (str): str is string => typeof str === \"string\",\n ),\n ]\n }\n\n static groupBy<T, R>(\n array: T[],\n propertyCallback: (item: T) => R,\n ): { id: R; items: T[] }[] {\n return array.reduce((groupedArray, value) => {\n const key = propertyCallback(value)\n let grouped = groupedArray.find((i) => i.id === key)\n if (!grouped) {\n grouped = { id: key, items: [] }\n groupedArray.push(grouped)\n }\n grouped.items.push(value)\n return groupedArray\n }, [] as Array<{ id: R; items: T[] }>)\n }\n\n static uniq<T>(array: T[], criteria?: (item: T) => any): T[]\n static uniq<T, K extends keyof T>(array: T[], property: K): T[]\n static uniq<T, K extends keyof T>(\n array: T[],\n criteriaOrProperty?: ((item: T) => any) | K,\n ): T[] {\n return array.reduce((uniqueArray, item) => {\n let found: boolean = false\n if (typeof criteriaOrProperty === \"function\") {\n const itemValue = criteriaOrProperty(item)\n found = !!uniqueArray.find(\n (uniqueItem) =>\n criteriaOrProperty(uniqueItem) === itemValue,\n )\n } else if (typeof criteriaOrProperty === \"string\") {\n found = !!uniqueArray.find(\n (uniqueItem) =>\n uniqueItem[criteriaOrProperty] ===\n item[criteriaOrProperty],\n )\n } else {\n found = uniqueArray.indexOf(item) !== -1\n }\n\n if (!found) uniqueArray.push(item)\n\n return uniqueArray\n }, [] as T[])\n }\n\n // Checks if it's an object made by Object.create(null), {} or new Object()\n private static isPlainObject(item: any) {\n if (item === null || item === undefined) {\n return false\n }\n\n return !item.constructor || item.constructor === Object\n }\n\n private static mergeArrayKey(\n target: any,\n key: number,\n value: any,\n memo: Map<any, any>,\n ) {\n // Have we seen this before? Prevent infinite recursion.\n if (memo.has(value)) {\n target[key] = memo.get(value)\n return\n }\n\n if (value instanceof Promise) {\n // Skip promises entirely.\n // This is a hold-over from the old code & is because we don't want to pull in\n // the lazy fields. Ideally we'd remove these promises via another function first\n // but for now we have to do it here.\n return\n }\n\n if (!this.isPlainObject(value) && !Array.isArray(value)) {\n target[key] = value\n return\n }\n\n if (!target[key]) {\n target[key] = Array.isArray(value) ? [] : {}\n }\n\n memo.set(value, target[key])\n this.merge(target[key], value, memo)\n memo.delete(value)\n }\n\n private static mergeObjectKey(\n target: any,\n key: string,\n value: any,\n memo: Map<any, any>,\n ) {\n // Have we seen this before? Prevent infinite recursion.\n if (memo.has(value)) {\n Object.assign(target, { [key]: memo.get(value) })\n return\n }\n\n if (value instanceof Promise) {\n // Skip promises entirely.\n // This is a hold-over from the old code & is because we don't want to pull in\n // the lazy fields. Ideally we'd remove these promises via another function first\n // but for now we have to do it here.\n return\n }\n\n if (!this.isPlainObject(value) && !Array.isArray(value)) {\n Object.assign(target, { [key]: value })\n return\n }\n\n if (!target[key]) {\n Object.assign(target, { [key]: Array.isArray(value) ? [] : {} })\n }\n\n memo.set(value, target[key])\n this.merge(target[key], value, memo)\n memo.delete(value)\n }\n\n private static merge(\n target: any,\n source: any,\n memo: Map<any, any> = new Map(),\n ): any {\n if (this.isPlainObject(target) && this.isPlainObject(source)) {\n for (const key of Object.keys(source)) {\n this.mergeObjectKey(target, key, source[key], memo)\n }\n }\n\n if (Array.isArray(target) && Array.isArray(source)) {\n for (let key = 0; key < source.length; key++) {\n this.mergeArrayKey(target, key, source[key], memo)\n }\n }\n }\n\n /**\n * Deep Object.assign.\n */\n static mergeDeep(target: any, ...sources: any[]): any {\n if (!sources.length) {\n return target\n }\n\n for (const source of sources) {\n OrmUtils.merge(target, source)\n }\n\n return target\n }\n\n /**\n * Deep compare objects.\n *\n * @see http://stackoverflow.com/a/1144249\n */\n static deepCompare(...args: any[]): boolean {\n let i: any, l: any, leftChain: any, rightChain: any\n\n if (arguments.length < 1) {\n return true // Die silently? Don't know how to handle such case, please help...\n // throw \"Need two or more arguments to compare\";\n }\n\n for (i = 1, l = arguments.length; i < l; i++) {\n leftChain = [] // Todo: this can be cached\n rightChain = []\n\n if (\n !this.compare2Objects(\n leftChain,\n rightChain,\n arguments[0],\n arguments[i],\n )\n ) {\n return false\n }\n }\n\n return true\n }\n\n /**\n * Gets deeper value of object.\n */\n static deepValue(obj: ObjectLiteral, path: string) {\n const segments = path.split(\".\")\n for (let i = 0, len = segments.length; i < len; i++) {\n obj = obj[segments[i]]\n }\n return obj\n }\n\n static replaceEmptyObjectsWithBooleans(obj: any) {\n for (let key in obj) {\n if (obj[key] && typeof obj[key] === \"object\") {\n if (Object.keys(obj[key]).length === 0) {\n obj[key] = true\n } else {\n this.replaceEmptyObjectsWithBooleans(obj[key])\n }\n }\n }\n }\n\n static propertyPathsToTruthyObject(paths: string[]) {\n let obj: any = {}\n for (let path of paths) {\n const props = path.split(\".\")\n if (!props.length) continue\n\n if (!obj[props[0]] || obj[props[0]] === true) {\n obj[props[0]] = {}\n }\n let recursiveChild = obj[props[0]]\n for (let [key, prop] of props.entries()) {\n if (key === 0) continue\n\n if (recursiveChild[prop]) {\n recursiveChild = recursiveChild[prop]\n } else if (key === props.length - 1) {\n recursiveChild[prop] = {}\n recursiveChild = null\n } else {\n recursiveChild[prop] = {}\n recursiveChild = recursiveChild[prop]\n }\n }\n }\n this.replaceEmptyObjectsWithBooleans(obj)\n return obj\n }\n\n /**\n * Check if two entity-id-maps are the same\n */\n static compareIds(\n firstId: ObjectLiteral | undefined,\n secondId: ObjectLiteral | undefined,\n ): boolean {\n if (\n firstId === undefined ||\n firstId === null ||\n secondId === undefined ||\n secondId === null\n )\n return false\n\n // Optimized version for the common case\n if (\n ((typeof firstId.id === \"string\" &&\n typeof secondId.id === \"string\") ||\n (typeof firstId.id === \"number\" &&\n typeof secondId.id === \"number\")) &&\n Object.keys(firstId).length === 1 &&\n Object.keys(secondId).length === 1\n ) {\n return firstId.id === secondId.id\n }\n\n return OrmUtils.deepCompare(firstId, secondId)\n }\n\n /**\n * Transforms given value into boolean value.\n */\n static toBoolean(value: any): boolean {\n if (typeof value === \"boolean\") return value\n\n if (typeof value === \"string\") return value === \"true\" || value === \"1\"\n\n if (typeof value === \"number\") return value > 0\n\n return false\n }\n\n /**\n * Composes an object from the given array of keys and values.\n */\n static zipObject(keys: any[], values: any[]): ObjectLiteral {\n return keys.reduce((object, column, index) => {\n object[column] = values[index]\n return object\n }, {} as ObjectLiteral)\n }\n\n /**\n * Compares two arrays.\n */\n static isArraysEqual(arr1: any[], arr2: any[]): boolean {\n if (arr1.length !== arr2.length) return false\n return arr1.every((element) => {\n return arr2.indexOf(element) !== -1\n })\n }\n\n static areMutuallyExclusive<T>(...lists: T[][]): boolean {\n const haveSharedObjects = lists.some((list) => {\n const otherLists = lists.filter((otherList) => otherList !== list)\n return list.some((item) =>\n otherLists.some((otherList) => otherList.includes(item)),\n )\n })\n return !haveSharedObjects\n }\n\n // -------------------------------------------------------------------------\n // Private methods\n // -------------------------------------------------------------------------\n\n private static compare2Objects(\n leftChain: any,\n rightChain: any,\n x: any,\n y: any,\n ) {\n let p\n\n // remember that NaN === NaN returns false\n // and isNaN(undefined) returns true\n if (Number.isNaN(x) && Number.isNaN(y)) return true\n\n // Compare primitives and functions.\n // Check if both arguments link to the same object.\n // Especially useful on the step where we compare prototypes\n if (x === y) return true\n\n // Unequal, but either is null or undefined (use case: jsonb comparison)\n // PR #3776, todo: add tests\n if (x === null || y === null || x === undefined || y === undefined)\n return false\n\n // Fix the buffer compare bug.\n // See: https://github.com/typeorm/typeorm/issues/3654\n if (\n (typeof x.equals === \"function\" ||\n typeof x.equals === \"function\") &&\n x.equals(y)\n )\n return true\n\n // Works in case when functions are created in constructor.\n // Comparing dates is a common scenario. Another built-ins?\n // We can even handle functions passed across iframes\n if (\n (typeof x === \"function\" && typeof y === \"function\") ||\n (x instanceof Date && y instanceof Date) ||\n (x instanceof RegExp && y instanceof RegExp) ||\n (typeof x === \"string\" && typeof y === \"string\") ||\n (typeof x === \"number\" && typeof y === \"number\")\n )\n return x.toString() === y.toString()\n\n // At last checking prototypes as good as we can\n if (!(typeof x === \"object\" && typeof y === \"object\")) return false\n\n if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) return false\n\n if (x.constructor !== y.constructor) return false\n\n if (x.prototype !== y.prototype) return false\n\n // Check for infinitive linking loops\n if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1)\n return false\n\n // Quick checking of one object being a subset of another.\n // todo: cache the structure of arguments[0] for performance\n for (p in y) {\n if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {\n return false\n } else if (typeof y[p] !== typeof x[p]) {\n return false\n }\n }\n\n for (p in x) {\n if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {\n return false\n } else if (typeof y[p] !== typeof x[p]) {\n return false\n }\n\n switch (typeof x[p]) {\n case \"object\":\n case \"function\":\n leftChain.push(x)\n rightChain.push(y)\n\n if (\n !this.compare2Objects(leftChain, rightChain, x[p], y[p])\n ) {\n return false\n }\n\n leftChain.pop()\n rightChain.pop()\n break\n\n default:\n if (x[p] !== y[p]) {\n return false\n }\n break\n }\n }\n\n return true\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/util/OrmUtils.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,QAAQ;IACjB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,KAAK,CAAI,KAAU,EAAE,IAAY;QACpC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC9D,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,sBAAsB,CACzB,iBAAiC;QAEjC,OAAO;YACH,iBAAiB,CAAC,MAAM,CACpB,CAAC,GAAG,EAAY,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAC7C;YACD,iBAAiB,CAAC,MAAM,CACpB,CAAC,GAAG,EAAiB,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAClD;SACJ,CAAA;IACL,CAAC;IAED,MAAM,CAAC,OAAO,CACV,KAAU,EACV,gBAAgC;QAEhC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;YACxC,MAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;YACnC,IAAI,OAAO,GAA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,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBACpC,OAAO,KAAK,CAAA;aACf;SACJ;QAED,KAAK,CAAC,IAAI,CAAC,EAAE;YACT,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;gBAC7C,OAAO,KAAK,CAAA;aACf;iBAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBACpC,OAAO,KAAK,CAAA;aACf;YAED,QAAQ,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBACjB,KAAK,QAAQ,CAAC;gBACd,KAAK,UAAU;oBACX,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;oBACjB,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;oBAElB,IACI,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1D;wBACE,OAAO,KAAK,CAAA;qBACf;oBAED,SAAS,CAAC,GAAG,EAAE,CAAA;oBACf,UAAU,CAAC,GAAG,EAAE,CAAA;oBAChB,MAAK;gBAET;oBACI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;wBACf,OAAO,KAAK,CAAA;qBACf;oBACD,MAAK;aACZ;SACJ;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ","file":"OrmUtils.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\n\nexport class OrmUtils {\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n /**\n * Chunks array into pieces.\n */\n static chunk<T>(array: T[], size: number): T[][] {\n return Array.from(Array(Math.ceil(array.length / size)), (_, i) => {\n return array.slice(i * size, i * size + size)\n })\n }\n\n static splitClassesAndStrings<T>(\n classesAndStrings: (string | T)[],\n ): [T[], string[]] {\n return [\n classesAndStrings.filter(\n (cls): cls is T => typeof cls !== \"string\",\n ),\n classesAndStrings.filter(\n (str): str is string => typeof str === \"string\",\n ),\n ]\n }\n\n static groupBy<T, R>(\n array: T[],\n propertyCallback: (item: T) => R,\n ): { id: R; items: T[] }[] {\n return array.reduce((groupedArray, value) => {\n const key = propertyCallback(value)\n let grouped = groupedArray.find((i) => i.id === key)\n if (!grouped) {\n grouped = { id: key, items: [] }\n groupedArray.push(grouped)\n }\n grouped.items.push(value)\n return groupedArray\n }, [] as Array<{ id: R; items: T[] }>)\n }\n\n static uniq<T>(array: T[], criteria?: (item: T) => any): T[]\n static uniq<T, K extends keyof T>(array: T[], property: K): T[]\n static uniq<T, K extends keyof T>(\n array: T[],\n criteriaOrProperty?: ((item: T) => any) | K,\n ): T[] {\n return array.reduce((uniqueArray, item) => {\n let found: boolean = false\n if (typeof criteriaOrProperty === \"function\") {\n const itemValue = criteriaOrProperty(item)\n found = !!uniqueArray.find(\n (uniqueItem) =>\n criteriaOrProperty(uniqueItem) === itemValue,\n )\n } else if (typeof criteriaOrProperty === \"string\") {\n found = !!uniqueArray.find(\n (uniqueItem) =>\n uniqueItem[criteriaOrProperty] ===\n item[criteriaOrProperty],\n )\n } else {\n found = uniqueArray.indexOf(item) !== -1\n }\n\n if (!found) uniqueArray.push(item)\n\n return uniqueArray\n }, [] as T[])\n }\n\n // Checks if it's an object made by Object.create(null), {} or new Object()\n private static isPlainObject(item: any) {\n if (item === null || item === undefined) {\n return false\n }\n\n return !item.constructor || item.constructor === Object\n }\n\n private static mergeArrayKey(\n target: any,\n key: number,\n value: any,\n memo: Map<any, any>,\n ) {\n // Have we seen this before? Prevent infinite recursion.\n if (memo.has(value)) {\n target[key] = memo.get(value)\n return\n }\n\n if (value instanceof Promise) {\n // Skip promises entirely.\n // This is a hold-over from the old code & is because we don't want to pull in\n // the lazy fields. Ideally we'd remove these promises via another function first\n // but for now we have to do it here.\n return\n }\n\n if (!this.isPlainObject(value) && !Array.isArray(value)) {\n target[key] = value\n return\n }\n\n if (!target[key]) {\n target[key] = Array.isArray(value) ? [] : {}\n }\n\n memo.set(value, target[key])\n this.merge(target[key], value, memo)\n memo.delete(value)\n }\n\n private static mergeObjectKey(\n target: any,\n key: string,\n value: any,\n memo: Map<any, any>,\n ) {\n // Have we seen this before? Prevent infinite recursion.\n if (memo.has(value)) {\n Object.assign(target, { [key]: memo.get(value) })\n return\n }\n\n if (value instanceof Promise) {\n // Skip promises entirely.\n // This is a hold-over from the old code & is because we don't want to pull in\n // the lazy fields. Ideally we'd remove these promises via another function first\n // but for now we have to do it here.\n return\n }\n\n if (!this.isPlainObject(value) && !Array.isArray(value)) {\n Object.assign(target, { [key]: value })\n return\n }\n\n if (!target[key]) {\n Object.assign(target, { [key]: Array.isArray(value) ? [] : {} })\n }\n\n memo.set(value, target[key])\n this.merge(target[key], value, memo)\n memo.delete(value)\n }\n\n private static merge(\n target: any,\n source: any,\n memo: Map<any, any> = new Map(),\n ): any {\n if (this.isPlainObject(target) && this.isPlainObject(source)) {\n for (const key of Object.keys(source)) {\n if (key === \"__proto__\") continue\n this.mergeObjectKey(target, key, source[key], memo)\n }\n }\n\n if (Array.isArray(target) && Array.isArray(source)) {\n for (let key = 0; key < source.length; key++) {\n this.mergeArrayKey(target, key, source[key], memo)\n }\n }\n }\n\n /**\n * Deep Object.assign.\n */\n static mergeDeep(target: any, ...sources: any[]): any {\n if (!sources.length) {\n return target\n }\n\n for (const source of sources) {\n OrmUtils.merge(target, source)\n }\n\n return target\n }\n\n /**\n * Deep compare objects.\n *\n * @see http://stackoverflow.com/a/1144249\n */\n static deepCompare(...args: any[]): boolean {\n let i: any, l: any, leftChain: any, rightChain: any\n\n if (arguments.length < 1) {\n return true // Die silently? Don't know how to handle such case, please help...\n // throw \"Need two or more arguments to compare\";\n }\n\n for (i = 1, l = arguments.length; i < l; i++) {\n leftChain = [] // Todo: this can be cached\n rightChain = []\n\n if (\n !this.compare2Objects(\n leftChain,\n rightChain,\n arguments[0],\n arguments[i],\n )\n ) {\n return false\n }\n }\n\n return true\n }\n\n /**\n * Gets deeper value of object.\n */\n static deepValue(obj: ObjectLiteral, path: string) {\n const segments = path.split(\".\")\n for (let i = 0, len = segments.length; i < len; i++) {\n obj = obj[segments[i]]\n }\n return obj\n }\n\n static replaceEmptyObjectsWithBooleans(obj: any) {\n for (let key in obj) {\n if (obj[key] && typeof obj[key] === \"object\") {\n if (Object.keys(obj[key]).length === 0) {\n obj[key] = true\n } else {\n this.replaceEmptyObjectsWithBooleans(obj[key])\n }\n }\n }\n }\n\n static propertyPathsToTruthyObject(paths: string[]) {\n let obj: any = {}\n for (let path of paths) {\n const props = path.split(\".\")\n if (!props.length) continue\n\n if (!obj[props[0]] || obj[props[0]] === true) {\n obj[props[0]] = {}\n }\n let recursiveChild = obj[props[0]]\n for (let [key, prop] of props.entries()) {\n if (key === 0) continue\n\n if (recursiveChild[prop]) {\n recursiveChild = recursiveChild[prop]\n } else if (key === props.length - 1) {\n recursiveChild[prop] = {}\n recursiveChild = null\n } else {\n recursiveChild[prop] = {}\n recursiveChild = recursiveChild[prop]\n }\n }\n }\n this.replaceEmptyObjectsWithBooleans(obj)\n return obj\n }\n\n /**\n * Check if two entity-id-maps are the same\n */\n static compareIds(\n firstId: ObjectLiteral | undefined,\n secondId: ObjectLiteral | undefined,\n ): boolean {\n if (\n firstId === undefined ||\n firstId === null ||\n secondId === undefined ||\n secondId === null\n )\n return false\n\n // Optimized version for the common case\n if (\n ((typeof firstId.id === \"string\" &&\n typeof secondId.id === \"string\") ||\n (typeof firstId.id === \"number\" &&\n typeof secondId.id === \"number\")) &&\n Object.keys(firstId).length === 1 &&\n Object.keys(secondId).length === 1\n ) {\n return firstId.id === secondId.id\n }\n\n return OrmUtils.deepCompare(firstId, secondId)\n }\n\n /**\n * Transforms given value into boolean value.\n */\n static toBoolean(value: any): boolean {\n if (typeof value === \"boolean\") return value\n\n if (typeof value === \"string\") return value === \"true\" || value === \"1\"\n\n if (typeof value === \"number\") return value > 0\n\n return false\n }\n\n /**\n * Composes an object from the given array of keys and values.\n */\n static zipObject(keys: any[], values: any[]): ObjectLiteral {\n return keys.reduce((object, column, index) => {\n object[column] = values[index]\n return object\n }, {} as ObjectLiteral)\n }\n\n /**\n * Compares two arrays.\n */\n static isArraysEqual(arr1: any[], arr2: any[]): boolean {\n if (arr1.length !== arr2.length) return false\n return arr1.every((element) => {\n return arr2.indexOf(element) !== -1\n })\n }\n\n static areMutuallyExclusive<T>(...lists: T[][]): boolean {\n const haveSharedObjects = lists.some((list) => {\n const otherLists = lists.filter((otherList) => otherList !== list)\n return list.some((item) =>\n otherLists.some((otherList) => otherList.includes(item)),\n )\n })\n return !haveSharedObjects\n }\n\n // -------------------------------------------------------------------------\n // Private methods\n // -------------------------------------------------------------------------\n\n private static compare2Objects(\n leftChain: any,\n rightChain: any,\n x: any,\n y: any,\n ) {\n let p\n\n // remember that NaN === NaN returns false\n // and isNaN(undefined) returns true\n if (Number.isNaN(x) && Number.isNaN(y)) return true\n\n // Compare primitives and functions.\n // Check if both arguments link to the same object.\n // Especially useful on the step where we compare prototypes\n if (x === y) return true\n\n // Unequal, but either is null or undefined (use case: jsonb comparison)\n // PR #3776, todo: add tests\n if (x === null || y === null || x === undefined || y === undefined)\n return false\n\n // Fix the buffer compare bug.\n // See: https://github.com/typeorm/typeorm/issues/3654\n if (\n (typeof x.equals === \"function\" ||\n typeof x.equals === \"function\") &&\n x.equals(y)\n )\n return true\n\n // Works in case when functions are created in constructor.\n // Comparing dates is a common scenario. Another built-ins?\n // We can even handle functions passed across iframes\n if (\n (typeof x === \"function\" && typeof y === \"function\") ||\n (x instanceof Date && y instanceof Date) ||\n (x instanceof RegExp && y instanceof RegExp) ||\n (typeof x === \"string\" && typeof y === \"string\") ||\n (typeof x === \"number\" && typeof y === \"number\")\n )\n return x.toString() === y.toString()\n\n // At last checking prototypes as good as we can\n if (!(typeof x === \"object\" && typeof y === \"object\")) return false\n\n if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) return false\n\n if (x.constructor !== y.constructor) return false\n\n if (x.prototype !== y.prototype) return false\n\n // Check for infinitive linking loops\n if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1)\n return false\n\n // Quick checking of one object being a subset of another.\n // todo: cache the structure of arguments[0] for performance\n for (p in y) {\n if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {\n return false\n } else if (typeof y[p] !== typeof x[p]) {\n return false\n }\n }\n\n for (p in x) {\n if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {\n return false\n } else if (typeof y[p] !== typeof x[p]) {\n return false\n }\n\n switch (typeof x[p]) {\n case \"object\":\n case \"function\":\n leftChain.push(x)\n rightChain.push(y)\n\n if (\n !this.compare2Objects(leftChain, rightChain, x[p], y[p])\n ) {\n return false\n }\n\n leftChain.pop()\n rightChain.pop()\n break\n\n default:\n if (x[p] !== y[p]) {\n return false\n }\n break\n }\n }\n\n return true\n }\n}\n"],"sourceRoot":".."}
|
package/cli-ts-node-commonjs.js
CHANGED
|
File without changes
|
package/cli-ts-node-esm.js
CHANGED
|
File without changes
|
package/cli.js
CHANGED
|
File without changes
|
package/commands/InitCommand.js
CHANGED
|
@@ -434,7 +434,7 @@ AppDataSource.initialize().then(async () => {
|
|
|
434
434
|
services:
|
|
435
435
|
|
|
436
436
|
mysql:
|
|
437
|
-
image: "mysql:
|
|
437
|
+
image: "mysql:8.0.30"
|
|
438
438
|
ports:
|
|
439
439
|
- "3306:3306"
|
|
440
440
|
environment:
|
|
@@ -449,7 +449,7 @@ services:
|
|
|
449
449
|
services:
|
|
450
450
|
|
|
451
451
|
mariadb:
|
|
452
|
-
image: "mariadb:10.
|
|
452
|
+
image: "mariadb:10.8.4"
|
|
453
453
|
ports:
|
|
454
454
|
- "3306:3306"
|
|
455
455
|
environment:
|
|
@@ -464,7 +464,7 @@ services:
|
|
|
464
464
|
services:
|
|
465
465
|
|
|
466
466
|
postgres:
|
|
467
|
-
image: "postgres:
|
|
467
|
+
image: "postgres:14.5"
|
|
468
468
|
ports:
|
|
469
469
|
- "5432:5432"
|
|
470
470
|
environment:
|
|
@@ -478,7 +478,7 @@ services:
|
|
|
478
478
|
services:
|
|
479
479
|
|
|
480
480
|
cockroachdb:
|
|
481
|
-
image: "cockroachdb/cockroach:
|
|
481
|
+
image: "cockroachdb/cockroach:v22.1.6"
|
|
482
482
|
command: start --insecure
|
|
483
483
|
ports:
|
|
484
484
|
- "26257:26257"
|
|
@@ -509,7 +509,7 @@ services:
|
|
|
509
509
|
services:
|
|
510
510
|
|
|
511
511
|
mongodb:
|
|
512
|
-
image: "mongo:
|
|
512
|
+
image: "mongo:5.0.12"
|
|
513
513
|
container_name: "typeorm-mongodb"
|
|
514
514
|
ports:
|
|
515
515
|
- "27017:27017"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAmsB3E,CAAC;IAjsBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IA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,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAAA;gBAC7D,MAAK;SACZ;QAED,IAAI,OAAO,EAAE;YACT,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;YAC/C,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;SACtD;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAxsBD,kCAwsBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^7.3.0\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAmsB3E,CAAC;IAjsBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf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CAAA;gBAC5C,MAAK;YACT,KAAK,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAA;gBAC9C,MAAK;YACT,KAAK,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAAA;gBAC7D,MAAK;SACZ;QAED,IAAI,OAAO,EAAE;YACT,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;YAC/C,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;SACtD;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAxsBD,kCAwsBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:8.0.30\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.8.4\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:14.5\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v22.1.6\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:5.0.12\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^7.3.0\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -68,6 +68,10 @@ export interface BaseDataSourceOptions {
|
|
|
68
68
|
* Maximum number of milliseconds query should be executed before logger log a warning.
|
|
69
69
|
*/
|
|
70
70
|
readonly maxQueryExecutionTime?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum number of clients the pool should contain.
|
|
73
|
+
*/
|
|
74
|
+
readonly poolSize?: number;
|
|
71
75
|
/**
|
|
72
76
|
* Indicates if database schema should be auto created on every application launch.
|
|
73
77
|
* Be careful with this option and don't use this in production - otherwise you can lose production data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/data-source/BaseDataSourceOptions.ts"],"names":[],"mappings":"","file":"BaseDataSourceOptions.js","sourcesContent":["import { EntitySchema } from \"../entity-schema/EntitySchema\"\nimport { LoggerOptions } from \"../logger/LoggerOptions\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { DatabaseType } from \"../driver/types/DatabaseType\"\nimport { Logger } from \"../logger/Logger\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { MixedList } from \"../common/MixedList\"\n\n/**\n * BaseDataSourceOptions is set of DataSourceOptions shared by all database types.\n */\nexport interface BaseDataSourceOptions {\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n *\n * @deprecated\n */\n readonly name?: string\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: MixedList<Function | string | EntitySchema>\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: MixedList<Function | string>\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and glob patterns representing migration files.\n */\n readonly migrations?: MixedList<Function | string>\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\"\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?:\n | \"advanced-console\"\n | \"simple-console\"\n | \"file\"\n | \"debug\"\n | Logger\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any\n\n /**\n * Specifies how relations must be loaded - using \"joins\" or separate queries.\n * If you are loading too much data with nested joins it's better to load relations\n * using separate queries.\n *\n * Default strategy is \"join\", but this default can be changed here.\n * Also, strategy can be set per-query in FindOptions and QueryBuilder.\n */\n readonly relationLoadStrategy?: \"join\" | \"query\"\n\n /**\n * Optionally applied \"typename\" to the model.\n * If set, then each hydrated model will have this property with the target model / entity name inside.\n *\n * (works like a discriminator property).\n */\n readonly typename?: string\n\n /**\n * Holds reference to the baseDirectory where configuration file are expected.\n *\n * @internal\n */\n baseDirectory?: string\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?:\n | boolean\n | {\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?:\n | \"database\"\n | \"redis\"\n | \"ioredis\"\n | \"ioredis/cluster\" // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: DataSource) => QueryResultCache\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/data-source/BaseDataSourceOptions.ts"],"names":[],"mappings":"","file":"BaseDataSourceOptions.js","sourcesContent":["import { EntitySchema } from \"../entity-schema/EntitySchema\"\nimport { LoggerOptions } from \"../logger/LoggerOptions\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { DatabaseType } from \"../driver/types/DatabaseType\"\nimport { Logger } from \"../logger/Logger\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { MixedList } from \"../common/MixedList\"\n\n/**\n * BaseDataSourceOptions is set of DataSourceOptions shared by all database types.\n */\nexport interface BaseDataSourceOptions {\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n *\n * @deprecated\n */\n readonly name?: string\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: MixedList<Function | string | EntitySchema>\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: MixedList<Function | string>\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and glob patterns representing migration files.\n */\n readonly migrations?: MixedList<Function | string>\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\"\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?:\n | \"advanced-console\"\n | \"simple-console\"\n | \"file\"\n | \"debug\"\n | Logger\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number\n\n /**\n * Maximum number of clients the pool should contain.\n */\n readonly poolSize?: number\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any\n\n /**\n * Specifies how relations must be loaded - using \"joins\" or separate queries.\n * If you are loading too much data with nested joins it's better to load relations\n * using separate queries.\n *\n * Default strategy is \"join\", but this default can be changed here.\n * Also, strategy can be set per-query in FindOptions and QueryBuilder.\n */\n readonly relationLoadStrategy?: \"join\" | \"query\"\n\n /**\n * Optionally applied \"typename\" to the model.\n * If set, then each hydrated model will have this property with the target model / entity name inside.\n *\n * (works like a discriminator property).\n */\n readonly typename?: string\n\n /**\n * Holds reference to the baseDirectory where configuration file are expected.\n *\n * @internal\n */\n baseDirectory?: string\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?:\n | boolean\n | {\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?:\n | \"database\"\n | \"redis\"\n | \"ioredis\"\n | \"ioredis/cluster\" // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: DataSource) => QueryResultCache\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -214,7 +214,7 @@ export declare class DataSource {
|
|
|
214
214
|
/**
|
|
215
215
|
* Creates a new query builder that can be used to build a SQL query.
|
|
216
216
|
*/
|
|
217
|
-
createQueryBuilder<Entity>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
|
|
217
|
+
createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
|
|
218
218
|
/**
|
|
219
219
|
* Creates a new query builder that can be used to build a SQL query.
|
|
220
220
|
*/
|