Options
All
  • Public
  • Public/Protected
  • All
Menu

@imqueue/rpc

Index

Type aliases

AcquiredLock

AcquiredLock: T | boolean

ClassDescriptions

ClassDescriptions: object

Type declaration

CommentBlockMetadata

CommentBlockMetadata: object

Type declaration

CommentMetadata

CommentMetadata: object

Type declaration

ICacheAdapter

ICacheAdapter: ICacheConstructor | ICache | string

IMQLockQueue

IMQLockQueue: Array<IMQLockTask>

IMQLockTask

IMQLockTask: [function, function]

Variables

Const DEFAULT_IMQ_CLIENT_OPTIONS

DEFAULT_IMQ_CLIENT_OPTIONS: IMQClientOptions = Object.assign({},DEFAULT_IMQ_OPTIONS, {cleanup: true,cleanupFilter: '*:client',path: './src/clients',compile: true,timeout: 30000,write: true,},)

Default client options

type

{IMQClientOptions}

Const DEFAULT_IMQ_SERVICE_OPTIONS

DEFAULT_IMQ_SERVICE_OPTIONS: IMQServiceOptions = Object.assign({},DEFAULT_IMQ_OPTIONS, {cleanup: true,cleanupFilter: '*:client',multiProcess: false,childrenPerCore: 1,},)

Default service options

type

{IMQServiceOptions}

Const DEFAULT_REDIS_CACHE_OPTIONS

DEFAULT_REDIS_CACHE_OPTIONS: IMQOptions & object = Object.assign({}, DEFAULT_IMQ_OPTIONS, {prefix: 'imq-cache'})

Const IMQ_PID_DIR

IMQ_PID_DIR: string = path.resolve(IMQ_TMP_DIR, '.imq-rpc')

Const IMQ_TMP_DIR

IMQ_TMP_DIR: string = process.env.TMPDIR ||// istanbul ignore next'/tmp'

Const RX_ARG_NAMES

RX_ARG_NAMES: RegExp = /^(\S+)([=\s]+.*?)?$/

Const RX_COMMA_SPLIT

RX_COMMA_SPLIT: RegExp = /\s*,\s*/

Const RX_DESCRIPTION

RX_DESCRIPTION: RegExp = /^([\s\S]*?)@/

Const RX_LI_CLEANUP

RX_LI_CLEANUP: RegExp = /^\s*-\s*/

Const RX_MULTILINE_CLEANUP

RX_MULTILINE_CLEANUP: RegExp = /\*?\n +\* ?/g

Const RX_OPTIONAL

RX_OPTIONAL: RegExp = /^\[(.*?)\]$/

Const RX_SPACE_SPLIT

RX_SPACE_SPLIT: RegExp = / /

Const RX_TAG

RX_TAG: RegExp = /(@[^@]+)/g

Const RX_TYPE

RX_TYPE: RegExp = /\{([\s\S]+)\}/

Const SIGNALS

SIGNALS: string[] = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGBREAK']

Const TS_TYPES

TS_TYPES: string[] = ['object','string','number','boolean','null','undefined']

Const descriptions

descriptions: ClassDescriptions

Const hash

hash: any = require('murmurhash-native')

machineIdSync

machineIdSync: any

Let serviceDescription

serviceDescription: Description | null = null

Const tsOptions

tsOptions: any = require('../tsconfig.json').compilerOptions

Functions

IMQError

  • IMQError(code: string, message: string, stack: any, method: any, args: any): IMQRPCError

argumentNames

  • argumentNames(fn: function): string[]
  • Lookup and returns a list of argument names for a given function

    Parameters

    • fn: function
        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    Returns string[]

Const cache

cast

  • cast(type: string): string
  • Converts JavaScript type to most close possible TypeScript type

    Parameters

    • type: string

    Returns string

cleanType

  • cleanType(typedef: string): string
  • Removes Promise from type definition if any

    access

    private

    Parameters

    • typedef: string

    Returns string

compile

  • Compiles client source code and returns loaded module

    access

    private

    Parameters

    Returns Promise<any>

expose

  • expose(): function
  • Expose decorator factory

    Returns function

    {( target: object, methodName: (string), descriptor: TypedPropertyDescriptor<(...args: any[]) => any> ) => void} - decorator function

      • (...args: any[]): any
      • Parameters

        • Rest ...args: any[]

        Returns any

