mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
more
This commit is contained in:
33
src/utils/objects.ts
Normal file
33
src/utils/objects.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
const isDeepSubset = (actual: ExpectedAny, expected: ExpectedAny): boolean => {
|
||||
if (typeof expected !== 'object' || expected === null) {
|
||||
return actual === expected;
|
||||
}
|
||||
|
||||
if (typeof actual !== 'object' || actual === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(expected)) {
|
||||
if (!Array.isArray(actual)) {
|
||||
return false;
|
||||
}
|
||||
return expected.every((expectedItem) => actual.some((actualItem) => isDeepSubset(actualItem, expectedItem)));
|
||||
}
|
||||
|
||||
// Iterate over the keys of the expected object
|
||||
for (const key in expected) {
|
||||
if (Object.prototype.hasOwnProperty.call(expected, key)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(actual, key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isDeepSubset(actual[key], expected[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export { isDeepSubset };
|
||||
@@ -9,4 +9,12 @@ const decodeSecret = <T extends Record<string, string>>(
|
||||
) as T;
|
||||
};
|
||||
|
||||
export { decodeSecret };
|
||||
const encodeSecret = <T extends Record<string, string>>(data: T | undefined): Record<string, string> | undefined => {
|
||||
if (!data) {
|
||||
return undefined;
|
||||
}
|
||||
return Object.fromEntries(
|
||||
Object.entries(data).map(([name, value]) => [name, Buffer.from(value, 'utf8').toString('base64')]),
|
||||
);
|
||||
};
|
||||
export { decodeSecret, encodeSecret };
|
||||
|
||||
Reference in New Issue
Block a user