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-provider

v1.0.12

Published

Pict Provider Base Class

Readme

Pict Provider

The base class for Pict data providers. Extends fable-serviceproviderbase with lifecycle hooks for initialization, rendering, solving, and data loading, giving providers access to Pict's application state, logging, and template engine.

Build Status npm version License: MIT


Features

  • Service Provider Pattern - Registers with a Pict instance via dependency injection, gaining access to logging, configuration, and other services
  • Lifecycle Hooks - Override onInitialize, onPreRender, onPreSolve, onLoadDataAsync, and onSaveDataAsync to add custom behavior at each stage
  • Sync and Async - Every lifecycle method has both synchronous and async (callback-based) variants
  • Auto-Initialize - Providers can initialize automatically when the Pict application starts, with configurable ordinal for ordering
  • Auto-Solve - Providers can participate in the application solve cycle automatically
  • Template Registration - Declare default templates in the provider options and they are registered with the Pict template engine on construction
  • TypeScript Definitions - Ships with .d.ts type definitions
  • AppData Access - Direct access to this.AppData and this.Bundle for shared application state

Installation

npm install pict-provider

Quick Start

const libPictProvider = require('pict-provider');

class WeatherProvider extends libPictProvider
{
	constructor(pFable, pOptions, pServiceHash)
	{
		super(pFable, pOptions, pServiceHash);
		this.serviceType = 'WeatherProvider';
	}

	onInitialize()
	{
		this.log.info('WeatherProvider initialized');
		return true;
	}

	onLoadDataAsync(fCallback)
	{
		// Fetch weather data and store it in AppData
		this.AppData.Weather = { temperature: 72, condition: 'Sunny' };
		return fCallback();
	}
}

// Register with a Pict instance
let _Pict = new (require('pict'))();
let _Weather = _Pict.addProvider('Weather', {}, WeatherProvider);
_Weather.initialize();

Lifecycle

Providers participate in the Pict application lifecycle through hookable methods. Each phase has three stages (before, main, after) and both sync and async variants.

Initialization

Called once when the provider is initialized, either manually or automatically when the application starts.

| Method | Async Variant | Description | |--------|---------------|-------------| | onBeforeInitialize() | onBeforeInitializeAsync(fCallback) | Pre-initialization setup | | onInitialize() | onInitializeAsync(fCallback) | Main initialization logic | | onAfterInitialize() | onAfterInitializeAsync(fCallback) | Post-initialization cleanup |

onInitializeAsync(fCallback)
{
	this.log.info('Loading configuration...');
	// Perform async setup
	return fCallback();
}

Rendering

Called when the provider's render cycle is triggered.

| Method | Async Variant | Description | |--------|---------------|-------------| | onPreRender() | onPreRenderAsync(fCallback) | Pre-render logic | | render() | renderAsync(fCallback) | Trigger the render cycle |

Solving

Called during the application solve cycle, used for computing derived state.

| Method | Async Variant | Description | |--------|---------------|-------------| | onPreSolve() | onPreSolveAsync(fCallback) | Pre-solve logic | | solve() | solveAsync(fCallback) | Trigger the solve cycle |

Data Loading

Called during the application data load phase.

| Method | Description | |--------|-------------| | onBeforeLoadDataAsync(fCallback) | Pre-load hook | | onLoadDataAsync(fCallback) | Main data loading logic | | onAfterLoadDataAsync(fCallback) | Post-load hook |

Data Saving

Called during the application data save phase.

| Method | Description | |--------|-------------| | onBeforeSaveDataAsync(fCallback) | Pre-save hook | | onSaveDataAsync(fCallback) | Main data saving logic | | onAfterSaveDataAsync(fCallback) | Post-save hook |

Configuration

Pass options when registering the provider:

let _Provider = _Pict.addProvider('MyProvider',
{
	ProviderIdentifier: 'MyProvider',

	AutoInitialize: true,
	AutoInitializeOrdinal: 0,

	AutoLoadDataWithApp: true,

	AutoSolveWithApp: true,
	AutoSolveOrdinal: 0,

	Manifests: {},

	Templates:
	[
		{
			Prefix: 'MyPrefix',
			Postfix: '-MyTemplate',
			Template: '<div>{~Data:Record.Name~}</div>'
		}
	]
}, MyProviderClass);

| Option | Type | Default | Description | |--------|------|---------|-------------| | ProviderIdentifier | String | Auto-generated UUID | Human-readable identifier for logging | | AutoInitialize | Boolean | true | Initialize automatically when the app starts | | AutoInitializeOrdinal | Number | 0 | Initialization order (lower runs first) | | AutoLoadDataWithApp | Boolean | true | Participate in the app data load cycle | | AutoSolveWithApp | Boolean | true | Participate in the app solve cycle | | AutoSolveOrdinal | Number | 0 | Solve order (lower runs first) | | Manifests | Object | {} | Manifest definitions for the provider | | Templates | Array | [] | Default templates to register on construction |

Properties

Every provider instance has access to these properties:

| Property | Type | Description | |----------|------|-------------| | this.pict | Pict | The Pict instance (same as this.fable) | | this.AppData | Object | Shared application state | | this.Bundle | Object | Application bundle data | | this.log | Object | Logger instance | | this.options | Object | Merged configuration options | | this.UUID | String | Unique identifier for this provider instance | | this.Hash | String | Service hash for registry lookup | | this.initializeTimestamp | Number\|false | Timestamp of initialization, or false if not yet initialized | | this.lastSolvedTimestamp | Number\|false | Timestamp of last solve, or false if not yet solved |

Part of the Retold Framework

Pict Provider is the base class used throughout the Pict ecosystem:

Testing

Run the test suite:

npm test

Run with coverage:

npm run coverage

Related Packages

  • pict - MVC application framework
  • pict-view - View base class
  • fable - Application services framework

License

MIT

Contributing

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