@equinor/fusion-framework-module
Advanced tools
Comparing version 3.0.0 to 4.0.0-next.0
@@ -10,4 +10,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { BehaviorSubject, firstValueFrom, from, lastValueFrom, throwError } from 'rxjs'; | ||
import { filter, map, mergeMap, scan, timeout } from 'rxjs/operators'; | ||
import { BehaviorSubject, EMPTY, firstValueFrom, from, lastValueFrom, throwError } from 'rxjs'; | ||
import { catchError, filter, map, mergeMap, scan, tap, timeout } from 'rxjs/operators'; | ||
import { ModuleConsoleLogger } from './logger'; | ||
@@ -165,19 +165,13 @@ class RequiredModuleTimeoutError extends Error { | ||
const { modules, logger, _afterInit: afterInit } = this; | ||
yield Promise.allSettled(modules | ||
.filter((x) => !!x.postInitialize) | ||
.map((module) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
try { | ||
logger.debug(`🚀📌 post initializing moule ${logger.formatModuleName(module)}`); | ||
yield ((_a = module.postInitialize) === null || _a === void 0 ? void 0 : _a.call(module, { | ||
ref, | ||
modules: instance, | ||
instance: instance[module.name], | ||
})); | ||
logger.debug(`🚀📌 post initialized moule ${logger.formatModuleName(module)}`); | ||
} | ||
catch (err) { | ||
logger.warn(`🚀📌 post initialize failed moule ${logger.formatModuleName(module)}`); | ||
} | ||
}))); | ||
const postInitialize$ = from(modules).pipe(filter((module) => !!module.postInitialize), tap((module) => logger.debug(`🚀📌 post initializing moule ${logger.formatModuleName(module)}`)), mergeMap((module) => from(module.postInitialize({ | ||
ref, | ||
modules: instance, | ||
instance: instance[module.name], | ||
})).pipe(tap(() => { | ||
logger.debug(`🚀📌 post initialized moule ${logger.formatModuleName(module)}`); | ||
}), catchError((err) => { | ||
logger.warn(`🚀📌 post initialize failed moule ${logger.formatModuleName(module)}`, err); | ||
return EMPTY; | ||
})))); | ||
yield lastValueFrom(postInitialize$); | ||
if (afterInit.length) { | ||
@@ -184,0 +178,0 @@ try { |
@@ -0,1 +1,2 @@ | ||
import { ObservableInput } from 'rxjs'; | ||
export type ModuleInitializerArgs<TConfig, TDeps extends Array<AnyModule> = []> = { | ||
@@ -15,4 +16,4 @@ ref?: any; | ||
instance: TType; | ||
modules: Record<TKey, TType> & ModulesInstanceType<ModulesType<TDeps>>; | ||
}) => void | Promise<void>; | ||
modules: ModuleInstance; | ||
}) => ObservableInput<void>; | ||
dispose?: (args: { | ||
@@ -19,0 +20,0 @@ ref?: any; |
{ | ||
"name": "@equinor/fusion-framework-module", | ||
"version": "3.0.0", | ||
"version": "4.0.0-next.0", | ||
"description": "", | ||
@@ -31,3 +31,3 @@ "main": "dist/esm/index.js", | ||
}, | ||
"gitHead": "3462d21feac22290eec2dce3b00602da22a7a74d" | ||
"gitHead": "a2d5050515d375c7546b321aba27d11239869d97" | ||
} |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { BehaviorSubject, firstValueFrom, from, lastValueFrom, throwError } from 'rxjs'; | ||
import { filter, map, mergeMap, scan, timeout } from 'rxjs/operators'; | ||
import { BehaviorSubject, EMPTY, firstValueFrom, from, lastValueFrom, throwError } from 'rxjs'; | ||
import { catchError, filter, map, mergeMap, scan, tap, timeout } from 'rxjs/operators'; | ||
@@ -288,32 +288,40 @@ import { IModuleConsoleLogger, ModuleConsoleLogger } from './logger'; | ||
const { modules, logger, _afterInit: afterInit } = this; | ||
/** call all added post config hooks */ | ||
await Promise.allSettled( | ||
modules | ||
.filter((x) => !!x.postInitialize) | ||
.map(async (module) => { | ||
try { | ||
const postInitialize$ = from(modules).pipe( | ||
filter((module): module is Required<AnyModule> => !!module.postInitialize), | ||
tap((module) => | ||
logger.debug(`🚀📌 post initializing moule ${logger.formatModuleName(module)}`) | ||
), | ||
mergeMap((module) => | ||
from( | ||
module.postInitialize({ | ||
ref, | ||
modules: instance, | ||
instance: | ||
instance[ | ||
module.name as keyof ModulesInstanceType< | ||
CombinedModules<T, TModules> | ||
> | ||
], | ||
}) | ||
).pipe( | ||
tap(() => { | ||
logger.debug( | ||
`🚀📌 post initializing moule ${logger.formatModuleName(module)}` | ||
); | ||
await module.postInitialize?.({ | ||
ref, | ||
modules: instance, | ||
instance: | ||
instance[ | ||
module.name as keyof ModulesInstanceType< | ||
CombinedModules<T, TModules> | ||
> | ||
], | ||
}); | ||
logger.debug( | ||
`🚀📌 post initialized moule ${logger.formatModuleName(module)}` | ||
); | ||
} catch (err) { | ||
}), | ||
catchError((err) => { | ||
logger.warn( | ||
`🚀📌 post initialize failed moule ${logger.formatModuleName(module)}` | ||
`🚀📌 post initialize failed moule ${logger.formatModuleName(module)}`, | ||
err | ||
); | ||
} | ||
}) | ||
return EMPTY; | ||
}) | ||
) | ||
) | ||
); | ||
/** call all added post config hooks */ | ||
await lastValueFrom(postInitialize$); | ||
if (afterInit.length) { | ||
@@ -320,0 +328,0 @@ try { |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { ObservableInput } from 'rxjs'; | ||
export type ModuleInitializerArgs<TConfig, TDeps extends Array<AnyModule> = []> = { | ||
@@ -24,4 +26,4 @@ ref?: any; | ||
instance: TType; | ||
modules: Record<TKey, TType> & ModulesInstanceType<ModulesType<TDeps>>; | ||
}) => void | Promise<void>; | ||
modules: ModuleInstance; // Record<TKey, TType> & ModulesInstanceType<ModulesType<TDeps>>; | ||
}) => ObservableInput<void>; | ||
dispose?: (args: { | ||
@@ -28,0 +30,0 @@ ref?: any; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138254
942
2