import { Resource, ResourceId } from '../rest-collection-resources.js'; import { MakeCustomApiRequestParams } from '../rest-resource.js'; import { StoreRegistry } from '../rest-store-registry.js'; /** Options that govern the behavior of a REST resource data store. */ export interface RestResourceStoreOptions { idProperty: string; resourceId?: ResourceId; restCollectionUrl?: string; resourceUrl?: string | null; referencePathsToExpand?: string[]; } /** Default options that govern the behavior of a REST resource data store */ export declare const DEFAULT_REST_RESOURCE_STORE_OPTIONS: RestResourceStoreOptions; export type RestResourceStatus = 'Uninitialized' | 'NotLoaded' | 'Loading' | 'Loaded' | 'Failed'; export type RestResourceStoreStatus = 'NotLoaded' | 'Loading' | 'Loaded' | 'Failed'; /** A REST collection's state, including settings and contents. */ export interface RestResourceStoreState { idProperty: string; resourceId: ResourceId | null; resourceUrl: string | null; resource: Resource | null; status: RestResourceStoreStatus; referencePathsToExpand: string[] | null; _loadId?: string; } interface RestResourceQueryParams { /** Deterministically JSON-serialized array of path strings to expand. */ r?: string; } declare const makeStore: (storeId: string, options: RestResourceStoreOptions) => import("pinia").StoreDefinition) => string | null; /** Get the REST query parameters that can be determined from the options. */ fixedQueryParams: (state: { idProperty: string; resourceId: ResourceId | null; resourceUrl: string | null; resource: Resource | null; status: RestResourceStoreStatus; referencePathsToExpand: string[] | null; _loadId?: string | undefined; } & import("pinia").PiniaCustomStateProperties) => RestResourceQueryParams; }, { /** * Reset the store to its initial state. * * Configuration is retained, but REST resource content and contextual state are reset. */ reset(): void; setResourceId(resourceId: ResourceId | null): Promise; setResourceUrl(resourceUrl: string | null): Promise; /** * Clear the resource. * * Configuration and contextual state are retained, but REST collection contents are reset. */ clear(): void; /** * Load the resource, if it has not been loaded. * * The resource will be loaded if its current status is not Loaded, Loading, or Failed. */ ensureResourceLoaded(): Promise; /** * Load the resource. * * @return A promise that resolves when the resource has been loaded. */ loadResource(): Promise; /** * Verify that the resource does not exist in the remote collection. * * After checking the remote collection and verifying that the resource does not exist, this function calls * {@link recordDeletion} to delete it from the local collection. * * @return true if the record does not exist in the remote collection, false if it does or if an error occurred. */ checkForDeletedResource(): Promise; /** * Record a deletion, removing the deleted resource from the local collection. * * This should be called after deleting the resource from the remote collection. It is called, for instance, by * {@link deleteResource}; but it can also be called when the application is aware of a deletion from the remote * collection made by other means. */ recordDeletion(): void; /** * Record an insertion, adding the inserted resource to the local collection. * * This should be called after inserting a resource into the remote collection. It is called, for instance, by * {@link saveResource}; but it can also be called when the application is aware of insertions into the remote * collection made by other means. * * This should only be called if the inserted resource is a saved version of the resource tracked by this store. * Otherwise the store's resource may not match its resourceId and resourceUrl properties when the function * returns. * * It is important that the resources to be added to the local collection have the same object-graph * characteristics as other resources in the local collection. (These characteristics include property inclusions * and exclusions, as well as reference expansions.) To ensure this, you may call {@refreshResource} to fetch the * resource using the collection's settings. * * @param resource The resource that has been inserted. */ recordInsertion(resource: Resource): void; /** * Record an update, making the same changes in the local resource. * * This should be called after updating a remote resource. It is called, for instance, by {@link saveResource} and * {@link refreshResource}; but it can also be called when the application is aware of updates in the remote * collection made by other means. * * This should only be called if the inserted resource is a saved version of the resource tracked by this store. * Otherwise the store's resource may not match its resourceId and resourceUrl properties when the function * returns. * * It is important that the resource have the same object-graph characteristics as other resources in the local * collection. (These characteristics include property inclusions and exclusions, as well as reference * expansions.) To ensure this, you may instead call {@refreshResource} to fetch the resource using the * collection's settings; this will in turn call {@link recordUpdate}. * * @param resource The resource that has been updated. */ recordUpdate(resource: Resource): void; refreshResource(): Promise; /** * Delete the resource. * * A delete request is sent to the REST API. If it succeeds, the resource is removed from the local store. */ deleteResource(): Promise; /** * Write a new or updated resource to the remote resource, then mirror the change locally. * * After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the * return value) has the same object-graph characteristics as the rest of the local collection. * * @param resource The new or updated resource. If it has an ID, an update will be attempted; otherwise it will be * created. * @returns The refreshed local resource after the change has been persisted to the remote collection, or null if * the operation failed. */ saveResource(resource: Resource): Promise; /** * Update only the specified properties of the remote resource, then mirror the change locally. * * After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the * return value) has the same object-graph characteristics as the rest of the local collection. * * @param partialResource The partial resource to merge. * @returns The refreshed local resource after the change has been persisted to the remote collection, or null if * the operation failed. */ updateResource(partialResource: Resource): Promise; makeCustomApiRequest(params: MakeCustomApiRequestParams): Promise; }>; export type RestResourceStore = ReturnType>; export declare const storeRegistry: StoreRegistry) => string | null; /** Get the REST query parameters that can be determined from the options. */ fixedQueryParams: (state: { idProperty: string; resourceId: ResourceId | null; resourceUrl: string | null; resource: Resource | null; status: RestResourceStoreStatus; referencePathsToExpand: string[] | null; _loadId?: string | undefined; } & import("pinia").PiniaCustomStateProperties) => RestResourceQueryParams; }, { /** * Reset the store to its initial state. * * Configuration is retained, but REST resource content and contextual state are reset. */ reset(): void; setResourceId(resourceId: ResourceId | null): Promise; setResourceUrl(resourceUrl: string | null): Promise; /** * Clear the resource. * * Configuration and contextual state are retained, but REST collection contents are reset. */ clear(): void; /** * Load the resource, if it has not been loaded. * * The resource will be loaded if its current status is not Loaded, Loading, or Failed. */ ensureResourceLoaded(): Promise; /** * Load the resource. * * @return A promise that resolves when the resource has been loaded. */ loadResource(): Promise; /** * Verify that the resource does not exist in the remote collection. * * After checking the remote collection and verifying that the resource does not exist, this function calls * {@link recordDeletion} to delete it from the local collection. * * @return true if the record does not exist in the remote collection, false if it does or if an error occurred. */ checkForDeletedResource(): Promise; /** * Record a deletion, removing the deleted resource from the local collection. * * This should be called after deleting the resource from the remote collection. It is called, for instance, by * {@link deleteResource}; but it can also be called when the application is aware of a deletion from the remote * collection made by other means. */ recordDeletion(): void; /** * Record an insertion, adding the inserted resource to the local collection. * * This should be called after inserting a resource into the remote collection. It is called, for instance, by * {@link saveResource}; but it can also be called when the application is aware of insertions into the remote * collection made by other means. * * This should only be called if the inserted resource is a saved version of the resource tracked by this store. * Otherwise the store's resource may not match its resourceId and resourceUrl properties when the function * returns. * * It is important that the resources to be added to the local collection have the same object-graph * characteristics as other resources in the local collection. (These characteristics include property inclusions * and exclusions, as well as reference expansions.) To ensure this, you may call {@refreshResource} to fetch the * resource using the collection's settings. * * @param resource The resource that has been inserted. */ recordInsertion(resource: Resource): void; /** * Record an update, making the same changes in the local resource. * * This should be called after updating a remote resource. It is called, for instance, by {@link saveResource} and * {@link refreshResource}; but it can also be called when the application is aware of updates in the remote * collection made by other means. * * This should only be called if the inserted resource is a saved version of the resource tracked by this store. * Otherwise the store's resource may not match its resourceId and resourceUrl properties when the function * returns. * * It is important that the resource have the same object-graph characteristics as other resources in the local * collection. (These characteristics include property inclusions and exclusions, as well as reference * expansions.) To ensure this, you may instead call {@refreshResource} to fetch the resource using the * collection's settings; this will in turn call {@link recordUpdate}. * * @param resource The resource that has been updated. */ recordUpdate(resource: Resource): void; refreshResource(): Promise; /** * Delete the resource. * * A delete request is sent to the REST API. If it succeeds, the resource is removed from the local store. */ deleteResource(): Promise; /** * Write a new or updated resource to the remote resource, then mirror the change locally. * * After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the * return value) has the same object-graph characteristics as the rest of the local collection. * * @param resource The new or updated resource. If it has an ID, an update will be attempted; otherwise it will be * created. * @returns The refreshed local resource after the change has been persisted to the remote collection, or null if * the operation failed. */ saveResource(resource: Resource): Promise; /** * Update only the specified properties of the remote resource, then mirror the change locally. * * After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the * return value) has the same object-graph characteristics as the rest of the local collection. * * @param partialResource The partial resource to merge. * @returns The refreshed local resource after the change has been persisted to the remote collection, or null if * the operation failed. */ updateResource(partialResource: Resource): Promise; makeCustomApiRequest(params: MakeCustomApiRequestParams): Promise; }>>; export default makeStore; //# sourceMappingURL=rest-resource-store.d.ts.map