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

vaas-framework

v1.9.16

Published

Virtual as a Service Framework

Downloads

32

Readme

vaas-framework

Virtual as a Service Framework

Structure

Structure

Quick Start

Quick init vaas project command:

npm init vaas

simple app base code

// # src/apps/mini/index.ts
import {VaasServerType, Decorator } from 'vaas-framework'

export default class Mini {
    @Decorator.VaasServer({type:'http',method:'get',routerName:'/hello'})
    async hello({req,res}:VaasServerType.HttpParams) {
        return {
            hello:'world'
        }
    }
}

api doc

vaas.config.js

export interface VaasConfig {
    appsDir:string,
    port:number,
    getAppNameByRequest:GetAppNameByRequest, 
    getAppConfigByAppName:GetAppConfigByAppName,
    showErrorStack:boolean
    isPrepareWorker:boolean
}
  • type GetAppNameByRequest
export interface GetAppNameByRequest {
  (request:Koa.Request): Promise<string>;
}
  • type GetAppConfigByAppName
export interface GetAppConfigByAppName {
  (appName:string): Promise<AppConfig>;
}
  • type AppConfig
export interface AppConfig {
  maxWorkerNum:number,
  allowModuleSet:Set<string>,
  timeout:number,
  resourceLimits?:ResourceLimits
}
interface ResourceLimits {
  /**
   * The maximum size of a heap space for recently created objects.
   */
  maxYoungGenerationSizeMb?: number | undefined;
  /**
   * The maximum size of the main heap in MB.
   */
  maxOldGenerationSizeMb?: number | undefined;
  /**
   * The size of a pre-allocated memory range used for generated code.
   */
  codeRangeSizeMb?: number | undefined;
  /**
   * The default maximum stack size for the thread. Small values may lead to unusable Worker instances.
   * @default 4
   */
  stackSizeMb?: number | undefined;
}

Decorator.VaasServer

export function VaasServer(vaasServer:ServerValue={type:'http'})
  • type ServerValue
export interface ServerValue {
  type:ServerType,
  method?: 'get' | 'post' | 'put' | 'delete' | 'patch'| 'options';
  routerName?: string;
}

routerName will be translated to regular expressions using path-to-regexp.

req&res

export interface HttpParams {
    req: RequestConfig;
    res: ResponseConfig;
}
  • type RequestConfig
export interface RequestConfig {
    /**
     * Get the charset when present or undefined.
     */
    readonly charset: string;
    /**
     * Return parsed Content-Length when present.
     */
    readonly length: number;
    /**
     * Return the request mime type void of
     * parameters such as "charset".
     */
    readonly type: string;
    /**
     * Return request header, alias as request.header
     */
    readonly headers: NodeJS.Dict<string | string[]>;
    /**
     * Get request body.
     */
    readonly body?: Record<string, any>;
    /**
    * Get query string.
    */
    readonly rawBody: string;
    /**
     * Get/Set request URL.
     */
    url: string;
    /**
     * Get origin of URL.
     */
    readonly origin: string;
    /**
     * Get full request URL.
     */
    readonly href: string;
    /**
     * Get/Set request method.
     */
    method: string;
    /**
     * Get request pathname.
     * Set pathname, retaining the query-string when present.
     */
    path: string;
    /**
     * Get parsed routerName-params.
     * Set routerName-params as an object.
     */
    params: NodeJS.Dict<string | string[]>;
    /**
     * Get parsed query-string.
     * Set query-string as an object.
     */
    query: NodeJS.Dict<string | string[]>;
    /**
     * Get/Set query string.
     */
    querystring: string;
    /**
     * Get the search string. Same as the querystring
     * except it includes the leading ?.
     *
     * Set the search string. Same as
     * response.querystring= but included for ubiquity.
     */
    search: string;
    /**
     * Parse the "Host" header field host
     * and support X-Forwarded-Host when a
     * proxy is enabled.
     */
    readonly host: string;
    /**
     * Parse the "Host" header field hostname
     * and support X-Forwarded-Host when a
     * proxy is enabled.
     */
    readonly hostname: string;
    /**
     * Check if the request is fresh, aka
     * Last-Modified and/or the ETag
     * still match.
     */
    readonly fresh: boolean;
    /**
     * Check if the request is stale, aka
     * "Last-Modified" and / or the "ETag" for the
     * resource has changed.
     */
    readonly stale: boolean;
    /**
     * Check if the request is idempotent.
     */
    readonly idempotent: boolean;
    /**
     * Return the protocol string "http" or "https"
     * when requested with TLS. When the proxy setting
     * is enabled the "X-Forwarded-Proto" header
     * field will be trusted. If you're running behind
     * a reverse proxy that supplies https for you this
     * may be enabled.
     */
    readonly protocol: string;
    /**
     * Short-hand for:
     *
     *    this.protocol == 'https'
     */
    readonly secure: boolean;
    /**
     * Request remote address. Supports X-Forwarded-For when app.proxy is true.
     */
    readonly ip: string;
    /**
     * When `app.proxy` is `true`, parse
     * the "X-Forwarded-For" ip address list.
     *
     * For example if the value were "client, proxy1, proxy2"
     * you would receive the array `["client", "proxy1", "proxy2"]`
     * where "proxy2" is the furthest down-stream.
     */
    readonly ips: string[];
}
  • type ResponseConfig
export interface ResponseConfig {
    /**
     * Return response header.
     */
    headers: NodeJS.Dict<OutgoingHttpHeader>;
    /**
      * Get/Set response status code.
      */
    status: number;
    /**
     * Get response status message
     */
    readonly message: string;
    /**
     * Return parsed response Content-Length when present.
     * Set Content-Length field to `n`.
     */
    length: number;
    /**
     * Return the response mime type void of
     * parameters such as "charset".
     *
     * Set Content-Type response header with `type` through `mime.lookup()`
     * when it does not contain a charset.
     *
     * Examples:
     *
     *     this.type = '.html';
     *     this.type = 'html';
     *     this.type = 'json';
     *     this.type = 'application/json';
     *     this.type = 'png';
     */
    type: string;
    /**
     * Get the Last-Modified date in Date form, if it exists.
     * Set the Last-Modified date using a string or a Date.
     *
     *     this.response.lastModified = new Date();
     *     this.response.lastModified = '2013-09-13';
     */
    lastModified: Date;
    /**
     * Get/Set the ETag of a response.
     * This will normalize the quotes if necessary.
     *
     *     this.response.etag = 'md5hashsum';
     *     this.response.etag = '"md5hashsum"';
     *     this.response.etag = 'W/"123456789"';
     *
     * @param {String} etag
     * @api public
     */
    etag: string;
}

rpc.rpcInvote

export async function rpcInvote<P,R>(appServerName:string,params:P):Promise<R>

appServerName is appName.serverName