Skip to content

Commit 5ace100

Browse files
committed
docs: updated API reference
1 parent bf06715 commit 5ace100

File tree

3 files changed

+88
-19
lines changed

3 files changed

+88
-19
lines changed

docs/api-reference/core/ChainedAttribute.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx';
1111
import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx';
1212
import {Attribute} from '/snippets/Attribute.mdx';
1313

14-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/expressions/chained_attribute.py#L29-L185" />
14+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/expressions/chained_attribute.py#L29-L182" />
1515

1616
### Inherits from
1717
[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable)

docs/api-reference/typescript/TSImport.mdx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx';
1111
import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx';
1212
import {Attribute} from '/snippets/Attribute.mdx';
1313

14-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L31-L605" />
14+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L32-L648" />
1515

1616
### Inherits from
1717
[Exportable](/api-reference/core/Exportable), [Import](/api-reference/core/Import), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName)
@@ -86,6 +86,10 @@ import {Attribute} from '/snippets/Attribute.mdx';
8686
<HorizontalDivider light={true} />
8787
<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Indicates if the symbol is exported from its defining file." />
8888

89+
### <span className="text-primary">is_namespace_import</span>
90+
<HorizontalDivider light={true} />
91+
<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Returns True if this import is importing a namespace." />
92+
8993
### <span className="text-primary">is_reexported</span>
9094
<HorizontalDivider light={true} />
9195
<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Determines if the symbol is re-exported from a different file." />
@@ -102,6 +106,10 @@ import {Attribute} from '/snippets/Attribute.mdx';
102106
<HorizontalDivider light={true} />
103107
<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> } description="If import is a module import, returns any namespace prefix that must be used with import reference." />
104108

109+
### <span className="text-primary">namespace_imports</span>
110+
<HorizontalDivider light={true} />
111+
<Attribute type={ <><span>list[</span> <a href="/api-reference/typescript/TSNamespace" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSNamespace</a> <span>]</span></> } description="Returns any namespace objects imported by this import statement." />
112+
105113
### <span className="text-primary">parent</span>
106114
<HorizontalDivider light={true} />
107115
<Attribute type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a></> } description="The parent node of this Editable instance." />
@@ -271,7 +279,7 @@ Adds a visual flag comment to the end of this Editable's source text.
271279

272280
### <span className="text-primary">get_import_string</span>
273281
Generates an import string for an import statement.
274-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L548-L571" />
282+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L549-L572" />
275283

276284
<ParameterWrapper>
277285
<Parameter
@@ -435,7 +443,7 @@ Checks if this node is a descendant of the given editable instance in the AST.
435443

436444
### <span className="text-primary">is_default_import</span>
437445
Determines whether the import is a default export import.
438-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L78-L90" />
446+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L79-L91" />
439447

440448
<ParameterWrapper>
441449
<Parameter
@@ -452,7 +460,7 @@ Determines whether the import is a default export import.
452460

453461
### <span className="text-primary">is_module_import</span>
454462
Determines if an import represents a module-level import.
455-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L58-L75" />
463+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L59-L76" />
456464

457465
<ParameterWrapper>
458466
<Parameter
@@ -485,7 +493,7 @@ Returns True if this import is importing a symbol rather than a module.
485493

486494
### <span className="text-primary">is_type_import</span>
487495
Checks if an import is a type import.
488-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L35-L55" />
496+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L36-L56" />
489497

490498

491499
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the import is a type import, False otherwise."/>
@@ -626,7 +634,7 @@ Search and replace occurrences of text within this node's source and its extende
626634

627635
### <span className="text-primary">resolve_import</span>
628636
Resolves an import statement to its target file and symbol.
629-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L200-L278" />
637+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L201-L279" />
630638

631639
<ParameterWrapper>
632640
<Parameter
@@ -672,7 +680,7 @@ Returns a list of all regex match of `regex_pattern`, similar to python's re.sea
672680

673681
### <span className="text-primary">set_import_module</span>
674682
Sets the module of an import.
675-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L582-L605" />
683+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/import_resolution.py#L625-L648" />
676684

677685
<ParameterWrapper>
678686
<Parameter

docs/api-reference/typescript/TSNamespace.mdx

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx';
1111
import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx';
1212
import {Attribute} from '/snippets/Attribute.mdx';
1313

14-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L31-L208" />
14+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L44-L400" />
1515

1616
### Inherits from
1717
[HasName](/api-reference/core/HasName), [TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable)
@@ -46,6 +46,10 @@ import {Attribute} from '/snippets/Attribute.mdx';
4646
<HorizontalDivider light={true} />
4747
<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> } description="Retrieves the exported name of a symbol from its file." />
4848

49+
### <span className="text-primary">exports</span>
50+
<HorizontalDivider light={true} />
51+
<Attribute type={ <><span>list[</span> <a href="/api-reference/typescript/TSExport" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSExport</a> <span>]</span></> } description="Returns all Export symbols in the namespace." />
52+
4953
### <span className="text-primary">extended</span>
5054
<HorizontalDivider light={true} />
5155
<Attribute type={ <><a href="/api-reference/core/SymbolGroup" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SymbolGroup</a></> } description="Returns a SymbolGroup of all extended nodes associated with this element." />
@@ -224,6 +228,31 @@ Insert a keyword in the appropriate place before this symbol if it doesn't alrea
224228
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description=""/>
225229

226230

231+
### <span className="text-primary">add_symbol</span>
232+
Adds a new symbol to the namespace, optionally exporting it if applicable. If the symbol already exists in the namespace, returns the existing symbol.
233+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L278-L303" />
234+
235+
236+
<Return return_type={ <><a href="/api-reference/typescript/TSSymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSSymbol</a> <span>| None</span></> } description="The existing symbol if it already exists in the file or None if it was added."/>
237+
238+
239+
### <span className="text-primary">add_symbol_from_source</span>
240+
Adds a symbol to a namespace from a string representation.
241+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L258-L275" />
242+
243+
<ParameterWrapper>
244+
<Parameter
245+
name="source"
246+
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> }
247+
description="String representation of the symbol to be added. This should be valid source code for"
248+
defaultValue=""
249+
/>
250+
</ParameterWrapper>
251+
252+
253+
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="The symbol is added directly to the namespace's content."/>
254+
255+
227256
### <span className="text-primary">ancestors</span>
228257
Find all ancestors of the node of the given type. Does not return itself
229258
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1119-L1127" />
@@ -346,7 +375,7 @@ Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag.
346375

347376
### <span className="text-primary">get_class</span>
348377
Get a class by name from this namespace.
349-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L135-L143" />
378+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L182-L190" />
350379

351380

352381
<Return return_type={ <><a href="/api-reference/typescript/TSClass" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSClass</a> <span>| None</span></> } description=""/>
@@ -371,18 +400,18 @@ Returns a specific JSX element from within this symbol's JSX elements.
371400

372401
### <span className="text-primary">get_enum</span>
373402
Get an enum by name from this namespace.
374-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L165-L173" />
403+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L212-L220" />
375404

376405

377406
<Return return_type={ <><a href="/api-reference/typescript/TSEnum" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSEnum</a> <span>| None</span></> } description=""/>
378407

379408

380409
### <span className="text-primary">get_function</span>
381410
Get a function by name from this namespace.
382-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L107-L124" />
411+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L163-L171" />
383412

384413

385-
<Return return_type={ <><a href="/api-reference/typescript/TSFunction" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSFunction</a> <span>| None</span></> } description="The found function, or None if not found"/>
414+
<Return return_type={ <><a href="/api-reference/typescript/TSFunction" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSFunction</a> <span>| None</span></> } description=""/>
386415

387416

388417
### <span className="text-primary">get_import_string</span>
@@ -422,7 +451,7 @@ Generates the appropriate import string for a symbol.
422451

