@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 51 lines 1.28 KB
Raw
1 import { DocComment } from './DocComment';
2 import { isValidJsIdentifier } from './isValidJsIdentifier';
3 import { WellKnownSymbol } from './WellKnownSymbol';
4 import { ValueBuilder } from './ValueBuilder';
5 import { Writer } from './Writer';
6 import type { BasicBuilder } from './BasicBuilder';
7
8 export class PropertyValue implements BasicBuilder {
9 private isOptional = false;
10 private docComment?: DocComment;
11
12 constructor(
13 public name: string | WellKnownSymbol,
14 public value: ValueBuilder
15 ) {}
16
17 optional(): this {
18 this.isOptional = true;
19 return this;
20 }
21
22 setDocComment(docComment: DocComment): this {
23 this.docComment = docComment;
24 return this;
25 }
26
27 write(writer: Writer): void {
28 if (this.docComment) {
29 writer.write(this.docComment);
30 }
31
32 if (typeof this.name === 'string') {
33 if (isValidJsIdentifier(this.name)) {
34 writer.write(this.name);
35 } else {
36 writer.write('[').write(JSON.stringify(this.name)).write(']');
37 }
38 } else {
39 writer.write('[').write(this.name).write(']');
40 }
41
42 if (this.isOptional) {
43 writer.write('?');
44 }
45 writer.write(': ').write(this.value);
46 }
47 }
48
49 export function propertyValue(name: string | WellKnownSymbol, value: ValueBuilder) {
50 return new PropertyValue(name, value);
51 }