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

next
ts 41 lines 1.17 KB
Raw
1 import type { AnyDeclarationBuilder } from './AnyDeclarationBuilder';
2 import type { BasicBuilder } from './BasicBuilder';
3 import type { DocSectionComment } from './DocSectionComment';
4 import { Export } from './Export';
5 import type { ExportFrom } from './ExportFrom';
6 import type { Import } from './Import';
7 import { Writer } from './Writer';
8
9 export type FileItem =
10 AnyDeclarationBuilder | Export<AnyDeclarationBuilder> | ExportFrom | DocSectionComment;
11 export class File implements BasicBuilder {
12 private imports: Import[] = [];
13 private declarations: FileItem[] = [];
14
15 addImport(moduleImport: Import) {
16 this.imports.push(moduleImport);
17 return this;
18 }
19 add(declaration: FileItem) {
20 this.declarations.push(declaration);
21 }
22
23 write(writer: Writer<undefined>): void {
24 for (const moduleImport of this.imports) {
25 writer.writeLine(moduleImport);
26 }
27 if (this.imports.length > 0) {
28 writer.newLine();
29 }
30 for (const [i, declaration] of this.declarations.entries()) {
31 writer.writeLine(declaration);
32 if (i < this.declarations.length - 1) {
33 writer.newLine();
34 }
35 }
36 }
37 }
38
39 export function file(): File {
40 return new File();
41 }