-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs(module): update tsdoc for `Module` interface * feat(module): add semver * feat(module): add version attribute to module * feat(module): add base module provider class + create a common interface for module providers + create a base class for creating module provider * fix(module): add semver to legacy providers * docs(module): create change log for semver * docs(module): create changelog for base module provider
- Loading branch information
Showing
10 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@equinor/fusion-framework-module": minor | ||
--- | ||
|
||
__Feat(module)__ add base module class | ||
|
||
As a module developer there should be a base provider class to extend, which handles basic wireing. | ||
|
||
Some aspects of providers should be the same for all, like `version` handling. | ||
|
||
These new features does not change any existing code, only tooling for future development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
"@equinor/fusion-framework-module": minor | ||
--- | ||
|
||
__Feat(module): add semver__ | ||
|
||
In some cases other modules might require features in sibling modules | ||
```ts | ||
if (modules.context.version.satisfies('>=7.2')) { | ||
// do some code | ||
} else { | ||
throw Error('this feature requires ContextModule of 7.2 or higher, please update depencies') | ||
} | ||
``` | ||
|
||
Usage: | ||
- log telemetry about module usage and outdated application | ||
- debug code runtime by knowing version of implementation | ||
- write inter-opt when breaking changes accour | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/modules/module/src/lib/provider/BaseModuleProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import SemanticVersion from '../semantic-version'; | ||
|
||
import { type IModuleProvider } from './IModuleProvider'; | ||
|
||
import { Subscription, type TeardownLogic } from 'rxjs'; | ||
|
||
type BaseModuleProviderCtorArgs<TConfig = unknown> = { | ||
version: string; | ||
config: TConfig; | ||
}; | ||
|
||
/** | ||
* Base class for creating module provider | ||
* | ||
* this is the interface which is returned after enabling a module | ||
*/ | ||
export abstract class BaseModuleProvider<TConfig = unknown> implements IModuleProvider { | ||
#version: SemanticVersion; | ||
#subscriptions: Subscription; | ||
|
||
public get version() { | ||
return this.#version; | ||
} | ||
|
||
constructor(args: BaseModuleProviderCtorArgs<TConfig>) { | ||
this.#version = new SemanticVersion(args.version); | ||
this.#subscriptions = new Subscription(); | ||
this._init(args.config); | ||
} | ||
|
||
protected abstract _init(config: TConfig): void; | ||
|
||
/** | ||
* Add teardown down function, which is called on dispose. | ||
* | ||
* @param teardown dispose callback function | ||
* @returns callback for removing the teardown | ||
*/ | ||
protected _addTeardown(teardown: Exclude<TeardownLogic, void>): VoidFunction { | ||
this.#subscriptions.add(teardown); | ||
return () => this.#subscriptions.remove(teardown); | ||
} | ||
|
||
public dispose() { | ||
this.#subscriptions.unsubscribe(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import SemanticVersion from '../semantic-version'; | ||
|
||
export interface IModuleProvider { | ||
get version(): SemanticVersion; | ||
dispose: VoidFunction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { IModuleProvider } from './IModuleProvider'; | ||
export { BaseModuleProvider } from './BaseModuleProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { SemVer, satisfies } from 'semver'; | ||
|
||
/** | ||
* Extension of {@link SemVer} to expose `satisfies` | ||
* @see {@link [SemVer](https://www.npmjs.com/package/semver)} | ||
*/ | ||
export class SemanticVersion extends SemVer { | ||
public satisfies(arg: Parameters<typeof satisfies>[1]) { | ||
return satisfies(this, arg); | ||
} | ||
} | ||
|
||
export default SemanticVersion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters