mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
refactor: completely remove ionic
This commit is contained in:
161
web/projects/ui/src/app/utils/config-utilities.ts
Normal file
161
web/projects/ui/src/app/utils/config-utilities.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import { CT } from '@start9labs/start-sdk'
|
||||
|
||||
export class Range {
|
||||
min?: number
|
||||
max?: number
|
||||
minInclusive!: boolean
|
||||
maxInclusive!: boolean
|
||||
|
||||
static from(s: string = '(*,*)'): Range {
|
||||
const r = new Range()
|
||||
r.minInclusive = s.startsWith('[')
|
||||
r.maxInclusive = s.endsWith(']')
|
||||
const [minStr, maxStr] = s.split(',').map(a => a.trim())
|
||||
r.min = minStr === '(*' ? undefined : Number(minStr.slice(1))
|
||||
r.max = maxStr === '*)' ? undefined : Number(maxStr.slice(0, -1))
|
||||
return r
|
||||
}
|
||||
|
||||
checkIncludes(n: number) {
|
||||
if (
|
||||
this.hasMin() &&
|
||||
(this.min > n || (!this.minInclusive && this.min == n))
|
||||
) {
|
||||
throw new Error(this.minMessage())
|
||||
}
|
||||
if (
|
||||
this.hasMax() &&
|
||||
(this.max < n || (!this.maxInclusive && this.max == n))
|
||||
) {
|
||||
throw new Error(this.maxMessage())
|
||||
}
|
||||
}
|
||||
|
||||
private hasMin(): this is Range & { min: number } {
|
||||
return this.min !== undefined
|
||||
}
|
||||
|
||||
private hasMax(): this is Range & { max: number } {
|
||||
return this.max !== undefined
|
||||
}
|
||||
|
||||
private minMessage(): string {
|
||||
return `greater than${this.minInclusive ? ' or equal to' : ''} ${this.min}`
|
||||
}
|
||||
|
||||
private maxMessage(): string {
|
||||
return `less than${this.maxInclusive ? ' or equal to' : ''} ${this.max}`
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultString(defaultSpec: CT.DefaultString): string {
|
||||
if (typeof defaultSpec === 'string') {
|
||||
return defaultSpec
|
||||
} else {
|
||||
let s = ''
|
||||
for (let i = 0; i < defaultSpec.len; i++) {
|
||||
s = s + getRandomCharInSet(defaultSpec.charset)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
// a,g,h,A-Z,,,,-
|
||||
function getRandomCharInSet(charset: string): string {
|
||||
const set = stringToCharSet(charset)
|
||||
let charIdx = Math.floor(Math.random() * set.len)
|
||||
for (let range of set.ranges) {
|
||||
if (range.len > charIdx) {
|
||||
return String.fromCharCode(range.start.charCodeAt(0) + charIdx)
|
||||
}
|
||||
charIdx -= range.len
|
||||
}
|
||||
throw new Error('unreachable')
|
||||
}
|
||||
|
||||
function stringToCharSet(charset: string): CharSet {
|
||||
let set: CharSet = { ranges: [], len: 0 }
|
||||
let start: string | null = null
|
||||
let end: string | null = null
|
||||
let in_range = false
|
||||
for (let char of charset) {
|
||||
switch (char) {
|
||||
case ',':
|
||||
if (start !== null && end !== null) {
|
||||
if (start!.charCodeAt(0) > end!.charCodeAt(0)) {
|
||||
throw new Error('start > end of charset')
|
||||
}
|
||||
const len = end.charCodeAt(0) - start.charCodeAt(0) + 1
|
||||
set.ranges.push({
|
||||
start,
|
||||
end,
|
||||
len,
|
||||
})
|
||||
set.len += len
|
||||
start = null
|
||||
end = null
|
||||
in_range = false
|
||||
} else if (start !== null && !in_range) {
|
||||
set.len += 1
|
||||
set.ranges.push({ start, end: start, len: 1 })
|
||||
start = null
|
||||
} else if (start !== null && in_range) {
|
||||
end = ','
|
||||
} else if (start === null && end === null && !in_range) {
|
||||
start = ','
|
||||
} else {
|
||||
throw new Error('unexpected ","')
|
||||
}
|
||||
break
|
||||
case '-':
|
||||
if (start === null) {
|
||||
start = '-'
|
||||
} else if (!in_range) {
|
||||
in_range = true
|
||||
} else if (in_range && end === null) {
|
||||
end = '-'
|
||||
} else {
|
||||
throw new Error('unexpected "-"')
|
||||
}
|
||||
break
|
||||
default:
|
||||
if (start === null) {
|
||||
start = char
|
||||
} else if (in_range && end === null) {
|
||||
end = char
|
||||
} else {
|
||||
throw new Error(`unexpected "${char}"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (start !== null && end !== null) {
|
||||
if (start!.charCodeAt(0) > end!.charCodeAt(0)) {
|
||||
throw new Error('start > end of charset')
|
||||
}
|
||||
const len = end.charCodeAt(0) - start.charCodeAt(0) + 1
|
||||
set.ranges.push({
|
||||
start,
|
||||
end,
|
||||
len,
|
||||
})
|
||||
set.len += len
|
||||
} else if (start !== null) {
|
||||
set.len += 1
|
||||
set.ranges.push({
|
||||
start,
|
||||
end: start,
|
||||
len: 1,
|
||||
})
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
interface CharSet {
|
||||
ranges: {
|
||||
start: string
|
||||
end: string
|
||||
len: number
|
||||
}[]
|
||||
len: number
|
||||
}
|
||||
9
web/projects/ui/src/app/utils/configBuilderToSpec.ts
Normal file
9
web/projects/ui/src/app/utils/configBuilderToSpec.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { CB } from '@start9labs/start-sdk'
|
||||
|
||||
export async function configBuilderToSpec(
|
||||
builder:
|
||||
| CB.Config<Record<string, unknown>, unknown>
|
||||
| CB.Config<Record<string, unknown>, never>,
|
||||
) {
|
||||
return builder.build({} as any)
|
||||
}
|
||||
18
web/projects/ui/src/app/utils/dry-update.ts
Normal file
18
web/projects/ui/src/app/utils/dry-update.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Emver } from '@start9labs/shared'
|
||||
import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
import { getManifest } from './get-package-data'
|
||||
|
||||
export function dryUpdate(
|
||||
{ id, version }: { id: string; version: string },
|
||||
pkgs: DataModel['packageData'],
|
||||
emver: Emver,
|
||||
): string[] {
|
||||
return Object.values(pkgs)
|
||||
.filter(
|
||||
pkg =>
|
||||
Object.keys(pkg.currentDependencies || {}).some(
|
||||
pkgId => pkgId === id,
|
||||
) && !emver.satisfies(version, pkg.currentDependencies[id].versionSpec),
|
||||
)
|
||||
.map(pkg => getManifest(pkg).title)
|
||||
}
|
||||
59
web/projects/ui/src/app/utils/get-package-data.ts
Normal file
59
web/projects/ui/src/app/utils/get-package-data.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
import {
|
||||
DataModel,
|
||||
InstalledState,
|
||||
InstallingState,
|
||||
PackageDataEntry,
|
||||
UpdatingState,
|
||||
} from 'src/app/services/patch-db/data-model'
|
||||
import { firstValueFrom } from 'rxjs'
|
||||
import { T } from '@start9labs/start-sdk'
|
||||
|
||||
export async function getPackage(
|
||||
patch: PatchDB<DataModel>,
|
||||
id: string,
|
||||
): Promise<PackageDataEntry | undefined> {
|
||||
return firstValueFrom(patch.watch$('packageData', id))
|
||||
}
|
||||
|
||||
export async function getAllPackages(
|
||||
patch: PatchDB<DataModel>,
|
||||
): Promise<DataModel['packageData']> {
|
||||
return firstValueFrom(patch.watch$('packageData'))
|
||||
}
|
||||
|
||||
export function getManifest(pkg: PackageDataEntry): T.Manifest {
|
||||
return isInstalling(pkg)
|
||||
? pkg.stateInfo.installingInfo.newManifest
|
||||
: pkg.stateInfo.manifest!
|
||||
}
|
||||
|
||||
export function isInstalled(
|
||||
pkg: PackageDataEntry,
|
||||
): pkg is PackageDataEntry<InstalledState> {
|
||||
return pkg.stateInfo.state === 'installed'
|
||||
}
|
||||
|
||||
export function isRemoving(
|
||||
pkg: PackageDataEntry,
|
||||
): pkg is PackageDataEntry<InstalledState> {
|
||||
return pkg.stateInfo.state === 'removing'
|
||||
}
|
||||
|
||||
export function isInstalling(
|
||||
pkg: PackageDataEntry,
|
||||
): pkg is PackageDataEntry<InstallingState> {
|
||||
return pkg.stateInfo.state === 'installing'
|
||||
}
|
||||
|
||||
export function isRestoring(
|
||||
pkg: PackageDataEntry,
|
||||
): pkg is PackageDataEntry<InstallingState> {
|
||||
return pkg.stateInfo.state === 'restoring'
|
||||
}
|
||||
|
||||
export function isUpdating(
|
||||
pkg: PackageDataEntry,
|
||||
): pkg is PackageDataEntry<UpdatingState> {
|
||||
return pkg.stateInfo.state === 'updating'
|
||||
}
|
||||
9
web/projects/ui/src/app/utils/get-server-info.ts
Normal file
9
web/projects/ui/src/app/utils/get-server-info.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
import { DataModel, ServerInfo } from 'src/app/services/patch-db/data-model'
|
||||
import { firstValueFrom } from 'rxjs'
|
||||
|
||||
export async function getServerInfo(
|
||||
patch: PatchDB<DataModel>,
|
||||
): Promise<ServerInfo> {
|
||||
return firstValueFrom(patch.watch$('serverInfo'))
|
||||
}
|
||||
8
web/projects/ui/src/app/utils/has-deps.ts
Normal file
8
web/projects/ui/src/app/utils/has-deps.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { PackageDataEntry } from 'src/app/services/patch-db/data-model'
|
||||
|
||||
export function hasCurrentDeps(
|
||||
id: string,
|
||||
pkgs: Record<string, PackageDataEntry>,
|
||||
): boolean {
|
||||
return !!Object.values(pkgs).some(pkg => !!pkg.currentDependencies[id])
|
||||
}
|
||||
3
web/projects/ui/src/app/utils/mask.ts
Normal file
3
web/projects/ui/src/app/utils/mask.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function mask(val: string, max: number = Infinity): string {
|
||||
return '●'.repeat(Math.min(max, val.length))
|
||||
}
|
||||
31
web/projects/ui/src/app/utils/system-utilities.ts
Normal file
31
web/projects/ui/src/app/utils/system-utilities.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export const SYSTEM_UTILITIES: Record<string, { icon: string; title: string }> =
|
||||
{
|
||||
'/portal/system/backups': {
|
||||
icon: 'tuiIconSave',
|
||||
title: 'Backups',
|
||||
},
|
||||
'/portal/system/logs': {
|
||||
icon: 'tuiIconFileText',
|
||||
title: 'Logs',
|
||||
},
|
||||
'/portal/system/marketplace': {
|
||||
icon: 'tuiIconShoppingCart',
|
||||
title: 'Marketplace',
|
||||
},
|
||||
'/portal/system/updates': {
|
||||
icon: 'tuiIconGlobe',
|
||||
title: 'Updates',
|
||||
},
|
||||
'/portal/system/sideload': {
|
||||
icon: 'tuiIconUpload',
|
||||
title: 'Sideload',
|
||||
},
|
||||
'/portal/system/settings': {
|
||||
icon: 'tuiIconTool',
|
||||
title: 'Settings',
|
||||
},
|
||||
'/portal/system/notifications': {
|
||||
icon: 'tuiIconBell',
|
||||
title: 'Notifications',
|
||||
},
|
||||
}
|
||||
3
web/projects/ui/src/app/utils/to-router-link.ts
Normal file
3
web/projects/ui/src/app/utils/to-router-link.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function toRouterLink(id: string): string {
|
||||
return id.includes('/') ? id : `/portal/service/${id}`
|
||||
}
|
||||
Reference in New Issue
Block a user