@lizard-build/sdk 0.1.58 → 0.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -23,9 +23,10 @@ declare class PlatformClient {
23
23
  readonly config: ConnectionConfig;
24
24
  constructor(opts: ConnectionOpts);
25
25
  private json;
26
- request<T>(method: string, path: string, body?: unknown): Promise<T>;
26
+ /** `timeoutMs` overrides the connection's requestTimeoutMs for a call known to be slow, never shortening it. */
27
+ request<T>(method: string, path: string, body?: unknown, timeoutMs?: number): Promise<T>;
27
28
  get<T>(path: string): Promise<T>;
28
- post<T>(path: string, body?: unknown): Promise<T>;
29
+ post<T>(path: string, body?: unknown, timeoutMs?: number): Promise<T>;
29
30
  put<T>(path: string, body: unknown): Promise<T>;
30
31
  patch<T>(path: string, body: unknown): Promise<T>;
31
32
  delete<T = void>(path: string, body?: unknown): Promise<T>;
@@ -1175,9 +1176,10 @@ declare class Sandbox extends SandboxClient {
1175
1176
  }): Promise<ForkResult<this>[]>;
1176
1177
  /**
1177
1178
  * Save this sandbox -- memory, running processes and files -- as a private
1178
- * snapshot. A Firecracker snapshot is `ready` as soon as this returns (about 2 s);
1179
- * start copies of it with {@link Sandbox.restore} (about 0.4 s each). The source
1180
- * keeps running. `poolSize` applies to container sandboxes only.
1179
+ * snapshot. A Firecracker snapshot is `ready` as soon as this returns: about 2 s, up to
1180
+ * a few minutes for a sandbox that filled most of its memory (its memory is uploaded
1181
+ * first), so the call waits up to 11 minutes. Start copies of it with {@link Sandbox.restore}
1182
+ * (about 0.4 s each). The source keeps running. `poolSize` applies to container sandboxes only.
1181
1183
  */
1182
1184
  snapshot(name?: string, opts?: SnapshotOpts): Promise<SandboxSnapshot>;
1183
1185
  unexpose(port: number): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -23,9 +23,10 @@ declare class PlatformClient {
23
23
  readonly config: ConnectionConfig;
24
24
  constructor(opts: ConnectionOpts);
25
25
  private json;
26
- request<T>(method: string, path: string, body?: unknown): Promise<T>;
26
+ /** `timeoutMs` overrides the connection's requestTimeoutMs for a call known to be slow, never shortening it. */
27
+ request<T>(method: string, path: string, body?: unknown, timeoutMs?: number): Promise<T>;
27
28
  get<T>(path: string): Promise<T>;
28
- post<T>(path: string, body?: unknown): Promise<T>;
29
+ post<T>(path: string, body?: unknown, timeoutMs?: number): Promise<T>;
29
30
  put<T>(path: string, body: unknown): Promise<T>;
30
31
  patch<T>(path: string, body: unknown): Promise<T>;
31
32
  delete<T = void>(path: string, body?: unknown): Promise<T>;
@@ -1175,9 +1176,10 @@ declare class Sandbox extends SandboxClient {
1175
1176
  }): Promise<ForkResult<this>[]>;
1176
1177
  /**
1177
1178
  * Save this sandbox -- memory, running processes and files -- as a private
1178
- * snapshot. A Firecracker snapshot is `ready` as soon as this returns (about 2 s);
1179
- * start copies of it with {@link Sandbox.restore} (about 0.4 s each). The source
1180
- * keeps running. `poolSize` applies to container sandboxes only.
1179
+ * snapshot. A Firecracker snapshot is `ready` as soon as this returns: about 2 s, up to
1180
+ * a few minutes for a sandbox that filled most of its memory (its memory is uploaded
1181
+ * first), so the call waits up to 11 minutes. Start copies of it with {@link Sandbox.restore}
1182
+ * (about 0.4 s each). The source keeps running. `poolSize` applies to container sandboxes only.
1181
1183
  */
1182
1184
  snapshot(name?: string, opts?: SnapshotOpts): Promise<SandboxSnapshot>;
1183
1185
  unexpose(port: number): Promise<void>;
package/dist/index.js CHANGED
@@ -176,19 +176,20 @@ var PlatformClient = class {
176
176
  const text = await res.text();
177
177
  return text ? JSON.parse(text) : void 0;
178
178
  }
