nest-hex 0.3.2 → 0.4.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.
Files changed (31) hide show
  1. package/README.md +59 -16
  2. package/dist/shared/chunk-btf6z45c.js +13 -0
  3. package/dist/src/cli/bin.js +24 -2612
  4. package/dist/src/cli/commands/index.js +157 -2227
  5. package/dist/src/cli/config/defaults.js +3 -57
  6. package/dist/src/cli/config/define-config.js +3 -57
  7. package/dist/src/cli/config/loader.js +16 -88
  8. package/dist/src/cli/config/validator.js +5 -59
  9. package/dist/src/cli/generators/adapter.generator.js +23 -329
  10. package/dist/src/cli/generators/base.generator.js +21 -239
  11. package/dist/src/cli/generators/index.js +23 -466
  12. package/dist/src/cli/generators/port.generator.js +23 -329
  13. package/dist/src/cli/generators/service.generator.js +15 -321
  14. package/dist/src/cli/index.js +6 -68
  15. package/dist/src/cli/types/config.types.js +0 -56
  16. package/dist/src/cli/types/generator.types.js +0 -56
  17. package/dist/src/cli/types/index.js +0 -56
  18. package/dist/src/cli/types/template.types.js +0 -56
  19. package/dist/src/cli/ui/components/index.d.ts +9 -2
  20. package/dist/src/cli/ui/components/index.js +322 -1137
  21. package/dist/src/cli/utils/file-writer.d.ts +0 -4
  22. package/dist/src/cli/utils/file-writer.js +13 -60
  23. package/dist/src/cli/utils/linter-detector.js +10 -64
  24. package/dist/src/cli/utils/linter-runner.js +5 -59
  25. package/dist/src/cli/utils/name-transformer.js +3 -62
  26. package/dist/src/cli/utils/path-resolver.js +8 -65
  27. package/dist/src/cli/utils/port-scanner.js +12 -67
  28. package/dist/src/cli/utils/template-renderer.js +11 -64
  29. package/dist/src/index.d.ts +23 -48
  30. package/dist/src/index.js +20 -77
  31. package/package.json +11 -8
package/README.md CHANGED
@@ -1,8 +1,17 @@
1
- # nest-hex
1
+ </br>
2
+ <img src="https://raw.githubusercontent.com/LiorVainer/nest-hex/main/assets/icon.png">
3
+ </br>
4
+ </br>
2
5
 
