@b9g/filesystem 0.1.4 → 0.1.5

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 CHANGED
@@ -244,45 +244,58 @@ router.post('/upload', async (request) => {
244
244
  });
245
245
  ```
246
246
 
247
+ ## Exports
248
+
249
+ ### Classes
250
+
251
+ - `ShovelFileHandle` - FileSystemFileHandle implementation
252
+ - `ShovelDirectoryHandle` - FileSystemDirectoryHandle implementation
253
+ - `ShovelHandle` - Base handle class
254
+ - `CustomBucketStorage` - Bucket storage with custom backend factories
255
+
256
+ ### Types
257
+
258
+ - `Bucket` - Alias for FileSystemDirectoryHandle
259
+ - `BucketStorage` - Interface for bucket storage (`open(name): Promise<FileSystemDirectoryHandle>`)
260
+ - `BucketFactory` - Factory function type for creating bucket backends
261
+ - `FileSystemConfig` - Configuration for filesystem backends
262
+ - `FileSystemPermissionDescriptor` - Permission descriptor type
263
+ - `FileSystemBackend` - Backend interface for filesystem implementations
264
+
247
265
  ## API Reference
248
266
 
249
- ### FilesystemRegistry
267
+ ### BucketStorage
250
268
 
251
269
  ```typescript
