typemold 1.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 (39) hide show
  1. package/LICENSE +43 -0
  2. package/README.md +235 -0
  3. package/dist/cjs/decorators.js +284 -0
  4. package/dist/cjs/index.js +74 -0
  5. package/dist/cjs/mapper.js +153 -0
  6. package/dist/cjs/nestjs/index.js +12 -0
  7. package/dist/cjs/nestjs/mapper.module.js +103 -0
  8. package/dist/cjs/nestjs/mapper.service.js +161 -0
  9. package/dist/cjs/registry.js +179 -0
  10. package/dist/cjs/types.js +17 -0
  11. package/dist/cjs/utils.js +136 -0
  12. package/dist/esm/decorators.js +274 -0
  13. package/dist/esm/index.js +51 -0
  14. package/dist/esm/mapper.js +149 -0
  15. package/dist/esm/nestjs/index.js +6 -0
  16. package/dist/esm/nestjs/mapper.module.js +100 -0
  17. package/dist/esm/nestjs/mapper.service.js +125 -0
  18. package/dist/esm/registry.js +175 -0
  19. package/dist/esm/types.js +14 -0
  20. package/dist/esm/utils.js +127 -0
  21. package/dist/types/decorators.d.ts +206 -0
  22. package/dist/types/decorators.d.ts.map +1 -0
  23. package/dist/types/index.d.ts +46 -0
  24. package/dist/types/index.d.ts.map +1 -0
  25. package/dist/types/mapper.d.ts +93 -0
  26. package/dist/types/mapper.d.ts.map +1 -0
  27. package/dist/types/nestjs/index.d.ts +7 -0
  28. package/dist/types/nestjs/index.d.ts.map +1 -0
  29. package/dist/types/nestjs/mapper.module.d.ts +89 -0
  30. package/dist/types/nestjs/mapper.module.d.ts.map +1 -0
  31. package/dist/types/nestjs/mapper.service.d.ts +80 -0
  32. package/dist/types/nestjs/mapper.service.d.ts.map +1 -0
  33. package/dist/types/registry.d.ts +60 -0
  34. package/dist/types/registry.d.ts.map +1 -0
  35. package/dist/types/types.d.ts +120 -0
  36. package/dist/types/types.d.ts.map +1 -0
  37. package/dist/types/utils.d.ts +30 -0
  38. package/dist/types/utils.d.ts.map +1 -0
  39. package/package.json +92 -0
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @sevirial/nest-mapper - Decorators
3
+ * Property decorators for defining mapping configurations
4
+ */
5
+ import "reflect-metadata";
6
+ import { PropertyPath, TransformFn, Constructor } from "./types";
7
+ /**
8
+ * Maps a property from a source path or using a transform function.
9
+ *
10
+ * @example
11
+ * // Direct property mapping
12
+ * class UserDto {
13
+ * @MapFrom('firstName')
14
+ * name: string;
15
+ * }
16
+ *
17
+ * @example
18
+ * // Nested path mapping
19
+ * class UserDto {
20
+ * @MapFrom('profile.avatar')
21
+ * avatarUrl: string;
22
+ * }
23
+ *
24
+ * @example
25
+ * // Transform function with typed source
26
+ * class UserDto {
27
+ * @MapFrom<User>((src) => src.age >= 18) // ← IntelliSense for src!
28
+ * isAdult: boolean;
29
+ * }
30
+ */
31
+ export declare function MapFrom<TSource = any>(sourcePathOrTransform: PropertyPath | TransformFn<TSource>): PropertyDecorator;
32
+ /**
33
+ * Creates a type-safe mapping configuration with full IntelliSense support.
34
+ * Use this builder pattern when you need autocomplete for source paths.
35
+ *
36
+ * @example
37
+ * interface User {
38
+ * username: string;
39
+ * profile: { avatar: string; bio: string };
40
+ * }
41
+ *
42
+ * // Option 1: Define mappings with full autocomplete
43
+ * const toUserDto = createMapping<User, UserDto>({
44
+ * avatar: 'profile.avatar', // ✨ Autocomplete for paths!
45
+ * bio: src => src.profile.bio, // ✨ Autocomplete for transforms!
46
+ * });
47
+ *
48
+ * // Usage
49
+ * const dto = toUserDto(userEntity);
50
+ *
51
+ * @example
52
+ * // Option 2: Use with Mapper
53
+ * const dto = Mapper.mapWith(user, toUserDto);
54
+ */
55
+ export declare function createMapping<TSource, TTarget>(mappings: TypedMappingConfig<TSource, TTarget>): (source: TSource) => Partial<TTarget>;
56
+ /**
57
+ * Type-safe mapping configuration object.
58
+ * Keys are target DTO properties, values are source paths or transform functions.
59
+ */
60
+ export type TypedMappingConfig<TSource, TTarget> = {
61
+ [K in keyof TTarget]?: PathsOf<TSource> | ((source: TSource) => TTarget[K]);
62
+ };
63
+ /**
64
+ * Utility type that extracts all possible dot-notation paths from an object type.
65
+ * Provides IntelliSense for nested property paths.
66
+ *
67
+ * @example
68
+ * type User = { profile: { avatar: string } };
69
+ * type Paths = PathsOf<User>; // 'profile' | 'profile.avatar'
70
+ */
71
+ export type PathsOf<T, Depth extends number = 3> = Depth extends 0 ? never : T extends object ? {
72
+ [K in keyof T & string]: T[K] extends object ? K | `${K}.${PathsOf<T[K], Prev[Depth]>}` : K;
73
+ }[keyof T & string] : never;
74
+ type Prev = [never, 0, 1, 2, 3];
75
+ /**
76
+ * Automatically maps a property with the same name from source.
77
+ *
78
+ * @example
79
+ * class UserDto {
80
+ * @AutoMap()
81
+ * username: string; // Maps from source.username
82
+ * }
83
+ */
84
+ export declare function AutoMap(): PropertyDecorator;
85
+ /**
86
+ * Assigns a property to one or more field groups for runtime projection.
87
+ *
88
+ * @example
89
+ * // Basic usage with strings
90
+ * class UserDto {
91
+ * @FieldGroup('minimal', 'public')
92
+ * @AutoMap()
93
+ * username: string;
94
+ * }
95
+ *
96
+ * @example
97
+ * // Type-safe usage with const object (recommended for autocomplete!)
98
+ * const Groups = createFieldGroups('minimal', 'public', 'full');
99
+ *
100
+ * class UserDto {
101
+ * @FieldGroup(Groups.minimal, Groups.public) // ✨ Autocomplete!
102
+ * @AutoMap()
103
+ * username: string;
104
+ * }
105
+ */
106
+ export declare function FieldGroup(...groups: string[]): PropertyDecorator;
107
+ /**
108
+ * Creates a type-safe field groups object with autocomplete support.
109
+ * Use this to define your groups once and get IntelliSense everywhere!
110
+ *
111
+ * @example
112
+ * // Define groups once
113
+ * export const UserGroups = createFieldGroups('minimal', 'public', 'full');
114
+ *
115
+ * class UserDto {
116
+ * @FieldGroup(UserGroups.minimal, UserGroups.public) // ✨ Autocomplete!
117
+ * @AutoMap()
118
+ * username: string;
119
+ *
120
+ * @FieldGroup(UserGroups.full)
121
+ * @AutoMap()
122
+ * email: string;
123
+ * }
124
+ *
125
+ * // Usage with type-safety
126
+ * Mapper.map(user, UserDto, { group: UserGroups.minimal }); // ✨ Autocomplete!
127
+ */
128
+ export declare function createFieldGroups<T extends string>(...groups: T[]): {
129
+ readonly [K in T]: K;
130
+ };
131
+ /**
132
+ * Type for extracting group names from a created field groups object.
133
+ * Useful for typing function parameters.
134
+ *
135
+ * @example
136
+ * const Groups = createFieldGroups('minimal', 'public', 'full');
137
+ * type GroupName = GroupsOf<typeof Groups>; // 'minimal' | 'public' | 'full'
138
+ */
139
+ export type GroupsOf<T> = T extends {
140
+ [K in infer U]: K;
141
+ } ? U : never;
142
+ /**
143
+ * Built-in field groups with autocomplete - use these directly!
144
+ * No need to define your own groups for common use cases.
145
+ *
146
+ * @example
147
+ * class UserDto {
148
+ * @FieldGroup(Groups.MINIMAL, Groups.PUBLIC) // ✨ Autocomplete!
149
+ * @AutoMap()
150
+ * username: string;
151
+ *
152
+ * @FieldGroup(Groups.DETAILED)
153
+ * @AutoMap()
154
+ * email: string;
155
+ * }
156
+ *
157
+ * // Usage
158
+ * Mapper.map(user, UserDto, { group: Groups.MINIMAL }); // ✨ Autocomplete!
159
+ */
160
+ export declare const Groups: Readonly<{
161
+ /** Minimal fields - just the essentials (e.g., id, name) */
162
+ readonly MINIMAL: "minimal";
163
+ /** Summary fields - brief overview */
164
+ readonly SUMMARY: "summary";
165
+ /** Public fields - safe to expose publicly */
166
+ readonly PUBLIC: "public";
167
+ /** Private fields - internal use only */
168
+ readonly PRIVATE: "private";
169
+ /** Detailed fields - comprehensive info */
170
+ readonly DETAILED: "detailed";
171
+ /** Full fields - everything */
172
+ readonly FULL: "full";
173
+ /** List view fields - for table/list displays */
174
+ readonly LIST: "list";
175
+ /** Detail view fields - for detail pages */
176
+ readonly DETAIL: "detail";
177
+ /** Admin fields - administrative data */
178
+ readonly ADMIN: "admin";
179
+ /** API response fields */
180
+ readonly API: "api";
181
+ }>;
182
+ /** Type representing all built-in group names */
183
+ export type BuiltInGroup = (typeof Groups)[keyof typeof Groups];
184
+ /**
185
+ * Ignores a property during mapping.
186
+ *
187
+ * @example
188
+ * class UserDto {
189
+ * @Ignore()
190
+ * internalId: string; // Will not be mapped
191
+ * }
192
+ */
193
+ export declare function Ignore(): PropertyDecorator;
194
+ /**
195
+ * Specifies the type for nested object mapping.
196
+ *
197
+ * @example
198
+ * class UserDto {
199
+ * @NestedType(() => AddressDto)
200
+ * @MapFrom('address')
201
+ * address: AddressDto;
202
+ * }
203
+ */
204
+ export declare function NestedType<T>(typeFactory: () => Constructor<T>): PropertyDecorator;
205
+ export {};
206
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAEL,YAAY,EACZ,WAAW,EAEX,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAG,GAAG,EACnC,qBAAqB,EAAE,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,GACzD,iBAAiB,CA2BnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAC5C,QAAQ,EAAE,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,GAC7C,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAiBvC;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,EAAE,OAAO,IAAI;KAChD,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC5E,CAAC;AAgBF;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,CAAC,CA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D;AACjD,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAEhE;;;;;;;;GAQG;AACH,wBAAgB,MAAM,IAAI,iBAAiB,CAqB1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,WAAW,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,GAChC,iBAAiB,CASnB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * typemold
3
+ * A lightweight, high-performance object mapper for TypeScript and Node.js
4
+ *
5
+ * @author Chetan Joshi
6
+ * @license MIT
7
+ *
8
+ * @example
9
+ * // Basic mapping
10
+ * import { Mapper, MapFrom, AutoMap } from 'typemold';
11
+ *
12
+ * class UserDto {
13
+ * @AutoMap()
14
+ * username: string;
15
+ *
16
+ * @MapFrom('profile.avatar')
17
+ * avatar: string;
18
+ *
19
+ * @MapFrom((src) => src.age >= 18)
20
+ * isAdult: boolean;
21
+ * }
22
+ *
23
+ * const userDto = Mapper.map(userEntity, UserDto);
24
+ *
25
+ * @example
26
+ * // Runtime field projection
27
+ * const minimal = Mapper.map(user, UserDto, { pick: ['username', 'avatar'] });
28
+ * const safe = Mapper.map(user, UserDto, { omit: ['email', 'password'] });
29
+ * const public = Mapper.map(user, UserDto, { group: 'public' });
30
+ *
31
+ * @example
32
+ * // NestJS integration (optional)
33
+ * import { MapperModule, MapperService } from 'typemold';
34
+ *
35
+ * @Module({
36
+ * imports: [MapperModule.forRoot()],
37
+ * })
38
+ * export class AppModule {}
39
+ */
40
+ export { Mapper } from "./mapper";
41
+ export { MapFrom, createMapping, TypedMappingConfig, PathsOf, AutoMap, FieldGroup, createFieldGroups, GroupsOf, Groups, BuiltInGroup, Ignore, NestedType, } from "./decorators";
42
+ export { Constructor, TransformFn, PropertyPath, MapOptions, MappingContext, TypeConverter, PropertyMappingConfig, CompiledMapper, METADATA_KEYS, } from "./types";
43
+ export { MappingRegistry, MapperFactory } from "./registry";
44
+ export { getNestedValue, pickKeys, omitKeys, isPlainObject, isClassInstance, } from "./utils";
45
+ export { MapperModule, MapperModuleOptions, MapperModuleAsyncOptions, MapperService, MapperServiceOptions, MAPPER_OPTIONS, } from "./nestjs";
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EACL,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,OAAO,EACP,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,MAAM,EACN,UAAU,GACX,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,EACL,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,oBAAoB,EACpB,cAAc,GACf,MAAM,UAAU,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @sevirial/nest-mapper - Core Mapper
3
+ * Main mapper class with static methods for easy usage
4
+ */
5
+ import "reflect-metadata";
6
+ import { Constructor, MapOptions, MappingContext, CompiledMapper, TypeConverter } from "./types";
7
+ /**
8
+ * Main Mapper class - provides static methods for object mapping
9
+ *
10
+ * @example
11
+ * // Basic usage
12
+ * const userDto = Mapper.map(userEntity, UserDto);
13
+ *
14
+ * @example
15
+ * // With field projection
16
+ * const minimalUser = Mapper.map(userEntity, UserDto, { pick: ['username', 'avatar'] });
17
+ *
18
+ * @example
19
+ * // With field groups
20
+ * const publicUser = Mapper.map(userEntity, UserDto, { group: 'public' });
21
+ *
22
+ * @example
23
+ * // Array mapping
24
+ * const userDtos = Mapper.mapArray(users, UserDto);
25
+ */
26
+ export declare class Mapper {
27
+ private static typeConverters;
28
+ private static globalContext;
29
+ /**
30
+ * Maps a source object to a target DTO class
31
+ *
32
+ * @param source - Source object to map from
33
+ * @param targetType - Target DTO class constructor
34
+ * @param options - Optional mapping options for field projection
35
+ * @returns Mapped target object
36
+ */
37
+ static map<TSource, TTarget>(source: TSource, targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): TTarget;
38
+ /**
39
+ * Maps an array of source objects to target DTOs
40
+ *
41
+ * @param sources - Array of source objects
42
+ * @param targetType - Target DTO class constructor
43
+ * @param options - Optional mapping options for field projection
44
+ * @returns Array of mapped target objects
45
+ */
46
+ static mapArray<TSource, TTarget>(sources: TSource[], targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): TTarget[];
47
+ /**
48
+ * Maps source to target and returns only specified fields (shorthand)
49
+ *
50
+ * @example
51
+ * const result = Mapper.pick(user, UserDto, ['username', 'avatar']);
52
+ */
53
+ static pick<TSource, TTarget, K extends keyof TTarget>(source: TSource, targetType: Constructor<TTarget>, fields: K[]): Pick<TTarget, K>;
54
+ /**
55
+ * Maps source to target excluding specified fields (shorthand)
56
+ *
57
+ * @example
58
+ * const result = Mapper.omit(user, UserDto, ['password', 'email']);
59
+ */
60
+ static omit<TSource, TTarget, K extends keyof TTarget>(source: TSource, targetType: Constructor<TTarget>, fields: K[]): Omit<TTarget, K>;
61
+ /**
62
+ * Maps source using a predefined field group (shorthand)
63
+ *
64
+ * @example
65
+ * const result = Mapper.group(user, UserDto, 'minimal');
66
+ */
67
+ static group<TSource, TTarget>(source: TSource, targetType: Constructor<TTarget>, groupName: string): Partial<TTarget>;
68
+ /**
69
+ * Creates a reusable mapper function for better performance in loops
70
+ *
71
+ * @example
72
+ * const mapToUserDto = Mapper.createMapper(UserDto);
73
+ * const users = entities.map(mapToUserDto);
74
+ */
75
+ static createMapper<TSource, TTarget>(targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): (source: TSource) => TTarget;
76
+ /**
77
+ * Registers a type converter for automatic type transformations
78
+ */
79
+ static registerConverter<TSource, TTarget>(converter: TypeConverter<TSource, TTarget>): void;
80
+ /**
81
+ * Sets global context that will be available to all transform functions
82
+ */
83
+ static setGlobalContext(context: Partial<MappingContext>): void;
84
+ /**
85
+ * Clears all cached mappers (useful for testing or hot-reload scenarios)
86
+ */
87
+ static clearCache(): void;
88
+ /**
89
+ * Gets the compiled mapper for inspection (useful for debugging)
90
+ */
91
+ static getCompiledMapper<TSource, TTarget>(targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): CompiledMapper<TSource, TTarget> | undefined;
92
+ }
93
+ //# sourceMappingURL=mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../src/mapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EACL,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc,EACd,aAAa,EAEd,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAC,cAAc,CAAuB;IACpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAsB;IAElD;;;;;;;OAOG;IACH,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EACzB,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,OAAO;IAmBV;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAA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;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IAIzB;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,EACvC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS;CAOhD"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @sevirial/nest-mapper - NestJS Integration
3
+ * Re-exports for NestJS-specific functionality
4
+ */
5
+ export { MapperModule, MapperModuleOptions, MapperModuleAsyncOptions, } from "./mapper.module";
6
+ export { MapperService, MapperServiceOptions, MAPPER_OPTIONS, } from "./mapper.service";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nestjs/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,cAAc,GACf,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @sevirial/nest-mapper - NestJS MapperModule
3
+ * Dynamic module for NestJS integration
4
+ */
5
+ import { DynamicModule, Type, InjectionToken, OptionalFactoryDependency } from "@nestjs/common";
6
+ import { MapperServiceOptions } from "./mapper.service";
7
+ /**
8
+ * Module options for MapperModule.forRoot()
9
+ */
10
+ export interface MapperModuleOptions extends MapperServiceOptions {
11
+ /**
12
+ * Make module global (available everywhere without importing)
13
+ * @default true
14
+ */
15
+ isGlobal?: boolean;
16
+ }
17
+ /**
18
+ * Async module options for MapperModule.forRootAsync()
19
+ */
20
+ export interface MapperModuleAsyncOptions {
21
+ /**
22
+ * Make module global
23
+ */
24
+ isGlobal?: boolean;
25
+ /**
26
+ * Modules to import for dependency injection
27
+ */
28
+ imports?: Array<Type<unknown> | DynamicModule>;
29
+ /**
30
+ * Factory function to create options
31
+ */
32
+ useFactory: (...args: unknown[]) => Promise<MapperServiceOptions> | MapperServiceOptions;
33
+ /**
34
+ * Dependencies to inject into factory
35
+ */
36
+ inject?: Array<InjectionToken | OptionalFactoryDependency>;
37
+ }
38
+ /**
39
+ * NestJS Module for @sevirial/nest-mapper
40
+ *
41
+ * @example
42
+ * // Basic usage (global by default)
43
+ * @Module({
44
+ * imports: [MapperModule.forRoot()],
45
+ * })
46
+ * export class AppModule {}
47
+ *
48
+ * @example
49
+ * // With options
50
+ * @Module({
51
+ * imports: [
52
+ * MapperModule.forRoot({
53
+ * enableValidation: true,
54
+ * converters: [myDateConverter],
55
+ * }),
56
+ * ],
57
+ * })
58
+ * export class AppModule {}
59
+ *
60
+ * @example
61
+ * // Async configuration
62
+ * @Module({
63
+ * imports: [
64
+ * MapperModule.forRootAsync({
65
+ * imports: [ConfigModule],
66
+ * useFactory: (config: ConfigService) => ({
67
+ * enableValidation: config.get('ENABLE_VALIDATION'),
68
+ * }),
69
+ * inject: [ConfigService],
70
+ * }),
71
+ * ],
72
+ * })
73
+ * export class AppModule {}
74
+ */
75
+ export declare class MapperModule {
76
+ /**
77
+ * Configure the mapper module with static options
78
+ */
79
+ static forRoot(options?: MapperModuleOptions): DynamicModule;
80
+ /**
81
+ * Configure the mapper module with async options (factory pattern)
82
+ */
83
+ static forRootAsync(options: MapperModuleAsyncOptions): DynamicModule;
84
+ /**
85
+ * For feature modules that need the mapper (when not using isGlobal)
86
+ */
87
+ static forFeature(): DynamicModule;
88
+ }
89
+ //# sourceMappingURL=mapper.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.module.d.ts","sourceRoot":"","sources":["../../../src/nestjs/mapper.module.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,aAAa,EAGb,IAAI,EACJ,cAAc,EACd,yBAAyB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,oBAAoB,EAErB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,CAAC;IAE/C;;OAEG;IACH,UAAU,EAAE,CACV,GAAG,IAAI,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAC;IAE1D;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,yBAAyB,CAAC,CAAC;CAC5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBACa,YAAY;IACvB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,aAAa;IAgB5D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IAkBrE;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,aAAa;CAOnC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @sevirial/nest-mapper - NestJS MapperService
3
+ * Injectable service for NestJS dependency injection
4
+ */
5
+ import { Constructor, MapOptions, TypeConverter } from "../types";
6
+ /**
7
+ * Injection token for MapperModule options
8
+ */
9
+ export declare const MAPPER_OPTIONS: unique symbol;
10
+ /**
11
+ * Options for MapperService
12
+ */
13
+ export interface MapperServiceOptions {
14
+ /**
15
+ * Enable validation integration with class-validator
16
+ */
17
+ enableValidation?: boolean;
18
+ /**
19
+ * Custom type converters
20
+ */
21
+ converters?: TypeConverter[];
22
+ /**
23
+ * Global extras available to all transform functions
24
+ */
25
+ globalExtras?: Record<string, unknown>;
26
+ }
27
+ /**
28
+ * Injectable mapper service for NestJS
29
+ *
30
+ * @example
31
+ * @Injectable()
32
+ * export class UserService {
33
+ * constructor(private readonly mapper: MapperService) {}
34
+ *
35
+ * async getUser(id: string): Promise<UserDto> {
36
+ * const user = await this.userRepo.findOne(id);
37
+ * return this.mapper.map(user, UserDto);
38
+ * }
39
+ * }
40
+ */
41
+ export declare class MapperService {
42
+ private readonly options;
43
+ private validator;
44
+ constructor(options?: MapperServiceOptions);
45
+ /**
46
+ * Lazily loads class-validator for hybrid integration
47
+ */
48
+ private initializeValidator;
49
+ /**
50
+ * Maps a source object to a target DTO
51
+ */
52
+ map<TSource, TTarget>(source: TSource, targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): TTarget;
53
+ /**
54
+ * Maps an array of source objects to target DTOs
55
+ */
56
+ mapArray<TSource, TTarget>(sources: TSource[], targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): TTarget[];
57
+ /**
58
+ * Maps and validates the result using class-validator (if enabled)
59
+ *
60
+ * @throws ValidationError[] if validation fails
61
+ */
62
+ mapAndValidate<TSource, TTarget extends object>(source: TSource, targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): Promise<TTarget>;
63
+ /**
64
+ * Pick specific fields (shorthand)
65
+ */
66
+ pick<TSource, TTarget, K extends keyof TTarget>(source: TSource, targetType: Constructor<TTarget>, fields: K[]): Pick<TTarget, K>;
67
+ /**
68
+ * Omit specific fields (shorthand)
69
+ */
70
+ omit<TSource, TTarget, K extends keyof TTarget>(source: TSource, targetType: Constructor<TTarget>, fields: K[]): Omit<TTarget, K>;
71
+ /**
72
+ * Use a field group (shorthand)
73
+ */
74
+ group<TSource, TTarget>(source: TSource, targetType: Constructor<TTarget>, groupName: string): Partial<TTarget>;
75
+ /**
76
+ * Creates a reusable mapper function
77
+ */
78
+ createMapper<TSource, TTarget>(targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): (source: TSource) => TTarget;
79
+ }
80
+ //# sourceMappingURL=mapper.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.service.d.ts","sourceRoot":"","sources":["../../../src/nestjs/mapper.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;;;;;;;;;;;;GAaG;AACH,qBACa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,SAAS,CACV;gBAG+B,OAAO,CAAC,EAAE,oBAAoB;IAsBpE;;OAEG;YACW,mBAAmB;IAUjC;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,OAAO,EAClB,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,OAAO;IAIV;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,EACvB,OAAO,EAAE,OAAO,EAAE,EAClB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,OAAO,EAAE;IAIZ;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,OAAO,SAAS,MAAM,EAClD,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC;IAanB;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,SAAS,MAAM,OAAO,EAC5C,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,MAAM,EAAE,CAAC,EAAE,GACV,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAInB;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,SAAS,MAAM,OAAO,EAC5C,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,MAAM,EAAE,CAAC,EAAE,GACV,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAInB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAInB;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,EAC3B,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO;CAGhC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @sevirial/nest-mapper - Mapping Registry
3
+ * Singleton registry for storing and caching mapping configurations
4
+ */
5
+ import "reflect-metadata";
6
+ import { Constructor, MappingRegistryEntry, CompiledMapper, MapOptions } from "./types";
7
+ /**
8
+ * Global mapping registry - singleton pattern for performance
9
+ */
10
+ declare class MappingRegistryClass {
11
+ private readonly registry;
12
+ private readonly compiledMappers;
13
+ /**
14
+ * Gets or creates a registry entry for a target DTO class
15
+ */
16
+ getEntry<TTarget>(targetType: Constructor<TTarget>): MappingRegistryEntry<unknown, TTarget>;
17
+ /**
18
+ * Creates a mapping entry by reading decorator metadata
19
+ */
20
+ private createEntryFromMetadata;
21
+ /**
22
+ * Gets a compiled mapper for the given target type and options signature
23
+ */
24
+ getCompiledMapper<TSource, TTarget>(targetType: Constructor<TTarget>, optionsKey?: string): CompiledMapper<TSource, TTarget> | undefined;
25
+ /**
26
+ * Stores a compiled mapper for reuse
27
+ */
28
+ setCompiledMapper<TSource, TTarget>(targetType: Constructor<TTarget>, optionsKey: string, mapper: CompiledMapper<TSource, TTarget>): void;
29
+ /**
30
+ * Clears all cached mappers (useful for testing)
31
+ */
32
+ clearCache(): void;
33
+ /**
34
+ * Generates a cache key for mapping options
35
+ */
36
+ getOptionsKey<TTarget>(options?: MapOptions<TTarget>): string;
37
+ }
38
+ /**
39
+ * Singleton instance
40
+ */
41
+ export declare const MappingRegistry: MappingRegistryClass;
42
+ /**
43
+ * Mapper Factory - Creates optimized mapping functions
44
+ */
45
+ export declare class MapperFactory {
46
+ /**
47
+ * Creates a compiled mapper for the given target type with optional field projection
48
+ */
49
+ static createMapper<TSource, TTarget>(targetType: Constructor<TTarget>, options?: MapOptions<TTarget>): CompiledMapper<TSource, TTarget>;
50
+ /**
51
+ * Determines which properties to map based on options
52
+ */
53
+ private static getPropertiesToMap;
54
+ /**
55
+ * Builds an optimized mapping function
56
+ */
57
+ private static buildMapper;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EACL,WAAW,EACX,oBAAoB,EAEpB,cAAc,EAEd,UAAU,EAEX,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,cAAM,oBAAoB;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgD;IACzE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAG5B;IAEJ;;OAEG;IACH,QAAQ,CAAC,OAAO,EACd,UAAU,EAAE,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