@kikiutils/mongoose 2.0.0-rc.0 → 2.0.0-rc.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.
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const customMongooseOptions = {};
3
4
  /**
4
5
  * Mongoose connections.
5
6
  *
@@ -9,4 +10,5 @@
9
10
  */
10
11
  const mongooseConnections = {};
11
12
 
13
+ exports.customMongooseOptions = customMongooseOptions;
12
14
  exports.mongooseConnections = mongooseConnections;
@@ -1,4 +1,6 @@
1
1
  import type { MongooseConnections } from './types';
2
+ import type { CustomMongooseOptions } from './types/options';
3
+ export declare const customMongooseOptions: CustomMongooseOptions;
2
4
  /**
3
5
  * Mongoose connections.
4
6
  *
@@ -1,3 +1,4 @@
1
+ const customMongooseOptions = {};
1
2
  /**
2
3
  * Mongoose connections.
3
4
  *
@@ -7,4 +8,4 @@
7
8
  */
8
9
  const mongooseConnections = {};
9
10
 
10
- export { mongooseConnections };
11
+ export { customMongooseOptions, mongooseConnections };
package/constants.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const utils = require('./utils.cjs');
4
- const _connections = require('./_connections.cjs');
4
+ const _internals = require('./_internals.cjs');
5
5
 
6
6
  /**
7
7
  * Common Mongoose schemas.
@@ -14,5 +14,5 @@ const _connections = require('./_connections.cjs');
14
14
  */
15
15
  const commonMongooseSchemas = utils.createCommonMongooseSchemas();
16
16
 
17
- exports.mongooseConnections = _connections.mongooseConnections;
17
+ exports.mongooseConnections = _internals.mongooseConnections;
18
18
  exports.commonMongooseSchemas = commonMongooseSchemas;
package/constants.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { mongooseConnections } from './_connections';
2
1
  import type { schemaBuilders } from './schema-builders';
2
+ export { mongooseConnections } from './_internals';
3
3
  export type DoNotUseOrRemoveThisType = typeof schemaBuilders;
4
4
  /**
5
5
  * Common Mongoose schemas.
package/constants.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createCommonMongooseSchemas } from './utils.mjs';
2
- export { mongooseConnections } from './_connections.mjs';
2
+ export { mongooseConnections } from './_internals.mjs';
3
3
 
4
4
  /**
5
5
  * Common Mongoose schemas.
package/options.cjs CHANGED
@@ -1,8 +1,19 @@
1
1
  'use strict';
2
2
 
3
+ const _internals = require('./_internals.cjs');
4
+
3
5
  /**
4
6
  * @deprecated - Will be removed in the next major version. Use {@link setCustomMongooseOptions} instead.
5
7
  */
6
8
  const customMongooseOptions = {};
9
+ /**
10
+ * Sets custom options.
11
+ *
12
+ * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called
13
+ * every time {@link buildMongooseModel} is used. Inside this function, you can modify
14
+ * the schema, allowing you to apply common settings to all global schemas.
15
+ */
16
+ const setCustomMongooseOptions = (key, value) => (_internals.customMongooseOptions[key] = value);
7
17
 
8
18
  exports.customMongooseOptions = customMongooseOptions;
19
+ exports.setCustomMongooseOptions = setCustomMongooseOptions;
package/options.mjs CHANGED
@@ -1,6 +1,16 @@
1
+ import { customMongooseOptions as customMongooseOptions$1 } from './_internals.mjs';
2
+
1
3
  /**
2
4
  * @deprecated - Will be removed in the next major version. Use {@link setCustomMongooseOptions} instead.
3
5
  */
4
6
  const customMongooseOptions = {};
7
+ /**
8
+ * Sets custom options.
9
+ *
10
+ * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called
11
+ * every time {@link buildMongooseModel} is used. Inside this function, you can modify
12
+ * the schema, allowing you to apply common settings to all global schemas.
13
+ */
14
+ const setCustomMongooseOptions = (key, value) => (customMongooseOptions$1[key] = value);
5
15
 
6
- export { customMongooseOptions };
16
+ export { customMongooseOptions, setCustomMongooseOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.0.0-rc.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,7 +9,7 @@
9
9
  "url": "git+https://github.com/kiki-kanri/kikiutils-node-mongoose.git"
10
10
  },
