@orkestrel/workspace 0.0.6 → 0.0.8

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.
@@ -1,14 +1,20 @@
1
- import { DriverInterface } from '@orkestrel/database';
2
- import { EmitterErrorHandler } from '@orkestrel/emitter';
3
- import { EmitterHooks } from '@orkestrel/emitter';
4
- import { EmitterInterface } from '@orkestrel/emitter';
5
- import { TableInterface } from '@orkestrel/database';
1
+ import type { DriverInterface } from '@orkestrel/database';
2
+ import type { EmitterErrorHandler } from '@orkestrel/emitter';
3
+ import type { EmitterHooks } from '@orkestrel/emitter';
4
+ import type { EmitterInterface } from '@orkestrel/emitter';
5
+ import type { TableInterface } from '@orkestrel/database';
6
+
7
+ /** Holds the binary arm of a file's immutable content: a base64 payload and its MIME. */
8
+ export declare interface BinaryContent {
9
+ readonly base64: string;
10
+ readonly mime: BinaryMIME;
11
+ }
6
12
 
7
- /** The binary MIME labels supported by a binary {@link FileContent} arm. */
13
+ /** Names the MIME labels a binary {@link FileContent} arm supports. */
8
14
  export declare type BinaryMIME = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
9
15
 
10
16
  /**
11
- * Clamp a position to text bounds.
17
+ * Clamps a position to text bounds.
12
18
  *
13
19
  * @param text - The addressed text
14
20
  * @param position - The requested position
@@ -22,7 +28,7 @@ export declare type BinaryMIME = 'image/png' | 'image/jpeg' | 'image/gif' | 'ima
22
28
  export declare function clampPosition(text: string, position: Position): Position;
23
29
 
24
30
  /**
25
- * Clamp both positions in a range to text bounds.
31
+ * Clamps both positions in a range to text bounds.
26
32
  *
27
33
  * @param text - The addressed text
28
34
  * @param range - The requested range
@@ -36,7 +42,20 @@ export declare function clampPosition(text: string, position: Position): Positio
36
42
  export declare function clampRange(text: string, range: Range): Range;
37
43
 
38
44
  /**
39
- * Compute the byte size of file content.
45
+ * Computes the decoded byte length of a base64 string, arithmetically rather than by decoding it.
46
+ *
47
+ * @param base64 - The base64 string
48
+ * @returns The decoded byte count
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * computeDecodedSize('AAAA') // 3
53
+ * ```
54
+ */
55
+ export declare function computeDecodedSize(base64: string): number;
56
+
57
+ /**
58
+ * Computes the byte size of file content.
40
59
  *
41
60
  * @param content - The content to measure
42
61
  * @returns UTF-8 bytes for text or decoded bytes for binary content
@@ -49,7 +68,7 @@ export declare function clampRange(text: string, range: Range): Range;
49
68
  export declare function computeSize(content: FileContent): number;
50
69
 
51
70
  /**
52
- * Count the lines in file content.
71
+ * Counts the lines in file content.
53
72
  *
54
73
  * @param content - The content to inspect
55
74
  * @returns The text line count, or zero for empty text and binary content
@@ -62,9 +81,10 @@ export declare function computeSize(content: FileContent): number;
62
81
  export declare function countLines(content: FileContent): number;
63
82
 
64
83
  /**
65
- * Create the binary arm of {@link FileContent}.
84
+ * Creates the binary arm of {@link FileContent}, returned as {@link BinaryContent} rather than
85
+ * as the whole union.
66
86
  *
67
- * @param data - The base64 payload
87
+ * @param base64 - The base64 payload
68
88
  * @param mime - The binary MIME
69
89
  * @returns Binary file content
70
90
  *
@@ -75,12 +95,13 @@ export declare function countLines(content: FileContent): number;
75
95
  * createBinaryContent('AAAA', 'image/png')
76
96
  * ```
77
97
  */
78
- export declare function createBinaryContent(data: string, mime: BinaryMIME): FileContent;
98
+ export declare function createBinaryContent(base64: string, mime: BinaryMIME): BinaryContent;
79
99
 
