@wirestate/lit 0.6.0 → 0.7.0-experimental.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/README.md +246 -10
  3. package/cjs/development/index.js +788 -58
  4. package/cjs/development/index.js.map +1 -1
  5. package/cjs/production/index.js +1 -1
  6. package/cjs/production/index.js.map +1 -1
  7. package/esm/development/commands/on-command-controller.js +59 -0
  8. package/esm/development/commands/on-command-controller.js.map +1 -0
  9. package/esm/development/commands/on-command.js +46 -0
  10. package/esm/development/commands/on-command.js.map +1 -0
  11. package/esm/development/commands/use-on-command.js +31 -0
  12. package/esm/development/commands/use-on-command.js.map +1 -0
  13. package/esm/development/consumption/injection.js +43 -9
  14. package/esm/development/consumption/injection.js.map +1 -1
  15. package/esm/development/consumption/use-injection.js +40 -6
  16. package/esm/development/consumption/use-injection.js.map +1 -1
  17. package/esm/development/context/ioc-context.js +12 -2
  18. package/esm/development/context/ioc-context.js.map +1 -1
  19. package/esm/development/error/error-code.js +4 -0
  20. package/esm/development/error/error-code.js.map +1 -0
  21. package/esm/development/events/on-event-controller.js +68 -0
  22. package/esm/development/events/on-event-controller.js.map +1 -0
  23. package/esm/development/events/on-event.js +68 -0
  24. package/esm/development/events/on-event.js.map +1 -0
  25. package/esm/development/events/use-on-events.js +42 -0
  26. package/esm/development/events/use-on-events.js.map +1 -0
  27. package/esm/development/index.js +16 -4
  28. package/esm/development/index.js.map +1 -1
  29. package/esm/development/provision/injectables-provide.js +47 -0
  30. package/esm/development/provision/injectables-provide.js.map +1 -0
  31. package/esm/development/provision/injectables-provider-controller.js +123 -0
  32. package/esm/development/provision/injectables-provider-controller.js.map +1 -0
  33. package/esm/development/provision/ioc-provide.js +58 -0
  34. package/esm/development/provision/ioc-provide.js.map +1 -0
  35. package/esm/development/provision/ioc-provider-controller.js +75 -0
  36. package/esm/development/provision/ioc-provider-controller.js.map +1 -0
  37. package/esm/development/provision/use-injectables-provider.js +27 -0
  38. package/esm/development/provision/use-injectables-provider.js.map +1 -0
  39. package/esm/development/provision/use-ioc-provision.js +27 -0
  40. package/esm/development/provision/use-ioc-provision.js.map +1 -0
  41. package/esm/development/queries/on-query-controller.js +59 -0
  42. package/esm/development/queries/on-query-controller.js.map +1 -0
  43. package/esm/development/queries/on-query.js +46 -0
  44. package/esm/development/queries/on-query.js.map +1 -0
  45. package/esm/development/queries/use-on-query.js +31 -0
  46. package/esm/development/queries/use-on-query.js.map +1 -0
  47. package/esm/production/commands/on-command-controller.js +1 -0
  48. package/esm/production/commands/on-command-controller.js.map +1 -0
  49. package/esm/production/commands/on-command.js +1 -0
  50. package/esm/production/commands/on-command.js.map +1 -0
  51. package/esm/production/commands/use-on-command.js +1 -0
  52. package/esm/production/commands/use-on-command.js.map +1 -0
  53. package/esm/production/consumption/injection.js +1 -1
  54. package/esm/production/consumption/injection.js.map +1 -1
  55. package/esm/production/consumption/use-injection.js +1 -1
  56. package/esm/production/consumption/use-injection.js.map +1 -1
  57. package/esm/production/context/ioc-context.js +1 -1
  58. package/esm/production/context/ioc-context.js.map +1 -1
  59. package/esm/production/error/error-code.js +1 -0
  60. package/esm/production/error/error-code.js.map +1 -0
  61. package/esm/production/events/on-event-controller.js +1 -0
  62. package/esm/production/events/on-event-controller.js.map +1 -0
  63. package/esm/production/events/on-event.js +1 -0
  64. package/esm/production/events/on-event.js.map +1 -0
  65. package/esm/production/events/use-on-events.js +1 -0
  66. package/esm/production/events/use-on-events.js.map +1 -0
  67. package/esm/production/index.js +1 -1
  68. package/esm/production/provision/injectables-provide.js +1 -0
  69. package/esm/production/provision/injectables-provide.js.map +1 -0
  70. package/esm/production/provision/injectables-provider-controller.js +1 -0
  71. package/esm/production/provision/injectables-provider-controller.js.map +1 -0
  72. package/esm/production/provision/ioc-provide.js +1 -0
  73. package/esm/production/provision/ioc-provide.js.map +1 -0
  74. package/esm/production/provision/ioc-provider-controller.js +1 -0
  75. package/esm/production/provision/ioc-provider-controller.js.map +1 -0
  76. package/esm/production/provision/use-injectables-provider.js +1 -0
  77. package/esm/production/provision/use-injectables-provider.js.map +1 -0
  78. package/esm/production/provision/use-ioc-provision.js +1 -0
  79. package/esm/production/provision/use-ioc-provision.js.map +1 -0
  80. package/esm/production/queries/on-query-controller.js +1 -0
  81. package/esm/production/queries/on-query-controller.js.map +1 -0
  82. package/esm/production/queries/on-query.js +1 -0
  83. package/esm/production/queries/on-query.js.map +1 -0
  84. package/esm/production/queries/use-on-query.js +1 -0
  85. package/esm/production/queries/use-on-query.js.map +1 -0
  86. package/index.d.ts +730 -29
  87. package/package.json +1 -1
  88. package/esm/development/provision/container-provider-controller.js +0 -41
  89. package/esm/development/provision/container-provider-controller.js.map +0 -1
  90. package/esm/development/provision/services-provider-controller.js +0 -63
  91. package/esm/development/provision/services-provider-controller.js.map +0 -1
  92. package/esm/development/provision/use-container-provision.js +0 -9
  93. package/esm/development/provision/use-container-provision.js.map +0 -1
  94. package/esm/production/provision/container-provider-controller.js +0 -1
  95. package/esm/production/provision/container-provider-controller.js.map +0 -1
  96. package/esm/production/provision/services-provider-controller.js +0 -1
  97. package/esm/production/provision/services-provider-controller.js.map +0 -1
  98. package/esm/production/provision/use-container-provision.js +0 -1
  99. package/esm/production/provision/use-container-provision.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,14 +1,44 @@
