Skip to content

Lifecycle

When you create a minion:

  1. A UUID v4 id is generated
  2. createdAt and updatedAt are set to the current time
  3. Fields are validated against the MinionType schema
  4. Default values from the schema are applied
  5. status defaults to "active" if not specified
import { createMinion } from 'minions-sdk';
const { minion, validation } = createMinion({
title: 'My Note',
fields: { content: 'Hello world' },
}, noteType);
if (!validation.valid) {
console.error(validation.errors);
}

Updates merge new field values with existing ones. updatedAt is refreshed.

import { updateMinion } from 'minions-sdk';
const { minion: updated } = updateMinion(existing, {
fields: { content: 'Updated content' },
}, noteType);

Soft delete marks a minion as deleted without removing it. Relations are preserved.

import { softDelete } from 'minions-sdk';
const deleted = softDelete(minion, 'user-123');
// deleted.deletedAt is set
// deleted.deletedBy is 'user-123'

Restoring clears the deletion markers.

import { restoreMinion } from 'minions-sdk';
const restored = restoreMinion(deleted);
// restored.deletedAt is null

Hard delete permanently removes the minion. All relations involving it must also be removed.

import { hardDelete } from 'minions-sdk';
hardDelete(minion, graph); // clean up relations
myMinionStore.delete(minion.id); // then remove from your storage