tsclient

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package tsclient generates a TypeScript SDK for the API: the types a front end holds, one method per endpoint, and a factory per live-sync stream.

It exists for the reason the Go client generator does, and the reason bites harder here. A hand-written TypeScript client is a second description of the API kept in step by whoever remembers, and the failure is quiet: a client that stopped sending a field compiles perfectly, and a type that says `string` about a column the server now sends as null is a runtime error in somebody's browser rather than a build failure. This one is written from the document the router was built from, so the two cannot disagree about a path, a status, or the name of a key.

What it does not generate is everything underneath the methods: the request, the credential, the failure, the pagination. That is the same in every project and lives, hand-written, in the `@rig-ts/client` package — and the streaming half lives in `@rig-ts/electric`, which is a separate package because the sync client and TanStack DB come with it and a project that streams nothing should install nothing.

Two shapes for one row

A row reaches a front end two ways, and they are not the same shape. Over REST it arrives as `encoding/json` wrote it, under the keys the document's `json_case` produced — `createdAt` by default. Over a stream it arrives as Postgres printed it, under column names — `created_at`. rig's shape endpoint is a proxy in front of the sync service and does not rewrite the rows, so there is nothing in the middle to reconcile them.

So a streamed resource gets a second type, `<Resource>Row`, keyed by column. Declaring one type and using it for both is the bug this generator exists to prevent, only with the compiler agreeing.

Index

Constants

View Source
const DefaultClientModule = "@rig-ts/client"

DefaultClientModule is the hand-written half of the SDK, which the generated half calls into.

View Source
const DefaultElectricModule = "@rig-ts/electric"

DefaultElectricModule is the hand-written half of the streaming layer. It is only ever imported by a project that has a table with `electric: {enabled: true}`, so a project without one never has to install it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct{}

Generator emits the TypeScript client.

func New

func New() *Generator

New builds the generator.

func (*Generator) Description

func (*Generator) Description() string

Description implements gen.Generator.

func (*Generator) Generate

func (g *Generator) Generate(
	_ context.Context, doc *ir.Document, opts gen.Options,
) ([]gen.Artifact, error)

Generate implements gen.Generator.

func (*Generator) Name

func (*Generator) Name() string

Name implements gen.Generator.

func (*Generator) Version

func (*Generator) Version() string

Version implements gen.Generator.

type Options

type Options struct {
	// ClientImport is the module specifier of the SDK runtime. It is here for a
	// fork, a vendored copy, or a registry of your own; a project has no reason
	// to set it.
	ClientImport string `json:"client_import"`

	// ElectricImport is the same, for the streaming runtime.
	ElectricImport string `json:"electric_import"`

	// DefaultBaseURL is emitted as a constant when it is set, so a development
	// tool can build a client without naming the server.
	//
	// Deprecated: rig.yaml's top-level `servers:` block names the deployments
	// for every SDK generator and for the OpenAPI document, so a real project
	// ships an SDK that knows where its API is rather than one whose consumer
	// has to be told. This is read only when that block is absent, and rig warns
	// (RIG3010) when it is set.
	DefaultBaseURL string `json:"default_base_url"`
}

Options configure the generator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL