@akemona-org/strapi-database 3.7.0 → 3.7.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.
@@ -46,22 +46,22 @@ class DatabaseManager {
46
46
  }
47
47
 
48
48
  async destroy() {
49
- await Promise.all(this.connectors.getAll().map(connector => connector.destroy()));
49
+ await Promise.all(this.connectors.getAll().map((connector) => connector.destroy()));
50
50
  }
51
51
 
52
52
  initializeModelsMap() {
53
- Object.keys(this.strapi.models).forEach(modelKey => {
53
+ Object.keys(this.strapi.models).forEach((modelKey) => {
54
54
  const model = this.strapi.models[modelKey];
55
55
  this.models.set(model.uid, model);
56
56
  });
57
57
 
58
- Object.keys(this.strapi.admin.models).forEach(modelKey => {
58
+ Object.keys(this.strapi.admin.models).forEach((modelKey) => {
59
59
  const model = this.strapi.admin.models[modelKey];
60
60
  this.models.set(model.uid, model);
61
61
  });
62
62
 
63
- Object.keys(this.strapi.plugins).forEach(pluginKey => {
64
- Object.keys(this.strapi.plugins[pluginKey].models).forEach(modelKey => {
63
+ Object.keys(this.strapi.plugins).forEach((pluginKey) => {
64
+ Object.keys(this.strapi.plugins[pluginKey].models).forEach((modelKey) => {
65
65
  const model = this.strapi.plugins[pluginKey].models[modelKey];
66
66
  this.models.set(model.uid, model);
67
67
  });
@@ -125,13 +125,13 @@ class DatabaseManager {
125
125
  }
126
126
 
127
127
  getModelByCollectionName(collectionName) {
128
- return Array.from(this.models.values()).find(model => {
128
+ return Array.from(this.models.values()).find((model) => {
129
129
  return model.collectionName === collectionName;
130
130
  });
131
131
  }
132
132
 
133
133
  getModelByGlobalId(globalId) {
134
- return Array.from(this.models.values()).find(model => {
134
+ return Array.from(this.models.values()).find((model) => {
135
135
  return model.globalId === globalId;
136
136
  });
137
137
  }
@@ -141,7 +141,7 @@ class DatabaseManager {
141
141
  return [this.getModel(attr.component)];
142
142
  }
143
143
  if (attr.type === 'dynamiczone') {
144
- return attr.components.map(compoName => this.getModel(compoName));
144
+ return attr.components.map((compoName) => this.getModel(compoName));
145
145
  }
146
146
  if (attr.model || attr.collection) {
147
147
  return [this.getModelByAssoc(attr)];
@@ -61,6 +61,6 @@ class MigrationManager {
61
61
  }
62
62
  }
63
63
 
64
- module.exports = strapi => {
64
+ module.exports = (strapi) => {
65
65
  return new MigrationManager(strapi);
66
66
  };
@@ -21,7 +21,7 @@ module.exports = function createQuery(opts) {
21
21
  });
22
22
 
23
23
  const createMany = (entities, { concurrency = 100 } = {}, ...rest) => {
24
- return pmap(entities, entity => createFn(entity, ...rest), {
24
+ return pmap(entities, (entity) => createFn(entity, ...rest), {
25
25
  concurrency,
26
26
  stopOnError: true,
27
27
  });
@@ -3,23 +3,25 @@
3
3
  const { replaceIdByPrimaryKey } = require('../utils/primary-key');
4
4
  const { executeBeforeLifecycle, executeAfterLifecycle } = require('../utils/lifecycles');
5
5
 
6
- const withLifecycles = ({ query, model, fn }) => async (params, ...rest) => {
7
- // substitute id for primaryKey value in params
8
- const newParams = replaceIdByPrimaryKey(params, model);
9
- const queryArguments = [newParams, ...rest];
6
+ const withLifecycles =
7
+ ({ query, model, fn }) =>
8
+ async (params, ...rest) => {
9
+ // substitute id for primaryKey value in params
10
+ const newParams = replaceIdByPrimaryKey(params, model);
11
+ const queryArguments = [newParams, ...rest];
10
12
 
11
- // execute before hook
12
- await executeBeforeLifecycle(query, model, ...queryArguments);
13
+ // execute before hook
14
+ await executeBeforeLifecycle(query, model, ...queryArguments);
13
15
 
14
- // execute query
15
- const result = await fn(...queryArguments);
16
+ // execute query
17
+ const result = await fn(...queryArguments);
16
18
 
17
- // execute after hook with result and arguments
18
- await executeAfterLifecycle(query, model, result, ...queryArguments);
19
+ // execute after hook with result and arguments
20
+ await executeAfterLifecycle(query, model, result, ...queryArguments);
19
21
 
20
- // return result
21
- return result;
22
- };
22
+ // return result
23
+ return result;
24
+ };
23
25
 
24
26
  // wraps a connectorQuery call with:
25
27
  // - param substitution
@@ -2,15 +2,17 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
 
5
- const createPaginatedQuery = ({ fetch, count }) => async (queryParams, ...args) => {
6
- const params = _.omit(queryParams, ['page', 'pageSize']);
7
- const pagination = await getPaginationInfos(queryParams, count, ...args);
5
+ const createPaginatedQuery =
6
+ ({ fetch, count }) =>
7
+ async (queryParams, ...args) => {
8
+ const params = _.omit(queryParams, ['page', 'pageSize']);
9
+ const pagination = await getPaginationInfos(queryParams, count, ...args);
8
10
 
9
- Object.assign(params, paginationToQueryParams(pagination));
10
- const results = await fetch(params, undefined, ...args);
11
+ Object.assign(params, paginationToQueryParams(pagination));
12
+ const results = await fetch(params, undefined, ...args);
11
13
 
12
- return { results, pagination };
13
- };
14
+ return { results, pagination };
15
+ };
14
16
 
15
17
  const createSearchPageQuery = ({ search, countSearch }) =>
16
18
  createPaginatedQuery({ fetch: search, count: countSearch });
@@ -29,7 +31,7 @@ const getPaginationInfos = async (queryParams, count, ...args) => {
29
31
  };
30
32
  };
31
33
 
32
- const withDefaultPagination = params => {
34
+ const withDefaultPagination = (params) => {
33
35
  const { page = 1, pageSize = 100, ...rest } = params;
34
36
 
35
37
  return {
@@ -9,10 +9,7 @@ const VError = require('verror');
9
9
  */
10
10
  module.exports = function requireConnector(connector) {
11
11
  if (!connector) {
12
- throw new VError(
13
- { name: 'ConnectorError' },
14
- 'initialize connector without name'
15
- );
12
+ throw new VError({ name: 'ConnectorError' }, 'initialize connector without name');
16
13
  }
17
14
 
18
15
  try {
@@ -44,9 +44,9 @@ const checkDuplicatedTableNames = ({ strapi }) => {
44
44
  });
45
45
  });
46
46
 
47
- modelsWithInfo.forEach(modelA => {
47
+ modelsWithInfo.forEach((modelA) => {
48
48
  const similarModelFound = modelsWithInfo.find(
49
- modelB =>
49
+ (modelB) =>
50
50
  modelB.model.collectionName === modelA.model.collectionName &&
51
51
  modelB.model.uid !== modelA.model.uid
52
52
  );
@@ -19,10 +19,8 @@ const checkReservedAttributeNames = (model, { manager }) => {
19
19
  ).defaultTimestamps;
20
20
 
21
21
  if (Array.isArray(model.options.timestamps)) {
22
- const [
23
- createdAtAttribute = connectorCreatedAt,
24
- updatedAtAttribute = connectorUpdatedAt,
25
- ] = model.options.timestamps;
22
+ const [createdAtAttribute = connectorCreatedAt, updatedAtAttribute = connectorUpdatedAt] =
23
+ model.options.timestamps;
26
24
 
27
25
  reservedNames.push(createdAtAttribute, updatedAtAttribute);
28
26
  } else {
@@ -43,7 +41,7 @@ const checkReservedAttributeNames = (model, { manager }) => {
43
41
  }
44
42
  };
45
43
 
46
- const checkReservedModelName = model => {
44
+ const checkReservedModelName = (model) => {
47
45
  if (constants.RESERVED_MODEL_NAMES.includes(model.modelName)) {
48
46
  throw new ModelError(
49
47
  `"${model.modelName}" is a reserved model name. You need to rename your model and the files associated with it.`
@@ -51,13 +49,13 @@ const checkReservedModelName = model => {
51
49
  }
52
50
  };
53
51
 
54
- const getModelsFrom = source => _.flatMap(source, iteratee => _.values(iteratee.models));
52
+ const getModelsFrom = (source) => _.flatMap(source, (iteratee) => _.values(iteratee.models));
55
53
 
56
54
  /**
57
55
  * Checks that there are no model using reserved names (content type, component, attributes)
58
56
  */
59
57
  module.exports = ({ strapi, manager }) => {
60
- [...getModelsFrom(strapi.api), ...getModelsFrom(strapi.plugins)].forEach(model => {
58
+ [...getModelsFrom(strapi.api), ...getModelsFrom(strapi.plugins)].forEach((model) => {
61
59
  checkReservedModelName(model);
62
60
  checkReservedAttributeNames(model, { manager });
63
61
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.7.0",
6
+ "version": "3.7.2",
7
7
  "description": "Strapi's database layer",
8
8
  "homepage": "https://strapi.akemona.com",
9
9
  "main": "./lib/index.js",
@@ -31,11 +31,11 @@
31
31
  },
32
32
  "license": "SEE LICENSE IN LICENSE",
33
33
  "dependencies": {
34
- "@akemona-org/strapi-utils": "3.7.0",
34
+ "@akemona-org/strapi-utils": "3.7.2",
35
35
  "debug": "4.3.1",
36
36
  "lodash": "4.17.21",
37
37
  "p-map": "4.0.0",
38
38
  "verror": "^1.10.0"
39
39
  },
40
- "gitHead": "129a8d6191b55810fd66448dcc47fee829df986c"
40
+ "gitHead": "4ab59dbae5135819558c6ae27b45a556ff27cf55"
41
41
  }