import { type Ref } from "vue"; import type { ModelType, Method, Service, ApiRoutedType, DataSourceType, ItemMethod, ListMethod, TypeDiscriminatorToType, PropNames } from "./metadata.js"; import { type Model, type DataSource } from "./model.js"; import { type VueInstance } from "./util.js"; import { type AxiosResponse, type AxiosRequestConfig } from "axios"; export type { AxiosPromise, AxiosRequestConfig } from "axios"; export { isAxiosError } from "axios"; export interface ApiResult { wasSuccessful: boolean; message?: string; } export interface ValidationIssue { property: string; issue: string; } export interface ItemResult extends ApiResult { object?: T; refMap?: { [key: string]: any; }; validationIssues?: ValidationIssue[]; } export interface ListResult extends ApiResult { list?: T[]; page?: number; pageSize?: number; pageCount?: number; totalCount?: number; } export interface DataSourceParameters { /** A string that the server may use to include/exclude certain data from the results. See Coalesce's full documentation for details. */ includes?: string | null; /** * A data source instance that will be used to load the data. * Classes are found in `models.g.ts` as `.DataSources.`, e.g. `Person.DataSources.WithRelations`. */ dataSource?: DataSource | null; /** If true, request that the server use System.Text.Json reference preservation handling when serializing the response, * which can significantly reduce the size of the response payload. This will also cause the resulting * `Model` and `ViewModel` instances on the client to be deduplicated. */ refResponse?: boolean; } export declare class DataSourceParameters { constructor(); } export interface SaveParameters = any> extends DataSourceParameters { /** * A list of field names to save. * If set, only the specified fields as well as any primary key * will be sent to the server. The server will ignore fields that are not set. */ fields?: PropNames[] | null; } export declare class SaveParameters> extends DataSourceParameters { constructor(); } export interface FilterParameters extends DataSourceParameters { /** A search term to search by. Searching behavior is determined by the server. */ search?: string | null; /** A collection of key-value pairs to filter by, * where keys are property names on the type and values are as follows: * - Strings will match exactly unless an asterisk is found in the filter, in which case they will be matched with `string.StartsWith` with the asterisk stripped out. - Numeric values will match exactly. Multiple comma-delimited values will create a filter that will match on any of the provided values. - Enums will match by string or numeric value. Multiple comma-delimited values will create a filter that will match on any of the provided values. - Dates with a time component will be matched exactly. - Dates with no time component will match any dates that fell on that day. - The values `null` and `"null"` match a `null` property value (except string properties). */ filter: { [fieldName: string]: string | number | boolean | null | undefined; }; } export declare class FilterParameters extends DataSourceParameters { constructor(); } export interface ListParameters extends FilterParameters { /** The page of data to request, starting at 1. */ page?: number | null; /** The number of items per page to request. */ pageSize?: number | null; /** If true, a total count of items will not be determined. `pageCount` and `totalCount` will be returned as -1. */ noCount?: boolean | null; /** * The name of a field to order the results by. If suffixed with " DESC", results will be sorted descending (same as using non-suffixed `orderByDescending`) * If this and `orderByDescending` are blank, default ordering determined by the server will be used. * */ orderBy?: string | null; /** * The name of a field to order the results by in descending order. * If this and `orderBy` are blank, default ordering determined by the server will be used. * */ orderByDescending?: string | null; /** * A list of field names to request. The results returned will only have these fields populated - all other fields will be null. */ fields?: string[] | null; } export declare class ListParameters extends FilterParameters { constructor(); } export type StandardParameters = ListParameters | FilterParameters | DataSourceParameters | SaveParameters; /** * Maps the given API standard parameters object into an flat object of key-value pairs * that is suitable for use as a URL querystring. * @param parameters The parameters to map. */ export declare function mapParamsToDto(parameters?: StandardParameters): { [s: string]: string; }; /** * Maps the given flat object of key-value pairs into an API parameters object. * @param dto The flat object to map. * @param parametersType The constructor of the parameters object to create. * @param modelClass The generated model class (containing a `DataSources` namespace) 1 */ export declare function mapQueryToParams(flatQuery: any, parametersType: new () => T, modelMeta: ModelType): T; export declare function getMessageForError(error: unknown): string; export type AxiosItemResult = AxiosResponse>; export type AxiosListResult = AxiosResponse>; export type ItemResultPromise = Promise>>; export type ListResultPromise = Promise>>; export type ApiResultPromise = Promise | AxiosListResult>; /** Axios instance to be used by all Coalesce API requests. Can be configured as needed. */ export declare const AxiosClient: import("axios").AxiosInstance; /** * Sets up detection of application version changes by monitoring the `X-App-Build` * response header on API responses. When the header value changes from the initially * observed value, `isUpdateAvailable` becomes true. * * On the server, call `app.UseAppVersionHeader()` to emit this header. * * @param axiosInstance The Axios instance to monitor. Defaults to the Coalesce `AxiosClient`. * @returns An object with an `isUpdateAvailable` ref that becomes true when a new version is detected. */ export declare function useAppUpdateCheck(axiosInstance?: import("axios").AxiosInstance): { isUpdateAvailable: Ref; }; export type ApiCallerConcurrency = "cancel" | "disallow" | "allow" | "debounce"; type ItemTransportTypeSpecifier = "item" | ItemMethod | ((methods: T["methods"]) => ItemMethod); type ListTransportTypeSpecifier = "list" | ListMethod | ((methods: T["methods"]) => ListMethod); type TransportTypeSpecifier = ItemTransportTypeSpecifier | ListTransportTypeSpecifier; type ResultType = T extends ItemTransportTypeSpecifier ? AxiosResponse> | TNonResult : T extends ListTransportTypeSpecifier ? AxiosResponse> | TNonResult : never; type ResultPromiseType = T extends ItemTransportTypeSpecifier ? Promise> | TNonResult> : T extends ListTransportTypeSpecifier ? Promise> | TNonResult> : never; type ApiCallerInvoker> = (this: any, client: TClient, ...args: TArgs) => TReturn; type ApiCallerArgsInvoker> = (this: any, client: TClient, args: TArgs) => TReturn; export type ApiStateType = T extends ItemTransportTypeSpecifier ? ItemApiState : T extends ListTransportTypeSpecifier ? ListApiState : never; export type ApiStateTypeWithArgs = T extends ItemTransportTypeSpecifier ? ItemApiStateWithArgs : T extends ListTransportTypeSpecifier ? ListApiStateWithArgs : never; export interface BulkSaveRequest { items: BulkSaveRequestItem[]; } export interface BulkSaveRequestItem { type: string; action: "save" | "delete" | "none"; root?: boolean; data: Record; refs?: Record; } export declare class ApiClient { $metadata: T; constructor($metadata: T); /** Flag to enable global caching of identical GET requests * that have been made simultaneously. */ protected _simultaneousGetCaching: boolean; /** Enable simultaneous request caching, causing identical GET requests made * at the same time across all ApiClient instances to be handled with the same AJAX request. * @deprecated Renamed to `$useSimultaneousRequestCaching`. */ $withSimultaneousRequestCaching(): this; /** Enable simultaneous request caching, causing identical GET requests made * at the same time across all ApiClient instances to be handled with the same AJAX request. */ $useSimultaneousRequestCaching(): this; /** Enable or disable ref response handling for the API client. * When enabled, requests will include the Accept header 'application/json+ref' * to use System.Text.Json reference preservation handling, which can significantly * reduce response sizes by deduplicating identical objects. */ $useRefResponse(enable?: boolean): this; /** * Create a wrapper function for an API call. This function maintains properties which represent the state of its previous invocation. * @param resultType An indicator of whether the API endpoint returns an ItemResult or a ListResult * @param invokerFactory method that will call the API. The signature of the function, minus the apiClient parameter, will be the call signature of the wrapper. */ $makeCaller>(resultType: TTransportType, invoker: ApiCallerInvoker | undefined | void, this>): ApiStateType; /** * Create a wrapper function for an API call. This function maintains properties which represent the state of its previous invocation. * @param resultType An indicator of whether the API endpoint returns an ItemResult or a ListResult * @param invokerFactory method that will call the API. The signature of the function, minus the apiClient parameter, will be the call signature of the wrapper. * @param invokerFactory method that will call the API with an args object as the only parameter. This may be called by using `.withArgs()` on the function that is returned from `$makeCaller`. The value of the args object will default to `.args` if not specified. */ $makeCaller>(resultType: TTransportType, invoker: ApiCallerInvoker | undefined | void, this>, argsFactory: () => TArgsObj, argsInvoker: ApiCallerArgsInvoker | undefined | void, this>): ApiStateTypeWithArgs; /** * Invoke the specified method using the provided set of parameters. * @param method The metadata of the API method to invoke * @param params The parameters to provide to the API method. * @param config A full `AxiosRequestConfig` to merge in. */ $invoke(method: TMethod, params: ParamsObject, config?: AxiosRequestConfig, standardParameters?: DataSourceParameters): Promise>>; private _observedRequests?; } export type ParamsObject = { [P in keyof TMethod["params"]]: TypeDiscriminatorToType | null | undefined; }; export declare class ModelApiClient> extends ApiClient { get(id: string | number | Date, parameters?: DataSourceParameters, config?: AxiosRequestConfig): ItemResultPromise; list(parameters?: Partial, config?: AxiosRequestConfig): ListResultPromise; count(parameters?: Partial, config?: AxiosRequestConfig): ItemResultPromise; save(item: TModel, parameters?: SaveParameters, config?: AxiosRequestConfig): ItemResultPromise; bulkSave(data: BulkSaveRequest, parameters?: DataSourceParameters, config?: AxiosRequestConfig): ItemResultPromise; delete(id: string | number | Date, parameters?: DataSourceParameters, config?: AxiosRequestConfig): ItemResultPromise; /** Value metadata for handling ItemResult returns from the standard API endpoints. */ private get $itemValueMeta(); /** Value metadata for handling ListResult returns from the standard API endpoints. */ private get $collectionValueMeta(); } export declare abstract class ServiceApiClient extends ApiClient { } type ApiStateHook = (this: any, state: TThis) => void | Promise; export type ResponseCachingConfiguration = { /** Function that will determine the cache key used for a particular request. * Return a falsy value to prevent caching. The default key is the request URL. */ key?: (req: AxiosRequestConfig, defaultKey: string) => string | null | undefined; /** The maximum age of a cached response. If null, the entry will not expire. Default 1 hour. * * The smallest of the current configured max age and the max age that was set at the time of the cached response is used. */ maxAgeSeconds?: number | null; /** The Storage (default `sessionStorage`) that will hold cached responses. */ storage?: Storage; }; declare abstract class ApiStateBase { /** Invokes a call to this API endpoint. */ readonly invoke: this; protected readonly apiClient: ApiClient; protected readonly invoker: ApiCallerInvoker | undefined | void, ApiClient>; protected abstract _invokeInternal(thisArg: any, invoker: Function, args: any[]): Promise | ListResult>; protected _pendingPromise: Promise | undefined; constructor(apiClient: ApiClient, invoker: ApiCallerInvoker | undefined | void, ApiClient>); } export declare abstract class ApiState extends ApiStateBase { /** The metadata of the method being called, if it was provided. */ abstract $metadata?: Method; abstract result: TResult | TResult[] | null; private readonly __isLoading; /** True if a request is currently pending. */ get isLoading(): boolean; set isLoading(v: boolean); private readonly __wasSuccessful; /** True if the previous request was successful. */ get wasSuccessful(): boolean | null; set wasSuccessful(v: boolean | null); private readonly __message; /** Error message returned by the previous request. */ get message(): string | null; set message(v: string | null); private readonly __hasResult; /** Whether `.result` is null or not. * Using this prop to check for a result avoids a subscription * against the whole result object, which will change each time the method is called. */ get hasResult(): boolean; set hasResult(v: boolean); private readonly __rawResponse; /** The raw axios response returned by the previous request. * Can be used to read headers and other HTTP data from the response. */ get rawResponse(): AxiosResponse | ListResult, any, {}> | undefined; /** Reset all state fields of the instance. * Does not reset configuration like response caching and concurrency mode. */ reset(): void; private __responseCacheConfig?; /** * Enable response caching for the API caller, * saving previous responses to persistent storage (default: `sessionStorage`) so they can later * be used to populate `result` when an identical request is made but before any initial network response is received. * * Response caching does not prevent any HTTP requests from being made, but instead * will temporarily load an old response while the fresh response is being fetched. * * Do not use for any endpoint that could contain sensitive data. */ useResponseCaching(configuration?: ResponseCachingConfiguration | false): this; protected _simultaneousGetCaching: boolean; /** Enable simultaneous request caching for the API caller, * causing all identical GET requests made with this setting enabled * to be handled with the same AJAX request. */ useSimultaneousRequestCaching(): this; protected _refResponse?: boolean; /** Enable or disable ref response handling for the API caller. * When enabled, requests will include the Accept header 'application/json+ref' * to use System.Text.Json reference preservation handling, which can significantly * reduce response sizes by deduplicating identical objects. * @param enable Whether to enable ref response handling. Default is true. */ useRefResponse(enable?: boolean): this; private _concurrencyMode; /** * Set the concurrency mode for this API caller. Default is "disallow". * @param mode Behavior for when a request is made while there is already an outstanding request. * * "cancel" - Cancel the outstanding request first. * * "debounce" - if a request is made while one is outstanding, enqueue it to start after the outstanding * request is done. If another request is made while one is already enqueued, the enqueued request is abandoned * and replaced by the last request that was made. * * "disallow" - Throw an error. * * "allow" - Permit the second request to be made. The ultimate values of the state fields may not be representative of the last request made. */ setConcurrency(mode: ApiCallerConcurrency): this; /** * Get or set the concurrency mode for this API caller. Default is "disallow". * @param mode Behavior for when a request is made while there is already an outstanding request. * * "cancel" - cancel the outstanding request first. * * "debounce" - if a request is made while one is outstanding, enqueue it to start after the outstanding * request is done. If another request is made while one is already enqueued, the enqueued request is abandoned * and replaced by the last request that was made. * * "disallow" - throw an error. * * "allow" - permit the second request to be made. The ultimate state of the state fields may not be representative of the last request made. */ get concurrencyMode(): ApiCallerConcurrency; set concurrencyMode(val: ApiCallerConcurrency); private _cancelToken; /** * Function that can be called to cancel a pending request. */ cancel(): void; /** Invoke a call to the API endpoint after an affirmative confirmation from the user. */ confirmInvoke(message: string, ...args: TArgs): Promise | undefined; private _callbacks; /** * Attach a callback to be invoked when the request to this endpoint succeeds. * @param callback A callback to be called when a request to this endpoint succeeds. */ onFulfilled(callback: ApiStateHook): this; /** * Attach a callback to be invoked when the request to this endpoint fails. * @param callback A callback to be called when a request to this endpoint fails. */ onRejected(callback: ApiStateHook): this; protected abstract setResponseProps(data: ApiResult): void; private _debounceSignal; protected _invokeInternal(thisArg: any, invoker: Function, args: any[]): Promise; constructor(apiClient: ApiClient, invoker: ApiCallerInvoker | undefined | void, ApiClient>); } export interface ItemApiState { (...args: TArgs): Promise; } export declare class ItemApiState extends ApiState { /** The metadata of the method being called, if it was provided. */ $metadata?: TMethod; /** * Returns the promise of the currently pending request, * or `undefined` if no request is pending. */ getPromise(): Promise | undefined; private readonly __validationIssues; /** Validation issues returned by the previous request. */ get validationIssues(): { property: string; issue: string; }[] | null; set validationIssues(v: { property: string; issue: string; }[] | null); private readonly __result; /** Principal data returned by the previous request. */ get result(): TResult | null; set result(v: TResult | null); get rawResponse(): AxiosResponse>; constructor(apiClient: ApiClient, invoker: ApiCallerInvoker | undefined | void, ApiClient>); reset(): void; private _objectUrl?; /** If the result is a blob or file, returns an Object URL representing that result. * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL * @param vue A Vue instance through which the lifecycle of the object URL will be managed. */ getResultObjectUrl(vue?: VueInstance | null | undefined): undefined | (TResult extends Blob ? string : never); protected setResponseProps(data: ItemResult): void; } export declare class ItemApiStateWithArgs extends ItemApiState { private argsFactory; private argsInvoker; private readonly __args; /** Values that will be used as arguments if the method is invoked with `this.invokeWithArgs()`. */ get args(): TArgsObj; set args(v: TArgsObj); reset(resetArgs?: boolean): void; /** Invokes a call to this API endpoint. * If `args` is not provided, the values in `this.args` will be used for the method's parameters. */ invokeWithArgs(args?: TArgsObj): Promise; /** Replace `this.args` with a new, blank object containing default values (typically nulls) */ resetArgs(): void; /** Invoke a call to the API endpoint after an affirmative confirmation from the user. * If `args` is not provided, the values in `this.args` will be used for the method's parameters. */ confirmInvokeWithArgs(message: string, args?: TArgsObj): Promise | undefined; /** Returns the URL for the endpoint, including querystring parameters, if invoked using `this.args`. */ get url(): string | null; constructor(apiClient: ApiClient, invoker: ApiCallerInvoker, ApiClient>, argsFactory: () => TArgsObj, argsInvoker: ApiCallerArgsInvoker, ApiClient>); } export interface ListApiState { /** Invokes a call to this API endpoint. */ (...args: TArgs): Promise; } export declare class ListApiState extends ApiState { /** The metadata of the method being called, if it was provided. */ $metadata?: TMethod; /** * Returns the promise of the currently pending request, * or `undefined` if no request is pending. */ getPromise(): Promise | undefined; private readonly __page; /** Page number returned by the previous request. */ get page(): number | null; set page(v: number | null); private readonly __pageSize; /** Page size returned by the previous request. */ get pageSize(): number | null; set pageSize(v: number | null); private readonly __pageCount; /** Page count returned by the previous request. */ get pageCount(): number | null; set pageCount(v: number | null); private readonly __totalCount; /** Total Count returned by the previous request. */ get totalCount(): number | null; set totalCount(v: number | null); private readonly __result; /** Principal data returned by the previous request. */ get result(): TResult[] | null; set result(v: TResult[] | null); get rawResponse(): AxiosResponse>; constructor(apiClient: ApiClient, invoker: ApiCallerInvoker | undefined | void, ApiClient>); reset(): void; protected setResponseProps(data: ListResult): void; } export declare class ListApiStateWithArgs extends ListApiState { private argsFactory; private argsInvoker; private readonly __args; /** Values that will be used as arguments if the method is invoked with `this.invokeWithArgs()`. */ get args(): TArgsObj; set args(v: TArgsObj); reset(resetArgs?: boolean): void; /** Invokes a call to this API endpoint. * If `args` is not provided, the values in `this.args` will be used for the method's parameters. */ invokeWithArgs(args?: TArgsObj): Promise; /** Replace `this.args` with a new, blank object containing default values (typically nulls) */ resetArgs(): void; /** Invoke a call to the API endpoint after an affirmative confirmation from the user. * If `args` is not provided, the values in `this.args` will be used for the method's parameters. */ confirmInvokeWithArgs(message: string, args?: TArgsObj): Promise | undefined; constructor(apiClient: ApiClient, invoker: ApiCallerInvoker, ApiClient>, argsFactory: () => TArgsObj, argsInvoker: ApiCallerArgsInvoker, ApiClient>); } export type AnyArgCaller = ListApiStateWithArgs | ItemApiStateWithArgs; declare module "@vue/reactivity" { interface RefUnwrapBailTypes { coalesceApiModels: ApiState | ApiClient; } }