@strapi/strapi 4.10.6 → 4.10.7

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.
@@ -59,6 +59,10 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
59
59
  return options;
60
60
  },
61
61
 
62
+ async wrapResult(result) {
63
+ return result;
64
+ },
65
+
62
66
  async emitEvent(uid, event, entity) {
63
67
  // Ignore audit log events to prevent infinite loops
64
68
  if (uid === 'admin::audit-log') {
@@ -83,10 +87,12 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
83
87
  const query = transformParamsToQuery(uid, wrappedParams);
84
88
 
85
89
  if (kind === 'singleType') {
86
- return db.query(uid).findOne(query);
90
+ const entity = db.query(uid).findOne(query);
91
+ return this.wrapResult(entity, { uid, action: 'findOne' });
87
92
  }
88
93
 
89
- return db.query(uid).findMany(query);
94
+ const entities = await db.query(uid).findMany(query);
95
+ return this.wrapResult(entities, { uid, action: 'findMany' });
90
96
  },
91
97
 
92
98
  async findPage(uid, opts) {
@@ -94,7 +100,11 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
94
100
 
95
101
  const query = transformParamsToQuery(uid, wrappedParams);
96
102
 
97
- return db.query(uid).findPage(query);
103
+ const page = await db.query(uid).findPage(query);
104
+ return {
105
+ ...page,
106
+ results: await this.wrapResult(page.results, { uid, action: 'findPage' }),
107
+ };
98
108
  },
99
109
 
100
110
  // TODO: streamline the logic based on the populate option
@@ -103,7 +113,11 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
103
113
 
104
114
  const query = transformParamsToQuery(uid, wrappedParams);
105
115
 
106
- return db.query(uid).findPage(query);
116
+ const entities = await db.query(uid).findPage(query);
117
+ return {
118
+ ...entities,
119
+ results: await this.wrapResult(entities.results, { uid, action: 'findWithRelationCounts' }),
120
+ };
107
121
  },
108
122
 
109
123
  async findWithRelationCounts(uid, opts) {
@@ -111,7 +125,8 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
111
125
 
112
126
  const query = transformParamsToQuery(uid, wrappedParams);
113
127
 
114
- return db.query(uid).findMany(query);
128
+ const entities = await db.query(uid).findMany(query);
129
+ return this.wrapResult(entities, { uid, action: 'findWithRelationCounts' });
115
130
  },
116
131
 
117
132
  async findOne(uid, entityId, opts) {
@@ -119,7 +134,8 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
119
134
 
120
135
  const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));
121
136
 
122
- return db.query(uid).findOne({ ...query, where: { id: entityId } });
137
+ const entity = await db.query(uid).findOne({ ...query, where: { id: entityId } });
138
+ return this.wrapResult(entity, { uid, action: 'findOne' });
123
139
  },
124
140
 
125
141
  async count(uid, opts) {
@@ -162,6 +178,8 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
162
178
  entity = await this.findOne(uid, entity.id, wrappedParams);
163
179
  }
164
180
 
181
+ entity = await this.wrapResult(entity, { uid, action: 'create' });
182
+
165
183
  await this.emitEvent(uid, ENTRY_CREATE, entity);
166
184
 
167
185
  return entity;
@@ -213,6 +231,8 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
213
231
  entity = await this.findOne(uid, entity.id, wrappedParams);
214
232
  }
215
233
 
234
+ entity = await this.wrapResult(entity, { uid, action: 'update' });
235
+
216
236
  await this.emitEvent(uid, ENTRY_UPDATE, entity);
217
237
 
218
238
  return entity;
@@ -224,7 +244,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
224
244
  // select / populate
225
245
  const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));
226
246
 
