@vectorfyco/valbridge
v1.1.0
Published
Runtime schema lookup client for generated valbridge TypeScript artifacts
Maintainers
Readme
Runtime client for valbridge-generated TypeScript validators with full type inference and compile-time safety.
Installation
npm install @vectorfyco/valbridge
# or
pnpm add @vectorfyco/valbridgeQuick start
import { createValbridgeClient } from "@vectorfyco/valbridge";
import { schemas } from "./.valbridge/valbridge.gen.js";
const valbridge = createValbridgeClient({ schemas });
// Lookup a schema by namespace:id key (with full autocomplete)
const userSchema = valbridge("user:Profile");
const result = userSchema.parse({ id: "123", name: "john" });Default namespace
Set a default namespace to omit the prefix for that namespace:
const valbridge = createValbridgeClient({
schemas,
defaultNamespace: "user"
});
// Shorthand for "user:Profile"
const profile = valbridge("Profile");
// Full key still works for other namespaces
const tsConfig = valbridge("another:TSConfig");Type extraction
Use ValbridgeType to extract TypeScript types from registered schemas at zero runtime cost:
import type { ValbridgeType } from "@vectorfyco/valbridge";
type UserProfile = ValbridgeType<"user:Profile">;
function validateUser(data: unknown): UserProfile {
return valbridge("user:Profile").parse(data);
}Generated output structure
The maintained TypeScript path uses Zod. Generated artifacts expose both runtime schemas and extracted types:
// Generated code
const user_User = z.object({ id: z.string(), name: z.string() });
type user_UserType = z.infer<typeof user_User>;
export const schemas = { "user:User": user_User } as const;
export type SchemaTypes = { "user:User": user_UserType };Both valbridge("user:User") and ValbridgeType<"user:User"> work with full type inference.
Key behaviors
- Runtime lookup -- only entries with a runtime schema appear in the
schemasobject - Type extraction -- all entries appear in
SchemaTypes, regardless of runtime validators - Compile-time safety -- TypeScript prevents using invalid keys; full autocomplete for all registered schemas
- Error messages --
valbridge("nonexistent:Key")throwsError: Unknown schema: nonexistent:Key. Run valbridge generate.
Related packages
| Package | Purpose |
| --- | --- |
| @vectorfyco/valbridge-core | Core IR and JSON Schema parser |
| @vectorfyco/valbridge-zod | Zod adapter for code generation |
| @vectorfyco/valbridge-cli | CLI to generate validators |
