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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@webspaceiq/service-objects

v0.1.0

Published

> A small TypeScript library for defining, looking up and executing user defined service objects.

Downloads

4

Readme

Service Objects

A small TypeScript library for defining, looking up and executing user defined service objects.

A service is a user defined class that implements the IService interface.

export interface IService<T, U> {

    execute(context: IServiceContext<T>): U;
}

Additionally a service has a constructor interface.

export interface IServiceConstructor {

    new(...args: any[]): IServiceInterface; 

    /**
     * Every service class has a static 
     * serviceName property
     */   
    serviceName: string;
}

This library defines an API for creating, storing, looking up and executing services. This is achieved with the help of service executors, service repositories and decorators.

import { IExecutionContext, IServiceInterface, IServiceConstructor } from "@alstradocs/service-objects";

export interface IServiceExecutor {

    executeService<T, U>(context: IExecutionContext<T>): U
}

export interface IServiceRepository {

    get(serviceName: string): IServiceInterface;

    register(serviceName: string, serviceConstructor: IServiceConstructor): void;
}

Installation

NPM:

npm install @alstradocs/service-objects --save

Usage example

1. Define Services

First you need a service. You can simply annotate a class with the @IsService decorator.

import { IsService, IServiceContext } from "@alstradocs/service-objects";

interface BinaryOperands {
    firstOperand: number;
    secondOperand: number;
}

@IsService()
class AdditionService {

    public static serviceName = 'AdditionService';

    execute(context: IServiceContext<BinaryOperands>): number {
        let { firstOperand, secondOperand } = context.data;
        return firstOperand + secondOperand;
    }
}

2. Instantiate/Define Service Repository

Next you add your shining new service to an instance of IServiceRepository. A service repository is just a fancy name for a service store. You can use the default repository

import { ServiceRepository } from "@alstradocs/service-objects";

// Initialize service repo with just a single service ...
let serviceInfo = { 
        serviceName:AdditionService.serviceName, 
        serviceContructor: AdditionService 
};
let repository = new ServiceRepository([serviceInfo]);

// ... or add to existing repo
repository.register(AdditionService.serviceName, AdditionService);

Or you can implement your own repository

import { IsServiceRepository, IServiceConstructor } from "@alstradocs/service-objects";

@IsServiceRepository()
export class MyServiceRepository {

    get(serviceName: string): IServiceInterface {
        ...
    }

    register(serviceName: string, serviceConstructor: IServiceConstructor): void {
        ...
    }
}
// ... Instantiate repo and add service
let repository = new MyServiceRepository();
repository.register(AdditionService.serviceName, AdditionService);

3. Define/Instanstiate A Service Execcutor

To execute your service, you need an instance of IServiceExecutor. The service executor is a object that knows how to find and execute services. It uses the service repository for this. You can use the default executor.

import { ServiceRepository } from "@alstradocs/service-objects";

let repository = // initialize repo
// instantiate executor with given repo
let serviceExecutor = new ServiceExecutor(repository);

Or you can implement your own executor

import { IsServiceExecutor, IExecutionContext } from "@alstradocs/service-objects";

@IsServiceExecutor()
export class MyServiceExecutor {
    
    executeService<T, U>(context: IExecutionContext<T>): U {
        ...
    }
}
// ... instantiate and execute (context contains all info required to execute a service)
let serviceExecutor = new MyServiceExecutor();

4. Execute Service

The final step is executing the service.

serviceExecutor.executeService(context);

Typically all the entire setup above (apart from step 4) will be done once before or during app/script inititialization. You can then store the executor app/script wide and make it available to execute services as needed.

For more examples and usage, please refer to the source code.

Release History

  • 1.0.0
    • Work in progress

Meta

Edward Banfa – @EdwardBanfa[email protected]

Distributed under the Apache license. See LICENSE for more information.

https://github.com/alstradocs/service-objects

Readme Image

robot clipart png from pngtree.com