0.5.1 • Published 1 year ago

@clappcodes/transporter v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago
________                                                        _____               
___  __/______________ ________ ________________ ______ __________  /______ ________
__  /   __  ___/_  __ `/__  __ \__  ___/___  __ \_  __ \__  ___/_  __/_  _ \__  ___/
_  /    _  /    / /_/ / _  / / /_(__  ) __  /_/ // /_/ /_  /    / /_  /  __/_  /    
/_/     /_/     \__,_/  /_/ /_/ /____/  _  .___/ \____/ /_/     \__/  \___/ /_/     
                                        /_/                                         
@clappcodes/transporter

Request handler

import route from '@clappcodes/transporter/route';
import { BroadcastStream, transform } from '@clappcodes/transporter/stream';

const toUpperCase = route.post('/toUpperCase', ({ request }) =>
  request.body
    ?.pipeThrough(new TextDecoderStream())
    .pipeThrough(transform.toUpperCase())
    .pipeThrough(new TextEncoderStream()));

const echo = route.post('/echo', (ctx) => {
  const stream = new BroadcastStream();

  ctx.request.body?.pipeTo(stream.writable);
  ctx.headers.set('content-type', 'text/event-stream');

  return stream.readable;
});

route(route.cors(), echo, toUpperCase)
  .serve({ port: 3000 });

Quick start

  • Just paste in console
import('https://esm.sh/@clappcodes/transporter/stream')
  .then(({ transport, transform }) =>
    transport.pipe(
      transport.text(`https://transporter.deno.dev/toUpperCase`),
      transport.text(`https://transporter.deno.dev/echo`),
      transform.toUpperCase(),
    )
  )
  .then((stream) => {
    stream.read(console.log);
    stream.write('Hello World');
  });
import { transport } from "@clappcodes/transporter/stream";

const stream = transport.pipe(
  transport.text("/toUpperCase", /** toUpperCase */)
  transport.text("/echo", /** echo */)
);

stream.read(console.log);
stream.write("Hello"); // => HELLO
0.4.9

1 year ago

0.4.8

1 year ago

0.3.9

1 year ago

0.3.0

1 year ago

0.4.5

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.4.7

1 year ago

0.3.8

1 year ago

0.2.9

1 year ago

0.4.6

1 year ago

0.3.7

1 year ago

0.2.8

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.4.3

1 year ago

0.5.1

1 year ago

0.4.2

1 year ago

0.3.3

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.2.3

1 year ago

0.1.4

1 year ago

0.2.2

1 year ago

0.1.6

1 year ago

0.1.3

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago