@sisques-labs/nestjs-kit 0.1.0 → 0.1.1

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
@@ -141,19 +141,11 @@ For contributors working on this repository:
141
141
 
142
142
  ## Module Setup
143
143
 
144
- Import **`SharedModule`** in your root or core module. It is **`@Global()`** and only registers cross-cutting pieces that do not require a database (for example **`MutationResponseGraphQLMapper`** and shared GraphQL enum registration). It does **not** import MongoDB or TypeORM—you add those only if you need them.
144
+ The library is **opt-in by feature**. Import **`MongoModule`**, **`TypeOrmModule`**, GraphQL pieces (DTOs, **`registerSharedGraphqlEnums`**, mappers, plugins), and domain exports only when you need them.
145
145
 
146
- ```typescript
147
- import { Module } from '@nestjs/common';
148
- import { SharedModule } from '@sisques-labs/nestjs-kit';
146
+ **`SharedModule`** is an optional **empty** `Module` kept for backward compatibility; it registers **no** providers and is **not** `@Global()`.
149
147
 
150
- @Module({
151
- imports: [SharedModule],
152
- })
153
- export class AppModule {}
154
- ```
155
-
156
- **Optional database modules** (import alongside `SharedModule` when you use them):
148
+ **Optional database modules:**
157
149
 
158
150
  - **`MongoModule`** — provides `MongoMasterService` (`MONGODB_URI`, `MONGODB_DATABASE` via `ConfigService`).
159
151
  - **`TypeOrmModule`** — registers `TypeOrmModule.forRootAsync` using `DATABASE_*` config; requires **`ConfigModule`** in the app (for example `ConfigModule.forRoot({ isGlobal: true })`).
@@ -161,16 +153,11 @@ export class AppModule {}
161
153
  ```typescript
162
154
  import { Module } from '@nestjs/common';
163
155
  import { ConfigModule } from '@nestjs/config';
164
- import {
165
- SharedModule,
166
- MongoModule,
167
- TypeOrmModule,
168
- } from '@sisques-labs/nestjs-kit';
156
+ import { MongoModule, TypeOrmModule } from '@sisques-labs/nestjs-kit';
169
157
 
170
158
  @Module({
171
159
  imports: [
172
160
  ConfigModule.forRoot({ isGlobal: true }),
173
- SharedModule,
174
161
  MongoModule, // omit if you do not use MongoDB
175
162
  TypeOrmModule, // omit if you do not use TypeORM
176
163
  ],
@@ -607,6 +594,14 @@ type UserTypeormDto = BaseTypeormDto & {
607
594
 
608
595
  ## Transport Layer (GraphQL)
609
596
 
597
+ If you use **`@nestjs/graphql`**, call **`registerSharedGraphqlEnums()`** once before schema generation (for example at the top of `main.ts` before `NestFactory.create`, or from a small module imported by `AppModule`). Add **`MutationResponseGraphQLMapper`** and **`ComplexityPlugin`** to your own GraphQL module’s **`providers`** when you use them—this package does **not** register them via **`SharedModule`**.
598
+
599
+ ```typescript
600
+ import { registerSharedGraphqlEnums } from '@sisques-labs/nestjs-kit';
601
+
602
+ registerSharedGraphqlEnums();
603
+ ```
604
+
610
605
  ### Input DTOs
611
606
 
612
607
  #### `BaseFindByCriteriaInput`
@@ -689,11 +684,16 @@ deleteUsers(@Args('ids', { type: () => [String] }) ids: string[]): Promise<Mutat
689
684
 
690
685
  ### Mappers
691
686
 
692
- `MutationResponseGraphQLMapper` is a NestJS injectable service provided by `SharedModule` that maps domain results to `MutationResponseDto`.
687
+ `MutationResponseGraphQLMapper` is a NestJS injectable that maps domain results to `MutationResponseDto`. Register it in the module that declares your resolvers (or a dedicated GraphQL module).
693
688
 
694
689
  ```typescript
695
690
  import { MutationResponseGraphQLMapper } from '@sisques-labs/nestjs-kit';
696
691
 
692
+ @Module({
693
+ providers: [MutationResponseGraphQLMapper, UserResolver],
694
+ })
695
+ export class UserGraphqlModule {}
696
+
697
697
  @Resolver()
