@blaxel/core 0.2.96-preview.204 → 0.2.96-preview.206

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.
Files changed (76) hide show
  1. package/README.md +37 -2
  2. package/dist/cjs/.tsbuildinfo +1 -1
  3. package/dist/cjs/common/pagination.js +92 -0
  4. package/dist/cjs/common/pagination.test.js +81 -0
  5. package/dist/cjs/common/settings.js +3 -3
  6. package/dist/cjs/common/settings.test.js +3 -3
  7. package/dist/cjs/drive/index.js +39 -4
  8. package/dist/cjs/index.js +1 -0
  9. package/dist/cjs/jobs/jobs.js +42 -10
  10. package/dist/cjs/sandbox/client/sdk.gen.js +2 -2
  11. package/dist/cjs/sandbox/preview.js +8 -3
  12. package/dist/cjs/sandbox/sandbox.js +40 -33
  13. package/dist/cjs/sandbox/schedule.js +51 -21
  14. package/dist/cjs/types/common/pagination.d.ts +35 -0
  15. package/dist/cjs/types/common/pagination.test.d.ts +1 -0
  16. package/dist/cjs/types/drive/index.d.ts +35 -5
  17. package/dist/cjs/types/index.d.ts +1 -0
  18. package/dist/cjs/types/jobs/jobs.d.ts +33 -3
  19. package/dist/cjs/types/sandbox/client/sdk.gen.d.ts +2 -2
  20. package/dist/cjs/types/sandbox/client/types.gen.d.ts +28 -1
  21. package/dist/cjs/types/sandbox/preview.d.ts +2 -2
  22. package/dist/cjs/types/sandbox/sandbox.d.ts +36 -3
  23. package/dist/cjs/types/sandbox/schedule.d.ts +35 -2
  24. package/dist/cjs/types/volume/index.d.ts +37 -4
  25. package/dist/cjs/volume/index.js +41 -4
  26. package/dist/cjs-browser/.tsbuildinfo +1 -1
  27. package/dist/cjs-browser/common/pagination.js +92 -0
  28. package/dist/cjs-browser/common/pagination.test.js +81 -0
  29. package/dist/cjs-browser/common/settings.js +3 -3
  30. package/dist/cjs-browser/common/settings.test.js +3 -3
  31. package/dist/cjs-browser/drive/index.js +39 -4
  32. package/dist/cjs-browser/index.js +1 -0
  33. package/dist/cjs-browser/jobs/jobs.js +42 -10
  34. package/dist/cjs-browser/sandbox/client/sdk.gen.js +2 -2
  35. package/dist/cjs-browser/sandbox/preview.js +8 -3
  36. package/dist/cjs-browser/sandbox/sandbox.js +40 -33
  37. package/dist/cjs-browser/sandbox/schedule.js +51 -21
  38. package/dist/cjs-browser/types/common/pagination.d.ts +35 -0
  39. package/dist/cjs-browser/types/common/pagination.test.d.ts +1 -0
  40. package/dist/cjs-browser/types/drive/index.d.ts +35 -5
  41. package/dist/cjs-browser/types/index.d.ts +1 -0
  42. package/dist/cjs-browser/types/jobs/jobs.d.ts +33 -3
  43. package/dist/cjs-browser/types/sandbox/client/sdk.gen.d.ts +2 -2
  44. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +28 -1
  45. package/dist/cjs-browser/types/sandbox/preview.d.ts +2 -2
  46. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +36 -3
  47. package/dist/cjs-browser/types/sandbox/schedule.d.ts +35 -2
  48. package/dist/cjs-browser/types/volume/index.d.ts +37 -4
  49. package/dist/cjs-browser/volume/index.js +41 -4
  50. package/dist/esm/.tsbuildinfo +1 -1
  51. package/dist/esm/common/pagination.js +88 -0
  52. package/dist/esm/common/pagination.test.js +79 -0
  53. package/dist/esm/common/settings.js +3 -3
  54. package/dist/esm/common/settings.test.js +3 -3
  55. package/dist/esm/drive/index.js +39 -4
  56. package/dist/esm/index.js +1 -0
  57. package/dist/esm/jobs/jobs.js +42 -10
  58. package/dist/esm/sandbox/client/sdk.gen.js +2 -2
  59. package/dist/esm/sandbox/preview.js +8 -3
  60. package/dist/esm/sandbox/sandbox.js +40 -33
  61. package/dist/esm/sandbox/schedule.js +51 -21
  62. package/dist/esm/volume/index.js +41 -4
  63. package/dist/esm-browser/.tsbuildinfo +1 -1
  64. package/dist/esm-browser/common/pagination.js +88 -0
  65. package/dist/esm-browser/common/pagination.test.js +79 -0
  66. package/dist/esm-browser/common/settings.js +3 -3
  67. package/dist/esm-browser/common/settings.test.js +3 -3
  68. package/dist/esm-browser/drive/index.js +39 -4
  69. package/dist/esm-browser/index.js +1 -0
  70. package/dist/esm-browser/jobs/jobs.js +42 -10
  71. package/dist/esm-browser/sandbox/client/sdk.gen.js +2 -2
  72. package/dist/esm-browser/sandbox/preview.js +8 -3
  73. package/dist/esm-browser/sandbox/sandbox.js +40 -33
  74. package/dist/esm-browser/sandbox/schedule.js +51 -21
  75. package/dist/esm-browser/volume/index.js +41 -4
  76. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrapListData = unwrapListData;
