Files
privacy.sexy/tests/unit/shared/Stubs/SharedFunctionCollectionStub.ts
undergroundwires c138f74460 Refactor to unify scripts/categories as Executable
This commit consolidates scripts and categories under a unified
'Executable' concept. This simplifies the architecture and improves code
readability.

- Introduce subfolders within `src/domain` to segregate domain elements.
- Update class and interface names by removing the 'I' prefix in
  alignment with new coding standards.
- Replace 'Node' with 'Executable' to clarify usage; reserve 'Node'
  exclusively for the UI's tree component.
2024-06-12 12:36:40 +02:00

34 lines
1.2 KiB
TypeScript

import type { ISharedFunction } from '@/application/Parser/Executable/Script/Compiler/Function/ISharedFunction';
import type { ISharedFunctionCollection } from '@/application/Parser/Executable/Script/Compiler/Function/ISharedFunctionCollection';
import { createSharedFunctionStubWithCode } from './SharedFunctionStub';
export class SharedFunctionCollectionStub implements ISharedFunctionCollection {
private readonly functions = new Map<string, ISharedFunction>();
public withFunctions(...funcs: readonly ISharedFunction[]): this {
for (const func of funcs) {
this.functions.set(func.name, func);
}
return this;
}
public getFunctionByName(name: string): ISharedFunction {
const foundFunction = this.functions.get(name);
if (foundFunction) {
return foundFunction;
}
return createSharedFunctionStubWithCode()
.withName(name)
.withCode('code by SharedFunctionCollectionStub')
.withRevertCode('revert-code by SharedFunctionCollectionStub');
}
public getRequiredParameterNames(functionName: string): string[] {
return this.getFunctionByName(functionName)
.parameters
.all
.filter((p) => !p.isOptional)
.map((p) => p.name);
}
}