ts-patch-mongoose 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/README.md +22 -3
  2. package/package.json +5 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ts-patch-mongoose
2
2
 
3
- Patch history & events for mongoose models
3
+ Patch history & events plugin for mongoose
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/ts-patch-mongoose)](https://www.npmjs.com/package/ts-patch-mongoose)
6
6
  [![npm](https://img.shields.io/npm/dt/ts-patch-mongoose)](https://www.npmjs.com/package/ts-patch-mongoose)
@@ -19,7 +19,7 @@ Patch history & events for mongoose models
19
19
 
20
20
  ts-patch-mongoose is a plugin for mongoose
21
21
  \
22
- I needed to track changes in my mongoose models and save them as patch history (audit log) in separate collection. Events will allow me to track changes in my models and react to them in other parts of the application. I also wanted to omit some fields from patch history.
22
+ I need to track changes of mongoose models and save them as patch history (audit log) in separate collection. Changes must also emit events that I can subscribe to and react in other parts of my application. I also want to omit some fields from patch history.
23
23
 
24
24
  ## Features
25
25
 
@@ -42,6 +42,8 @@ yarn add ts-patch-mongoose
42
42
 
43
43
  ## Example
44
44
 
45
+ How to use it with express [ts-express-swc](https://github.com/ilovepixelart/ts-express-swc)
46
+
45
47
  Create your event constants `events.ts`
46
48
 
47
49
  ```typescript
@@ -50,6 +52,19 @@ export const USER_UPDATED = 'user-updated'
50
52
  export const USER_DELETED = 'user-deleted'
51
53
  ```
52
54
 
55
+ Create your interface `IUser.ts`
56
+
57
+ ```typescript
58
+ interface IUser {
59
+ name: string
60
+ role: string
61
+ createdAt?: Date
62
+ updatedAt?: Date
63
+ }
64
+
65
+ export default IUser
66
+ ```
67
+
53
68
  Setup your mongoose model `User.ts`
54
69
 
55
70
  ```typescript
@@ -103,10 +118,14 @@ patchEventEmitter.on(USER_CREATED, ({ doc }) => {
103
118
  })
104
119
 
105
120
  patchEventEmitter.on(USER_UPDATED, ({ doc, oldDoc, patch }) => {
106
- console.log('User updated', doc, patch)
121
+ console.log('User updated', doc, oldDoc, patch)
107
122
  })
108
123
 
109
124
  patchEventEmitter.on(USER_DELETED, ({ doc }) => {
110
125
  console.log('User deleted', doc)
111
126
  })
112
127
  ```
128
+
129
+ ## Check my other projects
130
+
131
+ - [ts-migrate-mongoose](https://github.com/ilovepixelart/ts-migrate-mongoose) - Migration framework for mongoose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-patch-mongoose",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Patch history & events for mongoose models",
5
5
  "author": "Alex Eagle",
6
6
  "license": "MIT",
@@ -31,7 +31,9 @@
31
31
  "emit",
32
32
  "create",
33
33
  "update",
34
- "delete"
34
+ "delete",
35
+ "audit",
36
+ "log"
35
37
  ],
36
38
  "engines": {
37
39
  "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
@@ -71,7 +73,7 @@
71
73
  "devDependencies": {
72
74
  "@shelf/jest-mongodb": "4.1.7",
73
75
  "@swc/cli": "0.1.62",
74
- "@swc/core": "1.3.46",
76
+ "@swc/core": "1.3.49",
75
77
  "@swc/helpers": "0.5.0",
76
78
  "@swc/jest": "0.2.24",
77
79
  "@swc/register": "0.1.10",