@tactical-ddd/nx 0.0.1-alpha.3 → 0.0.2-alpha.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 +66 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,12 +63,75 @@ libs/shared/
|
|
|
63
63
|
This is the lowest and most abstract layer of the application. It establishes the "social contracts" between different parts of the system and the backend.
|
|
64
64
|
|
|
65
65
|
- **What's inside:** Global TypeScript interfaces, data types, validation schemas (Zod/Yup), API response shapes (DTOs), and global domain event structures.
|
|
66
|
-
- **Default Interfaces:**
|
|
67
|
-
- `HttpClient` — a generic interface for HTTP clients (GET, POST, PUT, PATCH, DELETE).
|
|
68
|
-
- `Store` — a simple key-value storage interface (GET, SET, DELETE).
|
|
66
|
+
- **Default Interfaces:** Ships with two foundational infrastructure contracts — `HttpClient` and `Store` (see [Default Contracts](#default-contracts) below).
|
|
69
67
|
- **Features:** This library is generated without a unit test runner (`unitTestRunner: 'none'`) because it contains strictly compile-time types and interfaces that carry no executable logic.
|
|
70
68
|
- **Import Rule:** It is strictly forbidden to import anything into this library from any other modules in the workspace.
|
|
71
69
|
|
|
70
|
+
#### Default Contracts
|
|
71
|
+
|
|
72
|
+
The `contracts` library is not generated empty — it is seeded with two foundational infrastructure contracts that the rest of the architecture (notably `libs/shared/infrastructure`) is expected to implement. Each interface is paired with a DI token (`Symbol.for(...)`), so it can be bound and resolved through a dependency-injection container (e.g. Inversify) without leaking the concrete implementation. Both are re-exported from the library barrel (`index.ts`):
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { HttpClient, HttpClientOptions, Store } from '@my-org/shared-contracts';
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| Interface | DI Token | Purpose |
|
|
79
|
+
| ------------ | -------------- | ------------------------------------------------------------------------------- |
|
|
80
|
+
| `HttpClient` | `HttpClient.$` | Transport-agnostic HTTP contract (`get` / `post` / `put` / `patch` / `delete`). |
|
|
81
|
+
| `Store` | `Store.$` | Async key/value persistence contract (`set` / `get` / `delete`). |
|
|
82
|
+
|
|
83
|
+
##### `HttpClient`
|
|
84
|
+
|
|
85
|
+
A framework- and library-agnostic HTTP boundary. Concrete implementations (Axios, Fetch, etc.) live in `libs/shared/infrastructure`; consumers depend only on this interface. The companion `HttpClientOptions` type carries per-request settings (e.g. `timeout`).
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
export type HttpClientOptions = {
|
|
89
|
+
timeout: number;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export interface HttpClient {
|
|
93
|
+
get<T>(url: string, options?: HttpClientOptions): Promise<T>;
|
|
94
|
+
post<T, K = unknown>(
|
|
95
|
+
url: string,
|
|
96
|
+
data?: K,
|
|
97
|
+
options?: HttpClientOptions,
|
|
98
|
+
): Promise<T>;
|
|
99
|
+
put<T, K = unknown>(
|
|
100
|
+
url: string,
|
|
101
|
+
data?: K,
|
|
102
|
+
options?: HttpClientOptions,
|
|
103
|
+
): Promise<T>;
|
|
104
|
+
patch<T, K = unknown>(
|
|
105
|
+
url: string,
|
|
106
|
+
data?: K,
|
|
107
|
+
options?: HttpClientOptions,
|
|
108
|
+
): Promise<T>;
|
|
109
|
+
delete<T>(url: string, options?: HttpClientOptions): Promise<T>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// DI token — bind your concrete client to this symbol.
|
|
113
|
+
export const HttpClient = {
|
|
114
|
+
$: Symbol.for('HttpClient'),
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
##### `Store`
|
|
119
|
+
|
|
120
|
+
A generic, async key/value persistence boundary. Back it with `localStorage`, `IndexedDB`, an in-memory map, or any remote store — the contract stays the same.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
export interface Store {
|
|
124
|
+
set<T>(key: string, value: T): Promise<boolean>;
|
|
125
|
+
get<T>(key: string): Promise<T | null>;
|
|
126
|
+
delete(service: string): Promise<boolean>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// DI token — bind your concrete store to this symbol.
|
|
130
|
+
export const Store = {
|
|
131
|
+
$: Symbol.for('Store'),
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
|
|
72
135
|
### 2. 🛠 utils
|
|
73
136
|
|
|
74
137
|
**Nx Tags:** `scope:shared`, `type:utils`
|