import { Method } from 'axios'; import { Ref } from 'vue'; export declare class ApiClientError extends Error { context: object | undefined; innerError: any; constructor(message: any, context?: object | undefined, innerError?: any); } export declare const clearAllRestCollections: () => void; export declare 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 declare interface ConcreteRestResourceStoreOptionsInput { referencePathsToExpand?: string[]; resourceId?: ResourceId; resourceUrl?: string; } export declare function initRestClient(config: RestClientConfigInput): void; export declare interface LoadResourcesParams { firstPageSize?: number; pageSize?: number; } export declare interface MakeCustomApiRequestParams { method?: Method; subpath?: string; url?: string; data?: any; } /** A resource from a REST collection. */ export declare type Resource = object; /** * A primary key value identifying a resource within its collection. * * Every resource must have an ID, which is currently assumed to be stored in its _id property. */ export declare type ResourceId = T; /** A subcollection belonging to each resource of a certain type. */ export declare interface ResourceSubcollection { /** The subcollection name, which is used in constructing its path. */ name: string; /** The resource type of subcollection members. */ type: ResourceType; } /** A REST resource type, i.e. a description of items in one REST collection. */ export declare interface ResourceType { /** The REST collection name, which is used in constructing its path. */ collectionName: string; /** The property path (in dot notation) for each resource's primary key. */ idProperty?: string; /** Subcollections of each resource. */ subcollections?: ResourceSubcollection[]; /** Custom data attached by the client. */ custom?: { [key: string]: any; }; } export declare const restClient: { config: RestClientConfig; }; declare interface RestClientConfig extends RestClientConfigInput { apiBaseUrl: string; useVueLogger: boolean; } declare interface RestClientConfigInput { apiBaseUrl?: string; useVueLogger?: boolean; } /** * 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 declare 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; } /** Options that define a REST collection. */ export declare 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 declare type RestCollectionOrder = any; export declare type RestCollectionQuery = any; declare type RestCollectionStatus = 'Uninitialized' | 'NotLoaded' | 'Loading' | 'LoadingMore' | 'Loaded' | 'Failed'; export declare 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 declare type RestCollectionStoreReadyCallback = (() => void) | (() => Promise); /** * A REST resource client. * * This represents one resource fetched from a REST API. More commonly, clients will use a {@link RestCollection}, but * {@link RestResourceClient} is sometimes useful for consuming individual responses from APIs that are not really * RESTful. */ export declare interface RestResourceClient { /** * The REST resource client's unique identifier, which is 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 RestResourceClient}. */ resourceClientId: 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; /** A status indicating whether resources have been loaded yet from the REST API. */ status: Ref; /** The local version of the resource loaded from the REST API. */ resource: Ref; /** The ID of the REST resource. */ resourceId: Ref; /** The URL of the REST resource. */ resourceUrl: 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. */ reconfigureClient: (options: RestResourceOptions) => void; setEnabled: (enabled: boolean) => void; setResourceId: (resourceId: ResourceId | null) => Promise; setResourceUrl: (resourceUrl: string | null) => Promise; /** * Ensure that a Pinia store has been created for this REST resource. * * This does not normally need to be called, because it will happen automatically when the {@link RestResourceClient} * is created and when {@link resourceClientId}, {@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; /** Return the {@link RestResourceClient} to the NotLoaded state, where no resource has been fetched yet. */ clear: () => void; /** * Fetch the resource from the REST API, if this has not happened yet. * * A client that observes changes to the reactive property {@link resource} should never need to call this. * * @return A promise that returns when the resource has loaded or loading has failed. */ ensureResourceLoaded: () => Promise; /** * Load the resource from the REST API. * * A client that observes changes to the reactive property {@link resource} should never need to call this. * * @return A promise that returns when the resource has loaded or loading has failed. */ loadResource: () => 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. */ checkForDeletedResource: () => Promise; recordDeletion: () => void; recordInsertion: (resource: T) => void; recordUpdate: (resource: T) => void; refreshResource: () => Promise; deleteResource: () => Promise; saveResource: (resource: T) => Promise; updateResource: (partialResource: T) => Promise; makeCustomApiRequest: (params: MakeCustomApiRequestParams) => Promise; } /** Options that define a REST resource client. */ export declare interface RestResourceOptions { /** * The REST resource client'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 resource client's * {@link resourceClientId} property. * * There are two circumstances where you may want to specify a resource client ID: * 1. You have already created a resource client and want to give another Vue component access to it. In this case, * pass the value of the collection's {@link resourceClientId} property in the options to the second component's * {@link useRestResource} call. * 2. You want to assign a canonical ID to the client, so that components can call {@link useRestResrouce} 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 resource client 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 RestResource}s share a single data store. * - If a Pinia store does not exist, then when creating a new resource client, the ID will be used instead of * generating a new unique ID. */ resourceClientId?: string; draftBatchId?: string; enabled?: boolean; /** The resource type. */ resourceType?: Ref | ResourceType | undefined; /** Options that govern the behavior of the REST resource's data store module. */ options?: RestResourceStoreOptionsInput; } declare type RestResourceStatus = 'Uninitialized' | 'NotLoaded' | 'Loading' | 'Loaded' | 'Failed'; export declare interface RestResourceStoreOptionsInput { referencePathsToExpand?: string[] | ((resourceType: ResourceType) => string[]); resourceId?: ResourceId; resourceUrl?: string; } export declare interface SelectResourcesOptions { addToSelection?: boolean; edit?: boolean; } /** Parameters to {@link RestCollection.setTransientDataForResources} */ export declare 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 declare const useRestCollection: (params?: RestCollectionOptions) => RestCollection; export declare const useRestResource: (params?: RestResourceOptions) => RestResourceClient; export { }