@lizard-build/sdk 0.1.57 → 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 +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +16 -10
- package/dist/index.mjs +16 -10
- package/package.json +1 -1
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
|
-
|
|
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>;
|
|
@@ -920,6 +921,8 @@ interface SandboxSnapshot {
|
|
|
920
921
|
createdAt: number;
|
|
921
922
|
/** Where it may be restored; see {@link SnapshotScope}. */
|
|
922
923
|
scope: SnapshotScope;
|
|
924
|
+
/** Whether the source had a volume attached (a restore then cannot attach another); `null` for older snapshots, which cannot take one. */
|
|
925
|
+
sourceVolume: boolean | null;
|
|
923
926
|
/** The user who took it; `null` for snapshots from before snapshots belonged to a user. */
|
|
924
927
|
createdBy: string | null;
|
|
925
928
|
}
|
|
@@ -1173,9 +1176,10 @@ declare class Sandbox extends SandboxClient {
|
|
|
1173
1176
|
}): Promise<ForkResult<this>[]>;
|
|
1174
1177
|
/**
|
|
1175
1178
|
* Save this sandbox -- memory, running processes and files -- as a private
|
|
1176
|
-
* snapshot. A Firecracker snapshot is `ready` as soon as this returns
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
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.
|
|
1179
1183
|
*/
|
|
1180
1184
|
snapshot(name?: string, opts?: SnapshotOpts): Promise<SandboxSnapshot>;
|
|
1181
1185
|
unexpose(port: number): Promise<void>;
|
|
@@ -1190,11 +1194,14 @@ declare class Sandbox extends SandboxClient {
|
|
|
1190
1194
|
static getSnapshot(snapshotId: string, opts?: ConnectionOpts): Promise<SandboxSnapshot>;
|
|
1191
1195
|
/**
|
|
1192
1196
|
* Start a new sandbox from a snapshot, in its region. `projectId` puts it in another project,
|
|
1193
|
-
* in any of your workspaces, as the snapshot's scope allows; default: the
|
|
1197
|
+
* in any of your workspaces, as the snapshot's scope allows; default: the volume's project, else
|
|
1198
|
+
* the snapshot's own. `volumeId` mounts that volume at `/workspace` (a Firecracker snapshot of a
|
|
1199
|
+
* sandbox that had no volume attached; the volume must be in the snapshot's region).
|
|
1194
1200
|
*/
|
|
1195
1201
|
static restore(snapshotId: string, opts?: ConnectionOpts & {
|
|
1196
1202
|
timeoutMs?: number;
|
|
1197
1203
|
projectId?: string;
|
|
1204
|
+
volumeId?: string;
|
|
1198
1205
|
}): Promise<Sandbox>;
|
|
1199
1206
|
/** Change where a snapshot you took may be restored. */
|
|
1200
1207
|
static setSnapshotScope(snapshotId: string, scope: SnapshotScope, opts?: ConnectionOpts): Promise<SandboxSnapshot>;
|
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
|
-
|
|
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>;
|
|
@@ -920,6 +921,8 @@ interface SandboxSnapshot {
|
|
|
920
921
|
createdAt: number;
|
|
921
922
|
/** Where it may be restored; see {@link SnapshotScope}. */
|
|
922
923
|
scope: SnapshotScope;
|
|
924
|
+
/** Whether the source had a volume attached (a restore then cannot attach another); `null` for older snapshots, which cannot take one. */
|
|
925
|
+
sourceVolume: boolean | null;
|
|
923
926
|
/** The user who took it; `null` for snapshots from before snapshots belonged to a user. */
|
|
924
927
|
createdBy: string | null;
|
|
925
928
|
}
|
|
@@ -1173,9 +1176,10 @@ declare class Sandbox extends SandboxClient {
|
|
|
1173
1176
|
}): Promise<ForkResult<this>[]>;
|
|
1174
1177
|
/**
|
|
1175
1178
|
* Save this sandbox -- memory, running processes and files -- as a private
|
|
1176
|
-
* snapshot. A Firecracker snapshot is `ready` as soon as this returns
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
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.
|
|
1179
1183
|
*/
|
|
1180
1184
|
snapshot(name?: string, opts?: SnapshotOpts): Promise<SandboxSnapshot>;
|
|
1181
1185
|
unexpose(port: number): Promise<void>;
|
|
@@ -1190,11 +1194,14 @@ declare class Sandbox extends SandboxClient {
|
|
|
1190
1194
|
static getSnapshot(snapshotId: string, opts?: ConnectionOpts): Promise<SandboxSnapshot>;
|
|
1191
1195
|
/**
|
|
1192
1196
|
* Start a new sandbox from a snapshot, in its region. `projectId` puts it in another project,
|
|
1193
|
-
* in any of your workspaces, as the snapshot's scope allows; default: the
|
|
1197
|
+
* in any of your workspaces, as the snapshot's scope allows; default: the volume's project, else
|
|
1198
|
+
* the snapshot's own. `volumeId` mounts that volume at `/workspace` (a Firecracker snapshot of a
|
|
1199
|
+
* sandbox that had no volume attached; the volume must be in the snapshot's region).
|
|
1194
1200
|
*/
|
|
1195
1201
|
static restore(snapshotId: string, opts?: ConnectionOpts & {
|
|
1196
1202
|
timeoutMs?: number;
|
|
1197
1203
|
projectId?: string;
|
|
1204
|
+
volumeId?: string;
|
|
1198
1205
|
}): Promise<Sandbox>;
|
|
1199
1206
|
/** Change where a snapshot you took may be restored. */
|
|
1200
1207
|
static setSnapshotScope(snapshotId: string, scope: SnapshotScope, opts?: ConnectionOpts): Promise<SandboxSnapshot>;
|
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
|
-
|
|
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
|
|
1290
|
-
*
|
|
1291
|
-
*
|
|
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}`);
|
|
@@ -1312,15 +1315,18 @@ var Sandbox = class extends SandboxClient {
|
|
|
1312
1315
|
}
|
|
1313
1316
|
/**
|
|
1314
1317
|
* Start a new sandbox from a snapshot, in its region. `projectId` puts it in another project,
|
|
1315
|
-
* in any of your workspaces, as the snapshot's scope allows; default: the
|
|
1318
|
+
* in any of your workspaces, as the snapshot's scope allows; default: the volume's project, else
|
|
1319
|
+
* the snapshot's own. `volumeId` mounts that volume at `/workspace` (a Firecracker snapshot of a
|
|
1320
|
+
* sandbox that had no volume attached; the volume must be in the snapshot's region).
|
|
1316
1321
|
*/
|
|
1317
1322
|
static async restore(snapshotId, opts) {
|
|
1318
1323
|
const client = new PlatformClient(opts ?? {});
|
|
1319
1324
|
const snapshot = await this.getSnapshot(snapshotId, opts);
|
|
1320
1325
|
const result = await client.post("/api/sandboxes", {
|
|
1321
1326
|
snapshotId,
|
|
1322
|
-
projectId: opts?.projectId ?? snapshot.projectId,
|
|
1327
|
+
projectId: opts?.projectId ?? (opts?.volumeId ? void 0 : snapshot.projectId),
|
|
1323
1328
|
region: snapshot.region,
|
|
1329
|
+
volumeId: opts?.volumeId,
|
|
1324
1330
|
timeoutMs: opts?.timeoutMs ?? DEFAULT_SANDBOX_TIMEOUT_MS
|
|
1325
1331
|
});
|
|
1326
1332
|
return new this({ ...opts, sandboxId: result.sandboxId ?? result.id });
|
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
|
-
|
|
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
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
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}`);
|
|
@@ -1259,15 +1262,18 @@ var Sandbox = class extends SandboxClient {
|
|
|
1259
1262
|
}
|
|
1260
1263
|
/**
|
|
1261
1264
|
* Start a new sandbox from a snapshot, in its region. `projectId` puts it in another project,
|
|
1262
|
-
* in any of your workspaces, as the snapshot's scope allows; default: the
|
|
1265
|
+
* in any of your workspaces, as the snapshot's scope allows; default: the volume's project, else
|
|
1266
|
+
* the snapshot's own. `volumeId` mounts that volume at `/workspace` (a Firecracker snapshot of a
|
|
1267
|
+
* sandbox that had no volume attached; the volume must be in the snapshot's region).
|
|
1263
1268
|
*/
|
|
1264
1269
|
static async restore(snapshotId, opts) {
|
|
1265
1270
|
const client = new PlatformClient(opts ?? {});
|
|
1266
1271
|
const snapshot = await this.getSnapshot(snapshotId, opts);
|
|
1267
1272
|
const result = await client.post("/api/sandboxes", {
|
|
1268
1273
|
snapshotId,
|
|
1269
|
-
projectId: opts?.projectId ?? snapshot.projectId,
|
|
1274
|
+
projectId: opts?.projectId ?? (opts?.volumeId ? void 0 : snapshot.projectId),
|
|
1270
1275
|
region: snapshot.region,
|
|
1276
|
+
volumeId: opts?.volumeId,
|
|
1271
1277
|
timeoutMs: opts?.timeoutMs ?? DEFAULT_SANDBOX_TIMEOUT_MS
|
|
1272
1278
|
});
|
|
1273
1279
|
return new this({ ...opts, sandboxId: result.sandboxId ?? result.id });
|
package/package.json
CHANGED