@empyria/moleculer

中文文档
0.1.29发布于 2026/11/01MITES Module

Moleculer helpers for Empyria

原始使用文档
文档目录7 节
  1. Requirements
  2. Install
  3. Usage
  4. Modules
  5. Known limitation: ConnectorMixin
  6. Scripts
  7. License

@empyria/moleculer

Moleculer helpers for Empyria, a nanoservice framework built primarily on Bun: a base service mixin, and a context-validating guard middleware against unwanted (unauthenticated or cross-federation) access.

Requirements

  • Bun >=1.4.0 or Node.js >=26
  • Plain ESM, no build step, no TypeScript

Both requirements come from @empyria/classification and @empyria/common, which this package depends on and which use the native Temporal global for all date/time handling.

Install

bun add @empyria/moleculer

Usage

import { ServiceBroker } from 'moleculer'
import { BaseMixin, MetaGuard } from '@empyria/moleculer'

const broker = new ServiceBroker({
    middlewares: [MetaGuard({ resolveUser: true, whitelistedActions: ['v1.Internal.action'] })],
})

broker.createService({
    name: 'my-service',
    mixins: [BaseMixin],
    actions: {
        hello(ctx) {
            return `Hello, ${ctx.meta.user.actor}`
        },
    },
})

Everything is re-exported from the package root via Mixins.js. The broker connection helper and lower-level utilities are separate subpath exports, importable directly:

import { connect } from '@empyria/moleculer/Connector.js'
import { hashPassword, verifyPassword } from '@empyria/moleculer/util/Crypto.js'

Modules

ModulePurpose
Mixins.jsPackage entry point; re-exports BaseMixin and MetaGuard.
MetaGuard.middleware.jsMetaGuard — a Moleculer middleware guarding actions/events against unwanted access, with optional caller resolution.
mixins/Base.mixin.jsBaseMixin — stamps a Empyria meta (actor/federation/flow/process IDs) on service start, and exposes the package version.
mixins/Connector.mixin.jsConnectorMixin — adds optional Redis/Mongo setup. Not yet exported from Mixins.js — see below.
Connector.jsconnect — starts a Moleculer broker and waits for required services.
util/Context.jsContext helpers: getParams, getUser, validateContext, actionStamped, timeStamped, checkDefined.
util/Crypto.jsHashing, Ed25519 signing/verification, and password hashing (hashPassword/verifyPassword).

Known limitation: ConnectorMixin

mixins/Connector.mixin.js imports @empyria/redis and @empyria/mongo, which aren't published as standalone packages yet. It's intentionally left out of the Mixins.js barrel so the rest of the package stays importable — until those two are published, use it only via a direct subpath import (@empyria/moleculer/mixins/Connector.mixin.js), where it will fail to resolve.

Every exported function is documented with JSDoc directly in its source file — hovering a function in VSCode or Zed shows its parameters and return type without any extra tooling, since both editors read JSDoc from plain .js files automatically.

Tests live under test/, one file per module, separate from the sources. Several exercise a real moleculer ServiceBroker rather than mocks.

Scripts

bun run format       # check formatting (oxfmt)
bun run format:fix   # apply formatting
bun run lint         # lint (oxlint)
bun run lint:fix     # lint and fix
bun run test         # run tests with coverage

License

MIT © Imre Fazekas

版本与发布记录

@empyria/moleculer 共发布 28 个版本,首次发布于 2026/08/16;过去 12 个月发布了 28 个版本。

版本发布日期距今
0.1.29latest2026/11/012 天前
0.1.282026/10/295 天前
0.1.272026/10/259 天前
0.1.262026/10/2311 天前
0.1.252026/10/1815 天前
0.1.242026/10/1618 天前

关于 @empyria/moleculer 的常见问题

@empyria/moleculer 是什么?

emyria的分子帮手

如何安装 @empyria/moleculer?

在项目目录运行 npm install @empyria/moleculer,或使用 pnpm add / yarn add / bun add。

@empyria/moleculer 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/empyria__moleculer 是否存在。

@empyria/moleculer 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@empyria/moleculer 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@empyria/moleculer 可以商用吗?

@empyria/moleculer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@empyria/moleculer 还在维护吗?

最新版本 0.1.29 发布于 2026/11/01(2 天前);至今共发布 28 个版本,其中过去 12 个月发布了 28 个;首次发布于 2026/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。