@digitaldefiance/node-express-suite 3.18.3 → 4.0.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 (68) hide show
  1. package/README.md +230 -1
  2. package/package.json +1 -1
  3. package/src/__tests__/helpers/setup-test-env.d.ts +2 -1
  4. package/src/__tests__/helpers/setup-test-env.d.ts.map +1 -1
  5. package/src/__tests__/helpers/setup-test-env.js +55 -43
  6. package/src/__tests__/helpers/setup-test-env.js.map +1 -1
  7. package/src/application.d.ts +37 -11
  8. package/src/application.d.ts.map +1 -1
  9. package/src/application.js +106 -27
  10. package/src/application.js.map +1 -1
  11. package/src/{application-base.d.ts → base-application.d.ts} +4 -4
  12. package/src/{application-base.d.ts.map → base-application.d.ts.map} +1 -1
  13. package/src/{application-base.js → base-application.js} +4 -4
  14. package/src/{application-base.js.map → base-application.js.map} +1 -1
  15. package/src/builders/application-builder.d.ts +13 -8
  16. package/src/builders/application-builder.d.ts.map +1 -1
  17. package/src/builders/application-builder.js +18 -3
  18. package/src/builders/application-builder.js.map +1 -1
  19. package/src/index.d.ts +3 -3
  20. package/src/index.d.ts.map +1 -1
  21. package/src/index.js +5 -4
  22. package/src/index.js.map +1 -1
  23. package/src/interfaces/document-store.d.ts +3 -34
  24. package/src/interfaces/document-store.d.ts.map +1 -1
  25. package/src/interfaces/document-store.js +5 -3
  26. package/src/interfaces/document-store.js.map +1 -1
  27. package/src/interfaces/index.d.ts +1 -0
  28. package/src/interfaces/index.d.ts.map +1 -1
  29. package/src/interfaces/index.js +1 -0
  30. package/src/interfaces/index.js.map +1 -1
  31. package/src/interfaces/mongoose-document-store.d.ts +42 -0
  32. package/src/interfaces/mongoose-document-store.d.ts.map +1 -0
  33. package/src/interfaces/mongoose-document-store.js +10 -0
  34. package/src/interfaces/mongoose-document-store.js.map +1 -0
  35. package/src/{application-concrete.d.ts → mongo-application-concrete.d.ts} +12 -6
  36. package/src/mongo-application-concrete.d.ts.map +1 -0
  37. package/src/mongo-application-concrete.js +49 -0
  38. package/src/mongo-application-concrete.js.map +1 -0
  39. package/src/plugins/database-plugin.d.ts +66 -0
  40. package/src/plugins/database-plugin.d.ts.map +1 -0
  41. package/src/plugins/database-plugin.js +10 -0
  42. package/src/plugins/database-plugin.js.map +1 -0
  43. package/src/plugins/index.d.ts +2 -0
  44. package/src/plugins/index.d.ts.map +1 -1
  45. package/src/plugins/index.js +2 -0
  46. package/src/plugins/index.js.map +1 -1
  47. package/src/plugins/mongo-database-plugin.d.ts +115 -0
  48. package/src/plugins/mongo-database-plugin.d.ts.map +1 -0
  49. package/src/plugins/mongo-database-plugin.js +234 -0
  50. package/src/plugins/mongo-database-plugin.js.map +1 -0
  51. package/src/services/mongoose-document-store.d.ts +3 -3
  52. package/src/services/mongoose-document-store.d.ts.map +1 -1
  53. package/src/services/mongoose-document-store.js.map +1 -1
  54. package/src/utils/index.d.ts +2 -0
  55. package/src/utils/index.d.ts.map +1 -0
  56. package/src/utils/index.js +6 -0
  57. package/src/utils/index.js.map +1 -0
  58. package/src/utils/no-op-database.d.ts +8 -0
  59. package/src/utils/no-op-database.d.ts.map +1 -0
  60. package/src/utils/no-op-database.js +37 -0
  61. package/src/utils/no-op-database.js.map +1 -0
  62. package/src/application-concrete.d.ts.map +0 -1
  63. package/src/application-concrete.js +0 -34
  64. package/src/application-concrete.js.map +0 -1
  65. package/src/mongo-application-base.d.ts +0 -81
  66. package/src/mongo-application-base.d.ts.map +0 -1
  67. package/src/mongo-application-base.js +0 -216
  68. package/src/mongo-application-base.js.map +0 -1
package/README.md CHANGED
@@ -1769,6 +1769,235 @@ For issues and questions:
1769
1769
  - GitHub Issues: <https://github.com/Digital-Defiance/node-express-suite/issues>
