ts-patch-mongoose 2.6.4 → 2.6.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 (90) hide show
  1. package/.swcrc +1 -1
  2. package/LICENSE +1 -1
  3. package/biome.json +30 -0
  4. package/dist/cjs/em.js +2 -2
  5. package/dist/cjs/em.js.map +1 -1
  6. package/dist/cjs/helpers.js +1 -1
  7. package/dist/cjs/helpers.js.map +1 -1
  8. package/dist/cjs/hooks/delete-hooks.js +5 -13
  9. package/dist/cjs/hooks/delete-hooks.js.map +1 -1
  10. package/dist/cjs/hooks/save-hooks.js +1 -1
  11. package/dist/cjs/hooks/save-hooks.js.map +1 -1
  12. package/dist/cjs/hooks/update-hooks.js +6 -14
  13. package/dist/cjs/hooks/update-hooks.js.map +1 -1
  14. package/dist/cjs/models/History.js.map +1 -1
  15. package/dist/cjs/patch.js +7 -11
  16. package/dist/cjs/patch.js.map +1 -1
  17. package/dist/cjs/plugin.js +2 -2
  18. package/dist/cjs/plugin.js.map +1 -1
  19. package/dist/cjs/types/em.d.ts +1 -1
  20. package/dist/cjs/types/em.d.ts.map +1 -1
  21. package/dist/cjs/types/hooks/delete-hooks.d.ts.map +1 -1
  22. package/dist/cjs/types/hooks/save-hooks.d.ts.map +1 -1
  23. package/dist/cjs/types/hooks/update-hooks.d.ts.map +1 -1
  24. package/dist/cjs/types/interfaces/IHistory.d.ts +1 -1
  25. package/dist/cjs/types/interfaces/IHistory.d.ts.map +1 -1
  26. package/dist/cjs/types/models/History.d.ts +6 -0
  27. package/dist/cjs/types/models/History.d.ts.map +1 -1
  28. package/dist/cjs/types/patch.d.ts +2 -2
  29. package/dist/cjs/types/patch.d.ts.map +1 -1
  30. package/dist/cjs/types/plugin.d.ts.map +1 -1
  31. package/dist/cjs/version.js +1 -1
  32. package/dist/cjs/version.js.map +1 -1
  33. package/dist/esm/em.js +1 -1
  34. package/dist/esm/em.js.map +1 -1
  35. package/dist/esm/helpers.js +1 -1
  36. package/dist/esm/helpers.js.map +1 -1
  37. package/dist/esm/hooks/delete-hooks.js +5 -13
  38. package/dist/esm/hooks/delete-hooks.js.map +1 -1
  39. package/dist/esm/hooks/save-hooks.js +1 -1
  40. package/dist/esm/hooks/save-hooks.js.map +1 -1
  41. package/dist/esm/hooks/update-hooks.js +6 -14
  42. package/dist/esm/hooks/update-hooks.js.map +1 -1
  43. package/dist/esm/models/History.js.map +1 -1
  44. package/dist/esm/patch.js +7 -11
  45. package/dist/esm/patch.js.map +1 -1
  46. package/dist/esm/plugin.js +2 -2
  47. package/dist/esm/plugin.js.map +1 -1
  48. package/dist/esm/types/em.d.ts +1 -1
  49. package/dist/esm/types/em.d.ts.map +1 -1
  50. package/dist/esm/types/hooks/delete-hooks.d.ts.map +1 -1
  51. package/dist/esm/types/hooks/save-hooks.d.ts.map +1 -1
  52. package/dist/esm/types/hooks/update-hooks.d.ts.map +1 -1
  53. package/dist/esm/types/interfaces/IHistory.d.ts +1 -1
  54. package/dist/esm/types/interfaces/IHistory.d.ts.map +1 -1
  55. package/dist/esm/types/models/History.d.ts +6 -0
  56. package/dist/esm/types/models/History.d.ts.map +1 -1
  57. package/dist/esm/types/patch.d.ts +2 -2
  58. package/dist/esm/types/patch.d.ts.map +1 -1
  59. package/dist/esm/types/plugin.d.ts.map +1 -1
  60. package/dist/esm/version.js +1 -1
  61. package/dist/esm/version.js.map +1 -1
  62. package/jest.config.ts +6 -20
  63. package/package.json +12 -23
  64. package/src/em.ts +1 -1
  65. package/src/helpers.ts +1 -1
  66. package/src/hooks/delete-hooks.ts +6 -14
  67. package/src/hooks/save-hooks.ts +3 -4
  68. package/src/hooks/update-hooks.ts +7 -18
  69. package/src/interfaces/IHistory.ts +1 -1
  70. package/src/interfaces/IHookContext.ts +1 -1
  71. package/src/models/History.ts +41 -38
  72. package/src/patch.ts +10 -15
  73. package/src/plugin.ts +3 -4
  74. package/src/version.ts +1 -1
  75. package/tests/patch.test.ts +2 -2
  76. package/tests/plugin-event-created.test.ts +23 -48
  77. package/tests/plugin-event-deleted.test.ts +4 -4
  78. package/tests/plugin-event-updated.test.ts +34 -22
  79. package/tests/plugin-global.test.ts +39 -35
  80. package/tests/plugin-omit-all.test.ts +2 -2
  81. package/tests/plugin-patch-history-disabled.test.ts +2 -2
  82. package/tests/plugin-pre-delete.test.ts +2 -2
  83. package/tests/plugin-pre-save.test.ts +1 -2
  84. package/tests/plugin.test.ts +3 -3
  85. package/tests/schemas/DescriptionSchema.ts +8 -5
  86. package/tests/schemas/ProductSchema.ts +22 -19
  87. package/tests/schemas/UserSchema.ts +12 -9
  88. package/tsconfig.json +4 -14
  89. package/.eslintignore +0 -4
  90. package/.eslintrc +0 -96
