Skip to content

defineActions

function defineActions<T>(actions): T;

Defined in: src/standard-schema.ts:108

Declare the typed action catalog. Identity at runtime; preserves the literal types so core.record() can infer action names and metadata shapes.

Type Parameter
T extends ActionMap
Parameter Type
actions T

T

import * as v from "valibot";
import { createAuditCore, defineActions } from "@xtandard/audit";
const actions = defineActions({
"invoice.paid": {
metadata: v.object({ invoiceId: v.string(), amount: v.number() }),
targets: ["invoice"],
description: "An invoice was paid",
},
"member.removed": { targets: ["user"] },
});
const audit = createAuditCore({ storage, actions });
await audit.record({
tenant: "acme",
action: "invoice.paid", // ← autocompletes; typos are compile errors
actor: { id: "user_1" },
metadata: { invoiceId: "inv_1", amount: 4200 }, // ← typed
});