1
1
  import { ReactiveElement, ReactiveControllerHost, ReactiveController } from '@lit/reactive-element';
2
- import { ServiceIdentifier, Container, Newable, InjectableDescriptor, SeedEntries } from '@wirestate/core';
2
+ import { ServiceIdentifier, CommandType, CommandHandler, Event, EventType, EventHandler, QueryType, QueryHandler, Container, Newable, InjectableDescriptor, SeedEntries } from '@wirestate/core';
3
3
  import { ContextProvider, ContextConsumer } from '@lit/context';
4
- import { Callable } from '@wirestate/core/types/general';
5
4
 
5
+ /**
6
+ * Any object with string or symbol keys.
7
+ *
8
+ * @group Types
9
+ */
10
+ type AnyObject = Record<string | symbol, any>;
11
+ /**
12
+ * Type that can be null.
13
+ *
14
+ * @group Types
15
+ */
6
16
  type Optional<T> = T | null;
7
- type Maybe<T> = T | null | undefined;
17
+ /**
18
+ * Value or a promise of that value.
19
+ *
20
+ * @group Types
21
+ */
22
+ type MaybePromise<T> = T | Promise<T>;
23
+ /**
24
+ * Helper to extract the interface of a type.
25
+ *
26
+ * @group Types
27
+ */
8
28
  type Interface<T> = {
9
29
  [K in keyof T]: T[K];
10
30
  };
31
+ /**
32
+ * Return type for decorators.
33
+ *
34
+ * @group Types
35
+ */
11
36
  type DecoratorReturn = void | any;
37
+ /**
38
+ * Ensures that a decorated field matches the type being provided.
39
+ *
40
+ * @group Types
41
+ */
12
42
  type FieldMustMatchProvidedType<Obj, Key extends PropertyKey, ProvidedType> = Obj extends Record<Key, infer ConsumingType> ? [ProvidedType] extends [ConsumingType] ? DecoratorReturn : {
13
43
  message: "provided type not assignable to consuming field";
14
44
  provided: ProvidedType;
@@ -19,30 +49,476 @@ type FieldMustMatchProvidedType<Obj, Key extends PropertyKey, ProvidedType> = Ob
19
49
  consuming: ConsumingType | undefined;
20
50
  } : DecoratorReturn;
21
51
 
22
- type InjectionDecorator<ValueType> = {
23
- <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends ValueType>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
24
- <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, ValueType>;
25
- };
52
+ /**
53
+ * Represents definition of the injection decorator.
54
+ *
55
+ * @remarks
56
+ * Supports both TC39 and legacy experimental decorators.
57
+ *
58
+ * @group Consumption
59
+ */
60
+ interface InjectionDecorator<T> {
61
+ <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends T>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
62
+ <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, T>;
63
+ }
64
+ /**
65
+ * Represents options for the {@link injection} decorator.
66
+ *
67
+ * @group Consumption
68
+ */
26
69
  interface InjectionOptions<T> {
70
+ /**
71
+ * The service identifier to inject.
72
+ */
27
73
  injectionId: ServiceIdentifier<T>;
28
- subscribe?: boolean;
74
+ /**
75
+ * Whether to subscribe to container changes.
76
+ *
77
+ * @remarks
78
+ * If true, the property will be updated if the container in the context changes.
79
+ * Defaults to false.
80
+ */
81
+ once?: boolean;
29
82
  }
