1.0.1 • Published 10 months ago

@abdavid9207/paginator-adapter v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Paginator adapter

This is an adapter for various paginations between backend and frontend frameworks

Install: npm i @abdavid9207/paginator-adapter

How to use:

`
/**
 * TServerPagination is an interfaze with server pagination schema. 
 * TClientPagination is an interfaze with client pagination schema.
 */
const paginator = createPagination<TServerPagination, TClientPagination>(
    url: 'http://some.server.com',
    adapter: new QuasarAdapter(), //Or other adapter implemented for you.
    filters: [], //Optional.
    options: {} //Optional to.
)

//For Laravel and Quasar pagination use this.
const laravelPaginator = createLaravelQuasarPagination<TData>(
    url: 'http://laravel.server.com',
    filters: [], //Optional.
    options: {} //Optional to.
)`

An adapter is used to create the body of the request to the server. You can create any adapter. You just have to create a class that implements the interface Adapter<TClientPAginator>.

The paginator uses native javascript fetch to make the request. But you can use any http client by implementing the method onRequest.

For example, using axios:

`const paginator = createPagination(
    url: 'http://some.server.com',
    adapter: new QuasarAdapter(), //Or other adapter implemented for you.
    filters: [], //Optional.
    options: {
        /**
         * Filter can be empty array.
         */
        onRequest: (url: string, requestBody: Record<string, any>, filters: Filter[]): Promise<TServerPagination> => {

            requestBody.filters = JSON.stringify(filters)

            return axios.get(url, {
                data: requestBody
            })
        }
    }
)`
1.0.1

10 months ago

1.0.0

10 months ago