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

lysis-typescript-classes-generator

v0.0.12

Published

Generate TypeScript classes for JSON LD backend

Downloads

76

Readme

Lysis TypeScript classes generator

Overview

This generator creates TypeScript classes to handle object provided by the API.

Samples

Base and extended classes

Example of base classes, the book base class, named BookBase:

export class BookBase {
  id: number;
  isbn: string;
  description: string;
  author: string;
  title: string;
  publicationDate: Date;

}

This class should not be modified, as it is overwritten during next generations.

Another class is automatically generated, inherited from the base class:

import { BookBase } from './BookBase';

export class Book implements BookBase {
}

This Book class inherits from BookBase and is not overwritten during further generations.

It is the perfect place to add customizations.

Other classes dependencies

Reviews are performed on a book. So a review owns a book property:

import { Book } from './Book';

export class ReviewBase {
  id: number;
  rating: number;
  body: string;
  book: Book;
  author: string;
  publicationDate: Date;

  setBook(id: number): ReviewBase {
    this.book = new Book();
    this.book.id = id;
    this.book['@id'] = '/books/' + id;
    return this;
  }
}

The type of the book property is Book. It is automatically imported.

The setBook method is here to automatically populate the book property with a book object from the provided book id.

It is almost useful when creating a new review, before posting it. The real value will overwrite this temporary book value when the backend POST response will be received.

Under the hood, the Restangular configuration module (available soon), transforms the book['@id'] as the correct value.

Index file

The index file is the one to include in the application controller, services, ... to use classes.

import { Book } from '../api/backend-classes';

export class MyComponent implements OnInit {
  private currentBook: Book;

  // [...]
}

Use

Prerequisites

If it is not already done, install api-lysis globally and as dev dependency:

npm install api-lysis -g
npm install api-lysis --save-dev

### Install this generator

Install this generator:

npm install lysis-typescript-classes-generator --save-dev

Configuration

Configuration sample:

apis:
  http://localhost:8000:
    basePath: 'my-backend'
    hydraPrefix: 'hydra:'
    generators:
      lysis-typescript-classes-generator:
        dir: 'classes'

Class files are generated in my-backend/classes.

If dir is not set, the default value is backend-classes.

todo:

  • force extended class overwrite (default false)