Skip to content

Commit 3109420

Browse files
committed
feat: Add toContract to File and Folder class
1 parent 978bcab commit 3109420

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.4.8",
3+
"version": "1.4.9",
44
"description": "",
55
"license": "MIT",
66
"author": "João Lenon",
@@ -18,7 +18,7 @@
1818
"nodejs"
1919
],
2020
"devDependencies": {
21-
"@secjs/contracts": "1.1.7",
21+
"@secjs/contracts": "1.1.8",
2222
"@secjs/exceptions": "1.0.4",
2323
"@secjs/logger": "1.2.2",
2424
"@types/debug": "4.1.5",

src/Classes/File.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { lookup } from 'mime-types'
2727
import { randomBytes } from 'crypto'
2828
import { parse, isAbsolute } from 'path'
2929
import { InternalServerException } from '@secjs/exceptions'
30+
import { FileContract } from '@secjs/contracts'
3031

3132
export interface FileJsonContract {
3233
dir: string
@@ -98,6 +99,13 @@ export class File {
9899
)
99100
}
100101

102+
toContract(): FileContract {
103+
return {
104+
path: this.path,
105+
value: this.getContentSync(),
106+
}
107+
}
108+
101109
toJSON(): FileJsonContract {
102110
return JSON.parse(
103111
JSON.stringify({

src/Classes/Folder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Parser } from './Parser'
2525
import { randomBytes } from 'crypto'
2626
import { isAbsolute, join, parse, resolve } from 'path'
2727
import { InternalServerException } from '@secjs/exceptions'
28+
import { DirectoryContract } from '@secjs/contracts'
2829

2930
export interface FolderJsonContract {
3031
dir: string
@@ -75,6 +76,14 @@ export class Folder {
7576
this.createFolderValues(mockedValues)
7677
}
7778

79+
toContract(): DirectoryContract {
80+
return {
81+
path: this.path,
82+
files: this.files.map(file => file.toContract()),
83+
folders: this.folders.map(folder => folder.toContract()),
84+
}
85+
}
86+
7887
toJSON(): FolderJsonContract {
7988
return JSON.parse(
8089
JSON.stringify({

src/utils/global.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import { unset as unsetFn } from '../Functions/unset'
1111
import { Path as PathInstance } from '../Classes/Path'
12+
import { DirectoryContract, FileContract } from '@secjs/contracts'
1213
import { File as FileInstance, FileJsonContract } from '../Classes/File'
1314
import { Folder as FolderInstance, FolderJsonContract } from '../Classes/Folder'
1415

@@ -69,6 +70,7 @@ declare global {
6970
isCopy?: boolean,
7071
)
7172

73+
toContract(): FileContract
7274
toJSON(): FileJsonContract
7375
createSync(): File
7476
create(): Promise<File>
@@ -199,6 +201,8 @@ declare global {
199201
* @param isCopy Default is false
200202
*/
201203
constructor(folderPath: string, mockedValues?: boolean, isCopy?: boolean)
204+
205+
toContract(): DirectoryContract
202206
toJSON(): FolderJsonContract
203207
createSync(): Folder
204208
create(): Promise<Folder>

0 commit comments

Comments
 (0)