fileExists

  • fileExists(path: string): Promise<Object>
  • Checks if file exists at given path

    Parameters

    • path: string

    Returns Promise<Object>

forgetPid

  • forgetPid(name: string, id: number, logger: ILogger, path?: string): void
  • Removes pid file for a given name and id

    Parameters

    • name: string
    • id: number
    • logger: ILogger
    • Default value path: string = IMQ_PID_DIR

    Returns void

generalCallback

  • generalCallback(resolve: function, reject: function, err?: Error): void
  • Constructs and return callback which will resolve promise using given resolver and rejector

    Parameters

    • resolve: function
        • (): void
        • Returns void

    • reject: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    • Optional err: Error

    Returns void

generator

get

  • get<T>(prop: string, className: string, method: string, defaults: T): T
  • Helper function to make easy descriptions parts extractions

    Type parameters

    • T

    Parameters

    • prop: string

      property name to extract

    • className: string

      class name to lookup

    • method: string

      method name to lookup

    • defaults: T

      a default value to use if nothing found

    Returns T

    • found value

getClassMethods

getDescription

  • Fetches and returns service description using the timeout (to handle situations when the service is not started)

    access

    private

    Parameters

    Returns Promise<Description>

isValidArgsCount

  • Checks if given args match given args description at least by args count

    Parameters

    Returns boolean

lock

  • lock(enabled?: boolean): (Anonymous function)
  • @lock() decorator implementation Will make all simultaneous similar method calls locked to be resolved with the first obtained values. Similarity is identified by a bypassed method argument values.

    Parameters

    • Default value enabled: boolean = true

    Returns (Anonymous function)

    {( target: any, methodName: (string), descriptor: TypedPropertyDescriptor<(...args: any[]) => any> ) => void}

mkdir

  • mkdir(path: string): Promise<Object>

osUuid

  • osUuid(): string

parseComment

parseDescriptions

  • parseDescriptions(name: string, src: string): void
  • Finds and parses methods and their comment blocks for a given class

    Parameters

    • name: string

      class name

    • src: string

      class source code

    Returns void

pid

  • pid(name: string, path?: string): number
  • Returns increment-based process identifier for a given name

    Parameters

    • name: string

      name of a service to create pid file for

    • Default value path: string = IMQ_PID_DIR

      directory to

    Returns number

promisedType

  • promisedType(typedef: string): string
  • Return promised typedef of a given type if its missing

    c @access private

    Parameters

    • typedef: string

    Returns string

property

  • property(type: string, isOptional?: boolean): any
  • Implements '@property' decorator factory This is used to specify complex service types to be exposed

    example
    import { property, expose, IMQService } from '@imqueue/rpc';
    
    class Address {
        @property('string')
        country: string;
    
        @property('string')
        city: string;
    
        @property('string')
        address: string;
    
        @property('string', true)
        zipCode?: string; // this is optional
    }
    
    class User {
        @property('string')
        firstName: string;
    
        @property('string')
        lastName: string;
    
        @property('string')
        email: string;
    
        @property('Array<Address>', true)
        address?: Array<Address>;
    }
    
    // now we can use those complex types as service methods args
    // and them will be properly exposed to service clients
    
    class UserService extends IMQService {
    
        @expose()
        public save(user: User) {
            // do smth with given user data to persis it
        }
    
        @expose()
        public find(id: number): User {
           // find and return user
        }
    
    }

    Parameters

    • type: string
    • Default value isOptional: boolean = false

    Returns any

    {( target: any, methodName: (string), descriptor: TypedPropertyDescriptor<(...args: any[]) => any> ) => void}

remote

  • remote(): (Anonymous function)
  • Implements '@remote' decorator factory

    Returns (Anonymous function)

    {( target: any, methodName: (string), descriptor: TypedPropertyDescriptor<(...args: any[]) => any> ) => void}

signature

  • signature(className: string, methodName: string | symbol, args: any[]): string
  • Constructs and returns hash string for a given set of className, methodName and arguments.

    Parameters

    • className: string
    • methodName: string | symbol
    • args: any[]

    Returns string

toComment

  • toComment(typedef: string, promised?: boolean): string
  • Type to comment

    access

    private

    Parameters

    • typedef: string
    • Default value promised: boolean = false

    Returns string

writeFile

  • writeFile(path: string, content: string): Promise<Object>
  • Promisable writeFile

    Parameters

    • path: string
    • content: string

    Returns Promise<Object>