zync-nest-data-module 1.0.0 → 1.1.38

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 (80) hide show
  1. package/.prettierrc.json +23 -0
  2. package/README.md +226 -439
  3. package/dist/backup/backup.module.d.ts +1 -1
  4. package/dist/backup/backup.module.js +6 -6
  5. package/dist/backup/backup.module.js.map +1 -1
  6. package/dist/backup/backup.service.d.ts +1 -0
  7. package/dist/backup/backup.service.js +41 -18
  8. package/dist/backup/backup.service.js.map +1 -1
  9. package/dist/backup/backup.worker.d.ts +1 -0
  10. package/dist/backup/backup.worker.js +43 -0
  11. package/dist/backup/backup.worker.js.map +1 -0
  12. package/dist/base/dto.d.ts +19 -0
  13. package/dist/base/dto.js +86 -0
  14. package/dist/base/dto.js.map +1 -0
  15. package/dist/base/index.d.ts +2 -0
  16. package/dist/base/index.js +19 -0
  17. package/dist/base/index.js.map +1 -0
  18. package/dist/base/resolver.d.ts +6 -0
  19. package/dist/base/resolver.js +54 -0
  20. package/dist/base/resolver.js.map +1 -0
  21. package/dist/database/database.module.d.ts +5 -1
  22. package/dist/database/database.module.js +24 -19
  23. package/dist/database/database.module.js.map +1 -1
  24. package/dist/database/database.repository.d.ts +3 -2
  25. package/dist/database/database.repository.js +32 -25
  26. package/dist/database/database.repository.js.map +1 -1
  27. package/dist/database/database.scheme.d.ts +2 -8
  28. package/dist/database/database.scheme.js +2 -2
  29. package/dist/database/database.scheme.js.map +1 -1
  30. package/dist/database/database.service.d.ts +5 -3
  31. package/dist/database/database.service.js +44 -17
  32. package/dist/database/database.service.js.map +1 -1
  33. package/dist/database/database.transaction.d.ts +7 -7
  34. package/dist/database/database.transaction.js +61 -50
  35. package/dist/database/database.transaction.js.map +1 -1
  36. package/dist/database/database.uniqueId.d.ts +8 -3
  37. package/dist/database/database.uniqueId.js +26 -7
  38. package/dist/database/database.uniqueId.js.map +1 -1
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.js +2 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/redis/index.d.ts +2 -0
  43. package/dist/redis/index.js +19 -0
  44. package/dist/redis/index.js.map +1 -0
  45. package/dist/redis/redis.module.d.ts +2 -0
  46. package/dist/redis/redis.module.js +43 -0
  47. package/dist/redis/redis.module.js.map +1 -0
  48. package/dist/redis/redis.service.d.ts +27 -0
  49. package/dist/redis/redis.service.js +126 -0
  50. package/dist/redis/redis.service.js.map +1 -0
  51. package/dist/service/service.d.ts +2 -2
  52. package/dist/service/service.js +42 -56
  53. package/dist/service/service.js.map +1 -1
  54. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  55. package/libs/src/app.controller.ts +53 -46
  56. package/libs/src/app.module.ts +13 -10
  57. package/libs/src/backup/backup.module.ts +2 -2
  58. package/libs/src/backup/backup.service.ts +60 -69
  59. package/libs/src/backup/backup.worker.ts +35 -0
  60. package/libs/src/base/dto.ts +46 -0
  61. package/libs/src/base/index.ts +2 -0
  62. package/libs/src/base/resolver.ts +20 -0
  63. package/libs/src/database/database.module.ts +24 -22
  64. package/libs/src/database/database.repository.ts +47 -50
  65. package/libs/src/database/database.scheme.ts +2 -2
  66. package/libs/src/database/database.service.ts +61 -22
  67. package/libs/src/database/database.transaction.ts +62 -64
  68. package/libs/src/database/database.uniqueId.ts +39 -8
  69. package/libs/src/index.ts +3 -1
  70. package/libs/src/main.ts +8 -18
  71. package/libs/src/redis/index.ts +2 -0
  72. package/libs/src/redis/redis.interface.ts +34 -0
  73. package/libs/src/redis/redis.module.ts +30 -0
  74. package/libs/src/redis/redis.service.ts +137 -0
  75. package/libs/src/service/service.ts +48 -68
  76. package/libs/src/test/test.controller.ts +59 -0
  77. package/libs/src/test/test.module.ts +8 -4
  78. package/libs/src/test/test.redis.ts +19 -0
  79. package/libs/src/test/test.resolver.ts +10 -19
  80. package/package.json +45 -26
