mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-27 19:39:52 +00:00
26 lines
1.3 KiB
TypeScript
26 lines
1.3 KiB
TypeScript
![]() |
import StorageArray from 'ember-local-storage/local/array';
|
||
|
import { DataModelEntityInstance } from '@datahub/data-models/entity/entity-factory';
|
||
|
import { IStoredEntityAttrs } from '@datahub/lists/types/list';
|
||
|
|
||
|
/**
|
||
|
* Finds a DataModelEntity's stored attributes in a list of IStoredEntityAttrs or vice-versa, using the urn for equality comparison
|
||
|
* If the urn's match the representations are considered equivalent
|
||
|
* @template T is assignable to IStoredEntityAttrs or DataModelEntityInstance, not necessarily assignable to U
|
||
|
* @template U is assignable to IStoredEntityAttrs or DataModelEntityInstance, not necessarily assignable to T
|
||
|
* @param {(StorageArray<T> | Array<T>)} list the list containing the representations to search through
|
||
|
*/
|
||
|
export const findEntityInList = <
|
||
|
T extends IStoredEntityAttrs | DataModelEntityInstance,
|
||
|
U extends IStoredEntityAttrs | DataModelEntityInstance
|
||
|
>(
|
||
|
list: StorageArray<T> | Array<T>
|
||
|
): ((attributes: U) => U | T | undefined) => ({ urn }: U | T): U | T | undefined => list.findBy('urn', urn);
|
||
|
|
||
|
/**
|
||
|
* Serializes the interesting attributes from a DataModelEntityInstance that can be used to rehydrate the instance later
|
||
|
*/
|
||
|
export const serializeForStorage = ({ urn, displayName }: DataModelEntityInstance): IStoredEntityAttrs => ({
|
||
|
urn,
|
||
|
type: displayName
|
||
|
});
|