@kikiutils/mongoose 1.1.0 → 1.2.0

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.
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mongoose connections.
5
+ *
6
+ * This constant is a record of named Mongoose connections, allowing multiple
7
+ * database connections to be managed within the application. An optional `default`
8
+ * connection can also be specified for use when a specific connection is not provided.
9
+ */
10
+ const mongooseConnections = {};
11
+
12
+ exports.mongooseConnections = mongooseConnections;
@@ -0,0 +1,9 @@
1
+ import type { MongooseConnections } from './types';
2
+ /**
3
+ * Mongoose connections.
4
+ *
5
+ * This constant is a record of named Mongoose connections, allowing multiple
6
+ * database connections to be managed within the application. An optional `default`
7
+ * connection can also be specified for use when a specific connection is not provided.
8
+ */
9
+ export declare const mongooseConnections: MongooseConnections;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Mongoose connections.
3
+ *
4
+ * This constant is a record of named Mongoose connections, allowing multiple
5
+ * database connections to be managed within the application. An optional `default`
6
+ * connection can also be specified for use when a specific connection is not provided.
7
+ */
8
+ const mongooseConnections = {};
9
+
10
+ export { mongooseConnections };
package/constants.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const utils = require('./utils.cjs');
4
+ const _connections = require('./_connections.cjs');
4
5
 
5
6
  /**
6
7
  * Common Mongoose schemas.
@@ -10,14 +11,6 @@ const utils = require('./utils.cjs');
10
11
  * field types and configurations used across multiple models.
11
12
  */
12
13
  const commonMongooseSchemas = utils.createCommonMongooseSchemas();
13
- /**
14
- * Mongoose connections.
15
- *
16
- * This constant is a record of named Mongoose connections, allowing multiple
17
- * database connections to be managed within the application. An optional `default`
18
- * connection can also be specified for use when a specific connection is not provided.
19
- */
20
- const mongooseConnections = {};
21
14
 
15
+ exports.mongooseConnections = _connections.mongooseConnections;
22
16
  exports.commonMongooseSchemas = commonMongooseSchemas;
23
- exports.mongooseConnections = mongooseConnections;
package/constants.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Connection } from 'mongoose';
1
+ export { mongooseConnections } from './_connections';
2
2
  /**
3
3
  * Common Mongoose schemas.
4
4
  *
@@ -167,13 +167,3 @@ export declare const commonMongooseSchemas: {
167
167
  };
168
168
  };
169
169
  };
170
- /**
171
- * Mongoose connections.
172
- *
173
- * This constant is a record of named Mongoose connections, allowing multiple
174
- * database connections to be managed within the application. An optional `default`
175
- * connection can also be specified for use when a specific connection is not provided.
176
- */
177
- export declare const mongooseConnections: Record<string, Connection> & {
178
- default?: Connection;
179
- };
package/constants.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createCommonMongooseSchemas } from './utils.mjs';
2
+ export { mongooseConnections } from './_connections.mjs';
2
3
 
3
4
  /**
4
5
  * Common Mongoose schemas.
@@ -8,13 +9,5 @@ import { createCommonMongooseSchemas } from './utils.mjs';
8
9
  * field types and configurations used across multiple models.
9
10
  */
10
11
  const commonMongooseSchemas = createCommonMongooseSchemas();
11
- /**
12
- * Mongoose connections.
13
- *
14
- * This constant is a record of named Mongoose connections, allowing multiple
15
- * database connections to be managed within the application. An optional `default`
16
- * connection can also be specified for use when a specific connection is not provided.
17
- */
18
- const mongooseConnections = {};
19
12
 
20
- export { commonMongooseSchemas, mongooseConnections };
13
+ export { commonMongooseSchemas };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
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",
@@ -50,6 +50,11 @@
50
50
  "require": "./*.cjs",
51
51
  "types": "./*.d.ts"
52
52
  },