package/README.md CHANGED
@@ -1,18 +1,16 @@
1
- # Zync NestJS Library
1
+ # Zync NestJS Data Module
2
2
 
3
- A comprehensive NestJS library providing database backup utilities, file upload services, and common utilities for modern web applications.
3
+ A comprehensive NestJS data module providing database utilities, backup services, and base service classes for modern web applications built with MongoDB and Mongoose.
4
4
 
5
5
  ## 📦 Features
6
6
 
7
+ - **Database Module**: Complete MongoDB/Mongoose integration with repositories, transactions, and utilities
7
8
  - **Database Backup Service**: Automated MongoDB backup with cloud storage support
8
- - **File Upload Service**: Handle file uploads with image resizing and cloud storage
9
- - **Bucket Service**: AWS S3/DigitalOcean Spaces integration
10
- - **Firebase Service**: Push notification service with FCM integration
11
- - **Mailer Service**: Email sending service with template support
12
- - **Exabytes SMS Service**: SMS sending service via Exabytes API
13
- - **UltraMsg Service**: WhatsApp messaging service via UltraMsg API
14
- - **Message Service**: Unified messaging service for various channels
15
- - **Utility Functions**: Common helpers for date formatting, file handling, and more
9
+ - **Base Service Class**: Generic service class with CRUD operations and pagination
10
+ - **Database Utilities**: Helper functions for database operations, unique ID generation, and data synchronization
11
+ - **Transaction Management**: Built-in transaction support for complex database operations
12
+ - **Repository Pattern**: Abstract base repository with common database operations
13
+ - **Database Schema Utilities**: Schema management and validation helpers
16
14
 
17
15
  ## 🚀 Installation
18
16
 
@@ -20,8 +18,8 @@ A comprehensive NestJS library providing database backup utilities, file upload
20
18
 
21
19
  ```bash
22
20
  # Clone the repository
23
- git clone <repository-url>
24
- cd zync-nest-library
21
+ git clone https://github.com/zynctech/zync-nest-data-module.git
22
+ cd zync-nest-data-module
25
23
 
26
24
  # Install dependencies
27
25
  pnpm install
@@ -32,14 +30,23 @@ pnpm run build
32
30
 
33
31
  ### Using in Other Projects
34
32
 
35
- #### Method 1: File Path Dependency (Recommended for pnpm)
33
+ #### Method 1: npm/pnpm install from registry
34
+
35
+ ```bash
36
+ # Install from AsyncTech registry
37
+ npm install zync-nest-data-module --registry https://registry.asynctechs.com/
38
+ # or
39
+ pnpm add zync-nest-data-module --registry https://registry.asynctechs.com/
40
+ ```
41
+
42
+ #### Method 2: File Path Dependency (For local development)
36
43
 
37
44
  In your project's `package.json`:
38
45
 
39
46
  ```json
40
47
  {
41
48
  "dependencies": {
42
- "zync-nest-library": "file:../../zync-library/zync-nest-library"
49
+ "zync-nest-data-module": "file:../../zync-library/zync-nest-data-module"
43
50
  }
44
51
  }
45
52
  ```
@@ -49,17 +56,17 @@ Then run:
49
56
  pnpm install
50
57
  ```
51
58
 
52
- #### Method 2: npm link (For npm users)
59
+ #### Method 3: npm link (For npm users)
53
60
 
54
61
  ```bash
55
62
  # In the library directory
56
63
  npm link
57
64
 
58
65
  # In your consuming project
59
- npm link zync-nest-library
66
+ npm link zync-nest-data-module
60
67
  ```
61
68
 
62
- #### Method 3: pnpm link (Alternative for pnpm)
69
+ #### Method 4: pnpm link (Alternative for pnpm)
63
70
 
64
71
  ```bash
65
72
  # Setup pnpm global bin directory (one-time setup)
@@ -69,7 +76,7 @@ pnpm setup
69
76
  pnpm link --global
70
77
 
71
78
  # In your consuming project
72
- pnpm link --global zync-nest-library
79
+ pnpm link --global zync-nest-data-module
73
80
  ```
74
81
 
75
82
  ## 📚 Usage
@@ -81,439 +88,209 @@ Import the required modules in your NestJS application:
81
88
  ```typescript
82
89
  import { Module } from '@nestjs/common';
83
90
  import {
84
- ApDbBackupModule,
85
- UploadModule,
86
- FirebaseModule,
87
- MailerModule,
88
- MessageModule
89
- } from 'zync-nest-library';
91
+ DatabaseModule,
92
+ BackupModule,
93
+ BaseService
94
+ } from 'zync-nest-data-module';
90
95
 
91
96
  @Module({
92
97
  imports: [
93
- ApDbBackupModule,
94
- UploadModule,
95
- FirebaseModule,
96
- MailerModule,
97
- MessageModule,
98
+ DatabaseModule,
99
+ BackupModule,
98
100
  // ... other modules
99
101
  ],
100
102
  })
101
103
  export class AppModule {}
102
104
  ```
