@gesslar/toolkit 3.22.2 → 3.24.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/README.md +2 -5
- package/package.json +10 -4
- package/src/browser/lib/Data.js +16 -2
- package/src/browser/lib/OObject.js +196 -0
- package/src/browser/lib/Promised.js +4 -2
- package/src/browser/lib/Time.js +4 -2
- package/src/browser/lib/TypeSpec.js +24 -5
- package/src/node/index.js +0 -3
- package/src/node/lib/DirectoryObject.js +100 -212
- package/src/node/lib/FileObject.js +71 -44
- package/src/node/lib/FileSystem.js +11 -48
- package/src/node/lib/Glog.js +2 -12
- package/src/node/lib/Valid.js +8 -1
- package/types/browser/lib/Data.d.ts +26 -4
- package/types/browser/lib/Data.d.ts.map +1 -1
- package/types/browser/lib/OObject.d.ts +127 -0
- package/types/browser/lib/OObject.d.ts.map +1 -0
- package/types/browser/lib/Promised.d.ts.map +1 -1
- package/types/browser/lib/Time.d.ts.map +1 -1
- package/types/browser/lib/TypeSpec.d.ts +42 -6
- package/types/browser/lib/TypeSpec.d.ts.map +1 -1
- package/types/node/index.d.ts +0 -3
- package/types/node/lib/DirectoryObject.d.ts +93 -51
- package/types/node/lib/DirectoryObject.d.ts.map +1 -1
- package/types/node/lib/FileObject.d.ts +12 -7
- package/types/node/lib/FileObject.d.ts.map +1 -1
- package/types/node/lib/FileSystem.d.ts +16 -23
- package/types/node/lib/FileSystem.d.ts.map +1 -1
- package/types/node/lib/Glog.d.ts +0 -7
- package/types/node/lib/Glog.d.ts.map +1 -1
- package/types/node/lib/Valid.d.ts +17 -2
- package/types/node/lib/Valid.d.ts.map +1 -1
- package/src/node/lib/TempDirectoryObject.js +0 -165
- package/src/node/lib/VDirectoryObject.js +0 -198
- package/src/node/lib/VFileObject.js +0 -110
- package/types/node/lib/TempDirectoryObject.d.ts +0 -42
- package/types/node/lib/TempDirectoryObject.d.ts.map +0 -1
- package/types/node/lib/VDirectoryObject.d.ts +0 -132
- package/types/node/lib/VDirectoryObject.d.ts.map +0 -1
- package/types/node/lib/VFileObject.d.ts +0 -33
- package/types/node/lib/VFileObject.d.ts.map +0 -1
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file VDirectoryObject.js
|
|
3
|
-
* @description Abstract base class for directory objects that are constrained
|
|
4
|
-
* to a specific directory tree (the "cap"). This provides security by ensuring
|
|
5
|
-
* all operations remain within the capped directory hierarchy.
|
|
6
|
-
*
|
|
7
|
-
* This class is not intended to be instantiated directly. Use subclasses like
|
|
8
|
-
* TempDirectoryObject that define specific caps.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import path from "node:path"
|
|
12
|
-
|
|
13
|
-
import DirectoryObject from "./DirectoryObject.js"
|
|
14
|
-
import FileSystem from "./FileSystem.js"
|
|
15
|
-
import Valid from "./Valid.js"
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* VDirectoryObject extends DirectoryObject with constraints that ensure
|
|
19
|
-
* all operations are restricted to a specific directory tree (the "cap").
|
|
20
|
-
*
|
|
21
|
-
* All path operations are validated to ensure they remain within the
|
|
22
|
-
* cap directory hierarchy for security.
|
|
23
|
-
*
|
|
24
|
-
* @augments DirectoryObject
|
|
25
|
-
*/
|
|
26
|
-
export default class VDirectoryObject extends DirectoryObject {
|
|
27
|
-
#real
|
|
28
|
-
#cap
|
|
29
|
-
#cappedParentPath
|
|
30
|
-
#cappedParent
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Constructs a VDirectoryObject instance.
|
|
34
|
-
*
|
|
35
|
-
* Without a parent, creates a new cap at the specified real directory location
|
|
36
|
-
* with virtual path "/". With a parent, the path is resolved relative to the
|
|
37
|
-
* parent's virtual path (absolute paths treated as cap-relative).
|
|
38
|
-
*
|
|
39
|
-
* @param {string} [directory="."] - Real directory path when no parent (becomes cap), or relative/absolute virtual path when parent provided
|
|
40
|
-
* @param {VDirectoryObject?} [parent] - Optional parent capped directory
|
|
41
|
-
* @throws {Sass} If parent is provided but not a VDirectoryObject
|
|
42
|
-
* @example
|
|
43
|
-
* // Create new capped directory at current directory
|
|
44
|
-
* const cwd = new VDirectoryObject()
|
|
45
|
-
* // Virtual path: "/", Real path: process.cwd(), Cap: itself
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* // Create new capped directory
|
|
49
|
-
* const cache = new VDirectoryObject("/home/user/.cache")
|
|
50
|
-
* // Virtual path: "/", Real path: /home/user/.cache, Cap: itself
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* // Create subdirectory with parent
|
|
54
|
-
* const data = new VDirectoryObject("data", cache)
|
|
55
|
-
* // Virtual path: /data, Real path: /home/user/.cache/data, Cap: cache
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* // Virtual absolute path with parent (treated as cap-relative)
|
|
59
|
-
* const config = new VDirectoryObject("/etc/config", cache)
|
|
60
|
-
* // Virtual path: /etc/config, Real path: /home/user/.cache/etc/config, Cap: cache
|
|
61
|
-
*/
|
|
62
|
-
constructor(directory, source=null) {
|
|
63
|
-
Valid.type(source, "Null|VDirectoryObject")
|
|
64
|
-
|
|
65
|
-
directory ||= "."
|
|
66
|
-
|
|
67
|
-
const baseLocalPath = source?.path ?? "/"
|
|
68
|
-
const baseRealPath = source?.real.path ?? directory
|
|
69
|
-
|
|
70
|
-
if(source && directory.startsWith("/"))
|
|
71
|
-
directory = directory.slice(1)
|
|
72
|
-
|
|
73
|
-
// Find out what directory means to the basePath
|
|
74
|
-
const realResolved = FileSystem.resolvePath(baseRealPath, directory)
|
|
75
|
-
const localResolved = source
|
|
76
|
-
? FileSystem.resolvePath(baseLocalPath, directory)
|
|
77
|
-
: path.parse(path.resolve("")).root
|
|
78
|
-
|
|
79
|
-
super(localResolved)
|
|
80
|
-
|
|
81
|
-
this.#real = new DirectoryObject(realResolved)
|
|
82
|
-
this.#cap = source?.cap ?? this
|
|
83
|
-
|
|
84
|
-
if(source) {
|
|
85
|
-
this.#cappedParent = source
|
|
86
|
-
this.#cappedParentPath = source.path
|
|
87
|
-
} else {
|
|
88
|
-
this.#cappedParent = null
|
|
89
|
-
this.#cappedParentPath = null
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Creates a VDirectoryObject from the current working directory.
|
|
95
|
-
* This is useful when working with pnpx or other tools where you need to
|
|
96
|
-
* cap at the project's root directory determined at runtime.
|
|
97
|
-
*
|
|
98
|
-
* @returns {VDirectoryObject} A VDirectoryObject capped at the current working directory
|
|
99
|
-
* @example
|
|
100
|
-
* // When using pnpx or similar tools
|
|
101
|
-
* const projectRoot = VDirectoryObject.fromCwd()
|
|
102
|
-
* const srcDir = projectRoot.getDirectory("src")
|
|
103
|
-
* // srcDir is capped at the project root
|
|
104
|
-
*/
|
|
105
|
-
static fromCwd() {
|
|
106
|
-
return new this(process.cwd())
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Indicates whether this directory is capped (constrained to a specific tree).
|
|
111
|
-
* Always returns true for VDirectoryObject instances.
|
|
112
|
-
*
|
|
113
|
-
* @returns {boolean} True for all VDirectoryObject instances
|
|
114
|
-
* @example
|
|
115
|
-
* const capped = new TempDirectoryObject("myapp")
|
|
116
|
-
* console.log(capped.isVirtual) // true
|
|
117
|
-
*
|
|
118
|
-
* const regular = new DirectoryObject("/tmp")
|
|
119
|
-
* console.log(regular.isVirtual) // false
|
|
120
|
-
*/
|
|
121
|
-
get isVirtual() {
|
|
122
|
-
return true
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Returns the cap (root) of the capped directory tree.
|
|
127
|
-
* For root VDirectoryObject instances, returns itself.
|
|
128
|
-
* For children, returns the inherited cap from the parent chain.
|
|
129
|
-
*
|
|
130
|
-
* @returns {VDirectoryObject} The cap directory object (root of the capped tree)
|
|
131
|
-
* @example
|
|
132
|
-
* const temp = new TempDirectoryObject("myapp")
|
|
133
|
-
* console.log(temp.cap === temp) // true (root is its own cap)
|
|
134
|
-
*
|
|
135
|
-
* const subdir = temp.getDirectory("data")
|
|
136
|
-
* console.log(subdir.cap === temp) // true (child inherits parent's cap)
|
|
137
|
-
*/
|
|
138
|
-
get cap() {
|
|
139
|
-
return this.#cap
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Returns a plain DirectoryObject representing the actual filesystem location.
|
|
144
|
-
* This provides an "escape hatch" from the capped environment to interact
|
|
145
|
-
* with the real filesystem when needed.
|
|
146
|
-
*
|
|
147
|
-
* @returns {DirectoryObject} Uncapped directory object at the real filesystem path
|
|
148
|
-
* @example
|
|
149
|
-
* const temp = new TempDirectoryObject("myapp")
|
|
150
|
-
* const subdir = temp.getDirectory("data")
|
|
151
|
-
*
|
|
152
|
-
* // Work within the capped environment (virtual paths)
|
|
153
|
-
* console.log(subdir.path) // "/data" (virtual)
|
|
154
|
-
* subdir.getFile("config.json") // Stays within cap
|
|
155
|
-
*
|
|
156
|
-
* // Break out to real filesystem when needed
|
|
157
|
-
* console.log(subdir.real.path) // "/tmp/myapp-ABC123/data" (real)
|
|
158
|
-
* subdir.real.parent // Can traverse outside the cap
|
|
159
|
-
*/
|
|
160
|
-
get real() {
|
|
161
|
-
return this.#real
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Returns the parent directory of this capped directory.
|
|
166
|
-
* Returns null only if this directory is at the cap (the "root" of the capped tree).
|
|
167
|
-
*
|
|
168
|
-
* Note: The returned parent is a VDirectoryObject with the same cap.
|
|
169
|
-
* This maintains the capping behavior throughout the directory hierarchy.
|
|
170
|
-
*
|
|
171
|
-
* @returns {VDirectoryObject|null} Parent directory or null if at cap root
|
|
172
|
-
* @example
|
|
173
|
-
* const capped = new TempDirectoryObject("myapp")
|
|
174
|
-
* const subdir = capped.getDirectory("data")
|
|
175
|
-
* console.log(subdir.parent.path) // Returns parent VDirectoryObject
|
|
176
|
-
* console.log(capped.parent) // null (at cap root)
|
|
177
|
-
*/
|
|
178
|
-
get parent() {
|
|
179
|
-
return this.#cappedParent
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Returns the path of the parent directory.
|
|
184
|
-
* Returns null if this directory is at the cap root (no parent).
|
|
185
|
-
*
|
|
186
|
-
* @returns {string|null} The parent directory path, or null if at cap root
|
|
187
|
-
* @example
|
|
188
|
-
* const temp = new TempDirectoryObject("myapp")
|
|
189
|
-
* console.log(temp.parentPath) // null (at cap root)
|
|
190
|
-
*
|
|
191
|
-
* const subdir = temp.getDirectory("data")
|
|
192
|
-
* console.log(subdir.parentPath) // "/" (parent's virtual path)
|
|
193
|
-
*/
|
|
194
|
-
get parentPath() {
|
|
195
|
-
return this.#cappedParentPath
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file VFileObject.js
|
|
3
|
-
* @description Class representing a virtual file within a capped directory tree.
|
|
4
|
-
* Extends FileObject with virtual path support and real filesystem mapping.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import DirectoryObject from "./DirectoryObject.js"
|
|
8
|
-
import FileObject from "./FileObject.js"
|
|
9
|
-
import FS from "./FileSystem.js"
|
|
10
|
-
import Valid from "./Valid.js"
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* VFileObject extends FileObject with virtual path support, maintaining both
|
|
14
|
-
* a virtual path (relative to cap) and a real filesystem path.
|
|
15
|
-
*
|
|
16
|
-
* Virtual files must have a VDirectoryObject parent and cannot exist independently.
|
|
17
|
-
* All file operations use the real filesystem path while exposing clean virtual paths.
|
|
18
|
-
*
|
|
19
|
-
* @property {string} supplied - User-supplied path
|
|
20
|
-
* @property {string} path - The virtual file path (relative to cap)
|
|
21
|
-
* @property {URL} url - The file URL
|
|
22
|
-
* @property {string} name - The file name
|
|
23
|
-
* @property {string} module - The file name without extension
|
|
24
|
-
* @property {string} extension - The file extension
|
|
25
|
-
* @property {boolean} isFile - Always true for files
|
|
26
|
-
* @property {boolean} isVirtual - Always true for VFileObject instances
|
|
27
|
-
* @property {VDirectoryObject} parent - The parent virtual directory object
|
|
28
|
-
* @property {FileObject} real - The real filesystem FileObject
|
|
29
|
-
* @property {Promise<boolean>} exists - Whether the file exists (async)
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
export default class VFileObject extends FileObject {
|
|
33
|
-
#real
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Constructs a VFileObject instance.
|
|
37
|
-
*
|
|
38
|
-
* @param {string} virtualPath - The virtual file path (can be absolute like "/path/to/file.ext" or relative like "file.txt")
|
|
39
|
-
* @param {VDirectoryObject} parent - The parent virtual directory (required, used for cap reference)
|
|
40
|
-
*/
|
|
41
|
-
constructor(virtualPath, parent) {
|
|
42
|
-
Valid.type(virtualPath, "String", {allowEmpty: false})
|
|
43
|
-
Valid.type(parent, "VDirectoryObject")
|
|
44
|
-
|
|
45
|
-
// Normalize the virtual path
|
|
46
|
-
const normalizedVirtual = FS.fixSlashes(virtualPath)
|
|
47
|
-
const isAbsolute = normalizedVirtual.startsWith("/")
|
|
48
|
-
|
|
49
|
-
// If absolute path, it's already resolved from cap root (from getFile())
|
|
50
|
-
// If relative path, resolve from parent directory (from hasFile(), read(), etc.)
|
|
51
|
-
let resolvedVirtualPath
|
|
52
|
-
if(isAbsolute) {
|
|
53
|
-
// Absolute path is already resolved - use as-is
|
|
54
|
-
resolvedVirtualPath = normalizedVirtual
|
|
55
|
-
} else {
|
|
56
|
-
// Relative path: resolve from parent directory (not cap root!)
|
|
57
|
-
resolvedVirtualPath = FS.resolvePath(parent.path, normalizedVirtual)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const normalized = FS.fixSlashes(resolvedVirtualPath)
|
|
61
|
-
|
|
62
|
-
// Extract the directory and filename from the resolved virtual path
|
|
63
|
-
const {dir: virtualDir, base} = FS.pathParts(normalized)
|
|
64
|
-
|
|
65
|
-
// Determine the virtual parent directory
|
|
66
|
-
// If virtualDir is "/" or empty or equals cap path, use the cap root
|
|
67
|
-
// Otherwise, construct the parent directory path relative to cap
|
|
68
|
-
let virtualParent
|
|
69
|
-
if(!virtualDir || virtualDir === "/" || virtualDir === parent.cap.path) {
|
|
70
|
-
virtualParent = parent.cap
|
|
71
|
-
} else {
|
|
72
|
-
// virtualDir is something like "/path/to" - we need to create a VDirectoryObject for it
|
|
73
|
-
// Strip leading "/" if present to make it relative to cap
|
|
74
|
-
const dirRelativeToCap = virtualDir.startsWith("/") ? virtualDir.slice(1) : virtualDir
|
|
75
|
-
// Use the VDirectoryObject constructor to create the parent directory
|
|
76
|
-
virtualParent = new parent.constructor(dirRelativeToCap, parent.cap)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Call super with just the filename and the virtual parent
|
|
80
|
-
// This ensures FileObject sets up the virtual path correctly
|
|
81
|
-
super(base, virtualParent)
|
|
82
|
-
|
|
83
|
-
// Convert virtual path to real path
|
|
84
|
-
// The resolved virtual path is relative to the cap root, so we resolve it relative to cap's real path
|
|
85
|
-
const capRealPath = parent.cap.real.path
|
|
86
|
-
|
|
87
|
-
// Strip leading "/" from resolved virtual path if present to make it relative
|
|
88
|
-
const relativeFromCap = normalized.startsWith("/")
|
|
89
|
-
? normalized.slice(1)
|
|
90
|
-
: normalized
|
|
91
|
-
|
|
92
|
-
// Resolve the real filesystem path
|
|
93
|
-
const realPath = FS.resolvePath(capRealPath, relativeFromCap)
|
|
94
|
-
|
|
95
|
-
// Create FileObject with the full real path
|
|
96
|
-
// Extract directory and filename parts
|
|
97
|
-
const {dir: realDir, base: realBase} = FS.pathParts(realPath)
|
|
98
|
-
const realParentDir = new DirectoryObject(realDir)
|
|
99
|
-
|
|
100
|
-
this.#real = new FileObject(realBase, realParentDir)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get isVirtual() {
|
|
104
|
-
return true
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
get real() {
|
|
108
|
-
return this.#real
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TempDirectoryObject extends VDirectoryObject with the cap set to
|
|
3
|
-
* the OS's temporary directory. Temporary directories are created
|
|
4
|
-
* synchronously during construction and exist immediately.
|
|
5
|
-
*
|
|
6
|
-
* All path operations are validated to ensure they remain within the temp
|
|
7
|
-
* directory hierarchy for security.
|
|
8
|
-
*
|
|
9
|
-
* @augments VDirectoryObject
|
|
10
|
-
*/
|
|
11
|
-
export default class TempDirectoryObject extends VDirectoryObject {
|
|
12
|
-
/**
|
|
13
|
-
* TempDirectoryObject does not support fromCwd() since it is specifically
|
|
14
|
-
* designed to work within the OS temporary directory tree.
|
|
15
|
-
*
|
|
16
|
-
* @throws {Sass} Always throws an error
|
|
17
|
-
*/
|
|
18
|
-
static fromCwd(): void;
|
|
19
|
-
get isTemporary(): boolean;
|
|
20
|
-
get cap(): any;
|
|
21
|
-
/**
|
|
22
|
-
* Recursively removes a temporary directory and all its contents.
|
|
23
|
-
*
|
|
24
|
-
* This method will delete all files and subdirectories within this directory,
|
|
25
|
-
* then delete the directory itself. It only works on directories explicitly
|
|
26
|
-
* marked as temporary for safety.
|
|
27
|
-
*
|
|
28
|
-
* @async
|
|
29
|
-
* @returns {Promise<void>}
|
|
30
|
-
* @throws {Sass} If the directory is not marked as temporary
|
|
31
|
-
* @throws {Sass} If the directory deletion fails
|
|
32
|
-
* @example
|
|
33
|
-
* const tempDir = new TempDirectoryObject("my-temp")
|
|
34
|
-
* await tempDir.assureExists()
|
|
35
|
-
* // ... use the directory ...
|
|
36
|
-
* await tempDir.remove() // Recursively deletes everything
|
|
37
|
-
*/
|
|
38
|
-
remove(): Promise<void>;
|
|
39
|
-
#private;
|
|
40
|
-
}
|
|
41
|
-
import VDirectoryObject from "./VDirectoryObject.js";
|
|
42
|
-
//# sourceMappingURL=TempDirectoryObject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TempDirectoryObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/TempDirectoryObject.js"],"names":[],"mappings":"AAiBA;;;;;;;;;GASG;AACH;IAgIE;;;;;OAKG;IACH,uBAEC;IA1ED,2BAEC;IAwBD,eAEC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,UATa,OAAO,CAAC,IAAI,CAAC,CAWzB;;CA0BF;6BAzJ4B,uBAAuB"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* VDirectoryObject extends DirectoryObject with constraints that ensure
|
|
3
|
-
* all operations are restricted to a specific directory tree (the "cap").
|
|
4
|
-
*
|
|
5
|
-
* All path operations are validated to ensure they remain within the
|
|
6
|
-
* cap directory hierarchy for security.
|
|
7
|
-
*
|
|
8
|
-
* @augments DirectoryObject
|
|
9
|
-
*/
|
|
10
|
-
export default class VDirectoryObject extends DirectoryObject {
|
|
11
|
-
/**
|
|
12
|
-
* Creates a VDirectoryObject from the current working directory.
|
|
13
|
-
* This is useful when working with pnpx or other tools where you need to
|
|
14
|
-
* cap at the project's root directory determined at runtime.
|
|
15
|
-
*
|
|
16
|
-
* @returns {VDirectoryObject} A VDirectoryObject capped at the current working directory
|
|
17
|
-
* @example
|
|
18
|
-
* // When using pnpx or similar tools
|
|
19
|
-
* const projectRoot = VDirectoryObject.fromCwd()
|
|
20
|
-
* const srcDir = projectRoot.getDirectory("src")
|
|
21
|
-
* // srcDir is capped at the project root
|
|
22
|
-
*/
|
|
23
|
-
static fromCwd(): VDirectoryObject;
|
|
24
|
-
/**
|
|
25
|
-
* Constructs a VDirectoryObject instance.
|
|
26
|
-
*
|
|
27
|
-
* Without a parent, creates a new cap at the specified real directory location
|
|
28
|
-
* with virtual path "/". With a parent, the path is resolved relative to the
|
|
29
|
-
* parent's virtual path (absolute paths treated as cap-relative).
|
|
30
|
-
*
|
|
31
|
-
* @param {string} [directory="."] - Real directory path when no parent (becomes cap), or relative/absolute virtual path when parent provided
|
|
32
|
-
* @param {VDirectoryObject?} [parent] - Optional parent capped directory
|
|
33
|
-
* @throws {Sass} If parent is provided but not a VDirectoryObject
|
|
34
|
-
* @example
|
|
35
|
-
* // Create new capped directory at current directory
|
|
36
|
-
* const cwd = new VDirectoryObject()
|
|
37
|
-
* // Virtual path: "/", Real path: process.cwd(), Cap: itself
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* // Create new capped directory
|
|
41
|
-
* const cache = new VDirectoryObject("/home/user/.cache")
|
|
42
|
-
* // Virtual path: "/", Real path: /home/user/.cache, Cap: itself
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* // Create subdirectory with parent
|
|
46
|
-
* const data = new VDirectoryObject("data", cache)
|
|
47
|
-
* // Virtual path: /data, Real path: /home/user/.cache/data, Cap: cache
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* // Virtual absolute path with parent (treated as cap-relative)
|
|
51
|
-
* const config = new VDirectoryObject("/etc/config", cache)
|
|
52
|
-
* // Virtual path: /etc/config, Real path: /home/user/.cache/etc/config, Cap: cache
|
|
53
|
-
*/
|
|
54
|
-
constructor(directory?: string, source?: any);
|
|
55
|
-
/**
|
|
56
|
-
* Indicates whether this directory is capped (constrained to a specific tree).
|
|
57
|
-
* Always returns true for VDirectoryObject instances.
|
|
58
|
-
*
|
|
59
|
-
* @returns {boolean} True for all VDirectoryObject instances
|
|
60
|
-
* @example
|
|
61
|
-
* const capped = new TempDirectoryObject("myapp")
|
|
62
|
-
* console.log(capped.isVirtual) // true
|
|
63
|
-
*
|
|
64
|
-
* const regular = new DirectoryObject("/tmp")
|
|
65
|
-
* console.log(regular.isVirtual) // false
|
|
66
|
-
*/
|
|
67
|
-
get isVirtual(): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Returns the cap (root) of the capped directory tree.
|
|
70
|
-
* For root VDirectoryObject instances, returns itself.
|
|
71
|
-
* For children, returns the inherited cap from the parent chain.
|
|
72
|
-
*
|
|
73
|
-
* @returns {VDirectoryObject} The cap directory object (root of the capped tree)
|
|
74
|
-
* @example
|
|
75
|
-
* const temp = new TempDirectoryObject("myapp")
|
|
76
|
-
* console.log(temp.cap === temp) // true (root is its own cap)
|
|
77
|
-
*
|
|
78
|
-
* const subdir = temp.getDirectory("data")
|
|
79
|
-
* console.log(subdir.cap === temp) // true (child inherits parent's cap)
|
|
80
|
-
*/
|
|
81
|
-
get cap(): VDirectoryObject;
|
|
82
|
-
/**
|
|
83
|
-
* Returns a plain DirectoryObject representing the actual filesystem location.
|
|
84
|
-
* This provides an "escape hatch" from the capped environment to interact
|
|
85
|
-
* with the real filesystem when needed.
|
|
86
|
-
*
|
|
87
|
-
* @returns {DirectoryObject} Uncapped directory object at the real filesystem path
|
|
88
|
-
* @example
|
|
89
|
-
* const temp = new TempDirectoryObject("myapp")
|
|
90
|
-
* const subdir = temp.getDirectory("data")
|
|
91
|
-
*
|
|
92
|
-
* // Work within the capped environment (virtual paths)
|
|
93
|
-
* console.log(subdir.path) // "/data" (virtual)
|
|
94
|
-
* subdir.getFile("config.json") // Stays within cap
|
|
95
|
-
*
|
|
96
|
-
* // Break out to real filesystem when needed
|
|
97
|
-
* console.log(subdir.real.path) // "/tmp/myapp-ABC123/data" (real)
|
|
98
|
-
* subdir.real.parent // Can traverse outside the cap
|
|
99
|
-
*/
|
|
100
|
-
get real(): DirectoryObject;
|
|
101
|
-
/**
|
|
102
|
-
* Returns the parent directory of this capped directory.
|
|
103
|
-
* Returns null only if this directory is at the cap (the "root" of the capped tree).
|
|
104
|
-
*
|
|
105
|
-
* Note: The returned parent is a VDirectoryObject with the same cap.
|
|
106
|
-
* This maintains the capping behavior throughout the directory hierarchy.
|
|
107
|
-
*
|
|
108
|
-
* @returns {VDirectoryObject|null} Parent directory or null if at cap root
|
|
109
|
-
* @example
|
|
110
|
-
* const capped = new TempDirectoryObject("myapp")
|
|
111
|
-
* const subdir = capped.getDirectory("data")
|
|
112
|
-
* console.log(subdir.parent.path) // Returns parent VDirectoryObject
|
|
113
|
-
* console.log(capped.parent) // null (at cap root)
|
|
114
|
-
*/
|
|
115
|
-
get parent(): VDirectoryObject | null;
|
|
116
|
-
/**
|
|
117
|
-
* Returns the path of the parent directory.
|
|
118
|
-
* Returns null if this directory is at the cap root (no parent).
|
|
119
|
-
*
|
|
120
|
-
* @returns {string|null} The parent directory path, or null if at cap root
|
|
121
|
-
* @example
|
|
122
|
-
* const temp = new TempDirectoryObject("myapp")
|
|
123
|
-
* console.log(temp.parentPath) // null (at cap root)
|
|
124
|
-
*
|
|
125
|
-
* const subdir = temp.getDirectory("data")
|
|
126
|
-
* console.log(subdir.parentPath) // "/" (parent's virtual path)
|
|
127
|
-
*/
|
|
128
|
-
get parentPath(): string | null;
|
|
129
|
-
#private;
|
|
130
|
-
}
|
|
131
|
-
import DirectoryObject from "./DirectoryObject.js";
|
|
132
|
-
//# sourceMappingURL=VDirectoryObject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VDirectoryObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/VDirectoryObject.js"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AACH;IAmEE;;;;;;;;;;;OAWG;IACH,kBAPa,gBAAgB,CAS5B;IA3ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,wBAvBW,MAAM,gBAoDhB;IAkBD;;;;;;;;;;;OAWG;IACH,iBARa,OAAO,CAUnB;IAED;;;;;;;;;;;;OAYG;IACH,WARa,gBAAgB,CAU5B;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,YAba,eAAe,CAe3B;IAED;;;;;;;;;;;;;OAaG;IACH,cAPa,gBAAgB,GAAC,IAAI,CASjC;IAED;;;;;;;;;;;OAWG;IACH,kBARa,MAAM,GAAC,IAAI,CAUvB;;CAEF;4BAzL2B,sBAAsB"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* VFileObject extends FileObject with virtual path support, maintaining both
|
|
3
|
-
* a virtual path (relative to cap) and a real filesystem path.
|
|
4
|
-
*
|
|
5
|
-
* Virtual files must have a VDirectoryObject parent and cannot exist independently.
|
|
6
|
-
* All file operations use the real filesystem path while exposing clean virtual paths.
|
|
7
|
-
*
|
|
8
|
-
* @property {string} supplied - User-supplied path
|
|
9
|
-
* @property {string} path - The virtual file path (relative to cap)
|
|
10
|
-
* @property {URL} url - The file URL
|
|
11
|
-
* @property {string} name - The file name
|
|
12
|
-
* @property {string} module - The file name without extension
|
|
13
|
-
* @property {string} extension - The file extension
|
|
14
|
-
* @property {boolean} isFile - Always true for files
|
|
15
|
-
* @property {boolean} isVirtual - Always true for VFileObject instances
|
|
16
|
-
* @property {VDirectoryObject} parent - The parent virtual directory object
|
|
17
|
-
* @property {FileObject} real - The real filesystem FileObject
|
|
18
|
-
* @property {Promise<boolean>} exists - Whether the file exists (async)
|
|
19
|
-
*/
|
|
20
|
-
export default class VFileObject extends FileObject {
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a VFileObject instance.
|
|
23
|
-
*
|
|
24
|
-
* @param {string} virtualPath - The virtual file path (can be absolute like "/path/to/file.ext" or relative like "file.txt")
|
|
25
|
-
* @param {VDirectoryObject} parent - The parent virtual directory (required, used for cap reference)
|
|
26
|
-
*/
|
|
27
|
-
constructor(virtualPath: string, parent: VDirectoryObject);
|
|
28
|
-
get isVirtual(): boolean;
|
|
29
|
-
get real(): FileObject;
|
|
30
|
-
#private;
|
|
31
|
-
}
|
|
32
|
-
import FileObject from "./FileObject.js";
|
|
33
|
-
//# sourceMappingURL=VFileObject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VFileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/VFileObject.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;IAGE;;;;;OAKG;IACH,yBAHW,MAAM,UACN,gBAAgB,EA8D1B;IAED,yBAEC;IAED,uBAEC;;CACF;uBAtGsB,iBAAiB"}
|