All Projects → megaease → easegress-assemblyscript-sdk

megaease / easegress-assemblyscript-sdk

Licence: Apache-2.0 license
AssemblyScript SDK for Easegress

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to easegress-assemblyscript-sdk

atari2600-wasm
An Atari 2600 emulator written in AssemblyScript compiled to WebAssembly
Stars: ✭ 50 (+233.33%)
Mutual labels:  assemblyscript
guest-book
Sign in with NEAR and add a message to the guest book!
Stars: ✭ 68 (+353.33%)
Mutual labels:  assemblyscript
Lunatic
Lunatic is an Erlang-inspired runtime for WebAssembly
Stars: ✭ 2,074 (+13726.67%)
Mutual labels:  assemblyscript
as-string-sink
An efficient dynamically sized string buffer (aka String Builder) for AssemblyScript
Stars: ✭ 23 (+53.33%)
Mutual labels:  assemblyscript
assemblyscript-json
JSON encoder / decoder for AssemblyScript
Stars: ✭ 140 (+833.33%)
Mutual labels:  assemblyscript
redstone-smartcontracts
An implementation of the Arweave SmartWeave smart contracts protocol.
Stars: ✭ 42 (+180%)
Mutual labels:  assemblyscript
pallet-contracts-waterfall
Collection of simple Substrate smart contract examples written in Rust, AssemblyScript, Solang and the smart contract language ink! to test substrates pallet-contracts module
Stars: ✭ 28 (+86.67%)
Mutual labels:  assemblyscript
examples
A collection of AssemblyScript examples.
Stars: ✭ 233 (+1453.33%)
Mutual labels:  assemblyscript
gomoku-wasm
A Gomoku game implements with WebAssembly
Stars: ✭ 30 (+100%)
Mutual labels:  assemblyscript
Lucet
Lucet, the Sandboxing WebAssembly Compiler.
Stars: ✭ 4,006 (+26606.67%)
Mutual labels:  assemblyscript
as-bignum
Fixed length big numbers for AssemblyScript 🚀
Stars: ✭ 49 (+226.67%)
Mutual labels:  assemblyscript
rabin-wasm
Rabin fingerprinting implemented in WASM
Stars: ✭ 26 (+73.33%)
Mutual labels:  assemblyscript
Babylon.Font
Generate text mesh for BabylonJS using WASM, written in AssemblyScript.
Stars: ✭ 22 (+46.67%)
Mutual labels:  assemblyscript
website
AssemblyScript's website and documentation.
Stars: ✭ 47 (+213.33%)
Mutual labels:  assemblyscript
Assemblyscript
A TypeScript-like language for WebAssembly.
Stars: ✭ 13,152 (+87580%)
Mutual labels:  assemblyscript
wasm4
Build retro games using WebAssembly for a fantasy console.
Stars: ✭ 711 (+4640%)
Mutual labels:  assemblyscript
as-sha256
AssemblyScript implementation of SHA256
Stars: ✭ 15 (+0%)
Mutual labels:  assemblyscript
assemblyscript-regex
A regex engine for AssemblyScript
Stars: ✭ 81 (+440%)
Mutual labels:  assemblyscript
blurhash-as
Blurhash implementation in AssemblyScript
Stars: ✭ 26 (+73.33%)
Mutual labels:  assemblyscript
counter
Increment and decrement a counter with this simple smart contract via a web page.
Stars: ✭ 21 (+40%)
Mutual labels:  assemblyscript

Easegress AssemblyScript SDK

This is the AssemblyScript SDK for Easegress, it can be used to extend the ability of Easegress.

Prerequisites

The following assumes that a recent version of Git, Node.js and its package manager npm are installed. Basic knowledge about writing and working with TypeScript modules, which is very similar, is a plus.

Local Development

  1. Clone this repo to somewhere on disk.

  2. Switch to a new directory and initialize a new node module:

npm init
  1. Install the AssemblyScript compiler using npm, assume that the compiler is not required in production and make it a development dependency:
npm install --save-dev assemblyscript
  1. Once installed, the compiler provides a handy scaffolding utility to quickly set up a new AssemblyScript project, for example in the directory of the just initialized node module:
npx asinit .
  1. Add --use abort= to the end asc assembly/index.ts ... command in package.json, for example,

Before add --use abort=:

...
    "scripts": {
        "test": "node tests",
        "asbuild:debug": "asc assembly/index.ts --target debug",
        "asbuild:release": "asc assembly/index.ts --target release",
        "asbuild": "npm run asbuild:debug && npm run asbuild:release",
        "start": "npx serve ."
    },
...

After add --use abort=:

...
    "scripts": {
        "test": "node tests",
        "asbuild:debug": "asc assembly/index.ts --target debug --use abort=",
        "asbuild:release": "asc assembly/index.ts --target release --use abort=",
        "asbuild": "npm run asbuild:debug && npm run asbuild:release",
        "start": "npx serve ."
    },
...
  1. Copy this into assembly/index.ts, note to replace PATH_TO_SDK_REPO with the path in the first step:
// As required by Easegress, these functions must be exported
// Use relative path here, like ../../easegress-assemblyscript-sdk/easegress/proxy
export * from 'PATH_TO_SDK_REPO/easegress/proxy'

// Use relative path here, like ../../easegress-assemblyscript-sdk/easegress
import { Program, request, LogLevel, log, registerProgramFactory } from 'PATH_TO_SDK_REPO/easegress'

class AddHeaderAndSetBody extends Program {
    constructor(params: Map<string, string>) {
        super(params)
    }

    run(): i32 {
        super.run()
        let v = request.getHeader( "Foo" )
        if( v.length > 10 ) {
            log( LogLevel.Warning, "The length of Foo is greater than 10" )
        }
        if( v.length > 0 ) {
            request.addHeader( "Wasm-Added", v )
        }
        request.setBody( String.UTF8.encode("I have a new body now") )
        return 0
    }
}

registerProgramFactory((params: Map<string, string>) => {
    return new AddHeaderAndSetBody(params)
}
  1. Build with this command
npm run asbuild

If everything is right, debug.wasm (the debug version) and release.wasm (the release version) will be generated at the build folder.

Deploy and execute

Please refer the documentation of WasmHost for deploying and executing the compiled Wasm code.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].