Skip to content
Back to skills

Hive Handler

ASecurity

How to create event handlers in Hive framework

  • 57 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added May 31, 2026
developmentjavascriptjavareactdatabase

Security analysis

A100/100

Scanned May 31, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill hive-handler --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hive Handler?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hive Handler
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-hive-handler/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-hive-handler)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: hive-handler
description: How to create event handlers in Hive framework
globs:
  - src/resources/**/handlers/*.js
alwaysApply: false
---

# Creating Event Handlers

Handlers react to database events automatically.

Location: `/src/resources/{name}/handlers/{handlerName}.js`

## Template

```javascript
import db from 'db';

const myService = db.services.myResource;

myService.on('created', async ({ doc }) => {
  // Handle creation
});

myService.on('updated', async ({ doc, prevDoc }) => {
  // Handle update
});

myService.on('removed', async ({ doc }) => {
  // Handle removal
});
```

## Events

| Event | Payload | Trigger |
|-------|---------|---------|
| `created` | `{ doc }` | After `service.create()` |
| `updated` | `{ doc, prevDoc }` | After `service.updateOne/Many()` |
| `removed` | `{ doc }` | After `service.remove()` |

## Common Patterns

**Create related record:**
```javascript
taskService.on('created', async ({ doc }) => {
  await eventService.create({
    type: 'task.created',
    data: { task: doc },
    project: doc.project,
  });
});
```

**Update parent on child change:**
```javascript
docService.on('created', async ({ doc }) => {
  if (doc.role === 'case-study') {
    await projectService.updateOne(
      { _id: doc.project._id },
      (p) => ({ ...p, caseStudy: doc })
    );
  }
});
```

**React to specific field change:**
```javascript
import ifUpdated from 'helpers/db/ifUpdated';

taskService.on('updated', ifUpdated(['status'], async ({ doc, prevDoc }) => {
  // Only runs when status changed
}));
```

**Cleanup on delete:**
```javascript
docService.on('removed', async ({ doc }) => {
  await eventService.remove({ 'data.doc._id': doc._id });
});
```

## Rules

- Keep handlers fast (don't block response)
- Use `atomic.update` for silent bulk updates (no events)
- Use `ifUpdated` helper to filter field changes

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.