@fluidframework/synthesize 2.0.0-internal.7.3.0 → 2.0.0-internal.7.4.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.
@@ -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;;;AAIU,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\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer =\n\t\"IFluidDependencySynthesizer\";\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 */\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"]}
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;;;;GAIG;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
+ {"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,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,I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AW,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,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,Q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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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,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 { }
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IFluidDependencySynthesizer } from \".\";\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 */\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 */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t };\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 */\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 };\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n */\nexport type FluidObjectProvider<T> =\n\t| NonNullable<T>\n\t| Promise<NonNullable<T>>\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IFluidDependencySynthesizer } from \".\";\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 * @alpha\n */\nexport type FluidObjectSymbolProvider<T> = {\n\t[P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to an object that implements\n * the property.\n * @alpha\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t };\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 * @alpha\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]?: Promise<T[P] | undefined>;\n\t };\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n * @alpha\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @internal\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/dist/types.d.ts CHANGED
@@ -13,6 +13,7 @@ import { IFluidDependencySynthesizer } from ".";
13
13
  * ```typescript
14
14
  * { IFoo: "IFoo" }
15
15
  * ```
16
+ * @alpha
16
17
  */
17
18
  export type FluidObjectSymbolProvider<T> = {
18
19
  [P in keyof T]?: P;
@@ -21,6 +22,7 @@ export type FluidObjectSymbolProvider<T> = {
21
22
  * This is a condensed version of Record that requires the object has all
22
23
  * the FluidObject properties as its type mapped to an object that implements
23
24
  * the property.
25
+ * @alpha
24
26
  */
25
27
  export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
26
28
  [P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
@@ -29,16 +31,19 @@ export type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<s
29
31
  * This is a condensed version of Record that requires the object has all
30
32
  * the FluidObject properties as its type, mapped to an object that implements
31
33
  * the property or undefined.
34
+ * @alpha
32
35
  */
33
36
  export type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
34
37
  [P in keyof T]?: Promise<T[P] | undefined>;
35
38
  };
36
39
  /**
37
40
  * Combined type for Optional and Required Async Fluid object Providers
41
+ * @alpha
38
42
  */
39
43
  export type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
40
44
  /**
41
45
  * Multiple ways to provide a Fluid object.
46
+ * @internal
42
47
  */
43
48
  export type FluidObjectProvider<T> = NonNullable<T> | Promise<NonNullable<T>> | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>) | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);
44
49
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,GAAG,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gCAAgC,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAClE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACrB;KACC,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;CACpE,CAAC;AAEL;;;;GAIG;AACH,MAAM,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M,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;CACzC,CAAC;AAEL;;;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"}
@@ -0,0 +1,37 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from "./types.mjs";
6
+ /**
7
+ * @alpha
8
+ */
9
+ export declare const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer;
10
+ /**
11
+ * @alpha
12
+ */
13
+ export interface IProvideFluidDependencySynthesizer {
14
+ IFluidDependencySynthesizer: IFluidDependencySynthesizer;
15
+ }
16
+ /**
17
+ * IFluidDependencySynthesizer can generate FluidObjects based on the IProvideFluidObject pattern.
18
+ * It allow for registering providers and uses synthesize to generate a new object with the optional
19
+ * and required types.
20
+ * @alpha
21
+ */
22
+ export interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {
23
+ /**
24
+ * synthesize takes optional and required types and returns an object that will fulfill the
25
+ * defined types based off objects that has been previously registered.
26
+ *
27
+ * @param optionalTypes - optional types to be in the Scope object
28
+ * @param requiredTypes - required types that need to be in the Scope object
29
+ */
30
+ synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
31
+ /**
32
+ * Check if a given type is registered
33
+ * @param type - Type to check
34
+ */
35
+ has(type: string): boolean;
36
+ }
37
+ //# sourceMappingURL=IFluidDependencySynthesizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IFluidDependencySynthesizer.d.ts","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,wBAAwB,EAAE,yBAAyB,EAAE;AAE9D;;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"}
@@ -2,5 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ /**
6
+ * @alpha
7
+ */
5
8
  export const IFluidDependencySynthesizer = "IFluidDependencySynthesizer";
6
9
  //# sourceMappingURL=IFluidDependencySynthesizer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"IFluidDependencySynthesizer.mjs","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,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 { AsyncFluidObjectProvider, FluidObjectSymbolProvider } from \"./types\";\n\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer =\n\t\"IFluidDependencySynthesizer\";\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 */\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"]}
1
+ {"version":3,"file":"IFluidDependencySynthesizer.mjs","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 { 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"]}
@@ -0,0 +1,46 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AsyncFluidObjectProvider, FluidObjectSymbolProvider, FluidObjectProvider } from "./types.mjs";
6
+ import { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer.mjs";
7
+ /**
8
+ * DependencyContainer is similar to a IoC Container. It takes providers and will
9
+ * synthesize an object based on them when requested.
10
+ * @internal
11
+ */
12
+ export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer {
13
+ private readonly providers;
14
+ private readonly parents;
15
+ get IFluidDependencySynthesizer(): this;
16
+ constructor(...parents: (IFluidDependencySynthesizer | undefined)[]);
17
+ /**
18
+ * Add a new provider
19
+ * @param type - Name of the Type T being provided
20
+ * @param provider - A provider that will resolve the T correctly when asked
21
+ * @throws - If passing a type that's already registered
22
+ */
23
+ register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void;
24
+ /**
25
+ * Remove a provider
26
+ * @param type - Name of the provider to remove
27
+ */
28
+ unregister(type: keyof TMap): void;
29
+ /**
30
+ * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}
31
+ */
32
+ synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
33
+ /**
34
+ * {@inheritDoc (IFluidDependencySynthesizer:interface).has}
35
+ * @param excludeParents - If true, exclude checking parent registries
36
+ */
37
+ has(type: string, excludeParents?: boolean): boolean;
38
+ /**
39
+ * @deprecated Needed for backwards compatability.
40
+ */
41
+ private getProvider;
42
+ private generateRequired;
43
+ private generateOptional;
44
+ private resolveProvider;
45
+ }
46
+ //# sourceMappingURL=dependencyContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencyContainer.d.ts","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAGI,EACN,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EAGnB;OACM,EAAE,2BAA2B,EAAE;AAEtC;;;;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"}
@@ -7,6 +7,7 @@ import { IFluidDependencySynthesizer } from "./IFluidDependencySynthesizer.mjs";
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 class DependencyContainer {
12
13
  get IFluidDependencySynthesizer() {
@@ -1 +1 @@
1
- {"version":3,"file":"dependencyContainer.mjs","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,WAAW,EAAE,MAAM,4BAA4B;OAQjD,EAAE,2BAA2B,EAAE;AAEtC;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAG/B,IAAW,2BAA2B;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAmB,GAAG,OAAoD;QANzD,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAO5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;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AC,CAAC;qBACtB;gBACF,CAAC;aACD,CAAC;SACF;QACD,OAAO;YACN,GAAG;gBACF,IAAI,QAAQ,EAAE;oBACb,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;gCACN,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;6BACZ;wBACF,CAAC,CAAC,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACH;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\";\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.mjs","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,WAAW,EAAE,MAAM,4BAA4B;OAQjD,EAAE,2BAA2B,EAAE;AAEtC;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAG/B,IAAW,2BAA2B;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAmB,GAAG,OAAoD;QANzD,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAO5E,IAAI,C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C,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,WAAW,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","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"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { DependencyContainer } from "./dependencyContainer.mjs";
6
+ export { IFluidDependencySynthesizer, IProvideFluidDependencySynthesizer, } from "./IFluidDependencySynthesizer.mjs";
7
+ export { AsyncFluidObjectProvider, AsyncOptionalFluidObjectProvider, AsyncRequiredFluidObjectProvider, FluidObjectProvider, FluidObjectSymbolProvider, } from "./types.mjs";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,mBAAmB,EAAE;OACvB,EACN,2BAA2B,EAC3B,kCAAkC,GAClC;OACM,EACN,wBAAwB,EACxB,gCAAgC,EAChC,gCAAgC,EAChC,mBAAmB,EACnB,yBAAyB,GACzB"}
@@ -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 { }
package/lib/types.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { IFluidDependencySynthesizer } from ".";
2
+ /**
3
+ * This is a condensed version of Record that requires the object has all
4
+ * the FluidObject properties as its type mapped to a string representation
5
+ * of that property.
6
+ *
7
+ * @example
8
+ *
9
+ * ```typescript
10
+ * { IFoo: "IFoo" }
11
+ * ```
12
+ * @alpha
13
+ */
14
+ export type FluidObjectSymbolProvider<T> = {
15
+ [P in keyof T]?: P;
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 type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
24
+ [P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;
25
+ };
26
+ /**
27
+ * This is a condensed version of Record that requires the object has all
28
+ * the FluidObject properties as its type, mapped to an object that implements
29
+ * the property or undefined.
30
+ * @alpha
31
+ */
32
+ export type AsyncOptionalFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {
33
+ [P in keyof T]?: Promise<T[P] | undefined>;
34
+ };
35
+ /**
36
+ * Combined type for Optional and Required Async Fluid object Providers
37
+ * @alpha
38
+ */
39
+ export type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;
40
+ /**
41
+ * Multiple ways to provide a Fluid object.
42
+ * @internal
43
+ */
44
+ export type FluidObjectProvider<T> = NonNullable<T> | Promise<NonNullable<T>> | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>) | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);
45
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"OAIO,EAAE,2BAA2B,EAAE,MAAM,GAAG;AAE/C;;;;;;;;;;;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;KACC,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;CACpE,CAAC;AAEL;;;;;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;CACzC,CAAC;AAEL;;;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.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IFluidDependencySynthesizer } from \".\";\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 */\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 */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t };\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 */\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 };\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n */\nexport type FluidObjectProvider<T> =\n\t| NonNullable<T>\n\t| Promise<NonNullable<T>>\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n\t| ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IFluidDependencySynthesizer } from \".\";\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 * @alpha\n */\nexport type FluidObjectSymbolProvider<T> = {\n\t[P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the FluidObject properties as its type mapped to an object that implements\n * the property.\n * @alpha\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>;\n\t };\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 * @alpha\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n\t? Record<string, never>\n\t: {\n\t\t\t[P in keyof T]?: Promise<T[P] | undefined>;\n\t };\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n * @alpha\n */\nexport type AsyncFluidObjectProvider<O, R = undefined> = AsyncOptionalFluidObjectProvider<O> &\n\tAsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n * @internal\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.0.0-internal.7.3.0",
3
+ "version": "2.0.0-internal.7.4.0",
4
4
  "description": "A library for synthesizing scope objects.",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -11,18 +11,6 @@
11
11
  "license": "MIT",
12
12
  "author": "Microsoft and contributors",
13
13
  "sideEffects": false,
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./lib/index.d.ts",
18
- "default": "./lib/index.mjs"
19
- },
20
- "require": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.cjs"
23
- }
24
- }
25
- },
26
14
  "main": "dist/index.cjs",
27
15
  "module": "lib/index.mjs",
28
16
  "types": "dist/index.d.ts",
@@ -51,21 +39,23 @@
51
39
  "temp-directory": "nyc/.nyc_output"
52
40
  },
53
41
  "dependencies": {
54
- "@fluidframework/core-utils": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0"
42
+ "@fluidframework/core-utils": ">=2.0.0-internal.7.4.0 <2.0.0-internal.7.5.0"
55
43
  },
56
44
  "devDependencies": {
45
+ "@arethetypeswrong/cli": "^0.13.3",
57
46
  "@fluid-tools/build-cli": "^0.28.0",
58
47
  "@fluidframework/build-common": "^2.0.3",
59
48
  "@fluidframework/build-tools": "^0.28.0",
60
- "@fluidframework/core-interfaces": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
61
- "@fluidframework/datastore": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
49
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.7.4.0 <2.0.0-internal.7.5.0",
50
+ "@fluidframework/datastore": ">=2.0.0-internal.7.4.0 <2.0.0-internal.7.5.0",
62
51
  "@fluidframework/eslint-config-fluid": "^3.1.0",
63
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.7.3.0 <2.0.0-internal.7.4.0",
52
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.7.4.0 <2.0.0-internal.7.5.0",
64
53
  "@fluidframework/synthesize-previous": "npm:@fluidframework/synthesize@2.0.0-internal.7.2.0",
65
54
  "@microsoft/api-extractor": "^7.38.3",
66
55
  "@types/mocha": "^9.1.1",
67
- "@types/node": "^16.18.38",
56
+ "@types/node": "^18.19.0",
68
57
  "c8": "^7.7.1",
58
+ "copyfiles": "^2.4.1",
69
59
  "cross-env": "^7.0.3",
70
60
  "eslint": "~8.50.0",
71
61
  "mocha": "^10.2.0",
@@ -77,25 +67,42 @@
77
67
  "tsc-multi": "^1.1.0",
78
68
  "typescript": "~5.1.6"
79
69
  },
70
+ "fluidBuild": {
71
+ "tasks": {
72
+ "build:docs": {
73
+ "dependsOn": [
74
+ "...",
75
+ "api-extractor:commonjs",
76
+ "api-extractor:esnext"
77
+ ],
78
+ "script": false
79
+ }
80
+ }
81
+ },
80
82
  "typeValidation": {
81
83
  "broken": {}
82
84
  },
83
85
  "scripts": {
86
+ "api": "fluid-build . --task api",
87
+ "api-extractor:commonjs": "api-extractor run --local",
88
+ "api-extractor:esnext": "copyfiles -u 1 \"dist/**/*-@(alpha|beta|public|untrimmed).d.ts\" lib",
84
89
  "build": "fluid-build . --task build",
85
90
  "build:commonjs": "fluid-build . --task commonjs",
86
91
  "build:compile": "fluid-build . --task compile",
87
- "build:docs": "api-extractor run --local",
92
+ "build:docs": "fluid-build . --task api",
88
93
  "build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
89
94
  "build:test": "tsc-multi --config ./tsc-multi.test.json",
95
+ "check:are-the-types-wrong": "attw --pack",
96
+ "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
90
97
  "ci:build:docs": "api-extractor run",
91
98
  "clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
92
99
  "eslint": "eslint --format stylish src",
93
100
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
94
101
  "format": "npm run prettier:fix",
95
- "lint": "npm run prettier && npm run eslint",
102
+ "lint": "npm run prettier && npm run check:release-tags && npm run eslint",
96
103
  "lint:fix": "npm run prettier:fix && npm run eslint:fix",
97
- "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
98
- "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
104
+ "prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
105
+ "prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
99
106
  "test": "npm run test:mocha",
100
107
  "test:coverage": "c8 npm test",
101
108
  "test:mocha": "mocha --ignore \"dist/test/types/*\" --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup",