A declarative marker capacity that opts a model's repository operations into metrics. It wraps no methods itself — it only stamps two statics (
isMeterable,meterName) onto the adorned class for a (future) repository boundary to read.
Meterable is the lightest possible kind of capacity: a pure marker. Enabling it
does one thing at compose time — it defines two static fields on the model's class:
| Static | Type | Meaning |
|---|---|---|
isMeterable |
boolean |
true — signals a repository that this model's ops should be timed. |
meterName |
string |
Display prefix for operation metrics (User.load, Post.create, …). |
What it is not:
- It is not a behaviour capacity. It adds no instance methods, no statics beyond the two above, no lifecycle hooks, no events.
- It does not itself time anything. The actual timing is supposed to happen at the
repository boundary, which reads
isMeterable/meterNameand calls a telemetry recorder. - It is not currently wired to any consumer in this codebase (see §6 — this is a real gap, not a usage error on your part).
In the capacity taxonomy it sits alongside Queriable, Servable, Referencible,
Aggregable as a marker / opt-in capacity: declare it, and a downstream layer
should react — but in this repo the downstream layer does not exist yet.
Meterable has no schema marker type (no MeterableSchema, unlike
ImmutableSchema / VersionableSchema / Hashable, and no RandomisableSchema). It
is purely infrastructural, like Clonable and Comparable.
It is registered in compose.ts's REGISTRY (["Meterable", Meterable] at
compose.ts:206), so — unlike Referencible — it works in both declarative forms:
- ARRAY:
{ capacity: Meterable, options: { name: "User" } }or[Meterable] - OBJECT:
{ Meterable: { name: "User" } }(resolved viaREGISTRY)
An unknown object-form name still throws, but Meterable is a known name.
export const Meterable = <TBase extends CapacityComposer>(
Base: TBase,
_mod?: any,
options: MeterableOptions = {},
_ctx?: ComposeContext,
) => {
const MeterableClass = class extends (Base as any) {
static isMeterable = true;
static meterName = options.name ?? (Base as any).schemaName ?? Base.name;
};
return MeterableClass as unknown as TBase & MeterableStatic;
};Behaviour notes:
- It returns a new subclass (like
JsonSerialisable,Immutable,Triggerable,Clonable,Comparable,Randomisable), not an in-place mutation likeProtobufEncodableorReferencible. - The two statics are
static, so they live on the class (not the instance) and are visible toRepository/PostRepostatically, without a live instance. isMeterableis alwaystrue(it can't be turned off per-model; you opt out by simply not declaring the capacity).
Enable it like any other capacity, with the optional name (the metric prefix):
import { Meterable } from "@/capacities/meterable";
defineModel(UserSchema, (t) => [
Identifiable,
Validatable,
Persistable, // ← the intended consumer (once it exists)
{ capacity: Meterable, options: { name: "User" } },
// or shorthand: [Meterable] (meterName falls back to schemaName, see §5)
]);In this repo Meterable is enabled on the current models:
| Model | name |
Source |
|---|---|---|
User |
"User" |
src/models/user.ts |
Repository |
"Repository" |
src/models/repository.ts |
Each passes name explicitly, so the metric prefix matches the model name rather than
the schema name.
static meterName = options.name ?? (Base as any).schemaName ?? Base.name;Resolution order (left to right):
options.name— explicit, as in the current models.Base.schemaName— e.g."UserSchema","PostData"— if you omitname.Base.name— the JS class name, the final fallback.
If you omit name, the prefix becomes the schema name, which often differs from
the model/table/route name (e.g. PostData.load instead of Post.load). The
examples always pass name, so this fallback is rarely exercised — but it means the
capacity is not guaranteed to produce a "human" model name on its own.
meterable.ts's docstring claims the timing happens at the repository boundary:
The actual timing happens at the repository boundary —
Repository.meteredforUser, the equivalent private helper inPostRepo— which callsqueryTelemetry.recordOperation(...). That reuses the SAME in-memory collector + OTLP sink the driver-level query metrics use, so operation metrics show up in/debug/operations(dev) and asdb.client.operations.*OTEL metrics (prod).
I grepped the entire src/ tree for every identifier in that claim. None of them
exist as code — they appear only inside comments:
| Claimed identifier | Where it's referenced | Exists as code? |
|---|---|---|
Repository class |
meterable.ts:33, user.ts:215 |
❌ no repository*.ts |
PostRepo |
meterable.ts:34, post.ts:257 |
❌ not present (see versionable.md — PostRepo/version-history store are unimplemented) |
Repository.metered |
meterable.ts:33 |
❌ only in comment |
queryTelemetry module |
meterable.ts:35-37 |
❌ no telemetry*.ts |
recordOperation |
meterable.ts:35 |
❌ only in comment |
/debug/operations route |
meterable.ts:9,37 |
❌ only in comment |
db.client.operations.* |
meterable.ts:37 |
❌ only in comment |
(src/services/ contains only event-bus.ts and transport.ts; there is no
repository or telemetry module.)
Conclusion: Meterable is currently an inert marker. It correctly stamps
isMeterable = true and meterName onto the five models, but nothing reads those
statics. At runtime, enabling it has zero observable effect today.
To make it live, you'd need to:
- Build the repository boundary (a
Repository/PostRepoor an equivalent wrapper around the Drizzle client) that, before each operation, checksModel.isMeterableand, iftrue, starts a timer keyed byModel.meterName + "." + op. - Provide a
queryTelemetrycollector (recordOperation(name, ms, ok)) that buffers in memory and exports OTLP — and wire a/debug/operationsdev route to read it.
Until then, treat Meterable as documentation of intent: "these five models should
be instrumented" — recorded in the capacity list, not yet enforced in code.
- Runtime: two statics on the class. Visible to anything that imports the composed
model class. No instance-side footprint, so it's irrelevant to
Immutablefreeze,Clonabledeep-copy,JsonSerialisableserialisation, andHashable's content address. - Type-level:
compose.ts's fold surfacesMeterableStatic(isMeterable,meterName) as part ofCapacityInstance, so a typedModel.isMeterableis available withoutdeclare. (The two arestatic, so they're not part of the instance shape either way.)
Meterable is orthogonal to every other capacity — it touches neither the instance
nor the schema. It composes cleanly with anything, but its value depends on a
repository boundary that, today, does not exist.
- With
Persistable/SqlSerialisable: the intended consumer would be the repository thatPersistablegenerates — butPersistable's runtime is itself partially unwired (seepersistable/triggerabledocs).Meterableonly adds the opt-in signal; it does not create the timing. - With
Servable/Queriable/Aggregable: read-model routes could also be timed, but the same "no consumer" rule applies. - With
Triggerable: there is no hook or event thatMeterableemits or consumes. They are unrelated except that both are opt-in markers.
| Capacity | Relationship |
|---|---|
Queriable / Servable / Aggregable |
Shown alongside Meterable in the template examples; the operation timing would naturally attach to the repository/route layer those capacities generate. (Not yet wired.) |
Persistable |
The intended — but currently absent — consumer of isMeterable (the repository boundary it implies). |
Comparable / Clonable / Randomisable |
Other behaviour capacities that do add real runtime surface; Meterable adds none. |
Immutable / Versionable / Hashable |
Marker types (…Schema) that also gate behaviour; Meterable has no schema marker and gates nothing yet. |
- Inert today. The single most important thing:
Meterablehas no consumer in this codebase. Declaring it sets two statics nobody reads — no metrics are emitted, in dev or prod. Don't expect/debug/operationsordb.client.operations.*to appear until a repository boundary is built (see §6). meterNamefallback mismatch. Omitnameand the prefix becomesschemaName(e.g.PostData), which may not match your table/route/model name. Always passnameexplicitly, as the current models do.- No per-op API. There is no
inst.meter()/Model.meter(). It is a binary opt-in flag only. Any granularity (which ops, what dimensions) would live in the still-missing repository layer. - Not the same as SQL query metrics. The docstring describes sharing a sink with "driver-level query metrics" — but that telemetry module also doesn't exist yet. The two are conceptually distinct (operation-level vs driver-level) and neither is implemented.
- Opting out = not declaring it. There's no
{ enabled: false }. To stop a model being metered, remove the capacity (and, once a consumer exists, that consumer will then skip it becauseisMeterablewill beundefined/false).
- Capacity introduction — where
Meterablesits in the full catalog (and the "declare once" rule at §3). - Capacity queriable — example wiring (
Post). - Capacity servable — example wiring (
Thread); the route layer a future consumer would time. - Capacity aggregable — example wiring (
Thread). - Capacity versionable — notes that
PostRepo/ the version-history store (a would-beMeterableconsumer) are not yet implemented. - Data models & storage — the canonical capacity lists for
User/Post/Board.