import { Ref } from 'vue'; import { Resource, ResourceId, ResourceType } from './rest-collection-resources.js'; import { RestCollectionStatus } from './stores/rest-collection-store.js'; /** Options that define a REST collection. */ export interface RestCollectionOptions { /** * The REST collection's unique identifier, which will be used as the ID of its Pinia store. * * This is normally generated, and the generated ID may be accessed using the collection's {@link collectionId} * property. * * There are two circumstances where you may want to specify a collection ID: * 1. You have already created a collection and want to give another Vue component access to it. In this case, pass * the value of the collection's {@link collectionId} property in the options to the second component's * {@link useRestCollection} call. * 2. You want to assign a canonical ID to the collection, so that components can call {@link useRestCollection} to * create it or to access it if it already exists. In this case, you can assign the ID manually, but you must ensure * that it does not conflict with any other Pinia store IDs used in the Vue application. * * - If not specified, an unique ID will be generated. * - If specified, the REST collection will check whether a Pinia store with this ID already exists. * - If one exists, that store will be used, and other options will be ignored. This is a way to have multiple * components' {@link RestCollection}s share a single data store. * - If a Pinia store does not exist, then when creating a new collection, the ID will be used instead of generating * a new unique ID. */ collectionId?: string; draftBatchId?: string; enabled?: boolean; /** The resource type. */ resourceType?: Ref | ResourceType | undefined; /** Options that govern the behavior of the REST collections's data store module. */ options?: RestCollectionStoreOptionsInput; } export interface ConcreteRestCollectionStoreOptionsInput { detail?: { allowMultiple?: boolean; autoEdit?: boolean; autoFromMultipleSelection?: boolean; autoFromSingleInsertion?: boolean; autoFromSingleSelection?: boolean; constrainToSelection?: boolean; }; filter?: { namedFilter?: string | null; query?: any | null; resourceIds?: ResourceId[] | null; }; limit?: number | null; limitTransientDataToLocalCollection?: boolean; loadId?: string | null; loading?: { firstPageSize?: number | null; pageSize?: number | null; }; order?: [any, string][]; propertiesToExclude?: string[]; referencePathsToExpand?: string[]; restCollectionUrl?: string | null; } export interface RestCollectionStoreOptionsInput { detail?: { allowMultiple?: boolean; autoEdit?: boolean; autoFromMultipleSelection?: boolean; autoFromSingleInsertion?: boolean; autoFromSingleSelection?: boolean; constrainToSelection?: boolean; }; filter?: { namedFilter?: string | null; query?: any | null | ((resourceType: ResourceType) => any | null); resourceIds?: ResourceId[] | null; }; limit?: number | null; limitTransientDataToLocalCollection?: boolean; loadId?: string | null; loading?: { firstPageSize?: number | null; pageSize?: number | null; }; order?: [any, string][]; propertiesToExclude?: string[] | ((resourceType: ResourceType) => string[]); referencePathsToExpand?: string[] | ((resourceType: ResourceType) => string[]); restCollectionUrl?: string | null; } export interface LoadResourcesParams { firstPageSize?: number; pageSize?: number; } export interface SelectResourcesOptions { addToSelection?: boolean; edit?: boolean; } /** Parameters to {@link RestCollection.setTransientDataForResources} */ export interface SetTransientDataParams { /** Transient data keyed by resource ID. */ transientData: { /** Transient data for one resource. */ [resourceId: ResourceId]: object; }; /** * Flag indicating whether new transient data should replace existing transient data for each resource or be merged * with it. */ merge?: boolean; } export type RestCollectionStoreReadyCallback = (() => void) | (() => Promise); /** * A REST collection. * * This represents a collection of resources (records) fetched from a REST API. Most commonly, it represents all the * resources from one collection endpoint of the REST API; but filters can be added when using a REST API that supports * them. */ export interface RestCollection { /** * The REST collection's unique ID, which is used as the ID of its Pinia store. * * If you want to share the store with another component, you can pass this ID when creating the second component's * {@link RestCollection}. */ collectionId: Ref; /** The draft batch ID, if one was passed in {@link RestCollectionOptions.draftBatchId}. */ draftBatchId: Ref; /** A flag indicating whether accessing the local collection will fetch data from the remote collection. */ enabled: Ref; /** * The resource type for this collection. * * To allow for asynchronous loading of resource types, this may be undefined. */ resourceType: Ref; /** * The REST collection URL. * * This is reported by the actual Pinia store. It may be arrived at in three ways: * - It may have been specified in {@link RestCollectionOptions.options}. * - It may have been calculated from the entity type and draft batch ID. This is the most common scenario. * - Or this RestCollection may reference an existing store, in which case the URL was determined by the collection * that originally created the store. * * It defaults to null when no store is present. */ restCollectionUrl: Ref; /** A status indicating whether resources have been loaded yet from the REST API. */ status: Ref; batchSaveAttempted: Ref; listNavigators: { [name: string]: any; }; /** * An array of resources that have failed validation. The client must manage this list by calling * {@link setInvalidResourceIds} **/ invalidResources: Ref; /** The array of resources that have been loaded from the REST API into the local collection. */ resources: Ref; /** The total number of resources available in the remote collection. */ remoteCollectionSize: Ref; /** Transient data that a client has associated with the resources via {@link setTransientDataForResources}. */ transientData: Ref; /** Resources in the current detail view, a sublist of {@link resources}. */ detailSelection: Ref; /** A flag indicating whether the detail selection is currently being edited or only displayed. */ editingDetailSelection: Ref; /** The current selection, a sublist of {@link resources}. */ selection: Ref; /** * Apply new configuration options. * * The result is much like creating a new RestCollection, except that the client can continue using the same * properties. * * @param options New options to apply. */ reconfigureCollection: (options: RestCollectionOptions) => void; setEditingDetailSelection: (editingDetailSelection: boolean) => void; setEnabled: (enabled: boolean) => void; /** * Set filter consisting of a list of resource IDs to fetch from the collection. * * This relies on a filtering request format that is not a part of the informal REST standard, so use of this method * should be limited to APIs that adhere to our extended REST standard, i.e. TODO. * * If the previous state was anything other than NotLoaded, the collection will be immediately refreshed as if the * client had called {@link loadResources}. Calls made with await will return once the first page of results have * loaded or failed (just as when you call {@link loadResources} with await). * * @param filterResourceIds The list if resource IDs to fetch from the REST collection. * @return A promise that resolves when the first page of resources is loaded, or immediately if the collection does * not need to be reloaded. */ setFilterResourceIds: (filterResourceIds: ResourceId[]) => Promise; /** * Apply a new filter query. * * Since filter queries are not a part of the informal REST standard, use of this method should be limited to APIs * that adhere to our extended REST standard, i.e. TODO. * * If the previous state was anything other than NotLoaded, the collection will be immediately refreshed as if the * client had called {@link loadResources}. Calls made with await will return once the first page of results have * loaded or failed (just as when you call {@link loadResources} with await). * * @param query The query for filtering the REST collection. This will be sent to the REST API as a query parameter. */ setQuery: (query: any | null | ((resourceType: ResourceType) => any | null)) => Promise; /** * Ensure that a Pinia store has been created for this REST collection. * * This does not normally need to be called, because it will happen automatically when the {@link RestCollection} is * created and when {@link collectionId}, {@link resourceType}, or options change. * * @return true if the store has been created or replaced. (Note that false does not indicate that the store does not * exist.) */ ensureStore: () => boolean; setBatchSaveAttempted: (batchSaveAttempted: boolean) => void; /** Return the {@link RestCollection} to the NotLoaded state, where no resources have been fetched yet. */ clear: () => void; /** * Fetch the collection from the REST API, if this has not happened yet. * * A client that observes changes to the reactive property {@link resources} should never need to call this. * * @return A promise that resolves when the first page of results have loaded or loading has failed. */ ensureCollectionLoaded: () => Promise; /** * Fetch the collection from the REST API. * * A client that observes changes to the reactive property {@link resources} should never need to call this. * * If you call this with await, the call will return once the first page of results have loaded or failed. * * @param payload Parameters governing page size. * @return A promise that resolves when the first page of results have loaded or loading has failed. */ loadResources: (params: LoadResourcesParams) => Promise; /** * Start editing a new resource, whose properties are all undefined except for any passed in the parameter. * * @param resourceDefaults An object containing initial property values for the new resource. */ addResource: (resourceDefaults?: T) => void; checkForDeletedResource: (resourceId: ResourceId) => Promise; recordDeletion: (resourceId: ResourceId) => void; recordInsertion: (resource: T, { insertAtBeginning, transientData }?: { insertAtBeginning?: boolean; transientData?: any; }) => void; recordUpdate: (resource: T) => void; /** * Refresh one resource by fetching it again from the REST API. * * If you call this with await, it will return once the API call has completed. * * @param resourceId The ID of the resource to refresh. */ refreshResource: (resourceId: ResourceId) => Promise; /** * Delete one resource. * * If you call this with await, it will return once the API call has completed. * * @param resourceId The ID of the resource to delete. */ deleteResource: (resourceId: ResourceId) => Promise; /** * Save one resource (new or updated). * * The resource will be updated if it has a resource ID, created if not. * * If you call this with await, it will return once the API call has completed, and if the APi call succeeded, it will * return the newly saved item. * * @param resource The resource to create or update. */ saveResource: (resource: T) => Promise; /** * Save multiple resources (new or updated). * * Each resource will be updated if it has a resource ID, created if not. * * If you call this with await, it will return once the API call has completed, and if the APi call succeeded, it will * return the newly saved item. * * @param params TODO */ saveResources: (resources: T[]) => Promise; /** * Partial update of one resource. * * If you call this with await, it will return once the API call has completed, and if the APi call succeeded, it will * return the newly saved item. * * @param partialResource The partial resource to update. */ updateResource: (partialResource: T) => Promise; /** * Partial update of multiple resources. * * If you call this with await, it will return once the API call has completed, and if the APi call succeeded, it will * return the saved items. * * @param partialResources The partial resources to update. */ updateResources: (partialResources: T[]) => Promise; /** * Record which resources have failed validation. * * The REST collection does not interact directly with any validation code. The ability to record which resources * failed validation is purely a convenience for clients that want to store this information. To store more complex * information about validation, consider setting transient data associated with resources. * * @param resourceIds The IDs of all resources that failed validation. */ setInvalidResourceIds: (resourceIds: ResourceId[]) => void; /** Clear all transient data associated with resources. */ clearTransientData: () => void; /** * Associate transient data with REST resources that have been fetched from the API. * * @param params Parameters, including transient data for zero or more resources, keyed by resource ID. */ setTransientDataForResources: (params: SetTransientDataParams) => void; clearSelection: () => void; deselectResources: (resourceIds: ResourceId[]) => void; selectResources: (resourceIds: ResourceId[], options?: SelectResourcesOptions) => void; hideDetail: () => void; deregisterEditor: (editor: any) => void; registerEditor: (editor: any) => void; deregisterListNavigator: ({ name, listNavigator }: { name: string; listNavigator: any; }) => void; registerListNavigator: ({ name, listNavigator }: { name: string; listNavigator: any; }) => void; onItemsStoreReady: (callback: RestCollectionStoreReadyCallback) => void; } declare const _default: (params?: RestCollectionOptions) => RestCollection; export default _default; export declare const clearAllRestCollections: () => void; //# sourceMappingURL=rest-collection.d.ts.map