typemold 1.0.2 → 2.0.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 (2) hide show
  1. package/README.md +72 -59
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -4,6 +4,7 @@ A **lightweight**, **high-performance** object mapper for TypeScript & Node.js w
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/typemold.svg)](https://www.npmjs.com/package/typemold)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Downloads](https://img.shields.io/npm/dm/typemold.svg)](https://www.npmjs.com/package/typemold)
7
8
 
8
9
  ## Features
9
10
 
@@ -11,20 +12,46 @@ A **lightweight**, **high-performance** object mapper for TypeScript & Node.js w
11
12
  - 🎯 **Runtime Field Projection** - Pick/omit fields without creating multiple DTOs
12
13
  - 📦 **Lightweight** - ~3KB gzipped, zero runtime dependencies
13
14
  - 🏷️ **Field Groups** - Define reusable field sets with decorators
14
- - 🔧 **NestJS Integration** - Full module support with DI
15
+ - 🔧 **NestJS Integration** - Full module support with DI (separate import)
15
16
  - ✅ **TypeScript First** - Full strict mode support
16
17
  - 🔄 **Hybrid Validation** - Optional class-validator integration
17
18
 
18
- ## Installation
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ### Node.js / Express / Fastify
19
24
 
20
25
  ```bash
21
- npm install typemold
26
+ npm install typemold reflect-metadata
27
+ ```
28
+
29
+ ```typescript
30
+ // Usage
31
+ import { Mapper, AutoMap, MapFrom } from "typemold";
32
+ ```
33
+
34
+ ---
35
+
36
+ ### NestJS
37
+
38
+ ```bash
39
+ npm install typemold reflect-metadata
40
+ ```
22
41
 
23
- # Peer dependency (already in NestJS projects)
24
- npm install reflect-metadata
42
+ ```typescript
43
+ // Core decorators & Mapper
44
+ import { Mapper, AutoMap, MapFrom } from "typemold";
45
+
46
+ // NestJS module & service (separate subpath)
47
+ import { MapperModule, MapperService } from "typemold/nestjs";
25
48
  ```
26
49
 
27
- ## Quick Start
50
+ > **Note:** NestJS integration requires `@nestjs/common` and `@nestjs/core` (usually already installed in NestJS projects).
51
+
52
+ ---
53
+
54
+ ## 🚀 Quick Start
28
55
 
29
56
  ### 1. Define Your DTO
30
57
 
@@ -58,7 +85,9 @@ const userDto = Mapper.map(userEntity, UserDto);
58
85
  const userDtos = Mapper.mapArray(users, UserDto);
59
86
  ```
60
87
 
61
- ## Runtime Field Projection ⭐
88
+ ---
89
+
90
+ ## ⭐ Runtime Field Projection
62
91
 
63
92
  **The killer feature** - reuse a single DTO across multiple endpoints:
64
93
 
@@ -67,7 +96,7 @@ const userDtos = Mapper.mapArray(users, UserDto);
67
96
  Mapper.map(user, UserDto);
68
97
  // Result: { username, avatarUrl, isAdult, email }
69
98
 
70
- // Only username and avatar (shorthand)
99
+ // Only username and avatar
71
100
  Mapper.pick(user, UserDto, ["username", "avatarUrl"]);
72
101
  // Result: { username, avatarUrl }
73
102
 
@@ -80,7 +109,9 @@ Mapper.map(user, UserDto, { pick: ["username", "avatarUrl"] });
80
109
  Mapper.map(user, UserDto, { omit: ["email"] });
81
110
  ```
82
111
 
83
- ## Field Groups
112
+ ---
113
+
114
+ ## 🏷️ Field Groups
84
115
 
85
116
  Define reusable field sets:
86
117
 
@@ -107,12 +138,11 @@ class UserDto {
107
138
  Mapper.group(user, UserDto, "minimal"); // { username, avatar }
108
139
  Mapper.group(user, UserDto, "public"); // { username, avatar, bio }
109
140
  Mapper.group(user, UserDto, "full"); // { bio, email }
110
-
111
- // Or via options
112
- Mapper.map(user, UserDto, { group: "minimal" });
113
141
  ```
114
142
 
115
- ## Decorators
143
+ ---
144
+
145
+ ## 🎨 Decorators
116
146
 
117
147
  | Decorator | Description | Example |
118
148
  | ------------------------- | ---------------------------- | ------------------------------------------------ |
@@ -123,46 +153,20 @@ Mapper.map(user, UserDto, { group: "minimal" });
123
153
  | `@Ignore()` | Skips property | `@Ignore() internalId: string` |
124
154
  | `@NestedType(() => Type)` | Nested object mapping | `@NestedType(() => AddressDto)` |
125
155
 
126
- ## NestJS Integration
156
+ ---
127
157
 
128
- ### Basic Setup
158
+ ## 🔧 NestJS Integration
129
159
 
130
- ```typescript
131
- import { Module } from "@nestjs/common";
132
- import { MapperModule } from "typemold";
160
+ > Import from `typemold/nestjs`
133
161
 
134
- @Module({
135
- imports: [MapperModule.forRoot()], // Global by default
136
- })
137
- export class AppModule {}
138
- ```
139
-
140
- ### With Validation
162
+ ### Setup
141
163
 
142
164
  ```typescript
143
- @Module({
144
- imports: [
145
- MapperModule.forRoot({
146
- enableValidation: true, // Uses class-validator if installed
147
- }),
148
- ],
149
- })
150
- export class AppModule {}
151
- ```
152
-
153
- ### Async Configuration
165
+ import { Module } from "@nestjs/common";
166
+ import { MapperModule } from "typemold/nestjs";
154
167
 
155
- ```typescript
156
168
  @Module({
157
- imports: [
158
- MapperModule.forRootAsync({
159
- imports: [ConfigModule],
160
- useFactory: (config: ConfigService) => ({
161
- enableValidation: config.get("ENABLE_VALIDATION"),
162
- }),
163
- inject: [ConfigService],
164
- }),
165
- ],
169
+ imports: [MapperModule.forRoot()],
166
170
  })
167
171
  export class AppModule {}
168
172
  ```
@@ -171,7 +175,7 @@ export class AppModule {}
171
175
 
172
176
  ```typescript
173
177
  import { Injectable } from "@nestjs/common";
174
- import { MapperService } from "typemold";
178
+ import { MapperService } from "typemold/nestjs";
175
179
 
176
180
  @Injectable()
177
181
  export class UserService {
@@ -182,23 +186,28 @@ export class UserService {
182
186
  return this.mapper.map(user, UserDto);
183
187
  }
184
188
 
185
- async getUserMinimal(id: string): Promise<Partial<UserDto>> {
189
+ async getUserMinimal(id: string) {
186
190
  const user = await this.userRepo.findOne(id);
187
191
  return this.mapper.group(user, UserDto, "minimal");
188
192
  }
189
-
190
- async getPostAuthor(
191
- postId: string
192
- ): Promise<Pick<UserDto, "username" | "avatar">> {
193
- const user = await this.getPostUser(postId);
194
- return this.mapper.pick(user, UserDto, ["username", "avatar"]);
195
- }
196
193
  }
197
194
  ```
198
195
 
199
- ## Performance
196
+ ### Async Configuration
197
+
198
+ ```typescript
199
+ MapperModule.forRootAsync({
200
+ imports: [ConfigModule],
201
+ useFactory: (config: ConfigService) => ({
202
+ enableValidation: config.get("ENABLE_VALIDATION"),
203
+ }),
204
+ inject: [ConfigService],
205
+ });
206
+ ```
207
+
208
+ ---
200
209
 
201
- Thanks to compiled & cached mappers, performance is near-identical to hand-written mapping code:
210
+ ## Performance
202
211
 
203
212
  | Operation | typemold | @automapper/nestjs | Manual |
204
213
  | ------------ | ---------- | ------------------ | -------- |
@@ -206,7 +215,9 @@ Thanks to compiled & cached mappers, performance is near-identical to hand-writt
206
215
  | Array (1000) | ~1.5ms | ~40ms | ~1ms |
207
216
  | Memory | O(1) cache | O(n) profiles | None |
208
217
 
209
- ## API Reference
218
+ ---
219
+
220
+ ## 📚 API Reference
210
221
 
211
222
  ### Mapper (Static)
212
223
 
@@ -216,7 +227,7 @@ Mapper.mapArray(sources, TargetDto, options?)
216
227
  Mapper.pick(source, TargetDto, ['field1', 'field2'])
217
228
  Mapper.omit(source, TargetDto, ['field1'])
218
229
  Mapper.group(source, TargetDto, 'groupName')
219
- Mapper.createMapper(TargetDto, options?) // Returns reusable function
230
+ Mapper.createMapper(TargetDto, options?)
220
231
  ```
221
232
 
222
233
  ### MapOptions
@@ -230,6 +241,8 @@ interface MapOptions<T> {
230
241
  }
231
242
  ```
232
243
 
244
+ ---
245
+
233
246
  ## License
234
247
 
235
248
  MIT © [Chetan Joshi](https://github.com/ErrorX407)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typemold",
3
- "version": "1.0.2",
3
+ "version": "2.0.0",
4
4
  "description": "A lightweight, high-performance object mapper for TypeScript and Node.js with runtime field projection",
5
5
  "author": {
6
6
  "name": "Chetan Joshi",
@@ -60,9 +60,9 @@
60
60
  },
61
61
  "homepage": "https://github.com/ErrorX407/typemold#readme",
62
62
  "peerDependencies": {
63
- "reflect-metadata": "^0.1.13 || ^0.2.0",
64
63
  "@nestjs/common": ">=9.0.0",
65
- "@nestjs/core": ">=9.0.0"
64
+ "@nestjs/core": ">=9.0.0",
65
+ "reflect-metadata": "^0.1.13 || ^0.2.0"
66
66
  },
67
67
  "peerDependenciesMeta": {
68
68
  "@nestjs/common": {