How to use the transit-js.writer function in transit-js

To help you get started, we’ve selected a few transit-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github banterfm / graphql-crunch / bench / bench.js View on Github external
const {join} = require('path');
const {readFileSync} = require('fs');
const {gzipSync} = require('zlib');
const {crunch, uncrunch} = require('../src');
const transit = require('transit-js');
const msgpack = require("msgpack-lite");

const tWriter = transit.writer('json');
const tReader = transit.reader('json');

const blobs = {
  // From https://gist.githubusercontent.com/stevekrenzel/8553b5cc5462164bc9ac5b2897978405/raw/f07292666eb621a2d29dc8cee0c78a4ddb3bbadd/swapi.json
  "Large SWAPI": join(__dirname, './json/large.json'),

  // From https://gist.githubusercontent.com/stevekrenzel/88c16d8655d25bed7c1b61f1750eb362/raw/4c4b7806ba51afa479224011f8138ef1346f08f6/swapi.json
  "Small SWAPI": join(__dirname, './json/small.json'),

  // From https://catalog.data.gov/dataset/2010-census-populations-by-zip-code/resource/74f7a51d-36ae-4a28-9345-d8e07321f2e4
  "Census": join(__dirname, './json/census.json'),

  // From https://data.oregon.gov/api/views/i8h7-mn6v/rows.json
  "Businesses": join(__dirname, './json/businesses.json'),

  //"Banter Feed": join(__dirname, './json/feed.json'),
github honzabrecka / composable-fetch / examples / transit.js View on Github external
const { composableFetch, pipeP } = require('../dist/index')
const fetch = require('isomorphic-fetch')
const transit = require('transit-js')
const log = console.log.bind(console)
const writer = transit.writer('json')
const reader = transit.reader('json')

const decodeTransit = (res) => {
  res.data = reader.read(res.data)
  return res
}

const fetchTransit = pipeP(
  composableFetch.withBaseUrl('https://echo-http-server.herokuapp.com'),
  composableFetch.withHeader('Content-Type', 'application/json'),
  composableFetch.withHeader('Accept', 'application/json'),
  composableFetch.withEncodedBody((v) => writer.write(v)),
  composableFetch.retryable(composableFetch.fetch1(fetch)),
  composableFetch.withTimeout(1000),
  composableFetch.withRetry(),
  composableFetch.withSafe204(),
github honzabrecka / composable-fetch / examples / composable.js View on Github external
const composableFetch = require('../dist/index')
const { pipeP, tryCatchP } = require('../dist/index')
const transit = require('transit-js')

const log = console.log.bind(console)
const writer = transit.writer('json')
const reader = transit.reader('json')

const fetch = pipeP(
  composableFetch.retryableFetch,
  composableFetch.withRetry(),
  composableFetch.withSafe204(),
  composableFetch.withClone,
  composableFetch.checkStatus,
)

const data = ({ data }) => data

const JSONReq = pipeP(
  composableFetch.withBaseUrl('https://example.com/api'),
  composableFetch.withHeader('Content-Type', 'application/json'),
  composableFetch.withHeader('Accept', 'application/json'),
github sweet-js / sweet-core / src / serializer.js View on Github external
rep: (v) => {
    if (List.isList(v.token)) {
      return [v.token, v.scopesets];
    } else {
      let t = transit.objectToMap(v.token);
      t.set("type", typeMap.indexOf(v.token.type));
      return [t, v.scopesets];
    }
  }
});
let SymbolHandler = transit.makeWriteHandler({
  tag: () => "symb",
  rep: (v) =>  [v.name]
});

let writer = transit.writer("json", {
  handlers: transit.map([
    List, ListHandler,
    Map, MapHandler,
    Syntax, SyntaxHandler,
    SymbolClass, SymbolHandler
  ])
});

function makeReader(bindings) {
  return transit.reader("json", {
    arrayBuilder: {
      init: () => List().asMutable(),
      add: (ret, val) => ret.push(val),
      finalize: (ret) => ret.asImmutable(),
      fromArray: (arr) => List(arr)
    },

transit-js

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Javascript.

Apache-2.0
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis