@bernierllc/nevar-mixin-bridge
v0.1.0
Published
Utilities for building withX() mixin functions for the Nevar rules engine
Readme
@bernierllc/nevar-mixin-bridge
Mixin definition utilities for the Nevar rules engine. Allows domain-specific extensions to register triggers, operators, actions, and context providers onto a Nevar instance under a namespace.
Installation
npm install @bernierllc/nevar-mixin-bridgeUsage
import { defineMixin } from '@bernierllc/nevar-mixin-bridge';
import type { MixinDefinition } from '@bernierllc/nevar-mixin-bridge';
import { z } from 'zod';
const ecommerceMixin = defineMixin('ecommerce', {
triggers: [
{
key: 'order.placed',
payloadSchema: z.object({ orderId: z.string(), total: z.number() }),
description: 'Fires when an order is placed',
category: 'commerce',
},
],
operators: [
{
name: 'currency_gt',
definition: {
label: 'Currency Greater Than',
category: 'commerce',
evaluate: (field, target) => Number(field) > Number(target),
schema: z.number(),
fieldTypes: ['number'],
},
},
],
actions: [
{
actionType: 'send-receipt',
definition: {
execute: async (config, context) => {
// Send receipt logic
return { sent: true };
},
},
},
],
contextProviders: [
{
prefix: 'order',
provider: async (payload) => ({
total: 99.99,
currency: 'USD',
}),
},
],
methods: {
getOrderStatus: (orderId: string) => 'shipped',
},
});
// Apply to a Nevar instance
ecommerceMixin(nevar);
// Methods are accessible under the namespace
// nevar.ecommerce.getOrderStatus('order-1')API
defineMixin(namespace, definition)
Creates a mixin function that can be applied to a Nevar instance. The returned function registers all triggers, operators, actions, and context providers defined in the mixin, and mounts any methods at nevar[namespace].
Parameters:
namespace: string- The namespace to mount methods underdefinition: MixinDefinition- The mixin definition containing triggers, operators, actions, context providers, and methods
Returns: (nevar: NevarLike) => void - A function that applies the mixin to a Nevar instance
Throws: NevarValidationError if the namespace is already registered on the instance.
Types
MixinDefinition- Complete mixin definition with optionaltriggers,operators,actions,contextProviders, andmethodsMixinTrigger- Trigger definition withkey,payloadSchema, optionaldescriptionandcategoryMixinOperator- Operator definition withnameanddefinition: OperatorDefinitionMixinAction- Action definition withactionTypeanddefinition: ActionHandlerDefinitionMixinContextProvider- Context provider withprefixandproviderfunctionActionHandlerDefinition- Action handler withexecutefunction and optionaldescriptionNevarLike- Minimal interface for a Nevar instance that supports registration methods
Integration Documentation
Logger Integration
This package does not integrate with @bernierllc/logger. As a core package, logger integration is optional and not included by default. Consumers should handle logging at the service layer.
NeverHub Integration
This package does not integrate with @bernierllc/neverhub-adapter. As a core package, NeverHub integration is not applicable. NeverHub registration should be handled by service-layer packages that compose this package.
License
Copyright (c) 2025 Bernier LLC. All rights reserved.
