cspell-io 10.0.0 → 10.1.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +201 -202
  2. package/dist/index.js +56 -29
  3. package/package.json +6 -6
package/dist/index.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname } from "@cspell/url";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { ServiceBus } from "@cspell/cspell-service-bus";
4
-
5
4
  //#region src/async/asyncIterable.d.ts
6
5
  /**
7
- * Reads an entire iterable and converts it into a promise.
8
- * @param asyncIterable the async iterable to wait for.
9
- */
6
+ * Reads an entire iterable and converts it into a promise.
7
+ * @param asyncIterable the async iterable to wait for.
8
+ */
10
9
  declare function toArray<T>(asyncIterable: AsyncIterable<T> | Iterable<T> | Iterable<Promise<T>>): Promise<T[]>;
11
10
  //#endregion
12
11
  //#region src/models/BufferEncoding.d.ts
@@ -16,47 +15,47 @@ type BufferEncoding = "base64" | "base64url" | "hex" | TextEncoding;
16
15
  //#region src/models/FileResource.d.ts
17
16
  interface FileReference {
18
17
  /**
19
- * The URL of the File
20
- */
18
+ * The URL of the File
19
+ */
21
20
  readonly url: URL;
22
21
  /**
23
- * The filename of the file if known.
24
- * Useful for `data:` urls.
25
- */
22
+ * The filename of the file if known.
23
+ * Useful for `data:` urls.
24
+ */
26
25
  readonly baseFilename?: string | undefined;
27
26
  /**
28
- * The encoding to use when reading the file.
29
- */
27
+ * The encoding to use when reading the file.
28
+ */
30
29
  readonly encoding?: BufferEncoding | undefined;
31
30
  /**
32
- * - `true` if the content had been gzip compressed.
33
- * - `false` if the content was NOT gzip compressed.
34
- * - `undefined` if it is unknown
35
- */
31
+ * - `true` if the content had been gzip compressed.
32
+ * - `false` if the content was NOT gzip compressed.
33
+ * - `undefined` if it is unknown
34
+ */
36
35
  readonly gz?: boolean | undefined;
37
36
  }
38
37
  interface FileResource extends FileReference {
39
38
  /**
40
- * The contents of the file
41
- */
39
+ * The contents of the file
40
+ */
42
41
  readonly content: string | Uint8Array<ArrayBuffer>;
43
42
  }
44
43
  interface TextFileResource extends FileResource {
45
44
  /**
46
- * Extract the text of the file.
47
- * @param encoding - optional encoding to use when decoding the content.
48
- * by default it uses the encoding of the file if one was specified, otherwise it uses `utf8`.
49
- * If the content is a string, then the encoding is ignored.
50
- */
45
+ * Extract the text of the file.
46
+ * @param encoding - optional encoding to use when decoding the content.
47
+ * by default it uses the encoding of the file if one was specified, otherwise it uses `utf8`.
48
+ * If the content is a string, then the encoding is ignored.
49
+ */
51
50
  getText(encoding?: BufferEncoding): string;
52
51
  /**
53
- * Get the bytes of the file.
54
- * @param gunzip - gunzip the data.
55
- * - `true` to gunzip the data before returning it.
56
- * - `false` to return the data as is.
57
- * - `undefined` to gunzip the data if the file is marked as gzipped.
58
- * @returns the bytes of the file.
59
- */
52
+ * Get the bytes of the file.
53
+ * @param gunzip - gunzip the data.
54
+ * - `true` to gunzip the data before returning it.
55
+ * - `false` to return the data as is.
56
+ * - `undefined` to gunzip the data if the file is marked as gzipped.
57
+ * @returns the bytes of the file.
58
+ */
60
59
  getBytes(gunzip?: boolean): Promise<Uint8Array<ArrayBuffer>>;
61
60
  }
62
61
  type UrlOrFilename = string | URL;