227
- const entityToDelete = await db.query(uid).findOne({
247
+ let entityToDelete = await db.query(uid).findOne({
228
248
  ...query,
229
249
  where: { id: entityId },
230
250
  });
@@ -238,6 +258,8 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
238
258
  await db.query(uid).delete({ where: { id: entityToDelete.id } });
239
259
  await deleteComponents(uid, componentsToDelete, { loadComponents: false });
240
260
 
261
+ entityToDelete = await this.wrapResult(entityToDelete, { uid, action: 'delete' });
262
+
241
263
  await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
242
264
 
243
265
  return entityToDelete;
@@ -250,7 +272,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
250
272
  // select / populate
251
273
  const query = transformParamsToQuery(uid, wrappedParams);
252
274
 
253
- const entitiesToDelete = await db.query(uid).findMany(query);
275
+ let entitiesToDelete = await db.query(uid).findMany(query);
254
276
 
255
277
  if (!entitiesToDelete.length) {
256
278
  return null;
@@ -265,21 +287,27 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
265
287
  componentsToDelete.map((compos) => deleteComponents(uid, compos, { loadComponents: false }))
266
288
  );
267
289
 
290
+ entitiesToDelete = await this.wrapResult(entitiesToDelete, { uid, action: 'delete' });
291
+
268
292
  // Trigger webhooks. One for each entity
269
293
  await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
270
294
 
271
295
  return deletedEntities;
272
296
  },
273
297
 
274
- load(uid, entity, field, params = {}) {
298
+ async load(uid, entity, field, params = {}) {
275
299
  if (!_.isString(field)) {
276
300
  throw new Error(`Invalid load. Expected "${field}" to be a string`);
277
301
  }
278
302
 
279
- return db.query(uid).load(entity, field, transformLoadParamsToQuery(uid, field, params));
303
+ const loadedEntity = await db
304
+ .query(uid)
305
+ .load(entity, field, transformLoadParamsToQuery(uid, field, params));
306
+
307
+ return this.wrapResult(loadedEntity, { uid, field, action: 'load' });
280
308
  },
281
309
 
282
- loadPages(uid, entity, field, params = {}, pagination = {}) {
310
+ async loadPages(uid, entity, field, params = {}, pagination = {}) {
283
311
  if (!_.isString(field)) {
284
312
  throw new Error(`Invalid load. Expected "${field}" to be a string`);
285
313
  }
@@ -293,7 +321,12 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
293
321
 
294
322
  const query = transformLoadParamsToQuery(uid, field, params, pagination);
295
323
 
296
- return db.query(uid).loadPages(entity, field, query);
324
+ const loadedPage = await db.query(uid).loadPages(entity, field, query);
325
+
326
+ return {
327
+ ...loadedPage,
328
+ results: await this.wrapResult(loadedPage.results, { uid, field, action: 'load' }),
329
+ };
297
330
  },
298
331
  });
299
332
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.10.6",
3
+ "version": "4.10.7",
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",
@@ -81,19 +81,19 @@
81
81
  "dependencies": {
82
82
  "@koa/cors": "3.4.3",
83
83
  "@koa/router": "10.1.1",
84
- "@strapi/admin": "4.10.6",
85
- "@strapi/data-transfer": "4.10.6",
86
- "@strapi/database": "4.10.6",
87
- "@strapi/generate-new": "4.10.6",
88
- "@strapi/generators": "4.10.6",
89
- "@strapi/logger": "4.10.6",
90
- "@strapi/permissions": "4.10.6",
91
- "@strapi/plugin-content-manager": "4.10.6",
92
- "@strapi/plugin-content-type-builder": "4.10.6",
93
- "@strapi/plugin-email": "4.10.6",
94
- "@strapi/plugin-upload": "4.10.6",
95
- "@strapi/typescript-utils": "4.10.6",
96
- "@strapi/utils": "4.10.6",
84
+ "@strapi/admin": "4.10.7",
85
+ "@strapi/data-transfer": "4.10.7",
86
+ "@strapi/database": "4.10.7",
87
+ "@strapi/generate-new": "4.10.7",
88
+ "@strapi/generators": "4.10.7",
89
+ "@strapi/logger": "4.10.7",
90
+ "@strapi/permissions": "4.10.7",
91
+ "@strapi/plugin-content-manager": "4.10.7",
92
+ "@strapi/plugin-content-type-builder": "4.10.7",
93
+ "@strapi/plugin-email": "4.10.7",
94
+ "@strapi/plugin-upload": "4.10.7",
95
+ "@strapi/typescript-utils": "4.10.7",
96
+ "@strapi/utils": "4.10.7",
97
97
  "bcryptjs": "2.4.3",
98
98
  "boxen": "5.1.2",
99
99
  "chalk": "4.1.2",
@@ -142,5 +142,5 @@
142
142
  "node": ">=14.19.1 <=18.x.x",
143
143
  "npm": ">=6.0.0"
144
144
  },
145
- "gitHead": "7dbae9d05d765b85927e1ccff282ac9d82d0a9eb"
145
+ "gitHead": "da080df32b85cdd59d46bdda5c984a346cad0860"
146
146
  }