This commit is contained in:
Niels Lyngsø
2023-07-04 21:01:09 +02:00
parent da302a12f3
commit 2c1d399063
2 changed files with 34 additions and 0 deletions

View File

@@ -1,6 +1,23 @@
import { DataSourceResponse, UmbPagedData } from '../index.js';
import { Diff } from '@umbraco-cms/backoffice/utils';
/**
* This function extends the data set of a paged DataSourceResponse.
* Provide the desired type as a generic type parameter.
* This will require the appendData argument to fill in the missing properties of the items.
* @param response {DataSourceResponse<UmbPagedData<object>>}
* @param appendData {object} Additional properties to append to the data set.
* @returns {DataSourceResponse<UmbPagedData<object>>}
*
* @example
*
* type originalResponseType = { foo: string };
* type extendedResponseType = { foo: string, bar: string };
*
* const extendedResponse = extendDataSourcePagedResponseData<extendedResponseType>(originalResponse, { bar: 'some additional data' });
*
* extendedResponse.data.items[0].bar is now equal to 'some additional data'
*/
export function extendDataSourcePagedResponseData<
ExtendedDataType extends IncomingDataType,
IncomingDataType extends object = object,

View File

@@ -1,6 +1,23 @@
import { DataSourceResponse } from '../index.js';
import { Diff } from '@umbraco-cms/backoffice/utils';
/**
* This function extends the data set of a DataSourceResponse.
* Provide the desired type as a generic type parameter.
* This will require the appendData argument to fill in the missing properties of the data.
* @param response {DataSourceResponse<object>}
* @param appendData {object} Additional properties to append to the data.
* @returns {DataSourceResponse<object>}
*
* @example
*
* type originalResponseType = { foo: string };
* type extendedResponseType = { foo: string, bar: string };
*
* const extendedResponse = extendDataSourceResponseData<extendedResponseType>(originalResponse, { bar: 'some additional data' });
*
* extendedResponse.data.bar is now equal to 'some additional data'
*/
export function extendDataSourceResponseData<
ExtendedDataType extends IncomingDataType,
IncomingDataType extends object = object,