disk 0.8.20 → 0.8.22

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/README.md CHANGED
@@ -271,6 +271,29 @@ const workspace = archil.workspace({
271
271
  When `queueMs` is set without `checkoutPaths`, the mount root is acquired
272
272
  during mount setup instead.
273
273
 
274
+ ## Delegations
275
+
276
+ A delegation grants a client exclusive write access to an inode on a shared
277
+ disk. List the delegations currently held on a disk and forcibly revoke one —
278
+ useful for reclaiming write access from a client that crashed or lost
279
+ connectivity without checking its delegations in:
280
+
281
+ ```ts
282
+ const disk = await archil.disks.get("dsk-0123456789abcdef");
283
+
284
+ for (const d of await disk.listDelegations()) {
285
+ // { clientId, inodeId, path?, isPending, isOrphaned }
286
+ if (d.isOrphaned) {
287
+ await disk.revokeDelegation(d);
288
+ }
289
+ }
290
+ ```
291
+
292
+ A delegation has no ID of its own — it is identified by the
293
+ `(clientId, inodeId)` pair. `isOrphaned` entries are held by clients no longer
294
+ connected to the disk. `path` is resolved best-effort by the server and may be
295
+ absent.
296
+
274
297
  A `Workspace` is a full filesystem in its own right — it has the same object API
275
298
  a `Disk` does (`getObject` / `putObject` / `deleteObject` / `listObjects` /
276
299
  `grep` / `exec`; both implement the `FileSystem` interface), so you can use it
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-BuqSzAcO.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-BepELcl6.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. */
@@ -50,6 +50,7 @@ type GCSMount = components["schemas"]["GCSMount"];
50
50
  type R2Mount = components["schemas"]["R2Mount"];
51
51
  type S3CompatibleMount = components["schemas"]["S3CompatibleMount"];
52
52
  type AzureBlobMount = components["schemas"]["AzureBlobMount"];
53
+ type Delegation = components["schemas"]["DelegationEntry"];
53
54
  type DiskUser = components["schemas"]["DiskUser"];
54
55
  type TokenUser = components["schemas"]["TokenUser"];
55
56
  type AwsStsUser = components["schemas"]["AwsStsUser"];
@@ -305,7 +306,20 @@ interface DeleteObjectsResult {
305
306
  /** Per-key failures; empty when every key was deleted. */
306
307
  errors: DeleteObjectsError[];
307
308
  }
308
- interface PutObjectOptions {
309
+ /**
310
+ * POSIX attributes to set on a newly created object, sent to the S3 gateway as
311
+ * `x-archil-*` headers. All optional — anything omitted falls back to the
312
+ * server-side defaults (currently `root:root`, mode `0644`).
313
+ */
314
+ interface PosixCreateAttrs {
315
+ /** POSIX mode bits for the created file, e.g. `0o644`. Sent in octal. */
316
+ mode?: number;
317
+ /** Owning user id, e.g. `1000`. */
318
+ uid?: number;
319
+ /** Owning group id, e.g. `1000`. */
320
+ gid?: number;
321
+ }
322
+ interface PutObjectOptions extends PosixCreateAttrs {
309
323
  /** MIME type to store the object with. Default "application/octet-stream". */
310
324
  contentType?: string;
311
325
  /**
@@ -323,6 +337,13 @@ interface PutObjectOptions {
323
337
  /** Max parts uploaded in parallel on the multipart path. Default 4. */
324
338
  concurrency?: number;
325
339
  }
340
+ interface AppendObjectOptions extends PosixCreateAttrs {
341
+ /**
342
+ * MIME type, applied only when the object is newly created. Default
343
+ * "application/octet-stream".
344
+ */
345
+ contentType?: string;
346
+ }
326
347
  /**
327
348
  * The S3 transport function {@link DiskMultipart} uses, supplied by the owning
328
349
  * {@link Disk} so the namespace shares the disk's credential and endpoint.
@@ -333,6 +354,7 @@ type S3RequestFn = (method: "GET" | "PUT" | "DELETE" | "HEAD" | "POST", key: str
333
354
  contentType?: string;
334
355
  query?: Record<string, string | number>;
335
356
  retry?: boolean;
357
+ extraHeaders?: Record<string, string>;
336
358
  }) => Promise<{
337
359
  ok: boolean;
338
360
  status: number;
@@ -375,6 +397,30 @@ declare class Disk implements FileSystem {
375
397
  identifier: string;
376
398
  }>;
377
399
  removeTokenUser(identifier: string): Promise<void>;
400
+ /**
401
+ * List all delegations currently held on this disk. A delegation grants a
402
+ * client exclusive write access to an inode; it has no ID of its own and is
403
+ * identified by the (clientId, inodeId) pair — pass those to
404
+ * `revokeDelegation` to release one. Entries with `isOrphaned: true` are
405
+ * held by clients no longer connected to the disk (disconnected without
406
+ * checking in). `path` is resolved best-effort by the server and may be
407
+ * absent.
408
+ */
409
+ listDelegations(): Promise<Delegation[]>;
410
+ /**
411
+ * Forcibly revoke a delegation, reclaiming write access from a client that
412
+ * is unreachable or crashed without checking its delegations in.
413
+ *
414
+ * Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
415
+ * entry from `listDelegations` directly:
416
+ *
417
+ * ```ts
418
+ * for (const d of await disk.listDelegations()) {
419
+ * if (d.isOrphaned) await disk.revokeDelegation(d);
420
+ * }
421
+ * ```
422
+ */
423
+ revokeDelegation(delegation: Pick<Delegation, "clientId" | "inodeId">): Promise<void>;
378
424
  getAllowedIPs(): Promise<string[]>;
379
425
  setAllowedIPs(allowedIps: string[]): Promise<string[]>;
380
426
  addAllowedIP(ip: string): Promise<string[]>;
@@ -439,12 +485,16 @@ declare class Disk implements FileSystem {
439
485
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
440
486
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
441
487
  *
488
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
489
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
490
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
491
+ *
442
492
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
443
493
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
444
494
  * @param options Either a content-type string, or {@link PutObjectOptions}
445
495
  * (`contentType`, `multipartThreshold`, `partSize`,
446
- * `concurrency`). Content type defaults to
447
- * "application/octet-stream".
496
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
497
+ * to "application/octet-stream".
448
498
  */
449
499
  putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
450
500
  /**
@@ -468,11 +518,18 @@ declare class Disk implements FileSystem {
468
518
  * would duplicate the bytes. On a transient failure, re-append yourself only
469
519
  * after confirming the object's size.
470
520
  *
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.
521
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
522
+ * POSIX attributes of the newly created file (same headers as
523
+ * {@link putObject}); they have no effect on an append to an existing object.
524
+ *
525
+ * @param key Path on the disk (e.g. "logs/app.log")
526
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
527
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
528
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
529
+ * to "application/octet-stream" and applies only when the
530
+ * object is newly created.
474
531
  */
475
- appendObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
532
+ appendObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | AppendObjectOptions): Promise<PutObjectResult>;
476
533
  /**
477
534
  * Delete an object from the disk via the S3-compatible DeleteObject API.
478
535
  * Idempotent: deleting a key that doesn't exist resolves successfully, per
@@ -572,8 +629,10 @@ declare class DiskMultipart {
572
629
  *
573
630
  * @param key Path on the disk the finished object will live at.
574
631
  * @param contentType MIME type to store the object with.
632
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
633
+ * object (see {@link PosixCreateAttrs}).
575
634
  */
576
- create(key: string, contentType?: string): Promise<MultipartUpload>;
635
+ create(key: string, contentType?: string, attrs?: PosixCreateAttrs): Promise<MultipartUpload>;
577
636
  /**
578
637
  * Upload one part (UploadPart) and return its entity tag, which you must
579
638
  * collect (with its part number) and pass to {@link complete}. Every part
@@ -638,4 +697,4 @@ declare class DiskMultipart {
638
697
  */
639
698
  declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
640
699
  //#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 };
700
+ export { TokenUser as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3Mount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, S3CompatibleMount as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, FileSystem 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, MountConfig as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, ApiClient as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse 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. */
@@ -50,6 +50,7 @@ type GCSMount = components["schemas"]["GCSMount"];
50
50
  type R2Mount = components["schemas"]["R2Mount"];
51
51
  type S3CompatibleMount = components["schemas"]["S3CompatibleMount"];
52
52
  type AzureBlobMount = components["schemas"]["AzureBlobMount"];
53
+ type Delegation = components["schemas"]["DelegationEntry"];
53
54
  type DiskUser = components["schemas"]["DiskUser"];
54
55
  type TokenUser = components["schemas"]["TokenUser"];
55
56
  type AwsStsUser = components["schemas"]["AwsStsUser"];
@@ -305,7 +306,20 @@ interface DeleteObjectsResult {
305
306
  /** Per-key failures; empty when every key was deleted. */
306
307
  errors: DeleteObjectsError[];
307
308
  }
308
- interface PutObjectOptions {
309
+ /**
310
+ * POSIX attributes to set on a newly created object, sent to the S3 gateway as
311
+ * `x-archil-*` headers. All optional — anything omitted falls back to the
312
+ * server-side defaults (currently `root:root`, mode `0644`).
313
+ */
314
+ interface PosixCreateAttrs {
315
+ /** POSIX mode bits for the created file, e.g. `0o644`. Sent in octal. */
316
+ mode?: number;
317
+ /** Owning user id, e.g. `1000`. */
318
+ uid?: number;
319
+ /** Owning group id, e.g. `1000`. */
320
+ gid?: number;
321
+ }
322
+ interface PutObjectOptions extends PosixCreateAttrs {
309
323
  /** MIME type to store the object with. Default "application/octet-stream". */
310
324
  contentType?: string;
311
325
  /**
@@ -323,6 +337,13 @@ interface PutObjectOptions {
323
337
  /** Max parts uploaded in parallel on the multipart path. Default 4. */
324
338
  concurrency?: number;
325
339
  }
340
+ interface AppendObjectOptions extends PosixCreateAttrs {
341
+ /**
342
+ * MIME type, applied only when the object is newly created. Default
343
+ * "application/octet-stream".
344
+ */
345
+ contentType?: string;
346
+ }
326
347
  /**
327
348
  * The S3 transport function {@link DiskMultipart} uses, supplied by the owning
328
349
  * {@link Disk} so the namespace shares the disk's credential and endpoint.
@@ -333,6 +354,7 @@ type S3RequestFn = (method: "GET" | "PUT" | "DELETE" | "HEAD" | "POST", key: str
333
354
  contentType?: string;
334
355
  query?: Record<string, string | number>;
335
356
  retry?: boolean;
357
+ extraHeaders?: Record<string, string>;
336
358
  }) => Promise<{
337
359
  ok: boolean;
338
360
  status: number;
@@ -375,6 +397,30 @@ declare class Disk implements FileSystem {
375
397
  identifier: string;
376
398
  }>;
377
399
  removeTokenUser(identifier: string): Promise<void>;
400
+ /**
401
+ * List all delegations currently held on this disk. A delegation grants a
402
+ * client exclusive write access to an inode; it has no ID of its own and is
403
+ * identified by the (clientId, inodeId) pair — pass those to
404
+ * `revokeDelegation` to release one. Entries with `isOrphaned: true` are
405
+ * held by clients no longer connected to the disk (disconnected without
406
+ * checking in). `path` is resolved best-effort by the server and may be
407
+ * absent.
408
+ */
409
+ listDelegations(): Promise<Delegation[]>;
410
+ /**
411
+ * Forcibly revoke a delegation, reclaiming write access from a client that
412
+ * is unreachable or crashed without checking its delegations in.
413
+ *
414
+ * Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
415
+ * entry from `listDelegations` directly:
416
+ *
417
+ * ```ts
418
+ * for (const d of await disk.listDelegations()) {
419
+ * if (d.isOrphaned) await disk.revokeDelegation(d);
420
+ * }
421
+ * ```
422
+ */
423
+ revokeDelegation(delegation: Pick<Delegation, "clientId" | "inodeId">): Promise<void>;
378
424
  getAllowedIPs(): Promise<string[]>;
379
425
  setAllowedIPs(allowedIps: string[]): Promise<string[]>;
380
426
  addAllowedIP(ip: string): Promise<string[]>;
@@ -439,12 +485,16 @@ declare class Disk implements FileSystem {
439
485
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
440
486
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
441
487
  *
488
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
489
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
490
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
491
+ *
442
492
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
443
493
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
444
494
  * @param options Either a content-type string, or {@link PutObjectOptions}
445
495
  * (`contentType`, `multipartThreshold`, `partSize`,
446
- * `concurrency`). Content type defaults to
447
- * "application/octet-stream".
496
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
497
+ * to "application/octet-stream".
448
498
  */
449
499
  putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
450
500
  /**
@@ -468,11 +518,18 @@ declare class Disk implements FileSystem {
468
518
  * would duplicate the bytes. On a transient failure, re-append yourself only
469
519
  * after confirming the object's size.
470
520
  *
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.
521
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
522
+ * POSIX attributes of the newly created file (same headers as
523
+ * {@link putObject}); they have no effect on an append to an existing object.
524
+ *
525
+ * @param key Path on the disk (e.g. "logs/app.log")
526
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
527
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
528
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
529
+ * to "application/octet-stream" and applies only when the
530
+ * object is newly created.
474
531
  */
475
- appendObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
532
+ appendObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | AppendObjectOptions): Promise<PutObjectResult>;
476
533
  /**
477
534
  * Delete an object from the disk via the S3-compatible DeleteObject API.
478
535
  * Idempotent: deleting a key that doesn't exist resolves successfully, per
@@ -572,8 +629,10 @@ declare class DiskMultipart {
572
629
  *
573
630
  * @param key Path on the disk the finished object will live at.
574
631
  * @param contentType MIME type to store the object with.
632
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
633
+ * object (see {@link PosixCreateAttrs}).
575
634
  */
576
- create(key: string, contentType?: string): Promise<MultipartUpload>;
635
+ create(key: string, contentType?: string, attrs?: PosixCreateAttrs): Promise<MultipartUpload>;
577
636
  /**
578
637
  * Upload one part (UploadPart) and return its entity tag, which you must
579
638
  * collect (with its part number) and pass to {@link complete}. Every part
@@ -638,4 +697,4 @@ declare class DiskMultipart {
638
697
  */
639
698
  declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
640
699
  //#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 };
700
+ export { TokenUser as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3Mount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, S3CompatibleMount as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, FileSystem 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, MountConfig as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, ApiClient as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse 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.20";
137
+ const VERSION = "0.8.22";
138
138
  const USER_AGENT = `archil-js/${VERSION}`;
139
139
  //#endregion
140
140
  //#region src/client.ts
@@ -275,6 +275,41 @@ var Disk = class {
275
275
  async removeTokenUser(identifier) {
276
276
  await this.removeUser("token", identifier);
277
277
  }
278
+ /**
279
+ * List all delegations currently held on this disk. A delegation grants a
280
+ * client exclusive write access to an inode; it has no ID of its own and is
281
+ * identified by the (clientId, inodeId) pair — pass those to
282
+ * `revokeDelegation` to release one. Entries with `isOrphaned: true` are
283
+ * held by clients no longer connected to the disk (disconnected without
284
+ * checking in). `path` is resolved best-effort by the server and may be
285
+ * absent.
286
+ */
287
+ async listDelegations() {
288
+ return (await unwrap(this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }))).delegations;
289
+ }
290
+ /**
291
+ * Forcibly revoke a delegation, reclaiming write access from a client that
292
+ * is unreachable or crashed without checking its delegations in.
293
+ *
294
+ * Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
295
+ * entry from `listDelegations` directly:
296
+ *
297
+ * ```ts
298
+ * for (const d of await disk.listDelegations()) {
299
+ * if (d.isOrphaned) await disk.revokeDelegation(d);
300
+ * }
301
+ * ```
302
+ */
303
+ async revokeDelegation(delegation) {
304
+ const { clientId, inodeId } = delegation;
305
+ await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
306
+ params: { path: { id: this.id } },
307
+ body: {
308
+ clientId,
309
+ inodeId
310
+ }
311
+ }));
312
+ }
278
313
  async getAllowedIPs() {
279
314
  return (await unwrap(this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }))).allowedIps;
280
315
  }
