@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
@@ -1,216 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview MongoDB/Mongoose-specific application base class.
4
- * Extends BaseApplication with IDocumentStore support, Mongoose model access,
5
- * schema maps, and dev database management.
6
- * @module mongo-application-base
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MongoApplicationBase = void 0;
10
- const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
11
- const application_base_1 = require("./application-base");
12
- const mongoose_document_store_1 = require("./services/mongoose-document-store");
13
- const mongo_authentication_provider_1 = require("./services/mongo-authentication-provider");
14
- /**
15
- * Duck-typing check to determine if a value conforms to the IDatabase interface.
16
- * Checks for the key methods that distinguish IDatabase from IDocumentStore.
17
- */
18
- function isIDatabase(value) {
19
- return (typeof value === 'object' &&
20
- value !== null &&
21
- 'collection' in value &&
22
- 'startSession' in value &&
23
- typeof value['collection'] === 'function' &&
24
- typeof value['startSession'] === 'function');
25
- }
26
- /**
27
- * MongoDB/Mongoose-specific application base class.
28
- * Extends BaseApplication with legacy IDocumentStore support for backward
29
- * compatibility. Provides Mongoose-specific accessors: db, schemaMap,
30
- * devDatabase, getModel().
31
- *
32
- * Accepts either an IDatabase or an IDocumentStore in the constructor.
33
- * When an IDocumentStore is provided, a no-op IDatabase adapter is used
34
- * for the parent class, and the document store handles all database operations.
35
- */
36
- class MongoApplicationBase extends application_base_1.BaseApplication {
37
- /**
38
- * The injected document store handling all database operations.
39
- * Set when a legacy IDocumentStore is passed to the constructor.
40
- * @deprecated Prefer IDatabase for new code.
41
- */
42
- _documentStore;
43
- /**
44
- * Whether the constructor received an IDocumentStore (legacy path).
45
- */
46
- _isLegacyDocumentStore;
47
- /**
48
- * Schema map for all models, delegated to the document store.
49
- * Only available when a legacy IDocumentStore is used.
50
- */
51
- get schemaMap() {
52
- if (!this._documentStore) {
53
- throw new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_SchemaMapIsNotLoadedYet);
54
- }
55
- const map = this._documentStore.schemaMap;
56
- if (!map) {
57
- throw new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_SchemaMapIsNotLoadedYet);
58
- }
59
- return map;
60
- }
61
- /**
62
- * Get the connected MongoDB database instance.
63
- * @deprecated Use database (IDatabase) or getCollection instead for storage-agnostic access.
64
- */
65
- get db() {
66
- if (this._documentStore instanceof mongoose_document_store_1.MongooseDocumentStore) {
67
- return this._documentStore.db;
68
- }
69
- throw new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_DatabaseNotConnectedYet);
70
- }
71
- /**
72
- * Get the injected document store.
73
- * @deprecated Prefer database (IDatabase) for new code.
74
- */
75
- get documentStore() {
76
- return this._documentStore;
77
- }
78
- /**
79
- * Get the in-memory MongoDB instance (if any), delegated to the document store.
80
- * Only available when a legacy IDocumentStore is used.
81
- */
82
- get devDatabase() {
83
- return this._documentStore?.devDatabase;
84
- }
85
- constructor(environment, databaseOrStore, constants = suite_core_lib_1.Constants) {
86
- if (isIDatabase(databaseOrStore)) {
87
- // IDatabase path — pass directly to parent
88
- super(environment, databaseOrStore, constants);
89
- this._documentStore = undefined;
90
- this._isLegacyDocumentStore = false;
91
- }
92
- else {
93
- // Legacy IDocumentStore path — create a no-op IDatabase for the parent
94
- // since the document store manages its own connection lifecycle.
95
- super(environment, createNoOpDatabase(), constants);
96
- this._documentStore = databaseOrStore;
97
- this._isLegacyDocumentStore = true;
98
- }
99
- }
100
- /**
101
- * Start the application.
102
- * When using a legacy IDocumentStore, handles dev database setup and
103
- * delegates connection to the document store.
104
- * When using IDatabase, delegates to the parent class.
105
- */
106
- async start(mongoUri, delayReady) {
107
- if (this._isLegacyDocumentStore && this._documentStore) {
108
- // Legacy IDocumentStore path
109
- if (this._ready) {
110
- console.error('Failed to start the application:', 'Application is already running');
111
- const err = new Error('Application is already running');
112
- if (process.env['NODE_ENV'] === 'test') {
113
- throw err;
114
- }
115
- process.exit(1);
116
- }
117
- // Handle dev database setup
118
- if (this.environment.devDatabase && !this._documentStore.devDatabase) {
119
- if (this._documentStore.setupDevStore) {
120
- mongoUri = (await this._documentStore.setupDevStore());
121
- }
122
- }
123
- try {
124
- const uri = mongoUri ?? this.environment.mongo?.uri;
125
- await this._documentStore.connect(uri);
126
- // Wire up the Mongoose-backed authentication provider
127
- if (!this.authProvider) {
128
- this.authProvider = new mongo_authentication_provider_1.MongoAuthenticationProvider(this);
129
- }
130
- // Initialize plugins
131
- await this.plugins.initAll(this);
132
- }
133
- catch (err) {
134
- const sanitizedErr = err instanceof Error
135
- ? err.message.replace(/[\r\n]/g, ' ')
136
- : String(err).replace(/[\r\n]/g, ' ');
137
- console.error('Failed to start the application:', sanitizedErr);
138
- if (process.env['NODE_ENV'] === 'test') {
139
- throw err;
140
- }
141
- process.exit(1);
142
- }
143
- this._ready = delayReady ? false : true;
144
- }
145
- else {
146
- // IDatabase path — delegate to parent
147
- await super.start(mongoUri, delayReady);
148
- }
149
- }
150
- /**
151
- * Stop the application.
152
- * When using a legacy IDocumentStore, delegates disconnection to the store.
153
- * When using IDatabase, delegates to the parent class.
154
- */
155
- async stop() {
156
- if (this._isLegacyDocumentStore && this._documentStore) {
157
- // Legacy IDocumentStore path
158
- await this.plugins.stopAll();
159
- await this._documentStore.disconnect();
160
- if (this._documentStore.devDatabase) {
161
- await this._documentStore.devDatabase.stop();
162
- }
163
- this._ready = false;
164
- }
165
- else {
166
- // IDatabase path — delegate to parent
167
- await super.stop();
168
- }
169
- }
170
- /**
171
- * Get a model by name, delegated to the legacy document store.
172
- * @deprecated Use getCollection<T>(name) with IDatabase instead.
173
- * @param modelName Name of the model
174
- */
175
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
- getModel(modelName) {
177
- if (!this._documentStore) {
178
- throw new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.Admin_Error_DatabaseNotConnectedYet);
179
- }
180
- return this._documentStore.getModel(modelName);
181
- }
182
- }
183
- exports.MongoApplicationBase = MongoApplicationBase;
184
- /**
185
- * Creates a no-op IDatabase that does nothing.
186
- * Used when a legacy IDocumentStore manages its own connection lifecycle.
187
- */
188
- function createNoOpDatabase() {
189
- return {
190
- collection() {
191
- throw new Error('No-op IDatabase: use the document store for collection access');
192
- },
193
- startSession() {
194
- throw new Error('No-op IDatabase: use the document store for session management');
195
- },
196
- withTransaction() {
197
- throw new Error('No-op IDatabase: use the document store for transactions');
198
- },
199
- listCollections() {
200
- return [];
201
- },
202
- async dropCollection() {
203
- return false;
204
- },
205
- async connect() {
206
- // no-op — document store manages connection
207
- },
208
- async disconnect() {
209
- // no-op — document store manages disconnection
210
- },
211
- isConnected() {
212
- return false;
213
- },
214
- };
215
- }
216
- //# sourceMappingURL=mongo-application-base.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongo-application-base.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-express-suite/src/mongo-application-base.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAMH,oEAIyC;AAEzC,yDAAqD;AAMrD,gFAA2E;AAC3E,4FAAuF;AAIvF;;;GAGG;AACH,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,cAAc,IAAI,KAAK;QACvB,OAAQ,KAAiC,CAAC,YAAY,CAAC,KAAK,UAAU;QACtE,OAAQ,KAAiC,CAAC,cAAc,CAAC,KAAK,UAAU,CACzE,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAa,oBAOX,SAAQ,kCAA8C;IAGtD;;;;OAIG;IACgB,cAAc,CAEnB;IAEd;;OAEG;IACgB,sBAAsB,CAAU;IAEnD;;;OAGG;IACH,IAAW,SAAS;QAClB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,uCAAsB,CAC9B,mCAAkB,CAAC,mCAAmC,CACvD,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;QAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,uCAAsB,CAC9B,mCAAkB,CAAC,mCAAmC,CACvD,CAAC;QACJ,CAAC;QACD,OAAO,GAAiC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,IAA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