4
+ exports.createPaginatedList = createPaginatedList;
5
+ function unwrapListData(response) {
6
+ if (!response) {
7
+ return [];
8
+ }
9
+ if (Array.isArray(response)) {
10
+ return response;
11
+ }
12
+ return response.data ?? [];
13
+ }
14
+ function unwrapListMeta(response) {
15
+ if (!response || Array.isArray(response)) {
16
+ return { hasMore: false };
17
+ }
18
+ return response.meta ?? { hasMore: false };
19
+ }
20
+ async function createPaginatedList({ response, fetchPage, mapItem, query, seenCursors, }) {
21
+ const meta = unwrapListMeta(response);
22
+ const data = await Promise.all(unwrapListData(response).map(mapItem));
23
+ const cursors = new Set(seenCursors);
24
+ if (query?.cursor) {
25
+ cursors.add(query.cursor);
26
+ }
27
+ const list = {
28
+ data,
29
+ meta,
30
+ // Derive `hasMore` from cursor presence, not `meta.hasMore`: `nextPage()`
31
+ // can only advance when there is a `nextCursor`, so a consumer doing
32
+ // `if (page.hasMore) await page.nextPage()` must never see `hasMore: true`
33
+ // while `nextPage()` returns null. Keeping the two in sync prevents silent
34
+ // truncation if the API ever sends `hasMore: true` without a cursor.
35
+ get hasMore() {
36
+ return Boolean(list.nextCursor);
37
+ },
38
+ get nextCursor() {
39
+ return meta.nextCursor || undefined;
40
+ },
41
+ async nextPage() {
42
+ const cursor = list.nextCursor;
43
+ if (!cursor) {
44
+ return null;
45
+ }
46
+ if (cursors.has(cursor)) {
47
+ throw new Error("Pagination returned a repeated cursor");
48
+ }
49
+ const nextQuery = { ...(query ?? {}), cursor };
50
+ const nextSeenCursors = new Set(cursors);
51
+ nextSeenCursors.add(cursor);
52
+ return createPaginatedList({
53
+ response: await fetchPage(nextQuery),
54
+ fetchPage,
55
+ mapItem,
56
+ query: nextQuery,
57
+ seenCursors: nextSeenCursors,
58
+ });
59
+ },
60
+ async autoPagingEach(onItem) {
61
+ for await (const item of list) {
62
+ const shouldContinue = await onItem(item);
63
+ if (shouldContinue === false) {
64
+ return;
65
+ }
66
+ }
67
+ },
68
+ async autoPagingToArray(options) {
69
+ if (!options || !Number.isFinite(options.limit) || options.limit <= 0) {
70
+ throw new Error("autoPagingToArray requires a positive limit");
71
+ }
72
+ const items = [];
73
+ for await (const item of list) {
74
+ items.push(item);
75
+ if (items.length >= options.limit) {
76
+ return items;
77
+ }
78
+ }
79
+ return items;
80
+ },
81
+ async *[Symbol.asyncIterator]() {
82
+ let page = list;
83
+ while (page) {
84
+ for (const item of page.data) {
85
+ yield item;
86
+ }
87
+ page = await page.nextPage();
88
+ }
89
+ },
90
+ };
91
+ return list;
92
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const pagination_js_1 = require("./pagination.js");
5
+ (0, vitest_1.describe)("pagination helpers", () => {
6
+ (0, vitest_1.it)("unwraps legacy array and paginated list responses", () => {
7
+ (0, vitest_1.expect)((0, pagination_js_1.unwrapListData)([{ name: "legacy" }])).toEqual([{ name: "legacy" }]);
8
+ (0, vitest_1.expect)((0, pagination_js_1.unwrapListData)({
9
+ data: [{ name: "paginated" }],
10
+ meta: { hasMore: false },
11
+ })).toEqual([{ name: "paginated" }]);
12
+ });
13
+ (0, vitest_1.it)("returns page data and lets callers request the next page", async () => {
14
+ const cursors = [];
15
+ const fetchPage = async (query) => {
16
+ await Promise.resolve();
17
+ cursors.push(query?.cursor);
18
+ if (!query?.cursor) {
19
+ return {
20
+ data: ["first"],
21
+ meta: { hasMore: true, nextCursor: "next-page" },
22
+ };
23
+ }
24
+ return {
25
+ data: ["second"],
26
+ meta: { hasMore: false },
27
+ };
28
+ };
29
+ const page = await (0, pagination_js_1.createPaginatedList)({
30
+ response: await fetchPage(),
31
+ fetchPage,
32
+ mapItem: (item) => item.toUpperCase(),
33
+ });
34
+ (0, vitest_1.expect)(page.data).toEqual(["FIRST"]);
35
+ (0, vitest_1.expect)(page.hasMore).toBe(true);
36
+ (0, vitest_1.expect)(page.nextCursor).toBe("next-page");
37
+ const nextPage = await page.nextPage();
38
+ (0, vitest_1.expect)(nextPage?.data).toEqual(["SECOND"]);
39
+ (0, vitest_1.expect)(cursors).toEqual([undefined, "next-page"]);
40
+ });
41
+ (0, vitest_1.it)("keeps hasMore consistent with nextPage when the API omits a cursor", async () => {
42
+ const fetchPage = async () => {
43
+ await Promise.resolve();
44
+ // API reports more data but gives no cursor to fetch it.
45
+ return {
46
+ data: ["only"],
47
+ meta: { hasMore: true },
48
+ };
49
+ };
50
+ const page = await (0, pagination_js_1.createPaginatedList)({
51
+ response: await fetchPage(),
52
+ fetchPage,
53
+ mapItem: (item) => item,
54
+ });
55
+ // hasMore must reflect what nextPage() can actually deliver.
56
+ (0, vitest_1.expect)(page.hasMore).toBe(false);
57
+ await (0, vitest_1.expect)(page.nextPage()).resolves.toBeNull();
58
+ await (0, vitest_1.expect)(page.autoPagingToArray({ limit: 10 })).resolves.toEqual(["only"]);
59
+ });
60
+ (0, vitest_1.it)("supports auto paging with an explicit limit", async () => {
61
+ const fetchPage = async (query) => {
62
+ await Promise.resolve();
63
+ if (!query?.cursor) {
64
+ return {
65
+ data: ["first"],
66
+ meta: { hasMore: true, nextCursor: "next-page" },
67
+ };
68
+ }
69
+ return {
70
+ data: ["second"],
71
+ meta: { hasMore: false },
72
+ };
73
+ };
74
+ const page = await (0, pagination_js_1.createPaginatedList)({
75
+ response: await fetchPage(),
76
+ fetchPage,
77
+ mapItem: (item) => item,
78
+ });
79
+ await (0, vitest_1.expect)(page.autoPagingToArray({ limit: 2 })).resolves.toEqual(["first", "second"]);
80
+ });
81
+ });
@@ -28,10 +28,10 @@ function missingCredentialsMessage() {
28
28
  return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
29
29
  }
30
30
  // Build info - these placeholders are replaced at build time by build:replace-imports
31
- const BUILD_VERSION = "0.2.96-preview.204";
32
- const BUILD_COMMIT = "05c335edad327feae5ecd407b96b385a7662a701";
31
+ const BUILD_VERSION = "0.2.96-preview.206";
32
+ const BUILD_COMMIT = "f48d4c2e1e8d3bd3ee61decfacc3cd4f3ab0323d";
33
33
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
34
- const BLAXEL_API_VERSION = "2026-04-16";
34
+ const BLAXEL_API_VERSION = "2026-04-28";
35
35
  // Cache for config.yaml tracking value
36
36
  let configTrackingValue = null;
37
37
  let configTrackingLoaded = false;
@@ -43,10 +43,10 @@ const env_js_1 = require("./env.js");
43
43
  (0, vitest_1.afterEach)(() => {
44
44
  delete env_js_1.env.BL_API_VERSION;
45
45
  });
46
- (0, vitest_1.it)('defaults to 2026-04-16 when BL_API_VERSION is not set', async () => {
46
+ (0, vitest_1.it)('defaults to 2026-04-28 when BL_API_VERSION is not set', async () => {
47
47
  delete env_js_1.env.BL_API_VERSION;
48
48
  const { settings } = await Promise.resolve().then(() => __importStar(require('./settings.js')));
49
- (0, vitest_1.expect)(settings.apiVersion).toBe('2026-04-16');
49
+ (0, vitest_1.expect)(settings.apiVersion).toBe('2026-04-28');
50
50
  });
51
51
  (0, vitest_1.it)('headers include Blaxel-Version set to the default', async () => {
52
52
  delete env_js_1.env.BL_API_VERSION;
@@ -55,7 +55,7 @@ const env_js_1 = require("./env.js");
55
55
  const previous = settings.credentials;
56
56
  settings.credentials = new apikey_js_1.ApiKey({ apiKey: 'test-key', workspace: 'test-ws' });
57
57
  try {
58
- (0, vitest_1.expect)(settings.headers['Blaxel-Version']).toBe('2026-04-16');
58
+ (0, vitest_1.expect)(settings.headers['Blaxel-Version']).toBe('2026-04-28');
59
59
  }
60
60
  finally {
61
61
  settings.credentials = previous;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DriveInstance = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const index_js_1 = require("../client/index.js");
6
+ const pagination_js_1 = require("../common/pagination.js");
6
7
  const settings_js_1 = require("../common/settings.js");
7
8
  class DriveInstance {
8
9
  drive;
@@ -90,10 +91,44 @@ class DriveInstance {
90
91
  });
91
92
  return new DriveInstance(data);
92
93
  }
93
- static async list() {
94
- const { data } = await (0, index_js_1.listDrives)({ throwOnError: true });
95
- const items = Array.isArray(data) ? data : (data?.data ?? []);
96
- return items.map((drive) => new DriveInstance(drive));
94
+ /**
95
+ * List one page of drives.
96
+ *
97
+ * The returned page exposes `data` for the current page, `meta` for cursor
98
+ * metadata, and helpers to fetch more pages only when you need them.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const page = await DriveInstance.list({ limit: 50 });
103
+ *
104
+ * for (const drive of page.data) {
105
+ * console.log(drive.name);
106
+ * }
107
+ *
108
+ * const nextPage = await page.nextPage();
109
+ * ```
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const allDrives = await (await DriveInstance.list()).autoPagingToArray({
114
+ * limit: 1000,
115
+ * });
116
+ * ```
117
+ */
118
+ static async list(query) {
119
+ const fetchPage = async (pageQuery) => {
120
+ const { data } = await (0, index_js_1.listDrives)({
121
+ query: pageQuery,
122
+ throwOnError: true,
123
+ });
124
+ return data;
125
+ };
126
+ return (0, pagination_js_1.createPaginatedList)({
127
+ response: await fetchPage(query),
128
+ fetchPage,
129
+ mapItem: (drive) => new DriveInstance(drive),
130
+ query,
131
+ });
97
132
  }
98
133
  static async delete(driveName) {
99
134
  const { data } = await (0, index_js_1.deleteDrive)({
@@ -23,6 +23,7 @@ __exportStar(require("./common/node.js"), exports);
23
23
  __exportStar(require("./common/errors.js"), exports);
24
24
  __exportStar(require("./common/internal.js"), exports);
25
25
  __exportStar(require("./common/logger.js"), exports);
26
+ __exportStar(require("./common/pagination.js"), exports);
26
27
  __exportStar(require("./common/settings.js"), exports);
27
28
  __exportStar(require("./common/webhook.js"), exports);
28
29
  __exportStar(require("./drive/index.js"), exports);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blJob = void 0;
4
4
  const index_js_1 = require("../client/index.js");
5
5
  const logger_js_1 = require("../common/logger.js");
6
+ const pagination_js_1 = require("../common/pagination.js");
6
7
  const settings_js_1 = require("../common/settings.js");
7
8
  const telemetry_js_1 = require("../telemetry/telemetry.js");
8
9
  class BlJob {
@@ -78,19 +79,50 @@ class BlJob {
78
79
  return data;
79
80
  }
80
81
  /**
81
- * List all executions for this job
82
+ * List one page of executions for this job.
83
+ *
84
+ * The returned page exposes `data` for the current page, `meta` for cursor
85
+ * metadata, and helpers to fetch more pages only when you need them.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const job = blJob("daily-import");
90
+ * const page = await job.listExecutions({ limit: 50 });
91
+ *
92
+ * for (const execution of page.data) {
93
+ * console.log(execution.status);
94
+ * }
95
+ *
96
+ * const nextPage = await page.nextPage();
97
+ * ```
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const job = blJob("daily-import");
102
+ * const executions = await (await job.listExecutions()).autoPagingToArray({
103
+ * limit: 1000,
104
+ * });
105
+ * ```
82
106
  */
83
- async listExecutions() {
107
+ async listExecutions(query) {
84
108
  logger_js_1.logger.debug(`Listing executions for job: ${this.jobName}`);
85
- const { data } = await (0, index_js_1.listJobExecutions)({
86
- path: {
87
- jobId: this.jobName,
88
- },
89
- headers: settings_js_1.settings.headers,
90
- throwOnError: true,
109
+ const fetchPage = async (pageQuery) => {
110
+ const { data } = await (0, index_js_1.listJobExecutions)({
111
+ path: {
112
+ jobId: this.jobName,
113
+ },
114
+ query: pageQuery,
115
+ headers: settings_js_1.settings.headers,
116
+ throwOnError: true,
117
+ });
118
+ return data;
119
+ };
120
+ return (0, pagination_js_1.createPaginatedList)({
121
+ response: await fetchPage(query),
122
+ fetchPage,
123
+ mapItem: (execution) => execution,
124
+ query,
91
125
  });
92
- const items = Array.isArray(data) ? data : (data?.data ?? []);
93
- return items;
94
126
  }
95
127
  /**
96
128
  * Get the status of a specific execution
@@ -92,7 +92,7 @@ const getDrivesMount = (options) => {
92
92
  exports.getDrivesMount = getDrivesMount;
93
93
  /**
94
94
  * Attach a drive to a local path
95
- * Mounts an agent drive using the blfs binary to a local path, optionally mounting a subpath within the drive
95
+ * Mounts an agent drive using the blfs binary to a local path, optionally mounting a subpath within the drive. Supports optional UID/GID mapping to remap file ownership between the local sandbox and the filer (always mapped to filer UID/GID 0). Mapping values can be set per-request via uidMap/gidMap fields, or globally via BLFS_UID_MAP/BLFS_GID_MAP environment variables (request values take precedence).
96
96
  */
97
97
  const postDrivesMount = (options) => {
98
98
  return (options.client ?? client_gen_1.client).post({
@@ -643,7 +643,7 @@ exports.getProcessByIdentifierLogsStream = getProcessByIdentifierLogsStream;
643
643
  * Triggers an upgrade of the sandbox-api process. Returns 200 immediately before upgrading.
644
644
  * The upgrade will: download the specified binary from GitHub releases, validate it, and restart.
645
645
  * All running processes will be preserved across the upgrade.
646
- * Available versions: "develop" (default), "main", "latest", or specific tag like "v1.0.0"
646
+ * Available versions: "latest" (default, most recent release), "develop", "main", or specific tag like "v1.0.0"
647
647
  * You can also specify a custom baseUrl for forks (defaults to https://github.com/blaxel-ai/sandbox/releases)
648
648
  */
649
649
  const postUpgrade = (options) => {
@@ -105,24 +105,29 @@ class SandboxPreviews {
105
105
  });
106
106
  return data.map((preview) => new SandboxPreview(preview));
107
107
  }
108
- async create(preview) {
108
+ async create(preview, force) {
109
+ const query = {};
110
+ if (force) {
111
+ query['force'] = 'true';
112
+ }
109
113
  const { data } = await (0, index_js_1.createSandboxPreview)({
110
114
  path: {
111
115
  sandboxName: this.sandboxName,
112
116
  },
117
+ query,
113
118
  body: preview,
114
119
  throwOnError: true,
115
120
  });
116
121
  return new SandboxPreview(data);
117
122
  }
118
- async createIfNotExists(preview) {
123
+ async createIfNotExists(preview, force) {
119
124
  try {
120
125
  const previewInstance = await this.get(preview.metadata.name);
121
126
  return previewInstance;
122
127
  }
123
128
  catch (e) {
124
129
  if (typeof e === "object" && e !== null && "code" in e && e.code === 404) {
125
- return this.create(preview);
130
+ return this.create(preview, force);
126
131
  }
127
132
  throw e;
128
133
  }
@@ -37,6 +37,7 @@ exports.SandboxInstance = void 0;
37
37
  const uuid_1 = require("uuid");
38
38
  const index_js_1 = require("../client/index.js");
39
39
  const logger_js_1 = require("../common/logger.js");
40
+ const pagination_js_1 = require("../common/pagination.js");
40
41
  const settings_js_1 = require("../common/settings.js");
41
42
  const index_js_2 = require("./codegen/index.js");
42
43
  const index_js_3 = require("./drive/index.js");
@@ -283,40 +284,46 @@ class SandboxInstance {
283
284
  const instance = new SandboxInstance(data);
284
285
  return SandboxInstance.attachH2Session(instance);
285
286
  }
286
- static async list({ externalId } = {}) {
287
- const { data: raw } = await (0, index_js_1.listSandboxes)({
288
- query: externalId ? { externalId } : undefined,
289
- throwOnError: true,
287
+ /**
288
+ * List one page of sandboxes.
289
+ *
290
+ * The returned page exposes `data` for the current page, `meta` for cursor
291
+ * metadata, and helpers to fetch more pages only when you need them.
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * const page = await SandboxInstance.list({ limit: 50 });
296
+ *
297
+ * for (const sandbox of page.data) {
298
+ * console.log(sandbox.metadata.name);
299
+ * }
300
+ *
301
+ * const nextPage = await page.nextPage();
302
+ * ```
303
+ *
304
+ * @example
305
+ * ```ts
306
+ * const page = await SandboxInstance.list({ limit: 100 });
307
+ *
308
+ * for await (const sandbox of page) {
309
+ * console.log(sandbox.metadata.name);
310
+ * }
311
+ * ```
312
+ */
313
+ static async list(query) {
314
+ const fetchPage = async (pageQuery) => {
315
+ const { data } = await (0, index_js_1.listSandboxes)({
316
+ query: pageQuery,
317
+ throwOnError: true,
318
+ });
319
+ return data;
320
+ };
321
+ return (0, pagination_js_1.createPaginatedList)({
322
+ response: await fetchPage(query),
323
+ fetchPage,
324
+ mapItem: (sandbox) => SandboxInstance.attachH2Session(new SandboxInstance(sandbox)),
325
+ query,
290
326
  });
291
- const items = (Array.isArray(raw) ? raw : (raw?.data ?? []));
292
- const instances = items.map((sb) => new SandboxInstance(sb));
293
- if (!settings_js_1.settings.disableH2) {
294
- const { h2Pool } = await Promise.resolve().then(() => __importStar(require("../common/h2pool.js")));
295
- const uniqueDomains = [
296
- ...new Set(instances
297
- .map((i) => SandboxInstance.edgeDomainForRegion(i.spec?.region))
298
- .filter((d) => d !== null)),
299
- ];
300
- const sessionByDomain = new Map();
301
- await Promise.all(uniqueDomains.map(async (domain) => {
302
- try {
303
- sessionByDomain.set(domain, await h2Pool.get(domain));
304
- }
305
- catch {
306
- sessionByDomain.set(domain, null);
307
- }
308
- }));
309
- for (const instance of instances) {
310
- const domain = SandboxInstance.edgeDomainForRegion(instance.spec?.region);
311
- if (domain) {
312
- const session = sessionByDomain.get(domain) ?? null;
313
- instance.h2Session = session;
314
- instance.sandbox.h2Session = session;
315
- instance.sandbox.h2Domain = domain;
316
- }
317
- }
318
- }
319
- return instances;
320
327
  }
321
328
  static async delete(sandboxName) {
322
329
  const { data } = await (0, index_js_1.deleteSandbox)({
@@ -2,15 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SandboxSchedules = void 0;
4
4
  const index_js_1 = require("../client/index.js");
5
- // Schedule list endpoints return a bare array on older API versions and a
6
- // cursor-paginated `{ data, meta }` envelope starting on Blaxel-Version
7
- // 2026-04-28. Handle both so the wrapper works regardless of the SDK's default
8
- // version.
9
- function unwrapPage(data) {
10
- if (Array.isArray(data))
11
- return data;
12
- return data?.data ?? [];
13
- }
5
+ const pagination_js_1 = require("../common/pagination.js");
14
6
  // SandboxSchedules manages a sandbox's schedules. A schedule entry is a flat
15
7
  // record (id/type/value/input) with no sub-resource of its own, so methods
16
8
  // return the raw SandboxScheduleEntry rather than a wrapper class (the generated
@@ -23,15 +15,38 @@ class SandboxSchedules {
23
15
  get sandboxName() {
24
16
  return this.sandbox.metadata.name;
25
17
  }
18
+ /**
19
+ * List one page of the sandbox's schedules.
20
+ *
21
+ * The returned page exposes `data` for the current page, `meta` for cursor
22
+ * metadata, and `nextPage()` / `autoPagingEach()` / `autoPagingToArray()`
23
+ * helpers. Iterate it directly with `for await` to walk every page.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const page = await sandbox.schedules.list({ limit: 50 });
28
+ * for await (const schedule of page) {
29
+ * console.log(schedule.id);
30
+ * }
31
+ * ```
32
+ */
26
33
  async list(options = {}) {
27
- const { data } = await (0, index_js_1.listSandboxSchedules)({
28
- path: {
29
- sandboxName: this.sandboxName,
30
- },
34
+ const fetchPage = async (query) => {
35
+ const { data } = await (0, index_js_1.listSandboxSchedules)({
36
+ path: {
37
+ sandboxName: this.sandboxName,
38
+ },
39
+ query,
40
+ throwOnError: true,
41
+ });
42
+ return data;
43
+ };
44
+ return (0, pagination_js_1.createPaginatedList)({
45
+ response: await fetchPage(options),
46
+ fetchPage,
47
+ mapItem: (entry) => entry,
31
48
  query: options,
32
- throwOnError: true,
33
49
  });
34
- return unwrapPage(data);
35
50
  }
36
51
  async create(schedule) {
37
52
  const { data } = await (0, index_js_1.createSandboxSchedule)({
@@ -77,15 +92,30 @@ class SandboxSchedules {
77
92
  // List the execution history of every schedule on the sandbox, newest first.
78
93
  // Executions are sandbox-scoped, not per-schedule; filter by `scheduleId` on
79
94
  // the returned records to isolate a single schedule's runs.
95
+ /**
96
+ * List one page of schedule executions, newest first.
97
+ *
98
+ * The returned page exposes `data`, `meta`, and `nextPage()` /
99
+ * `autoPagingEach()` / `autoPagingToArray()` helpers. Iterate it directly
100
+ * with `for await` to walk every page.
101
+ */
80
102
  async executions(options = {}) {
81
- const { data } = await (0, index_js_1.listSandboxScheduleExecutions)({
82
- path: {
83
- sandboxName: this.sandboxName,
84
- },
103
+ const fetchPage = async (query) => {
104
+ const { data } = await (0, index_js_1.listSandboxScheduleExecutions)({
105
+ path: {
106
+ sandboxName: this.sandboxName,
107
+ },
108
+ query,
109
+ throwOnError: true,
110
+ });
111
+ return data;
112
+ };
113
+ return (0, pagination_js_1.createPaginatedList)({
114
+ response: await fetchPage(options),
115
+ fetchPage,
116
+ mapItem: (execution) => execution,
85
117
  query: options,
86
- throwOnError: true,
87
118
  });
88
- return unwrapPage(data);
89
119
  }
90
120
  }
91
121
  exports.SandboxSchedules = SandboxSchedules;
@@ -0,0 +1,35 @@
1
+ export type PaginatedListMeta = {
2
+ hasMore?: boolean;
3
+ nextCursor?: string;
4
+ total?: number;
5
+ };
6
+ export type CursorPaginationQuery = {
7
+ cursor?: string;
8
+ };
9
+ export type ListResponse<T> = T[] | {
10
+ data?: T[] | null;
11
+ meta?: PaginatedListMeta | null;
12
+ } | null | undefined;
13
+ export type AutoPagingEachCallback<T> = (item: T) => boolean | void | Promise<boolean | void>;
14
+ export type AutoPagingToArrayOptions = {
15
+ limit: number;
16
+ };
17
+ export type PaginatedList<T, TQuery extends CursorPaginationQuery = CursorPaginationQuery> = AsyncIterable<T> & {
18
+ data: T[];
19
+ meta: PaginatedListMeta;
20
+ hasMore: boolean;
21
+ nextCursor?: string;
22
+ nextPage(): Promise<PaginatedList<T, TQuery> | null>;
23
+ autoPagingEach(onItem: AutoPagingEachCallback<T>): Promise<void>;
24
+ autoPagingToArray(options: AutoPagingToArrayOptions): Promise<T[]>;
25
+ };
26
+ type CreatePaginatedListOptions<TRaw, TItem, TQuery extends CursorPaginationQuery> = {
27
+ response: ListResponse<TRaw>;
28
+ fetchPage: (query?: TQuery) => Promise<ListResponse<TRaw>>;
29
+ mapItem: (item: TRaw) => TItem | Promise<TItem>;
30
+ query?: TQuery;
31
+ seenCursors?: Set<string>;
32
+ };
33
+ export declare function unwrapListData<T>(response: ListResponse<T>): T[];
34
+ export declare function createPaginatedList<TRaw, TItem, TQuery extends CursorPaginationQuery = CursorPaginationQuery>({ response, fetchPage, mapItem, query, seenCursors, }: CreatePaginatedListOptions<TRaw, TItem, TQuery>): Promise<PaginatedList<TItem, TQuery>>;
35
+ export {};
@@ -0,0 +1 @@
1
+ export {};