@@ -394,12 +429,16 @@ var Disk = class {
394
429
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
395
430
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
396
431
  *
432
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
433
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
434
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
435
+ *
397
436
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
398
437
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
399
438
  * @param options Either a content-type string, or {@link PutObjectOptions}
400
439
  * (`contentType`, `multipartThreshold`, `partSize`,
401
- * `concurrency`). Content type defaults to
402
- * "application/octet-stream".
440
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
441
+ * to "application/octet-stream".
403
442
  */
404
443
  async putObject(key, body, options) {
405
444
  const opts = typeof options === "string" ? { contentType: options } : options ?? {};
@@ -410,22 +449,23 @@ var Disk = class {
410
449
  if (bytes.length <= threshold) {
411
450
  const resp = await this._s3Request("PUT", key, {
412
451
  body,
413
- contentType
452
+ contentType,
453
+ extraHeaders: posixCreateHeaders(opts)
414
454
  });
415
455
  if (!resp.ok) throw parseS3Error("PutObject", resp.status, resp.statusText, decodeText(resp.body));
416
456
  return { etag: resp.headers.get("etag") ?? void 0 };
417
457
  }
418
- return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY));
458
+ return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY), opts);
419
459
  }
420
460
  /**
421
461
  * Upload a large body through the multipart lifecycle: split into `partSize`
422
462
  * parts, upload them with bounded concurrency, then complete — aborting the
423
463
  * upload if any part fails so nothing is left half-staged. @internal
424
464
  */
