@fgv/ts-extras 5.1.0-0 → 5.1.0-2
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.
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
* SOFTWARE.
|
|
21
21
|
*/
|
|
22
22
|
import { unzipSync, unzip } from 'fflate';
|
|
23
|
-
import { succeed, fail, captureResult
|
|
23
|
+
import { succeed, fail, captureResult } from '@fgv/ts-utils';
|
|
24
24
|
/**
|
|
25
25
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
26
|
+
* ZIP files are read-only, so this item does not support mutation.
|
|
27
|
+
* Use {@link FileTree.isMutableFileItem | isMutableFileItem} to check before attempting mutations.
|
|
26
28
|
* @public
|
|
27
29
|
*/
|
|
28
30
|
export class ZipFileItem {
|
|
@@ -58,30 +60,6 @@ export class ZipFileItem {
|
|
|
58
60
|
this.extension = accessors.getExtension(zipFilePath);
|
|
59
61
|
this.baseName = accessors.getBaseName(zipFilePath, this.extension);
|
|
60
62
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
63
|
-
*/
|
|
64
|
-
getIsMutable() {
|
|
65
|
-
return this._accessors.fileIsMutable(this.absolutePath);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Sets the contents of the file as parsed JSON.
|
|
69
|
-
* @param json - The JSON to set as the contents of the file.
|
|
70
|
-
* @returns A Result indicating success or failure.
|
|
71
|
-
*/
|
|
72
|
-
setContents(json) {
|
|
73
|
-
return captureResult(() => JSON.stringify(json, null, 2)).onSuccess((contents) => this.setRawContents(contents).onSuccess(() => Success.with(json)));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Sets the contents of the file as a string.
|
|
77
|
-
* @param contents - The string to set as the contents of the file.
|
|
78
|
-
* @returns A Result indicating success or failure.
|
|
79
|
-
*/
|
|
80
|
-
setRawContents(contents) {
|
|
81
|
-
return this.getIsMutable().asResult.onSuccess(() =>
|
|
82
|
-
/* c8 ignore next - unreachable: ZIP files are always read-only */
|
|
83
|
-
this._accessors.saveFileContents(this.absolutePath, contents));
|
|
84
|
-
}
|
|
85
63
|
/**
|
|
86
64
|
* Sets the content type of the file.
|
|
87
65
|
* @param contentType - The content type of the file.
|
|
@@ -142,7 +120,9 @@ export class ZipDirectoryItem {
|
|
|
142
120
|
}
|
|
143
121
|
}
|
|
144
122
|
/**
|
|
145
|
-
*
|
|
123
|
+
* Read-only file tree accessors for ZIP archives.
|
|
124
|
+
* ZIP archives are read-only by design — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
125
|
+
* to check before attempting mutations.
|
|
146
126
|
* @public
|
|
147
127
|
*/
|
|
148
128
|
export class ZipFileTreeAccessors {
|
|
@@ -262,23 +242,6 @@ export class ZipFileTreeAccessors {
|
|
|
262
242
|
this._itemCache.set(absolutePath, item);
|
|
263
243
|
});
|
|
264
244
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
267
|
-
* @param path - The path of the file.
|
|
268
|
-
* @returns A `DetailedResult` indicating success or failure.
|
|
269
|
-
*/
|
|
270
|
-
fileIsMutable(__path) {
|
|
271
|
-
return failWithDetail('ZIP files are read-only', 'not-supported');
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Saves the contents of a file.
|
|
275
|
-
* @param path - The path of the file.
|
|
276
|
-
* @param contents - The contents of the file.
|
|
277
|
-
* @returns A `Result` indicating success or failure.
|
|
278
|
-
*/
|
|
279
|
-
saveFileContents(__path, __contents) {
|
|
280
|
-
return failWithDetail('ZIP files are read-only', 'not-supported');
|
|
281
|
-
}
|
|
282
245
|
/**
|
|
283
246
|
* Resolves paths to an absolute path.
|
|
284
247
|
*/
|
package/dist/ts-extras.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Conversion } from '@fgv/ts-utils';
|
|
2
2
|
import { Converter } from '@fgv/ts-utils';
|
|
3
|
-
import { DetailedResult } from '@fgv/ts-utils';
|
|
4
3
|
import { FileTree } from '@fgv/ts-json-base';
|
|
5
4
|
import { Hash as Hash_2 } from '@fgv/ts-utils';
|
|
6
5
|
import { JsonValue } from '@fgv/ts-json-base';
|
|
@@ -2338,6 +2337,8 @@ declare class ZipDirectoryItem<TCT extends string = string> implements FileTree.
|
|
|
2338
2337
|
|
|
2339
2338
|
/**
|
|
2340
2339
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
2340
|
+
* ZIP files are read-only, so this item does not support mutation.
|
|
2341
|
+
* Use {@link FileTree.isMutableFileItem | isMutableFileItem} to check before attempting mutations.
|
|
2341
2342
|
* @public
|
|
2342
2343
|
*/
|
|
2343
2344
|
declare class ZipFileItem<TCT extends string = string> implements FileTree.IFileTreeFileItem<TCT> {
|
|
@@ -2388,22 +2389,6 @@ declare class ZipFileItem<TCT extends string = string> implements FileTree.IFile
|
|
|
2388
2389
|
* @param accessors - The ZIP file tree accessors.
|
|
2389
2390
|
*/
|
|
2390
2391
|
constructor(zipFilePath: string, contents: string, accessors: ZipFileTreeAccessors<TCT>);
|
|
2391
|
-
/**
|
|
2392
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
2393
|
-
*/
|
|
2394
|
-
getIsMutable(): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
2395
|
-
/**
|
|
2396
|
-
* Sets the contents of the file as parsed JSON.
|
|
2397
|
-
* @param json - The JSON to set as the contents of the file.
|
|
2398
|
-
* @returns A Result indicating success or failure.
|
|
2399
|
-
*/
|
|
2400
|
-
setContents(json: JsonValue): Result<JsonValue>;
|
|
2401
|
-
/**
|
|
2402
|
-
* Sets the contents of the file as a string.
|
|
2403
|
-
* @param contents - The string to set as the contents of the file.
|
|
2404
|
-
* @returns A Result indicating success or failure.
|
|
2405
|
-
*/
|
|
2406
|
-
setRawContents(contents: string): Result<string>;
|
|
2407
2392
|
/**
|
|
2408
2393
|
* Sets the content type of the file.
|
|
2409
2394
|
* @param contentType - The content type of the file.
|
|
@@ -2434,10 +2419,12 @@ declare namespace ZipFileTree {
|
|
|
2434
2419
|
export { ZipFileTree }
|
|
2435
2420
|
|
|
2436
2421
|
/**
|
|
2437
|
-
*
|
|
2422
|
+
* Read-only file tree accessors for ZIP archives.
|
|
2423
|
+
* ZIP archives are read-only by design — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
2424
|
+
* to check before attempting mutations.
|
|
2438
2425
|
* @public
|
|
2439
2426
|
*/
|
|
2440
|
-
declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.
|
|
2427
|
+
declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.IFileTreeAccessors<TCT> {
|
|
2441
2428
|
/**
|
|
2442
2429
|
* The unzipped file data.
|
|
2443
2430
|
*/
|
|
@@ -2509,19 +2496,6 @@ declare class ZipFileTreeAccessors<TCT extends string = string> implements FileT
|
|
|
2509
2496
|
* Builds the cache of all items in the ZIP archive.
|
|
2510
2497
|
*/
|
|
2511
2498
|
private _buildItemCache;
|
|
2512
|
-
/**
|
|
2513
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
2514
|
-
* @param path - The path of the file.
|
|
2515
|
-
* @returns A `DetailedResult` indicating success or failure.
|
|
2516
|
-
*/
|
|
2517
|
-
fileIsMutable(__path: string): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
2518
|
-
/**
|
|
2519
|
-
* Saves the contents of a file.
|
|
2520
|
-
* @param path - The path of the file.
|
|
2521
|
-
* @param contents - The contents of the file.
|
|
2522
|
-
* @returns A `Result` indicating success or failure.
|
|
2523
|
-
*/
|
|
2524
|
-
saveFileContents(__path: string, __contents: string): Result<string>;
|
|
2525
2499
|
/**
|
|
2526
2500
|
* Resolves paths to an absolute path.
|
|
2527
2501
|
*/
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Result, Converter, Validator
|
|
1
|
+
import { Result, Converter, Validator } from '@fgv/ts-utils';
|
|
2
2
|
import { FileTree, JsonValue } from '@fgv/ts-json-base';
|
|
3
3
|
/**
|
|
4
4
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
5
|
+
* ZIP files are read-only, so this item does not support mutation.
|
|
6
|
+
* Use {@link FileTree.isMutableFileItem | isMutableFileItem} to check before attempting mutations.
|
|
5
7
|
* @public
|
|
6
8
|
*/
|
|
7
9
|
export declare class ZipFileItem<TCT extends string = string> implements FileTree.IFileTreeFileItem<TCT> {
|
|
@@ -52,22 +54,6 @@ export declare class ZipFileItem<TCT extends string = string> implements FileTre
|
|
|
52
54
|
* @param accessors - The ZIP file tree accessors.
|
|
53
55
|
*/
|
|
54
56
|
constructor(zipFilePath: string, contents: string, accessors: ZipFileTreeAccessors<TCT>);
|
|
55
|
-
/**
|
|
56
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
57
|
-
*/
|
|
58
|
-
getIsMutable(): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
59
|
-
/**
|
|
60
|
-
* Sets the contents of the file as parsed JSON.
|
|
61
|
-
* @param json - The JSON to set as the contents of the file.
|
|
62
|
-
* @returns A Result indicating success or failure.
|
|
63
|
-
*/
|
|
64
|
-
setContents(json: JsonValue): Result<JsonValue>;
|
|
65
|
-
/**
|
|
66
|
-
* Sets the contents of the file as a string.
|
|
67
|
-
* @param contents - The string to set as the contents of the file.
|
|
68
|
-
* @returns A Result indicating success or failure.
|
|
69
|
-
*/
|
|
70
|
-
setRawContents(contents: string): Result<string>;
|
|
71
57
|
/**
|
|
72
58
|
* Sets the content type of the file.
|
|
73
59
|
* @param contentType - The content type of the file.
|
|
@@ -116,10 +102,12 @@ export declare class ZipDirectoryItem<TCT extends string = string> implements Fi
|
|
|
116
102
|
getChildren(): Result<ReadonlyArray<FileTree.FileTreeItem<TCT>>>;
|
|
117
103
|
}
|
|
118
104
|
/**
|
|
119
|
-
*
|
|
105
|
+
* Read-only file tree accessors for ZIP archives.
|
|
106
|
+
* ZIP archives are read-only by design — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
107
|
+
* to check before attempting mutations.
|
|
120
108
|
* @public
|
|
121
109
|
*/
|
|
122
|
-
export declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.
|
|
110
|
+
export declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.IFileTreeAccessors<TCT> {
|
|
123
111
|
/**
|
|
124
112
|
* The unzipped file data.
|
|
125
113
|
*/
|
|
@@ -191,19 +179,6 @@ export declare class ZipFileTreeAccessors<TCT extends string = string> implement
|
|
|
191
179
|
* Builds the cache of all items in the ZIP archive.
|
|
192
180
|
*/
|
|
193
181
|
private _buildItemCache;
|
|
194
|
-
/**
|
|
195
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
196
|
-
* @param path - The path of the file.
|
|
197
|
-
* @returns A `DetailedResult` indicating success or failure.
|
|
198
|
-
*/
|
|
199
|
-
fileIsMutable(__path: string): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
200
|
-
/**
|
|
201
|
-
* Saves the contents of a file.
|
|
202
|
-
* @param path - The path of the file.
|
|
203
|
-
* @param contents - The contents of the file.
|
|
204
|
-
* @returns A `Result` indicating success or failure.
|
|
205
|
-
*/
|
|
206
|
-
saveFileContents(__path: string, __contents: string): Result<string>;
|
|
207
182
|
/**
|
|
208
183
|
* Resolves paths to an absolute path.
|
|
209
184
|
*/
|
|
@@ -26,6 +26,8 @@ const fflate_1 = require("fflate");
|
|
|
26
26
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
27
|
/**
|
|
28
28
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
29
|
+
* ZIP files are read-only, so this item does not support mutation.
|
|
30
|
+
* Use {@link FileTree.isMutableFileItem | isMutableFileItem} to check before attempting mutations.
|
|
29
31
|
* @public
|
|
30
32
|
*/
|
|
31
33
|
class ZipFileItem {
|
|
@@ -61,30 +63,6 @@ class ZipFileItem {
|
|
|
61
63
|
this.extension = accessors.getExtension(zipFilePath);
|
|
62
64
|
this.baseName = accessors.getBaseName(zipFilePath, this.extension);
|
|
63
65
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
66
|
-
*/
|
|
67
|
-
getIsMutable() {
|
|
68
|
-
return this._accessors.fileIsMutable(this.absolutePath);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Sets the contents of the file as parsed JSON.
|
|
72
|
-
* @param json - The JSON to set as the contents of the file.
|
|
73
|
-
* @returns A Result indicating success or failure.
|
|
74
|
-
*/
|
|
75
|
-
setContents(json) {
|
|
76
|
-
return (0, ts_utils_1.captureResult)(() => JSON.stringify(json, null, 2)).onSuccess((contents) => this.setRawContents(contents).onSuccess(() => ts_utils_1.Success.with(json)));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Sets the contents of the file as a string.
|
|
80
|
-
* @param contents - The string to set as the contents of the file.
|
|
81
|
-
* @returns A Result indicating success or failure.
|
|
82
|
-
*/
|
|
83
|
-
setRawContents(contents) {
|
|
84
|
-
return this.getIsMutable().asResult.onSuccess(() =>
|
|
85
|
-
/* c8 ignore next - unreachable: ZIP files are always read-only */
|
|
86
|
-
this._accessors.saveFileContents(this.absolutePath, contents));
|
|
87
|
-
}
|
|
88
66
|
/**
|
|
89
67
|
* Sets the content type of the file.
|
|
90
68
|
* @param contentType - The content type of the file.
|
|
@@ -147,7 +125,9 @@ class ZipDirectoryItem {
|
|
|
147
125
|
}
|
|
148
126
|
exports.ZipDirectoryItem = ZipDirectoryItem;
|
|
149
127
|
/**
|
|
150
|
-
*
|
|
128
|
+
* Read-only file tree accessors for ZIP archives.
|
|
129
|
+
* ZIP archives are read-only by design — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
130
|
+
* to check before attempting mutations.
|
|
151
131
|
* @public
|
|
152
132
|
*/
|
|
153
133
|
class ZipFileTreeAccessors {
|
|
@@ -267,23 +247,6 @@ class ZipFileTreeAccessors {
|
|
|
267
247
|
this._itemCache.set(absolutePath, item);
|
|
268
248
|
});
|
|
269
249
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Returns a boolean indicating whether this file can be saved.
|
|
272
|
-
* @param path - The path of the file.
|
|
273
|
-
* @returns A `DetailedResult` indicating success or failure.
|
|
274
|
-
*/
|
|
275
|
-
fileIsMutable(__path) {
|
|
276
|
-
return (0, ts_utils_1.failWithDetail)('ZIP files are read-only', 'not-supported');
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Saves the contents of a file.
|
|
280
|
-
* @param path - The path of the file.
|
|
281
|
-
* @param contents - The contents of the file.
|
|
282
|
-
* @returns A `Result` indicating success or failure.
|
|
283
|
-
*/
|
|
284
|
-
saveFileContents(__path, __contents) {
|
|
285
|
-
return (0, ts_utils_1.failWithDetail)('ZIP files are read-only', 'not-supported');
|
|
286
|
-
}
|
|
287
250
|
/**
|
|
288
251
|
* Resolves paths to an absolute path.
|
|
289
252
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-extras",
|
|
3
|
-
"version": "5.1.0-
|
|
3
|
+
"version": "5.1.0-2",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-extras.d.ts",
|
|
@@ -42,6 +42,18 @@
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "heft build --clean",
|
|
47
|
+
"clean": "heft clean",
|
|
48
|
+
"test": "heft test --clean",
|
|
49
|
+
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
50
|
+
"build-all": "rushx build; rushx build-docs",
|
|
51
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
52
|
+
"clean-jest": "jest --clear-cache",
|
|
53
|
+
"coverage": "jest --coverage",
|
|
54
|
+
"lint": "eslint src --ext .ts",
|
|
55
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
56
|
+
},
|
|
45
57
|
"sideEffects": false,
|
|
46
58
|
"keywords": [
|
|
47
59
|
"typescript",
|
|
@@ -54,6 +66,7 @@
|
|
|
54
66
|
},
|
|
55
67
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-extras#ts-utils",
|
|
56
68
|
"devDependencies": {
|
|
69
|
+
"@fgv/heft-dual-rig": "workspace:*",
|
|
57
70
|
"@jest/expect-utils": "^29.7.0",
|
|
58
71
|
"@microsoft/api-documenter": "^7.28.2",
|
|
59
72
|
"@microsoft/api-extractor": "^7.55.2",
|
|
@@ -83,38 +96,25 @@
|
|
|
83
96
|
"@types/heft-jest": "1.0.6",
|
|
84
97
|
"@rushstack/heft-jest-plugin": "1.2.6",
|
|
85
98
|
"eslint-plugin-tsdoc": "~0.5.2",
|
|
99
|
+
"@fgv/ts-utils-jest": "workspace:*",
|
|
100
|
+
"@fgv/ts-utils": "workspace:*",
|
|
86
101
|
"@types/js-yaml": "~4.0.9",
|
|
87
102
|
"typedoc": "~0.28.16",
|
|
88
|
-
"typedoc-plugin-markdown": "~4.9.0"
|
|
89
|
-
"@fgv/ts-utils-jest": "5.1.0-0",
|
|
90
|
-
"@fgv/heft-dual-rig": "0.1.0",
|
|
91
|
-
"@fgv/ts-utils": "5.1.0-0"
|
|
103
|
+
"typedoc-plugin-markdown": "~4.9.0"
|
|
92
104
|
},
|
|
93
105
|
"dependencies": {
|
|
94
106
|
"luxon": "^3.7.2",
|
|
95
107
|
"mustache": "^4.2.0",
|
|
96
108
|
"papaparse": "^5.4.1",
|
|
97
109
|
"fflate": "~0.8.2",
|
|
98
|
-
"
|
|
99
|
-
"
|
|
110
|
+
"@fgv/ts-json-base": "workspace:*",
|
|
111
|
+
"js-yaml": "~4.1.1"
|
|
100
112
|
},
|
|
101
113
|
"peerDependencies": {
|
|
102
|
-
"@fgv/ts-utils": "
|
|
114
|
+
"@fgv/ts-utils": "workspace:*"
|
|
103
115
|
},
|
|
104
116
|
"repository": {
|
|
105
117
|
"type": "git",
|
|
106
118
|
"url": "https://github.com/ErikFortune/fgv.git"
|
|
107
|
-
},
|
|
108
|
-
"scripts": {
|
|
109
|
-
"build": "heft build --clean",
|
|
110
|
-
"clean": "heft clean",
|
|
111
|
-
"test": "heft test --clean",
|
|
112
|
-
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
113
|
-
"build-all": "rushx build; rushx build-docs",
|
|
114
|
-
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
115
|
-
"clean-jest": "jest --clear-cache",
|
|
116
|
-
"coverage": "jest --coverage",
|
|
117
|
-
"lint": "eslint src --ext .ts",
|
|
118
|
-
"fixlint": "eslint src --ext .ts --fix"
|
|
119
119
|
}
|
|
120
|
-
}
|
|
120
|
+
}
|