@openclaw/fs-safe 0.1.1 → 0.2.0

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 (207) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +58 -2
  3. package/dist/absolute-path.d.ts +14 -0
  4. package/dist/absolute-path.d.ts.map +1 -1
  5. package/dist/absolute-path.js +203 -2
  6. package/dist/advanced.d.ts +2 -1
  7. package/dist/advanced.d.ts.map +1 -1
  8. package/dist/advanced.js +2 -1
  9. package/dist/archive-staging.d.ts.map +1 -1
  10. package/dist/archive-staging.js +81 -7
  11. package/dist/archive.d.ts.map +1 -1
  12. package/dist/archive.js +25 -42
  13. package/dist/bounded-read-stream.d.ts +8 -0
  14. package/dist/bounded-read-stream.d.ts.map +1 -0
  15. package/dist/bounded-read-stream.js +20 -0
  16. package/dist/config.d.ts +1 -0
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js +1 -0
  19. package/dist/directory-guard.d.ts +18 -0
  20. package/dist/directory-guard.d.ts.map +1 -0
  21. package/dist/directory-guard.js +70 -0
  22. package/dist/file-lock.d.ts +4 -2
  23. package/dist/file-lock.d.ts.map +1 -1
  24. package/dist/file-lock.js +13 -2
  25. package/dist/file-store-boundary.d.ts +25 -0
  26. package/dist/file-store-boundary.d.ts.map +1 -0
  27. package/dist/file-store-boundary.js +168 -0
  28. package/dist/file-store-prune.d.ts +12 -0
  29. package/dist/file-store-prune.d.ts.map +1 -0
  30. package/dist/file-store-prune.js +86 -0
  31. package/dist/file-store-source.d.ts +5 -0
  32. package/dist/file-store-source.d.ts.map +1 -0
  33. package/dist/file-store-source.js +30 -0
  34. package/dist/file-store.d.ts +2 -6
  35. package/dist/file-store.d.ts.map +1 -1
  36. package/dist/file-store.js +122 -125
  37. package/dist/guarded-mkdir.d.ts +6 -0
  38. package/dist/guarded-mkdir.d.ts.map +1 -0
  39. package/dist/guarded-mkdir.js +45 -0
  40. package/dist/guarded-mutation.d.ts +33 -0
  41. package/dist/guarded-mutation.d.ts.map +1 -0
  42. package/dist/guarded-mutation.js +76 -0
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +2 -0
  46. package/dist/json-document-store.d.ts +2 -0
  47. package/dist/json-document-store.d.ts.map +1 -1
  48. package/dist/json-document-store.js +7 -3
  49. package/dist/json-durable-queue.d.ts +45 -0
  50. package/dist/json-durable-queue.d.ts.map +1 -0
  51. package/dist/json-durable-queue.js +200 -0
  52. package/dist/json.d.ts +35 -5
  53. package/dist/json.d.ts.map +1 -1
  54. package/dist/json.js +69 -2
  55. package/dist/local-roots.d.ts.map +1 -1
  56. package/dist/local-roots.js +17 -3
  57. package/dist/lock-config.d.ts +10 -0
  58. package/dist/lock-config.d.ts.map +1 -0
  59. package/dist/lock-config.js +12 -0
  60. package/dist/move-path.d.ts +1 -0
  61. package/dist/move-path.d.ts.map +1 -1
  62. package/dist/move-path.js +195 -7
  63. package/dist/output.d.ts +13 -0
  64. package/dist/output.d.ts.map +1 -0
  65. package/dist/output.js +69 -0
  66. package/dist/path-stat.d.ts +4 -0
  67. package/dist/path-stat.d.ts.map +1 -0
  68. package/dist/path-stat.js +15 -0
  69. package/dist/path.d.ts +1 -0
  70. package/dist/path.d.ts.map +1 -1
  71. package/dist/path.js +6 -3
  72. package/dist/pinned-write.d.ts.map +1 -1
  73. package/dist/pinned-write.js +44 -19
  74. package/dist/private-file-store.d.ts +5 -7
  75. package/dist/private-file-store.d.ts.map +1 -1
  76. package/dist/private-file-store.js +21 -34
  77. package/dist/private-temp-workspace.d.ts.map +1 -1
  78. package/dist/private-temp-workspace.js +28 -15
  79. package/dist/regular-file.d.ts.map +1 -1
  80. package/dist/regular-file.js +52 -8
  81. package/dist/replace-directory.d.ts.map +1 -1
  82. package/dist/replace-directory.js +5 -4
  83. package/dist/replace-file.d.ts +1 -1
  84. package/dist/replace-file.d.ts.map +1 -1
  85. package/dist/replace-file.js +93 -31
  86. package/dist/root-context.d.ts +23 -0
  87. package/dist/root-context.d.ts.map +1 -0
  88. package/dist/root-context.js +62 -0
  89. package/dist/root-errors.d.ts +4 -0
  90. package/dist/root-errors.d.ts.map +1 -0
  91. package/dist/root-errors.js +21 -0
  92. package/dist/root-impl.d.ts +108 -0
  93. package/dist/root-impl.d.ts.map +1 -0
  94. package/dist/{safe-root.js → root-impl.js} +484 -265
  95. package/dist/root.d.ts +1 -107
  96. package/dist/root.d.ts.map +1 -1
  97. package/dist/root.js +1 -1332
  98. package/dist/safe-path-segment.d.ts +9 -0
  99. package/dist/safe-path-segment.d.ts.map +1 -0
  100. package/dist/safe-path-segment.js +51 -0
  101. package/dist/secret-file.d.ts.map +1 -1
  102. package/dist/secret-file.js +6 -1
  103. package/dist/sibling-temp.d.ts +1 -0
  104. package/dist/sibling-temp.d.ts.map +1 -1
  105. package/dist/sibling-temp.js +32 -7
  106. package/dist/sidecar-lock.d.ts +2 -0
  107. package/dist/sidecar-lock.d.ts.map +1 -1
  108. package/dist/sidecar-lock.js +93 -13
  109. package/dist/store.d.ts +1 -0
  110. package/dist/store.d.ts.map +1 -1
  111. package/dist/store.js +1 -0
  112. package/dist/temp-target.d.ts.map +1 -1
  113. package/dist/temp-target.js +7 -4
  114. package/dist/test-hooks.d.ts +6 -0
  115. package/dist/test-hooks.d.ts.map +1 -1
  116. package/dist/text-atomic.d.ts +7 -0
  117. package/dist/text-atomic.d.ts.map +1 -1
  118. package/dist/text-atomic.js +3 -2
  119. package/dist/trash.d.ts.map +1 -1
  120. package/dist/trash.js +48 -13
  121. package/docs/advanced.md +110 -0
  122. package/docs/archive.md +199 -0
  123. package/docs/atomic.md +191 -0
  124. package/docs/config.md +94 -0
  125. package/docs/contributing.md +80 -0
  126. package/docs/errors.md +154 -0
  127. package/docs/file-store.md +213 -0
  128. package/docs/filename.md +0 -0
  129. package/docs/index.md +77 -0
  130. package/docs/install-path.md +167 -0
  131. package/docs/install.md +150 -0
  132. package/docs/json-store.md +204 -0
  133. package/docs/json.md +192 -0
  134. package/docs/local-roots.md +164 -0
  135. package/docs/output.md +92 -0
  136. package/docs/path-scope.md +130 -0
  137. package/docs/path.md +191 -0
  138. package/docs/permissions.md +95 -0
  139. package/docs/private-file-store.md +45 -0
  140. package/docs/python-helper.md +103 -0
  141. package/docs/quickstart.md +147 -0
  142. package/docs/reading.md +174 -0
  143. package/docs/regular-file.md +175 -0
  144. package/docs/root.md +205 -0
  145. package/docs/secret-file.md +154 -0
  146. package/docs/secure-file.md +82 -0
  147. package/docs/security-model.md +99 -0
  148. package/docs/sidecar-lock.md +230 -0
  149. package/docs/store.md +77 -0
  150. package/docs/temp.md +284 -0
  151. package/docs/test-hooks.md +74 -0
  152. package/docs/testing.md +178 -0
  153. package/docs/timing.md +121 -0
  154. package/docs/types.md +155 -0
  155. package/docs/walk.md +63 -0
  156. package/docs/writing.md +222 -0
  157. package/package.json +10 -2
  158. package/dist/archive-utils.d.ts +0 -3
  159. package/dist/archive-utils.d.ts.map +0 -1
  160. package/dist/archive-utils.js +0 -26
  161. package/dist/boundary-file-read.d.ts +0 -44
  162. package/dist/boundary-file-read.d.ts.map +0 -1
  163. package/dist/boundary-file-read.js +0 -129
  164. package/dist/boundary-path.d.ts +0 -39
  165. package/dist/boundary-path.d.ts.map +0 -1
  166. package/dist/boundary-path.js +0 -598
  167. package/dist/fs-pinned-path-helper.d.ts +0 -7
  168. package/dist/fs-pinned-path-helper.d.ts.map +0 -1
  169. package/dist/fs-pinned-path-helper.js +0 -182
  170. package/dist/fs-pinned-write-helper.d.ts +0 -21
  171. package/dist/fs-pinned-write-helper.d.ts.map +0 -1
  172. package/dist/fs-pinned-write-helper.js +0 -263
  173. package/dist/hardlink-guards.d.ts +0 -7
  174. package/dist/hardlink-guards.d.ts.map +0 -1
  175. package/dist/hardlink-guards.js +0 -30
  176. package/dist/install-safe-path.d.ts +0 -20
  177. package/dist/install-safe-path.d.ts.map +0 -1
  178. package/dist/install-safe-path.js +0 -94
  179. package/dist/json-file.d.ts +0 -3
  180. package/dist/json-file.d.ts.map +0 -1
  181. package/dist/json-file.js +0 -123
  182. package/dist/json-files.d.ts +0 -20
  183. package/dist/json-files.d.ts.map +0 -1
  184. package/dist/json-files.js +0 -153
  185. package/dist/path-alias-guards.d.ts +0 -19
  186. package/dist/path-alias-guards.d.ts.map +0 -1
  187. package/dist/path-alias-guards.js +0 -21
  188. package/dist/path-guards.d.ts +0 -7
  189. package/dist/path-guards.d.ts.map +0 -1
  190. package/dist/path-guards.js +0 -49
  191. package/dist/path-safety.d.ts +0 -12
  192. package/dist/path-safety.d.ts.map +0 -1
  193. package/dist/path-safety.js +0 -50
  194. package/dist/safe-open-sync.d.ts +0 -24
  195. package/dist/safe-open-sync.d.ts.map +0 -1
  196. package/dist/safe-open-sync.js +0 -71
  197. package/dist/safe-root.d.ts +0 -123
  198. package/dist/safe-root.d.ts.map +0 -1
  199. package/dist/secure-temp-workspace.d.ts +0 -25
  200. package/dist/secure-temp-workspace.d.ts.map +0 -1
  201. package/dist/secure-temp-workspace.js +0 -136
  202. package/dist/sibling-temp-file.d.ts +0 -16
  203. package/dist/sibling-temp-file.d.ts.map +0 -1
  204. package/dist/sibling-temp-file.js +0 -73
  205. package/dist/sibling-temp-write.d.ts +0 -8
  206. package/dist/sibling-temp-write.d.ts.map +0 -1
  207. package/dist/sibling-temp-write.js +0 -40
