@@ -18,6 +18,7 @@ import path from "path";
1818import { Sequelize , DataTypes , Model } from "sequelize" ;
1919import { jsonDataType , parentPath } from "./databaseUtils" ;
2020import { LicensePolicy , Resource } from "../importedJsonTypes" ;
21+ import { getPathDepth } from "../../utils/paths" ;
2122
2223export interface InfoFlatFileAttributes {
2324 type : string ;
@@ -110,6 +111,7 @@ export interface FlatFileAttributes
110111 id : number ;
111112 fileId : number ;
112113 path : string ;
114+ level : number ;
113115 parent : string ;
114116}
115117
@@ -129,6 +131,7 @@ export default function flatFileModel(sequelize: Sequelize) {
129131 unique : true ,
130132 allowNull : false ,
131133 } ,
134+ level : DataTypes . INTEGER ,
132135 parent : { type : DataTypes . STRING , defaultValue : "" } ,
133136 copyright_statements : jsonDataType ( "copyright_statements" , [ ] ) ,
134137 copyright_holders : jsonDataType ( "copyright_holders" , [ ] ) ,
@@ -242,6 +245,7 @@ interface FlattenedFile {
242245 fileId : number ;
243246 path : string ;
244247 parent : string ;
248+ level : number ;
245249 copyright_statements : unknown [ ] ;
246250 copyright_holders : unknown [ ] ;
247251 copyright_authors : unknown [ ] ;
@@ -311,11 +315,13 @@ interface FlattenedFile {
311315 package_data_dependencies : unknown [ ] ;
312316 package_data_related_packages : unknown [ ] ;
313317}
318+
314319export function flattenFile ( file : Resource ) : FlattenedFile {
315320 return {
316321 id : file . id ,
317322 fileId : file . id ,
318323 path : file . path ,
324+ level : getPathDepth ( file . path ) ,
319325 parent : parentPath ( file . path ) ,
320326 copyright_statements : getCopyrightValues ( file . copyrights , "copyright" ) ,
321327 copyright_holders : getCopyrightValues ( file . holders , "holder" ) ,
0 commit comments