disk 0.8.19 → 0.8.21

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/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as listDisks, i as deleteApiKey, n as createApiKey, o as getDisk, r as createDisk, s as listApiKeys, t as configure, y as ArchilApiError } from "./src--b7LHPh_.mjs";
2
+ import { c as listDisks, i as deleteApiKey, n as createApiKey, o as getDisk, r as createDisk, s as listApiKeys, t as configure, y as ArchilApiError } from "./src-CrK7pSLW.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { Command, Option } from "commander";
5
5
  //#region bin/cli.ts
@@ -25,7 +25,7 @@ interface FileSystem {
25
25
  /** Read an object's full contents. Throws `ArchilS3Error` (404) if absent. */
26
26
  getObject(key: string): Promise<Uint8Array>;
27
27
  /** Create or overwrite an object. */
28
- putObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
28
+ putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
29
29
  /** Delete an object (idempotent). */
30
30
  deleteObject(key: string): Promise<void>;
31
31
  /** List objects and common (directory) prefixes under a key prefix. */
@@ -305,7 +305,20 @@ interface DeleteObjectsResult {
305
305
  /** Per-key failures; empty when every key was deleted. */
306
306
  errors: DeleteObjectsError[];
307
307
  }
308
- interface PutObjectOptions {
308
+ /**
309
+ * POSIX attributes to set on a newly created object, sent to the S3 gateway as
310
+ * `x-archil-*` headers. All optional — anything omitted falls back to the
311
+ * server-side defaults (currently `root:root`, mode `0644`).
312
+ */
313
+ interface PosixCreateAttrs {
314
+ /** POSIX mode bits for the created file, e.g. `0o644`. Sent in octal. */
315
+ mode?: number;
316
+ /** Owning user id, e.g. `1000`. */
317
+ uid?: number;
318
+ /** Owning group id, e.g. `1000`. */
319
+ gid?: number;
320
+ }
321
+ interface PutObjectOptions extends PosixCreateAttrs {
309
322
  /** MIME type to store the object with. Default "application/octet-stream". */
310
323
  contentType?: string;
311
324
  /**
@@ -323,6 +336,13 @@ interface PutObjectOptions {
323
336
  /** Max parts uploaded in parallel on the multipart path. Default 4. */
324
337
  concurrency?: number;
325
338
  }
339
+ interface AppendObjectOptions extends PosixCreateAttrs {
340
+ /**
341
+ * MIME type, applied only when the object is newly created. Default
342
+ * "application/octet-stream".
343
+ */
344
+ contentType?: string;
345
+ }
326
346
  /**
327
347
  * The S3 transport function {@link DiskMultipart} uses, supplied by the owning
328
348
  * {@link Disk} so the namespace shares the disk's credential and endpoint.
@@ -333,6 +353,7 @@ type S3RequestFn = (method: "GET" | "PUT" | "DELETE" | "HEAD" | "POST", key: str
333
353
  contentType?: string;
334
354
  query?: Record<string, string | number>;
335
355
  retry?: boolean;
356
+ extraHeaders?: Record<string, string>;
336
357
  }) => Promise<{
337
358
  ok: boolean;
338
359
  status: number;
@@ -439,12 +460,16 @@ declare class Disk implements FileSystem {
439
460
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
440
461
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
441
462
  *
463
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
464
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
465
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
466
+ *
442
467
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
443
468
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
444
469
  * @param options Either a content-type string, or {@link PutObjectOptions}
445
470
  * (`contentType`, `multipartThreshold`, `partSize`,
446
- * `concurrency`). Content type defaults to
447
- * "application/octet-stream".
471
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
472
+ * to "application/octet-stream".
448
473
  */
449
474
  putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
450
475
  /**
@@ -468,11 +493,18 @@ declare class Disk implements FileSystem {
468
493
  * would duplicate the bytes. On a transient failure, re-append yourself only
469
494
  * after confirming the object's size.
470
495
  *
471
- * @param key Path on the disk (e.g. "logs/app.log")
472
- * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
473
- * @param contentType MIME type, applied only when the object is newly created.
496
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
497
+ * POSIX attributes of the newly created file (same headers as
498
+ * {@link putObject}); they have no effect on an append to an existing object.
499
+ *
500
+ * @param key Path on the disk (e.g. "logs/app.log")
501
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
502
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
503
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
504
+ * to "application/octet-stream" and applies only when the
505
+ * object is newly created.
474
506
  */
475
- appendObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
507
+ appendObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | AppendObjectOptions): Promise<PutObjectResult>;
476
508
  /**
477
509
  * Delete an object from the disk via the S3-compatible DeleteObject API.
478
510
  * Idempotent: deleting a key that doesn't exist resolves successfully, per
@@ -572,8 +604,10 @@ declare class DiskMultipart {
572
604
  *
573
605
  * @param key Path on the disk the finished object will live at.
574
606
  * @param contentType MIME type to store the object with.
607
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
608
+ * object (see {@link PosixCreateAttrs}).
575
609
  */
576
- create(key: string, contentType?: string): Promise<MultipartUpload>;
610
+ create(key: string, contentType?: string, attrs?: PosixCreateAttrs): Promise<MultipartUpload>;
577
611
  /**
578
612
  * Upload one part (UploadPart) and return its entity tag, which you must
579
613
  * collect (with its part number) and pass to {@link complete}. Every part
@@ -638,4 +672,4 @@ declare class DiskMultipart {
638
672
  */
639
673
  declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
640
674
  //#endregion
641
- export { AwsStsUser as A, ExecRequest as B, S3Object as C, effectiveUploadPartSize as D, UploadPart as E, DiskMetrics as F, MountConfigResponse as G, GrepMatch as H, DiskResponse as I, S3CompatibleMount as J, MountResponse as K, DiskStatus as L, ConnectedClient as M, CreateApiTokenRequest as N, ApiTokenResponse as O, CreateDiskRequest as P, ApiClient as Q, DiskUser as R, PutObjectResult as S, ShareUrlResult as T, GrepStoppedReason as U, GCSMount as V, MountConfig as W, TokenUser as X, S3Mount as Y, FileSystem as Z, MultipartUploadSummary as _, Disk as a, PartListing as b, GrepOptions as c, ListObjectsOptions as d, ListObjectsResult as f, MultipartUploadListing as g, MultipartUpload as h, DeleteObjectsResult as i, AzureBlobMount as j, AuthorizedUser as k, GrepResult as l, MountOptions as m, DeleteObjectsError as n, DiskMultipart as o, ListPartsOptions as p, R2Mount as q, DeleteObjectsOptions as r, ExecResult as s, CompletedMultipartUpload as t, ListMultipartUploadsOptions as u, ObjectMetadata as v, ShareUrlOptions as w, PutObjectOptions as x, PartInfo as y, ExecDiskResult as z };
675
+ export { FileSystem as $, ApiTokenResponse as A, DiskUser as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepStoppedReason as G, ExecRequest as H, CreateDiskRequest as I, MountResponse as J, MountConfig as K, DiskMetrics as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, TokenUser as Q, DiskResponse as R, PosixCreateAttrs as S, S3Object as T, GCSMount as U, ExecDiskResult as V, GrepMatch as W, S3CompatibleMount as X, R2Mount as Y, S3Mount as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, ApiClient as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, Disk as o, ListObjectsResult as p, MountConfigResponse as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskStatus as z };
@@ -25,7 +25,7 @@ interface FileSystem {
25
25
  /** Read an object's full contents. Throws `ArchilS3Error` (404) if absent. */
26
26
  getObject(key: string): Promise<Uint8Array>;
27
27
  /** Create or overwrite an object. */
28
- putObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
28
+ putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
29
29
  /** Delete an object (idempotent). */
30
30
  deleteObject(key: string): Promise<void>;
31
31
  /** List objects and common (directory) prefixes under a key prefix. */
@@ -305,7 +305,20 @@ interface DeleteObjectsResult {
305
305
  /** Per-key failures; empty when every key was deleted. */
306
306
  errors: DeleteObjectsError[];
307
307
  }
308
- interface PutObjectOptions {
308
+ /**
309
+ * POSIX attributes to set on a newly created object, sent to the S3 gateway as
310
+ * `x-archil-*` headers. All optional — anything omitted falls back to the
311
+ * server-side defaults (currently `root:root`, mode `0644`).
312
+ */
313
+ interface PosixCreateAttrs {
314
+ /** POSIX mode bits for the created file, e.g. `0o644`. Sent in octal. */
315
+ mode?: number;
316
+ /** Owning user id, e.g. `1000`. */
317
+ uid?: number;
318
+ /** Owning group id, e.g. `1000`. */
319
+ gid?: number;
320
+ }
321
+ interface PutObjectOptions extends PosixCreateAttrs {
309
322
  /** MIME type to store the object with. Default "application/octet-stream". */
310
323
  contentType?: string;
311
324
  /**
@@ -323,6 +336,13 @@ interface PutObjectOptions {
323
336
  /** Max parts uploaded in parallel on the multipart path. Default 4. */
324
337
  concurrency?: number;
325
338
  }
339
+ interface AppendObjectOptions extends PosixCreateAttrs {
340
+ /**
341
+ * MIME type, applied only when the object is newly created. Default
342
+ * "application/octet-stream".
343
+ */
344
+ contentType?: string;
345
+ }
326
346
  /**
327
347
  * The S3 transport function {@link DiskMultipart} uses, supplied by the owning
328
348
  * {@link Disk} so the namespace shares the disk's credential and endpoint.
@@ -333,6 +353,7 @@ type S3RequestFn = (method: "GET" | "PUT" | "DELETE" | "HEAD" | "POST", key: str
333
353
  contentType?: string;
334
354
  query?: Record<string, string | number>;
335
355
  retry?: boolean;
356
+ extraHeaders?: Record<string, string>;
336
357
  }) => Promise<{
337
358
  ok: boolean;
338
359
  status: number;
@@ -439,12 +460,16 @@ declare class Disk implements FileSystem {
439
460
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
440
461
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
441
462
  *
463
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
464
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
465
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
466
+ *
442
467
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
443
468
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
444
469
  * @param options Either a content-type string, or {@link PutObjectOptions}
445
470
  * (`contentType`, `multipartThreshold`, `partSize`,
446
- * `concurrency`). Content type defaults to
447
- * "application/octet-stream".
471
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
472
+ * to "application/octet-stream".
448
473
  */
449
474
  putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
450
475
  /**
@@ -468,11 +493,18 @@ declare class Disk implements FileSystem {
468
493
  * would duplicate the bytes. On a transient failure, re-append yourself only
469
494
  * after confirming the object's size.
470
495
  *
471
- * @param key Path on the disk (e.g. "logs/app.log")
472
- * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
473
- * @param contentType MIME type, applied only when the object is newly created.
496
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
497
+ * POSIX attributes of the newly created file (same headers as
498
+ * {@link putObject}); they have no effect on an append to an existing object.
499
+ *
500
+ * @param key Path on the disk (e.g. "logs/app.log")
501
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
502
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
503
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
504
+ * to "application/octet-stream" and applies only when the
505
+ * object is newly created.
474
506
  */
475
- appendObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
507
+ appendObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | AppendObjectOptions): Promise<PutObjectResult>;
476
508
  /**
477
509
  * Delete an object from the disk via the S3-compatible DeleteObject API.
478
510
  * Idempotent: deleting a key that doesn't exist resolves successfully, per
@@ -572,8 +604,10 @@ declare class DiskMultipart {
572
604
  *
573
605
  * @param key Path on the disk the finished object will live at.
574
606
  * @param contentType MIME type to store the object with.
607
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
608
+ * object (see {@link PosixCreateAttrs}).
575
609
  */
576
- create(key: string, contentType?: string): Promise<MultipartUpload>;
610
+ create(key: string, contentType?: string, attrs?: PosixCreateAttrs): Promise<MultipartUpload>;
577
611
  /**
578
612
  * Upload one part (UploadPart) and return its entity tag, which you must
579
613
  * collect (with its part number) and pass to {@link complete}. Every part
@@ -638,4 +672,4 @@ declare class DiskMultipart {
638
672
  */
639
673
  declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
640
674
  //#endregion
641
- export { AwsStsUser as A, ExecRequest as B, S3Object as C, effectiveUploadPartSize as D, UploadPart as E, DiskMetrics as F, MountConfigResponse as G, GrepMatch as H, DiskResponse as I, S3CompatibleMount as J, MountResponse as K, DiskStatus as L, ConnectedClient as M, CreateApiTokenRequest as N, ApiTokenResponse as O, CreateDiskRequest as P, ApiClient as Q, DiskUser as R, PutObjectResult as S, ShareUrlResult as T, GrepStoppedReason as U, GCSMount as V, MountConfig as W, TokenUser as X, S3Mount as Y, FileSystem as Z, MultipartUploadSummary as _, Disk as a, PartListing as b, GrepOptions as c, ListObjectsOptions as d, ListObjectsResult as f, MultipartUploadListing as g, MultipartUpload as h, DeleteObjectsResult as i, AzureBlobMount as j, AuthorizedUser as k, GrepResult as l, MountOptions as m, DeleteObjectsError as n, DiskMultipart as o, ListPartsOptions as p, R2Mount as q, DeleteObjectsOptions as r, ExecResult as s, CompletedMultipartUpload as t, ListMultipartUploadsOptions as u, ObjectMetadata as v, ShareUrlOptions as w, PutObjectOptions as x, PartInfo as y, ExecDiskResult as z };
675
+ export { FileSystem as $, ApiTokenResponse as A, DiskUser as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepStoppedReason as G, ExecRequest as H, CreateDiskRequest as I, MountResponse as J, MountConfig as K, DiskMetrics as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, TokenUser as Q, DiskResponse as R, PosixCreateAttrs as S, S3Object as T, GCSMount as U, ExecDiskResult as V, GrepMatch as W, S3CompatibleMount as X, R2Mount as Y, S3Mount as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, ApiClient as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, Disk as o, ListObjectsResult as p, MountConfigResponse as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskStatus as z };
package/dist/index.cjs CHANGED
@@ -134,7 +134,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
134
134
  }
135
135
  //#endregion
136
136
  //#region src/version.ts
137
- const VERSION = "0.8.19";
137
+ const VERSION = "0.8.21";
138
138
  const USER_AGENT = `archil-js/${VERSION}`;
139
139
  //#endregion
140
140
  //#region src/client.ts
@@ -153,10 +153,21 @@ function createApiClient(opts) {
153
153
  * Unwrap the API envelope: return data on success, throw ArchilApiError on failure.
154
154
  */
155
155
  async function unwrap(promise) {
156
+ return (await unwrapPage(promise)).data;
157
+ }
158
+ /**
159
+ * Unwrap a paginated list envelope: like {@link unwrap}, but also surface the
160
+ * envelope's `nextCursor` (undefined on the last page or from a server that
161
+ * doesn't paginate).
162
+ */
163
+ async function unwrapPage(promise) {
156
164
  const { data: body, error, response } = await promise;
157
165
  if (error || !body) throw new ArchilApiError(error?.error ?? `API request failed with status ${response.status}`, response.status);
158
166
  if (!body.success) throw new ArchilApiError(body.error ?? "Unknown API error", response.status);
159
- return body.data;
167
+ return {
168
+ data: body.data,
169
+ nextCursor: body.nextCursor
170
+ };
160
171
  }
161
172
  /**
162
173
  * Unwrap an API response that has no data payload (e.g., delete operations).
@@ -383,12 +394,16 @@ var Disk = class {
383
394
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
384
395
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
385
396
  *
397
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
398
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
399
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
400
+ *
386
401
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
387
402
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
388
403
  * @param options Either a content-type string, or {@link PutObjectOptions}
389
404
  * (`contentType`, `multipartThreshold`, `partSize`,
390
- * `concurrency`). Content type defaults to
391
- * "application/octet-stream".
405
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
406
+ * to "application/octet-stream".
392
407
  */
393
408
  async putObject(key, body, options) {
394
409
  const opts = typeof options === "string" ? { contentType: options } : options ?? {};
@@ -399,22 +414,23 @@ var Disk = class {
399
414
  if (bytes.length <= threshold) {
400
415
  const resp = await this._s3Request("PUT", key, {
401
416
  body,
402
- contentType
417
+ contentType,
418
+ extraHeaders: posixCreateHeaders(opts)
403
419
  });
404
420
  if (!resp.ok) throw parseS3Error("PutObject", resp.status, resp.statusText, decodeText(resp.body));
405
421
  return { etag: resp.headers.get("etag") ?? void 0 };
406
422
  }
407
- return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY));
423
+ return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY), opts);
408
424
  }