1770
1770
  - Email: <support@digitaldefiance.org>
1771
1771
 
1772
+ ## Plugin-Based Architecture
1773
+
1774
+ The framework uses a plugin-based architecture that separates database concerns from the core application. This replaces the old deep inheritance hierarchy (Mongo base → Application → concrete subclass) with a composable plugin pattern.
1775
+
1776
+ ### Architecture Overview
1777
+
1778
+ ```
1779
+ BaseApplication<TID> ← Database-agnostic base (accepts IDatabase)
1780
+ └── Application<TID> ← HTTP/Express layer (server, routing, middleware)
1781
+ └── useDatabasePlugin() ← Plug in any database backend
1782
+
1783
+ IDatabasePlugin<TID> ← Plugin interface for database backends
1784
+ └── MongoDatabasePlugin ← Mongoose/MongoDB implementation
1785
+
1786
+ MongoApplicationConcrete ← Ready-to-use concrete class for testing/dev
1787
+ ```
1788
+
1789
+ ### Core Classes
1790
+
1791
+ | Class | Purpose |
1792
+ |-------|---------|
1793
+ | `BaseApplication<TID>` | Database-agnostic base. Accepts an `IDatabase` instance and optional lifecycle hooks. Manages `PluginManager`, `ServiceContainer`, and environment. |
1794
+ | `Application<TID>` | Extends `BaseApplication` with Express HTTP/HTTPS server, routing, CSP/Helmet config, and middleware. Database-agnostic — database backends are provided via `IDatabasePlugin`. |
1795
+ | `MongoApplicationConcrete<TID>` | Concrete `Application` subclass for testing/development. Wires up `MongoDatabasePlugin` with default configuration, schema maps, and a dummy email service. Replaces the old concrete class. |
1796
+
1797
+ ### IDatabasePlugin Interface
1798
+
1799
+ The `IDatabasePlugin<TID>` interface extends `IApplicationPlugin<TID>` with database-specific lifecycle hooks:
1800
+
1801
+ ```typescript
1802
+ interface IDatabasePlugin<TID> extends IApplicationPlugin<TID> {
1803
+ readonly database: IDatabase;
1804
+ readonly authenticationProvider?: IAuthenticationProvider<TID>;
1805
+
1806
+ connect(uri?: string): Promise<void>;
1807
+ disconnect(): Promise<void>;
1808
+ isConnected(): boolean;
1809
+
1810
+ // Optional dev/test store management
1811
+ setupDevStore?(): Promise<string>;
1812
+ teardownDevStore?(): Promise<void>;
1813
+ initializeDevStore?(): Promise<unknown>;
1814
+ }
1815
+ ```
1816
+
1817
+ ### MongoDatabasePlugin
1818
+
1819
+ `MongoDatabasePlugin` implements `IDatabasePlugin` for MongoDB/Mongoose:
1820
+
1821
+ ```typescript
1822
+ import { MongoDatabasePlugin } from '@digitaldefiance/node-express-suite';
1823
+
1824
+ const mongoPlugin = new MongoDatabasePlugin({
1825
+ schemaMapFactory: getSchemaMap,
1826
+ databaseInitFunction: DatabaseInitializationService.initUserDb.bind(DatabaseInitializationService),
1827
+ initResultHashFunction: DatabaseInitializationService.serverInitResultHash.bind(DatabaseInitializationService),
1828
+ environment,
1829
+ constants,
1830
+ });
1831
+ ```
1832
+
1833
+ It wraps a `MongooseDocumentStore` and provides:
1834
+ - Connection/disconnection lifecycle
1835
+ - Dev database provisioning via `MongoMemoryReplSet`
1836
+ - Authentication provider wiring
1837
+ - Mongoose model and schema map access
1838
+
1839
+ ### Application Constructor
1840
+
1841
+ The `Application` constructor accepts these parameters:
1842
+
1843
+ ```typescript
1844
+ constructor(
1845
+ environment: TEnvironment,
1846
+ apiRouterFactory: (app: IApplication<TID>) => BaseRouter<TID>,
1847
+ cspConfig?: ICSPConfig | HelmetOptions | IFlexibleCSP,
1848
+ constants?: TConstants,
1849
+ appRouterFactory?: (apiRouter: BaseRouter<TID>) => TAppRouter,
1850
+ customInitMiddleware?: typeof initMiddleware,
1851
+ database?: IDatabase, // Optional — use useDatabasePlugin() instead
1852
+ )
1853
+ ```
1854
+
1855
+ The `database` parameter is optional. When using a database plugin, the plugin's `database` property is used automatically.
1856
+
1857
+ ### Registering a Database Plugin
1858
+
1859
+ Use `useDatabasePlugin()` to register a database plugin with the application:
1860
+
1861
+ ```typescript
1862
+ const app = new Application(environment, apiRouterFactory);
1863
+ app.useDatabasePlugin(mongoPlugin);
1864
+ await app.start();
1865
+ ```
1866
+
1867
+ `useDatabasePlugin()` stores the plugin as the application's database plugin AND registers it with the `PluginManager`, so it participates in the full plugin lifecycle (`init`, `stop`).
1868
+
1869
+ ### Implementing a Custom Database Plugin (BrightChain Example)
1870
+
1871
+ To use a non-Mongo database, implement `IDatabasePlugin` directly. You do not need `IDocumentStore` or any Mongoose types:
1872
+
1873
+ ```typescript
1874
+ import type { IDatabasePlugin, IDatabase, IApplication } from '@digitaldefiance/node-express-suite';
1875
+
1876
+ class BrightChainDatabasePlugin implements IDatabasePlugin<Buffer> {
1877
+ readonly name = 'brightchain-database';
1878
+ readonly version = '1.0.0';
1879
+
1880
+ private _connected = false;
1881
+ private _database: IDatabase;
1882
+
1883
+ constructor(private config: BrightChainConfig) {
1884
+ this._database = new BrightChainDatabase(config);
1885
+ }
1886
+
1887
+ get database(): IDatabase {
1888
+ return this._database;
1889
+ }
1890
+
1891
+ // Optional: provide an auth provider if your DB manages authentication
1892
+ get authenticationProvider() {
1893
+ return undefined;
1894
+ }
1895
+
1896
+ async connect(uri?: string): Promise<void> {
1897
+ await this._database.connect(uri ?? this.config.connectionString);
1898
+ this._connected = true;
1899
+ }
1900
+
1901
+ async disconnect(): Promise<void> {
1902
+ await this._database.disconnect();
1903
+ this._connected = false;
1904
+ }
1905
+
1906
+ isConnected(): boolean {
1907
+ return this._connected;
1908
+ }
1909
+
1910
+ async init(app: IApplication<Buffer>): Promise<void> {
1911
+ // Wire up any app-level integrations after connection
1912
+ // e.g., register services, set auth provider, etc.
1913
+ }
1914
+
1915
+ async stop(): Promise<void> {
1916
+ await this.disconnect();
1917
+ }
1918
+ }
1919
+
1920
+ // Usage:
1921
+ const app = new Application(environment, apiRouterFactory);
1922
+ app.useDatabasePlugin(new BrightChainDatabasePlugin(config));
1923
+ await app.start();
1924
+ ```
1925
+
1926
+ ---
1927
+
1928
+ ## Migration Guide: Inheritance → Plugin Architecture
1929
+
1930
+ This section covers migrating from the old inheritance-based hierarchy to the new plugin-based architecture.
1931
+
1932
+ ### What Changed
1933
+
1934
+ | Before | After |
1935
+ |--------|-------|
1936
+ | Old Mongo base → `Application` → old concrete class | `BaseApplication` → `Application` + `IDatabasePlugin` |
1937
+ | Database logic baked into the class hierarchy | Database logic provided via plugins |
1938
+ | Old concrete class for testing/dev | `MongoApplicationConcrete` for testing/dev |
1939
+ | Extending the old Mongo base for custom apps | Implementing `IDatabasePlugin` for custom databases |
1940
+
1941
+ ### Before (Old Hierarchy)
1942
+
1943
+ ```typescript
1944
+ // Old: The concrete class extended Application which extended the Mongo base class
1945
+ // Database logic was tightly coupled into the inheritance chain
1946
+ import { /* old concrete class */ } from '@digitaldefiance/node-express-suite';
1947
+
1948
+ const app = new OldConcreteApp(environment);
1949
+ await app.start();
1950
+ ```
1951
+
1952
+ ### After (Plugin Architecture)
1953
+
1954
+ ```typescript
1955
+ // New: Application is database-agnostic, MongoDatabasePlugin provides Mongo support
1956
+ import { MongoApplicationConcrete } from '@digitaldefiance/node-express-suite';
1957
+
1958
+ // For testing/development (drop-in replacement for the old concrete class):
1959
+ const app = new MongoApplicationConcrete(environment);
1960
+ await app.start();
1961
+ ```
1962
+
1963
+ Or for custom wiring:
1964
+
1965
+ ```typescript
1966
+ import { Application, MongoDatabasePlugin } from '@digitaldefiance/node-express-suite';
1967
+
1968
+ const app = new Application(environment, apiRouterFactory);
1969
+
1970
+ const mongoPlugin = new MongoDatabasePlugin({
1971
+ schemaMapFactory: getSchemaMap,
1972
+ databaseInitFunction: DatabaseInitializationService.initUserDb.bind(DatabaseInitializationService),
1973
+ initResultHashFunction: DatabaseInitializationService.serverInitResultHash.bind(DatabaseInitializationService),
1974
+ environment,
1975
+ constants,
1976
+ });
1977
+
1978
+ app.useDatabasePlugin(mongoPlugin);
1979
+ await app.start();
1980
+ ```
1981
+
1982
+ ### Key Renames
1983
+
1984
+ | Old Name | New Name | Notes |
1985
+ |----------|----------|-------|
1986
+ | Old concrete class | `MongoApplicationConcrete` | Drop-in replacement for testing/dev |
1987
+ | Old Mongo base class | *(removed)* | Functionality moved to `BaseApplication` + `MongoDatabasePlugin` |
1988
+ | Old base file | `base-application.ts` | File renamed |
1989
+ | Old concrete file | `mongo-application-concrete.ts` | File renamed |
1990
+
1991
+ ### Migration Checklist
1992
+
1993
+ - [ ] Replace the old concrete class with `MongoApplicationConcrete`
1994
+ - [ ] Replace any old Mongo base subclasses with `Application` + `useDatabasePlugin()`
1995
+ - [ ] Update imports to use `base-application` (renamed from old base file)
1996
+ - [ ] Update imports to use `mongo-application-concrete` (renamed from old concrete file)
1997
+ - [ ] If you had a custom concrete subclass, convert it to use `MongoDatabasePlugin` or implement your own `IDatabasePlugin`
1998
+
1999
+ ---
2000
+
1772
2001
  ## Architecture Refactor (2025)
