typeorm 0.3.15-dev.f6a3ce7 → 0.3.16-dev.3d67901

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/browser/cache/DbQueryResultCache.d.ts +1 -1
  2. package/browser/cache/DbQueryResultCache.js +1 -1
  3. package/browser/cache/DbQueryResultCache.js.map +1 -1
  4. package/browser/cache/QueryResultCacheOptions.d.ts +2 -2
  5. package/browser/cache/QueryResultCacheOptions.js.map +1 -1
  6. package/browser/cache/RedisQueryResultCache.d.ts +1 -1
  7. package/browser/cache/RedisQueryResultCache.js +1 -1
  8. package/browser/cache/RedisQueryResultCache.js.map +1 -1
  9. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +4 -0
  10. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  11. package/browser/driver/mongodb/MongoDriver.js +1 -0
  12. package/browser/driver/mongodb/MongoDriver.js.map +1 -1
  13. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +6 -10
  14. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  15. package/browser/metadata-builder/RelationJoinColumnBuilder.d.ts +1 -1
  16. package/browser/metadata-builder/RelationJoinColumnBuilder.js +18 -20
  17. package/browser/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
  18. package/browser/persistence/SubjectChangedColumnsComputer.js +2 -1
  19. package/browser/persistence/SubjectChangedColumnsComputer.js.map +1 -1
  20. package/browser/query-builder/SelectQueryBuilder.d.ts +1 -1
  21. package/browser/query-builder/SelectQueryBuilder.js +3 -2
  22. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  23. package/browser/schema-builder/RdbmsSchemaBuilder.js +1 -1
  24. package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  25. package/cache/DbQueryResultCache.d.ts +1 -1
  26. package/cache/DbQueryResultCache.js +1 -1
  27. package/cache/DbQueryResultCache.js.map +1 -1
  28. package/cache/QueryResultCacheOptions.d.ts +2 -2
  29. package/cache/QueryResultCacheOptions.js.map +1 -1
  30. package/cache/RedisQueryResultCache.d.ts +1 -1
  31. package/cache/RedisQueryResultCache.js +1 -1
  32. package/cache/RedisQueryResultCache.js.map +1 -1
  33. package/driver/mongodb/MongoConnectionOptions.d.ts +4 -0
  34. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  35. package/driver/mongodb/MongoDriver.js +1 -0
  36. package/driver/mongodb/MongoDriver.js.map +1 -1
  37. package/driver/sqlite-abstract/AbstractSqliteDriver.js +6 -10
  38. package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  39. package/metadata-builder/RelationJoinColumnBuilder.d.ts +1 -1
  40. package/metadata-builder/RelationJoinColumnBuilder.js +18 -20
  41. package/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
  42. package/package.json +1 -1
  43. package/persistence/SubjectChangedColumnsComputer.js +2 -1
  44. package/persistence/SubjectChangedColumnsComputer.js.map +1 -1
  45. package/query-builder/SelectQueryBuilder.d.ts +1 -1
  46. package/query-builder/SelectQueryBuilder.js +3 -2
  47. package/query-builder/SelectQueryBuilder.js.map +1 -1
  48. package/schema-builder/RdbmsSchemaBuilder.js +1 -1
  49. package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
@@ -24,7 +24,7 @@ export declare class DbQueryResultCache implements QueryResultCache {
24
24
  */
25
25
  synchronize(queryRunner?: QueryRunner): Promise<void>;
26
26
  /**
27
- * Caches given query result.
27
+ * Get data from cache.
28
28
  * Returns cache result if found.
29
29
  * Returns undefined if result is not cached.
30
30
  */
@@ -99,7 +99,7 @@ export class DbQueryResultCache {
99
99
  }));
100
100
  }
