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

@blanderbit/vue-resolver

v0.1.2

Published

A flexible package that allows you to quickly configure a middleware for a router, with the ability to set up an authorization system, receive data for a page

Downloads

4

Readme

Vue Resolver

why we should be use this ?

    In every rather complex application on vue.js there is a need to get data before loading the page or check that the
    user is authorized, I thought that I could make one library with standard logic that can be reused

Support

    vue2 - router beforeEnter
    vue3 - router beforeEnter
    nuxt BeforeEnter router hook

Information

    Used to simplify work with the authorization system and obtain data before loading the page, 
    with the ability to check the existence of a token, get a list of data, run spinners

Functionality

    1 - getting data from request 
    2 - check if user Authorized
    3 - start spinner
    4 - redirect if get exception

How started

    npm i @blanderbit/vue-resolver or npm install @blanderbit/vue-resolver
global mode
    Information about mode - set value for all uses, what each function is for, see below
    import { VueResolver } from "@blanderbit/vue-resolver";
    
    const AltesiaRouterResolver = new VueResolver()
        .registerResolverFirstWorker(resolverFunctions.isUserAuthorized)
        .registerResolverFirstWorkerError(resolverFunctions.isAuthorizedError)
        .registerResolverSecondWorkerError(resolverFunctions.isResolveDataError)
        .registerAfterIntercept(finishSpinner)
        .registerBeforeIntercept(startSpinner);
        
    // usage for router object
    
    {
        path: 'test',
        component: TestPage,
        beforeEnter: AltesiaRouterResolver.routeInterceptor((to) => ({
            testData: () => $api.testDataRequest.get(to.query),
            testDataOne: () => $api.testDataRequest.getOne(to.query)
        }))
    } 
    
    // how get data from requests ?
    
    // open router component TestPage or TestPage nested component
    
    // you can use object route from component instance 
    
    // for example if you pass **testData** you will get data from route.meta
    
individual route mode
    Information about mode - set value for specific route, what each function is for, see below
    import { VueResolver } from "@blanderbit/vue-resolver";
    
    const RouterResolver = new VueResolver();
    
    const resolverGuardForSpecificPage = RouterResolver.routeInterceptor(
        () => ({}),
        {
            afterIntercept: ({ next }) => { // some checks if success
                next(ROUTES.USERS);
                finishSpinner();
            },
            resolveFirstWorkerError: ({ next }) => { // some checks if error
                next(true);
                finishSpinner();
            },
        }
    );
    
    // usage for router object
    {
        path: 'specific-page',
        component: resolverGuardForSpecificPage,
        beforeEnter: resolverGuardForLoginPage
    }, 

Information about routeInterceptor params

    1 - oobject where keys is the name of the data, value is the callback that should return the promise or data

        {
            testData: () => Promise,
            testDataOne: () => Promise
        }
        
    2 - object where keys are names of lifecycle hooks and values ​​are callback handlers,  thanks to which you can
        custom configure resolvers for different routes

Lifecycle hooks

    beforeIntercept - can pass for second param routeInterceptor, or fill it global registerBeforeIntercept
         usage - usually indicates that data loading has begun, for example, you can run a spinner on the page
    
    firstWorker- can pass for second param routeInterceptor - or set it global registerResolverFirstWorker  
        usage - used for primary data processing or, as a rule, checking for the existence of a token, obtaining data 
                about the user,  as an option to make a quick request to obtain data that the user is logged into the system    
                
    firstWorkerError - can pass for second param routeInterceptor, or fill it global  resolveFirstWorkerError
        usage - it is usually used when there is some kind of error when checking login data
            
    resolverSecondWorkerError - can pass for second param routeInterceptor, or fill it global resolveresolverSecondWorkerError
        usage -  is used as a rule when, upon receiving some data that we transmitted (the first to pass to second param for routeInterceptor),
                 we received some kind of error
          
    afterIntercept - can pass for second param routeInterceptor, or fill it global resolveAfterIntercept  
        usage - use when the interceptor finishes its execution, we can stop the spinner         

use only getting data without auth check

    firstWorker should be return - true, Promise<true>

EXAMPLES

getting data VUE3
    ----- resolver.js -----
    
    Import { VueResolver } from "@blanderbit/vue-resolver";
    
    const AltesiaRouterResolver = new VueResolver()
       .registerResolverFirstWorker(() => true)
       .registerAfterIntercept((e) => {
           // stop spinner
       })
       .registerBeforeIntercept((e) => {
           // start spinner
       });
    
    ----- router.js -----
        
    import { createRouter, createWebHistory } from 'vue-router';
    
    const routes = [
        {
            path: 'test',
            component: TestPage,
            beforeEnter: AltesiaRouterResolver.routeInterceptor((to, from) => ({
                testData: () => Promise.resolve([]) // or request and you can you "to, from" params
                testDataOne: () => $Promise.resolve({}) // or request, "to, from" params
            }))
        } 
    ]
    
    export const router = createRouter({
        history: createWebHistory('/'),
        routes
    });
    
    
    export default router;
    
    ----- TestPage.vue -----
    
    <template>
        <div>
            {{ testData }}
            {{ testDataOne }}
        </div>
    </template>
    
    <script>
        import { ref } from "vue";
        import { useRoute } from "vue-router";
    
        export default {
            setup() {
                const route = useRoute();
                return {
                    testData: ref(route.meta.testData),
                    testDataOne: ref(route.meta.testDataOne),
                }
            }
        }
    </script>
getting data with check user auth VUE3
    ----- resolver.js -----
    
    Import { VueResolver } from "@blanderbit/vue-resolver";
    
    const AltesiaRouterResolver = new VueResolver()
        .registerResolverFirstWorker(() => {
            // return promise for request check by user or check token, return boolean or Promise<boolean>
        })
        .registerResolverFirstWorkerError(() => //  get info about error for auth)
        .registerResolverSecondWorkerError(() => //  get info about error for data requests)
        .registerAfterIntercept((e) => {
            // stop spinner
        })
        .registerBeforeIntercept((e) => {
            // start spinner
        });
    
    ----- router.js -----
        
    import { createRouter, createWebHistory } from 'vue-router';
    
    const routes = [
        {
            path: 'test',
            component: TestPage,
            beforeEnter: AltesiaRouterResolver.routeInterceptor((to) => ({
                testData: () => Promise.resolve([]) // or request,
                testDataOne: () => $Promise.resolve({}) // or request,
            }))
        } 
    ]
    
    export const router = createRouter({
        history: createWebHistory('/'),
        routes
    });
    
    
    export default router;
    
    ----- TestPage.vue -----
    
    <template>
        <div>
            {{ testData }}
            {{ testDataOne }}
        </div>
    </template>
    
    <script>
        import { ref } from "vue";
        import { useRoute } from "vue-router";
    
        export default {
            setup() {
                const route = useRoute();
                return {
                    testData: ref(route.meta.testData),
                    testDataOne: ref(route.meta.testDataOne),
                }
            }
        }
    </script>