New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@orpc/transformer

Package Overview
Dependencies
Maintainers
0
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orpc/transformer

A library for transforming oRPC payloads in different client-server scenarios.

  • 0.10.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by900%
Maintainers
0
Weekly downloads
 
Created
Source

@orpc/transformer

A library for transforming oRPC payloads in different client-server scenarios.

Overview

@orpc/transformer provides two distinct sets of serializers and deserializers for different use cases:

  1. ORPC serializer/deserializer designed for internal oRPC clients and servers to communicate with each other.
  2. OpenAPI serializer/deserializer designed for external clients consuming the API through OpenAPI specifications.
import { ORPCDeserializer, ORPCSerializer } from '@orpc/transformer'

const serializer = new ORPCSerializer() // or OpenAPISerializer
const deserializer = new ORPCDeserializer() // or OpenAPIDeserializer

export async function fetch(request: Request) {
  const input = await deserializer.deserialize(request)

  const output = { some: 'data', file: new File([], 'file.txt'), date: new Date() }

  const { body, contentType } = serializer.serialize(output)

  return new Response(body, {
    headers: {
      'Content-Type': contentType,
    },
  })
}

Types Supported

  • string
  • number (include NaN)
  • boolean
  • null
  • undefined
  • Date (include Invalid Date)
  • BigInt
  • RegExp
  • URL
  • Set
  • Map
  • Blob
  • File

Implementations

oRPC Serializer/Deserializer

The primary implementation designed specifically for communication between oRPC clients and servers. This implementation is most powerful, but the payload is not human-readable.

OpenAPI Serializer/Deserializer

An implementation designed for external clients consuming the API through OpenAPI specifications. This is used when developers manually create HTTP requests based on the OpenAPI documentation.

The payload is human-readable, but the implementation is slower and requires provide schema to archive the same functionality as oRPC implementation.

With the wide of content-type support by OpenAPI, required user learns Bracket Notation to represent nested structures in some limited cases.

Bracket Notation

Bracket notation is a syntax used to represent nested structures in some limited cases.

const payload = {
  user: {
    name: 'John Doe',
    age: 30,
  },
  avatar: new File([], 'avatar.png'),
  friends: ['Alice', 'Bob'],
}

// with bracket notation

const equivalent = {
  'user[name]': 'John Doe',
  'user[age]': 30,
  'avatar': new File([], 'avatar.png'),
  'friends[]': 'Alice',
  'friends[]': 'Bob',
}

Keywords

FAQs

Package last updated on 01 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc