@tc-libs/database 3.6.0 → 3.8.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/README.md CHANGED
@@ -1,11 +1,90 @@
1
- # database
1
+ # @tc-libs/database
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Layer base Mongo/Mongoose del monorepo.
4
4
 
5
- ## Building
5
+ Il package contiene:
6
6
 
7
- Run `nx build database` to build the library.
7
+ - `DatabaseOptionsModule` per costruire `MongooseModuleOptions`
8
+ - abstract entity/repository riusabili
9
+ - interfacce per query, sessioni, cache e pagination
10
+ - costanti e decorator di supporto
8
11
 
9
- ## Running unit tests
12
+ ## `DatabaseOptionsModule`
10
13
 
11
- Run `nx test database` to execute the unit tests via [Jest](https://jestjs.io).
14
+ Serve per centralizzare la costruzione della connection string Mongo:
15
+
16
+ ```ts
17
+ DatabaseOptionsModule.register({
18
+ proto: 'mongodb',
19
+ host: '127.0.0.1:27017',
20
+ port: 27017,
21
+ name: 'mydb',
22
+ user: 'mongo',
23
+ password: 'secret',
24
+ debug: false,
25
+ });
26
+ ```
27
+
28
+ Poi:
29
+
30
+ ```ts
31
+ MongooseModule.forRootAsync({
32
+ imports: [DatabaseOptionsModule.register(...)],
33
+ useExisting: DatabaseOptionsService,
34
+ });
35
+ ```
36
+
37
+ ## Repository base
38
+
39
+ La classe piu importante e `DatabaseMongoRepositoryAbstract<Entity, EntityDocument>`.
40
+
41
+ Fornisce:
42
+
43
+ - CRUD standard
44
+ - join/populate opzionale
45
+ - `returnPlain`
46
+ - supporto `ClientSession`
47
+ - integrazione cache con `@tc-libs/app-cache`
48
+ - `raw()` per aggregate pipeline
49
+ - `startTransaction()`
50
+
51
+ ## Esempio repository custom
52
+
53
+ ```ts
54
+ export class UserRepository extends DatabaseMongoRepositoryAbstract<
55
+ UserEntity,
56
+ UserDoc
57
+ > {
58
+ protected readonly _logger = new Logger(UserRepository.name);
59
+
60
+ constructor(
61
+ @InjectModel(UserEntity.name) model: Model<UserEntity>,
62
+ @InjectConnection() connection: Connection,
63
+ cache: AppCacheService,
64
+ ) {
65
+ super(model, connection, cache);
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Abstract entity
71
+
72
+ - `DatabaseBaseEntityAbstract`
73
+ - `DatabaseMongoEntityAbstract`
74
+
75
+ Ti evitano di ridefinire sempre `_id`, `createdAt`, `updatedAt`.
76
+
77
+ ## Interfacce piu usate
78
+
79
+ - `IDatabaseFindOneOptions`
80
+ - `IDatabaseFindAllOptions`
81
+ - `IDatabaseCreateOptions`
82
+ - `IDatabaseManyOptions`
83
+ - `IDatabaseFindOneAndUpdateOptions`
84
+
85
+ ## Sviluppo
86
+
87
+ ```bash
88
+ nx build database
89
+ nx test database
90
+ ```
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tc-libs/database",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "dependencies": {
5
- "@tc-libs/app-cache": "3.6.0",
6
- "@tc-libs/pagination": "3.6.0",
5
+ "@tc-libs/app-cache": "3.8.0",
6
+ "@tc-libs/pagination": "3.8.0",
7
7
  "@nestjs/mongoose": "^11.0.3",
8
8
  "mongoose": "^8.13.1",
9
9
  "@nestjs/common": "^11.0.12",
@@ -1,3 +1,4 @@
1
1
  export * from './database.interface';
2
2
  export * from './database.mongo.base.entity.interface';
3
3
  export * from './i18n.entity.interface';
4
+ export * from './seo.entity.interface';
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./database.interface"), exports);
5
5
  tslib_1.__exportStar(require("./database.mongo.base.entity.interface"), exports);
6
6
  tslib_1.__exportStar(require("./i18n.entity.interface"), exports);
7
+ tslib_1.__exportStar(require("./seo.entity.interface"), exports);
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/database/src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,iFAAuD;AACvD,kEAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/database/src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,iFAAuD;AACvD,kEAAwC;AACxC,iEAAuC"}
@@ -0,0 +1,15 @@
1
+ import { I18nEntity } from './i18n.entity.interface';
2
+ export declare class SeoEntity {
3
+ title: I18nEntity;
4
+ description: I18nEntity;
5
+ tags?: I18nEntity[];
6
+ }
7
+ export declare const SeoEntitySchema: import("mongoose").Schema<SeoEntity, import("mongoose").Model<SeoEntity, any, any, any, import("mongoose").Document<unknown, any, SeoEntity> & SeoEntity & {
8
+ _id: import("mongoose").Types.ObjectId;
9
+ } & {
10
+ __v: number;
11
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, SeoEntity, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<SeoEntity>> & import("mongoose").FlatRecord<SeoEntity> & {
12
+ _id: import("mongoose").Types.ObjectId;
13
+ } & {
14
+ __v: number;
15
+ }>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeoEntitySchema = exports.SeoEntity = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const mongoose_1 = require("@nestjs/mongoose");
6
+ let SeoEntity = class SeoEntity {
7
+ };
8
+ exports.SeoEntity = SeoEntity;
9
+ exports.SeoEntity = SeoEntity = tslib_1.__decorate([
10
+ (0, mongoose_1.Schema)({ _id: false, timestamps: false, strict: false })
11
+ ], SeoEntity);
12
+ exports.SeoEntitySchema = mongoose_1.SchemaFactory.createForClass(SeoEntity);
13
+ //# sourceMappingURL=seo.entity.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seo.entity.interface.js","sourceRoot":"","sources":["../../../../../packages/database/src/interfaces/seo.entity.interface.ts"],"names":[],"mappings":";;;;AAAA,+CAAyD;AAIlD,IAAM,SAAS,GAAf,MAAM,SAAS;CAIrB,CAAA;AAJY,8BAAS;oBAAT,SAAS;IADrB,IAAA,iBAAM,EAAC,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;GAC5C,SAAS,CAIrB;AAEY,QAAA,eAAe,GAAG,wBAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC"}