@common-stack/store-mongo 8.6.1-alpha.9 → 9.0.1-alpha.2

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 @@
1
+ export { getMongoDBPoolOptions, mergeMongoDBOptions, validateMongoDBOptions, getMongoDBOptionsWithLogging, type MongooseConnectionOptions, } from './mongodb-pool-options';
@@ -0,0 +1,59 @@
1
+ /**
2
+ * MongoDB Connection Pool Configuration
3
+ *
4
+ * Centralized configuration for Mongoose connection pool settings.
5
+ * This ensures all applications using @common-stack/store-mongo have
6
+ * optimized connection pooling for concurrent requests.
7
+ *
8
+ * Environment-specific defaults:
9
+ * - Production: Large pool (100) for high concurrency
10
+ * - Staging: Medium pool (50) for load testing
11
+ * - Development: Small pool (10) for local development
12
+ * - Test: Minimal pool (5) for test isolation
13
+ */
14
+ export interface MongooseConnectionOptions {
15
+ maxPoolSize?: number;
16
+ minPoolSize?: number;
17
+ maxIdleTimeMS?: number;
18
+ waitQueueTimeoutMS?: number;
19
+ serverSelectionTimeoutMS?: number;
20
+ socketTimeoutMS?: number;
21
+ maxConnecting?: number;
22
+ retryWrites?: boolean;
23
+ retryReads?: boolean;
24
+ compressors?: string[];
25
+ connectTimeoutMS?: number;
26
+ [key: string]: any;
27
+ }
28
+ /**
29
+ * Get environment-specific MongoDB connection pool configuration
30
+ *
31
+ * @param env - Environment name (production, staging, development, test)
32
+ * @returns Mongoose connection options with pool configuration
33
+ */
34
+ export declare function getMongoDBPoolOptions(env?: string): MongooseConnectionOptions;
35
+ /**
36
+ * Merge user-provided options with environment defaults
37
+ * User options take precedence over defaults
38
+ *
39
+ * @param env - Environment name
40
+ * @param userOptions - Custom options to override defaults
41
+ * @returns Merged connection options
42
+ */
43
+ export declare function mergeMongoDBOptions(env?: string, userOptions?: MongooseConnectionOptions): MongooseConnectionOptions;
44
+ /**
45
+ * Validate connection options (development helper)
46
+ *
47
+ * @param options - Options to validate
48
+ * @returns true if options are valid, false otherwise
49
+ */
50
+ export declare function validateMongoDBOptions(options: MongooseConnectionOptions): boolean;
51
+ /**
52
+ * Get connection options for environment with optional logging
53
+ * Useful for debugging connection configuration
54
+ *
55
+ * @param env - Environment name
56
+ * @param verbose - Whether to log configuration
57
+ * @returns Connection options
58
+ */
59
+ export declare function getMongoDBOptionsWithLogging(env?: string, verbose?: boolean): MongooseConnectionOptions;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * MongoDB Connection Pool Configuration
3
+ *
4
+ * Centralized configuration for Mongoose connection pool settings.
5
+ * This ensures all applications using @common-stack/store-mongo have
6
+ * optimized connection pooling for concurrent requests.
7
+ *
8
+ * Environment-specific defaults:
9
+ * - Production: Large pool (100) for high concurrency
10
+ * - Staging: Medium pool (50) for load testing
11
+ * - Development: Small pool (10) for local development
12
+ * - Test: Minimal pool (5) for test isolation
13
+ */
14
+ /**
15
+ * Get environment-specific MongoDB connection pool configuration
16
+ *
17
+ * @param env - Environment name (production, staging, development, test)
18
+ * @returns Mongoose connection options with pool configuration
19
+ */
20
+ function getMongoDBPoolOptions(env = 'production') {
21
+ const configs = {
22
+ development: {
23
+ maxPoolSize: 10, // Smaller pool for dev
24
+ minPoolSize: 2, // Minimal baseline
25
+ maxIdleTimeMS: 30000, // Close idle connections quickly
26
+ waitQueueTimeoutMS: 10000, // Fail fast in queue
27
+ serverSelectionTimeoutMS: 5000,
28
+ socketTimeoutMS: 45000,
29
+ maxConnecting: 2, // Limit concurrent connects
30
+ retryWrites: false, // Disable retries in dev
31
+ retryReads: false,
32
+ compressors: ['snappy', 'zlib'],
33
+ connectTimeoutMS: 10000,
34
+ },
35
+ staging: {
36
+ maxPoolSize: 50, // Medium pool for staging
37
+ minPoolSize: 20, // Keep 20 connections ready
38
+ maxIdleTimeMS: 45000, // Moderate idle timeout
39
+ waitQueueTimeoutMS: 10000,
40
+ serverSelectionTimeoutMS: 5000,
41
+ socketTimeoutMS: 45000,
42
+ maxConnecting: 5, // Limit concurrent connects
43
+ retryWrites: true, // Enable retries in staging
44
+ retryReads: true,
45
+ compressors: ['snappy', 'zlib'],
46
+ connectTimeoutMS: 10000,
47
+ },
48
+ production: {
49
+ maxPoolSize: 100, // Large pool for production - supports 100 concurrent connections
50
+ minPoolSize: 50, // Keep 50 connections ready
51
+ maxIdleTimeMS: 60000, // Close idle connections after 1 minute
52
+ waitQueueTimeoutMS: 10000, // Fail fast if no connection available after 10s
53
+ serverSelectionTimeoutMS: 5000,
54
+ socketTimeoutMS: 45000,
55
+ maxConnecting: 10, // Allow up to 10 concurrent connection attempts
56
+ retryWrites: true, // Auto-retry writes on transient failures
57
+ retryReads: true, // Auto-retry reads on transient failures
58
+ compressors: ['snappy', 'zlib'], // Enable compression for bandwidth efficiency
59
+ connectTimeoutMS: 10000,
60
+ },
61
+ test: {
62
+ maxPoolSize: 5, // Minimal for test isolation
63
+ minPoolSize: 1, // One connection baseline
64
+ maxIdleTimeMS: 10000, // Quick cleanup
65
+ waitQueueTimeoutMS: 5000,
66
+ serverSelectionTimeoutMS: 3000,
67
+ socketTimeoutMS: 30000,
68
+ maxConnecting: 1, // Serialize connection attempts
69
+ retryWrites: false, // No retries in test
70
+ retryReads: false,
71
+ compressors: [], // Skip compression in test
72
+ connectTimeoutMS: 5000,
73
+ },
74
+ };
75
+ return configs[env] || configs.production;
76
+ }
77
+ /**
78
+ * Merge user-provided options with environment defaults
79
+ * User options take precedence over defaults
80
+ *
81
+ * @param env - Environment name
82
+ * @param userOptions - Custom options to override defaults
83
+ * @returns Merged connection options
84
+ */
85
+ function mergeMongoDBOptions(env = 'production', userOptions) {
86
+ const defaults = getMongoDBPoolOptions(env);
87
+ if (!userOptions) {
88
+ return defaults;
89
+ }
90
+ return {
91
+ ...defaults,
92
+ ...userOptions,
93
+ };
94
+ }
95
+ /**
96
+ * Validate connection options (development helper)
97
+ *
98
+ * @param options - Options to validate
99
+ * @returns true if options are valid, false otherwise
100
+ */
101
+ function validateMongoDBOptions(options) {
102
+ if (options.maxPoolSize && options.minPoolSize) {
103
+ if (options.minPoolSize > options.maxPoolSize) {
104
+ console.warn(`[MongoDB Options] Warning: minPoolSize (${options.minPoolSize}) > maxPoolSize (${options.maxPoolSize})`);
105
+ return false;
106
+ }
107
+ }
108
+ return true;
109
+ }
110
+ /**
111
+ * Get connection options for environment with optional logging
112
+ * Useful for debugging connection configuration
113
+ *
114
+ * @param env - Environment name
115
+ * @param verbose - Whether to log configuration
116
+ * @returns Connection options
117
+ */
118
+ function getMongoDBOptionsWithLogging(env = 'production', verbose = false) {
119
+ const options = getMongoDBPoolOptions(env);
120
+ if (verbose) {
121
+ console.info(`[MongoDB Pool Config] Environment: ${env}`);
122
+ console.info(`[MongoDB Pool Config] maxPoolSize: ${options.maxPoolSize}`);
123
+ console.info(`[MongoDB Pool Config] minPoolSize: ${options.minPoolSize}`);
124
+ console.info(`[MongoDB Pool Config] maxIdleTimeMS: ${options.maxIdleTimeMS}`);
125
+ console.info(`[MongoDB Pool Config] retryWrites: ${options.retryWrites}`);
126
+ console.info(`[MongoDB Pool Config] retryReads: ${options.retryReads}`);
127
+ }
128
+ return options;
129
+ }export{getMongoDBOptionsWithLogging,getMongoDBPoolOptions,mergeMongoDBOptions,validateMongoDBOptions};//# sourceMappingURL=mongodb-pool-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb-pool-options.js","sources":["../../src/config/mongodb-pool-options.ts"],"sourcesContent":["/**\n * MongoDB Connection Pool Configuration\n * \n * Centralized configuration for Mongoose connection pool settings.\n * This ensures all applications using @common-stack/store-mongo have\n * optimized connection pooling for concurrent requests.\n * \n * Environment-specific defaults:\n * - Production: Large pool (100) for high concurrency\n * - Staging: Medium pool (50) for load testing\n * - Development: Small pool (10) for local development\n * - Test: Minimal pool (5) for test isolation\n */\n\nexport interface MongooseConnectionOptions {\n maxPoolSize?: number;\n minPoolSize?: number;\n maxIdleTimeMS?: number;\n waitQueueTimeoutMS?: number;\n serverSelectionTimeoutMS?: number;\n socketTimeoutMS?: number;\n maxConnecting?: number;\n retryWrites?: boolean;\n retryReads?: boolean;\n compressors?: string[];\n connectTimeoutMS?: number;\n [key: string]: any;\n}\n\n/**\n * Get environment-specific MongoDB connection pool configuration\n * \n * @param env - Environment name (production, staging, development, test)\n * @returns Mongoose connection options with pool configuration\n */\nexport function getMongoDBPoolOptions(env: string = 'production'): MongooseConnectionOptions {\n const configs: Record<string, MongooseConnectionOptions> = {\n development: {\n maxPoolSize: 10, // Smaller pool for dev\n minPoolSize: 2, // Minimal baseline\n maxIdleTimeMS: 30000, // Close idle connections quickly\n waitQueueTimeoutMS: 10000, // Fail fast in queue\n serverSelectionTimeoutMS: 5000,\n socketTimeoutMS: 45000,\n maxConnecting: 2, // Limit concurrent connects\n retryWrites: false, // Disable retries in dev\n retryReads: false,\n compressors: ['snappy', 'zlib'],\n connectTimeoutMS: 10000,\n },\n staging: {\n maxPoolSize: 50, // Medium pool for staging\n minPoolSize: 20, // Keep 20 connections ready\n maxIdleTimeMS: 45000, // Moderate idle timeout\n waitQueueTimeoutMS: 10000,\n serverSelectionTimeoutMS: 5000,\n socketTimeoutMS: 45000,\n maxConnecting: 5, // Limit concurrent connects\n retryWrites: true, // Enable retries in staging\n retryReads: true,\n compressors: ['snappy', 'zlib'],\n connectTimeoutMS: 10000,\n },\n production: {\n maxPoolSize: 100, // Large pool for production - supports 100 concurrent connections\n minPoolSize: 50, // Keep 50 connections ready\n maxIdleTimeMS: 60000, // Close idle connections after 1 minute\n waitQueueTimeoutMS: 10000, // Fail fast if no connection available after 10s\n serverSelectionTimeoutMS: 5000,\n socketTimeoutMS: 45000,\n maxConnecting: 10, // Allow up to 10 concurrent connection attempts\n retryWrites: true, // Auto-retry writes on transient failures\n retryReads: true, // Auto-retry reads on transient failures\n compressors: ['snappy', 'zlib'], // Enable compression for bandwidth efficiency\n connectTimeoutMS: 10000,\n },\n test: {\n maxPoolSize: 5, // Minimal for test isolation\n minPoolSize: 1, // One connection baseline\n maxIdleTimeMS: 10000, // Quick cleanup\n waitQueueTimeoutMS: 5000,\n serverSelectionTimeoutMS: 3000,\n socketTimeoutMS: 30000,\n maxConnecting: 1, // Serialize connection attempts\n retryWrites: false, // No retries in test\n retryReads: false,\n compressors: [], // Skip compression in test\n connectTimeoutMS: 5000,\n },\n };\n\n return configs[env] || configs.production;\n}\n\n/**\n * Merge user-provided options with environment defaults\n * User options take precedence over defaults\n * \n * @param env - Environment name\n * @param userOptions - Custom options to override defaults\n * @returns Merged connection options\n */\nexport function mergeMongoDBOptions(\n env: string = 'production',\n userOptions?: MongooseConnectionOptions,\n): MongooseConnectionOptions {\n const defaults = getMongoDBPoolOptions(env);\n \n if (!userOptions) {\n return defaults;\n }\n\n return {\n ...defaults,\n ...userOptions,\n };\n}\n\n/**\n * Validate connection options (development helper)\n * \n * @param options - Options to validate\n * @returns true if options are valid, false otherwise\n */\nexport function validateMongoDBOptions(options: MongooseConnectionOptions): boolean {\n if (options.maxPoolSize && options.minPoolSize) {\n if (options.minPoolSize > options.maxPoolSize) {\n console.warn(\n `[MongoDB Options] Warning: minPoolSize (${options.minPoolSize}) > maxPoolSize (${options.maxPoolSize})`,\n );\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Get connection options for environment with optional logging\n * Useful for debugging connection configuration\n * \n * @param env - Environment name\n * @param verbose - Whether to log configuration\n * @returns Connection options\n */\nexport function getMongoDBOptionsWithLogging(\n env: string = 'production',\n verbose: boolean = false,\n): MongooseConnectionOptions {\n const options = getMongoDBPoolOptions(env);\n\n if (verbose) {\n console.info(`[MongoDB Pool Config] Environment: ${env}`);\n console.info(`[MongoDB Pool Config] maxPoolSize: ${options.maxPoolSize}`);\n console.info(`[MongoDB Pool Config] minPoolSize: ${options.minPoolSize}`);\n console.info(`[MongoDB Pool Config] maxIdleTimeMS: ${options.maxIdleTimeMS}`);\n console.info(`[MongoDB Pool Config] retryWrites: ${options.retryWrites}`);\n console.info(`[MongoDB Pool Config] retryReads: ${options.retryReads}`);\n }\n\n return options;\n}\n"],"names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C,CAAC;IAE3C,IAAI,OAAO,EAAE;AACX,QAAA,OAAO,CAAC,IAAI,CAAC,sCAAsC,GAAG,CAAA,CAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAA,mCAAA,EAAsC,OAAO,CAAC,WAAW,CAAE,CAAA,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAA,mCAAA,EAAsC,OAAO,CAAC,WAAW,CAAE,CAAA,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAA,qCAAA,EAAwC,OAAO,CAAC,aAAa,CAAE,CAAA,CAAC,CAAC;QAC9E,OAAO,CAAC,IAAI,CAAC,CAAA,mCAAA,EAAsC,OAAO,CAAC,WAAW,CAAE,CAAA,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAA,kCAAA,EAAqC,OAAO,CAAC,UAAU,CAAE,CAAA,CAAC,CAAC;KACzE;AAED,IAAA,OAAO,OAAO,CAAC;AACjB"}
@@ -1,3 +1,28 @@
1
1
  import * as mongoose from 'mongoose';
