Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow cloning a node #1077

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/files/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
return FileType.File
}

/**
* Returns a clone of the file
*/
clone(): File {
return new File(this.data)

Check warning on line 18 in lib/files/file.ts

View check run for this annotation

Codecov / codecov/patch

lib/files/file.ts#L18

Added line #L18 was not covered by tests
}

}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/files/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
return 'httpd/unix-directory'
}

/**
* Returns a clone of the folder
*/
clone(): Node {
return new Folder(this.data)

Check warning on line 35 in lib/files/folder.ts

View check run for this annotation

Codecov / codecov/patch

lib/files/folder.ts#L35

Added line #L35 was not covered by tests
}

}

/**
Expand Down
18 changes: 13 additions & 5 deletions lib/files/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
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

Expand Down Expand Up @@ -324,6 +320,13 @@
this._data.status = status
}

/**
* Get the node data
*/
get data(): NodeData {
return structuredClone(this._data)

Check warning on line 327 in lib/files/node.ts

View check run for this annotation

Codecov / codecov/patch

lib/files/node.ts#L327

Added line #L327 was not covered by tests
}

/**
* Move the node to a new destination
*
Expand Down Expand Up @@ -393,6 +396,11 @@
}
}

/**
* Returns a clone of the node
*/
abstract clone(): Node

}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"include": ["./lib/**/*.ts", "./*.d.ts"],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowImportingTsExtensions": true,
"moduleResolution": "Bundler",
"target": "ESNext",
"module": "ESNext",
Expand All @@ -10,5 +11,6 @@
"noImplicitAny": false,
"outDir": "./dist",
"rootDir": "./lib",
"noEmit": true,
}
}
Loading