80
100
  /**
81
- * Create a database-backed workspace snapshot store.
101
+ * Creates a database-backed workspace snapshot store, over an in-memory driver when the caller
102
+ * supplies none.
82
103
  *
83
- * @param driver - The database driver; defaults to an in-memory driver
104
+ * @param driver - The database driver. Default: an in-memory driver.
84
105
  * @returns A workspace store backed by the supplied driver
85
106
  *
86
107
  * @example
@@ -93,22 +114,43 @@ export declare function createBinaryContent(data: string, mime: BinaryMIME): Fil
93
114
  export declare function createDatabaseWorkspaceStore(driver?: DriverInterface): WorkspaceStoreInterface;
94
115
 
95
116
  /**
96
- * Create an immutable file with derived size and line counts.
117
+ * Creates an immutable file with derived size and line counts.
97
118
  *
98
119
  * @param input - The file path, content, and optional state
99
120
  * @returns A frozen file record
100
121
  *
101
- * @example
122
+ * @example Files and content
102
123
  * ```ts
103
- * import { createFile, createTextContent } from '@orkestrel/workspace'
104
- *
105
- * createFile({ path: 'a.txt', content: createTextContent('hello', 'text') })
124
+ * import {
125
+ * computeSize,
126
+ * countLines,
127
+ * createBinaryContent,
128
+ * createFile,
129
+ * createTextContent,
130
+ * inferLanguage,
131
+ * isBinary,
132
+ * isText,
133
+ * } from '@orkestrel/workspace'
134
+ *
135
+ * const note = createFile({
136
+ * path: 'notes.md',
137
+ * content: createTextContent('# Title\nBody', inferLanguage('notes.md')), // 'markdown'
138
+ * })
139
+ *
140
+ * note.size // 12 — UTF-8 bytes, through computeSize
141
+ * note.lines // 2 — through countLines
142
+ * note.state // 'created'
143
+ * isText(note.content) // true
144
+ *
145
+ * const icon = createFile({ path: 'icon.png', content: createBinaryContent('AAAA', 'image/png') })
146
+ * isBinary(icon.content) // true
147
+ * icon.size // 3 — decoded base64 bytes, through computeDecodedSize
106
148
  * ```
107
149
  */
108
150
  export declare function createFile(input: FileInput): FileInterface;
109
151
 
110
152
  /**
111
- * Create an in-memory workspace snapshot store.
153
+ * Creates an in-memory workspace snapshot store.
112
154
  *
113
155
  * @returns A process-local workspace store
114
156
  *
@@ -122,7 +164,8 @@ export declare function createFile(input: FileInput): FileInterface;
122
164
  export declare function createMemoryWorkspaceStore(): WorkspaceStoreInterface;
123
165
 
124
166
  /**
125
- * Create the text arm of {@link FileContent}.
167
+ * Creates the text arm of {@link FileContent}, returned as {@link TextContent} rather than as
168
+ * the whole union.
126
169
  *
127
170
  * @param text - The text body
128
171
  * @param language - The language tag
@@ -135,10 +178,10 @@ export declare function createMemoryWorkspaceStore(): WorkspaceStoreInterface;
135
178
  * createTextContent('hello', 'text')
136
179
  * ```
137
180
  */
138
- export declare function createTextContent(text: string, language: string): FileContent;
181
+ export declare function createTextContent(text: string, language: string): TextContent;
139
182
 
140
183
  /**
141
- * Create a workspace.
184
+ * Creates a workspace with the same identity, emitter, and seed options the constructor takes.
142
185
  *
143
186
  * @param options - Optional identity, emitter configuration, and initial files
144
187
  * @returns A working workspace
@@ -154,7 +197,7 @@ export declare function createTextContent(text: string, language: string): FileC
154
197
  export declare function createWorkspace(options?: WorkspaceOptions): WorkspaceInterface;
155
198
 
156
199
  /**
157
- * Create an empty workspace registry.
200
+ * Creates an empty workspace registry.
158
201
  *
159
202
  * @param options - Default event hooks and optional durability
160
203
  * @returns A workspace manager
@@ -170,21 +213,27 @@ export declare function createWorkspace(options?: WorkspaceOptions): WorkspaceIn
170
213
  export declare function createWorkspaceManager(options?: WorkspaceManagerOptions): WorkspaceManagerInterface;
171
214
 
172
215
  /**
173
- * A workspace snapshot store over a database table.
216
+ * Persists workspace snapshots in a database table.
174
217
  *
175
218
  * Snapshots occupy one opaque column and are narrowed when read back from the storage boundary.
176
219
  *
177
220
  * @example
178
221
  * ```ts
179
- * import { createDatabaseWorkspaceStore } from '@orkestrel/workspace'
180
- *
181
- * const store = createDatabaseWorkspaceStore()
222
+ * import { rawShape, stringShape } from '@orkestrel/contract'
223
+ * import { createDatabase, createMemoryDriver } from '@orkestrel/database'
224
+ * import { DatabaseWorkspaceStore } from '@orkestrel/workspace'
225
+ *
226
+ * const database = createDatabase({
227
+ * driver: createMemoryDriver(),
228
+ * tables: { workspaces: { id: stringShape(), snapshot: rawShape({}) } },
229
+ * })
230
+ * const store = new DatabaseWorkspaceStore(database.table('workspaces'))
182
231
  * ```
183
232
  */
