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 77 runs-on : ubuntu-latest
88 strategy :
99 matrix :
10- node_version : [12, 14 ]
10+ node_version : [14, 16 ]
1111
1212 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 1111 - uses : actions/checkout@v1
1212 - uses : actions/setup-node@v1
1313 with :
14- node-version : 14
14+ node-version : 16
1515
1616 publish-npm :
1717 name : Publish to npm
2121 - uses : actions/checkout@v1
2222 - uses : actions/setup-node@v1
2323 with :
24- node-version : 14
24+ node-version : 16
2525 registry-url : https://registry.npmjs.org/
2626 - run : npm publish
2727 env :
3535 - uses : actions/checkout@v1
3636 - uses : actions/setup-node@v1
3737 with :
38- node-version : 14
38+ node-version : 16
3939 registry-url : https://npm.pkg.github.com/
4040 scope : ' @abranhe'
4141 - name : Rename package to match GitHub repository
4444 - run : echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
4545 - run : npm publish --access public
4646 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 => {
42 const {
53 toJSON,
64 normalizeId,
75 removeVersion,
86 removePrivatePaths,
9- toJSON : { transform} = { }
7+ toJSON : { transform} = { } ,
108 } = schema . options ;
119
1210 const json = {
13- transform ( doc , ret , options ) {
11+ transform ( doc , returnValue , options ) {
1412 if ( ! removePrivatePaths ) {
1513 const { paths} = schema ;
1614
1715 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 ] ;
2218 }
2319 }
2420 }
2521
2622 if ( ! removeVersion ) {
27- const { __v} = ret ;
23+ const { __v} = returnValue ;
2824
2925 if ( ! __v ) {
30- delete ret . __v ;
26+ delete returnValue . __v ;
3127 }
3228 }
3329
3430 if ( ! normalizeId ) {
35- const { _id, id} = ret ;
31+ const { _id, id} = returnValue ;
3632
3733 if ( _id && ! id ) {
38- ret . id = _id . toString ( ) ;
39- delete ret . _id ;
34+ returnValue . id = _id . toString ( ) ;
35+ delete returnValue . _id ;
4036 }
4137 }
4238
4339 if ( transform ) {
44- return transform ( doc , ret , options ) ;
40+ return transform ( doc , returnValue , options ) ;
4541 }
46- }
42+ } ,
4743 } ;
4844
4945 schema . options . toJSON = { ...toJSON , ...json } ;
5046} ;
47+
48+ export default normalizeMongoose ;
Original file line number Diff line number Diff line change 11{
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+ }
3842}
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 )
26
37> Normalize Mongoose JSON output
48
@@ -22,7 +26,7 @@ $ npm install abranhe@normalize-mongoose
2226import mongoose from ' mongoose' ;
2327import normalize from ' normalize-mongoose' ;
2428
25- const personSchema = mongoose .Schema ({
29+ const personSchema = mongoose .Schema ({
2630 name: String ,
2731 age: Number ,
2832});
@@ -57,7 +61,7 @@ See how `normalize-mongoose` will clean the the JSON output:
5761import mongoose from ' mongoose' ;
5862import normalize from ' normalize-mongoose' ;
5963
60- const personSchema = mongoose .Schema ({
64+ const personSchema = mongoose .Schema ({
6165 name: String ,
6266 age: Number ,
6367 email: String ,
Original file line number Diff line number Diff line change 11import test from 'ava' ;
22import 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 ' ;
55
66test ( '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 } ) ;
99
1010 const personSchema = mongoose . Schema ( {
1111 name : String ,
1212 age : Number ,
1313 email : String ,
14- password : { type : String , private : true }
14+ password : { type : String , private : true } ,
1515 } ) ;
1616
1717 personSchema . plugin ( nm ) ;
@@ -24,7 +24,7 @@ test('Main', async t => {
2424 name : 'Abraham' ,
2525 age : 7 ,
262627- password : 'my_awesome_password'
27+ password : 'my_awesome_password' ,
2828 } ) ;
2929
3030 someone . save ( ) ;
@@ -34,7 +34,7 @@ test('Main', async t => {
3434 const expected = {
3535 age : 7 ,
363637- name : 'Abraham'
37+ name : 'Abraham' ,
3838 } ;
3939
4040 t . deepEqual ( result , { ...expected , id : result . id } ) ;
You can’t perform that action at this time.
0 commit comments