1773
2002
 
1774
2003
  **Major improvements with large complexity reduction:**
@@ -2654,7 +2883,7 @@ This release introduces a complete decorator-based API for defining controllers,
2654
2883
  ### Version 2.1.24
2655
2884
 
2656
2885
  - Provide mocks/fixtures for use in testing
2657
- - Provide concrete/runnable ApplicationConcrete class
2886
+ - Provide concrete/runnable MongoApplicationConcrete class
2658
2887
  - Export DummyEmailService for testing
2659
2888
  - Further streamline Application generics
2660
2889
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/node-express-suite",
3
- "version": "3.18.3",
3
+ "version": "4.0.0",
4
4
  "homepage": "https://github.com/Digital-Defiance/node-express-suite",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,10 +3,11 @@ import { IFailableResult } from '@digitaldefiance/suite-core-lib';
3
3
  import { HelmetOptions } from 'helmet';
4
4
  import { IBaseDocument } from '../../documents';
5
5
  import { IApplication, IConstants, ICSPConfig, IFlexibleCSP, IServerInitResult } from '../../interfaces';
6
+ import { IMongoApplication } from '../../interfaces/mongo-application';
6
7
  import { ITestEnvironment } from '../../interfaces/test-environment';
7
8
  import { initMiddleware } from '../../middleware-utils';
