@hamak/shared-utils 0.9.0 → 0.9.1
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.
|
@@ -12,6 +12,44 @@ export interface FileMemoState {
|
|
|
12
12
|
originalContent: Holder;
|
|
13
13
|
modified: boolean;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Client-side, UI-facing capabilities for a filesystem node.
|
|
17
|
+
*
|
|
18
|
+
* All fields optional — a provider specifies only what it needs (e.g.
|
|
19
|
+
* `{ write: false }`); the rest fall back to their defaults via
|
|
20
|
+
* {@link resolveNodePermissions} / {@link resolvePermissions}. When
|
|
21
|
+
* `state.permissions` is entirely absent the node is fully permissive (rwx),
|
|
22
|
+
* so existing nodes behave exactly as before.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: this is NOT a security boundary. It mirrors the source's real ACL so
|
|
25
|
+
* the UI can reflect what's allowed without a round-trip; server-side
|
|
26
|
+
* authorization still enforces for real.
|
|
27
|
+
*/
|
|
28
|
+
export interface FileSystemNodePermissions {
|
|
29
|
+
/** May the content be read/loaded. Default: true. */
|
|
30
|
+
read?: boolean;
|
|
31
|
+
/** May the content be edited (updateFileContent / setFileContent !fromRemote). Default: true. */
|
|
32
|
+
write?: boolean;
|
|
33
|
+
/** May the node be removed. Default: = write. */
|
|
34
|
+
remove?: boolean;
|
|
35
|
+
/** May the node be renamed / moved. Default: = write. */
|
|
36
|
+
rename?: boolean;
|
|
37
|
+
/** (directories) may children be created. Default: = write. */
|
|
38
|
+
createChildren?: boolean;
|
|
39
|
+
/** Human-facing reason surfaced in the UI ("Computed listing — read-only"). */
|
|
40
|
+
reason?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Fully-resolved permissions: every capability decided, `reason` optional.
|
|
44
|
+
*/
|
|
45
|
+
export interface ResolvedFileSystemNodePermissions {
|
|
46
|
+
read: boolean;
|
|
47
|
+
write: boolean;
|
|
48
|
+
remove: boolean;
|
|
49
|
+
rename: boolean;
|
|
50
|
+
createChildren: boolean;
|
|
51
|
+
reason?: string;
|
|
52
|
+
}
|
|
15
53
|
export interface FileSystemNodeState {
|
|
16
54
|
contentLoaded: boolean;
|
|
17
55
|
contentLoading: boolean;
|
|
@@ -20,10 +58,31 @@ export interface FileSystemNodeState {
|
|
|
20
58
|
message?: string;
|
|
21
59
|
};
|
|
22
60
|
memo?: FileMemoState;
|
|
61
|
+
/** Client-side capabilities. Absent = fully permissive (rwx). */
|
|
62
|
+
permissions?: FileSystemNodePermissions;
|
|
23
63
|
contentHistory: any[];
|
|
24
64
|
extensionStates: Record<string, unknown>;
|
|
25
65
|
}
|
|
26
66
|
export declare function fileSystemNodeInitialState(contentPresent?: boolean): FileSystemNodeState;
|
|
67
|
+
/**
|
|
68
|
+
* Fold a partial permissions object into fully-resolved capabilities, applying
|
|
69
|
+
* defaults: `read`/`write` default true, and `remove`/`rename`/`createChildren`
|
|
70
|
+
* default to the resolved `write` value. Node-local (no inheritance).
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveNodePermissions(perms?: FileSystemNodePermissions): ResolvedFileSystemNodePermissions;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve permissions for a node at `path` with directory inheritance.
|
|
75
|
+
*
|
|
76
|
+
* Walks root → target, folding each ancestor's explicitly-set capabilities;
|
|
77
|
+
* a child overrides its ancestors per-field (a read-only directory therefore
|
|
78
|
+
* makes descendants read-only unless a child sets `write: true`). Undefined
|
|
79
|
+
* fields fall through to defaults (see {@link resolveNodePermissions}).
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolvePermissions(root: FileSystemNode | undefined, path: Path): ResolvedFileSystemNodePermissions;
|
|
82
|
+
/** Node-local writability (no inheritance). Absent permissions ⇒ writable. */
|
|
83
|
+
export declare function isWritable(node: FileSystemNode | undefined): boolean;
|
|
84
|
+
/** Node-local read-only check (no inheritance). Inverse of {@link isWritable}. */
|
|
85
|
+
export declare function isReadOnly(node: FileSystemNode | undefined): boolean;
|
|
27
86
|
export interface FileSystemNodeBase {
|
|
28
87
|
type: 'directory' | 'file';
|
|
29
88
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-utils-filesystem.d.ts","sourceRoot":"","sources":["../src/core-utils-filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,YAAY,EAAE,MAAM,CAAgB;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpG,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,OAAO,CAAA;IACtB,cAAc,EAAE,OAAO,CAAA;IACvB,gBAAgB,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACtD,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,cAAc,EAAE,GAAG,EAAE,CAAA;IAErB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACzC;AAGD,wBAAgB,0BAA0B,CAAC,cAAc,UAAO,GAAG,mBAAmB,CAQrF;AAGD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,mBAAmB,CAAA;CAC3B;AAGD,MAAM,WAAW,aAAc,SAAQ,kBAAkB;IACvD,IAAI,EAAE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G,SAAS,GAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS;IAI3E,WAAW,CAAC,GAAG,EAAG,cAAc,GAAG,SAAS,GAAI,aAAa,GAAG,SAAS;IAGzE,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,EAAE,IAAI,EAAG,IAAI,GAAI,cAAc,GAAG,SAAS;IAKhG;;;;;;;OAOG;IACH,gBAAgB,CACd,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,GAAG,EACZ,MAAM,SAAW,EACjB,KAAK,sBAA+B,EACpC,QAAQ,UAAQ,GACf,QAAQ,GAAG,SAAS;CAoDxB;AAED,eAAO,MAAM,OAAO,gBAAuB,CAAA"}
|
|
@@ -8,6 +8,60 @@ export function fileSystemNodeInitialState(contentPresent = true) {
|
|
|
8
8
|
extensionStates: {}
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Fold a partial permissions object into fully-resolved capabilities, applying
|
|
13
|
+
* defaults: `read`/`write` default true, and `remove`/`rename`/`createChildren`
|
|
14
|
+
* default to the resolved `write` value. Node-local (no inheritance).
|
|
15
|
+
*/
|
|
16
|
+
export function resolveNodePermissions(perms) {
|
|
17
|
+
const read = perms?.read ?? true;
|
|
18
|
+
const write = perms?.write ?? true;
|
|
19
|
+
return {
|
|
20
|
+
read,
|
|
21
|
+
write,
|
|
22
|
+
remove: perms?.remove ?? write,
|
|
23
|
+
rename: perms?.rename ?? write,
|
|
24
|
+
createChildren: perms?.createChildren ?? write,
|
|
25
|
+
reason: perms?.reason
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolve permissions for a node at `path` with directory inheritance.
|
|
30
|
+
*
|
|
31
|
+
* Walks root → target, folding each ancestor's explicitly-set capabilities;
|
|
32
|
+
* a child overrides its ancestors per-field (a read-only directory therefore
|
|
33
|
+
* makes descendants read-only unless a child sets `write: true`). Undefined
|
|
34
|
+
* fields fall through to defaults (see {@link resolveNodePermissions}).
|
|
35
|
+
*/
|
|
36
|
+
export function resolvePermissions(root, path) {
|
|
37
|
+
const merged = {};
|
|
38
|
+
let current = root;
|
|
39
|
+
const segments = Pathway.of(path).getSegments();
|
|
40
|
+
for (let i = 0;; i++) {
|
|
41
|
+
const perms = current?.state?.permissions;
|
|
42
|
+
if (perms) {
|
|
43
|
+
// Later (deeper) nodes override earlier ones, per defined field only.
|
|
44
|
+
for (const key of Object.keys(perms)) {
|
|
45
|
+
if (perms[key] !== undefined) {
|
|
46
|
+
merged[key] = perms[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (i >= segments.length || current === undefined || current.type !== 'directory') {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
current = current.children[segments[i]];
|
|
54
|
+
}
|
|
55
|
+
return resolveNodePermissions(merged);
|
|
56
|
+
}
|
|
57
|
+
/** Node-local writability (no inheritance). Absent permissions ⇒ writable. */
|
|
58
|
+
export function isWritable(node) {
|
|
59
|
+
return resolveNodePermissions(node?.state?.permissions).write;
|
|
60
|
+
}
|
|
61
|
+
/** Node-local read-only check (no inheritance). Inverse of {@link isWritable}. */
|
|
62
|
+
export function isReadOnly(node) {
|
|
63
|
+
return !isWritable(node);
|
|
64
|
+
}
|
|
11
65
|
function isRoot(node) {
|
|
12
66
|
switch (node.type) {
|
|
13
67
|
case "directory": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fsutils = exports.DirectoryNodePathwayResolver = exports.fileSystemNodeInitialState = void 0;
|
|
3
|
+
exports.fsutils = exports.DirectoryNodePathwayResolver = exports.isReadOnly = exports.isWritable = exports.resolvePermissions = exports.resolveNodePermissions = exports.fileSystemNodeInitialState = void 0;
|
|
4
4
|
const core_utils_pathway_1 = require("./core-utils-pathway");
|
|
5
5
|
function fileSystemNodeInitialState(contentPresent = true) {
|
|
6
6
|
return {
|
|
@@ -12,6 +12,67 @@ function fileSystemNodeInitialState(contentPresent = true) {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
exports.fileSystemNodeInitialState = fileSystemNodeInitialState;
|
|
15
|
+
/**
|
|
16
|
+
* Fold a partial permissions object into fully-resolved capabilities, applying
|
|
17
|
+
* defaults: `read`/`write` default true, and `remove`/`rename`/`createChildren`
|
|
18
|
+
* default to the resolved `write` value. Node-local (no inheritance).
|
|
19
|
+
*/
|
|
20
|
+
function resolveNodePermissions(perms) {
|
|
21
|
+
var _a, _b, _c, _d, _e;
|
|
22
|
+
const read = (_a = perms === null || perms === void 0 ? void 0 : perms.read) !== null && _a !== void 0 ? _a : true;
|
|
23
|
+
const write = (_b = perms === null || perms === void 0 ? void 0 : perms.write) !== null && _b !== void 0 ? _b : true;
|
|
24
|
+
return {
|
|
25
|
+
read,
|
|
26
|
+
write,
|
|
27
|
+
remove: (_c = perms === null || perms === void 0 ? void 0 : perms.remove) !== null && _c !== void 0 ? _c : write,
|
|
28
|
+
rename: (_d = perms === null || perms === void 0 ? void 0 : perms.rename) !== null && _d !== void 0 ? _d : write,
|
|
29
|
+
createChildren: (_e = perms === null || perms === void 0 ? void 0 : perms.createChildren) !== null && _e !== void 0 ? _e : write,
|
|
30
|
+
reason: perms === null || perms === void 0 ? void 0 : perms.reason
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.resolveNodePermissions = resolveNodePermissions;
|
|
34
|
+
/**
|
|
35
|
+
* Resolve permissions for a node at `path` with directory inheritance.
|
|
36
|
+
*
|
|
37
|
+
* Walks root → target, folding each ancestor's explicitly-set capabilities;
|
|
38
|
+
* a child overrides its ancestors per-field (a read-only directory therefore
|
|
39
|
+
* makes descendants read-only unless a child sets `write: true`). Undefined
|
|
40
|
+
* fields fall through to defaults (see {@link resolveNodePermissions}).
|
|
41
|
+
*/
|
|
42
|
+
function resolvePermissions(root, path) {
|
|
43
|
+
var _a;
|
|
44
|
+
const merged = {};
|
|
45
|
+
let current = root;
|
|
46
|
+
const segments = core_utils_pathway_1.Pathway.of(path).getSegments();
|
|
47
|
+
for (let i = 0;; i++) {
|
|
48
|
+
const perms = (_a = current === null || current === void 0 ? void 0 : current.state) === null || _a === void 0 ? void 0 : _a.permissions;
|
|
49
|
+
if (perms) {
|
|
50
|
+
// Later (deeper) nodes override earlier ones, per defined field only.
|
|
51
|
+
for (const key of Object.keys(perms)) {
|
|
52
|
+
if (perms[key] !== undefined) {
|
|
53
|
+
merged[key] = perms[key];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (i >= segments.length || current === undefined || current.type !== 'directory') {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
current = current.children[segments[i]];
|
|
61
|
+
}
|
|
62
|
+
return resolveNodePermissions(merged);
|
|
63
|
+
}
|
|
64
|
+
exports.resolvePermissions = resolvePermissions;
|
|
65
|
+
/** Node-local writability (no inheritance). Absent permissions ⇒ writable. */
|
|
66
|
+
function isWritable(node) {
|
|
67
|
+
var _a;
|
|
68
|
+
return resolveNodePermissions((_a = node === null || node === void 0 ? void 0 : node.state) === null || _a === void 0 ? void 0 : _a.permissions).write;
|
|
69
|
+
}
|
|
70
|
+
exports.isWritable = isWritable;
|
|
71
|
+
/** Node-local read-only check (no inheritance). Inverse of {@link isWritable}. */
|
|
72
|
+
function isReadOnly(node) {
|
|
73
|
+
return !isWritable(node);
|
|
74
|
+
}
|
|
75
|
+
exports.isReadOnly = isReadOnly;
|
|
15
76
|
function isRoot(node) {
|
|
16
77
|
switch (node.type) {
|
|
17
78
|
case "directory": {
|