File tree Expand file tree Collapse file tree 7 files changed +79
-84
lines changed Expand file tree Collapse file tree 7 files changed +79
-84
lines changed Original file line number Diff line number Diff line change 7
7
runs-on : ubuntu-latest
8
8
strategy :
9
9
matrix :
10
- node_version : [12, 14 ]
10
+ node_version : [14, 16 ]
11
11
12
12
steps :
13
- - uses : actions/checkout@master
14
- - name : Use Node.js ${{ matrix.node_version }}
15
- uses : actions/setup-node@v1
16
- with :
17
- version : ${{ matrix.node_version }}
18
- - name : Test
19
- run : |
20
- npm install
21
- npm test
13
+ - uses : actions/checkout@master
14
+ - uses : actions/setup-node@v1
15
+ with :
16
+ version : ${{ matrix.node_version }}
17
+ - name : Test
18
+ run : yarn && yarn test
Original file line number Diff line number Diff line change 11
11
- uses : actions/checkout@v1
12
12
- uses : actions/setup-node@v1
13
13
with :
14
- node-version : 14
14
+ node-version : 16
15
15
16
16
publish-npm :
17
17
name : Publish to npm
21
21
- uses : actions/checkout@v1
22
22
- uses : actions/setup-node@v1
23
23
with :
24
- node-version : 14
24
+ node-version : 16
25
25
registry-url : https://registry.npmjs.org/
26
26
- run : npm publish
27
27
env :
35
35
- uses : actions/checkout@v1
36
36
- uses : actions/setup-node@v1
37
37
with :
38
- node-version : 14
38
+ node-version : 16
39
39
registry-url : https://npm.pkg.github.com/
40
40
scope : ' @abranhe'
41
41
- name : Rename package to match GitHub repository
44
44
- run : echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
45
45
- run : npm publish --access public
46
46
env :
47
- NODE_AUTH_TOKEN : ${{secrets.GITHUB_TOKEN}}
47
+ NODE_AUTH_TOKEN : ${{secrets.GITHUB_TOKEN}}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
-
3
- module . exports = schema => {
1
+ const normalizeMongoose = schema => {
4
2
const {
5
3
toJSON,
6
4
normalizeId,
7
5
removeVersion,
8
6
removePrivatePaths,
9
- toJSON : { transform} = { }
7
+ toJSON : { transform} = { } ,
10
8
} = schema . options ;
11
9
12
10
const json = {
13
- transform ( doc , ret , options ) {
11
+ transform ( doc , returnValue , options ) {
14
12
if ( ! removePrivatePaths ) {
15
13
const { paths} = schema ;
16
14
17
15
for ( const path in paths ) {
18
- if ( paths [ path ] . options && paths [ path ] . options . private ) {
19
- if ( ret [ path ] ) {
20
- delete ret [ path ] ;
21
- }
16
+ if ( paths [ path ] . options && paths [ path ] . options . private && returnValue [ path ] ) {
17
+ delete returnValue [ path ] ;
22
18
}
23
19
}
24
20
}
25
21
26
22
if ( ! removeVersion ) {
27
- const { __v} = ret ;
23
+ const { __v} = returnValue ;
28
24
29
25
if ( ! __v ) {
30
- delete ret . __v ;
26
+ delete returnValue . __v ;
31
27
}
32
28
}
33
29
34
30
if ( ! normalizeId ) {
35
- const { _id, id} = ret ;
31
+ const { _id, id} = returnValue ;
36
32
37
33
if ( _id && ! id ) {
38
- ret . id = _id . toString ( ) ;
39
- delete ret . _id ;
34
+ returnValue . id = _id . toString ( ) ;
35
+ delete returnValue . _id ;
40
36
}
41
37
}
42
38
43
39
if ( transform ) {
44
- return transform ( doc , ret , options ) ;
40
+ return transform ( doc , returnValue , options ) ;
45
41
}
46
- }
42
+ } ,
47
43
} ;
48
44
49
45
schema . options . toJSON = { ...toJSON , ...json } ;
50
46
} ;
47
+
48
+ export default normalizeMongoose ;
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " normalize-mongoose" ,
3
- "version" : " 0.0.2" ,
4
- "description" : " Normalize Mongoose JSON output" ,
5
- "license" : " MIT" ,
6
- "repository" : " abranhe/normalize-mongoose" ,
7
- "homepage" : " https://p.abranhe.com/normalize-mongoose" ,
8
- "author" : {
9
- "name" : " Abraham Hernandez" ,
10
-
11
- "url" : " https://abranhe.com"
12
- },
13
- "engines" : {
14
- "node" : " >=8"
15
- },
16
- "scripts" : {
17
- "test" : " xo && ava"
18
- },
19
- "files" : [ " index.js" , " index.d.ts" ],
20
- "keywords" : [
21
- " mongoose" ,
22
- " normalize" ,
23
- " normalize-mongoose" ,
24
- " plugin" ,
25
- " mongoose-plugin"
26
- ],
27
- "devDependencies" : {
28
- "ava" : " ^3.15.0" ,
29
- "mongoose" : " ^6.0.4" ,
30
- "xo" : " ^0.46.1" ,
31
- "mongodb-memory-server" : " ^7.2.0"
32
- },
33
- "xo" : {
34
- "rules" : {
35
- "new-cap" : 0
36
- }
37
- }
2
+ "name" : " normalize-mongoose" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " Normalize Mongoose JSON output" ,
5
+ "license" : " MIT" ,
6
+ "repository" : " abranhe/normalize-mongoose" ,
7
+ "homepage" : " https://p.abranhe.com/normalize-mongoose" ,
8
+ "author" : {
9
+ "name" : " Abraham Hernandez" ,
10
+
11
+ "url" : " https://abranhe.com"
12
+ },
13
+ "type" : " module" ,
14
+ "engines" : {
15
+ "node" : " >=12"
16
+ },
17
+ "scripts" : {
18
+ "test" : " xo && ava"
19
+ },
20
+ "files" : [
21
+ " index.js" ,
22
+ " index.d.ts"
23
+ ],
24
+ "keywords" : [
25
+ " mongoose" ,
26
+ " normalize" ,
27
+ " normalize-mongoose" ,
28
+ " plugin" ,
29
+ " mongoose-plugin"
30
+ ],
31
+ "devDependencies" : {
32
+ "ava" : " ^3.15.0" ,
33
+ "mongodb-memory-server" : " ^7.2.0" ,
34
+ "mongoose" : " ^6.0.4" ,
35
+ "xo" : " ^0.46.3"
36
+ },
37
+ "xo" : {
38
+ "rules" : {
39
+ "new-cap" : " off"
40
+ }
41
+ }
38
42
}
Original file line number Diff line number Diff line change 1
- # normalize-mongoose [ ![ Build Status] ( https://travis-ci.com/abranhe/normalize-mongoose.svg )] ( https://travis-ci.com/abranhe/normalize-mongoose ) [ ![ GH Status] ( https://github.com/abranhe/normalize-mongoose/workflows/build/badge.svg )] ( https://github.com/abranhe/normalize-mongoose/actions ) [ ![ NPM] ( https://img.shields.io/npm/v/normalize-mongoose )] ( https://npmjs.org/normalize-mongoose )
1
+ # normalize-mongoose
2
+
3
+ [ ![ GH Status] ( https://github.com/abranhe/normalize-mongoose/workflows/build/badge.svg )] ( https://github.com/abranhe/normalize-mongoose/actions )
4
+ [ ![ NPM] ( https://img.shields.io/npm/v/normalize-mongoose )] ( https://npmjs.org/normalize-mongoose )
5
+ [ ![ License] ( https://img.shields.io/npm/l/normalize-mongoose )] ( https://npmjs.org/normalize-mongoose )
2
6
3
7
> Normalize Mongoose JSON output
4
8
@@ -22,7 +26,7 @@ $ npm install abranhe@normalize-mongoose
22
26
import mongoose from ' mongoose' ;
23
27
import normalize from ' normalize-mongoose' ;
24
28
25
- const personSchema = mongoose .Schema ({
29
+ const personSchema = mongoose .Schema ({
26
30
name: String ,
27
31
age: Number ,
28
32
});
@@ -57,7 +61,7 @@ See how `normalize-mongoose` will clean the the JSON output:
57
61
import mongoose from ' mongoose' ;
58
62
import normalize from ' normalize-mongoose' ;
59
63
60
- const personSchema = mongoose .Schema ({
64
+ const personSchema = mongoose .Schema ({
61
65
name: String ,
62
66
age: Number ,
63
67
email: String ,
Original file line number Diff line number Diff line change 1
1
import test from 'ava' ;
2
2
import mongoose from 'mongoose' ;
3
- import mms from 'mongodb-memory-server' ;
4
- import nm from '.' ;
3
+ import { MongoMemoryServer } from 'mongodb-memory-server' ;
4
+ import nm from './index.js ' ;
5
5
6
6
test ( 'Main' , async t => {
7
- const mongodb = new mms ( ) ;
8
- mongoose . connect ( await mongodb . getConnectionString ( ) , { useNewUrlParser : true } ) ;
7
+ const mongodb = await MongoMemoryServer . create ( ) ;
8
+ mongoose . connect ( mongodb . getUri ( ) , { useNewUrlParser : true } ) ;
9
9
10
10
const personSchema = mongoose . Schema ( {
11
11
name : String ,
12
12
age : Number ,
13
13
email : String ,
14
- password : { type : String , private : true }
14
+ password : { type : String , private : true } ,
15
15
} ) ;
16
16
17
17
personSchema . plugin ( nm ) ;
@@ -24,7 +24,7 @@ test('Main', async t => {
24
24
name : 'Abraham' ,
25
25
age : 7 ,
26
26
27
- password : 'my_awesome_password'
27
+ password : 'my_awesome_password' ,
28
28
} ) ;
29
29
30
30
someone . save ( ) ;
@@ -34,7 +34,7 @@ test('Main', async t => {
34
34
const expected = {
35
35
age : 7 ,
36
36
37
- name : 'Abraham'
37
+ name : 'Abraham' ,
38
38
} ;
39
39
40
40
t . deepEqual ( result , { ...expected , id : result . id } ) ;
You can’t perform that action at this time.
0 commit comments