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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/browser/driver/DriverUtils.js +2 -5
  2. package/browser/driver/DriverUtils.js.map +1 -1
  3. package/browser/driver/sqlserver/SqlServerConnectionCredentialsOptions.d.ts +2 -1
  4. package/browser/driver/sqlserver/SqlServerConnectionCredentialsOptions.js.map +1 -1
  5. package/browser/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.d.ts +12 -0
  6. package/browser/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js +3 -0
  7. package/browser/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js.map +1 -0
  8. package/browser/error/QueryFailedError.d.ts +3 -3
  9. package/browser/error/QueryFailedError.js.map +1 -1
  10. package/browser/find-options/FindOptionsUtils.js +1 -1
  11. package/browser/find-options/FindOptionsUtils.js.map +1 -1
  12. package/browser/naming-strategy/DefaultNamingStrategy.d.ts +0 -1
  13. package/browser/naming-strategy/DefaultNamingStrategy.js +0 -3
  14. package/browser/naming-strategy/DefaultNamingStrategy.js.map +1 -1
  15. package/browser/naming-strategy/NamingStrategyInterface.d.ts +0 -4
  16. package/browser/naming-strategy/NamingStrategyInterface.js.map +1 -1
  17. package/browser/persistence/Subject.js +2 -1
  18. package/browser/persistence/Subject.js.map +1 -1
  19. package/browser/query-builder/QueryBuilder.js +1 -1
  20. package/browser/query-builder/QueryBuilder.js.map +1 -1
  21. package/browser/repository/Repository.d.ts +1 -1
  22. package/browser/repository/Repository.js +9 -5
  23. package/browser/repository/Repository.js.map +1 -1
  24. package/commands/CommandUtils.js +6 -1
  25. package/commands/CommandUtils.js.map +1 -1
  26. package/commands/EntityCreateCommand.d.ts +3 -0
  27. package/commands/EntityCreateCommand.js +7 -0
  28. package/commands/EntityCreateCommand.js.map +1 -1
  29. package/commands/MigrationCreateCommand.d.ts +5 -1
  30. package/commands/MigrationCreateCommand.js +6 -1
  31. package/commands/MigrationCreateCommand.js.map +1 -1
  32. package/commands/MigrationGenerateCommand.d.ts +5 -1
  33. package/commands/MigrationGenerateCommand.js +5 -0
  34. package/commands/MigrationGenerateCommand.js.map +1 -1
  35. package/commands/SubscriberCreateCommand.d.ts +3 -0
  36. package/commands/SubscriberCreateCommand.js +7 -0
  37. package/commands/SubscriberCreateCommand.js.map +1 -1
  38. package/driver/DriverUtils.js +2 -5
  39. package/driver/DriverUtils.js.map +1 -1
  40. package/driver/sqlserver/SqlServerConnectionCredentialsOptions.d.ts +2 -1
  41. package/driver/sqlserver/SqlServerConnectionCredentialsOptions.js.map +1 -1
  42. package/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.d.ts +12 -0
  43. package/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js +4 -0
  44. package/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.js.map +1 -0
  45. package/error/QueryFailedError.d.ts +3 -3
  46. package/error/QueryFailedError.js.map +1 -1
  47. package/find-options/FindOptionsUtils.js +1 -1
  48. package/find-options/FindOptionsUtils.js.map +1 -1
  49. package/naming-strategy/DefaultNamingStrategy.d.ts +0 -1
  50. package/naming-strategy/DefaultNamingStrategy.js +0 -3
  51. package/naming-strategy/DefaultNamingStrategy.js.map +1 -1
  52. package/naming-strategy/NamingStrategyInterface.d.ts +0 -4
  53. package/naming-strategy/NamingStrategyInterface.js.map +1 -1
  54. package/package.json +1 -1
  55. package/persistence/Subject.js +2 -1
  56. package/persistence/Subject.js.map +1 -1
  57. package/query-builder/QueryBuilder.js +1 -1
  58. package/query-builder/QueryBuilder.js.map +1 -1
  59. package/repository/Repository.d.ts +1 -1
  60. package/repository/Repository.js +9 -5
  61. package/repository/Repository.js.map +1 -1