30
- declare function injection<T>({ injectionId, subscribe }: InjectionOptions<T>): InjectionDecorator<T>;
83
+ /**
84
+ * Decorator to inject a service from the IoC container into a Lit element property.
85
+ *
86
+ * @group Consumption
87
+ *
88
+ * @param optionsOrInjectionId - Injection options or service identifier.
89
+ * @returns An instance of {@link InjectionDecorator}.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * class MyElement extends LitElement {
94
+ * @injection(MyService)
95
+ * private myService!: MyService;
96
+ *
97
+ * public render() {
98
+ * return html`<div>${this.myService.getName()}</div>`;
99
+ * }
100
+ * }
101
+ * ```
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * class MyElement extends LitElement {
106
+ * @injection({ injectionId: MyService, once: true })
107
+ * private myService!: MyService;
108
+ *
109
+ * public render() {
110
+ * return html`<div>${this.myService.getName()}</div>`;
111
+ * }
112
+ * }
113
+ * ```
114
+ */
115
+ declare function injection<T>(optionsOrInjectionId: InjectionOptions<T> | ServiceIdentifier<T>): InjectionDecorator<T>;
31
116
 
117
+ /**
118
+ * Represents options for the {@link useInjection} hook.
119
+ *
120
+ * @group Consumption
121
+ */
32
122
  interface UseInjectionOptions<T> {
123
+ /**
124
+ * Whether to subscribe to container changes.
125
+ *
126
+ * @remarks
127
+ * If true, the service will be fetched only once when the controller is created.
128
+ * Defaults to false.
129
+ */
33
130
  once?: boolean;
131
+ /**
132
+ * Initial value before the service is fetched.
133
+ */
34
134
  value?: Optional<T>;
135
+ /**
136
+ * The service identifier to inject.
137
+ */
35
138
  injectionId: ServiceIdentifier<T>;
36
139
  }
140
+ /**
141
+ * Represents result of the {@link useInjection} hook.
142
+ *
143
+ * @group Consumption
144
+ */
37
145
  interface UseInjectionValue<T> {
146
+ /**
147
+ * The service identifier used for injection.
148
+ */
38
149
  injectionId: ServiceIdentifier<T>;
150
+ /**
151
+ * The injected service instance.
152
+ */
39
153
  value: T;
40
154
  }
