@xylabs/mongo 5.0.83 → 5.0.84

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 +110 -0
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -43,6 +43,8 @@ Base functionality used throughout XYO TypeScript/JavaScript libraries that acce
43
43
 
44
44
  ***
45
45
 
46
+ Provides a typed wrapper around common MongoDB collection operations.
47
+
46
48
  ## Type Parameters
47
49
 
48
50
  ### T
@@ -75,6 +77,8 @@ new BaseMongoSdk<T>(config): BaseMongoSdk<T>;
75
77
  config: BaseMongoSdkConfig;
76
78
  ```
77
79
 
80
+ The MongoDB SDK configuration for this instance.
81
+
78
82
  ## Accessors
79
83
 
80
84
  ### uri
@@ -85,6 +89,8 @@ config: BaseMongoSdkConfig;
85
89
  get uri(): string;
86
90
  ```
87
91
 
92
+ Returns the MongoDB connection URI, either from the config or constructed from individual credential fields.
93
+
88
94
  #### Returns
89
95
 
90
96
  `string`
@@ -97,12 +103,16 @@ get uri(): string;
97
103
  deleteMany(filter): Promise<DeleteResult>;
98
104
  ```
99
105
 
106
+ Deletes all documents matching the filter.
107
+
100
108
  ### Parameters
101
109
 
102
110
  #### filter
103
111
 
104
112
  `Filter`\<`T`\>
105
113
 
114
+ The query filter to match documents for deletion
115
+
106
116
  ### Returns
107
117
 
108
118
  `Promise`\<`DeleteResult`\>
@@ -115,12 +125,16 @@ deleteMany(filter): Promise<DeleteResult>;
115
125
  deleteOne(filter): Promise<DeleteResult>;
116
126
  ```
117
127
 
128
+ Deletes the first document matching the filter.
129
+
118
130
  ### Parameters
119
131
 
120
132
  #### filter
121
133
 
122
134
  `Filter`\<`T`\>
123
135
 
136
+ The query filter to match a document for deletion
137
+
124
138
  ### Returns
125
139
 
126
140
  `Promise`\<`DeleteResult`\>
@@ -133,12 +147,16 @@ deleteOne(filter): Promise<DeleteResult>;
133
147
  find(filter): Promise<FindCursor<WithId<T>>>;
134
148
  ```
135
149
 
150
+ Finds all documents matching the filter and returns a cursor.
151
+
136
152
  ### Parameters
137
153
 
138
154
  #### filter
139
155
 
140
156
  `Filter`\<`T`\>
141
157
 
158
+ The query filter
159
+
142
160
  ### Returns
143
161
 
144
162
  `Promise`\<`FindCursor`\<`WithId`\<`T`\>\>\>
@@ -151,16 +169,22 @@ find(filter): Promise<FindCursor<WithId<T>>>;
151
169
  findOne(filter): Promise<WithId<T> | null>;
152
170
  ```
153
171
 
172
+ Finds a single document matching the filter.
173
+
154
174
  ### Parameters
155
175
 
156
176
  #### filter
157
177
 
158
178
  `Filter`\<`T`\>
159
179
 
180
+ The query filter
181
+
160
182
  ### Returns
161
183
 
162
184
  `Promise`\<`WithId`\<`T`\> \| `null`\>
163
185
 
186
+ The matched document, or `null` if not found
187
+
164
188
  ***
165
189
 
166
190
  ### insertMany()
@@ -169,16 +193,22 @@ findOne(filter): Promise<WithId<T> | null>;
169
193
  insertMany(items, options?): Promise<InsertManyResult<T>>;
170
194
  ```
171
195
 
196
+ Inserts multiple documents into the collection.
197
+
172
198
  ### Parameters
173
199
 
174
200
  #### items
175
201
 
176
202
  `OptionalUnlessRequiredId`\<`T`\>[]
177
203
 
204
+ The documents to insert
205
+
178
206
  #### options?
179
207
 
180
208
  `BulkWriteOptions`
181
209
 
210
+ Optional bulk write options
211
+
182
212
  ### Returns
183
213
 
184
214
  `Promise`\<`InsertManyResult`\<`T`\>\>
@@ -191,16 +221,22 @@ insertMany(items, options?): Promise<InsertManyResult<T>>;
191
221
  insertOne(item, options?): Promise<InsertOneResult<T>>;
192
222
  ```
193
223
 
224
+ Inserts a single document into the collection.
225
+
194
226
  ### Parameters
195
227
 
196
228
  #### item
197
229
 
198
230
  `OptionalUnlessRequiredId`\<`T`\>
199
231
 
232
+ The document to insert
233
+
200
234
  #### options?
201
235
 
202
236
  `InsertOneOptions`
203
237
 
238
+ Optional insert options
239
+
204
240
  ### Returns
205
241
 
206
242
  `Promise`\<`InsertOneResult`\<`T`\>\>
@@ -216,20 +252,28 @@ replaceOne(
216
252
  options?): Promise<UpdateResult<T>>;
