ts-patch-mongoose 2.9.3 → 2.9.5

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,5 +1,5 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.2.7/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.3.1/schema.json",
3
3
  "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4
4
  "files": {
5
5
  "ignoreUnknown": false,
package/dist/index.cjs CHANGED
@@ -1,11 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var lodashEs = require('lodash-es');
3
+ var isEmpty = require('lodash/isEmpty.js');
4
4
  var ms = require('ms');
5
5
  var mongoose = require('mongoose');
6
+ var isArray = require('lodash/isArray.js');
6
7
  var jsonpatch = require('fast-json-patch');
8
+ var chunk = require('lodash/chunk.js');
9
+ var isFunction = require('lodash/isFunction.js');
7
10
  var omit = require('omit-deep');
8
11
  var EventEmitter = require('node:events');
12
+ var cloneDeep = require('lodash/cloneDeep.js');
13
+ var forEach = require('lodash/forEach.js');
14
+ var isObjectLike = require('lodash/isObjectLike.js');
15
+ var keys = require('lodash/keys.js');
9
16
  var powerAssign = require('power-assign');
10
17
  var semver = require('semver');
11
18
 
@@ -104,24 +111,24 @@ function getJsonOmit(opts, doc) {
104
111
  }
105
112
  function getObjectOmit(opts, doc) {
106
113
  if (opts.omit) {
107
- return omit(lodashEs.isFunction(doc?.toObject) ? doc.toObject() : doc, opts.omit);
114
+ return omit(isFunction(doc?.toObject) ? doc.toObject() : doc, opts.omit);
108
115
  }
109
116
  return doc;
110
117
  }
111
118
  async function getUser(opts, doc) {
112
- if (lodashEs.isFunction(opts.getUser)) {
119
+ if (isFunction(opts.getUser)) {
113
120
  return await opts.getUser(doc);
114
121
  }
115
122
  return void 0;
116
123
  }
117
124
  async function getReason(opts, doc) {
118
- if (lodashEs.isFunction(opts.getReason)) {
125
+ if (isFunction(opts.getReason)) {
119
126
  return await opts.getReason(doc);
120
127
  }
121
128
  return void 0;
122
129
  }
123
130
  async function getMetadata(opts, doc) {
124
- if (lodashEs.isFunction(opts.getMetadata)) {
131
+ if (isFunction(opts.getMetadata)) {
125
132
  return await opts.getMetadata(doc);
126
133
  }
127
134
  return void 0;
@@ -144,8 +151,8 @@ async function bulkPatch(opts, context, eventKey, docsKey) {
144
151
  const event = opts[eventKey];
145
152
  const docs = context[docsKey];
146
153
  const key = eventKey === "eventCreated" ? "doc" : "oldDoc";
147
- if (lodashEs.isEmpty(docs) || !event && !history) return;
148
- const chunks = lodashEs.chunk(docs, 1e3);
154
+ if (isEmpty(docs) || !event && !history) return;
155
+ const chunks = chunk(docs, 1e3);
149
156
  for (const chunk2 of chunks) {
150
157
  const bulk = [];
151
158
  for (const doc of chunk2) {
@@ -169,7 +176,7 @@ async function bulkPatch(opts, context, eventKey, docsKey) {
169
176
  });
170
177
  }
171
178
  }
172
- if (history && !lodashEs.isEmpty(bulk)) {
179
+ if (history && !isEmpty(bulk)) {
173
180
  await HistoryModel.bulkWrite(bulk, { ordered: false }).catch((error) => {
174
181
  console.error(error.message);
175
182
  });
@@ -183,9 +190,9 @@ async function updatePatch(opts, context, current, original) {
183
190
  const history = isPatchHistoryEnabled(opts, context);
184
191
  const currentObject = getJsonOmit(opts, current);
185
192
  const originalObject = getJsonOmit(opts, original);
186
- if (lodashEs.isEmpty(originalObject) || lodashEs.isEmpty(currentObject)) return;
193
+ if (isEmpty(originalObject) || isEmpty(currentObject)) return;
187
194
  const patch = jsonpatch.compare(originalObject, currentObject, true);
188
- if (lodashEs.isEmpty(patch)) return;
195
+ if (isEmpty(patch)) return;
189
196
  emitEvent(context, opts.eventUpdated, { oldDoc: original, doc: current, patch });
190
197
  if (history) {
191
198
  let version = 0;
@@ -227,16 +234,16 @@ const deleteHooksInitialize = (schema, opts) => {
227
234
  };
228
235
  if (["remove", "deleteMany"].includes(this._context.op) && !options.single) {
229
236
  const docs = await model.find(filter).lean().exec();
230
- if (!lodashEs.isEmpty(docs)) {
237
+ if (!isEmpty(docs)) {
231
238
  this._context.deletedDocs = docs;
232
239
  }
233
240
  } else {
234
241
  const doc = await model.findOne(filter).lean().exec();
235
- if (!lodashEs.isEmpty(doc)) {
242
+ if (!isEmpty(doc)) {
236
243
  this._context.deletedDocs = [doc];
237
244
  }
238
245
  }
239
- if (opts.preDelete && lodashEs.isArray(this._context.deletedDocs) && !lodashEs.isEmpty(this._context.deletedDocs)) {
246
+ if (opts.preDelete && isArray(this._context.deletedDocs) && !isEmpty(this._context.deletedDocs)) {
240
247
  await opts.preDelete(this._context.deletedDocs);
241
248
  }
242
249
  });
@@ -272,7 +279,7 @@ const saveHooksInitialize = (schema, opts) => {
272
279
  const updateMethods = ["update", "updateOne", "replaceOne", "updateMany", "findOneAndUpdate", "findOneAndReplace", "findByIdAndUpdate"];
273
280
  const assignUpdate = (document, update, commands) => {
274
281
  let updated = powerAssign.assign(document.toObject(toObjectOptions), update);
275
- lodashEs.forEach(commands, (command) => {
282
+ forEach(commands, (command) => {
276
283
  try {
277
284
  updated = powerAssign.assign(updated, command);
278
285
  } catch {
@@ -285,11 +292,11 @@ const assignUpdate = (document, update, commands) => {
285
292
  const splitUpdateAndCommands = (updateQuery) => {
286
293
  let update = {};
287
294
  const commands = [];
288
- if (!lodashEs.isEmpty(updateQuery) && !lodashEs.isArray(updateQuery) && lodashEs.isObjectLike(updateQuery)) {
289
- update = lodashEs.cloneDeep(updateQuery);
290
- const keysWithDollarSign = lodashEs.keys(update).filter((key) => key.startsWith("$"));
291
- if (!lodashEs.isEmpty(keysWithDollarSign)) {
292
- lodashEs.forEach(keysWithDollarSign, (key) => {
295
+ if (!isEmpty(updateQuery) && !isArray(updateQuery) && isObjectLike(updateQuery)) {
296
+ update = cloneDeep(updateQuery);
297
+ const keysWithDollarSign = keys(update).filter((key) => key.startsWith("$"));
298
+ if (!isEmpty(keysWithDollarSign)) {
299
+ forEach(keysWithDollarSign, (key) => {
293
300
  commands.push({ [key]: update[key] });
294
301
  delete update[key];
295
302
  });
@@ -330,13 +337,13 @@ const updateHooksInitialize = (schema, opts) => {
330
337
  let current = null;
331
338
  const filter = this.getFilter();
332
339
  const combined = assignUpdate(model.hydrate({}), update, commands);
333
- if (!lodashEs.isEmpty(update) && !current) {
340
+ if (!isEmpty(update) && !current) {
334
341
  current = await model.findOne(update).sort("desc").lean().exec();
335
342
  }
336
- if (!lodashEs.isEmpty(combined) && !current) {
343
+ if (!isEmpty(combined) && !current) {
337
344
  current = await model.findOne(combined).sort("desc").lean().exec();
338
345
  }
339
- if (!lodashEs.isEmpty(filter) && !current) {
346
+ if (!isEmpty(filter) && !current) {
340
347
  console.log("filter", filter);
341
348
  current = await model.findOne(filter).sort("desc").lean().exec();
342
349
  }
@@ -371,7 +378,7 @@ const patchHistoryPlugin = function plugin(schema, opts) {
371
378
  if (isMongooseLessThan8) {
372
379
  schema.pre(remove, { document: true, query: false }, async function() {
373
380
  const original = this.toObject(toObjectOptions);
374
- if (opts.preDelete && !lodashEs.isEmpty(original)) {
381
+ if (opts.preDelete && !isEmpty(original)) {
375
382
  await opts.preDelete([original]);
376
383
  }
377
384
  });
package/dist/index.mjs CHANGED
@@ -1,9 +1,16 @@
1
- import { isEmpty, chunk, isFunction, isArray, isObjectLike, cloneDeep, keys, forEach } from 'lodash-es';
1
+ import isEmpty from 'lodash/isEmpty.js';
2
2
  import ms from 'ms';
3
3
  import mongoose, { Schema, model } from 'mongoose';
4
+ import isArray from 'lodash/isArray.js';
4
5
  import jsonpatch from 'fast-json-patch';
6
+ import chunk from 'lodash/chunk.js';
7
+ import isFunction from 'lodash/isFunction.js';
5
8
  import omit from 'omit-deep';
6
9
  import EventEmitter from 'node:events';
10
+ import cloneDeep from 'lodash/cloneDeep.js';
11
+ import forEach from 'lodash/forEach.js';
12
+ import isObjectLike from 'lodash/isObjectLike.js';
13
+ import keys from 'lodash/keys.js';
7
14
  import { assign } from 'power-assign';
8
15
  import { satisfies } from 'semver';
9
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-patch-mongoose",
3
- "version": "2.9.3",
3
+ "version": "2.9.5",
4
4
  "description": "Patch history & events for mongoose models",
5
5
  "author": "ilovepixelart",
6
6
  "license": "MIT",
@@ -71,27 +71,27 @@
71
71
  "release": "npm install && npm run biome && npm run type:check && npm run build && np"
72
72
  },
73
73
  "dependencies": {
74
- "@types/lodash-es": "4.17.12",
74
+ "@types/lodash": "4.17.20",
75
75
  "@types/ms": "2.1.0",
76
76
  "@types/semver": "7.7.1",
77
77
  "fast-json-patch": "3.1.1",
78
- "lodash-es": "4.17.21",
78
+ "lodash": "4.17.21",
79
79
  "ms": "2.1.3",
80
80
  "omit-deep": "0.3.0",
81
81
  "power-assign": "0.2.10",
82
82
  "semver": "7.7.3"
83
83
  },
84
84
  "devDependencies": {
85
- "@biomejs/biome": "2.2.7",
85
+ "@biomejs/biome": "2.3.1",
86
86
  "@types/node": "24.9.1",
87
- "@vitest/coverage-v8": "4.0.2",
87
+ "@vitest/coverage-v8": "4.0.4",
88
88
  "mongodb-memory-server": "10.2.3",
89
89
  "mongoose": "8.19.2",
90
90
  "open-cli": "8.0.0",
91
91
  "pkgroll": "2.20.1",
92
92
  "simple-git-hooks": "2.13.1",
93
93
  "typescript": "5.9.3",
94
- "vitest": "4.0.2"
94
+ "vitest": "4.0.4"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "mongoose": ">=6.6.0 < 9"
@@ -1,4 +1,6 @@
1
- import { isArray, isEmpty } from 'lodash-es'
1
+ // Using CJS lodash with .js extensions for ESM compatibility
2
+ import isArray from 'lodash/isArray.js'
3
+ import isEmpty from 'lodash/isEmpty.js'
2
4
  import { isHookIgnored } from '../helpers'
3
5
  import { deletePatch } from '../patch'
4
6
 
@@ -1,4 +1,10 @@
1
- import { cloneDeep, forEach, isArray, isEmpty, isObjectLike, keys } from 'lodash-es'
1
+ // Using CJS lodash with .js extensions for ESM compatibility
2
+ import cloneDeep from 'lodash/cloneDeep.js'
3
+ import forEach from 'lodash/forEach.js'
4
+ import isArray from 'lodash/isArray.js'
5
+ import isEmpty from 'lodash/isEmpty.js'
6
+ import isObjectLike from 'lodash/isObjectLike.js'
7
+ import keys from 'lodash/keys.js'
2
8
  import { assign } from 'power-assign'
3
9
  import { isHookIgnored, toObjectOptions } from '../helpers'
4
10
  import { createPatch, updatePatch } from '../patch'
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { isEmpty } from 'lodash-es'
1
+ // Using CJS lodash with .js extension for ESM compatibility
2
+ import isEmpty from 'lodash/isEmpty.js'
2
3
  import { toObjectOptions } from './helpers'
3
4
  import { deleteHooksInitialize } from './hooks/delete-hooks'
4
5
  import { saveHooksInitialize } from './hooks/save-hooks'
package/src/patch.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import jsonpatch from 'fast-json-patch'
2
- import { chunk, isEmpty, isFunction } from 'lodash-es'
2
+ // Using CJS lodash with .js extensions for ESM compatibility
3
+ import chunk from 'lodash/chunk.js'
4
+ import isEmpty from 'lodash/isEmpty.js'
5
+ import isFunction from 'lodash/isFunction.js'
3
6
  import omit from 'omit-deep'
4
7
  import em from './em'
5
8
  import { HistoryModel } from './model'