@digitaldefiance/node-express-suite 3.12.16 → 3.13.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.
Files changed (53) hide show
  1. package/package.json +2 -1
  2. package/src/application-base.d.ts +50 -47
  3. package/src/application-base.d.ts.map +1 -1
  4. package/src/application-base.js +180 -229
  5. package/src/application-base.js.map +1 -1
  6. package/src/application.d.ts +2 -1
  7. package/src/application.d.ts.map +1 -1
  8. package/src/application.js +8 -4
  9. package/src/application.js.map +1 -1
  10. package/src/index.d.ts +1 -0
  11. package/src/index.d.ts.map +1 -1
  12. package/src/index.js +3 -1
  13. package/src/index.js.map +1 -1
  14. package/src/interfaces/document-store.d.ts +38 -0
  15. package/src/interfaces/document-store.d.ts.map +1 -0
  16. package/src/interfaces/document-store.js +8 -0
  17. package/src/interfaces/document-store.js.map +1 -0
  18. package/src/interfaces/failable-result.d.ts +2 -15
  19. package/src/interfaces/failable-result.d.ts.map +1 -1
  20. package/src/interfaces/failable-result.js +0 -5
  21. package/src/interfaces/failable-result.js.map +1 -1
  22. package/src/interfaces/index.d.ts +1 -0
  23. package/src/interfaces/index.d.ts.map +1 -1
  24. package/src/interfaces/index.js +1 -0
  25. package/src/interfaces/index.js.map +1 -1
  26. package/src/services/index.d.ts +4 -0
  27. package/src/services/index.d.ts.map +1 -1
  28. package/src/services/index.js +4 -0
  29. package/src/services/index.js.map +1 -1
  30. package/src/services/mongoose-collection.d.ts +52 -0
  31. package/src/services/mongoose-collection.d.ts.map +1 -0
  32. package/src/services/mongoose-collection.js +326 -0
  33. package/src/services/mongoose-collection.js.map +1 -0
  34. package/src/services/mongoose-database.d.ts +64 -0
  35. package/src/services/mongoose-database.d.ts.map +1 -0
  36. package/src/services/mongoose-database.js +121 -0
  37. package/src/services/mongoose-database.js.map +1 -0
  38. package/src/services/mongoose-document-store.d.ts +109 -0
  39. package/src/services/mongoose-document-store.d.ts.map +1 -0
  40. package/src/services/mongoose-document-store.js +264 -0
  41. package/src/services/mongoose-document-store.js.map +1 -0
  42. package/src/services/mongoose-session-adapter.d.ts +39 -0
  43. package/src/services/mongoose-session-adapter.d.ts.map +1 -0
  44. package/src/services/mongoose-session-adapter.js +63 -0
  45. package/src/services/mongoose-session-adapter.js.map +1 -0
  46. package/src/utils/default-mongo-uri-validator.d.ts +15 -0
  47. package/src/utils/default-mongo-uri-validator.d.ts.map +1 -0
  48. package/src/utils/default-mongo-uri-validator.js +46 -0
  49. package/src/utils/default-mongo-uri-validator.js.map +1 -0
  50. package/src/utils.d.ts +21 -2
  51. package/src/utils.d.ts.map +1 -1
  52. package/src/utils.js +124 -49
  53. package/src/utils.js.map +1 -1
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @fileoverview Mongoose database adapter implementing IDatabase.
3
+ * Wraps a mongoose connection to conform to the shared IDatabase interface
4
+ * from brightchain-lib, enabling application code to work with mongoose
5
+ * through the unified database contract.
6
+ * @module services/mongoose-database
7
+ */
8
+ import type { BsonDocument, CollectionOptions, IClientSession, ICollection, IDatabase } from '@brightchain/brightchain-lib';
9
+ import type { Connection } from '@digitaldefiance/mongoose-types';
10
+ /**
11
+ * Adapts a mongoose connection to the IDatabase interface.
12
+ * Allows existing mongoose-based applications to use the unified
13
+ * IDatabase contract from brightchain-lib.
14
+ */
15
+ export declare class MongooseDatabase implements IDatabase {
16
+ private _connection;
17
+ /**
18
+ * @param connection - Optional mongoose connection to wrap.
19
+ * Defaults to the global mongoose.connection if not provided.
20
+ */
21
+ constructor(connection?: Connection);
22
+ /**
23
+ * Get the underlying mongoose connection for direct access when needed.
24
+ */
25
+ get connection(): Connection;
26
+ /**
27
+ * Connect to MongoDB via mongoose.
28
+ * If a URI is provided, establishes a new connection.
29
+ * If already connected, this is a no-op.
30
+ */
31
+ connect(uri?: string): Promise<void>;
32
+ /**
33
+ * Disconnect from MongoDB.
34
+ */
35
+ disconnect(): Promise<void>;
36
+ /**
37
+ * Whether the mongoose connection is in the 'connected' state.
38
+ */
39
+ isConnected(): boolean;
40
+ /**
41
+ * Get or create a collection by name, returning an ICollection adapter.
42
+ */
43
+ collection<T extends BsonDocument = BsonDocument>(name: string, _options?: CollectionOptions): ICollection<T>;
44
+ /**
45
+ * Start a client session for transaction support.
46
+ * Wraps the mongoose session in an IClientSession adapter.
47
+ */
48
+ startSession(): IClientSession;
49
+ /**
50
+ * Execute a callback within a mongoose transaction with retry logic.
51
+ * Handles session lifecycle: start → transaction → commit/abort → end.
52
+ */
53
+ withTransaction<R>(fn: (session: IClientSession) => Promise<R>): Promise<R>;
54
+ /**
55
+ * List all collection names known to this connection.
56
+ */
57
+ listCollections(): string[];
58
+ /**
59
+ * Drop a collection by name.
60
+ * @returns true if the collection was dropped, false if it didn't exist.
61
+ */
62
+ dropCollection(name: string): Promise<boolean>;
63
+ }
64
+ //# sourceMappingURL=mongoose-database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-database.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/services/mongoose-database.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,SAAS,EACV,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAIlE;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAChD,OAAO,CAAC,WAAW,CAAa;IAEhC;;;OAGG;gBACS,UAAU,CAAC,EAAE,UAAU;IAInC;;OAEG;IACH,IAAI,UAAU,IAAI,UAAU,CAE3B;IAED;;;;OAIG;IACG,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,UAAU,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAC9C,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,WAAW,CAAC,CAAC,CAAC;IAIjB;;;OAGG;IACH,YAAY,IAAI,cAAc;IAW9B;;;OAGG;IACG,eAAe,CAAC,CAAC,EACrB,EAAE,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC;IAeb;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;;OAGG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAQrD"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Mongoose database adapter implementing IDatabase.
4
+ * Wraps a mongoose connection to conform to the shared IDatabase interface
5
+ * from brightchain-lib, enabling application code to work with mongoose
6
+ * through the unified database contract.
7
+ * @module services/mongoose-database
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MongooseDatabase = void 0;
11
+ const tslib_1 = require("tslib");
12
+ const mongoose_types_1 = tslib_1.__importDefault(require("@digitaldefiance/mongoose-types"));
13
+ const mongoose_collection_1 = require("./mongoose-collection");
14
+ const mongoose_session_adapter_1 = require("./mongoose-session-adapter");
15
+ /**
16
+ * Adapts a mongoose connection to the IDatabase interface.
17
+ * Allows existing mongoose-based applications to use the unified
18
+ * IDatabase contract from brightchain-lib.
19
+ */
20
+ class MongooseDatabase {
21
+ _connection;
22
+ /**
23
+ * @param connection - Optional mongoose connection to wrap.
24
+ * Defaults to the global mongoose.connection if not provided.
25
+ */
26
+ constructor(connection) {
27
+ this._connection = connection ?? mongoose_types_1.default.connection;
28
+ }
29
+ /**
30
+ * Get the underlying mongoose connection for direct access when needed.
31
+ */
32
+ get connection() {
33
+ return this._connection;
34
+ }
35
+ /**
36
+ * Connect to MongoDB via mongoose.
37
+ * If a URI is provided, establishes a new connection.
38
+ * If already connected, this is a no-op.
39
+ */
40
+ async connect(uri) {
41
+ if (uri) {
42
+ await mongoose_types_1.default.connect(uri);
43
+ this._connection = mongoose_types_1.default.connection;
44
+ }
45
+ }
46
+ /**
47
+ * Disconnect from MongoDB.
48
+ */
49
+ async disconnect() {
50
+ if (this._connection.readyState !== 0) {
51
+ await mongoose_types_1.default.disconnect();
52
+ }
53
+ }
54
+ /**
55
+ * Whether the mongoose connection is in the 'connected' state.
56
+ */
57
+ isConnected() {
58
+ return this._connection.readyState === 1;
59
+ }
60
+ /**
61
+ * Get or create a collection by name, returning an ICollection adapter.
62
+ */
63
+ collection(name, _options) {
64
+ return new mongoose_collection_1.MongooseCollection(this._connection, name);
65
+ }
66
+ /**
67
+ * Start a client session for transaction support.
68
+ * Wraps the mongoose session in an IClientSession adapter.
69
+ */
70
+ startSession() {
71
+ // mongoose.connection.startSession() is async, but IDatabase declares
72
+ // startSession() as synchronous. We create a deferred session adapter
73
+ // that initializes the native session lazily on first transaction use.
74
+ //
75
+ // For the synchronous contract, we use the underlying client directly.
76
+ const client = this._connection.getClient();
77
+ const nativeSession = client.startSession();
78
+ return new mongoose_session_adapter_1.MongooseSessionAdapter(nativeSession);
79
+ }
80
+ /**
81
+ * Execute a callback within a mongoose transaction with retry logic.
82
+ * Handles session lifecycle: start → transaction → commit/abort → end.
83
+ */
84
+ async withTransaction(fn) {
85
+ const adapter = this.startSession();
86
+ adapter.startTransaction();
87
+ try {
88
+ const result = await fn(adapter);
89
+ await adapter.commitTransaction();
90
+ return result;
91
+ }
92
+ catch (err) {
93
+ await adapter.abortTransaction();
94
+ throw err;
95
+ }
96
+ finally {
97
+ adapter.endSession();
98
+ }
99
+ }
100
+ /**
101
+ * List all collection names known to this connection.
102
+ */
103
+ listCollections() {
104
+ return Object.keys(this._connection.collections);
105
+ }
106
+ /**
107
+ * Drop a collection by name.
108
+ * @returns true if the collection was dropped, false if it didn't exist.
109
+ */
110
+ async dropCollection(name) {
111
+ try {
112
+ await this._connection.dropCollection(name);
113
+ return true;
114
+ }
115
+ catch {
116
+ return false;
117
+ }
118
+ }
119
+ }
120
+ exports.MongooseDatabase = MongooseDatabase;
121
+ //# sourceMappingURL=mongoose-database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-database.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/services/mongoose-database.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;AASH,6FAAuD;AAEvD,+DAA2D;AAC3D,yEAAoE;AAEpE;;;;GAIG;AACH,MAAa,gBAAgB;IACnB,WAAW,CAAa;IAEhC;;;OAGG;IACH,YAAY,UAAuB;QACjC,IAAI,CAAC,WAAW,GAAG,UAAU,IAAI,wBAAQ,CAAC,UAAU,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,GAAY;QACxB,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,wBAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,wBAAQ,CAAC,UAAU,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,WAAW,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;YACtC,MAAM,wBAAQ,CAAC,UAAU,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,UAAU,CACR,IAAY,EACZ,QAA4B;QAE5B,OAAO,IAAI,wCAAkB,CAAI,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,sEAAsE;QACtE,sEAAsE;QACtE,uEAAuE;QACvE,EAAE;QACF,uEAAuE;QACvE,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAC5C,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;QAC5C,OAAO,IAAI,iDAAsB,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CACnB,EAA2C;QAE3C,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACpC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC3B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;YACjC,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAClC,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;YACjC,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc,CAAC,IAAY;QAC/B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AA/GD,4CA+GC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @fileoverview Mongoose implementation of the IDocumentStore interface.
3
+ * Wraps existing mongoose logic previously embedded in BaseApplication.
4
+ * @module services/mongoose-document-store
5
+ */
6
+ import mongoose, { Model } from '@digitaldefiance/mongoose-types';
7
+ import { MongoMemoryReplSet } from 'mongodb-memory-server';
8
+ import { IBaseDocument } from '../documents/base';
9
+ import { Environment } from '../environment';
10
+ import { IApplication } from '../interfaces/application';
11
+ import { IConstants } from '../interfaces/constants';
12
+ import { IDocumentStore } from '../interfaces/document-store';
13
+ import { IFailableResult } from '../interfaces/failable-result';
14
+ import { SchemaMap } from '../types';
15
+ import type { PlatformID } from '@digitaldefiance/node-ecies-lib';
16
+ import type { BaseApplication } from '../application-base';
17
+ /**
18
+ * Mongoose implementation of IDocumentStore.
19
+ * Extracts and preserves the existing mongoose logic from BaseApplication.
20
+ * @template TID - Platform-specific ID type extending PlatformID
21
+ * @template TModelDocs - Record mapping model names to their document types
22
+ * @template TInitResults - Type of database initialization results
23
+ * @template TConstants - Application constants type
24
+ */
25
+ export declare class MongooseDocumentStore<TID extends PlatformID, TModelDocs extends Record<string, IBaseDocument<any, TID>>, TInitResults, TConstants extends IConstants = IConstants> implements IDocumentStore<TID, TModelDocs> {
26
+ /**
27
+ * Mongoose database instance
28
+ */
29
+ private _db?;
30
+ /**
31
+ * Schema map for all models
32
+ */
33
+ private _schemaMap?;
34
+ /**
35
+ * In-memory MongoDB instance for development
36
+ */
37
+ private _devDatabase?;
38
+ /**
39
+ * Function to create the schema map given a Mongoose connection
40
+ */
41
+ private readonly _schemaMapFactory;
42
+ /**
43
+ * Function to initialize the database with default data
44
+ */
45
+ private readonly _databaseInitFunction;
46
+ /**
47
+ * Function to create a hash from the database initialization results (for logging purposes)
48
+ */
49
+ private readonly _initResultHashFunction;
50
+ /**
51
+ * Application environment
52
+ */
53
+ private readonly _environment;
54
+ /**
55
+ * Application constants
56
+ */
57
+ private readonly _constants;
58
+ constructor(schemaMapFactory: (connection: mongoose.Connection) => SchemaMap<TID, TModelDocs>, databaseInitFunction: (application: BaseApplication<TID, TModelDocs, TInitResults>) => Promise<IFailableResult<TInitResults>>, initResultHashFunction: (initResults: TInitResults) => string, environment: Environment<TID>, constants?: TConstants);
59
+ /**
60
+ * Get the underlying mongoose instance (for backward compatibility).
61
+ */
62
+ get db(): typeof mongoose;
63
+ /** @inheritdoc */
64
+ get schemaMap(): SchemaMap<TID, TModelDocs> | undefined;
65
+ /** @inheritdoc */
66
+ get devDatabase(): MongoMemoryReplSet | undefined;
67
+ /**
68
+ * Validate MongoDB URI to prevent SSRF attacks.
69
+ * Delegates to the standalone defaultMongoUriValidator for reuse
70
+ * across both IDatabase and IDocumentStore paths.
71
+ */
72
+ private validateMongoUri;
73
+ /**
74
+ * Connect to MongoDB and initialize schemas.
75
+ * Extracted from BaseApplication.connectDatabase.
76
+ * @inheritdoc
77
+ */
78
+ connect(uri?: string): Promise<void>;
79
+ /**
80
+ * Disconnect from database.
81
+ * Extracted from BaseApplication.disconnectDatabase.
82
+ * @inheritdoc
83
+ */
84
+ disconnect(): Promise<void>;
85
+ /**
86
+ * Whether the store is currently connected and ready for operations.
87
+ * @inheritdoc
88
+ */
89
+ isConnected(): boolean;
90
+ /**
91
+ * Retrieve a model/collection handle by name.
92
+ * Delegates to ModelRegistry.
93
+ * @inheritdoc
94
+ */
95
+ getModel<T extends IBaseDocument<any, TID>>(modelName: string): Model<T>;
96
+ /**
97
+ * Set up an in-memory MongoDB instance for development.
98
+ * Extracted from BaseApplication.setupDevDatabase.
99
+ * @inheritdoc
100
+ */
101
+ setupDevStore(): Promise<string>;
102
+ /**
103
+ * Initialize the development database with default data.
104
+ * Extracted from BaseApplication.initializeDevDatabase.
105
+ * @inheritdoc
106
+ */
107
+ initializeDevStore<TResult = TInitResults>(app: IApplication<TID>): Promise<TResult>;
108
+ }
109
+ //# sourceMappingURL=mongoose-document-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-document-store.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/services/mongoose-document-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,iCA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oose logic previously embedded in BaseApplication.
5
+ * @module services/mongoose-document-store
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.MongooseDocumentStore = void 0;
9
+ const tslib_1 = require("tslib");
10
+ const mongoose_types_1 = tslib_1.__importDefault(require("@digitaldefiance/mongoose-types"));
11
+ const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
12
+ const mongodb_memory_server_1 = require("mongodb-memory-server");
13
+ const model_registry_1 = require("../model-registry");
14
+ const utils_1 = require("../utils");
15
+ const default_mongo_uri_validator_1 = require("../utils/default-mongo-uri-validator");
16
+ /**
17
+ * Mongoose implementation of IDocumentStore.
18
+ * Extracts and preserves the existing mongoose logic from BaseApplication.
19
+ * @template TID - Platform-specific ID type extending PlatformID
20
+ * @template TModelDocs - Record mapping model names to their document types
21
+ * @template TInitResults - Type of database initialization results
22
+ * @template TConstants - Application constants type
23
+ */
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ class MongooseDocumentStore {
26
+ /**
27
+ * Mongoose database instance
28
+ */
29
+ _db;
30
+ /**
31
+ * Schema map for all models
32
+ */
33
+ _schemaMap;
34
+ /**
35
+ * In-memory MongoDB instance for development
36
+ */
37
+ _devDatabase;
38
+ /**
39
+ * Function to create the schema map given a Mongoose connection
40
+ */
41
+ _schemaMapFactory;
42
+ /**
43
+ * Function to initialize the database with default data
44
+ */
45
+ _databaseInitFunction;
46
+ /**
47
+ * Function to create a hash from the database initialization results (for logging purposes)
48
+ */
49
+ _initResultHashFunction;
50
+ /**
51
+ * Application environment
52
+ */
53
+ _environment;
54
+ /**
55
+ * Application constants
56
+ */
57
+ _constants;
58
+ constructor(schemaMapFactory, databaseInitFunction, initResultHashFunction, environment, constants = suite_core_lib_1.Constants) {
59
+ this._schemaMapFactory = schemaMapFactory;
60
+ this._databaseInitFunction = databaseInitFunction;
61
+ this._initResultHashFunction = initResultHashFunction;
62
+ this._environment = environment;
63
+ this._constants = constants;
64
+ }
65
+ /**
66
+ * Get the underlying mongoose instance (for backward compatibility).
67
+ */
68
+ get db() {
69
+ if (!this._db) {
70
+ throw new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_DatabaseNotConnectedYet);
71
+ }
72
+ return this._db;
73
+ }
74
+ /** @inheritdoc */
75
+ get schemaMap() {
76
+ return this._schemaMap;
77
+ }
78
+ /** @inheritdoc */
79
+ get devDatabase() {
80
+ return this._devDatabase;
81
+ }
82
+ /**
83
+ * Validate MongoDB URI to prevent SSRF attacks.
84
+ * Delegates to the standalone defaultMongoUriValidator for reuse
85
+ * across both IDatabase and IDocumentStore paths.
86
+ */
87
+ validateMongoUri(uri) {
88
+ (0, default_mongo_uri_validator_1.defaultMongoUriValidator)(uri, this._environment.production);
89
+ }
90
+ /**
91
+ * Connect to MongoDB and initialize schemas.
92
+ * Extracted from BaseApplication.connectDatabase.
93
+ * @inheritdoc
94
+ */
95
+ async connect(uri) {
96
+ const mongoUri = uri ?? this._environment.mongo.uri;
97
+ const debug = this._environment.debug;
98
+ this.validateMongoUri(mongoUri);
99
+ (0, utils_1.debugLog)(debug, 'log', `[ ${(0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_Connecting, undefined, undefined, { constants: this._constants })} ] ${(0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_MongoDB, undefined, undefined, { constants: this._constants })}: ${mongoUri}`);
100
+ // Always disconnect first to ensure clean state
101
+ if (mongoose_types_1.default.connection.readyState !== 0) {
102
+ await mongoose_types_1.default.disconnect();
103
+ }
104
+ // amazonq-ignore-next-line solved above with validateMongoUri call
105
+ await mongoose_types_1.default.connect(mongoUri, {
106
+ maxPoolSize: this._environment.mongo.maxPoolSize,
107
+ minPoolSize: this._environment.mongo.minPoolSize,
108
+ maxIdleTimeMS: this._environment.mongo.maxIdleTimeMS,
109
+ serverSelectionTimeoutMS: this._environment.mongo.serverSelectionTimeoutMS,
110
+ socketTimeoutMS: this._environment.mongo.socketTimeoutMS,
111
+ retryWrites: this._environment.mongo.retryWrites,
112
+ retryReads: this._environment.mongo.retryReads,
113
+ readConcern: this._environment.mongo.readConcern,
114
+ writeConcern: this._environment.mongo.writeConcern,
115
+ });
116
+ this._db = mongoose_types_1.default;
117
+ await new Promise((resolve) => {
118
+ if (mongoose_types_1.default.connection.readyState === 1) {
119
+ resolve();
120
+ }
121
+ else {
122
+ mongoose_types_1.default.connection.once('connected', resolve);
123
+ }
124
+ });
125
+ const engine = (0, suite_core_lib_1.getSuiteCoreI18nEngine)({ constants: this._constants });
126
+ (0, utils_1.debugLog)(debug, 'log', engine.t('[ {{SuiteCoreStringKey.Common_Connected}} ] {{SuiteCoreStringKey.Common_MongoDB}}'));
127
+ (0, utils_1.debugLog)(debug, 'log', engine.t('[ {{SuiteCoreStringKey.Common_Loading}} ] {{SuiteCoreStringKey.Common_Schemas}}'));
128
+ this._schemaMap = this._schemaMapFactory(this.db.connection);
129
+ // Register all base models in ModelRegistry for extensibility
130
+ if (this._schemaMap) {
131
+ Object.values(this._schemaMap).forEach((schema) => {
132
+ model_registry_1.ModelRegistry.instance.register({
133
+ modelName: schema.modelName,
134
+ schema: schema.schema,
135
+ model: schema.model,
136
+ collection: schema.collection,
137
+ discriminators: schema.discriminators,
138
+ });
139
+ });
140
+ }
141
+ if (debug) {
142
+ Object.values(this._schemaMap).forEach((schema) => {
143
+ console.log(engine.t(`[ {{SuiteCoreStringKey.Common_Loaded}} ] {{SuiteCoreStringKey.Common_Schema}} '${schema.modelName.replace(/[\r\n]/g, '')}'`));
144
+ });
145
+ }
146
+ if (!this._db.connection.db) {
147
+ console.error(engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_FailedToSetTransactionTimeout));
148
+ }
149
+ else {
150
+ const command = {
151
+ ...(this._environment.mongo.setParameterSupported
152
+ ? { setParameter: 1 }
153
+ : {}),
154
+ ...(this._environment.mongo.useTransactions &&
155
+ this._environment.mongo.transactionLifetimeLimitSecondsSupported
156
+ ? {
157
+ transactionLifetimeLimitSeconds: this._environment.mongo.transactionTimeout,
158
+ }
159
+ : {}),
160
+ ...(this._environment.mongo.useTransactions &&
161
+ this._environment.mongo.maxTransactionLockRequestTimeoutMillisSupported
162
+ ? {
163
+ maxTransactionLockRequestTimeoutMillis: this._environment.mongo.transactionLockRequestTimeout,
164
+ }
165
+ : {}),
166
+ };
167
+ if (Object.keys(command).length > 0) {
168
+ await this._db.connection.db
169
+ .admin()
170
+ .command(command)
171
+ .catch(() => undefined);
172
+ }
173
+ (0, utils_1.debugLog)(debug, 'log', engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Admin_SetTransactionTimeoutSuccessfully));
174
+ }
175
+ }
176
+ /**
177
+ * Disconnect from database.
178
+ * Extracted from BaseApplication.disconnectDatabase.
179
+ * @inheritdoc
180
+ */
181
+ async disconnect() {
182
+ const debug = this._environment.debug;
183
+ if (this._db && mongoose_types_1.default.connection.readyState !== 0) {
184
+ await this._db.disconnect();
185
+ }
186
+ const engine = (0, suite_core_lib_1.getSuiteCoreI18nEngine)({ constants: this._constants });
187
+ this._db = undefined;
188
+ (0, utils_1.debugLog)(debug, 'log', `[ ${engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Common_Disconnected)} ] ${engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Common_MongoDB)}`);
189
+ }
190
+ /**
191
+ * Whether the store is currently connected and ready for operations.
192
+ * @inheritdoc
193
+ */
194
+ isConnected() {
195
+ return mongoose_types_1.default.connection.readyState === 1;
196
+ }
197
+ /**
198
+ * Retrieve a model/collection handle by name.
199
+ * Delegates to ModelRegistry.
200
+ * @inheritdoc
201
+ */
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
+ getModel(modelName) {
204
+ return model_registry_1.ModelRegistry.instance.get(modelName).model;
205
+ }
206
+ /**
207
+ * Set up an in-memory MongoDB instance for development.
208
+ * Extracted from BaseApplication.setupDevDatabase.
209
+ * @inheritdoc
210
+ */
211
+ async setupDevStore() {
212
+ this._devDatabase = await mongodb_memory_server_1.MongoMemoryReplSet.create({
213
+ replSet: { count: 1, storageEngine: 'wiredTiger' },
214
+ });
215
+ await this._devDatabase.waitUntilRunning();
216
+ const mongoUri = this._devDatabase.getUri(this._environment.devDatabase) +
217
+ '&maxPoolSize=20&minPoolSize=4';
218
+ this._environment.setEnvironment('mongo.uri', mongoUri);
219
+ (0, utils_1.debugLog)(this._environment.debug, 'log', `MongoDB Memory Server with transactions: ${mongoUri}`);
220
+ return mongoUri;
221
+ }
222
+ /**
223
+ * Initialize the development database with default data.
224
+ * Extracted from BaseApplication.initializeDevDatabase.
225
+ * @inheritdoc
226
+ */
227
+ async initializeDevStore(app) {
228
+ const engine = (0, suite_core_lib_1.getSuiteCoreI18nEngine)({ constants: this._constants });
229
+ (0, utils_1.debugLog)(this._environment.debug, 'log', `${engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Admin_StartingDatabaseInitialization)}: ${engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Admin_TransactionsEnabledDisabledTemplate, {
230
+ STATE: this._environment.mongo.useTransactions
231
+ ? engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Common_Enabled)
232
+ : engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Common_Disabled),
233
+ })}`);
234
+ let initTimeout;
235
+ const initTimeoutMs = 300000;
236
+ const accountDataResult = await Promise.race([
237
+ this._databaseInitFunction(app),
238
+ new Promise((_, reject) => {
239
+ initTimeout = setTimeout(() => {
240
+ const logMsg = engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_FailedToInitializeUserDatabaseTimeoutTemplate, { timeMs: initTimeoutMs.toString() });
241
+ console.error(logMsg);
242
+ reject(new Error(logMsg));
243
+ }, initTimeoutMs);
244
+ }),
245
+ ]);
246
+ if (initTimeout)
247
+ clearTimeout(initTimeout);
248
+ if (accountDataResult.success && accountDataResult.data) {
249
+ if (this._environment.detailedDebug) {
250
+ const initHash = this._initResultHashFunction(accountDataResult.data);
251
+ (0, utils_1.debugLog)(true, 'log', engine.translateStringKey(suite_core_lib_1.SuiteCoreStringKey.Admin_DatabaseInitializedWithOptionsHashTemplate, { hash: initHash }));
252
+ }
253
+ return accountDataResult.data;
254
+ }
255
+ else {
256
+ if (this._environment.detailedDebug && accountDataResult.error) {
257
+ (0, utils_1.debugLog)(true, 'log', accountDataResult.error);
258
+ }
259
+ throw new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_FailedToInitializeUserDatabase);
260
+ }
261
+ }
262
+ }
263
+ exports.MongooseDocumentStore = MongooseDocumentStore;
264
+ //# sourceMappingURL=mongoose-document-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-document-store.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/services/mongoose-document-store.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;AAEH,6FAAkE;AAClE,oEAMyC;AACzC,iEAA2D;AAQ3D,sDAAkD;AAElD,oCAAoC;AACpC,sFAAgF;AAIhF;;;;;;;GAOG;AACH,8DAA8D;AAC9D,MAAa,qBAAqB;IAMhC;;OAEG;IACK,GAAG,CAAmB;IAE9B;;OAEG;IACK,UAAU,CAA8B;IAEhD;;OAEG;IACK,YAAY,CAAsB;IAE1C;;OAEG;IACc,iBAAiB,CAEF;IAEhC;;OAEG;IACc,qBAAqB,CAEM;IAE5C;;OAEG;IACc,uBAAuB,CAE5B;IAEZ;;OAEG;IACc,YAAY,CAAmB;IAEhD;;OAEG;IACc,UAAU,CAAa;IAExC,YACE,gBAE+B,EAC/B,oBAE2C,EAC3C,sBAA6D,EAC7D,WAA6B,EAC7B,YAAwB,0BAAuB;QAE/C,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;QAC1C,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;QAClD,IAAI,CAAC,uBAAuB,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;YACxD,IAAI,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;gBACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACtE,IAAA,gBAAQ,EACN,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,kBAAkB,CACvB,mCAAkB,CAAC,gDAAgD,EACnE,EAAE,IAAI,EAAE,QAAQ,EAAE,CACnB,CACF,CAAC;YACJ,CAAC;YACD,OAAO,iBAAiB,CAAC,IAA0B,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,CAAC,YAAY,CAAC,aAAa,IAAI,iBAAiB,CAAC,KAAK,EAAE,CAAC;gBAC/D,IAAA,gBAAQ,EAAC,IAAI,EAAE,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC;YACjD,CAAC;YACD,MAAM,IAAI,uCAAsB,CAC9B,mCAAkB,CAAC,0CAA0C,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxXD,sDAwXC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Mongoose session adapter implementing IClientSession.
3
+ * Wraps a mongodb ClientSession to conform to the shared IClientSession interface
4
+ * from brightchain-lib.
5
+ * @module services/mongoose-session-adapter
6
+ */
7
+ import type { IClientSession } from '@brightchain/brightchain-lib';
8
+ import type { ClientSession } from 'mongodb';
9
+ /**
10
+ * Adapts a mongodb ClientSession to the IClientSession interface.
11
+ * This allows mongoose-based transaction code to work through the
12
+ * shared interface contract.
13
+ */
14
+ export declare class MongooseSessionAdapter implements IClientSession {
15
+ private readonly _session;
16
+ constructor(session: ClientSession);
17
+ /**
18
+ * Unique session ID as a string.
19
+ * Falls back to 'unknown' if the session has no server session yet.
20
+ */
21
+ get id(): string;
22
+ /**
23
+ * Whether a transaction is currently active on this session.
24
+ */
25
+ get inTransaction(): boolean;
26
+ /**
27
+ * Get the underlying mongodb ClientSession for passing to mongoose operations.
28
+ */
29
+ get nativeSession(): ClientSession;
30
+ /** Start a new transaction on this session. */
31
+ startTransaction(): void;
32
+ /** Commit the current transaction. */
33
+ commitTransaction(): Promise<void>;
34
+ /** Abort the current transaction. */
35
+ abortTransaction(): Promise<void>;
36
+ /** End this session, releasing server resources. */
37
+ endSession(): void;
38
+ }
39
+ //# sourceMappingURL=mongoose-session-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-session-adapter.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/services/mongoose-session-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;gBAE7B,OAAO,EAAE,aAAa;IAIlC;;;OAGG;IACH,IAAI,EAAE,IAAI,MAAM,CAMf;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,aAAa,CAEjC;IAED,+CAA+C;IAC/C,gBAAgB,IAAI,IAAI;IAIxB,sCAAsC;IAChC,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC,qCAAqC;IAC/B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvC,oDAAoD;IACpD,UAAU,IAAI,IAAI;CAKnB"}