@fgv/ts-extras 5.0.0-2 → 5.0.0-20

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.
Files changed (62) hide show
  1. package/.vscode/settings.json +27 -0
  2. package/config/api-extractor.json +343 -0
  3. package/config/rig.json +16 -0
  4. package/dist/ts-extras.d.ts +11 -4
  5. package/dist/tsdoc-metadata.json +1 -1
  6. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +11 -4
  7. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +57 -35
  8. package/lib/test/unit/converters.test.d.ts +2 -0
  9. package/lib/test/unit/csvHelpers.test.d.ts +2 -0
  10. package/lib/test/unit/extendedArray.test.d.ts +2 -0
  11. package/lib/test/unit/formatter.test.d.ts +2 -0
  12. package/lib/test/unit/md5Normalizer.test.d.ts +2 -0
  13. package/lib/test/unit/rangeOf.test.d.ts +2 -0
  14. package/lib/test/unit/recordJarHelpers.test.d.ts +2 -0
  15. package/lib/test/unit/zipFileTreeAccessors.test.d.ts +2 -0
  16. package/package.json +14 -15
  17. package/src/index.ts +31 -0
  18. package/src/packlets/conversion/converters.ts +124 -0
  19. package/src/packlets/conversion/index.ts +25 -0
  20. package/src/packlets/csv/csvHelpers.ts +58 -0
  21. package/src/packlets/csv/index.ts +23 -0
  22. package/src/packlets/experimental/extendedArray.ts +110 -0
  23. package/src/packlets/experimental/formatter.ts +114 -0
  24. package/src/packlets/experimental/index.ts +25 -0
  25. package/src/packlets/experimental/rangeOf.ts +222 -0
  26. package/src/packlets/hash/index.ts +23 -0
  27. package/src/packlets/hash/md5Normalizer.ts +38 -0
  28. package/src/packlets/record-jar/index.ts +23 -0
  29. package/src/packlets/record-jar/recordJarHelpers.ts +278 -0
  30. package/src/packlets/zip-file-tree/index.ts +33 -0
  31. package/src/packlets/zip-file-tree/zipFileTreeAccessors.ts +404 -0
  32. package/CHANGELOG.md +0 -98
  33. package/lib/index.d.ts.map +0 -1
  34. package/lib/index.js.map +0 -1
  35. package/lib/packlets/conversion/converters.d.ts.map +0 -1
  36. package/lib/packlets/conversion/converters.js.map +0 -1
  37. package/lib/packlets/conversion/index.d.ts.map +0 -1
  38. package/lib/packlets/conversion/index.js.map +0 -1
  39. package/lib/packlets/csv/csvHelpers.d.ts.map +0 -1
  40. package/lib/packlets/csv/csvHelpers.js.map +0 -1
  41. package/lib/packlets/csv/index.d.ts.map +0 -1
  42. package/lib/packlets/csv/index.js.map +0 -1
  43. package/lib/packlets/experimental/extendedArray.d.ts.map +0 -1
  44. package/lib/packlets/experimental/extendedArray.js.map +0 -1
  45. package/lib/packlets/experimental/formatter.d.ts.map +0 -1
  46. package/lib/packlets/experimental/formatter.js.map +0 -1
  47. package/lib/packlets/experimental/index.d.ts.map +0 -1
  48. package/lib/packlets/experimental/index.js.map +0 -1
  49. package/lib/packlets/experimental/rangeOf.d.ts.map +0 -1
  50. package/lib/packlets/experimental/rangeOf.js.map +0 -1
  51. package/lib/packlets/hash/index.d.ts.map +0 -1
  52. package/lib/packlets/hash/index.js.map +0 -1
  53. package/lib/packlets/hash/md5Normalizer.d.ts.map +0 -1
  54. package/lib/packlets/hash/md5Normalizer.js.map +0 -1
  55. package/lib/packlets/record-jar/index.d.ts.map +0 -1
  56. package/lib/packlets/record-jar/index.js.map +0 -1
  57. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +0 -1
  58. package/lib/packlets/record-jar/recordJarHelpers.js.map +0 -1
  59. package/lib/packlets/zip-file-tree/index.d.ts.map +0 -1
  60. package/lib/packlets/zip-file-tree/index.js.map +0 -1
  61. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts.map +0 -1
  62. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ {
2
+ "typescript.tsdk": "node_modules\\typescript\\lib",
3
+ "search.exclude": {
4
+ "**/boneyard": true
5
+ },
6
+ "files.exclude": {
7
+ "**/boneyard/**/*.ts": true
8
+ },
9
+ "cSpell.words": [
10
+ "badp",
11
+ "dflt",
12
+ "Eulers",
13
+ "fixlint",
14
+ "furst",
15
+ "luxon",
16
+ "nums",
17
+ "oopsy",
18
+ "papaparse",
19
+ "prefixp",
20
+ "TCONV",
21
+ "TDEST",
22
+ "TELEM",
23
+ "TSRC",
24
+ "TTOELEM",
25
+ "xyzzy"
26
+ ]
27
+ }
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Config file for API Extractor. For more info, please visit: https://api-extractor.com
3
+ */
4
+ {
5
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
6
+ /**
7
+ * Optionally specifies another JSON config file that this file extends from. This provides a way for
8
+ * standard settings to be shared across multiple projects.
9
+ *
10
+ * If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains
11
+ * the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
12
+ * resolved using NodeJS require().
13
+ *
14
+ * SUPPORTED TOKENS: none
15
+ * DEFAULT VALUE: ""
16
+ */
17
+ // "extends": "./shared/api-extractor-base.json"
18
+ // "extends": "my-package/include/api-extractor-base.json"
19
+ /**
20
+ * Determines the "<projectFolder>" token that can be used with other config file settings. The project folder
21
+ * typically contains the tsconfig.json and package.json config files, but the path is user-defined.
22
+ *
23
+ * The path is resolved relative to the folder of the config file that contains the setting.
24
+ *
25
+ * The default value for "projectFolder" is the token "<lookup>", which means the folder is determined by traversing
26
+ * parent folders, starting from the folder containing api-extractor.json, and stopping at the first folder
27
+ * that contains a tsconfig.json file. If a tsconfig.json file cannot be found in this way, then an error
28
+ * will be reported.
29
+ *
30
+ * SUPPORTED TOKENS: <lookup>
31
+ * DEFAULT VALUE: "<lookup>"
32
+ */
33
+ "projectFolder": "..",
34
+ /**
35
+ * (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
36
+ * analyzes the symbols exported by this module.
37
+ *
38
+ * The file extension must be ".d.ts" and not ".ts".
39
+ *
40
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
41
+ * prepend a folder token such as "<projectFolder>".
42
+ *
43
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
44
+ */
45
+ "mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
46
+ /**
47
+ * A list of NPM package names whose exports should be treated as part of this package.
48
+ *
49
+ * For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
50
+ * and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
51
+ * of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
52
+ * imports library2. To avoid this, we can specify:
53
+ *
54
+ * "bundledPackages": [ "library2" ],
55
+ *
56
+ * This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
57
+ * local files for library1.
58
+ */
59
+ "bundledPackages": [],
60
+ /**
61
+ * Determines how the TypeScript compiler engine will be invoked by API Extractor.
62
+ */
63
+ "compiler": {
64
+ /**
65
+ * Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project.
66
+ *
67
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
68
+ * prepend a folder token such as "<projectFolder>".
69
+ *
70
+ * Note: This setting will be ignored if "overrideTsconfig" is used.
71
+ *
72
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
73
+ * DEFAULT VALUE: "<projectFolder>/tsconfig.json"
74
+ */
75
+ // "tsconfigFilePath": "<projectFolder>/tsconfig.json",
76
+ /**
77
+ * Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk.
78
+ * The object must conform to the TypeScript tsconfig schema:
79
+ *
80
+ * http://json.schemastore.org/tsconfig
81
+ *
82
+ * If omitted, then the tsconfig.json file will be read from the "projectFolder".
83
+ *
84
+ * DEFAULT VALUE: no overrideTsconfig section
85
+ */
86
+ // "overrideTsconfig": {
87
+ // . . .
88
+ // }
89
+ /**
90
+ * This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended
91
+ * and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when
92
+ * dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses
93
+ * for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck.
94
+ *
95
+ * DEFAULT VALUE: false
96
+ */
97
+ // "skipLibCheck": true,
98
+ },
99
+ /**
100
+ * Configures how the API report file (*.api.md) will be generated.
101
+ */
102
+ "apiReport": {
103
+ /**
104
+ * (REQUIRED) Whether to generate an API report.
105
+ */
106
+ "enabled": true
107
+ /**
108
+ * The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce
109
+ * a full file path.
110
+ *
111
+ * The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/".
112
+ *
113
+ * SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
114
+ * DEFAULT VALUE: "<unscopedPackageName>.api.md"
115
+ */
116
+ // "reportFileName": "<unscopedPackageName>.api.md",
117
+ /**
118
+ * Specifies the folder where the API report file is written. The file name portion is determined by
119
+ * the "reportFileName" setting.
120
+ *
121
+ * The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy,
122
+ * e.g. for an API review.
123
+ *
124
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
125
+ * prepend a folder token such as "<projectFolder>".
126
+ *
127
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
128
+ * DEFAULT VALUE: "<projectFolder>/etc/"
129
+ */
130
+ // "reportFolder": "<projectFolder>/etc/",
131
+ /**
132
+ * Specifies the folder where the temporary report file is written. The file name portion is determined by
133
+ * the "reportFileName" setting.
134
+ *
135
+ * After the temporary file is written to disk, it is compared with the file in the "reportFolder".
136
+ * If they are different, a production build will fail.
137
+ *
138
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
139
+ * prepend a folder token such as "<projectFolder>".
140
+ *
141
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
142
+ * DEFAULT VALUE: "<projectFolder>/temp/"
143
+ */
144
+ // "reportTempFolder": "<projectFolder>/temp/"
145
+ },
146
+ /**
147
+ * Configures how the doc model file (*.api.json) will be generated.
148
+ */
149
+ "docModel": {
150
+ /**
151
+ * (REQUIRED) Whether to generate a doc model file.
152
+ */
153
+ "enabled": true
154
+ /**
155
+ * The output path for the doc model file. The file extension should be ".api.json".
156
+ *
157
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
158
+ * prepend a folder token such as "<projectFolder>".
159
+ *
160
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
161
+ * DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
162
+ */
163
+ // "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
164
+ },
165
+ /**
166
+ * Configures how the .d.ts rollup file will be generated.
167
+ */
168
+ "dtsRollup": {
169
+ /**
170
+ * (REQUIRED) Whether to generate the .d.ts rollup file.
171
+ */
172
+ "enabled": true
173
+ /**
174
+ * Specifies the output path for a .d.ts rollup file to be generated without any trimming.
175
+ * This file will include all declarations that are exported by the main entry point.
176
+ *
177
+ * If the path is an empty string, then this file will not be written.
178
+ *
179
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
180
+ * prepend a folder token such as "<projectFolder>".
181
+ *
182
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
183
+ * DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
184
+ */
185
+ // "untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
186
+ /**
187
+ * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
188
+ * This file will include only declarations that are marked as "@public" or "@beta".
189
+ *
190
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
191
+ * prepend a folder token such as "<projectFolder>".
192
+ *
193
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
194
+ * DEFAULT VALUE: ""
195
+ */
196
+ // "betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-beta.d.ts",
197
+ /**
198
+ * Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
199
+ * This file will include only declarations that are marked as "@public".
200
+ *
201
+ * If the path is an empty string, then this file will not be written.
202
+ *
203
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
204
+ * prepend a folder token such as "<projectFolder>".
205
+ *
206
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
207
+ * DEFAULT VALUE: ""
208
+ */
209
+ // "publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts",
210
+ /**
211
+ * When a declaration is trimmed, by default it will be replaced by a code comment such as
212
+ * "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the
213
+ * declaration completely.
214
+ *
215
+ * DEFAULT VALUE: false
216
+ */
217
+ // "omitTrimmingComments": true
218
+ },
219
+ /**
220
+ * Configures how the tsdoc-metadata.json file will be generated.
221
+ */
222
+ "tsdocMetadata": {
223
+ /**
224
+ * Whether to generate the tsdoc-metadata.json file.
225
+ *
226
+ * DEFAULT VALUE: true
227
+ */
228
+ // "enabled": true,
229
+ /**
230
+ * Specifies where the TSDoc metadata file should be written.
231
+ *
232
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
233
+ * prepend a folder token such as "<projectFolder>".
234
+ *
235
+ * The default value is "<lookup>", which causes the path to be automatically inferred from the "tsdocMetadata",
236
+ * "typings" or "main" fields of the project's package.json. If none of these fields are set, the lookup
237
+ * falls back to "tsdoc-metadata.json" in the package folder.
238
+ *
239
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
240
+ * DEFAULT VALUE: "<lookup>"
241
+ */
242
+ // "tsdocMetadataFilePath": "<projectFolder>/dist/tsdoc-metadata.json"
243
+ },
244
+ /**
245
+ * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
246
+ * will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
247
+ * To use the OS's default newline kind, specify "os".
248
+ *
249
+ * DEFAULT VALUE: "crlf"
250
+ */
251
+ // "newlineKind": "crlf",
252
+ /**
253
+ * Configures how API Extractor reports error and warning messages produced during analysis.
254
+ *
255
+ * There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages.
256
+ */
257
+ "messages": {
258
+ /**
259
+ * Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing
260
+ * the input .d.ts files.
261
+ *
262
+ * TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551"
263
+ *
264
+ * DEFAULT VALUE: A single "default" entry with logLevel=warning.
265
+ */
266
+ "compilerMessageReporting": {
267
+ /**
268
+ * Configures the default routing for messages that don't match an explicit rule in this table.
269
+ */
270
+ "default": {
271
+ /**
272
+ * Specifies whether the message should be written to the the tool's output log. Note that
273
+ * the "addToApiReportFile" property may supersede this option.
274
+ *
275
+ * Possible values: "error", "warning", "none"
276
+ *
277
+ * Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail
278
+ * and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes
279
+ * the "--local" option), the warning is displayed but the build will not fail.
280
+ *
281
+ * DEFAULT VALUE: "warning"
282
+ */
283
+ "logLevel": "warning"
284
+ /**
285
+ * When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md),
286
+ * then the message will be written inside that file; otherwise, the message is instead logged according to
287
+ * the "logLevel" option.
288
+ *
289
+ * DEFAULT VALUE: false
290
+ */
291
+ // "addToApiReportFile": false
292
+ }
293
+ // "TS2551": {
294
+ // "logLevel": "warning",
295
+ // "addToApiReportFile": true
296
+ // },
297
+ //
298
+ // . . .
299
+ },
300
+ /**
301
+ * Configures handling of messages reported by API Extractor during its analysis.
302
+ *
303
+ * API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag"
304
+ *
305
+ * DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings
306
+ */
307
+ "extractorMessageReporting": {
308
+ "default": {
309
+ "logLevel": "warning"
310
+ // "addToApiReportFile": false
311
+ },
312
+ "ae-unresolved-link": {
313
+ "logLevel": "none",
314
+ "addToApiReportFile": true
315
+ }
316
+ // "ae-extra-release-tag": {
317
+ // "logLevel": "warning",
318
+ // "addToApiReportFile": true
319
+ // },
320
+ //
321
+ // . . .
322
+ },
323
+ /**
324
+ * Configures handling of messages reported by the TSDoc parser when analyzing code comments.
325
+ *
326
+ * TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text"
327
+ *
328
+ * DEFAULT VALUE: A single "default" entry with logLevel=warning.
329
+ */
330
+ "tsdocMessageReporting": {
331
+ "default": {
332
+ "logLevel": "warning"
333
+ // "addToApiReportFile": false
334
+ }
335
+ // "tsdoc-link-tag-unescaped-text": {
336
+ // "logLevel": "warning",
337
+ // "addToApiReportFile": true
338
+ // },
339
+ //
340
+ // . . .
341
+ }
342
+ }
343
+ }
@@ -0,0 +1,16 @@
1
+ // The "rig.json" file directs tools to look for their config files in an external package.
2
+ // Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
3
+ {
4
+ "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
5
+ /**
6
+ * (Required) The name of the rig package to inherit from.
7
+ * It should be an NPM package name with the "-rig" suffix.
8
+ */
9
+ "rigPackageName": "@rushstack/heft-node-rig"
10
+ /**
11
+ * (Optional) Selects a config profile from the rig package. The name must consist of
12
+ * lowercase alphanumeric words separated by hyphens, for example "sample-profile".
13
+ * If omitted, then the "default" profile will be used."
14
+ */
15
+ // "rigProfile": "your-profile-name"
16
+ }
@@ -523,9 +523,9 @@ export { ZipFileTree }
523
523
  */
