@nimbus-cqrs/mongodb 2.0.1-beta.1 → 2.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/esm/lib/crud/updateMany.d.ts +1 -1
- package/esm/lib/crud/updateMany.d.ts.map +1 -1
- package/esm/lib/handleMongoError.d.ts.map +1 -1
- package/esm/lib/mongoConnectionManager.d.ts +59 -0
- package/esm/lib/mongoConnectionManager.d.ts.map +1 -1
- package/esm/lib/mongoConnectionManager.js +68 -3
- package/esm/lib/repository.d.ts +17 -1
- package/esm/lib/repository.d.ts.map +1 -1
- package/esm/lib/repository.js +35 -1
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ import type { Collection, Document, Filter, UpdateFilter, UpdateOptions, UpdateR
|
|
|
5
5
|
export type UpdateManyInput = {
|
|
6
6
|
collection: Collection<Document>;
|
|
7
7
|
filter: Filter<Document>;
|
|
8
|
-
update: UpdateFilter<Document
|
|
8
|
+
update: UpdateFilter<Document> | Document[];
|
|
9
9
|
options?: UpdateOptions;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/updateMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,aAAa,EACb,YAAY,EACf,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/updateMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,aAAa,EACb,YAAY,EACf,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAAE,CAAC;IAC5C,OAAO,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CACrB,KAAK,EAAE,eAAe,KACrB,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;AAErC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,UAaxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleMongoError.d.ts","sourceRoot":"","sources":["../../src/lib/handleMongoError.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,SAAS,EAGjB,MAAM,
|
|
1
|
+
{"version":3,"file":"handleMongoError.d.ts","sourceRoot":"","sources":["../../src/lib/handleMongoError.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,SAAS,EAGjB,MAAM,qDAAqD,CAAC;AAE7D;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,GAAG,KAAG,SAuB7C,CAAC"}
|
|
@@ -104,4 +104,63 @@ export declare class MongoConnectionManager {
|
|
|
104
104
|
*/
|
|
105
105
|
close(): Promise<void>;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Setup a named MongoConnectionManager instance and register it for later retrieval.
|
|
109
|
+
*
|
|
110
|
+
* Use this function to configure a MongoConnectionManager at application
|
|
111
|
+
* startup, then retrieve it later with {@link getMongoConnectionManager}.
|
|
112
|
+
*
|
|
113
|
+
* @param {object} params - The setup parameters.
|
|
114
|
+
* @param {string} params.uri - The MongoDB connection URI.
|
|
115
|
+
* @param {MongoClientOptions} [params.options] - Options forwarded to the underlying `MongoClient`.
|
|
116
|
+
* @param {string} [params.name] - The unique name for this MongoConnectionManager instance. Defaults to 'default'.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { setupMongoConnectionManager } from '@nimbus-cqrs/mongodb';
|
|
121
|
+
* import { getEnv } from '@nimbus-cqrs/utils';
|
|
122
|
+
* import { ServerApiVersion } from 'mongodb';
|
|
123
|
+
*
|
|
124
|
+
* const env = getEnv({ variables: ['MONGO_URL'] });
|
|
125
|
+
*
|
|
126
|
+
* setupMongoConnectionManager({
|
|
127
|
+
* uri: env.MONGO_URL,
|
|
128
|
+
* options: {
|
|
129
|
+
* appName: 'my-app',
|
|
130
|
+
* serverApi: {
|
|
131
|
+
* version: ServerApiVersion.v1,
|
|
132
|
+
* strict: false,
|
|
133
|
+
* deprecationErrors: true,
|
|
134
|
+
* },
|
|
135
|
+
* },
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare const setupMongoConnectionManager: ({ uri, options, name }: {
|
|
140
|
+
uri: string;
|
|
141
|
+
options?: MongoClientOptions;
|
|
142
|
+
name?: string;
|
|
143
|
+
}) => void;
|
|
144
|
+
/**
|
|
145
|
+
* Get a named MongoConnectionManager instance.
|
|
146
|
+
*
|
|
147
|
+
* Returns the instance previously registered via
|
|
148
|
+
* {@link setupMongoConnectionManager}. Throws if no manager has been
|
|
149
|
+
* registered under the given `name` yet.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} [name] - The name of the MongoConnectionManager instance to retrieve. Defaults to 'default'.
|
|
152
|
+
*
|
|
153
|
+
* @returns {MongoConnectionManager} The registered MongoConnectionManager instance.
|
|
154
|
+
*
|
|
155
|
+
* @throws {Error} If no MongoConnectionManager has been registered under `name`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { getMongoConnectionManager } from '@nimbus-cqrs/mongodb';
|
|
160
|
+
*
|
|
161
|
+
* const mongoManager = getMongoConnectionManager();
|
|
162
|
+
* const collection = await mongoManager.getCollection('my-db', 'users');
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare const getMongoConnectionManager: (name?: string) => MongoConnectionManager;
|
|
107
166
|
//# sourceMappingURL=mongoConnectionManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoConnectionManager.d.ts","sourceRoot":"","sources":["../../src/lib/mongoConnectionManager.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,UAAU,EACf,KAAK,EAAE,EACP,WAAW,EACX,KAAK,kBAAkB,EAC1B,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAuC;IAC/D,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAqB;IAE/C;;;;;OAKG;IACH,OAAO;IAKP;;;;;;;;;OASG;WACW,WAAW,CACrB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,kBAAkB,GAC7B,sBAAsB;
|
|
1
|
+
{"version":3,"file":"mongoConnectionManager.d.ts","sourceRoot":"","sources":["../../src/lib/mongoConnectionManager.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,UAAU,EACf,KAAK,EAAE,EACP,WAAW,EACX,KAAK,kBAAkB,EAC1B,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAuC;IAC/D,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAqB;IAE/C;;;;;OAKG;IACH,OAAO;IAKP;;;;;;;;;OASG;WACW,WAAW,CACrB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,kBAAkB,GAC7B,sBAAsB;IASzB;;;;;;;;OAQG;IACI,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC;IAqCxC;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAKrD;;;;;;OAMG;IACU,aAAa,CACtB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACvB,OAAO,CAAC,UAAU,CAAC;IAKtB;;;;;OAKG;IACU,WAAW,IAAI,OAAO,CAC/B;QAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CACpD;IAeD;;;;;;;;OAQG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAqCtC;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,2BAA2B,GACpC,wBAAoC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,KACF,IAKF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,yBAAyB,GAClC,OAAM,MAAkB,KACzB,sBAUF,CAAC"}
|
|
@@ -62,9 +62,7 @@ export class MongoConnectionManager {
|
|
|
62
62
|
* @returns {MongoConnectionManager} The singleton instance of the MongoConnectionManager
|
|
63
63
|
*/
|
|
64
64
|
static getInstance(uri, options) {
|
|
65
|
-
|
|
66
|
-
MongoConnectionManager._instance = new MongoConnectionManager(uri, options);
|
|
67
|
-
}
|
|
65
|
+
MongoConnectionManager._instance ??= new MongoConnectionManager(uri, options);
|
|
68
66
|
return MongoConnectionManager._instance;
|
|
69
67
|
}
|
|
70
68
|
/**
|
|
@@ -193,3 +191,70 @@ export class MongoConnectionManager {
|
|
|
193
191
|
}
|
|
194
192
|
}
|
|
195
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Registry to store named MongoConnectionManager instances.
|
|
196
|
+
*/
|
|
197
|
+
const mongoConnectionManagerRegistry = new Map();
|
|
198
|
+
/**
|
|
199
|
+
* Setup a named MongoConnectionManager instance and register it for later retrieval.
|
|
200
|
+
*
|
|
201
|
+
* Use this function to configure a MongoConnectionManager at application
|
|
202
|
+
* startup, then retrieve it later with {@link getMongoConnectionManager}.
|
|
203
|
+
*
|
|
204
|
+
* @param {object} params - The setup parameters.
|
|
205
|
+
* @param {string} params.uri - The MongoDB connection URI.
|
|
206
|
+
* @param {MongoClientOptions} [params.options] - Options forwarded to the underlying `MongoClient`.
|
|
207
|
+
* @param {string} [params.name] - The unique name for this MongoConnectionManager instance. Defaults to 'default'.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { setupMongoConnectionManager } from '@nimbus-cqrs/mongodb';
|
|
212
|
+
* import { getEnv } from '@nimbus-cqrs/utils';
|
|
213
|
+
* import { ServerApiVersion } from 'mongodb';
|
|
214
|
+
*
|
|
215
|
+
* const env = getEnv({ variables: ['MONGO_URL'] });
|
|
216
|
+
*
|
|
217
|
+
* setupMongoConnectionManager({
|
|
218
|
+
* uri: env.MONGO_URL,
|
|
219
|
+
* options: {
|
|
220
|
+
* appName: 'my-app',
|
|
221
|
+
* serverApi: {
|
|
222
|
+
* version: ServerApiVersion.v1,
|
|
223
|
+
* strict: false,
|
|
224
|
+
* deprecationErrors: true,
|
|
225
|
+
* },
|
|
226
|
+
* },
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export const setupMongoConnectionManager = ({ uri, options, name = 'default' }) => {
|
|
231
|
+
mongoConnectionManagerRegistry.set(name, MongoConnectionManager.getInstance(uri, options));
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Get a named MongoConnectionManager instance.
|
|
235
|
+
*
|
|
236
|
+
* Returns the instance previously registered via
|
|
237
|
+
* {@link setupMongoConnectionManager}. Throws if no manager has been
|
|
238
|
+
* registered under the given `name` yet.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} [name] - The name of the MongoConnectionManager instance to retrieve. Defaults to 'default'.
|
|
241
|
+
*
|
|
242
|
+
* @returns {MongoConnectionManager} The registered MongoConnectionManager instance.
|
|
243
|
+
*
|
|
244
|
+
* @throws {Error} If no MongoConnectionManager has been registered under `name`.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { getMongoConnectionManager } from '@nimbus-cqrs/mongodb';
|
|
249
|
+
*
|
|
250
|
+
* const mongoManager = getMongoConnectionManager();
|
|
251
|
+
* const collection = await mongoManager.getCollection('my-db', 'users');
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export const getMongoConnectionManager = (name = 'default') => {
|
|
255
|
+
const instance = mongoConnectionManagerRegistry.get(name);
|
|
256
|
+
if (!instance) {
|
|
257
|
+
throw new Error(`MongoConnectionManager "${name}" has not been initialized. Call setupMongoConnectionManager({ name: "${name}", uri, options }) first.`);
|
|
258
|
+
}
|
|
259
|
+
return instance;
|
|
260
|
+
};
|
package/esm/lib/repository.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BulkWriteOptions, Collection, CountDocumentsOptions, DeleteOptions, Document, Filter, FindOptions, InsertOneOptions, ReplaceOptions, Sort } from 'mongodb';
|
|
1
|
+
import type { BulkWriteOptions, Collection, CountDocumentsOptions, DeleteOptions, Document, Filter, FindOptions, InsertOneOptions, ReplaceOptions, Sort, UpdateFilter, UpdateOptions, UpdateResult } from 'mongodb';
|
|
2
2
|
import type { ZodType } from 'zod';
|
|
3
3
|
/**
|
|
4
4
|
* Type for entities that have a string id.
|
|
@@ -113,6 +113,22 @@ export declare class MongoDBRepository<TEntity extends WithStringId<Record<strin
|
|
|
113
113
|
items: TEntity[];
|
|
114
114
|
options?: BulkWriteOptions;
|
|
115
115
|
}): Promise<TEntity[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Update a single document.
|
|
118
|
+
*/
|
|
119
|
+
updateOne({ filter, update, options, }: {
|
|
120
|
+
filter: Filter<Document>;
|
|
121
|
+
update: UpdateFilter<Document> | Document[];
|
|
122
|
+
options?: UpdateOptions;
|
|
123
|
+
}): Promise<UpdateResult<Document>>;
|
|
124
|
+
/**
|
|
125
|
+
* Update multiple documents.
|
|
126
|
+
*/
|
|
127
|
+
updateMany({ filter, update, options, }: {
|
|
128
|
+
filter: Filter<Document>;
|
|
129
|
+
update: UpdateFilter<Document> | Document[];
|
|
130
|
+
options?: UpdateOptions;
|
|
131
|
+
}): Promise<UpdateResult<Document>>;
|
|
116
132
|
/**
|
|
117
133
|
* Replace a single document.
|
|
118
134
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/lib/repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,gBAAgB,EAChB,UAAU,EACV,qBAAqB,EACrB,aAAa,EACb,QAAQ,EACR,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,IAAI,
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/lib/repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,gBAAgB,EAChB,UAAU,EACV,qBAAqB,EACrB,aAAa,EACb,QAAQ,EACR,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,YAAY,EACf,MAAM,SAAS,CAAC;AA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EACpB,IAAI,EACJ,OAAO,GACV,EAAE;QACC,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,CAAC,EAAE,cAAc,CAAC;KAC5B,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BpB;;OAEG;IACU,WAAW,CAAC,EACrB,KAAK,EACL,OAAO,GACV,EAAE;QACC,KAAK,EAAE,OAAO,EAAE,CAAC;QACjB,OAAO,CAAC,EAAE,gBAAgB,CAAC;KAC9B,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAqBtB;;OAEG;IACU,SAAS,CAAC,EACnB,IAAI,EACJ,OAAO,GACV,EAAE;QACC,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,CAAC,EAAE,aAAa,CAAC;KAC3B,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBpB;;OAEG;IACU,UAAU,CAAC,EACpB,KAAK,EACL,OAAO,GACV,EAAE;QACC,KAAK,EAAE,OAAO,EAAE,CAAC;QACjB,OAAO,CAAC,EAAE,aAAa,CAAC;KAC3B,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAazB"}
|
package/esm/lib/repository.js
CHANGED
|
@@ -10,6 +10,8 @@ import { findOne } from './crud/findOne.js';
|
|
|
10
10
|
import { insertMany } from './crud/insertMany.js';
|
|
11
11
|
import { insertOne } from './crud/insertOne.js';
|
|
12
12
|
import { replaceOne } from './crud/replaceOne.js';
|
|
13
|
+
import { updateMany } from './crud/updateMany.js';
|
|
14
|
+
import { updateOne } from './crud/updateOne.js';
|
|
13
15
|
/**
|
|
14
16
|
* Repository for interacting with a MongoDB Collection
|
|
15
17
|
* which provides a type-safe interface for MongoDB CRUD operations.
|
|
@@ -101,7 +103,7 @@ export class MongoDBRepository {
|
|
|
101
103
|
return res;
|
|
102
104
|
}
|
|
103
105
|
catch (error) {
|
|
104
|
-
if (error.name === '
|
|
106
|
+
if (error.name === 'NOT_FOUND') {
|
|
105
107
|
throw new NotFoundException(`${this._entityName} not found`, {
|
|
106
108
|
errorCode: `${toSnakeCase(this._entityName).toUpperCase()}_NOT_FOUND`,
|
|
107
109
|
reason: `Could not find ${this._entityName} matching the given filter`,
|
|
@@ -161,6 +163,38 @@ export class MongoDBRepository {
|
|
|
161
163
|
});
|
|
162
164
|
return items;
|
|
163
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Update a single document.
|
|
168
|
+
*/
|
|
169
|
+
async updateOne({ filter, update, options, }) {
|
|
170
|
+
const collection = await this._getCollection();
|
|
171
|
+
const res = await updateOne({
|
|
172
|
+
collection,
|
|
173
|
+
filter,
|
|
174
|
+
update,
|
|
175
|
+
options,
|
|
176
|
+
});
|
|
177
|
+
if (res.matchedCount === 0) {
|
|
178
|
+
throw new NotFoundException(`${this._entityName} not found`, {
|
|
179
|
+
errorCode: `${toSnakeCase(this._entityName).toUpperCase()}_NOT_FOUND`,
|
|
180
|
+
reason: `Could not find ${this._entityName} matching the given filter`,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return res;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Update multiple documents.
|
|
187
|
+
*/
|
|
188
|
+
async updateMany({ filter, update, options, }) {
|
|
189
|
+
const collection = await this._getCollection();
|
|
190
|
+
const res = await updateMany({
|
|
191
|
+
collection,
|
|
192
|
+
filter,
|
|
193
|
+
update,
|
|
194
|
+
options,
|
|
195
|
+
});
|
|
196
|
+
return res;
|
|
197
|
+
}
|
|
164
198
|
/**
|
|
165
199
|
* Replace a single document.
|
|
166
200
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbus-cqrs/mongodb",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Simplify Event-Driven Applications - MongoDB integration for the Nimbus framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nimbus",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@opentelemetry/api": "^1.9.1",
|
|
36
36
|
"mongodb": "^7.1.1",
|
|
37
37
|
"zod": "^4.3.6",
|
|
38
|
-
"@nimbus-cqrs/core": "^2.
|
|
38
|
+
"@nimbus-cqrs/core": "^2.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^22.0.0"
|