@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

Synced Nov 21, 04:45 UTC

next
ts 89 lines 1.95 KB
Raw
1 import type { BasicBuilder } from './BasicBuilder';
2 import { Writer } from './Writer';
3
4 export type ExportFrom = NamespaceExport | BindingsExport | ExportAllFrom;
5
6 export class NamespaceExport implements BasicBuilder {
7 constructor(
8 private from: string,
9 private namespace: string
10 ) {}
11
12 write(writer: Writer<undefined>): void {
13 writer.write(`export * as ${this.namespace} from '${this.from}'`);
14 }
15 }
16
17 export class BindingsExport implements BasicBuilder {
18 private namedExports: NamedExport[] = [];
19 constructor(private from: string) {}
20
21 named(namedExport: string | NamedExport) {
22 if (typeof namedExport === 'string') {
23 namedExport = new NamedExport(namedExport);
24 }
25 this.namedExports.push(namedExport);
26 return this;
27 }
28
29 write(writer: Writer<undefined>): void {
30 writer
31 .write('export ')
32 .write('{ ')
33 .writeJoined(', ', this.namedExports)
34 .write(' }')
35
36 .write(` from "${this.from}"`);
37 }
38 }
39
40 export class NamedExport implements BasicBuilder {
41 private alias: string | undefined;
42 private type = false;
43
44 constructor(readonly name: string) {}
45
46 as(alias: string) {
47 this.alias = alias;
48 return this;
49 }
50
51 typeOnly(): this {
52 this.type = true;
53 return this;
54 }
55
56 write(writer: Writer): void {
57 if (this.type) {
58 writer.write('type ');
59 }
60 writer.write(this.name);
61 if (this.alias) {
62 writer.write(' as ').write(this.alias);
63 }
64 }
65 }
66
67 export class ExportAllFrom implements BasicBuilder {
68 constructor(private from: string) {}
69
70 asNamespace(namespace: string) {
71 return new NamespaceExport(this.from, namespace);
72 }
73
74 named(binding: string | NamedExport) {
75 return new BindingsExport(this.from).named(binding);
76 }
77
78 write(writer: Writer): void {
79 writer.write(`export * from "${this.from}"`);
80 }
81 }
82
83 export function moduleExportFrom(from: string) {
84 return new ExportAllFrom(from);
85 }
86
87 export function namedExport(name: string) {
88 return new NamedExport(name);
89 }