184
233
  export declare class DatabaseWorkspaceStore implements WorkspaceStoreInterface {
185
234
  #private;
186
235
  /**
187
- * Wrap a workspace snapshot table.
236
+ * Wraps a workspace snapshot table.
188
237
  *
189
238
  * @param table - The table keyed by workspace identifier
190
239
  */
@@ -195,20 +244,7 @@ export declare class DatabaseWorkspaceStore implements WorkspaceStoreInterface {
195
244
  }
196
245
 
197
246
  /**
198
- * Compute the decoded byte length of a base64 string.
199
- *
200
- * @param base64 - The base64 data
201
- * @returns The decoded byte count
202
- *
203
- * @example
204
- * ```ts
205
- * decodedSize('AAAA') // 3
206
- * ```
207
- */
208
- export declare function decodedSize(base64: string): number;
209
-
210
- /**
211
- * Escape regular-expression metacharacters for literal matching.
247
+ * Escapes regular-expression metacharacters for literal matching.
212
248
  *
213
249
  * @param value - The literal text
214
250
  * @returns The escaped regular-expression source
@@ -221,32 +257,30 @@ export declare function decodedSize(base64: string): number;
221
257
  export declare function escapeRegExp(value: string): string;
222
258
 
223
259
  /**
224
- * File extensions mapped to language tags for text content.
260
+ * Maps file extensions to language tags for text content.
225
261
  *
226
- * Unknown extensions intentionally fall back to `text` in
262
+ * The table is frozen, and an extension it does not list falls back to `text` in
227
263
  * {@link import('./helpers.js').inferLanguage}.
228
264
  */
229
265
  export declare const EXTENSION_LANGUAGES: Readonly<Record<string, string>>;
230
266
 
231
267
  /**
232
- * The immutable content of a file: either text with a language tag or base64 data with a MIME.
268
+ * Holds a file's immutable content: either text with a language tag or a base64 string with a
269
+ * MIME. The union carries no discriminant field, so a caller narrows it with a guard.
233
270
  */
234
- export declare type FileContent = {
235
- readonly text: string;
236
- readonly language: string;
237
- } | {
238
- readonly data: string;
239
- readonly mime: BinaryMIME;
240
- };
271
+ export declare type FileContent = TextContent | BinaryContent;
241
272
 
242
- /** The caller-supplied data used to create an immutable file. */
273
+ /**
274
+ * Carries the caller-supplied values used to create an immutable file. The byte size and the line
275
+ * count are derived rather than supplied.
276
+ */
243
277
  export declare interface FileInput {
244
278
  readonly path: string;
245
279
  readonly content: FileContent;
246
280
  readonly state?: FileState;
247
281
  }
248
282
 
249
- /** An immutable path-addressed file with derived byte and line counts. */
283
+ /** Represents an immutable path-addressed file with derived byte and line counts. */
250
284
  export declare interface FileInterface {
251
285
  readonly path: string;
252
286
  readonly content: FileContent;
@@ -255,11 +289,14 @@ export declare interface FileInterface {
255
289
  readonly lines: number;
256
290
  }
257
291
 
258
- /** The edit state of an immutable file value. */
292
+ /**
293
+ * Names the edit state of an immutable file value: `created` for the first write to a path and
294
+ * `modified` for every later edit of that path.
295
+ */
259
296
  export declare type FileState = 'created' | 'modified';
260
297
 
261
298
  /**
262
- * Infer a language tag from the final file extension.
299
+ * Infers a language tag from the final file extension.
263
300
  *
264
301
  * @param path - The file path
265
302
  * @returns The mapped language, or `text` when the extension is absent or unknown
@@ -272,26 +309,23 @@ export declare type FileState = 'created' | 'modified';
272
309
  export declare function inferLanguage(path: string): string;
273
310
 
274
311
  /**
275
- * Determine whether content is the binary arm.
312
+ * Determines whether content is the binary arm.
276
313
  *
277
314
  * @param content - The file content
278
- * @returns Whether the content carries base64 data and a MIME
315
+ * @returns True if the content carries a base64 string and a MIME; false otherwise
279
316
  *
280
317
  * @example
281
318
  * ```ts
282
- * isBinary({ data: 'AAAA', mime: 'image/png' }) // true
319
+ * isBinary({ base64: 'AAAA', mime: 'image/png' }) // true
283
320
  * ```
284
321
  */
285
- export declare function isBinary(content: FileContent): content is {
286
- readonly data: string;
287
- readonly mime: BinaryMIME;
288
- };
322
+ export declare function isBinary(content: FileContent): content is BinaryContent;
289
323
 
290
324
  /**
291
- * Narrow an unknown value to an immutable file record.
325
+ * Narrows an unknown value to an immutable file record.
292
326
  *
293
327
  * @param value - The value to inspect
294
- * @returns Whether the value has the file shape
328
+ * @returns True if the value has the file shape; false otherwise
295
329
  *
296
330
  * @example
297
331
  * ```ts
@@ -301,26 +335,23 @@ export declare function isBinary(content: FileContent): content is {
301
335
  export declare function isFile(value: unknown): value is FileInterface;
302
336
 
303
337
  /**
304
- * Determine whether content is the text arm.
338
+ * Determines whether content is the text arm.
305
339
  *
306
340
  * @param content - The file content
307
- * @returns Whether the content carries text and a language
341
+ * @returns True if the content carries text and a language; false otherwise
308
342
  *
309
343
  * @example
310
344
  * ```ts
311
345
  * isText({ text: 'hello', language: 'text' }) // true
312
346
  * ```
313
347
  */
314
- export declare function isText(content: FileContent): content is {
315
- readonly text: string;
316
- readonly language: string;
317
- };
348
+ export declare function isText(content: FileContent): content is TextContent;
318
349
 
319
350
  /**
320
- * Determine whether a 1-based range is structurally valid.
351
+ * Determines whether a 1-based range is structurally valid.
321
352
  *
322
353
  * @param range - The range to inspect
323
- * @returns Whether both positions are positive and ordered
354
+ * @returns True if both positions are positive and ordered; false otherwise
324
355
  *
325
356
  * @example
326
357
  * ```ts
@@ -330,10 +361,14 @@ export declare function isText(content: FileContent): content is {
330
361
  export declare function isValidRange(range: Range): boolean;
331
362
 
332
363
  /**
333
- * Narrow a caught value to a {@link WorkspaceError}.
364
+ * Narrows a caught value to a {@link WorkspaceError}.
365
+ *
366
+ * @remarks
367
+ * The check is one `instanceof` test, so it stays total: every input answers `true` or `false`
368
+ * and none throws.
334
369
  *
335
370
  * @param value - The caught value
336
- * @returns Whether the value is a workspace error
371
+ * @returns True if the value is a workspace error; false otherwise
337
372
  *
338
373
  * @example
339
374
  * ```ts
@@ -343,10 +378,10 @@ export declare function isValidRange(range: Range): boolean;
343
378
  export declare function isWorkspaceError(value: unknown): value is WorkspaceError;
344
379
 
345
380
  /**
346
- * Narrow an unknown value to a workspace snapshot.
381
+ * Narrows an unknown value to a workspace snapshot.
347
382
  *
348
383
  * @param value - The value read from a persistence boundary
349
- * @returns Whether the value has the workspace snapshot shape
384
+ * @returns True if the value has the workspace snapshot shape; false otherwise
350
385
  *
351
386
  * @example
352
387
  * ```ts
@@ -356,7 +391,7 @@ export declare function isWorkspaceError(value: unknown): value is WorkspaceErro
356
391
  export declare function isWorkspaceSnapshot(value: unknown): value is WorkspaceSnapshot;
357
392
 
358
393
  /**
359
- * A process-local workspace snapshot store.
394
+ * Holds workspace snapshots in the current process.
360
395
  *
361
396
  * @example
362
397
  * ```ts
@@ -373,7 +408,7 @@ export declare class MemoryWorkspaceStore implements WorkspaceStoreInterface {
373
408
  }
374
409
 
375
410
  /**
376
- * Convert a 1-based position to a zero-based string offset.
411
+ * Converts a 1-based position to a zero-based string offset.
377
412
  *
378
413
  * @param text - The addressed text
379
414
  * @param position - The requested position
@@ -386,20 +421,20 @@ export declare class MemoryWorkspaceStore implements WorkspaceStoreInterface {
386
421
  */
387
422
  export declare function offsetAt(text: string, position: Position): number;
388
423
 
389
- /** A 1-based caret position inside text. */
424
+ /** Locates a 1-based caret inside text. */
390
425
  export declare interface Position {
391
426
  readonly line: number;
392
427
  readonly column: number;
393
428
  }
394
429
 
395
- /** A half-open text span whose start is inclusive and end is exclusive. */
430
+ /** Represents a half-open text span whose start is inclusive and end is exclusive. */
396
431
  export declare interface Range {
397
432
  readonly start: Position;
398
433
  readonly end: Position;
399
434
  }
400
435
 
401
436
  /**
402
- * Assemble a nested range from four 1-based coordinates.
437
+ * Assembles a nested range from four 1-based coordinates.
403
438
  *
404
439
  * @param fromLine - The start line
405
440
  * @param fromColumn - The start column
@@ -414,19 +449,19 @@ export declare interface Range {
414
449
  */
415
450
  export declare function rangeOf(fromLine: number, fromColumn: number, toLine: number, toColumn: number): Range;
416
451
 
417
- /** The content and clamped span returned by a ranged read. */
452
+ /** Carries the content and clamped span returned by a ranged read. */
418
453
  export declare interface ReadResult {
419
454
  readonly content: string;
420
455
  readonly range: Range;
421
456
  }
422
457
 
423
- /** The tallies produced by a replacement operation. */
458
+ /** Carries the tallies a replacement produced: the occurrences replaced and the files changed. */
424
459
  export declare interface ReplaceResult {
425
460
  readonly occurrences: number;
426
461
  readonly files: number;
427
462
  }
428
463
 
429
- /** One 1-based search hit and the full line that contains it. */
464
+ /** Reports one 1-based search hit and the full line that contains it. */
430
465
  export declare interface SearchMatch {
431
466
  readonly path: string;
432
467
  readonly line: number;
@@ -436,11 +471,13 @@ export declare interface SearchMatch {
436
471
  }
437
472
 
438
473
  /**
439
- * Search and replacement behavior.
474
+ * Configures search and replacement behavior.
440
475
  *
441
476
  * @remarks
442
- * `regex` treats the query as regular-expression source, `sensitive` controls case sensitivity,
443
- * and `limit` caps the search or replacement count.
477
+ * If `regex` is `true`, the query is treated as regular-expression source; if `false`, it is
478
+ * escaped and matched literally. Default: `false`. If `sensitive` is `false`, matching ignores
479
+ * case; if `true`, it does not. Default: `true`. `limit` caps the search or replacement count.
480
+ * Default: unlimited.
444
481
  */
445
482
  export declare interface SearchOptions {
446
483
  readonly regex?: boolean;
@@ -449,7 +486,7 @@ export declare interface SearchOptions {
449
486
  }
450
487
 
451
488
  /**
452
- * Slice a clamped half-open text range.
489
+ * Slices a clamped half-open text range.
453
490
  *
454
491
  * @param text - The source text
455
492
  * @param range - The requested range
@@ -463,7 +500,7 @@ export declare interface SearchOptions {
463
500
  export declare function sliceRange(text: string, range: Range): string;
464
501
 
465
502
  /**
466
- * Replace a clamped half-open text range.
503
+ * Replaces a clamped half-open text range.
467
504
  *
468
505
  * @param text - The source text
469
506
  * @param range - The requested range
@@ -477,12 +514,19 @@ export declare function sliceRange(text: string, range: Range): string;
477
514
  */
478
515
  export declare function spliceRange(text: string, range: Range, replacement: string): string;
479
516
 
517
+ /** Holds the text arm of a file's immutable content: a body and its language tag. */
518
+ export declare interface TextContent {
519
+ readonly text: string;
520
+ readonly language: string;
521
+ }
522
+
480
523
  /**
481
- * A mutable path-keyed editing surface over immutable files.
524
+ * Implements `WorkspaceInterface` over one insertion-ordered path map the instance owns,
525
+ * projecting fresh arrays on every read.
482
526
  *
483
527
  * Whole-file edits create text files, ranged edits operate only on existing text files, and
484
528
  * binary files remain available through construction-time hydration. Mutations emit after the
485
- * registry has changed.
529
+ * file map has changed.
486
530
  *
487
531
  * @example
488
532
  * ```ts
@@ -497,7 +541,7 @@ export declare function spliceRange(text: string, range: Range, replacement: str
497
541
  export declare class Workspace implements WorkspaceInterface {
498
542
  #private;
499
543
  /**
500
- * Create a workspace.
544
+ * Creates a workspace.
501
545
  *
502
546
  * @param options - Optional identity, emitter configuration, and initial files
503
547
  */
@@ -530,12 +574,15 @@ export declare class Workspace implements WorkspaceInterface {
530
574
  destroy(): void;
531
575
  }
532
576
 
533
- /** An invalid workspace edit or search operation. */
577
+ /**
578
+ * Reports an invalid workspace edit or search operation, carrying a {@link WorkspaceErrorCode}
579
+ * and, when the operation had one, the context it ran under.
580
+ */
534
581
  export declare class WorkspaceError extends Error {
535
582
  readonly code: WorkspaceErrorCode;
536
583
  readonly context?: Readonly<Record<string, unknown>>;
537
584
  /**
538
- * Create a workspace error.
585
+ * Creates a workspace error.
539
586
  *
540
587
  * @param code - The machine-readable failure code
541
588
  * @param message - The human-readable failure message
@@ -544,10 +591,10 @@ export declare class WorkspaceError extends Error {
544
591
  constructor(code: WorkspaceErrorCode, message: string, context?: Readonly<Record<string, unknown>>);
545
592
  }
546
593
 
547
- /** The machine-readable failure codes raised by the workspace edit surface. */
548
- export declare type WorkspaceErrorCode = 'MODALITY' | 'PATTERN' | 'RANGE';
594
+ /** Names the machine-readable failure codes raised by the workspace edit surface. */
595
+ export declare type WorkspaceErrorCode = 'MISSING' | 'MODALITY' | 'PATTERN' | 'RANGE';
549
596
 
550
- /** Events emitted after workspace mutations complete. */
597
+ /** Names the events emitted after workspace mutations complete. */
551
598
  export declare type WorkspaceEventMap = {
552
599
  readonly write: readonly [file: FileInterface];
553
600
  readonly remove: readonly [path: string];
@@ -555,38 +602,180 @@ export declare type WorkspaceEventMap = {
555
602
  readonly clear: readonly [];
556
603
  };
557
604
 
558
- /** A mutable path-keyed editing surface over immutable file values. */
605
+ /** Represents a mutable path-keyed editing surface over immutable file values. */
559
606
  export declare interface WorkspaceInterface {
607
+ /** Reports the registry key, either supplied at construction or minted. */
560
608
  readonly id: string;
609
+ /** Reports the owned emitter that publishes every settled mutation. */
561
610
  readonly emitter: EmitterInterface<WorkspaceEventMap>;
611
+ /** Reports how many files the map holds. */
562
612
  readonly count: number;
613
+ /**
614
+ * Finds the file value stored at one path.
615
+ *
616
+ * @param path - The path to look up
617
+ * @returns The frozen file value, or `undefined` when the path is absent
618
+ */
563
619
  file(path: string): FileInterface | undefined;
620
+ /**
621
+ * Lists every file in insertion order.
622
+ *
623
+ * @returns A fresh array of the frozen file values
624
+ */
564
625
  files(): readonly FileInterface[];
626
+ /**
627
+ * Reads a text file whole.
628
+ *
629
+ * @param path - The path to read
630
+ * @returns The file's text, or `undefined` when the path is absent or holds binary content
631
+ */
565
632
  read(path: string): string | undefined;
633
+ /**
634
+ * Reads a clamped span of a text file.
635
+ *
636
+ * @param path - The path to read
637
+ * @param range - The requested half-open span, clamped to the text's bounds
638
+ * @returns The span's text and the span actually covered, or `undefined` when the path is absent
639
+ * @throws Thrown when a range is requested for binary content (`MODALITY`).
640
+ */
566
641
  read(path: string, range: Range): ReadResult | undefined;
642
+ /**
643
+ * Reads a batch of text files.
644
+ *
645
+ * @param paths - The paths to read
646
+ * @returns Each present text path mapped to its text, with absent and binary paths omitted
647
+ */
567
648
  read(paths: readonly string[]): Readonly<Record<string, string>>;
649
+ /**
650
+ * Checks whether one path is present.
651
+ *
652
+ * @param path - The path to test
653
+ * @returns True if the workspace holds the path; false otherwise
654
+ */
568
655
  has(path: string): boolean;
656
+ /**
657
+ * Checks whether every path in a batch is present.
658
+ *
659
+ * @param paths - The paths to test
660
+ * @returns True if every entry succeeded; false otherwise
661
+ */
569
662
  has(paths: readonly string[]): boolean;
663
+ /**
664
+ * Scans text files for a query, skipping binary content.
665
+ *
666
+ * @param query - The literal text, or regular-expression source under `regex`
667
+ * @param options - Optional matching controls
668
+ * @returns Each hit in insertion order across files, then line order within a file
669
+ * @throws Thrown when the pattern source will not compile (`PATTERN`).
670
+ */
570
671
  search(query: string, options?: SearchOptions): readonly SearchMatch[];
672
+ /**
673
+ * Rewrites every match across the text files, skipping binary content.
674
+ *
675
+ * @param query - The literal text, or regular-expression source under `regex`
676
+ * @param replacement - The text each match becomes
677
+ * @param options - Optional matching controls
678
+ * @returns The occurrences replaced and the files changed
679
+ * @throws Thrown when the pattern source will not compile (`PATTERN`).
680
+ */
571
681
  replace(query: string, replacement: string, options?: SearchOptions): ReplaceResult;
682
+ /**
683
+ * Writes whole text to a path, creating it when absent and retyping a binary path as text.
684
+ *
685
+ * @param path - The path to write
686
+ * @param content - The text the path holds afterwards
687
+ */
572
688
  write(path: string, content: string): void;
689
+ /**
690
+ * Splices a clamped span of an existing text file.
691
+ *
692
+ * @param path - The path to edit
693
+ * @param content - The text the span becomes
694
+ * @param range - The half-open span to replace, clamped to the text's bounds
695
+ * @throws Thrown when a ranged write names a missing path (`MISSING`) or binary content
696
+ * (`MODALITY`), or the range is inverted or has a coordinate below 1 (`RANGE`).
697
+ */
573
698
  write(path: string, content: string, range: Range): void;
699
+ /**
700
+ * Writes a record batch, one whole-text write per entry.
701
+ *
702
+ * @param files - Each path mapped to the text it holds afterwards
703
+ */
574
704
  write(files: Readonly<Record<string, string>>): void;
705
+ /**
706
+ * Puts text before a path's existing content, treating an absent path as empty text.
707
+ *
708
+ * @param path - The path to edit
709
+ * @param content - The text placed before what is there
710
+ * @throws Thrown when the target path holds binary content (`MODALITY`).
711
+ */
575
712
  prepend(path: string, content: string): void;
713
+ /**
714
+ * Puts text before existing content for each entry of a record batch.
715
+ *
716
+ * @param files - Each path mapped to the text placed before what is there
717
+ * @throws Thrown when a target path holds binary content (`MODALITY`).
718
+ */
576
719
  prepend(files: Readonly<Record<string, string>>): void;
720
+ /**
721
+ * Puts text after a path's existing content, treating an absent path as empty text.
722
+ *
723
+ * @param path - The path to edit
724
+ * @param content - The text placed after what is there
725
+ * @throws Thrown when the target path holds binary content (`MODALITY`).
726
+ */
577
727
  append(path: string, content: string): void;
728
+ /**
729
+ * Puts text after existing content for each entry of a record batch.
730
+ *
731
+ * @param files - Each path mapped to the text placed after what is there
732
+ * @throws Thrown when a target path holds binary content (`MODALITY`).
733
+ */
578
734
  append(files: Readonly<Record<string, string>>): void;
735
+ /**
736
+ * Re-keys one file to a new path, keeping the source's insertion slot.
737
+ *
738
+ * @param from - The path to move
739
+ * @param to - The path the file takes
740
+ * @returns True if the file moved; false otherwise, which a same-path move also reports
741
+ */
579
742
  move(from: string, to: string): boolean;
743
+ /**
744
+ * Re-keys each entry of a mapping batch, moving every source it can.
745
+ *
746
+ * @param mapping - Each source path mapped to its target path
747
+ * @returns True if every entry succeeded; false otherwise
748
+ */
580
749
  move(mapping: Readonly<Record<string, string>>): boolean;
750
+ /**
751
+ * Drops one path, leaving an absent path untouched.
752
+ *
753
+ * @param path - The path to drop
754
+ * @returns True if a file was dropped; false otherwise
755
+ */
581
756
  remove(path: string): boolean;
757
+ /**
758
+ * Drops each path of a batch, dropping every present path.
759
+ *
760
+ * @param paths - The paths to drop
761
+ * @returns True if every entry succeeded; false otherwise
762
+ */
582
763
  remove(paths: readonly string[]): boolean;
764
+ /** Empties the workspace and emits one `clear`, never a burst of per-path removals. */
583
765
  clear(): void;
766
+ /**
767
+ * Projects the identity and a flat file list into a serializable value.
768
+ *
769
+ * @returns The JSON-serializable state a store persists
770
+ */
584
771
  snapshot(): WorkspaceSnapshot;
772
+ /** Releases the owned emitter, leaving the editing surface functional and unobserved. */
585
773
  destroy(): void;
586
774
  }
587
775
 
588
776
  /**
589
- * An insertion-ordered workspace registry with an active selection.
777
+ * Implements `WorkspaceManagerInterface` over an insertion-ordered id map and one active id
778
+ * the instance owns, resolving `active` through that map on every read and holding no emitter.
590
779
  *
591
780
  * A supplied store adds lenient snapshot `open` and `save` operations. Event defaults flow into
592
781
  * workspaces created through the registry, while observability remains owned by each workspace.
@@ -603,7 +792,7 @@ export declare interface WorkspaceInterface {
603
792
  export declare class WorkspaceManager implements WorkspaceManagerInterface {
604
793
  #private;
605
794
  /**
606
- * Create a registry.
795
+ * Creates a registry.
607
796
  *
608
797
  * @param options - Default event hooks and optional snapshot store
609
798
  */
@@ -621,24 +810,82 @@ export declare class WorkspaceManager implements WorkspaceManagerInterface {
621
810
  clear(): void;
622
811
  }
623
812
 
624
- /** An insertion-ordered workspace registry with an active selection and optional durability. */
813
+ /**
814
+ * Represents an insertion-ordered workspace registry with an active selection and optional
815
+ * durability.
816
+ */
625
817
  export declare interface WorkspaceManagerInterface {
818
+ /** Reports how many workspaces the registry holds. */
626
819
  readonly count: number;
820
+ /** Reports the current selection, resolved through the registry on every read. */
627
821
  readonly active: WorkspaceInterface | undefined;
822
+ /**
823
+ * Finds one registered workspace by id.
824
+ *
825
+ * @param id - The workspace identifier
826
+ * @returns The registered workspace, or `undefined` when the id is unknown
827
+ */
628
828
  workspace(id: string): WorkspaceInterface | undefined;
829
+ /**
830
+ * Lists registered workspaces in insertion order.
831
+ *
832
+ * @returns A fresh array of the registered workspaces
833
+ */
629
834
  workspaces(): readonly WorkspaceInterface[];
835
+ /**
836
+ * Creates and registers a workspace, activating it when no selection is active yet.
837
+ *
838
+ * @param options - Optional identity, emitter configuration, and initial files; the registry's
839
+ * own `on` and `error` supply the defaults
840
+ * @returns The registered workspace
841
+ */
630
842
  add(options?: WorkspaceOptions): WorkspaceInterface;
843
+ /**
844
+ * Re-points the active selection at a registered workspace.
845
+ *
846
+ * @param id - The workspace identifier
847
+ * @returns The newly active workspace, or `undefined` when the id is unknown, which leaves the
848
+ * selection unchanged
849
+ */
631
850
  switch(id: string): WorkspaceInterface | undefined;
851
+ /**
852
+ * Activates a registered workspace, or hydrates one from a stored snapshot on a registry miss.
853
+ *
854
+ * @param id - The workspace identifier
855
+ * @returns The active workspace, or `undefined` when neither the registry nor the store holds
856
+ * the id
857
+ */
632
858
  open(id: string): Promise<WorkspaceInterface | undefined>;
859
+ /**
860
+ * Persists a registered workspace's snapshot under its own id.
861
+ *
862
+ * @param id - The workspace identifier
863
+ * @returns True if the snapshot was written; false otherwise, which an unregistered id and a
864
+ * registry with no store both report
865
+ */
633
866
  save(id: string): Promise<boolean>;
867
+ /**
868
+ * Drops one registered workspace and destroys it.
869
+ *
870
+ * @param id - The workspace identifier
871
+ * @returns True if a workspace was dropped; false otherwise
872
+ */
634
873
  remove(id: string): boolean;
874
+ /**
875
+ * Drops each id of a batch, dropping every registered one.
876
+ *
877
+ * @param ids - The workspace identifiers
878
+ * @returns True if every entry succeeded; false otherwise
879
+ */
635
880
  remove(ids: readonly string[]): boolean;
881
+ /** Empties the registry, destroying each workspace and clearing the selection. */
636
882
  clear(): void;
637
883
  }
638
884
 
639
885
  /**
640
- * Workspace-manager construction options.
886
+ * Configures a workspace registry at construction.
641
887
  *
888
+ * @remarks
642
889
  * `on` and `error` become defaults for created workspaces; `store` supplies optional durability.
643
890
  */
644
891
  export declare interface WorkspaceManagerOptions {
@@ -648,11 +895,12 @@ export declare interface WorkspaceManagerOptions {
648
895
  }
649
896
 
650
897
  /**
651
- * Workspace construction options.
898
+ * Configures a workspace at construction.
652
899
  *
653
900
  * @remarks
654
- * `id` supplies the registry key, `on` supplies initial event listeners, `error` receives isolated
655
- * listener failures, and `seed` hydrates initial immutable files without emitting edits.
901
+ * `id` supplies the registry key. Default: a minted UUID. `on` supplies initial event listeners,
902
+ * `error` receives isolated listener failures, and `seed` hydrates initial immutable files without
903
+ * emitting edits.
656
904
  */
657
905
  export declare interface WorkspaceOptions {
658
906
  readonly id?: string;
@@ -661,36 +909,36 @@ export declare interface WorkspaceOptions {
661
909
  readonly seed?: Iterable<FileInterface>;
662
910
  }
663
911
 
664
- /** A JSON-serializable workspace snapshot. */
912
+ /** Represents a workspace's stored state in JSON-serializable form. */
665
913
  export declare interface WorkspaceSnapshot {
666
914
  readonly id: string;
667
915
  readonly files: readonly FileInterface[];
668
916
  }
669
917
 
670
- /** The database row used to persist one opaque workspace snapshot. */
918
+ /** Represents the database row used to persist one opaque workspace snapshot. */
671
919
  export declare interface WorkspaceSnapshotRow {
672
920
  readonly id: string;
673
921
  readonly snapshot: unknown;
674
922
  }
675
923
 
676
- /** The asynchronous point-access persistence contract for workspace snapshots. */
924
+ /** Persists workspace snapshots through an asynchronous point-access contract. */
677
925
  export declare interface WorkspaceStoreInterface {
678
926
  /**
679
- * Resolve a snapshot.
927
+ * Resolves a snapshot by workspace id.
680
928
  *
681
929
  * @param id - The workspace identifier
682
930
  * @returns The snapshot, or `undefined` when absent
683
931
  */
684
932
  get(id: string): Promise<WorkspaceSnapshot | undefined>;
685
933
  /**
686
- * Insert or replace a snapshot under its own identifier.
934
+ * Inserts or replaces a snapshot under its own identifier.
687
935
  *
688
936
  * @param snapshot - The snapshot to persist
689
937
  * @returns A promise that resolves when persistence completes
690
938
  */
691
939
  set(snapshot: WorkspaceSnapshot): Promise<void>;
692
940
  /**
693
- * Delete a snapshot when present.
941
+ * Deletes a snapshot when present.
694
942
  *
695
943
  * @param id - The workspace identifier
696
944
  * @returns A promise that resolves when deletion completes