import { type ApplicationService, type HttpRouterService } from '@adonisjs/core/types'; import { type HttpContext } from '@adonisjs/core/http'; import { type Component } from './component.js'; import type ComponentContext from './component_context.js'; import { Checksum } from './checksum.js'; import type { Config } from './define_config.js'; import { type Synth } from '../index.js'; import type { ComponentSnapshot, ComponentCall, MountOptions, ComponentHookConstructor, ComponentConstructor } from './types.js'; import { type ChainableTest } from './features/support_testing/base_testable.js'; export default class Livewire { #private; app: ApplicationService; router: HttpRouterService; config: Config; checksum: Checksum; static FEATURES: ComponentHookConstructor[]; static PROPERTY_SYNTHESIZERS: Array; constructor(app: ApplicationService, router: HttpRouterService, config: Config); static componentHook(feature: ComponentHookConstructor): void; componentHook(feature: ComponentHookConstructor): void; static registerPropertySynthesizer(synth: typeof Synth | (typeof Synth)[]): void; registerPropertySynthesizer(synth: typeof Synth | (typeof Synth)[]): void; /** * Check if a component exists by name * PHP parity: exists($componentNameOrClass) */ exists(name: string): boolean; /** * Set query params for testing * PHP parity: withQueryParams($params) * * @example * ```ts * await Livewire * .withQueryParams({ page: 1, sort: 'name' }) * .test(SearchComponent) * ``` */ withQueryParams(params: Record): this; /** * Set a cookie for testing * PHP parity: withCookie($name, $value) * * Applied as a raw `Cookie` request header. Components should read cookies via * `request.plainCookie(name, { encoded: false })`. Does not support AdonisJS's * signed/encrypted `request.cookie()`, which needs the app's APP_KEY to produce * a value the decrypt step accepts. */ withCookie(name: string, value: string): this; /** * Set cookies for testing * PHP parity: withCookies($cookies) * * Applied as a raw `Cookie` request header. Components should read cookies via * `request.plainCookie(name, { encoded: false })`. Does not support AdonisJS's * signed/encrypted `request.cookie()`, which needs the app's APP_KEY to produce * a value the decrypt step accepts. * * @example * ```ts * await Livewire * .withCookies({ session_id: 'abc123' }) * .test(MyComponent) * ``` */ withCookies(cookies: Record): this; /** * Set headers for testing * PHP parity: withHeaders($headers) * * @example * ```ts * await Livewire * .withHeaders({ 'Accept-Language': 'pt-BR' }) * .test(MyComponent) * ``` */ withHeaders(headers: Record): this; /** * Disable lazy loading for testing * PHP parity: withoutLazyLoading() * * @example * ```ts * await Livewire * .withoutLazyLoading() * .test(LazyComponent) * ``` */ withoutLazyLoading(): this; withHttpContext(ctx: HttpContext): this; /** * Set the authenticated user for testing * PHP parity: actingAs($user, $driver = null) * * @example * ```ts * const user = await User.find(1) * await Livewire * .actingAs(user) * .test(ProfileComponent) * ``` */ actingAs(user: any, guard?: string): this; /** * Test a Livewire component * PHP parity: Livewire::test($name, $params = []) * * Creates a Testable instance, mounts it immediately with the given params, and * returns a chainable fluent testing API. Do NOT call `.mount()` again on the * result — it will re-run boot/mount lifecycle hooks a second time. * * @example * ```ts * import Livewire from 'adonisjs-livewire/services/main' * import Counter from '#livewire/counter' * * await Livewire.test(Counter) * .call('increment') * .assertSet('count', 1) * ``` */ test(componentClass: ComponentConstructor, params?: Record): ChainableTest; /** * Check if current request is a Livewire request * PHP parity: isLivewireRequest() */ static isLivewireRequest(ctx?: HttpContext): boolean; /** * Instance method for isLivewireRequest */ isLivewireRequest(ctx?: HttpContext): boolean; /** * Get the current component from the Livewire context * PHP parity: current() */ static current(): Component | null; /** * Flush static state between requests (useful for testing) * PHP parity: flushState() */ static flushState(): void; /** * Instance method to flush state and clear component cache */ flushState(): void; static generateComponentData(component: Component): Record; mount(ctx: HttpContext, name: string, params?: Record, options?: MountOptions, slots?: Record): Promise; new(ctx: HttpContext, name: string, id?: string | null): Promise; static extractRequestViewLocals(ctx?: HttpContext): any; static setOrUpdateComponentView(component: Component, ctx?: HttpContext): void; update(ctx: HttpContext, snapshot: ComponentSnapshot, updates: Record, calls: ComponentCall[]): Promise<[ComponentSnapshot, import("./types.js").ComponentEffects]>; snapshot(component: Component, context?: ComponentContext | null): Promise; /** * Register a component class under the given name. * * @remarks Prior to the ComponentRegistry extraction this returned the * internal Map from `Map.prototype.set()`. That was accidental exposure * of an implementation detail; no code in this repo or its tests * consumed the return value. This method is now `void` by design. */ component(name: string, component: ComponentConstructor): void; /** * Register a Lucid model class under the given name, so ModelSynth can * resolve it without relying on the models_namespace directory * convention. Mirrors component(). */ registerModel(name: string, Ctor: any): void; insertAttributesIntoHtmlRoot(html: string, attributes: { [key: string]: string; }): string; }