diff --git a/content/v2/http-trigger.md b/content/v2/http-trigger.md index 01ab28e6..4263a433 100644 --- a/content/v2/http-trigger.md +++ b/content/v2/http-trigger.md @@ -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"; diff --git a/content/v2/javascript-components.md b/content/v2/javascript-components.md index 015b3b57..2ab45e46 100644 --- a/content/v2/javascript-components.md +++ b/content/v2/javascript-components.md @@ -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 diff --git a/content/v2/kv-store-api-guide.md b/content/v2/kv-store-api-guide.md index d8ee6dcc..68ec37fe 100644 --- a/content/v2/kv-store-api-guide.md +++ b/content/v2/kv-store-api-guide.md @@ -83,9 +83,9 @@ fn handle_request(_req: Request) -> Result { {{ 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"; @@ -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 }} diff --git a/content/v2/language-support-overview.md b/content/v2/language-support-overview.md index e5d277fd..49dd329f 100644 --- a/content/v2/language-support-overview.md +++ b/content/v2/language-support-overview.md @@ -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? | |-----|-----| diff --git a/content/v2/mqtt-outbound.md b/content/v2/mqtt-outbound.md index fb6931de..04845c45 100644 --- a/content/v2/mqtt-outbound.md +++ b/content/v2/mqtt-outbound.md @@ -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. @@ -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). diff --git a/content/v2/rdbms-storage.md b/content/v2/rdbms-storage.md index 5865eb69..690416d2 100644 --- a/content/v2/rdbms-storage.md +++ b/content/v2/rdbms-storage.md @@ -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. diff --git a/content/v2/redis-outbound.md b/content/v2/redis-outbound.md index 97a29473..1a59e08f 100644 --- a/content/v2/redis-outbound.md +++ b/content/v2/redis-outbound.md @@ -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" diff --git a/content/v2/serverless-ai-api-guide.md b/content/v2/serverless-ai-api-guide.md index db123823..e650665a 100644 --- a/content/v2/serverless-ai-api-guide.md +++ b/content/v2/serverless-ai-api-guide.md @@ -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" @@ -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 }} diff --git a/content/v2/sqlite-api-guide.md b/content/v2/sqlite-api-guide.md index 2e0a287e..cf2232d7 100644 --- a/content/v2/sqlite-api-guide.md +++ b/content/v2/sqlite-api-guide.md @@ -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"; diff --git a/content/v2/variables.md b/content/v2/variables.md index 70c1000d..2884fadd 100644 --- a/content/v2/variables.md +++ b/content/v2/variables.md @@ -133,7 +133,7 @@ async fn handle_api_call_with_token(_req: Request) -> anyhow::Result [**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"; diff --git a/content/v3/ai-sentiment-analysis-api-tutorial.md b/content/v3/ai-sentiment-analysis-api-tutorial.md index b820f8ca..9633054d 100644 --- a/content/v3/ai-sentiment-analysis-api-tutorial.md +++ b/content/v3/ai-sentiment-analysis-api-tutorial.md @@ -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 { diff --git a/content/v3/build.md b/content/v3/build.md index 76cc1183..40e2a8d7 100644 --- a/content/v3/build.md +++ b/content/v3/build.md @@ -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" } } ``` diff --git a/content/v3/http-trigger.md b/content/v3/http-trigger.md index 7f06e032..0784bf3c 100644 --- a/content/v3/http-trigger.md +++ b/content/v3/http-trigger.md @@ -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. diff --git a/content/v3/javascript-components.md b/content/v3/javascript-components.md index ea7ecd0f..87c7c8c1 100644 --- a/content/v3/javascript-components.md +++ b/content/v3/javascript-components.md @@ -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 @@ -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 @@ -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/'; @@ -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 @@ -331,21 +336,24 @@ The SDK does not support the full specification of `Node.js`. A limited set of A ```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: diff --git a/content/v3/key-value-store-tutorial.md b/content/v3/key-value-store-tutorial.md index 07c6964c..e3203fa7 100644 --- a/content/v3/key-value-store-tutorial.md +++ b/content/v3/key-value-store-tutorial.md @@ -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 ``` @@ -234,7 +236,7 @@ fn handle_request(req: Request) -> anyhow::Result { ```typescript import { AutoRouter } from 'itty-router'; -import { Kv } from '@fermyon/spin-sdk'; +import { openDefault } from '@spinframework/spin-kv'; const decoder = new TextDecoder(); @@ -242,7 +244,7 @@ let router = AutoRouter(); router .all("*", async (req: Request) => { - let store = Kv.openDefault(); + let store = openDefault(); let status = 200; let body; diff --git a/content/v3/kv-store-api-guide.md b/content/v3/kv-store-api-guide.md index d4167c3a..a28ab671 100644 --- a/content/v3/kv-store-api-guide.md +++ b/content/v3/kv-store-api-guide.md @@ -83,19 +83,19 @@ fn handle_request(_req: Request) -> Result { {{ 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/) -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/stable/modules/Kv.html) which returns a [handle to the store](https://spinframework.github.io/spin-js-sdk/stable/interfaces/Kv.Store.html). For example: +The key value functions can be accessed after opening a store using either [the `open` or the `openDefault` functions](https://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-kv.html) which returns a [handle to the store](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-kv.Store.html). For example: ```ts import { AutoRouter } from 'itty-router'; -import { Kv } from '@fermyon/spin-sdk'; +import { openDefault } from '@spinframework/spin-kv'; let router = AutoRouter(); router .get("/", () => { - let store = Kv.openDefault() + let store = openDefault() store.set("mykey", "myvalue") return new Response(store.get("mykey") ?? "Key not found"); }) @@ -109,14 +109,14 @@ addEventListener('fetch', async (event: FetchEvent) => { **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/stable/interfaces/Kv.Store.html#get) +[`get` **Operation**](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-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/stable/interfaces/Kv.Store.html#set) +[`set` **Operation**](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-kv.Store.html#set) - The value argument is of the type `Uint8Array | string | object`. -[`setJson`](https://spinframework.github.io/spin-js-sdk/stable/interfaces/Kv.Store.html#setJson) and [`getJson` **Operation**](https://spinframework.github.io/spin-js-sdk/stable/interfaces/Kv.Store.html#getJson) +[`setJson`](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-kv.Store.html#setjson) and [`getJson` **Operation**](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-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 }} diff --git a/content/v3/language-support-overview.md b/content/v3/language-support-overview.md index 94598dfc..d0ea48d9 100644 --- a/content/v3/language-support-overview.md +++ b/content/v3/language-support-overview.md @@ -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/stable/) to see specific modules, functions, variables and syntax relating to the following TS/JS features.** +**[📄 Visit the JS/TS Spin SDK reference documentation](https://spinframework.github.io/spin-js-sdk/) to see specific modules, functions, variables and syntax relating to the following TS/JS features.** | Feature | SDK Supported? | |-----|-----| diff --git a/content/v3/mqtt-outbound.md b/content/v3/mqtt-outbound.md index 90077703..0bba8769 100644 --- a/content/v3/mqtt-outbound.md +++ b/content/v3/mqtt-outbound.md @@ -57,11 +57,13 @@ 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/stable/modules/Mqtt.html) +> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-mqtt.html) -To access an MQTT server, use the `Mqtt.open` function. +To access an MQTT server, use the `open` function. ```ts +import { open, QoS } from "@spinframework/spin-mqtt"; + let connection = Mqtt.open(address, username, password, keepAliveSecs); ``` @@ -72,7 +74,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/stable/modules/Mqtt.html) +For full details of the MQTT API, see the [Spin SDK reference documentation](https://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-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/main/examples/spin-host-apis/spin-mqtt). diff --git a/content/v3/rdbms-storage.md b/content/v3/rdbms-storage.md index 176da8fc..6368d909 100644 --- a/content/v3/rdbms-storage.md +++ b/content/v3/rdbms-storage.md @@ -73,14 +73,14 @@ 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/stable/) +> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/) The code below is an [Outbound MySQL example](https://github.com/spinframework/spin-js-sdk/tree/main/examples/spin-host-apis/spin-mysql). There is also an outbound [PostgreSQL example](https://github.com/spinframework/spin-js-sdk/tree/main/examples/spin-host-apis/spin-postgres) available. ```ts // https://itty.dev/itty-router/routers/autorouter import { AutoRouter } from 'itty-router'; -import { Mysql } from '@fermyon/spin-sdk'; +import { open } from '@spinframework/spin-mysql'; // Connects as the root user without a password const DB_URL = "mysql://root:@127.0.0.1/spin_dev" @@ -97,7 +97,7 @@ let router = AutoRouter(); router .get("/", () => { - let conn = Mysql.open(DB_URL); + let conn = open(DB_URL); conn.execute('delete from test where id=?', [4]); conn.execute('insert into test values (4,5)', []); let ret = conn.query('select * from test', []); diff --git a/content/v3/redis-outbound.md b/content/v3/redis-outbound.md index 1308f710..ddc56936 100644 --- a/content/v3/redis-outbound.md +++ b/content/v3/redis-outbound.md @@ -89,14 +89,14 @@ 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/stable/) +> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/) -Redis functions are available on [the `Redis` module](https://spinframework.github.io/spin-js-sdk/stable/modules/Redis.html). The function names match the operations above. For example: +Redis functions are available on [the `Redis` module](https://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-redis.html). The function names match the operations above. For example: ```javascript -import { Redis } from "@fermyon/spin-sdk" +import { open } from "@spinframework/spin-redis" -let db = Redis.open("redis://localhost:6379") +let db = open("redis://localhost:6379") let value = db.get(key); ``` diff --git a/content/v3/serverless-ai-api-guide.md b/content/v3/serverless-ai-api-guide.md index 84cb465a..1088804f 100644 --- a/content/v3/serverless-ai-api-guide.md +++ b/content/v3/serverless-ai-api-guide.md @@ -116,21 +116,21 @@ 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/stable/modules/Llm.html) +> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/) -To use Serverless AI functions, [the `Llm` module](https://spinframework.github.io/spin-js-sdk/stable/modules/Llm.html) from the Spin SDK provides two methods: `infer` and `generateEmbeddings`. For example: +To use Serverless AI functions, [the `@spinframework/spin-llm` pacakge](https://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-llm.html) provides two methods: `infer` and `generateEmbeddings`. For example: ```javascript import { AutoRouter } from 'itty-router'; -import { Llm } from '@fermyon/spin-sdk'; +import { inferencingModels, EmbeddingModels, infer, generateEmbeddings } from '@spinframework/spin-llm'; let router = AutoRouter(); router .get("/", () => { - let embeddings = Llm.generateEmbeddings(Llm.EmbeddingModels.AllMiniLmL6V2, ["someString"]) + let embeddings = generateEmbeddings(EmbeddingModels.AllMiniLmL6V2, ["someString"]) console.log(embeddings.embeddings) - let result = Llm.infer(Llm.InferencingModels.Llama2Chat, prompt) + let result = infer(InferencingModels.Llama2Chat, prompt) return new Response(result.text); }) @@ -146,15 +146,15 @@ addEventListener('fetch', async (event: FetchEvent) => { `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/stable/enums/Llm.InferencingModels.html). -- The optional third parameter which is an [InferencingOptions](https://spinframework.github.io/spin-js-sdk/stable/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/stable/interfaces/Llm.EmbeddingResult.html). +- 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/enums/_spinframework_spin-llm.InferencingModels.html). +- The optional third parameter which is an [InferencingOptions](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-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/interfaces/_spinframework_spin-llm.InferenceResult.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/stable/enums/Llm.EmbeddingModels.html). -- The return value is an [`EmbeddingResult`](https://spinframework.github.io/spin-js-sdk/stable/interfaces/Llm.EmbeddingResult.html) +- The model name is a string. There are enums for the inbuilt models (AllMiniLmL6V2) in [`EmbeddingModels`](https://spinframework.github.io/spin-js-sdk/enums/_spinframework_spin-llm.EmbeddingModels.html). +- The return value is an [`EmbeddingResult`](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-llm.EmbeddingResult.html) {{ blockEnd }} diff --git a/content/v3/sqlite-api-guide.md b/content/v3/sqlite-api-guide.md index 92cfa450..987d817c 100644 --- a/content/v3/sqlite-api-guide.md +++ b/content/v3/sqlite-api-guide.md @@ -119,13 +119,13 @@ struct ToDo { {{ startTab "Typescript"}} -> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/stable/modules/Sqlite.html) +> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/) -To use SQLite functions, use [the `Sqlite.open` or `Sqlite.openDefault` function](https://spinframework.github.io/spin-js-sdk/stable/modules/Sqlite.html) to obtain [a `SqliteConnection` object](https://spinframework.github.io/spin-js-sdk/stable/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://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-sqlite.html) to obtain [a `SqliteConnection` object](https://spinframework.github.io/spin-js-sdk/interfaces/_spinframework_spin-sqlite.SqliteConnection.html). `SqliteConnection` provides the `execute` method as described above. For example: ```javascript import { AutoRouter } from 'itty-router'; -import { Sqlite } from '@fermyon/spin-sdk'; +import { Sqlite } from '@spinframework/spin-sqlite'; let router = AutoRouter(); router diff --git a/content/v3/variables.md b/content/v3/variables.md index 46ed0198..8eeb7049 100644 --- a/content/v3/variables.md +++ b/content/v3/variables.md @@ -134,7 +134,7 @@ async fn handle_api_call_with_token(_req: Request) -> anyhow::Result [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/stable/modules/Variables.html) +> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-js-sdk/modules/_spinframework_spin-variables.html) ```ts import { AutoRouter } from 'itty-router';