2
- declare const generateMongo: (monoUrl: any) => mongoose.Connection;
3
- export { generateMongo };
2
+ import { getMongoDBPoolOptions, mergeMongoDBOptions, type MongooseConnectionOptions } from '../config/mongodb-pool-options';
3
+ /**
4
+ * Generate MongoDB connection with optimized pool configuration
5
+ *
6
+ * This helper automatically applies environment-specific MongoDB connection
7
+ * pool settings to ensure optimal performance for concurrent requests.
8
+ *
9
+ * @param mongoUrl - MongoDB connection string
10
+ * @param env - Environment name (production, staging, development, test)
11
+ * @param customOptions - Optional custom options to override defaults
12
+ * @returns Mongoose connection
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Use with default pool settings for environment
17
+ * const connection = generateMongo('mongodb://localhost:27017/mydb', 'production');
18
+ *
19
+ * // Override specific settings
20
+ * const connection = generateMongo(
21
+ * 'mongodb://localhost:27017/mydb',
22
+ * 'production',
23
+ * { maxPoolSize: 200 } // Custom pool size
24
+ * );
25
+ * ```
26
+ */
27
+ declare const generateMongo: (mongoUrl: string, env?: string, customOptions?: MongooseConnectionOptions) => mongoose.Connection;
28
+ export { generateMongo, getMongoDBPoolOptions, mergeMongoDBOptions };
@@ -1,18 +1,50 @@
1
- import*as mongoose from'mongoose';const generateMongo = (mongoUrl) => {
2
- // creates default connection
1
+ import*as mongoose from'mongoose';import {mergeMongoDBOptions}from'../config/mongodb-pool-options.js';export{getMongoDBPoolOptions}from'../config/mongodb-pool-options.js';/**
2
+ * Generate MongoDB connection with optimized pool configuration
3
+ *
4
+ * This helper automatically applies environment-specific MongoDB connection
5
+ * pool settings to ensure optimal performance for concurrent requests.
6
+ *
7
+ * @param mongoUrl - MongoDB connection string
8
+ * @param env - Environment name (production, staging, development, test)
9
+ * @param customOptions - Optional custom options to override defaults
10
+ * @returns Mongoose connection
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // Use with default pool settings for environment
15
+ * const connection = generateMongo('mongodb://localhost:27017/mydb', 'production');
16
+ *
17
+ * // Override specific settings
18
+ * const connection = generateMongo(
19
+ * 'mongodb://localhost:27017/mydb',
20
+ * 'production',
21
+ * { maxPoolSize: 200 } // Custom pool size
22
+ * );
23
+ * ```
24
+ */
25
+ const generateMongo = (mongoUrl, env = 'production', customOptions) => {
26
+ // Get environment-specific pool configuration
27
+ const poolOptions = mergeMongoDBOptions(env, customOptions);
28
+ // Log configuration in development mode
29
+ if (env === 'development') {
30
+ console.info('[MongoDB] Connecting with pool options:', {
31
+ maxPoolSize: poolOptions.maxPoolSize,
32
+ minPoolSize: poolOptions.minPoolSize,
33
+ maxIdleTimeMS: poolOptions.maxIdleTimeMS,
34
+ });
35
+ }
36
+ // creates default connection with pool configuration
3
37
  mongoose
4
- .connect(mongoUrl, {})
38
+ .connect(mongoUrl, poolOptions)
5
39
  .then(() => {
6
- console.info('mogoose connect - success');
7
- // console.info(`uri - ${uri}`);
8
- // console.info(`connectionOptions - ${connectionOptions}`);
40
+ console.info(`[MongoDB] Connection successful - Pool: max=${poolOptions.maxPoolSize}, min=${poolOptions.minPoolSize}`);
9
41
  })
10
42
  .catch((err) => {
11
- console.error('mogoose connect - error - ', err);
43
+ console.error('[MongoDB] Connection failed:', err.message);
12
44
  // throw err;
13
45
  process.kill(process.pid);
14
46
  });
15
47
  // to access default connection
16
48
  const mongooseConnection = mongoose.connection;
17
49
  return mongooseConnection;
18
- };export{generateMongo};//# sourceMappingURL=mongoose-connection.js.map
50
+ };export{generateMongo,mergeMongoDBOptions};//# sourceMappingURL=mongoose-connection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mongoose-connection.js","sources":["../../src/helpers/mongoose-connection.ts"],"sourcesContent":["import * as mongoose from 'mongoose';\n\nconst generateMongo: (monoUrl) => mongoose.Connection = (mongoUrl) => {\n // creates default connection\n mongoose\n .connect(mongoUrl, {})\n .then(() => {\n console.info('mogoose connect - success');\n // console.info(`uri - ${uri}`);\n // console.info(`connectionOptions - ${connectionOptions}`);\n })\n .catch((err: mongoose.Error) => {\n console.error('mogoose connect - error - ', err);\n // throw err;\n process.kill(process.pid);\n });\n // to access default connection\n const mongooseConnection: mongoose.Connection = mongoose.connection;\n\n return mongooseConnection;\n};\n\nexport { generateMongo };\n"],"names":[],"mappings":"kCAEA,MAAM,aAAa,GAAqC,CAAC,QAAQ,KAAI;;IAEjE,QAAQ;AACH,SAAA,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,IAAI,CAAC,MAAK;AACP,QAAA,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;;;AAG9C,KAAC,CAAC;AACD,SAAA,KAAK,CAAC,CAAC,GAAmB,KAAI;AAC3B,QAAA,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;;AAEjD,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9B,KAAC,CAAC,CAAC;;AAEP,IAAA,MAAM,kBAAkB,GAAwB,QAAQ,CAAC,UAAU,CAAC;AAEpE,IAAA,OAAO,kBAAkB,CAAC;AAC9B"}
1
+ {"version":3,"file":"mongoose-connection.js","sources":["../../src/helpers/mongoose-connection.ts"],"sourcesContent":["import * as mongoose from 'mongoose';\nimport {\n getMongoDBPoolOptions,\n mergeMongoDBOptions,\n type MongooseConnectionOptions,\n} from '../config/mongodb-pool-options';\n\n/**\n * Generate MongoDB connection with optimized pool configuration\n *\n * This helper automatically applies environment-specific MongoDB connection\n * pool settings to ensure optimal performance for concurrent requests.\n *\n * @param mongoUrl - MongoDB connection string\n * @param env - Environment name (production, staging, development, test)\n * @param customOptions - Optional custom options to override defaults\n * @returns Mongoose connection\n *\n * @example\n * ```typescript\n * // Use with default pool settings for environment\n * const connection = generateMongo('mongodb://localhost:27017/mydb', 'production');\n *\n * // Override specific settings\n * const connection = generateMongo(\n * 'mongodb://localhost:27017/mydb',\n * 'production',\n * { maxPoolSize: 200 } // Custom pool size\n * );\n * ```\n */\nconst generateMongo: (\n mongoUrl: string,\n env?: string,\n customOptions?: MongooseConnectionOptions,\n) => mongoose.Connection = (mongoUrl, env = 'production', customOptions) => {\n // Get environment-specific pool configuration\n const poolOptions = mergeMongoDBOptions(env, customOptions);\n\n // Log configuration in development mode\n if (env === 'development') {\n console.info('[MongoDB] Connecting with pool options:', {\n maxPoolSize: poolOptions.maxPoolSize,\n minPoolSize: poolOptions.minPoolSize,\n maxIdleTimeMS: poolOptions.maxIdleTimeMS,\n });\n }\n\n // creates default connection with pool configuration\n mongoose\n .connect(mongoUrl, poolOptions)\n .then(() => {\n console.info(`[MongoDB] Connection successful - Pool: max=${poolOptions.maxPoolSize}, min=${poolOptions.minPoolSize}`);\n })\n .catch((err: mongoose.Error) => {\n console.error('[MongoDB] Connection failed:', err.message);\n // throw err;\n process.kill(process.pid);\n });\n\n // to access default connection\n const mongooseConnection: mongoose.Connection = mongoose.connection;\n\n return mongooseConnection;\n};\n\nexport { generateMongo, getMongoDBPoolOptions, mergeMongoDBOptions };\n"],"names":[],"mappings":"2KAOA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,MAAA,aAAa,GAIQ,CAAC,QAAQ,EAAE,GAAG,GAAG,YAAY,EAAE,aAAa,KAAI;;IAEzE,MAAM,WAAW,GAAG,mBAAmB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;;AAG5D,IAAA,IAAI,GAAG,KAAK,aAAa,EAAE;AACzB,QAAA,OAAO,CAAC,IAAI,CAAC,yCAAyC,EAAE;YACtD,WAAW,EAAE,WAAW,CAAC,WAAW;YACpC,WAAW,EAAE,WAAW,CAAC,WAAW;YACpC,aAAa,EAAE,WAAW,CAAC,aAAa;AACzC,SAAA,CAAC,CAAC;KACJ;;IAGD,QAAQ;AACL,SAAA,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC;SAC9B,IAAI,CAAC,MAAK;AACT,QAAA,OAAO,CAAC,IAAI,CAAC,CAAA,4CAAA,EAA+C,WAAW,CAAC,WAAW,CAAA,MAAA,EAAS,WAAW,CAAC,WAAW,CAAA,CAAE,CAAC,CAAC;AACzH,KAAC,CAAC;AACD,SAAA,KAAK,CAAC,CAAC,GAAmB,KAAI;QAC7B,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;AAE3D,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC5B,KAAC,CAAC,CAAC;;AAGL,IAAA,MAAM,kBAAkB,GAAwB,QAAQ,CAAC,UAAU,CAAC;AAEpE,IAAA,OAAO,kBAAkB,CAAC;AAC5B"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './config';
1
2
  export * from './helpers';
2
3
  export * from './services';
3
4
  export * from './store';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.js';export{ConnectionPoolManager}from'./services/ConnectionPoolManager.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields2,commonModelSchemaOptions2}from'./store/models/common-options-v2.js';export{addIdVirtualFields,applyCommonSchemaPlugins,applyLeanVirtuals,commonModeSchemaOptions}from'./store/models/common-options.js';export{BaseMongoRepository}from'./store/repositories/BaseMongoRepository.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader2}from'./dataloaders/bulk-dataloader-v2.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin as BaseServiceMixin2}from'./mixins/BaseServiceMixin.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.js';export{PAGINATION_OPTIONS}from'./interfaces/getAllArgs.js';//# sourceMappingURL=index.js.map
