/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { CompositeFilterDescriptor, GroupDescriptor, SortDescriptor, State } from '@progress/kendo-data-query'; import { DataSource, DataSourceProps } from './use-data-source.js'; /** * Configuration properties for the remote data source. * Extends the basic DataSourceProps with remote data operations capabilities. * * @template T - The type of data items in the data source. Defaults to any object. */ export interface RemoteDataSourceProps extends DataSourceProps { /** * Map of original data items read from the remote source, indexed by ID. */ reads?: Map; /** * Map of created items that need to be synced with the remote source. */ creates?: Map; /** * Map of updated items that need to be synced with the remote source. */ updates?: Map; /** * Map of items marked for deletion that need to be synced with the remote source. */ deletes?: Map; /** * Determines if filtering operations should be performed on the server. * When true, filter parameters are sent to the server during read operations. * * @default true */ serverFiltering?: boolean; /** * Determines if sorting operations should be performed on the server. * When true, sort parameters are sent to the server during read operations. * * @default true */ serverSorting?: boolean; /** * Determines if paging operations should be performed on the server. * When true, skip and take parameters are sent to the server during read operations. * * @default true */ serverPaging?: boolean; /** * Determines if grouping operations should be performed on the server. * When true, group parameters are sent to the server during read operations. * * @default true */ serverGrouping?: boolean; /** * Configuration for CRUD operations transport. * Defines how data is sent to and received from the server. */ transport?: { /** * Configuration for create operations. * Can be either an object specifying the endpoint configuration or a function for custom implementation. */ create?: { /** * URL for the create operation. Can be a string or a function that returns a string based on the data item. */ url: string | ((dataItem: T) => string); /** * HTTP method to use for the create operation. * * @default "POST" */ method?: string; /** * Content-Type header to use for the request. * * @default "application/json" */ contentType?: string; /** * Additional data to include in the request. */ data?: { [key: string]: any; }; /** * Function that transforms the request data before sending it to the server. * * @param data - The data item to transform * @returns Transformed data */ parameterMap?: (data: T) => any; /** * Callback executed when the create operation is successful. * * @param data - The created data item */ onSuccess?: (data: T) => void; /** * Function to process the server response. * * @param response - The server response * @returns Processed data item or null */ onResponse?: (response: any) => T | null; /** * Callback executed when the create operation fails. * * @param error - The error from the server */ onError?: (error: any) => void; } | ((options: { data: T; }) => Promise); /** * Configuration for read operations. * Can be either an object specifying the endpoint configuration or a function for custom implementation. */ read?: { /** * URL for the read operation. Can be a string or a function that returns a string. */ url: string | (() => string); /** * HTTP method to use for the read operation. * * @default "GET" */ method?: string; /** * Content-Type header to use for the request. */ contentType?: string; /** * Additional data to include in the request. */ data?: { [key: string]: any; }; /** * Function that transforms the request data before sending it to the server. * * @param data - The request parameters including filter, paging, sorting, and grouping info * @returns Transformed request parameters */ parameterMap?: (data: { filter?: CompositeFilterDescriptor; skip?: number; take?: number; sort?: SortDescriptor[]; group?: GroupDescriptor[]; }) => any; /** * Callback executed when the read operation is successful. * * @param data - The retrieved data items */ onSuccess?: (data: T[]) => void; /** * Function to process the server response. * * @param response - The server response * @returns Processed data item or null */ onResponse?: (response: any) => T | null; /** * Callback executed when the read operation fails. * * @param error - The error from the server */ onError?: (error: any) => void; } | ((options: { filter?: CompositeFilterDescriptor; skip?: number; take?: number; sort?: SortDescriptor[]; group?: GroupDescriptor[]; onSuccess?: (data: T[]) => void; onResponse?: (response: any) => T | null; onError?: (error: any) => void; }) => Promise); /** * Configuration for update operations. * Can be either an object specifying the endpoint configuration or a function for custom implementation. */ update?: { /** * URL for the update operation. Can be a string or a function that returns a string based on the data item. */ url: string | ((dataItem: T) => string); /** * HTTP method to use for the update operation. * * @default "PUT" */ method?: string; /** * Content-Type header to use for the request. * * @default "application/json" */ contentType?: string; /** * Additional data to include in the request. */ data?: { [key: string]: any; }; /** * Function that transforms the request data before sending it to the server. * * @param data - The data item to transform * @returns Transformed data */ parameterMap?: (data: T) => any; /** * Callback executed when the update operation is successful. * * @param data - The updated data item */ onSuccess?: (data: T) => void; /** * Function to process the server response. * * @param response - The server response * @returns Processed data item or null */ onResponse?: (response: any) => T | null; /** * Callback executed when the update operation fails. * * @param error - The error from the server */ onError?: (error: any) => void; } | ((options: { data: T; }) => Promise); /** * Configuration for delete operations. * Can be either an object specifying the endpoint configuration or a function for custom implementation. */ delete?: { /** * URL for the delete operation. Can be a string or a function that returns a string based on the data item. */ url: string | ((dataItem: T) => string); /** * HTTP method to use for the delete operation. * * @default "DELETE" */ method?: string; /** * Content-Type header to use for the request. */ contentType?: string; /** * Additional data to include in the request. */ data?: { [key: string]: any; }; /** * Function that transforms the request data before sending it to the server. * * @param data - The data item to transform * @returns Transformed data */ parameterMap?: (data: T) => any; /** * Callback executed when the delete operation is successful. * * @param data - The deleted data item */ onSuccess?: (data: T) => void; /** * Function to process the server response. * * @param response - The server response * @returns Processed data item or null */ onResponse?: (response: any) => T | null; /** * Callback executed when the delete operation fails. * * @param error - The error from the server */ onError?: (error: any) => void; } | ((options: { data: T; }) => Promise); }; /** * Schema configuration for parsing and mapping server responses. * Extends the base DataSourceProps schema with additional properties for remote data. */ schema: DataSourceProps['schema'] & { /** * Specifies the field in the response that contains the data items, * or a function that extracts the data items from the response. */ data?: string | ((data: any) => T[]); /** * Specifies the field in the response that contains the total count, * or a function that extracts the total count from the response. */ total?: string | ((data: any) => number); /** * Specifies the field in the response that contains error information, * or a function that extracts error information from the response. */ errors?: string | ((data: any) => any); }; } /** * Represents a remote data source with CRUD operations (Create, Read, Update, Delete). * * @template T - The type of data items in the data source. Defaults to any. */ export type RemoteDataSource = DataSource & { /** Set of original data items read from the remote source, indexed by ID */ reads: Map; /** Map of created items that need to be synced */ creates: Map; /** Map of updated items that need to be synced */ updates: Map; /** Map of items marked for deletion that need to be synced */ deletes: Map; /** Map of dirty fields for each item */ dirty: Map>; /** Map of errors for each item */ errors: Map; /** Adds an error to an item */ addError: (params: { error: any; data?: T; }) => void; /** Removes an error from an item */ removeError: (params: { error: any; }) => void; /** Removes all errors for an item */ removeErrors: (params: { data: T; }) => void; /** Removes all errors */ removeAllErrors: () => void; /** Reads data from the remote source */ read: (state?: State) => Promise; /** Creates a new item */ create: (params: { data: T; }) => void; /** Updates an existing item */ update: (params: { data: T; field?: string; }) => void; /** Deletes an item */ delete: (params: { data: T; }) => void; /** Syncs all pending changes with the remote source */ sync: () => Promise; /** Syncs a single item with the remote source */ syncItem: (params: { data: T; }) => Promise; /** Removes an item from creates */ removeCreate: (params: { data: T; }) => void; /** Removes an item from updates */ removeUpdate: (params: { data: T; }) => void; /** Removes an item from deletes */ removeDelete: (params: { data: T; }) => void; /** Adds an item to reads */ pushCreate: (params: { data: T; }) => void; /** Updates an item in reads */ pushUpdate: (params: { data: T; }) => void; /** Removes an item from reads */ pushDelete: (params: { data: T; }) => void; /** Discards all pending changes */ discard: () => void; }; /** * A hook that extends the functionality of useDataSource by adding support for remote data operations. * It enables you to connect to remote endpoints and perform CRUD operations while managing the data state locally. * * @template T - The type of data items in the data source * @param {RemoteDataSourceProps} props - The configuration options for the remote data source. * @returns {RemoteDataSource} An object containing all the properties and methods from useDataSource plus additional methods for interacting with remote data. */ export declare const useRemoteDataSource: (props: RemoteDataSourceProps) => RemoteDataSource;