@kikiutils/mongoose 1.2.0 → 1.2.1
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/README.md +1 -1
- package/package.json +7 -11
- package/utils.cjs +3 -3
- package/utils.mjs +3 -3
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ pnpm add @kikiutils/mongoose
|
|
|
35
35
|
|
|
36
36
|
You can also use yarn, npm, or bun to add the dependency.
|
|
37
37
|
|
|
38
|
-
That's it! You're ready to use this package in your project. Check out the
|
|
38
|
+
That's it! You're ready to use this package in your project. Check out the [usage instructions](#usage) below ✨.
|
|
39
39
|
|
|
40
40
|
# Usage
|
|
41
41
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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
|
"license": "MIT",
|
|
6
6
|
"author": "kiki-kanri",
|
|
@@ -9,27 +9,23 @@
|
|
|
9
9
|
"url": "git+https://github.com/kiki-kanri/kikiutils-node-mongoose.git"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "
|
|
12
|
+
"build": "ts-project-builder ./src/constants.ts ./src/utils.ts --clean --preserve-modules",
|
|
13
13
|
"bumplog": "changelogen --bump"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"decimal.js": "^10.4.3",
|
|
17
17
|
"lodash": "^4.17.21",
|
|
18
|
-
"mongoose": "^8.5.
|
|
19
|
-
"mongoose-aggregate-paginate-v2": "^1.1.
|
|
20
|
-
"mongoose-paginate-v2": "^1.8.
|
|
18
|
+
"mongoose": "^8.5.2",
|
|
19
|
+
"mongoose-aggregate-paginate-v2": "^1.1.2",
|
|
20
|
+
"mongoose-paginate-v2": "^1.8.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@kikiutils/prettierrc": "^1.3.2",
|
|
24
24
|
"@kikiutils/tsconfigs": "^3.0.1",
|
|
25
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
26
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
27
25
|
"@types/lodash": "^4.17.7",
|
|
28
|
-
"@types/node": "^
|
|
26
|
+
"@types/node": "^22.2.0",
|
|
29
27
|
"changelogen": "^0.5.5",
|
|
30
|
-
"
|
|
31
|
-
"rollup-plugin-delete": "^2.0.0",
|
|
32
|
-
"rollup-plugin-node-externals": "^7.1.2"
|
|
28
|
+
"ts-project-builder": "^3.0.1"
|
|
33
29
|
},
|
|
34
30
|
"keywords": [
|
|
35
31
|
"Decimal128",
|
package/utils.cjs
CHANGED
|
@@ -47,7 +47,7 @@ function buildMongooseModel(collection, name, schema, options) {
|
|
|
47
47
|
schema.plugin(mongooseAggregatePaginate__default);
|
|
48
48
|
schema.plugin(mongoosePaginate__default);
|
|
49
49
|
schema.set('timestamps', options?.timestamps === undefined ? true : options.timestamps);
|
|
50
|
-
return (options?.connection || _connections.mongooseConnections.default || (_connections.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://
|
|
50
|
+
return (options?.connection || _connections.mongooseConnections.default || (_connections.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Creates common Mongoose schema definitions with optional custom schemas and settings.
|
|
@@ -64,8 +64,8 @@ function buildMongooseModel(collection, name, schema, options) {
|
|
|
64
64
|
* @returns The merged common and custom schemas.
|
|
65
65
|
*/
|
|
66
66
|
function createCommonMongooseSchemas(customSchemas, options) {
|
|
67
|
-
const autoRoundAndToFixedDecimal128Places = options?.autoRoundAndToFixedDecimal128?.places
|
|
68
|
-
const autoRoundAndToFixedDecimal128Rounding = options?.autoRoundAndToFixedDecimal128?.rounding
|
|
67
|
+
const autoRoundAndToFixedDecimal128Places = options?.autoRoundAndToFixedDecimal128?.places ?? 2;
|
|
68
|
+
const autoRoundAndToFixedDecimal128Rounding = options?.autoRoundAndToFixedDecimal128?.rounding ?? Decimal__default.ROUND_DOWN;
|
|
69
69
|
const baseAutoRoundAndToFixedDecimal128 = {
|
|
70
70
|
set: (value) => new Decimal__default(value.toString()).toFixed(autoRoundAndToFixedDecimal128Places, autoRoundAndToFixedDecimal128Rounding),
|
|
71
71
|
type: mongoose__default.Schema.Types.Decimal128
|
package/utils.mjs
CHANGED
|
@@ -37,7 +37,7 @@ function buildMongooseModel(collection, name, schema, options) {
|
|
|
37
37
|
schema.plugin(mongooseAggregatePaginate);
|
|
38
38
|
schema.plugin(mongoosePaginate);
|
|
39
39
|
schema.set('timestamps', options?.timestamps === undefined ? true : options.timestamps);
|
|
40
|
-
return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://
|
|
40
|
+
return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Creates common Mongoose schema definitions with optional custom schemas and settings.
|
|
@@ -54,8 +54,8 @@ function buildMongooseModel(collection, name, schema, options) {
|
|
|
54
54
|
* @returns The merged common and custom schemas.
|
|
55
55
|
*/
|
|
56
56
|
function createCommonMongooseSchemas(customSchemas, options) {
|
|
57
|
-
const autoRoundAndToFixedDecimal128Places = options?.autoRoundAndToFixedDecimal128?.places
|
|
58
|
-
const autoRoundAndToFixedDecimal128Rounding = options?.autoRoundAndToFixedDecimal128?.rounding
|
|
57
|
+
const autoRoundAndToFixedDecimal128Places = options?.autoRoundAndToFixedDecimal128?.places ?? 2;
|
|
58
|
+
const autoRoundAndToFixedDecimal128Rounding = options?.autoRoundAndToFixedDecimal128?.rounding ?? Decimal.ROUND_DOWN;
|
|
59
59
|
const baseAutoRoundAndToFixedDecimal128 = {
|
|
60
60
|
set: (value) => new Decimal(value.toString()).toFixed(autoRoundAndToFixedDecimal128Places, autoRoundAndToFixedDecimal128Rounding),
|
|
61
61
|
type: mongoose.Schema.Types.Decimal128
|