103
105
 
104
- ### Database Backup Service
105
-
106
- The `DbBackupService` provides automated MongoDB backup functionality with optional cloud storage.
107
-
108
- #### Configuration
109
-
110
- ```typescript
111
- import { IDbBackupConfig } from 'zync-nest-library';
112
-
113
- const backupConfig: IDbBackupConfig = {
114
- env: 'production',
115
- mongodb: {
116
- connectionStrings: 'mongodb://localhost:27017/mydb'
117
- // or multiple connections: ['mongodb://...', 'mongodb://...']
118
- },
119
- backup: {
120
- dir: './backups',
121
- enabled: true,
122
- maxBackups: 10,
123
- isDownload: false,
124
- uploadToSpace: true
125
- },
126
- spaces: {
127
- name: 'my-bucket',
128
- region: 'nyc3',
129
- key: 'your-access-key',
130
- secret: 'your-secret-key',
131
- endpoint: 'https://nyc3.digitaloceanspaces.com',
132
- dir: 'backups'
133
- }
134
- };
135
- ```
136
-
137
- #### Usage
138
-
139
- ```typescript
140
- import { Injectable } from '@nestjs/common';
141
- import { DbBackupService } from 'zync-nest-library';
142
-
143
- @Injectable()
144
- export class MyService {
145
- constructor(private readonly backupService: DbBackupService) {}
106
+ ### Database Module
146
107
 
147
- async createBackup() {
148
- await this.backupService.backup();
149
- }
108
+ The `DatabaseModule` provides comprehensive MongoDB/Mongoose integration with repositories, transactions, and utilities.
150
109
 
151
- async scheduleBackups() {
152
- // Set up automated backups (runs every 6 hours by default)
153
- this.backupService.startBackupSchedule();
154
- }
155
- }
156
- ```
157
-
158
- ### Upload Service
110
+ #### Database Schema
159
111
 
160
- The `UploadService` handles file uploads with automatic image resizing and cloud storage integration.
161
-
162
- #### Interfaces
112
+ The module includes a `BaseSchema` class that provides common fields for all documents:
163
113
 
164
114
  ```typescript
165
- import { IUpload, IUploadResult } from 'zync-nest-library';
166
-
167
- // Upload interface
168
- interface IUpload {
169
- type?: "base64" | "buffer";
170
- file: any;
171
- filepath?: string;
172
- filename: string;
173
- filetype: string;
174
- dir?: string;
175
- transformName?: boolean;
176
- }
115
+ import { BaseSchema } from 'zync-nest-data-module';
177
116
 
178
- // Upload result
179
- interface IUploadResult {
117
+ @Schema()
118
+ export class MyDocument extends BaseSchema {
119
+ @Prop({ required: true })
180
120
  name: string;
181
- type: string;
182
- uri: string;
183
- lgUri?: string; // Large thumbnail
184
- mdUri?: string; // Medium thumbnail
185
- smUri?: string; // Small thumbnail
121
+
122
+ @Prop()
123
+ description: string;
186
124
  }
187
125
  ```
188
126
 
189
- #### Usage
127
+ #### Repository Pattern
190
128
 
191
- ```typescript
192
- import { Injectable } from '@nestjs/common';
193
- import { UploadService } from 'zync-nest-library';
194
-
195
- @Injectable()
196
- export class FileService {
197
- constructor(private readonly uploadService: UploadService) {}
198
-
199
- async uploadFile(file: Express.Multer.File): Promise<IUploadResult> {
200
- const uploadData: IUpload = {
201
- type: 'buffer',
202
- file: file.buffer,
203
- filename: file.originalname,
204
- filetype: file.mimetype,
205
- dir: 'uploads',
206
- transformName: true
207
- };
208
-
209
- return await this.uploadService.uploadFile(uploadData);
210
- }
211
-
212
- async uploadBase64Image(base64: string): Promise<IUploadResult> {
213
- const uploadData: IUpload = {
214
- type: 'base64',
215
- file: base64,
216
- filename: 'image.jpg',
217
- filetype: 'image/jpeg',
218
- dir: 'images'
219
- };
220
-
221
- return await this.uploadService.uploadFile(uploadData);
222
- }
223
- }
224
- ```
225
-
226
- ### Bucket Service
227
-
228
- The `BucketService` provides direct integration with cloud storage services (AWS S3, DigitalOcean Spaces).
229
-
230
- #### Configuration
231
-
232
- ```typescript
233
- // In your environment or config
234
- export default () => ({
235
- bucket: {
236
- name: process.env.aws_bucket,
237
- region: process.env.aws_s3_region,
238
- key: process.env.aws_access_key_id,
239
- secret: process.env.aws_secret_access_key,
240
- endpoint: process.env.aws_s3_endpoint,
241
- }
242
- });
243
- ```
244
-
245
- #### Usage
129
+ Create repositories by extending `AbstractBaseRepository`:
246
130
 
