@microsoft/fast-element 2.0.0-beta.1 → 2.0.0-beta.4

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 (58) hide show
  1. package/CHANGELOG.json +147 -0
  2. package/CHANGELOG.md +42 -1
  3. package/dist/dts/components/fast-definitions.d.ts +11 -8
  4. package/dist/dts/components/fast-element.d.ts +13 -3
  5. package/dist/dts/context.d.ts +157 -0
  6. package/dist/dts/di/di.d.ts +854 -0
  7. package/dist/dts/hooks.d.ts +2 -2
  8. package/dist/dts/interfaces.d.ts +39 -7
  9. package/dist/dts/metadata.d.ts +25 -0
  10. package/dist/dts/observation/arrays.d.ts +1 -1
  11. package/dist/dts/observation/behavior.d.ts +4 -4
  12. package/dist/dts/observation/observable.d.ts +59 -72
  13. package/dist/dts/styles/element-styles.d.ts +6 -0
  14. package/dist/dts/templating/binding-signal.d.ts +21 -0
  15. package/dist/dts/templating/binding-two-way.d.ts +31 -0
  16. package/dist/dts/templating/binding.d.ts +74 -201
  17. package/dist/dts/templating/compiler.d.ts +1 -2
  18. package/dist/dts/templating/html-directive.d.ts +31 -3
  19. package/dist/dts/templating/render.d.ts +277 -0
  20. package/dist/dts/templating/repeat.d.ts +13 -63
  21. package/dist/dts/templating/template.d.ts +11 -60
  22. package/dist/dts/templating/view.d.ts +9 -9
  23. package/dist/dts/templating/when.d.ts +3 -3
  24. package/dist/dts/testing/exports.d.ts +2 -0
  25. package/dist/dts/testing/fixture.d.ts +90 -0
  26. package/dist/dts/testing/timeout.d.ts +7 -0
  27. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +0 -0
  28. package/dist/esm/components/fast-definitions.js +27 -27
  29. package/dist/esm/components/fast-element.js +20 -4
  30. package/dist/esm/context.js +163 -0
  31. package/dist/esm/debug.js +35 -4
  32. package/dist/esm/di/di.js +1349 -0
  33. package/dist/esm/metadata.js +60 -0
  34. package/dist/esm/observation/arrays.js +1 -1
  35. package/dist/esm/observation/observable.js +73 -21
  36. package/dist/esm/platform.js +1 -1
  37. package/dist/esm/styles/element-styles.js +14 -0
  38. package/dist/esm/templating/binding-signal.js +79 -0
  39. package/dist/esm/templating/binding-two-way.js +98 -0
  40. package/dist/esm/templating/binding.js +137 -313
  41. package/dist/esm/templating/compiler.js +30 -7
  42. package/dist/esm/templating/html-directive.js +16 -2
  43. package/dist/esm/templating/render.js +392 -0
  44. package/dist/esm/templating/repeat.js +60 -38
  45. package/dist/esm/templating/template.js +9 -26
  46. package/dist/esm/templating/when.js +5 -4
  47. package/dist/esm/testing/exports.js +2 -0
  48. package/dist/esm/testing/fixture.js +88 -0
  49. package/dist/esm/testing/timeout.js +24 -0
  50. package/dist/fast-element.api.json +8509 -10358
  51. package/dist/fast-element.d.ts +315 -522
  52. package/dist/fast-element.debug.js +417 -438
  53. package/dist/fast-element.debug.min.js +1 -1
  54. package/dist/fast-element.js +382 -434
  55. package/dist/fast-element.min.js +1 -1
  56. package/dist/fast-element.untrimmed.d.ts +324 -529
  57. package/docs/api-report.md +124 -232
  58. package/package.json +32 -4
