import { Method } from 'axios'; import { Ref } from 'vue'; import { Resource, ResourceId, ResourceType } from './rest-collection-resources.js'; import { RestResourceStatus } from './stores/rest-resource-store.js'; /** Options that define a REST resource client. */ export 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; } export interface ConcreteRestResourceStoreOptionsInput { referencePathsToExpand?: string[]; resourceId?: ResourceId; resourceUrl?: string; } export interface RestResourceStoreOptionsInput { referencePathsToExpand?: string[] | ((resourceType: ResourceType) => string[]); resourceId?: ResourceId; resourceUrl?: string; } export interface MakeCustomApiRequestParams { method?: Method; subpath?: string; url?: string; data?: any; } /** * 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 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; } declare const _default: (params?: RestResourceOptions) => RestResourceClient; export default _default; //# sourceMappingURL=rest-resource.d.ts.map