npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@libvue/laravel-orion-api

v0.0.17

Published

A Laravel Orion compatible repository-based Javascript http-client powered by axios.

Downloads

58

Readme

laravel-orion-api

license coverage npm (tag)

A Laravel Orion compatible repository-based Javascript http-client powered by axios.

Install

> npm install --save @libvue/laravel-orion-api

Setup

Create a BaseRepository

// BaseRepository.js
import { LaravelOrionAPI } from "@libvue/laravel-orion-api";

class BaseRepository extends LaravelOrionAPI {
    constructor() {
        // If you want to use a custom axios config, use super(yourAxiosConfig), else just use super()
        super();
        this.baseURL = `${import.meta.env.VITE_API_DOMAIN}`;
        this.path = "";
    }
}

export default BaseRepository;

Extend from this BaseRepository

// PostRepository.js
import BaseRepository from "./BaseRepository.js";

class PostRepository extends BaseRepository {
    constructor() {
        super();
        this.path = "/posts";
    }
}

export default PostRepository;

Use it in different styles

By Creating an Instance

// app.js
import PostRepository from "PostRepository.js";
const PostRepositoryInstance = new PostRepository();

// Search some posts
PostRepositoryInstance.search({ limit: 10, sort: "-id" }).then((data) => {
    console.log(data);
});

By using a builder function

// app.js
import PostRepository from "PostRepository.js";

// Search some posts
PostRepository.make().search({ limit: 10, sort: "-id" }).then((data) => {
    console.log(data);
});

By Importing an instance

// app.js
import PostRepository from "PostRepository.js"; // Should use `export default new PostRepository()`;

// Search some posts
PostRepository.search({ limit: 10, sort: "-id" }).then((data) => {
    console.log(data);
});

Constructor Configuration

| variable | default | description | |:-------------|-------------|-----------------------------------------------------------------------| | baseURL | / | Sets the baseURL for that instance | | path | '' | Sets the relative path to the baseURL | | autoAbort | true | Enables aborting ongoing requests for all methods inside the instance |

Request Methods

| instance method | http-method | parameters | Restricted data keys | |:---------------------|--------------------|-------------------------------------------|----------------------------------------------------------| | index | GET | data | includes, aggregates | | search | POST | data | page, limit, sort, filters, search, includes, aggregates | | store | POST | data, multipart | - | | show | GET | id, data | includes, aggregates | | update | PATCH, PUT or POST | id, data, multipart, method = 'PATCH' | - | | destroy | DELETE | id | - | | restore | POST | id | - | | batchStore | POST | data, multipart | - | | batchUpdate | PATCH or POST | data | - | | batchDestroy | DELETE | data | - | | batchRestore | POST | data | - | | indexRelation | GET | id, relation, data | includes, aggregates | | searchRelation | POST | id, relation, data | page, limit, sort, filters, search, includes, aggregates | | showRelation | GET | id, relation, relationId, data | includes, aggregates | | storeRelation | POST | id, relation, data, multipart | - | | updateRelation | PATCH or POST | id, relation, relationId, data, multipart | - | | destroyRelation | DELETE | id, relation, relationId | - | | restoreRelation | POST | id, relation, relationId | - | | batchStoreRelation | POST | id, relation, data, multipart | - | | batchUpdateRelation | PATCH or POST | id, relation, data, multipart | - | | batchDestroyRelation | DELETE | id, relation, data | - | | batchRestoreRelation | POST | id, relation, data | - | | sync | PATCH | id, relation, data | - | | toggle | PATCH | id, relation, data | - | | attach | POST | id, relation, data | - | | detach | DELETE | id, relation, data | - | | pivot | PATCH | id, relation, relationId, data | - | | associate | POST | id, relation, relatedKey | - | | dissociate | DELETE | id, relation, relationId | - | | abort | - | methodName OR custom id | - |

Helper Methods

| instance method | description | |:--------------------|-----------------------------------------------------------------------------------------------------------| | make | A builder function if you need to create an instance in the chain | | withoutAutoAbort | If the instance has autoAbort enabled, you can disable this effect for methods that use this in the chain | | withAutoAbort | If the instance has autoAbort disabled, you can enable this effect for methods that use this in the chain | | withAbortId | Changes the default abort id (method name), so you can use Instance.abort(abortId) more precise. |

In depth aborting

Default behaviour

By default autoAbort is set to true for the entire instance.

Note: This will only with work synchronous requests.

Example:

const UserRepositoryInstance = new UserRepository();

// First Call
UserRepositoryInstance.index().catch((e) => {
    console.log(e.code);                    // ERR_CANCELED
});
// Second call 
UserRepositoryInstance.index().catch((e) => {
    console.log(e.code);                    // ERR_CANCELED
});
// Third Call 
UserRepositoryInstance.index().then((result) => {
    console.log(result.status);             // 200
});

Disable autoAbort for entire instance

Disabling autoAbort will not auto-abort anything. Ongoing requests can still be canceled with the UserRepository.abort('method') or UserRepository.abort('id') methods.

Example:

class UserRepository extends LaravelOrionAPI {
    constructor(withDelay = false) {
        super();
        this.autoAbort = false;               // Disable autoAbort here
    }
}
const UserRepositoryInstance = new UserRepository();

// First Call 
UserRepositoryInstance.index().then((result) => {
    console.log(result.status)                // 200
});
// Second call 
UserRepositoryInstance.index().then((result) => {
    console.log(result.status)                // 200
});
// Third Call 
UserRepositoryInstance.index().then((result) => {
    console.log(result.status)                // 200
});

Disable autoAbort for a single method

Example:

const UserRepositoryInstance = new UserRepository();

// First Call
UserRepositoryInstance.withoutAutoAbort().index().then((result) => {
    console.log(result.status);             // 200
});
// Second call 
UserRepositoryInstance.withoutAutoAbort().index().then((result) => {
    console.log(result.status);             // 200
});
// Third Call 
UserRepositoryInstance.withoutAutoAbort().index().then((result) => {
    console.log(result.status);             // 200
});

Note: If you are using the index() for two different purposes simultaneously, you must use withAbortId() to avoid weird behaviour. See example below

Example:

// First Call
const UserRepositoryInstance = new UserRepository();

UserRepositoryInstance.withoutAutoAbort().index().then((result) => {
    console.log(result.status);             // 200
});
// Second call 
UserRepositoryInstance.withoutAutoAbort().index().then((result) => {
    console.log(result.status);             // 200
});
// Third Call 
UserRepositoryInstance.withAbortId('other-purpose').index().catch((e) => {
    console.log(e.code);                    // ERR_CANCELED 
});
// Fourth Call 
UserRepositoryInstance.withAbortId('other-purpose').index().then((result) => {
    console.log(result.status);             // 200 
});