101
101
  /**
102
- * Caches given query result.
102
+ * Get data from cache.
103
103
  * Returns cache result if found.
104
104
  * Returns undefined if result is not cached.
105
105
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/cache/DbQueryResultCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,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AC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACpD,OAAO,EAAE;iBACJ,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC;iBAChC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;gBAC/C,UAAU;aACb,CAAC;iBACD,OAAO,EAAE,CAAA;QAClB,CAAC,CAAC,CACL,CAAA;QAED,IAAI,CAAC,WAAW,EAAE;YACd,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;SAC/B;IACL,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACO,cAAc,CAAC,WAAyB;QAC9C,IAAI,WAAW;YAAE,OAAO,WAAW,CAAA;QAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;IAC9C,CAAC;CACJ","file":"DbQueryResultCache.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { v4 as uuidv4 } from \"uuid\"\n\n/**\n * Caches query result into current database, into separate table called \"query-result-cache\".\n */\nexport class DbQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Private properties\n // -------------------------------------------------------------------------\n\n private queryResultCacheTable: string\n\n private queryResultCacheDatabase?: string\n\n private queryResultCacheSchema?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {\n const { schema } = this.connection.driver.options as any\n const database = this.connection.driver.database\n const cacheOptions =\n typeof this.connection.options.cache === \"object\"\n ? this.connection.options.cache\n : {}\n const cacheTableName = cacheOptions.tableName || \"query-result-cache\"\n\n this.queryResultCacheDatabase = database\n this.queryResultCacheSchema = schema\n this.queryResultCacheTable = this.connection.driver.buildTableName(\n cacheTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {}\n\n /**\n * Disconnects with given cache provider.\n */\n async disconnect(): Promise<void> {}\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner?: QueryRunner): Promise<void> {\n queryRunner = this.getQueryRunner(queryRunner)\n const driver = this.connection.driver\n const tableExist = await queryRunner.hasTable(\n this.queryResultCacheTable,\n ) // todo: table name should be configurable\n if (tableExist) return\n\n await queryRunner.createTable(\n new Table({\n database: this.queryResultCacheDatabase,\n schema: this.queryResultCacheSchema,\n name: this.queryResultCacheTable,\n columns: [\n {\n name: \"id\",\n isPrimary: true,\n isNullable: false,\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheId,\n }),\n generationStrategy:\n driver.options.type === \"spanner\"\n ? \"uuid\"\n : \"increment\",\n isGenerated: true,\n },\n {\n name: \"identifier\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheIdentifier,\n }),\n isNullable: true,\n },\n {\n name: \"time\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheTime,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"duration\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheDuration,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"query\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheQuery,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"result\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheResult,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n\n /**\n * Caches given query result.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n queryRunner = this.getQueryRunner(queryRunner)\n const qb = this.connection\n .createQueryBuilder(queryRunner)\n .select()\n .from(this.queryResultCacheTable, \"cache\")\n\n if (options.identifier) {\n return qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\n \"identifier\",\n )} = :identifier`,\n )\n .setParameters({\n identifier:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.identifier, \"nvarchar\")\n : options.identifier,\n })\n .getRawOne()\n } else if (options.query) {\n if (this.connection.driver.options.type === \"oracle\") {\n return qb\n .where(\n `dbms_lob.compare(${qb.escape(\"cache\")}.${qb.escape(\n \"query\",\n )}, :query) = 0`,\n { query: options.query },\n )\n .getRawOne()\n }\n\n return qb\n .where(`${qb.escape(\"cache\")}.${qb.escape(\"query\")} = :query`)\n .setParameters({\n query:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.query, \"nvarchar\")\n : options.query,\n })\n .getRawOne()\n }\n\n return Promise.resolve(undefined)\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n const duration =\n typeof savedCache.duration === \"string\"\n ? parseInt(savedCache.duration)\n : savedCache.duration\n return (\n (typeof savedCache.time === \"string\"\n ? parseInt(savedCache.time as any)\n : savedCache.time)! +\n duration <\n new Date().getTime()\n )\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const shouldCreateQueryRunner =\n queryRunner === undefined ||\n queryRunner?.getReplicationMode() === \"slave\"\n\n if (queryRunner === undefined || shouldCreateQueryRunner) {\n queryRunner = this.connection.createQueryRunner(\"master\")\n }\n\n let insertedValues: ObjectLiteral = options\n if (this.connection.driver.options.type === \"mssql\") {\n // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table\n insertedValues = {\n identifier: new MssqlParameter(options.identifier, \"nvarchar\"),\n time: new MssqlParameter(options.time, \"bigint\"),\n duration: new MssqlParameter(options.duration, \"int\"),\n query: new MssqlParameter(options.query, \"nvarchar\"),\n result: new MssqlParameter(options.result, \"nvarchar\"),\n }\n }\n\n if (savedCache && savedCache.identifier) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n qb.where(`${qb.escape(\"identifier\")} = :condition`, {\n condition: insertedValues.identifier,\n })\n await qb.execute()\n } else if (savedCache && savedCache.query) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n if (this.connection.driver.options.type === \"oracle\") {\n qb.where(`dbms_lob.compare(\"query\", :condition) = 0`, {\n condition: insertedValues.query,\n })\n } else {\n qb.where(`${qb.escape(\"query\")} = :condition`, {\n condition: insertedValues.query,\n })\n }\n\n await qb.execute()\n } else {\n // Spanner does not support auto-generated columns\n if (\n this.connection.driver.options.type === \"spanner\" &&\n !insertedValues.id\n ) {\n insertedValues.id = uuidv4()\n }\n\n // otherwise insert\n await queryRunner.manager\n .createQueryBuilder()\n .insert()\n .into(this.queryResultCacheTable)\n .values(insertedValues)\n .execute()\n }\n\n if (shouldCreateQueryRunner) {\n await queryRunner.release()\n }\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner: QueryRunner): Promise<void> {\n return this.getQueryRunner(queryRunner).clearTable(\n this.queryResultCacheTable,\n )\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n let _queryRunner: QueryRunner = queryRunner || this.getQueryRunner()\n await Promise.all(\n identifiers.map((identifier) => {\n const qb = _queryRunner.manager.createQueryBuilder()\n return qb\n .delete()\n .from(this.queryResultCacheTable)\n .where(`${qb.escape(\"identifier\")} = :identifier`, {\n identifier,\n })\n .execute()\n }),\n )\n\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a query runner to work with.\n */\n protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner {\n if (queryRunner) return queryRunner\n\n return this.connection.createQueryRunner()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/cache/DbQueryResultCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAGrD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAW3B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,CAAA;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAA;QAChD,MAAM,YAAY,GACd,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC7C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK;YAC/B,CAAC,CAAC,EAAE,CAAA;QACZ,MAAM,cAAc,GAAG,YAAY,CAAC,SAAS,IAAI,oBAAoB,CAAA;QAErE,IAAI,CAAC,wBAAwB,GAAG,QAAQ,CAAA;QACxC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAA;QACpC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CA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AE,CAAA;SACjB;QAED,IAAI,uBAAuB,EAAE;YACzB,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;SAC9B;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,WAAwB;QAChC,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,UAAU,CAC9C,IAAI,CAAC,qBAAqB,CAC7B,CAAA;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,WAAqB,EACrB,WAAyB;QAEzB,IAAI,YAAY,GAAgB,WAAW,IAAI,IAAI,CAAC,cAAc,EAAE,CAAA;QACpE,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACpD,OAAO,EAAE;iBACJ,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC;iBAChC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;gBAC/C,UAAU;aACb,CAAC;iBACD,OAAO,EAAE,CAAA;QAClB,CAAC,CAAC,CACL,CAAA;QAED,IAAI,CAAC,WAAW,EAAE;YACd,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;SAC/B;IACL,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACO,cAAc,CAAC,WAAyB;QAC9C,IAAI,WAAW;YAAE,OAAO,WAAW,CAAA;QAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;IAC9C,CAAC;CACJ","file":"DbQueryResultCache.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { v4 as uuidv4 } from \"uuid\"\n\n/**\n * Caches query result into current database, into separate table called \"query-result-cache\".\n */\nexport class DbQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Private properties\n // -------------------------------------------------------------------------\n\n private queryResultCacheTable: string\n\n private queryResultCacheDatabase?: string\n\n private queryResultCacheSchema?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {\n const { schema } = this.connection.driver.options as any\n const database = this.connection.driver.database\n const cacheOptions =\n typeof this.connection.options.cache === \"object\"\n ? this.connection.options.cache\n : {}\n const cacheTableName = cacheOptions.tableName || \"query-result-cache\"\n\n this.queryResultCacheDatabase = database\n this.queryResultCacheSchema = schema\n this.queryResultCacheTable = this.connection.driver.buildTableName(\n cacheTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {}\n\n /**\n * Disconnects with given cache provider.\n */\n async disconnect(): Promise<void> {}\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner?: QueryRunner): Promise<void> {\n queryRunner = this.getQueryRunner(queryRunner)\n const driver = this.connection.driver\n const tableExist = await queryRunner.hasTable(\n this.queryResultCacheTable,\n ) // todo: table name should be configurable\n if (tableExist) return\n\n await queryRunner.createTable(\n new Table({\n database: this.queryResultCacheDatabase,\n schema: this.queryResultCacheSchema,\n name: this.queryResultCacheTable,\n columns: [\n {\n name: \"id\",\n isPrimary: true,\n isNullable: false,\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheId,\n }),\n generationStrategy:\n driver.options.type === \"spanner\"\n ? \"uuid\"\n : \"increment\",\n isGenerated: true,\n },\n {\n name: \"identifier\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheIdentifier,\n }),\n isNullable: true,\n },\n {\n name: \"time\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheTime,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"duration\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheDuration,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"query\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheQuery,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"result\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheResult,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n queryRunner = this.getQueryRunner(queryRunner)\n const qb = this.connection\n .createQueryBuilder(queryRunner)\n .select()\n .from(this.queryResultCacheTable, \"cache\")\n\n if (options.identifier) {\n return qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\n \"identifier\",\n )} = :identifier`,\n )\n .setParameters({\n identifier:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.identifier, \"nvarchar\")\n : options.identifier,\n })\n .getRawOne()\n } else if (options.query) {\n if (this.connection.driver.options.type === \"oracle\") {\n return qb\n .where(\n `dbms_lob.compare(${qb.escape(\"cache\")}.${qb.escape(\n \"query\",\n )}, :query) = 0`,\n { query: options.query },\n )\n .getRawOne()\n }\n\n return qb\n .where(`${qb.escape(\"cache\")}.${qb.escape(\"query\")} = :query`)\n .setParameters({\n query:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.query, \"nvarchar\")\n : options.query,\n })\n .getRawOne()\n }\n\n return Promise.resolve(undefined)\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n const duration =\n typeof savedCache.duration === \"string\"\n ? parseInt(savedCache.duration)\n : savedCache.duration\n return (\n (typeof savedCache.time === \"string\"\n ? parseInt(savedCache.time as any)\n : savedCache.time)! +\n duration <\n new Date().getTime()\n )\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const shouldCreateQueryRunner =\n queryRunner === undefined ||\n queryRunner?.getReplicationMode() === \"slave\"\n\n if (queryRunner === undefined || shouldCreateQueryRunner) {\n queryRunner = this.connection.createQueryRunner(\"master\")\n }\n\n let insertedValues: ObjectLiteral = options\n if (this.connection.driver.options.type === \"mssql\") {\n // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table\n insertedValues = {\n identifier: new MssqlParameter(options.identifier, \"nvarchar\"),\n time: new MssqlParameter(options.time, \"bigint\"),\n duration: new MssqlParameter(options.duration, \"int\"),\n query: new MssqlParameter(options.query, \"nvarchar\"),\n result: new MssqlParameter(options.result, \"nvarchar\"),\n }\n }\n\n if (savedCache && savedCache.identifier) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n qb.where(`${qb.escape(\"identifier\")} = :condition`, {\n condition: insertedValues.identifier,\n })\n await qb.execute()\n } else if (savedCache && savedCache.query) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n if (this.connection.driver.options.type === \"oracle\") {\n qb.where(`dbms_lob.compare(\"query\", :condition) = 0`, {\n condition: insertedValues.query,\n })\n } else {\n qb.where(`${qb.escape(\"query\")} = :condition`, {\n condition: insertedValues.query,\n })\n }\n\n await qb.execute()\n } else {\n // Spanner does not support auto-generated columns\n if (\n this.connection.driver.options.type === \"spanner\" &&\n !insertedValues.id\n ) {\n insertedValues.id = uuidv4()\n }\n\n // otherwise insert\n await queryRunner.manager\n .createQueryBuilder()\n .insert()\n .into(this.queryResultCacheTable)\n .values(insertedValues)\n .execute()\n }\n\n if (shouldCreateQueryRunner) {\n await queryRunner.release()\n }\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner: QueryRunner): Promise<void> {\n return this.getQueryRunner(queryRunner).clearTable(\n this.queryResultCacheTable,\n )\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n let _queryRunner: QueryRunner = queryRunner || this.getQueryRunner()\n await Promise.all(\n identifiers.map((identifier) => {\n const qb = _queryRunner.manager.createQueryBuilder()\n return qb\n .delete()\n .from(this.queryResultCacheTable)\n .where(`${qb.escape(\"identifier\")} = :identifier`, {\n identifier,\n })\n .execute()\n }),\n )\n\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a query runner to work with.\n */\n protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner {\n if (queryRunner) return queryRunner\n\n return this.connection.createQueryRunner()\n }\n}\n"],"sourceRoot":".."}
@@ -6,7 +6,7 @@ export interface QueryResultCacheOptions {
6
6
  * Cache identifier set by user.
7
7
  * Can be empty.
8
8
  */
9
- identifier: string;
9
+ identifier?: string;
10
10
  /**
11
11
  * Time, when cache was created.
12
12
  */
@@ -18,7 +18,7 @@ export interface QueryResultCacheOptions {
18
18
  /**
19
19
  * Cached query.
20
20
  */
21
- query: string;
21
+ query?: string;
22
22
  /**
23
23
  * Query result that will be cached.
24
24
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/cache/QueryResultCacheOptions.ts"],"names":[],"mappings":"","file":"QueryResultCacheOptions.js","sourcesContent":["/**\n * Options passed to QueryResultCache class.\n */\nexport interface QueryResultCacheOptions {\n /**\n * Cache identifier set by user.\n * Can be empty.\n */\n identifier: string\n\n /**\n * Time, when cache was created.\n */\n time?: number\n\n /**\n * Duration in milliseconds during which results will be returned from cache.\n */\n duration: number\n\n /**\n * Cached query.\n */\n query: string\n\n /**\n * Query result that will be cached.\n */\n result?: any\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/cache/QueryResultCacheOptions.ts"],"names":[],"mappings":"","file":"QueryResultCacheOptions.js","sourcesContent":["/**\n * Options passed to QueryResultCache class.\n */\nexport interface QueryResultCacheOptions {\n /**\n * Cache identifier set by user.\n * Can be empty.\n */\n identifier?: string\n\n /**\n * Time, when cache was created.\n */\n time?: number\n\n /**\n * Duration in milliseconds during which results will be returned from cache.\n */\n duration: number\n\n /**\n * Cached query.\n */\n query?: string\n\n /**\n * Query result that will be cached.\n */\n result?: any\n}\n"],"sourceRoot":".."}
@@ -33,7 +33,7 @@ export declare class RedisQueryResultCache implements QueryResultCache {
33
33
  */
34
34
  synchronize(queryRunner: QueryRunner): Promise<void>;
35
35
  /**
36
- * Caches given query result.
36
+ * Get data from cache.
37
37
  * Returns cache result if found.
38
38
  * Returns undefined if result is not cached.
39
39
  */
@@ -85,7 +85,7 @@ export class RedisQueryResultCache {
85
85
  */
86
86
  async synchronize(queryRunner) { }
87
87
  /**
88
- * Caches given query result.
88
+ * Get data from cache.
89
89
  * Returns cache result if found.
90
90
  * Returns undefined if result is not cached.
91
91
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/cache/RedisQueryResultCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAoB9B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EAChC,UAAmD;QADzC,eAAU,GAAV,UAAU,CAAY;QAGhC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAA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EAA4E;IAE5E;;OAEG;IACO,SAAS,CAAC,GAAW;QAC3B,OAAO,IAAI,OAAO,CAAO,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAQ,EAAE,MAAW,EAAE,EAAE;gBAC3C,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;gBACzB,EAAE,EAAE,CAAA;YACR,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC;IAED;;OAEG;IACO,SAAS;QACf,IAAI;YACA,IAAI,IAAI,CAAC,UAAU,KAAK,iBAAiB,EAAE;gBACvC,OAAO,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;aACvC;iBAAM;gBACH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;aAC7C;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,YAAY,CAClB,4BAA4B,IAAI,CAAC,UAAU,wCAAwC,IAAI,CAAC,UAAU,WAAW,CAChH,CAAA;SACJ;IACL,CAAC;CACJ","file":"RedisQueryResultCache.js","sourcesContent":["import { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { TypeORMError } from \"../error/TypeORMError\"\n\n/**\n * Caches query result into Redis database.\n */\nexport class RedisQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Redis module instance loaded dynamically.\n */\n protected redis: any\n\n /**\n * Connected redis client.\n */\n protected client: any\n\n /**\n * Type of the Redis Client (redis or ioredis).\n */\n protected clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\"\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected connection: DataSource,\n clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\",\n ) {\n this.clientType = clientType\n this.redis = this.loadRedis()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {\n const cacheOptions: any = this.connection.options.cache\n if (this.clientType === \"redis\") {\n this.client = this.redis.createClient({\n ...cacheOptions?.options,\n legacyMode: true,\n })\n if (\n typeof this.connection.options.cache === \"object\" &&\n this.connection.options.cache.ignoreErrors\n ) {\n this.client.on(\"error\", (err: any) => {\n this.connection.logger.log(\"warn\", err)\n })\n }\n if (\"connect\" in this.client) {\n await this.client.connect()\n }\n } else if (this.clientType === \"ioredis\") {\n if (cacheOptions && cacheOptions.port) {\n if (cacheOptions.options) {\n this.client = new this.redis(\n cacheOptions.port,\n cacheOptions.options,\n )\n } else {\n this.client = new this.redis(cacheOptions.port)\n }\n } else if (cacheOptions && cacheOptions.options) {\n this.client = new this.redis(cacheOptions.options)\n } else {\n this.client = new this.redis()\n }\n } else if (this.clientType === \"ioredis/cluster\") {\n if (\n cacheOptions &&\n cacheOptions.options &&\n Array.isArray(cacheOptions.options)\n ) {\n this.client = new this.redis.Cluster(cacheOptions.options)\n } else if (\n cacheOptions &&\n cacheOptions.options &&\n cacheOptions.options.startupNodes\n ) {\n this.client = new this.redis.Cluster(\n cacheOptions.options.startupNodes,\n cacheOptions.options.options,\n )\n } else {\n throw new TypeORMError(\n `options.startupNodes required for ${this.clientType}.`,\n )\n }\n }\n }\n\n /**\n * Disconnects the connection\n */\n async disconnect(): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.quit((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n this.client = undefined\n })\n })\n }\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner: QueryRunner): Promise<void> {}\n\n /**\n * Caches given query result.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n return new Promise<QueryResultCacheOptions | undefined>((ok, fail) => {\n if (options.identifier) {\n this.client.get(options.identifier, (err: any, result: any) => {\n if (err) return fail(err)\n ok(JSON.parse(result))\n })\n } else if (options.query) {\n this.client.get(options.query, (err: any, result: any) => {\n if (err) return fail(err)\n ok(JSON.parse(result))\n })\n } else {\n ok(undefined)\n }\n })\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n return savedCache.time! + savedCache.duration < new Date().getTime()\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n return new Promise<void>((ok, fail) => {\n if (options.identifier) {\n this.client.set(\n options.identifier,\n JSON.stringify(options),\n \"PX\",\n options.duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n } else if (options.query) {\n this.client.set(\n options.query,\n JSON.stringify(options),\n \"PX\",\n options.duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n }\n })\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner?: QueryRunner): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.flushdb((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n await Promise.all(\n identifiers.map((identifier) => {\n return this.deleteKey(identifier)\n }),\n )\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Removes a single key from redis database.\n */\n protected deleteKey(key: string): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.del(key, (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Loads redis dependency.\n */\n protected loadRedis(): any {\n try {\n if (this.clientType === \"ioredis/cluster\") {\n return PlatformTools.load(\"ioredis\")\n } else {\n return PlatformTools.load(this.clientType)\n }\n } catch (e) {\n throw new TypeORMError(\n `Cannot use cache because ${this.clientType} is not installed. Please run \"npm i ${this.clientType} --save\".`,\n )\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/cache/RedisQueryResultCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAoB9B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EAChC,UAAmD;QADzC,eAAU,GAAV,UAAU,CAAY;QAGhC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;IACjC,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,OAAO;QACT,MAAM,YAAY,GAAQ,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAA;QACvD,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO,EAAE;YAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;gBAClC,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO;gBACxB,UAAU,EAAE,IAAI;aACnB,CAAC,CAAA;YACF,IACI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;gBACjD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,EAC5C;gBACE,IAAI,CAAC,MAAM,CA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C7C;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,YAAY,CAClB,4BAA4B,IAAI,CAAC,UAAU,wCAAwC,IAAI,CAAC,UAAU,WAAW,CAChH,CAAA;SACJ;IACL,CAAC;CACJ","file":"RedisQueryResultCache.js","sourcesContent":["import { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { TypeORMError } from \"../error/TypeORMError\"\n\n/**\n * Caches query result into Redis database.\n */\nexport class RedisQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Redis module instance loaded dynamically.\n */\n protected redis: any\n\n /**\n * Connected redis client.\n */\n protected client: any\n\n /**\n * Type of the Redis Client (redis or ioredis).\n */\n protected clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\"\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected connection: DataSource,\n clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\",\n ) {\n this.clientType = clientType\n this.redis = this.loadRedis()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {\n const cacheOptions: any = this.connection.options.cache\n if (this.clientType === \"redis\") {\n this.client = this.redis.createClient({\n ...cacheOptions?.options,\n legacyMode: true,\n })\n if (\n typeof this.connection.options.cache === \"object\" &&\n this.connection.options.cache.ignoreErrors\n ) {\n this.client.on(\"error\", (err: any) => {\n this.connection.logger.log(\"warn\", err)\n })\n }\n if (\"connect\" in this.client) {\n await this.client.connect()\n }\n } else if (this.clientType === \"ioredis\") {\n if (cacheOptions && cacheOptions.port) {\n if (cacheOptions.options) {\n this.client = new this.redis(\n cacheOptions.port,\n cacheOptions.options,\n )\n } else {\n this.client = new this.redis(cacheOptions.port)\n }\n } else if (cacheOptions && cacheOptions.options) {\n this.client = new this.redis(cacheOptions.options)\n } else {\n this.client = new this.redis()\n }\n } else if (this.clientType === \"ioredis/cluster\") {\n if (\n cacheOptions &&\n cacheOptions.options &&\n Array.isArray(cacheOptions.options)\n ) {\n this.client = new this.redis.Cluster(cacheOptions.options)\n } else if (\n cacheOptions &&\n cacheOptions.options &&\n cacheOptions.options.startupNodes\n ) {\n this.client = new this.redis.Cluster(\n cacheOptions.options.startupNodes,\n cacheOptions.options.options,\n )\n } else {\n throw new TypeORMError(\n `options.startupNodes required for ${this.clientType}.`,\n )\n }\n }\n }\n\n /**\n * Disconnects the connection\n */\n async disconnect(): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.quit((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n this.client = undefined\n })\n })\n }\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner: QueryRunner): Promise<void> {}\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n return new Promise<QueryResultCacheOptions | undefined>((ok, fail) => {\n if (options.identifier) {\n this.client.get(options.identifier, (err: any, result: any) => {\n if (err) return fail(err)\n ok(JSON.parse(result))\n })\n } else if (options.query) {\n this.client.get(options.query, (err: any, result: any) => {\n if (err) return fail(err)\n ok(JSON.parse(result))\n })\n } else {\n ok(undefined)\n }\n })\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n return savedCache.time! + savedCache.duration < new Date().getTime()\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n return new Promise<void>((ok, fail) => {\n if (options.identifier) {\n this.client.set(\n options.identifier,\n JSON.stringify(options),\n \"PX\",\n options.duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n } else if (options.query) {\n this.client.set(\n options.query,\n JSON.stringify(options),\n \"PX\",\n options.duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n }\n })\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner?: QueryRunner): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.flushdb((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n await Promise.all(\n identifiers.map((identifier) => {\n return this.deleteKey(identifier)\n }),\n )\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Removes a single key from redis database.\n */\n protected deleteKey(key: string): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.del(key, (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Loads redis dependency.\n */\n protected loadRedis(): any {\n try {\n if (this.clientType === \"ioredis/cluster\") {\n return PlatformTools.load(\"ioredis\")\n } else {\n return PlatformTools.load(this.clientType)\n }\n } catch (e) {\n throw new TypeORMError(\n `Cannot use cache because ${this.clientType} is not installed. Please run \"npm i ${this.clientType} --save\".`,\n )\n }\n }\n}\n"],"sourceRoot":".."}
@@ -38,6 +38,10 @@ export interface MongoConnectionOptions extends BaseDataSourceOptions {
38
38
  * Database name to connect to.
39
39
  */
40
40
  readonly database?: string;
41
+ /**
42
+ * Specifies whether to force dispatch all operations to the specified host. Default: false
43
+ */
44
+ readonly directConnection?: boolean;
41
45
  /**
42
46
  * The driver object
43
47
  * This defaults to require("mongodb")
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/mongodb/MongoConnectionOptions.ts"],"names":[],"mappings":"","file":"MongoConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { ReadPreference } from \"./typings\"\n\n/**\n * MongoDB specific connection options.\n * Synced with http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html\n */\nexport interface MongoConnectionOptions extends BaseDataSourceOptions {\n /**\n * Database type.\n */\n readonly type: \"mongodb\"\n\n /**\n * Connection url where perform connection to.\n */\n readonly url?: string\n\n /**\n * Database host.\n */\n readonly host?: string\n\n /**\n * Database host replica set.\n */\n readonly hostReplicaSet?: string\n\n /**\n * Database host port.\n */\n readonly port?: number\n\n /**\n * Database username.\n */\n readonly username?: string\n\n /**\n * Database password.\n */\n readonly password?: string\n\n /**\n * Database name to connect to.\n */\n readonly database?: string\n\n /**\n * The driver object\n * This defaults to require(\"mongodb\")\n */\n readonly driver?: any\n\n /**\n * Use ssl connection (needs to have a mongod server with ssl support). Default: false\n */\n readonly ssl?: boolean\n\n /**\n * Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).\n * Default: true\n */\n readonly sslValidate?: boolean\n\n /**\n * Array of valid certificates either as Buffers or Strings\n * (needs to have a mongod server with ssl support, 2.4 or higher).\n */\n readonly sslCA?: string | Buffer\n\n /**\n * String or buffer containing the certificate we wish to present\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslCert?: string | Buffer\n\n /**\n * String or buffer containing the certificate private key we wish to present\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslKey?: string\n\n /**\n * String or buffer containing the certificate password\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslPass?: string | Buffer\n\n /**\n * SSL Certificate revocation list binary buffer\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslCRL?: string | Buffer\n\n /**\n * Reconnect on error. Default: true\n */\n readonly autoReconnect?: boolean\n\n /**\n * TCP Socket NoDelay option. Default: true\n */\n readonly noDelay?: boolean\n\n /**\n * The number of milliseconds to wait before initiating keepAlive on the TCP socket. Default: 30000\n */\n readonly keepAlive?: number\n\n /**\n * TCP Connection timeout setting. Default: 30000\n */\n readonly connectTimeoutMS?: number\n\n /**\n * Version of IP stack. Can be 4, 6.\n * If undefined, will attempt to connect with IPv6, and will fall back to IPv4 on failure\n */\n readonly family?: number\n\n /**\n * TCP Socket timeout setting. Default: 360000\n */\n readonly socketTimeoutMS?: number\n\n /**\n * Server attempt to reconnect #times. Default 30\n */\n readonly reconnectTries?: number\n\n /**\n * Server will wait #milliseconds between retries. Default 1000\n */\n readonly reconnectInterval?: number\n\n /**\n * Control if high availability monitoring runs for Replicaset or Mongos proxies. Default true\n */\n readonly ha?: boolean\n\n /**\n * The High availability period for replicaset inquiry. Default: 10000\n */\n readonly haInterval?: number\n\n /**\n * The name of the replicaset to connect to\n */\n readonly replicaSet?: string\n\n /**\n * Sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms).\n * Default: 15\n */\n readonly acceptableLatencyMS?: number\n\n /**\n * Sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms).\n * Default: 15\n */\n readonly secondaryAcceptableLatencyMS?: number\n\n /**\n * Sets if the driver should connect even if no primary is available. Default: false\n */\n readonly connectWithNoPrimary?: boolean\n\n /**\n * If the database authentication is dependent on another databaseName.\n */\n readonly authSource?: string\n\n /**\n * The write concern.\n */\n readonly w?: string | number\n\n /**\n * The write concern timeout value.\n */\n readonly wtimeout?: number\n\n /**\n * Specify a journal write concern. Default: false\n */\n readonly j?: boolean\n\n /**\n * Force server to assign _id values instead of driver. Default: false\n */\n readonly forceServerObjectId?: boolean\n\n /**\n * Serialize functions on any object. Default: false\n */\n readonly serializeFunctions?: boolean\n\n /**\n * Specify if the BSON serializer should ignore undefined fields. Default: false\n */\n readonly ignoreUndefined?: boolean\n\n /**\n * Return document results as raw BSON buffers. Default: false\n */\n readonly raw?: boolean\n\n /**\n * Promotes Long values to number if they fit inside the 53 bits resolution. Default: true\n */\n readonly promoteLongs?: boolean\n\n /**\n * Promotes Binary BSON values to native Node Buffers. Default: false\n */\n readonly promoteBuffers?: boolean\n\n /**\n * Promotes BSON values to native types where possible, set to false to only receive wrapper types. Default: true\n */\n readonly promoteValues?: boolean\n\n /**\n * Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit. Default: false\n */\n readonly domainsEnabled?: boolean\n\n /**\n * Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection,\n * default is -1 which is unlimited.\n */\n readonly bufferMaxEntries?: number\n\n /**\n * The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY,\n * ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).\n */\n readonly readPreference?: ReadPreference | string\n\n /**\n * A primary key factory object for generation of custom _id keys.\n */\n readonly pkFactory?: any\n\n /**\n * A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible.\n */\n readonly promiseLibrary?: any\n\n /**\n * Specify a read concern for the collection. (only MongoDB 3.2 or higher supported).\n */\n readonly readConcern?: any\n\n /**\n * Specify a maxStalenessSeconds value for secondary reads, minimum is 90 seconds\n */\n readonly maxStalenessSeconds?: number\n\n /**\n * Specify the log level used by the driver logger (error/warn/info/debug).\n */\n readonly loggerLevel?: \"error\" | \"warn\" | \"info\" | \"debug\"\n\n // Do not overwrite BaseDataSourceOptions.logger\n // readonly logger?: any;\n\n /**\n * Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function\n * Default: true\n */\n readonly checkServerIdentity?: boolean | Function\n\n /**\n * Validate MongoClient passed in options for correctness. Default: false\n */\n readonly validateOptions?: boolean | any\n\n /**\n * The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections\n */\n readonly appname?: string\n\n /**\n * Sets the authentication mechanism that MongoDB will use to authenticate the connection\n */\n readonly authMechanism?: string\n\n /**\n * Type of compression to use: snappy or zlib\n */\n readonly compression?: any\n\n /**\n * Specify a file sync write concern. Default: false\n */\n readonly fsync?: boolean\n\n /**\n * Read preference tags\n */\n readonly readPreferenceTags?: any[]\n\n /**\n * The number of retries for a tailable cursor. Default: 5\n */\n readonly numberOfRetries?: number\n\n /**\n * Enable auto reconnecting for single server instances. Default: true\n */\n readonly auto_reconnect?: boolean\n\n /**\n * Enable command monitoring for this client. Default: false\n */\n readonly monitorCommands?: boolean\n\n /**\n * If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections\n */\n readonly minSize?: number\n\n /**\n * Determines whether or not to use the new url parser. Default: false\n */\n readonly useNewUrlParser?: boolean\n\n /**\n * Determines whether or not to use the new Server Discovery and Monitoring engine. Default: false\n * https://github.com/mongodb/node-mongodb-native/releases/tag/v3.2.1\n */\n readonly useUnifiedTopology?: boolean\n\n /**\n * Automatic Client-Side Field Level Encryption configuration.\n */\n readonly autoEncryption?: any\n\n /**\n * Enables or disables the ability to retry writes upon encountering transient network errors.\n */\n readonly retryWrites?: boolean\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/mongodb/MongoConnectionOptions.ts"],"names":[],"mappings":"","file":"MongoConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { ReadPreference } from \"./typings\"\n\n/**\n * MongoDB specific connection options.\n * Synced with http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html\n */\nexport interface MongoConnectionOptions extends BaseDataSourceOptions {\n /**\n * Database type.\n */\n readonly type: \"mongodb\"\n\n /**\n * Connection url where perform connection to.\n */\n readonly url?: string\n\n /**\n * Database host.\n */\n readonly host?: string\n\n /**\n * Database host replica set.\n */\n readonly hostReplicaSet?: string\n\n /**\n * Database host port.\n */\n readonly port?: number\n\n /**\n * Database username.\n */\n readonly username?: string\n\n /**\n * Database password.\n */\n readonly password?: string\n\n /**\n * Database name to connect to.\n */\n readonly database?: string\n\n /**\n * Specifies whether to force dispatch all operations to the specified host. Default: false\n */\n readonly directConnection?: boolean\n\n /**\n * The driver object\n * This defaults to require(\"mongodb\")\n */\n readonly driver?: any\n\n /**\n * Use ssl connection (needs to have a mongod server with ssl support). Default: false\n */\n readonly ssl?: boolean\n\n /**\n * Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).\n * Default: true\n */\n readonly sslValidate?: boolean\n\n /**\n * Array of valid certificates either as Buffers or Strings\n * (needs to have a mongod server with ssl support, 2.4 or higher).\n */\n readonly sslCA?: string | Buffer\n\n /**\n * String or buffer containing the certificate we wish to present\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslCert?: string | Buffer\n\n /**\n * String or buffer containing the certificate private key we wish to present\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslKey?: string\n\n /**\n * String or buffer containing the certificate password\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslPass?: string | Buffer\n\n /**\n * SSL Certificate revocation list binary buffer\n * (needs to have a mongod server with ssl support, 2.4 or higher)\n */\n readonly sslCRL?: string | Buffer\n\n /**\n * Reconnect on error. Default: true\n */\n readonly autoReconnect?: boolean\n\n /**\n * TCP Socket NoDelay option. Default: true\n */\n readonly noDelay?: boolean\n\n /**\n * The number of milliseconds to wait before initiating keepAlive on the TCP socket. Default: 30000\n */\n readonly keepAlive?: number\n\n /**\n * TCP Connection timeout setting. Default: 30000\n */\n readonly connectTimeoutMS?: number\n\n /**\n * Version of IP stack. Can be 4, 6.\n * If undefined, will attempt to connect with IPv6, and will fall back to IPv4 on failure\n */\n readonly family?: number\n\n /**\n * TCP Socket timeout setting. Default: 360000\n */\n readonly socketTimeoutMS?: number\n\n /**\n * Server attempt to reconnect #times. Default 30\n */\n readonly reconnectTries?: number\n\n /**\n * Server will wait #milliseconds between retries. Default 1000\n */\n readonly reconnectInterval?: number\n\n /**\n * Control if high availability monitoring runs for Replicaset or Mongos proxies. Default true\n */\n readonly ha?: boolean\n\n /**\n * The High availability period for replicaset inquiry. Default: 10000\n */\n readonly haInterval?: number\n\n /**\n * The name of the replicaset to connect to\n */\n readonly replicaSet?: string\n\n /**\n * Sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms).\n * Default: 15\n */\n readonly acceptableLatencyMS?: number\n\n /**\n * Sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms).\n * Default: 15\n */\n readonly secondaryAcceptableLatencyMS?: number\n\n /**\n * Sets if the driver should connect even if no primary is available. Default: false\n */\n readonly connectWithNoPrimary?: boolean\n\n /**\n * If the database authentication is dependent on another databaseName.\n */\n readonly authSource?: string\n\n /**\n * The write concern.\n */\n readonly w?: string | number\n\n /**\n * The write concern timeout value.\n */\n readonly wtimeout?: number\n\n /**\n * Specify a journal write concern. Default: false\n */\n readonly j?: boolean\n\n /**\n * Force server to assign _id values instead of driver. Default: false\n */\n readonly forceServerObjectId?: boolean\n\n /**\n * Serialize functions on any object. Default: false\n */\n readonly serializeFunctions?: boolean\n\n /**\n * Specify if the BSON serializer should ignore undefined fields. Default: false\n */\n readonly ignoreUndefined?: boolean\n\n /**\n * Return document results as raw BSON buffers. Default: false\n */\n readonly raw?: boolean\n\n /**\n * Promotes Long values to number if they fit inside the 53 bits resolution. Default: true\n */\n readonly promoteLongs?: boolean\n\n /**\n * Promotes Binary BSON values to native Node Buffers. Default: false\n */\n readonly promoteBuffers?: boolean\n\n /**\n * Promotes BSON values to native types where possible, set to false to only receive wrapper types. Default: true\n */\n readonly promoteValues?: boolean\n\n /**\n * Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit. Default: false\n */\n readonly domainsEnabled?: boolean\n\n /**\n * Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection,\n * default is -1 which is unlimited.\n */\n readonly bufferMaxEntries?: number\n\n /**\n * The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY,\n * ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).\n */\n readonly readPreference?: ReadPreference | string\n\n /**\n * A primary key factory object for generation of custom _id keys.\n */\n readonly pkFactory?: any\n\n /**\n * A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible.\n */\n readonly promiseLibrary?: any\n\n /**\n * Specify a read concern for the collection. (only MongoDB 3.2 or higher supported).\n */\n readonly readConcern?: any\n\n /**\n * Specify a maxStalenessSeconds value for secondary reads, minimum is 90 seconds\n */\n readonly maxStalenessSeconds?: number\n\n /**\n * Specify the log level used by the driver logger (error/warn/info/debug).\n */\n readonly loggerLevel?: \"error\" | \"warn\" | \"info\" | \"debug\"\n\n // Do not overwrite BaseDataSourceOptions.logger\n // readonly logger?: any;\n\n /**\n * Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function\n * Default: true\n */\n readonly checkServerIdentity?: boolean | Function\n\n /**\n * Validate MongoClient passed in options for correctness. Default: false\n */\n readonly validateOptions?: boolean | any\n\n /**\n * The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections\n */\n readonly appname?: string\n\n /**\n * Sets the authentication mechanism that MongoDB will use to authenticate the connection\n */\n readonly authMechanism?: string\n\n /**\n * Type of compression to use: snappy or zlib\n */\n readonly compression?: any\n\n /**\n * Specify a file sync write concern. Default: false\n */\n readonly fsync?: boolean\n\n /**\n * Read preference tags\n */\n readonly readPreferenceTags?: any[]\n\n /**\n * The number of retries for a tailable cursor. Default: 5\n */\n readonly numberOfRetries?: number\n\n /**\n * Enable auto reconnecting for single server instances. Default: true\n */\n readonly auto_reconnect?: boolean\n\n /**\n * Enable command monitoring for this client. Default: false\n */\n readonly monitorCommands?: boolean\n\n /**\n * If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections\n */\n readonly minSize?: number\n\n /**\n * Determines whether or not to use the new url parser. Default: false\n */\n readonly useNewUrlParser?: boolean\n\n /**\n * Determines whether or not to use the new Server Discovery and Monitoring engine. Default: false\n * https://github.com/mongodb/node-mongodb-native/releases/tag/v3.2.1\n */\n readonly useUnifiedTopology?: boolean\n\n /**\n * Automatic Client-Side Field Level Encryption configuration.\n */\n readonly autoEncryption?: any\n\n /**\n * Enables or disables the ability to retry writes upon encountering transient network errors.\n */\n readonly retryWrites?: boolean\n}\n"],"sourceRoot":"../.."}
@@ -148,6 +148,7 @@ export class MongoDriver {
148
148
  "useUnifiedTopology",
149
149
  "autoEncryption",
150
150
  "retryWrites",
151
+ "directConnection",
151
152
  ];
152
153
  this.cteCapabilities = {
153
154
  enabled: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/mongodb/MongoDriver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAE3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAK5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAK5E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D;;GAEG;AACH,MAAM,OAAO,WAAW;IAkMpB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAxK5C;;WAEG;QACH,iBAAY,GAAY,KAAK,CAAA;QAE7B;;WAEG;QACH,gB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AAO,CAAC,KAAK,EAAE;gBAC9C,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;aACvD;iBAAM,IAAI,UAAU,IAAI,OAAO,EAAE;gBAC9B,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;aACjD;SACJ;QAED,OAAO,YAAY,CAAA;IACvB,CAAC;CACJ","file":"MongoDriver.js","sourcesContent":["import { Driver } from \"../Driver\"\nimport { ConnectionIsNotSetError } from \"../../error/ConnectionIsNotSetError\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { CteCapabilities } from \"../types/CteCapabilities\"\nimport { MongoQueryRunner } from \"./MongoQueryRunner\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"../../metadata/ColumnMetadata\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { MongoConnectionOptions } from \"./MongoConnectionOptions\"\nimport { MappedColumnTypes } from \"../types/MappedColumnTypes\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { MongoSchemaBuilder } from \"../../schema-builder/MongoSchemaBuilder\"\nimport { DataTypeDefaults } from \"../types/DataTypeDefaults\"\nimport { TableColumn } from \"../../schema-builder/table/TableColumn\"\nimport { DataSourceOptions } from \"../../data-source/DataSourceOptions\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { ObjectUtils } from \"../../util/ObjectUtils\"\nimport { ApplyValueTransformers } from \"../../util/ApplyValueTransformers\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { DriverUtils } from \"../DriverUtils\"\nimport { TypeORMError } from \"../../error\"\nimport { Table } from \"../../schema-builder/table/Table\"\nimport { View } from \"../../schema-builder/view/View\"\nimport { TableForeignKey } from \"../../schema-builder/table/TableForeignKey\"\nimport { InstanceChecker } from \"../../util/InstanceChecker\"\nimport { UpsertType } from \"../types/UpsertType\"\n\n/**\n * Organizes communication with MongoDB.\n */\nexport class MongoDriver implements Driver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Underlying mongodb library.\n */\n mongodb: any\n\n /**\n * Mongodb does not require to dynamically create query runner each time,\n * because it does not have a regular connection pool as RDBMS systems have.\n */\n queryRunner?: MongoQueryRunner\n\n // -------------------------------------------------------------------------\n // Public Implemented Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: MongoConnectionOptions\n\n /**\n * Master database used to perform all write queries.\n */\n database?: string\n\n /**\n * Indicates if replication is enabled.\n */\n isReplicated: boolean = false\n\n /**\n * Indicates if tree tables are supported by this driver.\n */\n treeSupport = false\n\n /**\n * Represent transaction support by this driver\n */\n transactionSupport = \"none\" as const\n\n /**\n * Mongodb does not need to have column types because they are not used in schema sync.\n */\n supportedDataTypes: ColumnType[] = []\n\n /**\n * Returns type of upsert supported by driver if any\n */\n supportedUpsertTypes: UpsertType[]\n\n /**\n * Gets list of spatial column data types.\n */\n spatialTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support length by a driver.\n */\n withLengthColumnTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support precision by a driver.\n */\n withPrecisionColumnTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support scale by a driver.\n */\n withScaleColumnTypes: ColumnType[] = []\n\n /**\n * Mongodb does not need to have a strong defined mapped column types because they are not used in schema sync.\n */\n mappedDataTypes: MappedColumnTypes = {\n createDate: \"int\",\n createDateDefault: \"\",\n updateDate: \"int\",\n updateDateDefault: \"\",\n deleteDate: \"int\",\n deleteDateNullable: true,\n version: \"int\",\n treeLevel: \"int\",\n migrationId: \"int\",\n migrationName: \"int\",\n migrationTimestamp: \"int\",\n cacheId: \"int\",\n cacheIdentifier: \"int\",\n cacheTime: \"int\",\n cacheDuration: \"int\",\n cacheQuery: \"int\",\n cacheResult: \"int\",\n metadataType: \"int\",\n metadataDatabase: \"int\",\n metadataSchema: \"int\",\n metadataTable: \"int\",\n metadataName: \"int\",\n metadataValue: \"int\",\n }\n\n /**\n * Default values of length, precision and scale depends on column data type.\n * Used in the cases when length/precision/scale is not specified by user.\n */\n dataTypeDefaults: DataTypeDefaults\n\n /**\n * No documentation specifying a maximum length for identifiers could be found\n * for MongoDB.\n */\n maxAliasLength?: number\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Valid mongo connection options\n * NOTE: Keep sync with MongoConnectionOptions\n * Sync with http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html\n */\n protected validOptionNames: string[] = [\n \"poolSize\",\n \"ssl\",\n \"sslValidate\",\n \"sslCA\",\n \"sslCert\",\n \"sslKey\",\n \"sslPass\",\n \"sslCRL\",\n \"autoReconnect\",\n \"noDelay\",\n \"keepAlive\",\n \"keepAliveInitialDelay\",\n \"connectTimeoutMS\",\n \"family\",\n \"socketTimeoutMS\",\n \"reconnectTries\",\n \"reconnectInterval\",\n \"ha\",\n \"haInterval\",\n \"replicaSet\",\n \"secondaryAcceptableLatencyMS\",\n \"acceptableLatencyMS\",\n \"connectWithNoPrimary\",\n \"authSource\",\n \"w\",\n \"wtimeout\",\n \"j\",\n \"writeConcern\",\n \"forceServerObjectId\",\n \"serializeFunctions\",\n \"ignoreUndefined\",\n \"raw\",\n \"bufferMaxEntries\",\n \"readPreference\",\n \"pkFactory\",\n \"promiseLibrary\",\n \"readConcern\",\n \"maxStalenessSeconds\",\n \"loggerLevel\",\n // Do not overwrite BaseDataSourceOptions.logger\n // \"logger\",\n \"promoteValues\",\n \"promoteBuffers\",\n \"promoteLongs\",\n \"domainsEnabled\",\n \"checkServerIdentity\",\n \"validateOptions\",\n \"appname\",\n // omit auth - we are building url from username and password\n // \"auth\"\n \"authMechanism\",\n \"compression\",\n \"fsync\",\n \"readPreferenceTags\",\n \"numberOfRetries\",\n \"auto_reconnect\",\n \"minSize\",\n \"monitorCommands\",\n \"useNewUrlParser\",\n \"useUnifiedTopology\",\n \"autoEncryption\",\n \"retryWrites\",\n ]\n\n cteCapabilities: CteCapabilities = {\n enabled: false,\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {\n this.options = connection.options as MongoConnectionOptions\n\n // validate options to make sure everything is correct and driver will be able to establish connection\n this.validateOptions(connection.options)\n\n // load mongodb package\n this.loadDependencies()\n\n this.database = DriverUtils.buildMongoDBDriverOptions(\n this.options,\n ).database\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n const options = DriverUtils.buildMongoDBDriverOptions(this.options)\n\n const client = await this.mongodb.MongoClient.connect(\n this.buildConnectionUrl(options),\n this.buildConnectionOptions(options),\n )\n\n this.queryRunner = new MongoQueryRunner(this.connection, client)\n ObjectUtils.assign(this.queryRunner, {\n manager: this.connection.manager,\n })\n }\n\n afterConnect(): Promise<void> {\n return Promise.resolve()\n }\n\n /**\n * Closes connection with the database.\n */\n async disconnect(): Promise<void> {\n if (!this.queryRunner) throw new ConnectionIsNotSetError(\"mongodb\")\n // const handler = (err: any) => (err ? fail(err) : ok())\n this.queryRunner.databaseConnection.close()\n this.queryRunner = undefined\n // return ok()\n }\n\n /**\n * Creates a schema builder used to build and sync a schema.\n */\n createSchemaBuilder() {\n return new MongoSchemaBuilder(this.connection)\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode) {\n return this.queryRunner!\n }\n\n /**\n * Replaces parameters in the given sql with special escaping character\n * and an array of parameter names to be passed to a query.\n */\n escapeQueryWithParameters(\n sql: string,\n parameters: ObjectLiteral,\n nativeParameters: ObjectLiteral,\n ): [string, any[]] {\n throw new TypeORMError(\n `This operation is not supported by Mongodb driver.`,\n )\n }\n\n /**\n * Escapes a column name.\n */\n escape(columnName: string): string {\n return columnName\n }\n\n /**\n * Build full table name with database name, schema name and table name.\n * E.g. myDB.mySchema.myTable\n */\n buildTableName(\n tableName: string,\n schema?: string,\n database?: string,\n ): string {\n return tableName\n }\n\n /**\n * Parse a target table name or other types and return a normalized table definition.\n */\n parseTableName(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): { tableName: string; schema?: string; database?: string } {\n if (InstanceChecker.isEntityMetadata(target)) {\n return {\n tableName: target.tableName,\n }\n }\n\n if (InstanceChecker.isTable(target) || InstanceChecker.isView(target)) {\n return {\n tableName: target.name,\n }\n }\n\n if (InstanceChecker.isTableForeignKey(target)) {\n return {\n tableName: target.referencedTableName,\n }\n }\n\n return {\n tableName: target,\n }\n }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type and metadata.\n */\n preparePersistentValue(value: any, columnMetadata: ColumnMetadata): any {\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformTo(\n columnMetadata.transformer,\n value,\n )\n return value\n }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type or metadata.\n */\n prepareHydratedValue(value: any, columnMetadata: ColumnMetadata): any {\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformFrom(\n columnMetadata.transformer,\n value,\n )\n return value\n }\n\n /**\n * Creates a database type from a given column metadata.\n */\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n normalizeDefault(columnMetadata: ColumnMetadata): string | undefined {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Normalizes \"isUnique\" value of the column.\n */\n normalizeIsUnique(column: ColumnMetadata): boolean {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Calculates column length taking into account the default length values.\n */\n getColumnLength(column: ColumnMetadata): string {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n createFullType(column: TableColumn): string {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Obtains a new database connection to a master server.\n * Used for replication.\n * If replication is not setup then returns default connection's database connection.\n */\n obtainMasterConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Obtains a new database connection to a slave server.\n * Used for replication.\n * If replication is not setup then returns master (default) connection's database connection.\n */\n obtainSlaveConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertedId: any) {\n return metadata.objectIdColumn!.createValueMap(insertedId)\n }\n\n /**\n * Differentiate columns of this table and columns from the given column metadatas columns\n * and returns only changed.\n */\n findChangedColumns(\n tableColumns: TableColumn[],\n columnMetadatas: ColumnMetadata[],\n ): ColumnMetadata[] {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Returns true if driver supports RETURNING / OUTPUT statement.\n */\n isReturningSqlSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports uuid values generation on its own.\n */\n isUUIDGenerationSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports fulltext indices.\n */\n isFullTextColumnTypeSupported(): boolean {\n return false\n }\n\n /**\n * Creates an escaped parameter.\n */\n createParameter(parameterName: string, index: number): string {\n return \"\"\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validate driver options to make sure everything is correct and driver will be able to establish connection.\n */\n protected validateOptions(options: DataSourceOptions) {\n // todo: fix\n // if (!options.url) {\n // if (!options.database)\n // throw new DriverOptionNotSetError(\"database\");\n // }\n }\n\n /**\n * Loads all driver dependencies.\n */\n protected loadDependencies(): any {\n try {\n const mongodb = this.options.driver || PlatformTools.load(\"mongodb\")\n this.mongodb = mongodb\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"MongoDB\", \"mongodb\")\n }\n }\n\n /**\n * Builds connection url that is passed to underlying driver to perform connection to the mongodb database.\n */\n protected buildConnectionUrl(options: { [key: string]: any }): string {\n const schemaUrlPart = options.type.toLowerCase()\n const credentialsUrlPart =\n options.username && options.password\n ? `${options.username}:${options.password}@`\n : \"\"\n\n const portUrlPart =\n schemaUrlPart === \"mongodb+srv\" ? \"\" : `:${options.port || \"27017\"}`\n\n let connectionString: string\n if (options.replicaSet) {\n connectionString = `${schemaUrlPart}://${credentialsUrlPart}${\n options.hostReplicaSet ||\n options.host + portUrlPart ||\n \"127.0.0.1\" + portUrlPart\n }/${options.database || \"\"}?replicaSet=${options.replicaSet}${\n options.tls ? \"&tls=true\" : \"\"\n }`\n } else {\n connectionString = `${schemaUrlPart}://${credentialsUrlPart}${\n options.host || \"127.0.0.1\"\n }${portUrlPart}/${options.database || \"\"}${\n options.tls ? \"?tls=true\" : \"\"\n }`\n }\n\n return connectionString\n }\n\n /**\n * Build connection options from MongoConnectionOptions\n */\n protected buildConnectionOptions(options: { [key: string]: any }): any {\n const mongoOptions: any = {}\n\n for (let index = 0; index < this.validOptionNames.length; index++) {\n const optionName = this.validOptionNames[index]\n\n if (options.extra && optionName in options.extra) {\n mongoOptions[optionName] = options.extra[optionName]\n } else if (optionName in options) {\n mongoOptions[optionName] = options[optionName]\n }\n }\n\n return mongoOptions\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/mongodb/MongoDriver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAE3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAK5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAK5E,OAAO,EAAE,WAAW,EAAE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AAE,GACpC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAChC,EAAE,CAAA;SACL;QAED,OAAO,gBAAgB,CAAA;IAC3B,CAAC;IAED;;OAEG;IACO,sBAAsB,CAAC,OAA+B;QAC5D,MAAM,YAAY,GAAQ,EAAE,CAAA;QAE5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;YAE/C,IAAI,OAAO,CAAC,KAAK,IAAI,UAAU,IAAI,OAAO,CAAC,KAAK,EAAE;gBAC9C,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;aACvD;iBAAM,IAAI,UAAU,IAAI,OAAO,EAAE;gBAC9B,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;aACjD;SACJ;QAED,OAAO,YAAY,CAAA;IACvB,CAAC;CACJ","file":"MongoDriver.js","sourcesContent":["import { Driver } from \"../Driver\"\nimport { ConnectionIsNotSetError } from \"../../error/ConnectionIsNotSetError\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { CteCapabilities } from \"../types/CteCapabilities\"\nimport { MongoQueryRunner } from \"./MongoQueryRunner\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"../../metadata/ColumnMetadata\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { MongoConnectionOptions } from \"./MongoConnectionOptions\"\nimport { MappedColumnTypes } from \"../types/MappedColumnTypes\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { MongoSchemaBuilder } from \"../../schema-builder/MongoSchemaBuilder\"\nimport { DataTypeDefaults } from \"../types/DataTypeDefaults\"\nimport { TableColumn } from \"../../schema-builder/table/TableColumn\"\nimport { DataSourceOptions } from \"../../data-source/DataSourceOptions\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { ObjectUtils } from \"../../util/ObjectUtils\"\nimport { ApplyValueTransformers } from \"../../util/ApplyValueTransformers\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { DriverUtils } from \"../DriverUtils\"\nimport { TypeORMError } from \"../../error\"\nimport { Table } from \"../../schema-builder/table/Table\"\nimport { View } from \"../../schema-builder/view/View\"\nimport { TableForeignKey } from \"../../schema-builder/table/TableForeignKey\"\nimport { InstanceChecker } from \"../../util/InstanceChecker\"\nimport { UpsertType } from \"../types/UpsertType\"\n\n/**\n * Organizes communication with MongoDB.\n */\nexport class MongoDriver implements Driver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Underlying mongodb library.\n */\n mongodb: any\n\n /**\n * Mongodb does not require to dynamically create query runner each time,\n * because it does not have a regular connection pool as RDBMS systems have.\n */\n queryRunner?: MongoQueryRunner\n\n // -------------------------------------------------------------------------\n // Public Implemented Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: MongoConnectionOptions\n\n /**\n * Master database used to perform all write queries.\n */\n database?: string\n\n /**\n * Indicates if replication is enabled.\n */\n isReplicated: boolean = false\n\n /**\n * Indicates if tree tables are supported by this driver.\n */\n treeSupport = false\n\n /**\n * Represent transaction support by this driver\n */\n transactionSupport = \"none\" as const\n\n /**\n * Mongodb does not need to have column types because they are not used in schema sync.\n */\n supportedDataTypes: ColumnType[] = []\n\n /**\n * Returns type of upsert supported by driver if any\n */\n supportedUpsertTypes: UpsertType[]\n\n /**\n * Gets list of spatial column data types.\n */\n spatialTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support length by a driver.\n */\n withLengthColumnTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support precision by a driver.\n */\n withPrecisionColumnTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support scale by a driver.\n */\n withScaleColumnTypes: ColumnType[] = []\n\n /**\n * Mongodb does not need to have a strong defined mapped column types because they are not used in schema sync.\n */\n mappedDataTypes: MappedColumnTypes = {\n createDate: \"int\",\n createDateDefault: \"\",\n updateDate: \"int\",\n updateDateDefault: \"\",\n deleteDate: \"int\",\n deleteDateNullable: true,\n version: \"int\",\n treeLevel: \"int\",\n migrationId: \"int\",\n migrationName: \"int\",\n migrationTimestamp: \"int\",\n cacheId: \"int\",\n cacheIdentifier: \"int\",\n cacheTime: \"int\",\n cacheDuration: \"int\",\n cacheQuery: \"int\",\n cacheResult: \"int\",\n metadataType: \"int\",\n metadataDatabase: \"int\",\n metadataSchema: \"int\",\n metadataTable: \"int\",\n metadataName: \"int\",\n metadataValue: \"int\",\n }\n\n /**\n * Default values of length, precision and scale depends on column data type.\n * Used in the cases when length/precision/scale is not specified by user.\n */\n dataTypeDefaults: DataTypeDefaults\n\n /**\n * No documentation specifying a maximum length for identifiers could be found\n * for MongoDB.\n */\n maxAliasLength?: number\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Valid mongo connection options\n * NOTE: Keep sync with MongoConnectionOptions\n * Sync with http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html\n */\n protected validOptionNames: string[] = [\n \"poolSize\",\n \"ssl\",\n \"sslValidate\",\n \"sslCA\",\n \"sslCert\",\n \"sslKey\",\n \"sslPass\",\n \"sslCRL\",\n \"autoReconnect\",\n \"noDelay\",\n \"keepAlive\",\n \"keepAliveInitialDelay\",\n \"connectTimeoutMS\",\n \"family\",\n \"socketTimeoutMS\",\n \"reconnectTries\",\n \"reconnectInterval\",\n \"ha\",\n \"haInterval\",\n \"replicaSet\",\n \"secondaryAcceptableLatencyMS\",\n \"acceptableLatencyMS\",\n \"connectWithNoPrimary\",\n \"authSource\",\n \"w\",\n \"wtimeout\",\n \"j\",\n \"writeConcern\",\n \"forceServerObjectId\",\n \"serializeFunctions\",\n \"ignoreUndefined\",\n \"raw\",\n \"bufferMaxEntries\",\n \"readPreference\",\n \"pkFactory\",\n \"promiseLibrary\",\n \"readConcern\",\n \"maxStalenessSeconds\",\n \"loggerLevel\",\n // Do not overwrite BaseDataSourceOptions.logger\n // \"logger\",\n \"promoteValues\",\n \"promoteBuffers\",\n \"promoteLongs\",\n \"domainsEnabled\",\n \"checkServerIdentity\",\n \"validateOptions\",\n \"appname\",\n // omit auth - we are building url from username and password\n // \"auth\"\n \"authMechanism\",\n \"compression\",\n \"fsync\",\n \"readPreferenceTags\",\n \"numberOfRetries\",\n \"auto_reconnect\",\n \"minSize\",\n \"monitorCommands\",\n \"useNewUrlParser\",\n \"useUnifiedTopology\",\n \"autoEncryption\",\n \"retryWrites\",\n \"directConnection\",\n ]\n\n cteCapabilities: CteCapabilities = {\n enabled: false,\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {\n this.options = connection.options as MongoConnectionOptions\n\n // validate options to make sure everything is correct and driver will be able to establish connection\n this.validateOptions(connection.options)\n\n // load mongodb package\n this.loadDependencies()\n\n this.database = DriverUtils.buildMongoDBDriverOptions(\n this.options,\n ).database\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n const options = DriverUtils.buildMongoDBDriverOptions(this.options)\n\n const client = await this.mongodb.MongoClient.connect(\n this.buildConnectionUrl(options),\n this.buildConnectionOptions(options),\n )\n\n this.queryRunner = new MongoQueryRunner(this.connection, client)\n ObjectUtils.assign(this.queryRunner, {\n manager: this.connection.manager,\n })\n }\n\n afterConnect(): Promise<void> {\n return Promise.resolve()\n }\n\n /**\n * Closes connection with the database.\n */\n async disconnect(): Promise<void> {\n if (!this.queryRunner) throw new ConnectionIsNotSetError(\"mongodb\")\n // const handler = (err: any) => (err ? fail(err) : ok())\n this.queryRunner.databaseConnection.close()\n this.queryRunner = undefined\n // return ok()\n }\n\n /**\n * Creates a schema builder used to build and sync a schema.\n */\n createSchemaBuilder() {\n return new MongoSchemaBuilder(this.connection)\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode) {\n return this.queryRunner!\n }\n\n /**\n * Replaces parameters in the given sql with special escaping character\n * and an array of parameter names to be passed to a query.\n */\n escapeQueryWithParameters(\n sql: string,\n parameters: ObjectLiteral,\n nativeParameters: ObjectLiteral,\n ): [string, any[]] {\n throw new TypeORMError(\n `This operation is not supported by Mongodb driver.`,\n )\n }\n\n /**\n * Escapes a column name.\n */\n escape(columnName: string): string {\n return columnName\n }\n\n /**\n * Build full table name with database name, schema name and table name.\n * E.g. myDB.mySchema.myTable\n */\n buildTableName(\n tableName: string,\n schema?: string,\n database?: string,\n ): string {\n return tableName\n }\n\n /**\n * Parse a target table name or other types and return a normalized table definition.\n */\n parseTableName(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): { tableName: string; schema?: string; database?: string } {\n if (InstanceChecker.isEntityMetadata(target)) {\n return {\n tableName: target.tableName,\n }\n }\n\n if (InstanceChecker.isTable(target) || InstanceChecker.isView(target)) {\n return {\n tableName: target.name,\n }\n }\n\n if (InstanceChecker.isTableForeignKey(target)) {\n return {\n tableName: target.referencedTableName,\n }\n }\n\n return {\n tableName: target,\n }\n }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type and metadata.\n */\n preparePersistentValue(value: any, columnMetadata: ColumnMetadata): any {\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformTo(\n columnMetadata.transformer,\n value,\n )\n return value\n }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type or metadata.\n */\n prepareHydratedValue(value: any, columnMetadata: ColumnMetadata): any {\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformFrom(\n columnMetadata.transformer,\n value,\n )\n return value\n }\n\n /**\n * Creates a database type from a given column metadata.\n */\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n normalizeDefault(columnMetadata: ColumnMetadata): string | undefined {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Normalizes \"isUnique\" value of the column.\n */\n normalizeIsUnique(column: ColumnMetadata): boolean {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Calculates column length taking into account the default length values.\n */\n getColumnLength(column: ColumnMetadata): string {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n createFullType(column: TableColumn): string {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Obtains a new database connection to a master server.\n * Used for replication.\n * If replication is not setup then returns default connection's database connection.\n */\n obtainMasterConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Obtains a new database connection to a slave server.\n * Used for replication.\n * If replication is not setup then returns master (default) connection's database connection.\n */\n obtainSlaveConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertedId: any) {\n return metadata.objectIdColumn!.createValueMap(insertedId)\n }\n\n /**\n * Differentiate columns of this table and columns from the given column metadatas columns\n * and returns only changed.\n */\n findChangedColumns(\n tableColumns: TableColumn[],\n columnMetadatas: ColumnMetadata[],\n ): ColumnMetadata[] {\n throw new TypeORMError(\n `MongoDB is schema-less, not supported by this driver.`,\n )\n }\n\n /**\n * Returns true if driver supports RETURNING / OUTPUT statement.\n */\n isReturningSqlSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports uuid values generation on its own.\n */\n isUUIDGenerationSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports fulltext indices.\n */\n isFullTextColumnTypeSupported(): boolean {\n return false\n }\n\n /**\n * Creates an escaped parameter.\n */\n createParameter(parameterName: string, index: number): string {\n return \"\"\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validate driver options to make sure everything is correct and driver will be able to establish connection.\n */\n protected validateOptions(options: DataSourceOptions) {\n // todo: fix\n // if (!options.url) {\n // if (!options.database)\n // throw new DriverOptionNotSetError(\"database\");\n // }\n }\n\n /**\n * Loads all driver dependencies.\n */\n protected loadDependencies(): any {\n try {\n const mongodb = this.options.driver || PlatformTools.load(\"mongodb\")\n this.mongodb = mongodb\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"MongoDB\", \"mongodb\")\n }\n }\n\n /**\n * Builds connection url that is passed to underlying driver to perform connection to the mongodb database.\n */\n protected buildConnectionUrl(options: { [key: string]: any }): string {\n const schemaUrlPart = options.type.toLowerCase()\n const credentialsUrlPart =\n options.username && options.password\n ? `${options.username}:${options.password}@`\n : \"\"\n\n const portUrlPart =\n schemaUrlPart === \"mongodb+srv\" ? \"\" : `:${options.port || \"27017\"}`\n\n let connectionString: string\n if (options.replicaSet) {\n connectionString = `${schemaUrlPart}://${credentialsUrlPart}${\n options.hostReplicaSet ||\n options.host + portUrlPart ||\n \"127.0.0.1\" + portUrlPart\n }/${options.database || \"\"}?replicaSet=${options.replicaSet}${\n options.tls ? \"&tls=true\" : \"\"\n }`\n } else {\n connectionString = `${schemaUrlPart}://${credentialsUrlPart}${\n options.host || \"127.0.0.1\"\n }${portUrlPart}/${options.database || \"\"}${\n options.tls ? \"?tls=true\" : \"\"\n }`\n }\n\n return connectionString\n }\n\n /**\n * Build connection options from MongoConnectionOptions\n */\n protected buildConnectionOptions(options: { [key: string]: any }): any {\n const mongoOptions: any = {}\n\n for (let index = 0; index < this.validOptionNames.length; index++) {\n const optionName = this.validOptionNames[index]\n\n if (options.extra && optionName in options.extra) {\n mongoOptions[optionName] = options.extra[optionName]\n } else if (optionName in options) {\n mongoOptions[optionName] = options[optionName]\n }\n }\n\n return mongoOptions\n }\n}\n"],"sourceRoot":"../.."}
@@ -223,15 +223,13 @@ export class AbstractSqliteDriver {
223
223
  // TODO: think about `toUTC` conversion
224
224
  return DateUtils.mixedDateToUtcDatetimeString(value);
225
225
  }
226
- else if (columnMetadata.type === "json") {
227
- return JSON.stringify(value);
226
+ else if (columnMetadata.type === "json" ||
227
+ columnMetadata.type === "simple-json") {
228
+ return DateUtils.simpleJsonToString(value);
228
229
  }
229
230
  else if (columnMetadata.type === "simple-array") {
230
231
  return DateUtils.simpleArrayToString(value);
231
232
  }
232
- else if (columnMetadata.type === "simple-json") {
233
- return DateUtils.simpleJsonToString(value);
234
- }
235
233
  else if (columnMetadata.type === "simple-enum") {
236
234
  return DateUtils.simpleEnumToString(value);
237
235
  }
@@ -281,15 +279,13 @@ export class AbstractSqliteDriver {
281
279
  else if (columnMetadata.type === "time") {
282
280
  value = DateUtils.mixedTimeToString(value);
283
281
  }
284
- else if (columnMetadata.type === "json") {
285
- value = typeof value === "string" ? JSON.parse(value) : value;
282
+ else if (columnMetadata.type === "json" ||
283
+ columnMetadata.type === "simple-json") {
284
+ value = DateUtils.stringToSimpleJson(value);
286
285
  }
287
286
  else if (columnMetadata.type === "simple-array") {
288
287
  value = DateUtils.stringToSimpleArray(value);
289
288
  }
290
- else if (columnMetadata.type === "simple-json") {
291
- value = DateUtils.stringToSimpleJson(value);
292
- }
293
289
  else if (columnMetadata.type === "simple-enum") {
294
290
  value = DateUtils.stringToSimpleEnum(value, columnMetadata);
295
291
  }