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

@tango-ts/serializers

v0.9.0

Published

Tango serializers: DRF-style validation and model serialization with inferred TypeScript types.

Downloads

2,702

Readme

@tango-ts/serializers

Responsibility

DRF-style serialization and validation. This package turns model definitions into typed serializers: configured output fields, typed input data, runtime validation, DRF-shaped error maps, and save() through the real ORM manager. It does not own HTTP views, routing, pagination, or permissions.

What it responds to

  • A model declared with model(...).
  • Serializer configuration: fields, readOnlyFields, and nested.
  • Typed application input via forInput(...), or request payloads via forUnknownInput(...).

Functionality

  • modelSerializer(model, { fields, readOnlyFields, nested }).
  • serialize(row) returns only configured fields with inferred output types.
  • Read-only nested serializers (DRF's author = AuthorSerializer(read_only=True)): nested: { author: AuthorSerializer } keys are the model's relation names (authorId -> author) and are type-checked against the related model. serialize then requires the related row (what selectRelated returns, recursively for multi-level nesting), renders it through the nested serializer, and renders a missing relation as null. Nested keys are output-only: in input they are silently ignored (DRF parity) and never satisfy required writable fields.
  • forInput(data) is compile-time checked against writable model fields.
  • forUnknownInput(payload) validates request payloads at runtime.
  • datetime/date fields accept ISO 8601 strings over JSON (validated against explicit patterns, not new Date(...) parsing) and are normalized to Date for the ORM.
  • isValid(), errors, validatedData.
  • save() calls Model.objects.create(...) using validated data.

Design patterns that matter here

  • Inferred types: input/output shapes derive from the model field map and serializer config. No hand-written DTO interfaces.
  • Two input paths: trusted application code uses typed forInput; untrusted request bodies use forUnknownInput.
  • Production overlap: save() is integration-tested against real MySQL through the ORM, not mocked.
  • DRF oracle: validation envelope parity is tested against real DRF for covered cases.

Public contract

Everything exported from src/index.ts: modelSerializer, ModelSerializerInstance, ValidationErrors, SerializerInput, SerializerOutput, SerializerRow, nested serializer types (NestedSerializerLike, NestedSerializerMap, NestedSerializersOption), and config/model interfaces.

Testing

  • Type-level (test/model-serializer.test-d.ts): configured fields, readonly input, required fields, invalid model fields, nested output inference, and invalid nested configs failing to compile.
  • Unit (test/model-serializer.test.ts): serialization and validation behavior, including nested output, null relations, and multi-level nesting.
  • Parity (test/drf-parity.test.ts): required-field error envelope and read-only nested input semantics compared to real DRF via uv run.
  • Integration (test/model-serializer.integration.test.ts): save() and nested selectRelated serialization against real MySQL.