jsii-pacmak
Version:
A code generation framework for jsii backend languages
92 lines • 3.63 kB
TypeScript
import { Assembly, OptionalValue, TypeReference, Type } from '@jsii/spec';
import { CodeMaker } from 'codemaker';
/**
* The position of a type
*
* Types are rendered differently depending on what position they're in:
*
* - `type`: a type annotation; these are not evaluated during execution.
* - `value`: a value in a function body; these are evaluated when the function is called.
* - `decl`: a value in a class declaration; these are evaluated when a class is being
* instantiated, before it's done.
*/
export type TypePosition = 'type' | 'value' | 'decl';
/**
* Actually more of a TypeNameFactory than a TypeName
*/
export interface TypeName {
pythonType(pos: TypePosition, context: NamingContext): string;
requiredImports(context: NamingContext): PythonImports;
}
export interface PythonImports {
/**
* For a given source module, what elements to import. The empty string value
* indicates a need to import the module fully ("import <name>") instead of
* doing a piecemeal import ("from <name> import <item>").
*/
readonly [sourcePackage: string]: ReadonlySet<string>;
}
/**
* The context in which a PythonType is being considered.
*/
export interface NamingContext {
/** The assembly in which the PythonType is expressed. */
readonly assembly: Assembly;
/** A resolver to obtain complete information about a type. */
readonly typeResolver: (fqn: string) => Type;
/** The submodule of the assembly in which the PythonType is expressed (could be the module root) */
readonly submodule: string;
/** Holds the set of intersection types used in the current module */
readonly intersectionTypes: IntersectionTypesRegistry;
/**
* A an array representing the stack of declarations currently being
* initialized. All of these names can only be referred to using a forward
* reference (stringified type name) in the context of type signatures (but
* they can be used safely from implementations so long as those are not *run*
* as part of the declaration).
*
* Closest to the current type is at the end.
*
* @default []
*/
readonly surroundingTypeFqns?: readonly string[];
/**
* Disables generating typing.Optional wrappers
* @default false
* @internal
*/
readonly ignoreOptional?: boolean;
/**
* Whether the type is emitted for a parameter or not. This may change the
* exact type signature being emitted (e.g: Arrays are typing.Sequence[T] for
* parameters, and typing.List[T] otherwise).
*/
readonly parameterType?: boolean;
}
export declare function toTypeName(ref?: OptionalValue | TypeReference): TypeName;
/**
* Obtains the Python package name for a given submodule FQN.
*
* @param fqn the submodule FQN for which a package name is needed.
* @param rootAssm the assembly this FQN belongs to.
*/
export declare function toPackageName(fqn: string, rootAssm: Assembly): string;
export declare function mergePythonImports(...pythonImports: readonly PythonImports[]): PythonImports;
export declare function toPythonFqn(fqn: string, rootAssm: Assembly): {
assemblyName: string;
packageName: string;
pythonFqn: string;
};
/**
* Holds a set of intersection types used by the current set of modules
*/
export declare class IntersectionTypesRegistry {
private readonly types;
/**
* Return a unique name for a protocol that extends the given types
*/
obtain(types: string[]): string;
get typeNames(): string[];
flushHelperTypes(code: CodeMaker): void;
}
//# sourceMappingURL=type-name.d.ts.map