import { AbstractConstructor, Constructor, IntrinsicSymbolId } from "./utility"; import { t } from "@rbxts/t"; interface BaseDescriptor { /** * The ID of this decorator. */ id: string; /** * The object this decorator is attached to. */ object: AbstractConstructor; /** * The constructor this decorator is attached to, unless abstract. */ constructor?: Constructor; } export interface ClassDescriptor extends BaseDescriptor { } export interface MethodDescriptor extends PropertyDescriptor { } export interface PropertyDescriptor extends BaseDescriptor { property: string; isStatic: boolean; } interface AttachedDecorator { object: AbstractConstructor; constructor?: Constructor; arguments: T; } type TSDecorator = T & { _flamework_Decorator: never; }; type ClassDecorator = TSDecorator<(ctor: defined) => never>; type MethodDecorator = TSDecorator<(target: defined, propertyKey: string, descriptor: defined) => never>; type PropertyDecorator = TSDecorator<(target: defined, propertyKey: string) => never>; type DecoratorWithMetadata = T & { _flamework_Parameters: P; }; type DecoratorParameters = T extends { _flamework_Parameters: infer P; } ? P : []; type AnyDecorator = DecoratorWithMetadata<(...args: never[]) => unknown, unknown[]>; type Decorator

= DecoratorWithMetadata

