@fluidframework/synthesize 0.54.2 → 0.56.0-49831
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.
- package/dist/IFluidDependencySynthesizer.d.ts +4 -32
- package/dist/IFluidDependencySynthesizer.d.ts.map +1 -1
- package/dist/IFluidDependencySynthesizer.js.map +1 -1
- package/dist/dependencyContainer.d.ts +15 -19
- package/dist/dependencyContainer.d.ts.map +1 -1
- package/dist/dependencyContainer.js +61 -63
- package/dist/dependencyContainer.js.map +1 -1
- package/dist/test/dependencyContainer.spec.js +49 -39
- package/dist/test/dependencyContainer.spec.js.map +1 -1
- package/dist/test/tsconfig.tsbuildinfo +54 -82
- package/dist/types.d.ts +9 -26
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/lib/IFluidDependencySynthesizer.js.map +1 -1
- package/lib/dependencyContainer.js +61 -63
- package/lib/dependencyContainer.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/package.json +14 -15
|
@@ -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 {
|
|
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,22 +13,6 @@ export interface IProvideFluidDependencySynthesizer {
|
|
|
20
13
|
* and required types.
|
|
21
14
|
*/
|
|
22
15
|
export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
23
|
-
/**
|
|
24
|
-
* All the registered types available
|
|
25
|
-
*/
|
|
26
|
-
readonly registeredTypes: Iterable<(keyof IFluidObject)>;
|
|
27
|
-
/**
|
|
28
|
-
* Add a new provider
|
|
29
|
-
* @param type - Name of the Type T being provided
|
|
30
|
-
* @param provider - A provider that will resolve the T correctly when asked
|
|
31
|
-
* @throws - If passing a type that's already registered
|
|
32
|
-
*/
|
|
33
|
-
register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void;
|
|
34
|
-
/**
|
|
35
|
-
* Remove a provider
|
|
36
|
-
* @param type - Name of the provider to remove
|
|
37
|
-
*/
|
|
38
|
-
unregister<T extends keyof IFluidObject>(type: T): void;
|
|
39
16
|
/**
|
|
40
17
|
* synthesize takes optional and required types and returns an object that will fulfill the
|
|
41
18
|
* defined types based off objects that has been previously registered.
|
|
@@ -43,16 +20,11 @@ export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynt
|
|
|
43
20
|
* @param optionalTypes - optional types to be in the Scope object
|
|
44
21
|
* @param requiredTypes - required types that need to be in the Scope object
|
|
45
22
|
*/
|
|
46
|
-
synthesize<O
|
|
23
|
+
synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
|
|
47
24
|
/**
|
|
48
25
|
* Check if a given type is registered
|
|
49
|
-
* @param
|
|
50
|
-
*/
|
|
51
|
-
has(...types: (keyof IFluidObject)[]): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Get a provider. undefined if not available.
|
|
54
|
-
* @param type - Type to get
|
|
26
|
+
* @param type - Type to check
|
|
55
27
|
*/
|
|
56
|
-
|
|
28
|
+
has(type: string): boolean;
|
|
57
29
|
}
|
|
58
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,
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EAC5B,MAAM,SAAS,CAAC;AAEjB,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;IAEnF;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,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;;;
|
|
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,42 +2,38 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
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 {
|
|
13
|
-
parent: IFluidDependencySynthesizer | undefined;
|
|
11
|
+
export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
14
12
|
private readonly providers;
|
|
13
|
+
private readonly parents;
|
|
15
14
|
get IFluidDependencySynthesizer(): this;
|
|
15
|
+
constructor(...parents: (IFluidDependencySynthesizer | undefined)[]);
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
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
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
constructor(parent?: IFluidDependencySynthesizer | undefined);
|
|
22
|
+
register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Remove a provider
|
|
25
|
+
* @param type - Name of the provider to remove
|
|
23
26
|
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* {@inheritDoc (IFluidDependencySynthesizer:interface).unregister}
|
|
27
|
-
*/
|
|
28
|
-
unregister<T extends keyof IFluidObject>(type: T): void;
|
|
27
|
+
unregister(type: keyof TMap): void;
|
|
29
28
|
/**
|
|
30
29
|
* {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
|
|
31
30
|
*/
|
|
32
|
-
synthesize<O
|
|
31
|
+
synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
|
|
33
32
|
/**
|
|
34
33
|
* {@inheritDoc (IFluidDependencySynthesizer:interface).has}
|
|
34
|
+
* @param excludeParents - If true, exclude checking parent registries
|
|
35
35
|
*/
|
|
36
|
-
has(
|
|
37
|
-
/**
|
|
38
|
-
* {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}
|
|
39
|
-
*/
|
|
40
|
-
getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined;
|
|
36
|
+
has(type: string, excludeParents?: boolean): boolean;
|
|
41
37
|
private generateRequired;
|
|
42
38
|
private generateOptional;
|
|
43
39
|
private resolveProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EAGtB,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"}
|
|
@@ -5,33 +5,32 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.DependencyContainer = void 0;
|
|
8
|
+
const IFluidDependencySynthesizer_1 = require("./IFluidDependencySynthesizer");
|
|
8
9
|
/**
|
|
9
10
|
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
10
11
|
* synthesize an object based on them when requested.
|
|
11
12
|
*/
|
|
12
13
|
class DependencyContainer {
|
|
13
|
-
constructor(
|
|
14
|
-
this.parent = parent;
|
|
14
|
+
constructor(...parents) {
|
|
15
15
|
this.providers = new Map();
|
|
16
|
+
this.parents = parents.filter((v) => v !== undefined);
|
|
16
17
|
}
|
|
17
18
|
get IFluidDependencySynthesizer() { return this; }
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* {@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
|
|
26
24
|
*/
|
|
27
25
|
register(type, provider) {
|
|
28
|
-
if (this.has(type)) {
|
|
26
|
+
if (this.providers.has(type)) {
|
|
29
27
|
throw new Error(`Attempting to register a provider of type ${type} that already exists`);
|
|
30
28
|
}
|
|
31
29
|
this.providers.set(type, provider);
|
|
32
30
|
}
|
|
33
31
|
/**
|
|
34
|
-
*
|
|
32
|
+
* Remove a provider
|
|
33
|
+
* @param type - Name of the provider to remove
|
|
35
34
|
*/
|
|
36
35
|
unregister(type) {
|
|
37
36
|
if (this.providers.has(type)) {
|
|
@@ -42,77 +41,76 @@ class DependencyContainer {
|
|
|
42
41
|
* {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
|
|
43
42
|
*/
|
|
44
43
|
synthesize(optionalTypes, requiredTypes) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
const required = this.generateRequired(requiredTypes);
|
|
52
|
-
const optional = this.generateOptional(optionalTypes);
|
|
53
|
-
return Object.assign(Object.assign({}, required), optional);
|
|
44
|
+
const base = {};
|
|
45
|
+
this.generateRequired(base, requiredTypes);
|
|
46
|
+
this.generateOptional(base, optionalTypes);
|
|
47
|
+
Object.defineProperty(base, IFluidDependencySynthesizer_1.IFluidDependencySynthesizer, { get: () => this });
|
|
48
|
+
return base;
|
|
54
49
|
}
|
|
55
50
|
/**
|
|
56
51
|
* {@inheritDoc (IFluidDependencySynthesizer:interface).has}
|
|
52
|
+
* @param excludeParents - If true, exclude checking parent registries
|
|
57
53
|
*/
|
|
58
|
-
has(
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}
|
|
65
|
-
*/
|
|
66
|
-
getProvider(type) {
|
|
67
|
-
// If we have the provider return it
|
|
68
|
-
const provider = this.providers.get(type);
|
|
69
|
-
if (provider) {
|
|
70
|
-
return provider;
|
|
54
|
+
has(type, excludeParents) {
|
|
55
|
+
if (this.providers.has(type)) {
|
|
56
|
+
return true;
|
|
71
57
|
}
|
|
72
|
-
if (
|
|
73
|
-
return this.
|
|
58
|
+
if (excludeParents !== true) {
|
|
59
|
+
return this.parents.some((p) => p.has(type));
|
|
74
60
|
}
|
|
75
|
-
return
|
|
61
|
+
return false;
|
|
76
62
|
}
|
|
77
|
-
generateRequired(types) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
generateRequired(base, types) {
|
|
64
|
+
if (types === undefined)
|
|
65
|
+
return;
|
|
66
|
+
for (const key of Object.keys(types)) {
|
|
67
|
+
const provider = this.resolveProvider(key);
|
|
68
|
+
if (provider === undefined) {
|
|
69
|
+
throw new Error(`Object attempted to be created without registered required provider ${key}`);
|
|
83
70
|
}
|
|
84
|
-
|
|
85
|
-
}
|
|
71
|
+
Object.defineProperty(base, key, provider);
|
|
72
|
+
}
|
|
86
73
|
}
|
|
87
|
-
generateOptional(types) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
74
|
+
generateOptional(base, types) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (types === undefined)
|
|
77
|
+
return;
|
|
78
|
+
for (const key of Object.keys(types)) {
|
|
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);
|
|
84
|
+
}
|
|
96
85
|
}
|
|
97
|
-
resolveProvider(
|
|
86
|
+
resolveProvider(t) {
|
|
87
|
+
// If we have the provider return it
|
|
88
|
+
const provider = this.providers.get(t);
|
|
89
|
+
if (provider === undefined) {
|
|
90
|
+
for (const parent of this.parents) {
|
|
91
|
+
const sp = { [t]: t };
|
|
92
|
+
const syn = parent.synthesize(sp, {});
|
|
93
|
+
const descriptor = Object.getOwnPropertyDescriptor(syn, t);
|
|
94
|
+
if (descriptor !== undefined) {
|
|
95
|
+
return descriptor;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
98
100
|
// The double nested gets are required for lazy loading the provider resolution
|
|
99
101
|
if (typeof provider === "function") {
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
101
|
-
const self = this;
|
|
102
102
|
return {
|
|
103
|
-
get
|
|
103
|
+
get() {
|
|
104
104
|
if (provider && typeof provider === "function") {
|
|
105
|
-
return Promise.resolve(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
});
|
|
105
|
+
return Promise.resolve(this[IFluidDependencySynthesizer_1.IFluidDependencySynthesizer])
|
|
106
|
+
.then(async (fds) => provider(fds))
|
|
107
|
+
.then((p) => p === null || p === void 0 ? void 0 : p[t]);
|
|
110
108
|
}
|
|
111
109
|
},
|
|
112
110
|
};
|
|
113
111
|
}
|
|
114
112
|
return {
|
|
115
|
-
get
|
|
113
|
+
get() {
|
|
116
114
|
if (provider) {
|
|
117
115
|
return Promise.resolve(provider).then((p) => {
|
|
118
116
|
if (p) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,+EAEuC;AAEvC;;;GAGG;AACH,MAAa,mBAAmB;IAK5B,YAAmB,GAAI,OAAoD;QAJ1D,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAKzE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC5F,CAAC;IAJD,IAAW,2BAA2B,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAMzD;;;;;OAKG;IACI,QAAQ,CAAoC,IAAO,EAAE,QAA4C;QACpG,IAAI,IAAI,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C1B,OAAO,UAAU,CAAC;iBACrB;aACJ;YACD,OAAO,SAAS,CAAC;SACpB;QAED,+EAA+E;QAC/E,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;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"]}
|