Implementation:TobikoData Sqlmesh Model Artifact
| Knowledge Sources | |
|---|---|
| Domains | Web_UI, Data_Models |
| Last Updated | 2026-02-07 20:00 GMT |
Overview
Base model class for file system artifacts (files and directories) in the SQLMesh web UI, providing path and naming functionality.
Description
ModelArtifact is an abstract base class that represents file system artifacts in the SQLMesh web client. It extends ModelInitial and provides core functionality for managing artifact paths, names, and parent-child relationships within the directory tree structure. The class supports both local (unsaved) and remote (saved to disk) artifacts, with utilities for renaming, copying, and hierarchical navigation.
Key features include unique ID generation based on path, untitled artifact detection, parent directory references, and static methods for finding artifacts within directory structures.
Usage
Use this class as the foundation for implementing file and directory models in the web UI's file explorer component, enabling proper artifact management and navigation.
Code Reference
Source Location
- Repository: TobikoData_Sqlmesh
- File: web/client/src/models/artifact.ts
Signature
export class ModelArtifact<
T extends InitialArtifact = InitialArtifact
> extends ModelInitial<T> {
private _path: string
private _name: string
parent: ModelDirectory | undefined
remove: boolean = false
constructor(initial?: T | ModelArtifact, parent?: ModelDirectory)
get id(): ID
get name(): string
get path(): string
get isUntitled(): boolean
get isLocal(): boolean
get isRemote(): boolean
get withParent(): boolean
copyName(): string
rename(newName: string): void
static findArtifactByPath(
directory: ModelDirectory,
path: string
): ModelArtifact | undefined
}
Import
import { ModelArtifact } from '@models/artifact'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| initial | ModelArtifact | No | Initial artifact data containing name and path |
| parent | ModelDirectory | No | Parent directory reference for hierarchical structure |
Outputs
| Property | Type | Description |
|---|---|---|
| id | ID | Unique identifier (path if available, otherwise initial.id) |
| name | string | Artifact name |
| path | string | Full file system path |
| isUntitled | boolean | True if name is empty string |
| isLocal | boolean | True if path is empty (not saved) |
| isRemote | boolean | True if path exists (saved to disk) |
| withParent | boolean | True if parent directory exists |
Usage Examples
// Create a new artifact with parent directory
const artifact = new ModelArtifact(
{ name: 'my_model.sql', path: 'models/my_model.sql' },
parentDirectory
)
// Check artifact state
if (artifact.isRemote && !artifact.isUntitled) {
console.log(`Saved artifact: ${artifact.name}`)
}
// Rename an artifact
artifact.rename('new_name.sql')
// Generate copy name with unique suffix
const copyName = artifact.copyName()
// Result: "Copy of my_model__unique123.sql"
// Find artifact by path in directory tree
const found = ModelArtifact.findArtifactByPath(
rootDirectory,
'models/my_model.sql'
)