@fluidframework/synthesize 2.53.1 → 2.60.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/CHANGELOG.md +4 -0
- package/api-report/{synthesize.legacy.alpha.api.md → synthesize.legacy.beta.api.md} +10 -10
- package/dist/IFluidDependencySynthesizer.d.ts +3 -6
- package/dist/IFluidDependencySynthesizer.d.ts.map +1 -1
- package/dist/IFluidDependencySynthesizer.js +1 -2
- package/dist/IFluidDependencySynthesizer.js.map +1 -1
- package/dist/dependencyContainer.d.ts +1 -1
- package/dist/dependencyContainer.js +1 -1
- package/dist/dependencyContainer.js.map +1 -1
- package/dist/types.d.ts +5 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/lib/IFluidDependencySynthesizer.d.ts +3 -6
- package/lib/IFluidDependencySynthesizer.d.ts.map +1 -1
- package/lib/IFluidDependencySynthesizer.js +1 -2
- package/lib/IFluidDependencySynthesizer.js.map +1 -1
- package/lib/dependencyContainer.d.ts +1 -1
- package/lib/dependencyContainer.js +1 -1
- package/lib/dependencyContainer.js.map +1 -1
- package/lib/types.d.ts +5 -10
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/package.json +7 -7
- package/src/IFluidDependencySynthesizer.ts +3 -6
- package/src/dependencyContainer.ts +1 -1
- package/src/types.ts +5 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
##
|
|
1
|
+
## Beta API Report File for "@fluidframework/synthesize"
|
|
2
2
|
|
|
3
3
|
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
|
|
7
|
-
// @
|
|
7
|
+
// @beta @legacy
|
|
8
8
|
export type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
|
|
9
9
|
|
|
10
|
-
// @
|
|
10
|
+
// @beta @legacy
|
|
11
11
|
export type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
12
12
|
[P in keyof T]?: Promise<T[P] | undefined>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
// @
|
|
15
|
+
// @beta @legacy
|
|
16
16
|
export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
17
17
|
[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
// @
|
|
20
|
+
// @beta @legacy
|
|
21
21
|
export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
22
22
|
constructor(...parents: (IFluidDependencySynthesizer | undefined)[]);
|
|
23
23
|
has(type: string, excludeParents?: boolean): boolean;
|
|
@@ -28,24 +28,24 @@ export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
|
28
28
|
unregister(type: keyof TMap): void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// @
|
|
31
|
+
// @beta @legacy
|
|
32
32
|
export type FluidObjectProvider<T> = NonNullable<T> | Promise<NonNullable<T>> | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>) | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);
|
|
33
33
|
|
|
34
|
-
// @
|
|
34
|
+
// @beta @legacy
|
|
35
35
|
export type FluidObjectSymbolProvider<T> = {
|
|
36
36
|
[P in keyof T]?: P;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
// @
|
|
39
|
+
// @beta @legacy (undocumented)
|
|
40
40
|
export const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
|
|
41
41
|
|
|
42
|
-
// @
|
|
42
|
+
// @beta @legacy
|
|
43
43
|
export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
44
44
|
has(type: string): boolean;
|
|
45
45
|
synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// @
|
|
48
|
+
// @beta @legacy (undocumented)
|
|
49
49
|
export interface IProvideFluidDependencySynthesizer {
|
|
50
50
|
// (undocumented)
|
|
51
51
|
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from "./types.js";
|
|
6
6
|
/**
|
|
7
|
-
* @legacy
|
|
8
|
-
* @alpha
|
|
7
|
+
* @legacy @beta
|
|
9
8
|
*/
|
|
10
9
|
export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
|
|
11
10
|
/**
|
|
12
|
-
* @legacy
|
|
13
|
-
* @alpha
|
|
11
|
+
* @legacy @beta
|
|
14
12
|
*/
|
|
15
13
|
export interface IProvideFluidDependencySynthesizer {
|
|
16
14
|
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
@@ -19,8 +17,7 @@ export interface IProvideFluidDependencySynthesizer {
|
|
|
19
17
|
* IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
|
|
20
18
|
* It allow for registering providers and uses synthesize to generate a new object with the optional
|
|
21
19
|
* and required types.
|
|
22
|
-
* @legacy
|
|
23
|
-
* @alpha
|
|
20
|
+
* @legacy @beta
|
|
24
21
|
*/
|
|
25
22
|
export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
26
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF;;GAEG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,kCAClB,CAAC;AAE/B;;GAEG;AACH,MAAM,WAAW,kCAAkC;IAClD,2BAA2B,EAAE,2BAA2B,CAAC;CACzD;AAED;;;;;GAKG;AACH,MAAM,WAAW,2BAA4B,SAAQ,kCAAkC;IACtF;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAClD,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GACnD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAElC;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B"}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.IFluidDependencySynthesizer = void 0;
|
|
8
8
|
/**
|
|
9
|
-
* @legacy
|
|
10
|
-
* @alpha
|
|
9
|
+
* @legacy @beta
|
|
11
10
|
*/
|
|
12
11
|
exports.IFluidDependencySynthesizer = "IFluidDependencySynthesizer";
|
|
13
12
|
//# sourceMappingURL=IFluidDependencySynthesizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH;;GAEG;AACU,QAAA,2BAA2B,GACvC,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from \"./types.js\";\n\n/**\n * @legacy @beta\n */\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer =\n\t\"IFluidDependencySynthesizer\";\n\n/**\n * @legacy @beta\n */\nexport interface IProvideFluidDependencySynthesizer {\n\tIFluidDependencySynthesizer: IFluidDependencySynthesizer;\n}\n\n/**\n * IFluidDependencySynthesizer can generate FluidObjects 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 * @legacy @beta\n */\nexport interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {\n\t/**\n\t * synthesize takes optional and required types and returns an object that will fulfill the\n\t * defined types based off objects that has been previously registered.\n\t *\n\t * @param optionalTypes - optional types to be in the Scope object\n\t * @param requiredTypes - required types that need to be in the Scope object\n\t */\n\tsynthesize<O, R = undefined | Record<string, never>>(\n\t\toptionalTypes: FluidObjectSymbolProvider<O>,\n\t\trequiredTypes: Required<FluidObjectSymbolProvider<R>>,\n\t): AsyncFluidObjectProvider<O, R>;\n\n\t/**\n\t * Check if a given type is registered\n\t * @param type - Type to check\n\t */\n\thas(type: string): boolean;\n}\n"]}
|
|
@@ -8,7 +8,7 @@ import type { AsyncFluidObjectProvider, FluidObjectProvider, FluidObjectSymbolPr
|
|
|
8
8
|
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
9
9
|
* synthesize an object based on them when requested.
|
|
10
10
|
* @legacy
|
|
11
|
-
* @
|
|
11
|
+
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
14
14
|
private readonly providers;
|
|
@@ -11,7 +11,7 @@ const IFluidDependencySynthesizer_js_1 = require("./IFluidDependencySynthesizer.
|
|
|
11
11
|
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
12
12
|
* synthesize an object based on them when requested.
|
|
13
13
|
* @legacy
|
|
14
|
-
* @
|
|
14
|
+
* @beta
|
|
15
15
|
*/
|
|
16
16
|
class DependencyContainer {
|
|
17
17
|
get IFluidDependencySynthesizer() {
|
|
@@ -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;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,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;YAC9B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;IACF,CAAC;IAED;;OAEG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,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;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 type {\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"]}
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right (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 type {\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 * @beta\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
CHANGED
|
@@ -13,8 +13,7 @@ import type { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer.
|
|
|
13
13
|
* ```typescript
|
|
14
14
|
* { IFoo: "IFoo" }
|
|
15
15
|
* ```
|
|
16
|
-
* @legacy
|
|
17
|
-
* @alpha
|
|
16
|
+
* @legacy @beta
|
|
18
17
|
*/
|
|
19
18
|
export type FluidObjectSymbolProvider<T> = {
|
|
20
19
|
[P in keyof T]?: P;
|
|
@@ -23,8 +22,7 @@ export type FluidObjectSymbolProvider<T> = {
|
|
|
23
22
|
* This is a condensed version of Record that requires the object has all
|
|
24
23
|
* the FluidObject properties as its type mapped to an object that implements
|
|
25
24
|
* the property.
|
|
26
|
-
* @legacy
|
|
27
|
-
* @alpha
|
|
25
|
+
* @legacy @beta
|
|
28
26
|
*/
|
|
29
27
|
export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
30
28
|
[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
|
|
@@ -33,22 +31,19 @@ export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<s
|
|
|
33
31
|
* This is a condensed version of Record that requires the object has all
|
|
34
32
|
* the FluidObject properties as its type, mapped to an object that implements
|
|
35
33
|
* the property or undefined.
|
|
36
|
-
* @legacy
|
|
37
|
-
* @alpha
|
|
34
|
+
* @legacy @beta
|
|
38
35
|
*/
|
|
39
36
|
export type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
40
37
|
[P in keyof T]?: Promise<T[P] | undefined>;
|
|
41
38
|
};
|
|
42
39
|
/**
|
|
43
40
|
* Combined type for Optional and Required Async Fluid object Providers
|
|
44
|
-
* @legacy
|
|
45
|
-
* @alpha
|
|
41
|
+
* @legacy @beta
|
|
46
42
|
*/
|
|
47
43
|
export type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
|
|
48
44
|
/**
|
|
49
45
|
* Multiple ways to provide a Fluid object.
|
|
50
|
-
* @legacy
|
|
51
|
-
* @alpha
|
|
46
|
+
* @legacy @beta
|
|
52
47
|
*/
|
|
53
48
|
export type FluidObjectProvider<T> = NonNullable<T> | Promise<NonNullable<T>> | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>) | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);
|
|
54
49
|
//# sourceMappingURL=types.d.ts.map
|
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,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAEpF
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAEpF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;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;;;;;GAKG;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;;;GAGG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,IAAI,gCAAgC,CAAC,CAAC,CAAC,GAC3F,gCAAgC,CAAC,CAAC,CAAC,CAAC;AAErC;;;GAGG;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/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 type { 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
|
|
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 type { 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 @beta\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 @beta\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 @beta\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 @beta\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @legacy @beta\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"]}
|
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from "./types.js";
|
|
6
6
|
/**
|
|
7
|
-
* @legacy
|
|
8
|
-
* @alpha
|
|
7
|
+
* @legacy @beta
|
|
9
8
|
*/
|
|
10
9
|
export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
|
|
11
10
|
/**
|
|
12
|
-
* @legacy
|
|
13
|
-
* @alpha
|
|
11
|
+
* @legacy @beta
|
|
14
12
|
*/
|
|
15
13
|
export interface IProvideFluidDependencySynthesizer {
|
|
16
14
|
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
@@ -19,8 +17,7 @@ export interface IProvideFluidDependencySynthesizer {
|
|
|
19
17
|
* IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
|
|
20
18
|
* It allow for registering providers and uses synthesize to generate a new object with the optional
|
|
21
19
|
* and required types.
|
|
22
|
-
* @legacy
|
|
23
|
-
* @alpha
|
|
20
|
+
* @legacy @beta
|
|
24
21
|
*/
|
|
25
22
|
export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
26
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF;;GAEG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,kCAClB,CAAC;AAE/B;;GAEG;AACH,MAAM,WAAW,kCAAkC;IAClD,2BAA2B,EAAE,2BAA2B,CAAC;CACzD;AAED;;;;;GAKG;AACH,MAAM,WAAW,2BAA4B,SAAQ,kCAAkC;IACtF;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAClD,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAC3C,aAAa,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GACnD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAElC;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACvC,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from \"./types.js\";\n\n/**\n * @legacy @beta\n */\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer =\n\t\"IFluidDependencySynthesizer\";\n\n/**\n * @legacy @beta\n */\nexport interface IProvideFluidDependencySynthesizer {\n\tIFluidDependencySynthesizer: IFluidDependencySynthesizer;\n}\n\n/**\n * IFluidDependencySynthesizer can generate FluidObjects 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 * @legacy @beta\n */\nexport interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {\n\t/**\n\t * synthesize takes optional and required types and returns an object that will fulfill the\n\t * defined types based off objects that has been previously registered.\n\t *\n\t * @param optionalTypes - optional types to be in the Scope object\n\t * @param requiredTypes - required types that need to be in the Scope object\n\t */\n\tsynthesize<O, R = undefined | Record<string, never>>(\n\t\toptionalTypes: FluidObjectSymbolProvider<O>,\n\t\trequiredTypes: Required<FluidObjectSymbolProvider<R>>,\n\t): AsyncFluidObjectProvider<O, R>;\n\n\t/**\n\t * Check if a given type is registered\n\t * @param type - Type to check\n\t */\n\thas(type: string): boolean;\n}\n"]}
|
|
@@ -8,7 +8,7 @@ import type { AsyncFluidObjectProvider, FluidObjectProvider, FluidObjectSymbolPr
|
|
|
8
8
|
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
9
9
|
* synthesize an object based on them when requested.
|
|
10
10
|
* @legacy
|
|
11
|
-
* @
|
|
11
|
+
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
14
14
|
private readonly providers;
|
|
@@ -8,7 +8,7 @@ import { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer.js";
|
|
|
8
8
|
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
9
9
|
* synthesize an object based on them when requested.
|
|
10
10
|
* @legacy
|
|
11
|
-
* @
|
|
11
|
+
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export class DependencyContainer {
|
|
14
14
|
get IFluidDependencySynthesizer() {
|
|
@@ -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;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,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,E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,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 type {\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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AC,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 type {\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 * @beta\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
CHANGED
|
@@ -13,8 +13,7 @@ import type { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer.
|
|
|
13
13
|
* ```typescript
|
|
14
14
|
* { IFoo: "IFoo" }
|
|
15
15
|
* ```
|
|
16
|
-
* @legacy
|
|
17
|
-
* @alpha
|
|
16
|
+
* @legacy @beta
|
|
18
17
|
*/
|
|
19
18
|
export type FluidObjectSymbolProvider<T> = {
|
|
20
19
|
[P in keyof T]?: P;
|
|
@@ -23,8 +22,7 @@ export type FluidObjectSymbolProvider<T> = {
|
|
|
23
22
|
* This is a condensed version of Record that requires the object has all
|
|
24
23
|
* the FluidObject properties as its type mapped to an object that implements
|
|
25
24
|
* the property.
|
|
26
|
-
* @legacy
|
|
27
|
-
* @alpha
|
|
25
|
+
* @legacy @beta
|
|
28
26
|
*/
|
|
29
27
|
export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
30
28
|
[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
|
|
@@ -33,22 +31,19 @@ export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<s
|
|
|
33
31
|
* This is a condensed version of Record that requires the object has all
|
|
34
32
|
* the FluidObject properties as its type, mapped to an object that implements
|
|
35
33
|
* the property or undefined.
|
|
36
|
-
* @legacy
|
|
37
|
-
* @alpha
|
|
34
|
+
* @legacy @beta
|
|
38
35
|
*/
|
|
39
36
|
export type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
40
37
|
[P in keyof T]?: Promise<T[P] | undefined>;
|
|
41
38
|
};
|
|
42
39
|
/**
|
|
43
40
|
* Combined type for Optional and Required Async Fluid object Providers
|
|
44
|
-
* @legacy
|
|
45
|
-
* @alpha
|
|
41
|
+
* @legacy @beta
|
|
46
42
|
*/
|
|
47
43
|
export type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
|
|
48
44
|
/**
|
|
49
45
|
* Multiple ways to provide a Fluid object.
|
|
50
|
-
* @legacy
|
|
51
|
-
* @alpha
|
|
46
|
+
* @legacy @beta
|
|
52
47
|
*/
|
|
53
48
|
export type FluidObjectProvider<T> = NonNullable<T> | Promise<NonNullable<T>> | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>) | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);
|
|
54
49
|
//# sourceMappingURL=types.d.ts.map
|
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,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAEpF
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAEpF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;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;;;;;GAKG;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;;;GAGG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,IAAI,gCAAgC,CAAC,CAAC,CAAC,GAC3F,gCAAgC,CAAC,CAAC,CAAC,CAAC;AAErC;;;GAGG;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 type { 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
|
|
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 type { 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 @beta\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 @beta\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 @beta\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 @beta\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @legacy @beta\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.60.0",
|
|
4
4
|
"description": "A library for synthesizing scope objects.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,19 +69,19 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluidframework/core-utils": "~2.
|
|
72
|
+
"@fluidframework/core-utils": "~2.60.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.
|
|
77
|
+
"@fluid-internal/mocha-test-setup": "~2.60.0",
|
|
78
78
|
"@fluid-tools/build-cli": "^0.57.0",
|
|
79
79
|
"@fluidframework/build-common": "^2.0.3",
|
|
80
80
|
"@fluidframework/build-tools": "^0.57.0",
|
|
81
|
-
"@fluidframework/core-interfaces": "~2.
|
|
82
|
-
"@fluidframework/datastore": "~2.
|
|
83
|
-
"@fluidframework/eslint-config-fluid": "^
|
|
84
|
-
"@fluidframework/runtime-utils": "~2.
|
|
81
|
+
"@fluidframework/core-interfaces": "~2.60.0",
|
|
82
|
+
"@fluidframework/datastore": "~2.60.0",
|
|
83
|
+
"@fluidframework/eslint-config-fluid": "^6.0.0",
|
|
84
|
+
"@fluidframework/runtime-utils": "~2.60.0",
|
|
85
85
|
"@fluidframework/synthesize-previous": "npm:@fluidframework/synthesize@2.53.0",
|
|
86
86
|
"@microsoft/api-extractor": "7.52.8",
|
|
87
87
|
"@types/mocha": "^10.0.10",
|
|
@@ -6,15 +6,13 @@
|
|
|
6
6
|
import type { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from "./types.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @legacy
|
|
10
|
-
* @alpha
|
|
9
|
+
* @legacy @beta
|
|
11
10
|
*/
|
|
12
11
|
export const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer =
|
|
13
12
|
"IFluidDependencySynthesizer";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
* @legacy
|
|
17
|
-
* @alpha
|
|
15
|
+
* @legacy @beta
|
|
18
16
|
*/
|
|
19
17
|
export interface IProvideFluidDependencySynthesizer {
|
|
20
18
|
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
@@ -24,8 +22,7 @@ export interface IProvideFluidDependencySynthesizer {
|
|
|
24
22
|
* IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
|
|
25
23
|
* It allow for registering providers and uses synthesize to generate a new object with the optional
|
|
26
24
|
* and required types.
|
|
27
|
-
* @legacy
|
|
28
|
-
* @alpha
|
|
25
|
+
* @legacy @beta
|
|
29
26
|
*/
|
|
30
27
|
export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
31
28
|
/**
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
19
19
|
* synthesize an object based on them when requested.
|
|
20
20
|
* @legacy
|
|
21
|
-
* @
|
|
21
|
+
* @beta
|
|
22
22
|
*/
|
|
23
23
|
export class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type here
|
package/src/types.ts
CHANGED
|
@@ -15,8 +15,7 @@ import type { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer.
|
|
|
15
15
|
* ```typescript
|
|
16
16
|
* { IFoo: "IFoo" }
|
|
17
17
|
* ```
|
|
18
|
-
* @legacy
|
|
19
|
-
* @alpha
|
|
18
|
+
* @legacy @beta
|
|
20
19
|
*/
|
|
21
20
|
export type FluidObjectSymbolProvider<T> = {
|
|
22
21
|
[P in keyof T]?: P;
|
|
@@ -26,8 +25,7 @@ export type FluidObjectSymbolProvider<T> = {
|
|
|
26
25
|
* This is a condensed version of Record that requires the object has all
|
|
27
26
|
* the FluidObject properties as its type mapped to an object that implements
|
|
28
27
|
* the property.
|
|
29
|
-
* @legacy
|
|
30
|
-
* @alpha
|
|
28
|
+
* @legacy @beta
|
|
31
29
|
*/
|
|
32
30
|
export type AsyncRequiredFluidObjectProvider<T> = T extends undefined
|
|
33
31
|
? Record<string, never>
|
|
@@ -40,8 +38,7 @@ export type AsyncRequiredFluidObjectProvider<T> = T extends undefined
|
|
|
40
38
|
* This is a condensed version of Record that requires the object has all
|
|
41
39
|
* the FluidObject properties as its type, mapped to an object that implements
|
|
42
40
|
* the property or undefined.
|
|
43
|
-
* @legacy
|
|
44
|
-
* @alpha
|
|
41
|
+
* @legacy @beta
|
|
45
42
|
*/
|
|
46
43
|
export type AsyncOptionalFluidObjectProvider<T> = T extends undefined
|
|
47
44
|
? Record<string, never>
|
|
@@ -51,16 +48,14 @@ export type AsyncOptionalFluidObjectProvider<T> = T extends undefined
|
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* Combined type for Optional and Required Async Fluid object Providers
|
|
54
|
-
* @legacy
|
|
55
|
-
* @alpha
|
|
51
|
+
* @legacy @beta
|
|
56
52
|
*/
|
|
57
53
|
export type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &
|
|
58
54
|
AsyncRequiredFluidObjectProvider<R>;
|
|
59
55
|
|
|
60
56
|
/**
|
|
61
57
|
* Multiple ways to provide a Fluid object.
|
|
62
|
-
* @legacy
|
|
63
|
-
* @alpha
|
|
58
|
+
* @legacy @beta
|
|
64
59
|
*/
|
|
65
60
|
export type FluidObjectProvider<T> =
|
|
66
61
|
| NonNullable<T>
|