@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Syncing…

next
ts 72 lines 1.75 KB
Raw
1 import { GenericParameter } from './GenericParameter';
2 import { Method } from './Method';
3 import { NamedType } from './NamedType';
4 import { Property } from './Property';
5 import { TypeBuilder } from './TypeBuilder';
6 import { Writer } from './Writer';
7 import { OperatorPrecedence } from './OperatorPrecedence';
8
9 type InterfaceItem = Method | Property;
10
11 export class InterfaceDeclaration extends TypeBuilder {
12 needsParenthesisWhenIndexed = true;
13 readonly precedence = OperatorPrecedence.ObjectType;
14
15 private items: InterfaceItem[] = [];
16 private genericParameters: GenericParameter[] = [];
17 private extendedTypes: NamedType[] = [];
18
19 constructor(readonly name: string) {
20 super();
21 }
22
23 add(item: InterfaceItem): this {
24 this.items.push(item);
25 return this;
26 }
27
28 addMultiple(items: InterfaceItem[]): this {
29 for (const item of items) {
30 this.add(item);
31 }
32 return this;
33 }
34
35 addGenericParameter(param: GenericParameter) {
36 this.genericParameters.push(param);
37 return this;
38 }
39
40 extends(type: NamedType) {
41 this.extendedTypes.push(type);
42 return this;
43 }
44
45 write(writer: Writer): void {
46 writer.write('interface ').write(this.name);
47 if (this.genericParameters.length > 0) {
48 writer.write('<').writeJoined(', ', this.genericParameters).write('>');
49 }
50
51 if (this.extendedTypes.length > 0) {
52 writer.write(' extends ').writeJoined(', ', this.extendedTypes);
53 }
54 if (this.items.length === 0) {
55 writer.writeLine(' {}');
56 return;
57 }
58
59 writer
60 .writeLine(' {')
61 .withIndent(() => {
62 for (const item of this.items) {
63 writer.writeLine(item);
64 }
65 })
66 .write('}');
67 }
68 }
69
70 export function interfaceDeclaration(name: string) {
71 return new InterfaceDeclaration(name);
72 }