425
- async _putMultipart(key, bytes, contentType, partSize, concurrency) {
465
+ async _putMultipart(key, bytes, contentType, partSize, concurrency, attrs = {}) {
426
466
  const effectivePartSize = effectiveUploadPartSize(bytes.length, partSize);
427
467
  const mp = this.multipart;
428
- const upload = await mp.create(key, contentType);
468
+ const upload = await mp.create(key, contentType, attrs);
429
469
  try {
430
470
  const partCount = Math.ceil(bytes.length / effectivePartSize);
431
471
  const parts = new Array(partCount);
@@ -461,16 +501,25 @@ var Disk = class {
461
501
  * would duplicate the bytes. On a transient failure, re-append yourself only
462
502
  * after confirming the object's size.
463
503
  *
464
- * @param key Path on the disk (e.g. "logs/app.log")
465
- * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
466
- * @param contentType MIME type, applied only when the object is newly created.
504
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
505
+ * POSIX attributes of the newly created file (same headers as
506
+ * {@link putObject}); they have no effect on an append to an existing object.
507
+ *
508
+ * @param key Path on the disk (e.g. "logs/app.log")
509
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
510
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
511
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
512
+ * to "application/octet-stream" and applies only when the
513
+ * object is newly created.
467
514
  */
468
- async appendObject(key, body, contentType = "application/octet-stream") {
515
+ async appendObject(key, body, options) {
516
+ const opts = typeof options === "string" ? { contentType: options } : options ?? {};
469
517
  const resp = await this._s3Request("PUT", key, {
470
518
  body,
471
- contentType,
519
+ contentType: opts.contentType ?? "application/octet-stream",
472
520
  query: { append: "true" },
473
- retry: false
521
+ retry: false,
522
+ extraHeaders: posixCreateHeaders(opts)
474
523
  });
475
524
  if (!resp.ok) throw parseS3Error("AppendObject", resp.status, resp.statusText, decodeText(resp.body));
476
525
  return { etag: resp.headers.get("etag") ?? void 0 };
@@ -636,7 +685,10 @@ var Disk = class {
636
685
  body: opts.body,
637
686
  bodySerializer: (b) => b
638
687
  } : {},
639
- ...opts.contentType ? { headers: { "Content-Type": opts.contentType } } : {}
688
+ ...opts.contentType || opts.extraHeaders ? { headers: {
689
+ ...opts.contentType ? { "Content-Type": opts.contentType } : {},
690
+ ...opts.extraHeaders
691
+ } } : {}
640
692
  };
641
693
  const hasBody = method === "GET" || method === "POST";
642
694
  const maxRetries = opts.retry === false ? 0 : MAX_S3_RETRIES;
@@ -722,11 +774,14 @@ var DiskMultipart = class {
722
774
  *
723
775
  * @param key Path on the disk the finished object will live at.
724
776
  * @param contentType MIME type to store the object with.
777
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
778
+ * object (see {@link PosixCreateAttrs}).
725
779
  */
726
- async create(key, contentType) {
780
+ async create(key, contentType, attrs = {}) {
727
781
  const resp = await this.s3Request("POST", key, {
728
782
  query: { uploads: "" },
729
- contentType
783
+ contentType,
784
+ extraHeaders: posixCreateHeaders(attrs)
730
785
  });
731
786
  if (!resp.ok) throw parseS3Error("CreateMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
732
787
  const root = parseXml(decodeText(resp.body)).InitiateMultipartUploadResult ?? {};
@@ -847,6 +902,25 @@ var DiskMultipart = class {
847
902
  return parseListMultipartUploadsResult(decodeText(resp.body));
848
903
  }
849
904
  };
905
+ /**
906
+ * Headers the S3 gateway accepts to set POSIX mode/owner on newly created
907
+ * objects (see fshandler `x-archil-*` PutObject attrs).
908
+ */
909
+ const ARCHIL_MODE_HEADER = "x-archil-mode";
910
+ const ARCHIL_UID_HEADER = "x-archil-uid";
911
+ const ARCHIL_GID_HEADER = "x-archil-gid";
912
+ /**
913
+ * Build the `x-archil-*` headers for {@link PosixCreateAttrs}. `mode` is sent
914
+ * in octal (`0o640` → "640"), matching the gateway's parser and the Python SDK.
915
+ * Returns undefined when no attribute is set, so no headers are added.
916
+ */
917
+ function posixCreateHeaders(attrs) {
918
+ const headers = {};
919
+ if (attrs.mode !== void 0) headers[ARCHIL_MODE_HEADER] = attrs.mode.toString(8);
920
+ if (attrs.uid !== void 0) headers[ARCHIL_UID_HEADER] = String(attrs.uid);
921
+ if (attrs.gid !== void 0) headers[ARCHIL_GID_HEADER] = String(attrs.gid);
922
+ return Object.keys(headers).length > 0 ? headers : void 0;
923
+ }
850
924
  /** S3's per-request cap on DeleteObjects keys; larger inputs are batched. */
851
925
  const MAX_DELETE_OBJECTS_PER_REQUEST = 1e3;
852
926
  /** Automatic retries for a transient S3 failure (5xx / 429 / network error). */
@@ -1226,10 +1300,10 @@ var Workspace = class {
1226
1300
  const { entry, diskKey } = this.route(key);
1227
1301
  return entry.disk.getObject(diskKey);
1228
1302
  }
1229
- async putObject(key, body, contentType) {
1303
+ async putObject(key, body, options) {
1230
1304
  const { entry, diskKey } = this.route(key);
1231
1305
  if (entry.readOnly) throw new Error(`${key} is on a read-only disk and cannot be written.`);
1232
- return entry.disk.putObject(diskKey, body, contentType);
1306
+ return entry.disk.putObject(diskKey, body, options);
1233
1307
  }
1234
1308
  async deleteObject(key) {
1235
1309
  const { entry, diskKey } = this.route(key);
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
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 TokenUser, A as ApiTokenResponse, B as DiskStatus, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepMatch, H as ExecDiskResult, I as CreateDiskRequest, J as MountConfigResponse, K as GrepStoppedReason, L as Delegation, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as S3Mount, R as DiskMetrics, S as PosixCreateAttrs, T as S3Object, U as ExecRequest, V as DiskUser, W as GCSMount, X as R2Mount, Y as MountResponse, Z as S3CompatibleMount, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as FileSystem, 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 MountConfig, r as DeleteObjectsError, s as DiskMultipart, t as AppendObjectOptions, tt as ApiClient, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskResponse } from "./disk-DEqV3mtA.cjs";
2
2
 
3
3
  //#region src/disks.d.ts
4
4
  interface ListDisksOptions {
@@ -114,7 +114,7 @@ declare class Workspace implements FileSystem {
114
114
  /** Map a disk key back to its workspace key (`<name>/...`), stripping the mount subdirectory. */
115
115
  private abs;
116
116
  getObject(key: string): Promise<Uint8Array>;
117
- putObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
117
+ putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
118
118
  deleteObject(key: string): Promise<void>;
119
119
  listObjects(prefix?: string, opts?: ListObjectsOptions): Promise<ListObjectsResult>;
120
120
  grep(opts: GrepOptions): Promise<GrepResult>;
@@ -284,4 +284,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
284
284
  */
285
285
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
286
286
  //#endregion
287
- 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 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 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 Delegation, 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,4 +1,4 @@
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 TokenUser, A as ApiTokenResponse, B as DiskStatus, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepMatch, H as ExecDiskResult, I as CreateDiskRequest, J as MountConfigResponse, K as GrepStoppedReason, L as Delegation, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as S3Mount, R as DiskMetrics, S as PosixCreateAttrs, T as S3Object, U as ExecRequest, V as DiskUser, W as GCSMount, X as R2Mount, Y as MountResponse, Z as S3CompatibleMount, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as FileSystem, 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 MountConfig, r as DeleteObjectsError, s as DiskMultipart, t as AppendObjectOptions, tt as ApiClient, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskResponse } from "./disk-DEqV3mtA.mjs";
2
2
 
3
3
  //#region src/disks.d.ts
4
4
  interface ListDisksOptions {
@@ -114,7 +114,7 @@ declare class Workspace implements FileSystem {
114
114
  /** Map a disk key back to its workspace key (`<name>/...`), stripping the mount subdirectory. */
115
115
  private abs;
116
116
  getObject(key: string): Promise<Uint8Array>;
117
- putObject(key: string, body: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<PutObjectResult>;
117
+ putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
118
118
  deleteObject(key: string): Promise<void>;
119
119
  listObjects(prefix?: string, opts?: ListObjectsOptions): Promise<ListObjectsResult>;
120
120
  grep(opts: GrepOptions): Promise<GrepResult>;
@@ -284,4 +284,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
284
284
  */
285
285
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
286
286
  //#endregion
287
- 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 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 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 Delegation, 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-BuqSzAcO.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-BepELcl6.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 { et as FileSystem } from "../disk-DEqV3mtA.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 { et as FileSystem } from "../disk-DEqV3mtA.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.20";
114
+ const VERSION = "0.8.22";
115
115
  const USER_AGENT = `archil-js/${VERSION}`;
116
116
  //#endregion
117
117
  //#region src/client.ts
@@ -252,6 +252,41 @@ var Disk = class {
252
252
  async removeTokenUser(identifier) {
253
253
  await this.removeUser("token", identifier);
254
254
  }
255
+ /**
256
+ * List all delegations currently held on this disk. A delegation grants a
257
+ * client exclusive write access to an inode; it has no ID of its own and is
258
+ * identified by the (clientId, inodeId) pair — pass those to
259
+ * `revokeDelegation` to release one. Entries with `isOrphaned: true` are
260
+ * held by clients no longer connected to the disk (disconnected without
261
+ * checking in). `path` is resolved best-effort by the server and may be
262
+ * absent.
263
+ */
264
+ async listDelegations() {
265
+ return (await unwrap(this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }))).delegations;
266
+ }
267
+ /**
268
+ * Forcibly revoke a delegation, reclaiming write access from a client that
269
+ * is unreachable or crashed without checking its delegations in.
270
+ *
271
+ * Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
272
+ * entry from `listDelegations` directly:
273
+ *
274
+ * ```ts
275
+ * for (const d of await disk.listDelegations()) {
276
+ * if (d.isOrphaned) await disk.revokeDelegation(d);
277
+ * }
278
+ * ```
279
+ */
280
+ async revokeDelegation(delegation) {
281
+ const { clientId, inodeId } = delegation;
282
+ await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
283
+ params: { path: { id: this.id } },
284
+ body: {
285
+ clientId,
286
+ inodeId
287
+ }
288
+ }));
289
+ }
255
290
  async getAllowedIPs() {
256
291
  return (await unwrap(this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }))).allowedIps;
257
292
  }
@@ -371,12 +406,16 @@ var Disk = class {
371
406
  * limits. Returns the entity tag the server assigned (a multipart upload's tag
372
407
  * is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
373
408
  *
409
+ * Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
410
+ * file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
411
+ * sandbox). Defaults are server-side (currently `root:root` mode `0644`).
412
+ *
374
413
  * @param key Path on the disk (e.g. "reports/2026-01/data.json")
375
414
  * @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
376
415
  * @param options Either a content-type string, or {@link PutObjectOptions}
377
416
  * (`contentType`, `multipartThreshold`, `partSize`,
378
- * `concurrency`). Content type defaults to
379
- * "application/octet-stream".
417
+ * `concurrency`, `mode`, `uid`, `gid`). Content type defaults
418
+ * to "application/octet-stream".
380
419
  */
381
420
  async putObject(key, body, options) {
382
421
  const opts = typeof options === "string" ? { contentType: options } : options ?? {};
@@ -387,22 +426,23 @@ var Disk = class {
387
426
  if (bytes.length <= threshold) {
388
427
  const resp = await this._s3Request("PUT", key, {
389
428
  body,
390
- contentType
429
+ contentType,
430
+ extraHeaders: posixCreateHeaders(opts)
391
431
  });
392
432
  if (!resp.ok) throw parseS3Error("PutObject", resp.status, resp.statusText, decodeText(resp.body));
393
433
  return { etag: resp.headers.get("etag") ?? void 0 };
394
434
  }
395
- return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY));
435
+ return this._putMultipart(key, bytes, contentType, partSize, Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY), opts);
396
436
  }
397
437
  /**
398
438
  * Upload a large body through the multipart lifecycle: split into `partSize`
399
439
  * parts, upload them with bounded concurrency, then complete — aborting the
400
440
  * upload if any part fails so nothing is left half-staged. @internal
401
441
  */
402
- async _putMultipart(key, bytes, contentType, partSize, concurrency) {
442
+ async _putMultipart(key, bytes, contentType, partSize, concurrency, attrs = {}) {
403
443
  const effectivePartSize = effectiveUploadPartSize(bytes.length, partSize);
404
444
  const mp = this.multipart;
405
- const upload = await mp.create(key, contentType);
445
+ const upload = await mp.create(key, contentType, attrs);
406
446
  try {
407
447
  const partCount = Math.ceil(bytes.length / effectivePartSize);
408
448
  const parts = new Array(partCount);
@@ -438,16 +478,25 @@ var Disk = class {
438
478
  * would duplicate the bytes. On a transient failure, re-append yourself only
439
479
  * after confirming the object's size.
440
480
  *
441
- * @param key Path on the disk (e.g. "logs/app.log")
442
- * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
443
- * @param contentType MIME type, applied only when the object is newly created.
481
+ * When the object does not yet exist, optional `mode` / `uid` / `gid` set the
482
+ * POSIX attributes of the newly created file (same headers as
483
+ * {@link putObject}); they have no effect on an append to an existing object.
484
+ *
485
+ * @param key Path on the disk (e.g. "logs/app.log")
486
+ * @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
487
+ * @param options Either a content-type string, or {@link AppendObjectOptions}
488
+ * (`contentType`, `mode`, `uid`, `gid`). Content type defaults
489
+ * to "application/octet-stream" and applies only when the
490
+ * object is newly created.
444
491
  */
445
- async appendObject(key, body, contentType = "application/octet-stream") {
492
+ async appendObject(key, body, options) {
493
+ const opts = typeof options === "string" ? { contentType: options } : options ?? {};
446
494
  const resp = await this._s3Request("PUT", key, {
447
495
  body,
448
- contentType,
496
+ contentType: opts.contentType ?? "application/octet-stream",
449
497
  query: { append: "true" },
450
- retry: false
498
+ retry: false,
499
+ extraHeaders: posixCreateHeaders(opts)
451
500
  });
452
501
  if (!resp.ok) throw parseS3Error("AppendObject", resp.status, resp.statusText, decodeText(resp.body));
453
502
  return { etag: resp.headers.get("etag") ?? void 0 };
@@ -613,7 +662,10 @@ var Disk = class {
613
662
  body: opts.body,
614
663
  bodySerializer: (b) => b
615
664
  } : {},
616
- ...opts.contentType ? { headers: { "Content-Type": opts.contentType } } : {}
665
+ ...opts.contentType || opts.extraHeaders ? { headers: {
666
+ ...opts.contentType ? { "Content-Type": opts.contentType } : {},
667
+ ...opts.extraHeaders
668
+ } } : {}
617
669
  };
618
670
  const hasBody = method === "GET" || method === "POST";
619
671
  const maxRetries = opts.retry === false ? 0 : MAX_S3_RETRIES;
@@ -699,11 +751,14 @@ var DiskMultipart = class {
699
751
  *
700
752
  * @param key Path on the disk the finished object will live at.
701
753
  * @param contentType MIME type to store the object with.
754
+ * @param attrs Optional POSIX `mode` / `uid` / `gid` for the completed
755
+ * object (see {@link PosixCreateAttrs}).
702
756
  */
703
- async create(key, contentType) {
757
+ async create(key, contentType, attrs = {}) {
704
758
  const resp = await this.s3Request("POST", key, {
705
759
  query: { uploads: "" },
706
- contentType
760
+ contentType,
761
+ extraHeaders: posixCreateHeaders(attrs)
707
762
  });
708
763
  if (!resp.ok) throw parseS3Error("CreateMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
709
764
  const root = parseXml(decodeText(resp.body)).InitiateMultipartUploadResult ?? {};
@@ -824,6 +879,25 @@ var DiskMultipart = class {
824
879
  return parseListMultipartUploadsResult(decodeText(resp.body));
825
880
  }
826
881
  };
882
+ /**
883
+ * Headers the S3 gateway accepts to set POSIX mode/owner on newly created
884
+ * objects (see fshandler `x-archil-*` PutObject attrs).
885
+ */
886
+ const ARCHIL_MODE_HEADER = "x-archil-mode";
887
+ const ARCHIL_UID_HEADER = "x-archil-uid";
888
+ const ARCHIL_GID_HEADER = "x-archil-gid";
889
+ /**
890
+ * Build the `x-archil-*` headers for {@link PosixCreateAttrs}. `mode` is sent
891
+ * in octal (`0o640` → "640"), matching the gateway's parser and the Python SDK.
892
+ * Returns undefined when no attribute is set, so no headers are added.
893
+ */
894
+ function posixCreateHeaders(attrs) {
895
+ const headers = {};
896
+ if (attrs.mode !== void 0) headers[ARCHIL_MODE_HEADER] = attrs.mode.toString(8);
897
+ if (attrs.uid !== void 0) headers[ARCHIL_UID_HEADER] = String(attrs.uid);
898
+ if (attrs.gid !== void 0) headers[ARCHIL_GID_HEADER] = String(attrs.gid);
899
+ return Object.keys(headers).length > 0 ? headers : void 0;
900
+ }
827
901
  /** S3's per-request cap on DeleteObjects keys; larger inputs are batched. */
828
902
  const MAX_DELETE_OBJECTS_PER_REQUEST = 1e3;
829
903
  /** Automatic retries for a transient S3 failure (5xx / 429 / network error). */
@@ -1203,10 +1277,10 @@ var Workspace = class {
1203
1277
  const { entry, diskKey } = this.route(key);
1204
1278
  return entry.disk.getObject(diskKey);
1205
1279
  }
1206
- async putObject(key, body, contentType) {
1280
+ async putObject(key, body, options) {
1207
1281
  const { entry, diskKey } = this.route(key);
1208
1282
  if (entry.readOnly) throw new Error(`${key} is on a read-only disk and cannot be written.`);
1209
- return entry.disk.putObject(diskKey, body, contentType);
1283
+ return entry.disk.putObject(diskKey, body, options);
1210
1284
  }
1211
1285
  async deleteObject(key) {
1212
1286
  const { entry, diskKey } = this.route(key);
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "disk",
3
- "version": "0.8.20",
3
+ "version": "0.8.22",
4
4
  "description": "Pure-JS client and CLI for Archil disks",
5
+ "keywords": [
6
+ "archil",
7
+ "disk",
8
+ "filesystem",
9
+ "cli"
10
+ ],
11
+ "homepage": "https://archil.com",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "url": "https://github.com/archil-data/archil-sdk"
15
+ },
5
16
  "type": "module",
6
17
  "main": "dist/index.cjs",
7
18
  "module": "dist/index.mjs",
@@ -27,7 +38,7 @@
27
38
  "LICENSE"
28
39
  ],
29
40
  "dependencies": {
30
- "@archildata/api-types": "^0.0.1",
41
+ "@archildata/api-types": "^0.0.4",
31
42
  "commander": "^14.0.3",
32
43
  "fast-xml-parser": "^5.7.0",
33
44
  "openapi-fetch": "^0.13.5",
@@ -42,13 +53,6 @@
42
53
  "engines": {
43
54
  "node": ">= 22"
44
55
  },
45
- "keywords": [
46
- "archil",
47
- "disk",
48
- "filesystem",
49
- "cli"
50
- ],
51
- "license": "MIT",
52
56
  "scripts": {
53
57
  "build": "tsdown",
54
58
  "dev": "tsdown --watch",