@fluidframework/synthesize 2.42.0 → 2.43.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.
- package/.eslintrc.cjs +1 -4
- package/CHANGELOG.md +4 -0
- package/dist/dependencyContainer.d.ts +2 -0
- package/dist/dependencyContainer.d.ts.map +1 -1
- package/dist/dependencyContainer.js +11 -2
- package/dist/dependencyContainer.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/lib/dependencyContainer.d.ts +2 -0
- package/lib/dependencyContainer.d.ts.map +1 -1
- package/lib/dependencyContainer.js +11 -2
- package/lib/dependencyContainer.js.map +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/package.json +9 -9
- package/src/dependencyContainer.ts +20 -10
- package/src/types.ts +1 -0
package/.eslintrc.cjs
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
extends: [
|
|
8
|
-
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
|
|
9
|
-
"prettier",
|
|
10
|
-
],
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/recommended"), "prettier"],
|
|
11
8
|
parserOptions: {
|
|
12
9
|
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
13
10
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -37,6 +37,8 @@ export declare class DependencyContainer<TMap> implements IFluidDependencySynthe
|
|
|
37
37
|
*/
|
|
38
38
|
has(type: string, excludeParents?: boolean): boolean;
|
|
39
39
|
/**
|
|
40
|
+
* Get a provider for the given type.
|
|
41
|
+
* @param provider - The name of the provider to get
|
|
40
42
|
* @deprecated Needed for backwards compatability.
|
|
41
43
|
*/
|
|
42
44
|
private getProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EACN,wBAAwB,EAGxB,mBAAmB,EACnB,yBAAyB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,YAAW,2BAA2B;
|
|
1
|
+
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EACN,wBAAwB,EAGxB,mBAAmB,EACnB,yBAAyB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,YAAW,2BAA2B;IAE5E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmD;IAC7E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,IAAW,2BAA2B,IAAI,IAAI,CAE7C;gBAEkB,GAAG,OAAO,EAAE,CAAC,2BAA2B,GAAG,SAAS,CAAC,EAAE;IAI1E;;;;;OAKG;IACI,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,IAAI,EAChD,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAC1C,IAAI;IAUP;;;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,EACzD,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GACnD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC;IASjC;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO;IAS3D;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAuBnB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,eAAe;CAiDvB"}
|
|
@@ -18,6 +18,7 @@ class DependencyContainer {
|
|
|
18
18
|
return this;
|
|
19
19
|
}
|
|
20
20
|
constructor(...parents) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type here
|
|
21
22
|
this.providers = new Map();
|
|
22
23
|
this.parents = parents.filter((v) => v !== undefined);
|
|
23
24
|
}
|
|
@@ -46,6 +47,7 @@ class DependencyContainer {
|
|
|
46
47
|
* {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
|
|
47
48
|
*/
|
|
48
49
|
synthesize(optionalTypes, requiredTypes) {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
49
51
|
const base = {};
|
|
50
52
|
this.generateRequired(base, requiredTypes);
|
|
51
53
|
this.generateOptional(base, optionalTypes);
|
|
@@ -66,6 +68,8 @@ class DependencyContainer {
|
|
|
66
68
|
return false;
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
71
|
+
* Get a provider for the given type.
|
|
72
|
+
* @param provider - The name of the provider to get
|
|
69
73
|
* @deprecated Needed for backwards compatability.
|
|
70
74
|
*/
|
|
71
75
|
getProvider(provider) {
|
|
@@ -82,6 +86,7 @@ class DependencyContainer {
|
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
88
|
// older implementations of the IFluidDependencySynthesizer exposed getProvider
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
85
90
|
const maybeGetProvider = parent;
|
|
86
91
|
if (maybeGetProvider?.getProvider !== undefined) {
|
|
87
92
|
return maybeGetProvider.getProvider(provider);
|
|
@@ -116,6 +121,7 @@ class DependencyContainer {
|
|
|
116
121
|
}
|
|
117
122
|
resolveProvider(t) {
|
|
118
123
|
// If we have the provider return it
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
119
125
|
const provider = this.providers.get(t);
|
|
120
126
|
if (provider === undefined) {
|
|
121
127
|
for (const parent of this.parents) {
|
|
@@ -135,9 +141,11 @@ class DependencyContainer {
|
|
|
135
141
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
136
142
|
get() {
|
|
137
143
|
if (provider && typeof provider === "function") {
|
|
138
|
-
return Promise.resolve(this[IFluidDependencySynthesizer_js_1.IFluidDependencySynthesizer])
|
|
144
|
+
return (Promise.resolve(this[IFluidDependencySynthesizer_js_1.IFluidDependencySynthesizer])
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call
|
|
139
146
|
.then(async (fds) => provider(fds))
|
|
140
|
-
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
148
|
+
.then((p) => p?.[t]));
|
|
141
149
|
}
|
|
142
150
|
},
|
|
143
151
|
};
|
|
@@ -148,6 +156,7 @@ class DependencyContainer {
|
|
|
148
156
|
return new internal_1.LazyPromise(async () => {
|
|
149
157
|
return Promise.resolve(provider).then((p) => {
|
|
150
158
|
if (p) {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
151
160
|
return p[t];
|
|
152
161
|
}
|
|
153
162
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAkE;AAElE,qFAA+E;AAS/E;;;;;GAKG;AACH,MAAa,mBAAmB;IAG/B,IAAW,2BAA2B;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAmB,GA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AA+E;QAC/E,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACpC,OAAO;gBACN,qEAAqE;gBACrE,GAAG;oBACF,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;wBAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,4DAA2B,CAAC,CAAC;6BACvD,IAAI,CAAC,KAAK,EAAE,GAAG,EAAgB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;6BAChD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;oBACvB,CAAC;gBACF,CAAC;aACD,CAAC;QACH,CAAC;QACD,OAAO;YACN,GAAG;gBACF,IAAI,QAAQ,EAAE,CAAC;oBACd,OAAO,IAAI,sBAAW,CAAC,KAAK,IAAI,EAAE;wBACjC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;4BAC3C,IAAI,CAAC,EAAE,CAAC;gCACP,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;4BACb,CAAC;wBACF,CAAC,CAAC,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD;AA1KD,kDA0KC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { LazyPromise } from \"@fluidframework/core-utils/internal\";\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\nimport {\n\tAsyncFluidObjectProvider,\n\tAsyncOptionalFluidObjectProvider,\n\tAsyncRequiredFluidObjectProvider,\n\tFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n} from \"./types.js\";\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 * @legacy\n * @alpha\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n\tprivate readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();\n\tprivate readonly parents: IFluidDependencySynthesizer[];\n\tpublic get IFluidDependencySynthesizer() {\n\t\treturn this;\n\t}\n\n\tpublic constructor(...parents: (IFluidDependencySynthesizer | undefined)[]) {\n\t\tthis.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n\t}\n\n\t/**\n\t * Add a new provider\n\t * @param type - Name of the Type T being provided\n\t * @param provider - A provider that will resolve the T correctly when asked\n\t * @throws - If passing a type that's already registered\n\t */\n\tpublic register<T extends keyof TMap = keyof TMap>(\n\t\ttype: T,\n\t\tprovider: FluidObjectProvider<Pick<TMap, T>>,\n\t): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Attempting to register a provider of type ${String(type)} that already exists`,\n\t\t\t);\n\t\t}\n\n\t\tthis.providers.set(type, provider);\n\t}\n\n\t/**\n\t * Remove a provider\n\t * @param type - Name of the provider to remove\n\t */\n\tpublic unregister(type: keyof TMap): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthis.providers.delete(type);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n\t */\n\tpublic synthesize<O, R = undefined | Record<string, never>>(\n\t\toptionalTypes: FluidObjectSymbolProvider<O>,\n\t\trequiredTypes: Required<FluidObjectSymbolProvider<R>>,\n\t): AsyncFluidObjectProvider<O, R> {\n\t\tconst base: AsyncFluidObjectProvider<O, R> = {} as any;\n\t\tthis.generateRequired<R>(base, requiredTypes);\n\t\tthis.generateOptional<O>(base, optionalTypes);\n\t\tObject.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n\t\treturn base;\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n\t * @param excludeParents - If true, exclude checking parent registries\n\t */\n\tpublic has(type: string, excludeParents?: boolean): boolean {\n\t\tif (this.providers.has(type as keyof TMap)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (excludeParents !== true) {\n\t\t\treturn this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n\t\t}\n\t\treturn false;\n\t}\n\t/**\n\t * @deprecated Needed for backwards compatability.\n\t */\n\tprivate getProvider(provider: string & keyof TMap) {\n\t\t// this was removed, but some partners have trouble with back compat where they\n\t\t// use invalid patterns with FluidObject and IFluidDependencySynthesizer\n\t\t// this is just for back compat until those are removed\n\t\tif (this.has(provider)) {\n\t\t\tif (this.providers.has(provider)) {\n\t\t\t\treturn this.providers.get(provider);\n\t\t\t}\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\tif (parent instanceof DependencyContainer) {\n\t\t\t\t\treturn parent.getProvider(provider);\n\t\t\t\t} else {\n\t\t\t\t\t// older implementations of the IFluidDependencySynthesizer exposed getProvider\n\t\t\t\t\tconst maybeGetProvider: { getProvider?(provider: string & keyof TMap) } =\n\t\t\t\t\t\tparent as any;\n\t\t\t\t\tif (maybeGetProvider?.getProvider !== undefined) {\n\t\t\t\t\t\treturn maybeGetProvider.getProvider(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate generateRequired<T>(\n\t\tbase: AsyncRequiredFluidObjectProvider<T>,\n\t\ttypes: Required<FluidObjectSymbolProvider<T>>,\n\t) {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\tconst provider = this.resolveProvider(key);\n\t\t\tif (provider === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Object attempted to be created without registered required provider ${String(key)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate generateOptional<T>(\n\t\tbase: AsyncOptionalFluidObjectProvider<T>,\n\t\ttypes: FluidObjectSymbolProvider<T>,\n\t) {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\t// back-compat: in 0.56 we allow undefined in the types, but we didn't before\n\t\t\t// this will keep runtime back compat, eventually we should support undefined properties\n\t\t\t// rather than properties that return promises that resolve to undefined\n\t\t\tconst provider = this.resolveProvider(key) ?? { get: async () => undefined };\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {\n\t\t// If we have the provider return it\n\t\tconst provider = this.providers.get(t);\n\t\tif (provider === undefined) {\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tconst sp = { [t]: t } as FluidObjectSymbolProvider<Pick<TMap, T>>;\n\t\t\t\tconst syn = parent.synthesize<Pick<TMap, T>, Record<string, unknown>>(sp, {});\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(syn, t);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\treturn descriptor;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The double nested gets are required for lazy loading the provider resolution\n\t\tif (typeof provider === \"function\") {\n\t\t\treturn {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t\t\tget() {\n\t\t\t\t\tif (provider && typeof provider === \"function\") {\n\t\t\t\t\t\treturn Promise.resolve(this[IFluidDependencySynthesizer])\n\t\t\t\t\t\t\t.then(async (fds): Promise<any> => provider(fds))\n\t\t\t\t\t\t\t.then((p) => p?.[t]);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tget() {\n\t\t\t\tif (provider) {\n\t\t\t\t\treturn new LazyPromise(async () => {\n\t\t\t\t\t\treturn Promise.resolve(provider).then((p) => {\n\t\t\t\t\t\t\tif (p) {\n\t\t\t\t\t\t\t\treturn p[t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,CAAC,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD;AApLD,kDAoLC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { LazyPromise } from \"@fluidframework/core-utils/internal\";\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\nimport {\n\tAsyncFluidObjectProvider,\n\tAsyncOptionalFluidObjectProvider,\n\tAsyncRequiredFluidObjectProvider,\n\tFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n} from \"./types.js\";\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 * @legacy\n * @alpha\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type here\n\tprivate readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();\n\tprivate readonly parents: IFluidDependencySynthesizer[];\n\tpublic get IFluidDependencySynthesizer(): this {\n\t\treturn this;\n\t}\n\n\tpublic constructor(...parents: (IFluidDependencySynthesizer | undefined)[]) {\n\t\tthis.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n\t}\n\n\t/**\n\t * Add a new provider\n\t * @param type - Name of the Type T being provided\n\t * @param provider - A provider that will resolve the T correctly when asked\n\t * @throws - If passing a type that's already registered\n\t */\n\tpublic register<T extends keyof TMap = keyof TMap>(\n\t\ttype: T,\n\t\tprovider: FluidObjectProvider<Pick<TMap, T>>,\n\t): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Attempting to register a provider of type ${String(type)} that already exists`,\n\t\t\t);\n\t\t}\n\n\t\tthis.providers.set(type, provider);\n\t}\n\n\t/**\n\t * Remove a provider\n\t * @param type - Name of the provider to remove\n\t */\n\tpublic unregister(type: keyof TMap): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthis.providers.delete(type);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n\t */\n\tpublic synthesize<O, R = undefined | Record<string, never>>(\n\t\toptionalTypes: FluidObjectSymbolProvider<O>,\n\t\trequiredTypes: Required<FluidObjectSymbolProvider<R>>,\n\t): AsyncFluidObjectProvider<O, R> {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst base: AsyncFluidObjectProvider<O, R> = {} as AsyncFluidObjectProvider<O, R>;\n\t\tthis.generateRequired<R>(base, requiredTypes);\n\t\tthis.generateOptional<O>(base, optionalTypes);\n\t\tObject.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n\t\treturn base;\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n\t * @param excludeParents - If true, exclude checking parent registries\n\t */\n\tpublic has(type: string, excludeParents?: boolean): boolean {\n\t\tif (this.providers.has(type as keyof TMap)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (excludeParents !== true) {\n\t\t\treturn this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n\t\t}\n\t\treturn false;\n\t}\n\t/**\n\t * Get a provider for the given type.\n\t * @param provider - The name of the provider to get\n\t * @deprecated Needed for backwards compatability.\n\t */\n\tprivate getProvider(provider: string & keyof TMap): PropertyDescriptor | undefined {\n\t\t// this was removed, but some partners have trouble with back compat where they\n\t\t// use invalid patterns with FluidObject and IFluidDependencySynthesizer\n\t\t// this is just for back compat until those are removed\n\t\tif (this.has(provider)) {\n\t\t\tif (this.providers.has(provider)) {\n\t\t\t\treturn this.providers.get(provider);\n\t\t\t}\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\tif (parent instanceof DependencyContainer) {\n\t\t\t\t\treturn parent.getProvider(provider);\n\t\t\t\t} else {\n\t\t\t\t\t// older implementations of the IFluidDependencySynthesizer exposed getProvider\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\tconst maybeGetProvider = parent as { getProvider?(provider: string & keyof TMap) };\n\t\t\t\t\tif (maybeGetProvider?.getProvider !== undefined) {\n\t\t\t\t\t\treturn maybeGetProvider.getProvider(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate generateRequired<T>(\n\t\tbase: AsyncRequiredFluidObjectProvider<T>,\n\t\ttypes: Required<FluidObjectSymbolProvider<T>>,\n\t): void {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\tconst provider = this.resolveProvider(key);\n\t\t\tif (provider === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Object attempted to be created without registered required provider ${String(key)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate generateOptional<T>(\n\t\tbase: AsyncOptionalFluidObjectProvider<T>,\n\t\ttypes: FluidObjectSymbolProvider<T>,\n\t): void {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\t// back-compat: in 0.56 we allow undefined in the types, but we didn't before\n\t\t\t// this will keep runtime back compat, eventually we should support undefined properties\n\t\t\t// rather than properties that return promises that resolve to undefined\n\t\t\tconst provider = this.resolveProvider(key) ?? { get: async () => undefined };\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {\n\t\t// If we have the provider return it\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\tconst provider = this.providers.get(t);\n\t\tif (provider === undefined) {\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tconst sp = { [t]: t } as FluidObjectSymbolProvider<Pick<TMap, T>>;\n\t\t\t\tconst syn = parent.synthesize<Pick<TMap, T>, Record<string, unknown>>(sp, {});\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(syn, t);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\treturn descriptor;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The double nested gets are required for lazy loading the provider resolution\n\t\tif (typeof provider === \"function\") {\n\t\t\treturn {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t\t\tget() {\n\t\t\t\t\tif (provider && typeof provider === \"function\") {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tPromise.resolve(this[IFluidDependencySynthesizer])\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call\n\t\t\t\t\t\t\t\t.then(async (fds): Promise<any> => provider(fds))\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t.then((p) => p?.[t])\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tget() {\n\t\t\t\tif (provider) {\n\t\t\t\t\treturn new LazyPromise(async () => {\n\t\t\t\t\t\treturn Promise.resolve(provider).then((p) => {\n\t\t\t\t\t\t\tif (p) {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\treturn p[t];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n}\n"]}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAA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H,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC9B,WAAW,CAAC,CAAC,CAAC,GACd,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,mBAAmB,EAAE,2BAA2B,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,GACtE,CAAC,CAAC,mBAAmB,EAAE,2BAA2B,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to a string representation\n * of that property.\n *\n * @example\n *\n * ```typescript\n * { IFoo: \"IFoo\" }\n * ```\n * @legacy\n * @alpha\n */\nexport type FluidObjectSymbolProvider<T> = {\n\t[P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to an object that implements\n * the property.\n * @legacy\n * @alpha\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t\t};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type, mapped to an object that implements\n * the property or undefined.\n * @legacy\n * @alpha\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]?: Promise<T[P] | undefined>;\n\t\t};\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n * @legacy\n * @alpha\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @legacy\n * @alpha\n */\nexport type FluidObjectProvider<T> =\n\t| NonNullable<T>\n\t| Promise<NonNullable<T>>\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to a string representation\n * of that property.\n *\n * @example\n *\n * ```typescript\n * { IFoo: \"IFoo\" }\n * ```\n * @legacy\n * @alpha\n */\nexport type FluidObjectSymbolProvider<T> = {\n\t[P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to an object that implements\n * the property.\n * @legacy\n * @alpha\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null -- supported by JavaScript; it isn't deprecated\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t\t};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type, mapped to an object that implements\n * the property or undefined.\n * @legacy\n * @alpha\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]?: Promise<T[P] | undefined>;\n\t\t};\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n * @legacy\n * @alpha\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @legacy\n * @alpha\n */\nexport type FluidObjectProvider<T> =\n\t| NonNullable<T>\n\t| Promise<NonNullable<T>>\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);\n"]}
|
|
@@ -37,6 +37,8 @@ export declare class DependencyContainer<TMap> implements IFluidDependencySynthe
|
|
|
37
37
|
*/
|
|
38
38
|
has(type: string, excludeParents?: boolean): boolean;
|
|
39
39
|
/**
|
|
40
|
+
* Get a provider for the given type.
|
|
41
|
+
* @param provider - The name of the provider to get
|
|
40
42
|
* @deprecated Needed for backwards compatability.
|
|
41
43
|
*/
|
|
42
44
|
private getProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EACN,wBAAwB,EAGxB,mBAAmB,EACnB,yBAAyB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,YAAW,2BAA2B;
|
|
1
|
+
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EACN,wBAAwB,EAGxB,mBAAmB,EACnB,yBAAyB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,YAAW,2BAA2B;IAE5E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmD;IAC7E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,IAAW,2BAA2B,IAAI,IAAI,CAE7C;gBAEkB,GAAG,OAAO,EAAE,CAAC,2BAA2B,GAAG,SAAS,CAAC,EAAE;IAI1E;;;;;OAKG;IACI,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,IAAI,EAChD,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAC1C,IAAI;IAUP;;;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,EACzD,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GACnD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC;IASjC;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO;IAS3D;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAuBnB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,eAAe;CAiDvB"}
|
|
@@ -15,6 +15,7 @@ export class DependencyContainer {
|
|
|
15
15
|
return this;
|
|
16
16
|
}
|
|
17
17
|
constructor(...parents) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type here
|
|
18
19
|
this.providers = new Map();
|
|
19
20
|
this.parents = parents.filter((v) => v !== undefined);
|
|
20
21
|
}
|
|
@@ -43,6 +44,7 @@ export class DependencyContainer {
|
|
|
43
44
|
* {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
|
|
44
45
|
*/
|
|
45
46
|
synthesize(optionalTypes, requiredTypes) {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
46
48
|
const base = {};
|
|
47
49
|
this.generateRequired(base, requiredTypes);
|
|
48
50
|
this.generateOptional(base, optionalTypes);
|
|
@@ -63,6 +65,8 @@ export class DependencyContainer {
|
|
|
63
65
|
return false;
|
|
64
66
|
}
|
|
65
67
|
/**
|
|
68
|
+
* Get a provider for the given type.
|
|
69
|
+
* @param provider - The name of the provider to get
|
|
66
70
|
* @deprecated Needed for backwards compatability.
|
|
67
71
|
*/
|
|
68
72
|
getProvider(provider) {
|
|
@@ -79,6 +83,7 @@ export class DependencyContainer {
|
|
|
79
83
|
}
|
|
80
84
|
else {
|
|
81
85
|
// older implementations of the IFluidDependencySynthesizer exposed getProvider
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
82
87
|
const maybeGetProvider = parent;
|
|
83
88
|
if (maybeGetProvider?.getProvider !== undefined) {
|
|
84
89
|
return maybeGetProvider.getProvider(provider);
|
|
@@ -113,6 +118,7 @@ export class DependencyContainer {
|
|
|
113
118
|
}
|
|
114
119
|
resolveProvider(t) {
|
|
115
120
|
// If we have the provider return it
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
116
122
|
const provider = this.providers.get(t);
|
|
117
123
|
if (provider === undefined) {
|
|
118
124
|
for (const parent of this.parents) {
|
|
@@ -132,9 +138,11 @@ export class DependencyContainer {
|
|
|
132
138
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
133
139
|
get() {
|
|
134
140
|
if (provider && typeof provider === "function") {
|
|
135
|
-
return Promise.resolve(this[IFluidDependencySynthesizer])
|
|
141
|
+
return (Promise.resolve(this[IFluidDependencySynthesizer])
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call
|
|
136
143
|
.then(async (fds) => provider(fds))
|
|
137
|
-
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
145
|
+
.then((p) => p?.[t]));
|
|
138
146
|
}
|
|
139
147
|
},
|
|
140
148
|
};
|
|
@@ -145,6 +153,7 @@ export class DependencyContainer {
|
|
|
145
153
|
return new LazyPromise(async () => {
|
|
146
154
|
return Promise.resolve(provider).then((p) => {
|
|
147
155
|
if (p) {
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
148
157
|
return p[t];
|
|
149
158
|
}
|
|
150
159
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAS/E;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IAG/B,IAAW,2BAA2B;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAmB,GAAG,OAAoD;QANzD,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAO5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACI,QAAQ,CACd,IAAO,EACP,QAA4C;QAE5C,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACd,6CAA6C,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAC/E,CAAC;QACH,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,IAAgB;QACjC,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9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CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;4BAC3C,IAAI,CAAC,EAAE,CAAC;gCACP,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;4BACb,CAAC;wBACF,CAAC,CAAC,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { LazyPromise } from \"@fluidframework/core-utils/internal\";\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\nimport {\n\tAsyncFluidObjectProvider,\n\tAsyncOptionalFluidObjectProvider,\n\tAsyncRequiredFluidObjectProvider,\n\tFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n} from \"./types.js\";\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 * @legacy\n * @alpha\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n\tprivate readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();\n\tprivate readonly parents: IFluidDependencySynthesizer[];\n\tpublic get IFluidDependencySynthesizer() {\n\t\treturn this;\n\t}\n\n\tpublic constructor(...parents: (IFluidDependencySynthesizer | undefined)[]) {\n\t\tthis.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n\t}\n\n\t/**\n\t * Add a new provider\n\t * @param type - Name of the Type T being provided\n\t * @param provider - A provider that will resolve the T correctly when asked\n\t * @throws - If passing a type that's already registered\n\t */\n\tpublic register<T extends keyof TMap = keyof TMap>(\n\t\ttype: T,\n\t\tprovider: FluidObjectProvider<Pick<TMap, T>>,\n\t): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Attempting to register a provider of type ${String(type)} that already exists`,\n\t\t\t);\n\t\t}\n\n\t\tthis.providers.set(type, provider);\n\t}\n\n\t/**\n\t * Remove a provider\n\t * @param type - Name of the provider to remove\n\t */\n\tpublic unregister(type: keyof TMap): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthis.providers.delete(type);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n\t */\n\tpublic synthesize<O, R = undefined | Record<string, never>>(\n\t\toptionalTypes: FluidObjectSymbolProvider<O>,\n\t\trequiredTypes: Required<FluidObjectSymbolProvider<R>>,\n\t): AsyncFluidObjectProvider<O, R> {\n\t\tconst base: AsyncFluidObjectProvider<O, R> = {} as any;\n\t\tthis.generateRequired<R>(base, requiredTypes);\n\t\tthis.generateOptional<O>(base, optionalTypes);\n\t\tObject.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n\t\treturn base;\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n\t * @param excludeParents - If true, exclude checking parent registries\n\t */\n\tpublic has(type: string, excludeParents?: boolean): boolean {\n\t\tif (this.providers.has(type as keyof TMap)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (excludeParents !== true) {\n\t\t\treturn this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n\t\t}\n\t\treturn false;\n\t}\n\t/**\n\t * @deprecated Needed for backwards compatability.\n\t */\n\tprivate getProvider(provider: string & keyof TMap) {\n\t\t// this was removed, but some partners have trouble with back compat where they\n\t\t// use invalid patterns with FluidObject and IFluidDependencySynthesizer\n\t\t// this is just for back compat until those are removed\n\t\tif (this.has(provider)) {\n\t\t\tif (this.providers.has(provider)) {\n\t\t\t\treturn this.providers.get(provider);\n\t\t\t}\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\tif (parent instanceof DependencyContainer) {\n\t\t\t\t\treturn parent.getProvider(provider);\n\t\t\t\t} else {\n\t\t\t\t\t// older implementations of the IFluidDependencySynthesizer exposed getProvider\n\t\t\t\t\tconst maybeGetProvider: { getProvider?(provider: string & keyof TMap) } =\n\t\t\t\t\t\tparent as any;\n\t\t\t\t\tif (maybeGetProvider?.getProvider !== undefined) {\n\t\t\t\t\t\treturn maybeGetProvider.getProvider(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate generateRequired<T>(\n\t\tbase: AsyncRequiredFluidObjectProvider<T>,\n\t\ttypes: Required<FluidObjectSymbolProvider<T>>,\n\t) {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\tconst provider = this.resolveProvider(key);\n\t\t\tif (provider === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Object attempted to be created without registered required provider ${String(key)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate generateOptional<T>(\n\t\tbase: AsyncOptionalFluidObjectProvider<T>,\n\t\ttypes: FluidObjectSymbolProvider<T>,\n\t) {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\t// back-compat: in 0.56 we allow undefined in the types, but we didn't before\n\t\t\t// this will keep runtime back compat, eventually we should support undefined properties\n\t\t\t// rather than properties that return promises that resolve to undefined\n\t\t\tconst provider = this.resolveProvider(key) ?? { get: async () => undefined };\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {\n\t\t// If we have the provider return it\n\t\tconst provider = this.providers.get(t);\n\t\tif (provider === undefined) {\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tconst sp = { [t]: t } as FluidObjectSymbolProvider<Pick<TMap, T>>;\n\t\t\t\tconst syn = parent.synthesize<Pick<TMap, T>, Record<string, unknown>>(sp, {});\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(syn, t);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\treturn descriptor;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The double nested gets are required for lazy loading the provider resolution\n\t\tif (typeof provider === \"function\") {\n\t\t\treturn {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t\t\tget() {\n\t\t\t\t\tif (provider && typeof provider === \"function\") {\n\t\t\t\t\t\treturn Promise.resolve(this[IFluidDependencySynthesizer])\n\t\t\t\t\t\t\t.then(async (fds): Promise<any> => provider(fds))\n\t\t\t\t\t\t\t.then((p) => p?.[t]);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tget() {\n\t\t\t\tif (provider) {\n\t\t\t\t\treturn new LazyPromise(async () => {\n\t\t\t\t\t\treturn Promise.resolve(provider).then((p) => {\n\t\t\t\t\t\t\tif (p) {\n\t\t\t\t\t\t\t\treturn p[t];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAS/E;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IAI/B,IAAW,2BAA2B;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAmB,GAAG,OAAoD;QAP1E,4FAA4F;QAC3E,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAO5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACzF,CAA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AQ,KAAK,UAAU,EAAE,CAAC;wBAChD,OAAO,CACN,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;4BACjD,iGAAiG;6BAChG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAgB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;4BACjD,sEAAsE;6BACrE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CACrB,CAAC;oBACH,CAAC;gBACF,CAAC;aACD,CAAC;QACH,CAAC;QACD,OAAO;YACN,GAAG;gBACF,IAAI,QAAQ,EAAE,CAAC;oBACd,OAAO,IAAI,WAAW,CAAC,KAAK,IAAI,EAAE;wBACjC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;4BAC3C,IAAI,CAAC,EAAE,CAAC;gCACP,sEAAsE;gCACtE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;4BACb,CAAC;wBACF,CAAC,CAAC,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { LazyPromise } from \"@fluidframework/core-utils/internal\";\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\nimport {\n\tAsyncFluidObjectProvider,\n\tAsyncOptionalFluidObjectProvider,\n\tAsyncRequiredFluidObjectProvider,\n\tFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n} from \"./types.js\";\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 * @legacy\n * @alpha\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type here\n\tprivate readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();\n\tprivate readonly parents: IFluidDependencySynthesizer[];\n\tpublic get IFluidDependencySynthesizer(): this {\n\t\treturn this;\n\t}\n\n\tpublic constructor(...parents: (IFluidDependencySynthesizer | undefined)[]) {\n\t\tthis.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n\t}\n\n\t/**\n\t * Add a new provider\n\t * @param type - Name of the Type T being provided\n\t * @param provider - A provider that will resolve the T correctly when asked\n\t * @throws - If passing a type that's already registered\n\t */\n\tpublic register<T extends keyof TMap = keyof TMap>(\n\t\ttype: T,\n\t\tprovider: FluidObjectProvider<Pick<TMap, T>>,\n\t): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Attempting to register a provider of type ${String(type)} that already exists`,\n\t\t\t);\n\t\t}\n\n\t\tthis.providers.set(type, provider);\n\t}\n\n\t/**\n\t * Remove a provider\n\t * @param type - Name of the provider to remove\n\t */\n\tpublic unregister(type: keyof TMap): void {\n\t\tif (this.providers.has(type)) {\n\t\t\tthis.providers.delete(type);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n\t */\n\tpublic synthesize<O, R = undefined | Record<string, never>>(\n\t\toptionalTypes: FluidObjectSymbolProvider<O>,\n\t\trequiredTypes: Required<FluidObjectSymbolProvider<R>>,\n\t): AsyncFluidObjectProvider<O, R> {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst base: AsyncFluidObjectProvider<O, R> = {} as AsyncFluidObjectProvider<O, R>;\n\t\tthis.generateRequired<R>(base, requiredTypes);\n\t\tthis.generateOptional<O>(base, optionalTypes);\n\t\tObject.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n\t\treturn base;\n\t}\n\n\t/**\n\t * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n\t * @param excludeParents - If true, exclude checking parent registries\n\t */\n\tpublic has(type: string, excludeParents?: boolean): boolean {\n\t\tif (this.providers.has(type as keyof TMap)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (excludeParents !== true) {\n\t\t\treturn this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n\t\t}\n\t\treturn false;\n\t}\n\t/**\n\t * Get a provider for the given type.\n\t * @param provider - The name of the provider to get\n\t * @deprecated Needed for backwards compatability.\n\t */\n\tprivate getProvider(provider: string & keyof TMap): PropertyDescriptor | undefined {\n\t\t// this was removed, but some partners have trouble with back compat where they\n\t\t// use invalid patterns with FluidObject and IFluidDependencySynthesizer\n\t\t// this is just for back compat until those are removed\n\t\tif (this.has(provider)) {\n\t\t\tif (this.providers.has(provider)) {\n\t\t\t\treturn this.providers.get(provider);\n\t\t\t}\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\tif (parent instanceof DependencyContainer) {\n\t\t\t\t\treturn parent.getProvider(provider);\n\t\t\t\t} else {\n\t\t\t\t\t// older implementations of the IFluidDependencySynthesizer exposed getProvider\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\tconst maybeGetProvider = parent as { getProvider?(provider: string & keyof TMap) };\n\t\t\t\t\tif (maybeGetProvider?.getProvider !== undefined) {\n\t\t\t\t\t\treturn maybeGetProvider.getProvider(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate generateRequired<T>(\n\t\tbase: AsyncRequiredFluidObjectProvider<T>,\n\t\ttypes: Required<FluidObjectSymbolProvider<T>>,\n\t): void {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\tconst provider = this.resolveProvider(key);\n\t\t\tif (provider === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Object attempted to be created without registered required provider ${String(key)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate generateOptional<T>(\n\t\tbase: AsyncOptionalFluidObjectProvider<T>,\n\t\ttypes: FluidObjectSymbolProvider<T>,\n\t): void {\n\t\tif (types === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n\t\t\t// back-compat: in 0.56 we allow undefined in the types, but we didn't before\n\t\t\t// this will keep runtime back compat, eventually we should support undefined properties\n\t\t\t// rather than properties that return promises that resolve to undefined\n\t\t\tconst provider = this.resolveProvider(key) ?? { get: async () => undefined };\n\t\t\tObject.defineProperty(base, key, provider);\n\t\t}\n\t}\n\n\tprivate resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {\n\t\t// If we have the provider return it\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\tconst provider = this.providers.get(t);\n\t\tif (provider === undefined) {\n\t\t\tfor (const parent of this.parents) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tconst sp = { [t]: t } as FluidObjectSymbolProvider<Pick<TMap, T>>;\n\t\t\t\tconst syn = parent.synthesize<Pick<TMap, T>, Record<string, unknown>>(sp, {});\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(syn, t);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\treturn descriptor;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The double nested gets are required for lazy loading the provider resolution\n\t\tif (typeof provider === \"function\") {\n\t\t\treturn {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t\t\tget() {\n\t\t\t\t\tif (provider && typeof provider === \"function\") {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tPromise.resolve(this[IFluidDependencySynthesizer])\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call\n\t\t\t\t\t\t\t\t.then(async (fds): Promise<any> => provider(fds))\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t.then((p) => p?.[t])\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tget() {\n\t\t\t\tif (provider) {\n\t\t\t\t\treturn new LazyPromise(async () => {\n\t\t\t\t\t\treturn Promise.resolve(provider).then((p) => {\n\t\t\t\t\t\t\tif (p) {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\treturn p[t];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n}\n"]}
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAClE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACrB;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAClE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACrB;KAEC,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;CACrE,CAAC;AAEJ;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAClE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACrB;KACC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAC1C,CAAC;AAEJ;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,IAAI,gCAAgC,CAAC,CAAC,CAAC,GAC3F,gCAAgC,CAAC,CAAC,CAAC,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC9B,WAAW,CAAC,CAAC,CAAC,GACd,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,mBAAmB,EAAE,2BAA2B,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,GACtE,CAAC,CAAC,mBAAmB,EAAE,2BAA2B,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to a string representation\n * of that property.\n *\n * @example\n *\n * ```typescript\n * { IFoo: \"IFoo\" }\n * ```\n * @legacy\n * @alpha\n */\nexport type FluidObjectSymbolProvider<T> = {\n\t[P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to an object that implements\n * the property.\n * @legacy\n * @alpha\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t\t};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type, mapped to an object that implements\n * the property or undefined.\n * @legacy\n * @alpha\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]?: Promise<T[P] | undefined>;\n\t\t};\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n * @legacy\n * @alpha\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @legacy\n * @alpha\n */\nexport type FluidObjectProvider<T> =\n\t| NonNullable<T>\n\t| Promise<NonNullable<T>>\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer.js\";\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to a string representation\n * of that property.\n *\n * @example\n *\n * ```typescript\n * { IFoo: \"IFoo\" }\n * ```\n * @legacy\n * @alpha\n */\nexport type FluidObjectSymbolProvider<T> = {\n\t[P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to an object that implements\n * the property.\n * @legacy\n * @alpha\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null -- supported by JavaScript; it isn't deprecated\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t\t};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type, mapped to an object that implements\n * the property or undefined.\n * @legacy\n * @alpha\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]?: Promise<T[P] | undefined>;\n\t\t};\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n * @legacy\n * @alpha\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @legacy\n * @alpha\n */\nexport type FluidObjectProvider<T> =\n\t| NonNullable<T>\n\t| Promise<NonNullable<T>>\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/synthesize",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.43.0",
|
|
4
4
|
"description": "A library for synthesizing scope objects.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,20 +69,20 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluidframework/core-utils": "~2.
|
|
72
|
+
"@fluidframework/core-utils": "~2.43.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
76
76
|
"@biomejs/biome": "~1.9.3",
|
|
77
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
78
|
-
"@fluid-tools/build-cli": "^0.
|
|
77
|
+
"@fluid-internal/mocha-test-setup": "~2.43.0",
|
|
78
|
+
"@fluid-tools/build-cli": "^0.56.0",
|
|
79
79
|
"@fluidframework/build-common": "^2.0.3",
|
|
80
|
-
"@fluidframework/build-tools": "^0.
|
|
81
|
-
"@fluidframework/core-interfaces": "~2.
|
|
82
|
-
"@fluidframework/datastore": "~2.
|
|
80
|
+
"@fluidframework/build-tools": "^0.56.0",
|
|
81
|
+
"@fluidframework/core-interfaces": "~2.43.0",
|
|
82
|
+
"@fluidframework/datastore": "~2.43.0",
|
|
83
83
|
"@fluidframework/eslint-config-fluid": "^5.7.4",
|
|
84
|
-
"@fluidframework/runtime-utils": "~2.
|
|
85
|
-
"@fluidframework/synthesize-previous": "npm:@fluidframework/synthesize@2.
|
|
84
|
+
"@fluidframework/runtime-utils": "~2.43.0",
|
|
85
|
+
"@fluidframework/synthesize-previous": "npm:@fluidframework/synthesize@2.42.0",
|
|
86
86
|
"@microsoft/api-extractor": "7.52.8",
|
|
87
87
|
"@types/mocha": "^10.0.10",
|
|
88
88
|
"@types/node": "^18.19.0",
|
|
@@ -21,9 +21,10 @@ import {
|
|
|
21
21
|
* @alpha
|
|
22
22
|
*/
|
|
23
23
|
export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type here
|
|
24
25
|
private readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();
|
|
25
26
|
private readonly parents: IFluidDependencySynthesizer[];
|
|
26
|
-
public get IFluidDependencySynthesizer() {
|
|
27
|
+
public get IFluidDependencySynthesizer(): this {
|
|
27
28
|
return this;
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -67,7 +68,8 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
67
68
|
optionalTypes: FluidObjectSymbolProvider<O>,
|
|
68
69
|
requiredTypes: Required<FluidObjectSymbolProvider<R>>,
|
|
69
70
|
): AsyncFluidObjectProvider<O, R> {
|
|
70
|
-
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
72
|
+
const base: AsyncFluidObjectProvider<O, R> = {} as AsyncFluidObjectProvider<O, R>;
|
|
71
73
|
this.generateRequired<R>(base, requiredTypes);
|
|
72
74
|
this.generateOptional<O>(base, optionalTypes);
|
|
73
75
|
Object.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });
|
|
@@ -88,9 +90,11 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
88
90
|
return false;
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
93
|
+
* Get a provider for the given type.
|
|
94
|
+
* @param provider - The name of the provider to get
|
|
91
95
|
* @deprecated Needed for backwards compatability.
|
|
92
96
|
*/
|
|
93
|
-
private getProvider(provider: string & keyof TMap) {
|
|
97
|
+
private getProvider(provider: string & keyof TMap): PropertyDescriptor | undefined {
|
|
94
98
|
// this was removed, but some partners have trouble with back compat where they
|
|
95
99
|
// use invalid patterns with FluidObject and IFluidDependencySynthesizer
|
|
96
100
|
// this is just for back compat until those are removed
|
|
@@ -103,8 +107,8 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
103
107
|
return parent.getProvider(provider);
|
|
104
108
|
} else {
|
|
105
109
|
// older implementations of the IFluidDependencySynthesizer exposed getProvider
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
111
|
+
const maybeGetProvider = parent as { getProvider?(provider: string & keyof TMap) };
|
|
108
112
|
if (maybeGetProvider?.getProvider !== undefined) {
|
|
109
113
|
return maybeGetProvider.getProvider(provider);
|
|
110
114
|
}
|
|
@@ -116,7 +120,7 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
116
120
|
private generateRequired<T>(
|
|
117
121
|
base: AsyncRequiredFluidObjectProvider<T>,
|
|
118
122
|
types: Required<FluidObjectSymbolProvider<T>>,
|
|
119
|
-
) {
|
|
123
|
+
): void {
|
|
120
124
|
if (types === undefined) {
|
|
121
125
|
return;
|
|
122
126
|
}
|
|
@@ -134,7 +138,7 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
134
138
|
private generateOptional<T>(
|
|
135
139
|
base: AsyncOptionalFluidObjectProvider<T>,
|
|
136
140
|
types: FluidObjectSymbolProvider<T>,
|
|
137
|
-
) {
|
|
141
|
+
): void {
|
|
138
142
|
if (types === undefined) {
|
|
139
143
|
return;
|
|
140
144
|
}
|
|
@@ -149,6 +153,7 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
149
153
|
|
|
150
154
|
private resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {
|
|
151
155
|
// If we have the provider return it
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
152
157
|
const provider = this.providers.get(t);
|
|
153
158
|
if (provider === undefined) {
|
|
154
159
|
for (const parent of this.parents) {
|
|
@@ -169,9 +174,13 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
169
174
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
170
175
|
get() {
|
|
171
176
|
if (provider && typeof provider === "function") {
|
|
172
|
-
return
|
|
173
|
-
.
|
|
174
|
-
|
|
177
|
+
return (
|
|
178
|
+
Promise.resolve(this[IFluidDependencySynthesizer])
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call
|
|
180
|
+
.then(async (fds): Promise<any> => provider(fds))
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
182
|
+
.then((p) => p?.[t])
|
|
183
|
+
);
|
|
175
184
|
}
|
|
176
185
|
},
|
|
177
186
|
};
|
|
@@ -182,6 +191,7 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
182
191
|
return new LazyPromise(async () => {
|
|
183
192
|
return Promise.resolve(provider).then((p) => {
|
|
184
193
|
if (p) {
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
185
195
|
return p[t];
|
|
186
196
|
}
|
|
187
197
|
});
|
package/src/types.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type FluidObjectSymbolProvider<T> = {
|
|
|
32
32
|
export type AsyncRequiredFluidObjectProvider<T> = T extends undefined
|
|
33
33
|
? Record<string, never>
|
|
34
34
|
: {
|
|
35
|
+
// eslint-disable-next-line @rushstack/no-new-null -- supported by JavaScript; it isn't deprecated
|
|
35
36
|
[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
|
|
36
37
|
};
|
|
37
38
|
|