@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.
- package/CHANGELOG.md +58 -0
- package/README.md +58 -2
- package/dist/absolute-path.d.ts +14 -0
- package/dist/absolute-path.d.ts.map +1 -1
- package/dist/absolute-path.js +203 -2
- package/dist/advanced.d.ts +2 -1
- package/dist/advanced.d.ts.map +1 -1
- package/dist/advanced.js +2 -1
- package/dist/archive-staging.d.ts.map +1 -1
- package/dist/archive-staging.js +81 -7
- package/dist/archive.d.ts.map +1 -1
- package/dist/archive.js +25 -42
- package/dist/bounded-read-stream.d.ts +8 -0
- package/dist/bounded-read-stream.d.ts.map +1 -0
- package/dist/bounded-read-stream.js +20 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/directory-guard.d.ts +18 -0
- package/dist/directory-guard.d.ts.map +1 -0
- package/dist/directory-guard.js +70 -0
- package/dist/file-lock.d.ts +4 -2
- package/dist/file-lock.d.ts.map +1 -1
- package/dist/file-lock.js +13 -2
- package/dist/file-store-boundary.d.ts +25 -0
- package/dist/file-store-boundary.d.ts.map +1 -0
- package/dist/file-store-boundary.js +168 -0
- package/dist/file-store-prune.d.ts +12 -0
- package/dist/file-store-prune.d.ts.map +1 -0
- package/dist/file-store-prune.js +86 -0
- package/dist/file-store-source.d.ts +5 -0
- package/dist/file-store-source.d.ts.map +1 -0
- package/dist/file-store-source.js +30 -0
- package/dist/file-store.d.ts +2 -6
- package/dist/file-store.d.ts.map +1 -1
- package/dist/file-store.js +122 -125
- package/dist/guarded-mkdir.d.ts +6 -0
- package/dist/guarded-mkdir.d.ts.map +1 -0
- package/dist/guarded-mkdir.js +45 -0
- package/dist/guarded-mutation.d.ts +33 -0
- package/dist/guarded-mutation.d.ts.map +1 -0
- package/dist/guarded-mutation.js +76 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/json-document-store.d.ts +2 -0
- package/dist/json-document-store.d.ts.map +1 -1
- package/dist/json-document-store.js +7 -3
- package/dist/json-durable-queue.d.ts +45 -0
- package/dist/json-durable-queue.d.ts.map +1 -0
- package/dist/json-durable-queue.js +200 -0
- package/dist/json.d.ts +35 -5
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +69 -2
- package/dist/local-roots.d.ts.map +1 -1
- package/dist/local-roots.js +17 -3
- package/dist/lock-config.d.ts +10 -0
- package/dist/lock-config.d.ts.map +1 -0
- package/dist/lock-config.js +12 -0
- package/dist/move-path.d.ts +1 -0
- package/dist/move-path.d.ts.map +1 -1
- package/dist/move-path.js +195 -7
- package/dist/output.d.ts +13 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +69 -0
- package/dist/path-stat.d.ts +4 -0
- package/dist/path-stat.d.ts.map +1 -0
- package/dist/path-stat.js +15 -0
- package/dist/path.d.ts +1 -0
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +6 -3
- package/dist/pinned-write.d.ts.map +1 -1
- package/dist/pinned-write.js +44 -19
- package/dist/private-file-store.d.ts +5 -7
- package/dist/private-file-store.d.ts.map +1 -1
- package/dist/private-file-store.js +21 -34
- package/dist/private-temp-workspace.d.ts.map +1 -1
- package/dist/private-temp-workspace.js +28 -15
- package/dist/regular-file.d.ts.map +1 -1
- package/dist/regular-file.js +52 -8
- package/dist/replace-directory.d.ts.map +1 -1
- package/dist/replace-directory.js +5 -4
- package/dist/replace-file.d.ts +1 -1
- package/dist/replace-file.d.ts.map +1 -1
- package/dist/replace-file.js +93 -31
- package/dist/root-context.d.ts +23 -0
- package/dist/root-context.d.ts.map +1 -0
- package/dist/root-context.js +62 -0
- package/dist/root-errors.d.ts +4 -0
- package/dist/root-errors.d.ts.map +1 -0
- package/dist/root-errors.js +21 -0
- package/dist/root-impl.d.ts +108 -0
- package/dist/root-impl.d.ts.map +1 -0
- package/dist/{safe-root.js → root-impl.js} +484 -265
- package/dist/root.d.ts +1 -107
- package/dist/root.d.ts.map +1 -1
- package/dist/root.js +1 -1332
- package/dist/safe-path-segment.d.ts +9 -0
- package/dist/safe-path-segment.d.ts.map +1 -0
- package/dist/safe-path-segment.js +51 -0
- package/dist/secret-file.d.ts.map +1 -1
- package/dist/secret-file.js +6 -1
- package/dist/sibling-temp.d.ts +1 -0
- package/dist/sibling-temp.d.ts.map +1 -1
- package/dist/sibling-temp.js +32 -7
- package/dist/sidecar-lock.d.ts +2 -0
- package/dist/sidecar-lock.d.ts.map +1 -1
- package/dist/sidecar-lock.js +93 -13
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +1 -0
- package/dist/temp-target.d.ts.map +1 -1
- package/dist/temp-target.js +7 -4
- package/dist/test-hooks.d.ts +6 -0
- package/dist/test-hooks.d.ts.map +1 -1
- package/dist/text-atomic.d.ts +7 -0
- package/dist/text-atomic.d.ts.map +1 -1
- package/dist/text-atomic.js +3 -2
- package/dist/trash.d.ts.map +1 -1
- package/dist/trash.js +48 -13
- package/docs/advanced.md +110 -0
- package/docs/archive.md +199 -0
- package/docs/atomic.md +191 -0
- package/docs/config.md +94 -0
- package/docs/contributing.md +80 -0
- package/docs/errors.md +154 -0
- package/docs/file-store.md +213 -0
- package/docs/filename.md +0 -0
- package/docs/index.md +77 -0
- package/docs/install-path.md +167 -0
- package/docs/install.md +150 -0
- package/docs/json-store.md +204 -0
- package/docs/json.md +192 -0
- package/docs/local-roots.md +164 -0
- package/docs/output.md +92 -0
- package/docs/path-scope.md +130 -0
- package/docs/path.md +191 -0
- package/docs/permissions.md +95 -0
- package/docs/private-file-store.md +45 -0
- package/docs/python-helper.md +103 -0
- package/docs/quickstart.md +147 -0
- package/docs/reading.md +174 -0
- package/docs/regular-file.md +175 -0
- package/docs/root.md +205 -0
- package/docs/secret-file.md +154 -0
- package/docs/secure-file.md +82 -0
- package/docs/security-model.md +99 -0
- package/docs/sidecar-lock.md +230 -0
- package/docs/store.md +77 -0
- package/docs/temp.md +284 -0
- package/docs/test-hooks.md +74 -0
- package/docs/testing.md +178 -0
- package/docs/timing.md +121 -0
- package/docs/types.md +155 -0
- package/docs/walk.md +63 -0
- package/docs/writing.md +222 -0
- package/package.json +10 -2
- package/dist/archive-utils.d.ts +0 -3
- package/dist/archive-utils.d.ts.map +0 -1
- package/dist/archive-utils.js +0 -26
- package/dist/boundary-file-read.d.ts +0 -44
- package/dist/boundary-file-read.d.ts.map +0 -1
- package/dist/boundary-file-read.js +0 -129
- package/dist/boundary-path.d.ts +0 -39
- package/dist/boundary-path.d.ts.map +0 -1
- package/dist/boundary-path.js +0 -598
- package/dist/fs-pinned-path-helper.d.ts +0 -7
- package/dist/fs-pinned-path-helper.d.ts.map +0 -1
- package/dist/fs-pinned-path-helper.js +0 -182
- package/dist/fs-pinned-write-helper.d.ts +0 -21
- package/dist/fs-pinned-write-helper.d.ts.map +0 -1
- package/dist/fs-pinned-write-helper.js +0 -263
- package/dist/hardlink-guards.d.ts +0 -7
- package/dist/hardlink-guards.d.ts.map +0 -1
- package/dist/hardlink-guards.js +0 -30
- package/dist/install-safe-path.d.ts +0 -20
- package/dist/install-safe-path.d.ts.map +0 -1
- package/dist/install-safe-path.js +0 -94
- package/dist/json-file.d.ts +0 -3
- package/dist/json-file.d.ts.map +0 -1
- package/dist/json-file.js +0 -123
- package/dist/json-files.d.ts +0 -20
- package/dist/json-files.d.ts.map +0 -1
- package/dist/json-files.js +0 -153
- package/dist/path-alias-guards.d.ts +0 -19
- package/dist/path-alias-guards.d.ts.map +0 -1
- package/dist/path-alias-guards.js +0 -21
- package/dist/path-guards.d.ts +0 -7
- package/dist/path-guards.d.ts.map +0 -1
- package/dist/path-guards.js +0 -49
- package/dist/path-safety.d.ts +0 -12
- package/dist/path-safety.d.ts.map +0 -1
- package/dist/path-safety.js +0 -50
- package/dist/safe-open-sync.d.ts +0 -24
- package/dist/safe-open-sync.d.ts.map +0 -1
- package/dist/safe-open-sync.js +0 -71
- package/dist/safe-root.d.ts +0 -123
- package/dist/safe-root.d.ts.map +0 -1
- package/dist/secure-temp-workspace.d.ts +0 -25
- package/dist/secure-temp-workspace.d.ts.map +0 -1
- package/dist/secure-temp-workspace.js +0 -136
- package/dist/sibling-temp-file.d.ts +0 -16
- package/dist/sibling-temp-file.d.ts.map +0 -1
- package/dist/sibling-temp-file.js +0 -73
- package/dist/sibling-temp-write.d.ts +0 -8
- package/dist/sibling-temp-write.d.ts.map +0 -1
- 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
|
-
}
|
package/dist/boundary-path.d.ts
DELETED
|
@@ -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"}
|