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

@zuu/owl

v4.0.8

Published

Zuu's Experimental GraphQL Implementation

Downloads

23

Readme

@zuu/owl

Gitter Version Downloads/week License

What is Owl?

Is a component of the Zuu framework designed to be stacked on top of Mink and provide all the juicy, nightly, experimental code in the new GraphQL stack ;)

Want to contribute?

Here's how!

Quick intro

Everyone loves GraphQL... for many reasons. It solves many of the REST's problems (underfetching, overfetching, unwanted resource access, unwanted resource fields exposure, the big number of request enpoints and many more...)

Developing GraphQL in TypeScript for the nodejs platform is a pain... Mainly because you have to write your types twice (your internal interfaces and also the exposed SDL schema [ if you don't know what i'm talking about, go learn GraphQL then comeback and continue ;) ]).

If there only was a cool piece of code that could transform those cool ESNext decorators (that TypeScript already provides experimental suport) to the SDL schema automagically... OH WAIT! THERE IS! That's exactly what owl aims at doing :) (and much more)

Object types

You can define your custom schema types using decorators like @ObjectType and @Field(type?) like so:

@ObjectType()
export class Alumni {
    @Field({nullable: true})
    public description: string;

    @Field(type => [String])
    public editions: string[];

    @Field(type => AlumniUser)
    public user: AlumniUser;
};

Resolvers

Name by convention.. Easy to define using @Resolver decorator. Inside a resolver you can definde queries (@Query), mutations (@Mutation) and subscription (@Subscription). You can also inject the current context, mutation or query arguments and the PubSub engine in the methods!

@Resolver()
export class NotificationsResolver {
    @Inject private notificationBundler: NotificationBundler;

    private notificationRepository: Repository<Notification>;

    private self() {
        if (!this.notificationRepository) this.notificationRepository = getRepository(Notification);
    }

    @Subscription(returns => Notification, {
        topics: "NOTIFICATIONS",
        filter: async ({ payload, context }: ResolverFilterData<Notification>) => (await payload.user).id == (<any>context).user.id,
    })
    userNotifications(@Root() notification: Notification) {
        return notification;
    }

    @Query(returns => [Notification])
    public async notifications(
        @Arg("type", { nullable: true }) type: string,
        @Arg("status", { nullable: true }) status: string,
        @Ctx("user") user: User
    ): Promise<Notification[]> {
        this.self();

        let query: any = { user };
        if (type) query.type = type;
        if (status) query.status = status;

        let notifications = await this.notificationRepository.find(query)
        return notifications;
    }

    @Query(returns => Notification)
    public async notification(
        @Ctx("notifications") notifications: Notification[]
    ): Promise<Notification> {
        if(!notifications[0]) throw new RequiredResourceNotProvidedError("notifications");
        return notifications[0];
    }

    @Mutation(returns => Notification, { nullable: true })
    public async pushNotification(
        @Arg("type", { nullable: true }) type: string,
        @Arg("status", { nullable: true }) status: string,
        @Arg("message", { nullable: true }) message: string,
        @Arg("payload", { nullable: true }) payload: string,
        @Arg("icon", {nullable: true}) icon: IconInputType,
        @Arg("targetUser", { nullable: true }) targetUser: string,
        @PubSub("NOTIFICATIONS") publish: Publisher<Notification>,
        @Ctx("user") user: User
    ): Promise<Notification> {
        this.self();

        if(targetUser) user = await User.findOne(targetUser);
        if(!user) return null;

        let notificaion = await this.notificationBundler.assemble(<NotificationType>type, message, payload, <NotificationStatus>status, !icon ? undefined : icon.export());
        (await user.notifications).push(notificaion);
        await user.save();

        await publish(notificaion);
        return notificaion;
    }

    @Mutation(returns => [Notification])
    public async seeNotifications(
        @Ctx("notifications") notifications: Notification[]
    ): Promise<Notification[]> {
        if(!notifications) throw new RequiredResourceNotProvidedError("notifications");

        for(let i = 0; i < notifications.length; i++) {
            notifications[i].status = NotificationStatus.SEEN;
            await notifications[i].save();
        }
        return notifications;
    }

    @Mutation(returns => [Notification])
    public async seeAllNotifications(
        @Ctx("user") user: User
    ): Promise<Notification[]> {
        let notifications = await this.notifications(undefined, NotificationStatus.SENT, user);
        return await this.seeNotifications(notifications);
    }
}