247
131
  ```typescript
248
132
  import { Injectable } from '@nestjs/common';
249
- import { BucketService } from 'zync-nest-library';
133
+ import { AbstractBaseRepository, IPageParams } from 'zync-nest-data-module';
250
134
 
251
135
  @Injectable()
252
- export class CloudStorageService {
253
- constructor(private readonly bucketService: BucketService) {}
136
+ export class MyRepository extends AbstractBaseRepository<MyDocument> {
137
+ constructor(@InjectModel(MyDocument.name) model: SoftDeleteModel<MyDocument>) {
138
+ super(model);
139
+ }
254
140
 
255
- async uploadToBucket(buffer: Buffer, key: string) {
256
- return await this.bucketService.upload(buffer, key);
141
+ protected buildQuery(query: Partial<MyDocument>): any {
142
+ return query;
257
143
  }
258
144
 
259
- async downloadFromBucket(key: string) {
260
- return await this.bucketService.download(key);
145
+ public async mapData(data: any, isCreate: boolean): Promise<MyDocument> {
146
+ return data;
261
147
  }
262
148
 
263
- async deleteFromBucket(key: string) {
264
- return await this.bucketService.delete(key);
149
+ // Additional custom methods
150
+ async findByName(name: string): Promise<MyDocument[]> {
151
+ return this.find({ name });
265
152
  }
266
153
  }
267
154
  ```
268
155
 
269
- ### Firebase Service
270
-
271
- The `FirebaseService` provides push notification functionality using Firebase Cloud Messaging (FCM).
272
-
273
- #### Configuration
274
-
275
- First, you need to set up Firebase Admin SDK with a service account key:
156
+ #### Transaction Support
276
157
 
277
- 1. Download your Firebase service account key JSON file
278
- 2. Place it in your project root as `serviceAccount.json`
279
- 3. The service will automatically initialize Firebase Admin SDK
280
-
281
- #### Interfaces
282
-
283
- ```typescript
284
- import { INotification } from 'zync-nest-library';
285
-
286
- interface INotification {
287
- title: string;
288
- body: string;
289
- topic?: string;
290
- image?: string;
291
- data?: {
292
- type: "ORDER" | "SCHEME" | "RATE" | "PUSH" | "FEED";
293
- [x: string]: string;
294
- };
295
- }
296
- ```
297
-
298
- #### Usage
158
+ Use transactions for complex operations:
299
159
 
300
160
  ```typescript
301
161
  import { Injectable } from '@nestjs/common';
302
- import { FirebaseService, INotification } from 'zync-nest-library';
162
+ import { TransactionManager } from 'zync-nest-data-module';
303
163
 
304
164
  @Injectable()
305
- export class NotificationService {
306
- constructor(private readonly firebaseService: FirebaseService) {}
307
-
308
- async sendToDevices(tokens: string[], notification: INotification) {
309
- await this.firebaseService.sendPushNotification(tokens, notification);
310
- }
311
-
312
- async sendToTopic(topic: string, notification: INotification) {
313
- await this.firebaseService.sendPushNotificationToTopic(topic, notification);
314
- }
315
-
316
- async subscribeToTopic(topic: string, tokens: string[]) {
317
- await this.firebaseService.subscribeToTopic(topic, tokens);
165
+ export class MyService {
166
+ constructor(
167
+ private readonly transactionManager: TransactionManager,
168
+ private readonly myRepository: MyRepository
169
+ ) {}
170
+
171
+ async complexOperation() {
172
+ return await this.transactionManager.runTransaction(async (session) => {
173
+ this.myRepository.session = session;
174
+
175
+ const doc1 = await this.myRepository.create({ name: 'Document 1' });
176
+ const doc2 = await this.myRepository.create({ name: 'Document 2' });
177
+
178
+ return { doc1, doc2 };
179
+ });
318
180
  }
319
181
  }
320
182
  ```
321
183
 
322
- ### Mailer Service
323
-
324
- The `MailerService` provides email sending functionality with template support.
325
-
326
- #### Configuration
184
+ #### Pagination
327
185
 
