Skip to content

Commit

Permalink
[dsch] added support for mongoose@7
Browse files Browse the repository at this point in the history
  • Loading branch information
DScheglov committed Jul 12, 2023
1 parent 6ac31cd commit a84e29a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
language: node_js
node_js:
- "10"
- "12"
- "14"
- "16"
- "18"

env:
- MONGOOSE_VERSION=5
- MONGOOSE_VERSION=6
- MONGOOSE_VERSION=7

install:
- npm install
Expand Down
15 changes: 15 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,26 @@ const hasProperty = Function.prototype.call.bind(

const readConstraint = constraint => (Array.isArray(constraint) ? constraint[0] : constraint);

const normalizeSelection = fields => Object.keys(fields).reduce(
(target, key) => Object.defineProperty(
target,
key.replace(/^-/, ''),
{
value: fields[key],
enumerable: true,
writable: true,
configurable: true,
},
),
{},
);

module.exports = {
findPath,
ensurePath,
compose,
idX,
hasProperty,
readConstraint,
normalizeSelection,
};
4 changes: 3 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { findPath } = require('./helpers');
const { findPath, normalizeSelection } = require('./helpers');

module.exports = model_jsonSchema;

Expand Down Expand Up @@ -139,6 +139,8 @@ function __excludedPaths(schema, selection) {
}, {});
}

selection = normalizeSelection(selection);

const needToAddVirtuals = schema.options && schema.options.toJSON
&& (schema.options.toJSON.virtuals || schema.options.toJSON.getters);

Expand Down

0 comments on commit a84e29a

Please sign in to comment.