@fgv/ts-json-base 5.0.2 → 5.1.0-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.
- package/dist/packlets/converters/converters.js +36 -14
- package/dist/packlets/file-tree/directoryItem.js +99 -4
- package/dist/packlets/file-tree/fileItem.js +47 -9
- package/dist/packlets/file-tree/fileTreeAccessors.js +59 -1
- package/dist/packlets/file-tree/filterSpec.js +74 -0
- package/dist/packlets/file-tree/fsTree.js +107 -12
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js +279 -21
- package/dist/packlets/file-tree/in-memory/treeBuilder.js +31 -0
- package/dist/packlets/file-tree/index.browser.js +1 -0
- package/dist/packlets/file-tree/index.js +1 -0
- package/dist/packlets/json-file/file.js +1 -1
- package/dist/packlets/json-file/jsonFsHelper.js +1 -1
- package/dist/packlets/validators/validators.js +8 -8
- package/dist/ts-json-base.d.ts +439 -65
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/converters/converters.d.ts +20 -13
- package/lib/packlets/converters/converters.js +36 -13
- package/lib/packlets/file-tree/directoryItem.d.ts +29 -6
- package/lib/packlets/file-tree/directoryItem.js +98 -3
- package/lib/packlets/file-tree/fileItem.d.ts +31 -14
- package/lib/packlets/file-tree/fileItem.js +46 -8
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts +237 -3
- package/lib/packlets/file-tree/fileTreeAccessors.js +63 -0
- package/lib/packlets/file-tree/filterSpec.d.ts +10 -0
- package/lib/packlets/file-tree/filterSpec.js +77 -0
- package/lib/packlets/file-tree/fsTree.d.ts +37 -13
- package/lib/packlets/file-tree/fsTree.js +106 -11
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +37 -13
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +278 -20
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +15 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js +31 -0
- package/lib/packlets/file-tree/index.browser.d.ts +1 -0
- package/lib/packlets/file-tree/index.browser.js +1 -0
- package/lib/packlets/file-tree/index.d.ts +1 -0
- package/lib/packlets/file-tree/index.js +1 -0
- package/lib/packlets/json-file/file.d.ts +1 -1
- package/lib/packlets/json-file/file.js +1 -1
- package/lib/packlets/json-file/jsonFsHelper.d.ts +1 -1
- package/lib/packlets/json-file/jsonFsHelper.js +1 -1
- package/lib/packlets/validators/validators.d.ts +9 -9
- package/lib/packlets/validators/validators.js +8 -8
- package/package.json +29 -30
- package/dist/test/fixtures/file-tree/docs/api/reference.json +0 -1
|
@@ -1,6 +1,42 @@
|
|
|
1
|
-
import { Result } from '@fgv/ts-utils';
|
|
1
|
+
import { DetailedResult, Result } from '@fgv/ts-utils';
|
|
2
2
|
import { Converter, Validator } from '@fgv/ts-utils';
|
|
3
3
|
import { JsonValue } from '../json';
|
|
4
|
+
/**
|
|
5
|
+
* Indicates the persistence capability of a save operation.
|
|
6
|
+
* - `persistent`: Changes are saved to durable storage (e.g., file system).
|
|
7
|
+
* - `transient`: Changes are saved in memory only and will be lost on reload.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type SaveCapability = 'persistent' | 'transient';
|
|
11
|
+
/**
|
|
12
|
+
* Indicates the reason a save operation cannot be performed.
|
|
13
|
+
* - `not-supported`: The accessors do not support mutation.
|
|
14
|
+
* - `read-only`: The file or file system is read-only.
|
|
15
|
+
* - `not-mutable`: Mutability is disabled in configuration.
|
|
16
|
+
* - `path-excluded`: The path is excluded by the mutability filter.
|
|
17
|
+
* - `permission-denied`: Insufficient permissions to write.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type SaveFailureReason = 'not-supported' | 'read-only' | 'not-mutable' | 'path-excluded' | 'permission-denied';
|
|
21
|
+
/**
|
|
22
|
+
* Detail type for getIsMutable results.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export type SaveDetail = SaveCapability | SaveFailureReason;
|
|
26
|
+
/**
|
|
27
|
+
* Filter specification for controlling which paths are mutable.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export interface IFilterSpec {
|
|
31
|
+
/**
|
|
32
|
+
* Paths or patterns to include. If specified, only matching paths are mutable.
|
|
33
|
+
*/
|
|
34
|
+
include?: (string | RegExp)[];
|
|
35
|
+
/**
|
|
36
|
+
* Paths or patterns to exclude. Matching paths are not mutable.
|
|
37
|
+
*/
|
|
38
|
+
exclude?: (string | RegExp)[];
|
|
39
|
+
}
|
|
4
40
|
/**
|
|
5
41
|
* Type of item in a file tree.
|
|
6
42
|
* @public
|
|
@@ -18,9 +54,27 @@ export type ContentTypeFactory<TCT extends string = string> = (filePath: string,
|
|
|
18
54
|
export interface IFileTreeInitParams<TCT extends string = string> {
|
|
19
55
|
prefix?: string;
|
|
20
56
|
inferContentType?: ContentTypeFactory<TCT>;
|
|
57
|
+
/**
|
|
58
|
+
* Controls mutability of the file tree.
|
|
59
|
+
* - `undefined` or `false`: No files are mutable.
|
|
60
|
+
* - `true`: All files are mutable.
|
|
61
|
+
* - `IFilterSpec`: Only files matching the filter are mutable.
|
|
62
|
+
*/
|
|
63
|
+
mutable?: boolean | IFilterSpec;
|
|
21
64
|
}
|
|
22
65
|
/**
|
|
23
|
-
*
|
|
66
|
+
* Options for deleting a child item from a directory.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface IDeleteChildOptions {
|
|
70
|
+
/**
|
|
71
|
+
* If true, recursively delete directory children and their contents.
|
|
72
|
+
* Default: false (fail if directory is non-empty).
|
|
73
|
+
*/
|
|
74
|
+
recursive?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Interface for a read-only file in a file tree.
|
|
24
78
|
* @public
|
|
25
79
|
*/
|
|
26
80
|
export interface IFileTreeFileItem<TCT extends string = string> {
|
|
@@ -70,7 +124,37 @@ export interface IFileTreeFileItem<TCT extends string = string> {
|
|
|
70
124
|
getRawContents(): Result<string>;
|
|
71
125
|
}
|
|
72
126
|
/**
|
|
73
|
-
*
|
|
127
|
+
* Extended file item interface that supports mutation operations.
|
|
128
|
+
* Use {@link FileTree.isMutableFileItem | isMutableFileItem} type guard to narrow.
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export interface IMutableFileTreeFileItem<TCT extends string = string> extends IFileTreeFileItem<TCT> {
|
|
132
|
+
/**
|
|
133
|
+
* Indicates whether this file can be saved.
|
|
134
|
+
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
135
|
+
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
136
|
+
*/
|
|
137
|
+
getIsMutable(): DetailedResult<boolean, SaveDetail>;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the contents of the file from a JSON value.
|
|
140
|
+
* @param json - The JSON value to serialize and save.
|
|
141
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
142
|
+
*/
|
|
143
|
+
setContents(json: JsonValue): Result<JsonValue>;
|
|
144
|
+
/**
|
|
145
|
+
* Sets the raw contents of the file.
|
|
146
|
+
* @param contents - The string contents to save.
|
|
147
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
148
|
+
*/
|
|
149
|
+
setRawContents(contents: string): Result<string>;
|
|
150
|
+
/**
|
|
151
|
+
* Deletes this file from its backing store.
|
|
152
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
153
|
+
*/
|
|
154
|
+
delete(): Result<boolean>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Interface for a read-only directory in a file tree.
|
|
74
158
|
* @public
|
|
75
159
|
*/
|
|
76
160
|
export interface IFileTreeDirectoryItem<TCT extends string = string> {
|
|
@@ -93,11 +177,71 @@ export interface IFileTreeDirectoryItem<TCT extends string = string> {
|
|
|
93
177
|
*/
|
|
94
178
|
getChildren(): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
95
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Extended directory item interface that supports mutation operations.
|
|
182
|
+
* Use {@link FileTree.isMutableDirectoryItem | isMutableDirectoryItem} type guard to narrow.
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export interface IMutableFileTreeDirectoryItem<TCT extends string = string> extends IFileTreeDirectoryItem<TCT> {
|
|
186
|
+
/**
|
|
187
|
+
* Creates a new file as a child of this directory.
|
|
188
|
+
* @param name - The file name to create.
|
|
189
|
+
* @param contents - The string contents to write.
|
|
190
|
+
* @returns `Success` with the new file item, or `Failure` with an error message.
|
|
191
|
+
*/
|
|
192
|
+
createChildFile(name: string, contents: string): Result<IMutableFileTreeFileItem<TCT>>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a new subdirectory as a child of this directory.
|
|
195
|
+
* @param name - The directory name to create.
|
|
196
|
+
* @returns `Success` with the new directory item, or `Failure` with an error message.
|
|
197
|
+
*/
|
|
198
|
+
createChildDirectory(name: string): Result<IMutableFileTreeDirectoryItem<TCT>>;
|
|
199
|
+
/**
|
|
200
|
+
* Deletes a child item from this directory.
|
|
201
|
+
* @param name - The name of the child to delete.
|
|
202
|
+
* @param options - Optional {@link FileTree.IDeleteChildOptions | options} controlling deletion behavior.
|
|
203
|
+
* @returns `Success` with `true` if the child was deleted, or `Failure` with an error message.
|
|
204
|
+
*/
|
|
205
|
+
deleteChild(name: string, options?: IDeleteChildOptions): Result<boolean>;
|
|
206
|
+
/**
|
|
207
|
+
* Deletes this directory from its backing store.
|
|
208
|
+
* The directory must be empty or the operation will fail.
|
|
209
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
210
|
+
*/
|
|
211
|
+
delete(): Result<boolean>;
|
|
212
|
+
}
|
|
96
213
|
/**
|
|
97
214
|
* Type for an item in a file tree.
|
|
98
215
|
* @public
|
|
99
216
|
*/
|
|
100
217
|
export type FileTreeItem<TCT extends string = string> = IFileTreeFileItem<TCT> | IFileTreeDirectoryItem<TCT>;
|
|
218
|
+
/**
|
|
219
|
+
* Type for a mutable item in a file tree.
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
export type MutableFileTreeItem<TCT extends string = string> = IMutableFileTreeFileItem<TCT> | IMutableFileTreeDirectoryItem<TCT>;
|
|
223
|
+
/**
|
|
224
|
+
* A file item that may or may not be mutable at runtime.
|
|
225
|
+
*
|
|
226
|
+
* Use this type for parameters or fields where the code checks for mutability
|
|
227
|
+
* and handles the read-only case gracefully. Use {@link FileTree.IMutableFileTreeFileItem}
|
|
228
|
+
* when mutation is required.
|
|
229
|
+
*
|
|
230
|
+
* Narrow with {@link FileTree.isMutableFileItem} to access mutation methods.
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
export type AnyFileTreeFileItem<TCT extends string = string> = IFileTreeFileItem<TCT> | IMutableFileTreeFileItem<TCT>;
|
|
234
|
+
/**
|
|
235
|
+
* A directory item that may or may not be mutable at runtime.
|
|
236
|
+
*
|
|
237
|
+
* Use this type for parameters or fields where the code checks for mutability
|
|
238
|
+
* and handles the read-only case gracefully. Use {@link FileTree.IMutableFileTreeDirectoryItem}
|
|
239
|
+
* when mutation is required.
|
|
240
|
+
*
|
|
241
|
+
* Narrow with {@link FileTree.isMutableDirectoryItem} to access mutation methods.
|
|
242
|
+
* @public
|
|
243
|
+
*/
|
|
244
|
+
export type AnyFileTreeDirectoryItem<TCT extends string = string> = IFileTreeDirectoryItem<TCT> | IMutableFileTreeDirectoryItem<TCT>;
|
|
101
245
|
/**
|
|
102
246
|
* Common abstraction layer interface for a tree of files
|
|
103
247
|
* (e.g. a file system or a zip file).
|
|
@@ -155,4 +299,94 @@ export interface IFileTreeAccessors<TCT extends string = string> {
|
|
|
155
299
|
*/
|
|
156
300
|
getChildren(path: string): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
157
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Extended accessors interface that supports mutation operations.
|
|
304
|
+
* All mutation methods are required — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
305
|
+
* type guard to check if an accessor supports mutation.
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
export interface IMutableFileTreeAccessors<TCT extends string = string> extends IFileTreeAccessors<TCT> {
|
|
309
|
+
/**
|
|
310
|
+
* Checks if a file at the given path can be saved.
|
|
311
|
+
* @param path - The path to check.
|
|
312
|
+
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
313
|
+
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
314
|
+
*/
|
|
315
|
+
fileIsMutable(path: string): DetailedResult<boolean, SaveDetail>;
|
|
316
|
+
/**
|
|
317
|
+
* Saves the contents to a file at the given path.
|
|
318
|
+
* @param path - The path of the file to save.
|
|
319
|
+
* @param contents - The string contents to save.
|
|
320
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
321
|
+
*/
|
|
322
|
+
saveFileContents(path: string, contents: string): Result<string>;
|
|
323
|
+
/**
|
|
324
|
+
* Deletes a file at the given path.
|
|
325
|
+
* @param path - The path of the file to delete.
|
|
326
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
327
|
+
*/
|
|
328
|
+
deleteFile(path: string): Result<boolean>;
|
|
329
|
+
/**
|
|
330
|
+
* Creates a directory at the given path, including any missing parent directories.
|
|
331
|
+
* @param path - The path of the directory to create.
|
|
332
|
+
* @returns `Success` with the absolute path if created, or `Failure` with an error message.
|
|
333
|
+
*/
|
|
334
|
+
createDirectory(path: string): Result<string>;
|
|
335
|
+
/**
|
|
336
|
+
* Deletes a directory at the given path.
|
|
337
|
+
* The directory must be empty or the operation will fail.
|
|
338
|
+
* @param path - The path of the directory to delete.
|
|
339
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
340
|
+
*/
|
|
341
|
+
deleteDirectory(path: string): Result<boolean>;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Extended accessors interface that supports persistence operations.
|
|
345
|
+
* @public
|
|
346
|
+
*/
|
|
347
|
+
export interface IPersistentFileTreeAccessors<TCT extends string = string> extends IMutableFileTreeAccessors<TCT> {
|
|
348
|
+
/**
|
|
349
|
+
* Synchronize all dirty files to persistent storage.
|
|
350
|
+
* @returns Promise resolving to success or failure
|
|
351
|
+
*/
|
|
352
|
+
syncToDisk(): Promise<Result<void>>;
|
|
353
|
+
/**
|
|
354
|
+
* Check if there are unsaved changes.
|
|
355
|
+
* @returns True if there are dirty files
|
|
356
|
+
*/
|
|
357
|
+
isDirty(): boolean;
|
|
358
|
+
/**
|
|
359
|
+
* Get paths of all files with unsaved changes.
|
|
360
|
+
* @returns Array of dirty file paths
|
|
361
|
+
*/
|
|
362
|
+
getDirtyPaths(): string[];
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Type guard to check if accessors support mutation.
|
|
366
|
+
* @param accessors - The accessors to check.
|
|
367
|
+
* @returns `true` if the accessors implement {@link FileTree.IMutableFileTreeAccessors}.
|
|
368
|
+
* @public
|
|
369
|
+
*/
|
|
370
|
+
export declare function isMutableAccessors<TCT extends string = string>(accessors: IFileTreeAccessors<TCT>): accessors is IMutableFileTreeAccessors<TCT>;
|
|
371
|
+
/**
|
|
372
|
+
* Type guard to check if accessors support persistence.
|
|
373
|
+
* @param accessors - The accessors to check.
|
|
374
|
+
* @returns `true` if the accessors implement {@link FileTree.IPersistentFileTreeAccessors}.
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
export declare function isPersistentAccessors<TCT extends string = string>(accessors: IFileTreeAccessors<TCT>): accessors is IPersistentFileTreeAccessors<TCT>;
|
|
378
|
+
/**
|
|
379
|
+
* Type guard to check if a file item supports mutation.
|
|
380
|
+
* @param item - The file item to check.
|
|
381
|
+
* @returns `true` if the item implements {@link FileTree.IMutableFileTreeFileItem}.
|
|
382
|
+
* @public
|
|
383
|
+
*/
|
|
384
|
+
export declare function isMutableFileItem<TCT extends string = string>(item: AnyFileTreeFileItem<TCT> | FileTreeItem<TCT>): item is IMutableFileTreeFileItem<TCT>;
|
|
385
|
+
/**
|
|
386
|
+
* Type guard to check if a directory item supports mutation.
|
|
387
|
+
* @param item - The directory item to check.
|
|
388
|
+
* @returns `true` if the item implements {@link FileTree.IMutableFileTreeDirectoryItem}.
|
|
389
|
+
* @public
|
|
390
|
+
*/
|
|
391
|
+
export declare function isMutableDirectoryItem<TCT extends string = string>(item: AnyFileTreeDirectoryItem<TCT> | FileTreeItem<TCT>): item is IMutableFileTreeDirectoryItem<TCT>;
|
|
158
392
|
//# sourceMappingURL=fileTreeAccessors.d.ts.map
|
|
@@ -21,4 +21,67 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.isMutableAccessors = isMutableAccessors;
|
|
25
|
+
exports.isPersistentAccessors = isPersistentAccessors;
|
|
26
|
+
exports.isMutableFileItem = isMutableFileItem;
|
|
27
|
+
exports.isMutableDirectoryItem = isMutableDirectoryItem;
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Type Guards
|
|
30
|
+
// ============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* Type guard to check if accessors support mutation.
|
|
33
|
+
* @param accessors - The accessors to check.
|
|
34
|
+
* @returns `true` if the accessors implement {@link FileTree.IMutableFileTreeAccessors}.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
function isMutableAccessors(accessors) {
|
|
38
|
+
const mutable = accessors;
|
|
39
|
+
return (typeof mutable.fileIsMutable === 'function' &&
|
|
40
|
+
typeof mutable.saveFileContents === 'function' &&
|
|
41
|
+
typeof mutable.deleteFile === 'function' &&
|
|
42
|
+
typeof mutable.createDirectory === 'function' &&
|
|
43
|
+
typeof mutable.deleteDirectory === 'function');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to check if accessors support persistence.
|
|
47
|
+
* @param accessors - The accessors to check.
|
|
48
|
+
* @returns `true` if the accessors implement {@link FileTree.IPersistentFileTreeAccessors}.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
function isPersistentAccessors(accessors) {
|
|
52
|
+
const persistent = accessors;
|
|
53
|
+
/* c8 ignore next 6 - no current accessor implements IPersistentFileTreeAccessors */
|
|
54
|
+
return (isMutableAccessors(accessors) &&
|
|
55
|
+
typeof persistent.syncToDisk === 'function' &&
|
|
56
|
+
typeof persistent.isDirty === 'function' &&
|
|
57
|
+
typeof persistent.getDirtyPaths === 'function');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a file item supports mutation.
|
|
61
|
+
* @param item - The file item to check.
|
|
62
|
+
* @returns `true` if the item implements {@link FileTree.IMutableFileTreeFileItem}.
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
function isMutableFileItem(item) {
|
|
66
|
+
const mutable = item;
|
|
67
|
+
return (mutable.type === 'file' &&
|
|
68
|
+
typeof mutable.getIsMutable === 'function' &&
|
|
69
|
+
typeof mutable.setContents === 'function' &&
|
|
70
|
+
typeof mutable.setRawContents === 'function' &&
|
|
71
|
+
typeof mutable.delete === 'function');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Type guard to check if a directory item supports mutation.
|
|
75
|
+
* @param item - The directory item to check.
|
|
76
|
+
* @returns `true` if the item implements {@link FileTree.IMutableFileTreeDirectoryItem}.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
function isMutableDirectoryItem(item) {
|
|
80
|
+
const mutable = item;
|
|
81
|
+
return (mutable.type === 'directory' &&
|
|
82
|
+
typeof mutable.createChildFile === 'function' &&
|
|
83
|
+
typeof mutable.createChildDirectory === 'function' &&
|
|
84
|
+
typeof mutable.deleteChild === 'function' &&
|
|
85
|
+
typeof mutable.delete === 'function');
|
|
86
|
+
}
|
|
24
87
|
//# sourceMappingURL=fileTreeAccessors.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IFilterSpec } from './fileTreeAccessors';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a path is allowed by a mutability configuration.
|
|
4
|
+
* @param path - The path to check.
|
|
5
|
+
* @param mutable - The mutability configuration.
|
|
6
|
+
* @returns `true` if the path is mutable according to the configuration.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPathMutable(path: string, mutable: boolean | IFilterSpec | undefined): boolean;
|
|
10
|
+
//# sourceMappingURL=filterSpec.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.isPathMutable = isPathMutable;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a path matches a single pattern (string or RegExp).
|
|
27
|
+
* @param path - The path to check.
|
|
28
|
+
* @param pattern - The pattern to match against.
|
|
29
|
+
* @returns `true` if the path matches the pattern.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function matchesPattern(path, pattern) {
|
|
33
|
+
if (typeof pattern === 'string') {
|
|
34
|
+
return path === pattern || path.startsWith(pattern + '/') || path.includes(pattern);
|
|
35
|
+
}
|
|
36
|
+
return pattern.test(path);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a path matches any pattern in an array.
|
|
40
|
+
* @param path - The path to check.
|
|
41
|
+
* @param patterns - The patterns to match against.
|
|
42
|
+
* @returns `true` if the path matches any pattern.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
function matchesAny(path, patterns) {
|
|
46
|
+
if (!patterns || patterns.length === 0) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return patterns.some((pattern) => matchesPattern(path, pattern));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a path is allowed by a mutability configuration.
|
|
53
|
+
* @param path - The path to check.
|
|
54
|
+
* @param mutable - The mutability configuration.
|
|
55
|
+
* @returns `true` if the path is mutable according to the configuration.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
function isPathMutable(path, mutable) {
|
|
59
|
+
if (mutable === undefined || mutable === false) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (mutable === true) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const { include, exclude } = mutable;
|
|
66
|
+
// If exclude patterns are specified and path matches, it's not mutable
|
|
67
|
+
if (matchesAny(path, exclude)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
// If include patterns are specified, path must match at least one
|
|
71
|
+
if (include && include.length > 0) {
|
|
72
|
+
return matchesAny(path, include);
|
|
73
|
+
}
|
|
74
|
+
// No include patterns means all paths (not excluded) are mutable
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=filterSpec.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FileTreeItem,
|
|
2
|
-
import { Result } from '@fgv/ts-utils';
|
|
1
|
+
import { FileTreeItem, IFileTreeInitParams, IMutableFileTreeAccessors, SaveDetail } from './fileTreeAccessors';
|
|
2
|
+
import { DetailedResult, Result } from '@fgv/ts-utils';
|
|
3
3
|
/**
|
|
4
|
-
* Implementation of {@link FileTree.
|
|
5
|
-
* file system to access files and directories.
|
|
4
|
+
* Implementation of {@link FileTree.IMutableFileTreeAccessors} that uses the
|
|
5
|
+
* file system to access and modify files and directories.
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
export declare class FsFileTreeAccessors<TCT extends string = string> implements
|
|
8
|
+
export declare class FsFileTreeAccessors<TCT extends string = string> implements IMutableFileTreeAccessors<TCT> {
|
|
9
9
|
/**
|
|
10
10
|
* Optional path prefix to prepend to all paths.
|
|
11
11
|
*/
|
|
@@ -15,6 +15,10 @@ export declare class FsFileTreeAccessors<TCT extends string = string> implements
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
protected readonly _inferContentType: (filePath: string) => Result<TCT | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* The mutability configuration.
|
|
20
|
+
*/
|
|
21
|
+
private readonly _mutable;
|
|
18
22
|
/**
|
|
19
23
|
* Construct a new instance of the {@link FileTree.FsFileTreeAccessors | FsFileTreeAccessors} class.
|
|
20
24
|
* @param params - Optional {@link FileTree.IFileTreeInitParams | initialization parameters}.
|
|
@@ -22,36 +26,56 @@ export declare class FsFileTreeAccessors<TCT extends string = string> implements
|
|
|
22
26
|
*/
|
|
23
27
|
constructor(params?: IFileTreeInitParams<TCT>);
|
|
24
28
|
/**
|
|
25
|
-
* {@
|
|
29
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.resolveAbsolutePath}
|
|
26
30
|
*/
|
|
27
31
|
resolveAbsolutePath(...paths: string[]): string;
|
|
28
32
|
/**
|
|
29
|
-
* {@
|
|
33
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.getExtension}
|
|
30
34
|
*/
|
|
31
35
|
getExtension(itemPath: string): string;
|
|
32
36
|
/**
|
|
33
|
-
* {@
|
|
37
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.getBaseName}
|
|
34
38
|
*/
|
|
35
39
|
getBaseName(itemPath: string, suffix?: string): string;
|
|
36
40
|
/**
|
|
37
|
-
* {@
|
|
41
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.joinPaths}
|
|
38
42
|
*/
|
|
39
43
|
joinPaths(...paths: string[]): string;
|
|
40
44
|
/**
|
|
41
|
-
* {@
|
|
45
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.getItem}
|
|
42
46
|
*/
|
|
43
47
|
getItem(itemPath: string): Result<FileTreeItem<TCT>>;
|
|
44
48
|
/**
|
|
45
|
-
* {@
|
|
49
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.getFileContents}
|
|
46
50
|
*/
|
|
47
51
|
getFileContents(filePath: string): Result<string>;
|
|
48
52
|
/**
|
|
49
|
-
* {@
|
|
53
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.getFileContentType}
|
|
50
54
|
*/
|
|
51
55
|
getFileContentType(filePath: string, provided?: string): Result<TCT | undefined>;
|
|
52
56
|
/**
|
|
53
|
-
* {@
|
|
57
|
+
* {@inheritDoc FileTree.IFileTreeAccessors.getChildren}
|
|
54
58
|
*/
|
|
55
59
|
getChildren(dirPath: string): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
60
|
+
/**
|
|
61
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.fileIsMutable}
|
|
62
|
+
*/
|
|
63
|
+
fileIsMutable(path: string): DetailedResult<boolean, SaveDetail>;
|
|
64
|
+
/**
|
|
65
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.saveFileContents}
|
|
66
|
+
*/
|
|
67
|
+
saveFileContents(path: string, contents: string): Result<string>;
|
|
68
|
+
/**
|
|
69
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.deleteFile}
|
|
70
|
+
*/
|
|
71
|
+
deleteFile(path: string): Result<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.createDirectory}
|
|
74
|
+
*/
|
|
75
|
+
createDirectory(dirPath: string): Result<string>;
|
|
76
|
+
/**
|
|
77
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.deleteDirectory}
|
|
78
|
+
*/
|
|
79
|
+
deleteDirectory(dirPath: string): Result<boolean>;
|
|
56
80
|
}
|
|
57
81
|
//# sourceMappingURL=fsTree.d.ts.map
|