mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-19 00:09:08 +00:00
- Add Platform API module to proxy requests to Platform API service - Add Elasticsearch service for pipeline catalog sync (CRUD operations) - Add DynamoDB service for storing pipeline tables/inputs configuration - Sync pipeline creation/update/delete to Elasticsearch index - Extract tables from jobs with connector-specific mappings: - JDBC: table_name, load_type, column_include_list, incremental_column_name - Singer: replication_method -> full_load/incremental - S3: same as Singer - Map connector types to DynamoDB types (jdbc->database, singer->application, s3->file) - Validate connector type is provided in job input - Normalize pipeline IDs for Platform API (replace - with _), keep UUIDs for ES 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
149 lines
3.5 KiB
TypeScript
149 lines
3.5 KiB
TypeScript
import { Injectable, Inject } from '@nestjs/common';
|
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
import {
|
|
DynamoDBDocumentClient,
|
|
GetCommand,
|
|
PutCommand,
|
|
DeleteCommand,
|
|
TranslateConfig,
|
|
} from '@aws-sdk/lib-dynamodb';
|
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
import { v4 as uuid } from 'uuid';
|
|
import { DYNAMODB_CONFIG } from './dynamodb.config';
|
|
|
|
export interface InputDocument {
|
|
id: string;
|
|
client_id: string;
|
|
user_id: string;
|
|
created_at: string;
|
|
name: string;
|
|
description?: string;
|
|
plugin: string;
|
|
type: string;
|
|
tables?: Array<{
|
|
name: string;
|
|
type: string;
|
|
columns?: string[];
|
|
reference_column?: { name: string; type: string };
|
|
}>;
|
|
credentials?: Record<string, any>;
|
|
}
|
|
|
|
@Injectable()
|
|
export class DynamoDBService {
|
|
private documentClient: DynamoDBDocumentClient;
|
|
private logger: any;
|
|
|
|
constructor(
|
|
@Inject(DadosferaLogger) dadosferaLogger: DadosferaLogger,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
|
|
const dynamoConfig = { region: DYNAMODB_CONFIG.region() };
|
|
const marshallOptions: TranslateConfig = {
|
|
marshallOptions: {
|
|
removeUndefinedValues: true,
|
|
},
|
|
};
|
|
|
|
const dynamoDb = new DynamoDBClient(dynamoConfig);
|
|
this.documentClient = DynamoDBDocumentClient.from(dynamoDb, marshallOptions);
|
|
}
|
|
|
|
async createInput(
|
|
clientId: string,
|
|
userId: string,
|
|
data: {
|
|
name: string;
|
|
description?: string;
|
|
plugin: string;
|
|
type: string;
|
|
tables?: Array<{
|
|
name: string;
|
|
type: string;
|
|
columns?: string[];
|
|
reference_column?: { name: string; type: string };
|
|
}>;
|
|
},
|
|
): Promise<InputDocument> {
|
|
const tableName = DYNAMODB_CONFIG.inputsTable();
|
|
const id = uuid();
|
|
const created_at = new Date().toISOString();
|
|
|
|
const item: InputDocument = {
|
|
id,
|
|
client_id: clientId,
|
|
user_id: userId,
|
|
created_at,
|
|
name: data.name,
|
|
description: data.description,
|
|
plugin: data.plugin,
|
|
type: data.type,
|
|
tables: data.tables,
|
|
};
|
|
|
|
this.logger.info('DynamoDB: Creating input', {
|
|
tableName,
|
|
inputId: id,
|
|
plugin: data.plugin,
|
|
});
|
|
|
|
const putCommand = new PutCommand({
|
|
TableName: tableName,
|
|
Item: item,
|
|
});
|
|
|
|
try {
|
|
await this.documentClient.send(putCommand);
|
|
this.logger.info('DynamoDB: Input created successfully', { inputId: id });
|
|
return item;
|
|
} catch (error) {
|
|
this.logger.error('DynamoDB: Failed to create input', {
|
|
tableName,
|
|
inputId: id,
|
|
region: DYNAMODB_CONFIG.region(),
|
|
error: error.message,
|
|
errorName: error.name,
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async findInput(clientId: string, inputId: string): Promise<InputDocument | null> {
|
|
const tableName = DYNAMODB_CONFIG.inputsTable();
|
|
|
|
const getCommand = new GetCommand({
|
|
TableName: tableName,
|
|
Key: {
|
|
id: inputId,
|
|
client_id: clientId,
|
|
},
|
|
});
|
|
|
|
const { Item } = await this.documentClient.send(getCommand);
|
|
|
|
return Item as InputDocument | null;
|
|
}
|
|
|
|
async deleteInput(clientId: string, inputId: string): Promise<void> {
|
|
const tableName = DYNAMODB_CONFIG.inputsTable();
|
|
|
|
this.logger.info('DynamoDB: Deleting input', {
|
|
tableName,
|
|
inputId,
|
|
});
|
|
|
|
const deleteCommand = new DeleteCommand({
|
|
TableName: tableName,
|
|
Key: {
|
|
id: inputId,
|
|
client_id: clientId,
|
|
},
|
|
});
|
|
|
|
await this.documentClient.send(deleteCommand);
|
|
|
|
this.logger.info('DynamoDB: Input deleted successfully', { inputId });
|
|
}
|
|
}
|