179
- request(method, path, body) {
179
+ /** `timeoutMs` overrides the connection's requestTimeoutMs for a call known to be slow, never shortening it. */
180
+ request(method, path, body, timeoutMs) {
180
181
  return fetch(`${this.config.apiUrl}${path}`, {
181
182
  method,
182
183
  headers: this.config.headers,
183
184
  body: body === void 0 ? void 0 : JSON.stringify(body),
184
- signal: AbortSignal.timeout(this.config.requestTimeoutMs)
185
+ signal: AbortSignal.timeout(Math.max(this.config.requestTimeoutMs, timeoutMs ?? 0))
185
186
  }).then((res) => this.json(res));
186
187
  }
187
188
  get(path) {
188
189
  return this.request("GET", path);
189
190
  }
190
- post(path, body) {
191
- return this.request("POST", path, body);
191
+ post(path, body, timeoutMs) {
192
+ return this.request("POST", path, body, timeoutMs);
192
193
  }
193
194
  put(path, body) {
194
195
  return this.request("PUT", path, body);
@@ -1126,6 +1127,7 @@ var SandboxClient = class {
1126
1127
  };
1127
1128
 
1128
1129
  // src/sandbox/index.ts
1130
+ var SNAPSHOT_TIMEOUT_MS = 11 * 6e4;
1129
1131
  var Sandbox = class extends SandboxClient {
1130
1132
  constructor(opts) {
1131
1133
  super();
@@ -1286,12 +1288,13 @@ var Sandbox = class extends SandboxClient {
1286
1288
  }
1287
1289
  /**
1288
1290
  * Save this sandbox -- memory, running processes and files -- as a private
1289
- * snapshot. A Firecracker snapshot is `ready` as soon as this returns (about 2 s);
1290
- * start copies of it with {@link Sandbox.restore} (about 0.4 s each). The source
1291
- * keeps running. `poolSize` applies to container sandboxes only.
1291
+ * snapshot. A Firecracker snapshot is `ready` as soon as this returns: about 2 s, up to
1292
+ * a few minutes for a sandbox that filled most of its memory (its memory is uploaded
1293
+ * first), so the call waits up to 11 minutes. Start copies of it with {@link Sandbox.restore}
1294
+ * (about 0.4 s each). The source keeps running. `poolSize` applies to container sandboxes only.
1292
1295
  */
1293
1296
  snapshot(name = `Snapshot ${this.sandboxId}`, opts = {}) {
1294
- return new PlatformClient(this.resolveOpts()).post(`/api/sandboxes/${this.sandboxId}/snapshot`, { name, poolSize: opts.poolSize ?? 5, scope: opts.scope });
1297
+ return new PlatformClient(this.resolveOpts()).post(`/api/sandboxes/${this.sandboxId}/snapshot`, { name, poolSize: opts.poolSize ?? 5, scope: opts.scope }, SNAPSHOT_TIMEOUT_MS);
1295
1298
  }
1296
1299
  unexpose(port) {
1297
1300
  return new PlatformClient(this.resolveOpts()).delete(`/api/sandboxes/${this.sandboxId}/expose/${port}`);
package/dist/index.mjs CHANGED
@@ -123,19 +123,20 @@ var PlatformClient = class {
123
123
  const text = await res.text();
124
124
  return text ? JSON.parse(text) : void 0;
125
125
  }
126
- request(method, path, body) {
126
+ /** `timeoutMs` overrides the connection's requestTimeoutMs for a call known to be slow, never shortening it. */
127
+ request(method, path, body, timeoutMs) {
127
128
  return fetch(`${this.config.apiUrl}${path}`, {
128
129
  method,
129
130
  headers: this.config.headers,
130
131
  body: body === void 0 ? void 0 : JSON.stringify(body),
131
- signal: AbortSignal.timeout(this.config.requestTimeoutMs)
132
+ signal: AbortSignal.timeout(Math.max(this.config.requestTimeoutMs, timeoutMs ?? 0))
132
133
  }).then((res) => this.json(res));
133
134
  }
134
135
  get(path) {
135
136
  return this.request("GET", path);
136
137
  }
137
- post(path, body) {
138
- return this.request("POST", path, body);
138
+ post(path, body, timeoutMs) {
139
+ return this.request("POST", path, body, timeoutMs);
139
140
  }
140
141
  put(path, body) {
141
142
  return this.request("PUT", path, body);
@@ -1073,6 +1074,7 @@ var SandboxClient = class {
1073
1074
  };
1074
1075
 
1075
1076
  // src/sandbox/index.ts
1077
+ var SNAPSHOT_TIMEOUT_MS = 11 * 6e4;
1076
1078
  var Sandbox = class extends SandboxClient {
1077
1079
  constructor(opts) {
1078
1080
  super();
@@ -1233,12 +1235,13 @@ var Sandbox = class extends SandboxClient {
1233
1235
  }
1234
1236
  /**
1235
1237
  * Save this sandbox -- memory, running processes and files -- as a private
1236
- * snapshot. A Firecracker snapshot is `ready` as soon as this returns (about 2 s);
1237
- * start copies of it with {@link Sandbox.restore} (about 0.4 s each). The source
1238
- * keeps running. `poolSize` applies to container sandboxes only.
1238
+ * snapshot. A Firecracker snapshot is `ready` as soon as this returns: about 2 s, up to
1239
+ * a few minutes for a sandbox that filled most of its memory (its memory is uploaded
1240
+ * first), so the call waits up to 11 minutes. Start copies of it with {@link Sandbox.restore}
1241
+ * (about 0.4 s each). The source keeps running. `poolSize` applies to container sandboxes only.
1239
1242
  */
1240
1243
  snapshot(name = `Snapshot ${this.sandboxId}`, opts = {}) {
1241
- return new PlatformClient(this.resolveOpts()).post(`/api/sandboxes/${this.sandboxId}/snapshot`, { name, poolSize: opts.poolSize ?? 5, scope: opts.scope });
1244
+ return new PlatformClient(this.resolveOpts()).post(`/api/sandboxes/${this.sandboxId}/snapshot`, { name, poolSize: opts.poolSize ?? 5, scope: opts.scope }, SNAPSHOT_TIMEOUT_MS);
1242
1245
  }
1243
1246
  unexpose(port) {
1244
1247
  return new PlatformClient(this.resolveOpts()).delete(`/api/sandboxes/${this.sandboxId}/expose/${port}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lizard-build/sdk",
3
- "version": "0.1.58",
3
+ "version": "0.1.59",
4
4
  "description": "TypeScript SDK for Lizard: Firecracker microVM sandboxes, code execution and cloud apps.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",