This commit introduces type validation for parameter values within the parser/compiler, aligning with the YAML schema. It aims to eliminate dependencies on side effects in the collection files. This update changes the treatment of data types in the Windows collection, moving away from unintended type casting by the compiler. Previously, numeric and boolean values were used even though only string types were supported. This behavior was unstable and untested, and has now been adjusted to use strings exclusively. Changes ensure that parameter values are correctly validated as strings, enhancing stability and maintainability.
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import type { FunctionCallArgument } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Argument/FunctionCallArgument';
|
|
import type { IFunctionCallArgumentCollection } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Argument/IFunctionCallArgumentCollection';
|
|
import { FunctionCallArgumentStub } from './FunctionCallArgumentStub';
|
|
|
|
export class FunctionCallArgumentCollectionStub implements IFunctionCallArgumentCollection {
|
|
private args = new Array<FunctionCallArgument>();
|
|
|
|
public withEmptyArguments(): this {
|
|
this.args.length = 0;
|
|
return this;
|
|
}
|
|
|
|
public withSomeArguments(): this {
|
|
return this
|
|
.withArgument('firstTestParameterName', 'first-parameter-argument-value')
|
|
.withArgument('secondTestParameterName', 'second-parameter-argument-value')
|
|
.withArgument('thirdTestParameterName', 'third-parameter-argument-value');
|
|
}
|
|
|
|
public withArgument(parameterName: string, argumentValue: string): this {
|
|
const arg = new FunctionCallArgumentStub()
|
|
.withParameterName(parameterName)
|
|
.withArgumentValue(argumentValue);
|
|
this.addArgument(arg);
|
|
return this;
|
|
}
|
|
|
|
public withArguments(args: { readonly [index: string]: string }): this {
|
|
for (const [name, value] of Object.entries(args)) {
|
|
this.withArgument(name, value);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public hasArgument(parameterName: string): boolean {
|
|
return this.args.some((a) => a.parameterName === parameterName);
|
|
}
|
|
|
|
public addArgument(argument: FunctionCallArgument): void {
|
|
this.args.push(argument);
|
|
}
|
|
|
|
public getAllParameterNames(): string[] {
|
|
return this.args.map((a) => a.parameterName);
|
|
}
|
|
|
|
public getArgument(parameterName: string): FunctionCallArgument {
|
|
const arg = this.args.find((a) => a.parameterName === parameterName);
|
|
if (!arg) {
|
|
throw new Error(`no argument exists for parameter "${parameterName}"`);
|
|
}
|
|
return arg;
|
|
}
|
|
}
|