@jrmc/adonis-etl 1.0.0-alpha.1 → 1.0.1
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
CHANGED
|
@@ -1 +1,266 @@
|
|
|
1
|
-
# adonis-etl
|
|
1
|
+
# @jrmc/adonis-etl
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40jrmc%2Fadonis-etl)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
AdonisJS ETL skaffold commands package - Generate ETL (Extract, Transform, Load) components for your AdonisJS applications.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🚀 **Interactive CLI** - Guided command to create ETL components
|
|
11
|
+
- 📦 **Component Generation** - Generate Source, Transform, and Destination classes
|
|
12
|
+
- 🎯 **Smart Naming** - Automatic class naming based on your ETL process
|
|
13
|
+
- 🔧 **TypeScript Ready** - Full TypeScript support with proper interfaces
|
|
14
|
+
- 📁 **Organized Structure** - Files are created in proper directories (`app/etl/`)
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
node ace add @jrmc/adonis-etl
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Custom Directory Configuration
|
|
23
|
+
|
|
24
|
+
You can customize the directory where ETL files are generated by adding a `directories` configuration to your `adonisrc.ts`:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// adonisrc.ts
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
directories: {
|
|
30
|
+
etl: 'etl', // Custom path for ETL files
|
|
31
|
+
},
|
|
32
|
+
// ... other configurations
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
If not specified, files will be generated in the default `app/etl/` directory.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Generate ETL Components
|
|
41
|
+
|
|
42
|
+
Run the interactive command to create your ETL components:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
node ace make:etl my-process
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The command will guide you through:
|
|
49
|
+
|
|
50
|
+
1. **Selecting components** - Choose which ETL components to create:
|
|
51
|
+
- Source (data extraction)
|
|
52
|
+
- Transform (data transformation)
|
|
53
|
+
- Destination (data loading)
|
|
54
|
+
|
|
55
|
+
2. **Defining source type** - Specify your data source (e.g., `database`, `api`, `file`)
|
|
56
|
+
|
|
57
|
+
3. **Defining destination type** - Specify your data destination (e.g., `database`, `api`, `file`)
|
|
58
|
+
|
|
59
|
+
### Example
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
$ node ace make:etl import-product
|
|
63
|
+
|
|
64
|
+
? Which ETL components do you want to create? ›
|
|
65
|
+
❯◉ Source
|
|
66
|
+
◉ Transform
|
|
67
|
+
◉ Destination
|
|
68
|
+
|
|
69
|
+
? What is the source type? (e.g., database, api, file) › csv
|
|
70
|
+
? What is the destination type? (e.g., database, api, file) › db
|
|
71
|
+
|
|
72
|
+
✅ ETL files created successfully for: import-product
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This will create (with default configuration):
|
|
76
|
+
|
|
77
|
+
- `app/etl/sources/import_product_csv_source.ts`
|
|
78
|
+
- `app/etl/transforms/import_product_csv_to_db_transform.ts`
|
|
79
|
+
- `app/etl/destinations/import_product_db_destination.ts`
|
|
80
|
+
|
|
81
|
+
Or with custom directory configuration (`directories.etl: 'Opsone/jerem'`):
|
|
82
|
+
|
|
83
|
+
- `Opsone/jerem/sources/import_product_csv_source.ts`
|
|
84
|
+
- `Opsone/jerem/transforms/import_product_csv_to_db_transform.ts`
|
|
85
|
+
- `Opsone/jerem/destinations/import_product_db_destination.ts`
|
|
86
|
+
|
|
87
|
+
## Generated Files
|
|
88
|
+
|
|
89
|
+
### Source Component
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Source } from '@jrmc/adonis-etl'
|
|
93
|
+
|
|
94
|
+
export default class ImportProductCsvSource implements Source {
|
|
95
|
+
async *each() {
|
|
96
|
+
// Implement your data extraction logic here
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Transform Component
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { Transform } from '@jrmc/adonis-etl'
|
|
105
|
+
|
|
106
|
+
export default class ImportProductCsvToDbTransform implements Transform {
|
|
107
|
+
async process(row: unknown) {
|
|
108
|
+
// Implement your data transformation logic here
|
|
109
|
+
return row
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Destination Component
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { Destination } from '@jrmc/adonis-etl'
|
|
118
|
+
|
|
119
|
+
export default class ImportProductDbDestination implements Destination {
|
|
120
|
+
async write(row: unknown) {
|
|
121
|
+
// Implement your data loading logic here
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Usage Examples
|
|
127
|
+
|
|
128
|
+
The `sample/` folder contains two complete ETL implementation examples:
|
|
129
|
+
|
|
130
|
+
### 1. Books Import (Source → Destination)
|
|
131
|
+
|
|
132
|
+
This example shows a simple ETL process without transformation:
|
|
133
|
+
|
|
134
|
+
**Command:** `node ace import:books`
|
|
135
|
+
|
|
136
|
+
**Components:**
|
|
137
|
+
- **Source**: `book_csv_source.ts` - Reads a CSV file of books (5M records) with batch processing (500 items)
|
|
138
|
+
- **Destination**: `book_db_destination.ts` - Inserts data into database via `db.table().multiInsert()`
|
|
139
|
+
|
|
140
|
+
**Features:**
|
|
141
|
+
- Batch processing for performance optimization
|
|
142
|
+
- CSV error handling (empty lines and errors ignored)
|
|
143
|
+
- Optimized buffer (128KB) for large files
|
|
144
|
+
|
|
145
|
+
### 2. Products Import (Source → Transform → Destination)
|
|
146
|
+
|
|
147
|
+
This example shows a complete ETL process with data transformation:
|
|
148
|
+
|
|
149
|
+
**Command:** `node ace import:products`
|
|
150
|
+
|
|
151
|
+
**Components:**
|
|
152
|
+
- **Source**: `product_csv_source.ts` - Reads a CSV file of products (500K records)
|
|
153
|
+
- **Transform**: `product_csv_to_db_transform.ts` - Transforms CSV data (French column names → English)
|
|
154
|
+
- **Destination**: `product_db_destination.ts` - Saves via Lucid model `Product.create()`
|
|
155
|
+
|
|
156
|
+
**Features:**
|
|
157
|
+
- Column name transformation (e.g., `Nom` → `name`, `Prix` → `price`)
|
|
158
|
+
- AdonisJS model usage for persistence
|
|
159
|
+
- Data processing logging
|
|
160
|
+
|
|
161
|
+
### Example Files Structure
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
sample/
|
|
165
|
+
├── commands/
|
|
166
|
+
│ ├── import_books.ts # Books import command
|
|
167
|
+
│ └── import_products.ts # Products import command
|
|
168
|
+
├── etl/
|
|
169
|
+
│ ├── sources/
|
|
170
|
+
│ │ ├── book_csv_source.ts
|
|
171
|
+
│ │ └── product_csv_source.ts
|
|
172
|
+
│ ├── transforms/
|
|
173
|
+
│ │ └── product_csv_to_db_transform.ts
|
|
174
|
+
│ ├── destinations/
|
|
175
|
+
│ │ ├── book_db_destination.ts
|
|
176
|
+
│ │ └── product_db_destination.ts
|
|
177
|
+
│ └── resources/
|
|
178
|
+
│ ├── books.csv # Sample data
|
|
179
|
+
│ └── products.csv # Sample data
|
|
180
|
+
└── app/models/
|
|
181
|
+
├── book.ts # Book model
|
|
182
|
+
└── product.ts # Product model
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
These examples demonstrate different possible approaches:
|
|
186
|
+
- **Batch processing** vs **line-by-line processing**
|
|
187
|
+
- **Direct database insertion** vs **Lucid model usage**
|
|
188
|
+
- **With or without data transformation**
|
|
189
|
+
|
|
190
|
+
## Performance Optimization
|
|
191
|
+
|
|
192
|
+
For large-scale ETL operations, consider integrating with a job queue system (like BullMQ, or AdonisJS Queue package) to run ETL processes asynchronously, distribute workload across multiple workers, and improve reliability with automatic retry mechanisms.
|
|
193
|
+
|
|
194
|
+
## Dependencies
|
|
195
|
+
|
|
196
|
+
This package requires:
|
|
197
|
+
- `@jrmc/etl` - The core ETL library
|
|
198
|
+
- AdonisJS 6.x
|
|
199
|
+
- Node.js 22.17.0+
|
|
200
|
+
|
|
201
|
+
## File Structure
|
|
202
|
+
|
|
203
|
+
Generated files are organized in the following structure:
|
|
204
|
+
|
|
205
|
+
**Default structure:**
|
|
206
|
+
```
|
|
207
|
+
app/
|
|
208
|
+
└── etl/
|
|
209
|
+
├── sources/
|
|
210
|
+
│ └── your_source_files.ts
|
|
211
|
+
├── transforms/
|
|
212
|
+
│ └── your_transform_files.ts
|
|
213
|
+
└── destinations/
|
|
214
|
+
└── your_destination_files.ts
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Custom structure (with `directories.etl: 'src/module/etl'`):**
|
|
218
|
+
```
|
|
219
|
+
src/
|
|
220
|
+
└── module/
|
|
221
|
+
└── etl/
|
|
222
|
+
├── sources/
|
|
223
|
+
│ └── your_source_files.ts
|
|
224
|
+
├── transforms/
|
|
225
|
+
│ └── your_transform_files.ts
|
|
226
|
+
└── destinations/
|
|
227
|
+
└── your_destination_files.ts
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Naming Convention
|
|
231
|
+
|
|
232
|
+
The generated class names follow this pattern:
|
|
233
|
+
|
|
234
|
+
- **Source**: `{process_name}_{source_type}_source`
|
|
235
|
+
- **Transform**: `{process_name}_{source_type}_to_{destination_type}_transform`
|
|
236
|
+
- **Destination**: `{process_name}_{destination_type}_destination`
|
|
237
|
+
|
|
238
|
+
All names are automatically converted to snake_case for file names and PascalCase for class names.
|
|
239
|
+
|
|
240
|
+
**Example**: For process `import-product` with source `csv` and destination `db`:
|
|
241
|
+
- File: `import_product_csv_source.ts` → Class: `ImportProductCsvSource`
|
|
242
|
+
- File: `import_product_csv_to_db_transform.ts` → Class: `ImportProductCsvToDbTransform`
|
|
243
|
+
- File: `import_product_db_destination.ts` → Class: `ImportProductDbDestination`
|
|
244
|
+
|
|
245
|
+
## Contributing
|
|
246
|
+
|
|
247
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
252
|
+
|
|
253
|
+
## Author
|
|
254
|
+
|
|
255
|
+
**Jeremy Chaufourier**
|
|
256
|
+
- Email: jeremy@chaufourier.fr
|
|
257
|
+
- GitHub: [@batosai](https://github.com/batosai)
|
|
258
|
+
|
|
259
|
+
## Changelog
|
|
260
|
+
|
|
261
|
+
### 1.0.0
|
|
262
|
+
- Initial release
|
|
263
|
+
- Interactive ETL component generation
|
|
264
|
+
- Support for Source, Transform, and Destination components
|
|
265
|
+
- TypeScript support
|
|
266
|
+
- Custom directory configuration support via `directories.etl` in adonisrc.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{{#var resourceFileName = string(className).snakeCase().ext('.ts').toString()}}
|
|
2
2
|
{{{
|
|
3
3
|
exports({
|
|
4
|
-
to: app.makePath('app/etl/destinations', resourceFileName)
|
|
4
|
+
to: app.makePath(app.rcFile.directories['etl'] || 'app/etl/', 'destinations', resourceFileName)
|
|
5
5
|
})
|
|
6
6
|
}}}
|
|
7
|
-
import { Destination } from '@jrmc/adonis-etl'
|
|
7
|
+
import type { Destination } from '@jrmc/adonis-etl'
|
|
8
8
|
|
|
9
9
|
export default class {{ className }} implements Destination {
|
|
10
10
|
async write(row: unknown) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{{#var resourceFileName = string(className).snakeCase().ext('.ts').toString()}}
|
|
2
2
|
{{{
|
|
3
3
|
exports({
|
|
4
|
-
to: app.makePath('app/etl/sources', resourceFileName)
|
|
4
|
+
to: app.makePath(app.rcFile.directories['etl'] || 'app/etl/', 'sources', resourceFileName)
|
|
5
5
|
})
|
|
6
6
|
}}}
|
|
7
|
-
import { Source } from '@jrmc/adonis-etl'
|
|
7
|
+
import type { Source } from '@jrmc/adonis-etl'
|
|
8
8
|
|
|
9
9
|
export default class {{ className }} implements Source {
|
|
10
10
|
async *each() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{{#var resourceFileName = string(className).snakeCase().ext('.ts').toString()}}
|
|
2
2
|
{{{
|
|
3
3
|
exports({
|
|
4
|
-
to: app.makePath('app/etl/transforms', resourceFileName)
|
|
4
|
+
to: app.makePath(app.rcFile.directories['etl'] || 'app/etl/', 'transforms', resourceFileName)
|
|
5
5
|
})
|
|
6
6
|
}}}
|
|
7
|
-
import { Transform } from '@jrmc/adonis-etl'
|
|
7
|
+
import type { Transform } from '@jrmc/adonis-etl'
|
|
8
8
|
|
|
9
9
|
export default class {{ className }} implements Transform {
|
|
10
10
|
async process(row: unknown) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jrmc/adonis-etl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"adonisjs",
|
|
6
6
|
"etl",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"author": "Jeremy Chaufourier jeremy@chaufourier.fr",
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"description": "AdonisJS ETL commands package",
|
|
12
|
+
"description": "AdonisJS ETL skaffold commands package - Generate ETL (Extract, Transform, Load) components for your AdonisJS applications.",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "build/index.js",
|
|
15
15
|
"repository": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"prettier": "@adonisjs/prettier-config",
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public",
|
|
53
|
-
"tag": "
|
|
53
|
+
"tag": "latest"
|
|
54
54
|
},
|
|
55
55
|
"volta": {
|
|
56
56
|
"node": "22.17.0"
|