328
- ```typescript
329
- import { IMailerConfig } from 'zync-nest-library';
330
-
331
- const mailerConfig: IMailerConfig = {
332
- logo: 'https://example.com/logo.png',
333
- host: 'smtp.gmail.com',
334
- user: 'your-email@gmail.com',
335
- pass: 'your-app-password',
336
- from: 'noreply@yourcompany.com',
337
- port: '587',
338
- playStore: 'https://play.google.com/store/apps/details?id=your.app',
339
- appStore: 'https://apps.apple.com/app/your-app/id123456789'
340
- };
341
- ```
342
-
343
- #### Environment Variables
344
-
345
- ```env
346
- # Email Configuration
347
- MAILER_HOST=smtp.gmail.com
348
- MAILER_USER=your-email@gmail.com
349
- MAILER_PASS=your-app-password
350
- MAILER_FROM=noreply@yourcompany.com
351
- MAILER_PORT=587
352
- MAILER_LOGO=https://example.com/logo.png
353
- MAILER_PLAY_STORE=https://play.google.com/store/apps/details?id=your.app
354
- MAILER_APP_STORE=https://apps.apple.com/app/your-app/id123456789
355
- ```
356
-
357
- #### Usage
186
+ Use built-in pagination functionality:
358
187
 
359
188
  ```typescript
360
- import { Injectable } from '@nestjs/common';
361
- import { MailerService, IMail } from 'zync-nest-library';
362
-
363
- @Injectable()
364
- export class EmailService {
365
- constructor(private readonly mailerService: MailerService) {}
366
-
367
- async sendEmail(mailData: IMail) {
368
- await this.mailerService.sendMail(mailData);
369
- }
370
-
371
- async sendWelcomeEmail(email: string, name: string) {
372
- const mailData: IMail = {
373
- to: email,
374
- subject: 'Welcome to Our Platform',
375
- template: 'welcome',
376
- context: {
377
- name: name,
378
- loginUrl: 'https://yourapp.com/login'
379
- }
380
- };
381
-
382
- await this.mailerService.sendMail(mailData);
383
- }
189
+ async getPaginatedData(pageParams: IPageParams) {
190
+ return await this.myRepository.page({
191
+ ...pageParams,
192
+ // additional query filters
193
+ });
384
194
  }
385
195
  ```
386
196
 
387
- ### Exabytes SMS Service
388
-
389
- The Exabytes SMS service provides SMS sending functionality via Exabytes API.
390
-
391
- #### Configuration
392
-
393
- Configure the Exabytes SMS service using environment variables:
394
-
395
- ```env
396
- # Exabytes SMS Configuration
397
- exabytes_sms_username=your_username
398
- exabytes_sms_password=your_password
399
- exabytes_sms_url=https://sms.exabytes.com/api/send
400
- exabytes_sms_sendid=YOUR_SENDER_ID
401
- ```
402
-
403
- #### Usage
404
-
405
- The Exabytes SMS service is typically used through the unified Message Service for SMS functionality.
406
-
407
- ### UltraMsg Service
197
+ ### Database Backup Service
408
198
 
409
- The `UltraMsgService` provides WhatsApp messaging functionality via UltraMsg API.
199
+ The `BackupService` provides automated MongoDB backup functionality with cloud storage support.
410
200
 
411
201
  #### Configuration
412
202
 
413
- Configure the UltraMsg service using environment variables:
203
+ Configure backup settings using environment variables:
414
204
 
415
205
  ```env
416
- # UltraMsg Configuration
417
- ultramsg_instance=your_instance_id
418
- ultramsg_token=your_api_token
419
- ultramsg_url=https://api.ultramsg.com
206
+ # Database Backup Configuration
207
+ app_env=production
208
+ mongodb_backup_connection_strings=mongodb://localhost:27017/mydb
209
+ db_backup_enabled=true
210
+ db_backup_dir=./backups
211
+ db_backup_max=10
212
+
213
+ # Cloud Storage Configuration (DigitalOcean Spaces / AWS S3)
214
+ aws_bucket=my-backup-bucket
215
+ aws_s3_region=nyc3
216
+ aws_access_key_id=your-access-key
217
+ aws_secret_access_key=your-secret-key
218
+ s3_spaces_endpoint=https://nyc3.digitaloceanspaces.com
219
+ s3_spaces_dir=db-backups
420
220
  ```
421
221
 
422
222
  #### Usage
423
223
 
