// Creates a note — requires the `notes:write` scope, declared DECLARATIVELY. // // This is the form to reach for by default. The framework enforces it in the // dispatch spine: before the executor, and before the transaction opens, so an // unauthorized call never touches the DB. It also lands in the capability // manifest, which is what lets `voltro check` fail on a guard requiring a scope // no role grants — an in-handler `permission()` call is invisible to that // check. Compare `notes.delete`, which needs the in-handler form for a reason. // // Declaring `guards:` merges the framework-wide `ScopeError` into the // descriptor's error union automatically, so the client receives the denial // typed without an explicit `error:` field. `ScopeError` is the ONE denial tag // — declarative guards and `permission()` both fail with it, so a client // branches once. import { defineMutation } from '@voltro/protocol' import { Schema } from 'effect' export const createNote = defineMutation({ name: 'notes.create', target: { table: 'notes', op: 'insert' }, guards: [{ scope: 'notes:write' }], input: Schema.Struct({ title: Schema.NonEmptyString, body: Schema.String, }), output: Schema.Struct({ id: Schema.String, title: Schema.String, body: Schema.String, tenantId: Schema.String, }), })