1
+ export{getMongoDBOptionsWithLogging,getMongoDBPoolOptions,mergeMongoDBOptions,validateMongoDBOptions}from'./config/mongodb-pool-options.js';export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.js';export{ConnectionPoolManager}from'./services/ConnectionPoolManager.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields2,commonModelSchemaOptions2}from'./store/models/common-options-v2.js';export{addIdVirtualFields,applyCommonSchemaPlugins,applyLeanVirtuals,commonModeSchemaOptions}from'./store/models/common-options.js';export{BaseMongoRepository}from'./store/repositories/BaseMongoRepository.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader2}from'./dataloaders/bulk-dataloader-v2.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin as BaseServiceMixin2}from'./mixins/BaseServiceMixin.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.js';export{PAGINATION_OPTIONS}from'./interfaces/getAllArgs.js';//# sourceMappingURL=index.js.map
package/lib/module.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare const _default: any;
1
+ import { Feature } from '@common-stack/server-core';
2
+ declare const _default: Feature<any, any>;
2
3
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common-stack/store-mongo",
3
- "version": "8.6.1-alpha.9",
3
+ "version": "9.0.1-alpha.2",
4
4
  "description": "Sample core for higher packages to depend on",
5
5
  "license": "UNLICENSED",
6
6
  "author": "CDMBase LLC",
@@ -24,11 +24,11 @@
24
24
  "watch": "npm run build:lib:watch"
25
25
  },
26
26
  "dependencies": {
27
- "@common-stack/core": "8.6.1-alpha.9",
27
+ "@common-stack/core": "9.0.1-alpha.1",
28
28
  "mongoose-lean-virtuals": "^0.9.1"
29
29
  },
30
30
  "devDependencies": {
31
- "common": "8.6.1-alpha.9",
31
+ "common": "9.0.1-alpha.1",
32
32
  "moleculer": "^0.14.33",
33
33
  "mongoose": "^6.12.8"
34
34
  },
@@ -56,8 +56,8 @@
56
56
  ]
57
57
  }
58
58
  },
59
- "gitHead": "b660069d9fb23784d2a755574be34938e5c8778b",
60
59
  "typescript": {
61
60
  "definition": "lib/index.d.ts"
62
- }
61
+ },
62
+ "gitHead": "7e6591c1599d92f774de57bcf65480510d527b95"
63
63
  }