@expeed/ngx-data-mapper 1.3.2 → 1.3.4
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 +284 -0
- package/fesm2022/expeed-ngx-data-mapper.mjs +180 -1622
- package/fesm2022/expeed-ngx-data-mapper.mjs.map +1 -1
- package/package.json +2 -3
- package/types/expeed-ngx-data-mapper.d.ts +40 -619
package/README.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# @expeed/ngx-data-mapper
|
|
2
|
+
|
|
3
|
+
A visual drag-and-drop data mapping component for Angular applications. Create field mappings between source and target JSON schemas with transformations, array mapping, and default values.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Drag & Drop Mapping**: Visually connect source fields to target fields
|
|
8
|
+
- **Multi-Source Mapping**: Combine multiple source fields into one target (concatenation)
|
|
9
|
+
- **Transformations**: Apply data transformations (uppercase, lowercase, trim, date formatting, number formatting, substring, replace, mask, templating)
|
|
10
|
+
- **Array Mapping**: Map array fields with optional filtering
|
|
11
|
+
- **Array-to-Object**: Select single item from array using first, last, or conditional logic
|
|
12
|
+
- **Default Values**: Set defaults for unmapped target fields
|
|
13
|
+
- **Endpoint Dragging**: Reassign mappings by dragging connection endpoints
|
|
14
|
+
- **Real-time Preview**: View transformations with sample data
|
|
15
|
+
- **Import/Export**: Save and load mappings as JSON
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @expeed/ngx-data-mapper
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Peer Dependencies
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @angular/cdk @angular/material
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Basic Usage
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Component } from '@angular/core';
|
|
35
|
+
import { DataMapperComponent, JsonSchema, FieldMapping } from '@expeed/ngx-data-mapper';
|
|
36
|
+
|
|
37
|
+
@Component({
|
|
38
|
+
selector: 'app-mapper',
|
|
39
|
+
standalone: true,
|
|
40
|
+
imports: [DataMapperComponent],
|
|
41
|
+
template: `
|
|
42
|
+
<data-mapper
|
|
43
|
+
[sourceSchema]="sourceSchema"
|
|
44
|
+
[targetSchema]="targetSchema"
|
|
45
|
+
[sampleData]="sampleData"
|
|
46
|
+
(mappingsChange)="onMappingsChange($event)"
|
|
47
|
+
/>
|
|
48
|
+
`
|
|
49
|
+
})
|
|
50
|
+
export class MapperComponent {
|
|
51
|
+
sourceSchema: JsonSchema = {
|
|
52
|
+
type: 'object',
|
|
53
|
+
title: 'Source',
|
|
54
|
+
properties: {
|
|
55
|
+
firstName: { type: 'string', title: 'First Name' },
|
|
56
|
+
lastName: { type: 'string', title: 'Last Name' },
|
|
57
|
+
birthDate: { type: 'string', format: 'date', title: 'Birth Date' }
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
targetSchema: JsonSchema = {
|
|
62
|
+
type: 'object',
|
|
63
|
+
title: 'Target',
|
|
64
|
+
properties: {
|
|
65
|
+
fullName: { type: 'string', title: 'Full Name' },
|
|
66
|
+
age: { type: 'integer', title: 'Age' }
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
sampleData = {
|
|
71
|
+
firstName: 'John',
|
|
72
|
+
lastName: 'Doe',
|
|
73
|
+
birthDate: '1990-05-15'
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
onMappingsChange(mappings: FieldMapping[]): void {
|
|
77
|
+
console.log('Mappings:', mappings);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### With Schema Document (Multiple Definitions)
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { SchemaDocument } from '@expeed/ngx-data-mapper';
|
|
86
|
+
|
|
87
|
+
sourceSchema: SchemaDocument = {
|
|
88
|
+
$defs: {
|
|
89
|
+
Customer: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {
|
|
92
|
+
name: { type: 'string' },
|
|
93
|
+
email: { type: 'string' }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Reference specific definition
|
|
100
|
+
sourceSchemaRef = '#/$defs/Customer';
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<data-mapper
|
|
105
|
+
[sourceSchema]="sourceSchema"
|
|
106
|
+
[targetSchema]="targetSchema"
|
|
107
|
+
[sourceSchemaRef]="sourceSchemaRef"
|
|
108
|
+
[targetSchemaRef]="targetSchemaRef"
|
|
109
|
+
(mappingsChange)="onMappingsChange($event)"
|
|
110
|
+
/>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Import/Export Mappings
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { ViewChild } from '@angular/core';
|
|
117
|
+
import { DataMapperComponent } from '@expeed/ngx-data-mapper';
|
|
118
|
+
|
|
119
|
+
@ViewChild(DataMapperComponent) mapper!: DataMapperComponent;
|
|
120
|
+
|
|
121
|
+
exportMappings(): void {
|
|
122
|
+
const json = this.mapper.exportMappings();
|
|
123
|
+
// Save to file or API
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
importMappings(json: string): void {
|
|
127
|
+
this.mapper.importMappings(json);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
clearMappings(): void {
|
|
131
|
+
this.mapper.clearAllMappings();
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## API Reference
|
|
136
|
+
|
|
137
|
+
### DataMapperComponent
|
|
138
|
+
|
|
139
|
+
#### Inputs
|
|
140
|
+
|
|
141
|
+
| Input | Type | Default | Description |
|
|
142
|
+
|-------|------|---------|-------------|
|
|
143
|
+
| `sourceSchema` | `JsonSchema \| SchemaDocument` | - | Source schema definition |
|
|
144
|
+
| `targetSchema` | `JsonSchema \| SchemaDocument` | - | Target schema definition |
|
|
145
|
+
| `sourceSchemaRef` | `string` | - | JSON pointer to source definition (e.g., `#/$defs/Source`) |
|
|
146
|
+
| `targetSchemaRef` | `string` | - | JSON pointer to target definition (e.g., `#/$defs/Target`) |
|
|
147
|
+
| `sampleData` | `Record<string, unknown>` | `{}` | Sample data for transformation preview |
|
|
148
|
+
|
|
149
|
+
#### Outputs
|
|
150
|
+
|
|
151
|
+
| Output | Type | Description |
|
|
152
|
+
|--------|------|-------------|
|
|
153
|
+
| `mappingsChange` | `EventEmitter<FieldMapping[]>` | Emits when mappings change |
|
|
154
|
+
|
|
155
|
+
#### Public Methods
|
|
156
|
+
|
|
157
|
+
| Method | Returns | Description |
|
|
158
|
+
|--------|---------|-------------|
|
|
159
|
+
| `exportMappings()` | `string` | Export all mappings as JSON |
|
|
160
|
+
| `importMappings(json: string)` | `void` | Import mappings from JSON |
|
|
161
|
+
| `clearAllMappings()` | `void` | Remove all mappings |
|
|
162
|
+
|
|
163
|
+
## Transformations
|
|
164
|
+
|
|
165
|
+
Available transformation types:
|
|
166
|
+
|
|
167
|
+
| Type | Description | Example |
|
|
168
|
+
|------|-------------|---------|
|
|
169
|
+
| `uppercase` | Convert to uppercase | "hello" → "HELLO" |
|
|
170
|
+
| `lowercase` | Convert to lowercase | "HELLO" → "hello" |
|
|
171
|
+
| `trim` | Remove whitespace | " hello " → "hello" |
|
|
172
|
+
| `concat` | Concatenate multiple fields | "John" + "Doe" → "John Doe" |
|
|
173
|
+
| `substring` | Extract part of string | "hello"[0:3] → "hel" |
|
|
174
|
+
| `replace` | Replace text | "hello" → "hi" |
|
|
175
|
+
| `mask` | Mask characters | "1234567890" → "******7890" |
|
|
176
|
+
| `dateFormat` | Format date | "2024-01-15" → "Jan 15, 2024" |
|
|
177
|
+
| `numberFormat` | Format number | 1234.5 → "1,234.50" |
|
|
178
|
+
| `template` | Template string | "${firstName} ${lastName}" |
|
|
179
|
+
| `datePart` | Extract date part | Extract year, month, day |
|
|
180
|
+
|
|
181
|
+
## Array Mapping
|
|
182
|
+
|
|
183
|
+
### Array to Array
|
|
184
|
+
|
|
185
|
+
Map arrays with optional filtering:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// Filter array items
|
|
189
|
+
{
|
|
190
|
+
type: 'array-mapping',
|
|
191
|
+
filter: {
|
|
192
|
+
conditions: [
|
|
193
|
+
{ field: 'status', operator: 'equals', value: 'active' }
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Array to Object
|
|
200
|
+
|
|
201
|
+
Select single item from array:
|
|
202
|
+
|
|
203
|
+
| Mode | Description |
|
|
204
|
+
|------|-------------|
|
|
205
|
+
| `first` | Select first item |
|
|
206
|
+
| `last` | Select last item |
|
|
207
|
+
| `condition` | Select item matching condition |
|
|
208
|
+
|
|
209
|
+
## Default Values
|
|
210
|
+
|
|
211
|
+
Set default values for unmapped target fields:
|
|
212
|
+
|
|
213
|
+
| Type | Description |
|
|
214
|
+
|------|-------------|
|
|
215
|
+
| `static` | Fixed value |
|
|
216
|
+
| `null` | Null value |
|
|
217
|
+
| `empty-string` | Empty string |
|
|
218
|
+
| `empty-array` | Empty array [] |
|
|
219
|
+
| `empty-object` | Empty object {} |
|
|
220
|
+
| `current-date` | Current date |
|
|
221
|
+
| `current-datetime` | Current date and time |
|
|
222
|
+
| `uuid` | Generated UUID |
|
|
223
|
+
|
|
224
|
+
## Styling
|
|
225
|
+
|
|
226
|
+
Customize appearance with CSS custom properties:
|
|
227
|
+
|
|
228
|
+
```css
|
|
229
|
+
data-mapper {
|
|
230
|
+
--data-mapper-bg: #f8fafc;
|
|
231
|
+
--data-mapper-panel-bg: #ffffff;
|
|
232
|
+
--data-mapper-text-primary: #1e293b;
|
|
233
|
+
--data-mapper-text-secondary: #64748b;
|
|
234
|
+
--data-mapper-accent-primary: #6366f1;
|
|
235
|
+
--data-mapper-connector-color: #6366f1;
|
|
236
|
+
--data-mapper-border-color: #e2e8f0;
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Dark Theme
|
|
241
|
+
|
|
242
|
+
```css
|
|
243
|
+
data-mapper {
|
|
244
|
+
--data-mapper-bg: #1e293b;
|
|
245
|
+
--data-mapper-panel-bg: #334155;
|
|
246
|
+
--data-mapper-text-primary: #f1f5f9;
|
|
247
|
+
--data-mapper-text-secondary: #cbd5e1;
|
|
248
|
+
--data-mapper-accent-primary: #818cf8;
|
|
249
|
+
--data-mapper-connector-color: #818cf8;
|
|
250
|
+
--data-mapper-border-color: #475569;
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Exports
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// Components
|
|
258
|
+
export { DataMapperComponent } from './lib/components/data-mapper/data-mapper.component';
|
|
259
|
+
export { SchemaTreeComponent } from './lib/components/schema-tree/schema-tree.component';
|
|
260
|
+
|
|
261
|
+
// Services
|
|
262
|
+
export { MappingService } from './lib/services/mapping.service';
|
|
263
|
+
export { TransformationService } from './lib/services/transformation.service';
|
|
264
|
+
export { SchemaParserService } from './lib/services/schema-parser.service';
|
|
265
|
+
export { SvgConnectorService } from './lib/services/svg-connector.service';
|
|
266
|
+
|
|
267
|
+
// Types
|
|
268
|
+
export { JsonSchema, SchemaDocument } from './lib/models/json-schema.model';
|
|
269
|
+
export { FieldMapping, FieldReference } from './lib/models/field-mapping.model';
|
|
270
|
+
export { TransformationConfig, TransformationType } from './lib/models/transformation.model';
|
|
271
|
+
export { ArrayMapping, ArrayToObjectMapping } from './lib/models/array-mapping.model';
|
|
272
|
+
export { DefaultValue, DefaultValueType } from './lib/models/default-value.model';
|
|
273
|
+
export { SchemaTreeNode, FieldType } from './lib/models/schema-tree.model';
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Requirements
|
|
277
|
+
|
|
278
|
+
- Angular 19+
|
|
279
|
+
- Angular Material 19+
|
|
280
|
+
- Angular CDK 19+
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
Apache 2.0
|