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.
- package/LICENSE +43 -0
- package/README.md +235 -0
- package/dist/cjs/decorators.js +284 -0
- package/dist/cjs/index.js +74 -0
- package/dist/cjs/mapper.js +153 -0
- package/dist/cjs/nestjs/index.js +12 -0
- package/dist/cjs/nestjs/mapper.module.js +103 -0
- package/dist/cjs/nestjs/mapper.service.js +161 -0
- package/dist/cjs/registry.js +179 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/utils.js +136 -0
- package/dist/esm/decorators.js +274 -0
- package/dist/esm/index.js +51 -0
- package/dist/esm/mapper.js +149 -0
- package/dist/esm/nestjs/index.js +6 -0
- package/dist/esm/nestjs/mapper.module.js +100 -0
- package/dist/esm/nestjs/mapper.service.js +125 -0
- package/dist/esm/registry.js +175 -0
- package/dist/esm/types.js +14 -0
- package/dist/esm/utils.js +127 -0
- package/dist/types/decorators.d.ts +206 -0
- package/dist/types/decorators.d.ts.map +1 -0
- package/dist/types/index.d.ts +46 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/mapper.d.ts +93 -0
- package/dist/types/mapper.d.ts.map +1 -0
- package/dist/types/nestjs/index.d.ts +7 -0
- package/dist/types/nestjs/index.d.ts.map +1 -0
- package/dist/types/nestjs/mapper.module.d.ts +89 -0
- package/dist/types/nestjs/mapper.module.d.ts.map +1 -0
- package/dist/types/nestjs/mapper.service.d.ts +80 -0
- package/dist/types/nestjs/mapper.service.d.ts.map +1 -0
- package/dist/types/registry.d.ts +60 -0
- package/dist/types/registry.d.ts.map +1 -0
- package/dist/types/types.d.ts +120 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +30 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sevirial/nest-mapper - Type Definitions
|
|
3
|
+
* Core types for the high-performance object mapper
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Constructor type for class instantiation
|
|
7
|
+
*/
|
|
8
|
+
export type Constructor<T = any> = new (...args: any[]) => T;
|
|
9
|
+
/**
|
|
10
|
+
* Transform function that converts source value to target value
|
|
11
|
+
*/
|
|
12
|
+
export type TransformFn<TSource = any, TResult = any> = (source: TSource, context?: MappingContext) => TResult;
|
|
13
|
+
/**
|
|
14
|
+
* Property path as string (supports nested paths like 'profile.avatar')
|
|
15
|
+
*/
|
|
16
|
+
export type PropertyPath = string;
|
|
17
|
+
/**
|
|
18
|
+
* Mapping configuration for a single property
|
|
19
|
+
*/
|
|
20
|
+
export interface PropertyMappingConfig {
|
|
21
|
+
/** Target property name on the DTO */
|
|
22
|
+
targetKey: string;
|
|
23
|
+
/** Source property path or transform function */
|
|
24
|
+
source: PropertyPath | TransformFn;
|
|
25
|
+
/** Whether this is a transform function */
|
|
26
|
+
isTransform: boolean;
|
|
27
|
+
/** Field groups this property belongs to */
|
|
28
|
+
groups: string[];
|
|
29
|
+
/** Whether to ignore this property */
|
|
30
|
+
ignore: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compiled mapping function for optimal performance
|
|
34
|
+
*/
|
|
35
|
+
export type CompiledMapper<TSource = any, TTarget = any> = (source: TSource, context?: MappingContext) => TTarget;
|
|
36
|
+
/**
|
|
37
|
+
* Context passed during mapping operations
|
|
38
|
+
*/
|
|
39
|
+
export interface MappingContext {
|
|
40
|
+
/** Extra data available to transform functions */
|
|
41
|
+
extras?: Record<string, unknown>;
|
|
42
|
+
/** Current depth for circular reference detection */
|
|
43
|
+
depth?: number;
|
|
44
|
+
/** Already mapped objects for circular reference handling */
|
|
45
|
+
visited?: WeakMap<object, unknown>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for mapping operations with runtime field projection
|
|
49
|
+
*/
|
|
50
|
+
export interface MapOptions<TTarget = any> {
|
|
51
|
+
/**
|
|
52
|
+
* Pick only specific fields from the target DTO
|
|
53
|
+
* @example { pick: ['username', 'avatar'] }
|
|
54
|
+
*/
|
|
55
|
+
pick?: (keyof TTarget)[];
|
|
56
|
+
/**
|
|
57
|
+
* Omit specific fields from the target DTO
|
|
58
|
+
* @example { omit: ['password', 'email'] }
|
|
59
|
+
*/
|
|
60
|
+
omit?: (keyof TTarget)[];
|
|
61
|
+
/**
|
|
62
|
+
* Use a predefined field group
|
|
63
|
+
* @example { group: 'minimal' }
|
|
64
|
+
*/
|
|
65
|
+
group?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Extra context data available to transform functions
|
|
68
|
+
*/
|
|
69
|
+
extras?: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Configuration for the MapperModule
|
|
73
|
+
*/
|
|
74
|
+
export interface MapperModuleOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Enable validation integration with class-validator
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
enableValidation?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Global options applied to all mappings
|
|
82
|
+
*/
|
|
83
|
+
globalOptions?: Partial<MapOptions>;
|
|
84
|
+
/**
|
|
85
|
+
* Custom type converters
|
|
86
|
+
*/
|
|
87
|
+
converters?: TypeConverter[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Type converter for automatic type transformations
|
|
91
|
+
*/
|
|
92
|
+
export interface TypeConverter<TSource = any, TTarget = any> {
|
|
93
|
+
/** Source type to convert from */
|
|
94
|
+
sourceType: Constructor<TSource> | string;
|
|
95
|
+
/** Target type to convert to */
|
|
96
|
+
targetType: Constructor<TTarget> | string;
|
|
97
|
+
/** Conversion function */
|
|
98
|
+
convert: (value: TSource) => TTarget;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Metadata key constants
|
|
102
|
+
*/
|
|
103
|
+
export declare const METADATA_KEYS: {
|
|
104
|
+
readonly PROPERTY_MAPPINGS: symbol;
|
|
105
|
+
readonly FIELD_GROUPS: symbol;
|
|
106
|
+
readonly AUTO_MAP: symbol;
|
|
107
|
+
readonly IGNORE: symbol;
|
|
108
|
+
readonly NESTED_TYPE: symbol;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Internal mapping registry entry
|
|
112
|
+
*/
|
|
113
|
+
export interface MappingRegistryEntry<TSource = any, TTarget = any> {
|
|
114
|
+
sourceType?: Constructor<TSource>;
|
|
115
|
+
targetType: Constructor<TTarget>;
|
|
116
|
+
compiledMapper?: CompiledMapper<TSource, TTarget>;
|
|
117
|
+
propertyConfigs: Map<string, PropertyMappingConfig>;
|
|
118
|
+
fieldGroups: Map<string, Set<string>>;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,CACtD,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,cAAc,KACrB,OAAO,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,MAAM,EAAE,YAAY,GAAG,WAAW,CAAC;IACnC,2CAA2C;IAC3C,WAAW,EAAE,OAAO,CAAC;IACrB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,sCAAsC;IACtC,MAAM,EAAE,OAAO,CAAC;CACjB;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OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACtC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;CAMhB,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG;IAChE,UAAU,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IACpD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CACvC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sevirial/nest-mapper - Utility Functions
|
|
3
|
+
* Helper functions for the mapping engine
|
|
4
|
+
*/
|
|
5
|
+
export declare function getNestedValue<T = unknown>(obj: Record<string, unknown> | null | undefined, path: string): T | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a value is a plain object (not an array, Date, etc.)
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a value is a class instance (not a plain object)
|
|
12
|
+
*/
|
|
13
|
+
export declare function isClassInstance(value: unknown): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a shallow clone of an object with only specified keys
|
|
16
|
+
*/
|
|
17
|
+
export declare function pickKeys<T extends Record<string, unknown>>(obj: T, keys: (keyof T)[]): Partial<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a shallow clone of an object without specified keys
|
|
20
|
+
*/
|
|
21
|
+
export declare function omitKeys<T extends Record<string, unknown>>(obj: T, keys: (keyof T)[]): Partial<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets all property keys including inherited ones
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAllPropertyKeys(target: object): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Deep clones an object (for handling circular references)
|
|
28
|
+
*/
|
|
29
|
+
export declare function deepClone<T>(obj: T, visited?: WeakMap<object, unknown>): T;
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EAC/C,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,SAAS,CAyBf;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIvD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxD,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAChB,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxD,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAChB,OAAO,CAAC,CAAC,CAAC,CASZ;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAc3D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,GAAG,EAAE,CAAC,EACN,OAAO,2BAAiC,GACvC,CAAC,CA6BH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "typemold",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight, high-performance object mapper for TypeScript and Node.js with runtime field projection",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Chetan Joshi",
|
|
7
|
+
"email": "chetanjoshi707@gmail.com",
|
|
8
|
+
"url": "https://github.com/ErrorX407"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/cjs/index.js",
|
|
12
|
+
"module": "dist/esm/index.js",
|
|
13
|
+
"types": "dist/types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"require": "./dist/cjs/index.js",
|
|
17
|
+
"import": "./dist/esm/index.js",
|
|
18
|
+
"types": "./dist/types/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
27
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
28
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
29
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
30
|
+
"test": "jest",
|
|
31
|
+
"test:watch": "jest --watch",
|
|
32
|
+
"test:coverage": "jest --coverage",
|
|
33
|
+
"benchmark": "ts-node benchmarks/index.ts",
|
|
34
|
+
"lint": "eslint src --ext .ts",
|
|
35
|
+
"prepublishOnly": "npm run build && npm test"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"mapper",
|
|
39
|
+
"object-mapper",
|
|
40
|
+
"dto",
|
|
41
|
+
"typescript",
|
|
42
|
+
"nestjs",
|
|
43
|
+
"nodejs",
|
|
44
|
+
"transform",
|
|
45
|
+
"serialization",
|
|
46
|
+
"automapper",
|
|
47
|
+
"type-safe"
|
|
48
|
+
],
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/ErrorX407/typemold.git"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/ErrorX407/typemold/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/ErrorX407/typemold#readme",
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
59
|
+
"@nestjs/common": ">=9.0.0",
|
|
60
|
+
"@nestjs/core": ">=9.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"@nestjs/common": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"@nestjs/core": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"optionalDependencies": {
|
|
71
|
+
"class-validator": ">=0.14.0"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@nestjs/common": "^10.0.0",
|
|
75
|
+
"@nestjs/core": "^10.0.0",
|
|
76
|
+
"@nestjs/testing": "^10.0.0",
|
|
77
|
+
"@types/jest": "^29.5.0",
|
|
78
|
+
"@types/node": "^20.0.0",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
80
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
81
|
+
"class-validator": "^0.14.0",
|
|
82
|
+
"eslint": "^8.0.0",
|
|
83
|
+
"jest": "^29.5.0",
|
|
84
|
+
"reflect-metadata": "^0.2.0",
|
|
85
|
+
"ts-jest": "^29.1.0",
|
|
86
|
+
"ts-node": "^10.9.0",
|
|
87
|
+
"typescript": "^5.0.0"
|
|
88
|
+
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": ">=16.0.0"
|
|
91
|
+
}
|
|
92
|
+
}
|