method to extend data source response data
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { DataSourceResponse } from '../index.js';
|
||||
|
||||
type FilterKeys<T, U> = {
|
||||
[K in keyof T]: K extends keyof U ? never : K;
|
||||
};
|
||||
|
||||
type Diff<U, T> = Pick<T, FilterKeys<T, U>[keyof T]>;
|
||||
|
||||
export function extendDataSourceResponseData<
|
||||
ExtendedDataType extends IncomingDataType,
|
||||
IncomingDataType extends object = object,
|
||||
MissingPropsType extends object = Omit<Diff<IncomingDataType, ExtendedDataType>, '$type'>,
|
||||
// Maybe this Omit<..., "$ype"> can be removed, but for now it kept showing up as a difference, though its not a difference on the two types.
|
||||
ToType = IncomingDataType & ExtendedDataType
|
||||
>(response: DataSourceResponse<IncomingDataType>, appendData: MissingPropsType): DataSourceResponse<ToType> {
|
||||
if (response.data === undefined) return response as unknown as DataSourceResponse<ToType>;
|
||||
return { ...response, data: { ...response.data, ...appendData } as unknown as ToType };
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
export * from './collection-data-source.interface.js';
|
||||
export * from './copy-data-source.interface.js';
|
||||
export * from './data-source-response.interface.js';
|
||||
export * from './data-source.interface.js';
|
||||
export * from './extend-data-source-response-data.function.js';
|
||||
export * from './folder-data-source.interface.js';
|
||||
export * from './tree-data-source.interface.js';
|
||||
export * from './item-data-source.interface.js';
|
||||
export * from './move-data-source.interface.js';
|
||||
export * from './copy-data-source.interface.js';
|
||||
export * from './collection-data-source.interface.js';
|
||||
export * from './tree-data-source.interface.js';
|
||||
|
||||
Reference in New Issue
Block a user