@microsoft/fast-element 1.10.5 → 2.0.0-beta.10

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