@@ -0,0 +1,854 @@
1
+ import { ContextDecorator } from "../context.js";
2
+ import { Constructable } from "../interfaces.js";
3
+ /**
4
+ * Represents a custom callback for resolving a request from the container.
5
+ * The handler is the container that is invoking the callback. The requestor
6
+ * is the original container that made the request. The handler and the requestor
7
+ * may not be the same if the request has bubbled up to a parent container in the DI hierarchy.
8
+ * The resolver is the instance of the resolver that stores the callback. This is provided in case
9
+ * the callback needs a place or key against which to store state across resolutions.
10
+ * @public
11
+ */
12
+ export declare type ResolveCallback<T = any> = (handler: Container, requestor: Container, resolver: Resolver<T>) => T;
13
+ interface ResolverLike<C, K = any> {
14
+ readonly $isResolver: true;
15
+ resolve(handler: C, requestor: C): Resolved<K>;
16
+ getFactory?(container: C): (K extends Constructable ? Factory<K> : never) | null;
17
+ }
18
+ /**
19
+ * Internally, the DI system maps "keys" to "resolvers". A resolver controls
20
+ * how a dependency is resolved. Resolvers for transient, singleton, etc. are
21
+ * provided out of the box, but you can also implement Resolver yourself and supply
22
+ * custom logic for resolution.
23
+ * @public
24
+ */
25
+ export interface Resolver<K = any> extends ResolverLike<Container, K> {
26
+ }
27
+ /**
28
+ * Implemented by objects that wish to register dependencies in the container
29
+ * by creating resolvers.
30
+ * @public
31
+ */
32
+ export interface Registration<K = any> {
33
+ /**
34
+ * Creates a resolver for a desired dependency.
35
+ * @param container - The container to register the dependency within.
36
+ * @param key - The key to register dependency under, if overridden.
37
+ */
38
+ register(container: Container): Resolver<K>;
39
+ }
40
+ /**
41
+ * Transforms an object after it is created but before it is returned
42
+ * to the requestor.
43
+ * @public
44
+ */
45
+ export declare type Transformer<K> = (instance: Resolved<K>) => Resolved<K>;
46
+ /**
47
+ * Used by the default Resolver to create instances of objects when needed.
48
+ * @public
49
+ */
50
+ export interface Factory<T extends Constructable = any> {
51
+ /**
52
+ * The concrete type this factory creates.
53
+ */
54
+ readonly Type: T;
55
+ /**
56
+ * Registers a transformer function to alter the object after instantiation but before
57
+ * returning the final constructed instance.
58
+ * @param transformer - The transformer function.
59
+ */
60
+ registerTransformer(transformer: Transformer<T>): void;
61
+ /**
62
+ * Constructs an instance of the factory's object.
63
+ * @param container - The container the object is being constructor for.
64
+ * @param dynamicDependencies - Dynamic dependencies supplied to the constructor.
65
+ */
66
+ construct(container: Container, dynamicDependencies?: Key[]): Resolved<T>;
67
+ }
68
+ /**
69
+ * Implemented by objects capable of resolving services and other dependencies.
70
+ * @public
71
+ */
72
+ export interface ServiceLocator {
73
+ /**
74
+ * Determines whether the locator has the ability to provide an implementation
75
+ * for the requested key.
76
+ * @param key - The dependency key to lookup.
77
+ * @param searchAncestors - Indicates whether to search the entire hierarchy of service locators.
78
+ */
79
+ has<K extends Key>(key: K | Key, searchAncestors: boolean): boolean;
80
+ /**
81
+ * Gets a dependency by key.
82
+ * @param key - The key to lookup.
83
+ */
84
+ get<K extends Key>(key: K): Resolved<K>;
85
+ /**
86
+ * Gets a dependency by key.
87
+ * @param key - The key to lookup.
88
+ */
89
+ get<K extends Key>(key: Key): Resolved<K>;
90
+ /**
91
+ * Gets a dependency by key.
92
+ * @param key - The key to lookup.
93
+ */
94
+ get<K extends Key>(key: K | Key): Resolved<K>;
95
+ /**
96
+ * Gets an array of all dependencies by key.
97
+ * @param key - The key to lookup.
98
+ * @param searchAncestors - Indicates whether to search the entire hierarchy of service locators.
99
+ */
100
+ getAll<K extends Key>(key: K, searchAncestors?: boolean): readonly Resolved<K>[];
101
+ /**
102
+ * Gets an array of all dependencies by key.
103
+ * @param key - The key to lookup.
104
+ * @param searchAncestors - Indicates whether to search the entire hierarchy of service locators.
105
+ */
106
+ getAll<K extends Key>(key: Key, searchAncestors?: boolean): readonly Resolved<K>[];
107
+ /**
108
+ * Gets an array of all dependencies by key.
109
+ * @param key - The key to lookup.
110
+ * @param searchAncestors - Indicates whether to search the entire hierarchy of service locators.
111
+ */
112
+ getAll<K extends Key>(key: K | Key, searchAncestors?: boolean): readonly Resolved<K>[];
113
+ }
114
+ /**
115
+ * Implemented by objects that which to register dependencies in a container.
116
+ * @public
117
+ */
118
+ export interface Registry {
119
+ /**
120
+ * Registers dependencies in the specified container.
121
+ * @param container - The container to register dependencies in.
122
+ * @param params - Parameters that affect the registration process.
123
+ * @remarks
124
+ * If this registry doubles as a Registration, it should return a Resolver
125
+ * for the registered dependency.
126
+ */
127
+ register(container: Container, ...params: unknown[]): void | Resolver;
128
+ }
129
+ /**
130
+ * Implemented by dependency injection containers.
131
+ * @public
132
+ */
133
+ export interface Container extends ServiceLocator {
134
+ /**
135
+ * Registers dependencies with the container via registration objects.
136
+ * @param params - The registration objects.
137
+ */
138
+ register(...params: any[]): Container;
139
+ /**
140
+ * Registers a resolver with the container for the specified key.
141
+ * @param key - The key to register the resolver under.
142
+ * @param resolver - The resolver to register.
143
+ */
144
+ registerResolver<K extends Key, T = K>(key: K, resolver: Resolver<T>): Resolver<T>;
145
+ /**
146
+ * Registers a transformer with the container for the specified key.
147
+ * @param key - The key to resolved to register the transformer with.
148
+ * @param transformer - The transformer to register.
149
+ */
150
+ registerTransformer<K extends Key, T = K>(key: K, transformer: Transformer<T>): boolean;
151
+ /**
152
+ * Gets a resolver for the specified key.
153
+ * @param key - The key to get the resolver for.
154
+ * @param autoRegister - Indicates whether or not to try to auto-register a dependency for
155
+ * the key if one is not explicitly registered.
156
+ */
157
+ getResolver<K extends Key, T = K>(key: K | Key, autoRegister?: boolean): Resolver<T> | null;
158
+ /**
159
+ * Registers a factory with the container for the specified key.
160
+ * @param key - The key to register the factory under.
161
+ * @param factory - The factory to register.
162
+ */
163
+ registerFactory<T extends Constructable>(key: T, factory: Factory<T>): void;
164
+ /**
165
+ * Gets the factory for the specified key.
166
+ * @param key - The key to get the factory for.
167
+ */
168
+ getFactory<T extends Constructable>(key: T): Factory<T>;
169
+ /**
170
+ * Creates a child dependency injection container parented to this container.
171
+ * @param config - The configuration for the new container.
172
+ */
173
+ createChild(config?: Partial<Omit<ContainerConfiguration, "parentLocator">>): Container;
174
+ }
175
+ /**
176
+ * A Container that is associated with a specific Node in the DOM.
177
+ * @public
178
+ */
179
+ export interface DOMContainer extends Container {
180
+ /**
181
+ * Instructs this particular Container to handle W3C Community Context requests
182
+ * that propagate to its associated DOM node.
183
+ * @param enable - true to enable context requests handling; false otherwise.
184
+ * @beta
185
+ */
186
+ handleContextRequests(enable: boolean): void;
187
+ }
188
+ /**
189
+ * A utility class used that constructs and registers resolvers for a dependency
190
+ * injection container. Supports a standard set of object lifetimes.
191
+ * @public
192
+ */
193
+ export declare class ResolverBuilder<K> {
194
+ private container;
195
+ private key;
196
+ /**
197
+ *
198
+ * @param container - The container to create resolvers for.
199
+ * @param key - The key to register resolvers under.
200
+ */
201
+ constructor(container: Container, key: Key);
202
+ /**
203
+ * Creates a resolver for an existing object instance.
204
+ * @param value - The instance to resolve.
205
+ * @returns The resolver.
206
+ */
207
+ instance(value: K): Resolver<K>;
208
+ /**
209
+ * Creates a resolver that enforces a singleton lifetime.
210
+ * @param value - The type to create and cache the singleton for.
211
+ * @returns The resolver.
212
+ */
213
+ singleton(value: Constructable): Resolver<K>;
214
+ /**
215
+ * Creates a resolver that creates a new instance for every dependency request.
216
+ * @param value - The type to create instances of.
217
+ * @returns - The resolver.
218
+ */
219
+ transient(value: Constructable): Resolver<K>;
220
+ /**
221
+ * Creates a resolver that invokes a callback function for every dependency resolution
222
+ * request, allowing custom logic to return the dependency.
223
+ * @param value - The callback to call during resolution.
224
+ * @returns The resolver.
225
+ */
226
+ callback(value: ResolveCallback<K>): Resolver<K>;
227
+ /**
228
+ * Creates a resolver that invokes a callback function the first time that a dependency
229
+ * resolution is requested. The returned value is then cached and provided for all
230
+ * subsequent requests.
231
+ * @param value - The callback to call during the first resolution.
232
+ * @returns The resolver.
233
+ */
234
+ cachedCallback(value: ResolveCallback<K>): Resolver<K>;
235
+ /**
236
+ * Aliases the current key to a different key.
237
+ * @param destinationKey - The key to point the alias to.
238
+ * @returns The resolver.
239
+ */
240
+ aliasTo(destinationKey: Key): Resolver<K>;
241
+ private registerResolver;
242
+ }
243
+ /**
244
+ * Represents an object that can register itself.
245
+ * @public
246
+ */
247
+ export declare type RegisterSelf<T extends Constructable> = {
248
+ /**
249
+ * Registers itself with the container.
250
+ * @param container - The container to register with.
251
+ */
252
+ register(container: Container): Resolver<InstanceType<T>>;
253
+ /**
254
+ * Indicates whether during auto registration the object should be
255
+ * registered in the requesting container rather than the handling container.
256
+ */
257
+ registerInRequestor: boolean;
258
+ };
259
+ /**
260
+ * A key that is used to register dependencies with a dependency injection container.
261
+ * @public
262
+ */
263
+ export declare type Key = PropertyKey | object | ContextDecorator | Constructable | Resolver;
264
+ /**
265
+ * Represents something resolved from a service locator.
266
+ * @public
267
+ */
268
+ export declare type Resolved<K> = K extends ContextDecorator<infer T> ? T : K extends Constructable ? InstanceType<K> : K extends ResolverLike<any, infer T1> ? T1 extends Constructable ? InstanceType<T1> : T1 : K;
269
+ /**
270
+ * A class that declares constructor injected dependencies through
271
+ * a static "inject" field array of keys.
272
+ * @public
273
+ */
274
+ export declare type Injectable<T = {}> = Constructable<T> & {
275
+ inject?: Key[];
276
+ };
277
+ /**
278
+ * A function capable of locating the parent container based on a container's owner.
279
+ * @remarks
280
+ * A container owner is usually an HTMLElement instance.
281
+ * @public
282
+ */
283
+ export declare type ParentLocator = (owner: any) => Container | null;
284
+ /**
285
+ * Configuration for a dependency injection container.
286
+ * @public
287
+ */
288
+ export interface ContainerConfiguration {
289
+ /**
290
+ * The locator function used to find the parent of the container.
291
+ */
292
+ parentLocator: ParentLocator;
293
+ /**
294
+ * Indicates whether this container should resolve dependencies that are directly made
295
+ * by its owner. The default is "false" which results in the parent container being used.
296
+ */
297
+ responsibleForOwnerRequests: boolean;
298
+ /**
299
+ * Gets the default resolver to use during auto-registration.
300
+ * @param key - The key to register the dependency with.
301
+ * @param handler - The container that is handling the auto-registration request.
302
+ */
303
+ defaultResolver(key: Key, handler: Container): Resolver;
304
+ }
305
+ /**
306
+ * A set of default resolvers useful in configuring a container.
307
+ * @public
308
+ */
309
+ export declare const DefaultResolver: Readonly<{
310
+ /**
311
+ * Disables auto-registration and throws for all un-registered dependencies.
312
+ * @param key - The key to create the resolver for.
313
+ */
314
+ none(key: Key): Resolver;
315
+ /**
316
+ * Provides default singleton resolution behavior during auto-registration.
317
+ * @param key - The key to create the resolver for.
318
+ * @returns The resolver.
319
+ */
320
+ singleton(key: Key): Resolver;
321
+ /**
322
+ * Provides default transient resolution behavior during auto-registration.
323
+ * @param key - The key to create the resolver for.
324
+ * @returns The resolver.
325
+ */
326
+ transient(key: Key): Resolver;
327
+ }>;
328
+ /**
329
+ * Configuration for a dependency injection container.
330
+ * @public
331
+ */
332
+ export declare const ContainerConfiguration: Readonly<{
333
+ /**
334
+ * The default configuration used when creating a DOM-disconnected container.
335
+ * @remarks
336
+ * The default creates a root container, with no parent container. It does not handle
337
+ * owner requests and it uses singleton resolution behavior for auto-registration.
338
+ */
339
+ default: Readonly<ContainerConfiguration>;
340
+ }>;
341
+ /**
342
+ * Used to configure a dependency injection interface key.
343
+ * @public
344
+ */
345
+ export interface InterfaceConfiguration {
346
+ /**
347
+ * The friendly name for the interface. Useful for debugging.
348
+ */
349
+ friendlyName?: string;
350
+ /**
351
+ * When true, the dependency will be re-resolved when FASTElement connection changes.
352
+ * If the resolved value changes due to connection change, a {@link @microsoft/fast-element#Observable | notification }
353
+ * will be emitted for the property, with the previous and next values provided to any subscriber.
354
+ */
355
+ respectConnection?: boolean;
356
+ }
357
+ declare function createContext<K extends Key>(nameConfigOrCallback?: string | ((builder: ResolverBuilder<K>) => Resolver<K>) | InterfaceConfiguration, configuror?: (builder: ResolverBuilder<K>) => Resolver<K>): ContextDecorator<K>;
358
+ /**
359
+ * The gateway to dependency injection APIs.
360
+ * @public
361
+ */
362
+ export declare const DI: Readonly<{
363
+ /**
364
+ * Installs dependency injection as the default strategy for handling
365
+ * all calls to Context.request.
366
+ * @param fallback - Creates a container if one cannot be found.
367
+ */
368
+ installAsContextRequestStrategy(fallback?: () => DOMContainer): void;
369
+ /**
370
+ * Creates a new dependency injection container.
371
+ * @param config - The configuration for the container.
372
+ * @returns A newly created dependency injection container.
373
+ */
374
+ createContainer(config?: Partial<ContainerConfiguration>): Container;
375
+ /**
376
+ * Finds the dependency injection container responsible for providing dependencies
377
+ * to the specified node.
378
+ * @param target - The node to find the responsible container for.
379
+ * @param fallback - Creates a container if one cannot be found.
380
+ * @returns The container responsible for providing dependencies to the node.
381
+ * @remarks
382
+ * This will be the same as the parent container if the specified node
383
+ * does not itself host a container configured with responsibleForOwnerRequests.
384
+ */
385
+ findResponsibleContainer(target: EventTarget, fallback?: () => DOMContainer): DOMContainer;
386
+ /**
387
+ * Find the dependency injection container up the DOM tree from this node.
388
+ * @param target - The node to find the parent container for.
389
+ * @param fallback - Creates a container if one cannot be found.
390
+ * @returns The parent container of this node.
391
+ * @remarks
392
+ * This will be the same as the responsible container if the specified node
393
+ * does not itself host a container configured with responsibleForOwnerRequests.
394
+ */
395
+ findParentContainer(target: EventTarget, fallback?: () => DOMContainer): DOMContainer;
396
+ /**
397
+ * Returns a dependency injection container if one is explicitly owned by the specified
398
+ * node. If one is not owned, then a new container is created and assigned to the node.
399
+ * @param target - The node to find or create the container for.
400
+ * @param config - The configuration for the container if one needs to be created.
401
+ * @returns The located or created container.
402
+ * @remarks
403
+ * This API does not search for a responsible or parent container. It looks only for a container
404
+ * directly defined on the specified node and creates one at that location if one does not
405
+ * already exist.
406
+ */
407
+ getOrCreateDOMContainer(target?: EventTarget, config?: Partial<Omit<ContainerConfiguration, "parentLocator">>): DOMContainer;
408
+ /**
409
+ * Gets the dependency keys representing what is needed to instantiate the specified type.
410
+ * @param Type - The type to get the dependencies for.
411
+ * @returns An array of dependency keys.
412
+ */
413
+ getDependencies(Type: Constructable | Injectable): Key[];
414
+ /**
415
+ * Defines a property on a web component class. The value of this property will
416
+ * be resolved from the dependency injection container responsible for the element
417
+ * instance, based on where it is connected in the DOM.
418
+ * @param target - The target to define the property on.
419
+ * @param propertyName - The name of the property to define.
420
+ * @param key - The dependency injection key.
421
+ * @param respectConnection - Indicates whether or not to update the property value if the
422
+ * hosting component is disconnected and then re-connected at a different location in the DOM.
423
+ * @remarks
424
+ * The respectConnection option is only applicable to elements that descend from FASTElement.
425
+ */
426
+ defineProperty(target: {}, propertyName: string, key: Key, respectConnection?: boolean): void;
427
+ /**
428
+ * Creates a dependency injection key.
429
+ * @param nameConfigOrCallback - A friendly name for the key or a lambda that configures a
430
+ * default resolution for the dependency.
431
+ * @param configuror - If a friendly name was provided for the first parameter, then an optional
432
+ * lambda that configures a default resolution for the dependency can be provided second.
433
+ * @returns The created key.
434
+ * @remarks
435
+ * The created key can be used as a property decorator or constructor parameter decorator,
436
+ * in addition to its standard use in an inject array or through direct container APIs.
437
+ */
438
+ createContext: typeof createContext;
439
+ /**
440
+ * @deprecated
441
+ * Use DI.createContext instead.
442
+ */
443
+ createInterface: typeof createContext;
444
+ /**
445
+ * A decorator that specifies what to inject into its target.
446
+ * @param dependencies - The dependencies to inject.
447
+ * @returns The decorator to be applied to the target class.
448
+ * @remarks
449
+ * The decorator can be used to decorate a class, listing all of the classes dependencies.
450
+ * Or it can be used to decorate a constructor parameter, indicating what to inject for that
451
+ * parameter.
452
+ * Or it can be used for a web component property, indicating what that property should resolve to.
453
+ */
454
+ inject(...dependencies: Key[]): (target: any, key?: string | number, descriptor?: PropertyDescriptor | number) => void;
455
+ /**
456
+ * Registers the `target` class as a transient dependency; each time the dependency is resolved
457
+ * a new instance will be created.
458
+ *
459
+ * @param target - The class / constructor function to register as transient.
460
+ * @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver.
461
+ *
462
+ * @example
463
+ * On an existing class
464
+ * ```ts
465
+ * class Foo { }
466
+ * DI.transient(Foo);
467
+ * ```
468
+ *
469
+ * @example
470
+ * Inline declaration
471
+ *
472
+ * ```ts
473
+ * const Foo = DI.transient(class { });
474
+ * // Foo is now strongly typed with register
475
+ * Foo.register(container);
476
+ * ```
477
+ *
478
+ * @public
479
+ */
480
+ transient<T extends Constructable<{}>>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
481
+ /**
482
+ * Registers the `target` class as a singleton dependency; the class will only be created once. Each
483
+ * consecutive time the dependency is resolved, the same instance will be returned.
484
+ *
485
+ * @param target - The class / constructor function to register as a singleton.
486
+ * @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver.
487
+ * @example
488
+ * On an existing class
489
+ * ```ts
490
+ * class Foo { }
491
+ * DI.singleton(Foo);
492
+ * ```
493
+ *
494
+ * @example
495
+ * Inline declaration
496
+ * ```ts
497
+ * const Foo = DI.singleton(class { });
498
+ * // Foo is now strongly typed with register
499
+ * Foo.register(container);
500
+ * ```
501
+ *
502
+ * @public
503
+ */
504
+ singleton<T_1 extends Constructable<{}>>(target: T_1 & Partial<RegisterSelf<T_1>>, options?: SingletonOptions): T_1 & RegisterSelf<T_1>;
505
+ }>;
506
+ /**
507
+ * The key that resolves the dependency injection Container itself.
508
+ * @public
509
+ */
510
+ export declare const Container: ContextDecorator<Container>;
511
+ /**
512
+ * The key that resolves a DOMContainer itself.
513
+ * @public
514
+ */
515
+ export declare const DOMContainer: ContextDecorator<DOMContainer>;
516
+ /**
517
+ * The key that resolves the ServiceLocator itself.
518
+ * @public
519
+ */
520
+ export declare const ServiceLocator: ContextDecorator<ServiceLocator>;
521
+ /**
522
+ * A decorator that specifies what to inject into its target.
523
+ * @param dependencies - The dependencies to inject.
524
+ * @returns The decorator to be applied to the target class.
525
+ * @remarks
526
+ * The decorator can be used to decorate a class, listing all of the classes dependencies.
527
+ * Or it can be used to decorate a constructor paramter, indicating what to inject for that
528
+ * parameter.
529
+ * Or it can be used for a web component property, indicating what that property should resolve to.
530
+ *
531
+ * @public
532
+ */
533
+ export declare const inject: (...dependencies: Key[]) => (target: any, key?: string | number, descriptor?: PropertyDescriptor | number) => void;
534
+ declare function transientDecorator<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
535
+ /**
536
+ * Registers the decorated class as a transient dependency; each time the dependency is resolved
537
+ * a new instance will be created.
538
+ *
539
+ * @example
540
+ * ```ts
541
+ * @transient()
542
+ * class Foo { }
543
+ * ```
544
+ *
545
+ * @public
546
+ */
547
+ export declare function transient<T extends Constructable>(): typeof transientDecorator;
548
+ /**
549
+ * Registers the `target` class as a transient dependency; each time the dependency is resolved
550
+ * a new instance will be created.
551
+ *
552
+ * @param target - The class / constructor function to register as transient.
553
+ *
554
+ * @example
555
+ * ```ts
556
+ * @transient()
557
+ * class Foo { }
558
+ * ```
559
+ *
560
+ * @public
561
+ */
562
+ export declare function transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
563
+ declare type SingletonOptions = {
564
+ scoped: boolean;
565
+ };
566
+ declare function singletonDecorator<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
567
+ /**
568
+ * Registers the decorated class as a singleton dependency; the class will only be created once. Each
569
+ * consecutive time the dependency is resolved, the same instance will be returned.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * @singleton()
574
+ * class Foo { }
575
+ * ```
576
+ *
577
+ * @public
578
+ */
579
+ export declare function singleton<T extends Constructable>(): typeof singletonDecorator;
580
+ /**
581
+ * @public
582
+ */
583
+ export declare function singleton<T extends Constructable>(options?: SingletonOptions): typeof singletonDecorator;
584
+ /**
585
+ * Registers the `target` class as a singleton dependency; the class will only be created once. Each
586
+ * consecutive time the dependency is resolved, the same instance will be returned.
587
+ *
588
+ * @param target - The class / constructor function to register as a singleton.
589
+ *
590
+ * @example
591
+ * ```ts
592
+ * @singleton()
593
+ * class Foo { }
594
+ * ```
595
+ *
596
+ * @public
597
+ */
598
+ export declare function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
599
+ /**
600
+ * A decorator and DI resolver that will resolve an array of all dependencies
601
+ * registered with the specified key.
602
+ * @param key - The key to resolve all dependencies for.
603
+ * @param searchAncestors - [optional] Indicates whether to search ancestor containers.
604
+ * @public
605
+ */
606
+ export declare const all: (key: any, searchAncestors?: boolean) => ReturnType<typeof DI.inject>;
607
+ /**
608
+ * A decorator that lazily injects a dependency depending on whether the `Key` is present at the time of function call.
609
+ *
610
+ * @example
611
+ * You need to make your argument a function that returns the type, for example
612
+ * ```ts
613
+ * class Foo {
614
+ * constructor( @lazy('random') public random: () => number )
615
+ * }
616
+ * const foo = container.get(Foo); // instanceof Foo
617
+ * foo.random(); // throws
618
+ * ```
619
+ * would throw an exception because you haven't registered `'random'` before calling the method.
620
+ * @example
621
+ * This, would give you a new 'Math.random()' number each time.
622
+ * ```ts
623
+ * class Foo {
624
+ * constructor( @lazy('random') public random: () => random )
625
+ * }
626
+ * container.register(Registration.callback('random', Math.random ));
627
+ * container.get(Foo).random(); // some random number
628
+ * container.get(Foo).random(); // another random number
629
+ * ```
630
+ *
631
+ * `@lazy` does not manage the lifecycle of the underlying key. If you want a singleton, you have to register as a
632
+ * `singleton`, `transient` would also behave as you would expect, providing you a new instance each time.
633
+ *
634
+ * @param key - The key to lazily resolve.
635
+ * see {@link DI.createContext} on interactions with interfaces
636
+ *
637
+ * @public
638
+ */
639
+ export declare const lazy: (key: any) => any;
640
+ /**
641
+ * A decorator that allows you to optionally inject a dependency depending on whether the [[`Key`]] is present, for example:
642
+ * @example
643
+ * ```ts
644
+ * class Foo {
645
+ * constructor( @inject('mystring') public str: string = 'somestring' )
646
+ * }
647
+ * container.get(Foo); // throws
648
+ * ```
649
+ * would fail
650
+ *
651
+ * @example
652
+ * ```ts
653
+ * class Foo {
654
+ * constructor( @optional('mystring') public str: string = 'somestring' )
655
+ * }
656
+ * container.get(Foo).str // somestring
657
+ * ```
658
+ * if you use it without a default it will inject `undefined`, so remember to mark your input type as
659
+ * possibly `undefined`!
660
+ *
661
+ * @param key - The key to optionally resolve.
662
+ * see {@link DI.createContext} on interactions with interfaces
663
+ *
664
+ * @public
665
+ */
666
+ export declare const optional: (key: any) => any;
667
+ /**
668
+ * A decorator that tells the container not to try to inject a dependency.
669
+ *
670
+ * @public
671
+ */
672
+ export declare function ignore(target: Injectable, property?: string | number, descriptor?: PropertyDescriptor | number): void;
673
+ /**
674
+ * A decorator that indicates that a new instance should be injected scoped to the
675
+ * container that requested the instance.
676
+ * @param key - The dependency key for the new instance.
677
+ * @remarks
678
+ * This creates a resolver with an instance strategy pointing to the new instance, effectively
679
+ * making this a singleton, scoped to the container or DOM's subtree.
680
+ *
681
+ * @public
682
+ */
683
+ export declare const newInstanceForScope: (key: any) => any;
684
+ /**
685
+ * A decorator that indicates that a new instance should be injected.
686
+ * @param key - The dependency key for the new instance.
687
+ * @remarks
688
+ * The instance is not internally cached with a resolver as newInstanceForScope does.
689
+ *
690
+ * @public
691
+ */
692
+ export declare const newInstanceOf: (key: any) => any;
693
+ /** @internal */
694
+ export declare const enum ResolverStrategy {
695
+ instance = 0,
696
+ singleton = 1,
697
+ transient = 2,
698
+ callback = 3,
699
+ array = 4,
700
+ alias = 5
701
+ }
702
+ /** @internal */
703
+ export declare class ResolverImpl implements Resolver, Registration {
704
+ key: Key;
705
+ strategy: ResolverStrategy;
706
+ state: any;
707
+ constructor(key: Key, strategy: ResolverStrategy, state: any);
708
+ get $isResolver(): true;
709
+ private resolving;
710
+ register(container: Container): Resolver;
711
+ resolve(handler: Container, requestor: Container): any;
712
+ getFactory(container: Container): Factory | null;
713
+ }
714
+ /** @internal */
715
+ export declare class FactoryImpl<T extends Constructable = any> implements Factory<T> {
716
+ Type: T;
717
+ private readonly dependencies;
718
+ private transformers;
719
+ constructor(Type: T, dependencies: Key[]);
720
+ construct(container: Container, dynamicDependencies?: Key[]): Resolved<T>;
721
+ registerTransformer(transformer: (instance: any) => any): void;
722
+ }
723
+ /**
724
+ * @internal
725
+ */
726
+ export declare class ContainerImpl implements DOMContainer {
727
+ protected owner: any;
728
+ protected config: ContainerConfiguration;
729
+ private _parent;
730
+ private registerDepth;
731
+ private resolvers;
732
+ private isHandlingContextRequests;
733
+ get parent(): ContainerImpl | null;
734
+ get depth(): number;
735
+ get responsibleForOwnerRequests(): boolean;
736
+ constructor(owner: any, config: ContainerConfiguration);
737
+ handleContextRequests(enable: boolean): void;
738
+ register(...params: any[]): Container;
739
+ registerResolver<K extends Key, T = K>(key: K, resolver: Resolver<T>): Resolver<T>;
740
+ registerTransformer<K extends Key, T = K>(key: K, transformer: Transformer<T>): boolean;
741
+ getResolver<K extends Key, T = K>(key: K | Key, autoRegister?: boolean): Resolver<T> | null;
742
+ has<K extends Key>(key: K, searchAncestors?: boolean): boolean;
743
+ get<K extends Key>(key: K): Resolved<K>;
744
+ getAll<K extends Key>(key: K, searchAncestors?: boolean): readonly Resolved<K>[];
745
+ getFactory<K extends Constructable>(Type: K): Factory<K>;
746
+ registerFactory<K extends Constructable>(key: K, factory: Factory<K>): void;
747
+ createChild(config?: Partial<Omit<ContainerConfiguration, "parentLocator">>): Container;
748
+ private jitRegister;
749
+ }
750
+ /**
751
+ * You can use the resulting Registration of any of the factory methods
752
+ * to register with the container.
753
+ *
754
+ * @example
755
+ * ```
756
+ * class Foo {}
757
+ * const container = DI.createContainer();
758
+ * container.register(Registration.instance(Foo, new Foo()));
759
+ * container.get(Foo);
760
+ * ```
761
+ *
762
+ * @public
763
+ */
764
+ export declare const Registration: Readonly<{
765
+ /**
766
+ * Allows you to pass an instance.
767
+ * Every time you request this {@link Key} you will get this instance back.
768
+ *
769
+ * @example
770
+ * ```
771
+ * Registration.instance(Foo, new Foo()));
772
+ * ```
773
+ *
774
+ * @param key - The key to register the instance under.
775
+ * @param value - The instance to return when the key is requested.
776
+ */
777
+ instance<T>(key: Key, value: T): Registration<T>;
778
+ /**
779
+ * Creates an instance from the class.
780
+ * Every time you request this {@link Key} you will get the same one back.
781
+ *
782
+ * @example
783
+ * ```
784
+ * Registration.singleton(Foo, Foo);
785
+ * ```
786
+ *
787
+ * @param key - The key to register the singleton under.
788
+ * @param value - The class to instantiate as a singleton when first requested.
789
+ */
790
+ singleton<T_1 extends Constructable<{}>>(key: Key, value: T_1): Registration<InstanceType<T_1>>;
791
+ /**
792
+ * Creates an instance from a class.
793
+ * Every time you request this {@link Key} you will get a new instance.
794
+ *
795
+ * @example
796
+ * ```
797
+ * Registration.instance(Foo, Foo);
798
+ * ```
799
+ *
800
+ * @param key - The key to register the instance type under.
801
+ * @param value - The class to instantiate each time the key is requested.
802
+ */
803
+ transient<T_2 extends Constructable<{}>>(key: Key, value: T_2): Registration<InstanceType<T_2>>;
804
+ /**
805
+ * Delegates to a callback function to provide the dependency.
806
+ * Every time you request this {@link Key} the callback will be invoked to provide
807
+ * the dependency.
808
+ *
809
+ * @example
810
+ * ```
811
+ * Registration.callback(Foo, () => new Foo());
812
+ * Registration.callback(Bar, (c: Container) => new Bar(c.get(Foo)));
813
+ * ```
814
+ *
815
+ * @param key - The key to register the callback for.
816
+ * @param callback - The function that is expected to return the dependency.
817
+ */
818
+ callback<T_3>(key: Key, callback: ResolveCallback<T_3>): Registration<Resolved<T_3>>;
819
+ /**
820
+ * Delegates to a callback function to provide the dependency and then caches the
821
+ * dependency for future requests.
822
+ *
823
+ * @example
824
+ * ```
825
+ * Registration.cachedCallback(Foo, () => new Foo());
826
+ * Registration.cachedCallback(Bar, (c: Container) => new Bar(c.get(Foo)));
827
+ * ```
828
+ *
829
+ * @param key - The key to register the callback for.
830
+ * @param callback - The function that is expected to return the dependency.
831
+ * @remarks
832
+ * If you pass the same Registration to another container, the same cached value will be used.
833
+ * Should all references to the resolver returned be removed, the cache will expire.
834
+ */
835
+ cachedCallback<T_4>(key: Key, callback: ResolveCallback<T_4>): Registration<Resolved<T_4>>;
836
+ /**
837
+ * Creates an alternate {@link Key} to retrieve an instance by.
838
+ *
839
+ * @example
840
+ * ```
841
+ * Register.singleton(Foo, Foo)
842
+ * Register.aliasTo(Foo, MyFoos);
843
+ *
844
+ * container.getAll(MyFoos) // contains an instance of Foo
845
+ * ```
846
+ *
847
+ * @param originalKey - The original key that has been registered.
848
+ * @param aliasKey - The alias to the original key.
849
+ */
850
+ aliasTo<T_5>(originalKey: T_5, aliasKey: Key): Registration<Resolved<T_5>>;
851
+ }>;
852
+ /** @internal */
853
+ export declare function validateKey(key: any): void;
854
+ export {};