forest-express-sequelize 8.4.8 → 8.4.9

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [8.4.9](https://github.com/ForestAdmin/forest-express-sequelize/compare/v8.4.8...v8.4.9) (2022-01-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * return data of field who have the same name as model ([#880](https://github.com/ForestAdmin/forest-express-sequelize/issues/880)) ([cee9327](https://github.com/ForestAdmin/forest-express-sequelize/commit/cee9327ac9fb5dec1e2c6293a4955390db059ff8))
7
+
1
8
  ## [8.4.8](https://github.com/ForestAdmin/forest-express-sequelize/compare/v8.4.7...v8.4.8) (2021-11-30)
2
9
 
3
10
 
@@ -78,7 +78,7 @@ function extractRequestedFields(requestedFields, modelOrAssociation, schemas) {
78
78
  return extractRequestedFieldsForAssociation(associationName, requestedFields && requestedFields[associationName] ? requestedFields[associationName].split(',') : [], schemas[modelOrAssociation.associations[associationName].target.name]);
79
79
  }).flat();
80
80
  const modelFields = requestedFields[modelOrAssociation.name].split(',').filter(function (fieldName) {
81
- return !requestedFields[fieldName];
81
+ return Object.prototype.hasOwnProperty.call(modelOrAssociation.rawAttributes, fieldName);
82
82
  });
83
83
  const smartFields = extractRequestedSmartField(requestedFields, schemas[modelOrAssociation.name]);
84
84
  return Array.from(new Set([...primaryKeyArray, ...modelFields, ...smartFields, ...allAssociationFields]));
@@ -2,7 +2,7 @@ postgres :
2
2
  image : postgres:9.4.5
3
3
  container_name : forest_express_sequelize_postgres
4
4
  ports :
5
- - "5436:5432"
5
+ - "5437:5432"
6
6
  environment:
7
7
  - POSTGRES_DB=forest-express-sequelize-test
8
8
  - POSTGRES_USER=forest
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "forest-express-sequelize",
3
3
  "description": "Official Express/Sequelize Liana for Forest",
4
- "version": "8.4.8",
4
+ "version": "8.4.9",
5
5
  "author": "Sandro Munda <sandro@munda.me>",
6
6
  "contributors": [
7
7
  "Arnaud Besnier <arnaudibesnier@gmail.com>",
@@ -64,7 +64,7 @@
64
64
  "onchange": "6.0.0",
65
65
  "pg": "8.4.2",
66
66
  "semantic-release": "17.4.7",
67
- "semantic-release-npm-deprecate-old-versions": "1.1.2",
67
+ "semantic-release-npm-deprecate-old-versions": "1.3.2",
68
68
  "semantic-release-slack-bot": "2.1.1",
69
69
  "sequelize": "5.21.3",
70
70
  "sequelize-fixtures": "1.1.1",
package/test/databases.js CHANGED
@@ -42,7 +42,7 @@ class ConnectionManager {
42
42
  * @type {Record<string, ConnectionManager>}
43
43
  */
44
44
  module.exports = {
45
- sequelizePostgres: new ConnectionManager('Postgresql 9.4', 'postgres://forest:secret@localhost:5436/forest-express-sequelize-test'),
45
+ sequelizePostgres: new ConnectionManager('Postgresql 9.4', 'postgres://forest:secret@localhost:5437/forest-express-sequelize-test'),
46
46
  sequelizeMySQLMin: new ConnectionManager('MySQL 5.6', 'mysql://forest:secret@localhost:8998/forest-express-sequelize-test'),
47
47
  sequelizeMySQLMax: new ConnectionManager('MySQL 8.0', 'mysql://forest:secret@localhost:8999/forest-express-sequelize-test'),
48
48
  };
@@ -8,7 +8,7 @@ const databaseOptions = {
8
8
  };
9
9
 
10
10
  const sequelize = new Sequelize(
11
- 'postgres://forest:secret@localhost:5436/forest-express-sequelize-test',
11
+ 'postgres://forest:secret@localhost:5437/forest-express-sequelize-test',
12
12
  databaseOptions,
13
13
  );
14
14
 
@@ -23,6 +23,11 @@ describe('services > requested-fields-extractor', () => {
23
23
  name: 'user',
24
24
  primaryKeys: { id: null, uid: null },
25
25
  associations: {},
26
+ rawAttributes: {
27
+ id: {},
28
+ uid: {},
29
+ name: {},
30
+ },
26
31
  };
27
32
 
28
33
  const schemas = {
@@ -51,6 +56,11 @@ describe('services > requested-fields-extractor', () => {
51
56
  name: 'user',
52
57
  primaryKeys: { id: null, uid: null },
53
58
  associations: {},
59
+ rawAttributes: {
60
+ id: {},
61
+ uid: {},
62
+ name: {},
63
+ },
54
64
  };
55
65
 
56
66
  const schemas = {
@@ -68,6 +78,38 @@ describe('services > requested-fields-extractor', () => {
68
78
  expect(result).toStrictEqual(['id', 'name']);
69
79
  });
70
80
 
81
+ it('should include field with same name as the model', () => {
82
+ expect.assertions(1);
83
+
84
+ const fields = {
85
+ user: 'id,user',
86
+ };
87
+
88
+ const model = {
89
+ name: 'user',
90
+ primaryKeys: { id: null },
91
+ associations: {},
92
+ rawAttributes: {
93
+ id: {},
94
+ user: {},
95
+ },
96
+ };
97
+
98
+ const schemas = {
99
+ user: {
100
+ name: 'user',
101
+ fields: [{
102
+ field: 'user',
103
+ isVirtual: false,
104
+ }],
105
+ },
106
+ };
107
+
108
+ const result = extractRequestedFields(fields, model, schemas);
109
+
110
+ expect(result).toStrictEqual(['id', 'user']);
111
+ });
112
+
71
113
  it('should include all associations\' requested fields', () => {
72
114
  expect.assertions(1);
73
115
 
@@ -87,6 +129,11 @@ describe('services > requested-fields-extractor', () => {
87
129
  },
88
130
  },
89
131
  },
132
+ rawAttributes: {
133
+ id: {},
134
+ uid: {},
135
+ name: {},
136
+ },
90
137
  };
91
138
 
92
139
  const schemas = {
@@ -130,6 +177,12 @@ describe('services > requested-fields-extractor', () => {
130
177
  },
131
178
  },
132
179
  },
180
+ rawAttributes: {
181
+ id: {},
182
+ uid: {},
183
+ name: {},
184
+ account: {},
185
+ },
133
186
  };
134
187
 
135
188
  const schemas = {
@@ -180,6 +233,12 @@ describe('services > requested-fields-extractor', () => {
180
233
  },
181
234
  },
182
235
  },
236
+ rawAttributes: {
237
+ id: {},
238
+ uid: {},
239
+ name: {},
240
+ account: {},
241
+ },
183
242
  };
184
243
 
185
244
  const schemas = {
@@ -222,6 +281,10 @@ describe('services > requested-fields-extractor', () => {
222
281
  name: 'user',
223
282
  primaryKeys: { id: null, uid: null },
224
283
  associations: {},
284
+ rawAttributes: {
285
+ id: {},
286
+ uid: {},
287
+ },
225
288
  };
226
289
 
227
290
  const schemas = {