Skip to content

Latest commit

 

History

History

zed-wasm

zed-wasm

The Zed command line tools built for WebAssembly.

View the interactive demo

Zed is a suite of technologies for managing, storing, and processing data. It's a superset of schema-defined tables, and unstructured documents; an emerging concept we call super-structured data.

The storage layer, type system, query language, and zq command-line utility are just a few of the tools Zed offers to the data community.

This package brings Zed into your browser.

Example

<script type="module">
  import { zq } from 'https://cdn.jsdelivr.net/npm/@brimdata/zed-wasm/index.js';

  const result = await zq({
    input: '1 2 3',
    program: 'this + 1',
  });

  console.log(result);
  /* (3) [Int64, Int64, Int64]
        0 : Int64 {value: '2', type: TypeOfInt64}
        1 : Int64 {value: '3', type: TypeOfInt64}
        2 : Int64 {value: '4', type: TypeOfInt64} */
</script>

Installation

The easiest way to work with the published version of zed-wasm is to use a CDN like JsDelivr. Use the URL below inside of a script tag with the type property set to "module".

const { zq } = await import('https://cdn.jsdelivr.net/npm/@brimdata/zed-wasm/index.js');

API

Only the zq function is exposed at the moment. It takes an options object and returns an array of Zed Value Objects.

function zq(options: {
  input?: string | File | Blob | ReadableStream | any[];
  program?: string;
  inputFormat?: InputFormat; // Defaults to auto
  outputFormat?: "js" | "zed" // Defaults to js
}): Promise<any[]>;

type InputFormat =
  | 'auto'
  | 'arrows'
  | 'csv'
  | 'json'
  | 'line'
  | 'zeek'
  | 'zjson'
  | 'zng'
  | 'zson';

Running Browser Tests

Tests are written with Mocha. To run them:

yarn nx test-browser zed-wasm

When you make changes, run yarn nx build zed-wasm, then reload the page.