picker-db 4.13.0 → 4.16.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/CLAUDE.md ADDED
@@ -0,0 +1,87 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ **picker-db** is a JavaScript library that provides Mongoose models and schemas for connecting to Picker MongoDB databases. It abstracts database operations and promotes code reuse across Picker microservices.
8
+
9
+ **Key Technologies:**
10
+ - Mongoose 8.0.4 for MongoDB schema definition and operations
11
+ - Winston for logging
12
+ - Node v16.13.1 (specified in .nvmrc)
13
+
14
+ ## Architecture
15
+
16
+ ### Core Service (modules/picker/index.js)
17
+ The `PickerMongoDBService` class is the main entry point. It wraps Mongoose operations and provides consistent CRUD and query methods:
18
+
19
+ - **Connection Management**: `connect()`, `disconnect()` - Initialize and close MongoDB connections
20
+ - **CRUD Operations**: `createData()`, `updateData()`, `updateMultiple()`, `deleteData()`, `deleteMany()`
21
+ - **Query Operations**: `getDataAsync()`, `getFirstMatch()`, `countData()` - Support criteria, projection, and options
22
+ - **Advanced Queries**: `aggregateData()`, `aggregateDataCursor()` with disk allowance for large datasets
23
+ - **Relationships**: `getDataPopulateAsync()`, `getFirstMatchPopulate()` - Support Mongoose population for references
24
+
25
+ ### Models and Schemas
26
+ - **models/index.js**: Registers all 28+ schemas as Mongoose models (User, Bookings, Driver, Customer, etc.) and exports them as a factory function receiving a mongoose connection
27
+ - **schemas/**: Individual schema definitions for domain models. Each schema is a function that receives a mongoose connection and returns a Schema object
28
+ - Schema definitions use Mongoose's nested subdocuments and references for relationships
29
+
30
+ ### Database Connection (lib/Mongo/index.js)
31
+ The `MongoDB` class handles connection setup with three environment types:
32
+ - **"local"**: Local MongoDB (`mongodb://host:port/dbName`)
33
+ - **"atlas"**: MongoDB Atlas (uses `dbUri` directly)
34
+ - **default**: Standard auth (`mongodb://username:password@host:port/dbName`)
35
+
36
+ Configuration options:
37
+ - `auth`: Connection credentials and environment
38
+ - `dbName`: Database name
39
+ - `isLoggingEnabled`: Enable Winston logging for connection events
40
+ - `isDebugEnabled`: Enable Mongoose debug mode
41
+ - `useNewUrlParser`, `useUnifiedTopology`: Mongoose connection options
42
+
43
+ ## Development Commands
44
+
45
+ **ESLint**: Check code style (uses standard config)
46
+ ```bash
47
+ npx eslint .
48
+ npx eslint path/to/file.js
49
+ ```
50
+
51
+ **Note**: No test command is currently configured. To run tests in the future:
52
+ ```bash
53
+ npm test
54
+ ```
55
+
56
+ ## Code Style and Conventions
57
+
58
+ **ESLint Configuration** (.eslintrc.json):
59
+ - Double quotes for strings (not single)
60
+ - Semicolons required at end of statements
61
+ - `const`/`let` required (no `var`)
62
+ - Capitalized comments required
63
+ - Comma-dangle: always-multiline for arrays, objects, imports, exports, functions
64
+ - `no-console` warnings for console usage
65
+ - Follows StandardJS rules with some customizations
66
+
67
+ **Best Practices**:
68
+ - Schema definitions are functions that receive a Mongoose connection - this allows multiple connections
69
+ - All operations in `PickerMongoDBService` are async and return Promises
70
+ - Methods accept `modelName` (string) as first parameter to select which model to operate on
71
+ - Use `lean()` option in queries for performance when you don't need full Mongoose documents
72
+ - Use `aggregateDataCursor()` for large datasets (batchSize: 2000)
73
+
74
+ ## Important Files
75
+
76
+ - **index.js**: Exports `PickerMongoDBService` - the main class for library users
77
+ - **modules/picker/index.js**: Core service implementation with all CRUD methods
78
+ - **modules/picker/models/index.js**: Model factory - returns object with all registered models
79
+ - **modules/picker/schemas/**: 28+ individual schema definitions (bookings.js, user.js, driver.js, etc.)
80
+ - **lib/Mongo/index.js**: MongoDB connection management
81
+ - **lib/Mongo/typedef.js**: JSDoc type definitions for configuration objects
82
+ - **constants.js**: Project-wide constants (business enums, API user types, etc.)
83
+ - **playground/testService.js**: Example usage of the library
84
+
85
+ ## Recent Context
86
+
87
+ The repository is on the `feature/CT-187-index-optimizations` branch with uncommitted changes to `modules/picker/schemas/bookings.js`. This work is focused on database index optimizations.
@@ -22,3 +22,12 @@ pipelines:
22
22
  - pipe: atlassian/npm-publish:0.3.3
23
23
  variables:
24
24
  NPM_TOKEN: $NPM_TOKEN
25
+ custom:
26
+ weekly-security-audit:
27
+ - step:
28
+ name: Weekly Security Audit
29
+ caches:
30
+ - node
31
+ script:
32
+ - npm install
33
+ - npm audit --audit-level=critical
@@ -12,7 +12,6 @@ module.exports = (connection) => {
12
12
  const BalanceTransactionSchema = new connection.base.Schema({
13
13
  transactionID: {
14
14
  type: Number,
15
- index: true,
16
15
  },
17
16
  type: {
18
17
  type: String,
@@ -49,7 +49,6 @@ module.exports = (connection) => {
49
49
  },
50
50
  contificoId: {
51
51
  type: String,
52
- index: true,
53
52
  default: null,
54
53
  },
55
54
  error: {
@@ -62,7 +61,6 @@ module.exports = (connection) => {
62
61
  },
63
62
  contificoNumericId: {
64
63
  type: Number,
65
- index: true,
66
64
  },
67
65
  }, { timestamps: true });
68
66
 
@@ -6,13 +6,10 @@ module.exports = (connection) => {
6
6
  business: {
7
7
  type: connection.base.Schema.ObjectId,
8
8
  ref: "User",
9
- index: true,
10
9
  },
11
10
  workspaceID: {
12
11
  type: connection.base.Schema.ObjectId,
13
12
  default: null,
14
- index: true,
15
- sparse: true,
16
13
  },
17
14
  bookingID: {
18
15
  type: connection.base.Schema.ObjectId,
@@ -21,12 +18,9 @@ module.exports = (connection) => {
21
18
  },
22
19
  bookingNumericId: {
23
20
  type: Number,
24
- index: true,
25
- sparse: true,
26
21
  },
27
22
  ipAddress: {
28
23
  type: String,
29
- index: true,
30
24
  },
31
25
  status: {
32
26
  type: String,
@@ -181,14 +181,12 @@ module.exports = (connection) => {
181
181
  },
182
182
  customerName: {
183
183
  type: String,
184
- index: true,
185
184
  required: true,
186
185
  },
187
186
  customerMobile: {
188
187
  type: String,
189
188
  required: true,
190
189
  trim: true,
191
- index: true,
192
190
  },
193
191
  customerCountryCode: {
194
192
  type: String,
@@ -237,14 +235,10 @@ module.exports = (connection) => {
237
235
  },
238
236
  driverName: {
239
237
  type: String,
240
- index: true,
241
- sparse: true,
242
238
  default: null,
243
239
  },
244
240
  driverMobile: {
245
241
  type: String,
246
- index: true,
247
- sparse: true,
248
242
  default: null,
249
243
  },
250
244
  driverImage: {
@@ -342,7 +336,6 @@ module.exports = (connection) => {
342
336
  VEHICLE_TYPES.LITE.INDEX,
343
337
  VEHICLE_TYPES.BIKE.INDEX,
344
338
  ],
345
- index: true,
346
339
  },
347
340
  carName: {
348
341
  type: String,
@@ -411,7 +404,7 @@ module.exports = (connection) => {
411
404
  default: null,
412
405
  },
413
406
  },
414
- corporateID: { type: String, index: true },
407
+ corporateID: { type: String },
415
408
  corporateChargeStatus: {
416
409
  type: String,
417
410
  default: "PENDING",
@@ -511,8 +504,6 @@ module.exports = (connection) => {
511
504
  massDeliveryID: {
512
505
  type: connection.base.Schema.ObjectId,
513
506
  ref: "MassDelivery",
514
- index: true,
515
- sparse: true,
516
507
  default: null,
517
508
  },
518
509
  // #region Pricing Info
@@ -630,15 +621,11 @@ module.exports = (connection) => {
630
621
  type: connection.base.Schema.ObjectId,
631
622
  ref: "Region",
632
623
  default: null,
633
- index: true,
634
- sparse: true,
635
624
  },
636
625
  superRegionID: {
637
626
  type: connection.base.Schema.ObjectId,
638
627
  ref: "SuperRegion",
639
628
  default: null,
640
- index: true,
641
- sparse: true,
642
629
  },
643
630
  // #endregion Distance Info
644
631
  // #region Time info
@@ -746,7 +733,6 @@ module.exports = (connection) => {
746
733
  min: 0,
747
734
  }, // In milliseconds
748
735
  isActive: {
749
- index: true,
750
736
  type: Boolean,
751
737
  default: true,
752
738
  },
@@ -779,11 +765,13 @@ module.exports = (connection) => {
779
765
  },
780
766
  externalBookingId: {
781
767
  type: String,
782
- index: true,
783
768
  },
784
769
  userBookingCreator: {
785
770
  type: String,
786
771
  },
772
+ userBookingCreatorEmail: {
773
+ type: String,
774
+ },
787
775
  isActiveOnBatch: {
788
776
  type: Boolean,
789
777
  default: true,
@@ -838,7 +826,7 @@ module.exports = (connection) => {
838
826
  rating: {
839
827
  type: Number,
840
828
  },
841
- isWithHack: { type: Boolean, index: true, sparse: true },
829
+ isWithHack: { type: Boolean },
842
830
  // REASIGNMENT COUNTERS
843
831
  counters: {
844
832
  totalReassignments: { type: Number, default: 0 },
@@ -68,14 +68,11 @@ module.exports = (connection) => {
68
68
  const BusinessSchema = new connection.base.Schema({
69
69
  companyMobile: {
70
70
  type: String,
71
- index: true,
72
71
  trim: true,
73
- sparse: true,
74
72
  },
75
73
  companyCountryCode: { type: String },
76
74
  companyFullMobile: {
77
75
  type: String,
78
- index: true,
79
76
  },
80
77
 
81
78
  companyName: { type: String },
@@ -151,8 +148,6 @@ module.exports = (connection) => {
151
148
  deviceToken: {
152
149
  type: String,
153
150
  trim: true,
154
- index: true,
155
- sparse: true,
156
151
  },
157
152
  // #endregion Device information
158
153
 
@@ -43,7 +43,15 @@ module.exports = (connection) => {
43
43
  type: String,
44
44
  required: false,
45
45
  index: true,
46
- }
46
+ },
47
+ userBookingCreator: {
48
+ type: String,
49
+ required: false,
50
+ },
51
+ userBookingCreatorEmail: {
52
+ type: String,
53
+ required: false,
54
+ },
47
55
  }, { timestamps: false });
48
56
 
49
57
  return MiniBookingSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picker-db",
3
- "version": "4.13.0",
3
+ "version": "4.16.0",
4
4
  "description": "Picker DB services",
5
5
  "main": "index.js",
6
6
  "scripts": {