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

@cheep/transport

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cheep/transport

[@cheep/transport](https://www.npmjs.com/package/@cheep/transport) will help you to build Event Driven applications with 💯 type safety.

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

Transport

@cheep/transport will help you to build Event Driven applications with 💯 type safety.

Basic (dynamic) example:

import { MemoryTransport } from '@cheep/transport'

// creating transport object
const transport = new MemoryTransport()

// initialization is async process
await transport.init()

// register listeners for specific routes
transport.on('PING', async () => 'PONG')

// start listening messages
await transport.start()

// RPC call on the PING route
const result = await transport.execute({
  route: 'PING',
  payload: {},
})

// result will be 'PONG'
expect(result).toBe('PONG')

// stop listening messages
await transport.stop()

// dispose will call stop as well if necessary
await transport.dispose()

Basic (Type Safed) Example:

import { 
  MemoryTransport, 
  createTransportHandler,
  createTransportApi,
  ApiWithExecutableKeys,
} from '@cheep/transport'

/**
 * Define api type
 */
type Api = {
  Command: {
    User: {
      login: (props: {
        username: string
        password: string
      }): Promise<boolean>
    }
  }
}

type UserApi = ApiWithExecutableKeys<Api, 'Command'>


/**
 * Use UserApi for type safety
 */
const transport = new MemoryTransport()

const handler = createTransportHandler<UserApi>(transport)
const api = createTransportApi<UserApi>(transport)

await transport.init()

// register listeners
handler.on(
  x => x.Command.User.login,
  (_, payload) => {
    return payload.username === payload.password
  },
)

await transport.start()

// RPC call on the PING route
const result = await api.execute.Command.User.login({
  username: 'Me',
  password: 'Me',
})

expect(result).toBe('PONG')

await transport.dispose()

Keywords

FAQs

Package last updated on 17 Mar 2021

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