npm.io
0.7.1 • Published 2d ago

@super-line/core

Licence
MIT
Version
0.7.1
Deps
1
Size
88 kB
Vulns
0
Weekly
928

@super-line/core

Shared core for super-line — end-to-end typesafe WebSockets for TypeScript. This package holds the pieces both ends import: defineContract, runtime validation, the SuperLineError model, and the Serializer / Adapter interfaces.

pnpm add @super-line/core zod
import { z } from 'zod'
import { defineContract } from '@super-line/core'

export const api = defineContract({
  shared: {
    serverToClient: { message: { payload: z.object({ text: z.string() }) } },
  },
  roles: {
    user: {
      clientToServer: {
        send: { input: z.object({ text: z.string() }), output: z.object({ id: z.string() }) },
      },
    },
  },
})

The contract is split by direction (clientToServer / serverToClient) and scoped by role, then implemented by @super-line/server and called by @super-line/client.

MIT Mert

Keywords