phantomaton-plugins

0.0.2 • Public • Published

Phantomaton Plugins 🔌

A simplified and more expressive way to create plugins for the Phantomaton AI framework.

Installation 📦

npm install phantomaton-plugins

Usage 🛠️

import plugins from 'phantomaton-plugins';

// Create a plugin that exposes extension points
const api = plugins.create({
  message: plugins.singleton,
  effects: plugins.composite
});

// Create a plugin that provides implementations
const impl = plugins.create([
  plugins.define(api.message).as('Hello, world!'),
  plugins.define(api.effects).as(msg => console.log(msg))
]);

Plugin Creation Patterns 🎭

The plugins.create function supports several argument patterns for flexibility:

Extension Point Declaration

// First argument can be an object mapping names to extension point types
const api = plugins.create({
  single: plugins.singleton,
  many: plugins.composite,
  maybe: plugins.optional
});

Instance Creation

// A function that takes config and returns an instance
const plugin = plugins.create(config => ({
  value: config.someValue
}));

Component Installation

Components can be provided either as an array:

// Static array of components to install
const plugin = plugins.create([
  plugins.define(other.extension).as(value)
]);

Or as a function that receives context:

// Function receiving { configuration, extensions, instance }
const plugin = plugins.create(({ instance }) => [
  plugins.define(other.extension).as(instance.value)
]);

Combining Patterns

These patterns can be combined, with arguments processed in order:

  1. Extension point declarations (object)
  2. Instance creator (function, if not last argument)
  3. Component installer (array or function, must be last argument)
const plugin = plugins.create(
  { api: plugins.singleton },      // Extension points
  config => ({ foo: config.foo }), // Instance creator
  ({ instance }) => [             // Component installer
    plugins.define(other.ext).as(instance.foo)
  ]
);

Entry Points 🚪

The library includes start and input extension points from priestess for defining application entry points:

const main = plugins.create([
  plugins.define(plugins.start)
    .with(plugins.input)
    .as(input => () => console.log(input))
]);

Dependencies 🔗

Built on top of:

Contributing 🦄

We welcome contributions to the Phantomaton Plugins project! If you have any ideas, bug reports, or pull requests, please feel free to submit them on the Phantomaton Plugins GitHub repository.

License 📜

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i phantomaton-plugins

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

12.2 kB

Total Files

9

Last publish

Collaborators

  • phantomaton