@kikiutils/mongoose 2.1.2 → 2.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
5
5
  "author": "kiki-kanri",
6
6
  "license": "MIT",
@@ -55,14 +55,14 @@
55
55
  "dependencies": {
56
56
  "decimal.js": "^10.4.3",
57
57
  "lodash": "^4.17.21",
58
- "mongoose": "^8.8.4",
58
+ "mongoose": "^8.9.0",
59
59
  "mongoose-aggregate-paginate-v2": "^1.1.2",
60
60
  "mongoose-paginate-v2": "^1.8.5",
61
61
  "type-fest": "^4.30.1"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@kikiutils/changelogen": "^0.7.0",
65
- "@kikiutils/eslint-config": "^0.7.1",
65
+ "@kikiutils/eslint-config": "^0.7.3",
66
66
  "@kikiutils/tsconfigs": "^3.0.2",
67
67
  "@types/jest": "^29.5.14",
68
68
  "@types/lodash": "^4.17.13",
@@ -21,7 +21,7 @@ function decimal128SchemaBuilder() {
21
21
  };
22
22
  }
23
23
  if (key === 'setToStringGetter') {
24
- schema.get = (value) => value.toString();
24
+ schema.get = (value) => value?.toString();
25
25
  return receiver;
26
26
  }
27
27
  return Reflect.get(target, key, receiver);
@@ -8,7 +8,7 @@ interface BaseProps {
8
8
  type: Schema.Types.Decimal128;
9
9
  }
10
10
  interface ToStringGetterSchema {
11
- get: (value: Types.Decimal128) => string;
11
+ get: (value?: Types.Decimal128) => string | undefined;
12
12
  }
13
13
  interface ToStringSetterSchema {
14
14
  set: (value: {
@@ -15,7 +15,7 @@ function decimal128SchemaBuilder() {
15
15
  };
16
16
  }
17
17
  if (key === 'setToStringGetter') {
18
- schema.get = (value) => value.toString();
18
+ schema.get = (value) => value?.toString();
19
19
  return receiver;
20
20
  }
21
21
  return Reflect.get(target, key, receiver);
package/utils.cjs CHANGED
@@ -3,7 +3,6 @@
3
3
  const mongoose = require('mongoose');
4
4
  const mongooseAggregatePaginate = require('mongoose-aggregate-paginate-v2');
5
5
  const mongoosePaginate = require('mongoose-paginate-v2');
6
- const node_process = require('node:process');
7
6
  const _internals = require('./_internals.cjs');
8
7
  const constants = require('./constants.cjs');
9
8
  const normalize = require('./plugins/normalize.cjs');
@@ -48,7 +47,7 @@ function buildMongooseModel(collection, name, schema, options) {
48
47
  schema.plugin(mongoosePaginate__default);
49
48
  schema.set('timestamps', options?.timestamps ?? true);
50
49
  _internals.customMongooseOptions.beforeModelBuild?.(schema);
51
- return (options?.connection || constants.mongooseConnections.default || (constants.mongooseConnections.default = mongoose__default.createConnection(node_process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
50
+ return (options?.connection || constants.mongooseConnections.default || (constants.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
52
51
  }
53
52
  /**
54
53
  * Converts a document or ObjectId to a document using the specified model.
package/utils.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import mongoose, { Types } from 'mongoose';
2
2
  import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
3
3
  import mongoosePaginate from 'mongoose-paginate-v2';
4
- import { env } from 'node:process';
5
4
  import { customMongooseOptions } from './_internals.mjs';
6
5
  import { mongooseConnections } from './constants.mjs';
7
6
  import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
@@ -40,7 +39,7 @@ function buildMongooseModel(collection, name, schema, options) {
40
39
  schema.plugin(mongoosePaginate);
41
40
  schema.set('timestamps', options?.timestamps ?? true);
42
41
  customMongooseOptions.beforeModelBuild?.(schema);
43
- return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
42
+ return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
44
43
  }
45
44
  /**
46
45
  * Converts a document or ObjectId to a document using the specified model.