@@ -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" , [ ] ) ,
@@ -245,6 +248,7 @@ interface FlattenedFile {
245248 fileId : number ;
246249 path : string ;
247250 parent : string ;
251+ level : number ;
248252 copyright_statements : unknown [ ] ;
249253 copyright_holders : unknown [ ] ;
250254 copyright_authors : unknown [ ] ;
@@ -314,11 +318,13 @@ interface FlattenedFile {
314318 package_data_dependencies : unknown [ ] ;
315319 package_data_related_packages : unknown [ ] ;
316320}
321+
317322export function flattenFile ( file : Resource ) : FlattenedFile {
318323 return {
319324 id : file . id ,
320325 fileId : file . id ,
321326 path : file . path ,
327+ level : getPathDepth ( file . path ) ,
322328 parent : parentPath ( file . path ) ,
323329 copyright_statements : getCopyrightValues ( file . copyrights , "copyright" ) ,
324330 copyright_holders : getCopyrightValues ( file . holders , "holder" ) ,
0 commit comments