@openclaw/fs-safe 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +1 -1
  3. package/dist/advanced.d.ts +2 -2
  4. package/dist/advanced.d.ts.map +1 -1
  5. package/dist/advanced.js +2 -2
  6. package/dist/archive-kind.d.ts +1 -0
  7. package/dist/archive-kind.d.ts.map +1 -1
  8. package/dist/archive-kind.js +6 -0
  9. package/dist/archive-limits.d.ts +0 -1
  10. package/dist/archive-limits.d.ts.map +1 -1
  11. package/dist/archive-limits.js +0 -3
  12. package/dist/archive-native.d.ts.map +1 -1
  13. package/dist/archive-native.js +5 -8
  14. package/dist/archive-parser-errors.d.ts +2 -0
  15. package/dist/archive-parser-errors.d.ts.map +1 -0
  16. package/dist/archive-parser-errors.js +12 -0
  17. package/dist/archive-read.d.ts.map +1 -1
  18. package/dist/archive-read.js +7 -13
  19. package/dist/archive-tar-wasm.d.ts +1 -1
  20. package/dist/archive-tar-wasm.d.ts.map +1 -1
  21. package/dist/archive-tar-wasm.js +5 -8
  22. package/dist/archive.d.ts.map +1 -1
  23. package/dist/archive.js +43 -6
  24. package/dist/atomic.d.ts +1 -1
  25. package/dist/atomic.d.ts.map +1 -1
  26. package/dist/atomic.js +1 -1
  27. package/dist/bounded-read-stream.d.ts +1 -5
  28. package/dist/bounded-read-stream.d.ts.map +1 -1
  29. package/dist/bounded-read-stream.js +5 -13
  30. package/dist/byte-budget.d.ts +0 -1
  31. package/dist/byte-budget.d.ts.map +1 -1
  32. package/dist/byte-budget.js +1 -1
  33. package/dist/directory-mode-owner.d.ts.map +1 -1
  34. package/dist/directory-mode-owner.js +2 -0
  35. package/dist/error-detail.d.ts +1 -0
  36. package/dist/error-detail.d.ts.map +1 -1
  37. package/dist/error-detail.js +6 -0
  38. package/dist/file-store-boundary.d.ts +1 -1
  39. package/dist/file-store-boundary.d.ts.map +1 -1
  40. package/dist/file-store-boundary.js +2 -13
  41. package/dist/file-store.js +1 -1
  42. package/dist/file-sync.d.ts +5 -0
  43. package/dist/file-sync.d.ts.map +1 -0
  44. package/dist/file-sync.js +19 -0
  45. package/dist/guarded-mutation.d.ts +3 -0
  46. package/dist/guarded-mutation.d.ts.map +1 -1
  47. package/dist/guarded-mutation.js +5 -1
  48. package/dist/home-dir.d.ts +0 -10
  49. package/dist/home-dir.d.ts.map +1 -1
  50. package/dist/home-dir.js +0 -28
  51. package/dist/json-durable-queue-ownership.d.ts +1 -0
  52. package/dist/json-durable-queue-ownership.d.ts.map +1 -1
  53. package/dist/json-durable-queue-ownership.js +139 -18
  54. package/dist/json-durable-queue.d.ts.map +1 -1
  55. package/dist/json-durable-queue.js +5 -10
  56. package/dist/json-store.d.ts.map +1 -1
  57. package/dist/json-store.js +1 -1
  58. package/dist/local-roots.d.ts.map +1 -1
  59. package/dist/local-roots.js +2 -3
  60. package/dist/move-path-cleanup.d.ts +1 -1
  61. package/dist/move-path-cleanup.d.ts.map +1 -1
  62. package/dist/move-path-cleanup.js +4 -2
  63. package/dist/move-path.d.ts +9 -0
  64. package/dist/move-path.d.ts.map +1 -1
  65. package/dist/move-path.js +53 -16
  66. package/dist/native-operations.d.ts +0 -1
  67. package/dist/native-operations.d.ts.map +1 -1
  68. package/dist/native-operations.js +0 -10
  69. package/dist/native-pinned-write-windows.d.ts.map +1 -1
  70. package/dist/native-pinned-write-windows.js +5 -4
  71. package/dist/native-staged-file.d.ts +8 -1
  72. package/dist/native-staged-file.d.ts.map +1 -1
  73. package/dist/native-staged-file.js +30 -9
  74. package/dist/opened-realpath.d.ts +12 -1
  75. package/dist/opened-realpath.d.ts.map +1 -1
  76. package/dist/opened-realpath.js +8 -7
  77. package/dist/output.d.ts.map +1 -1
  78. package/dist/output.js +26 -2
  79. package/dist/path-policy.js +1 -1
  80. package/dist/permissions.d.ts +1 -0
  81. package/dist/permissions.d.ts.map +1 -1
  82. package/dist/permissions.js +3 -0
  83. package/dist/pinned-write.d.ts +1 -2
  84. package/dist/pinned-write.d.ts.map +1 -1
  85. package/dist/pinned-write.js +2 -11
  86. package/dist/private-temp-workspace.js +1 -1
  87. package/dist/publish-file.js +2 -2
  88. package/dist/replace-file-copy-source.d.ts.map +1 -1
  89. package/dist/replace-file-copy-source.js +2 -7
  90. package/dist/replace-file-descriptor.d.ts.map +1 -1
  91. package/dist/replace-file-descriptor.js +3 -16
  92. package/dist/replace-file-temp-owner.d.ts.map +1 -1
  93. package/dist/replace-file-temp-owner.js +2 -7
  94. package/dist/replace-file.d.ts.map +1 -1
  95. package/dist/replace-file.js +21 -8
  96. package/dist/root-errors.d.ts +1 -0
  97. package/dist/root-errors.d.ts.map +1 -1
  98. package/dist/root-errors.js +9 -0
  99. package/dist/root-file.d.ts.map +1 -1
  100. package/dist/root-file.js +17 -28
  101. package/dist/root-impl.d.ts.map +1 -1
  102. package/dist/root-impl.js +12 -33
  103. package/dist/root-path.d.ts.map +1 -1
  104. package/dist/root-path.js +49 -94
  105. package/dist/root-write-mode.d.ts +6 -0
  106. package/dist/root-write-mode.d.ts.map +1 -0
  107. package/dist/root-write-mode.js +60 -0
  108. package/dist/root-write-verification.js +2 -2
  109. package/dist/safe-path-segment.d.ts +1 -0
  110. package/dist/safe-path-segment.d.ts.map +1 -1
  111. package/dist/safe-path-segment.js +1 -1
  112. package/dist/secret-file.d.ts.map +1 -1
  113. package/dist/secret-file.js +2 -9
  114. package/dist/secret-read-async.d.ts.map +1 -1
  115. package/dist/secret-read-async.js +2 -10
  116. package/dist/secret-read-policy.d.ts +4 -0
  117. package/dist/secret-read-policy.d.ts.map +1 -1
  118. package/dist/secret-read-policy.js +12 -0
  119. package/dist/sibling-staged-file.d.ts.map +1 -1
  120. package/dist/sibling-staged-file.js +2 -7
  121. package/dist/sidecar-lock-policy.d.ts +0 -1
  122. package/dist/sidecar-lock-policy.d.ts.map +1 -1
  123. package/dist/sidecar-lock-policy.js +0 -4
  124. package/dist/string-coerce.d.ts +0 -9
  125. package/dist/string-coerce.d.ts.map +1 -1
  126. package/dist/string-coerce.js +0 -56
  127. package/dist/temp-target.d.ts.map +1 -1
  128. package/dist/temp-target.js +1 -12
  129. package/docs/atomic.md +53 -19
  130. package/docs/staged-file.md +6 -2
  131. package/docs/writing.md +5 -0
  132. package/package.json +8 -8
  133. package/dist/archive-tar-extract.d.ts +0 -11
  134. package/dist/archive-tar-extract.d.ts.map +0 -1
  135. package/dist/archive-tar-extract.js +0 -49
  136. package/dist/fsync.d.ts +0 -2
  137. package/dist/fsync.d.ts.map +0 -1
  138. package/dist/fsync.js +0 -1
  139. package/dist/json-durable-queue-retirement.d.ts +0 -9
  140. package/dist/json-durable-queue-retirement.d.ts.map +0 -1
  141. package/dist/json-durable-queue-retirement.js +0 -126
  142. package/dist/json-durable-queue-transfer-lock.d.ts +0 -2
  143. package/dist/json-durable-queue-transfer-lock.d.ts.map +0 -1
  144. package/dist/json-durable-queue-transfer-lock.js +0 -19
  145. package/dist/mode.d.ts +0 -2
  146. package/dist/mode.d.ts.map +0 -1
  147. package/dist/mode.js +0 -3
  148. package/dist/output-sibling.d.ts +0 -8
  149. package/dist/output-sibling.d.ts.map +0 -1
  150. package/dist/output-sibling.js +0 -30
  151. package/dist/read-error.d.ts +0 -2
  152. package/dist/read-error.d.ts.map +0 -1
  153. package/dist/read-error.js +0 -11
  154. package/dist/short-path.d.ts +0 -2
  155. package/dist/short-path.d.ts.map +0 -1
  156. package/dist/short-path.js +0 -7
  157. package/dist/staged-file.d.ts +0 -10
  158. package/dist/staged-file.d.ts.map +0 -1
  159. package/dist/staged-file.js +0 -15
