@equinor/fusion-query
Version:
Reactive data fetching and caching library with observable streams and comprehensive event system
56 lines • 2.16 kB
JavaScript
import { v4 as generateGUID } from 'uuid';
import { createAction, createAsyncAction, } from '@equinor/fusion-observable';
const createActions = () => ({
/**
* Action to initiate a request.
*
* @param args - The arguments for the request.
* @param options - Optional parameters including a reference and retry options.
* @returns An action with the request details and metadata.
*/
request: createAction('client/request', (args, options) => ({
payload: { args, options },
meta: { transaction: generateGUID(), created: Date.now() },
})),
/**
* Async action to execute a request.
*
* @param transaction - The unique identifier for the transaction.
* @returns An async action with the transaction details and metadata.
*/
execute: createAsyncAction('client/execute', (transaction) => ({
payload: transaction,
meta: { transaction, created: Date.now() },
}), (result) => ({
payload: result,
meta: { transaction: result.transaction, created: Date.now() },
}), (error, transaction) => ({
payload: { error },
meta: { transaction, created: Date.now() },
})),
/**
* Action to cancel a request.
*
* @param transaction - The unique identifier for the transaction to cancel.
* @param reason - Optional reason for cancellation.
* @returns An action with the cancellation details and metadata.
*/
cancel: createAction('client/cancel', (transaction, reason) => ({
payload: { transaction, reason },
meta: { transaction, created: Date.now() },
})),
/**
* Action to report an error.
*
* @param transaction - The unique identifier for the transaction that errored.
* @param error - The error that occurred.
* @returns An action with the error details and metadata.
*/
error: createAction('client/error', (transaction, error) => ({
payload: { transaction, error },
meta: { transaction, created: Date.now() },
})),
});
export const actions = createActions();
export default actions;
//# sourceMappingURL=actions.js.map