ts-patch-mongoose 2.9.0 → 2.9.2

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.
package/biome.json CHANGED
@@ -1,16 +1,36 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.2.0/schema.json",
3
3
  "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4
4
  "files": {
5
5
  "ignoreUnknown": false,
6
- "ignore": ["node_modules", "dist", "coverage"]
6
+ "includes": ["src/**/*.ts", "tests/**/*.ts"]
7
7
  },
8
8
  "formatter": { "enabled": true, "indentStyle": "space", "indentWidth": 2 },
9
- "organizeImports": { "enabled": true },
9
+ "assist": {
10
+ "actions": {
11
+ "source": {
12
+ "organizeImports": {
13
+ "level": "on",
14
+ "options": {
15
+ "groups": [
16
+ "vitest",
17
+ ":BLANK_LINE:",
18
+ ":NODE:",
19
+ { "type": false },
20
+ ":BLANK_LINE:"
21
+ ]
22
+ }
23
+ }
24
+ }
25
+ }
26
+ },
10
27
  "linter": {
11
28
  "enabled": true,
12
29
  "rules": {
13
- "recommended": true
30
+ "recommended": true,
31
+ "correctness": {
32
+ "noUnusedVariables": "off"
33
+ }
14
34
  }
15
35
  },
16
36
  "javascript": {
package/dist/index.cjs CHANGED
@@ -6,8 +6,8 @@ var ms = require('ms');
6
6
  var mongoose = require('mongoose');
7
7
  var jsonpatch = require('fast-json-patch');
8
8
  var omit = require('omit-deep');
9
- var semver = require('semver');
10
9
  var powerAssign = require('power-assign');
10
+ var semver = require('semver');
11
11
 
12
12
  class PatchEventEmitter extends EventEmitter {
13
13
  }
@@ -211,13 +211,6 @@ async function deletePatch(opts, context) {
211
211
  await bulkPatch(opts, context, "eventDeleted", "deletedDocs");
212
212
  }
213
213
 
214
- const isMongooseLessThan8 = semver.satisfies(mongoose.version, "<8");
215
- const isMongooseLessThan7 = semver.satisfies(mongoose.version, "<7");
216
- const isMongoose6 = semver.satisfies(mongoose.version, "6");
217
- if (isMongoose6) {
218
- mongoose.set("strictQuery", false);
219
- }
220
-
221
214
  const deleteMethods = ["remove", "findOneAndDelete", "findOneAndRemove", "findByIdAndDelete", "findByIdAndRemove", "deleteOne", "deleteMany"];
222
215
  const deleteHooksInitialize = (schema, opts) => {
223
216
  schema.pre(deleteMethods, { document: false, query: true }, async function() {
@@ -354,6 +347,13 @@ const updateHooksInitialize = (schema, opts) => {
354
347
  });
355
348
  };
356
349
 
350
+ const isMongooseLessThan8 = semver.satisfies(mongoose.version, "<8");
351
+ const isMongooseLessThan7 = semver.satisfies(mongoose.version, "<7");
352
+ const isMongoose6 = semver.satisfies(mongoose.version, "6");
353
+ if (isMongoose6) {
354
+ mongoose.set("strictQuery", false);
355
+ }
356
+
357
357
  const remove = isMongooseLessThan7 ? "remove" : "deleteOne";
358
358
  const patchEventEmitter = em;
359
359
  const patchHistoryPlugin = function plugin(schema, opts) {
package/dist/index.d.cts CHANGED
@@ -72,4 +72,5 @@ declare const patchEventEmitter: {
72
72
 
73
73
  declare const patchHistoryPlugin: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
74
74
 
75
- export { type History, type HookContext, type Metadata, type PatchContext, type PatchEvent, type PluginOptions, type User, patchEventEmitter, patchHistoryPlugin, setPatchHistoryTTL };
75
+ export { patchEventEmitter, patchHistoryPlugin, setPatchHistoryTTL };
76
+ export type { History, HookContext, Metadata, PatchContext, PatchEvent, PluginOptions, User };
package/dist/index.d.mts CHANGED
@@ -72,4 +72,5 @@ declare const patchEventEmitter: {
72
72
 
73
73
  declare const patchHistoryPlugin: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
74
74
 
75
- export { type History, type HookContext, type Metadata, type PatchContext, type PatchEvent, type PluginOptions, type User, patchEventEmitter, patchHistoryPlugin, setPatchHistoryTTL };
75
+ export { patchEventEmitter, patchHistoryPlugin, setPatchHistoryTTL };
76
+ export type { History, HookContext, Metadata, PatchContext, PatchEvent, PluginOptions, User };
package/dist/index.mjs CHANGED
@@ -4,8 +4,8 @@ import ms from 'ms';
4
4
  import mongoose, { Schema, model } from 'mongoose';
5
5
  import jsonpatch from 'fast-json-patch';
6
6
  import omit from 'omit-deep';
7
- import { satisfies } from 'semver';
8
7
  import { assign } from 'power-assign';
8
+ import { satisfies } from 'semver';
9
9
 
10
10
  class PatchEventEmitter extends EventEmitter {
11
11
  }
@@ -209,13 +209,6 @@ async function deletePatch(opts, context) {
209
209
  await bulkPatch(opts, context, "eventDeleted", "deletedDocs");
210
210
  }
211
211
 
212
- const isMongooseLessThan8 = satisfies(mongoose.version, "<8");
213
- const isMongooseLessThan7 = satisfies(mongoose.version, "<7");
214
- const isMongoose6 = satisfies(mongoose.version, "6");
215
- if (isMongoose6) {
216
- mongoose.set("strictQuery", false);
217
- }
218
-
219
212
  const deleteMethods = ["remove", "findOneAndDelete", "findOneAndRemove", "findByIdAndDelete", "findByIdAndRemove", "deleteOne", "deleteMany"];
220
213
  const deleteHooksInitialize = (schema, opts) => {
221
214
  schema.pre(deleteMethods, { document: false, query: true }, async function() {
@@ -352,6 +345,13 @@ const updateHooksInitialize = (schema, opts) => {
352
345
  });
353
346
  };
354
347
 
348
+ const isMongooseLessThan8 = satisfies(mongoose.version, "<8");
349
+ const isMongooseLessThan7 = satisfies(mongoose.version, "<7");
350
+ const isMongoose6 = satisfies(mongoose.version, "6");
351
+ if (isMongoose6) {
352
+ mongoose.set("strictQuery", false);
353
+ }
354
+
355
355
  const remove = isMongooseLessThan7 ? "remove" : "deleteOne";
356
356
  const patchEventEmitter = em;
357
357
  const patchHistoryPlugin = function plugin(schema, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-patch-mongoose",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "Patch history & events for mongoose models",
5
5
  "author": "ilovepixelart",
6
6
  "license": "MIT",
@@ -71,7 +71,7 @@
71
71
  "release": "npm install && npm run biome && npm run type:check && npm run build && np"
72
72
  },
73
73
  "dependencies": {
74
- "@types/lodash": "4.17.16",
74
+ "@types/lodash": "4.17.20",
75
75
  "@types/ms": "2.1.0",
76
76
  "@types/semver": "7.7.0",
77
77
  "fast-json-patch": "3.1.1",
@@ -79,19 +79,19 @@
79
79
  "ms": "2.1.3",
80
80
  "omit-deep": "0.3.0",
81
81
  "power-assign": "0.2.10",
82
- "semver": "7.7.1"
82
+ "semver": "7.7.2"
83
83
  },
84
84
  "devDependencies": {
85
- "@biomejs/biome": "1.9.4",
86
- "@types/node": "22.14.1",
87
- "@vitest/coverage-v8": "3.1.1",
88
- "mongodb-memory-server": "10.1.4",
89
- "mongoose": "8.13.2",
85
+ "@biomejs/biome": "2.2.0",
86
+ "@types/node": "24.3.0",
87
+ "@vitest/coverage-v8": "3.2.4",
88
+ "mongodb-memory-server": "10.2.0",
89
+ "mongoose": "8.17.1",
90
90
  "open-cli": "8.0.0",
91
- "pkgroll": "2.12.1",
92
- "simple-git-hooks": "2.12.1",
93
- "typescript": "5.8.3",
94
- "vitest": "3.1.1"
91
+ "pkgroll": "2.15.3",
92
+ "simple-git-hooks": "2.13.1",
93
+ "typescript": "5.9.2",
94
+ "vitest": "3.2.4"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "mongoose": ">=6.6.0 < 9"
package/src/helpers.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import ms from 'ms'
2
-
3
2
  import { HistoryModel } from './model'
4
3
 
5
4
  import type { QueryOptions, ToObjectOptions } from 'mongoose'
@@ -1,5 +1,4 @@
1
1
  import _ from 'lodash'
2
-
3
2
  import { isHookIgnored } from '../helpers'
4
3
  import { deletePatch } from '../patch'
5
4
 
@@ -1,6 +1,5 @@
1
1
  import _ from 'lodash'
2
2
  import { assign } from 'power-assign'
3
-
4
3
  import { isHookIgnored, toObjectOptions } from '../helpers'
5
4
  import { createPatch, updatePatch } from '../patch'
6
5
 
package/src/index.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  import _ from 'lodash'
2
2
  import em from './em'
3
-
4
3
  import { toObjectOptions } from './helpers'
5
- import { createPatch, deletePatch } from './patch'
6
- import { isMongooseLessThan7, isMongooseLessThan8 } from './version'
7
-
8
4
  import { deleteHooksInitialize } from './hooks/delete-hooks'
9
5
  import { saveHooksInitialize } from './hooks/save-hooks'
10
6
  import { updateHooksInitialize } from './hooks/update-hooks'
7
+ import { createPatch, deletePatch } from './patch'
8
+ import { isMongooseLessThan7, isMongooseLessThan8 } from './version'
11
9
 
12
10
  import type { HydratedDocument, Model, Schema } from 'mongoose'
13
11
  import type { PatchContext, PluginOptions } from './types'
@@ -20,7 +18,6 @@ const remove = isMongooseLessThan7 ? 'remove' : 'deleteOne'
20
18
  export const patchEventEmitter = em
21
19
 
22
20
  export { setPatchHistoryTTL } from './helpers'
23
-
24
21
  export * from './types'
25
22
 
26
23
  /**
package/src/model.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Schema, model } from 'mongoose'
1
+ import { model, Schema } from 'mongoose'
2
2
 
3
3
  import type { History } from './types'
4
4
 
package/src/patch.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import jsonpatch from 'fast-json-patch'
2
2
  import _ from 'lodash'
3
3
  import omit from 'omit-deep'
4
+ import em from './em'
5
+ import { HistoryModel } from './model'
4
6
 
5
7
  import type { HydratedDocument, MongooseError, Types } from 'mongoose'
6
8
  import type { Metadata, PatchContext, PatchEvent, PluginOptions, User } from './types'
7
9
 
8
- import em from './em'
9
- import { HistoryModel } from './model'
10
-
11
10
  function isPatchHistoryEnabled<T>(opts: PluginOptions<T>, context: PatchContext<T>): boolean {
12
11
  return !opts.patchHistoryDisabled && !context.ignorePatchHistory
13
12
  }
@@ -1,11 +1,10 @@
1
- import ms from 'ms'
1
+ import type { Mock, MockInstance } from 'vitest'
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3
3
 
4
+ import ms from 'ms'
4
5
  import { setPatchHistoryTTL } from '../src/helpers'
5
6
  import { HistoryModel } from '../src/model'
6
7
 
7
- import type { Mock, MockInstance } from 'vitest'
8
-
9
8
  vi.mock('../src/model', () => ({
10
9
  HistoryModel: {
11
10
  collection: {
@@ -1,7 +1,6 @@
1
1
  import fs from 'node:fs'
2
- import mongoose from 'mongoose'
3
-
4
2
  import { MongoMemoryServer } from 'mongodb-memory-server'
3
+ import mongoose from 'mongoose'
5
4
 
6
5
  const server = (dbName: string) => {
7
6
  let mongo: MongoMemoryServer
@@ -1,19 +1,16 @@
1
1
  import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
2
2
 
3
+ import { afterEach } from 'node:test'
3
4
  import mongoose from 'mongoose'
4
-
5
+ import em from '../src/em'
5
6
  import { patchHistoryPlugin } from '../src/index'
6
7
  import { bulkPatch, getData, getJsonOmit, getMetadata, getReason, getUser, getValue, updatePatch } from '../src/patch'
7
-
8
8
  import { USER_DELETED } from './constants/events'
9
+ import server from './mongo/server'
9
10
  import { type User, UserSchema } from './schemas/User'
10
11
 
11
12
  import type { HydratedDocument } from 'mongoose'
12
-
13
- import { afterEach } from 'node:test'
14
- import em from '../src/em'
15
13
  import type { PatchContext, PluginOptions } from '../src/types'
16
- import server from './mongo/server'
17
14
 
18
15
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
19
16
 
@@ -1,14 +1,12 @@
1
- import mongoose, { Types, model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model, Types } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { patchHistoryPlugin } from '../src/index'
6
+ import { HistoryModel } from '../src/model'
5
7
  import { isMongooseLessThan7 } from '../src/version'
6
-
7
- import em from '../src/em'
8
8
  import { USER_CREATED } from './constants/events'
9
9
  import server from './mongo/server'
10
-
11
- import { HistoryModel } from '../src/model'
12
10
  import { type User, UserSchema } from './schemas/User'
13
11
 
14
12
  vi.mock('../src/em', () => ({ default: { emit: vi.fn((event: string, data: Record<string, unknown>) => console.log(event, data)) } }))
@@ -1,15 +1,13 @@
1
- import mongoose, { model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { toObjectOptions } from '../src/helpers'
5
6
  import { patchHistoryPlugin } from '../src/index'
6
7
  import { HistoryModel } from '../src/model'
7
8
  import { isMongooseLessThan7 } from '../src/version'
8
-
9
- import em from '../src/em'
10
9
  import { USER_DELETED } from './constants/events'
11
10
  import server from './mongo/server'
12
-
13
11
  import { type User, UserSchema } from './schemas/User'
14
12
 
15
13
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
@@ -1,14 +1,12 @@
1
- import mongoose, { Types, model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model, Types } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { patchHistoryPlugin } from '../src/index'
6
+ import { HistoryModel } from '../src/model'
5
7
  import { isMongooseLessThan7 } from '../src/version'
6
-
7
- import em from '../src/em'
8
8
  import { USER_UPDATED } from './constants/events'
9
9
  import server from './mongo/server'
10
-
11
- import { HistoryModel } from '../src/model'
12
10
  import { type User, UserSchema } from './schemas/User'
13
11
 
14
12
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
@@ -1,13 +1,11 @@
1
- import mongoose, { model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
4
- import { patchHistoryPlugin } from '../src/index'
5
-
3
+ import mongoose, { model } from 'mongoose'
6
4
  import em from '../src/em'
5
+ import { patchHistoryPlugin } from '../src/index'
6
+ import { HistoryModel } from '../src/model'
7
7
  import { GLOBAL_CREATED, GLOBAL_DELETED, GLOBAL_UPDATED } from './constants/events'
8
8
  import server from './mongo/server'
9
-
10
- import { HistoryModel } from '../src/model'
11
9
  import { type Product, ProductSchema } from './schemas/Product'
12
10
  import { type User, UserSchema } from './schemas/User'
13
11
 
@@ -1,13 +1,11 @@
1
- import mongoose, { Types, model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model, Types } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { patchHistoryPlugin } from '../src/index'
6
+ import { HistoryModel } from '../src/model'
5
7
  import { isMongooseLessThan7 } from '../src/version'
6
-
7
- import em from '../src/em'
8
8
  import server from './mongo/server'
9
-
10
- import { HistoryModel } from '../src/model'
11
9
  import { type User, UserSchema } from './schemas/User'
12
10
 
13
11
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
@@ -1,13 +1,11 @@
1
- import mongoose, { model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { patchHistoryPlugin } from '../src/index'
6
+ import { HistoryModel } from '../src/model'
5
7
  import { isMongooseLessThan7 } from '../src/version'
6
-
7
- import em from '../src/em'
8
8
  import server from './mongo/server'
9
-
10
- import { HistoryModel } from '../src/model'
11
9
  import { type User, UserSchema } from './schemas/User'
12
10
 
13
11
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
@@ -1,13 +1,11 @@
1
- import mongoose, { model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { patchHistoryPlugin } from '../src/index'
5
6
  import { isMongooseLessThan7 } from '../src/version'
6
-
7
- import em from '../src/em'
8
7
  import { USER_DELETED } from './constants/events'
9
8
  import server from './mongo/server'
10
-
11
9
  import { type User, UserSchema } from './schemas/User'
12
10
 
13
11
  const preDeleteMock = vi.fn()
@@ -1,12 +1,10 @@
1
- import mongoose, { model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
4
- import { patchHistoryPlugin } from '../src/index'
5
-
3
+ import mongoose, { model } from 'mongoose'
6
4
  import em from '../src/em'
5
+ import { patchHistoryPlugin } from '../src/index'
7
6
  import { USER_CREATED } from './constants/events'
8
7
  import server from './mongo/server'
9
-
10
8
  import { type User, UserSchema } from './schemas/User'
11
9
 
12
10
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
@@ -40,7 +38,6 @@ describe('plugin - preSave test', () => {
40
38
 
41
39
  it('should create a User and execute save, and omit User role in history', async () => {
42
40
  const john = await UserModel.create({ name: 'John', role: 'user' })
43
- // @ts-expect-error __v is a hidden field in Mongoose model
44
41
  const { __v, role, ...doc } = john.toJSON()
45
42
 
46
43
  expect(em.emit).toHaveBeenCalledTimes(1)
@@ -1,14 +1,12 @@
1
- import mongoose, { model } from 'mongoose'
2
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
3
2
 
3
+ import mongoose, { model } from 'mongoose'
4
+ import em from '../src/em'
4
5
  import { patchHistoryPlugin } from '../src/index'
6
+ import { HistoryModel } from '../src/model'
5
7
  import { isMongooseLessThan7 } from '../src/version'
6
-
7
- import em from '../src/em'
8
8
  import { USER_CREATED, USER_DELETED, USER_UPDATED } from './constants/events'
9
9
  import server from './mongo/server'
10
-
11
- import { HistoryModel } from '../src/model'
12
10
  import { type User, UserSchema } from './schemas/User'
13
11
 
14
12
  vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))