PluginApiContract
The contract a provider declares for its API: every key is a method the API is promising to expose, and its value optionally carries the payload schemas for that method.
The KEYS are the part that always matters — they drive the shape check that decides whether a published record is usable at all. The schemas are optional and only ever consulted while debugging.
Why the shape check is a
typeofrather than a schema over the whole API object. In zod 4z.function()returns a function FACTORY, not a schema, so it cannot be az.object()member directly. There is a known workaround (zod#4143) —z.custom((fn) => functionSchema.implement(fn))— and it does buy correctz.infertypes for a function member. It does not buy runtime validation here, though:z.customis a boolean predicate that returns its input unchanged, so the validating wrapperimplementbuilds is discarded and the check collapses back to “is it callable”. Keeping that wrapper would need a further.transform(), and would then move validation onto every call instead of behind the debug gate, and bind the contract to zod specifically — which is exactly what reaching through Standard Schema avoids. So the declared method names are checked withtypeof, and the payloads are validated per method instead.
Import:
import type { PluginApiContract } from 'obsidian-dev-utils/obsidian/plugin/plugin-api';Signature:
export type PluginApiContractSignature:
type PluginApiContract = Record<string, PluginApiMethodContract>Type: Record<string, PluginApiMethodContract>
Links to this page: