Skip to content

Commit a3b6cd6

Browse files
authored
chore(force-release): release version 7
2 parents 0f989a5 + 2114fa0 commit a3b6cd6

File tree

16 files changed

+1071
-535
lines changed

16 files changed

+1071
-535
lines changed

CHANGELOG.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# [7.0.0-beta.5](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.0.0-beta.4...v7.0.0-beta.5) (2021-02-09)
2+
3+
4+
### Bug Fixes
5+
6+
* **forestadmin-schema:** regenerate forestadmin schema only when files are valid ([#477](https://github.com/ForestAdmin/forest-express-mongoose/issues/477)) ([558177a](https://github.com/ForestAdmin/forest-express-mongoose/commit/558177a89f81937c24c7d22258c20cf2d5faf178))
7+
* **smart-action-hook:** value injected to an enum field of type is now correctly handled ([#480](https://github.com/ForestAdmin/forest-express-mongoose/issues/480)) ([2593fb5](https://github.com/ForestAdmin/forest-express-mongoose/commit/2593fb588d2a3ce01e52969a5b3fb1800ee59cdc))
8+
* array display with smart field ([#464](https://github.com/ForestAdmin/forest-express-mongoose/issues/464)) ([2119f53](https://github.com/ForestAdmin/forest-express-mongoose/commit/2119f53d7e76dc2ca86f7b4906f4488d06153db1))
9+
* display correct reference field when it is a smartfield ([#471](https://github.com/ForestAdmin/forest-express-mongoose/issues/471)) ([ade568a](https://github.com/ForestAdmin/forest-express-mongoose/commit/ade568ae33bbe8fdcf26d1073263a0c82c365254))
10+
* fix related data list display ([#467](https://github.com/ForestAdmin/forest-express-mongoose/issues/467)) ([4ffa177](https://github.com/ForestAdmin/forest-express-mongoose/commit/4ffa177f19bb6bad622cc8d75caad56a85c28b7a))
11+
* **filters:** ensure 'is present' behaves as in forest-express-sequelize ([1a914c1](https://github.com/ForestAdmin/forest-express-mongoose/commit/1a914c1c611b5c2a13b001546b0de6081c6a25d0))
12+
* **filters:** ensure 'is present' behaves as in forest-express-sequelize ([fb3d531](https://github.com/ForestAdmin/forest-express-mongoose/commit/fb3d5311b2b4269edffba688dfe3b3bd3c98dd42))
13+
14+
15+
### Features
16+
17+
* **filter:** add possibility to filter on smart field ([090a902](https://github.com/ForestAdmin/forest-express-mongoose/commit/090a902d1f85cc082b0d4176343a19f823e3421d))
18+
* **filter:** add possibility to filter on smart field ([#478](https://github.com/ForestAdmin/forest-express-mongoose/issues/478)) ([e27feca](https://github.com/ForestAdmin/forest-express-mongoose/commit/e27feca408f26efcf61d65e7b47a1d9ae1ad2dfc))
19+
* **smart actions:** introduce smart action forms hooks ([#459](https://github.com/ForestAdmin/forest-express-mongoose/issues/459)) ([a7c8183](https://github.com/ForestAdmin/forest-express-mongoose/commit/a7c81838b27333b90d90815a6209c4a713176ad9))
20+
121
## [6.7.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v6.7.1...v6.7.2) (2021-01-20)
222

323

@@ -20,6 +40,20 @@
2040
* **filter:** add possibility to filter on smart field ([090a902](https://github.com/ForestAdmin/forest-express-mongoose/commit/090a902d1f85cc082b0d4176343a19f823e3421d))
2141
* **filter:** add possibility to filter on smart field ([#478](https://github.com/ForestAdmin/forest-express-mongoose/issues/478)) ([e27feca](https://github.com/ForestAdmin/forest-express-mongoose/commit/e27feca408f26efcf61d65e7b47a1d9ae1ad2dfc))
2242

43+
# [7.0.0-beta.4](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.0.0-beta.3...v7.0.0-beta.4) (2021-01-08)
44+
45+
46+
### Bug Fixes
47+
48+
* **authentication:** error when authenticating with an invalid token in cookies ([#476](https://github.com/ForestAdmin/forest-express-mongoose/issues/476)) ([e61460a](https://github.com/ForestAdmin/forest-express-mongoose/commit/e61460a8c35d2bae86a9c915908ae1a8146243c3))
49+
50+
# [7.0.0-beta.3](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.0.0-beta.2...v7.0.0-beta.3) (2021-01-06)
51+
52+
53+
### Bug Fixes
54+
55+
* user being disconnected after 33min instead of 14 days ([#474](https://github.com/ForestAdmin/forest-express-mongoose/issues/474)) ([8a70566](https://github.com/ForestAdmin/forest-express-mongoose/commit/8a70566653c52c4447668cbe9e383488e4c3a071))
56+
2357
## [6.6.3](https://github.com/ForestAdmin/forest-express-mongoose/compare/v6.6.2...v6.6.3) (2020-12-21)
2458

2559

@@ -47,6 +81,7 @@
4781
### Features
4882

4983
* **smart actions:** introduce smart action forms hooks ([#459](https://github.com/ForestAdmin/forest-express-mongoose/issues/459)) ([a7c8183](https://github.com/ForestAdmin/forest-express-mongoose/commit/a7c81838b27333b90d90815a6209c4a713176ad9))
84+
* **role-permissions:** support the new role ACL format ([#577](https://github.com/ForestAdmin/forest-express/issues/569)) ([4aed30f](https://github.com/ForestAdmin/forest-express/commit/4aed30fefabf616360a05e54e7b4c6ff71c7a038))
5085

5186
## [6.5.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v6.5.1...v6.5.2) (2020-12-03)
5287

@@ -56,6 +91,18 @@
5691
* **filters:** ensure 'is present' behaves as in forest-express-sequelize ([1a914c1](https://github.com/ForestAdmin/forest-express-mongoose/commit/1a914c1c611b5c2a13b001546b0de6081c6a25d0))
5792
* **filters:** ensure 'is present' behaves as in forest-express-sequelize ([fb3d531](https://github.com/ForestAdmin/forest-express-mongoose/commit/fb3d5311b2b4269edffba688dfe3b3bd3c98dd42))
5893

94+
# [7.0.0-beta.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.0.0-beta.1...v7.0.0-beta.2) (2020-12-02)
95+
96+
97+
### Bug Fixes
98+
99+
* **smart fields:** compute properly smart fields with mongoose ([#453](https://github.com/ForestAdmin/forest-express-mongoose/issues/453)) ([55c33f7](https://github.com/ForestAdmin/forest-express-mongoose/commit/55c33f774b1b4fe4f2c490d6b0ac354a5d7c8f5f))
100+
* export error handler middleware ([#443](https://github.com/ForestAdmin/forest-express-mongoose/issues/443)) ([220f4c3](https://github.com/ForestAdmin/forest-express-mongoose/commit/220f4c37b9d0b1e652ce3e4c9489c49932a7abc8))
101+
102+
### Features
103+
104+
* **smart actions:** endpoint that handle forms' load hooks ([86b15a3](https://github.com/ForestAdmin/forest-express-mongoose/commit/86b15a37bdf2f702142b83fbc0882a8cfd6c7359))
105+
59106
## [6.5.1](https://github.com/ForestAdmin/forest-express-mongoose/compare/v6.5.0...v6.5.1) (2020-12-01)
60107

61108

@@ -77,6 +124,20 @@
77124

78125
* export error handler middleware ([#443](https://github.com/ForestAdmin/forest-express-mongoose/issues/443)) ([220f4c3](https://github.com/ForestAdmin/forest-express-mongoose/commit/220f4c37b9d0b1e652ce3e4c9489c49932a7abc8))
79126

127+
# [7.0.0-beta.1](https://github.com/ForestAdmin/forest-express-mongoose/compare/v6.4.0...v7.0.0-beta.1) (2020-11-24)
128+
129+
130+
### Features
131+
132+
* init function now uses connections & objectMapping instead of sequelize as parameter ([#432](https://github.com/ForestAdmin/forest-express-mongoose/issues/432)) ([97b2ac2](https://github.com/ForestAdmin/forest-express-mongoose/commit/97b2ac2e29374de51435c5dff79fd033b41b74eb))
133+
134+
135+
### BREAKING CHANGES
136+
137+
* mongoose options is not supported anymore by Liana.init()
138+
connections and objectMapping is now required on Liana.init().
139+
Update forest-express dependency to 8.0.0-beta.1 (See https://github.com/ForestAdmin/forest-express/tree/v8.0.0-beta.1)
140+
80141
# [6.4.0](https://github.com/ForestAdmin/forest-express-mongoose/compare/v6.3.10...v6.4.0) (2020-11-17)
81142

82143

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "forest-express-mongoose",
33
"description": "Official Express/Mongoose Liana for Forest",
4-
"version": "6.7.2",
4+
"version": "7.0.0-beta.5",
55
"author": "Sandro Munda <[email protected]>",
66
"contributors": [
77
"Arnaud Besnier <[email protected]>",
@@ -26,7 +26,7 @@
2626
"dependencies": {
2727
"@babel/runtime": "7.10.1",
2828
"bluebird": "2.9.25",
29-
"forest-express": "7.9.6",
29+
"forest-express": "8.0.0",
3030
"http-errors": "1.7.2",
3131
"lodash": "4.17.19",
3232
"moment": "2.24.0",

src/adapters/mongoose.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const P = require('bluebird');
22
const _ = require('lodash');
33
const Interface = require('forest-express');
44
const utils = require('../utils/schema');
5-
const mongooseUtils = require('../services/mongoose-utils');
65

76
/* eslint-disable */
87
function unflatten(data) {
@@ -27,15 +26,14 @@ function unflatten(data) {
2726
module.exports = (model, opts) => {
2827
const fields = [];
2928
const paths = unflatten(model.schema.paths);
30-
const { mongoose } = opts;
29+
const { Mongoose } = opts;
3130
// NOTICE: mongoose.base is used when opts.mongoose is not the default connection.
32-
const Schema = mongoose.Schema || mongoose.base.Schema;
3331
let schemaType;
3432

3533
function formatRef(ref) {
36-
const models = mongooseUtils.getModels(opts);
37-
if (models[ref]) {
38-
return utils.getModelName(models[ref]);
34+
const referenceModel = utils.getReferenceModel(opts, ref);
35+
if (referenceModel) {
36+
return utils.getModelName(referenceModel);
3937
}
4038
Interface.logger.warn(`Cannot find the reference "${ref}" on the model "${model.modelName}".`);
4139
return null;
@@ -105,7 +103,7 @@ module.exports = (model, opts) => {
105103
if (_.isFunction(type) && type.name === 'ObjectId') {
106104
return 'String';
107105
}
108-
if (type instanceof Schema) {
106+
if (type instanceof Mongoose.Schema) {
109107
return schemaType(type);
110108
}
111109

@@ -138,7 +136,7 @@ module.exports = (model, opts) => {
138136
|| _.keys(fieldInfo.caster.options).length === 0)) {
139137
return [getTypeFromMongoose(fieldInfo.caster)];
140138
}
141-
if (fieldInfo.options.type[0] instanceof Schema) {
139+
if (fieldInfo.options.type[0] instanceof Mongoose.Schema) {
142140
// Schema
143141
return [schemaType(fieldInfo.options.type[0])];
144142
}
@@ -212,7 +210,7 @@ module.exports = (model, opts) => {
212210
|| (
213211
fieldInfo.path === '_id'
214212
&& !fieldInfo.options.auto
215-
&& fieldInfo.options.type !== mongoose.Schema.ObjectId
213+
&& fieldInfo.options.type !== Mongoose.ObjectId
216214
);
217215
}
218216

src/index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const P = require('bluebird');
33
const Interface = require('forest-express');
44
const utils = require('./utils/schema');
55
const orm = require('./utils/orm');
6-
const mongooseUtils = require('./services/mongoose-utils');
76

87
const REGEX_VERSION = /(\d+\.)?(\d+\.)?(\*|\d+)/;
98

@@ -29,11 +28,18 @@ exports.PUBLIC_ROUTES = Interface.PUBLIC_ROUTES;
2928
exports.init = (opts) => {
3029
exports.opts = opts;
3130

32-
// NOTICE: Ensure compatibility with the old middleware configuration.
33-
if (!('connections' in opts)) {
34-
opts.connections = [opts.mongoose];
31+
if (!opts.objectMapping) {
32+
Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
33+
return Promise.resolve(() => {});
3534
}
3635

36+
if (opts.mongoose) {
37+
Interface.logger.warn('The mongoose option is not supported anymore. Please remove this option.');
38+
}
39+
40+
opts.Mongoose = opts.objectMapping;
41+
opts.useMultipleDatabases = Object.keys(opts.connections).length > 1;
42+
3743
exports.getLianaName = () => 'forest-express-mongoose';
3844

3945
exports.getLianaVersion = () => {
@@ -44,17 +50,12 @@ exports.init = (opts) => {
4450
return null;
4551
};
4652

47-
exports.getOrmVersion = () => {
48-
if (!opts.mongoose) { return null; }
49-
return orm.getVersion(opts.mongoose);
50-
};
53+
exports.getOrmVersion = () => orm.getVersion(opts.Mongoose);
5154

52-
exports.getDatabaseType = () => 'MongoDB';
55+
exports.getDatabaseType = () => (opts.useMultipleDatabases ? 'multiple' : 'MongoDB');
5356

5457
exports.SchemaAdapter = require('./adapters/mongoose');
5558

56-
exports.getModels = () => mongooseUtils.getModels(opts);
57-
5859
exports.getModelName = utils.getModelName;
5960
// TODO: Remove nameOld attribute once the lianas versions older than 2.0.0 are minority
6061
exports.getModelNameOld = utils.getModelNameOld;

src/services/filters-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function FiltersParser(model, timezone, options) {
1818
const parseString = (value) => {
1919
// NOTICE: Check if the value is a real ObjectID. By default, the isValid method returns true
2020
// for a random string with length 12 (example: 'Black Friday').
21-
const { ObjectId } = options.mongoose.Types;
21+
const { ObjectId } = options.Mongoose.Types;
2222
if (ObjectId.isValid(value) && ObjectId(value).toString() === value) {
2323
return ObjectId(value);
2424
}

src/services/has-many-getter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function HasManyGetter(model, association, opts, params) {
4949
return new P((resolve, reject) => {
5050
let id = params.recordId;
5151
if (OBJECTID_REGEXP.test(params.recordId)) {
52-
id = opts.mongoose.Types.ObjectId(id);
52+
id = opts.Mongoose.Types.ObjectId(id);
5353
}
5454

5555
return model

src/services/mongoose-utils.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/services/query-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function QueryBuilder(model, params, opts) {
4747
return this;
4848
}
4949

50-
const referencedKey = field.reference.split('.')[1];
50+
const referencedKey = utils.getReferenceField(field.reference);
5151
const subModel = utils.getReferenceModel(opts, field.reference);
5252
joinQuery.push({
5353
$lookup: {
@@ -111,7 +111,7 @@ function QueryBuilder(model, params, opts) {
111111
};
112112

113113
this.addCountToQuery = (jsonQuery) => {
114-
if (Orm.hasRequiredVersion(opts.mongoose, '3.4')) {
114+
if (Orm.hasRequiredVersion(opts.Mongoose, '3.4')) {
115115
jsonQuery.push({ $count: 'count' });
116116
} else {
117117
jsonQuery.push({ $group: { _id: null, count: { $sum: 1 } } });

src/services/search-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function SearchBuilder(model, opts, params, searchFields) {
3030

3131
if (value.instance === 'ObjectID') {
3232
if (new RegExp('^[0-9a-fA-F]{24}$').test(params.search)) {
33-
condition[key] = opts.mongoose.Types.ObjectId(params.search);
33+
condition[key] = opts.Mongoose.Types.ObjectId(params.search);
3434
pushCondition(condition, key);
3535
}
3636
} else if (value.instance === 'Number') {

src/utils/schema.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const mongooseUtils = require('../services/mongoose-utils');
2-
31
exports.getReferenceModel = (options, reference) => {
4-
const models = mongooseUtils.getModels(options);
5-
return models[exports.getReferenceCollectionName(reference)];
2+
const { connections } = options;
3+
return Object.values(connections)
4+
.reduce((models, connection) => models.concat(Object.values(connection.models)), [])
5+
.find((model) => exports.getModelName(model) === exports.getReferenceCollectionName(reference));
66
};
77

88
exports.getReferenceField = (reference) => reference.split('.')[1];

0 commit comments

Comments
 (0)