mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
chore: Add in the ability to remove the bad sections?
This commit is contained in:
@@ -826,9 +826,11 @@ export class SystemForEmbassy implements System {
|
|||||||
}
|
}
|
||||||
async function removePointers(value: T.ConfigRes): Promise<T.ConfigRes> {
|
async function removePointers(value: T.ConfigRes): Promise<T.ConfigRes> {
|
||||||
const startingSpec = structuredClone(value.spec)
|
const startingSpec = structuredClone(value.spec)
|
||||||
|
const config =
|
||||||
|
value.config && cleanConfigFromPointers(value.config, startingSpec)
|
||||||
const spec = cleanSpecOfPointers(startingSpec)
|
const spec = cleanSpecOfPointers(startingSpec)
|
||||||
|
|
||||||
return { ...value, spec }
|
return { config, spec }
|
||||||
}
|
}
|
||||||
|
|
||||||
const matchPointer = object({
|
const matchPointer = object({
|
||||||
@@ -871,6 +873,44 @@ function cleanSpecOfPointers<T>(mutSpec: T): T {
|
|||||||
|
|
||||||
return mutSpec
|
return mutSpec
|
||||||
}
|
}
|
||||||
|
function isKeyOf<O extends object>(
|
||||||
|
key: string,
|
||||||
|
ofObject: O,
|
||||||
|
): key is keyof O & string {
|
||||||
|
return key in ofObject
|
||||||
|
}
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
type CleanConfigFromPointers<C, S> =
|
||||||
|
[C, S] extends [object, object] ? {
|
||||||
|
[K in (keyof C & keyof S ) & string]: (
|
||||||
|
S[K] extends {type: "pointer"} ? never :
|
||||||
|
S[K] extends {spec: object & infer B} ? CleanConfigFromPointers<C[K], B> :
|
||||||
|
C[K]
|
||||||
|
)
|
||||||
|
} :
|
||||||
|
null
|
||||||
|
|
||||||
|
function cleanConfigFromPointers<C, S>(
|
||||||
|
config: C,
|
||||||
|
spec: S,
|
||||||
|
): CleanConfigFromPointers<C, S> {
|
||||||
|
const newConfig = {} as CleanConfigFromPointers<C, S>
|
||||||
|
|
||||||
|
if (!(object.test(config) && object.test(spec)) || newConfig == null)
|
||||||
|
return null as CleanConfigFromPointers<C, S>
|
||||||
|
|
||||||
|
for (const key of Object.keys(spec)) {
|
||||||
|
if (!isKeyOf(key, spec)) continue
|
||||||
|
if (!isKeyOf(key, config)) continue
|
||||||
|
const partSpec = spec[key]
|
||||||
|
if (matchPointer.test(partSpec)) continue
|
||||||
|
;(newConfig as any)[key] = matchSpec.test(partSpec)
|
||||||
|
? cleanConfigFromPointers(config[key], partSpec.spec)
|
||||||
|
: config[key]
|
||||||
|
}
|
||||||
|
return newConfig as CleanConfigFromPointers<C, S>
|
||||||
|
}
|
||||||
|
|
||||||
async function updateConfig(
|
async function updateConfig(
|
||||||
effects: HostSystemStartOs,
|
effects: HostSystemStartOs,
|
||||||
|
|||||||
Reference in New Issue
Block a user