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

pict-serviceproviderbase

v1.0.3

Published

Simple base classes for pict services.

Readme

Pict Service Provider Base

Base class for creating services that integrate with the Pict application framework. Extends fable-serviceproviderbase to add a this.pict reference, bridging the generic Fable service infrastructure into the Pict ecosystem.

How It Relates to Fable

Retold's service architecture has two layers:

Your Service
    └── PictServiceProviderBase (this module)
            └── FableServiceProviderBase (fable-serviceproviderbase)

fable-serviceproviderbase provides the foundation: dependency injection via a Fable instance, service registration, UUID/Hash identity, logging and access to other services through the shared services map. It knows nothing about Pict.

This module adds one thing: when connectFable() is called, it also sets this.pict as a reference to the passed-in Fable/Pict instance. Because Pict itself extends Fable, this.pict and this.fable point to the same object. The alias exists so that service code can read naturally when working in a Pict application context.

What You Get from the Fable Layer

Every service that extends this class inherits these properties and behaviors from fable-serviceproviderbase:

| Property | Description | |----------|-------------| | this.fable | The Fable/Pict instance (set on construction or via connectFable) | | this.UUID | Unique identifier, from fable.getUUID() or auto-generated for core services | | this.Hash | Instance key within the service map (defaults to UUID) | | this.options | Configuration object passed at construction | | this.log | Shortcut to fable.Logging | | this.services | Shared map of all registered default service instances | | this.servicesMap | Hierarchical map organized by service type then hash | | this.serviceType | Identifier string (set by your subclass) |

What This Module Adds

| Property | Description | |----------|-------------| | this.pict | Reference to the Pict instance (alias for this.fable) |

The connectFable() override calls super.connectFable() first (which sets up fable, log, services, servicesMap), then assigns this.pict if it has not already been set.

Basic Services

There are two instantiation patterns. The standard pattern takes a fully initialized Pict object:

const libPictServiceProviderBase = require('pict-serviceproviderbase');

class SimpleService extends libPictServiceProviderBase
{
    constructor(pPict, pOptions, pServiceHash)
    {
        super(pPict, pOptions, pServiceHash);

        this.serviceType = 'SimpleService';
    }

    doSomething()
    {
        // this.pict and this.fable are the same object
        this.pict.log.info(`SimpleService ${this.UUID}::${this.Hash} is doing something.`);
    }
}

Register and instantiate through Pict's service manager:

const libPict = require('pict');

// Register the service class
libPict.addServiceType('SimpleService', SimpleService);

// Create Pict instance and instantiate the service
const _Pict = new libPict({ /* settings */ });
const myService = _Pict.instantiateServiceProvider('SimpleService',
    { /* options */ }, 'my-instance');

myService.doSomething();

Core Pre-initialization Services

For services that must exist before Pict is fully initialized, create the service without a Fable instance and connect it later:

const libPictServiceProviderBase = require('pict-serviceproviderbase');

// Use the CoreServiceProviderBase export (same class, semantic alias)
class EarlyService extends libPictServiceProviderBase.CoreServiceProviderBase
{
    constructor(pOptions, pServiceHash)
    {
        super(pOptions, pServiceHash);
        this.serviceType = 'EarlyService';
    }
}

// Create before Pict exists
const earlyService = new EarlyService({ bufferSize: 100 }, 'EarlyService-1');
// earlyService.fable === false at this point
// earlyService.pict === undefined

// Later, after Pict is initialized:
const _Pict = new libPict({ /* settings */ });
_Pict.serviceManager.connectPreinitServiceProviderInstance(earlyService);
// earlyService.fable and earlyService.pict now reference _Pict

The caveat is that log, services, and pict are not available until connectFable() has been called. Code that runs before connection should not depend on those properties.

Pict Services Available to Your Service

Once connected, your service can access everything Pict provides:

// Logging
this.pict.log.info('Message');
this.pict.log.error('Problem');

// Application settings
const val = this.pict.settings.SomeConfigKey;

// UUID generation
const id = this.pict.getUUID();

// Shared application state
this.pict.AppData.myValue = 42;

// Other registered services
this.services.SomeOtherService.doWork();

// Templating
const html = this.pict.parseTemplate('Hello {~Data:Name~}', { Name: 'World' });

Multiple Instances

The service manager supports multiple instances of the same service type, distinguished by their Hash:

_Pict.serviceManager.instantiateServiceProvider('DatabaseService',
    { host: 'primary.db' }, 'PrimaryDB');
_Pict.serviceManager.instantiateServiceProvider('DatabaseService',
    { host: 'replica.db' }, 'ReplicaDB');

// Access by hash
_Pict.serviceManager.servicesMap.DatabaseService.PrimaryDB;
_Pict.serviceManager.servicesMap.DatabaseService.ReplicaDB;

// Switch which instance is the default
_Pict.serviceManager.setDefaultServiceInstantiation('DatabaseService', 'ReplicaDB');
// Now _Pict.serviceManager.services.DatabaseService points to ReplicaDB

Related Packages

License

MIT

Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the Retold Contributing Guide.