mirror of
https://github.com/ComposioHQ/composio.git
synced 2026-09-22 11:46:35 +08:00
73570901f2
Co-authored-by: jkomyno <12381818+jkomyno@users.noreply.github.com>
31 lines
732 B
TypeScript
31 lines
732 B
TypeScript
import type { BasicBuilder } from './BasicBuilder';
|
|
import { TypeContext } from './OperatorPrecedence';
|
|
import { TypeBuilder } from './TypeBuilder';
|
|
import { Writer } from './Writer';
|
|
|
|
export class Parameter implements BasicBuilder {
|
|
private isOptional = false;
|
|
constructor(
|
|
private name: string,
|
|
private type: TypeBuilder
|
|
) {}
|
|
|
|
optional(): this {
|
|
this.isOptional = true;
|
|
return this;
|
|
}
|
|
|
|
write(writer: Writer): void {
|
|
writer.write(this.name);
|
|
if (this.isOptional) {
|
|
writer.write('?');
|
|
}
|
|
writer.write(': ');
|
|
this.type.writeInContext(writer, TypeContext.FunctionParameter);
|
|
}
|
|
}
|
|
|
|
export function parameter(name: string, type: TypeBuilder) {
|
|
return new Parameter(name, type);
|
|
}
|