@miiajs/mongoose 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ruslan Matiushev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @miiajs/mongoose
2
+
3
+ MongoDB integration via Mongoose for MiiaJS with injectable models.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @miiajs/mongoose mongoose
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ **[miiajs.com/docs/packages/mongoose](https://miiajs.com/docs/packages/mongoose)**
14
+
15
+ ## License
16
+
17
+ MIT
@@ -0,0 +1,5 @@
1
+ import type { Logger } from '@miiajs/core';
2
+ import type mongoose from 'mongoose';
3
+ export declare function createConnection(uri: string, logger: Logger, options?: mongoose.ConnectOptions): Promise<mongoose.Connection>;
4
+ export declare function closeConnection(connection: mongoose.Connection): Promise<void>;
5
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAEpC,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,QAAQ,CAAC,cAAc,GAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAU9B;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpF"}
@@ -0,0 +1,13 @@
1
+ export async function createConnection(uri, logger, options) {
2
+ const { createConnection: create } = await import('mongoose');
3
+ const connection = create(uri, options);
4
+ connection.on('error', (err) => {
5
+ logger.error(`Connection error: ${err.message}`, err.stack);
6
+ });
7
+ await connection.asPromise();
8
+ return connection;
9
+ }
10
+ export async function closeConnection(connection) {
11
+ await connection.close();
12
+ }
13
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAW,EACX,MAAc,EACd,OAAiC;IAEjC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;IAC7D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAEvC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QAC7B,MAAM,CAAC,KAAK,CAAC,qBAAqB,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;IAEF,MAAM,UAAU,CAAC,SAAS,EAAE,CAAA;IAC5B,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAA+B;IACnE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAA;AAC1B,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Default number of connection attempts before giving up.
3
+ * Override via MongooseModuleOptions.retry.attempts.
4
+ */
5
+ export declare const DEFAULT_RETRY_ATTEMPTS = 3;
6
+ /**
7
+ * Default delay (ms) between connection retries.
8
+ * Override via MongooseModuleOptions.retry.delay.
9
+ */
10
+ export declare const DEFAULT_RETRY_DELAY = 2000;
11
+ /**
12
+ * Node.js network error codes considered retryable during connection.
13
+ * Non-retryable errors (e.g. auth failure) abort immediately.
14
+ */
15
+ export declare const RETRYABLE_CODES: ReadonlySet<string>;
16
+ /** Logger context tag for this package. */
17
+ export declare const LOGGER_CONTEXT = "MongooseModule";
18
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAA;AAEvC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,OAAQ,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,CAM9C,CAAA;AAEF,2CAA2C;AAC3C,eAAO,MAAM,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Default number of connection attempts before giving up.
3
+ * Override via MongooseModuleOptions.retry.attempts.
4
+ */
5
+ export const DEFAULT_RETRY_ATTEMPTS = 3;
6
+ /**
7
+ * Default delay (ms) between connection retries.
8
+ * Override via MongooseModuleOptions.retry.delay.
9
+ */
10
+ export const DEFAULT_RETRY_DELAY = 2_000;
11
+ /**
12
+ * Node.js network error codes considered retryable during connection.
13
+ * Non-retryable errors (e.g. auth failure) abort immediately.
14
+ */
15
+ export const RETRYABLE_CODES = new Set([
16
+ 'ECONNREFUSED',
17
+ 'ECONNRESET',
18
+ 'ETIMEDOUT',
19
+ 'ENOTFOUND',
20
+ 'EAI_AGAIN',
21
+ ]);
22
+ /** Logger context tag for this package. */
23
+ export const LOGGER_CONTEXT = 'MongooseModule';
24
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAA;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC1D,cAAc;IACd,YAAY;IACZ,WAAW;IACX,WAAW;IACX,WAAW;CACZ,CAAC,CAAA;AAEF,2CAA2C;AAC3C,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type mongoose from 'mongoose';
2
+ export type ModelToken<T> = (new () => mongoose.Model<T>) & {
3
+ readonly modelName: string;
4
+ readonly schema: mongoose.Schema<T>;
5
+ readonly __miiaMongooseModel: true;
6
+ };
7
+ export declare function defineModel<T>(name: string, schema: mongoose.Schema<T>): ModelToken<T>;
8
+ //# sourceMappingURL=define-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-model.d.ts","sourceRoot":"","sources":["../src/define-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAEpC,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACnC,QAAQ,CAAC,mBAAmB,EAAE,IAAI,CAAA;CACnC,CAAA;AAMD,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAQtF"}
@@ -0,0 +1,14 @@
1
+ // defineModel не мемоізується: identity = export site (один раз на модель).
2
+ // Повторний defineModel('User', schema) свідомо створює окремий токен -
3
+ // для multi-connection use-case. Колізія імен моделей ловиться runtime у
4
+ // MongooseService.onInit, cross-registry колізія - через console.warn у register().
5
+ export function defineModel(name, schema) {
6
+ const Token = class {
7
+ static modelName = name;
8
+ static schema = schema;
9
+ static __miiaMongooseModel = true;
10
+ };
11
+ Object.defineProperty(Token, 'name', { value: `MongooseModel(${name})` });
12
+ return Token;
13
+ }
14
+ //# sourceMappingURL=define-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-model.js","sourceRoot":"","sources":["../src/define-model.ts"],"names":[],"mappings":"AAQA,4EAA4E;AAC5E,wEAAwE;AACxE,yEAAyE;AACzE,oFAAoF;AACpF,MAAM,UAAU,WAAW,CAAI,IAAY,EAAE,MAA0B;IACrE,MAAM,KAAK,GAAG;QACZ,MAAM,CAAC,SAAS,GAAG,IAAI,CAAA;QACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;QACtB,MAAM,CAAC,mBAAmB,GAAG,IAAa,CAAA;KAC3C,CAAA;IACD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,iBAAiB,IAAI,GAAG,EAAE,CAAC,CAAA;IACzE,OAAO,KAAiC,CAAA;AAC1C,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { MongooseModule } from './mongoose.module.js';
2
+ export { defineModel } from './define-model.js';
3
+ export { mongooseConnection } from './tokens.js';
4
+ export type { MongooseModuleOptions, ModelToken, MongooseConnectionToken } from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,YAAY,EAAE,qBAAqB,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { MongooseModule } from './mongoose.module.js';
2
+ export { defineModel } from './define-model.js';
3
+ export { mongooseConnection } from './tokens.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { ConfiguredModule, OptionsOrFactory } from '@miiajs/core';
2
+ import type { MongooseModuleOptions } from './types.js';
3
+ import type { ModelToken } from './define-model.js';
4
+ export declare class MongooseModule {
5
+ static configure(optionsOrFactory: OptionsOrFactory<MongooseModuleOptions>, name?: string): ConfiguredModule;
6
+ static register(models: ModelToken<any>[], name?: string): ConfiguredModule;
7
+ }
8
+ //# sourceMappingURL=mongoose.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose.module.d.ts","sourceRoot":"","sources":["../src/mongoose.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAgC,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAGpG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AA4FnD,qBAAa,cAAc;IACzB,MAAM,CAAC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB;IAgC5G,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB;CA8B5E"}
@@ -0,0 +1,139 @@
1
+ import { resolveOptions } from '@miiajs/core';
2
+ import { MongooseService } from './mongoose.service.js';
3
+ import { getInternalServiceToken, getRegistryToken, mongooseConnection } from './tokens.js';
4
+ // ─── Lazy proxies ────────────────────────────────────────────────────────────
5
+ // MongooseService.onInit happens AFTER provider factories run, so we can't
6
+ // return a real Connection / Model from the factory. Proxy defers underlying
7
+ // lookup until first property access.
8
+ function createLazyProxy(get) {
9
+ let cached;
10
+ const resolve = () => (cached ??= get());
11
+ return new Proxy({}, {
12
+ get(_, prop) {
13
+ const target = resolve();
14
+ const value = target[prop];
15
+ return typeof value === 'function' ? value.bind(target) : value;
16
+ },
17
+ has(_, prop) {
18
+ return prop in resolve();
19
+ },
20
+ ownKeys() {
21
+ return Reflect.ownKeys(resolve());
22
+ },
23
+ getOwnPropertyDescriptor(_, prop) {
24
+ return Object.getOwnPropertyDescriptor(resolve(), prop);
25
+ },
26
+ });
27
+ }
28
+ // Mongoose-specific Model proxy: callable target so we can intercept `new`
29
+ // (mongoose's `new User({...})` document idiom) and forwards prototype lookup
30
+ // so `doc instanceof UserModel` keeps working.
31
+ function createMongooseModelProxy(get) {
32
+ let cached;
33
+ const resolve = () => (cached ??= get());
34
+ // Wrap a function so the proxy is callable / constructable, matching mongoose's runtime shape.
35
+ const target = function () { };
36
+ return new Proxy(target, {
37
+ get(_, prop) {
38
+ const model = resolve();
39
+ const value = model[prop];
40
+ return typeof value === 'function' ? value.bind(model) : value;
41
+ },
42
+ has(_, prop) {
43
+ return prop in resolve();
44
+ },
45
+ ownKeys() {
46
+ return Reflect.ownKeys(resolve());
47
+ },
48
+ getOwnPropertyDescriptor(_, prop) {
49
+ return Object.getOwnPropertyDescriptor(resolve(), prop);
50
+ },
51
+ getPrototypeOf() {
52
+ return Object.getPrototypeOf(resolve());
53
+ },
54
+ construct(_, args) {
55
+ const ModelCtor = resolve();
56
+ return new ModelCtor(...args);
57
+ },
58
+ });
59
+ }
60
+ // ─── Cross-connection collision warning ──────────────────────────────────────
61
+ const seenTokens = new WeakMap();
62
+ function checkCrossConnectionCollision(models, conn) {
63
+ for (const token of models) {
64
+ const previous = seenTokens.get(token);
65
+ if (previous !== undefined && previous !== conn) {
66
+ const fmt = (n) => (n === '' ? 'default' : n);
67
+ console.warn(`[Miia/Mongoose] Token ${token.name} registered in connections "${fmt(previous)}" and "${fmt(conn)}". ` +
68
+ `Use a separate defineModel(...) per connection.`);
69
+ }
70
+ seenTokens.set(token, conn);
71
+ }
72
+ }
73
+ // ─── Friendly error helper ───────────────────────────────────────────────────
74
+ function configureMissingError(name, suffix) {
75
+ return new Error(`[Miia/Mongoose] ${suffix} ` +
76
+ `MongooseModule.configure() is missing in the root module${name ? ` for connection "${name}"` : ''}.`);
77
+ }
78
+ // ─── MongooseModule ──────────────────────────────────────────────────────────
79
+ export class MongooseModule {
80
+ static configure(optionsOrFactory, name) {
81
+ const serviceToken = getInternalServiceToken(name);
82
+ const registryToken = getRegistryToken(name);
83
+ const connToken = mongooseConnection(name);
84
+ const ModuleClass = name ? class MongooseNamedModule {
85
+ } : MongooseModule;
86
+ return {
87
+ module: ModuleClass,
88
+ providers: [
89
+ {
90
+ token: registryToken,
91
+ factory: () => new Map(),
92
+ },
93
+ {
94
+ token: serviceToken,
95
+ factory: (resolve) => {
96
+ const options = resolveOptions(optionsOrFactory, { resolve });
97
+ const registry = resolve(registryToken);
98
+ return new MongooseService(options, registry);
99
+ },
100
+ },
101
+ {
102
+ token: connToken,
103
+ factory: (resolve) => {
104
+ return createLazyProxy(() => resolve(serviceToken).connection);
105
+ },
106
+ },
107
+ ],
108
+ };
109
+ }
110
+ static register(models, name) {
111
+ const serviceToken = getInternalServiceToken(name);
112
+ const registryToken = getRegistryToken(name);
113
+ const conn = name ?? '';
114
+ checkCrossConnectionCollision(models, conn);
115
+ const FeatureModule = class MongooseFeatureModule {
116
+ };
117
+ const providers = models.map((token) => ({
118
+ token,
119
+ factory: (resolve) => {
120
+ let service;
121
+ let registry;
122
+ try {
123
+ service = resolve(serviceToken);
124
+ registry = resolve(registryToken);
125
+ }
126
+ catch {
127
+ throw configureMissingError(name, `inject(${token.name}) failed:`);
128
+ }
129
+ registry.set(token, token);
130
+ return createMongooseModelProxy(() => service.getModel(token));
131
+ },
132
+ }));
133
+ return {
134
+ module: FeatureModule,
135
+ providers,
136
+ };
137
+ }
138
+ }
139
+ //# sourceMappingURL=mongoose.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose.module.js","sourceRoot":"","sources":["../src/mongoose.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAI7C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE3F,gFAAgF;AAChF,2EAA2E;AAC3E,6EAA6E;AAC7E,sCAAsC;AAEtC,SAAS,eAAe,CAAmB,GAAY;IACrD,IAAI,MAAqB,CAAA;IACzB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAA;IACxC,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE;QACxB,GAAG,CAAC,CAAC,EAAE,IAAI;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AC,CAAA;QAClD,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;QAEvB,6BAA6B,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAE3C,MAAM,aAAa,GAAG,MAAM,qBAAqB;SAAkB,CAAA;QAEnE,MAAM,SAAS,GAAsB,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC1D,KAAK;YACL,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;gBACnB,IAAI,OAAwB,CAAA;gBAC5B,IAAI,QAA+C,CAAA;gBACnD,IAAI,CAAC;oBACH,OAAO,GAAG,OAAO,CAAkB,YAAY,CAAC,CAAA;oBAChD,QAAQ,GAAG,OAAO,CAAwC,aAAa,CAAC,CAAA;gBAC1E,CAAC;gBAAC,MAAM,CAAC;oBACP,MAAM,qBAAqB,CAAC,IAAI,EAAE,UAAU,KAAK,CAAC,IAAI,WAAW,CAAC,CAAA;gBACpE,CAAC;gBACD,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;gBAC1B,OAAO,wBAAwB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;YAChE,CAAC;SACF,CAAC,CAAC,CAAA;QAEH,OAAO;YACL,MAAM,EAAE,aAAa;YACrB,SAAS;SACV,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import type mongoose from 'mongoose';
2
+ import type { MongooseModuleOptions } from './types.js';
3
+ import type { ModelToken } from './define-model.js';
4
+ /**
5
+ * Internal lifecycle owner for a MongooseModule connection. NOT exported from
6
+ * the package index. Users interact with @miiajs/mongoose through `inject(User)`
7
+ * / `inject(mongooseConnection())` only.
8
+ */
9
+ export declare class MongooseService {
10
+ private readonly options;
11
+ private readonly registry;
12
+ private logger;
13
+ private _connection;
14
+ private _models;
15
+ constructor(options: MongooseModuleOptions, registry: Map<ModelToken<any>, ModelToken<any>>);
16
+ get connection(): mongoose.Connection;
17
+ getModel(token: ModelToken<any>): mongoose.Model<any>;
18
+ onInit(): Promise<void>;
19
+ onDestroy(): Promise<void>;
20
+ private assertNoModelNameCollision;
21
+ }
22
+ //# sourceMappingURL=mongoose.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose.service.d.ts","sourceRoot":"","sources":["../src/mongoose.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD;;;;GAIG;AACH,qBAAa,eAAe;IAMxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAN3B,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,OAAO,CAAkD;gBAG9C,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAGlE,IAAI,UAAU,IAAI,QAAQ,CAAC,UAAU,CAKpC;IAED,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC;IAW/C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAgDvB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAUhC,OAAO,CAAC,0BAA0B;CAcnC"}
@@ -0,0 +1,95 @@
1
+ import { Logger } from '@miiajs/core';
2
+ import { closeConnection, createConnection } from './connection.js';
3
+ import { DEFAULT_RETRY_ATTEMPTS, DEFAULT_RETRY_DELAY, LOGGER_CONTEXT, RETRYABLE_CODES } from './constants.js';
4
+ /**
5
+ * Internal lifecycle owner for a MongooseModule connection. NOT exported from
6
+ * the package index. Users interact with @miiajs/mongoose through `inject(User)`
7
+ * / `inject(mongooseConnection())` only.
8
+ */
9
+ export class MongooseService {
10
+ options;
11
+ registry;
12
+ logger = new Logger(LOGGER_CONTEXT);
13
+ _connection = null;
14
+ _models = new Map();
15
+ constructor(options, registry) {
16
+ this.options = options;
17
+ this.registry = registry;
18
+ }
19
+ get connection() {
20
+ if (!this._connection) {
21
+ throw new Error('[Miia/Mongoose] Not connected. Ensure app.init() was called.');
22
+ }
23
+ return this._connection;
24
+ }
25
+ getModel(token) {
26
+ const m = this._models.get(token);
27
+ if (!m) {
28
+ throw new Error(`[Miia/Mongoose] Model "${token.modelName}" not initialized. ` +
29
+ `Did you forget to register it with MongooseModule.register([${token.name}])?`);
30
+ }
31
+ return m;
32
+ }
33
+ async onInit() {
34
+ this.assertNoModelNameCollision();
35
+ const attempts = this.options.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS;
36
+ const delay = this.options.retry?.delay ?? DEFAULT_RETRY_DELAY;
37
+ for (let i = 1; i <= attempts; i++) {
38
+ let connection = null;
39
+ try {
40
+ connection = await createConnection(this.options.uri, this.logger, this.options.connectionOptions);
41
+ this._connection = connection;
42
+ for (const token of this.registry.values()) {
43
+ const compiled = connection.model(token.modelName, token.schema);
44
+ this._models.set(token, compiled);
45
+ }
46
+ this.logger.log('Connected to MongoDB');
47
+ return;
48
+ }
49
+ catch (error) {
50
+ // Resource leak fix: close connection if it succeeded but a later
51
+ // step (model compilation) failed.
52
+ if (connection) {
53
+ try {
54
+ await closeConnection(connection);
55
+ }
56
+ catch {
57
+ // swallow - we're already in an error path
58
+ }
59
+ this._connection = null;
60
+ this._models.clear();
61
+ }
62
+ const code = error?.code ?? error?.cause?.code;
63
+ const retryable = code && RETRYABLE_CODES.has(code);
64
+ if (!retryable || i === attempts) {
65
+ this.logger.error(retryable ? `Failed to connect after ${attempts} attempts` : `Connection failed: ${error.message}`, error.stack);
66
+ throw error;
67
+ }
68
+ this.logger.error(`MongoDB connection failed. Retrying (${i}/${attempts})...`);
69
+ await new Promise((r) => setTimeout(r, delay));
70
+ }
71
+ }
72
+ }
73
+ async onDestroy() {
74
+ this.logger.log('Disconnecting from MongoDB...');
75
+ if (this._connection) {
76
+ await closeConnection(this._connection);
77
+ }
78
+ this._connection = null;
79
+ this._models.clear();
80
+ this.logger.log('Disconnected from MongoDB');
81
+ }
82
+ assertNoModelNameCollision() {
83
+ const seen = new Map();
84
+ for (const token of this.registry.values()) {
85
+ const previous = seen.get(token.modelName);
86
+ if (previous && previous !== token) {
87
+ throw new Error(`[Miia/Mongoose] Two distinct ModelToken-s registered for the same model name ` +
88
+ `"${token.modelName}" on the same connection. ` +
89
+ `Each model must be defined once per connection.`);
90
+ }
91
+ seen.set(token.modelName, token);
92
+ }
93
+ }
94
+ }
95
+ //# sourceMappingURL=mongoose.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose.service.js","sourceRoot":"","sources":["../src/mongoose.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE7G;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAMP;IACA;IANX,MAAM,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAAA;IACnC,WAAW,GAA+B,IAAI,CAAA;IAC9C,OAAO,GAAG,IAAI,GAAG,EAAwC,CAAA;IAEjE,YACmB,OAA8B,EAC9B,QAA+C;QAD/C,YAAO,GAAP,OAAO,CAAuB;QAC9B,aAAQ,GAAR,QAAQ,CAAuC;IAC/D,CAAC;IAEJ,IAAI,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,WAAW,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E,CAAC;YACrB,MAAM,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACzC,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;QACpB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IAC9C,CAAC;IAEO,0BAA0B;QAChC,MAAM,IAAI,GAAG,IAAI,GAAG,EAA2B,CAAA;QAC/C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;YAC1C,IAAI,QAAQ,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CACb,+EAA+E;oBAC7E,IAAI,KAAK,CAAC,SAAS,4BAA4B;oBAC/C,iDAAiD,CACpD,CAAA;YACH,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import type mongoose from 'mongoose';
2
+ export type MongooseConnectionToken = new () => mongoose.Connection;
3
+ /**
4
+ * Returns a typed DI token for the raw `mongoose.Connection` of a MongooseModule connection.
5
+ *
6
+ * - `mongooseConnection()` - default connection.
7
+ * - `mongooseConnection('analytics')` - named connection.
8
+ *
9
+ * Memoized by name: the same name always returns the same token,
10
+ * so DI identity is stable across modules.
11
+ */
12
+ export declare function mongooseConnection(name?: string): MongooseConnectionToken;
13
+ export declare function getInternalServiceToken(name?: string): string;
14
+ export declare function getRegistryToken(name?: string): string;
15
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAEpC,MAAM,MAAM,uBAAuB,GAAG,UAAU,QAAQ,CAAC,UAAU,CAAA;AAInE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAUzE;AAID,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtD"}
package/dist/tokens.js ADDED
@@ -0,0 +1,29 @@
1
+ const cache = new Map();
2
+ /**
3
+ * Returns a typed DI token for the raw `mongoose.Connection` of a MongooseModule connection.
4
+ *
5
+ * - `mongooseConnection()` - default connection.
6
+ * - `mongooseConnection('analytics')` - named connection.
7
+ *
8
+ * Memoized by name: the same name always returns the same token,
9
+ * so DI identity is stable across modules.
10
+ */
11
+ export function mongooseConnection(name) {
12
+ const key = name ?? '';
13
+ let cls = cache.get(key);
14
+ if (!cls) {
15
+ cls = class {
16
+ static __name = `mongooseConnection(${name ?? 'default'})`;
17
+ };
18
+ cache.set(key, cls);
19
+ }
20
+ return cls;
21
+ }
22
+ // ─── Internal token helpers (not exported from package index) ─────────────
23
+ export function getInternalServiceToken(name) {
24
+ return name ? `__MONGOOSE_SERVICE_${name}` : '__MONGOOSE_SERVICE';
25
+ }
26
+ export function getRegistryToken(name) {
27
+ return name ? `__MONGOOSE_REGISTRY_${name}` : '__MONGOOSE_REGISTRY';
28
+ }
29
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAIA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmC,CAAA;AAExD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAa;IAC9C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACxB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG;YACJ,MAAM,CAAU,MAAM,GAAG,sBAAsB,IAAI,IAAI,SAAS,GAAG,CAAA;SAC9B,CAAA;QACvC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,6EAA6E;AAE7E,MAAM,UAAU,uBAAuB,CAAC,IAAa;IACnD,OAAO,IAAI,CAAC,CAAC,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAA;AACrE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type mongoose from 'mongoose';
2
+ export interface MongooseModuleOptions {
3
+ uri: string;
4
+ connectionOptions?: mongoose.ConnectOptions;
5
+ retry?: {
6
+ attempts?: number;
7
+ delay?: number;
8
+ };
9
+ }
10
+ export type { ModelToken } from './define-model.js';
11
+ export type { MongooseConnectionToken } from './tokens.js';
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAEpC,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,iBAAiB,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAA;IAC3C,KAAK,CAAC,EAAE;QACN,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@miiajs/mongoose",
3
+ "version": "0.1.0",
4
+ "author": "Ruslan Matiushev",
5
+ "license": "MIT",
6
+ "description": "MongoDB integration for MiiaJS via Mongoose.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/miiajs/miia.git",
10
+ "directory": "packages/mongoose"
11
+ },
12
+ "homepage": "https://github.com/miiajs/miia/tree/main/packages/mongoose#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/miiajs/miia/issues"
15
+ },
16
+ "keywords": [
17
+ "miiajs",
18
+ "miia",
19
+ "mongoose",
20
+ "mongodb",
21
+ "odm"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "sideEffects": false,
41
+ "engines": {
42
+ "node": ">=22.22.1",
43
+ "bun": ">=1.3.11",
44
+ "deno": ">=2.6.1"
45
+ },
46
+ "dependencies": {
47
+ "@miiajs/core": "workspace:*"
48
+ },
49
+ "peerDependencies": {
50
+ "mongoose": "^9.4.1"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc --build",
54
+ "clean": "tsc --build --clean"
55
+ },
56
+ "devDependencies": {
57
+ "mongoose": "^9.4.1"
58
+ }
59
+ }