409
425
  /**
410
426
  * Upload a large body through the multipart lifecycle: split into `partSize`
411
427
  * parts, upload them with bounded concurrency, then complete — aborting the
412
428
  * upload if any part fails so nothing is left half-staged. @internal
413
429
  */
414
- async _putMultipart(key, bytes, contentType, partSize, concurrency) {
430
+ async _putMultipart(key, bytes, contentType, partSize, concurrency, attrs = {}) {
415
431
  const effectivePartSize = effectiveUploadPartSize(bytes.length, partSize);
416
432
  const mp = this.multipart;
417
- const upload = await mp.create(key, contentType);
433
+ const upload = await mp.create(key, contentType, attrs);
418
434
  try {
419
435
  const partCount = Math.ceil(bytes.length / effectivePartSize);
420
436
  const parts = new Array(partCount);
@@ -450,16 +466,25 @@ var Disk = class {
450
466
  * would duplicate the bytes. On a transient failure, re-append yourself only
451
467
  * after confirming the object's size.
452
468
  *
453
- * @param key Path on the disk (e.g. "logs/app.log")
454
- * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
455
- * @param contentType MIME type, applied only when the object is newly created.
469
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
470
+ * POSIX attributes of the newly created file (same headers as
471
+ * {@link putObject}); they have no effect on an append to an existing object.
472
+ *
473
+ * @param key Path on the disk (e.g. "logs/app.log")
474
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
475
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
476
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
477
+ * to "application/octet-stream" and applies only when the
478
+ * object is newly created.
456
479
  */
457
- async appendObject(key, body, contentType = "application/octet-stream") {
480
+ async appendObject(key, body, options) {
481
+ const opts = typeof options === "string" ? { contentType: options } : options ?? {};
458
482
  const resp = await this._s3Request("PUT", key, {
459
483
  body,
460
- contentType,
484
+ contentType: opts.contentType ?? "application/octet-stream",
461
485
  query: { append: "true" },
462
- retry: false
486
+ retry: false,
487
+ extraHeaders: posixCreateHeaders(opts)
463
488
  });
464
489
  if (!resp.ok) throw parseS3Error("AppendObject", resp.status, resp.statusText, decodeText(resp.body));
465
490
  return { etag: resp.headers.get("etag") ?? void 0 };
@@ -625,7 +650,10 @@ var Disk = class {
625
650
  body: opts.body,
626
651
  bodySerializer: (b) => b
627
652
  } : {},
628
- ...opts.contentType ? { headers: { "Content-Type": opts.contentType } } : {}
653
+ ...opts.contentType || opts.extraHeaders ? { headers: {
654
+ ...opts.contentType ? { "Content-Type": opts.contentType } : {},
655
+ ...opts.extraHeaders
656
+ } } : {}
629
657
  };
630
658
  const hasBody = method === "GET" || method === "POST";
631
659
  const maxRetries = opts.retry === false ? 0 : MAX_S3_RETRIES;
@@ -711,11 +739,14 @@ var DiskMultipart = class {
711
739
  *
712
740
  * @param key Path on the disk the finished object will live at.
713
741
  * @param contentType MIME type to store the object with.
742
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
743
+ * object (see {@link PosixCreateAttrs}).
714
744
  */
715
- async create(key, contentType) {
745
+ async create(key, contentType, attrs = {}) {
716
746
  const resp = await this.s3Request("POST", key, {
717
747
  query: { uploads: "" },
718
- contentType
748
+ contentType,
749
+ extraHeaders: posixCreateHeaders(attrs)
719
750
  });
720
751
  if (!resp.ok) throw parseS3Error("CreateMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
721
752
  const root = parseXml(decodeText(resp.body)).InitiateMultipartUploadResult ?? {};
@@ -836,6 +867,25 @@ var DiskMultipart = class {
836
867
  return parseListMultipartUploadsResult(decodeText(resp.body));
837
868
  }
838
869
  };
870
+ /**
871
+ * Headers the S3 gateway accepts to set POSIX mode/owner on newly created
872
+ * objects (see fshandler `x-archil-*` PutObject attrs).
873
+ */
874
+ const ARCHIL_MODE_HEADER = "x-archil-mode";
875
+ const ARCHIL_UID_HEADER = "x-archil-uid";
876
+ const ARCHIL_GID_HEADER = "x-archil-gid";
877
+ /**
878
+ * Build the `x-archil-*` headers for {@link PosixCreateAttrs}. `mode` is sent
879
+ * in octal (`0o640` → "640"), matching the gateway's parser and the Python SDK.
880
+ * Returns undefined when no attribute is set, so no headers are added.
881
+ */
882
+ function posixCreateHeaders(attrs) {
883
+ const headers = {};
884
+ if (attrs.mode !== void 0) headers[ARCHIL_MODE_HEADER] = attrs.mode.toString(8);
885
+ if (attrs.uid !== void 0) headers[ARCHIL_UID_HEADER] = String(attrs.uid);
886
+ if (attrs.gid !== void 0) headers[ARCHIL_GID_HEADER] = String(attrs.gid);
887
+ return Object.keys(headers).length > 0 ? headers : void 0;
888
+ }
839
889
  /** S3's per-request cap on DeleteObjects keys; larger inputs are batched. */
840
890
  const MAX_DELETE_OBJECTS_PER_REQUEST = 1e3;
841
891
  /** Automatic retries for a transient S3 failure (5xx / 429 / network error). */
@@ -995,6 +1045,8 @@ function parseListMultipartUploadsResult(xml) {
995
1045
  }
996
1046
  //#endregion
997
1047
  //#region src/disks.ts
1048
+ /** Server-side maximum page size for GET /api/disks. */
1049
+ const DISK_PAGE_LIMIT = 100;
998
1050
  var Disks = class {
999
1051
  /** @internal */
1000
1052
  _client;
@@ -1008,12 +1060,45 @@ var Disks = class {
1008
1060
  this._region = region;
1009
1061
  this._s3BaseUrl = s3BaseUrl;
1010
1062
  }
1063
+ /**
1064
+ * List the account's disks. Fetches in cursor-driven pages (bounded server
1065
+ * work per request) and follows `nextCursor` until exhausted, so the result
1066
+ * is complete even for very large accounts. Use `limit` to cap the total, or
1067
+ * {@link listPage} to walk pages yourself.
1068
+ */
1011
1069
  async list(opts) {
1012
- return (await unwrap(this._client.GET("/api/disks", { params: { query: {
1070
+ if (opts?.name !== void 0) return (await this.listPage(opts)).disks;
1071
+ const limit = opts?.limit;
1072
+ let cursor = opts?.cursor;
1073
+ const disks = [];
1074
+ for (;;) {
1075
+ const remaining = limit === void 0 ? void 0 : limit - disks.length;
1076
+ if (remaining !== void 0 && remaining <= 0) return disks;
1077
+ const pageLimit = remaining === void 0 ? DISK_PAGE_LIMIT : Math.min(remaining, DISK_PAGE_LIMIT);
1078
+ const page = await this.listPage({
1079
+ limit: pageLimit,
1080
+ cursor
1081
+ });
1082
+ disks.push(...remaining === void 0 ? page.disks : page.disks.slice(0, remaining));
1083
+ if (!page.nextCursor || page.nextCursor === cursor) return disks;
1084
+ cursor = page.nextCursor;
1085
+ }
1086
+ }
1087
+ /**
1088
+ * Fetch a single page of disks. `nextCursor` on the result resumes the
1089
+ * listing (it can also be persisted, e.g. across requests of a paginated UI).
1090
+ */
1091
+ async listPage(opts) {
1092
+ const { data, nextCursor } = await unwrapPage(this._client.GET("/api/disks", { params: { query: {
1013
1093
  limit: opts?.limit,
1014
1094
  cursor: opts?.cursor,
1015
1095
  name: opts?.name
1016
- } } }))).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
1096
+ } } }));
1097
+ const disks = (data ?? []).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
1098
+ return nextCursor ? {
1099
+ disks,
1100
+ nextCursor
1101
+ } : { disks };
1017
1102
  }
1018
1103
  async get(id) {
1019
1104
  return new Disk(await unwrap(this._client.GET("/api/disks/{id}", { params: { path: { id } } })), this._client, this._region, this._s3BaseUrl);
@@ -1180,10 +1265,10 @@ var Workspace = class {
1180
1265
  const { entry, diskKey } = this.route(key);
1181
1266
  return entry.disk.getObject(diskKey);
1182
1267
  }
1183
- async putObject(key, body, contentType) {
1268
+ async putObject(key, body, options) {
1184
1269
  const { entry, diskKey } = this.route(key);
1185
1270
  if (entry.readOnly) throw new Error(`${key} is on a read-only disk and cannot be written.`);
1186
- return entry.disk.putObject(diskKey, body, contentType);
1271
+ return entry.disk.putObject(diskKey, body, options);
1187
1272
  }
1188
1273
  async deleteObject(key) {
1189
1274
  const { entry, diskKey } = this.route(key);
package/dist/index.d.cts CHANGED
@@ -1,11 +1,21 @@
1
- import { A as AwsStsUser, B as ExecRequest, C as S3Object, D as effectiveUploadPartSize, E as UploadPart, F as DiskMetrics, G as MountConfigResponse, H as GrepMatch, I as DiskResponse, J as S3CompatibleMount, K as MountResponse, L as DiskStatus, M as ConnectedClient, N as CreateApiTokenRequest, O as ApiTokenResponse, P as CreateDiskRequest, Q as ApiClient, R as DiskUser, S as PutObjectResult, T as ShareUrlResult, U as GrepStoppedReason, V as GCSMount, W as MountConfig, X as TokenUser, Y as S3Mount, Z as FileSystem, _ as MultipartUploadSummary, a as Disk, b as PartListing, c as GrepOptions, d as ListObjectsOptions, f as ListObjectsResult, g as MultipartUploadListing, h as MultipartUpload, i as DeleteObjectsResult, j as AzureBlobMount, k as AuthorizedUser, l as GrepResult, m as MountOptions, n as DeleteObjectsError, o as DiskMultipart, p as ListPartsOptions, q as R2Mount, r as DeleteObjectsOptions, s as ExecResult, t as CompletedMultipartUpload, u as ListMultipartUploadsOptions, v as ObjectMetadata, w as ShareUrlOptions, x as PutObjectOptions, y as PartInfo, z as ExecDiskResult } from "./disk-BLF7FFqG.cjs";
1
+ import { $ as FileSystem, A as ApiTokenResponse, B as DiskUser, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepStoppedReason, H as ExecRequest, I as CreateDiskRequest, J as MountResponse, K as MountConfig, L as DiskMetrics, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as TokenUser, R as DiskResponse, S as PosixCreateAttrs, T as S3Object, U as GCSMount, V as ExecDiskResult, W as GrepMatch, X as S3CompatibleMount, Y as R2Mount, Z as S3Mount, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as ApiClient, f as ListObjectsOptions, g as MultipartUpload, h as MountOptions, i as DeleteObjectsOptions, j as AuthorizedUser, k as effectiveUploadPartSize, l as GrepOptions, m as ListPartsOptions, n as CompletedMultipartUpload, o as Disk, p as ListObjectsResult, q as MountConfigResponse, r as DeleteObjectsError, s as DiskMultipart, t as AppendObjectOptions, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskStatus } from "./disk-BhRejJas.cjs";
2
2
 
3
3
  //#region src/disks.d.ts
4
4
  interface ListDisksOptions {
5
+ /** Cap on the total number of disks returned. */
5
6
  limit?: number;
7
+ /** Resume listing from a previous page's `nextCursor`. */
6
8
  cursor?: string;
7
9
  name?: string;
8
10
  }
11
+ interface DiskListPage {
12
+ disks: Disk[];
13
+ /**
14
+ * Set when more disks remain beyond this page; pass it back as `cursor` to
15
+ * fetch the next one. Undefined on the last page.
16
+ */
17
+ nextCursor?: string;
18
+ }
9
19
  interface CreateDiskResult {
10
20
  disk: Disk;
11
21
  token: string | null;
@@ -21,7 +31,18 @@ declare class Disks {
21
31
  private readonly _s3BaseUrl?;
22
32
  /** @internal */
23
33
  constructor(client: ApiClient, region: string, s3BaseUrl?: string);
34
+ /**
35
+ * List the account's disks. Fetches in cursor-driven pages (bounded server
36
+ * work per request) and follows `nextCursor` until exhausted, so the result
37
+ * is complete even for very large accounts. Use `limit` to cap the total, or
38
+ * {@link listPage} to walk pages yourself.
39
+ */
24
40
  list(opts?: ListDisksOptions): Promise<Disk[]>;
41
+ /**
42
+ * Fetch a single page of disks. `nextCursor` on the result resumes the
43
+ * listing (it can also be persisted, e.g. across requests of a paginated UI).
44
+ */
45
+ listPage(opts?: ListDisksOptions): Promise<DiskListPage>;
25
46
  get(id: string): Promise<Disk>;
26
47
  /**
27
48
  * Create a new disk with an auto-generated mount token.
@@ -93,7 +114,7 @@ declare class Workspace implements FileSystem {
93
114
  /** Map a disk key back to its workspace key (`<name>/...`), stripping the mount subdirectory. */
94
115
  private abs;
95
116
  getObject(key: string): Promise<Uint8Array>;
96
- putObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
117
+ putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
97
118
  deleteObject(key: string): Promise<void>;
98
119
  listObjects(prefix?: string, opts?: ListObjectsOptions): Promise<ListObjectsResult>;
99
120
  grep(opts: GrepOptions): Promise<GrepResult>;
@@ -263,4 +284,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
263
284
  */
264
285
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
265
286
  //#endregion
266
- export { type ApiTokenResponse, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PutObjectOptions, type PutObjectResult, type R2Mount, type S3CompatibleMount, type S3Mount, type S3Object, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, deleteApiKey, effectiveUploadPartSize, exec, getDisk, listApiKeys, listDisks, workspace };
287
+ export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type S3CompatibleMount, type S3Mount, type S3Object, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, deleteApiKey, effectiveUploadPartSize, exec, getDisk, listApiKeys, listDisks, workspace };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,21 @@
1
- import { A as AwsStsUser, B as ExecRequest, C as S3Object, D as effectiveUploadPartSize, E as UploadPart, F as DiskMetrics, G as MountConfigResponse, H as GrepMatch, I as DiskResponse, J as S3CompatibleMount, K as MountResponse, L as DiskStatus, M as ConnectedClient, N as CreateApiTokenRequest, O as ApiTokenResponse, P as CreateDiskRequest, Q as ApiClient, R as DiskUser, S as PutObjectResult, T as ShareUrlResult, U as GrepStoppedReason, V as GCSMount, W as MountConfig, X as TokenUser, Y as S3Mount, Z as FileSystem, _ as MultipartUploadSummary, a as Disk, b as PartListing, c as GrepOptions, d as ListObjectsOptions, f as ListObjectsResult, g as MultipartUploadListing, h as MultipartUpload, i as DeleteObjectsResult, j as AzureBlobMount, k as AuthorizedUser, l as GrepResult, m as MountOptions, n as DeleteObjectsError, o as DiskMultipart, p as ListPartsOptions, q as R2Mount, r as DeleteObjectsOptions, s as ExecResult, t as CompletedMultipartUpload, u as ListMultipartUploadsOptions, v as ObjectMetadata, w as ShareUrlOptions, x as PutObjectOptions, y as PartInfo, z as ExecDiskResult } from "./disk-BLF7FFqG.mjs";
1
+ import { $ as FileSystem, A as ApiTokenResponse, B as DiskUser, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepStoppedReason, H as ExecRequest, I as CreateDiskRequest, J as MountResponse, K as MountConfig, L as DiskMetrics, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as TokenUser, R as DiskResponse, S as PosixCreateAttrs, T as S3Object, U as GCSMount, V as ExecDiskResult, W as GrepMatch, X as S3CompatibleMount, Y as R2Mount, Z as S3Mount, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as ApiClient, f as ListObjectsOptions, g as MultipartUpload, h as MountOptions, i as DeleteObjectsOptions, j as AuthorizedUser, k as effectiveUploadPartSize, l as GrepOptions, m as ListPartsOptions, n as CompletedMultipartUpload, o as Disk, p as ListObjectsResult, q as MountConfigResponse, r as DeleteObjectsError, s as DiskMultipart, t as AppendObjectOptions, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskStatus } from "./disk-BhRejJas.mjs";
2
2
 
3
3
  //#region src/disks.d.ts
4
4
  interface ListDisksOptions {
5
+ /** Cap on the total number of disks returned. */
5
6
  limit?: number;
7
+ /** Resume listing from a previous page's `nextCursor`. */
6
8
  cursor?: string;
7
9
  name?: string;
8
10
  }
11
+ interface DiskListPage {
12
+ disks: Disk[];
13
+ /**
14
+ * Set when more disks remain beyond this page; pass it back as `cursor` to
15
+ * fetch the next one. Undefined on the last page.
16
+ */
17
+ nextCursor?: string;
18
+ }
9
19
  interface CreateDiskResult {
10
20
  disk: Disk;
11
21
  token: string | null;
@@ -21,7 +31,18 @@ declare class Disks {
21
31
  private readonly _s3BaseUrl?;
22
32
  /** @internal */
23
33
  constructor(client: ApiClient, region: string, s3BaseUrl?: string);
34
+ /**
35
+ * List the account's disks. Fetches in cursor-driven pages (bounded server
36
+ * work per request) and follows `nextCursor` until exhausted, so the result
37
+ * is complete even for very large accounts. Use `limit` to cap the total, or
38
+ * {@link listPage} to walk pages yourself.
39
+ */
24
40
  list(opts?: ListDisksOptions): Promise<Disk[]>;
41
+ /**
42
+ * Fetch a single page of disks. `nextCursor` on the result resumes the
43
+ * listing (it can also be persisted, e.g. across requests of a paginated UI).
44
+ */
45
+ listPage(opts?: ListDisksOptions): Promise<DiskListPage>;
25
46
  get(id: string): Promise<Disk>;
26
47
  /**
27
48
  * Create a new disk with an auto-generated mount token.
@@ -93,7 +114,7 @@ declare class Workspace implements FileSystem {
93
114
  /** Map a disk key back to its workspace key (`<name>/...`), stripping the mount subdirectory. */
94
115
  private abs;
95
116
  getObject(key: string): Promise<Uint8Array>;
96
- putObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
117
+ putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
97
118
  deleteObject(key: string): Promise<void>;
98
119
  listObjects(prefix?: string, opts?: ListObjectsOptions): Promise<ListObjectsResult>;
99
120
  grep(opts: GrepOptions): Promise<GrepResult>;
@@ -263,4 +284,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
263
284
  */
264
285
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
265
286
  //#endregion
266
- export { type ApiTokenResponse, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PutObjectOptions, type PutObjectResult, type R2Mount, type S3CompatibleMount, type S3Mount, type S3Object, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, deleteApiKey, effectiveUploadPartSize, exec, getDisk, listApiKeys, listDisks, workspace };
287
+ export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type S3CompatibleMount, type S3Mount, type S3Object, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, deleteApiKey, effectiveUploadPartSize, exec, getDisk, listApiKeys, listDisks, workspace };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as USER_AGENT, a as exec, b as ArchilError, c as listDisks, d as Workspace, f as Tokens, g as effectiveUploadPartSize, h as DiskMultipart, i as deleteApiKey, l as workspace, m as Disk, n as createApiKey, o as getDisk, p as Disks, r as createDisk, s as listApiKeys, t as configure, u as Archil, v as VERSION, x as ArchilS3Error, y as ArchilApiError } from "./src--b7LHPh_.mjs";
1
+ import { _ as USER_AGENT, a as exec, b as ArchilError, c as listDisks, d as Workspace, f as Tokens, g as effectiveUploadPartSize, h as DiskMultipart, i as deleteApiKey, l as workspace, m as Disk, n as createApiKey, o as getDisk, p as Disks, r as createDisk, s as listApiKeys, t as configure, u as Archil, v as VERSION, x as ArchilS3Error, y as ArchilApiError } from "./src-CrK7pSLW.mjs";
2
2
  export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, deleteApiKey, effectiveUploadPartSize, exec, getDisk, listApiKeys, listDisks, workspace };
@@ -1,4 +1,4 @@
1
- import { Z as FileSystem } from "../disk-BLF7FFqG.cjs";
1
+ import { $ as FileSystem } from "../disk-BhRejJas.cjs";
2
2
  import { ZodType, z } from "zod";
3
3
 
4
4
  //#region src/internal/tools.d.ts
@@ -1,4 +1,4 @@
1
- import { Z as FileSystem } from "../disk-BLF7FFqG.mjs";
1
+ import { $ as FileSystem } from "../disk-BhRejJas.mjs";
2
2
  import { ZodType, z } from "zod";
3
3
 
4
4
  //#region src/internal/tools.d.ts
@@ -111,7 +111,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
111
111
  }
112
112
  //#endregion
113
113
  //#region src/version.ts
114
- const VERSION = "0.8.19";
114
+ const VERSION = "0.8.21";
115
115
  const USER_AGENT = `archil-js/${VERSION}`;
116
116
  //#endregion
117
117
  //#region src/client.ts
@@ -130,10 +130,21 @@ function createApiClient(opts) {
130
130
  * Unwrap the API envelope: return data on success, throw ArchilApiError on failure.
131
131
  */
132
132
  async function unwrap(promise) {
133
+ return (await unwrapPage(promise)).data;
134
+ }
135
+ /**
136
+ * Unwrap a paginated list envelope: like {@link unwrap}, but also surface the
137
+ * envelope's `nextCursor` (undefined on the last page or from a server that
138
+ * doesn't paginate).
139
+ */
140
+ async function unwrapPage(promise) {
133
141
  const { data: body, error, response } = await promise;
134
142
  if (error || !body) throw new ArchilApiError(error?.error ?? `API request failed with status ${response.status}`, response.status);
135
143
  if (!body.success) throw new ArchilApiError(body.error ?? "Unknown API error", response.status);
136
- return body.data;
144
+ return {
145
+ data: body.data,
146
+ nextCursor: body.nextCursor
147
+ };
137
148
  }
138
149
  /**
139
150
  * Unwrap an API response that has no data payload (e.g., delete operations).
@@ -360,12 +371,16 @@ var Disk = class {
360
371
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
361
372
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
362
373
  *
374
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
375
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
376
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
377
+ *
363
378
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
364
379
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
365
380
  * @param options Either a content-type string, or {@link PutObjectOptions}
366
381
  * (`contentType`, `multipartThreshold`, `partSize`,
367
- * `concurrency`). Content type defaults to
368
- * "application/octet-stream".
382
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
383
+ * to "application/octet-stream".
369
384
  */
370
385
  async putObject(key, body, options) {
371
386
  const opts = typeof options === "string" ? { contentType: options } : options ?? {};
@@ -376,22 +391,23 @@ var Disk = class {
376
391
  if (bytes.length <= threshold) {
377
392
  const resp = await this._s3Request("PUT", key, {
378
393
  body,
379
- contentType
394
+ contentType,
395
+ extraHeaders: posixCreateHeaders(opts)
380
396
  });
381
397
  if (!resp.ok) throw parseS3Error("PutObject", resp.status, resp.statusText, decodeText(resp.body));
382
398
  return { etag: resp.headers.get("etag") ?? void 0 };
383
399
  }
384
- return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY));
400
+ return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY), opts);
385
401
  }
386
402
  /**
387
403
  * Upload a large body through the multipart lifecycle: split into `partSize`
388
404
  * parts, upload them with bounded concurrency, then complete — aborting the
389
405
  * upload if any part fails so nothing is left half-staged. @internal
390
406
  */
391
- async _putMultipart(key, bytes, contentType, partSize, concurrency) {
407
+ async _putMultipart(key, bytes, contentType, partSize, concurrency, attrs = {}) {
392
408
  const effectivePartSize = effectiveUploadPartSize(bytes.length, partSize);
393
409
  const mp = this.multipart;
394
- const upload = await mp.create(key, contentType);
410
+ const upload = await mp.create(key, contentType, attrs);
395
411
  try {
396
412
  const partCount = Math.ceil(bytes.length / effectivePartSize);
397
413
  const parts = new Array(partCount);
@@ -427,16 +443,25 @@ var Disk = class {
427
443
  * would duplicate the bytes. On a transient failure, re-append yourself only
428
444
  * after confirming the object's size.
429
445
  *
430
- * @param key Path on the disk (e.g. "logs/app.log")
431
- * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
432
- * @param contentType MIME type, applied only when the object is newly created.
446
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
447
+ * POSIX attributes of the newly created file (same headers as
448
+ * {@link putObject}); they have no effect on an append to an existing object.
449
+ *
450
+ * @param key Path on the disk (e.g. "logs/app.log")
451
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
452
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
453
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
454
+ * to "application/octet-stream" and applies only when the
455
+ * object is newly created.
433
456
  */
434
- async appendObject(key, body, contentType = "application/octet-stream") {
457
+ async appendObject(key, body, options) {
458
+ const opts = typeof options === "string" ? { contentType: options } : options ?? {};
435
459
  const resp = await this._s3Request("PUT", key, {
436
460
  body,
437
- contentType,
461
+ contentType: opts.contentType ?? "application/octet-stream",
438
462
  query: { append: "true" },
439
- retry: false
463
+ retry: false,
464
+ extraHeaders: posixCreateHeaders(opts)
440
465
  });
441
466
  if (!resp.ok) throw parseS3Error("AppendObject", resp.status, resp.statusText, decodeText(resp.body));
442
467
  return { etag: resp.headers.get("etag") ?? void 0 };
@@ -602,7 +627,10 @@ var Disk = class {
602
627
  body: opts.body,
603
628
  bodySerializer: (b) => b
604
629
  } : {},
605
- ...opts.contentType ? { headers: { "Content-Type": opts.contentType } } : {}
630
+ ...opts.contentType || opts.extraHeaders ? { headers: {
631
+ ...opts.contentType ? { "Content-Type": opts.contentType } : {},
632
+ ...opts.extraHeaders
633
+ } } : {}
606
634
  };
607
635
  const hasBody = method === "GET" || method === "POST";
608
636
  const maxRetries = opts.retry === false ? 0 : MAX_S3_RETRIES;
@@ -688,11 +716,14 @@ var DiskMultipart = class {
688
716
  *
689
717
  * @param key Path on the disk the finished object will live at.
690
718
  * @param contentType MIME type to store the object with.
719
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
720
+ * object (see {@link PosixCreateAttrs}).
691
721
  */
692
- async create(key, contentType) {
722
+ async create(key, contentType, attrs = {}) {
693
723
  const resp = await this.s3Request("POST", key, {
694
724
  query: { uploads: "" },
695
- contentType
725
+ contentType,
726
+ extraHeaders: posixCreateHeaders(attrs)
696
727
  });
697
728
  if (!resp.ok) throw parseS3Error("CreateMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
698
729
  const root = parseXml(decodeText(resp.body)).InitiateMultipartUploadResult ?? {};
@@ -813,6 +844,25 @@ var DiskMultipart = class {
813
844
  return parseListMultipartUploadsResult(decodeText(resp.body));
814
845
  }
815
846
  };
847
+ /**
848
+ * Headers the S3 gateway accepts to set POSIX mode/owner on newly created
849
+ * objects (see fshandler `x-archil-*` PutObject attrs).
850
+ */
851
+ const ARCHIL_MODE_HEADER = "x-archil-mode";
852
+ const ARCHIL_UID_HEADER = "x-archil-uid";
853
+ const ARCHIL_GID_HEADER = "x-archil-gid";
854
+ /**
855
+ * Build the `x-archil-*` headers for {@link PosixCreateAttrs}. `mode` is sent
856
+ * in octal (`0o640` → "640"), matching the gateway's parser and the Python SDK.
857
+ * Returns undefined when no attribute is set, so no headers are added.
858
+ */
859
+ function posixCreateHeaders(attrs) {
860
+ const headers = {};
861
+ if (attrs.mode !== void 0) headers[ARCHIL_MODE_HEADER] = attrs.mode.toString(8);
862
+ if (attrs.uid !== void 0) headers[ARCHIL_UID_HEADER] = String(attrs.uid);
863
+ if (attrs.gid !== void 0) headers[ARCHIL_GID_HEADER] = String(attrs.gid);
864
+ return Object.keys(headers).length > 0 ? headers : void 0;
865
+ }
816
866
  /** S3's per-request cap on DeleteObjects keys; larger inputs are batched. */
817
867
  const MAX_DELETE_OBJECTS_PER_REQUEST = 1e3;
818
868
  /** Automatic retries for a transient S3 failure (5xx / 429 / network error). */
@@ -972,6 +1022,8 @@ function parseListMultipartUploadsResult(xml) {
972
1022
  }
973
1023
  //#endregion
974
1024
  //#region src/disks.ts
1025
+ /** Server-side maximum page size for GET /api/disks. */
1026
+ const DISK_PAGE_LIMIT = 100;
975
1027
  var Disks = class {
976
1028
  /** @internal */
977
1029
  _client;
@@ -985,12 +1037,45 @@ var Disks = class {
985
1037
  this._region = region;
986
1038
  this._s3BaseUrl = s3BaseUrl;
987
1039
  }
1040
+ /**
1041
+ * List the account's disks. Fetches in cursor-driven pages (bounded server
1042
+ * work per request) and follows `nextCursor` until exhausted, so the result
1043
+ * is complete even for very large accounts. Use `limit` to cap the total, or
1044
+ * {@link listPage} to walk pages yourself.
1045
+ */
988
1046
  async list(opts) {
989
- return (await unwrap(this._client.GET("/api/disks", { params: { query: {
1047
+ if (opts?.name !== void 0) return (await this.listPage(opts)).disks;
1048
+ const limit = opts?.limit;
1049
+ let cursor = opts?.cursor;
1050
+ const disks = [];
1051
+ for (;;) {
1052
+ const remaining = limit === void 0 ? void 0 : limit - disks.length;
1053
+ if (remaining !== void 0 && remaining <= 0) return disks;
1054
+ const pageLimit = remaining === void 0 ? DISK_PAGE_LIMIT : Math.min(remaining, DISK_PAGE_LIMIT);
1055
+ const page = await this.listPage({
1056
+ limit: pageLimit,
1057
+ cursor
1058
+ });
1059
+ disks.push(...remaining === void 0 ? page.disks : page.disks.slice(0, remaining));
1060
+ if (!page.nextCursor || page.nextCursor === cursor) return disks;
1061
+ cursor = page.nextCursor;
1062
+ }
1063
+ }
1064
+ /**
1065
+ * Fetch a single page of disks. `nextCursor` on the result resumes the
1066
+ * listing (it can also be persisted, e.g. across requests of a paginated UI).
1067
+ */
1068
+ async listPage(opts) {
1069
+ const { data, nextCursor } = await unwrapPage(this._client.GET("/api/disks", { params: { query: {
990
1070
  limit: opts?.limit,
991
1071
  cursor: opts?.cursor,
992
1072
  name: opts?.name
993
- } } }))).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
1073
+ } } }));
1074
+ const disks = (data ?? []).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
1075
+ return nextCursor ? {
1076
+ disks,
1077
+ nextCursor
1078
+ } : { disks };
994
1079
  }
995
1080
  async get(id) {
996
1081
  return new Disk(await unwrap(this._client.GET("/api/disks/{id}", { params: { path: { id } } })), this._client, this._region, this._s3BaseUrl);
@@ -1157,10 +1242,10 @@ var Workspace = class {
1157
1242
  const { entry, diskKey } = this.route(key);
1158
1243
  return entry.disk.getObject(diskKey);
1159
1244
  }
1160
- async putObject(key, body, contentType) {
1245
+ async putObject(key, body, options) {
1161
1246
  const { entry, diskKey } = this.route(key);
1162
1247
  if (entry.readOnly) throw new Error(`${key} is on a read-only disk and cannot be written.`);
1163
- return entry.disk.putObject(diskKey, body, contentType);
1248
+ return entry.disk.putObject(diskKey, body, options);
1164
1249
  }
1165
1250
  async deleteObject(key) {
1166
1251
  const { entry, diskKey } = this.route(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disk",
3
- "version": "0.8.19",
3
+ "version": "0.8.21",
4
4
  "description": "Pure-JS client and CLI for Archil disks",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@archildata/api-types": "^0.0.1",
31
31
  "commander": "^14.0.3",
32
- "fast-xml-parser": "^4.5.1",
32
+ "fast-xml-parser": "^5.7.0",
33
33
  "openapi-fetch": "^0.13.5",
34
34
  "zod": "^4.4.3"
35
35
  },