@@ -8,12 +8,18 @@ import {
88 type ModelDefaultCatalog ,
99 type ModelDefinition ,
1010} from '@/api/client'
11+ import type { ModelFQN , ModelName , ModelPath } from '@/types/models'
1112import { isArrayNotEmpty } from '@/utils/index'
1213import { ModelInitial } from './initial'
1314import type { Lineage } from './lineage'
1415
15- export interface InitialSQLMeshModel extends Model {
16- lineage ?: Record < string , Lineage >
16+ export interface InitialSQLMeshModel
17+ extends Omit < Model , 'name' | 'fqn' | 'path' | 'full_path' > {
18+ name : ModelName
19+ fqn : ModelFQN
20+ path : ModelPath
21+ full_path : ModelPath
22+ lineage ?: Record < ModelName , Lineage >
1723}
1824
1925export class ModelSQLMeshModel <
@@ -22,9 +28,10 @@ export class ModelSQLMeshModel<
2228 _details : ModelDetails = { }
2329 _detailsIndex : string = ''
2430
25- name : string
26- fqn : string
27- path : string
31+ name : ModelName
32+ fqn : ModelFQN
33+ path : ModelPath
34+ full_path : ModelPath
2835 dialect : string
2936 type : ModelType
3037 columns : Column [ ]
@@ -46,10 +53,11 @@ export class ModelSQLMeshModel<
4653 } ,
4754 )
4855
49- this . name = encodeURI ( this . initial . name )
50- this . fqn = encodeURI ( this . initial . fqn )
56+ this . name = encodeURI ( this . initial . name ) as ModelName
57+ this . fqn = encodeURI ( this . initial . fqn ) as ModelFQN
5158 this . default_catalog = this . initial . default_catalog
52- this . path = this . initial . path
59+ this . path = this . initial . path as ModelPath
60+ this . full_path = this . initial . full_path as ModelPath
5361 this . dialect = this . initial . dialect
5462 this . description = this . initial . description
5563 this . sql = this . initial . sql
@@ -127,17 +135,21 @@ export class ModelSQLMeshModel<
127135 } else if ( key === 'details' ) {
128136 this . details = value as ModelDetails
129137 } else if ( key === 'name' ) {
130- this . name = encodeURI ( value as string )
138+ this . name = encodeURI ( value as string ) as ModelName
131139 } else if ( key === 'fqn' ) {
132- this . fqn = encodeURI ( value as string )
140+ this . fqn = encodeURI ( value as string ) as ModelFQN
133141 } else if ( key === 'type' ) {
134142 this . type = value as ModelType
135143 } else if ( key === 'default_catalog' ) {
136144 this . default_catalog = value as ModelDefaultCatalog
137145 } else if ( key === 'description' ) {
138146 this . description = value as ModelDescription
139147 } else if ( key in this ) {
140- this [ key as 'path' | 'dialect' | 'sql' ] = value as string
148+ if ( key === 'path' || key === 'full_path' ) {
149+ ; ( this as any ) [ key ] = value as ModelPath
150+ } else {
151+ ; ( this as any ) [ key ] = value as string
152+ }
141153 }
142154 }
143155 }
0 commit comments