@hyperfrontend/versioning/repository/modelsmodels
Repository data models: platforms, configurations, and inference results.
RepositoryPlatform plus KnownPlatform, PLATFORM_HOSTNAMES, isKnownPlatform, and detectPlatformFromHostname cover the supported source-code platforms (GitHub, GitLab, Bitbucket, Azure DevOps). RepositoryConfig (built via createRepositoryConfig, validated via isRepositoryConfig) carries the platform, owner, repo name, and the CompareUrlFormatter that produces version-diff URLs. RepositoryResolution (with createDisabledResolution, createExplicitResolution, createInferredResolution) captures how a resolution was reached — explicitly configured, inferred from package.json, or deliberately disabled.
API Reference
ƒ Functions
No compare URLs will be generated.
Returns
RepositoryResolutionExample
Disabling repository resolution
const config = createDisabledResolution()
// { mode: 'disabled' }Parameters
| Name | Type | Description |
|---|---|---|
§repository | RepositoryConfig | The repository config to use |
Returns
RepositoryResolutionExample
Using an explicit repository configuration
const config = createExplicitResolution({
platform: 'github',
baseUrl: 'https://github.com/owner/repo'
})Parameters
| Name | Type | Description |
|---|---|---|
§inferenceOrder | unknown | Order to try inference sources (default: package-json first) (default: ...) |
Returns
RepositoryResolutionExample
Configuring inference order
// Default order: package.json → git remote
const config = createInferredResolution()
// Custom order: git remote → package.json
const customOrder = createInferredResolution(['git-remote', 'package-json'])Normalizes the base URL by stripping trailing slashes and validating that custom platforms have a formatter function.
Parameters
| Name | Type | Description |
|---|---|---|
§options | CreateRepositoryConfigOptions | Repository configuration options |
Returns
RepositoryConfigExample
Creating repository configurations
// GitHub repository
const config = createRepositoryConfig({
platform: 'github',
baseUrl: 'https://github.com/owner/repo'
})
// Custom platform
const customConfig = createRepositoryConfig({
platform: 'custom',
baseUrl: 'https://my-git.internal/repo',
formatCompareUrl: (from, to) => `https://my-git.internal/diff/${from}/${to}`
})First checks for exact match in known platforms, then applies heuristics for self-hosted instances (e.g.,
github.company.com → github).Parameters
| Name | Type | Description |
|---|---|---|
§hostname | string | Hostname to detect platform from (e.g., "github.com") |
Returns
RepositoryPlatformExample
Detecting platform from hostname
detectPlatformFromHostname('github.com') // 'github'
detectPlatformFromHostname('gitlab.mycompany.com') // 'gitlab'
detectPlatformFromHostname('custom-git.internal') // 'unknown'Parameters
| Name | Type | Description |
|---|---|---|
§platform | RepositoryPlatform | Platform identifier to check |
Returns
unknownExample
Checking if platform has built-in support
isKnownPlatform('github') // true
isKnownPlatform('gitlab') // true
isKnownPlatform('custom') // false
isKnownPlatform('unknown') // falseParameters
| Name | Type | Description |
|---|---|---|
§value | unknown | Value to check |
Returns
unknownExample
Type-checking repository config values
const config = { platform: 'github', baseUrl: 'https://...' }
if (isRepositoryConfig(config)) {
// config is typed as RepositoryConfig
}Parameters
| Name | Type | Description |
|---|---|---|
§value | unknown | Value to check |
Returns
unknownExample
Type-checking resolution configurations
import { isRepositoryResolution } from '@hyperfrontend/versioning'
const config = loadConfig()
if (isRepositoryResolution(config.repository)) {
console.log('Repository mode:', config.repository.mode)
}◈ Interfaces
Supports both standard platforms and self-hosted instances. When using a known platform, compare URLs are generated automatically. For custom or unknown platforms, provide a
formatCompareUrl function.Properties
readonly baseUrl:string— This is the URL without any trailing slashes or paths like
/compare.readonly formatCompareUrl?:CompareUrlFormatter— Required when
platform is 'custom'. Optional for known platforms (overrides built-in formatter). Receives the from and to tags, returns the full compare URL.
Provides fine-grained control over repository resolution behavior.
Properties
readonly inferenceOrder?:unknown— mode is 'inferred'. Sources are tried in order until one succeeds. Default:
['package-json', 'git-remote']readonly repository?:RepositoryConfig— Required when
mode is 'explicit'. Ignored when mode is 'inferred' or 'disabled'.◆ Types
type CompareUrlFormatter = (fromCommit: string, toCommit: string) => stringEach platform has a specific URL format for compare links:
github:{baseUrl}/compare/{fromCommit}...{toCommit}gitlab:{baseUrl}/-/compare/{fromCommit}...{toCommit}bitbucket:{baseUrl}/compare/{toCommit}..{fromCommit}(reversed order)azure-devops:{baseUrl}/compare?version=GT{toCommit}&compareVersion=GT{fromCommit}
type KnownPlatform = "github" | "gitlab" | "bitbucket" | "azure-devops"package-json: Read fromrepositoryfield in package.jsongit-remote: Read fromgit remote get-url origin
type RepositoryInferenceSource = "package-json" | "git-remote"- Known platforms have built-in compare URL formatters
customrequires a customformatCompareUrlfunctionunknownindicates platform could not be determined (no URL generation)
type RepositoryPlatform = KnownPlatform | "custom" | "unknown"explicit: Use only the providedRepositoryConfig; error if missinginferred: Auto-detect from package.json repository field or git remotedisabled: Do not generate compare URLs (default for backward compatibility)
type RepositoryResolutionMode = "explicit" | "inferred" | "disabled"