Skip to content

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 typeof rather than a schema over the whole API object. In zod 4 z.function() returns a function FACTORY, not a schema, so it cannot be a z.object() member directly. There is a known workaround (zod#4143) — z.custom((fn) => functionSchema.implement(fn)) — and it does buy correct z.infer types for a function member. It does not buy runtime validation here, though: z.custom is a boolean predicate that returns its input unchanged, so the validating wrapper implement builds 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 with typeof, and the payloads are validated per method instead.

Import:

import type { PluginApiContract } from 'obsidian-dev-utils/obsidian/plugin/plugin-api';

Signature:

export type PluginApiContract

Signature:

type PluginApiContract = Record<string, PluginApiMethodContract>

Type: Record<string, PluginApiMethodContract>


Links to this page: