Lifecycle
Creation
Section titled “Creation”When you create a minion:
- A UUID v4
idis generated createdAtandupdatedAtare set to the current time- Fields are validated against the MinionType schema
- Default values from the schema are applied
statusdefaults 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);}from minions import create_minionfrom minions.schemas import note_type
minion, validation = create_minion( {"title": "My Note", "fields": {"content": "Hello world"}}, note_type,)
if not validation.valid: print(validation.errors)Update
Section titled “Update”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);from minions import update_minion
updated, validation = update_minion( existing, {"fields": {"content": "Updated content"}}, note_type,)Soft Delete
Section titled “Soft Delete”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'from minions import soft_delete
deleted = soft_delete(minion, "user-123")# deleted.deleted_at is set# deleted.deleted_by is "user-123"Restore
Section titled “Restore”Restoring clears the deletion markers.
import { restoreMinion } from 'minions-sdk';
const restored = restoreMinion(deleted);// restored.deletedAt is nullfrom minions import restore_minion
restored = restore_minion(deleted)# restored.deleted_at is NoneHard Delete
Section titled “Hard Delete”Hard delete permanently removes the minion. All relations involving it must also be removed.
import { hardDelete } from 'minions-sdk';
hardDelete(minion, graph); // clean up relationsmyMinionStore.delete(minion.id); // then remove from your storagefrom minions import hard_delete
hard_delete(minion, graph) # clean up relationsmy_minion_store.delete(minion.id) # then remove from your storage