Skip to content

Hedystia 2.3 - Universal WebSocket, PostgreSQL, and Enhanced Validations

Native Node.js support, @hedystia/ws package, PostgreSQL driver, and major validations expansion.

Hedystia 2.3 is a landmark release that removes the Node.js adapter requirement, introduces a universal WebSocket package, adds PostgreSQL database support, and significantly expands the schema validation library.

🌐 @hedystia/ws — Universal WebSocket Package

A new standalone WebSocket library that works identically on Bun, Node.js, and Deno. Ships no HTTP server — just portable WebSocket primitives.

bash
bun add @hedystia/ws

Server

Portable WebSocketServer with topic-based pub/sub, consuming raw HTTP upgrade tuples:

ts
import { createServer } from "node:http";
import { WebSocketServer } from "@hedystia/ws/server";

const wss = new WebSocketServer({
  open: (ws) => ws.subscribe("room:general"),
  message: (ws, msg) => ws.publish("room:general", msg),
});

const http = createServer((_req, res) => res.end("ok"));
http.on("upgrade", (req, socket, head) => {
  wss.upgrade({ rawRequest: req, socket, head }, { data: { user: "anon" } });
});
http.listen(3000);

Client

Runtime-aware createWebSocket that works across all environments:

ts
import { createWebSocket } from "@hedystia/ws/client";

const ws = createWebSocket("ws://localhost:3000", {
  headers: { authorization: "Bearer token" },
});

Runtime Detection

ts
import { detectRuntime, isBun, isNode, isDeno } from "@hedystia/ws";
detectRuntime(); // "bun" | "node" | "deno" | "browser"

🚀 Native Node.js Support (hedystia Core)

Hedystia's HTTP layer now runs natively on Node.js without @hedystia/adapter.

Before:

ts
import { adapter } from "@hedystia/adapter";
import { createServer } from "node:http";
const app = new Framework().get("/", () => "ok");
createServer(adapter(app).toNodeHandler()).listen(3000);

After:

ts
import Framework from "hedystia";
new Framework().get("/", () => "ok").listen(3000);

Same code works under bun run and node --run. WebSocket subscriptions, lifecycle hooks, publish, and the activity heartbeat all work natively on Node.

🗄️ PostgreSQL Driver for @hedystia/db

@hedystia/db now supports PostgreSQL natively via the pg package with full CRUD, transactions, and caching support.

bash
bun add @hedystia/db pg
typescript
import { database, table, integer, varchar } from "@hedystia/db";

const users = table("users", {
  id: integer().primaryKey().autoIncrement(),
  name: varchar(255).notNull(),
  email: varchar(255).unique(),
});

const db = database({
  schemas: { users },
  database: { name: "postgres", provider: "pg" },
  connection: {
    host: "localhost",
    port: 5432,
    user: "postgres",
    password: "password",
    database: "mydb",
  },
  syncSchemas: true,
});

await db.initialize();

The SQL compiler handles PostgreSQL dialect specifics — quoted identifiers, GENERATED BY DEFAULT AS IDENTITY, and RETURNING clauses.

✨ Enhanced Validations — @hedystia/validations

The h schema builder receives a major expansion with 20+ new factories and methods.

New Schema Factories

APIDescription
h.bigint()Bigint validation with .min() / .max() / .coerce()
h.undefined()Accepts only undefined
h.void()Void type
h.unknown()Accepts anything, typed as unknown
h.never()Always fails validation
h.tuple(a, b, ...)Fixed-length array with .rest_()
h.record(v) / h.record(k, v)Dynamic key object
h.map(k, v)Native Map<K, V>
h.set(v)Native Set<V>
h.intersection(a, b, ...)AllOf with deep-merge
h.discriminatedUnion(d, [...])Tagged union with O(1) lookup
h.lazy(() => schema)Recursive schemas
h.default(schema, v | fn)Default value
h.transform(schema, fn)Post-process validated value
h.refine(schema, check, msg?)Custom predicate
h.pipe(a, b)Chain schemas sequentially
h.coerce.string() / .number() / .boolean() / .bigint()Coercion shortcuts

New Methods on Existing Schemas

SchemaNew Methods
NumberSchemaType.int()
ArraySchema.min(n) / .max(n) / .nonEmpty()
ObjectSchemaType.strict() / .passthrough() / .extend() / .merge() / .pick() / .omit() / .partial()

📋 Summary

Hedystia 2.3 delivers:

  1. @hedystia/ws — Universal WebSocket package for Bun, Node.js, Deno
  2. Native Node.js — No adapter needed, app.listen(port) works everywhere
  3. PostgreSQL driver — Production-grade Postgres support for @hedystia/db
  4. Enhanced validations — 20+ new schema factories and object/array methods

Upgrade

bash
bun update hedystia @hedystia/ws @hedystia/db @hedystia/validations

Full Documentation


Thank you to everyone in the Hedystia community for your feedback and support.