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 🙏

© 2025 – Pkg Stats / Ryan Hefner

stdb-zod-gen-runtime

v0.1.0

Published

Runtime helpers for SpacetimeDB Zod schema generator

Downloads

3

Readme

@stdb-zod-gen/runtime

Runtime helpers for @stdb-zod-gen/cli — custom Zod types that coerce frontend primitives to SpacetimeDB SDK types.

Installation

pnpm add @stdb-zod-gen/runtime

Usage

This package is automatically imported by generated schemas. You can also use it manually:

import { z } from 'zod';
import { zodSpacetime } from '@stdb-zod-gen/runtime';

const UserSchema = z.object({
  identity: zodSpacetime.identity(),
  createdAt: zodSpacetime.timestamp(),
  sessionDuration: zodSpacetime.timeDuration(),
});

// Accepts frontend primitives
const user = UserSchema.parse({
  identity: '0x' + '0'.repeat(64),  // hex string → Identity
  createdAt: new Date(),             // Date → Timestamp
  sessionDuration: 5000,             // number (ms) → TimeDuration
});

API

zodSpacetime.identity()

Accepts: Identity, hex string, bigint Returns: Identity

const schema = zodSpacetime.identity();

schema.parse(new Identity(123n));           // ✅ Identity
schema.parse('0x' + '0'.repeat(64));        // ✅ hex string → Identity
schema.parse(123456789n);                   // ✅ bigint → Identity
schema.parse('invalid');                     // ❌ throws

zodSpacetime.timestamp()

Accepts: Timestamp, Date, ISO string, Unix ms Returns: Timestamp

const schema = zodSpacetime.timestamp();

schema.parse(new Timestamp(...));           // ✅ Timestamp
schema.parse(new Date());                   // ✅ Date → Timestamp
schema.parse('2025-10-18T12:00:00Z');       // ✅ ISO string → Timestamp
schema.parse(1729252800000);                // ✅ Unix ms → Timestamp
schema.parse('invalid');                     // ❌ throws

zodSpacetime.timeDuration()

Accepts: TimeDuration, number (milliseconds) Returns: TimeDuration

const schema = zodSpacetime.timeDuration();

schema.parse(new TimeDuration(...));        // ✅ TimeDuration
schema.parse(5000);                         // ✅ 5000ms → TimeDuration
schema.parse(-1);                            // ❌ throws (must be non-negative)

zodSpacetime.connectionId()

Accepts: ConnectionId, string Returns: ConnectionId

const schema = zodSpacetime.connectionId();

schema.parse(new ConnectionId(...));        // ✅ ConnectionId
schema.parse('12345');                      // ✅ string → ConnectionId

Error Messages

Clear, actionable error messages:

zodSpacetime.identity().parse('invalid');
// ZodError: Invalid Identity: Must be a 64-character hex string (with optional 0x prefix)

zodSpacetime.timestamp().parse('not-a-date');
// ZodError: Invalid Timestamp: Invalid time value

Why This Package?

SpacetimeDB uses custom classes (Identity, Timestamp, etc.) but frontend forms/APIs typically use primitives (string, Date). This package bridges the gap:

Without coercion (manual conversion):

const identity = Identity.fromString(formData.identity);
const timestamp = Timestamp.fromDate(new Date(formData.createdAt));

With coercion (automatic):

const data = UserSchema.parse(formData);
// data.identity is Identity
// data.createdAt is Timestamp

TypeScript Support

Fully typed with TypeScript 5.7+. All types are inferred correctly:

const schema = z.object({
  identity: zodSpacetime.identity(),
});

type Inferred = z.infer<typeof schema>;
// { identity: Identity }

Requirements

  • SpacetimeDB SDK ≥ 1.6.0
  • Zod ≥ 4.0.0

License

MIT