Rework PackageDataEntry for new strategy (#2573)

* rework PackageDataEntry for new strategy

* fix type error

* fix issues with manifest fetching

* mock installs working
This commit is contained in:
Matt Hill
2024-03-19 08:38:04 -06:00
committed by GitHub
parent c8be701f0e
commit cc38dab76f
64 changed files with 1759 additions and 2068 deletions

View File

@@ -4,12 +4,14 @@ import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators'
import { PatchDB } from 'patch-db-client'
import {
DataModel,
HealthCheckResult,
HealthResult,
InstalledPackageDataEntry,
InstalledState,
PackageDataEntry,
PackageMainStatus,
PackageState,
} from './patch-db/data-model'
import * as deepEqual from 'fast-deep-equal'
import { isInstalled } from '../util/get-package-data'
export type AllDependencyErrors = Record<string, PkgDependencyErrors>
export type PkgDependencyErrors = Record<string, DependencyError | null>
@@ -55,14 +57,14 @@ export class DepErrorService {
pkgId: string,
outerErrors: AllDependencyErrors,
): PkgDependencyErrors {
const pkgInstalled = pkgs[pkgId].installed
const pkg = pkgs[pkgId]
if (!pkgInstalled) return {}
if (!isInstalled(pkg)) return {}
return currentDeps(pkgs, pkgId).reduce(
(innerErrors, depId): PkgDependencyErrors => ({
...innerErrors,
[depId]: this.getDepError(pkgs, pkgInstalled, depId, outerErrors),
[depId]: this.getDepError(pkgs, pkg, depId, outerErrors),
}),
{} as PkgDependencyErrors,
)
@@ -70,21 +72,21 @@ export class DepErrorService {
private getDepError(
pkgs: DataModel['package-data'],
pkgInstalled: InstalledPackageDataEntry,
pkg: PackageDataEntry<InstalledState>,
depId: string,
outerErrors: AllDependencyErrors,
): DependencyError | null {
const depInstalled = pkgs[depId]?.installed
const dep = pkgs[depId]
// not installed
if (!depInstalled) {
if (!dep || dep['state-info'].state !== PackageState.Installed) {
return {
type: DependencyErrorType.NotInstalled,
}
}
const pkgManifest = pkgInstalled.manifest
const depManifest = depInstalled.manifest
const pkgManifest = pkg['state-info'].manifest
const depManifest = dep['state-info'].manifest
// incorrect version
if (
@@ -102,16 +104,14 @@ export class DepErrorService {
// invalid config
if (
Object.values(pkgInstalled.status['dependency-config-errors']).some(
err => !!err,
)
Object.values(pkg.status['dependency-config-errors']).some(err => !!err)
) {
return {
type: DependencyErrorType.ConfigUnsatisfied,
}
}
const depStatus = depInstalled.status.main.status
const depStatus = dep.status.main.status
// not running
if (
@@ -125,12 +125,8 @@ export class DepErrorService {
// health check failure
if (depStatus === PackageMainStatus.Running) {
for (let id of pkgInstalled['current-dependencies'][depId][
'health-checks'
]) {
if (
depInstalled.status.main.health[id]?.result !== HealthResult.Success
) {
for (let id of pkg['current-dependencies'][depId]['health-checks']) {
if (dep.status.main.health[id]?.result !== HealthResult.Success) {
return {
type: DependencyErrorType.HealthChecksFailed,
}
@@ -154,9 +150,9 @@ export class DepErrorService {
}
function currentDeps(pkgs: DataModel['package-data'], id: string): string[] {
return Object.keys(
pkgs[id]?.installed?.['current-dependencies'] || {},
).filter(depId => depId !== id)
return Object.keys(pkgs[id]?.['current-dependencies'] || {}).filter(
depId => depId !== id,
)
}
function dependencyDepth(