api-schema
@vkma.dev/api-schema is generated TypeScript types plus zod and valibot schemas for the VK API, built from VKCOM/vk-api-schema.
npm install @vkma.dev/api-schema# optional peers, only if you use the corresponding subpathnpm install zod # for @vkma.dev/api-schema/zodnpm install valibot # for @vkma.dev/api-schema/valibotTypes and constants from the root (no validator dependency needed):
import { API_VERSION, AppsApp, AppsGetCatalogParams, MessagesMessage } from "@vkma.dev/api-schema";
const params: AppsGetCatalogParams = { count: 10 };zod schemas from @vkma.dev/api-schema/zod (export names carry a Schema suffix):
import { AppsGetCatalogParamsSchema } from "@vkma.dev/api-schema/zod";
AppsGetCatalogParamsSchema.parse({ count: 10 });valibot schemas from @vkma.dev/api-schema/valibot (same names):
import { BaseObjectSchema } from "@vkma.dev/api-schema/valibot";
BaseObjectSchema.parse({ id: 1, title: "app" });Granular imports
Section titled “Granular imports”The barrels export everything, and in plain Node (no tree-shaking) importing one evaluates the whole package. When cold-start time matters, import a single section module instead; the specifiers are extensionless:
import { BaseObjectSchema } from "@vkma.dev/api-schema/valibot/base/objects";import { MessagesSendParamsSchema } from "@vkma.dev/api-schema/zod/messages/methods";Method map
Section titled “Method map”MethodMap (root) types every documented method by its dotted name; MethodSchemas (zod/valibot) is the runtime counterpart. params is always present, response only where the VK schema documents one; methods with several response variants (extended etc.) get a union of them.
import type { MethodMap } from "@vkma.dev/api-schema";import { MethodSchemas } from "@vkma.dev/api-schema/zod";
type Call = <M extends keyof MethodMap>( method: M, params: MethodMap[M]["params"],) => Promise<MethodMap[M]["response"]>;
MethodSchemas["ads.getAccounts"].params.parse({});The runtime response slot holds the base variant (<method>_response); extended variants (…_extended_response and friends) stay available as their own exports.
Versioning
Section titled “Versioning”The package minor encodes the API version (0.5199.x ↔ API 5.199); API_VERSION comes from the schema and a test asserts it.
Learn more
Section titled “Learn more”- Types — naming, EnumNames, API_VERSION, MethodMap
- Validators — zod and valibot, granular imports
- Versioning — the minor as the VK API version, schema updates