import type { ClassLike } from 'utilium'; import type { Options } from './attributes.js'; import type { Field, FieldConfigInit, FieldOptions } from './fields.js'; import * as primitive from './primitives.js'; import type { StructConstructor, StructType } from './structs.shared.js'; interface Init { fields: Field[]; } type _DecoratorMetadata = DecoratorMetadata & { structInit?: Init; }; interface DecoratorContext { metadata: _DecoratorMetadata; } /** * Decorates a class as a struct. */ export declare function struct(this: Function | Options | void, ...options: Options[]): (target: T, context: ClassDecoratorContext & DecoratorContext) => T; export declare namespace struct { var packed: typeof struct; var align: (alignment: number) => typeof struct; } /** * deprecated Use the new `union` function instead. */ export interface UnionOptions { align?: number; } /** * Decorates a class as a union. */ export declare function union(options?: UnionOptions): (target: T, context: ClassDecoratorContext & DecoratorContext) => T; /** * Decorates a class member as a struct field. */ export declare function field(type: FieldConfigInit | StructConstructor, opt?: FieldOptions): (value: Target, context: Context) => Result; type Target = ClassAccessorDecoratorTarget; type Result = ClassAccessorDecoratorResult; type Context = ClassAccessorDecoratorContext & DecoratorContext; type Decorator = (value: Target, context: Context) => Result; declare function _shortcut(typeName: T): { (length: number, options?: Omit): Decorator; (value: Target, context: Context): Result; }; /** * Shortcuts for primitive types * Instead of writing `@field(primitive.types[primitive.normalize()])`, you can write `@types.type`. * You can also use `@types.type(length)` for arrays. */ export declare const types: { [K in primitive.ValidName]: ReturnType>; }; /** * Due to restrictions on decorators, `@struct` can not narrow the type of the class. * You must use the function to wrap the base class in the `extends` clause to force the correct type. */ export declare function $from(t: ClassLike): StructConstructor; export declare namespace $from { var typed: (t: ClassLike) => StructFromTypedArray; } type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float16Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; export interface StructFromTypedArray extends StructType<{}> { prototype: T; new (buffer: TArrayBuffer, byteOffset?: number, byteLength?: number): T; new (length: number): T; new (array: ArrayLike): T; readonly BYTES_PER_ELEMENT?: number; } export {};