@orkestrel/workspace 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/core/index.cjs +112 -101
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +312 -103
- package/dist/src/core/index.d.ts +312 -103
- package/dist/src/core/index.js +112 -101
- package/dist/src/core/index.js.map +1 -1
- package/package.json +20 -16
|
@@ -4,11 +4,17 @@ import { EmitterHooks } from '@orkestrel/emitter';
|
|
|
4
4
|
import { EmitterInterface } from '@orkestrel/emitter';
|
|
5
5
|
import { TableInterface } from '@orkestrel/database';
|
|
6
6
|
|
|
7
|
-
/**
|
|
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
|
+
}
|
|
12
|
+
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
45
|
+
* Computes the decoded byte length of a base64 string.
|
|
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
|
-
*
|
|
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,9 @@ export declare function computeSize(content: FileContent): number;
|
|
|
62
81
|
export declare function countLines(content: FileContent): number;
|
|
63
82
|
|
|
64
83
|
/**
|
|
65
|
-
*
|
|
84
|
+
* Creates the binary arm of {@link FileContent}.
|
|
66
85
|
*
|
|
67
|
-
* @param
|
|
86
|
+
* @param base64 - The base64 payload
|
|
68
87
|
* @param mime - The binary MIME
|
|
69
88
|
* @returns Binary file content
|
|
70
89
|
*
|
|
@@ -75,12 +94,12 @@ export declare function countLines(content: FileContent): number;
|
|
|
75
94
|
* createBinaryContent('AAAA', 'image/png')
|
|
76
95
|
* ```
|
|
77
96
|
*/
|
|
78
|
-
export declare function createBinaryContent(
|
|
97
|
+
export declare function createBinaryContent(base64: string, mime: BinaryMIME): BinaryContent;
|
|
79
98
|
|
|
80
99
|
/**
|
|
81
|
-
*
|
|
100
|
+
* Creates a database-backed workspace snapshot store.
|
|
82
101
|
*
|
|
83
|
-
* @param driver - The database driver
|
|
102
|
+
* @param driver - The database driver. Default: an in-memory driver.
|
|
84
103
|
* @returns A workspace store backed by the supplied driver
|
|
85
104
|
*
|
|
86
105
|
* @example
|
|
@@ -93,7 +112,7 @@ export declare function createBinaryContent(data: string, mime: BinaryMIME): Fil
|
|
|
93
112
|
export declare function createDatabaseWorkspaceStore(driver?: DriverInterface): WorkspaceStoreInterface;
|
|
94
113
|
|
|
95
114
|
/**
|
|
96
|
-
*
|
|
115
|
+
* Creates an immutable file with derived size and line counts.
|
|
97
116
|
*
|
|
98
117
|
* @param input - The file path, content, and optional state
|
|
99
118
|
* @returns A frozen file record
|
|
@@ -108,7 +127,7 @@ export declare function createDatabaseWorkspaceStore(driver?: DriverInterface):
|
|
|
108
127
|
export declare function createFile(input: FileInput): FileInterface;
|
|
109
128
|
|
|
110
129
|
/**
|
|
111
|
-
*
|
|
130
|
+
* Creates an in-memory workspace snapshot store.
|
|
112
131
|
*
|
|
113
132
|
* @returns A process-local workspace store
|
|
114
133
|
*
|
|
@@ -122,7 +141,7 @@ export declare function createFile(input: FileInput): FileInterface;
|
|
|
122
141
|
export declare function createMemoryWorkspaceStore(): WorkspaceStoreInterface;
|
|
123
142
|
|
|
124
143
|
/**
|
|
125
|
-
*
|
|
144
|
+
* Creates the text arm of {@link FileContent}.
|
|
126
145
|
*
|
|
127
146
|
* @param text - The text body
|
|
128
147
|
* @param language - The language tag
|
|
@@ -135,10 +154,10 @@ export declare function createMemoryWorkspaceStore(): WorkspaceStoreInterface;
|
|
|
135
154
|
* createTextContent('hello', 'text')
|
|
136
155
|
* ```
|
|
137
156
|
*/
|
|
138
|
-
export declare function createTextContent(text: string, language: string):
|
|
157
|
+
export declare function createTextContent(text: string, language: string): TextContent;
|
|
139
158
|
|
|
140
159
|
/**
|
|
141
|
-
*
|
|
160
|
+
* Creates a workspace.
|
|
142
161
|
*
|
|
143
162
|
* @param options - Optional identity, emitter configuration, and initial files
|
|
144
163
|
* @returns A working workspace
|
|
@@ -154,7 +173,7 @@ export declare function createTextContent(text: string, language: string): FileC
|
|
|
154
173
|
export declare function createWorkspace(options?: WorkspaceOptions): WorkspaceInterface;
|
|
155
174
|
|
|
156
175
|
/**
|
|
157
|
-
*
|
|
176
|
+
* Creates an empty workspace registry.
|
|
158
177
|
*
|
|
159
178
|
* @param options - Default event hooks and optional durability
|
|
160
179
|
* @returns A workspace manager
|
|
@@ -170,21 +189,27 @@ export declare function createWorkspace(options?: WorkspaceOptions): WorkspaceIn
|
|
|
170
189
|
export declare function createWorkspaceManager(options?: WorkspaceManagerOptions): WorkspaceManagerInterface;
|
|
171
190
|
|
|
172
191
|
/**
|
|
173
|
-
*
|
|
192
|
+
* Persists workspace snapshots in a database table.
|
|
174
193
|
*
|
|
175
194
|
* Snapshots occupy one opaque column and are narrowed when read back from the storage boundary.
|
|
176
195
|
*
|
|
177
196
|
* @example
|
|
178
197
|
* ```ts
|
|
179
|
-
* import {
|
|
180
|
-
*
|
|
181
|
-
*
|
|
198
|
+
* import { rawShape, stringShape } from '@orkestrel/contract'
|
|
199
|
+
* import { createDatabase, createMemoryDriver } from '@orkestrel/database'
|
|
200
|
+
* import { DatabaseWorkspaceStore } from '@orkestrel/workspace'
|
|
201
|
+
*
|
|
202
|
+
* const database = createDatabase({
|
|
203
|
+
* driver: createMemoryDriver(),
|
|
204
|
+
* tables: { workspaces: { id: stringShape(), snapshot: rawShape({}) } },
|
|
205
|
+
* })
|
|
206
|
+
* const store = new DatabaseWorkspaceStore(database.table('workspaces'))
|
|
182
207
|
* ```
|
|
183
208
|
*/
|
|
184
209
|
export declare class DatabaseWorkspaceStore implements WorkspaceStoreInterface {
|
|
185
210
|
#private;
|
|
186
211
|
/**
|
|
187
|
-
*
|
|
212
|
+
* Wraps a workspace snapshot table.
|
|
188
213
|
*
|
|
189
214
|
* @param table - The table keyed by workspace identifier
|
|
190
215
|
*/
|
|
@@ -195,20 +220,7 @@ export declare class DatabaseWorkspaceStore implements WorkspaceStoreInterface {
|
|
|
195
220
|
}
|
|
196
221
|
|
|
197
222
|
/**
|
|
198
|
-
*
|
|
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.
|
|
223
|
+
* Escapes regular-expression metacharacters for literal matching.
|
|
212
224
|
*
|
|
213
225
|
* @param value - The literal text
|
|
214
226
|
* @returns The escaped regular-expression source
|
|
@@ -221,7 +233,7 @@ export declare function decodedSize(base64: string): number;
|
|
|
221
233
|
export declare function escapeRegExp(value: string): string;
|
|
222
234
|
|
|
223
235
|
/**
|
|
224
|
-
*
|
|
236
|
+
* Maps file extensions to language tags for text content.
|
|
225
237
|
*
|
|
226
238
|
* Unknown extensions intentionally fall back to `text` in
|
|
227
239
|
* {@link import('./helpers.js').inferLanguage}.
|
|
@@ -229,24 +241,19 @@ export declare function escapeRegExp(value: string): string;
|
|
|
229
241
|
export declare const EXTENSION_LANGUAGES: Readonly<Record<string, string>>;
|
|
230
242
|
|
|
231
243
|
/**
|
|
232
|
-
*
|
|
244
|
+
* Holds a file's immutable content: either text with a language tag or a base64 string with a
|
|
245
|
+
* MIME.
|
|
233
246
|
*/
|
|
234
|
-
export declare type FileContent =
|
|
235
|
-
readonly text: string;
|
|
236
|
-
readonly language: string;
|
|
237
|
-
} | {
|
|
238
|
-
readonly data: string;
|
|
239
|
-
readonly mime: BinaryMIME;
|
|
240
|
-
};
|
|
247
|
+
export declare type FileContent = TextContent | BinaryContent;
|
|
241
248
|
|
|
242
|
-
/**
|
|
249
|
+
/** Carries the caller-supplied values used to create an immutable file. */
|
|
243
250
|
export declare interface FileInput {
|
|
244
251
|
readonly path: string;
|
|
245
252
|
readonly content: FileContent;
|
|
246
253
|
readonly state?: FileState;
|
|
247
254
|
}
|
|
248
255
|
|
|
249
|
-
/**
|
|
256
|
+
/** Represents an immutable path-addressed file with derived byte and line counts. */
|
|
250
257
|
export declare interface FileInterface {
|
|
251
258
|
readonly path: string;
|
|
252
259
|
readonly content: FileContent;
|
|
@@ -255,11 +262,11 @@ export declare interface FileInterface {
|
|
|
255
262
|
readonly lines: number;
|
|
256
263
|
}
|
|
257
264
|
|
|
258
|
-
/**
|
|
265
|
+
/** Names the edit state of an immutable file value. */
|
|
259
266
|
export declare type FileState = 'created' | 'modified';
|
|
260
267
|
|
|
261
268
|
/**
|
|
262
|
-
*
|
|
269
|
+
* Infers a language tag from the final file extension.
|
|
263
270
|
*
|
|
264
271
|
* @param path - The file path
|
|
265
272
|
* @returns The mapped language, or `text` when the extension is absent or unknown
|
|
@@ -272,26 +279,23 @@ export declare type FileState = 'created' | 'modified';
|
|
|
272
279
|
export declare function inferLanguage(path: string): string;
|
|
273
280
|
|
|
274
281
|
/**
|
|
275
|
-
*
|
|
282
|
+
* Checks whether content is the binary arm.
|
|
276
283
|
*
|
|
277
284
|
* @param content - The file content
|
|
278
|
-
* @returns
|
|
285
|
+
* @returns True if the content carries a base64 string and a MIME; false otherwise
|
|
279
286
|
*
|
|
280
287
|
* @example
|
|
281
288
|
* ```ts
|
|
282
|
-
* isBinary({
|
|
289
|
+
* isBinary({ base64: 'AAAA', mime: 'image/png' }) // true
|
|
283
290
|
* ```
|
|
284
291
|
*/
|
|
285
|
-
export declare function isBinary(content: FileContent): content is
|
|
286
|
-
readonly data: string;
|
|
287
|
-
readonly mime: BinaryMIME;
|
|
288
|
-
};
|
|
292
|
+
export declare function isBinary(content: FileContent): content is BinaryContent;
|
|
289
293
|
|
|
290
294
|
/**
|
|
291
|
-
*
|
|
295
|
+
* Narrows an unknown value to an immutable file record.
|
|
292
296
|
*
|
|
293
297
|
* @param value - The value to inspect
|
|
294
|
-
* @returns
|
|
298
|
+
* @returns True if the value has the file shape; false otherwise
|
|
295
299
|
*
|
|
296
300
|
* @example
|
|
297
301
|
* ```ts
|
|
@@ -301,26 +305,23 @@ export declare function isBinary(content: FileContent): content is {
|
|
|
301
305
|
export declare function isFile(value: unknown): value is FileInterface;
|
|
302
306
|
|
|
303
307
|
/**
|
|
304
|
-
*
|
|
308
|
+
* Determines whether content is the text arm.
|
|
305
309
|
*
|
|
306
310
|
* @param content - The file content
|
|
307
|
-
* @returns
|
|
311
|
+
* @returns True if the content carries text and a language; false otherwise
|
|
308
312
|
*
|
|
309
313
|
* @example
|
|
310
314
|
* ```ts
|
|
311
315
|
* isText({ text: 'hello', language: 'text' }) // true
|
|
312
316
|
* ```
|
|
313
317
|
*/
|
|
314
|
-
export declare function isText(content: FileContent): content is
|
|
315
|
-
readonly text: string;
|
|
316
|
-
readonly language: string;
|
|
317
|
-
};
|
|
318
|
+
export declare function isText(content: FileContent): content is TextContent;
|
|
318
319
|
|
|
319
320
|
/**
|
|
320
|
-
*
|
|
321
|
+
* Determines whether a 1-based range is structurally valid.
|
|
321
322
|
*
|
|
322
323
|
* @param range - The range to inspect
|
|
323
|
-
* @returns
|
|
324
|
+
* @returns True if both positions are positive and ordered; false otherwise
|
|
324
325
|
*
|
|
325
326
|
* @example
|
|
326
327
|
* ```ts
|
|
@@ -330,10 +331,10 @@ export declare function isText(content: FileContent): content is {
|
|
|
330
331
|
export declare function isValidRange(range: Range): boolean;
|
|
331
332
|
|
|
332
333
|
/**
|
|
333
|
-
*
|
|
334
|
+
* Narrows a caught value to a {@link WorkspaceError}.
|
|
334
335
|
*
|
|
335
336
|
* @param value - The caught value
|
|
336
|
-
* @returns
|
|
337
|
+
* @returns True if the value is a workspace error; false otherwise
|
|
337
338
|
*
|
|
338
339
|
* @example
|
|
339
340
|
* ```ts
|
|
@@ -343,10 +344,10 @@ export declare function isValidRange(range: Range): boolean;
|
|
|
343
344
|
export declare function isWorkspaceError(value: unknown): value is WorkspaceError;
|
|
344
345
|
|
|
345
346
|
/**
|
|
346
|
-
*
|
|
347
|
+
* Narrows an unknown value to a workspace snapshot.
|
|
347
348
|
*
|
|
348
349
|
* @param value - The value read from a persistence boundary
|
|
349
|
-
* @returns
|
|
350
|
+
* @returns True if the value has the workspace snapshot shape; false otherwise
|
|
350
351
|
*
|
|
351
352
|
* @example
|
|
352
353
|
* ```ts
|
|
@@ -356,7 +357,7 @@ export declare function isWorkspaceError(value: unknown): value is WorkspaceErro
|
|
|
356
357
|
export declare function isWorkspaceSnapshot(value: unknown): value is WorkspaceSnapshot;
|
|
357
358
|
|
|
358
359
|
/**
|
|
359
|
-
*
|
|
360
|
+
* Holds workspace snapshots in the current process.
|
|
360
361
|
*
|
|
361
362
|
* @example
|
|
362
363
|
* ```ts
|
|
@@ -373,7 +374,7 @@ export declare class MemoryWorkspaceStore implements WorkspaceStoreInterface {
|
|
|
373
374
|
}
|
|
374
375
|
|
|
375
376
|
/**
|
|
376
|
-
*
|
|
377
|
+
* Converts a 1-based position to a zero-based string offset.
|
|
377
378
|
*
|
|
378
379
|
* @param text - The addressed text
|
|
379
380
|
* @param position - The requested position
|
|
@@ -386,20 +387,20 @@ export declare class MemoryWorkspaceStore implements WorkspaceStoreInterface {
|
|
|
386
387
|
*/
|
|
387
388
|
export declare function offsetAt(text: string, position: Position): number;
|
|
388
389
|
|
|
389
|
-
/**
|
|
390
|
+
/** Locates a 1-based caret inside text. */
|
|
390
391
|
export declare interface Position {
|
|
391
392
|
readonly line: number;
|
|
392
393
|
readonly column: number;
|
|
393
394
|
}
|
|
394
395
|
|
|
395
|
-
/**
|
|
396
|
+
/** Represents a half-open text span whose start is inclusive and end is exclusive. */
|
|
396
397
|
export declare interface Range {
|
|
397
398
|
readonly start: Position;
|
|
398
399
|
readonly end: Position;
|
|
399
400
|
}
|
|
400
401
|
|
|
401
402
|
/**
|
|
402
|
-
*
|
|
403
|
+
* Assembles a nested range from four 1-based coordinates.
|
|
403
404
|
*
|
|
404
405
|
* @param fromLine - The start line
|
|
405
406
|
* @param fromColumn - The start column
|
|
@@ -414,19 +415,19 @@ export declare interface Range {
|
|
|
414
415
|
*/
|
|
415
416
|
export declare function rangeOf(fromLine: number, fromColumn: number, toLine: number, toColumn: number): Range;
|
|
416
417
|
|
|
417
|
-
/**
|
|
418
|
+
/** Carries the content and clamped span returned by a ranged read. */
|
|
418
419
|
export declare interface ReadResult {
|
|
419
420
|
readonly content: string;
|
|
420
421
|
readonly range: Range;
|
|
421
422
|
}
|
|
422
423
|
|
|
423
|
-
/**
|
|
424
|
+
/** Carries the tallies produced by a replacement operation. */
|
|
424
425
|
export declare interface ReplaceResult {
|
|
425
426
|
readonly occurrences: number;
|
|
426
427
|
readonly files: number;
|
|
427
428
|
}
|
|
428
429
|
|
|
429
|
-
/**
|
|
430
|
+
/** Reports one 1-based search hit and the full line that contains it. */
|
|
430
431
|
export declare interface SearchMatch {
|
|
431
432
|
readonly path: string;
|
|
432
433
|
readonly line: number;
|
|
@@ -436,11 +437,13 @@ export declare interface SearchMatch {
|
|
|
436
437
|
}
|
|
437
438
|
|
|
438
439
|
/**
|
|
439
|
-
*
|
|
440
|
+
* Configures search and replacement behavior.
|
|
440
441
|
*
|
|
441
442
|
* @remarks
|
|
442
|
-
* `regex`
|
|
443
|
-
* and `
|
|
443
|
+
* If `regex` is `true`, the query is treated as regular-expression source; if `false`, it is
|
|
444
|
+
* escaped and matched literally. Default: `false`. If `sensitive` is `false`, matching ignores
|
|
445
|
+
* case; if `true`, it does not. Default: `true`. `limit` caps the search or replacement count.
|
|
446
|
+
* Default: unlimited.
|
|
444
447
|
*/
|
|
445
448
|
export declare interface SearchOptions {
|
|
446
449
|
readonly regex?: boolean;
|
|
@@ -449,7 +452,7 @@ export declare interface SearchOptions {
|
|
|
449
452
|
}
|
|
450
453
|
|
|
451
454
|
/**
|
|
452
|
-
*
|
|
455
|
+
* Slices a clamped half-open text range.
|
|
453
456
|
*
|
|
454
457
|
* @param text - The source text
|
|
455
458
|
* @param range - The requested range
|
|
@@ -463,7 +466,7 @@ export declare interface SearchOptions {
|
|
|
463
466
|
export declare function sliceRange(text: string, range: Range): string;
|
|
464
467
|
|
|
465
468
|
/**
|
|
466
|
-
*
|
|
469
|
+
* Replaces a clamped half-open text range.
|
|
467
470
|
*
|
|
468
471
|
* @param text - The source text
|
|
469
472
|
* @param range - The requested range
|
|
@@ -477,8 +480,14 @@ export declare function sliceRange(text: string, range: Range): string;
|
|
|
477
480
|
*/
|
|
478
481
|
export declare function spliceRange(text: string, range: Range, replacement: string): string;
|
|
479
482
|
|
|
483
|
+
/** Holds the text arm of a file's immutable content: a body and its language tag. */
|
|
484
|
+
export declare interface TextContent {
|
|
485
|
+
readonly text: string;
|
|
486
|
+
readonly language: string;
|
|
487
|
+
}
|
|
488
|
+
|
|
480
489
|
/**
|
|
481
|
-
*
|
|
490
|
+
* Provides a mutable path-keyed editing surface over immutable files.
|
|
482
491
|
*
|
|
483
492
|
* Whole-file edits create text files, ranged edits operate only on existing text files, and
|
|
484
493
|
* binary files remain available through construction-time hydration. Mutations emit after the
|
|
@@ -497,7 +506,7 @@ export declare function spliceRange(text: string, range: Range, replacement: str
|
|
|
497
506
|
export declare class Workspace implements WorkspaceInterface {
|
|
498
507
|
#private;
|
|
499
508
|
/**
|
|
500
|
-
*
|
|
509
|
+
* Creates a workspace.
|
|
501
510
|
*
|
|
502
511
|
* @param options - Optional identity, emitter configuration, and initial files
|
|
503
512
|
*/
|
|
@@ -530,12 +539,12 @@ export declare class Workspace implements WorkspaceInterface {
|
|
|
530
539
|
destroy(): void;
|
|
531
540
|
}
|
|
532
541
|
|
|
533
|
-
/**
|
|
542
|
+
/** Reports an invalid workspace edit or search operation. */
|
|
534
543
|
export declare class WorkspaceError extends Error {
|
|
535
544
|
readonly code: WorkspaceErrorCode;
|
|
536
545
|
readonly context?: Readonly<Record<string, unknown>>;
|
|
537
546
|
/**
|
|
538
|
-
*
|
|
547
|
+
* Creates a workspace error.
|
|
539
548
|
*
|
|
540
549
|
* @param code - The machine-readable failure code
|
|
541
550
|
* @param message - The human-readable failure message
|
|
@@ -544,10 +553,10 @@ export declare class WorkspaceError extends Error {
|
|
|
544
553
|
constructor(code: WorkspaceErrorCode, message: string, context?: Readonly<Record<string, unknown>>);
|
|
545
554
|
}
|
|
546
555
|
|
|
547
|
-
/**
|
|
548
|
-
export declare type WorkspaceErrorCode = 'MODALITY' | 'PATTERN' | 'RANGE';
|
|
556
|
+
/** Names the machine-readable failure codes raised by the workspace edit surface. */
|
|
557
|
+
export declare type WorkspaceErrorCode = 'MISSING' | 'MODALITY' | 'PATTERN' | 'RANGE';
|
|
549
558
|
|
|
550
|
-
/**
|
|
559
|
+
/** Names the events emitted after workspace mutations complete. */
|
|
551
560
|
export declare type WorkspaceEventMap = {
|
|
552
561
|
readonly write: readonly [file: FileInterface];
|
|
553
562
|
readonly remove: readonly [path: string];
|
|
@@ -555,38 +564,179 @@ export declare type WorkspaceEventMap = {
|
|
|
555
564
|
readonly clear: readonly [];
|
|
556
565
|
};
|
|
557
566
|
|
|
558
|
-
/**
|
|
567
|
+
/** Represents a mutable path-keyed editing surface over immutable file values. */
|
|
559
568
|
export declare interface WorkspaceInterface {
|
|
569
|
+
/** Reports the registry key, either supplied at construction or minted. */
|
|
560
570
|
readonly id: string;
|
|
571
|
+
/** Reports the owned emitter that publishes every settled mutation. */
|
|
561
572
|
readonly emitter: EmitterInterface<WorkspaceEventMap>;
|
|
573
|
+
/** Reports how many files the map holds. */
|
|
562
574
|
readonly count: number;
|
|
575
|
+
/**
|
|
576
|
+
* Finds the file value stored at one path.
|
|
577
|
+
*
|
|
578
|
+
* @param path - The path to look up
|
|
579
|
+
* @returns The frozen file value, or `undefined` when the path is absent
|
|
580
|
+
*/
|
|
563
581
|
file(path: string): FileInterface | undefined;
|
|
582
|
+
/**
|
|
583
|
+
* Lists every file in insertion order.
|
|
584
|
+
*
|
|
585
|
+
* @returns A fresh array of the frozen file values
|
|
586
|
+
*/
|
|
564
587
|
files(): readonly FileInterface[];
|
|
588
|
+
/**
|
|
589
|
+
* Reads a text file whole.
|
|
590
|
+
*
|
|
591
|
+
* @param path - The path to read
|
|
592
|
+
* @returns The file's text, or `undefined` when the path is absent or holds binary content
|
|
593
|
+
*/
|
|
565
594
|
read(path: string): string | undefined;
|
|
595
|
+
/**
|
|
596
|
+
* Reads a clamped span of a text file.
|
|
597
|
+
*
|
|
598
|
+
* @param path - The path to read
|
|
599
|
+
* @param range - The requested half-open span, clamped to the text's bounds
|
|
600
|
+
* @returns The span's text and the span actually covered, or `undefined` when the path is absent
|
|
601
|
+
* @throws Thrown when a range is requested for binary content (`MODALITY`).
|
|
602
|
+
*/
|
|
566
603
|
read(path: string, range: Range): ReadResult | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* Reads a batch of text files.
|
|
606
|
+
*
|
|
607
|
+
* @param paths - The paths to read
|
|
608
|
+
* @returns Each present text path mapped to its text, with absent and binary paths omitted
|
|
609
|
+
*/
|
|
567
610
|
read(paths: readonly string[]): Readonly<Record<string, string>>;
|
|
611
|
+
/**
|
|
612
|
+
* Checks whether one path is present.
|
|
613
|
+
*
|
|
614
|
+
* @param path - The path to test
|
|
615
|
+
* @returns True if the workspace holds the path; false otherwise
|
|
616
|
+
*/
|
|
568
617
|
has(path: string): boolean;
|
|
618
|
+
/**
|
|
619
|
+
* Checks whether every path in a batch is present.
|
|
620
|
+
*
|
|
621
|
+
* @param paths - The paths to test
|
|
622
|
+
* @returns True if every entry succeeded; false otherwise
|
|
623
|
+
*/
|
|
569
624
|
has(paths: readonly string[]): boolean;
|
|
625
|
+
/**
|
|
626
|
+
* Scans text files for a query, skipping binary content.
|
|
627
|
+
*
|
|
628
|
+
* @param query - The literal text, or regular-expression source under `regex`
|
|
629
|
+
* @param options - Optional matching controls
|
|
630
|
+
* @returns Each hit in insertion order across files, then line order within a file
|
|
631
|
+
* @throws Thrown when the pattern source will not compile (`PATTERN`).
|
|
632
|
+
*/
|
|
570
633
|
search(query: string, options?: SearchOptions): readonly SearchMatch[];
|
|
634
|
+
/**
|
|
635
|
+
* Rewrites every match across the text files, skipping binary content.
|
|
636
|
+
*
|
|
637
|
+
* @param query - The literal text, or regular-expression source under `regex`
|
|
638
|
+
* @param replacement - The text each match becomes
|
|
639
|
+
* @param options - Optional matching controls
|
|
640
|
+
* @returns The occurrences replaced and the files changed
|
|
641
|
+
* @throws Thrown when the pattern source will not compile (`PATTERN`).
|
|
642
|
+
*/
|
|
571
643
|
replace(query: string, replacement: string, options?: SearchOptions): ReplaceResult;
|
|
644
|
+
/**
|
|
645
|
+
* Writes whole text to a path, creating it when absent and retyping a binary path as text.
|
|
646
|
+
*
|
|
647
|
+
* @param path - The path to write
|
|
648
|
+
* @param content - The text the path holds afterwards
|
|
649
|
+
*/
|
|
572
650
|
write(path: string, content: string): void;
|
|
651
|
+
/**
|
|
652
|
+
* Splices a clamped span of an existing text file.
|
|
653
|
+
*
|
|
654
|
+
* @param path - The path to edit
|
|
655
|
+
* @param content - The text the span becomes
|
|
656
|
+
* @param range - The half-open span to replace, clamped to the text's bounds
|
|
657
|
+
* @throws Thrown when a ranged write names a missing path (`MISSING`) or binary content
|
|
658
|
+
* (`MODALITY`), or the range is inverted or has a coordinate below 1 (`RANGE`).
|
|
659
|
+
*/
|
|
573
660
|
write(path: string, content: string, range: Range): void;
|
|
661
|
+
/**
|
|
662
|
+
* Writes a record batch, one whole-text write per entry.
|
|
663
|
+
*
|
|
664
|
+
* @param files - Each path mapped to the text it holds afterwards
|
|
665
|
+
*/
|
|
574
666
|
write(files: Readonly<Record<string, string>>): void;
|
|
667
|
+
/**
|
|
668
|
+
* Puts text before a path's existing content, treating an absent path as empty text.
|
|
669
|
+
*
|
|
670
|
+
* @param path - The path to edit
|
|
671
|
+
* @param content - The text placed before what is there
|
|
672
|
+
* @throws Thrown when the target path holds binary content (`MODALITY`).
|
|
673
|
+
*/
|
|
575
674
|
prepend(path: string, content: string): void;
|
|
675
|
+
/**
|
|
676
|
+
* Puts text before existing content for each entry of a record batch.
|
|
677
|
+
*
|
|
678
|
+
* @param files - Each path mapped to the text placed before what is there
|
|
679
|
+
* @throws Thrown when a target path holds binary content (`MODALITY`).
|
|
680
|
+
*/
|
|
576
681
|
prepend(files: Readonly<Record<string, string>>): void;
|
|
682
|
+
/**
|
|
683
|
+
* Puts text after a path's existing content, treating an absent path as empty text.
|
|
684
|
+
*
|
|
685
|
+
* @param path - The path to edit
|
|
686
|
+
* @param content - The text placed after what is there
|
|
687
|
+
* @throws Thrown when the target path holds binary content (`MODALITY`).
|
|
688
|
+
*/
|
|
577
689
|
append(path: string, content: string): void;
|
|
690
|
+
/**
|
|
691
|
+
* Puts text after existing content for each entry of a record batch.
|
|
692
|
+
*
|
|
693
|
+
* @param files - Each path mapped to the text placed after what is there
|
|
694
|
+
* @throws Thrown when a target path holds binary content (`MODALITY`).
|
|
695
|
+
*/
|
|
578
696
|
append(files: Readonly<Record<string, string>>): void;
|
|
697
|
+
/**
|
|
698
|
+
* Re-keys one file to a new path, keeping the source's insertion slot.
|
|
699
|
+
*
|
|
700
|
+
* @param from - The path to move
|
|
701
|
+
* @param to - The path the file takes
|
|
702
|
+
* @returns True if the file moved; false otherwise, which a same-path move also reports
|
|
703
|
+
*/
|
|
579
704
|
move(from: string, to: string): boolean;
|
|
705
|
+
/**
|
|
706
|
+
* Re-keys each entry of a mapping batch, moving every source it can.
|
|
707
|
+
*
|
|
708
|
+
* @param mapping - Each source path mapped to its target path
|
|
709
|
+
* @returns True if every entry succeeded; false otherwise
|
|
710
|
+
*/
|
|
580
711
|
move(mapping: Readonly<Record<string, string>>): boolean;
|
|
712
|
+
/**
|
|
713
|
+
* Drops one path, leaving an absent path untouched.
|
|
714
|
+
*
|
|
715
|
+
* @param path - The path to drop
|
|
716
|
+
* @returns True if a file was dropped; false otherwise
|
|
717
|
+
*/
|
|
581
718
|
remove(path: string): boolean;
|
|
719
|
+
/**
|
|
720
|
+
* Drops each path of a batch, dropping every present path.
|
|
721
|
+
*
|
|
722
|
+
* @param paths - The paths to drop
|
|
723
|
+
* @returns True if every entry succeeded; false otherwise
|
|
724
|
+
*/
|
|
582
725
|
remove(paths: readonly string[]): boolean;
|
|
726
|
+
/** Empties the workspace and emits one `clear`, never a burst of per-path removals. */
|
|
583
727
|
clear(): void;
|
|
728
|
+
/**
|
|
729
|
+
* Projects the identity and a flat file list into a serializable value.
|
|
730
|
+
*
|
|
731
|
+
* @returns The JSON-serializable state a store persists
|
|
732
|
+
*/
|
|
584
733
|
snapshot(): WorkspaceSnapshot;
|
|
734
|
+
/** Releases the owned emitter, leaving the editing surface functional and unobserved. */
|
|
585
735
|
destroy(): void;
|
|
586
736
|
}
|
|
587
737
|
|
|
588
738
|
/**
|
|
589
|
-
*
|
|
739
|
+
* Provides an insertion-ordered workspace registry with an active selection.
|
|
590
740
|
*
|
|
591
741
|
* A supplied store adds lenient snapshot `open` and `save` operations. Event defaults flow into
|
|
592
742
|
* workspaces created through the registry, while observability remains owned by each workspace.
|
|
@@ -603,7 +753,7 @@ export declare interface WorkspaceInterface {
|
|
|
603
753
|
export declare class WorkspaceManager implements WorkspaceManagerInterface {
|
|
604
754
|
#private;
|
|
605
755
|
/**
|
|
606
|
-
*
|
|
756
|
+
* Creates a registry.
|
|
607
757
|
*
|
|
608
758
|
* @param options - Default event hooks and optional snapshot store
|
|
609
759
|
*/
|
|
@@ -621,24 +771,82 @@ export declare class WorkspaceManager implements WorkspaceManagerInterface {
|
|
|
621
771
|
clear(): void;
|
|
622
772
|
}
|
|
623
773
|
|
|
624
|
-
/**
|
|
774
|
+
/**
|
|
775
|
+
* Represents an insertion-ordered workspace registry with an active selection and optional
|
|
776
|
+
* durability.
|
|
777
|
+
*/
|
|
625
778
|
export declare interface WorkspaceManagerInterface {
|
|
779
|
+
/** Reports how many workspaces the registry holds. */
|
|
626
780
|
readonly count: number;
|
|
781
|
+
/** Reports the current selection, resolved through the registry on every read. */
|
|
627
782
|
readonly active: WorkspaceInterface | undefined;
|
|
783
|
+
/**
|
|
784
|
+
* Finds one registered workspace by id.
|
|
785
|
+
*
|
|
786
|
+
* @param id - The workspace identifier
|
|
787
|
+
* @returns The registered workspace, or `undefined` when the id is unknown
|
|
788
|
+
*/
|
|
628
789
|
workspace(id: string): WorkspaceInterface | undefined;
|
|
790
|
+
/**
|
|
791
|
+
* Lists registered workspaces in insertion order.
|
|
792
|
+
*
|
|
793
|
+
* @returns A fresh array of the registered workspaces
|
|
794
|
+
*/
|
|
629
795
|
workspaces(): readonly WorkspaceInterface[];
|
|
796
|
+
/**
|
|
797
|
+
* Creates and registers a workspace, activating it when no selection is active yet.
|
|
798
|
+
*
|
|
799
|
+
* @param options - Optional identity, emitter configuration, and initial files; the registry's
|
|
800
|
+
* own `on` and `error` supply the defaults
|
|
801
|
+
* @returns The registered workspace
|
|
802
|
+
*/
|
|
630
803
|
add(options?: WorkspaceOptions): WorkspaceInterface;
|
|
804
|
+
/**
|
|
805
|
+
* Re-points the active selection at a registered workspace.
|
|
806
|
+
*
|
|
807
|
+
* @param id - The workspace identifier
|
|
808
|
+
* @returns The newly active workspace, or `undefined` when the id is unknown, which leaves the
|
|
809
|
+
* selection unchanged
|
|
810
|
+
*/
|
|
631
811
|
switch(id: string): WorkspaceInterface | undefined;
|
|
812
|
+
/**
|
|
813
|
+
* Activates a registered workspace, or hydrates one from a stored snapshot on a registry miss.
|
|
814
|
+
*
|
|
815
|
+
* @param id - The workspace identifier
|
|
816
|
+
* @returns The active workspace, or `undefined` when neither the registry nor the store holds
|
|
817
|
+
* the id
|
|
818
|
+
*/
|
|
632
819
|
open(id: string): Promise<WorkspaceInterface | undefined>;
|
|
820
|
+
/**
|
|
821
|
+
* Persists a registered workspace's snapshot under its own id.
|
|
822
|
+
*
|
|
823
|
+
* @param id - The workspace identifier
|
|
824
|
+
* @returns True if the snapshot was written; false otherwise, which an unregistered id and a
|
|
825
|
+
* registry with no store both report
|
|
826
|
+
*/
|
|
633
827
|
save(id: string): Promise<boolean>;
|
|
828
|
+
/**
|
|
829
|
+
* Drops one registered workspace and destroys it.
|
|
830
|
+
*
|
|
831
|
+
* @param id - The workspace identifier
|
|
832
|
+
* @returns True if a workspace was dropped; false otherwise
|
|
833
|
+
*/
|
|
634
834
|
remove(id: string): boolean;
|
|
835
|
+
/**
|
|
836
|
+
* Drops each id of a batch, dropping every registered one.
|
|
837
|
+
*
|
|
838
|
+
* @param ids - The workspace identifiers
|
|
839
|
+
* @returns True if every entry succeeded; false otherwise
|
|
840
|
+
*/
|
|
635
841
|
remove(ids: readonly string[]): boolean;
|
|
842
|
+
/** Empties the registry, destroying each workspace and clearing the selection. */
|
|
636
843
|
clear(): void;
|
|
637
844
|
}
|
|
638
845
|
|
|
639
846
|
/**
|
|
640
|
-
*
|
|
847
|
+
* Configures a workspace registry at construction.
|
|
641
848
|
*
|
|
849
|
+
* @remarks
|
|
642
850
|
* `on` and `error` become defaults for created workspaces; `store` supplies optional durability.
|
|
643
851
|
*/
|
|
644
852
|
export declare interface WorkspaceManagerOptions {
|
|
@@ -648,11 +856,12 @@ export declare interface WorkspaceManagerOptions {
|
|
|
648
856
|
}
|
|
649
857
|
|
|
650
858
|
/**
|
|
651
|
-
*
|
|
859
|
+
* Configures a workspace at construction.
|
|
652
860
|
*
|
|
653
861
|
* @remarks
|
|
654
|
-
* `id` supplies the registry key
|
|
655
|
-
* listener failures, and `seed` hydrates initial immutable files without
|
|
862
|
+
* `id` supplies the registry key. Default: a minted UUID. `on` supplies initial event listeners,
|
|
863
|
+
* `error` receives isolated listener failures, and `seed` hydrates initial immutable files without
|
|
864
|
+
* emitting edits.
|
|
656
865
|
*/
|
|
657
866
|
export declare interface WorkspaceOptions {
|
|
658
867
|
readonly id?: string;
|
|
@@ -661,36 +870,36 @@ export declare interface WorkspaceOptions {
|
|
|
661
870
|
readonly seed?: Iterable<FileInterface>;
|
|
662
871
|
}
|
|
663
872
|
|
|
664
|
-
/**
|
|
873
|
+
/** Represents a workspace's stored state in JSON-serializable form. */
|
|
665
874
|
export declare interface WorkspaceSnapshot {
|
|
666
875
|
readonly id: string;
|
|
667
876
|
readonly files: readonly FileInterface[];
|
|
668
877
|
}
|
|
669
878
|
|
|
670
|
-
/**
|
|
879
|
+
/** Represents the database row used to persist one opaque workspace snapshot. */
|
|
671
880
|
export declare interface WorkspaceSnapshotRow {
|
|
672
881
|
readonly id: string;
|
|
673
882
|
readonly snapshot: unknown;
|
|
674
883
|
}
|
|
675
884
|
|
|
676
|
-
/**
|
|
885
|
+
/** Persists workspace snapshots through an asynchronous point-access contract. */
|
|
677
886
|
export declare interface WorkspaceStoreInterface {
|
|
678
887
|
/**
|
|
679
|
-
*
|
|
888
|
+
* Resolves a snapshot.
|
|
680
889
|
*
|
|
681
890
|
* @param id - The workspace identifier
|
|
682
891
|
* @returns The snapshot, or `undefined` when absent
|
|
683
892
|
*/
|
|
684
893
|
get(id: string): Promise<WorkspaceSnapshot | undefined>;
|
|
685
894
|
/**
|
|
686
|
-
*
|
|
895
|
+
* Inserts or replaces a snapshot under its own identifier.
|
|
687
896
|
*
|
|
688
897
|
* @param snapshot - The snapshot to persist
|
|
689
898
|
* @returns A promise that resolves when persistence completes
|
|
690
899
|
*/
|
|
691
900
|
set(snapshot: WorkspaceSnapshot): Promise<void>;
|
|
692
901
|
/**
|
|
693
|
-
*
|
|
902
|
+
* Deletes a snapshot when present.
|
|
694
903
|
*
|
|
695
904
|
* @param id - The workspace identifier
|
|
696
905
|
* @returns A promise that resolves when deletion completes
|