Code Monkey home page Code Monkey logo

spin-js-sdk's People

Contributors

calebschoepp avatar dependabot[bot] avatar dicej avatar karthik2804 avatar mikkelhegn avatar radu-matei avatar rajatjindal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spin-js-sdk's Issues

Packaging and distribution for the native binary

Building and preparing a JS component for Spin needs a CLI binary that prepares and pre-initialises runtime. This additional binary needs to be on the user's system at spin build time, so there needs to be a way to fetch it.

Currently, there are two ways of fetching this that I can think of:

  • Spin plugin
  • JS dev dependency

Any thoughts on the two, @dicej?

Signature for handler function, response chaining

A usual pattern when writing HTTP handlers in JavaScript is having a function that takes both the request and response, and constructing the response using a builder-like pattern, by chaining the desired status, headers, or body.

An example using Express:

app.get('/', (req, res) => {
	res.status(500).send('Something broke!')
})

This is similar to how other JS frameworks construct HTTP handlers — is this something we'd consider implementing into this SDK?

It is a departure from other Spin SDKs and from the current implementation of this SDK, which takes in the request as a parameter, and returns the response as the result.

Consider migrating to SpiderMonkey when it's ready

Shopify and Igalia are making good progress adding SpiderMonkey AOT-to-Wasm support and expect to have it ready in the first half of 2023. Shopify expects to switch Javy over to it at that point, and we should consider doing the same for our SDK.

`TextEncoder` and `TextDecoder`

I'm trying to use an external library that needs a TextDecoder, and I had the imports in the following order:

import <some library that needs TextEncoder and TextDecoder>;
import { TextEncoder, TextDecoder } from "fast-text-encoding";

Building this results in TextDecoder not defined:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Uncaught ReferenceError: 'TextDecoder' is not defined
    at <anonymous> (script.js:1645)
    at <anonymous> (script.js:1882)
    at <eval> (script.js:1885)
', crates/spin-js-engine/src/lib.rs:193:15
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: the `wizer.initialize` function trapped

Caused by:
    wasm trap: wasm `unreachable` instruction executed
    wasm backtrace:
        0: 0x188002 - <unknown>!__rust_start_panic
    note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information

Swapping the imports order works around this issue. However, it would be great if TextEncoder, TextDecoder and others would be available without having to 1) care about the import order, and 2) manually add it as a dependency.

As a side note, I am bumping into a similar issue for new URL, but so far haven't been able to import a package that works around the issue.

Unknown Wasm section warning

Running make on the example results in the following warning — although the build succeeds.

$ make
...
mkdir -p target
crates/spin-js-cli/target/release/spinjs -o target/spin-http-js.wasm spin-http.js
warning: unknown name subsection with id 9 at 4807649

Alias for `fetch`

Do we want to consider aliasing spinSdk.http.send to fetch (or rather adapting it to the same signature)?

Does that set an expectation that certain functions are available, or is it helpful to have familiar constructs?

Linux ARM64 Support

Hi folks! Loving spin so far, but I'm doing my development on a Linux ARM64 machine: is it possible to support this architecture in coming releases, please?

`process` not defined

I am trying to use an external package and the build fails with: Uncaught ReferenceError: 'process' is not defined

Add methods to the request object

It would be nice if we could add the following methods to the HttpRequest interface to allow for easier handling of requests.

  • json
  • text
  • formdata

Rename to `spin-js-sdk`?

The convention we are going for with new Spin SDK repositories is spin-<language>-sdk — would it make sense to rename this repository as well?

Improving routing?

Scenario: I am trying to build a single component that can handle multiple paths.
How should one handle routing inside a component?

Here is what I currently have:

export const handleRequest: HandleRequest = async function(
  request: HttpRequest
): Promise<HttpResponse> {
  switch (request.headers["spin-path-info"]) {
    case "/list": {
      return await list(...);
    }
    case "/remove": {
      return await remove(...);
    }
    case "/add": {
      return await add(...);
    }

    default: {
      return { status: 500, headers: {} };
    }
  }

Do we want to consider a lightweight router? How would it look like?

Spin template version compatibility tags

When a user runs spin templates install --git https://github.com/fermyon/spin-js-sdk, Spin looks in the repo for a Git tag of the form spin/templates/vX.Y matching the major-minor version of Spin.

If that tag is found, Spin installs the version of the template at that tag. This means that if a SDK makes potentially breaking changes (for example, referring to new host components), old Spin versions still install templates with compatible SDK versions.

If no tag is found, Spin 'falls forward' and installs from main. This could cause Spin to pick up a template that references a SDK version that imports host services that aren't in the user's version of Spin, which would result in errors at runtime.

It would be good to start tagging the JS SDK repo with template version compatibility tags. We probably don't need to do older versions of Spin but maybe v0.7 and v0.8 tags so that users of those versions get stable versions of the templates?

Here is an example from the Spin repo itself:

image

Typed options for `fetch`

The fetch function in the SDK takes an optional parameter options, which is defined as object in the TypeScript SDK:

    function fetch(uri: string, options?: object): Promise<FetchResult>;

This means there is no type checking for the options parameter, which makes fetch requests quite error prone.

Implement `setTimeout`

In trying to use the SDK, I encountered the missing timeout function:

 ReferenceError: 'setTimeout' is not defined

Rename NPM package to `@fermyon/spin-sdk`

This way, when importing, it would go from

import { HandleRequest, HttpResponse} from "@fermyon/spin-sdk-types"

to

import { HandleRequest, HttpResponse} from "@fermyon/spin-sdk"

Additionally, we might want to extend the SDK to include other things, not just types.

Publish `spinjs` as a `spin` plugin

Ideally, we'd like spinjs to be a published NPM package that developers can npm add to their project to make Spin apps.

I've never done this, myself, so I don't know the best way to do it. A quick search turned up https://www.woubuc.be/blog/post/publishing-rust-binary-on-npm/, which might be a good place to start.

Ideally, this would be built and published via a GitHub action, but it could be just a bash script to start with.

Let's package spinjs as a spin plugin, and publish the TS type declarations separately as an NPM package.

Spin build fails when using the one of the templates from spin-js-sdk

Steps to reproduce

  • use the steps from here to init and build a new ts component
    i.e.
> spin new http-ts ts-hello-test --accept-defaults
> npm install
> spin build
  • run spin build again

Result: When running spin build for the 2nd time you get the following error
image

Workaround

In order to build your app for the 2nd time, you need to manually delete the following folders: -p, dist and target

Other info:

OS: Windows 11 Pro, Version 10.0.22621 Build 22621
Spin: 0.7.1 (6cf7447 2022-12-19)
Spin plugin: js2wasm 0.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.