11
11
  "scripts": {
12
- "build": "ts-project-builder ./src/constants.ts ./src/schema-builders/index.ts ./src/utils.ts --clean --preserve-modules",
12
+ "build": "ts-project-builder ./src/constants.ts ./src/options.ts ./src/schema-builders/index.ts ./src/utils.ts --clean --preserve-modules",
13
13
  "bumplog": "changelogen --bump",
14
14
  "release": "pnpm run build && pnpm run test && changelogen --push --release && sh ./build-and-publish.sh",
15
15
  "test": "jest --coverage"
@@ -61,6 +61,7 @@ export interface Decimal128SchemaBuilder<Props extends {
61
61
  *
62
62
  * @param places - The number of decimal places to round to (default is 2).
63
63
  * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).
64
+ *
64
65
  * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.
65
66
  */
66
67
  setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<{
@@ -39,6 +39,7 @@ export interface StringSchemaBuilder<Props extends {
39
39
  * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.
40
40
  *
41
41
  * @param message - The custom error message to return if validation fails. Defaults to a standard IPv4 validation message.
42
+ *
42
43
  * @returns A schema builder with IPv4 validation and the `trim` option enabled.
43
44
  */
44
45
  ipv4: <T extends string = typeof defaultIPv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<{
@@ -49,6 +50,7 @@ export interface StringSchemaBuilder<Props extends {
49
50
  * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.
50
51
  *
51
52
  * @param message - The custom error message to return if validation fails. Defaults to a standard IPv6 validation message.
53
+ *
52
54
  * @returns A schema builder with IPv6 validation and the `trim` option enabled.
53
55
  */
54
56
  ipv6: <T extends string = typeof defaultIPv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<{
@@ -59,6 +61,7 @@ export interface StringSchemaBuilder<Props extends {
59
61
  * This method ensures the string length is exactly or within a specified range.
60
62
  *
61
63
  * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.
64
+ *
62
65
  * @returns A schema builder with both `maxlength` and `minlength` options applied.
63
66
  */
64
67
  length: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
package/utils.cjs CHANGED
@@ -6,8 +6,7 @@ const mongoose = require('mongoose');
6
6
  const mongooseAggregatePaginate = require('mongoose-aggregate-paginate-v2');
7
7
  const mongoosePaginate = require('mongoose-paginate-v2');
8
8
  const net = require('node:net');
9
- const _connections = require('./_connections.cjs');
10
- const _options = require('./_options.cjs');
9
+ const _internals = require('./_internals.cjs');
11
10
  const options = require('./options.cjs');
12
11
  const normalize = require('./plugins/normalize.cjs');
13
12
 
@@ -54,8 +53,8 @@ function buildMongooseModel(collection, name, schema, options$1) {
54
53
  schema.plugin(mongooseAggregatePaginate__default);
55
54
  schema.plugin(mongoosePaginate__default);
56
55
  schema.set('timestamps', options$1?.timestamps === undefined ? true : options$1.timestamps);
57
- (_options.customMongooseOptions.beforeModelBuild || options.customMongooseOptions.beforeModelBuild)?.(schema);
58
- return (options$1?.connection || _connections.mongooseConnections.default || (_connections.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
56
+ (_internals.customMongooseOptions.beforeModelBuild || options.customMongooseOptions.beforeModelBuild)?.(schema);
57
+ return (options$1?.connection || _internals.mongooseConnections.default || (_internals.mongooseConnections.default = mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).model(name, schema, collection);
59
58
  }
60
59
  /**
61
60
  * Creates common Mongoose schema definitions with optional custom schemas and settings.
package/utils.mjs CHANGED
@@ -4,8 +4,7 @@ import mongoose, { Types } from 'mongoose';
4
4
  import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
5
5
  import mongoosePaginate from 'mongoose-paginate-v2';
6
6
  import net from 'node:net';
7
- import { mongooseConnections } from './_connections.mjs';
8
- import { customMongooseOptions } from './_options.mjs';
7
+ import { customMongooseOptions, mongooseConnections } from './_internals.mjs';
9
8
  import { customMongooseOptions as customMongooseOptions$1 } from './options.mjs';
10
9
  import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
11
10
 
package/_options.cjs DELETED
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const customMongooseOptions = {};
4
-
5
- exports.customMongooseOptions = customMongooseOptions;
package/_options.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { CustomMongooseOptions } from './types/options';
2
- export declare const customMongooseOptions: CustomMongooseOptions;
package/_options.mjs DELETED
@@ -1,3 +0,0 @@
1
- const customMongooseOptions = {};
2
-
3
- export { customMongooseOptions };