1.12.0 • Published 1 year ago

webtopics v1.12.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

⚡️ WebTopics

Typed pub / sub, request / responses for web apps using Socket.io and Zod, inspired by ROS.

[ Documentation ]

Features

Typed and validated topics and services via Zod

const SensorTopic = createTopic("sensor", z.object({
  "temperature": z.number(),
  "humidity": z.number()
}))
client.pub(SensorTopic, {temperature: 20, humidity: "50%"}) // Error: Expected number, received string

Collaborative topics

client1.pub(channel, {a: "1"})
client2.pub(channel, {b: "2"}) // New state merged on old by default
client3.sub(channel, (value) => {
  console.log(value) // {a: "1", b: "2"}
})
client2.pub(channel, {b: "2"}, true) // Or publishing as an overwrite
// client 3 receives: {b: "2"}

Async service calls

const AdditionService = createService("add", 
  // Request schema
  z.object({
    "a": z.number(),
    "b": z.number()
  }), 
  // Response schema
  z.number()
)
...

// Call service
const result = await client.req(AdditionService, someClientID, {a: 1, b: 2}) // Promise<number>

Packagable channels for easy sharing between client and server

export const AdditionService = createService("add", 
  z.object({
    "a": z.number(),
    "b": z.number()
  }), 
  z.number()
)

export const SensorTopic = createTopic("sensor", z.object({
  "temperature": z.number(),
  "humidity": z.number()
}))
...

// Client and server can share the same channels from an external package
import {AdditionService, SensorTopic} from "channels"
1.12.0

1 year ago

1.11.4

1 year ago

1.11.1

1 year ago

1.11.0

1 year ago

1.10.2

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.9.10

1 year ago

1.9.9

1 year ago

1.9.8

1 year ago

1.9.7

1 year ago

1.9.6

1 year ago

1.9.5

1 year ago

1.9.4

1 year ago

1.9.3

1 year ago

1.9.2

1 year ago

1.9.1

1 year ago

1.9.0

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.10

1 year ago

1.6.9

1 year ago

1.6.8

1 year ago

1.6.7

1 year ago

1.6.6

1 year ago

1.6.5

1 year ago

1.6.3

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago