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

@kronos-integration/service

v11.2.0

Published

Base service implementation

Downloads

3,691

Readme

npm License Typed with TypeScript bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

@kronos-integration/service

Base service implementation

Service states

stateDiagram-v2
    stopped --> starting [1]
    starting --> failed: [2]
    starting --> running: [3]
    running --> stopping: [4]
    running --> failed: [5]
    stopping --> failed: [6]
    stopping --> stopped: [7]

The transitions are: | Number | From | To | Condition | | ------ | ---- | -- | --------- | | 1 | ~stopped~ | ~starting~ | | | 2 | ~starting~ | ~failed~ | | | 3 | ~starting~ | ~running~ | | | 4 | ~running~ | ~stopping~ | | | 5 | ~running~ | ~failed~ | | | 6 | ~stopping~ | ~failed~ | | | 7 | ~stopping~ | ~stopped~ | |

API

Table of Contents

EndpointsMixin

Endpoint accessor mixin. Manages endpoints in a container.

Parameters

  • superclass

endpoints

Default set of endpoints to create.

Returns Object {} empty set

ServiceConfig

Extends Service

Config providing service. Dispatches config requests to services. Also preserves them until a maching service becomes avaliable.

Properties

  • preservedConfigs Map<string, Object> values for services not already established

configFor

Deliver configuration for a given service.

Parameters

clearPreserved

Forget about preserved config of a service.

Parameters

configureValue

Set config entry.

Parameters

  • key string path to the value
  • value any

configure

Parameters

autostart

We always start immediate.

Returns boolean true

name

Returns string 'config'

merge

Merge from b into a. When a and b are arrays of values only the none duplicates are appendend to a.

Parameters

  • a any
  • b any

Returns any merged b into a

defineServiceConsumerProperties

Assign services based on a configuration.

Parameters

ServiceLogger

Extends Service

Log receiving service.

autostart

We always start immediate.

Returns boolean true

name

Returns string 'logger'

endpoints

Adds a log input endpoint to the set of Service endpoints.

Returns Object predefined endpoints

ServiceProviderMixin

Provide services and hold service configuration. By default a service provider has two build in services 'logger' and 'config'.

Parameters

  • superclass
  • serviceLoggerClass (optional, default ServiceLogger)
  • serviceConfigClass (optional, default ServiceConfig)

Service

Extends EndpointsMixin(StateTransitionMixin(LogLevelMixin(class {}), prepareActions({ start: { stopped: rsfDefault }, restart: { stopped: rsfDefault, running: { target: "running", during: "restarting", timeout } }, stop: { running: ssfDefault, starting: ssfDefault, failed: ssfDefault } }), "stopped"))

Service The initial state is 'stopped'. All services have at least three endpoints:

  • log out: log events
  • config in: configuration request
  • command in: administrative actions to be executed by the step

Parameters

  • config Object

    • config.name string
    • config.logLevel string
    • config.autostart boolean defaults to false
    • config.description string human readable description
    • config.endpoints Object will be merged with the build in ones
  • ic InitializationContext

Properties

extendetName

Used in human readable state messages. Besides the actual service name it may contain additional short hints.

Returns string

stateChanged

Called when the service state changes. Emits a serviceStateChanged event to the owner.

Parameters

rejectWrongState

Called when state transition is not allowed.

Parameters

  • action string originating action name
  • Throws any always

timeoutForTransition

Deliver transition timeout.

Parameters

Returns number milliseconds before throwing for a long running transition

_start

Opens all endpoint connections.

_stop

Closes all endpoint connections.

_restart

Restart action. default implementation does a _stop() and a _start()

Returns Promise fulfills after start

restartIfRunning

Restarts if in running mode. Otherwise does nothing.

Returns Promise resolves when restart is done (or immediate if no restart triggered)

toStringAttributes

Mapping of properties used in toString.

Returns Object

isServiceProvider

Base service is not a provider.

Returns boolean false

toString

Returns the string representation of this service.

Returns string human readable name

toJSONWithOptions

Deliver json representation.

Parameters

  • options Object

    • options.includeRuntimeInfo boolean include runtime informtion like state
    • options.includeDefaults boolean include default endpoints
    • options.includeName boolean include name of the service
    • options.includeConfig boolean include config attributes
    • options.includePrivate boolean include private config attributes

Returns Object json representation

name

Defaults to the type.

Returns string type

autostart

Should we start when beeing registered.

Returns boolean false

_configure

Takes attribute values from config parameters and copies them over to the object. Copying is done according to configurationAttributes. Which means we loop over all configuration attributes. and then for each attribute decide if we use the default, call a setter function or simply assign the attribute value.

Parameters

Returns Set of modified attributes

configure

Use new configuration. Internally calls _configure(config) as the constructor does. If attribute with needsRestart are touched the restartIfRunning method will be called.

Parameters

Returns Promise fillfills when config is applied

log

Adds service name to the log event.

Parameters

configurationAttributes

Meta information for the config attributes.

  • default optional default value of the attribute
  • needsRestart optional modification requires a service restart
  • setter(newValue,attribute) optional function to be used if simple value assignment is not enough The Service class only defines the logLevel, and start/stop/restart timeout attribute

Returns Object

endpoints

Definition of the predefined endpoints.

  • log out
  • config in

Returns Object predefined endpoints

StandaloneServiceProvider

Extends ServiceProviderMixin(Service)

Simple service manager (for examples and testing only).

name

Returns string 'standalone-provider'

install

With npm do:

npm install @kronos-integration/service

license

BSD-2-Clause