// Create a note + record a CUSTOM Prometheus metric. // // `counter(name, desc)` registers a metric in Effect's global MetricRegistry — // the same registry GET /metrics (prometheusPlugin) and the DevTools Metrics // panel both read, so your counter shows up in both with no extra wiring. // We keep the handler ASYNC (so the test can `await execute(input, ctx)`) and // bump the counter with a tiny `Effect.runSync` — Metric.increment is a // synchronous effect. import { Effect, Metric } from 'effect' import type { AppContext } from '@voltro/runtime' import { counter } from '@voltro/runtime' // Module-level so it's the SAME metric across every call (not re-created). const notesCreated = counter('app_notes_created_total', 'Notes created via notes.create.') const execute = async (input: { title: string; body: string }, ctx: AppContext) => { Effect.runSync(Metric.increment(notesCreated)) // → app_notes_created_total in /metrics // tenant() auto-stamps tenantId (+ audit columns) from ctx.request.subject. // `done: false` is set explicitly — a column DEFAULT only fills in on a SQL // store; the memory store leaves an omitted column null, which would fail the // `done: Schema.Boolean` output encode over the rpc wire. const row = await ctx.store.insert('notes', { title: input.title, body: input.body, done: false }) return { id: row['id'] as string, title: row['title'] as string, body: row['body'] as string, done: row['done'] as boolean, tenantId: row['tenantId'] as string, } } export default execute