@strapi/database 4.14.5 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -210,8 +210,7 @@ const SQL_QUERIES$3 = {
210
210
  )
211
211
  };
212
212
  const toStrapiType$2 = (column) => {
213
- var _a;
214
- const rootType = (_a = column.data_type.toLowerCase().match(/[^(), ]+/)) == null ? void 0 : _a[0];
213
+ const rootType = column.data_type.toLowerCase().match(/[^(), ]+/)?.[0];
215
214
  switch (rootType) {
216
215
  case "integer": {
217
216
  return { type: "integer" };
@@ -506,8 +505,7 @@ const SQL_QUERIES$2 = {
506
505
  )
507
506
  };
508
507
  const toStrapiType$1 = (column) => {
509
- var _a;
510
- const rootType = (_a = column.data_type.toLowerCase().match(/[^(), ]+/)) == null ? void 0 : _a[0];
508
+ const rootType = column.data_type.toLowerCase().match(/[^(), ]+/)?.[0];
511
509
  switch (rootType) {
512
510
  case "int": {
513
511
  if (column.column_key === "PRI") {
@@ -742,9 +740,8 @@ class MysqlDialect extends Dialect {
742
740
  return true;
743
741
  }
744
742
  supportsWindowFunctions() {
745
- var _a, _b, _c;
746
- const isMysqlDB = !((_a = this.info) == null ? void 0 : _a.database) || this.info.database === MYSQL;
747
- const isBeforeV8 = !semver.valid((_b = this.info) == null ? void 0 : _b.version) || semver.lt(((_c = this.info) == null ? void 0 : _c.version) ?? "", "8.0.0");
743
+ const isMysqlDB = !this.info?.database || this.info.database === MYSQL;
744
+ const isBeforeV8 = !semver.valid(this.info?.version) || semver.lt(this.info?.version ?? "", "8.0.0");
748
745
  if (isMysqlDB && isBeforeV8) {
749
746
  return false;
750
747
  }
@@ -765,9 +762,8 @@ const SQL_QUERIES = {
765
762
  FOREIGN_KEY_LIST: "pragma foreign_key_list(??)"
766
763
  };
767
764
  const toStrapiType = (column) => {
768
- var _a;
769
765
  const { type } = column;
770
- const rootType = (_a = type.toLowerCase().match(/[^(), ]+/)) == null ? void 0 : _a[0];
766
+ const rootType = type.toLowerCase().match(/[^(), ]+/)?.[0];
771
767
  switch (rootType) {
772
768
  case "integer": {
773
769
  if (column.pk) {
@@ -1043,8 +1039,7 @@ const createSchemaBuilder = (db) => {
1043
1039
  */
1044
1040
  // TODO: implement force option to disable removal in DB
1045
1041
  async updateSchema(schemaDiff) {
1046
- var _a;
1047
- const forceMigration = (_a = db.config.settings) == null ? void 0 : _a.forceMigration;
1042
+ const forceMigration = db.config.settings?.forceMigration;
1048
1043
  await db.dialect.startSchemaUpdate();
1049
1044
  await db.connection.transaction(async (trx) => {
1050
1045
  await this.createTables(schemaDiff.tables.added, trx);
@@ -1100,8 +1095,7 @@ const createHelpers = (db) => {
1100
1095
  }
1101
1096
  };
1102
1097
  const dropIndex = (tableBuilder, index2) => {
1103
- var _a;
1104
- if (!((_a = db.config.settings) == null ? void 0 : _a.forceMigration)) {
1098
+ if (!db.config.settings?.forceMigration) {
1105
1099
  return;
1106
1100
  }
1107
1101
  const { type, columns, name } = index2;
@@ -1139,8 +1133,7 @@ const createHelpers = (db) => {
1139
1133
  return col;
1140
1134
  };
1141
1135
  const dropColumn = (tableBuilder, column) => {
1142
- var _a;
1143
- if (!((_a = db.config.settings) == null ? void 0 : _a.forceMigration)) {
1136
+ if (!db.config.settings?.forceMigration) {
1144
1137
  return;
1145
1138
  }
1146
1139
  return tableBuilder.dropColumn(column.name);
@@ -1519,7 +1512,7 @@ const createSchemaDiff = (db) => {
1519
1512
  for (const srcTable of srcSchema.tables) {
1520
1513
  if (!helpers.hasTable(destSchema, srcTable.name) && !reservedTables.includes(srcTable.name)) {
1521
1514
  const dependencies = persistedTables.filter((table) => {
1522
- const dependsOn = table == null ? void 0 : table.dependsOn;
1515
+ const dependsOn = table?.dependsOn;
1523
1516
  if (!_.isArray(dependsOn)) {
1524
1517
  return;
1525
1518
  }
@@ -3211,7 +3204,7 @@ const morphToMany = async (input, ctx) => {
3211
3204
  continue;
3212
3205
  }
3213
3206
  const qb2 = db.entityManager.createQueryBuilder(type);
3214
- const rows = await qb2.init((on == null ? void 0 : on[type]) ?? typePopulate).addSelect(`${qb2.alias}.${idColumn.referencedColumn}`).where({ [idColumn.referencedColumn]: ids }).execute({ mapResults: false });
3207
+ const rows = await qb2.init(on?.[type] ?? typePopulate).addSelect(`${qb2.alias}.${idColumn.referencedColumn}`).where({ [idColumn.referencedColumn]: ids }).execute({ mapResults: false });
3215
3208
  map2[type] = _.groupBy(idColumn.referencedColumn)(rows);
3216
3209
  }
3217
3210
  results.forEach((result) => {
@@ -3257,7 +3250,7 @@ const morphToOne = async (input, ctx) => {
3257
3250
  return;
3258
3251
  }
3259
3252
  const qb = db.entityManager.createQueryBuilder(type);
3260
- const rows = await qb.init((on == null ? void 0 : on[type]) ?? typePopulate).addSelect(`${qb.alias}.${idColumn.referencedColumn}`).where({ [idColumn.referencedColumn]: ids }).execute({ mapResults: false });
3253
+ const rows = await qb.init(on?.[type] ?? typePopulate).addSelect(`${qb.alias}.${idColumn.referencedColumn}`).where({ [idColumn.referencedColumn]: ids }).execute({ mapResults: false });
3261
3254
  map2[type] = _.groupBy(idColumn.referencedColumn)(rows);
3262
3255
  }
3263
3256
  results.forEach((result) => {
@@ -3809,15 +3802,15 @@ const transactionCtx = {
3809
3802
  },
3810
3803
  get() {
3811
3804
  const store = storage.getStore();
3812
- return store == null ? void 0 : store.trx;
3805
+ return store?.trx;
3813
3806
  },
3814
3807
  async commit(trx) {
3815
3808
  const store = storage.getStore();
3816
- if (store == null ? void 0 : store.trx) {
3809
+ if (store?.trx) {
3817
3810
  store.trx = null;
3818
3811
  }
3819
3812
  await trx.commit();
3820
- if (!(store == null ? void 0 : store.commitCallbacks.length)) {
3813
+ if (!store?.commitCallbacks.length) {
3821
3814
  return;
3822
3815
  }
3823
3816
  store.commitCallbacks.forEach((cb) => cb());
@@ -3825,11 +3818,11 @@ const transactionCtx = {
3825
3818
  },
3826
3819
  async rollback(trx) {
3827
3820
  const store = storage.getStore();
3828
- if (store == null ? void 0 : store.trx) {
3821
+ if (store?.trx) {
3829
3822
  store.trx = null;
3830
3823
  }
3831
3824
  await trx.rollback();
3832
- if (!(store == null ? void 0 : store.rollbackCallbacks.length)) {
3825
+ if (!store?.rollbackCallbacks.length) {
3833
3826
  return;
3834
3827
  }
3835
3828
  store.rollbackCallbacks.forEach((cb) => cb());
@@ -3837,13 +3830,13 @@ const transactionCtx = {
3837
3830
  },
3838
3831
  onCommit(cb) {
3839
3832
  const store = storage.getStore();
3840
- if (store == null ? void 0 : store.commitCallbacks) {
3833
+ if (store?.commitCallbacks) {
3841
3834
  store.commitCallbacks.push(cb);
3842
3835
  }
3843
3836
  },
3844
3837
  onRollback(cb) {
3845
3838
  const store = storage.getStore();
3846
- if (store == null ? void 0 : store.rollbackCallbacks) {
3839
+ if (store?.rollbackCallbacks) {
3847
3840
  store.rollbackCallbacks.push(cb);
3848
3841
  }
3849
3842
  }
@@ -4382,7 +4375,7 @@ const getMorphToManyRowsLinkedToMorphOne = (rows, {
4382
4375
  const relatedType = row[typeColumn.name];
4383
4376
  const field = row.field;
4384
4377
  const targetAttribute = db.metadata.get(relatedType).attributes[field];
4385
- return (targetAttribute == null ? void 0 : targetAttribute.target) === uid && (targetAttribute == null ? void 0 : targetAttribute.morphBy) === attributeName && (targetAttribute == null ? void 0 : targetAttribute.relation) === "morphOne";
4378
+ return targetAttribute?.target === uid && targetAttribute?.morphBy === attributeName && targetAttribute?.relation === "morphOne";
4386
4379
  });
4387
4380
  const deleteRelatedMorphOneRelationsAfterMorphToManyUpdate = async (rows, {
4388
4381
  uid,
@@ -4474,7 +4467,6 @@ const deleteRelations = async ({
4474
4467
  relIdsToDelete = [],
4475
4468
  transaction: trx
4476
4469
  }) => {
4477
- var _a;
4478
4470
  const { joinTable } = attribute;
4479
4471
  const { joinColumn, inverseJoinColumn } = joinTable;
4480
4472
  const all = relIdsToDelete === "all";
@@ -4490,7 +4482,7 @@ const deleteRelations = async ({
4490
4482
  ...all ? {} : { [inverseJoinColumn.name]: { $in: relIdsToDelete } }
4491
4483
  }).where(joinTable.on || {}).orderBy("id").limit(batchSize).transacting(trx).execute();
4492
4484
  done = batchToDelete.length < batchSize;
4493
- lastId = ((_a = batchToDelete[batchToDelete.length - 1]) == null ? void 0 : _a.id) || 0;
4485
+ lastId = batchToDelete[batchToDelete.length - 1]?.id || 0;
4494
4486
  const batchIds = map(inverseJoinColumn.name, batchToDelete);
4495
4487
  await createQueryBuilder(joinTable.name, db).delete().where({
4496
4488
  [joinColumn.name]: id,
@@ -4677,8 +4669,7 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
4677
4669
  {}
4678
4670
  );
4679
4671
  const mappedRelations = connectArr.reduce((mapper, relation) => {
4680
- var _a, _b;
4681
- const adjacentRelId = ((_a = relation.position) == null ? void 0 : _a.before) || ((_b = relation.position) == null ? void 0 : _b.after);
4672
+ const adjacentRelId = relation.position?.before || relation.position?.after;
4682
4673
  if (!adjacentRelId || !relationInInitialArray[adjacentRelId] && !mapper[adjacentRelId]) {
4683
4674
  needsSorting = true;
4684
4675
  }
@@ -4695,15 +4686,14 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
4695
4686
  if (!needsSorting)
4696
4687
  return connectArr;
4697
4688
  const computeRelation = (relation, relationsSeenInBranch) => {
4698
- var _a, _b, _c;
4699
- const adjacentRelId = ((_a = relation.position) == null ? void 0 : _a.before) || ((_b = relation.position) == null ? void 0 : _b.after);
4689
+ const adjacentRelId = relation.position?.before || relation.position?.after;
4700
4690
  const adjacentRelation = mappedRelations[adjacentRelId];
4701
4691
  if (adjacentRelId && relationsSeenInBranch[adjacentRelId]) {
4702
4692
  throw new InvalidRelationError(
4703
4693
  "A circular reference was found in the connect array. One relation is trying to connect before/after another one that is trying to connect before/after it"
4704
4694
  );
4705
4695
  }
4706
- if ((_c = mappedRelations[relation.id]) == null ? void 0 : _c.computed) {
4696
+ if (mappedRelations[relation.id]?.computed) {
4707
4697
  return;
4708
4698
  }
4709
4699
  mappedRelations[relation.id].computed = true;
@@ -4728,13 +4718,12 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
4728
4718
  return sortedConnect;
4729
4719
  };
4730
4720
  const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
4731
- var _a;
4732
4721
  const computedRelations = castArray(initArr ?? []).map((r) => ({
4733
4722
  init: true,
4734
4723
  id: r[idColumn],
4735
4724
  order: Number(r[orderColumn]) || 1
4736
4725
  }));
4737
- const maxOrder = ((_a = maxBy("order", computedRelations)) == null ? void 0 : _a.order) || 0;
4726
+ const maxOrder = maxBy("order", computedRelations)?.order || 0;
4738
4727
  const findRelation = (id) => {
4739
4728
  const idx = computedRelations.findIndex((r) => r.id === id);
4740
4729
  return { idx, relation: computedRelations[idx] };
@@ -4746,9 +4735,8 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
4746
4735
  }
4747
4736
  };
4748
4737
  const insertRelation = (r) => {
4749
- var _a2, _b, _c;
4750
4738
  let idx;
4751
- if ((_a2 = r.position) == null ? void 0 : _a2.before) {
4739
+ if (r.position?.before) {
4752
4740
  const { idx: _idx, relation } = findRelation(r.position.before);
4753
4741
  if (relation.init) {
4754
4742
  r.order = relation.order - 0.5;
@@ -4756,7 +4744,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
4756
4744
  r.order = relation.order;
4757
4745
  }
4758
4746
  idx = _idx;
4759
- } else if ((_b = r.position) == null ? void 0 : _b.after) {
4747
+ } else if (r.position?.after) {
4760
4748
  const { idx: _idx, relation } = findRelation(r.position.after);
4761
4749
  if (relation.init) {
4762
4750
  r.order = relation.order + 0.5;
@@ -4764,7 +4752,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
4764
4752
  r.order = relation.order;
4765
4753
  }
4766
4754
  idx = _idx + 1;
4767
- } else if ((_c = r.position) == null ? void 0 : _c.start) {
4755
+ } else if (r.position?.start) {
4768
4756
  r.order = 0.5;
4769
4757
  idx = 0;
4770
4758
  } else {
@@ -4803,8 +4791,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
4803
4791
  */
4804
4792
  getOrderMap() {
4805
4793
  return _$1(computedRelations).groupBy("order").reduce((acc, relations) => {
4806
- var _a2;
4807
- if ((_a2 = relations[0]) == null ? void 0 : _a2.init)
4794
+ if (relations[0]?.init)
4808
4795
  return acc;
4809
4796
  relations.forEach((relation, idx) => {
4810
4797
  acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
@@ -4889,27 +4876,26 @@ const toIdArray = (data) => {
4889
4876
  return uniqWith(isEqual, array);
4890
4877
  };
4891
4878
  const toAssocs = (data) => {
4892
- var _a;
4893
4879
  if (isArray(data) || isString$1(data) || isNumber$1(data) || isNull(data) || isRecord(data) && "id" in data) {
4894
4880
  return {
4895
4881
  set: isNull(data) ? data : toIdArray(data)
4896
4882
  };
4897
4883
  }
4898
- if (data == null ? void 0 : data.set) {
4884
+ if (data?.set) {
4899
4885
  return {
4900
4886
  set: isNull(data.set) ? data.set : toIdArray(data.set)
4901
4887
  };
4902
4888
  }
4903
4889
  return {
4904
4890
  options: {
4905
- strict: (_a = data == null ? void 0 : data.options) == null ? void 0 : _a.strict
4891
+ strict: data?.options?.strict
4906
4892
  },
4907
- connect: toIdArray(data == null ? void 0 : data.connect).map((elm) => ({
4893
+ connect: toIdArray(data?.connect).map((elm) => ({
4908
4894
  id: elm.id,
4909
4895
  position: elm.position ? elm.position : { end: true },
4910
4896
  __pivot: elm.__pivot ?? {}
4911
4897
  })),
4912
- disconnect: toIdArray(data == null ? void 0 : data.disconnect)
4898
+ disconnect: toIdArray(data?.disconnect)
4913
4899
  };
4914
4900
  };
4915
4901
  const processData = (metadata, data = {}, { withDefaults = false } = {}) => {
@@ -5035,7 +5021,7 @@ const createEntityManager = (db) => {
5035
5021
  const createdEntries = await this.createQueryBuilder(uid).insert(dataToInsert).execute();
5036
5022
  const result = {
5037
5023
  count: data.length,
5038
- ids: createdEntries.map((entry) => typeof entry === "object" ? entry == null ? void 0 : entry.id : entry)
5024
+ ids: createdEntries.map((entry) => typeof entry === "object" ? entry?.id : entry)
5039
5025
  };
5040
5026
  await db.lifecycles.run("afterCreateMany", uid, { params, result }, states);
5041
5027
  return result;
@@ -5174,7 +5160,6 @@ const createEntityManager = (db) => {
5174
5160
  * Attach relations to a new entity
5175
5161
  */
5176
5162
  async attachRelations(uid, id, data, options) {
5177
- var _a, _b, _c;
5178
5163
  const { attributes } = db.metadata.get(uid);
5179
5164
  const { transaction: trx } = options ?? {};
5180
5165
  for (const attributeName of Object.keys(attributes)) {
@@ -5194,7 +5179,7 @@ const createEntityManager = (db) => {
5194
5179
  }
5195
5180
  if (targetAttribute.relation === "morphToOne") {
5196
5181
  const { idColumn, typeColumn } = targetAttribute.morphColumn;
5197
- const relId = toId((_a = cleanRelationData.set) == null ? void 0 : _a[0]);
5182
+ const relId = toId(cleanRelationData.set?.[0]);
5198
5183
  await this.createQueryBuilder(target).update({ [idColumn.name]: id, [typeColumn.name]: uid }).where({ id: relId }).transacting(trx).execute();
5199
5184
  } else if (targetAttribute.relation === "morphToMany") {
5200
5185
  const { joinTable } = targetAttribute;
@@ -5203,7 +5188,7 @@ const createEntityManager = (db) => {
5203
5188
  if (isEmpty(cleanRelationData.set)) {
5204
5189
  continue;
5205
5190
  }
5206
- const rows = ((_b = cleanRelationData.set) == null ? void 0 : _b.map((data2, idx) => {
5191
+ const rows = cleanRelationData.set?.map((data2, idx) => {
5207
5192
  return {
5208
5193
  [joinColumn.name]: data2.id,
5209
5194
  [idColumn.name]: id,
@@ -5213,7 +5198,7 @@ const createEntityManager = (db) => {
5213
5198
  order: idx + 1,
5214
5199
  field: attributeName
5215
5200
  };
5216
- })) ?? [];
5201
+ }) ?? [];
5217
5202
  await this.createQueryBuilder(joinTable.name).insert(rows).transacting(trx).execute();
5218
5203
  }
5219
5204
  continue;
@@ -5226,14 +5211,14 @@ const createEntityManager = (db) => {
5226
5211
  if (isEmpty(cleanRelationData.set)) {
5227
5212
  continue;
5228
5213
  }
5229
- const rows = ((_c = cleanRelationData.set) == null ? void 0 : _c.map((data2, idx) => ({
5214
+ const rows = cleanRelationData.set?.map((data2, idx) => ({
5230
5215
  [joinColumn.name]: id,
5231
5216
  [idColumn.name]: data2.id,
5232
5217
  [typeColumn.name]: data2[typeField],
5233
5218
  ..."on" in joinTable && joinTable.on || {},
5234
5219
  ...data2.__pivot || {},
5235
5220
  order: idx + 1
5236
- }))) ?? [];
5221
+ })) ?? [];
5237
5222
  await deleteRelatedMorphOneRelationsAfterMorphToManyUpdate(rows, {
5238
5223
  uid,
5239
5224
  attributeName,
@@ -5317,7 +5302,6 @@ const createEntityManager = (db) => {
5317
5302
  */
5318
5303
  // TODO: check relation exists (handled by FKs except for polymorphics)
5319
5304
  async updateRelations(uid, id, data, options) {
5320
- var _a, _b, _c, _d, _e, _f;
5321
5305
  const { attributes } = db.metadata.get(uid);
5322
5306
  const { transaction: trx } = options ?? {};
5323
5307
  for (const attributeName of Object.keys(attributes)) {
@@ -5333,7 +5317,7 @@ const createEntityManager = (db) => {
5333
5317
  const { idColumn, typeColumn } = targetAttribute.morphColumn;
5334
5318
  await this.createQueryBuilder(target).update({ [idColumn.name]: null, [typeColumn.name]: null }).where({ [idColumn.name]: id, [typeColumn.name]: uid }).transacting(trx).execute();
5335
5319
  if (!isNull(cleanRelationData.set)) {
5336
- const relId = toIds((_a = cleanRelationData.set) == null ? void 0 : _a[0]);
5320
+ const relId = toIds(cleanRelationData.set?.[0]);
5337
5321
  await this.createQueryBuilder(target).update({ [idColumn.name]: id, [typeColumn.name]: uid }).where({ id: relId }).transacting(trx).execute();
5338
5322
  }
5339
5323
  } else if (targetAttribute.type === "relation" && targetAttribute.relation === "morphToMany") {
@@ -5349,7 +5333,7 @@ const createEntityManager = (db) => {
5349
5333
  if (isEmpty(cleanRelationData.set)) {
5350
5334
  continue;
5351
5335
  }
5352
- const rows = (_b = cleanRelationData.set) == null ? void 0 : _b.map((data2, idx) => ({
5336
+ const rows = cleanRelationData.set?.map((data2, idx) => ({
5353
5337
  [joinColumn.name]: data2.id,
5354
5338
  [idColumn.name]: id,
5355
5339
  [typeColumn.name]: uid,
@@ -5422,7 +5406,7 @@ const createEntityManager = (db) => {
5422
5406
  let relIdsToaddOrMove;
5423
5407
  if (isPartialUpdate) {
5424
5408
  if (isAnyToOne(attribute)) {
5425
- cleanRelationData.connect = (_c = cleanRelationData.connect) == null ? void 0 : _c.slice(-1);
5409
+ cleanRelationData.connect = cleanRelationData.connect?.slice(-1);
5426
5410
  }
5427
5411
  relIdsToaddOrMove = toIds(cleanRelationData.connect);
5428
5412
  const relIdsToDelete = toIds(
@@ -5458,11 +5442,8 @@ const createEntityManager = (db) => {
5458
5442
  [joinColumn.name]: id,
5459
5443
  [inverseJoinColumn.name]: {
5460
5444
  $in: compact(
5461
- (_d = cleanRelationData.connect) == null ? void 0 : _d.map(
5462
- (r) => {
5463
- var _a2, _b2;
5464
- return ((_a2 = r.position) == null ? void 0 : _a2.after) || ((_b2 = r.position) == null ? void 0 : _b2.before);
5465
- }
5445
+ cleanRelationData.connect?.map(
5446
+ (r) => r.position?.after || r.position?.before
5466
5447
  )
5467
5448
  )
5468
5449
  }
@@ -5477,7 +5458,7 @@ const createEntityManager = (db) => {
5477
5458
  adjacentRelations,
5478
5459
  inverseJoinColumn.name,
5479
5460
  joinTable.orderColumnName,
5480
- (_e = cleanRelationData.options) == null ? void 0 : _e.strict
5461
+ cleanRelationData.options?.strict
5481
5462
  ).connect(cleanRelationData.connect ?? []).getOrderMap();
5482
5463
  insert.forEach((row) => {
5483
5464
  row[orderColumnName] = orderMap[row[inverseJoinColumn.name]];
@@ -5507,7 +5488,7 @@ const createEntityManager = (db) => {
5507
5488
  await cleanOrderColumns({ attribute, db, id, transaction: trx });
5508
5489
  } else {
5509
5490
  if (isAnyToOne(attribute)) {
5510
- cleanRelationData.set = (_f = cleanRelationData.set) == null ? void 0 : _f.slice(-1);
5491
+ cleanRelationData.set = cleanRelationData.set?.slice(-1);
5511
5492
  }
5512
5493
  relIdsToaddOrMove = toIds(cleanRelationData.set);
5513
5494
  await deleteRelations({
@@ -5824,9 +5805,8 @@ const createMigrationsProvider = (db) => {
5824
5805
  const migrations = createUmzugProvider(db);
5825
5806
  return {
5826
5807
  async shouldRun() {
5827
- var _a, _b;
5828
5808
  const pending = await migrations.pending();
5829
- return pending.length > 0 && ((_b = (_a = db.config) == null ? void 0 : _a.settings) == null ? void 0 : _b.runMigrations) === true;
5809
+ return pending.length > 0 && db.config?.settings?.runMigrations === true;
5830
5810
  },
5831
5811
  async up() {
5832
5812
  await migrations.up();
@@ -5837,10 +5817,9 @@ const createMigrationsProvider = (db) => {
5837
5817
  };
5838
5818
  };
5839
5819
  const modelsLifecyclesSubscriber = async (event) => {
5840
- var _a, _b;
5841
5820
  const { model } = event;
5842
5821
  if (model.lifecycles && event.action in model.lifecycles) {
5843
- await ((_b = (_a = model.lifecycles)[event.action]) == null ? void 0 : _b.call(_a, event));
5822
+ await model.lifecycles[event.action]?.(event);
5844
5823
  }
5845
5824
  };
5846
5825
  const timestampsLifecyclesSubscriber = {
@@ -5920,7 +5899,6 @@ const createLifecyclesProvider = (db) => {
5920
5899
  * @param {Map<any, any>} states
5921
5900
  */
5922
5901
  async run(action, uid, properties, states = /* @__PURE__ */ new Map()) {
5923
- var _a;
5924
5902
  for (let i = 0; i < subscribers.length; i += 1) {
5925
5903
  const subscriber = subscribers[i];
5926
5904
  if (typeof subscriber === "function") {
@@ -5937,7 +5915,7 @@ const createLifecyclesProvider = (db) => {
5937
5915
  if (hasAction && hasModel) {
5938
5916
  const state = states.get(subscriber) || {};
5939
5917
  const event = this.createEvent(action, uid, properties, state);
5940
- await ((_a = subscriber[action]) == null ? void 0 : _a.call(subscriber, event));
5918
+ await subscriber[action]?.(event);
5941
5919
  if (event.state) {
5942
5920
  states.set(subscriber, event.state);
5943
5921
  }