npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arki/contracts

v0.0.3

Published

Shared Zod schemas and Drizzle contract helpers — branded ID-aware select/insert/update schemas with auto-applied column refinements.

Readme

@arki/contracts

Shared Zod schemas and Drizzle contract helpers — branded ID-aware select / insert / update schemas with auto-applied column refinements.

Installation

npm install @arki/contracts
# or
bun add @arki/contracts
# or
pnpm add @arki/contracts

Peer-installs:

  • drizzle-orm
  • zod (v4)
  • zod-form-data

Why

drizzle-zod's createSelectSchema walks Drizzle's dataType strings to infer Zod shapes. That mechanism loses three things:

  1. Branded ID types declared via varchar('id').$type<\usr_${string}`>()collapse to plainstring`.
  2. jsonb('col').$type<Shape>() shapes collapse to unknown.
  3. Runtime validation schemas stashed on a column by an ID-factory side-channel are not applied automatically.

@arki/contracts wraps drizzle-zod's factories so the output schema preserves the branded type and auto-applies any column-stashed runtime schema, with user-provided refines still winning.

Usage

Re-exported Zod surface

import { z } from '@arki/contracts';

const Email = z.email();

The package re-exports everything from zod/v4, so you do not need a direct zod import alongside it.

Form data helpers

import { formData } from '@arki/contracts';

const schema = formData.zfd.formData({
  name: formData.zfd.text(),
  age: formData.zfd.numeric(),
});

Branded select / insert / update schemas

import { jsonb, pgTable, varchar } from 'drizzle-orm/pg-core';

import { createInsertSchema, createSelectSchema } from '@arki/contracts';

const users = pgTable('users', {
  id: varchar('id').$type<`usr_${string}`>().primaryKey(),
  email: varchar('email').notNull(),
  profile: jsonb('profile').$type<{ displayName: string }>(),
});

const userSelect = createSelectSchema(users);
type User = z.infer<typeof userSelect>;
// { id: `usr_${string}`; email: string; profile: { displayName: string } | null }

If an ID-factory stashed a Zod schema on a column via COLUMN_ZOD_SCHEMA, parsing rejects values with the wrong prefix:

userSelect.parse({ id: 'org_42', email: '[email protected]', profile: null });
// throws: id must start with "usr_"

User-provided refines override the auto-applied schema:

const strictSelect = createSelectSchema(users, {
  email: schema => schema.email(),
});

API

  • createSelectSchema(table, refine?) — branded select schema.
  • createInsertSchema(table, refine?) — branded insert schema.
  • createUpdateSchema(table, refine?) — every field optional, otherwise like insert.
  • COLUMN_ZOD_SCHEMASymbol.for('@arki/contracts/columnZodSchema') side-channel for ID factories.
  • bufferSchema, jsonSchema, literalSchema, createSchemaFactory — re-exported from drizzle-orm/zod.
  • formData — re-exported zod-form-data namespace.
  • z, ZodError, every Zod export — re-exported from zod/v4.

Documentation

@arki/contracts is framework-agnostic and works on its own. When you compose it with the @arki/dot application framework, see packages/dot/docs/ for plugin authoring, lifecycle, and diagnostics.

License

MIT. See LICENSE.