typeorm 0.3.10-dev.a1960e1 → 0.3.10-dev.de15df1

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 (113) hide show
  1. package/browser/data-source/BaseDataSourceOptions.d.ts +4 -0
  2. package/browser/data-source/BaseDataSourceOptions.js.map +1 -1
  3. package/browser/decorator/options/RelationOptions.d.ts +5 -2
  4. package/browser/decorator/options/RelationOptions.js.map +1 -1
  5. package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
  6. package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
  7. package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
  8. package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
  9. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
  10. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  11. package/browser/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
  12. package/browser/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
  13. package/browser/driver/cockroachdb/CockroachDriver.js +1 -0
  14. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  15. package/browser/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
  16. package/browser/driver/cordova/CordovaConnectionOptions.js.map +1 -1
  17. package/browser/driver/expo/ExpoConnectionOptions.d.ts +1 -0
  18. package/browser/driver/expo/ExpoConnectionOptions.js.map +1 -1
  19. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
  20. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  21. package/browser/driver/mysql/MysqlDriver.js +1 -1
  22. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  23. package/browser/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
  24. package/browser/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
  25. package/browser/driver/oracle/OracleDriver.js +2 -0
  26. package/browser/driver/oracle/OracleDriver.js.map +1 -1
  27. package/browser/driver/postgres/PostgresDriver.js +1 -0
  28. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  29. package/browser/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
  30. package/browser/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
  31. package/browser/driver/sap/SapConnectionOptions.d.ts +1 -0
  32. package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
  33. package/browser/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
  34. package/browser/driver/spanner/SpannerConnectionOptions.js.map +1 -1
  35. package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
  36. package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
  37. package/browser/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
  38. package/browser/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
  39. package/browser/driver/sqljs/SqljsDriver.d.ts +1 -0
  40. package/browser/driver/sqljs/SqljsDriver.js +3 -1
  41. package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
  42. package/browser/driver/sqljs/SqljsQueryRunner.js +3 -1
  43. package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  44. package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
  45. package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  46. package/browser/entity-schema/EntitySchemaRelationOptions.d.ts +4 -2
  47. package/browser/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
  48. package/browser/metadata/RelationMetadata.d.ts +4 -2
  49. package/browser/metadata/RelationMetadata.js.map +1 -1
  50. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +30 -27
  51. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  52. package/browser/query-builder/RelationIdLoader.js +15 -14
  53. package/browser/query-builder/RelationIdLoader.js.map +1 -1
  54. package/browser/query-builder/SelectQueryBuilder.js +1 -1
  55. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  56. package/commands/InitCommand.js +5 -5
  57. package/commands/InitCommand.js.map +1 -1
  58. package/data-source/BaseDataSourceOptions.d.ts +4 -0
  59. package/data-source/BaseDataSourceOptions.js.map +1 -1
  60. package/decorator/options/RelationOptions.d.ts +5 -2
  61. package/decorator/options/RelationOptions.js.map +1 -1
  62. package/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
  63. package/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
  64. package/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
  65. package/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
  66. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
  67. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  68. package/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
  69. package/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
  70. package/driver/cockroachdb/CockroachDriver.js +1 -0
  71. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  72. package/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
  73. package/driver/cordova/CordovaConnectionOptions.js.map +1 -1
  74. package/driver/expo/ExpoConnectionOptions.d.ts +1 -0
  75. package/driver/expo/ExpoConnectionOptions.js.map +1 -1
  76. package/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
  77. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  78. package/driver/mysql/MysqlDriver.js +1 -1
  79. package/driver/mysql/MysqlDriver.js.map +1 -1
  80. package/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
  81. package/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
  82. package/driver/oracle/OracleDriver.js +2 -0
  83. package/driver/oracle/OracleDriver.js.map +1 -1
  84. package/driver/postgres/PostgresDriver.js +1 -0
  85. package/driver/postgres/PostgresDriver.js.map +1 -1
  86. package/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
  87. package/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
  88. package/driver/sap/SapConnectionOptions.d.ts +1 -0
  89. package/driver/sap/SapConnectionOptions.js.map +1 -1
  90. package/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
  91. package/driver/spanner/SpannerConnectionOptions.js.map +1 -1
  92. package/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
  93. package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
  94. package/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
  95. package/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
  96. package/driver/sqljs/SqljsDriver.d.ts +1 -0
  97. package/driver/sqljs/SqljsDriver.js +3 -1
  98. package/driver/sqljs/SqljsDriver.js.map +1 -1
  99. package/driver/sqljs/SqljsQueryRunner.js +3 -1
  100. package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  101. package/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
  102. package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  103. package/entity-schema/EntitySchemaRelationOptions.d.ts +4 -2
  104. package/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
  105. package/metadata/RelationMetadata.d.ts +4 -2
  106. package/metadata/RelationMetadata.js.map +1 -1
  107. package/package.json +1 -1
  108. package/persistence/subject-builder/OneToManySubjectBuilder.js +30 -27
  109. package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  110. package/query-builder/RelationIdLoader.js +15 -14
  111. package/query-builder/RelationIdLoader.js.map +1 -1
  112. package/query-builder/SelectQueryBuilder.js +1 -1
  113. package/query-builder/SelectQueryBuilder.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/sqljs/SqljsDriver.ts"],"names":[],"mappings":";;;AAAA,kFAA8E;AAE9E,yDAAqD;AAGrD,+FAA2F;AAC3F,iFAA6E;AAC7E,gEAA4D;AAE5D,kDAA8C;AAG9C,u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I,KAAK,SAAS,EAAE;YAClC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAA;YAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACvB;aAAM;YACH,IAAI;gBACA,MAAM,MAAM,GACR,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,6BAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;aACvB;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,IAAI,+DAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;aAC/D;SACJ;IACL,CAAC;CACJ;AAhSD,kCAgSC","file":"SqljsDriver.js","sourcesContent":["import { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { SqljsConnectionOptions } from \"./SqljsConnectionOptions\"\nimport { SqljsQueryRunner } from \"./SqljsQueryRunner\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { TypeORMError } from \"../../error\"\n\n// This is needed to satisfy the typescript compiler.\ninterface Window {\n SQL: any\n localforage: any\n}\ndeclare let window: Window\n\nexport class SqljsDriver extends AbstractSqliteDriver {\n // The driver specific options.\n options: SqljsConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n // If autoSave is enabled by user, location or autoSaveCallback have to be set\n // because either autoSave saves to location or calls autoSaveCallback.\n if (\n this.options.autoSave &&\n !this.options.location &&\n !this.options.autoSaveCallback\n ) {\n throw new DriverOptionNotSetError(`location or autoSaveCallback`)\n }\n\n // load sql.js package\n this.loadDependencies()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection()\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n this.queryRunner = undefined\n this.databaseConnection.close()\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) this.queryRunner = new SqljsQueryRunner(this)\n\n return this.queryRunner\n }\n\n /**\n * Loads a database from a given file (Node.js), local storage key (browser) or array.\n * This will delete the current database!\n */\n async load(\n fileNameOrLocalStorageOrData: string | Uint8Array,\n checkIfFileOrLocalStorageExists: boolean = true,\n ): Promise<any> {\n if (typeof fileNameOrLocalStorageOrData === \"string\") {\n // content has to be loaded\n if (PlatformTools.type === \"node\") {\n // Node.js\n // fileNameOrLocalStorageOrData should be a path to the file\n if (PlatformTools.fileExist(fileNameOrLocalStorageOrData)) {\n const database = PlatformTools.readFileSync(\n fileNameOrLocalStorageOrData,\n )\n return this.createDatabaseConnectionWithImport(database)\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // File doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing an existing file.\n // File will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n } else {\n // browser\n // fileNameOrLocalStorageOrData should be a local storage / indexedDB key\n let localStorageContent = null\n if (this.options.useLocalForage) {\n if (window.localforage) {\n localStorageContent = await window.localforage.getItem(\n fileNameOrLocalStorageOrData,\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n localStorageContent =\n PlatformTools.getGlobalVariable().localStorage.getItem(\n fileNameOrLocalStorageOrData,\n )\n }\n\n if (localStorageContent != null) {\n // localStorage value exists.\n return this.createDatabaseConnectionWithImport(\n JSON.parse(localStorageContent),\n )\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // localStorage value doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing anything.\n // localStorage value will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n }\n } else {\n return this.createDatabaseConnectionWithImport(\n fileNameOrLocalStorageOrData,\n )\n }\n }\n\n /**\n * Saved the current database to the given file (Node.js), local storage key (browser) or\n * indexedDB key (browser with enabled useLocalForage option).\n * If no location path is given, the location path in the options (if specified) will be used.\n */\n async save(location?: string) {\n if (!location && !this.options.location) {\n throw new TypeORMError(\n `No location is set, specify a location parameter or add the location option to your configuration`,\n )\n }\n\n let path = \"\"\n if (location) {\n path = location\n } else if (this.options.location) {\n path = this.options.location\n }\n\n if (PlatformTools.type === \"node\") {\n try {\n const content = Buffer.from(this.databaseConnection.export())\n await PlatformTools.writeFile(path, content)\n } catch (e) {\n throw new TypeORMError(`Could not save database, error: ${e}`)\n }\n } else {\n const database: Uint8Array = this.databaseConnection.export()\n // convert Uint8Array to number array to improve local-storage storage\n const databaseArray = [].slice.call(database)\n if (this.options.useLocalForage) {\n if (window.localforage) {\n await window.localforage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n PlatformTools.getGlobalVariable().localStorage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n }\n }\n }\n\n /**\n * This gets called by the QueryRunner when a change to the database is made.\n * If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,\n * otherwise the save method is called which saves it to file (Node.js), local storage (browser)\n * or indexedDB (browser with enabled useLocalForage option).\n */\n async autoSave() {\n if (this.options.autoSave) {\n if (this.options.autoSaveCallback) {\n await this.options.autoSaveCallback(this.export())\n } else {\n await this.save()\n }\n }\n }\n\n /**\n * Returns the current database as Uint8Array.\n */\n export(): Uint8Array {\n return this.databaseConnection.export()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertResult: any) {\n const generatedMap = metadata.generatedColumns.reduce(\n (map, generatedColumn) => {\n // seems to be the only way to get the inserted id, see https://github.com/kripken/sql.js/issues/77\n if (\n generatedColumn.isPrimary &&\n generatedColumn.generationStrategy === \"increment\"\n ) {\n const query = \"SELECT last_insert_rowid()\"\n try {\n let result = this.databaseConnection.exec(query)\n this.connection.logger.logQuery(query)\n return OrmUtils.mergeDeep(\n map,\n generatedColumn.createValueMap(\n result[0].values[0][0],\n ),\n )\n } catch (e) {\n this.connection.logger.logQueryError(e, query, [])\n }\n }\n\n return map\n },\n {} as ObjectLiteral,\n )\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n * If the location option is set, the database is loaded first.\n */\n protected createDatabaseConnection(): Promise<any> {\n if (this.options.location) {\n return this.load(this.options.location, false)\n }\n\n return this.createDatabaseConnectionWithImport(this.options.database)\n }\n\n /**\n * Creates connection with an optional database.\n * If database is specified it is loaded, otherwise a new empty database is created.\n */\n protected async createDatabaseConnectionWithImport(\n database?: Uint8Array,\n ): Promise<any> {\n // sql.js < 1.0 exposes an object with a `Database` method.\n const isLegacyVersion = typeof this.sqlite.Database === \"function\"\n const sqlite = isLegacyVersion\n ? this.sqlite\n : await this.sqlite(this.options.sqlJsConfig)\n if (database && database.length > 0) {\n this.databaseConnection = new sqlite.Database(database)\n } else {\n this.databaseConnection = new sqlite.Database()\n }\n\n this.databaseConnection.exec(`PRAGMA foreign_keys = ON`)\n\n return this.databaseConnection\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n if (PlatformTools.type === \"browser\") {\n const sqlite = this.options.driver || window.SQL\n this.sqlite = sqlite\n } else {\n try {\n const sqlite =\n this.options.driver || PlatformTools.load(\"sql.js\")\n this.sqlite = sqlite\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"sql.js\", \"sql.js\")\n }\n }\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../../src/driver/sqljs/SqljsDriver.ts"],"names":[],"mappings":";;;AAAA,kFAA8E;AAE9E,yDAAqD;AAGrD,+FAA2F;AAC3F,iFAA6E;AAC7E,gEAA4D;AAE5D,kDAA8C;AAG9C,uCAA0C;AAS1C,MAAa,WAAY,SAAQ,2CAAoB;IAIjD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,8EAA8E;QAC9E,uEAAuE;QACvE,IACI,IAAI,CAAC,OAAO,CAAC,QAAQ;YACrB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;YACtB,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAChC;YACE,MAAM,IAAI,iDAAuB,CAAC,8BAA8B,CAAC,CAAA;SACpE;QAED,sBAAsB;QACtB,IAAI,CAAC,gBAAgB,EAAE,CAAA;IAC3B,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,OAAO;QACT,IAAI,CAAC,kBAAkB,GAAG,MAAM,IAAI,CAAC,wBAAwB,EAAE,CAAA;IACnE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACZ,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;QAC5B,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,IAAqB;QACnC,IAAI,CAAC,IAAI,CAAC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AAM;YACb,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACjD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACjC,IAAI,CAAC,kBAAkB,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;SAC1D;aAAM;YACH,IAAI,CAAC,kBAAkB,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAA;SAClD;QAED,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;QAExD,OAAO,IAAI,CAAC,kBAAkB,CAAA;IAClC,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI,6BAAa,CAAC,IAAI,KAAK,SAAS,EAAE;YAClC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAA;YAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACvB;aAAM;YACH,IAAI;gBACA,MAAM,MAAM,GACR,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,6BAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;aACvB;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,IAAI,+DAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;aAC/D;SACJ;IACL,CAAC;CACJ;AAjSD,kCAiSC","file":"SqljsDriver.js","sourcesContent":["import { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { SqljsConnectionOptions } from \"./SqljsConnectionOptions\"\nimport { SqljsQueryRunner } from \"./SqljsQueryRunner\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { TypeORMError } from \"../../error\"\n\n// This is needed to satisfy the typescript compiler.\ninterface Window {\n SQL: any\n localforage: any\n}\ndeclare let window: Window\n\nexport class SqljsDriver extends AbstractSqliteDriver {\n // The driver specific options.\n options: SqljsConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n // If autoSave is enabled by user, location or autoSaveCallback have to be set\n // because either autoSave saves to location or calls autoSaveCallback.\n if (\n this.options.autoSave &&\n !this.options.location &&\n !this.options.autoSaveCallback\n ) {\n throw new DriverOptionNotSetError(`location or autoSaveCallback`)\n }\n\n // load sql.js package\n this.loadDependencies()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection()\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n this.queryRunner = undefined\n this.databaseConnection.close()\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) this.queryRunner = new SqljsQueryRunner(this)\n\n return this.queryRunner\n }\n\n /**\n * Loads a database from a given file (Node.js), local storage key (browser) or array.\n * This will delete the current database!\n */\n async load(\n fileNameOrLocalStorageOrData: string | Uint8Array,\n checkIfFileOrLocalStorageExists: boolean = true,\n ): Promise<any> {\n if (typeof fileNameOrLocalStorageOrData === \"string\") {\n // content has to be loaded\n if (PlatformTools.type === \"node\") {\n // Node.js\n // fileNameOrLocalStorageOrData should be a path to the file\n if (PlatformTools.fileExist(fileNameOrLocalStorageOrData)) {\n const database = PlatformTools.readFileSync(\n fileNameOrLocalStorageOrData,\n )\n return this.createDatabaseConnectionWithImport(database)\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // File doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing an existing file.\n // File will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n } else {\n // browser\n // fileNameOrLocalStorageOrData should be a local storage / indexedDB key\n let localStorageContent = null\n if (this.options.useLocalForage) {\n if (window.localforage) {\n localStorageContent = await window.localforage.getItem(\n fileNameOrLocalStorageOrData,\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n localStorageContent =\n PlatformTools.getGlobalVariable().localStorage.getItem(\n fileNameOrLocalStorageOrData,\n )\n }\n\n if (localStorageContent != null) {\n // localStorage value exists.\n return this.createDatabaseConnectionWithImport(\n JSON.parse(localStorageContent),\n )\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // localStorage value doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing anything.\n // localStorage value will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n }\n } else {\n return this.createDatabaseConnectionWithImport(\n fileNameOrLocalStorageOrData,\n )\n }\n }\n\n /**\n * Saved the current database to the given file (Node.js), local storage key (browser) or\n * indexedDB key (browser with enabled useLocalForage option).\n * If no location path is given, the location path in the options (if specified) will be used.\n */\n async save(location?: string) {\n if (!location && !this.options.location) {\n throw new TypeORMError(\n `No location is set, specify a location parameter or add the location option to your configuration`,\n )\n }\n\n let path = \"\"\n if (location) {\n path = location\n } else if (this.options.location) {\n path = this.options.location\n }\n\n if (PlatformTools.type === \"node\") {\n try {\n const content = Buffer.from(this.databaseConnection.export())\n await PlatformTools.writeFile(path, content)\n } catch (e) {\n throw new TypeORMError(`Could not save database, error: ${e}`)\n }\n } else {\n const database: Uint8Array = this.databaseConnection.export()\n // convert Uint8Array to number array to improve local-storage storage\n const databaseArray = [].slice.call(database)\n if (this.options.useLocalForage) {\n if (window.localforage) {\n await window.localforage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n PlatformTools.getGlobalVariable().localStorage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n }\n }\n }\n\n /**\n * This gets called by the QueryRunner when a change to the database is made.\n * If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,\n * otherwise the save method is called which saves it to file (Node.js), local storage (browser)\n * or indexedDB (browser with enabled useLocalForage option).\n * Don't auto-save when in transaction as the call to export will end the current transaction\n */\n async autoSave() {\n if (this.options.autoSave && !this.queryRunner?.isTransactionActive) {\n if (this.options.autoSaveCallback) {\n await this.options.autoSaveCallback(this.export())\n } else {\n await this.save()\n }\n }\n }\n\n /**\n * Returns the current database as Uint8Array.\n */\n export(): Uint8Array {\n return this.databaseConnection.export()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertResult: any) {\n const generatedMap = metadata.generatedColumns.reduce(\n (map, generatedColumn) => {\n // seems to be the only way to get the inserted id, see https://github.com/kripken/sql.js/issues/77\n if (\n generatedColumn.isPrimary &&\n generatedColumn.generationStrategy === \"increment\"\n ) {\n const query = \"SELECT last_insert_rowid()\"\n try {\n let result = this.databaseConnection.exec(query)\n this.connection.logger.logQuery(query)\n return OrmUtils.mergeDeep(\n map,\n generatedColumn.createValueMap(\n result[0].values[0][0],\n ),\n )\n } catch (e) {\n this.connection.logger.logQueryError(e, query, [])\n }\n }\n\n return map\n },\n {} as ObjectLiteral,\n )\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n * If the location option is set, the database is loaded first.\n */\n protected createDatabaseConnection(): Promise<any> {\n if (this.options.location) {\n return this.load(this.options.location, false)\n }\n\n return this.createDatabaseConnectionWithImport(this.options.database)\n }\n\n /**\n * Creates connection with an optional database.\n * If database is specified it is loaded, otherwise a new empty database is created.\n */\n protected async createDatabaseConnectionWithImport(\n database?: Uint8Array,\n ): Promise<any> {\n // sql.js < 1.0 exposes an object with a `Database` method.\n const isLegacyVersion = typeof this.sqlite.Database === \"function\"\n const sqlite = isLegacyVersion\n ? this.sqlite\n : await this.sqlite(this.options.sqlJsConfig)\n if (database && database.length > 0) {\n this.databaseConnection = new sqlite.Database(database)\n } else {\n this.databaseConnection = new sqlite.Database()\n }\n\n this.databaseConnection.exec(`PRAGMA foreign_keys = ON`)\n\n return this.databaseConnection\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n if (PlatformTools.type === \"browser\") {\n const sqlite = this.options.driver || window.SQL\n this.sqlite = sqlite\n } else {\n try {\n const sqlite =\n this.options.driver || PlatformTools.load(\"sql.js\")\n this.sqlite = sqlite\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"sql.js\", \"sql.js\")\n }\n }\n }\n}\n"],"sourceRoot":"../.."}
