@fluidframework/synthesize 0.55.0-48551 → 0.56.0

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.
@@ -2,14 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidObject } from "@fluidframework/core-interfaces";
6
- import { AsyncFluidObjectProvider, FluidObjectSymbolProvider, FluidObjectProvider, FluidObjectKey } from "./types";
7
- declare module "@fluidframework/core-interfaces" {
8
- interface IFluidObject {
9
- /** @deprecated - use `FluidObject<IFluidDependencySynthesizer>` instead */
10
- readonly IFluidDependencySynthesizer?: IFluidDependencySynthesizer;
11
- }
12
- }
5
+ import { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from "./types";
13
6
  export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
14
7
  export interface IProvideFluidDependencySynthesizer {
15
8
  IFluidDependencySynthesizer: IFluidDependencySynthesizer;
@@ -20,25 +13,6 @@ export interface IProvideFluidDependencySynthesizer {
20
13
  * and required types.
21
14
  */
22
15
  export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
23
- /**
24
- * @deprecated - This will only be available on DependencyContainer
25
- * All the registered types available
26
- */
27
- readonly registeredTypes: Iterable<(keyof IFluidObject)>;
28
- /**
29
- * @deprecated - This will only be available on DependencyContainer
30
- * Add a new provider
31
- * @param type - Name of the Type T being provided
32
- * @param provider - A provider that will resolve the T correctly when asked
33
- * @throws - If passing a type that's already registered
34
- */
35
- register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void;
36
- /**
37
- * @deprecated - This will only be available on DependencyContainer
38
- * Remove a provider
39
- * @param type - Name of the provider to remove
40
- */
41
- unregister<T extends keyof IFluidObject>(type: T): void;
42
16
  /**
43
17
  * synthesize takes optional and required types and returns an object that will fulfill the
44
18
  * defined types based off objects that has been previously registered.
@@ -46,17 +20,11 @@ export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynt
46
20
  * @param optionalTypes - optional types to be in the Scope object
47
21
  * @param requiredTypes - required types that need to be in the Scope object
48
22
  */
49
- synthesize<O extends IFluidObject, R extends IFluidObject>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: FluidObjectSymbolProvider<R>): AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>>;
23
+ synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
50
24
  /**
51
25
  * Check if a given type is registered
52
26
  * @param type - Type to check
53
27
  */
54
- has(type: (keyof IFluidObject)): boolean;
55
- /**
56
- * @deprecated - This will be removed. Use synthesize or has instead
57
- * Get a provider. undefined if not available.
58
- * @param type - Type to get
59
- */
60
- getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined;
28
+ has(type: string): boolean;
61
29
  }
62
30
  //# sourceMappingURL=IFluidDependencySynthesizer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,cAAc,EACjB,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,iCAAiC,CAAC;IAC7C,UAAiB,YAAY;QACzB,2EAA2E;QAC3E,QAAQ,CAAC,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;KACtE;CACJ;AAED,eAAO,MAAM,2BAA2B,EAAE,MAAM,kCACb,CAAC;AAEpC,MAAM,WAAW,kCAAkC;IAC/C,2BAA2B,EAAE,2BAA2B,CAAC;CAC5D;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA4B,SAAQ,kCAAkC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G,SAAS,GAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC5C,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GAC1D,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAElC;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiBU,QAAA,2BAA2B,GAClC,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidObject } from \"@fluidframework/core-interfaces\";\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n FluidObjectProvider,\n FluidObjectKey,\n} from \"./types\";\n\ndeclare module \"@fluidframework/core-interfaces\" {\n export interface IFluidObject {\n /** @deprecated - use `FluidObject<IFluidDependencySynthesizer>` instead */\n readonly IFluidDependencySynthesizer?: IFluidDependencySynthesizer;\n }\n}\n\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer\n = \"IFluidDependencySynthesizer\";\n\nexport interface IProvideFluidDependencySynthesizer {\n IFluidDependencySynthesizer: IFluidDependencySynthesizer;\n}\n\n/**\n * IFluidDependencySynthesizer can generate IFluidObjects based on the IProvideFluidObject pattern.\n * It allow for registering providers and uses synthesize to generate a new object with the optional\n * and required types.\n */\nexport interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {\n /**\n * @deprecated - This will only be available on DependencyContainer\n * All the registered types available\n */\n readonly registeredTypes: Iterable<(keyof IFluidObject)>;\n\n /**\n * @deprecated - This will only be available on DependencyContainer\n * Add a new provider\n * @param type - Name of the Type T being provided\n * @param provider - A provider that will resolve the T correctly when asked\n * @throws - If passing a type that's already registered\n */\n register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void;\n\n /**\n * @deprecated - This will only be available on DependencyContainer\n * Remove a provider\n * @param type - Name of the provider to remove\n */\n unregister<T extends keyof IFluidObject>(type: T): void;\n\n /**\n * synthesize takes optional and required types and returns an object that will fulfill the\n * defined types based off objects that has been previously registered.\n *\n * @param optionalTypes - optional types to be in the Scope object\n * @param requiredTypes - required types that need to be in the Scope object\n */\n synthesize<\n O extends IFluidObject,\n R extends IFluidObject>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: FluidObjectSymbolProvider<R>,\n ): AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>>;\n\n /**\n * Check if a given type is registered\n * @param type - Type to check\n */\n has(type: (keyof IFluidObject)): boolean;\n\n /**\n * @deprecated - This will be removed. Use synthesize or has instead\n * Get a provider. undefined if not available.\n * @param type - Type to get\n */\n getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined;\n}\n"]}
1
+ {"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOU,QAAA,2BAA2B,GAClC,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n} from \"./types\";\n\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer\n = \"IFluidDependencySynthesizer\";\n\nexport interface IProvideFluidDependencySynthesizer {\n IFluidDependencySynthesizer: IFluidDependencySynthesizer;\n}\n\n/**\n * IFluidDependencySynthesizer can generate IFluidObjects based on the IProvideFluidObject pattern.\n * It allow for registering providers and uses synthesize to generate a new object with the optional\n * and required types.\n */\nexport interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {\n \n /**\n * synthesize takes optional and required types and returns an object that will fulfill the\n * defined types based off objects that has been previously registered.\n *\n * @param optionalTypes - optional types to be in the Scope object\n * @param requiredTypes - required types that need to be in the Scope object\n */\n synthesize<O, R = undefined | Record<string, never>>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: Required<FluidObjectSymbolProvider<R>>,\n ): AsyncFluidObjectProvider<O, R>;\n\n /**\n * Check if a given type is registered\n * @param type - Type to check\n */\n has(type: string): boolean;\n}\n"]}
@@ -2,46 +2,38 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidObject } from "@fluidframework/core-interfaces";
6
- import { AsyncFluidObjectProvider, FluidObjectSymbolProvider, FluidObjectProvider, FluidObjectKey } from "./types";
5
+ import { AsyncFluidObjectProvider, FluidObjectSymbolProvider, FluidObjectProvider } from "./types";
7
6
  import { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer";
8
7
  /**
9
8
  * DependencyContainer is similar to a IoC Container. It takes providers and will
10
9
  * synthesize an object based on them when requested.
11
10
  */
12
- export declare class DependencyContainer implements IFluidDependencySynthesizer {
11
+ export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
13
12
  private readonly providers;
14
13
  private readonly parents;
15
14
  get IFluidDependencySynthesizer(): this;
16
- /**
17
- * @deprecated - use has instead
18
- * {@inheritDoc (IFluidDependencySynthesizer:interface).registeredTypes}
19
- */
20
- get registeredTypes(): Iterable<(keyof IFluidObject)>;
21
15
  constructor(...parents: (IFluidDependencySynthesizer | undefined)[]);
22
16
  /**
23
- * {@inheritDoc (IFluidDependencySynthesizer:interface).register}
17
+ * Add a new provider
18
+ * @param type - Name of the Type T being provided
19
+ * @param provider - A provider that will resolve the T correctly when asked
20
+ * @throws - If passing a type that's already registered
24
21
  */
25
- register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void;
22
+ register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void;
26
23
  /**
27
- * {@inheritDoc (IFluidDependencySynthesizer:interface).unregister}
24
+ * Remove a provider
25
+ * @param type - Name of the provider to remove
28
26
  */
29
- unregister<T extends keyof IFluidObject>(type: T): void;
27
+ unregister(type: keyof TMap): void;
30
28
  /**
31
29
  * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
32
30
  */
33
- synthesize<O extends IFluidObject, R extends IFluidObject = {}>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: FluidObjectSymbolProvider<R>): AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>>;
31
+ synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
34
32
  /**
35
33
  * {@inheritDoc (IFluidDependencySynthesizer:interface).has}
36
34
  * @param excludeParents - If true, exclude checking parent registries
37
35
  */
38
- has(type: (keyof IFluidObject), excludeParents?: boolean): boolean;
39
- /**
40
- * @deprecated - use synthesize or has instead
41
- *
42
- * {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}
43
- */
44
- getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined;
36
+ has(type: string, excludeParents?: boolean): boolean;
45
37
  private generateRequired;
46
38
  private generateOptional;
47
39
  private resolveProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,cAAc,EAGjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACH,2BAA2B,EAC9B,MAAM,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,2BAA2B;IACnE,O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AGtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACH,2BAA2B,EAC9B,MAAM,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,YAAW,2BAA2B;IACzE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmD;IAC7E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,IAAW,2BAA2B,SAAmB;gBAEtC,GAAI,OAAO,EAAE,CAAC,2BAA2B,GAAG,SAAS,CAAC,EAAE;IAI3E;;;;;OAKG;IACI,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI;IAQ/G;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI;IAMzC;;OAEG;IACI,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACtD,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GACtD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC;IAQjC;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO;IAU3D,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,eAAe;CAyC1B"}
@@ -17,14 +17,10 @@ class DependencyContainer {
17
17
  }
18
18
  get IFluidDependencySynthesizer() { return this; }
19
19
  /**
20
- * @deprecated - use has instead
21
- * {@inheritDoc (IFluidDependencySynthesizer:interface).registeredTypes}
22
- */
23
- get registeredTypes() {
24
- return this.providers.keys();
25
- }
26
- /**
27
- * {@inheritDoc (IFluidDependencySynthesizer:interface).register}
20
+ * Add a new provider
21
+ * @param type - Name of the Type T being provided
22
+ * @param provider - A provider that will resolve the T correctly when asked
23
+ * @throws - If passing a type that's already registered
28
24
  */
29
25
  register(type, provider) {
30
26
  if (this.providers.has(type)) {
@@ -33,7 +29,8 @@ class DependencyContainer {
33
29
  this.providers.set(type, provider);
34
30
  }
35
31
  /**
36
- * {@inheritDoc (IFluidDependencySynthesizer:interface).unregister}
32
+ * Remove a provider
33
+ * @param type - Name of the provider to remove
37
34
  */
38
35
  unregister(type) {
39
36
  if (this.providers.has(type)) {
@@ -63,26 +60,9 @@ class DependencyContainer {
63
60
  }
64
61
  return false;
65
62
  }
66
- /**
67
- * @deprecated - use synthesize or has instead
68
- *
69
- * {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}
70
- */
71
- getProvider(type) {
72
- // If we have the provider return it
73
- const provider = this.providers.get(type);
74
- if (provider) {
75
- return provider;
76
- }
77
- for (const parent of this.parents) {
78
- const p = parent.getProvider(type);
79
- if (p !== undefined) {
80
- return p;
81
- }
82
- }
83
- return undefined;
84
- }
85
63
  generateRequired(base, types) {
64
+ if (types === undefined)
65
+ return;
86
66
  for (const key of Object.keys(types)) {
87
67
  const provider = this.resolveProvider(key);
88
68
  if (provider === undefined) {
@@ -92,11 +72,15 @@ class DependencyContainer {
92
72
  }
93
73
  }
94
74
  generateOptional(base, types) {
75
+ var _a;
76
+ if (types === undefined)
77
+ return;
95
78
  for (const key of Object.keys(types)) {
96
- const provider = this.resolveProvider(key);
97
- if (provider !== undefined) {
98
- Object.defineProperty(base, key, provider);
99
- }
79
+ // back-compat: in 0.56 we allow undefined in the types, but we didn't before
80
+ // this will keep runtime back compat, eventually we should support undefined properties
81
+ // rather than properties that return promises that resolve to undefined
82
+ const provider = (_a = this.resolveProvider(key)) !== null && _a !== void 0 ? _a : { get: () => Promise.resolve(undefined) };
83
+ Object.defineProperty(base, key, provider);
100
84
  }
101
85
  }
102
86
  resolveProvider(t) {
@@ -104,9 +88,7 @@ class DependencyContainer {
104
88
  const provider = this.providers.get(t);
105
89
  if (provider === undefined) {
106
90
  for (const parent of this.parents) {
107
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
108
91
  const sp = { [t]: t };
109
- // eslint-disable-next-line @typescript-eslint/ban-types
110
92
  const syn = parent.synthesize(sp, {});
111
93
  const descriptor = Object.getOwnPropertyDescriptor(syn, t);
112
94
  if (descriptor !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,+EAEuC;AAEvC;;;GAGG;AACH,MAAa,mBAAmB;IAa5B,YAAmB,GAAI,OAAoD;QAZ1D,cAAS,GAAG,IAAI,GAAG,EAAgD,CAAC;QAajF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC5F,CAAC;IAZD,IAAW,2BAA2B,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD;;;OAGG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAMD;;OAEG;IACI,QAAQ,CAA+B,IAAO,EAAE,QAAgC;QACnF,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,6CAA6C,IAAI,sBAAsB,CAAC,CAAC;SAC5F;QAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACI,UAAU,CAA+B,IAAO;QACnD,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CA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,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAChC,OAAO;gBACH,GAAG;oBACC,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;wBAC5C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,yDAA2B,CAAC,CAAC;6BACpD,IAAI,CAAC,KAAK,EAAE,GAAG,EAAgB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;6BAChD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAG,CAAC,CAAC,CAAC,CAAC;qBAC5B;gBACL,CAAC;aACJ,CAAC;SACL;QACD,OAAO;YACC,GAAG;gBACC,IAAI,QAAQ,EAAE;oBACV,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;wBACxC,IAAI,CAAC,EAAE;4BACH,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;yBACf;oBACL,CAAC,CAAC,CAAC;iBACN;YACL,CAAC;SACJ,CAAC;IACV,CAAC;CACJ;AAtKD,kDAsKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidObject } from \"@fluidframework/core-interfaces\";\n\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n FluidObjectProvider,\n FluidObjectKey,\n AsyncOptionalFluidObjectProvider,\n AsyncRequiredFluidObjectProvider,\n} from \"./types\";\nimport {\n IFluidDependencySynthesizer,\n} from \"./IFluidDependencySynthesizer\";\n\n/**\n * DependencyContainer is similar to a IoC Container. It takes providers and will\n * synthesize an object based on them when requested.\n */\nexport class DependencyContainer implements IFluidDependencySynthesizer {\n private readonly providers = new Map<keyof IFluidObject, FluidObjectProvider<any>>();\n private readonly parents: IFluidDependencySynthesizer[];\n public get IFluidDependencySynthesizer() { return this; }\n\n /**\n * @deprecated - use has instead\n * {@inheritDoc (IFluidDependencySynthesizer:interface).registeredTypes}\n */\n public get registeredTypes(): Iterable<(keyof IFluidObject)> {\n return this.providers.keys();\n }\n\n public constructor(... parents: (IFluidDependencySynthesizer | undefined)[]) {\n this.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).register}\n */\n public register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void {\n if (this.providers.has(type)) {\n throw new Error(`Attempting to register a provider of type ${type} that already exists`);\n }\n\n this.providers.set(type, provider);\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).unregister}\n */\n public unregister<T extends keyof IFluidObject>(type: T): void {\n if (this.providers.has(type)) {\n this.providers.delete(type);\n }\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n */\n public synthesize<\n O extends IFluidObject,\n // eslint-disable-next-line @typescript-eslint/ban-types\n R extends IFluidObject = {}>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: FluidObjectSymbolProvider<R>,\n ): AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>> {\n const base: AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>> = {} as any;\n this.generateRequired<R>(base, requiredTypes);\n this.generateOptional<O>(base, optionalTypes);\n Object.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n return base;\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n * @param excludeParents - If true, exclude checking parent registries\n */\n public has(type: (keyof IFluidObject), excludeParents?: boolean): boolean {\n if (this.providers.has(type)) {\n return true;\n }\n if (excludeParents !== true) {\n return this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n }\n return false;\n }\n\n /**\n * @deprecated - use synthesize or has instead\n *\n * {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}\n */\n public getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined {\n // If we have the provider return it\n const provider = this.providers.get(type);\n if (provider) {\n return provider;\n }\n\n for(const parent of this.parents) {\n const p = parent.getProvider(type);\n if (p !== undefined) {\n return p;\n }\n }\n\n return undefined;\n }\n\n private generateRequired<T extends IFluidObject>(\n base: AsyncRequiredFluidObjectProvider<FluidObjectKey<T>>,\n types: FluidObjectSymbolProvider<T>,\n ) {\n for(const key of Object.keys(types) as unknown as (keyof IFluidObject)[]) {\n const provider = this.resolveProvider(key);\n if(provider === undefined) {\n throw new Error(`Object attempted to be created without registered required provider ${key}`);\n }\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private generateOptional<T extends IFluidObject>(\n base: AsyncOptionalFluidObjectProvider<FluidObjectKey<T>>,\n types: FluidObjectSymbolProvider<T>,\n ) {\n for(const key of Object.keys(types) as unknown as (keyof IFluidObject)[]) {\n const provider = this.resolveProvider(key);\n if(provider !== undefined) {\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n }\n\n private resolveProvider<T extends keyof IFluidObject>(t: T): PropertyDescriptor | undefined {\n // If we have the provider return it\n const provider = this.providers.get(t);\n if (provider === undefined) {\n for(const parent of this.parents) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const sp = { [t]: t } as FluidObjectSymbolProvider<Pick<IFluidObject, T>>;\n // eslint-disable-next-line @typescript-eslint/ban-types\n const syn = parent.synthesize<Pick<IFluidObject, T>,{}>(\n sp,\n {});\n const descriptor = Object.getOwnPropertyDescriptor(syn, t);\n if (descriptor !== undefined) {\n return descriptor;\n }\n }\n return undefined;\n }\n\n // The double nested gets are required for lazy loading the provider resolution\n if (typeof provider === \"function\") {\n return {\n get() {\n if (provider && typeof provider === \"function\") {\n return Promise.resolve(this[IFluidDependencySynthesizer])\n .then(async (fds): Promise<any> => provider(fds))\n .then((p) => p?.[t]);\n }\n },\n };\n }\n return {\n get() {\n if (provider) {\n return Promise.resolve(provider).then((p) => {\n if (p) {\n return p[t];\n }\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AAC,CAAC,CAAC;iBACN;YACL,CAAC;SACJ,CAAC;IACV,CAAC;CACJ;AA1ID,kDA0IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n FluidObjectProvider,\n AsyncOptionalFluidObjectProvider,\n AsyncRequiredFluidObjectProvider,\n} from \"./types\";\nimport {\n IFluidDependencySynthesizer,\n} from \"./IFluidDependencySynthesizer\";\n\n/**\n * DependencyContainer is similar to a IoC Container. It takes providers and will\n * synthesize an object based on them when requested.\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n private readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();\n private readonly parents: IFluidDependencySynthesizer[];\n public get IFluidDependencySynthesizer() { return this; }\n\n public constructor(... parents: (IFluidDependencySynthesizer | undefined)[]) {\n this.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n }\n\n /**\n * Add a new provider\n * @param type - Name of the Type T being provided\n * @param provider - A provider that will resolve the T correctly when asked\n * @throws - If passing a type that's already registered\n */\n public register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void {\n if (this.providers.has(type)) {\n throw new Error(`Attempting to register a provider of type ${type} that already exists`);\n }\n\n this.providers.set(type, provider);\n }\n\n /**\n * Remove a provider\n * @param type - Name of the provider to remove\n */\n public unregister(type: keyof TMap): void {\n if (this.providers.has(type)) {\n this.providers.delete(type);\n }\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n */\n public synthesize<O, R = undefined | Record<string, never>>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: Required<FluidObjectSymbolProvider<R>>,\n ): AsyncFluidObjectProvider<O, R> {\n const base: AsyncFluidObjectProvider<O, R> = {} as any;\n this.generateRequired<R>(base, requiredTypes);\n this.generateOptional<O>(base, optionalTypes);\n Object.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n return base;\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n * @param excludeParents - If true, exclude checking parent registries\n */\n public has(type: string, excludeParents?: boolean): boolean {\n if (this.providers.has(type as keyof TMap)) {\n return true;\n }\n if (excludeParents !== true) {\n return this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n }\n return false;\n }\n\n private generateRequired<T>(\n base: AsyncRequiredFluidObjectProvider<T>,\n types: Required<FluidObjectSymbolProvider<T>>,\n ) {\n if(types === undefined) return;\n for(const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n const provider = this.resolveProvider(key);\n if(provider === undefined) {\n throw new Error(`Object attempted to be created without registered required provider ${key}`);\n }\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private generateOptional<T>(\n base: AsyncOptionalFluidObjectProvider<T>,\n types: FluidObjectSymbolProvider<T>,\n ) {\n if(types === undefined) return;\n for(const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n // back-compat: in 0.56 we allow undefined in the types, but we didn't before\n // this will keep runtime back compat, eventually we should support undefined properties\n // rather than properties that return promises that resolve to undefined\n const provider = this.resolveProvider(key) ?? {get:()=>Promise.resolve(undefined)};\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {\n // If we have the provider return it\n const provider = this.providers.get(t);\n if (provider === undefined) {\n for(const parent of this.parents) {\n const sp = { [t]: t } as FluidObjectSymbolProvider<Pick<TMap, T>>;\n const syn = parent.synthesize<Pick<TMap, T>,{}>(\n sp,\n {});\n const descriptor = Object.getOwnPropertyDescriptor(syn, t);\n if (descriptor !== undefined) {\n return descriptor;\n }\n }\n return undefined;\n }\n\n // The double nested gets are required for lazy loading the provider resolution\n if (typeof provider === \"function\") {\n return {\n get() {\n if (provider && typeof provider === \"function\") {\n return Promise.resolve(this[IFluidDependencySynthesizer])\n .then(async (fds): Promise<any> => provider(fds))\n .then((p) => p?.[t]);\n }\n },\n };\n }\n return {\n get() {\n if (provider) {\n return Promise.resolve(provider).then((p) => {\n if (p) {\n return p[t];\n }\n });\n }\n },\n };\n }\n}\n"]}
@@ -35,7 +35,7 @@ describe("Routerlicious", () => {
35
35
  const dc = new __1.DependencyContainer();
36
36
  const mock = new MockLoadable();
37
37
  dc.register(core_interfaces_1.IFluidLoadable, mock);
38
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
38
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, undefined);
39
39
  const loadable = await s.IFluidLoadable;
40
40
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
41
41
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -45,7 +45,7 @@ describe("Routerlicious", () => {
45
45
  const dc = new __1.DependencyContainer();
46
46
  const mock = new MockLoadable();
47
47
  dc.register(core_interfaces_1.IFluidLoadable, Promise.resolve(mock));
48
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
48
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, undefined);
49
49
  const loadable = await s.IFluidLoadable;
50
50
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
51
51
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -56,7 +56,7 @@ describe("Routerlicious", () => {
56
56
  const mock = new MockLoadable();
57
57
  const factory = () => mock;
58
58
  dc.register(core_interfaces_1.IFluidLoadable, factory);
59
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
59
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, undefined);
60
60
  const loadable = await s.IFluidLoadable;
61
61
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
62
62
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -67,7 +67,7 @@ describe("Routerlicious", () => {
67
67
  const mock = new MockLoadable();
68
68
  const factory = async () => mock;
69
69
  dc.register(core_interfaces_1.IFluidLoadable, factory);
70
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
70
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, undefined);
71
71
  const loadable = await s.IFluidLoadable;
72
72
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
73
73
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -77,8 +77,7 @@ describe("Routerlicious", () => {
77
77
  const dc = new __1.DependencyContainer();
78
78
  const mock = new MockLoadable();
79
79
  dc.register(core_interfaces_1.IFluidLoadable, mock);
80
- // eslint-disable-next-line @typescript-eslint/ban-types
81
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
80
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
82
81
  const loadable = await s.IFluidLoadable;
83
82
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
84
83
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -88,8 +87,7 @@ describe("Routerlicious", () => {
88
87
  const dc = new __1.DependencyContainer();
89
88
  const mock = new MockLoadable();
90
89
  dc.register(core_interfaces_1.IFluidLoadable, Promise.resolve(mock));
91
- // eslint-disable-next-line @typescript-eslint/ban-types
92
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
90
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
93
91
  const loadable = await s.IFluidLoadable;
94
92
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
95
93
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -100,8 +98,7 @@ describe("Routerlicious", () => {
100
98
  const mock = new MockLoadable();
101
99
  const factory = () => mock;
102
100
  dc.register(core_interfaces_1.IFluidLoadable, factory);
103
- // eslint-disable-next-line @typescript-eslint/ban-types
104
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
101
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
105
102
  const loadable = await s.IFluidLoadable;
106
103
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
107
104
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -112,8 +109,7 @@ describe("Routerlicious", () => {
112
109
  const mock = new MockLoadable();
113
110
  const factory = async () => mock;
114
111
  dc.register(core_interfaces_1.IFluidLoadable, factory);
115
- // eslint-disable-next-line @typescript-eslint/ban-types
116
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
112
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
117
113
  const loadable = await s.IFluidLoadable;
118
114
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
119
115
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -125,7 +121,7 @@ describe("Routerlicious", () => {
125
121
  dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
126
122
  const configMock = new MockFluidConfiguration();
127
123
  dc.register(core_interfaces_1.IFluidConfiguration, configMock);
128
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, {});
124
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, undefined);
129
125
  const loadable = await s.IFluidLoadable;
130
126
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
131
127
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -137,7 +133,7 @@ describe("Routerlicious", () => {
137
133
  const dc = new __1.DependencyContainer();
138
134
  const loadableMock = new MockLoadable();
139
135
  dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
140
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, {});
136
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, undefined);
141
137
  const loadable = await s.IFluidLoadable;
142
138
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
143
139
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -146,7 +142,7 @@ describe("Routerlicious", () => {
146
142
  });
147
143
  it(`Two Optional Modules none registered`, async () => {
148
144
  const dc = new __1.DependencyContainer();
149
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, {});
145
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, undefined);
150
146
  const loadable = await s.IFluidLoadable;
151
147
  assert_1.strict(!loadable, "Optional IFluidLoadable was not registered");
152
148
  const config = await s.IFluidConfiguration;
@@ -158,8 +154,7 @@ describe("Routerlicious", () => {
158
154
  dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
159
155
  const configMock = new MockFluidConfiguration();
160
156
  dc.register(core_interfaces_1.IFluidConfiguration, configMock);
161
- // eslint-disable-next-line @typescript-eslint/ban-types
162
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration });
157
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration });
163
158
  const loadable = await s.IFluidLoadable;
164
159
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
165
160
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -169,15 +164,14 @@ describe("Routerlicious", () => {
169
164
  });
170
165
  it(`Required Provider not registered should throw`, async () => {
171
166
  const dc = new __1.DependencyContainer();
172
- // eslint-disable-next-line @typescript-eslint/ban-types
173
- assert_1.strict.throws(() => dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable }), Error);
167
+ assert_1.strict.throws(() => dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable }), Error);
174
168
  });
175
169
  it(`Optional Provider found in Parent`, async () => {
176
170
  const parentDc = new __1.DependencyContainer();
177
171
  const mock = new MockLoadable();
178
172
  parentDc.register(core_interfaces_1.IFluidLoadable, mock);
179
173
  const dc = new __1.DependencyContainer(parentDc);
180
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
174
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, undefined);
181
175
  const loadable = await s.IFluidLoadable;
182
176
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
183
177
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -190,7 +184,7 @@ describe("Routerlicious", () => {
190
184
  const dc = new __1.DependencyContainer(parentDc);
191
185
  const configMock = new MockFluidConfiguration();
192
186
  dc.register(core_interfaces_1.IFluidConfiguration, configMock);
193
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, {});
187
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration }, undefined);
194
188
  const loadable = await s.IFluidLoadable;
195
189
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
196
190
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -204,7 +198,7 @@ describe("Routerlicious", () => {
204
198
  const dc = new __1.DependencyContainer(parentDc);
205
199
  const loadableMock = new MockLoadable();
206
200
  dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
207
- const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
201
+ const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, undefined);
208
202
  const loadable = await s.IFluidLoadable;
209
203
  assert_1.strict(loadable, "Optional IFluidLoadable was registered");
210
204
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -214,8 +208,7 @@ describe("Routerlicious", () => {
214
208
  const mock = new MockLoadable();
215
209
  parentDc.register(core_interfaces_1.IFluidLoadable, mock);
216
210
  const dc = new __1.DependencyContainer(parentDc);
217
- // eslint-disable-next-line @typescript-eslint/ban-types
218
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
211
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
219
212
  const loadable = await s.IFluidLoadable;
220
213
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
221
214
  assert_1.strict(loadable === mock, "IFluidLoadable is expected");
@@ -228,8 +221,7 @@ describe("Routerlicious", () => {
228
221
  const dc = new __1.DependencyContainer(parentDc);
229
222
  const configMock = new MockFluidConfiguration();
230
223
  dc.register(core_interfaces_1.IFluidConfiguration, configMock);
231
- // eslint-disable-next-line @typescript-eslint/ban-types
232
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration });
224
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable, IFluidConfiguration: core_interfaces_1.IFluidConfiguration });
233
225
  const loadable = await s.IFluidLoadable;
234
226
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
235
227
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -243,8 +235,7 @@ describe("Routerlicious", () => {
243
235
  const dc = new __1.DependencyContainer(parentDc);
244
236
  const loadableMock = new MockLoadable();
245
237
  dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
246
- // eslint-disable-next-line @typescript-eslint/ban-types
247
- const s = dc.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
238
+ const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
248
239
  const loadable = await s.IFluidLoadable;
249
240
  assert_1.strict(loadable, "Required IFluidLoadable was registered");
250
241
  assert_1.strict(loadable === loadableMock, "IFluidLoadable is expected");
@@ -253,7 +244,6 @@ describe("Routerlicious", () => {
253
244
  const dc = new __1.DependencyContainer();
254
245
  dc.register(core_interfaces_1.IFluidLoadable, new MockLoadable());
255
246
  assert_1.strict(dc.has(core_interfaces_1.IFluidLoadable), "DependencyContainer has IFluidLoadable");
256
- assert_1.strict(Array.from(dc.registeredTypes).length === 1, "DependencyContainer has one module");
257
247
  });
258
248
  it(`Registering the same type twice throws`, async () => {
259
249
  const dc = new __1.DependencyContainer();
@@ -265,7 +255,6 @@ describe("Routerlicious", () => {
265
255
  dc.register(core_interfaces_1.IFluidLoadable, new MockLoadable());
266
256
  dc.unregister(core_interfaces_1.IFluidLoadable);
267
257
  assert_1.strict(!dc.has(core_interfaces_1.IFluidLoadable), "DependencyContainer doesn't have IFluidLoadable");
268
- assert_1.strict(Array.from(dc.registeredTypes).length === 0, "Manager has no modules");
269
258
  });
270
259
  it(`Registering then Unregistering then Registering`, async () => {
271
260
  const dc = new __1.DependencyContainer();
@@ -281,16 +270,6 @@ describe("Routerlicious", () => {
281
270
  assert_1.strict(dc.has(core_interfaces_1.IFluidLoadable), "Manager has IFluidLoadable");
282
271
  assert_1.strict(dc.has(core_interfaces_1.IFluidConfiguration), "Manager has IFluidConfiguration");
283
272
  assert_1.strict(dc.has(core_interfaces_1.IFluidLoadable) && dc.has(core_interfaces_1.IFluidConfiguration), "Manager has IFluidLoadable & IFluidConfiguration");
284
- assert_1.strict(Array.from(dc.registeredTypes).length === 2, "Manager has two modules");
285
- });
286
- it(`registeredModules() resolves correctly`, async () => {
287
- const dc = new __1.DependencyContainer();
288
- dc.register(core_interfaces_1.IFluidLoadable, new MockLoadable());
289
- dc.register(core_interfaces_1.IFluidConfiguration, new MockFluidConfiguration());
290
- const modules = Array.from(dc.registeredTypes);
291
- assert_1.strict(modules.length === 2, "Manager has two modules");
292
- assert_1.strict(modules.includes(core_interfaces_1.IFluidLoadable), "Manager has IFluidLoadable");
293
- assert_1.strict(modules.includes(core_interfaces_1.IFluidConfiguration), "Manager has IFluidConfiguration");
294
273
  });
295
274
  it(`Child has Parent modules`, async () => {
296
275
  const parentDc = new __1.DependencyContainer();
@@ -307,17 +286,22 @@ describe("Routerlicious", () => {
307
286
  it(`Parent Resolved from Child`, async () => {
308
287
  const parentDc = new __1.DependencyContainer();
309
288
  const loadableToHandle = async (fds) => {
310
- // eslint-disable-next-line @typescript-eslint/ban-types
311
- const loadable = fds.synthesize({}, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
289
+ const loadable = fds.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable });
312
290
  return (await loadable.IFluidLoadable).handle;
313
291
  };
314
292
  parentDc.register(core_interfaces_1.IFluidHandle, loadableToHandle);
315
293
  const dc = new __1.DependencyContainer(parentDc);
316
294
  const loadableMock = new MockLoadable();
317
295
  dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
318
- const deps = dc.synthesize({ IFluidHandle: core_interfaces_1.IFluidHandle }, {});
296
+ const deps = dc.synthesize({ IFluidHandle: core_interfaces_1.IFluidHandle }, undefined);
319
297
  assert_1.strict(await deps.IFluidHandle !== undefined, "handle undefined");
320
298
  });
299
+ it(`Undefined Provider is not Undefined`, async () => {
300
+ const dc = new __1.DependencyContainer();
301
+ const deps = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable }, {});
302
+ assert_1.strict(deps.IFluidLoadable !== undefined, "handle undefined");
303
+ assert_1.strict(await deps.IFluidLoadable === undefined, "handle undefined");
304
+ });
321
305
  });
322
306
  });
323
307
  });