ProvenPin Install

superjson dates maps sets bigint undefined: working versions (tested 2026-10-16)

Serialize and deserialize values holding Date, Map, Set, BigInt and undefined with superjson, asserting types and the json/meta shape survive offline.

passed3 passed · 0 failed2026-10-16 19:55 UTC
Status
passed
Last passed
2026-10-16 19:55 UTC
Tests
3 / 3
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
superjson@2.2.6@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38958328921

The code

Exactly the files that passed. Your agent can pull them with get_recipe("superjson-dates-maps") (install), or see them on GitHub.

package.json
{
  "name": "superjson-dates-maps",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "superjson": "2.2.6"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/codec.ts
import superjson, { type SuperJSONResult } from "superjson";

export function encode(value: unknown): string {
  return superjson.stringify(value);
}

export function decode<T>(text: string): T {
  return superjson.parse<T>(text);
}

export function serialize<T>(value: T): SuperJSONResult {
  return superjson.serialize(value);
}

export function deserialize<T>(payload: SuperJSONResult): T {
  return superjson.deserialize<T>(payload);
}
test/codec.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { decode, deserialize, encode, serialize } from "../src/codec.ts";

type Payload = {
  when: Date;
  map: Map<string, number>;
  set: Set<string>;
  big: bigint;
  missing: undefined;
};

function sample(): Payload {
  return {
    when: new Date("2024-01-02T03:04:05.000Z"),
    map: new Map<string, number>([
      ["a", 1],
      ["b", 2],
    ]),
    set: new Set<string>(["x", "y"]),
    big: 9007199254740993n,
    missing: undefined,
  };
}

test("round trips Date, Map, Set, BigInt and undefined", () => {
  const back = decode<Payload>(encode(sample()));

  assert.ok(back.when instanceof Date);
  assert.equal(back.when.toISOString(), "2024-01-02T03:04:05.000Z");

  assert.ok(back.map instanceof Map);
  assert.deepEqual([...back.map.entries()], [
    ["a", 1],
    ["b", 2],
  ]);

  assert.ok(back.set instanceof Set);
  assert.deepEqual([...back.set.values()], ["x", "y"]);

  assert.equal(typeof back.big, "bigint");
  assert.equal(back.big, 9007199254740993n);

  assert.ok("missing" in back);
  assert.equal(back.missing, undefined);
});

test("exposes the json and meta annotations", () => {
  const result = serialize(sample());
  const json = result.json as Record<string, unknown>;
  const meta = result.meta as { values?: Record<string, string[]> };

  assert.deepEqual(json.when, "2024-01-02T03:04:05.000Z");
  assert.deepEqual(json.map, [
    ["a", 1],
    ["b", 2],
  ]);
  assert.deepEqual(json.set, ["x", "y"]);
  assert.equal(json.big, "9007199254740993");
  assert.equal(json.missing, null);

  assert.deepEqual(meta.values, {
    when: ["Date"],
    map: ["map"],
    set: ["set"],
    big: ["bigint"],
    missing: ["undefined"],
  });
});

test("stringify and serialize produce equivalent payloads", () => {
  const fromString = decode<Payload>(encode(sample()));
  const fromObject = deserialize<Payload>(serialize(sample()));

  assert.deepEqual(fromObject, fromString);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.