-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Feature] Add data source methods * [Feature] Add DataSourceController * [Feature] Make waitToBeReady public (again) * [EDT-1714] mapping tools separated * [EDT-1714] feat: mapping tools separated * [EDT-1714] feat: mapping tools separated * [EDT-1714] setDataRow method added to DataSourceController.ts * [EDT-1714] subscription onDataRowChanged added * [Feature] Expose data source * [EDT-1714] conflicts * [EDT-1714] export DataConnectorTypes * [EDT-1714] subscription onDataRowChanged dropped * [EDT-1714] better comments for DataItemMappingTools --------- Co-authored-by: Laurent Raymond <1528484+Dvergar@users.noreply.github.com>
- Loading branch information
1 parent
8de043c
commit 9079986
Showing
7 changed files
with
152 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { DataItem } from '../types/DataConnectorTypes'; | ||
|
||
/** | ||
* Utility tools for mapping between `EngineDataItem` and `DataItem`. | ||
*/ | ||
export class DataItemMappingTools { | ||
/** | ||
* Checks if the given value is a `DatePropertyWrapper`. | ||
* | ||
* @param value The value to check. | ||
* @returns `true` if the value is a `DatePropertyWrapper`, otherwise `false`. | ||
*/ | ||
private isDatePropertyWrapper( | ||
value: string | number | boolean | DatePropertyWrapper | null, | ||
): value is DatePropertyWrapper { | ||
return typeof value === 'object' && value?.type === 'date'; | ||
} | ||
|
||
/** | ||
* Checks if the given value is a `Date` object instance. | ||
* | ||
* @param value The value to check. | ||
* @returns `true` if the value is a `Date` object, otherwise `false`. | ||
*/ | ||
private isDateObject(value: string | number | boolean | Date | null): value is Date { | ||
return value instanceof Date; | ||
} | ||
|
||
/** | ||
* Transforms an `EngineDataItem` into a `DataItem`. | ||
* | ||
* Converts `DatePropertyWrapper` values to JavaScript `Date` objects | ||
* while keeping other values unchanged. | ||
* | ||
* @param dataItem the EngineDataItem to transform. | ||
* @returns the resulting `DataItem` with parsed date properties. | ||
*/ | ||
mapEngineToDataItem(dataItem: EngineDataItem): DataItem { | ||
const parsedItem: DataItem = {}; | ||
|
||
Object.entries(dataItem).forEach(([key, value]) => { | ||
parsedItem[key] = this.isDatePropertyWrapper(value) ? new Date(value.value) : value; | ||
}); | ||
|
||
return parsedItem; | ||
} | ||
|
||
/** | ||
* Transforms a `DataItem` into an `EngineDataItem`. | ||
* | ||
* Converts JavaScript `Date` objects to `DatePropertyWrapper` objects | ||
* while keeping other values unchanged. | ||
* | ||
* @param dataItem the `DataItem` to transform. | ||
* @returns the resulting `EngineDataItem` with parsed date properties. | ||
*/ | ||
mapDataItemToEngine(dataItem: DataItem): EngineDataItem { | ||
const parsedItem: EngineDataItem = {}; | ||
|
||
Object.entries(dataItem).forEach(([key, value]) => { | ||
parsedItem[key] = this.isDateObject(value) | ||
? ({ value: value.getTime(), type: 'date' } as DatePropertyWrapper) | ||
: value; | ||
}); | ||
|
||
return parsedItem; | ||
} | ||
} | ||
|
||
/** | ||
* Internal type used to wrap date objects on the engine side. | ||
*/ | ||
export type DatePropertyWrapper = { | ||
value: number; | ||
type: 'date'; | ||
}; | ||
|
||
/** | ||
* Engine data item type. | ||
*/ | ||
export type EngineDataItem = { | ||
[key: string]: string | number | boolean | DatePropertyWrapper | null; | ||
}; |