@strapi/database 4.26.0 → 4.26.2

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
@@ -2,7 +2,7 @@ import semver from "semver";
2
2
  import path from "path";
3
3
  import fse from "fs-extra";
4
4
  import createDebug from "debug";
5
- import _, { isNil, castArray, prop, omit, toString, toNumber, isString as isString$1, padCharsEnd, isArray, isPlainObject, isFinite, groupBy, pipe, mapValues, map, isEmpty, maxBy, pick, flow, mergeWith, has, uniqBy, isNull, differenceWith, isEqual, compact, difference, isObject, isInteger, isNumber as isNumber$1, isUndefined, uniqWith } from "lodash/fp";
5
+ import _, { isNil, castArray, prop, omit, toString, toNumber, padCharsEnd, isString as isString$1, isArray, isPlainObject, isFinite, groupBy, pipe, mapValues, map, isEmpty, maxBy, pick, has, isNull, differenceWith, isEqual, uniqBy, compact, difference, flow, mergeWith, isNumber as isNumber$1, isUndefined, isObject, uniqWith, isInteger } from "lodash/fp";
6
6
  import crypto, { randomBytes } from "crypto";
7
7
  import { isOperatorOfType, isOperator, mapAsync } from "@strapi/utils";
8
8
  import * as dateFns from "date-fns";
@@ -1884,8 +1884,7 @@ const createOneToOne = (attributeName, attribute, meta, metadata) => {
1884
1884
  } else {
1885
1885
  createJoinColum(metadata, {
1886
1886
  attribute,
1887
- attributeName,
1888
- meta
1887
+ attributeName
1889
1888
  });
1890
1889
  }
1891
1890
  }
@@ -1914,8 +1913,7 @@ const createManyToOne = (attributeName, attribute, meta, metadata) => {
1914
1913
  } else {
1915
1914
  createJoinColum(metadata, {
1916
1915
  attribute,
1917
- attributeName,
1918
- meta
1916
+ attributeName
1919
1917
  });
1920
1918
  }
1921
1919
  };
@@ -3381,17 +3379,17 @@ const applyPopulate = async (results, populate, ctx) => {
3381
3379
  case "morphOne":
3382
3380
  case "morphMany": {
3383
3381
  const targetMeta = db.metadata.get(attribute.target);
3384
- const input = { attribute, attributeName, results, populateValue, targetMeta, isCount };
3382
+ const input = { attribute, attributeName, results, populateValue, targetMeta };
3385
3383
  await morphX(input, ctx);
3386
3384
  break;
3387
3385
  }
3388
3386
  case "morphToMany": {
3389
- const input = { attribute, attributeName, results, populateValue, isCount };
3387
+ const input = { attribute, attributeName, results, populateValue };
3390
3388
  await morphToMany(input, ctx);
3391
3389
  break;
3392
3390
  }
3393
3391
  case "morphToOne": {
3394
- const input = { attribute, attributeName, results, populateValue, isCount };
3392
+ const input = { attribute, attributeName, results, populateValue };
3395
3393
  await morphToOne(input, ctx);
3396
3394
  break;
3397
3395
  }
@@ -4636,8 +4634,7 @@ const cleanOrderColumns = async ({
4636
4634
  }
4637
4635
  };
4638
4636
  const updateInverseOrderColumn = async () => {
4639
- if (!hasInverseOrderColumn(attribute) || isEmpty(inverseRelIds))
4640
- return;
4637
+ if (!hasInverseOrderColumn(attribute) || isEmpty(inverseRelIds)) return;
4641
4638
  const selectRowsToOrder = (joinTableName) => db.connection(joinTableName).select("id").rowNumber("inv_order", inverseOrderColumnName, inverseJoinColumn.name).where(inverseJoinColumn.name, "in", inverseRelIds).toSQL();
4642
4639
  switch (strapi.db.dialect.client) {
4643
4640
  case "mysql": {
@@ -4776,8 +4773,7 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
4776
4773
  ...mapper
4777
4774
  };
4778
4775
  }, {});
4779
- if (!needsSorting)
4780
- return connectArr;
4776
+ if (!needsSorting) return connectArr;
4781
4777
  const computeRelation = (relation, relationsSeenInBranch) => {
4782
4778
  const adjacentRelId = relation.position?.before || relation.position?.after;
4783
4779
  const adjacentRelation = mappedRelations[adjacentRelId];
@@ -4884,8 +4880,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
4884
4880
  */
4885
4881
  getOrderMap() {
4886
4882
  return _$1(computedRelations).groupBy("order").reduce((acc, relations) => {
4887
- if (relations[0]?.init)
4888
- return acc;
4883
+ if (relations[0]?.init) return acc;
4889
4884
  relations.forEach((relation, idx) => {
4890
4885
  acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
4891
4886
  });
@@ -5688,8 +5683,7 @@ const createEntityManager = (db) => {
5688
5683
  }
5689
5684
  continue;
5690
5685
  }
5691
- if (attribute.relation === "morphToOne")
5692
- ;
5686
+ if (attribute.relation === "morphToOne") ;
5693
5687
  if (attribute.relation === "morphToMany") {
5694
5688
  const { joinTable } = attribute;
5695
5689
  const { joinColumn } = joinTable;
@@ -5999,8 +5993,7 @@ const createLifecyclesProvider = (db) => {
5999
5993
  * @param {Map<any, any>} states
6000
5994
  */
6001
5995
  async run(action, uid, properties, states = /* @__PURE__ */ new Map()) {
6002
- if (isLifecycleHooksDisabled)
6003
- return states;
5996
+ if (isLifecycleHooksDisabled) return states;
6004
5997
  for (let i = 0; i < subscribers.length; i += 1) {
6005
5998
  const subscriber = subscribers[i];
6006
5999
  if (typeof subscriber === "function") {
@@ -6177,8 +6170,7 @@ const getLinksWithoutMappedBy = (db) => {
6177
6170
  };
6178
6171
  const isLinkTableEmpty = async (db, linkTableName) => {
6179
6172
  const exists = await db.getSchemaConnection().hasTable(linkTableName);
6180
- if (!exists)
6181
- return true;
6173
+ if (!exists) return true;
6182
6174
  const result = await db.getConnection().from(linkTableName).count("* as count");
6183
6175
  return Number(result[0].count) === 0;
6184
6176
  };
@@ -6199,8 +6191,7 @@ const validateBidirectionalRelations = async (db) => {
6199
6191
  process.emitWarning(
6200
6192
  `Error on attribute "${relation.inversedBy}" in model "${invContentType.singularName}" (${invContentType.uid}). Please modify your ${invContentType.singularName} schema by renaming the key "inversedBy" to "mappedBy". Ex: { "inversedBy": "${invRelation.inversedBy}" } -> { "mappedBy": "${invRelation.inversedBy}" }`
6201
6193
  );
6202
- } else
6203
- ;
6194
+ } else ;
6204
6195
  }
6205
6196
  };
6206
6197
  const validateRelations = async (db) => {