Data Importable
The DataImportable module is a TypeScript module that provides functionality for importing and managing data within a system. It utilizes several other modules and extends their capabilities, particularly focusing on handling data transformations, checking types, and managing properties through imports. This module is especially useful in scenarios where dynamic data import and type-checking are required, ensuring the integrity and compatibility of the data being processed.
Table of Contents
Classes Overview
DataImportableSettings
This class extends ClassLineageSettings and is used for managing settings related to Data Importable functionalities.
- Properties:
extensionDataImportable: A static property that defines the extension data identifier.- Constructor: Accepts a partial object of
DataImportableSettingsfor initialization.
DataImportableExtensionData
This class implements the TypeToolsExtensionData interface and handles actions that occur before and after data imports.
- Properties:
beforeimports: An array of functions that execute before data import.afterimports: An array of functions that execute after data import.import: A method that manages the import process with optional skeleton and assignment parameters.
DataImportable
This class implements the TypeToolsExtension interface and is the core handler for managing data imports and extensions.
-
Static Methods:
getExtensionData: Retrieves extension data from the target using specified settings.typeCheck: Checks if the target complies with theDataImportablesettings.implementOn: Implements the data import capabilities on a given target.
-
Properties:
settings: Instance ofDataImportableSettingsused for configuration.
-
Constructor: Accepts optional settings to initialize the
DataImportableinstance.
Methods and Their Functionality
getExtensionData(target, settings): Retrieves and returns the extension data for a specified target using the provided settings. This method is crucial for accessing the configuration related to data import functionality.
static getExtensionData(target: any, settings = DataImportableSettings): DataImportableExtensionData {
return TypeToolsBase.getExtension(target, settings.extensionDataImportable, settings);
}
typeCheck(target, settings): Determines if a target is compatible with theDataImportablesettings by checking for the presence of extension data.
static typeCheck(target: any, settings = DataImportableSettings): boolean {
return target && !!DataImportable.getExtensionData(target, settings);
}
implementOn(target, settings): Integrates data import capabilities onto a specified target. It ensures that the necessary context and properties management are established.
static implementOn(target: any, settings = DataImportableSettings) {
// Implementation logic here
}
import: This method withinDataImportableExtensionDatamanages the actual data import process, applying any necessary transformations and handling errors or cancellations gracefully.
import(data: any, skel?: any, assignOnly?: boolean) {
// Import logic here
}
Usage Guide
To effectively use the DataImportable functionalities in your TypeScript project, follow these steps:
-
Initialize Settings: Create an instance of
DataImportableSettingswith any required custom settings. -
Implement on Target: Use
DataImportable.implementOn(target)to apply data import capabilities to your target object. -
Perform Data Import: Call the
importmethod on the target's extension data to manage data import, transformations, and ensure type safety.
Example
// Initialize settings
const settings = new DataImportableSettings();
// Implement on target
const targetObject = {};
DataImportable.implementOn(targetObject, settings);
// Import data
targetObject.import({ key: 'value' });