@fluidframework/synthesize 2.0.0-internal.7.3.0 → 2.0.0-internal.8.0.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/dist/IFluidDependencySynthesizer.cjs +3 -0
- package/dist/IFluidDependencySynthesizer.cjs.map +1 -1
- package/dist/IFluidDependencySynthesizer.d.ts +7 -0
- package/dist/IFluidDependencySynthesizer.d.ts.map +1 -1
- package/dist/dependencyContainer.cjs +1 -0
- package/dist/dependencyContainer.cjs.map +1 -1
- package/dist/dependencyContainer.d.ts +1 -0
- package/dist/dependencyContainer.d.ts.map +1 -1
- package/dist/synthesize-alpha.d.ts +81 -0
- package/dist/synthesize-beta.d.ts +17 -0
- package/dist/synthesize-public.d.ts +17 -0
- package/dist/synthesize-untrimmed.d.ts +123 -0
- package/dist/test/dependencyContainer.spec.cjs +43 -46
- package/dist/test/dependencyContainer.spec.cjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/lib/IFluidDependencySynthesizer.d.ts +37 -0
- package/lib/IFluidDependencySynthesizer.d.ts.map +1 -0
- package/lib/IFluidDependencySynthesizer.mjs +3 -0
- package/lib/IFluidDependencySynthesizer.mjs.map +1 -1
- package/lib/dependencyContainer.d.ts +46 -0
- package/lib/dependencyContainer.d.ts.map +1 -0
- package/lib/dependencyContainer.mjs +1 -0
- package/lib/dependencyContainer.mjs.map +1 -1
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/synthesize-alpha.d.ts +81 -0
- package/lib/synthesize-beta.d.ts +17 -0
- package/lib/synthesize-public.d.ts +17 -0
- package/lib/synthesize-untrimmed.d.ts +123 -0
- package/lib/types.d.ts +45 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.mjs.map +1 -1
- package/package.json +29 -22
|
@@ -5,5 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.IFluidDependencySynthesizer = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
8
11
|
exports.IFluidDependencySynthesizer = "IFluidDependencySynthesizer";
|
|
9
12
|
//# sourceMappingURL=IFluidDependencySynthesizer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFluidDependencySynthesizer.cjs","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.cjs","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 { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from \"./types\";\n\n/**\n * @alpha\n */\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer =\n\t\"IFluidDependencySynthesizer\";\n\n/**\n * @alpha\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 * @alpha\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"]}
|
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
6
9
|
export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
|
|
10
|
+
/**
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
7
13
|
export interface IProvideFluidDependencySynthesizer {
|
|
8
14
|
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
9
15
|
}
|
|
@@ -11,6 +17,7 @@ export interface IProvideFluidDependencySynthesizer {
|
|
|
11
17
|
* IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
|
|
12
18
|
* It allow for registering providers and uses synthesize to generate a new object with the optional
|
|
13
19
|
* and required types.
|
|
20
|
+
* @alpha
|
|
14
21
|
*/
|
|
15
22
|
export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
16
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAE9E,eAAO,MAAM,2BAA2B,EAAE,MAAM,kCAClB,CAAC;AAE/B,MAAM,WAAW,kCAAkC;IAClD,2BAA2B,EAAE,2BAA2B,CAAC;CACzD;AAED
|
|
1
|
+
{"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAE9E;;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"}
|
|
@@ -10,6 +10,7 @@ const IFluidDependencySynthesizer_1 = require("./IFluidDependencySynthesizer.cjs
|
|
|
10
10
|
/**
|
|
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
|
+
* @internal
|
|
13
14
|
*/
|
|
14
15
|
class DependencyContainer {
|
|
15
16
|
get IFluidDependencySynthesizer() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.cjs","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAyD;AAQzD,mFAA4E;AAE5E;;;GAGG;AACH,MAAa,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,EAA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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;qBACtB;gBACF,CAAC;aACD,CAAC;SACF;QACD,OAAO;YACN,GAAG;gBACF,IAAI,QAAQ,EAAE;oBACb,OAAO,IAAI,wBAAW,CAAC,KAAK,IAAI,EAAE;wBACjC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;4BAC3C,IAAI,CAAC,EAAE;gCACN,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;6BACZ;wBACF,CAAC,CAAC,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACH;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD;AA5KD,kDA4KC","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\";\nimport {\n\tAsyncFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n\tFluidObjectProvider,\n\tAsyncOptionalFluidObjectProvider,\n\tAsyncRequiredFluidObjectProvider,\n} from \"./types\";\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer\";\n\n/**\n * DependencyContainer is similar to a IoC Container. It takes providers and will\n * synthesize an object based on them when requested.\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n\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(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t)}`,\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.cjs","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAyD;AAQzD,mFAA4E;AAE5E;;;;GAIG;AACH,MAAa,mBAAmB;IAG/B,IAAW,2BAA2B;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAmB,GAAG,OAAoD;QANzD,cAAS,GAAG,IAAI,GAAG,EAAw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EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;6BAChD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;qBACtB;gBACF,CAAC;aACD,CAAC;SACF;QACD,OAAO;YACN,GAAG;gBACF,IAAI,QAAQ,EAAE;oBACb,OAAO,IAAI,wBAAW,CAAC,KAAK,IAAI,EAAE;wBACjC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;4BAC3C,IAAI,CAAC,EAAE;gCACN,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;6BACZ;wBACF,CAAC,CAAC,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACH;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD;AA5KD,kDA4KC","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\";\nimport {\n\tAsyncFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n\tFluidObjectProvider,\n\tAsyncOptionalFluidObjectProvider,\n\tAsyncRequiredFluidObjectProvider,\n} from \"./types\";\nimport { IFluidDependencySynthesizer } from \"./IFluidDependencySynthesizer\";\n\n/**\n * DependencyContainer is similar to a IoC Container. It takes providers and will\n * synthesize an object based on them when requested.\n * @internal\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(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t)}`,\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"]}
|
|
@@ -7,6 +7,7 @@ import { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer";
|
|
|
7
7
|
/**
|
|
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
|
+
* @internal
|
|
10
11
|
*/
|
|
11
12
|
export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
12
13
|
private readonly providers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EAGnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E
|
|
1
|
+
{"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EAGnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;;;GAIG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,YAAW,2BAA2B;IAC5E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmD;IAC7E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,IAAW,2BAA2B,SAErC;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;IAQjC;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO;IAS3D;;OAEG;IACH,OAAO,CAAC,WAAW;IAuBnB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,eAAe;CA2CvB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combined type for Optional and Required Async Fluid object Providers
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
export declare type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This is a condensed version of Record that requires the object has all
|
|
9
|
+
* the FluidObject properties as its type, mapped to an object that implements
|
|
10
|
+
* the property or undefined.
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export declare type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
14
|
+
[P in keyof T]?: Promise<T[P] | undefined>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is a condensed version of Record that requires the object has all
|
|
19
|
+
* the FluidObject properties as its type mapped to an object that implements
|
|
20
|
+
* the property.
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export declare type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
24
|
+
[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/* Excluded from this release type: DependencyContainer */
|
|
28
|
+
|
|
29
|
+
/* Excluded from this release type: FluidObjectProvider */
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* This is a condensed version of Record that requires the object has all
|
|
33
|
+
* the FluidObject properties as its type mapped to a string representation
|
|
34
|
+
* of that property.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
*
|
|
38
|
+
* ```typescript
|
|
39
|
+
* { IFoo: "IFoo" }
|
|
40
|
+
* ```
|
|
41
|
+
* @alpha
|
|
42
|
+
*/
|
|
43
|
+
export declare type FluidObjectSymbolProvider<T> = {
|
|
44
|
+
[P in keyof T]?: P;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @alpha
|
|
49
|
+
*/
|
|
50
|
+
export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
|
|
54
|
+
* It allow for registering providers and uses synthesize to generate a new object with the optional
|
|
55
|
+
* and required types.
|
|
56
|
+
* @alpha
|
|
57
|
+
*/
|
|
58
|
+
export declare interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
59
|
+
/**
|
|
60
|
+
* synthesize takes optional and required types and returns an object that will fulfill the
|
|
61
|
+
* defined types based off objects that has been previously registered.
|
|
62
|
+
*
|
|
63
|
+
* @param optionalTypes - optional types to be in the Scope object
|
|
64
|
+
* @param requiredTypes - required types that need to be in the Scope object
|
|
65
|
+
*/
|
|
66
|
+
synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
|
|
67
|
+
/**
|
|
68
|
+
* Check if a given type is registered
|
|
69
|
+
* @param type - Type to check
|
|
70
|
+
*/
|
|
71
|
+
has(type: string): boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @alpha
|
|
76
|
+
*/
|
|
77
|
+
export declare interface IProvideFluidDependencySynthesizer {
|
|
78
|
+
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* Excluded from this release type: AsyncFluidObjectProvider */
|
|
2
|
+
|
|
3
|
+
/* Excluded from this release type: AsyncOptionalFluidObjectProvider */
|
|
4
|
+
|
|
5
|
+
/* Excluded from this release type: AsyncRequiredFluidObjectProvider */
|
|
6
|
+
|
|
7
|
+
/* Excluded from this release type: DependencyContainer */
|
|
8
|
+
|
|
9
|
+
/* Excluded from this release type: FluidObjectProvider */
|
|
10
|
+
|
|
11
|
+
/* Excluded from this release type: FluidObjectSymbolProvider */
|
|
12
|
+
|
|
13
|
+
/* Excluded from this release type: IFluidDependencySynthesizer */
|
|
14
|
+
|
|
15
|
+
/* Excluded from this release type: IProvideFluidDependencySynthesizer */
|
|
16
|
+
|
|
17
|
+
export { }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* Excluded from this release type: AsyncFluidObjectProvider */
|
|
2
|
+
|
|
3
|
+
/* Excluded from this release type: AsyncOptionalFluidObjectProvider */
|
|
4
|
+
|
|
5
|
+
/* Excluded from this release type: AsyncRequiredFluidObjectProvider */
|
|
6
|
+
|
|
7
|
+
/* Excluded from this release type: DependencyContainer */
|
|
8
|
+
|
|
9
|
+
/* Excluded from this release type: FluidObjectProvider */
|
|
10
|
+
|
|
11
|
+
/* Excluded from this release type: FluidObjectSymbolProvider */
|
|
12
|
+
|
|
13
|
+
/* Excluded from this release type: IFluidDependencySynthesizer */
|
|
14
|
+
|
|
15
|
+
/* Excluded from this release type: IProvideFluidDependencySynthesizer */
|
|
16
|
+
|
|
17
|
+
export { }
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combined type for Optional and Required Async Fluid object Providers
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
export declare type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This is a condensed version of Record that requires the object has all
|
|
9
|
+
* the FluidObject properties as its type, mapped to an object that implements
|
|
10
|
+
* the property or undefined.
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export declare type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
14
|
+
[P in keyof T]?: Promise<T[P] | undefined>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is a condensed version of Record that requires the object has all
|
|
19
|
+
* the FluidObject properties as its type mapped to an object that implements
|
|
20
|
+
* the property.
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export declare type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
|
|
24
|
+
[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* DependencyContainer is similar to a IoC Container. It takes providers and will
|
|
29
|
+
* synthesize an object based on them when requested.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
|
|
33
|
+
private readonly providers;
|
|
34
|
+
private readonly parents;
|
|
35
|
+
get IFluidDependencySynthesizer(): this;
|
|
36
|
+
constructor(...parents: (IFluidDependencySynthesizer | undefined)[]);
|
|
37
|
+
/**
|
|
38
|
+
* Add a new provider
|
|
39
|
+
* @param type - Name of the Type T being provided
|
|
40
|
+
* @param provider - A provider that will resolve the T correctly when asked
|
|
41
|
+
* @throws - If passing a type that's already registered
|
|
42
|
+
*/
|
|
43
|
+
register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Remove a provider
|
|
46
|
+
* @param type - Name of the provider to remove
|
|
47
|
+
*/
|
|
48
|
+
unregister(type: keyof TMap): void;
|
|
49
|
+
/**
|
|
50
|
+
* {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
|
|
51
|
+
*/
|
|
52
|
+
synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
|
|
53
|
+
/**
|
|
54
|
+
* {@inheritDoc (IFluidDependencySynthesizer:interface).has}
|
|
55
|
+
* @param excludeParents - If true, exclude checking parent registries
|
|
56
|
+
*/
|
|
57
|
+
has(type: string, excludeParents?: boolean): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Needed for backwards compatability.
|
|
60
|
+
*/
|
|
61
|
+
private getProvider;
|
|
62
|
+
private generateRequired;
|
|
63
|
+
private generateOptional;
|
|
64
|
+
private resolveProvider;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Multiple ways to provide a Fluid object.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export declare type FluidObjectProvider<T> = NonNullable<T> | Promise<NonNullable<T>> | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>) | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* This is a condensed version of Record that requires the object has all
|
|
75
|
+
* the FluidObject properties as its type mapped to a string representation
|
|
76
|
+
* of that property.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* { IFoo: "IFoo" }
|
|
82
|
+
* ```
|
|
83
|
+
* @alpha
|
|
84
|
+
*/
|
|
85
|
+
export declare type FluidObjectSymbolProvider<T> = {
|
|
86
|
+
[P in keyof T]?: P;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @alpha
|
|
91
|
+
*/
|
|
92
|
+
export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
|
|
96
|
+
* It allow for registering providers and uses synthesize to generate a new object with the optional
|
|
97
|
+
* and required types.
|
|
98
|
+
* @alpha
|
|
99
|
+
*/
|
|
100
|
+
export declare interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
|
|
101
|
+
/**
|
|
102
|
+
* synthesize takes optional and required types and returns an object that will fulfill the
|
|
103
|
+
* defined types based off objects that has been previously registered.
|
|
104
|
+
*
|
|
105
|
+
* @param optionalTypes - optional types to be in the Scope object
|
|
106
|
+
* @param requiredTypes - required types that need to be in the Scope object
|
|
107
|
+
*/
|
|
108
|
+
synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
|
|
109
|
+
/**
|
|
110
|
+
* Check if a given type is registered
|
|
111
|
+
* @param type - Type to check
|
|
112
|
+
*/
|
|
113
|
+
has(type: string): boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @alpha
|
|
118
|
+
*/
|
|
119
|
+
export declare interface IProvideFluidDependencySynthesizer {
|
|
120
|
+
IFluidDependencySynthesizer: IFluidDependencySynthesizer;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { }
|
|
@@ -28,19 +28,16 @@ class MockLoadable {
|
|
|
28
28
|
return new datastore_1.FluidObjectHandle(this, "", mockHandleContext);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const ISomeObject = "ISomeObject";
|
|
32
|
+
class MockSomeObject {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.value = 0;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
mimeType: "",
|
|
38
|
-
status: 200,
|
|
39
|
-
value: "",
|
|
40
|
-
};
|
|
36
|
+
get ISomeObject() {
|
|
37
|
+
return this;
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
describe("
|
|
40
|
+
describe("someObjectlicious", () => {
|
|
44
41
|
describe("Aqueduct", () => {
|
|
45
42
|
describe("DependencyContainer", () => {
|
|
46
43
|
it(`One Optional Provider registered via value`, async () => {
|
|
@@ -181,48 +178,48 @@ describe("Routerlicious", () => {
|
|
|
181
178
|
const dc = new index_1.DependencyContainer();
|
|
182
179
|
const loadableMock = new MockLoadable();
|
|
183
180
|
dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
|
|
184
|
-
const
|
|
185
|
-
dc.register(
|
|
186
|
-
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable,
|
|
181
|
+
const someObjectMock = new MockSomeObject();
|
|
182
|
+
dc.register(ISomeObject, someObjectMock);
|
|
183
|
+
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, ISomeObject }, undefined);
|
|
187
184
|
const loadable = await s.IFluidLoadable;
|
|
188
185
|
(0, assert_1.strict)(loadable, "Optional IFluidLoadable was registered");
|
|
189
186
|
(0, assert_1.strict)(loadable === loadableMock, "IFluidLoadable is expected");
|
|
190
|
-
const
|
|
191
|
-
(0, assert_1.strict)(
|
|
192
|
-
(0, assert_1.strict)(
|
|
187
|
+
const someObject = await s.ISomeObject;
|
|
188
|
+
(0, assert_1.strict)(someObject, "Optional ISomeObject was registered");
|
|
189
|
+
(0, assert_1.strict)(someObject === someObjectMock, "ISomeObject is expected");
|
|
193
190
|
});
|
|
194
191
|
it(`Two Optional Modules one registered`, async () => {
|
|
195
192
|
const dc = new index_1.DependencyContainer();
|
|
196
193
|
const loadableMock = new MockLoadable();
|
|
197
194
|
dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
|
|
198
|
-
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable,
|
|
195
|
+
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, ISomeObject }, undefined);
|
|
199
196
|
const loadable = await s.IFluidLoadable;
|
|
200
197
|
(0, assert_1.strict)(loadable, "Optional IFluidLoadable was registered");
|
|
201
198
|
(0, assert_1.strict)(loadable === loadableMock, "IFluidLoadable is expected");
|
|
202
|
-
const
|
|
203
|
-
(0, assert_1.strict)(!
|
|
199
|
+
const someObject = await s.ISomeObject;
|
|
200
|
+
(0, assert_1.strict)(!someObject, "Optional ISomeObject was not registered");
|
|
204
201
|
});
|
|
205
202
|
it(`Two Optional Modules none registered`, async () => {
|
|
206
203
|
const dc = new index_1.DependencyContainer();
|
|
207
|
-
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable,
|
|
204
|
+
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, ISomeObject }, undefined);
|
|
208
205
|
const loadable = await s.IFluidLoadable;
|
|
209
206
|
(0, assert_1.strict)(!loadable, "Optional IFluidLoadable was not registered");
|
|
210
|
-
const
|
|
211
|
-
(0, assert_1.strict)(!
|
|
207
|
+
const someObject = await s.ISomeObject;
|
|
208
|
+
(0, assert_1.strict)(!someObject, "Optional ISomeObject was not registered");
|
|
212
209
|
});
|
|
213
210
|
it(`Two Required Modules all registered`, async () => {
|
|
214
211
|
const dc = new index_1.DependencyContainer();
|
|
215
212
|
const loadableMock = new MockLoadable();
|
|
216
213
|
dc.register(core_interfaces_1.IFluidLoadable, loadableMock);
|
|
217
|
-
const
|
|
218
|
-
dc.register(
|
|
219
|
-
const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable,
|
|
214
|
+
const someObjectMock = new MockSomeObject();
|
|
215
|
+
dc.register(ISomeObject, someObjectMock);
|
|
216
|
+
const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable, ISomeObject });
|
|
220
217
|
const loadable = await s.IFluidLoadable;
|
|
221
218
|
(0, assert_1.strict)(loadable, "Required IFluidLoadable was registered");
|
|
222
219
|
(0, assert_1.strict)(loadable === loadableMock, "IFluidLoadable is expected");
|
|
223
|
-
const
|
|
224
|
-
(0, assert_1.strict)(
|
|
225
|
-
(0, assert_1.strict)(
|
|
220
|
+
const someObject = await s.ISomeObject;
|
|
221
|
+
(0, assert_1.strict)(someObject, "Required ISomeObject was registered");
|
|
222
|
+
(0, assert_1.strict)(someObject === someObjectMock, "ISomeObject is expected");
|
|
226
223
|
});
|
|
227
224
|
it(`Required Provider not registered should throw`, async () => {
|
|
228
225
|
const dc = new index_1.DependencyContainer();
|
|
@@ -246,15 +243,15 @@ describe("Routerlicious", () => {
|
|
|
246
243
|
const loadableMock = new MockLoadable();
|
|
247
244
|
parentDc.register(core_interfaces_1.IFluidLoadable, loadableMock);
|
|
248
245
|
const dc = new index_1.DependencyContainer(parentDc);
|
|
249
|
-
const
|
|
250
|
-
dc.register(
|
|
251
|
-
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable,
|
|
246
|
+
const someObjectMock = new MockSomeObject();
|
|
247
|
+
dc.register(ISomeObject, someObjectMock);
|
|
248
|
+
const s = dc.synthesize({ IFluidLoadable: core_interfaces_1.IFluidLoadable, ISomeObject }, undefined);
|
|
252
249
|
const loadable = await s.IFluidLoadable;
|
|
253
250
|
(0, assert_1.strict)(loadable, "Optional IFluidLoadable was registered");
|
|
254
251
|
(0, assert_1.strict)(loadable === loadableMock, "IFluidLoadable is expected");
|
|
255
|
-
const
|
|
256
|
-
(0, assert_1.strict)(
|
|
257
|
-
(0, assert_1.strict)(
|
|
252
|
+
const someObject = await s.ISomeObject;
|
|
253
|
+
(0, assert_1.strict)(someObject, "Optional ISomeObject was registered");
|
|
254
|
+
(0, assert_1.strict)(someObject === someObjectMock, "ISomeObject is expected");
|
|
258
255
|
});
|
|
259
256
|
it(`Optional Provider found in Parent and Child resolves Child`, async () => {
|
|
260
257
|
const parentDc = new index_1.DependencyContainer();
|
|
@@ -285,15 +282,15 @@ describe("Routerlicious", () => {
|
|
|
285
282
|
const loadableMock = new MockLoadable();
|
|
286
283
|
parentDc.register(core_interfaces_1.IFluidLoadable, loadableMock);
|
|
287
284
|
const dc = new index_1.DependencyContainer(parentDc);
|
|
288
|
-
const
|
|
289
|
-
dc.register(
|
|
290
|
-
const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable,
|
|
285
|
+
const someObjectMock = new MockSomeObject();
|
|
286
|
+
dc.register(ISomeObject, someObjectMock);
|
|
287
|
+
const s = dc.synthesize(undefined, { IFluidLoadable: core_interfaces_1.IFluidLoadable, ISomeObject });
|
|
291
288
|
const loadable = await s.IFluidLoadable;
|
|
292
289
|
(0, assert_1.strict)(loadable, "Required IFluidLoadable was registered");
|
|
293
290
|
(0, assert_1.strict)(loadable === loadableMock, "IFluidLoadable is expected");
|
|
294
|
-
const
|
|
295
|
-
(0, assert_1.strict)(
|
|
296
|
-
(0, assert_1.strict)(
|
|
291
|
+
const someObject = await s.ISomeObject;
|
|
292
|
+
(0, assert_1.strict)(someObject, "Required ISomeObject was registered");
|
|
293
|
+
(0, assert_1.strict)(someObject === someObjectMock, "ISomeObject is expected");
|
|
297
294
|
});
|
|
298
295
|
it(`Required Provider found in Parent and Child resolves Child`, async () => {
|
|
299
296
|
const parentDc = new index_1.DependencyContainer();
|
|
@@ -334,21 +331,21 @@ describe("Routerlicious", () => {
|
|
|
334
331
|
it(`has() resolves correctly in all variations`, async () => {
|
|
335
332
|
const dc = new index_1.DependencyContainer();
|
|
336
333
|
dc.register(core_interfaces_1.IFluidLoadable, new MockLoadable());
|
|
337
|
-
dc.register(
|
|
334
|
+
dc.register(ISomeObject, new MockSomeObject());
|
|
338
335
|
(0, assert_1.strict)(dc.has(core_interfaces_1.IFluidLoadable), "Manager has IFluidLoadable");
|
|
339
|
-
(0, assert_1.strict)(dc.has(
|
|
340
|
-
(0, assert_1.strict)(dc.has(core_interfaces_1.IFluidLoadable) && dc.has(
|
|
336
|
+
(0, assert_1.strict)(dc.has(ISomeObject), "Manager has ISomeObject");
|
|
337
|
+
(0, assert_1.strict)(dc.has(core_interfaces_1.IFluidLoadable) && dc.has(ISomeObject), "Manager has IFluidLoadable & ISomeObject");
|
|
341
338
|
});
|
|
342
339
|
it(`Child has Parent modules`, async () => {
|
|
343
340
|
const parentDc = new index_1.DependencyContainer();
|
|
344
341
|
const loadableMock = new MockLoadable();
|
|
345
342
|
parentDc.register(core_interfaces_1.IFluidLoadable, loadableMock);
|
|
346
343
|
const dc = new index_1.DependencyContainer(parentDc);
|
|
347
|
-
const
|
|
348
|
-
dc.register(
|
|
344
|
+
const someObjectMock = new MockSomeObject();
|
|
345
|
+
dc.register(ISomeObject, someObjectMock);
|
|
349
346
|
(0, assert_1.strict)(dc.has(core_interfaces_1.IFluidLoadable), "has includes parent registered");
|
|
350
347
|
(0, assert_1.strict)(!dc.has(core_interfaces_1.IFluidLoadable, true), "has does not include excluded parent registered");
|
|
351
|
-
(0, assert_1.strict)(dc.has(
|
|
348
|
+
(0, assert_1.strict)(dc.has(ISomeObject), "has includes registered");
|
|
352
349
|
(0, assert_1.strict)(!dc.has(core_interfaces_1.IFluidHandle), "does not include not registered");
|
|
353
350
|
});
|
|
354
351
|
it(`Parent Resolved from Child`, async () => {
|