@@ -74,9 +73,9 @@ declare class CFileReference implements FileReference {
74
73
  readonly encoding: BufferEncoding | undefined;
75
74
  readonly baseFilename: string | undefined;
76
75
  /**
77
- * Use to ensure the nominal type separation between CFileReference and FileReference
78
- * See: https://github.com/microsoft/TypeScript/wiki/FAQ#when-and-why-are-classes-nominal
79
- */
76
+ * Use to ensure the nominal type separation between CFileReference and FileReference
77
+ * See: https://github.com/microsoft/TypeScript/wiki/FAQ#when-and-why-are-classes-nominal
78
+ */
80
79
  private _?;
81
80
  readonly gz: boolean | undefined;
82
81
  constructor(url: URL, encoding: BufferEncoding | undefined, baseFilename: string | undefined, gz: boolean | undefined);
@@ -117,42 +116,42 @@ declare function renameFileResource(fileResource: FileResource, url: URL): FileR
117
116
  //#endregion
118
117
  //#region src/models/Stats.d.ts
119
118
  /**
120
- * Subset of definition from the Node definition to avoid a dependency upon a specific version of Node
121
- */
119
+ * Subset of definition from the Node definition to avoid a dependency upon a specific version of Node
120
+ */
122
121
  interface Stats {
123
122
  /**
124
- * Size of file in byes, -1 if unknown.
125
- */
123
+ * Size of file in byes, -1 if unknown.
124
+ */
126
125
  size: number;
127
126
  /**
128
- * Modification time, 0 if unknown.
129
- */
127
+ * Modification time, 0 if unknown.
128
+ */
130
129
  mtimeMs: number;
131
130
  /**
132
- * Used by web requests to see if a resource has changed.
133
- */
131
+ * Used by web requests to see if a resource has changed.
132
+ */
134
133
  eTag?: string | undefined;
135
134
  /**
136
- * The file type.
137
- */
135
+ * The file type.
136
+ */
138
137
  fileType?: FileType | undefined;
139
138
  }
140
139
  declare enum FileType {
141
140
  /**
142
- * The file type is unknown.
143
- */
141
+ * The file type is unknown.
142
+ */
144
143
  Unknown = 0,
145
144
  /**
146
- * A regular file.
147
- */
145
+ * A regular file.
146
+ */
148
147
  File = 1,
149
148
  /**
150
- * A directory.
151
- */
149
+ * A directory.
150
+ */
152
151
  Directory = 2,
153
152
  /**
154
- * A symbolic link.
155
- */
153
+ * A symbolic link.
154
+ */
156
155
  SymbolicLink = 64
157
156
  }
158
157
  interface DirEntry {
@@ -163,11 +162,11 @@ interface DirEntry {
163
162
  //#endregion
164
163
  //#region src/common/stat.d.ts
165
164
  /**
166
- * Compare two Stats to see if they have the same value.
167
- * @param left - Stats
168
- * @param right - Stats
169
- * @returns 0 - equal; 1 - left > right; -1 left < right
170
- */
165
+ * Compare two Stats to see if they have the same value.
166
+ * @param left - Stats
167
+ * @param right - Stats
168
+ * @returns 0 - equal; 1 - left > right; -1 left < right
169
+ */
171
170
  declare function compareStats(left: Stats, right: Stats): number;
172
171
  //#endregion
173
172
  //#region src/models/disposable.d.ts
@@ -188,89 +187,89 @@ interface ReadFileOptions$1 {
188
187
  type ReadFileOptionsOrEncoding = ReadFileOptions$1 | BufferEncoding;
189
188
  interface CSpellIO {
190
189
  /**
191
- * Read a file
192
- * @param urlOrFilename - uri of the file to read
193
- * @param options - optional options for reading the file.
194
- * @returns A TextFileResource.
195
- */
190
+ * Read a file
191
+ * @param urlOrFilename - uri of the file to read
192
+ * @param options - optional options for reading the file.
193
+ * @returns A TextFileResource.
194
+ */
196
195
  readFile(urlOrFilename: UrlOrReference$2, options?: ReadFileOptionsOrEncoding): Promise<TextFileResource>;
197
196
  /**
198
- * Read a file in Sync mode.
199
- * Note: `http` requests will fail.
200
- * @param urlOrFilename - uri of the file to read
201
- * @param encoding - optional encoding.
202
- * @returns A TextFileResource.
203
- * @deprecated Use `readFile` instead.
204
- */
197
+ * Read a file in Sync mode.
198
+ * Note: `http` requests will fail.
199
+ * @param urlOrFilename - uri of the file to read
200
+ * @param encoding - optional encoding.
201
+ * @returns A TextFileResource.
202
+ * @deprecated Use `readFile` instead.
203
+ */
205
204
  readFileSync(urlOrFilename: UrlOrReference$2, encoding?: BufferEncoding): TextFileResource;
206
205
  /**
207
- * Write content to a file using utf-8 encoding.
208
- * It will fail to write to non-file uris.
209
- * @param urlOrFilename - uri
210
- * @param content - string to write.
211
- */
206
+ * Write content to a file using utf-8 encoding.
207
+ * It will fail to write to non-file uris.
208
+ * @param urlOrFilename - uri
209
+ * @param content - string to write.
210
+ */
212
211
  writeFile(urlOrFilename: UrlOrReference$2, content: string | ArrayBufferView): Promise<FileReference>;
213
212
  /**
214
- * Read a directory.
215
- * @param urlOrFilename - uri
216
- */
213
+ * Read a directory.
214
+ * @param urlOrFilename - uri
215
+ */
217
216
  readDirectory(urlOrFilename: string | URL): Promise<DirEntry[]>;
218
217
  /**
219
- * Get Stats on a uri.
220
- * @param urlOrFilename - uri to fetch stats on
221
- * @returns Stats if successful.
222
- */
218
+ * Get Stats on a uri.
219
+ * @param urlOrFilename - uri to fetch stats on
220
+ * @returns Stats if successful.
221
+ */
223
222
  getStat(urlOrFilename: UrlOrReference$2): Promise<Stats>;
224
223
  /**
225
- * Get Stats on a uri.
226
- * @param urlOrFilename - uri to fetch stats on
227
- * @returns Stats if successful, otherwise it throws an error.
228
- * @deprecated Use `getStat` instead.
229
- */
224
+ * Get Stats on a uri.
225
+ * @param urlOrFilename - uri to fetch stats on
226
+ * @returns Stats if successful, otherwise it throws an error.
227
+ * @deprecated Use `getStat` instead.
228
+ */
230
229
  getStatSync(urlOrFilename: UrlOrReference$2): Stats;
231
230
  /**
232
- * Compare two Stats.
233
- * @param left - left stat
234
- * @param right - right stat
235
- * @returns 0 if they are equal and non-zero if they are not.
236
- */
231
+ * Compare two Stats.
232
+ * @param left - left stat
233
+ * @param right - right stat
234
+ * @returns 0 if they are equal and non-zero if they are not.
235
+ */
237
236
  compareStats(left: Stats, right: Stats): number;
238
237
  /**
239
- * Convert a string to a URL
240
- * @param urlOrFilename - string or URL to convert.
241
- * If it is a URL, then it is just returned as is.
242
- * If is is a string and fully formed URL, then it is parsed.
243
- * If it is a string without a protocol/scheme it is assumed to be relative to `relativeTo`.
244
- * @param relativeTo - optional
245
- */
238
+ * Convert a string to a URL
239
+ * @param urlOrFilename - string or URL to convert.
240
+ * If it is a URL, then it is just returned as is.
241
+ * If is is a string and fully formed URL, then it is parsed.
242
+ * If it is a string without a protocol/scheme it is assumed to be relative to `relativeTo`.
243
+ * @param relativeTo - optional
244
+ */
246
245
  toURL(urlOrFilename: UrlOrReference$2, relativeTo?: string | URL): URL;
247
246
  /**
248
- * Convert a string to a File URL
249
- * @param urlOrFilename - string or URL to convert.
250
- * @param relativeTo - optional
251
- */
247
+ * Convert a string to a File URL
248
+ * @param urlOrFilename - string or URL to convert.
249
+ * @param relativeTo - optional
250
+ */
252
251
  toFileURL(urlOrFilename: UrlOrFilename, relativeTo?: string | URL): URL;
253
252
  /**
254
- * Try to determine the base name of a URL.
255
- *
256
- * Note: this handles `data:` URLs with `filename` attribute:
257
- *
258
- * Example:
259
- * - `data:text/plain;charset=utf8;filename=hello.txt,Hello` would have a filename of `hello.txt`
260
- * - `file:///user/project/cspell.config.yaml` would have a filename of `cspell.config.yaml`
261
- * - `https://raw.guc.com/sss/cspell/main/cspell.schema.json` would have a filename of `cspell.schema.json`
262
- * @param urlOrFilename - string or URL to extract the basename from.
263
- */
253
+ * Try to determine the base name of a URL.
254
+ *
255
+ * Note: this handles `data:` URLs with `filename` attribute:
256
+ *
257
+ * Example:
258
+ * - `data:text/plain;charset=utf8;filename=hello.txt,Hello` would have a filename of `hello.txt`
259
+ * - `file:///user/project/cspell.config.yaml` would have a filename of `cspell.config.yaml`
260
+ * - `https://raw.guc.com/sss/cspell/main/cspell.schema.json` would have a filename of `cspell.schema.json`
261
+ * @param urlOrFilename - string or URL to extract the basename from.
262
+ */
264
263
  urlBasename(urlOrFilename: UrlOrReference$2): string;
265
264
  /**
266
- * Try to determine the directory URL of the uri.
267
- *
268
- * Example:
269
- * - `file:///user/local/file.txt` becomes `file:///user/local/`
270
- * - `file:///user/local/` becomes `file:///user/`
271
- *
272
- * @param urlOrFilename - string or URL
273
- */
265
+ * Try to determine the directory URL of the uri.
266
+ *
267
+ * Example:
268
+ * - `file:///user/local/file.txt` becomes `file:///user/local/`
269
+ * - `file:///user/local/` becomes `file:///user/`
270
+ *
271
+ * @param urlOrFilename - string or URL
272
+ */
274
273
  urlDirname(urlOrFilename: UrlOrReference$2): URL;
275
274
  }
276
275
  //#endregion
@@ -311,15 +310,15 @@ type TArrayBufferView<T extends ArrayBuffer = ArrayBuffer> = ArrayBufferView<T>;
311
310
  //#endregion
312
311
  //#region src/node/dataUrl.d.ts
313
312
  /**
314
- * Generates a string of the following format:
315
- *
316
- * `data:[mediaType][;charset=<encoding>[;base64],<data>`
317
- *
318
- * - `encoding` - defaults to `utf8` for text data
319
- * @param data
320
- * @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
321
- * @param attributes - Additional attributes
322
- */
313
+ * Generates a string of the following format:
314
+ *
315
+ * `data:[mediaType][;charset=<encoding>[;base64],<data>`
316
+ *
317
+ * - `encoding` - defaults to `utf8` for text data
318
+ * @param data
319
+ * @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
320
+ * @param attributes - Additional attributes
321
+ */
323
322
  declare function encodeDataUrl(data: string | TArrayBufferView | Uint8Array<ArrayBuffer>, mediaType: string, attributes?: Iterable<readonly [string, string]> | undefined): string;
324
323
  declare function toDataUrl(data: string | TArrayBufferView, mediaType: string, attributes?: Iterable<[string, string]> | undefined): URL;
325
324
  //#endregion
@@ -347,49 +346,49 @@ interface ReadFileOptions {
347
346
  }
348
347
  interface VFileSystemCore {
349
348
  /**
350
- * Read a file.
351
- * @param url - URL to read
352
- * @param encoding - optional encoding
353
- * @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
354
- */
349
+ * Read a file.
350
+ * @param url - URL to read
351
+ * @param encoding - optional encoding
352
+ * @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
353
+ */
355
354
  readFile(url: UrlOrReference, encoding: BufferEncoding): Promise<TextFileResource>;
356
355
  /**
357
- * Read a file.
358
- * @param url - URL to read
359
- * @param options - options for reading the file.
360
- * @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
361
- */
356
+ * Read a file.
357
+ * @param url - URL to read
358
+ * @param options - options for reading the file.
359
+ * @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
360
+ */
362
361
  readFile(url: UrlOrReference, options?: ReadFileOptions | BufferEncoding): Promise<TextFileResource>;
363
362
  /**
364
- * Write a file
365
- * @param file - the file to write
366
- */
363
+ * Write a file
364
+ * @param file - the file to write
365
+ */
367
366
  writeFile(file: FileResource): Promise<FileReference>;
368
367
  /**
369
- * Get the stats for a url.
370
- * @param url - Url to fetch stats for.
371
- */
368
+ * Get the stats for a url.
369
+ * @param url - Url to fetch stats for.
370
+ */
372
371
  stat(url: UrlOrReference): Promise<VfsStat>;
373
372
  /**
374
- * Read the directory entries for a url.
375
- * The url should end with `/` to indicate a directory.
376
- * @param url - the url to read the directory entries for.
377
- */
373
+ * Read the directory entries for a url.
374
+ * The url should end with `/` to indicate a directory.
375
+ * @param url - the url to read the directory entries for.
376
+ */
378
377
  readDirectory(url: URL): Promise<VfsDirEntry[]>;
379
378
  /**
380
- * Get the capabilities for a URL.
381
- * The capabilities can be more restrictive than the general capabilities of the provider.
382
- * @param url - the url to try
383
- */
379
+ * Get the capabilities for a URL.
380
+ * The capabilities can be more restrictive than the general capabilities of the provider.
381
+ * @param url - the url to try
382
+ */
384
383
  getCapabilities(url: URL): Readonly<FSCapabilities>;
385
384
  /**
386
- * Information about the provider.
387
- * It is up to the provider to define what information is available.
388
- */
385
+ * Information about the provider.
386
+ * It is up to the provider to define what information is available.
387
+ */
389
388
  providerInfo: Readonly<FileSystemProviderInfo>;
390
389
  /**
391
- * Indicates that a provider was found for the url.
392
- */
390
+ * Indicates that a provider was found for the url.
391
+ */
393
392
  hasProvider: boolean;
394
393
  }
395
394
  interface VFileSystem extends VFileSystemCore {
@@ -427,24 +426,24 @@ type NextProvider = (url: URL) => VProviderFileSystem | undefined;
427
426
  interface VirtualFS extends DisposableEx {
428
427
  registerFileSystemProvider(provider: VFileSystemProvider, ...providers: VFileSystemProvider[]): DisposableEx;
429
428
  /**
430
- * Get the fs for a given url.
431
- */
429
+ * Get the fs for a given url.
430
+ */
432
431
  getFS(url: URL): VFileSystem;
433
432
  /**
434
- * The file system. All requests will first use getFileSystem to get the file system before making the request.
435
- */
433
+ * The file system. All requests will first use getFileSystem to get the file system before making the request.
434
+ */
436
435
  readonly fs: Required<VFileSystem>;
437
436
  /**
438
- * The file system core. All requests will first use getFileSystem to get the file system before making the request.
439
- */
437
+ * The file system core. All requests will first use getFileSystem to get the file system before making the request.
438
+ */
440
439
  readonly fsc: Required<VFileSystemCore>;
441
440
  /**
442
- * Clear the cache of file systems.
443
- */
441
+ * Clear the cache of file systems.
442
+ */
444
443
  reset(): void;
445
444
  /**
446
- * Indicates that logging has been enabled.
447
- */
445
+ * Indicates that logging has been enabled.
446
+ */
448
447
  loggingEnabled: boolean;
449
448
  enableLogging(value?: boolean): void;
450
449
  }
@@ -456,33 +455,33 @@ interface VProviderFileSystem extends DisposableEx {
456
455
  readFile(url: UrlOrReference, options?: VProviderFileSystemReadFileOptions): Promise<FileResource>;
457
456
  writeFile(file: FileResource): Promise<FileReference>;
458
457
  /**
459
- * Information about the provider.
460
- * It is up to the provider to define what information is available.
461
- */
458
+ * Information about the provider.
459
+ * It is up to the provider to define what information is available.
460
+ */
462
461
  providerInfo: FileSystemProviderInfo;
463
462
  stat(url: UrlOrReference): Stats | Promise<Stats>;
464
463
  readDirectory(url: URL): Promise<DirEntry[]>;
465
464
  /**
466
- * These are the general capabilities for the provider's file system.
467
- * It is possible for a provider to support more capabilities for a given url by providing a getCapabilities function.
468
- */
465
+ * These are the general capabilities for the provider's file system.
466
+ * It is possible for a provider to support more capabilities for a given url by providing a getCapabilities function.
467
+ */
469
468
  capabilities: FSCapabilityFlags;
470
469
  /**
471
- * Get the capabilities for a URL. Makes it possible for a provider to support more capabilities for a given url.
472
- * These capabilities should be more restrictive than the general capabilities.
473
- * @param url - the url to try
474
- * @returns the capabilities for the url.
475
- */
470
+ * Get the capabilities for a URL. Makes it possible for a provider to support more capabilities for a given url.
471
+ * These capabilities should be more restrictive than the general capabilities.
472
+ * @param url - the url to try
473
+ * @returns the capabilities for the url.
474
+ */
476
475
  getCapabilities?: (url: URL) => FSCapabilities;
477
476
  }
478
477
  interface VFileSystemProvider extends Partial<DisposableEx> {
479
478
  /** Name of the Provider */
480
479
  name: string;
481
480
  /**
482
- * Get the file system for a given url. The provider is cached based upon the protocol and hostname.
483
- * @param url - the url to get the file system for.
484
- * @param next - call this function to get the next provider to try. This is useful for chaining providers that operate on the same protocol.
485
- */
481
+ * Get the file system for a given url. The provider is cached based upon the protocol and hostname.
482
+ * @param url - the url to get the file system for.
483
+ * @param next - call this function to get the next provider to try. This is useful for chaining providers that operate on the same protocol.
484
+ */
486
485
  getFileSystem(url: URL, next: NextProvider): VProviderFileSystem | undefined;
487
486
  }
488
487
  //#endregion
@@ -493,31 +492,31 @@ declare function getDefaultVirtualFs(): VirtualFS;
493
492
  //#region src/VirtualFS/redirectProvider.d.ts
494
493
  interface RedirectOptions {
495
494
  /**
496
- * Option ts to mask the capabilities of the provider.
497
- * @default: -1
498
- */
495
+ * Option ts to mask the capabilities of the provider.
496
+ * @default: -1
497
+ */
499
498
  capabilitiesMask?: number;
500
499
  capabilities?: FSCapabilityFlags;
501
500
  }
502
501
  /**
503
- * Create a provider that will redirect requests from the publicRoot to the privateRoot.
504
- * This is useful for creating a virtual file system that is a subset of another file system.
505
- *
506
- * Example:
507
- * ```ts
508
- * const vfs = createVirtualFS();
509
- * const provider = createRedirectProvider('test', new URL('file:///public/'), new URL('file:///private/'))
510
- * vfs.registerFileSystemProvider(provider);
511
- * // Read the content of `file:///private/file.txt`
512
- * const file = vfs.fs.readFile(new URL('file:///public/file.txt');
513
- * ```
514
- *
515
- * @param name - name of the provider
516
- * @param publicRoot - the root of the public file system.
517
- * @param privateRoot - the root of the private file system.
518
- * @param options - options for the provider.
519
- * @returns FileSystemProvider
520
- */
502
+ * Create a provider that will redirect requests from the publicRoot to the privateRoot.
503
+ * This is useful for creating a virtual file system that is a subset of another file system.
504
+ *
505
+ * Example:
506
+ * ```ts
507
+ * const vfs = createVirtualFS();
508
+ * const provider = createRedirectProvider('test', new URL('file:///public/'), new URL('file:///private/'))
509
+ * vfs.registerFileSystemProvider(provider);
510
+ * // Read the content of `file:///private/file.txt`
511
+ * const file = vfs.fs.readFile(new URL('file:///public/file.txt');
512
+ * ```
513
+ *
514
+ * @param name - name of the provider
515
+ * @param publicRoot - the root of the public file system.
516
+ * @param privateRoot - the root of the private file system.
517
+ * @param options - options for the provider.
518
+ * @returns FileSystemProvider
519
+ */
521
520
  declare function createRedirectProvider(name: string, publicRoot: URL, privateRoot: URL, options?: RedirectOptions): VFileSystemProvider;
522
521
  //#endregion
523
522
  export { type BufferEncoding, CFileReference, CFileResource, CSPELL_VFS_PROTOCOL, type CSpellIO, CSpellIONode, FSCapabilityFlags, type FileReference, type FileResource, type Stats, type TextEncoding, type TextFileResource, type VFileSystem, type VFileSystemCore, type VFileSystemProvider, FileType as VFileType, type VFindEntryType, type VFindUpPredicate, type VFindUpURLOptions, type VProviderFileSystem, type VfsDirEntry, type VfsStat, type VirtualFS, toArray as asyncIterableToArray, compareStats, createRedirectProvider, fromFileResource as createTextFileResource, createVirtualFS, encodeDataUrl, getDefaultCSpellIO, getDefaultVirtualFs, getStat, getStatSync, isFileURL, isUrlLike, readFileText, readFileTextSync, renameFileReference, renameFileResource, toDataUrl, toFileURL, toURL, urlBasename, urlDirname, urlOrReferenceToUrl, writeToFile, writeToFileIterable, writeToFileIterable as writeToFileIterableP };
package/dist/index.js CHANGED
@@ -22,6 +22,9 @@ async function toArray(asyncIterable) {
22
22
  //#endregion
23
23
  //#region src/common/CFileReference.ts
24
24
  var CFileReference = class CFileReference {
25
+ url;
26
+ encoding;
27
+ baseFilename;
25
28
  /**
26
29
  * Use to ensure the nominal type separation between CFileReference and FileReference
27
30
  * See: https://github.com/microsoft/TypeScript/wiki/FAQ#when-and-why-are-classes-nominal
@@ -86,12 +89,14 @@ function toFileResourceRequest(file, encoding, signal) {
86
89
  //#endregion
87
90
  //#region src/errors/errors.ts
88
91
  var ErrorNotImplemented = class extends Error {
92
+ method;
89
93
  constructor(method, options) {
90
94
  super(`Method ${method} is not supported.`, options);
91
95
  this.method = method;
92
96
  }
93
97
  };
94
98
  var AssertionError = class extends Error {
99
+ message;
95
100
  constructor(message, options) {
96
101
  super(message, options);
97
102
  this.message = message;
@@ -214,7 +219,8 @@ function isGZipped(data) {
214
219
  }
215
220
  function decompressBuffer(data) {
216
221
  if (!isGZipped(data)) return data;
217
- return gunzipSync(arrayBufferViewToBuffer(data));
222
+ const buf = arrayBufferViewToBuffer(data);
223
+ return gunzipSync(buf);
218
224
  }
219
225
  async function decompress(data, method = "gzip") {
220
226
  const ds = new DecompressionStream(method || "deflate-raw");
@@ -457,6 +463,9 @@ const _fetch = globalThis.fetch;
457
463
  //#endregion
458
464
  //#region src/node/file/FetchError.ts
459
465
  var FetchUrlError = class FetchUrlError extends Error {
466
+ code;
467
+ status;
468
+ url;
460
469
  constructor(message, code, status, url) {
461
470
  super(message);
462
471
  this.code = code;
@@ -510,7 +519,8 @@ async function fetchHead(request) {
510
519
  }
511
520
  async function fetchURL(url, signal) {
512
521
  try {
513
- const response = await _fetch(signal ? new Request(url, { signal }) : url);
522
+ const request = signal ? new Request(url, { signal }) : url;
523
+ const response = await _fetch(request);
514
524
  if (!response.ok) throw FetchUrlError.create(url, response.status);
515
525
  return await response.bytes();
516
526
  } catch (e) {
@@ -738,13 +748,14 @@ function direntToDirEntry(dir, dirent) {
738
748
  };
739
749
  }
740
750
  function toFileType(statLike) {
741
- const t = statLike.isFile() ? FileType.File : statLike.isDirectory() ? FileType.Directory : FileType.Unknown;
742
- return statLike.isSymbolicLink() ? t | FileType.SymbolicLink : t;
751
+ const t = statLike.isFile() ? 1 : statLike.isDirectory() ? 2 : 0;
752
+ return statLike.isSymbolicLink() ? t | 64 : t;
743
753
  }
744
754
  //#endregion
745
755
  //#region src/CSpellIONode.ts
746
756
  let defaultCSpellIONode = void 0;
747
757
  var CSpellIONode = class {
758
+ serviceBus;
748
759
  constructor(serviceBus = new ServiceBus()) {
749
760
  this.serviceBus = serviceBus;
750
761
  registerHandlers(serviceBus);
@@ -843,7 +854,9 @@ function writeToFile(filename, data, encoding) {
843
854
  return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
844
855
  }
845
856
  function writeToFileIterable(filename, data, encoding) {
846
- return pipeline(Stream.Readable.from(encoderTransformer(data, encoding)), /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough(), fs.createWriteStream(filename));
857
+ const stream = Stream.Readable.from(encoderTransformer(data, encoding));
858
+ const zip = /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough();
859
+ return pipeline(stream, zip, fs.createWriteStream(filename));
847
860
  }
848
861
  //#endregion
849
862
  //#region src/file/file.ts
@@ -961,6 +974,8 @@ var VFSNotFoundError = class extends VFSError {
961
974
  }
962
975
  };
963
976
  var VFSErrorUnsupportedRequest = class extends VFSError {
977
+ request;
978
+ parameters;
964
979
  constructor(request, url, parameters) {
965
980
  super(`Unsupported request: ${request}`, { url });
966
981
  this.request = request;
@@ -1012,7 +1027,7 @@ var MemFileSystemProvider = class {
1012
1027
  var MemVFileSystem = class {
1013
1028
  name;
1014
1029
  protocol;
1015
- capabilities = FSCapabilityFlags.ReadWrite | FSCapabilityFlags.Stat;
1030
+ capabilities = 7;
1016
1031
  #files = /* @__PURE__ */ new Map();
1017
1032
  constructor(name, protocol) {
1018
1033
  this.name = name;
@@ -1037,7 +1052,7 @@ var MemVFileSystem = class {
1037
1052
  const stats = {
1038
1053
  size: file.content.length,
1039
1054
  mtimeMs: performance.now(),
1040
- fileType: FileType.File
1055
+ fileType: 1
1041
1056
  };
1042
1057
  const u = urlOrReferenceToUrl(file);
1043
1058
  this.#files.set(u.href, {
@@ -1082,23 +1097,24 @@ var MemVFileSystem = class {
1082
1097
  //#endregion
1083
1098
  //#region src/VirtualFS/capabilities.ts
1084
1099
  var CFsCapabilities = class {
1100
+ flags;
1085
1101
  constructor(flags) {
1086
1102
  this.flags = flags;
1087
1103
  }
1088
1104
  get readFile() {
1089
- return !!(this.flags & FSCapabilityFlags.Read);
1105
+ return !!(this.flags & 2);
1090
1106
  }
1091
1107
  get writeFile() {
1092
- return !!(this.flags & FSCapabilityFlags.Write);
1108
+ return !!(this.flags & 4);
1093
1109
  }
1094
1110
  get readDirectory() {
1095
- return !!(this.flags & FSCapabilityFlags.ReadDir);
1111
+ return !!(this.flags & 8);
1096
1112
  }
1097
1113
  get writeDirectory() {
1098
- return !!(this.flags & FSCapabilityFlags.WriteDir);
1114
+ return !!(this.flags & 16);
1099
1115
  }
1100
1116
  get stat() {
1101
- return !!(this.flags & FSCapabilityFlags.Stat);
1117
+ return !!(this.flags & 1);
1102
1118
  }
1103
1119
  };
1104
1120
  function fsCapabilities(flags) {
@@ -1107,27 +1123,29 @@ function fsCapabilities(flags) {
1107
1123
  //#endregion
1108
1124
  //#region src/VirtualFS/CFileType.ts
1109
1125
  var CFileType = class {
1126
+ fileType;
1110
1127
  constructor(fileType) {
1111
1128
  this.fileType = fileType;
1112
1129
  }
1113
1130
  isFile() {
1114
- return this.fileType === FileType.File;
1131
+ return this.fileType === 1;
1115
1132
  }
1116
1133
  isDirectory() {
1117
- return this.fileType === FileType.Directory;
1134
+ return this.fileType === 2;
1118
1135
  }
1119
1136
  isUnknown() {
1120
1137
  return !this.fileType;
1121
1138
  }
1122
1139
  isSymbolicLink() {
1123
- return !!(this.fileType & FileType.SymbolicLink);
1140
+ return !!(this.fileType & 64);
1124
1141
  }
1125
1142
  };
1126
1143
  //#endregion
1127
1144
  //#region src/VirtualFS/CVfsStat.ts
1128
1145
  var CVfsStat = class extends CFileType {
1146
+ stat;
1129
1147
  constructor(stat) {
1130
- super(stat.fileType || FileType.Unknown);
1148
+ super(stat.fileType || 0);
1131
1149
  this.stat = stat;
1132
1150
  }
1133
1151
  get size() {
@@ -1143,15 +1161,15 @@ var CVfsStat = class extends CFileType {
1143
1161
  //#endregion
1144
1162
  //#region src/VirtualFS/WrappedProviderFs.ts
1145
1163
  function cspellIOToFsProvider(cspellIO) {
1146
- const capabilities = FSCapabilityFlags.Stat | FSCapabilityFlags.ReadWrite | FSCapabilityFlags.ReadDir;
1147
- const capabilitiesHttp = capabilities & ~FSCapabilityFlags.Write & ~FSCapabilityFlags.ReadDir;
1164
+ const capabilities = 15;
1165
+ const capabilitiesHttp = 3;
1148
1166
  const capMap = {
1149
1167
  "file:": capabilities,
1150
1168
  "http:": capabilitiesHttp,
1151
1169
  "https:": capabilitiesHttp
1152
1170
  };
1153
1171
  const name = "CSpellIO";
1154
- const supportedProtocols = new Set([
1172
+ const supportedProtocols = /* @__PURE__ */ new Set([
1155
1173
  "file:",
1156
1174
  "http:",
1157
1175
  "https:"
@@ -1166,7 +1184,7 @@ function cspellIOToFsProvider(cspellIO) {
1166
1184
  dispose,
1167
1185
  capabilities,
1168
1186
  getCapabilities(url) {
1169
- return fsCapabilities(capMap[url.protocol] || FSCapabilityFlags.None);
1187
+ return fsCapabilities(capMap[url.protocol] || 0);
1170
1188
  },
1171
1189
  [Symbol.dispose]: dispose
1172
1190
  };
@@ -1182,6 +1200,8 @@ function wrapError(e) {
1182
1200
  return e;
1183
1201
  }
1184
1202
  var WrappedProviderFs = class WrappedProviderFs {
1203
+ fs;
1204
+ eventLogger;
1185
1205
  hasProvider;
1186
1206
  capabilities;
1187
1207
  providerInfo;
@@ -1190,7 +1210,7 @@ var WrappedProviderFs = class WrappedProviderFs {
1190
1210
  this.fs = fs;
1191
1211
  this.eventLogger = eventLogger;
1192
1212
  this.hasProvider = !!fs;
1193
- this.capabilities = fs?.capabilities || FSCapabilityFlags.None;
1213
+ this.capabilities = fs?.capabilities || 0;
1194
1214
  this._capabilities = fsCapabilities(this.capabilities);
1195
1215
  this.providerInfo = fs?.providerInfo || { name: "unknown" };
1196
1216
  }
@@ -1213,7 +1233,7 @@ var WrappedProviderFs = class WrappedProviderFs {
1213
1233
  const url = urlOrReferenceToUrl(urlRef);
1214
1234
  this.logEvent("stat", "start", traceID, url);
1215
1235
  try {
1216
- checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Stat, "stat", url);
1236
+ checkCapabilityOrThrow(this.fs, this.capabilities, 1, "stat", url);
1217
1237
  return new CVfsStat(await this.fs.stat(urlRef));
1218
1238
  } catch (e) {
1219
1239
  this.logEvent("stat", "error", traceID, url, e instanceof Error ? e.message : "");
@@ -1227,7 +1247,7 @@ var WrappedProviderFs = class WrappedProviderFs {
1227
1247
  const url = urlOrReferenceToUrl(urlRef);
1228
1248
  this.logEvent("readFile", "start", traceID, url);
1229
1249
  try {
1230
- checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Read, "readFile", url);
1250
+ checkCapabilityOrThrow(this.fs, this.capabilities, 2, "readFile", url);
1231
1251
  const readOptions = toOptions(optionsOrEncoding);
1232
1252
  return fromFileResource(await this.fs.readFile(urlRef, readOptions), readOptions?.encoding);
1233
1253
  } catch (e) {
@@ -1241,7 +1261,7 @@ var WrappedProviderFs = class WrappedProviderFs {
1241
1261
  const traceID = performance.now();
1242
1262
  this.logEvent("readDir", "start", traceID, url);
1243
1263
  try {
1244
- checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.ReadDir, "readDirectory", url);
1264
+ checkCapabilityOrThrow(this.fs, this.capabilities, 8, "readDirectory", url);
1245
1265
  return (await this.fs.readDirectory(url)).map((e) => new CVfsDirEntry(e));
1246
1266
  } catch (e) {
1247
1267
  this.logEvent("readDir", "error", traceID, url, e instanceof Error ? e.message : "");
@@ -1255,7 +1275,7 @@ var WrappedProviderFs = class WrappedProviderFs {
1255
1275
  const url = file.url;
1256
1276
  this.logEvent("writeFile", "start", traceID, url);
1257
1277
  try {
1258
- checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Write, "writeFile", file.url);
1278
+ checkCapabilityOrThrow(this.fs, this.capabilities, 4, "writeFile", file.url);
1259
1279
  return await this.fs.writeFile(file);
1260
1280
  } catch (e) {
1261
1281
  this.logEvent("writeFile", "error", traceID, url, e instanceof Error ? e.message : "");
@@ -1269,9 +1289,10 @@ var WrappedProviderFs = class WrappedProviderFs {
1269
1289
  }
1270
1290
  };
1271
1291
  function checkCapabilityOrThrow(fs, capabilities, flag, name, url) {
1272
- if (!(capabilities & flag)) throw new VFSErrorUnsupportedRequest(name, url);
1292
+ if (!(capabilities & flag) || !fs) throw new VFSErrorUnsupportedRequest(name, url);
1273
1293
  }
1274
1294
  var CVfsDirEntry = class extends CFileType {
1295
+ entry;
1275
1296
  _url;
1276
1297
  constructor(entry) {
1277
1298
  super(entry.fileType);
@@ -1438,7 +1459,7 @@ function createVirtualFS(cspellIO) {
1438
1459
  const cspell = cspellIO || getDefaultCSpellIO();
1439
1460
  const vfs = new CVirtualFS();
1440
1461
  vfs.registerFileSystemProvider(cspellIOToFsProvider(cspell));
1441
- vfs.registerFileSystemProvider(new MemFileSystemProvider(CSPELL_VFS_PROTOCOL + "default", CSPELL_VFS_PROTOCOL));
1462
+ vfs.registerFileSystemProvider(new MemFileSystemProvider("cspell-vfs:default", CSPELL_VFS_PROTOCOL));
1442
1463
  return vfs;
1443
1464
  }
1444
1465
  let defaultVirtualFs = void 0;
@@ -1449,6 +1470,10 @@ function getDefaultVirtualFs() {
1449
1470
  //#endregion
1450
1471
  //#region src/VirtualFS/redirectProvider.ts
1451
1472
  var RedirectProvider = class {
1473
+ name;
1474
+ publicRoot;
1475
+ privateRoot;
1476
+ options;
1452
1477
  constructor(name, publicRoot, privateRoot, options = { capabilitiesMask: -1 }) {
1453
1478
  this.name = name;
1454
1479
  this.publicRoot = publicRoot;
@@ -1537,7 +1562,8 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1537
1562
  },
1538
1563
  readFile: async (url, options) => {
1539
1564
  const url2 = mapUrlOrReferenceToPrivate(url);
1540
- return mapFileResourceToPublic(await fs.readFile(url2, options));
1565
+ const file = await fs.readFile(url2, options);
1566
+ return mapFileResourceToPublic(file);
1541
1567
  },
1542
1568
  readDirectory: async (url) => {
1543
1569
  const url2 = mapToPrivate(url);
@@ -1545,7 +1571,8 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1545
1571
  },
1546
1572
  writeFile: async (file) => {
1547
1573
  const fileRef2 = mapFileResourceToPrivate(file);
1548
- return mapFileReferenceToPublic(await fs.writeFile(fileRef2));
1574
+ const fileRef3 = await fs.writeFile(fileRef2);
1575
+ return mapFileReferenceToPublic(fileRef3);
1549
1576
  },
1550
1577
  providerInfo: {
1551
1578
  ...fs.providerInfo,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "provenance": true
6
6
  },
7
- "version": "10.0.0",
7
+ "version": "10.1.0",
8
8
  "description": "A library of useful I/O functions used across various cspell tools.",
9
9
  "type": "module",
10
10
  "sideEffects": false,
@@ -51,13 +51,13 @@
51
51
  "node": ">=22.18.0"
52
52
  },
53
53
  "devDependencies": {
54
- "lorem-ipsum": "^2.0.8",
55
- "typescript": "~5.9.3",
54
+ "lorem-ipsum": "^3.0.0",
55
+ "typescript": "~6.0.3",
56
56
  "vitest-fetch-mock": "^0.4.5"
57
57
  },
58
58
  "dependencies": {
59
- "@cspell/cspell-service-bus": "10.0.0",
60
- "@cspell/url": "10.0.0"
59
+ "@cspell/cspell-service-bus": "10.1.0",
60
+ "@cspell/url": "10.1.0"
61
61
  },
62
- "gitHead": "6ddfd576b6bb554a7cb8dba1ab053a0b6ff8021f"
62
+ "gitHead": "401518c5e37c06fb406aedadb3fc7a1c27eca8e6"
63
63
  }