217
253
  ```
218
254
 
255
+ Replaces a single document matching the filter.
256
+
219
257
  ### Parameters
220
258
 
221
259
  #### filter
222
260
 
223
261
  `Filter`\<`T`\>
224
262
 
263
+ The query filter to match the document
264
+
225
265
  #### item
226
266
 
227
267
  `OptionalUnlessRequiredId`\<`T`\>
228
268
 
269
+ The replacement document
270
+
229
271
  #### options?
230
272
 
231
273
  `ReplaceOptions`
232
274
 
275
+ Optional replace options
276
+
233
277
  ### Returns
234
278
 
235
279
  `Promise`\<`UpdateResult`\<`T`\>\>
@@ -242,16 +286,22 @@ options?): Promise<UpdateResult<T>>;
242
286
  updateOne(filter, fields): Promise<UpdateResult<T>>;
243
287
  ```
244
288
 
289
+ Updates a single document matching the filter without upserting.
290
+
245
291
  ### Parameters
246
292
 
247
293
  #### filter
248
294
 
249
295
  `Filter`\<`T`\>
250
296
 
297
+ The query filter to match the document
298
+
251
299
  #### fields
252
300
 
253
301
  `UpdateFilter`\<`T`\>
254
302
 
303
+ The update operations to apply
304
+
255
305
  ### Returns
256
306
 
257
307
  `Promise`\<`UpdateResult`\<`T`\>\>
@@ -264,16 +314,22 @@ updateOne(filter, fields): Promise<UpdateResult<T>>;
264
314
  upsertOne(filter, fields): Promise<UpdateResult<T>>;
265
315
  ```
266
316
 
317
+ Updates a single document matching the filter, inserting it if it does not exist.
318
+
267
319
  ### Parameters
268
320
 
269
321
  #### filter
270
322
 
271
323
  `Filter`\<`T`\>
272
324
 
325
+ The query filter to match the document
326
+
273
327
  #### fields
274
328
 
275
329
  `UpdateFilter`\<`T`\>
276
330
 
331
+ The update operations to apply
332
+
277
333
  ### Returns
278
334
 
279
335
  `Promise`\<`UpdateResult`\<`T`\>\>
@@ -286,6 +342,8 @@ upsertOne(filter, fields): Promise<UpdateResult<T>>;
286
342
  useCollection<R>(func): Promise<R>;
287
343
  ```
288
344
 
345
+ Executes a callback with access to the configured MongoDB collection.
346
+
289
347
  ### Type Parameters
290
348
 
291
349
  #### R
@@ -298,10 +356,14 @@ useCollection<R>(func): Promise<R>;
298
356
 
299
357
  (`collection`) => `R` \| `Promise`\<`R`\>
300
358
 
359
+ A callback receiving the typed collection
360
+
301
361
  ### Returns
302
362
 
303
363
  `Promise`\<`R`\>
304
364
 
365
+ The result of the callback
366
+
305
367
  ***
306
368
 
307
369
  ### useMongo()
@@ -310,6 +372,8 @@ useCollection<R>(func): Promise<R>;
310
372
  useMongo<R>(func): Promise<R>;
311
373
  ```
312
374
 
375
+ Executes a callback with a connected MongoClient, handling connection and disconnection.
376
+
313
377
  ### Type Parameters
314
378
 
315
379
  #### R
@@ -322,16 +386,22 @@ useMongo<R>(func): Promise<R>;
322
386
 
323
387
  (`client`) => `R` \| `Promise`\<`R`\>
324
388
 
389
+ A callback receiving the connected MongoClient
390
+
325
391
  ### Returns
326
392
 
327
393
  `Promise`\<`R`\>
328
394
 
395
+ The result of the callback
396
+
329
397
  ### <a id="MongoClientWrapper"></a>MongoClientWrapper
330
398
 
331
399
  [**@xylabs/mongo**](#../README)
332
400
 
333
401
  ***
334
402
 
403
+ Manages a shared pool of MongoClient instances, reusing connections by URI.
404
+
335
405
  ## Constructors
336
406
 
337
407
  ### Constructor
@@ -369,6 +439,8 @@ new MongoClientWrapper(
369
439
  readonly static clients: Map<string, MongoClientWrapper>;
370
440
  ```
371
441
 
442
+ Global cache of wrapper instances keyed by connection URI.
443
+
372
444
  ## Methods
373
445
 
374
446
  ### get()
@@ -380,24 +452,34 @@ static get(
380
452
  closeDelay?): MongoClientWrapper;