41
- declare function useInjection<T extends object, E extends ReactiveControllerHost & HTMLElement>(host: E, { once, injectionId, value }: UseInjectionOptions<T>): UseInjectionValue<T>;
155
+ /**
156
+ * Hook (controller) to inject a service from the IoC container.
157
+ *
158
+ * @group Consumption
159
+ *
160
+ * @param host - The host element.
161
+ * @param optionsOrInjectionId - Injection options or service identifier.
162
+ * @returns An instance of {@link UseInjectionValue}.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * class MyElement extends LitElement {
167
+ * private myService = useInjection(this, MyService);
168
+ *
169
+ * render() {
170
+ * return html`<div>${this.myService.value.getName()}</div>`;
171
+ * }
172
+ * }
173
+ * ```
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * class MyElement extends LitElement {
178
+ * private myService = useInjection(this, { injectionId: MyService, once: true });
179
+ *
180
+ * render() {
181
+ * return html`<div>${this.myService.value.getName()}</div>`;
182
+ * }
183
+ * }
184
+ * ```
185
+ */
186
+ declare function useInjection<T extends object, E extends ReactiveControllerHost & HTMLElement>(host: E, optionsOrInjectionId: UseInjectionOptions<T> | ServiceIdentifier<T>): UseInjectionValue<T>;
187
+
188
+ /**
189
+ * Represents interface for the {@link onCommand} decorator.
190
+ *
191
+ * @remarks
192
+ * Supports both TC39 and legacy experimental decorators.
193
+ *
194
+ * @group Commands
195
+ */
196
+ interface OnCommandDecorator<D = unknown, R = unknown> {
197
+ <This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, data: D) => MaybePromise<R>, context: ClassMethodDecoratorContext<This>): void;
198
+ (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
199
+ }
200
+ /**
201
+ * Decorator for Lit element methods that handle a specific command.
202
+ *
203
+ * @remarks
204
+ * The handler is registered when the host connects and unregistered when it disconnects.
205
+ *
206
+ * @group Commands
207
+ *
208
+ * @param type - Unique identifier of the command to handle.
209
+ * @returns A method decorator function.
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * class MyElement extends LitElement {
214
+ * @onCommand("SAVE")
215
+ * private onSave(data: SomeData): void {
216
+ * // handle command
217
+ * }
218
+ * }
219
+ * ```
220
+ */
221
+ declare function onCommand<D = unknown, R = unknown>(type: CommandType): OnCommandDecorator<D, R>;
222
+
223
+ /**
224
+ * Controller that registers a command handler for the host element's lifetime.
225
+ *
226
+ * @remarks
227
+ * The handler is registered when the host connects and unregistered when it disconnects.
228
+ * It automatically re-registers if the IoC container is updated.
229
+ *
230
+ * @group Commands
231
+ */
232
+ declare class OnCommandController<D = unknown, R = unknown> implements ReactiveController {
233
+ private bus;
234
+ private unregister;
235
+ private readonly type;
236
+ private readonly handler;
237
+ /**
238
+ * @param host - The host element.
239
+ * @param type - Unique identifier of the command to handle.
240
+ * @param handler - The command handler function.
241
+ */
242
+ constructor(host: ReactiveElement, type: CommandType, handler: CommandHandler<D, R>);
243
+ hostConnected(): void;
244
+ hostDisconnected(): void;
245
+ private reregister;
246
+ private cleanup;
247
+ }
248
+
249
+ /**
250
+ * Represents options for the {@link useOnCommand} hook.
251
+ *
252
+ * @group Commands
253
+ */
254
+ interface UseOnCommandOptions<D = unknown, R = unknown> {
255
+ /**
256
+ * The command type to listen for.
257
+ */
258
+ type: CommandType;
259
+ /**
260
+ * The command handler function.
261
+ */
262
+ handler: CommandHandler<D, R>;
263
+ }
264
+ /**
265
+ * Hook that registers a command handler for the host element's lifetime.
266
+ *
267
+ * @group Commands
268
+ *
269
+ * @param host - The host element.
270
+ * @param options - Command handling options.
271
+ * @param options.type - The command type to listen for.
272
+ * @param options.handler - The command handler function.
273
+ * @returns The command controller instance.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * class MyElement extends LitElement {
278
+ * private onSave = useOnCommand(this, {
279
+ * type: "SAVE",
280
+ * handler: (data) => console.log("Saving:", data),
281
+ * });
282
+ * }
283
+ * ```
284
+ */
285
+ declare function useOnCommand<D = unknown, R = unknown>(host: ReactiveElement, { type, handler }: UseOnCommandOptions<D, R>): OnCommandController<D, R>;
286
+
287
+ /**
288
+ * Represents type definition for the on-event decorator.
289
+ *
290
+ * @remarks
291
+ * Supports both TC39 and legacy experimental decorators.
292
+ *
293
+ * @group Events
294
+ */
295
+ interface OnEventDecorator<E extends Event = Event> {
296
+ <This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, event: E) => void, context: ClassMethodDecoratorContext<This>): void;
297
+ (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
298
+ }
299
+ /**
300
+ * Decorator for Lit element methods that handle events from the event bus.
301
+ *
302
+ * @remarks
303
+ * The handler is registered when the host connects and unregistered when it disconnects.
304
+ *
305
+ * @group Events
306
+ *
307
+ * @param types - Event types to listen for. If omitted, all events will be handled.
308
+ * @returns A method decorator function.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * class MyElement extends LitElement {
313
+ * @onEvent()
314
+ * private onMyEvent(event: Event) {
315
+ * console.log("Event received:", event);
316
+ * }
317
+ * }
318
+ * ```
319
+ *
320
+ * @example
321
+ * ```typescript
322
+ * class MyElement extends LitElement {
323
+ * @onEvent("MY_EVENT_TYPE")
324
+ * private onMyEvent(event: MyEvent) {
325
+ * console.log("Event received:", event);
326
+ * }
327
+ * }
328
+ * ```
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * class MyElement extends LitElement {
333
+ * @onEvent(["MY_EVENT_TYPE_1", "MY_EVENT_TYPE_2"])
334
+ * private onMyEvent(event: Event) {
335
+ * console.log("Event received:", event);
336
+ * }
337
+ * }
338
+ * ```
339
+ */
340
+ declare function onEvent<E extends Event = Event>(types?: EventType | ReadonlyArray<EventType>): OnEventDecorator<E>;
341
+
342
+ /**
343
+ * Controller that subscribes to events for the host element's lifetime.
344
+ *
345
+ * @remarks
346
+ * The handler is registered when the host connects and unregistered when it disconnects.
347
+ * It automatically re-subscribes if the IoC container is updated.
348
+ *
349
+ * @group Events
350
+ */
351
+ declare class OnEventController<E extends Event = Event> implements ReactiveController {
352
+ private bus;
353
+ private unsubscriber;
354
+ private readonly types;
355
+ private readonly handler;
356
+ /**
357
+ * @param host - The host element.
358
+ * @param types - Event types to listen for. If null, all events will be handled.
359
+ * @param handler - The event handler function.
360
+ */
361
+ constructor(host: ReactiveElement, types: Optional<ReadonlyArray<EventType>>, handler: EventHandler<E>);
362
+ hostConnected(): void;
363
+ hostDisconnected(): void;
364
+ private resubscribe;
365
+ private cleanup;
366
+ }
367
+
368
+ /**
369
+ * Represents options for the {@link useOnEvents} hook.
370
+ *
371
+ * @group Events
372
+ */
373
+ interface UseOnEventsOptions<E extends Event = Event> {
374
+ /**
375
+ * The event handler function.
376
+ */
377
+ handler: EventHandler<E>;
378
+ /**
379
+ * Event types to listen for. If null or undefined, all events will be handled.
380
+ */
381
+ types?: Optional<EventType | ReadonlyArray<EventType>>;
382
+ }
383
+ /**
384
+ * Hook that subscribes to events for the host element's lifetime.
385
+ *
386
+ * @group Events
387
+ *
388
+ * @param host - The host element.
389
+ * @param options - Event handling options.
390
+ * @param options.handler - Event handler function.
391
+ * @param options.types - Event types to listen for, if null or undefined, all events will be handled.
392
+ * @returns An instance of {@link OnEventController}.
393
+ *
394
+ * @example
395
+ * ```typescript
396
+ * class MyElement extends LitElement {
397
+ * private eventHandler = useOnEvents(this, {
398
+ * handler: (event) => console.log(event),
399
+ * });
400
+ * }
401
+ * ```
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * class MyElement extends LitElement {
406
+ * private eventHandler = useOnEvents(this, {
407
+ * types: ["MY_EVENT"],
408
+ * handler: (event) => console.log(event),
409
+ * });
410
+ * }
411
+ * ```
412
+ */
413
+ declare function useOnEvents<E extends Event = Event>(host: ReactiveElement, { types, handler }: UseOnEventsOptions): OnEventController<E>;
414
+
415
+ /**
416
+ * Represents interface for the {@link onQuery} decorator.
417
+ *
418
+ * @remarks
419
+ * Supports both TC39 and legacy experimental decorators.
420
+ *
421
+ * @group Queries
422
+ */
423
+ interface OnQueryDecorator<D = unknown, R = unknown> {
424
+ <This extends Interface<Omit<ReactiveElement, "renderRoot">>>(value: (this: This, data: D) => MaybePromise<R>, context: ClassMethodDecoratorContext<This>): void;
425
+ (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
426
+ }
427
+ /**
428
+ * Decorator for Lit element methods that handle a specific query.
429
+ *
430
+ * @remarks
431
+ * The handler is registered when the host connects and unregistered when it disconnects.
432
+ *
433
+ * @group Queries
434
+ *
435
+ * @param type - Unique identifier of the query to handle.
436
+ * @returns A method decorator function.
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * class MyElement extends LitElement {
441
+ * @onQuery("GET_USER_NAME")
442
+ * private onGetUserName(data: QueryData) {
443
+ * return "Alice";
444
+ * }
445
+ * }
446
+ * ```
447
+ */
448
+ declare function onQuery<D = unknown, R = unknown>(type: QueryType): OnQueryDecorator<D, R>;
42
449
 
450
+ /**
451
+ * Reactive controller that registers a query handler on the {@link QueryBus} for the host element's lifetime.
452
+ *
453
+ * @remarks
454
+ * The handler is registered when the host connects and unregistered when it disconnects.
455
+ * It automatically re-registers if the IoC container is updated.
456
+ *
457
+ * @group Queries
458
+ */
459
+ declare class OnQueryController<D = unknown, R = unknown> implements ReactiveController {
460
+ private bus;
461
+ private unregister;
462
+ private readonly type;
463
+ private readonly handler;
464
+ /**
465
+ * @param host - The host element.
466
+ * @param type - Unique identifier of the query to handle.
467
+ * @param handler - The query handler function.
468
+ */
469
+ constructor(host: ReactiveElement, type: QueryType, handler: QueryHandler<D, R>);
470
+ hostConnected(): void;
471
+ hostDisconnected(): void;
472
+ private reregister;
473
+ private cleanup;
474
+ }
475
+
476
+ /**
477
+ * Represents options for the {@link useOnQuery} hook.
478
+ *
479
+ * @group Queries
480
+ */
481
+ interface UseOnQueryOptions<D = unknown, R = unknown> {
482
+ /**
483
+ * The query type to handle.
484
+ */
485
+ type: QueryType;
486
+ /**
487
+ * The query handler function.
488
+ */
489
+ handler: QueryHandler<D, R>;
490
+ }
491
+ /**
492
+ * Hook that registers a query handler for the host element's lifetime.
493
+ *
494
+ * @group Queries
495
+ *
496
+ * @param host - The host element.
497
+ * @param options - Query handling options.
498
+ * @param options.type - The query type to handle.
499
+ * @param options.handler - The query handler function.
500
+ * @returns An instance of {@link OnQueryController}.
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * class MyElement extends LitElement {
505
+ * private getUserController = useOnQuery(this, {
506
+ * type: "GET_USER",
507
+ * handler: (data) => ({ name: "Alice" }),
508
+ * });
509
+ * }
510
+ * ```
511
+ */
512
+ declare function useOnQuery<D = unknown, R = unknown>(host: ReactiveElement, { type, handler }: UseOnQueryOptions<D, R>): OnQueryController<D, R>;
513
+
514
+ /**
515
+ * Interface for the IoC context value.
516
+ *
517
+ * @group Context
518
+ */
43
519
  interface IocContext {
44
520
  /**
45
- * Inversify container.
521
+ * The IoC container instance.
46
522
  */
47
523
  readonly container: Container;
48
524
  /**
@@ -50,47 +526,272 @@ interface IocContext {
50
526
  */
51
527
  readonly revision: number;
52
528
  /**
53
- * Forces a revision update.
529
+ * Function to force a revision update.
54
530
  */
55
531
  readonly nextRevision: () => number;
56
532
  }
57
- declare const ContainerContext: {
533
+ /**
534
+ * Lit context object for providing and consuming the IoC container.
535
+ *
536
+ * @group Context
537
+ */
538
+ declare const IocContextObject: {
58
539
  __context__: IocContext;
59
540
  };
60
541
 
61
- declare class ContainerProviderController implements ReactiveController {
542
+ /**
543
+ * Represents options for the {@link IocProviderController}.
544
+ *
545
+ * @group Provision
546
+ */
547
+ interface IocProviderControllerOptions {
548
+ /**
549
+ * Optional existing container to use. If not provided, a new one will be created.
550
+ */
551
+ container?: Container;
552
+ /**
553
+ * Optional seed data to apply to the container.
554
+ */
555
+ seed?: AnyObject;
556
+ }
557
+ /**
558
+ * Controller that provides an IoC container context to the host element and its children.
559
+ *
560
+ * @remarks
561
+ * It manages the lifecycle of the container and handles revision updates to notify consumers.
562
+ * The container is created (or used from options) when the controller is instantiated.
563
+ * Seed data is applied when the host connects.
564
+ *
565
+ * @group Provision
566
+ */
567
+ declare class IocProviderController<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> implements ReactiveController {
62
568
  private readonly host;
63
- protected provider: ContextProvider<typeof ContainerContext>;
569
+ protected readonly provider: ContextProvider<typeof IocContextObject>;
570
+ protected readonly seed?: AnyObject;
64
571
  protected revision: number;
572
+ /**
573
+ * The managed Inversify IoC container.
574
+ */
65
575
  container: Container;
66
- constructor(host: ReactiveControllerHost & HTMLElement, container?: Maybe<Container>);
576
+ /**
577
+ * @returns Current {@link IocContext} value served to child consumers.
578
+ */
579
+ get value(): IocContext;
580
+ /**
581
+ * @param host - The host element.
582
+ * @param options - Provisioning options.
583
+ * @param options.container - Optional existing container to use. If not provided, a new one will be created.
584
+ * @param options.seed - Optional seed data to apply to the container.
585
+ */
586
+ constructor(host: E, { container, seed }?: IocProviderControllerOptions);
67
587
  hostConnected(): void;
68
588
  hostDisconnected(): void;
69
589
  nextRevision(): number;
70
590
  }
71
591
 
72
- interface ServicesProviderControllerOptions {
592
+ /**
593
+ * Represents interface for the {@link iocProvide} decorator.
594
+ *
595
+ * @remarks
596
+ * Supports both TC39 and legacy experimental decorators.
597
+ *
598
+ * @group Provision
599
+ */
600
+ interface IocProviderDecorator<E extends ReactiveElement = ReactiveElement> {
601
+ <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends IocProviderController<E>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
602
+ <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, IocProviderController<E>>;
603
+ }
604
+ /**
605
+ * Decorator that provides an IoC container to child components.
606
+ *
607
+ * @remarks
608
+ * The container is provided via Lit context. It is created (or used from options) when the host connects.
609
+ *
610
+ * @group Provision
611
+ *
612
+ * @param options - Provisioning options.
613
+ * @param options.container - Optional existing container to use, if not provided, a new one will be created.
614
+ * @param options.seed - Optional seed data to apply to the container.
615
+ * @returns An instance of {@link IocProviderDecorator}.
616
+ *
617
+ * @example
618
+ * ```typescript
619
+ * class MyRootElement extends LitElement {
620
+ * @iocProvide({ seed: { someData: "value" } })
621
+ * private ioc!: IocProviderController;
622
+ * }
623
+ * ```
624
+ */
625
+ declare function iocProvide<E extends ReactiveElement>({ container, seed, }?: IocProviderControllerOptions): IocProviderDecorator<E>;
626
+
627
+ /**
628
+ * Represents a function that returns a value of type `T`.
629
+ *
630
+ * @group general-types
631
+ *
632
+ * @template T - The return type of the function.
633
+ */
634
+ type Callable<T> = () => T;
635
+
636
+ /**
637
+ * Represents options for the {@link InjectablesProviderController}.
638
+ *
639
+ * @group Provision
640
+ */
641
+ interface InjectablesProviderControllerOptions {
642
+ /**
643
+ * List of service entries to bind to the container.
644
+ */
73
645
  entries: ReadonlyArray<Newable<object> | InjectableDescriptor>;
74
- into?: IocContext | (() => IocContext);
646
+ /**
647
+ * Target IoC context to bind injectables into.
648
+ * If not provided, uses the context from the nearest provider.
649
+ * Accepts a static {@link IocContext} reference or a resolver function.
650
+ */
651
+ into?: IocContext | Callable<IocContext>;
652
+ /**
653
+ * List of service identifiers to activate (get from container) immediately after binding.
654
+ */
75
655
  activate?: ReadonlyArray<ServiceIdentifier>;
656
+ /**
657
+ * Seed data to apply to the container before binding.
658
+ * Applied before entries are bound so that `@Inject(SEEDS_TOKEN)` works during activation.
659
+ */
76
660
  seeds?: SeedEntries;
77
661
  }
78
- declare class ServicesProviderController<E extends ReactiveControllerHost & HTMLElement> implements ReactiveController {
662
+ /**
663
+ * Controller that binds injectables to an IoC container for the host element's lifetime.
664
+ *
665
+ * @remarks
666
+ * Entries are bound when the host connects and unbound when it disconnects.
667
+ * If no `into` context is provided, it uses the nearest {@link IocProviderController}.
668
+ * Seeds are applied before entries are bound.
669
+ *
670
+ * @group Provision
671
+ *
672
+ * @example
673
+ * ```typescript
674
+ * class MyComponent extends LitElement {
675
+ * private services = new InjectablesProviderController(this, {
676
+ * entries: [AuthService, UserService],
677
+ * activate: [AuthService],
678
+ * seeds: [[AuthService, { role: "admin" }]],
679
+ * });
680
+ * }
681
+ * ```
682
+ */
683
+ declare class InjectablesProviderController<E extends ReactiveControllerHost & HTMLElement = ReactiveControllerHost & HTMLElement> implements ReactiveController {
79
684
  private readonly host;
80
- readonly consumer: ContextConsumer<typeof ContainerContext, E>;
81
- readonly entries: ReadonlyArray<Newable<object> | InjectableDescriptor>;
82
- readonly activate: Maybe<ReadonlyArray<ServiceIdentifier>>;
83
- readonly seeds: Maybe<SeedEntries>;
84
- readonly into: Maybe<IocContext | Callable<IocContext>>;
85
- constructor(host: E, options: ServicesProviderControllerOptions);
685
+ protected readonly consumer?: ContextConsumer<typeof IocContextObject, E>;
686
+ private readonly entries;
687
+ private readonly activate;
688
+ private readonly seeds;
689
+ private readonly into;
690
+ /**
691
+ * Tracks the context to which entries are currently bound, for correct cleanup on disconnect.
692
+ */
693
+ private boundContext;
694
+ /**
695
+ * @param host - The host element.
696
+ * @param options - Provisioning options.
697
+ * @param options.entries - List of service entries to bind to the container.
698
+ * @param options.into - Target IoC context; if omitted, uses the nearest provider context.
699
+ * @param options.activate - List of service identifiers to activate immediately after binding.
700
+ * @param options.seeds - Seed data applied before binding.
701
+ */
702
+ constructor(host: E, options: InjectablesProviderControllerOptions);
86
703
  hostConnected(): void;
87
704
  hostDisconnected(): void;
705
+ private bind;
706
+ private unbind;
707
+ }
708
+
709
+ /**
710
+ * Represents type for the {@link injectablesProvide} decorator.
711
+ *
712
+ * @remarks
713
+ * Supports both TC39 and legacy experimental decorators.
714
+ *
715
+ * @group Provision
716
+ */
717
+ interface InjectablesProviderDecorator<T extends ReactiveElement = ReactiveElement> {
718
+ <C extends Interface<Omit<ReactiveElement, "renderRoot">>, V extends InjectablesProviderController<T>>(value: ClassAccessorDecoratorTarget<C, V>, context: ClassAccessorDecoratorContext<C, V>): void;
719
+ <K extends PropertyKey, Proto extends Interface<Omit<ReactiveElement, "renderRoot">>>(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType<Proto, K, InjectablesProviderController<T>>;
88
720
  }
721
+ /**
722
+ * Decorator that binds a set of injectables to the nearest IoC container for the host element's lifetime.
723
+ *
724
+ * @remarks
725
+ * Entries are bound when the host connects and unbound when it disconnects.
726
+ *
727
+ * @group Provision
728
+ *
729
+ * @param options - Provisioning options.
730
+ * @returns An instance of {@link InjectablesProviderDecorator}.
731
+ *
732
+ * @example
733
+ * ```typescript
734
+ * class MyComponent extends LitElement {
735
+ * @injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
736
+ * public controller!: InjectablesProviderController<MyComponent>;
737
+ * }
738
+ * ```
739
+ */
740
+ declare function injectablesProvide<E extends ReactiveElement = ReactiveElement>(options: InjectablesProviderControllerOptions): InjectablesProviderDecorator<E>;
89
741
 
90
- interface UseContainerProvisionOptions {
742
+ /**
743
+ * Hook that binds injectables to the nearest IoC container for the host element's lifetime.
744
+ *
745
+ * @group Provision
746
+ *
747
+ * @param host - The host element.
748
+ * @param options - Provisioning options.
749
+ * @returns An instance of {@link InjectablesProviderController}.
750
+ *
751
+ * @example
752
+ * ```typescript
753
+ * class MyComponent extends LitElement {
754
+ * private services = useInjectablesProvider(this, {
755
+ * entries: [AuthService, UserService],
756
+ * activate: [AuthService],
757
+ * });
758
+ * }
759
+ * ```
760
+ */
761
+ declare function useInjectablesProvider<E extends ReactiveControllerHost & HTMLElement>(host: E, options: InjectablesProviderControllerOptions): InjectablesProviderController<E>;
762
+
763
+ /**
764
+ * Represents options for the {@link useIocProvision} hook.
765
+ *
766
+ * @group Provision
767
+ */
768
+ interface UseIocProvisionOptions {
769
+ /**
770
+ * Optional existing container to use.
771
+ */
91
772
  container?: Container;
773
+ /**
774
+ * Optional seed data to apply to the container.
775
+ */
776
+ seed?: AnyObject;
92
777
  }
93
- declare function useContainerProvision<E extends ReactiveControllerHost & HTMLElement>(host: E, { container }: UseContainerProvisionOptions): UseContainerProvisionOptions;
778
+ /**
779
+ * Hook that provides an IoC container to the host element and its children.
780
+ *
781
+ * @group Provision
782
+ *
783
+ * @param host - The host element.
784
+ * @param options - Provisioning options.
785
+ * @returns An instance of {@link IocProviderController}.
786
+ *
787
+ * @example
788
+ * ```typescript
789
+ * class MyRootElement extends LitElement {
790
+ * private ioc = useIocProvision(this, { seed: { initialData: "..." } });
791
+ * }
792
+ * ```
793
+ */
794
+ declare function useIocProvision<E extends ReactiveControllerHost & HTMLElement>(host: E, options?: UseIocProvisionOptions): IocProviderController<E>;
94
795
 
95
- export { ContainerContext, ContainerProviderController, ServicesProviderController, injection, useContainerProvision, useInjection };
96
- export type { InjectionDecorator, UseInjectionOptions, UseInjectionValue };
796
+ export { InjectablesProviderController, IocContextObject, IocProviderController, OnCommandController, OnEventController, OnQueryController, injectablesProvide, injection, iocProvide, onCommand, onEvent, onQuery, useInjectablesProvider, useInjection, useIocProvision, useOnCommand, useOnEvents, useOnQuery };
797
+ export type { InjectablesProviderControllerOptions, InjectablesProviderDecorator, InjectionDecorator, InjectionOptions, IocContext, IocProviderControllerOptions, IocProviderDecorator, OnCommandDecorator, OnEventDecorator, OnQueryDecorator, UseInjectionOptions, UseInjectionValue, UseIocProvisionOptions, UseOnCommandOptions, UseOnEventsOptions, UseOnQueryOptions };