@fluidframework/synthesize 0.55.2 → 0.56.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,MAAM,CAAC,MAAM,2BAA2B,GAClC,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidObject } from \"@fluidframework/core-interfaces\";\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n FluidObjectProvider,\n FluidObjectKey,\n} from \"./types\";\n\ndeclare module \"@fluidframework/core-interfaces\" {\n export interface IFluidObject {\n /** @deprecated - use `FluidObject<IFluidDependencySynthesizer>` instead */\n readonly IFluidDependencySynthesizer?: IFluidDependencySynthesizer;\n }\n}\n\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer\n = \"IFluidDependencySynthesizer\";\n\nexport interface IProvideFluidDependencySynthesizer {\n IFluidDependencySynthesizer: IFluidDependencySynthesizer;\n}\n\n/**\n * IFluidDependencySynthesizer can generate IFluidObjects based on the IProvideFluidObject pattern.\n * It allow for registering providers and uses synthesize to generate a new object with the optional\n * and required types.\n */\nexport interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {\n /**\n * @deprecated - This will only be available on DependencyContainer\n * All the registered types available\n */\n readonly registeredTypes: Iterable<(keyof IFluidObject)>;\n\n /**\n * @deprecated - This will only be available on DependencyContainer\n * Add a new provider\n * @param type - Name of the Type T being provided\n * @param provider - A provider that will resolve the T correctly when asked\n * @throws - If passing a type that's already registered\n */\n register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void;\n\n /**\n * @deprecated - This will only be available on DependencyContainer\n * Remove a provider\n * @param type - Name of the provider to remove\n */\n unregister<T extends keyof IFluidObject>(type: T): void;\n\n /**\n * synthesize takes optional and required types and returns an object that will fulfill the\n * defined types based off objects that has been previously registered.\n *\n * @param optionalTypes - optional types to be in the Scope object\n * @param requiredTypes - required types that need to be in the Scope object\n */\n synthesize<\n O extends IFluidObject,\n R extends IFluidObject>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: FluidObjectSymbolProvider<R>,\n ): AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>>;\n\n /**\n * Check if a given type is registered\n * @param type - Type to check\n */\n has(type: (keyof IFluidObject)): boolean;\n\n /**\n * @deprecated - This will be removed. Use synthesize or has instead\n * Get a provider. undefined if not available.\n * @param type - Type to get\n */\n getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined;\n}\n"]}
1
+ {"version":3,"file":"IFluidDependencySynthesizer.js","sourceRoot":"","sources":["../src/IFluidDependencySynthesizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,CAAC,MAAM,2BAA2B,GAClC,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n} from \"./types\";\n\nexport const IFluidDependencySynthesizer: keyof IProvideFluidDependencySynthesizer\n = \"IFluidDependencySynthesizer\";\n\nexport interface IProvideFluidDependencySynthesizer {\n IFluidDependencySynthesizer: IFluidDependencySynthesizer;\n}\n\n/**\n * IFluidDependencySynthesizer can generate IFluidObjects based on the IProvideFluidObject pattern.\n * It allow for registering providers and uses synthesize to generate a new object with the optional\n * and required types.\n */\nexport interface IFluidDependencySynthesizer extends IProvideFluidDependencySynthesizer {\n \n /**\n * synthesize takes optional and required types and returns an object that will fulfill the\n * defined types based off objects that has been previously registered.\n *\n * @param optionalTypes - optional types to be in the Scope object\n * @param requiredTypes - required types that need to be in the Scope object\n */\n synthesize<O, R = undefined | Record<string, never>>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: Required<FluidObjectSymbolProvider<R>>,\n ): AsyncFluidObjectProvider<O, R>;\n\n /**\n * Check if a given type is registered\n * @param type - Type to check\n */\n has(type: string): boolean;\n}\n"]}
@@ -14,14 +14,10 @@ export class DependencyContainer {
14
14
  }
15
15
  get IFluidDependencySynthesizer() { return this; }