381
453
  ```
382
454
 
455
+ Gets or creates a cached MongoClientWrapper for the given URI.
456
+
383
457
  ### Parameters
384
458
 
385
459
  #### uri
386
460
 
387
461
  `string`
388
462
 
463
+ The MongoDB connection URI
464
+
389
465
  #### poolSize?
390
466
 
391
467
  `number`
392
468
 
469
+ Maximum connection pool size
470
+
393
471
  #### closeDelay?
394
472
 
395
473
  `number`
396
474
 
475
+ Delay in milliseconds before closing idle connections
476
+
397
477
  ### Returns
398
478
 
399
479
  `MongoClientWrapper`
400
480
 
481
+ A cached or newly created wrapper instance
482
+
401
483
  ***
402
484
 
403
485
  ### connect()
@@ -406,6 +488,8 @@ static get(
406
488
  connect(): Promise<MongoClient>;
407
489
  ```
408
490
 
491
+ Connects to MongoDB and returns the underlying MongoClient.
492
+
409
493
  ### Returns
410
494
 
411
495
  `Promise`\<`MongoClient`\>
@@ -418,6 +502,8 @@ connect(): Promise<MongoClient>;
418
502
  disconnect(): Promise<number>;
419
503
  ```
420
504
 
505
+ Disconnects from MongoDB.
506
+
421
507
  ### Returns
422
508
 
423
509
  `Promise`\<`number`\>
@@ -430,6 +516,8 @@ disconnect(): Promise<number>;
430
516
  initiateClose(): Promise<void>;
431
517
  ```
432
518
 
519
+ Initiates a graceful close of the connection.
520
+
433
521
  ### Returns
434
522
 
435
523
  `Promise`\<`void`\>
@@ -442,6 +530,8 @@ initiateClose(): Promise<void>;
442
530
 
443
531
  ***
444
532
 
533
+ Private configuration options for the Mongo SDK containing connection credentials.
534
+
445
535
  ## Properties
446
536
 
447
537
  ### dbConnectionString?
@@ -450,6 +540,8 @@ initiateClose(): Promise<void>;
450
540
  optional dbConnectionString: string;
451
541
  ```
452
542
 
543
+ A full MongoDB connection string, used instead of individual credential fields.
544
+
453
545
  ***
454
546
 
455
547
  ### dbDomain?
@@ -458,6 +550,8 @@ optional dbConnectionString: string;
458
550
  optional dbDomain: string;
459
551
  ```
460
552
 
553
+ The MongoDB Atlas cluster domain.
554
+
461
555
  ***
462
556
 
463
557
  ### dbName?
@@ -466,6 +560,8 @@ optional dbDomain: string;
466
560
  optional dbName: string;
467
561
  ```
468
562
 
563
+ The database name to connect to.
564
+
469
565
  ***
470
566
 
471
567
  ### dbPassword?
@@ -474,6 +570,8 @@ optional dbName: string;
474
570
  optional dbPassword: string;
475
571
  ```
476
572
 
573
+ The password for MongoDB authentication.
574
+
477
575
  ***
478
576
 
479
577
  ### dbUserName?
@@ -482,12 +580,16 @@ optional dbPassword: string;
482
580
  optional dbUserName: string;
483
581
  ```
484
582
 
583
+ The username for MongoDB authentication.
584
+
485
585
  ### <a id="BaseMongoSdkPublicConfig"></a>BaseMongoSdkPublicConfig
486
586
 
487
587
  [**@xylabs/mongo**](#../README)
488
588
 
489
589
  ***
490
590
 
591
+ Public configuration options for the Mongo SDK, safe to expose to clients.
592
+
491
593
  ## Properties
492
594
 
493
595
  ### closeDelay?
@@ -496,6 +598,8 @@ optional dbUserName: string;
496
598
  optional closeDelay: number;
497
599
  ```
498
600
 
601
+ Delay in milliseconds before closing idle connections.
602
+
499
603
  ***
500
604
 
501
605
  ### collection
@@ -504,6 +608,8 @@ optional closeDelay: number;
504
608
  collection: string;
505
609
  ```
506
610
 
611
+ The MongoDB collection name to operate on.
612
+
507
613
  ***
508
614
 
509
615
  ### maxPoolSize?
@@ -512,6 +618,8 @@ collection: string;
512
618
  optional maxPoolSize: number;
513
619
  ```
514
620
 
621
+ Maximum number of connections in the connection pool.
622
+
515
623
  ### type-aliases
516
624
 
517
625
  ### <a id="BaseMongoSdkConfig"></a>BaseMongoSdkConfig
@@ -524,6 +632,8 @@ optional maxPoolSize: number;
524
632
  type BaseMongoSdkConfig = BaseMongoSdkPublicConfig & BaseMongoSdkPrivateConfig;
525
633
  ```
526
634
 
635
+ Combined public and private MongoDB SDK configuration.
636
+
527
637
 
528
638
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
529
639
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/mongo",
3
- "version": "5.0.83",
3
+ "version": "5.0.84",
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.83"
49
+ "@xylabs/assert": "~5.0.84"
50
50
  },
51
51
  "devDependencies": {
52
- "@xylabs/tsconfig": "~7.4.11",
52
+ "@xylabs/tsconfig": "~7.4.13",
53
53
  "mongodb": "^7.1.0",
54
54
  "typescript": "~5.9.3",
55
55
  "vitest": "~4.0.18"