From e431ac265cede5e71f4c3fa59e3748b653bdd0e5 Mon Sep 17 00:00:00 2001 From: Reynaldi Chernando <12949382+reynaldichernando@users.noreply.github.com> Date: Sat, 13 Dec 2025 03:55:39 +0700 Subject: [PATCH] Fix FS types (#2134) --- src/puter-js/index.d.ts | 4 +- src/puter-js/types/modules/filesystem.d.ts | 106 ++++++++++++++++----- src/puter-js/types/puter.d.ts | 4 +- 3 files changed, 86 insertions(+), 28 deletions(-) diff --git a/src/puter-js/index.d.ts b/src/puter-js/index.d.ts index 1d026106..a1f80150 100644 --- a/src/puter-js/index.d.ts +++ b/src/puter-js/index.d.ts @@ -4,7 +4,7 @@ import type { Apps, AppListOptions, AppRecord, CreateAppOptions, UpdateAppAttrib import type { Auth, APIUsage, AllowanceInfo, AppUsage, AuthUser, DetailedAppUsage, MonthlyUsage } from './types/modules/auth.d.ts'; import type { Debug } from './types/modules/debug.d.ts'; import type { Driver, DriverDescriptor, Drivers } from './types/modules/drivers.d.ts'; -import type { PuterJSFileSystemModule, CopyOptions, DeleteOptions, MkdirOptions, MoveOptions, ReadOptions, ReaddirOptions, SignResult, SpaceInfo, UploadOptions, WriteOptions } from './types/modules/filesystem.d.ts'; +import type { FS, CopyOptions, DeleteOptions, MkdirOptions, MoveOptions, ReadOptions, ReaddirOptions, SignResult, SpaceInfo, UploadOptions, WriteOptions } from './types/modules/filesystem.d.ts'; import type { FSItem, FileSignatureInfo, InternalFSProperties } from './types/modules/fs-item.d.ts'; import type { Hosting, Subdomain } from './types/modules/hosting.d.ts'; import type { KV, KVIncrementPath, KVPair } from './types/modules/kv.d.ts'; @@ -83,7 +83,7 @@ export type { PTLSSocket, Puter, PuterEnvironment, - PuterJSFileSystemModule, + FS, ReadOptions, ReaddirOptions, RequestCallbacks, diff --git a/src/puter-js/types/modules/filesystem.d.ts b/src/puter-js/types/modules/filesystem.d.ts index 62cabdd9..5df2284a 100644 --- a/src/puter-js/types/modules/filesystem.d.ts +++ b/src/puter-js/types/modules/filesystem.d.ts @@ -7,37 +7,43 @@ export interface SpaceInfo { } export interface CopyOptions extends RequestCallbacks { - source: string; - destination: string; + source?: string; + destination?: string; overwrite?: boolean; newName?: string; createMissingParents?: boolean; dedupeName?: boolean; newMetadata?: Record; excludeSocketID?: string; + original_client_socket_id?: string; } export interface MoveOptions extends RequestCallbacks { - source: string; - destination: string; + source?: string; + destination?: string; overwrite?: boolean; newName?: string; createMissingParents?: boolean; newMetadata?: Record; excludeSocketID?: string; + original_client_socket_id?: string; } export interface MkdirOptions extends RequestCallbacks { path?: string; overwrite?: boolean; dedupeName?: boolean; + rename?: boolean; createMissingParents?: boolean; + recursive?: boolean; + shortcutTo?: string; } export interface DeleteOptions extends RequestCallbacks { - path?: string; + paths?: string | string[]; recursive?: boolean; descendantsOnly?: boolean; + descendants_only?: boolean; } export interface ReadOptions extends RequestCallbacks { @@ -57,24 +63,48 @@ export interface ReaddirOptions extends RequestCallbacks { export interface RenameOptions extends RequestCallbacks { uid?: string; path?: string; - newName: string; + newName?: string; + excludeSocketID?: string; + original_client_socket_id?: string; } -export interface UploadOptions extends RequestCallbacks { +export interface StatOptions extends RequestCallbacks { + path?: string; + uid?: string; + consistency?: 'strong' | 'eventual'; + returnSubdomains?: boolean; + returnPermissions?: boolean; + returnVersions?: boolean; + returnSize?: boolean; +} + +export interface UploadOptions extends RequestCallbacks { overwrite?: boolean; dedupeName?: boolean; name?: string; parsedDataTransferItems?: boolean; createFileParent?: boolean; + createMissingAncestors?: boolean; + createMissingParents?: boolean; + shortcutTo?: string; + appUID?: string; + strict?: boolean; init?: (operationId: string, xhr: XMLHttpRequest) => void; - error?: (e: unknown) => void; + start?: () => void; + progress?: (operationId: string, progress: number) => void; + abort?: (operationId: string) => void; } export interface WriteOptions extends RequestCallbacks { overwrite?: boolean; dedupeName?: boolean; createMissingParents?: boolean; + createMissingAncestors?: boolean; name?: string; + init?: (operationId: string, xhr: XMLHttpRequest) => void; + start?: () => void; + progress?: (operationId: string, progress: number) => void; + abort?: (operationId: string) => void; } export interface SignResult> { @@ -82,23 +112,51 @@ export interface SignResult> { items: T | T[]; } -export class PuterJSFileSystemModule { - constructor (context: Record); +export type UploadItems = DataTransferItemList | DataTransferItem | FileList | File[] | Blob[] | Blob | File | string | unknown[]; + +export class FS { + space (): Promise; + space (options: RequestCallbacks): Promise; + space (success: (value: SpaceInfo) => void, error?: (reason: unknown) => void): Promise; + + mkdir (options: MkdirOptions): Promise; + mkdir (path: string, options?: MkdirOptions): Promise; + mkdir (path: string, options: MkdirOptions, success: (value: FSItem) => void, error?: (reason: unknown) => void): Promise; + mkdir (path: string, success: (value: FSItem) => void, error?: (reason: unknown) => void): Promise; + + copy (options: CopyOptions): Promise; + copy (source: string, destination: string, options?: CopyOptions): Promise; + copy (source: string, destination: string, options: CopyOptions | undefined, success: (value: FSItem) => void, error?: (reason: unknown) => void): Promise; + + move (options: MoveOptions): Promise; + move (source: string, destination: string, options?: MoveOptions): Promise; + + rename (options: RenameOptions): Promise; + rename (path: string, newName: string, success?: (value: FSItem) => void, error?: (reason: unknown) => void): Promise; + + read (options: ReadOptions): Promise; + read (path: string, options?: ReadOptions): Promise; + read (path: string, success: (value: Blob) => void, error?: (reason: unknown) => void): Promise; + + readdir (options: ReaddirOptions): Promise; + readdir (path: string, success?: (value: FSItem[]) => void, error?: (reason: unknown) => void): Promise; + + stat (options: StatOptions): Promise; + stat (path: string, options?: StatOptions): Promise; + stat (path: string, options: StatOptions, success: (value: FSItem) => void, error?: (reason: unknown) => void): Promise; + stat (path: string, success: (value: FSItem) => void, error?: (reason: unknown) => void): Promise; + + delete (options: DeleteOptions): Promise; + delete (paths: string | string[], options?: DeleteOptions): Promise; + + upload (items: UploadItems, dirPath?: string, options?: UploadOptions): Promise; + + write (file: File): Promise; + write (path: string, data: string | File | Blob | ArrayBuffer | ArrayBufferView, options?: WriteOptions): Promise; - space (options?: RequestCallbacks): Promise; - mkdir (pathOrOptions: string | MkdirOptions, options?: MkdirOptions): Promise; - copy (sourceOrOptions: string | CopyOptions, destination?: string, options?: CopyOptions): Promise; - rename (pathOrUid: string, newName: string, options?: RenameOptions): Promise; - upload (items: FileList | File[] | Blob[] | Blob | string | unknown[], dirPath?: string, options?: UploadOptions): Promise; - read (pathOrOptions: string | ReadOptions, options?: ReadOptions): Promise; - delete (pathOrOptions: string | DeleteOptions, options?: DeleteOptions): Promise; - move (sourceOrOptions: string | MoveOptions, destination?: string, options?: MoveOptions): Promise; - write (path: string, data?: string | File | Blob | ArrayBuffer | ArrayBufferView, options?: WriteOptions): Promise; sign (appUid: string, items: unknown | unknown[], success?: (result: SignResult) => void, error?: (reason: unknown) => void): Promise; - symlink (targetPath: string, linkPath: string, options?: Record): Promise; - getReadURL (path: string, expiresIn?: number): Promise; - readdir (pathOrOptions?: string | ReaddirOptions, options?: ReaddirOptions): Promise; - stat (pathOrUid: string, options?: Record): Promise; - FSItem: typeof FSItem; + symlink (target: string, linkPath: string): Promise; + + getReadURL (path: string, expiresIn?: string): Promise; } diff --git a/src/puter-js/types/puter.d.ts b/src/puter-js/types/puter.d.ts index 07e14548..631fce84 100644 --- a/src/puter-js/types/puter.d.ts +++ b/src/puter-js/types/puter.d.ts @@ -3,7 +3,7 @@ import type { Apps } from './modules/apps.d.ts'; import type { Auth } from './modules/auth.d.ts'; import type { Debug } from './modules/debug.d.ts'; import type { Drivers } from './modules/drivers.d.ts'; -import type { PuterJSFileSystemModule, SpaceInfo } from './modules/filesystem.d.ts'; +import type { FS } from './modules/filesystem.d.ts'; import type { FSItem } from './modules/fs-item.d.ts'; import type { Hosting } from './modules/hosting.d.ts'; import type { KV } from './modules/kv.d.ts'; @@ -51,7 +51,7 @@ export class Puter { apps: Apps; auth: Auth; os: OS; - fs: PuterJSFileSystemModule; + fs: FS; ui: UI; hosting: Hosting; kv: KV;