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

@theogonic/zeus

v0.1.6

Published

Typescript Generator for Clean Architecture

Downloads

65

Readme

Zeus

NPM Version NPM Downloads NPM License

Motivation

Zeus are a code generator tries to generated as much as types from perspective of clean architecture. Once using "JSON Schema-like" zeus YAML to define the shape of usecase, method and its request and response, Zeus can generated interface, glue code of controller layer like restful layer, graphql layer (schema and actual code), etc.

Taking benefits of Nestjs and its dependency injection, Zeus can even generate ready-to-use restful controller (including code of path/query/body parameter handling/formatting). Please see Generators too find more powerful features.

Full Example

Zeus Generator Configuration

examples/user-usecase/zeus.yaml

Zeus Definition

examples/user-usecase/defs

Generated Result

examples/generated

Commands to generate examples

$ ./zeus --proto user.proto

Generators

ts

ts generator generate related interfaces for usecase defined in Zeus Definition file. Generated interfaces are following:

  1. usecase itself
  2. each method's request and response

Example

// !!! ALL CODE BELOW ARE GENERATED BY ZEUS !!!

export interface CreateUserRequest {
...
} 

...

export interface UserUsercase {
    createUser(request: CreateUserRequest): Promise<CreateUserResponse>;
    ...
}

rest-nestjs

rest-nestjs generator generates ready-to-use Nestjs controller which provide restful API to a usecase. It depends on interfaces generated by ts generator. The generated code is ready-to-use. Body, path, query these details are configurable in the Zeus Definition file.

Example

// !!! ALL CODE BELOW ARE GENERATED BY ZEUS !!!

import { UserUsercase, USER_USERCASE, ...  } from "./types";

@Controller("user")
@ApiTags("user")
export class UserUsercaseController {
    constructor(
    @Inject(USER_USERCASE)
    private readonly userUsercase: UserUsercase) { }
    @Post("users")
    @ApiOkResponse({ type: CreateUserResponseDto })
    @()
    createUser(
    @Body()
    body: CreateUserRequestBodyDto, 
    @User()
    user) {
        const ucReq = {
            id: body.id,
            name: body.name,
            age: body.age,
            user
        } as CreateUserRequest;
        return this.userUsercase.createUser(ucReq);
    }
    ...
}

gql

gql generator generates the GraphQL type regarding to the types section in Zeus Definition file

Example

# !!! ALL CODE BELOW ARE GENERATED BY ZEUS !!!

type JwtUser {
  id: String
  email: String
  org: String
}

type Query {
  hello(request: Request): Response
}

gql-nestjs

Example

# !!! ALL CODE BELOW ARE GENERATED BY ZEUS !!!

import { Inject, Logger } from "@nestjs/common";
import { Args, Context, Mutation, Parent, Query, ResolveField, Resolver, ResolveReference } from "@nestjs/graphql";
import { UserUsercase, USER_USERCASE } from "./types";
@Resolver()
export class UserUsercaseResolver {
    constructor(
    @Inject(USER_USERCASE)
    private readonly userUsercase: UserUsercase) { }
    @Mutation()
    async createUser(
    @Args("request")
    request) {
        return this.userUsercase.createUser({
            ...request
        });
    }
    ....
}

general-entity

general-entity generated the types for @theogonic/gaea. If your project used @theogonic/gaea as your entity library (handling database related operations), you have read-to-use Entitys and Daos!

Example

# !!! ALL CODE BELOW ARE GENERATED BY ZEUS !!!

import { BaseGeneralObject, BaseGeneralObjectDao } from '@theogonic/gaea';
import { User } from './types';
export class UserEntity extends BaseGeneralObject implements User {
  constructor(meta: BaseGeneralObject['meta'], obj: Omit<User, 'meta'>) {
    super(meta);
    this.tags = obj.tags;
    this.profile = obj.profile;
  }
  tags: User['tags'];
  profile: User['profile'];
}
export class UserEntityDao extends BaseGeneralObjectDao<UserEntity> {
  target = UserEntity;
}

Zeus Generator Configuration YAML Format

This yaml is to tell zeus which generator is/are going to be used, where it should output and detail/extra configs for specific generator.

Zeus Definition YAML Format

This yaml defines shape of usecase(s) and its method(s) including request and request.