Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions content/v2/http-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ For a full Rust SDK reference, see the [Rust Spin SDK documentation](https://doc

{{ startTab "TypeScript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/)

The user must a define a function named `handler` which the SDK attaches to the [`FetchEvent` listener](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent). Note that the incoming HTTP event is translated to a `FetchEvent`.

The handler function takes in two arguments a [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and a [ResponseBuilder](https://spinframework.github.io/spin-js-sdk/v2.3/classes/ResponseBuilder.html)
The handler function takes in two arguments a [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and a [ResponseBuilder](https://fermyon.github.io/spin-js-sdk/v2.3/classes/ResponseBuilder.html)

```ts
import { ResponseBuilder } from "@fermyon/spin-sdk";
Expand Down
2 changes: 1 addition & 1 deletion content/v2/javascript-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ With JavaScript being a very popular language, Spin provides an SDK to support b

> All examples from this page can be found in [the JavaScript SDK repository on GitHub](https://github.com/spinframework/spin-js-sdk/tree/sdk-v2/examples).

[**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/)
[**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/)

## Installing Templates

Expand Down
10 changes: 5 additions & 5 deletions content/v2/kv-store-api-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ fn handle_request(_req: Request) -> Result<impl IntoResponse> {

{{ startTab "Typescript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/)

The key value functions can be accessed after opening a store using either [the `Kv.open` or the `Kv.openDefault` methods](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Kv.html) which returns a [handle to the store](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html). For example:
The key value functions can be accessed after opening a store using either [the `Kv.open` or the `Kv.openDefault` methods](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Kv.html) which returns a [handle to the store](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html). For example:

```ts
import { ResponseBuilder , Kv} from "@fermyon/spin-sdk";
Expand All @@ -102,14 +102,14 @@ export async function handler(req: Request, res: ResponseBuilder) {
**General Notes**
- The SDK doesn't surface the `close` operation. It automatically closes all stores at the end of the request; there's no way to close them early.

[`get` **Operation**](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#get)
[`get` **Operation**](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#get)
- The result is of the type `Uint8Array | null`
- If the key does not exist, `get` returns `null`

[`set` **Operation**](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#set)
[`set` **Operation**](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#set)
- The value argument is of the type `Uint8Array | string | object`.

[`setJson`](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#setJson) and [`getJson` **Operation**](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#getJson)
[`setJson`](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#setJson) and [`getJson` **Operation**](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Kv.Store.html#getJson)
- Applications can store JavaScript objects using `setJson`; these are serialized within the store as JSON. These serialized objects can be retrieved and deserialized using `getJson`. If you call `getJson` on a key that doesn't exist then it returns an empty object.

{{ blockEnd }}
Expand Down
2 changes: 1 addition & 1 deletion content/v2/language-support-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This page contains information about language support for Spin features:

{{ startTab "TypeScript"}}

**[📄 Visit the JS/TS Spin SDK reference documentation](https://spinframework.github.io/spin-js-sdk/v2.3/) to see specific modules, functions, variables and syntax relating to the following TS/JS features.**
**[📄 Visit the JS/TS Spin SDK reference documentation](https://fermyon.github.io/spin-js-sdk/v2.3/) to see specific modules, functions, variables and syntax relating to the following TS/JS features.**

| Feature | SDK Supported? |
|-----|-----|
Expand Down
4 changes: 2 additions & 2 deletions content/v2/mqtt-outbound.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can find a complete Rust code example for using outbound MQTT from an HTTP c

{{ startTab "TypeScript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Mqtt.html)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Mqtt.html)

To access an MQTT server, use the `Mqtt.open` function.

Expand All @@ -72,7 +72,7 @@ let catPicture = new Uint8Array(await req.arraybuffer());
connection.publish("pets", catPicture, QoS.AtleastOnce);
```

For full details of the MQTT API, see the [Spin SDK reference documentation](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Mqtt.html)
For full details of the MQTT API, see the [Spin SDK reference documentation](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Mqtt.html)

You can find a complete Rust code example for using outbound MQTT from an HTTP component in the [Spin Rust SDK repository on GitHub](https://github.com/spinframework/spin-js-sdk/tree/sdk-v2/examples/spin-host-apis/spin-mqtt).

Expand Down
2 changes: 1 addition & 1 deletion content/v2/rdbms-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ For full information about the MySQL and PostgreSQL APIs, see [the Spin SDK refe

{{ startTab "TypeScript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/)

The code below is an [Outbound MySQL example](https://github.com/spinframework/spin-js-sdk/tree/sdk-v2/examples/spin-host-apis/spin-mysql). There is also an outbound [PostgreSQL example](https://github.com/spinframework/spin-js-sdk/tree/sdk-v2/examples/spin-host-apis/spin-postgres) available.

Expand Down
4 changes: 2 additions & 2 deletions content/v2/redis-outbound.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ You can find a complete Rust code example for using outbound Redis from an HTTP

{{ startTab "TypeScript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/)

Redis functions are available on [the `Redis` module](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Redis.html). The function names match the operations above. For example:
Redis functions are available on [the `Redis` module](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Redis.html). The function names match the operations above. For example:

```javascript
import { Redis } from "@fermyon/spin-sdk"
Expand Down
14 changes: 7 additions & 7 deletions content/v2/serverless-ai-api-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ The `infer_with_options` examples, operation:

{{ startTab "Typescript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Llm.html)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Llm.html)

To use Serverless AI functions, [the `Llm` module](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Llm.html) from the Spin SDK provides two methods: `infer` and `generateEmbeddings`. For example:
To use Serverless AI functions, [the `Llm` module](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Llm.html) from the Spin SDK provides two methods: `infer` and `generateEmbeddings`. For example:

```javascript
import { ResponseBuilder, Llm} from "@fermyon/spin-sdk"
Expand All @@ -134,15 +134,15 @@ export async function handler(req: Request, res: ResponseBuilder) {
`infer` operation:

- It takes in the following arguments - model name, prompt and a optional third parameter for inferencing options.
- The model name is a string. There are enums for the inbuilt models (llama2-chat and codellama) in [`InferencingModels`](https://spinframework.github.io/spin-js-sdk/v2.3/enums/Llm.InferencingModels.html).
- The optional third parameter which is an [InferencingOptions](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Llm.InferencingOptions.html) interface allows you to specify parameters such as `maxTokens`, `repeatPenalty`, `repeatPenaltyLastNTokenCount`, `temperature`, `topK`, `topP`.
- The return value is an [`InferenceResult`](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Llm.EmbeddingResult.html).
- The model name is a string. There are enums for the inbuilt models (llama2-chat and codellama) in [`InferencingModels`](https://fermyon.github.io/spin-js-sdk/v2.3/enums/Llm.InferencingModels.html).
- The optional third parameter which is an [InferencingOptions](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Llm.InferencingOptions.html) interface allows you to specify parameters such as `maxTokens`, `repeatPenalty`, `repeatPenaltyLastNTokenCount`, `temperature`, `topK`, `topP`.
- The return value is an [`InferenceResult`](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Llm.EmbeddingResult.html).

`generateEmbeddings` operation:

- It takes two arguments - model name and list of strings to generate the embeddings for.
- The model name is a string. There are enums for the inbuilt models (AllMiniLmL6V2) in [`EmbeddingModels`](https://spinframework.github.io/spin-js-sdk/v2.3/enums/Llm.EmbeddingModels.html).
- The return value is an [`EmbeddingResult`](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Llm.EmbeddingResult.html)
- The model name is a string. There are enums for the inbuilt models (AllMiniLmL6V2) in [`EmbeddingModels`](https://fermyon.github.io/spin-js-sdk/v2.3/enums/Llm.EmbeddingModels.html).
- The return value is an [`EmbeddingResult`](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Llm.EmbeddingResult.html)

{{ blockEnd }}

Expand Down
4 changes: 2 additions & 2 deletions content/v2/sqlite-api-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ struct ToDo {

{{ startTab "Typescript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Sqlite.html)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Sqlite.html)
To use SQLite functions, use [the `Sqlite.open` or `Sqlite.openDefault` function](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Sqlite.html) to obtain [a `SqliteConnection` object](https://spinframework.github.io/spin-js-sdk/v2.3/interfaces/Sqlite.SqliteConnection.html). `SqliteConnection` provides the `execute` method as described above. For example:
To use SQLite functions, use [the `Sqlite.open` or `Sqlite.openDefault` function](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Sqlite.html) to obtain [a `SqliteConnection` object](https://fermyon.github.io/spin-js-sdk/v2.3/interfaces/Sqlite.SqliteConnection.html). `SqliteConnection` provides the `execute` method as described above. For example:

```javascript
import { ResponseBuilder, Sqlite } from "@fermyon/spin-sdk";
Expand Down
2 changes: 1 addition & 1 deletion content/v2/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async fn handle_api_call_with_token(_req: Request) -> anyhow::Result<impl IntoRe

{{ startTab "TypeScript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/v2.3/modules/Variables.html)
> [**Want to go straight to the reference documentation?** Find it here.](https://fermyon.github.io/spin-js-sdk/v2.3/modules/Variables.html)

```ts
import { ResponseBuilder, Variables } from "@fermyon/spin-sdk";
Expand Down
3 changes: 2 additions & 1 deletion content/v3/ai-sentiment-analysis-api-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ impl FromStr for Sentiment {
{{ startTab "TypeScript"}}

```typescript
import { Llm, Kv } from "@fermyon/spin-sdk";
import * as Llm from "@spinframework/spin-llm";
import * as Kv from "@spinframework/spin-kv";
import { AutoRouter } from 'itty-router';

interface SentimentAnalysisRequest {
Expand Down
2 changes: 1 addition & 1 deletion content/v3/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ It's normally convenient to put the detailed build instructions in `package.json
```json
{
"scripts": {
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/spin-http-js.wasm"
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -o target/spin-http-js.wasm"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion content/v3/http-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ For a full Rust SDK reference, see the [Rust Spin SDK documentation](https://doc

{{ startTab "TypeScript"}}

> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/stable/)
> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/)
Building a Spin HTTP component with the JavaScript/TypeScript SDK now involves adding an event listener for the `fetch` event. This event listener handles incoming HTTP requests and allows you to construct and return HTTP responses.

Expand Down
38 changes: 23 additions & 15 deletions content/v3/javascript-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ With JavaScript being a very popular language, Spin provides an SDK to support b

> All examples from this page can be found in [the JavaScript SDK repository on GitHub](https://github.com/spinframework/spin-js-sdk/tree/main/examples).

[**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/stable/)
[**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/)

## Installing Templates

Expand Down Expand Up @@ -77,19 +77,18 @@ This creates a directory of the following structure:

```text
hello-world
├── config
│ └── knitwit.json
├── package.json
├── README.md
├── spin.toml
├── src
└── index.ts
   └── index.ts
├── tsconfig.json
└── webpack.config.js
```

The source for the component is present in `src/index.ts`. [Webpack](https://webpack.js.org) is used to bundle the component into a single `.js` file which will then be compiled to a `.wasm` module.

{{ details "Going from JavaScript to Wasm" "The JS source is compiled to a `wasm` module using the `j2w` node executable provided by the `@fermyon/spin-sdk` which is a wrapper around `ComponentizeJS`. The `knitwit.json` is the configuration file used by [knitwit](https://github.com/fermyon/knitwit) to manage the WebAssembly dependencies of each package."}}
{{ details "Going from JavaScript to Wasm" "The JS source is compiled to a `wasm` module using the `j2w` node executable provided by the `@fermyon/spin-sdk` which is a wrapper around `ComponentizeJS` that is used to manage the dependencies."}}

## Building and Running the Template

Expand Down Expand Up @@ -259,13 +258,13 @@ You must [add `http://self` or `http://self.alt` to the component's `allowed_out
> You can find a complete example for using outbound Redis from an HTTP component
> in the [spin-js-sdk repository on GitHub](https://github.com/spinframework/spin-js-sdk/blob/main/examples/spin-host-apis/spin-redis).

Using the Spin's JS SDK, you can use the Redis key/value store and to publish messages to Redis channels.
We can install and use the `@spinframework/spin-redis` package to use the Redis key/value store and to publish messages to Redis channels.

Let's see how we can use the JS/TS SDK to connect to Redis:

```javascript
import { AutoRouter } from 'itty-router';
import { Redis } from '@fermyon/spin-sdk';
import { Redis } from '@spinframework/spin-redis';

const encoder = new TextEncoder();
const redisAddress = 'redis://localhost:6379/';
Expand Down Expand Up @@ -314,14 +313,20 @@ Spin has a key-value store built in. For information about using it from TypeScr

## Storing Data in SQLite

We can use the `@spinframework/spin-sqlite` package to interact with Spin's SQLite interface.

For more information about using SQLite from TypeScript/Javascript, see [SQLite storage](sqlite-api-guide).

## Storing Data in MySQL and PostgreSQL Relational Databases

We can use the `@spinframework/spin-mysql`, `@spinframework/spin-postgres` package to interact with Spin's RDBMS interfaces.

For more information about using relational databases from TypeScript/JavaScript, see [Relational Databases](rdbms-storage).

## AI Inferencing From JS/TS Components

We can use the `@spinframework/spin-llm` package to interact with Spin's LLM interface.

For more information about using Serverless AI from JS/TS, see the [Serverless AI](serverless-ai-api-guide) API guide.

## Node.js Compatibility
Expand All @@ -331,21 +336,24 @@ The SDK does not support the full specification of `Node.js`. A limited set of A
<!-- @selectiveCpy -->

```bash
$ npm install @fermyon/wasi-ext
$ npm install @spinframework/wasi-ext
```

Once installed, the plugin provided by it can be added to the webpack config:

```js
const WasiExtPlugin = require("wasi-ext/plugin")
import WasiExtPlugin from "@spinframework/wasi-ext/plugin/index.js";

module.exports = {
export default config = () => {
...
plugins: [
new WasiExtPlugin()
],
...
};
return {
...
plugins: [
new WasiExtPlugin()
],
...
}
}
```

This library only currently supports the following polyfills:
Expand Down
6 changes: 4 additions & 2 deletions content/v3/key-value-store-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ $ spin new -t http-rust spin-key-value

```bash
$ spin new -t http-ts spin-key-value
$ cd spin-key-value
$ npm install @spinframework/spin-kv

# Reference: https://github.com/spinframework/spin-js-sdk/tree/main/examples/spin-host-apis/spin-kv
```
Expand Down Expand Up @@ -234,15 +236,15 @@ fn handle_request(req: Request) -> anyhow::Result<impl IntoResponse> {

```typescript
import { AutoRouter } from 'itty-router';
import { Kv } from '@fermyon/spin-sdk';
import { openDefault } from '@spinframework/spin-kv';

const decoder = new TextDecoder();

let router = AutoRouter();

router
.all("*", async (req: Request) => {
let store = Kv.openDefault();
let store = openDefault();
let status = 200;
let body;

Expand Down
Loading
Loading