diff --git a/lib/files/file.ts b/lib/files/file.ts index dfc3d064..4c7c3421 100644 --- a/lib/files/file.ts +++ b/lib/files/file.ts @@ -11,6 +11,13 @@ export class File extends Node { return FileType.File } + /** + * Returns a clone of the file + */ + clone(): File { + return new File(this.data) + } + } /** diff --git a/lib/files/folder.ts b/lib/files/folder.ts index 940612d7..d53250ad 100644 --- a/lib/files/folder.ts +++ b/lib/files/folder.ts @@ -28,6 +28,13 @@ export class Folder extends Node { return 'httpd/unix-directory' } + /** + * Returns a clone of the folder + */ + clone(): Node { + return new Folder(this.data) + } + } /** diff --git a/lib/files/node.ts b/lib/files/node.ts index 611c7250..6978c111 100644 --- a/lib/files/node.ts +++ b/lib/files/node.ts @@ -21,13 +21,9 @@ export enum NodeStatus { LOCKED = 'locked', } -interface NodeInternalData extends NodeData { - attributes: Attribute -} - export abstract class Node { - private _data: NodeInternalData + private _data: NodeData private _attributes: Attribute private _knownDavService = /(remote|public)\.php\/(web)?dav/i @@ -324,6 +320,13 @@ export abstract class Node { this._data.status = status } + /** + * Get the node data + */ + get data(): NodeData { + return structuredClone(this._data) + } + /** * Move the node to a new destination * @@ -393,6 +396,11 @@ export abstract class Node { } } + /** + * Returns a clone of the node + */ + abstract clone(): Node + } /** diff --git a/lib/index.ts b/lib/index.ts index dcf95135..e28f7cde 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -19,6 +19,7 @@ export { FileType } from './files/fileType' export { File, type IFile } from './files/file' export { Folder, type IFolder } from './files/folder' export { Node, NodeStatus, type INode } from './files/node' +export type { NodeData } from './files/nodeData.ts' export * from './utils/filename-validation' export { getUniqueName } from './utils/filename' diff --git a/tsconfig.json b/tsconfig.json index 807337f3..9cede049 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "include": ["./lib/**/*.ts", "./*.d.ts"], "compilerOptions": { "allowSyntheticDefaultImports": true, + "allowImportingTsExtensions": true, "moduleResolution": "Bundler", "target": "ESNext", "module": "ESNext", @@ -10,5 +11,6 @@ "noImplicitAny": false, "outDir": "./dist", "rootDir": "./lib", + "noEmit": true, } }