8
9
  import { AppRouter, BaseRouter } from '../../routers';
9
10
  import { SchemaMap } from '../../types';
10
11
  import type { PlatformID } from '@digitaldefiance/node-ecies-lib';
11
- export declare function setupTestEnvironment<TID extends PlatformID = Buffer, TModelDocs extends Record<string, IBaseDocument<any, TID>> = Record<string, IBaseDocument<any, TID>>, TConstants extends IConstants = IConstants, TAppRouter extends AppRouter<TID> = AppRouter<TID>>(constants: TConstants, apiRouterFactory: (app: IApplication<TID>) => BaseRouter<TID>, schemaMapFactory: (connection: Connection) => SchemaMap<TID, TModelDocs>, appRouterFactory?: (apiRouter: BaseRouter<TID>) => TAppRouter, customInitMiddleware?: typeof initMiddleware, envLocation?: string, databaseInitFunction?: (application: IApplication<TID>) => Promise<IFailableResult<IServerInitResult<TID>>>, initResultHashFunction?: (initResults: IServerInitResult<TID>) => string, cspConfig?: ICSPConfig | HelmetOptions | IFlexibleCSP): Promise<ITestEnvironment<TID>>;
12
+ export declare function setupTestEnvironment<TID extends PlatformID = Buffer, TModelDocs extends Record<string, IBaseDocument<never, TID>> = Record<string, IBaseDocument<never, TID>>, TConstants extends IConstants = IConstants, TAppRouter extends AppRouter<TID> = AppRouter<TID>>(constants: TConstants, apiRouterFactory: (app: IApplication<TID>) => BaseRouter<TID>, schemaMapFactory: (connection: Connection) => SchemaMap<TID, TModelDocs>, appRouterFactory?: (apiRouter: BaseRouter<TID>) => TAppRouter, customInitMiddleware?: typeof initMiddleware, envLocation?: string, databaseInitFunction?: (application: IMongoApplication<TID>) => Promise<IFailableResult<IServerInitResult<TID>>>, initResultHashFunction?: (initResults: IServerInitResult<TID>) => string, cspConfig?: ICSPConfig | HelmetOptions | IFlexibleCSP): Promise<ITestEnvironment<TID>>;
12
13
  //# sourceMappingURL=setup-test-env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup-test-env.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-express-suite/src/__tests__/helpers/setup-test-env.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,YAAY,EACZ,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MA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1