53
+ "./_connections": {
54
+ "import": null,
55
+ "require": null,
56
+ "types": null
57
+ },
53
58
  "./plugins/*": {
54
59
  "import": "./plugins/*.mjs",
55
60
  "require": "./plugins/*.cjs",
@@ -4,6 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const lodash = require('lodash');
6
6
 
7
+ const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
8
+
9
+ const lodash__default = /*#__PURE__*/_interopDefaultCompat(lodash);
10
+
11
+ const { get: lodashGet, set: lodashSet, unset: lodashUnset } = lodash__default;
7
12
  /**
8
13
  * Mongoose plugin to normalize the JSON output of documents.
9
14
  *
@@ -29,11 +34,11 @@ const mongooseNormalizePlugin = (schema) => {
29
34
  delete copiedRet._id;
30
35
  for (const path in schema.paths) {
31
36
  if (schema.paths[path]?.options?.private)
32
- lodash.unset(copiedRet, path);
37
+ lodashUnset(copiedRet, path);
33
38
  if (schema.paths[path]?.instance === 'Decimal128') {
34
- const value = lodash.get(copiedRet, path);
39
+ const value = lodashGet(copiedRet, path);
35
40
  if (value)
36
- lodash.set(copiedRet, path, value.toString());
41
+ lodashSet(copiedRet, path, value.toString());
37
42
  }
38
43
  }
39
44
  delete copiedRet.__v;
@@ -1,5 +1,6 @@
1
- import { unset, get, set } from 'lodash';
1
+ import lodash from 'lodash';
2
2
 
3
+ const { get: lodashGet, set: lodashSet, unset: lodashUnset } = lodash;
3
4
  /**
4
5
  * Mongoose plugin to normalize the JSON output of documents.
5
6
  *
@@ -25,11 +26,11 @@ const mongooseNormalizePlugin = (schema) => {
25
26
  delete copiedRet._id;
26
27
  for (const path in schema.paths) {
27
28
  if (schema.paths[path]?.options?.private)
28
- unset(copiedRet, path);
29
+ lodashUnset(copiedRet, path);
29
30
  if (schema.paths[path]?.instance === 'Decimal128') {
30
- const value = get(copiedRet, path);
31
+ const value = lodashGet(copiedRet, path);
31
32
  if (value)
32
- set(copiedRet, path, value.toString());
33
+ lodashSet(copiedRet, path, value.toString());
33
34
  }
34
35
  }
35
36
  delete copiedRet.__v;
package/types/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import type { AggregatePaginateModel, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
1
+ import type { AggregatePaginateModel, Connection, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
2
2
  export type {} from './aggregate-paginate';
3
3
  export type {} from './paginate';
4
4
  export interface BaseModelStatics<RawDocType, InstanceMethodsAndOverrides = {}, QueryHelpers = {}> {
5
5
  }
6
+ export interface MongooseConnections {
7
+ default?: Connection;
8
+ }
6
9
  declare global {
7
10
  /**
8
11
  * Type definition for a base Mongoose document type.
package/utils.cjs CHANGED
@@ -5,16 +5,18 @@ const lodash = require('lodash');
5
5
  const mongoose = require('mongoose');
6
6
  const mongooseAggregatePaginate = require('mongoose-aggregate-paginate-v2');
7
7
  const mongoosePaginate = require('mongoose-paginate-v2');
8
- const constants = require('./constants.cjs');
8
+ const _connections = require('./_connections.cjs');
9
9
  const normalize = require('./plugins/normalize.cjs');
10
10
 
11
11
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
12
12
 
13
13
  const Decimal__default = /*#__PURE__*/_interopDefaultCompat(Decimal);
14
+ const lodash__default = /*#__PURE__*/_interopDefaultCompat(lodash);
14
15
  const mongoose__default = /*#__PURE__*/_interopDefaultCompat(mongoose);
15
16
  const mongooseAggregatePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongooseAggregatePaginate);
16
17
  const mongoosePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongoosePaginate);
17
18
 
19
+ const { merge } = lodash__default;
18
20
  /**
19
21
  * Builds and returns a Mongoose model with specified schema and options.
20
22
  *
@@ -45,7 +47,7 @@ function buildMongooseModel(collection, name, schema, options) {
45
47
  schema.plugin(mongooseAggregatePaginate__default);
46
48
  schema.plugin(mongoosePaginate__default);
47
49
  schema.set('timestamps', options?.timestamps === undefined ? true : options.timestamps);
48
- return (options?.connection || constants.mongooseConnections.default || (constants.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://localhost:27017'))).model(name, schema, collection);
50
+ return (options?.connection || _connections.mongooseConnections.default || (_connections.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://localhost:27017'))).model(name, schema, collection);
49
51
  }
50
52
  /**
51
53
  * Creates common Mongoose schema definitions with optional custom schemas and settings.
@@ -71,7 +73,7 @@ function createCommonMongooseSchemas(customSchemas, options) {
71
73
  const baseRequiredBoolean = { required: true, type: Boolean };
72
74
  const baseRequiredNumber = { required: true, type: Number };
73
75
  const baseRequiredObjectId = { required: true, type: mongoose__default.Schema.Types.ObjectId };
74
- return lodash.merge({
76
+ return merge({
75
77
  boolean: {
76
78
  defaultFalse: {
77
79
  nonRequired: { default: false, type: Boolean },
package/utils.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import Decimal from 'decimal.js';
2
- import { merge } from 'lodash';
2
+ import lodash from 'lodash';
3
3
  import mongoose, { Types } from 'mongoose';
4
4
  import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
5
5
  import mongoosePaginate from 'mongoose-paginate-v2';
6
- import { mongooseConnections } from './constants.mjs';
6
+ import { mongooseConnections } from './_connections.mjs';
7
7
  import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
8
8
 
9
+ const { merge } = lodash;
9
10
  /**
10
11
  * Builds and returns a Mongoose model with specified schema and options.
11
12
  *