Skip to content

Commit

Permalink
chore: Add in the ability to remove the bad sections?
Browse files Browse the repository at this point in the history
  • Loading branch information
Blu-J committed Feb 23, 2024
1 parent 3bd7596 commit 4e3075a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,11 @@ export class SystemForEmbassy implements System {
}
async function removePointers(value: T.ConfigRes): Promise<T.ConfigRes> {
const startingSpec = structuredClone(value.spec)
const config =
value.config && cleanConfigFromPointers(value.config, startingSpec)
const spec = cleanSpecOfPointers(startingSpec)

return { ...value, spec }
return { config, spec }
}

const matchPointer = object({
Expand Down Expand Up @@ -871,6 +873,44 @@ function cleanSpecOfPointers<T>(mutSpec: T): T {

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(
effects: HostSystemStartOs,
Expand Down

0 comments on commit 4e3075a

Please sign in to comment.