hazo_files 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/db_schema.mdc +0 -0
- package/.cursor/rules/design.mdc +0 -0
- package/.cursor/rules/general.mdc +0 -0
- package/CHANGE_LOG.md +341 -0
- package/CLAUDE.md +926 -0
- package/README.md +929 -0
- package/SETUP_CHECKLIST.md +931 -0
- package/TECHDOC.md +325 -0
- package/dist/index.d.mts +1031 -0
- package/dist/index.d.ts +1031 -0
- package/dist/index.js +2457 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2333 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ui/index.js +4054 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/index.mjs +3982 -0
- package/dist/ui/index.mjs.map +1 -0
- package/docs/ADDING_MODULES.md +964 -0
- package/hazo_files_config.ini +31 -0
- package/package.json +83 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1031 @@
|
|
|
1
|
+
import { OAuth2Client } from 'google-auth-library';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Naming rule types for hazo_files package
|
|
5
|
+
* Used for configuring and generating file/folder names based on patterns
|
|
6
|
+
*/
|
|
7
|
+
/** Variable category for grouping in UI */
|
|
8
|
+
type VariableCategory = 'user' | 'date' | 'file' | 'counter';
|
|
9
|
+
/** A variable that can be used in naming patterns */
|
|
10
|
+
interface NamingVariable {
|
|
11
|
+
/** Variable name (without braces), e.g., "project_name", "YYYY" */
|
|
12
|
+
variable_name: string;
|
|
13
|
+
/** Human-readable description */
|
|
14
|
+
description: string;
|
|
15
|
+
/** Example value for preview */
|
|
16
|
+
example_value: string;
|
|
17
|
+
/** Category for grouping in UI */
|
|
18
|
+
category?: VariableCategory;
|
|
19
|
+
}
|
|
20
|
+
/** A segment in a naming pattern */
|
|
21
|
+
interface PatternSegment {
|
|
22
|
+
/** Unique ID for React keys and drag-drop operations */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Type of segment */
|
|
25
|
+
type: 'variable' | 'literal';
|
|
26
|
+
/** Variable name (for type='variable') or literal text (for type='literal') */
|
|
27
|
+
value: string;
|
|
28
|
+
}
|
|
29
|
+
/** Complete naming rule schema */
|
|
30
|
+
interface NamingRuleSchema {
|
|
31
|
+
/** Schema version for future compatibility */
|
|
32
|
+
version: number;
|
|
33
|
+
/** Pattern segments for file names */
|
|
34
|
+
filePattern: PatternSegment[];
|
|
35
|
+
/** Pattern segments for folder names (can include / for nested paths) */
|
|
36
|
+
folderPattern: PatternSegment[];
|
|
37
|
+
/** Optional metadata */
|
|
38
|
+
metadata?: {
|
|
39
|
+
/** Optional name for the rule */
|
|
40
|
+
name?: string;
|
|
41
|
+
/** Optional description */
|
|
42
|
+
description?: string;
|
|
43
|
+
/** ISO date string when created */
|
|
44
|
+
createdAt?: string;
|
|
45
|
+
/** ISO date string when last updated */
|
|
46
|
+
updatedAt?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Result of name generation */
|
|
50
|
+
interface GeneratedNameResult {
|
|
51
|
+
/** Whether generation was successful */
|
|
52
|
+
success: boolean;
|
|
53
|
+
/** Generated name (if successful) */
|
|
54
|
+
name?: string;
|
|
55
|
+
/** Error message (if failed) */
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Options for name generation functions */
|
|
59
|
+
interface NameGenerationOptions {
|
|
60
|
+
/** Custom date formats to use (overrides defaults) */
|
|
61
|
+
dateFormats?: string[];
|
|
62
|
+
/** Date to use for date variables (defaults to current date) */
|
|
63
|
+
date?: Date;
|
|
64
|
+
/** Whether to preserve original file extension (default: true) */
|
|
65
|
+
preserveExtension?: boolean;
|
|
66
|
+
/** Counter value for {counter} variable */
|
|
67
|
+
counterValue?: number;
|
|
68
|
+
/** Number of digits for counter padding (default: 3) */
|
|
69
|
+
counterDigits?: number;
|
|
70
|
+
}
|
|
71
|
+
/** History entry for undo/redo in the configurator */
|
|
72
|
+
interface NamingRuleHistoryEntry {
|
|
73
|
+
/** File pattern at this point */
|
|
74
|
+
filePattern: PatternSegment[];
|
|
75
|
+
/** Folder pattern at this point */
|
|
76
|
+
folderPattern: PatternSegment[];
|
|
77
|
+
/** Timestamp of the change */
|
|
78
|
+
timestamp: number;
|
|
79
|
+
}
|
|
80
|
+
/** Props for the NamingRuleConfigurator component */
|
|
81
|
+
interface NamingRuleConfiguratorProps {
|
|
82
|
+
/** User-defined variables to include */
|
|
83
|
+
variables: NamingVariable[];
|
|
84
|
+
/** Initial schema to load (for editing existing rules) */
|
|
85
|
+
initialSchema?: NamingRuleSchema;
|
|
86
|
+
/** Callback when schema changes */
|
|
87
|
+
onChange?: (schema: NamingRuleSchema) => void;
|
|
88
|
+
/** Callback when user exports the schema */
|
|
89
|
+
onExport?: (schema: NamingRuleSchema) => void;
|
|
90
|
+
/** Callback when user imports a schema */
|
|
91
|
+
onImport?: (schema: NamingRuleSchema) => void;
|
|
92
|
+
/** Additional CSS class name */
|
|
93
|
+
className?: string;
|
|
94
|
+
/** Custom date formats (overrides config defaults) */
|
|
95
|
+
customDateFormats?: string[];
|
|
96
|
+
/** Read-only mode - disables editing */
|
|
97
|
+
readOnly?: boolean;
|
|
98
|
+
/** Original file name for preview (to show extension preservation) */
|
|
99
|
+
sampleFileName?: string;
|
|
100
|
+
}
|
|
101
|
+
/** State returned by useNamingRule hook */
|
|
102
|
+
interface UseNamingRuleState {
|
|
103
|
+
/** Current file pattern */
|
|
104
|
+
filePattern: PatternSegment[];
|
|
105
|
+
/** Current folder pattern */
|
|
106
|
+
folderPattern: PatternSegment[];
|
|
107
|
+
/** Whether undo is available */
|
|
108
|
+
canUndo: boolean;
|
|
109
|
+
/** Whether redo is available */
|
|
110
|
+
canRedo: boolean;
|
|
111
|
+
/** Whether patterns have been modified from initial state */
|
|
112
|
+
isDirty: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** Actions returned by useNamingRule hook */
|
|
115
|
+
interface UseNamingRuleActions {
|
|
116
|
+
addToFilePattern: (segment: PatternSegment, index?: number) => void;
|
|
117
|
+
removeFromFilePattern: (id: string) => void;
|
|
118
|
+
updateFilePatternSegment: (id: string, value: string) => void;
|
|
119
|
+
reorderFilePattern: (fromIndex: number, toIndex: number) => void;
|
|
120
|
+
clearFilePattern: () => void;
|
|
121
|
+
addToFolderPattern: (segment: PatternSegment, index?: number) => void;
|
|
122
|
+
removeFromFolderPattern: (id: string) => void;
|
|
123
|
+
updateFolderPatternSegment: (id: string, value: string) => void;
|
|
124
|
+
reorderFolderPattern: (fromIndex: number, toIndex: number) => void;
|
|
125
|
+
clearFolderPattern: () => void;
|
|
126
|
+
undo: () => void;
|
|
127
|
+
redo: () => void;
|
|
128
|
+
getSchema: () => NamingRuleSchema;
|
|
129
|
+
loadSchema: (schema: NamingRuleSchema) => void;
|
|
130
|
+
reset: () => void;
|
|
131
|
+
}
|
|
132
|
+
/** Return type of useNamingRule hook */
|
|
133
|
+
interface UseNamingRuleReturn extends UseNamingRuleState, UseNamingRuleActions {
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Core types for the hazo_files package
|
|
138
|
+
*/
|
|
139
|
+
/** Supported storage provider types */
|
|
140
|
+
type StorageProvider = 'local' | 'google_drive';
|
|
141
|
+
/** File item representing a file in storage */
|
|
142
|
+
interface FileItem {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
path: string;
|
|
146
|
+
size: number;
|
|
147
|
+
mimeType: string;
|
|
148
|
+
createdAt: Date;
|
|
149
|
+
modifiedAt: Date;
|
|
150
|
+
isDirectory: false;
|
|
151
|
+
parentId?: string;
|
|
152
|
+
metadata?: Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
/** Folder item representing a directory in storage */
|
|
155
|
+
interface FolderItem {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
path: string;
|
|
159
|
+
createdAt: Date;
|
|
160
|
+
modifiedAt: Date;
|
|
161
|
+
isDirectory: true;
|
|
162
|
+
parentId?: string;
|
|
163
|
+
children?: (FileItem | FolderItem)[];
|
|
164
|
+
metadata?: Record<string, unknown>;
|
|
165
|
+
}
|
|
166
|
+
/** Union type for file system items */
|
|
167
|
+
type FileSystemItem = FileItem | FolderItem;
|
|
168
|
+
/** Configuration for the file manager */
|
|
169
|
+
interface HazoFilesConfig {
|
|
170
|
+
provider: StorageProvider;
|
|
171
|
+
local?: LocalStorageConfig;
|
|
172
|
+
google_drive?: GoogleDriveConfig;
|
|
173
|
+
}
|
|
174
|
+
/** Local storage specific configuration */
|
|
175
|
+
interface LocalStorageConfig {
|
|
176
|
+
basePath: string;
|
|
177
|
+
allowedExtensions?: string[];
|
|
178
|
+
maxFileSize?: number;
|
|
179
|
+
}
|
|
180
|
+
/** Google Drive specific configuration */
|
|
181
|
+
interface GoogleDriveConfig {
|
|
182
|
+
clientId: string;
|
|
183
|
+
clientSecret: string;
|
|
184
|
+
redirectUri: string;
|
|
185
|
+
refreshToken?: string;
|
|
186
|
+
accessToken?: string;
|
|
187
|
+
rootFolderId?: string;
|
|
188
|
+
}
|
|
189
|
+
/** Result of file operations */
|
|
190
|
+
interface OperationResult<T = void> {
|
|
191
|
+
success: boolean;
|
|
192
|
+
data?: T;
|
|
193
|
+
error?: string;
|
|
194
|
+
}
|
|
195
|
+
/** Progress callback for upload/download operations */
|
|
196
|
+
type ProgressCallback = (progress: number, bytesTransferred: number, totalBytes: number) => void;
|
|
197
|
+
/** Options for upload operations */
|
|
198
|
+
interface UploadOptions {
|
|
199
|
+
overwrite?: boolean;
|
|
200
|
+
onProgress?: ProgressCallback;
|
|
201
|
+
metadata?: Record<string, unknown>;
|
|
202
|
+
}
|
|
203
|
+
/** Options for download operations */
|
|
204
|
+
interface DownloadOptions {
|
|
205
|
+
onProgress?: ProgressCallback;
|
|
206
|
+
}
|
|
207
|
+
/** Options for list operations */
|
|
208
|
+
interface ListOptions {
|
|
209
|
+
recursive?: boolean;
|
|
210
|
+
includeHidden?: boolean;
|
|
211
|
+
filter?: (item: FileSystemItem) => boolean;
|
|
212
|
+
}
|
|
213
|
+
/** Options for move operations */
|
|
214
|
+
interface MoveOptions {
|
|
215
|
+
overwrite?: boolean;
|
|
216
|
+
}
|
|
217
|
+
/** Options for rename operations */
|
|
218
|
+
interface RenameOptions {
|
|
219
|
+
overwrite?: boolean;
|
|
220
|
+
}
|
|
221
|
+
/** Tree node for folder tree representation */
|
|
222
|
+
interface TreeNode {
|
|
223
|
+
id: string;
|
|
224
|
+
name: string;
|
|
225
|
+
path: string;
|
|
226
|
+
children: TreeNode[];
|
|
227
|
+
isExpanded?: boolean;
|
|
228
|
+
isLoading?: boolean;
|
|
229
|
+
}
|
|
230
|
+
/** UI State for the file browser */
|
|
231
|
+
interface FileBrowserState {
|
|
232
|
+
currentPath: string;
|
|
233
|
+
selectedItem: FileSystemItem | null;
|
|
234
|
+
tree: TreeNode[];
|
|
235
|
+
files: FileSystemItem[];
|
|
236
|
+
isLoading: boolean;
|
|
237
|
+
error: string | null;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Interface that all storage modules must implement
|
|
241
|
+
*/
|
|
242
|
+
interface StorageModule {
|
|
243
|
+
/** Provider identifier */
|
|
244
|
+
readonly provider: StorageProvider;
|
|
245
|
+
/** Initialize the module with configuration */
|
|
246
|
+
initialize(config: HazoFilesConfig): Promise<void>;
|
|
247
|
+
/** Create a directory */
|
|
248
|
+
createDirectory(path: string): Promise<OperationResult<FolderItem>>;
|
|
249
|
+
/** Remove a directory */
|
|
250
|
+
removeDirectory(path: string, recursive?: boolean): Promise<OperationResult>;
|
|
251
|
+
/** Upload/save a file */
|
|
252
|
+
uploadFile(localPath: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
253
|
+
/** Download a file */
|
|
254
|
+
downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
|
|
255
|
+
/** Move a file or folder */
|
|
256
|
+
moveItem(sourcePath: string, destinationPath: string, options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
|
|
257
|
+
/** Delete a file */
|
|
258
|
+
deleteFile(path: string): Promise<OperationResult>;
|
|
259
|
+
/** Rename a file */
|
|
260
|
+
renameFile(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FileItem>>;
|
|
261
|
+
/** Rename a folder */
|
|
262
|
+
renameFolder(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FolderItem>>;
|
|
263
|
+
/** List contents of a directory */
|
|
264
|
+
listDirectory(path: string, options?: ListOptions): Promise<OperationResult<FileSystemItem[]>>;
|
|
265
|
+
/** Get item info */
|
|
266
|
+
getItem(path: string): Promise<OperationResult<FileSystemItem>>;
|
|
267
|
+
/** Check if item exists */
|
|
268
|
+
exists(path: string): Promise<boolean>;
|
|
269
|
+
/** Get folder tree structure */
|
|
270
|
+
getFolderTree(path?: string, depth?: number): Promise<OperationResult<TreeNode[]>>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* File Manager Service
|
|
275
|
+
* Main service that provides a unified API for file operations
|
|
276
|
+
* Delegates to the appropriate storage module based on configuration
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
interface FileManagerOptions {
|
|
280
|
+
/** Path to configuration file */
|
|
281
|
+
configPath?: string;
|
|
282
|
+
/** Configuration object (takes precedence over configPath) */
|
|
283
|
+
config?: HazoFilesConfig;
|
|
284
|
+
/** Auto-initialize on creation */
|
|
285
|
+
autoInit?: boolean;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* FileManager - Main service class for file operations
|
|
289
|
+
*/
|
|
290
|
+
declare class FileManager {
|
|
291
|
+
private module;
|
|
292
|
+
private config;
|
|
293
|
+
private initialized;
|
|
294
|
+
private options;
|
|
295
|
+
constructor(options?: FileManagerOptions);
|
|
296
|
+
/**
|
|
297
|
+
* Initialize the file manager with configuration
|
|
298
|
+
*/
|
|
299
|
+
initialize(config?: HazoFilesConfig): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Initialize synchronously (uses sync config loading)
|
|
302
|
+
*/
|
|
303
|
+
initializeSync(config?: HazoFilesConfig): void;
|
|
304
|
+
/**
|
|
305
|
+
* Check if manager is initialized
|
|
306
|
+
*/
|
|
307
|
+
isInitialized(): boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Get the current configuration
|
|
310
|
+
*/
|
|
311
|
+
getConfig(): HazoFilesConfig | null;
|
|
312
|
+
/**
|
|
313
|
+
* Get the current provider
|
|
314
|
+
*/
|
|
315
|
+
getProvider(): StorageProvider | null;
|
|
316
|
+
/**
|
|
317
|
+
* Get the underlying storage module
|
|
318
|
+
*/
|
|
319
|
+
getModule(): StorageModule;
|
|
320
|
+
/**
|
|
321
|
+
* Ensure manager is initialized
|
|
322
|
+
*/
|
|
323
|
+
private ensureInitialized;
|
|
324
|
+
/**
|
|
325
|
+
* Create a directory at the specified path
|
|
326
|
+
*/
|
|
327
|
+
createDirectory(path: string): Promise<OperationResult<FolderItem>>;
|
|
328
|
+
/**
|
|
329
|
+
* Remove a directory
|
|
330
|
+
* @param path - Directory path
|
|
331
|
+
* @param recursive - If true, remove directory and all contents
|
|
332
|
+
*/
|
|
333
|
+
removeDirectory(path: string, recursive?: boolean): Promise<OperationResult>;
|
|
334
|
+
/**
|
|
335
|
+
* Upload/save a file
|
|
336
|
+
* @param source - File path, Buffer, or ReadableStream
|
|
337
|
+
* @param remotePath - Destination path in storage
|
|
338
|
+
* @param options - Upload options
|
|
339
|
+
*/
|
|
340
|
+
uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
341
|
+
/**
|
|
342
|
+
* Download a file
|
|
343
|
+
* @param remotePath - Path in storage
|
|
344
|
+
* @param localPath - Optional local destination path
|
|
345
|
+
* @param options - Download options
|
|
346
|
+
*/
|
|
347
|
+
downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
|
|
348
|
+
/**
|
|
349
|
+
* Move a file or folder
|
|
350
|
+
* @param sourcePath - Current path
|
|
351
|
+
* @param destinationPath - New path
|
|
352
|
+
* @param options - Move options
|
|
353
|
+
*/
|
|
354
|
+
moveItem(sourcePath: string, destinationPath: string, options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
|
|
355
|
+
/**
|
|
356
|
+
* Delete a file
|
|
357
|
+
*/
|
|
358
|
+
deleteFile(path: string): Promise<OperationResult>;
|
|
359
|
+
/**
|
|
360
|
+
* Rename a file
|
|
361
|
+
* @param path - Current file path
|
|
362
|
+
* @param newName - New filename (not full path)
|
|
363
|
+
* @param options - Rename options
|
|
364
|
+
*/
|
|
365
|
+
renameFile(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FileItem>>;
|
|
366
|
+
/**
|
|
367
|
+
* Rename a folder
|
|
368
|
+
* @param path - Current folder path
|
|
369
|
+
* @param newName - New folder name (not full path)
|
|
370
|
+
* @param options - Rename options
|
|
371
|
+
*/
|
|
372
|
+
renameFolder(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FolderItem>>;
|
|
373
|
+
/**
|
|
374
|
+
* List contents of a directory
|
|
375
|
+
* @param path - Directory path
|
|
376
|
+
* @param options - List options
|
|
377
|
+
*/
|
|
378
|
+
listDirectory(path: string, options?: ListOptions): Promise<OperationResult<FileSystemItem[]>>;
|
|
379
|
+
/**
|
|
380
|
+
* Get information about a file or folder
|
|
381
|
+
*/
|
|
382
|
+
getItem(path: string): Promise<OperationResult<FileSystemItem>>;
|
|
383
|
+
/**
|
|
384
|
+
* Check if a file or folder exists
|
|
385
|
+
*/
|
|
386
|
+
exists(path: string): Promise<boolean>;
|
|
387
|
+
/**
|
|
388
|
+
* Get folder tree structure
|
|
389
|
+
* @param path - Starting path (default: root)
|
|
390
|
+
* @param depth - Maximum depth to traverse
|
|
391
|
+
*/
|
|
392
|
+
getFolderTree(path?: string, depth?: number): Promise<OperationResult<TreeNode[]>>;
|
|
393
|
+
/**
|
|
394
|
+
* Create a file with string content
|
|
395
|
+
*/
|
|
396
|
+
writeFile(path: string, content: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
397
|
+
/**
|
|
398
|
+
* Read a file as string
|
|
399
|
+
*/
|
|
400
|
+
readFile(path: string): Promise<OperationResult<string>>;
|
|
401
|
+
/**
|
|
402
|
+
* Copy a file to a new location
|
|
403
|
+
*/
|
|
404
|
+
copyFile(sourcePath: string, destinationPath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
405
|
+
/**
|
|
406
|
+
* Ensure a directory exists (creates if needed)
|
|
407
|
+
*/
|
|
408
|
+
ensureDirectory(path: string): Promise<OperationResult<FolderItem>>;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Create a new FileManager instance
|
|
412
|
+
*/
|
|
413
|
+
declare function createFileManager(options?: FileManagerOptions): FileManager;
|
|
414
|
+
/**
|
|
415
|
+
* Create and initialize a FileManager instance
|
|
416
|
+
*/
|
|
417
|
+
declare function createInitializedFileManager(options?: FileManagerOptions): Promise<FileManager>;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Configuration loader for hazo_files
|
|
421
|
+
* Reads configuration from hazo_files_config.ini file
|
|
422
|
+
*/
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Parse INI configuration file and return typed config object
|
|
426
|
+
*/
|
|
427
|
+
declare function parseConfig(configContent: string): HazoFilesConfig;
|
|
428
|
+
/**
|
|
429
|
+
* Load configuration from file
|
|
430
|
+
* @param configPath - Path to the config file, defaults to hazo_files_config.ini in current directory
|
|
431
|
+
*/
|
|
432
|
+
declare function loadConfig(configPath?: string): HazoFilesConfig;
|
|
433
|
+
/**
|
|
434
|
+
* Load configuration asynchronously
|
|
435
|
+
*/
|
|
436
|
+
declare function loadConfigAsync(configPath?: string): Promise<HazoFilesConfig>;
|
|
437
|
+
/**
|
|
438
|
+
* Generate a sample configuration file content
|
|
439
|
+
*/
|
|
440
|
+
declare function generateSampleConfig(): string;
|
|
441
|
+
/**
|
|
442
|
+
* Save configuration to file
|
|
443
|
+
*/
|
|
444
|
+
declare function saveConfig(config: HazoFilesConfig, configPath?: string): Promise<void>;
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Common utility functions
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Create a successful operation result
|
|
452
|
+
*/
|
|
453
|
+
declare function successResult<T>(data?: T): OperationResult<T>;
|
|
454
|
+
/**
|
|
455
|
+
* Create a failed operation result
|
|
456
|
+
*/
|
|
457
|
+
declare function errorResult<T = void>(error: string): OperationResult<T>;
|
|
458
|
+
/**
|
|
459
|
+
* Generate a unique ID
|
|
460
|
+
*/
|
|
461
|
+
declare function generateId(): string;
|
|
462
|
+
/**
|
|
463
|
+
* Format bytes to human readable string
|
|
464
|
+
*/
|
|
465
|
+
declare function formatBytes(bytes: number, decimals?: number): string;
|
|
466
|
+
/**
|
|
467
|
+
* Check if item is a file
|
|
468
|
+
*/
|
|
469
|
+
declare function isFile(item: FileSystemItem): item is FileItem;
|
|
470
|
+
/**
|
|
471
|
+
* Check if item is a folder
|
|
472
|
+
*/
|
|
473
|
+
declare function isFolder(item: FileSystemItem): item is FolderItem;
|
|
474
|
+
/**
|
|
475
|
+
* Sort file system items (folders first, then alphabetically)
|
|
476
|
+
*/
|
|
477
|
+
declare function sortItems(items: FileSystemItem[]): FileSystemItem[];
|
|
478
|
+
/**
|
|
479
|
+
* Filter items by search term
|
|
480
|
+
*/
|
|
481
|
+
declare function filterItems(items: FileSystemItem[], searchTerm: string): FileSystemItem[];
|
|
482
|
+
/**
|
|
483
|
+
* Create a FileItem object
|
|
484
|
+
*/
|
|
485
|
+
declare function createFileItem(params: {
|
|
486
|
+
id: string;
|
|
487
|
+
name: string;
|
|
488
|
+
path: string;
|
|
489
|
+
size: number;
|
|
490
|
+
mimeType: string;
|
|
491
|
+
createdAt?: Date;
|
|
492
|
+
modifiedAt?: Date;
|
|
493
|
+
parentId?: string;
|
|
494
|
+
metadata?: Record<string, unknown>;
|
|
495
|
+
}): FileItem;
|
|
496
|
+
/**
|
|
497
|
+
* Create a FolderItem object
|
|
498
|
+
*/
|
|
499
|
+
declare function createFolderItem(params: {
|
|
500
|
+
id: string;
|
|
501
|
+
name: string;
|
|
502
|
+
path: string;
|
|
503
|
+
createdAt?: Date;
|
|
504
|
+
modifiedAt?: Date;
|
|
505
|
+
parentId?: string;
|
|
506
|
+
children?: (FileItem | FolderItem)[];
|
|
507
|
+
metadata?: Record<string, unknown>;
|
|
508
|
+
}): FolderItem;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Path manipulation utilities
|
|
512
|
+
*/
|
|
513
|
+
/**
|
|
514
|
+
* Normalize a path (handle separators, remove trailing slashes, resolve . and ..)
|
|
515
|
+
*/
|
|
516
|
+
declare function normalizePath(inputPath: string): string;
|
|
517
|
+
/**
|
|
518
|
+
* Join path segments
|
|
519
|
+
*/
|
|
520
|
+
declare function joinPath(...segments: string[]): string;
|
|
521
|
+
/**
|
|
522
|
+
* Get the parent directory of a path
|
|
523
|
+
*/
|
|
524
|
+
declare function getParentPath(inputPath: string): string;
|
|
525
|
+
/**
|
|
526
|
+
* Get the base name (file/folder name) from a path
|
|
527
|
+
*/
|
|
528
|
+
declare function getBaseName(inputPath: string): string;
|
|
529
|
+
/**
|
|
530
|
+
* Get the directory name from a path (alias for getParentPath)
|
|
531
|
+
*/
|
|
532
|
+
declare function getDirName(inputPath: string): string;
|
|
533
|
+
/**
|
|
534
|
+
* Get path segments as array
|
|
535
|
+
*/
|
|
536
|
+
declare function getPathSegments(inputPath: string): string[];
|
|
537
|
+
/**
|
|
538
|
+
* Check if a path is a child of another path
|
|
539
|
+
*/
|
|
540
|
+
declare function isChildPath(parentPath: string, childPath: string): boolean;
|
|
541
|
+
/**
|
|
542
|
+
* Get relative path from base to target
|
|
543
|
+
*/
|
|
544
|
+
declare function getRelativePath(basePath: string, targetPath: string): string;
|
|
545
|
+
/**
|
|
546
|
+
* Validate a path for security issues
|
|
547
|
+
*/
|
|
548
|
+
declare function validatePath(inputPath: string, basePath?: string): void;
|
|
549
|
+
/**
|
|
550
|
+
* Create a safe filename by removing/replacing invalid characters
|
|
551
|
+
*/
|
|
552
|
+
declare function sanitizeFilename(filename: string): string;
|
|
553
|
+
/**
|
|
554
|
+
* Get file extension
|
|
555
|
+
*/
|
|
556
|
+
declare function getExtension(filename: string): string;
|
|
557
|
+
/**
|
|
558
|
+
* Get filename without extension
|
|
559
|
+
*/
|
|
560
|
+
declare function getNameWithoutExtension(filename: string): string;
|
|
561
|
+
/**
|
|
562
|
+
* Check if filename has specific extension
|
|
563
|
+
*/
|
|
564
|
+
declare function hasExtension(filename: string, extension: string): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Get breadcrumb segments for a path
|
|
567
|
+
*/
|
|
568
|
+
declare function getBreadcrumbs(inputPath: string): Array<{
|
|
569
|
+
name: string;
|
|
570
|
+
path: string;
|
|
571
|
+
}>;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Base module class providing common functionality for all storage modules.
|
|
575
|
+
* All storage module implementations should extend this class.
|
|
576
|
+
*/
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Abstract base class for storage modules.
|
|
580
|
+
* Provides common functionality and enforces the StorageModule interface.
|
|
581
|
+
*/
|
|
582
|
+
declare abstract class BaseStorageModule implements StorageModule {
|
|
583
|
+
abstract readonly provider: StorageProvider;
|
|
584
|
+
protected config: HazoFilesConfig | null;
|
|
585
|
+
protected _initialized: boolean;
|
|
586
|
+
/**
|
|
587
|
+
* Check if the module is initialized
|
|
588
|
+
*/
|
|
589
|
+
get isInitialized(): boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Initialize the module with configuration.
|
|
592
|
+
* Subclasses should call super.initialize(config) first.
|
|
593
|
+
*/
|
|
594
|
+
initialize(config: HazoFilesConfig): Promise<void>;
|
|
595
|
+
/**
|
|
596
|
+
* Ensure the module is initialized before operations
|
|
597
|
+
*/
|
|
598
|
+
protected ensureInitialized(): void;
|
|
599
|
+
/**
|
|
600
|
+
* Get the provider-specific configuration
|
|
601
|
+
*/
|
|
602
|
+
protected getProviderConfig<T>(): T;
|
|
603
|
+
abstract createDirectory(path: string): Promise<OperationResult<FolderItem>>;
|
|
604
|
+
abstract removeDirectory(path: string, recursive?: boolean): Promise<OperationResult>;
|
|
605
|
+
abstract uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
606
|
+
abstract downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
|
|
607
|
+
abstract moveItem(sourcePath: string, destinationPath: string, options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
|
|
608
|
+
abstract deleteFile(path: string): Promise<OperationResult>;
|
|
609
|
+
abstract renameFile(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FileItem>>;
|
|
610
|
+
abstract renameFolder(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FolderItem>>;
|
|
611
|
+
abstract listDirectory(path: string, options?: ListOptions): Promise<OperationResult<FileSystemItem[]>>;
|
|
612
|
+
abstract getItem(path: string): Promise<OperationResult<FileSystemItem>>;
|
|
613
|
+
abstract exists(path: string): Promise<boolean>;
|
|
614
|
+
/**
|
|
615
|
+
* Get folder tree structure.
|
|
616
|
+
* Default implementation that can be overridden by subclasses for optimization.
|
|
617
|
+
*/
|
|
618
|
+
getFolderTree(path?: string, depth?: number): Promise<OperationResult<TreeNode[]>>;
|
|
619
|
+
/**
|
|
620
|
+
* Recursively build folder tree
|
|
621
|
+
*/
|
|
622
|
+
protected buildTree(path: string, maxDepth: number, currentDepth: number): Promise<TreeNode[]>;
|
|
623
|
+
protected normalizePath: typeof normalizePath;
|
|
624
|
+
protected joinPath: typeof joinPath;
|
|
625
|
+
protected getBaseName: typeof getBaseName;
|
|
626
|
+
protected getParentPath: typeof getParentPath;
|
|
627
|
+
protected successResult: typeof successResult;
|
|
628
|
+
protected errorResult: typeof errorResult;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Local File System Storage Module
|
|
633
|
+
* Implements file operations using Node.js fs module
|
|
634
|
+
*/
|
|
635
|
+
|
|
636
|
+
declare class LocalStorageModule extends BaseStorageModule {
|
|
637
|
+
readonly provider: StorageProvider;
|
|
638
|
+
private basePath;
|
|
639
|
+
private allowedExtensions;
|
|
640
|
+
private maxFileSize;
|
|
641
|
+
initialize(config: HazoFilesConfig): Promise<void>;
|
|
642
|
+
/**
|
|
643
|
+
* Resolve a virtual path to an absolute file system path
|
|
644
|
+
*/
|
|
645
|
+
private resolveFullPath;
|
|
646
|
+
/**
|
|
647
|
+
* Convert absolute path back to virtual path
|
|
648
|
+
*/
|
|
649
|
+
private toVirtualPath;
|
|
650
|
+
/**
|
|
651
|
+
* Validate file extension against allowed list
|
|
652
|
+
*/
|
|
653
|
+
private validateExtension;
|
|
654
|
+
/**
|
|
655
|
+
* Validate file size against maximum
|
|
656
|
+
*/
|
|
657
|
+
private validateFileSize;
|
|
658
|
+
/**
|
|
659
|
+
* Create file/folder stats to FileSystemItem
|
|
660
|
+
*/
|
|
661
|
+
private statToItem;
|
|
662
|
+
createDirectory(virtualPath: string): Promise<OperationResult<FolderItem>>;
|
|
663
|
+
removeDirectory(virtualPath: string, recursive?: boolean): Promise<OperationResult>;
|
|
664
|
+
uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
665
|
+
downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
|
|
666
|
+
moveItem(sourcePath: string, destinationPath: string, options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
|
|
667
|
+
deleteFile(virtualPath: string): Promise<OperationResult>;
|
|
668
|
+
renameFile(virtualPath: string, newName: string, options?: RenameOptions): Promise<OperationResult<FileItem>>;
|
|
669
|
+
renameFolder(virtualPath: string, newName: string, options?: RenameOptions): Promise<OperationResult<FolderItem>>;
|
|
670
|
+
listDirectory(virtualPath: string, options?: ListOptions): Promise<OperationResult<FileSystemItem[]>>;
|
|
671
|
+
getItem(virtualPath: string): Promise<OperationResult<FileSystemItem>>;
|
|
672
|
+
exists(virtualPath: string): Promise<boolean>;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Factory function to create a LocalStorageModule instance
|
|
676
|
+
*/
|
|
677
|
+
declare function createLocalModule(): LocalStorageModule;
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Google Drive OAuth Authentication Handler
|
|
681
|
+
* Manages OAuth flow, token storage, and token refresh
|
|
682
|
+
*/
|
|
683
|
+
|
|
684
|
+
interface GoogleAuthConfig {
|
|
685
|
+
clientId: string;
|
|
686
|
+
clientSecret: string;
|
|
687
|
+
redirectUri: string;
|
|
688
|
+
}
|
|
689
|
+
interface TokenData {
|
|
690
|
+
accessToken: string;
|
|
691
|
+
refreshToken: string;
|
|
692
|
+
expiryDate?: number;
|
|
693
|
+
scope?: string;
|
|
694
|
+
}
|
|
695
|
+
interface AuthCallbacks {
|
|
696
|
+
onTokensUpdated?: (tokens: TokenData) => Promise<void>;
|
|
697
|
+
getStoredTokens?: () => Promise<TokenData | null>;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Google Drive Authentication Manager
|
|
701
|
+
*/
|
|
702
|
+
declare class GoogleDriveAuth {
|
|
703
|
+
private oauth2Client;
|
|
704
|
+
private callbacks;
|
|
705
|
+
private tokens;
|
|
706
|
+
constructor(config: GoogleAuthConfig, callbacks?: AuthCallbacks);
|
|
707
|
+
/**
|
|
708
|
+
* Get the OAuth2 client instance
|
|
709
|
+
*/
|
|
710
|
+
getClient(): OAuth2Client;
|
|
711
|
+
/**
|
|
712
|
+
* Generate the authorization URL for OAuth consent
|
|
713
|
+
*/
|
|
714
|
+
getAuthUrl(state?: string): string;
|
|
715
|
+
/**
|
|
716
|
+
* Exchange authorization code for tokens
|
|
717
|
+
*/
|
|
718
|
+
exchangeCodeForTokens(code: string): Promise<TokenData>;
|
|
719
|
+
/**
|
|
720
|
+
* Set tokens directly (e.g., from stored tokens)
|
|
721
|
+
*/
|
|
722
|
+
setTokens(tokens: TokenData): Promise<void>;
|
|
723
|
+
/**
|
|
724
|
+
* Load tokens from storage using callback
|
|
725
|
+
*/
|
|
726
|
+
loadStoredTokens(): Promise<boolean>;
|
|
727
|
+
/**
|
|
728
|
+
* Check if authenticated
|
|
729
|
+
*/
|
|
730
|
+
isAuthenticated(): boolean;
|
|
731
|
+
/**
|
|
732
|
+
* Get current tokens
|
|
733
|
+
*/
|
|
734
|
+
getTokens(): TokenData | null;
|
|
735
|
+
/**
|
|
736
|
+
* Refresh the access token
|
|
737
|
+
*/
|
|
738
|
+
refreshAccessToken(): Promise<TokenData>;
|
|
739
|
+
/**
|
|
740
|
+
* Revoke access (disconnect)
|
|
741
|
+
*/
|
|
742
|
+
revokeAccess(): Promise<void>;
|
|
743
|
+
/**
|
|
744
|
+
* Check if token is expired or will expire soon
|
|
745
|
+
*/
|
|
746
|
+
isTokenExpired(bufferSeconds?: number): boolean;
|
|
747
|
+
/**
|
|
748
|
+
* Ensure valid access token (refresh if needed)
|
|
749
|
+
*/
|
|
750
|
+
ensureValidToken(): Promise<void>;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Create a new GoogleDriveAuth instance
|
|
754
|
+
*/
|
|
755
|
+
declare function createGoogleDriveAuth(config: GoogleAuthConfig, callbacks?: AuthCallbacks): GoogleDriveAuth;
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Google Drive Storage Module
|
|
759
|
+
* Implements file operations using Google Drive API
|
|
760
|
+
*/
|
|
761
|
+
|
|
762
|
+
declare class GoogleDriveModule extends BaseStorageModule {
|
|
763
|
+
readonly provider: StorageProvider;
|
|
764
|
+
private auth;
|
|
765
|
+
private drive;
|
|
766
|
+
private rootFolderId;
|
|
767
|
+
private authCallbacks;
|
|
768
|
+
/**
|
|
769
|
+
* Set authentication callbacks for token persistence
|
|
770
|
+
*/
|
|
771
|
+
setAuthCallbacks(callbacks: AuthCallbacks): void;
|
|
772
|
+
initialize(config: HazoFilesConfig): Promise<void>;
|
|
773
|
+
/**
|
|
774
|
+
* Get the auth instance for OAuth flow
|
|
775
|
+
*/
|
|
776
|
+
getAuth(): GoogleDriveAuth;
|
|
777
|
+
/**
|
|
778
|
+
* Check if user is authenticated
|
|
779
|
+
*/
|
|
780
|
+
isAuthenticated(): boolean;
|
|
781
|
+
/**
|
|
782
|
+
* Authenticate with provided tokens
|
|
783
|
+
*/
|
|
784
|
+
authenticate(tokens: TokenData): Promise<void>;
|
|
785
|
+
/**
|
|
786
|
+
* Ensure authenticated before operations
|
|
787
|
+
*/
|
|
788
|
+
private ensureAuthenticated;
|
|
789
|
+
/**
|
|
790
|
+
* Get folder ID from path (creates folders if needed for certain operations)
|
|
791
|
+
*/
|
|
792
|
+
private getIdFromPath;
|
|
793
|
+
/**
|
|
794
|
+
* Convert Drive file to FileSystemItem
|
|
795
|
+
*/
|
|
796
|
+
private driveFileToItem;
|
|
797
|
+
createDirectory(virtualPath: string): Promise<OperationResult<FolderItem>>;
|
|
798
|
+
removeDirectory(virtualPath: string, recursive?: boolean): Promise<OperationResult>;
|
|
799
|
+
uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
800
|
+
downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
|
|
801
|
+
moveItem(sourcePath: string, destinationPath: string, _options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
|
|
802
|
+
deleteFile(virtualPath: string): Promise<OperationResult>;
|
|
803
|
+
renameFile(virtualPath: string, newName: string, _options?: RenameOptions): Promise<OperationResult<FileItem>>;
|
|
804
|
+
renameFolder(virtualPath: string, newName: string, _options?: RenameOptions): Promise<OperationResult<FolderItem>>;
|
|
805
|
+
listDirectory(virtualPath: string, options?: ListOptions): Promise<OperationResult<FileSystemItem[]>>;
|
|
806
|
+
getItem(virtualPath: string): Promise<OperationResult<FileSystemItem>>;
|
|
807
|
+
exists(virtualPath: string): Promise<boolean>;
|
|
808
|
+
getFolderTree(path?: string, depth?: number): Promise<OperationResult<TreeNode[]>>;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Factory function to create a GoogleDriveModule instance
|
|
812
|
+
*/
|
|
813
|
+
declare function createGoogleDriveModule(): GoogleDriveModule;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Module Registry
|
|
817
|
+
* Central registry for all storage modules
|
|
818
|
+
*/
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Factory function type for creating modules
|
|
822
|
+
*/
|
|
823
|
+
type ModuleFactory = () => StorageModule;
|
|
824
|
+
/**
|
|
825
|
+
* Get a list of registered providers
|
|
826
|
+
*/
|
|
827
|
+
declare function getRegisteredProviders(): StorageProvider[];
|
|
828
|
+
/**
|
|
829
|
+
* Check if a provider is registered
|
|
830
|
+
*/
|
|
831
|
+
declare function isProviderRegistered(provider: string): provider is StorageProvider;
|
|
832
|
+
/**
|
|
833
|
+
* Create a storage module instance for the given provider
|
|
834
|
+
*/
|
|
835
|
+
declare function createModule(provider: StorageProvider): StorageModule;
|
|
836
|
+
/**
|
|
837
|
+
* Create and initialize a storage module with configuration
|
|
838
|
+
*/
|
|
839
|
+
declare function createAndInitializeModule(config: HazoFilesConfig): Promise<StorageModule>;
|
|
840
|
+
/**
|
|
841
|
+
* Register a custom module (for extensibility)
|
|
842
|
+
*/
|
|
843
|
+
declare function registerModule(provider: StorageProvider, factory: ModuleFactory): void;
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Custom error classes for hazo_files
|
|
847
|
+
*/
|
|
848
|
+
declare class HazoFilesError extends Error {
|
|
849
|
+
code: string;
|
|
850
|
+
details?: Record<string, unknown> | undefined;
|
|
851
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
|
|
852
|
+
}
|
|
853
|
+
declare class FileNotFoundError extends HazoFilesError {
|
|
854
|
+
constructor(path: string);
|
|
855
|
+
}
|
|
856
|
+
declare class DirectoryNotFoundError extends HazoFilesError {
|
|
857
|
+
constructor(path: string);
|
|
858
|
+
}
|
|
859
|
+
declare class FileExistsError extends HazoFilesError {
|
|
860
|
+
constructor(path: string);
|
|
861
|
+
}
|
|
862
|
+
declare class DirectoryExistsError extends HazoFilesError {
|
|
863
|
+
constructor(path: string);
|
|
864
|
+
}
|
|
865
|
+
declare class DirectoryNotEmptyError extends HazoFilesError {
|
|
866
|
+
constructor(path: string);
|
|
867
|
+
}
|
|
868
|
+
declare class PermissionDeniedError extends HazoFilesError {
|
|
869
|
+
constructor(path: string, operation: string);
|
|
870
|
+
}
|
|
871
|
+
declare class InvalidPathError extends HazoFilesError {
|
|
872
|
+
constructor(path: string, reason: string);
|
|
873
|
+
}
|
|
874
|
+
declare class FileTooLargeError extends HazoFilesError {
|
|
875
|
+
constructor(path: string, size: number, maxSize: number);
|
|
876
|
+
}
|
|
877
|
+
declare class InvalidExtensionError extends HazoFilesError {
|
|
878
|
+
constructor(path: string, extension: string, allowedExtensions: string[]);
|
|
879
|
+
}
|
|
880
|
+
declare class AuthenticationError extends HazoFilesError {
|
|
881
|
+
constructor(provider: string, message: string);
|
|
882
|
+
}
|
|
883
|
+
declare class ConfigurationError extends HazoFilesError {
|
|
884
|
+
constructor(message: string);
|
|
885
|
+
}
|
|
886
|
+
declare class OperationError extends HazoFilesError {
|
|
887
|
+
constructor(operation: string, message: string, details?: Record<string, unknown>);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* MIME type utilities
|
|
892
|
+
*/
|
|
893
|
+
/**
|
|
894
|
+
* Get MIME type from file extension
|
|
895
|
+
*/
|
|
896
|
+
declare function getMimeType(filename: string): string;
|
|
897
|
+
/**
|
|
898
|
+
* Get extension from MIME type
|
|
899
|
+
*/
|
|
900
|
+
declare function getExtensionFromMime(mimeType: string): string;
|
|
901
|
+
/**
|
|
902
|
+
* Check if file is an image
|
|
903
|
+
*/
|
|
904
|
+
declare function isImage(filenameOrMime: string): boolean;
|
|
905
|
+
/**
|
|
906
|
+
* Check if file is a video
|
|
907
|
+
*/
|
|
908
|
+
declare function isVideo(filenameOrMime: string): boolean;
|
|
909
|
+
/**
|
|
910
|
+
* Check if file is audio
|
|
911
|
+
*/
|
|
912
|
+
declare function isAudio(filenameOrMime: string): boolean;
|
|
913
|
+
/**
|
|
914
|
+
* Check if file is a text file
|
|
915
|
+
*/
|
|
916
|
+
declare function isText(filenameOrMime: string): boolean;
|
|
917
|
+
/**
|
|
918
|
+
* Check if file is a document (PDF, Word, Excel, etc.)
|
|
919
|
+
*/
|
|
920
|
+
declare function isDocument(filenameOrMime: string): boolean;
|
|
921
|
+
/**
|
|
922
|
+
* Check if file can be previewed in browser
|
|
923
|
+
*/
|
|
924
|
+
declare function isPreviewable(filenameOrMime: string): boolean;
|
|
925
|
+
/**
|
|
926
|
+
* Get file type category
|
|
927
|
+
*/
|
|
928
|
+
declare function getFileCategory(filenameOrMime: string): 'image' | 'video' | 'audio' | 'document' | 'text' | 'other';
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Naming utilities for hazo_files package
|
|
932
|
+
* Functions for generating file/folder names from naming rule schemas
|
|
933
|
+
*/
|
|
934
|
+
|
|
935
|
+
/** Default date formats supported by the system */
|
|
936
|
+
declare const DEFAULT_DATE_FORMATS: readonly ["YYYY", "YY", "MM", "M", "DD", "D", "MMM", "MMMM", "YYYY-MM-DD", "YYYY-MMM-DD", "DD-MM-YYYY", "MM-DD-YYYY"];
|
|
937
|
+
/** System date variables with descriptions */
|
|
938
|
+
declare const SYSTEM_DATE_VARIABLES: NamingVariable[];
|
|
939
|
+
/** System file metadata variables */
|
|
940
|
+
declare const SYSTEM_FILE_VARIABLES: NamingVariable[];
|
|
941
|
+
/** System counter variables */
|
|
942
|
+
declare const SYSTEM_COUNTER_VARIABLES: NamingVariable[];
|
|
943
|
+
/** All system variables combined */
|
|
944
|
+
declare const ALL_SYSTEM_VARIABLES: NamingVariable[];
|
|
945
|
+
/**
|
|
946
|
+
* Format a date according to the format token
|
|
947
|
+
*/
|
|
948
|
+
declare function formatDateToken(date: Date, format: string): string;
|
|
949
|
+
/**
|
|
950
|
+
* Check if a variable name is a date format
|
|
951
|
+
*/
|
|
952
|
+
declare function isDateVariable(variableName: string, dateFormats?: readonly string[]): boolean;
|
|
953
|
+
/**
|
|
954
|
+
* Check if a variable name is a file metadata variable
|
|
955
|
+
*/
|
|
956
|
+
declare function isFileMetadataVariable(variableName: string): boolean;
|
|
957
|
+
/**
|
|
958
|
+
* Check if a variable name is the counter variable
|
|
959
|
+
*/
|
|
960
|
+
declare function isCounterVariable(variableName: string): boolean;
|
|
961
|
+
/**
|
|
962
|
+
* Format counter value with padding
|
|
963
|
+
*/
|
|
964
|
+
declare function formatCounter(value: number, digits?: number): string;
|
|
965
|
+
/**
|
|
966
|
+
* Get file metadata values from a filename
|
|
967
|
+
*/
|
|
968
|
+
declare function getFileMetadataValues(filename?: string): Record<string, string>;
|
|
969
|
+
/**
|
|
970
|
+
* Generate a folder name using the schema and variable values
|
|
971
|
+
* Supports nested paths with / separators in the pattern
|
|
972
|
+
*/
|
|
973
|
+
declare function hazo_files_generate_folder_name(schema: NamingRuleSchema, variables: Record<string, string>, options?: NameGenerationOptions): GeneratedNameResult;
|
|
974
|
+
/**
|
|
975
|
+
* Generate a file name using the schema and variable values
|
|
976
|
+
* Optionally preserves the original file extension
|
|
977
|
+
*/
|
|
978
|
+
declare function hazo_files_generate_file_name(schema: NamingRuleSchema, variables: Record<string, string>, originalFileName?: string, options?: NameGenerationOptions): GeneratedNameResult;
|
|
979
|
+
/**
|
|
980
|
+
* Validate a naming rule schema
|
|
981
|
+
*/
|
|
982
|
+
declare function validateNamingRuleSchema(schema: unknown): schema is NamingRuleSchema;
|
|
983
|
+
/**
|
|
984
|
+
* Create an empty naming rule schema
|
|
985
|
+
*/
|
|
986
|
+
declare function createEmptyNamingRuleSchema(): NamingRuleSchema;
|
|
987
|
+
/**
|
|
988
|
+
* Generate a unique ID for pattern segments
|
|
989
|
+
*/
|
|
990
|
+
declare function generateSegmentId(): string;
|
|
991
|
+
/**
|
|
992
|
+
* Create a variable segment
|
|
993
|
+
*/
|
|
994
|
+
declare function createVariableSegment(variableName: string): PatternSegment;
|
|
995
|
+
/**
|
|
996
|
+
* Create a literal segment
|
|
997
|
+
*/
|
|
998
|
+
declare function createLiteralSegment(text: string): PatternSegment;
|
|
999
|
+
/**
|
|
1000
|
+
* Convert pattern to human-readable string representation
|
|
1001
|
+
*/
|
|
1002
|
+
declare function patternToString(pattern: PatternSegment[]): string;
|
|
1003
|
+
/**
|
|
1004
|
+
* Parse a pattern string to segments
|
|
1005
|
+
* Handles {variable} syntax for variables, everything else is literal
|
|
1006
|
+
*/
|
|
1007
|
+
declare function parsePatternString(patternStr: string): PatternSegment[];
|
|
1008
|
+
/**
|
|
1009
|
+
* Clone a pattern with new segment IDs
|
|
1010
|
+
*/
|
|
1011
|
+
declare function clonePattern(pattern: PatternSegment[]): PatternSegment[];
|
|
1012
|
+
/**
|
|
1013
|
+
* Get preview values for all system variables
|
|
1014
|
+
* Uses the current date and provided options
|
|
1015
|
+
*/
|
|
1016
|
+
declare function getSystemVariablePreviewValues(date?: Date, options?: {
|
|
1017
|
+
counterValue?: number;
|
|
1018
|
+
counterDigits?: number;
|
|
1019
|
+
originalFileName?: string;
|
|
1020
|
+
}): Record<string, string>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Generate a preview name from a pattern using example values
|
|
1023
|
+
*/
|
|
1024
|
+
declare function generatePreviewName(pattern: PatternSegment[], userVariables: NamingVariable[], options?: {
|
|
1025
|
+
date?: Date;
|
|
1026
|
+
counterValue?: number;
|
|
1027
|
+
counterDigits?: number;
|
|
1028
|
+
originalFileName?: string;
|
|
1029
|
+
}): string;
|
|
1030
|
+
|
|
1031
|
+
export { ALL_SYSTEM_VARIABLES, type AuthCallbacks, AuthenticationError, ConfigurationError, DEFAULT_DATE_FORMATS, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type FileBrowserState, FileExistsError, type FileItem, FileManager, type FileManagerOptions, FileNotFoundError, type FileSystemItem, FileTooLargeError, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type HazoFilesConfig, HazoFilesError, InvalidExtensionError, InvalidPathError, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MoveOptions, type NameGenerationOptions, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, type TreeNode, type UploadOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, clonePattern, createAndInitializeModule, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createLiteralSegment, createLocalModule, createModule, createVariableSegment, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateId, generatePreviewName, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getFileCategory, getFileMetadataValues, getMimeType, getNameWithoutExtension, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSystemVariablePreviewValues, hasExtension, hazo_files_generate_file_name, hazo_files_generate_folder_name, isAudio, isChildPath, isCounterVariable, isDateVariable, isDocument, isFile, isFileMetadataVariable, isFolder, isImage, isPreviewable, isProviderRegistered, isText, isVideo, joinPath, loadConfig, loadConfigAsync, normalizePath, parseConfig, parsePatternString, patternToString, registerModule, sanitizeFilename, saveConfig, sortItems, successResult, validateNamingRuleSchema, validatePath };
|