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.
- package/README.md +59 -16
- package/dist/shared/chunk-btf6z45c.js +13 -0
- package/dist/src/cli/bin.js +24 -2612
- package/dist/src/cli/commands/index.js +157 -2227
- package/dist/src/cli/config/defaults.js +3 -57
- package/dist/src/cli/config/define-config.js +3 -57
- package/dist/src/cli/config/loader.js +16 -88
- package/dist/src/cli/config/validator.js +5 -59
- package/dist/src/cli/generators/adapter.generator.js +23 -329
- package/dist/src/cli/generators/base.generator.js +21 -239
- package/dist/src/cli/generators/index.js +23 -466
- package/dist/src/cli/generators/port.generator.js +23 -329
- package/dist/src/cli/generators/service.generator.js +15 -321
- package/dist/src/cli/index.js +6 -68
- package/dist/src/cli/types/config.types.js +0 -56
- package/dist/src/cli/types/generator.types.js +0 -56
- package/dist/src/cli/types/index.js +0 -56
- package/dist/src/cli/types/template.types.js +0 -56
- package/dist/src/cli/ui/components/index.d.ts +9 -2
- package/dist/src/cli/ui/components/index.js +322 -1137
- package/dist/src/cli/utils/file-writer.d.ts +0 -4
- package/dist/src/cli/utils/file-writer.js +13 -60
- package/dist/src/cli/utils/linter-detector.js +10 -64
- package/dist/src/cli/utils/linter-runner.js +5 -59
- package/dist/src/cli/utils/name-transformer.js +3 -62
- package/dist/src/cli/utils/path-resolver.js +8 -65
- package/dist/src/cli/utils/port-scanner.js +12 -67
- package/dist/src/cli/utils/template-renderer.js +11 -64
- package/dist/src/index.d.ts +23 -48
- package/dist/src/index.js +20 -77
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
</br>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/LiorVainer/nest-hex/main/assets/icon.png">
|
|
3
|
+
</br>
|
|
4
|
+
</br>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
## nest-hex
|
|
7
|
+
|
|
8
|
+
[](https://github.com/LiorVainer/nest-hex)
|
|
9
|
+
[](https://www.npmjs.com/package/nest-hex)
|
|
10
|
+
[](https://packagephobia.com/result?p=nest-hex)
|
|
11
|
+
[](https://packagephobia.com/result?p=nest-hex)
|
|
12
|
+
[](https://www.npmjs.com/package/nest-hex)
|
|
4
13
|
|
|
5
|
-
|
|
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.
|
|
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 {
|
|
64
|
-
import {
|
|
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:
|
|
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
|
-
//
|
|
83
|
-
|
|
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<
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|