@jrmc/adonis-etl 1.0.0-alpha.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/LICENSE +21 -0
- package/README.md +1 -0
- package/build/commands/commands.json +1 -0
- package/build/commands/main.d.ts +4 -0
- package/build/commands/main.js +36 -0
- package/build/commands/make/etl.d.ts +13 -0
- package/build/commands/make/etl.js +95 -0
- package/build/configure.d.ts +2 -0
- package/build/configure.js +9 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +2 -0
- package/build/stubs/main.d.ts +1 -0
- package/build/stubs/main.js +2 -0
- package/build/stubs/make/etl/destinations/main.ts.stub +12 -0
- package/build/stubs/make/etl/sources/main.ts.stub +13 -0
- package/build/stubs/make/etl/transforms/main.ts.stub +13 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jeremy Chaufourier
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# adonis-etl
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"commands":[{"commandName":"make:etl","description":"Create a new ETL files (source, transform, destination)","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the ETL process","type":"string"}],"options":{},"filePath":"make/etl.js"}],"version":1}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-memory cache of commands after they have been loaded
|
|
5
|
+
*/
|
|
6
|
+
let commandsMetaData
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Reads the commands from the "./commands.json" file. Since, the commands.json
|
|
10
|
+
* file is generated automatically, we do not have to validate its contents
|
|
11
|
+
*/
|
|
12
|
+
export async function getMetaData() {
|
|
13
|
+
if (commandsMetaData) {
|
|
14
|
+
return commandsMetaData
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
|
|
18
|
+
commandsMetaData = JSON.parse(commandsIndex).commands
|
|
19
|
+
|
|
20
|
+
return commandsMetaData
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Imports the command by lookingup its path from the commands
|
|
25
|
+
* metadata
|
|
26
|
+
*/
|
|
27
|
+
export async function getCommand(metaData) {
|
|
28
|
+
const commands = await getMetaData()
|
|
29
|
+
const command = commands.find(({ commandName }) => metaData.commandName === commandName)
|
|
30
|
+
if (!command) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
|
|
35
|
+
return commandConstructor
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-etl
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
8
|
+
export default class MakeEtl extends BaseCommand {
|
|
9
|
+
static commandName: string;
|
|
10
|
+
static description: string;
|
|
11
|
+
name: string;
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-etl
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
};
|
|
13
|
+
// import { stubsRoot } from '../../stubs/main.js'
|
|
14
|
+
import { args, BaseCommand } from '@adonisjs/core/ace';
|
|
15
|
+
import string from '@adonisjs/core/helpers/string';
|
|
16
|
+
import { stubsRoot } from '../../stubs/main.js';
|
|
17
|
+
export default class MakeEtl extends BaseCommand {
|
|
18
|
+
static commandName = 'make:etl';
|
|
19
|
+
static description = 'Create a new ETL files (source, transform, destination)';
|
|
20
|
+
async run() {
|
|
21
|
+
// Ask which ETL components to create
|
|
22
|
+
const components = await this.prompt.multiple('Which ETL components do you want to create?', [
|
|
23
|
+
'Source',
|
|
24
|
+
'Transform',
|
|
25
|
+
'Destination'
|
|
26
|
+
], {
|
|
27
|
+
validate: (value) => {
|
|
28
|
+
if (!value || value.length === 0) {
|
|
29
|
+
return 'You must select at least one component';
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
// Ask for source details if source is selected
|
|
35
|
+
let sourceDetails = null;
|
|
36
|
+
if (components.includes('Source') || components.includes('Transform')) {
|
|
37
|
+
sourceDetails = await this.prompt.ask('What is the source type? (e.g., database, api, file)', {
|
|
38
|
+
validate: (value) => {
|
|
39
|
+
if (!value || value.trim().length === 0) {
|
|
40
|
+
return 'Source type is required';
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Ask for destination details if destination is selected
|
|
47
|
+
let destinationDetails = null;
|
|
48
|
+
if (components.includes('Destination') || components.includes('Transform')) {
|
|
49
|
+
destinationDetails = await this.prompt.ask('What is the destination type? (e.g., database, api, file)', {
|
|
50
|
+
validate: (value) => {
|
|
51
|
+
if (!value || value.trim().length === 0) {
|
|
52
|
+
return 'Destination type is required';
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const codemods = await this.createCodemods();
|
|
59
|
+
let className = null;
|
|
60
|
+
// Create the selected components
|
|
61
|
+
for (const component of components) {
|
|
62
|
+
if (component === 'Source') {
|
|
63
|
+
className = [
|
|
64
|
+
string.snakeCase(this.name),
|
|
65
|
+
string.snakeCase(sourceDetails),
|
|
66
|
+
'source',
|
|
67
|
+
].join('_');
|
|
68
|
+
}
|
|
69
|
+
else if (component === 'Destination') {
|
|
70
|
+
className = [
|
|
71
|
+
string.snakeCase(this.name),
|
|
72
|
+
string.snakeCase(destinationDetails),
|
|
73
|
+
'destination',
|
|
74
|
+
].join('_');
|
|
75
|
+
}
|
|
76
|
+
else if (component === 'Transform') {
|
|
77
|
+
className = [
|
|
78
|
+
string.snakeCase(this.name),
|
|
79
|
+
string.snakeCase(sourceDetails),
|
|
80
|
+
'to',
|
|
81
|
+
string.snakeCase(destinationDetails),
|
|
82
|
+
'transform',
|
|
83
|
+
].join('_');
|
|
84
|
+
}
|
|
85
|
+
const stubPath = `make/etl/${component.toLowerCase()}s/main.ts.stub`;
|
|
86
|
+
await codemods.makeUsingStub(stubsRoot, stubPath, {
|
|
87
|
+
className
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
this.logger.success(`ETL files created successfully for: ${this.name}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
__decorate([
|
|
94
|
+
args.string({ description: 'Name of the ETL process' })
|
|
95
|
+
], MakeEtl.prototype, "name", void 0);
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stubsRoot: string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{{#var resourceFileName = string(className).snakeCase().ext('.ts').toString()}}
|
|
2
|
+
{{{
|
|
3
|
+
exports({
|
|
4
|
+
to: app.makePath('app/etl/destinations', resourceFileName)
|
|
5
|
+
})
|
|
6
|
+
}}}
|
|
7
|
+
import { Destination } from '@jrmc/adonis-etl'
|
|
8
|
+
|
|
9
|
+
export default class {{ className }} implements Destination {
|
|
10
|
+
async write(row: unknown) {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{#var resourceFileName = string(className).snakeCase().ext('.ts').toString()}}
|
|
2
|
+
{{{
|
|
3
|
+
exports({
|
|
4
|
+
to: app.makePath('app/etl/sources', resourceFileName)
|
|
5
|
+
})
|
|
6
|
+
}}}
|
|
7
|
+
import { Source } from '@jrmc/adonis-etl'
|
|
8
|
+
|
|
9
|
+
export default class {{ className }} implements Source {
|
|
10
|
+
async *each() {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{#var resourceFileName = string(className).snakeCase().ext('.ts').toString()}}
|
|
2
|
+
{{{
|
|
3
|
+
exports({
|
|
4
|
+
to: app.makePath('app/etl/transforms', resourceFileName)
|
|
5
|
+
})
|
|
6
|
+
}}}
|
|
7
|
+
import { Transform } from '@jrmc/adonis-etl'
|
|
8
|
+
|
|
9
|
+
export default class {{ className }} implements Transform {
|
|
10
|
+
async process(row: unknown) {
|
|
11
|
+
return row
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jrmc/adonis-etl",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"adonisjs",
|
|
6
|
+
"etl",
|
|
7
|
+
"ace",
|
|
8
|
+
"commands"
|
|
9
|
+
],
|
|
10
|
+
"author": "Jeremy Chaufourier jeremy@chaufourier.fr",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"description": "AdonisJS ETL commands package",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "build/index.js",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/batosai/adonis-etl.git"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"build"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"build": "npm run clean && tsc && npm run copy-stubs",
|
|
25
|
+
"copy-stubs": "cp -r stubs/make build/stubs/",
|
|
26
|
+
"postbuild": "adonis-kit index build/commands",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"clean": "del-cli build",
|
|
29
|
+
"format": "prettier --write ."
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./build/index.js",
|
|
33
|
+
"./commands": "./build/commands/main.js",
|
|
34
|
+
"./commands/*": "./build/commands/*.js"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@jrmc/etl": "^1.0.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@adonisjs/assembler": "^7.8.2",
|
|
41
|
+
"@adonisjs/core": "^6.19.0",
|
|
42
|
+
"@adonisjs/lucid": "^21.7.0",
|
|
43
|
+
"@adonisjs/prettier-config": "^1.4.5",
|
|
44
|
+
"@adonisjs/tsconfig": "^1.4.1",
|
|
45
|
+
"@types/node": "^24.0.11",
|
|
46
|
+
"del-cli": "^7.0.0",
|
|
47
|
+
"prettier": "^3.6.2",
|
|
48
|
+
"typescript": "^5.8.3"
|
|
49
|
+
},
|
|
50
|
+
"prettier": "@adonisjs/prettier-config",
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"tag": "alpha"
|
|
54
|
+
},
|
|
55
|
+
"volta": {
|
|
56
|
+
"node": "22.17.0"
|
|
57
|
+
}
|
|
58
|
+
}
|