424
224
  ```typescript
425
225
  import { Injectable } from '@nestjs/common';
426
- import { UltraMsgService } from 'zync-nest-library';
226
+ import { BackupService } from 'zync-nest-data-module';
427
227
 
428
228
  @Injectable()
429
- export class WhatsAppService {
430
- constructor(private readonly ultraMsgService: UltraMsgService) {}
229
+ export class MyBackupService {
230
+ constructor(private readonly backupService: BackupService) {}
431
231
 
432
- async sendMessage(phone: string, message: string) {
433
- return await this.ultraMsgService.sendMessage(phone, message);
232
+ async createBackup() {
233
+ await this.backupService.backup();
434
234
  }
435
235
 
436
- async sendDocument(phone: string, document: string, caption?: string) {
437
- return await this.ultraMsgService.sendDocument(phone, document, caption);
236
+ async scheduleBackups() {
237
+ // Set up automated backups (runs every 6 hours by default)
238
+ this.backupService.startBackupSchedule();
438
239
  }
439
240
  }
440
241
  ```
441
242
 
442
- ### Message Service
243
+ ### Base Service Class
443
244
 
444
- The `MessageService` provides a unified interface for sending messages across different channels (Email, SMS, WhatsApp, Push Notifications).
445
-
446
- #### Usage
245
+ The `BaseService` provides a generic service class with common CRUD operations:
447
246
 
448
247
  ```typescript
449
248
  import { Injectable } from '@nestjs/common';
450
- import { MessageService } from 'zync-nest-library';
249
+ import { BaseService } from 'zync-nest-data-module';
451
250
 
452
251
  @Injectable()
453
- export class UnifiedMessageService {
454
- constructor(private readonly messageService: MessageService) {}
455
-
456
- async sendMultiChannelMessage(
457
- email: string,
458
- phone: string,
459
- pushTokens: string[],
460
- message: any
461
- ) {
462
- // Send via email
463
- await this.messageService.sendEmail({
464
- to: email,
465
- subject: message.subject,
466
- template: message.template,
467
- context: message.context
468
- });
469
-
470
- // Send via SMS (if configured)
471
- // await this.messageService.sendSMS(phone, message.text);
472
-
473
- // Send via WhatsApp (if configured)
474
- // await this.messageService.sendWhatsApp(phone, message.text);
252
+ export class MyService extends BaseService<MyDocument> {
253
+ constructor(myRepository: MyRepository) {
254
+ super(myRepository);
255
+ }
475
256
 
476
- // Send push notification
477
- await this.messageService.sendPushNotification(pushTokens, {
478
- title: message.title,
479
- body: message.body,
480
- data: message.data
481
- });
257
+ // Inherits all CRUD operations:
258
+ // - create(data)
259
+ // - update(_id, data)
260
+ // - findById(_id)
261
+ // - findOne(query)
262
+ // - find(query)
263
+ // - delete(_id)
264
+ // - page(query)
265
+
266
+ // Add custom business logic
267
+ async findActiveDocuments(): Promise<MyDocument[]> {
268
+ return this.find({ deleted: false });
482
269
  }
483
270
  }
484
271
  ```
485
272
 
486
- ### Utility Functions
273
+ ### Database Utilities
487
274
 
488
- The library includes various utility functions for common operations:
275
+ The module includes various utility functions:
489
276
 
490
277
  ```typescript
491
- import {
492
- DateUtils,
493
- mkdir,
494
- uuidFilenameTransform,
495
- bufferFromBase64,
496
- getBase64FileName,
497
- toSlug,
498
- fileDownloadResponse
499
- } from 'zync-nest-library';
500
-
501
- // Date utilities
502
- const timestamp = DateUtils.formatStringDate('25/12/2023');
503
-
504
- // File utilities
505
- const uniqueFilename = uuidFilenameTransform('image.jpg'); // Returns: uuid.jpg
506
- const buffer = bufferFromBase64('data:image/jpeg;base64,...');
507
- const filename = getBase64FileName('data:image/jpeg;base64,...'); // Returns: uuid.jpeg
508
-
509
- // String utilities
510
- const slug = toSlug('My Product Title'); // Returns: my-product-title-abc123
511
-
512
- // Directory creation
513
- mkdir('./uploads/images');
514
-
515
- // File download response (Express)
516
- fileDownloadResponse(res, buffer, 'report', 'pdf');
278
+ import {
279
+ DbUtils,
280
+ ApUniqueIdGenerator,
281
+ UniqueKeyTypes
282
+ } from 'zync-nest-data-module';
283
+
284
+ // Generate unique IDs
285
+ const uniqueId = await uniqueIdGenerator.generate({
286
+ prefix: 'DOC',
287
+ key: UniqueKeyTypes.DOCUMENT,
288
+ filter: { status: 'active' }
289
+ });
290
+
291
+ // Database utilities
292
+ const isValidObjectId = DbUtils.isValidObjectId('507f1f77bcf86cd799439011');
293
+ const objectId = DbUtils.toObjectId('507f1f77bcf86cd799439011');
517
294
  ```
