1.9.12 • Published 22 days ago

vaas-framework v1.9.12

Weekly downloads
-
License
MIT
Repository
github
Last release
22 days ago

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

1.9.12

22 days ago

1.9.11

26 days ago

1.9.10

26 days ago

1.9.9

28 days ago

1.9.8

30 days ago

1.9.7

30 days ago

1.9.6

1 month ago

1.9.5

3 months ago

1.9.3

3 months ago

1.9.2

3 months ago

1.8.2

4 months ago

1.8.1

4 months ago

1.7.2

4 months ago

1.7.1

4 months ago

1.6.1

5 months ago

1.5.6

5 months ago

1.5.5

5 months ago

1.2.8

12 months ago

1.2.10

11 months ago

1.5.3

9 months ago

1.5.2

9 months ago

1.5.1

9 months ago

1.3.2

10 months ago

1.3.1

10 months ago

1.2.9

12 months ago

1.2.7

1 year ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.2.6

1 year ago

1.0.8

2 years ago

1.2.5

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.2.3

1 year ago

1.0.5

2 years ago

1.2.2

1 year ago

1.2.1

1 year ago

1.0.3

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.25

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.1.1

1 year ago

1.0.39

1 year ago

1.0.38

2 years ago

1.1.2

1 year ago

1.0.40

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago