remove current-dependents, derive instead

remove pointers from current-dependencies

remove pointers and system pointers from FE
This commit is contained in:
Matt Hill
2023-02-16 20:34:20 -07:00
committed by Aiden McClelland
parent 8ee64d22b3
commit e4d283cc99
12 changed files with 43 additions and 111 deletions

View File

@@ -145,7 +145,7 @@ export class AppConfigPage {
this.saving = true this.saving = true
if (hasCurrentDeps(this.pkg)) { if (await hasCurrentDeps(this.patch, this.pkgId)) {
this.dryConfigure() this.dryConfigure()
} else { } else {
this.configure() this.configure()

View File

@@ -120,13 +120,13 @@ export class AppActionsPage {
} }
async tryUninstall(pkg: PackageDataEntry): Promise<void> { async tryUninstall(pkg: PackageDataEntry): Promise<void> {
const { title, alerts } = pkg.manifest const { title, alerts, id } = pkg.manifest
let message = let message =
alerts.uninstall || alerts.uninstall ||
`Uninstalling ${title} will permanently delete its data` `Uninstalling ${title} will permanently delete its data`
if (hasCurrentDeps(pkg)) { if (await hasCurrentDeps(this.patch, id)) {
message = `${message}. Services that depend on ${title} will no longer work properly and may crash` message = `${message}. Services that depend on ${title} will no longer work properly and may crash`
} }

View File

@@ -6,6 +6,7 @@ import {
PrimaryStatus, PrimaryStatus,
} from 'src/app/services/pkg-status-rendering.service' } from 'src/app/services/pkg-status-rendering.service'
import { import {
DataModel,
InterfaceDef, InterfaceDef,
PackageDataEntry, PackageDataEntry,
PackageState, PackageState,
@@ -18,6 +19,7 @@ import { ModalService } from 'src/app/services/modal.service'
import { DependencyInfo } from '../../pipes/to-dependencies.pipe' import { DependencyInfo } from '../../pipes/to-dependencies.pipe'
import { hasCurrentDeps } from 'src/app/util/has-deps' import { hasCurrentDeps } from 'src/app/util/has-deps'
import { ConnectionService } from 'src/app/services/connection.service' import { ConnectionService } from 'src/app/services/connection.service'
import { PatchDB } from 'patch-db-client'
@Component({ @Component({
selector: 'app-show-status', selector: 'app-show-status',
@@ -47,8 +49,13 @@ export class AppShowStatusComponent {
private readonly launcherService: UiLauncherService, private readonly launcherService: UiLauncherService,
private readonly modalService: ModalService, private readonly modalService: ModalService,
private readonly connectionService: ConnectionService, private readonly connectionService: ConnectionService,
private readonly patch: PatchDB<DataModel>,
) {} ) {}
private get id(): string {
return this.pkg.manifest.id
}
get interfaces(): Record<string, InterfaceDef> { get interfaces(): Record<string, InterfaceDef> {
return this.pkg.manifest.interfaces || {} return this.pkg.manifest.interfaces || {}
} }
@@ -99,10 +106,10 @@ export class AppShowStatusComponent {
} }
async tryStop(): Promise<void> { async tryStop(): Promise<void> {
const { title, alerts } = this.pkg.manifest const { title, alerts, id } = this.pkg.manifest
let message = alerts.stop || '' let message = alerts.stop || ''
if (hasCurrentDeps(this.pkg)) { if (await hasCurrentDeps(this.patch, id)) {
const depMessage = `Services that depend on ${title} will no longer work properly and may crash` const depMessage = `Services that depend on ${title} will no longer work properly and may crash`
message = message ? `${message}.\n\n${depMessage}` : depMessage message = message ? `${message}.\n\n${depMessage}` : depMessage
} }
@@ -134,10 +141,12 @@ export class AppShowStatusComponent {
} }
async tryRestart(): Promise<void> { async tryRestart(): Promise<void> {
if (hasCurrentDeps(this.pkg)) { const { id, title } = this.pkg.manifest
if (await hasCurrentDeps(this.patch, id)) {
const alert = await this.alertCtrl.create({ const alert = await this.alertCtrl.create({
header: 'Warning', header: 'Warning',
message: `Services that depend on ${this.pkg.manifest.title} may temporarily experiences issues`, message: `Services that depend on ${title} may temporarily experiences issues`,
buttons: [ buttons: [
{ {
text: 'Cancel', text: 'Cancel',
@@ -160,10 +169,6 @@ export class AppShowStatusComponent {
} }
} }
private get id(): string {
return this.pkg.manifest.id
}
private async start(): Promise<void> { private async start(): Promise<void> {
const loader = await this.loadingCtrl.create({ const loader = await this.loadingCtrl.create({
message: `Starting...`, message: `Starting...`,

View File

@@ -2,8 +2,8 @@ import { Pipe, PipeTransform } from '@angular/core'
import { NavigationExtras } from '@angular/router' import { NavigationExtras } from '@angular/router'
import { NavController } from '@ionic/angular' import { NavController } from '@ionic/angular'
import { import {
DependencyError,
DependencyErrorType, DependencyErrorType,
InstalledPackageDataEntry,
PackageDataEntry, PackageDataEntry,
} from 'src/app/services/patch-db/data-model' } from 'src/app/services/patch-db/data-model'
import { DependentInfo } from 'src/app/types/dependent-info' import { DependentInfo } from 'src/app/types/dependent-info'
@@ -31,24 +31,21 @@ export class ToDependenciesPipe implements PipeTransform {
transform(pkg: PackageDataEntry): DependencyInfo[] { transform(pkg: PackageDataEntry): DependencyInfo[] {
if (!pkg.installed) return [] if (!pkg.installed) return []
return Object.keys(pkg.installed?.['current-dependencies']) return Object.keys(pkg.installed['current-dependencies'])
.filter(id => !!pkg.manifest.dependencies[id]) .filter(id => !!pkg.manifest.dependencies[id])
.map(id => .map(id => this.setDepValues(pkg.installed!, id))
this.setDepValues(pkg, id, pkg.installed!.status['dependency-errors']),
)
} }
private setDepValues( private setDepValues(
pkg: PackageDataEntry, pkg: InstalledPackageDataEntry,
id: string, id: string,
errors: { [id: string]: DependencyError | null },
): DependencyInfo { ): DependencyInfo {
let errorText = '' let errorText = ''
let actionText = 'View' let actionText = 'View'
let action: () => any = () => let action: () => any = () =>
this.navCtrl.navigateForward(`/services/${id}`) this.navCtrl.navigateForward(`/services/${id}`)
const error = errors[id] const error = pkg.status['dependency-errors'][id]
if (error) { if (error) {
// health checks failed // health checks failed
@@ -84,7 +81,7 @@ export class ToDependenciesPipe implements PipeTransform {
errorText = `${errorText}. ${pkg.manifest.title} will not work as expected.` errorText = `${errorText}. ${pkg.manifest.title} will not work as expected.`
} }
const depInfo = pkg.installed?.['dependency-info'][id] const depInfo = pkg['dependency-info'][id]
return { return {
id, id,
@@ -98,7 +95,7 @@ export class ToDependenciesPipe implements PipeTransform {
} }
async fixDep( async fixDep(
pkg: PackageDataEntry, pkg: InstalledPackageDataEntry,
action: 'install' | 'update' | 'configure', action: 'install' | 'update' | 'configure',
id: string, id: string,
): Promise<void> { ): Promise<void> {
@@ -112,7 +109,7 @@ export class ToDependenciesPipe implements PipeTransform {
} }
private async installDep( private async installDep(
pkg: PackageDataEntry, pkg: InstalledPackageDataEntry,
depId: string, depId: string,
): Promise<void> { ): Promise<void> {
const version = pkg.manifest.dependencies[depId].version const version = pkg.manifest.dependencies[depId].version
@@ -133,7 +130,7 @@ export class ToDependenciesPipe implements PipeTransform {
} }
private async configureDep( private async configureDep(
pkg: PackageDataEntry, pkg: InstalledPackageDataEntry,
dependencyId: string, dependencyId: string,
): Promise<void> { ): Promise<void> {
const dependentInfo: DependentInfo = { const dependentInfo: DependentInfo = {

View File

@@ -84,11 +84,10 @@ export class MarketplaceShowControlsComponent {
if (!proceed) return if (!proceed) return
} }
if ( const { id, version } = this.pkg.manifest
this.emver.compare(this.localVersion, this.pkg.manifest.version) !==
0 && const currentDeps = await hasCurrentDeps(this.patch, id)
hasCurrentDeps(this.localPkg) if (currentDeps && this.emver.compare(this.localVersion, version) !== 0) {
) {
this.dryInstall(url) this.dryInstall(url)
} else { } else {
this.install(url) this.install(url)

View File

@@ -76,7 +76,7 @@ export class UpdatesPage {
delete this.marketplaceService.updateErrors[id] delete this.marketplaceService.updateErrors[id]
this.marketplaceService.updateQueue[id] = true this.marketplaceService.updateQueue[id] = true
if (hasCurrentDeps(local)) { if (await hasCurrentDeps(this.patch, local.manifest.id)) {
this.dryUpdate(manifest, url) this.dryUpdate(manifest, url)
} else { } else {
this.update(id, version, url) this.update(id, version, url)

View File

@@ -7,7 +7,6 @@ export type ValueType =
| 'enum' | 'enum'
| 'list' | 'list'
| 'object' | 'object'
| 'pointer'
| 'union' | 'union'
export type ValueSpec = ValueSpecOf<ValueType> export type ValueSpec = ValueSpecOf<ValueType>
@@ -24,8 +23,6 @@ export type ValueSpecOf<T extends ValueType> = T extends 'string'
? ValueSpecList ? ValueSpecList
: T extends 'object' : T extends 'object'
? ValueSpecObject ? ValueSpecObject
: T extends 'pointer'
? ValueSpecPointer
: T extends 'union' : T extends 'union'
? ValueSpecUnion ? ValueSpecUnion
: never : never
@@ -60,16 +57,6 @@ export interface ValueSpecUnion {
default: string default: string
} }
export interface ValueSpecPointer extends WithStandalone {
type: 'pointer'
subtype: 'package' | 'system'
'package-id': string
target: 'lan-address' | 'tor-address' | 'config' | 'tor-key'
interface: string // will only exist if target = tor-key || tor-address || lan-address
selector?: string // will only exist if target = config
multi?: boolean // will only exist if target = config
}
export interface ValueSpecObject extends WithStandalone { export interface ValueSpecObject extends WithStandalone {
type: 'object' type: 'object'
spec: ConfigSpec spec: ConfigSpec
@@ -81,7 +68,7 @@ export interface WithStandalone {
warning?: string warning?: string
} }
// no lists of booleans, lists, pointers // no lists of booleans or lists
export type ListValueSpecType = export type ListValueSpecType =
| 'string' | 'string'
| 'number' | 'number'

View File

@@ -309,15 +309,6 @@ export module Mock {
}, },
variants: { variants: {
internal: { internal: {
'lan-address': {
name: 'LAN Address',
type: 'pointer',
subtype: 'package',
target: 'lan-address',
description: 'the lan address',
interface: 'tor-address',
'package-id': '12341234',
},
'friendly-name': { 'friendly-name': {
name: 'Friendly Name', name: 'Friendly Name',
type: 'string', type: 'string',
@@ -1548,17 +1539,7 @@ export module Mock {
warning: 'Careful changing this', warning: 'Careful changing this',
}, },
variants: { variants: {
internal: { internal: {},
'lan-address': {
name: 'LAN Address',
type: 'pointer',
subtype: 'package',
target: 'lan-address',
'package-id': 'bitcoind',
description: 'the lan address',
interface: 'asdf',
},
},
external: { external: {
'emergency-contact': { 'emergency-contact': {
name: 'Emergency Contact', name: 'Emergency Contact',
@@ -1904,13 +1885,6 @@ export module Mock {
'lan-address': 'bitcoind-p2p-address.local', 'lan-address': 'bitcoind-p2p-address.local',
}, },
}, },
'system-pointers': [],
'current-dependents': {
lnd: {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': {}, 'current-dependencies': {},
'dependency-info': {}, 'dependency-info': {},
'marketplace-url': 'https://registry.start9.com/', 'marketplace-url': 'https://registry.start9.com/',
@@ -1943,16 +1917,8 @@ export module Mock {
'lan-address': 'bitcoinproxy-rpc-address.local', 'lan-address': 'bitcoinproxy-rpc-address.local',
}, },
}, },
'system-pointers': [],
'current-dependents': {
lnd: {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': { 'current-dependencies': {
bitcoind: { bitcoind: {
pointers: [],
'health-checks': [], 'health-checks': [],
}, },
}, },
@@ -2000,15 +1966,11 @@ export module Mock {
'lan-address': 'lnd-grpc-address.local', 'lan-address': 'lnd-grpc-address.local',
}, },
}, },
'system-pointers': [],
'current-dependents': {},
'current-dependencies': { 'current-dependencies': {
bitcoind: { bitcoind: {
pointers: [],
'health-checks': [], 'health-checks': [],
}, },
'btc-rpc-proxy': { 'btc-rpc-proxy': {
pointers: [],
'health-checks': [], 'health-checks': [],
}, },
}, },

View File

@@ -369,15 +369,6 @@ export const mockPatchData: DataModel = {
}, },
variants: { variants: {
internal: { internal: {
'lan-address': {
name: 'LAN Address',
type: 'pointer',
subtype: 'package',
target: 'lan-address',
'package-id': 'bitcoind',
description: 'the lan address',
interface: '',
},
'friendly-name': { 'friendly-name': {
name: 'Friendly Name', name: 'Friendly Name',
type: 'string', type: 'string',
@@ -454,13 +445,6 @@ export const mockPatchData: DataModel = {
'lan-address': 'bitcoind-p2p-address.local', 'lan-address': 'bitcoind-p2p-address.local',
}, },
}, },
'system-pointers': [],
'current-dependents': {
lnd: {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': {}, 'current-dependencies': {},
'dependency-info': {}, 'dependency-info': {},
'marketplace-url': 'https://registry.start9.com/', 'marketplace-url': 'https://registry.start9.com/',
@@ -654,15 +638,11 @@ export const mockPatchData: DataModel = {
'lan-address': 'lnd-grpc-address.local', 'lan-address': 'lnd-grpc-address.local',
}, },
}, },
'system-pointers': [],
'current-dependents': {},
'current-dependencies': { 'current-dependencies': {
bitcoind: { bitcoind: {
pointers: [],
'health-checks': [], 'health-checks': [],
}, },
'btc-rpc-proxy': { 'btc-rpc-proxy': {
pointers: [],
'health-checks': [], 'health-checks': [],
}, },
}, },

View File

@@ -89,7 +89,6 @@ export class FormService {
UntypedFormGroup | UntypedFormArray | UntypedFormControl UntypedFormGroup | UntypedFormArray | UntypedFormControl
> = {} > = {}
Object.entries(config).map(([key, spec]) => { Object.entries(config).map(([key, spec]) => {
if (spec.type === 'pointer') return
group[key] = this.getFormEntry(spec, current ? current[key] : undefined) group[key] = this.getFormEntry(spec, current ? current[key] : undefined)
}) })
return this.formBuilder.group(group, { validators }) return this.formBuilder.group(group, { validators })

View File

@@ -127,8 +127,6 @@ export interface InstalledPackageDataEntry {
status: Status status: Status
manifest: Manifest manifest: Manifest
'last-backup': string | null 'last-backup': string | null
'system-pointers': any[]
'current-dependents': { [id: string]: CurrentDependencyInfo }
'current-dependencies': { [id: string]: CurrentDependencyInfo } 'current-dependencies': { [id: string]: CurrentDependencyInfo }
'dependency-info': { 'dependency-info': {
[id: string]: { [id: string]: {
@@ -144,7 +142,6 @@ export interface InstalledPackageDataEntry {
} }
export interface CurrentDependencyInfo { export interface CurrentDependencyInfo {
pointers: any[]
'health-checks': string[] // array of health check IDs 'health-checks': string[] // array of health check IDs
} }

View File

@@ -1,7 +1,13 @@
import { PackageDataEntry } from '../services/patch-db/data-model' import { PatchDB } from 'patch-db-client'
import { DataModel } from '../services/patch-db/data-model'
import { getAllPackages } from './get-package-data'
export function hasCurrentDeps(pkg: PackageDataEntry): boolean { export async function hasCurrentDeps(
return !!Object.keys(pkg.installed?.['current-dependents'] || {}).filter( patch: PatchDB<DataModel>,
depId => depId !== pkg.manifest.id, id: string,
).length ): Promise<boolean> {
const pkgs = await getAllPackages(patch)
return !!Object.keys(pkgs)
.filter(pkgId => pkgId !== id)
.find(pkgId => pkgs[pkgId].installed?.['current-dependencies'][pkgId])
} }