github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/development/wasm/README.md (about)

     1  # WebAssembly Development Package
     2  
     3  This package provides SpiceDB's development functionality via a WebAssembly interface, for use with browser-based tooling.
     4  
     5  > **Warning**
     6  > The WebAssembly development interface is, at this time, **not stable** and subject to change between versions of SpiceDB.
     7  
     8  ## Generating WebAssembly
     9  
    10  ```sh
    11  GOOS=js GOARCH=wasm go build -o main.wasm
    12  ```
    13  
    14  ## Generating the types for use in TypeScript
    15  
    16  To generate TypeScript for the internal development messages used as part of the interface, add to a `buf.dev.gen.yaml` in the root of the SpiceDB package and then run `./buf.dev.gen.yaml`:
    17  
    18  ```yaml
    19  #!/usr/bin/env -S buf generate proto/internal/developer/v1/developer.proto --template
    20  ---
    21  version: "v1"
    22  plugins:
    23    - remote: buf.build/timostamm/plugins/protobuf-ts:v2.2.2-1
    24      out: "src/"
    25      opt:
    26        - long_type_string
    27        - generate_dependencies
    28  ```
    29  
    30  ## Integrating with the browser
    31  
    32  To see an example of invoking the WebAssembly based interface:
    33  
    34  1. Build `main.wasm` and copy into the [example](example) directory.
    35  2. Copy [https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.js](https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.js) into the [example](example) directory
    36  3. Run an HTTP server over the example directory and visit wasm.html:
    37  
    38  ```sh
    39  python3 -m http.server
    40  ```