package/src/plugin.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import _ from 'lodash'
2
2
  import em from './em'
3
3
 
4
+ import { toObjectOptions } from './helpers'
4
5
  import { createPatch, deletePatch } from './patch'
5
6
  import { isMongooseLessThan7, isMongooseLessThan8 } from './version'
6
- import { toObjectOptions } from './helpers'
7
7
 
8
+ import { deleteHooksInitialize } from './hooks/delete-hooks'
8
9
  import { saveHooksInitialize } from './hooks/save-hooks'
9
10
  import { updateHooksInitialize } from './hooks/update-hooks'
10
- import { deleteHooksInitialize } from './hooks/delete-hooks'
11
11
 
12
12
  import type { HydratedDocument, Model, Schema } from 'mongoose'
13
- import type IPluginOptions from './interfaces/IPluginOptions'
14
13
  import type IContext from './interfaces/IContext'
14
+ import type IPluginOptions from './interfaces/IPluginOptions'
15
15
 
16
16
  const remove = isMongooseLessThan7 ? 'remove' : 'deleteOne'
17
17
 
@@ -50,7 +50,6 @@ export const patchHistoryPlugin = function plugin<T>(schema: Schema<T>, opts: IP
50
50
  // @ts-expect-error - Mongoose 7 and below
51
51
  schema.pre(remove, { document: true, query: false }, async function () {
52
52
  // @ts-expect-error - Mongoose 7 and below
53
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
54
53
  const original = this.toObject(toObjectOptions) as HydratedDocument<T>
55
54
 
56
55
  if (opts.preDelete && !_.isEmpty(original)) {
package/src/version.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { satisfies } from 'semver'
2
1
  import mongoose from 'mongoose'
2
+ import { satisfies } from 'semver'
3
3
 
4
4
  export const isMongooseLessThan8 = satisfies(mongoose.version, '<8')
5
5
  export const isMongooseLessThan7 = satisfies(mongoose.version, '<7')
@@ -1,6 +1,6 @@
1
1
  import mongoose, { model } from 'mongoose'
2
2
 
3
- import { getUser, getReason, getMetadata, getData, getValue, getJsonOmit, bulkPatch, updatePatch } from '../src/patch'
3
+ import { bulkPatch, getData, getJsonOmit, getMetadata, getReason, getUser, getValue, updatePatch } from '../src/patch'
4
4
  import { patchHistoryPlugin } from '../src/plugin'
5
5
 
6
6
  import UserSchema from './schemas/UserSchema'
@@ -8,10 +8,10 @@ import UserSchema from './schemas/UserSchema'
8
8
  import { USER_DELETED } from './constants/events'
9
9
 
10
10
  import type { HydratedDocument } from 'mongoose'
11
+ import type IContext from '../src/interfaces/IContext'
11
12
  import type { User } from '../src/interfaces/IPluginOptions'
12
13
  import type IPluginOptions from '../src/interfaces/IPluginOptions'
13
14
  import type IUser from './interfaces/IUser'
14
- import type IContext from '../src/interfaces/IContext'
15
15
 
16
16
  import em from '../src/em'
17
17
 
@@ -1,9 +1,9 @@
1
- import { isMongooseLessThan7 } from '../src/version'
2
1
  import mongoose, { Types, model } from 'mongoose'
2
+ import { isMongooseLessThan7 } from '../src/version'
3
3
 
4
- import UserSchema from './schemas/UserSchema'
5
- import { patchHistoryPlugin } from '../src/plugin'
6
4
  import History from '../src/models/History'
5
+ import { patchHistoryPlugin } from '../src/plugin'
6
+ import UserSchema from './schemas/UserSchema'
7
7
 
8
8
  import em from '../src/em'
9
9
  import { USER_CREATED } from './constants/events'
@@ -88,11 +88,14 @@ describe('plugin - event created & patch history disabled', () => {
88
88
  })
89
89
 
90
90
  it('should insertMany() and emit three create events', async () => {
91
- const users = await User.insertMany([
92
- { name: 'John', role: 'user' },
93
- { name: 'Alice', role: 'user' },
94
- { name: 'Bob', role: 'user' },
95
- ], { ordered: true })
91
+ const users = await User.insertMany(
92
+ [
93
+ { name: 'John', role: 'user' },
94
+ { name: 'Alice', role: 'user' },
95
+ { name: 'Bob', role: 'user' },
96
+ ],
97
+ { ordered: true },
98
+ )
96
99
 
97
100
  const [john, alice, bob] = users
98
101
 
@@ -148,17 +151,9 @@ describe('plugin - event created & patch history disabled', () => {
148
151
  describe('upsert cases', () => {
149
152
  it('should update() + upsert and emit one create event', async () => {
150
153
  if (isMongooseLessThan7) {
151
- await User.update(
152
- { name: 'John' },
153
- { name: 'John', role: 'admin' },
154
- { upsert: true },
155
- )
154
+ await User.update({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
156
155
  } else {
157
- await User.findOneAndUpdate(
158
- { name: 'John' },
159
- { name: 'John', role: 'admin' },
160
- { upsert: true },
161
- )
156
+ await User.findOneAndUpdate({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
162
157
  }
163
158
 
164
159
  const user = await User.findOne({ name: 'John', role: 'admin' })
@@ -173,7 +168,7 @@ describe('plugin - event created & patch history disabled', () => {
173
168
  _id: user?._id,
174
169
  name: user?.name,
175
170
  role: user?.role,
176
- // Upsert does not set createdAt and updatedAt
171
+ // Upsert does not set createdAt and updatedAt
177
172
  }),
178
173
  })
179
174
 
@@ -185,11 +180,7 @@ describe('plugin - event created & patch history disabled', () => {
185
180
  })
186
181
 
187
182
  it('should updateOne() + upsert and emit one create event', async () => {
188
- await User.updateOne(
189
- { name: 'John' },
190
- { name: 'John', role: 'admin' },
191
- { upsert: true },
192
- )
183
+ await User.updateOne({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
193
184
 
194
185
  const user = await User.findOne({ name: 'John', role: 'admin' })
195
186
  expect(user).not.toBeNull()
@@ -203,7 +194,7 @@ describe('plugin - event created & patch history disabled', () => {
203
194
  _id: user?._id,
204
195
  name: user?.name,
205
196
  role: user?.role,
206
- // Upsert does not set createdAt and updatedAt
197
+ // Upsert does not set createdAt and updatedAt
207
198
  }),
208
199
  })
209
200
 
@@ -215,11 +206,7 @@ describe('plugin - event created & patch history disabled', () => {
215
206
  })
216
207
 
217
208
  it('should replaceOne() + upsert and emit one create event', async () => {
218
- await User.replaceOne(
219
- { name: 'John' },
220
- { name: 'John', role: 'admin' },
221
- { upsert: true },
222
- )
209
+ await User.replaceOne({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
223
210
 
224
211
  const user = await User.findOne({ name: 'John', role: 'admin' })
225
212
  expect(user).not.toBeNull()
@@ -245,11 +232,7 @@ describe('plugin - event created & patch history disabled', () => {
245
232
  })
246
233
 
247
234
  it('should updateMany() + upsert and emit one create event', async () => {
248
- await User.updateMany(
249
- { name: { $in: ['John', 'Alice', 'Bob'] } },
250
- { name: 'Steve', role: 'admin' },
251
- { upsert: true },
252
- )
235
+ await User.updateMany({ name: { $in: ['John', 'Alice', 'Bob'] } }, { name: 'Steve', role: 'admin' }, { upsert: true })
253
236
 
254
237
  const users = await User.findOne({ name: 'Steve', role: 'admin' })
255
238
 
@@ -262,7 +245,7 @@ describe('plugin - event created & patch history disabled', () => {
262
245
  _id: users?._id,
263
246
  name: users?.name,
264
247
  role: users?.role,
265
- // Upsert does not set createdAt and updatedAt
248
+ // Upsert does not set createdAt and updatedAt
266
249
  }),
267
250
  })
268
251
 
@@ -274,11 +257,7 @@ describe('plugin - event created & patch history disabled', () => {
274
257
  })
275
258
 
276
259
  it('should findOneAndUpdate() + upsert and emit one create event', async () => {
277
- await User.findOneAndUpdate(
278
- { name: 'John' },
279
- { name: 'John', role: 'admin' },
280
- { upsert: true },
281
- )
260
+ await User.findOneAndUpdate({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
282
261
 
283
262
  const user = await User.findOne({ name: 'John', role: 'admin' })
284
263
  expect(user).not.toBeNull()
@@ -292,7 +271,7 @@ describe('plugin - event created & patch history disabled', () => {
292
271
  _id: user?._id,
293
272
  name: user?.name,
294
273
  role: user?.role,
295
- // Upsert does not set createdAt and updatedAt
274
+ // Upsert does not set createdAt and updatedAt
296
275
  }),
297
276
  })
298
277
 
@@ -304,11 +283,7 @@ describe('plugin - event created & patch history disabled', () => {
304
283
  })
305
284
 
306
285
  it('should findOneAndReplace() + upsert and emit one create event', async () => {
307
- await User.findOneAndReplace(
308
- { name: 'John' },
309
- { name: 'John', role: 'admin' },
310
- { upsert: true },
311
- )
286
+ await User.findOneAndReplace({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
312
287
 
313
288
  const user = await User.findOne({ name: 'John', role: 'admin' })
314
289
  expect(user).not.toBeNull()
@@ -322,7 +297,7 @@ describe('plugin - event created & patch history disabled', () => {
322
297
  _id: user?._id,
323
298
  name: user?.name,
324
299
  role: user?.role,
325
- // Upsert does not set createdAt and updatedAt
300
+ // Upsert does not set createdAt and updatedAt
326
301
  }),
327
302
  })
328
303
 
@@ -1,13 +1,13 @@
1
- import { isMongooseLessThan7 } from '../src/version'
2
1
  import mongoose, { model } from 'mongoose'
2
+ import { isMongooseLessThan7 } from '../src/version'
3
3
 
4
- import UserSchema from './schemas/UserSchema'
5
- import { patchHistoryPlugin } from '../src/plugin'
6
4
  import History from '../src/models/History'
5
+ import { patchHistoryPlugin } from '../src/plugin'
6
+ import UserSchema from './schemas/UserSchema'
7
7
 
8
8
  import em from '../src/em'
9
- import { USER_DELETED } from './constants/events'
10
9
  import { toObjectOptions } from '../src/helpers'
10
+ import { USER_DELETED } from './constants/events'
11
11
 
12
12
  jest.mock('../src/em', () => {
13
13
  return {
@@ -2,9 +2,9 @@ import { isMongooseLessThan7 } from '../src/version'
2
2
 
3
3
  import mongoose, { Types, model } from 'mongoose'
4
4
 
5
- import UserSchema from './schemas/UserSchema'
6
- import { patchHistoryPlugin } from '../src/plugin'
7
5
  import History from '../src/models/History'
6
+ import { patchHistoryPlugin } from '../src/plugin'
7
+ import UserSchema from './schemas/UserSchema'
8
8
 
9
9
  import em from '../src/em'
10
10
  import { USER_UPDATED } from './constants/events'
@@ -84,11 +84,14 @@ describe('plugin - event updated & patch history disabled', () => {
84
84
  })
85
85
 
86
86
  it('should update() and emit three update event', async () => {
87
- await User.create([
88
- { name: 'Alice', role: 'user' },
89
- { name: 'Bob', role: 'user' },
90
- { name: 'John', role: 'user' },
91
- ], { ordered: true })
87
+ await User.create(
88
+ [
89
+ { name: 'Alice', role: 'user' },
90
+ { name: 'Bob', role: 'user' },
91
+ { name: 'John', role: 'user' },
92
+ ],
93
+ { ordered: true },
94
+ )
92
95
 
93
96
  if (isMongooseLessThan7) {
94
97
  await User.update({ role: 'user' }, { role: 'manager' })
@@ -114,11 +117,14 @@ describe('plugin - event updated & patch history disabled', () => {
114
117
  })
115
118
 
116
119
  it('should updateOne() and emit one update event', async () => {
117
- await User.create([
118
- { name: 'Alice', role: 'user' },
119
- { name: 'Bob', role: 'user' },
120
- { name: 'John', role: 'user' },
121
- ], { ordered: true })
120
+ await User.create(
121
+ [
122
+ { name: 'Alice', role: 'user' },
123
+ { name: 'Bob', role: 'user' },
124
+ { name: 'John', role: 'user' },
125
+ ],
126
+ { ordered: true },
127
+ )
122
128
 
123
129
  await User.updateOne({ name: 'Bob' }, { role: 'manager' })
124
130
  const users = await User.find({ role: 'manager' })
@@ -139,11 +145,14 @@ describe('plugin - event updated & patch history disabled', () => {
139
145
  })
140
146
 
141
147
  it('should replaceOne() and emit two update event', async () => {
142
- await User.create([
143
- { name: 'Alice', role: 'user' },
144
- { name: 'Bob', role: 'user' },
145
- { name: 'John', role: 'user' },
146
- ], { ordered: true })
148
+ await User.create(
149
+ [
150
+ { name: 'Alice', role: 'user' },
151
+ { name: 'Bob', role: 'user' },
152
+ { name: 'John', role: 'user' },
153
+ ],
154
+ { ordered: true },
155
+ )
147
156
 
148
157
  await User.replaceOne({ name: 'Bob' }, { name: 'Bob Doe', role: 'manager' })
149
158
  const users = await User.find({ role: 'manager' })
@@ -188,11 +197,14 @@ describe('plugin - event updated & patch history disabled', () => {
188
197
  })
189
198
 
190
199
  it('should updateMany() and emit two update event', async () => {
191
- await User.create([
192
- { name: 'Alice', role: 'user' },
193
- { name: 'Bob', role: 'user' },
194
- { name: 'John', role: 'user' },
195
- ], { ordered: true })
200
+ await User.create(
201
+ [
202
+ { name: 'Alice', role: 'user' },
203
+ { name: 'Bob', role: 'user' },
204
+ { name: 'John', role: 'user' },
205
+ ],
206
+ { ordered: true },
207
+ )
196
208
 
197
209
  await User.updateMany({ role: 'user' }, { role: 'manager' })
198
210
  const users = await User.find({ role: 'manager' })
@@ -1,12 +1,12 @@
1
1
  import mongoose from 'mongoose'
2
2
 
3
- import UserSchema from './schemas/UserSchema'
4
- import ProductSchema from './schemas/ProductSchema'
5
- import { patchHistoryPlugin } from '../src/plugin'
6
3
  import History from '../src/models/History'
4
+ import { patchHistoryPlugin } from '../src/plugin'
5
+ import ProductSchema from './schemas/ProductSchema'
6
+ import UserSchema from './schemas/UserSchema'
7
7
 
8
8
  import em from '../src/em'
9
- import { GLOBAL_CREATED, GLOBAL_UPDATED, GLOBAL_DELETED } from './constants/events'
9
+ import { GLOBAL_CREATED, GLOBAL_DELETED, GLOBAL_UPDATED } from './constants/events'
10
10
 
11
11
  jest.mock('../src/em', () => {
12
12
  return { emit: jest.fn() }
@@ -79,9 +79,7 @@ describe('plugin - global', () => {
79
79
  expect(second.doc).toBeUndefined()
80
80
 
81
81
  expect(second.patch).toHaveLength(1)
82
- expect(second.patch).toMatchObject([
83
- { op: 'add', path: '/groups/0', value: 'office' },
84
- ])
82
+ expect(second.patch).toMatchObject([{ op: 'add', path: '/groups/0', value: 'office' }])
85
83
 
86
84
  // 3 update
87
85
  expect(third.version).toBe(2)
@@ -93,9 +91,7 @@ describe('plugin - global', () => {
93
91
  expect(third.doc).toBeUndefined()
94
92
 
95
93
  expect(third.patch).toHaveLength(1)
96
- expect(third.patch).toMatchObject([
97
- { op: 'add', path: '/groups/1', value: 'school' },
98
- ])
94
+ expect(third.patch).toMatchObject([{ op: 'add', path: '/groups/1', value: 'school' }])
99
95
 
100
96
  expect(em.emit).toHaveBeenCalledTimes(3)
101
97
  expect(em.emit).toHaveBeenCalledWith(GLOBAL_CREATED, { doc: first.doc })
@@ -115,13 +111,17 @@ describe('plugin - global', () => {
115
111
  const product = await Product.create({ name: 'paper', groups: [] })
116
112
  expect(product.name).toBe('paper')
117
113
 
118
- await product.updateOne({
119
- groups: ['office'],
120
- }).exec()
114
+ await product
115
+ .updateOne({
116
+ groups: ['office'],
117
+ })
118
+ .exec()
121
119
 
122
- await product.updateOne({
123
- $push: { groups: 'school' },
124
- }).exec()
120
+ await product
121
+ .updateOne({
122
+ $push: { groups: 'school' },
123
+ })
124
+ .exec()
125
125
 
126
126
  const history = await History.find({})
127
127
  expect(history).toHaveLength(3)
@@ -153,9 +153,7 @@ describe('plugin - global', () => {
153
153
  expect(second.doc).toBeUndefined()
154
154
 
155
155
  expect(second.patch).toHaveLength(1)
156
- expect(second.patch).toMatchObject([
157
- { op: 'add', path: '/groups/0', value: 'office' },
158
- ])
156
+ expect(second.patch).toMatchObject([{ op: 'add', path: '/groups/0', value: 'office' }])
159
157
 
160
158
  // 3 update
161
159
  expect(third.version).toBe(2)
@@ -167,9 +165,7 @@ describe('plugin - global', () => {
167
165
  expect(third.doc).toBeUndefined()
168
166
 
169
167
  expect(third.patch).toHaveLength(1)
170
- expect(third.patch).toMatchObject([
171
- { op: 'add', path: '/groups/1', value: 'school' },
172
- ])
168
+ expect(third.patch).toMatchObject([{ op: 'add', path: '/groups/1', value: 'school' }])
173
169
 
174
170
  expect(em.emit).toHaveBeenCalledTimes(3)
175
171
  expect(em.emit).toHaveBeenCalledWith(GLOBAL_CREATED, { doc: first.doc })
@@ -263,13 +259,17 @@ describe('plugin - global', () => {
263
259
  const product = await Product.create({ name: 'paper', description: { summary: 'test1' } })
264
260
  expect(product.name).toBe('paper')
265
261
 
266
- await product.updateOne({
267
- description: { summary: 'test2' },
268
- }).exec()
262
+ await product
263
+ .updateOne({
264
+ description: { summary: 'test2' },
265
+ })
266
+ .exec()
269
267
 
270
- await product.updateOne({
271
- $set: { 'description.summary': 'test3' },
272
- }).exec()
268
+ await product
269
+ .updateOne({
270
+ $set: { 'description.summary': 'test3' },
271
+ })
272
+ .exec()
273
273
 
274
274
  const history = await History.find({})
275
275
  expect(history).toHaveLength(3)
@@ -431,13 +431,17 @@ describe('plugin - global', () => {
431
431
  const product = await Product.create({ name: 'paper', addedBy: john })
432
432
  expect(product.name).toBe('paper')
433
433
 
434
- await product.updateOne({
435
- addedBy: alice,
436
- }).exec()
437
-
438
- await product.updateOne({
439
- addedBy: { _id: john._id, name: 'John', role: 'manager' },
440
- }).exec()
434
+ await product
435
+ .updateOne({
436
+ addedBy: alice,
437
+ })
438
+ .exec()
439
+
440
+ await product
441
+ .updateOne({
442
+ addedBy: { _id: john._id, name: 'John', role: 'manager' },
443
+ })
444
+ .exec()
441
445
 
442
446
  const history = await History.find({})
443
447
  expect(history).toHaveLength(5)
@@ -2,9 +2,9 @@ import { isMongooseLessThan7 } from '../src/version'
2
2
 
3
3
  import mongoose, { Types, model } from 'mongoose'
4
4
 
5
- import UserSchema from './schemas/UserSchema'
6
- import { patchHistoryPlugin } from '../src/plugin'
7
5
  import History from '../src/models/History'
6
+ import { patchHistoryPlugin } from '../src/plugin'
7
+ import UserSchema from './schemas/UserSchema'
8
8
 
9
9
  import em from '../src/em'
10
10
 
@@ -2,9 +2,9 @@ import { isMongooseLessThan7 } from '../src/version'
2
2
 
3
3
  import mongoose, { model } from 'mongoose'
4
4
 
5
- import UserSchema from './schemas/UserSchema'
6
- import { patchHistoryPlugin } from '../src/plugin'
7
5
  import History from '../src/models/History'
6
+ import { patchHistoryPlugin } from '../src/plugin'
7
+ import UserSchema from './schemas/UserSchema'
8
8
 
9
9
  import em from '../src/em'
10
10
 
@@ -1,8 +1,8 @@
1
- import { isMongooseLessThan7 } from '../src/version'
2
1
  import mongoose, { model } from 'mongoose'
2
+ import { isMongooseLessThan7 } from '../src/version'
3
3
 
4
- import UserSchema from './schemas/UserSchema'
5
4
  import { patchHistoryPlugin } from '../src/plugin'
5
+ import UserSchema from './schemas/UserSchema'
6
6
 
7
7
  import { USER_DELETED } from './constants/events'
8
8
 
@@ -1,8 +1,7 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
1
  import mongoose, { model } from 'mongoose'
3
2
 
4
- import UserSchema from './schemas/UserSchema'
5
3
  import { patchHistoryPlugin } from '../src/plugin'
4
+ import UserSchema from './schemas/UserSchema'
6
5
 
7
6
  import { USER_CREATED } from './constants/events'
8
7
 
@@ -2,12 +2,12 @@ import { isMongooseLessThan7 } from '../src/version'
2
2
 
3
3
  import mongoose from 'mongoose'
4
4
 
5
- import UserSchema from './schemas/UserSchema'
6
- import { patchHistoryPlugin } from '../src/plugin'
7
5
  import History from '../src/models/History'
6
+ import { patchHistoryPlugin } from '../src/plugin'
7
+ import UserSchema from './schemas/UserSchema'
8
8
 
9
9
  import em from '../src/em'
10
- import { USER_CREATED, USER_UPDATED, USER_DELETED } from './constants/events'
10
+ import { USER_CREATED, USER_DELETED, USER_UPDATED } from './constants/events'
11
11
 
12
12
  jest.mock('../src/em', () => {
13
13
  return { emit: jest.fn() }
@@ -2,11 +2,14 @@ import { Schema } from 'mongoose'
2
2
 
3
3
  import type IDescription from '../interfaces/IDescription'
4
4
 
5
- const DescriptionSchema = new Schema<IDescription>({
6
- summary: {
7
- type: String,
8
- required: true,
5
+ const DescriptionSchema = new Schema<IDescription>(
6
+ {
7
+ summary: {
8
+ type: String,
9
+ required: true,
10
+ },
9
11
  },
10
- }, { timestamps: false, _id: false })
12
+ { timestamps: false, _id: false },
13
+ )
11
14
 
12
15
  export default DescriptionSchema
@@ -4,25 +4,28 @@ import DescriptionSchema from './DescriptionSchema'
4
4
 
5
5
  import type IProduct from '../interfaces/IProduct'
6
6
 
7
- const ProductSchema = new Schema<IProduct>({
8
- name: {
9
- type: String,
10
- required: true,
7
+ const ProductSchema = new Schema<IProduct>(
8
+ {
9
+ name: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ groups: {
14
+ type: [String],
15
+ required: false,
16
+ default: undefined,
17
+ },
18
+ description: {
19
+ type: DescriptionSchema,
20
+ required: false,
21
+ },
22
+ addedBy: {
23
+ type: Schema.Types.ObjectId,
24
+ required: false,
25
+ ref: 'User',
26
+ },
11
27
  },
12
- groups: {
13
- type: [String],
14
- required: false,
15
- default: undefined,
16
- },
17
- description: {
18
- type: DescriptionSchema,
19
- required: false,
20
- },
21
- addedBy: {
22
- type: Schema.Types.ObjectId,
23
- required: false,
24
- ref: 'User',
25
- },
26
- }, { timestamps: true })
28
+ { timestamps: true },
29
+ )
27
30
 
28
31
  export default ProductSchema
@@ -2,15 +2,18 @@ import { Schema } from 'mongoose'
2
2
 
3
3
  import type IUser from '../interfaces/IUser'
4
4
 
5
- const UserSchema = new Schema<IUser>({
6
- name: {
7
- type: String,
8
- required: true,
5
+ const UserSchema = new Schema<IUser>(
6
+ {
7
+ name: {
8
+ type: String,
9
+ required: true,
10
+ },
11
+ role: {
12
+ type: String,
13
+ required: true,
14
+ },
9
15
  },
10
- role: {
11
- type: String,
12
- required: true,
13
- },
14
- }, { timestamps: true })
16
+ { timestamps: true },
17
+ )
15
18
 
16
19
  export default UserSchema
package/tsconfig.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2021",
4
- "lib": [
5
- "ES2021"
6
- ],
4
+ "lib": ["ES2021"],
7
5
  "module": "CommonJS",
8
6
  "moduleResolution": "Node",
9
7
  "outDir": "dist",
@@ -23,7 +21,6 @@
23
21
  "noFallthroughCasesInSwitch": true,
24
22
  "noImplicitOverride": true,
25
23
  "noImplicitReturns": true,
26
- "noPropertyAccessFromIndexSignature": true,
27
24
  "noUncheckedIndexedAccess": true,
28
25
  "noUnusedLocals": true,
29
26
  "noUnusedParameters": true,
@@ -31,13 +28,6 @@
31
28
  "skipLibCheck": true,
32
29
  "sourceMap": true
33
30
  },
34
- "include": [
35
- "src"
36
- ],
37
- "exclude": [
38
- "tests",
39
- "dist",
40
- "coverage",
41
- "node_modules"
42
- ]
43
- }
31
+ "include": ["src"],
32
+ "exclude": ["tests", "dist", "coverage", "node_modules"]
33
+ }
package/.eslintignore DELETED
@@ -1,4 +0,0 @@
1
- node_modules
2
- dist
3
- coverage
4
- .env