16
16
  /**
17
- * @deprecated - use has instead
18
- * {@inheritDoc (IFluidDependencySynthesizer:interface).registeredTypes}
19
- */
20
- get registeredTypes() {
21
- return this.providers.keys();
22
- }
23
- /**
24
- * {@inheritDoc (IFluidDependencySynthesizer:interface).register}
17
+ * Add a new provider
18
+ * @param type - Name of the Type T being provided
19
+ * @param provider - A provider that will resolve the T correctly when asked
20
+ * @throws - If passing a type that's already registered
25
21
  */
26
22
  register(type, provider) {
27
23
  if (this.providers.has(type)) {
@@ -30,7 +26,8 @@ export class DependencyContainer {
30
26
  this.providers.set(type, provider);
31
27
  }
32
28
  /**
33
- * {@inheritDoc (IFluidDependencySynthesizer:interface).unregister}
29
+ * Remove a provider
30
+ * @param type - Name of the provider to remove
34
31
  */
35
32
  unregister(type) {
36
33
  if (this.providers.has(type)) {
@@ -61,25 +58,30 @@ export class DependencyContainer {
61
58
  return false;
62
59
  }
63
60
  /**
64
- * @deprecated - use synthesize or has instead
65
- *
66
- * {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}
61
+ * @deprecated - Needed for back compat
67
62
  */
68
- getProvider(type) {
69
- // If we have the provider return it
70
- const provider = this.providers.get(type);
71
- if (provider) {
72
- return provider;
73
- }
74
- for (const parent of this.parents) {
75
- const p = parent.getProvider(type);
76
- if (p !== undefined) {
77
- return p;
63
+ getProvider(provider) {
64
+ if (this.has(provider)) {
65
+ if (this.providers.has(provider)) {
66
+ return this.providers.get(provider);
67
+ }
68
+ for (const parent of this.parents) {
69
+ if (parent instanceof DependencyContainer) {
70
+ return parent.getProvider(provider);
71
+ }
72
+ else {
73
+ // eslint-disable-next-line @typescript-eslint/dot-notation
74
+ const maybeGetProvider = parent["getProvider"];
75
+ if (typeof maybeGetProvider === "function") {
76
+ return maybeGetProvider(provider);
77
+ }
78
+ }
78
79
  }
79
80
  }
80
- return undefined;
81
81
  }
82
82
  generateRequired(base, types) {
83
+ if (types === undefined)
84
+ return;
83
85
  for (const key of Object.keys(types)) {
84
86
  const provider = this.resolveProvider(key);
85
87
  if (provider === undefined) {
@@ -90,7 +92,12 @@ export class DependencyContainer {
90
92
  }
91
93
  generateOptional(base, types) {
92
94
  var _a;
95
+ if (types === undefined)
96
+ return;
93
97
  for (const key of Object.keys(types)) {
98
+ // back-compat: in 0.56 we allow undefined in the types, but we didn't before
99
+ // this will keep runtime back compat, eventually we should support undefined properties
100
+ // rather than properties that return promises that resolve to undefined
94
101
  const provider = (_a = this.resolveProvider(key)) !== null && _a !== void 0 ? _a : { get: () => Promise.resolve(undefined) };
95
102
  Object.defineProperty(base, key, provider);
96
103
  }
@@ -100,9 +107,7 @@ export class DependencyContainer {
100
107
  const provider = this.providers.get(t);
101
108
  if (provider === undefined) {
102
109
  for (const parent of this.parents) {
103
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
104
110
  const sp = { [t]: t };
105
- // eslint-disable-next-line @typescript-eslint/ban-types
106
111
  const syn = parent.synthesize(sp, {});
107
112
  const descriptor = Object.getOwnPropertyDescriptor(syn, t);
108
113
  if (descriptor !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EACH,2BAA2B,GAC9B,MAAM,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAa5B,YAAmB,GAAI,OAAoD;QAZ1D,cAAS,GAAG,IAAI,GAAG,EAAgD,CAAC;QAajF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,C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wBACxC,IAAI,CAAC,EAAE;4BACH,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;yBACf;oBACL,CAAC,CAAC,CAAC;iBACN;YACL,CAAC;SACJ,CAAC;IACV,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidObject } from \"@fluidframework/core-interfaces\";\n\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n FluidObjectProvider,\n FluidObjectKey,\n AsyncOptionalFluidObjectProvider,\n AsyncRequiredFluidObjectProvider,\n} from \"./types\";\nimport {\n IFluidDependencySynthesizer,\n} from \"./IFluidDependencySynthesizer\";\n\n/**\n * DependencyContainer is similar to a IoC Container. It takes providers and will\n * synthesize an object based on them when requested.\n */\nexport class DependencyContainer implements IFluidDependencySynthesizer {\n private readonly providers = new Map<keyof IFluidObject, FluidObjectProvider<any>>();\n private readonly parents: IFluidDependencySynthesizer[];\n public get IFluidDependencySynthesizer() { return this; }\n\n /**\n * @deprecated - use has instead\n * {@inheritDoc (IFluidDependencySynthesizer:interface).registeredTypes}\n */\n public get registeredTypes(): Iterable<(keyof IFluidObject)> {\n return this.providers.keys();\n }\n\n public constructor(... parents: (IFluidDependencySynthesizer | undefined)[]) {\n this.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).register}\n */\n public register<T extends keyof IFluidObject>(type: T, provider: FluidObjectProvider<T>): void {\n if (this.providers.has(type)) {\n throw new Error(`Attempting to register a provider of type ${type} that already exists`);\n }\n\n this.providers.set(type, provider);\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).unregister}\n */\n public unregister<T extends keyof IFluidObject>(type: T): void {\n if (this.providers.has(type)) {\n this.providers.delete(type);\n }\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n */\n public synthesize<\n O extends IFluidObject,\n // eslint-disable-next-line @typescript-eslint/ban-types\n R extends IFluidObject = {}>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: FluidObjectSymbolProvider<R>,\n ): AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>> {\n const base: AsyncFluidObjectProvider<FluidObjectKey<O>, FluidObjectKey<R>> = {} as any;\n this.generateRequired<R>(base, requiredTypes);\n this.generateOptional<O>(base, optionalTypes);\n Object.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n return base;\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n * @param excludeParents - If true, exclude checking parent registries\n */\n public has(type: (keyof IFluidObject), excludeParents?: boolean): boolean {\n if (this.providers.has(type)) {\n return true;\n }\n if (excludeParents !== true) {\n return this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n }\n return false;\n }\n\n /**\n * @deprecated - use synthesize or has instead\n *\n * {@inheritDoc (IFluidDependencySynthesizer:interface).getProvider}\n */\n public getProvider<T extends keyof IFluidObject>(type: T): FluidObjectProvider<T> | undefined {\n // If we have the provider return it\n const provider = this.providers.get(type);\n if (provider) {\n return provider;\n }\n\n for(const parent of this.parents) {\n const p = parent.getProvider(type);\n if (p !== undefined) {\n return p;\n }\n }\n\n return undefined;\n }\n\n private generateRequired<T extends IFluidObject>(\n base: AsyncRequiredFluidObjectProvider<FluidObjectKey<T>>,\n types: FluidObjectSymbolProvider<T>,\n ) {\n for(const key of Object.keys(types) as unknown as (keyof IFluidObject)[]) {\n const provider = this.resolveProvider(key);\n if(provider === undefined) {\n throw new Error(`Object attempted to be created without registered required provider ${key}`);\n }\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private generateOptional<T extends IFluidObject>(\n base: AsyncOptionalFluidObjectProvider<FluidObjectKey<T>>,\n types: FluidObjectSymbolProvider<T>,\n ) {\n for(const key of Object.keys(types) as unknown as (keyof IFluidObject)[]) {\n const provider = this.resolveProvider(key) ?? {get:()=>Promise.resolve(undefined)};\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private resolveProvider<T extends keyof IFluidObject>(t: T): PropertyDescriptor | undefined {\n // If we have the provider return it\n const provider = this.providers.get(t);\n if (provider === undefined) {\n for(const parent of this.parents) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const sp = { [t]: t } as FluidObjectSymbolProvider<Pick<IFluidObject, T>>;\n // eslint-disable-next-line @typescript-eslint/ban-types\n const syn = parent.synthesize<Pick<IFluidObject, T>,{}>(\n sp,\n {});\n const descriptor = Object.getOwnPropertyDescriptor(syn, t);\n if (descriptor !== undefined) {\n return descriptor;\n }\n }\n return undefined;\n }\n\n // The double nested gets are required for lazy loading the provider resolution\n if (typeof provider === \"function\") {\n return {\n get() {\n if (provider && typeof provider === \"function\") {\n return Promise.resolve(this[IFluidDependencySynthesizer])\n .then(async (fds): Promise<any> => provider(fds))\n .then((p) => p?.[t]);\n }\n },\n };\n }\n return {\n get() {\n if (provider) {\n return Promise.resolve(provider).then((p) => {\n if (p) {\n return p[t];\n }\n });\n }\n },\n };\n }\n}\n"]}
1
+ {"version":3,"file":"dependencyContainer.js","sourceRoot":"","sources":["../src/dependencyContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EACH,2BAA2B,GAC9B,MAAM,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAK5B,YAAmB,GAAI,OAAoD;QAJ1D,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAKzE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC5F,CAAC;IAJD,IAAW,2BAA2B,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAMzD;;;;;OAKG;IACI,QAAQ,CAAoC,IAAO,EAAE,QAA4C;QACpG,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAA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,IAAI,CAAC,EAAE;4BACH,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;yBACf;oBACL,CAAC,CAAC,CAAC;iBACN;YACL,CAAC;SACJ,CAAC;IACV,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n AsyncFluidObjectProvider,\n FluidObjectSymbolProvider,\n FluidObjectProvider,\n AsyncOptionalFluidObjectProvider,\n AsyncRequiredFluidObjectProvider,\n} from \"./types\";\nimport {\n IFluidDependencySynthesizer,\n} from \"./IFluidDependencySynthesizer\";\n\n/**\n * DependencyContainer is similar to a IoC Container. It takes providers and will\n * synthesize an object based on them when requested.\n */\nexport class DependencyContainer<TMap> implements IFluidDependencySynthesizer {\n private readonly providers = new Map<keyof TMap, FluidObjectProvider<any>>();\n private readonly parents: IFluidDependencySynthesizer[];\n public get IFluidDependencySynthesizer() { return this; }\n\n public constructor(... parents: (IFluidDependencySynthesizer | undefined)[]) {\n this.parents = parents.filter((v): v is IFluidDependencySynthesizer => v !== undefined);\n }\n\n /**\n * Add a new provider\n * @param type - Name of the Type T being provided\n * @param provider - A provider that will resolve the T correctly when asked\n * @throws - If passing a type that's already registered\n */\n public register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void {\n if (this.providers.has(type)) {\n throw new Error(`Attempting to register a provider of type ${type} that already exists`);\n }\n\n this.providers.set(type, provider);\n }\n\n /**\n * Remove a provider\n * @param type - Name of the provider to remove\n */\n public unregister(type: keyof TMap): void {\n if (this.providers.has(type)) {\n this.providers.delete(type);\n }\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).synthesize}\n */\n public synthesize<O, R = undefined | Record<string, never>>(\n optionalTypes: FluidObjectSymbolProvider<O>,\n requiredTypes: Required<FluidObjectSymbolProvider<R>>,\n ): AsyncFluidObjectProvider<O, R> {\n const base: AsyncFluidObjectProvider<O, R> = {} as any;\n this.generateRequired<R>(base, requiredTypes);\n this.generateOptional<O>(base, optionalTypes);\n Object.defineProperty(base, IFluidDependencySynthesizer, { get: () => this });\n return base;\n }\n\n /**\n * {@inheritDoc (IFluidDependencySynthesizer:interface).has}\n * @param excludeParents - If true, exclude checking parent registries\n */\n public has(type: string, excludeParents?: boolean): boolean {\n if (this.providers.has(type as keyof TMap)) {\n return true;\n }\n if (excludeParents !== true) {\n return this.parents.some((p: IFluidDependencySynthesizer) => p.has(type));\n }\n return false;\n }\n /**\n * @deprecated - Needed for back compat\n */\n private getProvider(provider: string & keyof TMap){\n if(this.has(provider)){\n if(this.providers.has(provider)){\n return this.providers.get(provider);\n }\n for(const parent of this.parents){\n if(parent instanceof DependencyContainer){\n return parent.getProvider(provider);\n }else{\n // eslint-disable-next-line @typescript-eslint/dot-notation\n const maybeGetProvider = parent[\"getProvider\"];\n if(typeof maybeGetProvider === \"function\"){\n return maybeGetProvider(provider);\n }\n }\n }\n }\n }\n\n private generateRequired<T>(\n base: AsyncRequiredFluidObjectProvider<T>,\n types: Required<FluidObjectSymbolProvider<T>>,\n ) {\n if(types === undefined) return;\n for(const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n const provider = this.resolveProvider(key);\n if(provider === undefined) {\n throw new Error(`Object attempted to be created without registered required provider ${key}`);\n }\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private generateOptional<T>(\n base: AsyncOptionalFluidObjectProvider<T>,\n types: FluidObjectSymbolProvider<T>,\n ) {\n if(types === undefined) return;\n for(const key of Object.keys(types) as unknown as (keyof TMap)[]) {\n // back-compat: in 0.56 we allow undefined in the types, but we didn't before\n // this will keep runtime back compat, eventually we should support undefined properties\n // rather than properties that return promises that resolve to undefined\n const provider = this.resolveProvider(key) ?? {get:()=>Promise.resolve(undefined)};\n Object.defineProperty(\n base,\n key,\n provider,\n );\n }\n }\n\n private resolveProvider<T extends keyof TMap>(t: T): PropertyDescriptor | undefined {\n // If we have the provider return it\n const provider = this.providers.get(t);\n if (provider === undefined) {\n for(const parent of this.parents) {\n const sp = { [t]: t } as FluidObjectSymbolProvider<Pick<TMap, T>>;\n const syn = parent.synthesize<Pick<TMap, T>,{}>(\n sp,\n {});\n const descriptor = Object.getOwnPropertyDescriptor(syn, t);\n if (descriptor !== undefined) {\n return descriptor;\n }\n }\n return undefined;\n }\n\n // The double nested gets are required for lazy loading the provider resolution\n if (typeof provider === \"function\") {\n return {\n get() {\n if (provider && typeof provider === \"function\") {\n return Promise.resolve(this[IFluidDependencySynthesizer])\n .then(async (fds): Promise<any> => provider(fds))\n .then((p) => p?.[t]);\n }\n },\n };\n }\n return {\n get() {\n if (provider) {\n return Promise.resolve(provider).then((p) => {\n if (p) {\n return p[t];\n }\n });\n }\n },\n };\n }\n}\n"]}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","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 { IFluidObject } from \"@fluidframework/core-interfaces\";\nimport { IFluidDependencySynthesizer } from \".\";\n\nexport type FluidObjectKey<T extends IFluidObject> = keyof T & keyof IFluidObject;\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the IFluidObject properties as its type mapped to a string representation\n * of that property.\n *\n * @example - \\{ IFoo: \"IFoo\" \\}\n */\nexport type FluidObjectSymbolProvider<T extends IFluidObject> = {\n [P in FluidObjectKey<T>]: FluidObjectKey<T> & P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the IFluidObject properties as its type mapped to an object that implements\n * the property.\n */\nexport type AsyncRequiredFluidObjectProvider<T extends keyof IFluidObject> = {\n [P in T]: Promise<NonNullable<IFluidObject[P]>>\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the IFluidObject properties as its type, mapped to an object that implements\n * the property or undefined.\n */\nexport type AsyncOptionalFluidObjectProvider<T extends keyof IFluidObject> = {\n [P in T]: Promise<IFluidObject[P] | undefined>;\n};\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n */\nexport type AsyncFluidObjectProvider<O extends keyof IFluidObject, R extends keyof IFluidObject>\n = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Provided a keyof IFluidObject will ensure the type is an instance of that type\n */\nexport type NonNullableFluidObject<T extends keyof IFluidObject> = NonNullable<IFluidObject[T]>;\n\n/**\n * Multiple ways to provide a Fluid object.\n */\nexport type FluidObjectProvider<T extends keyof IFluidObject> =\n NonNullableFluidObject<T>\n | Promise<NonNullableFluidObject<T>>\n | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullableFluidObject<T>)\n | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullableFluidObject<T>>);\n\n/**\n * @deprecated - create a new DependencyContainer instead\n * ProviderEntry is a mapping of the type to the Provider\n */\nexport interface ProviderEntry<T extends keyof IFluidObject> {\n type: T;\n provider: FluidObjectProvider<T>\n}\n\n/**\n * @deprecated - create a new DependencyContainer instead\n * A mapping of ProviderEntries\n */\nexport type DependencyContainerRegistry = Iterable<ProviderEntry<any>>;\n"]}
1
+ {"version":3,"file":"types.js","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 * This is a condensed version of Record that requires the object has all\n * the IFluidObject properties as its type mapped to a string representation\n * of that property.\n *\n * @example - \\{ IFoo: \"IFoo\" \\}\n */\nexport type FluidObjectSymbolProvider<T> = {\n [P in keyof T]?: P;\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the IFluidObject properties as its type mapped to an object that implements\n * the property.\n */\nexport type AsyncRequiredFluidObjectProvider<T> = T extends undefined ? Record<string, never> : {\n [P in keyof T]: Promise<NonNullable<Exclude<T[P], undefined | null>>>\n};\n\n/**\n * This is a condensed version of Record that requires the object has all\n * the IFluidObject properties as its type, mapped to an object that implements\n * the property or undefined.\n */\nexport type AsyncOptionalFluidObjectProvider<T> = T extends undefined\n ? Record<string, never>\n : {\n [P in keyof T]?: Promise<T[P] | undefined>;\n };\n\n/**\n * Combined type for Optional and Required Async Fluid object Providers\n */\nexport type AsyncFluidObjectProvider<O, R = undefined>\n = AsyncOptionalFluidObjectProvider<O> & AsyncRequiredFluidObjectProvider<R>;\n\n/**\n * Multiple ways to provide a Fluid object.\n */\nexport type FluidObjectProvider<T> =\n NonNullable<T>\n | Promise<NonNullable<T>>\n | ((dependencyContainer: IFluidDependencySynthesizer) => NonNullable<T>)\n | ((dependencyContainer: IFluidDependencySynthesizer) => Promise<NonNullable<T>>);"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/synthesize",
3
- "version": "0.55.2",
3
+ "version": "0.56.2",
4
4
  "description": "A library for synthesizing scope objects.",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": "https://github.com/microsoft/FluidFramework",
@@ -57,14 +57,12 @@
57
57
  ],
58
58
  "temp-directory": "nyc/.nyc_output"
59
59
  },
60
- "dependencies": {
61
- "@fluidframework/core-interfaces": "^0.41.0"
62
- },
63
60
  "devDependencies": {
64
61
  "@fluidframework/build-common": "^0.23.0",
65
- "@fluidframework/datastore": "^0.55.2",
62
+ "@fluidframework/core-interfaces": "^0.42.0",
63
+ "@fluidframework/datastore": "^0.56.2",
66
64
  "@fluidframework/eslint-config-fluid": "^0.25.0",
67
- "@fluidframework/mocha-test-setup": "^0.55.2",
65
+ "@fluidframework/mocha-test-setup": "^0.56.2",
68
66
  "@microsoft/api-extractor": "^7.16.1",
69
67
  "@rushstack/eslint-config": "^2.5.1",
70
68
  "@types/mocha": "^8.2.2",