423452
### <span className="text-primary">get_interface</span>
424453
Get an interface by name from this namespace.
425-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L145-L153" />
454+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L192-L200" />
426455

427456

428457
<Return return_type={ <><a href="/api-reference/typescript/TSInterface" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSInterface</a> <span>| None</span></> } description=""/>
@@ -438,31 +467,31 @@ Returns the name node of the object.
438467

439468
### <span className="text-primary">get_namespace</span>
440469
Get a namespace by name from this namespace.
441-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L175-L195" />
470+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L222-L242" />
442471

443472

444473
<Return return_type={ <><a href="/api-reference/typescript/TSNamespace" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSNamespace</a> <span>| None</span></> } description="The found namespace, or None if not found"/>
445474

446475

447476
### <span className="text-primary">get_nested_namespaces</span>
448477
Get all nested namespaces within this namespace.
449-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L197-L208" />
478+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L244-L255" />
450479

451480

452481
<Return return_type={ <><span>list[</span> <a href="/api-reference/typescript/TSNamespace" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSNamespace</a> <span>]</span></> } description="List of all nested namespace objects"/>
453482

454483

455484
### <span className="text-primary">get_symbol</span>
456-
Get a symbol by name from this namespace.
457-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L76-L96" />
485+
Get an exported or private symbol by name from this namespace. Returns only exported symbols by default.
486+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L88-L123" />
458487

459488

460489
<Return return_type={ <><a href="/api-reference/typescript/TSSymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSSymbol</a> <span>| None</span></> } description="The found symbol, or None if not found"/>
461490

462491

463492
### <span className="text-primary">get_type</span>
464493
Get a type alias by name from this namespace.
465-
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L155-L163" />
494+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L202-L210" />
466495

467496

468497
<Return return_type={ <><a href="/api-reference/typescript/TSTypeAlias" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSTypeAlias</a> <span>| None</span></> } description=""/>
@@ -677,6 +706,14 @@ Deletes this Node and its related extended nodes (e.g. decorators, comments).
677706
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description=""/>
678707

679708

709+
### <span className="text-primary">remove_symbol</span>
710+
Removes a symbol from the namespace by name.
711+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L306-L323" />
712+
713+
714+
<Return return_type={ <><a href="/api-reference/typescript/TSSymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSSymbol</a> <span>| None</span></> } description=""/>
715+
716+
680717
### <span className="text-primary">rename</span>
681718
Sets the name of an object and updates all its usages.
682719
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/has_name.py#L80-L89" />
@@ -694,6 +731,14 @@ Sets the name of an object and updates all its usages.
694731
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description=""/>
695732

696733

734+
### <span className="text-primary">rename_symbol</span>
735+
Renames a symbol within the namespace.
736+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L326-L335" />
737+
738+
739+
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description=""/>
740+
741+
697742
### <span className="text-primary">replace</span>
698743
Search and replace occurrences of text within this node's source and its extended nodes.
699744
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L432-L456" />
@@ -735,6 +780,22 @@ Search and replace occurrences of text within this node's source and its extende
735780
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The total number of replacements made."/>
736781

737782

783+
### <span className="text-primary">resolve_attribute</span>
784+
Resolves an attribute access on the namespace.
785+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L391-L400" />
786+
787+
788+
<Return return_type={ <><a href="/api-reference/typescript/TSSymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSSymbol</a> <span>| None</span></> } description=""/>
789+
790+
791+
### <span className="text-primary">resolve_import</span>
792+
Resolves an import name to a symbol within this namespace.
793+
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/typescript/namespace.py#L368-L388" />
794+
795+
796+
<Return return_type={ <><a href="/api-reference/typescript/TSSymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSSymbol</a> <span>| None</span></> } description=""/>
797+
798+
738799
### <span className="text-primary">search</span>
739800
Returns a list of all regex match of `regex_pattern`, similar to python's re.search().
740801
<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L520-L536" />

0 commit comments

Comments
 (0)