feat: publish HoloLake model-native living system source
This commit is contained in:
parent
6ad10edde1
commit
c395dd3a99
2467 changed files with 615073 additions and 0 deletions
|
|
@ -0,0 +1,79 @@
|
|||
export interface GuanghuEnterpriseDomain {
|
||||
accessState: string
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface GuanghuEnterpriseStatus {
|
||||
domains: GuanghuEnterpriseDomain[]
|
||||
execution: string
|
||||
hostState: string
|
||||
nodeId: string
|
||||
}
|
||||
|
||||
export type GuanghuEnterpriseState =
|
||||
| {
|
||||
checkedAt: null
|
||||
error: null
|
||||
phase: 'checking'
|
||||
status: null
|
||||
}
|
||||
| {
|
||||
checkedAt: number
|
||||
error: null
|
||||
phase: 'online'
|
||||
status: GuanghuEnterpriseStatus
|
||||
}
|
||||
| {
|
||||
checkedAt: number
|
||||
error: string
|
||||
phase: 'error'
|
||||
status: null
|
||||
}
|
||||
|
||||
export const INITIAL_GUANGHU_ENTERPRISE_STATE: GuanghuEnterpriseState = {
|
||||
checkedAt: null,
|
||||
error: null,
|
||||
phase: 'checking',
|
||||
status: null,
|
||||
}
|
||||
|
||||
function record(value: unknown): Record<string, unknown> | null {
|
||||
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
||||
? value as Record<string, unknown>
|
||||
: null
|
||||
}
|
||||
|
||||
function requiredText(value: unknown): string | null {
|
||||
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : null
|
||||
}
|
||||
|
||||
export function parseGuanghuEnterpriseStatus(value: unknown): GuanghuEnterpriseStatus {
|
||||
const payload = record(value)
|
||||
const nodeId = requiredText(payload?.node_id)
|
||||
const hostState = requiredText(payload?.host_state)
|
||||
const domains = Array.isArray(payload?.domains) ? payload.domains : null
|
||||
if (!payload || !nodeId || !hostState || !domains) {
|
||||
throw new Error('guanghu_enterprise_status_invalid')
|
||||
}
|
||||
|
||||
const projectedDomains = domains.map(item => {
|
||||
const domain = record(item)
|
||||
const id = requiredText(domain?.id)
|
||||
const name = requiredText(domain?.name)
|
||||
const accessState = requiredText(domain?.access_state)
|
||||
if (!domain || !id || !name || !accessState) {
|
||||
throw new Error('guanghu_enterprise_status_invalid')
|
||||
}
|
||||
return { accessState, id, name }
|
||||
})
|
||||
|
||||
return {
|
||||
domains: projectedDomains,
|
||||
execution: requiredText(payload.execution) ?? (
|
||||
payload.raw_shell === 'rejected' ? 'disabled' : 'unknown'
|
||||
),
|
||||
hostState,
|
||||
nodeId,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue