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

vuex-rql

v1.0.6

Published

Vuex rql api wrapper

Downloads

5

Readme

Vuex-rest

A powerful utility to simplify consumption of rest apis using RQL.

Setup

Place the following code in your store/index.ts

import {JWTAuth} from "vuex-rql";

const baseUrl = <string>process.env.VUE_APP_API_ENDPOINT
import app from 'vuex-rql'

app.configureAxios(baseUrl).configureAuth(new JWTAuth({
	path: baseUrl + '/authentication/',
	refreshPath: baseUrl + '/authentication/refresh/',
	storage: localStorage
}))

Usage

Create the users service

// store/services/user.ts

import {BaseModel, Service} from "vuex-rql";
import {Module} from "vuex-module-decorators";

export interface User extends BaseModel {
	email: string
	first_name: string
	last_name: string
}

@Module({name: 'users', namespaced: true})
export default class UserService extends Service<User> {
	path = 'users/'
}

Create the authentication service

// store/auth.ts

import {BaseAuthService} from "vue-rql";
import {User} from "@/store/services/user";
import {Module} from "vuex-module-decorators";

@Module({name: 'auth', namespaced: true})
export default class AuthService extends BaseAuthService<User> {
}

And finally connect everything to the store

interface RootState {
	users: ServiceState<User>,
}

const store = new Vuex.Store<RootState>({
	mutations: {},
	actions: {},
	modules: {
		'auth': AuthService,
		'users': UserService,
	}
})

export const usersService = getModule(UserService, store)
export const authService = getModule(AuthService, store)

You can now import it in your vue component and use in the following fashion

import {usersService} from '@/store'

usersService.find().then(data => {
	// do stuff
})

const data = usersService.findStore({}).results // acess data from store

Extending to include custom code

import app, {FindResponse} from "vuex-rql";

@Module({name: 'users', namespaced: true})
class CustomService extends Service<CustomType> {
	path = 'users/'

	@Action({rawError: true})
	async find(query?: Query<CustomType>): Promise<FindResponse<ModelType>> {
		let params: Query<CustomType> = Object.assign({}, query || {})
		this.context.commit('setFindState', true)
		return app.axios.get(this.path, {params}).then((response: AxiosResponse<FindResponse<ModelType>>) => {
			this.context.commit('setData', response.data)
			return response.data
		}).catch(e => {
			return Promise.reject(e)
		}).finally(() => {
			this.context.commit('setFindState', false)
		})
	}
}

Querying

$eq

Find users with name John:

usersService.findStore({name: 'John'})

or

usersService.findStore({name: {$eq: 'John'}})

$gt, $lt, $le, $ge

Find users between ages 18 and 65 inclusive

usersService.findStore({age: {$ge: 18, $le: 65}})

or exclusive

usersService.findStore({age: {$gt: 18, $lt: 65}})

$select

Return specific fields

usersService.findStore({$select: ['name', 'age']})

$like

Search for users with name John

usersService.findStore({name: {$like: 'John'}})

$ilike

Search for users with name John (case in-sensitive):

usersService.findStore({name: {$ilike: 'john'}})

$in, $out

Search for users where the property does ($in) or does not ($out) match any of the given values:

usersService.findStore({roleId: {$in: [2, 5]}})

or

usersService.findStore({roleId: {$out: [2, 5]}})

$or

Combine multiple queries using logical OR

usersService.findStore({
	$or: [
		{age: {$gt: 18, $lt: 65}},
		{active: {$eq: true}}
	]
})