518
295
 
519
296
  ## 🔧 Configuration
@@ -521,44 +298,29 @@ fileDownloadResponse(res, buffer, 'report', 'pdf');
521
298
  ### Environment Variables
522
299
 
523
300
  ```env
524
- # Cloud Storage (DigitalOcean Spaces / AWS S3)
525
- #-----------------s3-----------------#
526
- aws_access_key_id=xxxx
527
- aws_secret_access_key=xxxxx
301
+ # Application Environment
302
+ app_env=production
303
+ NODE_ENV=production
304
+ is_docker=false
305
+
306
+ # MongoDB Configuration
307
+ mongodb_url=mongodb://localhost:27017/mydb
308
+ mongodb_backup_connection_strings=mongodb://localhost:27017/mydb
309
+
310
+ # Database Backup Configuration
311
+ db_backup_enabled=true
312
+ db_backup_dir=./backups
313
+ db_backup_max=10
314
+
315
+ # Cloud Storage Configuration (DigitalOcean Spaces / AWS S3)
316
+ aws_bucket=my-backup-bucket
528
317
  aws_s3_region=nyc3
529
- aws_s3_endpoint=https://xxxx.nyc3.digitaloceanspaces.com
530
- aws_bucket=xxxx
318
+ aws_access_key_id=your-access-key
319
+ aws_secret_access_key=your-secret-key
320
+ aws_s3_endpoint=https://nyc3.digitaloceanspaces.com
531
321
  aws_base_key=development
532
-
533
- # Email Configuration (Mailer Service)
534
- #-----------------mailer-----------------#
535
- MAILER_HOST=smtp.gmail.com
536
- MAILER_USER=your-email@gmail.com
537
- MAILER_PASS=your-app-password
538
- MAILER_FROM=noreply@yourcompany.com
539
- MAILER_PORT=587
540
- MAILER_LOGO=https://example.com/logo.png
541
- MAILER_PLAY_STORE=https://play.google.com/store/apps/details?id=your.app
542
- MAILER_APP_STORE=https://apps.apple.com/app/your-app/id123456789
543
-
544
- # Exabytes SMS Configuration
545
- #-----------------exabytes-----------------#
546
- exabytes_sms_username=your_username
547
- exabytes_sms_password=your_password
548
- exabytes_sms_url=https://sms.exabytes.com/api/send
549
- exabytes_sms_sendid=YOUR_SENDER_ID
550
-
551
- # UltraMsg WhatsApp Configuration
552
- #-----------------ultramsg-----------------#
553
- ultramsg_instance=your_instance_id
554
- ultramsg_token=your_api_token
555
- ultramsg_url=https://api.ultramsg.com
556
-
557
- # Firebase Configuration
558
- #-----------------firebase-----------------#
559
- # Note: Firebase requires a service account JSON file
560
- # Place your serviceAccount.json file in the project root
561
- # Download from: Firebase Console > Project Settings > Service Accounts
322
+ s3_spaces_dir=db-backups
323
+ s3_spaces_endpoint=https://sgp1.digitaloceanspaces.com
562
324
  ```
563
325
 
564
326
  ## 🛠️ Development
@@ -569,14 +331,38 @@ ultramsg_url=https://api.ultramsg.com
569
331
  # Build the library
570
332
  pnpm run build
571
333
 
334
+ # Build library with clean (removes dist first)
335
+ pnpm run build:lib
336
+
572
337
  # Build in watch mode
573
338
  pnpm run build:watch
574
339
 
575
340
  # Clean build artifacts
576
341
  pnpm run clean
577
342
 
578
- # Build and clean
579
- pnpm run clean && pnpm run build
343
+ # Start the application (builds first)
344
+ pnpm run start
345
+
346
+ # Start in development mode (builds in watch mode + nodemon)
347
+ pnpm run start:dev
348
+
349
+ # Publish to AsyncTech registry
350
+ pnpm run publish:update
351
+
352
+ # Update links in consuming projects
353
+ pnpm run update-links
354
+
355
+ # Update links with version bump (minor)
356
+ pnpm run update-links:minor
357
+
358
+ # Update links with version bump (major)
359
+ pnpm run update-links:major
360
+
361
+ # Update links without building
362
+ pnpm run update-links:no-build
363
+
364
+ # Update links without version bump or build
365
+ pnpm run update-links:no-version
580
366
  ```
581
367
 
582
368
  ### Project Structure
@@ -584,43 +370,36 @@ pnpm run clean && pnpm run build
584
370
  ```
