Nice Philanthropist Metalhead

    @whook/whook
    TypeScript icon, indicating that this package has built-in type declarations

    8.1.1 • Public • Published

    @whook/whook

    Build strong and efficient REST web services.

    GitHub license NPM version

    whook allows you to create REST web services by providing its ingredients and the recipe to make it work altogether.

    The recipe is your Open API (OAS3) definition while ingredients are handlers, wrappers, services and their configuration.

    Quick start

    npm init @whook

    Learn more about Whook.

    API

    Members

    defaultPromise.<String>

    Initialize the API_DEFINITIONS service according to the porject handlers.

    defaultPromise.<String>

    Initialize the BASE_URL service according to the HOST/PORT so that applications fallbacks to that default base URL.

    defaultPromise.<Object>

    Initialize the CONFIGS service according to the NODE_ENV

    defaultPromise.<Number>

    Initialize the PORT service from ENV or auto-detection if none specified in ENV

    defaultPromise.<string>

    Auto detect the Whook PROJECT_DIR

    defaultPromise.<Object>

    Wrap the ENV service in order to filter ENV vars for the build

    defaultPromise.<string>

    Auto detect the Whook WHOOK_PLUGINS_PATHS

    Functions

    prepareServer(injectedNames, $)

    Runs the Whook server

    prepareEnvironment($)

    Prepare the Whook server environment

    initBuildConstants(constants)Promise.<Object>

    Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

    initENV(services)Promise.<Object>

    Initialize the ENV service using process env plus dotenv files

    initHost(services)Promise.<String>

    Initialize the HOST service from ENV or auto-detection if none specified in ENV

    initImporter(constants)Promise.<Object>

    Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

    default ⇒ Promise.<String>

    Initialize the API_DEFINITIONS service according to the porject handlers.

    Kind: global variable
    Returns: Promise.<String> - A promise of a containing the actual host.

    Param Type Default Description
    services Object The services API_DEFINITIONS depends on
    services.PROJECT_SRC Object The project sources location
    services.WHOOK_PLUGINS_PATHS Object The plugins paths to load services from
    [services.IGNORED_FILES_SUFFIXES] Object The files suffixes the autoloader must ignore
    [services.IGNORED_FILES_PREFIXES] Object The files prefixes the autoloader must ignore
    [services.FILTER_API_TAGS] Object Allows to only keep the endpoints taggeds with the given tags
    services.importer Object A service allowing to dynamically import ES modules
    [services.log] Object noop An optional logging service

    default ⇒ Promise.<String>

    Initialize the BASE_URL service according to the HOST/PORT so that applications fallbacks to that default base URL.

    Kind: global variable
    Returns: Promise.<String> - A promise of a containing the actual host.

    Param Type Default Description
    services Object The services BASE_URL depends on
    services.ENV Object The process environment
    services.CONFIG Object The injected CONFIG value
    [services.PROTOCOL] Object The injected PROTOCOL value
    services.HOST Object The injected HOST value
    services.PORT Object The injected PORT value
    [services.log] Object noop An optional logging service

    default ⇒ Promise.<Object>

    Initialize the CONFIGS service according to the NODE_ENV

    Kind: global variable
    Returns: Promise.<Object> - A promise of a an object the actual configuration properties.

    Param Type Default Description
    services Object The services CONFIGS depends on
    services.NODE_ENV Object The injected NODE_ENV value
    services.PROJECT_SRC Object The project source directory
    [services.log] Object noop An optional logging service
    services.importer Object A service allowing to dynamically import ES modules

    default ⇒ Promise.<Number>

    Initialize the PORT service from ENV or auto-detection if none specified in ENV

    Kind: global variable
    Returns: Promise.<Number> - A promise of a number representing the actual port.

    Param Type Default Description
    services Object The services PORT depends on
    [services.ENV] Object {} An optional environment object
    [services.log] Object noop An optional logging service
    services.importer Object A service allowing to dynamically import ES modules

    default ⇒ Promise.<string>

    Auto detect the Whook PROJECT_DIR

    Kind: global variable
    Returns: Promise.<string> - A promise of a number representing the actual port.

    Param Type Default Description
    services Object The services PROJECT_DIR depends on
    services.PWD Object The process working directory
    [services.log] Object noop An optional logging service

    default ⇒ Promise.<Object>

    Wrap the ENV service in order to filter ENV vars for the build

    Kind: global variable
    Returns: Promise.<Object> - A promise of an object containing the reshaped env vars.

    Param Type Default Description
    services Object The services ENV depends on
    services.NODE_ENV Object The injected NODE_ENV value to add it to the build env
    [services.PROXYED_ENV_VARS] Object {} A list of environment variable names to proxy
    [services.log] Object noop An optional logging service

    default ⇒ Promise.<string>

    Auto detect the Whook WHOOK_PLUGINS_PATHS

    Kind: global variable
    Returns: Promise.<string> - A promise of a number representing the actual port.

    Param Type Default Description
    services Object The services WHOOK_PLUGINS_PATHS depends on
    services.WHOOK_PLUGINS Array.<String> The active whook plugins list
    services.PROJECT_SRC String The project source directory
    [services.log] Object noop An optional logging service

    prepareServer(injectedNames, $) ⇒

    Runs the Whook server

    Kind: global function
    Returns: Object A promise of the injected services

    Param Type Description
    injectedNames Array.<String> Root dependencies names to instanciate and return
    $ Knifecycle The Knifecycle instance to use for the server run

    prepareEnvironment($) ⇒

    Prepare the Whook server environment

    Kind: global function
    Returns: Promise A promise of the Knifecycle instance

    Param Type Description
    $ Knifecycle The Knifecycle instance to set the various services

    initBuildConstants(constants) ⇒ Promise.<Object>

    Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

    Kind: global function
    Returns: Promise.<Object> - A promise of an object containing the gathered constants.

    Param Type Description
    constants Object The serializable constants to gather

    Example

    import { initBuildConstants } from '@whook/whook';
    import { alsoInject } from 'knifecycle';
    
    export default alsoInject(['MY_OWN_CONSTANT'], initBuildConstants);

    initENV(services) ⇒ Promise.<Object>

    Initialize the ENV service using process env plus dotenv files

    Kind: global function
    Returns: Promise.<Object> - A promise of an object containing the actual env vars.

    Param Type Default Description
    services Object The services ENV depends on
    services.NODE_ENV Object The injected NODE_ENV value to look for .env.${NODE_ENV} env file
    services.PWD Object The process current working directory
    [services.BASE_ENV] Object {} An optional base environment
    [services.log] Object noop An optional logging service

    initHost(services) ⇒ Promise.<String>

    Initialize the HOST service from ENV or auto-detection if none specified in ENV

    Kind: global function
    Returns: Promise.<String> - A promise of a containing the actual host.

    Param Type Default Description
    services Object The services HOST depends on
    [services.ENV] Object {} An optional environment object
    [services.log] Object noop An optional logging service
    services.importer Object A service allowing to dynamically import ES modules

    initImporter(constants) ⇒ Promise.<Object>

    Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

    Kind: global function
    Returns: Promise.<Object> - A promise of an object containing the gathered constants.

    Param Type Description
    constants Object The serializable constants to gather

    Example

    import { initBuildConstants } from '@whook/whook';
    import { alsoInject } from 'knifecycle';
    
    export default alsoInject(['MY_OWN_CONSTANT'], initBuildConstants);

    Authors

    License

    MIT

    Install

    npm i @whook/whook

    DownloadsWeekly Downloads

    199

    Version

    8.1.1

    License

    MIT

    Unpacked Size

    741 kB

    Total Files

    206

    Last publish

    Collaborators

    • nfroidure