@@ -54,7 +54,9 @@ class SqljsQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRu
54
54
  */
55
55
  async commitTransaction() {
56
56
  await super.commitTransaction();
57
- await this.flush();
57
+ if (!this.isTransactionActive) {
58
+ await this.flush();
59
+ }
58
60
  }
59
61
  /**
60
62
  * Executes a given SQL query.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/sqljs/SqljsQueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,4FAAwF;AAExF,8DAA0D;AAC1D,mEAA+D;AAC/D,gEAA4D;AAE5D;;GAEG;AACH,MAAa,gBAAiB,SAAQ,qDAAyB;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A;YACtD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAA;YACxB,MAAM,CAAC,GAAG,GAAG,OAAO,CAAA;YAEpB,SAAS,CAAC,IAAI,EAAE,CAAA;YAEhB,IAAI,OAAO,KAAK,QAAQ,EAAE;gBACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;aACtB;YAED,IAAI,mBAAmB,EAAE;gBACrB,OAAO,MAAM,CAAA;aAChB;iBAAM;gBACH,OAAO,MAAM,CAAC,GAAG,CAAA;aACpB;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,SAAS,EAAE;gBACX,SAAS,CAAC,IAAI,EAAE,CAAA;aACnB;YAED,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CACvC,CAAC,EACD,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;YACD,MAAM,IAAI,mCAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;SACnD;IACL,CAAC;CACJ;AA5ID,4CA4IC","file":"SqljsQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { SqljsDriver } from \"./SqljsDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class SqljsQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Flag to determine if a modification has happened since the last time this query runner has requested a save.\n */\n private isDirty = false\n\n /**\n * Database driver used by connection.\n */\n driver: SqljsDriver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: SqljsDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n private async flush() {\n if (this.isDirty) {\n await this.driver.autoSave()\n this.isDirty = false\n }\n }\n\n async release(): Promise<void> {\n await this.flush()\n return super.release()\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n */\n async commitTransaction(): Promise<void> {\n await super.commitTransaction()\n await this.flush()\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters: any[] = [],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const command = query.trim().split(\" \", 1)[0]\n\n const databaseConnection = this.driver.databaseConnection\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n let statement: any\n try {\n statement = databaseConnection.prepare(query)\n if (parameters) {\n parameters = parameters.map((p) =>\n typeof p !== \"undefined\" ? p : null,\n )\n\n statement.bind(parameters)\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n )\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n\n const records: any[] = []\n\n while (statement.step()) {\n records.push(statement.getAsObject())\n }\n\n const result = new QueryResult()\n\n result.affected = databaseConnection.getRowsModified()\n result.records = records\n result.raw = records\n\n statement.free()\n\n if (command !== \"SELECT\") {\n this.isDirty = true\n }\n\n if (useStructuredResult) {\n return result\n } else {\n return result.raw\n }\n } catch (e) {\n if (statement) {\n statement.free()\n }\n\n this.driver.connection.logger.logQueryError(\n e,\n query,\n parameters,\n this,\n )\n throw new QueryFailedError(query, parameters, e)\n }\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../../src/driver/sqljs/SqljsQueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,4FAAwF;AAExF,8DAA0D;AAC1D,mEAA+D;AAC/D,gEAA4D;AAE5D;;GAEG;AACH,MAAa,gBAAiB,SAAQ,qDAAyB;IAW3D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAAmB;QAC3B,KAAK,EAAE,CAAA;QAfX;;WAEG;QACK,YAAO,GAAG,KAAK,CAAA;QAanB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,eAAe;QACjB,MAAM,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAA;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAChB,MAAM,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAChD,CAAC;IAEO,KAAK,CAAC,KAAK;QACf,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;YAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;SACvB;IACL,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;QAClB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,iBAAiB;QACnB,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAA;QAC/B,IAAI,CAAC,IAAI,CAAC,mBA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AkB,EAClB,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;YAEL,MAAM,OAAO,GAAU,EAAE,CAAA;YAEzB,OAAO,SAAS,CAAC,IAAI,EAAE,EAAE;gBACrB,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAA;aACxC;YAED,MAAM,MAAM,GAAG,IAAI,yBAAW,EAAE,CAAA;YAEhC,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAC,eAAe,EAAE,CAAA;YACtD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAA;YACxB,MAAM,CAAC,GAAG,GAAG,OAAO,CAAA;YAEpB,SAAS,CAAC,IAAI,EAAE,CAAA;YAEhB,IAAI,OAAO,KAAK,QAAQ,EAAE;gBACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;aACtB;YAED,IAAI,mBAAmB,EAAE;gBACrB,OAAO,MAAM,CAAA;aAChB;iBAAM;gBACH,OAAO,MAAM,CAAC,GAAG,CAAA;aACpB;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,SAAS,EAAE;gBACX,SAAS,CAAC,IAAI,EAAE,CAAA;aACnB;YAED,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CACvC,CAAC,EACD,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;YACD,MAAM,IAAI,mCAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;SACnD;IACL,CAAC;CACJ;AA9ID,4CA8IC","file":"SqljsQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { SqljsDriver } from \"./SqljsDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class SqljsQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Flag to determine if a modification has happened since the last time this query runner has requested a save.\n */\n private isDirty = false\n\n /**\n * Database driver used by connection.\n */\n driver: SqljsDriver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: SqljsDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n private async flush() {\n if (this.isDirty) {\n await this.driver.autoSave()\n this.isDirty = false\n }\n }\n\n async release(): Promise<void> {\n await this.flush()\n return super.release()\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n */\n async commitTransaction(): Promise<void> {\n await super.commitTransaction()\n if (!this.isTransactionActive) {\n await this.flush()\n }\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters: any[] = [],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const command = query.trim().split(\" \", 1)[0]\n\n const databaseConnection = this.driver.databaseConnection\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n let statement: any\n try {\n statement = databaseConnection.prepare(query)\n if (parameters) {\n parameters = parameters.map((p) =>\n typeof p !== \"undefined\" ? p : null,\n )\n\n statement.bind(parameters)\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n )\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n\n const records: any[] = []\n\n while (statement.step()) {\n records.push(statement.getAsObject())\n }\n\n const result = new QueryResult()\n\n result.affected = databaseConnection.getRowsModified()\n result.records = records\n result.raw = records\n\n statement.free()\n\n if (command !== \"SELECT\") {\n this.isDirty = true\n }\n\n if (useStructuredResult) {\n return result\n } else {\n return result.raw\n }\n } catch (e) {\n if (statement) {\n statement.free()\n }\n\n this.driver.connection.logger.logQueryError(\n e,\n query,\n parameters,\n this,\n )\n throw new QueryFailedError(query, parameters, e)\n }\n }\n}\n"],"sourceRoot":"../.."}
@@ -233,4 +233,5 @@ export interface SqlServerConnectionOptions extends BaseDataSourceOptions, SqlSe
233
233
  */
234
234
  readonly slaves: SqlServerConnectionCredentialsOptions[];
235
235
  };