@@ -90,11 +90,8 @@ export class DriverUtils {
90
90
  * @return An alias that is no longer than the divers max alias length.
91
91
  */
92
92
  static buildAlias({ maxAliasLength }, buildOptions, ...alias) {
93
- const newAlias = alias.length === 1
94
- ? alias[0]
95
- : alias.join(buildOptions && buildOptions.joiner
96
- ? buildOptions.joiner
97
- : "_");
93
+ const joiner = buildOptions && buildOptions.joiner ? buildOptions.joiner : "_";
94
+ let newAlias = alias.length === 1 ? alias[0] : alias.join(joiner);
98
95
  if (maxAliasLength &&
99
96
  maxAliasLength > 0 &&
100
97
  newAlias.length > maxAliasLength) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/DriverUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc;QAChC,OAAO;YACH,QAAQ;YACR,SAAS;YACT,cAAc;YACd,cAAc;YACd,OAAO;YACP,MAAM;YACN,gBAAgB;YAChB,WAAW;SACd,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAc;QAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,CAAC,yBAAyB,CAAC,MAAc,EAAE,OAAe;QAC5D,OAAO,CACH,MAAM,CAAC,OAAO,IAAI,IAAI;YACtB,YAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CACzD,CAAA;IACL,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAc;QAClC,OAAO,CAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC,QAAQ,CAC1D,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aAAa,CAAC,EAAE;YACtD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SAC7B;QAED,OAAO,aAAa,CAAA;IACxB,CAAC;CACJ","file":"DriverUtils.js","sourcesContent":["import { Driver } from \"./Driver\"\nimport { hash, shorten } from \"../util/StringUtils\"\nimport { VersionUtils } from \"../util/VersionUtils\"\n\n/**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns true if given driver is SQLite-based driver.\n */\n static isSQLiteFamily(driver: Driver): boolean {\n return [\n \"sqlite\",\n \"cordova\",\n \"react-native\",\n \"nativescript\",\n \"sqljs\",\n \"expo\",\n \"better-sqlite3\",\n \"capacitor\",\n ].includes(driver.options.type)\n }\n\n /**\n * Returns true if given driver is MySQL-based driver.\n */\n static isMySQLFamily(driver: Driver): boolean {\n return [\"mysql\", \"mariadb\"].includes(driver.options.type)\n }\n\n static isReleaseVersionOrGreater(driver: Driver, version: string): boolean {\n return (\n driver.version != null &&\n VersionUtils.isGreaterOrEqual(driver.version, version)\n )\n }\n\n static isPostgresFamily(driver: Driver): boolean {\n return [\"postgres\", \"aurora-postgres\", \"cockroachdb\"].includes(\n driver.options.type,\n )\n }\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseConnectionUrl(options.url) as {\n [key: string]: any\n }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * buildDriverOptions for MongodDB only to support replica set\n */\n static buildMongoDBDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseMongoDBConnectionUrl(\n options.url,\n ) as { [key: string]: any }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * Joins and shortens alias if needed.\n *\n * If the alias length is greater than the limit allowed by the current\n * driver, replaces it with a shortend string, if the shortend string\n * is still too long, it will then hash the alias.\n *\n * @param driver Current `Driver`.\n * @param buildOptions Optional settings.\n * @param alias Alias parts.\n *\n * @return An alias that is no longer than the divers max alias length.\n */\n static buildAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | undefined,\n ...alias: string[]\n ): string {\n const newAlias =\n alias.length === 1\n ? alias[0]\n : alias.join(\n buildOptions && buildOptions.joiner\n ? buildOptions.joiner\n : \"_\",\n )\n if (\n maxAliasLength &&\n maxAliasLength > 0 &&\n newAlias.length > maxAliasLength\n ) {\n if (buildOptions && buildOptions.shorten === true) {\n const shortenedAlias = shorten(newAlias)\n if (shortenedAlias.length < maxAliasLength) {\n return shortenedAlias\n }\n }\n\n return hash(newAlias, { length: maxAliasLength })\n }\n\n return newAlias\n }\n\n /**\n * @deprecated use `buildAlias` instead.\n */\n static buildColumnAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | string,\n ...alias: string[]\n ) {\n if (typeof buildOptions === \"string\") {\n alias.unshift(buildOptions)\n buildOptions = { shorten: false, joiner: \"_\" }\n } else {\n buildOptions = Object.assign(\n { shorten: false, joiner: \"_\" },\n buildOptions,\n )\n }\n return this.buildAlias(\n { maxAliasLength } as Driver,\n buildOptions,\n ...alias,\n )\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n // remove mongodb query params\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n const [host, port] = hostAndPort.split(\":\")\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n }\n\n /**\n * Extracts connection data from the connection url for MongoDB to support replica set.\n */\n private static parseMongoDBConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n let afterQuestionMark = \"\"\n let host = undefined\n let port = undefined\n let hostReplicaSet = undefined\n let replicaSet = undefined\n\n let optionsObject: any = {}\n\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n // split params\n afterQuestionMark = afterBase.substr(\n afterBase.indexOf(\"?\") + 1,\n afterBase.length,\n )\n\n const optionsList = afterQuestionMark.split(\"&\")\n let optionKey: string\n let optionValue: string\n\n // create optionsObject for merge with connectionUrl object before return\n optionsList.forEach((optionItem) => {\n optionKey = optionItem.split(\"=\")[0]\n optionValue = optionItem.split(\"=\")[1]\n optionsObject[optionKey] = optionValue\n })\n\n // specific replicaSet value to set options about hostReplicaSet\n replicaSet = optionsObject[\"replicaSet\"]\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n\n // If replicaSet have value set It as hostlist, If not set like standalone host\n if (replicaSet) {\n hostReplicaSet = hostAndPort\n } else {\n ;[host, port] = hostAndPort.split(\":\")\n }\n\n let connectionUrl: any = {\n type: type,\n host: host,\n hostReplicaSet: hostReplicaSet,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n\n // Loop to set every options in connectionUrl to object\n for (const [key, value] of Object.entries(optionsObject)) {\n connectionUrl[key] = value\n }\n\n return connectionUrl\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/driver/DriverUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc;QAChC,OAAO;YACH,QAAQ;YACR,SAAS;YACT,cAAc;YACd,cAAc;YACd,OAAO;YACP,MAAM;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;SACxD;QAED,+EAA+E;QAC/E,IAAI,UAAU,EAAE;YACZ,cAAc,GAAG,WAAW,CAAA;SAC/B;aAAM;YACH,CAAC;YAAA,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SACzC;QAED,IAAI,aAAa,GAAQ;YACrB,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,IAAI;YACV,cAAc,EAAE,cAAc;YAC9B,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YACvC,QAAQ,EAAE,SAAS,IAAI,SAAS;SACnC,CAAA;QAED,uDAAuD;QACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACtD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SAC7B;QAED,OAAO,aAAa,CAAA;IACxB,CAAC;CACJ","file":"DriverUtils.js","sourcesContent":["import { Driver } from \"./Driver\"\nimport { hash, shorten } from \"../util/StringUtils\"\nimport { VersionUtils } from \"../util/VersionUtils\"\n\n/**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns true if given driver is SQLite-based driver.\n */\n static isSQLiteFamily(driver: Driver): boolean {\n return [\n \"sqlite\",\n \"cordova\",\n \"react-native\",\n \"nativescript\",\n \"sqljs\",\n \"expo\",\n \"better-sqlite3\",\n \"capacitor\",\n ].includes(driver.options.type)\n }\n\n /**\n * Returns true if given driver is MySQL-based driver.\n */\n static isMySQLFamily(driver: Driver): boolean {\n return [\"mysql\", \"mariadb\"].includes(driver.options.type)\n }\n\n static isReleaseVersionOrGreater(driver: Driver, version: string): boolean {\n return (\n driver.version != null &&\n VersionUtils.isGreaterOrEqual(driver.version, version)\n )\n }\n\n static isPostgresFamily(driver: Driver): boolean {\n return [\"postgres\", \"aurora-postgres\", \"cockroachdb\"].includes(\n driver.options.type,\n )\n }\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseConnectionUrl(options.url) as {\n [key: string]: any\n }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * buildDriverOptions for MongodDB only to support replica set\n */\n static buildMongoDBDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseMongoDBConnectionUrl(\n options.url,\n ) as { [key: string]: any }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * Joins and shortens alias if needed.\n *\n * If the alias length is greater than the limit allowed by the current\n * driver, replaces it with a shortend string, if the shortend string\n * is still too long, it will then hash the alias.\n *\n * @param driver Current `Driver`.\n * @param buildOptions Optional settings.\n * @param alias Alias parts.\n *\n * @return An alias that is no longer than the divers max alias length.\n */\n static buildAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | undefined,\n ...alias: string[]\n ): string {\n const joiner =\n buildOptions && buildOptions.joiner ? buildOptions.joiner : \"_\"\n\n let newAlias = alias.length === 1 ? alias[0] : alias.join(joiner)\n\n if (\n maxAliasLength &&\n maxAliasLength > 0 &&\n newAlias.length > maxAliasLength\n ) {\n if (buildOptions && buildOptions.shorten === true) {\n const shortenedAlias = shorten(newAlias)\n if (shortenedAlias.length < maxAliasLength) {\n return shortenedAlias\n }\n }\n\n return hash(newAlias, { length: maxAliasLength })\n }\n\n return newAlias\n }\n\n /**\n * @deprecated use `buildAlias` instead.\n */\n static buildColumnAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | string,\n ...alias: string[]\n ) {\n if (typeof buildOptions === \"string\") {\n alias.unshift(buildOptions)\n buildOptions = { shorten: false, joiner: \"_\" }\n } else {\n buildOptions = Object.assign(\n { shorten: false, joiner: \"_\" },\n buildOptions,\n )\n }\n return this.buildAlias(\n { maxAliasLength } as Driver,\n buildOptions,\n ...alias,\n )\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n // remove mongodb query params\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n const [host, port] = hostAndPort.split(\":\")\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n }\n\n /**\n * Extracts connection data from the connection url for MongoDB to support replica set.\n */\n private static parseMongoDBConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n let afterQuestionMark = \"\"\n let host = undefined\n let port = undefined\n let hostReplicaSet = undefined\n let replicaSet = undefined\n\n let optionsObject: any = {}\n\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n // split params\n afterQuestionMark = afterBase.substr(\n afterBase.indexOf(\"?\") + 1,\n afterBase.length,\n )\n\n const optionsList = afterQuestionMark.split(\"&\")\n let optionKey: string\n let optionValue: string\n\n // create optionsObject for merge with connectionUrl object before return\n optionsList.forEach((optionItem) => {\n optionKey = optionItem.split(\"=\")[0]\n optionValue = optionItem.split(\"=\")[1]\n optionsObject[optionKey] = optionValue\n })\n\n // specific replicaSet value to set options about hostReplicaSet\n replicaSet = optionsObject[\"replicaSet\"]\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n\n // If replicaSet have value set It as hostlist, If not set like standalone host\n if (replicaSet) {\n hostReplicaSet = hostAndPort\n } else {\n ;[host, port] = hostAndPort.split(\":\")\n }\n\n let connectionUrl: any = {\n type: type,\n host: host,\n hostReplicaSet: hostReplicaSet,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n\n // Loop to set every options in connectionUrl to object\n for (const [key, value] of Object.entries(optionsObject)) {\n connectionUrl[key] = value\n }\n\n return connectionUrl\n }\n}\n"],"sourceRoot":".."}
@@ -1,11 +1,12 @@
1
1
  import { DefaultAuthentication } from "./authentication/DefaultAuthentication";
2
2
  import { AzureActiveDirectoryAccessTokenAuthentication } from "./authentication/AzureActiveDirectoryAccessTokenAuthentication";
3
+ import { AzureActiveDirectoryDefaultAuthentication } from "./authentication/AzureActiveDirectoryDefaultAuthentication";
3
4
  import { AzureActiveDirectoryMsiAppServiceAuthentication } from "./authentication/AzureActiveDirectoryMsiAppServiceAuthentication";
4
5
  import { AzureActiveDirectoryMsiVmAuthentication } from "./authentication/AzureActiveDirectoryMsiVmAuthentication";
5
6
  import { AzureActiveDirectoryPasswordAuthentication } from "./authentication/AzureActiveDirectoryPasswordAuthentication";
6
7
  import { AzureActiveDirectoryServicePrincipalSecret } from "./authentication/AzureActiveDirectoryServicePrincipalSecret";
7
8
  import { NtlmAuthentication } from "./authentication/NtlmAuthentication";
8
- export type SqlServerConnectionCredentialsAuthenticationOptions = DefaultAuthentication | NtlmAuthentication | AzureActiveDirectoryAccessTokenAuthentication | AzureActiveDirectoryMsiAppServiceAuthentication | AzureActiveDirectoryMsiVmAuthentication | AzureActiveDirectoryPasswordAuthentication | AzureActiveDirectoryServicePrincipalSecret;
9
+ export type SqlServerConnectionCredentialsAuthenticationOptions = DefaultAuthentication | NtlmAuthentication | AzureActiveDirectoryAccessTokenAuthentication | AzureActiveDirectoryDefaultAuthentication | AzureActiveDirectoryMsiAppServiceAuthentication | AzureActiveDirectoryMsiVmAuthentication | AzureActiveDirectoryPasswordAuthentication | AzureActiveDirectoryServicePrincipalSecret;
9
10
  /**
10
11
  * SqlServer specific connection credential options.
11
12
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqlserver/SqlServerConnectionCredentialsOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionCredentialsOptions.js","sourcesContent":["import { DefaultAuthentication } from \"./authentication/DefaultAuthentication\"\nimport { AzureActiveDirectoryAccessTokenAuthentication } from \"./authentication/AzureActiveDirectoryAccessTokenAuthentication\"\nimport { AzureActiveDirectoryMsiAppServiceAuthentication } from \"./authentication/AzureActiveDirectoryMsiAppServiceAuthentication\"\nimport { AzureActiveDirectoryMsiVmAuthentication } from \"./authentication/AzureActiveDirectoryMsiVmAuthentication\"\nimport { AzureActiveDirectoryPasswordAuthentication } from \"./authentication/AzureActiveDirectoryPasswordAuthentication\"\nimport { AzureActiveDirectoryServicePrincipalSecret } from \"./authentication/AzureActiveDirectoryServicePrincipalSecret\"\nimport { NtlmAuthentication } from \"./authentication/NtlmAuthentication\"\n\nexport type SqlServerConnectionCredentialsAuthenticationOptions =\n | DefaultAuthentication\n | NtlmAuthentication\n | AzureActiveDirectoryAccessTokenAuthentication\n | AzureActiveDirectoryMsiAppServiceAuthentication\n | AzureActiveDirectoryMsiVmAuthentication\n | AzureActiveDirectoryPasswordAuthentication\n | AzureActiveDirectoryServicePrincipalSecret\n\n/**\n * SqlServer specific connection credential options.\n */\nexport interface SqlServerConnectionCredentialsOptions {\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 port.\n */\n readonly port?: number\n\n /**\n * Database name to connect to.\n */\n readonly database?: string\n\n /**\n * Database username.\n */\n readonly username?: string\n\n /**\n * Database password.\n */\n readonly password?: string\n\n /**\n * Authentication settings\n * It overrides username and password, when passed.\n */\n readonly authentication?: SqlServerConnectionCredentialsAuthenticationOptions\n\n /**\n * Once you set domain, driver will connect to SQL Server using domain login.\n * @see SqlServerConnectionCredentialsOptions.authentication\n * @see NtlmAuthentication\n * @deprecated\n */\n readonly domain?: string\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqlserver/SqlServerConnectionCredentialsOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionCredentialsOptions.js","sourcesContent":["import { DefaultAuthentication } from \"./authentication/DefaultAuthentication\"\nimport { AzureActiveDirectoryAccessTokenAuthentication } from \"./authentication/AzureActiveDirectoryAccessTokenAuthentication\"\nimport { AzureActiveDirectoryDefaultAuthentication } from \"./authentication/AzureActiveDirectoryDefaultAuthentication\"\nimport { AzureActiveDirectoryMsiAppServiceAuthentication } from \"./authentication/AzureActiveDirectoryMsiAppServiceAuthentication\"\nimport { AzureActiveDirectoryMsiVmAuthentication } from \"./authentication/AzureActiveDirectoryMsiVmAuthentication\"\nimport { AzureActiveDirectoryPasswordAuthentication } from \"./authentication/AzureActiveDirectoryPasswordAuthentication\"\nimport { AzureActiveDirectoryServicePrincipalSecret } from \"./authentication/AzureActiveDirectoryServicePrincipalSecret\"\nimport { NtlmAuthentication } from \"./authentication/NtlmAuthentication\"\n\nexport type SqlServerConnectionCredentialsAuthenticationOptions =\n | DefaultAuthentication\n | NtlmAuthentication\n | AzureActiveDirectoryAccessTokenAuthentication\n | AzureActiveDirectoryDefaultAuthentication\n | AzureActiveDirectoryMsiAppServiceAuthentication\n | AzureActiveDirectoryMsiVmAuthentication\n | AzureActiveDirectoryPasswordAuthentication\n | AzureActiveDirectoryServicePrincipalSecret\n\n/**\n * SqlServer specific connection credential options.\n */\nexport interface SqlServerConnectionCredentialsOptions {\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 port.\n */\n readonly port?: number\n\n /**\n * Database name to connect to.\n */\n readonly database?: string\n\n /**\n * Database username.\n */\n readonly username?: string\n\n /**\n * Database password.\n */\n readonly password?: string\n\n /**\n * Authentication settings\n * It overrides username and password, when passed.\n */\n readonly authentication?: SqlServerConnectionCredentialsAuthenticationOptions\n\n /**\n * Once you set domain, driver will connect to SQL Server using domain login.\n * @see SqlServerConnectionCredentialsOptions.authentication\n * @see NtlmAuthentication\n * @deprecated\n */\n readonly domain?: string\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,12 @@
1
+ export interface AzureActiveDirectoryDefaultAuthentication {
2
+ /**
3
+ * This uses DefaultAzureCredential from @azure/identity to try multiple methods of authentication
4
+ */
5
+ type: "azure-active-directory-default";
6
+ options: {
7
+ /**
8
+ * The clientId of the user you want to log in with, mapped to the managedIdentityClientId in tedious
9
+ */
10
+ clientId?: string;
11
+ };
12
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=AzureActiveDirectoryDefaultAuthentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../browser/src/driver/sqlserver/authentication/AzureActiveDirectoryDefaultAuthentication.ts"],"names":[],"mappings":"","file":"AzureActiveDirectoryDefaultAuthentication.js","sourcesContent":["export interface AzureActiveDirectoryDefaultAuthentication {\n /**\n * This uses DefaultAzureCredential from @azure/identity to try multiple methods of authentication\n */\n type: \"azure-active-directory-default\"\n options: {\n /**\n * The clientId of the user you want to log in with, mapped to the managedIdentityClientId in tedious\n */\n clientId?: string\n }\n}\n"],"sourceRoot":"../../.."}
@@ -2,9 +2,9 @@ import { TypeORMError } from "./TypeORMError";
2
2
  /**
3
3
  * Thrown when query execution has failed.
4
4
  */
5
- export declare class QueryFailedError extends TypeORMError {
5
+ export declare class QueryFailedError<T extends Error = Error> extends TypeORMError {
6
6
  readonly query: string;
7
7
  readonly parameters: any[] | undefined;
8
- readonly driverError: any;
9
- constructor(query: string, parameters: any[] | undefined, driverError: any);
8
+ readonly driverError: T;
9
+ constructor(query: string, parameters: any[] | undefined, driverError: T);
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/error/QueryFailedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9C,YACa,KAAa,EACb,UAA6B,EAC7B,WAAgB;QAEzB,KAAK,CACD,WAAW;aACN,QAAQ,EAAE;aACV,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;aACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;aACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAC/B,CAAA;QAVQ,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAmB;QAC7B,gBAAW,GAAX,WAAW,CAAK;QAUzB,IAAI,WAAW,EAAE;YACb,MAAM,EACF,IAAI,EAAE,CAAC,EAAE,sBAAsB;YAC/B,GAAG,eAAe,EACrB,GAAG,WAAW,CAAA;YAEf,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE;gBACrB,GAAG,eAAe;aACrB,CAAC,CAAA;SACL;IACL,CAAC;CACJ","file":"QueryFailedError.js","sourcesContent":["import { ObjectUtils } from \"../util/ObjectUtils\"\nimport { TypeORMError } from \"./TypeORMError\"\n\n/**\n * Thrown when query execution has failed.\n */\nexport class QueryFailedError extends TypeORMError {\n constructor(\n readonly query: string,\n readonly parameters: any[] | undefined,\n readonly driverError: any,\n ) {\n super(\n driverError\n .toString()\n .replace(/^error: /, \"\")\n .replace(/^Error: /, \"\")\n .replace(/^Request/, \"\"),\n )\n\n if (driverError) {\n const {\n name: _, // eslint-disable-line\n ...otherProperties\n } = driverError\n\n ObjectUtils.assign(this, {\n ...otherProperties,\n })\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/error/QueryFailedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,MAAM,OAAO,gBAA0C,SAAQ,YAAY;IACvE,YACa,KAAa,EACb,UAA6B,EAC7B,WAAc;QAEvB,KAAK,CACD,WAAW;aACN,QAAQ,EAAE;aACV,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;aACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;aACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAC/B,CAAA;QAVQ,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAmB;QAC7B,gBAAW,GAAX,WAAW,CAAG;QAUvB,IAAI,WAAW,EAAE;YACb,MAAM,EACF,IAAI,EAAE,CAAC,EAAE,sBAAsB;YAC/B,GAAG,eAAe,EACrB,GAAG,WAAW,CAAA;YAEf,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE;gBACrB,GAAG,eAAe;aACrB,CAAC,CAAA;SACL;IACL,CAAC;CACJ","file":"QueryFailedError.js","sourcesContent":["import { ObjectUtils } from \"../util/ObjectUtils\"\nimport { TypeORMError } from \"./TypeORMError\"\n\n/**\n * Thrown when query execution has failed.\n */\nexport class QueryFailedError<T extends Error = Error> extends TypeORMError {\n constructor(\n readonly query: string,\n readonly parameters: any[] | undefined,\n readonly driverError: T,\n ) {\n super(\n driverError\n .toString()\n .replace(/^error: /, \"\")\n .replace(/^Error: /, \"\")\n .replace(/^Request/, \"\"),\n )\n\n if (driverError) {\n const {\n name: _, // eslint-disable-line\n ...otherProperties\n } = driverError\n\n ObjectUtils.assign(this, {\n ...otherProperties,\n })\n }\n }\n}\n"],"sourceRoot":".."}
@@ -300,7 +300,7 @@ export class FindOptionsUtils {
300
300
  static joinEagerRelations(qb, alias, metadata) {
301
301
  metadata.eagerRelations.forEach((relation) => {
302
302
  // generate a relation alias
303
- let relationAlias = DriverUtils.buildAlias(qb.connection.driver, { joiner: "__" }, alias, relation.propertyPath);
303
+ let relationAlias = DriverUtils.buildAlias(qb.connection.driver, { joiner: "__" }, alias, relation.propertyName);
304
304
  // add a join for the relation
305
305
  // Checking whether the relation wasn't joined yet.
306
306
  let addJoin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AAQ,CAAC,YAAY,EAAE,EACzC;oBACE,SAAQ;iBACX;gBACD,OAAO,GAAG,KAAK,CAAA;gBACf,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;gBAC/B,MAAK;aACR;YAED,MAAM,gBAAgB,GAAG,OAAO,CAC5B,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAChC,CAAC,aAAa,EAAE,EAAE,CACd,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,aAAa,CACjD,CACJ,CAAA;YAED,IAAI,OAAO,IAAI,CAAC,gBAAgB,EAAE;gBAC9B,EAAE,CAAC,QAAQ,CAAC,KAAK,GAAG,GAAG,GAAG,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,CAAA;aAClE;YAED,qDAAqD;YACrD,oEAAoE;YACpE,IAAI,SAAS,GAAG,IAAI,CAAA;YACpB,KAAK,MAAM,MAAM,IAAI,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE;gBAC3C,IACI,MAAM,CAAC,SAAS,KAAK,SAAS;oBAC9B,MAAM,CAAC,OAAO,KAAK,SAAS;oBAC5B,MAAM,CAAC,SAAS,KAAK,aAAa,EACpC;oBACE,SAAQ;iBACX;gBACD,SAAS,GAAG,KAAK,CAAA;gBACjB,MAAK;aACR;YAED,IAAI,SAAS,EAAE;gBACX,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;aAC9B;YAED,uCAAuC;YACvC,IAAI,CAAC,kBAAkB,CACnB,EAAE,EACF,aAAa,EACb,QAAQ,CAAC,qBAAqB,CACjC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"FindOptionsUtils.js","sourcesContent":["import { FindManyOptions } from \"./FindManyOptions\"\nimport { FindOneOptions } from \"./FindOneOptions\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { FindRelationsNotFoundError } from \"../error\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { FindTreeOptions } from \"./FindTreeOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { EntityPropertyNotFoundError } from \"../error\"\n\n/**\n * Utilities to work with FindOptions.\n */\nexport class FindOptionsUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if given object is really instance of FindOneOptions interface.\n */\n static isFindOneOptions<Entity = any>(\n obj: any,\n ): obj is FindOneOptions<Entity> {\n const possibleOptions: FindOneOptions<Entity> = obj\n return (\n possibleOptions &&\n (Array.isArray(possibleOptions.select) ||\n Array.isArray(possibleOptions.relations) ||\n typeof possibleOptions.select === \"object\" ||\n typeof possibleOptions.relations === \"object\" ||\n typeof possibleOptions.where === \"object\" ||\n // typeof possibleOptions.where === \"string\" ||\n typeof possibleOptions.join === \"object\" ||\n typeof possibleOptions.order === \"object\" ||\n typeof possibleOptions.cache === \"object\" ||\n typeof possibleOptions.cache === \"boolean\" ||\n typeof possibleOptions.cache === \"number\" ||\n typeof possibleOptions.comment === \"string\" ||\n typeof possibleOptions.lock === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"boolean\" ||\n typeof possibleOptions.loadEagerRelations === \"boolean\" ||\n typeof possibleOptions.withDeleted === \"boolean\" ||\n typeof possibleOptions.relationLoadStrategy === \"string\" ||\n typeof possibleOptions.transaction === \"boolean\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindManyOptions interface.\n */\n static isFindManyOptions<Entity = any>(\n obj: any,\n ): obj is FindManyOptions<Entity> {\n const possibleOptions: FindManyOptions<Entity> = obj\n return (\n possibleOptions &&\n (this.isFindOneOptions(possibleOptions) ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"string\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"string\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindOptions interface.\n */\n static extractFindManyOptionsAlias(object: any): string | undefined {\n if (this.isFindManyOptions(object) && object.join)\n return object.join.alias\n\n return undefined\n }\n\n /**\n * Applies give find many options to the given query builder.\n\n static applyFindManyOptionsOrConditionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindManyOptions<T>|Partial<T>|undefined): SelectQueryBuilder<T> {\n if (this.isFindManyOptions(options))\n return this.applyOptionsToQueryBuilder(qb, options);\n\n if (options)\n return qb.where(options);\n\n return qb;\n }*/\n\n /**\n * Applies give find options to the given query builder.\n\n static applyOptionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindOneOptions<T>|FindManyOptions<T>|undefined): SelectQueryBuilder<T> {\n\n // if options are not set then simply return query builder. This is made for simplicity of usage.\n if (!options || (!this.isFindOneOptions(options) && !this.isFindManyOptions(options)))\n return qb;\n\n if (options.transaction === true) {\n qb.expressionMap.useTransaction = true;\n }\n\n if (!qb.expressionMap.mainAlias || !qb.expressionMap.mainAlias.hasMetadata)\n return qb;\n\n const metadata = qb.expressionMap.mainAlias!.metadata;\n\n // apply all options from FindOptions\n if (options.comment) {\n qb.comment(options.comment);\n }\n\n if (options.withDeleted) {\n qb.withDeleted();\n }\n\n if (options.select) {\n qb.select([]);\n options.select.forEach(select => {\n if (!metadata.hasColumnWithPropertyPath(`${select}`))\n throw new TypeORMError(`${select} column was not found in the ${metadata.name} entity.`);\n\n const columns = metadata.findColumnsWithPropertyPath(`${select}`);\n\n for (const column of columns) {\n qb.addSelect(qb.alias + \".\" + column.propertyPath);\n }\n });\n }\n\n if (options.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations];\n this.applyRelationsRecursively(qb, allRelations, qb.expressionMap.mainAlias!.name, qb.expressionMap.mainAlias!.metadata, \"\");\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations);\n }\n\n if (options.join) {\n if (options.join.leftJoin)\n Object.keys(options.join.leftJoin).forEach(key => {\n qb.leftJoin(options.join!.leftJoin![key], key);\n });\n\n if (options.join.innerJoin)\n Object.keys(options.join.innerJoin).forEach(key => {\n qb.innerJoin(options.join!.innerJoin![key], key);\n });\n\n if (options.join.leftJoinAndSelect)\n Object.keys(options.join.leftJoinAndSelect).forEach(key => {\n qb.leftJoinAndSelect(options.join!.leftJoinAndSelect![key], key);\n });\n\n if (options.join.innerJoinAndSelect)\n Object.keys(options.join.innerJoinAndSelect).forEach(key => {\n qb.innerJoinAndSelect(options.join!.innerJoinAndSelect![key], key);\n });\n }\n\n if (options.cache) {\n if (options.cache instanceof Object) {\n const cache = options.cache as { id: any, milliseconds: number };\n qb.cache(cache.id, cache.milliseconds);\n } else {\n qb.cache(options.cache);\n }\n }\n\n if (options.lock) {\n if (options.lock.mode === \"optimistic\") {\n qb.setLock(options.lock.mode, options.lock.version);\n } else if (\n options.lock.mode === \"pessimistic_read\" ||\n options.lock.mode === \"pessimistic_write\" ||\n options.lock.mode === \"dirty_read\" ||\n options.lock.mode === \"pessimistic_partial_write\" ||\n options.lock.mode === \"pessimistic_write_or_fail\" ||\n options.lock.mode === \"for_no_key_update\" ||\n options.lock.mode === \"for_key_share\"\n ) {\n const tableNames = options.lock.tables ? options.lock.tables.map((table) => {\n const tableAlias = qb.expressionMap.aliases.find((alias) => {\n return alias.metadata.tableNameWithoutPrefix === table;\n });\n if (!tableAlias) {\n throw new TypeORMError(`\"${table}\" is not part of this query`);\n }\n return qb.escape(tableAlias.name);\n }) : undefined;\n qb.setLock(options.lock.mode, undefined, tableNames);\n }\n }\n\n if (options.loadRelationIds === true) {\n qb.loadAllRelationIds();\n\n } else if (options.loadRelationIds instanceof Object) {\n qb.loadAllRelationIds(options.loadRelationIds as any);\n }\n\n if (options.where)\n qb.where(options.where);\n\n if ((options as FindManyOptions<T>).skip)\n qb.skip((options as FindManyOptions<T>).skip!);\n\n if ((options as FindManyOptions<T>).take)\n qb.take((options as FindManyOptions<T>).take!);\n\n if (options.order)\n Object.keys(options.order).forEach(key => {\n const order = ((options as FindOneOptions<T>).order as any)[key as any];\n\n if (!metadata.findColumnWithPropertyPath(key))\n throw new Error(`${key} column was not found in the ${metadata.name} entity.`);\n\n switch (order) {\n case 1:\n qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n break;\n case -1:\n qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n break;\n case \"ASC\":\n qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n break;\n case \"DESC\":\n qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n break;\n }\n });\n\n return qb;\n }*/\n\n static applyOptionsToTreeQueryBuilder<T extends ObjectLiteral>(\n qb: SelectQueryBuilder<T>,\n options?: FindTreeOptions,\n ): SelectQueryBuilder<T> {\n if (options?.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations]\n\n FindOptionsUtils.applyRelationsRecursively(\n qb,\n allRelations,\n qb.expressionMap.mainAlias!.name,\n qb.expressionMap.mainAlias!.metadata,\n \"\",\n )\n\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations)\n }\n\n return qb\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Adds joins for all relations and sub-relations of the given relations provided in the find options.\n */\n public static applyRelationsRecursively(\n qb: SelectQueryBuilder<any>,\n allRelations: string[],\n alias: string,\n metadata: EntityMetadata,\n prefix: string,\n ): void {\n // find all relations that match given prefix\n let matchedBaseRelations: RelationMetadata[] = []\n if (prefix) {\n const regexp = new RegExp(\"^\" + prefix.replace(\".\", \"\\\\.\") + \"\\\\.\")\n matchedBaseRelations = allRelations\n .filter((relation) => relation.match(regexp))\n .map((relation) =>\n metadata.findRelationWithPropertyPath(\n relation.replace(regexp, \"\"),\n ),\n )\n .filter((entity) => entity) as RelationMetadata[]\n } else {\n matchedBaseRelations = allRelations\n .map((relation) =>\n metadata.findRelationWithPropertyPath(relation),\n )\n .filter((entity) => entity) as RelationMetadata[]\n }\n\n // go through all matched relations and add join for them\n matchedBaseRelations.forEach((relation) => {\n // generate a relation alias\n let relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyPath,\n )\n\n // add a join for the found relation\n const selection = alias + \".\" + relation.propertyPath\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n qb.concatRelationMetadata(relation)\n } else {\n qb.leftJoinAndSelect(selection, relationAlias)\n }\n\n // remove added relations from the allRelations array, this is needed to find all not found relations at the end\n allRelations.splice(\n allRelations.indexOf(\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n ),\n 1,\n )\n\n // try to find sub-relations\n let relationMetadata: EntityMetadata | undefined\n let relationName: string | undefined\n\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n relationMetadata = relation.inverseEntityMetadata\n relationName = relationAlias\n } else {\n const join = qb.expressionMap.joinAttributes.find(\n (join) => join.entityOrProperty === selection,\n )\n relationMetadata = join!.metadata!\n relationName = join!.alias.name\n }\n\n if (!relationName || !relationMetadata) {\n throw new EntityPropertyNotFoundError(\n relation.propertyPath,\n metadata,\n )\n }\n\n this.applyRelationsRecursively(\n qb,\n allRelations,\n relationName,\n relationMetadata,\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n )\n\n // join the eager relations of the found relation\n // Only supported for \"join\" relationLoadStrategy\n if (qb.expressionMap.relationLoadStrategy === \"join\") {\n const relMetadata = metadata.relations.find(\n (metadata) =>\n metadata.propertyName === relation.propertyPath,\n )\n if (relMetadata) {\n this.joinEagerRelations(\n qb,\n relationAlias,\n relMetadata.inverseEntityMetadata,\n )\n }\n }\n })\n }\n\n public static joinEagerRelations(\n qb: SelectQueryBuilder<any>,\n alias: string,\n metadata: EntityMetadata,\n ) {\n metadata.eagerRelations.forEach((relation) => {\n // generate a relation alias\n let relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyPath,\n )\n\n // add a join for the relation\n // Checking whether the relation wasn't joined yet.\n let addJoin = true\n // TODO: Review this validation\n for (const join of qb.expressionMap.joinAttributes) {\n if (\n join.condition !== undefined ||\n join.mapToProperty !== undefined ||\n join.isMappingMany !== undefined ||\n join.direction !== \"LEFT\" ||\n join.entityOrProperty !==\n `${alias}.${relation.propertyPath}`\n ) {\n continue\n }\n addJoin = false\n relationAlias = join.alias.name\n break\n }\n\n const joinAlreadyAdded = Boolean(\n qb.expressionMap.joinAttributes.find(\n (joinAttribute) =>\n joinAttribute.alias.name === relationAlias,\n ),\n )\n\n if (addJoin && !joinAlreadyAdded) {\n qb.leftJoin(alias + \".\" + relation.propertyPath, relationAlias)\n }\n\n // Checking whether the relation wasn't selected yet.\n // This check shall be after the join check to detect relationAlias.\n let addSelect = true\n for (const select of qb.expressionMap.selects) {\n if (\n select.aliasName !== undefined ||\n select.virtual !== undefined ||\n select.selection !== relationAlias\n ) {\n continue\n }\n addSelect = false\n break\n }\n\n if (addSelect) {\n qb.addSelect(relationAlias)\n }\n\n // (recursive) join the eager relations\n this.joinEagerRelations(\n qb,\n relationAlias,\n relation.inverseEntityMetadata,\n )\n })\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/find-options/FindOptionsUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAInD,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AAEtD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACzB,4EAA4E;IAC5E,wBA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AI,KAAK,aAAa,CACjD,CACJ,CAAA;YAED,IAAI,OAAO,IAAI,CAAC,gBAAgB,EAAE;gBAC9B,EAAE,CAAC,QAAQ,CAAC,KAAK,GAAG,GAAG,GAAG,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,CAAA;aAClE;YAED,qDAAqD;YACrD,oEAAoE;YACpE,IAAI,SAAS,GAAG,IAAI,CAAA;YACpB,KAAK,MAAM,MAAM,IAAI,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE;gBAC3C,IACI,MAAM,CAAC,SAAS,KAAK,SAAS;oBAC9B,MAAM,CAAC,OAAO,KAAK,SAAS;oBAC5B,MAAM,CAAC,SAAS,KAAK,aAAa,EACpC;oBACE,SAAQ;iBACX;gBACD,SAAS,GAAG,KAAK,CAAA;gBACjB,MAAK;aACR;YAED,IAAI,SAAS,EAAE;gBACX,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;aAC9B;YAED,uCAAuC;YACvC,IAAI,CAAC,kBAAkB,CACnB,EAAE,EACF,aAAa,EACb,QAAQ,CAAC,qBAAqB,CACjC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"FindOptionsUtils.js","sourcesContent":["import { FindManyOptions } from \"./FindManyOptions\"\nimport { FindOneOptions } from \"./FindOneOptions\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { FindRelationsNotFoundError } from \"../error\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { FindTreeOptions } from \"./FindTreeOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { EntityPropertyNotFoundError } from \"../error\"\n\n/**\n * Utilities to work with FindOptions.\n */\nexport class FindOptionsUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if given object is really instance of FindOneOptions interface.\n */\n static isFindOneOptions<Entity = any>(\n obj: any,\n ): obj is FindOneOptions<Entity> {\n const possibleOptions: FindOneOptions<Entity> = obj\n return (\n possibleOptions &&\n (Array.isArray(possibleOptions.select) ||\n Array.isArray(possibleOptions.relations) ||\n typeof possibleOptions.select === \"object\" ||\n typeof possibleOptions.relations === \"object\" ||\n typeof possibleOptions.where === \"object\" ||\n // typeof possibleOptions.where === \"string\" ||\n typeof possibleOptions.join === \"object\" ||\n typeof possibleOptions.order === \"object\" ||\n typeof possibleOptions.cache === \"object\" ||\n typeof possibleOptions.cache === \"boolean\" ||\n typeof possibleOptions.cache === \"number\" ||\n typeof possibleOptions.comment === \"string\" ||\n typeof possibleOptions.lock === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"boolean\" ||\n typeof possibleOptions.loadEagerRelations === \"boolean\" ||\n typeof possibleOptions.withDeleted === \"boolean\" ||\n typeof possibleOptions.relationLoadStrategy === \"string\" ||\n typeof possibleOptions.transaction === \"boolean\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindManyOptions interface.\n */\n static isFindManyOptions<Entity = any>(\n obj: any,\n ): obj is FindManyOptions<Entity> {\n const possibleOptions: FindManyOptions<Entity> = obj\n return (\n possibleOptions &&\n (this.isFindOneOptions(possibleOptions) ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"string\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"string\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindOptions interface.\n */\n static extractFindManyOptionsAlias(object: any): string | undefined {\n if (this.isFindManyOptions(object) && object.join)\n return object.join.alias\n\n return undefined\n }\n\n /**\n * Applies give find many options to the given query builder.\n\n static applyFindManyOptionsOrConditionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindManyOptions<T>|Partial<T>|undefined): SelectQueryBuilder<T> {\n if (this.isFindManyOptions(options))\n return this.applyOptionsToQueryBuilder(qb, options);\n\n if (options)\n return qb.where(options);\n\n return qb;\n }*/\n\n /**\n * Applies give find options to the given query builder.\n\n static applyOptionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindOneOptions<T>|FindManyOptions<T>|undefined): SelectQueryBuilder<T> {\n\n // if options are not set then simply return query builder. This is made for simplicity of usage.\n if (!options || (!this.isFindOneOptions(options) && !this.isFindManyOptions(options)))\n return qb;\n\n if (options.transaction === true) {\n qb.expressionMap.useTransaction = true;\n }\n\n if (!qb.expressionMap.mainAlias || !qb.expressionMap.mainAlias.hasMetadata)\n return qb;\n\n const metadata = qb.expressionMap.mainAlias!.metadata;\n\n // apply all options from FindOptions\n if (options.comment) {\n qb.comment(options.comment);\n }\n\n if (options.withDeleted) {\n qb.withDeleted();\n }\n\n if (options.select) {\n qb.select([]);\n options.select.forEach(select => {\n if (!metadata.hasColumnWithPropertyPath(`${select}`))\n throw new TypeORMError(`${select} column was not found in the ${metadata.name} entity.`);\n\n const columns = metadata.findColumnsWithPropertyPath(`${select}`);\n\n for (const column of columns) {\n qb.addSelect(qb.alias + \".\" + column.propertyPath);\n }\n });\n }\n\n if (options.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations];\n this.applyRelationsRecursively(qb, allRelations, qb.expressionMap.mainAlias!.name, qb.expressionMap.mainAlias!.metadata, \"\");\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations);\n }\n\n if (options.join) {\n if (options.join.leftJoin)\n Object.keys(options.join.leftJoin).forEach(key => {\n qb.leftJoin(options.join!.leftJoin![key], key);\n });\n\n if (options.join.innerJoin)\n Object.keys(options.join.innerJoin).forEach(key => {\n qb.innerJoin(options.join!.innerJoin![key], key);\n });\n\n if (options.join.leftJoinAndSelect)\n Object.keys(options.join.leftJoinAndSelect).forEach(key => {\n qb.leftJoinAndSelect(options.join!.leftJoinAndSelect![key], key);\n });\n\n if (options.join.innerJoinAndSelect)\n Object.keys(options.join.innerJoinAndSelect).forEach(key => {\n qb.innerJoinAndSelect(options.join!.innerJoinAndSelect![key], key);\n });\n }\n\n if (options.cache) {\n if (options.cache instanceof Object) {\n const cache = options.cache as { id: any, milliseconds: number };\n qb.cache(cache.id, cache.milliseconds);\n } else {\n qb.cache(options.cache);\n }\n }\n\n if (options.lock) {\n if (options.lock.mode === \"optimistic\") {\n qb.setLock(options.lock.mode, options.lock.version);\n } else if (\n options.lock.mode === \"pessimistic_read\" ||\n options.lock.mode === \"pessimistic_write\" ||\n options.lock.mode === \"dirty_read\" ||\n options.lock.mode === \"pessimistic_partial_write\" ||\n options.lock.mode === \"pessimistic_write_or_fail\" ||\n options.lock.mode === \"for_no_key_update\" ||\n options.lock.mode === \"for_key_share\"\n ) {\n const tableNames = options.lock.tables ? options.lock.tables.map((table) => {\n const tableAlias = qb.expressionMap.aliases.find((alias) => {\n return alias.metadata.tableNameWithoutPrefix === table;\n });\n if (!tableAlias) {\n throw new TypeORMError(`\"${table}\" is not part of this query`);\n }\n return qb.escape(tableAlias.name);\n }) : undefined;\n qb.setLock(options.lock.mode, undefined, tableNames);\n }\n }\n\n if (options.loadRelationIds === true) {\n qb.loadAllRelationIds();\n\n } else if (options.loadRelationIds instanceof Object) {\n qb.loadAllRelationIds(options.loadRelationIds as any);\n }\n\n if (options.where)\n qb.where(options.where);\n\n if ((options as FindManyOptions<T>).skip)\n qb.skip((options as FindManyOptions<T>).skip!);\n\n if ((options as FindManyOptions<T>).take)\n qb.take((options as FindManyOptions<T>).take!);\n\n if (options.order)\n Object.keys(options.order).forEach(key => {\n const order = ((options as FindOneOptions<T>).order as any)[key as any];\n\n if (!metadata.findColumnWithPropertyPath(key))\n throw new Error(`${key} column was not found in the ${metadata.name} entity.`);\n\n switch (order) {\n case 1:\n qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n break;\n case -1:\n qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n break;\n case \"ASC\":\n qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n break;\n case \"DESC\":\n qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n break;\n }\n });\n\n return qb;\n }*/\n\n static applyOptionsToTreeQueryBuilder<T extends ObjectLiteral>(\n qb: SelectQueryBuilder<T>,\n options?: FindTreeOptions,\n ): SelectQueryBuilder<T> {\n if (options?.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations]\n\n FindOptionsUtils.applyRelationsRecursively(\n qb,\n allRelations,\n qb.expressionMap.mainAlias!.name,\n qb.expressionMap.mainAlias!.metadata,\n \"\",\n )\n\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations)\n }\n\n return qb\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Adds joins for all relations and sub-relations of the given relations provided in the find options.\n */\n public static applyRelationsRecursively(\n qb: SelectQueryBuilder<any>,\n allRelations: string[],\n alias: string,\n metadata: EntityMetadata,\n prefix: string,\n ): void {\n // find all relations that match given prefix\n let matchedBaseRelations: RelationMetadata[] = []\n if (prefix) {\n const regexp = new RegExp(\"^\" + prefix.replace(\".\", \"\\\\.\") + \"\\\\.\")\n matchedBaseRelations = allRelations\n .filter((relation) => relation.match(regexp))\n .map((relation) =>\n metadata.findRelationWithPropertyPath(\n relation.replace(regexp, \"\"),\n ),\n )\n .filter((entity) => entity) as RelationMetadata[]\n } else {\n matchedBaseRelations = allRelations\n .map((relation) =>\n metadata.findRelationWithPropertyPath(relation),\n )\n .filter((entity) => entity) as RelationMetadata[]\n }\n\n // go through all matched relations and add join for them\n matchedBaseRelations.forEach((relation) => {\n // generate a relation alias\n let relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyPath,\n )\n\n // add a join for the found relation\n const selection = alias + \".\" + relation.propertyPath\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n qb.concatRelationMetadata(relation)\n } else {\n qb.leftJoinAndSelect(selection, relationAlias)\n }\n\n // remove added relations from the allRelations array, this is needed to find all not found relations at the end\n allRelations.splice(\n allRelations.indexOf(\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n ),\n 1,\n )\n\n // try to find sub-relations\n let relationMetadata: EntityMetadata | undefined\n let relationName: string | undefined\n\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n relationMetadata = relation.inverseEntityMetadata\n relationName = relationAlias\n } else {\n const join = qb.expressionMap.joinAttributes.find(\n (join) => join.entityOrProperty === selection,\n )\n relationMetadata = join!.metadata!\n relationName = join!.alias.name\n }\n\n if (!relationName || !relationMetadata) {\n throw new EntityPropertyNotFoundError(\n relation.propertyPath,\n metadata,\n )\n }\n\n this.applyRelationsRecursively(\n qb,\n allRelations,\n relationName,\n relationMetadata,\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n )\n\n // join the eager relations of the found relation\n // Only supported for \"join\" relationLoadStrategy\n if (qb.expressionMap.relationLoadStrategy === \"join\") {\n const relMetadata = metadata.relations.find(\n (metadata) =>\n metadata.propertyName === relation.propertyPath,\n )\n if (relMetadata) {\n this.joinEagerRelations(\n qb,\n relationAlias,\n relMetadata.inverseEntityMetadata,\n )\n }\n }\n })\n }\n\n public static joinEagerRelations(\n qb: SelectQueryBuilder<any>,\n alias: string,\n metadata: EntityMetadata,\n ) {\n metadata.eagerRelations.forEach((relation) => {\n // generate a relation alias\n let relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyName,\n )\n\n // add a join for the relation\n // Checking whether the relation wasn't joined yet.\n let addJoin = true\n // TODO: Review this validation\n for (const join of qb.expressionMap.joinAttributes) {\n if (\n join.condition !== undefined ||\n join.mapToProperty !== undefined ||\n join.isMappingMany !== undefined ||\n join.direction !== \"LEFT\" ||\n join.entityOrProperty !==\n `${alias}.${relation.propertyPath}`\n ) {\n continue\n }\n addJoin = false\n relationAlias = join.alias.name\n break\n }\n\n const joinAlreadyAdded = Boolean(\n qb.expressionMap.joinAttributes.find(\n (joinAttribute) =>\n joinAttribute.alias.name === relationAlias,\n ),\n )\n\n if (addJoin && !joinAlreadyAdded) {\n qb.leftJoin(alias + \".\" + relation.propertyPath, relationAlias)\n }\n\n // Checking whether the relation wasn't selected yet.\n // This check shall be after the join check to detect relationAlias.\n let addSelect = true\n for (const select of qb.expressionMap.selects) {\n if (\n select.aliasName !== undefined ||\n select.virtual !== undefined ||\n select.selection !== relationAlias\n ) {\n continue\n }\n addSelect = false\n break\n }\n\n if (addSelect) {\n qb.addSelect(relationAlias)\n }\n\n // (recursive) join the eager relations\n this.joinEagerRelations(\n qb,\n relationAlias,\n relation.inverseEntityMetadata,\n )\n })\n }\n}\n"],"sourceRoot":".."}
@@ -40,7 +40,6 @@ export declare class DefaultNamingStrategy implements NamingStrategyInterface {
40
40
  * Note that table name comes here already normalized by #tableName method.
41
41
  */
42
42
  prefixTableName(prefix: string, tableName: string): string;
43
- eagerJoinRelationAlias(alias: string, propertyPath: string): string;
44
43
  nestedSetColumnNames: {
45
44
  left: string;
46
45
  right: string;
@@ -136,9 +136,6 @@ export class DefaultNamingStrategy {
136
136
  prefixTableName(prefix, tableName) {
137
137
  return prefix + tableName;
138
138
  }
139
- eagerJoinRelationAlias(alias, propertyPath) {
140
- return alias + "_" + propertyPath.replace(".", "_");
141
- }
142
139
  }
143
140
 
144
141
  //# sourceMappingURL=DefaultNamingStrategy.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/naming-strategy/DefaultNamingStrategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,S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,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAC3D,CAAC;IAED,cAAc,CAAC,YAAoB,EAAE,oBAA4B;QAC7D,OAAO,SAAS,CAAC,YAAY,GAAG,GAAG,GAAG,oBAAoB,CAAC,CAAA;IAC/D,CAAC;IAED,aAAa,CACT,cAAsB,EACtB,eAAuB,EACvB,iBAAyB,EACzB,kBAA0B;QAE1B,OAAO,SAAS,CACZ,cAAc;YACV,GAAG;YACH,iBAAiB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;YACtC,GAAG;YACH,eAAe,CACtB,CAAA;IACL,CAAC;IAED,gCAAgC,CAC5B,UAAkB,EAClB,KAAa;QAEb,OAAO,UAAU,GAAG,GAAG,GAAG,KAAK,CAAA;IACnC,CAAC;IAED,mBAAmB,CACf,SAAiB,EACjB,YAAoB,EACpB,UAAmB;QAEnB,OAAO,SAAS,CACZ,SAAS,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAC7D,CAAA;IACL,CAAC;IAED,0BAA0B,CACtB,SAAiB,EACjB,YAAoB,EACpB,UAAmB;QAEnB,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;IACxE,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,MAAc,EAAE,SAAiB;QAC7C,OAAO,MAAM,GAAG,SAAS,CAAA;IAC7B,CAAC;IAED,sBAAsB,CAAC,KAAa,EAAE,YAAoB;QACtD,OAAO,KAAK,GAAG,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACvD,CAAC;CAIJ","file":"DefaultNamingStrategy.js","sourcesContent":["import { NamingStrategyInterface } from \"./NamingStrategyInterface\"\nimport { RandomGenerator } from \"../util/RandomGenerator\"\nimport { camelCase, snakeCase, titleCase } from \"../util/StringUtils\"\nimport { Table } from \"../schema-builder/table/Table\"\n\n/**\n * Naming strategy that is used by default.\n */\nexport class DefaultNamingStrategy implements NamingStrategyInterface {\n protected getTableName(tableOrName: Table | string): string {\n if (typeof tableOrName !== \"string\") {\n tableOrName = tableOrName.name\n }\n\n return tableOrName.split(\".\").pop()!\n }\n /**\n * Normalizes table name.\n *\n * @param targetName Name of the target entity that can be used to generate a table name.\n * @param userSpecifiedName For example if user specified a table name in a decorator, e.g. @Entity(\"name\")\n */\n tableName(\n targetName: string,\n userSpecifiedName: string | undefined,\n ): string {\n return userSpecifiedName ? userSpecifiedName : snakeCase(targetName)\n }\n\n /**\n * Creates a table name for a junction table of a closure table.\n *\n * @param originalClosureTableName Name of the closure table which owns this junction table.\n */\n closureJunctionTableName(originalClosureTableName: string): string {\n return originalClosureTableName + \"_closure\"\n }\n\n columnName(\n propertyName: string,\n customName: string,\n embeddedPrefixes: string[],\n ): string {\n const name = customName || propertyName\n\n if (embeddedPrefixes.length)\n return camelCase(embeddedPrefixes.join(\"_\")) + titleCase(name)\n\n return name\n }\n\n relationName(propertyName: string): string {\n return propertyName\n }\n\n primaryKeyName(tableOrName: Table | string, columnNames: string[]): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n return \"PK_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n uniqueConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n return \"UQ_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n relationConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n where?: string,\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n let key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n if (where) key += `_${where}`\n\n return \"REL_\" + RandomGenerator.sha1(key).substr(0, 26)\n }\n\n defaultConstraintName(\n tableOrName: Table | string,\n columnName: string,\n ): string {\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${columnName}`\n return \"DF_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n foreignKeyName(\n tableOrName: Table | string,\n columnNames: string[],\n _referencedTablePath?: string,\n _referencedColumnNames?: string[],\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n return \"FK_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n indexName(\n tableOrName: Table | string,\n columnNames: string[],\n where?: string,\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n let key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n if (where) key += `_${where}`\n\n return \"IDX_\" + RandomGenerator.sha1(key).substr(0, 26)\n }\n\n checkConstraintName(\n tableOrName: Table | string,\n expression: string,\n isEnum?: boolean,\n ): string {\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${expression}`\n const name = \"CHK_\" + RandomGenerator.sha1(key).substr(0, 26)\n return isEnum ? `${name}_ENUM` : name\n }\n\n exclusionConstraintName(\n tableOrName: Table | string,\n expression: string,\n ): string {\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${expression}`\n return \"XCL_\" + RandomGenerator.sha1(key).substr(0, 26)\n }\n\n joinColumnName(relationName: string, referencedColumnName: string): string {\n return camelCase(relationName + \"_\" + referencedColumnName)\n }\n\n joinTableName(\n firstTableName: string,\n secondTableName: string,\n firstPropertyName: string,\n secondPropertyName: string,\n ): string {\n return snakeCase(\n firstTableName +\n \"_\" +\n firstPropertyName.replace(/\\./gi, \"_\") +\n \"_\" +\n secondTableName,\n )\n }\n\n joinTableColumnDuplicationPrefix(\n columnName: string,\n index: number,\n ): string {\n return columnName + \"_\" + index\n }\n\n joinTableColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string {\n return camelCase(\n tableName + \"_\" + (columnName ? columnName : propertyName),\n )\n }\n\n joinTableInverseColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string {\n return this.joinTableColumnName(tableName, propertyName, columnName)\n }\n\n /**\n * Adds globally set prefix to the table name.\n * This method is executed no matter if prefix was set or not.\n * Table name is either user's given table name, either name generated from entity target.\n * Note that table name comes here already normalized by #tableName method.\n */\n prefixTableName(prefix: string, tableName: string): string {\n return prefix + tableName\n }\n\n eagerJoinRelationAlias(alias: string, propertyPath: string): string {\n return alias + \"_\" + propertyPath.replace(\".\", \"_\")\n }\n\n nestedSetColumnNames = { left: \"nsleft\", right: \"nsright\" }\n materializedPathColumnName = \"mpath\"\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/naming-strategy/DefaultNamingStrategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,SAAS,EA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,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAC3D,CAAC;IAED,cAAc,CAAC,YAAoB,EAAE,oBAA4B;QAC7D,OAAO,SAAS,CAAC,YAAY,GAAG,GAAG,GAAG,oBAAoB,CAAC,CAAA;IAC/D,CAAC;IAED,aAAa,CACT,cAAsB,EACtB,eAAuB,EACvB,iBAAyB,EACzB,kBAA0B;QAE1B,OAAO,SAAS,CACZ,cAAc;YACV,GAAG;YACH,iBAAiB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;YACtC,GAAG;YACH,eAAe,CACtB,CAAA;IACL,CAAC;IAED,gCAAgC,CAC5B,UAAkB,EAClB,KAAa;QAEb,OAAO,UAAU,GAAG,GAAG,GAAG,KAAK,CAAA;IACnC,CAAC;IAED,mBAAmB,CACf,SAAiB,EACjB,YAAoB,EACpB,UAAmB;QAEnB,OAAO,SAAS,CACZ,SAAS,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAC7D,CAAA;IACL,CAAC;IAED,0BAA0B,CACtB,SAAiB,EACjB,YAAoB,EACpB,UAAmB;QAEnB,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;IACxE,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,MAAc,EAAE,SAAiB;QAC7C,OAAO,MAAM,GAAG,SAAS,CAAA;IAC7B,CAAC;CAIJ","file":"DefaultNamingStrategy.js","sourcesContent":["import { NamingStrategyInterface } from \"./NamingStrategyInterface\"\nimport { RandomGenerator } from \"../util/RandomGenerator\"\nimport { camelCase, snakeCase, titleCase } from \"../util/StringUtils\"\nimport { Table } from \"../schema-builder/table/Table\"\n\n/**\n * Naming strategy that is used by default.\n */\nexport class DefaultNamingStrategy implements NamingStrategyInterface {\n protected getTableName(tableOrName: Table | string): string {\n if (typeof tableOrName !== \"string\") {\n tableOrName = tableOrName.name\n }\n\n return tableOrName.split(\".\").pop()!\n }\n /**\n * Normalizes table name.\n *\n * @param targetName Name of the target entity that can be used to generate a table name.\n * @param userSpecifiedName For example if user specified a table name in a decorator, e.g. @Entity(\"name\")\n */\n tableName(\n targetName: string,\n userSpecifiedName: string | undefined,\n ): string {\n return userSpecifiedName ? userSpecifiedName : snakeCase(targetName)\n }\n\n /**\n * Creates a table name for a junction table of a closure table.\n *\n * @param originalClosureTableName Name of the closure table which owns this junction table.\n */\n closureJunctionTableName(originalClosureTableName: string): string {\n return originalClosureTableName + \"_closure\"\n }\n\n columnName(\n propertyName: string,\n customName: string,\n embeddedPrefixes: string[],\n ): string {\n const name = customName || propertyName\n\n if (embeddedPrefixes.length)\n return camelCase(embeddedPrefixes.join(\"_\")) + titleCase(name)\n\n return name\n }\n\n relationName(propertyName: string): string {\n return propertyName\n }\n\n primaryKeyName(tableOrName: Table | string, columnNames: string[]): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n return \"PK_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n uniqueConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n return \"UQ_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n relationConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n where?: string,\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n let key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n if (where) key += `_${where}`\n\n return \"REL_\" + RandomGenerator.sha1(key).substr(0, 26)\n }\n\n defaultConstraintName(\n tableOrName: Table | string,\n columnName: string,\n ): string {\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${columnName}`\n return \"DF_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n foreignKeyName(\n tableOrName: Table | string,\n columnNames: string[],\n _referencedTablePath?: string,\n _referencedColumnNames?: string[],\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n return \"FK_\" + RandomGenerator.sha1(key).substr(0, 27)\n }\n\n indexName(\n tableOrName: Table | string,\n columnNames: string[],\n where?: string,\n ): string {\n // sort incoming column names to avoid issue when [\"id\", \"name\"] and [\"name\", \"id\"] arrays\n const clonedColumnNames = [...columnNames]\n clonedColumnNames.sort()\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n let key = `${replacedTableName}_${clonedColumnNames.join(\"_\")}`\n if (where) key += `_${where}`\n\n return \"IDX_\" + RandomGenerator.sha1(key).substr(0, 26)\n }\n\n checkConstraintName(\n tableOrName: Table | string,\n expression: string,\n isEnum?: boolean,\n ): string {\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${expression}`\n const name = \"CHK_\" + RandomGenerator.sha1(key).substr(0, 26)\n return isEnum ? `${name}_ENUM` : name\n }\n\n exclusionConstraintName(\n tableOrName: Table | string,\n expression: string,\n ): string {\n const tableName = this.getTableName(tableOrName)\n const replacedTableName = tableName.replace(\".\", \"_\")\n const key = `${replacedTableName}_${expression}`\n return \"XCL_\" + RandomGenerator.sha1(key).substr(0, 26)\n }\n\n joinColumnName(relationName: string, referencedColumnName: string): string {\n return camelCase(relationName + \"_\" + referencedColumnName)\n }\n\n joinTableName(\n firstTableName: string,\n secondTableName: string,\n firstPropertyName: string,\n secondPropertyName: string,\n ): string {\n return snakeCase(\n firstTableName +\n \"_\" +\n firstPropertyName.replace(/\\./gi, \"_\") +\n \"_\" +\n secondTableName,\n )\n }\n\n joinTableColumnDuplicationPrefix(\n columnName: string,\n index: number,\n ): string {\n return columnName + \"_\" + index\n }\n\n joinTableColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string {\n return camelCase(\n tableName + \"_\" + (columnName ? columnName : propertyName),\n )\n }\n\n joinTableInverseColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string {\n return this.joinTableColumnName(tableName, propertyName, columnName)\n }\n\n /**\n * Adds globally set prefix to the table name.\n * This method is executed no matter if prefix was set or not.\n * Table name is either user's given table name, either name generated from entity target.\n * Note that table name comes here already normalized by #tableName method.\n */\n prefixTableName(prefix: string, tableName: string): string {\n return prefix + tableName\n }\n\n nestedSetColumnNames = { left: \"nsleft\", right: \"nsright\" }\n materializedPathColumnName = \"mpath\"\n}\n"],"sourceRoot":".."}
@@ -99,10 +99,6 @@ export interface NamingStrategyInterface {
99
99
  * Note that table name comes here already normalized by #tableName method.
100
100
  */
101
101
  prefixTableName(prefix: string, tableName: string): string;
102
- /**
103
- * Gets the name of the alias used for relation joins.
104
- */
105
- eagerJoinRelationAlias(alias: string, propertyPath: string): string;
106
102
  /**
107
103
  * Column names for nested sets.
108
104
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/naming-strategy/NamingStrategyInterface.ts"],"names":[],"mappings":"","file":"NamingStrategyInterface.js","sourcesContent":["import { Table } from \"../schema-builder/table/Table\"\nimport { View } from \"../schema-builder/view/View\"\n\n/**\n * Naming strategy defines how auto-generated names for such things like table name, or table column gonna be\n * generated.\n */\nexport interface NamingStrategyInterface {\n /**\n * Naming strategy name.\n */\n name?: string\n\n /**\n * Normalizes table name.\n *\n * @param targetName Name of the target entity that can be used to generate a table name.\n * @param userSpecifiedName For example if user specified a table name in a decorator, e.g. @Entity(\"name\")\n */\n tableName(targetName: string, userSpecifiedName: string | undefined): string\n\n /**\n * Creates a table name for a junction table of a closure table.\n *\n * @param originalClosureTableName Name of the closure table which owns this junction table.\n */\n closureJunctionTableName(originalClosureTableName: string): string\n\n /**\n * Gets the table's column name from the given property name.\n */\n columnName(\n propertyName: string,\n customName: string | undefined,\n embeddedPrefixes: string[],\n ): string\n\n /**\n * Gets the table's relation name from the given property name.\n */\n relationName(propertyName: string): string\n\n /**\n * Gets the table's primary key name from the given table name and column names.\n */\n primaryKeyName(tableOrName: Table | string, columnNames: string[]): string\n\n /**\n * Gets the table's unique constraint name from the given table name and column names.\n */\n uniqueConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n ): string\n\n /**\n * Gets the relation constraint (UNIQUE or UNIQUE INDEX) name from the given table name, column names\n * and WHERE condition, if UNIQUE INDEX used.\n */\n relationConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n where?: string,\n ): string\n\n /**\n * Gets the table's default constraint name from the given table name and column name.\n */\n defaultConstraintName(\n tableOrName: Table | string,\n columnName: string,\n ): string\n\n /**\n * Gets the name of the foreign key.\n */\n foreignKeyName(\n tableOrName: Table | string,\n columnNames: string[],\n referencedTablePath?: string,\n referencedColumnNames?: string[],\n ): string\n\n /**\n * Gets the name of the index - simple and compose index.\n */\n indexName(\n tableOrName: Table | View | string,\n columns: string[],\n where?: string,\n ): string\n\n /**\n * Gets the name of the check constraint.\n *\n * \"isEnum\" parameter is used to indicate if this check constraint used\n * to handle \"simple-enum\" type for databases that are not supporting \"enum\"\n * type out of the box. If \"true\", constraint is ignored during CHECK constraints\n * synchronization.\n */\n checkConstraintName(\n tableOrName: Table | string,\n expression: string,\n isEnum?: boolean,\n ): string\n\n /**\n * Gets the name of the exclusion constraint.\n */\n exclusionConstraintName(\n tableOrName: Table | string,\n expression: string,\n ): string\n\n /**\n * Gets the name of the join column used in the one-to-one and many-to-one relations.\n */\n joinColumnName(relationName: string, referencedColumnName: string): string\n\n /**\n * Gets the name of the join table used in the many-to-many relations.\n */\n joinTableName(\n firstTableName: string,\n secondTableName: string,\n firstPropertyName: string,\n secondPropertyName: string,\n ): string\n\n /**\n * Columns in join tables can have duplicate names in case of self-referencing.\n * This method provide a resolution for such column names.\n */\n joinTableColumnDuplicationPrefix(columnName: string, index: number): string\n\n /**\n * Gets the name of the column used for columns in the junction tables.\n *\n * The reverse?:boolean parameter denotes if the joinTableColumnName is called for the junctionColumn (false)\n * or the inverseJunctionColumns (true)\n */\n joinTableColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string\n\n /**\n * Gets the name of the column used for columns in the junction tables from the invers side of the relationship.\n */\n joinTableInverseColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string\n\n /**\n * Adds globally set prefix to the table name.\n * This method is executed no matter if prefix was set or not.\n * Table name is either user's given table name, either name generated from entity target.\n * Note that table name comes here already normalized by #tableName method.\n */\n prefixTableName(prefix: string, tableName: string): string\n\n /**\n * Gets the name of the alias used for relation joins.\n */\n eagerJoinRelationAlias(alias: string, propertyPath: string): string\n\n /**\n * Column names for nested sets.\n */\n nestedSetColumnNames: { left: string; right: string }\n\n /**\n * Column name for materialized paths.\n */\n materializedPathColumnName: string\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/naming-strategy/NamingStrategyInterface.ts"],"names":[],"mappings":"","file":"NamingStrategyInterface.js","sourcesContent":["import { Table } from \"../schema-builder/table/Table\"\nimport { View } from \"../schema-builder/view/View\"\n\n/**\n * Naming strategy defines how auto-generated names for such things like table name, or table column gonna be\n * generated.\n */\nexport interface NamingStrategyInterface {\n /**\n * Naming strategy name.\n */\n name?: string\n\n /**\n * Normalizes table name.\n *\n * @param targetName Name of the target entity that can be used to generate a table name.\n * @param userSpecifiedName For example if user specified a table name in a decorator, e.g. @Entity(\"name\")\n */\n tableName(targetName: string, userSpecifiedName: string | undefined): string\n\n /**\n * Creates a table name for a junction table of a closure table.\n *\n * @param originalClosureTableName Name of the closure table which owns this junction table.\n */\n closureJunctionTableName(originalClosureTableName: string): string\n\n /**\n * Gets the table's column name from the given property name.\n */\n columnName(\n propertyName: string,\n customName: string | undefined,\n embeddedPrefixes: string[],\n ): string\n\n /**\n * Gets the table's relation name from the given property name.\n */\n relationName(propertyName: string): string\n\n /**\n * Gets the table's primary key name from the given table name and column names.\n */\n primaryKeyName(tableOrName: Table | string, columnNames: string[]): string\n\n /**\n * Gets the table's unique constraint name from the given table name and column names.\n */\n uniqueConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n ): string\n\n /**\n * Gets the relation constraint (UNIQUE or UNIQUE INDEX) name from the given table name, column names\n * and WHERE condition, if UNIQUE INDEX used.\n */\n relationConstraintName(\n tableOrName: Table | string,\n columnNames: string[],\n where?: string,\n ): string\n\n /**\n * Gets the table's default constraint name from the given table name and column name.\n */\n defaultConstraintName(\n tableOrName: Table | string,\n columnName: string,\n ): string\n\n /**\n * Gets the name of the foreign key.\n */\n foreignKeyName(\n tableOrName: Table | string,\n columnNames: string[],\n referencedTablePath?: string,\n referencedColumnNames?: string[],\n ): string\n\n /**\n * Gets the name of the index - simple and compose index.\n */\n indexName(\n tableOrName: Table | View | string,\n columns: string[],\n where?: string,\n ): string\n\n /**\n * Gets the name of the check constraint.\n *\n * \"isEnum\" parameter is used to indicate if this check constraint used\n * to handle \"simple-enum\" type for databases that are not supporting \"enum\"\n * type out of the box. If \"true\", constraint is ignored during CHECK constraints\n * synchronization.\n */\n checkConstraintName(\n tableOrName: Table | string,\n expression: string,\n isEnum?: boolean,\n ): string\n\n /**\n * Gets the name of the exclusion constraint.\n */\n exclusionConstraintName(\n tableOrName: Table | string,\n expression: string,\n ): string\n\n /**\n * Gets the name of the join column used in the one-to-one and many-to-one relations.\n */\n joinColumnName(relationName: string, referencedColumnName: string): string\n\n /**\n * Gets the name of the join table used in the many-to-many relations.\n */\n joinTableName(\n firstTableName: string,\n secondTableName: string,\n firstPropertyName: string,\n secondPropertyName: string,\n ): string\n\n /**\n * Columns in join tables can have duplicate names in case of self-referencing.\n * This method provide a resolution for such column names.\n */\n joinTableColumnDuplicationPrefix(columnName: string, index: number): string\n\n /**\n * Gets the name of the column used for columns in the junction tables.\n *\n * The reverse?:boolean parameter denotes if the joinTableColumnName is called for the junctionColumn (false)\n * or the inverseJunctionColumns (true)\n */\n joinTableColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string\n\n /**\n * Gets the name of the column used for columns in the junction tables from the invers side of the relationship.\n */\n joinTableInverseColumnName(\n tableName: string,\n propertyName: string,\n columnName?: string,\n ): string\n\n /**\n * Adds globally set prefix to the table name.\n * This method is executed no matter if prefix was set or not.\n * Table name is either user's given table name, either name generated from entity target.\n * Note that table name comes here already normalized by #tableName method.\n */\n prefixTableName(prefix: string, tableName: string): string\n\n /**\n * Column names for nested sets.\n */\n nestedSetColumnNames: { left: string; right: string }\n\n /**\n * Column name for materialized paths.\n */\n materializedPathColumnName: string\n}\n"],"sourceRoot":".."}
@@ -115,7 +115,8 @@ export class Subject {
115
115
  (this.databaseEntityLoaded === false ||
116
116
  (this.databaseEntityLoaded && this.databaseEntity)) &&
117
117
  // ((this.entity && this.databaseEntity) || (!this.entity && !this.databaseEntity)) &&
118
- this.changeMaps.length > 0);
118
+ // ensure there are one or more changes for updatable columns
119
+ this.changeMaps.some((change) => !change.column || change.column.isUpdate));
119
120
  }
120
121
  /**
121
122
  * Checks if this subject must be soft-removed into the database.
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/persistence/Subject.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAG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ACpB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;oBACnD,IACI,aAAa,CAAC,gBAAgB;wBAC9B,aAAa,CAAC,gBAAgB,CAAC,qBAAqB;4BAChD,IAAI,CAAC,aAAc,CAAC,QAAQ,EAClC;wBACE,MAAM,KAAK,GACP,aAAa,CAAC,gBAAiB,CAAC,cAAc,CAC1C,IAAI,CAAC,aAAc,CAAC,MAAO,CAC9B,CAAA;wBACL,aAAa,CAAC,cAAc,CACxB,IAAI,CAAC,sBAAuB,EAC5B,KAAK,CACR,CAAA;qBACJ;gBACL,CAAC,CAAC,CAAA;aACL;YACD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAC1C,IAAI,CAAC,sBAAsB,CAC9B,CAAA;SACJ;aAAM,IAAI,IAAI,CAAC,cAAc,EAAE;YAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SACtE;IACL,CAAC;CACJ","file":"Subject.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { SubjectChangeMap } from \"./SubjectChangeMap\"\nimport { OrmUtils } from \"../util/OrmUtils\"\nimport { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Subject is a subject of persistence.\n * It holds information about each entity that needs to be persisted:\n * - what entity should be persisted\n * - what is database representation of the persisted entity\n * - what entity metadata of the persisted entity\n * - what is allowed to with persisted entity (insert/update/remove)\n *\n * Having this collection of subjects we can perform database queries.\n */\nexport class Subject {\n readonly \"@instanceof\" = Symbol.for(\"Subject\")\n\n // -------------------------------------------------------------------------\n // Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the subject entity.\n */\n metadata: EntityMetadata\n\n /**\n * Subject identifier.\n * This identifier is not limited to table entity primary columns.\n * This can be entity id or ids as well as some unique entity properties, like name or title.\n * Insert / Update / Remove operation will be executed by a given identifier.\n */\n identifier: ObjectLiteral | undefined = undefined\n\n /**\n * Copy of entity but with relational ids fulfilled.\n */\n entityWithFulfilledIds: ObjectLiteral | undefined = undefined\n\n /**\n * If subject was created by cascades this property will contain subject\n * from where this subject was created.\n */\n parentSubject?: Subject\n\n /**\n * Gets entity sent to the persistence (e.g. changed entity).\n * If entity is not set then this subject is created only for the entity loaded from the database,\n * or this subject is used for the junction operation (junction operations are relying only on identifier).\n */\n entity?: ObjectLiteral\n\n /**\n * Database entity.\n * THIS IS NOT RAW ENTITY DATA, its a real entity.\n */\n databaseEntity?: ObjectLiteral\n\n /**\n * Indicates if database entity was loaded.\n * No matter if it was found or not, it indicates the fact of loading.\n */\n databaseEntityLoaded: boolean = false\n\n /**\n * Changes needs to be applied in the database for the given subject.\n */\n changeMaps: SubjectChangeMap[] = []\n\n /**\n * Generated values returned by a database (for example generated id or default values).\n * Used in insert and update operations.\n * Has entity-like structure (not just column database name and values).\n */\n generatedMap?: ObjectLiteral\n\n /**\n * Inserted values with updated values of special and default columns.\n * Has entity-like structure (not just column database name and values).\n */\n insertedValueSet?: ObjectLiteral\n\n /**\n * Indicates if this subject can be inserted into the database.\n * This means that this subject either is newly persisted, either can be inserted by cascades.\n */\n canBeInserted: boolean = false\n\n /**\n * Indicates if this subject can be updated in the database.\n * This means that this subject either was persisted, either can be updated by cascades.\n */\n canBeUpdated: boolean = false\n\n /**\n * Indicates if this subject MUST be removed from the database.\n * This means that this subject either was removed, either was removed by cascades.\n */\n mustBeRemoved: boolean = false\n\n /**\n * Indicates if this subject can be soft-removed from the database.\n * This means that this subject either was soft-removed, either was soft-removed by cascades.\n */\n canBeSoftRemoved: boolean = false\n\n /**\n * Indicates if this subject can be recovered from the database.\n * This means that this subject either was recovered, either was recovered by cascades.\n */\n canBeRecovered: boolean = false\n\n /**\n * Relations updated by the change maps.\n */\n updatedRelationMaps: {\n relation: RelationMetadata\n value: ObjectLiteral\n }[] = []\n\n /**\n * List of updated columns\n */\n diffColumns: ColumnMetadata[] = []\n\n /**\n * List of updated relations\n */\n diffRelations: RelationMetadata[] = []\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: {\n metadata: EntityMetadata\n parentSubject?: Subject\n entity?: ObjectLiteral\n canBeInserted?: boolean\n canBeUpdated?: boolean\n mustBeRemoved?: boolean\n canBeSoftRemoved?: boolean\n canBeRecovered?: boolean\n identifier?: ObjectLiteral\n changeMaps?: SubjectChangeMap[]\n }) {\n this.metadata = options.metadata\n this.entity = options.entity\n this.parentSubject = options.parentSubject\n if (options.canBeInserted !== undefined)\n this.canBeInserted = options.canBeInserted\n if (options.canBeUpdated !== undefined)\n this.canBeUpdated = options.canBeUpdated\n if (options.mustBeRemoved !== undefined)\n this.mustBeRemoved = options.mustBeRemoved\n if (options.canBeSoftRemoved !== undefined)\n this.canBeSoftRemoved = options.canBeSoftRemoved\n if (options.canBeRecovered !== undefined)\n this.canBeRecovered = options.canBeRecovered\n if (options.identifier !== undefined)\n this.identifier = options.identifier\n if (options.changeMaps !== undefined)\n this.changeMaps.push(...options.changeMaps)\n\n this.recompute()\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Checks if this subject must be inserted into the database.\n * Subject can be inserted into the database if it is allowed to be inserted (explicitly persisted or by cascades)\n * and if it does not have database entity set.\n */\n get mustBeInserted() {\n return this.canBeInserted && !this.databaseEntity\n }\n\n /**\n * Checks if this subject must be updated into the database.\n * Subject can be updated in the database if it is allowed to be updated (explicitly persisted or by cascades)\n * and if it does have differentiated columns or relations.\n */\n get mustBeUpdated() {\n return (\n this.canBeUpdated &&\n this.identifier &&\n (this.databaseEntityLoaded === false ||\n (this.databaseEntityLoaded && this.databaseEntity)) &&\n // ((this.entity && this.databaseEntity) || (!this.entity && !this.databaseEntity)) &&\n this.changeMaps.length > 0\n )\n }\n\n /**\n * Checks if this subject must be soft-removed into the database.\n * Subject can be updated in the database if it is allowed to be soft-removed (explicitly persisted or by cascades)\n * and if it does have differentiated columns or relations.\n */\n get mustBeSoftRemoved() {\n return (\n this.canBeSoftRemoved &&\n this.identifier &&\n (this.databaseEntityLoaded === false ||\n (this.databaseEntityLoaded && this.databaseEntity))\n )\n }\n\n /**\n * Checks if this subject must be recovered into the database.\n * Subject can be updated in the database if it is allowed to be recovered (explicitly persisted or by cascades)\n * and if it does have differentiated columns or relations.\n */\n get mustBeRecovered() {\n return (\n this.canBeRecovered &&\n this.identifier &&\n (this.databaseEntityLoaded === false ||\n (this.databaseEntityLoaded && this.databaseEntity))\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a value set needs to be inserted / updated in the database.\n * Value set is based on the entity and change maps of the subject.\n * Important note: this method pops data from this subject's change maps.\n */\n createValueSetAndPopChangeMap(): ObjectLiteral {\n const changeMapsWithoutValues: SubjectChangeMap[] = []\n const changeSet = this.changeMaps.reduce((updateMap, changeMap) => {\n let value = changeMap.value\n if (InstanceChecker.isSubject(value)) {\n // referenced columns can refer on values both which were just inserted and which were present in the model\n // if entity was just inserted valueSets must contain all values from the entity and values just inserted in the database\n // so, here we check if we have a value set then we simply use it as value to get our reference column values\n // otherwise simply use an entity which cannot be just inserted at the moment and have all necessary data\n value = value.insertedValueSet\n ? value.insertedValueSet\n : value.entity\n }\n // value = changeMap.valueFactory ? changeMap.valueFactory(value) : changeMap.column.createValueMap(value);\n\n let valueMap: ObjectLiteral | undefined\n if (this.metadata.isJunction && changeMap.column) {\n valueMap = changeMap.column.createValueMap(\n changeMap.column.referencedColumn!.getEntityValue(value),\n )\n } else if (changeMap.column) {\n valueMap = changeMap.column.createValueMap(value)\n } else if (changeMap.relation) {\n // value can be a related object, for example: post.question = { id: 1 }\n // or value can be a null or direct relation id, e.g. post.question = 1\n // if its a direction relation id then we just set it to the valueMap,\n // however if its an object then we need to extract its relation id map and set it to the valueMap\n if (ObjectUtils.isObject(value) && !Buffer.isBuffer(value)) {\n // get relation id, e.g. referenced column name and its value,\n // for example: { id: 1 } which then will be set to relation, e.g. post.category = { id: 1 }\n const relationId =\n changeMap.relation!.getRelationIdMap(value)\n\n // but relation id can be empty, for example in the case when you insert a new post with category\n // and both post and category are newly inserted objects (by cascades) and in this case category will not have id\n // this means we need to insert post without question id and update post's questionId once question be inserted\n // that's why we create a new changeMap operation for future updation of the post entity\n if (relationId === undefined) {\n changeMapsWithoutValues.push(changeMap)\n this.canBeUpdated = true\n return updateMap\n }\n valueMap = changeMap.relation!.createValueMap(relationId)\n this.updatedRelationMaps.push({\n relation: changeMap.relation,\n value: relationId,\n })\n } else {\n // value can be \"null\" or direct relation id here\n valueMap = changeMap.relation!.createValueMap(value)\n this.updatedRelationMaps.push({\n relation: changeMap.relation,\n value: value,\n })\n }\n }\n\n OrmUtils.mergeDeep(updateMap, valueMap)\n return updateMap\n }, {} as ObjectLiteral)\n this.changeMaps = changeMapsWithoutValues\n return changeSet\n }\n\n /**\n * Recomputes entityWithFulfilledIds and identifier when entity changes.\n */\n recompute(): void {\n if (this.entity) {\n this.entityWithFulfilledIds = Object.assign({}, this.entity)\n if (this.parentSubject) {\n this.metadata.primaryColumns.forEach((primaryColumn) => {\n if (\n primaryColumn.relationMetadata &&\n primaryColumn.relationMetadata.inverseEntityMetadata ===\n this.parentSubject!.metadata\n ) {\n const value =\n primaryColumn.referencedColumn!.getEntityValue(\n this.parentSubject!.entity!,\n )\n primaryColumn.setEntityValue(\n this.entityWithFulfilledIds!,\n value,\n )\n }\n })\n }\n this.identifier = this.metadata.getEntityIdMap(\n this.entityWithFulfilledIds,\n )\n } else if (this.databaseEntity) {\n this.identifier = this.metadata.getEntityIdMap(this.databaseEntity)\n }\n }\n}\n"],"sourceRoot":".."}
1
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AAA;IACpB,CAAC;IAED;;OAEG;IACH,SAAS;QACL,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;YAC5D,IAAI,IAAI,CAAC,aAAa,EAAE;gBACpB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;oBACnD,IACI,aAAa,CAAC,gBAAgB;wBAC9B,aAAa,CAAC,gBAAgB,CAAC,qBAAqB;4BAChD,IAAI,CAAC,aAAc,CAAC,QAAQ,EAClC;wBACE,MAAM,KAAK,GACP,aAAa,CAAC,gBAAiB,CAAC,cAAc,CAC1C,IAAI,CAAC,aAAc,CAAC,MAAO,CAC9B,CAAA;wBACL,aAAa,CAAC,cAAc,CACxB,IAAI,CAAC,sBAAuB,EAC5B,KAAK,CACR,CAAA;qBACJ;gBACL,CAAC,CAAC,CAAA;aACL;YACD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAC1C,IAAI,CAAC,sBAAsB,CAC9B,CAAA;SACJ;aAAM,IAAI,IAAI,CAAC,cAAc,EAAE;YAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SACtE;IACL,CAAC;CACJ","file":"Subject.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { SubjectChangeMap } from \"./SubjectChangeMap\"\nimport { OrmUtils } from \"../util/OrmUtils\"\nimport { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Subject is a subject of persistence.\n * It holds information about each entity that needs to be persisted:\n * - what entity should be persisted\n * - what is database representation of the persisted entity\n * - what entity metadata of the persisted entity\n * - what is allowed to with persisted entity (insert/update/remove)\n *\n * Having this collection of subjects we can perform database queries.\n */\nexport class Subject {\n readonly \"@instanceof\" = Symbol.for(\"Subject\")\n\n // -------------------------------------------------------------------------\n // Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the subject entity.\n */\n metadata: EntityMetadata\n\n /**\n * Subject identifier.\n * This identifier is not limited to table entity primary columns.\n * This can be entity id or ids as well as some unique entity properties, like name or title.\n * Insert / Update / Remove operation will be executed by a given identifier.\n */\n identifier: ObjectLiteral | undefined = undefined\n\n /**\n * Copy of entity but with relational ids fulfilled.\n */\n entityWithFulfilledIds: ObjectLiteral | undefined = undefined\n\n /**\n * If subject was created by cascades this property will contain subject\n * from where this subject was created.\n */\n parentSubject?: Subject\n\n /**\n * Gets entity sent to the persistence (e.g. changed entity).\n * If entity is not set then this subject is created only for the entity loaded from the database,\n * or this subject is used for the junction operation (junction operations are relying only on identifier).\n */\n entity?: ObjectLiteral\n\n /**\n * Database entity.\n * THIS IS NOT RAW ENTITY DATA, its a real entity.\n */\n databaseEntity?: ObjectLiteral\n\n /**\n * Indicates if database entity was loaded.\n * No matter if it was found or not, it indicates the fact of loading.\n */\n databaseEntityLoaded: boolean = false\n\n /**\n * Changes needs to be applied in the database for the given subject.\n */\n changeMaps: SubjectChangeMap[] = []\n\n /**\n * Generated values returned by a database (for example generated id or default values).\n * Used in insert and update operations.\n * Has entity-like structure (not just column database name and values).\n */\n generatedMap?: ObjectLiteral\n\n /**\n * Inserted values with updated values of special and default columns.\n * Has entity-like structure (not just column database name and values).\n */\n insertedValueSet?: ObjectLiteral\n\n /**\n * Indicates if this subject can be inserted into the database.\n * This means that this subject either is newly persisted, either can be inserted by cascades.\n */\n canBeInserted: boolean = false\n\n /**\n * Indicates if this subject can be updated in the database.\n * This means that this subject either was persisted, either can be updated by cascades.\n */\n canBeUpdated: boolean = false\n\n /**\n * Indicates if this subject MUST be removed from the database.\n * This means that this subject either was removed, either was removed by cascades.\n */\n mustBeRemoved: boolean = false\n\n /**\n * Indicates if this subject can be soft-removed from the database.\n * This means that this subject either was soft-removed, either was soft-removed by cascades.\n */\n canBeSoftRemoved: boolean = false\n\n /**\n * Indicates if this subject can be recovered from the database.\n * This means that this subject either was recovered, either was recovered by cascades.\n */\n canBeRecovered: boolean = false\n\n /**\n * Relations updated by the change maps.\n */\n updatedRelationMaps: {\n relation: RelationMetadata\n value: ObjectLiteral\n }[] = []\n\n /**\n * List of updated columns\n */\n diffColumns: ColumnMetadata[] = []\n\n /**\n * List of updated relations\n */\n diffRelations: RelationMetadata[] = []\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: {\n metadata: EntityMetadata\n parentSubject?: Subject\n entity?: ObjectLiteral\n canBeInserted?: boolean\n canBeUpdated?: boolean\n mustBeRemoved?: boolean\n canBeSoftRemoved?: boolean\n canBeRecovered?: boolean\n identifier?: ObjectLiteral\n changeMaps?: SubjectChangeMap[]\n }) {\n this.metadata = options.metadata\n this.entity = options.entity\n this.parentSubject = options.parentSubject\n if (options.canBeInserted !== undefined)\n this.canBeInserted = options.canBeInserted\n if (options.canBeUpdated !== undefined)\n this.canBeUpdated = options.canBeUpdated\n if (options.mustBeRemoved !== undefined)\n this.mustBeRemoved = options.mustBeRemoved\n if (options.canBeSoftRemoved !== undefined)\n this.canBeSoftRemoved = options.canBeSoftRemoved\n if (options.canBeRecovered !== undefined)\n this.canBeRecovered = options.canBeRecovered\n if (options.identifier !== undefined)\n this.identifier = options.identifier\n if (options.changeMaps !== undefined)\n this.changeMaps.push(...options.changeMaps)\n\n this.recompute()\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Checks if this subject must be inserted into the database.\n * Subject can be inserted into the database if it is allowed to be inserted (explicitly persisted or by cascades)\n * and if it does not have database entity set.\n */\n get mustBeInserted() {\n return this.canBeInserted && !this.databaseEntity\n }\n\n /**\n * Checks if this subject must be updated into the database.\n * Subject can be updated in the database if it is allowed to be updated (explicitly persisted or by cascades)\n * and if it does have differentiated columns or relations.\n */\n get mustBeUpdated() {\n return (\n this.canBeUpdated &&\n this.identifier &&\n (this.databaseEntityLoaded === false ||\n (this.databaseEntityLoaded && this.databaseEntity)) &&\n // ((this.entity && this.databaseEntity) || (!this.entity && !this.databaseEntity)) &&\n // ensure there are one or more changes for updatable columns\n this.changeMaps.some(\n (change) => !change.column || change.column.isUpdate,\n )\n )\n }\n\n /**\n * Checks if this subject must be soft-removed into the database.\n * Subject can be updated in the database if it is allowed to be soft-removed (explicitly persisted or by cascades)\n * and if it does have differentiated columns or relations.\n */\n get mustBeSoftRemoved() {\n return (\n this.canBeSoftRemoved &&\n this.identifier &&\n (this.databaseEntityLoaded === false ||\n (this.databaseEntityLoaded && this.databaseEntity))\n )\n }\n\n /**\n * Checks if this subject must be recovered into the database.\n * Subject can be updated in the database if it is allowed to be recovered (explicitly persisted or by cascades)\n * and if it does have differentiated columns or relations.\n */\n get mustBeRecovered() {\n return (\n this.canBeRecovered &&\n this.identifier &&\n (this.databaseEntityLoaded === false ||\n (this.databaseEntityLoaded && this.databaseEntity))\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a value set needs to be inserted / updated in the database.\n * Value set is based on the entity and change maps of the subject.\n * Important note: this method pops data from this subject's change maps.\n */\n createValueSetAndPopChangeMap(): ObjectLiteral {\n const changeMapsWithoutValues: SubjectChangeMap[] = []\n const changeSet = this.changeMaps.reduce((updateMap, changeMap) => {\n let value = changeMap.value\n if (InstanceChecker.isSubject(value)) {\n // referenced columns can refer on values both which were just inserted and which were present in the model\n // if entity was just inserted valueSets must contain all values from the entity and values just inserted in the database\n // so, here we check if we have a value set then we simply use it as value to get our reference column values\n // otherwise simply use an entity which cannot be just inserted at the moment and have all necessary data\n value = value.insertedValueSet\n ? value.insertedValueSet\n : value.entity\n }\n // value = changeMap.valueFactory ? changeMap.valueFactory(value) : changeMap.column.createValueMap(value);\n\n let valueMap: ObjectLiteral | undefined\n if (this.metadata.isJunction && changeMap.column) {\n valueMap = changeMap.column.createValueMap(\n changeMap.column.referencedColumn!.getEntityValue(value),\n )\n } else if (changeMap.column) {\n valueMap = changeMap.column.createValueMap(value)\n } else if (changeMap.relation) {\n // value can be a related object, for example: post.question = { id: 1 }\n // or value can be a null or direct relation id, e.g. post.question = 1\n // if its a direction relation id then we just set it to the valueMap,\n // however if its an object then we need to extract its relation id map and set it to the valueMap\n if (ObjectUtils.isObject(value) && !Buffer.isBuffer(value)) {\n // get relation id, e.g. referenced column name and its value,\n // for example: { id: 1 } which then will be set to relation, e.g. post.category = { id: 1 }\n const relationId =\n changeMap.relation!.getRelationIdMap(value)\n\n // but relation id can be empty, for example in the case when you insert a new post with category\n // and both post and category are newly inserted objects (by cascades) and in this case category will not have id\n // this means we need to insert post without question id and update post's questionId once question be inserted\n // that's why we create a new changeMap operation for future updation of the post entity\n if (relationId === undefined) {\n changeMapsWithoutValues.push(changeMap)\n this.canBeUpdated = true\n return updateMap\n }\n valueMap = changeMap.relation!.createValueMap(relationId)\n this.updatedRelationMaps.push({\n relation: changeMap.relation,\n value: relationId,\n })\n } else {\n // value can be \"null\" or direct relation id here\n valueMap = changeMap.relation!.createValueMap(value)\n this.updatedRelationMaps.push({\n relation: changeMap.relation,\n value: value,\n })\n }\n }\n\n OrmUtils.mergeDeep(updateMap, valueMap)\n return updateMap\n }, {} as ObjectLiteral)\n this.changeMaps = changeMapsWithoutValues\n return changeSet\n }\n\n /**\n * Recomputes entityWithFulfilledIds and identifier when entity changes.\n */\n recompute(): void {\n if (this.entity) {\n this.entityWithFulfilledIds = Object.assign({}, this.entity)\n if (this.parentSubject) {\n this.metadata.primaryColumns.forEach((primaryColumn) => {\n if (\n primaryColumn.relationMetadata &&\n primaryColumn.relationMetadata.inverseEntityMetadata ===\n this.parentSubject!.metadata\n ) {\n const value =\n primaryColumn.referencedColumn!.getEntityValue(\n this.parentSubject!.entity!,\n )\n primaryColumn.setEntityValue(\n this.entityWithFulfilledIds!,\n value,\n )\n }\n })\n }\n this.identifier = this.metadata.getEntityIdMap(\n this.entityWithFulfilledIds,\n )\n } else if (this.databaseEntity) {\n this.identifier = this.metadata.getEntityIdMap(this.databaseEntity)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -529,7 +529,7 @@ export class QueryBuilder {
529
529
  // In some dialects query nesting is available - but not all. Because of this, we'll need
530
530
  // to scrub "ending" characters from the SQL but otherwise we can leave everything else
531
531
  // as-is and it should be valid.
532
- return `/* ${this.expressionMap.comment.replace("*/", "")} */ `;
532
+ return `/* ${this.expressionMap.comment.replace(/\*\//g, "")} */ `;
533
533
  }
534
534
  /**
535
535
  * Time travel queries for CockroachDB