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

@travetto/scaffold

v5.0.21

Published

App Scaffold for the Travetto framework

Downloads

665

Readme

App Scaffold

App Scaffold for the Travetto framework

A simple tool for scaffolding a reference project. To get started, you need to make sure:

Terminal: Setting up the necessary config

$ git config --global.username <Username> #Set your git username

Once the necessary configuration is setup, you can invoke the scaffolding by running

Terminal: Running Generator

$ npx @travetto/scaffold

# or

$ npx @travetto/scaffold@<version-or-tag>

The generator will ask about enabling the following features:

Restful Architecture

The RESTful API provides the necessary integration for exposing restful apis. When selecting the rest feature, you will need to specify which backend you want to include with your application, the default being express. Currently you can select from:

  • express
  • koa
  • fastify The code will establish some basic routes, specifically, GET / as the root endpoint. This will return the contents of your package.json as an identification operation.

Additional Rest Features

In addition to the core functionality, the rest feature has some useful sub-features. Specifically:

OpenAPI Specification support for the restful api. This will automatically expose a openapi.yml endpoint, and provide the necessary plumbing to support client generation.

Logging support for better formatting, debug like support, and colorized output. This is generally useful for server logs, especially during development.

Authentication

Authentication is also supported on the Restful endpoints by selecting Rest Auth during setup. This will support basic authentication running out of local memory, with user REST Sessions.

Testing

Testing can also be configured out of the box to provide simple test cases for the data model.

Data Modelling and Storage

The Data Modeling Support allows for modeling of application data, and provides mechanisms for storage and retrieval. When setting up your application, you will need to select which database backend you want to use:

Code: Todo Model

import { Model, ModelType } from '@travetto/model';

@Model()
export class Todo implements ModelType {
  id: string;
  text: string;
  completed?: boolean;
  userId?: string;
}

Basic tests are also included for the model to verify that database interaction and functionality is working properly.

Rest + Model

In the case both rest and model features are enabled, the code will produce a controller that exposes the Todo model via restful patterns.

Code: Todo controller

import { Controller, Get, Put, Post, Delete } from '@travetto/rest';
import { NotFoundError } from '@travetto/model';
import { Inject } from '@travetto/di';
import { ModelQuery, ModelQueryCrudSupport } from '@travetto/model-query';
import { Schema } from '@travetto/schema';

import { Todo } from './model';

@Schema()
class Query {
  q: object = {};
}

/**
 * Controller for managing all aspects of the Todo lifecycle
 */
@Controller('/todo')
export class TodoController {

  @Inject()
  source: ModelQueryCrudSupport;

  /**
   * Get all Todos
   */
  @Get('/')
  async getAll(query: Query): Promise<Todo[]> {
    query.q ??= {};
    return this.source.query(Todo, { where: query.q });
  }

  /**
   * Get Todo by id
   */
  @Get('/:id')
  async getOne(id: string): Promise<Todo> {
    const q: ModelQuery<Todo> = { where: { id } };
    if (typeof q.where !== 'string') {
    }
    return this.source.queryOne(Todo, q);
  }

  /**
   * Create a Todo
   */
  @Post('/')
  async save(todo: Todo): Promise<Todo> {
    return this.source.create(Todo, todo);
  }

  /**
   * Update a Todo
   */
  @Put('/:id')
  async update(todo: Todo): Promise<Todo> {
    return this.source.update(Todo, todo);
  }

  /**
   * Delete a Todo
   */
  @Delete('/:id')
  async remove(id: string): Promise<void> {
    const q: ModelQuery<Todo> = { where: { id } };
    if (typeof q.where !== 'string') {
    }
    if (await this.source.deleteByQuery(Todo, q) !== 1) {
      throw new NotFoundError(Todo, id);
    }
  }
}

Running

Once finished the application will reflect the modules chosen, and will be ready for execution, if you have configured a runnable application. Currently, this requires the rest feature to be selected.

Terminal: Starting the App

npm start