236
+ readonly poolSize?: never;
236
237
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: true).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n\n /**\n * Application name used for identifying a specific application in profiling, logging or tracing tools of SQL Server.\n * (default: node-mssql)\n */\n readonly appName?: string\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../../src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: true).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n\n /**\n * Application name used for identifying a specific application in profiling, logging or tracing tools of SQL Server.\n * (default: node-mssql)\n */\n readonly appName?: string\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
@@ -87,7 +87,9 @@ export interface EntitySchemaRelationOptions {
87
87
  */
88
88
  deferrable?: DeferrableType;
89
89
  /**
90
- * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
90
+ * When a parent is saved (with cascading but) without a child row that still exists in database, this will control what shall happen to them.
91
+ * delete will remove these rows from database. nullify will remove the relation key.
92
+ * skip will keep the relation intact. Removal of related item is only possible through its own repo.
91
93
  */
92
- orphanedRowAction?: "nullify" | "delete" | "soft-delete";
94
+ orphanedRowAction?: "nullify" | "delete" | "soft-delete" | "disable";
93
95
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/entity-schema/EntitySchemaRelationOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationOptions.js","sourcesContent":["import { JoinColumnOptions } from \"../decorator/options/JoinColumnOptions\"\nimport { RelationType } from \"../metadata/types/RelationTypes\"\nimport { JoinTableMultipleColumnsOptions } from \"../decorator/options/JoinTableMultipleColumnsOptions\"\nimport { DeferrableType } from \"../metadata/types/DeferrableType\"\nimport { OnDeleteType } from \"../metadata/types/OnDeleteType\"\nimport { OnUpdateType } from \"../metadata/types/OnUpdateType\"\nimport { JoinTableOptions } from \"../decorator/options/JoinTableOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\nexport interface EntitySchemaRelationOptions {\n /**\n * Indicates with which entity this relation is made.\n */\n target: EntityTarget<any>\n\n /**\n * Type of relation. Can be one of the value of the RelationTypes class.\n */\n type: RelationType\n\n /**\n * Inverse side of the relation.\n */\n inverseSide?: string\n\n /**\n * Indicates if this relation will be lazily loaded.\n */\n lazy?: boolean\n\n /**\n * Indicates if this relation will be eagerly loaded.\n */\n eager?: boolean\n\n /**\n * Indicates if persistence is enabled for the relation.\n * By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints?: boolean\n\n /**\n * Join table options of this column. If set to true then it simply means that it has a join table.\n */\n joinTable?: boolean | JoinTableOptions | JoinTableMultipleColumnsOptions\n\n /**\n * Join column options of this column. If set to true then it simply means that it has a join column.\n */\n joinColumn?: boolean | JoinColumnOptions | JoinColumnOptions[]\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n treeParent?: boolean\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n treeChildren?: boolean\n\n /**\n * If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.\n * This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.\n */\n cascade?:\n | boolean\n | (\"insert\" | \"update\" | \"remove\" | \"soft-remove\" | \"recover\")[]\n\n /**\n * Default database value.\n */\n default?: any\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\"\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/entity-schema/EntitySchemaRelationOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationOptions.js","sourcesContent":["import { JoinColumnOptions } from \"../decorator/options/JoinColumnOptions\"\nimport { RelationType } from \"../metadata/types/RelationTypes\"\nimport { JoinTableMultipleColumnsOptions } from \"../decorator/options/JoinTableMultipleColumnsOptions\"\nimport { DeferrableType } from \"../metadata/types/DeferrableType\"\nimport { OnDeleteType } from \"../metadata/types/OnDeleteType\"\nimport { OnUpdateType } from \"../metadata/types/OnUpdateType\"\nimport { JoinTableOptions } from \"../decorator/options/JoinTableOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\nexport interface EntitySchemaRelationOptions {\n /**\n * Indicates with which entity this relation is made.\n */\n target: EntityTarget<any>\n\n /**\n * Type of relation. Can be one of the value of the RelationTypes class.\n */\n type: RelationType\n\n /**\n * Inverse side of the relation.\n */\n inverseSide?: string\n\n /**\n * Indicates if this relation will be lazily loaded.\n */\n lazy?: boolean\n\n /**\n * Indicates if this relation will be eagerly loaded.\n */\n eager?: boolean\n\n /**\n * Indicates if persistence is enabled for the relation.\n * By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistence?: boolean\n\n /**\n * Indicates if this relation will be a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n primary?: boolean\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints?: boolean\n\n /**\n * Join table options of this column. If set to true then it simply means that it has a join table.\n */\n joinTable?: boolean | JoinTableOptions | JoinTableMultipleColumnsOptions\n\n /**\n * Join column options of this column. If set to true then it simply means that it has a join column.\n */\n joinColumn?: boolean | JoinColumnOptions | JoinColumnOptions[]\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n treeParent?: boolean\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n treeChildren?: boolean\n\n /**\n * If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.\n * This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.\n */\n cascade?:\n | boolean\n | (\"insert\" | \"update\" | \"remove\" | \"soft-remove\" | \"recover\")[]\n\n /**\n * Default database value.\n */\n default?: any\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n nullable?: boolean\n\n /**\n * Database cascade action on delete.\n */\n onDelete?: OnDeleteType\n\n /**\n * Database cascade action on update.\n */\n onUpdate?: OnUpdateType\n\n /**\n * Indicate if foreign key constraints can be deferred.\n */\n deferrable?: DeferrableType\n\n /**\n * When a parent is saved (with cascading but) without a child row that still exists in database, this will control what shall happen to them.\n * delete will remove these rows from database. nullify will remove the relation key.\n * skip will keep the relation intact. Removal of related item is only possible through its own repo.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\" | \"disable\"\n}\n"],"sourceRoot":".."}
@@ -90,9 +90,11 @@ export declare class RelationMetadata {
90
90
  */
91
91
  persistenceEnabled: boolean;
92
92
  /**
93
- * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.
93
+ * When a parent is saved (with cascading but) without a child row that still exists in database, this will control what shall happen to them.
94
+ * delete will remove these rows from database. nullify will remove the relation key.
95
+ * skip will keep the relation intact. Removal of related item is only possible through its own repo.
94
96
  */
95
- orphanedRowAction?: "nullify" | "delete" | "soft-delete";
97
+ orphanedRowAction?: "nullify" | "delete" | "soft-delete" | "disable";
96
98
  /**
97
99
  * If set to true then related objects are allowed to be inserted to the database.
98
100
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/metadata/RelationMetadata.ts"],"names":[],"mappings":";;;AACA,qDAAiD;AAUjD,oCAAuC;AACvC,qDAAiD;AACjD,6DAAyD;AAEzD;;GAEG;AACH,MAAa,gBAAgB;IAmQzB,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,YAAY,OAIX;QA9MD;;WAEG;QACH,iBAAY,GAAY,KAAK,CAAA;QAE7B;;WAEG;QACH,mBAAc,GAAY,KAAK,CAAA;QAE/B;;;WAGG;QACH,cAAS,GAAY,KAAK,CAAA;QAE1B;;WAEG;QACH,WAAM,GAAY,KAAK,CAAA;QAEvB;;WAEG;QACH,YAAO,GAAY,KAAK,CAAA;QAExB;;;;;WAKG;QACH,uBAAkB,GAAY,IAAI,CAAA;QAOlC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,wBAAmB,GAAY,KAAK,CAAA;QAEpC;;WAEG;QACH,qBAAgB,GAAY,KAAK,CAAA;QAEjC;;WAEG;QACH,eAAU,GAAY,IAAI,CAAA;QAiB1B;;;;WAIG;QACH,gCAA2B,GAAY,IAAI,CAAA;QAS3C;;WAEG;QACH,a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AAmB,CAAC,MAAM;YAEjD,OAAO,IAAI,CAAC,YAAY,CAAA;QAE5B,OAAO,CACH,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC;YACnD,GAAG;YACH,IAAI,CAAC,YAAY,CACpB,CAAA;IACL,CAAC;CACJ;AApoBD,4CAooBC","file":"RelationMetadata.js","sourcesContent":["import { RelationType } from \"./types/RelationTypes\"\nimport { EntityMetadata } from \"./EntityMetadata\"\nimport { ForeignKeyMetadata } from \"./ForeignKeyMetadata\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"./ColumnMetadata\"\nimport { EmbeddedMetadata } from \"./EmbeddedMetadata\"\nimport { RelationMetadataArgs } from \"../metadata-args/RelationMetadataArgs\"\nimport { DeferrableType } from \"./types/DeferrableType\"\nimport { OnUpdateType } from \"./types/OnUpdateType\"\nimport { OnDeleteType } from \"./types/OnDeleteType\"\nimport { PropertyTypeFactory } from \"./types/PropertyTypeInFunction\"\nimport { TypeORMError } from \"../error\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Contains all information about some entity's relation.\n */\nexport class RelationMetadata {\n // ---------------------------------------------------------------------\n // Public Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity where this relation is placed.\n *\n * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.\n */\n entityMetadata: EntityMetadata\n\n /**\n * Entity metadata of the entity that is targeted by this relation.\n *\n * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.\n */\n inverseEntityMetadata: EntityMetadata\n\n /**\n * Entity metadata of the junction table.\n * Junction tables have their own entity metadata objects.\n * Defined only for many-to-many relations.\n */\n junctionEntityMetadata?: EntityMetadata\n\n /**\n * Embedded metadata where this relation is.\n * If this relation is not in embed then this property value is undefined.\n */\n embeddedMetadata?: EmbeddedMetadata\n\n /**\n * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.\n */\n relationType: RelationType\n\n /**\n * Target entity to which this relation is applied.\n * Target IS NOT equal to entityMetadata.target, because relation\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Post.\n * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.\n * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.\n * Target can be string if its defined in entity schema instead of class.\n */\n target: Function | string\n\n /**\n * Target's property name to which relation decorator is applied.\n */\n propertyName: string\n\n /**\n * Gets full path to this column property (including relation name).\n * Full path is relevant when column is used in embeds (one or multiple nested).\n * For example it will return \"counters.subcounters.likes\".\n * If property is not in embeds then it returns just property name of the column.\n */\n propertyPath: string\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n isTreeParent: boolean = false\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n isTreeChildren: boolean = false\n\n /**\n * Indicates if this relation's column is a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n isPrimary: boolean = false\n\n /**\n * Indicates if this relation is lazily loaded.\n */\n isLazy: boolean = false\n\n /**\n * Indicates if this relation is eagerly loaded.\n */\n isEager: boolean = false\n\n /**\n * Indicates if persistence is enabled for the relation.\n * By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistenceEnabled: boolean = true\n\n /**\n * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\"\n\n /**\n * If set to true then related objects are allowed to be inserted to the database.\n */\n isCascadeInsert: boolean = false\n\n /**\n * If set to true then related objects are allowed to be updated in the database.\n */\n isCascadeUpdate: boolean = false\n\n /**\n * If set to true then related objects are allowed to be remove from the database.\n */\n isCascadeRemove: boolean = false\n\n /**\n * If set to true then related objects are allowed to be soft-removed from the database.\n */\n isCascadeSoftRemove: boolean = false\n\n /**\n * If set to true then related objects are allowed to be recovered from the database.\n */\n isCascadeRecover: boolean = false\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n isNullable: boolean = true\n\n /**\n * What to do with a relation on deletion of the row containing a foreign key.\n */\n onDelete?: OnDeleteType\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n onUpdate?: OnUpdateType\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n deferrable?: DeferrableType\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints: boolean = true\n\n /**\n * Gets the property's type to which this relation is applied.\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Category.\n */\n type: Function | string\n\n /**\n * Indicates if this side is an owner of this relation.\n */\n isOwning: boolean = false\n\n /**\n * Checks if this relation's type is \"one-to-one\".\n */\n isOneToOne: boolean = false\n\n /**\n * Checks if this relation is owner side of the \"one-to-one\" relation.\n * Owner side means this side of relation has a join column in the table.\n */\n isOneToOneOwner: boolean = false\n\n /**\n * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).\n */\n isWithJoinColumn: boolean = false\n\n /**\n * Checks if this relation is NOT owner side of the \"one-to-one\" relation.\n * NOT owner side means this side of relation does not have a join column in the table.\n */\n isOneToOneNotOwner: boolean = false\n\n /**\n * Checks if this relation's type is \"one-to-many\".\n */\n isOneToMany: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-one\".\n */\n isManyToOne: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-many\".\n */\n isManyToMany: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is owner side of the relationship.\n * Owner side means this side of relation has a join table.\n */\n isManyToManyOwner: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is NOT owner side of the relationship.\n * Not owner side means this side of relation does not have a join table.\n */\n isManyToManyNotOwner: boolean = false\n\n /**\n * Gets the property path of the inverse side of the relation.\n */\n inverseSidePropertyPath: string\n\n /**\n * Inverse side of the relation set by user.\n *\n * Inverse side set in the relation can be either string - property name of the column on inverse side,\n * either can be a function that accepts a map of properties with the object and returns one of them.\n * Second approach is used to achieve type-safety.\n */\n givenInverseSidePropertyFactory: PropertyTypeFactory<any>\n\n /**\n * Gets the relation metadata of the inverse side of this relation.\n */\n inverseRelation?: RelationMetadata\n\n /**\n * Join table name.\n */\n joinTableName: string\n\n /**\n * Foreign keys created for this relation.\n */\n foreignKeys: ForeignKeyMetadata[] = []\n\n /**\n * Join table columns.\n * Join columns can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be empty.\n * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.\n * If this relation is many-to-many then it takes all owner join columns from the junction entity.\n */\n joinColumns: ColumnMetadata[] = []\n\n /**\n * Inverse join table columns.\n * Inverse join columns are supported only for many-to-many relations\n * and can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be undefined.\n */\n inverseJoinColumns: ColumnMetadata[] = []\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata\n embeddedMetadata?: EmbeddedMetadata\n args: RelationMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata\n this.embeddedMetadata = options.embeddedMetadata!\n const args = options.args\n this.target = args.target\n this.propertyName = args.propertyName\n this.relationType = args.relationType\n\n if (args.inverseSideProperty)\n this.givenInverseSidePropertyFactory = args.inverseSideProperty\n\n this.isLazy = args.isLazy || false\n // this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"insert\") !== -1);\n // this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"update\") !== -1);\n // this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"remove\") !== -1);\n // this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n // this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isCascadeInsert =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"insert\") !== -1)\n this.isCascadeUpdate =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"update\") !== -1)\n this.isCascadeRemove =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"remove\") !== -1)\n this.isCascadeSoftRemove =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"soft-remove\") !== -1)\n this.isCascadeRecover =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"recover\") !== -1)\n // this.isPrimary = args.options.primary || false;\n this.isNullable =\n args.options.nullable === false || this.isPrimary ? false : true\n this.onDelete = args.options.onDelete\n this.onUpdate = args.options.onUpdate\n this.deferrable = args.options.deferrable\n this.createForeignKeyConstraints =\n args.options.createForeignKeyConstraints === false ? false : true\n this.isEager = args.options.eager || false\n this.persistenceEnabled =\n args.options.persistence === false ? false : true\n this.orphanedRowAction = args.options.orphanedRowAction || \"nullify\"\n this.isTreeParent = args.isTreeParent || false\n this.isTreeChildren = args.isTreeChildren || false\n\n if (typeof args.type === \"function\") {\n this.type =\n typeof args.type === \"function\"\n ? (args.type as () => any)()\n : args.type\n } else if (InstanceChecker.isEntitySchema(args.type)) {\n this.type = args.type.options.name\n } else if (\n ObjectUtils.isObject(args.type) &&\n typeof (args.type as any).name === \"string\"\n ) {\n this.type = (args.type as any).name\n } else {\n this.type = args.type as string | Function\n }\n\n this.isOneToOne = this.relationType === \"one-to-one\"\n this.isOneToMany = this.relationType === \"one-to-many\"\n this.isManyToOne = this.relationType === \"many-to-one\"\n this.isManyToMany = this.relationType === \"many-to-many\"\n this.isOneToOneNotOwner = this.isOneToOne ? true : false\n this.isManyToManyNotOwner = this.isManyToMany ? true : false\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Creates join column ids map from the given related entity ids array.\n */\n getRelationIdMap(entity: ObjectLiteral): ObjectLiteral | undefined {\n const joinColumns = this.isOwning\n ? this.joinColumns\n : this.inverseRelation!.joinColumns\n const referencedColumns = joinColumns.map(\n (joinColumn) => joinColumn.referencedColumn!,\n )\n // console.log(\"entity\", entity);\n // console.log(\"referencedColumns\", referencedColumns);\n return EntityMetadata.getValueMap(entity, referencedColumns)\n }\n\n /**\n * Ensures that given object is an entity id map.\n * If given id is an object then it means its already id map.\n * If given id isn't an object then it means its a value of the id column\n * and it creates a new id map with this value and name of the primary column.\n */\n ensureRelationIdMap(id: any): ObjectLiteral {\n if (ObjectUtils.isObject(id)) return id\n\n const joinColumns = this.isOwning\n ? this.joinColumns\n : this.inverseRelation!.joinColumns\n const referencedColumns = joinColumns.map(\n (joinColumn) => joinColumn.referencedColumn!,\n )\n\n if (referencedColumns.length > 1)\n throw new TypeORMError(\n `Cannot create relation id map for a single value because relation contains multiple referenced columns.`,\n )\n\n return referencedColumns[0].createValueMap(id)\n }\n\n /**\n * Extracts column value from the given entity.\n * If column is in embedded (or recursive embedded) it extracts its value from there.\n */\n getEntityValue(\n entity: ObjectLiteral,\n getLazyRelationsPromiseValue: boolean = false,\n ): any | undefined {\n if (entity === null || entity === undefined) return undefined\n // extract column value from embeddeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames]\n\n // next we need to access post[data][information][counters][this.propertyName] to get column value from the counters\n // this recursive function takes array of generated property names and gets the post[data][information][counters] embed\n const extractEmbeddedColumnValue = (\n propertyNames: string[],\n value: ObjectLiteral,\n ): any => {\n const propertyName = propertyNames.shift()\n if (propertyName) {\n if (value[propertyName]) {\n return extractEmbeddedColumnValue(\n propertyNames,\n value[propertyName],\n )\n }\n return undefined\n }\n return value\n }\n\n // once we get nested embed object we get its column, e.g. post[data][information][counters][this.propertyName]\n const embeddedObject = extractEmbeddedColumnValue(\n propertyNames,\n entity,\n )\n\n if (this.isLazy) {\n if (\n embeddedObject[\"__\" + this.propertyName + \"__\"] !==\n undefined\n )\n return embeddedObject[\"__\" + this.propertyName + \"__\"]\n\n if (getLazyRelationsPromiseValue === true)\n return embeddedObject[this.propertyName]\n\n return undefined\n }\n return embeddedObject\n ? embeddedObject[\n this.isLazy\n ? \"__\" + this.propertyName + \"__\"\n : this.propertyName\n ]\n : undefined\n } else {\n // no embeds - no problems. Simply return column name by property name of the entity\n if (this.isLazy) {\n if (entity[\"__\" + this.propertyName + \"__\"] !== undefined)\n return entity[\"__\" + this.propertyName + \"__\"]\n\n if (getLazyRelationsPromiseValue === true)\n return entity[this.propertyName]\n\n return undefined\n }\n return entity[this.propertyName]\n }\n }\n\n /**\n * Sets given entity's relation's value.\n * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.\n *\n * If merge is set to true, it merges given value into currently\n */\n setEntityValue(entity: ObjectLiteral, value: any): void {\n const propertyName = this.isLazy\n ? \"__\" + this.propertyName + \"__\"\n : this.propertyName\n\n if (this.embeddedMetadata) {\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const extractEmbeddedColumnValue = (\n embeddedMetadatas: EmbeddedMetadata[],\n map: ObjectLiteral,\n ): any => {\n // if (!object[embeddedMetadata.propertyName])\n // object[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n const embeddedMetadata = embeddedMetadatas.shift()\n if (embeddedMetadata) {\n if (!map[embeddedMetadata.propertyName])\n map[embeddedMetadata.propertyName] =\n embeddedMetadata.create()\n\n extractEmbeddedColumnValue(\n embeddedMetadatas,\n map[embeddedMetadata.propertyName],\n )\n return map\n }\n map[propertyName] = value\n return map\n }\n return extractEmbeddedColumnValue(\n [...this.embeddedMetadata.embeddedMetadataTree],\n entity,\n )\n } else {\n entity[propertyName] = value\n }\n }\n\n /**\n * Creates entity id map from the given entity ids array.\n */\n createValueMap(value: any) {\n // extract column value from embeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object and return it in a\n // { data: { information: { counters: { id: ... } } } } format\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames]\n\n // now need to access post[data][information][counters] to get column value from the counters\n // and on each step we need to create complex literal object, e.g. first { data },\n // then { data: { information } }, then { data: { information: { counters } } },\n // then { data: { information: { counters: [this.propertyName]: entity[data][information][counters][this.propertyName] } } }\n // this recursive function helps doing that\n const extractEmbeddedColumnValue = (\n propertyNames: string[],\n map: ObjectLiteral,\n ): any => {\n const propertyName = propertyNames.shift()\n if (propertyName) {\n map[propertyName] = {}\n extractEmbeddedColumnValue(propertyNames, map[propertyName])\n return map\n }\n map[this.propertyName] = value\n return map\n }\n return extractEmbeddedColumnValue(propertyNames, {})\n } else {\n // no embeds - no problems. Simply return column property name and its value of the entity\n return { [this.propertyName]: value }\n }\n }\n\n // ---------------------------------------------------------------------\n // Builder Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds some depend relation metadata properties.\n * This builder method should be used only after embedded metadata tree was build.\n */\n build() {\n this.propertyPath = this.buildPropertyPath()\n }\n\n /**\n * Registers given foreign keys in the relation.\n * This builder method should be used to register foreign key in the relation.\n */\n registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {\n this.foreignKeys.push(...foreignKeys)\n }\n\n /**\n * Registers given join columns in the relation.\n * This builder method should be used to register join column in the relation.\n */\n registerJoinColumns(\n joinColumns: ColumnMetadata[] = [],\n inverseJoinColumns: ColumnMetadata[] = [],\n ) {\n this.joinColumns = joinColumns\n this.inverseJoinColumns = inverseJoinColumns\n this.isOwning =\n this.isManyToOne ||\n ((this.isManyToMany || this.isOneToOne) &&\n this.joinColumns.length > 0)\n this.isOneToOneOwner = this.isOneToOne && this.isOwning\n this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning\n this.isManyToManyOwner = this.isManyToMany && this.isOwning\n this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning\n this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner\n }\n\n /**\n * Registers a given junction entity metadata.\n * This builder method can be called after junction entity metadata for the many-to-many relation was created.\n */\n registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata) {\n this.junctionEntityMetadata = junctionEntityMetadata\n this.joinTableName = junctionEntityMetadata.tableName\n if (this.inverseRelation) {\n this.inverseRelation.junctionEntityMetadata = junctionEntityMetadata\n this.joinTableName = junctionEntityMetadata.tableName\n }\n }\n\n /**\n * Builds inverse side property path based on given inverse side property factory.\n * This builder method should be used only after properties map of the inverse entity metadata was build.\n */\n buildInverseSidePropertyPath(): string {\n if (this.givenInverseSidePropertyFactory) {\n const ownerEntityPropertiesMap =\n this.inverseEntityMetadata.propertiesMap\n if (typeof this.givenInverseSidePropertyFactory === \"function\")\n return this.givenInverseSidePropertyFactory(\n ownerEntityPropertiesMap,\n )\n\n if (typeof this.givenInverseSidePropertyFactory === \"string\")\n return this.givenInverseSidePropertyFactory\n } else if (\n this.isTreeParent &&\n this.entityMetadata.treeChildrenRelation\n ) {\n return this.entityMetadata.treeChildrenRelation.propertyName\n } else if (\n this.isTreeChildren &&\n this.entityMetadata.treeParentRelation\n ) {\n return this.entityMetadata.treeParentRelation.propertyName\n }\n\n return \"\"\n }\n\n /**\n * Builds relation's property path based on its embedded tree.\n */\n buildPropertyPath(): string {\n if (\n !this.embeddedMetadata ||\n !this.embeddedMetadata.parentPropertyNames.length\n )\n return this.propertyName\n\n return (\n this.embeddedMetadata.parentPropertyNames.join(\".\") +\n \".\" +\n this.propertyName\n )\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/metadata/RelationMetadata.ts"],"names":[],"mappings":";;;AACA,qDAAiD;AAUjD,oCAAuC;AACvC,qDAAiD;AACjD,6DAAyD;AAEzD;;GAEG;AACH,MAAa,gBAAgB;IAqQzB,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,YAAY,OAIX;QAhND;;WAEG;QACH,iBAAY,GAAY,KAAK,CAAA;QAE7B;;WAEG;QACH,mBAAc,GAAY,KAAK,CAAA;QAE/B;;;WAGG;QACH,cAAS,GAAY,KAAK,CAAA;QAE1B;;WAEG;QACH,WAAM,GAAY,KAAK,CAAA;QAEvB;;WAEG;QACH,YAAO,GAAY,KAAK,CAAA;QAExB;;;;;WAKG;QACH,uBAAkB,GAAY,IAAI,CAAA;QASlC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,wBAAmB,GAAY,KAAK,CAAA;QAEpC;;WAEG;QACH,qBAAgB,GAAY,KAAK,CAAA;QAEjC;;WAEG;QACH,eAAU,GAAY,IAAI,CAAA;QAiB1B;;;;WAIG;QACH,gCAA2B,GAAY,IAAI,CAAA;QAS3C;;WAEG;QACH,aAAQ,GAAY,KAAK,CAAA;QAEzB;;WAEG;QACH,eAAU,GAAY,KAAK,CAAA;QAE3B;;;WAGG;QACH,oBAAe,GAAY,KAAK,CAAA;QAEhC;;WAEG;QACH,qBAAgB,GAAY,KAAK,CAAA;QAEjC;;;WAGG;QACH,uBAAkB,GAAY,KAAK,CAAA;QAEnC;;WAEG;QACH,gBAAW,GAAY,KAAK,CAAA;QAE5B;;WAEG;QACH,gBAAW,GAAY,KAAK,CAAA;QAE5B;;WAEG;QACH,iBAAY,GAAY,KAAK,C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;YACtB,IAAI,CAAC,eAAe,CAAC,sBAAsB,GAAG,sBAAsB,CAAA;YACpE,IAAI,CAAC,aAAa,GAAG,sBAAsB,CAAC,SAAS,CAAA;SACxD;IACL,CAAC;IAED;;;OAGG;IACH,4BAA4B;QACxB,IAAI,IAAI,CAAC,+BAA+B,EAAE;YACtC,MAAM,wBAAwB,GAC1B,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAA;YAC5C,IAAI,OAAO,IAAI,CAAC,+BAA+B,KAAK,UAAU;gBAC1D,OAAO,IAAI,CAAC,+BAA+B,CACvC,wBAAwB,CAC3B,CAAA;YAEL,IAAI,OAAO,IAAI,CAAC,+BAA+B,KAAK,QAAQ;gBACxD,OAAO,IAAI,CAAC,+BAA+B,CAAA;SAClD;aAAM,IACH,IAAI,CAAC,YAAY;YACjB,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAC1C;YACE,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,YAAY,CAAA;SAC/D;aAAM,IACH,IAAI,CAAC,cAAc;YACnB,IAAI,CAAC,cAAc,CAAC,kBAAkB,EACxC;YACE,OAAO,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAA;SAC7D;QAED,OAAO,EAAE,CAAA;IACb,CAAC;IAED;;OAEG;IACH,iBAAiB;QACb,IACI,CAAC,IAAI,CAAC,gBAAgB;YACtB,CAAC,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM;YAEjD,OAAO,IAAI,CAAC,YAAY,CAAA;QAE5B,OAAO,CACH,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC;YACnD,GAAG;YACH,IAAI,CAAC,YAAY,CACpB,CAAA;IACL,CAAC;CACJ;AAtoBD,4CAsoBC","file":"RelationMetadata.js","sourcesContent":["import { RelationType } from \"./types/RelationTypes\"\nimport { EntityMetadata } from \"./EntityMetadata\"\nimport { ForeignKeyMetadata } from \"./ForeignKeyMetadata\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"./ColumnMetadata\"\nimport { EmbeddedMetadata } from \"./EmbeddedMetadata\"\nimport { RelationMetadataArgs } from \"../metadata-args/RelationMetadataArgs\"\nimport { DeferrableType } from \"./types/DeferrableType\"\nimport { OnUpdateType } from \"./types/OnUpdateType\"\nimport { OnDeleteType } from \"./types/OnDeleteType\"\nimport { PropertyTypeFactory } from \"./types/PropertyTypeInFunction\"\nimport { TypeORMError } from \"../error\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Contains all information about some entity's relation.\n */\nexport class RelationMetadata {\n // ---------------------------------------------------------------------\n // Public Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity where this relation is placed.\n *\n * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.\n */\n entityMetadata: EntityMetadata\n\n /**\n * Entity metadata of the entity that is targeted by this relation.\n *\n * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.\n */\n inverseEntityMetadata: EntityMetadata\n\n /**\n * Entity metadata of the junction table.\n * Junction tables have their own entity metadata objects.\n * Defined only for many-to-many relations.\n */\n junctionEntityMetadata?: EntityMetadata\n\n /**\n * Embedded metadata where this relation is.\n * If this relation is not in embed then this property value is undefined.\n */\n embeddedMetadata?: EmbeddedMetadata\n\n /**\n * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.\n */\n relationType: RelationType\n\n /**\n * Target entity to which this relation is applied.\n * Target IS NOT equal to entityMetadata.target, because relation\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Post.\n * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.\n * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.\n * Target can be string if its defined in entity schema instead of class.\n */\n target: Function | string\n\n /**\n * Target's property name to which relation decorator is applied.\n */\n propertyName: string\n\n /**\n * Gets full path to this column property (including relation name).\n * Full path is relevant when column is used in embeds (one or multiple nested).\n * For example it will return \"counters.subcounters.likes\".\n * If property is not in embeds then it returns just property name of the column.\n */\n propertyPath: string\n\n /**\n * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.\n */\n isTreeParent: boolean = false\n\n /**\n * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.\n */\n isTreeChildren: boolean = false\n\n /**\n * Indicates if this relation's column is a primary key.\n * Can be used only for many-to-one and owner one-to-one relations.\n */\n isPrimary: boolean = false\n\n /**\n * Indicates if this relation is lazily loaded.\n */\n isLazy: boolean = false\n\n /**\n * Indicates if this relation is eagerly loaded.\n */\n isEager: boolean = false\n\n /**\n * Indicates if persistence is enabled for the relation.\n * By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.\n * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.\n * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.\n */\n persistenceEnabled: boolean = true\n\n /**\n * When a parent is saved (with cascading but) without a child row that still exists in database, this will control what shall happen to them.\n * delete will remove these rows from database. nullify will remove the relation key.\n * skip will keep the relation intact. Removal of related item is only possible through its own repo.\n */\n orphanedRowAction?: \"nullify\" | \"delete\" | \"soft-delete\" | \"disable\"\n\n /**\n * If set to true then related objects are allowed to be inserted to the database.\n */\n isCascadeInsert: boolean = false\n\n /**\n * If set to true then related objects are allowed to be updated in the database.\n */\n isCascadeUpdate: boolean = false\n\n /**\n * If set to true then related objects are allowed to be remove from the database.\n */\n isCascadeRemove: boolean = false\n\n /**\n * If set to true then related objects are allowed to be soft-removed from the database.\n */\n isCascadeSoftRemove: boolean = false\n\n /**\n * If set to true then related objects are allowed to be recovered from the database.\n */\n isCascadeRecover: boolean = false\n\n /**\n * Indicates if relation column value can be nullable or not.\n */\n isNullable: boolean = true\n\n /**\n * What to do with a relation on deletion of the row containing a foreign key.\n */\n onDelete?: OnDeleteType\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n onUpdate?: OnUpdateType\n\n /**\n * What to do with a relation on update of the row containing a foreign key.\n */\n deferrable?: DeferrableType\n\n /**\n * Indicates whether foreign key constraints will be created for join columns.\n * Can be used only for many-to-one and owner one-to-one relations.\n * Defaults to true.\n */\n createForeignKeyConstraints: boolean = true\n\n /**\n * Gets the property's type to which this relation is applied.\n *\n * For example for @ManyToMany(type => Category) in Post, target will be Category.\n */\n type: Function | string\n\n /**\n * Indicates if this side is an owner of this relation.\n */\n isOwning: boolean = false\n\n /**\n * Checks if this relation's type is \"one-to-one\".\n */\n isOneToOne: boolean = false\n\n /**\n * Checks if this relation is owner side of the \"one-to-one\" relation.\n * Owner side means this side of relation has a join column in the table.\n */\n isOneToOneOwner: boolean = false\n\n /**\n * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).\n */\n isWithJoinColumn: boolean = false\n\n /**\n * Checks if this relation is NOT owner side of the \"one-to-one\" relation.\n * NOT owner side means this side of relation does not have a join column in the table.\n */\n isOneToOneNotOwner: boolean = false\n\n /**\n * Checks if this relation's type is \"one-to-many\".\n */\n isOneToMany: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-one\".\n */\n isManyToOne: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-many\".\n */\n isManyToMany: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is owner side of the relationship.\n * Owner side means this side of relation has a join table.\n */\n isManyToManyOwner: boolean = false\n\n /**\n * Checks if this relation's type is \"many-to-many\", and is NOT owner side of the relationship.\n * Not owner side means this side of relation does not have a join table.\n */\n isManyToManyNotOwner: boolean = false\n\n /**\n * Gets the property path of the inverse side of the relation.\n */\n inverseSidePropertyPath: string\n\n /**\n * Inverse side of the relation set by user.\n *\n * Inverse side set in the relation can be either string - property name of the column on inverse side,\n * either can be a function that accepts a map of properties with the object and returns one of them.\n * Second approach is used to achieve type-safety.\n */\n givenInverseSidePropertyFactory: PropertyTypeFactory<any>\n\n /**\n * Gets the relation metadata of the inverse side of this relation.\n */\n inverseRelation?: RelationMetadata\n\n /**\n * Join table name.\n */\n joinTableName: string\n\n /**\n * Foreign keys created for this relation.\n */\n foreignKeys: ForeignKeyMetadata[] = []\n\n /**\n * Join table columns.\n * Join columns can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be empty.\n * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.\n * If this relation is many-to-many then it takes all owner join columns from the junction entity.\n */\n joinColumns: ColumnMetadata[] = []\n\n /**\n * Inverse join table columns.\n * Inverse join columns are supported only for many-to-many relations\n * and can be obtained only from owner side of the relation.\n * From non-owner side of the relation join columns will be undefined.\n */\n inverseJoinColumns: ColumnMetadata[] = []\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata\n embeddedMetadata?: EmbeddedMetadata\n args: RelationMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata\n this.embeddedMetadata = options.embeddedMetadata!\n const args = options.args\n this.target = args.target\n this.propertyName = args.propertyName\n this.relationType = args.relationType\n\n if (args.inverseSideProperty)\n this.givenInverseSidePropertyFactory = args.inverseSideProperty\n\n this.isLazy = args.isLazy || false\n // this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"insert\") !== -1);\n // this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"update\") !== -1);\n // this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"remove\") !== -1);\n // this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"soft-remove\") !== -1);\n // this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf(\"recover\") !== -1);\n this.isCascadeInsert =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"insert\") !== -1)\n this.isCascadeUpdate =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"update\") !== -1)\n this.isCascadeRemove =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"remove\") !== -1)\n this.isCascadeSoftRemove =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"soft-remove\") !== -1)\n this.isCascadeRecover =\n args.options.cascade === true ||\n (Array.isArray(args.options.cascade) &&\n args.options.cascade.indexOf(\"recover\") !== -1)\n // this.isPrimary = args.options.primary || false;\n this.isNullable =\n args.options.nullable === false || this.isPrimary ? false : true\n this.onDelete = args.options.onDelete\n this.onUpdate = args.options.onUpdate\n this.deferrable = args.options.deferrable\n this.createForeignKeyConstraints =\n args.options.createForeignKeyConstraints === false ? false : true\n this.isEager = args.options.eager || false\n this.persistenceEnabled =\n args.options.persistence === false ? false : true\n this.orphanedRowAction = args.options.orphanedRowAction || \"nullify\"\n this.isTreeParent = args.isTreeParent || false\n this.isTreeChildren = args.isTreeChildren || false\n\n if (typeof args.type === \"function\") {\n this.type =\n typeof args.type === \"function\"\n ? (args.type as () => any)()\n : args.type\n } else if (InstanceChecker.isEntitySchema(args.type)) {\n this.type = args.type.options.name\n } else if (\n ObjectUtils.isObject(args.type) &&\n typeof (args.type as any).name === \"string\"\n ) {\n this.type = (args.type as any).name\n } else {\n this.type = args.type as string | Function\n }\n\n this.isOneToOne = this.relationType === \"one-to-one\"\n this.isOneToMany = this.relationType === \"one-to-many\"\n this.isManyToOne = this.relationType === \"many-to-one\"\n this.isManyToMany = this.relationType === \"many-to-many\"\n this.isOneToOneNotOwner = this.isOneToOne ? true : false\n this.isManyToManyNotOwner = this.isManyToMany ? true : false\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Creates join column ids map from the given related entity ids array.\n */\n getRelationIdMap(entity: ObjectLiteral): ObjectLiteral | undefined {\n const joinColumns = this.isOwning\n ? this.joinColumns\n : this.inverseRelation!.joinColumns\n const referencedColumns = joinColumns.map(\n (joinColumn) => joinColumn.referencedColumn!,\n )\n // console.log(\"entity\", entity);\n // console.log(\"referencedColumns\", referencedColumns);\n return EntityMetadata.getValueMap(entity, referencedColumns)\n }\n\n /**\n * Ensures that given object is an entity id map.\n * If given id is an object then it means its already id map.\n * If given id isn't an object then it means its a value of the id column\n * and it creates a new id map with this value and name of the primary column.\n */\n ensureRelationIdMap(id: any): ObjectLiteral {\n if (ObjectUtils.isObject(id)) return id\n\n const joinColumns = this.isOwning\n ? this.joinColumns\n : this.inverseRelation!.joinColumns\n const referencedColumns = joinColumns.map(\n (joinColumn) => joinColumn.referencedColumn!,\n )\n\n if (referencedColumns.length > 1)\n throw new TypeORMError(\n `Cannot create relation id map for a single value because relation contains multiple referenced columns.`,\n )\n\n return referencedColumns[0].createValueMap(id)\n }\n\n /**\n * Extracts column value from the given entity.\n * If column is in embedded (or recursive embedded) it extracts its value from there.\n */\n getEntityValue(\n entity: ObjectLiteral,\n getLazyRelationsPromiseValue: boolean = false,\n ): any | undefined {\n if (entity === null || entity === undefined) return undefined\n // extract column value from embeddeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames]\n\n // next we need to access post[data][information][counters][this.propertyName] to get column value from the counters\n // this recursive function takes array of generated property names and gets the post[data][information][counters] embed\n const extractEmbeddedColumnValue = (\n propertyNames: string[],\n value: ObjectLiteral,\n ): any => {\n const propertyName = propertyNames.shift()\n if (propertyName) {\n if (value[propertyName]) {\n return extractEmbeddedColumnValue(\n propertyNames,\n value[propertyName],\n )\n }\n return undefined\n }\n return value\n }\n\n // once we get nested embed object we get its column, e.g. post[data][information][counters][this.propertyName]\n const embeddedObject = extractEmbeddedColumnValue(\n propertyNames,\n entity,\n )\n\n if (this.isLazy) {\n if (\n embeddedObject[\"__\" + this.propertyName + \"__\"] !==\n undefined\n )\n return embeddedObject[\"__\" + this.propertyName + \"__\"]\n\n if (getLazyRelationsPromiseValue === true)\n return embeddedObject[this.propertyName]\n\n return undefined\n }\n return embeddedObject\n ? embeddedObject[\n this.isLazy\n ? \"__\" + this.propertyName + \"__\"\n : this.propertyName\n ]\n : undefined\n } else {\n // no embeds - no problems. Simply return column name by property name of the entity\n if (this.isLazy) {\n if (entity[\"__\" + this.propertyName + \"__\"] !== undefined)\n return entity[\"__\" + this.propertyName + \"__\"]\n\n if (getLazyRelationsPromiseValue === true)\n return entity[this.propertyName]\n\n return undefined\n }\n return entity[this.propertyName]\n }\n }\n\n /**\n * Sets given entity's relation's value.\n * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.\n *\n * If merge is set to true, it merges given value into currently\n */\n setEntityValue(entity: ObjectLiteral, value: any): void {\n const propertyName = this.isLazy\n ? \"__\" + this.propertyName + \"__\"\n : this.propertyName\n\n if (this.embeddedMetadata) {\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const extractEmbeddedColumnValue = (\n embeddedMetadatas: EmbeddedMetadata[],\n map: ObjectLiteral,\n ): any => {\n // if (!object[embeddedMetadata.propertyName])\n // object[embeddedMetadata.propertyName] = embeddedMetadata.create();\n\n const embeddedMetadata = embeddedMetadatas.shift()\n if (embeddedMetadata) {\n if (!map[embeddedMetadata.propertyName])\n map[embeddedMetadata.propertyName] =\n embeddedMetadata.create()\n\n extractEmbeddedColumnValue(\n embeddedMetadatas,\n map[embeddedMetadata.propertyName],\n )\n return map\n }\n map[propertyName] = value\n return map\n }\n return extractEmbeddedColumnValue(\n [...this.embeddedMetadata.embeddedMetadataTree],\n entity,\n )\n } else {\n entity[propertyName] = value\n }\n }\n\n /**\n * Creates entity id map from the given entity ids array.\n */\n createValueMap(value: any) {\n // extract column value from embeds of entity if column is in embedded\n if (this.embeddedMetadata) {\n // example: post[data][information][counters].id where \"data\", \"information\" and \"counters\" are embeddeds\n // we need to get value of \"id\" column from the post real entity object and return it in a\n // { data: { information: { counters: { id: ... } } } } format\n\n // first step - we extract all parent properties of the entity relative to this column, e.g. [data, information, counters]\n const propertyNames = [...this.embeddedMetadata.parentPropertyNames]\n\n // now need to access post[data][information][counters] to get column value from the counters\n // and on each step we need to create complex literal object, e.g. first { data },\n // then { data: { information } }, then { data: { information: { counters } } },\n // then { data: { information: { counters: [this.propertyName]: entity[data][information][counters][this.propertyName] } } }\n // this recursive function helps doing that\n const extractEmbeddedColumnValue = (\n propertyNames: string[],\n map: ObjectLiteral,\n ): any => {\n const propertyName = propertyNames.shift()\n if (propertyName) {\n map[propertyName] = {}\n extractEmbeddedColumnValue(propertyNames, map[propertyName])\n return map\n }\n map[this.propertyName] = value\n return map\n }\n return extractEmbeddedColumnValue(propertyNames, {})\n } else {\n // no embeds - no problems. Simply return column property name and its value of the entity\n return { [this.propertyName]: value }\n }\n }\n\n // ---------------------------------------------------------------------\n // Builder Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds some depend relation metadata properties.\n * This builder method should be used only after embedded metadata tree was build.\n */\n build() {\n this.propertyPath = this.buildPropertyPath()\n }\n\n /**\n * Registers given foreign keys in the relation.\n * This builder method should be used to register foreign key in the relation.\n */\n registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {\n this.foreignKeys.push(...foreignKeys)\n }\n\n /**\n * Registers given join columns in the relation.\n * This builder method should be used to register join column in the relation.\n */\n registerJoinColumns(\n joinColumns: ColumnMetadata[] = [],\n inverseJoinColumns: ColumnMetadata[] = [],\n ) {\n this.joinColumns = joinColumns\n this.inverseJoinColumns = inverseJoinColumns\n this.isOwning =\n this.isManyToOne ||\n ((this.isManyToMany || this.isOneToOne) &&\n this.joinColumns.length > 0)\n this.isOneToOneOwner = this.isOneToOne && this.isOwning\n this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning\n this.isManyToManyOwner = this.isManyToMany && this.isOwning\n this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning\n this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner\n }\n\n /**\n * Registers a given junction entity metadata.\n * This builder method can be called after junction entity metadata for the many-to-many relation was created.\n */\n registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata) {\n this.junctionEntityMetadata = junctionEntityMetadata\n this.joinTableName = junctionEntityMetadata.tableName\n if (this.inverseRelation) {\n this.inverseRelation.junctionEntityMetadata = junctionEntityMetadata\n this.joinTableName = junctionEntityMetadata.tableName\n }\n }\n\n /**\n * Builds inverse side property path based on given inverse side property factory.\n * This builder method should be used only after properties map of the inverse entity metadata was build.\n */\n buildInverseSidePropertyPath(): string {\n if (this.givenInverseSidePropertyFactory) {\n const ownerEntityPropertiesMap =\n this.inverseEntityMetadata.propertiesMap\n if (typeof this.givenInverseSidePropertyFactory === \"function\")\n return this.givenInverseSidePropertyFactory(\n ownerEntityPropertiesMap,\n )\n\n if (typeof this.givenInverseSidePropertyFactory === \"string\")\n return this.givenInverseSidePropertyFactory\n } else if (\n this.isTreeParent &&\n this.entityMetadata.treeChildrenRelation\n ) {\n return this.entityMetadata.treeChildrenRelation.propertyName\n } else if (\n this.isTreeChildren &&\n this.entityMetadata.treeParentRelation\n ) {\n return this.entityMetadata.treeParentRelation.propertyName\n }\n\n return \"\"\n }\n\n /**\n * Builds relation's property path based on its embedded tree.\n */\n buildPropertyPath(): string {\n if (\n !this.embeddedMetadata ||\n !this.embeddedMetadata.parentPropertyNames.length\n )\n return this.propertyName\n\n return (\n this.embeddedMetadata.parentPropertyNames.join(\".\") +\n \".\" +\n this.propertyName\n )\n }\n}\n"],"sourceRoot":".."}
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "typeorm", "private": false, "version": "0.3.10-dev.a1960e1", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">= 12.9.0" }, "exports": { ".": { "types": "./index.d.ts", "node": { "import": "./index.mjs", "require": "./index.js", "types": "./index.d.ts" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": { "types": "./index.d.ts", "default": "./browser/index.js" }, "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "homepage": "https://typeorm.io", "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "spanner", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm", "cloud-spanner", "cloud-spanner-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", "@types/debug": "^4.1.5", "@types/js-yaml": "^4.0.0", "@types/mkdirp": "^1.0.1", "@types/mocha": "^8.2.1", "@types/node": "^14.14.31", "@types/rimraf": "^3.0.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^9.0.10", "@types/source-map-support": "^0.5.3", "@types/uuid": "^8.3.4", "@types/xml2js": "^0.4.8", "@types/yargs": "^17.0.2", "better-sqlite3": "^7.1.2", "chai": "^4.3.0", "chai-as-promised": "^7.1.1", "class-transformer": "^0.4.0", "conventional-changelog-angular": "^5.0.12", "conventional-changelog-cli": "^2.1.1", "del": "^6.0.0", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.0.0", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^5.1.1", "mocha": "^8.3.0", "mongodb": "^3.6.4", "mssql": "^7.3.0", "mysql": "^2.18.1", "mysql2": "^2.2.5", "pg": "^8.5.1", "pg-query-stream": "^4.0.0", "prettier": "^2.5.1", "redis": "^3.1.1", "remap-istanbul": "^0.13.0", "rimraf": "^3.0.2", "sinon": "^9.2.4", "sinon-chai": "^3.5.0", "source-map-support": "^0.5.19", "sql.js": "^1.4.0", "sqlite3": "^5.0.11", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0", "typescript": "^4.8.2" }, "peerDependencies": { "@google-cloud/spanner": "^5.18.0", "@sap/hana-client": "^2.12.25", "better-sqlite3": "^7.1.2", "hdb-pool": "^0.1.6", "ioredis": "^5.0.4", "mongodb": "^3.6.0", "mssql": "^7.3.0", "mysql2": "^2.2.5", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1 || ^4.0.0", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@google-cloud/spanner": { "optional": true }, "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.2", "app-root-path": "^3.0.0", "buffer": "^6.0.3", "chalk": "^4.1.0", "cli-highlight": "^2.1.11", "date-fns": "^2.28.0", "debug": "^4.3.3", "dotenv": "^16.0.0", "glob": "^7.2.0", "js-yaml": "^4.1.0", "mkdirp": "^1.0.4", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.3.1", "uuid": "^8.3.2", "xml2js": "^0.4.23", "yargs": "^17.3.1" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
1
+ { "name": "typeorm", "private": false, "version": "0.3.10-dev.de15df1", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">= 12.9.0" }, "exports": { ".": { "types": "./index.d.ts", "node": { "import": "./index.mjs", "require": "./index.js", "types": "./index.d.ts" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": { "types": "./index.d.ts", "default": "./browser/index.js" }, "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "homepage": "https://typeorm.io", "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "spanner", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm", "cloud-spanner", "cloud-spanner-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", "@types/debug": "^4.1.5", "@types/js-yaml": "^4.0.0", "@types/mkdirp": "^1.0.1", "@types/mocha": "^8.2.1", "@types/node": "^14.14.31", "@types/rimraf": "^3.0.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^9.0.10", "@types/source-map-support": "^0.5.3", "@types/uuid": "^8.3.4", "@types/xml2js": "^0.4.8", "@types/yargs": "^17.0.2", "better-sqlite3": "^7.1.2", "chai": "^4.3.0", "chai-as-promised": "^7.1.1", "class-transformer": "^0.4.0", "conventional-changelog-angular": "^5.0.12", "conventional-changelog-cli": "^2.1.1", "del": "^6.0.0", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.0.0", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^5.1.1", "mocha": "^8.3.0", "mongodb": "^3.6.4", "mssql": "^7.3.0", "mysql": "^2.18.1", "mysql2": "^2.2.5", "pg": "^8.5.1", "pg-query-stream": "^4.0.0", "prettier": "^2.5.1", "redis": "^3.1.1", "remap-istanbul": "^0.13.0", "rimraf": "^3.0.2", "sinon": "^9.2.4", "sinon-chai": "^3.5.0", "source-map-support": "^0.5.19", "sql.js": "^1.4.0", "sqlite3": "^5.0.11", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0", "typescript": "^4.8.2" }, "peerDependencies": { "@google-cloud/spanner": "^5.18.0", "@sap/hana-client": "^2.12.25", "better-sqlite3": "^7.1.2", "hdb-pool": "^0.1.6", "ioredis": "^5.0.4", "mongodb": "^3.6.0", "mssql": "^7.3.0", "mysql2": "^2.2.5", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1 || ^4.0.0", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@google-cloud/spanner": { "optional": true }, "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.2", "app-root-path": "^3.0.0", "buffer": "^6.0.3", "chalk": "^4.1.0", "cli-highlight": "^2.1.11", "date-fns": "^2.28.0", "debug": "^4.3.3", "dotenv": "^16.0.0", "glob": "^7.2.0", "js-yaml": "^4.1.0", "mkdirp": "^1.0.4", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.3.1", "uuid": "^8.3.2", "xml2js": "^0.4.23", "yargs": "^17.3.1" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
@@ -50,6 +50,7 @@ class OneToManySubjectBuilder {
50
50
  // prepare objects (relation id maps) for the database entity
51
51
  // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,
52
52
  // particularly their relation ids, e.g. category ids stored in the database
53
+ var _a;
53
54
  // in most cases relatedEntityDatabaseValues will contain only the entity key properties.
54
55
  // this is because subject.databaseEntity contains relations with loaded relation ids only.
55
56
  // however if the entity uses the afterLoad hook to calculate any properties, the fetched "key object" might include ADDITIONAL properties.
@@ -144,34 +145,36 @@ class OneToManySubjectBuilder {
144
145
  relatedPersistedEntityRelationIds.push(relationIdMap);
145
146
  });
146
147
  // find what related entities were added and what were removed based on difference between what we save and what database has
147
- EntityMetadata_1.EntityMetadata.difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds).forEach((removedRelatedEntityRelationId) => {
148
- // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind
149
- // todo: probably we can improve this in the future by finding entity with column those values,
150
- // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns
151
- // we create a new subject which operations will be executed in subject operation executor
152
- const removedRelatedEntitySubject = new Subject_1.Subject({
153
- metadata: relation.inverseEntityMetadata,
154
- parentSubject: subject,
155
- identifier: removedRelatedEntityRelationId,
148
+ if (((_a = relation.inverseRelation) === null || _a === void 0 ? void 0 : _a.orphanedRowAction) !== "disable") {
149
+ EntityMetadata_1.EntityMetadata.difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds).forEach((removedRelatedEntityRelationId) => {
150
+ // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind
151
+ // todo: probably we can improve this in the future by finding entity with column those values,
152
+ // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns
153
+ // we create a new subject which operations will be executed in subject operation executor
154
+ const removedRelatedEntitySubject = new Subject_1.Subject({
155
+ metadata: relation.inverseEntityMetadata,
156
+ parentSubject: subject,
157
+ identifier: removedRelatedEntityRelationId,
158
+ });
159
+ if (!relation.inverseRelation ||
160
+ relation.inverseRelation.orphanedRowAction === "nullify") {
161
+ removedRelatedEntitySubject.canBeUpdated = true;
162
+ removedRelatedEntitySubject.changeMaps = [
163
+ {
164
+ relation: relation.inverseRelation,
165
+ value: null,
166
+ },
167
+ ];
168
+ }
169
+ else if (relation.inverseRelation.orphanedRowAction === "delete") {
170
+ removedRelatedEntitySubject.mustBeRemoved = true;
171
+ }
172
+ else if (relation.inverseRelation.orphanedRowAction === "soft-delete") {
173
+ removedRelatedEntitySubject.canBeSoftRemoved = true;
174
+ }
175
+ this.subjects.push(removedRelatedEntitySubject);
156
176
  });
157
- if (!relation.inverseRelation ||
158
- relation.inverseRelation.orphanedRowAction === "nullify") {
159
- removedRelatedEntitySubject.canBeUpdated = true;
160
- removedRelatedEntitySubject.changeMaps = [
161
- {
162
- relation: relation.inverseRelation,
163
- value: null,
164
- },
165
- ];
166
- }
167
- else if (relation.inverseRelation.orphanedRowAction === "delete") {
168
- removedRelatedEntitySubject.mustBeRemoved = true;
169
- }
170
- else if (relation.inverseRelation.orphanedRowAction === "soft-delete") {
171
- removedRelatedEntitySubject.canBeSoftRemoved = true;
172
- }
173
- this.subjects.push(removedRelatedEntitySubject);
174
- });
177
+ }
175
178
  }
176
179
  }
177
180
  exports.OneToManySubjectBuilder = OneToManySubjectBuilder;