252
- class FilesystemRegistry {
253
- register(name: string, factory: () => Filesystem): void;
254
- get(name: string): Promise<Filesystem>;
255
- has(name: string): boolean;
256
- delete(name: string): boolean;
257
- keys(): string[];
270
+ interface BucketStorage {
271
+ open(name: string): Promise<FileSystemDirectoryHandle>;
272
+ }
273
+
274
+ class CustomBucketStorage implements BucketStorage {
275
+ register(name: string, factory: BucketFactory): void;
276
+ open(name: string): Promise<FileSystemDirectoryHandle>;
258
277
  }
259
278
  ```
260
279
 
261
- ### Filesystem Interface
280
+ ### FileSystemHandle Interface
262
281
 
263
282
  ```typescript
264
- interface Filesystem {
265
- getDirectoryHandle(name: string, options?: GetDirectoryOptions): Promise<DirectoryHandle>;
266
- }
267
-
268
- interface DirectoryHandle {
283
+ interface FileSystemDirectoryHandle {
269
284
  kind: 'directory';
270
285
  name: string;
271
-
272
- getDirectoryHandle(name: string, options?: GetDirectoryOptions): Promise<DirectoryHandle>;
273
- getFileHandle(name: string, options?: GetFileOptions): Promise<FileHandle>;
274
- removeEntry(name: string, options?: RemoveOptions): Promise<void>;
275
- entries(): AsyncIterableIterator<[string, DirectoryHandle | FileHandle]>;
286
+ getDirectoryHandle(name: string, options?: { create?: boolean }): Promise<FileSystemDirectoryHandle>;
287
+ getFileHandle(name: string, options?: { create?: boolean }): Promise<FileSystemFileHandle>;
288
+ removeEntry(name: string, options?: { recursive?: boolean }): Promise<void>;
289
+ entries(): AsyncIterableIterator<[string, FileSystemDirectoryHandle | FileSystemFileHandle]>;
276
290
  keys(): AsyncIterableIterator<string>;
277
- values(): AsyncIterableIterator<DirectoryHandle | FileHandle>;
291
+ values(): AsyncIterableIterator<FileSystemDirectoryHandle | FileSystemFileHandle>;
278
292
  }
279
293
 
280
- interface FileHandle {
294
+ interface FileSystemFileHandle {
281
295
  kind: 'file';
282
296
  name: string;
283
-
284
297
  getFile(): Promise<File>;
285
- createWritable(options?: CreateWritableOptions): Promise<WritableStream>;
298
+ createWritable(): Promise<FileSystemWritableFileStream>;
286
299
  }
287
300
  ```
288
301
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/filesystem",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Universal File System Access API implementations for all platforms",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
@@ -8,7 +8,6 @@
8
8
  "@types/bun": "^1.2.2"
9
9
  },
10
10
  "peerDependencies": {
11
- "@types/wicg-file-system-access": "^2023.10.7",
12
11
  "@types/node": "^18.0.0"
13
12
  },
14
13
  "peerDependenciesMeta": {
@@ -56,30 +55,6 @@
56
55
  "types": "./src/node.d.ts",
57
56
  "import": "./src/node.js"
58
57
  },
59
- "./registry": {
60
- "types": "./src/registry.d.ts",
61
- "import": "./src/registry.js"
62
- },
63
- "./registry.js": {
64
- "types": "./src/registry.d.ts",
65
- "import": "./src/registry.js"
66
- },
67
- "./types": {
68
- "types": "./src/types.d.ts",
69
- "import": "./src/types.js"
70
- },
71
- "./types.js": {
72
- "types": "./src/types.d.ts",
73
- "import": "./src/types.js"
74
- },
75
- "./package.json": "./package.json",
76
- "./directory-storage": {
77
- "types": "./src/directory-storage.d.ts",
78
- "import": "./src/directory-storage.js"
79
- },
80
- "./directory-storage.js": {
81
- "types": "./src/directory-storage.d.ts",
82
- "import": "./src/directory-storage.js"
83
- }
58
+ "./package.json": "./package.json"
84
59
  }
85
60
  }
package/src/bun-s3.d.ts CHANGED
@@ -1,46 +1,51 @@
1
1
  /**
2
- * Bun S3 implementation of File System Access API using built-in S3 support
2
+ * Bun S3 filesystem implementation
3
3
  *
4
- * Leverages Bun's native S3Client and S3File for high-performance
5
- * cloud storage operations with File System Access API compatibility.
4
+ * Provides S3Bucket (root) and S3FileSystemBackend for storage operations
5
+ * using Bun's native S3 client.
6
6
  */
7
- import type { Bucket, FileSystemConfig } from "./types.js";
7
+ import { type FileSystemBackend } from "./index.js";
8
8
  /**
9
- * Bun S3 implementation of FileSystemWritableFileStream
9
+ * S3 storage backend that implements FileSystemBackend using Bun's S3 client
10
10
  */
11
- export declare class BunS3FileSystemWritableFileStream extends WritableStream<Uint8Array> {
12
- private s3file;
13
- private writer;
14
- constructor(s3file: any);
11
+ export declare class S3FileSystemBackend implements FileSystemBackend {
12
+ #private;
13
+ constructor(s3Client: any, bucketName: string, prefix?: string);
14
+ stat(path: string): Promise<{
15
+ kind: "file" | "directory";
16
+ } | null>;
17
+ readFile(path: string): Promise<Uint8Array>;
18
+ writeFile(path: string, data: Uint8Array): Promise<void>;
19
+ listDir(path: string): Promise<Array<{
20
+ name: string;
21
+ kind: "file" | "directory";
22
+ }>>;
23
+ createDir(path: string): Promise<void>;
24
+ remove(path: string, recursive?: boolean): Promise<void>;
15
25
  }
16
26
  /**
17
- * Bun S3 implementation of FileSystemFileHandle
18
- */
19
- export declare class BunS3FileSystemFileHandle implements FileSystemFileHandle {
20
- private s3Client;
21
- private key;
22
- readonly kind: "file";
23
- readonly name: string;
24
- constructor(s3Client: any, // Bun S3Client
25
- key: string);
26
- getFile(): Promise<File>;
27
- createWritable(): Promise<FileSystemWritableFileStream>;
28
- createSyncAccessHandle(): Promise<FileSystemSyncAccessHandle>;
29
- isSameEntry(other: FileSystemHandle): Promise<boolean>;
30
- queryPermission(): Promise<PermissionState>;
31
- requestPermission(): Promise<PermissionState>;
32
- private getMimeType;
33
- }
34
- /**
35
- * Bun S3 implementation of FileSystemDirectoryHandle
27
+ * S3 bucket - root entry point for S3 filesystem using Bun's S3 client
28
+ * Implements FileSystemDirectoryHandle for S3 object storage
29
+ *
30
+ * Example usage with namespacing:
31
+ * ```typescript
32
+ * const s3 = new S3Client({ ... });
33
+ *
34
+ * // Use in CustomBucketStorage factory for multi-tenancy
35
+ * const buckets = new CustomBucketStorage(async (name) => {
36
+ * return new S3Bucket(
37
+ * s3,
38
+ * "my-company-bucket",
39
+ * `my-app/production/${name}` // Prefix for isolation
40
+ * );
41
+ * });
42
+ * ```
36
43
  */
37
- export declare class BunS3FileSystemDirectoryHandle implements FileSystemDirectoryHandle {
38
- private s3Client;
39
- private prefix;
44
+ export declare class S3Bucket implements FileSystemDirectoryHandle {
45
+ #private;
40
46
  readonly kind: "directory";
41
47
  readonly name: string;
42
- constructor(s3Client: any, // Bun S3Client
43
- prefix: string);
48
+ constructor(s3Client: any, bucketName: string, prefix?: string);
44
49
  getFileHandle(name: string, options?: {
45
50
  create?: boolean;
46
51
  }): Promise<FileSystemFileHandle>;
@@ -50,22 +55,18 @@ export declare class BunS3FileSystemDirectoryHandle implements FileSystemDirecto
50
55
  removeEntry(name: string, options?: {
51
56
  recursive?: boolean;
52
57
  }): Promise<void>;
53
- resolve(_possibleDescendant: FileSystemHandle): Promise<string[] | null>;
54
- entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
58
+ resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
59
+ entries(): AsyncIterableIterator<[
60
+ string,
61
+ FileSystemFileHandle | FileSystemDirectoryHandle
62
+ ]>;
55
63
  keys(): AsyncIterableIterator<string>;
56
- values(): AsyncIterableIterator<FileSystemHandle>;
64
+ values(): AsyncIterableIterator<FileSystemFileHandle | FileSystemDirectoryHandle>;
65
+ [Symbol.asyncIterator](): AsyncIterableIterator<[
66
+ string,
67
+ FileSystemFileHandle | FileSystemDirectoryHandle
68
+ ]>;
57
69
  isSameEntry(other: FileSystemHandle): Promise<boolean>;
58
70
  queryPermission(): Promise<PermissionState>;
59
71
  requestPermission(): Promise<PermissionState>;
60
72
  }
61
- /**
62
- * S3 bucket using Bun's native S3Client
63
- */
64
- export declare class S3Bucket implements Bucket {
65
- private config;
66
- private s3Client;
67
- constructor(s3Client: any, config?: FileSystemConfig);
68
- getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
69
- getConfig(): FileSystemConfig;
70
- dispose(): Promise<void>;
71
- }