@longzai-intelligence/shared-kernel-mapper 0.1.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 +73 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @longzai-intelligence/shared-kernel-mapper
|
|
2
|
+
|
|
3
|
+
Mapper 类型定义包,提供 ORM Mapper 和 Application Mapper 的统一接口类型。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @longzai-intelligence/shared-kernel-mapper
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
### ORM Mapper 接口
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import type { OrmMapper } from '@longzai-intelligence/shared-kernel-mapper';
|
|
17
|
+
|
|
18
|
+
type UserOrmMapper = OrmMapper<UserEntity, UserOrmEntity>;
|
|
19
|
+
|
|
20
|
+
// 实现示例
|
|
21
|
+
class UserOrmMapperImpl implements UserOrmMapper {
|
|
22
|
+
toDomain(orm: UserOrmEntity): UserEntity {
|
|
23
|
+
// 转换逻辑
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
toOrm(entity: UserEntity): UserOrmEntity {
|
|
27
|
+
// 转换逻辑
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Application Mapper 接口
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import type { ApplicationMapper } from '@longzai-intelligence/shared-kernel-mapper';
|
|
36
|
+
|
|
37
|
+
type UserMapper = ApplicationMapper<UserEntity, UserDTO>;
|
|
38
|
+
|
|
39
|
+
// 实现示例
|
|
40
|
+
class UserMapperImpl implements UserMapper {
|
|
41
|
+
toDTO(entity: UserEntity): UserDTO {
|
|
42
|
+
// 转换逻辑
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toDTOList(entities: UserEntity[]): UserDTO[] {
|
|
46
|
+
return entities.map((entity) => this.toDTO(entity));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### OrmMapper<TDomain, TOrm>
|
|
54
|
+
|
|
55
|
+
ORM Mapper 接口类型,定义领域实体与 ORM 实体之间的双向转换契约。
|
|
56
|
+
|
|
57
|
+
| 方法 | 签名 | 说明 |
|
|
58
|
+
|------|------|------|
|
|
59
|
+
| `toDomain` | `(orm: TOrm) => TDomain` | 将 ORM 实体转换为领域实体 |
|
|
60
|
+
| `toOrm` | `(entity: TDomain) => TOrm` | 将领域实体转换为 ORM 实体 |
|
|
61
|
+
|
|
62
|
+
### ApplicationMapper<TDomain, TDTO>
|
|
63
|
+
|
|
64
|
+
Application Mapper 接口类型,定义领域实体与 DTO 之间的转换契约。
|
|
65
|
+
|
|
66
|
+
| 方法 | 签名 | 说明 |
|
|
67
|
+
|------|------|------|
|
|
68
|
+
| `toDTO` | `(entity: TDomain) => TDTO` | 将领域实体转换为 DTO |
|
|
69
|
+
| `toDTOList` | `(entities: TDomain[]) => TDTO[]` | 批量将领域实体转换为 DTO |
|
|
70
|
+
|
|
71
|
+
## 相关文档
|
|
72
|
+
|
|
73
|
+
- [Domain Mapper 实现规范](../../../docs/standards/domain/domain-mapper-standard.md)
|
package/dist/index.cjs
ADDED
|
File without changes
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/mapper.types.d.ts
|
|
2
|
+
type OrmMapper<TDomain, TOrm> = {
|
|
3
|
+
toDomain(orm: TOrm): TDomain;
|
|
4
|
+
toOrm(entity: TDomain): TOrm;
|
|
5
|
+
};
|
|
6
|
+
type ApplicationMapper<TDomain, TDTO> = {
|
|
7
|
+
toDTO(entity: TDomain): TDTO;
|
|
8
|
+
toDTOList(entities: TDomain[]): TDTO[];
|
|
9
|
+
};
|
|
10
|
+
type DomainMapper<TDomain, TPersistence> = {
|
|
11
|
+
toDomain(data: TPersistence): TDomain;
|
|
12
|
+
toPersistence(entity: TDomain): TPersistence;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type ApplicationMapper, type DomainMapper, type OrmMapper };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/mapper.types.d.ts
|
|
2
|
+
type OrmMapper<TDomain, TOrm> = {
|
|
3
|
+
toDomain(orm: TOrm): TDomain;
|
|
4
|
+
toOrm(entity: TDomain): TOrm;
|
|
5
|
+
};
|
|
6
|
+
type ApplicationMapper<TDomain, TDTO> = {
|
|
7
|
+
toDTO(entity: TDomain): TDTO;
|
|
8
|
+
toDTOList(entities: TDomain[]): TDTO[];
|
|
9
|
+
};
|
|
10
|
+
type DomainMapper<TDomain, TPersistence> = {
|
|
11
|
+
toDomain(data: TPersistence): TDomain;
|
|
12
|
+
toPersistence(entity: TDomain): TPersistence;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type ApplicationMapper, type DomainMapper, type OrmMapper };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence/shared-kernel-mapper",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": {
|
|
10
|
+
"import": "./dist/index.d.mts",
|
|
11
|
+
"require": "./dist/index.d.cts"
|
|
12
|
+
},
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"build:prod": "NODE_ENV=production tsdown",
|
|
23
|
+
"prepublishOnly": "bun run build:prod",
|
|
24
|
+
"dev": "tsdown --watch",
|
|
25
|
+
"clean": "rimraf dist tsconfig/.cache",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"lint:fix": "eslint . --fix",
|
|
31
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
32
|
+
"typecheck:app": "tsc --noEmit -p tsconfig/app.json",
|
|
33
|
+
"typecheck:node": "tsc --noEmit -p tsconfig/node.json",
|
|
34
|
+
"typecheck:test": "tsc --noEmit -p tsconfig/test.json",
|
|
35
|
+
"upgrade-deps": "ncu -u"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/bun": "1.3.12",
|
|
39
|
+
"@types/node": "^25.6.0",
|
|
40
|
+
"eslint": "^10.2.1",
|
|
41
|
+
"rimraf": "^6.1.3",
|
|
42
|
+
"typescript": "^6.0.3",
|
|
43
|
+
"vitest": "^4.1.4",
|
|
44
|
+
"@longzai-intelligence/eslint-preset-library": "0.2.5",
|
|
45
|
+
"@longzai-intelligence/vitest-config": "0.0.9",
|
|
46
|
+
"@longzai-intelligence/typescript-config": "0.0.3",
|
|
47
|
+
"tsdown": "^0.21.9",
|
|
48
|
+
"@longzai-intelligence/tsdown-config": "0.0.1"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"shared-kernel",
|
|
52
|
+
"mapper"
|
|
53
|
+
],
|
|
54
|
+
"license": "UNLICENSED",
|
|
55
|
+
"module": "./dist/index.mjs"
|
|
56
|
+
}
|