698
698
  export class UserResolver {
699
699
  constructor(private readonly mutationMapper: MutationResponseGraphQLMapper) {}
@@ -710,7 +710,7 @@ export class UserResolver {
710
710
 
711
711
  ### Complexity Plugin
712
712
 
713
- `ComplexityPlugin` is an **Apollo Server plugin** (`@Plugin()` from `@nestjs/apollo`) that rejects operations whose estimated complexity exceeds **1000** (see `graphql-query-complexity`). It is **exported** from this package but **not** registered inside `SharedModule`—add it to your GraphQL module’s **`providers`** (or equivalent) so Nest discovers the plugin.
713
+ `ComplexityPlugin` is an **Apollo Server plugin** (`@Plugin()` from `@nestjs/apollo`) that rejects operations whose estimated complexity exceeds **1000** (see `graphql-query-complexity`). It is **exported** from this packageadd it to your GraphQL module’s **`providers`** (or equivalent) so Nest discovers the plugin.
714
714
 
715
715
  To assign complexity weights to fields use the `@Complexity` decorator from `@nestjs/graphql`:
716
716
 
@@ -741,6 +741,8 @@ export class GraphqlPluginsModule {}
741
741
 
742
742
  ## Enums
743
743
 
744
+ TypeScript enums are exported for domain and GraphQL use. For GraphQL schema generation, call **`registerSharedGraphqlEnums()`** once (see [Transport Layer (GraphQL)](#transport-layer-graphql)).
745
+
744
746
  ```typescript
745
747
  import {
746
748
  FilterOperator,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './shared/shared.module';
2
1
  export * from './shared/application/commands/base/base-command.handler';
3
2
  export * from './shared/application/commands/interfaces/base-command-handler.interface';
4
3
  export * from './shared/application/commands/update/base-update/base-update.command-handler';
@@ -66,8 +65,8 @@ export * from './shared/domain/value-objects/url/url.vo';
66
65
  export * from './shared/domain/value-objects/uuid/uuid.vo';
67
66
  export * from './shared/domain/view-models/base-view-model/base-view-model';
68
67
  export * from './shared/infrastructure/database/base-database.repository';
69
- export * from './shared/infrastructure/logging/formats/shared-winston.formats';
70
68
  export * from './shared/infrastructure/logging/factories/create-shared-winston-logger-options';
69
+ export * from './shared/infrastructure/logging/formats/shared-winston.formats';
71
70
  export * from './shared/infrastructure/logging/interfaces/shared-winston-logger-factory-options.interface';
72
71
  export * from './shared/infrastructure/database/mongodb/base-mongo/base-mongo-database.repository';
73
72
  export * from './shared/infrastructure/database/mongodb/base-mongo/base-mongo-master/base-mongo-master.repository';
@@ -80,6 +79,7 @@ export * from './shared/infrastructure/database/typeorm/entities/base-typeorm.en
80
79
  export * from './shared/infrastructure/database/typeorm/services/typeorm-master/typeorm-master.service';
81
80
  export * from './shared/infrastructure/database/typeorm/typeorm-module-options.factory';
82
81
  export * from './shared/infrastructure/database/typeorm/typeorm.module';
82
+ export * from './shared/transport/graphql/register-shared-graphql-enums';
83
83
  export * from './shared/transport/graphql/dtos/requests/base-filter/base-filter.input';
84
84
  export * from './shared/transport/graphql/dtos/requests/base-find-by-criteria/base-find-by-criteria.input';
85
85
  export * from './shared/transport/graphql/dtos/requests/base-pagination/base-pagination.input';
package/dist/index.js CHANGED
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./shared/shared.module"), exports);
18
17
  __exportStar(require("./shared/application/commands/base/base-command.handler"), exports);
19
18
  __exportStar(require("./shared/application/commands/interfaces/base-command-handler.interface"), exports);
20
19
  __exportStar(require("./shared/application/commands/update/base-update/base-update.command-handler"), exports);
@@ -82,8 +81,8 @@ __exportStar(require("./shared/domain/value-objects/url/url.vo"), exports);
82
81
  __exportStar(require("./shared/domain/value-objects/uuid/uuid.vo"), exports);
83
82
  __exportStar(require("./shared/domain/view-models/base-view-model/base-view-model"), exports);
84
83
  __exportStar(require("./shared/infrastructure/database/base-database.repository"), exports);
85
- __exportStar(require("./shared/infrastructure/logging/formats/shared-winston.formats"), exports);
86
84
  __exportStar(require("./shared/infrastructure/logging/factories/create-shared-winston-logger-options"), exports);
85
+ __exportStar(require("./shared/infrastructure/logging/formats/shared-winston.formats"), exports);
87
86
  __exportStar(require("./shared/infrastructure/logging/interfaces/shared-winston-logger-factory-options.interface"), exports);
88
87
  __exportStar(require("./shared/infrastructure/database/mongodb/base-mongo/base-mongo-database.repository"), exports);
89
88
  __exportStar(require("./shared/infrastructure/database/mongodb/base-mongo/base-mongo-master/base-mongo-master.repository"), exports);
@@ -96,6 +95,7 @@ __exportStar(require("./shared/infrastructure/database/typeorm/entities/base-typ
96
95
  __exportStar(require("./shared/infrastructure/database/typeorm/services/typeorm-master/typeorm-master.service"), exports);
97
96
  __exportStar(require("./shared/infrastructure/database/typeorm/typeorm-module-options.factory"), exports);
98
97
  __exportStar(require("./shared/infrastructure/database/typeorm/typeorm.module"), exports);
98
+ __exportStar(require("./shared/transport/graphql/register-shared-graphql-enums"), exports);
99
99
  __exportStar(require("./shared/transport/graphql/dtos/requests/base-filter/base-filter.input"), exports);
100
100
  __exportStar(require("./shared/transport/graphql/dtos/requests/base-find-by-criteria/base-find-by-criteria.input"), exports);
101
101
  __exportStar(require("./shared/transport/graphql/dtos/requests/base-pagination/base-pagination.input"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,yDAAuC;AAIvC,0FAAwE;AACxE,0GAAwF;AACxF,+GAA6F;AAC7F,kHAAgG;AAChG,oGAAkF;AAKlF,2FAAyE;AAGzE,oEAAkD;AAClD,mFAAiE;AAGjE,6EAA2D;AAC3D,qFAAmE;AACnE,4EAA0D;AAC1D,mGAAiF;AACjF,uGAAqF;AAGrF,8EAA4D;AAG5D,4EAA0D;AAC1D,qHAAmG;AACnG,iHAA+F;AAC/F,2HAAyG;AACzG,iHAA+F;AAC/F,2HAAyG;AACzG,6GAA2F;AAC3F,2GAAyF;AACzF,+GAA6F;AAC7F,mHAAiG;AACjG,mHAAiG;AACjG,iIAA+G;AAC/G,uHAAqG;AACrG,iHAA+F;AAC/F,mHAAiG;AACjG,uHAAqG;AACrG,6GAA2F;AAC3F,+GAA6F;AAG7F,0FAAwE;AACxE,2FAAyE;AACzE,sFAAoE;AACpE,8FAA4E;AAC5E,8FAA4E;AAC5E,+FAA6E;AAC7E,qFAAmE;AACnE,uGAAqF;AACrF,wGAAsF;AACtF,qFAAmE;AAGnE,6FAA2E;AAG3E,uFAAqE;AACrE,mFAAiE;AACjE,+EAA6D;AAC7D,6EAA2D;AAC3D,yFAAuE;AACvE,+EAA6D;AAC7D,6EAA2D;AAC3D,2EAAy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ACpE,8FAA4E;AAC5E,8FAA4E;AAC5E,+FAA6E;AAC7E,qFAAmE;AACnE,uGAAqF;AACrF,wGAAsF;AACtF,qFAAmE;AAGnE,6FAA2E;AAG3E,uFAAqE;AACrE,mFAAiE;AACjE,+EAA6D;AAC7D,6EAA2D;AAC3D,yFAAuE;AACvE,+EAA6D;AAC7D,6EAA2D;AAC3D,2EAAyD;AACzD,yEAAuD;AACvD,6EAA2D;AAC3D,2FAAyE;AACzE,iFAA+D;AAC/D,iFAA+D;AAC/D,+FAA6E;AAC7E,qFAAmE;AACnE,yFAAuE;AACvE,+EAA6D;AAC7D,6EAA2D;AAC3D,iFAA+D;AAC/D,qFAAmE;AACnE,2EAAyD;AACzD,6EAA2D;AAG3D,8FAA4E;AAI5E,4FAA0E;AAG1E,iHAA+F;AAC/F,iGAA+E;AAC/E,6HAA2G;AAG3G,qHAAmG;AACnG,qIAAmH;AACnH,+FAA6E;AAC7E,0FAAwE;AACxE,sHAAoG;AAGpG,2IAAyH;AACzH,iGAA+E;AAC/E,wGAAsF;AACtF,0HAAwG;AACxG,0GAAwF;AACxF,0FAAwE;AAKxE,2FAAyE;AAGzE,yGAAuF;AACvF,6HAA2G;AAC3G,iHAA+F;AAC/F,qGAAmF;AACnF,6GAA2F;AAG3F,4HAA0G;AAC1G,4GAA0F;AAC1F,kHAAgG;AAChG,6FAA2E;AAG3E,gHAA8F;AAG9F,uFAAqE"}
@@ -0,0 +1 @@
1
+ export declare function registerSharedGraphqlEnums(): void;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSharedGraphqlEnums = registerSharedGraphqlEnums;
4
+ const graphql_1 = require("@nestjs/graphql");
5
+ const filter_operator_enum_1 = require("../../domain/enums/filter-operator.enum");
6
+ const length_unit_enum_1 = require("../../domain/enums/length-unit/length-unit.enum");
7
+ const sort_direction_enum_1 = require("../../domain/enums/sort-direction.enum");
8
+ const user_role_enum_1 = require("../../domain/enums/user-context/user/user-role/user-role.enum");
9
+ const user_status_enum_1 = require("../../domain/enums/user-context/user/user-status/user-status.enum");
10
+ const DEFINITIONS = [
11
+ {
12
+ enum: filter_operator_enum_1.FilterOperator,
13
+ name: 'FilterOperator',
14
+ description: 'The operator to filter by',
15
+ },
16
+ {
17
+ enum: sort_direction_enum_1.SortDirection,
18
+ name: 'SortDirection',
19
+ description: 'The direction to sort by',
20
+ },
21
+ {
22
+ enum: length_unit_enum_1.LengthUnitEnum,
23
+ name: 'LengthUnitEnum',
24
+ description: 'The unit of the length',
25
+ },
26
+ {
27
+ enum: user_role_enum_1.UserRoleEnum,
28
+ name: 'UserRoleEnum',
29
+ description: 'The role of the user',
30
+ },
31
+ {
32
+ enum: user_status_enum_1.UserStatusEnum,
33
+ name: 'UserStatusEnum',
34
+ description: 'The status of the user',
35
+ },
36
+ ];
37
+ let registered = false;
38
+ function registerSharedGraphqlEnums() {
39
+ if (registered) {
40
+ return;
41
+ }
42
+ registered = true;
43
+ for (const { enum: enumType, name, description } of DEFINITIONS) {
44
+ (0, graphql_1.registerEnumType)(enumType, { name, description });
45
+ }
46
+ }
47
+ //# sourceMappingURL=register-shared-graphql-enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-shared-graphql-enums.js","sourceRoot":"","sources":["../../../../src/shared/transport/graphql/register-shared-graphql-enums.ts"],"names":[],"mappings":";;AA0CA,gEAQC;AAlDD,6CAAmD;AAEnD,kFAA4E;AAC5E,sFAAoF;AACpF,gFAA0E;AAC1E,kGAAgG;AAChG,wGAAsG;AAEtG,MAAM,WAAW,GAAG;IAClB;QACE,IAAI,EAAE,qCAAc;QACpB,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,2BAA2B;KACzC;IACD;QACE,IAAI,EAAE,mCAAa;QACnB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,0BAA0B;KACxC;IACD;QACE,IAAI,EAAE,iCAAc;QACpB,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,wBAAwB;KACtC;IACD;QACE,IAAI,EAAE,6BAAY;QAClB,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,sBAAsB;KACpC;IACD;QACE,IAAI,EAAE,iCAAc;QACpB,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,wBAAwB;KACtC;CACO,CAAC;AAEX,IAAI,UAAU,GAAG,KAAK,CAAC;AAMvB,SAAgB,0BAA0B;IACxC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IACD,UAAU,GAAG,IAAI,CAAC;IAClB,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,WAAW,EAAE,CAAC;QAChE,IAAA,0BAAgB,EAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}