@@ -1,129 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { resolveBoundaryPath, resolveBoundaryPathSync, } from "./boundary-path.js";
4
- import { openVerifiedFileSync, } from "./safe-open-sync.js";
5
- export function canUseBoundaryFileOpen(ioFs) {
6
- return (typeof ioFs.openSync === "function" &&
7
- typeof ioFs.closeSync === "function" &&
8
- typeof ioFs.fstatSync === "function" &&
9
- typeof ioFs.lstatSync === "function" &&
10
- typeof ioFs.realpathSync === "function" &&
11
- typeof ioFs.readFileSync === "function" &&
12
- typeof ioFs.constants === "object" &&
13
- ioFs.constants !== null);
14
- }
15
- export function openBoundaryFileSync(params) {
16
- const ioFs = params.ioFs ?? fs;
17
- const resolved = resolveBoundaryFilePathGeneric({
18
- absolutePath: params.absolutePath,
19
- resolve: (absolutePath) => resolveBoundaryPathSync({
20
- absolutePath,
21
- rootPath: params.rootPath,
22
- rootCanonicalPath: params.rootRealPath,
23
- boundaryLabel: params.boundaryLabel,
24
- skipLexicalRootCheck: params.skipLexicalRootCheck,
25
- }),
26
- });
27
- if (resolved instanceof Promise) {
28
- return toBoundaryValidationError(new Error("Unexpected async boundary resolution"));
29
- }
30
- return finalizeBoundaryFileOpen({
31
- resolved,
32
- maxBytes: params.maxBytes,
33
- rejectHardlinks: params.rejectHardlinks,
34
- allowedType: params.allowedType,
35
- ioFs,
36
- });
37
- }
38
- export function matchBoundaryFileOpenFailure(failure, handlers) {
39
- switch (failure.reason) {
40
- case "path":
41
- return handlers.path ? handlers.path(failure) : handlers.fallback(failure);
42
- case "validation":
43
- return handlers.validation ? handlers.validation(failure) : handlers.fallback(failure);
44
- case "io":
45
- return handlers.io ? handlers.io(failure) : handlers.fallback(failure);
46
- }
47
- return handlers.fallback(failure);
48
- }
49
- function openBoundaryFileResolved(params) {
50
- const opened = openVerifiedFileSync({
51
- filePath: params.absolutePath,
52
- resolvedPath: params.resolvedPath,
53
- rejectHardlinks: params.rejectHardlinks ?? true,
54
- maxBytes: params.maxBytes,
55
- allowedType: params.allowedType,
56
- ioFs: params.ioFs,
57
- });
58
- if (!opened.ok) {
59
- return opened;
60
- }
61
- return {
62
- ok: true,
63
- path: opened.path,
64
- fd: opened.fd,
65
- stat: opened.stat,
66
- rootRealPath: params.rootRealPath,
67
- };
68
- }
69
- function finalizeBoundaryFileOpen(params) {
70
- if ("ok" in params.resolved) {
71
- return params.resolved;
72
- }
73
- return openBoundaryFileResolved({
74
- absolutePath: params.resolved.absolutePath,
75
- resolvedPath: params.resolved.resolvedPath,
76
- rootRealPath: params.resolved.rootRealPath,
77
- maxBytes: params.maxBytes,
78
- rejectHardlinks: params.rejectHardlinks,
79
- allowedType: params.allowedType,
80
- ioFs: params.ioFs,
81
- });
82
- }
83
- export async function openBoundaryFile(params) {
84
- const ioFs = params.ioFs ?? fs;
85
- const maybeResolved = resolveBoundaryFilePathGeneric({
86
- absolutePath: params.absolutePath,
87
- resolve: (absolutePath) => resolveBoundaryPath({
88
- absolutePath,
89
- rootPath: params.rootPath,
90
- rootCanonicalPath: params.rootRealPath,
91
- boundaryLabel: params.boundaryLabel,
92
- policy: params.aliasPolicy,
93
- skipLexicalRootCheck: params.skipLexicalRootCheck,
94
- }),
95
- });
96
- const resolved = maybeResolved instanceof Promise ? await maybeResolved : maybeResolved;
97
- return finalizeBoundaryFileOpen({
98
- resolved,
99
- maxBytes: params.maxBytes,
100
- rejectHardlinks: params.rejectHardlinks,
101
- allowedType: params.allowedType,
102
- ioFs,
103
- });
104
- }
105
- function toBoundaryValidationError(error) {
106
- return { ok: false, reason: "validation", error };
107
- }
108
- function mapResolvedBoundaryPath(absolutePath, resolved) {
109
- return {
110
- absolutePath,
111
- resolvedPath: resolved.canonicalPath,
112
- rootRealPath: resolved.rootCanonicalPath,
113
- };
114
- }
115
- function resolveBoundaryFilePathGeneric(params) {
116
- const absolutePath = path.resolve(params.absolutePath);
117
- try {
118
- const resolved = params.resolve(absolutePath);
119
- if (resolved instanceof Promise) {
120
- return resolved
121
- .then((value) => mapResolvedBoundaryPath(absolutePath, value))
122
- .catch((error) => toBoundaryValidationError(error));
123
- }
124
- return mapResolvedBoundaryPath(absolutePath, resolved);
125
- }
126
- catch (error) {
127
- return toBoundaryValidationError(error);
128
- }
129
- }
@@ -1,39 +0,0 @@
1
- type BoundaryPathIntent = "read" | "write" | "create" | "delete" | "stat";
2
- export type BoundaryPathAliasPolicy = {
3
- allowFinalSymlinkForUnlink?: boolean;
4
- allowFinalHardlinkForUnlink?: boolean;
5
- };
6
- export declare const BOUNDARY_PATH_ALIAS_POLICIES: {
7
- readonly strict: Readonly<{
8
- allowFinalSymlinkForUnlink: false;
9
- allowFinalHardlinkForUnlink: false;
10
- }>;
11
- readonly unlinkTarget: Readonly<{
12
- allowFinalSymlinkForUnlink: true;
13
- allowFinalHardlinkForUnlink: true;
14
- }>;
15
- };
16
- type ResolveBoundaryPathParams = {
17
- absolutePath: string;
18
- rootPath: string;
19
- boundaryLabel: string;
20
- intent?: BoundaryPathIntent;
21
- policy?: BoundaryPathAliasPolicy;
22
- skipLexicalRootCheck?: boolean;
23
- rootCanonicalPath?: string;
24
- };
25
- type ResolvedBoundaryPathKind = "missing" | "file" | "directory" | "symlink" | "other";
26
- export type ResolvedBoundaryPath = {
27
- absolutePath: string;
28
- canonicalPath: string;
29
- rootPath: string;
30
- rootCanonicalPath: string;
31
- relativePath: string;
32
- exists: boolean;
33
- kind: ResolvedBoundaryPathKind;
34
- };
35
- export declare function resolveBoundaryPath(params: ResolveBoundaryPathParams): Promise<ResolvedBoundaryPath>;
36
- export declare function resolveBoundaryPathSync(params: ResolveBoundaryPathParams): ResolvedBoundaryPath;
37
- export declare function resolvePathViaExistingAncestorSync(targetPath: string): string;
38
- export {};
39
- //# sourceMappingURL=boundary-path.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"boundary-path.d.ts","sourceRoot":"","sources":["../src/boundary-path.ts"],"names":[],"mappings":"AAMA,KAAK,kBAAkB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1E,MAAM,MAAM,uBAAuB,GAAG;IACpC,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC,CAAC;AAEF,eAAO,MAAM,4BAA4B;;;;;;;;;CAS/B,CAAC;AAEX,KAAK,yBAAyB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,KAAK,wBAAwB,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAEvF,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,wBAAwB,CAAC;CAChC,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,oBAAoB,CAAC,CA+B/B;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,yBAAyB,GAAG,oBAAoB,CA+B/F;AAmkBD,wBAAgB,kCAAkC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA6B7E"}