fork of hey-api/openapi-ts because I need some additional things
1import type { AnalysisContext } from '@hey-api/codegen-core';
2
3import { py } from '../../ts-python';
4import { PyDsl } from '../base';
5
6type ImportName = { alias?: string; name: string };
7
8const Mixed = PyDsl<py.ImportStatement>;
9
10export class ImportPyDsl extends Mixed {
11 readonly '~dsl' = 'ImportPyDsl';
12
13 protected isFrom: boolean = true;
14 protected module: string = '';
15 protected names?: ReadonlyArray<ImportName>;
16
17 constructor(module: string);
18 constructor(module: string, isFrom: boolean);
19 constructor(module: string, names: ReadonlyArray<ImportName>, isFrom: boolean);
20 constructor(
21 module: string,
22 namesOrIsFrom?: ReadonlyArray<ImportName> | boolean,
23 isFrom?: boolean,
24 ) {
25 super();
26 this.module = module;
27 if (typeof namesOrIsFrom === 'boolean') {
28 this.isFrom = namesOrIsFrom;
29 } else if (Array.isArray(namesOrIsFrom)) {
30 this.names = namesOrIsFrom;
31 this.isFrom = isFrom ?? true;
32 } else {
33 this.isFrom = true;
34 }
35 }
36
37 static from(module: string, names?: ReadonlyArray<ImportName>): ImportPyDsl {
38 return names ? new ImportPyDsl(module, names, true) : new ImportPyDsl(module, true);
39 }
40
41 static direct(module: string): ImportPyDsl {
42 return new ImportPyDsl(module, false);
43 }
44
45 override analyze(_ctx: AnalysisContext): void {
46 super.analyze(_ctx);
47 }
48
49 override toAst(): py.ImportStatement {
50 return {
51 isFrom: this.isFrom,
52 kind: py.PyNodeKind.ImportStatement,
53 module: this.module,
54 names: this.names,
55 };
56 }
57}