3
- > A tiny, **class-based**, **NestJS-native** library for building **pluggable adapters** following the Ports & Adapters (Hexagonal Architecture) pattern with minimal boilerplate.
6
+ ## nest-hex
7
+
8
+ [![test coverage](https://badgen.net/badge/coverage/100%25/green?icon=github)](https://github.com/LiorVainer/nest-hex)
9
+ [![npm version](https://img.shields.io/npm/v/nest-hex?color=f00e0e&logo=npm&style=flat)](https://www.npmjs.com/package/nest-hex)
10
+ [![install size](https://packagephobia.com/badge?p=nest-hex)](https://packagephobia.com/result?p=nest-hex)
11
+ [![minizipped size](https://img.shields.io/bundlephobia/minzip/nest-hex)](https://packagephobia.com/result?p=nest-hex)
12
+ [![License](https://img.shields.io/github/license/liorvainer/nest-hex?color=orange)](https://www.npmjs.com/package/nest-hex)
4
13
 
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
14
+ > A tiny, **class-based**, **NestJS-native** library for building **pluggable adapters** following the Ports & Adapters (Hexagonal Architecture) pattern with minimal boilerplate.
6
15
 
7
16
  ## What is nest-hex?
8
17
 
@@ -58,15 +67,27 @@ export interface StoragePort {
58
67
  ### 2. Create an Adapter (Infrastructure Implementation)
59
68
 
60
69
  ```typescript
61
- // s3.adapter.ts
70
+ // s3.types.ts - Configuration types
71
+ import type { AdapterConfig } from 'nest-hex'
72
+ import type { STORAGE_PORT, StoragePort } from './storage.port'
73
+
74
+ export interface S3Options {
75
+ bucket: string
76
+ region: string
77
+ }
78
+
79
+ export type StorageToken = typeof STORAGE_PORT
80
+
81
+ export type S3AdapterConfig = AdapterConfig<StorageToken, StoragePort>
82
+
83
+ // s3.service.ts - Implementation service
62
84
  import { Injectable } from '@nestjs/common'
63
- import { Adapter } from 'nest-hex'
64
- import { STORAGE_PORT, type StoragePort } from './storage.port'
85
+ import type { StoragePort } from './storage.port'
86
+ import type { S3Options } from './s3.types'
65
87
 
66
- // Implementation service
67
88
  @Injectable()
68
- class S3Service implements StoragePort {
69
- constructor(private options: { bucket: string; region: string }) {}
89
+ export class S3Service implements StoragePort {
90
+ constructor(private options: S3Options) {}
70
91
 
71
92
  async upload(key: string, data: Buffer): Promise<string> {
72
93
  // AWS S3 upload logic here
@@ -79,12 +100,18 @@ class S3Service implements StoragePort {
79
100
  }
80
101
  }
81
102
 
82
- // Adapter module - single decorator declares everything!
83
- @Adapter({
103
+ // s3.adapter.ts - Adapter module
104
+ import { Adapter, AdapterBase } from 'nest-hex'
105
+ import { STORAGE_PORT } from './storage.port'
106
+ import { S3Service } from './s3.service'
107
+ import type { S3AdapterConfig, S3Options } from './s3.types'
108
+
109
+ // Single decorator with type safety!
110
+ @Adapter<S3AdapterConfig>({
84
111
  portToken: STORAGE_PORT,
85
112
  implementation: S3Service
86
113
  })
87
- export class S3Adapter extends AdapterBase<{ bucket: string; region: string }> {}
114
+ export class S3Adapter extends AdapterBase<S3Options> {}
88
115
  ```
89
116
 
90
117
  ### 3. Create a Domain Service
@@ -118,7 +145,7 @@ import { PortModule } from 'nest-hex'
118
145
  import { FileService } from './file.service'
119
146
 
120
147
  @Module({})
121
- export class FileModule extends PortModule<typeof FileService> {}
148
+ export class FileModule extends PortModule {}
122
149
  ```
123
150
 
124
151
  ### 5. Wire It Up
@@ -188,7 +215,12 @@ export class S3StorageModule {
188
215
  ### After (With nest-hex)
189
216
 
190
217
  ```typescript
191
- @Adapter({
218
+ // s3.types.ts
219
+ export type StorageToken = typeof STORAGE_PORT
220
+ export type S3AdapterConfig = AdapterConfig<StorageToken, StoragePort>
221
+
222
+ // s3.adapter.ts
223
+ @Adapter<S3AdapterConfig>({
192
224
  portToken: STORAGE_PORT,
193
225
  implementation: S3StorageService
194
226
  })
@@ -238,7 +270,12 @@ export class AppModule {}
238
270
  ### Adapters with Dependencies
239
271
 
240
272
  ```typescript
241
- @Adapter({
273
+ // axios.types.ts
274
+ export type HttpClientToken = typeof HTTP_CLIENT_PORT
275
+ export type AxiosAdapterConfig = AdapterConfig<HttpClientToken, HttpClientPort>
276
+
277
+ // axios.adapter.ts
278
+ @Adapter<AxiosAdapterConfig>({
242
279
  portToken: HTTP_CLIENT_PORT,
243
280
  implementation: AxiosHttpClient,
244
281
  imports: [HttpModule],
@@ -252,6 +289,11 @@ export class AxiosAdapter extends AdapterBase<AxiosOptions> {}
252
289
  ### Mock Adapters for Testing
253
290
 
254
291
  ```typescript
292
+ // mock-storage.types.ts
293
+ export type StorageToken = typeof STORAGE_PORT
294
+ export type MockStorageAdapterConfig = AdapterConfig<StorageToken, StoragePort>
295
+
296
+ // mock-storage.service.ts
255
297
  @Injectable()
256
298
  class MockStorageService implements StoragePort {
257
299
  async upload(key: string, data: Buffer): Promise<string> {
@@ -262,7 +304,8 @@ class MockStorageService implements StoragePort {
262
304
  }
263
305
  }
264
306
 
265
- @Adapter({
307
+ // mock-storage.adapter.ts
308
+ @Adapter<MockStorageAdapterConfig>({
266
309
  portToken: STORAGE_PORT,
267
310
  implementation: MockStorageService
268
311
  })
@@ -0,0 +1,13 @@
1
+ import { createRequire } from "node:module";
2
+ var __legacyDecorateClassTS = function(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
5
+ r = Reflect.decorate(decorators, target, key, desc);
6
+ else
7
+ for (var i = decorators.length - 1;i >= 0; i--)
8
+ if (d = decorators[i])
9
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
11
+ };
12
+
13
+ export { __legacyDecorateClassTS };