+ {"version":3,"file":"setup-test-env.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-express-suite/src/__tests__/helpers/setup-test-env.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,YAAY,EACZ,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,wBAAsB,oBAAoB,CACxC,GAAG,SAAS,UAAU,GAAG,MAAM,EAC/B,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CACnE,MAAM,EACN,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAC1B,EACD,UAAU,SAAS,UAAU,GAAG,UAAU,EAC1C,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,EAElD,SAAS,EAAE,UAAU,EACrB,gBAAgB,EAAE,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,GAAG,CAAC,EAC7D,gBAAgB,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,EACxE,gBAAgB,GAAE,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,UACV,EACxC,oBAAoB,GAAE,OAAO,cAA+B,EAC5D,WAAW,CAAC,EAAE,MAAM,EACpB,oBAAoB,CAAC,EAAE,CACrB,WAAW,EAAE,iBAAiB,CAAC,GAAG,CAAC,KAChC,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EACrD,sBAAsB,CAAC,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,MAAM,EACxE,SAAS,GAAE,UAAU,GAAG,aAAa,GAAG,YAWvC,GACA,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAmKhC"}
@@ -7,6 +7,7 @@ const environment_1 = require("../../environment");
7
7
  const middleware_utils_1 = require("../../middleware-utils");
8
8
  const routers_1 = require("../../routers");
9
9
  const services_1 = require("../../services");
