// Creates a note — but only if the `newEditor` flag is on for the caller. // The executor uses the IN-HANDLER guard `requireFlag(ctx, 'newEditor')`, which // fails typed `FlagDisabled` when the flag is off. Declaring `error: FlagDisabled` // here surfaces that to the client as a typed, pattern-matchable failure. // // `FlagDisabled` is imported from the browser-safe `/errors` subpath (no // node/db imports) so this descriptor stays safe for the client bundle. import { defineMutation } from '@voltro/protocol' import { FlagDisabled } from '@voltro/plugin-flags/errors' import { Schema } from 'effect' export const createNote = defineMutation({ name: 'notes.create', target: { table: 'notes', op: 'insert' }, // `requireFlag(ctx, 'newEditor')` in the executor answers "is this feature // switched on"; this line answers "who may call it". Two different questions // — a flag flipped on for everyone would otherwise silently answer both. // // Open because no auth strategy and no rbac ship here, so every caller is an // anonymous Subject holding no scopes and a `guards: [{ scope }]` would deny // all of them. The write carries only what the caller sent, into the tenant // on the request. openAccess: 'inserts a note built only from caller-supplied fields into the request\'s tenant. The ' + '`newEditor` flag decides whether the feature runs; this decides who may call it — a ' + 'release control is not an access decision.', input: Schema.Struct({ tenantId: Schema.String, title: Schema.NonEmptyString, body: Schema.String, }), output: Schema.Struct({ id: Schema.String, title: Schema.String, body: Schema.String, tenantId: Schema.String, }), error: FlagDisabled, })