Seneca Basic Utility Plugin
seneca-basic is a foundational utility plugin for the Seneca.js microservices framework. It provides a small, essential set of action patterns for internal per-process communication, primarily through a 'notes' mechanism, allowing plugins to store and retrieve keyed values or lists. These patterns include `set`, `get`, `push`, `list`, and `pop` for `role:basic, note:true` actions. The package is often bundled by default within the main `seneca` module, simplifying its integration for most users. Its current stable version is 1.0.0, though the latest detailed release notes visible are from v0.5.0 in 2016, indicating a mature and stable, rather than rapidly evolving, project. Release cadence is infrequent, likely tied to Seneca's own maintenance cycles. Its key differentiator is its tightly integrated role within the Seneca ecosystem, providing a lightweight, built-in mechanism for internal plugin coordination without external dependencies.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use CommonJS `require()` in an ECMAScript module (ESM) context without proper setup.fixEnsure your file is treated as a CommonJS module (e.g., `.js` file without `"type": "module"` in `package.json`, or explicitly `.cjs` extension). Alternatively, if using ESM, use `import()` or `createRequire` for compatibility. -
Error: Seneca: plugin 'basic' already exists.
cause The 'basic' plugin is being loaded twice because it's included by default and then explicitly loaded again via `seneca.use()` without disabling the default.fixWhen initializing Seneca, disable the default `basic` plugin: `const seneca = require('seneca')({ default_plugins: { 'basic': false } })`. -
Error: seneca: no action found for pattern { role: 'basic', note: true, cmd: 'set', ... }cause The `seneca-basic` plugin has not been successfully loaded into the Seneca instance.fixVerify that `seneca.use(require('seneca-basic'))` is correctly called and that no errors occurred during plugin loading. Ensure `default_plugins.basic` is set to `false` if loading explicitly.
Warnings
- breaking Version 0.5.0 of seneca-basic dropped support for Node.js versions 0.10, 0.12, and 5. Ensure you are running Node.js 6 or higher for compatibility.
- gotcha seneca-basic is typically included by default when you initialize a Seneca instance. If you intend to explicitly load it via `seneca.use(require('seneca-basic'))`, you must disable its default inclusion first, otherwise the plugin may be registered twice or behave unexpectedly.
- gotcha This package, like the core Seneca.js framework, is built with CommonJS modules in mind. Attempting to use ES module `import` syntax directly will result in errors in a standard Node.js environment without a transpiler or CommonJS wrapper.
- gotcha The package's primary purpose is for internal note-taking within a Seneca microservice process. It is not designed as a general-purpose key-value store or inter-process communication mechanism across different microservices or external applications.
Install
-
npm install seneca-basic -
yarn add seneca-basic -
pnpm add seneca-basic
Imports
- seneca
import seneca from 'seneca'
const seneca = require('seneca') - seneca-basic plugin
import senecaBasic from 'seneca-basic'
seneca.use(require('seneca-basic')) - Basic plugin config
const seneca = require('seneca')().use('basic')const seneca = require('seneca')({ default_plugins: { 'basic': false } })
Quickstart
const seneca = require('seneca')({
default_plugins: {
'basic': false
}
})
seneca.use(require('seneca-basic'))
async function run() {
// Set a note
await seneca.act({ role: 'basic', note: true, cmd: 'set', key: 'myKey', value: 'Hello Seneca!' })
console.log('Note 'myKey' set.')
// Get a note
const resultGet = await seneca.act({ role: 'basic', note: true, cmd: 'get', key: 'myKey' })
console.log(`Retrieved 'myKey': ${resultGet.value}`)
// Push to a list
await seneca.act({ role: 'basic', note: true, cmd: 'push', key: 'myList', value: 10 })
await seneca.act({ role: 'basic', note: true, cmd: 'push', key: 'myList', value: 20 })
console.log('Pushed values to 'myList'.')
// Get the list
const resultList = await seneca.act({ role: 'basic', note: true, cmd: 'list', key: 'myList' })
console.log(`Retrieved 'myList': ${resultList.value}`)
// Pop from the list
const resultPop = await seneca.act({ role: 'basic', note: true, cmd: 'pop', key: 'myList' })
console.log(`Popped from 'myList': ${resultPop.value}`)
const finalResultList = await seneca.act({ role: 'basic', note: true, cmd: 'list', key: 'myList' })
console.log(`'myList' after pop: ${finalResultList.value}`)
await seneca.close()
console.log('Seneca instance closed.')
}
run().catch(console.error)