@strapi/strapi 4.4.3 → 4.5.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.
@@ -47,12 +47,10 @@ const createComponents = async (uid, data) => {
47
47
  componentValue.map((value) => createComponent(componentUID, value))
48
48
  );
49
49
 
50
- // TODO: add order
51
- componentBody[attributeName] = components.map(({ id }, idx) => {
50
+ componentBody[attributeName] = components.map(({ id }) => {
52
51
  return {
53
52
  id,
54
53
  __pivot: {
55
- order: idx + 1,
56
54
  field: attributeName,
57
55
  component_type: componentUID,
58
56
  },
@@ -63,7 +61,6 @@ const createComponents = async (uid, data) => {
63
61
  componentBody[attributeName] = {
64
62
  id: component.id,
65
63
  __pivot: {
66
- order: 1,
67
64
  field: attributeName,
68
65
  component_type: componentUID,
69
66
  },
@@ -81,13 +78,12 @@ const createComponents = async (uid, data) => {
81
78
  }
82
79
 
83
80
  componentBody[attributeName] = await Promise.all(
84
- dynamiczoneValues.map(async (value, idx) => {
81
+ dynamiczoneValues.map(async (value) => {
85
82
  const { id } = await createComponent(value.__component, value);
86
83
  return {
87
84
  id,
88
85
  __component: value.__component,
89
86
  __pivot: {
90
- order: idx + 1,
91
87
  field: attributeName,
92
88
  },
93
89
  };
@@ -145,11 +141,10 @@ const updateComponents = async (uid, entityToUpdate, data) => {
145
141
  componentValue.map((value) => updateOrCreateComponent(componentUID, value))
146
142
  );
147
143
 
148
- componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }, idx) => {
144
+ componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {
149
145
  return {
150
146
  id,
151
147
  __pivot: {
152
- order: idx + 1,
153
148
  field: attributeName,
154
149
  component_type: componentUID,
155
150
  },
@@ -160,7 +155,6 @@ const updateComponents = async (uid, entityToUpdate, data) => {
160
155
  componentBody[attributeName] = component && {
161
156
  id: component.id,
162
157
  __pivot: {
163
- order: 1,
164
158
  field: attributeName,
165
159
  component_type: componentUID,
166
160
  },
@@ -180,14 +174,13 @@ const updateComponents = async (uid, entityToUpdate, data) => {
180
174
  }
181
175
 
182
176
  componentBody[attributeName] = await Promise.all(
183
- dynamiczoneValues.map(async (value, idx) => {
177
+ dynamiczoneValues.map(async (value) => {
184
178
  const { id } = await updateOrCreateComponent(value.__component, value);
185
179
 
186
180
  return {
187
181
  id,
188
182
  __component: value.__component,
189
183
  __pivot: {
190
- order: idx + 1,
191
184
  field: attributeName,
192
185
  },
193
186
  };
@@ -10,6 +10,8 @@ const {
10
10
  sanitize,
11
11
  } = require('@strapi/utils');
12
12
  const { ValidationError } = require('@strapi/utils').errors;
13
+ const { isAnyToMany } = require('@strapi/utils').relations;
14
+ const { transformParamsToQuery } = require('@strapi/utils').convertQueryParams;
13
15
  const uploadFiles = require('../utils/upload-files');
14
16
 
15
17
  const {
@@ -19,9 +21,16 @@ const {
19
21
  updateComponents,
20
22
  deleteComponents,
21
23
  } = require('./components');
22
- const { transformParamsToQuery, pickSelectionParams } = require('./params');
24
+ const { pickSelectionParams } = require('./params');
23
25
  const { applyTransforms } = require('./attributes');
24
26
 
27
+ const transformLoadParamsToQuery = (uid, field, params = {}, pagination = {}) => {
28
+ return {
29
+ ...transformParamsToQuery(uid, { populate: { [field]: params } }).populate[field],
30
+ ...pagination,
31
+ };
32
+ };
33
+
25
34
  // TODO: those should be strapi events used by the webhooks not the other way arround
26
35
  const { ENTRY_CREATE, ENTRY_UPDATE, ENTRY_DELETE } = webhookUtils.webhookEvents;
27
36
 
@@ -83,12 +92,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
83
92
 
84
93
  const query = transformParamsToQuery(uid, wrappedParams);
85
94
 
86
- const { results, pagination } = await db.query(uid).findPage(query);
87
-
88
- return {
89
- results,
90
- pagination,
91
- };
95
+ return db.query(uid).findPage(query);
92
96
  },
93
97
 
94
98
  async findWithRelationCounts(uid, opts) {
@@ -96,9 +100,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
96
100
 
97
101
  const query = transformParamsToQuery(uid, wrappedParams);
98
102
 
99
- const results = await db.query(uid).findMany(query);
100
-
101
- return results;
103
+ return db.query(uid).findMany(query);
102
104
  },
103
105
 
104
106
  async findOne(uid, entityId, opts) {
@@ -251,35 +253,28 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
251
253
  },
252
254
 
253
255
  load(uid, entity, field, params = {}) {
254
- const { attributes } = strapi.getModel(uid);
256
+ if (!_.isString(field)) {
257
+ throw new Error(`Invalid load. Expected "${field}" to be a string`);
258
+ }
255
259
 
256
- const attribute = attributes[field];
260
+ return db.query(uid).load(entity, field, transformLoadParamsToQuery(uid, field, params));
261
+ },
257
262
 
258
- const loadParams = {};
263
+ loadPages(uid, entity, field, params = {}, pagination = {}) {
264
+ if (!_.isString(field)) {
265
+ throw new Error(`Invalid load. Expected "${field}" to be a string`);
266
+ }
259
267
 
260
- switch (attribute.type) {
261
- case 'relation': {
262
- Object.assign(loadParams, transformParamsToQuery(attribute.target, params));
263
- break;
264
- }
265
- case 'component': {
266
- Object.assign(loadParams, transformParamsToQuery(attribute.component, params));
267
- break;
268
- }
269
- case 'dynamiczone': {
270
- Object.assign(loadParams, transformParamsToQuery(null, params));
271
- break;
272
- }
273
- case 'media': {
274
- Object.assign(loadParams, transformParamsToQuery('plugin::upload.file', params));
275
- break;
276
- }
277
- default: {
278
- break;
279
- }
268
+ const { attributes } = strapi.getModel(uid);
269
+ const attribute = attributes[field];
270
+
271
+ if (!isAnyToMany(attribute)) {
272
+ throw new Error(`Invalid load. Expected "${field}" to be an anyToMany relational attribute`);
280
273
  }
281
274
 
282
- return db.query(uid).load(entity, field, loadParams);
275
+ const query = transformLoadParamsToQuery(uid, field, params, pagination);
276
+
277
+ return db.query(uid).loadPages(entity, field, query);
283
278
  },
284
279
  });
285
280
 
@@ -1,95 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const { pick, isNil, toNumber, isInteger } = require('lodash/fp');
4
- const { PaginationError } = require('@strapi/utils').errors;
5
-
6
- const {
7
- convertSortQueryParams,
8
- convertLimitQueryParams,
9
- convertStartQueryParams,
10
- convertPopulateQueryParams,
11
- convertFiltersQueryParams,
12
- convertFieldsQueryParams,
13
- convertPublicationStateParams,
14
- } = require('@strapi/utils/lib/convert-query-params');
3
+ const { pick } = require('lodash/fp');
15
4
 
16
5
  const pickSelectionParams = pick(['fields', 'populate']);
17
6
 
18
- const transformParamsToQuery = (uid, params) => {
19
- // NOTE: can be a CT, a Compo or nothing in the case of polymorphism (DZ & morph relations)
20
- const schema = strapi.getModel(uid);
21
-
22
- const query = {};
23
-
24
- const { _q, sort, filters, fields, populate, page, pageSize, start, limit } = params;
25
-
26
- if (!isNil(_q)) {
27
- query._q = _q;
28
- }
29
-
30
- if (!isNil(sort)) {
31
- query.orderBy = convertSortQueryParams(sort);
32
- }
33
-
34
- if (!isNil(filters)) {
35
- query.where = convertFiltersQueryParams(filters, schema);
36
- }
37
-
38
- if (!isNil(fields)) {
39
- query.select = convertFieldsQueryParams(fields);
40
- }
41
-
42
- if (!isNil(populate)) {
43
- query.populate = convertPopulateQueryParams(populate, schema);
44
- }
45
-
46
- const isPagePagination = !isNil(page) || !isNil(pageSize);
47
- const isOffsetPagination = !isNil(start) || !isNil(limit);
48
-
49
- if (isPagePagination && isOffsetPagination) {
50
- throw new PaginationError(
51
- 'Invalid pagination attributes. You cannot use page and offset pagination in the same query'
52
- );
53
- }
54
-
55
- if (!isNil(page)) {
56
- const pageVal = toNumber(page);
57
-
58
- if (!isInteger(pageVal) || pageVal <= 0) {
59
- throw new PaginationError(
60
- `Invalid 'page' parameter. Expected an integer > 0, received: ${page}`
61
- );
62
- }
63
-
64
- query.page = pageVal;
65
- }
66
-
67
- if (!isNil(pageSize)) {
68
- const pageSizeVal = toNumber(pageSize);
69
-
70
- if (!isInteger(pageSizeVal) || pageSizeVal <= 0) {
71
- throw new PaginationError(
72
- `Invalid 'pageSize' parameter. Expected an integer > 0, received: ${page}`
73
- );
74
- }
75
-
76
- query.pageSize = pageSizeVal;
77
- }
78
-
79
- if (!isNil(start)) {
80
- query.offset = convertStartQueryParams(start);
81
- }
82
-
83
- if (!isNil(limit)) {
84
- query.limit = convertLimitQueryParams(limit);
85
- }
86
-
87
- convertPublicationStateParams(schema, params, query);
88
-
89
- return query;
90
- };
91
-
92
7
  module.exports = {
93
- transformParamsToQuery,
94
8
  pickSelectionParams,
95
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.4.3",
3
+ "version": "4.5.0-beta.0",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -78,20 +78,20 @@
78
78
  "test:unit": "jest --verbose"
79
79
  },
80
80
  "dependencies": {
81
- "@koa/cors": "3.4.1",
81
+ "@koa/cors": "3.4.2",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.4.3",
84
- "@strapi/database": "4.4.3",
85
- "@strapi/generate-new": "4.4.3",
86
- "@strapi/generators": "4.4.3",
87
- "@strapi/logger": "4.4.3",
88
- "@strapi/permissions": "4.4.3",
89
- "@strapi/plugin-content-manager": "4.4.3",
90
- "@strapi/plugin-content-type-builder": "4.4.3",
91
- "@strapi/plugin-email": "4.4.3",
92
- "@strapi/plugin-upload": "4.4.3",
93
- "@strapi/typescript-utils": "4.4.3",
94
- "@strapi/utils": "4.4.3",
83
+ "@strapi/admin": "4.5.0-beta.0",
84
+ "@strapi/database": "4.5.0-beta.0",
85
+ "@strapi/generate-new": "4.5.0-beta.0",
86
+ "@strapi/generators": "4.5.0-beta.0",
87
+ "@strapi/logger": "4.5.0-beta.0",
88
+ "@strapi/permissions": "4.5.0-beta.0",
89
+ "@strapi/plugin-content-manager": "4.5.0-beta.0",
90
+ "@strapi/plugin-content-type-builder": "4.5.0-beta.0",
91
+ "@strapi/plugin-email": "4.5.0-beta.0",
92
+ "@strapi/plugin-upload": "4.5.0-beta.0",
93
+ "@strapi/typescript-utils": "4.5.0-beta.0",
94
+ "@strapi/utils": "4.5.0-beta.0",
95
95
  "bcryptjs": "2.4.3",
96
96
  "boxen": "5.1.2",
97
97
  "chalk": "4.1.2",
@@ -140,5 +140,5 @@
140
140
  "node": ">=14.19.1 <=18.x.x",
141
141
  "npm": ">=6.0.0"
142
142
  },
143
- "gitHead": "f99314ead7f0fdf82b921b9d8f0282a91e952ca8"
143
+ "gitHead": "ee98b9a9cbb6e0e07e781ff9e87eb170c72e50df"
144
144
  }