524
524
  declare class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
525
525
  /**
526
- * The AdmZip instance containing the archive.
526
+ * The unzipped file data.
527
527
  */
528
- private readonly _zip;
528
+ private readonly _files;
529
529
  /**
530
530
  * Optional prefix to prepend to paths.
531
531
  */
@@ -536,17 +536,24 @@ declare class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
536
536
  private readonly _itemCache;
537
537
  /**
538
538
  * Constructor for ZipFileTreeAccessors.
539
- * @param zip - The AdmZip instance.
539
+ * @param files - The unzipped file data from fflate.
540
540
  * @param prefix - Optional prefix to prepend to paths.
541
541
  */
542
542
  private constructor();
543
543
  /**
544
- * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer.
544
+ * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (synchronous).
545
545
  * @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
546
546
  * @param prefix - Optional prefix to prepend to paths.
547
547
  * @returns Result containing the ZipFileTreeAccessors instance.
548
548
  */
549
549
  static fromBuffer(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Result<ZipFileTreeAccessors>;
550
+ /**
551
+ * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (asynchronous).
552
+ * @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
553
+ * @param prefix - Optional prefix to prepend to paths.
554
+ * @returns Promise containing Result with the ZipFileTreeAccessors instance.
555
+ */
556
+ static fromBufferAsync(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Promise<Result<ZipFileTreeAccessors>>;
550
557
  /**
551
558
  * Creates a new ZipFileTreeAccessors instance from a File object (browser environment).
552
559
  * @param file - The File object containing ZIP data.
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.49.1"
8
+ "packageVersion": "7.52.10"
9
9
  }
10
10
  ]
11
11
  }
@@ -87,9 +87,9 @@ export declare class ZipDirectoryItem implements FileTree.IFileTreeDirectoryItem
87
87
  */
88
88
  export declare class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
89
89
  /**
90
- * The AdmZip instance containing the archive.
90
+ * The unzipped file data.
91
91
  */
92
- private readonly _zip;
92
+ private readonly _files;
93
93
  /**
94
94
  * Optional prefix to prepend to paths.
95
95
  */
@@ -100,17 +100,24 @@ export declare class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors
100
100
  private readonly _itemCache;
101
101
  /**
102
102
  * Constructor for ZipFileTreeAccessors.
103
- * @param zip - The AdmZip instance.
103
+ * @param files - The unzipped file data from fflate.
104
104
  * @param prefix - Optional prefix to prepend to paths.
105
105
  */
106
106
  private constructor();
107
107
  /**
108
- * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer.
108
+ * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (synchronous).
109
109
  * @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
110
110
  * @param prefix - Optional prefix to prepend to paths.
111
111
  * @returns Result containing the ZipFileTreeAccessors instance.
112
112
  */
113
113
  static fromBuffer(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Result<ZipFileTreeAccessors>;
114
+ /**
115
+ * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (asynchronous).
116
+ * @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
117
+ * @param prefix - Optional prefix to prepend to paths.
118
+ * @returns Promise containing Result with the ZipFileTreeAccessors instance.
119
+ */
120
+ static fromBufferAsync(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Promise<Result<ZipFileTreeAccessors>>;
114
121
  /**
115
122
  * Creates a new ZipFileTreeAccessors instance from a File object (browser environment).
116
123
  * @param file - The File object containing ZIP data.
@@ -20,12 +20,9 @@
20
20
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  * SOFTWARE.
22
22
  */
23
- var __importDefault = (this && this.__importDefault) || function (mod) {
24
- return (mod && mod.__esModule) ? mod : { "default": mod };
25
- };
26
23
  Object.defineProperty(exports, "__esModule", { value: true });
27
24
  exports.ZipFileTreeAccessors = exports.ZipDirectoryItem = exports.ZipFileItem = void 0;
28
- const adm_zip_1 = __importDefault(require("adm-zip"));
25
+ const fflate_1 = require("fflate");
29
26
  const ts_utils_1 = require("@fgv/ts-utils");
30
27
  /**
31
28
  * Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
@@ -114,35 +111,62 @@ exports.ZipDirectoryItem = ZipDirectoryItem;
114
111
  class ZipFileTreeAccessors {
115
112
  /**
116
113
  * Constructor for ZipFileTreeAccessors.
117
- * @param zip - The AdmZip instance.
114
+ * @param files - The unzipped file data from fflate.
118
115
  * @param prefix - Optional prefix to prepend to paths.
119
116
  */
120
- constructor(zip, prefix) {
117
+ constructor(files, prefix) {
121
118
  /**
122
119
  * Cache of all items in the ZIP for efficient lookups.
123
120
  */
124
121
  this._itemCache = new Map();
125
- this._zip = zip;
122
+ this._files = files;
126
123
  this._prefix = prefix || '';
127
124
  this._buildItemCache();
128
125
  }
129
126
  /**
130
- * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer.
127
+ * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (synchronous).
131
128
  * @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
132
129
  * @param prefix - Optional prefix to prepend to paths.
133
130
  * @returns Result containing the ZipFileTreeAccessors instance.
134
131
  */
135
132
  static fromBuffer(zipBuffer, prefix) {
136
133
  try {
137
- const buffer = Buffer.from(zipBuffer);
138
- const zip = new adm_zip_1.default(buffer);
139
- return (0, ts_utils_1.succeed)(new ZipFileTreeAccessors(zip, prefix));
134
+ /* c8 ignore next 1 - defense in depth */
135
+ const uint8Buffer = zipBuffer instanceof Uint8Array ? zipBuffer : new Uint8Array(zipBuffer);
136
+ const files = (0, fflate_1.unzipSync)(uint8Buffer);
137
+ return (0, ts_utils_1.succeed)(new ZipFileTreeAccessors(files, prefix));
140
138
  }
141
139
  catch (error) {
142
- /* c8 ignore next 1 - defensive coding: AdmZip always throws Error objects in practice */
140
+ /* c8 ignore next 1 - defensive coding: fflate always throws Error objects in practice */
143
141
  return (0, ts_utils_1.fail)(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`);
144
142
  }
145
143
  }
144
+ /**
145
+ * Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (asynchronous).
146
+ * @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
147
+ * @param prefix - Optional prefix to prepend to paths.
148
+ * @returns Promise containing Result with the ZipFileTreeAccessors instance.
149
+ */
150
+ static async fromBufferAsync(zipBuffer, prefix) {
151
+ return new Promise((resolve) => {
152
+ try {
153
+ /* c8 ignore next 1 - defense in depth */
154
+ const uint8Buffer = zipBuffer instanceof Uint8Array ? zipBuffer : new Uint8Array(zipBuffer);
155
+ (0, fflate_1.unzip)(uint8Buffer, (err, files) => {
156
+ if (err) {
157
+ resolve((0, ts_utils_1.fail)(`Failed to load ZIP archive: ${err.message}`));
158
+ }
159
+ else {
160
+ resolve((0, ts_utils_1.succeed)(new ZipFileTreeAccessors(files, prefix)));
161
+ }
162
+ });
163
+ }
164
+ catch (error) {
165
+ /* c8 ignore next 5 - defensive coding: fflate always throws Error objects in practice */
166
+ resolve((0, ts_utils_1.fail)(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`));
167
+ }
168
+ });
169
+ }
146
170
  /**
147
171
  * Creates a new ZipFileTreeAccessors instance from a File object (browser environment).
148
172
  * @param file - The File object containing ZIP data.
@@ -152,7 +176,7 @@ class ZipFileTreeAccessors {
152
176
  static async fromFile(file, prefix) {
153
177
  try {
154
178
  const arrayBuffer = await file.arrayBuffer();
155
- return ZipFileTreeAccessors.fromBuffer(new Uint8Array(arrayBuffer), prefix);
179
+ return await ZipFileTreeAccessors.fromBufferAsync(new Uint8Array(arrayBuffer), prefix);
156
180
  }
157
181
  catch (error) {
158
182
  return (0, ts_utils_1.fail)(`Failed to read file: ${error instanceof Error ? error.message : String(error)}`);
@@ -163,40 +187,38 @@ class ZipFileTreeAccessors {
163
187
  */
164
188
  _buildItemCache() {
165
189
  const directories = new Set();
166
- const entries = this._zip.getEntries();
167
- // First pass: collect all directories from file paths
168
- entries.forEach((entry) => {
169
- if (!entry.isDirectory) {
170
- // Extract directory path from file path
171
- const pathParts = entry.entryName.split('/');
172
- for (let i = 1; i < pathParts.length; i++) {
173
- const dirPath = pathParts.slice(0, i).join('/');
190
+ // Process all files and collect directory paths
191
+ for (const [relativePath, fileData] of Object.entries(this._files)) {
192
+ // Skip directories in fflate output (they have null data)
193
+ /* c8 ignore next 5 - handles explicit directory entries from external ZIP tools (fflate doesn't create these) */
194
+ if (fileData === null || fileData === undefined) {
195
+ const dirPath = relativePath.replace(/\/$/, '');
196
+ if (dirPath) {
174
197
  directories.add(dirPath);
175
198
  }
176
199
  }
177
200
  else {
178
- // Also add explicit directories
179
- const dirPath = entry.entryName.replace(/\/$/, ''); // Remove trailing slash
180
- if (dirPath) {
181
- directories.add(dirPath);
201
+ // Extract directory paths from file paths
202
+ const pathParts = relativePath.split('/');
203
+ for (let i = 1; i < pathParts.length; i++) {
204
+ const dirPath = pathParts.slice(0, i).join('/');
205
+ if (dirPath) {
206
+ directories.add(dirPath);
207
+ }
182
208
  }
209
+ // Add the file item with its contents
210
+ const absolutePath = this.resolveAbsolutePath(relativePath);
211
+ const contents = new TextDecoder().decode(fileData);
212
+ const item = new ZipFileItem(relativePath, contents, this);
213
+ this._itemCache.set(absolutePath, item);
183
214
  }
184
- });
215
+ }
185
216
  // Add directory items to cache
186
217
  directories.forEach((dirPath) => {
187
218
  const absolutePath = this.resolveAbsolutePath(dirPath);
188
219
  const item = new ZipDirectoryItem(dirPath, this);
189
220
  this._itemCache.set(absolutePath, item);
190
221
  });
191
- // Add file items to cache
192
- entries.forEach((entry) => {
193
- if (!entry.isDirectory) {
194
- const absolutePath = this.resolveAbsolutePath(entry.entryName);
195
- const contents = entry.getData().toString('utf8');
196
- const item = new ZipFileItem(entry.entryName, contents, this);
197
- this._itemCache.set(absolutePath, item);
198
- }
199
- });
200
222
  }
201
223
  /**
202
224
  * Resolves paths to an absolute path.
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=converters.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=csvHelpers.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=extendedArray.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=formatter.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=md5Normalizer.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=rangeOf.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=recordJarHelpers.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=zipFileTreeAccessors.test.d.ts.map