fork of hey-api/openapi-ts because I need some additional things
1import type { AnalysisContext, Node } from '@hey-api/codegen-core';
2
3import type { py } from '../../ts-python';
4import type { MaybePyDsl } from '../base';
5import { CallPyDsl } from '../expr/call';
6import { AttrPyDsl } from '../expr/member';
7import type { BaseCtor, MixinCtor } from './types';
8
9export interface ExprMethods extends Node {
10 attr(object: MaybePyDsl<py.Expression>, prop: string): AttrPyDsl;
11 call(callee: MaybePyDsl<py.Expression>, ...args: Array<MaybePyDsl<py.Expression>>): CallPyDsl;
12}
13
14export function ExprMixin<T extends py.Expression, TBase extends BaseCtor<T>>(Base: TBase) {
15 abstract class Expr extends Base {
16 override analyze(ctx: AnalysisContext): void {
17 super.analyze(ctx);
18 }
19
20 protected attr(object: MaybePyDsl<py.Expression>, prop: string): AttrPyDsl {
21 return AttrPyDsl.attr(object, prop);
22 }
23
24 protected call(
25 callee: MaybePyDsl<py.Expression>,
26 ...args: Array<MaybePyDsl<py.Expression>>
27 ): CallPyDsl {
28 return new CallPyDsl(callee, ...args);
29 }
30 }
31
32 return Expr as unknown as MixinCtor<TBase, ExprMethods>;
33}