585
371
  libs/
586
372
  ├── src/
587
- │ ├── dbbackup/ # Database backup functionality
373
+ │ ├── backup/ # Database backup functionality
588
374
  │ │ ├── backup.config.ts
589
375
  │ │ ├── backup.interface.ts
590
376
  │ │ ├── backup.module.ts
591
- │ │ └── backup.service.ts
592
- ├── upload/ # File upload functionality
593
- ├── bucket/ # Cloud storage integration
594
- │ │ ├── upload.interface.ts
595
- │ │ ├── upload.module.ts
596
- │ │ ├── upload.service.ts
597
- │ │ └── upload.utils.ts
598
- │ ├── firebase/ # Firebase push notifications
599
- │ │ ├── firebase.interface.ts
600
- │ │ ├── firebase.module.ts
601
- │ │ └── firebase.service.ts
602
- ├── mailer/ # Email service
603
- ├── mailer.interface.ts
604
- │ │ ├── mailer.module.ts
605
- │ │ └── mailer.service.ts
606
- │ ├── message/ # Unified messaging service
607
- │ │ ├── message.module.ts
608
- │ │ └── message.service.ts
609
- │ ├── exabytes/ # SMS service via Exabytes
610
- │ │ ├── exabytes.config.ts
611
- │ │ ├── exabytes.interface.ts
612
- │ │ ├── exabytes.module.ts
613
- │ │ └── exabytes.service.ts
614
- │ ├── ultramsg/ # WhatsApp service via UltraMsg
615
- │ │ ├── ultramsg.config.ts
616
- │ │ ├── ultramsg.interface.ts
617
- │ │ ├── ultramsg.module.ts
618
- │ │ └── ultramsg.service.ts
619
- │ ├── utils/ # Utility functions
620
- │ │ ├── date.ts
621
- │ │ ├── object.ts
377
+ │ │ ├── backup.service.ts
378
+ │ └── index.ts
379
+ │ ├── database/ # Database utilities and patterns
380
+ │ │ ├── database.module.ts
381
+ │ │ ├── database.repository.ts
382
+ │ │ ├── database.scheme.ts
383
+ │ │ ├── database.service.ts
384
+ ├── database.sync.ts
385
+ │ │ ├── database.transaction.ts
386
+ │ │ ├── database.uniqueId.ts
387
+ │ │ ├── database.utils.ts
388
+ │ └── index.ts
389
+ │ ├── service/ # Base service class
390
+ │ │ ├── service.ts
622
391
  │ │ └── index.ts
623
- └── index.ts # Main exports
392
+ ├── test/ # Example/test implementation
393
+ │ │ ├── test.dto.ts
394
+ │ │ ├── test.module.ts
395
+ │ │ ├── test.repository.ts
396
+ │ │ ├── test.resolver.ts
397
+ │ │ ├── test.schema.ts
398
+ │ │ └── test.service.ts
399
+ │ ├── app.controller.ts
400
+ │ ├── app.module.ts
401
+ │ ├── main.ts
402
+ │ └── index.ts # Main exports
624
403
  └── tsconfig.lib.json
625
404
  ```
626
405
  ### Common Issues
@@ -631,7 +410,7 @@ If `pnpm link` doesn't work, use the file path dependency method instead:
631
410
  ```json
632
411
  {
633
412
  "dependencies": {
634
- "zync-nest-library": "file:../../zync-library/zync-nest-library"
413
+ "zync-nest-data-module": "file:../../zync-library/zync-nest-data-module"
635
414
  }
636
415
  }
637
416
  ```
@@ -654,7 +433,7 @@ If you see peer dependency warnings (e.g., `@nestjs/core` version mismatch), you
654
433
  #### 3. Build errors after linking
655
434
  Make sure to build the library first:
656
435
  ```bash
657
- cd zync-nest-library
436
+ cd zync-nest-data-module
658
437
  pnpm run build
659
438
  ```
660
439
 
@@ -667,6 +446,14 @@ pnpm run build
667
446
  # No need to reinstall - changes are automatically available in linked projects
668
447
  ```
669
448
 
449
+ #### 5. Registry access issues
450
+ If you encounter issues accessing the AsyncTech registry, ensure you have proper authentication:
451
+
452
+ ```bash
453
+ # Login to AsyncTech registry
454
+ npm login --registry https://registry.asynctechs.com/
455
+ ```
456
+
670
457
  ## 🐛 Issues
671
458
 
672
459
  If you encounter any issues or have questions, please file an issue on the project repository.