10
+ const mongo_database_plugin_1 = require("../../plugins/mongo-database-plugin");
10
11
  async function setupTestEnvironment(constants, apiRouterFactory, schemaMapFactory, appRouterFactory = (apiRouter) => new routers_1.AppRouter(apiRouter), customInitMiddleware = middleware_utils_1.initMiddleware, envLocation, databaseInitFunction, initResultHashFunction, cspConfig = {
11
12
  corsWhitelist: [],
12
13
  csp: {
@@ -28,29 +29,29 @@ async function setupTestEnvironment(constants, apiRouterFactory, schemaMapFactor
28
29
  }
29
30
  // Optimize MongoDB settings for test performance while maintaining reliability
30
31
  if (!process.env['MONGO_MAX_POOL_SIZE']) {
31
- process.env['MONGO_MAX_POOL_SIZE'] = '5'; // Increased for better concurrency
32
+ process.env['MONGO_MAX_POOL_SIZE'] = '5';
32
33
  }
33
34
  if (!process.env['MONGO_MIN_POOL_SIZE']) {
34
- process.env['MONGO_MIN_POOL_SIZE'] = '2'; // Increased for better performance
35
+ process.env['MONGO_MIN_POOL_SIZE'] = '2';
35
36
  }
36
37
  if (!process.env['MONGO_SERVER_SELECTION_TIMEOUT_MS']) {
37
- process.env['MONGO_SERVER_SELECTION_TIMEOUT_MS'] = '5000'; // Increased for stability
38
+ process.env['MONGO_SERVER_SELECTION_TIMEOUT_MS'] = '5000';
38
39
  }
39
40
  if (!process.env['MONGO_SOCKET_TIMEOUT_MS']) {
40
- process.env['MONGO_SOCKET_TIMEOUT_MS'] = '15000'; // Increased for stability
41
+ process.env['MONGO_SOCKET_TIMEOUT_MS'] = '15000';
41
42
  }
42
43
  if (!process.env['MONGO_TRANSACTION_TIMEOUT']) {
43
- process.env['MONGO_TRANSACTION_TIMEOUT'] = '15000'; // Increased for stability
44
+ process.env['MONGO_TRANSACTION_TIMEOUT'] = '15000';
44
45
  }
45
46
  if (!process.env['MONGO_TRANSACTION_LOCK_REQUEST_TIMEOUT']) {
46
- process.env['MONGO_TRANSACTION_LOCK_REQUEST_TIMEOUT'] = '8000'; // Increased for stability
47
+ process.env['MONGO_TRANSACTION_LOCK_REQUEST_TIMEOUT'] = '8000';
47
48
  }
48
49
  if (!process.env['MONGO_TRANSACTION_RETRY_BASE_DELAY']) {
49
- process.env['MONGO_TRANSACTION_RETRY_BASE_DELAY'] = '100'; // Increased for stability
50
+ process.env['MONGO_TRANSACTION_RETRY_BASE_DELAY'] = '100';
50
51
  }
51
52
  // Disable transactions in test environment for better reliability
52
53
  if (!process.env['MONGO_USE_TRANSACTIONS']) {
53
- process.env['MONGO_USE_TRANSACTIONS'] = 'false'; // Disable transactions for tests
54
+ process.env['MONGO_USE_TRANSACTIONS'] = 'false';
54
55
  }
55
56
  // Ensure language is set to English for consistent test behavior
56
57
  process.env.LANGUAGE = 'English (US)';
@@ -66,41 +67,47 @@ async function setupTestEnvironment(constants, apiRouterFactory, schemaMapFactor
66
67
  };
67
68
  setAdminLanguage('en-US');
68
69
  const env = new environment_1.Environment(envLocation, true);
69
- const application = new application_1.Application(env, apiRouterFactory, schemaMapFactory, databaseInitFunction ??
70
- services_1.DatabaseInitializationService.initUserDb.bind(services_1.DatabaseInitializationService), initResultHashFunction ??
71
- services_1.DatabaseInitializationService.serverInitResultHash.bind(services_1.DatabaseInitializationService), cspConfig, constants, appRouterFactory, customInitMiddleware);
72
- const initResult = await services_1.DatabaseInitializationService.initUserDb(application);
73
- if (!initResult.success || !initResult.data) {
74
- throw new Error('Failed to initialize database for tests');
75
- }
76
- const accountData = initResult.data;
77
- // Create and start your app
70
+ // Create the Application with MongoDatabasePlugin
71
+ const application = new application_1.Application(env, apiRouterFactory, cspConfig, constants, appRouterFactory, customInitMiddleware);
72
+ const mongoPlugin = new mongo_database_plugin_1.MongoDatabasePlugin({
73
+ schemaMapFactory,
74
+ databaseInitFunction: databaseInitFunction ??
75
+ services_1.DatabaseInitializationService.initUserDb.bind(services_1.DatabaseInitializationService),
76
+ initResultHashFunction: initResultHashFunction ??
77
+ services_1.DatabaseInitializationService.serverInitResultHash.bind(services_1.DatabaseInitializationService),
78
+ environment: env,
79
+ constants,
80
+ });
81
+ application.useDatabasePlugin(mongoPlugin);
82
+ // Create and start your app — this connects the DB, inits plugins,
83
+ // and runs initializeDevStore (which calls initUserDb) via the plugin.
78
84
  try {
79
85
  await application.start();
80
- const command = {
81
- ...(application.environment.mongo.setParameterSupported
82
- ? { setParameter: 1 }
83
- : {}),
84
- ...(application.environment.mongo.useTransactions &&
85
- application.environment.mongo.transactionLifetimeLimitSecondsSupported
86
- ? {
87
- transactionLifetimeLimitSeconds: application.environment.mongo.transactionTimeout,
88
- }
89
- : {}),
90
- ...(application.environment.mongo.useTransactions &&
91
- application.environment.mongo
92
- .maxTransactionLockRequestTimeoutMillisSupported
93
- ? {
94
- maxTransactionLockRequestTimeoutMillis: application.environment.mongo.transactionLockRequestTimeout,
95
- }
96
- : {}),
97
- };
98
- if (Object.keys(command).length > 0 && application.db.connection.db) {
99
- // Configure MongoDB for better concurrency
100
- await application.db.connection.db
101
- .admin()
102
- .command(command)
103
- .catch(() => undefined);
86
+ if (mongoPlugin.db.connection.db) {
87
+ const command = {
88
+ ...(application.environment.mongo.setParameterSupported
89
+ ? { setParameter: 1 }
90
+ : {}),
91
+ ...(application.environment.mongo.useTransactions &&
92
+ application.environment.mongo.transactionLifetimeLimitSecondsSupported
93
+ ? {
94
+ transactionLifetimeLimitSeconds: application.environment.mongo.transactionTimeout,
95
+ }
96
+ : {}),
97
+ ...(application.environment.mongo.useTransactions &&
98
+ application.environment.mongo
99
+ .maxTransactionLockRequestTimeoutMillisSupported
100
+ ? {
101
+ maxTransactionLockRequestTimeoutMillis: application.environment.mongo.transactionLockRequestTimeout,
102
+ }
103
+ : {}),
104
+ };
105
+ if (Object.keys(command).length > 0) {
106
+ await mongoPlugin.db.connection.db
107
+ .admin()
108
+ .command(command)
109
+ .catch(() => undefined);
110
+ }
104
111
  }
105
112
  }
106
113
  catch (error) {
@@ -110,9 +117,14 @@ async function setupTestEnvironment(constants, apiRouterFactory, schemaMapFactor
110
117
  }
111
118
  // Ensure the test process uses the same JWT secret as the application
112
119
  process.env.JWT_SECRET = application.environment.jwtSecret;
120
+ // Get the init result from the plugin (populated during start() → initializeDevStore)
121
+ const accountData = mongoPlugin.lastInitResult;
122
+ if (!accountData) {
123
+ throw new Error('Failed to initialize database for tests — no init result from plugin');
124
+ }
113
125
  return {
114
- application,
115
- mongoServer: application.devDatabase,
126
+ application: application,
127
+ mongoServer: mongoPlugin.devDatabase,
116
128
  mongoUri: application.environment.mongo.uri,
117
129
  accountData,
118
130
  dbName: application.environment.devDatabase,
@@ -1 +1 @@
1
- {"version":3,"file":"setup-test-env.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-express-suite/src/__tests__/helpers/setup-test-env.ts"],"names":[],"mappings":";;AAyBA,oDA+KC;AAxMD,wDAImC;AAInC,mDAAgD;AAEhD,mDAAgD;AAShD,6DAAwD;AACxD,2CAAsD;AACtD,6CAA+D;AAIxD,KAAK,UAAU,oBAAoB,CASxC,SAAqB,EACrB,gBAA6D,EAC7D,gBAAwE,EACxE,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B;iBACnD;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,eAAe;gBACjD,WAAW,CAAC,WAAW,CAAC,KAAK;qBAC1B,+CAA+C;gBAChD,CAAC,CAAC;oBACE,sCAAsC,EACpC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,6BAA6B;iBAC9D;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;QAEF,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YACpE,2CAA2C;YAC3C,MAAM,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE;iBAC/B,KAAK,EAAE;iBACP,OAAO,CAAC,OAAO,CAAC;iBAChB,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,+CAA+C,EAC/C,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAClC,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC1C,MAAM,KAAK,CAAC;IACd,CAAC;IAED,sEAAsE;IACtE,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC;IAE3D,OAAO;QACL,WAAW;QACX,WAAW,EAAE,WAAW,CAAC,WAAY;QACrC,QAAQ,EAAE,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,GAAI;QAC5C,WAAW;QACX,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,WAAY;KAC7C,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"setup-test-env.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-express-suite/src/__tests__/helpers/setup-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;QACrC,QAAQ,EAAE,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,GAAI;QAC5C,WAAW;QACX,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,WAAY;KAC7C,CAAC;AACJ,CAAC"}
@@ -1,24 +1,35 @@
1
1
  /**
2
- * @fileoverview Main application class with Express server.
3
- * Extends MongoApplicationBase with HTTP/HTTPS server and routing.
2
+ * @fileoverview Generic Express application class.
3
+ * Extends BaseApplication with HTTP/HTTPS server, routing, and middleware.
4
+ * Database-agnostic — database backends are provided via IDatabasePlugin.
4
5
  * @module application
5
6
  */
6
- import mongoose from '@digitaldefiance/mongoose-types';
7
7
  import { Application as ExpressApplication } from 'express';
8
8
  import { HelmetOptions } from 'helmet';
9
- import { MongoApplicationBase } from './mongo-application-base';
10
- import { IBaseDocument } from './documents/base';
9
+ import { BaseApplication } from './base-application';
11
10
  import { Environment } from './environment';
12
- import { IApplication, ICSPConfig, IFailableResult, IServerInitResult, IMongoApplication } from './interfaces';
11
+ import { IApplication, ICSPConfig } from './interfaces';
13
12
  import { IConstants } from './interfaces/constants';
14
- import { IDocumentStore } from './interfaces/document-store';
15
13
  import { IFlexibleCSP } from './interfaces/flexible-csp';
16
14
  import { initMiddleware } from './middleware-utils';
17
15
  import { AppRouter } from './routers/app';
18
16
  import { BaseRouter } from './routers/base';
19
- import { SchemaMap } from './types';
17
+ import { IDatabasePlugin } from './plugins/database-plugin';
18
+ import type { IDatabase } from './interfaces/storage';
20
19
  import type { PlatformID } from '@digitaldefiance/node-ecies-lib';
21
- export declare class Application<TInitResults extends IServerInitResult<TID>, TModelDocs extends Record<string, IBaseDocument<any, TID>>, TID extends PlatformID = Buffer, TEnvironment extends Environment<TID> = Environment<TID>, TConstants extends IConstants = IConstants, TAppRouter extends AppRouter<TID> = AppRouter<TID>> extends MongoApplicationBase<TID, TModelDocs, TInitResults, TConstants> implements IMongoApplication<TID> {
20
+ /**
21
+ * Generic Express application class.
22
+ *
23
+ * Provides HTTP/HTTPS server, routing, middleware, and error handling.
24
+ * Database backends are plugged in via IDatabasePlugin rather than
25
+ * being baked into the class hierarchy.
26
+ *
27
+ * @template TID - Platform ID type (Buffer, ObjectId, etc.)
28
+ * @template TEnvironment - Environment type
29
+ * @template TConstants - Constants type
30
+ * @template TAppRouter - App router type
31
+ */
32
+ export declare class Application<TID extends PlatformID = Buffer, TEnvironment extends Environment<TID> = Environment<TID>, TConstants extends IConstants = IConstants, TAppRouter extends AppRouter<TID> = AppRouter<TID>> extends BaseApplication<TID, unknown, TConstants> {
22
33
  readonly expressApp: ExpressApplication;
23
34
  private server;
24
35
  private readonly _cspConfig;
@@ -27,10 +38,25 @@ export declare class Application<TInitResults extends IServerInitResult<TID>, TM
27
38
  private readonly _initMiddleware;
28
39
  private _apiRouter?;
29
40
  private greenlockManager;
41
+ private _databasePlugin;
30
42
  get environment(): TEnvironment;
43
+ /**
44
+ * Get the registered database plugin, if any.
45
+ */
46
+ get databasePlugin(): IDatabasePlugin<TID> | null;
47
+ /**
48
+ * Register a database plugin. Must be called before start().
49
+ * The plugin will be initialized during start() and its database
50
+ * will be used as the application's primary database.
51
+ */
52
+ useDatabasePlugin(plugin: IDatabasePlugin<TID>): this;
53
+ /**
54
+ * Hook for subclasses to register services before the server starts.
55
+ * Called during the constructor.
56
+ */
31
57
  protected registerServices(): void;
32
- constructor(environment: TEnvironment, apiRouterFactory: (app: IApplication<TID>) => BaseRouter<TID>, schemaMapFactory: (connection: mongoose.Connection) => SchemaMap<TID, TModelDocs>, databaseInitFunction: (application: MongoApplicationBase<TID, TModelDocs, TInitResults>) => Promise<IFailableResult<TInitResults>>, initResultHashFunction: (initResults: TInitResults) => string, cspConfig?: ICSPConfig | HelmetOptions | IFlexibleCSP, constants?: TConstants, appRouterFactory?: (apiRouter: BaseRouter<TID>) => TAppRouter, customInitMiddleware?: typeof initMiddleware, documentStore?: IDocumentStore<TID, TModelDocs>);
33
- start(mongoUri?: string): Promise<void>;
58
+ constructor(environment: TEnvironment, apiRouterFactory: (app: IApplication<TID>) => BaseRouter<TID>, cspConfig?: ICSPConfig | HelmetOptions | IFlexibleCSP, constants?: TConstants, appRouterFactory?: (apiRouter: BaseRouter<TID>) => TAppRouter, customInitMiddleware?: typeof initMiddleware, database?: IDatabase);
59
+ start(uri?: string): Promise<void>;
34
60
  stop(): Promise<void>;
35
61
  }
36
62
  //# sourceMappingURL=application.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-express-suite/src/application.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AAOvD,OAAgB,EACd,WAAW,IAAI,kBAAkB,EAIlC,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EAEf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAiB,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAK5C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAOlE,qBAAa,WAAW,CACtB,YAAY,SAAS,iBAAi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AAE,YAAY,KAAK,MAAM,EAC7D,SAAS,GAAE,UAAU,GAAG,aAAa,GAAG,YAWvC,EACD,SAAS,GAAE,UAAoC,EAC/C,gBAAgB,GAAE,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,UAEP,EAC3C,oBAAoB,GAAE,OAAO,cAA+B,EAC5D,aAAa,CAAC,EAAE,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC;IAqB3B,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqKvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA0C5C"}
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-express-suite/src/application.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAgB,EACd,WAAW,IAAI,kBAAkB,EAIlC,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAe,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAiB,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAKlE;;;;;;;;;;;GAWG;AACH,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