From b94a6615ae0b1dece524668080a64abf2c2eaa6d Mon Sep 17 00:00:00 2001 From: Paul Butler Date: Mon, 24 Mar 2025 14:25:26 -0400 Subject: [PATCH] Add JavaScript memory limits --- README.md | 14 +++++++++++++- javascript/sdk/src/index.ts | 16 ++++++++++++++++ javascript/sdk/src/types.ts | 4 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f3871d8..ec7d8f2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Chat on Discord](https://img.shields.io/discord/939641163265232947?color=404eed&label=discord)](https://discord.gg/N5sEpsuhh9) | repo | version | -|-----------------------------------------------------|-----------------------------| +|-----------------------------------------------------|------------------------------| | [cli](https://github.com/jamsocket/forevervm) | [![npm](https://img.shields.io/npm/v/forevervm)](https://www.npmjs.com/package/forevervm) | | [sdk](https://github.com/jamsocket/forevervm) | [![npm](https://img.shields.io/npm/v/@forevervm/sdk)](https://www.npmjs.com/package/@forevervm/sdk) | @@ -106,3 +106,15 @@ const productionMachines = await fvm.listMachines({ tags: { env: 'production' } }) ``` + +Memory Limits +---------------- + +You can create machines with memory limits by specifying the memory size in megabytes: + +```typescript +// Create a machine with 512MB memory limit +const machineResponse = await fvm.createMachine({ + memory_mb: 512, +}) +``` diff --git a/javascript/sdk/src/index.ts b/javascript/sdk/src/index.ts index b3a2799..41bc679 100644 --- a/javascript/sdk/src/index.ts +++ b/javascript/sdk/src/index.ts @@ -266,4 +266,20 @@ plt.show()` expect(filteredMachines.machines.length).toBe(1) expect(filteredMachines.machines[0].tags?.unique).toBe(uniqueTag) }) + + test('createMachine with memory limit', async () => { + const fvm = new ForeverVM({ token: FOREVERVM_TOKEN, baseUrl: FOREVERVM_API_BASE }) + + // Create machine with memory limit + const machine = await fvm.createMachine({ + memory_mb: 512, + }) + expect(machine.machine_name).toBeDefined() + + // Verify the machine was created (note: we can't directly verify the memory limit + // through the API as it doesn't return this value in machine details) + const machines = await fvm.listMachines() + const found = machines.machines.find(({ name }) => name === machine.machine_name) + expect(found).toBeDefined() + }) } diff --git a/javascript/sdk/src/types.ts b/javascript/sdk/src/types.ts index 87f08e7..4c9e185 100644 --- a/javascript/sdk/src/types.ts +++ b/javascript/sdk/src/types.ts @@ -46,6 +46,10 @@ export interface WhoamiResponse { export interface CreateMachineRequest { tags?: Record + /** + * Memory size in MB. If not specified, a default value will be used. + */ + memory_mb?: number } export interface CreateMachineResponse {