@xylabs/mongo 5.0.84 → 5.0.86

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 (2) hide show
  1. package/README.md +112 -244
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
  Base functionality used throughout XYO TypeScript/JavaScript libraries that access Mongo DB
17
17
 
18
+
19
+
18
20
  ## Reference
19
21
 
20
22
  **@xylabs/mongo**
@@ -23,17 +25,23 @@ Base functionality used throughout XYO TypeScript/JavaScript libraries that acce
23
25
 
24
26
  ## Classes
25
27
 
26
- - [BaseMongoSdk](#classes/BaseMongoSdk)
27
- - [MongoClientWrapper](#classes/MongoClientWrapper)
28
+ | Class | Description |
29
+ | ------ | ------ |
30
+ | [BaseMongoSdk](#classes/BaseMongoSdk) | Provides a typed wrapper around common MongoDB collection operations. |
31
+ | [MongoClientWrapper](#classes/MongoClientWrapper) | Manages a shared pool of MongoClient instances, reusing connections by URI. |
28
32
 
29
33
  ## Interfaces
30
34
 
31
- - [BaseMongoSdkPublicConfig](#interfaces/BaseMongoSdkPublicConfig)
32
- - [BaseMongoSdkPrivateConfig](#interfaces/BaseMongoSdkPrivateConfig)
35
+ | Interface | Description |
36
+ | ------ | ------ |
37
+ | [BaseMongoSdkPublicConfig](#interfaces/BaseMongoSdkPublicConfig) | Public configuration options for the Mongo SDK, safe to expose to clients. |
38
+ | [BaseMongoSdkPrivateConfig](#interfaces/BaseMongoSdkPrivateConfig) | Private configuration options for the Mongo SDK containing connection credentials. |
33
39
 
34
40
  ## Type Aliases
35
41
 
36
- - [BaseMongoSdkConfig](#type-aliases/BaseMongoSdkConfig)
42
+ | Type Alias | Description |
43
+ | ------ | ------ |
44
+ | [BaseMongoSdkConfig](#type-aliases/BaseMongoSdkConfig) | Combined public and private MongoDB SDK configuration. |
37
45
 
38
46
  ### classes
39
47
 
@@ -47,23 +55,23 @@ Provides a typed wrapper around common MongoDB collection operations.
47
55
 
48
56
  ## Type Parameters
49
57
 
50
- ### T
51
-
52
- `T` *extends* `Document`
58
+ | Type Parameter |
59
+ | ------ |
60
+ | `T` *extends* `Document` |
53
61
 
54
62
  ## Constructors
55
63
 
56
64
  ### Constructor
57
65
 
58
66
  ```ts
59
- new BaseMongoSdk<T>(config): BaseMongoSdk<T>;
67
+ new BaseMongoSdk<T>(config: BaseMongoSdkConfig): BaseMongoSdk<T>;
60
68
  ```
61
69
 
62
70
  ### Parameters
63
71
 
64
- #### config
65
-
66
- [`BaseMongoSdkConfig`](#../type-aliases/BaseMongoSdkConfig)
72
+ | Parameter | Type |
73
+ | ------ | ------ |
74
+ | `config` | [`BaseMongoSdkConfig`](#../type-aliases/BaseMongoSdkConfig) |
67
75
 
68
76
  ### Returns
69
77
 
@@ -71,13 +79,9 @@ new BaseMongoSdk<T>(config): BaseMongoSdk<T>;
71
79
 
72
80
  ## Properties
73
81
 
74
- ### config
75
-
76
- ```ts
77
- config: BaseMongoSdkConfig;
78
- ```
79
-
80
- The MongoDB SDK configuration for this instance.
82
+ | Property | Type | Description |
83
+ | ------ | ------ | ------ |
84
+ | <a id="config"></a> `config` | [`BaseMongoSdkConfig`](#../type-aliases/BaseMongoSdkConfig) | The MongoDB SDK configuration for this instance. |
81
85
 
82
86
  ## Accessors
83
87
 
@@ -100,18 +104,16 @@ Returns the MongoDB connection URI, either from the config or constructed from i
100
104
  ### deleteMany()
101
105
 
102
106
  ```ts
103
- deleteMany(filter): Promise<DeleteResult>;
107
+ deleteMany(filter: Filter<T>): Promise<DeleteResult>;
104
108
  ```
105
109
 
106
110
  Deletes all documents matching the filter.
107
111
 
108
112
  ### Parameters
109
113
 
110
- #### filter
111
-
112
- `Filter`\<`T`\>
113
-
114
- The query filter to match documents for deletion
114
+ | Parameter | Type | Description |
115
+ | ------ | ------ | ------ |
116
+ | `filter` | `Filter`\<`T`\> | The query filter to match documents for deletion |
115
117
 
116
118
  ### Returns
117
119
 
@@ -122,18 +124,16 @@ The query filter to match documents for deletion
122
124
  ### deleteOne()
123
125
 
124
126
  ```ts
125
- deleteOne(filter): Promise<DeleteResult>;
127
+ deleteOne(filter: Filter<T>): Promise<DeleteResult>;
126
128
  ```
127
129
 
128
130
  Deletes the first document matching the filter.
129
131
 
130
132
  ### Parameters
131
133
 
132
- #### filter
133
-
134
- `Filter`\<`T`\>
135
-
136
- The query filter to match a document for deletion
134
+ | Parameter | Type | Description |
135
+ | ------ | ------ | ------ |
136
+ | `filter` | `Filter`\<`T`\> | The query filter to match a document for deletion |
137
137
 
138
138
  ### Returns
139
139
 
@@ -144,18 +144,16 @@ The query filter to match a document for deletion
144
144
  ### find()
145
145
 
146
146
  ```ts
147
- find(filter): Promise<FindCursor<WithId<T>>>;
147
+ find(filter: Filter<T>): Promise<FindCursor<WithId<T>>>;
148
148
  ```
149
149
 
150
150
  Finds all documents matching the filter and returns a cursor.
151
151
 
152
152
  ### Parameters
153
153
 
154
- #### filter
155
-
156
- `Filter`\<`T`\>
157
-
158
- The query filter
154
+ | Parameter | Type | Description |
155
+ | ------ | ------ | ------ |
156
+ | `filter` | `Filter`\<`T`\> | The query filter |
159
157
 
160
158
  ### Returns
161
159
 
@@ -166,18 +164,16 @@ The query filter
166
164
  ### findOne()
167
165
 
168
166
  ```ts
169
- findOne(filter): Promise<WithId<T> | null>;
167
+ findOne(filter: Filter<T>): Promise<WithId<T> | null>;
170
168
  ```
171
169
 
172
170
  Finds a single document matching the filter.
173
171
 
174
172
  ### Parameters
175
173
 
176
- #### filter
177
-
178
- `Filter`\<`T`\>
179
-
180
- The query filter
174
+ | Parameter | Type | Description |
175
+ | ------ | ------ | ------ |
176
+ | `filter` | `Filter`\<`T`\> | The query filter |
181
177
 
182
178
  ### Returns
183
179
 
@@ -190,24 +186,17 @@ The matched document, or `null` if not found
190
186
  ### insertMany()
191
187
 
192
188
  ```ts
193
- insertMany(items, options?): Promise<InsertManyResult<T>>;
189
+ insertMany(items: OptionalUnlessRequiredId<T>[], options?: BulkWriteOptions): Promise<InsertManyResult<T>>;
194
190
  ```
195
191
 
196
192
  Inserts multiple documents into the collection.
197
193
 
198
194
  ### Parameters
199
195
 
200
- #### items
201
-
202
- `OptionalUnlessRequiredId`\<`T`\>[]
203
-
204
- The documents to insert
205
-
206
- #### options?
207
-
208
- `BulkWriteOptions`
209
-
210
- Optional bulk write options
196
+ | Parameter | Type | Description |
197
+ | ------ | ------ | ------ |
198
+ | `items` | `OptionalUnlessRequiredId`\<`T`\>[] | The documents to insert |
199
+ | `options?` | `BulkWriteOptions` | Optional bulk write options |
211
200
 
212
201
  ### Returns
213
202
 
@@ -218,24 +207,17 @@ Optional bulk write options
218
207
  ### insertOne()
219
208
 
220
209
  ```ts
221
- insertOne(item, options?): Promise<InsertOneResult<T>>;
210
+ insertOne(item: OptionalUnlessRequiredId<T>, options?: InsertOneOptions): Promise<InsertOneResult<T>>;
222
211
  ```
223
212
 
224
213
  Inserts a single document into the collection.
225
214
 
226
215
  ### Parameters
227
216
 
228
- #### item
229
-
230
- `OptionalUnlessRequiredId`\<`T`\>
231
-
232
- The document to insert
233
-
234
- #### options?
235
-
236
- `InsertOneOptions`
237
-
238
- Optional insert options
217
+ | Parameter | Type | Description |
218
+ | ------ | ------ | ------ |
219
+ | `item` | `OptionalUnlessRequiredId`\<`T`\> | The document to insert |
220
+ | `options?` | `InsertOneOptions` | Optional insert options |
239
221
 
240
222
  ### Returns
241
223
 
@@ -247,32 +229,20 @@ Optional insert options
247
229
 
248
230
  ```ts
249
231
  replaceOne(
250
- filter,
251
- item,
252
- options?): Promise<UpdateResult<T>>;
232
+ filter: Filter<T>,
233
+ item: OptionalUnlessRequiredId<T>,
234
+ options?: ReplaceOptions): Promise<UpdateResult<T>>;
253
235
  ```
254
236
 
255
237
  Replaces a single document matching the filter.
256
238
 
257
239
  ### Parameters
258
240
 
259
- #### filter
260
-
261
- `Filter`\<`T`\>
262
-
263
- The query filter to match the document
264
-
265
- #### item
266
-
267
- `OptionalUnlessRequiredId`\<`T`\>
268
-
269
- The replacement document
270
-
271
- #### options?
272
-
273
- `ReplaceOptions`
274
-
275
- Optional replace options
241
+ | Parameter | Type | Description |
242
+ | ------ | ------ | ------ |
243
+ | `filter` | `Filter`\<`T`\> | The query filter to match the document |
244
+ | `item` | `OptionalUnlessRequiredId`\<`T`\> | The replacement document |
245
+ | `options?` | `ReplaceOptions` | Optional replace options |
276
246
 
277
247
  ### Returns
278
248
 
@@ -283,24 +253,17 @@ Optional replace options
283
253
  ### updateOne()
284
254
 
285
255
  ```ts
286
- updateOne(filter, fields): Promise<UpdateResult<T>>;
256
+ updateOne(filter: Filter<T>, fields: UpdateFilter<T>): Promise<UpdateResult<T>>;
287
257
  ```
288
258
 
289
259
  Updates a single document matching the filter without upserting.
290
260
 
291
261
  ### Parameters
292
262
 
293
- #### filter
294
-
295
- `Filter`\<`T`\>
296
-
297
- The query filter to match the document
298
-
299
- #### fields
300
-
301
- `UpdateFilter`\<`T`\>
302
-
303
- The update operations to apply
263
+ | Parameter | Type | Description |
264
+ | ------ | ------ | ------ |
265
+ | `filter` | `Filter`\<`T`\> | The query filter to match the document |
266
+ | `fields` | `UpdateFilter`\<`T`\> | The update operations to apply |
304
267
 
305
268
  ### Returns
306
269
 
@@ -311,24 +274,17 @@ The update operations to apply
311
274
  ### upsertOne()
312
275
 
313
276
  ```ts
314
- upsertOne(filter, fields): Promise<UpdateResult<T>>;
277
+ upsertOne(filter: Filter<T>, fields: UpdateFilter<T>): Promise<UpdateResult<T>>;
315
278
  ```
316
279
 
317
280
  Updates a single document matching the filter, inserting it if it does not exist.
318
281
 
319
282
  ### Parameters
320
283
 
321
- #### filter
322
-
323
- `Filter`\<`T`\>
324
-
325
- The query filter to match the document
326
-
327
- #### fields
328
-
329
- `UpdateFilter`\<`T`\>
330
-
331
- The update operations to apply
284
+ | Parameter | Type | Description |
285
+ | ------ | ------ | ------ |
286
+ | `filter` | `Filter`\<`T`\> | The query filter to match the document |
287
+ | `fields` | `UpdateFilter`\<`T`\> | The update operations to apply |
332
288
 
333
289
  ### Returns
334
290
 
@@ -339,24 +295,22 @@ The update operations to apply
339
295
  ### useCollection()
340
296
 
341
297
  ```ts
342
- useCollection<R>(func): Promise<R>;
298
+ useCollection<R>(func: (collection: Collection<T>) => R | Promise<R>): Promise<R>;
343
299
  ```
344
300
 
345
301
  Executes a callback with access to the configured MongoDB collection.
346
302
 
347
303
  ### Type Parameters
348
304
 
349
- #### R
350
-
351
- `R`
305
+ | Type Parameter |
306
+ | ------ |
307
+ | `R` |
352
308
 
353
309
  ### Parameters
354
310
 
355
- #### func
356
-
357
- (`collection`) => `R` \| `Promise`\<`R`\>
358
-
359
- A callback receiving the typed collection
311
+ | Parameter | Type | Description |
312
+ | ------ | ------ | ------ |
313
+ | `func` | (`collection`: `Collection`\<`T`\>) => `R` \| `Promise`\<`R`\> | A callback receiving the typed collection |
360
314
 
361
315
  ### Returns
362
316
 
@@ -369,24 +323,22 @@ The result of the callback
369
323
  ### useMongo()
370
324
 
371
325
  ```ts
372
- useMongo<R>(func): Promise<R>;
326
+ useMongo<R>(func: (client: MongoClient) => R | Promise<R>): Promise<R>;
373
327
  ```
374
328
 
375
329
  Executes a callback with a connected MongoClient, handling connection and disconnection.
376
330
 
377
331
  ### Type Parameters
378
332
 
379
- #### R
380
-
381
- `R`
333
+ | Type Parameter |
334
+ | ------ |
335
+ | `R` |
382
336
 
383
337
  ### Parameters
384
338
 
385
- #### func
386
-
387
- (`client`) => `R` \| `Promise`\<`R`\>
388
-
389
- A callback receiving the connected MongoClient
339
+ | Parameter | Type | Description |
340
+ | ------ | ------ | ------ |
341
+ | `func` | (`client`: `MongoClient`) => `R` \| `Promise`\<`R`\> | A callback receiving the connected MongoClient |
390
342
 
391
343
  ### Returns
392
344
 
@@ -408,24 +360,18 @@ Manages a shared pool of MongoClient instances, reusing connections by URI.
408
360
 
409
361
  ```ts
410
362
  new MongoClientWrapper(
411
- uri,
412
- maxPoolSize?,
413
- closeDelay?): MongoClientWrapper;
363
+ uri: string,
364
+ maxPoolSize?: number,
365
+ closeDelay?: number): MongoClientWrapper;
414
366
  ```
415
367
 
416
368
  ### Parameters
417
369
 
418
- #### uri
419
-
420
- `string`
421
-
422
- #### maxPoolSize?
423
-
424
- `number`
425
-
426
- #### closeDelay?
427
-
428
- `number`
370
+ | Parameter | Type |
371
+ | ------ | ------ |
372
+ | `uri` | `string` |
373
+ | `maxPoolSize?` | `number` |
374
+ | `closeDelay?` | `number` |
429
375
 
430
376
  ### Returns
431
377
 
@@ -433,13 +379,9 @@ new MongoClientWrapper(
433
379
 
434
380
  ## Properties
435
381
 
436
- ### clients
437
-
438
- ```ts
439
- readonly static clients: Map<string, MongoClientWrapper>;
440
- ```
441
-
442
- Global cache of wrapper instances keyed by connection URI.
382
+ | Property | Modifier | Type | Description |
383
+ | ------ | ------ | ------ | ------ |
384
+ | <a id="clients"></a> `clients` | `readonly` | `Map`\<`string`, `MongoClientWrapper`\> | Global cache of wrapper instances keyed by connection URI. |
443
385
 
444
386
  ## Methods
445
387
 
@@ -447,32 +389,20 @@ Global cache of wrapper instances keyed by connection URI.
447
389
 
448
390
  ```ts
449
391
  static get(
450
- uri,
451
- poolSize?,
452
- closeDelay?): MongoClientWrapper;
392
+ uri: string,
393
+ poolSize?: number,
394
+ closeDelay?: number): MongoClientWrapper;
453
395
  ```
454
396
 
455
397
  Gets or creates a cached MongoClientWrapper for the given URI.
456
398
 
457
399
  ### Parameters
458
400
 
459
- #### uri
460
-
461
- `string`
462
-
463
- The MongoDB connection URI
464
-
465
- #### poolSize?
466
-
467
- `number`
468
-
469
- Maximum connection pool size
470
-
471
- #### closeDelay?
472
-
473
- `number`
474
-
475
- Delay in milliseconds before closing idle connections
401
+ | Parameter | Type | Description |
402
+ | ------ | ------ | ------ |
403
+ | `uri` | `string` | The MongoDB connection URI |
404
+ | `poolSize?` | `number` | Maximum connection pool size |
405
+ | `closeDelay?` | `number` | Delay in milliseconds before closing idle connections |
476
406
 
477
407
  ### Returns
478
408
 
@@ -534,53 +464,13 @@ Private configuration options for the Mongo SDK containing connection credential
534
464
 
535
465
  ## Properties
536
466
 
537
- ### dbConnectionString?
538
-
539
- ```ts
540
- optional dbConnectionString: string;
541
- ```
542
-
543
- A full MongoDB connection string, used instead of individual credential fields.
544
-
545
- ***
546
-
547
- ### dbDomain?
548
-
549
- ```ts
550
- optional dbDomain: string;
551
- ```
552
-
553
- The MongoDB Atlas cluster domain.
554
-
555
- ***
556
-
557
- ### dbName?
558
-
559
- ```ts
560
- optional dbName: string;
561
- ```
562
-
563
- The database name to connect to.
564
-
565
- ***
566
-
567
- ### dbPassword?
568
-
569
- ```ts
570
- optional dbPassword: string;
571
- ```
572
-
573
- The password for MongoDB authentication.
574
-
575
- ***
576
-
577
- ### dbUserName?
578
-
579
- ```ts
580
- optional dbUserName: string;
581
- ```
582
-
583
- The username for MongoDB authentication.
467
+ | Property | Type | Description |
468
+ | ------ | ------ | ------ |
469
+ | <a id="dbconnectionstring"></a> `dbConnectionString?` | `string` | A full MongoDB connection string, used instead of individual credential fields. |
470
+ | <a id="dbdomain"></a> `dbDomain?` | `string` | The MongoDB Atlas cluster domain. |
471
+ | <a id="dbname"></a> `dbName?` | `string` | The database name to connect to. |
472
+ | <a id="dbpassword"></a> `dbPassword?` | `string` | The password for MongoDB authentication. |
473
+ | <a id="dbusername"></a> `dbUserName?` | `string` | The username for MongoDB authentication. |
584
474
 
585
475
  ### <a id="BaseMongoSdkPublicConfig"></a>BaseMongoSdkPublicConfig
586
476
 
@@ -592,33 +482,11 @@ Public configuration options for the Mongo SDK, safe to expose to clients.
592
482
 
593
483
  ## Properties
594
484
 
595
- ### closeDelay?
596
-
597
- ```ts
598
- optional closeDelay: number;
599
- ```
600
-
601
- Delay in milliseconds before closing idle connections.
602
-
603
- ***
604
-
605
- ### collection
606
-
607
- ```ts
608
- collection: string;
609
- ```
610
-
611
- The MongoDB collection name to operate on.
612
-
613
- ***
614
-
615
- ### maxPoolSize?
616
-
617
- ```ts
618
- optional maxPoolSize: number;
619
- ```
620
-
621
- Maximum number of connections in the connection pool.
485
+ | Property | Type | Description |
486
+ | ------ | ------ | ------ |
487
+ | <a id="closedelay"></a> `closeDelay?` | `number` | Delay in milliseconds before closing idle connections. |
488
+ | <a id="collection"></a> `collection` | `string` | The MongoDB collection name to operate on. |
489
+ | <a id="maxpoolsize"></a> `maxPoolSize?` | `number` | Maximum number of connections in the connection pool. |
622
490
 
623
491
  ### type-aliases
624
492
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/mongo",
3
- "version": "5.0.84",
3
+ "version": "5.0.86",
4
4
  "description": "Base functionality used throughout XYO TypeScript/JavaScript libraries that access Mongo DB",
5
5
  "keywords": [
6
6
  "mongo",
@@ -46,10 +46,10 @@
46
46
  "!**/*.test.*"
47
47
  ],
48
48
  "dependencies": {
49
- "@xylabs/assert": "~5.0.84"
49
+ "@xylabs/assert": "~5.0.86"
50
50
  },
51
51
  "devDependencies": {
52
- "@xylabs/tsconfig": "~7.4.13",
52
+ "@xylabs/tsconfig": "~7.4.16",
53
53
  "mongodb": "^7.1.0",
54
54
  "typescript": "~5.9.3",
55
55
  "vitest": "~4.0.18"