diff --git a/src/shared/XmlParser.ts b/src/shared/XmlParser.ts index 56b5569..ba07ef5 100644 --- a/src/shared/XmlParser.ts +++ b/src/shared/XmlParser.ts @@ -1,6 +1,7 @@ import * as xml2js from 'xml2js'; import * as Metadata from '../types/metadata.js'; import { Named, FullNamed, ObjectNamed } from '../types/metadata-addon.js'; +import { arraynge } from './arraynge.js'; const nameRegEx = new RegExp('.+/([^.]*)'); const parserOptions: xml2js.ParserOptions = { @@ -74,7 +75,7 @@ export class XmlParser { const objectName = nameRegEx.exec(fileName)?.[1] as string; // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access xml2js.parseString(xml, parserOptions, (err, result: { Workflow: Metadata.Workflow }) => { - for (const thisRule of result.Workflow.rules as Array>>) { + for (const thisRule of arraynge(result.Workflow.rules) as Array>>) { thisRule.objectName = objectName; workflowRules.push(thisRule); } diff --git a/src/shared/arraynge.ts b/src/shared/arraynge.ts new file mode 100644 index 0000000..e0a42eb --- /dev/null +++ b/src/shared/arraynge.ts @@ -0,0 +1,7 @@ +export function arraynge(input: Type | Type[] | undefined): Type[] { + if (input === undefined) { + return []; + } + + return Array.isArray(input) ? input : [input]; +}