Skip to content

Commit f39b84c

Browse files
committed
chore: add branded model string types
1 parent 8ff6aa2 commit f39b84c

3 files changed

Lines changed: 32 additions & 13 deletions

File tree

vscode/react/src/domain/lineage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type LineageColumn } from '@/api/client'
2+
import type { ModelFQN, ModelName } from '@/types/models'
23

34
export interface Lineage {
4-
models: string[]
5-
columns?: Record<string, LineageColumn>
5+
models: ModelFQN[]
6+
columns?: Record<ModelName, LineageColumn>
67
}

vscode/react/src/domain/sqlmesh-model.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ import {
88
type ModelDefaultCatalog,
99
type ModelDefinition,
1010
} from '@/api/client'
11+
import type { ModelFQN, ModelName, ModelPath } from '@/types/models'
1112
import { isArrayNotEmpty } from '@/utils/index'
1213
import { ModelInitial } from './initial'
1314
import 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

1925
export 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
}

vscode/react/src/types/models.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type Brand<T, B extends string> = T & { __brand: B }
2+
3+
export type ModelName = Brand<string, 'ModelName'>
4+
export type ModelFQN = Brand<string, 'ModelFQN'>
5+
export type ModelURI = Brand<string, 'ModelURI'>
6+
export type ModelPath = Brand<string, 'ModelPath'>

0 commit comments

Comments
 (0)