D) & D : (...args: P) => D, P>; type ListenerAddedEvent = (object: object) => void; type ListenerRemovedEvent = (object: object) => void; type DependencyRegistration = object | ((ctor: Constructor) => object); export declare namespace Modding { /** * Retrieves an object from its identifier. * * The reverse (getting an identifier from an object) can be achieved using the Reflect API directly. */ export function getObjectFromId(id: string): object | undefined; /** * Registers a listener for lifecycle events. */ export function addListener(object: object): void; /** * Removes a listener for lifecycle events and decorators. */ export function removeListener(object: object): void; /** * Registers a listener added event. * Fires whenever any listener is added. * * Fires for all existing listeners. */ export function onListenerAdded(func: ListenerAddedEvent): RBXScriptConnection; /** * Registers a listener added event. * Fires whenever a listener has a decorator with the specified ID. * * Fires for all existing listeners. * * @metadata macro */ export function onListenerAdded(func: ListenerAddedEvent, id?: IdRef): RBXScriptConnection; /** * Registers a listener added event. * Fires whenever a listener has a lifecycle event with the specified ID. * * Fires for all existing listeners. * * @metadata macro */ export function onListenerAdded(func: (value: T) => void, id?: IdRef): RBXScriptConnection; /** * Registers a listener removed event. * * Fires whenever any listener is removed. */ export function onListenerRemoved(func: ListenerRemovedEvent): RBXScriptConnection; /** * Registers a listener removed event. * * Fires whenever a listener has a decorator with the specified ID. * * @metadata macro */ export function onListenerRemoved(func: ListenerRemovedEvent, id?: IdRef): RBXScriptConnection; /** * Registers a listener removed event. * * Fires whenever a listener has a lifecycle event with the specified ID. * * @metadata macro */ export function onListenerRemoved(func: (object: T) => void, id?: IdRef): RBXScriptConnection; /** * Registers a class decorator. */ export function createDecorator(kind: "Class", func: (descriptor: ClassDescriptor, config: T) => void): Decorator; /** * Registers a method decorator. */ export function createDecorator(kind: "Method", func: (descriptor: MethodDescriptor, config: T) => void): Decorator; /** * Registers a property decorator. */ export function createDecorator(kind: "Property", func: (descriptor: PropertyDescriptor, config: T) => void): Decorator; /** * Registers a metadata class decorator. */ export function createMetaDecorator(kind: "Class"): Decorator; /** * Registers a metadata method decorator. */ export function createMetaDecorator(kind: "Method"): Decorator; /** * Registers a metadata property decorator. */ export function createMetaDecorator(kind: "Property"): Decorator; /** * Retrieves registered decorators. * * @metadata macro */ export function getDecorators(id?: IdRef): AttachedDecorator>[]; /** * Creates a map of every property using the specified decorator. * * @metadata macro */ export function getPropertyDecorators(obj: object, id?: IdRef): Map; }>; /** * Retrieves a decorator from an object or its properties. * * @metadata macro */ export function getDecorator(object: object, property?: string, id?: IdRef): { arguments: DecoratorParameters; } | undefined; /** * Retrieves a singleton or instantiates one if it does not exist. */ export function resolveSingleton(ctor: Constructor): T; /** * Modifies dependency resolution for a specific ID. * * If a function is passed, it will be called, passing the target constructor, every time that ID needs to be resolved. * Otherwise, the passed object is returned directly. * * @metadata macro */ export function registerDependency(dependency: DependencyRegistration, id?: IdRef): void; /** * Instantiates this class using dependency injection. */ export function createDependency(ctor: Constructor, options?: DependencyResolutionOptions): T; /** * Creates an object for this class and returns a deferred constructor. */ export function createDeferredDependency(ctor: Constructor, options?: DependencyResolutionOptions): readonly [T, () => void]; /** * This function is able to utilize Flamework's user macros to generate and inspect types. * This function supports all values natively supported by Flamework's user macros. * * For example, if you want to retrieve the properties of an instance, you could write code like this: * ```ts * // Returns an array of all keys part of the union. * const basePartKeys = Modding.inspect[]>(); * ``` * * @metadata macro */ export function inspect(value?: Modding.Many): T; /** * This API allows you to use more complex queries, inspect types, generate arbitrary objects based on types, etc. * * @experimental This API is considered experimental and may change. */ export type Many = T & { /** @hidden */ _flamework_macro_many: T; }; /** * Hashes a string literal type (such as an event name) under Flamework's {@link Many `Many`} API. * * The second type argument, `C`, is for providing a context to the hashing which will generate new hashes * for strings which already have a hash under another context. * * @experimental This API is considered experimental and may change. */ export type Hash = string & { /** @hidden */ _flamework_macro_hash: [T, C]; }; /** * This is equivalent to {@link Hash `Hash`} except it will only hash strings when `obfuscation` is turned on. * * @experimental This API is considered experimental and may change. */ export type Obfuscate = string & { /** @hidden */ _flamework_macro_hash: [T, C, true]; }; /** * Retrieves the labels from this tuple under Flamework's {@link Many `Many`} API. * * This can also be used to extract parameter names via `Parameters` * * @experimental This API is considered experimental and may change. */ export type TupleLabels = (string[] & { _flamework_macro_tuple_labels: T; }) | undefined; /** * Retrieves metadata about the specified type using Flamework's user macros. */ export type Generic> = GenericMetadata[M] & { /** @hidden */ _flamework_macro_generic: [T, M]; }; /** * Retrieves multiple types of metadata from Flamework's user macros. */ export type GenericMany> = Modding.Many<{ [k in M]: Generic; }>; /** * Retrieves metadata about the callsite using Flamework's user macros. */ export type Caller = CallerMetadata[M] & { /** @hidden */ _flamework_macro_caller: M; }; /** * Retrieves multiple types of metadata about the callsite using Flamework's user macros. */ export type CallerMany = Modding.Many<{ [k in M]: Caller; }>; /** * An internal type for intrinsic user macro metadata. * * @hidden */ export type Intrinsic = T & { _flamework_intrinsic: [N, ...M]; }; interface CallerMetadata { /** * The starting line of the expression. */ line: number; /** * The char at the start of the expression relative to the starting line. */ character: number; /** * The width of the expression. * This includes the width of multiline statements. */ width: number; /** * A unique identifier that can be used to identify exact callsites. * This can be used for hooks. */ uuid: string; /** * The source text for the expression. */ text: string; } interface GenericMetadata { /** * The ID of the type. */ id: string; /** * A string equivalent of the type. */ text: string; /** * A generated guard for the type. */ guard: t.check; } type IdRef = string | IntrinsicSymbolId; export {}; } interface DependencyResolutionOptions { /** * Fires whenever a dependency is attempting to be resolved. * * Return undefined to let Flamework resolve it. */ handle?: (id: string, index: number) => unknown; /** * Fires whenever Flamework tries to resolve a primitive (e.g string) */ handlePrimitive?: (id: string, index: number) => defined; } export {};