mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-18 23:09:59 +00:00
28 lines
665 B
TypeScript
28 lines
665 B
TypeScript
![]() |
import { Not } from "../utils";
|
||
|
|
||
|
const scalarTypes = ["string", "number", "boolean", "bigint"];
|
||
|
|
||
|
export class ObjectAliasError extends Error {}
|
||
|
|
||
|
/**
|
||
|
* Removes object aliases/anchors from a loaded YAML object
|
||
|
*/
|
||
|
export function validateNoObjectAliases<T extends {}>(obj: T, seen?: WeakSet<any>): void {
|
||
|
if (!seen) {
|
||
|
seen = new WeakSet();
|
||
|
}
|
||
|
|
||
|
for (const [key, value] of Object.entries(obj)) {
|
||
|
if (value == null || scalarTypes.includes(typeof value)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (seen.has(value)) {
|
||
|
throw new ObjectAliasError("Object aliases are not allowed");
|
||
|
}
|
||
|
|
||
|
validateNoObjectAliases(value as {}, seen);
|
||
|
seen.add(value);
|
||
|
}
|
||
|
}
|