@@ -1,19 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import path from "node:path";
3
- import { sha256Hex } from "./file-identity.js";
4
- import { withSidecarLock } from "./sidecar-lock.js";
5
- export async function withQueueTransferLock(filePath, run) {
6
- const lockPath = path.join(path.dirname(filePath), `.fs-safe-transfer-${sha256Hex(path.basename(filePath)).slice(0, 32)}.lock`);
7
- return await withSidecarLock(filePath, {
8
- managerKey: "fs-safe.queue-transfer",
9
- lockPath,
10
- staleMs: 30_000,
11
- staleRecovery: "fail-closed",
12
- timeoutMs: 45_000,
13
- payload: () => ({
14
- ownerToken: randomUUID(),
15
- createdAt: new Date().toISOString(),
16
- }),
17
- retry: { retries: 180, minTimeout: 25, maxTimeout: 250, factor: 1.1 },
18
- }, run);
19
- }
package/dist/mode.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function formatPosixMode(mode: number): string;
2
- //# sourceMappingURL=mode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mode.d.ts","sourceRoot":"","sources":["../src/mode.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
package/dist/mode.js DELETED
@@ -1,3 +0,0 @@
1
- export function formatPosixMode(mode) {
2
- return (mode & 0o777).toString(8).padStart(3, "0");
3
- }
@@ -1,8 +0,0 @@
1
- export declare function writeExternalFileViaSibling<T>(params: {
2
- finalPath: string;
3
- write: (filePath: string) => Promise<T>;
4
- fallbackFileName?: string;
5
- maxBytes?: number;
6
- mode?: number;
7
- }): Promise<T>;
8
- //# sourceMappingURL=output-sibling.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-sibling.d.ts","sourceRoot":"","sources":["../src/output-sibling.ts"],"names":[],"mappings":"AAuBA,wBAAsB,2BAA2B,CAAC,CAAC,EAAE,MAAM,EAAE;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,CAAC,CAAC,CAYb"}
@@ -1,30 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import path from "node:path";
3
- import { fitFileNameToPortableComponent, sanitizeUntrustedFileName } from "./filename.js";
4
- import { writeCallbackSibling } from "./sibling-staged-file.js";
5
- function safeFallbackFileName(fallbackFileName) {
6
- return sanitizeUntrustedFileName(fallbackFileName ?? "output.bin", "output.bin");
7
- }
8
- function buildSiblingTempPath(targetPath, fallbackFileName) {
9
- const prefix = `.fs-safe-output-${process.pid}-${randomUUID()}-`;
10
- const suffix = ".part";
11
- const safeTail = fitFileNameToPortableComponent({
12
- prefix,
13
- fileName: sanitizeUntrustedFileName(path.basename(targetPath), safeFallbackFileName(fallbackFileName)),
14
- suffix,
15
- });
16
- return path.join(path.dirname(targetPath), `${prefix}${safeTail}${suffix}`);
17
- }
18
- export async function writeExternalFileViaSibling(params) {
19
- const finalPath = path.resolve(params.finalPath);
20
- const { result } = await writeCallbackSibling({
21
- tempPath: buildSiblingTempPath(finalPath, params.fallbackFileName),
22
- write: params.write,
23
- resolveFinalPath: () => finalPath,
24
- mode: params.mode,
25
- maxBytes: params.maxBytes,
26
- syncTempFile: true,
27
- syncParentDir: true,
28
- });
29
- return result;
30
- }
@@ -1,2 +0,0 @@
1
- export declare function throwFsSafeReadError(error: unknown, label: string): never;
2
- //# sourceMappingURL=read-error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"read-error.d.ts","sourceRoot":"","sources":["../src/read-error.ts"],"names":[],"mappings":"AAGA,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAQzE"}
@@ -1,11 +0,0 @@
1
- import { FsSafeError } from "./errors.js";
2
- import { isNodeError } from "./path.js";
3
- export function throwFsSafeReadError(error, label) {
4
- if (error instanceof FsSafeError) {
5
- throw error;
6
- }
7
- if (isNodeError(error)) {
8
- throw new FsSafeError("read-failed", `${label} target could not be read`, { cause: error });
9
- }
10
- throw error;
11
- }
@@ -1,2 +0,0 @@
1
- export declare function shortPath(value: string): string;
2
- //# sourceMappingURL=short-path.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"short-path.d.ts","sourceRoot":"","sources":["../src/short-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI/C"}
@@ -1,7 +0,0 @@
1
- import os from "node:os";
2
- import { formatErrorDetail } from "./error-detail.js";
3
- export function shortPath(value) {
4
- const home = os.homedir();
5
- const shortened = value.startsWith(home) ? `~${value.slice(home.length)}` : value;
6
- return formatErrorDetail(shortened);
7
- }
@@ -1,10 +0,0 @@
1
- import type { DirectoryReceipt } from "./directory-durability.js";
2
- import type { StagedFile } from "./staged-file-types.js";
3
- export type { PublishedFileReceipt, StagedFile, StagedFileCleanupReceipt, StagedFileFailureDetails, StagedFilePublication, StagedFileReceipt, } from "./staged-file-types.js";
4
- export declare function stageFileInDirectory(options: {
5
- directory: string | DirectoryReceipt;
6
- content: string | Uint8Array;
7
- /** Published mode; the unpublished stage stays at 0600. Defaults to 0600. */
8
- mode?: number;
9
- }): Promise<StagedFile>;
10
- //# sourceMappingURL=staged-file.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"staged-file.d.ts","sourceRoot":"","sources":["../src/staged-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAKlE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,YAAY,EACV,oBAAoB,EAAE,UAAU,EAAE,wBAAwB,EAAE,wBAAwB,EACpF,qBAAqB,EAAE,iBAAiB,GACzC,MAAM,wBAAwB,CAAC;AAEhC,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACrC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,UAAU,CAAC,CAUtB"}
@@ -1,15 +0,0 @@
1
- import { FsSafeError } from "./errors.js";
2
- import { assertNativeStaging, createNativeStage } from "./native-staged-file.js";
3
- import { requireNativeBinding } from "./native.js";
4
- import { openStagedDirectory } from "./staged-directory.js";
5
- export async function stageFileInDirectory(options) {
6
- if (process.platform !== "linux" && process.platform !== "darwin") {
7
- throw new FsSafeError("unsupported-platform", "retained-directory staging requires Linux or macOS");
8
- }
9
- const binding = requireNativeBinding();
10
- assertNativeStaging(binding);
11
- const input = { kind: "buffer", data: Buffer.from(options.content) };
12
- const mode = options.mode ?? 0o600;
13
- const parent = openStagedDirectory(options.directory);
14
- return await createNativeStage(binding, parent.fd, parent.receipt, input, mode);
15
- }