@fgv/ts-extras 5.0.2 → 5.1.0-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/dist/index.browser.js +6 -2
- package/dist/index.js +5 -1
- package/dist/packlets/ai-assist/apiClient.js +484 -0
- package/dist/packlets/ai-assist/converters.js +121 -0
- package/dist/packlets/ai-assist/index.js +10 -0
- package/dist/packlets/ai-assist/model.js +90 -0
- package/dist/packlets/ai-assist/registry.js +145 -0
- package/dist/packlets/ai-assist/toolFormats.js +160 -0
- package/dist/packlets/crypto-utils/constants.js +48 -0
- package/dist/packlets/crypto-utils/converters.js +155 -0
- package/dist/packlets/crypto-utils/directEncryptionProvider.js +86 -0
- package/dist/packlets/crypto-utils/encryptedFile.js +161 -0
- package/dist/packlets/crypto-utils/index.browser.js +41 -0
- package/dist/packlets/crypto-utils/index.js +41 -0
- package/dist/packlets/crypto-utils/keystore/converters.js +84 -0
- package/dist/packlets/crypto-utils/keystore/index.js +31 -0
- package/dist/packlets/crypto-utils/keystore/keyStore.js +758 -0
- package/dist/packlets/crypto-utils/keystore/model.js +64 -0
- package/dist/packlets/crypto-utils/model.js +39 -0
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js +159 -0
- package/dist/packlets/experimental/formatter.js +1 -1
- package/dist/packlets/mustache/index.js +23 -0
- package/dist/packlets/mustache/interfaces.js +25 -0
- package/dist/packlets/mustache/mustacheTemplate.js +242 -0
- package/dist/packlets/record-jar/recordJarHelpers.js +1 -1
- package/dist/packlets/yaml/converters.js +46 -0
- package/dist/packlets/yaml/index.js +23 -0
- package/dist/packlets/zip-file-tree/index.js +1 -0
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +43 -2
- package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +40 -0
- package/dist/ts-extras.d.ts +1990 -112
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +3 -1
- package/lib/index.browser.js +6 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +9 -1
- package/lib/packlets/ai-assist/apiClient.d.ts +60 -0
- package/lib/packlets/ai-assist/apiClient.js +488 -0
- package/lib/packlets/ai-assist/converters.d.ts +55 -0
- package/lib/packlets/ai-assist/converters.js +124 -0
- package/lib/packlets/ai-assist/index.d.ts +10 -0
- package/lib/packlets/ai-assist/index.js +33 -0
- package/lib/packlets/ai-assist/model.d.ts +222 -0
- package/lib/packlets/ai-assist/model.js +95 -0
- package/lib/packlets/ai-assist/registry.d.ts +25 -0
- package/lib/packlets/ai-assist/registry.js +150 -0
- package/lib/packlets/ai-assist/toolFormats.d.ts +44 -0
- package/lib/packlets/ai-assist/toolFormats.js +166 -0
- package/lib/packlets/crypto-utils/constants.d.ts +26 -0
- package/lib/packlets/crypto-utils/constants.js +51 -0
- package/lib/packlets/crypto-utils/converters.d.ts +58 -0
- package/lib/packlets/crypto-utils/converters.js +192 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts +69 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.js +90 -0
- package/lib/packlets/crypto-utils/encryptedFile.d.ts +88 -0
- package/lib/packlets/crypto-utils/encryptedFile.js +201 -0
- package/lib/packlets/crypto-utils/index.browser.d.ts +14 -0
- package/lib/packlets/crypto-utils/index.browser.js +91 -0
- package/lib/packlets/crypto-utils/index.d.ts +15 -0
- package/lib/packlets/crypto-utils/index.js +88 -0
- package/lib/packlets/crypto-utils/keystore/converters.d.ts +29 -0
- package/lib/packlets/crypto-utils/keystore/converters.js +87 -0
- package/lib/packlets/crypto-utils/keystore/index.d.ts +9 -0
- package/lib/packlets/crypto-utils/keystore/index.js +71 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +239 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.js +795 -0
- package/lib/packlets/crypto-utils/keystore/model.d.ts +245 -0
- package/lib/packlets/crypto-utils/keystore/model.js +68 -0
- package/lib/packlets/crypto-utils/model.d.ts +236 -0
- package/lib/packlets/crypto-utils/model.js +76 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +62 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js +196 -0
- package/lib/packlets/experimental/formatter.d.ts +1 -1
- package/lib/packlets/experimental/formatter.js +1 -1
- package/lib/packlets/mustache/index.d.ts +3 -0
- package/lib/packlets/mustache/index.js +27 -0
- package/lib/packlets/mustache/interfaces.d.ts +97 -0
- package/lib/packlets/mustache/interfaces.js +26 -0
- package/lib/packlets/mustache/mustacheTemplate.d.ts +76 -0
- package/lib/packlets/mustache/mustacheTemplate.js +249 -0
- package/lib/packlets/record-jar/recordJarHelpers.js +1 -1
- package/lib/packlets/yaml/converters.d.ts +9 -0
- package/lib/packlets/yaml/converters.js +82 -0
- package/lib/packlets/yaml/index.d.ts +2 -0
- package/lib/packlets/yaml/index.js +39 -0
- package/lib/packlets/zip-file-tree/index.d.ts +1 -0
- package/lib/packlets/zip-file-tree/index.js +15 -0
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +31 -2
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +42 -1
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +27 -0
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +43 -0
- package/package.json +37 -18
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* SOFTWARE.
|
|
21
21
|
*/
|
|
22
22
|
import { unzipSync, unzip } from 'fflate';
|
|
23
|
-
import { succeed, fail, captureResult } from '@fgv/ts-utils';
|
|
23
|
+
import { succeed, fail, captureResult, failWithDetail, Success } from '@fgv/ts-utils';
|
|
24
24
|
/**
|
|
25
25
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
26
26
|
* @public
|
|
@@ -58,6 +58,30 @@ export class ZipFileItem {
|
|
|
58
58
|
this.extension = accessors.getExtension(zipFilePath);
|
|
59
59
|
this.baseName = accessors.getBaseName(zipFilePath, this.extension);
|
|
60
60
|
}
|
|
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
|
+
}
|
|
61
85
|
/**
|
|
62
86
|
* Sets the content type of the file.
|
|
63
87
|
* @param contentType - The content type of the file.
|
|
@@ -177,7 +201,7 @@ export class ZipFileTreeAccessors {
|
|
|
177
201
|
resolve(succeed(new ZipFileTreeAccessors(files, normalizedParams)));
|
|
178
202
|
}
|
|
179
203
|
});
|
|
180
|
-
/* c8 ignore next
|
|
204
|
+
/* c8 ignore next 5 - defensive coding: fflate reports errors via callback, not exceptions */
|
|
181
205
|
}
|
|
182
206
|
catch (error) {
|
|
183
207
|
resolve(fail(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`));
|
|
@@ -238,6 +262,23 @@ export class ZipFileTreeAccessors {
|
|
|
238
262
|
this._itemCache.set(absolutePath, item);
|
|
239
263
|
});
|
|
240
264
|
}
|
|
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
|
+
}
|
|
241
282
|
/**
|
|
242
283
|
* Resolves paths to an absolute path.
|
|
243
284
|
*/
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { zipSync, strToU8 } from 'fflate';
|
|
23
|
+
import { captureResult } from '@fgv/ts-utils';
|
|
24
|
+
/**
|
|
25
|
+
* Creates a zip file from an array of text files.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export function createZipFromTextFiles(files, options) {
|
|
29
|
+
return captureResult(() => {
|
|
30
|
+
var _a;
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const f of files) {
|
|
33
|
+
const normalizedPath = f.path.replace(/^\/+/, '');
|
|
34
|
+
out[normalizedPath] = strToU8(f.contents);
|
|
35
|
+
}
|
|
36
|
+
return zipSync(out, { level: (_a = options === null || options === void 0 ? void 0 : options.level) !== null && _a !== void 0 ? _a : 6 });
|
|
37
|
+
/* c8 ignore next - defensive: zipSync only throws on internal library errors */
|
|
38
|
+
}).withErrorFormat((e) => `Failed to create zip: ${e}`);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=zipFileTreeWriter.js.map
|