@strapi/database 4.3.7 → 4.4.0-beta.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.
@@ -34,7 +34,7 @@ const processData = (metadata, data = {}, { withDefaults = false } = {}) => {
34
34
 
35
35
  const obj = {};
36
36
 
37
- for (const attributeName in attributes) {
37
+ for (const attributeName of Object.keys(attributes)) {
38
38
  const attribute = attributes[attributeName];
39
39
 
40
40
  if (types.isScalar(attribute.type)) {
@@ -333,7 +333,7 @@ const createEntityManager = (db) => {
333
333
  async attachRelations(uid, id, data) {
334
334
  const { attributes } = db.metadata.get(uid);
335
335
 
336
- for (const attributeName in attributes) {
336
+ for (const attributeName of Object.keys(attributes)) {
337
337
  const attribute = attributes[attributeName];
338
338
 
339
339
  const isValidLink = _.has(attributeName, data) && !_.isNil(data[attributeName]);
@@ -487,7 +487,7 @@ const createEntityManager = (db) => {
487
487
  async updateRelations(uid, id, data) {
488
488
  const { attributes } = db.metadata.get(uid);
489
489
 
490
- for (const attributeName in attributes) {
490
+ for (const attributeName of Object.keys(attributes)) {
491
491
  const attribute = attributes[attributeName];
492
492
 
493
493
  if (attribute.type !== 'relation' || !_.has(attributeName, data)) {
@@ -667,7 +667,7 @@ const createEntityManager = (db) => {
667
667
  async deleteRelations(uid, id) {
668
668
  const { attributes } = db.metadata.get(uid);
669
669
 
670
- for (const attributeName in attributes) {
670
+ for (const attributeName of Object.keys(attributes)) {
671
671
  const attribute = attributes[attributeName];
672
672
 
673
673
  if (attribute.type !== 'relation') {
@@ -54,7 +54,7 @@ const createLifecyclesProvider = (db) => {
54
54
  * @param {Map<any, any>} states
55
55
  */
56
56
  async run(action, uid, properties, states = new Map()) {
57
- for (let i = 0; i < subscribers.length; i++) {
57
+ for (let i = 0; i < subscribers.length; i += 1) {
58
58
  const subscriber = subscribers[i];
59
59
  if (typeof subscriber === 'function') {
60
60
  const state = states.get(subscriber) || {};
@@ -71,7 +71,7 @@ const applyJoin = (qb, join) => {
71
71
  inner.on(`${rootTable}.${rootColumn}`, `${alias}.${referencedColumn}`);
72
72
 
73
73
  if (on) {
74
- for (const key in on) {
74
+ for (const key of Object.keys(on)) {
75
75
  inner.onVal(`${alias}.${key}`, on[key]);
76
76
  }
77
77
  }
@@ -8,7 +8,7 @@ const { fromRow } = require('./transform');
8
8
  const getRootLevelPopulate = (meta) => {
9
9
  const populate = {};
10
10
 
11
- for (const attributeName in meta.attributes) {
11
+ for (const attributeName of Object.keys(meta.attributes)) {
12
12
  const attribute = meta.attributes[attributeName];
13
13
  if (attribute.type === 'relation') {
14
14
  populate[attributeName] = true;
@@ -72,7 +72,7 @@ const processPopulate = (populate, ctx) => {
72
72
  }
73
73
 
74
74
  const finalPopulate = {};
75
- for (const key in populateMap) {
75
+ for (const key of Object.keys(populateMap)) {
76
76
  const attribute = meta.attributes[key];
77
77
 
78
78
  if (!attribute) {
@@ -119,7 +119,7 @@ const applyPopulate = async (results, populate, ctx) => {
119
119
  return results;
120
120
  }
121
121
 
122
- for (const key in populate) {
122
+ for (const key of Object.keys(populate)) {
123
123
  const attribute = meta.attributes[key];
124
124
  const targetMeta = db.metadata.get(attribute.target);
125
125
 
@@ -540,7 +540,7 @@ const applyPopulate = async (results, populate, ctx) => {
540
540
  }, {});
541
541
 
542
542
  const map = {};
543
- for (const type in idsByType) {
543
+ for (const type of Object.keys(idsByType)) {
544
544
  const ids = idsByType[type];
545
545
 
546
546
  // type was removed but still in morph relation
@@ -604,7 +604,7 @@ const applyPopulate = async (results, populate, ctx) => {
604
604
  }, {});
605
605
 
606
606
  const map = {};
607
- for (const type in idsByType) {
607
+ for (const type of Object.keys(idsByType)) {
608
608
  const ids = idsByType[type];
609
609
 
610
610
  // type was removed but still in morph relation
@@ -53,7 +53,7 @@ const toRow = (meta, data = {}) => {
53
53
 
54
54
  const { attributes } = meta;
55
55
 
56
- for (const key in data) {
56
+ for (const key of Object.keys(data)) {
57
57
  const attribute = attributes[key];
58
58
 
59
59
  if (!attribute || attribute.columnName === key) {
@@ -76,7 +76,7 @@ const processAttributeWhere = (attribute, where, operator = '$eq') => {
76
76
 
77
77
  const filters = {};
78
78
 
79
- for (const key in where) {
79
+ for (const key of Object.keys(where)) {
80
80
  const value = where[key];
81
81
 
82
82
  if (!isOperator(key)) {
@@ -119,7 +119,7 @@ const processWhere = (where, ctx) => {
119
119
  const filters = {};
120
120
 
121
121
  // for each key in where
122
- for (const key in where) {
122
+ for (const key of Object.keys(where)) {
123
123
  const value = where[key];
124
124
 
125
125
  // if operator $and $or then loop over them
@@ -27,7 +27,13 @@ const createQueryBuilder = (uid, db) => {
27
27
  };
28
28
 
29
29
  let counter = 0;
30
- const getAlias = () => `t${counter++}`;
30
+ const getAlias = () => {
31
+ const alias = `t${counter}`;
32
+
33
+ counter += 1;
34
+
35
+ return alias;
36
+ };
31
37
 
32
38
  return {
33
39
  alias: getAlias(),
@@ -316,7 +316,7 @@ const createHelpers = (db) => {
316
316
  debug(`Creating column ${addedColumn.name}`);
317
317
 
318
318
  if (addedColumn.type === 'increments' && !db.dialect.canAddIncrements()) {
319
- tableBuilder.integer(addedColumn.name).unsigned().notNullable();
319
+ tableBuilder.integer(addedColumn.name).unsigned();
320
320
  tableBuilder.primary(addedColumn.name);
321
321
  } else {
322
322
  createColumn(tableBuilder, addedColumn);
@@ -25,7 +25,7 @@ const createTable = (meta) => {
25
25
  columns: [],
26
26
  };
27
27
 
28
- for (const key in meta.attributes) {
28
+ for (const key of Object.keys(meta.attributes)) {
29
29
  const attribute = meta.attributes[key];
30
30
 
31
31
  if (types.isRelation(attribute.type)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/database",
3
- "version": "4.3.7",
3
+ "version": "4.4.0-beta.0",
4
4
  "description": "Strapi's database layer",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -39,8 +39,8 @@
39
39
  "umzug": "3.1.1"
40
40
  },
41
41
  "engines": {
42
- "node": ">=14.19.1 <=16.x.x",
42
+ "node": ">=14.19.1 <=18.x.x",
43
43
  "npm": ">=6.0.0"
44
44
  },
45
- "gitHead": "73f523b98322cea8992c72977b94a73a624d2e79"
45
+ "gitHead": "cae16f7f259fa4473a55e8fea57839cda98f34ae"
46
46
  }