@mikro-orm/core 7.2.0-dev.2 → 7.2.0-dev.21

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 (86) hide show
  1. package/EntityManager.d.ts +42 -8
  2. package/EntityManager.js +256 -70
  3. package/MikroORM.d.ts +4 -0
  4. package/MikroORM.js +9 -0
  5. package/cache/CacheAdapter.d.ts +6 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +7 -2
  8. package/connections/Connection.d.ts +10 -1
  9. package/connections/Connection.js +9 -0
  10. package/drivers/DatabaseDriver.d.ts +17 -1
  11. package/drivers/DatabaseDriver.js +203 -41
  12. package/drivers/IDatabaseDriver.d.ts +1 -0
  13. package/entity/Collection.js +4 -2
  14. package/entity/EntityFactory.js +6 -0
  15. package/entity/EntityLoader.d.ts +7 -1
  16. package/entity/EntityLoader.js +46 -11
  17. package/entity/EntityRepository.d.ts +4 -5
  18. package/entity/EntityRepository.js +7 -2
  19. package/entity/defineEntity.d.ts +48 -14
  20. package/entity/defineEntity.js +32 -1
  21. package/enums.d.ts +5 -1
  22. package/enums.js +2 -0
  23. package/errors.d.ts +36 -0
  24. package/errors.js +90 -0
  25. package/events/EventManager.js +6 -3
  26. package/exceptions.d.ts +5 -0
  27. package/exceptions.js +5 -0
  28. package/hydration/ObjectHydrator.d.ts +2 -0
  29. package/hydration/ObjectHydrator.js +15 -8
  30. package/index.d.ts +1 -1
  31. package/metadata/EntitySchema.js +5 -2
  32. package/metadata/MetadataDiscovery.d.ts +3 -0
  33. package/metadata/MetadataDiscovery.js +161 -28
  34. package/metadata/MetadataProvider.js +1 -1
  35. package/metadata/MetadataStorage.d.ts +4 -3
  36. package/metadata/MetadataStorage.js +32 -2
  37. package/metadata/Routine.js +4 -1
  38. package/metadata/types.d.ts +19 -3
  39. package/naming-strategy/AbstractNamingStrategy.js +2 -1
  40. package/naming-strategy/NamingStrategy.d.ts +2 -1
  41. package/package.json +1 -1
  42. package/platforms/Platform.d.ts +24 -3
  43. package/platforms/Platform.js +63 -1
  44. package/types/BigIntType.d.ts +1 -0
  45. package/types/BigIntType.js +23 -0
  46. package/types/DateTimeType.d.ts +1 -0
  47. package/types/DateTimeType.js +8 -0
  48. package/types/StringType.d.ts +14 -3
  49. package/types/StringType.js +34 -4
  50. package/types/TextType.d.ts +2 -4
  51. package/types/TextType.js +2 -8
  52. package/types/Type.d.ts +11 -0
  53. package/types/Type.js +4 -4
  54. package/types/index.d.ts +2 -2
  55. package/typings.d.ts +58 -2
  56. package/typings.js +24 -1
  57. package/unit-of-work/ChangeSet.js +10 -7
  58. package/unit-of-work/ChangeSetPersister.js +32 -20
  59. package/unit-of-work/UnitOfWork.js +11 -4
  60. package/utils/AbstractMigrator.d.ts +1 -1
  61. package/utils/AbstractMigrator.js +3 -2
  62. package/utils/Configuration.d.ts +15 -1
  63. package/utils/Configuration.js +13 -2
  64. package/utils/Cursor.d.ts +2 -0
  65. package/utils/Cursor.js +44 -39
  66. package/utils/DataloaderUtils.js +2 -1
  67. package/utils/EntityComparator.d.ts +2 -0
  68. package/utils/EntityComparator.js +11 -4
  69. package/utils/QueryHelper.d.ts +17 -0
  70. package/utils/QueryHelper.js +100 -4
  71. package/utils/RawQueryFragment.d.ts +6 -0
  72. package/utils/RawQueryFragment.js +15 -6
  73. package/utils/RequestContext.d.ts +2 -2
  74. package/utils/RequestContext.js +11 -2
  75. package/utils/TransactionManager.d.ts +6 -0
  76. package/utils/TransactionManager.js +36 -3
  77. package/utils/Utils.d.ts +14 -2
  78. package/utils/Utils.js +36 -6
  79. package/utils/clone.js +6 -0
  80. package/utils/env-vars.js +1 -0
  81. package/utils/index.d.ts +1 -0
  82. package/utils/index.js +1 -0
  83. package/utils/rls-utils.d.ts +35 -0
  84. package/utils/rls-utils.js +97 -0
  85. package/utils/upsert-utils.d.ts +9 -1
  86. package/utils/upsert-utils.js +26 -3
@@ -72,6 +72,22 @@ export function getOnConflictFields(meta, data, uniqueFields, options) {
72
72
  }
73
73
  return keys;
74
74
  }
75
+ /**
76
+ * Detects properties that will get their value generated by an `onCreate` hook during the upsert,
77
+ * i.e. those with an `onCreate` hook and no value provided. Such values are meant for the insert
78
+ * clause only and must not overwrite an existing row via the `on conflict do update set` clause.
79
+ * The property filter mirrors `EntityFactory.assignDefaultValues`.
80
+ * @internal
81
+ */
82
+ export function getOnCreateGeneratedFields(meta, data) {
83
+ return meta.props
84
+ .filter(prop => prop.onCreate &&
85
+ !prop.embedded &&
86
+ ![ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) &&
87
+ !(prop.getter && !prop.setter) &&
88
+ data[prop.name] == null)
89
+ .map(prop => prop.name);
90
+ }
75
91
  /** @internal */
76
92
  export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
77
93
  /* v8 ignore next */
@@ -122,7 +138,14 @@ function getPropertyValue(obj, key) {
122
138
  }
123
139
  /** @internal */
124
140
  export function getWhereCondition(meta, onConflictFields, data, where) {
125
- const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
141
+ // TPT children do not inherit the unique flags and indexes of their parent tables
142
+ const uniqueProps = new Set();
143
+ const uniques = [];
144
+ for (let current = meta; current; current = current.tptParent) {
145
+ current.props.filter(p => p.unique).forEach(p => uniqueProps.add(p.name));
146
+ uniques.push(...current.uniques);
147
+ }
148
+ const unique = onConflictFields ?? [...uniqueProps];
126
149
  const propIndex = !isRaw(unique) &&
127
150
  unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
128
151
  if (onConflictFields || where == null) {
@@ -136,8 +159,8 @@ export function getWhereCondition(meta, onConflictFields, data, where) {
136
159
  }
137
160
  where = { [key]: getPropertyValue(data, unique[propIndex]) };
138
161
  }
139
- else if (meta.uniques.length > 0) {
140
- for (const u of meta.uniques) {
162
+ else {
163
+ for (const u of uniques) {
141
164
  if (Utils.asArray(u.properties).every(p => data[p] != null)) {
142
165
  where = Utils.asArray(u.properties).reduce((o, key) => {
143
166
  o[key] = data[key];